blob: 9db6a66bd5829df559017d56e2ab9c358955842b [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Nicolas Capens16004fc2014-06-11 11:29:11 -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//
Geoff Lang0a73dd82014-11-19 16:18:08 -05006#ifndef COMPILER_TRANSLATOR_PARSECONTEXT_H_
7#define COMPILER_TRANSLATOR_PARSECONTEXT_H_
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008
Jamie Madilld4a3a312014-06-25 16:04:56 -04009#include "compiler/translator/Compiler.h"
Geoff Lang17732822013-08-29 13:46:49 -040010#include "compiler/translator/Diagnostics.h"
11#include "compiler/translator/DirectiveHandler.h"
Jamie Madillb1a85f42014-08-19 15:23:24 -040012#include "compiler/translator/Intermediate.h"
Geoff Lang17732822013-08-29 13:46:49 -040013#include "compiler/translator/SymbolTable.h"
Martin Radev70866b82016-07-22 15:27:42 +030014#include "compiler/translator/QualifierTypes.h"
daniel@transgaming.comb401a922012-10-26 18:58:24 +000015#include "compiler/preprocessor/Preprocessor.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000016
Jamie Madill06145232015-05-13 13:10:01 -040017struct TMatrixFields
18{
daniel@transgaming.com0578f812010-05-17 09:58:39 +000019 bool wholeRow;
20 bool wholeCol;
21 int row;
22 int col;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000023};
24
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025//
26// The following are extra variables needed during parsing, grouped together so
27// they can be passed to the parser without needing a global.
28//
Jamie Madill6e06b1f2015-05-14 10:01:17 -040029class TParseContext : angle::NonCopyable
Jamie Madill06145232015-05-13 13:10:01 -040030{
Jamie Madill6e06b1f2015-05-14 10:01:17 -040031 public:
Jamie Madill06145232015-05-13 13:10:01 -040032 TParseContext(TSymbolTable &symt,
33 TExtensionBehavior &ext,
34 TIntermediate &interm,
35 sh::GLenum type,
36 ShShaderSpec spec,
37 int options,
38 bool checksPrecErrors,
39 TInfoSink &is,
Olli Etuahoe1a94c62015-11-16 17:35:25 +020040 const ShBuiltInResources &resources)
Jamie Madill06145232015-05-13 13:10:01 -040041 : intermediate(interm),
42 symbolTable(symt),
Corentin Wallezbc99bb62015-05-14 17:42:20 -040043 mDeferredSingleDeclarationErrorCheck(false),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040044 mShaderType(type),
45 mShaderSpec(spec),
Kenneth Russellbccc65d2016-07-19 16:48:43 -070046 mCompileOptions(options),
Corentin Wallezbc99bb62015-05-14 17:42:20 -040047 mShaderVersion(100),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040048 mTreeRoot(nullptr),
Jamie Madill06145232015-05-13 13:10:01 -040049 mLoopNestingLevel(0),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040050 mStructNestingLevel(0),
Jamie Madill06145232015-05-13 13:10:01 -040051 mSwitchNestingLevel(0),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040052 mCurrentFunctionType(nullptr),
Jamie Madill06145232015-05-13 13:10:01 -040053 mFunctionReturnsValue(false),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040054 mChecksPrecisionErrors(checksPrecErrors),
Olli Etuahoa6996682015-10-12 14:32:30 +030055 mFragmentPrecisionHighOnESSL1(false),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040056 mDefaultMatrixPacking(EmpColumnMajor),
57 mDefaultBlockStorage(EbsShared),
58 mDiagnostics(is),
Olli Etuahoe1a94c62015-11-16 17:35:25 +020059 mDirectiveHandler(ext,
60 mDiagnostics,
61 mShaderVersion,
Olli Etuaho5f80d012016-01-11 11:16:01 +020062 mShaderType,
Olli Etuahoe1a94c62015-11-16 17:35:25 +020063 resources.WEBGL_debug_shader_precision == 1),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040064 mPreprocessor(&mDiagnostics, &mDirectiveHandler),
65 mScanner(nullptr),
Jamie Madill14e95b32015-05-07 10:10:41 -040066 mUsesFragData(false),
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +030067 mUsesFragColor(false),
Olli Etuahoe1a94c62015-11-16 17:35:25 +020068 mUsesSecondaryOutputs(false),
69 mMinProgramTexelOffset(resources.MinProgramTexelOffset),
Martin Radev802abe02016-08-04 17:48:32 +030070 mMaxProgramTexelOffset(resources.MaxProgramTexelOffset),
Martin Radev70866b82016-07-22 15:27:42 +030071 mComputeShaderLocalSizeDeclared(false),
72 mDeclaringFunction(false)
Olli Etuahofa33d582015-04-09 14:33:12 +030073 {
Martin Radev802abe02016-08-04 17:48:32 +030074 mComputeShaderLocalSize.fill(-1);
Olli Etuahofa33d582015-04-09 14:33:12 +030075 }
Jamie Madill06145232015-05-13 13:10:01 -040076
Jamie Madill6e06b1f2015-05-14 10:01:17 -040077 const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
78 pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
79 void *getScanner() const { return mScanner; }
80 void setScanner(void *scanner) { mScanner = scanner; }
81 int getShaderVersion() const { return mShaderVersion; }
82 sh::GLenum getShaderType() const { return mShaderType; }
83 ShShaderSpec getShaderSpec() const { return mShaderSpec; }
84 int numErrors() const { return mDiagnostics.numErrors(); }
85 TInfoSink &infoSink() { return mDiagnostics.infoSink(); }
Jamie Madill06145232015-05-13 13:10:01 -040086 void error(const TSourceLoc &loc, const char *reason, const char *token,
87 const char *extraInfo="");
88 void warning(const TSourceLoc &loc, const char *reason, const char *token,
89 const char *extraInfo="");
Jamie Madill14e95b32015-05-07 10:10:41 -040090
Olli Etuaho7c3848e2015-11-04 13:19:17 +020091 // If isError is false, a warning will be reported instead.
92 void outOfRangeError(bool isError,
93 const TSourceLoc &loc,
94 const char *reason,
95 const char *token,
96 const char *extraInfo = "");
97
Jamie Madill6e06b1f2015-05-14 10:01:17 -040098 TIntermNode *getTreeRoot() const { return mTreeRoot; }
99 void setTreeRoot(TIntermNode *treeRoot) { mTreeRoot = treeRoot; }
100
Olli Etuahoa6996682015-10-12 14:32:30 +0300101 bool getFragmentPrecisionHigh() const
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400102 {
Olli Etuahoa6996682015-10-12 14:32:30 +0300103 return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300;
104 }
105 void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh)
106 {
107 mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400108 }
109
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400110 void setLoopNestingLevel(int loopNestintLevel)
111 {
112 mLoopNestingLevel = loopNestintLevel;
113 }
114
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400115 void incrLoopNestingLevel() { ++mLoopNestingLevel; }
116 void decrLoopNestingLevel() { --mLoopNestingLevel; }
117
118 void incrSwitchNestingLevel() { ++mSwitchNestingLevel; }
119 void decrSwitchNestingLevel() { --mSwitchNestingLevel; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000120
Martin Radev802abe02016-08-04 17:48:32 +0300121 bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; }
Martin Radev4c4c8e72016-08-04 12:25:34 +0300122 sh::WorkGroupSize getComputeShaderLocalSize() const;
Martin Radev802abe02016-08-04 17:48:32 +0300123
Martin Radev70866b82016-07-22 15:27:42 +0300124 void enterFunctionDeclaration() { mDeclaringFunction = true; }
125
126 void exitFunctionDeclaration() { mDeclaringFunction = false; }
127
128 bool declaringFunction() const { return mDeclaringFunction; }
129
Jamie Madill5c097022014-08-20 16:38:32 -0400130 // This method is guaranteed to succeed, even if no variable with 'name' exists.
131 const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol);
Olli Etuaho82c29ed2015-11-03 13:06:54 +0200132 TIntermTyped *parseVariableIdentifier(const TSourceLoc &location,
133 const TString *name,
134 const TSymbol *symbol);
Jamie Madill5c097022014-08-20 16:38:32 -0400135
Jamie Madill06145232015-05-13 13:10:01 -0400136 bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc &line);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000137
Jamie Madill06145232015-05-13 13:10:01 -0400138 void assignError(const TSourceLoc &line, const char *op, TString left, TString right);
139 void unaryOpError(const TSourceLoc &line, const char *op, TString operand);
140 void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right);
Olli Etuaho856c4972016-08-08 11:38:39 +0300141
Olli Etuaho8a176262016-08-16 14:23:01 +0300142 // Check functions - the ones that return bool return false if an error was generated.
143
Olli Etuaho856c4972016-08-08 11:38:39 +0300144 bool checkIsNotReserved(const TSourceLoc &line, const TString &identifier);
145 void checkPrecisionSpecified(const TSourceLoc &line, TPrecision precision, TBasicType type);
146 bool checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node);
147 void checkIsConst(TIntermTyped *node);
148 void checkIsScalarInteger(TIntermTyped *node, const char *token);
Qiankun Miaof69682b2016-08-16 14:50:42 +0800149 bool checkIsAtGlobalLevel(const TSourceLoc &line, const char *token);
Olli Etuaho856c4972016-08-08 11:38:39 +0300150 bool checkConstructorArguments(const TSourceLoc &line,
151 TIntermNode *argumentsNode,
152 const TFunction &function,
153 TOperator op,
154 const TType &type);
155
156 // Returns a sanitized array size to use (the size is at least 1).
157 unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr);
Olli Etuaho8a176262016-08-16 14:23:01 +0300158 bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &elementQualifier);
159 bool checkIsValidTypeForArray(const TSourceLoc &line, const TPublicType &elementType);
Olli Etuaho856c4972016-08-08 11:38:39 +0300160 bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
161 void checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type);
162 void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType);
Martin Radev4a9cd802016-09-01 16:51:51 +0300163 bool checkIsNotSampler(const TSourceLoc &line,
164 const TTypeSpecifierNonArray &pType,
165 const char *reason);
Olli Etuaho856c4972016-08-08 11:38:39 +0300166 void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType);
167 void checkLocationIsNotSpecified(const TSourceLoc &location,
168 const TLayoutQualifier &layoutQualifier);
169 void checkOutParameterIsNotSampler(const TSourceLoc &line,
170 TQualifier qualifier,
171 const TType &type);
172 void checkIsParameterQualifierValid(const TSourceLoc &line,
Martin Radev70866b82016-07-22 15:27:42 +0300173 const TTypeQualifierBuilder &typeQualifierBuilder,
Olli Etuaho856c4972016-08-08 11:38:39 +0300174 TType *type);
175 bool checkCanUseExtension(const TSourceLoc &line, const TString &extension);
Olli Etuaho383b7912016-08-05 11:22:59 +0300176 void singleDeclarationErrorCheck(const TPublicType &publicType,
177 const TSourceLoc &identifierLocation);
Olli Etuaho856c4972016-08-08 11:38:39 +0300178 void checkLayoutQualifierSupported(const TSourceLoc &location,
179 const TString &layoutQualifierName,
180 int versionRequired);
181 bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location,
182 const TLayoutQualifier &layoutQualifier);
183
184 void functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall);
Martin Radev70866b82016-07-22 15:27:42 +0300185 void checkInvariantVariableQualifier(bool invariant,
186 const TQualifier qualifier,
187 const TSourceLoc &invariantLocation);
Olli Etuaho856c4972016-08-08 11:38:39 +0300188 void checkInputOutputTypeIsValidES3(const TQualifier qualifier,
189 const TPublicType &type,
190 const TSourceLoc &qualifierLocation);
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000191
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400192 const TPragma &pragma() const { return mDirectiveHandler.pragma(); }
193 const TExtensionBehavior &extensionBehavior() const { return mDirectiveHandler.extensionBehavior(); }
Jamie Madill06145232015-05-13 13:10:01 -0400194 bool supportsExtension(const char *extension);
195 bool isExtensionEnabled(const char *extension) const;
196 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
197 void handlePragmaDirective(const TSourceLoc &loc, const char *name, const char *value, bool stdgl);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000198
Jamie Madill06145232015-05-13 13:10:01 -0400199 bool containsSampler(const TType &type);
Jamie Madill06145232015-05-13 13:10:01 -0400200 const TFunction* findFunction(
201 const TSourceLoc &line, TFunction *pfnCall, int inputShaderVersion, bool *builtIn = 0);
202 bool executeInitializer(const TSourceLoc &line,
203 const TString &identifier,
204 const TPublicType &pType,
205 TIntermTyped *initializer,
206 TIntermNode **intermNode);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000207
Martin Radev70866b82016-07-22 15:27:42 +0300208 TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400209 const TPublicType &typeSpecifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200210
Olli Etuahofa33d582015-04-09 14:33:12 +0300211 TIntermAggregate *parseSingleDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400212 const TSourceLoc &identifierOrTypeLocation,
213 const TString &identifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200214 TIntermAggregate *parseSingleArrayDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400215 const TSourceLoc &identifierLocation,
216 const TString &identifier,
217 const TSourceLoc &indexLocation,
218 TIntermTyped *indexExpression);
219 TIntermAggregate *parseSingleInitDeclaration(const TPublicType &publicType,
220 const TSourceLoc &identifierLocation,
221 const TString &identifier,
222 const TSourceLoc &initLocation,
223 TIntermTyped *initializer);
Jamie Madill47e3ec02014-08-20 16:38:33 -0400224
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300225 // Parse a declaration like "type a[n] = initializer"
226 // Note that this does not apply to declarations like "type[n] a = initializer"
227 TIntermAggregate *parseSingleArrayInitDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400228 const TSourceLoc &identifierLocation,
229 const TString &identifier,
230 const TSourceLoc &indexLocation,
231 TIntermTyped *indexExpression,
232 const TSourceLoc &initLocation,
233 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300234
Martin Radev70866b82016-07-22 15:27:42 +0300235 TIntermAggregate *parseInvariantDeclaration(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400236 const TSourceLoc &identifierLoc,
237 const TString *identifier,
238 const TSymbol *symbol);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200239
Jamie Madill06145232015-05-13 13:10:01 -0400240 TIntermAggregate *parseDeclarator(TPublicType &publicType,
241 TIntermAggregate *aggregateDeclaration,
242 const TSourceLoc &identifierLocation,
243 const TString &identifier);
244 TIntermAggregate *parseArrayDeclarator(TPublicType &publicType,
245 TIntermAggregate *aggregateDeclaration,
246 const TSourceLoc &identifierLocation,
247 const TString &identifier,
248 const TSourceLoc &arrayLocation,
249 TIntermTyped *indexExpression);
250 TIntermAggregate *parseInitDeclarator(const TPublicType &publicType,
251 TIntermAggregate *aggregateDeclaration,
252 const TSourceLoc &identifierLocation,
253 const TString &identifier,
254 const TSourceLoc &initLocation,
255 TIntermTyped *initializer);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200256
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300257 // Parse a declarator like "a[n] = initializer"
Jamie Madill06145232015-05-13 13:10:01 -0400258 TIntermAggregate *parseArrayInitDeclarator(const TPublicType &publicType,
259 TIntermAggregate *aggregateDeclaration,
260 const TSourceLoc &identifierLocation,
261 const TString &identifier,
262 const TSourceLoc &indexLocation,
263 TIntermTyped *indexExpression,
264 const TSourceLoc &initLocation,
265 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300266
Martin Radev70866b82016-07-22 15:27:42 +0300267 void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder);
Olli Etuahoee63f5d2016-01-04 11:34:54 +0200268 TIntermAggregate *addFunctionPrototypeDeclaration(const TFunction &function,
269 const TSourceLoc &location);
270 TIntermAggregate *addFunctionDefinition(const TFunction &function,
271 TIntermAggregate *functionPrototype,
272 TIntermAggregate *functionBody,
273 const TSourceLoc &location);
Jamie Madill185fb402015-06-12 15:48:48 -0400274 void parseFunctionPrototype(const TSourceLoc &location,
275 TFunction *function,
276 TIntermAggregate **aggregateOut);
277 TFunction *parseFunctionDeclarator(const TSourceLoc &location,
278 TFunction *function);
Olli Etuaho9de84a52016-06-14 17:36:01 +0300279 TFunction *parseFunctionHeader(const TPublicType &type,
280 const TString *name,
281 const TSourceLoc &location);
Jamie Madill06145232015-05-13 13:10:01 -0400282 TFunction *addConstructorFunc(const TPublicType &publicType);
283 TIntermTyped *addConstructor(TIntermNode *arguments,
Jamie Madill06145232015-05-13 13:10:01 -0400284 TOperator op,
285 TFunction *fnCall,
286 const TSourceLoc &line);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300287
Jamie Madill06145232015-05-13 13:10:01 -0400288 TIntermTyped *addConstStruct(
289 const TString &identifier, TIntermTyped *node, const TSourceLoc& line);
290 TIntermTyped *addIndexExpression(TIntermTyped *baseExpression,
291 const TSourceLoc& location,
292 TIntermTyped *indexExpression);
293 TIntermTyped* addFieldSelectionExpression(TIntermTyped *baseExpression,
294 const TSourceLoc &dotLocation,
295 const TString &fieldString,
296 const TSourceLoc &fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +0000297
Martin Radev70866b82016-07-22 15:27:42 +0300298 TFieldList *addStructDeclaratorListWithQualifiers(
299 const TTypeQualifierBuilder &typeQualifierBuilder,
300 TPublicType *typeSpecifier,
301 TFieldList *fieldList);
Jamie Madill06145232015-05-13 13:10:01 -0400302 TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList);
Martin Radev4a9cd802016-09-01 16:51:51 +0300303 TTypeSpecifierNonArray addStructure(const TSourceLoc &structLine,
304 const TSourceLoc &nameLine,
305 const TString *structName,
306 TFieldList *fieldList);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000307
Martin Radev70866b82016-07-22 15:27:42 +0300308 TIntermAggregate *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400309 const TSourceLoc &nameLine,
310 const TString &blockName,
311 TFieldList *fieldList,
312 const TString *instanceName,
313 const TSourceLoc &instanceLine,
314 TIntermTyped *arrayIndex,
Martin Radev70866b82016-07-22 15:27:42 +0300315 const TSourceLoc &arrayIndexLine);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000316
Martin Radev802abe02016-08-04 17:48:32 +0300317 void parseLocalSize(const TString &qualifierType,
318 const TSourceLoc &qualifierTypeLine,
319 int intValue,
320 const TSourceLoc &intValueLine,
321 const std::string &intValueString,
322 size_t index,
Martin Radev4c4c8e72016-08-04 12:25:34 +0300323 sh::WorkGroupSize *localSize);
Jamie Madill06145232015-05-13 13:10:01 -0400324 TLayoutQualifier parseLayoutQualifier(
325 const TString &qualifierType, const TSourceLoc &qualifierTypeLine);
326 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
327 const TSourceLoc &qualifierTypeLine,
Jamie Madill06145232015-05-13 13:10:01 -0400328 int intValue,
329 const TSourceLoc &intValueLine);
Olli Etuaho613b9592016-09-05 12:05:53 +0300330 TTypeQualifierBuilder *createTypeQualifierBuilder(const TSourceLoc &loc);
Martin Radev802abe02016-08-04 17:48:32 +0300331 TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier,
332 TLayoutQualifier rightQualifier,
333 const TSourceLoc &rightQualifierLocation);
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000334
kbr@chromium.org476541f2011-10-27 21:14:51 +0000335 // Performs an error check for embedded struct declarations.
Olli Etuaho383b7912016-08-05 11:22:59 +0300336 void enterStructDeclaration(const TSourceLoc &line, const TString &identifier);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000337 void exitStructDeclaration();
338
Olli Etuaho8a176262016-08-16 14:23:01 +0300339 void checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field);
Olli Etuaho09b22472015-02-11 11:47:26 +0200340
Olli Etuahoa3a36662015-02-17 13:46:51 +0200341 TIntermSwitch *addSwitch(TIntermTyped *init, TIntermAggregate *statementList, const TSourceLoc &loc);
342 TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc);
343 TIntermCase *addDefault(const TSourceLoc &loc);
344
Jamie Madill06145232015-05-13 13:10:01 -0400345 TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
346 TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
347 TIntermTyped *addBinaryMath(
348 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
349 TIntermTyped *addBinaryMathBooleanResult(
350 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
351 TIntermTyped *addAssign(
352 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuaho49300862015-02-20 14:54:49 +0200353
Olli Etuaho0b2d2dc2015-11-04 16:35:32 +0200354 TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
355
Olli Etuaho49300862015-02-20 14:54:49 +0200356 TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc);
357 TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +0200358
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200359 void checkTextureOffsetConst(TIntermAggregate *functionCall);
Jamie Madill06145232015-05-13 13:10:01 -0400360 TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall,
361 TIntermNode *paramNode,
362 TIntermNode *thisNode,
363 const TSourceLoc &loc,
364 bool *fatalError);
Olli Etuahofc1806e2015-03-17 13:03:11 +0200365
Jamie Madill06145232015-05-13 13:10:01 -0400366 TIntermTyped *addTernarySelection(
367 TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock, const TSourceLoc &line);
Olli Etuaho52901742015-04-15 13:42:45 +0300368
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400369 // TODO(jmadill): make these private
370 TIntermediate &intermediate; // to hold and build a parse tree
371 TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed
372
Olli Etuahofc1806e2015-03-17 13:03:11 +0200373 private:
Olli Etuaho90892fb2016-07-14 14:44:51 +0300374 // Returns a clamped index.
375 int checkIndexOutOfRange(bool outOfRangeIndexIsError,
376 const TSourceLoc &location,
377 int index,
378 int arraySize,
379 const char *reason,
380 const char *token);
381
382 // Constant folding for element access. Note that the returned node does not have the correct
383 // type - it is expected to be fixed later.
384 TIntermConstantUnion *foldVectorSwizzle(TVectorFields &fields,
385 TIntermConstantUnion *baseNode,
386 const TSourceLoc &location);
387 TIntermConstantUnion *foldMatrixSubscript(int index,
388 TIntermConstantUnion *baseNode,
389 const TSourceLoc &location);
390 TIntermConstantUnion *foldArraySubscript(int index,
391 TIntermConstantUnion *baseNode,
392 const TSourceLoc &location);
393
Olli Etuaho2935c582015-04-08 14:32:06 +0300394 bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable);
395
Olli Etuaho856c4972016-08-08 11:38:39 +0300396 void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line,
397 const TString &identifier,
398 TPublicType *type);
Olli Etuaho376f1b52015-04-13 13:23:41 +0300399
Olli Etuaho8a176262016-08-16 14:23:01 +0300400 bool checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation,
401 const TPublicType &elementType);
402
Olli Etuaho1dded802016-08-18 18:13:13 +0300403 // Assumes that multiplication op has already been set based on the types.
404 bool isMultiplicationTypeCombinationValid(TOperator op, const TType &left, const TType &right);
405
Jamie Madill06145232015-05-13 13:10:01 -0400406 TIntermTyped *addBinaryMathInternal(
407 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
408 TIntermTyped *createAssign(
409 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuahof6c694b2015-03-26 14:50:53 +0200410 // The funcReturnType parameter is expected to be non-null when the operation is a built-in function.
411 // It is expected to be null for other unary operators.
Jamie Madill06145232015-05-13 13:10:01 -0400412 TIntermTyped *createUnaryMath(
413 TOperator op, TIntermTyped *child, const TSourceLoc &loc, const TType *funcReturnType);
Olli Etuahod6b14282015-03-17 14:31:35 +0200414
Olli Etuaho47fd36a2015-03-19 14:22:24 +0200415 // Return true if the checks pass
Jamie Madill06145232015-05-13 13:10:01 -0400416 bool binaryOpCommonCheck(
417 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuahofa33d582015-04-09 14:33:12 +0300418
419 // Set to true when the last/current declarator list was started with an empty declaration.
420 bool mDeferredSingleDeclarationErrorCheck;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400421
422 sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
423 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700424 int mCompileOptions; // Options passed to TCompiler
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400425 int mShaderVersion;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400426 TIntermNode *mTreeRoot; // root of parse tree being created
427 int mLoopNestingLevel; // 0 if outside all loops
428 int mStructNestingLevel; // incremented while parsing a struct declaration
429 int mSwitchNestingLevel; // 0 if outside all switch statements
430 const TType *mCurrentFunctionType; // the return type of the function that's currently being parsed
431 bool mFunctionReturnsValue; // true if a non-void function has a return
432 bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit.
Olli Etuahoa6996682015-10-12 14:32:30 +0300433 bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling
434 // ESSL1.
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400435 TLayoutMatrixPacking mDefaultMatrixPacking;
436 TLayoutBlockStorage mDefaultBlockStorage;
437 TString mHashErrMsg;
438 TDiagnostics mDiagnostics;
439 TDirectiveHandler mDirectiveHandler;
440 pp::Preprocessor mPreprocessor;
441 void *mScanner;
Jamie Madill14e95b32015-05-07 10:10:41 -0400442 bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
443 bool mUsesFragColor;
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +0300444 bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or
445 // gl_Secondary FragColor or both.
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200446 int mMinProgramTexelOffset;
447 int mMaxProgramTexelOffset;
Martin Radev802abe02016-08-04 17:48:32 +0300448
449 // keep track of local group size declared in layout. It should be declared only once.
450 bool mComputeShaderLocalSizeDeclared;
Martin Radev4c4c8e72016-08-04 12:25:34 +0300451 sh::WorkGroupSize mComputeShaderLocalSize;
Martin Radev70866b82016-07-22 15:27:42 +0300452 // keeps track whether we are declaring / defining a function
453 bool mDeclaringFunction;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000454};
455
Jamie Madill06145232015-05-13 13:10:01 -0400456int PaParseStrings(
457 size_t count, const char *const string[], const int length[], TParseContext *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000458
Geoff Lang0a73dd82014-11-19 16:18:08 -0500459#endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_