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,
ident: &ast::Ident,
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,
sub_span,
id,
item.id);
- },
- None => ()
+ }
+ None => (),
}
}
}
}
- fn process_mod(&mut self,
- item: &ast::Item) { // The module in question, represented as an item.
+ fn process_mod(&mut self, item: &ast::Item) { // The module in question, represented as an 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)
}
- 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,
visit::walk_exprs(self, &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),
}
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),
}
}
field_data.ref_id,
field_data.scope);
}
- },
+ }
ast::ExprTupField(ref sub_ex, idx) => {
if generated_code(sub_ex.span) {
return
&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),
}
}
impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
- pub fn new(tcx: &'l ty::ctxt<'tcx>) -> SaveContext <'l, 'tcx> {
+ pub fn new(tcx: &'l ty::ctxt<'tcx>) -> SaveContext<'l, 'tcx> {
let span_utils = SpanUtils::new(&tcx.sess);
SaveContext::from_span_utils(tcx, span_utils)
}
pub fn from_span_utils(tcx: &'l ty::ctxt<'tcx>,
span_utils: SpanUtils<'l>)
-> SaveContext<'l, 'tcx> {
- SaveContext {
- tcx: tcx,
- span_utils: span_utils,
- }
+ SaveContext { tcx: tcx, span_utils: span_utils }
}
// List external crates used by the current crate.
scope: self.enclosing_scope(item.id),
filename: filename,
})
- },
+ }
ast::ItemEnum(..) => {
let enum_name = format!("::{}", self.tcx.map.path_to_string(item.id));
let val = self.span_utils.snippet(item.span);
qualname: enum_name,
scope: self.enclosing_scope(item.id),
})
- },
+ }
ast::ItemImpl(_, _, _, ref trait_ref, ref typ, _) => {
let mut type_data = None;
let sub_span;
scope: parent,
ref_id: id,
});
- },
+ }
_ => {
// Less useful case, impl for a compound type.
let span = typ.span;
value: "".to_owned(),
type_value: typ,
})
- },
+ }
_ => None,
}
}
// FIXME would be nice to take a MethodItem here, but the ast provides both
// trait and impl flavours, so the caller must do the disassembly.
- pub fn get_method_data(&self,
- id: ast::NodeId,
- name: ast::Name,
- span: Span) -> FunctionData {
+ pub fn get_method_data(&self, id: ast::NodeId, name: ast::Name, span: Span) -> FunctionData {
// The qualname for a method is the trait name or name of the struct in an impl in
// which the method is declared in, followed by the method's name.
let qualname = match self.tcx.impl_of_method(DefId::local(id)) {
result.push_str(" as ");
result.push_str(
&self.tcx.item_path_str(def_id));
- },
+ }
None => {}
}
result.push_str(">");
self.tcx.sess.span_bug(span,
&format!("Container {} for method {} not an impl?",
impl_id.node, id));
- },
+ }
}
- },
+ }
_ => {
self.tcx.sess.span_bug(span,
&format!("Container {} for method {} is not a node item {:?}",
impl_id.node, id, self.tcx.map.get(impl_id.node)));
- },
+ }
},
None => match self.tcx.trait_of_item(DefId::local(id)) {
Some(def_id) => {
def_id.node, id));
}
}
- },
+ }
None => {
self.tcx.sess.span_bug(span,
&format!("Could not find container for method {}", id));
- },
+ }
},
};
let method_id = self.tcx.tables.borrow().method_map[&method_call].def_id;
let (def_id, decl_id) = match self.tcx.impl_or_trait_item(method_id).container() {
ty::ImplContainer(_) => (Some(method_id), None),
- ty::TraitContainer(_) => (None, Some(method_id))
+ ty::TraitContainer(_) => (None, Some(method_id)),
};
let sub_span = self.span_utils.sub_span_for_meth_name(expr.span);
let parent = self.enclosing_scope(expr.id);
}
}
- pub fn get_path_data(&self,
- id: NodeId,
- path: &ast::Path)
- -> Option<Data> {
+ pub fn get_path_data(&self, id: NodeId, path: &ast::Path) -> Option<Data> {
let def_map = self.tcx.def_map.borrow();
if !def_map.contains_key(&id) {
self.tcx.sess.span_bug(path.span,
ref_id: def_id,
decl_id: Some(decl_id),
}))
- },
+ }
def::DefFn(def_id, _) => {
Some(Data::FunctionCallData(FunctionCallData {
ref_id: def_id,
impl PathCollector {
fn new() -> PathCollector {
- PathCollector {
- collected_paths: vec![],
- }
+ PathCollector { collected_paths: vec![] }
}
}
None => {
info!("Could not find crate name, using 'unknown_crate'");
String::from("unknown_crate")
- },
+ }
};
info!("Dumping crate {}", cratename);
// If the expression is a macro expansion or other generated code, run screaming
// and don't index.
pub fn generated_code(span: Span) -> bool {
- span.expn_id != NO_EXPANSION || span == DUMMY_SP
+ span.expn_id != NO_EXPANSION || span == DUMMY_SP
}
use std::io::Write;
use syntax::ast;
-use syntax::ast::{NodeId};
+use syntax::ast::NodeId;
use syntax::codemap::*;
const ZERO_DEF_ID: DefId = DefId { node: 0, krate: 0 };
pub struct Recorder {
// output file
- pub out: Box<Write+'static>,
+ pub out: Box<Write + 'static>,
pub dump_spans: bool,
}
}
}
- pub fn dump_span(&mut self,
- su: SpanUtils,
- kind: &str,
- span: Span,
- _sub_span: Option<Span>) {
+ pub fn dump_span(&mut self, su: SpanUtils, kind: &str, span: Span, _sub_span: Option<Span>) {
assert!(self.dump_spans);
let result = format!("span,kind,{},{},text,\"{}\"\n",
kind, su.extent_str(span), escape(su.snippet(span)));
impl<'a> FmtStrs<'a> {
pub fn new(rec: Box<Recorder>, span: SpanUtils<'a>) -> FmtStrs<'a> {
- FmtStrs {
- recorder: rec,
- span: span,
- }
+ FmtStrs { recorder: rec, span: span }
}
// A map from kind of item to a tuple of
match r {
Variable => ("variable",
vec!("id","name","qualname","value","type","scopeid"),
- true, true),
+ true,
+ true),
Enum => ("enum", vec!("id","qualname","scopeid","value"), true, true),
Variant => ("variant",
vec!("id","name","qualname","type","value","scopeid"),
- true, true),
+ true,
+ true),
VariantStruct => ("variant_struct",
vec!("id","ctor_id","qualname","type","value","scopeid"),
- true, true),
+ true,
+ true),
Function => ("function",
vec!("id","qualname","declid","declidcrate","scopeid"),
- true, true),
+ true,
+ true),
MethodDecl => ("method_decl", vec!("id","qualname","scopeid"), true, true),
Struct => ("struct", vec!("id","ctor_id","qualname","scopeid","value"), true, true),
Trait => ("trait", vec!("id","qualname","scopeid","value"), true, true),
Impl => ("impl",
vec!("id","refid","refidcrate","traitid","traitidcrate","scopeid"),
- true, true),
+ true,
+ true),
Module => ("module", vec!("id","qualname","scopeid","def_file"), true, false),
- UseAlias => ("use_alias",
- vec!("id","refid","refidcrate","name","scopeid"),
- true, true),
+ UseAlias => ("use_alias", vec!("id","refid","refidcrate","name","scopeid"), true, true),
UseGlob => ("use_glob", vec!("id","value","scopeid"), true, true),
ExternCrate => ("extern_crate",
vec!("id","name","location","crate","scopeid"),
- true, true),
+ true,
+ true),
Inheritance => ("inheritance",
vec!("base","basecrate","derived","derivedcrate"),
- true, false),
+ true,
+ false),
MethodCall => ("method_call",
vec!("refid","refidcrate","declid","declidcrate","scopeid"),
- true, true),
+ true,
+ true),
Typedef => ("typedef", vec!("id","qualname","value"), true, true),
ExternalCrate => ("external_crate", vec!("name","crate","file_name"), false, false),
Crate => ("crate", vec!("name"), true, false),
FnCall => ("fn_call", vec!("refid","refidcrate","qualname","scopeid"), true, true),
ModRef => ("mod_ref", vec!("refid","refidcrate","qualname","scopeid"), true, true),
VarRef => ("var_ref", vec!("refid","refidcrate","qualname","scopeid"), true, true),
- TypeRef => ("type_ref",
- vec!("refid","refidcrate","qualname","scopeid"),
- true, true),
- FnRef => ("fn_ref", vec!("refid","refidcrate","qualname","scopeid"), true, true)
+ TypeRef => ("type_ref", vec!("refid","refidcrate","qualname","scopeid"), true, true),
+ FnRef => ("fn_ref", vec!("refid","refidcrate","qualname","scopeid"), true, true),
}
}
kind: &'static str,
fields: &Vec<&'static str>,
values: Vec<String>,
- span: Span) -> Option<String> {
+ span: Span)
+ -> Option<String> {
if values.len() != fields.len() {
self.span.sess.span_bug(span, &format!(
"Mismatch between length of fields for '{}', expected '{}', found '{}'",
}))
}
- pub fn record_without_span(&mut self,
- kind: Row,
- values: Vec<String>,
- span: Span) {
+ pub fn record_without_span(&mut self, kind: Row, values: Vec<String>, span: Span) {
let (label, ref fields, needs_span, dump_spans) = FmtStrs::lookup_row(kind);
if needs_span {
scope_id: NodeId) {
let values = match decl_id {
Some(decl_id) => svec!(id, name, decl_id.node, decl_id.krate, scope_id),
- None => svec!(id, name, "", "", scope_id)
+ None => svec!(id, name, "", "", scope_id),
};
self.check_and_record(Function,
span,
parent: NodeId) {
let (mod_node, mod_crate) = match mod_id {
Some(mod_id) => (mod_id.node, mod_id.krate),
- None => (0, 0)
+ None => (0, 0),
};
self.check_and_record(UseAlias,
span,
span: Span,
sub_span: Option<Span>,
id: DefId,
- scope_id:NodeId) {
+ scope_id: NodeId) {
self.check_and_record(FnCall,
span,
sub_span,
scope_id: NodeId) {
let (dfn, dfk) = match defid {
Some(defid) => (defid.node, defid.krate),
- None => (0, 0)
+ None => (0, 0),
};
let (dcn, dck) = match declid {
Some(declid) => (s!(declid.node), s!(declid.krate)),
- None => ("".to_string(), "".to_string())
+ None => ("".to_string(), "".to_string()),
};
self.check_and_record(MethodCall,
span,
svec!(dfn, dfk, dcn, dck, scope_id));
}
- pub fn sub_mod_ref_str(&mut self,
- span: Span,
- sub_span: Span,
- qualname: &str,
- parent:NodeId) {
+ pub fn sub_mod_ref_str(&mut self, span: Span, sub_span: Span, qualname: &str, parent: NodeId) {
self.record_with_span(ModRef,
span,
sub_span,
svec!(id, qualname, value));
}
- pub fn crate_str(&mut self,
- span: Span,
- name: &str) {
+ pub fn crate_str(&mut self, span: Span, name: &str) {
self.record_with_span(Crate,
span,
span,
svec!(name));
}
- pub fn external_crate_str(&mut self,
- span: Span,
- name: &str,
- num: ast::CrateNum) {
+ pub fn external_crate_str(&mut self, span: Span, name: &str, num: ast::CrateNum) {
let lo_loc = self.span.sess.codemap().lookup_char_pos(span.lo);
self.record_without_span(ExternalCrate,
svec!(name, num, lo_loc.file.name),
span);
}
- pub fn sub_type_ref_str(&mut self,
- span: Span,
- sub_span: Span,
- qualname: &str) {
+ pub fn sub_type_ref_str(&mut self, span: Span, sub_span: Span, qualname: &str) {
self.record_with_span(TypeRef,
span,
sub_span,
use syntax::ast;
use syntax::codemap::*;
use syntax::parse::lexer;
-use syntax::parse::lexer::{Reader,StringReader};
+use syntax::parse::lexer::{Reader, StringReader};
use syntax::parse::token;
use syntax::parse::token::{keywords, Token};
impl<'a> SpanUtils<'a> {
pub fn new(sess: &'a Session) -> SpanUtils<'a> {
- SpanUtils {
- sess: sess,
- err_count: Cell::new(0)
- }
+ SpanUtils { sess: sess, err_count: Cell::new(0) }
}
// Standard string for extents/location.
match sub_span {
None => None,
Some(sub) => {
- let FileMapAndBytePos {fm, pos} =
- self.sess.codemap().lookup_byte_offset(span.lo);
+ let FileMapAndBytePos {fm, pos} = self.sess.codemap().lookup_byte_offset(span.lo);
let base = pos + fm.start_pos;
Some(Span {
lo: base + self.sess.codemap().lookup_byte_offset(sub.lo).pos,
if ts.tok == token::Eof {
return self.make_sub_span(span, result)
}
- if bracket_count == 0 &&
- (ts.tok.is_ident() || ts.tok.is_keyword(keywords::SelfValue)) {
+ if bracket_count == 0 && (ts.tok.is_ident() || ts.tok.is_keyword(keywords::SelfValue)) {
result = Some(ts.sp);
}
token::Lt => 1,
token::Gt => -1,
token::BinOp(token::Shr) => -2,
- _ => 0
+ _ => 0,
}
}
}
if ts.tok == token::Eof {
return None;
}
- if bracket_count == 0 &&
- (ts.tok.is_ident() || ts.tok.is_keyword(keywords::SelfValue)) {
+ if bracket_count == 0 && (ts.tok.is_ident() || ts.tok.is_keyword(keywords::SelfValue)) {
return self.make_sub_span(span, Some(ts.sp));
}
token::Lt => 1,
token::Gt => -1,
token::BinOp(token::Shr) => -2,
- _ => 0
+ _ => 0,
}
}
}
last_span = None;
let mut next = toks.real_token();
- if (next.tok == token::OpenDelim(token::Paren) ||
- next.tok == token::Lt) &&
- bracket_count == 0 &&
- prev.tok.is_ident() {
+ if (next.tok == token::OpenDelim(token::Paren) || next.tok == token::Lt) &&
+ bracket_count == 0 && prev.tok.is_ident() {
result = Some(prev.sp);
}
- if bracket_count == 0 &&
- next.tok == token::ModSep {
+ if bracket_count == 0 && next.tok == token::ModSep {
let old = prev;
prev = next;
next = toks.real_token();
- if next.tok == token::Lt &&
- old.tok.is_ident() {
+ if next.tok == token::Lt && old.tok.is_ident() {
result = Some(old.sp);
}
}
token::OpenDelim(token::Paren) | token::Lt => 1,
token::CloseDelim(token::Paren) | token::Gt => -1,
token::BinOp(token::Shr) => -2,
- _ => 0
+ _ => 0,
};
if prev.tok.is_ident() && bracket_count == 0 {
loop {
let next = toks.real_token();
- if (next.tok == token::Lt ||
- next.tok == token::Colon) &&
- bracket_count == 0 &&
+ if (next.tok == token::Lt || next.tok == token::Colon) && bracket_count == 0 &&
prev.tok.is_ident() {
result = Some(prev.sp);
}
token::Gt => -1,
token::BinOp(token::Shl) => 2,
token::BinOp(token::Shr) => -2,
- _ => 0
+ _ => 0,
};
if next.tok == token::Eof {
token::Gt => -1,
token::BinOp(token::Shl) => 2,
token::BinOp(token::Shr) => -2,
- _ => 0
+ _ => 0,
};
// Ignore the `>::` in `<Type as Trait>::AssocTy`.
}
}
- pub fn sub_span_after_keyword(&self,
- span: Span,
- keyword: keywords::Keyword) -> Option<Span> {
+ pub fn sub_span_after_keyword(&self, span: Span, keyword: keywords::Keyword) -> Option<Span> {
self.sub_span_after(span, |t| t.is_keyword(keyword))
}
- pub fn sub_span_after_token(&self,
- span: Span,
- tok: Token) -> Option<Span> {
+ pub fn sub_span_after_token(&self, span: Span, tok: Token) -> Option<Span> {
self.sub_span_after(span, |t| t == tok)
}
- fn sub_span_after<F: Fn(Token) -> bool>(&self,
- span: Span,
- f: F) -> Option<Span> {
+ fn sub_span_after<F: Fn(Token) -> bool>(&self, span: Span, f: F) -> Option<Span> {
let mut toks = self.retokenise_span(span);
loop {
let ts = toks.real_token();