Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / compiler / translator / UnfoldShortCircuitAST.h
1 //
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.
5 //
6 // UnfoldShortCircuitAST is an AST traverser to replace short-circuiting
7 // operations with ternary operations.
8 //
9
10 #ifndef COMPILER_UNFOLD_SHORT_CIRCUIT_AST_H_
11 #define COMPILER_UNFOLD_SHORT_CIRCUIT_AST_H_
12
13 #include "common/angleutils.h"
14 #include "compiler/translator/IntermNode.h"
15
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().
19
20 class UnfoldShortCircuitAST : public TIntermTraverser
21 {
22   public:
23     UnfoldShortCircuitAST() { }
24
25     virtual bool visitBinary(Visit visit, TIntermBinary *);
26
27     void updateTree();
28
29   private:
30     struct NodeUpdateEntry
31     {
32         NodeUpdateEntry(TIntermNode *_parent,
33                         TIntermNode *_original,
34                         TIntermNode *_replacement)
35             : parent(_parent),
36               original(_original),
37               replacement(_replacement) {}
38
39         TIntermNode *parent;
40         TIntermNode *original;
41         TIntermNode *replacement;
42     };
43
44     // During traversing, save all the replacements that need to happen;
45     // then replace them by calling updateNodes().
46     std::vector<NodeUpdateEntry> replacements;
47
48     DISALLOW_COPY_AND_ASSIGN(UnfoldShortCircuitAST);
49 };
50
51 #endif  // COMPILER_UNFOLD_SHORT_CIRCUIT_AST_H_