Skip to content

Commit 822ed2c

Browse files
committed
Small refactors.
Factor out some shared code from the start of process_fwding_mthd and process_bkwding_mthd; get rid of unneeded temp variable.
1 parent 3b5b29c commit 822ed2c

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

src/comp/middle/trans_objects.rs

+26-34
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,26 @@ fn finish_vtbl(cx: @local_ctxt, llmethods: [ValueRef], name: str) ->
590590
ret gvar;
591591
}
592592

593+
// begin_fn: Set up an LLVM function for backwarding and forwarding functions.
594+
fn begin_fn(cx: @local_ctxt, sp: span, m: @ty::method,
595+
ty_params: [ast::ty_param], fn_name: str) -> ValueRef {
596+
597+
// Create a local context that's aware of the name of the method we're
598+
// creating.
599+
let mcx: @local_ctxt = @{path: cx.path + ["method", m.ident] with *cx};
600+
601+
// Make up a name for the function.
602+
let s: str =
603+
mangle_internal_name_by_path_and_seq(mcx.ccx, mcx.path, fn_name);
604+
605+
// Get the function's type and declare it.
606+
let llfn_ty: TypeRef = type_of_meth(cx.ccx, sp, m, ty_params);
607+
let llfn: ValueRef =
608+
decl_internal_fastcall_fn(cx.ccx.llmod, s, llfn_ty);
609+
610+
ret llfn;
611+
}
612+
593613
// process_bkwding_mthd: Create the backwarding function that appears in a
594614
// backwarding vtable slot.
595615
//
@@ -608,22 +628,7 @@ fn process_bkwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method,
608628
ty_params: [ast::ty_param], outer_obj_ty: ty::t,
609629
_additional_field_tys: [ty::t]) -> ValueRef {
610630

611-
// Create a local context that's aware of the name of the method we're
612-
// creating.
613-
let mcx: @local_ctxt = @{path: cx.path + ["method", m.ident] with *cx};
614-
615-
// Make up a name for the backwarding function.
616-
let fn_name: str = "backwarding_fn";
617-
let s: str =
618-
mangle_internal_name_by_path_and_seq(mcx.ccx, mcx.path, fn_name);
619-
620-
// Get the backwarding function's type and declare it.
621-
let llbackwarding_fn_ty: TypeRef = type_of_meth(cx.ccx, sp, m, ty_params);
622-
let llbackwarding_fn: ValueRef =
623-
decl_internal_fastcall_fn(cx.ccx.llmod, s, llbackwarding_fn_ty);
624-
625-
// Create a new function context and block context for the backwarding
626-
// function, holding onto a pointer to the first block.
631+
let llbackwarding_fn = begin_fn(cx, sp, m, ty_params, "backwarding_fn");
627632
let fcx = new_fn_ctxt(cx, sp, llbackwarding_fn);
628633
let bcx = new_top_block_ctxt(fcx);
629634
let lltop = bcx.llbb;
@@ -688,8 +693,8 @@ fn process_bkwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method,
688693

689694
// Set up the three implicit arguments to the outer method we'll need to
690695
// call.
691-
let self_arg = llself_obj_ptr;
692-
let llouter_mthd_args: [ValueRef] = [llretptr, fcx.lltaskptr, self_arg];
696+
let llouter_mthd_args: [ValueRef] = [llretptr, fcx.lltaskptr,
697+
llself_obj_ptr];
693698

694699
// Copy the explicit arguments that are being passed into the forwarding
695700
// function (they're in fcx.llargs) to llouter_mthd_args.
@@ -728,22 +733,9 @@ fn process_fwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method,
728733
backwarding_vtbl: ValueRef,
729734
additional_field_tys: [ty::t]) -> ValueRef {
730735

731-
// Create a local context that's aware of the name of the method we're
732-
// creating.
733-
let mcx: @local_ctxt = @{path: cx.path + ["method", m.ident] with *cx};
734-
735-
// Make up a name for the forwarding function.
736-
let fn_name: str = "forwarding_fn";
737-
let s: str =
738-
mangle_internal_name_by_path_and_seq(mcx.ccx, mcx.path, fn_name);
739-
740-
// Get the forwarding function's type and declare it.
741-
let llforwarding_fn_ty = type_of_meth(cx.ccx, sp, m, ty_params);
742-
let llforwarding_fn: ValueRef =
743-
decl_internal_fastcall_fn(cx.ccx.llmod, s, llforwarding_fn_ty);
744-
745-
// Create a new function context and block context for the forwarding
746-
// function, holding onto a pointer to the first block.
736+
// Create a new function context and block context for the function,
737+
// holding onto a pointer to the first block.
738+
let llforwarding_fn = begin_fn(cx, sp, m, ty_params, "forwarding_fn");
747739
let fcx = new_fn_ctxt(cx, sp, llforwarding_fn);
748740
let bcx = new_top_block_ctxt(fcx);
749741
let lltop = bcx.llbb;

0 commit comments

Comments
 (0)