X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Fparser.h;h=a935356ecd1339e68e6bb82f2752a5d47e6a25fb;hp=743149d83362a84be8b91e5b13dad8789e90bede;hb=76cc18518fc8b0b4fa11fda153e7d9b3899ed112;hpb=47286086863b6009192ffdb3d3471c83211ee943 diff --git a/source/glsl/parser.h b/source/glsl/parser.h index 743149d8..a935356e 100644 --- a/source/glsl/parser.h +++ b/source/glsl/parser.h @@ -1,83 +1,52 @@ #ifndef MSP_GL_SL_PARSER_H_ #define MSP_GL_SL_PARSER_H_ -#include -#include #include #include #include +#include "preprocessor.h" #include "syntax.h" +#include "tokenizer.h" namespace Msp { namespace GL { namespace SL { -struct Location -{ - std::string name; - unsigned line; -}; +class ModuleCache; class Parser { private: - enum OperatorType - { - NO_OPERATOR, - BINARY, - PREFIX, - POSTFIX - }; - - enum Associativity - { - LEFT_TO_RIGHT, - RIGHT_TO_LEFT - }; - - struct Operator - { - const char token[4]; - unsigned precedence; - OperatorType type; - Associativity assoc; - }; - + ModuleCache *mod_cache; std::string source; - unsigned source_index; - Location location; - std::string::const_iterator iter; - std::string::const_iterator source_end; - bool allow_preprocess; + int base_index; + int source_index; + Tokenizer tokenizer; + Preprocessor preprocessor; bool allow_stage_change; - std::string last_token; - std::deque next_tokens; Module *module; + std::vector imported_modules; Stage *cur_stage; - std::set declared_types; - - static Operator operators[]; + std::set global_types; + std::set stage_types; + std::vector errors; public: - Parser(); - ~Parser(); + Parser(ModuleCache *); - Module &parse(const std::string &, const std::string &, unsigned = 0); - Module &parse(IO::Base &, const std::string &, unsigned = 0); + void parse(Module &, const std::string &, const std::string &, int); + void parse(Module &, IO::Base &, const std::string &, int); private: - void parse_source(); + void parse_source(const std::string &, int); + void set_required_version(const Version &); + void source_reference(unsigned, const std::string &); + void stage_change(Stage::Type); + void line_change(int, unsigned); - const std::string &peek_token(unsigned = 0); - const std::string &parse_token(); - std::string parse_token_(); - std::string parse_identifier(); - std::string parse_number(); - std::string parse_other(); - void skip_comment_and_whitespace(); - void expect(const std::string &); std::string expect_type(); std::string expect_identifier(); + int expect_integer(); bool check(const std::string &); static bool is_interface_qualifier(const std::string &); @@ -85,7 +54,6 @@ private: static bool is_interpolation_qualifier(const std::string &); static bool is_precision_qualifier(const std::string &); static bool is_qualifier(const std::string &); - static bool is_builtin_type(const std::string &); bool is_type(const std::string &); bool is_identifier(const std::string &); @@ -95,17 +63,28 @@ private: void preprocess_pragma_msp(); void preprocess_stage(); + template + RefPtr create_node(); + template + RefPtr parse_with_recovery(RefPtr (Parser::*)()); RefPtr parse_global_declaration(); RefPtr parse_statement(); RefPtr parse_import(); RefPtr parse_precision(); RefPtr parse_layout(); - void parse_block(Block &, bool); - RefPtr parse_expression(unsigned = 0); - RefPtr parse_binary(const RefPtr &, const Operator *); + template + void parse_block(Block &, bool, RefPtr (Parser::*)()); + RefPtr parse_expression(const Operator * = 0); + RefPtr parse_literal(); + RefPtr parse_binary(const RefPtr &, const Operator &); + RefPtr parse_ternary(const RefPtr &, const Operator &); RefPtr parse_function_call(const VariableReference &); + RefPtr parse_type_declaration(); + RefPtr parse_basic_type_declaration(); + RefPtr parse_image_type_declaration(); RefPtr parse_struct_declaration(); RefPtr parse_variable_declaration(); + RefPtr parse_variable_declaration_with_layout(); RefPtr parse_function_declaration(); RefPtr parse_interface_block(); RefPtr parse_conditional();