diff options
author | John Hodge <tpg@mutabah.net> | 2016-06-07 12:16:21 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-06-07 12:16:21 +0800 |
commit | 1e2fca15c8ef76b40a1aec36938dde069536a668 (patch) | |
tree | 36ecf36553b47d63d7069773b0b9eaa259ddad6e /src/hir | |
parent | f1d8a4382fc5d40f7fd53391cd9879566392f984 (diff) | |
download | mrust-1e2fca15c8ef76b40a1aec36938dde069536a668.tar.gz |
HIR Typecheck - Inherent function lookup
Diffstat (limited to 'src/hir')
-rw-r--r-- | src/hir/hir.cpp | 14 | ||||
-rw-r--r-- | src/hir/hir.hpp | 3 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp index 756e4b7b..29d7e975 100644 --- a/src/hir/hir.cpp +++ b/src/hir/hir.cpp @@ -259,7 +259,7 @@ const ::HIR::Function& ::HIR::Crate::get_function_by_path(const Span& sp, const } } -const bool ::HIR::Crate::find_trait_impls(const ::HIR::SimplePath& trait, const ::HIR::TypeRef& type, t_cb_resolve_type ty_res, ::std::function<bool(const ::HIR::TraitImpl&)> callback) const +bool ::HIR::Crate::find_trait_impls(const ::HIR::SimplePath& trait, const ::HIR::TypeRef& type, t_cb_resolve_type ty_res, ::std::function<bool(const ::HIR::TraitImpl&)> callback) const { auto its = this->m_trait_impls.equal_range( trait ); for( auto it = its.first; it != its.second; ++ it ) @@ -273,3 +273,15 @@ const bool ::HIR::Crate::find_trait_impls(const ::HIR::SimplePath& trait, const } return false; } +bool ::HIR::Crate::find_type_impls(const ::HIR::TypeRef& type, t_cb_resolve_type ty_res, ::std::function<bool(const ::HIR::TypeImpl&)> callback) const +{ + for( const auto& impl : this->m_type_impls ) + { + if( impl.matches_type(type, ty_res) ) { + if( callback(impl) ) { + return true; + } + } + } + return false; +} diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp index 73e7b1af..c6dec6c8 100644 --- a/src/hir/hir.hpp +++ b/src/hir/hir.hpp @@ -275,7 +275,8 @@ public: const ::HIR::ValueItem& get_valitem_by_path(const Span& sp, const ::HIR::SimplePath& path) const; const ::HIR::Function& get_function_by_path(const Span& sp, const ::HIR::SimplePath& path) const; - const bool find_trait_impls(const ::HIR::SimplePath& path, const ::HIR::TypeRef& type, t_cb_resolve_type ty_res, ::std::function<bool(const ::HIR::TraitImpl&)> callback) const; + bool find_trait_impls(const ::HIR::SimplePath& path, const ::HIR::TypeRef& type, t_cb_resolve_type ty_res, ::std::function<bool(const ::HIR::TraitImpl&)> callback) const; + bool find_type_impls(const ::HIR::TypeRef& type, t_cb_resolve_type ty_res, ::std::function<bool(const ::HIR::TypeImpl&)> callback) const; }; } // namespace HIR |