1 // Copyright 2015 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.
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.
11 //! See docs in build/expr/mod.rs
13 use build
::{BlockAnd, BlockAndExtension, Builder}
;
14 use build
::expr
::category
::Category
;
16 use rustc
::mir
::repr
::*;
18 impl<'a
,'tcx
> Builder
<'a
,'tcx
> {
19 /// Compile `expr` into a value that can be used as an operand.
20 /// If `expr` is an lvalue like `x`, this will introduce a
21 /// temporary `tmp = x`, so that we capture the value of `x` at
23 pub fn as_operand
<M
>(&mut self, block
: BasicBlock
, expr
: M
) -> BlockAnd
<Operand
<'tcx
>>
24 where M
: Mirror
<'tcx
, Output
= Expr
<'tcx
>>
26 let expr
= self.hir
.mirror(expr
);
27 self.expr_as_operand(block
, expr
)
30 fn expr_as_operand(&mut self,
31 mut block
: BasicBlock
,
33 -> BlockAnd
<Operand
<'tcx
>> {
34 debug
!("expr_as_operand(block={:?}, expr={:?})", block
, expr
);
37 if let ExprKind
::Scope { extent, value }
= expr
.kind
{
38 return this
.in_scope(extent
, block
, |this
, _
| this
.as_operand(block
, value
));
41 let category
= Category
::of(&expr
.kind
).unwrap();
42 debug
!("expr_as_operand: category={:?} for={:?}", category
, expr
.kind
);
44 Category
::Constant
=> {
45 let constant
= this
.as_constant(expr
);
46 block
.and(Operand
::Constant(constant
))
49 Category
::Rvalue(..) => {
50 let operand
= unpack
!(block
= this
.as_temp(block
, expr
));
51 block
.and(Operand
::Consume(operand
))