]>
Commit | Line | Data |
---|---|---|
92a42be0 SL |
1 | // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
92a42be0 | 11 | use rustc::mir::repr as mir; |
3157f602 | 12 | |
a7813a04 | 13 | use common::{self, BlockAndBuilder}; |
92a42be0 SL |
14 | |
15 | use super::MirContext; | |
3157f602 | 16 | use super::LocalRef; |
92a42be0 SL |
17 | |
18 | impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { | |
19 | pub fn trans_statement(&mut self, | |
7453a54e | 20 | bcx: BlockAndBuilder<'bcx, 'tcx>, |
92a42be0 | 21 | statement: &mir::Statement<'tcx>) |
7453a54e | 22 | -> BlockAndBuilder<'bcx, 'tcx> { |
92a42be0 SL |
23 | debug!("trans_statement(statement={:?})", statement); |
24 | ||
3157f602 | 25 | let debug_loc = self.debug_loc(statement.source_info); |
a7813a04 XL |
26 | debug_loc.apply_to_bcx(&bcx); |
27 | debug_loc.apply(bcx.fcx()); | |
92a42be0 SL |
28 | match statement.kind { |
29 | mir::StatementKind::Assign(ref lvalue, ref rvalue) => { | |
3157f602 XL |
30 | if let Some(index) = self.mir.local_index(lvalue) { |
31 | match self.locals[index] { | |
32 | LocalRef::Lvalue(tr_dest) => { | |
33 | self.trans_rvalue(bcx, tr_dest, rvalue, debug_loc) | |
34 | } | |
35 | LocalRef::Operand(None) => { | |
36 | let (bcx, operand) = self.trans_rvalue_operand(bcx, rvalue, | |
37 | debug_loc); | |
38 | self.locals[index] = LocalRef::Operand(Some(operand)); | |
39 | bcx | |
40 | } | |
41 | LocalRef::Operand(Some(_)) => { | |
42 | let ty = self.lvalue_ty(lvalue); | |
a7813a04 | 43 | |
3157f602 XL |
44 | if !common::type_is_zero_size(bcx.ccx(), ty) { |
45 | span_bug!(statement.source_info.span, | |
46 | "operand {:?} already assigned", | |
47 | rvalue); | |
48 | } else { | |
49 | // If the type is zero-sized, it's already been set here, | |
50 | // but we still need to make sure we translate the operand | |
51 | self.trans_rvalue_operand(bcx, rvalue, debug_loc).0 | |
92a42be0 SL |
52 | } |
53 | } | |
54 | } | |
3157f602 XL |
55 | } else { |
56 | let tr_dest = self.trans_lvalue(&bcx, lvalue); | |
57 | self.trans_rvalue(bcx, tr_dest, rvalue, debug_loc) | |
92a42be0 SL |
58 | } |
59 | } | |
92a42be0 SL |
60 | } |
61 | } | |
62 | } |