diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/src/bind/binder.hxx | |
Diffstat (limited to 'tiger-compiler/src/bind/binder.hxx')
| -rw-r--r-- | tiger-compiler/src/bind/binder.hxx | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/tiger-compiler/src/bind/binder.hxx b/tiger-compiler/src/bind/binder.hxx new file mode 100644 index 0000000..0facad9 --- /dev/null +++ b/tiger-compiler/src/bind/binder.hxx @@ -0,0 +1,124 @@ +/** + ** \file bind/binder.hxx + ** \brief Inline methods of bind::Binder. + **/ + +// FIXME DONE: Some code was deleted here. + +#pragma once + +#include <bind/binder.hh> + +namespace bind +{ + inline Binder::Binder() + { + scoped_map_fun_ = misc::scoped_map<const misc::symbol, ast::FunctionDec*>(); + scoped_map_var_ = misc::scoped_map<const misc::symbol, ast::VarDec*>(); + scoped_map_ty_ = misc::scoped_map<const misc::symbol, ast::TypeDec*>(); + loop_ = std::vector<ast::Exp*>(); + error_ = misc::error(); + } + + inline void Binder::body_func(ast::FunctionDec& e) + { + begin_scope(); + bool tmp = in_a_scope_; + in_a_scope_ = true; + e.formals_get().accept(*this); + this->accept(e.body_get()); + in_a_scope_ = tmp; + end_scope(); + } + + template <> + inline void Binder::visit_dec_head<ast::FunctionDec>(ast::FunctionDec& e) + { + if (e.name_get() == "_main") + { + if (is_main_already_) + { + error_ << misc::error::error_type::bind; + error_ << "Un deuxieme _main??????\n"; + return; + } + is_main_already_ = true; + if (in_a_scope_) + { + error_ << misc::error::error_type::bind; + error_ << "BRADDOCK, je vous préviens, attention ou vous mettez votre _main!!"; + return; + } + } + scoped_map_fun_.put(e.name_get(), &e); + } + + template <> + inline void Binder::visit_dec_bod<ast::FunctionDec>(ast::FunctionDec& e) + { + bool actual = in_a_while_; + in_a_while_ = false; + this->accept(e.result_get()); + body_func(e); + in_a_while_ = actual; + } + + /// @brief visit header so the Ast can know this type exist + /// @param e an Dec of a funcrion or ast + template <> + inline void Binder::visit_dec_head<ast::TypeDec>(ast::TypeDec& e) + { + scoped_map_ty_.put(e.name_get(), &e); + } + + template <> + inline void Binder::visit_dec_bod<ast::TypeDec>(ast::TypeDec& e) + { + super_type::operator()(e); + } + + inline void Binder::begin_scope() + { + scoped_map_fun_.scope_begin(); + scoped_map_ty_.scope_begin(); + scoped_map_var_.scope_begin(); + } + + inline void Binder::end_scope() + { + scoped_map_fun_.scope_end(); + scoped_map_ty_.scope_end(); + scoped_map_var_.scope_end(); + } + + inline void Binder::err_undef(const ast::Location& loc, const misc::symbol& name) + { + error_ << misc::error::error_type::bind; + error_ << loc << ": undeclared variable: " << name << "\n"; + } + + inline void Binder::err_type_undef(const ast::Location& loc, const misc::symbol& name) + { + error_ << misc::error::error_type::bind; + error_ << loc << ": undeclared type: " << name << "\n"; + } + + inline void Binder::is_there__main() + { + if (!is_main_already_) + { + error_ << misc::error::error_type::bind; + error_ << "Bah bro il est ou ton _main??????\n"; + } + } + + inline void Binder::err_ddec(const ast::Location& loc, + const ast::Location& first, + const misc::symbol& name) + { + error_ << misc::error::error_type::bind; + error_ << loc << ": redefinition: " << name << "\n"; + error_ << first << ": first definition\n"; + } + +} // namespace bind
\ No newline at end of file |
