]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/parser.h
Recognize unknown index as matching any index
[libs/gl.git] / source / glsl / parser.h
1 #ifndef MSP_GL_SL_PARSER_H_
2 #define MSP_GL_SL_PARSER_H_
3
4 #include <set>
5 #include <string>
6 #include <msp/io/base.h>
7 #include "preprocessor.h"
8 #include "syntax.h"
9 #include "tokenizer.h"
10
11 namespace Msp {
12 namespace GL {
13 namespace SL {
14
15 class ModuleCache;
16
17 class Parser
18 {
19 private:
20         ModuleCache *mod_cache;
21         std::string source;
22         int base_index;
23         int source_index;
24         Tokenizer tokenizer;
25         Preprocessor preprocessor;
26         bool allow_stage_change;
27         Module *module;
28         std::vector<const Module *> imported_modules;
29         Stage *cur_stage;
30         std::set<std::string> global_types;
31         std::set<std::string> stage_types;
32         std::vector<std::string> errors;
33
34 public:
35         Parser(ModuleCache *);
36
37         void parse(Module &, const std::string &, const std::string &, int);
38         void parse(Module &, IO::Base &, const std::string &, int);
39
40 private:
41         void parse_source(const std::string &, int);
42         void set_required_version(const Version &);
43         void source_reference(unsigned, const std::string &);
44         void stage_change(Stage::Type);
45         void line_change(int, unsigned);
46
47         std::string expect_type();
48         std::string expect_identifier();
49         int expect_integer();
50         bool check(const std::string &);
51
52         static bool is_interface_qualifier(const std::string &);
53         static bool is_sampling_qualifier(const std::string &);
54         static bool is_interpolation_qualifier(const std::string &);
55         static bool is_precision_qualifier(const std::string &);
56         static bool is_qualifier(const std::string &);
57         bool is_type(const std::string &);
58         bool is_identifier(const std::string &);
59
60         void preprocess();
61         void preprocess_version();
62         void preprocess_pragma();
63         void preprocess_pragma_msp();
64         void preprocess_stage();
65
66         template<typename T>
67         RefPtr<T> create_node();
68         template<typename T>
69         RefPtr<T> parse_with_recovery(RefPtr<T> (Parser::*)());
70         RefPtr<Statement> parse_global_declaration();
71         RefPtr<Statement> parse_statement();
72         RefPtr<Import> parse_import();
73         RefPtr<Precision> parse_precision();
74         RefPtr<Layout> parse_layout();
75         template<typename T>
76         void parse_block(Block &, bool, RefPtr<T> (Parser::*)());
77         RefPtr<Expression> parse_expression(const Operator * = 0);
78         RefPtr<Literal> parse_literal();
79         RefPtr<BinaryExpression> parse_binary(const RefPtr<Expression> &, const Operator &);
80         RefPtr<TernaryExpression> parse_ternary(const RefPtr<Expression> &, const Operator &);
81         RefPtr<FunctionCall> parse_function_call(const VariableReference &);
82         RefPtr<TypeDeclaration> parse_type_declaration();
83         RefPtr<BasicTypeDeclaration> parse_basic_type_declaration();
84         RefPtr<ImageTypeDeclaration> parse_image_type_declaration();
85         RefPtr<StructDeclaration> parse_struct_declaration();
86         RefPtr<VariableDeclaration> parse_variable_declaration();
87         RefPtr<VariableDeclaration> parse_variable_declaration_with_layout();
88         RefPtr<FunctionDeclaration> parse_function_declaration();
89         RefPtr<InterfaceBlock> parse_interface_block();
90         RefPtr<Conditional> parse_conditional();
91         RefPtr<Iteration> parse_for();
92         RefPtr<Iteration> parse_while();
93         RefPtr<Passthrough> parse_passthrough();
94         RefPtr<Return> parse_return();
95 };
96
97 } // namespace SL
98 } // namespace GL
99 } // namespace Msp
100
101 #endif