use syntax::print::pprust::{path_to_string, ty_to_string};
use syntax::ptr::P;
+use rustc_front::lowering::lower_expr;
+
use super::span_utils::SpanUtils;
use super::recorder::{Recorder, FmtStrs};
span: SpanUtils<'l>,
fmt: FmtStrs<'l>,
- cur_scope: NodeId
+ cur_scope: NodeId,
}
impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
pub fn new(tcx: &'l ty::ctxt<'tcx>,
analysis: &'l ty::CrateAnalysis,
- output_file: Box<File>) -> DumpCsvVisitor<'l, 'tcx> {
+ output_file: Box<File>)
+ -> DumpCsvVisitor<'l, 'tcx> {
let span_utils = SpanUtils::new(&tcx.sess);
DumpCsvVisitor {
sess: &tcx.sess,
save_ctxt: SaveContext::from_span_utils(tcx, span_utils.clone()),
analysis: analysis,
span: span_utils.clone(),
- fmt: FmtStrs::new(box Recorder {
- out: output_file,
- dump_spans: false,
- }, span_utils),
- cur_scope: 0
+ fmt: FmtStrs::new(box Recorder { out: output_file, dump_spans: false },
+ span_utils),
+ cur_scope: 0,
}
}
- fn nest<F>(&mut self, scope_id: NodeId, f: F) where
- F: FnOnce(&mut DumpCsvVisitor<'l, 'tcx>),
+ fn nest<F>(&mut self, scope_id: NodeId, f: F)
+ where F: FnOnce(&mut DumpCsvVisitor<'l, 'tcx>)
{
let parent_scope = self.cur_scope;
self.cur_scope = scope_id;
let mut segs = vec!();
for (i, (seg, span)) in path.segments.iter().zip(&spans).enumerate() {
segs.push(seg.clone());
- let sub_path = ast::Path{span: *span, // span for the last segment
- global: path.global,
- segments: segs};
+ let sub_path = ast::Path {
+ span: *span, // span for the last segment
+ global: path.global,
+ segments: segs,
+ };
let qualname = if i == 0 && path.global {
format!("::{}", path_to_string(&sub_path))
} else {
def::DefPrimTy(_) => {
self.sess.span_bug(span, &format!("lookup_def_kind for unexpected item: {:?}",
def));
- },
+ }
}
}
}
}
- fn process_struct_field_def(&mut self,
- field: &ast::StructField,
- parent_id: NodeId) {
+ fn process_struct_field_def(&mut self, field: &ast::StructField, parent_id: NodeId) {
let field_data = self.save_ctxt.get_field_data(field, parent_id);
if let Some(field_data) = field_data {
self.fmt.field_str(field.span,
// Dump generic params bindings, then visit_generics
fn process_generic_params(&mut self,
- generics:&ast::Generics,
+ generics: &ast::Generics,
full_span: Span,
prefix: &str,
id: NodeId) {
self.nest(item.id, |v| v.visit_block(&body));
}
- fn process_static_or_const_item(&mut self,
- item: &ast::Item,
- typ: &ast::Ty,
- expr: &ast::Expr)
- {
+ fn process_static_or_const_item(&mut self, item: &ast::Item, typ: &ast::Ty, expr: &ast::Expr) {
let var_data = self.save_ctxt.get_item_data(item);
down_cast_data!(var_data, VariableData, self, item.span);
self.fmt.static_str(item.span,
fn process_const(&mut self,
id: ast::NodeId,
- ident: &ast::Ident,
+ name: ast::Name,
span: Span,
typ: &ast::Ty,
- expr: &ast::Expr)
- {
+ expr: &ast::Expr) {
let qualname = format!("::{}", self.tcx.map.path_to_string(id));
let sub_span = self.span.sub_span_after_keyword(span,
self.fmt.static_str(span,
sub_span,
id,
- &ident.name.as_str(),
+ &name.as_str(),
&qualname,
&self.span.snippet(expr.span),
&ty_to_string(&*typ),
sub_span,
id,
item.id);
- },
- None => ()
+ }
+ None => (),
}
}
}
}
- fn process_mod(&mut self,
- item: &ast::Item) { // The module in question, represented as an item.
+ // `item` is the module in question, represented as an item.
+ fn process_mod(&mut self, item: &ast::Item) {
let mod_data = self.save_ctxt.get_item_data(item);
down_cast_data!(mod_data, ModData, self, item.span);
self.fmt.mod_str(item.span,
&mod_data.filename);
}
- fn process_path(&mut self,
- id: NodeId,
- path: &ast::Path,
- ref_kind: Option<recorder::Row>) {
+ fn process_path(&mut self, id: NodeId, path: &ast::Path, ref_kind: Option<recorder::Row>) {
if generated_code(path.span) {
return;
}
def::DefStruct(_) |
def::DefVariant(..) |
def::DefFn(..) => self.write_sub_paths_truncated(path, false),
- _ => {},
+ _ => {}
}
}
}
}
- visit::walk_expr_opt(self, base)
+ walk_list!(self, visit_expr, base);
}
- fn process_method_call(&mut self,
- ex: &ast::Expr,
- args: &Vec<P<ast::Expr>>) {
+ fn process_method_call(&mut self, ex: &ast::Expr, args: &Vec<P<ast::Expr>>) {
if let Some(call_data) = self.save_ctxt.get_expr_data(ex) {
down_cast_data!(call_data, MethodCallData, self, ex.span);
self.fmt.meth_call_str(ex.span,
}
// walk receiver and args
- visit::walk_exprs(self, &args);
+ walk_list!(self, visit_expr, args);
}
- fn process_pat(&mut self, p:&ast::Pat) {
+ fn process_pat(&mut self, p: &ast::Pat) {
if generated_code(p.span) {
return;
}
self.visit_pat(&field.pat);
}
}
- _ => visit::walk_pat(self, p)
+ _ => visit::walk_pat(self, p),
}
}
}
sub_span,
def_id,
self.cur_scope),
- None => {},
+ None => {}
}
Some(def_id)
- },
+ }
None => None,
};
match plid.node {
ast::PathListIdent { id, .. } => {
match self.lookup_type_ref(id) {
- Some(def_id) =>
- match self.lookup_def_kind(id, plid.span) {
- Some(kind) => {
- self.fmt.ref_str(
+ Some(def_id) => match self.lookup_def_kind(id, plid.span) {
+ Some(kind) => {
+ self.fmt.ref_str(
kind, plid.span,
Some(plid.span),
def_id, self.cur_scope);
- }
- None => ()
- },
- None => ()
+ }
+ None => (),
+ },
+ None => (),
}
- },
- ast::PathListMod { .. } => ()
+ }
+ ast::PathListMod { .. } => (),
}
}
self.visit_ty(&**ty);
self.process_generic_params(ty_params, item.span, &qualname, item.id);
- },
+ }
ast::ItemMac(_) => (),
_ => visit::walk_item(self, item),
}
fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) {
match trait_item.node {
ast::ConstTraitItem(ref ty, Some(ref expr)) => {
- self.process_const(trait_item.id, &trait_item.ident,
+ self.process_const(trait_item.id, trait_item.ident.name,
trait_item.span, &*ty, &*expr);
}
ast::MethodTraitItem(ref sig, ref body) => {
fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) {
match impl_item.node {
ast::ConstImplItem(ref ty, ref expr) => {
- self.process_const(impl_item.id, &impl_item.ident,
+ self.process_const(impl_item.id, impl_item.ident.name,
impl_item.span, &ty, &expr);
}
ast::MethodImplItem(ref sig, ref body) => {
sub_span,
id,
self.cur_scope);
- },
- None => ()
+ }
+ None => (),
}
self.write_sub_paths_truncated(path, false);
visit::walk_path(self, path);
- },
+ }
_ => visit::walk_ty(self, t),
}
}
visit::walk_expr(self, ex);
}
ast::ExprStruct(ref path, ref fields, ref base) => {
- let adt = self.tcx.expr_ty(ex).ty_adt_def().unwrap();
- let def = self.tcx.resolve_expr(ex);
+ let hir_expr = lower_expr(ex);
+ let adt = self.tcx.expr_ty(&hir_expr).ty_adt_def().unwrap();
+ let def = self.tcx.resolve_expr(&hir_expr);
self.process_struct_lit(ex,
path,
fields,
field_data.ref_id,
field_data.scope);
}
- },
+ }
ast::ExprTupField(ref sub_ex, idx) => {
if generated_code(sub_ex.span) {
return
self.visit_expr(&**sub_ex);
- let ty = &self.tcx.expr_ty_adjusted(&**sub_ex).sty;
+ let hir_node = lower_expr(sub_ex);
+ let ty = &self.tcx.expr_ty_adjusted(&hir_node).sty;
match *ty {
ty::TyStruct(def, _) => {
let sub_span = self.span.sub_span_after_token(ex.span, token::Dot);
&format!("Expected struct or tuple \
type, found {:?}", ty)),
}
- },
+ }
ast::ExprClosure(_, ref decl, ref body) => {
if generated_code(body.span) {
return
// walk the body
self.nest(ex.id, |v| v.visit_block(&**body));
- },
+ }
_ => {
visit::walk_expr(self, ex)
}
}
let def = def_map.get(&id).unwrap().full_def();
match def {
- def::DefLocal(id) => {
+ def::DefLocal(id) => {
let value = if immut == ast::MutImmutable {
self.span.snippet(p.span).to_string()
} else {
def::DefConst(..) |
def::DefAssociatedConst(..) => {}
_ => error!("unexpected definition kind when processing collected paths: {:?}",
- def)
+ def),
}
}
for &(id, ref path, ref_kind) in &paths_to_process {
self.process_path(id, path, ref_kind);
}
- visit::walk_expr_opt(self, &arm.guard);
+ walk_list!(self, visit_expr, &arm.guard);
self.visit_expr(&arm.body);
}
}
// Just walk the initialiser and type (don't want to walk the pattern again).
- visit::walk_ty_opt(self, &l.ty);
- visit::walk_expr_opt(self, &l.init);
+ walk_list!(self, visit_ty, &l.ty);
+ walk_list!(self, visit_expr, &l.init);
}
}