zenilib: zenilib/jni/external/angle/src/compiler/ParseHelper.h Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ParseHelper.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2002-2013 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 loopNestingLevel(0),
37 structNestingLevel(0),
38 currentFunctionType(NULL),
39 functionReturnsValue(false),
40 checksPrecisionErrors(checksPrecErrors),
41 diagnostics(is),
42 directiveHandler(ext, diagnostics),
43 preprocessor(&diagnostics, &directiveHandler),
44 scanner(NULL) { }
45 TIntermediate& intermediate; // to hold and build a parse tree
46 TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed
47 ShShaderType shaderType; // vertex or fragment language (future: pack or unpack)
48 ShShaderSpec shaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
49 int compileOptions;
50 const char* sourcePath; // Path of source file or NULL.
51 TIntermNode* treeRoot; // root of parse tree being created
52 int loopNestingLevel; // 0 if outside all loops
53 int structNestingLevel; // incremented while parsing a struct declaration
54 const TType* currentFunctionType; // the return type of the function that's currently being parsed
55 bool functionReturnsValue; // true if a non-void function has a return
56 bool checksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit.
57 bool fragmentPrecisionHigh; // true if highp precision is supported in the fragment language.
58 TString HashErrMsg;
59 TDiagnostics diagnostics;
60 TDirectiveHandler directiveHandler;
61 pp::Preprocessor preprocessor;
62 void* scanner;
63
64 int numErrors() const { return diagnostics.numErrors(); }
65 TInfoSink& infoSink() { return diagnostics.infoSink(); }
66 void error(const TSourceLoc& loc, const char *reason, const char* token,
67 const char* extraInfo="");
68 void warning(const TSourceLoc& loc, const char* reason, const char* token,
69 const char* extraInfo="");
70 void trace(const char* str);
71 void recover();
72
73 bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc& line);
74 bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, const TSourceLoc& line);
75
76 bool reservedErrorCheck(const TSourceLoc& line, const TString& identifier);
77 void assignError(const TSourceLoc& line, const char* op, TString left, TString right);
78 void unaryOpError(const TSourceLoc& line, const char* op, TString operand);
79 void binaryOpError(const TSourceLoc& line, const char* op, TString left, TString right);
80 bool precisionErrorCheck(const TSourceLoc& line, TPrecision precision, TBasicType type);
81 bool lValueErrorCheck(const TSourceLoc& line, const char* op, TIntermTyped*);
82 bool constErrorCheck(TIntermTyped* node);
83 bool integerErrorCheck(TIntermTyped* node, const char* token);
84 bool globalErrorCheck(const TSourceLoc& line, bool global, const char* token);
85 bool constructorErrorCheck(const TSourceLoc& line, TIntermNode*, TFunction&, TOperator, TType*);
86 bool arraySizeErrorCheck(const TSourceLoc& line, TIntermTyped* expr, int& size);
87 bool arrayQualifierErrorCheck(const TSourceLoc& line, TPublicType type);
88 bool arrayTypeErrorCheck(const TSourceLoc& line, TPublicType type);
89 bool arrayErrorCheck(const TSourceLoc& line, TString& identifier, TPublicType type, TVariable*& variable);
90 bool voidErrorCheck(const TSourceLoc&, const TString&, const TPublicType&);
91 bool boolErrorCheck(const TSourceLoc&, const TIntermTyped*);
92 bool boolErrorCheck(const TSourceLoc&, const TPublicType&);
93 bool samplerErrorCheck(const TSourceLoc& line, const TPublicType& pType, const char* reason);
94 bool structQualifierErrorCheck(const TSourceLoc& line, const TPublicType& pType);
95 bool parameterSamplerErrorCheck(const TSourceLoc& line, TQualifier qualifier, const TType& type);
96 bool nonInitConstErrorCheck(const TSourceLoc& line, TString& identifier, TPublicType& type, bool array);
97 bool nonInitErrorCheck(const TSourceLoc& line, TString& identifier, TPublicType& type, TVariable*& variable);
98 bool paramErrorCheck(const TSourceLoc& line, TQualifier qualifier, TQualifier paramQualifier, TType* type);
99 bool extensionErrorCheck(const TSourceLoc& line, const TString&);
100
101 const TPragma& pragma() const { return directiveHandler.pragma(); }
102 const TExtensionBehavior& extensionBehavior() const { return directiveHandler.extensionBehavior(); }
103 bool supportsExtension(const char* extension);
104 bool isExtensionEnabled(const char* extension) const;
105
106 bool containsSampler(TType& type);
107 bool areAllChildConst(TIntermAggregate* aggrNode);
108 const TFunction* findFunction(const TSourceLoc& line, TFunction* pfnCall, bool *builtIn = 0);
109 bool executeInitializer(const TSourceLoc& line, TString& identifier, TPublicType& pType,
110 TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0);
111
112 TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, const TSourceLoc&);
113 TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type);
114 TIntermTyped* constructStruct(TIntermNode*, TType*, int, const TSourceLoc&, bool subset);
115 TIntermTyped* constructBuiltIn(const TType*, TOperator, TIntermNode*, const TSourceLoc&, bool subset);
116 TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, const TSourceLoc&);
117 TIntermTyped* addConstMatrixNode(int , TIntermTyped*, const TSourceLoc&);
118 TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, const TSourceLoc& line);
119 TIntermTyped* addConstStruct(TString& , TIntermTyped*, const TSourceLoc&);
120 TIntermTyped* addIndexExpression(TIntermTyped *baseExpression, const TSourceLoc& location, TIntermTyped *indexExpression);
121
122 // Performs an error check for embedded struct declarations.
123 // Returns true if an error was raised due to the declaration of
124 // this struct.
125 bool enterStructDeclaration(const TSourceLoc& line, const TString& identifier);
126 void exitStructDeclaration();
127
128 bool structNestingErrorCheck(const TSourceLoc& line, const TField& field);
129 };
130
131 int PaParseStrings(size_t count, const char* const string[], const int length[],
132 TParseContext* context);
133
134 #endif // _PARSER_HELPER_INCLUDED_
TOperator
TOperator
Definition: intermediate.h:29
TParseContext::error
void error(const TSourceLoc &loc, const char *reason, const char *token, const char *extraInfo="")
Definition: ParseHelper.cpp:178
TMatrixFields
Definition: ParseHelper.h:16
TParseContext::lValueErrorCheck
bool lValueErrorCheck(const TSourceLoc &line, const char *op, TIntermTyped *)
Definition: ParseHelper.cpp:268
TParseContext::symbolTable
TSymbolTable & symbolTable
Definition: ParseHelper.h:46
TParseContext::checksPrecisionErrors
bool checksPrecisionErrors
Definition: ParseHelper.h:56
TQualifier
TQualifier
Definition: BaseTypes.h:81
TParseContext::preprocessor
pp::Preprocessor preprocessor
Definition: ParseHelper.h:61
TParseContext::foldConstConstructor
TIntermTyped * foldConstConstructor(TIntermAggregate *aggrNode, const TType &type)
Definition: ParseHelper.cpp:1131
TExtensionBehavior
std::map< std::string, TBehavior > TExtensionBehavior
Definition: ExtensionBehavior.h:35
TField
Definition: Types.h:19
type
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
TParseContext::shaderType
ShShaderType shaderType
Definition: ParseHelper.h:47
TParseContext::voidErrorCheck
bool voidErrorCheck(const TSourceLoc &, const TString &, const TPublicType &)
Definition: ParseHelper.cpp:572
TDirectiveHandler
Definition: DirectiveHandler.h:16
left
GLint left
Definition: glew.h:7291
DirectiveHandler.h
TParseContext::shaderSpec
ShShaderSpec shaderSpec
Definition: ParseHelper.h:48
NULL
#define NULL
Definition: ftobjs.h:61
TParseContext::arraySizeErrorCheck
bool arraySizeErrorCheck(const TSourceLoc &line, TIntermTyped *expr, int &size)
Definition: ParseHelper.cpp:676
TPublicType
Definition: Types.h:259
TParseContext::scanner
void * scanner
Definition: ParseHelper.h:62
location
GLint location
Definition: gl2ext.h:1164
TMatrixFields::wholeCol
bool wholeCol
Definition: ParseHelper.h:18
pp::Preprocessor
Definition: Preprocessor.h:22
TParseContext
Definition: ParseHelper.h:27
TIntermediate
Definition: localintermediate.h:23
TSymbolTable
Definition: SymbolTable.h:237
TParseContext::addConstructor
TIntermTyped * addConstructor(TIntermNode *, const TType *, TOperator, TFunction *, const TSourceLoc &)
Definition: ParseHelper.cpp:1052
TPragma
Definition: Pragma.h:10
TParseContext::warning
void warning(const TSourceLoc &loc, const char *reason, const char *token, const char *extraInfo="")
Definition: ParseHelper.cpp:190
TParseContext::constructBuiltIn
TIntermTyped * constructBuiltIn(const TType *, TOperator, TIntermNode *, const TSourceLoc &, bool subset)
Definition: ParseHelper.cpp:1160
TMatrixFields::row
int row
Definition: ParseHelper.h:19
TParseContext::directiveHandler
TDirectiveHandler directiveHandler
Definition: ParseHelper.h:60
TParseContext::fragmentPrecisionHigh
bool fragmentPrecisionHigh
Definition: ParseHelper.h:57
TParseContext::addConstStruct
TIntermTyped * addConstStruct(TString &, TIntermTyped *, const TSourceLoc &)
Definition: ParseHelper.cpp:1364
TParseContext::executeInitializer
bool executeInitializer(const TSourceLoc &line, TString &identifier, TPublicType &pType, TIntermTyped *initializer, TIntermNode *&intermNode, TVariable *variable=0)
Definition: ParseHelper.cpp:946
TParseContext::globalErrorCheck
bool globalErrorCheck(const TSourceLoc &line, bool global, const char *token)
Definition: ParseHelper.cpp:413
TParseContext::binaryOpError
void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right)
Definition: ParseHelper.cpp:231
TIntermTyped
Definition: intermediate.h:245
TParseContext::sourcePath
const char * sourcePath
Definition: ParseHelper.h:50
TDiagnostics
Definition: Diagnostics.h:14
variable
GLenum GLenum variable
Definition: glew.h:12631
Preprocessor.h
localintermediate.h
TParseContext::pragma
const TPragma & pragma() const
Definition: ParseHelper.h:101
TType
Definition: Types.h:93
array
GLenum array
Definition: glew.h:8327
TIntermAggregate
Definition: intermediate.h:460
TParseContext::compileOptions
int compileOptions
Definition: ParseHelper.h:49
TParseContext::unaryOpError
void unaryOpError(const TSourceLoc &line, const char *op, TString operand)
Definition: ParseHelper.cpp:219
TParseContext::extensionErrorCheck
bool extensionErrorCheck(const TSourceLoc &line, const TString &)
Definition: ParseHelper.cpp:867
TVectorFields
Definition: localintermediate.h:14
PaParseStrings
int PaParseStrings(size_t count, const char *const string[], const int length[], TParseContext *context)
Definition: ParseHelper.cpp:1582
TParseContext::reservedErrorCheck
bool reservedErrorCheck(const TSourceLoc &line, const TString &identifier)
Definition: ParseHelper.cpp:432
TParseContext::findFunction
const TFunction * findFunction(const TSourceLoc &line, TFunction *pfnCall, bool *builtIn=0)
Definition: ParseHelper.cpp:919
TParseContext::currentFunctionType
const TType * currentFunctionType
Definition: ParseHelper.h:54
TParseContext::exitStructDeclaration
void exitStructDeclaration()
Definition: ParseHelper.cpp:1408
length
GLsizei GLsizei * length
Definition: gl2ext.h:792
TParseContext::assignError
void assignError(const TSourceLoc &line, const char *op, TString left, TString right)
Definition: ParseHelper.cpp:208
TParseContext::constErrorCheck
bool constErrorCheck(TIntermTyped *node)
Definition: ParseHelper.cpp:381
count
GLint GLsizei count
Definition: gl2ext.h:1011
TParseContext::addConstVectorNode
TIntermTyped * addConstVectorNode(TVectorFields &, TIntermTyped *, const TSourceLoc &)
Definition: ParseHelper.cpp:1249
TParseContext::functionReturnsValue
bool functionReturnsValue
Definition: ParseHelper.h:55
TMatrixFields::wholeRow
bool wholeRow
Definition: ParseHelper.h:17
TParseContext::samplerErrorCheck
bool samplerErrorCheck(const TSourceLoc &line, const TPublicType &pType, const char *reason)
Definition: ParseHelper.cpp:610
TParseContext::supportsExtension
bool supportsExtension(const char *extension)
Definition: ParseHelper.cpp:888
Diagnostics.h
TParseContext::infoSink
TInfoSink & infoSink()
Definition: ParseHelper.h:65
TParseContext::containsSampler
bool containsSampler(TType &type)
Definition: ParseHelper.cpp:655
TParseContext::HashErrMsg
TString HashErrMsg
Definition: ParseHelper.h:58
TParseContext::trace
void trace(const char *str)
Definition: ParseHelper.cpp:200
index
GLuint index
Definition: glew.h:1800
TParseContext::intermediate
TIntermediate & intermediate
Definition: ParseHelper.h:45
TParseContext::addIndexExpression
TIntermTyped * addIndexExpression(TIntermTyped *baseExpression, const TSourceLoc &location, TIntermTyped *indexExpression)
Definition: ParseHelper.cpp:1446
TBasicType
TBasicType
Definition: BaseTypes.h:36
TParseContext::boolErrorCheck
bool boolErrorCheck(const TSourceLoc &, const TIntermTyped *)
Definition: ParseHelper.cpp:586
TString
std::basic_string< char, std::char_traits< char >, TStringAllocator > TString
Definition: Common.h:41
TParseContext::numErrors
int numErrors() const
Definition: ParseHelper.h:64
TParseContext::diagnostics
TDiagnostics diagnostics
Definition: ParseHelper.h:59
TParseContext::structNestingLevel
int structNestingLevel
Definition: ParseHelper.h:53
TFunction
Definition: SymbolTable.h:129
TMatrixFields::col
int col
Definition: ParseHelper.h:20
TParseContext::areAllChildConst
bool areAllChildConst(TIntermAggregate *aggrNode)
Definition: ParseHelper.cpp:1028
TParseContext::treeRoot
TIntermNode * treeRoot
Definition: ParseHelper.h:51
TParseContext::parameterSamplerErrorCheck
bool parameterSamplerErrorCheck(const TSourceLoc &line, TQualifier qualifier, const TType &type)
Definition: ParseHelper.cpp:644
TParseContext::precisionErrorCheck
bool precisionErrorCheck(const TSourceLoc &line, TPrecision precision, TBasicType type)
Definition: ParseHelper.cpp:240
TParseContext::arrayErrorCheck
bool arrayErrorCheck(const TSourceLoc &line, TString &identifier, TPublicType type, TVariable *&variable)
Definition: ParseHelper.cpp:736
TSourceLoc
Definition: Common.h:17
TParseContext::arrayTypeErrorCheck
bool arrayTypeErrorCheck(const TSourceLoc &line, TPublicType type)
Definition: ParseHelper.cpp:715
TParseContext::extensionBehavior
const TExtensionBehavior & extensionBehavior() const
Definition: ParseHelper.h:102
TParseContext::addConstArrayNode
TIntermTyped * addConstArrayNode(int index, TIntermTyped *node, const TSourceLoc &line)
Definition: ParseHelper.cpp:1328
TPrecision
TPrecision
Definition: BaseTypes.h:13
ShHandle.h
TDiagnostics::numErrors
int numErrors() const
Definition: Diagnostics.h:22
ShShaderType
ShShaderType
Definition: ShaderLang.h:48
TIntermNode
Definition: intermediate.h:206
TVariable
Definition: SymbolTable.h:76
TParseContext::addConstMatrixNode
TIntermTyped * addConstMatrixNode(int, TIntermTyped *, const TSourceLoc &)
Definition: ParseHelper.cpp:1293
SymbolTable.h
TParseContext::integerErrorCheck
bool integerErrorCheck(TIntermTyped *node, const char *token)
Definition: ParseHelper.cpp:397
str
#define str(s)
ShShaderSpec
ShShaderSpec
Definition: ShaderLang.h:53
TParseContext::nonInitConstErrorCheck
bool nonInitConstErrorCheck(const TSourceLoc &line, TString &identifier, TPublicType &type, bool array)
Definition: ParseHelper.cpp:796
TParseContext::loopNestingLevel
int loopNestingLevel
Definition: ParseHelper.h:52
context
TParseContext * context
Definition: glslang_tab.cpp:1907
precision
GLenum GLint GLint * precision
Definition: glew.h:3391
TDiagnostics::infoSink
TInfoSink & infoSink()
Definition: Diagnostics.h:20
TParseContext::parseVectorFields
bool parseVectorFields(const TString &, int vecSize, TVectorFields &, const TSourceLoc &line)
Definition: ParseHelper.cpp:25
right
GLfloat right
Definition: glew.h:13816
TParseContext::constructStruct
TIntermTyped * constructStruct(TIntermNode *, TType *, int, const TSourceLoc &, bool subset)
Definition: ParseHelper.cpp:1222
TParseContext::enterStructDeclaration
bool enterStructDeclaration(const TSourceLoc &line, const TString &identifier)
Definition: ParseHelper.cpp:1393
TParseContext::paramErrorCheck
bool paramErrorCheck(const TSourceLoc &line, TQualifier qualifier, TQualifier paramQualifier, TType *type)
Definition: ParseHelper.cpp:848
TParseContext::TParseContext
TParseContext(TSymbolTable &symt, TExtensionBehavior &ext, TIntermediate &interm, ShShaderType type, ShShaderSpec spec, int options, bool checksPrecErrors, const char *sourcePath, TInfoSink &is)
Definition: ParseHelper.h:28
TDirectiveHandler::pragma
const TPragma & pragma() const
Definition: DirectiveHandler.h:23
TParseContext::arrayQualifierErrorCheck
bool arrayQualifierErrorCheck(const TSourceLoc &line, TPublicType type)
Definition: ParseHelper.cpp:700
TDirectiveHandler::extensionBehavior
const TExtensionBehavior & extensionBehavior() const
Definition: DirectiveHandler.h:24
TParseContext::isExtensionEnabled
bool isExtensionEnabled(const char *extension) const
Definition: ParseHelper.cpp:895
false
#define false
Definition: ftrandom.c:50
TParseContext::structQualifierErrorCheck
bool structQualifierErrorCheck(const TSourceLoc &line, const TPublicType &pType)
Definition: ParseHelper.cpp:629
TParseContext::constructorErrorCheck
bool constructorErrorCheck(const TSourceLoc &line, TIntermNode *, TFunction &, TOperator, TType *)
Definition: ParseHelper.cpp:470
TParseContext::structNestingErrorCheck
bool structNestingErrorCheck(const TSourceLoc &line, const TField &field)
Definition: ParseHelper.cpp:1419
TParseContext::nonInitErrorCheck
bool nonInitErrorCheck(const TSourceLoc &line, TString &identifier, TPublicType &type, TVariable *&variable)
Definition: ParseHelper.cpp:828
TInfoSink
Definition: InfoSink.h:108
TParseContext::recover
void recover()
Definition: ParseHelper.cpp:171
size
GLsizei size
Definition: gl2ext.h:1467
TParseContext::parseMatrixFields
bool parseMatrixFields(const TString &, int matSize, TMatrixFields &, const TSourceLoc &line)
Definition: ParseHelper.cpp:118