1 // 2 // Copyright 2020 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 #ifndef COMPILER_TRANSLATOR_NODETYPE_H_ 8 #define COMPILER_TRANSLATOR_NODETYPE_H_ 9 10 #include "compiler/translator/tree_util/IntermTraverse.h" 11 12 namespace sh 13 { 14 15 enum class NodeType 16 { 17 Unknown, 18 Symbol, 19 ConstantUnion, 20 FunctionPrototype, 21 PreprocessorDirective, 22 Unary, 23 Binary, 24 Ternary, 25 Swizzle, 26 IfElse, 27 Switch, 28 Case, 29 FunctionDefinition, 30 Aggregate, 31 Block, 32 GlobalQualifierDeclaration, 33 Declaration, 34 Loop, 35 Branch, 36 }; 37 38 // This is a function like object instead of a function that stack allocates this because 39 // TIntermTraverser is a heavy object to construct. 40 class GetNodeType : private TIntermTraverser 41 { 42 public: GetNodeType()43 GetNodeType() : TIntermTraverser(true, false, false) {} 44 operator()45 NodeType operator()(TIntermNode &node) 46 { 47 node.visit(Visit::PreVisit, this); 48 return mNodeType; 49 } 50 51 private: visitSymbol(TIntermSymbol *)52 void visitSymbol(TIntermSymbol *) override { mNodeType = NodeType::Symbol; } 53 visitConstantUnion(TIntermConstantUnion *)54 void visitConstantUnion(TIntermConstantUnion *) override { mNodeType = NodeType::ConstantUnion; } 55 visitFunctionPrototype(TIntermFunctionPrototype *)56 void visitFunctionPrototype(TIntermFunctionPrototype *) override 57 { 58 mNodeType = NodeType::FunctionPrototype; 59 } 60 visitPreprocessorDirective(TIntermPreprocessorDirective *)61 void visitPreprocessorDirective(TIntermPreprocessorDirective *) override 62 { 63 mNodeType = NodeType::PreprocessorDirective; 64 } 65 visitSwizzle(Visit,TIntermSwizzle *)66 bool visitSwizzle(Visit, TIntermSwizzle *) override 67 { 68 mNodeType = NodeType::Swizzle; 69 return false; 70 } 71 visitBinary(Visit,TIntermBinary *)72 bool visitBinary(Visit, TIntermBinary *) override 73 { 74 mNodeType = NodeType::Binary; 75 return false; 76 } 77 visitUnary(Visit,TIntermUnary *)78 bool visitUnary(Visit, TIntermUnary *) override 79 { 80 mNodeType = NodeType::Unary; 81 return false; 82 } 83 visitTernary(Visit,TIntermTernary *)84 bool visitTernary(Visit, TIntermTernary *) override 85 { 86 mNodeType = NodeType::Ternary; 87 return false; 88 } 89 visitIfElse(Visit,TIntermIfElse *)90 bool visitIfElse(Visit, TIntermIfElse *) override 91 { 92 mNodeType = NodeType::IfElse; 93 return false; 94 } 95 visitSwitch(Visit,TIntermSwitch *)96 bool visitSwitch(Visit, TIntermSwitch *) override 97 { 98 mNodeType = NodeType::Switch; 99 return false; 100 } 101 visitCase(Visit,TIntermCase *)102 bool visitCase(Visit, TIntermCase *) override 103 { 104 mNodeType = NodeType::Case; 105 return false; 106 } 107 visitFunctionDefinition(Visit,TIntermFunctionDefinition *)108 bool visitFunctionDefinition(Visit, TIntermFunctionDefinition *) override 109 { 110 mNodeType = NodeType::FunctionDefinition; 111 return false; 112 } 113 visitAggregate(Visit,TIntermAggregate *)114 bool visitAggregate(Visit, TIntermAggregate *) override 115 { 116 mNodeType = NodeType::Aggregate; 117 return false; 118 } 119 visitBlock(Visit,TIntermBlock *)120 bool visitBlock(Visit, TIntermBlock *) override 121 { 122 mNodeType = NodeType::Block; 123 return false; 124 } 125 visitGlobalQualifierDeclaration(Visit,TIntermGlobalQualifierDeclaration *)126 bool visitGlobalQualifierDeclaration(Visit, TIntermGlobalQualifierDeclaration *) override 127 { 128 mNodeType = NodeType::GlobalQualifierDeclaration; 129 return false; 130 } 131 visitDeclaration(Visit,TIntermDeclaration *)132 bool visitDeclaration(Visit, TIntermDeclaration *) override 133 { 134 mNodeType = NodeType::Declaration; 135 return false; 136 } 137 visitLoop(Visit,TIntermLoop *)138 bool visitLoop(Visit, TIntermLoop *) override 139 { 140 mNodeType = NodeType::Loop; 141 return false; 142 } 143 visitBranch(Visit,TIntermBranch *)144 bool visitBranch(Visit, TIntermBranch *) override 145 { 146 mNodeType = NodeType::Branch; 147 return false; 148 } 149 150 NodeType mNodeType; 151 }; 152 153 } // namespace sh 154 155 #endif // COMPILER_TRANSLATOR_NODETYPE_H_ 156