blob: cdc86761cb2e1eea7c78ed274c77e486253e2b7f [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
alokp@chromium.orgad771eb2010-09-07 17:36:23 +00009#include "compiler/ExtensionBehavior.h"
10#include "compiler/localintermediate.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011#include "compiler/ShHandle.h"
12#include "compiler/SymbolTable.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000013
14struct TMatrixFields {
daniel@transgaming.com0578f812010-05-17 09:58:39 +000015 bool wholeRow;
16 bool wholeCol;
17 int row;
18 int col;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000019};
20
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000021struct TPragma {
daniel@transgaming.com0578f812010-05-17 09:58:39 +000022 TPragma(bool o, bool d) : optimize(o), debug(d) { }
23 bool optimize;
24 bool debug;
25 TPragmaTable pragmaTable;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000026};
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//
32struct TParseContext {
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000033 TParseContext(TSymbolTable& symt, const TExtensionBehavior& ext, TIntermediate& interm, ShShaderType type, ShShaderSpec spec, TInfoSink& is) :
34 intermediate(interm), symbolTable(symt), extensionBehavior(ext), infoSink(is), shaderType(type), shaderSpec(spec), treeRoot(0),
daniel@transgaming.com0578f812010-05-17 09:58:39 +000035 recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0),
36 inTypeParen(false), contextPragma(true, false) { }
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.orgad771eb2010-09-07 17:36:23 +000039 TExtensionBehavior extensionBehavior; // mapping between supported extensions and current behavior.
daniel@transgaming.com0578f812010-05-17 09:58:39 +000040 TInfoSink& infoSink;
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000041 ShShaderType shaderType; // vertex or fragment language (future: pack or unpack)
42 ShShaderSpec shaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
daniel@transgaming.com0578f812010-05-17 09:58:39 +000043 TIntermNode* treeRoot; // root of parse tree being created
44 bool recoveredFromError; // true if a parse error has occurred, but we continue to parse
45 int numErrors;
46 bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier
47 int loopNestingLevel; // 0 if outside all loops
48 bool inTypeParen; // true if in parentheses, looking only for an identifier
49 const TType* currentFunctionType; // the return type of the function that's currently being parsed
50 bool functionReturnsValue; // true if a non-void function has a return
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000051
alokp@chromium.orgc54bf502010-07-22 16:49:09 +000052 void error(TSourceLoc, const char *szReason, const char *szToken,
53 const char *szExtraInfoFormat, ...);
daniel@transgaming.com0578f812010-05-17 09:58:39 +000054 bool reservedErrorCheck(int line, const TString& identifier);
55 void recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000056
daniel@transgaming.com0578f812010-05-17 09:58:39 +000057 bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line);
58 bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, int line);
59 void assignError(int line, const char* op, TString left, TString right);
60 void unaryOpError(int line, const char* op, TString operand);
61 void binaryOpError(int line, const char* op, TString left, TString right);
daniel@transgaming.coma5d76232010-05-17 09:58:47 +000062 bool precisionErrorCheck(int line, TPrecision precision, TBasicType type);
daniel@transgaming.com0578f812010-05-17 09:58:39 +000063 bool lValueErrorCheck(int line, const char* op, TIntermTyped*);
64 bool constErrorCheck(TIntermTyped* node);
65 bool integerErrorCheck(TIntermTyped* node, const char* token);
66 bool globalErrorCheck(int line, bool global, const char* token);
67 bool constructorErrorCheck(int line, TIntermNode*, TFunction&, TOperator, TType*);
68 bool arraySizeErrorCheck(int line, TIntermTyped* expr, int& size);
69 bool arrayQualifierErrorCheck(int line, TPublicType type);
70 bool arrayTypeErrorCheck(int line, TPublicType type);
71 bool arrayErrorCheck(int line, TString& identifier, TPublicType type, TVariable*& variable);
72 bool voidErrorCheck(int, const TString&, const TPublicType&);
73 bool boolErrorCheck(int, const TIntermTyped*);
74 bool boolErrorCheck(int, const TPublicType&);
75 bool samplerErrorCheck(int line, const TPublicType& pType, const char* reason);
76 bool structQualifierErrorCheck(int line, const TPublicType& pType);
77 bool parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type);
78 bool containsSampler(TType& type);
79 bool nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type);
80 bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type);
81 bool paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type);
alokp@chromium.org8815d7f2010-09-09 17:30:03 +000082 bool extensionErrorCheck(int line, const TString&);
daniel@transgaming.com0578f812010-05-17 09:58:39 +000083 const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0);
84 bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType,
85 TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0);
86 bool areAllChildConst(TIntermAggregate* aggrNode);
87 TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, TSourceLoc);
88 TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type);
89 TIntermTyped* constructStruct(TIntermNode*, TType*, int, TSourceLoc, bool subset);
90 TIntermTyped* constructBuiltIn(const TType*, TOperator, TIntermNode*, TSourceLoc, bool subset);
91 TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, TSourceLoc);
92 TIntermTyped* addConstMatrixNode(int , TIntermTyped*, TSourceLoc);
93 TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line);
94 TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc);
95 bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc);
96 struct TPragma contextPragma;
97 TString HashErrMsg;
98 bool AfterEOF;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000099};
100
alokp@chromium.org07620a52010-09-23 17:53:56 +0000101int PaParseStrings(const char* const argv[], const int strLen[], int argc, TParseContext&);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000102void PaReservedWord();
103int PaIdentOrType(TString& id, TParseContext&, TSymbol*&);
104int PaParseComment(int &lineno, TParseContext&);
105void setInitialState();
106
107typedef TParseContext* TParseContextPointer;
108extern TParseContextPointer& GetGlobalParseContext();
109#define GlobalParseContext GetGlobalParseContext()
110
111typedef struct TThreadParseContextRec
112{
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000113 TParseContext *lpGlobalParseContext;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000114} TThreadParseContext;
115
116#endif // _PARSER_HELPER_INCLUDED_