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
4#ifndef QSSG_GLSLAST_H
5#define QSSG_GLSLAST_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/glsl_p.h>
19#include <QtQuick3DGlslParser/private/glslmemorypool_p.h>
20#include <qstring.h>
21
23
24namespace GLSL {
25
26class AST;
27class TranslationUnitAST;
28class ExpressionAST;
29class IdentifierExpressionAST;
30class LiteralExpressionAST;
31class BinaryExpressionAST;
32class UnaryExpressionAST;
33class TernaryExpressionAST;
34class AssignmentExpressionAST;
35class MemberAccessExpressionAST;
36class FunctionCallExpressionAST;
37class FunctionIdentifierAST;
38class DeclarationExpressionAST;
39class StatementAST;
40class ExpressionStatementAST;
41class CompoundStatementAST;
42class IfStatementAST;
43class WhileStatementAST;
44class DoStatementAST;
45class ForStatementAST;
46class JumpStatementAST;
47class ReturnStatementAST;
48class SwitchStatementAST;
49class CaseLabelStatementAST;
50class DeclarationStatementAST;
51class TypeAST;
52class BasicTypeAST;
53class NamedTypeAST;
54class ArrayTypeAST;
55class StructTypeAST;
56class LayoutQualifierAST;
57class QualifiedTypeAST;
58class DeclarationAST;
59class PrecisionDeclarationAST;
60class ParameterDeclarationAST;
61class VariableDeclarationAST;
62class TypeDeclarationAST;
63class TypeAndVariableDeclarationAST;
64class InvariantDeclarationAST;
65class InitDeclarationAST;
66class FunctionDeclarationAST;
67class Visitor;
68
69template <typename T>
70class Q_QUICK3DGLSLPARSER_EXPORT List: public Managed
71{
72public:
73 List(const T &value_)
74 : value(value_), next(this), lineno(0) {}
75
77 : value(value_), lineno(0)
78 {
80 previous->next = this;
81 }
82
84 {
85 List *head = next;
86 next = nullptr;
87 return head;
88 }
89
92 int lineno;
93};
94
95// Append two lists, which are assumed to still be circular, pre-finish.
96template <typename T>
98{
99 if (!first)
100 return second;
101 else if (!second)
102 return first;
107 return second;
108}
109
110class Q_QUICK3DGLSLPARSER_EXPORT AST: public Managed
111{
112public:
113 enum Kind {
115
116 // Translation unit
118
119 // Primary expressions
122
123 // Unary expressions
132
133 // Binary expressions
155
156 // Other expressions
163
164 // Assignment expressions
176
177 // Statements
193
194 // Types
204
205 // Declarations
214 };
215
216 virtual TranslationUnitAST *asTranslationUnit() { return nullptr; }
217
218 virtual ExpressionAST *asExpression() { return nullptr; }
219 virtual IdentifierExpressionAST *asIdentifierExpression() { return nullptr; }
220 virtual LiteralExpressionAST *asLiteralExpression() { return nullptr; }
221 virtual BinaryExpressionAST *asBinaryExpression() { return nullptr; }
222 virtual UnaryExpressionAST *asUnaryExpression() { return nullptr; }
223 virtual TernaryExpressionAST *asTernaryExpression() { return nullptr; }
224 virtual AssignmentExpressionAST *asAssignmentExpression() { return nullptr; }
227 virtual FunctionIdentifierAST *asFunctionIdentifier() { return nullptr; }
229
230 virtual StatementAST *asStatement() { return nullptr; }
231 virtual ExpressionStatementAST *asExpressionStatement() { return nullptr; }
232 virtual CompoundStatementAST *asCompoundStatement() { return nullptr; }
233 virtual IfStatementAST *asIfStatement() { return nullptr; }
234 virtual WhileStatementAST *asWhileStatement() { return nullptr; }
235 virtual DoStatementAST *asDoStatement() { return nullptr; }
236 virtual ForStatementAST *asForStatement() { return nullptr; }
237 virtual JumpStatementAST *asJumpStatement() { return nullptr; }
238 virtual ReturnStatementAST *asReturnStatement() { return nullptr; }
239 virtual SwitchStatementAST *asSwitchStatement() { return nullptr; }
240 virtual CaseLabelStatementAST *asCaseLabelStatement() { return nullptr; }
241 virtual DeclarationStatementAST *asDeclarationStatement() { return nullptr; }
242
243 virtual TypeAST *asType() { return nullptr; }
244 virtual BasicTypeAST *asBasicType() { return nullptr; }
245 virtual NamedTypeAST *asNamedType() { return nullptr; }
246 virtual ArrayTypeAST *asArrayType() { return nullptr; }
247 virtual StructTypeAST *asStructType() { return nullptr; }
248 virtual QualifiedTypeAST *asQualifiedType() { return nullptr; }
249 virtual LayoutQualifierAST *asLayoutQualifier() { return nullptr; }
250
251 virtual DeclarationAST *asDeclaration() { return nullptr; }
252 virtual PrecisionDeclarationAST *asPrecisionDeclaration() { return nullptr; }
253 virtual ParameterDeclarationAST *asParameterDeclaration() { return nullptr; }
254 virtual VariableDeclarationAST *asVariableDeclaration() { return nullptr; }
255 virtual TypeDeclarationAST *asTypeDeclaration() { return nullptr; }
257 virtual InvariantDeclarationAST *asInvariantDeclaration() { return nullptr; }
258 virtual InitDeclarationAST *asInitDeclaration() { return nullptr; }
259 virtual FunctionDeclarationAST *asFunctionDeclaration() { return nullptr; }
260
261 void accept(Visitor *visitor);
262 static void accept(AST *ast, Visitor *visitor);
263
264 template <typename T>
265 static void accept(List<T> *it, Visitor *visitor)
266 {
267 for (; it; it = it->next)
269 }
270
271 virtual void accept0(Visitor *visitor) = 0;
272
273protected:
275
276 template <typename T>
277 static List<T> *finish(List<T> *list)
278 {
279 if (! list)
280 return nullptr;
281 return list->finish(); // convert the circular list with a linked list.
282 }
283
284public: // attributes
285 int kind;
287
288protected:
289 ~AST() override {} // Managed types cannot be deleted.
290};
291
292class Q_QUICK3DGLSLPARSER_EXPORT TranslationUnitAST: public AST
293{
294public:
297
299
301
302public: // attributes
304};
305
306class Q_QUICK3DGLSLPARSER_EXPORT ExpressionAST: public AST
307{
308protected:
310
311public:
313};
314
315class Q_QUICK3DGLSLPARSER_EXPORT IdentifierExpressionAST: public ExpressionAST
316{
317public:
320
322
324
325public: // attributes
326 const QString *name;
327};
328
329class Q_QUICK3DGLSLPARSER_EXPORT LiteralExpressionAST: public ExpressionAST
330{
331public:
334
336
338
339public: // attributes
341};
342
343class Q_QUICK3DGLSLPARSER_EXPORT BinaryExpressionAST: public ExpressionAST
344{
345public:
348
350
352
353public: // attributes
356};
357
358class Q_QUICK3DGLSLPARSER_EXPORT UnaryExpressionAST: public ExpressionAST
359{
360public:
363
365
367
368public: // attributes
370};
371
387
402
403class Q_QUICK3DGLSLPARSER_EXPORT MemberAccessExpressionAST: public ExpressionAST
404{
405public:
408
410
412
413public: // attributes
416};
417
439
440class Q_QUICK3DGLSLPARSER_EXPORT FunctionIdentifierAST: public AST
441{
442public:
447
449
451
452public: // attributes
453 const QString *name;
455};
456
474
475class Q_QUICK3DGLSLPARSER_EXPORT StatementAST: public AST
476{
477protected:
479
480public:
482};
483
484class Q_QUICK3DGLSLPARSER_EXPORT ExpressionStatementAST: public StatementAST
485{
486public:
489
491
493
494public: // attributes
496};
497
498class Q_QUICK3DGLSLPARSER_EXPORT CompoundStatementAST: public StatementAST
499{
500public:
507
509
511
512public: // attributes
514 int start;
515 int end;
516 Block *symbol; // decoration
517};
518
535
536class Q_QUICK3DGLSLPARSER_EXPORT WhileStatementAST: public StatementAST
537{
538public:
541
543
545
546public: // attributes
549};
550
551class Q_QUICK3DGLSLPARSER_EXPORT DoStatementAST: public StatementAST
552{
553public:
556
558
560
561public: // attributes
564};
565
582
583class Q_QUICK3DGLSLPARSER_EXPORT JumpStatementAST: public StatementAST
584{
585public:
587
589
591};
592
593class Q_QUICK3DGLSLPARSER_EXPORT ReturnStatementAST: public StatementAST
594{
595public:
599
601
603
604public: // attributes
606};
607
608class Q_QUICK3DGLSLPARSER_EXPORT SwitchStatementAST: public StatementAST
609{
610public:
613
615
617
618public: // attributes
621};
622
623class Q_QUICK3DGLSLPARSER_EXPORT CaseLabelStatementAST: public StatementAST
624{
625public:
629
631
633
634public: // attributes
636};
637
638class Q_QUICK3DGLSLPARSER_EXPORT DeclarationStatementAST: public StatementAST
639{
640public:
643
645
647
648public: // attributes
650};
651
652class Q_QUICK3DGLSLPARSER_EXPORT TypeAST: public AST
653{
654protected:
656
657public:
659 {
660 PrecNotValid, // Precision not valid (e.g. structs).
661 PrecUnspecified, // Precision not known, but can be validly set.
664 Highp
665 };
666
667 TypeAST *asType() override { return this; }
668
669 virtual Precision precision() const = 0;
670
671 // Set the precision for the innermost basic type. Returns false if it
672 // is not valid to set a precision (e.g. structs).
674};
675
676class Q_QUICK3DGLSLPARSER_EXPORT BasicTypeAST: public TypeAST
677{
678public:
679 // Pass the parser's token code: T_VOID, T_VEC4, etc.
680 BasicTypeAST(int _token, const char *_name);
681
683
685
688
689public: // attributes
691 int token;
692 const char *name;
693};
694
695class Q_QUICK3DGLSLPARSER_EXPORT NamedTypeAST: public TypeAST
696{
697public:
699
701
703
706
707public: // attributes
708 const QString *name;
709};
710
730
731class Q_QUICK3DGLSLPARSER_EXPORT StructTypeAST: public TypeAST
732{
733public:
734 class Field: public AST
735 {
736 public:
738 : AST(Kind_StructField), name(_name), type(nullptr) {}
739
740 // Takes the outer shell of an array type with the innermost
741 // element type set to null. The fixInnerTypes() function will
742 // set the innermost element type to a meaningful value.
745
747
749
750 const QString *name;
752 };
753
758
760
762
765
766 // Fix the inner types of a field list. The "innerType" will
767 // be copied into the "array holes" of all fields.
769
770public: // attributes
771 const QString *name;
773};
774
775class Q_QUICK3DGLSLPARSER_EXPORT LayoutQualifierAST: public AST
776{
777public:
780
783
784public: // attributes
785 const QString *name;
787};
788
789class Q_QUICK3DGLSLPARSER_EXPORT QualifiedTypeAST: public TypeAST
790{
791public:
795
796 enum
797 {
798 StorageMask = 0x000000FF,
799 NoStorage = 0x00000000,
800 Const = 0x00000001,
801 Attribute = 0x00000002,
802 Varying = 0x00000003,
803 CentroidVarying = 0x00000004,
804 In = 0x00000005,
805 Out = 0x00000006,
806 CentroidIn = 0x00000007,
807 CentroidOut = 0x00000008,
808 PatchIn = 0x00000009,
809 PatchOut = 0x0000000A,
810 SampleIn = 0x0000000B,
811 SampleOut = 0x0000000C,
812 Uniform = 0x0000000D,
813 InterpolationMask = 0x00000F00,
814 NoInterpolation = 0x00000000,
815 Smooth = 0x00000100,
816 Flat = 0x00000200,
817 NoPerspective = 0x00000300,
818 Invariant = 0x00010000,
819 Struct = 0x00020000
820 };
821
823
825
828
829public: // attributes
833};
834
835class Q_QUICK3DGLSLPARSER_EXPORT DeclarationAST: public AST
836{
837protected:
839
840public:
842};
843
859
883
903
904class Q_QUICK3DGLSLPARSER_EXPORT TypeDeclarationAST: public DeclarationAST
905{
906public:
909
911
913
914public: // attributes
916};
917
934
935class Q_QUICK3DGLSLPARSER_EXPORT InvariantDeclarationAST: public DeclarationAST
936{
937public:
940
942
944
945public: // attributes
946 const QString *name;
947};
948
949class Q_QUICK3DGLSLPARSER_EXPORT InitDeclarationAST: public DeclarationAST
950{
951public:
954
956
958
959public: // attributes
961};
962
963class Q_QUICK3DGLSLPARSER_EXPORT FunctionDeclarationAST : public DeclarationAST
964{
965public:
969
971
973
975
976 bool isPrototype() const { return body == nullptr; }
977
978public: // attributes
980 const QString *name;
983};
984
985} // namespace GLSL
986
987QT_END_NAMESPACE
988
989#endif // QSSG_GLSLAST_H
List< T > * appendLists(List< T > *first, List< T > *second)
Definition glslast_p.h:97
Combined button and popup list for selecting options.