blob: 2ffd7de80a93120ee30c4321831024e189edcbc2 [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"
daniel@transgaming.comb401a922012-10-26 18:58:24 +000014#include "compiler/preprocessor/Preprocessor.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000015
Jamie Madill06145232015-05-13 13:10:01 -040016struct TMatrixFields
17{
daniel@transgaming.com0578f812010-05-17 09:58:39 +000018 bool wholeRow;
19 bool wholeCol;
20 int row;
21 int col;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000022};
23
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000024//
25// The following are extra variables needed during parsing, grouped together so
26// they can be passed to the parser without needing a global.
27//
Jamie Madill6e06b1f2015-05-14 10:01:17 -040028class TParseContext : angle::NonCopyable
Jamie Madill06145232015-05-13 13:10:01 -040029{
Jamie Madill6e06b1f2015-05-14 10:01:17 -040030 public:
Jamie Madill06145232015-05-13 13:10:01 -040031 TParseContext(TSymbolTable &symt,
32 TExtensionBehavior &ext,
33 TIntermediate &interm,
34 sh::GLenum type,
35 ShShaderSpec spec,
36 int options,
37 bool checksPrecErrors,
38 TInfoSink &is,
Olli Etuahoe1a94c62015-11-16 17:35:25 +020039 const ShBuiltInResources &resources)
Jamie Madill06145232015-05-13 13:10:01 -040040 : intermediate(interm),
41 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),
Corentin Wallezbc99bb62015-05-14 17:42:20 -040045 mShaderVersion(100),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040046 mTreeRoot(nullptr),
Jamie Madill06145232015-05-13 13:10:01 -040047 mLoopNestingLevel(0),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040048 mStructNestingLevel(0),
Jamie Madill06145232015-05-13 13:10:01 -040049 mSwitchNestingLevel(0),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040050 mCurrentFunctionType(nullptr),
Jamie Madill06145232015-05-13 13:10:01 -040051 mFunctionReturnsValue(false),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040052 mChecksPrecisionErrors(checksPrecErrors),
Olli Etuahoa6996682015-10-12 14:32:30 +030053 mFragmentPrecisionHighOnESSL1(false),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040054 mDefaultMatrixPacking(EmpColumnMajor),
55 mDefaultBlockStorage(EbsShared),
56 mDiagnostics(is),
Olli Etuahoe1a94c62015-11-16 17:35:25 +020057 mDirectiveHandler(ext,
58 mDiagnostics,
59 mShaderVersion,
Olli Etuaho5f80d012016-01-11 11:16:01 +020060 mShaderType,
Olli Etuahoe1a94c62015-11-16 17:35:25 +020061 resources.WEBGL_debug_shader_precision == 1),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040062 mPreprocessor(&mDiagnostics, &mDirectiveHandler),
63 mScanner(nullptr),
Jamie Madill14e95b32015-05-07 10:10:41 -040064 mUsesFragData(false),
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +030065 mUsesFragColor(false),
Olli Etuahoe1a94c62015-11-16 17:35:25 +020066 mUsesSecondaryOutputs(false),
67 mMinProgramTexelOffset(resources.MinProgramTexelOffset),
Martin Radev802abe02016-08-04 17:48:32 +030068 mMaxProgramTexelOffset(resources.MaxProgramTexelOffset),
69 mComputeShaderLocalSizeDeclared(false)
Olli Etuahofa33d582015-04-09 14:33:12 +030070 {
Martin Radev802abe02016-08-04 17:48:32 +030071 mComputeShaderLocalSize.fill(-1);
Olli Etuahofa33d582015-04-09 14:33:12 +030072 }
Jamie Madill06145232015-05-13 13:10:01 -040073
Jamie Madill6e06b1f2015-05-14 10:01:17 -040074 const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
75 pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
76 void *getScanner() const { return mScanner; }
77 void setScanner(void *scanner) { mScanner = scanner; }
78 int getShaderVersion() const { return mShaderVersion; }
79 sh::GLenum getShaderType() const { return mShaderType; }
80 ShShaderSpec getShaderSpec() const { return mShaderSpec; }
81 int numErrors() const { return mDiagnostics.numErrors(); }
82 TInfoSink &infoSink() { return mDiagnostics.infoSink(); }
Jamie Madill06145232015-05-13 13:10:01 -040083 void error(const TSourceLoc &loc, const char *reason, const char *token,
84 const char *extraInfo="");
85 void warning(const TSourceLoc &loc, const char *reason, const char *token,
86 const char *extraInfo="");
Jamie Madill14e95b32015-05-07 10:10:41 -040087
Olli Etuaho7c3848e2015-11-04 13:19:17 +020088 // If isError is false, a warning will be reported instead.
89 void outOfRangeError(bool isError,
90 const TSourceLoc &loc,
91 const char *reason,
92 const char *token,
93 const char *extraInfo = "");
94
Jamie Madill6e06b1f2015-05-14 10:01:17 -040095 TIntermNode *getTreeRoot() const { return mTreeRoot; }
96 void setTreeRoot(TIntermNode *treeRoot) { mTreeRoot = treeRoot; }
97
Olli Etuahoa6996682015-10-12 14:32:30 +030098 bool getFragmentPrecisionHigh() const
Jamie Madill6e06b1f2015-05-14 10:01:17 -040099 {
Olli Etuahoa6996682015-10-12 14:32:30 +0300100 return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300;
101 }
102 void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh)
103 {
104 mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400105 }
106
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400107 void setLoopNestingLevel(int loopNestintLevel)
108 {
109 mLoopNestingLevel = loopNestintLevel;
110 }
111
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400112 void incrLoopNestingLevel() { ++mLoopNestingLevel; }
113 void decrLoopNestingLevel() { --mLoopNestingLevel; }
114
115 void incrSwitchNestingLevel() { ++mSwitchNestingLevel; }
116 void decrSwitchNestingLevel() { --mSwitchNestingLevel; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000117
Martin Radev802abe02016-08-04 17:48:32 +0300118 bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; }
119 TLocalSize getComputeShaderLocalSize() const;
120
Jamie Madill5c097022014-08-20 16:38:32 -0400121 // This method is guaranteed to succeed, even if no variable with 'name' exists.
122 const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol);
Olli Etuaho82c29ed2015-11-03 13:06:54 +0200123 TIntermTyped *parseVariableIdentifier(const TSourceLoc &location,
124 const TString *name,
125 const TSymbol *symbol);
Jamie Madill5c097022014-08-20 16:38:32 -0400126
Jamie Madill06145232015-05-13 13:10:01 -0400127 bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc &line);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000128
Jamie Madill06145232015-05-13 13:10:01 -0400129 void assignError(const TSourceLoc &line, const char *op, TString left, TString right);
130 void unaryOpError(const TSourceLoc &line, const char *op, TString operand);
131 void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right);
Olli Etuaho856c4972016-08-08 11:38:39 +0300132
133 bool checkIsNotReserved(const TSourceLoc &line, const TString &identifier);
134 void checkPrecisionSpecified(const TSourceLoc &line, TPrecision precision, TBasicType type);
135 bool checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node);
136 void checkIsConst(TIntermTyped *node);
137 void checkIsScalarInteger(TIntermTyped *node, const char *token);
138 void checkIsAtGlobalLevel(const TSourceLoc &line, const char *token);
139 bool checkConstructorArguments(const TSourceLoc &line,
140 TIntermNode *argumentsNode,
141 const TFunction &function,
142 TOperator op,
143 const TType &type);
144
145 // Returns a sanitized array size to use (the size is at least 1).
146 unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr);
147 bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &type);
148 bool checkIsValidTypeForArray(const TSourceLoc &line, const TPublicType &type);
149 bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
150 void checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type);
151 void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType);
152 bool checkIsNotSampler(const TSourceLoc &line, const TPublicType &pType, const char *reason);
153 void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType);
154 void checkLocationIsNotSpecified(const TSourceLoc &location,
155 const TLayoutQualifier &layoutQualifier);
156 void checkOutParameterIsNotSampler(const TSourceLoc &line,
157 TQualifier qualifier,
158 const TType &type);
159 void checkIsParameterQualifierValid(const TSourceLoc &line,
160 TQualifier qualifier,
161 TQualifier paramQualifier,
162 TType *type);
163 bool checkCanUseExtension(const TSourceLoc &line, const TString &extension);
Olli Etuaho383b7912016-08-05 11:22:59 +0300164 void singleDeclarationErrorCheck(const TPublicType &publicType,
165 const TSourceLoc &identifierLocation);
Olli Etuaho856c4972016-08-08 11:38:39 +0300166 void checkLayoutQualifierSupported(const TSourceLoc &location,
167 const TString &layoutQualifierName,
168 int versionRequired);
169 bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location,
170 const TLayoutQualifier &layoutQualifier);
171
172 void functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall);
173 void checkInvariantIsOutVariableES3(const TQualifier qualifier,
174 const TSourceLoc &invariantLocation);
175 void checkInputOutputTypeIsValidES3(const TQualifier qualifier,
176 const TPublicType &type,
177 const TSourceLoc &qualifierLocation);
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000178
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400179 const TPragma &pragma() const { return mDirectiveHandler.pragma(); }
180 const TExtensionBehavior &extensionBehavior() const { return mDirectiveHandler.extensionBehavior(); }
Jamie Madill06145232015-05-13 13:10:01 -0400181 bool supportsExtension(const char *extension);
182 bool isExtensionEnabled(const char *extension) const;
183 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
184 void handlePragmaDirective(const TSourceLoc &loc, const char *name, const char *value, bool stdgl);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000185
Jamie Madill06145232015-05-13 13:10:01 -0400186 bool containsSampler(const TType &type);
Jamie Madill06145232015-05-13 13:10:01 -0400187 const TFunction* findFunction(
188 const TSourceLoc &line, TFunction *pfnCall, int inputShaderVersion, bool *builtIn = 0);
189 bool executeInitializer(const TSourceLoc &line,
190 const TString &identifier,
191 const TPublicType &pType,
192 TIntermTyped *initializer,
193 TIntermNode **intermNode);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000194
Jamie Madill06145232015-05-13 13:10:01 -0400195 TPublicType addFullySpecifiedType(TQualifier qualifier,
196 bool invariant,
197 TLayoutQualifier layoutQualifier,
198 const TPublicType &typeSpecifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200199
Olli Etuahofa33d582015-04-09 14:33:12 +0300200 TIntermAggregate *parseSingleDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400201 const TSourceLoc &identifierOrTypeLocation,
202 const TString &identifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200203 TIntermAggregate *parseSingleArrayDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400204 const TSourceLoc &identifierLocation,
205 const TString &identifier,
206 const TSourceLoc &indexLocation,
207 TIntermTyped *indexExpression);
208 TIntermAggregate *parseSingleInitDeclaration(const TPublicType &publicType,
209 const TSourceLoc &identifierLocation,
210 const TString &identifier,
211 const TSourceLoc &initLocation,
212 TIntermTyped *initializer);
Jamie Madill47e3ec02014-08-20 16:38:33 -0400213
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300214 // Parse a declaration like "type a[n] = initializer"
215 // Note that this does not apply to declarations like "type[n] a = initializer"
216 TIntermAggregate *parseSingleArrayInitDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400217 const TSourceLoc &identifierLocation,
218 const TString &identifier,
219 const TSourceLoc &indexLocation,
220 TIntermTyped *indexExpression,
221 const TSourceLoc &initLocation,
222 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300223
Jamie Madill06145232015-05-13 13:10:01 -0400224 TIntermAggregate *parseInvariantDeclaration(const TSourceLoc &invariantLoc,
225 const TSourceLoc &identifierLoc,
226 const TString *identifier,
227 const TSymbol *symbol);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200228
Jamie Madill06145232015-05-13 13:10:01 -0400229 TIntermAggregate *parseDeclarator(TPublicType &publicType,
230 TIntermAggregate *aggregateDeclaration,
231 const TSourceLoc &identifierLocation,
232 const TString &identifier);
233 TIntermAggregate *parseArrayDeclarator(TPublicType &publicType,
234 TIntermAggregate *aggregateDeclaration,
235 const TSourceLoc &identifierLocation,
236 const TString &identifier,
237 const TSourceLoc &arrayLocation,
238 TIntermTyped *indexExpression);
239 TIntermAggregate *parseInitDeclarator(const TPublicType &publicType,
240 TIntermAggregate *aggregateDeclaration,
241 const TSourceLoc &identifierLocation,
242 const TString &identifier,
243 const TSourceLoc &initLocation,
244 TIntermTyped *initializer);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200245
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300246 // Parse a declarator like "a[n] = initializer"
Jamie Madill06145232015-05-13 13:10:01 -0400247 TIntermAggregate *parseArrayInitDeclarator(const TPublicType &publicType,
248 TIntermAggregate *aggregateDeclaration,
249 const TSourceLoc &identifierLocation,
250 const TString &identifier,
251 const TSourceLoc &indexLocation,
252 TIntermTyped *indexExpression,
253 const TSourceLoc &initLocation,
254 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300255
Jamie Madilla295edf2013-06-06 11:56:48 -0400256 void parseGlobalLayoutQualifier(const TPublicType &typeQualifier);
Olli Etuahoee63f5d2016-01-04 11:34:54 +0200257 TIntermAggregate *addFunctionPrototypeDeclaration(const TFunction &function,
258 const TSourceLoc &location);
259 TIntermAggregate *addFunctionDefinition(const TFunction &function,
260 TIntermAggregate *functionPrototype,
261 TIntermAggregate *functionBody,
262 const TSourceLoc &location);
Jamie Madill185fb402015-06-12 15:48:48 -0400263 void parseFunctionPrototype(const TSourceLoc &location,
264 TFunction *function,
265 TIntermAggregate **aggregateOut);
266 TFunction *parseFunctionDeclarator(const TSourceLoc &location,
267 TFunction *function);
Olli Etuaho9de84a52016-06-14 17:36:01 +0300268 TFunction *parseFunctionHeader(const TPublicType &type,
269 const TString *name,
270 const TSourceLoc &location);
Jamie Madill06145232015-05-13 13:10:01 -0400271 TFunction *addConstructorFunc(const TPublicType &publicType);
272 TIntermTyped *addConstructor(TIntermNode *arguments,
Jamie Madill06145232015-05-13 13:10:01 -0400273 TOperator op,
274 TFunction *fnCall,
275 const TSourceLoc &line);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300276
Jamie Madill06145232015-05-13 13:10:01 -0400277 TIntermTyped *addConstStruct(
278 const TString &identifier, TIntermTyped *node, const TSourceLoc& line);
279 TIntermTyped *addIndexExpression(TIntermTyped *baseExpression,
280 const TSourceLoc& location,
281 TIntermTyped *indexExpression);
282 TIntermTyped* addFieldSelectionExpression(TIntermTyped *baseExpression,
283 const TSourceLoc &dotLocation,
284 const TString &fieldString,
285 const TSourceLoc &fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +0000286
Jamie Madill06145232015-05-13 13:10:01 -0400287 TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList);
288 TPublicType addStructure(const TSourceLoc &structLine,
289 const TSourceLoc &nameLine,
290 const TString *structName,
291 TFieldList *fieldList);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000292
Jamie Madill06145232015-05-13 13:10:01 -0400293 TIntermAggregate* addInterfaceBlock(const TPublicType &typeQualifier,
294 const TSourceLoc &nameLine,
295 const TString &blockName,
296 TFieldList *fieldList,
297 const TString *instanceName,
298 const TSourceLoc &instanceLine,
299 TIntermTyped *arrayIndex,
300 const TSourceLoc& arrayIndexLine);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000301
Martin Radev802abe02016-08-04 17:48:32 +0300302 void parseLocalSize(const TString &qualifierType,
303 const TSourceLoc &qualifierTypeLine,
304 int intValue,
305 const TSourceLoc &intValueLine,
306 const std::string &intValueString,
307 size_t index,
308 TLocalSize *localSize);
Jamie Madill06145232015-05-13 13:10:01 -0400309 TLayoutQualifier parseLayoutQualifier(
310 const TString &qualifierType, const TSourceLoc &qualifierTypeLine);
311 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
312 const TSourceLoc &qualifierTypeLine,
Jamie Madill06145232015-05-13 13:10:01 -0400313 int intValue,
314 const TSourceLoc &intValueLine);
Martin Radev802abe02016-08-04 17:48:32 +0300315 TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier,
316 TLayoutQualifier rightQualifier,
317 const TSourceLoc &rightQualifierLocation);
Jamie Madillf2e0f9b2013-08-26 16:39:42 -0400318 TPublicType joinInterpolationQualifiers(const TSourceLoc &interpolationLoc, TQualifier interpolationQualifier,
319 const TSourceLoc &storageLoc, TQualifier storageQualifier);
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000320
kbr@chromium.org476541f2011-10-27 21:14:51 +0000321 // Performs an error check for embedded struct declarations.
Olli Etuaho383b7912016-08-05 11:22:59 +0300322 void enterStructDeclaration(const TSourceLoc &line, const TString &identifier);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000323 void exitStructDeclaration();
324
Jamie Madill06145232015-05-13 13:10:01 -0400325 bool structNestingErrorCheck(const TSourceLoc &line, const TField &field);
Olli Etuaho09b22472015-02-11 11:47:26 +0200326
Olli Etuahoa3a36662015-02-17 13:46:51 +0200327 TIntermSwitch *addSwitch(TIntermTyped *init, TIntermAggregate *statementList, const TSourceLoc &loc);
328 TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc);
329 TIntermCase *addDefault(const TSourceLoc &loc);
330
Jamie Madill06145232015-05-13 13:10:01 -0400331 TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
332 TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
333 TIntermTyped *addBinaryMath(
334 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
335 TIntermTyped *addBinaryMathBooleanResult(
336 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
337 TIntermTyped *addAssign(
338 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuaho49300862015-02-20 14:54:49 +0200339
Olli Etuaho0b2d2dc2015-11-04 16:35:32 +0200340 TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
341
Olli Etuaho49300862015-02-20 14:54:49 +0200342 TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc);
343 TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +0200344
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200345 void checkTextureOffsetConst(TIntermAggregate *functionCall);
Jamie Madill06145232015-05-13 13:10:01 -0400346 TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall,
347 TIntermNode *paramNode,
348 TIntermNode *thisNode,
349 const TSourceLoc &loc,
350 bool *fatalError);
Olli Etuahofc1806e2015-03-17 13:03:11 +0200351
Jamie Madill06145232015-05-13 13:10:01 -0400352 TIntermTyped *addTernarySelection(
353 TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock, const TSourceLoc &line);
Olli Etuaho52901742015-04-15 13:42:45 +0300354
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400355 // TODO(jmadill): make these private
356 TIntermediate &intermediate; // to hold and build a parse tree
357 TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed
358
Olli Etuahofc1806e2015-03-17 13:03:11 +0200359 private:
Olli Etuaho90892fb2016-07-14 14:44:51 +0300360 // Returns a clamped index.
361 int checkIndexOutOfRange(bool outOfRangeIndexIsError,
362 const TSourceLoc &location,
363 int index,
364 int arraySize,
365 const char *reason,
366 const char *token);
367
368 // Constant folding for element access. Note that the returned node does not have the correct
369 // type - it is expected to be fixed later.
370 TIntermConstantUnion *foldVectorSwizzle(TVectorFields &fields,
371 TIntermConstantUnion *baseNode,
372 const TSourceLoc &location);
373 TIntermConstantUnion *foldMatrixSubscript(int index,
374 TIntermConstantUnion *baseNode,
375 const TSourceLoc &location);
376 TIntermConstantUnion *foldArraySubscript(int index,
377 TIntermConstantUnion *baseNode,
378 const TSourceLoc &location);
379
Olli Etuaho2935c582015-04-08 14:32:06 +0300380 bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable);
381
Olli Etuaho856c4972016-08-08 11:38:39 +0300382 void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line,
383 const TString &identifier,
384 TPublicType *type);
Olli Etuaho376f1b52015-04-13 13:23:41 +0300385
Jamie Madill06145232015-05-13 13:10:01 -0400386 TIntermTyped *addBinaryMathInternal(
387 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
388 TIntermTyped *createAssign(
389 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuahof6c694b2015-03-26 14:50:53 +0200390 // The funcReturnType parameter is expected to be non-null when the operation is a built-in function.
391 // It is expected to be null for other unary operators.
Jamie Madill06145232015-05-13 13:10:01 -0400392 TIntermTyped *createUnaryMath(
393 TOperator op, TIntermTyped *child, const TSourceLoc &loc, const TType *funcReturnType);
Olli Etuahod6b14282015-03-17 14:31:35 +0200394
Olli Etuaho47fd36a2015-03-19 14:22:24 +0200395 // Return true if the checks pass
Jamie Madill06145232015-05-13 13:10:01 -0400396 bool binaryOpCommonCheck(
397 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuahofa33d582015-04-09 14:33:12 +0300398
399 // Set to true when the last/current declarator list was started with an empty declaration.
400 bool mDeferredSingleDeclarationErrorCheck;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400401
402 sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
403 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
404 int mShaderVersion;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400405 TIntermNode *mTreeRoot; // root of parse tree being created
406 int mLoopNestingLevel; // 0 if outside all loops
407 int mStructNestingLevel; // incremented while parsing a struct declaration
408 int mSwitchNestingLevel; // 0 if outside all switch statements
409 const TType *mCurrentFunctionType; // the return type of the function that's currently being parsed
410 bool mFunctionReturnsValue; // true if a non-void function has a return
411 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 +0300412 bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling
413 // ESSL1.
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400414 TLayoutMatrixPacking mDefaultMatrixPacking;
415 TLayoutBlockStorage mDefaultBlockStorage;
416 TString mHashErrMsg;
417 TDiagnostics mDiagnostics;
418 TDirectiveHandler mDirectiveHandler;
419 pp::Preprocessor mPreprocessor;
420 void *mScanner;
Jamie Madill14e95b32015-05-07 10:10:41 -0400421 bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
422 bool mUsesFragColor;
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +0300423 bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or
424 // gl_Secondary FragColor or both.
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200425 int mMinProgramTexelOffset;
426 int mMaxProgramTexelOffset;
Martin Radev802abe02016-08-04 17:48:32 +0300427
428 // keep track of local group size declared in layout. It should be declared only once.
429 bool mComputeShaderLocalSizeDeclared;
430 TLocalSize mComputeShaderLocalSize;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000431};
432
Jamie Madill06145232015-05-13 13:10:01 -0400433int PaParseStrings(
434 size_t count, const char *const string[], const int length[], TParseContext *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000435
Geoff Lang0a73dd82014-11-19 16:18:08 -0500436#endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_