summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/ast/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/ast/pretty-printer.hh
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/src/ast/pretty-printer.hh')
-rw-r--r--tiger-compiler/src/ast/pretty-printer.hh96
1 files changed, 96 insertions, 0 deletions
diff --git a/tiger-compiler/src/ast/pretty-printer.hh b/tiger-compiler/src/ast/pretty-printer.hh
new file mode 100644
index 0000000..7532331
--- /dev/null
+++ b/tiger-compiler/src/ast/pretty-printer.hh
@@ -0,0 +1,96 @@
+/**
+ ** \file ast/pretty-printer.hh
+ ** \brief Declaration of ast::PrettyPrinter.
+ */
+
+#pragma once
+
+#include <ast/assert-visitor.hh>
+#include <ast/default-visitor.hh>
+#include <ast/object-visitor.hh>
+
+namespace ast
+{
+ /// Visit an Ast and print the content of each node.
+ class PrettyPrinter
+ : virtual public DefaultConstVisitor
+ , virtual public ObjectConstVisitor
+ , virtual public AssertConstVisitor
+ {
+ public:
+ using super_type = DefaultConstVisitor;
+ // Import overloaded virtual functions.
+ using super_type::operator();
+
+ /// Build to print on \a ostr.
+ PrettyPrinter(std::ostream& ostr);
+
+ /// Visit methods.
+ /// \{
+ void operator()(const SimpleVar& e) override;
+ void operator()(const FieldVar& e) override;
+ void operator()(const SubscriptVar& e) override;
+ void operator()(const CastExp& e) override;
+ // FIXME DONE: Some code was deleted here.
+ void operator()(const NilExp& e) override;
+ void operator()(const IntExp& e) override;
+ void operator()(const StringExp& e) override;
+ void operator()(const ObjectExp& e) override;
+ void operator()(const CallExp& e) override;
+ void operator()(const MethodCallExp& e) override;
+ void operator()(const OpExp& e) override;
+ void operator()(const RecordExp& e) override;
+ void operator()(const SeqExp& e) override;
+ void operator()(const AssignExp& e) override;
+ void operator()(const IfExp& e) override;
+ void operator()(const WhileExp& e) override;
+ void operator()(const ForExp& e) override;
+ void operator()(const BreakExp&) override;
+ void operator()(const LetExp& e) override;
+ void operator()(const ArrayExp& e) override;
+ void operator()(const FieldInit& e) override;
+ /// \}
+
+ /// Visit Var declarations.
+ void operator()(const VarChunk& e) override;
+ void operator()(const VarDec& e) override;
+
+ /// Visit Function declarations.
+ void operator()(const FunctionChunk& e) override;
+ void operator()(const FunctionDec& e) override;
+ void operator()(const MethodChunk& e) override;
+ void operator()(const MethodDec& e) override;
+
+ /// Visit Type declarations.
+ void operator()(const TypeChunk& e) override;
+ void operator()(const TypeDec& e) override;
+
+ /** \} */
+
+ /** \name Visit Type related nodes.
+ ** \{ */
+ void operator()(const NameTy& e) override;
+ void operator()(const RecordTy& e) override;
+ void operator()(const ArrayTy& e) override;
+ void operator()(const ClassTy& e) override;
+ /** \} */
+
+ /** \name Visit Field related nodes. */
+ void operator()(const Field& e) override;
+
+ /** \name Visit Assertion nodes. */
+ void operator()(const AssertExp& e) override;
+
+ private:
+ // Factor pretty-printing of RecordExp and RecordTy.
+ template <typename RecordClass> void print_record(const RecordClass& e);
+
+ // Whether we are in a ast::ClassTy.
+ bool within_classty_p_ = false;
+
+ protected:
+ /// The stream to print on.
+ std::ostream& ostr_;
+ };
+
+} // namespace ast