aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-implitem.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-03-25 16:24:59 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-03-27 18:55:14 +0000
commit573120551a0bc6813f32ed371df65311724e96dd (patch)
treed4262132bacfd6a705078f4e64973a5b8cfbe1c4 /gcc/rust/backend/rust-compile-implitem.h
parente9bb91b4a7caaab185d029d9c093c520366462d8 (diff)
downloadgcc-573120551a0bc6813f32ed371df65311724e96dd.zip
gcc-573120551a0bc6813f32ed371df65311724e96dd.tar.gz
gcc-573120551a0bc6813f32ed371df65311724e96dd.tar.bz2
Add generics for impl blocks
Generics paramters to impl blocks allows each impl-item to inherit these and get handled in a similar way as to normal functions. Fixes #237
Diffstat (limited to 'gcc/rust/backend/rust-compile-implitem.h')
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h28
1 files changed, 23 insertions, 5 deletions
diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h
index 0817424..15aba9b 100644
--- a/gcc/rust/backend/rust-compile-implitem.h
+++ b/gcc/rust/backend/rust-compile-implitem.h
@@ -35,9 +35,10 @@ class CompileInherentImplItem : public HIRCompileBase
public:
static void Compile (TyTy::BaseType *self, HIR::InherentImplItem *item,
- Context *ctx, bool compile_fns)
+ Context *ctx, bool compile_fns,
+ TyTy::BaseType *concrete = nullptr)
{
- CompileInherentImplItem compiler (self, ctx, compile_fns);
+ CompileInherentImplItem compiler (self, ctx, compile_fns, concrete);
item->accept_vis (compiler);
}
@@ -92,6 +93,21 @@ public:
}
TyTy::FnType *fntype = static_cast<TyTy::FnType *> (fntype_tyty);
+ if (fntype->has_subsititions_defined ())
+ {
+ // we cant do anything for this only when it is used
+ if (concrete == nullptr)
+ return;
+ else
+ {
+ rust_assert (concrete->get_kind () == TyTy::TypeKind::FNDEF);
+ fntype = static_cast<TyTy::FnType *> (concrete);
+
+ // override the Hir Lookups for the substituions in this context
+ fntype->override_context ();
+ }
+ }
+
// convert to the actual function type
::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
@@ -111,7 +127,6 @@ public:
ctx->insert_function_decl (fntype->get_ty_ref (), fndecl);
// setup the params
-
TyTy::BaseType *tyret = fntype->get_return_type ();
std::vector<Bvariable *> param_vars;
@@ -431,12 +446,15 @@ public:
}
private:
- CompileInherentImplItem (TyTy::BaseType *self, Context *ctx, bool compile_fns)
- : HIRCompileBase (ctx), self (self), compile_fns (compile_fns)
+ CompileInherentImplItem (TyTy::BaseType *self, Context *ctx, bool compile_fns,
+ TyTy::BaseType *concrete)
+ : HIRCompileBase (ctx), self (self), compile_fns (compile_fns),
+ concrete (concrete)
{}
TyTy::BaseType *self;
bool compile_fns;
+ TyTy::BaseType *concrete;
};
} // namespace Compile