Skip to content

Commit

Permalink
Use Names in HIR Items
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Sep 22, 2015
1 parent ae77dbb commit a4af958
Show file tree
Hide file tree
Showing 35 changed files with 206 additions and 205 deletions.
18 changes: 9 additions & 9 deletions src/librustc/front/map/blocks.rs
Expand Up @@ -26,7 +26,7 @@ pub use self::Code::*;
use front::map::{self, Node};
use syntax::abi;
use rustc_front::hir::{Block, FnDecl};
use syntax::ast::{NodeId, Ident};
use syntax::ast::{Name, NodeId};
use rustc_front::hir as ast;
use syntax::codemap::Span;
use rustc_front::visit::FnKind;
Expand Down Expand Up @@ -107,7 +107,7 @@ impl<'a> Code<'a> {
/// These are all the components one can extract from a fn item for
/// use when implementing FnLikeNode operations.
struct ItemFnParts<'a> {
ident: Ident,
name: Name,
decl: &'a ast::FnDecl,
unsafety: ast::Unsafety,
constness: ast::Constness,
Expand Down Expand Up @@ -189,21 +189,21 @@ impl<'a> FnLikeNode<'a> {

pub fn kind(self) -> FnKind<'a> {
let item = |p: ItemFnParts<'a>| -> FnKind<'a> {
FnKind::ItemFn(p.ident.name, p.generics, p.unsafety, p.constness, p.abi, p.vis)
FnKind::ItemFn(p.name, p.generics, p.unsafety, p.constness, p.abi, p.vis)
};
let closure = |_: ClosureParts| {
FnKind::Closure
};
let method = |_, ident: Ident, sig: &'a ast::MethodSig, vis, _, _| {
FnKind::Method(ident.name, sig, vis)
let method = |_, name: Name, sig: &'a ast::MethodSig, vis, _, _| {
FnKind::Method(name, sig, vis)
};
self.handle(item, method, closure)
}

fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
I: FnOnce(ItemFnParts<'a>) -> A,
M: FnOnce(NodeId,
Ident,
Name,
&'a ast::MethodSig,
Option<ast::Visibility>,
&'a ast::Block,
Expand All @@ -216,7 +216,7 @@ impl<'a> FnLikeNode<'a> {
ast::ItemFn(ref decl, unsafety, constness, abi, ref generics, ref block) =>
item_fn(ItemFnParts {
id: i.id,
ident: i.ident,
name: i.name,
decl: &**decl,
unsafety: unsafety,
body: &**block,
Expand All @@ -230,14 +230,14 @@ impl<'a> FnLikeNode<'a> {
},
map::NodeTraitItem(ti) => match ti.node {
ast::MethodTraitItem(ref sig, Some(ref body)) => {
method(ti.id, ti.ident, sig, None, body, ti.span)
method(ti.id, ti.name, sig, None, body, ti.span)
}
_ => panic!("trait method FnLikeNode that is not fn-like"),
},
map::NodeImplItem(ii) => {
match ii.node {
ast::MethodImplItem(ref sig, ref body) => {
method(ii.id, ii.ident, sig, Some(ii.vis), body, ii.span)
method(ii.id, ii.name, sig, Some(ii.vis), body, ii.span)
}
_ => {
panic!("impl method FnLikeNode that is not fn-like")
Expand Down
38 changes: 19 additions & 19 deletions src/librustc/front/map/mod.rs
Expand Up @@ -17,7 +17,7 @@ use metadata::inline::InlinedItem as II;
use middle::def_id::DefId;

use syntax::abi;
use syntax::ast::{self, Name, NodeId, Ident, CRATE_NODE_ID, DUMMY_NODE_ID};
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID, DUMMY_NODE_ID};
use syntax::codemap::{Span, Spanned};
use syntax::parse::token;

Expand Down Expand Up @@ -475,14 +475,14 @@ impl<'ast> Map<'ast> {
NodeItem(item) => {
match item.node {
ItemMod(_) | ItemForeignMod(_) => {
PathMod(item.ident.name)
PathMod(item.name)
}
_ => PathName(item.ident.name)
_ => PathName(item.name)
}
}
NodeForeignItem(i) => PathName(i.ident.name),
NodeImplItem(ii) => PathName(ii.ident.name),
NodeTraitItem(ti) => PathName(ti.ident.name),
NodeForeignItem(i) => PathName(i.name),
NodeImplItem(ii) => PathName(ii.name),
NodeTraitItem(ti) => PathName(ti.name),
NodeVariant(v) => PathName(v.node.name.name),
NodeLifetime(lt) => PathName(lt.name),
_ => panic!("no path elem for {:?}", node)
Expand All @@ -499,9 +499,9 @@ impl<'ast> Map<'ast> {
self.with_path(id, |path| path_to_string(path))
}

fn path_to_str_with_ident(&self, id: NodeId, i: Ident) -> String {
fn path_to_str_with_name(&self, id: NodeId, name: Name) -> String {
self.with_path(id, |path| {
path_to_string(path.chain(Some(PathName(i.name))))
path_to_string(path.chain(Some(PathName(name))))
})
}

Expand Down Expand Up @@ -652,7 +652,7 @@ impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> {
match map.find(id) {
None => return None,
Some(NodeItem(item)) if item_is_mod(&*item) =>
return Some((id, item.ident.name)),
return Some((id, item.name)),
_ => {}
}
let parent = map.get_parent(id);
Expand Down Expand Up @@ -708,11 +708,11 @@ trait Named {

impl<T:Named> Named for Spanned<T> { fn name(&self) -> Name { self.node.name() } }

impl Named for Item { fn name(&self) -> Name { self.ident.name } }
impl Named for ForeignItem { fn name(&self) -> Name { self.ident.name } }
impl Named for Item { fn name(&self) -> Name { self.name } }
impl Named for ForeignItem { fn name(&self) -> Name { self.name } }
impl Named for Variant_ { fn name(&self) -> Name { self.name.name } }
impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
impl Named for TraitItem { fn name(&self) -> Name { self.name } }
impl Named for ImplItem { fn name(&self) -> Name { self.name } }

pub trait FoldOps {
fn new_id(&self, id: NodeId) -> NodeId {
Expand Down Expand Up @@ -1040,7 +1040,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {

match map.find(id) {
Some(NodeItem(item)) => {
let path_str = map.path_to_str_with_ident(id, item.ident);
let path_str = map.path_to_str_with_name(id, item.name);
let item_str = match item.node {
ItemExternCrate(..) => "extern crate",
ItemUse(..) => "use",
Expand All @@ -1059,25 +1059,25 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
format!("{} {}{}", item_str, path_str, id_str)
}
Some(NodeForeignItem(item)) => {
let path_str = map.path_to_str_with_ident(id, item.ident);
let path_str = map.path_to_str_with_name(id, item.name);
format!("foreign item {}{}", path_str, id_str)
}
Some(NodeImplItem(ii)) => {
match ii.node {
ConstImplItem(..) => {
format!("assoc const {} in {}{}",
ii.ident,
ii.name,
map.path_to_string(id),
id_str)
}
MethodImplItem(..) => {
format!("method {} in {}{}",
ii.ident,
ii.name,
map.path_to_string(id), id_str)
}
TypeImplItem(_) => {
format!("assoc type {} in {}{}",
ii.ident,
ii.name,
map.path_to_string(id),
id_str)
}
Expand All @@ -1092,7 +1092,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {

format!("{} {} in {}{}",
kind,
ti.ident,
ti.name,
map.path_to_string(id),
id_str)
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/metadata/creader.rs
Expand Up @@ -201,17 +201,17 @@ impl<'a> CrateReader<'a> {
match i.node {
hir::ItemExternCrate(ref path_opt) => {
debug!("resolving extern crate stmt. ident: {} path_opt: {:?}",
i.ident, path_opt);
i.name, path_opt);
let name = match *path_opt {
Some(name) => {
validate_crate_name(Some(self.sess), &name.as_str(),
Some(i.span));
name.to_string()
}
None => i.ident.to_string(),
None => i.name.to_string(),
};
Some(CrateInfo {
ident: i.ident.to_string(),
ident: i.name.to_string(),
name: name,
id: i.id,
should_link: should_link_hir(i),
Expand Down
38 changes: 19 additions & 19 deletions src/librustc/metadata/encoder.rs
Expand Up @@ -426,16 +426,16 @@ fn encode_reexported_static_methods(ecx: &EncodeContext,
// encoded metadata for static methods relative to Bar,
// but not yet for Foo.
//
if path_differs || item.ident.name != exp.name {
if path_differs || item.name != exp.name {
if !encode_reexported_static_base_methods(ecx, rbml_w, exp) {
if encode_reexported_static_trait_methods(ecx, rbml_w, exp) {
debug!("(encode reexported static methods) {} [trait]",
item.ident.name);
item.name);
}
}
else {
debug!("(encode reexported static methods) {} [base]",
item.ident.name);
item.name);
}
}
}
Expand Down Expand Up @@ -520,7 +520,7 @@ fn encode_info_for_mod(ecx: &EncodeContext,
});

if let hir::ItemImpl(..) = item.node {
let (ident, did) = (item.ident, item.id);
let (ident, did) = (item.name, item.id);
debug!("(encoding info for module) ... encoding impl {} ({}/{})",
ident,
did, ecx.tcx.map.node_to_string(did));
Expand Down Expand Up @@ -1014,7 +1014,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
}
encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_symbol(ecx, rbml_w, item.id);
encode_name(rbml_w, item.ident.name);
encode_name(rbml_w, item.name);
encode_path(rbml_w, path);
encode_visibility(rbml_w, vis);
encode_stability(rbml_w, stab);
Expand All @@ -1027,7 +1027,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_def_id(rbml_w, def_id);
encode_family(rbml_w, 'C');
encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_name(rbml_w, item.ident.name);
encode_name(rbml_w, item.name);
encode_path(rbml_w, path);
encode_attributes(rbml_w, &item.attrs);
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
Expand All @@ -1042,7 +1042,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_family(rbml_w, FN_FAMILY);
let tps_len = generics.ty_params.len();
encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_name(rbml_w, item.ident.name);
encode_name(rbml_w, item.name);
encode_path(rbml_w, path);
encode_attributes(rbml_w, &item.attrs);
let needs_inline = tps_len > 0 || attr::requests_inline(&item.attrs);
Expand All @@ -1066,15 +1066,15 @@ fn encode_info_for_item(ecx: &EncodeContext,
&item.attrs,
item.id,
path,
item.ident.name,
item.name,
item.vis);
}
hir::ItemForeignMod(ref fm) => {
add_to_index(item, rbml_w, index);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
encode_family(rbml_w, 'n');
encode_name(rbml_w, item.ident.name);
encode_name(rbml_w, item.name);
encode_path(rbml_w, path);

// Encode all the items in this module.
Expand All @@ -1092,7 +1092,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_def_id(rbml_w, def_id);
encode_family(rbml_w, 'y');
encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_name(rbml_w, item.ident.name);
encode_name(rbml_w, item.name);
encode_path(rbml_w, path);
encode_visibility(rbml_w, vis);
encode_stability(rbml_w, stab);
Expand All @@ -1106,7 +1106,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_family(rbml_w, 't');
encode_item_variances(rbml_w, ecx, item.id);
encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_name(rbml_w, item.ident.name);
encode_name(rbml_w, item.name);
encode_attributes(rbml_w, &item.attrs);
encode_repr_attrs(rbml_w, ecx, &item.attrs);
for v in &enum_definition.variants {
Expand Down Expand Up @@ -1146,7 +1146,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_bounds_and_type_for_item(rbml_w, ecx, item.id);

encode_item_variances(rbml_w, ecx, item.id);
encode_name(rbml_w, item.ident.name);
encode_name(rbml_w, item.name);
encode_attributes(rbml_w, &item.attrs);
encode_path(rbml_w, path.clone());
encode_stability(rbml_w, stab);
Expand All @@ -1168,7 +1168,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
// If this is a tuple-like struct, encode the type of the constructor.
match struct_def.ctor_id {
Some(ctor_id) => {
encode_info_for_struct_ctor(ecx, rbml_w, item.ident.name,
encode_info_for_struct_ctor(ecx, rbml_w, item.name,
ctor_id, index, def_id.node);
}
None => {}
Expand All @@ -1179,7 +1179,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
encode_family(rbml_w, 'd');
encode_name(rbml_w, item.ident.name);
encode_name(rbml_w, item.name);
encode_unsafety(rbml_w, unsafety);

let trait_ref = tcx.impl_trait_ref(DefId::local(item.id)).unwrap();
Expand All @@ -1197,7 +1197,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_def_id(rbml_w, def_id);
encode_family(rbml_w, 'i');
encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_name(rbml_w, item.ident.name);
encode_name(rbml_w, item.name);
encode_attributes(rbml_w, &item.attrs);
encode_unsafety(rbml_w, unsafety);
encode_polarity(rbml_w, polarity);
Expand Down Expand Up @@ -1306,7 +1306,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_predicates(rbml_w, ecx, &tcx.lookup_super_predicates(def_id),
tag_item_super_predicates);
encode_trait_ref(rbml_w, ecx, trait_def.trait_ref, tag_item_trait_ref);
encode_name(rbml_w, item.ident.name);
encode_name(rbml_w, item.name);
encode_attributes(rbml_w, &item.attrs);
encode_visibility(rbml_w, vis);
encode_stability(rbml_w, stab);
Expand Down Expand Up @@ -1483,7 +1483,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
hir::ForeignItemFn(ref fndecl, _) => {
encode_family(rbml_w, FN_FAMILY);
encode_bounds_and_type_for_item(rbml_w, ecx, nitem.id);
encode_name(rbml_w, nitem.ident.name);
encode_name(rbml_w, nitem.name);
if abi == abi::RustIntrinsic || abi == abi::PlatformIntrinsic {
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Foreign(nitem));
}
Expand All @@ -1504,7 +1504,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
let stab = stability::lookup(ecx.tcx, DefId::local(nitem.id));
encode_stability(rbml_w, stab);
encode_symbol(ecx, rbml_w, nitem.id);
encode_name(rbml_w, nitem.ident.name);
encode_name(rbml_w, nitem.name);
}
}
encode_path(rbml_w, path);
Expand All @@ -1528,7 +1528,7 @@ fn my_visit_foreign_item(ni: &hir::ForeignItem,
index: &mut Vec<IndexEntry>) {
debug!("writing foreign item {}::{}",
ecx.tcx.map.path_to_string(ni.id),
ni.ident);
ni.name);

let abi = ecx.tcx.map.get_foreign_abi(ni.id);
ecx.tcx.map.with_path(ni.id, |path| {
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/astencode.rs
Expand Up @@ -155,16 +155,16 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
let raw_ii = decode_ast(ast_doc);
let ii = ast_map::map_decoded_item(&dcx.tcx.map, path, raw_ii, dcx);

let ident = match *ii {
InlinedItem::Item(ref i) => i.ident,
InlinedItem::Foreign(ref i) => i.ident,
InlinedItem::TraitItem(_, ref ti) => ti.ident,
InlinedItem::ImplItem(_, ref ii) => ii.ident
let name = match *ii {
InlinedItem::Item(ref i) => i.name,
InlinedItem::Foreign(ref i) => i.name,
InlinedItem::TraitItem(_, ref ti) => ti.name,
InlinedItem::ImplItem(_, ref ii) => ii.name
};
debug!("Fn named: {}", ident);
debug!("Fn named: {}", name);
debug!("< Decoded inlined fn: {}::{}",
path_as_str.unwrap(),
ident);
name);
region::resolve_inlined_item(&tcx.sess, &tcx.region_maps, ii);
decode_side_tables(dcx, ast_doc);
match *ii {
Expand Down

0 comments on commit a4af958

Please sign in to comment.