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
glsltypes_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_GLSLTYPES_H
7#define QSSG_GLSLTYPES_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/glsltype_p.h>
21#include <QtQuick3DGlslParser/private/glslsymbol_p.h>
22#include <QVector>
23#include <QHash>
24#include <QString>
25#include <QStringList>
26
28
29namespace GLSL {
30
31class Q_QUICK3DGLSLPARSER_EXPORT ScalarType: public Type
32{
33public:
34 const ScalarType *asScalarType() const override { return this; }
35};
36
37class Q_QUICK3DGLSLPARSER_EXPORT UndefinedType: public Type
38{
39public:
40 QString toString() const override { return QLatin1String("undefined"); }
41 const UndefinedType *asUndefinedType() const override { return this; }
42 bool isEqualTo(const Type *other) const override;
43 bool isLessThan(const Type *other) const override;
44};
45
46class Q_QUICK3DGLSLPARSER_EXPORT VoidType: public Type
47{
48public:
49 QString toString() const override { return QLatin1String("void"); }
50 const VoidType *asVoidType() const override { return this; }
51 bool isEqualTo(const Type *other) const override;
52 bool isLessThan(const Type *other) const override;
53};
54
55class Q_QUICK3DGLSLPARSER_EXPORT BoolType: public ScalarType
56{
57public:
58 QString toString() const override { return QLatin1String("bool"); }
59 const BoolType *asBoolType() const override { return this; }
60 bool isEqualTo(const Type *other) const override;
61 bool isLessThan(const Type *other) const override;
62};
63
64class Q_QUICK3DGLSLPARSER_EXPORT IntType: public ScalarType
65{
66public:
67 QString toString() const override { return QLatin1String("int"); }
68 const IntType *asIntType() const override { return this; }
69 bool isEqualTo(const Type *other) const override;
70 bool isLessThan(const Type *other) const override;
71};
72
73class Q_QUICK3DGLSLPARSER_EXPORT UIntType: public ScalarType
74{
75public:
76 QString toString() const override { return QLatin1String("uint"); }
77 const UIntType *asUIntType() const override { return this; }
78 bool isEqualTo(const Type *other) const override;
79 bool isLessThan(const Type *other) const override;
80};
81
82class Q_QUICK3DGLSLPARSER_EXPORT FloatType: public ScalarType
83{
84public:
85 QString toString() const override { return QLatin1String("float"); }
86 const FloatType *asFloatType() const override { return this; }
87 bool isEqualTo(const Type *other) const override;
88 bool isLessThan(const Type *other) const override;
89};
90
91class Q_QUICK3DGLSLPARSER_EXPORT DoubleType: public ScalarType
92{
93public:
94 QString toString() const override { return QLatin1String("double"); }
95 const DoubleType *asDoubleType() const override { return this; }
96 bool isEqualTo(const Type *other) const override;
97 bool isLessThan(const Type *other) const override;
98};
99
100// Type that can be indexed with the [] operator.
101class Q_QUICK3DGLSLPARSER_EXPORT IndexType: public Type
102{
103public:
105
106 const Type *indexElementType() const { return _indexElementType; }
107
108 const IndexType *asIndexType() const override { return this; }
109
110private:
111 const Type *_indexElementType;
112};
113
114class Q_QUICK3DGLSLPARSER_EXPORT VectorType: public IndexType, public Scope
115{
116public:
119
120 QString toString() const override;
121 const Type *elementType() const { return indexElementType(); }
122 int dimension() const { return _dimension; }
123
124 QList<Symbol *> members() const override { return _members.values(); }
125
126 void add(Symbol *symbol) override;
127 Symbol *find(const QString &name) const override;
128 const Type *type() const override { return this; }
129
130 const VectorType *asVectorType() const override { return this; }
131 bool isEqualTo(const Type *other) const override;
132 bool isLessThan(const Type *other) const override;
133
134private:
135 int _dimension;
137
138 friend class Engine;
139
141 void populateMembers(Engine *engine, const char *components);
142};
143
144class Q_QUICK3DGLSLPARSER_EXPORT MatrixType: public IndexType
145{
146public:
149
150 const Type *elementType() const { return _elementType; }
151 const Type *columnType() const { return indexElementType(); }
152 int columns() const { return _columns; }
153 int rows() const { return _rows; }
154
155 QString toString() const override;
156 const MatrixType *asMatrixType() const override { return this; }
157 bool isEqualTo(const Type *other) const override;
158 bool isLessThan(const Type *other) const override;
159
160private:
161 const Type *_elementType;
162 int _columns;
163 int _rows;
164};
165
166class Q_QUICK3DGLSLPARSER_EXPORT ArrayType: public IndexType
167{
168public:
169 explicit ArrayType(const Type *elementType)
171
172 const Type *elementType() const { return indexElementType(); }
173
174 QString toString() const override;
175 const ArrayType *asArrayType() const override { return this; }
176 bool isEqualTo(const Type *other) const override;
177 bool isLessThan(const Type *other) const override;
178};
179
180class Q_QUICK3DGLSLPARSER_EXPORT Struct: public Type, public Scope
181{
182public:
183 Struct(Scope *scope = nullptr)
184 : Scope(scope) {}
185
186 QList<Symbol *> members() const override;
187 void add(Symbol *member) override;
188 Symbol *find(const QString &name) const override;
189
190 // as Type
191 QString toString() const override { return name(); }
192 const Struct *asStructType() const override { return this; }
193 bool isEqualTo(const Type *other) const override;
194 bool isLessThan(const Type *other) const override;
195
196 // as Symbol
197 Struct *asStruct() override { return this; } // as Symbol
198 const Type *type() const override { return this; }
199
200private:
202};
203
204class Q_QUICK3DGLSLPARSER_EXPORT Function: public Type, public Scope
205{
206public:
207 Function(Scope *scope = nullptr)
208 : Scope(scope) {}
209
210 const Type *returnType() const;
211 void setReturnType(const Type *returnType);
212
213 QVector<Argument *> arguments() const;
214 void addArgument(Argument *arg);
215 int argumentCount() const;
216 Argument *argumentAt(int index) const;
217
218 // as Type
219 QString prettyPrint() const;
220 QString toString() const override;
221 const Function *asFunctionType() const override { return this; }
222 bool isEqualTo(const Type *other) const override;
223 bool isLessThan(const Type *other) const override;
224
225 // as Symbol
226 Function *asFunction() override { return this; }
227 const Type *type() const override { return this; }
228
229 Symbol *find(const QString &name) const override;
230
231 QList<Symbol *> members() const override;
233 if (! symbol)
234 return;
235 else if (Argument *arg = symbol->asArgument())
237 }
238
239private:
240 const Type *_returnType;
242};
243
244class Q_QUICK3DGLSLPARSER_EXPORT SamplerType: public Type
245{
246public:
247 explicit SamplerType(int kind) : _kind(kind) {}
248
249 // Kind of sampler as a token code; e.g. T_SAMPLER2D.
250 int kind() const { return _kind; }
251
252 QString toString() const override;
253 const SamplerType *asSamplerType() const override { return this; }
254 bool isEqualTo(const Type *other) const override;
255 bool isLessThan(const Type *other) const override;
256
257private:
258 int _kind;
259};
260
261class Q_QUICK3DGLSLPARSER_EXPORT OverloadSet: public Type, public Scope
262{
263public:
264 OverloadSet(Scope *enclosingScope = nullptr);
265
266 QVector<Function *> functions() const;
268
269 // as symbol
271 const Type *type() const override;
272 Symbol *find(const QString &name) const override;
273 void add(Symbol *symbol) override;
274
275 // as type
276 QString toString() const override { return QLatin1String("overload"); }
277 const OverloadSet *asOverloadSetType() const override { return this; }
278 bool isEqualTo(const Type *other) const override;
279 bool isLessThan(const Type *other) const override;
280
281private:
283};
284
285} // namespace GLSL
286
287QT_END_NAMESPACE
288
289#endif // QSSG_GLSLTYPES_H
const Type * intern(const Type &ty)
Combined button and popup list for selecting options.
bool operator()(const Type &value, const Type &other) const