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