gfx/angle/src/compiler/ParseHelper.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/angle/src/compiler/ParseHelper.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,134 @@
     1.4 +//
     1.5 +// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
     1.6 +// Use of this source code is governed by a BSD-style license that can be
     1.7 +// found in the LICENSE file.
     1.8 +//
     1.9 +#ifndef _PARSER_HELPER_INCLUDED_
    1.10 +#define _PARSER_HELPER_INCLUDED_
    1.11 +
    1.12 +#include "compiler/Diagnostics.h"
    1.13 +#include "compiler/DirectiveHandler.h"
    1.14 +#include "compiler/localintermediate.h"
    1.15 +#include "compiler/preprocessor/Preprocessor.h"
    1.16 +#include "compiler/ShHandle.h"
    1.17 +#include "compiler/SymbolTable.h"
    1.18 +
    1.19 +struct TMatrixFields {
    1.20 +    bool wholeRow;
    1.21 +    bool wholeCol;
    1.22 +    int row;
    1.23 +    int col;
    1.24 +};
    1.25 +
    1.26 +//
    1.27 +// The following are extra variables needed during parsing, grouped together so
    1.28 +// they can be passed to the parser without needing a global.
    1.29 +//
    1.30 +struct TParseContext {
    1.31 +    TParseContext(TSymbolTable& symt, TExtensionBehavior& ext, TIntermediate& interm, ShShaderType type, ShShaderSpec spec, int options, bool checksPrecErrors, const char* sourcePath, TInfoSink& is) :
    1.32 +            intermediate(interm),
    1.33 +            symbolTable(symt),
    1.34 +            shaderType(type),
    1.35 +            shaderSpec(spec),
    1.36 +            compileOptions(options),
    1.37 +            sourcePath(sourcePath),
    1.38 +            treeRoot(0),
    1.39 +            loopNestingLevel(0),
    1.40 +            structNestingLevel(0),
    1.41 +            currentFunctionType(NULL),
    1.42 +            functionReturnsValue(false),
    1.43 +            checksPrecisionErrors(checksPrecErrors),
    1.44 +            diagnostics(is),
    1.45 +            directiveHandler(ext, diagnostics),
    1.46 +            preprocessor(&diagnostics, &directiveHandler),
    1.47 +            scanner(NULL) {  }
    1.48 +    TIntermediate& intermediate; // to hold and build a parse tree
    1.49 +    TSymbolTable& symbolTable;   // symbol table that goes with the language currently being parsed
    1.50 +    ShShaderType shaderType;              // vertex or fragment language (future: pack or unpack)
    1.51 +    ShShaderSpec shaderSpec;              // The language specification compiler conforms to - GLES2 or WebGL.
    1.52 +    int compileOptions;
    1.53 +    const char* sourcePath;      // Path of source file or NULL.
    1.54 +    TIntermNode* treeRoot;       // root of parse tree being created
    1.55 +    int loopNestingLevel;        // 0 if outside all loops
    1.56 +    int structNestingLevel;      // incremented while parsing a struct declaration
    1.57 +    const TType* currentFunctionType;  // the return type of the function that's currently being parsed
    1.58 +    bool functionReturnsValue;   // true if a non-void function has a return
    1.59 +    bool checksPrecisionErrors;  // true if an error will be generated when a variable is declared without precision, explicit or implicit.
    1.60 +    bool fragmentPrecisionHigh;  // true if highp precision is supported in the fragment language.
    1.61 +    TString HashErrMsg;
    1.62 +    TDiagnostics diagnostics;
    1.63 +    TDirectiveHandler directiveHandler;
    1.64 +    pp::Preprocessor preprocessor;
    1.65 +    void* scanner;
    1.66 +
    1.67 +    int numErrors() const { return diagnostics.numErrors(); }
    1.68 +    TInfoSink& infoSink() { return diagnostics.infoSink(); }
    1.69 +    void error(const TSourceLoc& loc, const char *reason, const char* token,
    1.70 +               const char* extraInfo="");
    1.71 +    void warning(const TSourceLoc& loc, const char* reason, const char* token,
    1.72 +                 const char* extraInfo="");
    1.73 +    void trace(const char* str);
    1.74 +    void recover();
    1.75 +
    1.76 +    bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc& line);
    1.77 +    bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, const TSourceLoc& line);
    1.78 +
    1.79 +    bool reservedErrorCheck(const TSourceLoc& line, const TString& identifier);
    1.80 +    void assignError(const TSourceLoc& line, const char* op, TString left, TString right);
    1.81 +    void unaryOpError(const TSourceLoc& line, const char* op, TString operand);
    1.82 +    void binaryOpError(const TSourceLoc& line, const char* op, TString left, TString right);
    1.83 +    bool precisionErrorCheck(const TSourceLoc& line, TPrecision precision, TBasicType type);
    1.84 +    bool lValueErrorCheck(const TSourceLoc& line, const char* op, TIntermTyped*);
    1.85 +    bool constErrorCheck(TIntermTyped* node);
    1.86 +    bool integerErrorCheck(TIntermTyped* node, const char* token);
    1.87 +    bool globalErrorCheck(const TSourceLoc& line, bool global, const char* token);
    1.88 +    bool constructorErrorCheck(const TSourceLoc& line, TIntermNode*, TFunction&, TOperator, TType*);
    1.89 +    bool arraySizeErrorCheck(const TSourceLoc& line, TIntermTyped* expr, int& size);
    1.90 +    bool arrayQualifierErrorCheck(const TSourceLoc& line, TPublicType type);
    1.91 +    bool arrayTypeErrorCheck(const TSourceLoc& line, TPublicType type);
    1.92 +    bool arrayErrorCheck(const TSourceLoc& line, TString& identifier, TPublicType type, TVariable*& variable);
    1.93 +    bool voidErrorCheck(const TSourceLoc&, const TString&, const TPublicType&);
    1.94 +    bool boolErrorCheck(const TSourceLoc&, const TIntermTyped*);
    1.95 +    bool boolErrorCheck(const TSourceLoc&, const TPublicType&);
    1.96 +    bool samplerErrorCheck(const TSourceLoc& line, const TPublicType& pType, const char* reason);
    1.97 +    bool structQualifierErrorCheck(const TSourceLoc& line, const TPublicType& pType);
    1.98 +    bool parameterSamplerErrorCheck(const TSourceLoc& line, TQualifier qualifier, const TType& type);
    1.99 +    bool nonInitConstErrorCheck(const TSourceLoc& line, TString& identifier, TPublicType& type, bool array);
   1.100 +    bool nonInitErrorCheck(const TSourceLoc& line, TString& identifier, TPublicType& type, TVariable*& variable);
   1.101 +    bool paramErrorCheck(const TSourceLoc& line, TQualifier qualifier, TQualifier paramQualifier, TType* type);
   1.102 +    bool extensionErrorCheck(const TSourceLoc& line, const TString&);
   1.103 +
   1.104 +    const TPragma& pragma() const { return directiveHandler.pragma(); }
   1.105 +    const TExtensionBehavior& extensionBehavior() const { return directiveHandler.extensionBehavior(); }
   1.106 +    bool supportsExtension(const char* extension);
   1.107 +    bool isExtensionEnabled(const char* extension) const;
   1.108 +
   1.109 +    bool containsSampler(TType& type);
   1.110 +    bool areAllChildConst(TIntermAggregate* aggrNode);
   1.111 +    const TFunction* findFunction(const TSourceLoc& line, TFunction* pfnCall, bool *builtIn = 0);
   1.112 +    bool executeInitializer(const TSourceLoc& line, TString& identifier, TPublicType& pType,
   1.113 +                            TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0);
   1.114 +
   1.115 +    TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, const TSourceLoc&);
   1.116 +    TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type);
   1.117 +    TIntermTyped* constructStruct(TIntermNode*, TType*, int, const TSourceLoc&, bool subset);
   1.118 +    TIntermTyped* constructBuiltIn(const TType*, TOperator, TIntermNode*, const TSourceLoc&, bool subset);
   1.119 +    TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, const TSourceLoc&);
   1.120 +    TIntermTyped* addConstMatrixNode(int , TIntermTyped*, const TSourceLoc&);
   1.121 +    TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, const TSourceLoc& line);
   1.122 +    TIntermTyped* addConstStruct(TString& , TIntermTyped*, const TSourceLoc&);
   1.123 +    TIntermTyped* addIndexExpression(TIntermTyped *baseExpression, const TSourceLoc& location, TIntermTyped *indexExpression);
   1.124 +
   1.125 +    // Performs an error check for embedded struct declarations.
   1.126 +    // Returns true if an error was raised due to the declaration of
   1.127 +    // this struct.
   1.128 +    bool enterStructDeclaration(const TSourceLoc& line, const TString& identifier);
   1.129 +    void exitStructDeclaration();
   1.130 +
   1.131 +    bool structNestingErrorCheck(const TSourceLoc& line, const TField& field);
   1.132 +};
   1.133 +
   1.134 +int PaParseStrings(size_t count, const char* const string[], const int length[],
   1.135 +                   TParseContext* context);
   1.136 +
   1.137 +#endif // _PARSER_HELPER_INCLUDED_

mercurial