Skip to content

Commit

Permalink
Rename hir::map::NodeKind to hir::Node
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Aug 27, 2018
1 parent ecbdfb4 commit e2a1cce
Show file tree
Hide file tree
Showing 48 changed files with 500 additions and 507 deletions.
28 changes: 14 additions & 14 deletions src/librustc/hir/map/blocks.rs
Expand Up @@ -22,8 +22,8 @@
//! for the `Code` associated with a particular NodeId.

use hir as ast;
use hir::map::{self, NodeKind};
use hir::{Expr, FnDecl};
use hir::map;
use hir::{Expr, FnDecl, Node};
use hir::intravisit::FnKind;
use syntax::ast::{Attribute, Ident, Name, NodeId};
use syntax_pos::Span;
Expand All @@ -39,7 +39,7 @@ use syntax_pos::Span;
///
/// To construct one, use the `Code::from_node` function.
#[derive(Copy, Clone, Debug)]
pub struct FnLikeNode<'a> { node: NodeKind<'a> }
pub struct FnLikeNode<'a> { node: Node<'a> }

/// MaybeFnLike wraps a method that indicates if an object
/// corresponds to some FnLikeNode.
Expand Down Expand Up @@ -95,11 +95,11 @@ impl<'a> Code<'a> {
/// Attempts to construct a Code from presumed FnLike or Expr node input.
pub fn from_node(map: &map::Map<'a>, id: NodeId) -> Option<Code<'a>> {
match map.get(id) {
map::NodeKind::Block(_) => {
map::Node::Block(_) => {
// Use the parent, hopefully an expression node.
Code::from_node(map, map.get_parent_node(id))
}
map::NodeKind::Expr(expr) => Some(Code::Expr(expr)),
map::Node::Expr(expr) => Some(Code::Expr(expr)),
node => FnLikeNode::from_node(node).map(Code::FnLike)
}
}
Expand Down Expand Up @@ -143,12 +143,12 @@ impl<'a> ClosureParts<'a> {

impl<'a> FnLikeNode<'a> {
/// Attempts to construct a FnLikeNode from presumed FnLike node input.
pub fn from_node(node: NodeKind) -> Option<FnLikeNode> {
pub fn from_node(node: Node) -> Option<FnLikeNode> {
let fn_like = match node {
map::NodeKind::Item(item) => item.is_fn_like(),
map::NodeKind::TraitItem(tm) => tm.is_fn_like(),
map::NodeKind::ImplItem(it) => it.is_fn_like(),
map::NodeKind::Expr(e) => e.is_fn_like(),
map::Node::Item(item) => item.is_fn_like(),
map::Node::TraitItem(tm) => tm.is_fn_like(),
map::Node::ImplItem(it) => it.is_fn_like(),
map::Node::Expr(e) => e.is_fn_like(),
_ => false
};
if fn_like {
Expand Down Expand Up @@ -234,7 +234,7 @@ impl<'a> FnLikeNode<'a> {
C: FnOnce(ClosureParts<'a>) -> A,
{
match self.node {
map::NodeKind::Item(i) => match i.node {
map::Node::Item(i) => match i.node {
ast::ItemKind::Fn(ref decl, header, ref generics, block) =>
item_fn(ItemFnParts {
id: i.id,
Expand All @@ -249,13 +249,13 @@ impl<'a> FnLikeNode<'a> {
}),
_ => bug!("item FnLikeNode that is not fn-like"),
},
map::NodeKind::TraitItem(ti) => match ti.node {
map::Node::TraitItem(ti) => match ti.node {
ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => {
method(ti.id, ti.ident, sig, None, body, ti.span, &ti.attrs)
}
_ => bug!("trait method FnLikeNode that is not fn-like"),
},
map::NodeKind::ImplItem(ii) => {
map::Node::ImplItem(ii) => {
match ii.node {
ast::ImplItemKind::Method(ref sig, body) => {
method(ii.id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
Expand All @@ -265,7 +265,7 @@ impl<'a> FnLikeNode<'a> {
}
}
},
map::NodeKind::Expr(e) => match e.node {
map::Node::Expr(e) => match e.node {
ast::ExprKind::Closure(_, ref decl, block, _fn_decl_span, _gen) =>
closure(ClosureParts::new(&decl, block, e.id, e.span, &e.attrs)),
_ => bug!("expr FnLikeNode that is not fn-like"),
Expand Down
44 changes: 22 additions & 22 deletions src/librustc/hir/map/collector.rs
Expand Up @@ -117,7 +117,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
collector.insert_entry(CRATE_NODE_ID, Entry {
parent: ast::DUMMY_NODE_ID,
dep_node: root_mod_sig_dep_index,
node: NodeKind::Crate,
node: Node::Crate,
});

collector
Expand Down Expand Up @@ -190,7 +190,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
self.map[id.as_usize()] = Some(entry);
}

fn insert(&mut self, id: NodeId, node: NodeKind<'hir>) {
fn insert(&mut self, id: NodeId, node: Node<'hir>) {
let entry = Entry {
parent: self.parent_node,
dep_node: if self.currently_in_body {
Expand Down Expand Up @@ -309,13 +309,13 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
debug_assert_eq!(i.hir_id.owner,
self.definitions.opt_def_index(i.id).unwrap());
self.with_dep_node_owner(i.hir_id.owner, i, |this| {
this.insert(i.id, NodeKind::Item(i));
this.insert(i.id, Node::Item(i));
this.with_parent(i.id, |this| {
match i.node {
ItemKind::Struct(ref struct_def, _) => {
// If this is a tuple-like struct, register the constructor.
if !struct_def.is_struct() {
this.insert(struct_def.id(), NodeKind::StructCtor(struct_def));
this.insert(struct_def.id(), Node::StructCtor(struct_def));
}
}
_ => {}
Expand All @@ -326,23 +326,23 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
}

fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem) {
self.insert(foreign_item.id, NodeKind::ForeignItem(foreign_item));
self.insert(foreign_item.id, Node::ForeignItem(foreign_item));

self.with_parent(foreign_item.id, |this| {
intravisit::walk_foreign_item(this, foreign_item);
});
}

fn visit_generic_param(&mut self, param: &'hir GenericParam) {
self.insert(param.id, NodeKind::GenericParam(param));
self.insert(param.id, Node::GenericParam(param));
intravisit::walk_generic_param(self, param);
}

fn visit_trait_item(&mut self, ti: &'hir TraitItem) {
debug_assert_eq!(ti.hir_id.owner,
self.definitions.opt_def_index(ti.id).unwrap());
self.with_dep_node_owner(ti.hir_id.owner, ti, |this| {
this.insert(ti.id, NodeKind::TraitItem(ti));
this.insert(ti.id, Node::TraitItem(ti));

this.with_parent(ti.id, |this| {
intravisit::walk_trait_item(this, ti);
Expand All @@ -354,7 +354,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
debug_assert_eq!(ii.hir_id.owner,
self.definitions.opt_def_index(ii.id).unwrap());
self.with_dep_node_owner(ii.hir_id.owner, ii, |this| {
this.insert(ii.id, NodeKind::ImplItem(ii));
this.insert(ii.id, Node::ImplItem(ii));

this.with_parent(ii.id, |this| {
intravisit::walk_impl_item(this, ii);
Expand All @@ -364,9 +364,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {

fn visit_pat(&mut self, pat: &'hir Pat) {
let node = if let PatKind::Binding(..) = pat.node {
NodeKind::Binding(pat)
Node::Binding(pat)
} else {
NodeKind::Pat(pat)
Node::Pat(pat)
};
self.insert(pat.id, node);

Expand All @@ -376,15 +376,15 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
}

fn visit_anon_const(&mut self, constant: &'hir AnonConst) {
self.insert(constant.id, NodeKind::AnonConst(constant));
self.insert(constant.id, Node::AnonConst(constant));

self.with_parent(constant.id, |this| {
intravisit::walk_anon_const(this, constant);
});
}

fn visit_expr(&mut self, expr: &'hir Expr) {
self.insert(expr.id, NodeKind::Expr(expr));
self.insert(expr.id, Node::Expr(expr));

self.with_parent(expr.id, |this| {
intravisit::walk_expr(this, expr);
Expand All @@ -393,23 +393,23 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {

fn visit_stmt(&mut self, stmt: &'hir Stmt) {
let id = stmt.node.id();
self.insert(id, NodeKind::Stmt(stmt));
self.insert(id, Node::Stmt(stmt));

self.with_parent(id, |this| {
intravisit::walk_stmt(this, stmt);
});
}

fn visit_ty(&mut self, ty: &'hir Ty) {
self.insert(ty.id, NodeKind::Ty(ty));
self.insert(ty.id, Node::Ty(ty));

self.with_parent(ty.id, |this| {
intravisit::walk_ty(this, ty);
});
}

fn visit_trait_ref(&mut self, tr: &'hir TraitRef) {
self.insert(tr.ref_id, NodeKind::TraitRef(tr));
self.insert(tr.ref_id, Node::TraitRef(tr));

self.with_parent(tr.ref_id, |this| {
intravisit::walk_trait_ref(this, tr);
Expand All @@ -423,21 +423,21 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
}

fn visit_block(&mut self, block: &'hir Block) {
self.insert(block.id, NodeKind::Block(block));
self.insert(block.id, Node::Block(block));
self.with_parent(block.id, |this| {
intravisit::walk_block(this, block);
});
}

fn visit_local(&mut self, l: &'hir Local) {
self.insert(l.id, NodeKind::Local(l));
self.insert(l.id, Node::Local(l));
self.with_parent(l.id, |this| {
intravisit::walk_local(this, l)
})
}

fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) {
self.insert(lifetime.id, NodeKind::Lifetime(lifetime));
self.insert(lifetime.id, Node::Lifetime(lifetime));
}

fn visit_vis(&mut self, visibility: &'hir Visibility) {
Expand All @@ -446,7 +446,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
VisibilityKind::Crate(_) |
VisibilityKind::Inherited => {}
VisibilityKind::Restricted { id, .. } => {
self.insert(id, NodeKind::Visibility(visibility));
self.insert(id, Node::Visibility(visibility));
self.with_parent(id, |this| {
intravisit::walk_vis(this, visibility);
});
Expand All @@ -458,20 +458,20 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
let def_index = self.definitions.opt_def_index(macro_def.id).unwrap();

self.with_dep_node_owner(def_index, macro_def, |this| {
this.insert(macro_def.id, NodeKind::MacroDef(macro_def));
this.insert(macro_def.id, Node::MacroDef(macro_def));
});
}

fn visit_variant(&mut self, v: &'hir Variant, g: &'hir Generics, item_id: NodeId) {
let id = v.node.data.id();
self.insert(id, NodeKind::Variant(v));
self.insert(id, Node::Variant(v));
self.with_parent(id, |this| {
intravisit::walk_variant(this, v, g, item_id);
});
}

fn visit_struct_field(&mut self, field: &'hir StructField) {
self.insert(field.id, NodeKind::Field(field));
self.insert(field.id, Node::Field(field));
self.with_parent(field.id, |this| {
intravisit::walk_struct_field(this, field);
});
Expand Down

0 comments on commit e2a1cce

Please sign in to comment.