diff options
author | John Hodge <tpg@mutabah.net> | 2016-02-18 18:41:39 +1100 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-02-18 18:41:39 +1100 |
commit | 651ab293f3bfa117dae618edb9a4a9f328e07a91 (patch) | |
tree | d8a7ce58aa58a018a1f86aa5fa3f73e57e6c238a /src/ast/ast.cpp | |
parent | 13075f30738556212ca0ff02d28dab75c268c1fd (diff) | |
download | mrust-651ab293f3bfa117dae618edb9a4a9f328e07a91.tar.gz |
Random commit
Diffstat (limited to 'src/ast/ast.cpp')
-rw-r--r-- | src/ast/ast.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 7ab461d5..7d9e16c5 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -217,6 +217,16 @@ void Crate::post_parse() };
iterate_module(m_root_module, cb);
iterate_module(g_compiler_module, cb);
+
+ // Create a map of inherent impls
+ for( const auto& impl : m_impl_index )
+ {
+ if( impl->def().trait().is_valid() == false )
+ {
+ auto& ent = m_impl_map[impl->def().type()];
+ ent.push_back( impl );
+ }
+ }
}
void Crate::iterate_functions(fcn_visitor_t* visitor)
@@ -286,24 +296,31 @@ bool Crate::check_impls_wildcard(const Path& trait, const TypeRef& type) const }
-::std::vector<ImplRef> Crate::find_inherent_impls(const TypeRef& type) const
+bool Crate::find_inherent_impls(const TypeRef& type, ::std::function<bool(const Impl& , ::std::vector<TypeRef> )> callback) const
{
assert( !type.is_type_param() );
- ::std::vector<ImplRef> ret;
-
for( auto implptr : m_impl_index )
{
Impl& impl = *implptr;
- DEBUG("- " << impl.def());
- ::std::vector<TypeRef> out_params;
- if( impl.def().matches(out_params, AST::Path(), type) )
+ if( impl.def().trait().is_valid() )
+ {
+ // Trait
+ }
+ else
{
- ret.push_back( ImplRef(impl, out_params) );
+ DEBUG("- " << impl.def());
+ ::std::vector<TypeRef> out_params;
+ if( impl.def().matches(out_params, AST::Path(), type) )
+ {
+ if( callback(impl, out_params) ) {
+ return true;
+ }
+ }
}
}
- return ret;
+ return false;
}
::rust::option<ImplRef> Crate::find_impl(const Path& trait, const TypeRef& type) const
|