convert librustc record types to structs
specifically: freevars::freevar_entry ty::{field_ty,AutoAdjustment,AutoRef} mod::{method_param,method_map_entry}
This commit is contained in:
parent
d5d77b9351
commit
28da4ecdaa
@ -930,14 +930,18 @@ fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
|
||||
let item = lookup_item(id, data);
|
||||
let mut result = ~[];
|
||||
for reader::tagged_docs(item, tag_item_field) |an_item| {
|
||||
let f = item_family(an_item);
|
||||
if f == PublicField || f == PrivateField || f == InheritedField {
|
||||
let name = item_name(intr, an_item);
|
||||
let did = item_def_id(an_item, cdata);
|
||||
let mt = field_mutability(an_item);
|
||||
result.push({ident: name, id: did, vis:
|
||||
family_to_visibility(f), mutability: mt});
|
||||
}
|
||||
let f = item_family(an_item);
|
||||
if f == PublicField || f == PrivateField || f == InheritedField {
|
||||
let name = item_name(intr, an_item);
|
||||
let did = item_def_id(an_item, cdata);
|
||||
let mt = field_mutability(an_item);
|
||||
result.push(ty::field_ty {
|
||||
ident: name,
|
||||
id: did, vis:
|
||||
family_to_visibility(f),
|
||||
mutability: mt,
|
||||
});
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
@ -448,16 +448,20 @@ impl ast::def: tr {
|
||||
|
||||
impl ty::AutoAdjustment: tr {
|
||||
fn tr(xcx: extended_decode_ctxt) -> ty::AutoAdjustment {
|
||||
{autoderefs: self.autoderefs,
|
||||
autoref: self.autoref.map(|ar| ar.tr(xcx))}
|
||||
ty::AutoAdjustment {
|
||||
autoderefs: self.autoderefs,
|
||||
autoref: self.autoref.map(|ar| ar.tr(xcx)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ty::AutoRef: tr {
|
||||
fn tr(xcx: extended_decode_ctxt) -> ty::AutoRef {
|
||||
{kind: self.kind,
|
||||
region: self.region.tr(xcx),
|
||||
mutbl: self.mutbl}
|
||||
ty::AutoRef {
|
||||
kind: self.kind,
|
||||
region: self.region.tr(xcx),
|
||||
mutbl: self.mutbl,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -503,7 +507,10 @@ impl reader::Decoder: ebml_decoder_helper {
|
||||
|
||||
impl freevar_entry: tr {
|
||||
fn tr(xcx: extended_decode_ctxt) -> freevar_entry {
|
||||
{def: self.def.tr(xcx), span: self.span.tr(xcx)}
|
||||
freevar_entry {
|
||||
def: self.def.tr(xcx),
|
||||
span: self.span.tr(xcx),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -533,21 +540,20 @@ fn encode_method_map_entry(ecx: @e::encode_ctxt,
|
||||
impl reader::Decoder: read_method_map_entry_helper {
|
||||
fn read_method_map_entry(xcx: extended_decode_ctxt) -> method_map_entry {
|
||||
do self.read_rec {
|
||||
{self_arg:
|
||||
self.read_field(~"self_arg", 0u, || {
|
||||
self.read_arg(xcx)
|
||||
}),
|
||||
explicit_self:
|
||||
self.read_field(~"explicit_self", 2u, || {
|
||||
method_map_entry {
|
||||
self_arg: self.read_field(~"self_arg", 0u, || {
|
||||
self.read_arg(xcx)
|
||||
}),
|
||||
explicit_self: self.read_field(~"explicit_self", 2u, || {
|
||||
let self_type: ast::self_ty_ = Decodable::decode(&self);
|
||||
self_type
|
||||
}),
|
||||
origin:
|
||||
self.read_field(~"origin", 1u, || {
|
||||
let method_origin: method_origin =
|
||||
Decodable::decode(&self);
|
||||
method_origin.tr(xcx)
|
||||
})}
|
||||
}),
|
||||
origin: self.read_field(~"origin", 1u, || {
|
||||
let method_origin: method_origin =
|
||||
Decodable::decode(&self);
|
||||
method_origin.tr(xcx)
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -559,7 +565,12 @@ impl method_origin: tr {
|
||||
typeck::method_static(did.tr(xcx))
|
||||
}
|
||||
typeck::method_param(ref mp) => {
|
||||
typeck::method_param({trait_id:(*mp).trait_id.tr(xcx),.. (*mp)})
|
||||
typeck::method_param(
|
||||
typeck::method_param {
|
||||
trait_id: mp.trait_id.tr(xcx),
|
||||
.. *mp
|
||||
}
|
||||
)
|
||||
}
|
||||
typeck::method_trait(did, m, vstore) => {
|
||||
typeck::method_trait(did.tr(xcx), m, vstore)
|
||||
|
@ -34,10 +34,10 @@ export has_freevars;
|
||||
// (The def_upvar will already have been stripped).
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
type freevar_entry = {
|
||||
struct freevar_entry {
|
||||
def: ast::def, //< The variable being accessed free.
|
||||
span: span //< First span where it is accessed (there can be multiple)
|
||||
};
|
||||
}
|
||||
type freevar_info = @~[@freevar_entry];
|
||||
type freevar_map = HashMap<ast::node_id, freevar_info>;
|
||||
|
||||
@ -79,7 +79,10 @@ fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk)
|
||||
if i == depth { // Made it to end of loop
|
||||
let dnum = ast_util::def_id_of_def(def).node;
|
||||
if !seen.contains_key(dnum) {
|
||||
refs.push(@{def:def, span:expr.span});
|
||||
refs.push(@freevar_entry {
|
||||
def: def,
|
||||
span: expr.span,
|
||||
});
|
||||
seen.insert(dnum, ());
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,11 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
|
||||
// XXX: External crates.
|
||||
}
|
||||
}
|
||||
method_param({trait_id: trait_id, method_num: method_num, _}) |
|
||||
method_param(method_param {
|
||||
trait_id: trait_id,
|
||||
method_num: method_num,
|
||||
_
|
||||
}) |
|
||||
method_trait(trait_id, method_num, _) |
|
||||
method_self(trait_id, method_num) => {
|
||||
if trait_id.crate == local_crate {
|
||||
|
@ -209,8 +209,12 @@ fn trans_method_callee(bcx: block, callee_id: ast::node_id,
|
||||
})
|
||||
}
|
||||
}
|
||||
typeck::method_param({trait_id:trait_id, method_num:off,
|
||||
param_num:p, bound_num:b}) => {
|
||||
typeck::method_param(typeck::method_param {
|
||||
trait_id: trait_id,
|
||||
method_num: off,
|
||||
param_num: p,
|
||||
bound_num: b
|
||||
}) => {
|
||||
match bcx.fcx.param_substs {
|
||||
Some(ref substs) => {
|
||||
let vtbl = base::find_vtable(bcx.tcx(), substs, p, b);
|
||||
|
@ -182,7 +182,10 @@ fn traverse_inline_body(cx: ctx, body: blk) {
|
||||
}
|
||||
expr_field(_, _, _) => {
|
||||
match cx.method_map.find(e.id) {
|
||||
Some({origin: typeck::method_static(did), _}) => {
|
||||
Some(typeck::method_map_entry {
|
||||
origin: typeck::method_static(did),
|
||||
_
|
||||
}) => {
|
||||
traverse_def_id(cx, did);
|
||||
}
|
||||
_ => ()
|
||||
@ -190,7 +193,10 @@ fn traverse_inline_body(cx: ctx, body: blk) {
|
||||
}
|
||||
expr_method_call(*) => {
|
||||
match cx.method_map.find(e.id) {
|
||||
Some({origin: typeck::method_static(did), _}) => {
|
||||
Some(typeck::method_map_entry {
|
||||
origin: typeck::method_static(did),
|
||||
_
|
||||
}) => {
|
||||
traverse_def_id(cx, did);
|
||||
}
|
||||
Some(_) => {}
|
||||
|
@ -233,7 +233,10 @@ fn mark_for_method_call(cx: ctx, e_id: node_id, callee_id: node_id) {
|
||||
}
|
||||
}
|
||||
}
|
||||
typeck::method_param({param_num: param, _}) => {
|
||||
typeck::method_param(typeck::method_param {
|
||||
param_num: param,
|
||||
_
|
||||
}) => {
|
||||
cx.uses[param] |= use_tydesc;
|
||||
}
|
||||
typeck::method_trait(*) | typeck::method_self(*) => (),
|
||||
|
@ -272,12 +272,12 @@ enum vstore {
|
||||
vstore_slice(Region)
|
||||
}
|
||||
|
||||
type field_ty = {
|
||||
struct field_ty {
|
||||
ident: ident,
|
||||
id: def_id,
|
||||
vis: ast::visibility,
|
||||
mutability: ast::struct_mutability
|
||||
};
|
||||
mutability: ast::struct_mutability,
|
||||
}
|
||||
|
||||
/// How an lvalue is to be used.
|
||||
#[auto_encode]
|
||||
@ -356,18 +356,18 @@ impl region_variance : cmp::Eq {
|
||||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
pub type AutoAdjustment = {
|
||||
pub struct AutoAdjustment {
|
||||
autoderefs: uint,
|
||||
autoref: Option<AutoRef>
|
||||
};
|
||||
}
|
||||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
pub type AutoRef = {
|
||||
pub struct AutoRef {
|
||||
kind: AutoRefKind,
|
||||
region: Region,
|
||||
mutbl: ast::mutability
|
||||
};
|
||||
}
|
||||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
@ -3086,8 +3086,9 @@ fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map,
|
||||
// and then the method bounds themselves...
|
||||
ty::lookup_item_type(tcx, did).bounds
|
||||
}
|
||||
typeck::method_param({trait_id:trt_id,
|
||||
method_num:n_mth, _}) |
|
||||
typeck::method_param(typeck::method_param {
|
||||
trait_id: trt_id,
|
||||
method_num: n_mth, _}) |
|
||||
typeck::method_trait(trt_id, n_mth, _) |
|
||||
typeck::method_self(trt_id, n_mth) => {
|
||||
// ...trait methods bounds, in contrast, include only the
|
||||
@ -4075,25 +4076,27 @@ pure fn is_public(f: field_ty) -> bool {
|
||||
}
|
||||
|
||||
fn struct_field_tys(fields: ~[@struct_field]) -> ~[field_ty] {
|
||||
let mut rslt = ~[];
|
||||
for fields.each |field| {
|
||||
do fields.map |field| {
|
||||
match field.node.kind {
|
||||
named_field(ident, mutability, visibility) => {
|
||||
rslt.push({ident: ident,
|
||||
id: ast_util::local_def(field.node.id),
|
||||
vis: visibility,
|
||||
mutability: mutability});
|
||||
field_ty {
|
||||
ident: ident,
|
||||
id: ast_util::local_def(field.node.id),
|
||||
vis: visibility,
|
||||
mutability: mutability,
|
||||
}
|
||||
}
|
||||
unnamed_field => {
|
||||
rslt.push({ident:
|
||||
syntax::parse::token::special_idents::unnamed_field,
|
||||
id: ast_util::local_def(field.node.id),
|
||||
vis: ast::public,
|
||||
mutability: ast::struct_immutable});
|
||||
field_ty {
|
||||
ident:
|
||||
syntax::parse::token::special_idents::unnamed_field,
|
||||
id: ast_util::local_def(field.node.id),
|
||||
vis: ast::public,
|
||||
mutability: ast::struct_immutable,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rslt
|
||||
}
|
||||
|
||||
// Return a list of fields corresponding to the struct's items
|
||||
|
@ -455,10 +455,13 @@ impl LookupContext {
|
||||
explicit_self: method.self_ty,
|
||||
num_method_tps: method.tps.len(),
|
||||
self_mode: get_mode_from_self_type(method.self_ty),
|
||||
origin: method_param({trait_id:init_trait_id,
|
||||
method_num:pos,
|
||||
param_num:param_ty.idx,
|
||||
bound_num:this_bound_idx})
|
||||
origin: method_param(
|
||||
method_param {
|
||||
trait_id: init_trait_id,
|
||||
method_num: pos,
|
||||
param_num: param_ty.idx,
|
||||
bound_num: this_bound_idx,
|
||||
})
|
||||
};
|
||||
|
||||
debug!("pushing inherent candidate for param: %?", cand);
|
||||
@ -834,10 +837,14 @@ impl LookupContext {
|
||||
Some(move mme) => {
|
||||
self.fcx.write_adjustment(
|
||||
self.self_expr.id,
|
||||
@{autoderefs: autoderefs,
|
||||
autoref: Some({kind: kind,
|
||||
region: region,
|
||||
mutbl: *mutbl})});
|
||||
@ty::AutoAdjustment {
|
||||
autoderefs: autoderefs,
|
||||
autoref: Some(ty::AutoRef {
|
||||
kind: kind,
|
||||
region: region,
|
||||
mutbl: *mutbl,
|
||||
}),
|
||||
});
|
||||
return Some(mme);
|
||||
}
|
||||
}
|
||||
@ -1004,10 +1011,14 @@ impl LookupContext {
|
||||
};
|
||||
|
||||
self.fcx.write_ty_substs(self.callee_id, fty, all_substs);
|
||||
return {self_arg: {mode: ast::expl(candidate.self_mode),
|
||||
ty: candidate.rcvr_ty},
|
||||
explicit_self: candidate.explicit_self,
|
||||
origin: candidate.origin};
|
||||
method_map_entry {
|
||||
self_arg: {
|
||||
mode: ast::expl(candidate.self_mode),
|
||||
ty: candidate.rcvr_ty,
|
||||
},
|
||||
explicit_self: candidate.explicit_self,
|
||||
origin: candidate.origin,
|
||||
}
|
||||
}
|
||||
|
||||
fn enforce_trait_instance_limitations(&self,
|
||||
@ -1050,7 +1061,7 @@ impl LookupContext {
|
||||
method_static(method_id) | method_self(method_id, _) => {
|
||||
bad = self.tcx().destructors.contains_key(method_id);
|
||||
}
|
||||
method_param({trait_id: trait_id, _}) |
|
||||
method_param(method_param { trait_id: trait_id, _ }) |
|
||||
method_trait(trait_id, _, _) => {
|
||||
bad = self.tcx().destructor_for_type.contains_key(trait_id);
|
||||
}
|
||||
|
@ -730,7 +730,10 @@ impl @fn_ctxt {
|
||||
|
||||
fn write_autoderef_adjustment(node_id: ast::node_id, derefs: uint) {
|
||||
if derefs == 0 { return; }
|
||||
self.write_adjustment(node_id, @{autoderefs: derefs, autoref: None});
|
||||
self.write_adjustment(
|
||||
node_id,
|
||||
@ty::AutoAdjustment { autoderefs: derefs, autoref: None }
|
||||
);
|
||||
}
|
||||
|
||||
fn write_adjustment(node_id: ast::node_id, adj: @ty::AutoAdjustment) {
|
||||
|
@ -324,7 +324,9 @@ fn constrain_auto_ref(
|
||||
|
||||
let adjustment = rcx.fcx.inh.adjustments.find(expr.id);
|
||||
let region = match adjustment {
|
||||
Some(@{autoref: Some(ref auto_ref), _}) => auto_ref.region,
|
||||
Some(@ty::AutoAdjustment { autoref: Some(ref auto_ref), _ }) => {
|
||||
auto_ref.region
|
||||
},
|
||||
_ => { return; }
|
||||
};
|
||||
|
||||
|
@ -20,6 +20,7 @@ use middle::typeck::check::{fn_ctxt, lookup_local, self_info};
|
||||
use middle::typeck::infer::{force_all, resolve_all, resolve_region};
|
||||
use middle::typeck::infer::{resolve_type};
|
||||
use middle::typeck::infer;
|
||||
use middle::typeck::method_map_entry;
|
||||
use middle::typeck::{vtable_param, vtable_trait, write_substs_to_tcx};
|
||||
use middle::typeck::{write_ty_to_tcx};
|
||||
use util::ppaux;
|
||||
@ -63,8 +64,11 @@ fn resolve_method_map_entry(fcx: @fn_ctxt, sp: span, id: ast::node_id)
|
||||
for resolve_type_vars_in_type(fcx, sp, mme.self_arg.ty).each |t| {
|
||||
fcx.ccx.method_map.insert(
|
||||
id,
|
||||
{self_arg: {mode: mme.self_arg.mode, ty: *t},
|
||||
..*mme});
|
||||
method_map_entry {
|
||||
self_arg: {mode: mme.self_arg.mode, ty: *t},
|
||||
.. *mme
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,14 +95,16 @@ fn resolve_type_vars_for_node(wbcx: wb_ctxt, sp: span, id: ast::node_id)
|
||||
Some(*autoref)
|
||||
}
|
||||
Ok(r) => {
|
||||
Some({region: r, ..*autoref})
|
||||
Some(ty::AutoRef {region: r, ..*autoref})
|
||||
}
|
||||
}
|
||||
}
|
||||
None => None
|
||||
};
|
||||
|
||||
let resolved_adj = @{autoref: resolved_autoref, ..*adj};
|
||||
let resolved_adj = @ty::AutoAdjustment {
|
||||
autoref: resolved_autoref,
|
||||
..*adj};
|
||||
debug!("Adjustments for node %d: %?", id, resolved_adj);
|
||||
fcx.tcx().adjustments.insert(id, resolved_adj);
|
||||
}
|
||||
|
@ -275,9 +275,9 @@ priv impl Assign {
|
||||
do sub.tys(a, nr_b).chain |_t| {
|
||||
let r_a = self.infcx.next_region_var_nb(self.span);
|
||||
do sub.contraregions(r_a, r_b).chain |_r| {
|
||||
Ok(Some(@{
|
||||
Ok(Some(@ty::AutoAdjustment {
|
||||
autoderefs: autoderefs,
|
||||
autoref: Some({
|
||||
autoref: Some(ty::AutoRef {
|
||||
kind: kind,
|
||||
region: r_a,
|
||||
mutbl: m
|
||||
|
@ -142,7 +142,7 @@ pub enum method_origin {
|
||||
// with a bounded trait.
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
type method_param = {
|
||||
struct method_param {
|
||||
// the trait containing the method to be invoked
|
||||
trait_id: ast::def_id,
|
||||
|
||||
@ -154,10 +154,10 @@ type method_param = {
|
||||
param_num: uint,
|
||||
|
||||
// index of the bound for this type parameter which specifies the trait
|
||||
bound_num: uint
|
||||
};
|
||||
bound_num: uint,
|
||||
}
|
||||
|
||||
pub type method_map_entry = {
|
||||
pub struct method_map_entry {
|
||||
// the type and mode of the self parameter, which is not reflected
|
||||
// in the fn type (FIXME #3446)
|
||||
self_arg: ty::arg,
|
||||
@ -166,8 +166,8 @@ pub type method_map_entry = {
|
||||
explicit_self: ast::self_ty_,
|
||||
|
||||
// method details being invoked
|
||||
origin: method_origin
|
||||
};
|
||||
origin: method_origin,
|
||||
}
|
||||
|
||||
// maps from an expression id that corresponds to a method call to the details
|
||||
// of the method to be invoked
|
||||
|
Loading…
x
Reference in New Issue
Block a user