diff options
Diffstat (limited to 'tiger-compiler/src/type/pretty-printer.hh')
| -rw-r--r-- | tiger-compiler/src/type/pretty-printer.hh | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tiger-compiler/src/type/pretty-printer.hh b/tiger-compiler/src/type/pretty-printer.hh new file mode 100644 index 0000000..786cfcf --- /dev/null +++ b/tiger-compiler/src/type/pretty-printer.hh @@ -0,0 +1,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 |
