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 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 9 | #include "compiler/ShHandle.h" |
| 10 | #include "compiler/SymbolTable.h" |
| 11 | #include "compiler/localintermediate.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 12 | |
| 13 | struct TMatrixFields { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 14 | bool wholeRow; |
| 15 | bool wholeCol; |
| 16 | int row; |
| 17 | int col; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 18 | }; |
| 19 | |
| 20 | typedef enum { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 21 | EBhRequire, |
| 22 | EBhEnable, |
| 23 | EBhWarn, |
| 24 | EBhDisable |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 25 | } TBehavior; |
| 26 | |
| 27 | struct TPragma { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 28 | TPragma(bool o, bool d) : optimize(o), debug(d) { } |
| 29 | bool optimize; |
| 30 | bool debug; |
| 31 | TPragmaTable pragmaTable; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | // |
| 35 | // The following are extra variables needed during parsing, grouped together so |
| 36 | // they can be passed to the parser without needing a global. |
| 37 | // |
| 38 | struct TParseContext { |
alokp@chromium.org | 613ef31 | 2010-07-21 18:54:22 +0000 | [diff] [blame^] | 39 | TParseContext(TSymbolTable& symt, TIntermediate& interm, EShLanguage l, EShSpec s, TInfoSink& is) : |
| 40 | intermediate(interm), symbolTable(symt), infoSink(is), language(l), spec(s), treeRoot(0), |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 41 | recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0), |
| 42 | inTypeParen(false), contextPragma(true, false) { } |
| 43 | TIntermediate& intermediate; // to hold and build a parse tree |
| 44 | TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed |
| 45 | TInfoSink& infoSink; |
| 46 | EShLanguage language; // vertex or fragment language (future: pack or unpack) |
alokp@chromium.org | 613ef31 | 2010-07-21 18:54:22 +0000 | [diff] [blame^] | 47 | EShSpec spec; // The language specification compiler conforms to - GLES2 or WebGL. |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 48 | TIntermNode* treeRoot; // root of parse tree being created |
| 49 | bool recoveredFromError; // true if a parse error has occurred, but we continue to parse |
| 50 | int numErrors; |
| 51 | bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier |
| 52 | int loopNestingLevel; // 0 if outside all loops |
| 53 | bool inTypeParen; // true if in parentheses, looking only for an identifier |
| 54 | const TType* currentFunctionType; // the return type of the function that's currently being parsed |
| 55 | bool functionReturnsValue; // true if a non-void function has a return |
| 56 | TMap<TString, TBehavior> extensionBehavior; |
| 57 | void initializeExtensionBehavior(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 58 | |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 59 | void C_DECL error(TSourceLoc, const char *szReason, const char *szToken, |
| 60 | const char *szExtraInfoFormat, ...); |
| 61 | bool reservedErrorCheck(int line, const TString& identifier); |
| 62 | void recover(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 63 | |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 64 | bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line); |
| 65 | bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, int line); |
| 66 | void assignError(int line, const char* op, TString left, TString right); |
| 67 | void unaryOpError(int line, const char* op, TString operand); |
| 68 | void binaryOpError(int line, const char* op, TString left, TString right); |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 69 | bool precisionErrorCheck(int line, TPrecision precision, TBasicType type); |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 70 | bool lValueErrorCheck(int line, const char* op, TIntermTyped*); |
| 71 | bool constErrorCheck(TIntermTyped* node); |
| 72 | bool integerErrorCheck(TIntermTyped* node, const char* token); |
| 73 | bool globalErrorCheck(int line, bool global, const char* token); |
| 74 | bool constructorErrorCheck(int line, TIntermNode*, TFunction&, TOperator, TType*); |
| 75 | bool arraySizeErrorCheck(int line, TIntermTyped* expr, int& size); |
| 76 | bool arrayQualifierErrorCheck(int line, TPublicType type); |
| 77 | bool arrayTypeErrorCheck(int line, TPublicType type); |
| 78 | bool arrayErrorCheck(int line, TString& identifier, TPublicType type, TVariable*& variable); |
| 79 | bool voidErrorCheck(int, const TString&, const TPublicType&); |
| 80 | bool boolErrorCheck(int, const TIntermTyped*); |
| 81 | bool boolErrorCheck(int, const TPublicType&); |
| 82 | bool samplerErrorCheck(int line, const TPublicType& pType, const char* reason); |
| 83 | bool structQualifierErrorCheck(int line, const TPublicType& pType); |
| 84 | bool parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type); |
| 85 | bool containsSampler(TType& type); |
| 86 | bool nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type); |
| 87 | bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type); |
| 88 | bool paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type); |
| 89 | bool extensionErrorCheck(int line, const char*); |
| 90 | const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0); |
| 91 | bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType, |
| 92 | TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0); |
| 93 | bool areAllChildConst(TIntermAggregate* aggrNode); |
| 94 | TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, TSourceLoc); |
| 95 | TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type); |
| 96 | TIntermTyped* constructStruct(TIntermNode*, TType*, int, TSourceLoc, bool subset); |
| 97 | TIntermTyped* constructBuiltIn(const TType*, TOperator, TIntermNode*, TSourceLoc, bool subset); |
| 98 | TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, TSourceLoc); |
| 99 | TIntermTyped* addConstMatrixNode(int , TIntermTyped*, TSourceLoc); |
| 100 | TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line); |
| 101 | TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc); |
| 102 | bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc); |
| 103 | struct TPragma contextPragma; |
| 104 | TString HashErrMsg; |
| 105 | bool AfterEOF; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext&); |
| 109 | void PaReservedWord(); |
| 110 | int PaIdentOrType(TString& id, TParseContext&, TSymbol*&); |
| 111 | int PaParseComment(int &lineno, TParseContext&); |
| 112 | void setInitialState(); |
| 113 | |
| 114 | typedef TParseContext* TParseContextPointer; |
| 115 | extern TParseContextPointer& GetGlobalParseContext(); |
| 116 | #define GlobalParseContext GetGlobalParseContext() |
| 117 | |
| 118 | typedef struct TThreadParseContextRec |
| 119 | { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 120 | TParseContext *lpGlobalParseContext; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 121 | } TThreadParseContext; |
| 122 | |
| 123 | #endif // _PARSER_HELPER_INCLUDED_ |