daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | 16004fc | 2014-06-11 11:29:11 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 6 | #ifndef COMPILER_TRANSLATOR_PARSECONTEXT_H_ |
| 7 | #define COMPILER_TRANSLATOR_PARSECONTEXT_H_ |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 8 | |
Jamie Madill | d4a3a31 | 2014-06-25 16:04:56 -0400 | [diff] [blame] | 9 | #include "compiler/translator/Compiler.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 10 | #include "compiler/translator/Diagnostics.h" |
| 11 | #include "compiler/translator/DirectiveHandler.h" |
Jamie Madill | b1a85f4 | 2014-08-19 15:23:24 -0400 | [diff] [blame] | 12 | #include "compiler/translator/Intermediate.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 13 | #include "compiler/translator/SymbolTable.h" |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame^] | 14 | #include "compiler/translator/QualifierTypes.h" |
daniel@transgaming.com | b401a92 | 2012-10-26 18:58:24 +0000 | [diff] [blame] | 15 | #include "compiler/preprocessor/Preprocessor.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 16 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 17 | struct TMatrixFields |
| 18 | { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 19 | bool wholeRow; |
| 20 | bool wholeCol; |
| 21 | int row; |
| 22 | int col; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 23 | }; |
| 24 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 25 | // |
| 26 | // The following are extra variables needed during parsing, grouped together so |
| 27 | // they can be passed to the parser without needing a global. |
| 28 | // |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 29 | class TParseContext : angle::NonCopyable |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 30 | { |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 31 | public: |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 32 | TParseContext(TSymbolTable &symt, |
| 33 | TExtensionBehavior &ext, |
| 34 | TIntermediate &interm, |
| 35 | sh::GLenum type, |
| 36 | ShShaderSpec spec, |
| 37 | int options, |
| 38 | bool checksPrecErrors, |
| 39 | TInfoSink &is, |
Olli Etuaho | e1a94c6 | 2015-11-16 17:35:25 +0200 | [diff] [blame] | 40 | const ShBuiltInResources &resources) |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 41 | : intermediate(interm), |
| 42 | symbolTable(symt), |
Corentin Wallez | bc99bb6 | 2015-05-14 17:42:20 -0400 | [diff] [blame] | 43 | mDeferredSingleDeclarationErrorCheck(false), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 44 | mShaderType(type), |
| 45 | mShaderSpec(spec), |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 46 | mCompileOptions(options), |
Corentin Wallez | bc99bb6 | 2015-05-14 17:42:20 -0400 | [diff] [blame] | 47 | mShaderVersion(100), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 48 | mTreeRoot(nullptr), |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 49 | mLoopNestingLevel(0), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 50 | mStructNestingLevel(0), |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 51 | mSwitchNestingLevel(0), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 52 | mCurrentFunctionType(nullptr), |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 53 | mFunctionReturnsValue(false), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 54 | mChecksPrecisionErrors(checksPrecErrors), |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 55 | mFragmentPrecisionHighOnESSL1(false), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 56 | mDefaultMatrixPacking(EmpColumnMajor), |
| 57 | mDefaultBlockStorage(EbsShared), |
| 58 | mDiagnostics(is), |
Olli Etuaho | e1a94c6 | 2015-11-16 17:35:25 +0200 | [diff] [blame] | 59 | mDirectiveHandler(ext, |
| 60 | mDiagnostics, |
| 61 | mShaderVersion, |
Olli Etuaho | 5f80d01 | 2016-01-11 11:16:01 +0200 | [diff] [blame] | 62 | mShaderType, |
Olli Etuaho | e1a94c6 | 2015-11-16 17:35:25 +0200 | [diff] [blame] | 63 | resources.WEBGL_debug_shader_precision == 1), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 64 | mPreprocessor(&mDiagnostics, &mDirectiveHandler), |
| 65 | mScanner(nullptr), |
Jamie Madill | 14e95b3 | 2015-05-07 10:10:41 -0400 | [diff] [blame] | 66 | mUsesFragData(false), |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 67 | mUsesFragColor(false), |
Olli Etuaho | e1a94c6 | 2015-11-16 17:35:25 +0200 | [diff] [blame] | 68 | mUsesSecondaryOutputs(false), |
| 69 | mMinProgramTexelOffset(resources.MinProgramTexelOffset), |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 70 | mMaxProgramTexelOffset(resources.MaxProgramTexelOffset), |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame^] | 71 | mComputeShaderLocalSizeDeclared(false), |
| 72 | mDeclaringFunction(false) |
Olli Etuaho | fa33d58 | 2015-04-09 14:33:12 +0300 | [diff] [blame] | 73 | { |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 74 | mComputeShaderLocalSize.fill(-1); |
Olli Etuaho | fa33d58 | 2015-04-09 14:33:12 +0300 | [diff] [blame] | 75 | } |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 76 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 77 | const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; } |
| 78 | pp::Preprocessor &getPreprocessor() { return mPreprocessor; } |
| 79 | void *getScanner() const { return mScanner; } |
| 80 | void setScanner(void *scanner) { mScanner = scanner; } |
| 81 | int getShaderVersion() const { return mShaderVersion; } |
| 82 | sh::GLenum getShaderType() const { return mShaderType; } |
| 83 | ShShaderSpec getShaderSpec() const { return mShaderSpec; } |
| 84 | int numErrors() const { return mDiagnostics.numErrors(); } |
| 85 | TInfoSink &infoSink() { return mDiagnostics.infoSink(); } |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 86 | void error(const TSourceLoc &loc, const char *reason, const char *token, |
| 87 | const char *extraInfo=""); |
| 88 | void warning(const TSourceLoc &loc, const char *reason, const char *token, |
| 89 | const char *extraInfo=""); |
Jamie Madill | 14e95b3 | 2015-05-07 10:10:41 -0400 | [diff] [blame] | 90 | |
Olli Etuaho | 7c3848e | 2015-11-04 13:19:17 +0200 | [diff] [blame] | 91 | // If isError is false, a warning will be reported instead. |
| 92 | void outOfRangeError(bool isError, |
| 93 | const TSourceLoc &loc, |
| 94 | const char *reason, |
| 95 | const char *token, |
| 96 | const char *extraInfo = ""); |
| 97 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 98 | TIntermNode *getTreeRoot() const { return mTreeRoot; } |
| 99 | void setTreeRoot(TIntermNode *treeRoot) { mTreeRoot = treeRoot; } |
| 100 | |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 101 | bool getFragmentPrecisionHigh() const |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 102 | { |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 103 | return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300; |
| 104 | } |
| 105 | void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh) |
| 106 | { |
| 107 | mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh; |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 108 | } |
| 109 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 110 | void setLoopNestingLevel(int loopNestintLevel) |
| 111 | { |
| 112 | mLoopNestingLevel = loopNestintLevel; |
| 113 | } |
| 114 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 115 | void incrLoopNestingLevel() { ++mLoopNestingLevel; } |
| 116 | void decrLoopNestingLevel() { --mLoopNestingLevel; } |
| 117 | |
| 118 | void incrSwitchNestingLevel() { ++mSwitchNestingLevel; } |
| 119 | void decrSwitchNestingLevel() { --mSwitchNestingLevel; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 120 | |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 121 | bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; } |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 122 | sh::WorkGroupSize getComputeShaderLocalSize() const; |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 123 | |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame^] | 124 | void enterFunctionDeclaration() { mDeclaringFunction = true; } |
| 125 | |
| 126 | void exitFunctionDeclaration() { mDeclaringFunction = false; } |
| 127 | |
| 128 | bool declaringFunction() const { return mDeclaringFunction; } |
| 129 | |
Jamie Madill | 5c09702 | 2014-08-20 16:38:32 -0400 | [diff] [blame] | 130 | // This method is guaranteed to succeed, even if no variable with 'name' exists. |
| 131 | const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol); |
Olli Etuaho | 82c29ed | 2015-11-03 13:06:54 +0200 | [diff] [blame] | 132 | TIntermTyped *parseVariableIdentifier(const TSourceLoc &location, |
| 133 | const TString *name, |
| 134 | const TSymbol *symbol); |
Jamie Madill | 5c09702 | 2014-08-20 16:38:32 -0400 | [diff] [blame] | 135 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 136 | bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc &line); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 137 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 138 | void assignError(const TSourceLoc &line, const char *op, TString left, TString right); |
| 139 | void unaryOpError(const TSourceLoc &line, const char *op, TString operand); |
| 140 | void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 141 | |
Olli Etuaho | 8a17626 | 2016-08-16 14:23:01 +0300 | [diff] [blame] | 142 | // Check functions - the ones that return bool return false if an error was generated. |
| 143 | |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 144 | bool checkIsNotReserved(const TSourceLoc &line, const TString &identifier); |
| 145 | void checkPrecisionSpecified(const TSourceLoc &line, TPrecision precision, TBasicType type); |
| 146 | bool checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node); |
| 147 | void checkIsConst(TIntermTyped *node); |
| 148 | void checkIsScalarInteger(TIntermTyped *node, const char *token); |
Qiankun Miao | f69682b | 2016-08-16 14:50:42 +0800 | [diff] [blame] | 149 | bool checkIsAtGlobalLevel(const TSourceLoc &line, const char *token); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 150 | bool checkConstructorArguments(const TSourceLoc &line, |
| 151 | TIntermNode *argumentsNode, |
| 152 | const TFunction &function, |
| 153 | TOperator op, |
| 154 | const TType &type); |
| 155 | |
| 156 | // Returns a sanitized array size to use (the size is at least 1). |
| 157 | unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr); |
Olli Etuaho | 8a17626 | 2016-08-16 14:23:01 +0300 | [diff] [blame] | 158 | bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &elementQualifier); |
| 159 | bool checkIsValidTypeForArray(const TSourceLoc &line, const TPublicType &elementType); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 160 | bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type); |
| 161 | void checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type); |
| 162 | void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType); |
| 163 | bool checkIsNotSampler(const TSourceLoc &line, const TPublicType &pType, const char *reason); |
| 164 | void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType); |
| 165 | void checkLocationIsNotSpecified(const TSourceLoc &location, |
| 166 | const TLayoutQualifier &layoutQualifier); |
| 167 | void checkOutParameterIsNotSampler(const TSourceLoc &line, |
| 168 | TQualifier qualifier, |
| 169 | const TType &type); |
| 170 | void checkIsParameterQualifierValid(const TSourceLoc &line, |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame^] | 171 | const TTypeQualifierBuilder &typeQualifierBuilder, |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 172 | TType *type); |
| 173 | bool checkCanUseExtension(const TSourceLoc &line, const TString &extension); |
Olli Etuaho | 383b791 | 2016-08-05 11:22:59 +0300 | [diff] [blame] | 174 | void singleDeclarationErrorCheck(const TPublicType &publicType, |
| 175 | const TSourceLoc &identifierLocation); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 176 | void checkLayoutQualifierSupported(const TSourceLoc &location, |
| 177 | const TString &layoutQualifierName, |
| 178 | int versionRequired); |
| 179 | bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location, |
| 180 | const TLayoutQualifier &layoutQualifier); |
| 181 | |
| 182 | void functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall); |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame^] | 183 | void checkInvariantVariableQualifier(bool invariant, |
| 184 | const TQualifier qualifier, |
| 185 | const TSourceLoc &invariantLocation); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 186 | void checkInputOutputTypeIsValidES3(const TQualifier qualifier, |
| 187 | const TPublicType &type, |
| 188 | const TSourceLoc &qualifierLocation); |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 189 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 190 | const TPragma &pragma() const { return mDirectiveHandler.pragma(); } |
| 191 | const TExtensionBehavior &extensionBehavior() const { return mDirectiveHandler.extensionBehavior(); } |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 192 | bool supportsExtension(const char *extension); |
| 193 | bool isExtensionEnabled(const char *extension) const; |
| 194 | void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior); |
| 195 | void handlePragmaDirective(const TSourceLoc &loc, const char *name, const char *value, bool stdgl); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 196 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 197 | bool containsSampler(const TType &type); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 198 | const TFunction* findFunction( |
| 199 | const TSourceLoc &line, TFunction *pfnCall, int inputShaderVersion, bool *builtIn = 0); |
| 200 | bool executeInitializer(const TSourceLoc &line, |
| 201 | const TString &identifier, |
| 202 | const TPublicType &pType, |
| 203 | TIntermTyped *initializer, |
| 204 | TIntermNode **intermNode); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 205 | |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame^] | 206 | TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 207 | const TPublicType &typeSpecifier); |
Olli Etuaho | e7847b0 | 2015-03-16 11:56:12 +0200 | [diff] [blame] | 208 | |
Olli Etuaho | fa33d58 | 2015-04-09 14:33:12 +0300 | [diff] [blame] | 209 | TIntermAggregate *parseSingleDeclaration(TPublicType &publicType, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 210 | const TSourceLoc &identifierOrTypeLocation, |
| 211 | const TString &identifier); |
Olli Etuaho | e7847b0 | 2015-03-16 11:56:12 +0200 | [diff] [blame] | 212 | TIntermAggregate *parseSingleArrayDeclaration(TPublicType &publicType, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 213 | const TSourceLoc &identifierLocation, |
| 214 | const TString &identifier, |
| 215 | const TSourceLoc &indexLocation, |
| 216 | TIntermTyped *indexExpression); |
| 217 | TIntermAggregate *parseSingleInitDeclaration(const TPublicType &publicType, |
| 218 | const TSourceLoc &identifierLocation, |
| 219 | const TString &identifier, |
| 220 | const TSourceLoc &initLocation, |
| 221 | TIntermTyped *initializer); |
Jamie Madill | 47e3ec0 | 2014-08-20 16:38:33 -0400 | [diff] [blame] | 222 | |
Olli Etuaho | 3875ffd | 2015-04-10 16:45:14 +0300 | [diff] [blame] | 223 | // Parse a declaration like "type a[n] = initializer" |
| 224 | // Note that this does not apply to declarations like "type[n] a = initializer" |
| 225 | TIntermAggregate *parseSingleArrayInitDeclaration(TPublicType &publicType, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 226 | const TSourceLoc &identifierLocation, |
| 227 | const TString &identifier, |
| 228 | const TSourceLoc &indexLocation, |
| 229 | TIntermTyped *indexExpression, |
| 230 | const TSourceLoc &initLocation, |
| 231 | TIntermTyped *initializer); |
Olli Etuaho | 3875ffd | 2015-04-10 16:45:14 +0300 | [diff] [blame] | 232 | |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame^] | 233 | TIntermAggregate *parseInvariantDeclaration(const TTypeQualifierBuilder &typeQualifierBuilder, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 234 | const TSourceLoc &identifierLoc, |
| 235 | const TString *identifier, |
| 236 | const TSymbol *symbol); |
Olli Etuaho | e7847b0 | 2015-03-16 11:56:12 +0200 | [diff] [blame] | 237 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 238 | TIntermAggregate *parseDeclarator(TPublicType &publicType, |
| 239 | TIntermAggregate *aggregateDeclaration, |
| 240 | const TSourceLoc &identifierLocation, |
| 241 | const TString &identifier); |
| 242 | TIntermAggregate *parseArrayDeclarator(TPublicType &publicType, |
| 243 | TIntermAggregate *aggregateDeclaration, |
| 244 | const TSourceLoc &identifierLocation, |
| 245 | const TString &identifier, |
| 246 | const TSourceLoc &arrayLocation, |
| 247 | TIntermTyped *indexExpression); |
| 248 | TIntermAggregate *parseInitDeclarator(const TPublicType &publicType, |
| 249 | TIntermAggregate *aggregateDeclaration, |
| 250 | const TSourceLoc &identifierLocation, |
| 251 | const TString &identifier, |
| 252 | const TSourceLoc &initLocation, |
| 253 | TIntermTyped *initializer); |
Olli Etuaho | e7847b0 | 2015-03-16 11:56:12 +0200 | [diff] [blame] | 254 | |
Olli Etuaho | 3875ffd | 2015-04-10 16:45:14 +0300 | [diff] [blame] | 255 | // Parse a declarator like "a[n] = initializer" |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 256 | TIntermAggregate *parseArrayInitDeclarator(const TPublicType &publicType, |
| 257 | TIntermAggregate *aggregateDeclaration, |
| 258 | const TSourceLoc &identifierLocation, |
| 259 | const TString &identifier, |
| 260 | const TSourceLoc &indexLocation, |
| 261 | TIntermTyped *indexExpression, |
| 262 | const TSourceLoc &initLocation, |
| 263 | TIntermTyped *initializer); |
Olli Etuaho | 3875ffd | 2015-04-10 16:45:14 +0300 | [diff] [blame] | 264 | |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame^] | 265 | void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder); |
Olli Etuaho | ee63f5d | 2016-01-04 11:34:54 +0200 | [diff] [blame] | 266 | TIntermAggregate *addFunctionPrototypeDeclaration(const TFunction &function, |
| 267 | const TSourceLoc &location); |
| 268 | TIntermAggregate *addFunctionDefinition(const TFunction &function, |
| 269 | TIntermAggregate *functionPrototype, |
| 270 | TIntermAggregate *functionBody, |
| 271 | const TSourceLoc &location); |
Jamie Madill | 185fb40 | 2015-06-12 15:48:48 -0400 | [diff] [blame] | 272 | void parseFunctionPrototype(const TSourceLoc &location, |
| 273 | TFunction *function, |
| 274 | TIntermAggregate **aggregateOut); |
| 275 | TFunction *parseFunctionDeclarator(const TSourceLoc &location, |
| 276 | TFunction *function); |
Olli Etuaho | 9de84a5 | 2016-06-14 17:36:01 +0300 | [diff] [blame] | 277 | TFunction *parseFunctionHeader(const TPublicType &type, |
| 278 | const TString *name, |
| 279 | const TSourceLoc &location); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 280 | TFunction *addConstructorFunc(const TPublicType &publicType); |
| 281 | TIntermTyped *addConstructor(TIntermNode *arguments, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 282 | TOperator op, |
| 283 | TFunction *fnCall, |
| 284 | const TSourceLoc &line); |
Olli Etuaho | 90892fb | 2016-07-14 14:44:51 +0300 | [diff] [blame] | 285 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 286 | TIntermTyped *addConstStruct( |
| 287 | const TString &identifier, TIntermTyped *node, const TSourceLoc& line); |
| 288 | TIntermTyped *addIndexExpression(TIntermTyped *baseExpression, |
| 289 | const TSourceLoc& location, |
| 290 | TIntermTyped *indexExpression); |
| 291 | TIntermTyped* addFieldSelectionExpression(TIntermTyped *baseExpression, |
| 292 | const TSourceLoc &dotLocation, |
| 293 | const TString &fieldString, |
| 294 | const TSourceLoc &fieldLocation); |
shannonwoods@chromium.org | a910088 | 2013-05-30 00:11:39 +0000 | [diff] [blame] | 295 | |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame^] | 296 | TFieldList *addStructDeclaratorListWithQualifiers( |
| 297 | const TTypeQualifierBuilder &typeQualifierBuilder, |
| 298 | TPublicType *typeSpecifier, |
| 299 | TFieldList *fieldList); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 300 | TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList); |
| 301 | TPublicType addStructure(const TSourceLoc &structLine, |
| 302 | const TSourceLoc &nameLine, |
| 303 | const TString *structName, |
| 304 | TFieldList *fieldList); |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 305 | |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame^] | 306 | TIntermAggregate *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 307 | const TSourceLoc &nameLine, |
| 308 | const TString &blockName, |
| 309 | TFieldList *fieldList, |
| 310 | const TString *instanceName, |
| 311 | const TSourceLoc &instanceLine, |
| 312 | TIntermTyped *arrayIndex, |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame^] | 313 | const TSourceLoc &arrayIndexLine); |
shannonwoods@chromium.org | 5668c5d | 2013-05-30 00:11:48 +0000 | [diff] [blame] | 314 | |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 315 | void parseLocalSize(const TString &qualifierType, |
| 316 | const TSourceLoc &qualifierTypeLine, |
| 317 | int intValue, |
| 318 | const TSourceLoc &intValueLine, |
| 319 | const std::string &intValueString, |
| 320 | size_t index, |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 321 | sh::WorkGroupSize *localSize); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 322 | TLayoutQualifier parseLayoutQualifier( |
| 323 | const TString &qualifierType, const TSourceLoc &qualifierTypeLine); |
| 324 | TLayoutQualifier parseLayoutQualifier(const TString &qualifierType, |
| 325 | const TSourceLoc &qualifierTypeLine, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 326 | int intValue, |
| 327 | const TSourceLoc &intValueLine); |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 328 | TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier, |
| 329 | TLayoutQualifier rightQualifier, |
| 330 | const TSourceLoc &rightQualifierLocation); |
shannonwoods@chromium.org | 302adfe | 2013-05-30 00:21:06 +0000 | [diff] [blame] | 331 | |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 332 | // Performs an error check for embedded struct declarations. |
Olli Etuaho | 383b791 | 2016-08-05 11:22:59 +0300 | [diff] [blame] | 333 | void enterStructDeclaration(const TSourceLoc &line, const TString &identifier); |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 334 | void exitStructDeclaration(); |
| 335 | |
Olli Etuaho | 8a17626 | 2016-08-16 14:23:01 +0300 | [diff] [blame] | 336 | void checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field); |
Olli Etuaho | 09b2247 | 2015-02-11 11:47:26 +0200 | [diff] [blame] | 337 | |
Olli Etuaho | a3a3666 | 2015-02-17 13:46:51 +0200 | [diff] [blame] | 338 | TIntermSwitch *addSwitch(TIntermTyped *init, TIntermAggregate *statementList, const TSourceLoc &loc); |
| 339 | TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc); |
| 340 | TIntermCase *addDefault(const TSourceLoc &loc); |
| 341 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 342 | TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc); |
| 343 | TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc); |
| 344 | TIntermTyped *addBinaryMath( |
| 345 | TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
| 346 | TIntermTyped *addBinaryMathBooleanResult( |
| 347 | TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
| 348 | TIntermTyped *addAssign( |
| 349 | TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
Olli Etuaho | 4930086 | 2015-02-20 14:54:49 +0200 | [diff] [blame] | 350 | |
Olli Etuaho | 0b2d2dc | 2015-11-04 16:35:32 +0200 | [diff] [blame] | 351 | TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
| 352 | |
Olli Etuaho | 4930086 | 2015-02-20 14:54:49 +0200 | [diff] [blame] | 353 | TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc); |
| 354 | TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc); |
Olli Etuaho | c4ba3be | 2015-03-02 14:42:24 +0200 | [diff] [blame] | 355 | |
Olli Etuaho | e1a94c6 | 2015-11-16 17:35:25 +0200 | [diff] [blame] | 356 | void checkTextureOffsetConst(TIntermAggregate *functionCall); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 357 | TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall, |
| 358 | TIntermNode *paramNode, |
| 359 | TIntermNode *thisNode, |
| 360 | const TSourceLoc &loc, |
| 361 | bool *fatalError); |
Olli Etuaho | fc1806e | 2015-03-17 13:03:11 +0200 | [diff] [blame] | 362 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 363 | TIntermTyped *addTernarySelection( |
| 364 | TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock, const TSourceLoc &line); |
Olli Etuaho | 5290174 | 2015-04-15 13:42:45 +0300 | [diff] [blame] | 365 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 366 | // TODO(jmadill): make these private |
| 367 | TIntermediate &intermediate; // to hold and build a parse tree |
| 368 | TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed |
| 369 | |
Olli Etuaho | fc1806e | 2015-03-17 13:03:11 +0200 | [diff] [blame] | 370 | private: |
Olli Etuaho | 90892fb | 2016-07-14 14:44:51 +0300 | [diff] [blame] | 371 | // Returns a clamped index. |
| 372 | int checkIndexOutOfRange(bool outOfRangeIndexIsError, |
| 373 | const TSourceLoc &location, |
| 374 | int index, |
| 375 | int arraySize, |
| 376 | const char *reason, |
| 377 | const char *token); |
| 378 | |
| 379 | // Constant folding for element access. Note that the returned node does not have the correct |
| 380 | // type - it is expected to be fixed later. |
| 381 | TIntermConstantUnion *foldVectorSwizzle(TVectorFields &fields, |
| 382 | TIntermConstantUnion *baseNode, |
| 383 | const TSourceLoc &location); |
| 384 | TIntermConstantUnion *foldMatrixSubscript(int index, |
| 385 | TIntermConstantUnion *baseNode, |
| 386 | const TSourceLoc &location); |
| 387 | TIntermConstantUnion *foldArraySubscript(int index, |
| 388 | TIntermConstantUnion *baseNode, |
| 389 | const TSourceLoc &location); |
| 390 | |
Olli Etuaho | 2935c58 | 2015-04-08 14:32:06 +0300 | [diff] [blame] | 391 | bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable); |
| 392 | |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 393 | void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line, |
| 394 | const TString &identifier, |
| 395 | TPublicType *type); |
Olli Etuaho | 376f1b5 | 2015-04-13 13:23:41 +0300 | [diff] [blame] | 396 | |
Olli Etuaho | 8a17626 | 2016-08-16 14:23:01 +0300 | [diff] [blame] | 397 | bool checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation, |
| 398 | const TPublicType &elementType); |
| 399 | |
Olli Etuaho | 1dded80 | 2016-08-18 18:13:13 +0300 | [diff] [blame] | 400 | // Assumes that multiplication op has already been set based on the types. |
| 401 | bool isMultiplicationTypeCombinationValid(TOperator op, const TType &left, const TType &right); |
| 402 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 403 | TIntermTyped *addBinaryMathInternal( |
| 404 | TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
| 405 | TIntermTyped *createAssign( |
| 406 | TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
Olli Etuaho | f6c694b | 2015-03-26 14:50:53 +0200 | [diff] [blame] | 407 | // The funcReturnType parameter is expected to be non-null when the operation is a built-in function. |
| 408 | // It is expected to be null for other unary operators. |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 409 | TIntermTyped *createUnaryMath( |
| 410 | TOperator op, TIntermTyped *child, const TSourceLoc &loc, const TType *funcReturnType); |
Olli Etuaho | d6b1428 | 2015-03-17 14:31:35 +0200 | [diff] [blame] | 411 | |
Olli Etuaho | 47fd36a | 2015-03-19 14:22:24 +0200 | [diff] [blame] | 412 | // Return true if the checks pass |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 413 | bool binaryOpCommonCheck( |
| 414 | TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
Olli Etuaho | fa33d58 | 2015-04-09 14:33:12 +0300 | [diff] [blame] | 415 | |
| 416 | // Set to true when the last/current declarator list was started with an empty declaration. |
| 417 | bool mDeferredSingleDeclarationErrorCheck; |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 418 | |
| 419 | sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack) |
| 420 | ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL. |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 421 | int mCompileOptions; // Options passed to TCompiler |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 422 | int mShaderVersion; |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 423 | TIntermNode *mTreeRoot; // root of parse tree being created |
| 424 | int mLoopNestingLevel; // 0 if outside all loops |
| 425 | int mStructNestingLevel; // incremented while parsing a struct declaration |
| 426 | int mSwitchNestingLevel; // 0 if outside all switch statements |
| 427 | const TType *mCurrentFunctionType; // the return type of the function that's currently being parsed |
| 428 | bool mFunctionReturnsValue; // true if a non-void function has a return |
| 429 | bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit. |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 430 | bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling |
| 431 | // ESSL1. |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 432 | TLayoutMatrixPacking mDefaultMatrixPacking; |
| 433 | TLayoutBlockStorage mDefaultBlockStorage; |
| 434 | TString mHashErrMsg; |
| 435 | TDiagnostics mDiagnostics; |
| 436 | TDirectiveHandler mDirectiveHandler; |
| 437 | pp::Preprocessor mPreprocessor; |
| 438 | void *mScanner; |
Jamie Madill | 14e95b3 | 2015-05-07 10:10:41 -0400 | [diff] [blame] | 439 | bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor |
| 440 | bool mUsesFragColor; |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 441 | bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or |
| 442 | // gl_Secondary FragColor or both. |
Olli Etuaho | e1a94c6 | 2015-11-16 17:35:25 +0200 | [diff] [blame] | 443 | int mMinProgramTexelOffset; |
| 444 | int mMaxProgramTexelOffset; |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 445 | |
| 446 | // keep track of local group size declared in layout. It should be declared only once. |
| 447 | bool mComputeShaderLocalSizeDeclared; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 448 | sh::WorkGroupSize mComputeShaderLocalSize; |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame^] | 449 | // keeps track whether we are declaring / defining a function |
| 450 | bool mDeclaringFunction; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 451 | }; |
| 452 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 453 | int PaParseStrings( |
| 454 | size_t count, const char *const string[], const int length[], TParseContext *context); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 455 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 456 | #endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_ |