All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 //
9 #include "compiler/Diagnostics.h"
13 #include "compiler/ShHandle.h"
14 #include "compiler/SymbolTable.h"
16 struct TMatrixFields {
17  bool wholeRow;
18  bool wholeCol;
19  int row;
20  int col;
21 };
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),
40  checksPrecisionErrors(checksPrecErrors),
41  diagnostics(is),
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.
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.
62  void* scanner;
64  int numErrors() const { return diagnostics.numErrors(); }
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();
73  bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc& line);
74  bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, const TSourceLoc& line);
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);
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);
86  bool arraySizeErrorCheck(const TSourceLoc& line, TIntermTyped* expr, int& size);
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&);
101  const TPragma& pragma() const { return directiveHandler.pragma(); }
103  bool supportsExtension(const char* extension);
104  bool isExtensionEnabled(const char* extension) const;
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);
114  TIntermTyped* constructStruct(TIntermNode*, TType*, int, const TSourceLoc&, bool subset);
115  TIntermTyped* constructBuiltIn(const TType*, TOperator, TIntermNode*, const TSourceLoc&, bool subset);
118  TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, const TSourceLoc& line);
120  TIntermTyped* addIndexExpression(TIntermTyped *baseExpression, const TSourceLoc& location, TIntermTyped *indexExpression);
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();
128  bool structNestingErrorCheck(const TSourceLoc& line, const TField& field);
129 };
131 int PaParseStrings(size_t count, const char* const string[], const int length[],
Definition: intermediate.h:29
void error(const TSourceLoc &loc, const char *reason, const char *token, const char *extraInfo="")
bool lValueErrorCheck(const TSourceLoc &line, const char *op, TIntermTyped *)
TSymbolTable & symbolTable
Definition: ParseHelper.h:46
bool checksPrecisionErrors
Definition: ParseHelper.h:56
Definition: BaseTypes.h:81
pp::Preprocessor preprocessor
Definition: ParseHelper.h:61
TIntermTyped * foldConstConstructor(TIntermAggregate *aggrNode, const TType &type)
std::map< std::string, TBehavior > TExtensionBehavior
Definition: Types.h:19
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
ShShaderType shaderType
Definition: ParseHelper.h:47
bool voidErrorCheck(const TSourceLoc &, const TString &, const TPublicType &)
GLint left
Definition: glew.h:7291
ShShaderSpec shaderSpec
Definition: ParseHelper.h:48
#define NULL
Definition: ftobjs.h:61
bool arraySizeErrorCheck(const TSourceLoc &line, TIntermTyped *expr, int &size)
void * scanner
Definition: ParseHelper.h:62
GLint location
Definition: gl2ext.h:1164
TIntermTyped * addConstructor(TIntermNode *, const TType *, TOperator, TFunction *, const TSourceLoc &)
Definition: Pragma.h:10
void warning(const TSourceLoc &loc, const char *reason, const char *token, const char *extraInfo="")
TIntermTyped * constructBuiltIn(const TType *, TOperator, TIntermNode *, const TSourceLoc &, bool subset)
TDirectiveHandler directiveHandler
Definition: ParseHelper.h:60
bool fragmentPrecisionHigh
Definition: ParseHelper.h:57
TIntermTyped * addConstStruct(TString &, TIntermTyped *, const TSourceLoc &)
bool executeInitializer(const TSourceLoc &line, TString &identifier, TPublicType &pType, TIntermTyped *initializer, TIntermNode *&intermNode, TVariable *variable=0)
bool globalErrorCheck(const TSourceLoc &line, bool global, const char *token)
void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right)
const char * sourcePath
Definition: ParseHelper.h:50
GLenum GLenum variable
Definition: glew.h:12631
const TPragma & pragma() const
Definition: ParseHelper.h:101
Definition: Types.h:93
GLenum array
Definition: glew.h:8327
int compileOptions
Definition: ParseHelper.h:49
void unaryOpError(const TSourceLoc &line, const char *op, TString operand)
bool extensionErrorCheck(const TSourceLoc &line, const TString &)
int PaParseStrings(size_t count, const char *const string[], const int length[], TParseContext *context)
bool reservedErrorCheck(const TSourceLoc &line, const TString &identifier)
const TFunction * findFunction(const TSourceLoc &line, TFunction *pfnCall, bool *builtIn=0)
const TType * currentFunctionType
Definition: ParseHelper.h:54
void exitStructDeclaration()
GLsizei GLsizei * length
Definition: gl2ext.h:792
void assignError(const TSourceLoc &line, const char *op, TString left, TString right)
bool constErrorCheck(TIntermTyped *node)
GLint GLsizei count
Definition: gl2ext.h:1011
TIntermTyped * addConstVectorNode(TVectorFields &, TIntermTyped *, const TSourceLoc &)
bool functionReturnsValue
Definition: ParseHelper.h:55
bool samplerErrorCheck(const TSourceLoc &line, const TPublicType &pType, const char *reason)
bool supportsExtension(const char *extension)
TInfoSink & infoSink()
Definition: ParseHelper.h:65
bool containsSampler(TType &type)
TString HashErrMsg
Definition: ParseHelper.h:58
void trace(const char *str)
GLuint index
Definition: glew.h:1800
TIntermediate & intermediate
Definition: ParseHelper.h:45
TIntermTyped * addIndexExpression(TIntermTyped *baseExpression, const TSourceLoc &location, TIntermTyped *indexExpression)
Definition: BaseTypes.h:36
bool boolErrorCheck(const TSourceLoc &, const TIntermTyped *)
std::basic_string< char, std::char_traits< char >, TStringAllocator > TString
Definition: Common.h:41
int numErrors() const
Definition: ParseHelper.h:64
TDiagnostics diagnostics
Definition: ParseHelper.h:59
int structNestingLevel
Definition: ParseHelper.h:53
bool areAllChildConst(TIntermAggregate *aggrNode)
TIntermNode * treeRoot
Definition: ParseHelper.h:51
bool parameterSamplerErrorCheck(const TSourceLoc &line, TQualifier qualifier, const TType &type)
bool precisionErrorCheck(const TSourceLoc &line, TPrecision precision, TBasicType type)
bool arrayErrorCheck(const TSourceLoc &line, TString &identifier, TPublicType type, TVariable *&variable)
bool arrayTypeErrorCheck(const TSourceLoc &line, TPublicType type)
const TExtensionBehavior & extensionBehavior() const
Definition: ParseHelper.h:102
TIntermTyped * addConstArrayNode(int index, TIntermTyped *node, const TSourceLoc &line)
Definition: BaseTypes.h:13
int numErrors() const
Definition: Diagnostics.h:22
Definition: ShaderLang.h:48
TIntermTyped * addConstMatrixNode(int, TIntermTyped *, const TSourceLoc &)
bool integerErrorCheck(TIntermTyped *node, const char *token)
#define str(s)
Definition: ShaderLang.h:53
bool nonInitConstErrorCheck(const TSourceLoc &line, TString &identifier, TPublicType &type, bool array)
int loopNestingLevel
Definition: ParseHelper.h:52
TParseContext * context
GLenum GLint GLint * precision
Definition: glew.h:3391
TInfoSink & infoSink()
Definition: Diagnostics.h:20
bool parseVectorFields(const TString &, int vecSize, TVectorFields &, const TSourceLoc &line)
Definition: ParseHelper.cpp:25
GLfloat right
Definition: glew.h:13816
TIntermTyped * constructStruct(TIntermNode *, TType *, int, const TSourceLoc &, bool subset)
bool enterStructDeclaration(const TSourceLoc &line, const TString &identifier)
bool paramErrorCheck(const TSourceLoc &line, TQualifier qualifier, TQualifier paramQualifier, TType *type)
TParseContext(TSymbolTable &symt, TExtensionBehavior &ext, TIntermediate &interm, ShShaderType type, ShShaderSpec spec, int options, bool checksPrecErrors, const char *sourcePath, TInfoSink &is)
Definition: ParseHelper.h:28
const TPragma & pragma() const
bool arrayQualifierErrorCheck(const TSourceLoc &line, TPublicType type)
const TExtensionBehavior & extensionBehavior() const
bool isExtensionEnabled(const char *extension) const
#define false
Definition: ftrandom.c:50
bool structQualifierErrorCheck(const TSourceLoc &line, const TPublicType &pType)
bool constructorErrorCheck(const TSourceLoc &line, TIntermNode *, TFunction &, TOperator, TType *)
bool structNestingErrorCheck(const TSourceLoc &line, const TField &field)
bool nonInitErrorCheck(const TSourceLoc &line, TString &identifier, TPublicType &type, TVariable *&variable)
GLsizei size
Definition: gl2ext.h:1467
bool parseMatrixFields(const TString &, int matSize, TMatrixFields &, const TSourceLoc &line)