blob: da7c42047ac68a0208d9b125160e700c74efe533 [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,
60 resources.WEBGL_debug_shader_precision == 1),
Jamie Madill6e06b1f2015-05-14 10:01:17 -040061 mPreprocessor(&mDiagnostics, &mDirectiveHandler),
62 mScanner(nullptr),
Jamie Madill14e95b32015-05-07 10:10:41 -040063 mUsesFragData(false),
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +030064 mUsesFragColor(false),
Olli Etuahoe1a94c62015-11-16 17:35:25 +020065 mUsesSecondaryOutputs(false),
66 mMinProgramTexelOffset(resources.MinProgramTexelOffset),
67 mMaxProgramTexelOffset(resources.MaxProgramTexelOffset)
Olli Etuahofa33d582015-04-09 14:33:12 +030068 {
69 }
Jamie Madill06145232015-05-13 13:10:01 -040070
Jamie Madill6e06b1f2015-05-14 10:01:17 -040071 const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
72 pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
73 void *getScanner() const { return mScanner; }
74 void setScanner(void *scanner) { mScanner = scanner; }
75 int getShaderVersion() const { return mShaderVersion; }
76 sh::GLenum getShaderType() const { return mShaderType; }
77 ShShaderSpec getShaderSpec() const { return mShaderSpec; }
78 int numErrors() const { return mDiagnostics.numErrors(); }
79 TInfoSink &infoSink() { return mDiagnostics.infoSink(); }
Jamie Madill06145232015-05-13 13:10:01 -040080 void error(const TSourceLoc &loc, const char *reason, const char *token,
81 const char *extraInfo="");
82 void warning(const TSourceLoc &loc, const char *reason, const char *token,
83 const char *extraInfo="");
Jamie Madill14e95b32015-05-07 10:10:41 -040084
Olli Etuaho7c3848e2015-11-04 13:19:17 +020085 // If isError is false, a warning will be reported instead.
86 void outOfRangeError(bool isError,
87 const TSourceLoc &loc,
88 const char *reason,
89 const char *token,
90 const char *extraInfo = "");
91
daniel@transgaming.com0578f812010-05-17 09:58:39 +000092 void recover();
Jamie Madill6e06b1f2015-05-14 10:01:17 -040093 TIntermNode *getTreeRoot() const { return mTreeRoot; }
94 void setTreeRoot(TIntermNode *treeRoot) { mTreeRoot = treeRoot; }
95
Olli Etuahoa6996682015-10-12 14:32:30 +030096 bool getFragmentPrecisionHigh() const
Jamie Madill6e06b1f2015-05-14 10:01:17 -040097 {
Olli Etuahoa6996682015-10-12 14:32:30 +030098 return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300;
99 }
100 void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh)
101 {
102 mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400103 }
104
105 bool getFunctionReturnsValue() const { return mFunctionReturnsValue; }
106 void setFunctionReturnsValue(bool functionReturnsValue)
107 {
108 mFunctionReturnsValue = functionReturnsValue;
109 }
110
111 void setLoopNestingLevel(int loopNestintLevel)
112 {
113 mLoopNestingLevel = loopNestintLevel;
114 }
115
116 const TType *getCurrentFunctionType() const { return mCurrentFunctionType; }
117 void setCurrentFunctionType(const TType *currentFunctionType)
118 {
119 mCurrentFunctionType = currentFunctionType;
120 }
121
122 void incrLoopNestingLevel() { ++mLoopNestingLevel; }
123 void decrLoopNestingLevel() { --mLoopNestingLevel; }
124
125 void incrSwitchNestingLevel() { ++mSwitchNestingLevel; }
126 void decrSwitchNestingLevel() { --mSwitchNestingLevel; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000127
Jamie Madill5c097022014-08-20 16:38:32 -0400128 // This method is guaranteed to succeed, even if no variable with 'name' exists.
129 const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol);
Olli Etuaho82c29ed2015-11-03 13:06:54 +0200130 TIntermTyped *parseVariableIdentifier(const TSourceLoc &location,
131 const TString *name,
132 const TSymbol *symbol);
Jamie Madill5c097022014-08-20 16:38:32 -0400133
Jamie Madill06145232015-05-13 13:10:01 -0400134 bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc &line);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000135
Jamie Madill06145232015-05-13 13:10:01 -0400136 bool reservedErrorCheck(const TSourceLoc &line, const TString &identifier);
137 void assignError(const TSourceLoc &line, const char *op, TString left, TString right);
138 void unaryOpError(const TSourceLoc &line, const char *op, TString operand);
139 void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right);
140 bool precisionErrorCheck(const TSourceLoc &line, TPrecision precision, TBasicType type);
141 bool lValueErrorCheck(const TSourceLoc &line, const char *op, TIntermTyped*);
142 bool constErrorCheck(TIntermTyped *node);
143 bool integerErrorCheck(TIntermTyped *node, const char *token);
144 bool globalErrorCheck(const TSourceLoc &line, bool global, const char *token);
Olli Etuaho15c2ac32015-11-09 15:51:43 +0200145 bool constructorErrorCheck(const TSourceLoc &line,
146 TIntermNode *argumentsNode,
147 TFunction &function,
148 TOperator op,
149 TType *type);
Jamie Madill06145232015-05-13 13:10:01 -0400150 bool arraySizeErrorCheck(const TSourceLoc &line, TIntermTyped *expr, int &size);
Olli Etuaho3739d232015-04-08 12:23:44 +0300151 bool arrayQualifierErrorCheck(const TSourceLoc &line, const TPublicType &type);
Jamie Madill06145232015-05-13 13:10:01 -0400152 bool arrayTypeErrorCheck(const TSourceLoc &line, const TPublicType &type);
Olli Etuaho6ed7bbe2015-04-07 18:08:46 +0300153 bool voidErrorCheck(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
Jamie Madill075edd82013-07-08 13:30:19 -0400154 bool boolErrorCheck(const TSourceLoc&, const TIntermTyped*);
155 bool boolErrorCheck(const TSourceLoc&, const TPublicType&);
Jamie Madill06145232015-05-13 13:10:01 -0400156 bool samplerErrorCheck(const TSourceLoc &line, const TPublicType &pType, const char *reason);
157 bool locationDeclaratorListCheck(const TSourceLoc &line, const TPublicType &pType);
158 bool parameterSamplerErrorCheck(const TSourceLoc &line, TQualifier qualifier, const TType &type);
159 bool paramErrorCheck(const TSourceLoc &line, TQualifier qualifier, TQualifier paramQualifier, TType *type);
160 bool extensionErrorCheck(const TSourceLoc &line, const TString&);
161 bool singleDeclarationErrorCheck(const TPublicType &publicType, const TSourceLoc &identifierLocation);
162 bool layoutLocationErrorCheck(const TSourceLoc &location, const TLayoutQualifier &layoutQualifier);
Olli Etuahob6e07a62015-02-16 12:22:10 +0200163 bool functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *);
Olli Etuaho37ad4742015-04-27 13:18:50 +0300164 void es3InvariantErrorCheck(const TQualifier qualifier, const TSourceLoc &invariantLocation);
Olli Etuahocc36b982015-07-10 14:14:18 +0300165 void es3InputOutputTypeCheck(const TQualifier qualifier,
166 const TPublicType &type,
167 const TSourceLoc &qualifierLocation);
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000168
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400169 const TPragma &pragma() const { return mDirectiveHandler.pragma(); }
170 const TExtensionBehavior &extensionBehavior() const { return mDirectiveHandler.extensionBehavior(); }
Jamie Madill06145232015-05-13 13:10:01 -0400171 bool supportsExtension(const char *extension);
172 bool isExtensionEnabled(const char *extension) const;
173 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
174 void handlePragmaDirective(const TSourceLoc &loc, const char *name, const char *value, bool stdgl);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000175
Jamie Madill06145232015-05-13 13:10:01 -0400176 bool containsSampler(const TType &type);
Jamie Madill06145232015-05-13 13:10:01 -0400177 const TFunction* findFunction(
178 const TSourceLoc &line, TFunction *pfnCall, int inputShaderVersion, bool *builtIn = 0);
179 bool executeInitializer(const TSourceLoc &line,
180 const TString &identifier,
181 const TPublicType &pType,
182 TIntermTyped *initializer,
183 TIntermNode **intermNode);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000184
Jamie Madill06145232015-05-13 13:10:01 -0400185 TPublicType addFullySpecifiedType(TQualifier qualifier,
186 bool invariant,
187 TLayoutQualifier layoutQualifier,
188 const TPublicType &typeSpecifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200189
Olli Etuahofa33d582015-04-09 14:33:12 +0300190 TIntermAggregate *parseSingleDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400191 const TSourceLoc &identifierOrTypeLocation,
192 const TString &identifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200193 TIntermAggregate *parseSingleArrayDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400194 const TSourceLoc &identifierLocation,
195 const TString &identifier,
196 const TSourceLoc &indexLocation,
197 TIntermTyped *indexExpression);
198 TIntermAggregate *parseSingleInitDeclaration(const TPublicType &publicType,
199 const TSourceLoc &identifierLocation,
200 const TString &identifier,
201 const TSourceLoc &initLocation,
202 TIntermTyped *initializer);
Jamie Madill47e3ec02014-08-20 16:38:33 -0400203
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300204 // Parse a declaration like "type a[n] = initializer"
205 // Note that this does not apply to declarations like "type[n] a = initializer"
206 TIntermAggregate *parseSingleArrayInitDeclaration(TPublicType &publicType,
Jamie Madill06145232015-05-13 13:10:01 -0400207 const TSourceLoc &identifierLocation,
208 const TString &identifier,
209 const TSourceLoc &indexLocation,
210 TIntermTyped *indexExpression,
211 const TSourceLoc &initLocation,
212 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300213
Jamie Madill06145232015-05-13 13:10:01 -0400214 TIntermAggregate *parseInvariantDeclaration(const TSourceLoc &invariantLoc,
215 const TSourceLoc &identifierLoc,
216 const TString *identifier,
217 const TSymbol *symbol);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200218
Jamie Madill06145232015-05-13 13:10:01 -0400219 TIntermAggregate *parseDeclarator(TPublicType &publicType,
220 TIntermAggregate *aggregateDeclaration,
221 const TSourceLoc &identifierLocation,
222 const TString &identifier);
223 TIntermAggregate *parseArrayDeclarator(TPublicType &publicType,
224 TIntermAggregate *aggregateDeclaration,
225 const TSourceLoc &identifierLocation,
226 const TString &identifier,
227 const TSourceLoc &arrayLocation,
228 TIntermTyped *indexExpression);
229 TIntermAggregate *parseInitDeclarator(const TPublicType &publicType,
230 TIntermAggregate *aggregateDeclaration,
231 const TSourceLoc &identifierLocation,
232 const TString &identifier,
233 const TSourceLoc &initLocation,
234 TIntermTyped *initializer);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200235
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300236 // Parse a declarator like "a[n] = initializer"
Jamie Madill06145232015-05-13 13:10:01 -0400237 TIntermAggregate *parseArrayInitDeclarator(const TPublicType &publicType,
238 TIntermAggregate *aggregateDeclaration,
239 const TSourceLoc &identifierLocation,
240 const TString &identifier,
241 const TSourceLoc &indexLocation,
242 TIntermTyped *indexExpression,
243 const TSourceLoc &initLocation,
244 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300245
Jamie Madilla295edf2013-06-06 11:56:48 -0400246 void parseGlobalLayoutQualifier(const TPublicType &typeQualifier);
Jamie Madill185fb402015-06-12 15:48:48 -0400247 void parseFunctionPrototype(const TSourceLoc &location,
248 TFunction *function,
249 TIntermAggregate **aggregateOut);
250 TFunction *parseFunctionDeclarator(const TSourceLoc &location,
251 TFunction *function);
Jamie Madill06145232015-05-13 13:10:01 -0400252 TFunction *addConstructorFunc(const TPublicType &publicType);
253 TIntermTyped *addConstructor(TIntermNode *arguments,
254 TType *type,
255 TOperator op,
256 TFunction *fnCall,
257 const TSourceLoc &line);
Olli Etuaho7c3848e2015-11-04 13:19:17 +0200258 TIntermTyped *addConstVectorNode(TVectorFields &fields,
259 TIntermConstantUnion *node,
260 const TSourceLoc &line,
261 bool outOfRangeIndexIsError);
262 TIntermTyped *addConstMatrixNode(int index,
263 TIntermConstantUnion *node,
264 const TSourceLoc &line,
265 bool outOfRangeIndexIsError);
266 TIntermTyped *addConstArrayNode(int index,
267 TIntermConstantUnion *node,
268 const TSourceLoc &line,
269 bool outOfRangeIndexIsError);
Jamie Madill06145232015-05-13 13:10:01 -0400270 TIntermTyped *addConstStruct(
271 const TString &identifier, TIntermTyped *node, const TSourceLoc& line);
272 TIntermTyped *addIndexExpression(TIntermTyped *baseExpression,
273 const TSourceLoc& location,
274 TIntermTyped *indexExpression);
275 TIntermTyped* addFieldSelectionExpression(TIntermTyped *baseExpression,
276 const TSourceLoc &dotLocation,
277 const TString &fieldString,
278 const TSourceLoc &fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +0000279
Jamie Madill06145232015-05-13 13:10:01 -0400280 TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList);
281 TPublicType addStructure(const TSourceLoc &structLine,
282 const TSourceLoc &nameLine,
283 const TString *structName,
284 TFieldList *fieldList);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000285
Jamie Madill06145232015-05-13 13:10:01 -0400286 TIntermAggregate* addInterfaceBlock(const TPublicType &typeQualifier,
287 const TSourceLoc &nameLine,
288 const TString &blockName,
289 TFieldList *fieldList,
290 const TString *instanceName,
291 const TSourceLoc &instanceLine,
292 TIntermTyped *arrayIndex,
293 const TSourceLoc& arrayIndexLine);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000294
Jamie Madill06145232015-05-13 13:10:01 -0400295 TLayoutQualifier parseLayoutQualifier(
296 const TString &qualifierType, const TSourceLoc &qualifierTypeLine);
297 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
298 const TSourceLoc &qualifierTypeLine,
299 const TString &intValueString,
300 int intValue,
301 const TSourceLoc &intValueLine);
Jamie Madilla5efff92013-06-06 11:56:47 -0400302 TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier, TLayoutQualifier rightQualifier);
Jamie Madillf2e0f9b2013-08-26 16:39:42 -0400303 TPublicType joinInterpolationQualifiers(const TSourceLoc &interpolationLoc, TQualifier interpolationQualifier,
304 const TSourceLoc &storageLoc, TQualifier storageQualifier);
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000305
kbr@chromium.org476541f2011-10-27 21:14:51 +0000306 // Performs an error check for embedded struct declarations.
307 // Returns true if an error was raised due to the declaration of
308 // this struct.
Jamie Madill06145232015-05-13 13:10:01 -0400309 bool enterStructDeclaration(const TSourceLoc &line, const TString &identifier);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000310 void exitStructDeclaration();
311
Jamie Madill06145232015-05-13 13:10:01 -0400312 bool structNestingErrorCheck(const TSourceLoc &line, const TField &field);
Olli Etuaho09b22472015-02-11 11:47:26 +0200313
Olli Etuahoa3a36662015-02-17 13:46:51 +0200314 TIntermSwitch *addSwitch(TIntermTyped *init, TIntermAggregate *statementList, const TSourceLoc &loc);
315 TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc);
316 TIntermCase *addDefault(const TSourceLoc &loc);
317
Jamie Madill06145232015-05-13 13:10:01 -0400318 TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
319 TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
320 TIntermTyped *addBinaryMath(
321 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
322 TIntermTyped *addBinaryMathBooleanResult(
323 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
324 TIntermTyped *addAssign(
325 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuaho49300862015-02-20 14:54:49 +0200326
Olli Etuaho0b2d2dc2015-11-04 16:35:32 +0200327 TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
328
Olli Etuaho49300862015-02-20 14:54:49 +0200329 TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc);
330 TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +0200331
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200332 void checkTextureOffsetConst(TIntermAggregate *functionCall);
Jamie Madill06145232015-05-13 13:10:01 -0400333 TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall,
334 TIntermNode *paramNode,
335 TIntermNode *thisNode,
336 const TSourceLoc &loc,
337 bool *fatalError);
Olli Etuahofc1806e2015-03-17 13:03:11 +0200338
Jamie Madill06145232015-05-13 13:10:01 -0400339 TIntermTyped *addTernarySelection(
340 TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock, const TSourceLoc &line);
Olli Etuaho52901742015-04-15 13:42:45 +0300341
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400342 // TODO(jmadill): make these private
343 TIntermediate &intermediate; // to hold and build a parse tree
344 TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed
345
Olli Etuahofc1806e2015-03-17 13:03:11 +0200346 private:
Olli Etuaho2935c582015-04-08 14:32:06 +0300347 bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable);
348
Olli Etuaho376f1b52015-04-13 13:23:41 +0300349 bool nonInitErrorCheck(const TSourceLoc &line, const TString &identifier, TPublicType *type);
350
Jamie Madill06145232015-05-13 13:10:01 -0400351 TIntermTyped *addBinaryMathInternal(
352 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
353 TIntermTyped *createAssign(
354 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuahof6c694b2015-03-26 14:50:53 +0200355 // The funcReturnType parameter is expected to be non-null when the operation is a built-in function.
356 // It is expected to be null for other unary operators.
Jamie Madill06145232015-05-13 13:10:01 -0400357 TIntermTyped *createUnaryMath(
358 TOperator op, TIntermTyped *child, const TSourceLoc &loc, const TType *funcReturnType);
Olli Etuahod6b14282015-03-17 14:31:35 +0200359
Olli Etuaho47fd36a2015-03-19 14:22:24 +0200360 // Return true if the checks pass
Jamie Madill06145232015-05-13 13:10:01 -0400361 bool binaryOpCommonCheck(
362 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
Olli Etuahofa33d582015-04-09 14:33:12 +0300363
364 // Set to true when the last/current declarator list was started with an empty declaration.
365 bool mDeferredSingleDeclarationErrorCheck;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400366
367 sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
368 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
369 int mShaderVersion;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400370 TIntermNode *mTreeRoot; // root of parse tree being created
371 int mLoopNestingLevel; // 0 if outside all loops
372 int mStructNestingLevel; // incremented while parsing a struct declaration
373 int mSwitchNestingLevel; // 0 if outside all switch statements
374 const TType *mCurrentFunctionType; // the return type of the function that's currently being parsed
375 bool mFunctionReturnsValue; // true if a non-void function has a return
376 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 +0300377 bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling
378 // ESSL1.
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400379 TLayoutMatrixPacking mDefaultMatrixPacking;
380 TLayoutBlockStorage mDefaultBlockStorage;
381 TString mHashErrMsg;
382 TDiagnostics mDiagnostics;
383 TDirectiveHandler mDirectiveHandler;
384 pp::Preprocessor mPreprocessor;
385 void *mScanner;
Jamie Madill14e95b32015-05-07 10:10:41 -0400386 bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
387 bool mUsesFragColor;
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +0300388 bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or
389 // gl_Secondary FragColor or both.
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200390 int mMinProgramTexelOffset;
391 int mMaxProgramTexelOffset;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000392};
393
Jamie Madill06145232015-05-13 13:10:01 -0400394int PaParseStrings(
395 size_t count, const char *const string[], const int length[], TParseContext *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000396
Geoff Lang0a73dd82014-11-19 16:18:08 -0500397#endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_