Sat, 03 Jan 2015 20:18:00 +0100
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 | #include "compiler/depgraph/DependencyGraphBuilder.h" |
michael@0 | 8 | |
michael@0 | 9 | void TDependencyGraphBuilder::build(TIntermNode* node, TDependencyGraph* graph) |
michael@0 | 10 | { |
michael@0 | 11 | TDependencyGraphBuilder builder(graph); |
michael@0 | 12 | builder.build(node); |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | bool TDependencyGraphBuilder::visitAggregate(Visit visit, TIntermAggregate* intermAggregate) |
michael@0 | 16 | { |
michael@0 | 17 | switch (intermAggregate->getOp()) { |
michael@0 | 18 | case EOpFunction: visitFunctionDefinition(intermAggregate); break; |
michael@0 | 19 | case EOpFunctionCall: visitFunctionCall(intermAggregate); break; |
michael@0 | 20 | default: visitAggregateChildren(intermAggregate); break; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | return false; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | void TDependencyGraphBuilder::visitFunctionDefinition(TIntermAggregate* intermAggregate) |
michael@0 | 27 | { |
michael@0 | 28 | // Currently, we do not support user defined functions. |
michael@0 | 29 | if (intermAggregate->getName() != "main(") |
michael@0 | 30 | return; |
michael@0 | 31 | |
michael@0 | 32 | visitAggregateChildren(intermAggregate); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | // Takes an expression like "f(x)" and creates a dependency graph like |
michael@0 | 36 | // "x -> argument 0 -> function call". |
michael@0 | 37 | void TDependencyGraphBuilder::visitFunctionCall(TIntermAggregate* intermFunctionCall) |
michael@0 | 38 | { |
michael@0 | 39 | TGraphFunctionCall* functionCall = mGraph->createFunctionCall(intermFunctionCall); |
michael@0 | 40 | |
michael@0 | 41 | // Run through the function call arguments. |
michael@0 | 42 | int argumentNumber = 0; |
michael@0 | 43 | TIntermSequence& intermArguments = intermFunctionCall->getSequence(); |
michael@0 | 44 | for (TIntermSequence::const_iterator iter = intermArguments.begin(); |
michael@0 | 45 | iter != intermArguments.end(); |
michael@0 | 46 | ++iter, ++argumentNumber) |
michael@0 | 47 | { |
michael@0 | 48 | TNodeSetMaintainer nodeSetMaintainer(this); |
michael@0 | 49 | |
michael@0 | 50 | TIntermNode* intermArgument = *iter; |
michael@0 | 51 | intermArgument->traverse(this); |
michael@0 | 52 | |
michael@0 | 53 | if (TParentNodeSet* argumentNodes = mNodeSets.getTopSet()) { |
michael@0 | 54 | TGraphArgument* argument = mGraph->createArgument(intermFunctionCall, argumentNumber); |
michael@0 | 55 | connectMultipleNodesToSingleNode(argumentNodes, argument); |
michael@0 | 56 | argument->addDependentNode(functionCall); |
michael@0 | 57 | } |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | // Push the leftmost symbol of this function call into the current set of dependent symbols to |
michael@0 | 61 | // represent the result of this function call. |
michael@0 | 62 | // Thus, an expression like "y = f(x)" will yield a dependency graph like |
michael@0 | 63 | // "x -> argument 0 -> function call -> y". |
michael@0 | 64 | // This line essentially passes the function call node back up to an earlier visitAssignment |
michael@0 | 65 | // call, which will create the connection "function call -> y". |
michael@0 | 66 | mNodeSets.insertIntoTopSet(functionCall); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | void TDependencyGraphBuilder::visitAggregateChildren(TIntermAggregate* intermAggregate) |
michael@0 | 70 | { |
michael@0 | 71 | TIntermSequence& sequence = intermAggregate->getSequence(); |
michael@0 | 72 | for(TIntermSequence::const_iterator iter = sequence.begin(); iter != sequence.end(); ++iter) |
michael@0 | 73 | { |
michael@0 | 74 | TIntermNode* intermChild = *iter; |
michael@0 | 75 | intermChild->traverse(this); |
michael@0 | 76 | } |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | void TDependencyGraphBuilder::visitSymbol(TIntermSymbol* intermSymbol) |
michael@0 | 80 | { |
michael@0 | 81 | // Push this symbol into the set of dependent symbols for the current assignment or condition |
michael@0 | 82 | // that we are traversing. |
michael@0 | 83 | TGraphSymbol* symbol = mGraph->getOrCreateSymbol(intermSymbol); |
michael@0 | 84 | mNodeSets.insertIntoTopSet(symbol); |
michael@0 | 85 | |
michael@0 | 86 | // If this symbol is the current leftmost symbol under an assignment, replace the previous |
michael@0 | 87 | // leftmost symbol with this symbol. |
michael@0 | 88 | if (!mLeftmostSymbols.empty() && mLeftmostSymbols.top() != &mRightSubtree) { |
michael@0 | 89 | mLeftmostSymbols.pop(); |
michael@0 | 90 | mLeftmostSymbols.push(symbol); |
michael@0 | 91 | } |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | bool TDependencyGraphBuilder::visitBinary(Visit visit, TIntermBinary* intermBinary) |
michael@0 | 95 | { |
michael@0 | 96 | TOperator op = intermBinary->getOp(); |
michael@0 | 97 | if (op == EOpInitialize || intermBinary->modifiesState()) |
michael@0 | 98 | visitAssignment(intermBinary); |
michael@0 | 99 | else if (op == EOpLogicalAnd || op == EOpLogicalOr) |
michael@0 | 100 | visitLogicalOp(intermBinary); |
michael@0 | 101 | else |
michael@0 | 102 | visitBinaryChildren(intermBinary); |
michael@0 | 103 | |
michael@0 | 104 | return false; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | void TDependencyGraphBuilder::visitAssignment(TIntermBinary* intermAssignment) |
michael@0 | 108 | { |
michael@0 | 109 | TIntermTyped* intermLeft = intermAssignment->getLeft(); |
michael@0 | 110 | if (!intermLeft) |
michael@0 | 111 | return; |
michael@0 | 112 | |
michael@0 | 113 | TGraphSymbol* leftmostSymbol = NULL; |
michael@0 | 114 | |
michael@0 | 115 | { |
michael@0 | 116 | TNodeSetMaintainer nodeSetMaintainer(this); |
michael@0 | 117 | |
michael@0 | 118 | { |
michael@0 | 119 | TLeftmostSymbolMaintainer leftmostSymbolMaintainer(this, mLeftSubtree); |
michael@0 | 120 | intermLeft->traverse(this); |
michael@0 | 121 | leftmostSymbol = mLeftmostSymbols.top(); |
michael@0 | 122 | |
michael@0 | 123 | // After traversing the left subtree of this assignment, we should have found a real |
michael@0 | 124 | // leftmost symbol, and the leftmost symbol should not be a placeholder. |
michael@0 | 125 | ASSERT(leftmostSymbol != &mLeftSubtree); |
michael@0 | 126 | ASSERT(leftmostSymbol != &mRightSubtree); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | if (TIntermTyped* intermRight = intermAssignment->getRight()) { |
michael@0 | 130 | TLeftmostSymbolMaintainer leftmostSymbolMaintainer(this, mRightSubtree); |
michael@0 | 131 | intermRight->traverse(this); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | if (TParentNodeSet* assignmentNodes = mNodeSets.getTopSet()) |
michael@0 | 135 | connectMultipleNodesToSingleNode(assignmentNodes, leftmostSymbol); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | // Push the leftmost symbol of this assignment into the current set of dependent symbols to |
michael@0 | 139 | // represent the result of this assignment. |
michael@0 | 140 | // An expression like "a = (b = c)" will yield a dependency graph like "c -> b -> a". |
michael@0 | 141 | // This line essentially passes the leftmost symbol of the nested assignment ("b" in this |
michael@0 | 142 | // example) back up to the earlier visitAssignment call for the outer assignment, which will |
michael@0 | 143 | // create the connection "b -> a". |
michael@0 | 144 | mNodeSets.insertIntoTopSet(leftmostSymbol); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | void TDependencyGraphBuilder::visitLogicalOp(TIntermBinary* intermLogicalOp) |
michael@0 | 148 | { |
michael@0 | 149 | if (TIntermTyped* intermLeft = intermLogicalOp->getLeft()) { |
michael@0 | 150 | TNodeSetPropagatingMaintainer nodeSetMaintainer(this); |
michael@0 | 151 | |
michael@0 | 152 | intermLeft->traverse(this); |
michael@0 | 153 | if (TParentNodeSet* leftNodes = mNodeSets.getTopSet()) { |
michael@0 | 154 | TGraphLogicalOp* logicalOp = mGraph->createLogicalOp(intermLogicalOp); |
michael@0 | 155 | connectMultipleNodesToSingleNode(leftNodes, logicalOp); |
michael@0 | 156 | } |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | if (TIntermTyped* intermRight = intermLogicalOp->getRight()) { |
michael@0 | 160 | TLeftmostSymbolMaintainer leftmostSymbolMaintainer(this, mRightSubtree); |
michael@0 | 161 | intermRight->traverse(this); |
michael@0 | 162 | } |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | void TDependencyGraphBuilder::visitBinaryChildren(TIntermBinary* intermBinary) |
michael@0 | 166 | { |
michael@0 | 167 | if (TIntermTyped* intermLeft = intermBinary->getLeft()) |
michael@0 | 168 | intermLeft->traverse(this); |
michael@0 | 169 | |
michael@0 | 170 | if (TIntermTyped* intermRight = intermBinary->getRight()) { |
michael@0 | 171 | TLeftmostSymbolMaintainer leftmostSymbolMaintainer(this, mRightSubtree); |
michael@0 | 172 | intermRight->traverse(this); |
michael@0 | 173 | } |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | bool TDependencyGraphBuilder::visitSelection(Visit visit, TIntermSelection* intermSelection) |
michael@0 | 177 | { |
michael@0 | 178 | if (TIntermNode* intermCondition = intermSelection->getCondition()) { |
michael@0 | 179 | TNodeSetMaintainer nodeSetMaintainer(this); |
michael@0 | 180 | |
michael@0 | 181 | intermCondition->traverse(this); |
michael@0 | 182 | if (TParentNodeSet* conditionNodes = mNodeSets.getTopSet()) { |
michael@0 | 183 | TGraphSelection* selection = mGraph->createSelection(intermSelection); |
michael@0 | 184 | connectMultipleNodesToSingleNode(conditionNodes, selection); |
michael@0 | 185 | } |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | if (TIntermNode* intermTrueBlock = intermSelection->getTrueBlock()) |
michael@0 | 189 | intermTrueBlock->traverse(this); |
michael@0 | 190 | |
michael@0 | 191 | if (TIntermNode* intermFalseBlock = intermSelection->getFalseBlock()) |
michael@0 | 192 | intermFalseBlock->traverse(this); |
michael@0 | 193 | |
michael@0 | 194 | return false; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | bool TDependencyGraphBuilder::visitLoop(Visit visit, TIntermLoop* intermLoop) |
michael@0 | 198 | { |
michael@0 | 199 | if (TIntermTyped* intermCondition = intermLoop->getCondition()) { |
michael@0 | 200 | TNodeSetMaintainer nodeSetMaintainer(this); |
michael@0 | 201 | |
michael@0 | 202 | intermCondition->traverse(this); |
michael@0 | 203 | if (TParentNodeSet* conditionNodes = mNodeSets.getTopSet()) { |
michael@0 | 204 | TGraphLoop* loop = mGraph->createLoop(intermLoop); |
michael@0 | 205 | connectMultipleNodesToSingleNode(conditionNodes, loop); |
michael@0 | 206 | } |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | if (TIntermNode* intermBody = intermLoop->getBody()) |
michael@0 | 210 | intermBody->traverse(this); |
michael@0 | 211 | |
michael@0 | 212 | if (TIntermTyped* intermExpression = intermLoop->getExpression()) |
michael@0 | 213 | intermExpression->traverse(this); |
michael@0 | 214 | |
michael@0 | 215 | return false; |
michael@0 | 216 | } |
michael@0 | 217 | |
michael@0 | 218 | |
michael@0 | 219 | void TDependencyGraphBuilder::connectMultipleNodesToSingleNode(TParentNodeSet* nodes, |
michael@0 | 220 | TGraphNode* node) const |
michael@0 | 221 | { |
michael@0 | 222 | for (TParentNodeSet::const_iterator iter = nodes->begin(); iter != nodes->end(); ++iter) |
michael@0 | 223 | { |
michael@0 | 224 | TGraphParentNode* currentNode = *iter; |
michael@0 | 225 | currentNode->addDependentNode(node); |
michael@0 | 226 | } |
michael@0 | 227 | } |