summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/type/pretty-printer.hh
blob: 786cfcfed6da1539571795b44b3c73123b6c5445 (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
/**
 ** \file type/pretty-printer.hh
 ** \brief Print the type hierarchy.
 */

#pragma once

#include <ostream>

#include <type/default-visitor.hh>
#include <type/fwd.hh>

namespace type
{
  class PrettyPrinter : public DefaultConstVisitor
  {
  public:
    /// Super class type.
    using super_type = DefaultConstVisitor;

    // Import overloaded \c operator() methods.
    using super_type::operator();

    /** \name Ctor & dtor.
     ** \{ */
    /// Construct a pretty printer.
    explicit PrettyPrinter(std::ostream& ostr);
    /** \} */

    /** \name Visit basic types.
     ** \{ */
    void operator()(const Nil& e) override;
    void operator()(const Void& e) override;
    void operator()(const Int& e) override;
    void operator()(const String& e) override;
    /** \} */

    /** \name Visit composed types.
     ** \{ */
    void operator()(const Named& e) override;
    void operator()(const Array& e) override;
    void operator()(const Record& e) override;
    void operator()(const Class& e) override;
    void operator()(const Function& e) override;
    /** \} */

    /** \name Visit Non type types.
     ** \{ */
    void operator()(const Attribute& e);
    void operator()(const Field& e);
    /** \} */

  private:
    /// The stream to print on.
    std::ostream& ostr_;
  };

  /// Overload redirection operator for Type.
  std::ostream& operator<<(std::ostream& ostr, const Type& t);

  /// Overload redirection operator for Attribute.
  std::ostream& operator<<(std::ostream& ostr, const Attribute& obj);

  /// Overload redirection operator for Field.
  std::ostream& operator<<(std::ostream& ostr, const Field& obj);

} // namespace type