blob: 77e901f750d1d4f1e604389ac313414b0507a175 [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 Etuahoaf6fc1b2017-01-26 17:45:35 -0800115 const TIntermSequence *arguments,
Olli Etuaho856c4972016-08-08 11:38:39 +0300116 const TType &type);
117
118 // Returns a sanitized array size to use (the size is at least 1).
119 unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr);
Olli Etuaho8a176262016-08-16 14:23:01 +0300120 bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &elementQualifier);
121 bool checkIsValidTypeForArray(const TSourceLoc &line, const TPublicType &elementType);
Olli Etuaho856c4972016-08-08 11:38:39 +0300122 bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
123 void checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type);
124 void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType);
jchen10cc2a10e2017-05-03 14:05:12 +0800125 bool checkIsNotOpaqueType(const TSourceLoc &line,
126 const TTypeSpecifierNonArray &pType,
127 const char *reason);
Olli Etuaho856c4972016-08-08 11:38:39 +0300128 void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType);
129 void checkLocationIsNotSpecified(const TSourceLoc &location,
130 const TLayoutQualifier &layoutQualifier);
Olli Etuaho856c4972016-08-08 11:38:39 +0300131 void checkIsParameterQualifierValid(const TSourceLoc &line,
Martin Radev70866b82016-07-22 15:27:42 +0300132 const TTypeQualifierBuilder &typeQualifierBuilder,
Olli Etuaho856c4972016-08-08 11:38:39 +0300133 TType *type);
134 bool checkCanUseExtension(const TSourceLoc &line, const TString &extension);
Olli Etuahobb7e5a72017-04-24 10:16:44 +0300135
136 // Done for all declarations, whether empty or not.
137 void declarationQualifierErrorCheck(const sh::TQualifier qualifier,
138 const sh::TLayoutQualifier &layoutQualifier,
139 const TSourceLoc &location);
140 // Done for the first non-empty declarator in a declaration.
141 void nonEmptyDeclarationErrorCheck(const TPublicType &publicType,
142 const TSourceLoc &identifierLocation);
143 // Done only for empty declarations.
Martin Radevb8b01222016-11-20 23:25:53 +0200144 void emptyDeclarationErrorCheck(const TPublicType &publicType, const TSourceLoc &location);
Olli Etuahobb7e5a72017-04-24 10:16:44 +0300145
Olli Etuaho856c4972016-08-08 11:38:39 +0300146 void checkLayoutQualifierSupported(const TSourceLoc &location,
147 const TString &layoutQualifierName,
148 int versionRequired);
149 bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location,
150 const TLayoutQualifier &layoutQualifier);
Olli Etuaho856c4972016-08-08 11:38:39 +0300151 void functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall);
Martin Radev70866b82016-07-22 15:27:42 +0300152 void checkInvariantVariableQualifier(bool invariant,
153 const TQualifier qualifier,
154 const TSourceLoc &invariantLocation);
Olli Etuaho856c4972016-08-08 11:38:39 +0300155 void checkInputOutputTypeIsValidES3(const TQualifier qualifier,
156 const TPublicType &type,
157 const TSourceLoc &qualifierLocation);
Martin Radev2cc85b32016-08-05 16:22:53 +0300158 void checkLocalVariableConstStorageQualifier(const TQualifierWrapperBase &qualifier);
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400159 const TPragma &pragma() const { return mDirectiveHandler.pragma(); }
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500160 const TExtensionBehavior &extensionBehavior() const
161 {
162 return mDirectiveHandler.extensionBehavior();
163 }
Jamie Madill06145232015-05-13 13:10:01 -0400164 bool supportsExtension(const char *extension);
165 bool isExtensionEnabled(const char *extension) const;
Olli Etuaho95468d12017-05-04 11:14:34 +0300166 bool isMultiviewExtensionEnabled() const
167 {
168 return mMultiviewAvailable &&
169 (isExtensionEnabled("GL_OVR_multiview") || isExtensionEnabled("GL_OVR_multiview2"));
170 }
Jamie Madill06145232015-05-13 13:10:01 -0400171 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500172 void handlePragmaDirective(const TSourceLoc &loc,
173 const char *name,
174 const char *value,
175 bool stdgl);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000176
Jamie Madill06145232015-05-13 13:10:01 -0400177 bool executeInitializer(const TSourceLoc &line,
178 const TString &identifier,
179 const TPublicType &pType,
180 TIntermTyped *initializer,
Olli Etuaho13389b62016-10-16 11:48:18 +0100181 TIntermBinary **initNode);
alokp@chromium.org75fe6b72011-08-14 05:31:22 +0000182
Olli Etuaho0e3aee32016-10-27 12:56:38 +0100183 void addFullySpecifiedType(TPublicType *typeSpecifier);
Martin Radev70866b82016-07-22 15:27:42 +0300184 TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder,
Jamie Madill06145232015-05-13 13:10:01 -0400185 const TPublicType &typeSpecifier);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200186
Olli Etuaho13389b62016-10-16 11:48:18 +0100187 TIntermDeclaration *parseSingleDeclaration(TPublicType &publicType,
188 const TSourceLoc &identifierOrTypeLocation,
189 const TString &identifier);
190 TIntermDeclaration *parseSingleArrayDeclaration(TPublicType &publicType,
191 const TSourceLoc &identifierLocation,
192 const TString &identifier,
193 const TSourceLoc &indexLocation,
194 TIntermTyped *indexExpression);
195 TIntermDeclaration *parseSingleInitDeclaration(const TPublicType &publicType,
196 const TSourceLoc &identifierLocation,
197 const TString &identifier,
198 const TSourceLoc &initLocation,
199 TIntermTyped *initializer);
Jamie Madill47e3ec02014-08-20 16:38:33 -0400200
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300201 // Parse a declaration like "type a[n] = initializer"
202 // Note that this does not apply to declarations like "type[n] a = initializer"
Olli Etuaho13389b62016-10-16 11:48:18 +0100203 TIntermDeclaration *parseSingleArrayInitDeclaration(TPublicType &publicType,
204 const TSourceLoc &identifierLocation,
205 const TString &identifier,
206 const TSourceLoc &indexLocation,
207 TIntermTyped *indexExpression,
208 const TSourceLoc &initLocation,
209 TIntermTyped *initializer);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300210
Olli Etuahobf4e1b72016-12-09 11:30:15 +0000211 TIntermInvariantDeclaration *parseInvariantDeclaration(
212 const TTypeQualifierBuilder &typeQualifierBuilder,
213 const TSourceLoc &identifierLoc,
214 const TString *identifier,
215 const TSymbol *symbol);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200216
Olli Etuaho13389b62016-10-16 11:48:18 +0100217 void parseDeclarator(TPublicType &publicType,
218 const TSourceLoc &identifierLocation,
219 const TString &identifier,
220 TIntermDeclaration *declarationOut);
221 void parseArrayDeclarator(TPublicType &publicType,
222 const TSourceLoc &identifierLocation,
223 const TString &identifier,
224 const TSourceLoc &arrayLocation,
225 TIntermTyped *indexExpression,
226 TIntermDeclaration *declarationOut);
227 void parseInitDeclarator(const TPublicType &publicType,
228 const TSourceLoc &identifierLocation,
229 const TString &identifier,
230 const TSourceLoc &initLocation,
231 TIntermTyped *initializer,
232 TIntermDeclaration *declarationOut);
Olli Etuahoe7847b02015-03-16 11:56:12 +0200233
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300234 // Parse a declarator like "a[n] = initializer"
Olli Etuaho13389b62016-10-16 11:48:18 +0100235 void parseArrayInitDeclarator(const TPublicType &publicType,
236 const TSourceLoc &identifierLocation,
237 const TString &identifier,
238 const TSourceLoc &indexLocation,
239 TIntermTyped *indexExpression,
240 const TSourceLoc &initLocation,
241 TIntermTyped *initializer,
242 TIntermDeclaration *declarationOut);
Olli Etuaho3875ffd2015-04-10 16:45:14 +0300243
Martin Radev70866b82016-07-22 15:27:42 +0300244 void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder);
Olli Etuaho16c745a2017-01-16 17:02:27 +0000245 TIntermFunctionPrototype *addFunctionPrototypeDeclaration(const TFunction &parsedFunction,
246 const TSourceLoc &location);
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000247 TIntermFunctionDefinition *addFunctionDefinition(TIntermFunctionPrototype *functionPrototype,
Olli Etuaho336b1472016-10-05 16:37:55 +0100248 TIntermBlock *functionBody,
249 const TSourceLoc &location);
Olli Etuaho476197f2016-10-11 13:59:08 +0100250 void parseFunctionDefinitionHeader(const TSourceLoc &location,
251 TFunction **function,
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000252 TIntermFunctionPrototype **prototypeOut);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500253 TFunction *parseFunctionDeclarator(const TSourceLoc &location, TFunction *function);
Olli Etuaho9de84a52016-06-14 17:36:01 +0300254 TFunction *parseFunctionHeader(const TPublicType &type,
255 const TString *name,
256 const TSourceLoc &location);
Jamie Madill06145232015-05-13 13:10:01 -0400257 TFunction *addConstructorFunc(const TPublicType &publicType);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300258
Jamie Madill06145232015-05-13 13:10:01 -0400259 TIntermTyped *addIndexExpression(TIntermTyped *baseExpression,
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500260 const TSourceLoc &location,
Jamie Madill06145232015-05-13 13:10:01 -0400261 TIntermTyped *indexExpression);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500262 TIntermTyped *addFieldSelectionExpression(TIntermTyped *baseExpression,
Jamie Madill06145232015-05-13 13:10:01 -0400263 const TSourceLoc &dotLocation,
264 const TString &fieldString,
265 const TSourceLoc &fieldLocation);
shannonwoods@chromium.orga9100882013-05-30 00:11:39 +0000266
Olli Etuaho4de340a2016-12-16 09:32:03 +0000267 TFieldList *combineStructFieldLists(TFieldList *processedFields,
268 const TFieldList *newlyAddedFields,
269 const TSourceLoc &location);
Martin Radev70866b82016-07-22 15:27:42 +0300270 TFieldList *addStructDeclaratorListWithQualifiers(
271 const TTypeQualifierBuilder &typeQualifierBuilder,
272 TPublicType *typeSpecifier,
273 TFieldList *fieldList);
Jamie Madill06145232015-05-13 13:10:01 -0400274 TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList);
Martin Radev4a9cd802016-09-01 16:51:51 +0300275 TTypeSpecifierNonArray addStructure(const TSourceLoc &structLine,
276 const TSourceLoc &nameLine,
277 const TString *structName,
278 TFieldList *fieldList);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000279
Olli Etuaho13389b62016-10-16 11:48:18 +0100280 TIntermDeclaration *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder,
281 const TSourceLoc &nameLine,
282 const TString &blockName,
283 TFieldList *fieldList,
284 const TString *instanceName,
285 const TSourceLoc &instanceLine,
286 TIntermTyped *arrayIndex,
287 const TSourceLoc &arrayIndexLine);
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000288
Martin Radev802abe02016-08-04 17:48:32 +0300289 void parseLocalSize(const TString &qualifierType,
290 const TSourceLoc &qualifierTypeLine,
291 int intValue,
292 const TSourceLoc &intValueLine,
293 const std::string &intValueString,
294 size_t index,
Martin Radev4c4c8e72016-08-04 12:25:34 +0300295 sh::WorkGroupSize *localSize);
Olli Etuaho09b04a22016-12-15 13:30:26 +0000296 void parseNumViews(int intValue,
297 const TSourceLoc &intValueLine,
298 const std::string &intValueString,
299 int *numViews);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500300 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
301 const TSourceLoc &qualifierTypeLine);
Jamie Madill06145232015-05-13 13:10:01 -0400302 TLayoutQualifier parseLayoutQualifier(const TString &qualifierType,
303 const TSourceLoc &qualifierTypeLine,
Jamie Madill06145232015-05-13 13:10:01 -0400304 int intValue,
305 const TSourceLoc &intValueLine);
Olli Etuaho613b9592016-09-05 12:05:53 +0300306 TTypeQualifierBuilder *createTypeQualifierBuilder(const TSourceLoc &loc);
Martin Radev802abe02016-08-04 17:48:32 +0300307 TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier,
308 TLayoutQualifier rightQualifier,
309 const TSourceLoc &rightQualifierLocation);
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000310
kbr@chromium.org476541f2011-10-27 21:14:51 +0000311 // Performs an error check for embedded struct declarations.
Olli Etuaho383b7912016-08-05 11:22:59 +0300312 void enterStructDeclaration(const TSourceLoc &line, const TString &identifier);
kbr@chromium.org476541f2011-10-27 21:14:51 +0000313 void exitStructDeclaration();
314
Olli Etuaho8a176262016-08-16 14:23:01 +0300315 void checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field);
Olli Etuaho09b22472015-02-11 11:47:26 +0200316
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100317 TIntermSwitch *addSwitch(TIntermTyped *init,
318 TIntermBlock *statementList,
319 const TSourceLoc &loc);
Olli Etuahoa3a36662015-02-17 13:46:51 +0200320 TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc);
321 TIntermCase *addDefault(const TSourceLoc &loc);
322
Jamie Madill06145232015-05-13 13:10:01 -0400323 TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
324 TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500325 TIntermTyped *addBinaryMath(TOperator op,
326 TIntermTyped *left,
327 TIntermTyped *right,
328 const TSourceLoc &loc);
329 TIntermTyped *addBinaryMathBooleanResult(TOperator op,
330 TIntermTyped *left,
331 TIntermTyped *right,
332 const TSourceLoc &loc);
333 TIntermTyped *addAssign(TOperator op,
334 TIntermTyped *left,
335 TIntermTyped *right,
336 const TSourceLoc &loc);
Olli Etuaho49300862015-02-20 14:54:49 +0200337
Olli Etuaho0b2d2dc2015-11-04 16:35:32 +0200338 TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
339
Olli Etuaho49300862015-02-20 14:54:49 +0200340 TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc);
341 TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc);
Olli Etuahoc4ba3be2015-03-02 14:42:24 +0200342
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200343 void checkTextureOffsetConst(TIntermAggregate *functionCall);
Martin Radev2cc85b32016-08-05 16:22:53 +0300344 void checkImageMemoryAccessForBuiltinFunctions(TIntermAggregate *functionCall);
345 void checkImageMemoryAccessForUserDefinedFunctions(const TFunction *functionDefinition,
346 const TIntermAggregate *functionCall);
Olli Etuahoaf6fc1b2017-01-26 17:45:35 -0800347 TIntermSequence *createEmptyArgumentsList();
Olli Etuaho72d10202017-01-19 15:58:30 +0000348
Olli Etuahoaf6fc1b2017-01-26 17:45:35 -0800349 // fnCall is only storing the built-in op, and function name or constructor type. arguments
Olli Etuaho72d10202017-01-19 15:58:30 +0000350 // has the arguments.
Jamie Madill06145232015-05-13 13:10:01 -0400351 TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall,
Olli Etuahoaf6fc1b2017-01-26 17:45:35 -0800352 TIntermSequence *arguments,
Jamie Madill06145232015-05-13 13:10:01 -0400353 TIntermNode *thisNode,
Olli Etuaho72d10202017-01-19 15:58:30 +0000354 const TSourceLoc &loc);
Olli Etuahofc1806e2015-03-17 13:03:11 +0200355
Olli Etuahod0bad2c2016-09-09 18:01:16 +0300356 TIntermTyped *addTernarySelection(TIntermTyped *cond,
357 TIntermTyped *trueExpression,
358 TIntermTyped *falseExpression,
359 const TSourceLoc &line);
Olli Etuaho52901742015-04-15 13:42:45 +0300360
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400361 // TODO(jmadill): make these private
Olli Etuahof119a262016-08-19 15:54:22 +0300362 TIntermediate intermediate; // to build a parse tree
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400363 TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed
364
Olli Etuahofc1806e2015-03-17 13:03:11 +0200365 private:
Olli Etuaho4de340a2016-12-16 09:32:03 +0000366 // Returns a clamped index. If it prints out an error message, the token is "[]".
Olli Etuaho90892fb2016-07-14 14:44:51 +0300367 int checkIndexOutOfRange(bool outOfRangeIndexIsError,
368 const TSourceLoc &location,
369 int index,
370 int arraySize,
Olli Etuaho4de340a2016-12-16 09:32:03 +0000371 const char *reason);
Olli Etuaho90892fb2016-07-14 14:44:51 +0300372
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500373 bool declareVariable(const TSourceLoc &line,
374 const TString &identifier,
375 const TType &type,
376 TVariable **variable);
Olli Etuaho2935c582015-04-08 14:32:06 +0300377
Olli Etuaho856c4972016-08-08 11:38:39 +0300378 void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line,
379 const TString &identifier,
380 TPublicType *type);
Olli Etuaho376f1b52015-04-13 13:23:41 +0300381
Olli Etuaho8a176262016-08-16 14:23:01 +0300382 bool checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation,
383 const TPublicType &elementType);
384
Olli Etuaho1dded802016-08-18 18:13:13 +0300385 // Assumes that multiplication op has already been set based on the types.
386 bool isMultiplicationTypeCombinationValid(TOperator op, const TType &left, const TType &right);
387
Martin Radev2cc85b32016-08-05 16:22:53 +0300388 void checkOutParameterIsNotOpaqueType(const TSourceLoc &line,
389 TQualifier qualifier,
390 const TType &type);
Martin Radev2cc85b32016-08-05 16:22:53 +0300391
Olli Etuaho43364892017-02-13 16:00:12 +0000392 void checkInternalFormatIsNotSpecified(const TSourceLoc &location,
393 TLayoutImageInternalFormat internalFormat);
394 void checkMemoryQualifierIsNotSpecified(const TMemoryQualifier &memoryQualifier,
395 const TSourceLoc &location);
396 void checkBindingIsValid(const TSourceLoc &identifierLocation, const TType &type);
397 void checkBindingIsNotSpecified(const TSourceLoc &location, int binding);
398 void checkImageBindingIsValid(const TSourceLoc &location, int binding, int arraySize);
399 void checkSamplerBindingIsValid(const TSourceLoc &location, int binding, int arraySize);
400
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000401 void checkUniformLocationInRange(const TSourceLoc &location,
402 int objectLocationCount,
403 const TLayoutQualifier &layoutQualifier);
404
Andrei Volykhina5527072017-03-22 16:46:30 +0300405 void checkYuvIsNotSpecified(const TSourceLoc &location, bool yuv);
406
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500407 TIntermTyped *addBinaryMathInternal(TOperator op,
408 TIntermTyped *left,
409 TIntermTyped *right,
410 const TSourceLoc &loc);
Olli Etuaho13389b62016-10-16 11:48:18 +0100411 TIntermBinary *createAssign(TOperator op,
412 TIntermTyped *left,
413 TIntermTyped *right,
414 const TSourceLoc &loc);
Olli Etuahoaf6fc1b2017-01-26 17:45:35 -0800415 TIntermTyped *createUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
416
417 TIntermTyped *addMethod(TFunction *fnCall,
418 TIntermSequence *arguments,
419 TIntermNode *thisNode,
420 const TSourceLoc &loc);
421 TIntermTyped *addConstructor(TIntermSequence *arguments,
Olli Etuahoaf6fc1b2017-01-26 17:45:35 -0800422 TType type,
423 const TSourceLoc &line);
424 TIntermTyped *addNonConstructorFunctionCall(TFunction *fnCall,
425 TIntermSequence *arguments,
426 const TSourceLoc &loc);
Olli Etuahod6b14282015-03-17 14:31:35 +0200427
Olli Etuaho47fd36a2015-03-19 14:22:24 +0200428 // Return true if the checks pass
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500429 bool binaryOpCommonCheck(TOperator op,
430 TIntermTyped *left,
431 TIntermTyped *right,
432 const TSourceLoc &loc);
Olli Etuahofa33d582015-04-09 14:33:12 +0300433
Olli Etuaho8ad9e752017-01-16 19:55:20 +0000434 TIntermFunctionPrototype *createPrototypeNodeFromFunction(const TFunction &function,
435 const TSourceLoc &location,
436 bool insertParametersToSymbolTable);
437
Olli Etuahobb7e5a72017-04-24 10:16:44 +0300438 // Set to true when the last/current declarator list was started with an empty declaration. The
439 // non-empty declaration error check will need to be performed if the empty declaration is
440 // followed by a declarator.
441 bool mDeferredNonEmptyDeclarationErrorCheck;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400442
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500443 sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack)
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800444 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
445 ShCompileOptions mCompileOptions; // Options passed to TCompiler
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400446 int mShaderVersion;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500447 TIntermBlock *mTreeRoot; // root of parse tree being created
448 int mLoopNestingLevel; // 0 if outside all loops
449 int mStructNestingLevel; // incremented while parsing a struct declaration
450 int mSwitchNestingLevel; // 0 if outside all switch statements
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800451 const TType
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500452 *mCurrentFunctionType; // the return type of the function that's currently being parsed
453 bool mFunctionReturnsValue; // true if a non-void function has a return
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800454 bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared
455 // without precision, explicit or implicit.
Olli Etuahoa6996682015-10-12 14:32:30 +0300456 bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling
457 // ESSL1.
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400458 TLayoutMatrixPacking mDefaultMatrixPacking;
459 TLayoutBlockStorage mDefaultBlockStorage;
460 TString mHashErrMsg;
Olli Etuaho77ba4082016-12-16 12:01:18 +0000461 TDiagnostics *mDiagnostics;
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400462 TDirectiveHandler mDirectiveHandler;
463 pp::Preprocessor mPreprocessor;
464 void *mScanner;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500465 bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor
Jamie Madill14e95b32015-05-07 10:10:41 -0400466 bool mUsesFragColor;
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +0300467 bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or
468 // gl_Secondary FragColor or both.
Olli Etuahoe1a94c62015-11-16 17:35:25 +0200469 int mMinProgramTexelOffset;
470 int mMaxProgramTexelOffset;
Martin Radev802abe02016-08-04 17:48:32 +0300471
Olli Etuaho09b04a22016-12-15 13:30:26 +0000472 bool mMultiviewAvailable;
473
Martin Radev802abe02016-08-04 17:48:32 +0300474 // keep track of local group size declared in layout. It should be declared only once.
475 bool mComputeShaderLocalSizeDeclared;
Martin Radev4c4c8e72016-08-04 12:25:34 +0300476 sh::WorkGroupSize mComputeShaderLocalSize;
Olli Etuaho09b04a22016-12-15 13:30:26 +0000477 // keep track of number of views declared in layout.
478 int mNumViews;
479 int mMaxNumViews;
Olli Etuaho43364892017-02-13 16:00:12 +0000480 int mMaxImageUnits;
481 int mMaxCombinedTextureImageUnits;
Olli Etuaho6ca2b652017-02-19 18:05:10 +0000482 int mMaxUniformLocations;
Martin Radev70866b82016-07-22 15:27:42 +0300483 // keeps track whether we are declaring / defining a function
484 bool mDeclaringFunction;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000485};
486
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500487int PaParseStrings(size_t count,
488 const char *const string[],
489 const int length[],
490 TParseContext *context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000491
Jamie Madill45bcc782016-11-07 13:58:48 -0500492} // namespace sh
493
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500494#endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_