blob: 626f335e892392bffaebaa7fae8aaa8d80873fb7 [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,
Olli Etuaho77ba4082016-12-16 12:01:18 +000041 TDiagnostics *diagnostics,
Jamie Madillacb4b812016-11-07 13:50:29 -050042 const ShBuiltInResources &resources);
jchen104cdac9e2017-05-08 11:01:20 +080043 ~TParseContext();
Jamie Madill06145232015-05-13 13:10:01 -040044
Jamie Madill6e06b1f2015-05-14 10:01:17 -040045 const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
46 pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
47 void *getScanner() const { return mScanner; }
48 void setScanner(void *scanner) { mScanner = scanner; }
49 int getShaderVersion() const { return mShaderVersion; }
50 sh::GLenum getShaderType() const { return mShaderType; }
51 ShShaderSpec getShaderSpec() const { return mShaderSpec; }
Olli Etuaho77ba4082016-12-16 12:01:18 +000052 int numErrors() const { return mDiagnostics->numErrors(); }
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
Olli Etuaho09b04a22016-12-15 13:30:26 +000085 int getNumViews() const { return mNumViews; }
86
Martin Radev70866b82016-07-22 15:27:42 +030087 void enterFunctionDeclaration() { mDeclaringFunction = true; }
88
89 void exitFunctionDeclaration() { mDeclaringFunction = false; }
90
91 bool declaringFunction() const { return mDeclaringFunction; }
92
Jamie Madill5c097022014-08-20 16:38:32 -040093 // This method is guaranteed to succeed, even if no variable with 'name' exists.
Jamie Madilld7b1ab52016-12-12 14:42:19 -050094 const TVariable *getNamedVariable(const TSourceLoc &location,
95 const TString *name,
96 const TSymbol *symbol);
Olli Etuaho82c29ed2015-11-03 13:06:54 +020097 TIntermTyped *parseVariableIdentifier(const TSourceLoc &location,
98 const TString *name,
99 const TSymbol *symbol);
Jamie Madill5c097022014-08-20 16:38:32 -0400100
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500101 bool parseVectorFields(const TString &, int vecSize, TVectorFields &, const TSourceLoc &line);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000102
Jamie Madill06145232015-05-13 13:10:01 -0400103 void assignError(const TSourceLoc &line, const char *op, TString left, TString right);
104 void unaryOpError(const TSourceLoc &line, const char *op, TString operand);
105 void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right);
Olli Etuaho856c4972016-08-08 11:38:39 +0300106
Olli Etuaho8a176262016-08-16 14:23:01 +0300107 // Check functions - the ones that return bool return false if an error was generated.
108
Olli Etuaho856c4972016-08-08 11:38:39 +0300109 bool checkIsNotReserved(const TSourceLoc &line, const TString &identifier);
110 void checkPrecisionSpecified(const TSourceLoc &line, TPrecision precision, TBasicType type);
111 bool checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node);
112 void checkIsConst(TIntermTyped *node);
113 void checkIsScalarInteger(TIntermTyped *node, const char *token);
Qiankun Miaof69682b2016-08-16 14:50:42 +0800114 bool checkIsAtGlobalLevel(const TSourceLoc &line, const char *token);
Olli Etuaho856c4972016-08-08 11:38:39 +0300115 bool checkConstructorArguments(const TSourceLoc &line,
Olli Etuahoaf6fc1b2017-01-26 17:45:35 -0800116 const TIntermSequence *arguments,
Olli Etuaho856c4972016-08-08 11:38:39 +0300117 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);
jchen10cc2a10e2017-05-03 14:05:12 +0800126 bool checkIsNotOpaqueType(const TSourceLoc &line,
127 const TTypeSpecifierNonArray &pType,
128 const char *reason);
Olli Etuaho856c4972016-08-08 11:38:39 +0300129 void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType);
130 void checkLocationIsNotSpecified(const TSourceLoc &location,
131 const TLayoutQualifier &layoutQualifier);
Olli Etuaho856c4972016-08-08 11:38:39 +0300132 void checkIsParameterQualifierValid(const TSourceLoc &line,
Martin Radev70866b82016-07-22 15:27:42 +0300133 const TTypeQualifierBuilder &typeQualifierBuilder,
Olli Etuaho856c4972016-08-08 11:38:39 +0300134 TType *type);
135 bool checkCanUseExtension(const TSourceLoc &line, const TString &extension);
Olli Etuahobb7e5a72017-04-24 10:16:44 +0300136
137 // Done for all declarations, whether empty or not.
138 void declarationQualifierErrorCheck(const sh::TQualifier qualifier,
139 const sh::TLayoutQualifier &layoutQualifier,
140 const TSourceLoc &location);
141 // Done for the first non-empty declarator in a declaration.
142 void nonEmptyDeclarationErrorCheck(const TPublicType &publicType,
143 const TSourceLoc &identifierLocation);
144 // Done only for empty declarations.
Martin Radevb8b01222016-11-20 23:25:53 +0200145 void emptyDeclarationErrorCheck(const TPublicType &publicType, const TSourceLoc &location);
Olli Etuahobb7e5a72017-04-24 10:16:44 +0300146
Olli Etuaho856c4972016-08-08 11:38:39 +0300147 void checkLayoutQualifierSupported(const TSourceLoc &location,
148 const TString &layoutQualifierName,
149 int versionRequired);
150 bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location,
151 const TLayoutQualifier &layoutQualifier);
Olli Etuaho856c4972016-08-08 11:38:39 +0300152 void functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall);
Martin Radev70866b82016-07-22 15:27:42 +0300153 void checkInvariantVariableQualifier(bool invariant,
154 const TQualifier qualifier,
155 const TSourceLoc &invariantLocation);
Olli Etuaho856c4972016-08-08 11:38:39 +0300156 void checkInputOutputTypeIsValidES3(const TQualifier qualifier,
157 const TPublicType &type,
158 const TSourceLoc &qualifierLocation);
Martin Radev2cc85b32016-08-05 16:22:53 +0300159 void checkLocalVariableConstStorageQualifier(const TQualifierWrapperBase &qualifier);
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400160 const TPragma &pragma() const { return mDirectiveHandler.pragma(); }
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500161 const TExtensionBehavior &extensionBehavior() const
162 {
163 return mDirectiveHandler.extensionBehavior();
164 }
Jamie Madill06145232015-05-13 13:10:01 -0400165 bool supportsExtension(const char *extension);
166 bool isExtensionEnabled(const char *extension) const;
Olli Etuaho95468d12017-05-04 11:14:34 +0300167 bool isMultiviewExtensionEnabled() const
168 {
169 return mMultiviewAvailable &&
170 (isExtensionEnabled("GL_OVR_multiview") || isExtensionEnabled("GL_OVR_multiview2"));
171 }
Jamie Madill06145232015-05-13 13:10:01 -0400172 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500173 void handlePragmaDirective(const TSourceLoc &loc,
174 const char *name,
175 const char *value,
176 bool stdgl);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000177
Jamie Madill06145232015-05-13 13:10:01 -0400178 bool executeInitializer(const TSourceLoc &line,
179 const TString &identifier,
180 const TPublicType &pType,
181 TIntermTyped *initializer,
Olli Etuaho13389b62016-10-16 11:48:18 +0100182 TIntermBinary **initNode);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000183
Olli Etuaho0e3aee32016-10-27 12:56:38 +0100184 void addFullySpecifiedType(TPublicType *typeSpecifier);
Martin Radev70866b82016-07-22 15:27:42 +0300185 TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400186 const TPublicType &typeSpecifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200187
Olli Etuaho13389b62016-10-16 11:48:18 +0100188 TIntermDeclaration *parseSingleDeclaration(TPublicType &publicType,
189 const TSourceLoc &identifierOrTypeLocation,
190 const TString &identifier);
191 TIntermDeclaration *parseSingleArrayDeclaration(TPublicType &publicType,
192 const TSourceLoc &identifierLocation,
193 const TString &identifier,
194 const TSourceLoc &indexLocation,
195 TIntermTyped *indexExpression);
196 TIntermDeclaration *parseSingleInitDeclaration(const TPublicType &publicType,
197 const TSourceLoc &identifierLocation,
198 const TString &identifier,
199 const TSourceLoc &initLocation,
200 TIntermTyped *initializer);
Jamie Madill47e3ec02014-08-20 16:38:33 -0400201
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300202 // Parse a declaration like "type a[n] = initializer"
203 // Note that this does not apply to declarations like "type[n] a = initializer"
Olli Etuaho13389b62016-10-16 11:48:18 +0100204 TIntermDeclaration *parseSingleArrayInitDeclaration(TPublicType &publicType,
205 const TSourceLoc &identifierLocation,
206 const TString &identifier,
207 const TSourceLoc &indexLocation,
208 TIntermTyped *indexExpression,
209 const TSourceLoc &initLocation,
210 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300211
Olli Etuahobf4e1b72016-12-09 11:30:15 +0000212 TIntermInvariantDeclaration *parseInvariantDeclaration(
213 const TTypeQualifierBuilder &typeQualifierBuilder,
214 const TSourceLoc &identifierLoc,
215 const TString *identifier,
216 const TSymbol *symbol);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200217
Olli Etuaho13389b62016-10-16 11:48:18 +0100218 void parseDeclarator(TPublicType &publicType,
219 const TSourceLoc &identifierLocation,
220 const TString &identifier,
221 TIntermDeclaration *declarationOut);
222 void parseArrayDeclarator(TPublicType &publicType,
223 const TSourceLoc &identifierLocation,
224 const TString &identifier,
225 const TSourceLoc &arrayLocation,
226 TIntermTyped *indexExpression,
227 TIntermDeclaration *declarationOut);
228 void parseInitDeclarator(const TPublicType &publicType,
229 const TSourceLoc &identifierLocation,
230 const TString &identifier,
231 const TSourceLoc &initLocation,
232 TIntermTyped *initializer,
233 TIntermDeclaration *declarationOut);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200234
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300235 // Parse a declarator like "a[n] = initializer"
Olli Etuaho13389b62016-10-16 11:48:18 +0100236 void parseArrayInitDeclarator(const TPublicType &publicType,
237 const TSourceLoc &identifierLocation,
238 const TString &identifier,
239 const TSourceLoc &indexLocation,
240 TIntermTyped *indexExpression,
241 const TSourceLoc &initLocation,
242 TIntermTyped *initializer,
243 TIntermDeclaration *declarationOut);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300244
Martin Radev70866b82016-07-22 15:27:42 +0300245 void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder);
Olli Etuaho16c745a2017-01-16 17:02:27 +0000246 TIntermFunctionPrototype *addFunctionPrototypeDeclaration(const TFunction &parsedFunction,
247 const TSourceLoc &location);
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000248 TIntermFunctionDefinition *addFunctionDefinition(TIntermFunctionPrototype *functionPrototype,
Olli Etuaho336b1472016-10-05 16:37:55 +0100249 TIntermBlock *functionBody,
250 const TSourceLoc &location);
Olli Etuaho476197f2016-10-11 13:59:08 +0100251 void parseFunctionDefinitionHeader(const TSourceLoc &location,
252 TFunction **function,
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000253 TIntermFunctionPrototype **prototypeOut);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500254 TFunction *parseFunctionDeclarator(const TSourceLoc &location, TFunction *function);
Olli Etuaho9de84a52016-06-14 17:36:01 +0300255 TFunction *parseFunctionHeader(const TPublicType &type,
256 const TString *name,
257 const TSourceLoc &location);
Jamie Madill06145232015-05-13 13:10:01 -0400258 TFunction *addConstructorFunc(const TPublicType &publicType);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300259
Jamie Madill06145232015-05-13 13:10:01 -0400260 TIntermTyped *addIndexExpression(TIntermTyped *baseExpression,
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500261 const TSourceLoc &location,
Jamie Madill06145232015-05-13 13:10:01 -0400262 TIntermTyped *indexExpression);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500263 TIntermTyped *addFieldSelectionExpression(TIntermTyped *baseExpression,
Jamie Madill06145232015-05-13 13:10:01 -0400264 const TSourceLoc &dotLocation,
265 const TString &fieldString,
266 const TSourceLoc &fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +0000267
Olli Etuaho4de340a2016-12-16 09:32:03 +0000268 TFieldList *combineStructFieldLists(TFieldList *processedFields,
269 const TFieldList *newlyAddedFields,
270 const TSourceLoc &location);
Martin Radev70866b82016-07-22 15:27:42 +0300271 TFieldList *addStructDeclaratorListWithQualifiers(
272 const TTypeQualifierBuilder &typeQualifierBuilder,
273 TPublicType *typeSpecifier,
274 TFieldList *fieldList);
Jamie Madill06145232015-05-13 13:10:01 -0400275 TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList);
Martin Radev4a9cd802016-09-01 16:51:51 +0300276 TTypeSpecifierNonArray addStructure(const TSourceLoc &structLine,
277 const TSourceLoc &nameLine,
278 const TString *structName,
279 TFieldList *fieldList);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000280
Olli Etuaho13389b62016-10-16 11:48:18 +0100281 TIntermDeclaration *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder,
282 const TSourceLoc &nameLine,
283 const TString &blockName,
284 TFieldList *fieldList,
285 const TString *instanceName,
286 const TSourceLoc &instanceLine,
287 TIntermTyped *arrayIndex,
288 const TSourceLoc &arrayIndexLine);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000289
Martin Radev802abe02016-08-04 17:48:32 +0300290 void parseLocalSize(const TString &qualifierType,
291 const TSourceLoc &qualifierTypeLine,
292 int intValue,
293 const TSourceLoc &intValueLine,
294 const std::string &intValueString,
295 size_t index,
Martin Radev4c4c8e72016-08-04 12:25:34 +0300296 sh::WorkGroupSize *localSize);
Olli Etuaho09b04a22016-12-15 13:30:26 +0000297 void parseNumViews(int intValue,
298 const TSourceLoc &intValueLine,
299 const std::string &intValueString,
300 int *numViews);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500301 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
302 const TSourceLoc &qualifierTypeLine);
Jamie Madill06145232015-05-13 13:10:01 -0400303 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
304 const TSourceLoc &qualifierTypeLine,
Jamie Madill06145232015-05-13 13:10:01 -0400305 int intValue,
306 const TSourceLoc &intValueLine);
Olli Etuaho613b9592016-09-05 12:05:53 +0300307 TTypeQualifierBuilder *createTypeQualifierBuilder(const TSourceLoc &loc);
Martin Radev802abe02016-08-04 17:48:32 +0300308 TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier,
309 TLayoutQualifier rightQualifier,
310 const TSourceLoc &rightQualifierLocation);
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000311
kbr@chromium.org476541f2011-10-27 21:14:51 +0000312 // Performs an error check for embedded struct declarations.
Olli Etuaho383b7912016-08-05 11:22:59 +0300313 void enterStructDeclaration(const TSourceLoc &line, const TString &identifier);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000314 void exitStructDeclaration();
315
Olli Etuaho8a176262016-08-16 14:23:01 +0300316 void checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field);
Olli Etuaho09b22472015-02-11 11:47:26 +0200317
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100318 TIntermSwitch *addSwitch(TIntermTyped *init,
319 TIntermBlock *statementList,
320 const TSourceLoc &loc);
Olli Etuahoa3a36662015-02-17 13:46:51 +0200321 TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc);
322 TIntermCase *addDefault(const TSourceLoc &loc);
323
Jamie Madill06145232015-05-13 13:10:01 -0400324 TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
325 TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500326 TIntermTyped *addBinaryMath(TOperator op,
327 TIntermTyped *left,
328 TIntermTyped *right,
329 const TSourceLoc &loc);
330 TIntermTyped *addBinaryMathBooleanResult(TOperator op,
331 TIntermTyped *left,
332 TIntermTyped *right,
333 const TSourceLoc &loc);
334 TIntermTyped *addAssign(TOperator op,
335 TIntermTyped *left,
336 TIntermTyped *right,
337 const TSourceLoc &loc);
Olli Etuaho49300862015-02-20 14:54:49 +0200338
Olli Etuaho0b2d2dc2015-11-04 16:35:32 +0200339 TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
340
Olli Etuaho49300862015-02-20 14:54:49 +0200341 TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc);
342 TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +0200343
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200344 void checkTextureOffsetConst(TIntermAggregate *functionCall);
Martin Radev2cc85b32016-08-05 16:22:53 +0300345 void checkImageMemoryAccessForBuiltinFunctions(TIntermAggregate *functionCall);
346 void checkImageMemoryAccessForUserDefinedFunctions(const TFunction *functionDefinition,
347 const TIntermAggregate *functionCall);
Olli Etuahoaf6fc1b2017-01-26 17:45:35 -0800348 TIntermSequence *createEmptyArgumentsList();
Olli Etuaho72d10202017-01-19 15:58:30 +0000349
Olli Etuahoaf6fc1b2017-01-26 17:45:35 -0800350 // fnCall is only storing the built-in op, and function name or constructor type. arguments
Olli Etuaho72d10202017-01-19 15:58:30 +0000351 // has the arguments.
Jamie Madill06145232015-05-13 13:10:01 -0400352 TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall,
Olli Etuahoaf6fc1b2017-01-26 17:45:35 -0800353 TIntermSequence *arguments,
Jamie Madill06145232015-05-13 13:10:01 -0400354 TIntermNode *thisNode,
Olli Etuaho72d10202017-01-19 15:58:30 +0000355 const TSourceLoc &loc);
Olli Etuahofc1806e2015-03-17 13:03:11 +0200356
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300357 TIntermTyped *addTernarySelection(TIntermTyped *cond,
358 TIntermTyped *trueExpression,
359 TIntermTyped *falseExpression,
360 const TSourceLoc &line);
Olli Etuaho52901742015-04-15 13:42:45 +0300361
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400362 // TODO(jmadill): make these private
Olli Etuahof119a262016-08-19 15:54:22 +0300363 TIntermediate intermediate; // to build a parse tree
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400364 TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed
365
Olli Etuahofc1806e2015-03-17 13:03:11 +0200366 private:
jchen104cdac9e2017-05-08 11:01:20 +0800367 class AtomicCounterBindingState;
368 constexpr static size_t kAtomicCounterSize = 4;
369 // UNIFORM_ARRAY_STRIDE for atomic counter arrays is an implementation-dependent value which
370 // can be queried after a program is linked according to ES 3.10 section 7.7.1. This is
371 // controversial with the offset inheritance as described in ESSL 3.10 section 4.4.6. Currently
372 // we treat it as always 4 in favour of the original interpretation in
373 // "ARB_shader_atomic_counters".
374 // TODO(jie.a.chen@intel.com): Double check this once the spec vagueness is resolved.
375 constexpr static size_t kAtomicCounterArrayStride = 4;
376
Olli Etuaho4de340a2016-12-16 09:32:03 +0000377 // Returns a clamped index. If it prints out an error message, the token is "[]".
Olli Etuaho90892fb2016-07-14 14:44:51 +0300378 int checkIndexOutOfRange(bool outOfRangeIndexIsError,
379 const TSourceLoc &location,
380 int index,
381 int arraySize,
Olli Etuaho4de340a2016-12-16 09:32:03 +0000382 const char *reason);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300383
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500384 bool declareVariable(const TSourceLoc &line,
385 const TString &identifier,
386 const TType &type,
387 TVariable **variable);
Olli Etuaho2935c582015-04-08 14:32:06 +0300388
Olli Etuaho856c4972016-08-08 11:38:39 +0300389 void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line,
390 const TString &identifier,
391 TPublicType *type);
Olli Etuaho376f1b52015-04-13 13:23:41 +0300392
Olli Etuaho8a176262016-08-16 14:23:01 +0300393 bool checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation,
394 const TPublicType &elementType);
jchen104cdac9e2017-05-08 11:01:20 +0800395 // Done for all atomic counter declarations, whether empty or not.
396 void atomicCounterQualifierErrorCheck(const TPublicType &publicType,
397 const TSourceLoc &location);
Olli Etuaho8a176262016-08-16 14:23:01 +0300398
Olli Etuaho1dded802016-08-18 18:13:13 +0300399 // Assumes that multiplication op has already been set based on the types.
400 bool isMultiplicationTypeCombinationValid(TOperator op, const TType &left, const TType &right);
401
Martin Radev2cc85b32016-08-05 16:22:53 +0300402 void checkOutParameterIsNotOpaqueType(const TSourceLoc &line,
403 TQualifier qualifier,
404 const TType &type);
Martin Radev2cc85b32016-08-05 16:22:53 +0300405
Olli Etuaho43364892017-02-13 16:00:12 +0000406 void checkInternalFormatIsNotSpecified(const TSourceLoc &location,
407 TLayoutImageInternalFormat internalFormat);
408 void checkMemoryQualifierIsNotSpecified(const TMemoryQualifier &memoryQualifier,
409 const TSourceLoc &location);
jchen104cdac9e2017-05-08 11:01:20 +0800410 void checkAtomicCounterOffsetIsNotOverlapped(TPublicType &publicType,
411 size_t size,
412 bool forceAppend,
413 const TSourceLoc &loc,
414 TType &type);
Olli Etuaho43364892017-02-13 16:00:12 +0000415 void checkBindingIsValid(const TSourceLoc &identifierLocation, const TType &type);
416 void checkBindingIsNotSpecified(const TSourceLoc &location, int binding);
jchen104cdac9e2017-05-08 11:01:20 +0800417 void checkOffsetIsNotSpecified(const TSourceLoc &location, int offset);
Olli Etuaho43364892017-02-13 16:00:12 +0000418 void checkImageBindingIsValid(const TSourceLoc &location, int binding, int arraySize);
419 void checkSamplerBindingIsValid(const TSourceLoc &location, int binding, int arraySize);
jchen10af713a22017-04-19 09:10:56 +0800420 void checkBlockBindingIsValid(const TSourceLoc &location, int binding, int arraySize);
jchen104cdac9e2017-05-08 11:01:20 +0800421 void checkAtomicCounterBindingIsValid(const TSourceLoc &location, int binding);
Olli Etuaho43364892017-02-13 16:00:12 +0000422
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000423 void checkUniformLocationInRange(const TSourceLoc &location,
424 int objectLocationCount,
425 const TLayoutQualifier &layoutQualifier);
426
Andrei Volykhina5527072017-03-22 16:46:30 +0300427 void checkYuvIsNotSpecified(const TSourceLoc &location, bool yuv);
428
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500429 TIntermTyped *addBinaryMathInternal(TOperator op,
430 TIntermTyped *left,
431 TIntermTyped *right,
432 const TSourceLoc &loc);
Olli Etuaho13389b62016-10-16 11:48:18 +0100433 TIntermBinary *createAssign(TOperator op,
434 TIntermTyped *left,
435 TIntermTyped *right,
436 const TSourceLoc &loc);
Olli Etuahoaf6fc1b2017-01-26 17:45:35 -0800437 TIntermTyped *createUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
438
439 TIntermTyped *addMethod(TFunction *fnCall,
440 TIntermSequence *arguments,
441 TIntermNode *thisNode,
442 const TSourceLoc &loc);
443 TIntermTyped *addConstructor(TIntermSequence *arguments,
Olli Etuahoaf6fc1b2017-01-26 17:45:35 -0800444 TType type,
445 const TSourceLoc &line);
446 TIntermTyped *addNonConstructorFunctionCall(TFunction *fnCall,
447 TIntermSequence *arguments,
448 const TSourceLoc &loc);
Olli Etuahod6b14282015-03-17 14:31:35 +0200449
Olli Etuaho47fd36a2015-03-19 14:22:24 +0200450 // Return true if the checks pass
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500451 bool binaryOpCommonCheck(TOperator op,
452 TIntermTyped *left,
453 TIntermTyped *right,
454 const TSourceLoc &loc);
Olli Etuahofa33d582015-04-09 14:33:12 +0300455
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000456 TIntermFunctionPrototype *createPrototypeNodeFromFunction(const TFunction &function,
457 const TSourceLoc &location,
458 bool insertParametersToSymbolTable);
459
jchen104cdac9e2017-05-08 11:01:20 +0800460 void setAtomicCounterBindingDefaultOffset(const TPublicType &declaration,
461 const TSourceLoc &location);
462
Olli Etuahobb7e5a72017-04-24 10:16:44 +0300463 // Set to true when the last/current declarator list was started with an empty declaration. The
464 // non-empty declaration error check will need to be performed if the empty declaration is
465 // followed by a declarator.
466 bool mDeferredNonEmptyDeclarationErrorCheck;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400467
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500468 sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800469 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
470 ShCompileOptions mCompileOptions; // Options passed to TCompiler
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400471 int mShaderVersion;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500472 TIntermBlock *mTreeRoot; // root of parse tree being created
473 int mLoopNestingLevel; // 0 if outside all loops
474 int mStructNestingLevel; // incremented while parsing a struct declaration
475 int mSwitchNestingLevel; // 0 if outside all switch statements
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800476 const TType
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500477 *mCurrentFunctionType; // the return type of the function that's currently being parsed
478 bool mFunctionReturnsValue; // true if a non-void function has a return
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800479 bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared
480 // without precision, explicit or implicit.
Olli Etuahoa6996682015-10-12 14:32:30 +0300481 bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling
482 // ESSL1.
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400483 TLayoutMatrixPacking mDefaultMatrixPacking;
484 TLayoutBlockStorage mDefaultBlockStorage;
485 TString mHashErrMsg;
Olli Etuaho77ba4082016-12-16 12:01:18 +0000486 TDiagnostics *mDiagnostics;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400487 TDirectiveHandler mDirectiveHandler;
488 pp::Preprocessor mPreprocessor;
489 void *mScanner;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500490 bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
Jamie Madill14e95b32015-05-07 10:10:41 -0400491 bool mUsesFragColor;
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +0300492 bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or
493 // gl_Secondary FragColor or both.
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200494 int mMinProgramTexelOffset;
495 int mMaxProgramTexelOffset;
Martin Radev802abe02016-08-04 17:48:32 +0300496
Olli Etuaho09b04a22016-12-15 13:30:26 +0000497 bool mMultiviewAvailable;
498
Martin Radev802abe02016-08-04 17:48:32 +0300499 // keep track of local group size declared in layout. It should be declared only once.
500 bool mComputeShaderLocalSizeDeclared;
Martin Radev4c4c8e72016-08-04 12:25:34 +0300501 sh::WorkGroupSize mComputeShaderLocalSize;
Olli Etuaho09b04a22016-12-15 13:30:26 +0000502 // keep track of number of views declared in layout.
503 int mNumViews;
504 int mMaxNumViews;
Olli Etuaho43364892017-02-13 16:00:12 +0000505 int mMaxImageUnits;
506 int mMaxCombinedTextureImageUnits;
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000507 int mMaxUniformLocations;
jchen10af713a22017-04-19 09:10:56 +0800508 int mMaxUniformBufferBindings;
jchen104cdac9e2017-05-08 11:01:20 +0800509 int mMaxAtomicCounterBindings;
510
Martin Radev70866b82016-07-22 15:27:42 +0300511 // keeps track whether we are declaring / defining a function
512 bool mDeclaringFunction;
jchen104cdac9e2017-05-08 11:01:20 +0800513
514 // Track the state of each atomic counter binding.
515 std::map<int, AtomicCounterBindingState> mAtomicCounterBindingStates;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000516};
517
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500518int PaParseStrings(size_t count,
519 const char *const string[],
520 const int length[],
521 TParseContext *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000522
Jamie Madill45bcc782016-11-07 13:58:48 -0500523} // namespace sh
524
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500525#endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_