]> git.tdb.fi Git - libs/gl.git/blob - source/programparser.h
Remove unused variable and struct declarations from the syntax tree
[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 main_module;
43         ProgramSyntax::Module *cur_module;
44         std::set<std::string> declared_types;
45
46         static Operator operators[];
47
48 public:
49         ProgramSyntax::Module &parse(const std::string &);
50         ProgramSyntax::Module &parse(IO::Base &);
51
52 private:
53         void parse_source(ProgramSyntax::Module &);
54
55         const std::string &peek_token(unsigned = 0);
56         std::string parse_token();
57         std::string parse_token_();
58         std::string parse_identifier();
59         std::string parse_number();
60         std::string parse_other();
61         bool skip_comment_and_whitespace();
62         void expect(const std::string &);
63         std::string expect_type();
64         std::string expect_identifier();
65         bool check(const std::string &);
66
67         static bool is_interface_qualifier(const std::string &);
68         static bool is_sampling_qualifier(const std::string &);
69         static bool is_qualifier(const std::string &);
70         static bool is_builtin_type(const std::string &);
71         bool is_type(const std::string &);
72         bool is_identifier(const std::string &);
73
74         ProgramSyntax::Node *parse_global_declaration();
75         ProgramSyntax::Node *parse_statement();
76         ProgramSyntax::Layout *parse_layout();
77         void parse_block(ProgramSyntax::Block &, bool);
78         ProgramSyntax::Expression *parse_expression(unsigned = 0);
79         ProgramSyntax::BinaryExpression *parse_binary(ProgramSyntax::Expression *, const Operator *);
80         ProgramSyntax::FunctionCall *parse_function_call(ProgramSyntax::VariableReference *);
81         ProgramSyntax::StructDeclaration *parse_struct_declaration();
82         ProgramSyntax::VariableDeclaration *parse_variable_declaration();
83         ProgramSyntax::FunctionDeclaration *parse_function_declaration();
84         void parse_function_parameter_list(ProgramSyntax::FunctionDeclaration &);
85         ProgramSyntax::InterfaceBlock *parse_interface_block();
86         ProgramSyntax::Conditional *parse_conditional();
87         ProgramSyntax::Iteration *parse_iteration();
88         ProgramSyntax::Return *parse_return();
89 };
90
91 } // namespace GL
92 } // namespace Msp
93
94 #endif