blob: a297f307c820f3770d5127857d32f28f9b41b8f4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/**
** \file ast/dumper-dot.hh
** \brief Declaration of ast::DumperDot.
*/
#pragma once
#include <ast/default-visitor.hh>
#include <misc/concepts.hh>
#include <misc/escape.hh>
namespace ast
{
/// \brief Dump an Ast into dot format.
class DumperDot : public ast::DefaultConstVisitor
{
public:
using super_type = ast::DefaultConstVisitor;
// Import overloaded virtual functions.
using super_type::operator();
/// Build a DumperDot.
DumperDot(std::ostream& ostr);
/// Destroy a DumperDot.
~DumperDot() override = default;
// Visit methods.
public:
void operator()(const ast::ArrayExp&) override;
void operator()(const ast::ArrayTy&) override;
void operator()(const ast::AssignExp&) override;
void operator()(const ast::BreakExp&) override;
void operator()(const ast::CallExp&) override;
void operator()(const ast::CastExp&) override;
void operator()(const ast::ChunkList&) override;
void operator()(const ast::ClassTy&) override;
void operator()(const ast::Field&) override;
void operator()(const ast::FieldInit&) override;
void operator()(const ast::FieldVar&) override;
void operator()(const ast::ForExp&) override;
void operator()(const ast::FunctionDec&) override;
void operator()(const ast::IfExp&) override;
void operator()(const ast::IntExp&) override;
void operator()(const ast::LetExp&) override;
void operator()(const ast::MethodCallExp&) override;
void operator()(const ast::MethodDec&) override;
void operator()(const ast::NameTy&) override;
void operator()(const ast::NilExp&) override;
void operator()(const ast::ObjectExp&) override;
void operator()(const ast::OpExp&) override;
void operator()(const ast::RecordExp&) override;
void operator()(const ast::RecordTy&) override;
void operator()(const ast::SeqExp&) override;
void operator()(const ast::SimpleVar&) override;
void operator()(const ast::StringExp&) override;
void operator()(const ast::SubscriptVar&) override;
void operator()(const ast::TypeDec&) override;
void operator()(const ast::VarDec&) override;
void operator()(const ast::WhileExp&) override;
void operator()(const ast::FunctionChunk&) override;
void operator()(const ast::MethodChunk&) override;
void operator()(const ast::TypeChunk&) override;
void operator()(const ast::VarChunk&) override;
void operator()(const ast::AssertExp&) override;
protected:
void dump(const std::string& field, const ast::Ast& t);
void dump(const std::string& field, const ast::Ast* t);
template <typename Container>
requires misc::ConstIterable<Container>
void dump_list(const std::string& field, const Container& l);
template <typename T> void dump_def(const T& e) const;
void dump_type(const ast::Typable& e);
template <typename E> void dump_chunk(const E& e, const std::string& name);
void display_link(unsigned long old_parent_id) const;
void footer_and_link(unsigned long old_parent_id) const;
template <typename T>
unsigned long node_html_header(const T& e, const std::string& type);
template <typename T>
void node_html_field(const std::string& name,
const T& content,
const std::string& sep = "");
void node_html_one_port(const std::string& p);
void node_html_ports(const std::vector<std::string>& ports = {});
template <typename T>
void node_html_port_list(const std::string& name,
const T& list,
bool chunk = false);
void node_html_footer() const;
protected:
/// The stream to print on.
std::ostream& ostr_;
/// The parent id
unsigned long parent_id = -1;
/// Number of fields
unsigned long inner_fields = 0;
/// The parent field
const std::string* parent_field = nullptr;
};
} // namespace ast
#include <ast/dumper-dot.hxx>
|