Navigation Menu

Skip to content

Commit

Permalink
Use Names in HIR visitors and folders
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Sep 22, 2015
1 parent 885d224 commit ae77dbb
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 65 deletions.
6 changes: 3 additions & 3 deletions src/librustc/front/map/blocks.rs
Expand Up @@ -189,13 +189,13 @@ impl<'a> FnLikeNode<'a> {

pub fn kind(self) -> FnKind<'a> {
let item = |p: ItemFnParts<'a>| -> FnKind<'a> {
FnKind::ItemFn(p.ident, p.generics, p.unsafety, p.constness, p.abi, p.vis)
FnKind::ItemFn(p.ident.name, p.generics, p.unsafety, p.constness, p.abi, p.vis)
};
let closure = |_: ClosureParts| {
FnKind::Closure
};
let method = |_, ident, sig: &'a ast::MethodSig, vis, _, _| {
FnKind::Method(ident, sig, vis)
let method = |_, ident: Ident, sig: &'a ast::MethodSig, vis, _, _| {
FnKind::Method(ident.name, sig, vis)
};
self.handle(item, method, closure)
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/lint/context.rs
Expand Up @@ -663,12 +663,12 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {

fn visit_struct_def(&mut self,
s: &hir::StructDef,
ident: ast::Ident,
name: ast::Name,
g: &hir::Generics,
id: ast::NodeId) {
run_lints!(self, check_struct_def, late_passes, s, ident, g, id);
run_lints!(self, check_struct_def, late_passes, s, name, g, id);
hir_visit::walk_struct_def(self, s);
run_lints!(self, check_struct_def_post, late_passes, s, ident, g, id);
run_lints!(self, check_struct_def_post, late_passes, s, name, g, id);
}

fn visit_struct_field(&mut self, s: &hir::StructField) {
Expand All @@ -691,8 +691,8 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
hir_visit::walk_ty(self, t);
}

fn visit_ident(&mut self, sp: Span, id: ast::Ident) {
run_lints!(self, check_ident, late_passes, sp, id);
fn visit_name(&mut self, sp: Span, name: ast::Name) {
run_lints!(self, check_name, late_passes, sp, name);
}

fn visit_mod(&mut self, m: &hir::Mod, s: Span, n: ast::NodeId) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/lint/mod.rs
Expand Up @@ -130,7 +130,7 @@ pub trait LintPass {
// FIXME: eliminate the duplication with `Visitor`. But this also
// contains a few lint-specific methods with no equivalent in `Visitor`.
pub trait LateLintPass: LintPass {
fn check_ident(&mut self, _: &LateContext, _: Span, _: ast::Ident) { }
fn check_name(&mut self, _: &LateContext, _: Span, _: ast::Name) { }
fn check_crate(&mut self, _: &LateContext, _: &hir::Crate) { }
fn check_mod(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { }
fn check_foreign_item(&mut self, _: &LateContext, _: &hir::ForeignItem) { }
Expand All @@ -150,9 +150,9 @@ pub trait LateLintPass: LintPass {
fn check_trait_item(&mut self, _: &LateContext, _: &hir::TraitItem) { }
fn check_impl_item(&mut self, _: &LateContext, _: &hir::ImplItem) { }
fn check_struct_def(&mut self, _: &LateContext,
_: &hir::StructDef, _: ast::Ident, _: &hir::Generics, _: ast::NodeId) { }
_: &hir::StructDef, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
fn check_struct_def_post(&mut self, _: &LateContext,
_: &hir::StructDef, _: ast::Ident, _: &hir::Generics, _: ast::NodeId) { }
_: &hir::StructDef, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
fn check_struct_field(&mut self, _: &LateContext, _: &hir::StructField) { }
fn check_variant(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
fn check_variant_post(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Expand Up @@ -207,7 +207,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {

impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {

fn visit_struct_def(&mut self, def: &hir::StructDef, _: ast::Ident,
fn visit_struct_def(&mut self, def: &hir::StructDef, _: ast::Name,
_: &hir::Generics, _: ast::NodeId) {
let has_extern_repr = self.struct_has_extern_repr;
let inherited_pub_visibility = self.inherited_pub_visibility;
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_back/svh.rs
Expand Up @@ -131,7 +131,7 @@ mod svh_visitor {
pub use self::SawExprComponent::*;
pub use self::SawStmtComponent::*;
use self::SawAbiComponent::*;
use syntax::ast::{self, NodeId, Ident};
use syntax::ast::{self, Name, NodeId};
use syntax::codemap::Span;
use syntax::parse::token;
use rustc_front::visit;
Expand Down Expand Up @@ -302,9 +302,9 @@ mod svh_visitor {
}

impl<'a, 'v> Visitor<'v> for StrictVersionHashVisitor<'a> {
fn visit_struct_def(&mut self, s: &StructDef, ident: Ident,
fn visit_struct_def(&mut self, s: &StructDef, name: Name,
g: &Generics, _: NodeId) {
SawStructDef(ident.name.as_str()).hash(self.st);
SawStructDef(name.as_str()).hash(self.st);
visit::walk_generics(self, g);
visit::walk_struct_def(self, s)
}
Expand Down Expand Up @@ -341,8 +341,8 @@ mod svh_visitor {
// (If you edit a method such that it deviates from the
// pattern, please move that method up above this comment.)

fn visit_ident(&mut self, _: Span, ident: Ident) {
SawIdent(ident.name.as_str()).hash(self.st);
fn visit_name(&mut self, _: Span, name: Name) {
SawIdent(name.as_str()).hash(self.st);
}

fn visit_lifetime_ref(&mut self, l: &Lifetime) {
Expand Down
40 changes: 22 additions & 18 deletions src/librustc_front/fold.rs
Expand Up @@ -12,7 +12,7 @@
//! and returns a piece of the same type.

use hir::*;
use syntax::ast::{Ident, NodeId, DUMMY_NODE_ID, Attribute, Attribute_, MetaItem};
use syntax::ast::{Ident, Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_, MetaItem};
use syntax::ast::{MetaWord, MetaList, MetaNameValue};
use hir;
use syntax::codemap::{respan, Span, Spanned};
Expand Down Expand Up @@ -147,8 +147,8 @@ pub trait Folder : Sized {
noop_fold_variant(v, self)
}

fn fold_ident(&mut self, i: Ident) -> Ident {
noop_fold_ident(i, self)
fn fold_name(&mut self, n: Name) -> Name {
noop_fold_name(n, self)
}

fn fold_usize(&mut self, i: usize) -> usize {
Expand Down Expand Up @@ -284,6 +284,10 @@ pub trait Folder : Sized {
}
}

fn fold_ident<T: Folder>(f: &mut T, i: Ident) -> Ident {
Ident { name: f.fold_name(i.name), ctxt: i.ctxt }
}

pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<P<MetaItem>>, fld: &mut T)
-> Vec<P<MetaItem>> {
meta_items.move_map(|x| fld.fold_meta_item(x))
Expand Down Expand Up @@ -435,8 +439,8 @@ pub fn noop_fold_variant<T: Folder>(v: P<Variant>, fld: &mut T) -> P<Variant> {
})
}

pub fn noop_fold_ident<T: Folder>(i: Ident, _: &mut T) -> Ident {
i
pub fn noop_fold_name<T: Folder>(n: Name, _: &mut T) -> Name {
n
}

pub fn noop_fold_usize<T: Folder>(i: usize, _: &mut T) -> usize {
Expand All @@ -447,7 +451,7 @@ pub fn noop_fold_path<T: Folder>(Path {global, segments, span}: Path, fld: &mut
Path {
global: global,
segments: segments.move_map(|PathSegment {identifier, parameters}| PathSegment {
identifier: fld.fold_ident(identifier),
identifier: fold_ident(fld, identifier),
parameters: fld.fold_path_parameters(parameters),
}),
span: fld.new_span(span)
Expand Down Expand Up @@ -719,7 +723,7 @@ pub fn noop_fold_struct_field<T: Folder>(f: StructField, fld: &mut T) -> StructF

pub fn noop_fold_field<T: Folder>(Field {ident, expr, span}: Field, folder: &mut T) -> Field {
Field {
ident: respan(ident.span, folder.fold_ident(ident.node)),
ident: respan(ident.span, fold_ident(folder, ident.node)),
expr: folder.fold_expr(expr),
span: folder.new_span(span)
}
Expand Down Expand Up @@ -835,7 +839,7 @@ pub fn noop_fold_trait_item<T: Folder>(i: P<TraitItem>, folder: &mut T)
-> SmallVector<P<TraitItem>> {
SmallVector::one(i.map(|TraitItem {id, ident, attrs, node, span}| TraitItem {
id: folder.new_id(id),
ident: folder.fold_ident(ident),
ident: fold_ident(folder, ident),
attrs: fold_attrs(attrs, folder),
node: match node {
ConstTraitItem(ty, default) => {
Expand All @@ -859,7 +863,7 @@ pub fn noop_fold_impl_item<T: Folder>(i: P<ImplItem>, folder: &mut T)
-> SmallVector<P<ImplItem>> {
SmallVector::one(i.map(|ImplItem {id, ident, attrs, node, vis, span}| ImplItem {
id: folder.new_id(id),
ident: folder.fold_ident(ident),
ident: fold_ident(folder, ident),
attrs: fold_attrs(attrs, folder),
vis: vis,
node: match node {
Expand Down Expand Up @@ -943,7 +947,7 @@ pub fn noop_fold_item_simple<T: Folder>(Item {id, ident, attrs, node, vis, span}

Item {
id: id,
ident: folder.fold_ident(ident),
ident: fold_ident(folder, ident),
attrs: fold_attrs(attrs, folder),
node: node,
vis: vis,
Expand All @@ -954,7 +958,7 @@ pub fn noop_fold_item_simple<T: Folder>(Item {id, ident, attrs, node, vis, span}
pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) -> P<ForeignItem> {
ni.map(|ForeignItem {id, ident, attrs, node, span, vis}| ForeignItem {
id: folder.new_id(id),
ident: folder.fold_ident(ident),
ident: fold_ident(folder, ident),
attrs: fold_attrs(attrs, folder),
node: match node {
ForeignItemFn(fdec, generics) => {
Expand Down Expand Up @@ -988,7 +992,7 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
PatIdent(binding_mode, pth1, sub) => {
PatIdent(binding_mode,
Spanned{span: folder.new_span(pth1.span),
node: folder.fold_ident(pth1.node)},
node: fold_ident(folder, pth1.node)},
sub.map(|x| folder.fold_pat(x)))
}
PatLit(e) => PatLit(folder.fold_expr(e)),
Expand Down Expand Up @@ -1048,7 +1052,7 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
}
ExprMethodCall(i, tps, args) => {
ExprMethodCall(
respan(folder.new_span(i.span), folder.fold_ident(i.node)),
respan(folder.new_span(i.span), fold_ident(folder, i.node)),
tps.move_map(|x| folder.fold_ty(x)),
args.move_map(|x| folder.fold_expr(x)))
}
Expand All @@ -1073,11 +1077,11 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
ExprWhile(cond, body, opt_ident) => {
ExprWhile(folder.fold_expr(cond),
folder.fold_block(body),
opt_ident.map(|i| folder.fold_ident(i)))
opt_ident.map(|i| fold_ident(folder, i)))
}
ExprLoop(body, opt_ident) => {
ExprLoop(folder.fold_block(body),
opt_ident.map(|i| folder.fold_ident(i)))
opt_ident.map(|i| fold_ident(folder, i)))
}
ExprMatch(expr, arms, source) => {
ExprMatch(folder.fold_expr(expr),
Expand All @@ -1101,7 +1105,7 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
ExprField(el, ident) => {
ExprField(folder.fold_expr(el),
respan(folder.new_span(ident.span),
folder.fold_ident(ident.node)))
fold_ident(folder, ident.node)))
}
ExprTupField(el, ident) => {
ExprTupField(folder.fold_expr(el),
Expand All @@ -1126,11 +1130,11 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
}
ExprBreak(opt_ident) => ExprBreak(opt_ident.map(|label|
respan(folder.new_span(label.span),
folder.fold_ident(label.node)))
fold_ident(folder, label.node)))
),
ExprAgain(opt_ident) => ExprAgain(opt_ident.map(|label|
respan(folder.new_span(label.span),
folder.fold_ident(label.node)))
fold_ident(folder, label.node)))
),
ExprRet(e) => ExprRet(e.map(|x| folder.fold_expr(x))),
ExprInlineAsm(InlineAsm {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_front/util.rs
Expand Up @@ -12,7 +12,7 @@ use hir;
use hir::*;
use visit::{self, Visitor, FnKind};
use syntax::ast_util;
use syntax::ast::{Ident, NodeId, DUMMY_NODE_ID};
use syntax::ast::{Ident, Name, NodeId, DUMMY_NODE_ID};
use syntax::codemap::Span;
use syntax::ptr::P;
use syntax::owned_slice::OwnedSlice;
Expand Down Expand Up @@ -286,7 +286,7 @@ impl<'a, 'v, O: ast_util::IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O>

fn visit_struct_def(&mut self,
struct_def: &StructDef,
_: Ident,
_: Name,
_: &hir::Generics,
id: NodeId) {
self.operation.visit_id(id);
Expand Down

0 comments on commit ae77dbb

Please sign in to comment.