use middle::ty;
use middle::typeck::astconv;
-use middle;
use util::nodemap::{DefIdMap, FnvHashMap, NodeMap};
use syntax::ast::*;
pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
-> Result<const_val, ~str> {
- use middle::ty;
fn fromb(b: bool) -> Result<const_val, ~str> { Ok(const_int(b as i64)) }
match e.node {
ExprUnary(UnNeg, inner) => {
}
pub struct StatRecorder<'a> {
- ccx: @CrateContext<'a>,
+ ccx: &'a CrateContext<'a>,
name: Option<~str>,
start: u64,
istart: uint,
}
impl<'a> StatRecorder<'a> {
- pub fn new(ccx: @CrateContext<'a>, name: ~str) -> StatRecorder<'a> {
+ pub fn new(ccx: &'a CrateContext<'a>, name: ~str) -> StatRecorder<'a> {
let start = if ccx.sess().trans_stats() {
time::precise_time_ns()
} else {
}
-pub fn get_res_dtor(ccx: @CrateContext,
+pub fn get_res_dtor(ccx: &CrateContext,
did: ast::DefId,
parent_id: ast::DefId,
substs: &[ty::t])
//
// Be warned! You must call `init_function` before doing anything with the
// returned function context.
-pub fn new_fn_ctxt<'a>(ccx: @CrateContext<'a>,
+pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext<'a>,
llfndecl: ValueRef,
id: ast::NodeId,
has_env: bool,
// trans_closure: Builds an LLVM function out of a source function.
// If the function closes over its environment a closure will be
// returned.
-pub fn trans_closure<'a>(ccx: @CrateContext,
- decl: &ast::FnDecl,
- body: &ast::Block,
- llfndecl: ValueRef,
- param_substs: Option<@param_substs>,
- id: ast::NodeId,
- _attributes: &[ast::Attribute],
- output_type: ty::t,
- maybe_load_env: <'b> |&'b Block<'b>| -> &'b Block<'b>) {
+pub fn trans_closure(ccx: &CrateContext,
+ decl: &ast::FnDecl,
+ body: &ast::Block,
+ llfndecl: ValueRef,
+ param_substs: Option<@param_substs>,
+ id: ast::NodeId,
+ _attributes: &[ast::Attribute],
+ output_type: ty::t,
+ maybe_load_env: <'a> |&'a Block<'a>| -> &'a Block<'a>) {
ccx.stats.n_closures.set(ccx.stats.n_closures.get() + 1);
let _icx = push_ctxt("trans_closure");
// trans_fn: creates an LLVM function corresponding to a source language
// function.
-pub fn trans_fn(ccx: @CrateContext,
+pub fn trans_fn(ccx: &CrateContext,
decl: &ast::FnDecl,
body: &ast::Block,
llfndecl: ValueRef,
param_substs, id, attrs, output_type, |bcx| bcx);
}
-pub fn trans_enum_variant(ccx: @CrateContext,
+pub fn trans_enum_variant(ccx: &CrateContext,
_enum_id: ast::NodeId,
variant: &ast::Variant,
_args: &[ast::VariantArg],
llfndecl);
}
-pub fn trans_tuple_struct(ccx: @CrateContext,
+pub fn trans_tuple_struct(ccx: &CrateContext,
_fields: &[ast::StructField],
ctor_id: ast::NodeId,
param_substs: Option<@param_substs>,
llfndecl);
}
-fn trans_enum_variant_or_tuple_like_struct(ccx: @CrateContext,
+fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
ctor_id: ast::NodeId,
disr: ty::Disr,
param_substs: Option<@param_substs>,
finish_fn(&fcx, bcx);
}
-pub fn trans_enum_def(ccx: @CrateContext, enum_definition: &ast::EnumDef,
- id: ast::NodeId, vi: @Vec<@ty::VariantInfo> ,
+pub fn trans_enum_def(ccx: &CrateContext, enum_definition: &ast::EnumDef,
+ id: ast::NodeId, vi: @Vec<@ty::VariantInfo>,
i: &mut uint) {
for &variant in enum_definition.variants.iter() {
let disr_val = vi.get(*i).disr_val;
}
pub struct TransItemVisitor<'a> {
- ccx: @CrateContext<'a>,
+ ccx: &'a CrateContext<'a>,
}
impl<'a> Visitor<()> for TransItemVisitor<'a> {
}
}
-pub fn trans_item(ccx: @CrateContext, item: &ast::Item) {
+pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
let _icx = push_ctxt("trans_item");
match item.node {
ast::ItemFn(decl, purity, _abis, ref generics, body) => {
}
}
-pub fn trans_struct_def(ccx: @CrateContext, struct_def: @ast::StructDef) {
+pub fn trans_struct_def(ccx: &CrateContext, struct_def: @ast::StructDef) {
// If this is a tuple-like struct, translate the constructor.
match struct_def.ctor_id {
// We only need to translate a constructor if there are fields;
// separate modules in the compiled program. That's because modules exist
// only as a convenience for humans working with the code, to organize names
// and control visibility.
-pub fn trans_mod(ccx: @CrateContext, m: &ast::Mod) {
+pub fn trans_mod(ccx: &CrateContext, m: &ast::Mod) {
let _icx = push_ctxt("trans_mod");
for item in m.items.iter() {
trans_item(ccx, *item);
}
}
-fn finish_register_fn(ccx: @CrateContext, sp: Span, sym: ~str, node_id: ast::NodeId,
+fn finish_register_fn(ccx: &CrateContext, sp: Span, sym: ~str, node_id: ast::NodeId,
llfn: ValueRef) {
{
let mut item_symbols = ccx.item_symbols.borrow_mut();
}
}
-fn register_fn(ccx: @CrateContext,
+fn register_fn(ccx: &CrateContext,
sp: Span,
sym: ~str,
node_id: ast::NodeId,
}
// only use this for foreign function ABIs and glue, use `register_fn` for Rust functions
-pub fn register_fn_llvmty(ccx: @CrateContext,
+pub fn register_fn_llvmty(ccx: &CrateContext,
sp: Span,
sym: ~str,
node_id: ast::NodeId,
// Create a _rust_main(args: ~[str]) function which will be called from the
// runtime rust_start function
-pub fn create_entry_wrapper(ccx: @CrateContext,
+pub fn create_entry_wrapper(ccx: &CrateContext,
_sp: Span,
main_llfn: ValueRef) {
let et = ccx.sess().entry_type.get().unwrap();
session::EntryNone => {} // Do nothing.
}
- fn create_entry_fn(ccx: @CrateContext,
+ fn create_entry_fn(ccx: &CrateContext,
rust_main: ValueRef,
use_start_lang_item: bool) {
let llfty = Type::func([ccx.int_type, Type::i8().ptr_to().ptr_to()],
}
}
-pub fn get_item_val(ccx: @CrateContext, id: ast::NodeId) -> ValueRef {
+pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
debug!("get_item_val(id=`{:?}`)", id);
let val = {
}
}
-fn register_method(ccx: @CrateContext, id: ast::NodeId,
+fn register_method(ccx: &CrateContext, id: ast::NodeId,
m: &ast::Method) -> ValueRef {
let mty = ty::node_id_to_type(ccx.tcx, id);
return (sym_name, map);
}
-pub fn fill_crate_map(ccx: @CrateContext, map: ValueRef) {
+pub fn fill_crate_map(ccx: &CrateContext, map: ValueRef) {
let event_loop_factory = match ccx.tcx.lang_items.event_loop_factory() {
Some(did) => unsafe {
if is_local(did) {
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
let llmod_id = link_meta.crateid.name + ".rs";
- let ccx = @CrateContext::new(llmod_id,
+ let ccx = &CrateContext::new(llmod_id,
&analysis.ty_cx,
analysis.exp_map2,
analysis.maps,
bcx
}
-pub fn get_wrapper_for_bare_fn(ccx: @CrateContext,
+pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
closure_ty: ty::t,
def: ast::Def,
fn_ptr: ValueRef,
block_arena: &'a TypedArena<Block<'a>>,
// This function's enclosing crate context.
- ccx: @CrateContext<'a>,
+ ccx: &'a CrateContext<'a>,
// Used and maintained by the debuginfo module.
debug_context: debuginfo::FunctionDebugContext,
})
}
- pub fn ccx(&self) -> @CrateContext<'a> { self.fcx.ccx }
+ pub fn ccx(&self) -> &'a CrateContext<'a> { self.fcx.ccx }
pub fn tcx(&self) -> &'a ty::ctxt {
self.fcx.ccx.tcx
}
}
}
-fn const_vec(cx: @CrateContext, e: &ast::Expr,
+fn const_vec(cx: &CrateContext, e: &ast::Expr,
es: &[@ast::Expr], is_local: bool) -> (ValueRef, Type, bool) {
let vec_ty = ty::expr_ty(cx.tcx, e);
let unit_ty = ty::sequence_element_type(cx.tcx, vec_ty);
}
}
-pub fn get_const_val(cx: @CrateContext,
+pub fn get_const_val(cx: &CrateContext,
mut def_id: ast::DefId) -> (ValueRef, bool) {
let contains_key = {
let const_values = cx.const_values.borrow();
!non_inlineable_statics.get().contains(&def_id.node))
}
-pub fn const_expr(cx: @CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef, bool) {
+pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef, bool) {
let (llconst, inlineable) = const_expr_unadjusted(cx, e, is_local);
let mut llconst = llconst;
let mut inlineable = inlineable;
// the bool returned is whether this expression can be inlined into other crates
// if it's assigned to a static.
-fn const_expr_unadjusted(cx: @CrateContext, e: &ast::Expr,
+fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
is_local: bool) -> (ValueRef, bool) {
let map_list = |exprs: &[@ast::Expr]| {
exprs.iter().map(|&e| const_expr(cx, e, is_local))
}
}
-pub fn trans_const(ccx: @CrateContext, m: ast::Mutability, id: ast::NodeId) {
+pub fn trans_const(ccx: &CrateContext, m: ast::Mutability, id: ast::NodeId) {
unsafe {
let _icx = push_ctxt("trans_const");
let g = base::get_item_val(ccx, id);
self.datum.shallow_copy(self.bcx, dst)
}
- pub fn ccx(&self) -> @CrateContext<'a> {
+ pub fn ccx(&self) -> &'a CrateContext<'a> {
self.bcx.ccx()
}
}
/// Create any deferred debug metadata nodes
-pub fn finalize(cx: @CrateContext) {
+pub fn finalize(cx: &CrateContext) {
if cx.dbg_cx.is_none() {
return;
}
ast::DefStatic(did, _) => {
let const_ty = expr_ty(bcx, ref_expr);
- fn get_did(ccx: @CrateContext, did: ast::DefId)
+ fn get_did(ccx: &CrateContext, did: ast::DefId)
-> ast::DefId {
if did.krate != ast::LOCAL_CRATE {
inline::maybe_instantiate_inline(ccx, did)
}
}
-pub fn register_static(ccx: @CrateContext,
- foreign_item: @ast::ForeignItem) -> ValueRef {
+pub fn register_static(ccx: &CrateContext,
+ foreign_item: &ast::ForeignItem) -> ValueRef {
let ty = ty::node_id_to_type(ccx.tcx, foreign_item.id);
let llty = type_of::type_of(ccx, ty);
// library then we've already declared the crate map
// so use that instead.
if attr::contains_name(foreign_item.attrs.as_slice(), "crate_map") {
- return if ccx.sess.building_library.get() {
+ return if ccx.sess().building_library.get() {
let s = "_rust_crate_map_toplevel";
let g = unsafe {
s.with_c_str(|buf| {
let linkage = match llvm_linkage_by_name(name.get()) {
Some(linkage) => linkage,
None => {
- ccx.sess.span_fatal(foreign_item.span,
- "invalid linkage specified");
+ ccx.sess().span_fatal(foreign_item.span,
+ "invalid linkage specified");
}
};
let llty2 = match ty::get(ty).sty {
ty::ty_ptr(ref mt) => type_of::type_of(ccx, mt.ty),
_ => {
- ccx.sess.span_fatal(foreign_item.span,
- "must have type `*T` or `*mut T`");
+ ccx.sess().span_fatal(foreign_item.span,
+ "must have type `*T` or `*mut T`");
}
};
unsafe {
}
}
-pub fn register_foreign_item_fn(ccx: @CrateContext, abis: AbiSet,
- foreign_item: @ast::ForeignItem) -> ValueRef {
+pub fn register_foreign_item_fn(ccx: &CrateContext, abis: AbiSet,
+ foreign_item: &ast::ForeignItem) -> ValueRef {
/*!
* Registers a foreign function found in a library.
* Just adds a LLVM global.
return bcx;
}
-pub fn trans_foreign_mod(ccx: @CrateContext, foreign_mod: &ast::ForeignMod) {
+pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &ast::ForeignMod) {
let _icx = push_ctxt("foreign::trans_foreign_mod");
for &foreign_item in foreign_mod.items.iter() {
match foreign_item.node {
// inline the one into the other. Of course we could just generate the
// correct code in the first place, but this is much simpler.
-pub fn register_rust_fn_with_foreign_abi(ccx: @CrateContext,
+pub fn register_rust_fn_with_foreign_abi(ccx: &CrateContext,
sp: Span,
sym: ~str,
node_id: ast::NodeId)
llfn
}
-pub fn trans_rust_fn_with_foreign_abi(ccx: @CrateContext,
+pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
decl: &ast::FnDecl,
body: &ast::Block,
attrs: &[ast::Attribute],
return build_wrap_fn(ccx, llrustfn, llwrapfn, &tys);
}
- fn build_rust_fn(ccx: @CrateContext,
+ fn build_rust_fn(ccx: &CrateContext,
decl: &ast::FnDecl,
body: &ast::Block,
attrs: &[ast::Attribute],
llfn
}
- unsafe fn build_wrap_fn(ccx: @CrateContext,
+ unsafe fn build_wrap_fn(ccx: &CrateContext,
llrustfn: ValueRef,
llwrapfn: ValueRef,
tys: &ForeignTypes) {
// This code is kind of a confused mess and needs to be reworked given
// the massive simplifications that have occurred.
-pub fn link_name(i: @ast::ForeignItem) -> InternedString {
+pub fn link_name(i: &ast::ForeignItem) -> InternedString {
match attr::first_attr_value_str_by_name(i.attrs.as_slice(),
"link_name") {
None => token::get_ident(i.ident),
drop_ty(bcx, vp, t)
}
-pub fn get_drop_glue(ccx: @CrateContext, t: ty::t) -> ValueRef {
+pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef {
let t = get_drop_glue_type(ccx, t);
{
let drop_glues = ccx.drop_glues.borrow();
glue
}
-pub fn lazily_emit_visit_glue(ccx: @CrateContext, ti: @tydesc_info) {
+pub fn lazily_emit_visit_glue(ccx: &CrateContext, ti: @tydesc_info) {
let _icx = push_ctxt("lazily_emit_visit_glue");
let llfnty = Type::glue_fn(type_of(ccx, ti.ty).ptr_to());
return llfn;
}
-fn make_generic_glue(ccx: @CrateContext,
+fn make_generic_glue(ccx: &CrateContext,
t: ty::t,
llfn: ValueRef,
helper: <'a> |&'a Block<'a>, ValueRef, ty::t|
llfn
}
-pub fn emit_tydescs(ccx: @CrateContext) {
+pub fn emit_tydescs(ccx: &CrateContext) {
let _icx = push_ctxt("emit_tydescs");
// As of this point, allow no more tydescs to be created.
ccx.finished_tydescs.set(true);
use syntax::ast_util::local_def;
use syntax::attr;
-pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::DefId)
+pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
-> ast::DefId {
let _icx = push_ctxt("maybe_instantiate_inline");
{
use syntax::parse::token;
use util::ppaux::ty_to_str;
-pub fn get_simple_intrinsic(ccx: @CrateContext, item: &ast::ForeignItem) -> Option<ValueRef> {
+pub fn get_simple_intrinsic(ccx: &CrateContext, item: &ast::ForeignItem) -> Option<ValueRef> {
let name = match token::get_ident(item.ident).get() {
"sqrtf32" => "llvm.sqrt.f32",
"sqrtf64" => "llvm.sqrt.f64",
Some(ccx.intrinsics.get_copy(&name))
}
-pub fn trans_intrinsic(ccx: @CrateContext,
+pub fn trans_intrinsic(ccx: &CrateContext,
decl: ValueRef,
item: &ast::ForeignItem,
substs: @param_substs,
be generated once they are invoked with specific type parameters,
see `trans::base::lval_static_fn()` or `trans::base::monomorphic_fn()`.
*/
-pub fn trans_impl(ccx: @CrateContext,
+pub fn trans_impl(ccx: &CrateContext,
name: ast::Ident,
methods: &[@ast::Method],
generics: &ast::Generics,
/// type parameters and so forth, else None
/// * `llfn`: the LLVM ValueRef for the method
///
-pub fn trans_method(ccx: @CrateContext, method: &ast::Method,
+pub fn trans_method(ccx: &CrateContext, method: &ast::Method,
param_substs: Option<@param_substs>,
llfn: ValueRef) -> ValueRef {
trans_fn(ccx, method.decl, method.body,
};
}
-pub fn vtable_id(ccx: @CrateContext,
+pub fn vtable_id(ccx: &CrateContext,
origin: &typeck::vtable_origin)
-> mono_id {
match origin {
use syntax::ast_map;
use syntax::ast_util::local_def;
-pub fn monomorphic_fn(ccx: @CrateContext,
+pub fn monomorphic_fn(ccx: &CrateContext,
fn_id: ast::DefId,
real_substs: &ty::substs,
vtables: Option<typeck::vtable_res>,
(lldecl, must_cast)
}
-pub fn make_mono_id(ccx: @CrateContext,
+pub fn make_mono_id(ccx: &CrateContext,
item: ast::DefId,
substs: ¶m_substs) -> mono_id {
// FIXME (possibly #5801): Need a lot of type hints to get