2 // Copyright (c) 2002-2013 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.
6 // UnfoldShortCircuitAST is an AST traverser to replace short-circuiting
7 // operations with ternary operations.
10 #ifndef COMPILER_UNFOLD_SHORT_CIRCUIT_AST_H_
11 #define COMPILER_UNFOLD_SHORT_CIRCUIT_AST_H_
13 #include "common/angleutils.h"
14 #include "compiler/translator/IntermNode.h"
16 // This traverser identifies all the short circuit binary nodes that need to
17 // be replaced, and creates the corresponding replacement nodes. However,
18 // the actual replacements happen after the traverse through updateTree().
20 class UnfoldShortCircuitAST : public TIntermTraverser
23 UnfoldShortCircuitAST() { }
25 virtual bool visitBinary(Visit visit, TIntermBinary *);
30 struct NodeUpdateEntry
32 NodeUpdateEntry(TIntermNode *_parent,
33 TIntermNode *_original,
34 TIntermNode *_replacement)
37 replacement(_replacement) {}
40 TIntermNode *original;
41 TIntermNode *replacement;
44 // During traversing, save all the replacements that need to happen;
45 // then replace them by calling updateNodes().
46 std::vector<NodeUpdateEntry> replacements;
48 DISALLOW_COPY_AND_ASSIGN(UnfoldShortCircuitAST);
51 #endif // COMPILER_UNFOLD_SHORT_CIRCUIT_AST_H_