CeresEngine
0.2.0
A game development framework
Loading...
Searching...
No Matches
Visitor.hpp
Go to the documentation of this file.
1
//
2
// CeresEngine - A game development framework
3
//
4
// Created by Rogiel Sulzbach.
5
// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6
//
7
8
#pragma once
9
10
#include "
CeresEngine/Foundation/SmartPtr.hpp
"
11
#include "
CeresEngine/Foundation/Container/Vector.hpp
"
12
13
#include <memory>
14
15
namespace
CeresEngine::ShaderCompiler
{
16
17
// Declare all AST node classes
18
19
#define DECLARATION_PTR(CLASS_NAME) \
20
struct CLASS_NAME; \
21
using CLASS_NAME##Ptr = SPtr<CLASS_NAME>
22
23
DECLARATION_PTR
(
AST
);
24
DECLARATION_PTR
(
TypedAST
);
25
DECLARATION_PTR
(
Statement
);
26
DECLARATION_PTR
(
Expression
);
27
DECLARATION_PTR
(
Declaration
);
28
29
DECLARATION_PTR
(
Program
);
30
DECLARATION_PTR
(
CodeBlock
);
31
DECLARATION_PTR
(
Attribute
);
32
DECLARATION_PTR
(
SwitchCase
);
33
DECLARATION_PTR
(
SamplerValue
);
34
DECLARATION_PTR
(
Register
);
35
DECLARATION_PTR
(
PackOffset
);
36
DECLARATION_PTR
(
ArrayDimension
);
37
DECLARATION_PTR
(
TypeSpecifier
);
38
39
DECLARATION_PTR
(
VarDeclaration
);
40
DECLARATION_PTR
(
BufferDeclaration
);
41
DECLARATION_PTR
(
SamplerDeclaration
);
42
DECLARATION_PTR
(
StructDeclaration
);
43
DECLARATION_PTR
(
AliasDeclaration
);
44
DECLARATION_PTR
(
FunctionDeclaration
);
45
DECLARATION_PTR
(
UniformBufferDeclaration
);
46
47
DECLARATION_PTR
(
BufferDeclarationStatement
);
48
DECLARATION_PTR
(
SamplerDeclarationStatement
);
49
DECLARATION_PTR
(
VarDeclarationStatement
);
50
DECLARATION_PTR
(
AliasDeclarationStatement
);
51
DECLARATION_PTR
(
BasicDeclarationStatement
);
52
53
DECLARATION_PTR
(
NullStatement
);
54
DECLARATION_PTR
(
CodeBlockStatement
);
55
DECLARATION_PTR
(
ForLoopStatement
);
56
DECLARATION_PTR
(
WhileLoopStatement
);
57
DECLARATION_PTR
(
DoWhileLoopStatement
);
58
DECLARATION_PTR
(
IfStatement
);
59
DECLARATION_PTR
(
ElseStatement
);
60
DECLARATION_PTR
(
SwitchStatement
);
61
DECLARATION_PTR
(
ExpressionStatement
);
62
DECLARATION_PTR
(
ReturnStatement
);
63
DECLARATION_PTR
(
CtrlTransferStatement
);
64
DECLARATION_PTR
(
LayoutStatement
);
65
66
DECLARATION_PTR
(
NullExpression
);
67
DECLARATION_PTR
(
SequenceExpression
);
68
DECLARATION_PTR
(
LiteralExpression
);
69
DECLARATION_PTR
(
TypeSpecifierExpression
);
70
DECLARATION_PTR
(
TernaryExpression
);
71
DECLARATION_PTR
(
BinaryExpression
);
72
DECLARATION_PTR
(
UnaryExpression
);
73
DECLARATION_PTR
(
PostUnaryExpression
);
74
DECLARATION_PTR
(
CallExpression
);
75
DECLARATION_PTR
(
BracketExpression
);
76
DECLARATION_PTR
(
ObjectExpression
);
77
DECLARATION_PTR
(
AssignExpression
);
78
DECLARATION_PTR
(
ArrayExpression
);
79
DECLARATION_PTR
(
CastExpression
);
80
DECLARATION_PTR
(
InitializerExpression
);
81
82
#undef DECLARATION_PTR
83
84
// Visitor interface
85
86
#define VISITOR_VISIT_PROC(CLASS_NAME) virtual void visit##CLASS_NAME(CLASS_NAME* ast, void* args)
87
88
#define DECLARATION_VISIT_PROC(CLASS_NAME) void visit##CLASS_NAME(CLASS_NAME* ast, void* args) override
89
90
#define VISIT_DEFAULT(CLASS_NAME) Visitor::visit##CLASS_NAME(ast, args)
91
92
class
Visitor
{
93
public
:
94
virtual
~Visitor
() =
default
;
95
96
VISITOR_VISIT_PROC
(
Program
);
97
VISITOR_VISIT_PROC
(
CodeBlock
);
98
VISITOR_VISIT_PROC
(
Attribute
);
99
VISITOR_VISIT_PROC
(
SwitchCase
);
100
VISITOR_VISIT_PROC
(
SamplerValue
);
101
VISITOR_VISIT_PROC
(
Register
);
102
VISITOR_VISIT_PROC
(
PackOffset
);
103
VISITOR_VISIT_PROC
(
ArrayDimension
);
104
VISITOR_VISIT_PROC
(
TypeSpecifier
);
105
106
VISITOR_VISIT_PROC
(
VarDeclaration
);
107
VISITOR_VISIT_PROC
(
BufferDeclaration
);
108
VISITOR_VISIT_PROC
(
SamplerDeclaration
);
109
VISITOR_VISIT_PROC
(
StructDeclaration
);
110
VISITOR_VISIT_PROC
(
AliasDeclaration
);
111
VISITOR_VISIT_PROC
(
FunctionDeclaration
);
112
VISITOR_VISIT_PROC
(
UniformBufferDeclaration
);
113
114
VISITOR_VISIT_PROC
(
BufferDeclarationStatement
);
115
VISITOR_VISIT_PROC
(
SamplerDeclarationStatement
);
116
VISITOR_VISIT_PROC
(
VarDeclarationStatement
);
117
VISITOR_VISIT_PROC
(
AliasDeclarationStatement
);
118
VISITOR_VISIT_PROC
(
BasicDeclarationStatement
);
119
120
VISITOR_VISIT_PROC
(
NullStatement
);
121
VISITOR_VISIT_PROC
(
CodeBlockStatement
);
122
VISITOR_VISIT_PROC
(
ForLoopStatement
);
123
VISITOR_VISIT_PROC
(
WhileLoopStatement
);
124
VISITOR_VISIT_PROC
(
DoWhileLoopStatement
);
125
VISITOR_VISIT_PROC
(
IfStatement
);
126
VISITOR_VISIT_PROC
(
ElseStatement
);
127
VISITOR_VISIT_PROC
(
SwitchStatement
);
128
VISITOR_VISIT_PROC
(
ExpressionStatement
);
129
VISITOR_VISIT_PROC
(
ReturnStatement
);
130
VISITOR_VISIT_PROC
(
CtrlTransferStatement
);
131
VISITOR_VISIT_PROC
(
LayoutStatement
);
132
133
VISITOR_VISIT_PROC
(
NullExpression
);
134
VISITOR_VISIT_PROC
(
SequenceExpression
);
135
VISITOR_VISIT_PROC
(
LiteralExpression
);
136
VISITOR_VISIT_PROC
(
TypeSpecifierExpression
);
137
VISITOR_VISIT_PROC
(
TernaryExpression
);
138
VISITOR_VISIT_PROC
(
BinaryExpression
);
139
VISITOR_VISIT_PROC
(
UnaryExpression
);
140
VISITOR_VISIT_PROC
(
PostUnaryExpression
);
141
VISITOR_VISIT_PROC
(
CallExpression
);
142
VISITOR_VISIT_PROC
(
BracketExpression
);
143
VISITOR_VISIT_PROC
(
AssignExpression
);
144
VISITOR_VISIT_PROC
(
ObjectExpression
);
145
VISITOR_VISIT_PROC
(
ArrayExpression
);
146
VISITOR_VISIT_PROC
(
CastExpression
);
147
VISITOR_VISIT_PROC
(
InitializerExpression
);
148
149
protected
:
150
template
<
typename
T>
void
visit
(
const
T
&
ast
,
void
* args =
nullptr
) {
151
if
(
ast
) {
152
ast
->visit(
this
, args);
153
}
154
}
155
156
template
<
typename
T>
void
visit
(
const
Vector<T>
&
astList
,
void
* args =
nullptr
) {
157
for
(
const
auto
&
ast
:
astList
) {
158
visit
(
ast
, args);
159
}
160
}
161
};
162
163
#undef VISITOR_VISIT_PROC
164
165
}
// namespace CeresEngine::ShaderCompiler
Vector.hpp
SmartPtr.hpp
DECLARATION_PTR
#define DECLARATION_PTR(CLASS_NAME)
Definition
TypeDenoter.hpp:25
VISITOR_VISIT_PROC
#define VISITOR_VISIT_PROC(CLASS_NAME)
Definition
Visitor.hpp:86
CeresEngine::ShaderCompiler::Visitor
Definition
Visitor.hpp:92
CeresEngine::ShaderCompiler::Visitor::~Visitor
virtual ~Visitor()=default
CeresEngine::ShaderCompiler::Visitor::visit
void visit(const Vector< T > &astList, void *args=nullptr)
Definition
Visitor.hpp:156
CeresEngine::ShaderCompiler::Visitor::visit
void visit(const T &ast, void *args=nullptr)
Definition
Visitor.hpp:150
CeresEngine::ShaderCompiler
Definition
AST.hpp:33
CeresEngine::Button::T
@ T
CeresEngine::Vector
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition
Vector.hpp:17
CeresEngine::hash
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition
Hash.hpp:25
CeresEngine::ShaderCompiler::AST
Definition
AST.hpp:77
CeresEngine::ShaderCompiler::AliasDeclaration
Definition
AST.hpp:735
CeresEngine::ShaderCompiler::AliasDeclarationStatement
Definition
AST.hpp:958
CeresEngine::ShaderCompiler::ArrayDimension
Definition
AST.hpp:453
CeresEngine::ShaderCompiler::ArrayExpression
Definition
AST.hpp:1302
CeresEngine::ShaderCompiler::AssignExpression
Definition
AST.hpp:1244
CeresEngine::ShaderCompiler::Attribute
Definition
AST.hpp:404
CeresEngine::ShaderCompiler::BasicDeclarationStatement
Definition
AST.hpp:886
CeresEngine::ShaderCompiler::BinaryExpression
Definition
AST.hpp:1135
CeresEngine::ShaderCompiler::BracketExpression
Definition
AST.hpp:1232
CeresEngine::ShaderCompiler::BufferDeclaration
Definition
AST.hpp:595
CeresEngine::ShaderCompiler::BufferDeclarationStatement
Definition
AST.hpp:864
CeresEngine::ShaderCompiler::CallExpression
Definition
AST.hpp:1170
CeresEngine::ShaderCompiler::CastExpression
Definition
AST.hpp:1319
CeresEngine::ShaderCompiler::CodeBlock
Definition
AST.hpp:388
CeresEngine::ShaderCompiler::CodeBlockStatement
Definition
AST.hpp:973
CeresEngine::ShaderCompiler::CtrlTransferStatement
Definition
AST.hpp:1049
CeresEngine::ShaderCompiler::Declaration
Definition
AST.hpp:281
CeresEngine::ShaderCompiler::DoWhileLoopStatement
Definition
AST.hpp:998
CeresEngine::ShaderCompiler::ElseStatement
Definition
AST.hpp:1015
CeresEngine::ShaderCompiler::Expression
Definition
AST.hpp:241
CeresEngine::ShaderCompiler::ExpressionStatement
Definition
AST.hpp:1030
CeresEngine::ShaderCompiler::ForLoopStatement
Definition
AST.hpp:980
CeresEngine::ShaderCompiler::FunctionDeclaration
Definition
AST.hpp:745
CeresEngine::ShaderCompiler::IfStatement
Definition
AST.hpp:1006
CeresEngine::ShaderCompiler::InitializerExpression
Definition
AST.hpp:1331
CeresEngine::ShaderCompiler::LayoutStatement
Definition
AST.hpp:1055
CeresEngine::ShaderCompiler::LiteralExpression
Definition
AST.hpp:1086
CeresEngine::ShaderCompiler::NullExpression
Definition
AST.hpp:1065
CeresEngine::ShaderCompiler::NullStatement
Definition
AST.hpp:968
CeresEngine::ShaderCompiler::ObjectExpression
Definition
AST.hpp:1257
CeresEngine::ShaderCompiler::PackOffset
Definition
AST.hpp:442
CeresEngine::ShaderCompiler::PostUnaryExpression
Definition
AST.hpp:1159
CeresEngine::ShaderCompiler::Program
Definition
AST.hpp:303
CeresEngine::ShaderCompiler::Register
Definition
AST.hpp:427
CeresEngine::ShaderCompiler::ReturnStatement
Definition
AST.hpp:1037
CeresEngine::ShaderCompiler::SamplerDeclaration
Definition
AST.hpp:618
CeresEngine::ShaderCompiler::SamplerDeclarationStatement
Definition
AST.hpp:875
CeresEngine::ShaderCompiler::SamplerValue
Definition
AST.hpp:396
CeresEngine::ShaderCompiler::SequenceExpression
Definition
AST.hpp:1072
CeresEngine::ShaderCompiler::Statement
Definition
AST.hpp:215
CeresEngine::ShaderCompiler::StructDeclaration
Definition
AST.hpp:635
CeresEngine::ShaderCompiler::SwitchCase
Definition
AST.hpp:416
CeresEngine::ShaderCompiler::SwitchStatement
Definition
AST.hpp:1022
CeresEngine::ShaderCompiler::TernaryExpression
Definition
AST.hpp:1120
CeresEngine::ShaderCompiler::TypeSpecifierExpression
Definition
AST.hpp:1111
CeresEngine::ShaderCompiler::TypeSpecifier
Definition
AST.hpp:476
CeresEngine::ShaderCompiler::TypedAST
Definition
AST.hpp:224
CeresEngine::ShaderCompiler::UnaryExpression
Definition
AST.hpp:1147
CeresEngine::ShaderCompiler::UniformBufferDeclaration
Definition
AST.hpp:840
CeresEngine::ShaderCompiler::VarDeclaration
Definition
AST.hpp:521
CeresEngine::ShaderCompiler::VarDeclarationStatement
Definition
AST.hpp:893
CeresEngine::ShaderCompiler::WhileLoopStatement
Definition
AST.hpp:990
Sources
CeresEngine
Material
ShaderCompiler
AST
Visitor
Visitor.hpp
Generated by
1.9.8