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