From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/src/object/renamer.hh | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tiger-compiler/src/object/renamer.hh (limited to 'tiger-compiler/src/object/renamer.hh') 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 + +#include +#include + +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 -- cgit v1.2.3