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 | |
| 9 | #include "ShHandle.h" |
| 10 | #include "SymbolTable.h" |
| 11 | #include "localintermediate.h" |
| 12 | |
| 13 | struct TMatrixFields { |
| 14 | bool wholeRow; |
| 15 | bool wholeCol; |
| 16 | int row; |
| 17 | int col; |
| 18 | }; |
| 19 | |
| 20 | typedef enum { |
| 21 | EBhRequire, |
| 22 | EBhEnable, |
| 23 | EBhWarn, |
| 24 | EBhDisable |
| 25 | } TBehavior; |
| 26 | |
| 27 | struct TPragma { |
| 28 | TPragma(bool o, bool d) : optimize(o), debug(d) { } |
| 29 | bool optimize; |
| 30 | bool debug; |
| 31 | TPragmaTable pragmaTable; |
| 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 { |
| 39 | TParseContext(TSymbolTable& symt, TIntermediate& interm, EShLanguage L, TInfoSink& is) : |
| 40 | intermediate(interm), symbolTable(symt), infoSink(is), language(L), treeRoot(0), |
| 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) |
| 47 | TIntermNode* treeRoot; // root of parse tree being created |
| 48 | bool recoveredFromError; // true if a parse error has occurred, but we continue to parse |
| 49 | int numErrors; |
| 50 | bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier |
| 51 | int loopNestingLevel; // 0 if outside all loops |
| 52 | bool inTypeParen; // true if in parentheses, looking only for an identifier |
| 53 | const TType* currentFunctionType; // the return type of the function that's currently being parsed |
| 54 | bool functionReturnsValue; // true if a non-void function has a return |
| 55 | TMap<TString, TBehavior> extensionBehavior; |
| 56 | void initializeExtensionBehavior(); |
| 57 | |
| 58 | void C_DECL error(TSourceLoc, const char *szReason, const char *szToken, |
| 59 | const char *szExtraInfoFormat, ...); |
| 60 | bool reservedErrorCheck(int line, const TString& identifier); |
| 61 | void recover(); |
| 62 | |
| 63 | bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line); |
| 64 | bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, int line); |
| 65 | void assignError(int line, const char* op, TString left, TString right); |
| 66 | void unaryOpError(int line, const char* op, TString operand); |
| 67 | void binaryOpError(int line, const char* op, TString left, TString right); |
| 68 | bool lValueErrorCheck(int line, const char* op, TIntermTyped*); |
| 69 | bool constErrorCheck(TIntermTyped* node); |
| 70 | bool integerErrorCheck(TIntermTyped* node, const char* token); |
| 71 | bool globalErrorCheck(int line, bool global, const char* token); |
| 72 | bool constructorErrorCheck(int line, TIntermNode*, TFunction&, TOperator, TType*); |
| 73 | bool arraySizeErrorCheck(int line, TIntermTyped* expr, int& size); |
| 74 | bool arrayQualifierErrorCheck(int line, TPublicType type); |
| 75 | bool arrayTypeErrorCheck(int line, TPublicType type); |
| 76 | bool arrayErrorCheck(int line, TString& identifier, TPublicType type, TVariable*& variable); |
| 77 | bool voidErrorCheck(int, const TString&, const TPublicType&); |
| 78 | bool boolErrorCheck(int, const TIntermTyped*); |
| 79 | bool boolErrorCheck(int, const TPublicType&); |
| 80 | bool samplerErrorCheck(int line, const TPublicType& pType, const char* reason); |
| 81 | bool structQualifierErrorCheck(int line, const TPublicType& pType); |
| 82 | bool parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type); |
| 83 | bool containsSampler(TType& type); |
| 84 | bool nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type); |
| 85 | bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type); |
| 86 | bool paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type); |
| 87 | bool extensionErrorCheck(int line, const char*); |
| 88 | const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0); |
| 89 | bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType, |
| 90 | TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0); |
| 91 | bool areAllChildConst(TIntermAggregate* aggrNode); |
| 92 | TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, TSourceLoc); |
| 93 | TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type); |
| 94 | TIntermTyped* constructStruct(TIntermNode*, TType*, int, TSourceLoc, bool subset); |
| 95 | TIntermTyped* constructBuiltIn(const TType*, TOperator, TIntermNode*, TSourceLoc, bool subset); |
| 96 | TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, TSourceLoc); |
| 97 | TIntermTyped* addConstMatrixNode(int , TIntermTyped*, TSourceLoc); |
| 98 | TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line); |
| 99 | TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc); |
| 100 | bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc); |
| 101 | struct TPragma contextPragma; |
| 102 | TString HashErrMsg; |
| 103 | bool AfterEOF; |
| 104 | }; |
| 105 | |
| 106 | int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext&); |
| 107 | void PaReservedWord(); |
| 108 | int PaIdentOrType(TString& id, TParseContext&, TSymbol*&); |
| 109 | int PaParseComment(int &lineno, TParseContext&); |
| 110 | void setInitialState(); |
| 111 | |
| 112 | typedef TParseContext* TParseContextPointer; |
| 113 | extern TParseContextPointer& GetGlobalParseContext(); |
| 114 | #define GlobalParseContext GetGlobalParseContext() |
| 115 | |
| 116 | typedef struct TThreadParseContextRec |
| 117 | { |
| 118 | TParseContext *lpGlobalParseContext; |
| 119 | } TThreadParseContext; |
| 120 | |
| 121 | #endif // _PARSER_HELPER_INCLUDED_ |