tipc
A TIP to LLVM compiler
ASTVisualizer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ASTVisitor.h"
4 #include <SyntaxTree.h>
5 #include <iostream>
6 #include <map>
7 #include <ostream>
8 #include <stack>
9 #include <string>
10 
25 public:
26  ASTVisualizer() : os(std::cout) {}
27  ASTVisualizer(std::ostream &os) : os(os) {}
28 
33  void buildGraph(SyntaxTree &tree);
34 
35 private:
36  std::ostream &os;
37  std::stack<ASTNode *> parent;
38  std::map<ASTNode *, std::string> vertexMap;
39 
40  void connect_node_to_parent(ASTNode *element);
41  void declare_node(ASTNode *element, std::string label = "");
42  void pushn(ASTNode *element, int n);
43  void process_node(ASTNode *element);
44 };
Abstract base class for all AST nodes.
Definition: ASTNode.h:34
Constructs a dot graph that can be used to visualize the AST.
Definition: ASTVisualizer.h:24
ASTVisualizer(std::ostream &os)
Definition: ASTVisualizer.h:27
void buildGraph(SyntaxTree &tree)
Construct a dot syntax compliant graph of the AST.
Definition: ASTVisualizer.cpp:7
ASTVisualizer()
Definition: ASTVisualizer.h:26
A convenient interface to the AST nodes.
Definition: SyntaxTree.h:16