RetroArch
hlslGrammar.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2016 Google, Inc.
3 // Copyright (C) 2016 LunarG, Inc.
4 //
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
11 // Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //
14 // Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following
16 // disclaimer in the documentation and/or other materials provided
17 // with the distribution.
18 //
19 // Neither the name of Google, Inc., nor the names of its
20 // contributors may be used to endorse or promote products derived
21 // from this software without specific prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 // POSSIBILITY OF SUCH DAMAGE.
35 //
36 
37 #ifndef HLSLGRAMMAR_H_
38 #define HLSLGRAMMAR_H_
39 
40 #include "hlslParseHelper.h"
41 #include "hlslOpMap.h"
42 #include "hlslTokenStream.h"
43 
44 namespace glslang {
45 
46  class TFunctionDeclarator;
47 
48  // Should just be the grammar aspect of HLSL.
49  // Described in more detail in hlslGrammar.cpp.
50 
51  class HlslGrammar : public HlslTokenStream {
52  public:
56  virtual ~HlslGrammar() { }
57 
58  bool parse();
59 
60  protected:
61  HlslGrammar();
63 
64  void expected(const char*);
65  void unimplemented(const char*);
67  bool acceptCompilationUnit();
72  bool acceptSamplerState();
74  bool acceptFullySpecifiedType(TType&, TIntermNode*& nodeList, const TAttributes&, bool forbidDeclarators = false);
77  bool acceptType(TType&);
78  bool acceptType(TType&, TIntermNode*& nodeList);
87  bool acceptSamplerType(TType&);
88  bool acceptTextureType(TType&);
93  bool acceptStruct(TType&, TIntermNode*& nodeList);
95  bool acceptMemberFunctionDefinition(TIntermNode*& nodeList, const TType&, TString& memberName,
100  bool acceptFunctionBody(TFunctionDeclarator& declarator, TIntermNode*& nodeList);
110  bool acceptFunctionCall(const TSourceLoc&, TString& name, TIntermTyped*&, TIntermTyped* objectBase);
112  bool acceptLiteral(TIntermTyped*&);
129 
131  const char* getTypeString(EHlslTokenClass tokenClass) const;
132 
133  HlslParseContext& _parseContext; // state of parsing and helper functions for building the intermediate
134  TIntermediate& intermediate; // the final product, the intermediate representation, includes the AST
135  bool typeIdentifiers; // shader uses some types as identifiers
136  };
137 
138 } // end namespace glslang
139 
140 #endif // HLSLGRAMMAR_H_
bool acceptAnnotations(TQualifier &)
Definition: hlslGrammar.cpp:1073
void expected(const char *)
Definition: hlslGrammar.cpp:68
GLuint const GLchar * name
Definition: glext.h:6671
bool acceptControlDeclaration(TIntermNode *&node)
Definition: hlslGrammar.cpp:536
bool acceptIterationStatement(TIntermNode *&, const TAttributes &)
Definition: hlslGrammar.cpp:3655
bool acceptLiteral(TIntermTyped *&)
Definition: hlslGrammar.cpp:3268
TIntermediate & intermediate
Definition: hlslGrammar.h:134
HlslGrammar(HlslScanContext &scanner, HlslParseContext &_parseContext)
Definition: hlslGrammar.h:53
bool acceptSamplerState()
Definition: hlslGrammar.cpp:190
Definition: Common.h:231
virtual ~HlslGrammar()
Definition: hlslGrammar.h:56
bool acceptSubpassInputType(TType &)
Definition: hlslGrammar.cpp:1107
bool acceptFunctionParameters(TFunction &)
Definition: hlslGrammar.cpp:2467
bool acceptScopedStatement(TIntermNode *&)
Definition: hlslGrammar.cpp:3367
Definition: localintermediate.h:210
bool acceptMemberFunctionDefinition(TIntermNode *&nodeList, const TType &, TString &memberName, TFunctionDeclarator &)
Definition: hlslGrammar.cpp:2433
const char * getTypeString(EHlslTokenClass tokenClass) const
Definition: hlslGrammar.cpp:4083
bool acceptCaseLabel(TIntermNode *&)
Definition: hlslGrammar.cpp:3854
TBuiltInVariable
Definition: BaseTypes.h:135
Definition: SymbolTable.h:216
bool acceptTextureBufferType(TType &)
Definition: hlslGrammar.cpp:2182
bool acceptCompilationUnit()
Definition: hlslGrammar.cpp:127
bool acceptStatement(TIntermNode *&)
Definition: hlslGrammar.cpp:3398
Definition: hlslParseHelper.h:49
bool acceptType(TType &)
Definition: hlslGrammar.cpp:1364
Definition: hlslGrammar.h:51
Definition: intermediate.h:988
bool acceptFunctionCall(const TSourceLoc &, TString &name, TIntermTyped *&, TIntermTyped *objectBase)
Definition: hlslGrammar.cpp:3188
bool acceptFullySpecifiedType(TType &, const TAttributes &)
Definition: hlslGrammar.cpp:584
bool acceptScopedCompoundStatement(TIntermNode *&)
Definition: hlslGrammar.cpp:3376
bool acceptConstantBufferType(TType &)
Definition: hlslGrammar.cpp:2141
bool acceptDefaultLabel(TIntermNode *&)
Definition: hlslGrammar.cpp:3879
bool acceptFunctionDefinition(TFunctionDeclarator &, TIntermNode *&nodeList, TVector< HlslToken > *deferredTokens)
Definition: hlslGrammar.cpp:2607
bool typeIdentifiers
Definition: hlslGrammar.h:135
bool acceptPostDecls(TQualifier &)
Definition: hlslGrammar.cpp:3944
bool acceptSamplerDeclarationDX9(TType &)
Definition: hlslGrammar.cpp:274
Definition: Types.h:1169
bool captureBlockTokens(TVector< HlslToken > &tokens)
Definition: hlslGrammar.cpp:4053
bool acceptTessellationDeclType(TBuiltInVariable &)
Definition: hlslGrammar.cpp:981
Definition: Types.h:418
bool acceptDeclaration(TIntermNode *&)
Definition: hlslGrammar.cpp:331
void acceptArraySpecifier(TArraySizes *&)
Definition: hlslGrammar.cpp:3899
bool parse()
Definition: hlslGrammar.cpp:62
bool acceptDefaultParameterDeclaration(const TType &, TIntermTyped *&)
Definition: hlslGrammar.cpp:2498
bool acceptSamplerType(TType &)
Definition: hlslGrammar.cpp:1173
bool acceptTextureType(TType &)
Definition: hlslGrammar.cpp:1225
TLayoutGeometry
Definition: Types.h:293
bool acceptTemplateVecMatBasicType(TBasicType &)
Definition: hlslGrammar.cpp:810
bool acceptStreamOutTemplateType(TType &, TLayoutGeometry &)
Definition: hlslGrammar.cpp:1044
HlslParseContext & _parseContext
Definition: hlslGrammar.h:133
PrecedenceLevel
Definition: hlslOpMap.h:43
bool acceptVectorTemplateType(TType &)
Definition: hlslGrammar.cpp:842
bool acceptSwitchStatement(TIntermNode *&, const TAttributes &)
Definition: hlslGrammar.cpp:3616
bool acceptNestedStatement(TIntermNode *&)
bool acceptCompoundStatement(TIntermNode *&)
Definition: hlslGrammar.cpp:3336
bool acceptParenExpression(TIntermTyped *&)
Definition: hlslGrammar.cpp:2651
Definition: arrays.h:222
bool acceptIdentifier(HlslToken &)
Definition: hlslGrammar.cpp:84
bool acceptAssignmentExpression(TIntermTyped *&)
Definition: hlslGrammar.cpp:2787
bool acceptExpression(TIntermTyped *&)
Definition: hlslGrammar.cpp:2688
Definition: arrays.h:46
void acceptAttributes(TAttributes &)
Definition: hlslGrammar.cpp:3475
bool acceptSimpleStatement(TIntermNode *&)
Definition: hlslGrammar.cpp:3307
bool acceptConstructor(TIntermTyped *&)
Definition: hlslGrammar.cpp:3156
bool acceptQualifier(TQualifier &)
Definition: hlslGrammar.cpp:649
Definition: hlslTokenStream.h:43
bool acceptSelectionStatement(TIntermNode *&, const TAttributes &)
Definition: hlslGrammar.cpp:3563
bool acceptBinaryExpression(TIntermTyped *&, PrecedenceLevel)
Definition: hlslGrammar.cpp:2892
Definition: hlslScanContext.h:56
bool acceptArguments(TFunction *, TIntermTyped *&)
Definition: hlslGrammar.cpp:3234
bool acceptInitializer(TIntermTyped *&)
Definition: hlslGrammar.cpp:2725
EHlslTokenClass
Definition: hlslTokens.h:42
HlslScanContext & scanner
Definition: hlslTokenStream.h:67
bool acceptDeclarationList(TIntermNode *&)
Definition: hlslGrammar.cpp:155
bool acceptJumpStatement(TIntermNode *&)
Definition: hlslGrammar.cpp:3793
bool acceptTessellationPatchTemplateType(TType &)
Definition: hlslGrammar.cpp:1000
TBasicType
Definition: BaseTypes.h:46
Definition: hlslScanContext.h:74
HlslGrammar & operator=(const HlslGrammar &)
void unimplemented(const char *)
Definition: hlslGrammar.cpp:73
bool acceptStructDeclarationList(TTypeList *&, TIntermNode *&nodeList, TVector< TFunctionDeclarator > &)
Definition: hlslGrammar.cpp:2329
bool acceptStructBufferType(TType &)
Definition: hlslGrammar.cpp:2224
bool acceptOutputPrimitiveGeometry(TLayoutGeometry &)
Definition: hlslGrammar.cpp:960
#define false
Definition: ordinals.h:83
bool acceptUnaryExpression(TIntermTyped *&)
Definition: hlslGrammar.cpp:2936
Definition: Common.h:175
Definition: intermediate.h:1042
bool acceptLayoutQualifierList(TQualifier &)
Definition: hlslGrammar.cpp:762
bool acceptConditionalExpression(TIntermTyped *&)
Definition: hlslGrammar.cpp:2842
Definition: hlslAttributes.h:48
bool acceptFunctionBody(TFunctionDeclarator &declarator, TIntermNode *&nodeList)
Definition: hlslGrammar.cpp:2618
bool acceptMatrixTemplateType(TType &)
Definition: hlslGrammar.cpp:894
bool acceptStruct(TType &, TIntermNode *&nodeList)
Definition: hlslGrammar.cpp:2027
Definition: lobject.h:303
bool acceptPostfixExpression(TIntermTyped *&)
Definition: hlslGrammar.cpp:3025
bool acceptParameterDeclaration(TFunction &)
Definition: hlslGrammar.cpp:2550