daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 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 | // |
| 6 | #ifndef _PARSER_HELPER_INCLUDED_ |
| 7 | #define _PARSER_HELPER_INCLUDED_ |
| 8 | |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 9 | #include "compiler/Diagnostics.h" |
| 10 | #include "compiler/DirectiveHandler.h" |
alokp@chromium.org | ad771eb | 2010-09-07 17:36:23 +0000 | [diff] [blame] | 11 | #include "compiler/localintermediate.h" |
daniel@transgaming.com | b401a92 | 2012-10-26 18:58:24 +0000 | [diff] [blame] | 12 | #include "compiler/preprocessor/Preprocessor.h" |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 13 | #include "compiler/ShHandle.h" |
| 14 | #include "compiler/SymbolTable.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 15 | |
| 16 | struct TMatrixFields { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 17 | bool wholeRow; |
| 18 | bool wholeCol; |
| 19 | int row; |
| 20 | int col; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 21 | }; |
| 22 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 23 | // |
| 24 | // The following are extra variables needed during parsing, grouped together so |
| 25 | // they can be passed to the parser without needing a global. |
| 26 | // |
| 27 | struct TParseContext { |
zmo@google.com | dc4b4f8 | 2011-06-17 00:42:53 +0000 | [diff] [blame] | 28 | TParseContext(TSymbolTable& symt, TExtensionBehavior& ext, TIntermediate& interm, ShShaderType type, ShShaderSpec spec, int options, bool checksPrecErrors, const char* sourcePath, TInfoSink& is) : |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 29 | intermediate(interm), |
| 30 | symbolTable(symt), |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 31 | shaderType(type), |
| 32 | shaderSpec(spec), |
| 33 | compileOptions(options), |
| 34 | sourcePath(sourcePath), |
| 35 | treeRoot(0), |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 36 | lexAfterType(false), |
| 37 | loopNestingLevel(0), |
| 38 | structNestingLevel(0), |
| 39 | inTypeParen(false), |
| 40 | currentFunctionType(NULL), |
| 41 | functionReturnsValue(false), |
| 42 | checksPrecisionErrors(checksPrecErrors), |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 43 | diagnostics(is), |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 44 | shaderVersion(100), |
| 45 | directiveHandler(ext, diagnostics, shaderVersion), |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 46 | preprocessor(&diagnostics, &directiveHandler), |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 47 | scanner(NULL) { } |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 48 | TIntermediate& intermediate; // to hold and build a parse tree |
| 49 | TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 50 | ShShaderType shaderType; // vertex or fragment language (future: pack or unpack) |
| 51 | ShShaderSpec shaderSpec; // The language specification compiler conforms to - GLES2 or WebGL. |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 52 | int shaderVersion; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 53 | int compileOptions; |
| 54 | const char* sourcePath; // Path of source file or NULL. |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 55 | TIntermNode* treeRoot; // root of parse tree being created |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 56 | bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier |
| 57 | int loopNestingLevel; // 0 if outside all loops |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 58 | int structNestingLevel; // incremented while parsing a struct declaration |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 59 | bool inTypeParen; // true if in parentheses, looking only for an identifier |
| 60 | const TType* currentFunctionType; // the return type of the function that's currently being parsed |
| 61 | bool functionReturnsValue; // true if a non-void function has a return |
zmo@google.com | dc4b4f8 | 2011-06-17 00:42:53 +0000 | [diff] [blame] | 62 | bool checksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit. |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 63 | bool fragmentPrecisionHigh; // true if highp precision is supported in the fragment language. |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 64 | TString HashErrMsg; |
| 65 | bool AfterEOF; |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 66 | TDiagnostics diagnostics; |
| 67 | TDirectiveHandler directiveHandler; |
| 68 | pp::Preprocessor preprocessor; |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 69 | void* scanner; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 70 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 71 | int getShaderVersion() const { return shaderVersion; } |
alokp@chromium.org | 6b49571 | 2012-06-29 00:06:58 +0000 | [diff] [blame] | 72 | int numErrors() const { return diagnostics.numErrors(); } |
alokp@chromium.org | 646ea1e | 2012-06-15 17:36:31 +0000 | [diff] [blame] | 73 | TInfoSink& infoSink() { return diagnostics.infoSink(); } |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 74 | void error(TSourceLoc loc, const char *reason, const char* token, |
maxvujovic@gmail.com | c6b3b3c | 2012-06-27 22:49:39 +0000 | [diff] [blame] | 75 | const char* extraInfo=""); |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 76 | void warning(TSourceLoc loc, const char* reason, const char* token, |
maxvujovic@gmail.com | c6b3b3c | 2012-06-27 22:49:39 +0000 | [diff] [blame] | 77 | const char* extraInfo=""); |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 78 | void trace(const char* str); |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 79 | void recover(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 80 | |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 81 | bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line); |
shannonwoods@chromium.org | 09e0988 | 2013-05-30 00:18:25 +0000 | [diff] [blame] | 82 | bool parseMatrixFields(const TString&, int matCols, int matRows, TMatrixFields&, int line); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 83 | |
| 84 | bool reservedErrorCheck(int line, const TString& identifier); |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 85 | void assignError(int line, const char* op, TString left, TString right); |
| 86 | void unaryOpError(int line, const char* op, TString operand); |
| 87 | void binaryOpError(int line, const char* op, TString left, TString right); |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 88 | bool precisionErrorCheck(int line, TPrecision precision, TBasicType type); |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 89 | bool lValueErrorCheck(int line, const char* op, TIntermTyped*); |
| 90 | bool constErrorCheck(TIntermTyped* node); |
| 91 | bool integerErrorCheck(TIntermTyped* node, const char* token); |
| 92 | bool globalErrorCheck(int line, bool global, const char* token); |
| 93 | bool constructorErrorCheck(int line, TIntermNode*, TFunction&, TOperator, TType*); |
| 94 | bool arraySizeErrorCheck(int line, TIntermTyped* expr, int& size); |
| 95 | bool arrayQualifierErrorCheck(int line, TPublicType type); |
| 96 | bool arrayTypeErrorCheck(int line, TPublicType type); |
| 97 | bool arrayErrorCheck(int line, TString& identifier, TPublicType type, TVariable*& variable); |
| 98 | bool voidErrorCheck(int, const TString&, const TPublicType&); |
| 99 | bool boolErrorCheck(int, const TIntermTyped*); |
| 100 | bool boolErrorCheck(int, const TPublicType&); |
| 101 | bool samplerErrorCheck(int line, const TPublicType& pType, const char* reason); |
| 102 | bool structQualifierErrorCheck(int line, const TPublicType& pType); |
| 103 | bool parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type); |
daniel@transgaming.com | 8abd0b7 | 2012-09-27 17:46:07 +0000 | [diff] [blame] | 104 | bool nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type, bool array); |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 105 | bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type, TVariable*& variable); |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 106 | bool paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type); |
alokp@chromium.org | 8815d7f | 2010-09-09 17:30:03 +0000 | [diff] [blame] | 107 | bool extensionErrorCheck(int line, const TString&); |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 108 | |
alokp@chromium.org | 73bc298 | 2012-06-19 18:48:05 +0000 | [diff] [blame] | 109 | const TExtensionBehavior& extensionBehavior() const { return directiveHandler.extensionBehavior(); } |
zmo@google.com | 09c323a | 2011-08-12 18:22:25 +0000 | [diff] [blame] | 110 | bool supportsExtension(const char* extension); |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 111 | void handleExtensionDirective(int line, const char* extName, const char* behavior); |
| 112 | |
| 113 | const TPragma& pragma() const { return directiveHandler.pragma(); } |
| 114 | void handlePragmaDirective(int line, const char* name, const char* value); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 115 | |
| 116 | bool containsSampler(TType& type); |
| 117 | bool areAllChildConst(TIntermAggregate* aggrNode); |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 118 | const TFunction* findFunction(int line, TFunction* pfnCall, int shaderVersion, bool *builtIn = 0); |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 119 | bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType, |
| 120 | TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 121 | bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc); |
| 122 | |
shannonwoods@chromium.org | 0f376ca | 2013-05-30 00:19:23 +0000 | [diff] [blame^] | 123 | TPublicType addFullySpecifiedType(TQualifier qualifier, const TPublicType& typeSpecifier); |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 124 | TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, TSourceLoc); |
| 125 | TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type); |
| 126 | TIntermTyped* constructStruct(TIntermNode*, TType*, int, TSourceLoc, bool subset); |
| 127 | TIntermTyped* constructBuiltIn(const TType*, TOperator, TIntermNode*, TSourceLoc, bool subset); |
| 128 | TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, TSourceLoc); |
| 129 | TIntermTyped* addConstMatrixNode(int , TIntermTyped*, TSourceLoc); |
| 130 | TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line); |
shannonwoods@chromium.org | a910088 | 2013-05-30 00:11:39 +0000 | [diff] [blame] | 131 | TIntermTyped* addConstStruct(const TString &identifier, TIntermTyped *node, TSourceLoc line); |
| 132 | TIntermTyped* addIndexExpression(TIntermTyped *baseExpression, TSourceLoc location, TIntermTyped *indexExpression); |
| 133 | TIntermTyped* addFieldSelectionExpression(TIntermTyped *baseExpression, TSourceLoc dotLocation, const TString &fieldString, TSourceLoc fieldLocation); |
| 134 | |
| 135 | TTypeList *addStructDeclaratorList(const TPublicType& typeSpecifier, TTypeList *typeList); |
| 136 | TPublicType addStructure(TSourceLoc structLine, TSourceLoc nameLine, const TString &structName, TTypeList* typeList); |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 137 | |
shannonwoods@chromium.org | 5668c5d | 2013-05-30 00:11:48 +0000 | [diff] [blame] | 138 | TIntermAggregate* addInterfaceBlock(const TPublicType& typeQualifier, TSourceLoc nameLine, const TString& blockName, TTypeList* typeList, |
| 139 | const TString& instanceName, TSourceLoc instanceLine, TIntermTyped* arrayIndex, TSourceLoc arrayIndexLine); |
| 140 | |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 141 | // Performs an error check for embedded struct declarations. |
| 142 | // Returns true if an error was raised due to the declaration of |
| 143 | // this struct. |
| 144 | bool enterStructDeclaration(TSourceLoc line, const TString& identifier); |
| 145 | void exitStructDeclaration(); |
| 146 | |
| 147 | bool structNestingErrorCheck(TSourceLoc line, const TType& fieldType); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 150 | int PaParseStrings(size_t count, const char* const string[], const int length[], |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 151 | TParseContext* context); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 152 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 153 | #endif // _PARSER_HELPER_INCLUDED_ |