daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | 16004fc | 2014-06-11 11:29:11 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 6 | #ifndef COMPILER_TRANSLATOR_PARSECONTEXT_H_ |
| 7 | #define COMPILER_TRANSLATOR_PARSECONTEXT_H_ |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 8 | |
Jamie Madill | d4a3a31 | 2014-06-25 16:04:56 -0400 | [diff] [blame] | 9 | #include "compiler/translator/Compiler.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 10 | #include "compiler/translator/Diagnostics.h" |
| 11 | #include "compiler/translator/DirectiveHandler.h" |
Jamie Madill | b1a85f4 | 2014-08-19 15:23:24 -0400 | [diff] [blame] | 12 | #include "compiler/translator/Intermediate.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 13 | #include "compiler/translator/SymbolTable.h" |
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 | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 16 | struct TMatrixFields |
| 17 | { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 18 | bool wholeRow; |
| 19 | bool wholeCol; |
| 20 | int row; |
| 21 | int col; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 24 | // |
| 25 | // The following are extra variables needed during parsing, grouped together so |
| 26 | // they can be passed to the parser without needing a global. |
| 27 | // |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 28 | class TParseContext : angle::NonCopyable |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 29 | { |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 30 | public: |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 31 | TParseContext(TSymbolTable &symt, |
| 32 | TExtensionBehavior &ext, |
| 33 | TIntermediate &interm, |
| 34 | sh::GLenum type, |
| 35 | ShShaderSpec spec, |
| 36 | int options, |
| 37 | bool checksPrecErrors, |
| 38 | TInfoSink &is, |
| 39 | bool debugShaderPrecisionSupported) |
| 40 | : intermediate(interm), |
| 41 | symbolTable(symt), |
Corentin Wallez | bc99bb6 | 2015-05-14 17:42:20 -0400 | [diff] [blame] | 42 | mDeferredSingleDeclarationErrorCheck(false), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 43 | mShaderType(type), |
| 44 | mShaderSpec(spec), |
Corentin Wallez | bc99bb6 | 2015-05-14 17:42:20 -0400 | [diff] [blame] | 45 | mShaderVersion(100), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 46 | mTreeRoot(nullptr), |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 47 | mLoopNestingLevel(0), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 48 | mStructNestingLevel(0), |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 49 | mSwitchNestingLevel(0), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 50 | mCurrentFunctionType(nullptr), |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 51 | mFunctionReturnsValue(false), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 52 | mChecksPrecisionErrors(checksPrecErrors), |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 53 | mFragmentPrecisionHighOnESSL1(false), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 54 | mDefaultMatrixPacking(EmpColumnMajor), |
| 55 | mDefaultBlockStorage(EbsShared), |
| 56 | mDiagnostics(is), |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 57 | mDirectiveHandler(ext, mDiagnostics, mShaderVersion, debugShaderPrecisionSupported), |
| 58 | mPreprocessor(&mDiagnostics, &mDirectiveHandler), |
| 59 | mScanner(nullptr), |
Jamie Madill | 14e95b3 | 2015-05-07 10:10:41 -0400 | [diff] [blame] | 60 | mUsesFragData(false), |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 61 | mUsesFragColor(false), |
| 62 | mUsesSecondaryOutputs(false) |
Olli Etuaho | fa33d58 | 2015-04-09 14:33:12 +0300 | [diff] [blame] | 63 | { |
| 64 | } |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 65 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 66 | const pp::Preprocessor &getPreprocessor() const { return mPreprocessor; } |
| 67 | pp::Preprocessor &getPreprocessor() { return mPreprocessor; } |
| 68 | void *getScanner() const { return mScanner; } |
| 69 | void setScanner(void *scanner) { mScanner = scanner; } |
| 70 | int getShaderVersion() const { return mShaderVersion; } |
| 71 | sh::GLenum getShaderType() const { return mShaderType; } |
| 72 | ShShaderSpec getShaderSpec() const { return mShaderSpec; } |
| 73 | int numErrors() const { return mDiagnostics.numErrors(); } |
| 74 | TInfoSink &infoSink() { return mDiagnostics.infoSink(); } |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 75 | void error(const TSourceLoc &loc, const char *reason, const char *token, |
| 76 | const char *extraInfo=""); |
| 77 | void warning(const TSourceLoc &loc, const char *reason, const char *token, |
| 78 | const char *extraInfo=""); |
Jamie Madill | 14e95b3 | 2015-05-07 10:10:41 -0400 | [diff] [blame] | 79 | |
Olli Etuaho | 7c3848e | 2015-11-04 13:19:17 +0200 | [diff] [blame] | 80 | // If isError is false, a warning will be reported instead. |
| 81 | void outOfRangeError(bool isError, |
| 82 | const TSourceLoc &loc, |
| 83 | const char *reason, |
| 84 | const char *token, |
| 85 | const char *extraInfo = ""); |
| 86 | |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 87 | void recover(); |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 88 | TIntermNode *getTreeRoot() const { return mTreeRoot; } |
| 89 | void setTreeRoot(TIntermNode *treeRoot) { mTreeRoot = treeRoot; } |
| 90 | |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 91 | bool getFragmentPrecisionHigh() const |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 92 | { |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 93 | return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300; |
| 94 | } |
| 95 | void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh) |
| 96 | { |
| 97 | mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh; |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | bool getFunctionReturnsValue() const { return mFunctionReturnsValue; } |
| 101 | void setFunctionReturnsValue(bool functionReturnsValue) |
| 102 | { |
| 103 | mFunctionReturnsValue = functionReturnsValue; |
| 104 | } |
| 105 | |
| 106 | void setLoopNestingLevel(int loopNestintLevel) |
| 107 | { |
| 108 | mLoopNestingLevel = loopNestintLevel; |
| 109 | } |
| 110 | |
| 111 | const TType *getCurrentFunctionType() const { return mCurrentFunctionType; } |
| 112 | void setCurrentFunctionType(const TType *currentFunctionType) |
| 113 | { |
| 114 | mCurrentFunctionType = currentFunctionType; |
| 115 | } |
| 116 | |
| 117 | void incrLoopNestingLevel() { ++mLoopNestingLevel; } |
| 118 | void decrLoopNestingLevel() { --mLoopNestingLevel; } |
| 119 | |
| 120 | void incrSwitchNestingLevel() { ++mSwitchNestingLevel; } |
| 121 | void decrSwitchNestingLevel() { --mSwitchNestingLevel; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 122 | |
Jamie Madill | 5c09702 | 2014-08-20 16:38:32 -0400 | [diff] [blame] | 123 | // This method is guaranteed to succeed, even if no variable with 'name' exists. |
| 124 | const TVariable *getNamedVariable(const TSourceLoc &location, const TString *name, const TSymbol *symbol); |
Olli Etuaho | 82c29ed | 2015-11-03 13:06:54 +0200 | [diff] [blame] | 125 | TIntermTyped *parseVariableIdentifier(const TSourceLoc &location, |
| 126 | const TString *name, |
| 127 | const TSymbol *symbol); |
Jamie Madill | 5c09702 | 2014-08-20 16:38:32 -0400 | [diff] [blame] | 128 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 129 | bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc &line); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 130 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 131 | bool reservedErrorCheck(const TSourceLoc &line, const TString &identifier); |
| 132 | void assignError(const TSourceLoc &line, const char *op, TString left, TString right); |
| 133 | void unaryOpError(const TSourceLoc &line, const char *op, TString operand); |
| 134 | void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right); |
| 135 | bool precisionErrorCheck(const TSourceLoc &line, TPrecision precision, TBasicType type); |
| 136 | bool lValueErrorCheck(const TSourceLoc &line, const char *op, TIntermTyped*); |
| 137 | bool constErrorCheck(TIntermTyped *node); |
| 138 | bool integerErrorCheck(TIntermTyped *node, const char *token); |
| 139 | bool globalErrorCheck(const TSourceLoc &line, bool global, const char *token); |
Olli Etuaho | 15c2ac3 | 2015-11-09 15:51:43 +0200 | [diff] [blame^] | 140 | bool constructorErrorCheck(const TSourceLoc &line, |
| 141 | TIntermNode *argumentsNode, |
| 142 | TFunction &function, |
| 143 | TOperator op, |
| 144 | TType *type); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 145 | bool arraySizeErrorCheck(const TSourceLoc &line, TIntermTyped *expr, int &size); |
Olli Etuaho | 3739d23 | 2015-04-08 12:23:44 +0300 | [diff] [blame] | 146 | bool arrayQualifierErrorCheck(const TSourceLoc &line, const TPublicType &type); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 147 | bool arrayTypeErrorCheck(const TSourceLoc &line, const TPublicType &type); |
Olli Etuaho | 6ed7bbe | 2015-04-07 18:08:46 +0300 | [diff] [blame] | 148 | bool voidErrorCheck(const TSourceLoc &line, const TString &identifier, const TBasicType &type); |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 149 | bool boolErrorCheck(const TSourceLoc&, const TIntermTyped*); |
| 150 | bool boolErrorCheck(const TSourceLoc&, const TPublicType&); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 151 | bool samplerErrorCheck(const TSourceLoc &line, const TPublicType &pType, const char *reason); |
| 152 | bool locationDeclaratorListCheck(const TSourceLoc &line, const TPublicType &pType); |
| 153 | bool parameterSamplerErrorCheck(const TSourceLoc &line, TQualifier qualifier, const TType &type); |
| 154 | bool paramErrorCheck(const TSourceLoc &line, TQualifier qualifier, TQualifier paramQualifier, TType *type); |
| 155 | bool extensionErrorCheck(const TSourceLoc &line, const TString&); |
| 156 | bool singleDeclarationErrorCheck(const TPublicType &publicType, const TSourceLoc &identifierLocation); |
| 157 | bool layoutLocationErrorCheck(const TSourceLoc &location, const TLayoutQualifier &layoutQualifier); |
Olli Etuaho | b6e07a6 | 2015-02-16 12:22:10 +0200 | [diff] [blame] | 158 | bool functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *); |
Olli Etuaho | 37ad474 | 2015-04-27 13:18:50 +0300 | [diff] [blame] | 159 | void es3InvariantErrorCheck(const TQualifier qualifier, const TSourceLoc &invariantLocation); |
Olli Etuaho | cc36b98 | 2015-07-10 14:14:18 +0300 | [diff] [blame] | 160 | void es3InputOutputTypeCheck(const TQualifier qualifier, |
| 161 | const TPublicType &type, |
| 162 | const TSourceLoc &qualifierLocation); |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 163 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 164 | const TPragma &pragma() const { return mDirectiveHandler.pragma(); } |
| 165 | const TExtensionBehavior &extensionBehavior() const { return mDirectiveHandler.extensionBehavior(); } |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 166 | bool supportsExtension(const char *extension); |
| 167 | bool isExtensionEnabled(const char *extension) const; |
| 168 | void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior); |
| 169 | void handlePragmaDirective(const TSourceLoc &loc, const char *name, const char *value, bool stdgl); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 170 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 171 | bool containsSampler(const TType &type); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 172 | const TFunction* findFunction( |
| 173 | const TSourceLoc &line, TFunction *pfnCall, int inputShaderVersion, bool *builtIn = 0); |
| 174 | bool executeInitializer(const TSourceLoc &line, |
| 175 | const TString &identifier, |
| 176 | const TPublicType &pType, |
| 177 | TIntermTyped *initializer, |
| 178 | TIntermNode **intermNode); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 179 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 180 | TPublicType addFullySpecifiedType(TQualifier qualifier, |
| 181 | bool invariant, |
| 182 | TLayoutQualifier layoutQualifier, |
| 183 | const TPublicType &typeSpecifier); |
Olli Etuaho | e7847b0 | 2015-03-16 11:56:12 +0200 | [diff] [blame] | 184 | |
Olli Etuaho | fa33d58 | 2015-04-09 14:33:12 +0300 | [diff] [blame] | 185 | TIntermAggregate *parseSingleDeclaration(TPublicType &publicType, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 186 | const TSourceLoc &identifierOrTypeLocation, |
| 187 | const TString &identifier); |
Olli Etuaho | e7847b0 | 2015-03-16 11:56:12 +0200 | [diff] [blame] | 188 | TIntermAggregate *parseSingleArrayDeclaration(TPublicType &publicType, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 189 | const TSourceLoc &identifierLocation, |
| 190 | const TString &identifier, |
| 191 | const TSourceLoc &indexLocation, |
| 192 | TIntermTyped *indexExpression); |
| 193 | TIntermAggregate *parseSingleInitDeclaration(const TPublicType &publicType, |
| 194 | const TSourceLoc &identifierLocation, |
| 195 | const TString &identifier, |
| 196 | const TSourceLoc &initLocation, |
| 197 | TIntermTyped *initializer); |
Jamie Madill | 47e3ec0 | 2014-08-20 16:38:33 -0400 | [diff] [blame] | 198 | |
Olli Etuaho | 3875ffd | 2015-04-10 16:45:14 +0300 | [diff] [blame] | 199 | // Parse a declaration like "type a[n] = initializer" |
| 200 | // Note that this does not apply to declarations like "type[n] a = initializer" |
| 201 | TIntermAggregate *parseSingleArrayInitDeclaration(TPublicType &publicType, |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 202 | const TSourceLoc &identifierLocation, |
| 203 | const TString &identifier, |
| 204 | const TSourceLoc &indexLocation, |
| 205 | TIntermTyped *indexExpression, |
| 206 | const TSourceLoc &initLocation, |
| 207 | TIntermTyped *initializer); |
Olli Etuaho | 3875ffd | 2015-04-10 16:45:14 +0300 | [diff] [blame] | 208 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 209 | TIntermAggregate *parseInvariantDeclaration(const TSourceLoc &invariantLoc, |
| 210 | const TSourceLoc &identifierLoc, |
| 211 | const TString *identifier, |
| 212 | const TSymbol *symbol); |
Olli Etuaho | e7847b0 | 2015-03-16 11:56:12 +0200 | [diff] [blame] | 213 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 214 | TIntermAggregate *parseDeclarator(TPublicType &publicType, |
| 215 | TIntermAggregate *aggregateDeclaration, |
| 216 | const TSourceLoc &identifierLocation, |
| 217 | const TString &identifier); |
| 218 | TIntermAggregate *parseArrayDeclarator(TPublicType &publicType, |
| 219 | TIntermAggregate *aggregateDeclaration, |
| 220 | const TSourceLoc &identifierLocation, |
| 221 | const TString &identifier, |
| 222 | const TSourceLoc &arrayLocation, |
| 223 | TIntermTyped *indexExpression); |
| 224 | TIntermAggregate *parseInitDeclarator(const TPublicType &publicType, |
| 225 | TIntermAggregate *aggregateDeclaration, |
| 226 | const TSourceLoc &identifierLocation, |
| 227 | const TString &identifier, |
| 228 | const TSourceLoc &initLocation, |
| 229 | TIntermTyped *initializer); |
Olli Etuaho | e7847b0 | 2015-03-16 11:56:12 +0200 | [diff] [blame] | 230 | |
Olli Etuaho | 3875ffd | 2015-04-10 16:45:14 +0300 | [diff] [blame] | 231 | // Parse a declarator like "a[n] = initializer" |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 232 | TIntermAggregate *parseArrayInitDeclarator(const TPublicType &publicType, |
| 233 | TIntermAggregate *aggregateDeclaration, |
| 234 | const TSourceLoc &identifierLocation, |
| 235 | const TString &identifier, |
| 236 | const TSourceLoc &indexLocation, |
| 237 | TIntermTyped *indexExpression, |
| 238 | const TSourceLoc &initLocation, |
| 239 | TIntermTyped *initializer); |
Olli Etuaho | 3875ffd | 2015-04-10 16:45:14 +0300 | [diff] [blame] | 240 | |
Jamie Madill | a295edf | 2013-06-06 11:56:48 -0400 | [diff] [blame] | 241 | void parseGlobalLayoutQualifier(const TPublicType &typeQualifier); |
Jamie Madill | 185fb40 | 2015-06-12 15:48:48 -0400 | [diff] [blame] | 242 | void parseFunctionPrototype(const TSourceLoc &location, |
| 243 | TFunction *function, |
| 244 | TIntermAggregate **aggregateOut); |
| 245 | TFunction *parseFunctionDeclarator(const TSourceLoc &location, |
| 246 | TFunction *function); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 247 | TFunction *addConstructorFunc(const TPublicType &publicType); |
| 248 | TIntermTyped *addConstructor(TIntermNode *arguments, |
| 249 | TType *type, |
| 250 | TOperator op, |
| 251 | TFunction *fnCall, |
| 252 | const TSourceLoc &line); |
Olli Etuaho | 7c3848e | 2015-11-04 13:19:17 +0200 | [diff] [blame] | 253 | TIntermTyped *addConstVectorNode(TVectorFields &fields, |
| 254 | TIntermConstantUnion *node, |
| 255 | const TSourceLoc &line, |
| 256 | bool outOfRangeIndexIsError); |
| 257 | TIntermTyped *addConstMatrixNode(int index, |
| 258 | TIntermConstantUnion *node, |
| 259 | const TSourceLoc &line, |
| 260 | bool outOfRangeIndexIsError); |
| 261 | TIntermTyped *addConstArrayNode(int index, |
| 262 | TIntermConstantUnion *node, |
| 263 | const TSourceLoc &line, |
| 264 | bool outOfRangeIndexIsError); |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 265 | TIntermTyped *addConstStruct( |
| 266 | const TString &identifier, TIntermTyped *node, const TSourceLoc& line); |
| 267 | TIntermTyped *addIndexExpression(TIntermTyped *baseExpression, |
| 268 | const TSourceLoc& location, |
| 269 | TIntermTyped *indexExpression); |
| 270 | TIntermTyped* addFieldSelectionExpression(TIntermTyped *baseExpression, |
| 271 | const TSourceLoc &dotLocation, |
| 272 | const TString &fieldString, |
| 273 | const TSourceLoc &fieldLocation); |
shannonwoods@chromium.org | a910088 | 2013-05-30 00:11:39 +0000 | [diff] [blame] | 274 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 275 | TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList); |
| 276 | TPublicType addStructure(const TSourceLoc &structLine, |
| 277 | const TSourceLoc &nameLine, |
| 278 | const TString *structName, |
| 279 | TFieldList *fieldList); |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 280 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 281 | TIntermAggregate* addInterfaceBlock(const TPublicType &typeQualifier, |
| 282 | const TSourceLoc &nameLine, |
| 283 | const TString &blockName, |
| 284 | TFieldList *fieldList, |
| 285 | const TString *instanceName, |
| 286 | const TSourceLoc &instanceLine, |
| 287 | TIntermTyped *arrayIndex, |
| 288 | const TSourceLoc& arrayIndexLine); |
shannonwoods@chromium.org | 5668c5d | 2013-05-30 00:11:48 +0000 | [diff] [blame] | 289 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 290 | TLayoutQualifier parseLayoutQualifier( |
| 291 | const TString &qualifierType, const TSourceLoc &qualifierTypeLine); |
| 292 | TLayoutQualifier parseLayoutQualifier(const TString &qualifierType, |
| 293 | const TSourceLoc &qualifierTypeLine, |
| 294 | const TString &intValueString, |
| 295 | int intValue, |
| 296 | const TSourceLoc &intValueLine); |
Jamie Madill | a5efff9 | 2013-06-06 11:56:47 -0400 | [diff] [blame] | 297 | TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier, TLayoutQualifier rightQualifier); |
Jamie Madill | f2e0f9b | 2013-08-26 16:39:42 -0400 | [diff] [blame] | 298 | TPublicType joinInterpolationQualifiers(const TSourceLoc &interpolationLoc, TQualifier interpolationQualifier, |
| 299 | const TSourceLoc &storageLoc, TQualifier storageQualifier); |
shannonwoods@chromium.org | 302adfe | 2013-05-30 00:21:06 +0000 | [diff] [blame] | 300 | |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 301 | // Performs an error check for embedded struct declarations. |
| 302 | // Returns true if an error was raised due to the declaration of |
| 303 | // this struct. |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 304 | bool enterStructDeclaration(const TSourceLoc &line, const TString &identifier); |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 305 | void exitStructDeclaration(); |
| 306 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 307 | bool structNestingErrorCheck(const TSourceLoc &line, const TField &field); |
Olli Etuaho | 09b2247 | 2015-02-11 11:47:26 +0200 | [diff] [blame] | 308 | |
Olli Etuaho | a3a3666 | 2015-02-17 13:46:51 +0200 | [diff] [blame] | 309 | TIntermSwitch *addSwitch(TIntermTyped *init, TIntermAggregate *statementList, const TSourceLoc &loc); |
| 310 | TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc); |
| 311 | TIntermCase *addDefault(const TSourceLoc &loc); |
| 312 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 313 | TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc); |
| 314 | TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc); |
| 315 | TIntermTyped *addBinaryMath( |
| 316 | TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
| 317 | TIntermTyped *addBinaryMathBooleanResult( |
| 318 | TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
| 319 | TIntermTyped *addAssign( |
| 320 | TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
Olli Etuaho | 4930086 | 2015-02-20 14:54:49 +0200 | [diff] [blame] | 321 | |
Olli Etuaho | 0b2d2dc | 2015-11-04 16:35:32 +0200 | [diff] [blame] | 322 | TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
| 323 | |
Olli Etuaho | 4930086 | 2015-02-20 14:54:49 +0200 | [diff] [blame] | 324 | TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc); |
| 325 | TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc); |
Olli Etuaho | c4ba3be | 2015-03-02 14:42:24 +0200 | [diff] [blame] | 326 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 327 | TIntermTyped *addFunctionCallOrMethod(TFunction *fnCall, |
| 328 | TIntermNode *paramNode, |
| 329 | TIntermNode *thisNode, |
| 330 | const TSourceLoc &loc, |
| 331 | bool *fatalError); |
Olli Etuaho | fc1806e | 2015-03-17 13:03:11 +0200 | [diff] [blame] | 332 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 333 | TIntermTyped *addTernarySelection( |
| 334 | TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock, const TSourceLoc &line); |
Olli Etuaho | 5290174 | 2015-04-15 13:42:45 +0300 | [diff] [blame] | 335 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 336 | // TODO(jmadill): make these private |
| 337 | TIntermediate &intermediate; // to hold and build a parse tree |
| 338 | TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed |
| 339 | |
Olli Etuaho | fc1806e | 2015-03-17 13:03:11 +0200 | [diff] [blame] | 340 | private: |
Olli Etuaho | 2935c58 | 2015-04-08 14:32:06 +0300 | [diff] [blame] | 341 | bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable); |
| 342 | |
Olli Etuaho | 376f1b5 | 2015-04-13 13:23:41 +0300 | [diff] [blame] | 343 | bool nonInitErrorCheck(const TSourceLoc &line, const TString &identifier, TPublicType *type); |
| 344 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 345 | TIntermTyped *addBinaryMathInternal( |
| 346 | TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
| 347 | TIntermTyped *createAssign( |
| 348 | TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
Olli Etuaho | f6c694b | 2015-03-26 14:50:53 +0200 | [diff] [blame] | 349 | // The funcReturnType parameter is expected to be non-null when the operation is a built-in function. |
| 350 | // It is expected to be null for other unary operators. |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 351 | TIntermTyped *createUnaryMath( |
| 352 | TOperator op, TIntermTyped *child, const TSourceLoc &loc, const TType *funcReturnType); |
Olli Etuaho | d6b1428 | 2015-03-17 14:31:35 +0200 | [diff] [blame] | 353 | |
Olli Etuaho | 47fd36a | 2015-03-19 14:22:24 +0200 | [diff] [blame] | 354 | // Return true if the checks pass |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 355 | bool binaryOpCommonCheck( |
| 356 | TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); |
Olli Etuaho | fa33d58 | 2015-04-09 14:33:12 +0300 | [diff] [blame] | 357 | |
| 358 | // Set to true when the last/current declarator list was started with an empty declaration. |
| 359 | bool mDeferredSingleDeclarationErrorCheck; |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 360 | |
| 361 | sh::GLenum mShaderType; // vertex or fragment language (future: pack or unpack) |
| 362 | ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES2 or WebGL. |
| 363 | int mShaderVersion; |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 364 | TIntermNode *mTreeRoot; // root of parse tree being created |
| 365 | int mLoopNestingLevel; // 0 if outside all loops |
| 366 | int mStructNestingLevel; // incremented while parsing a struct declaration |
| 367 | int mSwitchNestingLevel; // 0 if outside all switch statements |
| 368 | const TType *mCurrentFunctionType; // the return type of the function that's currently being parsed |
| 369 | bool mFunctionReturnsValue; // true if a non-void function has a return |
| 370 | bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit. |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 371 | bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling |
| 372 | // ESSL1. |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 373 | TLayoutMatrixPacking mDefaultMatrixPacking; |
| 374 | TLayoutBlockStorage mDefaultBlockStorage; |
| 375 | TString mHashErrMsg; |
| 376 | TDiagnostics mDiagnostics; |
| 377 | TDirectiveHandler mDirectiveHandler; |
| 378 | pp::Preprocessor mPreprocessor; |
| 379 | void *mScanner; |
Jamie Madill | 14e95b3 | 2015-05-07 10:10:41 -0400 | [diff] [blame] | 380 | bool mUsesFragData; // track if we are using both gl_FragData and gl_FragColor |
| 381 | bool mUsesFragColor; |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 382 | bool mUsesSecondaryOutputs; // Track if we are using either gl_SecondaryFragData or |
| 383 | // gl_Secondary FragColor or both. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 384 | }; |
| 385 | |
Jamie Madill | 0614523 | 2015-05-13 13:10:01 -0400 | [diff] [blame] | 386 | int PaParseStrings( |
| 387 | size_t count, const char *const string[], const int length[], TParseContext *context); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 388 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 389 | #endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_ |