2015-05-04 05:33:07 -05:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! Output a CSV file containing the output from rustc's analysis. The data is
|
|
|
|
//! primarily designed to be used as input to the DXR tool, specifically its
|
|
|
|
//! Rust plugin. It could also be used by IDEs or other code browsing, search, or
|
|
|
|
//! cross-referencing tools.
|
|
|
|
//!
|
|
|
|
//! Dumping the analysis is implemented by walking the AST and getting a bunch of
|
|
|
|
//! info out from all over the place. We use Def IDs to identify objects. The
|
|
|
|
//! tricky part is getting syntactic (span, source text) and semantic (reference
|
|
|
|
//! Def IDs) information for parts of expressions which the compiler has discarded.
|
|
|
|
//! E.g., in a path `foo::bar::baz`, the compiler only keeps a span for the whole
|
|
|
|
//! path and a reference to `baz`, but we want spans and references for all three
|
|
|
|
//! idents.
|
|
|
|
//!
|
|
|
|
//! SpanUtils is used to manipulate spans. In particular, to extract sub-spans
|
|
|
|
//! from spans (e.g., the span for `bar` from the above example path).
|
|
|
|
//! Recorder is used for recording the output in csv format. FmtStrs separates
|
|
|
|
//! the format of the output away from extracting it from the compiler.
|
|
|
|
//! DumpCsvVisitor walks the AST and processes it.
|
|
|
|
|
2015-05-05 05:03:20 -05:00
|
|
|
|
|
|
|
use super::{escape, generated_code, recorder, SaveContext, PathCollector};
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
use session::Session;
|
|
|
|
|
|
|
|
use middle::def;
|
|
|
|
use middle::ty::{self, Ty};
|
2015-06-09 18:40:45 -05:00
|
|
|
use rustc::ast_map::NodeItem;
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
use std::cell::Cell;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
use syntax::ast_util;
|
|
|
|
use syntax::ast::{self, NodeId, DefId};
|
|
|
|
use syntax::codemap::*;
|
|
|
|
use syntax::parse::token::{self, get_ident, keywords};
|
|
|
|
use syntax::owned_slice::OwnedSlice;
|
|
|
|
use syntax::visit::{self, Visitor};
|
|
|
|
use syntax::print::pprust::{path_to_string, ty_to_string};
|
|
|
|
use syntax::ptr::P;
|
|
|
|
|
|
|
|
use super::span_utils::SpanUtils;
|
|
|
|
use super::recorder::{Recorder, FmtStrs};
|
|
|
|
|
2015-06-08 17:36:30 -05:00
|
|
|
macro_rules! down_cast_data {
|
|
|
|
($id:ident, $kind:ident, $this:ident, $sp:expr) => {
|
|
|
|
let $id = if let super::Data::$kind(data) = $id {
|
|
|
|
data
|
|
|
|
} else {
|
|
|
|
$this.sess.span_bug($sp, &format!("unexpected data kind: {:?}", $id));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
|
2015-05-05 02:27:44 -05:00
|
|
|
save_ctxt: SaveContext<'l, 'tcx>,
|
2015-05-04 05:33:07 -05:00
|
|
|
sess: &'l Session,
|
2015-06-13 17:49:28 -05:00
|
|
|
tcx: &'l ty::ctxt<'tcx>,
|
|
|
|
analysis: &'l ty::CrateAnalysis,
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
span: SpanUtils<'l>,
|
|
|
|
fmt: FmtStrs<'l>,
|
|
|
|
|
|
|
|
cur_scope: NodeId
|
|
|
|
}
|
|
|
|
|
|
|
|
impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
2015-06-13 17:49:28 -05:00
|
|
|
pub fn new(tcx: &'l ty::ctxt<'tcx>,
|
|
|
|
analysis: &'l ty::CrateAnalysis,
|
2015-05-04 05:33:07 -05:00
|
|
|
output_file: Box<File>) -> DumpCsvVisitor<'l, 'tcx> {
|
2015-06-13 17:49:28 -05:00
|
|
|
let span_utils = SpanUtils {
|
|
|
|
sess: &tcx.sess,
|
|
|
|
err_count: Cell::new(0)
|
|
|
|
};
|
2015-05-04 05:33:07 -05:00
|
|
|
DumpCsvVisitor {
|
2015-06-13 17:49:28 -05:00
|
|
|
sess: &tcx.sess,
|
|
|
|
tcx: tcx,
|
|
|
|
save_ctxt: SaveContext::new(tcx, span_utils.clone()),
|
2015-05-04 05:33:07 -05:00
|
|
|
analysis: analysis,
|
2015-06-13 17:49:28 -05:00
|
|
|
span: span_utils.clone(),
|
2015-05-04 05:33:07 -05:00
|
|
|
fmt: FmtStrs::new(box Recorder {
|
|
|
|
out: output_file,
|
|
|
|
dump_spans: false,
|
2015-06-13 17:49:28 -05:00
|
|
|
}, span_utils),
|
2015-05-10 15:35:08 -05:00
|
|
|
cur_scope: 0
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-05 01:46:09 -05:00
|
|
|
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;
|
|
|
|
f(self);
|
|
|
|
self.cur_scope = parent_scope;
|
|
|
|
}
|
|
|
|
|
2015-05-04 05:33:07 -05:00
|
|
|
pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) {
|
2015-05-05 01:46:09 -05:00
|
|
|
// The current crate.
|
2015-05-04 05:33:07 -05:00
|
|
|
self.fmt.crate_str(krate.span, name);
|
|
|
|
|
2015-05-05 01:46:09 -05:00
|
|
|
// Dump info about all the external crates referenced from this crate.
|
|
|
|
for c in &self.save_ctxt.get_external_crates() {
|
2015-05-10 15:35:08 -05:00
|
|
|
self.fmt.external_crate_str(krate.span, &c.name, c.number);
|
2015-05-05 01:46:09 -05:00
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
self.fmt.recorder.record("end_external_crates\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return all non-empty prefixes of a path.
|
|
|
|
// For each prefix, we return the span for the last segment in the prefix and
|
|
|
|
// a str representation of the entire prefix.
|
|
|
|
fn process_path_prefixes(&self, path: &ast::Path) -> Vec<(Span, String)> {
|
|
|
|
let spans = self.span.spans_for_path_segments(path);
|
|
|
|
|
|
|
|
// Paths to enums seem to not match their spans - the span includes all the
|
|
|
|
// variants too. But they seem to always be at the end, so I hope we can cope with
|
|
|
|
// always using the first ones. So, only error out if we don't have enough spans.
|
|
|
|
// What could go wrong...?
|
|
|
|
if spans.len() < path.segments.len() {
|
|
|
|
error!("Mis-calculated spans for path '{}'. \
|
|
|
|
Found {} spans, expected {}. Found spans:",
|
|
|
|
path_to_string(path), spans.len(), path.segments.len());
|
|
|
|
for s in &spans {
|
|
|
|
let loc = self.sess.codemap().lookup_char_pos(s.lo);
|
|
|
|
error!(" '{}' in {}, line {}",
|
|
|
|
self.span.snippet(*s), loc.file.name, loc.line);
|
|
|
|
}
|
|
|
|
return vec!();
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut result: Vec<(Span, String)> = vec!();
|
|
|
|
|
|
|
|
let mut segs = vec!();
|
2015-06-10 11:22:20 -05:00
|
|
|
for (i, (seg, span)) in path.segments.iter().zip(&spans).enumerate() {
|
2015-05-04 05:33:07 -05:00
|
|
|
segs.push(seg.clone());
|
|
|
|
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 {
|
|
|
|
path_to_string(&sub_path)
|
|
|
|
};
|
|
|
|
result.push((*span, qualname));
|
|
|
|
segs = sub_path.segments;
|
|
|
|
}
|
|
|
|
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
|
|
|
// The global arg allows us to override the global-ness of the path (which
|
|
|
|
// actually means 'does the path start with `::`', rather than 'is the path
|
|
|
|
// semantically global). We use the override for `use` imports (etc.) where
|
|
|
|
// the syntax is non-global, but the semantics are global.
|
|
|
|
fn write_sub_paths(&mut self, path: &ast::Path, global: bool) {
|
|
|
|
let sub_paths = self.process_path_prefixes(path);
|
|
|
|
for (i, &(ref span, ref qualname)) in sub_paths.iter().enumerate() {
|
|
|
|
let qualname = if i == 0 && global && !path.global {
|
|
|
|
format!("::{}", qualname)
|
|
|
|
} else {
|
|
|
|
qualname.clone()
|
|
|
|
};
|
|
|
|
self.fmt.sub_mod_ref_str(path.span,
|
|
|
|
*span,
|
2015-06-02 14:21:49 -05:00
|
|
|
&qualname,
|
2015-05-04 05:33:07 -05:00
|
|
|
self.cur_scope);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// As write_sub_paths, but does not process the last ident in the path (assuming it
|
|
|
|
// will be processed elsewhere). See note on write_sub_paths about global.
|
|
|
|
fn write_sub_paths_truncated(&mut self, path: &ast::Path, global: bool) {
|
|
|
|
let sub_paths = self.process_path_prefixes(path);
|
|
|
|
let len = sub_paths.len();
|
|
|
|
if len <= 1 {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let sub_paths = &sub_paths[..len-1];
|
|
|
|
for (i, &(ref span, ref qualname)) in sub_paths.iter().enumerate() {
|
|
|
|
let qualname = if i == 0 && global && !path.global {
|
|
|
|
format!("::{}", qualname)
|
|
|
|
} else {
|
|
|
|
qualname.clone()
|
|
|
|
};
|
|
|
|
self.fmt.sub_mod_ref_str(path.span,
|
|
|
|
*span,
|
2015-06-02 14:21:49 -05:00
|
|
|
&qualname,
|
2015-05-04 05:33:07 -05:00
|
|
|
self.cur_scope);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// As write_sub_paths, but expects a path of the form module_path::trait::method
|
|
|
|
// Where trait could actually be a struct too.
|
|
|
|
fn write_sub_path_trait_truncated(&mut self, path: &ast::Path) {
|
|
|
|
let sub_paths = self.process_path_prefixes(path);
|
|
|
|
let len = sub_paths.len();
|
|
|
|
if len <= 1 {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let sub_paths = &sub_paths[.. (len-1)];
|
|
|
|
|
|
|
|
// write the trait part of the sub-path
|
|
|
|
let (ref span, ref qualname) = sub_paths[len-2];
|
|
|
|
self.fmt.sub_type_ref_str(path.span,
|
|
|
|
*span,
|
2015-06-02 14:21:49 -05:00
|
|
|
&qualname);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
// write the other sub-paths
|
|
|
|
if len <= 2 {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let sub_paths = &sub_paths[..len-2];
|
|
|
|
for &(ref span, ref qualname) in sub_paths {
|
|
|
|
self.fmt.sub_mod_ref_str(path.span,
|
|
|
|
*span,
|
2015-06-02 14:21:49 -05:00
|
|
|
&qualname,
|
2015-05-04 05:33:07 -05:00
|
|
|
self.cur_scope);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// looks up anything, not just a type
|
|
|
|
fn lookup_type_ref(&self, ref_id: NodeId) -> Option<DefId> {
|
2015-06-13 17:49:28 -05:00
|
|
|
if !self.tcx.def_map.borrow().contains_key(&ref_id) {
|
2015-05-04 05:33:07 -05:00
|
|
|
self.sess.bug(&format!("def_map has no key for {} in lookup_type_ref",
|
|
|
|
ref_id));
|
|
|
|
}
|
2015-06-13 17:49:28 -05:00
|
|
|
let def = self.tcx.def_map.borrow().get(&ref_id).unwrap().full_def();
|
2015-05-04 05:33:07 -05:00
|
|
|
match def {
|
|
|
|
def::DefPrimTy(_) => None,
|
|
|
|
_ => Some(def.def_id()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lookup_def_kind(&self, ref_id: NodeId, span: Span) -> Option<recorder::Row> {
|
2015-06-13 17:49:28 -05:00
|
|
|
let def_map = self.tcx.def_map.borrow();
|
2015-05-04 05:33:07 -05:00
|
|
|
if !def_map.contains_key(&ref_id) {
|
|
|
|
self.sess.span_bug(span, &format!("def_map has no key for {} in lookup_def_kind",
|
|
|
|
ref_id));
|
|
|
|
}
|
|
|
|
let def = def_map.get(&ref_id).unwrap().full_def();
|
|
|
|
match def {
|
|
|
|
def::DefMod(_) |
|
|
|
|
def::DefForeignMod(_) => Some(recorder::ModRef),
|
2015-06-08 00:47:52 -05:00
|
|
|
def::DefStruct(_) => Some(recorder::TypeRef),
|
2015-05-04 05:33:07 -05:00
|
|
|
def::DefTy(..) |
|
|
|
|
def::DefAssociatedTy(..) |
|
|
|
|
def::DefTrait(_) => Some(recorder::TypeRef),
|
|
|
|
def::DefStatic(_, _) |
|
|
|
|
def::DefConst(_) |
|
|
|
|
def::DefAssociatedConst(..) |
|
|
|
|
def::DefLocal(_) |
|
|
|
|
def::DefVariant(_, _, _) |
|
|
|
|
def::DefUpvar(..) => Some(recorder::VarRef),
|
|
|
|
|
|
|
|
def::DefFn(..) => Some(recorder::FnRef),
|
|
|
|
|
|
|
|
def::DefSelfTy(..) |
|
|
|
|
def::DefRegion(_) |
|
|
|
|
def::DefLabel(_) |
|
|
|
|
def::DefTyParam(..) |
|
|
|
|
def::DefUse(_) |
|
|
|
|
def::DefMethod(..) |
|
|
|
|
def::DefPrimTy(_) => {
|
|
|
|
self.sess.span_bug(span, &format!("lookup_def_kind for unexpected item: {:?}",
|
|
|
|
def));
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_formals(&mut self, formals: &Vec<ast::Arg>, qualname: &str) {
|
|
|
|
for arg in formals {
|
2015-05-05 05:03:20 -05:00
|
|
|
self.visit_pat(&arg.pat);
|
|
|
|
let mut collector = PathCollector::new();
|
|
|
|
collector.visit_pat(&arg.pat);
|
2015-05-04 05:33:07 -05:00
|
|
|
let span_utils = self.span.clone();
|
2015-05-05 05:03:20 -05:00
|
|
|
for &(id, ref p, _, _) in &collector.collected_paths {
|
2015-06-18 12:25:05 -05:00
|
|
|
let typ = self.tcx.node_types().get(&id).unwrap().to_string();
|
2015-05-04 05:33:07 -05:00
|
|
|
// get the span only for the name of the variable (I hope the path is only ever a
|
|
|
|
// variable name, but who knows?)
|
|
|
|
self.fmt.formal_str(p.span,
|
|
|
|
span_utils.span_for_last_ident(p.span),
|
|
|
|
id,
|
|
|
|
qualname,
|
|
|
|
&path_to_string(p),
|
2015-06-02 14:21:49 -05:00
|
|
|
&typ);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_method(&mut self, sig: &ast::MethodSig,
|
|
|
|
body: Option<&ast::Block>,
|
|
|
|
id: ast::NodeId, name: ast::Name,
|
|
|
|
span: Span) {
|
|
|
|
if generated_code(span) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug!("process_method: {}:{}", id, token::get_name(name));
|
|
|
|
|
|
|
|
let mut scope_id;
|
|
|
|
// 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.
|
2015-06-13 17:49:28 -05:00
|
|
|
let qualname = match ty::impl_of_method(self.tcx, ast_util::local_def(id)) {
|
|
|
|
Some(impl_id) => match self.tcx.map.get(impl_id.node) {
|
2015-05-04 05:33:07 -05:00
|
|
|
NodeItem(item) => {
|
|
|
|
scope_id = item.id;
|
|
|
|
match item.node {
|
|
|
|
ast::ItemImpl(_, _, _, _, ref ty, _) => {
|
2015-06-08 09:55:35 -05:00
|
|
|
let mut result = String::from("<");
|
2015-05-04 05:33:07 -05:00
|
|
|
result.push_str(&ty_to_string(&**ty));
|
|
|
|
|
2015-06-13 17:49:28 -05:00
|
|
|
match ty::trait_of_item(self.tcx, ast_util::local_def(id)) {
|
2015-05-04 05:33:07 -05:00
|
|
|
Some(def_id) => {
|
|
|
|
result.push_str(" as ");
|
|
|
|
result.push_str(
|
2015-06-13 17:49:28 -05:00
|
|
|
&ty::item_path_str(self.tcx, def_id));
|
2015-05-04 05:33:07 -05:00
|
|
|
},
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
result.push_str(">");
|
|
|
|
result
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
self.sess.span_bug(span,
|
|
|
|
&format!("Container {} for method {} not an impl?",
|
|
|
|
impl_id.node, id));
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
self.sess.span_bug(span,
|
|
|
|
&format!("Container {} for method {} is not a node item {:?}",
|
2015-06-13 17:49:28 -05:00
|
|
|
impl_id.node, id, self.tcx.map.get(impl_id.node)));
|
2015-05-04 05:33:07 -05:00
|
|
|
},
|
|
|
|
},
|
2015-06-13 17:49:28 -05:00
|
|
|
None => match ty::trait_of_item(self.tcx, ast_util::local_def(id)) {
|
2015-05-04 05:33:07 -05:00
|
|
|
Some(def_id) => {
|
|
|
|
scope_id = def_id.node;
|
2015-06-13 17:49:28 -05:00
|
|
|
match self.tcx.map.get(def_id.node) {
|
2015-05-04 05:33:07 -05:00
|
|
|
NodeItem(_) => {
|
2015-06-13 17:49:28 -05:00
|
|
|
format!("::{}", ty::item_path_str(self.tcx, def_id))
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
self.sess.span_bug(span,
|
|
|
|
&format!("Could not find container {} for method {}",
|
|
|
|
def_id.node, id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
None => {
|
|
|
|
self.sess.span_bug(span,
|
|
|
|
&format!("Could not find container for method {}", id));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let qualname = &format!("{}::{}", qualname, &token::get_name(name));
|
|
|
|
|
|
|
|
// record the decl for this def (if it has one)
|
2015-06-13 17:49:28 -05:00
|
|
|
let decl_id = ty::trait_item_of_item(self.tcx, ast_util::local_def(id))
|
2015-05-04 05:33:07 -05:00
|
|
|
.and_then(|new_id| {
|
|
|
|
let def_id = new_id.def_id();
|
|
|
|
if def_id.node != 0 && def_id != ast_util::local_def(id) {
|
|
|
|
Some(def_id)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let sub_span = self.span.sub_span_after_keyword(span, keywords::Fn);
|
|
|
|
if body.is_some() {
|
|
|
|
self.fmt.method_str(span,
|
|
|
|
sub_span,
|
|
|
|
id,
|
|
|
|
qualname,
|
|
|
|
decl_id,
|
|
|
|
scope_id);
|
|
|
|
self.process_formals(&sig.decl.inputs, qualname);
|
|
|
|
} else {
|
|
|
|
self.fmt.method_decl_str(span,
|
|
|
|
sub_span,
|
|
|
|
id,
|
|
|
|
qualname,
|
|
|
|
scope_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk arg and return types
|
|
|
|
for arg in &sig.decl.inputs {
|
|
|
|
self.visit_ty(&arg.ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let ast::Return(ref ret_ty) = sig.decl.output {
|
|
|
|
self.visit_ty(ret_ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk the fn body
|
|
|
|
if let Some(body) = body {
|
|
|
|
self.nest(id, |v| v.visit_block(body));
|
|
|
|
}
|
|
|
|
|
|
|
|
self.process_generic_params(&sig.generics,
|
|
|
|
span,
|
|
|
|
qualname,
|
|
|
|
id);
|
|
|
|
}
|
|
|
|
|
2015-06-05 00:50:04 -05:00
|
|
|
fn process_trait_ref(&mut self, trait_ref: &ast::TraitRef) {
|
|
|
|
let trait_ref_data = self.save_ctxt.get_trait_ref_data(trait_ref, self.cur_scope);
|
|
|
|
if let Some(trait_ref_data) = trait_ref_data {
|
|
|
|
self.fmt.ref_str(recorder::TypeRef,
|
|
|
|
trait_ref.path.span,
|
|
|
|
Some(trait_ref_data.span),
|
|
|
|
trait_ref_data.ref_id,
|
|
|
|
trait_ref_data.scope);
|
|
|
|
visit::walk_path(self, &trait_ref.path);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_struct_field_def(&mut self,
|
|
|
|
field: &ast::StructField,
|
2015-06-04 23:03:48 -05:00
|
|
|
parent_id: NodeId) {
|
|
|
|
let field_data = self.save_ctxt.get_field_data(field, parent_id);
|
|
|
|
if let Some(field_data) = field_data {
|
2015-06-08 17:36:30 -05:00
|
|
|
down_cast_data!(field_data, VariableData, self, field.span);
|
|
|
|
self.fmt.field_str(field.span,
|
|
|
|
Some(field_data.span),
|
|
|
|
field_data.id,
|
|
|
|
&field_data.name,
|
|
|
|
&field_data.qualname,
|
|
|
|
&field_data.type_value,
|
|
|
|
field_data.scope);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dump generic params bindings, then visit_generics
|
|
|
|
fn process_generic_params(&mut self,
|
|
|
|
generics:&ast::Generics,
|
|
|
|
full_span: Span,
|
|
|
|
prefix: &str,
|
|
|
|
id: NodeId) {
|
|
|
|
// We can't only use visit_generics since we don't have spans for param
|
|
|
|
// bindings, so we reparse the full_span to get those sub spans.
|
|
|
|
// However full span is the entire enum/fn/struct block, so we only want
|
|
|
|
// the first few to match the number of generics we're looking for.
|
|
|
|
let param_sub_spans = self.span.spans_for_ty_params(full_span,
|
|
|
|
(generics.ty_params.len() as isize));
|
2015-06-10 11:22:20 -05:00
|
|
|
for (param, param_ss) in generics.ty_params.iter().zip(param_sub_spans) {
|
2015-05-04 05:33:07 -05:00
|
|
|
// Append $id to name to make sure each one is unique
|
|
|
|
let name = format!("{}::{}${}",
|
|
|
|
prefix,
|
2015-06-10 11:22:20 -05:00
|
|
|
escape(self.span.snippet(param_ss)),
|
2015-05-04 05:33:07 -05:00
|
|
|
id);
|
|
|
|
self.fmt.typedef_str(full_span,
|
2015-06-10 11:22:20 -05:00
|
|
|
Some(param_ss),
|
2015-05-04 05:33:07 -05:00
|
|
|
param.id,
|
2015-06-02 14:21:49 -05:00
|
|
|
&name,
|
2015-05-04 05:33:07 -05:00
|
|
|
"");
|
|
|
|
}
|
|
|
|
self.visit_generics(generics);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_fn(&mut self,
|
|
|
|
item: &ast::Item,
|
|
|
|
decl: &ast::FnDecl,
|
|
|
|
ty_params: &ast::Generics,
|
|
|
|
body: &ast::Block) {
|
2015-05-10 15:35:08 -05:00
|
|
|
let fn_data = self.save_ctxt.get_item_data(item);
|
2015-06-08 17:36:30 -05:00
|
|
|
down_cast_data!(fn_data, FunctionData, self, item.span);
|
|
|
|
self.fmt.fn_str(item.span,
|
|
|
|
Some(fn_data.span),
|
|
|
|
fn_data.id,
|
|
|
|
&fn_data.qualname,
|
|
|
|
fn_data.scope);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
|
2015-06-08 17:36:30 -05:00
|
|
|
self.process_formals(&decl.inputs, &fn_data.qualname);
|
|
|
|
self.process_generic_params(ty_params, item.span, &fn_data.qualname, item.id);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
for arg in &decl.inputs {
|
2015-05-10 15:35:08 -05:00
|
|
|
self.visit_ty(&arg.ty);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if let ast::Return(ref ret_ty) = decl.output {
|
2015-05-10 15:35:08 -05:00
|
|
|
self.visit_ty(&ret_ty);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
2015-05-10 15:35:08 -05:00
|
|
|
self.nest(item.id, |v| v.visit_block(&body));
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
2015-05-10 15:35:08 -05:00
|
|
|
fn process_static_or_const_item(&mut self,
|
|
|
|
item: &ast::Item,
|
|
|
|
typ: &ast::Ty,
|
|
|
|
expr: &ast::Expr)
|
2015-05-04 05:33:07 -05:00
|
|
|
{
|
2015-05-10 15:35:08 -05:00
|
|
|
let var_data = self.save_ctxt.get_item_data(item);
|
2015-06-08 17:36:30 -05:00
|
|
|
down_cast_data!(var_data, VariableData, self, item.span);
|
|
|
|
self.fmt.static_str(item.span,
|
|
|
|
Some(var_data.span),
|
|
|
|
var_data.id,
|
|
|
|
&var_data.name,
|
|
|
|
&var_data.qualname,
|
|
|
|
&var_data.value,
|
|
|
|
&var_data.type_value,
|
|
|
|
var_data.scope);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2015-05-10 15:35:08 -05:00
|
|
|
self.visit_ty(&typ);
|
2015-05-04 05:33:07 -05:00
|
|
|
self.visit_expr(expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_const(&mut self,
|
|
|
|
id: ast::NodeId,
|
|
|
|
ident: &ast::Ident,
|
|
|
|
span: Span,
|
|
|
|
typ: &ast::Ty,
|
|
|
|
expr: &ast::Expr)
|
|
|
|
{
|
2015-06-13 17:49:28 -05:00
|
|
|
let qualname = format!("::{}", self.tcx.map.path_to_string(id));
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
let sub_span = self.span.sub_span_after_keyword(span,
|
|
|
|
keywords::Const);
|
2015-05-10 15:35:08 -05:00
|
|
|
|
2015-05-04 05:33:07 -05:00
|
|
|
self.fmt.static_str(span,
|
|
|
|
sub_span,
|
|
|
|
id,
|
|
|
|
&get_ident((*ident).clone()),
|
2015-06-02 14:21:49 -05:00
|
|
|
&qualname,
|
2015-05-10 15:35:08 -05:00
|
|
|
&self.span.snippet(expr.span),
|
2015-05-04 05:33:07 -05:00
|
|
|
&ty_to_string(&*typ),
|
|
|
|
self.cur_scope);
|
|
|
|
|
|
|
|
// walk type and init value
|
|
|
|
self.visit_ty(typ);
|
|
|
|
self.visit_expr(expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_struct(&mut self,
|
|
|
|
item: &ast::Item,
|
|
|
|
def: &ast::StructDef,
|
|
|
|
ty_params: &ast::Generics) {
|
2015-06-13 17:49:28 -05:00
|
|
|
let qualname = format!("::{}", self.tcx.map.path_to_string(item.id));
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
let ctor_id = match def.ctor_id {
|
|
|
|
Some(node_id) => node_id,
|
|
|
|
None => -1,
|
|
|
|
};
|
|
|
|
let val = self.span.snippet(item.span);
|
|
|
|
let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Struct);
|
|
|
|
self.fmt.struct_str(item.span,
|
|
|
|
sub_span,
|
|
|
|
item.id,
|
|
|
|
ctor_id,
|
2015-06-02 14:21:49 -05:00
|
|
|
&qualname,
|
2015-05-04 05:33:07 -05:00
|
|
|
self.cur_scope,
|
2015-06-02 14:21:49 -05:00
|
|
|
&val);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
// fields
|
|
|
|
for field in &def.fields {
|
2015-06-04 23:03:48 -05:00
|
|
|
self.process_struct_field_def(field, item.id);
|
|
|
|
self.visit_ty(&field.node.ty);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
2015-06-02 14:21:49 -05:00
|
|
|
self.process_generic_params(ty_params, item.span, &qualname, item.id);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn process_enum(&mut self,
|
|
|
|
item: &ast::Item,
|
|
|
|
enum_definition: &ast::EnumDef,
|
|
|
|
ty_params: &ast::Generics) {
|
2015-06-02 14:21:20 -05:00
|
|
|
let enum_data = self.save_ctxt.get_item_data(item);
|
2015-06-08 17:36:30 -05:00
|
|
|
down_cast_data!(enum_data, EnumData, self, item.span);
|
|
|
|
self.fmt.enum_str(item.span,
|
|
|
|
Some(enum_data.span),
|
|
|
|
enum_data.id,
|
|
|
|
&enum_data.qualname,
|
|
|
|
enum_data.scope,
|
|
|
|
&enum_data.value);
|
|
|
|
|
|
|
|
for variant in &enum_definition.variants {
|
|
|
|
let name = &get_ident(variant.node.name);
|
|
|
|
let mut qualname = enum_data.qualname.clone();
|
|
|
|
qualname.push_str("::");
|
|
|
|
qualname.push_str(name);
|
|
|
|
let val = self.span.snippet(variant.span);
|
|
|
|
match variant.node.kind {
|
|
|
|
ast::TupleVariantKind(ref args) => {
|
|
|
|
// first ident in span is the variant's name
|
|
|
|
self.fmt.tuple_variant_str(variant.span,
|
|
|
|
self.span.span_for_first_ident(variant.span),
|
|
|
|
variant.node.id,
|
|
|
|
name,
|
|
|
|
&qualname,
|
|
|
|
&enum_data.qualname,
|
|
|
|
&val,
|
|
|
|
enum_data.id);
|
|
|
|
for arg in args {
|
|
|
|
self.visit_ty(&*arg.ty);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2015-06-08 17:36:30 -05:00
|
|
|
}
|
|
|
|
ast::StructVariantKind(ref struct_def) => {
|
|
|
|
let ctor_id = match struct_def.ctor_id {
|
|
|
|
Some(node_id) => node_id,
|
|
|
|
None => -1,
|
|
|
|
};
|
|
|
|
self.fmt.struct_variant_str(variant.span,
|
|
|
|
self.span.span_for_first_ident(variant.span),
|
|
|
|
variant.node.id,
|
|
|
|
ctor_id,
|
|
|
|
&qualname,
|
|
|
|
&enum_data.qualname,
|
|
|
|
&val,
|
|
|
|
enum_data.id);
|
|
|
|
|
|
|
|
for field in &struct_def.fields {
|
|
|
|
self.process_struct_field_def(field, variant.node.id);
|
|
|
|
self.visit_ty(&*field.node.ty);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-08 17:36:30 -05:00
|
|
|
self.process_generic_params(ty_params, item.span, &enum_data.qualname, enum_data.id);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn process_impl(&mut self,
|
|
|
|
item: &ast::Item,
|
|
|
|
type_parameters: &ast::Generics,
|
|
|
|
trait_ref: &Option<ast::TraitRef>,
|
|
|
|
typ: &ast::Ty,
|
|
|
|
impl_items: &[P<ast::ImplItem>]) {
|
2015-06-05 00:50:04 -05:00
|
|
|
let impl_data = self.save_ctxt.get_item_data(item);
|
2015-06-08 17:36:30 -05:00
|
|
|
down_cast_data!(impl_data, ImplData, self, item.span);
|
|
|
|
match impl_data.self_ref {
|
|
|
|
Some(ref self_ref) => {
|
2015-06-05 00:50:04 -05:00
|
|
|
self.fmt.ref_str(recorder::TypeRef,
|
|
|
|
item.span,
|
2015-06-08 17:36:30 -05:00
|
|
|
Some(self_ref.span),
|
|
|
|
self_ref.ref_id,
|
|
|
|
self_ref.scope);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2015-06-08 17:36:30 -05:00
|
|
|
None => {
|
|
|
|
self.visit_ty(&typ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(ref trait_ref_data) = impl_data.trait_ref {
|
|
|
|
self.fmt.ref_str(recorder::TypeRef,
|
|
|
|
item.span,
|
|
|
|
Some(trait_ref_data.span),
|
|
|
|
trait_ref_data.ref_id,
|
|
|
|
trait_ref_data.scope);
|
|
|
|
visit::walk_path(self, &trait_ref.as_ref().unwrap().path);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
2015-06-08 17:36:30 -05:00
|
|
|
self.fmt.impl_str(item.span,
|
|
|
|
Some(impl_data.span),
|
|
|
|
impl_data.id,
|
|
|
|
impl_data.self_ref.map(|data| data.ref_id),
|
|
|
|
impl_data.trait_ref.map(|data| data.ref_id),
|
|
|
|
impl_data.scope);
|
|
|
|
|
2015-05-04 05:33:07 -05:00
|
|
|
self.process_generic_params(type_parameters, item.span, "", item.id);
|
|
|
|
for impl_item in impl_items {
|
|
|
|
self.visit_impl_item(impl_item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_trait(&mut self,
|
|
|
|
item: &ast::Item,
|
|
|
|
generics: &ast::Generics,
|
|
|
|
trait_refs: &OwnedSlice<ast::TyParamBound>,
|
|
|
|
methods: &[P<ast::TraitItem>]) {
|
2015-06-13 17:49:28 -05:00
|
|
|
let qualname = format!("::{}", self.tcx.map.path_to_string(item.id));
|
2015-05-04 05:33:07 -05:00
|
|
|
let val = self.span.snippet(item.span);
|
|
|
|
let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Trait);
|
|
|
|
self.fmt.trait_str(item.span,
|
|
|
|
sub_span,
|
|
|
|
item.id,
|
2015-06-02 14:21:49 -05:00
|
|
|
&qualname,
|
2015-05-04 05:33:07 -05:00
|
|
|
self.cur_scope,
|
2015-06-02 14:21:49 -05:00
|
|
|
&val);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
// super-traits
|
2015-06-08 16:51:54 -05:00
|
|
|
for super_bound in trait_refs.iter() {
|
2015-05-04 05:33:07 -05:00
|
|
|
let trait_ref = match *super_bound {
|
|
|
|
ast::TraitTyParamBound(ref trait_ref, _) => {
|
|
|
|
trait_ref
|
|
|
|
}
|
|
|
|
ast::RegionTyParamBound(..) => {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let trait_ref = &trait_ref.trait_ref;
|
|
|
|
match self.lookup_type_ref(trait_ref.ref_id) {
|
|
|
|
Some(id) => {
|
|
|
|
let sub_span = self.span.sub_span_for_type_name(trait_ref.path.span);
|
|
|
|
self.fmt.ref_str(recorder::TypeRef,
|
|
|
|
trait_ref.path.span,
|
|
|
|
sub_span,
|
|
|
|
id,
|
|
|
|
self.cur_scope);
|
|
|
|
self.fmt.inherit_str(trait_ref.path.span,
|
|
|
|
sub_span,
|
|
|
|
id,
|
|
|
|
item.id);
|
|
|
|
},
|
|
|
|
None => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk generics and methods
|
2015-06-02 14:21:49 -05:00
|
|
|
self.process_generic_params(generics, item.span, &qualname, item.id);
|
2015-05-04 05:33:07 -05:00
|
|
|
for method in methods {
|
|
|
|
self.visit_trait_item(method)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_mod(&mut self,
|
2015-05-25 17:35:53 -05:00
|
|
|
item: &ast::Item) { // The module in question, represented as an item.
|
|
|
|
let mod_data = self.save_ctxt.get_item_data(item);
|
2015-06-08 17:36:30 -05:00
|
|
|
down_cast_data!(mod_data, ModData, self, item.span);
|
|
|
|
self.fmt.mod_str(item.span,
|
|
|
|
Some(mod_data.span),
|
|
|
|
mod_data.id,
|
|
|
|
&mod_data.qualname,
|
|
|
|
mod_data.scope,
|
|
|
|
&mod_data.filename);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn process_path(&mut self,
|
|
|
|
id: NodeId,
|
|
|
|
span: Span,
|
|
|
|
path: &ast::Path,
|
|
|
|
ref_kind: Option<recorder::Row>) {
|
|
|
|
if generated_code(span) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-06-13 17:49:28 -05:00
|
|
|
let def_map = self.tcx.def_map.borrow();
|
2015-05-04 05:33:07 -05:00
|
|
|
if !def_map.contains_key(&id) {
|
|
|
|
self.sess.span_bug(span,
|
|
|
|
&format!("def_map has no key for {} in visit_expr", id));
|
|
|
|
}
|
|
|
|
let def = def_map.get(&id).unwrap().full_def();
|
|
|
|
let sub_span = self.span.span_for_last_ident(span);
|
|
|
|
match def {
|
|
|
|
def::DefUpvar(..) |
|
|
|
|
def::DefLocal(..) |
|
|
|
|
def::DefStatic(..) |
|
|
|
|
def::DefConst(..) |
|
|
|
|
def::DefAssociatedConst(..) |
|
|
|
|
def::DefVariant(..) => self.fmt.ref_str(ref_kind.unwrap_or(recorder::VarRef),
|
|
|
|
span,
|
|
|
|
sub_span,
|
|
|
|
def.def_id(),
|
|
|
|
self.cur_scope),
|
2015-06-08 00:47:52 -05:00
|
|
|
def::DefStruct(def_id) => self.fmt.ref_str(recorder::TypeRef,
|
2015-05-04 05:33:07 -05:00
|
|
|
span,
|
|
|
|
sub_span,
|
|
|
|
def_id,
|
|
|
|
self.cur_scope),
|
|
|
|
def::DefTy(def_id, _) => self.fmt.ref_str(recorder::TypeRef,
|
|
|
|
span,
|
|
|
|
sub_span,
|
|
|
|
def_id,
|
|
|
|
self.cur_scope),
|
|
|
|
def::DefMethod(declid, provenence) => {
|
|
|
|
let sub_span = self.span.sub_span_for_meth_name(span);
|
|
|
|
let defid = if declid.krate == ast::LOCAL_CRATE {
|
2015-06-13 17:49:28 -05:00
|
|
|
let ti = ty::impl_or_trait_item(self.tcx, declid);
|
2015-05-04 05:33:07 -05:00
|
|
|
match provenence {
|
|
|
|
def::FromTrait(def_id) => {
|
2015-06-13 17:49:28 -05:00
|
|
|
Some(ty::trait_items(self.tcx, def_id)
|
2015-05-04 05:33:07 -05:00
|
|
|
.iter()
|
|
|
|
.find(|mr| {
|
|
|
|
mr.name() == ti.name()
|
|
|
|
})
|
|
|
|
.unwrap()
|
|
|
|
.def_id())
|
|
|
|
}
|
|
|
|
def::FromImpl(def_id) => {
|
2015-06-13 17:49:28 -05:00
|
|
|
let impl_items = self.tcx.impl_items.borrow();
|
2015-05-04 05:33:07 -05:00
|
|
|
Some(impl_items.get(&def_id)
|
|
|
|
.unwrap()
|
|
|
|
.iter()
|
|
|
|
.find(|mr| {
|
|
|
|
ty::impl_or_trait_item(
|
2015-06-13 17:49:28 -05:00
|
|
|
self.tcx,
|
2015-05-04 05:33:07 -05:00
|
|
|
mr.def_id()
|
|
|
|
).name() == ti.name()
|
|
|
|
})
|
|
|
|
.unwrap()
|
|
|
|
.def_id())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
self.fmt.meth_call_str(span,
|
|
|
|
sub_span,
|
|
|
|
defid,
|
|
|
|
Some(declid),
|
|
|
|
self.cur_scope);
|
|
|
|
},
|
|
|
|
def::DefFn(def_id, _) => {
|
|
|
|
self.fmt.fn_call_str(span,
|
|
|
|
sub_span,
|
|
|
|
def_id,
|
|
|
|
self.cur_scope)
|
|
|
|
}
|
|
|
|
_ => self.sess.span_bug(span,
|
|
|
|
&format!("Unexpected def kind while looking \
|
|
|
|
up path in `{}`: `{:?}`",
|
|
|
|
self.span.snippet(span),
|
|
|
|
def)),
|
|
|
|
}
|
|
|
|
// modules or types in the path prefix
|
|
|
|
match def {
|
|
|
|
def::DefMethod(did, _) => {
|
2015-06-13 17:49:28 -05:00
|
|
|
let ti = ty::impl_or_trait_item(self.tcx, did);
|
2015-05-04 05:33:07 -05:00
|
|
|
if let ty::MethodTraitItem(m) = ti {
|
|
|
|
if m.explicit_self == ty::StaticExplicitSelfCategory {
|
|
|
|
self.write_sub_path_trait_truncated(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
def::DefLocal(_) |
|
|
|
|
def::DefStatic(_,_) |
|
|
|
|
def::DefConst(..) |
|
|
|
|
def::DefAssociatedConst(..) |
|
|
|
|
def::DefStruct(_) |
|
|
|
|
def::DefVariant(..) |
|
|
|
|
def::DefFn(..) => self.write_sub_paths_truncated(path, false),
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_struct_lit(&mut self,
|
|
|
|
ex: &ast::Expr,
|
|
|
|
path: &ast::Path,
|
|
|
|
fields: &Vec<ast::Field>,
|
|
|
|
base: &Option<P<ast::Expr>>) {
|
|
|
|
if generated_code(path.span) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
self.write_sub_paths_truncated(path, false);
|
|
|
|
|
2015-06-14 17:06:01 -05:00
|
|
|
if let Some(struct_lit_data) = self.save_ctxt.get_expr_data(ex) {
|
|
|
|
down_cast_data!(struct_lit_data, TypeRefData, self, ex.span);
|
|
|
|
self.fmt.ref_str(recorder::TypeRef,
|
|
|
|
ex.span,
|
|
|
|
Some(struct_lit_data.span),
|
|
|
|
struct_lit_data.ref_id,
|
|
|
|
struct_lit_data.scope);
|
|
|
|
let struct_def = struct_lit_data.ref_id;
|
|
|
|
|
|
|
|
for field in fields {
|
|
|
|
if generated_code(field.ident.span) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2015-06-14 17:06:01 -05:00
|
|
|
let field_data = self.save_ctxt.get_field_ref_data(field,
|
|
|
|
struct_def,
|
|
|
|
self.cur_scope);
|
|
|
|
self.fmt.ref_str(recorder::VarRef,
|
|
|
|
field.ident.span,
|
|
|
|
Some(field_data.span),
|
|
|
|
field_data.ref_id,
|
|
|
|
field_data.scope);
|
2015-06-08 16:51:54 -05:00
|
|
|
|
2015-06-14 17:06:01 -05:00
|
|
|
self.visit_expr(&field.expr)
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2015-06-08 16:51:54 -05:00
|
|
|
|
2015-05-04 05:33:07 -05:00
|
|
|
visit::walk_expr_opt(self, base)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_method_call(&mut self,
|
|
|
|
ex: &ast::Expr,
|
|
|
|
args: &Vec<P<ast::Expr>>) {
|
2015-06-13 17:49:28 -05:00
|
|
|
let method_map = self.tcx.method_map.borrow();
|
2015-05-04 05:33:07 -05:00
|
|
|
let method_callee = method_map.get(&ty::MethodCall::expr(ex.id)).unwrap();
|
|
|
|
let (def_id, decl_id) = match method_callee.origin {
|
|
|
|
ty::MethodStatic(def_id) |
|
|
|
|
ty::MethodStaticClosure(def_id) => {
|
|
|
|
// method invoked on an object with a concrete type (not a static method)
|
|
|
|
let decl_id =
|
2015-06-13 17:49:28 -05:00
|
|
|
match ty::trait_item_of_item(self.tcx, def_id) {
|
2015-05-04 05:33:07 -05:00
|
|
|
None => None,
|
|
|
|
Some(decl_id) => Some(decl_id.def_id()),
|
|
|
|
};
|
|
|
|
|
|
|
|
// This incantation is required if the method referenced is a
|
|
|
|
// trait's default implementation.
|
2015-06-13 17:49:28 -05:00
|
|
|
let def_id = match ty::impl_or_trait_item(self.tcx, def_id) {
|
2015-05-04 05:33:07 -05:00
|
|
|
ty::MethodTraitItem(method) => {
|
|
|
|
method.provided_source.unwrap_or(def_id)
|
|
|
|
}
|
|
|
|
_ => self.sess
|
|
|
|
.span_bug(ex.span,
|
|
|
|
"save::process_method_call: non-method \
|
|
|
|
DefId in MethodStatic or MethodStaticClosure"),
|
|
|
|
};
|
|
|
|
(Some(def_id), decl_id)
|
|
|
|
}
|
|
|
|
ty::MethodTypeParam(ref mp) => {
|
|
|
|
// method invoked on a type parameter
|
2015-06-13 17:49:28 -05:00
|
|
|
let trait_item = ty::trait_item(self.tcx,
|
2015-05-04 05:33:07 -05:00
|
|
|
mp.trait_ref.def_id,
|
|
|
|
mp.method_num);
|
|
|
|
(None, Some(trait_item.def_id()))
|
|
|
|
}
|
|
|
|
ty::MethodTraitObject(ref mo) => {
|
|
|
|
// method invoked on a trait instance
|
2015-06-13 17:49:28 -05:00
|
|
|
let trait_item = ty::trait_item(self.tcx,
|
2015-05-04 05:33:07 -05:00
|
|
|
mo.trait_ref.def_id,
|
|
|
|
mo.method_num);
|
|
|
|
(None, Some(trait_item.def_id()))
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let sub_span = self.span.sub_span_for_meth_name(ex.span);
|
|
|
|
self.fmt.meth_call_str(ex.span,
|
|
|
|
sub_span,
|
|
|
|
def_id,
|
|
|
|
decl_id,
|
|
|
|
self.cur_scope);
|
|
|
|
|
|
|
|
// walk receiver and args
|
2015-06-02 14:21:49 -05:00
|
|
|
visit::walk_exprs(self, &args);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn process_pat(&mut self, p:&ast::Pat) {
|
|
|
|
if generated_code(p.span) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
match p.node {
|
|
|
|
ast::PatStruct(ref path, ref fields, _) => {
|
|
|
|
visit::walk_path(self, path);
|
|
|
|
|
2015-06-13 17:49:28 -05:00
|
|
|
let def = self.tcx.def_map.borrow().get(&p.id).unwrap().full_def();
|
2015-05-04 05:33:07 -05:00
|
|
|
let struct_def = match def {
|
|
|
|
def::DefConst(..) | def::DefAssociatedConst(..) => None,
|
|
|
|
def::DefVariant(_, variant_id, _) => Some(variant_id),
|
|
|
|
_ => {
|
2015-06-13 17:49:28 -05:00
|
|
|
match ty::ty_to_def_id(ty::node_id_to_type(self.tcx, p.id)) {
|
2015-05-04 05:33:07 -05:00
|
|
|
None => {
|
|
|
|
self.sess.span_bug(p.span,
|
|
|
|
&format!("Could not find struct_def for `{}`",
|
|
|
|
self.span.snippet(p.span)));
|
|
|
|
}
|
|
|
|
Some(def_id) => Some(def_id),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if let Some(struct_def) = struct_def {
|
2015-06-13 17:49:28 -05:00
|
|
|
let struct_fields = ty::lookup_struct_fields(self.tcx, struct_def);
|
2015-05-04 05:33:07 -05:00
|
|
|
for &Spanned { node: ref field, span } in fields {
|
|
|
|
let sub_span = self.span.span_for_first_ident(span);
|
|
|
|
for f in &struct_fields {
|
|
|
|
if f.name == field.ident.name {
|
|
|
|
self.fmt.ref_str(recorder::VarRef,
|
|
|
|
span,
|
|
|
|
sub_span,
|
|
|
|
f.id,
|
|
|
|
self.cur_scope);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.visit_pat(&*field.pat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => visit::walk_pat(self, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
|
|
|
|
fn visit_item(&mut self, item: &ast::Item) {
|
|
|
|
if generated_code(item.span) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
match item.node {
|
|
|
|
ast::ItemUse(ref use_item) => {
|
|
|
|
match use_item.node {
|
|
|
|
ast::ViewPathSimple(ident, ref path) => {
|
|
|
|
let sub_span = self.span.span_for_last_ident(path.span);
|
|
|
|
let mod_id = match self.lookup_type_ref(item.id) {
|
|
|
|
Some(def_id) => {
|
|
|
|
match self.lookup_def_kind(item.id, path.span) {
|
|
|
|
Some(kind) => self.fmt.ref_str(kind,
|
|
|
|
path.span,
|
|
|
|
sub_span,
|
|
|
|
def_id,
|
|
|
|
self.cur_scope),
|
|
|
|
None => {},
|
|
|
|
}
|
|
|
|
Some(def_id)
|
|
|
|
},
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
|
|
|
// 'use' always introduces an alias, if there is not an explicit
|
|
|
|
// one, there is an implicit one.
|
|
|
|
let sub_span =
|
|
|
|
match self.span.sub_span_after_keyword(use_item.span, keywords::As) {
|
|
|
|
Some(sub_span) => Some(sub_span),
|
|
|
|
None => sub_span,
|
|
|
|
};
|
|
|
|
|
|
|
|
self.fmt.use_alias_str(path.span,
|
|
|
|
sub_span,
|
|
|
|
item.id,
|
|
|
|
mod_id,
|
|
|
|
&get_ident(ident),
|
|
|
|
self.cur_scope);
|
|
|
|
self.write_sub_paths_truncated(path, true);
|
|
|
|
}
|
|
|
|
ast::ViewPathGlob(ref path) => {
|
|
|
|
// Make a comma-separated list of names of imported modules.
|
|
|
|
let mut name_string = String::new();
|
|
|
|
let glob_map = &self.analysis.glob_map;
|
|
|
|
let glob_map = glob_map.as_ref().unwrap();
|
|
|
|
if glob_map.contains_key(&item.id) {
|
|
|
|
for n in glob_map.get(&item.id).unwrap() {
|
|
|
|
if !name_string.is_empty() {
|
|
|
|
name_string.push_str(", ");
|
|
|
|
}
|
|
|
|
name_string.push_str(n.as_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let sub_span = self.span.sub_span_of_token(path.span,
|
|
|
|
token::BinOp(token::Star));
|
|
|
|
self.fmt.use_glob_str(path.span,
|
|
|
|
sub_span,
|
|
|
|
item.id,
|
|
|
|
&name_string,
|
|
|
|
self.cur_scope);
|
|
|
|
self.write_sub_paths(path, true);
|
|
|
|
}
|
|
|
|
ast::ViewPathList(ref path, ref list) => {
|
|
|
|
for plid in list {
|
|
|
|
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(
|
|
|
|
kind, plid.span,
|
|
|
|
Some(plid.span),
|
|
|
|
def_id, self.cur_scope);
|
|
|
|
}
|
|
|
|
None => ()
|
|
|
|
},
|
|
|
|
None => ()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ast::PathListMod { .. } => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.write_sub_paths(path, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast::ItemExternCrate(ref s) => {
|
|
|
|
let name = get_ident(item.ident);
|
|
|
|
let name = &name;
|
|
|
|
let location = match *s {
|
|
|
|
Some(s) => s.to_string(),
|
|
|
|
None => name.to_string(),
|
|
|
|
};
|
|
|
|
let alias_span = self.span.span_for_last_ident(item.span);
|
|
|
|
let cnum = match self.sess.cstore.find_extern_mod_stmt_cnum(item.id) {
|
|
|
|
Some(cnum) => cnum,
|
|
|
|
None => 0,
|
|
|
|
};
|
|
|
|
self.fmt.extern_crate_str(item.span,
|
|
|
|
alias_span,
|
|
|
|
item.id,
|
|
|
|
cnum,
|
|
|
|
name,
|
2015-06-02 14:21:49 -05:00
|
|
|
&location,
|
2015-05-04 05:33:07 -05:00
|
|
|
self.cur_scope);
|
|
|
|
}
|
2015-05-05 07:47:04 -05:00
|
|
|
ast::ItemFn(ref decl, _, _, _, ref ty_params, ref body) =>
|
2015-05-04 05:33:07 -05:00
|
|
|
self.process_fn(item, &**decl, ty_params, &**body),
|
2015-05-10 15:35:08 -05:00
|
|
|
ast::ItemStatic(ref typ, _, ref expr) =>
|
|
|
|
self.process_static_or_const_item(item, typ, expr),
|
2015-05-04 05:33:07 -05:00
|
|
|
ast::ItemConst(ref typ, ref expr) =>
|
2015-05-10 15:35:08 -05:00
|
|
|
self.process_static_or_const_item(item, &typ, &expr),
|
2015-05-04 05:33:07 -05:00
|
|
|
ast::ItemStruct(ref def, ref ty_params) => self.process_struct(item, &**def, ty_params),
|
|
|
|
ast::ItemEnum(ref def, ref ty_params) => self.process_enum(item, def, ty_params),
|
|
|
|
ast::ItemImpl(_, _,
|
|
|
|
ref ty_params,
|
|
|
|
ref trait_ref,
|
|
|
|
ref typ,
|
|
|
|
ref impl_items) => {
|
|
|
|
self.process_impl(item,
|
|
|
|
ty_params,
|
|
|
|
trait_ref,
|
2015-06-05 00:50:04 -05:00
|
|
|
&typ,
|
2015-05-04 05:33:07 -05:00
|
|
|
impl_items)
|
|
|
|
}
|
|
|
|
ast::ItemTrait(_, ref generics, ref trait_refs, ref methods) =>
|
|
|
|
self.process_trait(item, generics, trait_refs, methods),
|
2015-05-25 17:35:53 -05:00
|
|
|
ast::ItemMod(ref m) => {
|
|
|
|
self.process_mod(item);
|
|
|
|
self.nest(item.id, |v| visit::walk_mod(v, m));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
ast::ItemTy(ref ty, ref ty_params) => {
|
2015-06-13 17:49:28 -05:00
|
|
|
let qualname = format!("::{}", self.tcx.map.path_to_string(item.id));
|
2015-05-04 05:33:07 -05:00
|
|
|
let value = ty_to_string(&**ty);
|
|
|
|
let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Type);
|
|
|
|
self.fmt.typedef_str(item.span,
|
|
|
|
sub_span,
|
|
|
|
item.id,
|
2015-06-02 14:21:49 -05:00
|
|
|
&qualname,
|
|
|
|
&value);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
self.visit_ty(&**ty);
|
|
|
|
self.process_generic_params(ty_params, item.span, &qualname, item.id);
|
|
|
|
},
|
|
|
|
ast::ItemMac(_) => (),
|
|
|
|
_ => visit::walk_item(self, item),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_generics(&mut self, generics: &ast::Generics) {
|
2015-06-11 07:56:07 -05:00
|
|
|
for param in generics.ty_params.iter() {
|
|
|
|
for bound in param.bounds.iter() {
|
2015-05-04 05:33:07 -05:00
|
|
|
if let ast::TraitTyParamBound(ref trait_ref, _) = *bound {
|
|
|
|
self.process_trait_ref(&trait_ref.trait_ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(ref ty) = param.default {
|
|
|
|
self.visit_ty(&**ty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
trait_item.span, &*ty, &*expr);
|
|
|
|
}
|
|
|
|
ast::MethodTraitItem(ref sig, ref body) => {
|
|
|
|
self.process_method(sig, body.as_ref().map(|x| &**x),
|
|
|
|
trait_item.id, trait_item.ident.name, trait_item.span);
|
|
|
|
}
|
|
|
|
ast::ConstTraitItem(_, None) |
|
|
|
|
ast::TypeTraitItem(..) => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
impl_item.span, &ty, &expr);
|
|
|
|
}
|
|
|
|
ast::MethodImplItem(ref sig, ref body) => {
|
|
|
|
self.process_method(sig, Some(body), impl_item.id,
|
|
|
|
impl_item.ident.name, impl_item.span);
|
|
|
|
}
|
|
|
|
ast::TypeImplItem(_) |
|
|
|
|
ast::MacImplItem(_) => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_ty(&mut self, t: &ast::Ty) {
|
|
|
|
if generated_code(t.span) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
match t.node {
|
|
|
|
ast::TyPath(_, ref path) => {
|
|
|
|
match self.lookup_type_ref(t.id) {
|
|
|
|
Some(id) => {
|
|
|
|
let sub_span = self.span.sub_span_for_type_name(t.span);
|
|
|
|
self.fmt.ref_str(recorder::TypeRef,
|
|
|
|
t.span,
|
|
|
|
sub_span,
|
|
|
|
id,
|
|
|
|
self.cur_scope);
|
|
|
|
},
|
|
|
|
None => ()
|
|
|
|
}
|
|
|
|
|
|
|
|
self.write_sub_paths_truncated(path, false);
|
|
|
|
|
|
|
|
visit::walk_path(self, path);
|
|
|
|
},
|
|
|
|
_ => visit::walk_ty(self, t),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_expr(&mut self, ex: &ast::Expr) {
|
|
|
|
if generated_code(ex.span) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
match ex.node {
|
|
|
|
ast::ExprCall(ref _f, ref _args) => {
|
|
|
|
// Don't need to do anything for function calls,
|
|
|
|
// because just walking the callee path does what we want.
|
|
|
|
visit::walk_expr(self, ex);
|
|
|
|
}
|
|
|
|
ast::ExprPath(_, ref path) => {
|
|
|
|
self.process_path(ex.id, path.span, path, None);
|
|
|
|
visit::walk_expr(self, ex);
|
|
|
|
}
|
|
|
|
ast::ExprStruct(ref path, ref fields, ref base) =>
|
|
|
|
self.process_struct_lit(ex, path, fields, base),
|
|
|
|
ast::ExprMethodCall(_, _, ref args) => self.process_method_call(ex, args),
|
2015-05-25 17:35:53 -05:00
|
|
|
ast::ExprField(ref sub_ex, _) => {
|
2015-05-04 05:33:07 -05:00
|
|
|
if generated_code(sub_ex.span) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-05-25 17:35:53 -05:00
|
|
|
self.visit_expr(&sub_ex);
|
|
|
|
|
2015-06-14 17:06:01 -05:00
|
|
|
if let Some(field_data) = self.save_ctxt.get_expr_data(ex) {
|
|
|
|
down_cast_data!(field_data, VariableRefData, self, ex.span);
|
|
|
|
self.fmt.ref_str(recorder::VarRef,
|
|
|
|
ex.span,
|
|
|
|
Some(field_data.span),
|
|
|
|
field_data.ref_id,
|
|
|
|
field_data.scope);
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
},
|
|
|
|
ast::ExprTupField(ref sub_ex, idx) => {
|
|
|
|
if generated_code(sub_ex.span) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
self.visit_expr(&**sub_ex);
|
|
|
|
|
2015-06-13 17:49:28 -05:00
|
|
|
let ty = &ty::expr_ty_adjusted(self.tcx, &**sub_ex).sty;
|
2015-05-04 05:33:07 -05:00
|
|
|
match *ty {
|
2015-06-11 18:21:46 -05:00
|
|
|
ty::TyStruct(def_id, _) => {
|
2015-06-13 17:49:28 -05:00
|
|
|
let fields = ty::lookup_struct_fields(self.tcx, def_id);
|
2015-05-04 05:33:07 -05:00
|
|
|
for (i, f) in fields.iter().enumerate() {
|
|
|
|
if i == idx.node {
|
|
|
|
let sub_span = self.span.sub_span_after_token(ex.span, token::Dot);
|
|
|
|
self.fmt.ref_str(recorder::VarRef,
|
|
|
|
ex.span,
|
|
|
|
sub_span,
|
|
|
|
f.id,
|
|
|
|
self.cur_scope);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-11 18:21:46 -05:00
|
|
|
ty::TyTuple(_) => {}
|
2015-05-04 05:33:07 -05:00
|
|
|
_ => self.sess.span_bug(ex.span,
|
|
|
|
&format!("Expected struct or tuple \
|
|
|
|
type, found {:?}", ty)),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ast::ExprClosure(_, ref decl, ref body) => {
|
|
|
|
if generated_code(body.span) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-06-08 09:55:35 -05:00
|
|
|
let mut id = String::from("$");
|
2015-05-04 05:33:07 -05:00
|
|
|
id.push_str(&ex.id.to_string());
|
2015-06-02 14:21:49 -05:00
|
|
|
self.process_formals(&decl.inputs, &id);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
// walk arg and return types
|
|
|
|
for arg in &decl.inputs {
|
|
|
|
self.visit_ty(&*arg.ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let ast::Return(ref ret_ty) = decl.output {
|
|
|
|
self.visit_ty(&**ret_ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk the body
|
|
|
|
self.nest(ex.id, |v| v.visit_block(&**body));
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
visit::walk_expr(self, ex)
|
2015-05-10 15:35:08 -05:00
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_mac(&mut self, _: &ast::Mac) {
|
|
|
|
// Just stop, macros are poison to us.
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_pat(&mut self, p: &ast::Pat) {
|
|
|
|
self.process_pat(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_arm(&mut self, arm: &ast::Arm) {
|
2015-05-05 05:03:20 -05:00
|
|
|
let mut collector = PathCollector::new();
|
2015-05-04 05:33:07 -05:00
|
|
|
for pattern in &arm.pats {
|
|
|
|
// collect paths from the arm's patterns
|
2015-05-05 05:03:20 -05:00
|
|
|
collector.visit_pat(&pattern);
|
|
|
|
self.visit_pat(&pattern);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is to get around borrow checking, because we need mut self to call process_path.
|
|
|
|
let mut paths_to_process = vec![];
|
|
|
|
// process collected paths
|
2015-05-10 15:35:08 -05:00
|
|
|
for &(id, ref p, immut, ref_kind) in &collector.collected_paths {
|
2015-06-13 17:49:28 -05:00
|
|
|
let def_map = self.tcx.def_map.borrow();
|
2015-05-04 05:33:07 -05:00
|
|
|
if !def_map.contains_key(&id) {
|
|
|
|
self.sess.span_bug(p.span,
|
|
|
|
&format!("def_map has no key for {} in visit_arm",
|
|
|
|
id));
|
|
|
|
}
|
|
|
|
let def = def_map.get(&id).unwrap().full_def();
|
|
|
|
match def {
|
|
|
|
def::DefLocal(id) => {
|
2015-05-10 15:35:08 -05:00
|
|
|
let value = if immut == ast::MutImmutable {
|
2015-05-04 05:33:07 -05:00
|
|
|
self.span.snippet(p.span).to_string()
|
|
|
|
} else {
|
|
|
|
"<mutable>".to_string()
|
|
|
|
};
|
|
|
|
|
|
|
|
assert!(p.segments.len() == 1, "qualified path for local variable def in arm");
|
|
|
|
self.fmt.variable_str(p.span,
|
|
|
|
Some(p.span),
|
|
|
|
id,
|
|
|
|
&path_to_string(p),
|
2015-06-02 14:21:49 -05:00
|
|
|
&value,
|
2015-05-04 05:33:07 -05:00
|
|
|
"")
|
|
|
|
}
|
|
|
|
def::DefVariant(..) | def::DefTy(..) | def::DefStruct(..) => {
|
|
|
|
paths_to_process.push((id, p.clone(), Some(ref_kind)))
|
|
|
|
}
|
|
|
|
// FIXME(nrc) what are these doing here?
|
|
|
|
def::DefStatic(_, _) |
|
|
|
|
def::DefConst(..) |
|
|
|
|
def::DefAssociatedConst(..) => {}
|
|
|
|
_ => error!("unexpected definition kind when processing collected paths: {:?}",
|
|
|
|
def)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for &(id, ref path, ref_kind) in &paths_to_process {
|
|
|
|
self.process_path(id, path.span, path, ref_kind);
|
|
|
|
}
|
|
|
|
visit::walk_expr_opt(self, &arm.guard);
|
|
|
|
self.visit_expr(&*arm.body);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_stmt(&mut self, s: &ast::Stmt) {
|
|
|
|
if generated_code(s.span) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
visit::walk_stmt(self, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_local(&mut self, l: &ast::Local) {
|
|
|
|
if generated_code(l.span) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// The local could declare multiple new vars, we must walk the
|
|
|
|
// pattern and collect them all.
|
2015-05-05 05:03:20 -05:00
|
|
|
let mut collector = PathCollector::new();
|
|
|
|
collector.visit_pat(&l.pat);
|
|
|
|
self.visit_pat(&l.pat);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
let value = self.span.snippet(l.span);
|
|
|
|
|
2015-05-10 15:35:08 -05:00
|
|
|
for &(id, ref p, immut, _) in &collector.collected_paths {
|
|
|
|
let value = if immut == ast::MutImmutable {
|
|
|
|
value.to_string()
|
|
|
|
} else {
|
|
|
|
"<mutable>".to_string()
|
|
|
|
};
|
2015-06-13 17:49:28 -05:00
|
|
|
let types = self.tcx.node_types();
|
2015-06-18 12:25:05 -05:00
|
|
|
let typ = types.get(&id).unwrap().to_string();
|
2015-05-04 05:33:07 -05:00
|
|
|
// Get the span only for the name of the variable (I hope the path
|
|
|
|
// is only ever a variable name, but who knows?).
|
|
|
|
let sub_span = self.span.span_for_last_ident(p.span);
|
|
|
|
// Rust uses the id of the pattern for var lookups, so we'll use it too.
|
|
|
|
self.fmt.variable_str(p.span,
|
|
|
|
sub_span,
|
|
|
|
id,
|
|
|
|
&path_to_string(p),
|
2015-06-02 14:21:49 -05:00
|
|
|
&value,
|
|
|
|
&typ);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|