1 // 2 // Copyright 2002 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 #ifndef COMPILER_TRANSLATOR_PARSECONTEXT_H_ 7 #define COMPILER_TRANSLATOR_PARSECONTEXT_H_ 8 9 #include "compiler/preprocessor/Preprocessor.h" 10 #include "compiler/translator/Compiler.h" 11 #include "compiler/translator/Declarator.h" 12 #include "compiler/translator/Diagnostics.h" 13 #include "compiler/translator/DirectiveHandler.h" 14 #include "compiler/translator/FunctionLookup.h" 15 #include "compiler/translator/QualifierTypes.h" 16 #include "compiler/translator/SymbolTable.h" 17 18 namespace sh 19 { 20 21 struct TMatrixFields 22 { 23 bool wholeRow; 24 bool wholeCol; 25 int row; 26 int col; 27 }; 28 29 // 30 // The following are extra variables needed during parsing, grouped together so 31 // they can be passed to the parser without needing a global. 32 // 33 class TParseContext : angle::NonCopyable 34 { 35 public: 36 TParseContext(TSymbolTable &symt, 37 TExtensionBehavior &ext, 38 sh::GLenum type, 39 ShShaderSpec spec, 40 ShCompileOptions options, 41 bool checksPrecErrors, 42 TDiagnostics *diagnostics, 43 const ShBuiltInResources &resources, 44 ShShaderOutput outputType); 45 ~TParseContext(); 46 47 bool anyMultiviewExtensionAvailable(); getPreprocessor()48 const angle::pp::Preprocessor &getPreprocessor() const { return mPreprocessor; } getPreprocessor()49 angle::pp::Preprocessor &getPreprocessor() { return mPreprocessor; } getScanner()50 void *getScanner() const { return mScanner; } setScanner(void * scanner)51 void setScanner(void *scanner) { mScanner = scanner; } getShaderVersion()52 int getShaderVersion() const { return mShaderVersion; } getShaderType()53 sh::GLenum getShaderType() const { return mShaderType; } getShaderSpec()54 ShShaderSpec getShaderSpec() const { return mShaderSpec; } numErrors()55 int numErrors() const { return mDiagnostics->numErrors(); } 56 void error(const TSourceLoc &loc, const char *reason, const char *token); 57 void error(const TSourceLoc &loc, const char *reason, const ImmutableString &token); 58 void warning(const TSourceLoc &loc, const char *reason, const char *token); 59 60 // If isError is false, a warning will be reported instead. 61 void outOfRangeError(bool isError, 62 const TSourceLoc &loc, 63 const char *reason, 64 const char *token); 65 getTreeRoot()66 TIntermBlock *getTreeRoot() const { return mTreeRoot; } 67 void setTreeRoot(TIntermBlock *treeRoot); 68 getFragmentPrecisionHigh()69 bool getFragmentPrecisionHigh() const 70 { 71 return mFragmentPrecisionHighOnESSL1 || mShaderVersion >= 300; 72 } setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh)73 void setFragmentPrecisionHighOnESSL1(bool fragmentPrecisionHigh) 74 { 75 mFragmentPrecisionHighOnESSL1 = fragmentPrecisionHigh; 76 } 77 isEarlyFragmentTestsSpecified()78 bool isEarlyFragmentTestsSpecified() const { return mEarlyFragmentTestsSpecified; } 79 setLoopNestingLevel(int loopNestintLevel)80 void setLoopNestingLevel(int loopNestintLevel) { mLoopNestingLevel = loopNestintLevel; } 81 incrLoopNestingLevel()82 void incrLoopNestingLevel() { ++mLoopNestingLevel; } decrLoopNestingLevel()83 void decrLoopNestingLevel() { --mLoopNestingLevel; } 84 incrSwitchNestingLevel()85 void incrSwitchNestingLevel() { ++mSwitchNestingLevel; } decrSwitchNestingLevel()86 void decrSwitchNestingLevel() { --mSwitchNestingLevel; } 87 isComputeShaderLocalSizeDeclared()88 bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; } 89 sh::WorkGroupSize getComputeShaderLocalSize() const; 90 getNumViews()91 int getNumViews() const { return mNumViews; } 92 enterFunctionDeclaration()93 void enterFunctionDeclaration() { mDeclaringFunction = true; } 94 exitFunctionDeclaration()95 void exitFunctionDeclaration() { mDeclaringFunction = false; } 96 declaringFunction()97 bool declaringFunction() const { return mDeclaringFunction; } 98 99 TIntermConstantUnion *addScalarLiteral(const TConstantUnion *constantUnion, 100 const TSourceLoc &line); 101 102 // This method is guaranteed to succeed, even if no variable with 'name' exists. 103 const TVariable *getNamedVariable(const TSourceLoc &location, 104 const ImmutableString &name, 105 const TSymbol *symbol); 106 TIntermTyped *parseVariableIdentifier(const TSourceLoc &location, 107 const ImmutableString &name, 108 const TSymbol *symbol); 109 110 // Look at a '.' field selector string and change it into offsets for a vector. 111 bool parseVectorFields(const TSourceLoc &line, 112 const ImmutableString &compString, 113 int vecSize, 114 TVector<int> *fieldOffsets); 115 116 void assignError(const TSourceLoc &line, const char *op, const TType &left, const TType &right); 117 void unaryOpError(const TSourceLoc &line, const char *op, const TType &operand); 118 void binaryOpError(const TSourceLoc &line, 119 const char *op, 120 const TType &left, 121 const TType &right); 122 123 // Check functions - the ones that return bool return false if an error was generated. 124 125 bool checkIsNotReserved(const TSourceLoc &line, const ImmutableString &identifier); 126 void checkPrecisionSpecified(const TSourceLoc &line, TPrecision precision, TBasicType type); 127 bool checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node); 128 void checkIsConst(TIntermTyped *node); 129 void checkIsScalarInteger(TIntermTyped *node, const char *token); 130 bool checkIsAtGlobalLevel(const TSourceLoc &line, const char *token); 131 bool checkConstructorArguments(const TSourceLoc &line, 132 const TIntermSequence &arguments, 133 const TType &type); 134 135 // Returns a sanitized array size to use (the size is at least 1). 136 unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr); 137 bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &elementQualifier); 138 bool checkArrayElementIsNotArray(const TSourceLoc &line, const TPublicType &elementType); 139 bool checkArrayOfArraysInOut(const TSourceLoc &line, 140 const TPublicType &elementType, 141 const TType &arrayType); 142 bool checkIsNonVoid(const TSourceLoc &line, 143 const ImmutableString &identifier, 144 const TBasicType &type); 145 bool checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type); 146 void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType); 147 bool checkIsNotOpaqueType(const TSourceLoc &line, 148 const TTypeSpecifierNonArray &pType, 149 const char *reason); 150 void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType); 151 void checkLocationIsNotSpecified(const TSourceLoc &location, 152 const TLayoutQualifier &layoutQualifier); 153 void checkStd430IsForShaderStorageBlock(const TSourceLoc &location, 154 const TLayoutBlockStorage &blockStorage, 155 const TQualifier &qualifier); 156 void checkIsParameterQualifierValid(const TSourceLoc &line, 157 const TTypeQualifierBuilder &typeQualifierBuilder, 158 TType *type); 159 160 // Check if at least one of the specified extensions can be used, and generate error/warning as 161 // appropriate according to the spec. 162 // This function is only needed for a few different small constant sizes of extension array, and 163 // we want to avoid unnecessary dynamic allocations. That's why checkCanUseOneOfExtensions is a 164 // template function rather than one taking a vector. 165 template <size_t size> 166 bool checkCanUseOneOfExtensions(const TSourceLoc &line, 167 const std::array<TExtension, size> &extensions); 168 bool checkCanUseExtension(const TSourceLoc &line, TExtension extension); 169 170 // Done for all declarations, whether empty or not. 171 void declarationQualifierErrorCheck(const sh::TQualifier qualifier, 172 const sh::TLayoutQualifier &layoutQualifier, 173 const TSourceLoc &location); 174 // Done for the first non-empty declarator in a declaration. 175 void nonEmptyDeclarationErrorCheck(const TPublicType &publicType, 176 const TSourceLoc &identifierLocation); 177 // Done only for empty declarations. 178 void emptyDeclarationErrorCheck(const TType &type, const TSourceLoc &location); 179 180 void checkCanUseLayoutQualifier(const TSourceLoc &location); 181 bool checkLayoutQualifierSupported(const TSourceLoc &location, 182 const ImmutableString &layoutQualifierName, 183 int versionRequired); 184 bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location, 185 const TLayoutQualifier &layoutQualifier); 186 void functionCallRValueLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall); 187 void checkInvariantVariableQualifier(bool invariant, 188 const TQualifier qualifier, 189 const TSourceLoc &invariantLocation); 190 void checkInputOutputTypeIsValidES3(const TQualifier qualifier, 191 const TPublicType &type, 192 const TSourceLoc &qualifierLocation); 193 void checkLocalVariableConstStorageQualifier(const TQualifierWrapperBase &qualifier); 194 void checkTCSOutVarIndexIsValid(TIntermBinary *binaryExpression, const TSourceLoc &location); pragma()195 const TPragma &pragma() const { return mDirectiveHandler.pragma(); } extensionBehavior()196 const TExtensionBehavior &extensionBehavior() const 197 { 198 return mDirectiveHandler.extensionBehavior(); 199 } 200 201 bool isExtensionEnabled(TExtension extension) const; 202 void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior); 203 void handlePragmaDirective(const TSourceLoc &loc, 204 const char *name, 205 const char *value, 206 bool stdgl); 207 208 // For built-ins that can be redeclared, adjusts the type qualifier so transformations can 209 // identify them correctly. 210 void adjustRedeclaredBuiltInType(const ImmutableString &identifier, TType *type); 211 212 // Returns true on success. *initNode may still be nullptr on success in case the initialization 213 // is not needed in the AST. 214 bool executeInitializer(const TSourceLoc &line, 215 const ImmutableString &identifier, 216 TType *type, 217 TIntermTyped *initializer, 218 TIntermBinary **initNode); 219 TIntermNode *addConditionInitializer(const TPublicType &pType, 220 const ImmutableString &identifier, 221 TIntermTyped *initializer, 222 const TSourceLoc &loc); 223 TIntermNode *addLoop(TLoopType type, 224 TIntermNode *init, 225 TIntermNode *cond, 226 TIntermTyped *expr, 227 TIntermNode *body, 228 const TSourceLoc &loc); 229 230 // For "if" test nodes. There are three children: a condition, a true path, and a false path. 231 // The two paths are in TIntermNodePair code. 232 TIntermNode *addIfElse(TIntermTyped *cond, TIntermNodePair code, const TSourceLoc &loc); 233 234 void addFullySpecifiedType(TPublicType *typeSpecifier); 235 TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder, 236 const TPublicType &typeSpecifier); 237 238 TIntermDeclaration *parseSingleDeclaration(TPublicType &publicType, 239 const TSourceLoc &identifierOrTypeLocation, 240 const ImmutableString &identifier); 241 TIntermDeclaration *parseSingleArrayDeclaration(TPublicType &elementType, 242 const TSourceLoc &identifierLocation, 243 const ImmutableString &identifier, 244 const TSourceLoc &indexLocation, 245 const TVector<unsigned int> &arraySizes); 246 TIntermDeclaration *parseSingleInitDeclaration(const TPublicType &publicType, 247 const TSourceLoc &identifierLocation, 248 const ImmutableString &identifier, 249 const TSourceLoc &initLocation, 250 TIntermTyped *initializer); 251 252 // Parse a declaration like "type a[n] = initializer" 253 // Note that this does not apply to declarations like "type[n] a = initializer" 254 TIntermDeclaration *parseSingleArrayInitDeclaration(TPublicType &elementType, 255 const TSourceLoc &identifierLocation, 256 const ImmutableString &identifier, 257 const TSourceLoc &indexLocation, 258 const TVector<unsigned int> &arraySizes, 259 const TSourceLoc &initLocation, 260 TIntermTyped *initializer); 261 262 TIntermGlobalQualifierDeclaration *parseGlobalQualifierDeclaration( 263 const TTypeQualifierBuilder &typeQualifierBuilder, 264 const TSourceLoc &identifierLoc, 265 const ImmutableString &identifier, 266 const TSymbol *symbol); 267 268 void parseDeclarator(TPublicType &publicType, 269 const TSourceLoc &identifierLocation, 270 const ImmutableString &identifier, 271 TIntermDeclaration *declarationOut); 272 void parseArrayDeclarator(TPublicType &elementType, 273 const TSourceLoc &identifierLocation, 274 const ImmutableString &identifier, 275 const TSourceLoc &arrayLocation, 276 const TVector<unsigned int> &arraySizes, 277 TIntermDeclaration *declarationOut); 278 void parseInitDeclarator(const TPublicType &publicType, 279 const TSourceLoc &identifierLocation, 280 const ImmutableString &identifier, 281 const TSourceLoc &initLocation, 282 TIntermTyped *initializer, 283 TIntermDeclaration *declarationOut); 284 285 // Parse a declarator like "a[n] = initializer" 286 void parseArrayInitDeclarator(const TPublicType &elementType, 287 const TSourceLoc &identifierLocation, 288 const ImmutableString &identifier, 289 const TSourceLoc &indexLocation, 290 const TVector<unsigned int> &arraySizes, 291 const TSourceLoc &initLocation, 292 TIntermTyped *initializer, 293 TIntermDeclaration *declarationOut); 294 295 TIntermNode *addEmptyStatement(const TSourceLoc &location); 296 297 void parseDefaultPrecisionQualifier(const TPrecision precision, 298 const TPublicType &type, 299 const TSourceLoc &loc); 300 void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder); 301 302 TIntermFunctionPrototype *addFunctionPrototypeDeclaration(const TFunction &parsedFunction, 303 const TSourceLoc &location); 304 TIntermFunctionDefinition *addFunctionDefinition(TIntermFunctionPrototype *functionPrototype, 305 TIntermBlock *functionBody, 306 const TSourceLoc &location); 307 void parseFunctionDefinitionHeader(const TSourceLoc &location, 308 const TFunction *function, 309 TIntermFunctionPrototype **prototypeOut); 310 TFunction *parseFunctionDeclarator(const TSourceLoc &location, TFunction *function); 311 TFunction *parseFunctionHeader(const TPublicType &type, 312 const ImmutableString &name, 313 const TSourceLoc &location); 314 315 TFunctionLookup *addNonConstructorFunc(const ImmutableString &name, const TSymbol *symbol); 316 TFunctionLookup *addConstructorFunc(const TPublicType &publicType); 317 318 TParameter parseParameterDeclarator(const TPublicType &publicType, 319 const ImmutableString &name, 320 const TSourceLoc &nameLoc); 321 322 TParameter parseParameterArrayDeclarator(const ImmutableString &name, 323 const TSourceLoc &nameLoc, 324 const TVector<unsigned int> &arraySizes, 325 const TSourceLoc &arrayLoc, 326 TPublicType *elementType); 327 328 TIntermTyped *addIndexExpression(TIntermTyped *baseExpression, 329 const TSourceLoc &location, 330 TIntermTyped *indexExpression); 331 TIntermTyped *addFieldSelectionExpression(TIntermTyped *baseExpression, 332 const TSourceLoc &dotLocation, 333 const ImmutableString &fieldString, 334 const TSourceLoc &fieldLocation); 335 336 // Parse declarator for a single field 337 TDeclarator *parseStructDeclarator(const ImmutableString &identifier, const TSourceLoc &loc); 338 TDeclarator *parseStructArrayDeclarator(const ImmutableString &identifier, 339 const TSourceLoc &loc, 340 const TVector<unsigned int> *arraySizes); 341 342 void checkDoesNotHaveDuplicateFieldName(const TFieldList::const_iterator begin, 343 const TFieldList::const_iterator end, 344 const ImmutableString &name, 345 const TSourceLoc &location); 346 TFieldList *addStructFieldList(TFieldList *fields, const TSourceLoc &location); 347 TFieldList *combineStructFieldLists(TFieldList *processedFields, 348 const TFieldList *newlyAddedFields, 349 const TSourceLoc &location); 350 TFieldList *addStructDeclaratorListWithQualifiers( 351 const TTypeQualifierBuilder &typeQualifierBuilder, 352 TPublicType *typeSpecifier, 353 const TDeclaratorList *declaratorList); 354 TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, 355 const TDeclaratorList *declaratorList); 356 TTypeSpecifierNonArray addStructure(const TSourceLoc &structLine, 357 const TSourceLoc &nameLine, 358 const ImmutableString &structName, 359 TFieldList *fieldList); 360 361 TIntermDeclaration *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder, 362 const TSourceLoc &nameLine, 363 const ImmutableString &blockName, 364 TFieldList *fieldList, 365 const ImmutableString &instanceName, 366 const TSourceLoc &instanceLine, 367 const TVector<unsigned int> *arraySizes, 368 const TSourceLoc &arraySizesLine); 369 370 void parseLocalSize(const ImmutableString &qualifierType, 371 const TSourceLoc &qualifierTypeLine, 372 int intValue, 373 const TSourceLoc &intValueLine, 374 const std::string &intValueString, 375 size_t index, 376 sh::WorkGroupSize *localSize); 377 void parseNumViews(int intValue, 378 const TSourceLoc &intValueLine, 379 const std::string &intValueString, 380 int *numViews); 381 void parseInvocations(int intValue, 382 const TSourceLoc &intValueLine, 383 const std::string &intValueString, 384 int *numInvocations); 385 void parseMaxVertices(int intValue, 386 const TSourceLoc &intValueLine, 387 const std::string &intValueString, 388 int *numMaxVertices); 389 void parseVertices(int intValue, 390 const TSourceLoc &intValueLine, 391 const std::string &intValueString, 392 int *numVertices); 393 void parseIndexLayoutQualifier(int intValue, 394 const TSourceLoc &intValueLine, 395 const std::string &intValueString, 396 int *index); 397 TLayoutQualifier parseLayoutQualifier(const ImmutableString &qualifierType, 398 const TSourceLoc &qualifierTypeLine); 399 TLayoutQualifier parseLayoutQualifier(const ImmutableString &qualifierType, 400 const TSourceLoc &qualifierTypeLine, 401 int intValue, 402 const TSourceLoc &intValueLine); 403 TTypeQualifierBuilder *createTypeQualifierBuilder(const TSourceLoc &loc); 404 TStorageQualifierWrapper *parseGlobalStorageQualifier(TQualifier qualifier, 405 const TSourceLoc &loc); 406 TStorageQualifierWrapper *parseVaryingQualifier(const TSourceLoc &loc); 407 TStorageQualifierWrapper *parseInQualifier(const TSourceLoc &loc); 408 TStorageQualifierWrapper *parseOutQualifier(const TSourceLoc &loc); 409 TStorageQualifierWrapper *parseInOutQualifier(const TSourceLoc &loc); 410 TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier, 411 TLayoutQualifier rightQualifier, 412 const TSourceLoc &rightQualifierLocation); 413 414 // Performs an error check for embedded struct declarations. 415 void enterStructDeclaration(const TSourceLoc &line, const ImmutableString &identifier); 416 void exitStructDeclaration(); 417 418 void checkIsBelowStructNestingLimit(const TSourceLoc &line, const TField &field); 419 420 TIntermSwitch *addSwitch(TIntermTyped *init, 421 TIntermBlock *statementList, 422 const TSourceLoc &loc); 423 TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &loc); 424 TIntermCase *addDefault(const TSourceLoc &loc); 425 426 TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc); 427 TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc); 428 TIntermTyped *addBinaryMath(TOperator op, 429 TIntermTyped *left, 430 TIntermTyped *right, 431 const TSourceLoc &loc); 432 TIntermTyped *addBinaryMathBooleanResult(TOperator op, 433 TIntermTyped *left, 434 TIntermTyped *right, 435 const TSourceLoc &loc); 436 TIntermTyped *addAssign(TOperator op, 437 TIntermTyped *left, 438 TIntermTyped *right, 439 const TSourceLoc &loc); 440 441 TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); 442 443 TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc); 444 TIntermBranch *addBranch(TOperator op, TIntermTyped *expression, const TSourceLoc &loc); 445 446 void appendStatement(TIntermBlock *block, TIntermNode *statement); 447 448 void checkTextureGather(TIntermAggregate *functionCall); 449 void checkTextureOffset(TIntermAggregate *functionCall); 450 void checkImageMemoryAccessForBuiltinFunctions(TIntermAggregate *functionCall); 451 void checkImageMemoryAccessForUserDefinedFunctions(const TFunction *functionDefinition, 452 const TIntermAggregate *functionCall); 453 void checkAtomicMemoryBuiltinFunctions(TIntermAggregate *functionCall); 454 void checkInterpolationFS(TIntermAggregate *functionCall); 455 456 // fnCall is only storing the built-in op, and function name or constructor type. arguments 457 // has the arguments. 458 TIntermTyped *addFunctionCallOrMethod(TFunctionLookup *fnCall, const TSourceLoc &loc); 459 460 TIntermTyped *addTernarySelection(TIntermTyped *cond, 461 TIntermTyped *trueExpression, 462 TIntermTyped *falseExpression, 463 const TSourceLoc &line); 464 getGeometryShaderMaxVertices()465 int getGeometryShaderMaxVertices() const { return mGeometryShaderMaxVertices; } getGeometryShaderInvocations()466 int getGeometryShaderInvocations() const 467 { 468 return (mGeometryShaderInvocations > 0) ? mGeometryShaderInvocations : 1; 469 } getGeometryShaderInputPrimitiveType()470 TLayoutPrimitiveType getGeometryShaderInputPrimitiveType() const 471 { 472 return mGeometryShaderInputPrimitiveType; 473 } getGeometryShaderOutputPrimitiveType()474 TLayoutPrimitiveType getGeometryShaderOutputPrimitiveType() const 475 { 476 return mGeometryShaderOutputPrimitiveType; 477 } getTessControlShaderOutputVertices()478 int getTessControlShaderOutputVertices() const { return mTessControlShaderOutputVertices; } getTessEvaluationShaderInputPrimitiveType()479 TLayoutTessEvaluationType getTessEvaluationShaderInputPrimitiveType() const 480 { 481 return mTessEvaluationShaderInputPrimitiveType; 482 } getTessEvaluationShaderInputVertexSpacingType()483 TLayoutTessEvaluationType getTessEvaluationShaderInputVertexSpacingType() const 484 { 485 return mTessEvaluationShaderInputVertexSpacingType; 486 } getTessEvaluationShaderInputOrderingType()487 TLayoutTessEvaluationType getTessEvaluationShaderInputOrderingType() const 488 { 489 return mTessEvaluationShaderInputOrderingType; 490 } getTessEvaluationShaderInputPointType()491 TLayoutTessEvaluationType getTessEvaluationShaderInputPointType() const 492 { 493 return mTessEvaluationShaderInputPointType; 494 } 495 markShaderHasPrecise()496 void markShaderHasPrecise() { mHasAnyPreciseType = true; } hasAnyPreciseType()497 bool hasAnyPreciseType() const { return mHasAnyPreciseType; } 498 getOutputType()499 ShShaderOutput getOutputType() const { return mOutputType; } 500 501 // TODO(jmadill): make this private 502 TSymbolTable &symbolTable; // symbol table that goes with the language currently being parsed 503 504 private: 505 class AtomicCounterBindingState; 506 constexpr static size_t kAtomicCounterSize = 4; 507 // UNIFORM_ARRAY_STRIDE for atomic counter arrays is an implementation-dependent value which 508 // can be queried after a program is linked according to ES 3.10 section 7.7.1. This is 509 // controversial with the offset inheritance as described in ESSL 3.10 section 4.4.6. Currently 510 // we treat it as always 4 in favour of the original interpretation in 511 // "ARB_shader_atomic_counters". 512 // TODO(jie.a.chen@intel.com): Double check this once the spec vagueness is resolved. 513 // Note that there may be tests in AtomicCounter_test that will need to be updated as well. 514 constexpr static size_t kAtomicCounterArrayStride = 4; 515 516 void markStaticReadIfSymbol(TIntermNode *node); 517 518 // Returns a clamped index. If it prints out an error message, the token is "[]". 519 int checkIndexLessThan(bool outOfRangeIndexIsError, 520 const TSourceLoc &location, 521 int index, 522 int arraySize, 523 const char *reason); 524 525 bool declareVariable(const TSourceLoc &line, 526 const ImmutableString &identifier, 527 const TType *type, 528 TVariable **variable); 529 530 void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line, 531 const ImmutableString &identifier, 532 TType *type); 533 534 TParameter parseParameterDeclarator(TType *type, 535 const ImmutableString &name, 536 const TSourceLoc &nameLoc); 537 538 bool checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation, 539 const TPublicType &elementType); 540 // Done for all atomic counter declarations, whether empty or not. 541 void atomicCounterQualifierErrorCheck(const TPublicType &publicType, 542 const TSourceLoc &location); 543 544 // Assumes that multiplication op has already been set based on the types. 545 bool isMultiplicationTypeCombinationValid(TOperator op, const TType &left, const TType &right); 546 547 void checkOutParameterIsNotOpaqueType(const TSourceLoc &line, 548 TQualifier qualifier, 549 const TType &type); 550 551 void checkInternalFormatIsNotSpecified(const TSourceLoc &location, 552 TLayoutImageInternalFormat internalFormat); 553 void checkMemoryQualifierIsNotSpecified(const TMemoryQualifier &memoryQualifier, 554 const TSourceLoc &location); 555 void checkAtomicCounterOffsetDoesNotOverlap(bool forceAppend, 556 const TSourceLoc &loc, 557 TType *type); 558 void checkAtomicCounterOffsetAlignment(const TSourceLoc &location, const TType &type); 559 560 void checkIndexIsNotSpecified(const TSourceLoc &location, int index); 561 void checkBindingIsValid(const TSourceLoc &identifierLocation, const TType &type); 562 void checkBindingIsNotSpecified(const TSourceLoc &location, int binding); 563 void checkOffsetIsNotSpecified(const TSourceLoc &location, int offset); 564 void checkImageBindingIsValid(const TSourceLoc &location, 565 int binding, 566 int arrayTotalElementCount); 567 void checkSamplerBindingIsValid(const TSourceLoc &location, 568 int binding, 569 int arrayTotalElementCount); 570 void checkBlockBindingIsValid(const TSourceLoc &location, 571 const TQualifier &qualifier, 572 int binding, 573 int arraySize); 574 void checkAtomicCounterBindingIsValid(const TSourceLoc &location, int binding); 575 576 void checkUniformLocationInRange(const TSourceLoc &location, 577 int objectLocationCount, 578 const TLayoutQualifier &layoutQualifier); 579 void checkAttributeLocationInRange(const TSourceLoc &location, 580 int objectLocationCount, 581 const TLayoutQualifier &layoutQualifier); 582 583 void checkYuvIsNotSpecified(const TSourceLoc &location, bool yuv); 584 585 void checkEarlyFragmentTestsIsNotSpecified(const TSourceLoc &location, bool earlyFragmentTests); 586 587 void checkNoncoherentIsSpecified(const TSourceLoc &location, bool noncoherent); 588 589 void checkNoncoherentIsNotSpecified(const TSourceLoc &location, bool noncoherent); 590 591 bool checkUnsizedArrayConstructorArgumentDimensionality(const TIntermSequence &arguments, 592 TType type, 593 const TSourceLoc &line); 594 595 void checkCombinedClipCullDistanceIsValid(const TSourceLoc &line, 596 const ImmutableString &identifier, 597 const int arraySize); 598 599 // Check texture offset is within range. 600 void checkSingleTextureOffset(const TSourceLoc &line, 601 const TConstantUnion *values, 602 size_t size, 603 int minOffsetValue, 604 int maxOffsetValue); 605 606 // Will set the size of the outermost array according to geometry shader input layout. 607 void checkGeometryShaderInputAndSetArraySize(const TSourceLoc &location, 608 const ImmutableString &token, 609 TType *type); 610 611 // Similar, for tessellation shaders. 612 void checkTessellationShaderUnsizedArraysAndSetSize(const TSourceLoc &location, 613 const ImmutableString &token, 614 TType *type); 615 616 // Will size any unsized array type so unsized arrays won't need to be taken into account 617 // further along the line in parsing. 618 void checkIsNotUnsizedArray(const TSourceLoc &line, 619 const char *errorMessage, 620 const ImmutableString &token, 621 TType *arrayType); 622 623 TIntermTyped *addBinaryMathInternal(TOperator op, 624 TIntermTyped *left, 625 TIntermTyped *right, 626 const TSourceLoc &loc); 627 TIntermTyped *createUnaryMath(TOperator op, 628 TIntermTyped *child, 629 const TSourceLoc &loc, 630 const TFunction *func); 631 632 TIntermTyped *addMethod(TFunctionLookup *fnCall, const TSourceLoc &loc); 633 TIntermTyped *addConstructor(TFunctionLookup *fnCall, const TSourceLoc &line); 634 TIntermTyped *addNonConstructorFunctionCall(TFunctionLookup *fnCall, const TSourceLoc &loc); 635 636 // Return either the original expression or the folded version of the expression in case the 637 // folded node will validate the same way during subsequent parsing. 638 TIntermTyped *expressionOrFoldedResult(TIntermTyped *expression); 639 640 // Return true if the checks pass 641 bool binaryOpCommonCheck(TOperator op, 642 TIntermTyped *left, 643 TIntermTyped *right, 644 const TSourceLoc &loc); 645 646 TIntermFunctionPrototype *createPrototypeNodeFromFunction(const TFunction &function, 647 const TSourceLoc &location, 648 bool insertParametersToSymbolTable); 649 650 void setAtomicCounterBindingDefaultOffset(const TPublicType &declaration, 651 const TSourceLoc &location); 652 653 bool checkPrimitiveTypeMatchesTypeQualifier(const TTypeQualifier &typeQualifier); 654 bool parseGeometryShaderInputLayoutQualifier(const TTypeQualifier &typeQualifier); 655 bool parseGeometryShaderOutputLayoutQualifier(const TTypeQualifier &typeQualifier); 656 void setGeometryShaderInputArraySize(unsigned int inputArraySize, const TSourceLoc &line); 657 658 bool parseTessControlShaderOutputLayoutQualifier(const TTypeQualifier &typeQualifier); 659 bool parseTessEvaluationShaderInputLayoutQualifier(const TTypeQualifier &typeQualifier); 660 661 // Set to true when the last/current declarator list was started with an empty declaration. The 662 // non-empty declaration error check will need to be performed if the empty declaration is 663 // followed by a declarator. 664 bool mDeferredNonEmptyDeclarationErrorCheck; 665 666 sh::GLenum mShaderType; // vertex/fragment/geometry/etc shader 667 ShShaderSpec mShaderSpec; // The language specification compiler conforms to - GLES/WebGL/etc. 668 ShCompileOptions mCompileOptions; // Options passed to TCompiler 669 int mShaderVersion; 670 TIntermBlock *mTreeRoot; // root of parse tree being created 671 int mLoopNestingLevel; // 0 if outside all loops 672 int mStructNestingLevel; // incremented while parsing a struct declaration 673 int mSwitchNestingLevel; // 0 if outside all switch statements 674 const TType 675 *mCurrentFunctionType; // the return type of the function that's currently being parsed 676 bool mFunctionReturnsValue; // true if a non-void function has a return 677 bool mChecksPrecisionErrors; // true if an error will be generated when a variable is declared 678 // without precision, explicit or implicit. 679 bool mFragmentPrecisionHighOnESSL1; // true if highp precision is supported when compiling 680 // ESSL1. 681 bool mEarlyFragmentTestsSpecified; // true if layout(early_fragment_tests) in; is specified. 682 TLayoutMatrixPacking mDefaultUniformMatrixPacking; 683 TLayoutBlockStorage mDefaultUniformBlockStorage; 684 TLayoutMatrixPacking mDefaultBufferMatrixPacking; 685 TLayoutBlockStorage mDefaultBufferBlockStorage; 686 TString mHashErrMsg; 687 TDiagnostics *mDiagnostics; 688 TDirectiveHandler mDirectiveHandler; 689 angle::pp::Preprocessor mPreprocessor; 690 void *mScanner; 691 int mMinProgramTexelOffset; 692 int mMaxProgramTexelOffset; 693 694 int mMinProgramTextureGatherOffset; 695 int mMaxProgramTextureGatherOffset; 696 697 // keep track of local group size declared in layout. It should be declared only once. 698 bool mComputeShaderLocalSizeDeclared; 699 sh::WorkGroupSize mComputeShaderLocalSize; 700 // keep track of number of views declared in layout. 701 int mNumViews; 702 int mMaxNumViews; 703 int mMaxImageUnits; 704 int mMaxCombinedTextureImageUnits; 705 int mMaxUniformLocations; 706 int mMaxUniformBufferBindings; 707 int mMaxVertexAttribs; 708 int mMaxAtomicCounterBindings; 709 int mMaxShaderStorageBufferBindings; 710 711 // keeps track whether we are declaring / defining a function 712 bool mDeclaringFunction; 713 714 // Track the state of each atomic counter binding. 715 std::map<int, AtomicCounterBindingState> mAtomicCounterBindingStates; 716 717 // Track the geometry shader global parameters declared in layout. 718 TLayoutPrimitiveType mGeometryShaderInputPrimitiveType; 719 TLayoutPrimitiveType mGeometryShaderOutputPrimitiveType; 720 int mGeometryShaderInvocations; 721 int mGeometryShaderMaxVertices; 722 int mMaxGeometryShaderInvocations; 723 int mMaxGeometryShaderMaxVertices; 724 unsigned int mGeometryInputArraySize; 725 726 int mMaxPatchVertices; 727 int mTessControlShaderOutputVertices; 728 TLayoutTessEvaluationType mTessEvaluationShaderInputPrimitiveType; 729 TLayoutTessEvaluationType mTessEvaluationShaderInputVertexSpacingType; 730 TLayoutTessEvaluationType mTessEvaluationShaderInputOrderingType; 731 TLayoutTessEvaluationType mTessEvaluationShaderInputPointType; 732 // List of array declarations without an explicit size that have come before layout(vertices=N). 733 // Once the vertex count is specified, these arrays are sized. 734 TVector<TType *> mTessControlDeferredArrayTypesToSize; 735 // Whether the |precise| keyword has been seen in the shader. 736 bool mHasAnyPreciseType; 737 738 // Track when we add new scope for func body in ESSL 1.00 spec 739 bool mFunctionBodyNewScope; 740 741 ShShaderOutput mOutputType; 742 }; 743 744 int PaParseStrings(size_t count, 745 const char *const string[], 746 const int length[], 747 TParseContext *context); 748 749 } // namespace sh 750 751 #endif // COMPILER_TRANSLATOR_PARSECONTEXT_H_ 752