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