]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/parser.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / glsl / parser.h
index 743149d83362a84be8b91e5b13dad8789e90bede..51616378c29c947653496ca71be80640081e55f4 100644 (file)
@@ -1,83 +1,53 @@
 #ifndef MSP_GL_SL_PARSER_H_
 #define MSP_GL_SL_PARSER_H_
 
-#include <deque>
-#include <map>
 #include <set>
 #include <string>
 #include <msp/io/base.h>
+#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<std::string> next_tokens;
        Module *module;
+       std::vector<const Module *> imported_modules;
        Stage *cur_stage;
-       std::set<std::string> declared_types;
-
-       static Operator operators[];
+       std::set<std::string> global_types;
+       std::set<std::string> stage_types;
+       std::vector<std::string> errors;
+       RefPtr<Statement> next_global_declaration;
 
 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 +55,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,19 +64,31 @@ private:
        void preprocess_pragma_msp();
        void preprocess_stage();
 
+       template<typename T>
+       RefPtr<T> create_node();
+       template<typename T>
+       RefPtr<T> parse_with_recovery(RefPtr<T> (Parser::*)());
        RefPtr<Statement> parse_global_declaration();
        RefPtr<Statement> parse_statement();
        RefPtr<Import> parse_import();
        RefPtr<Precision> parse_precision();
        RefPtr<Layout> parse_layout();
-       void parse_block(Block &, bool);
-       RefPtr<Expression> parse_expression(unsigned = 0);
-       RefPtr<BinaryExpression> parse_binary(const RefPtr<Expression> &, const Operator *);
+       template<typename T>
+       void parse_block(Block &, bool, RefPtr<T> (Parser::*)());
+       RefPtr<Expression> parse_expression(const Operator * = 0);
+       RefPtr<Literal> parse_literal();
+       RefPtr<BinaryExpression> parse_binary(const RefPtr<Expression> &, const Operator &);
+       RefPtr<TernaryExpression> parse_ternary(const RefPtr<Expression> &, const Operator &);
        RefPtr<FunctionCall> parse_function_call(const VariableReference &);
+       void add_type(TypeDeclaration &);
+       RefPtr<TypeDeclaration> parse_type_declaration();
+       RefPtr<BasicTypeDeclaration> parse_basic_type_declaration();
+       RefPtr<ImageTypeDeclaration> parse_image_type_declaration();
        RefPtr<StructDeclaration> parse_struct_declaration();
        RefPtr<VariableDeclaration> parse_variable_declaration();
+       RefPtr<VariableDeclaration> parse_variable_declaration_with_layout();
        RefPtr<FunctionDeclaration> parse_function_declaration();
-       RefPtr<InterfaceBlock> parse_interface_block();
+       RefPtr<StructDeclaration> parse_interface_block();
        RefPtr<Conditional> parse_conditional();
        RefPtr<Iteration> parse_for();
        RefPtr<Iteration> parse_while();