Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | // |
michael@0 | 2 | // Copyright (c) 2002-2010 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/ParseHelper.h" |
michael@0 | 8 | |
michael@0 | 9 | // |
michael@0 | 10 | // Use this class to carry along data from node to node in |
michael@0 | 11 | // the traversal |
michael@0 | 12 | // |
michael@0 | 13 | class TConstTraverser : public TIntermTraverser { |
michael@0 | 14 | public: |
michael@0 | 15 | TConstTraverser(ConstantUnion* cUnion, bool singleConstParam, TOperator constructType, TInfoSink& sink, TSymbolTable& symTable, TType& t) |
michael@0 | 16 | : error(false), |
michael@0 | 17 | index(0), |
michael@0 | 18 | unionArray(cUnion), |
michael@0 | 19 | type(t), |
michael@0 | 20 | constructorType(constructType), |
michael@0 | 21 | singleConstantParam(singleConstParam), |
michael@0 | 22 | infoSink(sink), |
michael@0 | 23 | symbolTable(symTable), |
michael@0 | 24 | size(0), |
michael@0 | 25 | isMatrix(false), |
michael@0 | 26 | matrixSize(0) { |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | bool error; |
michael@0 | 30 | |
michael@0 | 31 | protected: |
michael@0 | 32 | void visitSymbol(TIntermSymbol*); |
michael@0 | 33 | void visitConstantUnion(TIntermConstantUnion*); |
michael@0 | 34 | bool visitBinary(Visit visit, TIntermBinary*); |
michael@0 | 35 | bool visitUnary(Visit visit, TIntermUnary*); |
michael@0 | 36 | bool visitSelection(Visit visit, TIntermSelection*); |
michael@0 | 37 | bool visitAggregate(Visit visit, TIntermAggregate*); |
michael@0 | 38 | bool visitLoop(Visit visit, TIntermLoop*); |
michael@0 | 39 | bool visitBranch(Visit visit, TIntermBranch*); |
michael@0 | 40 | |
michael@0 | 41 | size_t index; |
michael@0 | 42 | ConstantUnion *unionArray; |
michael@0 | 43 | TType type; |
michael@0 | 44 | TOperator constructorType; |
michael@0 | 45 | bool singleConstantParam; |
michael@0 | 46 | TInfoSink& infoSink; |
michael@0 | 47 | TSymbolTable& symbolTable; |
michael@0 | 48 | size_t size; // size of the constructor ( 4 for vec4) |
michael@0 | 49 | bool isMatrix; |
michael@0 | 50 | size_t matrixSize; // dimension of the matrix (nominal size and not the instance size) |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | // |
michael@0 | 54 | // The rest of the file are the traversal functions. The last one |
michael@0 | 55 | // is the one that starts the traversal. |
michael@0 | 56 | // |
michael@0 | 57 | // Return true from interior nodes to have the external traversal |
michael@0 | 58 | // continue on to children. If you process children yourself, |
michael@0 | 59 | // return false. |
michael@0 | 60 | // |
michael@0 | 61 | |
michael@0 | 62 | void TConstTraverser::visitSymbol(TIntermSymbol* node) |
michael@0 | 63 | { |
michael@0 | 64 | infoSink.info.message(EPrefixInternalError, node->getLine(), "Symbol Node found in constant constructor"); |
michael@0 | 65 | return; |
michael@0 | 66 | |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | bool TConstTraverser::visitBinary(Visit visit, TIntermBinary* node) |
michael@0 | 70 | { |
michael@0 | 71 | TQualifier qualifier = node->getType().getQualifier(); |
michael@0 | 72 | |
michael@0 | 73 | if (qualifier != EvqConst) { |
michael@0 | 74 | TString buf; |
michael@0 | 75 | buf.append("'constructor' : assigning non-constant to "); |
michael@0 | 76 | buf.append(type.getCompleteString()); |
michael@0 | 77 | infoSink.info.message(EPrefixError, node->getLine(), buf.c_str()); |
michael@0 | 78 | error = true; |
michael@0 | 79 | return false; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | infoSink.info.message(EPrefixInternalError, node->getLine(), "Binary Node found in constant constructor"); |
michael@0 | 83 | |
michael@0 | 84 | return false; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | bool TConstTraverser::visitUnary(Visit visit, TIntermUnary* node) |
michael@0 | 88 | { |
michael@0 | 89 | TString buf; |
michael@0 | 90 | buf.append("'constructor' : assigning non-constant to "); |
michael@0 | 91 | buf.append(type.getCompleteString()); |
michael@0 | 92 | infoSink.info.message(EPrefixError, node->getLine(), buf.c_str()); |
michael@0 | 93 | error = true; |
michael@0 | 94 | return false; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | bool TConstTraverser::visitAggregate(Visit visit, TIntermAggregate* node) |
michael@0 | 98 | { |
michael@0 | 99 | if (!node->isConstructor() && node->getOp() != EOpComma) { |
michael@0 | 100 | TString buf; |
michael@0 | 101 | buf.append("'constructor' : assigning non-constant to "); |
michael@0 | 102 | buf.append(type.getCompleteString()); |
michael@0 | 103 | infoSink.info.message(EPrefixError, node->getLine(), buf.c_str()); |
michael@0 | 104 | error = true; |
michael@0 | 105 | return false; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | if (node->getSequence().size() == 0) { |
michael@0 | 109 | error = true; |
michael@0 | 110 | return false; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | bool flag = node->getSequence().size() == 1 && node->getSequence()[0]->getAsTyped()->getAsConstantUnion(); |
michael@0 | 114 | if (flag) |
michael@0 | 115 | { |
michael@0 | 116 | singleConstantParam = true; |
michael@0 | 117 | constructorType = node->getOp(); |
michael@0 | 118 | size = node->getType().getObjectSize(); |
michael@0 | 119 | |
michael@0 | 120 | if (node->getType().isMatrix()) { |
michael@0 | 121 | isMatrix = true; |
michael@0 | 122 | matrixSize = node->getType().getNominalSize(); |
michael@0 | 123 | } |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | for (TIntermSequence::iterator p = node->getSequence().begin(); |
michael@0 | 127 | p != node->getSequence().end(); p++) { |
michael@0 | 128 | |
michael@0 | 129 | if (node->getOp() == EOpComma) |
michael@0 | 130 | index = 0; |
michael@0 | 131 | |
michael@0 | 132 | (*p)->traverse(this); |
michael@0 | 133 | } |
michael@0 | 134 | if (flag) |
michael@0 | 135 | { |
michael@0 | 136 | singleConstantParam = false; |
michael@0 | 137 | constructorType = EOpNull; |
michael@0 | 138 | size = 0; |
michael@0 | 139 | isMatrix = false; |
michael@0 | 140 | matrixSize = 0; |
michael@0 | 141 | } |
michael@0 | 142 | return false; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | bool TConstTraverser::visitSelection(Visit visit, TIntermSelection* node) |
michael@0 | 146 | { |
michael@0 | 147 | infoSink.info.message(EPrefixInternalError, node->getLine(), "Selection Node found in constant constructor"); |
michael@0 | 148 | error = true; |
michael@0 | 149 | return false; |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node) |
michael@0 | 153 | { |
michael@0 | 154 | if (!node->getUnionArrayPointer()) |
michael@0 | 155 | { |
michael@0 | 156 | // The constant was not initialized, this should already have been logged |
michael@0 | 157 | assert(infoSink.info.size() != 0); |
michael@0 | 158 | return; |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | ConstantUnion* leftUnionArray = unionArray; |
michael@0 | 162 | size_t instanceSize = type.getObjectSize(); |
michael@0 | 163 | |
michael@0 | 164 | if (index >= instanceSize) |
michael@0 | 165 | return; |
michael@0 | 166 | |
michael@0 | 167 | if (!singleConstantParam) { |
michael@0 | 168 | size_t size = node->getType().getObjectSize(); |
michael@0 | 169 | |
michael@0 | 170 | ConstantUnion *rightUnionArray = node->getUnionArrayPointer(); |
michael@0 | 171 | for (size_t i = 0; i < size; i++) { |
michael@0 | 172 | if (index >= instanceSize) |
michael@0 | 173 | return; |
michael@0 | 174 | leftUnionArray[index] = rightUnionArray[i]; |
michael@0 | 175 | |
michael@0 | 176 | (index)++; |
michael@0 | 177 | } |
michael@0 | 178 | } else { |
michael@0 | 179 | size_t totalSize = index + size; |
michael@0 | 180 | ConstantUnion *rightUnionArray = node->getUnionArrayPointer(); |
michael@0 | 181 | if (!isMatrix) { |
michael@0 | 182 | size_t count = 0; |
michael@0 | 183 | for (size_t i = index; i < totalSize; i++) { |
michael@0 | 184 | if (i >= instanceSize) |
michael@0 | 185 | return; |
michael@0 | 186 | |
michael@0 | 187 | leftUnionArray[i] = rightUnionArray[count]; |
michael@0 | 188 | |
michael@0 | 189 | (index)++; |
michael@0 | 190 | |
michael@0 | 191 | if (node->getType().getObjectSize() > 1) |
michael@0 | 192 | count++; |
michael@0 | 193 | } |
michael@0 | 194 | } else { // for matrix constructors |
michael@0 | 195 | size_t count = 0; |
michael@0 | 196 | size_t element = index; |
michael@0 | 197 | for (size_t i = index; i < totalSize; i++) { |
michael@0 | 198 | if (i >= instanceSize) |
michael@0 | 199 | return; |
michael@0 | 200 | if (element - i == 0 || (i - element) % (matrixSize + 1) == 0 ) |
michael@0 | 201 | leftUnionArray[i] = rightUnionArray[count]; |
michael@0 | 202 | else |
michael@0 | 203 | leftUnionArray[i].setFConst(0.0f); |
michael@0 | 204 | |
michael@0 | 205 | (index)++; |
michael@0 | 206 | |
michael@0 | 207 | if (node->getType().getObjectSize() > 1) |
michael@0 | 208 | count++; |
michael@0 | 209 | } |
michael@0 | 210 | } |
michael@0 | 211 | } |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | bool TConstTraverser::visitLoop(Visit visit, TIntermLoop* node) |
michael@0 | 215 | { |
michael@0 | 216 | infoSink.info.message(EPrefixInternalError, node->getLine(), "Loop Node found in constant constructor"); |
michael@0 | 217 | error = true; |
michael@0 | 218 | return false; |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | bool TConstTraverser::visitBranch(Visit visit, TIntermBranch* node) |
michael@0 | 222 | { |
michael@0 | 223 | infoSink.info.message(EPrefixInternalError, node->getLine(), "Branch Node found in constant constructor"); |
michael@0 | 224 | error = true; |
michael@0 | 225 | return false; |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | // |
michael@0 | 229 | // This function is the one to call externally to start the traversal. |
michael@0 | 230 | // Individual functions can be initialized to 0 to skip processing of that |
michael@0 | 231 | // type of node. It's children will still be processed. |
michael@0 | 232 | // |
michael@0 | 233 | bool TIntermediate::parseConstTree(const TSourceLoc& line, TIntermNode* root, ConstantUnion* unionArray, TOperator constructorType, TSymbolTable& symbolTable, TType t, bool singleConstantParam) |
michael@0 | 234 | { |
michael@0 | 235 | if (root == 0) |
michael@0 | 236 | return false; |
michael@0 | 237 | |
michael@0 | 238 | TConstTraverser it(unionArray, singleConstantParam, constructorType, infoSink, symbolTable, t); |
michael@0 | 239 | |
michael@0 | 240 | root->traverse(&it); |
michael@0 | 241 | if (it.error) |
michael@0 | 242 | return true; |
michael@0 | 243 | else |
michael@0 | 244 | return false; |
michael@0 | 245 | } |