/** ** \file bind/binder.hxx ** \brief Inline methods of bind::Binder. **/ // FIXME DONE: Some code was deleted here. #pragma once #include namespace bind { inline Binder::Binder() { scoped_map_fun_ = misc::scoped_map(); scoped_map_var_ = misc::scoped_map(); scoped_map_ty_ = misc::scoped_map(); loop_ = std::vector(); 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& 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& 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& e) { scoped_map_ty_.put(e.name_get(), &e); } template <> inline void Binder::visit_dec_bod(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