summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/ast/libast.cc
blob: 0bebaa00fafa8c930f97ac940d74a9eea78b795f (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
/**
 ** \file ast/libast.cc
 ** \brief Public ast interface implementation.
 */

#include <fstream>

#include <ast/dumper-dot.hh>
#include <ast/libast.hh>
#include <ast/pretty-printer.hh>

// Define exported ast functions.
namespace ast
{
  // Making the following variables const is more than merely
  // stylistic.  If they were not, Swig will create set/get for them,
  // and there is no set (operator=), since it has a const member.

  /// xalloc slot to enable escapes display in Ast display.
  const misc::xalloc<bool> escapes_display;
  /// xalloc slot to enable bindings display in Ast display.
  const misc::xalloc<bool> bindings_display;

  // Print the TREE on OSTR.
  std::ostream& operator<<(std::ostream& ostr, const Ast& tree)
  {
    PrettyPrinter print(ostr);
    print(tree);
    return ostr;
  }

  /// Dump \a a on \a ostr.
  std::ostream& dump_dot(const Ast& tree, std::ostream& ostr)
  {
    DumperDot dump_dot(ostr);
    ostr << misc::resetindent << "digraph structs {" << misc::incendl;
    ostr << "splines=line;" << misc::iendl;
    ostr << "node [shape=plaintext]" << misc::iendl;
    dump_dot(tree);
    ostr << misc::decendl << "}" << misc::iendl;
    return ostr;
  }

} // namespace ast