diff options
Diffstat (limited to 'src/ast/ast.cpp')
-rw-r--r-- | src/ast/ast.cpp | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index fb289a20..d2006e52 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -106,6 +106,17 @@ SERIALISE_TYPE(ImplDef::, "AST_ImplDef", { s.item(m_type);
})
+bool Impl::has_named_item(const ::std::string& name) const
+{
+ for( const auto& it : this->functions() )
+ {
+ if( it.name == name ) {
+ return true;
+ }
+ }
+ return false;
+}
+
Impl& Impl::get_concrete(const ::std::vector<TypeRef>& param_types)
{
if( param_types.size() > 0 )
@@ -177,6 +188,17 @@ Crate::Crate(): {
}
+::rust::option<char> ImplRef::find_named_item(const ::std::string& name) const
+{
+ if( this->impl.has_named_item(name) ) {
+ return ::rust::Some(' ');
+ }
+ else {
+ return ::rust::None<char>();
+ }
+}
+
+
static void iterate_module(Module& mod, ::std::function<void(Module& mod)> fcn)
{
fcn(mod);
@@ -263,6 +285,39 @@ bool Crate::check_impls_wildcard(const Path& trait, const TypeRef& type) const return type.impls_wildcard(*this, trait);
}
+
+::std::vector<ImplRef> Crate::find_inherent_impls(const TypeRef& type) const
+{
+ assert( !type.is_type_param() );
+
+ ::std::vector<ImplRef> ret;
+
+ for( auto implptr : m_impl_index )
+ {
+ Impl& impl = *implptr;
+ ::std::vector<TypeRef> out_params;
+ if( impl.def().matches(out_params, AST::Path(), type) )
+ {
+ ret.push_back( ImplRef(impl, out_params) );
+ }
+ }
+
+ return ret;
+}
+
+::rust::option<ImplRef> Crate::find_impl(const Path& trait, const TypeRef& type) const
+{
+ ::std::vector<TypeRef> params;
+ Impl *out_impl;
+ if( find_impl(trait, type, &out_impl, ¶ms) )
+ {
+ return ::rust::Some( ImplRef(*out_impl, params) );
+ }
+ else {
+ return ::rust::None<ImplRef>();
+ }
+}
+
bool Crate::find_impl(const Path& trait, const TypeRef& type, Impl** out_impl, ::std::vector<TypeRef>* out_params) const
{
TRACE_FUNCTION_F("trait = " << trait << ", type = " << type);
@@ -1003,7 +1058,7 @@ bool TypeParams::check_params(Crate& crate, ::std::vector<TypeRef>& types, bool {
const auto& trait = bound.as_IsTrait().trait;
// Check if 'type' impls 'trait'
- if( !crate.find_impl(trait, trait) )
+ if( !crate.find_impl(trait, trait, nullptr, nullptr) )
{
throw ::std::runtime_error( FMT("No matching impl of "<<trait<<" for "<<type));
}
|