OSDN Git Service

Increment the version number.
[android-x86/external-swiftshader.git] / src / Radiance / compiler / ParseHelper.h
1 //
2 // Copyright (c) 2002-2012 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
9 #include "compiler/Diagnostics.h"
10 #include "compiler/DirectiveHandler.h"
11 #include "compiler/localintermediate.h"
12 #include "compiler/preprocessor/Preprocessor.h"
13 #include "compiler/ShHandle.h"
14 #include "compiler/SymbolTable.h"
15
16 struct TMatrixFields {
17     bool wholeRow;
18     bool wholeCol;
19     int row;
20     int col;
21 };
22
23 //
24 // The following are extra variables needed during parsing, grouped together so
25 // they can be passed to the parser without needing a global.
26 //
27 struct TParseContext {
28     TParseContext(TSymbolTable& symt, TExtensionBehavior& ext, TIntermediate& interm, ShShaderType type, ShShaderSpec spec, int options, bool checksPrecErrors, const char* sourcePath, TInfoSink& is) :
29             intermediate(interm),
30             symbolTable(symt),
31             shaderType(type),
32             shaderSpec(spec),
33             compileOptions(options),
34             sourcePath(sourcePath),
35             treeRoot(0),
36             lexAfterType(false),
37             loopNestingLevel(0),
38             structNestingLevel(0),
39             inTypeParen(false),
40             currentFunctionType(NULL),
41             functionReturnsValue(false),
42             checksPrecisionErrors(checksPrecErrors),
43             diagnostics(is),
44             directiveHandler(ext, diagnostics),
45             preprocessor(&diagnostics, &directiveHandler),
46             scanner(NULL) {  }
47     TIntermediate& intermediate; // to hold and build a parse tree
48     TSymbolTable& symbolTable;   // symbol table that goes with the language currently being parsed
49     ShShaderType shaderType;              // vertex or fragment language (future: pack or unpack)
50     ShShaderSpec shaderSpec;              // The language specification compiler conforms to - GLES2 or WebGL.
51     int compileOptions;
52     const char* sourcePath;      // Path of source file or NULL.
53     TIntermNode* treeRoot;       // root of parse tree being created
54     bool lexAfterType;           // true if we've recognized a type, so can only be looking for an identifier
55     int loopNestingLevel;        // 0 if outside all loops
56     int structNestingLevel;      // incremented while parsing a struct declaration
57     bool inTypeParen;            // true if in parentheses, looking only for an identifier
58     const TType* currentFunctionType;  // the return type of the function that's currently being parsed
59     bool functionReturnsValue;   // true if a non-void function has a return
60     bool checksPrecisionErrors;  // true if an error will be generated when a variable is declared without precision, explicit or implicit.
61     TString HashErrMsg;
62     bool AfterEOF;
63     TDiagnostics diagnostics;
64     TDirectiveHandler directiveHandler;
65     pp::Preprocessor preprocessor;
66     void* scanner;
67
68     int numErrors() const { return diagnostics.numErrors(); }
69     TInfoSink& infoSink() { return diagnostics.infoSink(); }
70     void error(TSourceLoc loc, const char *reason, const char* token,
71                const char* extraInfo="");
72     void warning(TSourceLoc loc, const char* reason, const char* token,
73                  const char* extraInfo="");
74     void trace(const char* str);
75     void recover();
76
77     bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line);
78     bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, int line);
79
80     bool reservedErrorCheck(int line, const TString& identifier);
81     void assignError(int line, const char* op, TString left, TString right);
82     void unaryOpError(int line, const char* op, TString operand);
83     void binaryOpError(int line, const char* op, TString left, TString right);
84     bool precisionErrorCheck(int line, TPrecision precision, TBasicType type);
85     bool lValueErrorCheck(int line, const char* op, TIntermTyped*);
86     bool constErrorCheck(TIntermTyped* node);
87     bool integerErrorCheck(TIntermTyped* node, const char* token);
88     bool globalErrorCheck(int line, bool global, const char* token);
89     bool constructorErrorCheck(int line, TIntermNode*, TFunction&, TOperator, TType*);
90     bool arraySizeErrorCheck(int line, TIntermTyped* expr, int& size);
91     bool arrayQualifierErrorCheck(int line, TPublicType type);
92     bool arrayTypeErrorCheck(int line, TPublicType type);
93     bool arrayErrorCheck(int line, TString& identifier, TPublicType type, TVariable*& variable);
94     bool voidErrorCheck(int, const TString&, const TPublicType&);
95     bool boolErrorCheck(int, const TIntermTyped*);
96     bool boolErrorCheck(int, const TPublicType&);
97     bool samplerErrorCheck(int line, const TPublicType& pType, const char* reason);
98     bool structQualifierErrorCheck(int line, const TPublicType& pType);
99     bool parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type);
100     bool nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type, bool array);
101     bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type, TVariable*& variable);
102     bool paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type);
103     bool extensionErrorCheck(int line, const TString&);
104
105     const TExtensionBehavior& extensionBehavior() const { return directiveHandler.extensionBehavior(); }
106     bool supportsExtension(const char* extension);
107     void handleExtensionDirective(int line, const char* extName, const char* behavior);
108
109     const TPragma& pragma() const { return directiveHandler.pragma(); }
110     void handlePragmaDirective(int line, const char* name, const char* value);
111
112     bool containsSampler(TType& type);
113     bool areAllChildConst(TIntermAggregate* aggrNode);
114     const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0);
115     bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType,
116                             TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0);
117     bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc);
118
119     TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, TSourceLoc);
120     TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type);
121     TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, TSourceLoc);
122     TIntermTyped* addConstMatrixNode(int , TIntermTyped*, TSourceLoc);
123     TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line);
124     TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc);
125
126     // Performs an error check for embedded struct declarations.
127     // Returns true if an error was raised due to the declaration of
128     // this struct.
129     bool enterStructDeclaration(TSourceLoc line, const TString& identifier);
130     void exitStructDeclaration();
131
132     bool structNestingErrorCheck(TSourceLoc line, const TType& fieldType);
133 };
134
135 int PaParseStrings(int count, const char* const string[], const int length[],
136                    TParseContext* context);
137
138 #endif // _PARSER_HELPER_INCLUDED_