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