blob: 55c5c4c2a1940c47df13e4b1c3d947ed665095a0 [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,
115 TIntermNode *argumentsNode,
116 const TFunction &function,
117 TOperator op,
118 const TType &type);
119
120 // Returns a sanitized array size to use (the size is at least 1).
121 unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr);
Olli Etuaho8a176262016-08-16 14:23:01 +0300122 bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &elementQualifier);
123 bool checkIsValidTypeForArray(const TSourceLoc &line, const TPublicType &elementType);
Olli Etuaho856c4972016-08-08 11:38:39 +0300124 bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
125 void checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type);
126 void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType);
Martin Radev4a9cd802016-09-01 16:51:51 +0300127 bool checkIsNotSampler(const TSourceLoc &line,
128 const TTypeSpecifierNonArray &pType,
129 const char *reason);
Martin Radev2cc85b32016-08-05 16:22:53 +0300130 bool checkIsNotImage(const TSourceLoc &line,
131 const TTypeSpecifierNonArray &pType,
132 const char *reason);
Olli Etuaho856c4972016-08-08 11:38:39 +0300133 void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType);
134 void checkLocationIsNotSpecified(const TSourceLoc &location,
135 const TLayoutQualifier &layoutQualifier);
Olli Etuaho856c4972016-08-08 11:38:39 +0300136 void checkIsParameterQualifierValid(const TSourceLoc &line,
Martin Radev70866b82016-07-22 15:27:42 +0300137 const TTypeQualifierBuilder &typeQualifierBuilder,
Olli Etuaho856c4972016-08-08 11:38:39 +0300138 TType *type);
139 bool checkCanUseExtension(const TSourceLoc &line, const TString &extension);
Olli Etuaho383b7912016-08-05 11:22:59 +0300140 void singleDeclarationErrorCheck(const TPublicType &publicType,
141 const TSourceLoc &identifierLocation);
Martin Radevb8b01222016-11-20 23:25:53 +0200142 void emptyDeclarationErrorCheck(const TPublicType &publicType, const TSourceLoc &location);
Olli Etuaho856c4972016-08-08 11:38:39 +0300143 void checkLayoutQualifierSupported(const TSourceLoc &location,
144 const TString &layoutQualifierName,
145 int versionRequired);
146 bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location,
147 const TLayoutQualifier &layoutQualifier);
Martin Radev2cc85b32016-08-05 16:22:53 +0300148 bool checkInternalFormatIsNotSpecified(const TSourceLoc &location,
149 TLayoutImageInternalFormat internalFormat);
Olli Etuaho856c4972016-08-08 11:38:39 +0300150 void functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall);
Martin Radev70866b82016-07-22 15:27:42 +0300151 void checkInvariantVariableQualifier(bool invariant,
152 const TQualifier qualifier,
153 const TSourceLoc &invariantLocation);
Olli Etuaho856c4972016-08-08 11:38:39 +0300154 void checkInputOutputTypeIsValidES3(const TQualifier qualifier,
155 const TPublicType &type,
156 const TSourceLoc &qualifierLocation);
Martin Radev2cc85b32016-08-05 16:22:53 +0300157 void checkLocalVariableConstStorageQualifier(const TQualifierWrapperBase &qualifier);
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400158 const TPragma &pragma() const { return mDirectiveHandler.pragma(); }
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500159 const TExtensionBehavior &extensionBehavior() const
160 {
161 return mDirectiveHandler.extensionBehavior();
162 }
Jamie Madill06145232015-05-13 13:10:01 -0400163 bool supportsExtension(const char *extension);
164 bool isExtensionEnabled(const char *extension) const;
165 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500166 void handlePragmaDirective(const TSourceLoc &loc,
167 const char *name,
168 const char *value,
169 bool stdgl);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000170
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500171 const TFunction *findFunction(const TSourceLoc &line,
172 TFunction *pfnCall,
173 int inputShaderVersion,
174 bool *builtIn = 0);
Jamie Madill06145232015-05-13 13:10:01 -0400175 bool executeInitializer(const TSourceLoc &line,
176 const TString &identifier,
177 const TPublicType &pType,
178 TIntermTyped *initializer,
Olli Etuaho13389b62016-10-16 11:48:18 +0100179 TIntermBinary **initNode);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000180
Olli Etuaho0e3aee32016-10-27 12:56:38 +0100181 void addFullySpecifiedType(TPublicType *typeSpecifier);
Martin Radev70866b82016-07-22 15:27:42 +0300182 TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400183 const TPublicType &typeSpecifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200184
Olli Etuaho13389b62016-10-16 11:48:18 +0100185 TIntermDeclaration *parseSingleDeclaration(TPublicType &publicType,
186 const TSourceLoc &identifierOrTypeLocation,
187 const TString &identifier);
188 TIntermDeclaration *parseSingleArrayDeclaration(TPublicType &publicType,
189 const TSourceLoc &identifierLocation,
190 const TString &identifier,
191 const TSourceLoc &indexLocation,
192 TIntermTyped *indexExpression);
193 TIntermDeclaration *parseSingleInitDeclaration(const TPublicType &publicType,
194 const TSourceLoc &identifierLocation,
195 const TString &identifier,
196 const TSourceLoc &initLocation,
197 TIntermTyped *initializer);
Jamie Madill47e3ec02014-08-20 16:38:33 -0400198
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300199 // Parse a declaration like "type a[n] = initializer"
200 // Note that this does not apply to declarations like "type[n] a = initializer"
Olli Etuaho13389b62016-10-16 11:48:18 +0100201 TIntermDeclaration *parseSingleArrayInitDeclaration(TPublicType &publicType,
202 const TSourceLoc &identifierLocation,
203 const TString &identifier,
204 const TSourceLoc &indexLocation,
205 TIntermTyped *indexExpression,
206 const TSourceLoc &initLocation,
207 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300208
Olli Etuahobf4e1b72016-12-09 11:30:15 +0000209 TIntermInvariantDeclaration *parseInvariantDeclaration(
210 const TTypeQualifierBuilder &typeQualifierBuilder,
211 const TSourceLoc &identifierLoc,
212 const TString *identifier,
213 const TSymbol *symbol);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200214
Olli Etuaho13389b62016-10-16 11:48:18 +0100215 void parseDeclarator(TPublicType &publicType,
216 const TSourceLoc &identifierLocation,
217 const TString &identifier,
218 TIntermDeclaration *declarationOut);
219 void parseArrayDeclarator(TPublicType &publicType,
220 const TSourceLoc &identifierLocation,
221 const TString &identifier,
222 const TSourceLoc &arrayLocation,
223 TIntermTyped *indexExpression,
224 TIntermDeclaration *declarationOut);
225 void parseInitDeclarator(const TPublicType &publicType,
226 const TSourceLoc &identifierLocation,
227 const TString &identifier,
228 const TSourceLoc &initLocation,
229 TIntermTyped *initializer,
230 TIntermDeclaration *declarationOut);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200231
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300232 // Parse a declarator like "a[n] = initializer"
Olli Etuaho13389b62016-10-16 11:48:18 +0100233 void parseArrayInitDeclarator(const TPublicType &publicType,
234 const TSourceLoc &identifierLocation,
235 const TString &identifier,
236 const TSourceLoc &indexLocation,
237 TIntermTyped *indexExpression,
238 const TSourceLoc &initLocation,
239 TIntermTyped *initializer,
240 TIntermDeclaration *declarationOut);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300241
Martin Radev70866b82016-07-22 15:27:42 +0300242 void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder);
Olli Etuaho16c745a2017-01-16 17:02:27 +0000243 TIntermFunctionPrototype *addFunctionPrototypeDeclaration(const TFunction &parsedFunction,
244 const TSourceLoc &location);
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000245 TIntermFunctionDefinition *addFunctionDefinition(TIntermFunctionPrototype *functionPrototype,
Olli Etuaho336b1472016-10-05 16:37:55 +0100246 TIntermBlock *functionBody,
247 const TSourceLoc &location);
Olli Etuaho476197f2016-10-11 13:59:08 +0100248 void parseFunctionDefinitionHeader(const TSourceLoc &location,
249 TFunction **function,
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000250 TIntermFunctionPrototype **prototypeOut);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500251 TFunction *parseFunctionDeclarator(const TSourceLoc &location, TFunction *function);
Olli Etuaho9de84a52016-06-14 17:36:01 +0300252 TFunction *parseFunctionHeader(const TPublicType &type,
253 const TString *name,
254 const TSourceLoc &location);
Jamie Madill06145232015-05-13 13:10:01 -0400255 TFunction *addConstructorFunc(const TPublicType &publicType);
256 TIntermTyped *addConstructor(TIntermNode *arguments,
Jamie Madill06145232015-05-13 13:10:01 -0400257 TOperator op,
258 TFunction *fnCall,
259 const TSourceLoc &line);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300260
Jamie Madill06145232015-05-13 13:10:01 -0400261 TIntermTyped *addIndexExpression(TIntermTyped *baseExpression,
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500262 const TSourceLoc &location,
Jamie Madill06145232015-05-13 13:10:01 -0400263 TIntermTyped *indexExpression);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500264 TIntermTyped *addFieldSelectionExpression(TIntermTyped *baseExpression,
Jamie Madill06145232015-05-13 13:10:01 -0400265 const TSourceLoc &dotLocation,
266 const TString &fieldString,
267 const TSourceLoc &fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +0000268
Olli Etuaho4de340a2016-12-16 09:32:03 +0000269 TFieldList *combineStructFieldLists(TFieldList *processedFields,
270 const TFieldList *newlyAddedFields,
271 const TSourceLoc &location);
Martin Radev70866b82016-07-22 15:27:42 +0300272 TFieldList *addStructDeclaratorListWithQualifiers(
273 const TTypeQualifierBuilder &typeQualifierBuilder,
274 TPublicType *typeSpecifier,
275 TFieldList *fieldList);
Jamie Madill06145232015-05-13 13:10:01 -0400276 TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList);
Martin Radev4a9cd802016-09-01 16:51:51 +0300277 TTypeSpecifierNonArray addStructure(const TSourceLoc &structLine,
278 const TSourceLoc &nameLine,
279 const TString *structName,
280 TFieldList *fieldList);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000281
Olli Etuaho13389b62016-10-16 11:48:18 +0100282 TIntermDeclaration *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder,
283 const TSourceLoc &nameLine,
284 const TString &blockName,
285 TFieldList *fieldList,
286 const TString *instanceName,
287 const TSourceLoc &instanceLine,
288 TIntermTyped *arrayIndex,
289 const TSourceLoc &arrayIndexLine);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000290
Martin Radev802abe02016-08-04 17:48:32 +0300291 void parseLocalSize(const TString &qualifierType,
292 const TSourceLoc &qualifierTypeLine,
293 int intValue,
294 const TSourceLoc &intValueLine,
295 const std::string &intValueString,
296 size_t index,
Martin Radev4c4c8e72016-08-04 12:25:34 +0300297 sh::WorkGroupSize *localSize);
Olli Etuaho09b04a22016-12-15 13:30:26 +0000298 void parseNumViews(int intValue,
299 const TSourceLoc &intValueLine,
300 const std::string &intValueString,
301 int *numViews);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500302 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
303 const TSourceLoc &qualifierTypeLine);
Jamie Madill06145232015-05-13 13:10:01 -0400304 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
305 const TSourceLoc &qualifierTypeLine,
Jamie Madill06145232015-05-13 13:10:01 -0400306 int intValue,
307 const TSourceLoc &intValueLine);
Olli Etuaho613b9592016-09-05 12:05:53 +0300308 TTypeQualifierBuilder *createTypeQualifierBuilder(const TSourceLoc &loc);
Martin Radev802abe02016-08-04 17:48:32 +0300309 TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier,
310 TLayoutQualifier rightQualifier,
311 const TSourceLoc &rightQualifierLocation);
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000312
kbr@chromium.org476541f2011-10-27 21:14:51 +0000313 // Performs an error check for embedded struct declarations.
Olli Etuaho383b7912016-08-05 11:22:59 +0300314 void enterStructDeclaration(const TSourceLoc &line, const TString &identifier);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000315 void exitStructDeclaration();
316
Olli Etuaho8a176262016-08-16 14:23:01 +0300317 void checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field);
Olli Etuaho09b22472015-02-11 11:47:26 +0200318
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100319 TIntermSwitch *addSwitch(TIntermTyped *init,
320 TIntermBlock *statementList,
321 const TSourceLoc &loc);
Olli Etuahoa3a36662015-02-17 13:46:51 +0200322 TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc);
323 TIntermCase *addDefault(const TSourceLoc &loc);
324
Jamie Madill06145232015-05-13 13:10:01 -0400325 TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
326 TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500327 TIntermTyped *addBinaryMath(TOperator op,
328 TIntermTyped *left,
329 TIntermTyped *right,
330 const TSourceLoc &loc);
331 TIntermTyped *addBinaryMathBooleanResult(TOperator op,
332 TIntermTyped *left,
333 TIntermTyped *right,
334 const TSourceLoc &loc);
335 TIntermTyped *addAssign(TOperator op,
336 TIntermTyped *left,
337 TIntermTyped *right,
338 const TSourceLoc &loc);
Olli Etuaho49300862015-02-20 14:54:49 +0200339
Olli Etuaho0b2d2dc2015-11-04 16:35:32 +0200340 TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
341
Olli Etuaho49300862015-02-20 14:54:49 +0200342 TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc);
343 TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +0200344
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200345 void checkTextureOffsetConst(TIntermAggregate *functionCall);
Martin Radev2cc85b32016-08-05 16:22:53 +0300346 void checkImageMemoryAccessForBuiltinFunctions(TIntermAggregate *functionCall);
347 void checkImageMemoryAccessForUserDefinedFunctions(const TFunction *functionDefinition,
348 const TIntermAggregate *functionCall);
Jamie Madill06145232015-05-13 13:10:01 -0400349 TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall,
350 TIntermNode *paramNode,
351 TIntermNode *thisNode,
352 const TSourceLoc &loc,
353 bool *fatalError);
Olli Etuahofc1806e2015-03-17 13:03:11 +0200354
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300355 TIntermTyped *addTernarySelection(TIntermTyped *cond,
356 TIntermTyped *trueExpression,
357 TIntermTyped *falseExpression,
358 const TSourceLoc &line);
Olli Etuaho52901742015-04-15 13:42:45 +0300359
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400360 // TODO(jmadill): make these private
Olli Etuahof119a262016-08-19 15:54:22 +0300361 TIntermediate intermediate; // to build a parse tree
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400362 TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed
363
Olli Etuahofc1806e2015-03-17 13:03:11 +0200364 private:
Olli Etuaho4de340a2016-12-16 09:32:03 +0000365 // Returns a clamped index. If it prints out an error message, the token is "[]".
Olli Etuaho90892fb2016-07-14 14:44:51 +0300366 int checkIndexOutOfRange(bool outOfRangeIndexIsError,
367 const TSourceLoc &location,
368 int index,
369 int arraySize,
Olli Etuaho4de340a2016-12-16 09:32:03 +0000370 const char *reason);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300371
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500372 bool declareVariable(const TSourceLoc &line,
373 const TString &identifier,
374 const TType &type,
375 TVariable **variable);
Olli Etuaho2935c582015-04-08 14:32:06 +0300376
Olli Etuaho856c4972016-08-08 11:38:39 +0300377 void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line,
378 const TString &identifier,
379 TPublicType *type);
Olli Etuaho376f1b52015-04-13 13:23:41 +0300380
Olli Etuaho8a176262016-08-16 14:23:01 +0300381 bool checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation,
382 const TPublicType &elementType);
383
Olli Etuaho1dded802016-08-18 18:13:13 +0300384 // Assumes that multiplication op has already been set based on the types.
385 bool isMultiplicationTypeCombinationValid(TOperator op, const TType &left, const TType &right);
386
Martin Radev2cc85b32016-08-05 16:22:53 +0300387 bool checkIsMemoryQualifierNotSpecified(const TMemoryQualifier &memoryQualifier,
388 const TSourceLoc &location);
389 void checkOutParameterIsNotImage(const TSourceLoc &line,
390 TQualifier qualifier,
391 const TType &type);
392 void checkOutParameterIsNotOpaqueType(const TSourceLoc &line,
393 TQualifier qualifier,
394 const TType &type);
395 void checkOutParameterIsNotSampler(const TSourceLoc &line,
396 TQualifier qualifier,
397 const TType &type);
398
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500399 TIntermTyped *addBinaryMathInternal(TOperator op,
400 TIntermTyped *left,
401 TIntermTyped *right,
402 const TSourceLoc &loc);
Olli Etuaho13389b62016-10-16 11:48:18 +0100403 TIntermBinary *createAssign(TOperator op,
404 TIntermTyped *left,
405 TIntermTyped *right,
406 const TSourceLoc &loc);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500407 // The funcReturnType parameter is expected to be non-null when the operation is a built-in
408 // function.
Olli Etuahof6c694b2015-03-26 14:50:53 +0200409 // It is expected to be null for other unary operators.
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500410 TIntermTyped *createUnaryMath(TOperator op,
411 TIntermTyped *child,
412 const TSourceLoc &loc,
413 const TType *funcReturnType);
Olli Etuahod6b14282015-03-17 14:31:35 +0200414
Olli Etuaho47fd36a2015-03-19 14:22:24 +0200415 // Return true if the checks pass
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500416 bool binaryOpCommonCheck(TOperator op,
417 TIntermTyped *left,
418 TIntermTyped *right,
419 const TSourceLoc &loc);
Olli Etuahofa33d582015-04-09 14:33:12 +0300420
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000421 TIntermFunctionPrototype *createPrototypeNodeFromFunction(const TFunction &function,
422 const TSourceLoc &location,
423 bool insertParametersToSymbolTable);
424
Olli Etuahofa33d582015-04-09 14:33:12 +0300425 // Set to true when the last/current declarator list was started with an empty declaration.
426 bool mDeferredSingleDeclarationErrorCheck;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400427
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500428 sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800429 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
430 ShCompileOptions mCompileOptions; // Options passed to TCompiler
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400431 int mShaderVersion;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500432 TIntermBlock *mTreeRoot; // root of parse tree being created
433 int mLoopNestingLevel; // 0 if outside all loops
434 int mStructNestingLevel; // incremented while parsing a struct declaration
435 int mSwitchNestingLevel; // 0 if outside all switch statements
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800436 const TType
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500437 *mCurrentFunctionType; // the return type of the function that's currently being parsed
438 bool mFunctionReturnsValue; // true if a non-void function has a return
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800439 bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared
440 // without precision, explicit or implicit.
Olli Etuahoa6996682015-10-12 14:32:30 +0300441 bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling
442 // ESSL1.
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400443 TLayoutMatrixPacking mDefaultMatrixPacking;
444 TLayoutBlockStorage mDefaultBlockStorage;
445 TString mHashErrMsg;
Olli Etuaho77ba4082016-12-16 12:01:18 +0000446 TDiagnostics *mDiagnostics;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400447 TDirectiveHandler mDirectiveHandler;
448 pp::Preprocessor mPreprocessor;
449 void *mScanner;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500450 bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
Jamie Madill14e95b32015-05-07 10:10:41 -0400451 bool mUsesFragColor;
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +0300452 bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or
453 // gl_Secondary FragColor or both.
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200454 int mMinProgramTexelOffset;
455 int mMaxProgramTexelOffset;
Martin Radev802abe02016-08-04 17:48:32 +0300456
Olli Etuaho09b04a22016-12-15 13:30:26 +0000457 bool mMultiviewAvailable;
458
Martin Radev802abe02016-08-04 17:48:32 +0300459 // keep track of local group size declared in layout. It should be declared only once.
460 bool mComputeShaderLocalSizeDeclared;
Martin Radev4c4c8e72016-08-04 12:25:34 +0300461 sh::WorkGroupSize mComputeShaderLocalSize;
Olli Etuaho09b04a22016-12-15 13:30:26 +0000462 // keep track of number of views declared in layout.
463 int mNumViews;
464 int mMaxNumViews;
Martin Radev70866b82016-07-22 15:27:42 +0300465 // keeps track whether we are declaring / defining a function
466 bool mDeclaringFunction;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000467};
468
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500469int PaParseStrings(size_t count,
470 const char *const string[],
471 const int length[],
472 TParseContext *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000473
Jamie Madill45bcc782016-11-07 13:58:48 -0500474} // namespace sh
475
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500476#endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_