blob: 8fb621475d7a90f92b68dbf1a29e8ff8a497bd0a [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
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.combbf56f72010-04-20 18:52:13 +00009#include "compiler/ShHandle.h"
10#include "compiler/SymbolTable.h"
11#include "compiler/localintermediate.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012
13struct TMatrixFields {
daniel@transgaming.com0578f812010-05-17 09:58:39 +000014 bool wholeRow;
15 bool wholeCol;
16 int row;
17 int col;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000018};
19
20typedef enum {
daniel@transgaming.com0578f812010-05-17 09:58:39 +000021 EBhRequire,
22 EBhEnable,
23 EBhWarn,
24 EBhDisable
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025} TBehavior;
26
27struct TPragma {
daniel@transgaming.com0578f812010-05-17 09:58:39 +000028 TPragma(bool o, bool d) : optimize(o), debug(d) { }
29 bool optimize;
30 bool debug;
31 TPragmaTable pragmaTable;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000032};
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//
38struct TParseContext {
alokp@chromium.org613ef312010-07-21 18:54:22 +000039 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.com0578f812010-05-17 09:58:39 +000041 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.org613ef312010-07-21 18:54:22 +000047 EShSpec spec; // The language specification compiler conforms to - GLES2 or WebGL.
daniel@transgaming.com0578f812010-05-17 09:58:39 +000048 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.com4f39fd92010-03-08 20:26:45 +000058
daniel@transgaming.com0578f812010-05-17 09:58:39 +000059 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.com4f39fd92010-03-08 20:26:45 +000063
daniel@transgaming.com0578f812010-05-17 09:58:39 +000064 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.coma5d76232010-05-17 09:58:47 +000069 bool precisionErrorCheck(int line, TPrecision precision, TBasicType type);
daniel@transgaming.com0578f812010-05-17 09:58:39 +000070 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.com4f39fd92010-03-08 20:26:45 +0000106};
107
108int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext&);
109void PaReservedWord();
110int PaIdentOrType(TString& id, TParseContext&, TSymbol*&);
111int PaParseComment(int &lineno, TParseContext&);
112void setInitialState();
113
114typedef TParseContext* TParseContextPointer;
115extern TParseContextPointer& GetGlobalParseContext();
116#define GlobalParseContext GetGlobalParseContext()
117
118typedef struct TThreadParseContextRec
119{
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000120 TParseContext *lpGlobalParseContext;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000121} TThreadParseContext;
122
123#endif // _PARSER_HELPER_INCLUDED_