7#include <llvm/Support/raw_ostream.h>
20 static constexpr const char* AST_KEY =
"ym_ast_";
26 optional<Loc> location;
27 optional<string> type;
29 vector<DotConnection> children{};
31 DotNode(
int index, optional<Loc> location, optional<string> type,
string kind)
32 : index(index), location(move(location)), type(move(type)), content(move(kind)) {}
34 [[nodiscard]]
auto simple()
const ->
bool {
return !location.has_value(); }
36 void write(llvm::raw_ostream& stream)
const;
39 struct DotConnection {
40 optional<string> line_label;
43 DotConnection(optional<string> line_label, DotNode child) noexcept
44 : line_label(move(line_label)), child(move(child)) {}
47 llvm::raw_ostream& m_stream;
50 unique_ptr<DotNode> m_root{};
52 auto add_node(
const string& content,
const char* label) -> DotNode&;
53 auto add_node(DotNode&& node,
const char* label) -> DotNode&;
56 explicit DotVisitor(llvm::raw_ostream& stream) : m_stream{stream} {
57 m_stream <<
"digraph \"yume\" {\nnode [shape=box, style=rounded];\n";
69 auto visit(std::nullptr_t null, string_view label) ->
DotVisitor&
override;
70 auto visit(
const string& str, string_view label) ->
DotVisitor&
override;
All nodes in the AST tree of the program inherit from this class.
auto visit(const ast::AST &expr, string_view label) -> DotVisitor &override
DotVisitor(DotVisitor &&)=delete
DotVisitor(const DotVisitor &)=delete
auto operator=(DotVisitor &&) -> DotVisitor &=delete
auto operator=(const DotVisitor &) -> DotVisitor &=delete
DotVisitor(llvm::raw_ostream &stream)