Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QSSG_GLSLPARSER_H
5#define QSSG_GLSLPARSER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick3DGlslParser/private/glsllexer_p.h>
19#include <QtQuick3DGlslParser/private/glslast_p.h>
20#include <QtQuick3DGlslParser/private/glslengine_p.h>
21#include <QtQuick3DGlslParser/private/glslparsertable_p.h>
22#include <vector>
23#include <stack>
24
26
27namespace GLSL {
28
29class Q_QUICK3DGLSLPARSER_EXPORT Parser: public GLSLParserTable
30{
31public:
32 union Value {
33 void *ptr;
36 List<AST *> *ast_list;
38 List<DeclarationAST *> *declaration_list;
40 List<ExpressionAST *> *expression_list;
42 List<StatementAST *> *statement_list;
45 List<StructTypeAST::Field *> *field_list;
50 struct {
53 } ifstmt;
54 struct {
57 } forstmt;
58 struct {
60 List<ExpressionAST *> *arguments;
64 List<LayoutQualifierAST *> *layout_list;
65 struct {
66 int qualifier;
67 List<LayoutQualifierAST *> *layout_list;
68 } type_qualifier;
69 struct {
71 const QString *name;
72 } param_declarator;
75 };
76
77 Parser(Engine *engine, const char *source, unsigned size, int variant);
78 ~Parser();
79
81 if (AST *u = parse(T_FEED_GLSL))
82 return u->asTranslationUnit();
83 return nullptr;
84 }
85
87 if (AST *u = parse(T_FEED_EXPRESSION))
88 return u->asExpression();
89 return nullptr;
90 }
91
92 AST *parse(int startToken);
93
94private:
95 // 1-based
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; }
104
105 inline int consumeToken() {
106 if (_index < int(_tokens.size()))
107 return _index++;
108 return static_cast<int>(_tokens.size()) - 1;
109 }
110 inline const Token &tokenAt(int index) const {
111 if (index == 0)
112 return _startToken;
113 return _tokens.at(index);
114 }
115 inline int tokenKind(int index) const {
116 if (index == 0)
117 return _startToken.kind;
118 return _tokens.at(index).kind;
119 }
120 void reduce(int ruleno);
121
122 void warning(int line, const QString &message)
123 {
124 _engine->warning(line, message);
125 }
126
127 void error(int line, const QString &message)
128 {
129 _engine->error(line, message);
130 }
131
132 template <typename T>
133 T *makeAstNode()
134 {
135 T *node = new (_engine->pool()) T ();
136 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
137 return node;
138 }
139
140 template <typename T, typename A1>
141 T *makeAstNode(A1 a1)
142 {
143 T *node = new (_engine->pool()) T (a1);
144 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
145 return node;
146 }
147
148 template <typename T, typename A1, typename A2>
149 T *makeAstNode(A1 a1, A2 a2)
150 {
151 T *node = new (_engine->pool()) T (a1, a2);
152 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
153 return node;
154 }
155
156 template <typename T, typename A1, typename A2, typename A3>
157 T *makeAstNode(A1 a1, A2 a2, A3 a3)
158 {
159 T *node = new (_engine->pool()) T (a1, a2, a3);
160 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
161 return node;
162 }
163
164 template <typename T, typename A1, typename A2, typename A3, typename A4>
165 T *makeAstNode(A1 a1, A2 a2, A3 a3, A4 a4)
166 {
167 T *node = new (_engine->pool()) T (a1, a2, a3, a4);
168 node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
169 return node;
170 }
171
172 TypeAST *makeBasicType(int token)
173 {
174 TypeAST *type = new (_engine->pool()) BasicTypeAST(token, spell[token]);
175 type->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
176 return type;
177 }
178
179private:
180 Engine *_engine;
181 int _tos;
182 int _index;
183 int yyloc;
184 int yytoken;
185 int yyrecovering;
186 bool _recovered;
187 Token _startToken;
188 std::vector<int> _stateStack;
189 std::vector<int> _locationStack;
190 std::vector<Value> _symStack;
191 std::vector<Token> _tokens;
192};
194} // namespace GLSL
195
197
198#endif // QSSG_GLSLPARSER_H
ExpressionAST * asExpression() override
Definition glslast_p.h:312
ExpressionAST * parseExpression()
TranslationUnitAST * parse()
TranslationUnitAST * asTranslationUnit() override
Definition glslast_p.h:298
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Token token
Definition keywords.cpp:444
Definition glsl_p.h:22
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
DBusConnection const char DBusError * error
#define Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(Ret, Flags, Enum)
Definition qflags.h:247
GLint location
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLenum type
GLuint GLsizei const GLchar * message
GLfloat n
GLsizei GLsizei GLchar * source
GLsizei const GLchar *const * string
[0]
Definition qopenglext.h:694
QDebug warning(QAnyStringView fileName, int lineNumber)
#define a3
#define a2
#define a1
QVariant variant
[1]
QJSEngine engine
[0]
FunctionDeclarationAST * function_declaration
List< ExpressionAST * > * arguments
List< ExpressionAST * > * expression_list
const QString * name
ExpressionAST * expression
FunctionIdentifierAST * function_identifier
StatementAST * thenClause
List< DeclarationAST * > * declaration_list
FunctionIdentifierAST * id
StatementAST * elseClause
ParameterDeclarationAST * param_declaration
ExpressionAST * increment
List< StructTypeAST::Field * > * field_list
StatementAST * statement
List< StatementAST * > * statement_list
TranslationUnitAST * translation_unit
const QString * string
ExpressionAST * condition
List< LayoutQualifierAST * > * layout_list
List< AST * > * ast_list
DeclarationAST * declaration
LayoutQualifierAST * layout
TypeAST::Precision precision
StructTypeAST::Field * field