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