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/bind/renamer.cc | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tiger-compiler/src/bind/renamer.cc (limited to 'tiger-compiler/src/bind/renamer.cc') 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 + +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 -- cgit v1.2.3