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