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