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 { |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame^] | 33 | TParseContext(TSymbolTable& symt, const TExtensionBehavior& ext, TIntermediate& interm, ShShaderType type, ShShaderSpec spec, int options, const char* sourcePath, TInfoSink& is) : |
| 34 | intermediate(interm), symbolTable(symt), extensionBehavior(ext), infoSink(is), shaderType(type), shaderSpec(spec), compileOptions(options), sourcePath(sourcePath), treeRoot(0), |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 35 | recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0), |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 36 | inTypeParen(false), scanner(NULL), contextPragma(true, false) { } |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 37 | TIntermediate& intermediate; // to hold and build a parse tree |
| 38 | TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed |
alokp@chromium.org | ad771eb | 2010-09-07 17:36:23 +0000 | [diff] [blame] | 39 | TExtensionBehavior extensionBehavior; // mapping between supported extensions and current behavior. |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 40 | TInfoSink& infoSink; |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 41 | ShShaderType shaderType; // vertex or fragment language (future: pack or unpack) |
| 42 | ShShaderSpec shaderSpec; // The language specification compiler conforms to - GLES2 or WebGL. |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame^] | 43 | int compileOptions; |
| 44 | const char* sourcePath; // Path of source file or NULL. |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 45 | TIntermNode* treeRoot; // root of parse tree being created |
| 46 | bool recoveredFromError; // true if a parse error has occurred, but we continue to parse |
| 47 | int numErrors; |
| 48 | bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier |
| 49 | int loopNestingLevel; // 0 if outside all loops |
| 50 | bool inTypeParen; // true if in parentheses, looking only for an identifier |
| 51 | const TType* currentFunctionType; // the return type of the function that's currently being parsed |
| 52 | bool functionReturnsValue; // true if a non-void function has a return |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 53 | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 54 | void error(TSourceLoc loc, const char *reason, const char* token, |
| 55 | const char* extraInfoFormat, ...); |
| 56 | void warning(TSourceLoc loc, const char* reason, const char* token, |
| 57 | const char* extraInfoFormat, ...); |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 58 | bool reservedErrorCheck(int line, const TString& identifier); |
| 59 | void recover(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 60 | |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 61 | bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line); |
| 62 | bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, int line); |
| 63 | void assignError(int line, const char* op, TString left, TString right); |
| 64 | void unaryOpError(int line, const char* op, TString operand); |
| 65 | void binaryOpError(int line, const char* op, TString left, TString right); |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 66 | bool precisionErrorCheck(int line, TPrecision precision, TBasicType type); |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 67 | bool lValueErrorCheck(int line, const char* op, TIntermTyped*); |
| 68 | bool constErrorCheck(TIntermTyped* node); |
| 69 | bool integerErrorCheck(TIntermTyped* node, const char* token); |
| 70 | bool globalErrorCheck(int line, bool global, const char* token); |
| 71 | bool constructorErrorCheck(int line, TIntermNode*, TFunction&, TOperator, TType*); |
| 72 | bool arraySizeErrorCheck(int line, TIntermTyped* expr, int& size); |
| 73 | bool arrayQualifierErrorCheck(int line, TPublicType type); |
| 74 | bool arrayTypeErrorCheck(int line, TPublicType type); |
| 75 | bool arrayErrorCheck(int line, TString& identifier, TPublicType type, TVariable*& variable); |
| 76 | bool voidErrorCheck(int, const TString&, const TPublicType&); |
| 77 | bool boolErrorCheck(int, const TIntermTyped*); |
| 78 | bool boolErrorCheck(int, const TPublicType&); |
| 79 | bool samplerErrorCheck(int line, const TPublicType& pType, const char* reason); |
| 80 | bool structQualifierErrorCheck(int line, const TPublicType& pType); |
| 81 | bool parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type); |
| 82 | bool containsSampler(TType& type); |
| 83 | bool nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type); |
| 84 | bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type); |
| 85 | bool paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type); |
alokp@chromium.org | 8815d7f | 2010-09-09 17:30:03 +0000 | [diff] [blame] | 86 | bool extensionErrorCheck(int line, const TString&); |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 87 | const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0); |
| 88 | bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType, |
| 89 | TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0); |
| 90 | bool areAllChildConst(TIntermAggregate* aggrNode); |
| 91 | TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, TSourceLoc); |
| 92 | TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type); |
| 93 | TIntermTyped* constructStruct(TIntermNode*, TType*, int, TSourceLoc, bool subset); |
| 94 | TIntermTyped* constructBuiltIn(const TType*, TOperator, TIntermNode*, TSourceLoc, bool subset); |
| 95 | TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, TSourceLoc); |
| 96 | TIntermTyped* addConstMatrixNode(int , TIntermTyped*, TSourceLoc); |
| 97 | TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line); |
| 98 | TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc); |
| 99 | bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc); |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 100 | void* scanner; |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 101 | struct TPragma contextPragma; |
| 102 | TString HashErrMsg; |
| 103 | bool AfterEOF; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 106 | int PaParseStrings(int count, const char* const string[], const int length[], |
| 107 | TParseContext* context); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 108 | |
| 109 | typedef TParseContext* TParseContextPointer; |
| 110 | extern TParseContextPointer& GetGlobalParseContext(); |
| 111 | #define GlobalParseContext GetGlobalParseContext() |
| 112 | |
| 113 | typedef struct TThreadParseContextRec |
| 114 | { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 115 | TParseContext *lpGlobalParseContext; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 116 | } TThreadParseContext; |
| 117 | |
| 118 | #endif // _PARSER_HELPER_INCLUDED_ |