blob: 250ff2d2dc9dc50ccbfdacda9df4112a15d01a27 [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 Madill45bcc782016-11-07 13:58:48 -050017namespace sh
18{
19
Jamie Madill06145232015-05-13 13:10:01 -040020struct TMatrixFields
21{
daniel@transgaming.com0578f812010-05-17 09:58:39 +000022 bool wholeRow;
23 bool wholeCol;
24 int row;
25 int col;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000026};
27
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000028//
29// The following are extra variables needed during parsing, grouped together so
30// they can be passed to the parser without needing a global.
31//
Jamie Madill6e06b1f2015-05-14 10:01:17 -040032class TParseContext : angle::NonCopyable
Jamie Madill06145232015-05-13 13:10:01 -040033{
Jamie Madill6e06b1f2015-05-14 10:01:17 -040034 public:
Jamie Madill06145232015-05-13 13:10:01 -040035 TParseContext(TSymbolTable &symt,
36 TExtensionBehavior &ext,
Jamie Madill06145232015-05-13 13:10:01 -040037 sh::GLenum type,
38 ShShaderSpec spec,
Qiankun Miao7ebb97f2016-09-08 18:01:50 +080039 ShCompileOptions options,
Jamie Madill06145232015-05-13 13:10:01 -040040 bool checksPrecErrors,
41 TInfoSink &is,
Jamie Madillacb4b812016-11-07 13:50:29 -050042 const ShBuiltInResources &resources);
Jamie Madill06145232015-05-13 13:10:01 -040043
Jamie Madill6e06b1f2015-05-14 10:01:17 -040044 const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
45 pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
46 void *getScanner() const { return mScanner; }
47 void setScanner(void *scanner) { mScanner = scanner; }
48 int getShaderVersion() const { return mShaderVersion; }
49 sh::GLenum getShaderType() const { return mShaderType; }
50 ShShaderSpec getShaderSpec() const { return mShaderSpec; }
51 int numErrors() const { return mDiagnostics.numErrors(); }
52 TInfoSink &infoSink() { return mDiagnostics.infoSink(); }
Olli Etuaho4de340a2016-12-16 09:32:03 +000053 void error(const TSourceLoc &loc, const char *reason, const char *token);
54 void warning(const TSourceLoc &loc, const char *reason, const char *token);
Jamie Madill14e95b32015-05-07 10:10:41 -040055
Olli Etuaho7c3848e2015-11-04 13:19:17 +020056 // If isError is false, a warning will be reported instead.
57 void outOfRangeError(bool isError,
58 const TSourceLoc &loc,
59 const char *reason,
Olli Etuaho4de340a2016-12-16 09:32:03 +000060 const char *token);
Olli Etuaho7c3848e2015-11-04 13:19:17 +020061
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 Madilld7b1ab52016-12-12 14:42:19 -050074 void setLoopNestingLevel(int loopNestintLevel) { mLoopNestingLevel = loopNestintLevel; }
Jamie Madill6e06b1f2015-05-14 10:01:17 -040075
Jamie Madill6e06b1f2015-05-14 10:01:17 -040076 void incrLoopNestingLevel() { ++mLoopNestingLevel; }
77 void decrLoopNestingLevel() { --mLoopNestingLevel; }
78
79 void incrSwitchNestingLevel() { ++mSwitchNestingLevel; }
80 void decrSwitchNestingLevel() { --mSwitchNestingLevel; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000081
Martin Radev802abe02016-08-04 17:48:32 +030082 bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; }
Martin Radev4c4c8e72016-08-04 12:25:34 +030083 sh::WorkGroupSize getComputeShaderLocalSize() const;
Martin Radev802abe02016-08-04 17:48:32 +030084
Martin Radev70866b82016-07-22 15:27:42 +030085 void enterFunctionDeclaration() { mDeclaringFunction = true; }
86
87 void exitFunctionDeclaration() { mDeclaringFunction = false; }
88
89 bool declaringFunction() const { return mDeclaringFunction; }
90
Jamie Madill5c097022014-08-20 16:38:32 -040091 // This method is guaranteed to succeed, even if no variable with 'name' exists.
Jamie Madilld7b1ab52016-12-12 14:42:19 -050092 const TVariable *getNamedVariable(const TSourceLoc &location,
93 const TString *name,
94 const TSymbol *symbol);
Olli Etuaho82c29ed2015-11-03 13:06:54 +020095 TIntermTyped *parseVariableIdentifier(const TSourceLoc &location,
96 const TString *name,
97 const TSymbol *symbol);
Jamie Madill5c097022014-08-20 16:38:32 -040098
Jamie Madilld7b1ab52016-12-12 14:42:19 -050099 bool parseVectorFields(const TString &, int vecSize, TVectorFields &, const TSourceLoc &line);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000100
Jamie Madill06145232015-05-13 13:10:01 -0400101 void assignError(const TSourceLoc &line, const char *op, TString left, TString right);
102 void unaryOpError(const TSourceLoc &line, const char *op, TString operand);
103 void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right);
Olli Etuaho856c4972016-08-08 11:38:39 +0300104
Olli Etuaho8a176262016-08-16 14:23:01 +0300105 // Check functions - the ones that return bool return false if an error was generated.
106
Olli Etuaho856c4972016-08-08 11:38:39 +0300107 bool checkIsNotReserved(const TSourceLoc &line, const TString &identifier);
108 void checkPrecisionSpecified(const TSourceLoc &line, TPrecision precision, TBasicType type);
109 bool checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node);
110 void checkIsConst(TIntermTyped *node);
111 void checkIsScalarInteger(TIntermTyped *node, const char *token);
Qiankun Miaof69682b2016-08-16 14:50:42 +0800112 bool checkIsAtGlobalLevel(const TSourceLoc &line, const char *token);
Olli Etuaho856c4972016-08-08 11:38:39 +0300113 bool checkConstructorArguments(const TSourceLoc &line,
114 TIntermNode *argumentsNode,
115 const TFunction &function,
116 TOperator op,
117 const TType &type);
118
119 // Returns a sanitized array size to use (the size is at least 1).
120 unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr);
Olli Etuaho8a176262016-08-16 14:23:01 +0300121 bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &elementQualifier);
122 bool checkIsValidTypeForArray(const TSourceLoc &line, const TPublicType &elementType);
Olli Etuaho856c4972016-08-08 11:38:39 +0300123 bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
124 void checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type);
125 void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType);
Martin Radev4a9cd802016-09-01 16:51:51 +0300126 bool checkIsNotSampler(const TSourceLoc &line,
127 const TTypeSpecifierNonArray &pType,
128 const char *reason);
Martin Radev2cc85b32016-08-05 16:22:53 +0300129 bool checkIsNotImage(const TSourceLoc &line,
130 const TTypeSpecifierNonArray &pType,
131 const char *reason);
Olli Etuaho856c4972016-08-08 11:38:39 +0300132 void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType);
133 void checkLocationIsNotSpecified(const TSourceLoc &location,
134 const TLayoutQualifier &layoutQualifier);
Olli Etuaho856c4972016-08-08 11:38:39 +0300135 void checkIsParameterQualifierValid(const TSourceLoc &line,
Martin Radev70866b82016-07-22 15:27:42 +0300136 const TTypeQualifierBuilder &typeQualifierBuilder,
Olli Etuaho856c4972016-08-08 11:38:39 +0300137 TType *type);
138 bool checkCanUseExtension(const TSourceLoc &line, const TString &extension);
Olli Etuaho383b7912016-08-05 11:22:59 +0300139 void singleDeclarationErrorCheck(const TPublicType &publicType,
140 const TSourceLoc &identifierLocation);
Martin Radevb8b01222016-11-20 23:25:53 +0200141 void emptyDeclarationErrorCheck(const TPublicType &publicType, const TSourceLoc &location);
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(); }
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500158 const TExtensionBehavior &extensionBehavior() const
159 {
160 return mDirectiveHandler.extensionBehavior();
161 }
Jamie Madill06145232015-05-13 13:10:01 -0400162 bool supportsExtension(const char *extension);
163 bool isExtensionEnabled(const char *extension) const;
164 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500165 void handlePragmaDirective(const TSourceLoc &loc,
166 const char *name,
167 const char *value,
168 bool stdgl);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000169
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500170 const TFunction *findFunction(const TSourceLoc &line,
171 TFunction *pfnCall,
172 int inputShaderVersion,
173 bool *builtIn = 0);
Jamie Madill06145232015-05-13 13:10:01 -0400174 bool executeInitializer(const TSourceLoc &line,
175 const TString &identifier,
176 const TPublicType &pType,
177 TIntermTyped *initializer,
Olli Etuaho13389b62016-10-16 11:48:18 +0100178 TIntermBinary **initNode);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000179
Olli Etuaho0e3aee32016-10-27 12:56:38 +0100180 void addFullySpecifiedType(TPublicType *typeSpecifier);
Martin Radev70866b82016-07-22 15:27:42 +0300181 TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400182 const TPublicType &typeSpecifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200183
Olli Etuaho13389b62016-10-16 11:48:18 +0100184 TIntermDeclaration *parseSingleDeclaration(TPublicType &publicType,
185 const TSourceLoc &identifierOrTypeLocation,
186 const TString &identifier);
187 TIntermDeclaration *parseSingleArrayDeclaration(TPublicType &publicType,
188 const TSourceLoc &identifierLocation,
189 const TString &identifier,
190 const TSourceLoc &indexLocation,
191 TIntermTyped *indexExpression);
192 TIntermDeclaration *parseSingleInitDeclaration(const TPublicType &publicType,
193 const TSourceLoc &identifierLocation,
194 const TString &identifier,
195 const TSourceLoc &initLocation,
196 TIntermTyped *initializer);
Jamie Madill47e3ec02014-08-20 16:38:33 -0400197
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300198 // Parse a declaration like "type a[n] = initializer"
199 // Note that this does not apply to declarations like "type[n] a = initializer"
Olli Etuaho13389b62016-10-16 11:48:18 +0100200 TIntermDeclaration *parseSingleArrayInitDeclaration(TPublicType &publicType,
201 const TSourceLoc &identifierLocation,
202 const TString &identifier,
203 const TSourceLoc &indexLocation,
204 TIntermTyped *indexExpression,
205 const TSourceLoc &initLocation,
206 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300207
Olli Etuahobf4e1b72016-12-09 11:30:15 +0000208 TIntermInvariantDeclaration *parseInvariantDeclaration(
209 const TTypeQualifierBuilder &typeQualifierBuilder,
210 const TSourceLoc &identifierLoc,
211 const TString *identifier,
212 const TSymbol *symbol);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200213
Olli Etuaho13389b62016-10-16 11:48:18 +0100214 void parseDeclarator(TPublicType &publicType,
215 const TSourceLoc &identifierLocation,
216 const TString &identifier,
217 TIntermDeclaration *declarationOut);
218 void parseArrayDeclarator(TPublicType &publicType,
219 const TSourceLoc &identifierLocation,
220 const TString &identifier,
221 const TSourceLoc &arrayLocation,
222 TIntermTyped *indexExpression,
223 TIntermDeclaration *declarationOut);
224 void parseInitDeclarator(const TPublicType &publicType,
225 const TSourceLoc &identifierLocation,
226 const TString &identifier,
227 const TSourceLoc &initLocation,
228 TIntermTyped *initializer,
229 TIntermDeclaration *declarationOut);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200230
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300231 // Parse a declarator like "a[n] = initializer"
Olli Etuaho13389b62016-10-16 11:48:18 +0100232 void parseArrayInitDeclarator(const TPublicType &publicType,
233 const TSourceLoc &identifierLocation,
234 const TString &identifier,
235 const TSourceLoc &indexLocation,
236 TIntermTyped *indexExpression,
237 const TSourceLoc &initLocation,
238 TIntermTyped *initializer,
239 TIntermDeclaration *declarationOut);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300240
Martin Radev70866b82016-07-22 15:27:42 +0300241 void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder);
Olli Etuaho476197f2016-10-11 13:59:08 +0100242 TIntermAggregate *addFunctionPrototypeDeclaration(const TFunction &parsedFunction,
Olli Etuahoee63f5d2016-01-04 11:34:54 +0200243 const TSourceLoc &location);
Olli Etuaho336b1472016-10-05 16:37:55 +0100244 TIntermFunctionDefinition *addFunctionDefinition(const TFunction &function,
245 TIntermAggregate *functionParameters,
246 TIntermBlock *functionBody,
247 const TSourceLoc &location);
Olli Etuaho476197f2016-10-11 13:59:08 +0100248 void parseFunctionDefinitionHeader(const TSourceLoc &location,
249 TFunction **function,
250 TIntermAggregate **aggregateOut);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500251 TFunction *parseFunctionDeclarator(const TSourceLoc &location, TFunction *function);
Olli Etuaho9de84a52016-06-14 17:36:01 +0300252 TFunction *parseFunctionHeader(const TPublicType &type,
253 const TString *name,
254 const TSourceLoc &location);
Jamie Madill06145232015-05-13 13:10:01 -0400255 TFunction *addConstructorFunc(const TPublicType &publicType);
256 TIntermTyped *addConstructor(TIntermNode *arguments,
Jamie Madill06145232015-05-13 13:10:01 -0400257 TOperator op,
258 TFunction *fnCall,
259 const TSourceLoc &line);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300260
Jamie Madill06145232015-05-13 13:10:01 -0400261 TIntermTyped *addIndexExpression(TIntermTyped *baseExpression,
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500262 const TSourceLoc &location,
Jamie Madill06145232015-05-13 13:10:01 -0400263 TIntermTyped *indexExpression);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500264 TIntermTyped *addFieldSelectionExpression(TIntermTyped *baseExpression,
Jamie Madill06145232015-05-13 13:10:01 -0400265 const TSourceLoc &dotLocation,
266 const TString &fieldString,
267 const TSourceLoc &fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +0000268
Olli Etuaho4de340a2016-12-16 09:32:03 +0000269 TFieldList *combineStructFieldLists(TFieldList *processedFields,
270 const TFieldList *newlyAddedFields,
271 const TSourceLoc &location);
Martin Radev70866b82016-07-22 15:27:42 +0300272 TFieldList *addStructDeclaratorListWithQualifiers(
273 const TTypeQualifierBuilder &typeQualifierBuilder,
274 TPublicType *typeSpecifier,
275 TFieldList *fieldList);
Jamie Madill06145232015-05-13 13:10:01 -0400276 TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList);
Martin Radev4a9cd802016-09-01 16:51:51 +0300277 TTypeSpecifierNonArray addStructure(const TSourceLoc &structLine,
278 const TSourceLoc &nameLine,
279 const TString *structName,
280 TFieldList *fieldList);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000281
Olli Etuaho13389b62016-10-16 11:48:18 +0100282 TIntermDeclaration *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder,
283 const TSourceLoc &nameLine,
284 const TString &blockName,
285 TFieldList *fieldList,
286 const TString *instanceName,
287 const TSourceLoc &instanceLine,
288 TIntermTyped *arrayIndex,
289 const TSourceLoc &arrayIndexLine);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000290
Martin Radev802abe02016-08-04 17:48:32 +0300291 void parseLocalSize(const TString &qualifierType,
292 const TSourceLoc &qualifierTypeLine,
293 int intValue,
294 const TSourceLoc &intValueLine,
295 const std::string &intValueString,
296 size_t index,
Martin Radev4c4c8e72016-08-04 12:25:34 +0300297 sh::WorkGroupSize *localSize);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500298 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
299 const TSourceLoc &qualifierTypeLine);
Jamie Madill06145232015-05-13 13:10:01 -0400300 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
301 const TSourceLoc &qualifierTypeLine,
Jamie Madill06145232015-05-13 13:10:01 -0400302 int intValue,
303 const TSourceLoc &intValueLine);
Olli Etuaho613b9592016-09-05 12:05:53 +0300304 TTypeQualifierBuilder *createTypeQualifierBuilder(const TSourceLoc &loc);
Martin Radev802abe02016-08-04 17:48:32 +0300305 TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier,
306 TLayoutQualifier rightQualifier,
307 const TSourceLoc &rightQualifierLocation);
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000308
kbr@chromium.org476541f2011-10-27 21:14:51 +0000309 // Performs an error check for embedded struct declarations.
Olli Etuaho383b7912016-08-05 11:22:59 +0300310 void enterStructDeclaration(const TSourceLoc &line, const TString &identifier);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000311 void exitStructDeclaration();
312
Olli Etuaho8a176262016-08-16 14:23:01 +0300313 void checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field);
Olli Etuaho09b22472015-02-11 11:47:26 +0200314
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100315 TIntermSwitch *addSwitch(TIntermTyped *init,
316 TIntermBlock *statementList,
317 const TSourceLoc &loc);
Olli Etuahoa3a36662015-02-17 13:46:51 +0200318 TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc);
319 TIntermCase *addDefault(const TSourceLoc &loc);
320
Jamie Madill06145232015-05-13 13:10:01 -0400321 TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
322 TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500323 TIntermTyped *addBinaryMath(TOperator op,
324 TIntermTyped *left,
325 TIntermTyped *right,
326 const TSourceLoc &loc);
327 TIntermTyped *addBinaryMathBooleanResult(TOperator op,
328 TIntermTyped *left,
329 TIntermTyped *right,
330 const TSourceLoc &loc);
331 TIntermTyped *addAssign(TOperator op,
332 TIntermTyped *left,
333 TIntermTyped *right,
334 const TSourceLoc &loc);
Olli Etuaho49300862015-02-20 14:54:49 +0200335
Olli Etuaho0b2d2dc2015-11-04 16:35:32 +0200336 TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
337
Olli Etuaho49300862015-02-20 14:54:49 +0200338 TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc);
339 TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +0200340
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200341 void checkTextureOffsetConst(TIntermAggregate *functionCall);
Martin Radev2cc85b32016-08-05 16:22:53 +0300342 void checkImageMemoryAccessForBuiltinFunctions(TIntermAggregate *functionCall);
343 void checkImageMemoryAccessForUserDefinedFunctions(const TFunction *functionDefinition,
344 const TIntermAggregate *functionCall);
Jamie Madill06145232015-05-13 13:10:01 -0400345 TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall,
346 TIntermNode *paramNode,
347 TIntermNode *thisNode,
348 const TSourceLoc &loc,
349 bool *fatalError);
Olli Etuahofc1806e2015-03-17 13:03:11 +0200350
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300351 TIntermTyped *addTernarySelection(TIntermTyped *cond,
352 TIntermTyped *trueExpression,
353 TIntermTyped *falseExpression,
354 const TSourceLoc &line);
Olli Etuaho52901742015-04-15 13:42:45 +0300355
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400356 // TODO(jmadill): make these private
Olli Etuahof119a262016-08-19 15:54:22 +0300357 TIntermediate intermediate; // to build a parse tree
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400358 TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed
359
Olli Etuahofc1806e2015-03-17 13:03:11 +0200360 private:
Olli Etuaho4de340a2016-12-16 09:32:03 +0000361 // Returns a clamped index. If it prints out an error message, the token is "[]".
Olli Etuaho90892fb2016-07-14 14:44:51 +0300362 int checkIndexOutOfRange(bool outOfRangeIndexIsError,
363 const TSourceLoc &location,
364 int index,
365 int arraySize,
Olli Etuaho4de340a2016-12-16 09:32:03 +0000366 const char *reason);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300367
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500368 bool declareVariable(const TSourceLoc &line,
369 const TString &identifier,
370 const TType &type,
371 TVariable **variable);
Olli Etuaho2935c582015-04-08 14:32:06 +0300372
Olli Etuaho856c4972016-08-08 11:38:39 +0300373 void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line,
374 const TString &identifier,
375 TPublicType *type);
Olli Etuaho376f1b52015-04-13 13:23:41 +0300376
Olli Etuaho8a176262016-08-16 14:23:01 +0300377 bool checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation,
378 const TPublicType &elementType);
379
Olli Etuaho1dded802016-08-18 18:13:13 +0300380 // Assumes that multiplication op has already been set based on the types.
381 bool isMultiplicationTypeCombinationValid(TOperator op, const TType &left, const TType &right);
382
Martin Radev2cc85b32016-08-05 16:22:53 +0300383 bool checkIsMemoryQualifierNotSpecified(const TMemoryQualifier &memoryQualifier,
384 const TSourceLoc &location);
385 void checkOutParameterIsNotImage(const TSourceLoc &line,
386 TQualifier qualifier,
387 const TType &type);
388 void checkOutParameterIsNotOpaqueType(const TSourceLoc &line,
389 TQualifier qualifier,
390 const TType &type);
391 void checkOutParameterIsNotSampler(const TSourceLoc &line,
392 TQualifier qualifier,
393 const TType &type);
394
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500395 TIntermTyped *addBinaryMathInternal(TOperator op,
396 TIntermTyped *left,
397 TIntermTyped *right,
398 const TSourceLoc &loc);
Olli Etuaho13389b62016-10-16 11:48:18 +0100399 TIntermBinary *createAssign(TOperator op,
400 TIntermTyped *left,
401 TIntermTyped *right,
402 const TSourceLoc &loc);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500403 // The funcReturnType parameter is expected to be non-null when the operation is a built-in
404 // function.
Olli Etuahof6c694b2015-03-26 14:50:53 +0200405 // It is expected to be null for other unary operators.
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500406 TIntermTyped *createUnaryMath(TOperator op,
407 TIntermTyped *child,
408 const TSourceLoc &loc,
409 const TType *funcReturnType);
Olli Etuahod6b14282015-03-17 14:31:35 +0200410
Olli Etuaho47fd36a2015-03-19 14:22:24 +0200411 // Return true if the checks pass
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500412 bool binaryOpCommonCheck(TOperator op,
413 TIntermTyped *left,
414 TIntermTyped *right,
415 const TSourceLoc &loc);
Olli Etuahofa33d582015-04-09 14:33:12 +0300416
417 // Set to true when the last/current declarator list was started with an empty declaration.
418 bool mDeferredSingleDeclarationErrorCheck;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400419
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500420 sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800421 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
422 ShCompileOptions mCompileOptions; // Options passed to TCompiler
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400423 int mShaderVersion;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500424 TIntermBlock *mTreeRoot; // root of parse tree being created
425 int mLoopNestingLevel; // 0 if outside all loops
426 int mStructNestingLevel; // incremented while parsing a struct declaration
427 int mSwitchNestingLevel; // 0 if outside all switch statements
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800428 const TType
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500429 *mCurrentFunctionType; // the return type of the function that's currently being parsed
430 bool mFunctionReturnsValue; // true if a non-void function has a return
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800431 bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared
432 // 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 Madilld7b1ab52016-12-12 14:42:19 -0500442 bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
Jamie Madill14e95b32015-05-07 10:10:41 -0400443 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 Madilld7b1ab52016-12-12 14:42:19 -0500456int PaParseStrings(size_t count,
457 const char *const string[],
458 const int length[],
459 TParseContext *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000460
Jamie Madill45bcc782016-11-07 13:58:48 -0500461} // namespace sh
462
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500463#endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_