summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/bind/renamer.cc
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/bind/renamer.cc
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/src/bind/renamer.cc')
-rw-r--r--tiger-compiler/src/bind/renamer.cc63
1 files changed, 63 insertions, 0 deletions
diff --git a/tiger-compiler/src/bind/renamer.cc b/tiger-compiler/src/bind/renamer.cc
new file mode 100644
index 0000000..1f13de0
--- /dev/null
+++ b/tiger-compiler/src/bind/renamer.cc
@@ -0,0 +1,63 @@
+/**
+ ** \file bind/renamer.cc
+ ** \brief Implementation of bind::Renamer.
+ */
+
+#include <bind/renamer.hh>
+
+namespace bind
+{
+ using namespace ast;
+
+ // FIXME DONE: Some code was deleted here.
+
+ void Renamer::operator()(ast::VarDec& e)
+ {
+ if (renames_.find(&e) != renames_.end())
+ super_type::operator()(e);
+ new_name_(&e);
+ e.name_set(renames_.at(&e));
+ super_type::operator()(e);
+ }
+ void Renamer::operator()(ast::TypeDec& e)
+ {
+ if (renames_.find(&e) != renames_.end())
+ super_type::operator()(e);
+ new_name_(&e);
+ e.name_set(renames_.at(&e));
+ super_type::operator()(e);
+ }
+ void Renamer::operator()(ast::FunctionDec& e)
+ {
+ if (e.body_get() == nullptr || e.name_get() == "_main"
+ || renames_.find(&e) != renames_.end())
+ {
+ super_type::operator()(e);
+ return;
+ }
+ new_name_(&e);
+ e.name_set(renames_.at(&e));
+ super_type::operator()(e);
+ }
+ void Renamer::operator()(ast::SimpleVar& e)
+ {
+ if (renames_.find(e.def_get()) != renames_.end())
+ e.name_set(renames_.at(e.def_get()));
+ }
+ void Renamer::operator()(ast::NameTy& e)
+ {
+ if (renames_.find(e.def_get()) != renames_.end())
+ e.name_set(renames_.at(e.def_get()));
+ }
+ void Renamer::operator()(ast::CallExp& e)
+ {
+ if (e.def_get() == nullptr || e.def_get()->body_get() == nullptr
+ || e.name_get() == "_main")
+ super_type::operator()(e);
+ else
+ {
+ e.name_set(renames_.at(e.def_get()));
+ super_type::operator()(e);
+ }
+ }
+} // namespace bind