diff options
Diffstat (limited to 'gcc/rust/backend/rust-compile-implitem.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-implitem.cc | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/gcc/rust/backend/rust-compile-implitem.cc b/gcc/rust/backend/rust-compile-implitem.cc index 4c7d8e8..1230c85 100644 --- a/gcc/rust/backend/rust-compile-implitem.cc +++ b/gcc/rust/backend/rust-compile-implitem.cc @@ -27,13 +27,34 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant) rust_assert (concrete != nullptr); TyTy::BaseType *resolved_type = concrete; - auto canonical_path = ctx->get_mappings ().lookup_canonical_path ( - constant.get_mappings ().get_nodeid ()); + tl::optional<Resolver::CanonicalPath> canonical_path; + if (flag_name_resolution_2_0) + { + auto &nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + + canonical_path = nr_ctx.values.to_canonical_path ( + constant.get_mappings ().get_nodeid ()); + } + else + { + canonical_path = ctx->get_mappings ().lookup_canonical_path ( + constant.get_mappings ().get_nodeid ()); + } + + rust_assert (canonical_path); + + HIR::Expr &const_value_expr = constant.get_expr (); + TyTy::BaseType *expr_type = nullptr; + bool ok = ctx->get_tyctx ()->lookup_type ( + const_value_expr.get_mappings ().get_hirid (), &expr_type); + rust_assert (ok); - HIR::Expr *const_value_expr = constant.get_expr ().get (); tree const_expr - = compile_constant_item (resolved_type, *canonical_path, const_value_expr, - constant.get_locus ()); + = compile_constant_item (constant.get_mappings ().get_hirid (), expr_type, + resolved_type, *canonical_path, const_value_expr, + constant.get_locus (), + const_value_expr.get_locus ()); ctx->push_const (const_expr); ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr); @@ -43,7 +64,7 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant) void CompileTraitItem::visit (HIR::TraitItemFunc &func) { - rust_assert (func.has_block_defined ()); + rust_assert (func.has_definition ()); rust_assert (concrete->get_kind () == TyTy::TypeKind::FNDEF); TyTy::FnType *fntype = static_cast<TyTy::FnType *> (concrete); @@ -75,18 +96,32 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func) fntype->override_context (); } - auto canonical_path = ctx->get_mappings ().lookup_canonical_path ( - func.get_mappings ().get_nodeid ()); + tl::optional<Resolver::CanonicalPath> canonical_path; + if (flag_name_resolution_2_0) + { + auto &nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + + canonical_path + = nr_ctx.values.to_canonical_path (func.get_mappings ().get_nodeid ()); + } + else + { + canonical_path = ctx->get_mappings ().lookup_canonical_path ( + func.get_mappings ().get_nodeid ()); + } + + rust_assert (canonical_path); // FIXME: How do we get the proper visibility here? auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC); HIR::TraitFunctionDecl &function = func.get_decl (); tree fndecl - = compile_function (function.get_function_name ().as_string (), + = compile_function (false, function.get_function_name ().as_string (), function.get_self (), function.get_function_params (), function.get_qualifiers (), vis, func.get_outer_attrs (), func.get_locus (), - func.get_block_expr ().get (), *canonical_path, fntype); + &func.get_block_expr (), *canonical_path, fntype); reference = address_expression (fndecl, ref_locus); } |