• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
32     {
33         // Matches expressions that are unfolded to if statements by UnfoldShortCircuitToIf
34         kUnfoldedShortCircuitExpression = 0x0001,
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 = 0x0001 << 1,
39 
40         // Matches dynamic indexing of vectors or matrices in l-values.
41         kDynamicIndexingOfVectorOrMatrixInLValue = 0x0001 << 2,
42 
43         // Matches declarations with more than one declared variables.
44         kMultiDeclaration = 0x0001 << 3,
45 
46         // Matches declarations of arrays.
47         kArrayDeclaration = 0x0001 << 4,
48 
49         // Matches declarations of structs where the struct type does not have a name.
50         kNamelessStructDeclaration = 0x0001 << 5,
51 
52         // Matches array length() method.
53         kArrayLengthMethod = 0x0001 << 6,
54 
55         // Matches a vector or matrix constructor whose arguments are scalarized by the
56         // SH_SCALARIZE_VEC_OR_MAT_CONSTRUCTOR_ARGUMENTS workaround.
57         kScalarizedVecOrMatConstructor = 0x0001 << 7
58     };
59     IntermNodePatternMatcher(const unsigned int mask);
60 
61     bool match(TIntermUnary *node);
62 
63     bool match(TIntermBinary *node, TIntermNode *parentNode);
64 
65     // Use this version for checking binary node matches in case you're using flag
66     // kDynamicIndexingOfVectorOrMatrixInLValue.
67     bool match(TIntermBinary *node, TIntermNode *parentNode, bool isLValueRequiredHere);
68 
69     bool match(TIntermAggregate *node, TIntermNode *parentNode);
70     bool match(TIntermTernary *node);
71     bool match(TIntermDeclaration *node);
72 
73   private:
74     const unsigned int mMask;
75 
76     bool matchInternal(TIntermBinary *node, TIntermNode *parentNode);
77 };
78 
79 }  // namespace sh
80 
81 #endif  // COMPILER_TRANSLATOR_TREEUTIL_INTERMNODEPATTERNMATCHER_H_
82