aboutsummaryrefslogtreecommitdiffstats
path: root/src/glslparser/glslsemantic_p.h
blob: be744dcc8316be564a9141662009f2944afaf214 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef QSSG_GLSLSEMANTIC_H
#define QSSG_GLSLSEMANTIC_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <QtQuick3DGlslParser/private/glslastvisitor_p.h>
#include <QtQuick3DGlslParser/private/glsltype_p.h>

QT_BEGIN_NAMESPACE

namespace GLSL {

class Q_QUICK3DGLSLPARSER_EXPORT Semantic: protected Visitor
{
public:
    Semantic();
    ~Semantic() override;

    struct ExprResult {
        ExprResult(const Type *type_ = nullptr, bool isConstant_ = false)
            : type(type_), isConstant(isConstant_) {}

        ~ExprResult() { }

        bool isValid() const {
            if (! type)
                return false;
            else if (type->asUndefinedType() != nullptr)
                return false;
            return true;
        }

        explicit operator bool() const { return isValid(); }

        const Type *type;
        bool isConstant;
    };

    void translationUnit(TranslationUnitAST *ast, Scope *globalScope, Engine *engine);
    ExprResult expression(ExpressionAST *ast, Scope *scope, Engine *engine);

protected:
    Engine *switchEngine(Engine *engine);
    Scope *switchScope(Scope *scope);

    bool implicitCast(const Type *type, const Type *target) const;

    ExprResult expression(ExpressionAST *ast);
    void statement(StatementAST *ast);
    const Type *type(TypeAST *ast);
    void declaration(DeclarationAST *ast);
    ExprResult functionIdentifier(FunctionIdentifierAST *ast);
    Symbol *field(StructTypeAST::Field *ast);
    void parameterDeclaration(ParameterDeclarationAST *ast, Function *fun);

    bool visit(TranslationUnitAST *ast) override;
    bool visit(FunctionIdentifierAST *ast) override;
    bool visit(StructTypeAST::Field *ast) override;

    // expressions
    bool visit(IdentifierExpressionAST *ast) override;
    bool visit(LiteralExpressionAST *ast) override;
    bool visit(BinaryExpressionAST *ast) override;
    bool visit(UnaryExpressionAST *ast) override;
    bool visit(TernaryExpressionAST *ast) override;
    bool visit(AssignmentExpressionAST *ast) override;
    bool visit(MemberAccessExpressionAST *ast) override;
    bool visit(FunctionCallExpressionAST *ast) override;
    bool visit(DeclarationExpressionAST *ast) override;

    // statements
    bool visit(ExpressionStatementAST *ast) override;
    bool visit(CompoundStatementAST *ast) override;
    bool visit(IfStatementAST *ast) override;
    bool visit(WhileStatementAST *ast) override;
    bool visit(DoStatementAST *ast) override;
    bool visit(ForStatementAST *ast) override;
    bool visit(JumpStatementAST *ast) override;
    bool visit(ReturnStatementAST *ast) override;
    bool visit(SwitchStatementAST *ast) override;
    bool visit(CaseLabelStatementAST *ast) override;
    bool visit(DeclarationStatementAST *ast) override;

    // types
    bool visit(BasicTypeAST *ast) override;
    bool visit(NamedTypeAST *ast) override;
    bool visit(ArrayTypeAST *ast) override;
    bool visit(StructTypeAST *ast) override;
    bool visit(QualifiedTypeAST *ast) override;
    bool visit(LayoutQualifierAST *ast) override { return Visitor::visit(ast); }

    // declarations
    bool visit(PrecisionDeclarationAST *ast) override;
    bool visit(ParameterDeclarationAST *ast) override;
    bool visit(VariableDeclarationAST *ast) override;
    bool visit(TypeDeclarationAST *ast) override;
    bool visit(TypeAndVariableDeclarationAST *ast) override;
    bool visit(InvariantDeclarationAST *ast) override;
    bool visit(InitDeclarationAST *ast) override;
    bool visit(FunctionDeclarationAST *ast) override;

private:
    Engine *_engine;
    Scope *_scope;
    const Type *_type;
    ExprResult _expr;
};

} // namespace GLSL

QT_END_NAMESPACE

#endif // QSSG_GLSLSEMANTIC_H