blob: b9907ba84dcc753d053f4b5adb4066720db3826d [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04002// Copyright (c) 2002-2014 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
Jamie Madill6b9cb252013-10-17 10:45:47 -04007#include "compiler/translator/ParseContext.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +00008
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
daniel@transgaming.comb401a922012-10-26 18:58:24 +000012#include "compiler/preprocessor/SourceLocation.h"
Olli Etuahoac5274d2015-02-20 10:19:08 +020013#include "compiler/translator/glslang.h"
14#include "compiler/translator/ValidateSwitch.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000015
alokp@chromium.org8b851c62012-06-15 16:25:11 +000016///////////////////////////////////////////////////////////////////////
17//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000018// Sub- vector and matrix fields
19//
20////////////////////////////////////////////////////////////////////////
21
22//
23// Look at a '.' field selector string and change it into offsets
24// for a vector.
25//
Jamie Madill075edd82013-07-08 13:30:19 -040026bool TParseContext::parseVectorFields(const TString& compString, int vecSize, TVectorFields& fields, const TSourceLoc& line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000027{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000028 fields.num = (int) compString.size();
29 if (fields.num > 4) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +000030 error(line, "illegal vector field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000031 return false;
32 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000034 enum {
35 exyzw,
36 ergba,
daniel@transgaming.comb3077d02013-01-11 04:12:09 +000037 estpq
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000038 } fieldSet[4];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000040 for (int i = 0; i < fields.num; ++i) {
41 switch (compString[i]) {
42 case 'x':
43 fields.offsets[i] = 0;
44 fieldSet[i] = exyzw;
45 break;
46 case 'r':
47 fields.offsets[i] = 0;
48 fieldSet[i] = ergba;
49 break;
50 case 's':
51 fields.offsets[i] = 0;
52 fieldSet[i] = estpq;
53 break;
54 case 'y':
55 fields.offsets[i] = 1;
56 fieldSet[i] = exyzw;
57 break;
58 case 'g':
59 fields.offsets[i] = 1;
60 fieldSet[i] = ergba;
61 break;
62 case 't':
63 fields.offsets[i] = 1;
64 fieldSet[i] = estpq;
65 break;
66 case 'z':
67 fields.offsets[i] = 2;
68 fieldSet[i] = exyzw;
69 break;
70 case 'b':
71 fields.offsets[i] = 2;
72 fieldSet[i] = ergba;
73 break;
74 case 'p':
75 fields.offsets[i] = 2;
76 fieldSet[i] = estpq;
77 break;
78
79 case 'w':
80 fields.offsets[i] = 3;
81 fieldSet[i] = exyzw;
82 break;
83 case 'a':
84 fields.offsets[i] = 3;
85 fieldSet[i] = ergba;
86 break;
87 case 'q':
88 fields.offsets[i] = 3;
89 fieldSet[i] = estpq;
90 break;
91 default:
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +000092 error(line, "illegal vector field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000093 return false;
94 }
95 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000096
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000097 for (int i = 0; i < fields.num; ++i) {
98 if (fields.offsets[i] >= vecSize) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +000099 error(line, "vector field selection out of range", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000100 return false;
101 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000102
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000103 if (i > 0) {
104 if (fieldSet[i] != fieldSet[i-1]) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000105 error(line, "illegal - vector component fields not from the same set", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000106 return false;
107 }
108 }
109 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000110
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000111 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000112}
113
114
115//
116// Look at a '.' field selector string and change it into offsets
117// for a matrix.
118//
Jamie Madill075edd82013-07-08 13:30:19 -0400119bool TParseContext::parseMatrixFields(const TString& compString, int matCols, int matRows, TMatrixFields& fields, const TSourceLoc& line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000120{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000121 fields.wholeRow = false;
122 fields.wholeCol = false;
123 fields.row = -1;
124 fields.col = -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000125
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000126 if (compString.size() != 2) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000127 error(line, "illegal length of matrix field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000128 return false;
129 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000130
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000131 if (compString[0] == '_') {
132 if (compString[1] < '0' || compString[1] > '3') {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000133 error(line, "illegal matrix field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000134 return false;
135 }
136 fields.wholeCol = true;
137 fields.col = compString[1] - '0';
138 } else if (compString[1] == '_') {
139 if (compString[0] < '0' || compString[0] > '3') {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000140 error(line, "illegal matrix field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000141 return false;
142 }
143 fields.wholeRow = true;
144 fields.row = compString[0] - '0';
145 } else {
146 if (compString[0] < '0' || compString[0] > '3' ||
147 compString[1] < '0' || compString[1] > '3') {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000148 error(line, "illegal matrix field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000149 return false;
150 }
151 fields.row = compString[0] - '0';
152 fields.col = compString[1] - '0';
153 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000154
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000155 if (fields.row >= matRows || fields.col >= matCols) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000156 error(line, "matrix field selection out of range", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000157 return false;
158 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000159
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000160 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000161}
162
163///////////////////////////////////////////////////////////////////////
164//
165// Errors
166//
167////////////////////////////////////////////////////////////////////////
168
169//
170// Track whether errors have occurred.
171//
172void TParseContext::recover()
173{
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000174}
175
176//
177// Used by flex/bison to output all syntax and parsing errors.
178//
Jamie Madill075edd82013-07-08 13:30:19 -0400179void TParseContext::error(const TSourceLoc& loc,
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000180 const char* reason, const char* token,
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000181 const char* extraInfo)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000182{
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000183 pp::SourceLocation srcLoc;
Jamie Madill075edd82013-07-08 13:30:19 -0400184 srcLoc.file = loc.first_file;
185 srcLoc.line = loc.first_line;
Shannon Woods7f2d7942013-11-19 15:07:58 -0500186 diagnostics.writeInfo(pp::Diagnostics::PP_ERROR,
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000187 srcLoc, reason, token, extraInfo);
alokp@chromium.orgff42c632010-05-10 15:14:30 +0000188
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000189}
190
Jamie Madill075edd82013-07-08 13:30:19 -0400191void TParseContext::warning(const TSourceLoc& loc,
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000192 const char* reason, const char* token,
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000193 const char* extraInfo) {
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000194 pp::SourceLocation srcLoc;
Jamie Madill075edd82013-07-08 13:30:19 -0400195 srcLoc.file = loc.first_file;
196 srcLoc.line = loc.first_line;
Shannon Woods7f2d7942013-11-19 15:07:58 -0500197 diagnostics.writeInfo(pp::Diagnostics::PP_WARNING,
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000198 srcLoc, reason, token, extraInfo);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000199}
200
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000201//
202// Same error message for all places assignments don't work.
203//
Jamie Madill075edd82013-07-08 13:30:19 -0400204void TParseContext::assignError(const TSourceLoc& line, const char* op, TString left, TString right)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000205{
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000206 std::stringstream extraInfoStream;
207 extraInfoStream << "cannot convert from '" << right << "' to '" << left << "'";
208 std::string extraInfo = extraInfoStream.str();
209 error(line, "", op, extraInfo.c_str());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000210}
211
212//
213// Same error message for all places unary operations don't work.
214//
Jamie Madill075edd82013-07-08 13:30:19 -0400215void TParseContext::unaryOpError(const TSourceLoc& line, const char* op, TString operand)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000216{
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000217 std::stringstream extraInfoStream;
218 extraInfoStream << "no operation '" << op << "' exists that takes an operand of type " << operand
219 << " (or there is no acceptable conversion)";
220 std::string extraInfo = extraInfoStream.str();
221 error(line, " wrong operand type", op, extraInfo.c_str());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000222}
223
224//
225// Same error message for all binary operations don't work.
226//
Jamie Madill075edd82013-07-08 13:30:19 -0400227void TParseContext::binaryOpError(const TSourceLoc& line, const char* op, TString left, TString right)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000228{
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000229 std::stringstream extraInfoStream;
230 extraInfoStream << "no operation '" << op << "' exists that takes a left-hand operand of type '" << left
231 << "' and a right operand of type '" << right << "' (or there is no acceptable conversion)";
232 std::string extraInfo = extraInfoStream.str();
233 error(line, " wrong operand types ", op, extraInfo.c_str());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000234}
235
Jamie Madill075edd82013-07-08 13:30:19 -0400236bool TParseContext::precisionErrorCheck(const TSourceLoc& line, TPrecision precision, TBasicType type){
zmo@google.comdc4b4f82011-06-17 00:42:53 +0000237 if (!checksPrecisionErrors)
238 return false;
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000239 switch( type ){
240 case EbtFloat:
241 if( precision == EbpUndefined ){
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000242 error( line, "No precision specified for (float)", "" );
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000243 return true;
244 }
245 break;
246 case EbtInt:
247 if( precision == EbpUndefined ){
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000248 error( line, "No precision specified (int)", "" );
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000249 return true;
250 }
251 break;
daniel@transgaming.com0eb64c32011-03-15 18:23:51 +0000252 default:
253 return false;
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000254 }
255 return false;
256}
257
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000258//
259// Both test and if necessary, spit out an error, to see if the node is really
260// an l-value that can be operated on this way.
261//
262// Returns true if the was an error.
263//
Jamie Madill075edd82013-07-08 13:30:19 -0400264bool TParseContext::lValueErrorCheck(const TSourceLoc& line, const char* op, TIntermTyped* node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000265{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000266 TIntermSymbol* symNode = node->getAsSymbolNode();
267 TIntermBinary* binaryNode = node->getAsBinaryNode();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000268
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000269 if (binaryNode) {
270 bool errorReturn;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000271
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000272 switch(binaryNode->getOp()) {
273 case EOpIndexDirect:
274 case EOpIndexIndirect:
275 case EOpIndexDirectStruct:
shannonwoods@chromium.org4430b0d2013-05-30 00:12:34 +0000276 case EOpIndexDirectInterfaceBlock:
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000277 return lValueErrorCheck(line, op, binaryNode->getLeft());
278 case EOpVectorSwizzle:
279 errorReturn = lValueErrorCheck(line, op, binaryNode->getLeft());
280 if (!errorReturn) {
281 int offset[4] = {0,0,0,0};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000282
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000283 TIntermTyped* rightNode = binaryNode->getRight();
284 TIntermAggregate *aggrNode = rightNode->getAsAggregate();
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700285
286 for (TIntermSequence::iterator p = aggrNode->getSequence()->begin();
287 p != aggrNode->getSequence()->end(); p++) {
shannon.woods%transgaming.com@gtempaccount.comc0d0c222013-04-13 03:29:36 +0000288 int value = (*p)->getAsTyped()->getAsConstantUnion()->getIConst(0);
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700289 offset[value]++;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000290 if (offset[value] > 1) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000291 error(line, " l-value of swizzle cannot have duplicate components", op);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000292
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000293 return true;
294 }
295 }
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700296 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000297
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000298 return errorReturn;
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700299 default:
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000300 break;
301 }
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000302 error(line, " l-value required", op);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000303
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000304 return true;
305 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000306
307
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000308 const char* symbol = 0;
309 if (symNode != 0)
310 symbol = symNode->getSymbol().c_str();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000311
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000312 const char* message = 0;
313 switch (node->getQualifier()) {
314 case EvqConst: message = "can't modify a const"; break;
315 case EvqConstReadOnly: message = "can't modify a const"; break;
316 case EvqAttribute: message = "can't modify an attribute"; break;
Jamie Madill19571812013-08-12 15:26:34 -0700317 case EvqFragmentIn: message = "can't modify an input"; break;
318 case EvqVertexIn: message = "can't modify an input"; break;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000319 case EvqUniform: message = "can't modify a uniform"; break;
320 case EvqVaryingIn: message = "can't modify a varying"; break;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000321 case EvqFragCoord: message = "can't modify gl_FragCoord"; break;
322 case EvqFrontFacing: message = "can't modify gl_FrontFacing"; break;
323 case EvqPointCoord: message = "can't modify gl_PointCoord"; break;
324 default:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000325
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000326 //
327 // Type that can't be written to?
328 //
Nicolas Capens344e7142013-06-24 15:39:21 -0400329 if (node->getBasicType() == EbtVoid) {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000330 message = "can't modify void";
Nicolas Capens344e7142013-06-24 15:39:21 -0400331 }
332 if (IsSampler(node->getBasicType())) {
333 message = "can't modify a sampler";
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000334 }
335 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000336
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000337 if (message == 0 && binaryNode == 0 && symNode == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000338 error(line, " l-value required", op);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000339
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000340 return true;
341 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000342
343
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000344 //
345 // Everything else is okay, no error.
346 //
347 if (message == 0)
348 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000349
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000350 //
351 // If we get here, we have an error and a message.
352 //
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000353 if (symNode) {
354 std::stringstream extraInfoStream;
355 extraInfoStream << "\"" << symbol << "\" (" << message << ")";
356 std::string extraInfo = extraInfoStream.str();
357 error(line, " l-value required", op, extraInfo.c_str());
358 }
359 else {
360 std::stringstream extraInfoStream;
361 extraInfoStream << "(" << message << ")";
362 std::string extraInfo = extraInfoStream.str();
363 error(line, " l-value required", op, extraInfo.c_str());
364 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000365
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000366 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000367}
368
369//
370// Both test, and if necessary spit out an error, to see if the node is really
371// a constant.
372//
373// Returns true if the was an error.
374//
375bool TParseContext::constErrorCheck(TIntermTyped* node)
376{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000377 if (node->getQualifier() == EvqConst)
378 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000379
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000380 error(node->getLine(), "constant expression required", "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000381
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000382 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000383}
384
385//
386// Both test, and if necessary spit out an error, to see if the node is really
387// an integer.
388//
389// Returns true if the was an error.
390//
391bool TParseContext::integerErrorCheck(TIntermTyped* node, const char* token)
392{
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000393 if (node->isScalarInt())
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000394 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000395
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000396 error(node->getLine(), "integer expression required", token);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000397
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000398 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000399}
400
401//
402// Both test, and if necessary spit out an error, to see if we are currently
403// globally scoped.
404//
405// Returns true if the was an error.
406//
Jamie Madill075edd82013-07-08 13:30:19 -0400407bool TParseContext::globalErrorCheck(const TSourceLoc& line, bool global, const char* token)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000408{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000409 if (global)
410 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000411
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000412 error(line, "only allowed at global scope", token);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000413
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000414 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000415}
416
417//
418// For now, keep it simple: if it starts "gl_", it's reserved, independent
419// of scope. Except, if the symbol table is at the built-in push-level,
420// which is when we are parsing built-ins.
alokp@chromium.org613ef312010-07-21 18:54:22 +0000421// Also checks for "webgl_" and "_webgl_" reserved identifiers if parsing a
422// webgl shader.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000423//
424// Returns true if there was an error.
425//
Jamie Madill075edd82013-07-08 13:30:19 -0400426bool TParseContext::reservedErrorCheck(const TSourceLoc& line, const TString& identifier)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000427{
alokp@chromium.org613ef312010-07-21 18:54:22 +0000428 static const char* reservedErrMsg = "reserved built-in name";
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000429 if (!symbolTable.atBuiltInLevel()) {
daniel@transgaming.com51db7fb2011-09-20 16:11:06 +0000430 if (identifier.compare(0, 3, "gl_") == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000431 error(line, reservedErrMsg, "gl_");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000432 return true;
433 }
Jamie Madill5508f392014-02-20 13:31:36 -0500434 if (IsWebGLBasedSpec(shaderSpec)) {
daniel@transgaming.com51db7fb2011-09-20 16:11:06 +0000435 if (identifier.compare(0, 6, "webgl_") == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000436 error(line, reservedErrMsg, "webgl_");
alokp@chromium.org613ef312010-07-21 18:54:22 +0000437 return true;
438 }
daniel@transgaming.com51db7fb2011-09-20 16:11:06 +0000439 if (identifier.compare(0, 7, "_webgl_") == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000440 error(line, reservedErrMsg, "_webgl_");
alokp@chromium.org613ef312010-07-21 18:54:22 +0000441 return true;
442 }
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000443 if (shaderSpec == SH_CSS_SHADERS_SPEC && identifier.compare(0, 4, "css_") == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000444 error(line, reservedErrMsg, "css_");
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000445 return true;
446 }
alokp@chromium.org613ef312010-07-21 18:54:22 +0000447 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000448 if (identifier.find("__") != TString::npos) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000449 error(line, "identifiers containing two consecutive underscores (__) are reserved as possible future keywords", identifier.c_str());
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000450 return true;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000451 }
452 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000453
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000454 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000455}
456
457//
458// Make sure there is enough data provided to the constructor to build
459// something of the type of the constructor. Also returns the type of
460// the constructor.
461//
462// Returns true if there was an error in construction.
463//
Jamie Madill075edd82013-07-08 13:30:19 -0400464bool TParseContext::constructorErrorCheck(const TSourceLoc& line, TIntermNode* node, TFunction& function, TOperator op, TType* type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000465{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000466 *type = function.getReturnType();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000467
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000468 bool constructingMatrix = false;
469 switch(op) {
470 case EOpConstructMat2:
471 case EOpConstructMat3:
472 case EOpConstructMat4:
473 constructingMatrix = true;
474 break;
475 default:
476 break;
477 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000478
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000479 //
480 // Note: It's okay to have too many components available, but not okay to have unused
481 // arguments. 'full' will go to true when enough args have been seen. If we loop
482 // again, there is an extra argument, so 'overfull' will become true.
483 //
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000484
Jamie Madill94bf7f22013-07-08 13:31:15 -0400485 size_t size = 0;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000486 bool constType = true;
487 bool full = false;
488 bool overFull = false;
489 bool matrixInMatrix = false;
490 bool arrayArg = false;
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000491 for (size_t i = 0; i < function.getParamCount(); ++i) {
alokp@chromium.orgb19403a2010-09-08 17:56:26 +0000492 const TParameter& param = function.getParam(i);
493 size += param.type->getObjectSize();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000494
alokp@chromium.orgb19403a2010-09-08 17:56:26 +0000495 if (constructingMatrix && param.type->isMatrix())
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000496 matrixInMatrix = true;
497 if (full)
498 overFull = true;
499 if (op != EOpConstructStruct && !type->isArray() && size >= type->getObjectSize())
500 full = true;
alokp@chromium.orgb19403a2010-09-08 17:56:26 +0000501 if (param.type->getQualifier() != EvqConst)
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000502 constType = false;
alokp@chromium.orgb19403a2010-09-08 17:56:26 +0000503 if (param.type->isArray())
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000504 arrayArg = true;
505 }
506
507 if (constType)
alokp@chromium.org58e54292010-08-24 21:40:03 +0000508 type->setQualifier(EvqConst);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000509
Olli Etuaho376f1b52015-04-13 13:23:41 +0300510 if (type->isArray())
511 {
512 if (type->isUnsizedArray())
513 {
514 type->setArraySize(function.getParamCount());
515 }
516 else if (static_cast<size_t>(type->getArraySize()) != function.getParamCount())
517 {
518 error(line, "array constructor needs one argument per array element", "constructor");
519 return true;
520 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000521 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000522
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000523 if (arrayArg && op != EOpConstructStruct) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000524 error(line, "constructing from a non-dereferenced array", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000525 return true;
526 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000527
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000528 if (matrixInMatrix && !type->isArray()) {
daniel@transgaming.combef0b6d2010-04-29 03:32:39 +0000529 if (function.getParamCount() != 1) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000530 error(line, "constructing matrix from matrix can only take one argument", "constructor");
daniel@transgaming.combef0b6d2010-04-29 03:32:39 +0000531 return true;
532 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000533 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000534
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000535 if (overFull) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000536 error(line, "too many arguments", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000537 return true;
538 }
539
Brendan Longeaa84062013-12-08 18:26:50 +0100540 if (op == EOpConstructStruct && !type->isArray() && type->getStruct()->fields().size() != function.getParamCount()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000541 error(line, "Number of constructor parameters does not match the number of structure fields", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000542 return true;
543 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000544
daniel@transgaming.com67d72522011-11-29 17:23:51 +0000545 if (!type->isMatrix() || !matrixInMatrix) {
daniel@transgaming.combef0b6d2010-04-29 03:32:39 +0000546 if ((op != EOpConstructStruct && size != 1 && size < type->getObjectSize()) ||
547 (op == EOpConstructStruct && size < type->getObjectSize())) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000548 error(line, "not enough data provided for construction", "constructor");
daniel@transgaming.combef0b6d2010-04-29 03:32:39 +0000549 return true;
550 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000551 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000552
daniel@transgaming.com0b53fc02011-03-09 15:12:12 +0000553 TIntermTyped *typed = node ? node->getAsTyped() : 0;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000554 if (typed == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000555 error(line, "constructor argument does not have a type", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000556 return true;
557 }
558 if (op != EOpConstructStruct && IsSampler(typed->getBasicType())) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000559 error(line, "cannot convert a sampler", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000560 return true;
561 }
562 if (typed->getBasicType() == EbtVoid) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000563 error(line, "cannot convert a void", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000564 return true;
565 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000566
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000567 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000568}
569
570// This function checks to see if a void variable has been declared and raise an error message for such a case
571//
572// returns true in case of an error
573//
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +0300574bool TParseContext::voidErrorCheck(const TSourceLoc &line, const TString &identifier, const TBasicType &type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000575{
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +0300576 if (type == EbtVoid)
577 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000578 error(line, "illegal use of type 'void'", identifier.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000579 return true;
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +0300580 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000581
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000582 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000583}
584
585// This function checks to see if the node (for the expression) contains a scalar boolean expression or not
586//
587// returns true in case of an error
588//
Jamie Madill075edd82013-07-08 13:30:19 -0400589bool TParseContext::boolErrorCheck(const TSourceLoc& line, const TIntermTyped* type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000590{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000591 if (type->getBasicType() != EbtBool || type->isArray() || type->isMatrix() || type->isVector()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000592 error(line, "boolean expression expected", "");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000593 return true;
594 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000595
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000596 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000597}
598
599// This function checks to see if the node (for the expression) contains a scalar boolean expression or not
600//
601// returns true in case of an error
602//
Jamie Madill075edd82013-07-08 13:30:19 -0400603bool TParseContext::boolErrorCheck(const TSourceLoc& line, const TPublicType& pType)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000604{
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000605 if (pType.type != EbtBool || pType.isAggregate()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000606 error(line, "boolean expression expected", "");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000607 return true;
608 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000609
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000610 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000611}
612
Jamie Madill075edd82013-07-08 13:30:19 -0400613bool TParseContext::samplerErrorCheck(const TSourceLoc& line, const TPublicType& pType, const char* reason)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000614{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000615 if (pType.type == EbtStruct) {
616 if (containsSampler(*pType.userDef)) {
alokp@chromium.org58e54292010-08-24 21:40:03 +0000617 error(line, reason, getBasicString(pType.type), "(structure contains a sampler)");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000618
619 return true;
620 }
621
622 return false;
623 } else if (IsSampler(pType.type)) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000624 error(line, reason, getBasicString(pType.type));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000625
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000626 return true;
627 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000628
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000629 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000630}
631
Jamie Madill075edd82013-07-08 13:30:19 -0400632bool TParseContext::locationDeclaratorListCheck(const TSourceLoc& line, const TPublicType &pType)
Jamie Madill0bd18df2013-06-20 11:55:52 -0400633{
634 if (pType.layoutQualifier.location != -1)
635 {
636 error(line, "location must only be specified for a single input or output variable", "location");
637 return true;
638 }
639
640 return false;
641}
642
Jamie Madill075edd82013-07-08 13:30:19 -0400643bool TParseContext::parameterSamplerErrorCheck(const TSourceLoc& line, TQualifier qualifier, const TType& type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000644{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000645 if ((qualifier == EvqOut || qualifier == EvqInOut) &&
646 type.getBasicType() != EbtStruct && IsSampler(type.getBasicType())) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000647 error(line, "samplers cannot be output parameters", type.getBasicString());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000648 return true;
649 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000650
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000651 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000652}
653
654bool TParseContext::containsSampler(TType& type)
655{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000656 if (IsSampler(type.getBasicType()))
657 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000658
Jamie Madill98493dd2013-07-08 14:39:03 -0400659 if (type.getBasicType() == EbtStruct || type.isInterfaceBlock()) {
660 const TFieldList& fields = type.getStruct()->fields();
661 for (unsigned int i = 0; i < fields.size(); ++i) {
662 if (containsSampler(*fields[i]->type()))
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000663 return true;
664 }
665 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000666
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000667 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000668}
669
670//
671// Do size checking for an array type's size.
672//
673// Returns true if there was an error.
674//
Jamie Madill075edd82013-07-08 13:30:19 -0400675bool TParseContext::arraySizeErrorCheck(const TSourceLoc& line, TIntermTyped* expr, int& size)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000676{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000677 TIntermConstantUnion* constant = expr->getAsConstantUnion();
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000678
Olli Etuahoe7847b02015-03-16 11:56:12 +0200679 if (constant == nullptr || !constant->isScalarInt())
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000680 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000681 error(line, "array size must be a constant integer expression", "");
Olli Etuahoe7847b02015-03-16 11:56:12 +0200682 size = 1;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000683 return true;
684 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000685
Nicolas Capens906744a2014-06-06 15:18:07 -0400686 unsigned int unsignedSize = 0;
687
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000688 if (constant->getBasicType() == EbtUInt)
689 {
Nicolas Capens906744a2014-06-06 15:18:07 -0400690 unsignedSize = constant->getUConst(0);
691 size = static_cast<int>(unsignedSize);
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000692 }
693 else
694 {
695 size = constant->getIConst(0);
696
Nicolas Capens906744a2014-06-06 15:18:07 -0400697 if (size < 0)
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000698 {
Nicolas Capens906744a2014-06-06 15:18:07 -0400699 error(line, "array size must be non-negative", "");
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000700 size = 1;
701 return true;
702 }
Nicolas Capens906744a2014-06-06 15:18:07 -0400703
704 unsignedSize = static_cast<unsigned int>(size);
705 }
706
707 if (size == 0)
708 {
709 error(line, "array size must be greater than zero", "");
710 size = 1;
711 return true;
712 }
713
714 // The size of arrays is restricted here to prevent issues further down the
715 // compiler/translator/driver stack. Shader Model 5 generation hardware is limited to
716 // 4096 registers so this should be reasonable even for aggressively optimizable code.
717 const unsigned int sizeLimit = 65536;
718
719 if (unsignedSize > sizeLimit)
720 {
721 error(line, "array size too large", "");
722 size = 1;
723 return true;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000724 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000725
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000726 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000727}
728
729//
730// See if this qualifier can be an array.
731//
732// Returns true if there is an error.
733//
Olli Etuaho3739d232015-04-08 12:23:44 +0300734bool TParseContext::arrayQualifierErrorCheck(const TSourceLoc &line, const TPublicType &type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000735{
Olli Etuaho3739d232015-04-08 12:23:44 +0300736 if ((type.qualifier == EvqAttribute) || (type.qualifier == EvqVertexIn) ||
737 (type.qualifier == EvqConst && shaderVersion < 300))
738 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000739 error(line, "cannot declare arrays of this qualifier", 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// See if this type can be an array.
748//
749// Returns true if there is an error.
750//
Jamie Madill075edd82013-07-08 13:30:19 -0400751bool TParseContext::arrayTypeErrorCheck(const TSourceLoc& line, TPublicType type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000752{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000753 //
754 // Can the type be an array?
755 //
756 if (type.array) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000757 error(line, "cannot declare arrays of arrays", TType(type).getCompleteString().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000758 return true;
759 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000760
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000761 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000762}
763
764//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000765// Enforce non-initializer type/qualifier rules.
766//
767// Returns true if there was an error.
768//
Olli Etuaho376f1b52015-04-13 13:23:41 +0300769bool TParseContext::nonInitErrorCheck(const TSourceLoc &line, const TString &identifier, TPublicType *type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000770{
Olli Etuaho3739d232015-04-08 12:23:44 +0300771 ASSERT(type != nullptr);
772 if (type->qualifier == EvqConst)
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000773 {
774 // Make the qualifier make sense.
Olli Etuaho3739d232015-04-08 12:23:44 +0300775 type->qualifier = EvqTemporary;
776
777 // Generate informative error messages for ESSL1.
778 // In ESSL3 arrays and structures containing arrays can be constant.
779 if (shaderVersion < 300 && type->isStructureContainingArrays())
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000780 {
781 error(line, "structures containing arrays may not be declared constant since they cannot be initialized", identifier.c_str());
782 }
783 else
784 {
785 error(line, "variables with qualifier 'const' must be initialized", identifier.c_str());
786 }
787
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000788 return true;
789 }
Olli Etuaho376f1b52015-04-13 13:23:41 +0300790 if (type->isUnsizedArray())
791 {
792 error(line, "implicitly sized arrays need to be initialized", identifier.c_str());
793 return true;
794 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000795 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000796}
797
Olli Etuaho2935c582015-04-08 14:32:06 +0300798// Do some simple checks that are shared between all variable declarations,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000799// and update the symbol table.
800//
Olli Etuaho2935c582015-04-08 14:32:06 +0300801// Returns true if declaring the variable succeeded.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000802//
Olli Etuaho2935c582015-04-08 14:32:06 +0300803bool TParseContext::declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type,
804 TVariable **variable)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000805{
Olli Etuaho2935c582015-04-08 14:32:06 +0300806 ASSERT((*variable) == nullptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000807
Olli Etuaho2935c582015-04-08 14:32:06 +0300808 bool needsReservedErrorCheck = true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000809
Olli Etuaho2935c582015-04-08 14:32:06 +0300810 // gl_LastFragData may be redeclared with a new precision qualifier
811 if (type.isArray() && identifier.compare(0, 15, "gl_LastFragData") == 0)
812 {
813 const TVariable *maxDrawBuffers =
814 static_cast<const TVariable *>(symbolTable.findBuiltIn("gl_MaxDrawBuffers", shaderVersion));
815 if (type.getArraySize() == maxDrawBuffers->getConstPointer()->getIConst())
816 {
817 if (TSymbol *builtInSymbol = symbolTable.findBuiltIn(identifier, shaderVersion))
818 {
819 needsReservedErrorCheck = extensionErrorCheck(line, builtInSymbol->getExtension());
820 }
821 }
822 else
823 {
824 error(line, "redeclaration of gl_LastFragData with size != gl_MaxDrawBuffers", identifier.c_str());
825 return false;
826 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000827 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000828
Olli Etuaho2935c582015-04-08 14:32:06 +0300829 if (needsReservedErrorCheck && reservedErrorCheck(line, identifier))
830 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000831
Olli Etuaho2935c582015-04-08 14:32:06 +0300832 (*variable) = new TVariable(&identifier, type);
833 if (!symbolTable.declare(*variable))
834 {
835 error(line, "redefinition", identifier.c_str());
836 delete (*variable);
837 (*variable) = nullptr;
838 return false;
839 }
840
841 if (voidErrorCheck(line, identifier, type.getBasicType()))
842 return false;
843
844 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000845}
846
Jamie Madill075edd82013-07-08 13:30:19 -0400847bool TParseContext::paramErrorCheck(const TSourceLoc& line, TQualifier qualifier, TQualifier paramQualifier, TType* type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000848{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000849 if (qualifier != EvqConst && qualifier != EvqTemporary) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000850 error(line, "qualifier not allowed on function parameter", getQualifierString(qualifier));
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000851 return true;
852 }
853 if (qualifier == EvqConst && paramQualifier != EvqIn) {
854 error(line, "qualifier not allowed with ", getQualifierString(qualifier), getQualifierString(paramQualifier));
855 return true;
856 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000857
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000858 if (qualifier == EvqConst)
alokp@chromium.org58e54292010-08-24 21:40:03 +0000859 type->setQualifier(EvqConstReadOnly);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000860 else
alokp@chromium.org58e54292010-08-24 21:40:03 +0000861 type->setQualifier(paramQualifier);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000862
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000863 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000864}
865
Jamie Madill075edd82013-07-08 13:30:19 -0400866bool TParseContext::extensionErrorCheck(const TSourceLoc& line, const TString& extension)
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000867{
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000868 const TExtensionBehavior& extBehavior = extensionBehavior();
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000869 TExtensionBehavior::const_iterator iter = extBehavior.find(extension.c_str());
870 if (iter == extBehavior.end()) {
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000871 error(line, "extension", extension.c_str(), "is not supported");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000872 return true;
873 }
zmo@google.comf5450912011-09-09 01:37:19 +0000874 // In GLSL ES, an extension's default behavior is "disable".
875 if (iter->second == EBhDisable || iter->second == EBhUndefined) {
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000876 error(line, "extension", extension.c_str(), "is disabled");
877 return true;
878 }
879 if (iter->second == EBhWarn) {
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000880 warning(line, "extension", extension.c_str(), "is being used");
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000881 return false;
882 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000883
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000884 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000885}
886
Olli Etuahofa33d582015-04-09 14:33:12 +0300887// These checks are common for all declarations starting a declarator list, and declarators that follow an empty
888// declaration.
889//
890bool TParseContext::singleDeclarationErrorCheck(TPublicType &publicType, const TSourceLoc &identifierLocation)
Jamie Madilla5efff92013-06-06 11:56:47 -0400891{
Olli Etuahofa33d582015-04-09 14:33:12 +0300892 switch (publicType.qualifier)
893 {
894 case EvqVaryingIn:
895 case EvqVaryingOut:
896 case EvqAttribute:
897 case EvqVertexIn:
898 case EvqFragmentOut:
899 if (publicType.type == EbtStruct)
900 {
901 error(identifierLocation, "cannot be used with a structure",
902 getQualifierString(publicType.qualifier));
903 return true;
904 }
905
906 default: break;
907 }
908
909 if (publicType.qualifier != EvqUniform && samplerErrorCheck(identifierLocation, publicType,
910 "samplers must be uniform"))
911 {
Jamie Madilla5efff92013-06-06 11:56:47 -0400912 return true;
Olli Etuahofa33d582015-04-09 14:33:12 +0300913 }
Jamie Madilla5efff92013-06-06 11:56:47 -0400914
915 // check for layout qualifier issues
916 const TLayoutQualifier layoutQualifier = publicType.layoutQualifier;
917
918 if (layoutQualifier.matrixPacking != EmpUnspecified)
919 {
Olli Etuahofa33d582015-04-09 14:33:12 +0300920 error(identifierLocation, "layout qualifier", getMatrixPackingString(layoutQualifier.matrixPacking),
921 "only valid for interface blocks");
Jamie Madill51a53c72013-06-19 09:24:43 -0400922 return true;
Jamie Madilla5efff92013-06-06 11:56:47 -0400923 }
924
925 if (layoutQualifier.blockStorage != EbsUnspecified)
926 {
Olli Etuahofa33d582015-04-09 14:33:12 +0300927 error(identifierLocation, "layout qualifier", getBlockStorageString(layoutQualifier.blockStorage),
928 "only valid for interface blocks");
Jamie Madill51a53c72013-06-19 09:24:43 -0400929 return true;
Jamie Madilla5efff92013-06-06 11:56:47 -0400930 }
931
Olli Etuahofa33d582015-04-09 14:33:12 +0300932 if (publicType.qualifier != EvqVertexIn && publicType.qualifier != EvqFragmentOut &&
933 layoutLocationErrorCheck(identifierLocation, publicType.layoutQualifier))
Jamie Madilla5efff92013-06-06 11:56:47 -0400934 {
Jamie Madill51a53c72013-06-19 09:24:43 -0400935 return true;
Jamie Madilla5efff92013-06-06 11:56:47 -0400936 }
937
938 return false;
939}
940
Jamie Madill075edd82013-07-08 13:30:19 -0400941bool TParseContext::layoutLocationErrorCheck(const TSourceLoc& location, const TLayoutQualifier &layoutQualifier)
Jamie Madilla5efff92013-06-06 11:56:47 -0400942{
943 if (layoutQualifier.location != -1)
944 {
945 error(location, "invalid layout qualifier:", "location", "only valid on program inputs and outputs");
946 return true;
947 }
948
949 return false;
950}
951
Olli Etuahob6e07a62015-02-16 12:22:10 +0200952bool TParseContext::functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *aggregate)
953{
954 for (size_t i = 0; i < fnCandidate->getParamCount(); ++i)
955 {
956 TQualifier qual = fnCandidate->getParam(i).type->getQualifier();
957 if (qual == EvqOut || qual == EvqInOut)
958 {
959 TIntermTyped *node = (*(aggregate->getSequence()))[i]->getAsTyped();
960 if (lValueErrorCheck(node->getLine(), "assign", node))
961 {
962 error(node->getLine(),
963 "Constant value cannot be passed for 'out' or 'inout' parameters.", "Error");
964 recover();
965 return true;
966 }
967 }
968 }
969 return false;
970}
971
zmo@google.com09c323a2011-08-12 18:22:25 +0000972bool TParseContext::supportsExtension(const char* extension)
973{
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000974 const TExtensionBehavior& extbehavior = extensionBehavior();
975 TExtensionBehavior::const_iterator iter = extbehavior.find(extension);
976 return (iter != extbehavior.end());
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000977}
978
Jamie Madill5d287f52013-07-12 15:38:19 -0400979bool TParseContext::isExtensionEnabled(const char* extension) const
980{
981 const TExtensionBehavior& extbehavior = extensionBehavior();
Shannon Woodsa49a9bf2013-08-02 17:23:14 -0400982 TExtensionBehavior::const_iterator iter = extbehavior.find(extension);
Jamie Madill5d287f52013-07-12 15:38:19 -0400983
984 if (iter == extbehavior.end())
985 {
986 return false;
987 }
988
989 return (iter->second == EBhEnable || iter->second == EBhRequire);
990}
991
Jamie Madill075edd82013-07-08 13:30:19 -0400992void TParseContext::handleExtensionDirective(const TSourceLoc& loc, const char* extName, const char* behavior)
993{
994 pp::SourceLocation srcLoc;
995 srcLoc.file = loc.first_file;
996 srcLoc.line = loc.first_line;
997 directiveHandler.handleExtension(srcLoc, extName, behavior);
998}
999
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001000void TParseContext::handlePragmaDirective(const TSourceLoc& loc, const char* name, const char* value, bool stdgl)
Jamie Madill075edd82013-07-08 13:30:19 -04001001{
1002 pp::SourceLocation srcLoc;
1003 srcLoc.file = loc.first_file;
1004 srcLoc.line = loc.first_line;
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001005 directiveHandler.handlePragma(srcLoc, name, value, stdgl);
Jamie Madill075edd82013-07-08 13:30:19 -04001006}
1007
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001008/////////////////////////////////////////////////////////////////////////////////
1009//
1010// Non-Errors.
1011//
1012/////////////////////////////////////////////////////////////////////////////////
1013
Jamie Madill5c097022014-08-20 16:38:32 -04001014const TVariable *TParseContext::getNamedVariable(const TSourceLoc &location,
1015 const TString *name,
1016 const TSymbol *symbol)
1017{
1018 const TVariable *variable = NULL;
1019
1020 if (!symbol)
1021 {
1022 error(location, "undeclared identifier", name->c_str());
1023 recover();
1024 }
1025 else if (!symbol->isVariable())
1026 {
1027 error(location, "variable expected", name->c_str());
1028 recover();
1029 }
1030 else
1031 {
1032 variable = static_cast<const TVariable*>(symbol);
1033
1034 if (symbolTable.findBuiltIn(variable->getName(), shaderVersion) &&
1035 !variable->getExtension().empty() &&
1036 extensionErrorCheck(location, variable->getExtension()))
1037 {
1038 recover();
1039 }
1040 }
1041
1042 if (!variable)
1043 {
1044 TType type(EbtFloat, EbpUndefined);
1045 TVariable *fakeVariable = new TVariable(name, type);
1046 symbolTable.declare(fakeVariable);
1047 variable = fakeVariable;
1048 }
1049
1050 return variable;
1051}
1052
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001053//
1054// Look up a function name in the symbol table, and make sure it is a function.
1055//
1056// Return the function symbol if found, otherwise 0.
1057//
Austin Kinross3ae64652015-01-26 15:51:39 -08001058const TFunction* TParseContext::findFunction(const TSourceLoc& line, TFunction* call, int inputShaderVersion, bool *builtIn)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001059{
alokp@chromium.org0a576182010-08-09 17:16:27 +00001060 // First find by unmangled name to check whether the function name has been
1061 // hidden by a variable name or struct typename.
Nicolas Capensd4a9b8d2013-07-18 11:01:22 -04001062 // If a function is found, check for one with a matching argument list.
Austin Kinross3ae64652015-01-26 15:51:39 -08001063 const TSymbol* symbol = symbolTable.find(call->getName(), inputShaderVersion, builtIn);
Nicolas Capensd4a9b8d2013-07-18 11:01:22 -04001064 if (symbol == 0 || symbol->isFunction()) {
Austin Kinross3ae64652015-01-26 15:51:39 -08001065 symbol = symbolTable.find(call->getMangledName(), inputShaderVersion, builtIn);
alokp@chromium.org0a576182010-08-09 17:16:27 +00001066 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001067
alokp@chromium.org0a576182010-08-09 17:16:27 +00001068 if (symbol == 0) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001069 error(line, "no matching overloaded function found", call->getName().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001070 return 0;
1071 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001072
alokp@chromium.org0a576182010-08-09 17:16:27 +00001073 if (!symbol->isFunction()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001074 error(line, "function name expected", call->getName().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001075 return 0;
1076 }
alokp@chromium.org0a576182010-08-09 17:16:27 +00001077
1078 return static_cast<const TFunction*>(symbol);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001079}
1080
1081//
1082// Initializers show up in several places in the grammar. Have one set of
1083// code to handle them here.
1084//
Jamie Madill3b5c2da2014-08-19 15:23:32 -04001085// Returns true on error, false if no error
1086//
Olli Etuaho2935c582015-04-08 14:32:06 +03001087bool TParseContext::executeInitializer(const TSourceLoc &line, const TString &identifier, TPublicType &pType,
Olli Etuahoe7847b02015-03-16 11:56:12 +02001088 TIntermTyped *initializer, TIntermNode **intermNode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001089{
Olli Etuahoe7847b02015-03-16 11:56:12 +02001090 ASSERT(intermNode != nullptr);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001091 TType type = TType(pType);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001092
Olli Etuaho2935c582015-04-08 14:32:06 +03001093 TVariable *variable = nullptr;
Olli Etuaho376f1b52015-04-13 13:23:41 +03001094 if (type.isUnsizedArray())
1095 {
1096 type.setArraySize(initializer->getArraySize());
1097 }
Olli Etuaho2935c582015-04-08 14:32:06 +03001098 if (!declareVariable(line, identifier, type, &variable))
1099 {
1100 return true;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001101 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001102
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001103 //
1104 // identifier must be of type constant, a global, or a temporary
1105 //
1106 TQualifier qualifier = variable->getType().getQualifier();
1107 if ((qualifier != EvqTemporary) && (qualifier != EvqGlobal) && (qualifier != EvqConst)) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001108 error(line, " cannot initialize this type of qualifier ", variable->getType().getQualifierString());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001109 return true;
1110 }
1111 //
1112 // test for and propagate constant
1113 //
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001114
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001115 if (qualifier == EvqConst) {
1116 if (qualifier != initializer->getType().getQualifier()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001117 std::stringstream extraInfoStream;
1118 extraInfoStream << "'" << variable->getType().getCompleteString() << "'";
1119 std::string extraInfo = extraInfoStream.str();
1120 error(line, " assigning non-constant to", "=", extraInfo.c_str());
alokp@chromium.org58e54292010-08-24 21:40:03 +00001121 variable->getType().setQualifier(EvqTemporary);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001122 return true;
1123 }
1124 if (type != initializer->getType()) {
1125 error(line, " non-matching types for const initializer ",
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001126 variable->getType().getQualifierString());
alokp@chromium.org58e54292010-08-24 21:40:03 +00001127 variable->getType().setQualifier(EvqTemporary);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001128 return true;
1129 }
1130 if (initializer->getAsConstantUnion()) {
Jamie Madill94bf7f22013-07-08 13:31:15 -04001131 variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001132 } else if (initializer->getAsSymbolNode()) {
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +00001133 const TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol(), 0);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001134 const TVariable* tVar = static_cast<const TVariable*>(symbol);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001135
Jamie Madill6ba6ead2015-05-04 14:21:21 -04001136 TConstantUnion* constArray = tVar->getConstPointer();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001137 variable->shareConstPointer(constArray);
1138 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001139 std::stringstream extraInfoStream;
1140 extraInfoStream << "'" << variable->getType().getCompleteString() << "'";
1141 std::string extraInfo = extraInfoStream.str();
1142 error(line, " cannot assign to", "=", extraInfo.c_str());
alokp@chromium.org58e54292010-08-24 21:40:03 +00001143 variable->getType().setQualifier(EvqTemporary);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001144 return true;
1145 }
1146 }
Olli Etuahoe7847b02015-03-16 11:56:12 +02001147
1148 if (qualifier != EvqConst)
1149 {
1150 TIntermSymbol *intermSymbol = intermediate.addSymbol(variable->getUniqueId(), variable->getName(),
1151 variable->getType(), line);
1152 *intermNode = createAssign(EOpInitialize, intermSymbol, initializer, line);
1153 if (*intermNode == nullptr)
1154 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001155 assignError(line, "=", intermSymbol->getCompleteString(), initializer->getCompleteString());
1156 return true;
1157 }
Olli Etuahoe7847b02015-03-16 11:56:12 +02001158 }
1159 else
1160 {
1161 *intermNode = nullptr;
1162 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001163
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001164 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001165}
1166
1167bool TParseContext::areAllChildConst(TIntermAggregate* aggrNode)
1168{
alokp@chromium.orgd300f5b2010-10-14 16:10:20 +00001169 ASSERT(aggrNode != NULL);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001170 if (!aggrNode->isConstructor())
1171 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001172
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001173 bool allConstant = true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001174
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001175 // check if all the child nodes are constants so that they can be inserted into
1176 // the parent node
Zhenyao Moe40d1e92014-07-16 17:40:36 -07001177 TIntermSequence *sequence = aggrNode->getSequence() ;
1178 for (TIntermSequence::iterator p = sequence->begin(); p != sequence->end(); ++p) {
alokp@chromium.orgd300f5b2010-10-14 16:10:20 +00001179 if (!(*p)->getAsTyped()->getAsConstantUnion())
1180 return false;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001181 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001182
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001183 return allConstant;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001184}
1185
Jamie Madilla5efff92013-06-06 11:56:47 -04001186TPublicType TParseContext::addFullySpecifiedType(TQualifier qualifier, TLayoutQualifier layoutQualifier, const TPublicType& typeSpecifier)
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001187{
1188 TPublicType returnType = typeSpecifier;
1189 returnType.qualifier = qualifier;
Jamie Madilla5efff92013-06-06 11:56:47 -04001190 returnType.layoutQualifier = layoutQualifier;
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001191
1192 if (typeSpecifier.array)
1193 {
1194 error(typeSpecifier.line, "not supported", "first-class array");
1195 recover();
Olli Etuaho693c9aa2015-04-07 17:50:36 +03001196 returnType.clearArrayness();
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001197 }
1198
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001199 if (shaderVersion < 300)
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001200 {
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001201 if (qualifier == EvqAttribute && (typeSpecifier.type == EbtBool || typeSpecifier.type == EbtInt))
1202 {
1203 error(typeSpecifier.line, "cannot be bool or int", getQualifierString(qualifier));
1204 recover();
1205 }
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001206
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001207 if ((qualifier == EvqVaryingIn || qualifier == EvqVaryingOut) &&
1208 (typeSpecifier.type == EbtBool || typeSpecifier.type == EbtInt))
1209 {
1210 error(typeSpecifier.line, "cannot be bool or int", getQualifierString(qualifier));
1211 recover();
1212 }
1213 }
1214 else
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001215 {
Jamie Madillb120eac2013-06-12 14:08:13 -04001216 switch (qualifier)
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001217 {
Jamie Madill19571812013-08-12 15:26:34 -07001218 case EvqSmoothIn:
1219 case EvqSmoothOut:
1220 case EvqVertexOut:
1221 case EvqFragmentIn:
1222 case EvqCentroidOut:
1223 case EvqCentroidIn:
1224 if (typeSpecifier.type == EbtBool)
1225 {
1226 error(typeSpecifier.line, "cannot be bool", getQualifierString(qualifier));
1227 recover();
1228 }
1229 if (typeSpecifier.type == EbtInt || typeSpecifier.type == EbtUInt)
1230 {
1231 error(typeSpecifier.line, "must use 'flat' interpolation here", getQualifierString(qualifier));
1232 recover();
1233 }
1234 break;
1235
1236 case EvqVertexIn:
1237 case EvqFragmentOut:
1238 case EvqFlatIn:
1239 case EvqFlatOut:
Jamie Madillb120eac2013-06-12 14:08:13 -04001240 if (typeSpecifier.type == EbtBool)
1241 {
1242 error(typeSpecifier.line, "cannot be bool", getQualifierString(qualifier));
1243 recover();
1244 }
1245 break;
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001246
Jamie Madillb120eac2013-06-12 14:08:13 -04001247 default: break;
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001248 }
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001249 }
1250
1251 return returnType;
1252}
1253
Olli Etuahofa33d582015-04-09 14:33:12 +03001254TIntermAggregate *TParseContext::parseSingleDeclaration(TPublicType &publicType,
1255 const TSourceLoc &identifierOrTypeLocation,
1256 const TString &identifier)
Jamie Madill60ed9812013-06-06 11:56:46 -04001257{
Olli Etuahofa33d582015-04-09 14:33:12 +03001258 TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, TType(publicType), identifierOrTypeLocation);
Jamie Madill60ed9812013-06-06 11:56:46 -04001259
Olli Etuahobab4c082015-04-24 16:38:49 +03001260 bool emptyDeclaration = (identifier == "");
Olli Etuahofa33d582015-04-09 14:33:12 +03001261
Olli Etuahobab4c082015-04-24 16:38:49 +03001262 mDeferredSingleDeclarationErrorCheck = emptyDeclaration;
1263
1264 if (emptyDeclaration)
1265 {
1266 if (publicType.isUnsizedArray())
1267 {
1268 // ESSL3 spec section 4.1.9: Array declaration which leaves the size unspecified is an error.
1269 // It is assumed that this applies to empty declarations as well.
1270 error(identifierOrTypeLocation, "empty array declaration needs to specify a size", identifier.c_str());
1271 }
1272 }
1273 else
Jamie Madill60ed9812013-06-06 11:56:46 -04001274 {
Olli Etuahofa33d582015-04-09 14:33:12 +03001275 if (singleDeclarationErrorCheck(publicType, identifierOrTypeLocation))
Jamie Madill60ed9812013-06-06 11:56:46 -04001276 recover();
1277
Olli Etuaho376f1b52015-04-13 13:23:41 +03001278 if (nonInitErrorCheck(identifierOrTypeLocation, identifier, &publicType))
Jamie Madill60ed9812013-06-06 11:56:46 -04001279 recover();
1280
Olli Etuaho2935c582015-04-08 14:32:06 +03001281 TVariable *variable = nullptr;
Olli Etuahofa33d582015-04-09 14:33:12 +03001282 if (!declareVariable(identifierOrTypeLocation, identifier, TType(publicType), &variable))
Jamie Madill60ed9812013-06-06 11:56:46 -04001283 recover();
1284
1285 if (variable && symbol)
Jamie Madill60ed9812013-06-06 11:56:46 -04001286 symbol->setId(variable->getUniqueId());
Jamie Madill60ed9812013-06-06 11:56:46 -04001287 }
1288
Olli Etuahoe7847b02015-03-16 11:56:12 +02001289 return intermediate.makeAggregate(symbol, identifierOrTypeLocation);
Jamie Madill60ed9812013-06-06 11:56:46 -04001290}
1291
Olli Etuahoe7847b02015-03-16 11:56:12 +02001292TIntermAggregate *TParseContext::parseSingleArrayDeclaration(TPublicType &publicType,
1293 const TSourceLoc &identifierLocation,
1294 const TString &identifier,
1295 const TSourceLoc &indexLocation,
1296 TIntermTyped *indexExpression)
Jamie Madill60ed9812013-06-06 11:56:46 -04001297{
Olli Etuahofa33d582015-04-09 14:33:12 +03001298 mDeferredSingleDeclarationErrorCheck = false;
1299
1300 if (singleDeclarationErrorCheck(publicType, identifierLocation))
Jamie Madill60ed9812013-06-06 11:56:46 -04001301 recover();
1302
Olli Etuaho376f1b52015-04-13 13:23:41 +03001303 if (nonInitErrorCheck(identifierLocation, identifier, &publicType))
Jamie Madill60ed9812013-06-06 11:56:46 -04001304 recover();
1305
1306 if (arrayTypeErrorCheck(indexLocation, publicType) || arrayQualifierErrorCheck(indexLocation, publicType))
1307 {
1308 recover();
1309 }
1310
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +03001311 TType arrayType(publicType);
Jamie Madill60ed9812013-06-06 11:56:46 -04001312
1313 int size;
1314 if (arraySizeErrorCheck(identifierLocation, indexExpression, size))
1315 {
1316 recover();
1317 }
Olli Etuahoe7847b02015-03-16 11:56:12 +02001318 // Make the type an array even if size check failed.
1319 // This ensures useless error messages regarding the variable's non-arrayness won't follow.
1320 arrayType.setArraySize(size);
Jamie Madill60ed9812013-06-06 11:56:46 -04001321
Olli Etuaho2935c582015-04-08 14:32:06 +03001322 TVariable *variable = nullptr;
1323 if (!declareVariable(identifierLocation, identifier, arrayType, &variable))
Jamie Madill60ed9812013-06-06 11:56:46 -04001324 recover();
1325
Olli Etuahoe7847b02015-03-16 11:56:12 +02001326 TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, arrayType, identifierLocation);
Jamie Madill60ed9812013-06-06 11:56:46 -04001327 if (variable && symbol)
Jamie Madill60ed9812013-06-06 11:56:46 -04001328 symbol->setId(variable->getUniqueId());
Jamie Madill60ed9812013-06-06 11:56:46 -04001329
Olli Etuahoe7847b02015-03-16 11:56:12 +02001330 return intermediate.makeAggregate(symbol, identifierLocation);
Jamie Madill60ed9812013-06-06 11:56:46 -04001331}
1332
Olli Etuahoe7847b02015-03-16 11:56:12 +02001333TIntermAggregate *TParseContext::parseSingleInitDeclaration(TPublicType &publicType,
1334 const TSourceLoc &identifierLocation,
1335 const TString &identifier,
1336 const TSourceLoc &initLocation,
1337 TIntermTyped *initializer)
Jamie Madill60ed9812013-06-06 11:56:46 -04001338{
Olli Etuahofa33d582015-04-09 14:33:12 +03001339 mDeferredSingleDeclarationErrorCheck = false;
1340
1341 if (singleDeclarationErrorCheck(publicType, identifierLocation))
Jamie Madill60ed9812013-06-06 11:56:46 -04001342 recover();
1343
Olli Etuahoe7847b02015-03-16 11:56:12 +02001344 TIntermNode *intermNode = nullptr;
1345 if (!executeInitializer(identifierLocation, identifier, publicType, initializer, &intermNode))
Jamie Madill60ed9812013-06-06 11:56:46 -04001346 {
1347 //
1348 // Build intermediate representation
1349 //
Olli Etuahoe7847b02015-03-16 11:56:12 +02001350 return intermNode ? intermediate.makeAggregate(intermNode, initLocation) : nullptr;
Jamie Madill60ed9812013-06-06 11:56:46 -04001351 }
1352 else
1353 {
1354 recover();
Olli Etuahoe7847b02015-03-16 11:56:12 +02001355 return nullptr;
Jamie Madill60ed9812013-06-06 11:56:46 -04001356 }
1357}
1358
Olli Etuaho3875ffd2015-04-10 16:45:14 +03001359TIntermAggregate *TParseContext::parseSingleArrayInitDeclaration(TPublicType &publicType,
1360 const TSourceLoc &identifierLocation,
1361 const TString &identifier,
1362 const TSourceLoc &indexLocation,
1363 TIntermTyped *indexExpression,
1364 const TSourceLoc &initLocation,
1365 TIntermTyped *initializer)
1366{
1367 mDeferredSingleDeclarationErrorCheck = false;
1368
1369 if (singleDeclarationErrorCheck(publicType, identifierLocation))
1370 recover();
1371
1372 if (arrayTypeErrorCheck(indexLocation, publicType) || arrayQualifierErrorCheck(indexLocation, publicType))
1373 {
1374 recover();
1375 }
1376
1377 TPublicType arrayType(publicType);
1378
Olli Etuaho376f1b52015-04-13 13:23:41 +03001379 int size = 0;
1380 // If indexExpression is nullptr, then the array will eventually get its size implicitly from the initializer.
1381 if (indexExpression != nullptr && arraySizeErrorCheck(identifierLocation, indexExpression, size))
Olli Etuaho3875ffd2015-04-10 16:45:14 +03001382 {
1383 recover();
1384 }
1385 // Make the type an array even if size check failed.
1386 // This ensures useless error messages regarding the variable's non-arrayness won't follow.
1387 arrayType.setArraySize(size);
1388
1389 // initNode will correspond to the whole of "type b[n] = initializer".
1390 TIntermNode *initNode = nullptr;
1391 if (!executeInitializer(identifierLocation, identifier, arrayType, initializer, &initNode))
1392 {
1393 return initNode ? intermediate.makeAggregate(initNode, initLocation) : nullptr;
1394 }
1395 else
1396 {
1397 recover();
1398 return nullptr;
1399 }
1400}
1401
Olli Etuahoe7847b02015-03-16 11:56:12 +02001402TIntermAggregate *TParseContext::parseInvariantDeclaration(const TSourceLoc &invariantLoc,
Jamie Madill47e3ec02014-08-20 16:38:33 -04001403 const TSourceLoc &identifierLoc,
1404 const TString *identifier,
1405 const TSymbol *symbol)
1406{
Jamie Madill3b5c2da2014-08-19 15:23:32 -04001407 // invariant declaration
Jamie Madill47e3ec02014-08-20 16:38:33 -04001408 if (globalErrorCheck(invariantLoc, symbolTable.atGlobalLevel(), "invariant varying"))
1409 {
1410 recover();
1411 }
1412
1413 if (!symbol)
1414 {
1415 error(identifierLoc, "undeclared identifier declared as invariant", identifier->c_str());
1416 recover();
Olli Etuahoe7847b02015-03-16 11:56:12 +02001417 return nullptr;
Jamie Madill47e3ec02014-08-20 16:38:33 -04001418 }
1419 else
1420 {
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001421 const TString kGlFrontFacing("gl_FrontFacing");
1422 if (*identifier == kGlFrontFacing)
1423 {
1424 error(identifierLoc, "identifier should not be declared as invariant", identifier->c_str());
1425 recover();
Olli Etuahoe7847b02015-03-16 11:56:12 +02001426 return nullptr;
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001427 }
Jamie Madill2c433252014-12-03 12:36:54 -05001428 symbolTable.addInvariantVarying(std::string(identifier->c_str()));
Jamie Madill3b5c2da2014-08-19 15:23:32 -04001429 const TVariable *variable = getNamedVariable(identifierLoc, identifier, symbol);
1430 ASSERT(variable);
1431 const TType &type = variable->getType();
1432 TIntermSymbol *intermSymbol = intermediate.addSymbol(variable->getUniqueId(),
1433 *identifier, type, identifierLoc);
1434
1435 TIntermAggregate *aggregate = intermediate.makeAggregate(intermSymbol, identifierLoc);
1436 aggregate->setOp(EOpInvariantDeclaration);
1437 return aggregate;
Jamie Madill47e3ec02014-08-20 16:38:33 -04001438 }
1439}
1440
Olli Etuahoe7847b02015-03-16 11:56:12 +02001441TIntermAggregate *TParseContext::parseDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration,
1442 const TSourceLoc &identifierLocation, const TString &identifier)
Jamie Madill502d66f2013-06-20 11:55:52 -04001443{
Olli Etuahofa33d582015-04-09 14:33:12 +03001444 // If the declaration starting this declarator list was empty (example: int,), some checks were not performed.
1445 if (mDeferredSingleDeclarationErrorCheck)
1446 {
1447 if (singleDeclarationErrorCheck(publicType, identifierLocation))
1448 recover();
1449 mDeferredSingleDeclarationErrorCheck = false;
1450 }
1451
Jamie Madill0bd18df2013-06-20 11:55:52 -04001452 if (locationDeclaratorListCheck(identifierLocation, publicType))
1453 recover();
1454
Olli Etuaho376f1b52015-04-13 13:23:41 +03001455 if (nonInitErrorCheck(identifierLocation, identifier, &publicType))
Jamie Madill502d66f2013-06-20 11:55:52 -04001456 recover();
1457
Olli Etuaho2935c582015-04-08 14:32:06 +03001458 TVariable *variable = nullptr;
1459 if (!declareVariable(identifierLocation, identifier, TType(publicType), &variable))
Jamie Madill502d66f2013-06-20 11:55:52 -04001460 recover();
Olli Etuahoe7847b02015-03-16 11:56:12 +02001461
1462 TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, TType(publicType), identifierLocation);
1463 if (variable && symbol)
Jamie Madill502d66f2013-06-20 11:55:52 -04001464 symbol->setId(variable->getUniqueId());
1465
Olli Etuahoe7847b02015-03-16 11:56:12 +02001466 return intermediate.growAggregate(aggregateDeclaration, symbol, identifierLocation);
Jamie Madill502d66f2013-06-20 11:55:52 -04001467}
1468
Olli Etuahoe7847b02015-03-16 11:56:12 +02001469TIntermAggregate *TParseContext::parseArrayDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration,
1470 const TSourceLoc &identifierLocation, const TString &identifier,
1471 const TSourceLoc &arrayLocation, TIntermTyped *indexExpression)
Jamie Madill502d66f2013-06-20 11:55:52 -04001472{
Olli Etuahofa33d582015-04-09 14:33:12 +03001473 // If the declaration starting this declarator list was empty (example: int,), some checks were not performed.
1474 if (mDeferredSingleDeclarationErrorCheck)
1475 {
1476 if (singleDeclarationErrorCheck(publicType, identifierLocation))
1477 recover();
1478 mDeferredSingleDeclarationErrorCheck = false;
1479 }
Jamie Madill502d66f2013-06-20 11:55:52 -04001480
Jamie Madill0bd18df2013-06-20 11:55:52 -04001481 if (locationDeclaratorListCheck(identifierLocation, publicType))
1482 recover();
1483
Olli Etuaho376f1b52015-04-13 13:23:41 +03001484 if (nonInitErrorCheck(identifierLocation, identifier, &publicType))
Jamie Madill502d66f2013-06-20 11:55:52 -04001485 recover();
1486
1487 if (arrayTypeErrorCheck(arrayLocation, publicType) || arrayQualifierErrorCheck(arrayLocation, publicType))
1488 {
1489 recover();
1490 }
Olli Etuaho93a90fd2015-04-07 18:14:07 +03001491 else
Jamie Madill502d66f2013-06-20 11:55:52 -04001492 {
Olli Etuahoe7847b02015-03-16 11:56:12 +02001493 TType arrayType = TType(publicType);
Jamie Madill502d66f2013-06-20 11:55:52 -04001494 int size;
1495 if (arraySizeErrorCheck(arrayLocation, indexExpression, size))
Olli Etuahoe7847b02015-03-16 11:56:12 +02001496 {
Jamie Madill502d66f2013-06-20 11:55:52 -04001497 recover();
Olli Etuahoe7847b02015-03-16 11:56:12 +02001498 }
Olli Etuaho693c9aa2015-04-07 17:50:36 +03001499 arrayType.setArraySize(size);
Olli Etuahoe7847b02015-03-16 11:56:12 +02001500
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +03001501 TVariable *variable = nullptr;
Olli Etuahoe7847b02015-03-16 11:56:12 +02001502 if (!declareVariable(identifierLocation, identifier, arrayType, &variable))
Jamie Madill502d66f2013-06-20 11:55:52 -04001503 recover();
Jamie Madill502d66f2013-06-20 11:55:52 -04001504
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +03001505 TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, arrayType, identifierLocation);
1506 if (variable && symbol)
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +03001507 symbol->setId(variable->getUniqueId());
Olli Etuahoe7847b02015-03-16 11:56:12 +02001508
1509 return intermediate.growAggregate(aggregateDeclaration, symbol, identifierLocation);
Jamie Madill502d66f2013-06-20 11:55:52 -04001510 }
Jamie Madill502d66f2013-06-20 11:55:52 -04001511
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +03001512 return nullptr;
Jamie Madill502d66f2013-06-20 11:55:52 -04001513}
1514
Olli Etuahoe7847b02015-03-16 11:56:12 +02001515TIntermAggregate *TParseContext::parseInitDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration,
1516 const TSourceLoc &identifierLocation, const TString &identifier,
1517 const TSourceLoc &initLocation, TIntermTyped *initializer)
Jamie Madill502d66f2013-06-20 11:55:52 -04001518{
Olli Etuahofa33d582015-04-09 14:33:12 +03001519 // If the declaration starting this declarator list was empty (example: int,), some checks were not performed.
1520 if (mDeferredSingleDeclarationErrorCheck)
1521 {
1522 if (singleDeclarationErrorCheck(publicType, identifierLocation))
1523 recover();
1524 mDeferredSingleDeclarationErrorCheck = false;
1525 }
Jamie Madill502d66f2013-06-20 11:55:52 -04001526
Jamie Madill0bd18df2013-06-20 11:55:52 -04001527 if (locationDeclaratorListCheck(identifierLocation, publicType))
1528 recover();
1529
Olli Etuahoe7847b02015-03-16 11:56:12 +02001530 TIntermNode *intermNode = nullptr;
1531 if (!executeInitializer(identifierLocation, identifier, publicType, initializer, &intermNode))
Jamie Madill502d66f2013-06-20 11:55:52 -04001532 {
1533 //
1534 // build the intermediate representation
1535 //
1536 if (intermNode)
1537 {
Olli Etuahoe7847b02015-03-16 11:56:12 +02001538 return intermediate.growAggregate(aggregateDeclaration, intermNode, initLocation);
Jamie Madill502d66f2013-06-20 11:55:52 -04001539 }
1540 else
1541 {
Olli Etuahoe7847b02015-03-16 11:56:12 +02001542 return aggregateDeclaration;
Jamie Madill502d66f2013-06-20 11:55:52 -04001543 }
1544 }
1545 else
1546 {
1547 recover();
Olli Etuahoe7847b02015-03-16 11:56:12 +02001548 return nullptr;
Jamie Madill502d66f2013-06-20 11:55:52 -04001549 }
1550}
1551
Olli Etuaho3875ffd2015-04-10 16:45:14 +03001552TIntermAggregate *TParseContext::parseArrayInitDeclarator(TPublicType &publicType,
1553 TIntermAggregate *aggregateDeclaration,
1554 const TSourceLoc& identifierLocation,
1555 const TString &identifier,
1556 const TSourceLoc& indexLocation,
1557 TIntermTyped *indexExpression,
1558 const TSourceLoc &initLocation, TIntermTyped *initializer)
1559{
1560 // If the declaration starting this declarator list was empty (example: int,), some checks were not performed.
1561 if (mDeferredSingleDeclarationErrorCheck)
1562 {
1563 if (singleDeclarationErrorCheck(publicType, identifierLocation))
1564 recover();
1565 mDeferredSingleDeclarationErrorCheck = false;
1566 }
1567
1568 if (locationDeclaratorListCheck(identifierLocation, publicType))
1569 recover();
1570
1571 if (arrayTypeErrorCheck(indexLocation, publicType) || arrayQualifierErrorCheck(indexLocation, publicType))
1572 {
1573 recover();
1574 }
1575
1576 TPublicType arrayType(publicType);
1577
Olli Etuaho376f1b52015-04-13 13:23:41 +03001578 int size = 0;
1579 // If indexExpression is nullptr, then the array will eventually get its size implicitly from the initializer.
1580 if (indexExpression != nullptr && arraySizeErrorCheck(identifierLocation, indexExpression, size))
Olli Etuaho3875ffd2015-04-10 16:45:14 +03001581 {
1582 recover();
1583 }
1584 // Make the type an array even if size check failed.
1585 // This ensures useless error messages regarding the variable's non-arrayness won't follow.
1586 arrayType.setArraySize(size);
1587
1588 // initNode will correspond to the whole of "b[n] = initializer".
1589 TIntermNode *initNode = nullptr;
1590 if (!executeInitializer(identifierLocation, identifier, arrayType, initializer, &initNode))
1591 {
1592 if (initNode)
1593 {
1594 return intermediate.growAggregate(aggregateDeclaration, initNode, initLocation);
1595 }
1596 else
1597 {
1598 return aggregateDeclaration;
1599 }
1600 }
1601 else
1602 {
1603 recover();
1604 return nullptr;
1605 }
1606}
1607
Jamie Madilla295edf2013-06-06 11:56:48 -04001608void TParseContext::parseGlobalLayoutQualifier(const TPublicType &typeQualifier)
1609{
1610 if (typeQualifier.qualifier != EvqUniform)
1611 {
1612 error(typeQualifier.line, "invalid qualifier:", getQualifierString(typeQualifier.qualifier), "global layout must be uniform");
1613 recover();
1614 return;
1615 }
1616
1617 const TLayoutQualifier layoutQualifier = typeQualifier.layoutQualifier;
1618 ASSERT(!layoutQualifier.isEmpty());
1619
1620 if (shaderVersion < 300)
1621 {
1622 error(typeQualifier.line, "layout qualifiers supported in GLSL ES 3.00 only", "layout");
1623 recover();
1624 return;
1625 }
1626
1627 if (layoutLocationErrorCheck(typeQualifier.line, typeQualifier.layoutQualifier))
1628 {
1629 recover();
1630 return;
1631 }
1632
Jamie Madill099c0f32013-06-20 11:55:52 -04001633 if (layoutQualifier.matrixPacking != EmpUnspecified)
1634 {
1635 defaultMatrixPacking = layoutQualifier.matrixPacking;
1636 }
1637
Geoff Langc6856732014-02-11 09:38:55 -05001638 if (layoutQualifier.blockStorage != EbsUnspecified)
Jamie Madill1566ef72013-06-20 11:55:54 -04001639 {
1640 defaultBlockStorage = layoutQualifier.blockStorage;
1641 }
Jamie Madilla295edf2013-06-06 11:56:48 -04001642}
1643
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00001644TFunction *TParseContext::addConstructorFunc(TPublicType publicType)
1645{
1646 TOperator op = EOpNull;
1647 if (publicType.userDef)
1648 {
1649 op = EOpConstructStruct;
1650 }
1651 else
1652 {
1653 switch (publicType.type)
1654 {
1655 case EbtFloat:
1656 if (publicType.isMatrix())
1657 {
1658 // TODO: non-square matrices
1659 switch(publicType.getCols())
1660 {
Jamie Madill28b97422013-07-08 14:01:38 -04001661 case 2: op = EOpConstructMat2; break;
1662 case 3: op = EOpConstructMat3; break;
1663 case 4: op = EOpConstructMat4; break;
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00001664 }
1665 }
1666 else
1667 {
1668 switch(publicType.getNominalSize())
1669 {
Jamie Madill28b97422013-07-08 14:01:38 -04001670 case 1: op = EOpConstructFloat; break;
1671 case 2: op = EOpConstructVec2; break;
1672 case 3: op = EOpConstructVec3; break;
1673 case 4: op = EOpConstructVec4; break;
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00001674 }
1675 }
1676 break;
1677
1678 case EbtInt:
1679 switch(publicType.getNominalSize())
1680 {
Jamie Madill28b97422013-07-08 14:01:38 -04001681 case 1: op = EOpConstructInt; break;
1682 case 2: op = EOpConstructIVec2; break;
1683 case 3: op = EOpConstructIVec3; break;
1684 case 4: op = EOpConstructIVec4; break;
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00001685 }
1686 break;
1687
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +00001688 case EbtUInt:
1689 switch(publicType.getNominalSize())
1690 {
Jamie Madill28b97422013-07-08 14:01:38 -04001691 case 1: op = EOpConstructUInt; break;
1692 case 2: op = EOpConstructUVec2; break;
1693 case 3: op = EOpConstructUVec3; break;
1694 case 4: op = EOpConstructUVec4; break;
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +00001695 }
1696 break;
1697
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00001698 case EbtBool:
1699 switch(publicType.getNominalSize())
1700 {
Jamie Madill28b97422013-07-08 14:01:38 -04001701 case 1: op = EOpConstructBool; break;
1702 case 2: op = EOpConstructBVec2; break;
1703 case 3: op = EOpConstructBVec3; break;
1704 case 4: op = EOpConstructBVec4; break;
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00001705 }
1706 break;
1707
1708 default: break;
1709 }
1710
1711 if (op == EOpNull)
1712 {
1713 error(publicType.line, "cannot construct this type", getBasicString(publicType.type));
1714 recover();
1715 publicType.type = EbtFloat;
1716 op = EOpConstructFloat;
1717 }
1718 }
1719
1720 TString tempString;
1721 TType type(publicType);
1722 return new TFunction(&tempString, type, op);
1723}
1724
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001725// This function is used to test for the correctness of the parameters passed to various constructor functions
1726// and also convert them to the right datatype if it is allowed and required.
1727//
1728// Returns 0 for an error or the constructed node (aggregate or typed) for no error.
1729//
Olli Etuaho21203702014-11-13 16:16:21 +02001730TIntermTyped *TParseContext::addConstructor(TIntermNode *arguments, TType *type, TOperator op, TFunction *fnCall, const TSourceLoc &line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001731{
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04001732 TIntermAggregate *aggregateArguments = arguments->getAsAggregate();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001733
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04001734 if (!aggregateArguments)
1735 {
1736 aggregateArguments = new TIntermAggregate;
Zhenyao Moe40d1e92014-07-16 17:40:36 -07001737 aggregateArguments->getSequence()->push_back(arguments);
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04001738 }
1739
Olli Etuahof40319e2015-03-10 14:33:00 +02001740 if (type->isArray())
1741 {
1742 // GLSL ES 3.00 section 5.4.4: Each argument must be the same type as the element type of the array.
1743 TIntermSequence *args = aggregateArguments->getSequence();
1744 for (size_t i = 0; i < args->size(); i++)
1745 {
1746 const TType &argType = (*args)[i]->getAsTyped()->getType();
1747 // It has already been checked that the argument is not an array.
1748 ASSERT(!argType.isArray());
1749 if (!argType.sameElementType(*type))
1750 {
1751 error(line, "Array constructor argument has an incorrect type", "Error");
1752 recover();
1753 return nullptr;
1754 }
1755 }
1756 }
1757 else if (op == EOpConstructStruct)
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04001758 {
1759 const TFieldList &fields = type->getStruct()->fields();
Zhenyao Moe40d1e92014-07-16 17:40:36 -07001760 TIntermSequence *args = aggregateArguments->getSequence();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001761
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04001762 for (size_t i = 0; i < fields.size(); i++)
1763 {
Nicolas Capensffd73872014-08-21 13:49:16 -04001764 if (i >= args->size() || (*args)[i]->getAsTyped()->getType() != *fields[i]->type())
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04001765 {
1766 error(line, "Structure constructor arguments do not match structure fields", "Error");
1767 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001768
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04001769 return 0;
1770 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001771 }
1772 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001773
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04001774 // Turn the argument list itself into a constructor
Olli Etuaho21203702014-11-13 16:16:21 +02001775 TIntermAggregate *constructor = intermediate.setAggregateOperator(aggregateArguments, op, line);
1776 TIntermTyped *constConstructor = foldConstConstructor(constructor, *type);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001777 if (constConstructor)
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04001778 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001779 return constConstructor;
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04001780 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001781
Olli Etuaho21203702014-11-13 16:16:21 +02001782 // Structs should not be precision qualified, the individual members may be.
1783 // Built-in types on the other hand should be precision qualified.
1784 if (op != EOpConstructStruct)
1785 {
1786 constructor->setPrecisionFromChildren();
1787 type->setPrecision(constructor->getPrecision());
1788 }
1789
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001790 return constructor;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001791}
1792
1793TIntermTyped* TParseContext::foldConstConstructor(TIntermAggregate* aggrNode, const TType& type)
1794{
Olli Etuahof40319e2015-03-10 14:33:00 +02001795 // TODO: Add support for folding array constructors
1796 bool canBeFolded = areAllChildConst(aggrNode) && !type.isArray();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001797 aggrNode->setType(type);
1798 if (canBeFolded) {
1799 bool returnVal = false;
Jamie Madill6ba6ead2015-05-04 14:21:21 -04001800 TConstantUnion* unionArray = new TConstantUnion[type.getObjectSize()];
Zhenyao Moe40d1e92014-07-16 17:40:36 -07001801 if (aggrNode->getSequence()->size() == 1) {
shannonwoods@chromium.org298f9072013-05-30 00:21:17 +00001802 returnVal = intermediate.parseConstTree(aggrNode->getLine(), aggrNode, unionArray, aggrNode->getOp(), type, true);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001803 }
1804 else {
shannonwoods@chromium.org298f9072013-05-30 00:21:17 +00001805 returnVal = intermediate.parseConstTree(aggrNode->getLine(), aggrNode, unionArray, aggrNode->getOp(), type);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001806 }
1807 if (returnVal)
1808 return 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001809
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001810 return intermediate.addConstantUnion(unionArray, type, aggrNode->getLine());
1811 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001812
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001813 return 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001814}
1815
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001816//
1817// This function returns the tree representation for the vector field(s) being accessed from contant vector.
1818// If only one component of vector is accessed (v.x or v[0] where v is a contant vector), then a contant node is
1819// returned, else an aggregate node is returned (for v.xy). The input to this function could either be the symbol
1820// node or it could be the intermediate tree representation of accessing fields in a constant structure or column of
1821// a constant matrix.
1822//
Jamie Madill075edd82013-07-08 13:30:19 -04001823TIntermTyped* TParseContext::addConstVectorNode(TVectorFields& fields, TIntermTyped* node, const TSourceLoc& line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001824{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001825 TIntermTyped* typedNode;
1826 TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001827
Jamie Madillb11e2482015-05-04 14:21:22 -04001828 const TConstantUnion *unionArray;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001829 if (tempConstantNode) {
1830 unionArray = tempConstantNode->getUnionArrayPointer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001831
alokp@chromium.org8b851c62012-06-15 16:25:11 +00001832 if (!unionArray) {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001833 return node;
1834 }
1835 } 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 +00001836 error(line, "Cannot offset into the vector", "Error");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001837 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001838
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001839 return 0;
1840 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001841
Jamie Madill6ba6ead2015-05-04 14:21:21 -04001842 TConstantUnion* constArray = new TConstantUnion[fields.num];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001843
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001844 for (int i = 0; i < fields.num; i++) {
Jamie Madill94bf7f22013-07-08 13:31:15 -04001845 if (fields.offsets[i] >= node->getType().getNominalSize()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001846 std::stringstream extraInfoStream;
1847 extraInfoStream << "vector field selection out of range '" << fields.offsets[i] << "'";
1848 std::string extraInfo = extraInfoStream.str();
1849 error(line, "", "[", extraInfo.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001850 recover();
1851 fields.offsets[i] = 0;
1852 }
1853
1854 constArray[i] = unionArray[fields.offsets[i]];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001855
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001856 }
1857 typedNode = intermediate.addConstantUnion(constArray, node->getType(), line);
1858 return typedNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001859}
1860
1861//
1862// This function returns the column being accessed from a constant matrix. The values are retrieved from
1863// the symbol table and parse-tree is built for a vector (each column of a matrix is a vector). The input
1864// to the function could either be a symbol node (m[0] where m is a constant matrix)that represents a
1865// constant matrix or it could be the tree representation of the constant matrix (s.m1[0] where s is a constant structure)
1866//
Jamie Madill075edd82013-07-08 13:30:19 -04001867TIntermTyped* TParseContext::addConstMatrixNode(int index, TIntermTyped* node, const TSourceLoc& line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001868{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001869 TIntermTyped* typedNode;
1870 TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001871
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +00001872 if (index >= node->getType().getCols()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001873 std::stringstream extraInfoStream;
1874 extraInfoStream << "matrix field selection out of range '" << index << "'";
1875 std::string extraInfo = extraInfoStream.str();
1876 error(line, "", "[", extraInfo.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001877 recover();
1878 index = 0;
1879 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001880
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001881 if (tempConstantNode) {
Jamie Madillb11e2482015-05-04 14:21:22 -04001882 TConstantUnion *unionArray = tempConstantNode->getUnionArrayPointer();
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00001883 int size = tempConstantNode->getType().getCols();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001884 typedNode = intermediate.addConstantUnion(&unionArray[size*index], tempConstantNode->getType(), line);
1885 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001886 error(line, "Cannot offset into the matrix", "Error");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001887 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001888
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001889 return 0;
1890 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001891
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001892 return typedNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001893}
1894
1895
1896//
1897// This function returns an element of an array accessed from a constant array. The values are retrieved from
1898// the symbol table and parse-tree is built for the type of the element. The input
1899// to the function could either be a symbol node (a[0] where a is a constant array)that represents a
1900// constant array or it could be the tree representation of the constant array (s.a1[0] where s is a constant structure)
1901//
Jamie Madill075edd82013-07-08 13:30:19 -04001902TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, const TSourceLoc& line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001903{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001904 TIntermTyped* typedNode;
1905 TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion();
1906 TType arrayElementType = node->getType();
1907 arrayElementType.clearArrayness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001908
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001909 if (index >= node->getType().getArraySize()) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001910 std::stringstream extraInfoStream;
1911 extraInfoStream << "array field selection out of range '" << index << "'";
1912 std::string extraInfo = extraInfoStream.str();
1913 error(line, "", "[", extraInfo.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001914 recover();
1915 index = 0;
1916 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001917
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001918 if (tempConstantNode) {
Jamie Madill94bf7f22013-07-08 13:31:15 -04001919 size_t arrayElementSize = arrayElementType.getObjectSize();
Jamie Madill6ba6ead2015-05-04 14:21:21 -04001920 TConstantUnion* unionArray = tempConstantNode->getUnionArrayPointer();
Jamie Madill94bf7f22013-07-08 13:31:15 -04001921 typedNode = intermediate.addConstantUnion(&unionArray[arrayElementSize * index], tempConstantNode->getType(), line);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001922 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001923 error(line, "Cannot offset into the array", "Error");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001924 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001925
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001926 return 0;
1927 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001928
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001929 return typedNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001930}
1931
1932
1933//
1934// This function returns the value of a particular field inside a constant structure from the symbol table.
1935// If there is an embedded/nested struct, it appropriately calls addConstStructNested or addConstStructFromAggr
1936// function and returns the parse-tree with the values of the embedded/nested struct.
1937//
Jamie Madill075edd82013-07-08 13:30:19 -04001938TIntermTyped* TParseContext::addConstStruct(const TString &identifier, TIntermTyped *node, const TSourceLoc& line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001939{
Jamie Madill98493dd2013-07-08 14:39:03 -04001940 const TFieldList& fields = node->getType().getStruct()->fields();
Jamie Madill94bf7f22013-07-08 13:31:15 -04001941 size_t instanceSize = 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001942
Jamie Madill98493dd2013-07-08 14:39:03 -04001943 for (size_t index = 0; index < fields.size(); ++index) {
1944 if (fields[index]->name() == identifier) {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001945 break;
1946 } else {
Jamie Madill98493dd2013-07-08 14:39:03 -04001947 instanceSize += fields[index]->type()->getObjectSize();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001948 }
1949 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001950
Jamie Madill94bf7f22013-07-08 13:31:15 -04001951 TIntermTyped *typedNode;
1952 TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001953 if (tempConstantNode) {
Jamie Madill6ba6ead2015-05-04 14:21:21 -04001954 TConstantUnion* constArray = tempConstantNode->getUnionArrayPointer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001955
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001956 typedNode = intermediate.addConstantUnion(constArray+instanceSize, tempConstantNode->getType(), line); // type will be changed in the calling function
1957 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001958 error(line, "Cannot offset into the structure", "Error");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001959 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001960
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001961 return 0;
1962 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001963
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001964 return typedNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001965}
1966
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00001967//
1968// Interface/uniform blocks
1969//
Jamie Madill98493dd2013-07-08 14:39:03 -04001970TIntermAggregate* TParseContext::addInterfaceBlock(const TPublicType& typeQualifier, const TSourceLoc& nameLine, const TString& blockName, TFieldList* fieldList,
1971 const TString* instanceName, const TSourceLoc& instanceLine, TIntermTyped* arrayIndex, const TSourceLoc& arrayIndexLine)
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00001972{
1973 if (reservedErrorCheck(nameLine, blockName))
1974 recover();
1975
1976 if (typeQualifier.qualifier != EvqUniform)
1977 {
1978 error(typeQualifier.line, "invalid qualifier:", getQualifierString(typeQualifier.qualifier), "interface blocks must be uniform");
1979 recover();
1980 }
1981
Jamie Madill099c0f32013-06-20 11:55:52 -04001982 TLayoutQualifier blockLayoutQualifier = typeQualifier.layoutQualifier;
1983 if (layoutLocationErrorCheck(typeQualifier.line, blockLayoutQualifier))
Jamie Madilla5efff92013-06-06 11:56:47 -04001984 {
1985 recover();
1986 }
1987
Jamie Madill099c0f32013-06-20 11:55:52 -04001988 if (blockLayoutQualifier.matrixPacking == EmpUnspecified)
1989 {
1990 blockLayoutQualifier.matrixPacking = defaultMatrixPacking;
1991 }
1992
Jamie Madill1566ef72013-06-20 11:55:54 -04001993 if (blockLayoutQualifier.blockStorage == EbsUnspecified)
1994 {
1995 blockLayoutQualifier.blockStorage = defaultBlockStorage;
1996 }
1997
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00001998 TSymbol* blockNameSymbol = new TInterfaceBlockName(&blockName);
Nicolas Capensadfffe42014-06-17 02:13:36 -04001999 if (!symbolTable.declare(blockNameSymbol)) {
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002000 error(nameLine, "redefinition", blockName.c_str(), "interface block name");
2001 recover();
2002 }
2003
Jamie Madill98493dd2013-07-08 14:39:03 -04002004 // check for sampler types and apply layout qualifiers
2005 for (size_t memberIndex = 0; memberIndex < fieldList->size(); ++memberIndex) {
2006 TField* field = (*fieldList)[memberIndex];
2007 TType* fieldType = field->type();
2008 if (IsSampler(fieldType->getBasicType())) {
2009 error(field->line(), "unsupported type", fieldType->getBasicString(), "sampler types are not allowed in interface blocks");
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002010 recover();
2011 }
2012
Jamie Madill98493dd2013-07-08 14:39:03 -04002013 const TQualifier qualifier = fieldType->getQualifier();
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002014 switch (qualifier)
2015 {
2016 case EvqGlobal:
2017 case EvqUniform:
2018 break;
2019 default:
Jamie Madill98493dd2013-07-08 14:39:03 -04002020 error(field->line(), "invalid qualifier on interface block member", getQualifierString(qualifier));
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002021 recover();
2022 break;
2023 }
Jamie Madilla5efff92013-06-06 11:56:47 -04002024
2025 // check layout qualifiers
Jamie Madill98493dd2013-07-08 14:39:03 -04002026 TLayoutQualifier fieldLayoutQualifier = fieldType->getLayoutQualifier();
2027 if (layoutLocationErrorCheck(field->line(), fieldLayoutQualifier))
Jamie Madilla5efff92013-06-06 11:56:47 -04002028 {
2029 recover();
2030 }
Jamie Madill099c0f32013-06-20 11:55:52 -04002031
Jamie Madill98493dd2013-07-08 14:39:03 -04002032 if (fieldLayoutQualifier.blockStorage != EbsUnspecified)
Jamie Madill1566ef72013-06-20 11:55:54 -04002033 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002034 error(field->line(), "invalid layout qualifier:", getBlockStorageString(fieldLayoutQualifier.blockStorage), "cannot be used here");
Jamie Madill1566ef72013-06-20 11:55:54 -04002035 recover();
2036 }
2037
Jamie Madill98493dd2013-07-08 14:39:03 -04002038 if (fieldLayoutQualifier.matrixPacking == EmpUnspecified)
Jamie Madill099c0f32013-06-20 11:55:52 -04002039 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002040 fieldLayoutQualifier.matrixPacking = blockLayoutQualifier.matrixPacking;
Jamie Madill099c0f32013-06-20 11:55:52 -04002041 }
Jamie Madill98493dd2013-07-08 14:39:03 -04002042 else if (!fieldType->isMatrix())
Jamie Madill099c0f32013-06-20 11:55:52 -04002043 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002044 error(field->line(), "invalid layout qualifier:", getMatrixPackingString(fieldLayoutQualifier.matrixPacking), "can only be used on matrix types");
Jamie Madill099c0f32013-06-20 11:55:52 -04002045 recover();
2046 }
2047
Jamie Madill98493dd2013-07-08 14:39:03 -04002048 fieldType->setLayoutQualifier(fieldLayoutQualifier);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002049 }
2050
Jamie Madill98493dd2013-07-08 14:39:03 -04002051 // add array index
2052 int arraySize = 0;
2053 if (arrayIndex != NULL)
2054 {
2055 if (arraySizeErrorCheck(arrayIndexLine, arrayIndex, arraySize))
2056 recover();
2057 }
2058
2059 TInterfaceBlock* interfaceBlock = new TInterfaceBlock(&blockName, fieldList, instanceName, arraySize, blockLayoutQualifier);
2060 TType interfaceBlockType(interfaceBlock, typeQualifier.qualifier, blockLayoutQualifier, arraySize);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002061
2062 TString symbolName = "";
2063 int symbolId = 0;
2064
Jamie Madill98493dd2013-07-08 14:39:03 -04002065 if (!instanceName)
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002066 {
2067 // define symbols for the members of the interface block
Jamie Madill98493dd2013-07-08 14:39:03 -04002068 for (size_t memberIndex = 0; memberIndex < fieldList->size(); ++memberIndex)
2069 {
2070 TField* field = (*fieldList)[memberIndex];
2071 TType* fieldType = field->type();
2072
2073 // set parent pointer of the field variable
2074 fieldType->setInterfaceBlock(interfaceBlock);
2075
2076 TVariable* fieldVariable = new TVariable(&field->name(), *fieldType);
2077 fieldVariable->setQualifier(typeQualifier.qualifier);
2078
Nicolas Capensadfffe42014-06-17 02:13:36 -04002079 if (!symbolTable.declare(fieldVariable)) {
Jamie Madill98493dd2013-07-08 14:39:03 -04002080 error(field->line(), "redefinition", field->name().c_str(), "interface block member name");
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002081 recover();
2082 }
2083 }
2084 }
2085 else
2086 {
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002087 // add a symbol for this interface block
Jamie Madill98493dd2013-07-08 14:39:03 -04002088 TVariable* instanceTypeDef = new TVariable(instanceName, interfaceBlockType, false);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002089 instanceTypeDef->setQualifier(typeQualifier.qualifier);
Jamie Madill98493dd2013-07-08 14:39:03 -04002090
Nicolas Capensadfffe42014-06-17 02:13:36 -04002091 if (!symbolTable.declare(instanceTypeDef)) {
Jamie Madill98493dd2013-07-08 14:39:03 -04002092 error(instanceLine, "redefinition", instanceName->c_str(), "interface block instance name");
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002093 recover();
2094 }
2095
2096 symbolId = instanceTypeDef->getUniqueId();
2097 symbolName = instanceTypeDef->getName();
2098 }
2099
Jamie Madill98493dd2013-07-08 14:39:03 -04002100 TIntermAggregate *aggregate = intermediate.makeAggregate(intermediate.addSymbol(symbolId, symbolName, interfaceBlockType, typeQualifier.line), nameLine);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002101 aggregate->setOp(EOpDeclaration);
Jamie Madill98493dd2013-07-08 14:39:03 -04002102
2103 exitStructDeclaration();
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002104 return aggregate;
2105}
2106
Jamie Madill075edd82013-07-08 13:30:19 -04002107bool TParseContext::enterStructDeclaration(const TSourceLoc& line, const TString& identifier)
kbr@chromium.org476541f2011-10-27 21:14:51 +00002108{
2109 ++structNestingLevel;
2110
2111 // Embedded structure definitions are not supported per GLSL ES spec.
2112 // They aren't allowed in GLSL either, but we need to detect this here
2113 // so we don't rely on the GLSL compiler to catch it.
2114 if (structNestingLevel > 1) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00002115 error(line, "", "Embedded struct definitions are not allowed");
kbr@chromium.org476541f2011-10-27 21:14:51 +00002116 return true;
2117 }
2118
2119 return false;
2120}
2121
2122void TParseContext::exitStructDeclaration()
2123{
2124 --structNestingLevel;
2125}
2126
2127namespace {
2128
2129const int kWebGLMaxStructNesting = 4;
2130
2131} // namespace
2132
Jamie Madill98493dd2013-07-08 14:39:03 -04002133bool TParseContext::structNestingErrorCheck(const TSourceLoc& line, const TField& field)
kbr@chromium.org476541f2011-10-27 21:14:51 +00002134{
Jamie Madill5508f392014-02-20 13:31:36 -05002135 if (!IsWebGLBasedSpec(shaderSpec)) {
kbr@chromium.org476541f2011-10-27 21:14:51 +00002136 return false;
2137 }
2138
Jamie Madill98493dd2013-07-08 14:39:03 -04002139 if (field.type()->getBasicType() != EbtStruct) {
kbr@chromium.org476541f2011-10-27 21:14:51 +00002140 return false;
2141 }
2142
2143 // We're already inside a structure definition at this point, so add
2144 // one to the field's struct nesting.
Jamie Madill98493dd2013-07-08 14:39:03 -04002145 if (1 + field.type()->getDeepestStructNesting() > kWebGLMaxStructNesting) {
Jamie Madill41a49272014-03-18 16:10:13 -04002146 std::stringstream reasonStream;
2147 reasonStream << "Reference of struct type "
2148 << field.type()->getStruct()->name().c_str()
2149 << " exceeds maximum allowed nesting level of "
2150 << kWebGLMaxStructNesting;
2151 std::string reason = reasonStream.str();
2152 error(line, reason.c_str(), field.name().c_str(), "");
kbr@chromium.org476541f2011-10-27 21:14:51 +00002153 return true;
2154 }
2155
2156 return false;
2157}
2158
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00002159//
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002160// Parse an array index expression
2161//
Jamie Madill075edd82013-07-08 13:30:19 -04002162TIntermTyped* TParseContext::addIndexExpression(TIntermTyped *baseExpression, const TSourceLoc& location, TIntermTyped *indexExpression)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002163{
2164 TIntermTyped *indexedExpression = NULL;
2165
2166 if (!baseExpression->isArray() && !baseExpression->isMatrix() && !baseExpression->isVector())
2167 {
2168 if (baseExpression->getAsSymbolNode())
2169 {
2170 error(location, " left of '[' is not of type array, matrix, or vector ", baseExpression->getAsSymbolNode()->getSymbol().c_str());
2171 }
2172 else
2173 {
2174 error(location, " left of '[' is not of type array, matrix, or vector ", "expression");
2175 }
2176 recover();
2177 }
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00002178
Jamie Madill21c1e452014-12-29 11:33:41 -05002179 TIntermConstantUnion *indexConstantUnion = indexExpression->getAsConstantUnion();
2180
2181 if (indexExpression->getQualifier() == EvqConst && indexConstantUnion)
Jamie Madill7164cf42013-07-08 13:30:59 -04002182 {
Jamie Madill21c1e452014-12-29 11:33:41 -05002183 int index = indexConstantUnion->getIConst(0);
Jamie Madill7164cf42013-07-08 13:30:59 -04002184 if (index < 0)
2185 {
2186 std::stringstream infoStream;
2187 infoStream << index;
2188 std::string info = infoStream.str();
2189 error(location, "negative index", info.c_str());
2190 recover();
2191 index = 0;
2192 }
2193 if (baseExpression->getType().getQualifier() == EvqConst)
2194 {
2195 if (baseExpression->isArray())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002196 {
Jamie Madill7164cf42013-07-08 13:30:59 -04002197 // constant folding for arrays
2198 indexedExpression = addConstArrayNode(index, baseExpression, location);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002199 }
Jamie Madill7164cf42013-07-08 13:30:59 -04002200 else if (baseExpression->isVector())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002201 {
Jamie Madill7164cf42013-07-08 13:30:59 -04002202 // constant folding for vectors
2203 TVectorFields fields;
2204 fields.num = 1;
2205 fields.offsets[0] = index; // need to do it this way because v.xy sends fields integer array
2206 indexedExpression = addConstVectorNode(fields, baseExpression, location);
2207 }
2208 else if (baseExpression->isMatrix())
2209 {
2210 // constant folding for matrices
2211 indexedExpression = addConstMatrixNode(index, baseExpression, location);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002212 }
2213 }
2214 else
2215 {
Jamie Madillb11e2482015-05-04 14:21:22 -04002216 int safeIndex = -1;
2217
Jamie Madill7164cf42013-07-08 13:30:59 -04002218 if (baseExpression->isArray())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002219 {
Jamie Madill18464b52013-07-08 14:01:55 -04002220 if (index >= baseExpression->getType().getArraySize())
Jamie Madill7164cf42013-07-08 13:30:59 -04002221 {
2222 std::stringstream extraInfoStream;
2223 extraInfoStream << "array index out of range '" << index << "'";
2224 std::string extraInfo = extraInfoStream.str();
2225 error(location, "", "[", extraInfo.c_str());
2226 recover();
Jamie Madillb11e2482015-05-04 14:21:22 -04002227 safeIndex = baseExpression->getType().getArraySize() - 1;
Jamie Madill7164cf42013-07-08 13:30:59 -04002228 }
Jamie Madill5d287f52013-07-12 15:38:19 -04002229 else if (baseExpression->getQualifier() == EvqFragData && index > 0 && !isExtensionEnabled("GL_EXT_draw_buffers"))
2230 {
2231 error(location, "", "[", "array indexes for gl_FragData must be zero when GL_EXT_draw_buffers is disabled");
2232 recover();
Jamie Madillb11e2482015-05-04 14:21:22 -04002233 safeIndex = 0;
Jamie Madill5d287f52013-07-12 15:38:19 -04002234 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002235 }
Jamie Madill7164cf42013-07-08 13:30:59 -04002236 else if ((baseExpression->isVector() || baseExpression->isMatrix()) && baseExpression->getType().getNominalSize() <= index)
shannonwoods@chromium.orge429ab72013-05-30 00:12:52 +00002237 {
Jamie Madill7164cf42013-07-08 13:30:59 -04002238 std::stringstream extraInfoStream;
2239 extraInfoStream << "field selection out of range '" << index << "'";
2240 std::string extraInfo = extraInfoStream.str();
2241 error(location, "", "[", extraInfo.c_str());
shannonwoods@chromium.orge429ab72013-05-30 00:12:52 +00002242 recover();
Jamie Madillb11e2482015-05-04 14:21:22 -04002243 safeIndex = baseExpression->getType().getNominalSize() - 1;
Jamie Madill46131a32013-06-20 11:55:50 -04002244 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002245
Jamie Madillb11e2482015-05-04 14:21:22 -04002246 // Don't modify the data of the previous constant union, because it can point
2247 // to builtins, like gl_MaxDrawBuffers. Instead use a new sanitized object.
2248 if (safeIndex != -1)
2249 {
2250 TConstantUnion *safeConstantUnion = new TConstantUnion();
2251 safeConstantUnion->setIConst(safeIndex);
2252 indexConstantUnion->replaceConstantUnion(safeConstantUnion);
2253 }
2254
Jamie Madill7164cf42013-07-08 13:30:59 -04002255 indexedExpression = intermediate.addIndex(EOpIndexDirect, baseExpression, indexExpression, location);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002256 }
2257 }
Jamie Madill7164cf42013-07-08 13:30:59 -04002258 else
2259 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002260 if (baseExpression->isInterfaceBlock())
Jamie Madill7164cf42013-07-08 13:30:59 -04002261 {
Jamie Madill19571812013-08-12 15:26:34 -07002262 error(location, "", "[", "array indexes for interface blocks arrays must be constant integral expressions");
Jamie Madill7164cf42013-07-08 13:30:59 -04002263 recover();
2264 }
Jamie Madill19571812013-08-12 15:26:34 -07002265 else if (baseExpression->getQualifier() == EvqFragmentOut)
Jamie Madill7164cf42013-07-08 13:30:59 -04002266 {
Jamie Madill19571812013-08-12 15:26:34 -07002267 error(location, "", "[", "array indexes for fragment outputs must be constant integral expressions");
Jamie Madill7164cf42013-07-08 13:30:59 -04002268 recover();
2269 }
2270
2271 indexedExpression = intermediate.addIndex(EOpIndexIndirect, baseExpression, indexExpression, location);
2272 }
2273
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002274 if (indexedExpression == 0)
2275 {
Jamie Madill6ba6ead2015-05-04 14:21:21 -04002276 TConstantUnion *unionArray = new TConstantUnion[1];
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002277 unionArray->setFConst(0.0f);
2278 indexedExpression = intermediate.addConstantUnion(unionArray, TType(EbtFloat, EbpHigh, EvqConst), location);
2279 }
2280 else if (baseExpression->isArray())
2281 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002282 const TType &baseType = baseExpression->getType();
2283 if (baseType.getStruct())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002284 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002285 TType copyOfType(baseType.getStruct());
2286 indexedExpression->setType(copyOfType);
2287 }
2288 else if (baseType.isInterfaceBlock())
2289 {
2290 TType copyOfType(baseType.getInterfaceBlock(), baseType.getQualifier(), baseType.getLayoutQualifier(), 0);
shannonwoods@chromium.orge429ab72013-05-30 00:12:52 +00002291 indexedExpression->setType(copyOfType);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002292 }
2293 else
2294 {
Minmin Gong794e0002015-04-07 18:31:54 -07002295 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqTemporary,
2296 static_cast<unsigned char>(baseExpression->getNominalSize()), static_cast<unsigned char>(baseExpression->getSecondarySize())));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002297 }
2298
2299 if (baseExpression->getType().getQualifier() == EvqConst)
2300 {
2301 indexedExpression->getTypePointer()->setQualifier(EvqConst);
2302 }
2303 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002304 else if (baseExpression->isMatrix())
2305 {
Jamie Madill7164cf42013-07-08 13:30:59 -04002306 TQualifier qualifier = baseExpression->getType().getQualifier() == EvqConst ? EvqConst : EvqTemporary;
Minmin Gong794e0002015-04-07 18:31:54 -07002307 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), qualifier, static_cast<unsigned char>(baseExpression->getRows())));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002308 }
2309 else if (baseExpression->isVector())
2310 {
Jamie Madill7164cf42013-07-08 13:30:59 -04002311 TQualifier qualifier = baseExpression->getType().getQualifier() == EvqConst ? EvqConst : EvqTemporary;
2312 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), qualifier));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002313 }
2314 else
2315 {
2316 indexedExpression->setType(baseExpression->getType());
2317 }
2318
2319 return indexedExpression;
2320}
2321
Jamie Madill075edd82013-07-08 13:30:19 -04002322TIntermTyped* TParseContext::addFieldSelectionExpression(TIntermTyped *baseExpression, const TSourceLoc& dotLocation, const TString &fieldString, const TSourceLoc& fieldLocation)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002323{
2324 TIntermTyped *indexedExpression = NULL;
2325
2326 if (baseExpression->isArray())
2327 {
2328 error(fieldLocation, "cannot apply dot operator to an array", ".");
2329 recover();
2330 }
2331
2332 if (baseExpression->isVector())
2333 {
2334 TVectorFields fields;
2335 if (!parseVectorFields(fieldString, baseExpression->getNominalSize(), fields, fieldLocation))
2336 {
2337 fields.num = 1;
2338 fields.offsets[0] = 0;
2339 recover();
2340 }
2341
2342 if (baseExpression->getType().getQualifier() == EvqConst)
2343 {
2344 // constant folding for vector fields
2345 indexedExpression = addConstVectorNode(fields, baseExpression, fieldLocation);
2346 if (indexedExpression == 0)
2347 {
2348 recover();
2349 indexedExpression = baseExpression;
2350 }
2351 else
2352 {
Minmin Gong794e0002015-04-07 18:31:54 -07002353 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqConst, (unsigned char) (fieldString).size()));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002354 }
2355 }
2356 else
2357 {
2358 TString vectorString = fieldString;
2359 TIntermTyped* index = intermediate.addSwizzle(fields, fieldLocation);
2360 indexedExpression = intermediate.addIndex(EOpVectorSwizzle, baseExpression, index, dotLocation);
Minmin Gong794e0002015-04-07 18:31:54 -07002361 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqTemporary, (unsigned char) vectorString.size()));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002362 }
2363 }
2364 else if (baseExpression->isMatrix())
2365 {
2366 TMatrixFields fields;
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00002367 if (!parseMatrixFields(fieldString, baseExpression->getCols(), baseExpression->getRows(), fields, fieldLocation))
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002368 {
2369 fields.wholeRow = false;
2370 fields.wholeCol = false;
2371 fields.row = 0;
2372 fields.col = 0;
2373 recover();
2374 }
2375
2376 if (fields.wholeRow || fields.wholeCol)
2377 {
2378 error(dotLocation, " non-scalar fields not implemented yet", ".");
2379 recover();
Jamie Madill6ba6ead2015-05-04 14:21:21 -04002380 TConstantUnion *unionArray = new TConstantUnion[1];
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002381 unionArray->setIConst(0);
2382 TIntermTyped* index = intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), fieldLocation);
2383 indexedExpression = intermediate.addIndex(EOpIndexDirect, baseExpression, index, dotLocation);
Minmin Gong794e0002015-04-07 18:31:54 -07002384 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(),EvqTemporary,
2385 static_cast<unsigned char>(baseExpression->getCols()), static_cast<unsigned char>(baseExpression->getRows())));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002386 }
2387 else
2388 {
Jamie Madill6ba6ead2015-05-04 14:21:21 -04002389 TConstantUnion *unionArray = new TConstantUnion[1];
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00002390 unionArray->setIConst(fields.col * baseExpression->getRows() + fields.row);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002391 TIntermTyped* index = intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), fieldLocation);
2392 indexedExpression = intermediate.addIndex(EOpIndexDirect, baseExpression, index, dotLocation);
2393 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision()));
2394 }
2395 }
2396 else if (baseExpression->getBasicType() == EbtStruct)
2397 {
2398 bool fieldFound = false;
Jamie Madill98493dd2013-07-08 14:39:03 -04002399 const TFieldList& fields = baseExpression->getType().getStruct()->fields();
2400 if (fields.empty())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002401 {
2402 error(dotLocation, "structure has no fields", "Internal Error");
2403 recover();
2404 indexedExpression = baseExpression;
2405 }
2406 else
2407 {
2408 unsigned int i;
Jamie Madill98493dd2013-07-08 14:39:03 -04002409 for (i = 0; i < fields.size(); ++i)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002410 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002411 if (fields[i]->name() == fieldString)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002412 {
2413 fieldFound = true;
2414 break;
2415 }
2416 }
2417 if (fieldFound)
2418 {
2419 if (baseExpression->getType().getQualifier() == EvqConst)
2420 {
2421 indexedExpression = addConstStruct(fieldString, baseExpression, dotLocation);
2422 if (indexedExpression == 0)
2423 {
2424 recover();
2425 indexedExpression = baseExpression;
2426 }
2427 else
2428 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002429 indexedExpression->setType(*fields[i]->type());
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002430 // change the qualifier of the return type, not of the structure field
2431 // as the structure definition is shared between various structures.
2432 indexedExpression->getTypePointer()->setQualifier(EvqConst);
2433 }
2434 }
2435 else
2436 {
Jamie Madill6ba6ead2015-05-04 14:21:21 -04002437 TConstantUnion *unionArray = new TConstantUnion[1];
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002438 unionArray->setIConst(i);
Jamie Madill98493dd2013-07-08 14:39:03 -04002439 TIntermTyped* index = intermediate.addConstantUnion(unionArray, *fields[i]->type(), fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002440 indexedExpression = intermediate.addIndex(EOpIndexDirectStruct, baseExpression, index, dotLocation);
Jamie Madill98493dd2013-07-08 14:39:03 -04002441 indexedExpression->setType(*fields[i]->type());
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002442 }
2443 }
2444 else
2445 {
2446 error(dotLocation, " no such field in structure", fieldString.c_str());
2447 recover();
2448 indexedExpression = baseExpression;
2449 }
2450 }
2451 }
Jamie Madill98493dd2013-07-08 14:39:03 -04002452 else if (baseExpression->isInterfaceBlock())
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002453 {
2454 bool fieldFound = false;
Jamie Madill98493dd2013-07-08 14:39:03 -04002455 const TFieldList& fields = baseExpression->getType().getInterfaceBlock()->fields();
2456 if (fields.empty())
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002457 {
2458 error(dotLocation, "interface block has no fields", "Internal Error");
2459 recover();
2460 indexedExpression = baseExpression;
2461 }
2462 else
2463 {
2464 unsigned int i;
Jamie Madill98493dd2013-07-08 14:39:03 -04002465 for (i = 0; i < fields.size(); ++i)
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002466 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002467 if (fields[i]->name() == fieldString)
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002468 {
2469 fieldFound = true;
2470 break;
2471 }
2472 }
2473 if (fieldFound)
2474 {
Jamie Madill6ba6ead2015-05-04 14:21:21 -04002475 TConstantUnion *unionArray = new TConstantUnion[1];
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002476 unionArray->setIConst(i);
Jamie Madill98493dd2013-07-08 14:39:03 -04002477 TIntermTyped* index = intermediate.addConstantUnion(unionArray, *fields[i]->type(), fieldLocation);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002478 indexedExpression = intermediate.addIndex(EOpIndexDirectInterfaceBlock, baseExpression, index, dotLocation);
Jamie Madill98493dd2013-07-08 14:39:03 -04002479 indexedExpression->setType(*fields[i]->type());
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002480 }
2481 else
2482 {
2483 error(dotLocation, " no such field in interface block", fieldString.c_str());
2484 recover();
2485 indexedExpression = baseExpression;
2486 }
2487 }
2488 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002489 else
2490 {
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002491 if (shaderVersion < 300)
2492 {
2493 error(dotLocation, " field selection requires structure, vector, or matrix on left hand side", fieldString.c_str());
2494 }
2495 else
2496 {
2497 error(dotLocation, " field selection requires structure, vector, matrix, or interface block on left hand side", fieldString.c_str());
2498 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002499 recover();
2500 indexedExpression = baseExpression;
2501 }
2502
2503 return indexedExpression;
2504}
2505
Jamie Madill075edd82013-07-08 13:30:19 -04002506TLayoutQualifier TParseContext::parseLayoutQualifier(const TString &qualifierType, const TSourceLoc& qualifierTypeLine)
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002507{
Jamie Madilla5efff92013-06-06 11:56:47 -04002508 TLayoutQualifier qualifier;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002509
Jamie Madilla5efff92013-06-06 11:56:47 -04002510 qualifier.location = -1;
2511 qualifier.matrixPacking = EmpUnspecified;
2512 qualifier.blockStorage = EbsUnspecified;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002513
2514 if (qualifierType == "shared")
2515 {
Jamie Madilla5efff92013-06-06 11:56:47 -04002516 qualifier.blockStorage = EbsShared;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002517 }
2518 else if (qualifierType == "packed")
2519 {
Jamie Madilla5efff92013-06-06 11:56:47 -04002520 qualifier.blockStorage = EbsPacked;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002521 }
2522 else if (qualifierType == "std140")
2523 {
Jamie Madilla5efff92013-06-06 11:56:47 -04002524 qualifier.blockStorage = EbsStd140;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002525 }
2526 else if (qualifierType == "row_major")
2527 {
Jamie Madilla5efff92013-06-06 11:56:47 -04002528 qualifier.matrixPacking = EmpRowMajor;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002529 }
2530 else if (qualifierType == "column_major")
2531 {
Jamie Madilla5efff92013-06-06 11:56:47 -04002532 qualifier.matrixPacking = EmpColumnMajor;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002533 }
2534 else if (qualifierType == "location")
2535 {
2536 error(qualifierTypeLine, "invalid layout qualifier", qualifierType.c_str(), "location requires an argument");
2537 recover();
2538 }
2539 else
2540 {
2541 error(qualifierTypeLine, "invalid layout qualifier", qualifierType.c_str());
2542 recover();
2543 }
2544
Jamie Madilla5efff92013-06-06 11:56:47 -04002545 return qualifier;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002546}
2547
Jamie Madill075edd82013-07-08 13:30:19 -04002548TLayoutQualifier TParseContext::parseLayoutQualifier(const TString &qualifierType, const TSourceLoc& qualifierTypeLine, const TString &intValueString, int intValue, const TSourceLoc& intValueLine)
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002549{
Jamie Madilla5efff92013-06-06 11:56:47 -04002550 TLayoutQualifier qualifier;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002551
Jamie Madilla5efff92013-06-06 11:56:47 -04002552 qualifier.location = -1;
2553 qualifier.matrixPacking = EmpUnspecified;
2554 qualifier.blockStorage = EbsUnspecified;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002555
2556 if (qualifierType != "location")
2557 {
2558 error(qualifierTypeLine, "invalid layout qualifier", qualifierType.c_str(), "only location may have arguments");
2559 recover();
2560 }
2561 else
2562 {
Jamie Madill05a80ce2013-06-20 11:55:49 -04002563 // must check that location is non-negative
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002564 if (intValue < 0)
2565 {
Jamie Madill05a80ce2013-06-20 11:55:49 -04002566 error(intValueLine, "out of range:", intValueString.c_str(), "location must be non-negative");
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002567 recover();
2568 }
2569 else
2570 {
Jamie Madilla5efff92013-06-06 11:56:47 -04002571 qualifier.location = intValue;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002572 }
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002573 }
2574
Jamie Madilla5efff92013-06-06 11:56:47 -04002575 return qualifier;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002576}
2577
Jamie Madilla5efff92013-06-06 11:56:47 -04002578TLayoutQualifier TParseContext::joinLayoutQualifiers(TLayoutQualifier leftQualifier, TLayoutQualifier rightQualifier)
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002579{
Jamie Madilla5efff92013-06-06 11:56:47 -04002580 TLayoutQualifier joinedQualifier = leftQualifier;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002581
Jamie Madilla5efff92013-06-06 11:56:47 -04002582 if (rightQualifier.location != -1)
2583 {
2584 joinedQualifier.location = rightQualifier.location;
2585 }
2586 if (rightQualifier.matrixPacking != EmpUnspecified)
2587 {
2588 joinedQualifier.matrixPacking = rightQualifier.matrixPacking;
2589 }
2590 if (rightQualifier.blockStorage != EbsUnspecified)
2591 {
2592 joinedQualifier.blockStorage = rightQualifier.blockStorage;
2593 }
2594
2595 return joinedQualifier;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002596}
2597
Jamie Madillf2e0f9b2013-08-26 16:39:42 -04002598TPublicType TParseContext::joinInterpolationQualifiers(const TSourceLoc &interpolationLoc, TQualifier interpolationQualifier,
2599 const TSourceLoc &storageLoc, TQualifier storageQualifier)
2600{
2601 TQualifier mergedQualifier = EvqSmoothIn;
2602
Jamie Madill19571812013-08-12 15:26:34 -07002603 if (storageQualifier == EvqFragmentIn) {
Jamie Madillf2e0f9b2013-08-26 16:39:42 -04002604 if (interpolationQualifier == EvqSmooth)
2605 mergedQualifier = EvqSmoothIn;
2606 else if (interpolationQualifier == EvqFlat)
2607 mergedQualifier = EvqFlatIn;
2608 else UNREACHABLE();
2609 }
2610 else if (storageQualifier == EvqCentroidIn) {
2611 if (interpolationQualifier == EvqSmooth)
2612 mergedQualifier = EvqCentroidIn;
2613 else if (interpolationQualifier == EvqFlat)
2614 mergedQualifier = EvqFlatIn;
2615 else UNREACHABLE();
2616 }
Jamie Madill19571812013-08-12 15:26:34 -07002617 else if (storageQualifier == EvqVertexOut) {
Jamie Madillf2e0f9b2013-08-26 16:39:42 -04002618 if (interpolationQualifier == EvqSmooth)
2619 mergedQualifier = EvqSmoothOut;
2620 else if (interpolationQualifier == EvqFlat)
2621 mergedQualifier = EvqFlatOut;
2622 else UNREACHABLE();
2623 }
2624 else if (storageQualifier == EvqCentroidOut) {
2625 if (interpolationQualifier == EvqSmooth)
2626 mergedQualifier = EvqCentroidOut;
2627 else if (interpolationQualifier == EvqFlat)
2628 mergedQualifier = EvqFlatOut;
2629 else UNREACHABLE();
2630 }
2631 else {
2632 error(interpolationLoc, "interpolation qualifier requires a fragment 'in' or vertex 'out' storage qualifier", getInterpolationString(interpolationQualifier));
2633 recover();
2634
2635 mergedQualifier = storageQualifier;
2636 }
2637
2638 TPublicType type;
2639 type.setBasic(EbtVoid, mergedQualifier, storageLoc);
2640 return type;
2641}
2642
Jamie Madill98493dd2013-07-08 14:39:03 -04002643TFieldList *TParseContext::addStructDeclaratorList(const TPublicType& typeSpecifier, TFieldList *fieldList)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002644{
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +03002645 if (voidErrorCheck(typeSpecifier.line, (*fieldList)[0]->name(), typeSpecifier.type))
2646 {
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002647 recover();
2648 }
2649
Jamie Madill98493dd2013-07-08 14:39:03 -04002650 for (unsigned int i = 0; i < fieldList->size(); ++i) {
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002651 //
2652 // Careful not to replace already known aspects of type, like array-ness
2653 //
Jamie Madill98493dd2013-07-08 14:39:03 -04002654 TType* type = (*fieldList)[i]->type();
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002655 type->setBasicType(typeSpecifier.type);
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00002656 type->setPrimarySize(typeSpecifier.primarySize);
2657 type->setSecondarySize(typeSpecifier.secondarySize);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002658 type->setPrecision(typeSpecifier.precision);
2659 type->setQualifier(typeSpecifier.qualifier);
Jamie Madilla5efff92013-06-06 11:56:47 -04002660 type->setLayoutQualifier(typeSpecifier.layoutQualifier);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002661
2662 // don't allow arrays of arrays
2663 if (type->isArray()) {
2664 if (arrayTypeErrorCheck(typeSpecifier.line, typeSpecifier))
2665 recover();
2666 }
2667 if (typeSpecifier.array)
2668 type->setArraySize(typeSpecifier.arraySize);
2669 if (typeSpecifier.userDef) {
2670 type->setStruct(typeSpecifier.userDef->getStruct());
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002671 }
2672
Jamie Madill98493dd2013-07-08 14:39:03 -04002673 if (structNestingErrorCheck(typeSpecifier.line, *(*fieldList)[i])) {
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002674 recover();
2675 }
2676 }
2677
Jamie Madill98493dd2013-07-08 14:39:03 -04002678 return fieldList;
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002679}
2680
Jamie Madill98493dd2013-07-08 14:39:03 -04002681TPublicType TParseContext::addStructure(const TSourceLoc& structLine, const TSourceLoc& nameLine, const TString *structName, TFieldList* fieldList)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002682{
Jamie Madill98493dd2013-07-08 14:39:03 -04002683 TStructure* structure = new TStructure(structName, fieldList);
2684 TType* structureType = new TType(structure);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002685
Jamie Madill9b820842015-02-12 10:40:10 -05002686 // Store a bool in the struct if we're at global scope, to allow us to
2687 // skip the local struct scoping workaround in HLSL.
Jamie Madillb960cc42015-02-12 15:33:20 +00002688 structure->setUniqueId(TSymbolTable::nextUniqueId());
Jamie Madill9b820842015-02-12 10:40:10 -05002689 structure->setAtGlobalScope(symbolTable.atGlobalLevel());
Jamie Madillbfa91f42014-06-05 15:45:18 -04002690
Jamie Madill98493dd2013-07-08 14:39:03 -04002691 if (!structName->empty())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002692 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002693 if (reservedErrorCheck(nameLine, *structName))
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002694 {
2695 recover();
2696 }
Jamie Madill98493dd2013-07-08 14:39:03 -04002697 TVariable* userTypeDef = new TVariable(structName, *structureType, true);
Nicolas Capensadfffe42014-06-17 02:13:36 -04002698 if (!symbolTable.declare(userTypeDef)) {
Jamie Madill98493dd2013-07-08 14:39:03 -04002699 error(nameLine, "redefinition", structName->c_str(), "struct");
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002700 recover();
2701 }
2702 }
2703
2704 // ensure we do not specify any storage qualifiers on the struct members
Jamie Madill98493dd2013-07-08 14:39:03 -04002705 for (unsigned int typeListIndex = 0; typeListIndex < fieldList->size(); typeListIndex++)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002706 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002707 const TField &field = *(*fieldList)[typeListIndex];
2708 const TQualifier qualifier = field.type()->getQualifier();
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002709 switch (qualifier)
2710 {
2711 case EvqGlobal:
2712 case EvqTemporary:
2713 break;
2714 default:
Jamie Madill98493dd2013-07-08 14:39:03 -04002715 error(field.line(), "invalid qualifier on struct member", getQualifierString(qualifier));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002716 recover();
2717 break;
2718 }
2719 }
2720
2721 TPublicType publicType;
2722 publicType.setBasic(EbtStruct, EvqTemporary, structLine);
Jamie Madill98493dd2013-07-08 14:39:03 -04002723 publicType.userDef = structureType;
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002724 exitStructDeclaration();
2725
2726 return publicType;
2727}
2728
Olli Etuahoa3a36662015-02-17 13:46:51 +02002729TIntermSwitch *TParseContext::addSwitch(TIntermTyped *init, TIntermAggregate *statementList, const TSourceLoc &loc)
2730{
Olli Etuaho53f076f2015-02-20 10:55:14 +02002731 TBasicType switchType = init->getBasicType();
2732 if ((switchType != EbtInt && switchType != EbtUInt) ||
2733 init->isMatrix() ||
2734 init->isArray() ||
2735 init->isVector())
2736 {
2737 error(init->getLine(), "init-expression in a switch statement must be a scalar integer", "switch");
2738 recover();
2739 return nullptr;
2740 }
2741
Olli Etuahoac5274d2015-02-20 10:19:08 +02002742 if (statementList)
2743 {
2744 if (!ValidateSwitch::validate(switchType, this, statementList, loc))
2745 {
2746 recover();
2747 return nullptr;
2748 }
2749 }
2750
Olli Etuahoa3a36662015-02-17 13:46:51 +02002751 TIntermSwitch *node = intermediate.addSwitch(init, statementList, loc);
2752 if (node == nullptr)
2753 {
2754 error(loc, "erroneous switch statement", "switch");
2755 recover();
2756 return nullptr;
2757 }
2758 return node;
2759}
2760
2761TIntermCase *TParseContext::addCase(TIntermTyped *condition, const TSourceLoc &loc)
2762{
Olli Etuaho53f076f2015-02-20 10:55:14 +02002763 if (mSwitchNestingLevel == 0)
2764 {
2765 error(loc, "case labels need to be inside switch statements", "case");
2766 recover();
2767 return nullptr;
2768 }
2769 if (condition == nullptr)
2770 {
2771 error(loc, "case label must have a condition", "case");
2772 recover();
2773 return nullptr;
2774 }
2775 if ((condition->getBasicType() != EbtInt && condition->getBasicType() != EbtUInt) ||
2776 condition->isMatrix() ||
2777 condition->isArray() ||
2778 condition->isVector())
2779 {
2780 error(condition->getLine(), "case label must be a scalar integer", "case");
2781 recover();
2782 }
2783 TIntermConstantUnion *conditionConst = condition->getAsConstantUnion();
2784 if (conditionConst == nullptr)
2785 {
2786 error(condition->getLine(), "case label must be constant", "case");
2787 recover();
2788 }
Olli Etuahoa3a36662015-02-17 13:46:51 +02002789 TIntermCase *node = intermediate.addCase(condition, loc);
2790 if (node == nullptr)
2791 {
2792 error(loc, "erroneous case statement", "case");
2793 recover();
2794 return nullptr;
2795 }
2796 return node;
2797}
2798
2799TIntermCase *TParseContext::addDefault(const TSourceLoc &loc)
2800{
Olli Etuaho53f076f2015-02-20 10:55:14 +02002801 if (mSwitchNestingLevel == 0)
2802 {
2803 error(loc, "default labels need to be inside switch statements", "default");
2804 recover();
2805 return nullptr;
2806 }
Olli Etuahoa3a36662015-02-17 13:46:51 +02002807 TIntermCase *node = intermediate.addCase(nullptr, loc);
2808 if (node == nullptr)
2809 {
2810 error(loc, "erroneous default statement", "default");
2811 recover();
2812 return nullptr;
2813 }
2814 return node;
2815}
2816
Olli Etuahof6c694b2015-03-26 14:50:53 +02002817TIntermTyped *TParseContext::createUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc,
2818 const TType *funcReturnType)
Olli Etuaho69c11b52015-03-26 12:59:00 +02002819{
2820 if (child == nullptr)
2821 {
2822 return nullptr;
2823 }
2824
2825 switch (op)
2826 {
2827 case EOpLogicalNot:
2828 if (child->getBasicType() != EbtBool ||
2829 child->isMatrix() ||
2830 child->isArray() ||
2831 child->isVector())
2832 {
2833 return nullptr;
2834 }
2835 break;
2836 case EOpBitwiseNot:
2837 if ((child->getBasicType() != EbtInt && child->getBasicType() != EbtUInt) ||
2838 child->isMatrix() ||
2839 child->isArray())
2840 {
2841 return nullptr;
2842 }
2843 break;
2844 case EOpPostIncrement:
2845 case EOpPreIncrement:
2846 case EOpPostDecrement:
2847 case EOpPreDecrement:
2848 case EOpNegative:
2849 case EOpPositive:
2850 if (child->getBasicType() == EbtStruct ||
Olli Etuahodca3e792015-03-26 13:24:04 +02002851 child->getBasicType() == EbtBool ||
Olli Etuaho69c11b52015-03-26 12:59:00 +02002852 child->isArray())
2853 {
2854 return nullptr;
2855 }
Olli Etuahodca3e792015-03-26 13:24:04 +02002856 // Operators for built-ins are already type checked against their prototype.
Olli Etuaho69c11b52015-03-26 12:59:00 +02002857 default:
2858 break;
2859 }
2860
Olli Etuahof6c694b2015-03-26 14:50:53 +02002861 return intermediate.addUnaryMath(op, child, loc, funcReturnType);
Olli Etuaho69c11b52015-03-26 12:59:00 +02002862}
2863
Olli Etuaho09b22472015-02-11 11:47:26 +02002864TIntermTyped *TParseContext::addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc)
2865{
Olli Etuahof6c694b2015-03-26 14:50:53 +02002866 TIntermTyped *node = createUnaryMath(op, child, loc, nullptr);
Olli Etuaho69c11b52015-03-26 12:59:00 +02002867 if (node == nullptr)
Olli Etuaho09b22472015-02-11 11:47:26 +02002868 {
2869 unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
2870 recover();
2871 return child;
2872 }
2873 return node;
2874}
2875
2876TIntermTyped *TParseContext::addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc)
2877{
2878 if (lValueErrorCheck(loc, GetOperatorString(op), child))
2879 recover();
2880 return addUnaryMath(op, child, loc);
2881}
2882
Olli Etuaho47fd36a2015-03-19 14:22:24 +02002883bool TParseContext::binaryOpCommonCheck(TOperator op, TIntermTyped *left, TIntermTyped *right,
Olli Etuahod6b14282015-03-17 14:31:35 +02002884 const TSourceLoc &loc)
2885{
2886 if (left->isArray() || right->isArray())
2887 {
Olli Etuahoe79904c2015-03-18 16:56:42 +02002888 if (shaderVersion < 300)
2889 {
2890 error(loc, "Invalid operation for arrays", GetOperatorString(op));
2891 return false;
2892 }
2893
2894 if (left->isArray() != right->isArray())
2895 {
2896 error(loc, "array / non-array mismatch", GetOperatorString(op));
2897 return false;
2898 }
2899
2900 switch (op)
2901 {
2902 case EOpEqual:
2903 case EOpNotEqual:
2904 case EOpAssign:
2905 case EOpInitialize:
2906 break;
2907 default:
2908 error(loc, "Invalid operation for arrays", GetOperatorString(op));
2909 return false;
2910 }
Olli Etuaho376f1b52015-04-13 13:23:41 +03002911 // At this point, size of implicitly sized arrays should be resolved.
Olli Etuahoe79904c2015-03-18 16:56:42 +02002912 if (left->getArraySize() != right->getArraySize())
2913 {
2914 error(loc, "array size mismatch", GetOperatorString(op));
2915 return false;
2916 }
Olli Etuahod6b14282015-03-17 14:31:35 +02002917 }
Olli Etuaho47fd36a2015-03-19 14:22:24 +02002918
2919 // Check ops which require integer / ivec parameters
2920 bool isBitShift = false;
2921 switch (op)
2922 {
2923 case EOpBitShiftLeft:
2924 case EOpBitShiftRight:
2925 case EOpBitShiftLeftAssign:
2926 case EOpBitShiftRightAssign:
2927 // Unsigned can be bit-shifted by signed and vice versa, but we need to
2928 // check that the basic type is an integer type.
2929 isBitShift = true;
2930 if (!IsInteger(left->getBasicType()) || !IsInteger(right->getBasicType()))
2931 {
2932 return false;
2933 }
2934 break;
2935 case EOpBitwiseAnd:
2936 case EOpBitwiseXor:
2937 case EOpBitwiseOr:
2938 case EOpBitwiseAndAssign:
2939 case EOpBitwiseXorAssign:
2940 case EOpBitwiseOrAssign:
2941 // It is enough to check the type of only one operand, since later it
2942 // is checked that the operand types match.
2943 if (!IsInteger(left->getBasicType()))
2944 {
2945 return false;
2946 }
2947 break;
2948 default:
2949 break;
2950 }
2951
2952 // GLSL ES 1.00 and 3.00 do not support implicit type casting.
2953 // So the basic type should usually match.
2954 if (!isBitShift && left->getBasicType() != right->getBasicType())
2955 {
2956 return false;
2957 }
2958
Olli Etuaho9dd217b2015-03-20 14:24:31 +02002959 // Check that type sizes match exactly on ops that require that.
Olli Etuahoff699002015-03-23 14:38:42 +02002960 // Also check restrictions for structs that contain arrays or samplers.
Olli Etuaho47fd36a2015-03-19 14:22:24 +02002961 switch(op)
2962 {
2963 case EOpAssign:
2964 case EOpInitialize:
2965 case EOpEqual:
2966 case EOpNotEqual:
Olli Etuaho9dd217b2015-03-20 14:24:31 +02002967 // ESSL 1.00 sections 5.7, 5.8, 5.9
2968 if (shaderVersion < 300 && left->getType().isStructureContainingArrays())
2969 {
2970 error(loc, "undefined operation for structs containing arrays", GetOperatorString(op));
2971 return false;
2972 }
Olli Etuahoff699002015-03-23 14:38:42 +02002973 // Samplers as l-values are disallowed also in ESSL 3.00, see section 4.1.7,
2974 // we interpret the spec so that this extends to structs containing samplers,
2975 // similarly to ESSL 1.00 spec.
2976 if ((shaderVersion < 300 || op == EOpAssign || op == EOpInitialize) &&
2977 left->getType().isStructureContainingSamplers())
2978 {
2979 error(loc, "undefined operation for structs containing samplers", GetOperatorString(op));
2980 return false;
2981 }
Olli Etuaho47fd36a2015-03-19 14:22:24 +02002982 case EOpLessThan:
2983 case EOpGreaterThan:
2984 case EOpLessThanEqual:
2985 case EOpGreaterThanEqual:
2986 if ((left->getNominalSize() != right->getNominalSize()) ||
2987 (left->getSecondarySize() != right->getSecondarySize()))
2988 {
2989 return false;
2990 }
2991 default:
2992 break;
2993 }
2994
Olli Etuahod6b14282015-03-17 14:31:35 +02002995 return true;
2996}
2997
Olli Etuahofc1806e2015-03-17 13:03:11 +02002998TIntermTyped *TParseContext::addBinaryMathInternal(TOperator op, TIntermTyped *left, TIntermTyped *right,
2999 const TSourceLoc &loc)
3000{
Olli Etuaho47fd36a2015-03-19 14:22:24 +02003001 if (!binaryOpCommonCheck(op, left, right, loc))
Olli Etuahod6b14282015-03-17 14:31:35 +02003002 return nullptr;
3003
Olli Etuahofc1806e2015-03-17 13:03:11 +02003004 switch (op)
3005 {
3006 case EOpEqual:
3007 case EOpNotEqual:
Olli Etuahofc1806e2015-03-17 13:03:11 +02003008 break;
3009 case EOpLessThan:
3010 case EOpGreaterThan:
3011 case EOpLessThanEqual:
3012 case EOpGreaterThanEqual:
Olli Etuahod6b14282015-03-17 14:31:35 +02003013 ASSERT(!left->isArray() && !right->isArray());
3014 if (left->isMatrix() || left->isVector() ||
Olli Etuahofc1806e2015-03-17 13:03:11 +02003015 left->getBasicType() == EbtStruct)
3016 {
3017 return nullptr;
3018 }
3019 break;
3020 case EOpLogicalOr:
3021 case EOpLogicalXor:
3022 case EOpLogicalAnd:
Olli Etuahod6b14282015-03-17 14:31:35 +02003023 ASSERT(!left->isArray() && !right->isArray());
Olli Etuahofc1806e2015-03-17 13:03:11 +02003024 if (left->getBasicType() != EbtBool ||
Olli Etuahod6b14282015-03-17 14:31:35 +02003025 left->isMatrix() || left->isVector())
Olli Etuahofc1806e2015-03-17 13:03:11 +02003026 {
3027 return nullptr;
3028 }
3029 break;
3030 case EOpAdd:
3031 case EOpSub:
3032 case EOpDiv:
3033 case EOpMul:
Olli Etuahod6b14282015-03-17 14:31:35 +02003034 ASSERT(!left->isArray() && !right->isArray());
Olli Etuahofc1806e2015-03-17 13:03:11 +02003035 if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool)
3036 {
3037 return nullptr;
3038 }
3039 break;
3040 case EOpIMod:
Olli Etuahod6b14282015-03-17 14:31:35 +02003041 ASSERT(!left->isArray() && !right->isArray());
Olli Etuahofc1806e2015-03-17 13:03:11 +02003042 // Note that this is only for the % operator, not for mod()
3043 if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool || left->getBasicType() == EbtFloat)
3044 {
3045 return nullptr;
3046 }
3047 break;
3048 // Note that for bitwise ops, type checking is done in promote() to
3049 // share code between ops and compound assignment
3050 default:
3051 break;
3052 }
3053
Olli Etuahofc1806e2015-03-17 13:03:11 +02003054 return intermediate.addBinaryMath(op, left, right, loc);
3055}
3056
Olli Etuaho09b22472015-02-11 11:47:26 +02003057TIntermTyped *TParseContext::addBinaryMath(TOperator op, TIntermTyped *left, TIntermTyped *right,
3058 const TSourceLoc &loc)
3059{
Olli Etuahofc1806e2015-03-17 13:03:11 +02003060 TIntermTyped *node = addBinaryMathInternal(op, left, right, loc);
Olli Etuaho09b22472015-02-11 11:47:26 +02003061 if (node == 0)
3062 {
3063 binaryOpError(loc, GetOperatorString(op), left->getCompleteString(), right->getCompleteString());
3064 recover();
3065 return left;
3066 }
3067 return node;
3068}
3069
3070TIntermTyped *TParseContext::addBinaryMathBooleanResult(TOperator op, TIntermTyped *left, TIntermTyped *right,
3071 const TSourceLoc &loc)
3072{
Olli Etuahofc1806e2015-03-17 13:03:11 +02003073 TIntermTyped *node = addBinaryMathInternal(op, left, right, loc);
Olli Etuaho09b22472015-02-11 11:47:26 +02003074 if (node == 0)
3075 {
3076 binaryOpError(loc, GetOperatorString(op), left->getCompleteString(), right->getCompleteString());
3077 recover();
Jamie Madill6ba6ead2015-05-04 14:21:21 -04003078 TConstantUnion *unionArray = new TConstantUnion[1];
Olli Etuaho09b22472015-02-11 11:47:26 +02003079 unionArray->setBConst(false);
3080 return intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), loc);
3081 }
3082 return node;
3083}
3084
Olli Etuahod6b14282015-03-17 14:31:35 +02003085TIntermTyped *TParseContext::createAssign(TOperator op, TIntermTyped *left, TIntermTyped *right,
3086 const TSourceLoc &loc)
3087{
Olli Etuaho47fd36a2015-03-19 14:22:24 +02003088 if (binaryOpCommonCheck(op, left, right, loc))
Olli Etuahod6b14282015-03-17 14:31:35 +02003089 {
3090 return intermediate.addAssign(op, left, right, loc);
3091 }
3092 return nullptr;
3093}
3094
3095TIntermTyped *TParseContext::addAssign(TOperator op, TIntermTyped *left, TIntermTyped *right,
3096 const TSourceLoc &loc)
3097{
3098 TIntermTyped *node = createAssign(op, left, right, loc);
3099 if (node == nullptr)
3100 {
3101 assignError(loc, "assign", left->getCompleteString(), right->getCompleteString());
3102 recover();
3103 return left;
3104 }
3105 return node;
3106}
3107
Olli Etuaho49300862015-02-20 14:54:49 +02003108TIntermBranch *TParseContext::addBranch(TOperator op, const TSourceLoc &loc)
3109{
3110 switch (op)
3111 {
3112 case EOpContinue:
3113 if (mLoopNestingLevel <= 0)
3114 {
3115 error(loc, "continue statement only allowed in loops", "");
3116 recover();
3117 }
3118 break;
3119 case EOpBreak:
Olli Etuaho53f076f2015-02-20 10:55:14 +02003120 if (mLoopNestingLevel <= 0 && mSwitchNestingLevel <= 0)
Olli Etuaho49300862015-02-20 14:54:49 +02003121 {
Olli Etuaho53f076f2015-02-20 10:55:14 +02003122 error(loc, "break statement only allowed in loops and switch statements", "");
Olli Etuaho49300862015-02-20 14:54:49 +02003123 recover();
3124 }
3125 break;
3126 case EOpReturn:
3127 if (currentFunctionType->getBasicType() != EbtVoid)
3128 {
3129 error(loc, "non-void function must return a value", "return");
3130 recover();
3131 }
3132 break;
3133 default:
3134 // No checks for discard
3135 break;
3136 }
3137 return intermediate.addBranch(op, loc);
3138}
3139
3140TIntermBranch *TParseContext::addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc)
3141{
3142 ASSERT(op == EOpReturn);
3143 mFunctionReturnsValue = true;
3144 if (currentFunctionType->getBasicType() == EbtVoid)
3145 {
3146 error(loc, "void function cannot return a value", "return");
3147 recover();
3148 }
3149 else if (*currentFunctionType != returnValue->getType())
3150 {
3151 error(loc, "function return is not matching type:", "return");
3152 recover();
3153 }
3154 return intermediate.addBranch(op, returnValue, loc);
3155}
3156
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003157TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermNode *paramNode, TIntermNode *thisNode,
3158 const TSourceLoc &loc, bool *fatalError)
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003159{
3160 *fatalError = false;
3161 TOperator op = fnCall->getBuiltInOp();
3162 TIntermTyped *callNode = nullptr;
3163
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003164 if (thisNode != nullptr)
3165 {
Jamie Madill6ba6ead2015-05-04 14:21:21 -04003166 TConstantUnion *unionArray = new TConstantUnion[1];
Olli Etuaho96e67382015-04-23 14:27:02 +03003167 int arraySize = 0;
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003168 TIntermTyped *typedThis = thisNode->getAsTyped();
3169 if (fnCall->getName() != "length")
3170 {
3171 error(loc, "invalid method", fnCall->getName().c_str());
3172 recover();
3173 }
3174 else if (paramNode != nullptr)
3175 {
3176 error(loc, "method takes no parameters", "length");
3177 recover();
3178 }
3179 else if (typedThis == nullptr || !typedThis->isArray())
3180 {
3181 error(loc, "length can only be called on arrays", "length");
3182 recover();
3183 }
3184 else
3185 {
Olli Etuaho96e67382015-04-23 14:27:02 +03003186 arraySize = typedThis->getArraySize();
Olli Etuaho39282e12015-04-23 15:41:48 +03003187 if (typedThis->getAsSymbolNode() == nullptr)
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003188 {
Olli Etuaho39282e12015-04-23 15:41:48 +03003189 // This code path can be hit with expressions like these:
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003190 // (a = b).length()
Olli Etuaho39282e12015-04-23 15:41:48 +03003191 // (func()).length()
3192 // (int[3](0, 1, 2)).length()
3193 // ESSL 3.00 section 5.9 defines expressions so that this is not actually a valid expression.
3194 // It allows "An array name with the length method applied" in contrast to GLSL 4.4 spec section 5.9
3195 // which allows "An array, vector or matrix expression with the length method applied".
3196 error(loc, "length can only be called on array names, not on array expressions", "length");
3197 recover();
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003198 }
3199 }
Olli Etuaho96e67382015-04-23 14:27:02 +03003200 unionArray->setIConst(arraySize);
3201 callNode = intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), loc);
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003202 }
3203 else if (op != EOpNull)
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003204 {
3205 //
3206 // Then this should be a constructor.
3207 // Don't go through the symbol table for constructors.
3208 // Their parameters will be verified algorithmically.
3209 //
3210 TType type(EbtVoid, EbpUndefined); // use this to get the type back
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003211 if (!constructorErrorCheck(loc, paramNode, *fnCall, op, &type))
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003212 {
3213 //
3214 // It's a constructor, of type 'type'.
3215 //
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003216 callNode = addConstructor(paramNode, &type, op, fnCall, loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003217 }
Olli Etuaho72ba85b2015-03-04 14:23:26 +02003218
3219 if (callNode == nullptr)
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003220 {
3221 recover();
3222 callNode = intermediate.setAggregateOperator(nullptr, op, loc);
3223 }
3224 callNode->setType(type);
3225 }
3226 else
3227 {
3228 //
3229 // Not a constructor. Find it in the symbol table.
3230 //
3231 const TFunction* fnCandidate;
3232 bool builtIn;
3233 fnCandidate = findFunction(loc, fnCall, shaderVersion, &builtIn);
3234 if (fnCandidate)
3235 {
3236 //
3237 // A declared function.
3238 //
3239 if (builtIn && !fnCandidate->getExtension().empty() &&
3240 extensionErrorCheck(loc, fnCandidate->getExtension()))
3241 {
3242 recover();
3243 }
3244 op = fnCandidate->getBuiltInOp();
3245 if (builtIn && op != EOpNull)
3246 {
3247 //
3248 // A function call mapped to a built-in operation.
3249 //
3250 if (fnCandidate->getParamCount() == 1)
3251 {
3252 //
3253 // Treat it like a built-in unary operator.
3254 //
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003255 callNode = createUnaryMath(op, paramNode->getAsTyped(), loc, &fnCandidate->getReturnType());
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003256 if (callNode == nullptr)
3257 {
3258 std::stringstream extraInfoStream;
3259 extraInfoStream << "built in unary operator function. Type: "
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003260 << static_cast<TIntermTyped*>(paramNode)->getCompleteString();
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003261 std::string extraInfo = extraInfoStream.str();
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003262 error(paramNode->getLine(), " wrong operand type", "Internal Error", extraInfo.c_str());
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003263 *fatalError = true;
3264 return nullptr;
3265 }
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003266 }
3267 else
3268 {
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003269 TIntermAggregate *aggregate = intermediate.setAggregateOperator(paramNode, op, loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003270 aggregate->setType(fnCandidate->getReturnType());
3271 aggregate->setPrecisionFromChildren();
3272 callNode = aggregate;
3273
3274 // Some built-in functions have out parameters too.
3275 functionCallLValueErrorCheck(fnCandidate, aggregate);
3276 }
3277 }
3278 else
3279 {
3280 // This is a real function call
3281
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003282 TIntermAggregate *aggregate = intermediate.setAggregateOperator(paramNode, EOpFunctionCall, loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003283 aggregate->setType(fnCandidate->getReturnType());
3284
3285 // this is how we know whether the given function is a builtIn function or a user defined function
3286 // if builtIn == false, it's a userDefined -> could be an overloaded builtIn function also
3287 // if builtIn == true, it's definitely a builtIn function with EOpNull
3288 if (!builtIn)
3289 aggregate->setUserDefined();
3290 aggregate->setName(fnCandidate->getMangledName());
Corentin Wallez71d147f2015-02-11 11:15:24 -08003291 aggregate->setFunctionId(fnCandidate->getUniqueId());
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003292
3293 // This needs to happen after the name is set
3294 if (builtIn)
3295 aggregate->setBuiltInFunctionPrecision();
3296
3297 callNode = aggregate;
3298
3299 functionCallLValueErrorCheck(fnCandidate, aggregate);
3300 }
3301 }
3302 else
3303 {
3304 // error message was put out by findFunction()
3305 // Put on a dummy node for error recovery
Jamie Madill6ba6ead2015-05-04 14:21:21 -04003306 TConstantUnion *unionArray = new TConstantUnion[1];
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003307 unionArray->setFConst(0.0f);
3308 callNode = intermediate.addConstantUnion(unionArray, TType(EbtFloat, EbpUndefined, EvqConst), loc);
3309 recover();
3310 }
3311 }
3312 delete fnCall;
3313 return callNode;
3314}
3315
Olli Etuaho52901742015-04-15 13:42:45 +03003316TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock,
3317 const TSourceLoc &loc)
3318{
3319 if (boolErrorCheck(loc, cond))
3320 recover();
3321
3322 if (trueBlock->getType() != falseBlock->getType())
3323 {
3324 binaryOpError(loc, ":", trueBlock->getCompleteString(), falseBlock->getCompleteString());
3325 recover();
3326 return falseBlock;
3327 }
Olli Etuahoa2d53032015-04-15 14:14:44 +03003328 // ESSL1 sections 5.2 and 5.7:
3329 // ESSL3 section 5.7:
3330 // Ternary operator is not among the operators allowed for structures/arrays.
3331 if (trueBlock->isArray() || trueBlock->getBasicType() == EbtStruct)
3332 {
3333 error(loc, "ternary operator is not allowed for structures or arrays", ":");
3334 recover();
3335 return falseBlock;
3336 }
Olli Etuaho52901742015-04-15 13:42:45 +03003337 return intermediate.addSelection(cond, trueBlock, falseBlock, loc);
3338}
Olli Etuaho49300862015-02-20 14:54:49 +02003339
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003340//
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00003341// Parse an array of strings using yyparse.
3342//
3343// Returns 0 for success.
3344//
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +00003345int PaParseStrings(size_t count, const char* const string[], const int length[],
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00003346 TParseContext* context) {
3347 if ((count == 0) || (string == NULL))
3348 return 1;
3349
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00003350 if (glslang_initialize(context))
3351 return 1;
3352
alokp@chromium.org408c45e2012-04-05 15:54:43 +00003353 int error = glslang_scan(count, string, length, context);
3354 if (!error)
3355 error = glslang_parse(context);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00003356
alokp@chromium.org73bc2982012-06-19 18:48:05 +00003357 glslang_finalize(context);
alokp@chromium.org8b851c62012-06-15 16:25:11 +00003358
alokp@chromium.org6b495712012-06-29 00:06:58 +00003359 return (error == 0) && (context->numErrors() == 0) ? 0 : 1;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00003360}
3361
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003362
alokp@chromium.org34b99cd2010-07-27 18:37:55 +00003363