blob: 7efc23fd7419b13e05ea37dca3c3f014fd4c2fa1 [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 {
zmo@google.comdc4b4f82011-06-17 00:42:53 +000033 TParseContext(TSymbolTable& symt, TExtensionBehavior& ext, TIntermediate& interm, ShShaderType type, ShShaderSpec spec, int options, bool checksPrecErrors, const char* sourcePath, TInfoSink& is) :
34 intermediate(interm), symbolTable(symt), extensionBehavior(ext), infoSink(is), shaderType(type), shaderSpec(spec), compileOptions(options), checksPrecisionErrors(checksPrecErrors), sourcePath(sourcePath), treeRoot(0),
daniel@transgaming.com0578f812010-05-17 09:58:39 +000035 recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0),
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000036 inTypeParen(false), scanner(NULL), contextPragma(true, false) { }
daniel@transgaming.com0578f812010-05-17 09:58:39 +000037 TIntermediate& intermediate; // to hold and build a parse tree
38 TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed
zmo@google.com5601ea02011-06-10 18:23:25 +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.
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000043 int compileOptions;
44 const char* sourcePath; // Path of source file or NULL.
daniel@transgaming.com0578f812010-05-17 09:58:39 +000045 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
zmo@google.comdc4b4f82011-06-17 00:42:53 +000053 bool checksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000054
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000055 void error(TSourceLoc loc, const char *reason, const char* token,
56 const char* extraInfoFormat, ...);
57 void warning(TSourceLoc loc, const char* reason, const char* token,
58 const char* extraInfoFormat, ...);
daniel@transgaming.com0578f812010-05-17 09:58:39 +000059 bool reservedErrorCheck(int line, const TString& identifier);
60 void recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000061
daniel@transgaming.com0578f812010-05-17 09:58:39 +000062 bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line);
63 bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, int line);
64 void assignError(int line, const char* op, TString left, TString right);
65 void unaryOpError(int line, const char* op, TString operand);
66 void binaryOpError(int line, const char* op, TString left, TString right);
daniel@transgaming.coma5d76232010-05-17 09:58:47 +000067 bool precisionErrorCheck(int line, TPrecision precision, TBasicType type);
daniel@transgaming.com0578f812010-05-17 09:58:39 +000068 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);
zmo@google.comfd747b82011-04-23 01:30:07 +000085 bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type, TVariable*& variable);
daniel@transgaming.com0578f812010-05-17 09:58:39 +000086 bool paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type);
alokp@chromium.org8815d7f2010-09-09 17:30:03 +000087 bool extensionErrorCheck(int line, const TString&);
zmo@google.com09c323a2011-08-12 18:22:25 +000088 bool supportsExtension(const char* extension);
daniel@transgaming.com0578f812010-05-17 09:58:39 +000089 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);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000102 void* scanner;
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000103 struct TPragma contextPragma;
104 TString HashErrMsg;
105 bool AfterEOF;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000106};
107
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000108int PaParseStrings(int count, const char* const string[], const int length[],
109 TParseContext* context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000110
111typedef TParseContext* TParseContextPointer;
112extern TParseContextPointer& GetGlobalParseContext();
113#define GlobalParseContext GetGlobalParseContext()
114
115typedef struct TThreadParseContextRec
116{
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000117 TParseContext *lpGlobalParseContext;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000118} TThreadParseContext;
119
120#endif // _PARSER_HELPER_INCLUDED_