summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/type/pretty-printer.hh
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/src/type/pretty-printer.hh
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/src/type/pretty-printer.hh')
-rw-r--r--tiger-compiler/src/type/pretty-printer.hh67
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