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
glslast_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_GLSLAST_H
7#define QSSG_GLSLAST_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/glsl_p.h>
21#include <QtQuick3DGlslParser/private/glslmemorypool_p.h>
22#include <qstring.h>
23
25
26namespace GLSL {
27
28class AST;
29class TranslationUnitAST;
30class ExpressionAST;
31class IdentifierExpressionAST;
32class LiteralExpressionAST;
33class BinaryExpressionAST;
34class UnaryExpressionAST;
35class TernaryExpressionAST;
36class AssignmentExpressionAST;
37class MemberAccessExpressionAST;
38class FunctionCallExpressionAST;
39class FunctionIdentifierAST;
40class DeclarationExpressionAST;
41class StatementAST;
42class ExpressionStatementAST;
43class CompoundStatementAST;
44class IfStatementAST;
45class WhileStatementAST;
46class DoStatementAST;
47class ForStatementAST;
48class JumpStatementAST;
49class ReturnStatementAST;
50class SwitchStatementAST;
51class CaseLabelStatementAST;
52class DeclarationStatementAST;
53class TypeAST;
54class BasicTypeAST;
55class NamedTypeAST;
56class ArrayTypeAST;
57class StructTypeAST;
58class LayoutQualifierAST;
59class QualifiedTypeAST;
60class DeclarationAST;
61class PrecisionDeclarationAST;
62class ParameterDeclarationAST;
63class VariableDeclarationAST;
64class TypeDeclarationAST;
65class TypeAndVariableDeclarationAST;
66class InvariantDeclarationAST;
67class InitDeclarationAST;
68class FunctionDeclarationAST;
69class Visitor;
70
71template <typename T>
72class Q_QUICK3DGLSLPARSER_EXPORT List: public Managed
73{
74public:
75 List(const T &value_)
76 : value(value_), next(this), lineno(0) {}
77
79 : value(value_), lineno(0)
80 {
82 previous->next = this;
83 }
84
86 {
87 List *head = next;
88 next = nullptr;
89 return head;
90 }
91
94 int lineno;
95};
96
97// Append two lists, which are assumed to still be circular, pre-finish.
98template <typename T>
100{
101 if (!first)
102 return second;
103 else if (!second)
104 return first;
109 return second;
110}
111
112class Q_QUICK3DGLSLPARSER_EXPORT AST: public Managed
113{
114public:
115 enum Kind {
117
118 // Translation unit
120
121 // Primary expressions
124
125 // Unary expressions
134
135 // Binary expressions
157
158 // Other expressions
165
166 // Assignment expressions
178
179 // Statements
195
196 // Types
206
207 // Declarations
216 };
217
218 virtual TranslationUnitAST *asTranslationUnit() { return nullptr; }
219
220 virtual ExpressionAST *asExpression() { return nullptr; }
221 virtual IdentifierExpressionAST *asIdentifierExpression() { return nullptr; }
222 virtual LiteralExpressionAST *asLiteralExpression() { return nullptr; }
223 virtual BinaryExpressionAST *asBinaryExpression() { return nullptr; }
224 virtual UnaryExpressionAST *asUnaryExpression() { return nullptr; }
225 virtual TernaryExpressionAST *asTernaryExpression() { return nullptr; }
226 virtual AssignmentExpressionAST *asAssignmentExpression() { return nullptr; }
229 virtual FunctionIdentifierAST *asFunctionIdentifier() { return nullptr; }
231
232 virtual StatementAST *asStatement() { return nullptr; }
233 virtual ExpressionStatementAST *asExpressionStatement() { return nullptr; }
234 virtual CompoundStatementAST *asCompoundStatement() { return nullptr; }
235 virtual IfStatementAST *asIfStatement() { return nullptr; }
236 virtual WhileStatementAST *asWhileStatement() { return nullptr; }
237 virtual DoStatementAST *asDoStatement() { return nullptr; }
238 virtual ForStatementAST *asForStatement() { return nullptr; }
239 virtual JumpStatementAST *asJumpStatement() { return nullptr; }
240 virtual ReturnStatementAST *asReturnStatement() { return nullptr; }
241 virtual SwitchStatementAST *asSwitchStatement() { return nullptr; }
242 virtual CaseLabelStatementAST *asCaseLabelStatement() { return nullptr; }
243 virtual DeclarationStatementAST *asDeclarationStatement() { return nullptr; }
244
245 virtual TypeAST *asType() { return nullptr; }
246 virtual BasicTypeAST *asBasicType() { return nullptr; }
247 virtual NamedTypeAST *asNamedType() { return nullptr; }
248 virtual ArrayTypeAST *asArrayType() { return nullptr; }
249 virtual StructTypeAST *asStructType() { return nullptr; }
250 virtual QualifiedTypeAST *asQualifiedType() { return nullptr; }
251 virtual LayoutQualifierAST *asLayoutQualifier() { return nullptr; }
252
253 virtual DeclarationAST *asDeclaration() { return nullptr; }
254 virtual PrecisionDeclarationAST *asPrecisionDeclaration() { return nullptr; }
255 virtual ParameterDeclarationAST *asParameterDeclaration() { return nullptr; }
256 virtual VariableDeclarationAST *asVariableDeclaration() { return nullptr; }
257 virtual TypeDeclarationAST *asTypeDeclaration() { return nullptr; }
259 virtual InvariantDeclarationAST *asInvariantDeclaration() { return nullptr; }
260 virtual InitDeclarationAST *asInitDeclaration() { return nullptr; }
261 virtual FunctionDeclarationAST *asFunctionDeclaration() { return nullptr; }
262
263 void accept(Visitor *visitor);
264 static void accept(AST *ast, Visitor *visitor);
265
266 template <typename T>
267 static void accept(List<T> *it, Visitor *visitor)
268 {
269 for (; it; it = it->next)
271 }
272
273 virtual void accept0(Visitor *visitor) = 0;
274
275protected:
277
278 template <typename T>
279 static List<T> *finish(List<T> *list)
280 {
281 if (! list)
282 return nullptr;
283 return list->finish(); // convert the circular list with a linked list.
284 }
285
286public: // attributes
287 int kind;
289
290protected:
291 ~AST() override {} // Managed types cannot be deleted.
292};
293
294class Q_QUICK3DGLSLPARSER_EXPORT TranslationUnitAST: public AST
295{
296public:
299
301
303
304public: // attributes
306};
307
308class Q_QUICK3DGLSLPARSER_EXPORT ExpressionAST: public AST
309{
310protected:
312
313public:
315};
316
317class Q_QUICK3DGLSLPARSER_EXPORT IdentifierExpressionAST: public ExpressionAST
318{
319public:
322
324
326
327public: // attributes
328 const QString *name;
329};
330
331class Q_QUICK3DGLSLPARSER_EXPORT LiteralExpressionAST: public ExpressionAST
332{
333public:
336
338
340
341public: // attributes
343};
344
345class Q_QUICK3DGLSLPARSER_EXPORT BinaryExpressionAST: public ExpressionAST
346{
347public:
350
352
354
355public: // attributes
358};
359
360class Q_QUICK3DGLSLPARSER_EXPORT UnaryExpressionAST: public ExpressionAST
361{
362public:
365
367
369
370public: // attributes
372};
373
389
404
405class Q_QUICK3DGLSLPARSER_EXPORT MemberAccessExpressionAST: public ExpressionAST
406{
407public:
410
412
414
415public: // attributes
418};
419
441
442class Q_QUICK3DGLSLPARSER_EXPORT FunctionIdentifierAST: public AST
443{
444public:
449
451
453
454public: // attributes
455 const QString *name;
457};
458
476
477class Q_QUICK3DGLSLPARSER_EXPORT StatementAST: public AST
478{
479protected:
481
482public:
484};
485
486class Q_QUICK3DGLSLPARSER_EXPORT ExpressionStatementAST: public StatementAST
487{
488public:
491
493
495
496public: // attributes
498};
499
500class Q_QUICK3DGLSLPARSER_EXPORT CompoundStatementAST: public StatementAST
501{
502public:
509
511
513
514public: // attributes
516 int start;
517 int end;
518 Block *symbol; // decoration
519};
520
537
538class Q_QUICK3DGLSLPARSER_EXPORT WhileStatementAST: public StatementAST
539{
540public:
543
545
547
548public: // attributes
551};
552
553class Q_QUICK3DGLSLPARSER_EXPORT DoStatementAST: public StatementAST
554{
555public:
558
560
562
563public: // attributes
566};
567
584
585class Q_QUICK3DGLSLPARSER_EXPORT JumpStatementAST: public StatementAST
586{
587public:
589
591
593};
594
595class Q_QUICK3DGLSLPARSER_EXPORT ReturnStatementAST: public StatementAST
596{
597public:
601
603
605
606public: // attributes
608};
609
610class Q_QUICK3DGLSLPARSER_EXPORT SwitchStatementAST: public StatementAST
611{
612public:
615
617
619
620public: // attributes
623};
624
625class Q_QUICK3DGLSLPARSER_EXPORT CaseLabelStatementAST: public StatementAST
626{
627public:
631
633
635
636public: // attributes
638};
639
640class Q_QUICK3DGLSLPARSER_EXPORT DeclarationStatementAST: public StatementAST
641{
642public:
645
647
649
650public: // attributes
652};
653
654class Q_QUICK3DGLSLPARSER_EXPORT TypeAST: public AST
655{
656protected:
658
659public:
661 {
662 PrecNotValid, // Precision not valid (e.g. structs).
663 PrecUnspecified, // Precision not known, but can be validly set.
667 };
668
669 TypeAST *asType() override { return this; }
670
671 virtual Precision precision() const = 0;
672
673 // Set the precision for the innermost basic type. Returns false if it
674 // is not valid to set a precision (e.g. structs).
676};
677
678class Q_QUICK3DGLSLPARSER_EXPORT BasicTypeAST: public TypeAST
679{
680public:
681 // Pass the parser's token code: T_VOID, T_VEC4, etc.
682 BasicTypeAST(int _token, const char *_name);
683
685
687
690
691public: // attributes
693 int token;
694 const char *name;
695};
696
697class Q_QUICK3DGLSLPARSER_EXPORT NamedTypeAST: public TypeAST
698{
699public:
701
703
705
708
709public: // attributes
710 const QString *name;
711};
712
732
733class Q_QUICK3DGLSLPARSER_EXPORT StructTypeAST: public TypeAST
734{
735public:
736 class Field: public AST
737 {
738 public:
740 : AST(Kind_StructField), name(_name), type(nullptr) {}
741
742 // Takes the outer shell of an array type with the innermost
743 // element type set to null. The fixInnerTypes() function will
744 // set the innermost element type to a meaningful value.
747
749
751
752 const QString *name;
754 };
755
760
762
764
767
768 // Fix the inner types of a field list. The "innerType" will
769 // be copied into the "array holes" of all fields.
771
772public: // attributes
773 const QString *name;
775};
776
777class Q_QUICK3DGLSLPARSER_EXPORT LayoutQualifierAST: public AST
778{
779public:
782
785
786public: // attributes
787 const QString *name;
789};
790
791class Q_QUICK3DGLSLPARSER_EXPORT QualifiedTypeAST: public TypeAST
792{
793public:
797
798 enum
799 {
800 StorageMask = 0x000000FF,
801 NoStorage = 0x00000000,
802 Const = 0x00000001,
803 Attribute = 0x00000002,
804 Varying = 0x00000003,
805 CentroidVarying = 0x00000004,
806 In = 0x00000005,
807 Out = 0x00000006,
808 CentroidIn = 0x00000007,
809 CentroidOut = 0x00000008,
810 PatchIn = 0x00000009,
811 PatchOut = 0x0000000A,
812 SampleIn = 0x0000000B,
813 SampleOut = 0x0000000C,
814 Uniform = 0x0000000D,
815 InterpolationMask = 0x00000F00,
816 NoInterpolation = 0x00000000,
817 Smooth = 0x00000100,
818 Flat = 0x00000200,
819 NoPerspective = 0x00000300,
820 Invariant = 0x00010000,
821 Struct = 0x00020000
822 };
823
825
827
830
831public: // attributes
835};
836
837class Q_QUICK3DGLSLPARSER_EXPORT DeclarationAST: public AST
838{
839protected:
841
842public:
844};
845
861
885
905
906class Q_QUICK3DGLSLPARSER_EXPORT TypeDeclarationAST: public DeclarationAST
907{
908public:
911
913
915
916public: // attributes
918};
919
936
937class Q_QUICK3DGLSLPARSER_EXPORT InvariantDeclarationAST: public DeclarationAST
938{
939public:
942
944
946
947public: // attributes
948 const QString *name;
949};
950
951class Q_QUICK3DGLSLPARSER_EXPORT InitDeclarationAST: public DeclarationAST
952{
953public:
956
958
960
961public: // attributes
963};
964
965class Q_QUICK3DGLSLPARSER_EXPORT FunctionDeclarationAST : public DeclarationAST
966{
967public:
971
973
975
977
978 bool isPrototype() const { return body == nullptr; }
979
980public: // attributes
982 const QString *name;
985};
986
987} // namespace GLSL
988
989QT_END_NAMESPACE
990
991#endif // QSSG_GLSLAST_H
Combined button and popup list for selecting options.