Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
glslparser_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
6#ifndef QSSG_GLSLPARSER_H
7#define QSSG_GLSLPARSER_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtQuick3DGlslParser/private/glsllexer_p.h>
21#include <QtQuick3DGlslParser/private/glslast_p.h>
22#include <QtQuick3DGlslParser/private/glslengine_p.h>
23#include <QtQuick3DGlslParser/private/glslparsertable_p.h>
24#include <vector>
25#include <stack>
26
27QT_BEGIN_NAMESPACE
28
29namespace GLSL {
30
31class Q_QUICK3DGLSLPARSER_EXPORT Parser: public GLSLParserTable
32{
33public:
34 union Value {
35 void *ptr;
36 const QString *string;
37 AST *ast;
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;
45 TypeAST *type;
46 StructTypeAST::Field *field;
47 List<StructTypeAST::Field *> *field_list;
48 TranslationUnitAST *translation_unit;
49 FunctionIdentifierAST *function_identifier;
50 AST::Kind kind;
51 TypeAST::Precision precision;
52 struct {
53 StatementAST *thenClause;
54 StatementAST *elseClause;
55 } ifstmt;
56 struct {
57 ExpressionAST *condition;
58 ExpressionAST *increment;
59 } forstmt;
60 struct {
61 FunctionIdentifierAST *id;
62 List<ExpressionAST *> *arguments;
63 } function;
64 int qualifier;
65 LayoutQualifierAST *layout;
66 List<LayoutQualifierAST *> *layout_list;
67 struct {
68 int qualifier;
69 List<LayoutQualifierAST *> *layout_list;
70 } type_qualifier;
71 struct {
72 TypeAST *type;
73 const QString *name;
74 } param_declarator;
75 ParameterDeclarationAST *param_declaration;
76 FunctionDeclarationAST *function_declaration;
77 };
78
79 Parser(Engine *engine, const char *source, unsigned size, int variant);
80 ~Parser();
81
82 TranslationUnitAST *parse() {
83 if (AST *u = parse(T_FEED_GLSL))
84 return u->asTranslationUnit();
85 return nullptr;
86 }
87
88 ExpressionAST *parseExpression() {
89 if (AST *u = parse(T_FEED_EXPRESSION))
90 return u->asExpression();
91 return nullptr;
92 }
93
94 AST *parse(int startToken);
95
96private:
97 // 1-based
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; }
106
107 inline int consumeToken() {
108 if (_index < int(_tokens.size()))
109 return _index++;
110 return static_cast<int>(_tokens.size()) - 1;
111 }
112 inline const Token &tokenAt(int index) const {
113 if (index == 0)
114 return _startToken;
115 return _tokens.at(index);
116 }
117 inline int tokenKind(int index) const {
118 if (index == 0)
119 return _startToken.kind;
120 return _tokens.at(index).kind;
121 }
122 void reduce(int ruleno);
123
124 void warning(int line, const QString &message)
125 {
126 _engine->warning(line, message);
127 }
128
129 void error(int line, const QString &message)
130 {
131 _engine->error(line, message);
132 }
133
134 template <typename T>
135 T *makeAstNode()
136 {
137 T *node = new (_engine->pool()) T ();
138 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
139 return node;
140 }
141
142 template <typename T, typename A1>
143 T *makeAstNode(A1 a1)
144 {
145 T *node = new (_engine->pool()) T (a1);
146 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
147 return node;
148 }
149
150 template <typename T, typename A1, typename A2>
151 T *makeAstNode(A1 a1, A2 a2)
152 {
153 T *node = new (_engine->pool()) T (a1, a2);
154 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
155 return node;
156 }
157
158 template <typename T, typename A1, typename A2, typename A3>
159 T *makeAstNode(A1 a1, A2 a2, A3 a3)
160 {
161 T *node = new (_engine->pool()) T (a1, a2, a3);
162 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
163 return node;
164 }
165
166 template <typename T, typename A1, typename A2, typename A3, typename A4>
167 T *makeAstNode(A1 a1, A2 a2, A3 a3, A4 a4)
168 {
169 T *node = new (_engine->pool()) T (a1, a2, a3, a4);
170 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
171 return node;
172 }
173
174 TypeAST *makeBasicType(int token)
175 {
176 TypeAST *type = new (_engine->pool()) BasicTypeAST(token, spell[token]);
177 type->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
178 return type;
179 }
180
181private:
182 Engine *_engine;
183 int _tos;
184 int _index;
185 int yyloc;
186 int yytoken;
187 int yyrecovering;
188 bool _recovered;
189 Token _startToken;
190 std::vector<int> _stateStack;
191 std::vector<int> _locationStack;
192 std::vector<Value> _symStack;
193 std::vector<Token> _tokens;
194};
195Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(int, GLSLParserTable::VariousConstants, Lexer::Variant)
196} // namespace GLSL
197
198QT_END_NAMESPACE
199
200#endif // QSSG_GLSLPARSER_H
const Type * intern(const Type &ty)
Combined button and popup list for selecting options.
bool operator()(const Type &value, const Type &other) const