daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2010 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 _PARSER_HELPER_INCLUDED_ |
| 7 | #define _PARSER_HELPER_INCLUDED_ |
| 8 | |
alokp@chromium.org | ad771eb | 2010-09-07 17:36:23 +0000 | [diff] [blame] | 9 | #include "compiler/ExtensionBehavior.h" |
| 10 | #include "compiler/localintermediate.h" |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 11 | #include "compiler/ShHandle.h" |
| 12 | #include "compiler/SymbolTable.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 13 | |
| 14 | struct TMatrixFields { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 15 | bool wholeRow; |
| 16 | bool wholeCol; |
| 17 | int row; |
| 18 | int col; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 19 | }; |
| 20 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 21 | struct TPragma { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 22 | TPragma(bool o, bool d) : optimize(o), debug(d) { } |
| 23 | bool optimize; |
| 24 | bool debug; |
| 25 | TPragmaTable pragmaTable; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | // |
| 29 | // The following are extra variables needed during parsing, grouped together so |
| 30 | // they can be passed to the parser without needing a global. |
| 31 | // |
| 32 | struct TParseContext { |
zmo@google.com | dc4b4f8 | 2011-06-17 00:42:53 +0000 | [diff] [blame] | 33 | 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^] | 34 | intermediate(interm), |
| 35 | symbolTable(symt), |
| 36 | extensionBehavior(ext), |
| 37 | infoSink(is), |
| 38 | shaderType(type), |
| 39 | shaderSpec(spec), |
| 40 | compileOptions(options), |
| 41 | sourcePath(sourcePath), |
| 42 | treeRoot(0), |
| 43 | numErrors(0), |
| 44 | lexAfterType(false), |
| 45 | loopNestingLevel(0), |
| 46 | structNestingLevel(0), |
| 47 | inTypeParen(false), |
| 48 | currentFunctionType(NULL), |
| 49 | functionReturnsValue(false), |
| 50 | checksPrecisionErrors(checksPrecErrors), |
| 51 | contextPragma(true, false), |
| 52 | scanner(NULL) { } |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 53 | TIntermediate& intermediate; // to hold and build a parse tree |
| 54 | TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 55 | TExtensionBehavior& extensionBehavior; // mapping between supported extensions and current behavior. |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 56 | TInfoSink& infoSink; |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 57 | ShShaderType shaderType; // vertex or fragment language (future: pack or unpack) |
| 58 | ShShaderSpec shaderSpec; // The language specification compiler conforms to - GLES2 or WebGL. |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 59 | int compileOptions; |
| 60 | const char* sourcePath; // Path of source file or NULL. |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 61 | TIntermNode* treeRoot; // root of parse tree being created |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 62 | int numErrors; |
| 63 | bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier |
| 64 | int loopNestingLevel; // 0 if outside all loops |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame^] | 65 | int structNestingLevel; // incremented while parsing a struct declaration |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 66 | bool inTypeParen; // true if in parentheses, looking only for an identifier |
| 67 | const TType* currentFunctionType; // the return type of the function that's currently being parsed |
| 68 | bool functionReturnsValue; // true if a non-void function has a return |
zmo@google.com | dc4b4f8 | 2011-06-17 00:42:53 +0000 | [diff] [blame] | 69 | bool checksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit. |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 70 | struct TPragma contextPragma; |
| 71 | TString HashErrMsg; |
| 72 | bool AfterEOF; |
| 73 | void* scanner; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 74 | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 75 | void error(TSourceLoc loc, const char *reason, const char* token, |
| 76 | const char* extraInfoFormat, ...); |
| 77 | void warning(TSourceLoc loc, const char* reason, const char* token, |
| 78 | const char* extraInfoFormat, ...); |
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); |
| 82 | bool parseMatrixFields(const TString&, int matSize, 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 | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 104 | bool nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type); |
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&); |
zmo@google.com | 09c323a | 2011-08-12 18:22:25 +0000 | [diff] [blame] | 108 | bool supportsExtension(const char* extension); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 109 | |
| 110 | bool containsSampler(TType& type); |
| 111 | bool areAllChildConst(TIntermAggregate* aggrNode); |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 112 | const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0); |
| 113 | bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType, |
| 114 | TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0); |
alokp@chromium.org | 75fe6b7 | 2011-08-14 05:31:22 +0000 | [diff] [blame] | 115 | bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc); |
| 116 | |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 117 | TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, TSourceLoc); |
| 118 | TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type); |
| 119 | TIntermTyped* constructStruct(TIntermNode*, TType*, int, TSourceLoc, bool subset); |
| 120 | TIntermTyped* constructBuiltIn(const TType*, TOperator, TIntermNode*, TSourceLoc, bool subset); |
| 121 | TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, TSourceLoc); |
| 122 | TIntermTyped* addConstMatrixNode(int , TIntermTyped*, TSourceLoc); |
| 123 | TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line); |
| 124 | TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc); |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame^] | 125 | |
| 126 | // Performs an error check for embedded struct declarations. |
| 127 | // Returns true if an error was raised due to the declaration of |
| 128 | // this struct. |
| 129 | bool enterStructDeclaration(TSourceLoc line, const TString& identifier); |
| 130 | void exitStructDeclaration(); |
| 131 | |
| 132 | bool structNestingErrorCheck(TSourceLoc line, const TType& fieldType); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 135 | int PaParseStrings(int count, const char* const string[], const int length[], |
| 136 | TParseContext* context); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 137 | |
| 138 | typedef TParseContext* TParseContextPointer; |
| 139 | extern TParseContextPointer& GetGlobalParseContext(); |
| 140 | #define GlobalParseContext GetGlobalParseContext() |
| 141 | |
| 142 | typedef struct TThreadParseContextRec |
| 143 | { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 144 | TParseContext *lpGlobalParseContext; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 145 | } TThreadParseContext; |
| 146 | |
| 147 | #endif // _PARSER_HELPER_INCLUDED_ |