blob: 8a8fbb5b88c38ae7fcbf81c47a84e6f0b92e129d [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);
Jamie Madill06145232015-05-13 13:10:01 -040043
Jamie Madill6e06b1f2015-05-14 10:01:17 -040044 const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; }
45 pp::Preprocessor &getPreprocessor() { return mPreprocessor; }
46 void *getScanner() const { return mScanner; }
47 void setScanner(void *scanner) { mScanner = scanner; }
48 int getShaderVersion() const { return mShaderVersion; }
49 sh::GLenum getShaderType() const { return mShaderType; }
50 ShShaderSpec getShaderSpec() const { return mShaderSpec; }
Olli Etuaho77ba4082016-12-16 12:01:18 +000051 int numErrors() const { return mDiagnostics->numErrors(); }
Olli Etuaho4de340a2016-12-16 09:32:03 +000052 void error(const TSourceLoc &loc, const char *reason, const char *token);
53 void warning(const TSourceLoc &loc, const char *reason, const char *token);
Jamie Madill14e95b32015-05-07 10:10:41 -040054
Olli Etuaho7c3848e2015-11-04 13:19:17 +020055 // If isError is false, a warning will be reported instead.
56 void outOfRangeError(bool isError,
57 const TSourceLoc &loc,
58 const char *reason,
Olli Etuaho4de340a2016-12-16 09:32:03 +000059 const char *token);
Olli Etuaho7c3848e2015-11-04 13:19:17 +020060
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010061 TIntermBlock *getTreeRoot() const { return mTreeRoot; }
62 void setTreeRoot(TIntermBlock *treeRoot) { mTreeRoot = treeRoot; }
Jamie Madill6e06b1f2015-05-14 10:01:17 -040063
Olli Etuahoa6996682015-10-12 14:32:30 +030064 bool getFragmentPrecisionHigh() const
Jamie Madill6e06b1f2015-05-14 10:01:17 -040065 {
Olli Etuahoa6996682015-10-12 14:32:30 +030066 return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300;
67 }
68 void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh)
69 {
70 mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh;
Jamie Madill6e06b1f2015-05-14 10:01:17 -040071 }
72
Jamie Madilld7b1ab52016-12-12 14:42:19 -050073 void setLoopNestingLevel(int loopNestintLevel) { mLoopNestingLevel = loopNestintLevel; }
Jamie Madill6e06b1f2015-05-14 10:01:17 -040074
Jamie Madill6e06b1f2015-05-14 10:01:17 -040075 void incrLoopNestingLevel() { ++mLoopNestingLevel; }
76 void decrLoopNestingLevel() { --mLoopNestingLevel; }
77
78 void incrSwitchNestingLevel() { ++mSwitchNestingLevel; }
79 void decrSwitchNestingLevel() { --mSwitchNestingLevel; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000080
Martin Radev802abe02016-08-04 17:48:32 +030081 bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; }
Martin Radev4c4c8e72016-08-04 12:25:34 +030082 sh::WorkGroupSize getComputeShaderLocalSize() const;
Martin Radev802abe02016-08-04 17:48:32 +030083
Olli Etuaho09b04a22016-12-15 13:30:26 +000084 int getNumViews() const { return mNumViews; }
85
Martin Radev70866b82016-07-22 15:27:42 +030086 void enterFunctionDeclaration() { mDeclaringFunction = true; }
87
88 void exitFunctionDeclaration() { mDeclaringFunction = false; }
89
90 bool declaringFunction() const { return mDeclaringFunction; }
91
Jamie Madill5c097022014-08-20 16:38:32 -040092 // This method is guaranteed to succeed, even if no variable with 'name' exists.
Jamie Madilld7b1ab52016-12-12 14:42:19 -050093 const TVariable *getNamedVariable(const TSourceLoc &location,
94 const TString *name,
95 const TSymbol *symbol);
Olli Etuaho82c29ed2015-11-03 13:06:54 +020096 TIntermTyped *parseVariableIdentifier(const TSourceLoc &location,
97 const TString *name,
98 const TSymbol *symbol);
Jamie Madill5c097022014-08-20 16:38:32 -040099
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500100 bool parseVectorFields(const TString &, int vecSize, TVectorFields &, const TSourceLoc &line);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000101
Jamie Madill06145232015-05-13 13:10:01 -0400102 void assignError(const TSourceLoc &line, const char *op, TString left, TString right);
103 void unaryOpError(const TSourceLoc &line, const char *op, TString operand);
104 void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right);
Olli Etuaho856c4972016-08-08 11:38:39 +0300105
Olli Etuaho8a176262016-08-16 14:23:01 +0300106 // Check functions - the ones that return bool return false if an error was generated.
107
Olli Etuaho856c4972016-08-08 11:38:39 +0300108 bool checkIsNotReserved(const TSourceLoc &line, const TString &identifier);
109 void checkPrecisionSpecified(const TSourceLoc &line, TPrecision precision, TBasicType type);
110 bool checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node);
111 void checkIsConst(TIntermTyped *node);
112 void checkIsScalarInteger(TIntermTyped *node, const char *token);
Qiankun Miaof69682b2016-08-16 14:50:42 +0800113 bool checkIsAtGlobalLevel(const TSourceLoc &line, const char *token);
Olli Etuaho856c4972016-08-08 11:38:39 +0300114 bool checkConstructorArguments(const TSourceLoc &line,
Olli Etuaho72d10202017-01-19 15:58:30 +0000115 const TIntermAggregate *argumentsNode,
Olli Etuaho856c4972016-08-08 11:38:39 +0300116 TOperator op,
117 const TType &type);
118
119 // Returns a sanitized array size to use (the size is at least 1).
120 unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr);
Olli Etuaho8a176262016-08-16 14:23:01 +0300121 bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &elementQualifier);
122 bool checkIsValidTypeForArray(const TSourceLoc &line, const TPublicType &elementType);
Olli Etuaho856c4972016-08-08 11:38:39 +0300123 bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
124 void checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type);
125 void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType);
Martin Radev4a9cd802016-09-01 16:51:51 +0300126 bool checkIsNotSampler(const TSourceLoc &line,
127 const TTypeSpecifierNonArray &pType,
128 const char *reason);
Martin Radev2cc85b32016-08-05 16:22:53 +0300129 bool checkIsNotImage(const TSourceLoc &line,
130 const TTypeSpecifierNonArray &pType,
131 const char *reason);
Olli Etuaho856c4972016-08-08 11:38:39 +0300132 void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType);
133 void checkLocationIsNotSpecified(const TSourceLoc &location,
134 const TLayoutQualifier &layoutQualifier);
Olli Etuaho856c4972016-08-08 11:38:39 +0300135 void checkIsParameterQualifierValid(const TSourceLoc &line,
Martin Radev70866b82016-07-22 15:27:42 +0300136 const TTypeQualifierBuilder &typeQualifierBuilder,
Olli Etuaho856c4972016-08-08 11:38:39 +0300137 TType *type);
138 bool checkCanUseExtension(const TSourceLoc &line, const TString &extension);
Olli Etuaho383b7912016-08-05 11:22:59 +0300139 void singleDeclarationErrorCheck(const TPublicType &publicType,
140 const TSourceLoc &identifierLocation);
Martin Radevb8b01222016-11-20 23:25:53 +0200141 void emptyDeclarationErrorCheck(const TPublicType &publicType, const TSourceLoc &location);
Olli Etuaho856c4972016-08-08 11:38:39 +0300142 void checkLayoutQualifierSupported(const TSourceLoc &location,
143 const TString &layoutQualifierName,
144 int versionRequired);
145 bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location,
146 const TLayoutQualifier &layoutQualifier);
Martin Radev2cc85b32016-08-05 16:22:53 +0300147 bool checkInternalFormatIsNotSpecified(const TSourceLoc &location,
148 TLayoutImageInternalFormat internalFormat);
Olli Etuaho856c4972016-08-08 11:38:39 +0300149 void functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall);
Martin Radev70866b82016-07-22 15:27:42 +0300150 void checkInvariantVariableQualifier(bool invariant,
151 const TQualifier qualifier,
152 const TSourceLoc &invariantLocation);
Olli Etuaho856c4972016-08-08 11:38:39 +0300153 void checkInputOutputTypeIsValidES3(const TQualifier qualifier,
154 const TPublicType &type,
155 const TSourceLoc &qualifierLocation);
Martin Radev2cc85b32016-08-05 16:22:53 +0300156 void checkLocalVariableConstStorageQualifier(const TQualifierWrapperBase &qualifier);
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400157 const TPragma &pragma() const { return mDirectiveHandler.pragma(); }
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500158 const TExtensionBehavior &extensionBehavior() const
159 {
160 return mDirectiveHandler.extensionBehavior();
161 }
Jamie Madill06145232015-05-13 13:10:01 -0400162 bool supportsExtension(const char *extension);
163 bool isExtensionEnabled(const char *extension) const;
164 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500165 void handlePragmaDirective(const TSourceLoc &loc,
166 const char *name,
167 const char *value,
168 bool stdgl);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000169
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500170 const TFunction *findFunction(const TSourceLoc &line,
171 TFunction *pfnCall,
172 int inputShaderVersion,
173 bool *builtIn = 0);
Jamie Madill06145232015-05-13 13:10:01 -0400174 bool executeInitializer(const TSourceLoc &line,
175 const TString &identifier,
176 const TPublicType &pType,
177 TIntermTyped *initializer,
Olli Etuaho13389b62016-10-16 11:48:18 +0100178 TIntermBinary **initNode);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000179
Olli Etuaho0e3aee32016-10-27 12:56:38 +0100180 void addFullySpecifiedType(TPublicType *typeSpecifier);
Martin Radev70866b82016-07-22 15:27:42 +0300181 TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400182 const TPublicType &typeSpecifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200183
Olli Etuaho13389b62016-10-16 11:48:18 +0100184 TIntermDeclaration *parseSingleDeclaration(TPublicType &publicType,
185 const TSourceLoc &identifierOrTypeLocation,
186 const TString &identifier);
187 TIntermDeclaration *parseSingleArrayDeclaration(TPublicType &publicType,
188 const TSourceLoc &identifierLocation,
189 const TString &identifier,
190 const TSourceLoc &indexLocation,
191 TIntermTyped *indexExpression);
192 TIntermDeclaration *parseSingleInitDeclaration(const TPublicType &publicType,
193 const TSourceLoc &identifierLocation,
194 const TString &identifier,
195 const TSourceLoc &initLocation,
196 TIntermTyped *initializer);
Jamie Madill47e3ec02014-08-20 16:38:33 -0400197
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300198 // Parse a declaration like "type a[n] = initializer"
199 // Note that this does not apply to declarations like "type[n] a = initializer"
Olli Etuaho13389b62016-10-16 11:48:18 +0100200 TIntermDeclaration *parseSingleArrayInitDeclaration(TPublicType &publicType,
201 const TSourceLoc &identifierLocation,
202 const TString &identifier,
203 const TSourceLoc &indexLocation,
204 TIntermTyped *indexExpression,
205 const TSourceLoc &initLocation,
206 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300207
Olli Etuahobf4e1b72016-12-09 11:30:15 +0000208 TIntermInvariantDeclaration *parseInvariantDeclaration(
209 const TTypeQualifierBuilder &typeQualifierBuilder,
210 const TSourceLoc &identifierLoc,
211 const TString *identifier,
212 const TSymbol *symbol);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200213
Olli Etuaho13389b62016-10-16 11:48:18 +0100214 void parseDeclarator(TPublicType &publicType,
215 const TSourceLoc &identifierLocation,
216 const TString &identifier,
217 TIntermDeclaration *declarationOut);
218 void parseArrayDeclarator(TPublicType &publicType,
219 const TSourceLoc &identifierLocation,
220 const TString &identifier,
221 const TSourceLoc &arrayLocation,
222 TIntermTyped *indexExpression,
223 TIntermDeclaration *declarationOut);
224 void parseInitDeclarator(const TPublicType &publicType,
225 const TSourceLoc &identifierLocation,
226 const TString &identifier,
227 const TSourceLoc &initLocation,
228 TIntermTyped *initializer,
229 TIntermDeclaration *declarationOut);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200230
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300231 // Parse a declarator like "a[n] = initializer"
Olli Etuaho13389b62016-10-16 11:48:18 +0100232 void parseArrayInitDeclarator(const TPublicType &publicType,
233 const TSourceLoc &identifierLocation,
234 const TString &identifier,
235 const TSourceLoc &indexLocation,
236 TIntermTyped *indexExpression,
237 const TSourceLoc &initLocation,
238 TIntermTyped *initializer,
239 TIntermDeclaration *declarationOut);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300240
Martin Radev70866b82016-07-22 15:27:42 +0300241 void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder);
Olli Etuaho16c745a2017-01-16 17:02:27 +0000242 TIntermFunctionPrototype *addFunctionPrototypeDeclaration(const TFunction &parsedFunction,
243 const TSourceLoc &location);
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000244 TIntermFunctionDefinition *addFunctionDefinition(TIntermFunctionPrototype *functionPrototype,
Olli Etuaho336b1472016-10-05 16:37:55 +0100245 TIntermBlock *functionBody,
246 const TSourceLoc &location);
Olli Etuaho476197f2016-10-11 13:59:08 +0100247 void parseFunctionDefinitionHeader(const TSourceLoc &location,
248 TFunction **function,
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000249 TIntermFunctionPrototype **prototypeOut);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500250 TFunction *parseFunctionDeclarator(const TSourceLoc &location, TFunction *function);
Olli Etuaho9de84a52016-06-14 17:36:01 +0300251 TFunction *parseFunctionHeader(const TPublicType &type,
252 const TString *name,
253 const TSourceLoc &location);
Jamie Madill06145232015-05-13 13:10:01 -0400254 TFunction *addConstructorFunc(const TPublicType &publicType);
Olli Etuaho72d10202017-01-19 15:58:30 +0000255 TIntermTyped *addConstructor(TIntermAggregate *arguments,
Jamie Madill06145232015-05-13 13:10:01 -0400256 TOperator op,
Olli Etuaho72d10202017-01-19 15:58:30 +0000257 TType type,
Jamie Madill06145232015-05-13 13:10:01 -0400258 const TSourceLoc &line);
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 Etuaho72d10202017-01-19 15:58:30 +0000348 TIntermAggregate *createEmptyArgumentsNode(const TSourceLoc &loc);
349
350 // fnCall is only storing the built-in op, and function name or constructor type. argumentsNode
351 // has the arguments.
Jamie Madill06145232015-05-13 13:10:01 -0400352 TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall,
Olli Etuaho72d10202017-01-19 15:58:30 +0000353 TIntermAggregate *argumentsNode,
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:
Olli Etuaho4de340a2016-12-16 09:32:03 +0000367 // Returns a clamped index. If it prints out an error message, the token is "[]".
Olli Etuaho90892fb2016-07-14 14:44:51 +0300368 int checkIndexOutOfRange(bool outOfRangeIndexIsError,
369 const TSourceLoc &location,
370 int index,
371 int arraySize,
Olli Etuaho4de340a2016-12-16 09:32:03 +0000372 const char *reason);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300373
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500374 bool declareVariable(const TSourceLoc &line,
375 const TString &identifier,
376 const TType &type,
377 TVariable **variable);
Olli Etuaho2935c582015-04-08 14:32:06 +0300378
Olli Etuaho856c4972016-08-08 11:38:39 +0300379 void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line,
380 const TString &identifier,
381 TPublicType *type);
Olli Etuaho376f1b52015-04-13 13:23:41 +0300382
Olli Etuaho8a176262016-08-16 14:23:01 +0300383 bool checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation,
384 const TPublicType &elementType);
385
Olli Etuaho1dded802016-08-18 18:13:13 +0300386 // Assumes that multiplication op has already been set based on the types.
387 bool isMultiplicationTypeCombinationValid(TOperator op, const TType &left, const TType &right);
388
Martin Radev2cc85b32016-08-05 16:22:53 +0300389 bool checkIsMemoryQualifierNotSpecified(const TMemoryQualifier &memoryQualifier,
390 const TSourceLoc &location);
391 void checkOutParameterIsNotImage(const TSourceLoc &line,
392 TQualifier qualifier,
393 const TType &type);
394 void checkOutParameterIsNotOpaqueType(const TSourceLoc &line,
395 TQualifier qualifier,
396 const TType &type);
397 void checkOutParameterIsNotSampler(const TSourceLoc &line,
398 TQualifier qualifier,
399 const TType &type);
400
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500401 TIntermTyped *addBinaryMathInternal(TOperator op,
402 TIntermTyped *left,
403 TIntermTyped *right,
404 const TSourceLoc &loc);
Olli Etuaho13389b62016-10-16 11:48:18 +0100405 TIntermBinary *createAssign(TOperator op,
406 TIntermTyped *left,
407 TIntermTyped *right,
408 const TSourceLoc &loc);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500409 TIntermTyped *createUnaryMath(TOperator op,
410 TIntermTyped *child,
Olli Etuaho2be2d5a2017-01-26 16:34:30 -0800411 const TSourceLoc &loc);
Olli Etuahod6b14282015-03-17 14:31:35 +0200412
Olli Etuaho47fd36a2015-03-19 14:22:24 +0200413 // Return true if the checks pass
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500414 bool binaryOpCommonCheck(TOperator op,
415 TIntermTyped *left,
416 TIntermTyped *right,
417 const TSourceLoc &loc);
Olli Etuahofa33d582015-04-09 14:33:12 +0300418
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000419 TIntermFunctionPrototype *createPrototypeNodeFromFunction(const TFunction &function,
420 const TSourceLoc &location,
421 bool insertParametersToSymbolTable);
422
Olli Etuahofa33d582015-04-09 14:33:12 +0300423 // Set to true when the last/current declarator list was started with an empty declaration.
424 bool mDeferredSingleDeclarationErrorCheck;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400425
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500426 sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800427 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
428 ShCompileOptions mCompileOptions; // Options passed to TCompiler
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400429 int mShaderVersion;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500430 TIntermBlock *mTreeRoot; // root of parse tree being created
431 int mLoopNestingLevel; // 0 if outside all loops
432 int mStructNestingLevel; // incremented while parsing a struct declaration
433 int mSwitchNestingLevel; // 0 if outside all switch statements
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800434 const TType
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500435 *mCurrentFunctionType; // the return type of the function that's currently being parsed
436 bool mFunctionReturnsValue; // true if a non-void function has a return
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800437 bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared
438 // without precision, explicit or implicit.
Olli Etuahoa6996682015-10-12 14:32:30 +0300439 bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling
440 // ESSL1.
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400441 TLayoutMatrixPacking mDefaultMatrixPacking;
442 TLayoutBlockStorage mDefaultBlockStorage;
443 TString mHashErrMsg;
Olli Etuaho77ba4082016-12-16 12:01:18 +0000444 TDiagnostics *mDiagnostics;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400445 TDirectiveHandler mDirectiveHandler;
446 pp::Preprocessor mPreprocessor;
447 void *mScanner;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500448 bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
Jamie Madill14e95b32015-05-07 10:10:41 -0400449 bool mUsesFragColor;
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +0300450 bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or
451 // gl_Secondary FragColor or both.
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200452 int mMinProgramTexelOffset;
453 int mMaxProgramTexelOffset;
Martin Radev802abe02016-08-04 17:48:32 +0300454
Olli Etuaho09b04a22016-12-15 13:30:26 +0000455 bool mMultiviewAvailable;
456
Martin Radev802abe02016-08-04 17:48:32 +0300457 // keep track of local group size declared in layout. It should be declared only once.
458 bool mComputeShaderLocalSizeDeclared;
Martin Radev4c4c8e72016-08-04 12:25:34 +0300459 sh::WorkGroupSize mComputeShaderLocalSize;
Olli Etuaho09b04a22016-12-15 13:30:26 +0000460 // keep track of number of views declared in layout.
461 int mNumViews;
462 int mMaxNumViews;
Martin Radev70866b82016-07-22 15:27:42 +0300463 // keeps track whether we are declaring / defining a function
464 bool mDeclaringFunction;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000465};
466
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500467int PaParseStrings(size_t count,
468 const char *const string[],
469 const int length[],
470 TParseContext *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000471
Jamie Madill45bcc782016-11-07 13:58:48 -0500472} // namespace sh
473
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500474#endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_