]> git.tdb.fi Git - libs/gl.git/blob - source/programparser.h
Derive ProgramCompiler::DeclarationCombiner from BlockModifier
[libs/gl.git] / source / programparser.h
1 #ifndef MSP_GL_PROGRAMPARSER_H_
2 #define MSP_GL_PROGRAMPARSER_H_
3
4 #include <deque>
5 #include <map>
6 #include <set>
7 #include <string>
8 #include <msp/io/base.h>
9 #include "programsyntax.h"
10
11 namespace Msp {
12 namespace GL {
13
14 class ProgramParser
15 {
16 private:
17         enum OperatorType
18         {
19                 NO_OPERATOR,
20                 BINARY,
21                 PREFIX,
22                 POSTFIX
23         };
24
25         enum Associativity
26         {
27                 LEFT_TO_RIGHT,
28                 RIGHT_TO_LEFT
29         };
30
31         struct Operator
32         {
33                 const char token[4];
34                 unsigned precedence;
35                 OperatorType type;
36                 Associativity assoc;
37         };
38
39         std::string source;
40         std::string::const_iterator iter;
41         std::deque<std::string> next_tokens;
42         ProgramSyntax::Module *module;
43         ProgramSyntax::Stage *cur_stage;
44         std::set<std::string> declared_types;
45
46         static Operator operators[];
47
48 public:
49         ProgramParser();
50         ~ProgramParser();
51
52         ProgramSyntax::Module &parse(const std::string &);
53         ProgramSyntax::Module &parse(IO::Base &);
54
55 private:
56         void parse_source();
57
58         const std::string &peek_token(unsigned = 0);
59         std::string parse_token();
60         std::string parse_token_();
61         std::string parse_identifier();
62         std::string parse_number();
63         std::string parse_other();
64         bool skip_comment_and_whitespace();
65         void expect(const std::string &);
66         std::string expect_type();
67         std::string expect_identifier();
68         bool check(const std::string &);
69
70         static bool is_interface_qualifier(const std::string &);
71         static bool is_sampling_qualifier(const std::string &);
72         static bool is_precision_qualifier(const std::string &);
73         static bool is_qualifier(const std::string &);
74         static bool is_builtin_type(const std::string &);
75         bool is_type(const std::string &);
76         bool is_identifier(const std::string &);
77
78         RefPtr<ProgramSyntax::Node> parse_global_declaration();
79         RefPtr<ProgramSyntax::Node> parse_statement();
80         RefPtr<ProgramSyntax::Import> parse_import();
81         RefPtr<ProgramSyntax::Precision> parse_precision();
82         RefPtr<ProgramSyntax::Layout> parse_layout();
83         void parse_block(ProgramSyntax::Block &, bool);
84         RefPtr<ProgramSyntax::Expression> parse_expression(unsigned = 0);
85         RefPtr<ProgramSyntax::BinaryExpression> parse_binary(const RefPtr<ProgramSyntax::Expression> &, const Operator *);
86         RefPtr<ProgramSyntax::FunctionCall> parse_function_call(const ProgramSyntax::VariableReference &);
87         RefPtr<ProgramSyntax::StructDeclaration> parse_struct_declaration();
88         RefPtr<ProgramSyntax::VariableDeclaration> parse_variable_declaration();
89         RefPtr<ProgramSyntax::FunctionDeclaration> parse_function_declaration();
90         RefPtr<ProgramSyntax::InterfaceBlock> parse_interface_block();
91         RefPtr<ProgramSyntax::Conditional> parse_conditional();
92         RefPtr<ProgramSyntax::Iteration> parse_iteration();
93         RefPtr<ProgramSyntax::Passthrough> parse_passthrough();
94         RefPtr<ProgramSyntax::Return> parse_return();
95 };
96
97 } // namespace GL
98 } // namespace Msp
99
100 #endif