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