31class Q_QUICK3DGLSLPARSER_EXPORT
Parser:
public GLSLParserTable
36 const QString *string;
38 List<AST *> *ast_list;
39 DeclarationAST *declaration;
40 List<DeclarationAST *> *declaration_list;
41 ExpressionAST *expression;
42 List<ExpressionAST *> *expression_list;
43 StatementAST *statement;
44 List<StatementAST *> *statement_list;
46 StructTypeAST::Field *field;
47 List<StructTypeAST::Field *> *field_list;
48 TranslationUnitAST *translation_unit;
49 FunctionIdentifierAST *function_identifier;
51 TypeAST::Precision precision;
53 StatementAST *thenClause;
54 StatementAST *elseClause;
57 ExpressionAST *condition;
58 ExpressionAST *increment;
61 FunctionIdentifierAST *id;
62 List<ExpressionAST *> *arguments;
65 LayoutQualifierAST *layout;
66 List<LayoutQualifierAST *> *layout_list;
69 List<LayoutQualifierAST *> *layout_list;
75 ParameterDeclarationAST *param_declaration;
76 FunctionDeclarationAST *function_declaration;
79 Parser(Engine *engine,
const char *source,
unsigned size,
int variant);
82 TranslationUnitAST *parse() {
83 if (AST *u = parse(T_FEED_GLSL))
84 return u->asTranslationUnit();
88 ExpressionAST *parseExpression() {
89 if (AST *u = parse(T_FEED_EXPRESSION))
90 return u->asExpression();
94 AST *parse(
int startToken);
98 int &location(
int n) {
return _locationStack[_tos + n - 1]; }
99 Value &sym(
int n) {
return _symStack[_tos + n - 1]; }
100 AST *&ast(
int n) {
return _symStack[_tos + n - 1].ast; }
101 const QString *&string(
int n) {
return _symStack[_tos + n - 1].string; }
102 ExpressionAST *&expression(
int n) {
return _symStack[_tos + n - 1].expression; }
103 StatementAST *&statement(
int n) {
return _symStack[_tos + n - 1].statement; }
104 TypeAST *&type(
int n) {
return _symStack[_tos + n - 1].type; }
105 FunctionDeclarationAST *&function(
int n) {
return _symStack[_tos + n - 1].function_declaration; }
107 inline int consumeToken() {
108 if (_index <
int(_tokens.size()))
110 return static_cast<
int>(_tokens.size()) - 1;
112 inline const Token &tokenAt(
int index)
const {
115 return _tokens.at(index);
117 inline int tokenKind(
int index)
const {
119 return _startToken.kind;
120 return _tokens.at(index).kind;
122 void reduce(
int ruleno);
124 void warning(
int line,
const QString &message)
126 _engine->warning(line, message);
129 void error(
int line,
const QString &message)
131 _engine->error(line, message);
134 template <
typename T>
137 T *node =
new (_engine->pool()) T ();
138 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
142 template <
typename T,
typename A1>
143 T *makeAstNode(A1 a1)
145 T *node =
new (_engine->pool()) T (a1);
146 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
150 template <
typename T,
typename A1,
typename A2>
151 T *makeAstNode(A1 a1, A2 a2)
153 T *node =
new (_engine->pool()) T (a1, a2);
154 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
158 template <
typename T,
typename A1,
typename A2,
typename A3>
159 T *makeAstNode(A1 a1, A2 a2, A3 a3)
161 T *node =
new (_engine->pool()) T (a1, a2, a3);
162 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
166 template <
typename T,
typename A1,
typename A2,
typename A3,
typename A4>
167 T *makeAstNode(A1 a1, A2 a2, A3 a3, A4 a4)
169 T *node =
new (_engine->pool()) T (a1, a2, a3, a4);
170 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
174 TypeAST *makeBasicType(
int token)
176 TypeAST *type =
new (_engine->pool()) BasicTypeAST(token, spell[token]);
177 type->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
190 std::vector<
int> _stateStack;
191 std::vector<
int> _locationStack;
192 std::vector<Value> _symStack;
193 std::vector<Token> _tokens;
195Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(
int, GLSLParserTable::VariousConstants, Lexer::Variant)