blob: be6fc61f76bbbc4baa6461c5543445b4d7840f22 [file] [log] [blame]
Olli Etuaho00f6fbb2016-07-20 16:32:29 +03001//
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
14class TIntermAggregate;
15class TIntermBinary;
16class TIntermNode;
17class TIntermSelection;
18
19class IntermNodePatternMatcher
20{
21 public:
Olli Etuaho7da98502016-07-20 18:45:09 +030022 static bool IsDynamicIndexingOfVectorOrMatrix(TIntermBinary *node);
23
Olli Etuaho00f6fbb2016-07-20 16:32:29 +030024 enum PatternType
25 {
Olli Etuaho7da98502016-07-20 18:45:09 +030026 // Matches expressions that are unfolded to if statements by UnfoldShortCircuitToIf
Olli Etuaho00f6fbb2016-07-20 16:32:29 +030027 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.
Olli Etuaho7da98502016-07-20 18:45:09 +030031 kExpressionReturningArray = 0x0002,
32
33 // Matches dynamic indexing of vectors or matrices in l-values.
34 kDynamicIndexingOfVectorOrMatrixInLValue = 0x0004
Olli Etuaho00f6fbb2016-07-20 16:32:29 +030035 };
36 IntermNodePatternMatcher(const unsigned int mask);
37
38 bool match(TIntermBinary *node, TIntermNode *parentNode);
Olli Etuaho7da98502016-07-20 18:45:09 +030039
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 Etuaho00f6fbb2016-07-20 16:32:29 +030044 bool match(TIntermAggregate *node, TIntermNode *parentNode);
45 bool match(TIntermSelection *node);
46
47 private:
48 const unsigned int mMask;
Olli Etuaho7da98502016-07-20 18:45:09 +030049
50 bool matchInternal(TIntermBinary *node, TIntermNode *parentNode);
Olli Etuaho00f6fbb2016-07-20 16:32:29 +030051};
52
53#endif