summaryrefslogtreecommitdiffstats
path: root/gfx/angle/checkout/src/compiler/translator/tree_util/NodeType.h
blob: 4ab63dbebb140c8c39a1c5d069d9ed5e8a224a0d (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//

#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_NODETYPE_H_
#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_NODETYPE_H_

#include "compiler/translator/tree_util/IntermTraverse.h"

namespace sh
{

enum class NodeType
{
    Unknown,
    Symbol,
    ConstantUnion,
    FunctionPrototype,
    PreprocessorDirective,
    Unary,
    Binary,
    Ternary,
    Swizzle,
    IfElse,
    Switch,
    Case,
    FunctionDefinition,
    Aggregate,
    Block,
    GlobalQualifierDeclaration,
    Declaration,
    Loop,
    Branch,
};

// This is a function like object instead of a function that stack allocates this because
// TIntermTraverser is a heavy object to construct.
class GetNodeType : private TIntermTraverser
{
    NodeType nodeType;

  public:
    GetNodeType() : TIntermTraverser(true, false, false) {}

    NodeType operator()(TIntermNode &node)
    {
        node.visit(Visit::PreVisit, this);
        return nodeType;
    }

  private:
    void visitSymbol(TIntermSymbol *) override { nodeType = NodeType::Symbol; }

    void visitConstantUnion(TIntermConstantUnion *) override { nodeType = NodeType::ConstantUnion; }

    void visitFunctionPrototype(TIntermFunctionPrototype *) override
    {
        nodeType = NodeType::FunctionPrototype;
    }

    void visitPreprocessorDirective(TIntermPreprocessorDirective *) override
    {
        nodeType = NodeType::PreprocessorDirective;
    }

    bool visitSwizzle(Visit, TIntermSwizzle *) override
    {
        nodeType = NodeType::Swizzle;
        return false;
    }

    bool visitBinary(Visit, TIntermBinary *) override
    {
        nodeType = NodeType::Binary;
        return false;
    }

    bool visitUnary(Visit, TIntermUnary *) override
    {
        nodeType = NodeType::Unary;
        return false;
    }

    bool visitTernary(Visit, TIntermTernary *) override
    {
        nodeType = NodeType::Ternary;
        return false;
    }

    bool visitIfElse(Visit, TIntermIfElse *) override
    {
        nodeType = NodeType::IfElse;
        return false;
    }

    bool visitSwitch(Visit, TIntermSwitch *) override
    {
        nodeType = NodeType::Switch;
        return false;
    }

    bool visitCase(Visit, TIntermCase *) override
    {
        nodeType = NodeType::Case;
        return false;
    }

    bool visitFunctionDefinition(Visit, TIntermFunctionDefinition *) override
    {
        nodeType = NodeType::FunctionDefinition;
        return false;
    }

    bool visitAggregate(Visit, TIntermAggregate *) override
    {
        nodeType = NodeType::Aggregate;
        return false;
    }

    bool visitBlock(Visit, TIntermBlock *) override
    {
        nodeType = NodeType::Block;
        return false;
    }

    bool visitGlobalQualifierDeclaration(Visit, TIntermGlobalQualifierDeclaration *) override
    {
        nodeType = NodeType::GlobalQualifierDeclaration;
        return false;
    }

    bool visitDeclaration(Visit, TIntermDeclaration *) override
    {
        nodeType = NodeType::Declaration;
        return false;
    }

    bool visitLoop(Visit, TIntermLoop *) override
    {
        nodeType = NodeType::Loop;
        return false;
    }

    bool visitBranch(Visit, TIntermBranch *) override
    {
        nodeType = NodeType::Branch;
        return false;
    }
};

}  // namespace sh

#endif  // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_NODETYPE_H_