michael@0: // michael@0: // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: #ifndef _PARSER_HELPER_INCLUDED_ michael@0: #define _PARSER_HELPER_INCLUDED_ michael@0: michael@0: #include "compiler/Diagnostics.h" michael@0: #include "compiler/DirectiveHandler.h" michael@0: #include "compiler/localintermediate.h" michael@0: #include "compiler/preprocessor/Preprocessor.h" michael@0: #include "compiler/ShHandle.h" michael@0: #include "compiler/SymbolTable.h" michael@0: michael@0: struct TMatrixFields { michael@0: bool wholeRow; michael@0: bool wholeCol; michael@0: int row; michael@0: int col; michael@0: }; michael@0: michael@0: // michael@0: // The following are extra variables needed during parsing, grouped together so michael@0: // they can be passed to the parser without needing a global. michael@0: // michael@0: struct TParseContext { michael@0: TParseContext(TSymbolTable& symt, TExtensionBehavior& ext, TIntermediate& interm, ShShaderType type, ShShaderSpec spec, int options, bool checksPrecErrors, const char* sourcePath, TInfoSink& is) : michael@0: intermediate(interm), michael@0: symbolTable(symt), michael@0: shaderType(type), michael@0: shaderSpec(spec), michael@0: compileOptions(options), michael@0: sourcePath(sourcePath), michael@0: treeRoot(0), michael@0: loopNestingLevel(0), michael@0: structNestingLevel(0), michael@0: currentFunctionType(NULL), michael@0: functionReturnsValue(false), michael@0: checksPrecisionErrors(checksPrecErrors), michael@0: diagnostics(is), michael@0: directiveHandler(ext, diagnostics), michael@0: preprocessor(&diagnostics, &directiveHandler), michael@0: scanner(NULL) { } michael@0: TIntermediate& intermediate; // to hold and build a parse tree michael@0: TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed michael@0: ShShaderType shaderType; // vertex or fragment language (future: pack or unpack) michael@0: ShShaderSpec shaderSpec; // The language specification compiler conforms to - GLES2 or WebGL. michael@0: int compileOptions; michael@0: const char* sourcePath; // Path of source file or NULL. michael@0: TIntermNode* treeRoot; // root of parse tree being created michael@0: int loopNestingLevel; // 0 if outside all loops michael@0: int structNestingLevel; // incremented while parsing a struct declaration michael@0: const TType* currentFunctionType; // the return type of the function that's currently being parsed michael@0: bool functionReturnsValue; // true if a non-void function has a return michael@0: bool checksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit. michael@0: bool fragmentPrecisionHigh; // true if highp precision is supported in the fragment language. michael@0: TString HashErrMsg; michael@0: TDiagnostics diagnostics; michael@0: TDirectiveHandler directiveHandler; michael@0: pp::Preprocessor preprocessor; michael@0: void* scanner; michael@0: michael@0: int numErrors() const { return diagnostics.numErrors(); } michael@0: TInfoSink& infoSink() { return diagnostics.infoSink(); } michael@0: void error(const TSourceLoc& loc, const char *reason, const char* token, michael@0: const char* extraInfo=""); michael@0: void warning(const TSourceLoc& loc, const char* reason, const char* token, michael@0: const char* extraInfo=""); michael@0: void trace(const char* str); michael@0: void recover(); michael@0: michael@0: bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc& line); michael@0: bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, const TSourceLoc& line); michael@0: michael@0: bool reservedErrorCheck(const TSourceLoc& line, const TString& identifier); michael@0: void assignError(const TSourceLoc& line, const char* op, TString left, TString right); michael@0: void unaryOpError(const TSourceLoc& line, const char* op, TString operand); michael@0: void binaryOpError(const TSourceLoc& line, const char* op, TString left, TString right); michael@0: bool precisionErrorCheck(const TSourceLoc& line, TPrecision precision, TBasicType type); michael@0: bool lValueErrorCheck(const TSourceLoc& line, const char* op, TIntermTyped*); michael@0: bool constErrorCheck(TIntermTyped* node); michael@0: bool integerErrorCheck(TIntermTyped* node, const char* token); michael@0: bool globalErrorCheck(const TSourceLoc& line, bool global, const char* token); michael@0: bool constructorErrorCheck(const TSourceLoc& line, TIntermNode*, TFunction&, TOperator, TType*); michael@0: bool arraySizeErrorCheck(const TSourceLoc& line, TIntermTyped* expr, int& size); michael@0: bool arrayQualifierErrorCheck(const TSourceLoc& line, TPublicType type); michael@0: bool arrayTypeErrorCheck(const TSourceLoc& line, TPublicType type); michael@0: bool arrayErrorCheck(const TSourceLoc& line, TString& identifier, TPublicType type, TVariable*& variable); michael@0: bool voidErrorCheck(const TSourceLoc&, const TString&, const TPublicType&); michael@0: bool boolErrorCheck(const TSourceLoc&, const TIntermTyped*); michael@0: bool boolErrorCheck(const TSourceLoc&, const TPublicType&); michael@0: bool samplerErrorCheck(const TSourceLoc& line, const TPublicType& pType, const char* reason); michael@0: bool structQualifierErrorCheck(const TSourceLoc& line, const TPublicType& pType); michael@0: bool parameterSamplerErrorCheck(const TSourceLoc& line, TQualifier qualifier, const TType& type); michael@0: bool nonInitConstErrorCheck(const TSourceLoc& line, TString& identifier, TPublicType& type, bool array); michael@0: bool nonInitErrorCheck(const TSourceLoc& line, TString& identifier, TPublicType& type, TVariable*& variable); michael@0: bool paramErrorCheck(const TSourceLoc& line, TQualifier qualifier, TQualifier paramQualifier, TType* type); michael@0: bool extensionErrorCheck(const TSourceLoc& line, const TString&); michael@0: michael@0: const TPragma& pragma() const { return directiveHandler.pragma(); } michael@0: const TExtensionBehavior& extensionBehavior() const { return directiveHandler.extensionBehavior(); } michael@0: bool supportsExtension(const char* extension); michael@0: bool isExtensionEnabled(const char* extension) const; michael@0: michael@0: bool containsSampler(TType& type); michael@0: bool areAllChildConst(TIntermAggregate* aggrNode); michael@0: const TFunction* findFunction(const TSourceLoc& line, TFunction* pfnCall, bool *builtIn = 0); michael@0: bool executeInitializer(const TSourceLoc& line, TString& identifier, TPublicType& pType, michael@0: TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0); michael@0: michael@0: TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, const TSourceLoc&); michael@0: TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type); michael@0: TIntermTyped* constructStruct(TIntermNode*, TType*, int, const TSourceLoc&, bool subset); michael@0: TIntermTyped* constructBuiltIn(const TType*, TOperator, TIntermNode*, const TSourceLoc&, bool subset); michael@0: TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, const TSourceLoc&); michael@0: TIntermTyped* addConstMatrixNode(int , TIntermTyped*, const TSourceLoc&); michael@0: TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, const TSourceLoc& line); michael@0: TIntermTyped* addConstStruct(TString& , TIntermTyped*, const TSourceLoc&); michael@0: TIntermTyped* addIndexExpression(TIntermTyped *baseExpression, const TSourceLoc& location, TIntermTyped *indexExpression); michael@0: michael@0: // Performs an error check for embedded struct declarations. michael@0: // Returns true if an error was raised due to the declaration of michael@0: // this struct. michael@0: bool enterStructDeclaration(const TSourceLoc& line, const TString& identifier); michael@0: void exitStructDeclaration(); michael@0: michael@0: bool structNestingErrorCheck(const TSourceLoc& line, const TField& field); michael@0: }; michael@0: michael@0: int PaParseStrings(size_t count, const char* const string[], const int length[], michael@0: TParseContext* context); michael@0: michael@0: #endif // _PARSER_HELPER_INCLUDED_