summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/object/renamer.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/object/renamer.hh
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/src/object/renamer.hh')
-rw-r--r--tiger-compiler/src/object/renamer.hh79
1 files changed, 79 insertions, 0 deletions
diff --git a/tiger-compiler/src/object/renamer.hh b/tiger-compiler/src/object/renamer.hh
new file mode 100644
index 0000000..6c62a86
--- /dev/null
+++ b/tiger-compiler/src/object/renamer.hh
@@ -0,0 +1,79 @@
+/**
+ ** \file object/renamer.hh
+ ** \brief Implementation of object::Renamer.
+ */
+
+#pragma once
+
+#include <map>
+
+#include <bind/renamer.hh>
+#include <object/fwd.hh>
+
+namespace object
+{
+ /// \brief Perform identifier renaming within an AST (in place),
+ /// with support for objects.
+ class Renamer : public bind::Renamer
+ {
+ public:
+ using super_type = ::bind::Renamer;
+
+ // Import overloaded virtual functions.
+ using super_type::operator();
+
+ /// Build a Renamer.
+ Renamer();
+
+ // Visit methods.
+ /// \name Visiting definition sites.
+ /// \{
+ /// This method is like bind::Binder's, but prevent the renaming
+ /// of attributes.
+ void operator()(ast::VarDec& e) override;
+ /// Rename methods.
+ void operator()(ast::MethodChunk& e) override;
+ /// Rename a method.
+ void operator()(ast::MethodDec& e) override;
+ /// In addition to performing the renaming, collect the name of
+ /// the classes.
+ void operator()(ast::TypeDec& e) override;
+ /// \}
+
+ /// \name Visiting usage sites.
+ /// \{
+ void operator()(ast::MethodCallExp& e) override;
+ /// \}
+
+ /// \name Visiting other object-related nodes.
+ ///
+ /// These methods should be part of an ObjectDefaultVisitor, but
+ /// our current design makes the implementation (and the use) of
+ /// such a visitor difficult.
+ /// \{
+ void operator()(ast::ClassTy& e) override;
+ void operator()(ast::ObjectExp& e) override;
+ /// \}
+
+ /// \name Visiting LetExp.
+ ///
+ /// In order to handle variable declarations that might be
+ /// situated in a ClassTy and yet do not qualify as attributes.
+ /// \{
+ void operator()(ast::LetExp& e) override;
+ /// \}
+
+ /// Class names.
+ /// \{
+ /// Get the class names.
+ class_names_type* class_names_get() const;
+
+ private:
+ /// Dictionnary mapping class types to their names.
+ class_names_type* class_names_;
+ /// Are we in a class definition?
+ bool within_class_ty_;
+ /// \}
+ };
+
+} // namespace object