1
Fork 0

Refactor MIR building for arguments.

This commit is contained in:
Scott Olson 2015-12-30 06:55:51 -06:00
parent b65277496c
commit f8b61340e3

View file

@ -138,29 +138,25 @@ impl<'a,'tcx> Builder<'a,'tcx> {
-> BlockAnd<Vec<ArgDecl<'tcx>>> -> BlockAnd<Vec<ArgDecl<'tcx>>>
{ {
self.in_scope(argument_extent, block, |this| { self.in_scope(argument_extent, block, |this| {
let arg_decls = { // to start, translate the argument patterns and collect the argument types.
let num_implicit_args = implicit_arguments.len(); let implicits = implicit_arguments.into_iter().map(|ty| (ty, None));
let implicit_arg_decls = implicit_arguments.into_iter() let explicits = explicit_arguments.into_iter().map(|(ty, pat)| (ty, Some(pat)));
.map(|ty| ArgDecl { ty: ty }); let arg_decls =
implicits
// to start, translate the argument patterns and collect the .chain(explicits)
// argument types. .enumerate()
let explicit_arg_decls = .map(|(index, (ty, pattern))| {
explicit_arguments if let Some(pattern) = pattern {
.into_iter() let lvalue = Lvalue::Arg(index as u32);
.enumerate()
.map(|(index, (ty, pattern))| {
let lvalue = Lvalue::Arg((num_implicit_args + index) as u32);
let pattern = this.hir.irrefutable_pat(pattern); let pattern = this.hir.irrefutable_pat(pattern);
unpack!(block = this.lvalue_into_pattern(block, unpack!(block = this.lvalue_into_pattern(block,
argument_extent, argument_extent,
pattern, pattern,
&lvalue)); &lvalue));
ArgDecl { ty: ty } }
}); ArgDecl { ty: ty }
})
implicit_arg_decls.chain(explicit_arg_decls).collect() .collect();
};
// start the first basic block and translate the body // start the first basic block and translate the body
unpack!(block = this.ast_block(&Lvalue::ReturnPointer, block, ast_block)); unpack!(block = this.ast_block(&Lvalue::ReturnPointer, block, ast_block));