Olli Etuaho | 00f6fbb | 2016-07-20 16:32:29 +0300 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 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_INTERMNODEPATTERNMATCHER_H_ |
| 12 | #define COMPILER_TRANSLATOR_INTERMNODEPATTERNMATCHER_H_ |
| 13 | |
| 14 | class TIntermAggregate; |
| 15 | class TIntermBinary; |
| 16 | class TIntermNode; |
Olli Etuaho | d0bad2c | 2016-09-09 18:01:16 +0300 | [diff] [blame] | 17 | class TIntermTernary; |
Olli Etuaho | 00f6fbb | 2016-07-20 16:32:29 +0300 | [diff] [blame] | 18 | |
| 19 | class IntermNodePatternMatcher |
| 20 | { |
| 21 | public: |
Jamie Madill | 666f65a | 2016-08-26 01:34:37 +0000 | [diff] [blame] | 22 | static bool IsDynamicIndexingOfVectorOrMatrix(TIntermBinary *node); |
| 23 | |
Olli Etuaho | 00f6fbb | 2016-07-20 16:32:29 +0300 | [diff] [blame] | 24 | enum PatternType |
| 25 | { |
Jamie Madill | 666f65a | 2016-08-26 01:34:37 +0000 | [diff] [blame] | 26 | // Matches expressions that are unfolded to if statements by UnfoldShortCircuitToIf |
Olli Etuaho | 00f6fbb | 2016-07-20 16:32:29 +0300 | [diff] [blame] | 27 | kUnfoldedShortCircuitExpression = 0x0001, |
| 28 | |
| 29 | // Matches expressions that return arrays with the exception of simple statements where a |
| 30 | // constructor or function call result is assigned. |
Jamie Madill | 666f65a | 2016-08-26 01:34:37 +0000 | [diff] [blame] | 31 | kExpressionReturningArray = 0x0002, |
| 32 | |
| 33 | // Matches dynamic indexing of vectors or matrices in l-values. |
| 34 | kDynamicIndexingOfVectorOrMatrixInLValue = 0x0004 |
Olli Etuaho | 00f6fbb | 2016-07-20 16:32:29 +0300 | [diff] [blame] | 35 | }; |
| 36 | IntermNodePatternMatcher(const unsigned int mask); |
| 37 | |
| 38 | bool match(TIntermBinary *node, TIntermNode *parentNode); |
Jamie Madill | 666f65a | 2016-08-26 01:34:37 +0000 | [diff] [blame] | 39 | |
| 40 | // Use this version for checking binary node matches in case you're using flag |
| 41 | // kDynamicIndexingOfVectorOrMatrixInLValue. |
| 42 | bool match(TIntermBinary *node, TIntermNode *parentNode, bool isLValueRequiredHere); |
| 43 | |
Olli Etuaho | 00f6fbb | 2016-07-20 16:32:29 +0300 | [diff] [blame] | 44 | bool match(TIntermAggregate *node, TIntermNode *parentNode); |
Olli Etuaho | d0bad2c | 2016-09-09 18:01:16 +0300 | [diff] [blame] | 45 | bool match(TIntermTernary *node); |
Olli Etuaho | 00f6fbb | 2016-07-20 16:32:29 +0300 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | const unsigned int mMask; |
Jamie Madill | 666f65a | 2016-08-26 01:34:37 +0000 | [diff] [blame] | 49 | |
| 50 | bool matchInternal(TIntermBinary *node, TIntermNode *parentNode); |
Olli Etuaho | 00f6fbb | 2016-07-20 16:32:29 +0300 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | #endif |