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/overload/binder.hh | |
Diffstat (limited to 'tiger-compiler/src/overload/binder.hh')
| -rw-r--r-- | tiger-compiler/src/overload/binder.hh | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tiger-compiler/src/overload/binder.hh b/tiger-compiler/src/overload/binder.hh new file mode 100644 index 0000000..607debb --- /dev/null +++ b/tiger-compiler/src/overload/binder.hh @@ -0,0 +1,65 @@ +/** + ** \file overload/binder.hh + ** \brief Declaration of overload::Binder. + **/ + +#pragma once + +#include <map> + +#include <bind/binder.hh> +#include <overload/over-table.hh> + +namespace overload +{ + /// Type of the dictionary of potential function bindings. + using overfun_bindings_type = std::multimap<ast::CallExp*, ast::FunctionDec*>; + + /** \brief Computing bindings with support for overloaded functions. + ** + ** This visitor inherits from Binder, but redefines methods + ** dealing with function declarations and uses, to allow + ** overloading. + ** + ** As overloading requires some knowledge of the type of the + ** arguments of a function, no real function binding is done here. + ** We store all potential function declarations (``homonyms'') for + ** each function call, and we'll let the overload::TypeChecker + ** decide later. + ** + ** Inheritance is declared virtual to enable diamond inheritance with + ** the combine::Binder (src/combine/binder.hh), inheriting from + ** overload::Binder and object::Binder, both inheriting from bind::Binder. + **/ + class Binder : virtual public bind::Binder + { + public: + /// Super class type. + using super_type = bind::Binder; + /// Import all the overloaded operator() methods. + using super_type::operator(); + + /* The visiting methods. */ + /// Visit a function call. + void operator()(ast::CallExp& e) override; + + /// Check a function declaration header. + void visit_dec_header(ast::FunctionDec& e); + /// Visit a chunk of function declarations. + void operator()(ast::FunctionChunk& e) override; + + /// Return the function bindings. + overfun_bindings_type& overfun_bindings_get(); + + // FIXME: Some code was deleted here (Overload scope handling). + /** \} */ + + private: + using overtable_type = OverTable<ast::FunctionDec>; + /// The environment of (overloaded) functions. + overtable_type overfuns_; + /// The potential function bindings. + overfun_bindings_type overfun_bindings_; + }; + +} // namespace overload |
