blob: 46701df573de8b835b4199d2377bf165c8a9c236 [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"
Dmitry Skiba01971112015-07-10 14:54:00 -040013#include "compiler/translator/Cache.h"
Olli Etuahoac5274d2015-02-20 10:19:08 +020014#include "compiler/translator/glslang.h"
15#include "compiler/translator/ValidateSwitch.h"
Olli Etuahob0c645e2015-05-12 14:25:36 +030016#include "compiler/translator/ValidateGlobalInitializer.h"
Olli Etuaho37ad4742015-04-27 13:18:50 +030017#include "compiler/translator/util.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000018
alokp@chromium.org8b851c62012-06-15 16:25:11 +000019///////////////////////////////////////////////////////////////////////
20//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000021// Sub- vector and matrix fields
22//
23////////////////////////////////////////////////////////////////////////
24
25//
26// Look at a '.' field selector string and change it into offsets
27// for a vector.
28//
Arun Patole7e7e68d2015-05-22 12:02:25 +053029bool TParseContext::parseVectorFields(const TString &compString, int vecSize, TVectorFields &fields,
30 const TSourceLoc &line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000031{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000032 fields.num = (int) compString.size();
Arun Patole7e7e68d2015-05-22 12:02:25 +053033 if (fields.num > 4)
34 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +000035 error(line, "illegal vector field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000036 return false;
37 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000039 enum {
40 exyzw,
41 ergba,
daniel@transgaming.comb3077d02013-01-11 04:12:09 +000042 estpq
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000043 } fieldSet[4];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000044
Arun Patole7e7e68d2015-05-22 12:02:25 +053045 for (int i = 0; i < fields.num; ++i)
46 {
47 switch (compString[i])
48 {
49 case 'x':
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000050 fields.offsets[i] = 0;
51 fieldSet[i] = exyzw;
52 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +053053 case 'r':
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000054 fields.offsets[i] = 0;
55 fieldSet[i] = ergba;
56 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +053057 case 's':
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000058 fields.offsets[i] = 0;
59 fieldSet[i] = estpq;
60 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +053061 case 'y':
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000062 fields.offsets[i] = 1;
63 fieldSet[i] = exyzw;
64 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +053065 case 'g':
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000066 fields.offsets[i] = 1;
67 fieldSet[i] = ergba;
68 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +053069 case 't':
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000070 fields.offsets[i] = 1;
71 fieldSet[i] = estpq;
72 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +053073 case 'z':
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000074 fields.offsets[i] = 2;
75 fieldSet[i] = exyzw;
76 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +053077 case 'b':
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000078 fields.offsets[i] = 2;
79 fieldSet[i] = ergba;
80 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +053081 case 'p':
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000082 fields.offsets[i] = 2;
83 fieldSet[i] = estpq;
84 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +053085
86 case 'w':
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000087 fields.offsets[i] = 3;
88 fieldSet[i] = exyzw;
89 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +053090 case 'a':
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000091 fields.offsets[i] = 3;
92 fieldSet[i] = ergba;
93 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +053094 case 'q':
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +000095 fields.offsets[i] = 3;
96 fieldSet[i] = estpq;
97 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +053098 default:
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +000099 error(line, "illegal vector field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000100 return false;
101 }
102 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000103
Arun Patole7e7e68d2015-05-22 12:02:25 +0530104 for (int i = 0; i < fields.num; ++i)
105 {
106 if (fields.offsets[i] >= vecSize)
107 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000108 error(line, "vector field selection out of range", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000109 return false;
110 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000111
Arun Patole7e7e68d2015-05-22 12:02:25 +0530112 if (i > 0)
113 {
114 if (fieldSet[i] != fieldSet[i-1])
115 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000116 error(line, "illegal - vector component fields not from the same set", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000117 return false;
118 }
119 }
120 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000121
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000122 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000123}
124
125
126//
127// Look at a '.' field selector string and change it into offsets
128// for a matrix.
129//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530130bool TParseContext::parseMatrixFields(const TString &compString, int matCols, int matRows, TMatrixFields &fields,
131 const TSourceLoc &line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000132{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000133 fields.wholeRow = false;
134 fields.wholeCol = false;
135 fields.row = -1;
136 fields.col = -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000137
Arun Patole7e7e68d2015-05-22 12:02:25 +0530138 if (compString.size() != 2)
139 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000140 error(line, "illegal length of matrix field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000141 return false;
142 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000143
Arun Patole7e7e68d2015-05-22 12:02:25 +0530144 if (compString[0] == '_')
145 {
146 if (compString[1] < '0' || compString[1] > '3')
147 {
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.wholeCol = true;
152 fields.col = compString[1] - '0';
Arun Patole7e7e68d2015-05-22 12:02:25 +0530153 }
154 else if (compString[1] == '_')
155 {
156 if (compString[0] < '0' || compString[0] > '3')
157 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000158 error(line, "illegal matrix field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000159 return false;
160 }
161 fields.wholeRow = true;
162 fields.row = compString[0] - '0';
Arun Patole7e7e68d2015-05-22 12:02:25 +0530163 }
164 else
165 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000166 if (compString[0] < '0' || compString[0] > '3' ||
Arun Patole7e7e68d2015-05-22 12:02:25 +0530167 compString[1] < '0' || compString[1] > '3')
168 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000169 error(line, "illegal matrix field selection", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000170 return false;
171 }
172 fields.row = compString[0] - '0';
173 fields.col = compString[1] - '0';
174 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000175
Arun Patole7e7e68d2015-05-22 12:02:25 +0530176 if (fields.row >= matRows || fields.col >= matCols)
177 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000178 error(line, "matrix field selection out of range", compString.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000179 return false;
180 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000181
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000182 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000183}
184
185///////////////////////////////////////////////////////////////////////
186//
187// Errors
188//
189////////////////////////////////////////////////////////////////////////
190
191//
192// Track whether errors have occurred.
193//
194void TParseContext::recover()
195{
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000196}
197
198//
199// Used by flex/bison to output all syntax and parsing errors.
200//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530201void TParseContext::error(const TSourceLoc &loc,
202 const char *reason, const char *token,
203 const char *extraInfo)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000204{
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000205 pp::SourceLocation srcLoc;
Jamie Madill075edd82013-07-08 13:30:19 -0400206 srcLoc.file = loc.first_file;
207 srcLoc.line = loc.first_line;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400208 mDiagnostics.writeInfo(pp::Diagnostics::PP_ERROR,
209 srcLoc, reason, token, extraInfo);
alokp@chromium.orgff42c632010-05-10 15:14:30 +0000210
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000211}
212
Arun Patole7e7e68d2015-05-22 12:02:25 +0530213void TParseContext::warning(const TSourceLoc &loc,
214 const char *reason, const char *token,
215 const char *extraInfo)
216{
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000217 pp::SourceLocation srcLoc;
Jamie Madill075edd82013-07-08 13:30:19 -0400218 srcLoc.file = loc.first_file;
219 srcLoc.line = loc.first_line;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400220 mDiagnostics.writeInfo(pp::Diagnostics::PP_WARNING,
221 srcLoc, reason, token, extraInfo);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000222}
223
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000224//
225// Same error message for all places assignments don't work.
226//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530227void TParseContext::assignError(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 << "cannot convert from '" << right << "' to '" << left << "'";
231 std::string extraInfo = extraInfoStream.str();
232 error(line, "", op, extraInfo.c_str());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000233}
234
235//
236// Same error message for all places unary operations don't work.
237//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530238void TParseContext::unaryOpError(const TSourceLoc &line, const char *op, TString operand)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000239{
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000240 std::stringstream extraInfoStream;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530241 extraInfoStream << "no operation '" << op << "' exists that takes an operand of type " << operand
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000242 << " (or there is no acceptable conversion)";
243 std::string extraInfo = extraInfoStream.str();
244 error(line, " wrong operand type", op, extraInfo.c_str());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000245}
246
247//
248// Same error message for all binary operations don't work.
249//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530250void TParseContext::binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000251{
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000252 std::stringstream extraInfoStream;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530253 extraInfoStream << "no operation '" << op << "' exists that takes a left-hand operand of type '" << left
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000254 << "' and a right operand of type '" << right << "' (or there is no acceptable conversion)";
255 std::string extraInfo = extraInfoStream.str();
Arun Patole7e7e68d2015-05-22 12:02:25 +0530256 error(line, " wrong operand types ", op, extraInfo.c_str());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000257}
258
Arun Patole7e7e68d2015-05-22 12:02:25 +0530259bool TParseContext::precisionErrorCheck(const TSourceLoc &line, TPrecision precision, TBasicType type)
260{
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400261 if (!mChecksPrecisionErrors)
zmo@google.comdc4b4f82011-06-17 00:42:53 +0000262 return false;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530263 switch(type)
264 {
265 case EbtFloat:
266 if( precision == EbpUndefined )
267 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000268 error( line, "No precision specified for (float)", "" );
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000269 return true;
270 }
271 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530272 case EbtInt:
273 if( precision == EbpUndefined )
274 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000275 error( line, "No precision specified (int)", "" );
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000276 return true;
277 }
278 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530279 default:
daniel@transgaming.com0eb64c32011-03-15 18:23:51 +0000280 return false;
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000281 }
282 return false;
283}
284
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000285//
286// Both test and if necessary, spit out an error, to see if the node is really
287// an l-value that can be operated on this way.
288//
289// Returns true if the was an error.
290//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530291bool TParseContext::lValueErrorCheck(const TSourceLoc &line, const char *op, TIntermTyped *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000292{
Arun Patole7e7e68d2015-05-22 12:02:25 +0530293 TIntermSymbol *symNode = node->getAsSymbolNode();
294 TIntermBinary *binaryNode = node->getAsBinaryNode();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000295
Arun Patole7e7e68d2015-05-22 12:02:25 +0530296 if (binaryNode)
297 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000298 bool errorReturn;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000299
Arun Patole7e7e68d2015-05-22 12:02:25 +0530300 switch(binaryNode->getOp())
301 {
302 case EOpIndexDirect:
303 case EOpIndexIndirect:
304 case EOpIndexDirectStruct:
305 case EOpIndexDirectInterfaceBlock:
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000306 return lValueErrorCheck(line, op, binaryNode->getLeft());
Arun Patole7e7e68d2015-05-22 12:02:25 +0530307 case EOpVectorSwizzle:
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000308 errorReturn = lValueErrorCheck(line, op, binaryNode->getLeft());
Arun Patole7e7e68d2015-05-22 12:02:25 +0530309 if (!errorReturn)
310 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000311 int offset[4] = {0,0,0,0};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000312
Arun Patole7e7e68d2015-05-22 12:02:25 +0530313 TIntermTyped *rightNode = binaryNode->getRight();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000314 TIntermAggregate *aggrNode = rightNode->getAsAggregate();
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700315
316 for (TIntermSequence::iterator p = aggrNode->getSequence()->begin();
Arun Patole7e7e68d2015-05-22 12:02:25 +0530317 p != aggrNode->getSequence()->end(); p++)
318 {
shannon.woods%transgaming.com@gtempaccount.comc0d0c222013-04-13 03:29:36 +0000319 int value = (*p)->getAsTyped()->getAsConstantUnion()->getIConst(0);
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700320 offset[value]++;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530321 if (offset[value] > 1)
322 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000323 error(line, " l-value of swizzle cannot have duplicate components", op);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000324
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000325 return true;
326 }
327 }
Zhenyao Moe40d1e92014-07-16 17:40:36 -0700328 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000329
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000330 return errorReturn;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530331 default:
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000332 break;
333 }
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000334 error(line, " l-value required", op);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000335
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000336 return true;
337 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000338
339
Arun Patole7e7e68d2015-05-22 12:02:25 +0530340 const char *symbol = 0;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000341 if (symNode != 0)
342 symbol = symNode->getSymbol().c_str();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000343
Arun Patole7e7e68d2015-05-22 12:02:25 +0530344 const char *message = 0;
345 switch (node->getQualifier())
346 {
347 case EvqConst:
348 message = "can't modify a const";
349 break;
350 case EvqConstReadOnly:
351 message = "can't modify a const";
352 break;
353 case EvqAttribute:
354 message = "can't modify an attribute";
355 break;
356 case EvqFragmentIn:
357 message = "can't modify an input";
358 break;
359 case EvqVertexIn:
360 message = "can't modify an input";
361 break;
362 case EvqUniform:
363 message = "can't modify a uniform";
364 break;
365 case EvqVaryingIn:
366 message = "can't modify a varying";
367 break;
368 case EvqFragCoord:
369 message = "can't modify gl_FragCoord";
370 break;
371 case EvqFrontFacing:
372 message = "can't modify gl_FrontFacing";
373 break;
374 case EvqPointCoord:
375 message = "can't modify gl_PointCoord";
376 break;
377 default:
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000378 //
379 // Type that can't be written to?
380 //
Arun Patole7e7e68d2015-05-22 12:02:25 +0530381 if (node->getBasicType() == EbtVoid)
382 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000383 message = "can't modify void";
Nicolas Capens344e7142013-06-24 15:39:21 -0400384 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530385 if (IsSampler(node->getBasicType()))
386 {
Nicolas Capens344e7142013-06-24 15:39:21 -0400387 message = "can't modify a sampler";
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000388 }
389 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000390
Arun Patole7e7e68d2015-05-22 12:02:25 +0530391 if (message == 0 && binaryNode == 0 && symNode == 0)
392 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000393 error(line, " l-value required", op);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000394
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000395 return true;
396 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000397
398
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000399 //
400 // Everything else is okay, no error.
401 //
402 if (message == 0)
403 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000404
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000405 //
406 // If we get here, we have an error and a message.
407 //
Arun Patole7e7e68d2015-05-22 12:02:25 +0530408 if (symNode)
409 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000410 std::stringstream extraInfoStream;
411 extraInfoStream << "\"" << symbol << "\" (" << message << ")";
412 std::string extraInfo = extraInfoStream.str();
413 error(line, " l-value required", op, extraInfo.c_str());
414 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530415 else
416 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000417 std::stringstream extraInfoStream;
418 extraInfoStream << "(" << message << ")";
419 std::string extraInfo = extraInfoStream.str();
420 error(line, " l-value required", op, extraInfo.c_str());
421 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000422
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000423 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000424}
425
426//
427// Both test, and if necessary spit out an error, to see if the node is really
428// a constant.
429//
430// Returns true if the was an error.
431//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530432bool TParseContext::constErrorCheck(TIntermTyped *node)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000433{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000434 if (node->getQualifier() == EvqConst)
435 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000436
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000437 error(node->getLine(), "constant expression required", "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000438
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000439 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000440}
441
442//
443// Both test, and if necessary spit out an error, to see if the node is really
444// an integer.
445//
446// Returns true if the was an error.
447//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530448bool TParseContext::integerErrorCheck(TIntermTyped *node, const char *token)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000449{
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000450 if (node->isScalarInt())
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000451 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000452
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000453 error(node->getLine(), "integer expression required", token);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000454
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000455 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000456}
457
458//
459// Both test, and if necessary spit out an error, to see if we are currently
460// globally scoped.
461//
462// Returns true if the was an error.
463//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530464bool TParseContext::globalErrorCheck(const TSourceLoc &line, bool global, const char *token)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000465{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000466 if (global)
467 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000468
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000469 error(line, "only allowed at global scope", token);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000470
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000471 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000472}
473
474//
475// For now, keep it simple: if it starts "gl_", it's reserved, independent
476// of scope. Except, if the symbol table is at the built-in push-level,
477// which is when we are parsing built-ins.
alokp@chromium.org613ef312010-07-21 18:54:22 +0000478// Also checks for "webgl_" and "_webgl_" reserved identifiers if parsing a
479// webgl shader.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000480//
481// Returns true if there was an error.
482//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530483bool TParseContext::reservedErrorCheck(const TSourceLoc &line, const TString &identifier)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000484{
Arun Patole7e7e68d2015-05-22 12:02:25 +0530485 static const char *reservedErrMsg = "reserved built-in name";
486 if (!symbolTable.atBuiltInLevel())
487 {
488 if (identifier.compare(0, 3, "gl_") == 0)
489 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000490 error(line, reservedErrMsg, "gl_");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000491 return true;
492 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530493 if (IsWebGLBasedSpec(mShaderSpec))
494 {
495 if (identifier.compare(0, 6, "webgl_") == 0)
496 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000497 error(line, reservedErrMsg, "webgl_");
alokp@chromium.org613ef312010-07-21 18:54:22 +0000498 return true;
499 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530500 if (identifier.compare(0, 7, "_webgl_") == 0)
501 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000502 error(line, reservedErrMsg, "_webgl_");
alokp@chromium.org613ef312010-07-21 18:54:22 +0000503 return true;
504 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530505 if (mShaderSpec == SH_CSS_SHADERS_SPEC && identifier.compare(0, 4, "css_") == 0)
506 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000507 error(line, reservedErrMsg, "css_");
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000508 return true;
509 }
alokp@chromium.org613ef312010-07-21 18:54:22 +0000510 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530511 if (identifier.find("__") != TString::npos)
512 {
513 error(line,
514 "identifiers containing two consecutive underscores (__) are reserved as possible future keywords",
515 identifier.c_str());
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000516 return true;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000517 }
518 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000519
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000520 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000521}
522
523//
524// Make sure there is enough data provided to the constructor to build
525// something of the type of the constructor. Also returns the type of
526// the constructor.
527//
528// Returns true if there was an error in construction.
529//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530530bool TParseContext::constructorErrorCheck(const TSourceLoc &line, TIntermNode *node, TFunction &function, TOperator op,
531 TType *type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000532{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000533 *type = function.getReturnType();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000534
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000535 bool constructingMatrix = false;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530536 switch(op)
537 {
538 case EOpConstructMat2:
Alexis Hetu07e57df2015-06-16 16:55:52 -0400539 case EOpConstructMat2x3:
540 case EOpConstructMat2x4:
541 case EOpConstructMat3x2:
Arun Patole7e7e68d2015-05-22 12:02:25 +0530542 case EOpConstructMat3:
Alexis Hetu07e57df2015-06-16 16:55:52 -0400543 case EOpConstructMat3x4:
544 case EOpConstructMat4x2:
545 case EOpConstructMat4x3:
Arun Patole7e7e68d2015-05-22 12:02:25 +0530546 case EOpConstructMat4:
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000547 constructingMatrix = true;
548 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530549 default:
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000550 break;
551 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000552
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000553 //
554 // Note: It's okay to have too many components available, but not okay to have unused
555 // arguments. 'full' will go to true when enough args have been seen. If we loop
556 // again, there is an extra argument, so 'overfull' will become true.
557 //
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000558
Jamie Madill94bf7f22013-07-08 13:31:15 -0400559 size_t size = 0;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000560 bool constType = true;
561 bool full = false;
562 bool overFull = false;
563 bool matrixInMatrix = false;
564 bool arrayArg = false;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530565 for (size_t i = 0; i < function.getParamCount(); ++i)
566 {
Dmitry Skibaefa3d8e2015-06-22 14:52:10 -0700567 const TConstParameter &param = function.getParam(i);
alokp@chromium.orgb19403a2010-09-08 17:56:26 +0000568 size += param.type->getObjectSize();
Arun Patole7e7e68d2015-05-22 12:02:25 +0530569
alokp@chromium.orgb19403a2010-09-08 17:56:26 +0000570 if (constructingMatrix && param.type->isMatrix())
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000571 matrixInMatrix = true;
572 if (full)
573 overFull = true;
574 if (op != EOpConstructStruct && !type->isArray() && size >= type->getObjectSize())
575 full = true;
alokp@chromium.orgb19403a2010-09-08 17:56:26 +0000576 if (param.type->getQualifier() != EvqConst)
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000577 constType = false;
alokp@chromium.orgb19403a2010-09-08 17:56:26 +0000578 if (param.type->isArray())
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000579 arrayArg = true;
580 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530581
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000582 if (constType)
alokp@chromium.org58e54292010-08-24 21:40:03 +0000583 type->setQualifier(EvqConst);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000584
Olli Etuaho376f1b52015-04-13 13:23:41 +0300585 if (type->isArray())
586 {
587 if (type->isUnsizedArray())
588 {
589 type->setArraySize(function.getParamCount());
590 }
591 else if (static_cast<size_t>(type->getArraySize()) != function.getParamCount())
592 {
593 error(line, "array constructor needs one argument per array element", "constructor");
594 return true;
595 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000596 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000597
Arun Patole7e7e68d2015-05-22 12:02:25 +0530598 if (arrayArg && op != EOpConstructStruct)
599 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000600 error(line, "constructing from a non-dereferenced array", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000601 return true;
602 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000603
Arun Patole7e7e68d2015-05-22 12:02:25 +0530604 if (matrixInMatrix && !type->isArray())
605 {
606 if (function.getParamCount() != 1)
607 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000608 error(line, "constructing matrix from matrix can only take one argument", "constructor");
daniel@transgaming.combef0b6d2010-04-29 03:32:39 +0000609 return true;
610 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000611 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000612
Arun Patole7e7e68d2015-05-22 12:02:25 +0530613 if (overFull)
614 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000615 error(line, "too many arguments", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000616 return true;
617 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530618
619 if (op == EOpConstructStruct && !type->isArray() && type->getStruct()->fields().size() != function.getParamCount())
620 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000621 error(line, "Number of constructor parameters does not match the number of structure fields", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000622 return true;
623 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000624
Arun Patole7e7e68d2015-05-22 12:02:25 +0530625 if (!type->isMatrix() || !matrixInMatrix)
626 {
daniel@transgaming.combef0b6d2010-04-29 03:32:39 +0000627 if ((op != EOpConstructStruct && size != 1 && size < type->getObjectSize()) ||
Arun Patole7e7e68d2015-05-22 12:02:25 +0530628 (op == EOpConstructStruct && size < type->getObjectSize()))
629 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000630 error(line, "not enough data provided for construction", "constructor");
daniel@transgaming.combef0b6d2010-04-29 03:32:39 +0000631 return true;
632 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000633 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000634
daniel@transgaming.com0b53fc02011-03-09 15:12:12 +0000635 TIntermTyped *typed = node ? node->getAsTyped() : 0;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530636 if (typed == 0)
637 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000638 error(line, "constructor argument does not have a type", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000639 return true;
640 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530641 if (op != EOpConstructStruct && IsSampler(typed->getBasicType()))
642 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000643 error(line, "cannot convert a sampler", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000644 return true;
645 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530646 if (typed->getBasicType() == EbtVoid)
647 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000648 error(line, "cannot convert a void", "constructor");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000649 return true;
650 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000651
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000652 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000653}
654
655// This function checks to see if a void variable has been declared and raise an error message for such a case
656//
657// returns true in case of an error
658//
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +0300659bool TParseContext::voidErrorCheck(const TSourceLoc &line, const TString &identifier, const TBasicType &type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000660{
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +0300661 if (type == EbtVoid)
662 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000663 error(line, "illegal use of type 'void'", identifier.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000664 return true;
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +0300665 }
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// This function checks to see if the node (for the expression) contains a scalar boolean expression or not
671//
672// returns true in case of an error
673//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530674bool TParseContext::boolErrorCheck(const TSourceLoc &line, const TIntermTyped *type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000675{
Arun Patole7e7e68d2015-05-22 12:02:25 +0530676 if (type->getBasicType() != EbtBool || type->isArray() || type->isMatrix() || type->isVector())
677 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000678 error(line, "boolean expression expected", "");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000679 return true;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530680 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000681
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000682 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000683}
684
685// This function checks to see if the node (for the expression) contains a scalar boolean expression or not
686//
687// returns true in case of an error
688//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530689bool TParseContext::boolErrorCheck(const TSourceLoc &line, const TPublicType &pType)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000690{
Arun Patole7e7e68d2015-05-22 12:02:25 +0530691 if (pType.type != EbtBool || pType.isAggregate())
692 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000693 error(line, "boolean expression expected", "");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000694 return true;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530695 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000696
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000697 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000698}
699
Arun Patole7e7e68d2015-05-22 12:02:25 +0530700bool TParseContext::samplerErrorCheck(const TSourceLoc &line, const TPublicType &pType, const char *reason)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000701{
Arun Patole7e7e68d2015-05-22 12:02:25 +0530702 if (pType.type == EbtStruct)
703 {
704 if (containsSampler(*pType.userDef))
705 {
alokp@chromium.org58e54292010-08-24 21:40:03 +0000706 error(line, reason, getBasicString(pType.type), "(structure contains a sampler)");
Arun Patole7e7e68d2015-05-22 12:02:25 +0530707
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000708 return true;
709 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530710
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000711 return false;
Arun Patole7e7e68d2015-05-22 12:02:25 +0530712 }
713 else if (IsSampler(pType.type))
714 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000715 error(line, reason, getBasicString(pType.type));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000716
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000717 return true;
718 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000719
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000720 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000721}
722
Arun Patole7e7e68d2015-05-22 12:02:25 +0530723bool TParseContext::locationDeclaratorListCheck(const TSourceLoc &line, const TPublicType &pType)
Jamie Madill0bd18df2013-06-20 11:55:52 -0400724{
725 if (pType.layoutQualifier.location != -1)
726 {
727 error(line, "location must only be specified for a single input or output variable", "location");
728 return true;
729 }
730
731 return false;
732}
733
Arun Patole7e7e68d2015-05-22 12:02:25 +0530734bool TParseContext::parameterSamplerErrorCheck(const TSourceLoc &line, TQualifier qualifier, const TType &type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000735{
Arun Patole7e7e68d2015-05-22 12:02:25 +0530736 if ((qualifier == EvqOut || qualifier == EvqInOut) &&
737 type.getBasicType() != EbtStruct && IsSampler(type.getBasicType()))
738 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000739 error(line, "samplers cannot be output parameters", type.getBasicString());
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
Arun Patole7e7e68d2015-05-22 12:02:25 +0530746bool TParseContext::containsSampler(const TType &type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000747{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000748 if (IsSampler(type.getBasicType()))
749 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000750
Arun Patole7e7e68d2015-05-22 12:02:25 +0530751 if (type.getBasicType() == EbtStruct || type.isInterfaceBlock())
752 {
753 const TFieldList &fields = type.getStruct()->fields();
754 for (unsigned int i = 0; i < fields.size(); ++i)
755 {
Jamie Madill98493dd2013-07-08 14:39:03 -0400756 if (containsSampler(*fields[i]->type()))
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000757 return true;
758 }
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//
765// Do size checking for an array type's size.
766//
767// Returns true if there was an error.
768//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530769bool TParseContext::arraySizeErrorCheck(const TSourceLoc &line, TIntermTyped *expr, int &size)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000770{
Arun Patole7e7e68d2015-05-22 12:02:25 +0530771 TIntermConstantUnion *constant = expr->getAsConstantUnion();
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000772
Olli Etuahoe7847b02015-03-16 11:56:12 +0200773 if (constant == nullptr || !constant->isScalarInt())
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000774 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000775 error(line, "array size must be a constant integer expression", "");
Olli Etuahoe7847b02015-03-16 11:56:12 +0200776 size = 1;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000777 return true;
778 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000779
Nicolas Capens906744a2014-06-06 15:18:07 -0400780 unsigned int unsignedSize = 0;
781
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000782 if (constant->getBasicType() == EbtUInt)
783 {
Nicolas Capens906744a2014-06-06 15:18:07 -0400784 unsignedSize = constant->getUConst(0);
785 size = static_cast<int>(unsignedSize);
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000786 }
787 else
788 {
789 size = constant->getIConst(0);
790
Nicolas Capens906744a2014-06-06 15:18:07 -0400791 if (size < 0)
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000792 {
Nicolas Capens906744a2014-06-06 15:18:07 -0400793 error(line, "array size must be non-negative", "");
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000794 size = 1;
795 return true;
796 }
Nicolas Capens906744a2014-06-06 15:18:07 -0400797
798 unsignedSize = static_cast<unsigned int>(size);
799 }
800
801 if (size == 0)
802 {
803 error(line, "array size must be greater than zero", "");
804 size = 1;
805 return true;
806 }
807
808 // The size of arrays is restricted here to prevent issues further down the
809 // compiler/translator/driver stack. Shader Model 5 generation hardware is limited to
810 // 4096 registers so this should be reasonable even for aggressively optimizable code.
811 const unsigned int sizeLimit = 65536;
812
813 if (unsignedSize > sizeLimit)
814 {
815 error(line, "array size too large", "");
816 size = 1;
817 return true;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000818 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000819
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000820 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000821}
822
823//
824// See if this qualifier can be an array.
825//
826// Returns true if there is an error.
827//
Olli Etuaho3739d232015-04-08 12:23:44 +0300828bool TParseContext::arrayQualifierErrorCheck(const TSourceLoc &line, const TPublicType &type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000829{
Olli Etuaho3739d232015-04-08 12:23:44 +0300830 if ((type.qualifier == EvqAttribute) || (type.qualifier == EvqVertexIn) ||
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400831 (type.qualifier == EvqConst && mShaderVersion < 300))
Olli Etuaho3739d232015-04-08 12:23:44 +0300832 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000833 error(line, "cannot declare arrays of this qualifier", TType(type).getCompleteString().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000834 return true;
835 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000836
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000837 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000838}
839
840//
841// See if this type can be an array.
842//
843// Returns true if there is an error.
844//
Arun Patole7e7e68d2015-05-22 12:02:25 +0530845bool TParseContext::arrayTypeErrorCheck(const TSourceLoc &line, const TPublicType &type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000846{
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000847 //
848 // Can the type be an array?
849 //
Jamie Madill06145232015-05-13 13:10:01 -0400850 if (type.array)
851 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000852 error(line, "cannot declare arrays of arrays", TType(type).getCompleteString().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000853 return true;
854 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000855
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000856 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000857}
858
859//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000860// Enforce non-initializer type/qualifier rules.
861//
862// Returns true if there was an error.
863//
Olli Etuaho376f1b52015-04-13 13:23:41 +0300864bool TParseContext::nonInitErrorCheck(const TSourceLoc &line, const TString &identifier, TPublicType *type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000865{
Olli Etuaho3739d232015-04-08 12:23:44 +0300866 ASSERT(type != nullptr);
867 if (type->qualifier == EvqConst)
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000868 {
869 // Make the qualifier make sense.
Olli Etuaho3739d232015-04-08 12:23:44 +0300870 type->qualifier = EvqTemporary;
871
872 // Generate informative error messages for ESSL1.
873 // In ESSL3 arrays and structures containing arrays can be constant.
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400874 if (mShaderVersion < 300 && type->isStructureContainingArrays())
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000875 {
Arun Patole7e7e68d2015-05-22 12:02:25 +0530876 error(line,
877 "structures containing arrays may not be declared constant since they cannot be initialized",
878 identifier.c_str());
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000879 }
880 else
881 {
882 error(line, "variables with qualifier 'const' must be initialized", identifier.c_str());
883 }
884
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000885 return true;
886 }
Olli Etuaho376f1b52015-04-13 13:23:41 +0300887 if (type->isUnsizedArray())
888 {
889 error(line, "implicitly sized arrays need to be initialized", identifier.c_str());
890 return true;
891 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000892 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000893}
894
Olli Etuaho2935c582015-04-08 14:32:06 +0300895// Do some simple checks that are shared between all variable declarations,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000896// and update the symbol table.
897//
Olli Etuaho2935c582015-04-08 14:32:06 +0300898// Returns true if declaring the variable succeeded.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000899//
Olli Etuaho2935c582015-04-08 14:32:06 +0300900bool TParseContext::declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type,
901 TVariable **variable)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000902{
Olli Etuaho2935c582015-04-08 14:32:06 +0300903 ASSERT((*variable) == nullptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000904
Olli Etuaho2935c582015-04-08 14:32:06 +0300905 bool needsReservedErrorCheck = true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000906
Olli Etuaho2935c582015-04-08 14:32:06 +0300907 // gl_LastFragData may be redeclared with a new precision qualifier
908 if (type.isArray() && identifier.compare(0, 15, "gl_LastFragData") == 0)
909 {
910 const TVariable *maxDrawBuffers =
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400911 static_cast<const TVariable *>(symbolTable.findBuiltIn("gl_MaxDrawBuffers", mShaderVersion));
Olli Etuaho2935c582015-04-08 14:32:06 +0300912 if (type.getArraySize() == maxDrawBuffers->getConstPointer()->getIConst())
913 {
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400914 if (TSymbol *builtInSymbol = symbolTable.findBuiltIn(identifier, mShaderVersion))
Olli Etuaho2935c582015-04-08 14:32:06 +0300915 {
916 needsReservedErrorCheck = extensionErrorCheck(line, builtInSymbol->getExtension());
917 }
918 }
919 else
920 {
921 error(line, "redeclaration of gl_LastFragData with size != gl_MaxDrawBuffers", identifier.c_str());
922 return false;
923 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000924 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000925
Olli Etuaho2935c582015-04-08 14:32:06 +0300926 if (needsReservedErrorCheck && reservedErrorCheck(line, identifier))
927 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000928
Olli Etuaho2935c582015-04-08 14:32:06 +0300929 (*variable) = new TVariable(&identifier, type);
930 if (!symbolTable.declare(*variable))
931 {
932 error(line, "redefinition", identifier.c_str());
933 delete (*variable);
934 (*variable) = nullptr;
935 return false;
936 }
937
938 if (voidErrorCheck(line, identifier, type.getBasicType()))
939 return false;
940
941 return true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000942}
943
Arun Patole7e7e68d2015-05-22 12:02:25 +0530944bool TParseContext::paramErrorCheck(const TSourceLoc &line, TQualifier qualifier, TQualifier paramQualifier,
945 TType *type)
946{
947 if (qualifier != EvqConst && qualifier != EvqTemporary)
948 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000949 error(line, "qualifier not allowed on function parameter", getQualifierString(qualifier));
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000950 return true;
951 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530952 if (qualifier == EvqConst && paramQualifier != EvqIn)
953 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000954 error(line, "qualifier not allowed with ", getQualifierString(qualifier), getQualifierString(paramQualifier));
955 return true;
956 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000957
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000958 if (qualifier == EvqConst)
alokp@chromium.org58e54292010-08-24 21:40:03 +0000959 type->setQualifier(EvqConstReadOnly);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000960 else
alokp@chromium.org58e54292010-08-24 21:40:03 +0000961 type->setQualifier(paramQualifier);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000962
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000963 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000964}
965
Arun Patole7e7e68d2015-05-22 12:02:25 +0530966bool TParseContext::extensionErrorCheck(const TSourceLoc &line, const TString &extension)
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000967{
Arun Patole7e7e68d2015-05-22 12:02:25 +0530968 const TExtensionBehavior &extBehavior = extensionBehavior();
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000969 TExtensionBehavior::const_iterator iter = extBehavior.find(extension.c_str());
Arun Patole7e7e68d2015-05-22 12:02:25 +0530970 if (iter == extBehavior.end())
971 {
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000972 error(line, "extension", extension.c_str(), "is not supported");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000973 return true;
974 }
zmo@google.comf5450912011-09-09 01:37:19 +0000975 // In GLSL ES, an extension's default behavior is "disable".
Arun Patole7e7e68d2015-05-22 12:02:25 +0530976 if (iter->second == EBhDisable || iter->second == EBhUndefined)
977 {
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000978 error(line, "extension", extension.c_str(), "is disabled");
979 return true;
980 }
Arun Patole7e7e68d2015-05-22 12:02:25 +0530981 if (iter->second == EBhWarn)
982 {
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000983 warning(line, "extension", extension.c_str(), "is being used");
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000984 return false;
985 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000986
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +0000987 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000988}
989
Olli Etuahofa33d582015-04-09 14:33:12 +0300990// These checks are common for all declarations starting a declarator list, and declarators that follow an empty
991// declaration.
992//
Jamie Madill06145232015-05-13 13:10:01 -0400993bool TParseContext::singleDeclarationErrorCheck(const TPublicType &publicType, const TSourceLoc &identifierLocation)
Jamie Madilla5efff92013-06-06 11:56:47 -0400994{
Olli Etuahofa33d582015-04-09 14:33:12 +0300995 switch (publicType.qualifier)
996 {
997 case EvqVaryingIn:
998 case EvqVaryingOut:
999 case EvqAttribute:
1000 case EvqVertexIn:
1001 case EvqFragmentOut:
1002 if (publicType.type == EbtStruct)
1003 {
1004 error(identifierLocation, "cannot be used with a structure",
1005 getQualifierString(publicType.qualifier));
1006 return true;
1007 }
1008
1009 default: break;
1010 }
1011
1012 if (publicType.qualifier != EvqUniform && samplerErrorCheck(identifierLocation, publicType,
1013 "samplers must be uniform"))
1014 {
Jamie Madilla5efff92013-06-06 11:56:47 -04001015 return true;
Olli Etuahofa33d582015-04-09 14:33:12 +03001016 }
Jamie Madilla5efff92013-06-06 11:56:47 -04001017
1018 // check for layout qualifier issues
1019 const TLayoutQualifier layoutQualifier = publicType.layoutQualifier;
1020
1021 if (layoutQualifier.matrixPacking != EmpUnspecified)
1022 {
Olli Etuahofa33d582015-04-09 14:33:12 +03001023 error(identifierLocation, "layout qualifier", getMatrixPackingString(layoutQualifier.matrixPacking),
1024 "only valid for interface blocks");
Jamie Madill51a53c72013-06-19 09:24:43 -04001025 return true;
Jamie Madilla5efff92013-06-06 11:56:47 -04001026 }
1027
1028 if (layoutQualifier.blockStorage != EbsUnspecified)
1029 {
Olli Etuahofa33d582015-04-09 14:33:12 +03001030 error(identifierLocation, "layout qualifier", getBlockStorageString(layoutQualifier.blockStorage),
1031 "only valid for interface blocks");
Jamie Madill51a53c72013-06-19 09:24:43 -04001032 return true;
Jamie Madilla5efff92013-06-06 11:56:47 -04001033 }
1034
Olli Etuahofa33d582015-04-09 14:33:12 +03001035 if (publicType.qualifier != EvqVertexIn && publicType.qualifier != EvqFragmentOut &&
1036 layoutLocationErrorCheck(identifierLocation, publicType.layoutQualifier))
Jamie Madilla5efff92013-06-06 11:56:47 -04001037 {
Jamie Madill51a53c72013-06-19 09:24:43 -04001038 return true;
Jamie Madilla5efff92013-06-06 11:56:47 -04001039 }
1040
1041 return false;
1042}
1043
Arun Patole7e7e68d2015-05-22 12:02:25 +05301044bool TParseContext::layoutLocationErrorCheck(const TSourceLoc &location, const TLayoutQualifier &layoutQualifier)
Jamie Madilla5efff92013-06-06 11:56:47 -04001045{
1046 if (layoutQualifier.location != -1)
1047 {
1048 error(location, "invalid layout qualifier:", "location", "only valid on program inputs and outputs");
1049 return true;
1050 }
1051
1052 return false;
1053}
1054
Olli Etuahob6e07a62015-02-16 12:22:10 +02001055bool TParseContext::functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *aggregate)
1056{
1057 for (size_t i = 0; i < fnCandidate->getParamCount(); ++i)
1058 {
1059 TQualifier qual = fnCandidate->getParam(i).type->getQualifier();
1060 if (qual == EvqOut || qual == EvqInOut)
1061 {
1062 TIntermTyped *node = (*(aggregate->getSequence()))[i]->getAsTyped();
1063 if (lValueErrorCheck(node->getLine(), "assign", node))
1064 {
1065 error(node->getLine(),
1066 "Constant value cannot be passed for 'out' or 'inout' parameters.", "Error");
1067 recover();
1068 return true;
1069 }
1070 }
1071 }
1072 return false;
1073}
1074
Olli Etuaho37ad4742015-04-27 13:18:50 +03001075void TParseContext::es3InvariantErrorCheck(const TQualifier qualifier, const TSourceLoc &invariantLocation)
1076{
1077 if (!sh::IsVaryingOut(qualifier) && qualifier != EvqFragmentOut)
1078 {
1079 error(invariantLocation, "Only out variables can be invariant.", "invariant");
1080 recover();
1081 }
1082}
1083
Arun Patole7e7e68d2015-05-22 12:02:25 +05301084bool TParseContext::supportsExtension(const char *extension)
zmo@google.com09c323a2011-08-12 18:22:25 +00001085{
Arun Patole7e7e68d2015-05-22 12:02:25 +05301086 const TExtensionBehavior &extbehavior = extensionBehavior();
alokp@chromium.org73bc2982012-06-19 18:48:05 +00001087 TExtensionBehavior::const_iterator iter = extbehavior.find(extension);
1088 return (iter != extbehavior.end());
alokp@chromium.org8b851c62012-06-15 16:25:11 +00001089}
1090
Arun Patole7e7e68d2015-05-22 12:02:25 +05301091bool TParseContext::isExtensionEnabled(const char *extension) const
Jamie Madill5d287f52013-07-12 15:38:19 -04001092{
Arun Patole7e7e68d2015-05-22 12:02:25 +05301093 const TExtensionBehavior &extbehavior = extensionBehavior();
Shannon Woodsa49a9bf2013-08-02 17:23:14 -04001094 TExtensionBehavior::const_iterator iter = extbehavior.find(extension);
Jamie Madill5d287f52013-07-12 15:38:19 -04001095
1096 if (iter == extbehavior.end())
1097 {
1098 return false;
1099 }
1100
1101 return (iter->second == EBhEnable || iter->second == EBhRequire);
1102}
1103
Arun Patole7e7e68d2015-05-22 12:02:25 +05301104void TParseContext::handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior)
Jamie Madill075edd82013-07-08 13:30:19 -04001105{
1106 pp::SourceLocation srcLoc;
1107 srcLoc.file = loc.first_file;
1108 srcLoc.line = loc.first_line;
Jamie Madill6e06b1f2015-05-14 10:01:17 -04001109 mDirectiveHandler.handleExtension(srcLoc, extName, behavior);
Jamie Madill075edd82013-07-08 13:30:19 -04001110}
1111
Arun Patole7e7e68d2015-05-22 12:02:25 +05301112void TParseContext::handlePragmaDirective(const TSourceLoc &loc, const char *name, const char *value, bool stdgl)
Jamie Madill075edd82013-07-08 13:30:19 -04001113{
1114 pp::SourceLocation srcLoc;
1115 srcLoc.file = loc.first_file;
1116 srcLoc.line = loc.first_line;
Jamie Madill6e06b1f2015-05-14 10:01:17 -04001117 mDirectiveHandler.handlePragma(srcLoc, name, value, stdgl);
Jamie Madill075edd82013-07-08 13:30:19 -04001118}
1119
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001120/////////////////////////////////////////////////////////////////////////////////
1121//
1122// Non-Errors.
1123//
1124/////////////////////////////////////////////////////////////////////////////////
1125
Jamie Madill5c097022014-08-20 16:38:32 -04001126const TVariable *TParseContext::getNamedVariable(const TSourceLoc &location,
1127 const TString *name,
1128 const TSymbol *symbol)
1129{
1130 const TVariable *variable = NULL;
1131
1132 if (!symbol)
1133 {
1134 error(location, "undeclared identifier", name->c_str());
1135 recover();
1136 }
1137 else if (!symbol->isVariable())
1138 {
1139 error(location, "variable expected", name->c_str());
1140 recover();
1141 }
1142 else
1143 {
1144 variable = static_cast<const TVariable*>(symbol);
1145
Jamie Madill6e06b1f2015-05-14 10:01:17 -04001146 if (symbolTable.findBuiltIn(variable->getName(), mShaderVersion) &&
Jamie Madill5c097022014-08-20 16:38:32 -04001147 !variable->getExtension().empty() &&
1148 extensionErrorCheck(location, variable->getExtension()))
1149 {
1150 recover();
1151 }
Jamie Madill14e95b32015-05-07 10:10:41 -04001152
1153 // Reject shaders using both gl_FragData and gl_FragColor
1154 TQualifier qualifier = variable->getType().getQualifier();
1155 if (qualifier == EvqFragData)
1156 {
1157 mUsesFragData = true;
1158 }
1159 else if (qualifier == EvqFragColor)
1160 {
1161 mUsesFragColor = true;
1162 }
1163
1164 // This validation is not quite correct - it's only an error to write to
1165 // both FragData and FragColor. For simplicity, and because users shouldn't
1166 // be rewarded for reading from undefined varaibles, return an error
1167 // if they are both referenced, rather than assigned.
1168 if (mUsesFragData && mUsesFragColor)
1169 {
1170 error(location, "cannot use both gl_FragData and gl_FragColor", name->c_str());
1171 recover();
1172 }
Jamie Madill5c097022014-08-20 16:38:32 -04001173 }
1174
1175 if (!variable)
1176 {
1177 TType type(EbtFloat, EbpUndefined);
1178 TVariable *fakeVariable = new TVariable(name, type);
1179 symbolTable.declare(fakeVariable);
1180 variable = fakeVariable;
1181 }
1182
1183 return variable;
1184}
1185
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001186//
1187// Look up a function name in the symbol table, and make sure it is a function.
1188//
1189// Return the function symbol if found, otherwise 0.
1190//
Arun Patole7e7e68d2015-05-22 12:02:25 +05301191const TFunction *TParseContext::findFunction(const TSourceLoc &line, TFunction *call, int inputShaderVersion,
1192 bool *builtIn)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001193{
alokp@chromium.org0a576182010-08-09 17:16:27 +00001194 // First find by unmangled name to check whether the function name has been
1195 // hidden by a variable name or struct typename.
Nicolas Capensd4a9b8d2013-07-18 11:01:22 -04001196 // If a function is found, check for one with a matching argument list.
Arun Patole7e7e68d2015-05-22 12:02:25 +05301197 const TSymbol *symbol = symbolTable.find(call->getName(), inputShaderVersion, builtIn);
1198 if (symbol == 0 || symbol->isFunction())
1199 {
Austin Kinross3ae64652015-01-26 15:51:39 -08001200 symbol = symbolTable.find(call->getMangledName(), inputShaderVersion, builtIn);
alokp@chromium.org0a576182010-08-09 17:16:27 +00001201 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001202
Arun Patole7e7e68d2015-05-22 12:02:25 +05301203 if (symbol == 0)
1204 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001205 error(line, "no matching overloaded function found", call->getName().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001206 return 0;
1207 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001208
Arun Patole7e7e68d2015-05-22 12:02:25 +05301209 if (!symbol->isFunction())
1210 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001211 error(line, "function name expected", call->getName().c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001212 return 0;
1213 }
alokp@chromium.org0a576182010-08-09 17:16:27 +00001214
1215 return static_cast<const TFunction*>(symbol);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001216}
1217
1218//
1219// Initializers show up in several places in the grammar. Have one set of
1220// code to handle them here.
1221//
Jamie Madill3b5c2da2014-08-19 15:23:32 -04001222// Returns true on error, false if no error
1223//
Jamie Madill06145232015-05-13 13:10:01 -04001224bool TParseContext::executeInitializer(const TSourceLoc &line, const TString &identifier, const TPublicType &pType,
Olli Etuahoe7847b02015-03-16 11:56:12 +02001225 TIntermTyped *initializer, TIntermNode **intermNode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001226{
Olli Etuahoe7847b02015-03-16 11:56:12 +02001227 ASSERT(intermNode != nullptr);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001228 TType type = TType(pType);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001229
Olli Etuaho2935c582015-04-08 14:32:06 +03001230 TVariable *variable = nullptr;
Olli Etuaho376f1b52015-04-13 13:23:41 +03001231 if (type.isUnsizedArray())
1232 {
1233 type.setArraySize(initializer->getArraySize());
1234 }
Olli Etuaho2935c582015-04-08 14:32:06 +03001235 if (!declareVariable(line, identifier, type, &variable))
1236 {
1237 return true;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001238 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001239
Olli Etuahob0c645e2015-05-12 14:25:36 +03001240 bool globalInitWarning = false;
1241 if (symbolTable.atGlobalLevel() && !ValidateGlobalInitializer(initializer, this, &globalInitWarning))
1242 {
1243 // Error message does not completely match behavior with ESSL 1.00, but
1244 // we want to steer developers towards only using constant expressions.
1245 error(line, "global variable initializers must be constant expressions", "=");
1246 return true;
1247 }
1248 if (globalInitWarning)
1249 {
1250 warning(line, "global variable initializers should be constant expressions "
1251 "(uniforms and globals are allowed in global initializers for legacy compatibility)", "=");
1252 }
1253
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001254 //
1255 // identifier must be of type constant, a global, or a temporary
1256 //
1257 TQualifier qualifier = variable->getType().getQualifier();
Arun Patole7e7e68d2015-05-22 12:02:25 +05301258 if ((qualifier != EvqTemporary) && (qualifier != EvqGlobal) && (qualifier != EvqConst))
1259 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001260 error(line, " cannot initialize this type of qualifier ", variable->getType().getQualifierString());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001261 return true;
1262 }
1263 //
1264 // test for and propagate constant
1265 //
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001266
Arun Patole7e7e68d2015-05-22 12:02:25 +05301267 if (qualifier == EvqConst)
1268 {
1269 if (qualifier != initializer->getType().getQualifier())
1270 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001271 std::stringstream extraInfoStream;
1272 extraInfoStream << "'" << variable->getType().getCompleteString() << "'";
1273 std::string extraInfo = extraInfoStream.str();
1274 error(line, " assigning non-constant to", "=", extraInfo.c_str());
alokp@chromium.org58e54292010-08-24 21:40:03 +00001275 variable->getType().setQualifier(EvqTemporary);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001276 return true;
1277 }
Arun Patole7e7e68d2015-05-22 12:02:25 +05301278 if (type != initializer->getType())
1279 {
1280 error(line, " non-matching types for const initializer ",
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001281 variable->getType().getQualifierString());
alokp@chromium.org58e54292010-08-24 21:40:03 +00001282 variable->getType().setQualifier(EvqTemporary);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001283 return true;
1284 }
Arun Patole7e7e68d2015-05-22 12:02:25 +05301285 if (initializer->getAsConstantUnion())
1286 {
Jamie Madill94bf7f22013-07-08 13:31:15 -04001287 variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer());
Arun Patole7e7e68d2015-05-22 12:02:25 +05301288 }
1289 else if (initializer->getAsSymbolNode())
1290 {
1291 const TSymbol *symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol(), 0);
1292 const TVariable *tVar = static_cast<const TVariable*>(symbol);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001293
Arun Patole7e7e68d2015-05-22 12:02:25 +05301294 TConstantUnion *constArray = tVar->getConstPointer();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001295 variable->shareConstPointer(constArray);
Arun Patole7e7e68d2015-05-22 12:02:25 +05301296 }
1297 else
1298 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00001299 std::stringstream extraInfoStream;
1300 extraInfoStream << "'" << variable->getType().getCompleteString() << "'";
1301 std::string extraInfo = extraInfoStream.str();
1302 error(line, " cannot assign to", "=", extraInfo.c_str());
alokp@chromium.org58e54292010-08-24 21:40:03 +00001303 variable->getType().setQualifier(EvqTemporary);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001304 return true;
1305 }
1306 }
Olli Etuahoe7847b02015-03-16 11:56:12 +02001307
1308 if (qualifier != EvqConst)
1309 {
1310 TIntermSymbol *intermSymbol = intermediate.addSymbol(variable->getUniqueId(), variable->getName(),
1311 variable->getType(), line);
1312 *intermNode = createAssign(EOpInitialize, intermSymbol, initializer, line);
1313 if (*intermNode == nullptr)
1314 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001315 assignError(line, "=", intermSymbol->getCompleteString(), initializer->getCompleteString());
1316 return true;
1317 }
Olli Etuahoe7847b02015-03-16 11:56:12 +02001318 }
1319 else
1320 {
1321 *intermNode = nullptr;
1322 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001323
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001324 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001325}
1326
Arun Patole7e7e68d2015-05-22 12:02:25 +05301327bool TParseContext::areAllChildConst(TIntermAggregate *aggrNode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001328{
alokp@chromium.orgd300f5b2010-10-14 16:10:20 +00001329 ASSERT(aggrNode != NULL);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001330 if (!aggrNode->isConstructor())
1331 return false;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001332
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001333 bool allConstant = true;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001334
Arun Patole7e7e68d2015-05-22 12:02:25 +05301335 // check if all the child nodes are constants so that they can be inserted into
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001336 // the parent node
Zhenyao Moe40d1e92014-07-16 17:40:36 -07001337 TIntermSequence *sequence = aggrNode->getSequence() ;
Arun Patole7e7e68d2015-05-22 12:02:25 +05301338 for (TIntermSequence::iterator p = sequence->begin(); p != sequence->end(); ++p)
1339 {
alokp@chromium.orgd300f5b2010-10-14 16:10:20 +00001340 if (!(*p)->getAsTyped()->getAsConstantUnion())
1341 return false;
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001342 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001343
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00001344 return allConstant;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001345}
1346
Olli Etuaho214c2d82015-04-27 14:49:13 +03001347TPublicType TParseContext::addFullySpecifiedType(TQualifier qualifier, bool invariant, TLayoutQualifier layoutQualifier,
Arun Patole7e7e68d2015-05-22 12:02:25 +05301348 const TPublicType &typeSpecifier)
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001349{
1350 TPublicType returnType = typeSpecifier;
1351 returnType.qualifier = qualifier;
Olli Etuaho214c2d82015-04-27 14:49:13 +03001352 returnType.invariant = invariant;
Jamie Madilla5efff92013-06-06 11:56:47 -04001353 returnType.layoutQualifier = layoutQualifier;
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001354
Jamie Madill6e06b1f2015-05-14 10:01:17 -04001355 if (mShaderVersion < 300)
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001356 {
Olli Etuahoc1ac41b2015-07-10 13:53:46 +03001357 if (typeSpecifier.array)
1358 {
1359 error(typeSpecifier.line, "not supported", "first-class array");
1360 recover();
1361 returnType.clearArrayness();
1362 }
1363
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001364 if (qualifier == EvqAttribute && (typeSpecifier.type == EbtBool || typeSpecifier.type == EbtInt))
1365 {
1366 error(typeSpecifier.line, "cannot be bool or int", getQualifierString(qualifier));
1367 recover();
1368 }
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001369
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001370 if ((qualifier == EvqVaryingIn || qualifier == EvqVaryingOut) &&
1371 (typeSpecifier.type == EbtBool || typeSpecifier.type == EbtInt))
1372 {
1373 error(typeSpecifier.line, "cannot be bool or int", getQualifierString(qualifier));
1374 recover();
1375 }
1376 }
1377 else
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001378 {
Olli Etuahoabb0c382015-07-13 12:01:12 +03001379 if (!layoutQualifier.isEmpty())
1380 {
1381 if (globalErrorCheck(typeSpecifier.line, symbolTable.atGlobalLevel(), "layout"))
1382 {
1383 recover();
1384 }
1385 }
Jamie Madillb120eac2013-06-12 14:08:13 -04001386 switch (qualifier)
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001387 {
Jamie Madill19571812013-08-12 15:26:34 -07001388 case EvqSmoothIn:
1389 case EvqSmoothOut:
1390 case EvqVertexOut:
1391 case EvqFragmentIn:
1392 case EvqCentroidOut:
1393 case EvqCentroidIn:
1394 if (typeSpecifier.type == EbtBool)
1395 {
1396 error(typeSpecifier.line, "cannot be bool", getQualifierString(qualifier));
1397 recover();
1398 }
1399 if (typeSpecifier.type == EbtInt || typeSpecifier.type == EbtUInt)
1400 {
1401 error(typeSpecifier.line, "must use 'flat' interpolation here", getQualifierString(qualifier));
1402 recover();
1403 }
1404 break;
1405
1406 case EvqVertexIn:
1407 case EvqFragmentOut:
1408 case EvqFlatIn:
1409 case EvqFlatOut:
Jamie Madillb120eac2013-06-12 14:08:13 -04001410 if (typeSpecifier.type == EbtBool)
1411 {
1412 error(typeSpecifier.line, "cannot be bool", getQualifierString(qualifier));
1413 recover();
1414 }
1415 break;
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001416
Jamie Madillb120eac2013-06-12 14:08:13 -04001417 default: break;
shannonwoods@chromium.org5703d882013-05-30 00:19:38 +00001418 }
shannonwoods@chromium.org0f376ca2013-05-30 00:19:23 +00001419 }
1420
1421 return returnType;
1422}
1423
Olli Etuahofa33d582015-04-09 14:33:12 +03001424TIntermAggregate *TParseContext::parseSingleDeclaration(TPublicType &publicType,
1425 const TSourceLoc &identifierOrTypeLocation,
1426 const TString &identifier)
Jamie Madill60ed9812013-06-06 11:56:46 -04001427{
Olli Etuahofa33d582015-04-09 14:33:12 +03001428 TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, TType(publicType), identifierOrTypeLocation);
Jamie Madill60ed9812013-06-06 11:56:46 -04001429
Olli Etuahobab4c082015-04-24 16:38:49 +03001430 bool emptyDeclaration = (identifier == "");
Olli Etuahofa33d582015-04-09 14:33:12 +03001431
Olli Etuahobab4c082015-04-24 16:38:49 +03001432 mDeferredSingleDeclarationErrorCheck = emptyDeclaration;
1433
1434 if (emptyDeclaration)
1435 {
1436 if (publicType.isUnsizedArray())
1437 {
1438 // ESSL3 spec section 4.1.9: Array declaration which leaves the size unspecified is an error.
1439 // It is assumed that this applies to empty declarations as well.
1440 error(identifierOrTypeLocation, "empty array declaration needs to specify a size", identifier.c_str());
1441 }
1442 }
1443 else
Jamie Madill60ed9812013-06-06 11:56:46 -04001444 {
Olli Etuahofa33d582015-04-09 14:33:12 +03001445 if (singleDeclarationErrorCheck(publicType, identifierOrTypeLocation))
Jamie Madill60ed9812013-06-06 11:56:46 -04001446 recover();
1447
Olli Etuaho376f1b52015-04-13 13:23:41 +03001448 if (nonInitErrorCheck(identifierOrTypeLocation, identifier, &publicType))
Jamie Madill60ed9812013-06-06 11:56:46 -04001449 recover();
1450
Olli Etuaho2935c582015-04-08 14:32:06 +03001451 TVariable *variable = nullptr;
Olli Etuahofa33d582015-04-09 14:33:12 +03001452 if (!declareVariable(identifierOrTypeLocation, identifier, TType(publicType), &variable))
Jamie Madill60ed9812013-06-06 11:56:46 -04001453 recover();
1454
1455 if (variable && symbol)
Jamie Madill60ed9812013-06-06 11:56:46 -04001456 symbol->setId(variable->getUniqueId());
Jamie Madill60ed9812013-06-06 11:56:46 -04001457 }
1458
Olli Etuahoe7847b02015-03-16 11:56:12 +02001459 return intermediate.makeAggregate(symbol, identifierOrTypeLocation);
Jamie Madill60ed9812013-06-06 11:56:46 -04001460}
1461
Olli Etuahoe7847b02015-03-16 11:56:12 +02001462TIntermAggregate *TParseContext::parseSingleArrayDeclaration(TPublicType &publicType,
1463 const TSourceLoc &identifierLocation,
1464 const TString &identifier,
1465 const TSourceLoc &indexLocation,
1466 TIntermTyped *indexExpression)
Jamie Madill60ed9812013-06-06 11:56:46 -04001467{
Olli Etuahofa33d582015-04-09 14:33:12 +03001468 mDeferredSingleDeclarationErrorCheck = false;
1469
1470 if (singleDeclarationErrorCheck(publicType, identifierLocation))
Jamie Madill60ed9812013-06-06 11:56:46 -04001471 recover();
1472
Olli Etuaho376f1b52015-04-13 13:23:41 +03001473 if (nonInitErrorCheck(identifierLocation, identifier, &publicType))
Jamie Madill60ed9812013-06-06 11:56:46 -04001474 recover();
1475
1476 if (arrayTypeErrorCheck(indexLocation, publicType) || arrayQualifierErrorCheck(indexLocation, publicType))
1477 {
1478 recover();
1479 }
1480
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +03001481 TType arrayType(publicType);
Jamie Madill60ed9812013-06-06 11:56:46 -04001482
1483 int size;
1484 if (arraySizeErrorCheck(identifierLocation, indexExpression, size))
1485 {
1486 recover();
1487 }
Olli Etuahoe7847b02015-03-16 11:56:12 +02001488 // Make the type an array even if size check failed.
1489 // This ensures useless error messages regarding the variable's non-arrayness won't follow.
1490 arrayType.setArraySize(size);
Jamie Madill60ed9812013-06-06 11:56:46 -04001491
Olli Etuaho2935c582015-04-08 14:32:06 +03001492 TVariable *variable = nullptr;
1493 if (!declareVariable(identifierLocation, identifier, arrayType, &variable))
Jamie Madill60ed9812013-06-06 11:56:46 -04001494 recover();
1495
Olli Etuahoe7847b02015-03-16 11:56:12 +02001496 TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, arrayType, identifierLocation);
Jamie Madill60ed9812013-06-06 11:56:46 -04001497 if (variable && symbol)
Jamie Madill60ed9812013-06-06 11:56:46 -04001498 symbol->setId(variable->getUniqueId());
Jamie Madill60ed9812013-06-06 11:56:46 -04001499
Olli Etuahoe7847b02015-03-16 11:56:12 +02001500 return intermediate.makeAggregate(symbol, identifierLocation);
Jamie Madill60ed9812013-06-06 11:56:46 -04001501}
1502
Jamie Madill06145232015-05-13 13:10:01 -04001503TIntermAggregate *TParseContext::parseSingleInitDeclaration(const TPublicType &publicType,
Olli Etuahoe7847b02015-03-16 11:56:12 +02001504 const TSourceLoc &identifierLocation,
1505 const TString &identifier,
1506 const TSourceLoc &initLocation,
1507 TIntermTyped *initializer)
Jamie Madill60ed9812013-06-06 11:56:46 -04001508{
Olli Etuahofa33d582015-04-09 14:33:12 +03001509 mDeferredSingleDeclarationErrorCheck = false;
1510
1511 if (singleDeclarationErrorCheck(publicType, identifierLocation))
Jamie Madill60ed9812013-06-06 11:56:46 -04001512 recover();
1513
Olli Etuahoe7847b02015-03-16 11:56:12 +02001514 TIntermNode *intermNode = nullptr;
1515 if (!executeInitializer(identifierLocation, identifier, publicType, initializer, &intermNode))
Jamie Madill60ed9812013-06-06 11:56:46 -04001516 {
1517 //
1518 // Build intermediate representation
1519 //
Olli Etuahoe7847b02015-03-16 11:56:12 +02001520 return intermNode ? intermediate.makeAggregate(intermNode, initLocation) : nullptr;
Jamie Madill60ed9812013-06-06 11:56:46 -04001521 }
1522 else
1523 {
1524 recover();
Olli Etuahoe7847b02015-03-16 11:56:12 +02001525 return nullptr;
Jamie Madill60ed9812013-06-06 11:56:46 -04001526 }
1527}
1528
Olli Etuaho3875ffd2015-04-10 16:45:14 +03001529TIntermAggregate *TParseContext::parseSingleArrayInitDeclaration(TPublicType &publicType,
1530 const TSourceLoc &identifierLocation,
1531 const TString &identifier,
1532 const TSourceLoc &indexLocation,
1533 TIntermTyped *indexExpression,
1534 const TSourceLoc &initLocation,
1535 TIntermTyped *initializer)
1536{
1537 mDeferredSingleDeclarationErrorCheck = false;
1538
1539 if (singleDeclarationErrorCheck(publicType, identifierLocation))
1540 recover();
1541
1542 if (arrayTypeErrorCheck(indexLocation, publicType) || arrayQualifierErrorCheck(indexLocation, publicType))
1543 {
1544 recover();
1545 }
1546
1547 TPublicType arrayType(publicType);
1548
Olli Etuaho376f1b52015-04-13 13:23:41 +03001549 int size = 0;
1550 // If indexExpression is nullptr, then the array will eventually get its size implicitly from the initializer.
1551 if (indexExpression != nullptr && arraySizeErrorCheck(identifierLocation, indexExpression, size))
Olli Etuaho3875ffd2015-04-10 16:45:14 +03001552 {
1553 recover();
1554 }
1555 // Make the type an array even if size check failed.
1556 // This ensures useless error messages regarding the variable's non-arrayness won't follow.
1557 arrayType.setArraySize(size);
1558
1559 // initNode will correspond to the whole of "type b[n] = initializer".
1560 TIntermNode *initNode = nullptr;
1561 if (!executeInitializer(identifierLocation, identifier, arrayType, initializer, &initNode))
1562 {
1563 return initNode ? intermediate.makeAggregate(initNode, initLocation) : nullptr;
1564 }
1565 else
1566 {
1567 recover();
1568 return nullptr;
1569 }
1570}
1571
Olli Etuahoe7847b02015-03-16 11:56:12 +02001572TIntermAggregate *TParseContext::parseInvariantDeclaration(const TSourceLoc &invariantLoc,
Jamie Madill47e3ec02014-08-20 16:38:33 -04001573 const TSourceLoc &identifierLoc,
1574 const TString *identifier,
1575 const TSymbol *symbol)
1576{
Jamie Madill3b5c2da2014-08-19 15:23:32 -04001577 // invariant declaration
Jamie Madill47e3ec02014-08-20 16:38:33 -04001578 if (globalErrorCheck(invariantLoc, symbolTable.atGlobalLevel(), "invariant varying"))
1579 {
1580 recover();
1581 }
1582
1583 if (!symbol)
1584 {
1585 error(identifierLoc, "undeclared identifier declared as invariant", identifier->c_str());
1586 recover();
Olli Etuahoe7847b02015-03-16 11:56:12 +02001587 return nullptr;
Jamie Madill47e3ec02014-08-20 16:38:33 -04001588 }
1589 else
1590 {
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001591 const TString kGlFrontFacing("gl_FrontFacing");
1592 if (*identifier == kGlFrontFacing)
1593 {
1594 error(identifierLoc, "identifier should not be declared as invariant", identifier->c_str());
1595 recover();
Olli Etuahoe7847b02015-03-16 11:56:12 +02001596 return nullptr;
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001597 }
Jamie Madill2c433252014-12-03 12:36:54 -05001598 symbolTable.addInvariantVarying(std::string(identifier->c_str()));
Jamie Madill3b5c2da2014-08-19 15:23:32 -04001599 const TVariable *variable = getNamedVariable(identifierLoc, identifier, symbol);
1600 ASSERT(variable);
1601 const TType &type = variable->getType();
1602 TIntermSymbol *intermSymbol = intermediate.addSymbol(variable->getUniqueId(),
1603 *identifier, type, identifierLoc);
1604
1605 TIntermAggregate *aggregate = intermediate.makeAggregate(intermSymbol, identifierLoc);
1606 aggregate->setOp(EOpInvariantDeclaration);
1607 return aggregate;
Jamie Madill47e3ec02014-08-20 16:38:33 -04001608 }
1609}
1610
Olli Etuahoe7847b02015-03-16 11:56:12 +02001611TIntermAggregate *TParseContext::parseDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration,
1612 const TSourceLoc &identifierLocation, const TString &identifier)
Jamie Madill502d66f2013-06-20 11:55:52 -04001613{
Olli Etuahofa33d582015-04-09 14:33:12 +03001614 // If the declaration starting this declarator list was empty (example: int,), some checks were not performed.
1615 if (mDeferredSingleDeclarationErrorCheck)
1616 {
1617 if (singleDeclarationErrorCheck(publicType, identifierLocation))
1618 recover();
1619 mDeferredSingleDeclarationErrorCheck = false;
1620 }
1621
Jamie Madill0bd18df2013-06-20 11:55:52 -04001622 if (locationDeclaratorListCheck(identifierLocation, publicType))
1623 recover();
1624
Olli Etuaho376f1b52015-04-13 13:23:41 +03001625 if (nonInitErrorCheck(identifierLocation, identifier, &publicType))
Jamie Madill502d66f2013-06-20 11:55:52 -04001626 recover();
1627
Olli Etuaho2935c582015-04-08 14:32:06 +03001628 TVariable *variable = nullptr;
1629 if (!declareVariable(identifierLocation, identifier, TType(publicType), &variable))
Jamie Madill502d66f2013-06-20 11:55:52 -04001630 recover();
Olli Etuahoe7847b02015-03-16 11:56:12 +02001631
1632 TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, TType(publicType), identifierLocation);
1633 if (variable && symbol)
Jamie Madill502d66f2013-06-20 11:55:52 -04001634 symbol->setId(variable->getUniqueId());
1635
Olli Etuahoe7847b02015-03-16 11:56:12 +02001636 return intermediate.growAggregate(aggregateDeclaration, symbol, identifierLocation);
Jamie Madill502d66f2013-06-20 11:55:52 -04001637}
1638
Olli Etuahoe7847b02015-03-16 11:56:12 +02001639TIntermAggregate *TParseContext::parseArrayDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration,
1640 const TSourceLoc &identifierLocation, const TString &identifier,
1641 const TSourceLoc &arrayLocation, TIntermTyped *indexExpression)
Jamie Madill502d66f2013-06-20 11:55:52 -04001642{
Olli Etuahofa33d582015-04-09 14:33:12 +03001643 // If the declaration starting this declarator list was empty (example: int,), some checks were not performed.
1644 if (mDeferredSingleDeclarationErrorCheck)
1645 {
1646 if (singleDeclarationErrorCheck(publicType, identifierLocation))
1647 recover();
1648 mDeferredSingleDeclarationErrorCheck = false;
1649 }
Jamie Madill502d66f2013-06-20 11:55:52 -04001650
Jamie Madill0bd18df2013-06-20 11:55:52 -04001651 if (locationDeclaratorListCheck(identifierLocation, publicType))
1652 recover();
1653
Olli Etuaho376f1b52015-04-13 13:23:41 +03001654 if (nonInitErrorCheck(identifierLocation, identifier, &publicType))
Jamie Madill502d66f2013-06-20 11:55:52 -04001655 recover();
1656
1657 if (arrayTypeErrorCheck(arrayLocation, publicType) || arrayQualifierErrorCheck(arrayLocation, publicType))
1658 {
1659 recover();
1660 }
Olli Etuaho93a90fd2015-04-07 18:14:07 +03001661 else
Jamie Madill502d66f2013-06-20 11:55:52 -04001662 {
Olli Etuahoe7847b02015-03-16 11:56:12 +02001663 TType arrayType = TType(publicType);
Jamie Madill502d66f2013-06-20 11:55:52 -04001664 int size;
1665 if (arraySizeErrorCheck(arrayLocation, indexExpression, size))
Olli Etuahoe7847b02015-03-16 11:56:12 +02001666 {
Jamie Madill502d66f2013-06-20 11:55:52 -04001667 recover();
Olli Etuahoe7847b02015-03-16 11:56:12 +02001668 }
Olli Etuaho693c9aa2015-04-07 17:50:36 +03001669 arrayType.setArraySize(size);
Olli Etuahoe7847b02015-03-16 11:56:12 +02001670
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +03001671 TVariable *variable = nullptr;
Olli Etuahoe7847b02015-03-16 11:56:12 +02001672 if (!declareVariable(identifierLocation, identifier, arrayType, &variable))
Jamie Madill502d66f2013-06-20 11:55:52 -04001673 recover();
Jamie Madill502d66f2013-06-20 11:55:52 -04001674
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +03001675 TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, arrayType, identifierLocation);
1676 if (variable && symbol)
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +03001677 symbol->setId(variable->getUniqueId());
Olli Etuahoe7847b02015-03-16 11:56:12 +02001678
1679 return intermediate.growAggregate(aggregateDeclaration, symbol, identifierLocation);
Jamie Madill502d66f2013-06-20 11:55:52 -04001680 }
Jamie Madill502d66f2013-06-20 11:55:52 -04001681
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +03001682 return nullptr;
Jamie Madill502d66f2013-06-20 11:55:52 -04001683}
1684
Jamie Madill06145232015-05-13 13:10:01 -04001685TIntermAggregate *TParseContext::parseInitDeclarator(const TPublicType &publicType, TIntermAggregate *aggregateDeclaration,
Olli Etuahoe7847b02015-03-16 11:56:12 +02001686 const TSourceLoc &identifierLocation, const TString &identifier,
1687 const TSourceLoc &initLocation, TIntermTyped *initializer)
Jamie Madill502d66f2013-06-20 11:55:52 -04001688{
Olli Etuahofa33d582015-04-09 14:33:12 +03001689 // If the declaration starting this declarator list was empty (example: int,), some checks were not performed.
1690 if (mDeferredSingleDeclarationErrorCheck)
1691 {
1692 if (singleDeclarationErrorCheck(publicType, identifierLocation))
1693 recover();
1694 mDeferredSingleDeclarationErrorCheck = false;
1695 }
Jamie Madill502d66f2013-06-20 11:55:52 -04001696
Jamie Madill0bd18df2013-06-20 11:55:52 -04001697 if (locationDeclaratorListCheck(identifierLocation, publicType))
1698 recover();
1699
Olli Etuahoe7847b02015-03-16 11:56:12 +02001700 TIntermNode *intermNode = nullptr;
1701 if (!executeInitializer(identifierLocation, identifier, publicType, initializer, &intermNode))
Jamie Madill502d66f2013-06-20 11:55:52 -04001702 {
1703 //
1704 // build the intermediate representation
1705 //
1706 if (intermNode)
1707 {
Olli Etuahoe7847b02015-03-16 11:56:12 +02001708 return intermediate.growAggregate(aggregateDeclaration, intermNode, initLocation);
Jamie Madill502d66f2013-06-20 11:55:52 -04001709 }
1710 else
1711 {
Olli Etuahoe7847b02015-03-16 11:56:12 +02001712 return aggregateDeclaration;
Jamie Madill502d66f2013-06-20 11:55:52 -04001713 }
1714 }
1715 else
1716 {
1717 recover();
Olli Etuahoe7847b02015-03-16 11:56:12 +02001718 return nullptr;
Jamie Madill502d66f2013-06-20 11:55:52 -04001719 }
1720}
1721
Jamie Madill06145232015-05-13 13:10:01 -04001722TIntermAggregate *TParseContext::parseArrayInitDeclarator(const TPublicType &publicType,
Olli Etuaho3875ffd2015-04-10 16:45:14 +03001723 TIntermAggregate *aggregateDeclaration,
Arun Patole7e7e68d2015-05-22 12:02:25 +05301724 const TSourceLoc &identifierLocation,
Olli Etuaho3875ffd2015-04-10 16:45:14 +03001725 const TString &identifier,
Arun Patole7e7e68d2015-05-22 12:02:25 +05301726 const TSourceLoc &indexLocation,
Olli Etuaho3875ffd2015-04-10 16:45:14 +03001727 TIntermTyped *indexExpression,
1728 const TSourceLoc &initLocation, TIntermTyped *initializer)
1729{
1730 // If the declaration starting this declarator list was empty (example: int,), some checks were not performed.
1731 if (mDeferredSingleDeclarationErrorCheck)
1732 {
1733 if (singleDeclarationErrorCheck(publicType, identifierLocation))
1734 recover();
1735 mDeferredSingleDeclarationErrorCheck = false;
1736 }
1737
1738 if (locationDeclaratorListCheck(identifierLocation, publicType))
1739 recover();
1740
1741 if (arrayTypeErrorCheck(indexLocation, publicType) || arrayQualifierErrorCheck(indexLocation, publicType))
1742 {
1743 recover();
1744 }
1745
1746 TPublicType arrayType(publicType);
1747
Olli Etuaho376f1b52015-04-13 13:23:41 +03001748 int size = 0;
1749 // If indexExpression is nullptr, then the array will eventually get its size implicitly from the initializer.
1750 if (indexExpression != nullptr && arraySizeErrorCheck(identifierLocation, indexExpression, size))
Olli Etuaho3875ffd2015-04-10 16:45:14 +03001751 {
1752 recover();
1753 }
1754 // Make the type an array even if size check failed.
1755 // This ensures useless error messages regarding the variable's non-arrayness won't follow.
1756 arrayType.setArraySize(size);
1757
1758 // initNode will correspond to the whole of "b[n] = initializer".
1759 TIntermNode *initNode = nullptr;
1760 if (!executeInitializer(identifierLocation, identifier, arrayType, initializer, &initNode))
1761 {
1762 if (initNode)
1763 {
1764 return intermediate.growAggregate(aggregateDeclaration, initNode, initLocation);
1765 }
1766 else
1767 {
1768 return aggregateDeclaration;
1769 }
1770 }
1771 else
1772 {
1773 recover();
1774 return nullptr;
1775 }
1776}
1777
Jamie Madilla295edf2013-06-06 11:56:48 -04001778void TParseContext::parseGlobalLayoutQualifier(const TPublicType &typeQualifier)
1779{
1780 if (typeQualifier.qualifier != EvqUniform)
1781 {
Arun Patole7e7e68d2015-05-22 12:02:25 +05301782 error(typeQualifier.line,
1783 "invalid qualifier:",
1784 getQualifierString(typeQualifier.qualifier), "global layout must be uniform");
Jamie Madilla295edf2013-06-06 11:56:48 -04001785 recover();
1786 return;
1787 }
1788
1789 const TLayoutQualifier layoutQualifier = typeQualifier.layoutQualifier;
1790 ASSERT(!layoutQualifier.isEmpty());
1791
Jamie Madill6e06b1f2015-05-14 10:01:17 -04001792 if (mShaderVersion < 300)
Jamie Madilla295edf2013-06-06 11:56:48 -04001793 {
1794 error(typeQualifier.line, "layout qualifiers supported in GLSL ES 3.00 only", "layout");
1795 recover();
1796 return;
1797 }
1798
1799 if (layoutLocationErrorCheck(typeQualifier.line, typeQualifier.layoutQualifier))
1800 {
1801 recover();
1802 return;
1803 }
1804
Jamie Madill099c0f32013-06-20 11:55:52 -04001805 if (layoutQualifier.matrixPacking != EmpUnspecified)
1806 {
Jamie Madill6e06b1f2015-05-14 10:01:17 -04001807 mDefaultMatrixPacking = layoutQualifier.matrixPacking;
Jamie Madill099c0f32013-06-20 11:55:52 -04001808 }
1809
Geoff Langc6856732014-02-11 09:38:55 -05001810 if (layoutQualifier.blockStorage != EbsUnspecified)
Jamie Madill1566ef72013-06-20 11:55:54 -04001811 {
Jamie Madill6e06b1f2015-05-14 10:01:17 -04001812 mDefaultBlockStorage = layoutQualifier.blockStorage;
Jamie Madill1566ef72013-06-20 11:55:54 -04001813 }
Jamie Madilla295edf2013-06-06 11:56:48 -04001814}
1815
Jamie Madill185fb402015-06-12 15:48:48 -04001816void TParseContext::parseFunctionPrototype(const TSourceLoc &location,
1817 TFunction *function,
1818 TIntermAggregate **aggregateOut)
1819{
1820 const TSymbol *builtIn = symbolTable.findBuiltIn(function->getMangledName(), getShaderVersion());
1821
1822 if (builtIn)
1823 {
1824 error(location, "built-in functions cannot be redefined", function->getName().c_str());
1825 recover();
1826 }
1827
1828 TFunction* prevDec = static_cast<TFunction*>(symbolTable.find(function->getMangledName(), getShaderVersion()));
1829 //
1830 // Note: 'prevDec' could be 'function' if this is the first time we've seen function
1831 // as it would have just been put in the symbol table. Otherwise, we're looking up
1832 // an earlier occurance.
1833 //
1834 if (prevDec->isDefined())
1835 {
1836 // Then this function already has a body.
1837 error(location, "function already has a body", function->getName().c_str());
1838 recover();
1839 }
1840 prevDec->setDefined();
1841 //
1842 // Overload the unique ID of the definition to be the same unique ID as the declaration.
1843 // Eventually we will probably want to have only a single definition and just swap the
1844 // arguments to be the definition's arguments.
1845 //
1846 function->setUniqueId(prevDec->getUniqueId());
1847
1848 // Raise error message if main function takes any parameters or return anything other than void
1849 if (function->getName() == "main")
1850 {
1851 if (function->getParamCount() > 0)
1852 {
1853 error(location, "function cannot take any parameter(s)", function->getName().c_str());
1854 recover();
1855 }
1856 if (function->getReturnType().getBasicType() != EbtVoid)
1857 {
1858 error(location, "", function->getReturnType().getBasicString(), "main function cannot return a value");
1859 recover();
1860 }
1861 }
1862
1863 //
1864 // Remember the return type for later checking for RETURN statements.
1865 //
1866 setCurrentFunctionType(&(prevDec->getReturnType()));
1867 setFunctionReturnsValue(false);
1868
1869 //
1870 // Insert parameters into the symbol table.
1871 // If the parameter has no name, it's not an error, just don't insert it
1872 // (could be used for unused args).
1873 //
1874 // Also, accumulate the list of parameters into the HIL, so lower level code
1875 // knows where to find parameters.
1876 //
1877 TIntermAggregate *paramNodes = new TIntermAggregate;
1878 for (size_t i = 0; i < function->getParamCount(); i++)
1879 {
1880 const TConstParameter &param = function->getParam(i);
1881 if (param.name != 0)
1882 {
1883 TVariable *variable = new TVariable(param.name, *param.type);
1884 //
1885 // Insert the parameters with name in the symbol table.
1886 //
1887 if (!symbolTable.declare(variable)) {
1888 error(location, "redefinition", variable->getName().c_str());
1889 recover();
1890 delete variable;
1891 }
1892
1893 //
1894 // Add the parameter to the HIL
1895 //
1896 TIntermSymbol *symbol = intermediate.addSymbol(variable->getUniqueId(),
1897 variable->getName(),
1898 variable->getType(), location);
1899
1900 paramNodes = intermediate.growAggregate(paramNodes, symbol, location);
1901 }
1902 else
1903 {
1904 paramNodes = intermediate.growAggregate(paramNodes, intermediate.addSymbol(0, "", *param.type, location), location);
1905 }
1906 }
1907 intermediate.setAggregateOperator(paramNodes, EOpParameters, location);
1908 *aggregateOut = paramNodes;
1909 setLoopNestingLevel(0);
1910}
1911
1912TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location,
1913 TFunction *function)
1914{
1915 //
1916 // Multiple declarations of the same function are allowed.
1917 //
1918 // If this is a definition, the definition production code will check for redefinitions
1919 // (we don't know at this point if it's a definition or not).
1920 //
1921 // Redeclarations are allowed. But, return types and parameter qualifiers must match.
1922 //
1923 TFunction *prevDec = static_cast<TFunction*>(symbolTable.find(function->getMangledName(), getShaderVersion()));
1924 if (prevDec)
1925 {
1926 if (prevDec->getReturnType() != function->getReturnType())
1927 {
1928 error(location,
1929 "overloaded functions must have the same return type",
1930 function->getReturnType().getBasicString());
1931 recover();
1932 }
1933 for (size_t i = 0; i < prevDec->getParamCount(); ++i)
1934 {
1935 if (prevDec->getParam(i).type->getQualifier() != function->getParam(i).type->getQualifier())
1936 {
1937 error(location,
1938 "overloaded functions must have the same parameter qualifiers",
1939 function->getParam(i).type->getQualifierString());
1940 recover();
1941 }
1942 }
1943 }
1944
1945 //
1946 // Check for previously declared variables using the same name.
1947 //
1948 TSymbol *prevSym = symbolTable.find(function->getName(), getShaderVersion());
1949 if (prevSym)
1950 {
1951 if (!prevSym->isFunction())
1952 {
1953 error(location, "redefinition", function->getName().c_str(), "function");
1954 recover();
1955 }
1956 }
1957 else
1958 {
1959 // Insert the unmangled name to detect potential future redefinition as a variable.
1960 TFunction *newFunction = new TFunction(NewPoolTString(function->getName().c_str()), &function->getReturnType());
1961 symbolTable.getOuterLevel()->insertUnmangled(newFunction);
1962 }
1963
1964 // We're at the inner scope level of the function's arguments and body statement.
1965 // Add the function prototype to the surrounding scope instead.
1966 symbolTable.getOuterLevel()->insert(function);
1967
1968 //
1969 // If this is a redeclaration, it could also be a definition,
1970 // in which case, we want to use the variable names from this one, and not the one that's
1971 // being redeclared. So, pass back up this declaration, not the one in the symbol table.
1972 //
1973 return function;
1974}
1975
Jamie Madill06145232015-05-13 13:10:01 -04001976TFunction *TParseContext::addConstructorFunc(const TPublicType &publicTypeIn)
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00001977{
Jamie Madill06145232015-05-13 13:10:01 -04001978 TPublicType publicType = publicTypeIn;
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00001979 TOperator op = EOpNull;
1980 if (publicType.userDef)
1981 {
1982 op = EOpConstructStruct;
1983 }
1984 else
1985 {
1986 switch (publicType.type)
1987 {
1988 case EbtFloat:
1989 if (publicType.isMatrix())
1990 {
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00001991 switch(publicType.getCols())
1992 {
Alexis Hetu07e57df2015-06-16 16:55:52 -04001993 case 2:
1994 switch(publicType.getRows())
1995 {
1996 case 2: op = EOpConstructMat2; break;
1997 case 3: op = EOpConstructMat2x3; break;
1998 case 4: op = EOpConstructMat2x4; break;
1999 }
2000 break;
2001 case 3:
2002 switch(publicType.getRows())
2003 {
2004 case 2: op = EOpConstructMat3x2; break;
2005 case 3: op = EOpConstructMat3; break;
2006 case 4: op = EOpConstructMat3x4; break;
2007 }
2008 break;
2009 case 4:
2010 switch(publicType.getRows())
2011 {
2012 case 2: op = EOpConstructMat4x2; break;
2013 case 3: op = EOpConstructMat4x3; break;
2014 case 4: op = EOpConstructMat4; break;
2015 }
2016 break;
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00002017 }
2018 }
2019 else
2020 {
2021 switch(publicType.getNominalSize())
2022 {
Jamie Madill28b97422013-07-08 14:01:38 -04002023 case 1: op = EOpConstructFloat; break;
2024 case 2: op = EOpConstructVec2; break;
2025 case 3: op = EOpConstructVec3; break;
2026 case 4: op = EOpConstructVec4; break;
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00002027 }
2028 }
2029 break;
2030
2031 case EbtInt:
2032 switch(publicType.getNominalSize())
2033 {
Jamie Madill28b97422013-07-08 14:01:38 -04002034 case 1: op = EOpConstructInt; break;
2035 case 2: op = EOpConstructIVec2; break;
2036 case 3: op = EOpConstructIVec3; break;
2037 case 4: op = EOpConstructIVec4; break;
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00002038 }
2039 break;
2040
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +00002041 case EbtUInt:
2042 switch(publicType.getNominalSize())
2043 {
Jamie Madill28b97422013-07-08 14:01:38 -04002044 case 1: op = EOpConstructUInt; break;
2045 case 2: op = EOpConstructUVec2; break;
2046 case 3: op = EOpConstructUVec3; break;
2047 case 4: op = EOpConstructUVec4; break;
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +00002048 }
2049 break;
2050
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00002051 case EbtBool:
2052 switch(publicType.getNominalSize())
2053 {
Jamie Madill28b97422013-07-08 14:01:38 -04002054 case 1: op = EOpConstructBool; break;
2055 case 2: op = EOpConstructBVec2; break;
2056 case 3: op = EOpConstructBVec3; break;
2057 case 4: op = EOpConstructBVec4; break;
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00002058 }
2059 break;
2060
2061 default: break;
2062 }
2063
2064 if (op == EOpNull)
2065 {
2066 error(publicType.line, "cannot construct this type", getBasicString(publicType.type));
2067 recover();
2068 publicType.type = EbtFloat;
2069 op = EOpConstructFloat;
2070 }
2071 }
2072
2073 TString tempString;
Dmitry Skiba7f17a502015-06-22 15:08:39 -07002074 const TType *type = new TType(publicType);
shannonwoods@chromium.org18851132013-05-30 00:19:54 +00002075 return new TFunction(&tempString, type, op);
2076}
2077
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002078// This function is used to test for the correctness of the parameters passed to various constructor functions
Arun Patole7e7e68d2015-05-22 12:02:25 +05302079// and also convert them to the right datatype if it is allowed and required.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002080//
2081// Returns 0 for an error or the constructed node (aggregate or typed) for no error.
2082//
Arun Patole7e7e68d2015-05-22 12:02:25 +05302083TIntermTyped *TParseContext::addConstructor(TIntermNode *arguments, TType *type, TOperator op, TFunction *fnCall,
2084 const TSourceLoc &line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002085{
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04002086 TIntermAggregate *aggregateArguments = arguments->getAsAggregate();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002087
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04002088 if (!aggregateArguments)
2089 {
2090 aggregateArguments = new TIntermAggregate;
Zhenyao Moe40d1e92014-07-16 17:40:36 -07002091 aggregateArguments->getSequence()->push_back(arguments);
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04002092 }
2093
Olli Etuahof40319e2015-03-10 14:33:00 +02002094 if (type->isArray())
2095 {
2096 // GLSL ES 3.00 section 5.4.4: Each argument must be the same type as the element type of the array.
2097 TIntermSequence *args = aggregateArguments->getSequence();
2098 for (size_t i = 0; i < args->size(); i++)
2099 {
2100 const TType &argType = (*args)[i]->getAsTyped()->getType();
2101 // It has already been checked that the argument is not an array.
2102 ASSERT(!argType.isArray());
2103 if (!argType.sameElementType(*type))
2104 {
2105 error(line, "Array constructor argument has an incorrect type", "Error");
2106 recover();
2107 return nullptr;
2108 }
2109 }
2110 }
2111 else if (op == EOpConstructStruct)
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04002112 {
2113 const TFieldList &fields = type->getStruct()->fields();
Zhenyao Moe40d1e92014-07-16 17:40:36 -07002114 TIntermSequence *args = aggregateArguments->getSequence();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002115
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04002116 for (size_t i = 0; i < fields.size(); i++)
2117 {
Nicolas Capensffd73872014-08-21 13:49:16 -04002118 if (i >= args->size() || (*args)[i]->getAsTyped()->getType() != *fields[i]->type())
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04002119 {
2120 error(line, "Structure constructor arguments do not match structure fields", "Error");
2121 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002122
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04002123 return 0;
2124 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002125 }
2126 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002127
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04002128 // Turn the argument list itself into a constructor
Olli Etuaho21203702014-11-13 16:16:21 +02002129 TIntermAggregate *constructor = intermediate.setAggregateOperator(aggregateArguments, op, line);
2130 TIntermTyped *constConstructor = foldConstConstructor(constructor, *type);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002131 if (constConstructor)
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04002132 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002133 return constConstructor;
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04002134 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002135
Olli Etuaho21203702014-11-13 16:16:21 +02002136 // Structs should not be precision qualified, the individual members may be.
2137 // Built-in types on the other hand should be precision qualified.
2138 if (op != EOpConstructStruct)
2139 {
2140 constructor->setPrecisionFromChildren();
2141 type->setPrecision(constructor->getPrecision());
2142 }
2143
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002144 return constructor;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002145}
2146
Arun Patole7e7e68d2015-05-22 12:02:25 +05302147TIntermTyped *TParseContext::foldConstConstructor(TIntermAggregate *aggrNode, const TType &type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002148{
Olli Etuahof40319e2015-03-10 14:33:00 +02002149 // TODO: Add support for folding array constructors
2150 bool canBeFolded = areAllChildConst(aggrNode) && !type.isArray();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002151 aggrNode->setType(type);
Arun Patole7e7e68d2015-05-22 12:02:25 +05302152 if (canBeFolded)
2153 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002154 bool returnVal = false;
Arun Patole7e7e68d2015-05-22 12:02:25 +05302155 TConstantUnion *unionArray = new TConstantUnion[type.getObjectSize()];
2156 if (aggrNode->getSequence()->size() == 1)
2157 {
2158 returnVal = intermediate.parseConstTree(aggrNode->getLine(), aggrNode, unionArray, aggrNode->getOp(), type,
2159 true);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002160 }
Arun Patole7e7e68d2015-05-22 12:02:25 +05302161 else
2162 {
2163 returnVal = intermediate.parseConstTree(aggrNode->getLine(), aggrNode, unionArray, aggrNode->getOp(),
2164 type);
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002165 }
2166 if (returnVal)
2167 return 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002168
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002169 return intermediate.addConstantUnion(unionArray, type, aggrNode->getLine());
2170 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002171
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002172 return 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002173}
2174
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002175//
2176// This function returns the tree representation for the vector field(s) being accessed from contant vector.
2177// If only one component of vector is accessed (v.x or v[0] where v is a contant vector), then a contant node is
2178// returned, else an aggregate node is returned (for v.xy). The input to this function could either be the symbol
Arun Patole7e7e68d2015-05-22 12:02:25 +05302179// node or it could be the intermediate tree representation of accessing fields in a constant structure or column of
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002180// a constant matrix.
2181//
Arun Patole7e7e68d2015-05-22 12:02:25 +05302182TIntermTyped *TParseContext::addConstVectorNode(TVectorFields &fields, TIntermTyped *node, const TSourceLoc &line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002183{
Arun Patole7e7e68d2015-05-22 12:02:25 +05302184 TIntermTyped *typedNode;
2185 TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002186
Jamie Madillb11e2482015-05-04 14:21:22 -04002187 const TConstantUnion *unionArray;
Arun Patole7e7e68d2015-05-22 12:02:25 +05302188 if (tempConstantNode)
2189 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002190 unionArray = tempConstantNode->getUnionArrayPointer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002191
Arun Patole7e7e68d2015-05-22 12:02:25 +05302192 if (!unionArray)
2193 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002194 return node;
2195 }
Arun Patole7e7e68d2015-05-22 12:02:25 +05302196 }
2197 else
2198 { // 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 +00002199 error(line, "Cannot offset into the vector", "Error");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002200 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002201
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002202 return 0;
2203 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002204
Arun Patole7e7e68d2015-05-22 12:02:25 +05302205 TConstantUnion *constArray = new TConstantUnion[fields.num];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002206
Arun Patole7e7e68d2015-05-22 12:02:25 +05302207 for (int i = 0; i < fields.num; i++)
2208 {
2209 if (fields.offsets[i] >= node->getType().getNominalSize())
2210 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00002211 std::stringstream extraInfoStream;
2212 extraInfoStream << "vector field selection out of range '" << fields.offsets[i] << "'";
2213 std::string extraInfo = extraInfoStream.str();
2214 error(line, "", "[", extraInfo.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002215 recover();
2216 fields.offsets[i] = 0;
2217 }
Arun Patole7e7e68d2015-05-22 12:02:25 +05302218
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002219 constArray[i] = unionArray[fields.offsets[i]];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002220
Arun Patole7e7e68d2015-05-22 12:02:25 +05302221 }
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002222 typedNode = intermediate.addConstantUnion(constArray, node->getType(), line);
2223 return typedNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002224}
2225
2226//
2227// This function returns the column being accessed from a constant matrix. The values are retrieved from
Arun Patole7e7e68d2015-05-22 12:02:25 +05302228// the symbol table and parse-tree is built for a vector (each column of a matrix is a vector). The input
2229// to the function could either be a symbol node (m[0] where m is a constant matrix)that represents a
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002230// constant matrix or it could be the tree representation of the constant matrix (s.m1[0] where s is a constant structure)
2231//
Arun Patole7e7e68d2015-05-22 12:02:25 +05302232TIntermTyped *TParseContext::addConstMatrixNode(int index, TIntermTyped *node, const TSourceLoc &line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002233{
Arun Patole7e7e68d2015-05-22 12:02:25 +05302234 TIntermTyped *typedNode;
2235 TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002236
Arun Patole7e7e68d2015-05-22 12:02:25 +05302237 if (index >= node->getType().getCols())
2238 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00002239 std::stringstream extraInfoStream;
2240 extraInfoStream << "matrix field selection out of range '" << index << "'";
2241 std::string extraInfo = extraInfoStream.str();
2242 error(line, "", "[", extraInfo.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002243 recover();
2244 index = 0;
2245 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002246
Arun Patole7e7e68d2015-05-22 12:02:25 +05302247 if (tempConstantNode)
2248 {
Jamie Madillb11e2482015-05-04 14:21:22 -04002249 TConstantUnion *unionArray = tempConstantNode->getUnionArrayPointer();
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00002250 int size = tempConstantNode->getType().getCols();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002251 typedNode = intermediate.addConstantUnion(&unionArray[size*index], tempConstantNode->getType(), line);
Arun Patole7e7e68d2015-05-22 12:02:25 +05302252 }
2253 else
2254 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00002255 error(line, "Cannot offset into the matrix", "Error");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002256 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002257
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002258 return 0;
2259 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002260
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002261 return typedNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002262}
2263
2264
2265//
2266// This function returns an element of an array accessed from a constant array. The values are retrieved from
Arun Patole7e7e68d2015-05-22 12:02:25 +05302267// the symbol table and parse-tree is built for the type of the element. The input
2268// to the function could either be a symbol node (a[0] where a is a constant array)that represents a
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002269// constant array or it could be the tree representation of the constant array (s.a1[0] where s is a constant structure)
2270//
Arun Patole7e7e68d2015-05-22 12:02:25 +05302271TIntermTyped *TParseContext::addConstArrayNode(int index, TIntermTyped *node, const TSourceLoc &line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002272{
Arun Patole7e7e68d2015-05-22 12:02:25 +05302273 TIntermTyped *typedNode;
2274 TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002275 TType arrayElementType = node->getType();
2276 arrayElementType.clearArrayness();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002277
Arun Patole7e7e68d2015-05-22 12:02:25 +05302278 if (index >= node->getType().getArraySize())
2279 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00002280 std::stringstream extraInfoStream;
2281 extraInfoStream << "array field selection out of range '" << index << "'";
2282 std::string extraInfo = extraInfoStream.str();
2283 error(line, "", "[", extraInfo.c_str());
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002284 recover();
2285 index = 0;
2286 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002287
Arun Patole7e7e68d2015-05-22 12:02:25 +05302288 if (tempConstantNode)
2289 {
Jamie Madill94bf7f22013-07-08 13:31:15 -04002290 size_t arrayElementSize = arrayElementType.getObjectSize();
Arun Patole7e7e68d2015-05-22 12:02:25 +05302291 TConstantUnion *unionArray = tempConstantNode->getUnionArrayPointer();
2292 typedNode = intermediate.addConstantUnion(&unionArray[arrayElementSize * index], tempConstantNode->getType(),
2293 line);
2294 }
2295 else
2296 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00002297 error(line, "Cannot offset into the array", "Error");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002298 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002299
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002300 return 0;
2301 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002302
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002303 return typedNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002304}
2305
2306
2307//
Arun Patole7e7e68d2015-05-22 12:02:25 +05302308// This function returns the value of a particular field inside a constant structure from the symbol table.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002309// If there is an embedded/nested struct, it appropriately calls addConstStructNested or addConstStructFromAggr
2310// function and returns the parse-tree with the values of the embedded/nested struct.
2311//
Arun Patole7e7e68d2015-05-22 12:02:25 +05302312TIntermTyped *TParseContext::addConstStruct(const TString &identifier, TIntermTyped *node, const TSourceLoc &line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002313{
Arun Patole7e7e68d2015-05-22 12:02:25 +05302314 const TFieldList &fields = node->getType().getStruct()->fields();
Jamie Madill94bf7f22013-07-08 13:31:15 -04002315 size_t instanceSize = 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002316
Arun Patole7e7e68d2015-05-22 12:02:25 +05302317 for (size_t index = 0; index < fields.size(); ++index)
2318 {
2319 if (fields[index]->name() == identifier)
2320 {
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002321 break;
Arun Patole7e7e68d2015-05-22 12:02:25 +05302322 }
2323 else
2324 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002325 instanceSize += fields[index]->type()->getObjectSize();
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002326 }
2327 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002328
Jamie Madill94bf7f22013-07-08 13:31:15 -04002329 TIntermTyped *typedNode;
2330 TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();
Arun Patole7e7e68d2015-05-22 12:02:25 +05302331 if (tempConstantNode)
2332 {
2333 TConstantUnion *constArray = tempConstantNode->getUnionArrayPointer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002334
Arun Patole7e7e68d2015-05-22 12:02:25 +05302335 // type will be changed in the calling function
2336 typedNode = intermediate.addConstantUnion(constArray+instanceSize, tempConstantNode->getType(), line);
2337 }
2338 else
2339 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00002340 error(line, "Cannot offset into the structure", "Error");
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002341 recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002342
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002343 return 0;
2344 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002345
daniel@transgaming.comea15b0e2010-04-29 03:32:36 +00002346 return typedNode;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002347}
2348
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002349//
2350// Interface/uniform blocks
2351//
Arun Patole7e7e68d2015-05-22 12:02:25 +05302352TIntermAggregate *TParseContext::addInterfaceBlock(const TPublicType &typeQualifier, const TSourceLoc &nameLine,
2353 const TString &blockName, TFieldList *fieldList,
2354 const TString *instanceName, const TSourceLoc &instanceLine,
2355 TIntermTyped *arrayIndex, const TSourceLoc &arrayIndexLine)
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002356{
2357 if (reservedErrorCheck(nameLine, blockName))
2358 recover();
2359
2360 if (typeQualifier.qualifier != EvqUniform)
2361 {
Arun Patole7e7e68d2015-05-22 12:02:25 +05302362 error(typeQualifier.line, "invalid qualifier:", getQualifierString(typeQualifier.qualifier),
2363 "interface blocks must be uniform");
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002364 recover();
2365 }
2366
Jamie Madill099c0f32013-06-20 11:55:52 -04002367 TLayoutQualifier blockLayoutQualifier = typeQualifier.layoutQualifier;
2368 if (layoutLocationErrorCheck(typeQualifier.line, blockLayoutQualifier))
Jamie Madilla5efff92013-06-06 11:56:47 -04002369 {
2370 recover();
2371 }
2372
Jamie Madill099c0f32013-06-20 11:55:52 -04002373 if (blockLayoutQualifier.matrixPacking == EmpUnspecified)
2374 {
Jamie Madill6e06b1f2015-05-14 10:01:17 -04002375 blockLayoutQualifier.matrixPacking = mDefaultMatrixPacking;
Jamie Madill099c0f32013-06-20 11:55:52 -04002376 }
2377
Jamie Madill1566ef72013-06-20 11:55:54 -04002378 if (blockLayoutQualifier.blockStorage == EbsUnspecified)
2379 {
Jamie Madill6e06b1f2015-05-14 10:01:17 -04002380 blockLayoutQualifier.blockStorage = mDefaultBlockStorage;
Jamie Madill1566ef72013-06-20 11:55:54 -04002381 }
2382
Arun Patole7e7e68d2015-05-22 12:02:25 +05302383 TSymbol *blockNameSymbol = new TInterfaceBlockName(&blockName);
2384 if (!symbolTable.declare(blockNameSymbol))
2385 {
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002386 error(nameLine, "redefinition", blockName.c_str(), "interface block name");
2387 recover();
2388 }
2389
Jamie Madill98493dd2013-07-08 14:39:03 -04002390 // check for sampler types and apply layout qualifiers
Arun Patole7e7e68d2015-05-22 12:02:25 +05302391 for (size_t memberIndex = 0; memberIndex < fieldList->size(); ++memberIndex)
2392 {
2393 TField *field = (*fieldList)[memberIndex];
2394 TType *fieldType = field->type();
2395 if (IsSampler(fieldType->getBasicType()))
2396 {
2397 error(field->line(), "unsupported type", fieldType->getBasicString(),
2398 "sampler types are not allowed in interface blocks");
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002399 recover();
2400 }
2401
Jamie Madill98493dd2013-07-08 14:39:03 -04002402 const TQualifier qualifier = fieldType->getQualifier();
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002403 switch (qualifier)
2404 {
2405 case EvqGlobal:
2406 case EvqUniform:
2407 break;
2408 default:
Jamie Madill98493dd2013-07-08 14:39:03 -04002409 error(field->line(), "invalid qualifier on interface block member", getQualifierString(qualifier));
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002410 recover();
2411 break;
2412 }
Jamie Madilla5efff92013-06-06 11:56:47 -04002413
2414 // check layout qualifiers
Jamie Madill98493dd2013-07-08 14:39:03 -04002415 TLayoutQualifier fieldLayoutQualifier = fieldType->getLayoutQualifier();
2416 if (layoutLocationErrorCheck(field->line(), fieldLayoutQualifier))
Jamie Madilla5efff92013-06-06 11:56:47 -04002417 {
2418 recover();
2419 }
Jamie Madill099c0f32013-06-20 11:55:52 -04002420
Jamie Madill98493dd2013-07-08 14:39:03 -04002421 if (fieldLayoutQualifier.blockStorage != EbsUnspecified)
Jamie Madill1566ef72013-06-20 11:55:54 -04002422 {
Arun Patole7e7e68d2015-05-22 12:02:25 +05302423 error(field->line(), "invalid layout qualifier:", getBlockStorageString(fieldLayoutQualifier.blockStorage),
2424 "cannot be used here");
Jamie Madill1566ef72013-06-20 11:55:54 -04002425 recover();
2426 }
2427
Jamie Madill98493dd2013-07-08 14:39:03 -04002428 if (fieldLayoutQualifier.matrixPacking == EmpUnspecified)
Jamie Madill099c0f32013-06-20 11:55:52 -04002429 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002430 fieldLayoutQualifier.matrixPacking = blockLayoutQualifier.matrixPacking;
Jamie Madill099c0f32013-06-20 11:55:52 -04002431 }
Olli Etuahofb6ab2c2015-07-09 20:55:28 +03002432 else if (!fieldType->isMatrix() && fieldType->getBasicType() != EbtStruct)
Jamie Madill099c0f32013-06-20 11:55:52 -04002433 {
Olli Etuahofb6ab2c2015-07-09 20:55:28 +03002434 warning(field->line(), "extraneous layout qualifier:",
2435 getMatrixPackingString(fieldLayoutQualifier.matrixPacking), "only has an effect on matrix types");
Jamie Madill099c0f32013-06-20 11:55:52 -04002436 }
2437
Jamie Madill98493dd2013-07-08 14:39:03 -04002438 fieldType->setLayoutQualifier(fieldLayoutQualifier);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002439 }
2440
Jamie Madill98493dd2013-07-08 14:39:03 -04002441 // add array index
2442 int arraySize = 0;
2443 if (arrayIndex != NULL)
2444 {
2445 if (arraySizeErrorCheck(arrayIndexLine, arrayIndex, arraySize))
2446 recover();
2447 }
2448
Arun Patole7e7e68d2015-05-22 12:02:25 +05302449 TInterfaceBlock *interfaceBlock = new TInterfaceBlock(&blockName, fieldList, instanceName, arraySize,
2450 blockLayoutQualifier);
Jamie Madill98493dd2013-07-08 14:39:03 -04002451 TType interfaceBlockType(interfaceBlock, typeQualifier.qualifier, blockLayoutQualifier, arraySize);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002452
2453 TString symbolName = "";
2454 int symbolId = 0;
2455
Jamie Madill98493dd2013-07-08 14:39:03 -04002456 if (!instanceName)
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002457 {
2458 // define symbols for the members of the interface block
Jamie Madill98493dd2013-07-08 14:39:03 -04002459 for (size_t memberIndex = 0; memberIndex < fieldList->size(); ++memberIndex)
2460 {
Arun Patole7e7e68d2015-05-22 12:02:25 +05302461 TField *field = (*fieldList)[memberIndex];
2462 TType *fieldType = field->type();
Jamie Madill98493dd2013-07-08 14:39:03 -04002463
2464 // set parent pointer of the field variable
2465 fieldType->setInterfaceBlock(interfaceBlock);
2466
Arun Patole7e7e68d2015-05-22 12:02:25 +05302467 TVariable *fieldVariable = new TVariable(&field->name(), *fieldType);
Jamie Madill98493dd2013-07-08 14:39:03 -04002468 fieldVariable->setQualifier(typeQualifier.qualifier);
2469
Arun Patole7e7e68d2015-05-22 12:02:25 +05302470 if (!symbolTable.declare(fieldVariable))
2471 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002472 error(field->line(), "redefinition", field->name().c_str(), "interface block member name");
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002473 recover();
2474 }
2475 }
2476 }
2477 else
2478 {
Olli Etuahoe0f623a2015-07-10 11:58:30 +03002479 if (reservedErrorCheck(instanceLine, *instanceName))
2480 recover();
2481
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002482 // add a symbol for this interface block
Arun Patole7e7e68d2015-05-22 12:02:25 +05302483 TVariable *instanceTypeDef = new TVariable(instanceName, interfaceBlockType, false);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002484 instanceTypeDef->setQualifier(typeQualifier.qualifier);
Jamie Madill98493dd2013-07-08 14:39:03 -04002485
Arun Patole7e7e68d2015-05-22 12:02:25 +05302486 if (!symbolTable.declare(instanceTypeDef))
2487 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002488 error(instanceLine, "redefinition", instanceName->c_str(), "interface block instance name");
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002489 recover();
2490 }
2491
2492 symbolId = instanceTypeDef->getUniqueId();
2493 symbolName = instanceTypeDef->getName();
2494 }
2495
Arun Patole7e7e68d2015-05-22 12:02:25 +05302496 TIntermAggregate *aggregate = intermediate.makeAggregate(intermediate.addSymbol(symbolId, symbolName,
2497 interfaceBlockType,
2498 typeQualifier.line),
2499 nameLine);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002500 aggregate->setOp(EOpDeclaration);
Jamie Madill98493dd2013-07-08 14:39:03 -04002501
2502 exitStructDeclaration();
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002503 return aggregate;
2504}
2505
Arun Patole7e7e68d2015-05-22 12:02:25 +05302506bool TParseContext::enterStructDeclaration(const TSourceLoc &line, const TString &identifier)
kbr@chromium.org476541f2011-10-27 21:14:51 +00002507{
Jamie Madill6e06b1f2015-05-14 10:01:17 -04002508 ++mStructNestingLevel;
kbr@chromium.org476541f2011-10-27 21:14:51 +00002509
2510 // Embedded structure definitions are not supported per GLSL ES spec.
2511 // They aren't allowed in GLSL either, but we need to detect this here
2512 // so we don't rely on the GLSL compiler to catch it.
Arun Patole7e7e68d2015-05-22 12:02:25 +05302513 if (mStructNestingLevel > 1)
2514 {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00002515 error(line, "", "Embedded struct definitions are not allowed");
kbr@chromium.org476541f2011-10-27 21:14:51 +00002516 return true;
2517 }
2518
2519 return false;
2520}
2521
2522void TParseContext::exitStructDeclaration()
2523{
Jamie Madill6e06b1f2015-05-14 10:01:17 -04002524 --mStructNestingLevel;
kbr@chromium.org476541f2011-10-27 21:14:51 +00002525}
2526
2527namespace {
2528
2529const int kWebGLMaxStructNesting = 4;
2530
2531} // namespace
2532
Arun Patole7e7e68d2015-05-22 12:02:25 +05302533bool TParseContext::structNestingErrorCheck(const TSourceLoc &line, const TField &field)
kbr@chromium.org476541f2011-10-27 21:14:51 +00002534{
Arun Patole7e7e68d2015-05-22 12:02:25 +05302535 if (!IsWebGLBasedSpec(mShaderSpec))
2536 {
kbr@chromium.org476541f2011-10-27 21:14:51 +00002537 return false;
2538 }
2539
Arun Patole7e7e68d2015-05-22 12:02:25 +05302540 if (field.type()->getBasicType() != EbtStruct)
2541 {
kbr@chromium.org476541f2011-10-27 21:14:51 +00002542 return false;
2543 }
2544
2545 // We're already inside a structure definition at this point, so add
2546 // one to the field's struct nesting.
Arun Patole7e7e68d2015-05-22 12:02:25 +05302547 if (1 + field.type()->getDeepestStructNesting() > kWebGLMaxStructNesting)
2548 {
Jamie Madill41a49272014-03-18 16:10:13 -04002549 std::stringstream reasonStream;
2550 reasonStream << "Reference of struct type "
2551 << field.type()->getStruct()->name().c_str()
2552 << " exceeds maximum allowed nesting level of "
2553 << kWebGLMaxStructNesting;
2554 std::string reason = reasonStream.str();
2555 error(line, reason.c_str(), field.name().c_str(), "");
kbr@chromium.org476541f2011-10-27 21:14:51 +00002556 return true;
2557 }
2558
2559 return false;
2560}
2561
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00002562//
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002563// Parse an array index expression
2564//
Arun Patole7e7e68d2015-05-22 12:02:25 +05302565TIntermTyped *TParseContext::addIndexExpression(TIntermTyped *baseExpression, const TSourceLoc &location,
2566 TIntermTyped *indexExpression)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002567{
2568 TIntermTyped *indexedExpression = NULL;
2569
2570 if (!baseExpression->isArray() && !baseExpression->isMatrix() && !baseExpression->isVector())
2571 {
2572 if (baseExpression->getAsSymbolNode())
2573 {
Arun Patole7e7e68d2015-05-22 12:02:25 +05302574 error(location, " left of '[' is not of type array, matrix, or vector ",
2575 baseExpression->getAsSymbolNode()->getSymbol().c_str());
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002576 }
2577 else
2578 {
2579 error(location, " left of '[' is not of type array, matrix, or vector ", "expression");
2580 }
2581 recover();
2582 }
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00002583
Jamie Madill21c1e452014-12-29 11:33:41 -05002584 TIntermConstantUnion *indexConstantUnion = indexExpression->getAsConstantUnion();
2585
2586 if (indexExpression->getQualifier() == EvqConst && indexConstantUnion)
Jamie Madill7164cf42013-07-08 13:30:59 -04002587 {
Jamie Madill21c1e452014-12-29 11:33:41 -05002588 int index = indexConstantUnion->getIConst(0);
Jamie Madill7164cf42013-07-08 13:30:59 -04002589 if (index < 0)
2590 {
2591 std::stringstream infoStream;
2592 infoStream << index;
2593 std::string info = infoStream.str();
2594 error(location, "negative index", info.c_str());
2595 recover();
2596 index = 0;
2597 }
2598 if (baseExpression->getType().getQualifier() == EvqConst)
2599 {
2600 if (baseExpression->isArray())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002601 {
Jamie Madill7164cf42013-07-08 13:30:59 -04002602 // constant folding for arrays
2603 indexedExpression = addConstArrayNode(index, baseExpression, location);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002604 }
Jamie Madill7164cf42013-07-08 13:30:59 -04002605 else if (baseExpression->isVector())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002606 {
Jamie Madill7164cf42013-07-08 13:30:59 -04002607 // constant folding for vectors
2608 TVectorFields fields;
2609 fields.num = 1;
2610 fields.offsets[0] = index; // need to do it this way because v.xy sends fields integer array
2611 indexedExpression = addConstVectorNode(fields, baseExpression, location);
2612 }
2613 else if (baseExpression->isMatrix())
2614 {
2615 // constant folding for matrices
2616 indexedExpression = addConstMatrixNode(index, baseExpression, location);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002617 }
2618 }
2619 else
2620 {
Jamie Madillb11e2482015-05-04 14:21:22 -04002621 int safeIndex = -1;
2622
Jamie Madill7164cf42013-07-08 13:30:59 -04002623 if (baseExpression->isArray())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002624 {
Jamie Madill18464b52013-07-08 14:01:55 -04002625 if (index >= baseExpression->getType().getArraySize())
Jamie Madill7164cf42013-07-08 13:30:59 -04002626 {
2627 std::stringstream extraInfoStream;
2628 extraInfoStream << "array index out of range '" << index << "'";
2629 std::string extraInfo = extraInfoStream.str();
2630 error(location, "", "[", extraInfo.c_str());
2631 recover();
Jamie Madillb11e2482015-05-04 14:21:22 -04002632 safeIndex = baseExpression->getType().getArraySize() - 1;
Jamie Madill7164cf42013-07-08 13:30:59 -04002633 }
Arun Patole7e7e68d2015-05-22 12:02:25 +05302634 else if (baseExpression->getQualifier() == EvqFragData && index > 0 &&
2635 !isExtensionEnabled("GL_EXT_draw_buffers"))
Jamie Madill5d287f52013-07-12 15:38:19 -04002636 {
Arun Patole7e7e68d2015-05-22 12:02:25 +05302637 error(location, "",
2638 "[", "array indexes for gl_FragData must be zero when GL_EXT_draw_buffers is disabled");
Jamie Madill5d287f52013-07-12 15:38:19 -04002639 recover();
Jamie Madillb11e2482015-05-04 14:21:22 -04002640 safeIndex = 0;
Jamie Madill5d287f52013-07-12 15:38:19 -04002641 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002642 }
Arun Patole7e7e68d2015-05-22 12:02:25 +05302643 else if ((baseExpression->isVector() || baseExpression->isMatrix()) &&
2644 baseExpression->getType().getNominalSize() <= index)
shannonwoods@chromium.orge429ab72013-05-30 00:12:52 +00002645 {
Jamie Madill7164cf42013-07-08 13:30:59 -04002646 std::stringstream extraInfoStream;
2647 extraInfoStream << "field selection out of range '" << index << "'";
2648 std::string extraInfo = extraInfoStream.str();
2649 error(location, "", "[", extraInfo.c_str());
shannonwoods@chromium.orge429ab72013-05-30 00:12:52 +00002650 recover();
Jamie Madillb11e2482015-05-04 14:21:22 -04002651 safeIndex = baseExpression->getType().getNominalSize() - 1;
Jamie Madill46131a32013-06-20 11:55:50 -04002652 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002653
Jamie Madillb11e2482015-05-04 14:21:22 -04002654 // Don't modify the data of the previous constant union, because it can point
2655 // to builtins, like gl_MaxDrawBuffers. Instead use a new sanitized object.
2656 if (safeIndex != -1)
2657 {
2658 TConstantUnion *safeConstantUnion = new TConstantUnion();
2659 safeConstantUnion->setIConst(safeIndex);
2660 indexConstantUnion->replaceConstantUnion(safeConstantUnion);
2661 }
2662
Jamie Madill7164cf42013-07-08 13:30:59 -04002663 indexedExpression = intermediate.addIndex(EOpIndexDirect, baseExpression, indexExpression, location);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002664 }
2665 }
Jamie Madill7164cf42013-07-08 13:30:59 -04002666 else
2667 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002668 if (baseExpression->isInterfaceBlock())
Jamie Madill7164cf42013-07-08 13:30:59 -04002669 {
Arun Patole7e7e68d2015-05-22 12:02:25 +05302670 error(location, "",
2671 "[", "array indexes for interface blocks arrays must be constant integral expressions");
Jamie Madill7164cf42013-07-08 13:30:59 -04002672 recover();
2673 }
Jamie Madill19571812013-08-12 15:26:34 -07002674 else if (baseExpression->getQualifier() == EvqFragmentOut)
Jamie Madill7164cf42013-07-08 13:30:59 -04002675 {
Jamie Madill19571812013-08-12 15:26:34 -07002676 error(location, "", "[", "array indexes for fragment outputs must be constant integral expressions");
Jamie Madill7164cf42013-07-08 13:30:59 -04002677 recover();
2678 }
2679
2680 indexedExpression = intermediate.addIndex(EOpIndexIndirect, baseExpression, indexExpression, location);
2681 }
2682
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002683 if (indexedExpression == 0)
2684 {
Jamie Madill6ba6ead2015-05-04 14:21:21 -04002685 TConstantUnion *unionArray = new TConstantUnion[1];
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002686 unionArray->setFConst(0.0f);
2687 indexedExpression = intermediate.addConstantUnion(unionArray, TType(EbtFloat, EbpHigh, EvqConst), location);
2688 }
2689 else if (baseExpression->isArray())
2690 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002691 const TType &baseType = baseExpression->getType();
2692 if (baseType.getStruct())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002693 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002694 TType copyOfType(baseType.getStruct());
2695 indexedExpression->setType(copyOfType);
2696 }
2697 else if (baseType.isInterfaceBlock())
2698 {
2699 TType copyOfType(baseType.getInterfaceBlock(), baseType.getQualifier(), baseType.getLayoutQualifier(), 0);
shannonwoods@chromium.orge429ab72013-05-30 00:12:52 +00002700 indexedExpression->setType(copyOfType);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002701 }
2702 else
2703 {
Arun Patole7e7e68d2015-05-22 12:02:25 +05302704 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(),
2705 EvqTemporary, static_cast<unsigned char>(baseExpression->getNominalSize()),
2706 static_cast<unsigned char>(baseExpression->getSecondarySize())));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002707 }
2708
2709 if (baseExpression->getType().getQualifier() == EvqConst)
2710 {
2711 indexedExpression->getTypePointer()->setQualifier(EvqConst);
2712 }
2713 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002714 else if (baseExpression->isMatrix())
2715 {
Jamie Madill7164cf42013-07-08 13:30:59 -04002716 TQualifier qualifier = baseExpression->getType().getQualifier() == EvqConst ? EvqConst : EvqTemporary;
Arun Patole7e7e68d2015-05-22 12:02:25 +05302717 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(),
2718 qualifier, static_cast<unsigned char>(baseExpression->getRows())));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002719 }
2720 else if (baseExpression->isVector())
2721 {
Jamie Madill7164cf42013-07-08 13:30:59 -04002722 TQualifier qualifier = baseExpression->getType().getQualifier() == EvqConst ? EvqConst : EvqTemporary;
2723 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(), qualifier));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002724 }
2725 else
2726 {
2727 indexedExpression->setType(baseExpression->getType());
2728 }
2729
2730 return indexedExpression;
2731}
2732
Arun Patole7e7e68d2015-05-22 12:02:25 +05302733TIntermTyped *TParseContext::addFieldSelectionExpression(TIntermTyped *baseExpression, const TSourceLoc &dotLocation,
2734 const TString &fieldString, const TSourceLoc &fieldLocation)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002735{
2736 TIntermTyped *indexedExpression = NULL;
2737
2738 if (baseExpression->isArray())
2739 {
2740 error(fieldLocation, "cannot apply dot operator to an array", ".");
2741 recover();
2742 }
2743
2744 if (baseExpression->isVector())
2745 {
2746 TVectorFields fields;
2747 if (!parseVectorFields(fieldString, baseExpression->getNominalSize(), fields, fieldLocation))
2748 {
2749 fields.num = 1;
2750 fields.offsets[0] = 0;
2751 recover();
2752 }
2753
2754 if (baseExpression->getType().getQualifier() == EvqConst)
2755 {
2756 // constant folding for vector fields
2757 indexedExpression = addConstVectorNode(fields, baseExpression, fieldLocation);
2758 if (indexedExpression == 0)
2759 {
2760 recover();
2761 indexedExpression = baseExpression;
2762 }
2763 else
2764 {
Arun Patole7e7e68d2015-05-22 12:02:25 +05302765 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(),
2766 EvqConst, (unsigned char) (fieldString).size()));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002767 }
2768 }
2769 else
2770 {
2771 TString vectorString = fieldString;
Arun Patole7e7e68d2015-05-22 12:02:25 +05302772 TIntermTyped *index = intermediate.addSwizzle(fields, fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002773 indexedExpression = intermediate.addIndex(EOpVectorSwizzle, baseExpression, index, dotLocation);
Arun Patole7e7e68d2015-05-22 12:02:25 +05302774 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(),
2775 EvqTemporary, (unsigned char) vectorString.size()));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002776 }
2777 }
2778 else if (baseExpression->isMatrix())
2779 {
2780 TMatrixFields fields;
Arun Patole7e7e68d2015-05-22 12:02:25 +05302781 if (!parseMatrixFields(fieldString, baseExpression->getCols(), baseExpression->getRows(), fields,
2782 fieldLocation))
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002783 {
2784 fields.wholeRow = false;
2785 fields.wholeCol = false;
2786 fields.row = 0;
2787 fields.col = 0;
2788 recover();
2789 }
2790
2791 if (fields.wholeRow || fields.wholeCol)
2792 {
2793 error(dotLocation, " non-scalar fields not implemented yet", ".");
2794 recover();
Jamie Madill6ba6ead2015-05-04 14:21:21 -04002795 TConstantUnion *unionArray = new TConstantUnion[1];
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002796 unionArray->setIConst(0);
Arun Patole7e7e68d2015-05-22 12:02:25 +05302797 TIntermTyped *index = intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst),
2798 fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002799 indexedExpression = intermediate.addIndex(EOpIndexDirect, baseExpression, index, dotLocation);
Arun Patole7e7e68d2015-05-22 12:02:25 +05302800 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision(),
2801 EvqTemporary, static_cast<unsigned char>(baseExpression->getCols()),
2802 static_cast<unsigned char>(baseExpression->getRows())));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002803 }
2804 else
2805 {
Jamie Madill6ba6ead2015-05-04 14:21:21 -04002806 TConstantUnion *unionArray = new TConstantUnion[1];
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00002807 unionArray->setIConst(fields.col * baseExpression->getRows() + fields.row);
Arun Patole7e7e68d2015-05-22 12:02:25 +05302808 TIntermTyped *index = intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst),
2809 fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002810 indexedExpression = intermediate.addIndex(EOpIndexDirect, baseExpression, index, dotLocation);
2811 indexedExpression->setType(TType(baseExpression->getBasicType(), baseExpression->getPrecision()));
2812 }
2813 }
2814 else if (baseExpression->getBasicType() == EbtStruct)
2815 {
2816 bool fieldFound = false;
Arun Patole7e7e68d2015-05-22 12:02:25 +05302817 const TFieldList &fields = baseExpression->getType().getStruct()->fields();
Jamie Madill98493dd2013-07-08 14:39:03 -04002818 if (fields.empty())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002819 {
2820 error(dotLocation, "structure has no fields", "Internal Error");
2821 recover();
2822 indexedExpression = baseExpression;
2823 }
2824 else
2825 {
2826 unsigned int i;
Jamie Madill98493dd2013-07-08 14:39:03 -04002827 for (i = 0; i < fields.size(); ++i)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002828 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002829 if (fields[i]->name() == fieldString)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002830 {
2831 fieldFound = true;
2832 break;
2833 }
2834 }
2835 if (fieldFound)
2836 {
2837 if (baseExpression->getType().getQualifier() == EvqConst)
2838 {
2839 indexedExpression = addConstStruct(fieldString, baseExpression, dotLocation);
2840 if (indexedExpression == 0)
2841 {
2842 recover();
2843 indexedExpression = baseExpression;
2844 }
2845 else
2846 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002847 indexedExpression->setType(*fields[i]->type());
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002848 // change the qualifier of the return type, not of the structure field
2849 // as the structure definition is shared between various structures.
2850 indexedExpression->getTypePointer()->setQualifier(EvqConst);
2851 }
2852 }
2853 else
2854 {
Jamie Madill6ba6ead2015-05-04 14:21:21 -04002855 TConstantUnion *unionArray = new TConstantUnion[1];
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002856 unionArray->setIConst(i);
Arun Patole7e7e68d2015-05-22 12:02:25 +05302857 TIntermTyped *index = intermediate.addConstantUnion(unionArray, *fields[i]->type(), fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002858 indexedExpression = intermediate.addIndex(EOpIndexDirectStruct, baseExpression, index, dotLocation);
Jamie Madill98493dd2013-07-08 14:39:03 -04002859 indexedExpression->setType(*fields[i]->type());
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002860 }
2861 }
2862 else
2863 {
2864 error(dotLocation, " no such field in structure", fieldString.c_str());
2865 recover();
2866 indexedExpression = baseExpression;
2867 }
2868 }
2869 }
Jamie Madill98493dd2013-07-08 14:39:03 -04002870 else if (baseExpression->isInterfaceBlock())
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002871 {
2872 bool fieldFound = false;
Arun Patole7e7e68d2015-05-22 12:02:25 +05302873 const TFieldList &fields = baseExpression->getType().getInterfaceBlock()->fields();
Jamie Madill98493dd2013-07-08 14:39:03 -04002874 if (fields.empty())
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002875 {
2876 error(dotLocation, "interface block has no fields", "Internal Error");
2877 recover();
2878 indexedExpression = baseExpression;
2879 }
2880 else
2881 {
2882 unsigned int i;
Jamie Madill98493dd2013-07-08 14:39:03 -04002883 for (i = 0; i < fields.size(); ++i)
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002884 {
Jamie Madill98493dd2013-07-08 14:39:03 -04002885 if (fields[i]->name() == fieldString)
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002886 {
2887 fieldFound = true;
2888 break;
2889 }
2890 }
2891 if (fieldFound)
2892 {
Jamie Madill6ba6ead2015-05-04 14:21:21 -04002893 TConstantUnion *unionArray = new TConstantUnion[1];
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002894 unionArray->setIConst(i);
Arun Patole7e7e68d2015-05-22 12:02:25 +05302895 TIntermTyped *index = intermediate.addConstantUnion(unionArray, *fields[i]->type(), fieldLocation);
2896 indexedExpression = intermediate.addIndex(EOpIndexDirectInterfaceBlock, baseExpression, index,
2897 dotLocation);
Jamie Madill98493dd2013-07-08 14:39:03 -04002898 indexedExpression->setType(*fields[i]->type());
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002899 }
2900 else
2901 {
2902 error(dotLocation, " no such field in interface block", fieldString.c_str());
2903 recover();
2904 indexedExpression = baseExpression;
2905 }
2906 }
2907 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002908 else
2909 {
Jamie Madill6e06b1f2015-05-14 10:01:17 -04002910 if (mShaderVersion < 300)
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002911 {
Arun Patole7e7e68d2015-05-22 12:02:25 +05302912 error(dotLocation, " field selection requires structure, vector, or matrix on left hand side",
2913 fieldString.c_str());
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002914 }
2915 else
2916 {
Arun Patole7e7e68d2015-05-22 12:02:25 +05302917 error(dotLocation,
2918 " field selection requires structure, vector, matrix, or interface block on left hand side",
2919 fieldString.c_str());
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +00002920 }
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00002921 recover();
2922 indexedExpression = baseExpression;
2923 }
2924
2925 return indexedExpression;
2926}
2927
Arun Patole7e7e68d2015-05-22 12:02:25 +05302928TLayoutQualifier TParseContext::parseLayoutQualifier(const TString &qualifierType, const TSourceLoc &qualifierTypeLine)
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002929{
Jamie Madilla5efff92013-06-06 11:56:47 -04002930 TLayoutQualifier qualifier;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002931
Jamie Madilla5efff92013-06-06 11:56:47 -04002932 qualifier.location = -1;
2933 qualifier.matrixPacking = EmpUnspecified;
2934 qualifier.blockStorage = EbsUnspecified;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002935
2936 if (qualifierType == "shared")
2937 {
Jamie Madilla5efff92013-06-06 11:56:47 -04002938 qualifier.blockStorage = EbsShared;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002939 }
2940 else if (qualifierType == "packed")
2941 {
Jamie Madilla5efff92013-06-06 11:56:47 -04002942 qualifier.blockStorage = EbsPacked;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002943 }
2944 else if (qualifierType == "std140")
2945 {
Jamie Madilla5efff92013-06-06 11:56:47 -04002946 qualifier.blockStorage = EbsStd140;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002947 }
2948 else if (qualifierType == "row_major")
2949 {
Jamie Madilla5efff92013-06-06 11:56:47 -04002950 qualifier.matrixPacking = EmpRowMajor;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002951 }
2952 else if (qualifierType == "column_major")
2953 {
Jamie Madilla5efff92013-06-06 11:56:47 -04002954 qualifier.matrixPacking = EmpColumnMajor;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002955 }
2956 else if (qualifierType == "location")
2957 {
2958 error(qualifierTypeLine, "invalid layout qualifier", qualifierType.c_str(), "location requires an argument");
2959 recover();
2960 }
2961 else
2962 {
2963 error(qualifierTypeLine, "invalid layout qualifier", qualifierType.c_str());
2964 recover();
2965 }
2966
Jamie Madilla5efff92013-06-06 11:56:47 -04002967 return qualifier;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002968}
2969
Arun Patole7e7e68d2015-05-22 12:02:25 +05302970TLayoutQualifier TParseContext::parseLayoutQualifier(const TString &qualifierType, const TSourceLoc &qualifierTypeLine,
2971 const TString &intValueString, int intValue,
2972 const TSourceLoc &intValueLine)
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002973{
Jamie Madilla5efff92013-06-06 11:56:47 -04002974 TLayoutQualifier qualifier;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002975
Jamie Madilla5efff92013-06-06 11:56:47 -04002976 qualifier.location = -1;
2977 qualifier.matrixPacking = EmpUnspecified;
2978 qualifier.blockStorage = EbsUnspecified;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002979
2980 if (qualifierType != "location")
2981 {
Arun Patole7e7e68d2015-05-22 12:02:25 +05302982 error(qualifierTypeLine, "invalid layout qualifier", qualifierType.c_str(),
2983 "only location may have arguments");
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002984 recover();
2985 }
2986 else
2987 {
Jamie Madill05a80ce2013-06-20 11:55:49 -04002988 // must check that location is non-negative
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002989 if (intValue < 0)
2990 {
Jamie Madill05a80ce2013-06-20 11:55:49 -04002991 error(intValueLine, "out of range:", intValueString.c_str(), "location must be non-negative");
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002992 recover();
2993 }
2994 else
2995 {
Jamie Madilla5efff92013-06-06 11:56:47 -04002996 qualifier.location = intValue;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002997 }
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00002998 }
2999
Jamie Madilla5efff92013-06-06 11:56:47 -04003000 return qualifier;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00003001}
3002
Jamie Madilla5efff92013-06-06 11:56:47 -04003003TLayoutQualifier TParseContext::joinLayoutQualifiers(TLayoutQualifier leftQualifier, TLayoutQualifier rightQualifier)
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00003004{
Jamie Madilla5efff92013-06-06 11:56:47 -04003005 TLayoutQualifier joinedQualifier = leftQualifier;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00003006
Jamie Madilla5efff92013-06-06 11:56:47 -04003007 if (rightQualifier.location != -1)
3008 {
3009 joinedQualifier.location = rightQualifier.location;
3010 }
3011 if (rightQualifier.matrixPacking != EmpUnspecified)
3012 {
3013 joinedQualifier.matrixPacking = rightQualifier.matrixPacking;
3014 }
3015 if (rightQualifier.blockStorage != EbsUnspecified)
3016 {
3017 joinedQualifier.blockStorage = rightQualifier.blockStorage;
3018 }
3019
3020 return joinedQualifier;
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +00003021}
3022
Arun Patole7e7e68d2015-05-22 12:02:25 +05303023TPublicType TParseContext::joinInterpolationQualifiers(const TSourceLoc &interpolationLoc,
3024 TQualifier interpolationQualifier,
3025 const TSourceLoc &storageLoc,
3026 TQualifier storageQualifier)
Jamie Madillf2e0f9b2013-08-26 16:39:42 -04003027{
3028 TQualifier mergedQualifier = EvqSmoothIn;
3029
Arun Patole7e7e68d2015-05-22 12:02:25 +05303030 if (storageQualifier == EvqFragmentIn)
3031 {
Jamie Madillf2e0f9b2013-08-26 16:39:42 -04003032 if (interpolationQualifier == EvqSmooth)
3033 mergedQualifier = EvqSmoothIn;
3034 else if (interpolationQualifier == EvqFlat)
3035 mergedQualifier = EvqFlatIn;
3036 else UNREACHABLE();
3037 }
Arun Patole7e7e68d2015-05-22 12:02:25 +05303038 else if (storageQualifier == EvqCentroidIn)
3039 {
Jamie Madillf2e0f9b2013-08-26 16:39:42 -04003040 if (interpolationQualifier == EvqSmooth)
3041 mergedQualifier = EvqCentroidIn;
3042 else if (interpolationQualifier == EvqFlat)
3043 mergedQualifier = EvqFlatIn;
3044 else UNREACHABLE();
3045 }
Arun Patole7e7e68d2015-05-22 12:02:25 +05303046 else if (storageQualifier == EvqVertexOut)
3047 {
Jamie Madillf2e0f9b2013-08-26 16:39:42 -04003048 if (interpolationQualifier == EvqSmooth)
3049 mergedQualifier = EvqSmoothOut;
3050 else if (interpolationQualifier == EvqFlat)
3051 mergedQualifier = EvqFlatOut;
3052 else UNREACHABLE();
3053 }
Arun Patole7e7e68d2015-05-22 12:02:25 +05303054 else if (storageQualifier == EvqCentroidOut)
3055 {
Jamie Madillf2e0f9b2013-08-26 16:39:42 -04003056 if (interpolationQualifier == EvqSmooth)
3057 mergedQualifier = EvqCentroidOut;
3058 else if (interpolationQualifier == EvqFlat)
3059 mergedQualifier = EvqFlatOut;
3060 else UNREACHABLE();
3061 }
Arun Patole7e7e68d2015-05-22 12:02:25 +05303062 else
3063 {
3064 error(interpolationLoc, "interpolation qualifier requires a fragment 'in' or vertex 'out' storage qualifier",
3065 getInterpolationString(interpolationQualifier));
Jamie Madillf2e0f9b2013-08-26 16:39:42 -04003066 recover();
3067
3068 mergedQualifier = storageQualifier;
3069 }
3070
3071 TPublicType type;
3072 type.setBasic(EbtVoid, mergedQualifier, storageLoc);
3073 return type;
3074}
3075
Arun Patole7e7e68d2015-05-22 12:02:25 +05303076TFieldList *TParseContext::addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003077{
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +03003078 if (voidErrorCheck(typeSpecifier.line, (*fieldList)[0]->name(), typeSpecifier.type))
3079 {
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003080 recover();
3081 }
3082
Arun Patole7e7e68d2015-05-22 12:02:25 +05303083 for (unsigned int i = 0; i < fieldList->size(); ++i)
3084 {
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003085 //
3086 // Careful not to replace already known aspects of type, like array-ness
3087 //
Arun Patole7e7e68d2015-05-22 12:02:25 +05303088 TType *type = (*fieldList)[i]->type();
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003089 type->setBasicType(typeSpecifier.type);
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +00003090 type->setPrimarySize(typeSpecifier.primarySize);
3091 type->setSecondarySize(typeSpecifier.secondarySize);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003092 type->setPrecision(typeSpecifier.precision);
3093 type->setQualifier(typeSpecifier.qualifier);
Jamie Madilla5efff92013-06-06 11:56:47 -04003094 type->setLayoutQualifier(typeSpecifier.layoutQualifier);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003095
3096 // don't allow arrays of arrays
Arun Patole7e7e68d2015-05-22 12:02:25 +05303097 if (type->isArray())
3098 {
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003099 if (arrayTypeErrorCheck(typeSpecifier.line, typeSpecifier))
3100 recover();
3101 }
3102 if (typeSpecifier.array)
3103 type->setArraySize(typeSpecifier.arraySize);
Arun Patole7e7e68d2015-05-22 12:02:25 +05303104 if (typeSpecifier.userDef)
3105 {
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003106 type->setStruct(typeSpecifier.userDef->getStruct());
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003107 }
3108
Arun Patole7e7e68d2015-05-22 12:02:25 +05303109 if (structNestingErrorCheck(typeSpecifier.line, *(*fieldList)[i]))
3110 {
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003111 recover();
3112 }
3113 }
3114
Jamie Madill98493dd2013-07-08 14:39:03 -04003115 return fieldList;
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003116}
3117
Arun Patole7e7e68d2015-05-22 12:02:25 +05303118TPublicType TParseContext::addStructure(const TSourceLoc &structLine, const TSourceLoc &nameLine,
3119 const TString *structName, TFieldList *fieldList)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003120{
Arun Patole7e7e68d2015-05-22 12:02:25 +05303121 TStructure *structure = new TStructure(structName, fieldList);
3122 TType *structureType = new TType(structure);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003123
Jamie Madill9b820842015-02-12 10:40:10 -05003124 // Store a bool in the struct if we're at global scope, to allow us to
3125 // skip the local struct scoping workaround in HLSL.
Jamie Madillb960cc42015-02-12 15:33:20 +00003126 structure->setUniqueId(TSymbolTable::nextUniqueId());
Jamie Madill9b820842015-02-12 10:40:10 -05003127 structure->setAtGlobalScope(symbolTable.atGlobalLevel());
Jamie Madillbfa91f42014-06-05 15:45:18 -04003128
Jamie Madill98493dd2013-07-08 14:39:03 -04003129 if (!structName->empty())
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003130 {
Jamie Madill98493dd2013-07-08 14:39:03 -04003131 if (reservedErrorCheck(nameLine, *structName))
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003132 {
3133 recover();
3134 }
Arun Patole7e7e68d2015-05-22 12:02:25 +05303135 TVariable *userTypeDef = new TVariable(structName, *structureType, true);
3136 if (!symbolTable.declare(userTypeDef))
3137 {
Jamie Madill98493dd2013-07-08 14:39:03 -04003138 error(nameLine, "redefinition", structName->c_str(), "struct");
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003139 recover();
3140 }
3141 }
3142
3143 // ensure we do not specify any storage qualifiers on the struct members
Jamie Madill98493dd2013-07-08 14:39:03 -04003144 for (unsigned int typeListIndex = 0; typeListIndex < fieldList->size(); typeListIndex++)
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003145 {
Jamie Madill98493dd2013-07-08 14:39:03 -04003146 const TField &field = *(*fieldList)[typeListIndex];
3147 const TQualifier qualifier = field.type()->getQualifier();
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003148 switch (qualifier)
3149 {
3150 case EvqGlobal:
3151 case EvqTemporary:
3152 break;
3153 default:
Jamie Madill98493dd2013-07-08 14:39:03 -04003154 error(field.line(), "invalid qualifier on struct member", getQualifierString(qualifier));
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003155 recover();
3156 break;
3157 }
3158 }
3159
3160 TPublicType publicType;
3161 publicType.setBasic(EbtStruct, EvqTemporary, structLine);
Jamie Madill98493dd2013-07-08 14:39:03 -04003162 publicType.userDef = structureType;
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003163 exitStructDeclaration();
3164
3165 return publicType;
3166}
3167
Olli Etuahoa3a36662015-02-17 13:46:51 +02003168TIntermSwitch *TParseContext::addSwitch(TIntermTyped *init, TIntermAggregate *statementList, const TSourceLoc &loc)
3169{
Olli Etuaho53f076f2015-02-20 10:55:14 +02003170 TBasicType switchType = init->getBasicType();
3171 if ((switchType != EbtInt && switchType != EbtUInt) ||
3172 init->isMatrix() ||
3173 init->isArray() ||
3174 init->isVector())
3175 {
3176 error(init->getLine(), "init-expression in a switch statement must be a scalar integer", "switch");
3177 recover();
3178 return nullptr;
3179 }
3180
Olli Etuahoac5274d2015-02-20 10:19:08 +02003181 if (statementList)
3182 {
3183 if (!ValidateSwitch::validate(switchType, this, statementList, loc))
3184 {
3185 recover();
3186 return nullptr;
3187 }
3188 }
3189
Olli Etuahoa3a36662015-02-17 13:46:51 +02003190 TIntermSwitch *node = intermediate.addSwitch(init, statementList, loc);
3191 if (node == nullptr)
3192 {
3193 error(loc, "erroneous switch statement", "switch");
3194 recover();
3195 return nullptr;
3196 }
3197 return node;
3198}
3199
3200TIntermCase *TParseContext::addCase(TIntermTyped *condition, const TSourceLoc &loc)
3201{
Olli Etuaho53f076f2015-02-20 10:55:14 +02003202 if (mSwitchNestingLevel == 0)
3203 {
3204 error(loc, "case labels need to be inside switch statements", "case");
3205 recover();
3206 return nullptr;
3207 }
3208 if (condition == nullptr)
3209 {
3210 error(loc, "case label must have a condition", "case");
3211 recover();
3212 return nullptr;
3213 }
3214 if ((condition->getBasicType() != EbtInt && condition->getBasicType() != EbtUInt) ||
3215 condition->isMatrix() ||
3216 condition->isArray() ||
3217 condition->isVector())
3218 {
3219 error(condition->getLine(), "case label must be a scalar integer", "case");
3220 recover();
3221 }
3222 TIntermConstantUnion *conditionConst = condition->getAsConstantUnion();
3223 if (conditionConst == nullptr)
3224 {
3225 error(condition->getLine(), "case label must be constant", "case");
3226 recover();
3227 }
Olli Etuahoa3a36662015-02-17 13:46:51 +02003228 TIntermCase *node = intermediate.addCase(condition, loc);
3229 if (node == nullptr)
3230 {
3231 error(loc, "erroneous case statement", "case");
3232 recover();
3233 return nullptr;
3234 }
3235 return node;
3236}
3237
3238TIntermCase *TParseContext::addDefault(const TSourceLoc &loc)
3239{
Olli Etuaho53f076f2015-02-20 10:55:14 +02003240 if (mSwitchNestingLevel == 0)
3241 {
3242 error(loc, "default labels need to be inside switch statements", "default");
3243 recover();
3244 return nullptr;
3245 }
Olli Etuahoa3a36662015-02-17 13:46:51 +02003246 TIntermCase *node = intermediate.addCase(nullptr, loc);
3247 if (node == nullptr)
3248 {
3249 error(loc, "erroneous default statement", "default");
3250 recover();
3251 return nullptr;
3252 }
3253 return node;
3254}
3255
Olli Etuahof6c694b2015-03-26 14:50:53 +02003256TIntermTyped *TParseContext::createUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc,
3257 const TType *funcReturnType)
Olli Etuaho69c11b52015-03-26 12:59:00 +02003258{
3259 if (child == nullptr)
3260 {
3261 return nullptr;
3262 }
3263
3264 switch (op)
3265 {
3266 case EOpLogicalNot:
3267 if (child->getBasicType() != EbtBool ||
3268 child->isMatrix() ||
3269 child->isArray() ||
3270 child->isVector())
3271 {
3272 return nullptr;
3273 }
3274 break;
3275 case EOpBitwiseNot:
3276 if ((child->getBasicType() != EbtInt && child->getBasicType() != EbtUInt) ||
3277 child->isMatrix() ||
3278 child->isArray())
3279 {
3280 return nullptr;
3281 }
3282 break;
3283 case EOpPostIncrement:
3284 case EOpPreIncrement:
3285 case EOpPostDecrement:
3286 case EOpPreDecrement:
3287 case EOpNegative:
3288 case EOpPositive:
3289 if (child->getBasicType() == EbtStruct ||
Olli Etuahodca3e792015-03-26 13:24:04 +02003290 child->getBasicType() == EbtBool ||
Olli Etuaho69c11b52015-03-26 12:59:00 +02003291 child->isArray())
3292 {
3293 return nullptr;
3294 }
Olli Etuahodca3e792015-03-26 13:24:04 +02003295 // Operators for built-ins are already type checked against their prototype.
Olli Etuaho69c11b52015-03-26 12:59:00 +02003296 default:
3297 break;
3298 }
3299
Olli Etuahof6c694b2015-03-26 14:50:53 +02003300 return intermediate.addUnaryMath(op, child, loc, funcReturnType);
Olli Etuaho69c11b52015-03-26 12:59:00 +02003301}
3302
Olli Etuaho09b22472015-02-11 11:47:26 +02003303TIntermTyped *TParseContext::addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc)
3304{
Olli Etuahof6c694b2015-03-26 14:50:53 +02003305 TIntermTyped *node = createUnaryMath(op, child, loc, nullptr);
Olli Etuaho69c11b52015-03-26 12:59:00 +02003306 if (node == nullptr)
Olli Etuaho09b22472015-02-11 11:47:26 +02003307 {
3308 unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
3309 recover();
3310 return child;
3311 }
3312 return node;
3313}
3314
3315TIntermTyped *TParseContext::addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc)
3316{
3317 if (lValueErrorCheck(loc, GetOperatorString(op), child))
3318 recover();
3319 return addUnaryMath(op, child, loc);
3320}
3321
Olli Etuaho47fd36a2015-03-19 14:22:24 +02003322bool TParseContext::binaryOpCommonCheck(TOperator op, TIntermTyped *left, TIntermTyped *right,
Olli Etuahod6b14282015-03-17 14:31:35 +02003323 const TSourceLoc &loc)
3324{
3325 if (left->isArray() || right->isArray())
3326 {
Jamie Madill6e06b1f2015-05-14 10:01:17 -04003327 if (mShaderVersion < 300)
Olli Etuahoe79904c2015-03-18 16:56:42 +02003328 {
3329 error(loc, "Invalid operation for arrays", GetOperatorString(op));
3330 return false;
3331 }
3332
3333 if (left->isArray() != right->isArray())
3334 {
3335 error(loc, "array / non-array mismatch", GetOperatorString(op));
3336 return false;
3337 }
3338
3339 switch (op)
3340 {
3341 case EOpEqual:
3342 case EOpNotEqual:
3343 case EOpAssign:
3344 case EOpInitialize:
3345 break;
3346 default:
3347 error(loc, "Invalid operation for arrays", GetOperatorString(op));
3348 return false;
3349 }
Olli Etuaho376f1b52015-04-13 13:23:41 +03003350 // At this point, size of implicitly sized arrays should be resolved.
Olli Etuahoe79904c2015-03-18 16:56:42 +02003351 if (left->getArraySize() != right->getArraySize())
3352 {
3353 error(loc, "array size mismatch", GetOperatorString(op));
3354 return false;
3355 }
Olli Etuahod6b14282015-03-17 14:31:35 +02003356 }
Olli Etuaho47fd36a2015-03-19 14:22:24 +02003357
3358 // Check ops which require integer / ivec parameters
3359 bool isBitShift = false;
3360 switch (op)
3361 {
3362 case EOpBitShiftLeft:
3363 case EOpBitShiftRight:
3364 case EOpBitShiftLeftAssign:
3365 case EOpBitShiftRightAssign:
3366 // Unsigned can be bit-shifted by signed and vice versa, but we need to
3367 // check that the basic type is an integer type.
3368 isBitShift = true;
3369 if (!IsInteger(left->getBasicType()) || !IsInteger(right->getBasicType()))
3370 {
3371 return false;
3372 }
3373 break;
3374 case EOpBitwiseAnd:
3375 case EOpBitwiseXor:
3376 case EOpBitwiseOr:
3377 case EOpBitwiseAndAssign:
3378 case EOpBitwiseXorAssign:
3379 case EOpBitwiseOrAssign:
3380 // It is enough to check the type of only one operand, since later it
3381 // is checked that the operand types match.
3382 if (!IsInteger(left->getBasicType()))
3383 {
3384 return false;
3385 }
3386 break;
3387 default:
3388 break;
3389 }
3390
3391 // GLSL ES 1.00 and 3.00 do not support implicit type casting.
3392 // So the basic type should usually match.
3393 if (!isBitShift && left->getBasicType() != right->getBasicType())
3394 {
3395 return false;
3396 }
3397
Olli Etuaho9dd217b2015-03-20 14:24:31 +02003398 // Check that type sizes match exactly on ops that require that.
Olli Etuahoff699002015-03-23 14:38:42 +02003399 // Also check restrictions for structs that contain arrays or samplers.
Olli Etuaho47fd36a2015-03-19 14:22:24 +02003400 switch(op)
3401 {
3402 case EOpAssign:
3403 case EOpInitialize:
3404 case EOpEqual:
3405 case EOpNotEqual:
Olli Etuaho9dd217b2015-03-20 14:24:31 +02003406 // ESSL 1.00 sections 5.7, 5.8, 5.9
Jamie Madill6e06b1f2015-05-14 10:01:17 -04003407 if (mShaderVersion < 300 && left->getType().isStructureContainingArrays())
Olli Etuaho9dd217b2015-03-20 14:24:31 +02003408 {
3409 error(loc, "undefined operation for structs containing arrays", GetOperatorString(op));
3410 return false;
3411 }
Olli Etuahoff699002015-03-23 14:38:42 +02003412 // Samplers as l-values are disallowed also in ESSL 3.00, see section 4.1.7,
3413 // we interpret the spec so that this extends to structs containing samplers,
3414 // similarly to ESSL 1.00 spec.
Jamie Madill6e06b1f2015-05-14 10:01:17 -04003415 if ((mShaderVersion < 300 || op == EOpAssign || op == EOpInitialize) &&
Olli Etuahoff699002015-03-23 14:38:42 +02003416 left->getType().isStructureContainingSamplers())
3417 {
3418 error(loc, "undefined operation for structs containing samplers", GetOperatorString(op));
3419 return false;
3420 }
Olli Etuaho47fd36a2015-03-19 14:22:24 +02003421 case EOpLessThan:
3422 case EOpGreaterThan:
3423 case EOpLessThanEqual:
3424 case EOpGreaterThanEqual:
3425 if ((left->getNominalSize() != right->getNominalSize()) ||
3426 (left->getSecondarySize() != right->getSecondarySize()))
3427 {
3428 return false;
3429 }
3430 default:
3431 break;
3432 }
3433
Olli Etuahod6b14282015-03-17 14:31:35 +02003434 return true;
3435}
3436
Olli Etuahofc1806e2015-03-17 13:03:11 +02003437TIntermTyped *TParseContext::addBinaryMathInternal(TOperator op, TIntermTyped *left, TIntermTyped *right,
3438 const TSourceLoc &loc)
3439{
Olli Etuaho47fd36a2015-03-19 14:22:24 +02003440 if (!binaryOpCommonCheck(op, left, right, loc))
Olli Etuahod6b14282015-03-17 14:31:35 +02003441 return nullptr;
3442
Olli Etuahofc1806e2015-03-17 13:03:11 +02003443 switch (op)
3444 {
3445 case EOpEqual:
3446 case EOpNotEqual:
Olli Etuahofc1806e2015-03-17 13:03:11 +02003447 break;
3448 case EOpLessThan:
3449 case EOpGreaterThan:
3450 case EOpLessThanEqual:
3451 case EOpGreaterThanEqual:
Olli Etuahod6b14282015-03-17 14:31:35 +02003452 ASSERT(!left->isArray() && !right->isArray());
3453 if (left->isMatrix() || left->isVector() ||
Olli Etuahofc1806e2015-03-17 13:03:11 +02003454 left->getBasicType() == EbtStruct)
3455 {
3456 return nullptr;
3457 }
3458 break;
3459 case EOpLogicalOr:
3460 case EOpLogicalXor:
3461 case EOpLogicalAnd:
Olli Etuahod6b14282015-03-17 14:31:35 +02003462 ASSERT(!left->isArray() && !right->isArray());
Olli Etuahofc1806e2015-03-17 13:03:11 +02003463 if (left->getBasicType() != EbtBool ||
Olli Etuahod6b14282015-03-17 14:31:35 +02003464 left->isMatrix() || left->isVector())
Olli Etuahofc1806e2015-03-17 13:03:11 +02003465 {
3466 return nullptr;
3467 }
3468 break;
3469 case EOpAdd:
3470 case EOpSub:
3471 case EOpDiv:
3472 case EOpMul:
Olli Etuahod6b14282015-03-17 14:31:35 +02003473 ASSERT(!left->isArray() && !right->isArray());
Olli Etuahofc1806e2015-03-17 13:03:11 +02003474 if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool)
3475 {
3476 return nullptr;
3477 }
3478 break;
3479 case EOpIMod:
Olli Etuahod6b14282015-03-17 14:31:35 +02003480 ASSERT(!left->isArray() && !right->isArray());
Olli Etuahofc1806e2015-03-17 13:03:11 +02003481 // Note that this is only for the % operator, not for mod()
3482 if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool || left->getBasicType() == EbtFloat)
3483 {
3484 return nullptr;
3485 }
3486 break;
3487 // Note that for bitwise ops, type checking is done in promote() to
3488 // share code between ops and compound assignment
3489 default:
3490 break;
3491 }
3492
Olli Etuahofc1806e2015-03-17 13:03:11 +02003493 return intermediate.addBinaryMath(op, left, right, loc);
3494}
3495
Olli Etuaho09b22472015-02-11 11:47:26 +02003496TIntermTyped *TParseContext::addBinaryMath(TOperator op, TIntermTyped *left, TIntermTyped *right,
3497 const TSourceLoc &loc)
3498{
Olli Etuahofc1806e2015-03-17 13:03:11 +02003499 TIntermTyped *node = addBinaryMathInternal(op, left, right, loc);
Olli Etuaho09b22472015-02-11 11:47:26 +02003500 if (node == 0)
3501 {
3502 binaryOpError(loc, GetOperatorString(op), left->getCompleteString(), right->getCompleteString());
3503 recover();
3504 return left;
3505 }
3506 return node;
3507}
3508
3509TIntermTyped *TParseContext::addBinaryMathBooleanResult(TOperator op, TIntermTyped *left, TIntermTyped *right,
3510 const TSourceLoc &loc)
3511{
Olli Etuahofc1806e2015-03-17 13:03:11 +02003512 TIntermTyped *node = addBinaryMathInternal(op, left, right, loc);
Olli Etuaho09b22472015-02-11 11:47:26 +02003513 if (node == 0)
3514 {
3515 binaryOpError(loc, GetOperatorString(op), left->getCompleteString(), right->getCompleteString());
3516 recover();
Jamie Madill6ba6ead2015-05-04 14:21:21 -04003517 TConstantUnion *unionArray = new TConstantUnion[1];
Olli Etuaho09b22472015-02-11 11:47:26 +02003518 unionArray->setBConst(false);
3519 return intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConst), loc);
3520 }
3521 return node;
3522}
3523
Olli Etuahod6b14282015-03-17 14:31:35 +02003524TIntermTyped *TParseContext::createAssign(TOperator op, TIntermTyped *left, TIntermTyped *right,
3525 const TSourceLoc &loc)
3526{
Olli Etuaho47fd36a2015-03-19 14:22:24 +02003527 if (binaryOpCommonCheck(op, left, right, loc))
Olli Etuahod6b14282015-03-17 14:31:35 +02003528 {
3529 return intermediate.addAssign(op, left, right, loc);
3530 }
3531 return nullptr;
3532}
3533
3534TIntermTyped *TParseContext::addAssign(TOperator op, TIntermTyped *left, TIntermTyped *right,
3535 const TSourceLoc &loc)
3536{
3537 TIntermTyped *node = createAssign(op, left, right, loc);
3538 if (node == nullptr)
3539 {
3540 assignError(loc, "assign", left->getCompleteString(), right->getCompleteString());
3541 recover();
3542 return left;
3543 }
3544 return node;
3545}
3546
Olli Etuaho49300862015-02-20 14:54:49 +02003547TIntermBranch *TParseContext::addBranch(TOperator op, const TSourceLoc &loc)
3548{
3549 switch (op)
3550 {
3551 case EOpContinue:
3552 if (mLoopNestingLevel <= 0)
3553 {
3554 error(loc, "continue statement only allowed in loops", "");
3555 recover();
3556 }
3557 break;
3558 case EOpBreak:
Olli Etuaho53f076f2015-02-20 10:55:14 +02003559 if (mLoopNestingLevel <= 0 && mSwitchNestingLevel <= 0)
Olli Etuaho49300862015-02-20 14:54:49 +02003560 {
Olli Etuaho53f076f2015-02-20 10:55:14 +02003561 error(loc, "break statement only allowed in loops and switch statements", "");
Olli Etuaho49300862015-02-20 14:54:49 +02003562 recover();
3563 }
3564 break;
3565 case EOpReturn:
Jamie Madill6e06b1f2015-05-14 10:01:17 -04003566 if (mCurrentFunctionType->getBasicType() != EbtVoid)
Olli Etuaho49300862015-02-20 14:54:49 +02003567 {
3568 error(loc, "non-void function must return a value", "return");
3569 recover();
3570 }
3571 break;
3572 default:
3573 // No checks for discard
3574 break;
3575 }
3576 return intermediate.addBranch(op, loc);
3577}
3578
3579TIntermBranch *TParseContext::addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc)
3580{
3581 ASSERT(op == EOpReturn);
3582 mFunctionReturnsValue = true;
Jamie Madill6e06b1f2015-05-14 10:01:17 -04003583 if (mCurrentFunctionType->getBasicType() == EbtVoid)
Olli Etuaho49300862015-02-20 14:54:49 +02003584 {
3585 error(loc, "void function cannot return a value", "return");
3586 recover();
3587 }
Jamie Madill6e06b1f2015-05-14 10:01:17 -04003588 else if (*mCurrentFunctionType != returnValue->getType())
Olli Etuaho49300862015-02-20 14:54:49 +02003589 {
3590 error(loc, "function return is not matching type:", "return");
3591 recover();
3592 }
3593 return intermediate.addBranch(op, returnValue, loc);
3594}
3595
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003596TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermNode *paramNode, TIntermNode *thisNode,
3597 const TSourceLoc &loc, bool *fatalError)
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003598{
3599 *fatalError = false;
3600 TOperator op = fnCall->getBuiltInOp();
3601 TIntermTyped *callNode = nullptr;
3602
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003603 if (thisNode != nullptr)
3604 {
Jamie Madill6ba6ead2015-05-04 14:21:21 -04003605 TConstantUnion *unionArray = new TConstantUnion[1];
Olli Etuaho96e67382015-04-23 14:27:02 +03003606 int arraySize = 0;
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003607 TIntermTyped *typedThis = thisNode->getAsTyped();
3608 if (fnCall->getName() != "length")
3609 {
3610 error(loc, "invalid method", fnCall->getName().c_str());
3611 recover();
3612 }
3613 else if (paramNode != nullptr)
3614 {
3615 error(loc, "method takes no parameters", "length");
3616 recover();
3617 }
3618 else if (typedThis == nullptr || !typedThis->isArray())
3619 {
3620 error(loc, "length can only be called on arrays", "length");
3621 recover();
3622 }
3623 else
3624 {
Olli Etuaho96e67382015-04-23 14:27:02 +03003625 arraySize = typedThis->getArraySize();
Olli Etuaho39282e12015-04-23 15:41:48 +03003626 if (typedThis->getAsSymbolNode() == nullptr)
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003627 {
Olli Etuaho39282e12015-04-23 15:41:48 +03003628 // This code path can be hit with expressions like these:
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003629 // (a = b).length()
Olli Etuaho39282e12015-04-23 15:41:48 +03003630 // (func()).length()
3631 // (int[3](0, 1, 2)).length()
3632 // ESSL 3.00 section 5.9 defines expressions so that this is not actually a valid expression.
3633 // It allows "An array name with the length method applied" in contrast to GLSL 4.4 spec section 5.9
3634 // which allows "An array, vector or matrix expression with the length method applied".
3635 error(loc, "length can only be called on array names, not on array expressions", "length");
3636 recover();
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003637 }
3638 }
Olli Etuaho96e67382015-04-23 14:27:02 +03003639 unionArray->setIConst(arraySize);
3640 callNode = intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), loc);
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003641 }
3642 else if (op != EOpNull)
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003643 {
3644 //
3645 // Then this should be a constructor.
3646 // Don't go through the symbol table for constructors.
3647 // Their parameters will be verified algorithmically.
3648 //
3649 TType type(EbtVoid, EbpUndefined); // use this to get the type back
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003650 if (!constructorErrorCheck(loc, paramNode, *fnCall, op, &type))
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003651 {
3652 //
3653 // It's a constructor, of type 'type'.
3654 //
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003655 callNode = addConstructor(paramNode, &type, op, fnCall, loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003656 }
Olli Etuaho72ba85b2015-03-04 14:23:26 +02003657
3658 if (callNode == nullptr)
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003659 {
3660 recover();
3661 callNode = intermediate.setAggregateOperator(nullptr, op, loc);
3662 }
3663 callNode->setType(type);
3664 }
3665 else
3666 {
3667 //
3668 // Not a constructor. Find it in the symbol table.
3669 //
Arun Patole7e7e68d2015-05-22 12:02:25 +05303670 const TFunction *fnCandidate;
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003671 bool builtIn;
Jamie Madill6e06b1f2015-05-14 10:01:17 -04003672 fnCandidate = findFunction(loc, fnCall, mShaderVersion, &builtIn);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003673 if (fnCandidate)
3674 {
3675 //
3676 // A declared function.
3677 //
3678 if (builtIn && !fnCandidate->getExtension().empty() &&
3679 extensionErrorCheck(loc, fnCandidate->getExtension()))
3680 {
3681 recover();
3682 }
3683 op = fnCandidate->getBuiltInOp();
3684 if (builtIn && op != EOpNull)
3685 {
3686 //
3687 // A function call mapped to a built-in operation.
3688 //
3689 if (fnCandidate->getParamCount() == 1)
3690 {
3691 //
3692 // Treat it like a built-in unary operator.
3693 //
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003694 callNode = createUnaryMath(op, paramNode->getAsTyped(), loc, &fnCandidate->getReturnType());
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003695 if (callNode == nullptr)
3696 {
3697 std::stringstream extraInfoStream;
3698 extraInfoStream << "built in unary operator function. Type: "
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003699 << static_cast<TIntermTyped*>(paramNode)->getCompleteString();
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003700 std::string extraInfo = extraInfoStream.str();
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003701 error(paramNode->getLine(), " wrong operand type", "Internal Error", extraInfo.c_str());
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003702 *fatalError = true;
3703 return nullptr;
3704 }
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003705 }
3706 else
3707 {
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003708 TIntermAggregate *aggregate = intermediate.setAggregateOperator(paramNode, op, loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003709 aggregate->setType(fnCandidate->getReturnType());
3710 aggregate->setPrecisionFromChildren();
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003711
3712 // Some built-in functions have out parameters too.
3713 functionCallLValueErrorCheck(fnCandidate, aggregate);
Arun Patole274f0702015-05-05 13:33:30 +05303714
3715 // See if we can constant fold a built-in.
Olli Etuahob43846e2015-06-02 18:18:57 +03003716 TIntermTyped *foldedNode = intermediate.foldAggregateBuiltIn(aggregate);
Arun Patole274f0702015-05-05 13:33:30 +05303717 if (foldedNode)
3718 {
Arun Patole274f0702015-05-05 13:33:30 +05303719 callNode = foldedNode;
3720 }
Olli Etuahob43846e2015-06-02 18:18:57 +03003721 else
3722 {
3723 callNode = aggregate;
3724 }
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003725 }
3726 }
3727 else
3728 {
3729 // This is a real function call
3730
Olli Etuahoffe6edf2015-04-13 17:32:03 +03003731 TIntermAggregate *aggregate = intermediate.setAggregateOperator(paramNode, EOpFunctionCall, loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003732 aggregate->setType(fnCandidate->getReturnType());
3733
3734 // this is how we know whether the given function is a builtIn function or a user defined function
3735 // if builtIn == false, it's a userDefined -> could be an overloaded builtIn function also
3736 // if builtIn == true, it's definitely a builtIn function with EOpNull
3737 if (!builtIn)
3738 aggregate->setUserDefined();
3739 aggregate->setName(fnCandidate->getMangledName());
Corentin Wallez71d147f2015-02-11 11:15:24 -08003740 aggregate->setFunctionId(fnCandidate->getUniqueId());
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003741
3742 // This needs to happen after the name is set
3743 if (builtIn)
3744 aggregate->setBuiltInFunctionPrecision();
3745
3746 callNode = aggregate;
3747
3748 functionCallLValueErrorCheck(fnCandidate, aggregate);
3749 }
3750 }
3751 else
3752 {
3753 // error message was put out by findFunction()
3754 // Put on a dummy node for error recovery
Jamie Madill6ba6ead2015-05-04 14:21:21 -04003755 TConstantUnion *unionArray = new TConstantUnion[1];
Olli Etuahoc4ba3be2015-03-02 14:42:24 +02003756 unionArray->setFConst(0.0f);
3757 callNode = intermediate.addConstantUnion(unionArray, TType(EbtFloat, EbpUndefined, EvqConst), loc);
3758 recover();
3759 }
3760 }
3761 delete fnCall;
3762 return callNode;
3763}
3764
Olli Etuaho52901742015-04-15 13:42:45 +03003765TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock,
3766 const TSourceLoc &loc)
3767{
3768 if (boolErrorCheck(loc, cond))
3769 recover();
3770
3771 if (trueBlock->getType() != falseBlock->getType())
3772 {
3773 binaryOpError(loc, ":", trueBlock->getCompleteString(), falseBlock->getCompleteString());
3774 recover();
3775 return falseBlock;
3776 }
Olli Etuahoa2d53032015-04-15 14:14:44 +03003777 // ESSL1 sections 5.2 and 5.7:
3778 // ESSL3 section 5.7:
3779 // Ternary operator is not among the operators allowed for structures/arrays.
3780 if (trueBlock->isArray() || trueBlock->getBasicType() == EbtStruct)
3781 {
3782 error(loc, "ternary operator is not allowed for structures or arrays", ":");
3783 recover();
3784 return falseBlock;
3785 }
Olli Etuaho52901742015-04-15 13:42:45 +03003786 return intermediate.addSelection(cond, trueBlock, falseBlock, loc);
3787}
Olli Etuaho49300862015-02-20 14:54:49 +02003788
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +00003789//
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00003790// Parse an array of strings using yyparse.
3791//
3792// Returns 0 for success.
3793//
Arun Patole7e7e68d2015-05-22 12:02:25 +05303794int PaParseStrings(size_t count, const char *const string[], const int length[],
3795 TParseContext *context)
3796{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00003797 if ((count == 0) || (string == NULL))
3798 return 1;
3799
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00003800 if (glslang_initialize(context))
3801 return 1;
3802
alokp@chromium.org408c45e2012-04-05 15:54:43 +00003803 int error = glslang_scan(count, string, length, context);
3804 if (!error)
3805 error = glslang_parse(context);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00003806
alokp@chromium.org73bc2982012-06-19 18:48:05 +00003807 glslang_finalize(context);
alokp@chromium.org8b851c62012-06-15 16:25:11 +00003808
alokp@chromium.org6b495712012-06-29 00:06:58 +00003809 return (error == 0) && (context->numErrors() == 0) ? 0 : 1;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00003810}
3811
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003812
alokp@chromium.org34b99cd2010-07-27 18:37:55 +00003813