blob: 08278f8ccee2bc0ddfe230322b62de8315a2357b [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
shannon.woods%transgaming.com@gtempaccount.comc0d0c222013-04-13 03:29:36 +00002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// 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.combbf56f72010-04-20 18:52:13 +00007#include "compiler/ParseHelper.h"
8
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00009#include <stdarg.h>
apatrick@chromium.org8187fa82010-06-15 22:09:28 +000010#include <stdio.h>
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000012#include "compiler/glslang.h"
daniel@transgaming.comb401a922012-10-26 18:58:24 +000013#include "compiler/preprocessor/SourceLocation.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000014
alokp@chromium.org8b851c62012-06-15 16:25:11 +000015///////////////////////////////////////////////////////////////////////
16//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000017// 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//
25bool TParseContext::parseVectorFields(const TString& compString, int vecSize, TVectorFields& fields, int line)
26{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000027 fields.num = (int) compString.size();
28 if (fields.num > 4) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +000029 error(line, "illegal vector field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000030 return false;
31 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000032
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000033 enum {
34 exyzw,
35 ergba,
daniel@transgaming.comb3077d02013-01-11 04:12:09 +000036 estpq
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000037 } fieldSet[4];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000039 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.comc6b3b3c2012-06-27 22:49:39 +000091 error(line, "illegal vector field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000092 return false;
93 }
94 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000095
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000096 for (int i = 0; i < fields.num; ++i) {
97 if (fields.offsets[i] >= vecSize) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +000098 error(line, "vector field selection out of range", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000099 return false;
100 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000101
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000102 if (i > 0) {
103 if (fieldSet[i] != fieldSet[i-1]) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000104 error(line, "illegal - vector component fields not from the same set", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000105 return false;
106 }
107 }
108 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000109
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000110 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000111}
112
113
114//
115// Look at a '.' field selector string and change it into offsets
116// for a matrix.
117//
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000118bool TParseContext::parseMatrixFields(const TString& compString, int matCols, int matRows, TMatrixFields& fields, int line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000119{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000120 fields.wholeRow = false;
121 fields.wholeCol = false;
122 fields.row = -1;
123 fields.col = -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000124
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000125 if (compString.size() != 2) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000126 error(line, "illegal length of matrix field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000127 return false;
128 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000129
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000130 if (compString[0] == '_') {
131 if (compString[1] < '0' || compString[1] > '3') {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000132 error(line, "illegal matrix field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000133 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.comc6b3b3c2012-06-27 22:49:39 +0000139 error(line, "illegal matrix field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000140 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.comc6b3b3c2012-06-27 22:49:39 +0000147 error(line, "illegal matrix field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000148 return false;
149 }
150 fields.row = compString[0] - '0';
151 fields.col = compString[1] - '0';
152 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000153
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000154 if (fields.row >= matRows || fields.col >= matCols) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000155 error(line, "matrix field selection out of range", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000156 return false;
157 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000158
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000159 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000160}
161
162///////////////////////////////////////////////////////////////////////
163//
164// Errors
165//
166////////////////////////////////////////////////////////////////////////
167
168//
169// Track whether errors have occurred.
170//
171void TParseContext::recover()
172{
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000173}
174
175//
176// Used by flex/bison to output all syntax and parsing errors.
177//
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000178void TParseContext::error(TSourceLoc loc,
179 const char* reason, const char* token,
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000180 const char* extraInfo)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000181{
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000182 pp::SourceLocation srcLoc;
183 DecodeSourceLoc(loc, &srcLoc.file, &srcLoc.line);
184 diagnostics.writeInfo(pp::Diagnostics::ERROR,
185 srcLoc, reason, token, extraInfo);
alokp@chromium.orgff42c632010-05-10 15:14:30 +0000186
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000187}
188
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000189void TParseContext::warning(TSourceLoc loc,
190 const char* reason, const char* token,
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000191 const char* extraInfo) {
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000192 pp::SourceLocation srcLoc;
193 DecodeSourceLoc(loc, &srcLoc.file, &srcLoc.line);
194 diagnostics.writeInfo(pp::Diagnostics::WARNING,
195 srcLoc, reason, token, extraInfo);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000196}
197
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000198void TParseContext::trace(const char* str)
199{
200 diagnostics.writeDebug(str);
201}
202
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000203//
204// Same error message for all places assignments don't work.
205//
206void TParseContext::assignError(int line, const char* op, TString left, TString right)
207{
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000208 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.com4f39fd92010-03-08 20:26:45 +0000212}
213
214//
215// Same error message for all places unary operations don't work.
216//
217void TParseContext::unaryOpError(int line, const char* op, TString operand)
218{
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000219 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.com4f39fd92010-03-08 20:26:45 +0000224}
225
226//
227// Same error message for all binary operations don't work.
228//
229void TParseContext::binaryOpError(int line, const char* op, TString left, TString right)
230{
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000231 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.com4f39fd92010-03-08 20:26:45 +0000236}
237
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000238bool TParseContext::precisionErrorCheck(int line, TPrecision precision, TBasicType type){
zmo@google.comdc4b4f82011-06-17 00:42:53 +0000239 if (!checksPrecisionErrors)
240 return false;
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000241 switch( type ){
242 case EbtFloat:
243 if( precision == EbpUndefined ){
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000244 error( line, "No precision specified for (float)", "" );
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000245 return true;
246 }
247 break;
248 case EbtInt:
249 if( precision == EbpUndefined ){
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000250 error( line, "No precision specified (int)", "" );
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000251 return true;
252 }
253 break;
daniel@transgaming.com0eb64c32011-03-15 18:23:51 +0000254 default:
255 return false;
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000256 }
257 return false;
258}
259
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000260//
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//
266bool TParseContext::lValueErrorCheck(int line, const char* op, TIntermTyped* node)
267{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000268 TIntermSymbol* symNode = node->getAsSymbolNode();
269 TIntermBinary* binaryNode = node->getAsBinaryNode();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000270
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000271 if (binaryNode) {
272 bool errorReturn;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000273
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000274 switch(binaryNode->getOp()) {
275 case EOpIndexDirect:
276 case EOpIndexIndirect:
277 case EOpIndexDirectStruct:
shannonwoods@chromium.org4430b0d2013-05-30 00:12:34 +0000278 case EOpIndexDirectInterfaceBlock:
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000279 return lValueErrorCheck(line, op, binaryNode->getLeft());
280 case EOpVectorSwizzle:
281 errorReturn = lValueErrorCheck(line, op, binaryNode->getLeft());
282 if (!errorReturn) {
283 int offset[4] = {0,0,0,0};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000284
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000285 TIntermTyped* rightNode = binaryNode->getRight();
286 TIntermAggregate *aggrNode = rightNode->getAsAggregate();
287
288 for (TIntermSequence::iterator p = aggrNode->getSequence().begin();
289 p != aggrNode->getSequence().end(); p++) {
shannon.woods%transgaming.com@gtempaccount.comc0d0c222013-04-13 03:29:36 +0000290 int value = (*p)->getAsTyped()->getAsConstantUnion()->getIConst(0);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000291 offset[value]++;
292 if (offset[value] > 1) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000293 error(line, " l-value of swizzle cannot have duplicate components", op);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000294
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000295 return true;
296 }
297 }
298 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000299
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000300 return errorReturn;
301 default:
302 break;
303 }
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000304 error(line, " l-value required", op);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000305
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000306 return true;
307 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000308
309
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000310 const char* symbol = 0;
311 if (symNode != 0)
312 symbol = symNode->getSymbol().c_str();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000313
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000314 const char* message = 0;
315 switch (node->getQualifier()) {
316 case EvqConst: message = "can't modify a const"; break;
317 case EvqConstReadOnly: message = "can't modify a const"; break;
318 case EvqAttribute: message = "can't modify an attribute"; break;
319 case EvqUniform: message = "can't modify a uniform"; break;
320 case EvqVaryingIn: message = "can't modify a varying"; break;
321 case EvqInput: message = "can't modify an input"; break;
322 case EvqFragCoord: message = "can't modify gl_FragCoord"; break;
323 case EvqFrontFacing: message = "can't modify gl_FrontFacing"; break;
324 case EvqPointCoord: message = "can't modify gl_PointCoord"; break;
325 default:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000326
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000327 //
328 // Type that can't be written to?
329 //
330 switch (node->getBasicType()) {
331 case EbtSampler2D:
332 case EbtSamplerCube:
333 message = "can't modify a sampler";
334 break;
335 case EbtVoid:
336 message = "can't modify void";
337 break;
338 default:
339 break;
340 }
341 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000342
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000343 if (message == 0 && binaryNode == 0 && symNode == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000344 error(line, " l-value required", op);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000345
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000346 return true;
347 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000348
349
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000350 //
351 // Everything else is okay, no error.
352 //
353 if (message == 0)
354 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000355
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000356 //
357 // If we get here, we have an error and a message.
358 //
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000359 if (symNode) {
360 std::stringstream extraInfoStream;
361 extraInfoStream << "\"" << symbol << "\" (" << message << ")";
362 std::string extraInfo = extraInfoStream.str();
363 error(line, " l-value required", op, extraInfo.c_str());
364 }
365 else {
366 std::stringstream extraInfoStream;
367 extraInfoStream << "(" << message << ")";
368 std::string extraInfo = extraInfoStream.str();
369 error(line, " l-value required", op, extraInfo.c_str());
370 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000371
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000372 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000373}
374
375//
376// Both test, and if necessary spit out an error, to see if the node is really
377// a constant.
378//
379// Returns true if the was an error.
380//
381bool TParseContext::constErrorCheck(TIntermTyped* node)
382{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000383 if (node->getQualifier() == EvqConst)
384 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000385
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000386 error(node->getLine(), "constant expression required", "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000387
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000388 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000389}
390
391//
392// Both test, and if necessary spit out an error, to see if the node is really
393// an integer.
394//
395// Returns true if the was an error.
396//
397bool TParseContext::integerErrorCheck(TIntermTyped* node, const char* token)
398{
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000399 if (node->isScalarInt())
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000400 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000401
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000402 error(node->getLine(), "integer expression required", token);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000403
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000404 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000405}
406
407//
408// Both test, and if necessary spit out an error, to see if we are currently
409// globally scoped.
410//
411// Returns true if the was an error.
412//
413bool TParseContext::globalErrorCheck(int line, bool global, const char* token)
414{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000415 if (global)
416 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000417
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000418 error(line, "only allowed at global scope", token);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000419
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000420 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000421}
422
423//
424// For now, keep it simple: if it starts "gl_", it's reserved, independent
425// of scope. Except, if the symbol table is at the built-in push-level,
426// which is when we are parsing built-ins.
alokp@chromium.org613ef312010-07-21 18:54:22 +0000427// Also checks for "webgl_" and "_webgl_" reserved identifiers if parsing a
428// webgl shader.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000429//
430// Returns true if there was an error.
431//
432bool TParseContext::reservedErrorCheck(int line, const TString& identifier)
433{
alokp@chromium.org613ef312010-07-21 18:54:22 +0000434 static const char* reservedErrMsg = "reserved built-in name";
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000435 if (!symbolTable.atBuiltInLevel()) {
daniel@transgaming.com51db7fb2011-09-20 16:11:06 +0000436 if (identifier.compare(0, 3, "gl_") == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000437 error(line, reservedErrMsg, "gl_");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000438 return true;
439 }
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000440 if (isWebGLBasedSpec(shaderSpec)) {
daniel@transgaming.com51db7fb2011-09-20 16:11:06 +0000441 if (identifier.compare(0, 6, "webgl_") == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000442 error(line, reservedErrMsg, "webgl_");
alokp@chromium.org613ef312010-07-21 18:54:22 +0000443 return true;
444 }
daniel@transgaming.com51db7fb2011-09-20 16:11:06 +0000445 if (identifier.compare(0, 7, "_webgl_") == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000446 error(line, reservedErrMsg, "_webgl_");
alokp@chromium.org613ef312010-07-21 18:54:22 +0000447 return true;
448 }
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000449 if (shaderSpec == SH_CSS_SHADERS_SPEC && identifier.compare(0, 4, "css_") == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000450 error(line, reservedErrMsg, "css_");
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000451 return true;
452 }
alokp@chromium.org613ef312010-07-21 18:54:22 +0000453 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000454 if (identifier.find("__") != TString::npos) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000455 error(line, "identifiers containing two consecutive underscores (__) are reserved as possible future keywords", identifier.c_str());
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000456 return true;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000457 }
458 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000459
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000460 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000461}
462
463//
464// Make sure there is enough data provided to the constructor to build
465// something of the type of the constructor. Also returns the type of
466// the constructor.
467//
468// Returns true if there was an error in construction.
469//
470bool TParseContext::constructorErrorCheck(int line, TIntermNode* node, TFunction& function, TOperator op, TType* type)
471{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000472 *type = function.getReturnType();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000473
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000474 bool constructingMatrix = false;
475 switch(op) {
476 case EOpConstructMat2:
477 case EOpConstructMat3:
478 case EOpConstructMat4:
479 constructingMatrix = true;
480 break;
481 default:
482 break;
483 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000484
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000485 //
486 // Note: It's okay to have too many components available, but not okay to have unused
487 // arguments. 'full' will go to true when enough args have been seen. If we loop
488 // again, there is an extra argument, so 'overfull' will become true.
489 //
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000490
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000491 int size = 0;
492 bool constType = true;
493 bool full = false;
494 bool overFull = false;
495 bool matrixInMatrix = false;
496 bool arrayArg = false;
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000497 for (size_t i = 0; i < function.getParamCount(); ++i) {
alokp@chromium.orgb19403a2010-09-08 17:56:26 +0000498 const TParameter& param = function.getParam(i);
499 size += param.type->getObjectSize();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000500
alokp@chromium.orgb19403a2010-09-08 17:56:26 +0000501 if (constructingMatrix && param.type->isMatrix())
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000502 matrixInMatrix = true;
503 if (full)
504 overFull = true;
505 if (op != EOpConstructStruct && !type->isArray() && size >= type->getObjectSize())
506 full = true;
alokp@chromium.orgb19403a2010-09-08 17:56:26 +0000507 if (param.type->getQualifier() != EvqConst)
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000508 constType = false;
alokp@chromium.orgb19403a2010-09-08 17:56:26 +0000509 if (param.type->isArray())
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000510 arrayArg = true;
511 }
512
513 if (constType)
alokp@chromium.org58e54292010-08-24 21:40:03 +0000514 type->setQualifier(EvqConst);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000515
shannon.woods@transgaming.com18bd2ec2013-02-28 23:19:46 +0000516 if (type->isArray() && static_cast<size_t>(type->getArraySize()) != function.getParamCount()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000517 error(line, "array constructor needs one argument per array element", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000518 return true;
519 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000520
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000521 if (arrayArg && op != EOpConstructStruct) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000522 error(line, "constructing from a non-dereferenced array", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000523 return true;
524 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000525
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000526 if (matrixInMatrix && !type->isArray()) {
daniel@transgaming.combef0b6d2010-04-29 03:32:39 +0000527 if (function.getParamCount() != 1) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000528 error(line, "constructing matrix from matrix can only take one argument", "constructor");
daniel@transgaming.combef0b6d2010-04-29 03:32:39 +0000529 return true;
530 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000531 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000532
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000533 if (overFull) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000534 error(line, "too many arguments", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000535 return true;
536 }
537
daniel@transgaming.com7b17fac2010-12-12 08:52:58 +0000538 if (op == EOpConstructStruct && !type->isArray() && int(type->getStruct()->size()) != function.getParamCount()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000539 error(line, "Number of constructor parameters does not match the number of structure fields", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000540 return true;
541 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000542
daniel@transgaming.com67d72522011-11-29 17:23:51 +0000543 if (!type->isMatrix() || !matrixInMatrix) {
daniel@transgaming.combef0b6d2010-04-29 03:32:39 +0000544 if ((op != EOpConstructStruct && size != 1 && size < type->getObjectSize()) ||
545 (op == EOpConstructStruct && size < type->getObjectSize())) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000546 error(line, "not enough data provided for construction", "constructor");
daniel@transgaming.combef0b6d2010-04-29 03:32:39 +0000547 return true;
548 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000549 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000550
daniel@transgaming.com0b53fc02011-03-09 15:12:12 +0000551 TIntermTyped *typed = node ? node->getAsTyped() : 0;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000552 if (typed == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000553 error(line, "constructor argument does not have a type", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000554 return true;
555 }
556 if (op != EOpConstructStruct && IsSampler(typed->getBasicType())) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000557 error(line, "cannot convert a sampler", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000558 return true;
559 }
560 if (typed->getBasicType() == EbtVoid) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000561 error(line, "cannot convert a void", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000562 return true;
563 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000564
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000565 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000566}
567
568// This function checks to see if a void variable has been declared and raise an error message for such a case
569//
570// returns true in case of an error
571//
572bool TParseContext::voidErrorCheck(int line, const TString& identifier, const TPublicType& pubType)
573{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000574 if (pubType.type == EbtVoid) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000575 error(line, "illegal use of type 'void'", identifier.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000576 return true;
577 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000578
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000579 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000580}
581
582// This function checks to see if the node (for the expression) contains a scalar boolean expression or not
583//
584// returns true in case of an error
585//
586bool TParseContext::boolErrorCheck(int line, const TIntermTyped* type)
587{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000588 if (type->getBasicType() != EbtBool || type->isArray() || type->isMatrix() || type->isVector()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000589 error(line, "boolean expression expected", "");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000590 return true;
591 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000592
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000593 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000594}
595
596// This function checks to see if the node (for the expression) contains a scalar boolean expression or not
597//
598// returns true in case of an error
599//
600bool TParseContext::boolErrorCheck(int line, const TPublicType& pType)
601{
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000602 if (pType.type != EbtBool || pType.isAggregate()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000603 error(line, "boolean expression expected", "");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000604 return true;
605 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000606
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000607 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000608}
609
610bool TParseContext::samplerErrorCheck(int line, const TPublicType& pType, const char* reason)
611{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000612 if (pType.type == EbtStruct) {
613 if (containsSampler(*pType.userDef)) {
alokp@chromium.org58e54292010-08-24 21:40:03 +0000614 error(line, reason, getBasicString(pType.type), "(structure contains a sampler)");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000615
616 return true;
617 }
618
619 return false;
620 } else if (IsSampler(pType.type)) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000621 error(line, reason, getBasicString(pType.type));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000622
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000623 return true;
624 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000625
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000626 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000627}
628
629bool TParseContext::structQualifierErrorCheck(int line, const TPublicType& pType)
630{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000631 if ((pType.qualifier == EvqVaryingIn || pType.qualifier == EvqVaryingOut || pType.qualifier == EvqAttribute) &&
632 pType.type == EbtStruct) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000633 error(line, "cannot be used with a structure", getQualifierString(pType.qualifier));
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000634
635 return true;
636 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000637
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000638 if (pType.qualifier != EvqUniform && samplerErrorCheck(line, pType, "samplers must be uniform"))
639 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000640
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000641 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000642}
643
644bool TParseContext::parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type)
645{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000646 if ((qualifier == EvqOut || qualifier == EvqInOut) &&
647 type.getBasicType() != EbtStruct && IsSampler(type.getBasicType())) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000648 error(line, "samplers cannot be output parameters", type.getBasicString());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000649 return true;
650 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000651
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000652 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000653}
654
655bool TParseContext::containsSampler(TType& type)
656{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000657 if (IsSampler(type.getBasicType()))
658 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000659
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000660 if (type.getBasicType() == EbtStruct || type.getBasicType() == EbtInterfaceBlock) {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000661 TTypeList& structure = *type.getStruct();
662 for (unsigned int i = 0; i < structure.size(); ++i) {
663 if (containsSampler(*structure[i].type))
664 return true;
665 }
666 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000667
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000668 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000669}
670
671//
672// Do size checking for an array type's size.
673//
674// Returns true if there was an error.
675//
676bool TParseContext::arraySizeErrorCheck(int line, TIntermTyped* expr, int& size)
677{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000678 TIntermConstantUnion* constant = expr->getAsConstantUnion();
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000679
680 if (constant == 0 || !constant->isScalarInt())
681 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000682 error(line, "array size must be a constant integer expression", "");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000683 return true;
684 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000685
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000686 if (constant->getBasicType() == EbtUInt)
687 {
688 unsigned int uintSize = constant->getUConst(0);
689 if (uintSize > static_cast<unsigned int>(std::numeric_limits<int>::max()))
690 {
691 error(line, "array size too large", "");
692 size = 1;
693 return true;
694 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000695
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000696 size = static_cast<int>(uintSize);
697 }
698 else
699 {
700 size = constant->getIConst(0);
701
702 if (size <= 0)
703 {
704 error(line, "array size must be a positive integer", "");
705 size = 1;
706 return true;
707 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000708 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000709
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000710 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000711}
712
713//
714// See if this qualifier can be an array.
715//
716// Returns true if there is an error.
717//
718bool TParseContext::arrayQualifierErrorCheck(int line, TPublicType type)
719{
alokp@chromium.org8f0f24a2010-09-01 21:06:24 +0000720 if ((type.qualifier == EvqAttribute) || (type.qualifier == EvqConst)) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000721 error(line, "cannot declare arrays of this qualifier", TType(type).getCompleteString().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000722 return true;
723 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000724
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000725 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000726}
727
728//
729// See if this type can be an array.
730//
731// Returns true if there is an error.
732//
733bool TParseContext::arrayTypeErrorCheck(int line, TPublicType type)
734{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000735 //
736 // Can the type be an array?
737 //
738 if (type.array) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000739 error(line, "cannot declare arrays of arrays", TType(type).getCompleteString().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000740 return true;
741 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000742
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000743 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000744}
745
746//
747// Do all the semantic checking for declaring an array, with and
748// without a size, and make the right changes to the symbol table.
749//
750// size == 0 means no specified size.
751//
752// Returns true if there was an error.
753//
754bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType type, TVariable*& variable)
755{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000756 //
757 // Don't check for reserved word use until after we know it's not in the symbol table,
758 // because reserved arrays can be redeclared.
759 //
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000760
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000761 bool builtIn = false;
762 bool sameScope = false;
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000763 TSymbol* symbol = symbolTable.find(identifier, 0, &builtIn, &sameScope);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000764 if (symbol == 0 || !sameScope) {
765 if (reservedErrorCheck(line, identifier))
766 return true;
767
768 variable = new TVariable(&identifier, TType(type));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000769
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000770 if (type.arraySize)
771 variable->getType().setArraySize(type.arraySize);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000772
shannonwoods@chromium.org1c848092013-05-30 00:02:34 +0000773 if (! symbolTable.declare(*variable)) {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000774 delete variable;
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000775 error(line, "INTERNAL ERROR inserting new symbol", identifier.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000776 return true;
777 }
778 } else {
779 if (! symbol->isVariable()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000780 error(line, "variable expected", identifier.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000781 return true;
782 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000783
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000784 variable = static_cast<TVariable*>(symbol);
785 if (! variable->getType().isArray()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000786 error(line, "redeclaring non-array as array", identifier.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000787 return true;
788 }
789 if (variable->getType().getArraySize() > 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000790 error(line, "redeclaration of array with size", identifier.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000791 return true;
792 }
793
794 if (! variable->getType().sameElementType(TType(type))) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000795 error(line, "redeclaration of array with a different type", identifier.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000796 return true;
797 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000798
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000799 TType* t = variable->getArrayInformationType();
800 while (t != 0) {
801 if (t->getMaxArraySize() > type.arraySize) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000802 error(line, "higher index value already used for the array", identifier.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000803 return true;
804 }
805 t->setArraySize(type.arraySize);
806 t = t->getArrayInformationType();
807 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000808
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000809 if (type.arraySize)
810 variable->getType().setArraySize(type.arraySize);
811 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000812
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000813 if (voidErrorCheck(line, identifier, type))
814 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000815
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000816 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000817}
818
819bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, bool updateFlag, TSourceLoc line)
820{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000821 bool builtIn = false;
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000822 TSymbol* symbol = symbolTable.find(node->getSymbol(), 0, &builtIn);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000823 if (symbol == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000824 error(line, " undeclared identifier", node->getSymbol().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000825 return true;
826 }
827 TVariable* variable = static_cast<TVariable*>(symbol);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000828
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000829 type->setArrayInformationType(variable->getArrayInformationType());
830 variable->updateArrayInformationType(type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000831
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000832 // special casing to test index value of gl_FragData. If the accessed index is >= gl_MaxDrawBuffers
833 // its an error
834 if (node->getSymbol() == "gl_FragData") {
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000835 TSymbol* fragData = symbolTable.find("gl_MaxDrawBuffers", 0, &builtIn);
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000836 ASSERT(fragData);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000837
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000838 int fragDataValue = static_cast<TVariable*>(fragData)->getConstPointer()[0].getIConst();
839 if (fragDataValue <= size) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000840 error(line, "", "[", "gl_FragData can only have a max array size of up to gl_MaxDrawBuffers");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000841 return true;
842 }
843 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000844
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000845 // we dont want to update the maxArraySize when this flag is not set, we just want to include this
846 // node type in the chain of node types so that its updated when a higher maxArraySize comes in.
847 if (!updateFlag)
848 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000849
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000850 size++;
851 variable->getType().setMaxArraySize(size);
852 type->setMaxArraySize(size);
853 TType* tt = type;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000854
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000855 while(tt->getArrayInformationType() != 0) {
856 tt = tt->getArrayInformationType();
857 tt->setMaxArraySize(size);
858 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000859
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000860 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000861}
862
863//
864// Enforce non-initializer type/qualifier rules.
865//
866// Returns true if there was an error.
867//
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000868bool TParseContext::nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type, bool array)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000869{
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000870 if (type.qualifier == EvqConst)
871 {
872 // Make the qualifier make sense.
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000873 type.qualifier = EvqTemporary;
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000874
875 if (array)
876 {
877 error(line, "arrays may not be declared constant since they cannot be initialized", identifier.c_str());
878 }
879 else if (type.isStructureContainingArrays())
880 {
881 error(line, "structures containing arrays may not be declared constant since they cannot be initialized", identifier.c_str());
882 }
883 else
884 {
885 error(line, "variables with qualifier 'const' must be initialized", identifier.c_str());
886 }
887
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000888 return true;
889 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000890
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000891 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000892}
893
894//
895// Do semantic checking for a variable declaration that has no initializer,
896// and update the symbol table.
897//
898// Returns true if there was an error.
899//
zmo@google.comfd747b82011-04-23 01:30:07 +0000900bool TParseContext::nonInitErrorCheck(int line, TString& identifier, TPublicType& type, TVariable*& variable)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000901{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000902 if (reservedErrorCheck(line, identifier))
903 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000904
zmo@google.comfd747b82011-04-23 01:30:07 +0000905 variable = new TVariable(&identifier, TType(type));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000906
shannonwoods@chromium.org1c848092013-05-30 00:02:34 +0000907 if (! symbolTable.declare(*variable)) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000908 error(line, "redefinition", variable->getName().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000909 delete variable;
zmo@google.comfd747b82011-04-23 01:30:07 +0000910 variable = 0;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000911 return true;
912 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000913
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000914 if (voidErrorCheck(line, identifier, type))
915 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000916
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000917 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000918}
919
920bool TParseContext::paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type)
921{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000922 if (qualifier != EvqConst && qualifier != EvqTemporary) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000923 error(line, "qualifier not allowed on function parameter", getQualifierString(qualifier));
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000924 return true;
925 }
926 if (qualifier == EvqConst && paramQualifier != EvqIn) {
927 error(line, "qualifier not allowed with ", getQualifierString(qualifier), getQualifierString(paramQualifier));
928 return true;
929 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000930
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000931 if (qualifier == EvqConst)
alokp@chromium.org58e54292010-08-24 21:40:03 +0000932 type->setQualifier(EvqConstReadOnly);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000933 else
alokp@chromium.org58e54292010-08-24 21:40:03 +0000934 type->setQualifier(paramQualifier);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000935
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000936 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000937}
938
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000939bool TParseContext::extensionErrorCheck(int line, const TString& extension)
940{
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000941 const TExtensionBehavior& extBehavior = extensionBehavior();
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000942 TExtensionBehavior::const_iterator iter = extBehavior.find(extension.c_str());
943 if (iter == extBehavior.end()) {
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000944 error(line, "extension", extension.c_str(), "is not supported");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000945 return true;
946 }
zmo@google.comf5450912011-09-09 01:37:19 +0000947 // In GLSL ES, an extension's default behavior is "disable".
948 if (iter->second == EBhDisable || iter->second == EBhUndefined) {
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000949 error(line, "extension", extension.c_str(), "is disabled");
950 return true;
951 }
952 if (iter->second == EBhWarn) {
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000953 warning(line, "extension", extension.c_str(), "is being used");
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000954 return false;
955 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000956
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000957 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000958}
959
zmo@google.com09c323a2011-08-12 18:22:25 +0000960bool TParseContext::supportsExtension(const char* extension)
961{
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000962 const TExtensionBehavior& extbehavior = extensionBehavior();
963 TExtensionBehavior::const_iterator iter = extbehavior.find(extension);
964 return (iter != extbehavior.end());
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000965}
966
967void TParseContext::handleExtensionDirective(int line, const char* extName, const char* behavior)
968{
969 pp::SourceLocation loc;
970 DecodeSourceLoc(line, &loc.file, &loc.line);
971 directiveHandler.handleExtension(loc, extName, behavior);
972}
973
974void TParseContext::handlePragmaDirective(int line, const char* name, const char* value)
975{
976 pp::SourceLocation loc;
977 DecodeSourceLoc(line, &loc.file, &loc.line);
978 directiveHandler.handlePragma(loc, name, value);
zmo@google.com09c323a2011-08-12 18:22:25 +0000979}
980
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000981/////////////////////////////////////////////////////////////////////////////////
982//
983// Non-Errors.
984//
985/////////////////////////////////////////////////////////////////////////////////
986
987//
988// Look up a function name in the symbol table, and make sure it is a function.
989//
990// Return the function symbol if found, otherwise 0.
991//
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000992const TFunction* TParseContext::findFunction(int line, TFunction* call, int shaderVersion, bool *builtIn)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000993{
alokp@chromium.org0a576182010-08-09 17:16:27 +0000994 // First find by unmangled name to check whether the function name has been
995 // hidden by a variable name or struct typename.
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000996 const TSymbol* symbol = symbolTable.find(call->getName(), shaderVersion, builtIn);
alokp@chromium.org0a576182010-08-09 17:16:27 +0000997 if (symbol == 0) {
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000998 symbol = symbolTable.find(call->getMangledName(), shaderVersion, builtIn);
alokp@chromium.org0a576182010-08-09 17:16:27 +0000999 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001000
alokp@chromium.org0a576182010-08-09 17:16:27 +00001001 if (symbol == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001002 error(line, "no matching overloaded function found", call->getName().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001003 return 0;
1004 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001005
alokp@chromium.org0a576182010-08-09 17:16:27 +00001006 if (!symbol->isFunction()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001007 error(line, "function name expected", call->getName().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001008 return 0;
1009 }
alokp@chromium.org0a576182010-08-09 17:16:27 +00001010
1011 return static_cast<const TFunction*>(symbol);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001012}
1013
1014//
1015// Initializers show up in several places in the grammar. Have one set of
1016// code to handle them here.
1017//
1018bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType,
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001019 TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001020{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001021 TType type = TType(pType);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001022
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001023 if (variable == 0) {
1024 if (reservedErrorCheck(line, identifier))
1025 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001026
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001027 if (voidErrorCheck(line, identifier, pType))
1028 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001029
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001030 //
1031 // add variable to symbol table
1032 //
1033 variable = new TVariable(&identifier, type);
shannonwoods@chromium.org1c848092013-05-30 00:02:34 +00001034 if (! symbolTable.declare(*variable)) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001035 error(line, "redefinition", variable->getName().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001036 return true;
1037 // don't delete variable, it's used by error recovery, and the pool
1038 // pop will take care of the memory
1039 }
1040 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001041
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001042 //
1043 // identifier must be of type constant, a global, or a temporary
1044 //
1045 TQualifier qualifier = variable->getType().getQualifier();
1046 if ((qualifier != EvqTemporary) && (qualifier != EvqGlobal) && (qualifier != EvqConst)) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001047 error(line, " cannot initialize this type of qualifier ", variable->getType().getQualifierString());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001048 return true;
1049 }
1050 //
1051 // test for and propagate constant
1052 //
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001053
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001054 if (qualifier == EvqConst) {
1055 if (qualifier != initializer->getType().getQualifier()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001056 std::stringstream extraInfoStream;
1057 extraInfoStream << "'" << variable->getType().getCompleteString() << "'";
1058 std::string extraInfo = extraInfoStream.str();
1059 error(line, " assigning non-constant to", "=", extraInfo.c_str());
alokp@chromium.org58e54292010-08-24 21:40:03 +00001060 variable->getType().setQualifier(EvqTemporary);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001061 return true;
1062 }
1063 if (type != initializer->getType()) {
1064 error(line, " non-matching types for const initializer ",
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001065 variable->getType().getQualifierString());
alokp@chromium.org58e54292010-08-24 21:40:03 +00001066 variable->getType().setQualifier(EvqTemporary);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001067 return true;
1068 }
1069 if (initializer->getAsConstantUnion()) {
alokp@chromium.org6ff56fd2010-05-05 16:37:50 +00001070 ConstantUnion* unionArray = variable->getConstPointer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001071
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001072 if (type.getObjectSize() == 1 && type.getBasicType() != EbtStruct) {
1073 *unionArray = (initializer->getAsConstantUnion()->getUnionArrayPointer())[0];
1074 } else {
1075 variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer());
1076 }
1077 } else if (initializer->getAsSymbolNode()) {
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +00001078 const TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol(), 0);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001079 const TVariable* tVar = static_cast<const TVariable*>(symbol);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001080
alokp@chromium.org6ff56fd2010-05-05 16:37:50 +00001081 ConstantUnion* constArray = tVar->getConstPointer();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001082 variable->shareConstPointer(constArray);
1083 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001084 std::stringstream extraInfoStream;
1085 extraInfoStream << "'" << variable->getType().getCompleteString() << "'";
1086 std::string extraInfo = extraInfoStream.str();
1087 error(line, " cannot assign to", "=", extraInfo.c_str());
alokp@chromium.org58e54292010-08-24 21:40:03 +00001088 variable->getType().setQualifier(EvqTemporary);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001089 return true;
1090 }
1091 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001092
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001093 if (qualifier != EvqConst) {
1094 TIntermSymbol* intermSymbol = intermediate.addSymbol(variable->getUniqueId(), variable->getName(), variable->getType(), line);
1095 intermNode = intermediate.addAssign(EOpInitialize, intermSymbol, initializer, line);
1096 if (intermNode == 0) {
1097 assignError(line, "=", intermSymbol->getCompleteString(), initializer->getCompleteString());
1098 return true;
1099 }
1100 } else
1101 intermNode = 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001102
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001103 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001104}
1105
1106bool TParseContext::areAllChildConst(TIntermAggregate* aggrNode)
1107{
alokp@chromium.orgd300f5b2010-10-14 16:10:20 +00001108 ASSERT(aggrNode != NULL);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001109 if (!aggrNode->isConstructor())
1110 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001111
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001112 bool allConstant = true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001113
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001114 // check if all the child nodes are constants so that they can be inserted into
1115 // the parent node
alokp@chromium.orgd300f5b2010-10-14 16:10:20 +00001116 TIntermSequence &sequence = aggrNode->getSequence() ;
1117 for (TIntermSequence::iterator p = sequence.begin(); p != sequence.end(); ++p) {
1118 if (!(*p)->getAsTyped()->getAsConstantUnion())
1119 return false;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001120 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001121
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001122 return allConstant;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001123}
1124
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001125TPublicType TParseContext::addFullySpecifiedType(TQualifier qualifier, const TPublicType& typeSpecifier)
1126{
1127 TPublicType returnType = typeSpecifier;
1128 returnType.qualifier = qualifier;
1129
1130 if (typeSpecifier.array)
1131 {
1132 error(typeSpecifier.line, "not supported", "first-class array");
1133 recover();
1134 returnType.setArray(false);
1135 }
1136
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001137 if (shaderVersion < 300)
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001138 {
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001139 if (qualifier == EvqAttribute && (typeSpecifier.type == EbtBool || typeSpecifier.type == EbtInt))
1140 {
1141 error(typeSpecifier.line, "cannot be bool or int", getQualifierString(qualifier));
1142 recover();
1143 }
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001144
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001145 if ((qualifier == EvqVaryingIn || qualifier == EvqVaryingOut) &&
1146 (typeSpecifier.type == EbtBool || typeSpecifier.type == EbtInt))
1147 {
1148 error(typeSpecifier.line, "cannot be bool or int", getQualifierString(qualifier));
1149 recover();
1150 }
1151 }
1152 else
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001153 {
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001154 if (qualifier == EvqAttribute && typeSpecifier.type == EbtBool)
1155 {
1156 error(typeSpecifier.line, "cannot be bool", getQualifierString(qualifier));
1157 recover();
1158 }
1159
1160 if ((qualifier == EvqVaryingIn || qualifier == EvqVaryingOut) && typeSpecifier.type == EbtBool)
1161 {
1162 error(typeSpecifier.line, "cannot be bool", getQualifierString(qualifier));
1163 recover();
1164 }
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001165 }
1166
1167 return returnType;
1168}
1169
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00001170TFunction *TParseContext::addConstructorFunc(TPublicType publicType)
1171{
1172 TOperator op = EOpNull;
1173 if (publicType.userDef)
1174 {
1175 op = EOpConstructStruct;
1176 }
1177 else
1178 {
1179 switch (publicType.type)
1180 {
1181 case EbtFloat:
1182 if (publicType.isMatrix())
1183 {
1184 // TODO: non-square matrices
1185 switch(publicType.getCols())
1186 {
1187 case 2: op = EOpConstructMat2; break;
1188 case 3: op = EOpConstructMat3; break;
1189 case 4: op = EOpConstructMat4; break;
1190 }
1191 }
1192 else
1193 {
1194 switch(publicType.getNominalSize())
1195 {
1196 case 1: op = EOpConstructFloat; break;
1197 case 2: op = EOpConstructVec2; break;
1198 case 3: op = EOpConstructVec3; break;
1199 case 4: op = EOpConstructVec4; break;
1200 }
1201 }
1202 break;
1203
1204 case EbtInt:
1205 switch(publicType.getNominalSize())
1206 {
1207 case 1: op = EOpConstructInt; break;
1208 case 2: op = EOpConstructIVec2; break;
1209 case 3: op = EOpConstructIVec3; break;
1210 case 4: op = EOpConstructIVec4; break;
1211 }
1212 break;
1213
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +00001214 case EbtUInt:
1215 switch(publicType.getNominalSize())
1216 {
1217 case 1: op = EOpConstructUnsignedInt; break;
1218 default: UNIMPLEMENTED(); break;
1219 }
1220 break;
1221
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00001222 case EbtBool:
1223 switch(publicType.getNominalSize())
1224 {
1225 case 1: op = EOpConstructBool; break;
1226 case 2: op = EOpConstructBVec2; break;
1227 case 3: op = EOpConstructBVec3; break;
1228 case 4: op = EOpConstructBVec4; break;
1229 }
1230 break;
1231
1232 default: break;
1233 }
1234
1235 if (op == EOpNull)
1236 {
1237 error(publicType.line, "cannot construct this type", getBasicString(publicType.type));
1238 recover();
1239 publicType.type = EbtFloat;
1240 op = EOpConstructFloat;
1241 }
1242 }
1243
1244 TString tempString;
1245 TType type(publicType);
1246 return new TFunction(&tempString, type, op);
1247}
1248
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001249// This function is used to test for the correctness of the parameters passed to various constructor functions
1250// and also convert them to the right datatype if it is allowed and required.
1251//
1252// Returns 0 for an error or the constructed node (aggregate or typed) for no error.
1253//
1254TIntermTyped* TParseContext::addConstructor(TIntermNode* node, const TType* type, TOperator op, TFunction* fnCall, TSourceLoc line)
1255{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001256 if (node == 0)
1257 return 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001258
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001259 TIntermAggregate* aggrNode = node->getAsAggregate();
1260
alokp@chromium.org58e54292010-08-24 21:40:03 +00001261 TTypeList::const_iterator memberTypes;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001262 if (op == EOpConstructStruct)
1263 memberTypes = type->getStruct()->begin();
1264
1265 TType elementType = *type;
1266 if (type->isArray())
1267 elementType.clearArrayness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001268
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001269 bool singleArg;
1270 if (aggrNode) {
1271 if (aggrNode->getOp() != EOpNull || aggrNode->getSequence().size() == 1)
1272 singleArg = true;
1273 else
1274 singleArg = false;
1275 } else
1276 singleArg = true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001277
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001278 TIntermTyped *newNode;
1279 if (singleArg) {
1280 // If structure constructor or array constructor is being called
1281 // for only one parameter inside the structure, we need to call constructStruct function once.
1282 if (type->isArray())
1283 newNode = constructStruct(node, &elementType, 1, node->getLine(), false);
1284 else if (op == EOpConstructStruct)
1285 newNode = constructStruct(node, (*memberTypes).type, 1, node->getLine(), false);
1286 else
1287 newNode = constructBuiltIn(type, op, node, node->getLine(), false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001288
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001289 if (newNode && newNode->getAsAggregate()) {
1290 TIntermTyped* constConstructor = foldConstConstructor(newNode->getAsAggregate(), *type);
1291 if (constConstructor)
1292 return constConstructor;
1293 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001294
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001295 return newNode;
1296 }
1297
1298 //
1299 // Handle list of arguments.
1300 //
1301 TIntermSequence &sequenceVector = aggrNode->getSequence() ; // Stores the information about the parameter to the constructor
1302 // if the structure constructor contains more than one parameter, then construct
1303 // each parameter
1304
1305 int paramCount = 0; // keeps a track of the constructor parameter number being checked
1306
1307 // for each parameter to the constructor call, check to see if the right type is passed or convert them
1308 // to the right type if possible (and allowed).
1309 // for structure constructors, just check if the right type is passed, no conversion is allowed.
1310
1311 for (TIntermSequence::iterator p = sequenceVector.begin();
1312 p != sequenceVector.end(); p++, paramCount++) {
1313 if (type->isArray())
1314 newNode = constructStruct(*p, &elementType, paramCount+1, node->getLine(), true);
1315 else if (op == EOpConstructStruct)
1316 newNode = constructStruct(*p, (memberTypes[paramCount]).type, paramCount+1, node->getLine(), true);
1317 else
1318 newNode = constructBuiltIn(type, op, *p, node->getLine(), true);
1319
1320 if (newNode) {
1321 *p = newNode;
1322 }
1323 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001324
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001325 TIntermTyped* constructor = intermediate.setAggregateOperator(aggrNode, op, line);
1326 TIntermTyped* constConstructor = foldConstConstructor(constructor->getAsAggregate(), *type);
1327 if (constConstructor)
1328 return constConstructor;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001329
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001330 return constructor;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001331}
1332
1333TIntermTyped* TParseContext::foldConstConstructor(TIntermAggregate* aggrNode, const TType& type)
1334{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001335 bool canBeFolded = areAllChildConst(aggrNode);
1336 aggrNode->setType(type);
1337 if (canBeFolded) {
1338 bool returnVal = false;
alokp@chromium.org6ff56fd2010-05-05 16:37:50 +00001339 ConstantUnion* unionArray = new ConstantUnion[type.getObjectSize()];
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001340 if (aggrNode->getSequence().size() == 1) {
1341 returnVal = intermediate.parseConstTree(aggrNode->getLine(), aggrNode, unionArray, aggrNode->getOp(), symbolTable, type, true);
1342 }
1343 else {
1344 returnVal = intermediate.parseConstTree(aggrNode->getLine(), aggrNode, unionArray, aggrNode->getOp(), symbolTable, type);
1345 }
1346 if (returnVal)
1347 return 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001348
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001349 return intermediate.addConstantUnion(unionArray, type, aggrNode->getLine());
1350 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001351
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001352 return 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001353}
1354
1355// Function for constructor implementation. Calls addUnaryMath with appropriate EOp value
1356// for the parameter to the constructor (passed to this function). Essentially, it converts
1357// the parameter types correctly. If a constructor expects an int (like ivec2) and is passed a
1358// float, then float is converted to int.
1359//
1360// Returns 0 for an error or the constructed node.
1361//
1362TIntermTyped* TParseContext::constructBuiltIn(const TType* type, TOperator op, TIntermNode* node, TSourceLoc line, bool subset)
1363{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001364 TIntermTyped* newNode;
1365 TOperator basicOp;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001366
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001367 //
1368 // First, convert types as needed.
1369 //
1370 switch (op) {
1371 case EOpConstructVec2:
1372 case EOpConstructVec3:
1373 case EOpConstructVec4:
1374 case EOpConstructMat2:
1375 case EOpConstructMat3:
1376 case EOpConstructMat4:
1377 case EOpConstructFloat:
1378 basicOp = EOpConstructFloat;
1379 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001380
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001381 case EOpConstructIVec2:
1382 case EOpConstructIVec3:
1383 case EOpConstructIVec4:
1384 case EOpConstructInt:
1385 basicOp = EOpConstructInt;
1386 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001387
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +00001388 case EOpConstructUnsignedInt:
1389 basicOp = EOpConstructUnsignedInt;
1390 break;
1391
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001392 case EOpConstructBVec2:
1393 case EOpConstructBVec3:
1394 case EOpConstructBVec4:
1395 case EOpConstructBool:
1396 basicOp = EOpConstructBool;
1397 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001398
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001399 default:
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001400 error(line, "unsupported construction", "");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001401 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001402
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001403 return 0;
1404 }
1405 newNode = intermediate.addUnaryMath(basicOp, node, node->getLine(), symbolTable);
1406 if (newNode == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001407 error(line, "can't convert", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001408 return 0;
1409 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001410
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001411 //
1412 // Now, if there still isn't an operation to do the construction, and we need one, add one.
1413 //
1414
1415 // Otherwise, skip out early.
1416 if (subset || (newNode != node && newNode->getType() == *type))
1417 return newNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001418
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001419 // setAggregateOperator will insert a new node for the constructor, as needed.
1420 return intermediate.setAggregateOperator(newNode, op, line);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001421}
1422
1423// This function tests for the type of the parameters to the structures constructors. Raises
1424// an error message if the expected type does not match the parameter passed to the constructor.
1425//
1426// Returns 0 for an error or the input node itself if the expected and the given parameter types match.
1427//
1428TIntermTyped* TParseContext::constructStruct(TIntermNode* node, TType* type, int paramCount, TSourceLoc line, bool subset)
1429{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001430 if (*type == node->getAsTyped()->getType()) {
1431 if (subset)
1432 return node->getAsTyped();
1433 else
1434 return intermediate.setAggregateOperator(node->getAsTyped(), EOpConstructStruct, line);
1435 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001436 std::stringstream extraInfoStream;
1437 extraInfoStream << "cannot convert parameter " << paramCount
1438 << " from '" << node->getAsTyped()->getType().getBasicString()
1439 << "' to '" << type->getBasicString() << "'";
1440 std::string extraInfo = extraInfoStream.str();
1441 error(line, "", "constructor", extraInfo.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001442 recover();
1443 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001444
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001445 return 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001446}
1447
1448//
1449// This function returns the tree representation for the vector field(s) being accessed from contant vector.
1450// If only one component of vector is accessed (v.x or v[0] where v is a contant vector), then a contant node is
1451// returned, else an aggregate node is returned (for v.xy). The input to this function could either be the symbol
1452// node or it could be the intermediate tree representation of accessing fields in a constant structure or column of
1453// a constant matrix.
1454//
1455TIntermTyped* TParseContext::addConstVectorNode(TVectorFields& fields, TIntermTyped* node, TSourceLoc line)
1456{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001457 TIntermTyped* typedNode;
1458 TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001459
alokp@chromium.org6ff56fd2010-05-05 16:37:50 +00001460 ConstantUnion *unionArray;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001461 if (tempConstantNode) {
1462 unionArray = tempConstantNode->getUnionArrayPointer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001463
alokp@chromium.org8b851c62012-06-15 16:25:11 +00001464 if (!unionArray) {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001465 return node;
1466 }
1467 } else { // The node has to be either a symbol node or an aggregate node or a tempConstant node, else, its an error
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001468 error(line, "Cannot offset into the vector", "Error");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001469 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001470
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001471 return 0;
1472 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001473
alokp@chromium.org6ff56fd2010-05-05 16:37:50 +00001474 ConstantUnion* constArray = new ConstantUnion[fields.num];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001475
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001476 for (int i = 0; i < fields.num; i++) {
1477 if (fields.offsets[i] >= node->getType().getObjectSize()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001478 std::stringstream extraInfoStream;
1479 extraInfoStream << "vector field selection out of range '" << fields.offsets[i] << "'";
1480 std::string extraInfo = extraInfoStream.str();
1481 error(line, "", "[", extraInfo.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001482 recover();
1483 fields.offsets[i] = 0;
1484 }
1485
1486 constArray[i] = unionArray[fields.offsets[i]];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001487
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001488 }
1489 typedNode = intermediate.addConstantUnion(constArray, node->getType(), line);
1490 return typedNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001491}
1492
1493//
1494// This function returns the column being accessed from a constant matrix. The values are retrieved from
1495// the symbol table and parse-tree is built for a vector (each column of a matrix is a vector). The input
1496// to the function could either be a symbol node (m[0] where m is a constant matrix)that represents a
1497// constant matrix or it could be the tree representation of the constant matrix (s.m1[0] where s is a constant structure)
1498//
1499TIntermTyped* TParseContext::addConstMatrixNode(int index, TIntermTyped* node, TSourceLoc line)
1500{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001501 TIntermTyped* typedNode;
1502 TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001503
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +00001504 if (index >= node->getType().getCols()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001505 std::stringstream extraInfoStream;
1506 extraInfoStream << "matrix field selection out of range '" << index << "'";
1507 std::string extraInfo = extraInfoStream.str();
1508 error(line, "", "[", extraInfo.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001509 recover();
1510 index = 0;
1511 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001512
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001513 if (tempConstantNode) {
alokp@chromium.org6ff56fd2010-05-05 16:37:50 +00001514 ConstantUnion* unionArray = tempConstantNode->getUnionArrayPointer();
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00001515 int size = tempConstantNode->getType().getCols();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001516 typedNode = intermediate.addConstantUnion(&unionArray[size*index], tempConstantNode->getType(), line);
1517 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001518 error(line, "Cannot offset into the matrix", "Error");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001519 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001520
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001521 return 0;
1522 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001523
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001524 return typedNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001525}
1526
1527
1528//
1529// This function returns an element of an array accessed from a constant array. The values are retrieved from
1530// the symbol table and parse-tree is built for the type of the element. The input
1531// to the function could either be a symbol node (a[0] where a is a constant array)that represents a
1532// constant array or it could be the tree representation of the constant array (s.a1[0] where s is a constant structure)
1533//
1534TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line)
1535{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001536 TIntermTyped* typedNode;
1537 TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion();
1538 TType arrayElementType = node->getType();
1539 arrayElementType.clearArrayness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001540
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001541 if (index >= node->getType().getArraySize()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001542 std::stringstream extraInfoStream;
1543 extraInfoStream << "array field selection out of range '" << index << "'";
1544 std::string extraInfo = extraInfoStream.str();
1545 error(line, "", "[", extraInfo.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001546 recover();
1547 index = 0;
1548 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001549
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001550 int arrayElementSize = arrayElementType.getObjectSize();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001551
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001552 if (tempConstantNode) {
alokp@chromium.org6ff56fd2010-05-05 16:37:50 +00001553 ConstantUnion* unionArray = tempConstantNode->getUnionArrayPointer();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001554 typedNode = intermediate.addConstantUnion(&unionArray[arrayElementSize * index], tempConstantNode->getType(), line);
1555 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001556 error(line, "Cannot offset into the array", "Error");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001557 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001558
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001559 return 0;
1560 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001561
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001562 return typedNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001563}
1564
1565
1566//
1567// This function returns the value of a particular field inside a constant structure from the symbol table.
1568// If there is an embedded/nested struct, it appropriately calls addConstStructNested or addConstStructFromAggr
1569// function and returns the parse-tree with the values of the embedded/nested struct.
1570//
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00001571TIntermTyped* TParseContext::addConstStruct(const TString &identifier, TIntermTyped *node, TSourceLoc line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001572{
alokp@chromium.org58e54292010-08-24 21:40:03 +00001573 const TTypeList* fields = node->getType().getStruct();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001574 TIntermTyped *typedNode;
1575 int instanceSize = 0;
1576 unsigned int index = 0;
1577 TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001578
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001579 for ( index = 0; index < fields->size(); ++index) {
1580 if ((*fields)[index].type->getFieldName() == identifier) {
1581 break;
1582 } else {
1583 instanceSize += (*fields)[index].type->getObjectSize();
1584 }
1585 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001586
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001587 if (tempConstantNode) {
alokp@chromium.org6ff56fd2010-05-05 16:37:50 +00001588 ConstantUnion* constArray = tempConstantNode->getUnionArrayPointer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001589
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001590 typedNode = intermediate.addConstantUnion(constArray+instanceSize, tempConstantNode->getType(), line); // type will be changed in the calling function
1591 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001592 error(line, "Cannot offset into the structure", "Error");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001593 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001594
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001595 return 0;
1596 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001597
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001598 return typedNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001599}
1600
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00001601//
1602// Interface/uniform blocks
1603//
1604TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualifier, TSourceLoc nameLine, const TString& blockName, TTypeList* typeList,
1605 const TString& instanceName, TSourceLoc instanceLine, TIntermTyped* arrayIndex, TSourceLoc arrayIndexLine)
1606{
1607 if (reservedErrorCheck(nameLine, blockName))
1608 recover();
1609
1610 if (typeQualifier.qualifier != EvqUniform)
1611 {
1612 error(typeQualifier.line, "invalid qualifier:", getQualifierString(typeQualifier.qualifier), "interface blocks must be uniform");
1613 recover();
1614 }
1615
1616 TSymbol* blockNameSymbol = new TInterfaceBlockName(&blockName);
1617 if (!symbolTable.declare(*blockNameSymbol)) {
1618 error(nameLine, "redefinition", blockName.c_str(), "interface block name");
1619 recover();
1620 }
1621
1622 // check for sampler types
1623 for (size_t memberIndex = 0; memberIndex < typeList->size(); ++memberIndex) {
1624 const TTypeLine& memberTypeLine = (*typeList)[memberIndex];
1625 TType* memberType = memberTypeLine.type;
1626 if (IsSampler(memberType->getBasicType())) {
1627 error(memberTypeLine.line, "unsupported type", memberType->getBasicString(), "sampler types are not allowed in interface blocks");
1628 recover();
1629 }
1630
1631 const TQualifier qualifier = memberTypeLine.type->getQualifier();
1632 switch (qualifier)
1633 {
1634 case EvqGlobal:
1635 case EvqUniform:
1636 break;
1637 default:
1638 error(memberTypeLine.line, "invalid qualifier on interface block member", getQualifierString(qualifier));
1639 recover();
1640 break;
1641 }
1642 }
1643
1644 TType* interfaceBlock = new TType(typeList, blockName);
1645 interfaceBlock->setBasicType(EbtInterfaceBlock);
1646 interfaceBlock->setQualifier(typeQualifier.qualifier);
1647
1648 TString symbolName = "";
1649 int symbolId = 0;
1650
1651 if (instanceName == "")
1652 {
1653 // define symbols for the members of the interface block
1654 for (size_t memberIndex = 0; memberIndex < typeList->size(); ++memberIndex) {
1655 const TTypeLine& memberTypeLine = (*typeList)[memberIndex];
1656 TType* memberType = memberTypeLine.type;
1657 memberType->setInterfaceBlockType(interfaceBlock);
1658 TVariable* memberVariable = new TVariable(&memberType->getFieldName(), *memberType);
1659 memberVariable->setQualifier(typeQualifier.qualifier);
1660 if (!symbolTable.declare(*memberVariable)) {
1661 error(memberTypeLine.line, "redefinition", memberType->getFieldName().c_str(), "interface block member name");
1662 recover();
1663 }
1664 }
1665 }
1666 else
1667 {
1668 interfaceBlock->setInstanceName(instanceName);
1669
1670 // add array index
1671 if (arrayIndex != NULL)
1672 {
1673 int size;
1674 if (arraySizeErrorCheck(arrayIndexLine, arrayIndex, size))
1675 recover();
1676 interfaceBlock->setArraySize(size);
1677 }
1678
1679 // add a symbol for this interface block
1680 TVariable* instanceTypeDef = new TVariable(&instanceName, *interfaceBlock, false);
1681 instanceTypeDef->setQualifier(typeQualifier.qualifier);
1682 if (!symbolTable.declare(*instanceTypeDef)) {
1683 error(instanceLine, "redefinition", instanceName.c_str(), "interface block instance name");
1684 recover();
1685 }
1686
1687 symbolId = instanceTypeDef->getUniqueId();
1688 symbolName = instanceTypeDef->getName();
1689 }
1690
1691 exitStructDeclaration();
1692 TIntermAggregate *aggregate = intermediate.makeAggregate(intermediate.addSymbol(symbolId, symbolName, *interfaceBlock, typeQualifier.line), nameLine);
1693 aggregate->setOp(EOpDeclaration);
1694 return aggregate;
1695}
1696
kbr@chromium.org476541f2011-10-27 21:14:51 +00001697bool TParseContext::enterStructDeclaration(int line, const TString& identifier)
1698{
1699 ++structNestingLevel;
1700
1701 // Embedded structure definitions are not supported per GLSL ES spec.
1702 // They aren't allowed in GLSL either, but we need to detect this here
1703 // so we don't rely on the GLSL compiler to catch it.
1704 if (structNestingLevel > 1) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001705 error(line, "", "Embedded struct definitions are not allowed");
kbr@chromium.org476541f2011-10-27 21:14:51 +00001706 return true;
1707 }
1708
1709 return false;
1710}
1711
1712void TParseContext::exitStructDeclaration()
1713{
1714 --structNestingLevel;
1715}
1716
1717namespace {
1718
1719const int kWebGLMaxStructNesting = 4;
1720
1721} // namespace
1722
1723bool TParseContext::structNestingErrorCheck(TSourceLoc line, const TType& fieldType)
1724{
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +00001725 if (!isWebGLBasedSpec(shaderSpec)) {
kbr@chromium.org476541f2011-10-27 21:14:51 +00001726 return false;
1727 }
1728
1729 if (fieldType.getBasicType() != EbtStruct) {
1730 return false;
1731 }
1732
1733 // We're already inside a structure definition at this point, so add
1734 // one to the field's struct nesting.
kbr@chromium.org9a4d1122012-01-05 20:06:28 +00001735 if (1 + fieldType.getDeepestStructNesting() > kWebGLMaxStructNesting) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001736 std::stringstream extraInfoStream;
1737 extraInfoStream << "Reference of struct type " << fieldType.getTypeName()
1738 << " exceeds maximum struct nesting of " << kWebGLMaxStructNesting;
1739 std::string extraInfo = extraInfoStream.str();
1740 error(line, "", "", extraInfo.c_str());
kbr@chromium.org476541f2011-10-27 21:14:51 +00001741 return true;
1742 }
1743
1744 return false;
1745}
1746
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00001747//
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00001748// Parse an array index expression
1749//
1750TIntermTyped* TParseContext::addIndexExpression(TIntermTyped *baseExpression, TSourceLoc location, TIntermTyped *indexExpression)
1751{
1752 TIntermTyped *indexedExpression = NULL;
1753
1754 if (!baseExpression->isArray() && !baseExpression->isMatrix() && !baseExpression->isVector())
1755 {
1756 if (baseExpression->getAsSymbolNode())
1757 {
1758 error(location, " left of '[' is not of type array, matrix, or vector ", baseExpression->getAsSymbolNode()->getSymbol().c_str());
1759 }
1760 else
1761 {
1762 error(location, " left of '[' is not of type array, matrix, or vector ", "expression");
1763 }
1764 recover();
1765 }
1766 if (baseExpression->getType().getQualifier() == EvqConst && indexExpression->getQualifier() == EvqConst)
1767 {
1768 if (baseExpression->isArray())
1769 {
1770 // constant folding for arrays
1771 indexedExpression = addConstArrayNode(indexExpression->getAsConstantUnion()->getIConst(0), baseExpression, location);
1772 }
1773 else if (baseExpression->isVector())
1774 {
1775 // constant folding for vectors
1776 TVectorFields fields;
1777 fields.num = 1;
1778 fields.offsets[0] = indexExpression->getAsConstantUnion()->getIConst(0); // need to do it this way because v.xy sends fields integer array
1779 indexedExpression = addConstVectorNode(fields, baseExpression, location);
1780 }
1781 else if (baseExpression->isMatrix())
1782 {
1783 // constant folding for matrices
1784 indexedExpression = addConstMatrixNode(indexExpression->getAsConstantUnion()->getIConst(0), baseExpression, location);
1785 }
1786 }
1787 else
1788 {
1789 if (indexExpression->getQualifier() == EvqConst)
1790 {
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00001791 const bool isMatrixOrVector = (baseExpression->isVector() || baseExpression->isMatrix());
1792 const bool indexOOR = (isMatrixOrVector && baseExpression->getType().getNominalSize() <= indexExpression->getAsConstantUnion()->getIConst(0));
1793
1794 // check for index out-of-range
1795 if (indexOOR && !baseExpression->isArray())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00001796 {
1797 std::stringstream extraInfoStream;
1798 extraInfoStream << "field selection out of range '" << indexExpression->getAsConstantUnion()->getIConst(0) << "'";
1799 std::string extraInfo = extraInfoStream.str();
1800 error(location, "", "[", extraInfo.c_str());
1801 recover();
1802 }
1803 else
1804 {
1805 if (baseExpression->isArray())
1806 {
1807 if (baseExpression->getType().getArraySize() == 0)
1808 {
1809 if (baseExpression->getType().getMaxArraySize() <= indexExpression->getAsConstantUnion()->getIConst(0))
1810 {
1811 if (arraySetMaxSize(baseExpression->getAsSymbolNode(), baseExpression->getTypePointer(), indexExpression->getAsConstantUnion()->getIConst(0), true, location))
1812 recover();
1813 }
1814 else
1815 {
1816 if (arraySetMaxSize(baseExpression->getAsSymbolNode(), baseExpression->getTypePointer(), 0, false, location))
1817 recover();
1818 }
1819 }
1820 else if ( indexExpression->getAsConstantUnion()->getIConst(0) >= baseExpression->getType().getArraySize())
1821 {
1822 std::stringstream extraInfoStream;
1823 extraInfoStream << "array index out of range '" << indexExpression->getAsConstantUnion()->getIConst(0) << "'";
1824 std::string extraInfo = extraInfoStream.str();
1825 error(location, "", "[", extraInfo.c_str());
1826 recover();
1827 }
1828 }
1829 indexedExpression = intermediate.addIndex(EOpIndexDirect, baseExpression, indexExpression, location);
1830 }
1831 }
1832 else
1833 {
1834 if (baseExpression->isArray() && baseExpression->getType().getArraySize() == 0)
1835 {
1836 error(location, "", "[", "array must be redeclared with a size before being indexed with a variable");
1837 recover();
1838 }
shannonwoods@chromium.orge429ab72013-05-30 00:12:52 +00001839 else if (baseExpression->getBasicType() == EbtInterfaceBlock)
1840 {
1841 error(location, "", "[", "array indexes for interface blocks arrays must be constant integeral expressions");
1842 recover();
1843 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00001844
1845 indexedExpression = intermediate.addIndex(EOpIndexIndirect, baseExpression, indexExpression, location);
1846 }
1847 }
1848 if (indexedExpression == 0)
1849 {
1850 ConstantUnion *unionArray = new ConstantUnion[1];
1851 unionArray->setFConst(0.0f);
1852 indexedExpression = intermediate.addConstantUnion(unionArray, TType(EbtFloat, EbpHigh, EvqConst), location);
1853 }
1854 else if (baseExpression->isArray())
1855 {
1856 if (baseExpression->getType().getStruct())
1857 {
shannonwoods@chromium.orge429ab72013-05-30 00:12:52 +00001858 TType copyOfType(baseExpression->getType().getStruct(), baseExpression->getType().getTypeName());
1859 copyOfType.setBasicType(baseExpression->getType().getBasicType()); // necessary to preserve interface block basic type
1860 indexedExpression->setType(copyOfType);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00001861 }
1862 else
1863 {
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00001864 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqTemporary, baseExpression->getNominalSize(), baseExpression->getSecondarySize()));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00001865 }
1866
1867 if (baseExpression->getType().getQualifier() == EvqConst)
1868 {
1869 indexedExpression->getTypePointer()->setQualifier(EvqConst);
1870 }
1871 }
1872 else if (baseExpression->isMatrix() && baseExpression->getType().getQualifier() == EvqConst)
1873 {
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00001874 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqConst, baseExpression->getRows()));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00001875 }
1876 else if (baseExpression->isMatrix())
1877 {
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00001878 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqTemporary, baseExpression->getRows()));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00001879 }
1880 else if (baseExpression->isVector() && baseExpression->getType().getQualifier() == EvqConst)
1881 {
1882 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqConst));
1883 }
1884 else if (baseExpression->isVector())
1885 {
1886 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqTemporary));
1887 }
1888 else
1889 {
1890 indexedExpression->setType(baseExpression->getType());
1891 }
1892
1893 return indexedExpression;
1894}
1895
1896TIntermTyped* TParseContext::addFieldSelectionExpression(TIntermTyped *baseExpression, TSourceLoc dotLocation, const TString &fieldString, TSourceLoc fieldLocation)
1897{
1898 TIntermTyped *indexedExpression = NULL;
1899
1900 if (baseExpression->isArray())
1901 {
1902 error(fieldLocation, "cannot apply dot operator to an array", ".");
1903 recover();
1904 }
1905
1906 if (baseExpression->isVector())
1907 {
1908 TVectorFields fields;
1909 if (!parseVectorFields(fieldString, baseExpression->getNominalSize(), fields, fieldLocation))
1910 {
1911 fields.num = 1;
1912 fields.offsets[0] = 0;
1913 recover();
1914 }
1915
1916 if (baseExpression->getType().getQualifier() == EvqConst)
1917 {
1918 // constant folding for vector fields
1919 indexedExpression = addConstVectorNode(fields, baseExpression, fieldLocation);
1920 if (indexedExpression == 0)
1921 {
1922 recover();
1923 indexedExpression = baseExpression;
1924 }
1925 else
1926 {
1927 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqConst, (int) (fieldString).size()));
1928 }
1929 }
1930 else
1931 {
1932 TString vectorString = fieldString;
1933 TIntermTyped* index = intermediate.addSwizzle(fields, fieldLocation);
1934 indexedExpression = intermediate.addIndex(EOpVectorSwizzle, baseExpression, index, dotLocation);
1935 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqTemporary, (int) vectorString.size()));
1936 }
1937 }
1938 else if (baseExpression->isMatrix())
1939 {
1940 TMatrixFields fields;
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00001941 if (!parseMatrixFields(fieldString, baseExpression->getCols(), baseExpression->getRows(), fields, fieldLocation))
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00001942 {
1943 fields.wholeRow = false;
1944 fields.wholeCol = false;
1945 fields.row = 0;
1946 fields.col = 0;
1947 recover();
1948 }
1949
1950 if (fields.wholeRow || fields.wholeCol)
1951 {
1952 error(dotLocation, " non-scalar fields not implemented yet", ".");
1953 recover();
1954 ConstantUnion *unionArray = new ConstantUnion[1];
1955 unionArray->setIConst(0);
1956 TIntermTyped* index = intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), fieldLocation);
1957 indexedExpression = intermediate.addIndex(EOpIndexDirect, baseExpression, index, dotLocation);
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00001958 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(),EvqTemporary, baseExpression->getCols(), baseExpression->getRows()));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00001959 }
1960 else
1961 {
1962 ConstantUnion *unionArray = new ConstantUnion[1];
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00001963 unionArray->setIConst(fields.col * baseExpression->getRows() + fields.row);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00001964 TIntermTyped* index = intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), fieldLocation);
1965 indexedExpression = intermediate.addIndex(EOpIndexDirect, baseExpression, index, dotLocation);
1966 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision()));
1967 }
1968 }
1969 else if (baseExpression->getBasicType() == EbtStruct)
1970 {
1971 bool fieldFound = false;
1972 const TTypeList* fields = baseExpression->getType().getStruct();
1973 if (fields == 0)
1974 {
1975 error(dotLocation, "structure has no fields", "Internal Error");
1976 recover();
1977 indexedExpression = baseExpression;
1978 }
1979 else
1980 {
1981 unsigned int i;
1982 for (i = 0; i < fields->size(); ++i)
1983 {
1984 if ((*fields)[i].type->getFieldName() == fieldString)
1985 {
1986 fieldFound = true;
1987 break;
1988 }
1989 }
1990 if (fieldFound)
1991 {
1992 if (baseExpression->getType().getQualifier() == EvqConst)
1993 {
1994 indexedExpression = addConstStruct(fieldString, baseExpression, dotLocation);
1995 if (indexedExpression == 0)
1996 {
1997 recover();
1998 indexedExpression = baseExpression;
1999 }
2000 else
2001 {
2002 indexedExpression->setType(*(*fields)[i].type);
2003 // change the qualifier of the return type, not of the structure field
2004 // as the structure definition is shared between various structures.
2005 indexedExpression->getTypePointer()->setQualifier(EvqConst);
2006 }
2007 }
2008 else
2009 {
2010 ConstantUnion *unionArray = new ConstantUnion[1];
2011 unionArray->setIConst(i);
2012 TIntermTyped* index = intermediate.addConstantUnion(unionArray, *(*fields)[i].type, fieldLocation);
2013 indexedExpression = intermediate.addIndex(EOpIndexDirectStruct, baseExpression, index, dotLocation);
2014 indexedExpression->setType(*(*fields)[i].type);
2015 }
2016 }
2017 else
2018 {
2019 error(dotLocation, " no such field in structure", fieldString.c_str());
2020 recover();
2021 indexedExpression = baseExpression;
2022 }
2023 }
2024 }
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002025 else if (baseExpression->getBasicType() == EbtInterfaceBlock)
2026 {
2027 bool fieldFound = false;
2028 const TTypeList* fields = baseExpression->getType().getStruct();
2029 if (fields == 0)
2030 {
2031 error(dotLocation, "interface block has no fields", "Internal Error");
2032 recover();
2033 indexedExpression = baseExpression;
2034 }
2035 else
2036 {
2037 unsigned int i;
2038 for (i = 0; i < fields->size(); ++i)
2039 {
2040 if ((*fields)[i].type->getFieldName() == fieldString)
2041 {
2042 fieldFound = true;
2043 break;
2044 }
2045 }
2046 if (fieldFound)
2047 {
2048 ConstantUnion *unionArray = new ConstantUnion[1];
2049 unionArray->setIConst(i);
2050 TIntermTyped* index = intermediate.addConstantUnion(unionArray, *(*fields)[i].type, fieldLocation);
2051 indexedExpression = intermediate.addIndex(EOpIndexDirectInterfaceBlock, baseExpression, index, dotLocation);
2052 indexedExpression->setType(*(*fields)[i].type);
2053 }
2054 else
2055 {
2056 error(dotLocation, " no such field in interface block", fieldString.c_str());
2057 recover();
2058 indexedExpression = baseExpression;
2059 }
2060 }
2061 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002062 else
2063 {
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002064 if (shaderVersion < 300)
2065 {
2066 error(dotLocation, " field selection requires structure, vector, or matrix on left hand side", fieldString.c_str());
2067 }
2068 else
2069 {
2070 error(dotLocation, " field selection requires structure, vector, matrix, or interface block on left hand side", fieldString.c_str());
2071 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002072 recover();
2073 indexedExpression = baseExpression;
2074 }
2075
2076 return indexedExpression;
2077}
2078
2079TTypeList *TParseContext::addStructDeclaratorList(const TPublicType& typeSpecifier, TTypeList *typeList)
2080{
2081 if (voidErrorCheck(typeSpecifier.line, (*typeList)[0].type->getFieldName(), typeSpecifier)) {
2082 recover();
2083 }
2084
2085 for (unsigned int i = 0; i < typeList->size(); ++i) {
2086 //
2087 // Careful not to replace already known aspects of type, like array-ness
2088 //
2089 TType* type = (*typeList)[i].type;
2090 type->setBasicType(typeSpecifier.type);
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00002091 type->setPrimarySize(typeSpecifier.primarySize);
2092 type->setSecondarySize(typeSpecifier.secondarySize);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002093 type->setPrecision(typeSpecifier.precision);
2094 type->setQualifier(typeSpecifier.qualifier);
2095
2096 // don't allow arrays of arrays
2097 if (type->isArray()) {
2098 if (arrayTypeErrorCheck(typeSpecifier.line, typeSpecifier))
2099 recover();
2100 }
2101 if (typeSpecifier.array)
2102 type->setArraySize(typeSpecifier.arraySize);
2103 if (typeSpecifier.userDef) {
2104 type->setStruct(typeSpecifier.userDef->getStruct());
2105 type->setTypeName(typeSpecifier.userDef->getTypeName());
2106 }
2107
2108 if (structNestingErrorCheck(typeSpecifier.line, *type)) {
2109 recover();
2110 }
2111 }
2112
2113 return typeList;
2114}
2115
2116TPublicType TParseContext::addStructure(TSourceLoc structLine, TSourceLoc nameLine, const TString &structName, TTypeList* typeList)
2117{
2118 TType* structure = new TType(typeList, structName);
2119
2120 if (!structName.empty())
2121 {
2122 if (reservedErrorCheck(nameLine, structName))
2123 {
2124 recover();
2125 }
2126 TVariable* userTypeDef = new TVariable(&structName, *structure, true);
2127 if (!symbolTable.declare(*userTypeDef)) {
2128 error(nameLine, "redefinition", structName.c_str(), "struct");
2129 recover();
2130 }
2131 }
2132
2133 // ensure we do not specify any storage qualifiers on the struct members
2134 for (unsigned int typeListIndex = 0; typeListIndex < typeList->size(); typeListIndex++)
2135 {
2136 const TTypeLine &typeLine = (*typeList)[typeListIndex];
2137 const TQualifier qualifier = typeLine.type->getQualifier();
2138 switch (qualifier)
2139 {
2140 case EvqGlobal:
2141 case EvqTemporary:
2142 break;
2143 default:
2144 error(typeLine.line, "invalid qualifier on struct member", getQualifierString(qualifier));
2145 recover();
2146 break;
2147 }
2148 }
2149
2150 TPublicType publicType;
2151 publicType.setBasic(EbtStruct, EvqTemporary, structLine);
2152 publicType.userDef = structure;
2153 exitStructDeclaration();
2154
2155 return publicType;
2156}
2157
2158//
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00002159// Parse an array of strings using yyparse.
2160//
2161// Returns 0 for success.
2162//
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +00002163int PaParseStrings(size_t count, const char* const string[], const int length[],
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00002164 TParseContext* context) {
2165 if ((count == 0) || (string == NULL))
2166 return 1;
2167
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00002168 if (glslang_initialize(context))
2169 return 1;
2170
alokp@chromium.org408c45e2012-04-05 15:54:43 +00002171 int error = glslang_scan(count, string, length, context);
2172 if (!error)
2173 error = glslang_parse(context);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00002174
alokp@chromium.org73bc2982012-06-19 18:48:05 +00002175 glslang_finalize(context);
alokp@chromium.org8b851c62012-06-15 16:25:11 +00002176
alokp@chromium.org6b495712012-06-29 00:06:58 +00002177 return (error == 0) && (context->numErrors() == 0) ? 0 : 1;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00002178}
2179
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002180
alokp@chromium.org34b99cd2010-07-27 18:37:55 +00002181