1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
use build::{BlockAnd, BlockAndExtension, Builder};
use build::scope::LoopScope;
use hair::*;
use rustc::mir::*;
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
pub fn stmt_expr(&mut self, mut block: BasicBlock, expr: Expr<'tcx>) -> BlockAnd<()> {
let this = self;
let expr_span = expr.span;
let source_info = this.source_info(expr.span);
match expr.kind {
ExprKind::Scope { extent, value } => {
let value = this.hir.mirror(value);
this.in_scope(extent, block, |this| this.stmt_expr(block, value))
}
ExprKind::Assign { lhs, rhs } => {
let lhs = this.hir.mirror(lhs);
let rhs = this.hir.mirror(rhs);
let lhs_span = lhs.span;
if this.hir.needs_drop(lhs.ty) {
let rhs = unpack!(block = this.as_local_operand(block, rhs));
let lhs = unpack!(block = this.as_lvalue(block, lhs));
unpack!(block = this.build_drop_and_replace(
block, lhs_span, lhs, rhs
));
block.unit()
} else {
let rhs = unpack!(block = this.as_local_rvalue(block, rhs));
let lhs = unpack!(block = this.as_lvalue(block, lhs));
this.cfg.push_assign(block, source_info, &lhs, rhs);
block.unit()
}
}
ExprKind::AssignOp { op, lhs, rhs } => {
let lhs = this.hir.mirror(lhs);
let lhs_ty = lhs.ty;
let rhs = unpack!(block = this.as_local_operand(block, rhs));
let lhs = unpack!(block = this.as_lvalue(block, lhs));
let result = unpack!(block = this.build_binary_op(block, op, expr_span, lhs_ty,
Operand::Consume(lhs.clone()), rhs));
this.cfg.push_assign(block, source_info, &lhs, result);
block.unit()
}
ExprKind::Continue { label } => {
let LoopScope { continue_block, extent, .. } =
*this.find_loop_scope(expr_span, label);
this.exit_scope(expr_span, extent, block, continue_block);
this.cfg.start_new_block().unit()
}
ExprKind::Break { label, value } => {
let (break_block, extent, destination) = {
let LoopScope {
break_block,
extent,
ref break_destination,
..
} = *this.find_loop_scope(expr_span, label);
(break_block, extent, break_destination.clone())
};
if let Some(value) = value {
unpack!(block = this.into(&destination, block, value))
} else {
this.cfg.push_assign_unit(block, source_info, &destination)
}
this.exit_scope(expr_span, extent, block, break_block);
this.cfg.start_new_block().unit()
}
ExprKind::Return { value } => {
block = match value {
Some(value) => {
unpack!(this.into(&Lvalue::Local(RETURN_POINTER), block, value))
}
None => {
this.cfg.push_assign_unit(block,
source_info,
&Lvalue::Local(RETURN_POINTER));
block
}
};
let extent = this.extent_of_return_scope();
let return_block = this.return_block();
this.exit_scope(expr_span, extent, block, return_block);
this.cfg.start_new_block().unit()
}
ExprKind::InlineAsm { asm, outputs, inputs } => {
let outputs = outputs.into_iter().map(|output| {
unpack!(block = this.as_lvalue(block, output))
}).collect();
let inputs = inputs.into_iter().map(|input| {
unpack!(block = this.as_local_operand(block, input))
}).collect();
this.cfg.push(block, Statement {
source_info: source_info,
kind: StatementKind::InlineAsm {
asm: asm.clone(),
outputs: outputs,
inputs: inputs
},
});
block.unit()
}
_ => {
let expr_ty = expr.ty;
let temp = this.temp(expr.ty.clone());
unpack!(block = this.into(&temp, block, expr));
unpack!(block = this.build_drop(block, expr_span, temp, expr_ty));
block.unit()
}
}
}
}