gfx/angle/src/compiler/depgraph/DependencyGraphBuilder.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 //
michael@0 2 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
michael@0 3 // Use of this source code is governed by a BSD-style license that can be
michael@0 4 // found in the LICENSE file.
michael@0 5 //
michael@0 6
michael@0 7 #ifndef COMPILER_DEPGRAPH_DEPENDENCY_GRAPH_BUILDER_H
michael@0 8 #define COMPILER_DEPGRAPH_DEPENDENCY_GRAPH_BUILDER_H
michael@0 9
michael@0 10 #include "compiler/depgraph/DependencyGraph.h"
michael@0 11
michael@0 12 //
michael@0 13 // Creates a dependency graph of symbols, function calls, conditions etc. by traversing a
michael@0 14 // intermediate tree.
michael@0 15 //
michael@0 16 class TDependencyGraphBuilder : public TIntermTraverser {
michael@0 17 public:
michael@0 18 static void build(TIntermNode* node, TDependencyGraph* graph);
michael@0 19
michael@0 20 virtual void visitSymbol(TIntermSymbol*);
michael@0 21 virtual bool visitBinary(Visit visit, TIntermBinary*);
michael@0 22 virtual bool visitSelection(Visit visit, TIntermSelection*);
michael@0 23 virtual bool visitAggregate(Visit visit, TIntermAggregate*);
michael@0 24 virtual bool visitLoop(Visit visit, TIntermLoop*);
michael@0 25
michael@0 26 private:
michael@0 27 typedef std::stack<TGraphSymbol*> TSymbolStack;
michael@0 28 typedef std::set<TGraphParentNode*> TParentNodeSet;
michael@0 29
michael@0 30 //
michael@0 31 // For collecting the dependent nodes of assignments, conditions, etc.
michael@0 32 // while traversing the intermediate tree.
michael@0 33 //
michael@0 34 // This data structure is stack of sets. Each set contains dependency graph parent nodes.
michael@0 35 //
michael@0 36 class TNodeSetStack {
michael@0 37 public:
michael@0 38 TNodeSetStack() {};
michael@0 39 ~TNodeSetStack() { clear(); }
michael@0 40
michael@0 41 // This should only be called after a pushSet.
michael@0 42 // Returns NULL if the top set is empty.
michael@0 43 TParentNodeSet* getTopSet() const
michael@0 44 {
michael@0 45 ASSERT(!nodeSets.empty());
michael@0 46 TParentNodeSet* topSet = nodeSets.top();
michael@0 47 return !topSet->empty() ? topSet : NULL;
michael@0 48 }
michael@0 49
michael@0 50 void pushSet() { nodeSets.push(new TParentNodeSet()); }
michael@0 51 void popSet()
michael@0 52 {
michael@0 53 ASSERT(!nodeSets.empty());
michael@0 54 delete nodeSets.top();
michael@0 55 nodeSets.pop();
michael@0 56 }
michael@0 57
michael@0 58 // Pops the top set and adds its contents to the new top set.
michael@0 59 // This should only be called after a pushSet.
michael@0 60 // If there is no set below the top set, the top set is just deleted.
michael@0 61 void popSetIntoNext()
michael@0 62 {
michael@0 63 ASSERT(!nodeSets.empty());
michael@0 64 TParentNodeSet* oldTopSet = nodeSets.top();
michael@0 65 nodeSets.pop();
michael@0 66
michael@0 67 if (!nodeSets.empty()) {
michael@0 68 TParentNodeSet* newTopSet = nodeSets.top();
michael@0 69 newTopSet->insert(oldTopSet->begin(), oldTopSet->end());
michael@0 70 }
michael@0 71
michael@0 72 delete oldTopSet;
michael@0 73 }
michael@0 74
michael@0 75 // Does nothing if there is no top set.
michael@0 76 // This can be called when there is no top set if we are visiting
michael@0 77 // symbols that are not under an assignment or condition.
michael@0 78 // We don't need to track those symbols.
michael@0 79 void insertIntoTopSet(TGraphParentNode* node)
michael@0 80 {
michael@0 81 if (nodeSets.empty())
michael@0 82 return;
michael@0 83
michael@0 84 nodeSets.top()->insert(node);
michael@0 85 }
michael@0 86
michael@0 87 void clear()
michael@0 88 {
michael@0 89 while (!nodeSets.empty())
michael@0 90 popSet();
michael@0 91 }
michael@0 92
michael@0 93 private:
michael@0 94 typedef std::stack<TParentNodeSet*> TParentNodeSetStack;
michael@0 95
michael@0 96 TParentNodeSetStack nodeSets;
michael@0 97 };
michael@0 98
michael@0 99 //
michael@0 100 // An instance of this class pushes a new node set when instantiated.
michael@0 101 // When the instance goes out of scope, it and pops the node set.
michael@0 102 //
michael@0 103 class TNodeSetMaintainer {
michael@0 104 public:
michael@0 105 TNodeSetMaintainer(TDependencyGraphBuilder* factory)
michael@0 106 : sets(factory->mNodeSets) { sets.pushSet(); }
michael@0 107 ~TNodeSetMaintainer() { sets.popSet(); }
michael@0 108 protected:
michael@0 109 TNodeSetStack& sets;
michael@0 110 };
michael@0 111
michael@0 112 //
michael@0 113 // An instance of this class pushes a new node set when instantiated.
michael@0 114 // When the instance goes out of scope, it and pops the top node set and adds its contents to
michael@0 115 // the new top node set.
michael@0 116 //
michael@0 117 class TNodeSetPropagatingMaintainer {
michael@0 118 public:
michael@0 119 TNodeSetPropagatingMaintainer(TDependencyGraphBuilder* factory)
michael@0 120 : sets(factory->mNodeSets) { sets.pushSet(); }
michael@0 121 ~TNodeSetPropagatingMaintainer() { sets.popSetIntoNext(); }
michael@0 122 protected:
michael@0 123 TNodeSetStack& sets;
michael@0 124 };
michael@0 125
michael@0 126 //
michael@0 127 // An instance of this class keeps track of the leftmost symbol while we're exploring an
michael@0 128 // assignment.
michael@0 129 // It will push the placeholder symbol kLeftSubtree when instantiated under a left subtree,
michael@0 130 // and kRightSubtree under a right subtree.
michael@0 131 // When it goes out of scope, it will pop the leftmost symbol at the top of the scope.
michael@0 132 // During traversal, the TDependencyGraphBuilder will replace kLeftSubtree with a real symbol.
michael@0 133 // kRightSubtree will never be replaced by a real symbol because we are tracking the leftmost
michael@0 134 // symbol.
michael@0 135 //
michael@0 136 class TLeftmostSymbolMaintainer {
michael@0 137 public:
michael@0 138 TLeftmostSymbolMaintainer(TDependencyGraphBuilder* factory, TGraphSymbol& subtree)
michael@0 139 : leftmostSymbols(factory->mLeftmostSymbols)
michael@0 140 {
michael@0 141 needsPlaceholderSymbol = leftmostSymbols.empty() || leftmostSymbols.top() != &subtree;
michael@0 142 if (needsPlaceholderSymbol)
michael@0 143 leftmostSymbols.push(&subtree);
michael@0 144 }
michael@0 145
michael@0 146 ~TLeftmostSymbolMaintainer()
michael@0 147 {
michael@0 148 if (needsPlaceholderSymbol)
michael@0 149 leftmostSymbols.pop();
michael@0 150 }
michael@0 151
michael@0 152 protected:
michael@0 153 TSymbolStack& leftmostSymbols;
michael@0 154 bool needsPlaceholderSymbol;
michael@0 155 };
michael@0 156
michael@0 157 TDependencyGraphBuilder(TDependencyGraph* graph)
michael@0 158 : TIntermTraverser(true, false, false)
michael@0 159 , mLeftSubtree(NULL)
michael@0 160 , mRightSubtree(NULL)
michael@0 161 , mGraph(graph) {}
michael@0 162 void build(TIntermNode* intermNode) { intermNode->traverse(this); }
michael@0 163
michael@0 164 void connectMultipleNodesToSingleNode(TParentNodeSet* nodes, TGraphNode* node) const;
michael@0 165
michael@0 166 void visitAssignment(TIntermBinary*);
michael@0 167 void visitLogicalOp(TIntermBinary*);
michael@0 168 void visitBinaryChildren(TIntermBinary*);
michael@0 169 void visitFunctionDefinition(TIntermAggregate*);
michael@0 170 void visitFunctionCall(TIntermAggregate* intermFunctionCall);
michael@0 171 void visitAggregateChildren(TIntermAggregate*);
michael@0 172
michael@0 173 TGraphSymbol mLeftSubtree;
michael@0 174 TGraphSymbol mRightSubtree;
michael@0 175
michael@0 176 TDependencyGraph* mGraph;
michael@0 177 TNodeSetStack mNodeSets;
michael@0 178 TSymbolStack mLeftmostSymbols;
michael@0 179 };
michael@0 180
michael@0 181 #endif // COMPILER_DEPGRAPH_DEPENDENCY_GRAPH_BUILDER_H

mercurial