blob: 718ff325ecca3fb4f29c2f228084e0c540fdea22 [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 {
daniel@transgaming.com0578f812010-05-17 09:58:39 +000039 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();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000057
daniel@transgaming.com0578f812010-05-17 09:58:39 +000058 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();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000062
daniel@transgaming.com0578f812010-05-17 09:58:39 +000063 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);
daniel@transgaming.coma5d76232010-05-17 09:58:47 +000068 bool precisionErrorCheck(int line, TPrecision precision, TBasicType type);
daniel@transgaming.com0578f812010-05-17 09:58:39 +000069 bool lValueErrorCheck(int line, const char* op, TIntermTyped*);
70 bool constErrorCheck(TIntermTyped* node);
71 bool integerErrorCheck(TIntermTyped* node, const char* token);
72 bool globalErrorCheck(int line, bool global, const char* token);
73 bool constructorErrorCheck(int line, TIntermNode*, TFunction&, TOperator, TType*);
74 bool arraySizeErrorCheck(int line, TIntermTyped* expr, int& size);
75 bool arrayQualifierErrorCheck(int line, TPublicType type);
76 bool arrayTypeErrorCheck(int line, TPublicType type);
77 bool arrayErrorCheck(int line, TString& identifier, TPublicType type, TVariable*& variable);
78 bool voidErrorCheck(int, const TString&, const TPublicType&);
79 bool boolErrorCheck(int, const TIntermTyped*);
80 bool boolErrorCheck(int, const TPublicType&);
81 bool samplerErrorCheck(int line, const TPublicType& pType, const char* reason);
82 bool structQualifierErrorCheck(int line, const TPublicType& pType);
83 bool parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type);
84 bool containsSampler(TType& type);
85 bool nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type);
86 bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type);
87 bool paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type);
88 bool extensionErrorCheck(int line, const char*);
89 const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0);
90 bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType,
91 TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0);
92 bool areAllChildConst(TIntermAggregate* aggrNode);
93 TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, TSourceLoc);
94 TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type);
95 TIntermTyped* constructStruct(TIntermNode*, TType*, int, TSourceLoc, bool subset);
96 TIntermTyped* constructBuiltIn(const TType*, TOperator, TIntermNode*, TSourceLoc, bool subset);
97 TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, TSourceLoc);
98 TIntermTyped* addConstMatrixNode(int , TIntermTyped*, TSourceLoc);
99 TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line);
100 TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc);
101 bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc);
102 struct TPragma contextPragma;
103 TString HashErrMsg;
104 bool AfterEOF;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000105};
106
107int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext&);
108void PaReservedWord();
109int PaIdentOrType(TString& id, TParseContext&, TSymbol*&);
110int PaParseComment(int &lineno, TParseContext&);
111void setInitialState();
112
113typedef TParseContext* TParseContextPointer;
114extern TParseContextPointer& GetGlobalParseContext();
115#define GlobalParseContext GetGlobalParseContext()
116
117typedef struct TThreadParseContextRec
118{
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000119 TParseContext *lpGlobalParseContext;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000120} TThreadParseContext;
121
122#endif // _PARSER_HELPER_INCLUDED_