1 | // Copyright (C) 2021 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QSSG_GLSLSEMANTIC_H |
5 | #define QSSG_GLSLSEMANTIC_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/glslastvisitor_p.h> |
19 | #include <QtQuick3DGlslParser/private/glsltype_p.h> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | namespace GLSL { |
24 | |
25 | class Q_QUICK3DGLSLPARSER_EXPORT Semantic: protected Visitor |
26 | { |
27 | public: |
28 | Semantic(); |
29 | ~Semantic() override; |
30 | |
31 | struct ExprResult { |
32 | ExprResult(const Type *type_ = nullptr, bool isConstant_ = false) |
33 | : type(type_), isConstant(isConstant_) {} |
34 | |
35 | ~ExprResult() { } |
36 | |
37 | bool isValid() const { |
38 | if (! type) |
39 | return false; |
40 | else if (type->asUndefinedType() != nullptr) |
41 | return false; |
42 | return true; |
43 | } |
44 | |
45 | explicit operator bool() const { return isValid(); } |
46 | |
47 | const Type *type; |
48 | bool isConstant; |
49 | }; |
50 | |
51 | void translationUnit(TranslationUnitAST *ast, Scope *globalScope, Engine *engine); |
52 | ExprResult expression(ExpressionAST *ast, Scope *scope, Engine *engine); |
53 | |
54 | protected: |
55 | Engine *switchEngine(Engine *engine); |
56 | Scope *switchScope(Scope *scope); |
57 | |
58 | bool implicitCast(const Type *type, const Type *target) const; |
59 | |
60 | ExprResult expression(ExpressionAST *ast); |
61 | void statement(StatementAST *ast); |
62 | const Type *type(TypeAST *ast); |
63 | void declaration(DeclarationAST *ast); |
64 | ExprResult functionIdentifier(FunctionIdentifierAST *ast); |
65 | Symbol *field(StructTypeAST::Field *ast); |
66 | void parameterDeclaration(ParameterDeclarationAST *ast, Function *fun); |
67 | |
68 | bool visit(TranslationUnitAST *ast) override; |
69 | bool visit(FunctionIdentifierAST *ast) override; |
70 | bool visit(StructTypeAST::Field *ast) override; |
71 | |
72 | // expressions |
73 | bool visit(IdentifierExpressionAST *ast) override; |
74 | bool visit(LiteralExpressionAST *ast) override; |
75 | bool visit(BinaryExpressionAST *ast) override; |
76 | bool visit(UnaryExpressionAST *ast) override; |
77 | bool visit(TernaryExpressionAST *ast) override; |
78 | bool visit(AssignmentExpressionAST *ast) override; |
79 | bool visit(MemberAccessExpressionAST *ast) override; |
80 | bool visit(FunctionCallExpressionAST *ast) override; |
81 | bool visit(DeclarationExpressionAST *ast) override; |
82 | |
83 | // statements |
84 | bool visit(ExpressionStatementAST *ast) override; |
85 | bool visit(CompoundStatementAST *ast) override; |
86 | bool visit(IfStatementAST *ast) override; |
87 | bool visit(WhileStatementAST *ast) override; |
88 | bool visit(DoStatementAST *ast) override; |
89 | bool visit(ForStatementAST *ast) override; |
90 | bool visit(JumpStatementAST *ast) override; |
91 | bool visit(ReturnStatementAST *ast) override; |
92 | bool visit(SwitchStatementAST *ast) override; |
93 | bool visit(CaseLabelStatementAST *ast) override; |
94 | bool visit(DeclarationStatementAST *ast) override; |
95 | |
96 | // types |
97 | bool visit(BasicTypeAST *ast) override; |
98 | bool visit(NamedTypeAST *ast) override; |
99 | bool visit(ArrayTypeAST *ast) override; |
100 | bool visit(StructTypeAST *ast) override; |
101 | bool visit(QualifiedTypeAST *ast) override; |
102 | bool visit(LayoutQualifierAST *ast) override { return Visitor::visit(ast); } |
103 | |
104 | // declarations |
105 | bool visit(PrecisionDeclarationAST *ast) override; |
106 | bool visit(ParameterDeclarationAST *ast) override; |
107 | bool visit(VariableDeclarationAST *ast) override; |
108 | bool visit(TypeDeclarationAST *ast) override; |
109 | bool visit(TypeAndVariableDeclarationAST *ast) override; |
110 | bool visit(InvariantDeclarationAST *ast) override; |
111 | bool visit(InitDeclarationAST *ast) override; |
112 | bool visit(FunctionDeclarationAST *ast) override; |
113 | |
114 | private: |
115 | Engine *_engine; |
116 | Scope *_scope; |
117 | const Type *_type; |
118 | ExprResult _expr; |
119 | }; |
120 | |
121 | } // namespace GLSL |
122 | |
123 | QT_END_NAMESPACE |
124 | |
125 | #endif // QSSG_GLSLSEMANTIC_H |
126 |