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
12
13#include <memory>
14
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
28
38
46
52
65
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
105
113
119
132
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
#define DECLARATION_PTR(CLASS_NAME)
Definition TypeDenoter.hpp:25
#define VISITOR_VISIT_PROC(CLASS_NAME)
Definition Visitor.hpp:86
Definition Visitor.hpp:92
void visit(const Vector< T > &astList, void *args=nullptr)
Definition Visitor.hpp:156
void visit(const T &ast, void *args=nullptr)
Definition Visitor.hpp:150
Definition AST.hpp:33
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition AST.hpp:1159