1 // 2 // Copyright 2016 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 // IntermNodePatternMatcher is a helper class for matching node trees to given patterns. 7 // It can be used whenever the same checks for certain node structures are common to multiple AST 8 // traversers. 9 // 10 11 #ifndef COMPILER_TRANSLATOR_TREEUTIL_INTERMNODEPATTERNMATCHER_H_ 12 #define COMPILER_TRANSLATOR_TREEUTIL_INTERMNODEPATTERNMATCHER_H_ 13 14 namespace sh 15 { 16 17 class TIntermAggregate; 18 class TIntermBinary; 19 class TIntermDeclaration; 20 class TIntermNode; 21 class TIntermTernary; 22 class TIntermUnary; 23 24 class IntermNodePatternMatcher 25 { 26 public: 27 static bool IsDynamicIndexingOfNonSSBOVectorOrMatrix(TIntermBinary *node); 28 static bool IsDynamicIndexingOfVectorOrMatrix(TIntermBinary *node); 29 static bool IsDynamicIndexingOfSwizzledVector(TIntermBinary *node); 30 31 enum PatternType : unsigned int 32 { 33 // Matches expressions that are unfolded to if statements by UnfoldShortCircuitToIf 34 kUnfoldedShortCircuitExpression = 1u << 0u, 35 36 // Matches expressions that return arrays with the exception of simple statements where a 37 // constructor or function call result is assigned. 38 kExpressionReturningArray = 1u << 1u, 39 40 // Matches dynamic indexing of vectors or matrices in l-values. 41 kDynamicIndexingOfVectorOrMatrixInLValue = 1u << 2u, 42 43 // Matches declarations with more than one declared variables. 44 kMultiDeclaration = 1u << 3u, 45 46 // Matches declarations of arrays. 47 kArrayDeclaration = 1u << 4u, 48 49 // Matches declarations of structs where the struct type does not have a name. 50 kNamelessStructDeclaration = 1u << 5u, 51 52 // Matches array length() method. 53 kArrayLengthMethod = 1u << 6u, 54 }; 55 IntermNodePatternMatcher(const unsigned int mask); 56 57 bool match(TIntermUnary *node) const; 58 59 bool match(TIntermBinary *node, TIntermNode *parentNode) const; 60 61 // Use this version for checking binary node matches in case you're using flag 62 // kDynamicIndexingOfVectorOrMatrixInLValue. 63 bool match(TIntermBinary *node, TIntermNode *parentNode, bool isLValueRequiredHere) const; 64 65 bool match(TIntermAggregate *node, TIntermNode *parentNode) const; 66 bool match(TIntermTernary *node) const; 67 bool match(TIntermDeclaration *node) const; 68 69 private: 70 const unsigned int mMask; 71 72 bool matchInternal(TIntermBinary *node, TIntermNode *parentNode) const; 73 }; 74 75 } // namespace sh 76 77 #endif // COMPILER_TRANSLATOR_TREEUTIL_INTERMNODEPATTERNMATCHER_H_ 78