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