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) 2002-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 | // |
michael@0 | 8 | // Symbol table for parsing. Most functionaliy and main ideas |
michael@0 | 9 | // are documented in the header file. |
michael@0 | 10 | // |
michael@0 | 11 | |
michael@0 | 12 | #if defined(_MSC_VER) |
michael@0 | 13 | #pragma warning(disable: 4718) |
michael@0 | 14 | #endif |
michael@0 | 15 | |
michael@0 | 16 | #include "compiler/SymbolTable.h" |
michael@0 | 17 | |
michael@0 | 18 | #include <stdio.h> |
michael@0 | 19 | #include <algorithm> |
michael@0 | 20 | #include <climits> |
michael@0 | 21 | |
michael@0 | 22 | TType::TType(const TPublicType &p) : |
michael@0 | 23 | type(p.type), precision(p.precision), qualifier(p.qualifier), size(p.size), matrix(p.matrix), array(p.array), arraySize(p.arraySize), structure(0) |
michael@0 | 24 | { |
michael@0 | 25 | if (p.userDef) |
michael@0 | 26 | structure = p.userDef->getStruct(); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | // |
michael@0 | 30 | // Recursively generate mangled names. |
michael@0 | 31 | // |
michael@0 | 32 | TString TType::buildMangledName() const |
michael@0 | 33 | { |
michael@0 | 34 | TString mangledName; |
michael@0 | 35 | if (isMatrix()) |
michael@0 | 36 | mangledName += 'm'; |
michael@0 | 37 | else if (isVector()) |
michael@0 | 38 | mangledName += 'v'; |
michael@0 | 39 | |
michael@0 | 40 | switch (type) { |
michael@0 | 41 | case EbtFloat: mangledName += 'f'; break; |
michael@0 | 42 | case EbtInt: mangledName += 'i'; break; |
michael@0 | 43 | case EbtBool: mangledName += 'b'; break; |
michael@0 | 44 | case EbtSampler2D: mangledName += "s2"; break; |
michael@0 | 45 | case EbtSamplerCube: mangledName += "sC"; break; |
michael@0 | 46 | case EbtStruct: mangledName += structure->mangledName(); break; |
michael@0 | 47 | default: break; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | mangledName += static_cast<char>('0' + getNominalSize()); |
michael@0 | 51 | if (isArray()) { |
michael@0 | 52 | char buf[20]; |
michael@0 | 53 | snprintf(buf, sizeof(buf), "%d", arraySize); |
michael@0 | 54 | mangledName += '['; |
michael@0 | 55 | mangledName += buf; |
michael@0 | 56 | mangledName += ']'; |
michael@0 | 57 | } |
michael@0 | 58 | return mangledName; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | size_t TType::getObjectSize() const |
michael@0 | 62 | { |
michael@0 | 63 | size_t totalSize = 0; |
michael@0 | 64 | |
michael@0 | 65 | if (getBasicType() == EbtStruct) |
michael@0 | 66 | totalSize = structure->objectSize(); |
michael@0 | 67 | else if (matrix) |
michael@0 | 68 | totalSize = size * size; |
michael@0 | 69 | else |
michael@0 | 70 | totalSize = size; |
michael@0 | 71 | |
michael@0 | 72 | if (isArray()) { |
michael@0 | 73 | size_t arraySize = getArraySize(); |
michael@0 | 74 | if (arraySize > INT_MAX / totalSize) |
michael@0 | 75 | totalSize = INT_MAX; |
michael@0 | 76 | else |
michael@0 | 77 | totalSize *= arraySize; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | return totalSize; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | bool TStructure::containsArrays() const |
michael@0 | 84 | { |
michael@0 | 85 | for (size_t i = 0; i < mFields->size(); ++i) { |
michael@0 | 86 | const TType* fieldType = (*mFields)[i]->type(); |
michael@0 | 87 | if (fieldType->isArray() || fieldType->isStructureContainingArrays()) |
michael@0 | 88 | return true; |
michael@0 | 89 | } |
michael@0 | 90 | return false; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | TString TStructure::buildMangledName() const |
michael@0 | 94 | { |
michael@0 | 95 | TString mangledName("struct-"); |
michael@0 | 96 | mangledName += *mName; |
michael@0 | 97 | for (size_t i = 0; i < mFields->size(); ++i) { |
michael@0 | 98 | mangledName += '-'; |
michael@0 | 99 | mangledName += (*mFields)[i]->type()->getMangledName(); |
michael@0 | 100 | } |
michael@0 | 101 | return mangledName; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | size_t TStructure::calculateObjectSize() const |
michael@0 | 105 | { |
michael@0 | 106 | size_t size = 0; |
michael@0 | 107 | for (size_t i = 0; i < mFields->size(); ++i) { |
michael@0 | 108 | size_t fieldSize = (*mFields)[i]->type()->getObjectSize(); |
michael@0 | 109 | if (fieldSize > INT_MAX - size) |
michael@0 | 110 | size = INT_MAX; |
michael@0 | 111 | else |
michael@0 | 112 | size += fieldSize; |
michael@0 | 113 | } |
michael@0 | 114 | return size; |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | int TStructure::calculateDeepestNesting() const |
michael@0 | 118 | { |
michael@0 | 119 | int maxNesting = 0; |
michael@0 | 120 | for (size_t i = 0; i < mFields->size(); ++i) { |
michael@0 | 121 | maxNesting = std::max(maxNesting, (*mFields)[i]->type()->getDeepestStructNesting()); |
michael@0 | 122 | } |
michael@0 | 123 | return 1 + maxNesting; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | // |
michael@0 | 127 | // Dump functions. |
michael@0 | 128 | // |
michael@0 | 129 | |
michael@0 | 130 | void TVariable::dump(TInfoSink& infoSink) const |
michael@0 | 131 | { |
michael@0 | 132 | infoSink.debug << getName().c_str() << ": " << type.getQualifierString() << " " << type.getPrecisionString() << " " << type.getBasicString(); |
michael@0 | 133 | if (type.isArray()) { |
michael@0 | 134 | infoSink.debug << "[0]"; |
michael@0 | 135 | } |
michael@0 | 136 | infoSink.debug << "\n"; |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | void TFunction::dump(TInfoSink &infoSink) const |
michael@0 | 140 | { |
michael@0 | 141 | infoSink.debug << getName().c_str() << ": " << returnType.getBasicString() << " " << getMangledName().c_str() << "\n"; |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | void TSymbolTableLevel::dump(TInfoSink &infoSink) const |
michael@0 | 145 | { |
michael@0 | 146 | tLevel::const_iterator it; |
michael@0 | 147 | for (it = level.begin(); it != level.end(); ++it) |
michael@0 | 148 | (*it).second->dump(infoSink); |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | void TSymbolTable::dump(TInfoSink &infoSink) const |
michael@0 | 152 | { |
michael@0 | 153 | for (int level = currentLevel(); level >= 0; --level) { |
michael@0 | 154 | infoSink.debug << "LEVEL " << level << "\n"; |
michael@0 | 155 | table[level]->dump(infoSink); |
michael@0 | 156 | } |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | // |
michael@0 | 160 | // Functions have buried pointers to delete. |
michael@0 | 161 | // |
michael@0 | 162 | TFunction::~TFunction() |
michael@0 | 163 | { |
michael@0 | 164 | for (TParamList::iterator i = parameters.begin(); i != parameters.end(); ++i) |
michael@0 | 165 | delete (*i).type; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | // |
michael@0 | 169 | // Symbol table levels are a map of pointers to symbols that have to be deleted. |
michael@0 | 170 | // |
michael@0 | 171 | TSymbolTableLevel::~TSymbolTableLevel() |
michael@0 | 172 | { |
michael@0 | 173 | for (tLevel::iterator it = level.begin(); it != level.end(); ++it) |
michael@0 | 174 | if ((*it).first == (*it).second->getMangledName()) |
michael@0 | 175 | delete (*it).second; |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | // |
michael@0 | 179 | // Change all function entries in the table with the non-mangled name |
michael@0 | 180 | // to be related to the provided built-in operation. This is a low |
michael@0 | 181 | // performance operation, and only intended for symbol tables that |
michael@0 | 182 | // live across a large number of compiles. |
michael@0 | 183 | // |
michael@0 | 184 | void TSymbolTableLevel::relateToOperator(const char* name, TOperator op) |
michael@0 | 185 | { |
michael@0 | 186 | tLevel::iterator it; |
michael@0 | 187 | for (it = level.begin(); it != level.end(); ++it) { |
michael@0 | 188 | if ((*it).second->isFunction()) { |
michael@0 | 189 | TFunction* function = static_cast<TFunction*>((*it).second); |
michael@0 | 190 | if (function->getName() == name) |
michael@0 | 191 | function->relateToOperator(op); |
michael@0 | 192 | } |
michael@0 | 193 | } |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | // |
michael@0 | 197 | // Change all function entries in the table with the non-mangled name |
michael@0 | 198 | // to be related to the provided built-in extension. This is a low |
michael@0 | 199 | // performance operation, and only intended for symbol tables that |
michael@0 | 200 | // live across a large number of compiles. |
michael@0 | 201 | // |
michael@0 | 202 | void TSymbolTableLevel::relateToExtension(const char* name, const TString& ext) |
michael@0 | 203 | { |
michael@0 | 204 | for (tLevel::iterator it = level.begin(); it != level.end(); ++it) { |
michael@0 | 205 | TSymbol* symbol = it->second; |
michael@0 | 206 | if (symbol->getName() == name) |
michael@0 | 207 | symbol->relateToExtension(ext); |
michael@0 | 208 | } |
michael@0 | 209 | } |