Simplify trans/exprs.rs DefStatic considerably

This commit is contained in:
Simonas Kazlauskas 2015-11-11 00:19:37 +02:00
parent 21deb18bfd
commit f1342ffb3c
2 changed files with 2 additions and 23 deletions

View file

@ -1221,6 +1221,6 @@ pub fn get_static_val<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
if let Some(node_id) = ccx.tcx().map.as_local_node_id(did) {
base::get_item_val(ccx, node_id)
} else {
base::trans_external_path(ccx, did, ty)
base::get_extern_const(ccx, did, ty)
}
}

View file

@ -941,29 +941,8 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
DatumBlock::new(bcx, datum.to_expr_datum())
}
def::DefStatic(did, _) => {
// There are two things that may happen here:
// 1) If the static item is defined in this crate, it will be
// translated using `get_item_val`, and we return a pointer to
// the result.
// 2) If the static item is defined in another crate then we add
// (or reuse) a declaration of an external global, and return a
// pointer to that.
let const_ty = expr_ty(bcx, ref_expr);
// For external constants, we don't inline.
let val = if let Some(node_id) = bcx.tcx().map.as_local_node_id(did) {
// Case 1.
// The LLVM global has the type of its initializer,
// which may not be equal to the enum's type for
// non-C-like enums.
let val = base::get_item_val(bcx.ccx(), node_id);
let pty = type_of::type_of(bcx.ccx(), const_ty).ptr_to();
PointerCast(bcx, val, pty)
} else {
// Case 2.
base::get_extern_const(bcx.ccx(), did, const_ty)
};
let val = get_static_val(bcx.ccx(), did, const_ty);
let lval = Lvalue::new("expr::trans_def");
DatumBlock::new(bcx, Datum::new(val, const_ty, LvalueExpr(lval)))
}