blob: c2c4bf2b4ac7eb82fa4b3edef0d4c234bb77fc62 [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,
Jamie Madill06145232015-05-13 13:10:01 -040034 sh::GLenum type,
35 ShShaderSpec spec,
Qiankun Miao7ebb97f2016-09-08 18:01:50 +080036 ShCompileOptions options,
Jamie Madill06145232015-05-13 13:10:01 -040037 bool checksPrecErrors,
38 TInfoSink &is,
Olli Etuahoe1a94c62015-11-16 17:35:25 +020039 const ShBuiltInResources &resources)
Olli Etuahof119a262016-08-19 15:54:22 +030040 : intermediate(),
Jamie Madill06145232015-05-13 13:10:01 -040041 symbolTable(symt),
Corentin Wallezbc99bb62015-05-14 17:42:20 -040042 mDeferredSingleDeclarationErrorCheck(false),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040043 mShaderType(type),
44 mShaderSpec(spec),
Kenneth Russellbccc65d2016-07-19 16:48:43 -070045 mCompileOptions(options),
Corentin Wallezbc99bb62015-05-14 17:42:20 -040046 mShaderVersion(100),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040047 mTreeRoot(nullptr),
Jamie Madill06145232015-05-13 13:10:01 -040048 mLoopNestingLevel(0),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040049 mStructNestingLevel(0),
Jamie Madill06145232015-05-13 13:10:01 -040050 mSwitchNestingLevel(0),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040051 mCurrentFunctionType(nullptr),
Jamie Madill06145232015-05-13 13:10:01 -040052 mFunctionReturnsValue(false),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040053 mChecksPrecisionErrors(checksPrecErrors),
Olli Etuahoa6996682015-10-12 14:32:30 +030054 mFragmentPrecisionHighOnESSL1(false),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040055 mDefaultMatrixPacking(EmpColumnMajor),
56 mDefaultBlockStorage(EbsShared),
57 mDiagnostics(is),
Olli Etuahoe1a94c62015-11-16 17:35:25 +020058 mDirectiveHandler(ext,
59 mDiagnostics,
60 mShaderVersion,
Olli Etuaho5f80d012016-01-11 11:16:01 +020061 mShaderType,
Olli Etuahoe1a94c62015-11-16 17:35:25 +020062 resources.WEBGL_debug_shader_precision == 1),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040063 mPreprocessor(&mDiagnostics, &mDirectiveHandler),
64 mScanner(nullptr),
Jamie Madill14e95b32015-05-07 10:10:41 -040065 mUsesFragData(false),
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +030066 mUsesFragColor(false),
Olli Etuahoe1a94c62015-11-16 17:35:25 +020067 mUsesSecondaryOutputs(false),
68 mMinProgramTexelOffset(resources.MinProgramTexelOffset),
Martin Radev802abe02016-08-04 17:48:32 +030069 mMaxProgramTexelOffset(resources.MaxProgramTexelOffset),
Martin Radev70866b82016-07-22 15:27:42 +030070 mComputeShaderLocalSizeDeclared(false),
71 mDeclaringFunction(false)
Olli Etuahofa33d582015-04-09 14:33:12 +030072 {
Martin Radev802abe02016-08-04 17:48:32 +030073 mComputeShaderLocalSize.fill(-1);
Olli Etuahofa33d582015-04-09 14:33:12 +030074 }
Jamie Madill06145232015-05-13 13:10:01 -040075
Jamie Madill6e06b1f2015-05-14 10:01:17 -040076 const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
77 pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
78 void *getScanner() const { return mScanner; }
79 void setScanner(void *scanner) { mScanner = scanner; }
80 int getShaderVersion() const { return mShaderVersion; }
81 sh::GLenum getShaderType() const { return mShaderType; }
82 ShShaderSpec getShaderSpec() const { return mShaderSpec; }
83 int numErrors() const { return mDiagnostics.numErrors(); }
84 TInfoSink &infoSink() { return mDiagnostics.infoSink(); }
Jamie Madill06145232015-05-13 13:10:01 -040085 void error(const TSourceLoc &loc, const char *reason, const char *token,
86 const char *extraInfo="");
87 void warning(const TSourceLoc &loc, const char *reason, const char *token,
88 const char *extraInfo="");
Jamie Madill14e95b32015-05-07 10:10:41 -040089
Olli Etuaho7c3848e2015-11-04 13:19:17 +020090 // If isError is false, a warning will be reported instead.
91 void outOfRangeError(bool isError,
92 const TSourceLoc &loc,
93 const char *reason,
94 const char *token,
95 const char *extraInfo = "");
96
Jamie Madill6e06b1f2015-05-14 10:01:17 -040097 TIntermNode *getTreeRoot() const { return mTreeRoot; }
98 void setTreeRoot(TIntermNode *treeRoot) { mTreeRoot = treeRoot; }
99
Olli Etuahoa6996682015-10-12 14:32:30 +0300100 bool getFragmentPrecisionHigh() const
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400101 {
Olli Etuahoa6996682015-10-12 14:32:30 +0300102 return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300;
103 }
104 void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh)
105 {
106 mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400107 }
108
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400109 void setLoopNestingLevel(int loopNestintLevel)
110 {
111 mLoopNestingLevel = loopNestintLevel;
112 }
113
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400114 void incrLoopNestingLevel() { ++mLoopNestingLevel; }
115 void decrLoopNestingLevel() { --mLoopNestingLevel; }
116
117 void incrSwitchNestingLevel() { ++mSwitchNestingLevel; }
118 void decrSwitchNestingLevel() { --mSwitchNestingLevel; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000119
Martin Radev802abe02016-08-04 17:48:32 +0300120 bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; }
Martin Radev4c4c8e72016-08-04 12:25:34 +0300121 sh::WorkGroupSize getComputeShaderLocalSize() const;
Martin Radev802abe02016-08-04 17:48:32 +0300122
Martin Radev70866b82016-07-22 15:27:42 +0300123 void enterFunctionDeclaration() { mDeclaringFunction = true; }
124
125 void exitFunctionDeclaration() { mDeclaringFunction = false; }
126
127 bool declaringFunction() const { return mDeclaringFunction; }
128
Jamie Madill5c097022014-08-20 16:38:32 -0400129 // This method is guaranteed to succeed, even if no variable with 'name' exists.
130 const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol);
Olli Etuaho82c29ed2015-11-03 13:06:54 +0200131 TIntermTyped *parseVariableIdentifier(const TSourceLoc &location,
132 const TString *name,
133 const TSymbol *symbol);
Jamie Madill5c097022014-08-20 16:38:32 -0400134
Jamie Madill06145232015-05-13 13:10:01 -0400135 bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc &line);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000136
Jamie Madill06145232015-05-13 13:10:01 -0400137 void assignError(const TSourceLoc &line, const char *op, TString left, TString right);
138 void unaryOpError(const TSourceLoc &line, const char *op, TString operand);
139 void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right);
Olli Etuaho856c4972016-08-08 11:38:39 +0300140
Olli Etuaho8a176262016-08-16 14:23:01 +0300141 // Check functions - the ones that return bool return false if an error was generated.
142
Olli Etuaho856c4972016-08-08 11:38:39 +0300143 bool checkIsNotReserved(const TSourceLoc &line, const TString &identifier);
144 void checkPrecisionSpecified(const TSourceLoc &line, TPrecision precision, TBasicType type);
145 bool checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node);
146 void checkIsConst(TIntermTyped *node);
147 void checkIsScalarInteger(TIntermTyped *node, const char *token);
Qiankun Miaof69682b2016-08-16 14:50:42 +0800148 bool checkIsAtGlobalLevel(const TSourceLoc &line, const char *token);
Olli Etuaho856c4972016-08-08 11:38:39 +0300149 bool checkConstructorArguments(const TSourceLoc &line,
150 TIntermNode *argumentsNode,
151 const TFunction &function,
152 TOperator op,
153 const TType &type);
154
155 // Returns a sanitized array size to use (the size is at least 1).
156 unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr);
Olli Etuaho8a176262016-08-16 14:23:01 +0300157 bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &elementQualifier);
158 bool checkIsValidTypeForArray(const TSourceLoc &line, const TPublicType &elementType);
Olli Etuaho856c4972016-08-08 11:38:39 +0300159 bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
160 void checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type);
161 void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType);
Martin Radev4a9cd802016-09-01 16:51:51 +0300162 bool checkIsNotSampler(const TSourceLoc &line,
163 const TTypeSpecifierNonArray &pType,
164 const char *reason);
Olli Etuaho856c4972016-08-08 11:38:39 +0300165 void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType);
166 void checkLocationIsNotSpecified(const TSourceLoc &location,
167 const TLayoutQualifier &layoutQualifier);
168 void checkOutParameterIsNotSampler(const TSourceLoc &line,
169 TQualifier qualifier,
170 const TType &type);
171 void checkIsParameterQualifierValid(const TSourceLoc &line,
Martin Radev70866b82016-07-22 15:27:42 +0300172 const TTypeQualifierBuilder &typeQualifierBuilder,
Olli Etuaho856c4972016-08-08 11:38:39 +0300173 TType *type);
174 bool checkCanUseExtension(const TSourceLoc &line, const TString &extension);
Olli Etuaho383b7912016-08-05 11:22:59 +0300175 void singleDeclarationErrorCheck(const TPublicType &publicType,
176 const TSourceLoc &identifierLocation);
Olli Etuaho856c4972016-08-08 11:38:39 +0300177 void checkLayoutQualifierSupported(const TSourceLoc &location,
178 const TString &layoutQualifierName,
179 int versionRequired);
180 bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location,
181 const TLayoutQualifier &layoutQualifier);
182
183 void functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall);
Martin Radev70866b82016-07-22 15:27:42 +0300184 void checkInvariantVariableQualifier(bool invariant,
185 const TQualifier qualifier,
186 const TSourceLoc &invariantLocation);
Olli Etuaho856c4972016-08-08 11:38:39 +0300187 void checkInputOutputTypeIsValidES3(const TQualifier qualifier,
188 const TPublicType &type,
189 const TSourceLoc &qualifierLocation);
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000190
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400191 const TPragma &pragma() const { return mDirectiveHandler.pragma(); }
192 const TExtensionBehavior &extensionBehavior() const { return mDirectiveHandler.extensionBehavior(); }
Jamie Madill06145232015-05-13 13:10:01 -0400193 bool supportsExtension(const char *extension);
194 bool isExtensionEnabled(const char *extension) const;
195 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
196 void handlePragmaDirective(const TSourceLoc &loc, const char *name, const char *value, bool stdgl);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000197
Jamie Madill06145232015-05-13 13:10:01 -0400198 bool containsSampler(const TType &type);
Jamie Madill06145232015-05-13 13:10:01 -0400199 const TFunction* findFunction(
200 const TSourceLoc &line, TFunction *pfnCall, int inputShaderVersion, bool *builtIn = 0);
201 bool executeInitializer(const TSourceLoc &line,
202 const TString &identifier,
203 const TPublicType &pType,
204 TIntermTyped *initializer,
205 TIntermNode **intermNode);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000206
Martin Radev70866b82016-07-22 15:27:42 +0300207 TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400208 const TPublicType &typeSpecifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200209
Olli Etuahofa33d582015-04-09 14:33:12 +0300210 TIntermAggregate *parseSingleDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400211 const TSourceLoc &identifierOrTypeLocation,
212 const TString &identifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200213 TIntermAggregate *parseSingleArrayDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400214 const TSourceLoc &identifierLocation,
215 const TString &identifier,
216 const TSourceLoc &indexLocation,
217 TIntermTyped *indexExpression);
218 TIntermAggregate *parseSingleInitDeclaration(const TPublicType &publicType,
219 const TSourceLoc &identifierLocation,
220 const TString &identifier,
221 const TSourceLoc &initLocation,
222 TIntermTyped *initializer);
Jamie Madill47e3ec02014-08-20 16:38:33 -0400223
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300224 // Parse a declaration like "type a[n] = initializer"
225 // Note that this does not apply to declarations like "type[n] a = initializer"
226 TIntermAggregate *parseSingleArrayInitDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400227 const TSourceLoc &identifierLocation,
228 const TString &identifier,
229 const TSourceLoc &indexLocation,
230 TIntermTyped *indexExpression,
231 const TSourceLoc &initLocation,
232 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300233
Martin Radev70866b82016-07-22 15:27:42 +0300234 TIntermAggregate *parseInvariantDeclaration(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400235 const TSourceLoc &identifierLoc,
236 const TString *identifier,
237 const TSymbol *symbol);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200238
Jamie Madill06145232015-05-13 13:10:01 -0400239 TIntermAggregate *parseDeclarator(TPublicType &publicType,
240 TIntermAggregate *aggregateDeclaration,
241 const TSourceLoc &identifierLocation,
242 const TString &identifier);
243 TIntermAggregate *parseArrayDeclarator(TPublicType &publicType,
244 TIntermAggregate *aggregateDeclaration,
245 const TSourceLoc &identifierLocation,
246 const TString &identifier,
247 const TSourceLoc &arrayLocation,
248 TIntermTyped *indexExpression);
249 TIntermAggregate *parseInitDeclarator(const TPublicType &publicType,
250 TIntermAggregate *aggregateDeclaration,
251 const TSourceLoc &identifierLocation,
252 const TString &identifier,
253 const TSourceLoc &initLocation,
254 TIntermTyped *initializer);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200255
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300256 // Parse a declarator like "a[n] = initializer"
Jamie Madill06145232015-05-13 13:10:01 -0400257 TIntermAggregate *parseArrayInitDeclarator(const TPublicType &publicType,
258 TIntermAggregate *aggregateDeclaration,
259 const TSourceLoc &identifierLocation,
260 const TString &identifier,
261 const TSourceLoc &indexLocation,
262 TIntermTyped *indexExpression,
263 const TSourceLoc &initLocation,
264 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300265
Martin Radev70866b82016-07-22 15:27:42 +0300266 void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder);
Olli Etuahoee63f5d2016-01-04 11:34:54 +0200267 TIntermAggregate *addFunctionPrototypeDeclaration(const TFunction &function,
268 const TSourceLoc &location);
269 TIntermAggregate *addFunctionDefinition(const TFunction &function,
270 TIntermAggregate *functionPrototype,
271 TIntermAggregate *functionBody,
272 const TSourceLoc &location);
Jamie Madill185fb402015-06-12 15:48:48 -0400273 void parseFunctionPrototype(const TSourceLoc &location,
274 TFunction *function,
275 TIntermAggregate **aggregateOut);
276 TFunction *parseFunctionDeclarator(const TSourceLoc &location,
277 TFunction *function);
Olli Etuaho9de84a52016-06-14 17:36:01 +0300278 TFunction *parseFunctionHeader(const TPublicType &type,
279 const TString *name,
280 const TSourceLoc &location);
Jamie Madill06145232015-05-13 13:10:01 -0400281 TFunction *addConstructorFunc(const TPublicType &publicType);
282 TIntermTyped *addConstructor(TIntermNode *arguments,
Jamie Madill06145232015-05-13 13:10:01 -0400283 TOperator op,
284 TFunction *fnCall,
285 const TSourceLoc &line);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300286
Jamie Madill06145232015-05-13 13:10:01 -0400287 TIntermTyped *addIndexExpression(TIntermTyped *baseExpression,
288 const TSourceLoc& location,
289 TIntermTyped *indexExpression);
290 TIntermTyped* addFieldSelectionExpression(TIntermTyped *baseExpression,
291 const TSourceLoc &dotLocation,
292 const TString &fieldString,
293 const TSourceLoc &fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +0000294
Martin Radev70866b82016-07-22 15:27:42 +0300295 TFieldList *addStructDeclaratorListWithQualifiers(
296 const TTypeQualifierBuilder &typeQualifierBuilder,
297 TPublicType *typeSpecifier,
298 TFieldList *fieldList);
Jamie Madill06145232015-05-13 13:10:01 -0400299 TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList);
Martin Radev4a9cd802016-09-01 16:51:51 +0300300 TTypeSpecifierNonArray addStructure(const TSourceLoc &structLine,
301 const TSourceLoc &nameLine,
302 const TString *structName,
303 TFieldList *fieldList);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000304
Martin Radev70866b82016-07-22 15:27:42 +0300305 TIntermAggregate *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400306 const TSourceLoc &nameLine,
307 const TString &blockName,
308 TFieldList *fieldList,
309 const TString *instanceName,
310 const TSourceLoc &instanceLine,
311 TIntermTyped *arrayIndex,
Martin Radev70866b82016-07-22 15:27:42 +0300312 const TSourceLoc &arrayIndexLine);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000313
Martin Radev802abe02016-08-04 17:48:32 +0300314 void parseLocalSize(const TString &qualifierType,
315 const TSourceLoc &qualifierTypeLine,
316 int intValue,
317 const TSourceLoc &intValueLine,
318 const std::string &intValueString,
319 size_t index,
Martin Radev4c4c8e72016-08-04 12:25:34 +0300320 sh::WorkGroupSize *localSize);
Jamie Madill06145232015-05-13 13:10:01 -0400321 TLayoutQualifier parseLayoutQualifier(
322 const TString &qualifierType, const TSourceLoc &qualifierTypeLine);
323 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
324 const TSourceLoc &qualifierTypeLine,
Jamie Madill06145232015-05-13 13:10:01 -0400325 int intValue,
326 const TSourceLoc &intValueLine);
Olli Etuaho613b9592016-09-05 12:05:53 +0300327 TTypeQualifierBuilder *createTypeQualifierBuilder(const TSourceLoc &loc);
Martin Radev802abe02016-08-04 17:48:32 +0300328 TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier,
329 TLayoutQualifier rightQualifier,
330 const TSourceLoc &rightQualifierLocation);
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000331
kbr@chromium.org476541f2011-10-27 21:14:51 +0000332 // Performs an error check for embedded struct declarations.
Olli Etuaho383b7912016-08-05 11:22:59 +0300333 void enterStructDeclaration(const TSourceLoc &line, const TString &identifier);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000334 void exitStructDeclaration();
335
Olli Etuaho8a176262016-08-16 14:23:01 +0300336 void checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field);
Olli Etuaho09b22472015-02-11 11:47:26 +0200337
Olli Etuahoa3a36662015-02-17 13:46:51 +0200338 TIntermSwitch *addSwitch(TIntermTyped *init, TIntermAggregate *statementList, const TSourceLoc &loc);
339 TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc);
340 TIntermCase *addDefault(const TSourceLoc &loc);
341
Jamie Madill06145232015-05-13 13:10:01 -0400342 TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
343 TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
344 TIntermTyped *addBinaryMath(
345 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
346 TIntermTyped *addBinaryMathBooleanResult(
347 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
348 TIntermTyped *addAssign(
349 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuaho49300862015-02-20 14:54:49 +0200350
Olli Etuaho0b2d2dc2015-11-04 16:35:32 +0200351 TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
352
Olli Etuaho49300862015-02-20 14:54:49 +0200353 TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc);
354 TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +0200355
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200356 void checkTextureOffsetConst(TIntermAggregate *functionCall);
Jamie Madill06145232015-05-13 13:10:01 -0400357 TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall,
358 TIntermNode *paramNode,
359 TIntermNode *thisNode,
360 const TSourceLoc &loc,
361 bool *fatalError);
Olli Etuahofc1806e2015-03-17 13:03:11 +0200362
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300363 TIntermTyped *addTernarySelection(TIntermTyped *cond,
364 TIntermTyped *trueExpression,
365 TIntermTyped *falseExpression,
366 const TSourceLoc &line);
Olli Etuaho52901742015-04-15 13:42:45 +0300367
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400368 // TODO(jmadill): make these private
Olli Etuahof119a262016-08-19 15:54:22 +0300369 TIntermediate intermediate; // to build a parse tree
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400370 TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed
371
Olli Etuahofc1806e2015-03-17 13:03:11 +0200372 private:
Olli Etuaho90892fb2016-07-14 14:44:51 +0300373 // Returns a clamped index.
374 int checkIndexOutOfRange(bool outOfRangeIndexIsError,
375 const TSourceLoc &location,
376 int index,
377 int arraySize,
378 const char *reason,
379 const char *token);
380
Olli Etuaho2935c582015-04-08 14:32:06 +0300381 bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable);
382
Olli Etuaho856c4972016-08-08 11:38:39 +0300383 void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line,
384 const TString &identifier,
385 TPublicType *type);
Olli Etuaho376f1b52015-04-13 13:23:41 +0300386
Olli Etuaho8a176262016-08-16 14:23:01 +0300387 bool checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation,
388 const TPublicType &elementType);
389
Olli Etuaho1dded802016-08-18 18:13:13 +0300390 // Assumes that multiplication op has already been set based on the types.
391 bool isMultiplicationTypeCombinationValid(TOperator op, const TType &left, const TType &right);
392
Jamie Madill06145232015-05-13 13:10:01 -0400393 TIntermTyped *addBinaryMathInternal(
394 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
395 TIntermTyped *createAssign(
396 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuahof6c694b2015-03-26 14:50:53 +0200397 // The funcReturnType parameter is expected to be non-null when the operation is a built-in function.
398 // It is expected to be null for other unary operators.
Jamie Madill06145232015-05-13 13:10:01 -0400399 TIntermTyped *createUnaryMath(
400 TOperator op, TIntermTyped *child, const TSourceLoc &loc, const TType *funcReturnType);
Olli Etuahod6b14282015-03-17 14:31:35 +0200401
Olli Etuaho47fd36a2015-03-19 14:22:24 +0200402 // Return true if the checks pass
Jamie Madill06145232015-05-13 13:10:01 -0400403 bool binaryOpCommonCheck(
404 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuahofa33d582015-04-09 14:33:12 +0300405
406 // Set to true when the last/current declarator list was started with an empty declaration.
407 bool mDeferredSingleDeclarationErrorCheck;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400408
409 sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800410 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
411 ShCompileOptions mCompileOptions; // Options passed to TCompiler
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400412 int mShaderVersion;
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800413 TIntermNode *mTreeRoot; // root of parse tree being created
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400414 int mLoopNestingLevel; // 0 if outside all loops
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800415 int mStructNestingLevel; // incremented while parsing a struct declaration
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400416 int mSwitchNestingLevel; // 0 if outside all switch statements
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800417 const TType
418 *mCurrentFunctionType; // the return type of the function that's currently being parsed
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400419 bool mFunctionReturnsValue; // true if a non-void function has a return
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800420 bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared
421 // without precision, explicit or implicit.
Olli Etuahoa6996682015-10-12 14:32:30 +0300422 bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling
423 // ESSL1.
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400424 TLayoutMatrixPacking mDefaultMatrixPacking;
425 TLayoutBlockStorage mDefaultBlockStorage;
426 TString mHashErrMsg;
427 TDiagnostics mDiagnostics;
428 TDirectiveHandler mDirectiveHandler;
429 pp::Preprocessor mPreprocessor;
430 void *mScanner;
Jamie Madill14e95b32015-05-07 10:10:41 -0400431 bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
432 bool mUsesFragColor;
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +0300433 bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or
434 // gl_Secondary FragColor or both.
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200435 int mMinProgramTexelOffset;
436 int mMaxProgramTexelOffset;
Martin Radev802abe02016-08-04 17:48:32 +0300437
438 // keep track of local group size declared in layout. It should be declared only once.
439 bool mComputeShaderLocalSizeDeclared;
Martin Radev4c4c8e72016-08-04 12:25:34 +0300440 sh::WorkGroupSize mComputeShaderLocalSize;
Martin Radev70866b82016-07-22 15:27:42 +0300441 // keeps track whether we are declaring / defining a function
442 bool mDeclaringFunction;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000443};
444
Jamie Madill06145232015-05-13 13:10:01 -0400445int PaParseStrings(
446 size_t count, const char *const string[], const int length[], TParseContext *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000447
Geoff Lang0a73dd82014-11-19 16:18:08 -0500448#endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_