daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2010 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 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 7 | #include "compiler/ParseHelper.h" |
| 8 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 9 | #include <stdarg.h> |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 10 | |
| 11 | #include "compiler/osinclude.h" |
| 12 | #include "compiler/InitializeParseContext.h" |
| 13 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 14 | /////////////////////////////////////////////////////////////////////// |
| 15 | // |
| 16 | // Sub- vector and matrix fields |
| 17 | // |
| 18 | //////////////////////////////////////////////////////////////////////// |
| 19 | |
| 20 | // |
| 21 | // Look at a '.' field selector string and change it into offsets |
| 22 | // for a vector. |
| 23 | // |
| 24 | bool TParseContext::parseVectorFields(const TString& compString, int vecSize, TVectorFields& fields, int line) |
| 25 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 26 | fields.num = (int) compString.size(); |
| 27 | if (fields.num > 4) { |
| 28 | error(line, "illegal vector field selection", compString.c_str(), ""); |
| 29 | return false; |
| 30 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 31 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 32 | enum { |
| 33 | exyzw, |
| 34 | ergba, |
| 35 | estpq, |
| 36 | } fieldSet[4]; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 37 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 38 | for (int i = 0; i < fields.num; ++i) { |
| 39 | switch (compString[i]) { |
| 40 | case 'x': |
| 41 | fields.offsets[i] = 0; |
| 42 | fieldSet[i] = exyzw; |
| 43 | break; |
| 44 | case 'r': |
| 45 | fields.offsets[i] = 0; |
| 46 | fieldSet[i] = ergba; |
| 47 | break; |
| 48 | case 's': |
| 49 | fields.offsets[i] = 0; |
| 50 | fieldSet[i] = estpq; |
| 51 | break; |
| 52 | case 'y': |
| 53 | fields.offsets[i] = 1; |
| 54 | fieldSet[i] = exyzw; |
| 55 | break; |
| 56 | case 'g': |
| 57 | fields.offsets[i] = 1; |
| 58 | fieldSet[i] = ergba; |
| 59 | break; |
| 60 | case 't': |
| 61 | fields.offsets[i] = 1; |
| 62 | fieldSet[i] = estpq; |
| 63 | break; |
| 64 | case 'z': |
| 65 | fields.offsets[i] = 2; |
| 66 | fieldSet[i] = exyzw; |
| 67 | break; |
| 68 | case 'b': |
| 69 | fields.offsets[i] = 2; |
| 70 | fieldSet[i] = ergba; |
| 71 | break; |
| 72 | case 'p': |
| 73 | fields.offsets[i] = 2; |
| 74 | fieldSet[i] = estpq; |
| 75 | break; |
| 76 | |
| 77 | case 'w': |
| 78 | fields.offsets[i] = 3; |
| 79 | fieldSet[i] = exyzw; |
| 80 | break; |
| 81 | case 'a': |
| 82 | fields.offsets[i] = 3; |
| 83 | fieldSet[i] = ergba; |
| 84 | break; |
| 85 | case 'q': |
| 86 | fields.offsets[i] = 3; |
| 87 | fieldSet[i] = estpq; |
| 88 | break; |
| 89 | default: |
| 90 | error(line, "illegal vector field selection", compString.c_str(), ""); |
| 91 | return false; |
| 92 | } |
| 93 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 94 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 95 | for (int i = 0; i < fields.num; ++i) { |
| 96 | if (fields.offsets[i] >= vecSize) { |
| 97 | error(line, "vector field selection out of range", compString.c_str(), ""); |
| 98 | return false; |
| 99 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 100 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 101 | if (i > 0) { |
| 102 | if (fieldSet[i] != fieldSet[i-1]) { |
| 103 | error(line, "illegal - vector component fields not from the same set", compString.c_str(), ""); |
| 104 | return false; |
| 105 | } |
| 106 | } |
| 107 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 108 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 109 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | |
| 113 | // |
| 114 | // Look at a '.' field selector string and change it into offsets |
| 115 | // for a matrix. |
| 116 | // |
| 117 | bool TParseContext::parseMatrixFields(const TString& compString, int matSize, TMatrixFields& fields, int line) |
| 118 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 119 | fields.wholeRow = false; |
| 120 | fields.wholeCol = false; |
| 121 | fields.row = -1; |
| 122 | fields.col = -1; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 123 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 124 | if (compString.size() != 2) { |
| 125 | error(line, "illegal length of matrix field selection", compString.c_str(), ""); |
| 126 | return false; |
| 127 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 128 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 129 | if (compString[0] == '_') { |
| 130 | if (compString[1] < '0' || compString[1] > '3') { |
| 131 | error(line, "illegal matrix field selection", compString.c_str(), ""); |
| 132 | return false; |
| 133 | } |
| 134 | fields.wholeCol = true; |
| 135 | fields.col = compString[1] - '0'; |
| 136 | } else if (compString[1] == '_') { |
| 137 | if (compString[0] < '0' || compString[0] > '3') { |
| 138 | error(line, "illegal matrix field selection", compString.c_str(), ""); |
| 139 | return false; |
| 140 | } |
| 141 | fields.wholeRow = true; |
| 142 | fields.row = compString[0] - '0'; |
| 143 | } else { |
| 144 | if (compString[0] < '0' || compString[0] > '3' || |
| 145 | compString[1] < '0' || compString[1] > '3') { |
| 146 | error(line, "illegal matrix field selection", compString.c_str(), ""); |
| 147 | return false; |
| 148 | } |
| 149 | fields.row = compString[0] - '0'; |
| 150 | fields.col = compString[1] - '0'; |
| 151 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 152 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 153 | if (fields.row >= matSize || fields.col >= matSize) { |
| 154 | error(line, "matrix field selection out of range", compString.c_str(), ""); |
| 155 | return false; |
| 156 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 157 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 158 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /////////////////////////////////////////////////////////////////////// |
| 162 | // |
| 163 | // Errors |
| 164 | // |
| 165 | //////////////////////////////////////////////////////////////////////// |
| 166 | |
| 167 | // |
| 168 | // Track whether errors have occurred. |
| 169 | // |
| 170 | void TParseContext::recover() |
| 171 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 172 | recoveredFromError = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | // |
| 176 | // Used by flex/bison to output all syntax and parsing errors. |
| 177 | // |
| 178 | void C_DECL TParseContext::error(TSourceLoc nLine, const char *szReason, const char *szToken, |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 179 | const char *szExtraInfoFormat, ...) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 180 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 181 | char szExtraInfo[400]; |
| 182 | va_list marker; |
alokp@chromium.org | ff42c63 | 2010-05-10 15:14:30 +0000 | [diff] [blame^] | 183 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 184 | va_start(marker, szExtraInfoFormat); |
alokp@chromium.org | ff42c63 | 2010-05-10 15:14:30 +0000 | [diff] [blame^] | 185 | |
| 186 | vsnprintf(szExtraInfo, sizeof(szExtraInfo), szExtraInfoFormat, marker); |
| 187 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 188 | /* VC++ format: file(linenum) : error #: 'token' : extrainfo */ |
| 189 | infoSink.info.prefix(EPrefixError); |
| 190 | infoSink.info.location(nLine); |
| 191 | infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n"; |
alokp@chromium.org | ff42c63 | 2010-05-10 15:14:30 +0000 | [diff] [blame^] | 192 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 193 | va_end(marker); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 194 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 195 | ++numErrors; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | // |
| 199 | // Same error message for all places assignments don't work. |
| 200 | // |
| 201 | void TParseContext::assignError(int line, const char* op, TString left, TString right) |
| 202 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 203 | error(line, "", op, "cannot convert from '%s' to '%s'", |
| 204 | right.c_str(), left.c_str()); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | // |
| 208 | // Same error message for all places unary operations don't work. |
| 209 | // |
| 210 | void TParseContext::unaryOpError(int line, const char* op, TString operand) |
| 211 | { |
| 212 | error(line, " wrong operand type", op, |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 213 | "no operation '%s' exists that takes an operand of type %s (or there is no acceptable conversion)", |
| 214 | op, operand.c_str()); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | // |
| 218 | // Same error message for all binary operations don't work. |
| 219 | // |
| 220 | void TParseContext::binaryOpError(int line, const char* op, TString left, TString right) |
| 221 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 222 | error(line, " wrong operand types ", op, |
| 223 | "no operation '%s' exists that takes a left-hand operand of type '%s' and " |
| 224 | "a right operand of type '%s' (or there is no acceptable conversion)", |
| 225 | op, left.c_str(), right.c_str()); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | // |
| 229 | // Both test and if necessary, spit out an error, to see if the node is really |
| 230 | // an l-value that can be operated on this way. |
| 231 | // |
| 232 | // Returns true if the was an error. |
| 233 | // |
| 234 | bool TParseContext::lValueErrorCheck(int line, const char* op, TIntermTyped* node) |
| 235 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 236 | TIntermSymbol* symNode = node->getAsSymbolNode(); |
| 237 | TIntermBinary* binaryNode = node->getAsBinaryNode(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 238 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 239 | if (binaryNode) { |
| 240 | bool errorReturn; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 241 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 242 | switch(binaryNode->getOp()) { |
| 243 | case EOpIndexDirect: |
| 244 | case EOpIndexIndirect: |
| 245 | case EOpIndexDirectStruct: |
| 246 | return lValueErrorCheck(line, op, binaryNode->getLeft()); |
| 247 | case EOpVectorSwizzle: |
| 248 | errorReturn = lValueErrorCheck(line, op, binaryNode->getLeft()); |
| 249 | if (!errorReturn) { |
| 250 | int offset[4] = {0,0,0,0}; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 251 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 252 | TIntermTyped* rightNode = binaryNode->getRight(); |
| 253 | TIntermAggregate *aggrNode = rightNode->getAsAggregate(); |
| 254 | |
| 255 | for (TIntermSequence::iterator p = aggrNode->getSequence().begin(); |
| 256 | p != aggrNode->getSequence().end(); p++) { |
| 257 | int value = (*p)->getAsTyped()->getAsConstantUnion()->getUnionArrayPointer()->getIConst(); |
| 258 | offset[value]++; |
| 259 | if (offset[value] > 1) { |
| 260 | error(line, " l-value of swizzle cannot have duplicate components", op, "", ""); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 261 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 262 | return true; |
| 263 | } |
| 264 | } |
| 265 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 266 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 267 | return errorReturn; |
| 268 | default: |
| 269 | break; |
| 270 | } |
| 271 | error(line, " l-value required", op, "", ""); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 272 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 273 | return true; |
| 274 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 275 | |
| 276 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 277 | const char* symbol = 0; |
| 278 | if (symNode != 0) |
| 279 | symbol = symNode->getSymbol().c_str(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 280 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 281 | const char* message = 0; |
| 282 | switch (node->getQualifier()) { |
| 283 | case EvqConst: message = "can't modify a const"; break; |
| 284 | case EvqConstReadOnly: message = "can't modify a const"; break; |
| 285 | case EvqAttribute: message = "can't modify an attribute"; break; |
| 286 | case EvqUniform: message = "can't modify a uniform"; break; |
| 287 | case EvqVaryingIn: message = "can't modify a varying"; break; |
| 288 | case EvqInput: message = "can't modify an input"; break; |
| 289 | case EvqFragCoord: message = "can't modify gl_FragCoord"; break; |
| 290 | case EvqFrontFacing: message = "can't modify gl_FrontFacing"; break; |
| 291 | case EvqPointCoord: message = "can't modify gl_PointCoord"; break; |
| 292 | default: |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 293 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 294 | // |
| 295 | // Type that can't be written to? |
| 296 | // |
| 297 | switch (node->getBasicType()) { |
| 298 | case EbtSampler2D: |
| 299 | case EbtSamplerCube: |
| 300 | message = "can't modify a sampler"; |
| 301 | break; |
| 302 | case EbtVoid: |
| 303 | message = "can't modify void"; |
| 304 | break; |
| 305 | default: |
| 306 | break; |
| 307 | } |
| 308 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 309 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 310 | if (message == 0 && binaryNode == 0 && symNode == 0) { |
| 311 | error(line, " l-value required", op, "", ""); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 312 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 313 | return true; |
| 314 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 315 | |
| 316 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 317 | // |
| 318 | // Everything else is okay, no error. |
| 319 | // |
| 320 | if (message == 0) |
| 321 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 322 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 323 | // |
| 324 | // If we get here, we have an error and a message. |
| 325 | // |
| 326 | if (symNode) |
| 327 | error(line, " l-value required", op, "\"%s\" (%s)", symbol, message); |
| 328 | else |
| 329 | error(line, " l-value required", op, "(%s)", message); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 330 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 331 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | // |
| 335 | // Both test, and if necessary spit out an error, to see if the node is really |
| 336 | // a constant. |
| 337 | // |
| 338 | // Returns true if the was an error. |
| 339 | // |
| 340 | bool TParseContext::constErrorCheck(TIntermTyped* node) |
| 341 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 342 | if (node->getQualifier() == EvqConst) |
| 343 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 344 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 345 | error(node->getLine(), "constant expression required", "", ""); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 346 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 347 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | // |
| 351 | // Both test, and if necessary spit out an error, to see if the node is really |
| 352 | // an integer. |
| 353 | // |
| 354 | // Returns true if the was an error. |
| 355 | // |
| 356 | bool TParseContext::integerErrorCheck(TIntermTyped* node, const char* token) |
| 357 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 358 | if (node->getBasicType() == EbtInt && node->getNominalSize() == 1) |
| 359 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 360 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 361 | error(node->getLine(), "integer expression required", token, ""); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 362 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 363 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | // |
| 367 | // Both test, and if necessary spit out an error, to see if we are currently |
| 368 | // globally scoped. |
| 369 | // |
| 370 | // Returns true if the was an error. |
| 371 | // |
| 372 | bool TParseContext::globalErrorCheck(int line, bool global, const char* token) |
| 373 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 374 | if (global) |
| 375 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 376 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 377 | error(line, "only allowed at global scope", token, ""); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 378 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 379 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | // |
| 383 | // For now, keep it simple: if it starts "gl_", it's reserved, independent |
| 384 | // of scope. Except, if the symbol table is at the built-in push-level, |
| 385 | // which is when we are parsing built-ins. |
| 386 | // |
| 387 | // Returns true if there was an error. |
| 388 | // |
| 389 | bool TParseContext::reservedErrorCheck(int line, const TString& identifier) |
| 390 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 391 | if (!symbolTable.atBuiltInLevel()) { |
| 392 | if (identifier.substr(0, 3) == TString("gl_")) { |
| 393 | error(line, "reserved built-in name", "gl_", ""); |
| 394 | return true; |
| 395 | } |
| 396 | if (identifier.find("__") != TString::npos) { |
| 397 | //error(line, "Two consecutive underscores are reserved for future use.", identifier.c_str(), "", ""); |
| 398 | //return true; |
| 399 | infoSink.info.message(EPrefixWarning, "Two consecutive underscores are reserved for future use.", line); |
| 400 | return false; |
| 401 | } |
| 402 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 403 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 404 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | // |
| 408 | // Make sure there is enough data provided to the constructor to build |
| 409 | // something of the type of the constructor. Also returns the type of |
| 410 | // the constructor. |
| 411 | // |
| 412 | // Returns true if there was an error in construction. |
| 413 | // |
| 414 | bool TParseContext::constructorErrorCheck(int line, TIntermNode* node, TFunction& function, TOperator op, TType* type) |
| 415 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 416 | *type = function.getReturnType(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 417 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 418 | bool constructingMatrix = false; |
| 419 | switch(op) { |
| 420 | case EOpConstructMat2: |
| 421 | case EOpConstructMat3: |
| 422 | case EOpConstructMat4: |
| 423 | constructingMatrix = true; |
| 424 | break; |
| 425 | default: |
| 426 | break; |
| 427 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 428 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 429 | // |
| 430 | // Note: It's okay to have too many components available, but not okay to have unused |
| 431 | // arguments. 'full' will go to true when enough args have been seen. If we loop |
| 432 | // again, there is an extra argument, so 'overfull' will become true. |
| 433 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 434 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 435 | int size = 0; |
| 436 | bool constType = true; |
| 437 | bool full = false; |
| 438 | bool overFull = false; |
| 439 | bool matrixInMatrix = false; |
| 440 | bool arrayArg = false; |
| 441 | for (int i = 0; i < function.getParamCount(); ++i) { |
| 442 | size += function[i].type->getObjectSize(); |
| 443 | |
| 444 | if (constructingMatrix && function[i].type->isMatrix()) |
| 445 | matrixInMatrix = true; |
| 446 | if (full) |
| 447 | overFull = true; |
| 448 | if (op != EOpConstructStruct && !type->isArray() && size >= type->getObjectSize()) |
| 449 | full = true; |
| 450 | if (function[i].type->getQualifier() != EvqConst) |
| 451 | constType = false; |
| 452 | if (function[i].type->isArray()) |
| 453 | arrayArg = true; |
| 454 | } |
| 455 | |
| 456 | if (constType) |
| 457 | type->changeQualifier(EvqConst); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 458 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 459 | if (type->isArray() && type->getArraySize() != function.getParamCount()) { |
| 460 | error(line, "array constructor needs one argument per array element", "constructor", ""); |
| 461 | return true; |
| 462 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 463 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 464 | if (arrayArg && op != EOpConstructStruct) { |
| 465 | error(line, "constructing from a non-dereferenced array", "constructor", ""); |
| 466 | return true; |
| 467 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 468 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 469 | if (matrixInMatrix && !type->isArray()) { |
daniel@transgaming.com | bef0b6d | 2010-04-29 03:32:39 +0000 | [diff] [blame] | 470 | if (function.getParamCount() != 1) { |
| 471 | error(line, "constructing matrix from matrix can only take one argument", "constructor", ""); |
| 472 | return true; |
| 473 | } |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 474 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 475 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 476 | if (overFull) { |
| 477 | error(line, "too many arguments", "constructor", ""); |
| 478 | return true; |
| 479 | } |
| 480 | |
| 481 | if (op == EOpConstructStruct && !type->isArray() && type->getStruct()->size() != function.getParamCount()) { |
| 482 | error(line, "Number of constructor parameters does not match the number of structure fields", "constructor", ""); |
| 483 | return true; |
| 484 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 485 | |
daniel@transgaming.com | bef0b6d | 2010-04-29 03:32:39 +0000 | [diff] [blame] | 486 | if (!type->isMatrix()) { |
| 487 | if ((op != EOpConstructStruct && size != 1 && size < type->getObjectSize()) || |
| 488 | (op == EOpConstructStruct && size < type->getObjectSize())) { |
| 489 | error(line, "not enough data provided for construction", "constructor", ""); |
| 490 | return true; |
| 491 | } |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 492 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 493 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 494 | TIntermTyped* typed = node->getAsTyped(); |
| 495 | if (typed == 0) { |
| 496 | error(line, "constructor argument does not have a type", "constructor", ""); |
| 497 | return true; |
| 498 | } |
| 499 | if (op != EOpConstructStruct && IsSampler(typed->getBasicType())) { |
| 500 | error(line, "cannot convert a sampler", "constructor", ""); |
| 501 | return true; |
| 502 | } |
| 503 | if (typed->getBasicType() == EbtVoid) { |
| 504 | error(line, "cannot convert a void", "constructor", ""); |
| 505 | return true; |
| 506 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 507 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 508 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | // This function checks to see if a void variable has been declared and raise an error message for such a case |
| 512 | // |
| 513 | // returns true in case of an error |
| 514 | // |
| 515 | bool TParseContext::voidErrorCheck(int line, const TString& identifier, const TPublicType& pubType) |
| 516 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 517 | if (pubType.type == EbtVoid) { |
| 518 | error(line, "illegal use of type 'void'", identifier.c_str(), ""); |
| 519 | return true; |
| 520 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 521 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 522 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | // This function checks to see if the node (for the expression) contains a scalar boolean expression or not |
| 526 | // |
| 527 | // returns true in case of an error |
| 528 | // |
| 529 | bool TParseContext::boolErrorCheck(int line, const TIntermTyped* type) |
| 530 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 531 | if (type->getBasicType() != EbtBool || type->isArray() || type->isMatrix() || type->isVector()) { |
| 532 | error(line, "boolean expression expected", "", ""); |
| 533 | return true; |
| 534 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 535 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 536 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | // This function checks to see if the node (for the expression) contains a scalar boolean expression or not |
| 540 | // |
| 541 | // returns true in case of an error |
| 542 | // |
| 543 | bool TParseContext::boolErrorCheck(int line, const TPublicType& pType) |
| 544 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 545 | if (pType.type != EbtBool || pType.array || pType.matrix || (pType.size > 1)) { |
| 546 | error(line, "boolean expression expected", "", ""); |
| 547 | return true; |
| 548 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 549 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 550 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | bool TParseContext::samplerErrorCheck(int line, const TPublicType& pType, const char* reason) |
| 554 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 555 | if (pType.type == EbtStruct) { |
| 556 | if (containsSampler(*pType.userDef)) { |
| 557 | error(line, reason, TType::getBasicString(pType.type), "(structure contains a sampler)"); |
| 558 | |
| 559 | return true; |
| 560 | } |
| 561 | |
| 562 | return false; |
| 563 | } else if (IsSampler(pType.type)) { |
| 564 | error(line, reason, TType::getBasicString(pType.type), ""); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 565 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 566 | return true; |
| 567 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 568 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 569 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | bool TParseContext::structQualifierErrorCheck(int line, const TPublicType& pType) |
| 573 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 574 | if ((pType.qualifier == EvqVaryingIn || pType.qualifier == EvqVaryingOut || pType.qualifier == EvqAttribute) && |
| 575 | pType.type == EbtStruct) { |
| 576 | error(line, "cannot be used with a structure", getQualifierString(pType.qualifier), ""); |
| 577 | |
| 578 | return true; |
| 579 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 580 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 581 | if (pType.qualifier != EvqUniform && samplerErrorCheck(line, pType, "samplers must be uniform")) |
| 582 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 583 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 584 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | bool TParseContext::parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type) |
| 588 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 589 | if ((qualifier == EvqOut || qualifier == EvqInOut) && |
| 590 | type.getBasicType() != EbtStruct && IsSampler(type.getBasicType())) { |
| 591 | error(line, "samplers cannot be output parameters", type.getBasicString(), ""); |
| 592 | return true; |
| 593 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 594 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 595 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | bool TParseContext::containsSampler(TType& type) |
| 599 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 600 | if (IsSampler(type.getBasicType())) |
| 601 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 602 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 603 | if (type.getBasicType() == EbtStruct) { |
| 604 | TTypeList& structure = *type.getStruct(); |
| 605 | for (unsigned int i = 0; i < structure.size(); ++i) { |
| 606 | if (containsSampler(*structure[i].type)) |
| 607 | return true; |
| 608 | } |
| 609 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 610 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 611 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | // |
| 615 | // Do size checking for an array type's size. |
| 616 | // |
| 617 | // Returns true if there was an error. |
| 618 | // |
| 619 | bool TParseContext::arraySizeErrorCheck(int line, TIntermTyped* expr, int& size) |
| 620 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 621 | TIntermConstantUnion* constant = expr->getAsConstantUnion(); |
| 622 | if (constant == 0 || constant->getBasicType() != EbtInt) { |
| 623 | error(line, "array size must be a constant integer expression", "", ""); |
| 624 | return true; |
| 625 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 626 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 627 | size = constant->getUnionArrayPointer()->getIConst(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 628 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 629 | if (size <= 0) { |
| 630 | error(line, "array size must be a positive integer", "", ""); |
| 631 | size = 1; |
| 632 | return true; |
| 633 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 634 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 635 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | // |
| 639 | // See if this qualifier can be an array. |
| 640 | // |
| 641 | // Returns true if there is an error. |
| 642 | // |
| 643 | bool TParseContext::arrayQualifierErrorCheck(int line, TPublicType type) |
| 644 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 645 | if (type.qualifier == EvqAttribute) { |
| 646 | error(line, "cannot declare arrays of this qualifier", TType(type).getCompleteString().c_str(), ""); |
| 647 | return true; |
| 648 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 649 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 650 | if (type.qualifier == EvqConst && extensionErrorCheck(line, "GL_3DL_array_objects")) |
| 651 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 652 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 653 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | // |
| 657 | // See if this type can be an array. |
| 658 | // |
| 659 | // Returns true if there is an error. |
| 660 | // |
| 661 | bool TParseContext::arrayTypeErrorCheck(int line, TPublicType type) |
| 662 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 663 | // |
| 664 | // Can the type be an array? |
| 665 | // |
| 666 | if (type.array) { |
| 667 | error(line, "cannot declare arrays of arrays", TType(type).getCompleteString().c_str(), ""); |
| 668 | return true; |
| 669 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 670 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 671 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | // |
| 675 | // Do all the semantic checking for declaring an array, with and |
| 676 | // without a size, and make the right changes to the symbol table. |
| 677 | // |
| 678 | // size == 0 means no specified size. |
| 679 | // |
| 680 | // Returns true if there was an error. |
| 681 | // |
| 682 | bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType type, TVariable*& variable) |
| 683 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 684 | // |
| 685 | // Don't check for reserved word use until after we know it's not in the symbol table, |
| 686 | // because reserved arrays can be redeclared. |
| 687 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 688 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 689 | bool builtIn = false; |
| 690 | bool sameScope = false; |
| 691 | TSymbol* symbol = symbolTable.find(identifier, &builtIn, &sameScope); |
| 692 | if (symbol == 0 || !sameScope) { |
| 693 | if (reservedErrorCheck(line, identifier)) |
| 694 | return true; |
| 695 | |
| 696 | variable = new TVariable(&identifier, TType(type)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 697 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 698 | if (type.arraySize) |
| 699 | variable->getType().setArraySize(type.arraySize); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 700 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 701 | if (! symbolTable.insert(*variable)) { |
| 702 | delete variable; |
| 703 | error(line, "INTERNAL ERROR inserting new symbol", identifier.c_str(), ""); |
| 704 | return true; |
| 705 | } |
| 706 | } else { |
| 707 | if (! symbol->isVariable()) { |
| 708 | error(line, "variable expected", identifier.c_str(), ""); |
| 709 | return true; |
| 710 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 711 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 712 | variable = static_cast<TVariable*>(symbol); |
| 713 | if (! variable->getType().isArray()) { |
| 714 | error(line, "redeclaring non-array as array", identifier.c_str(), ""); |
| 715 | return true; |
| 716 | } |
| 717 | if (variable->getType().getArraySize() > 0) { |
| 718 | error(line, "redeclaration of array with size", identifier.c_str(), ""); |
| 719 | return true; |
| 720 | } |
| 721 | |
| 722 | if (! variable->getType().sameElementType(TType(type))) { |
| 723 | error(line, "redeclaration of array with a different type", identifier.c_str(), ""); |
| 724 | return true; |
| 725 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 726 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 727 | TType* t = variable->getArrayInformationType(); |
| 728 | while (t != 0) { |
| 729 | if (t->getMaxArraySize() > type.arraySize) { |
| 730 | error(line, "higher index value already used for the array", identifier.c_str(), ""); |
| 731 | return true; |
| 732 | } |
| 733 | t->setArraySize(type.arraySize); |
| 734 | t = t->getArrayInformationType(); |
| 735 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 736 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 737 | if (type.arraySize) |
| 738 | variable->getType().setArraySize(type.arraySize); |
| 739 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 740 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 741 | if (voidErrorCheck(line, identifier, type)) |
| 742 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 743 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 744 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, bool updateFlag, TSourceLoc line) |
| 748 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 749 | bool builtIn = false; |
| 750 | TSymbol* symbol = symbolTable.find(node->getSymbol(), &builtIn); |
| 751 | if (symbol == 0) { |
| 752 | error(line, " undeclared identifier", node->getSymbol().c_str(), ""); |
| 753 | return true; |
| 754 | } |
| 755 | TVariable* variable = static_cast<TVariable*>(symbol); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 756 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 757 | type->setArrayInformationType(variable->getArrayInformationType()); |
| 758 | variable->updateArrayInformationType(type); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 759 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 760 | // special casing to test index value of gl_FragData. If the accessed index is >= gl_MaxDrawBuffers |
| 761 | // its an error |
| 762 | if (node->getSymbol() == "gl_FragData") { |
| 763 | TSymbol* fragData = symbolTable.find("gl_MaxDrawBuffers", &builtIn); |
| 764 | if (fragData == 0) { |
| 765 | infoSink.info.message(EPrefixInternalError, "gl_MaxDrawBuffers not defined", line); |
| 766 | return true; |
| 767 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 768 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 769 | int fragDataValue = static_cast<TVariable*>(fragData)->getConstPointer()[0].getIConst(); |
| 770 | if (fragDataValue <= size) { |
| 771 | error(line, "", "[", "gl_FragData can only have a max array size of up to gl_MaxDrawBuffers", ""); |
| 772 | return true; |
| 773 | } |
| 774 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 775 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 776 | // we dont want to update the maxArraySize when this flag is not set, we just want to include this |
| 777 | // node type in the chain of node types so that its updated when a higher maxArraySize comes in. |
| 778 | if (!updateFlag) |
| 779 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 780 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 781 | size++; |
| 782 | variable->getType().setMaxArraySize(size); |
| 783 | type->setMaxArraySize(size); |
| 784 | TType* tt = type; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 785 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 786 | while(tt->getArrayInformationType() != 0) { |
| 787 | tt = tt->getArrayInformationType(); |
| 788 | tt->setMaxArraySize(size); |
| 789 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 790 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 791 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | // |
| 795 | // Enforce non-initializer type/qualifier rules. |
| 796 | // |
| 797 | // Returns true if there was an error. |
| 798 | // |
| 799 | bool TParseContext::nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type) |
| 800 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 801 | // |
| 802 | // Make the qualifier make sense. |
| 803 | // |
| 804 | if (type.qualifier == EvqConst) { |
| 805 | type.qualifier = EvqTemporary; |
| 806 | error(line, "variables with qualifier 'const' must be initialized", identifier.c_str(), ""); |
| 807 | return true; |
| 808 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 809 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 810 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | // |
| 814 | // Do semantic checking for a variable declaration that has no initializer, |
| 815 | // and update the symbol table. |
| 816 | // |
| 817 | // Returns true if there was an error. |
| 818 | // |
| 819 | bool TParseContext::nonInitErrorCheck(int line, TString& identifier, TPublicType& type) |
| 820 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 821 | if (reservedErrorCheck(line, identifier)) |
| 822 | recover(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 823 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 824 | TVariable* variable = new TVariable(&identifier, TType(type)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 825 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 826 | if (! symbolTable.insert(*variable)) { |
| 827 | error(line, "redefinition", variable->getName().c_str(), ""); |
| 828 | delete variable; |
| 829 | return true; |
| 830 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 831 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 832 | if (voidErrorCheck(line, identifier, type)) |
| 833 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 834 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 835 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | bool TParseContext::paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type) |
| 839 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 840 | if (qualifier != EvqConst && qualifier != EvqTemporary) { |
| 841 | error(line, "qualifier not allowed on function parameter", getQualifierString(qualifier), ""); |
| 842 | return true; |
| 843 | } |
| 844 | if (qualifier == EvqConst && paramQualifier != EvqIn) { |
| 845 | error(line, "qualifier not allowed with ", getQualifierString(qualifier), getQualifierString(paramQualifier)); |
| 846 | return true; |
| 847 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 848 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 849 | if (qualifier == EvqConst) |
| 850 | type->changeQualifier(EvqConstReadOnly); |
| 851 | else |
| 852 | type->changeQualifier(paramQualifier); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 853 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 854 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | bool TParseContext::extensionErrorCheck(int line, const char* extension) |
| 858 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 859 | if (extensionBehavior[extension] == EBhWarn) { |
| 860 | infoSink.info.message(EPrefixWarning, ("extension " + TString(extension) + " is being used").c_str(), line); |
| 861 | return false; |
| 862 | } |
| 863 | if (extensionBehavior[extension] == EBhDisable) { |
| 864 | error(line, "extension", extension, "is disabled"); |
| 865 | return true; |
| 866 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 867 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 868 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | ///////////////////////////////////////////////////////////////////////////////// |
| 872 | // |
| 873 | // Non-Errors. |
| 874 | // |
| 875 | ///////////////////////////////////////////////////////////////////////////////// |
| 876 | |
| 877 | // |
| 878 | // Look up a function name in the symbol table, and make sure it is a function. |
| 879 | // |
| 880 | // Return the function symbol if found, otherwise 0. |
| 881 | // |
| 882 | const TFunction* TParseContext::findFunction(int line, TFunction* call, bool *builtIn) |
| 883 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 884 | const TSymbol* symbol = symbolTable.find(call->getMangledName(), builtIn); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 885 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 886 | if (symbol == 0) { |
| 887 | error(line, "no matching overloaded function found", call->getName().c_str(), ""); |
| 888 | return 0; |
| 889 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 890 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 891 | if (! symbol->isFunction()) { |
| 892 | error(line, "function name expected", call->getName().c_str(), ""); |
| 893 | return 0; |
| 894 | } |
| 895 | |
| 896 | const TFunction* function = static_cast<const TFunction*>(symbol); |
| 897 | |
| 898 | return function; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | // |
| 902 | // Initializers show up in several places in the grammar. Have one set of |
| 903 | // code to handle them here. |
| 904 | // |
| 905 | bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType, |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 906 | TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 907 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 908 | TType type = TType(pType); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 909 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 910 | if (variable == 0) { |
| 911 | if (reservedErrorCheck(line, identifier)) |
| 912 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 913 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 914 | if (voidErrorCheck(line, identifier, pType)) |
| 915 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 916 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 917 | // |
| 918 | // add variable to symbol table |
| 919 | // |
| 920 | variable = new TVariable(&identifier, type); |
| 921 | if (! symbolTable.insert(*variable)) { |
| 922 | error(line, "redefinition", variable->getName().c_str(), ""); |
| 923 | return true; |
| 924 | // don't delete variable, it's used by error recovery, and the pool |
| 925 | // pop will take care of the memory |
| 926 | } |
| 927 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 928 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 929 | // |
| 930 | // identifier must be of type constant, a global, or a temporary |
| 931 | // |
| 932 | TQualifier qualifier = variable->getType().getQualifier(); |
| 933 | if ((qualifier != EvqTemporary) && (qualifier != EvqGlobal) && (qualifier != EvqConst)) { |
| 934 | error(line, " cannot initialize this type of qualifier ", variable->getType().getQualifierString(), ""); |
| 935 | return true; |
| 936 | } |
| 937 | // |
| 938 | // test for and propagate constant |
| 939 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 940 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 941 | if (qualifier == EvqConst) { |
| 942 | if (qualifier != initializer->getType().getQualifier()) { |
| 943 | error(line, " assigning non-constant to", "=", "'%s'", variable->getType().getCompleteString().c_str()); |
| 944 | variable->getType().changeQualifier(EvqTemporary); |
| 945 | return true; |
| 946 | } |
| 947 | if (type != initializer->getType()) { |
| 948 | error(line, " non-matching types for const initializer ", |
| 949 | variable->getType().getQualifierString(), ""); |
| 950 | variable->getType().changeQualifier(EvqTemporary); |
| 951 | return true; |
| 952 | } |
| 953 | if (initializer->getAsConstantUnion()) { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 954 | ConstantUnion* unionArray = variable->getConstPointer(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 955 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 956 | if (type.getObjectSize() == 1 && type.getBasicType() != EbtStruct) { |
| 957 | *unionArray = (initializer->getAsConstantUnion()->getUnionArrayPointer())[0]; |
| 958 | } else { |
| 959 | variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer()); |
| 960 | } |
| 961 | } else if (initializer->getAsSymbolNode()) { |
| 962 | const TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol()); |
| 963 | const TVariable* tVar = static_cast<const TVariable*>(symbol); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 964 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 965 | ConstantUnion* constArray = tVar->getConstPointer(); |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 966 | variable->shareConstPointer(constArray); |
| 967 | } else { |
| 968 | error(line, " cannot assign to", "=", "'%s'", variable->getType().getCompleteString().c_str()); |
| 969 | variable->getType().changeQualifier(EvqTemporary); |
| 970 | return true; |
| 971 | } |
| 972 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 973 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 974 | if (qualifier != EvqConst) { |
| 975 | TIntermSymbol* intermSymbol = intermediate.addSymbol(variable->getUniqueId(), variable->getName(), variable->getType(), line); |
| 976 | intermNode = intermediate.addAssign(EOpInitialize, intermSymbol, initializer, line); |
| 977 | if (intermNode == 0) { |
| 978 | assignError(line, "=", intermSymbol->getCompleteString(), initializer->getCompleteString()); |
| 979 | return true; |
| 980 | } |
| 981 | } else |
| 982 | intermNode = 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 983 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 984 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | bool TParseContext::areAllChildConst(TIntermAggregate* aggrNode) |
| 988 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 989 | if (!aggrNode->isConstructor()) |
| 990 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 991 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 992 | bool allConstant = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 993 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 994 | // check if all the child nodes are constants so that they can be inserted into |
| 995 | // the parent node |
| 996 | if (aggrNode) { |
| 997 | TIntermSequence &childSequenceVector = aggrNode->getSequence() ; |
| 998 | for (TIntermSequence::iterator p = childSequenceVector.begin(); |
| 999 | p != childSequenceVector.end(); p++) { |
| 1000 | if (!(*p)->getAsTyped()->getAsConstantUnion()) |
| 1001 | return false; |
| 1002 | } |
| 1003 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1004 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1005 | return allConstant; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | // This function is used to test for the correctness of the parameters passed to various constructor functions |
| 1009 | // and also convert them to the right datatype if it is allowed and required. |
| 1010 | // |
| 1011 | // Returns 0 for an error or the constructed node (aggregate or typed) for no error. |
| 1012 | // |
| 1013 | TIntermTyped* TParseContext::addConstructor(TIntermNode* node, const TType* type, TOperator op, TFunction* fnCall, TSourceLoc line) |
| 1014 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1015 | if (node == 0) |
| 1016 | return 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1017 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1018 | TIntermAggregate* aggrNode = node->getAsAggregate(); |
| 1019 | |
| 1020 | TTypeList::iterator memberTypes; |
| 1021 | if (op == EOpConstructStruct) |
| 1022 | memberTypes = type->getStruct()->begin(); |
| 1023 | |
| 1024 | TType elementType = *type; |
| 1025 | if (type->isArray()) |
| 1026 | elementType.clearArrayness(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1027 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1028 | bool singleArg; |
| 1029 | if (aggrNode) { |
| 1030 | if (aggrNode->getOp() != EOpNull || aggrNode->getSequence().size() == 1) |
| 1031 | singleArg = true; |
| 1032 | else |
| 1033 | singleArg = false; |
| 1034 | } else |
| 1035 | singleArg = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1036 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1037 | TIntermTyped *newNode; |
| 1038 | if (singleArg) { |
| 1039 | // If structure constructor or array constructor is being called |
| 1040 | // for only one parameter inside the structure, we need to call constructStruct function once. |
| 1041 | if (type->isArray()) |
| 1042 | newNode = constructStruct(node, &elementType, 1, node->getLine(), false); |
| 1043 | else if (op == EOpConstructStruct) |
| 1044 | newNode = constructStruct(node, (*memberTypes).type, 1, node->getLine(), false); |
| 1045 | else |
| 1046 | newNode = constructBuiltIn(type, op, node, node->getLine(), false); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1047 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1048 | if (newNode && newNode->getAsAggregate()) { |
| 1049 | TIntermTyped* constConstructor = foldConstConstructor(newNode->getAsAggregate(), *type); |
| 1050 | if (constConstructor) |
| 1051 | return constConstructor; |
| 1052 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1053 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1054 | return newNode; |
| 1055 | } |
| 1056 | |
| 1057 | // |
| 1058 | // Handle list of arguments. |
| 1059 | // |
| 1060 | TIntermSequence &sequenceVector = aggrNode->getSequence() ; // Stores the information about the parameter to the constructor |
| 1061 | // if the structure constructor contains more than one parameter, then construct |
| 1062 | // each parameter |
| 1063 | |
| 1064 | int paramCount = 0; // keeps a track of the constructor parameter number being checked |
| 1065 | |
| 1066 | // for each parameter to the constructor call, check to see if the right type is passed or convert them |
| 1067 | // to the right type if possible (and allowed). |
| 1068 | // for structure constructors, just check if the right type is passed, no conversion is allowed. |
| 1069 | |
| 1070 | for (TIntermSequence::iterator p = sequenceVector.begin(); |
| 1071 | p != sequenceVector.end(); p++, paramCount++) { |
| 1072 | if (type->isArray()) |
| 1073 | newNode = constructStruct(*p, &elementType, paramCount+1, node->getLine(), true); |
| 1074 | else if (op == EOpConstructStruct) |
| 1075 | newNode = constructStruct(*p, (memberTypes[paramCount]).type, paramCount+1, node->getLine(), true); |
| 1076 | else |
| 1077 | newNode = constructBuiltIn(type, op, *p, node->getLine(), true); |
| 1078 | |
| 1079 | if (newNode) { |
| 1080 | *p = newNode; |
| 1081 | } |
| 1082 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1083 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1084 | TIntermTyped* constructor = intermediate.setAggregateOperator(aggrNode, op, line); |
| 1085 | TIntermTyped* constConstructor = foldConstConstructor(constructor->getAsAggregate(), *type); |
| 1086 | if (constConstructor) |
| 1087 | return constConstructor; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1088 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1089 | return constructor; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | TIntermTyped* TParseContext::foldConstConstructor(TIntermAggregate* aggrNode, const TType& type) |
| 1093 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1094 | bool canBeFolded = areAllChildConst(aggrNode); |
| 1095 | aggrNode->setType(type); |
| 1096 | if (canBeFolded) { |
| 1097 | bool returnVal = false; |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 1098 | ConstantUnion* unionArray = new ConstantUnion[type.getObjectSize()]; |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1099 | if (aggrNode->getSequence().size() == 1) { |
| 1100 | returnVal = intermediate.parseConstTree(aggrNode->getLine(), aggrNode, unionArray, aggrNode->getOp(), symbolTable, type, true); |
| 1101 | } |
| 1102 | else { |
| 1103 | returnVal = intermediate.parseConstTree(aggrNode->getLine(), aggrNode, unionArray, aggrNode->getOp(), symbolTable, type); |
| 1104 | } |
| 1105 | if (returnVal) |
| 1106 | return 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1107 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1108 | return intermediate.addConstantUnion(unionArray, type, aggrNode->getLine()); |
| 1109 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1110 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1111 | return 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | // Function for constructor implementation. Calls addUnaryMath with appropriate EOp value |
| 1115 | // for the parameter to the constructor (passed to this function). Essentially, it converts |
| 1116 | // the parameter types correctly. If a constructor expects an int (like ivec2) and is passed a |
| 1117 | // float, then float is converted to int. |
| 1118 | // |
| 1119 | // Returns 0 for an error or the constructed node. |
| 1120 | // |
| 1121 | TIntermTyped* TParseContext::constructBuiltIn(const TType* type, TOperator op, TIntermNode* node, TSourceLoc line, bool subset) |
| 1122 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1123 | TIntermTyped* newNode; |
| 1124 | TOperator basicOp; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1125 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1126 | // |
| 1127 | // First, convert types as needed. |
| 1128 | // |
| 1129 | switch (op) { |
| 1130 | case EOpConstructVec2: |
| 1131 | case EOpConstructVec3: |
| 1132 | case EOpConstructVec4: |
| 1133 | case EOpConstructMat2: |
| 1134 | case EOpConstructMat3: |
| 1135 | case EOpConstructMat4: |
| 1136 | case EOpConstructFloat: |
| 1137 | basicOp = EOpConstructFloat; |
| 1138 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1139 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1140 | case EOpConstructIVec2: |
| 1141 | case EOpConstructIVec3: |
| 1142 | case EOpConstructIVec4: |
| 1143 | case EOpConstructInt: |
| 1144 | basicOp = EOpConstructInt; |
| 1145 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1146 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1147 | case EOpConstructBVec2: |
| 1148 | case EOpConstructBVec3: |
| 1149 | case EOpConstructBVec4: |
| 1150 | case EOpConstructBool: |
| 1151 | basicOp = EOpConstructBool; |
| 1152 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1153 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1154 | default: |
| 1155 | error(line, "unsupported construction", "", ""); |
| 1156 | recover(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1157 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1158 | return 0; |
| 1159 | } |
| 1160 | newNode = intermediate.addUnaryMath(basicOp, node, node->getLine(), symbolTable); |
| 1161 | if (newNode == 0) { |
| 1162 | error(line, "can't convert", "constructor", ""); |
| 1163 | return 0; |
| 1164 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1165 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1166 | // |
| 1167 | // Now, if there still isn't an operation to do the construction, and we need one, add one. |
| 1168 | // |
| 1169 | |
| 1170 | // Otherwise, skip out early. |
| 1171 | if (subset || (newNode != node && newNode->getType() == *type)) |
| 1172 | return newNode; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1173 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1174 | // setAggregateOperator will insert a new node for the constructor, as needed. |
| 1175 | return intermediate.setAggregateOperator(newNode, op, line); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | // This function tests for the type of the parameters to the structures constructors. Raises |
| 1179 | // an error message if the expected type does not match the parameter passed to the constructor. |
| 1180 | // |
| 1181 | // Returns 0 for an error or the input node itself if the expected and the given parameter types match. |
| 1182 | // |
| 1183 | TIntermTyped* TParseContext::constructStruct(TIntermNode* node, TType* type, int paramCount, TSourceLoc line, bool subset) |
| 1184 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1185 | if (*type == node->getAsTyped()->getType()) { |
| 1186 | if (subset) |
| 1187 | return node->getAsTyped(); |
| 1188 | else |
| 1189 | return intermediate.setAggregateOperator(node->getAsTyped(), EOpConstructStruct, line); |
| 1190 | } else { |
| 1191 | error(line, "", "constructor", "cannot convert parameter %d from '%s' to '%s'", paramCount, |
| 1192 | node->getAsTyped()->getType().getBasicString(), type->getBasicString()); |
| 1193 | recover(); |
| 1194 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1195 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1196 | return 0; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | // |
| 1200 | // This function returns the tree representation for the vector field(s) being accessed from contant vector. |
| 1201 | // If only one component of vector is accessed (v.x or v[0] where v is a contant vector), then a contant node is |
| 1202 | // returned, else an aggregate node is returned (for v.xy). The input to this function could either be the symbol |
| 1203 | // node or it could be the intermediate tree representation of accessing fields in a constant structure or column of |
| 1204 | // a constant matrix. |
| 1205 | // |
| 1206 | TIntermTyped* TParseContext::addConstVectorNode(TVectorFields& fields, TIntermTyped* node, TSourceLoc line) |
| 1207 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1208 | TIntermTyped* typedNode; |
| 1209 | TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1210 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 1211 | ConstantUnion *unionArray; |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1212 | if (tempConstantNode) { |
| 1213 | unionArray = tempConstantNode->getUnionArrayPointer(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1214 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1215 | if (!unionArray) { // this error message should never be raised |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 1216 | infoSink.info.message(EPrefixInternalError, "ConstantUnion not initialized in addConstVectorNode function", line); |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1217 | recover(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1218 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1219 | return node; |
| 1220 | } |
| 1221 | } else { // The node has to be either a symbol node or an aggregate node or a tempConstant node, else, its an error |
| 1222 | error(line, "Cannot offset into the vector", "Error", ""); |
| 1223 | recover(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1224 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1225 | return 0; |
| 1226 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1227 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 1228 | ConstantUnion* constArray = new ConstantUnion[fields.num]; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1229 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1230 | for (int i = 0; i < fields.num; i++) { |
| 1231 | if (fields.offsets[i] >= node->getType().getObjectSize()) { |
| 1232 | error(line, "", "[", "vector field selection out of range '%d'", fields.offsets[i]); |
| 1233 | recover(); |
| 1234 | fields.offsets[i] = 0; |
| 1235 | } |
| 1236 | |
| 1237 | constArray[i] = unionArray[fields.offsets[i]]; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1238 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1239 | } |
| 1240 | typedNode = intermediate.addConstantUnion(constArray, node->getType(), line); |
| 1241 | return typedNode; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | // |
| 1245 | // This function returns the column being accessed from a constant matrix. The values are retrieved from |
| 1246 | // the symbol table and parse-tree is built for a vector (each column of a matrix is a vector). The input |
| 1247 | // to the function could either be a symbol node (m[0] where m is a constant matrix)that represents a |
| 1248 | // constant matrix or it could be the tree representation of the constant matrix (s.m1[0] where s is a constant structure) |
| 1249 | // |
| 1250 | TIntermTyped* TParseContext::addConstMatrixNode(int index, TIntermTyped* node, TSourceLoc line) |
| 1251 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1252 | TIntermTyped* typedNode; |
| 1253 | TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1254 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1255 | if (index >= node->getType().getNominalSize()) { |
| 1256 | error(line, "", "[", "matrix field selection out of range '%d'", index); |
| 1257 | recover(); |
| 1258 | index = 0; |
| 1259 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1260 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1261 | if (tempConstantNode) { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 1262 | ConstantUnion* unionArray = tempConstantNode->getUnionArrayPointer(); |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1263 | int size = tempConstantNode->getType().getNominalSize(); |
| 1264 | typedNode = intermediate.addConstantUnion(&unionArray[size*index], tempConstantNode->getType(), line); |
| 1265 | } else { |
| 1266 | error(line, "Cannot offset into the matrix", "Error", ""); |
| 1267 | recover(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1268 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1269 | return 0; |
| 1270 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1271 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1272 | return typedNode; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | |
| 1276 | // |
| 1277 | // This function returns an element of an array accessed from a constant array. The values are retrieved from |
| 1278 | // the symbol table and parse-tree is built for the type of the element. The input |
| 1279 | // to the function could either be a symbol node (a[0] where a is a constant array)that represents a |
| 1280 | // constant array or it could be the tree representation of the constant array (s.a1[0] where s is a constant structure) |
| 1281 | // |
| 1282 | TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line) |
| 1283 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1284 | TIntermTyped* typedNode; |
| 1285 | TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion(); |
| 1286 | TType arrayElementType = node->getType(); |
| 1287 | arrayElementType.clearArrayness(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1288 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1289 | if (index >= node->getType().getArraySize()) { |
| 1290 | error(line, "", "[", "array field selection out of range '%d'", index); |
| 1291 | recover(); |
| 1292 | index = 0; |
| 1293 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1294 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1295 | int arrayElementSize = arrayElementType.getObjectSize(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1296 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1297 | if (tempConstantNode) { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 1298 | ConstantUnion* unionArray = tempConstantNode->getUnionArrayPointer(); |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1299 | typedNode = intermediate.addConstantUnion(&unionArray[arrayElementSize * index], tempConstantNode->getType(), line); |
| 1300 | } else { |
| 1301 | error(line, "Cannot offset into the array", "Error", ""); |
| 1302 | recover(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1303 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1304 | return 0; |
| 1305 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1306 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1307 | return typedNode; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | |
| 1311 | // |
| 1312 | // This function returns the value of a particular field inside a constant structure from the symbol table. |
| 1313 | // If there is an embedded/nested struct, it appropriately calls addConstStructNested or addConstStructFromAggr |
| 1314 | // function and returns the parse-tree with the values of the embedded/nested struct. |
| 1315 | // |
| 1316 | TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* node, TSourceLoc line) |
| 1317 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1318 | TTypeList* fields = node->getType().getStruct(); |
| 1319 | TIntermTyped *typedNode; |
| 1320 | int instanceSize = 0; |
| 1321 | unsigned int index = 0; |
| 1322 | TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1323 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1324 | for ( index = 0; index < fields->size(); ++index) { |
| 1325 | if ((*fields)[index].type->getFieldName() == identifier) { |
| 1326 | break; |
| 1327 | } else { |
| 1328 | instanceSize += (*fields)[index].type->getObjectSize(); |
| 1329 | } |
| 1330 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1331 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1332 | if (tempConstantNode) { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 1333 | ConstantUnion* constArray = tempConstantNode->getUnionArrayPointer(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1334 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1335 | typedNode = intermediate.addConstantUnion(constArray+instanceSize, tempConstantNode->getType(), line); // type will be changed in the calling function |
| 1336 | } else { |
| 1337 | error(line, "Cannot offset into the structure", "Error", ""); |
| 1338 | recover(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1339 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1340 | return 0; |
| 1341 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1342 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1343 | return typedNode; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | // |
| 1347 | // Initialize all supported extensions to disable |
| 1348 | // |
| 1349 | void TParseContext::initializeExtensionBehavior() |
| 1350 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1351 | // |
| 1352 | // example code: extensionBehavior["test"] = EBhDisable; // where "test" is the name of |
| 1353 | // supported extension |
| 1354 | // |
| 1355 | extensionBehavior["GL_ARB_texture_rectangle"] = EBhRequire; |
| 1356 | extensionBehavior["GL_3DL_array_objects"] = EBhDisable; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | OS_TLSIndex GlobalParseContextIndex = OS_INVALID_TLS_INDEX; |
| 1360 | |
| 1361 | bool InitializeParseContextIndex() |
| 1362 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1363 | if (GlobalParseContextIndex != OS_INVALID_TLS_INDEX) { |
| 1364 | assert(0 && "InitializeParseContextIndex(): Parse Context already initalised"); |
| 1365 | return false; |
| 1366 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1367 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1368 | // |
| 1369 | // Allocate a TLS index. |
| 1370 | // |
| 1371 | GlobalParseContextIndex = OS_AllocTLSIndex(); |
| 1372 | |
| 1373 | if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) { |
| 1374 | assert(0 && "InitializeParseContextIndex(): Parse Context already initalised"); |
| 1375 | return false; |
| 1376 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1377 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1378 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | bool InitializeGlobalParseContext() |
| 1382 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1383 | if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) { |
| 1384 | assert(0 && "InitializeGlobalParseContext(): Parse Context index not initalised"); |
| 1385 | return false; |
| 1386 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1387 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1388 | TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex)); |
| 1389 | if (lpParseContext != 0) { |
| 1390 | assert(0 && "InitializeParseContextIndex(): Parse Context already initalised"); |
| 1391 | return false; |
| 1392 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1393 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1394 | TThreadParseContext *lpThreadData = new TThreadParseContext(); |
| 1395 | if (lpThreadData == 0) { |
| 1396 | assert(0 && "InitializeGlobalParseContext(): Unable to create thread parse context"); |
| 1397 | return false; |
| 1398 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1399 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1400 | lpThreadData->lpGlobalParseContext = 0; |
| 1401 | OS_SetTLSValue(GlobalParseContextIndex, lpThreadData); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1402 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1403 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | TParseContextPointer& GetGlobalParseContext() |
| 1407 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1408 | // |
| 1409 | // Minimal error checking for speed |
| 1410 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1411 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1412 | TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex)); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1413 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1414 | return lpParseContext->lpGlobalParseContext; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | bool FreeParseContext() |
| 1418 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1419 | if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) { |
| 1420 | assert(0 && "FreeParseContext(): Parse Context index not initalised"); |
| 1421 | return false; |
| 1422 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1423 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1424 | TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex)); |
| 1425 | if (lpParseContext) |
| 1426 | delete lpParseContext; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1427 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1428 | return true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | bool FreeParseContextIndex() |
| 1432 | { |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1433 | OS_TLSIndex tlsiIndex = GlobalParseContextIndex; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1434 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1435 | if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) { |
| 1436 | assert(0 && "FreeParseContextIndex(): Parse Context index not initalised"); |
| 1437 | return false; |
| 1438 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1439 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1440 | GlobalParseContextIndex = OS_INVALID_TLS_INDEX; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1441 | |
daniel@transgaming.com | ea15b0e | 2010-04-29 03:32:36 +0000 | [diff] [blame] | 1442 | return OS_FreeTLSIndex(tlsiIndex); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1443 | } |