aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-resolve-path.cc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-08-11 19:45:21 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-08-19 14:36:11 +0100
commit71cf0d44d3fceb235c95d5acaf92b498f8cf923b (patch)
tree4586cb6d436eeda82408da48709647f9f0cc5eb0 /gcc/rust/backend/rust-compile-resolve-path.cc
parent3f877a690dccd5faf5b75ad7b75e0bd85f0a5be4 (diff)
downloadgcc-71cf0d44d3fceb235c95d5acaf92b498f8cf923b.zip
gcc-71cf0d44d3fceb235c95d5acaf92b498f8cf923b.tar.gz
gcc-71cf0d44d3fceb235c95d5acaf92b498f8cf923b.tar.bz2
Add support for optional trait functions in method calls
This adds compilation support for optional trait functions with a function block. This does not support constants or default types yet. Trait references must do type resolution of their block, but this is only performed once a trait is resolved. In order to avoid recursive trait resolution we use a on_resolved callback to invoke this to occur. The trait resolver works as a query based system so you have to avoid the case of recursively resolving the trait untill it is stored in the internal mappings. Addresses #542
Diffstat (limited to 'gcc/rust/backend/rust-compile-resolve-path.cc')
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc31
1 files changed, 29 insertions, 2 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index 5f07a2a..97ba15d 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -138,8 +138,35 @@ ResolvePathRef::visit (HIR::PathInExpression &expr)
{
// this means we are defaulting back to the trait_item if
// possible
- // TODO
- gcc_unreachable ();
+ Resolver::TraitItemReference *trait_item_ref = nullptr;
+ bool ok = trait_ref->lookup_hir_trait_item (*trait_item,
+ &trait_item_ref);
+ rust_assert (ok); // found
+ rust_assert (
+ trait_item_ref->is_optional ()); // has definition
+
+ // FIXME
+ // TyTy::BaseType *self_type = nullptr;
+ // if (!ctx->get_tyctx ()->lookup_type (
+ // expr.get_receiver ()->get_mappings ().get_hirid (),
+ // &self_type))
+ // {
+ // rust_error_at (expr.get_locus (),
+ // "failed to resolve type for self param");
+ // return;
+ // }
+
+ // CompileTraitItem::Compile (
+ // self_type, trait_item_ref->get_hir_trait_item (), ctx,
+ // fntype);
+ // if (!ctx->lookup_function_decl (fntype->get_ty_ref (),
+ // &fn))
+ // {
+ // translated = ctx->get_backend ()->error_expression ();
+ // rust_error_at (expr.get_locus (),
+ // "forward declaration was not compiled");
+ // return;
+ // }
}
else
{