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" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 12 | #include "compiler/translator/SymbolTable.h" |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame] | 13 | #include "compiler/translator/QualifierTypes.h" |
daniel@transgaming.com | b401a92 | 2012-10-26 18:58:24 +0000 | [diff] [blame] | 14 | #include "compiler/preprocessor/Preprocessor.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 15 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 16 | namespace sh |
| 17 | { |
| 18 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 19 | struct TMatrixFields |
| 20 | { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 21 | bool wholeRow; |
| 22 | bool wholeCol; |
| 23 | int row; |
| 24 | int col; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 25 | }; |
| 26 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 27 | // |
| 28 | // The following are extra variables needed during parsing, grouped together so |
| 29 | // they can be passed to the parser without needing a global. |
| 30 | // |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 31 | class TParseContext : angle::NonCopyable |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 32 | { |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 33 | public: |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 34 | TParseContext(TSymbolTable &symt, |
| 35 | TExtensionBehavior &ext, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 36 | sh::GLenum type, |
| 37 | ShShaderSpec spec, |
Qiankun Miao | 7ebb97f | 2016-09-08 18:01:50 +0800 | [diff] [blame] | 38 | ShCompileOptions options, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 39 | bool checksPrecErrors, |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 40 | TDiagnostics *diagnostics, |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 41 | const ShBuiltInResources &resources); |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 42 | ~TParseContext(); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 43 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 44 | 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 Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 51 | int numErrors() const { return mDiagnostics->numErrors(); } |
Olli Etuaho | 4de340a | 2016-12-16 09:32:03 +0000 | [diff] [blame] | 52 | void error(const TSourceLoc &loc, const char *reason, const char *token); |
| 53 | void warning(const TSourceLoc &loc, const char *reason, const char *token); |
Jamie Madill | 14e95b3 | 2015-05-07 10:10:41 -0400 | [diff] [blame] | 54 | |
Olli Etuaho | 7c3848e | 2015-11-04 13:19:17 +0200 | [diff] [blame] | 55 | // If isError is false, a warning will be reported instead. |
| 56 | void outOfRangeError(bool isError, |
| 57 | const TSourceLoc &loc, |
| 58 | const char *reason, |
Olli Etuaho | 4de340a | 2016-12-16 09:32:03 +0000 | [diff] [blame] | 59 | const char *token); |
Olli Etuaho | 7c3848e | 2015-11-04 13:19:17 +0200 | [diff] [blame] | 60 | |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 61 | TIntermBlock *getTreeRoot() const { return mTreeRoot; } |
| 62 | void setTreeRoot(TIntermBlock *treeRoot) { mTreeRoot = treeRoot; } |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 63 | |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 64 | bool getFragmentPrecisionHigh() const |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 65 | { |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 66 | return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300; |
| 67 | } |
| 68 | void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh) |
| 69 | { |
| 70 | mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh; |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 73 | void setLoopNestingLevel(int loopNestintLevel) { mLoopNestingLevel = loopNestintLevel; } |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 74 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 75 | void incrLoopNestingLevel() { ++mLoopNestingLevel; } |
| 76 | void decrLoopNestingLevel() { --mLoopNestingLevel; } |
| 77 | |
| 78 | void incrSwitchNestingLevel() { ++mSwitchNestingLevel; } |
| 79 | void decrSwitchNestingLevel() { --mSwitchNestingLevel; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 80 | |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 81 | bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; } |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 82 | sh::WorkGroupSize getComputeShaderLocalSize() const; |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 83 | |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 84 | int getNumViews() const { return mNumViews; } |
| 85 | |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame] | 86 | void enterFunctionDeclaration() { mDeclaringFunction = true; } |
| 87 | |
| 88 | void exitFunctionDeclaration() { mDeclaringFunction = false; } |
| 89 | |
| 90 | bool declaringFunction() const { return mDeclaringFunction; } |
| 91 | |
Olli Etuaho | 56229f1 | 2017-07-10 14:16:33 +0300 | [diff] [blame] | 92 | TIntermConstantUnion *addScalarLiteral(const TConstantUnion *constantUnion, |
| 93 | const TSourceLoc &line); |
| 94 | |
Jamie Madill | 5c09702 | 2014-08-20 16:38:32 -0400 | [diff] [blame] | 95 | // This method is guaranteed to succeed, even if no variable with 'name' exists. |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 96 | const TVariable *getNamedVariable(const TSourceLoc &location, |
| 97 | const TString *name, |
| 98 | const TSymbol *symbol); |
Olli Etuaho | 82c29ed | 2015-11-03 13:06:54 +0200 | [diff] [blame] | 99 | TIntermTyped *parseVariableIdentifier(const TSourceLoc &location, |
| 100 | const TString *name, |
| 101 | const TSymbol *symbol); |
Jamie Madill | 5c09702 | 2014-08-20 16:38:32 -0400 | [diff] [blame] | 102 | |
Olli Etuaho | eb7f90f | 2017-07-07 17:25:23 +0300 | [diff] [blame] | 103 | // Look at a '.' field selector string and change it into offsets for a vector. |
| 104 | bool parseVectorFields(const TSourceLoc &line, |
| 105 | const TString &compString, |
| 106 | int vecSize, |
| 107 | TVector<int> *fieldOffsets); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 108 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 109 | void assignError(const TSourceLoc &line, const char *op, TString left, TString right); |
| 110 | void unaryOpError(const TSourceLoc &line, const char *op, TString operand); |
| 111 | void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 112 | |
Olli Etuaho | 8a17626 | 2016-08-16 14:23:01 +0300 | [diff] [blame] | 113 | // Check functions - the ones that return bool return false if an error was generated. |
| 114 | |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 115 | bool checkIsNotReserved(const TSourceLoc &line, const TString &identifier); |
| 116 | void checkPrecisionSpecified(const TSourceLoc &line, TPrecision precision, TBasicType type); |
| 117 | bool checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node); |
| 118 | void checkIsConst(TIntermTyped *node); |
| 119 | void checkIsScalarInteger(TIntermTyped *node, const char *token); |
Qiankun Miao | f69682b | 2016-08-16 14:50:42 +0800 | [diff] [blame] | 120 | bool checkIsAtGlobalLevel(const TSourceLoc &line, const char *token); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 121 | bool checkConstructorArguments(const TSourceLoc &line, |
Olli Etuaho | af6fc1b | 2017-01-26 17:45:35 -0800 | [diff] [blame] | 122 | const TIntermSequence *arguments, |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 123 | const TType &type); |
| 124 | |
| 125 | // Returns a sanitized array size to use (the size is at least 1). |
| 126 | unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr); |
Olli Etuaho | 8a17626 | 2016-08-16 14:23:01 +0300 | [diff] [blame] | 127 | bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &elementQualifier); |
| 128 | bool checkIsValidTypeForArray(const TSourceLoc &line, const TPublicType &elementType); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 129 | bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type); |
Olli Etuaho | 56229f1 | 2017-07-10 14:16:33 +0300 | [diff] [blame] | 130 | bool checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 131 | void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType); |
jchen10 | cc2a10e | 2017-05-03 14:05:12 +0800 | [diff] [blame] | 132 | bool checkIsNotOpaqueType(const TSourceLoc &line, |
| 133 | const TTypeSpecifierNonArray &pType, |
| 134 | const char *reason); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 135 | void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType); |
| 136 | void checkLocationIsNotSpecified(const TSourceLoc &location, |
| 137 | const TLayoutQualifier &layoutQualifier); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 138 | void checkIsParameterQualifierValid(const TSourceLoc &line, |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame] | 139 | const TTypeQualifierBuilder &typeQualifierBuilder, |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 140 | TType *type); |
| 141 | bool checkCanUseExtension(const TSourceLoc &line, const TString &extension); |
Olli Etuaho | bb7e5a7 | 2017-04-24 10:16:44 +0300 | [diff] [blame] | 142 | |
| 143 | // Done for all declarations, whether empty or not. |
| 144 | void declarationQualifierErrorCheck(const sh::TQualifier qualifier, |
| 145 | const sh::TLayoutQualifier &layoutQualifier, |
| 146 | const TSourceLoc &location); |
| 147 | // Done for the first non-empty declarator in a declaration. |
| 148 | void nonEmptyDeclarationErrorCheck(const TPublicType &publicType, |
| 149 | const TSourceLoc &identifierLocation); |
| 150 | // Done only for empty declarations. |
Martin Radev | b8b0122 | 2016-11-20 23:25:53 +0200 | [diff] [blame] | 151 | void emptyDeclarationErrorCheck(const TPublicType &publicType, const TSourceLoc &location); |
Olli Etuaho | bb7e5a7 | 2017-04-24 10:16:44 +0300 | [diff] [blame] | 152 | |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 153 | void checkLayoutQualifierSupported(const TSourceLoc &location, |
| 154 | const TString &layoutQualifierName, |
| 155 | int versionRequired); |
| 156 | bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location, |
| 157 | const TLayoutQualifier &layoutQualifier); |
Jiajia Qin | bc58515 | 2017-06-23 15:42:17 +0800 | [diff] [blame] | 158 | void functionCallRValueLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall); |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame] | 159 | void checkInvariantVariableQualifier(bool invariant, |
| 160 | const TQualifier qualifier, |
| 161 | const TSourceLoc &invariantLocation); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 162 | void checkInputOutputTypeIsValidES3(const TQualifier qualifier, |
| 163 | const TPublicType &type, |
| 164 | const TSourceLoc &qualifierLocation); |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 165 | void checkLocalVariableConstStorageQualifier(const TQualifierWrapperBase &qualifier); |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 166 | const TPragma &pragma() const { return mDirectiveHandler.pragma(); } |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 167 | const TExtensionBehavior &extensionBehavior() const |
| 168 | { |
| 169 | return mDirectiveHandler.extensionBehavior(); |
| 170 | } |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 171 | bool supportsExtension(const char *extension); |
| 172 | bool isExtensionEnabled(const char *extension) const; |
Olli Etuaho | 95468d1 | 2017-05-04 11:14:34 +0300 | [diff] [blame] | 173 | bool isMultiviewExtensionEnabled() const |
| 174 | { |
| 175 | return mMultiviewAvailable && |
| 176 | (isExtensionEnabled("GL_OVR_multiview") || isExtensionEnabled("GL_OVR_multiview2")); |
| 177 | } |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 178 | void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 179 | void handlePragmaDirective(const TSourceLoc &loc, |
| 180 | const char *name, |
| 181 | const char *value, |
| 182 | bool stdgl); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 183 | |
Olli Etuaho | 914b79a | 2017-06-19 16:03:19 +0300 | [diff] [blame] | 184 | // Returns true on success. *initNode may still be nullptr on success in case the initialization |
| 185 | // is not needed in the AST. |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 186 | bool executeInitializer(const TSourceLoc &line, |
| 187 | const TString &identifier, |
| 188 | const TPublicType &pType, |
| 189 | TIntermTyped *initializer, |
Olli Etuaho | 13389b6 | 2016-10-16 11:48:18 +0100 | [diff] [blame] | 190 | TIntermBinary **initNode); |
Olli Etuaho | 914b79a | 2017-06-19 16:03:19 +0300 | [diff] [blame] | 191 | TIntermNode *addConditionInitializer(const TPublicType &pType, |
| 192 | const TString &identifier, |
| 193 | TIntermTyped *initializer, |
| 194 | const TSourceLoc &loc); |
| 195 | TIntermNode *addLoop(TLoopType type, |
| 196 | TIntermNode *init, |
| 197 | TIntermNode *cond, |
| 198 | TIntermTyped *expr, |
| 199 | TIntermNode *body, |
| 200 | const TSourceLoc &loc); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 201 | |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 202 | // For "if" test nodes. There are three children: a condition, a true path, and a false path. |
| 203 | // The two paths are in TIntermNodePair code. |
| 204 | TIntermNode *addIfElse(TIntermTyped *cond, TIntermNodePair code, const TSourceLoc &loc); |
| 205 | |
Olli Etuaho | 0e3aee3 | 2016-10-27 12:56:38 +0100 | [diff] [blame] | 206 | void addFullySpecifiedType(TPublicType *typeSpecifier); |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame] | 207 | TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 208 | const TPublicType &typeSpecifier); |
Olli Etuaho | e7847b0 | 2015-03-16 11:56:12 +0200 | [diff] [blame] | 209 | |
Olli Etuaho | 13389b6 | 2016-10-16 11:48:18 +0100 | [diff] [blame] | 210 | TIntermDeclaration *parseSingleDeclaration(TPublicType &publicType, |
| 211 | const TSourceLoc &identifierOrTypeLocation, |
| 212 | const TString &identifier); |
| 213 | TIntermDeclaration *parseSingleArrayDeclaration(TPublicType &publicType, |
| 214 | const TSourceLoc &identifierLocation, |
| 215 | const TString &identifier, |
| 216 | const TSourceLoc &indexLocation, |
| 217 | TIntermTyped *indexExpression); |
| 218 | TIntermDeclaration *parseSingleInitDeclaration(const TPublicType &publicType, |
| 219 | const TSourceLoc &identifierLocation, |
| 220 | const TString &identifier, |
| 221 | const TSourceLoc &initLocation, |
| 222 | TIntermTyped *initializer); |
Jamie Madill | 47e3ec0 | 2014-08-20 16:38:33 -0400 | [diff] [blame] | 223 | |
Olli Etuaho | 3875ffd | 2015-04-10 16:45:14 +0300 | [diff] [blame] | 224 | // Parse a declaration like "type a[n] = initializer" |
| 225 | // 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] | 226 | TIntermDeclaration *parseSingleArrayInitDeclaration(TPublicType &publicType, |
| 227 | const TSourceLoc &identifierLocation, |
| 228 | const TString &identifier, |
| 229 | const TSourceLoc &indexLocation, |
| 230 | TIntermTyped *indexExpression, |
| 231 | const TSourceLoc &initLocation, |
| 232 | TIntermTyped *initializer); |
Olli Etuaho | 3875ffd | 2015-04-10 16:45:14 +0300 | [diff] [blame] | 233 | |
Olli Etuaho | bf4e1b7 | 2016-12-09 11:30:15 +0000 | [diff] [blame] | 234 | TIntermInvariantDeclaration *parseInvariantDeclaration( |
| 235 | const TTypeQualifierBuilder &typeQualifierBuilder, |
| 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 | |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 267 | void parseDefaultPrecisionQualifier(const TPrecision precision, |
| 268 | const TPublicType &type, |
| 269 | const TSourceLoc &loc); |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame] | 270 | void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder); |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 271 | |
Olli Etuaho | 16c745a | 2017-01-16 17:02:27 +0000 | [diff] [blame] | 272 | TIntermFunctionPrototype *addFunctionPrototypeDeclaration(const TFunction &parsedFunction, |
| 273 | const TSourceLoc &location); |
Olli Etuaho | 8ad9e75 | 2017-01-16 19:55:20 +0000 | [diff] [blame] | 274 | TIntermFunctionDefinition *addFunctionDefinition(TIntermFunctionPrototype *functionPrototype, |
Olli Etuaho | 336b147 | 2016-10-05 16:37:55 +0100 | [diff] [blame] | 275 | TIntermBlock *functionBody, |
| 276 | const TSourceLoc &location); |
Olli Etuaho | 476197f | 2016-10-11 13:59:08 +0100 | [diff] [blame] | 277 | void parseFunctionDefinitionHeader(const TSourceLoc &location, |
| 278 | TFunction **function, |
Olli Etuaho | 8ad9e75 | 2017-01-16 19:55:20 +0000 | [diff] [blame] | 279 | TIntermFunctionPrototype **prototypeOut); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 280 | TFunction *parseFunctionDeclarator(const TSourceLoc &location, TFunction *function); |
Olli Etuaho | 9de84a5 | 2016-06-14 17:36:01 +0300 | [diff] [blame] | 281 | TFunction *parseFunctionHeader(const TPublicType &type, |
| 282 | const TString *name, |
| 283 | const TSourceLoc &location); |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 284 | TFunction *addNonConstructorFunc(const TString *name, const TSourceLoc &loc); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 285 | TFunction *addConstructorFunc(const TPublicType &publicType); |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 286 | TParameter parseParameterDeclarator(const TPublicType &publicType, |
| 287 | const TString *name, |
| 288 | const TSourceLoc &nameLoc); |
| 289 | TParameter parseParameterArrayDeclarator(const TString *identifier, |
| 290 | const TSourceLoc &identifierLoc, |
| 291 | TIntermTyped *arraySize, |
| 292 | const TSourceLoc &arrayLoc, |
| 293 | TPublicType *type); |
Olli Etuaho | 90892fb | 2016-07-14 14:44:51 +0300 | [diff] [blame] | 294 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 295 | TIntermTyped *addIndexExpression(TIntermTyped *baseExpression, |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 296 | const TSourceLoc &location, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 297 | TIntermTyped *indexExpression); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 298 | TIntermTyped *addFieldSelectionExpression(TIntermTyped *baseExpression, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 299 | const TSourceLoc &dotLocation, |
| 300 | const TString &fieldString, |
| 301 | const TSourceLoc &fieldLocation); |
shannonwoods@chromium.org | a910088 | 2013-05-30 00:11:39 +0000 | [diff] [blame] | 302 | |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 303 | // Parse declarator for a single field |
| 304 | TField *parseStructDeclarator(TString *identifier, const TSourceLoc &loc); |
| 305 | TField *parseStructArrayDeclarator(TString *identifier, |
| 306 | const TSourceLoc &loc, |
| 307 | TIntermTyped *arraySize, |
| 308 | const TSourceLoc &arraySizeLoc); |
| 309 | |
Olli Etuaho | 4de340a | 2016-12-16 09:32:03 +0000 | [diff] [blame] | 310 | TFieldList *combineStructFieldLists(TFieldList *processedFields, |
| 311 | const TFieldList *newlyAddedFields, |
| 312 | const TSourceLoc &location); |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame] | 313 | TFieldList *addStructDeclaratorListWithQualifiers( |
| 314 | const TTypeQualifierBuilder &typeQualifierBuilder, |
| 315 | TPublicType *typeSpecifier, |
| 316 | TFieldList *fieldList); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 317 | TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList); |
Martin Radev | 4a9cd80 | 2016-09-01 16:51:51 +0300 | [diff] [blame] | 318 | TTypeSpecifierNonArray addStructure(const TSourceLoc &structLine, |
| 319 | const TSourceLoc &nameLine, |
| 320 | const TString *structName, |
| 321 | TFieldList *fieldList); |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 322 | |
Olli Etuaho | 13389b6 | 2016-10-16 11:48:18 +0100 | [diff] [blame] | 323 | TIntermDeclaration *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder, |
| 324 | const TSourceLoc &nameLine, |
| 325 | const TString &blockName, |
| 326 | TFieldList *fieldList, |
| 327 | const TString *instanceName, |
| 328 | const TSourceLoc &instanceLine, |
| 329 | TIntermTyped *arrayIndex, |
| 330 | const TSourceLoc &arrayIndexLine); |
shannonwoods@chromium.org | 5668c5d | 2013-05-30 00:11:48 +0000 | [diff] [blame] | 331 | |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 332 | void parseLocalSize(const TString &qualifierType, |
| 333 | const TSourceLoc &qualifierTypeLine, |
| 334 | int intValue, |
| 335 | const TSourceLoc &intValueLine, |
| 336 | const std::string &intValueString, |
| 337 | size_t index, |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 338 | sh::WorkGroupSize *localSize); |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 339 | void parseNumViews(int intValue, |
| 340 | const TSourceLoc &intValueLine, |
| 341 | const std::string &intValueString, |
| 342 | int *numViews); |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 343 | void parseInvocations(int intValue, |
| 344 | const TSourceLoc &intValueLine, |
| 345 | const std::string &intValueString, |
| 346 | int *numInvocations); |
| 347 | void parseMaxVertices(int intValue, |
| 348 | const TSourceLoc &intValueLine, |
| 349 | const std::string &intValueString, |
| 350 | int *numMaxVertices); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 351 | TLayoutQualifier parseLayoutQualifier(const TString &qualifierType, |
| 352 | const TSourceLoc &qualifierTypeLine); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 353 | TLayoutQualifier parseLayoutQualifier(const TString &qualifierType, |
| 354 | const TSourceLoc &qualifierTypeLine, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 355 | int intValue, |
| 356 | const TSourceLoc &intValueLine); |
Olli Etuaho | 613b959 | 2016-09-05 12:05:53 +0300 | [diff] [blame] | 357 | TTypeQualifierBuilder *createTypeQualifierBuilder(const TSourceLoc &loc); |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 358 | TStorageQualifierWrapper *parseGlobalStorageQualifier(TQualifier qualifier, |
| 359 | const TSourceLoc &loc); |
| 360 | TStorageQualifierWrapper *parseVaryingQualifier(const TSourceLoc &loc); |
| 361 | TStorageQualifierWrapper *parseInQualifier(const TSourceLoc &loc); |
| 362 | TStorageQualifierWrapper *parseOutQualifier(const TSourceLoc &loc); |
| 363 | TStorageQualifierWrapper *parseInOutQualifier(const TSourceLoc &loc); |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 364 | TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier, |
| 365 | TLayoutQualifier rightQualifier, |
| 366 | const TSourceLoc &rightQualifierLocation); |
shannonwoods@chromium.org | 302adfe | 2013-05-30 00:21:06 +0000 | [diff] [blame] | 367 | |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 368 | // Performs an error check for embedded struct declarations. |
Olli Etuaho | 383b791 | 2016-08-05 11:22:59 +0300 | [diff] [blame] | 369 | void enterStructDeclaration(const TSourceLoc &line, const TString &identifier); |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 370 | void exitStructDeclaration(); |
| 371 | |
Olli Etuaho | 8a17626 | 2016-08-16 14:23:01 +0300 | [diff] [blame] | 372 | void checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field); |
Olli Etuaho | 09b2247 | 2015-02-11 11:47:26 +0200 | [diff] [blame] | 373 | |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 374 | TIntermSwitch *addSwitch(TIntermTyped *init, |
| 375 | TIntermBlock *statementList, |
| 376 | const TSourceLoc &loc); |
Olli Etuaho | a3a3666 | 2015-02-17 13:46:51 +0200 | [diff] [blame] | 377 | TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc); |
| 378 | TIntermCase *addDefault(const TSourceLoc &loc); |
| 379 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 380 | TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc); |
| 381 | TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 382 | TIntermTyped *addBinaryMath(TOperator op, |
| 383 | TIntermTyped *left, |
| 384 | TIntermTyped *right, |
| 385 | const TSourceLoc &loc); |
| 386 | TIntermTyped *addBinaryMathBooleanResult(TOperator op, |
| 387 | TIntermTyped *left, |
| 388 | TIntermTyped *right, |
| 389 | const TSourceLoc &loc); |
| 390 | TIntermTyped *addAssign(TOperator op, |
| 391 | TIntermTyped *left, |
| 392 | TIntermTyped *right, |
| 393 | const TSourceLoc &loc); |
Olli Etuaho | 4930086 | 2015-02-20 14:54:49 +0200 | [diff] [blame] | 394 | |
Olli Etuaho | 0b2d2dc | 2015-11-04 16:35:32 +0200 | [diff] [blame] | 395 | TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
| 396 | |
Olli Etuaho | 4930086 | 2015-02-20 14:54:49 +0200 | [diff] [blame] | 397 | TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc); |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 398 | TIntermBranch *addBranch(TOperator op, TIntermTyped *expression, const TSourceLoc &loc); |
Olli Etuaho | c4ba3be | 2015-03-02 14:42:24 +0200 | [diff] [blame] | 399 | |
Olli Etuaho | e1a94c6 | 2015-11-16 17:35:25 +0200 | [diff] [blame] | 400 | void checkTextureOffsetConst(TIntermAggregate *functionCall); |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 401 | void checkImageMemoryAccessForBuiltinFunctions(TIntermAggregate *functionCall); |
| 402 | void checkImageMemoryAccessForUserDefinedFunctions(const TFunction *functionDefinition, |
| 403 | const TIntermAggregate *functionCall); |
Olli Etuaho | af6fc1b | 2017-01-26 17:45:35 -0800 | [diff] [blame] | 404 | TIntermSequence *createEmptyArgumentsList(); |
Olli Etuaho | 72d1020 | 2017-01-19 15:58:30 +0000 | [diff] [blame] | 405 | |
Olli Etuaho | af6fc1b | 2017-01-26 17:45:35 -0800 | [diff] [blame] | 406 | // fnCall is only storing the built-in op, and function name or constructor type. arguments |
Olli Etuaho | 72d1020 | 2017-01-19 15:58:30 +0000 | [diff] [blame] | 407 | // has the arguments. |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 408 | TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall, |
Olli Etuaho | af6fc1b | 2017-01-26 17:45:35 -0800 | [diff] [blame] | 409 | TIntermSequence *arguments, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 410 | TIntermNode *thisNode, |
Olli Etuaho | 72d1020 | 2017-01-19 15:58:30 +0000 | [diff] [blame] | 411 | const TSourceLoc &loc); |
Olli Etuaho | fc1806e | 2015-03-17 13:03:11 +0200 | [diff] [blame] | 412 | |
Olli Etuaho | d0bad2c | 2016-09-09 18:01:16 +0300 | [diff] [blame] | 413 | TIntermTyped *addTernarySelection(TIntermTyped *cond, |
| 414 | TIntermTyped *trueExpression, |
| 415 | TIntermTyped *falseExpression, |
| 416 | const TSourceLoc &line); |
Olli Etuaho | 5290174 | 2015-04-15 13:42:45 +0300 | [diff] [blame] | 417 | |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 418 | int getGeometryShaderMaxVertices() const { return mGeometryShaderMaxVertices; } |
| 419 | int getGeometryShaderInvocations() const |
| 420 | { |
| 421 | return (mGeometryShaderInvocations > 0) ? mGeometryShaderInvocations : 1; |
| 422 | } |
| 423 | TLayoutPrimitiveType getGeometryShaderInputPrimitiveType() const |
| 424 | { |
| 425 | return mGeometryShaderInputPrimitiveType; |
| 426 | } |
| 427 | TLayoutPrimitiveType getGeometryShaderOutputPrimitiveType() const |
| 428 | { |
| 429 | return mGeometryShaderOutputPrimitiveType; |
| 430 | } |
| 431 | |
Olli Etuaho | 56229f1 | 2017-07-10 14:16:33 +0300 | [diff] [blame] | 432 | // TODO(jmadill): make this private |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 433 | TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed |
| 434 | |
Olli Etuaho | fc1806e | 2015-03-17 13:03:11 +0200 | [diff] [blame] | 435 | private: |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 436 | class AtomicCounterBindingState; |
| 437 | constexpr static size_t kAtomicCounterSize = 4; |
| 438 | // UNIFORM_ARRAY_STRIDE for atomic counter arrays is an implementation-dependent value which |
| 439 | // can be queried after a program is linked according to ES 3.10 section 7.7.1. This is |
| 440 | // controversial with the offset inheritance as described in ESSL 3.10 section 4.4.6. Currently |
| 441 | // we treat it as always 4 in favour of the original interpretation in |
| 442 | // "ARB_shader_atomic_counters". |
| 443 | // TODO(jie.a.chen@intel.com): Double check this once the spec vagueness is resolved. |
| 444 | constexpr static size_t kAtomicCounterArrayStride = 4; |
| 445 | |
Olli Etuaho | 4de340a | 2016-12-16 09:32:03 +0000 | [diff] [blame] | 446 | // Returns a clamped index. If it prints out an error message, the token is "[]". |
Olli Etuaho | 90892fb | 2016-07-14 14:44:51 +0300 | [diff] [blame] | 447 | int checkIndexOutOfRange(bool outOfRangeIndexIsError, |
| 448 | const TSourceLoc &location, |
| 449 | int index, |
| 450 | int arraySize, |
Olli Etuaho | 4de340a | 2016-12-16 09:32:03 +0000 | [diff] [blame] | 451 | const char *reason); |
Olli Etuaho | 90892fb | 2016-07-14 14:44:51 +0300 | [diff] [blame] | 452 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 453 | bool declareVariable(const TSourceLoc &line, |
| 454 | const TString &identifier, |
| 455 | const TType &type, |
| 456 | TVariable **variable); |
Olli Etuaho | 2935c58 | 2015-04-08 14:32:06 +0300 | [diff] [blame] | 457 | |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 458 | void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line, |
| 459 | const TString &identifier, |
| 460 | TPublicType *type); |
Olli Etuaho | 376f1b5 | 2015-04-13 13:23:41 +0300 | [diff] [blame] | 461 | |
Olli Etuaho | 8a17626 | 2016-08-16 14:23:01 +0300 | [diff] [blame] | 462 | bool checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation, |
| 463 | const TPublicType &elementType); |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 464 | // Done for all atomic counter declarations, whether empty or not. |
| 465 | void atomicCounterQualifierErrorCheck(const TPublicType &publicType, |
| 466 | const TSourceLoc &location); |
Olli Etuaho | 8a17626 | 2016-08-16 14:23:01 +0300 | [diff] [blame] | 467 | |
Olli Etuaho | 1dded80 | 2016-08-18 18:13:13 +0300 | [diff] [blame] | 468 | // Assumes that multiplication op has already been set based on the types. |
| 469 | bool isMultiplicationTypeCombinationValid(TOperator op, const TType &left, const TType &right); |
| 470 | |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 471 | void checkOutParameterIsNotOpaqueType(const TSourceLoc &line, |
| 472 | TQualifier qualifier, |
| 473 | const TType &type); |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 474 | |
Olli Etuaho | 4336489 | 2017-02-13 16:00:12 +0000 | [diff] [blame] | 475 | void checkInternalFormatIsNotSpecified(const TSourceLoc &location, |
| 476 | TLayoutImageInternalFormat internalFormat); |
| 477 | void checkMemoryQualifierIsNotSpecified(const TMemoryQualifier &memoryQualifier, |
| 478 | const TSourceLoc &location); |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 479 | void checkAtomicCounterOffsetIsNotOverlapped(TPublicType &publicType, |
| 480 | size_t size, |
| 481 | bool forceAppend, |
| 482 | const TSourceLoc &loc, |
| 483 | TType &type); |
Olli Etuaho | 4336489 | 2017-02-13 16:00:12 +0000 | [diff] [blame] | 484 | void checkBindingIsValid(const TSourceLoc &identifierLocation, const TType &type); |
| 485 | void checkBindingIsNotSpecified(const TSourceLoc &location, int binding); |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 486 | void checkOffsetIsNotSpecified(const TSourceLoc &location, int offset); |
Olli Etuaho | 96f6adf | 2017-08-16 11:18:54 +0300 | [diff] [blame^] | 487 | void checkImageBindingIsValid(const TSourceLoc &location, |
| 488 | int binding, |
| 489 | int arrayTotalElementCount); |
| 490 | void checkSamplerBindingIsValid(const TSourceLoc &location, |
| 491 | int binding, |
| 492 | int arrayTotalElementCount); |
Jiajia Qin | bc58515 | 2017-06-23 15:42:17 +0800 | [diff] [blame] | 493 | void checkBlockBindingIsValid(const TSourceLoc &location, |
| 494 | const TQualifier &qualifier, |
| 495 | int binding, |
| 496 | int arraySize); |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 497 | void checkAtomicCounterBindingIsValid(const TSourceLoc &location, int binding); |
Olli Etuaho | 4336489 | 2017-02-13 16:00:12 +0000 | [diff] [blame] | 498 | |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 499 | void checkUniformLocationInRange(const TSourceLoc &location, |
| 500 | int objectLocationCount, |
| 501 | const TLayoutQualifier &layoutQualifier); |
| 502 | |
Andrei Volykhin | a552707 | 2017-03-22 16:46:30 +0300 | [diff] [blame] | 503 | void checkYuvIsNotSpecified(const TSourceLoc &location, bool yuv); |
| 504 | |
Olli Etuaho | 96f6adf | 2017-08-16 11:18:54 +0300 | [diff] [blame^] | 505 | bool checkUnsizedArrayConstructorArgumentDimensionality(TIntermSequence *arguments, |
| 506 | TType type, |
| 507 | const TSourceLoc &line); |
| 508 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 509 | TIntermTyped *addBinaryMathInternal(TOperator op, |
| 510 | TIntermTyped *left, |
| 511 | TIntermTyped *right, |
| 512 | const TSourceLoc &loc); |
Olli Etuaho | 13389b6 | 2016-10-16 11:48:18 +0100 | [diff] [blame] | 513 | TIntermBinary *createAssign(TOperator op, |
| 514 | TIntermTyped *left, |
| 515 | TIntermTyped *right, |
| 516 | const TSourceLoc &loc); |
Olli Etuaho | af6fc1b | 2017-01-26 17:45:35 -0800 | [diff] [blame] | 517 | TIntermTyped *createUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc); |
| 518 | |
| 519 | TIntermTyped *addMethod(TFunction *fnCall, |
| 520 | TIntermSequence *arguments, |
| 521 | TIntermNode *thisNode, |
| 522 | const TSourceLoc &loc); |
| 523 | TIntermTyped *addConstructor(TIntermSequence *arguments, |
Olli Etuaho | af6fc1b | 2017-01-26 17:45:35 -0800 | [diff] [blame] | 524 | TType type, |
| 525 | const TSourceLoc &line); |
| 526 | TIntermTyped *addNonConstructorFunctionCall(TFunction *fnCall, |
| 527 | TIntermSequence *arguments, |
| 528 | const TSourceLoc &loc); |
Olli Etuaho | d6b1428 | 2015-03-17 14:31:35 +0200 | [diff] [blame] | 529 | |
Olli Etuaho | 47fd36a | 2015-03-19 14:22:24 +0200 | [diff] [blame] | 530 | // Return true if the checks pass |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 531 | bool binaryOpCommonCheck(TOperator op, |
| 532 | TIntermTyped *left, |
| 533 | TIntermTyped *right, |
| 534 | const TSourceLoc &loc); |
Olli Etuaho | fa33d58 | 2015-04-09 14:33:12 +0300 | [diff] [blame] | 535 | |
Olli Etuaho | 8ad9e75 | 2017-01-16 19:55:20 +0000 | [diff] [blame] | 536 | TIntermFunctionPrototype *createPrototypeNodeFromFunction(const TFunction &function, |
| 537 | const TSourceLoc &location, |
| 538 | bool insertParametersToSymbolTable); |
| 539 | |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 540 | void setAtomicCounterBindingDefaultOffset(const TPublicType &declaration, |
| 541 | const TSourceLoc &location); |
| 542 | |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 543 | bool checkPrimitiveTypeMatchesTypeQualifier(const TTypeQualifier &typeQualifier); |
| 544 | bool parseGeometryShaderInputLayoutQualifier(const TTypeQualifier &typeQualifier); |
| 545 | bool parseGeometryShaderOutputLayoutQualifier(const TTypeQualifier &typeQualifier); |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 546 | void setGeometryShaderInputArraySizes(); |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 547 | |
Olli Etuaho | bb7e5a7 | 2017-04-24 10:16:44 +0300 | [diff] [blame] | 548 | // Set to true when the last/current declarator list was started with an empty declaration. The |
| 549 | // non-empty declaration error check will need to be performed if the empty declaration is |
| 550 | // followed by a declarator. |
| 551 | bool mDeferredNonEmptyDeclarationErrorCheck; |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 552 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 553 | sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack) |
Qiankun Miao | 7ebb97f | 2016-09-08 18:01:50 +0800 | [diff] [blame] | 554 | ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL. |
| 555 | ShCompileOptions mCompileOptions; // Options passed to TCompiler |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 556 | int mShaderVersion; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 557 | TIntermBlock *mTreeRoot; // root of parse tree being created |
| 558 | int mLoopNestingLevel; // 0 if outside all loops |
| 559 | int mStructNestingLevel; // incremented while parsing a struct declaration |
| 560 | int mSwitchNestingLevel; // 0 if outside all switch statements |
Qiankun Miao | 7ebb97f | 2016-09-08 18:01:50 +0800 | [diff] [blame] | 561 | const TType |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 562 | *mCurrentFunctionType; // the return type of the function that's currently being parsed |
| 563 | bool mFunctionReturnsValue; // true if a non-void function has a return |
Qiankun Miao | 7ebb97f | 2016-09-08 18:01:50 +0800 | [diff] [blame] | 564 | bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared |
| 565 | // without precision, explicit or implicit. |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 566 | bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling |
| 567 | // ESSL1. |
Jiajia Qin | bc58515 | 2017-06-23 15:42:17 +0800 | [diff] [blame] | 568 | TLayoutMatrixPacking mDefaultUniformMatrixPacking; |
| 569 | TLayoutBlockStorage mDefaultUniformBlockStorage; |
| 570 | TLayoutMatrixPacking mDefaultBufferMatrixPacking; |
| 571 | TLayoutBlockStorage mDefaultBufferBlockStorage; |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 572 | TString mHashErrMsg; |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 573 | TDiagnostics *mDiagnostics; |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 574 | TDirectiveHandler mDirectiveHandler; |
| 575 | pp::Preprocessor mPreprocessor; |
| 576 | void *mScanner; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 577 | bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor |
Jamie Madill | 14e95b3 | 2015-05-07 10:10:41 -0400 | [diff] [blame] | 578 | bool mUsesFragColor; |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 579 | bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or |
| 580 | // gl_Secondary FragColor or both. |
Olli Etuaho | e1a94c6 | 2015-11-16 17:35:25 +0200 | [diff] [blame] | 581 | int mMinProgramTexelOffset; |
| 582 | int mMaxProgramTexelOffset; |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 583 | |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 584 | bool mMultiviewAvailable; |
| 585 | |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 586 | // keep track of local group size declared in layout. It should be declared only once. |
| 587 | bool mComputeShaderLocalSizeDeclared; |
Martin Radev | 4c4c8e7 | 2016-08-04 12:25:34 +0300 | [diff] [blame] | 588 | sh::WorkGroupSize mComputeShaderLocalSize; |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 589 | // keep track of number of views declared in layout. |
| 590 | int mNumViews; |
| 591 | int mMaxNumViews; |
Olli Etuaho | 4336489 | 2017-02-13 16:00:12 +0000 | [diff] [blame] | 592 | int mMaxImageUnits; |
| 593 | int mMaxCombinedTextureImageUnits; |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 594 | int mMaxUniformLocations; |
jchen10 | af713a2 | 2017-04-19 09:10:56 +0800 | [diff] [blame] | 595 | int mMaxUniformBufferBindings; |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 596 | int mMaxAtomicCounterBindings; |
Jiajia Qin | bc58515 | 2017-06-23 15:42:17 +0800 | [diff] [blame] | 597 | int mMaxShaderStorageBufferBindings; |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 598 | |
Martin Radev | 70866b8 | 2016-07-22 15:27:42 +0300 | [diff] [blame] | 599 | // keeps track whether we are declaring / defining a function |
| 600 | bool mDeclaringFunction; |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 601 | |
| 602 | // Track the state of each atomic counter binding. |
| 603 | std::map<int, AtomicCounterBindingState> mAtomicCounterBindingStates; |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 604 | |
| 605 | // Track the geometry shader global parameters declared in layout. |
| 606 | TLayoutPrimitiveType mGeometryShaderInputPrimitiveType; |
| 607 | TLayoutPrimitiveType mGeometryShaderOutputPrimitiveType; |
| 608 | int mGeometryShaderInvocations; |
| 609 | int mGeometryShaderMaxVertices; |
| 610 | int mMaxGeometryShaderInvocations; |
| 611 | int mMaxGeometryShaderMaxVertices; |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 612 | int mGeometryShaderInputArraySize; // Track if all input array sizes are same and matches the |
| 613 | // latter input primitive declaration. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 614 | }; |
| 615 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 616 | int PaParseStrings(size_t count, |
| 617 | const char *const string[], |
| 618 | const int length[], |
| 619 | TParseContext *context); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 620 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 621 | } // namespace sh |
| 622 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 623 | #endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_ |