blob: c156100b53cde3030cbc8dd817cf65585b0a0a67 [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
Jamie Madill45bcc782016-11-07 13:58:48 -050014namespace sh
15{
16
Olli Etuaho00f6fbb2016-07-20 16:32:29 +030017class TIntermAggregate;
18class TIntermBinary;
19class TIntermNode;
Olli Etuahod0bad2c2016-09-09 18:01:16 +030020class TIntermTernary;
Corentin Wallez1212bca2016-11-23 13:44:05 -050021class TIntermDeclaration;
Olli Etuaho00f6fbb2016-07-20 16:32:29 +030022
23class IntermNodePatternMatcher
24{
25 public:
Jamie Madill666f65a2016-08-26 01:34:37 +000026 static bool IsDynamicIndexingOfVectorOrMatrix(TIntermBinary *node);
27
Olli Etuaho00f6fbb2016-07-20 16:32:29 +030028 enum PatternType
29 {
Jamie Madill666f65a2016-08-26 01:34:37 +000030 // Matches expressions that are unfolded to if statements by UnfoldShortCircuitToIf
Olli Etuaho00f6fbb2016-07-20 16:32:29 +030031 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 Madill666f65a2016-08-26 01:34:37 +000035 kExpressionReturningArray = 0x0002,
36
37 // Matches dynamic indexing of vectors or matrices in l-values.
Corentin Wallez1212bca2016-11-23 13:44:05 -050038 kDynamicIndexingOfVectorOrMatrixInLValue = 0x0004,
39
40 // Matches declarations with more than one declared variables
41 kMultiDeclaration = 0x0008,
Olli Etuaho00f6fbb2016-07-20 16:32:29 +030042 };
43 IntermNodePatternMatcher(const unsigned int mask);
44
45 bool match(TIntermBinary *node, TIntermNode *parentNode);
Jamie Madill666f65a2016-08-26 01:34:37 +000046
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 Etuaho00f6fbb2016-07-20 16:32:29 +030051 bool match(TIntermAggregate *node, TIntermNode *parentNode);
Olli Etuahod0bad2c2016-09-09 18:01:16 +030052 bool match(TIntermTernary *node);
Corentin Wallez1212bca2016-11-23 13:44:05 -050053 bool match(TIntermDeclaration *node);
Olli Etuaho00f6fbb2016-07-20 16:32:29 +030054
55 private:
56 const unsigned int mMask;
Jamie Madill666f65a2016-08-26 01:34:37 +000057
58 bool matchInternal(TIntermBinary *node, TIntermNode *parentNode);
Olli Etuaho00f6fbb2016-07-20 16:32:29 +030059};
60
Jamie Madill45bcc782016-11-07 13:58:48 -050061} // namespace sh
62
Olli Etuaho00f6fbb2016-07-20 16:32:29 +030063#endif