Convert ast::def_id into a struct.
This commit is contained in:
parent
bea67bde21
commit
df7d376d25
@ -218,13 +218,15 @@ fn item_parent_item(d: ebml::Doc) -> Option<ast::def_id> {
|
||||
fn translated_parent_item_opt(cnum: ast::crate_num, d: ebml::Doc) ->
|
||||
Option<ast::def_id> {
|
||||
let trait_did_opt = item_parent_item(d);
|
||||
trait_did_opt.map(|trait_did| {crate: cnum, node: trait_did.node})
|
||||
do trait_did_opt.map |trait_did| {
|
||||
ast::def_id { crate: cnum, node: trait_did.node }
|
||||
}
|
||||
}
|
||||
|
||||
fn item_reqd_and_translated_parent_item(cnum: ast::crate_num,
|
||||
d: ebml::Doc) -> ast::def_id {
|
||||
let trait_did = item_parent_item(d).expect(~"item without parent");
|
||||
{crate: cnum, node: trait_did.node}
|
||||
ast::def_id { crate: cnum, node: trait_did.node }
|
||||
}
|
||||
|
||||
fn item_def_id(d: ebml::Doc, cdata: cmd) -> ast::def_id {
|
||||
@ -313,7 +315,7 @@ fn enum_variant_ids(item: ebml::Doc, cdata: cmd) -> ~[ast::def_id] {
|
||||
let v = tag_items_data_item_variant;
|
||||
for reader::tagged_docs(item, v) |p| {
|
||||
let ext = reader::with_doc_data(p, |d| parse_def_id(d));
|
||||
ids.push({crate: cdata.cnum, node: ext.node});
|
||||
ids.push(ast::def_id { crate: cdata.cnum, node: ext.node });
|
||||
};
|
||||
return ids;
|
||||
}
|
||||
@ -384,7 +386,7 @@ fn item_to_def_like(item: ebml::Doc, did: ast::def_id, cnum: ast::crate_num)
|
||||
fn lookup_def(cnum: ast::crate_num, data: @~[u8], did_: ast::def_id) ->
|
||||
ast::def {
|
||||
let item = lookup_item(did_.node, data);
|
||||
let did = {crate: cnum, node: did_.node};
|
||||
let did = ast::def_id { crate: cnum, node: did_.node };
|
||||
// We treat references to enums as references to types.
|
||||
return def_like_to_def(item_to_def_like(item, did, cnum));
|
||||
}
|
||||
@ -393,7 +395,8 @@ fn get_type(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
|
||||
-> ty::ty_param_bounds_and_ty {
|
||||
|
||||
let item = lookup_item(id, cdata.data);
|
||||
let t = item_type({crate: cdata.cnum, node: id}, item, tcx, cdata);
|
||||
let t = item_type(ast::def_id { crate: cdata.cnum, node: id }, item, tcx,
|
||||
cdata);
|
||||
let tp_bounds = if family_has_type_params(item_family(item)) {
|
||||
item_ty_param_bounds(item, tcx, cdata)
|
||||
} else { @~[] };
|
||||
@ -640,8 +643,8 @@ fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id,
|
||||
let mut disr_val = 0;
|
||||
for variant_ids.each |did| {
|
||||
let item = find_item(did.node, items);
|
||||
let ctor_ty = item_type({crate: cdata.cnum, node: id}, item,
|
||||
tcx, cdata);
|
||||
let ctor_ty = item_type(ast::def_id { crate: cdata.cnum, node: id},
|
||||
item, tcx, cdata);
|
||||
let name = item_name(intr, item);
|
||||
let arg_tys = match ty::get(ctor_ty).sty {
|
||||
ty::ty_fn(ref f) => (*f).sig.inputs.map(|a| a.ty),
|
||||
@ -1141,11 +1144,11 @@ fn list_crate_metadata(intr: @ident_interner, bytes: @~[u8],
|
||||
// crate to the correct local crate number.
|
||||
fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id {
|
||||
if did.crate == ast::local_crate {
|
||||
return {crate: cdata.cnum, node: did.node};
|
||||
return ast::def_id { crate: cdata.cnum, node: did.node };
|
||||
}
|
||||
|
||||
match cdata.cnum_map.find(did.crate) {
|
||||
option::Some(n) => return {crate: n, node: did.node},
|
||||
option::Some(n) => ast::def_id { crate: n, node: did.node },
|
||||
option::None => fail ~"didn't find a crate in the cnum_map"
|
||||
}
|
||||
}
|
||||
|
@ -273,7 +273,8 @@ fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: writer::Encoder,
|
||||
ty_params: ~[ty_param]) {
|
||||
let mut disr_val = 0;
|
||||
let mut i = 0;
|
||||
let vi = ty::enum_variants(ecx.tcx, {crate: local_crate, node: id});
|
||||
let vi = ty::enum_variants(ecx.tcx,
|
||||
ast::def_id { crate: local_crate, node: id });
|
||||
for variants.each |variant| {
|
||||
index.push({val: variant.node.id, pos: ebml_w.writer.tell()});
|
||||
ebml_w.start_tag(tag_items_data_item);
|
||||
|
@ -470,7 +470,7 @@ fn parse_def_id(buf: &[u8]) -> ast::def_id {
|
||||
None => fail (fmt!("internal error: parse_def_id: id expected, but \
|
||||
found %?", def_part))
|
||||
};
|
||||
return {crate: crate_num, node: def_num};
|
||||
ast::def_id { crate: crate_num, node: def_num }
|
||||
}
|
||||
|
||||
fn parse_bounds_data(data: @~[u8], start: uint,
|
||||
|
@ -176,7 +176,7 @@ fn tr_def_id(did: ast::def_id) -> ast::def_id {
|
||||
}
|
||||
fn tr_intern_def_id(did: ast::def_id) -> ast::def_id {
|
||||
assert did.crate == ast::local_crate;
|
||||
{crate: ast::local_crate, node: self.tr_id(did.node)}
|
||||
ast::def_id { crate: ast::local_crate, node: self.tr_id(did.node) }
|
||||
}
|
||||
fn tr_span(_span: span) -> span {
|
||||
ast_util::dummy_sp() // FIXME (#1972): handle span properly
|
||||
@ -785,7 +785,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
|
||||
}
|
||||
}
|
||||
|
||||
let lid = {crate: ast::local_crate, node: id};
|
||||
let lid = ast::def_id { crate: ast::local_crate, node: id };
|
||||
do option::iter(&tcx.tcache.find(lid)) |tpbt| {
|
||||
do ebml_w.tag(c::tag_table_tcache) {
|
||||
ebml_w.id(id);
|
||||
@ -988,7 +988,7 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
|
||||
dcx.tcx.freevars.insert(id, fv_info);
|
||||
} else if tag == (c::tag_table_tcache as uint) {
|
||||
let tpbt = val_dsr.read_ty_param_bounds_and_ty(xcx);
|
||||
let lid = {crate: ast::local_crate, node: id};
|
||||
let lid = ast::def_id { crate: ast::local_crate, node: id };
|
||||
dcx.tcx.tcache.insert(lid, tpbt);
|
||||
} else if tag == (c::tag_table_param_bounds as uint) {
|
||||
let bounds = val_dsr.read_bounds(xcx);
|
||||
|
@ -359,7 +359,7 @@ fn collect_external_language_items() {
|
||||
do iter_crate_data(crate_store) |crate_number, _crate_metadata| {
|
||||
for each_lang_item(crate_store, crate_number)
|
||||
|node_id, item_index| {
|
||||
let def_id = { crate: crate_number, node: node_id };
|
||||
let def_id = def_id { crate: crate_number, node: node_id };
|
||||
self.collect_item(item_index, def_id);
|
||||
}
|
||||
}
|
||||
|
@ -817,7 +817,7 @@ fn Resolver(session: Session, lang_items: LanguageItems,
|
||||
|
||||
(*graph_root).define_module(Public,
|
||||
NoParentLink,
|
||||
Some({ crate: 0, node: 0 }),
|
||||
Some(def_id { crate: 0, node: 0 }),
|
||||
NormalModuleKind,
|
||||
has_legacy_export_attr(crate.node.attrs),
|
||||
crate.span);
|
||||
@ -1148,7 +1148,7 @@ fn build_reduced_graph_for_item(item: @item,
|
||||
self.add_child(ident, parent, ForbidDuplicateModules, sp);
|
||||
|
||||
let parent_link = self.get_parent_link(new_parent, ident);
|
||||
let def_id = { crate: 0, node: item.id };
|
||||
let def_id = def_id { crate: 0, node: item.id };
|
||||
(*name_bindings).define_module(privacy,
|
||||
parent_link,
|
||||
Some(def_id),
|
||||
@ -1172,7 +1172,7 @@ fn build_reduced_graph_for_item(item: @item,
|
||||
|
||||
let parent_link = self.get_parent_link(new_parent,
|
||||
ident);
|
||||
let def_id = { crate: 0, node: item.id };
|
||||
let def_id = def_id { crate: 0, node: item.id };
|
||||
(*name_bindings).define_module(privacy,
|
||||
parent_link,
|
||||
Some(def_id),
|
||||
@ -1609,7 +1609,7 @@ fn build_reduced_graph_for_view_item(view_item: @view_item,
|
||||
self.add_child(name, parent, ForbidDuplicateTypes,
|
||||
view_item.span);
|
||||
|
||||
let def_id = { crate: crate_id, node: 0 };
|
||||
let def_id = def_id { crate: crate_id, node: 0 };
|
||||
let parent_link = ModuleParentLink
|
||||
(self.get_module_from_parent(new_parent), name);
|
||||
|
||||
|
@ -2498,8 +2498,9 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item) {
|
||||
let _icx = ccx.insn_ctxt("trans_constant");
|
||||
match it.node {
|
||||
ast::item_enum(ref enum_definition, _) => {
|
||||
let vi = ty::enum_variants(ccx.tcx, {crate: ast::local_crate,
|
||||
node: it.id});
|
||||
let vi = ty::enum_variants(ccx.tcx,
|
||||
ast::def_id { crate: ast::local_crate,
|
||||
node: it.id });
|
||||
let mut i = 0;
|
||||
let path = item_path(ccx, it);
|
||||
for vec::each((*enum_definition).variants) |variant| {
|
||||
|
@ -928,7 +928,8 @@ fn add_external_crates() {
|
||||
do iter_crate_data(crate_store) |crate_number, _crate_metadata| {
|
||||
self.add_impls_for_module(impls_seen,
|
||||
crate_store,
|
||||
{ crate: crate_number, node: 0 });
|
||||
def_id { crate: crate_number,
|
||||
node: 0 });
|
||||
|
||||
for each_path(crate_store, crate_number) |path_entry| {
|
||||
match path_entry.def_like {
|
||||
|
@ -73,7 +73,7 @@ fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) {
|
||||
match /*bad*/copy crate_item.node {
|
||||
ast::item_mod(m) => {
|
||||
for m.items.each |intrinsic_item| {
|
||||
let def_id = { crate: ast::local_crate,
|
||||
let def_id = ast::def_id { crate: ast::local_crate,
|
||||
node: intrinsic_item.id };
|
||||
let substs = {self_r: None, self_ty: None, tps: ~[]};
|
||||
|
||||
@ -254,7 +254,7 @@ fn make_static_method_ty(ccx: @crate_ctxt,
|
||||
// build up a subst that shifts all of the parameters over
|
||||
// by one and substitute in a new type param for self
|
||||
|
||||
let dummy_defid = {crate: 0, node: 0};
|
||||
let dummy_defid = ast::def_id {crate: 0, node: 0};
|
||||
|
||||
let non_shifted_trait_tps = do vec::from_fn(trait_bounds.len()) |i| {
|
||||
ty::mk_param(ccx.tcx, i, dummy_defid)
|
||||
@ -458,7 +458,7 @@ fn compare_impl_method(tcx: ty::ctxt,
|
||||
let dummy_tps = do vec::from_fn((*trait_m.tps).len()) |i| {
|
||||
// hack: we don't know the def id of the impl tp, but it
|
||||
// is not important for unification
|
||||
ty::mk_param(tcx, i + impl_tps, {crate: 0, node: 0})
|
||||
ty::mk_param(tcx, i + impl_tps, ast::def_id {crate: 0, node: 0})
|
||||
};
|
||||
let trait_tps = trait_substs.tps.map(
|
||||
|t| replace_bound_self(tcx, *t, dummy_self_r));
|
||||
|
@ -93,7 +93,10 @@ struct path {
|
||||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
type def_id = {crate: crate_num, node: node_id};
|
||||
struct def_id {
|
||||
crate: crate_num,
|
||||
node: node_id,
|
||||
}
|
||||
|
||||
impl def_id : cmp::Eq {
|
||||
pure fn eq(&self, other: &def_id) -> bool {
|
||||
|
@ -54,7 +54,9 @@
|
||||
|
||||
pure fn path_to_ident(p: @path) -> ident { vec::last(p.idents) }
|
||||
|
||||
pure fn local_def(id: node_id) -> def_id { {crate: local_crate, node: id} }
|
||||
pure fn local_def(id: node_id) -> def_id {
|
||||
ast::def_id { crate: local_crate, node: id }
|
||||
}
|
||||
|
||||
pure fn is_local(did: ast::def_id) -> bool { did.crate == local_crate }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user