29class Q_QUICK3DGLSLPARSER_EXPORT
Parser:
public GLSLParserTable
34 const QString *string;
36 List<AST *> *ast_list;
37 DeclarationAST *declaration;
38 List<DeclarationAST *> *declaration_list;
39 ExpressionAST *expression;
40 List<ExpressionAST *> *expression_list;
41 StatementAST *statement;
42 List<StatementAST *> *statement_list;
44 StructTypeAST::Field *field;
45 List<StructTypeAST::Field *> *field_list;
46 TranslationUnitAST *translation_unit;
47 FunctionIdentifierAST *function_identifier;
49 TypeAST::Precision precision;
51 StatementAST *thenClause;
52 StatementAST *elseClause;
55 ExpressionAST *condition;
56 ExpressionAST *increment;
59 FunctionIdentifierAST *id;
60 List<ExpressionAST *> *arguments;
63 LayoutQualifierAST *layout;
64 List<LayoutQualifierAST *> *layout_list;
67 List<LayoutQualifierAST *> *layout_list;
73 ParameterDeclarationAST *param_declaration;
74 FunctionDeclarationAST *function_declaration;
77 Parser(Engine *engine,
const char *source,
unsigned size,
int variant);
80 TranslationUnitAST *parse() {
81 if (AST *u = parse(T_FEED_GLSL))
82 return u->asTranslationUnit();
86 ExpressionAST *parseExpression() {
87 if (AST *u = parse(T_FEED_EXPRESSION))
88 return u->asExpression();
92 AST *parse(
int startToken);
96 int &location(
int n) {
return _locationStack[_tos + n - 1]; }
97 Value &sym(
int n) {
return _symStack[_tos + n - 1]; }
98 AST *&ast(
int n) {
return _symStack[_tos + n - 1].ast; }
99 const QString *&string(
int n) {
return _symStack[_tos + n - 1].string; }
100 ExpressionAST *&expression(
int n) {
return _symStack[_tos + n - 1].expression; }
101 StatementAST *&statement(
int n) {
return _symStack[_tos + n - 1].statement; }
102 TypeAST *&type(
int n) {
return _symStack[_tos + n - 1].type; }
103 FunctionDeclarationAST *&function(
int n) {
return _symStack[_tos + n - 1].function_declaration; }
105 inline int consumeToken() {
106 if (_index <
int(_tokens.size()))
108 return static_cast<
int>(_tokens.size()) - 1;
110 inline const Token &tokenAt(
int index)
const {
113 return _tokens.at(index);
115 inline int tokenKind(
int index)
const {
117 return _startToken.kind;
118 return _tokens.at(index).kind;
120 void reduce(
int ruleno);
122 void warning(
int line,
const QString &message)
124 _engine->warning(line, message);
127 void error(
int line,
const QString &message)
129 _engine->error(line, message);
132 template <
typename T>
135 T *node =
new (_engine->pool()) T ();
136 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
140 template <
typename T,
typename A1>
141 T *makeAstNode(A1 a1)
143 T *node =
new (_engine->pool()) T (a1);
144 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
148 template <
typename T,
typename A1,
typename A2>
149 T *makeAstNode(A1 a1, A2 a2)
151 T *node =
new (_engine->pool()) T (a1, a2);
152 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
156 template <
typename T,
typename A1,
typename A2,
typename A3>
157 T *makeAstNode(A1 a1, A2 a2, A3 a3)
159 T *node =
new (_engine->pool()) T (a1, a2, a3);
160 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
164 template <
typename T,
typename A1,
typename A2,
typename A3,
typename A4>
165 T *makeAstNode(A1 a1, A2 a2, A3 a3, A4 a4)
167 T *node =
new (_engine->pool()) T (a1, a2, a3, a4);
168 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
172 TypeAST *makeBasicType(
int token)
174 TypeAST *type =
new (_engine->pool()) BasicTypeAST(token, spell[token]);
175 type->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
188 std::vector<
int> _stateStack;
189 std::vector<
int> _locationStack;
190 std::vector<Value> _symStack;
191 std::vector<Token> _tokens;
193Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(
int, GLSLParserTable::VariousConstants, Lexer::Variant)