Joos1W Compiler Framework
All Classes Functions Typedefs Pages
Decl.cc
1 #include <ostream>
2 #include <string>
3 
4 #include "ast/AST.h"
5 
6 namespace ast {
7 
8 using std::ostream;
9 using std::string;
10 
11 void AstNode::dump() const {
12  print(std::cerr, 0);
13  std::cerr << std::endl;
14 }
15 
16 // VarDecl /////////////////////////////////////////////////////////////////////
17 
18 ostream& VarDecl::print(ostream& os, int indentation) const {
19  auto i1 = indent(indentation);
20  os << i1 << "VarDecl {\n"
21  << i1 << " type: " << type()->toString() << "\n"
22  << i1 << " name: " << name() << "\n";
23  if(init()) {
24  init()->print(os, indentation + 1);
25  }
26  os << i1 << "}\n";
27  return os;
28 }
29 
30 int VarDecl::printDotNode(DotPrinter& dp) const {
31  int id = dp.id(this);
32  dp.startTLabel(id);
33  dp.printTableSingleRow("VarDecl", {"bgcolor", "lightblue"});
34  dp.printTableDoubleRow("type", type()->toString());
36  std::ostringstream expr;
37  if(init()) init()->print(expr, -1);
39  "init", expr.str(), {"port", "init"}, {"balign", "left"});
40  dp.endTLabel();
41  return id;
42 }
43 
44 // FieldDecl ///////////////////////////////////////////////////////////////////
45 
46 ostream& FieldDecl::print(ostream& os, int indentation) const {
47  auto i1 = indent(indentation);
48  os << i1 << "FieldDecl {\n"
49  << i1 << " modifiers: " << modifiers().toString() << "\n"
50  << i1 << " type: " << type()->toString() << "\n"
51  << i1 << " name: " << name() << "\n";
52  if(hasInit()) {
53  init()->print(os, indentation + 1);
54  }
55  os << i1 << "}\n";
56  return os;
57 }
58 
59 int FieldDecl::printDotNode(DotPrinter& dp) const {
60  int id = dp.id(this);
61  dp.startTLabel(id);
62  dp.printTableSingleRow("FieldDecl", {"bgcolor", "lightblue"});
63  dp.printTableDoubleRow("modifiers", modifiers().toString());
64  dp.printTableDoubleRow("type", type()->toString());
66  std::ostringstream expr;
67  if(hasInit()) init()->print(expr, -1);
69  "init", expr.str(), {"port", "init"}, {"balign", "left"});
70  dp.endTLabel();
71  return id;
72 }
73 
74 } // namespace ast