blob: ce71488d3046c77c6718adec25397000fcd3a9b8 [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
daniel@transgaming.com0578f812010-05-17 09:58:39 +000095 void recover();
Jamie Madill6e06b1f2015-05-14 10:01:17 -040096 TIntermNode *getTreeRoot() const { return mTreeRoot; }
97 void setTreeRoot(TIntermNode *treeRoot) { mTreeRoot = treeRoot; }
98
Olli Etuahoa6996682015-10-12 14:32:30 +030099 bool getFragmentPrecisionHigh() const
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400100 {
Olli Etuahoa6996682015-10-12 14:32:30 +0300101 return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300;
102 }
103 void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh)
104 {
105 mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400106 }
107
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400108 void setLoopNestingLevel(int loopNestintLevel)
109 {
110 mLoopNestingLevel = loopNestintLevel;
111 }
112
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400113 void incrLoopNestingLevel() { ++mLoopNestingLevel; }
114 void decrLoopNestingLevel() { --mLoopNestingLevel; }
115
116 void incrSwitchNestingLevel() { ++mSwitchNestingLevel; }
117 void decrSwitchNestingLevel() { --mSwitchNestingLevel; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000118
Martin Radev802abe02016-08-04 17:48:32 +0300119 bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; }
120 TLocalSize getComputeShaderLocalSize() const;
121
Jamie Madill5c097022014-08-20 16:38:32 -0400122 // This method is guaranteed to succeed, even if no variable with 'name' exists.
123 const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol);
Olli Etuaho82c29ed2015-11-03 13:06:54 +0200124 TIntermTyped *parseVariableIdentifier(const TSourceLoc &location,
125 const TString *name,
126 const TSymbol *symbol);
Jamie Madill5c097022014-08-20 16:38:32 -0400127
Jamie Madill06145232015-05-13 13:10:01 -0400128 bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc &line);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000129
Jamie Madill06145232015-05-13 13:10:01 -0400130 bool reservedErrorCheck(const TSourceLoc &line, const TString &identifier);
131 void assignError(const TSourceLoc &line, const char *op, TString left, TString right);
132 void unaryOpError(const TSourceLoc &line, const char *op, TString operand);
133 void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right);
134 bool precisionErrorCheck(const TSourceLoc &line, TPrecision precision, TBasicType type);
135 bool lValueErrorCheck(const TSourceLoc &line, const char *op, TIntermTyped*);
136 bool constErrorCheck(TIntermTyped *node);
137 bool integerErrorCheck(TIntermTyped *node, const char *token);
138 bool globalErrorCheck(const TSourceLoc &line, bool global, const char *token);
Olli Etuaho15c2ac32015-11-09 15:51:43 +0200139 bool constructorErrorCheck(const TSourceLoc &line,
140 TIntermNode *argumentsNode,
141 TFunction &function,
142 TOperator op,
143 TType *type);
Jamie Madill06145232015-05-13 13:10:01 -0400144 bool arraySizeErrorCheck(const TSourceLoc &line, TIntermTyped *expr, int &size);
Olli Etuaho3739d232015-04-08 12:23:44 +0300145 bool arrayQualifierErrorCheck(const TSourceLoc &line, const TPublicType &type);
Jamie Madill06145232015-05-13 13:10:01 -0400146 bool arrayTypeErrorCheck(const TSourceLoc &line, const TPublicType &type);
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +0300147 bool voidErrorCheck(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
Jamie Madill075edd82013-07-08 13:30:19 -0400148 bool boolErrorCheck(const TSourceLoc&, const TIntermTyped*);
149 bool boolErrorCheck(const TSourceLoc&, const TPublicType&);
Jamie Madill06145232015-05-13 13:10:01 -0400150 bool samplerErrorCheck(const TSourceLoc &line, const TPublicType &pType, const char *reason);
151 bool locationDeclaratorListCheck(const TSourceLoc &line, const TPublicType &pType);
152 bool parameterSamplerErrorCheck(const TSourceLoc &line, TQualifier qualifier, const TType &type);
153 bool paramErrorCheck(const TSourceLoc &line, TQualifier qualifier, TQualifier paramQualifier, TType *type);
154 bool extensionErrorCheck(const TSourceLoc &line, const TString&);
155 bool singleDeclarationErrorCheck(const TPublicType &publicType, const TSourceLoc &identifierLocation);
156 bool layoutLocationErrorCheck(const TSourceLoc &location, const TLayoutQualifier &layoutQualifier);
Martin Radev802abe02016-08-04 17:48:32 +0300157 void layoutSupportedErrorCheck(const TSourceLoc &location,
158 const TString &layoutQualifierName,
159 int versionRequired);
160 bool layoutWorkGroupSizeErrorCheck(const TSourceLoc &location,
161 const TLayoutQualifier &layoutQualifier);
Olli Etuahob6e07a62015-02-16 12:22:10 +0200162 bool functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *);
Olli Etuaho37ad4742015-04-27 13:18:50 +0300163 void es3InvariantErrorCheck(const TQualifier qualifier, const TSourceLoc &invariantLocation);
Olli Etuahocc36b982015-07-10 14:14:18 +0300164 void es3InputOutputTypeCheck(const TQualifier qualifier,
165 const TPublicType &type,
166 const TSourceLoc &qualifierLocation);
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000167
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400168 const TPragma &pragma() const { return mDirectiveHandler.pragma(); }
169 const TExtensionBehavior &extensionBehavior() const { return mDirectiveHandler.extensionBehavior(); }
Jamie Madill06145232015-05-13 13:10:01 -0400170 bool supportsExtension(const char *extension);
171 bool isExtensionEnabled(const char *extension) const;
172 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
173 void handlePragmaDirective(const TSourceLoc &loc, const char *name, const char *value, bool stdgl);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000174
Jamie Madill06145232015-05-13 13:10:01 -0400175 bool containsSampler(const TType &type);
Jamie Madill06145232015-05-13 13:10:01 -0400176 const TFunction* findFunction(
177 const TSourceLoc &line, TFunction *pfnCall, int inputShaderVersion, bool *builtIn = 0);
178 bool executeInitializer(const TSourceLoc &line,
179 const TString &identifier,
180 const TPublicType &pType,
181 TIntermTyped *initializer,
182 TIntermNode **intermNode);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000183
Jamie Madill06145232015-05-13 13:10:01 -0400184 TPublicType addFullySpecifiedType(TQualifier qualifier,
185 bool invariant,
186 TLayoutQualifier layoutQualifier,
187 const TPublicType &typeSpecifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200188
Olli Etuahofa33d582015-04-09 14:33:12 +0300189 TIntermAggregate *parseSingleDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400190 const TSourceLoc &identifierOrTypeLocation,
191 const TString &identifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200192 TIntermAggregate *parseSingleArrayDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400193 const TSourceLoc &identifierLocation,
194 const TString &identifier,
195 const TSourceLoc &indexLocation,
196 TIntermTyped *indexExpression);
197 TIntermAggregate *parseSingleInitDeclaration(const TPublicType &publicType,
198 const TSourceLoc &identifierLocation,
199 const TString &identifier,
200 const TSourceLoc &initLocation,
201 TIntermTyped *initializer);
Jamie Madill47e3ec02014-08-20 16:38:33 -0400202
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300203 // Parse a declaration like "type a[n] = initializer"
204 // Note that this does not apply to declarations like "type[n] a = initializer"
205 TIntermAggregate *parseSingleArrayInitDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400206 const TSourceLoc &identifierLocation,
207 const TString &identifier,
208 const TSourceLoc &indexLocation,
209 TIntermTyped *indexExpression,
210 const TSourceLoc &initLocation,
211 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300212
Jamie Madill06145232015-05-13 13:10:01 -0400213 TIntermAggregate *parseInvariantDeclaration(const TSourceLoc &invariantLoc,
214 const TSourceLoc &identifierLoc,
215 const TString *identifier,
216 const TSymbol *symbol);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200217
Jamie Madill06145232015-05-13 13:10:01 -0400218 TIntermAggregate *parseDeclarator(TPublicType &publicType,
219 TIntermAggregate *aggregateDeclaration,
220 const TSourceLoc &identifierLocation,
221 const TString &identifier);
222 TIntermAggregate *parseArrayDeclarator(TPublicType &publicType,
223 TIntermAggregate *aggregateDeclaration,
224 const TSourceLoc &identifierLocation,
225 const TString &identifier,
226 const TSourceLoc &arrayLocation,
227 TIntermTyped *indexExpression);
228 TIntermAggregate *parseInitDeclarator(const TPublicType &publicType,
229 TIntermAggregate *aggregateDeclaration,
230 const TSourceLoc &identifierLocation,
231 const TString &identifier,
232 const TSourceLoc &initLocation,
233 TIntermTyped *initializer);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200234
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300235 // Parse a declarator like "a[n] = initializer"
Jamie Madill06145232015-05-13 13:10:01 -0400236 TIntermAggregate *parseArrayInitDeclarator(const TPublicType &publicType,
237 TIntermAggregate *aggregateDeclaration,
238 const TSourceLoc &identifierLocation,
239 const TString &identifier,
240 const TSourceLoc &indexLocation,
241 TIntermTyped *indexExpression,
242 const TSourceLoc &initLocation,
243 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300244
Jamie Madilla295edf2013-06-06 11:56:48 -0400245 void parseGlobalLayoutQualifier(const TPublicType &typeQualifier);
Olli Etuahoee63f5d2016-01-04 11:34:54 +0200246 TIntermAggregate *addFunctionPrototypeDeclaration(const TFunction &function,
247 const TSourceLoc &location);
248 TIntermAggregate *addFunctionDefinition(const TFunction &function,
249 TIntermAggregate *functionPrototype,
250 TIntermAggregate *functionBody,
251 const TSourceLoc &location);
Jamie Madill185fb402015-06-12 15:48:48 -0400252 void parseFunctionPrototype(const TSourceLoc &location,
253 TFunction *function,
254 TIntermAggregate **aggregateOut);
255 TFunction *parseFunctionDeclarator(const TSourceLoc &location,
256 TFunction *function);
Olli Etuaho9de84a52016-06-14 17:36:01 +0300257 TFunction *parseFunctionHeader(const TPublicType &type,
258 const TString *name,
259 const TSourceLoc &location);
Jamie Madill06145232015-05-13 13:10:01 -0400260 TFunction *addConstructorFunc(const TPublicType &publicType);
261 TIntermTyped *addConstructor(TIntermNode *arguments,
262 TType *type,
263 TOperator op,
264 TFunction *fnCall,
265 const TSourceLoc &line);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300266
Jamie Madill06145232015-05-13 13:10:01 -0400267 TIntermTyped *addConstStruct(
268 const TString &identifier, TIntermTyped *node, const TSourceLoc& line);
269 TIntermTyped *addIndexExpression(TIntermTyped *baseExpression,
270 const TSourceLoc& location,
271 TIntermTyped *indexExpression);
272 TIntermTyped* addFieldSelectionExpression(TIntermTyped *baseExpression,
273 const TSourceLoc &dotLocation,
274 const TString &fieldString,
275 const TSourceLoc &fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +0000276
Jamie Madill06145232015-05-13 13:10:01 -0400277 TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList);
278 TPublicType addStructure(const TSourceLoc &structLine,
279 const TSourceLoc &nameLine,
280 const TString *structName,
281 TFieldList *fieldList);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000282
Jamie Madill06145232015-05-13 13:10:01 -0400283 TIntermAggregate* addInterfaceBlock(const TPublicType &typeQualifier,
284 const TSourceLoc &nameLine,
285 const TString &blockName,
286 TFieldList *fieldList,
287 const TString *instanceName,
288 const TSourceLoc &instanceLine,
289 TIntermTyped *arrayIndex,
290 const TSourceLoc& arrayIndexLine);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000291
Martin Radev802abe02016-08-04 17:48:32 +0300292 void parseLocalSize(const TString &qualifierType,
293 const TSourceLoc &qualifierTypeLine,
294 int intValue,
295 const TSourceLoc &intValueLine,
296 const std::string &intValueString,
297 size_t index,
298 TLocalSize *localSize);
Jamie Madill06145232015-05-13 13:10:01 -0400299 TLayoutQualifier parseLayoutQualifier(
300 const TString &qualifierType, const TSourceLoc &qualifierTypeLine);
301 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
302 const TSourceLoc &qualifierTypeLine,
Jamie Madill06145232015-05-13 13:10:01 -0400303 int intValue,
304 const TSourceLoc &intValueLine);
Martin Radev802abe02016-08-04 17:48:32 +0300305 TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier,
306 TLayoutQualifier rightQualifier,
307 const TSourceLoc &rightQualifierLocation);
Jamie Madillf2e0f9b2013-08-26 16:39:42 -0400308 TPublicType joinInterpolationQualifiers(const TSourceLoc &interpolationLoc, TQualifier interpolationQualifier,
309 const TSourceLoc &storageLoc, TQualifier storageQualifier);
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000310
kbr@chromium.org476541f2011-10-27 21:14:51 +0000311 // Performs an error check for embedded struct declarations.
312 // Returns true if an error was raised due to the declaration of
313 // this struct.
Jamie Madill06145232015-05-13 13:10:01 -0400314 bool enterStructDeclaration(const TSourceLoc &line, const TString &identifier);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000315 void exitStructDeclaration();
316
Jamie Madill06145232015-05-13 13:10:01 -0400317 bool structNestingErrorCheck(const TSourceLoc &line, const TField &field);
Olli Etuaho09b22472015-02-11 11:47:26 +0200318
Olli Etuahoa3a36662015-02-17 13:46:51 +0200319 TIntermSwitch *addSwitch(TIntermTyped *init, TIntermAggregate *statementList, const TSourceLoc &loc);
320 TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc);
321 TIntermCase *addDefault(const TSourceLoc &loc);
322
Jamie Madill06145232015-05-13 13:10:01 -0400323 TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
324 TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
325 TIntermTyped *addBinaryMath(
326 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
327 TIntermTyped *addBinaryMathBooleanResult(
328 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
329 TIntermTyped *addAssign(
330 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuaho49300862015-02-20 14:54:49 +0200331
Olli Etuaho0b2d2dc2015-11-04 16:35:32 +0200332 TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
333
Olli Etuaho49300862015-02-20 14:54:49 +0200334 TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc);
335 TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +0200336
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200337 void checkTextureOffsetConst(TIntermAggregate *functionCall);
Jamie Madill06145232015-05-13 13:10:01 -0400338 TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall,
339 TIntermNode *paramNode,
340 TIntermNode *thisNode,
341 const TSourceLoc &loc,
342 bool *fatalError);
Olli Etuahofc1806e2015-03-17 13:03:11 +0200343
Jamie Madill06145232015-05-13 13:10:01 -0400344 TIntermTyped *addTernarySelection(
345 TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock, const TSourceLoc &line);
Olli Etuaho52901742015-04-15 13:42:45 +0300346
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400347 // TODO(jmadill): make these private
348 TIntermediate &intermediate; // to hold and build a parse tree
349 TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed
350
Olli Etuahofc1806e2015-03-17 13:03:11 +0200351 private:
Olli Etuaho90892fb2016-07-14 14:44:51 +0300352 // Returns a clamped index.
353 int checkIndexOutOfRange(bool outOfRangeIndexIsError,
354 const TSourceLoc &location,
355 int index,
356 int arraySize,
357 const char *reason,
358 const char *token);
359
360 // Constant folding for element access. Note that the returned node does not have the correct
361 // type - it is expected to be fixed later.
362 TIntermConstantUnion *foldVectorSwizzle(TVectorFields &fields,
363 TIntermConstantUnion *baseNode,
364 const TSourceLoc &location);
365 TIntermConstantUnion *foldMatrixSubscript(int index,
366 TIntermConstantUnion *baseNode,
367 const TSourceLoc &location);
368 TIntermConstantUnion *foldArraySubscript(int index,
369 TIntermConstantUnion *baseNode,
370 const TSourceLoc &location);
371
Olli Etuaho2935c582015-04-08 14:32:06 +0300372 bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable);
373
Olli Etuaho376f1b52015-04-13 13:23:41 +0300374 bool nonInitErrorCheck(const TSourceLoc &line, const TString &identifier, TPublicType *type);
375
Jamie Madill06145232015-05-13 13:10:01 -0400376 TIntermTyped *addBinaryMathInternal(
377 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
378 TIntermTyped *createAssign(
379 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuahof6c694b2015-03-26 14:50:53 +0200380 // The funcReturnType parameter is expected to be non-null when the operation is a built-in function.
381 // It is expected to be null for other unary operators.
Jamie Madill06145232015-05-13 13:10:01 -0400382 TIntermTyped *createUnaryMath(
383 TOperator op, TIntermTyped *child, const TSourceLoc &loc, const TType *funcReturnType);
Olli Etuahod6b14282015-03-17 14:31:35 +0200384
Olli Etuaho47fd36a2015-03-19 14:22:24 +0200385 // Return true if the checks pass
Jamie Madill06145232015-05-13 13:10:01 -0400386 bool binaryOpCommonCheck(
387 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuahofa33d582015-04-09 14:33:12 +0300388
389 // Set to true when the last/current declarator list was started with an empty declaration.
390 bool mDeferredSingleDeclarationErrorCheck;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400391
392 sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
393 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
394 int mShaderVersion;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400395 TIntermNode *mTreeRoot; // root of parse tree being created
396 int mLoopNestingLevel; // 0 if outside all loops
397 int mStructNestingLevel; // incremented while parsing a struct declaration
398 int mSwitchNestingLevel; // 0 if outside all switch statements
399 const TType *mCurrentFunctionType; // the return type of the function that's currently being parsed
400 bool mFunctionReturnsValue; // true if a non-void function has a return
401 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 +0300402 bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling
403 // ESSL1.
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400404 TLayoutMatrixPacking mDefaultMatrixPacking;
405 TLayoutBlockStorage mDefaultBlockStorage;
406 TString mHashErrMsg;
407 TDiagnostics mDiagnostics;
408 TDirectiveHandler mDirectiveHandler;
409 pp::Preprocessor mPreprocessor;
410 void *mScanner;
Jamie Madill14e95b32015-05-07 10:10:41 -0400411 bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
412 bool mUsesFragColor;
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +0300413 bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or
414 // gl_Secondary FragColor or both.
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200415 int mMinProgramTexelOffset;
416 int mMaxProgramTexelOffset;
Martin Radev802abe02016-08-04 17:48:32 +0300417
418 // keep track of local group size declared in layout. It should be declared only once.
419 bool mComputeShaderLocalSizeDeclared;
420 TLocalSize mComputeShaderLocalSize;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000421};
422
Jamie Madill06145232015-05-13 13:10:01 -0400423int PaParseStrings(
424 size_t count, const char *const string[], const int length[], TParseContext *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000425
Geoff Lang0a73dd82014-11-19 16:18:08 -0500426#endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_