blob: 27b53bbb80ae03dc3a8409371a3f1ef185311a21 [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,
Jamie Madillacb4b812016-11-07 13:50:29 -050039 const ShBuiltInResources &resources);
Jamie Madill06145232015-05-13 13:10:01 -040040
Jamie Madill6e06b1f2015-05-14 10:01:17 -040041 const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
42 pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
43 void *getScanner() const { return mScanner; }
44 void setScanner(void *scanner) { mScanner = scanner; }
45 int getShaderVersion() const { return mShaderVersion; }
46 sh::GLenum getShaderType() const { return mShaderType; }
47 ShShaderSpec getShaderSpec() const { return mShaderSpec; }
48 int numErrors() const { return mDiagnostics.numErrors(); }
49 TInfoSink &infoSink() { return mDiagnostics.infoSink(); }
Jamie Madill06145232015-05-13 13:10:01 -040050 void error(const TSourceLoc &loc, const char *reason, const char *token,
51 const char *extraInfo="");
52 void warning(const TSourceLoc &loc, const char *reason, const char *token,
53 const char *extraInfo="");
Jamie Madill14e95b32015-05-07 10:10:41 -040054
Olli Etuaho7c3848e2015-11-04 13:19:17 +020055 // If isError is false, a warning will be reported instead.
56 void outOfRangeError(bool isError,
57 const TSourceLoc &loc,
58 const char *reason,
59 const char *token,
60 const char *extraInfo = "");
61
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010062 TIntermBlock *getTreeRoot() const { return mTreeRoot; }
63 void setTreeRoot(TIntermBlock *treeRoot) { mTreeRoot = treeRoot; }
Jamie Madill6e06b1f2015-05-14 10:01:17 -040064
Olli Etuahoa6996682015-10-12 14:32:30 +030065 bool getFragmentPrecisionHigh() const
Jamie Madill6e06b1f2015-05-14 10:01:17 -040066 {
Olli Etuahoa6996682015-10-12 14:32:30 +030067 return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300;
68 }
69 void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh)
70 {
71 mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh;
Jamie Madill6e06b1f2015-05-14 10:01:17 -040072 }
73
Jamie Madill6e06b1f2015-05-14 10:01:17 -040074 void setLoopNestingLevel(int loopNestintLevel)
75 {
76 mLoopNestingLevel = loopNestintLevel;
77 }
78
Jamie Madill6e06b1f2015-05-14 10:01:17 -040079 void incrLoopNestingLevel() { ++mLoopNestingLevel; }
80 void decrLoopNestingLevel() { --mLoopNestingLevel; }
81
82 void incrSwitchNestingLevel() { ++mSwitchNestingLevel; }
83 void decrSwitchNestingLevel() { --mSwitchNestingLevel; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000084
Martin Radev802abe02016-08-04 17:48:32 +030085 bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; }
Martin Radev4c4c8e72016-08-04 12:25:34 +030086 sh::WorkGroupSize getComputeShaderLocalSize() const;
Martin Radev802abe02016-08-04 17:48:32 +030087
Martin Radev70866b82016-07-22 15:27:42 +030088 void enterFunctionDeclaration() { mDeclaringFunction = true; }
89
90 void exitFunctionDeclaration() { mDeclaringFunction = false; }
91
92 bool declaringFunction() const { return mDeclaringFunction; }
93
Jamie Madill5c097022014-08-20 16:38:32 -040094 // This method is guaranteed to succeed, even if no variable with 'name' exists.
95 const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol);
Olli Etuaho82c29ed2015-11-03 13:06:54 +020096 TIntermTyped *parseVariableIdentifier(const TSourceLoc &location,
97 const TString *name,
98 const TSymbol *symbol);
Jamie Madill5c097022014-08-20 16:38:32 -040099
Jamie Madill06145232015-05-13 13:10:01 -0400100 bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc &line);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000101
Jamie Madill06145232015-05-13 13:10:01 -0400102 void assignError(const TSourceLoc &line, const char *op, TString left, TString right);
103 void unaryOpError(const TSourceLoc &line, const char *op, TString operand);
104 void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right);
Olli Etuaho856c4972016-08-08 11:38:39 +0300105
Olli Etuaho8a176262016-08-16 14:23:01 +0300106 // Check functions - the ones that return bool return false if an error was generated.
107
Olli Etuaho856c4972016-08-08 11:38:39 +0300108 bool checkIsNotReserved(const TSourceLoc &line, const TString &identifier);
109 void checkPrecisionSpecified(const TSourceLoc &line, TPrecision precision, TBasicType type);
110 bool checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node);
111 void checkIsConst(TIntermTyped *node);
112 void checkIsScalarInteger(TIntermTyped *node, const char *token);
Qiankun Miaof69682b2016-08-16 14:50:42 +0800113 bool checkIsAtGlobalLevel(const TSourceLoc &line, const char *token);
Olli Etuaho856c4972016-08-08 11:38:39 +0300114 bool checkConstructorArguments(const TSourceLoc &line,
115 TIntermNode *argumentsNode,
116 const TFunction &function,
117 TOperator op,
118 const TType &type);
119
120 // Returns a sanitized array size to use (the size is at least 1).
121 unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr);
Olli Etuaho8a176262016-08-16 14:23:01 +0300122 bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &elementQualifier);
123 bool checkIsValidTypeForArray(const TSourceLoc &line, const TPublicType &elementType);
Olli Etuaho856c4972016-08-08 11:38:39 +0300124 bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
125 void checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type);
126 void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType);
Martin Radev4a9cd802016-09-01 16:51:51 +0300127 bool checkIsNotSampler(const TSourceLoc &line,
128 const TTypeSpecifierNonArray &pType,
129 const char *reason);
Martin Radev2cc85b32016-08-05 16:22:53 +0300130 bool checkIsNotImage(const TSourceLoc &line,
131 const TTypeSpecifierNonArray &pType,
132 const char *reason);
Olli Etuaho856c4972016-08-08 11:38:39 +0300133 void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType);
134 void checkLocationIsNotSpecified(const TSourceLoc &location,
135 const TLayoutQualifier &layoutQualifier);
Olli Etuaho856c4972016-08-08 11:38:39 +0300136 void checkIsParameterQualifierValid(const TSourceLoc &line,
Martin Radev70866b82016-07-22 15:27:42 +0300137 const TTypeQualifierBuilder &typeQualifierBuilder,
Olli Etuaho856c4972016-08-08 11:38:39 +0300138 TType *type);
139 bool checkCanUseExtension(const TSourceLoc &line, const TString &extension);
Olli Etuaho383b7912016-08-05 11:22:59 +0300140 void singleDeclarationErrorCheck(const TPublicType &publicType,
141 const TSourceLoc &identifierLocation);
Olli Etuaho856c4972016-08-08 11:38:39 +0300142 void checkLayoutQualifierSupported(const TSourceLoc &location,
143 const TString &layoutQualifierName,
144 int versionRequired);
145 bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location,
146 const TLayoutQualifier &layoutQualifier);
Martin Radev2cc85b32016-08-05 16:22:53 +0300147 bool checkInternalFormatIsNotSpecified(const TSourceLoc &location,
148 TLayoutImageInternalFormat internalFormat);
Olli Etuaho856c4972016-08-08 11:38:39 +0300149 void functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall);
Martin Radev70866b82016-07-22 15:27:42 +0300150 void checkInvariantVariableQualifier(bool invariant,
151 const TQualifier qualifier,
152 const TSourceLoc &invariantLocation);
Olli Etuaho856c4972016-08-08 11:38:39 +0300153 void checkInputOutputTypeIsValidES3(const TQualifier qualifier,
154 const TPublicType &type,
155 const TSourceLoc &qualifierLocation);
Martin Radev2cc85b32016-08-05 16:22:53 +0300156 void checkLocalVariableConstStorageQualifier(const TQualifierWrapperBase &qualifier);
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400157 const TPragma &pragma() const { return mDirectiveHandler.pragma(); }
158 const TExtensionBehavior &extensionBehavior() const { return mDirectiveHandler.extensionBehavior(); }
Jamie Madill06145232015-05-13 13:10:01 -0400159 bool supportsExtension(const char *extension);
160 bool isExtensionEnabled(const char *extension) const;
161 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
162 void handlePragmaDirective(const TSourceLoc &loc, const char *name, const char *value, bool stdgl);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000163
Jamie Madill06145232015-05-13 13:10:01 -0400164 const TFunction* findFunction(
165 const TSourceLoc &line, TFunction *pfnCall, int inputShaderVersion, bool *builtIn = 0);
166 bool executeInitializer(const TSourceLoc &line,
167 const TString &identifier,
168 const TPublicType &pType,
169 TIntermTyped *initializer,
Olli Etuaho13389b62016-10-16 11:48:18 +0100170 TIntermBinary **initNode);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000171
Olli Etuaho0e3aee32016-10-27 12:56:38 +0100172 void addFullySpecifiedType(TPublicType *typeSpecifier);
Martin Radev70866b82016-07-22 15:27:42 +0300173 TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400174 const TPublicType &typeSpecifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200175
Olli Etuaho13389b62016-10-16 11:48:18 +0100176 TIntermDeclaration *parseSingleDeclaration(TPublicType &publicType,
177 const TSourceLoc &identifierOrTypeLocation,
178 const TString &identifier);
179 TIntermDeclaration *parseSingleArrayDeclaration(TPublicType &publicType,
180 const TSourceLoc &identifierLocation,
181 const TString &identifier,
182 const TSourceLoc &indexLocation,
183 TIntermTyped *indexExpression);
184 TIntermDeclaration *parseSingleInitDeclaration(const TPublicType &publicType,
185 const TSourceLoc &identifierLocation,
186 const TString &identifier,
187 const TSourceLoc &initLocation,
188 TIntermTyped *initializer);
Jamie Madill47e3ec02014-08-20 16:38:33 -0400189
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300190 // Parse a declaration like "type a[n] = initializer"
191 // Note that this does not apply to declarations like "type[n] a = initializer"
Olli Etuaho13389b62016-10-16 11:48:18 +0100192 TIntermDeclaration *parseSingleArrayInitDeclaration(TPublicType &publicType,
193 const TSourceLoc &identifierLocation,
194 const TString &identifier,
195 const TSourceLoc &indexLocation,
196 TIntermTyped *indexExpression,
197 const TSourceLoc &initLocation,
198 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300199
Martin Radev70866b82016-07-22 15:27:42 +0300200 TIntermAggregate *parseInvariantDeclaration(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400201 const TSourceLoc &identifierLoc,
202 const TString *identifier,
203 const TSymbol *symbol);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200204
Olli Etuaho13389b62016-10-16 11:48:18 +0100205 void parseDeclarator(TPublicType &publicType,
206 const TSourceLoc &identifierLocation,
207 const TString &identifier,
208 TIntermDeclaration *declarationOut);
209 void parseArrayDeclarator(TPublicType &publicType,
210 const TSourceLoc &identifierLocation,
211 const TString &identifier,
212 const TSourceLoc &arrayLocation,
213 TIntermTyped *indexExpression,
214 TIntermDeclaration *declarationOut);
215 void parseInitDeclarator(const TPublicType &publicType,
216 const TSourceLoc &identifierLocation,
217 const TString &identifier,
218 const TSourceLoc &initLocation,
219 TIntermTyped *initializer,
220 TIntermDeclaration *declarationOut);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200221
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300222 // Parse a declarator like "a[n] = initializer"
Olli Etuaho13389b62016-10-16 11:48:18 +0100223 void parseArrayInitDeclarator(const TPublicType &publicType,
224 const TSourceLoc &identifierLocation,
225 const TString &identifier,
226 const TSourceLoc &indexLocation,
227 TIntermTyped *indexExpression,
228 const TSourceLoc &initLocation,
229 TIntermTyped *initializer,
230 TIntermDeclaration *declarationOut);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300231
Martin Radev70866b82016-07-22 15:27:42 +0300232 void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder);
Olli Etuaho476197f2016-10-11 13:59:08 +0100233 TIntermAggregate *addFunctionPrototypeDeclaration(const TFunction &parsedFunction,
Olli Etuahoee63f5d2016-01-04 11:34:54 +0200234 const TSourceLoc &location);
Olli Etuaho336b1472016-10-05 16:37:55 +0100235 TIntermFunctionDefinition *addFunctionDefinition(const TFunction &function,
236 TIntermAggregate *functionParameters,
237 TIntermBlock *functionBody,
238 const TSourceLoc &location);
Olli Etuaho476197f2016-10-11 13:59:08 +0100239 void parseFunctionDefinitionHeader(const TSourceLoc &location,
240 TFunction **function,
241 TIntermAggregate **aggregateOut);
Jamie Madill185fb402015-06-12 15:48:48 -0400242 TFunction *parseFunctionDeclarator(const TSourceLoc &location,
243 TFunction *function);
Olli Etuaho9de84a52016-06-14 17:36:01 +0300244 TFunction *parseFunctionHeader(const TPublicType &type,
245 const TString *name,
246 const TSourceLoc &location);
Jamie Madill06145232015-05-13 13:10:01 -0400247 TFunction *addConstructorFunc(const TPublicType &publicType);
248 TIntermTyped *addConstructor(TIntermNode *arguments,
Jamie Madill06145232015-05-13 13:10:01 -0400249 TOperator op,
250 TFunction *fnCall,
251 const TSourceLoc &line);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300252
Jamie Madill06145232015-05-13 13:10:01 -0400253 TIntermTyped *addIndexExpression(TIntermTyped *baseExpression,
254 const TSourceLoc& location,
255 TIntermTyped *indexExpression);
256 TIntermTyped* addFieldSelectionExpression(TIntermTyped *baseExpression,
257 const TSourceLoc &dotLocation,
258 const TString &fieldString,
259 const TSourceLoc &fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +0000260
Martin Radev70866b82016-07-22 15:27:42 +0300261 TFieldList *addStructDeclaratorListWithQualifiers(
262 const TTypeQualifierBuilder &typeQualifierBuilder,
263 TPublicType *typeSpecifier,
264 TFieldList *fieldList);
Jamie Madill06145232015-05-13 13:10:01 -0400265 TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList);
Martin Radev4a9cd802016-09-01 16:51:51 +0300266 TTypeSpecifierNonArray addStructure(const TSourceLoc &structLine,
267 const TSourceLoc &nameLine,
268 const TString *structName,
269 TFieldList *fieldList);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000270
Olli Etuaho13389b62016-10-16 11:48:18 +0100271 TIntermDeclaration *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder,
272 const TSourceLoc &nameLine,
273 const TString &blockName,
274 TFieldList *fieldList,
275 const TString *instanceName,
276 const TSourceLoc &instanceLine,
277 TIntermTyped *arrayIndex,
278 const TSourceLoc &arrayIndexLine);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000279
Martin Radev802abe02016-08-04 17:48:32 +0300280 void parseLocalSize(const TString &qualifierType,
281 const TSourceLoc &qualifierTypeLine,
282 int intValue,
283 const TSourceLoc &intValueLine,
284 const std::string &intValueString,
285 size_t index,
Martin Radev4c4c8e72016-08-04 12:25:34 +0300286 sh::WorkGroupSize *localSize);
Jamie Madill06145232015-05-13 13:10:01 -0400287 TLayoutQualifier parseLayoutQualifier(
288 const TString &qualifierType, const TSourceLoc &qualifierTypeLine);
289 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
290 const TSourceLoc &qualifierTypeLine,
Jamie Madill06145232015-05-13 13:10:01 -0400291 int intValue,
292 const TSourceLoc &intValueLine);
Olli Etuaho613b9592016-09-05 12:05:53 +0300293 TTypeQualifierBuilder *createTypeQualifierBuilder(const TSourceLoc &loc);
Martin Radev802abe02016-08-04 17:48:32 +0300294 TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier,
295 TLayoutQualifier rightQualifier,
296 const TSourceLoc &rightQualifierLocation);
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000297
kbr@chromium.org476541f2011-10-27 21:14:51 +0000298 // Performs an error check for embedded struct declarations.
Olli Etuaho383b7912016-08-05 11:22:59 +0300299 void enterStructDeclaration(const TSourceLoc &line, const TString &identifier);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000300 void exitStructDeclaration();
301
Olli Etuaho8a176262016-08-16 14:23:01 +0300302 void checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field);
Olli Etuaho09b22472015-02-11 11:47:26 +0200303
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100304 TIntermSwitch *addSwitch(TIntermTyped *init,
305 TIntermBlock *statementList,
306 const TSourceLoc &loc);
Olli Etuahoa3a36662015-02-17 13:46:51 +0200307 TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc);
308 TIntermCase *addDefault(const TSourceLoc &loc);
309
Jamie Madill06145232015-05-13 13:10:01 -0400310 TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
311 TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
312 TIntermTyped *addBinaryMath(
313 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
314 TIntermTyped *addBinaryMathBooleanResult(
315 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
316 TIntermTyped *addAssign(
317 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuaho49300862015-02-20 14:54:49 +0200318
Olli Etuaho0b2d2dc2015-11-04 16:35:32 +0200319 TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
320
Olli Etuaho49300862015-02-20 14:54:49 +0200321 TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc);
322 TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +0200323
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200324 void checkTextureOffsetConst(TIntermAggregate *functionCall);
Martin Radev2cc85b32016-08-05 16:22:53 +0300325 void checkImageMemoryAccessForBuiltinFunctions(TIntermAggregate *functionCall);
326 void checkImageMemoryAccessForUserDefinedFunctions(const TFunction *functionDefinition,
327 const TIntermAggregate *functionCall);
Jamie Madill06145232015-05-13 13:10:01 -0400328 TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall,
329 TIntermNode *paramNode,
330 TIntermNode *thisNode,
331 const TSourceLoc &loc,
332 bool *fatalError);
Olli Etuahofc1806e2015-03-17 13:03:11 +0200333
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300334 TIntermTyped *addTernarySelection(TIntermTyped *cond,
335 TIntermTyped *trueExpression,
336 TIntermTyped *falseExpression,
337 const TSourceLoc &line);
Olli Etuaho52901742015-04-15 13:42:45 +0300338
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400339 // TODO(jmadill): make these private
Olli Etuahof119a262016-08-19 15:54:22 +0300340 TIntermediate intermediate; // to build a parse tree
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400341 TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed
342
Olli Etuahofc1806e2015-03-17 13:03:11 +0200343 private:
Olli Etuaho90892fb2016-07-14 14:44:51 +0300344 // Returns a clamped index.
345 int checkIndexOutOfRange(bool outOfRangeIndexIsError,
346 const TSourceLoc &location,
347 int index,
348 int arraySize,
349 const char *reason,
350 const char *token);
351
Olli Etuaho2935c582015-04-08 14:32:06 +0300352 bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable);
353
Olli Etuaho856c4972016-08-08 11:38:39 +0300354 void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line,
355 const TString &identifier,
356 TPublicType *type);
Olli Etuaho376f1b52015-04-13 13:23:41 +0300357
Olli Etuaho8a176262016-08-16 14:23:01 +0300358 bool checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation,
359 const TPublicType &elementType);
360
Olli Etuaho1dded802016-08-18 18:13:13 +0300361 // Assumes that multiplication op has already been set based on the types.
362 bool isMultiplicationTypeCombinationValid(TOperator op, const TType &left, const TType &right);
363
Martin Radev2cc85b32016-08-05 16:22:53 +0300364 bool checkIsMemoryQualifierNotSpecified(const TMemoryQualifier &memoryQualifier,
365 const TSourceLoc &location);
366 void checkOutParameterIsNotImage(const TSourceLoc &line,
367 TQualifier qualifier,
368 const TType &type);
369 void checkOutParameterIsNotOpaqueType(const TSourceLoc &line,
370 TQualifier qualifier,
371 const TType &type);
372 void checkOutParameterIsNotSampler(const TSourceLoc &line,
373 TQualifier qualifier,
374 const TType &type);
375
Jamie Madill06145232015-05-13 13:10:01 -0400376 TIntermTyped *addBinaryMathInternal(
377 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuaho13389b62016-10-16 11:48:18 +0100378 TIntermBinary *createAssign(TOperator op,
379 TIntermTyped *left,
380 TIntermTyped *right,
381 const TSourceLoc &loc);
Olli Etuahof6c694b2015-03-26 14:50:53 +0200382 // The funcReturnType parameter is expected to be non-null when the operation is a built-in function.
383 // It is expected to be null for other unary operators.
Jamie Madill06145232015-05-13 13:10:01 -0400384 TIntermTyped *createUnaryMath(
385 TOperator op, TIntermTyped *child, const TSourceLoc &loc, const TType *funcReturnType);
Olli Etuahod6b14282015-03-17 14:31:35 +0200386
Olli Etuaho47fd36a2015-03-19 14:22:24 +0200387 // Return true if the checks pass
Jamie Madill06145232015-05-13 13:10:01 -0400388 bool binaryOpCommonCheck(
389 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuahofa33d582015-04-09 14:33:12 +0300390
391 // Set to true when the last/current declarator list was started with an empty declaration.
392 bool mDeferredSingleDeclarationErrorCheck;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400393
394 sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800395 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
396 ShCompileOptions mCompileOptions; // Options passed to TCompiler
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400397 int mShaderVersion;
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100398 TIntermBlock *mTreeRoot; // root of parse tree being created
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400399 int mLoopNestingLevel; // 0 if outside all loops
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800400 int mStructNestingLevel; // incremented while parsing a struct declaration
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400401 int mSwitchNestingLevel; // 0 if outside all switch statements
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800402 const TType
403 *mCurrentFunctionType; // the return type of the function that's currently being parsed
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400404 bool mFunctionReturnsValue; // true if a non-void function has a return
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800405 bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared
406 // without precision, explicit or implicit.
Olli Etuahoa6996682015-10-12 14:32:30 +0300407 bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling
408 // ESSL1.
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400409 TLayoutMatrixPacking mDefaultMatrixPacking;
410 TLayoutBlockStorage mDefaultBlockStorage;
411 TString mHashErrMsg;
412 TDiagnostics mDiagnostics;
413 TDirectiveHandler mDirectiveHandler;
414 pp::Preprocessor mPreprocessor;
415 void *mScanner;
Jamie Madill14e95b32015-05-07 10:10:41 -0400416 bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
417 bool mUsesFragColor;
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +0300418 bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or
419 // gl_Secondary FragColor or both.
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200420 int mMinProgramTexelOffset;
421 int mMaxProgramTexelOffset;
Martin Radev802abe02016-08-04 17:48:32 +0300422
423 // keep track of local group size declared in layout. It should be declared only once.
424 bool mComputeShaderLocalSizeDeclared;
Martin Radev4c4c8e72016-08-04 12:25:34 +0300425 sh::WorkGroupSize mComputeShaderLocalSize;
Martin Radev70866b82016-07-22 15:27:42 +0300426 // keeps track whether we are declaring / defining a function
427 bool mDeclaringFunction;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000428};
429
Jamie Madill06145232015-05-13 13:10:01 -0400430int PaParseStrings(
431 size_t count, const char *const string[], const int length[], TParseContext *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000432
Geoff Lang0a73dd82014-11-19 16:18:08 -0500433#endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_