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.
|
|
|
|
|
2016-02-29 04:51:05 -06:00
|
|
|
//! Write the output of rustc's analysis to an implementor of Dump. The data is
|
2015-05-04 05:33:07 -05:00
|
|
|
//! 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).
|
2016-02-29 04:51:05 -06:00
|
|
|
//! DumpVisitor walks the AST and processes it, and an implementor of Dump
|
|
|
|
//! is used for recording the output in a format-agnostic way (see CsvDumper
|
|
|
|
//! for an example).
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
use session::Session;
|
|
|
|
|
2016-01-20 13:31:10 -06:00
|
|
|
use middle::def::Def;
|
2015-08-16 05:32:28 -05:00
|
|
|
use middle::def_id::DefId;
|
2016-03-22 10:30:57 -05:00
|
|
|
use rustc::ty::{self, TyCtxt};
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2016-01-29 01:22:55 -06:00
|
|
|
use std::collections::HashSet;
|
2016-02-29 04:51:05 -06:00
|
|
|
use std::hash::*;
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2016-02-11 12:16:33 -06:00
|
|
|
use syntax::ast::{self, NodeId, PatKind};
|
2015-05-04 05:33:07 -05:00
|
|
|
use syntax::codemap::*;
|
2015-07-28 11:07:20 -05:00
|
|
|
use syntax::parse::token::{self, keywords};
|
2015-05-04 05:33:07 -05:00
|
|
|
use syntax::visit::{self, Visitor};
|
|
|
|
use syntax::print::pprust::{path_to_string, ty_to_string};
|
|
|
|
use syntax::ptr::P;
|
|
|
|
|
2015-09-24 23:03:28 -05:00
|
|
|
use rustc_front::lowering::{lower_expr, LoweringContext};
|
2015-07-31 02:04:06 -05:00
|
|
|
|
2016-02-29 04:51:05 -06:00
|
|
|
use super::{escape, generated_code, SaveContext, PathCollector};
|
|
|
|
use super::data::*;
|
|
|
|
use super::dump::Dump;
|
2015-05-04 05:33:07 -05:00
|
|
|
use super::span_utils::SpanUtils;
|
2016-02-29 04:51:05 -06:00
|
|
|
use super::recorder;
|
2015-05-04 05:33:07 -05:00
|
|
|
|
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-10-21 11:20:46 -05:00
|
|
|
}
|
2015-06-08 17:36:30 -05:00
|
|
|
};
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2016-02-29 04:51:05 -06:00
|
|
|
pub struct DumpVisitor<'l, 'tcx: 'l, D: '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,
|
2016-02-29 17:36:51 -06:00
|
|
|
tcx: &'l TyCtxt<'tcx>,
|
2015-10-19 14:54:19 -05:00
|
|
|
analysis: &'l ty::CrateAnalysis<'l>,
|
2016-02-29 04:51:05 -06:00
|
|
|
dumper: &'l mut D,
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
span: SpanUtils<'l>,
|
|
|
|
|
2015-09-01 22:37:07 -05:00
|
|
|
cur_scope: NodeId,
|
2016-01-29 01:22:55 -06:00
|
|
|
|
|
|
|
// Set of macro definition (callee) spans, and the set
|
|
|
|
// of macro use (callsite) spans. We store these to ensure
|
|
|
|
// we only write one macro def per unique macro definition, and
|
|
|
|
// one macro use per unique callsite span.
|
|
|
|
mac_defs: HashSet<Span>,
|
|
|
|
mac_uses: HashSet<Span>,
|
|
|
|
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
2016-02-29 04:51:05 -06:00
|
|
|
impl <'l, 'tcx, D> DumpVisitor<'l, 'tcx, D>
|
|
|
|
where D: Dump
|
|
|
|
{
|
2016-02-29 17:36:51 -06:00
|
|
|
pub fn new(tcx: &'l TyCtxt<'tcx>,
|
2015-09-29 22:17:37 -05:00
|
|
|
lcx: &'l LoweringContext<'l>,
|
2015-10-19 14:54:19 -05:00
|
|
|
analysis: &'l ty::CrateAnalysis<'l>,
|
2016-02-29 04:51:05 -06:00
|
|
|
dumper: &'l mut D)
|
|
|
|
-> DumpVisitor<'l, 'tcx, D> {
|
2015-07-13 21:21:54 -05:00
|
|
|
let span_utils = SpanUtils::new(&tcx.sess);
|
2016-02-29 04:51:05 -06:00
|
|
|
DumpVisitor {
|
2015-06-13 17:49:28 -05:00
|
|
|
sess: &tcx.sess,
|
|
|
|
tcx: tcx,
|
2015-09-24 23:03:28 -05:00
|
|
|
save_ctxt: SaveContext::from_span_utils(tcx, lcx, span_utils.clone()),
|
2015-05-04 05:33:07 -05:00
|
|
|
analysis: analysis,
|
2016-02-29 04:51:05 -06:00
|
|
|
dumper: dumper,
|
2015-06-13 17:49:28 -05:00
|
|
|
span: span_utils.clone(),
|
2015-09-01 22:37:07 -05:00
|
|
|
cur_scope: 0,
|
2016-01-29 01:22:55 -06:00
|
|
|
mac_defs: HashSet::new(),
|
|
|
|
mac_uses: HashSet::new(),
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-01 22:37:07 -05:00
|
|
|
fn nest<F>(&mut self, scope_id: NodeId, f: F)
|
2016-02-29 04:51:05 -06:00
|
|
|
where F: FnOnce(&mut DumpVisitor<'l, 'tcx, D>)
|
2015-05-05 01:46:09 -05:00
|
|
|
{
|
|
|
|
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-11-03 15:16:06 -06:00
|
|
|
let source_file = self.tcx.sess.local_crate_source_file.as_ref();
|
2016-02-29 04:51:05 -06:00
|
|
|
let crate_root = source_file.map(|source_file| {
|
|
|
|
match source_file.file_name() {
|
2015-11-03 15:16:06 -06:00
|
|
|
Some(_) => source_file.parent().unwrap().display().to_string(),
|
|
|
|
None => source_file.display().to_string(),
|
2016-02-29 04:51:05 -06:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Info about all the external crates referenced from this crate.
|
|
|
|
let external_crates = self.save_ctxt.get_external_crates().into_iter().map(|c| {
|
|
|
|
ExternalCrateData {
|
|
|
|
name: c.name,
|
|
|
|
num: c.number
|
|
|
|
}
|
|
|
|
}).collect();
|
2015-11-03 15:16:06 -06:00
|
|
|
|
2015-05-05 01:46:09 -05:00
|
|
|
// The current crate.
|
2016-02-29 04:51:05 -06:00
|
|
|
let data = CratePreludeData {
|
|
|
|
crate_name: name.into(),
|
|
|
|
crate_root: crate_root,
|
|
|
|
external_crates: external_crates
|
|
|
|
};
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2016-02-29 04:51:05 -06:00
|
|
|
self.dumper.crate_prelude(krate.span, data);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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() {
|
2016-01-21 16:58:09 -06:00
|
|
|
if generated_code(path.span) {
|
|
|
|
return vec!();
|
|
|
|
}
|
2015-09-27 15:20:49 -05:00
|
|
|
error!("Mis-calculated spans for path '{}'. Found {} spans, expected {}. Found spans:",
|
|
|
|
path_to_string(path),
|
|
|
|
spans.len(),
|
|
|
|
path.segments.len());
|
2015-05-04 05:33:07 -05:00
|
|
|
for s in &spans {
|
|
|
|
let loc = self.sess.codemap().lookup_char_pos(s.lo);
|
|
|
|
error!(" '{}' in {}, line {}",
|
2015-09-27 15:20:49 -05:00
|
|
|
self.span.snippet(*s),
|
|
|
|
loc.file.name,
|
|
|
|
loc.line);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
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());
|
2015-09-01 22:37:07 -05:00
|
|
|
let sub_path = ast::Path {
|
|
|
|
span: *span, // span for the last segment
|
|
|
|
global: path.global,
|
|
|
|
segments: segs,
|
|
|
|
};
|
2015-05-04 05:33:07 -05:00
|
|
|
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()
|
|
|
|
};
|
2016-02-29 04:51:05 -06:00
|
|
|
self.dumper.mod_ref(path.span, ModRefData {
|
|
|
|
span: *span,
|
|
|
|
qualname: qualname,
|
|
|
|
scope: self.cur_scope,
|
|
|
|
ref_id: None
|
|
|
|
}.normalize(&self.tcx));
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
};
|
2016-02-29 04:51:05 -06:00
|
|
|
self.dumper.mod_ref(path.span, ModRefData {
|
|
|
|
span: *span,
|
|
|
|
qualname: qualname,
|
|
|
|
scope: self.cur_scope,
|
|
|
|
ref_id: None
|
|
|
|
}.normalize(&self.tcx));
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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];
|
2016-02-29 04:51:05 -06:00
|
|
|
self.dumper.type_ref(path.span, TypeRefData {
|
|
|
|
ref_id: None,
|
|
|
|
span: *span,
|
|
|
|
qualname: qualname.to_owned(),
|
|
|
|
scope: 0
|
|
|
|
});
|
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 {
|
2016-02-29 04:51:05 -06:00
|
|
|
self.dumper.mod_ref(path.span, ModRefData {
|
|
|
|
span: *span,
|
|
|
|
qualname: qualname.to_owned(),
|
|
|
|
scope: self.cur_scope,
|
|
|
|
ref_id: None
|
|
|
|
}.normalize(&self.tcx));
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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",
|
2015-09-27 15:20:49 -05:00
|
|
|
ref_id));
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
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 {
|
2016-01-20 13:31:10 -06:00
|
|
|
Def::PrimTy(..) => None,
|
|
|
|
Def::SelfTy(..) => None,
|
2015-05-04 05:33:07 -05:00
|
|
|
_ => Some(def.def_id()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-29 04:51:05 -06:00
|
|
|
fn process_def_kind(&mut self,
|
|
|
|
ref_id: NodeId,
|
|
|
|
span: Span,
|
|
|
|
sub_span: Option<Span>,
|
|
|
|
def_id: DefId,
|
|
|
|
scope: NodeId) {
|
|
|
|
if self.span.filter_generated(sub_span, 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(&ref_id) {
|
2015-09-27 15:20:49 -05:00
|
|
|
self.sess.span_bug(span,
|
|
|
|
&format!("def_map has no key for {} in lookup_def_kind",
|
|
|
|
ref_id));
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
let def = def_map.get(&ref_id).unwrap().full_def();
|
|
|
|
match def {
|
2016-01-20 13:31:10 -06:00
|
|
|
Def::Mod(_) |
|
2016-02-29 04:51:05 -06:00
|
|
|
Def::ForeignMod(_) => {
|
|
|
|
self.dumper.mod_ref(span, ModRefData {
|
|
|
|
span: sub_span.expect("No span found for mod ref"),
|
|
|
|
ref_id: Some(def_id),
|
|
|
|
scope: scope,
|
|
|
|
qualname: String::new()
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
|
|
|
Def::Struct(..) |
|
2016-01-20 13:31:10 -06:00
|
|
|
Def::Enum(..) |
|
|
|
|
Def::TyAlias(..) |
|
|
|
|
Def::AssociatedTy(..) |
|
2016-02-29 04:51:05 -06:00
|
|
|
Def::Trait(_) => {
|
|
|
|
self.dumper.type_ref(span, TypeRefData {
|
|
|
|
span: sub_span.expect("No span found for type ref"),
|
|
|
|
ref_id: Some(def_id),
|
|
|
|
scope: scope,
|
|
|
|
qualname: String::new()
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2016-01-20 13:31:10 -06:00
|
|
|
Def::Static(_, _) |
|
|
|
|
Def::Const(_) |
|
|
|
|
Def::AssociatedConst(..) |
|
|
|
|
Def::Local(..) |
|
|
|
|
Def::Variant(..) |
|
2016-02-29 04:51:05 -06:00
|
|
|
Def::Upvar(..) => {
|
|
|
|
self.dumper.variable_ref(span, VariableRefData {
|
|
|
|
span: sub_span.expect("No span found for var ref"),
|
|
|
|
ref_id: def_id,
|
|
|
|
scope: scope,
|
|
|
|
name: String::new()
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
|
|
|
Def::Fn(..) => {
|
|
|
|
self.dumper.function_ref(span, FunctionRefData {
|
|
|
|
span: sub_span.expect("No span found for fn ref"),
|
|
|
|
ref_id: def_id,
|
|
|
|
scope: scope
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2016-01-20 13:31:10 -06:00
|
|
|
Def::SelfTy(..) |
|
|
|
|
Def::Label(_) |
|
|
|
|
Def::TyParam(..) |
|
|
|
|
Def::Method(..) |
|
|
|
|
Def::PrimTy(_) |
|
|
|
|
Def::Err => {
|
2015-09-27 15:20:49 -05:00
|
|
|
self.sess.span_bug(span,
|
2016-02-29 04:51:05 -06:00
|
|
|
&format!("process_def_kind for unexpected item: {:?}", def));
|
2015-09-01 22:37:07 -05:00
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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?)
|
2016-02-29 04:51:05 -06:00
|
|
|
let sub_span = span_utils.span_for_last_ident(p.span);
|
|
|
|
if !self.span.filter_generated(sub_span, p.span) {
|
|
|
|
self.dumper.variable(p.span, VariableData {
|
|
|
|
id: id,
|
|
|
|
span: sub_span.expect("No span found for variable"),
|
|
|
|
name: path_to_string(p),
|
|
|
|
qualname: format!("{}::{}", qualname, path_to_string(p)),
|
|
|
|
type_value: typ,
|
|
|
|
value: String::new(),
|
|
|
|
scope: 0
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-08 19:23:29 -05:00
|
|
|
fn process_method(&mut self,
|
|
|
|
sig: &ast::MethodSig,
|
2015-05-04 05:33:07 -05:00
|
|
|
body: Option<&ast::Block>,
|
2015-07-08 19:23:29 -05:00
|
|
|
id: ast::NodeId,
|
|
|
|
name: ast::Name,
|
2015-05-04 05:33:07 -05:00
|
|
|
span: Span) {
|
2015-07-28 11:07:20 -05:00
|
|
|
debug!("process_method: {}:{}", id, name);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2016-01-21 16:58:09 -06:00
|
|
|
if let Some(method_data) = self.save_ctxt.get_method_data(id, name, span) {
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2016-01-21 16:58:09 -06:00
|
|
|
if body.is_some() {
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(method_data.span), span) {
|
|
|
|
self.dumper.function(span, method_data.clone().normalize(&self.tcx));
|
|
|
|
}
|
2016-01-21 16:58:09 -06:00
|
|
|
self.process_formals(&sig.decl.inputs, &method_data.qualname);
|
|
|
|
} else {
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(method_data.span), span) {
|
|
|
|
self.dumper.method(span, MethodData {
|
|
|
|
id: method_data.id,
|
|
|
|
span: method_data.span,
|
|
|
|
scope: method_data.scope,
|
|
|
|
qualname: method_data.qualname.clone(),
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2016-01-21 16:58:09 -06:00
|
|
|
}
|
|
|
|
self.process_generic_params(&sig.generics, span, &method_data.qualname, id);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// walk arg and return types
|
|
|
|
for arg in &sig.decl.inputs {
|
|
|
|
self.visit_ty(&arg.ty);
|
|
|
|
}
|
|
|
|
|
2016-02-08 08:04:11 -06:00
|
|
|
if let ast::FunctionRetTy::Ty(ref ret_ty) = sig.decl.output {
|
2015-05-04 05:33:07 -05:00
|
|
|
self.visit_ty(ret_ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk the fn body
|
|
|
|
if let Some(body) = body {
|
|
|
|
self.nest(id, |v| v.visit_block(body));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(trait_ref_data.span), trait_ref.path.span) {
|
|
|
|
self.dumper.type_ref(trait_ref.path.span, trait_ref_data.normalize(&self.tcx));
|
|
|
|
}
|
|
|
|
|
2015-06-05 00:50:04 -05:00
|
|
|
visit::walk_path(self, &trait_ref.path);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-01 22:37:07 -05:00
|
|
|
fn process_struct_field_def(&mut self, field: &ast::StructField, parent_id: NodeId) {
|
2015-06-04 23:03:48 -05:00
|
|
|
let field_data = self.save_ctxt.get_field_data(field, parent_id);
|
2016-02-29 04:51:05 -06:00
|
|
|
if let Some(mut field_data) = field_data {
|
|
|
|
if !self.span.filter_generated(Some(field_data.span), field.span) {
|
|
|
|
field_data.scope = normalize_node_id(&self.tcx, field_data.scope) as u32;
|
|
|
|
field_data.value = String::new();
|
|
|
|
self.dumper.variable(field.span, field_data.normalize(&self.tcx));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dump generic params bindings, then visit_generics
|
|
|
|
fn process_generic_params(&mut self,
|
2015-09-01 22:37:07 -05:00
|
|
|
generics: &ast::Generics,
|
2015-05-04 05:33:07 -05:00
|
|
|
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,
|
2015-09-27 15:20:49 -05:00
|
|
|
(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);
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(param_ss), full_span) {
|
|
|
|
self.dumper.typedef(full_span, TypedefData {
|
|
|
|
span: param_ss,
|
|
|
|
id: param.id,
|
|
|
|
qualname: name,
|
|
|
|
value: String::new()
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
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) {
|
2016-01-21 16:58:09 -06:00
|
|
|
if let Some(fn_data) = self.save_ctxt.get_item_data(item) {
|
|
|
|
down_cast_data!(fn_data, FunctionData, self, item.span);
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(fn_data.span), item.span) {
|
|
|
|
self.dumper.function(item.span, fn_data.clone().normalize(&self.tcx));
|
|
|
|
}
|
2016-01-21 16:58:09 -06: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
|
|
|
}
|
|
|
|
|
2016-02-08 08:04:11 -06:00
|
|
|
if let ast::FunctionRetTy::Ty(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-09-01 22:37:07 -05:00
|
|
|
fn process_static_or_const_item(&mut self, item: &ast::Item, typ: &ast::Ty, expr: &ast::Expr) {
|
2016-01-21 16:58:09 -06:00
|
|
|
if let Some(var_data) = self.save_ctxt.get_item_data(item) {
|
|
|
|
down_cast_data!(var_data, VariableData, self, item.span);
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(var_data.span), item.span) {
|
|
|
|
let mut var_data = var_data;
|
|
|
|
var_data.scope = normalize_node_id(&self.tcx, var_data.scope) as u32;
|
|
|
|
self.dumper.variable(item.span, var_data.normalize(&self.tcx));
|
|
|
|
}
|
2016-01-21 16:58:09 -06: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,
|
2015-09-24 15:05:02 -05:00
|
|
|
name: ast::Name,
|
2015-05-04 05:33:07 -05:00
|
|
|
span: Span,
|
|
|
|
typ: &ast::Ty,
|
2015-09-01 22:37:07 -05:00
|
|
|
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
|
|
|
|
2015-09-27 15:20:49 -05:00
|
|
|
let sub_span = self.span.sub_span_after_keyword(span, keywords::Const);
|
2015-05-10 15:35:08 -05:00
|
|
|
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(sub_span, span) {
|
|
|
|
self.dumper.variable(span, VariableData {
|
|
|
|
span: sub_span.expect("No span found for variable"),
|
|
|
|
id: id,
|
|
|
|
name: name.to_string(),
|
|
|
|
qualname: qualname,
|
|
|
|
value: self.span.snippet(expr.span),
|
|
|
|
type_value: ty_to_string(&typ),
|
|
|
|
scope: normalize_node_id(&self.tcx, self.cur_scope) as u32
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
// walk type and init value
|
|
|
|
self.visit_ty(typ);
|
|
|
|
self.visit_expr(expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_struct(&mut self,
|
|
|
|
item: &ast::Item,
|
2015-10-07 19:20:57 -05:00
|
|
|
def: &ast::VariantData,
|
2015-05-04 05:33:07 -05:00
|
|
|
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 val = self.span.snippet(item.span);
|
|
|
|
let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Struct);
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(sub_span, item.span) {
|
|
|
|
self.dumper.struct_data(item.span, StructData {
|
|
|
|
span: sub_span.expect("No span found for struct"),
|
|
|
|
id: item.id,
|
|
|
|
ctor_id: def.id(),
|
|
|
|
qualname: qualname.clone(),
|
|
|
|
scope: self.cur_scope,
|
|
|
|
value: val
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
|
|
|
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
// fields
|
2015-10-08 15:45:46 -05:00
|
|
|
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);
|
2016-01-21 16:58:09 -06:00
|
|
|
let enum_data = match enum_data {
|
|
|
|
None => return,
|
|
|
|
Some(data) => data,
|
|
|
|
};
|
2015-06-08 17:36:30 -05:00
|
|
|
down_cast_data!(enum_data, EnumData, self, item.span);
|
2016-02-29 04:51:05 -06:00
|
|
|
let normalized = enum_data.clone().normalize(&self.tcx);
|
|
|
|
if !self.span.filter_generated(Some(normalized.span), item.span) {
|
|
|
|
self.dumper.enum_data(item.span, normalized);
|
|
|
|
}
|
2015-06-08 17:36:30 -05:00
|
|
|
|
|
|
|
for variant in &enum_definition.variants {
|
2015-07-28 11:07:20 -05:00
|
|
|
let name = &variant.node.name.name.as_str();
|
2015-06-08 17:36:30 -05:00
|
|
|
let mut qualname = enum_data.qualname.clone();
|
|
|
|
qualname.push_str("::");
|
|
|
|
qualname.push_str(name);
|
|
|
|
let val = self.span.snippet(variant.span);
|
2015-10-01 10:47:27 -05:00
|
|
|
|
2016-01-21 23:53:23 -06:00
|
|
|
match variant.node.data {
|
|
|
|
ast::VariantData::Struct(..) => {
|
2016-02-29 04:51:05 -06:00
|
|
|
let sub_span = self.span.span_for_first_ident(variant.span);
|
|
|
|
if !self.span.filter_generated(sub_span, variant.span) {
|
|
|
|
self.dumper.struct_variant(variant.span, StructVariantData {
|
|
|
|
span: sub_span.expect("No span found for struct variant"),
|
|
|
|
id: variant.node.data.id(),
|
|
|
|
qualname: qualname,
|
|
|
|
type_value: enum_data.qualname.clone(),
|
|
|
|
value: val,
|
|
|
|
scope: enum_data.scope
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2016-01-21 23:53:23 -06:00
|
|
|
}
|
|
|
|
_ => {
|
2016-02-29 04:51:05 -06:00
|
|
|
let sub_span = self.span.span_for_first_ident(variant.span);
|
|
|
|
if !self.span.filter_generated(sub_span, variant.span) {
|
|
|
|
self.dumper.tuple_variant(variant.span, TupleVariantData {
|
|
|
|
span: sub_span.expect("No span found for tuple variant"),
|
|
|
|
id: variant.node.data.id(),
|
|
|
|
name: name.to_string(),
|
|
|
|
qualname: qualname,
|
|
|
|
type_value: enum_data.qualname.clone(),
|
|
|
|
value: val,
|
|
|
|
scope: enum_data.scope
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2016-01-21 23:53:23 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 10:47:27 -05:00
|
|
|
|
2015-10-08 15:45:46 -05:00
|
|
|
for field in variant.node.data.fields() {
|
2015-10-09 19:28:40 -05:00
|
|
|
self.process_struct_field_def(field, variant.node.data.id());
|
2016-02-09 14:24:11 -06:00
|
|
|
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,
|
2016-02-11 14:33:09 -06:00
|
|
|
impl_items: &[ast::ImplItem]) {
|
2016-01-21 16:58:09 -06:00
|
|
|
let mut has_self_ref = false;
|
|
|
|
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
|
|
|
|
down_cast_data!(impl_data, ImplData, self, item.span);
|
|
|
|
if let Some(ref self_ref) = impl_data.self_ref {
|
|
|
|
has_self_ref = true;
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(self_ref.span), item.span) {
|
|
|
|
self.dumper.type_ref(item.span, self_ref.clone().normalize(&self.tcx));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2016-01-21 16:58:09 -06:00
|
|
|
if let Some(ref trait_ref_data) = impl_data.trait_ref {
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(trait_ref_data.span), item.span) {
|
|
|
|
self.dumper.type_ref(item.span, trait_ref_data.clone().normalize(&self.tcx));
|
|
|
|
}
|
|
|
|
|
2016-01-21 16:58:09 -06:00
|
|
|
visit::walk_path(self, &trait_ref.as_ref().unwrap().path);
|
2015-06-08 17:36:30 -05:00
|
|
|
}
|
2016-01-21 16:58:09 -06:00
|
|
|
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(impl_data.span), item.span) {
|
|
|
|
self.dumper.impl_data(item.span, ImplData {
|
|
|
|
id: impl_data.id,
|
|
|
|
span: impl_data.span,
|
|
|
|
scope: impl_data.scope,
|
|
|
|
trait_ref: impl_data.trait_ref.map(|d| d.ref_id.unwrap()),
|
|
|
|
self_ref: impl_data.self_ref.map(|d| d.ref_id.unwrap())
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2015-06-08 17:36:30 -05:00
|
|
|
}
|
2016-01-21 16:58:09 -06:00
|
|
|
if !has_self_ref {
|
|
|
|
self.visit_ty(&typ);
|
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,
|
2015-12-16 12:44:33 -06:00
|
|
|
trait_refs: &ast::TyParamBounds,
|
2016-02-11 14:33:09 -06:00
|
|
|
methods: &[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);
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(sub_span, item.span) {
|
|
|
|
self.dumper.trait_data(item.span, TraitData {
|
|
|
|
span: sub_span.expect("No span found for trait"),
|
|
|
|
id: item.id,
|
|
|
|
qualname: qualname.clone(),
|
|
|
|
scope: self.cur_scope,
|
|
|
|
value: val
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
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;
|
2016-02-29 04:51:05 -06:00
|
|
|
if let Some(id) = self.lookup_type_ref(trait_ref.ref_id) {
|
|
|
|
let sub_span = self.span.sub_span_for_type_name(trait_ref.path.span);
|
|
|
|
if !self.span.filter_generated(sub_span, trait_ref.path.span) {
|
|
|
|
self.dumper.type_ref(trait_ref.path.span, TypeRefData {
|
|
|
|
span: sub_span.expect("No span found for trait ref"),
|
|
|
|
ref_id: Some(id),
|
|
|
|
scope: self.cur_scope,
|
|
|
|
qualname: String::new()
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
|
|
|
|
|
|
|
if !self.span.filter_generated(sub_span, trait_ref.path.span) {
|
|
|
|
let sub_span = sub_span.expect("No span for inheritance");
|
|
|
|
self.dumper.inheritance(InheritanceData {
|
|
|
|
span: sub_span,
|
|
|
|
base_id: id,
|
|
|
|
deriv_id: item.id
|
|
|
|
}.normalize(&self.tcx));
|
2015-09-01 22:37:07 -05:00
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-01 22:42:38 -05:00
|
|
|
// `item` is the module in question, represented as an item.
|
|
|
|
fn process_mod(&mut self, item: &ast::Item) {
|
2016-01-21 16:58:09 -06:00
|
|
|
if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
|
|
|
|
down_cast_data!(mod_data, ModData, self, item.span);
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(mod_data.span), item.span) {
|
|
|
|
self.dumper.mod_data(mod_data.normalize(&self.tcx));
|
|
|
|
}
|
2016-01-21 16:58:09 -06:00
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
2015-09-01 22:37:07 -05:00
|
|
|
fn process_path(&mut self, id: NodeId, path: &ast::Path, ref_kind: Option<recorder::Row>) {
|
2016-01-21 16:58:09 -06:00
|
|
|
let path_data = self.save_ctxt.get_path_data(id, path);
|
|
|
|
if generated_code(path.span) && path_data.is_none() {
|
2015-07-07 21:30:18 -05:00
|
|
|
return;
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
2015-07-25 00:47:26 -05:00
|
|
|
let path_data = match path_data {
|
|
|
|
Some(pd) => pd,
|
|
|
|
None => {
|
|
|
|
self.tcx.sess.span_bug(path.span,
|
2015-09-27 15:20:49 -05:00
|
|
|
&format!("Unexpected def kind while looking up path in \
|
|
|
|
`{}`",
|
2015-07-25 00:47:26 -05:00
|
|
|
self.span.snippet(path.span)))
|
|
|
|
}
|
|
|
|
};
|
2016-02-29 04:51:05 -06:00
|
|
|
|
2015-07-07 21:30:18 -05:00
|
|
|
match path_data {
|
2016-02-29 04:51:05 -06:00
|
|
|
Data::VariableRefData(vrd) => {
|
|
|
|
// FIXME: this whole block duplicates the code in process_def_kind
|
|
|
|
if !self.span.filter_generated(Some(vrd.span), path.span) {
|
|
|
|
match ref_kind {
|
|
|
|
Some(recorder::TypeRef) => {
|
|
|
|
self.dumper.type_ref(path.span, TypeRefData {
|
|
|
|
span: vrd.span,
|
|
|
|
ref_id: Some(vrd.ref_id),
|
|
|
|
scope: vrd.scope,
|
|
|
|
qualname: String::new()
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
|
|
|
Some(recorder::FnRef) => {
|
|
|
|
self.dumper.function_ref(path.span, FunctionRefData {
|
|
|
|
span: vrd.span,
|
|
|
|
ref_id: vrd.ref_id,
|
|
|
|
scope: vrd.scope
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
|
|
|
Some(recorder::ModRef) => {
|
|
|
|
self.dumper.mod_ref(path.span, ModRefData {
|
|
|
|
span: vrd.span,
|
|
|
|
ref_id: Some(vrd.ref_id),
|
|
|
|
scope: vrd.scope,
|
|
|
|
qualname: String::new()
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
|
|
|
Some(recorder::VarRef) | None
|
|
|
|
=> self.dumper.variable_ref(path.span, vrd.normalize(&self.tcx))
|
|
|
|
}
|
|
|
|
}
|
2015-07-07 21:30:18 -05:00
|
|
|
|
|
|
|
}
|
2016-02-29 04:51:05 -06:00
|
|
|
Data::TypeRefData(trd) => {
|
|
|
|
if !self.span.filter_generated(Some(trd.span), path.span) {
|
|
|
|
self.dumper.type_ref(path.span, trd.normalize(&self.tcx));
|
|
|
|
}
|
2015-07-07 21:30:18 -05:00
|
|
|
}
|
2016-02-29 04:51:05 -06:00
|
|
|
Data::MethodCallData(mcd) => {
|
|
|
|
if !self.span.filter_generated(Some(mcd.span), path.span) {
|
|
|
|
self.dumper.method_call(path.span, mcd.normalize(&self.tcx));
|
|
|
|
}
|
2015-07-07 21:30:18 -05:00
|
|
|
}
|
|
|
|
Data::FunctionCallData(fcd) => {
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(fcd.span), path.span) {
|
|
|
|
self.dumper.function_call(path.span, fcd.normalize(&self.tcx));
|
|
|
|
}
|
2015-07-07 21:30:18 -05:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
self.sess.span_bug(path.span,
|
|
|
|
&format!("Unexpected data: {:?}", path_data));
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
2015-07-07 21:30:18 -05:00
|
|
|
|
|
|
|
// Modules or types in the path prefix.
|
|
|
|
let def_map = self.tcx.def_map.borrow();
|
|
|
|
let def = def_map.get(&id).unwrap().full_def();
|
2015-05-04 05:33:07 -05:00
|
|
|
match def {
|
2016-01-20 13:31:10 -06:00
|
|
|
Def::Method(did) => {
|
2015-06-25 15:42:17 -05:00
|
|
|
let ti = self.tcx.impl_or_trait_item(did);
|
2015-05-04 05:33:07 -05:00
|
|
|
if let ty::MethodTraitItem(m) = ti {
|
2015-12-28 05:52:43 -06:00
|
|
|
if m.explicit_self == ty::ExplicitSelfCategory::Static {
|
2015-05-04 05:33:07 -05:00
|
|
|
self.write_sub_path_trait_truncated(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 13:31:10 -06:00
|
|
|
Def::Local(..) |
|
|
|
|
Def::Static(_,_) |
|
|
|
|
Def::Const(..) |
|
|
|
|
Def::AssociatedConst(..) |
|
|
|
|
Def::Struct(..) |
|
|
|
|
Def::Variant(..) |
|
|
|
|
Def::Fn(..) => self.write_sub_paths_truncated(path, false),
|
2015-09-01 22:37:07 -05:00
|
|
|
_ => {}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_struct_lit(&mut self,
|
|
|
|
ex: &ast::Expr,
|
|
|
|
path: &ast::Path,
|
|
|
|
fields: &Vec<ast::Field>,
|
2015-08-07 06:41:33 -05:00
|
|
|
variant: ty::VariantDef,
|
2015-05-04 05:33:07 -05:00
|
|
|
base: &Option<P<ast::Expr>>) {
|
|
|
|
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);
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(struct_lit_data.span), ex.span) {
|
|
|
|
self.dumper.type_ref(ex.span, struct_lit_data.normalize(&self.tcx));
|
|
|
|
}
|
|
|
|
|
2015-07-08 03:54:45 -05:00
|
|
|
let scope = self.save_ctxt.enclosing_scope(ex.id);
|
2015-06-14 17:06:01 -05:00
|
|
|
|
|
|
|
for field in fields {
|
2016-01-21 16:58:09 -06:00
|
|
|
if let Some(field_data) = self.save_ctxt
|
|
|
|
.get_field_ref_data(field, variant, scope) {
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(field_data.span), field.ident.span) {
|
|
|
|
self.dumper.variable_ref(field.ident.span, field_data.normalize(&self.tcx));
|
|
|
|
}
|
2016-01-21 16:58:09 -06:00
|
|
|
}
|
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-09-28 06:26:26 -05:00
|
|
|
walk_list!(self, visit_expr, base);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
2015-09-01 22:37:07 -05:00
|
|
|
fn process_method_call(&mut self, ex: &ast::Expr, args: &Vec<P<ast::Expr>>) {
|
2016-02-29 04:51:05 -06:00
|
|
|
if let Some(mcd) = self.save_ctxt.get_expr_data(ex) {
|
|
|
|
down_cast_data!(mcd, MethodCallData, self, ex.span);
|
|
|
|
if !self.span.filter_generated(Some(mcd.span), ex.span) {
|
|
|
|
self.dumper.method_call(ex.span, mcd.normalize(&self.tcx));
|
|
|
|
}
|
2015-07-06 18:42:43 -05:00
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
// walk receiver and args
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(self, visit_expr, args);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
2015-09-01 22:37:07 -05:00
|
|
|
fn process_pat(&mut self, p: &ast::Pat) {
|
2015-05-04 05:33:07 -05:00
|
|
|
match p.node {
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Struct(ref path, ref fields, _) => {
|
2015-05-04 05:33:07 -05:00
|
|
|
visit::walk_path(self, path);
|
2015-08-02 14:52:50 -05:00
|
|
|
let adt = self.tcx.node_id_to_type(p.id).ty_adt_def().unwrap();
|
|
|
|
let def = self.tcx.def_map.borrow()[&p.id].full_def();
|
|
|
|
let variant = adt.variant_of_def(def);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2015-08-02 14:52:50 -05:00
|
|
|
for &Spanned { node: ref field, span } in fields {
|
|
|
|
let sub_span = self.span.span_for_first_ident(span);
|
|
|
|
if let Some(f) = variant.find_field_named(field.ident.name) {
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(sub_span, span) {
|
|
|
|
self.dumper.variable_ref(span, VariableRefData {
|
|
|
|
span: sub_span.expect("No span fund for var ref"),
|
|
|
|
ref_id: f.did,
|
|
|
|
scope: self.cur_scope,
|
|
|
|
name: String::new()
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2015-08-02 14:52:50 -05:00
|
|
|
self.visit_pat(&field.pat);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
2015-09-01 22:37:07 -05:00
|
|
|
_ => visit::walk_pat(self, p),
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
2015-09-27 22:24:08 -05:00
|
|
|
|
|
|
|
|
|
|
|
fn process_var_decl(&mut self, p: &ast::Pat, value: String) {
|
|
|
|
// The local could declare multiple new vars, we must walk the
|
|
|
|
// pattern and collect them all.
|
|
|
|
let mut collector = PathCollector::new();
|
|
|
|
collector.visit_pat(&p);
|
|
|
|
self.visit_pat(&p);
|
|
|
|
|
|
|
|
for &(id, ref p, immut, _) in &collector.collected_paths {
|
2016-02-09 10:44:47 -06:00
|
|
|
let value = if immut == ast::Mutability::Immutable {
|
2015-09-27 22:24:08 -05:00
|
|
|
value.to_string()
|
|
|
|
} else {
|
|
|
|
"<mutable>".to_string()
|
|
|
|
};
|
|
|
|
let types = self.tcx.node_types();
|
2016-01-27 18:10:04 -06:00
|
|
|
let typ = types.get(&id).map(|t| t.to_string()).unwrap_or(String::new());
|
2015-09-27 22:24:08 -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.
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(sub_span, p.span) {
|
|
|
|
self.dumper.variable(p.span, VariableData {
|
|
|
|
span: sub_span.expect("No span found for variable"),
|
|
|
|
id: id,
|
|
|
|
name: path_to_string(p),
|
|
|
|
qualname: format!("{}${}", path_to_string(p), id),
|
|
|
|
value: value,
|
|
|
|
type_value: typ,
|
|
|
|
scope: 0
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2015-09-27 22:24:08 -05:00
|
|
|
}
|
|
|
|
}
|
2016-01-29 01:22:55 -06:00
|
|
|
|
|
|
|
/// Extract macro use and definition information from the AST node defined
|
|
|
|
/// by the given NodeId, using the expansion information from the node's
|
|
|
|
/// span.
|
|
|
|
///
|
|
|
|
/// If the span is not macro-generated, do nothing, else use callee and
|
|
|
|
/// callsite spans to record macro definition and use data, using the
|
|
|
|
/// mac_uses and mac_defs sets to prevent multiples.
|
|
|
|
fn process_macro_use(&mut self, span: Span, id: NodeId) {
|
|
|
|
let data = match self.save_ctxt.get_macro_use_data(span, id) {
|
|
|
|
None => return,
|
|
|
|
Some(data) => data,
|
|
|
|
};
|
|
|
|
let mut hasher = SipHasher::new();
|
|
|
|
data.callee_span.hash(&mut hasher);
|
|
|
|
let hash = hasher.finish();
|
|
|
|
let qualname = format!("{}::{}", data.name, hash);
|
|
|
|
// Don't write macro definition for imported macros
|
|
|
|
if !self.mac_defs.contains(&data.callee_span)
|
|
|
|
&& !data.imported {
|
|
|
|
self.mac_defs.insert(data.callee_span);
|
2016-02-03 01:44:53 -06:00
|
|
|
if let Some(sub_span) = self.span.span_for_macro_def_name(data.callee_span) {
|
2016-02-29 04:51:05 -06:00
|
|
|
self.dumper.macro_data(data.callee_span, MacroData {
|
|
|
|
span: sub_span,
|
|
|
|
name: data.name.clone(),
|
|
|
|
qualname: qualname.clone()
|
|
|
|
});
|
2016-02-03 01:44:53 -06:00
|
|
|
}
|
2016-01-29 01:22:55 -06:00
|
|
|
}
|
|
|
|
if !self.mac_uses.contains(&data.span) {
|
2016-02-03 01:44:53 -06:00
|
|
|
self.mac_uses.insert(data.span);
|
|
|
|
if let Some(sub_span) = self.span.span_for_macro_use_name(data.span) {
|
2016-02-29 04:51:05 -06:00
|
|
|
self.dumper.macro_use(data.span, MacroUseData {
|
|
|
|
span: sub_span,
|
|
|
|
name: data.name,
|
|
|
|
qualname: qualname,
|
|
|
|
scope: data.scope,
|
|
|
|
callee_span: data.callee_span,
|
|
|
|
imported: data.imported
|
|
|
|
}.normalize(&self.tcx));
|
2016-02-03 01:44:53 -06:00
|
|
|
}
|
2016-01-29 01:22:55 -06:00
|
|
|
}
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
2016-02-29 04:51:05 -06:00
|
|
|
impl<'l, 'tcx, 'v, D: Dump + 'l> Visitor<'v> for DumpVisitor<'l, 'tcx, D> {
|
2015-05-04 05:33:07 -05:00
|
|
|
fn visit_item(&mut self, item: &ast::Item) {
|
2016-02-09 04:36:51 -06:00
|
|
|
use syntax::ast::ItemKind::*;
|
2016-01-29 01:22:55 -06:00
|
|
|
self.process_macro_use(item.span, item.id);
|
2015-05-04 05:33:07 -05:00
|
|
|
match item.node {
|
2016-02-09 04:36:51 -06:00
|
|
|
Use(ref use_item) => {
|
2015-05-04 05:33:07 -05:00
|
|
|
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) => {
|
2016-02-29 04:51:05 -06:00
|
|
|
let scope = self.cur_scope;
|
|
|
|
self.process_def_kind(item.id, path.span, sub_span, def_id, scope);
|
|
|
|
|
2015-05-04 05:33:07 -05:00
|
|
|
Some(def_id)
|
2015-09-01 22:37:07 -05:00
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
|
|
|
// 'use' always introduces an alias, if there is not an explicit
|
|
|
|
// one, there is an implicit one.
|
2015-09-27 15:20:49 -05:00
|
|
|
let sub_span = match self.span.sub_span_after_keyword(use_item.span,
|
|
|
|
keywords::As) {
|
|
|
|
Some(sub_span) => Some(sub_span),
|
|
|
|
None => sub_span,
|
|
|
|
};
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(sub_span, path.span) {
|
|
|
|
self.dumper.use_data(path.span, UseData {
|
|
|
|
span: sub_span.expect("No span found for use"),
|
|
|
|
id: item.id,
|
|
|
|
mod_id: mod_id,
|
|
|
|
name: ident.name.to_string(),
|
|
|
|
scope: self.cur_scope
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
self.write_sub_paths_truncated(path, true);
|
|
|
|
}
|
|
|
|
ast::ViewPathGlob(ref path) => {
|
|
|
|
// Make a comma-separated list of names of imported modules.
|
2016-02-29 04:51:05 -06:00
|
|
|
let mut names = vec![];
|
2015-05-04 05:33:07 -05:00
|
|
|
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() {
|
2016-02-29 04:51:05 -06:00
|
|
|
names.push(n.to_string());
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-27 15:20:49 -05:00
|
|
|
let sub_span = self.span
|
|
|
|
.sub_span_of_token(path.span, token::BinOp(token::Star));
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(sub_span, path.span) {
|
|
|
|
self.dumper.use_glob(path.span, UseGlobData {
|
|
|
|
span: sub_span.expect("No span found for use glob"),
|
|
|
|
id: item.id,
|
|
|
|
names: names,
|
|
|
|
scope: self.cur_scope
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
self.write_sub_paths(path, true);
|
|
|
|
}
|
|
|
|
ast::ViewPathList(ref path, ref list) => {
|
|
|
|
for plid in list {
|
|
|
|
match plid.node {
|
2016-02-09 11:09:18 -06:00
|
|
|
ast::PathListItemKind::Ident { id, .. } => {
|
2016-02-29 04:51:05 -06:00
|
|
|
let scope = self.cur_scope;
|
|
|
|
if let Some(def_id) = self.lookup_type_ref(id) {
|
|
|
|
self.process_def_kind(id,
|
|
|
|
plid.span,
|
|
|
|
Some(plid.span),
|
|
|
|
def_id,
|
|
|
|
scope);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2015-09-01 22:37:07 -05:00
|
|
|
}
|
2016-02-09 11:09:18 -06:00
|
|
|
ast::PathListItemKind::Mod { .. } => (),
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.write_sub_paths(path, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ExternCrate(ref s) => {
|
2015-05-04 05:33:07 -05:00
|
|
|
let location = match *s {
|
|
|
|
Some(s) => s.to_string(),
|
2015-07-28 11:07:20 -05:00
|
|
|
None => item.ident.to_string(),
|
2015-05-04 05:33:07 -05:00
|
|
|
};
|
|
|
|
let alias_span = self.span.span_for_last_ident(item.span);
|
2015-11-21 13:39:05 -06:00
|
|
|
let cnum = match self.sess.cstore.extern_mod_stmt_cnum(item.id) {
|
2015-05-04 05:33:07 -05:00
|
|
|
Some(cnum) => cnum,
|
|
|
|
None => 0,
|
|
|
|
};
|
2016-02-29 04:51:05 -06:00
|
|
|
|
|
|
|
if !self.span.filter_generated(alias_span, item.span) {
|
|
|
|
self.dumper.extern_crate(item.span, ExternCrateData {
|
|
|
|
id: item.id,
|
|
|
|
name: item.ident.name.to_string(),
|
|
|
|
crate_num: cnum,
|
|
|
|
location: location,
|
|
|
|
span: alias_span.expect("No span found for extern crate"),
|
|
|
|
scope: self.cur_scope,
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
Fn(ref decl, _, _, _, ref ty_params, ref body) =>
|
2016-02-09 14:24:11 -06:00
|
|
|
self.process_fn(item, &decl, ty_params, &body),
|
2016-02-09 04:36:51 -06:00
|
|
|
Static(ref typ, _, ref expr) =>
|
2015-05-10 15:35:08 -05:00
|
|
|
self.process_static_or_const_item(item, typ, expr),
|
2016-02-09 04:36:51 -06:00
|
|
|
Const(ref typ, ref expr) =>
|
2015-05-10 15:35:08 -05:00
|
|
|
self.process_static_or_const_item(item, &typ, &expr),
|
2016-02-09 04:36:51 -06:00
|
|
|
Struct(ref def, ref ty_params) => self.process_struct(item, def, ty_params),
|
|
|
|
Enum(ref def, ref ty_params) => self.process_enum(item, def, ty_params),
|
|
|
|
Impl(_, _,
|
2015-05-04 05:33:07 -05:00
|
|
|
ref ty_params,
|
|
|
|
ref trait_ref,
|
|
|
|
ref typ,
|
|
|
|
ref impl_items) => {
|
2015-09-27 15:20:49 -05:00
|
|
|
self.process_impl(item, ty_params, trait_ref, &typ, impl_items)
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
Trait(_, ref generics, ref trait_refs, ref methods) =>
|
2015-05-04 05:33:07 -05:00
|
|
|
self.process_trait(item, generics, trait_refs, methods),
|
2016-02-09 04:36:51 -06:00
|
|
|
Mod(ref m) => {
|
2015-05-25 17:35:53 -05:00
|
|
|
self.process_mod(item);
|
|
|
|
self.nest(item.id, |v| visit::walk_mod(v, m));
|
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
Ty(ref ty, ref ty_params) => {
|
2015-06-13 17:49:28 -05:00
|
|
|
let qualname = format!("::{}", self.tcx.map.path_to_string(item.id));
|
2016-02-09 14:24:11 -06:00
|
|
|
let value = ty_to_string(&ty);
|
2015-05-04 05:33:07 -05:00
|
|
|
let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Type);
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(sub_span, item.span) {
|
|
|
|
self.dumper.typedef(item.span, TypedefData {
|
|
|
|
span: sub_span.expect("No span found for typedef"),
|
|
|
|
id: item.id,
|
|
|
|
qualname: qualname.clone(),
|
|
|
|
value: value
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2016-02-09 14:24:11 -06:00
|
|
|
self.visit_ty(&ty);
|
2015-05-04 05:33:07 -05:00
|
|
|
self.process_generic_params(ty_params, item.span, &qualname, item.id);
|
2015-09-01 22:37:07 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
Mac(_) => (),
|
2015-05-04 05:33:07 -05:00
|
|
|
_ => 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 {
|
2016-02-09 14:24:11 -06:00
|
|
|
self.visit_ty(&ty);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) {
|
2016-01-29 01:22:55 -06:00
|
|
|
self.process_macro_use(trait_item.span, trait_item.id);
|
2015-05-04 05:33:07 -05:00
|
|
|
match trait_item.node {
|
2016-02-09 10:54:11 -06:00
|
|
|
ast::TraitItemKind::Const(ref ty, Some(ref expr)) => {
|
2015-09-27 15:20:49 -05:00
|
|
|
self.process_const(trait_item.id,
|
|
|
|
trait_item.ident.name,
|
|
|
|
trait_item.span,
|
2016-02-09 14:24:11 -06:00
|
|
|
&ty,
|
|
|
|
&expr);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2016-02-09 10:54:11 -06:00
|
|
|
ast::TraitItemKind::Method(ref sig, ref body) => {
|
2015-07-08 19:23:29 -05:00
|
|
|
self.process_method(sig,
|
|
|
|
body.as_ref().map(|x| &**x),
|
|
|
|
trait_item.id,
|
|
|
|
trait_item.ident.name,
|
|
|
|
trait_item.span);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2016-02-09 10:54:11 -06:00
|
|
|
ast::TraitItemKind::Const(_, None) |
|
|
|
|
ast::TraitItemKind::Type(..) => {}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) {
|
2016-01-29 01:22:55 -06:00
|
|
|
self.process_macro_use(impl_item.span, impl_item.id);
|
2015-05-04 05:33:07 -05:00
|
|
|
match impl_item.node {
|
2015-11-13 07:15:04 -06:00
|
|
|
ast::ImplItemKind::Const(ref ty, ref expr) => {
|
2015-09-27 15:20:49 -05:00
|
|
|
self.process_const(impl_item.id,
|
|
|
|
impl_item.ident.name,
|
|
|
|
impl_item.span,
|
|
|
|
&ty,
|
|
|
|
&expr);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2015-11-13 07:15:04 -06:00
|
|
|
ast::ImplItemKind::Method(ref sig, ref body) => {
|
2015-07-08 19:23:29 -05:00
|
|
|
self.process_method(sig,
|
|
|
|
Some(body),
|
|
|
|
impl_item.id,
|
|
|
|
impl_item.ident.name,
|
|
|
|
impl_item.span);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2015-11-13 07:15:04 -06:00
|
|
|
ast::ImplItemKind::Type(_) |
|
|
|
|
ast::ImplItemKind::Macro(_) => {}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_ty(&mut self, t: &ast::Ty) {
|
2016-01-29 01:22:55 -06:00
|
|
|
self.process_macro_use(t.span, t.id);
|
2015-05-04 05:33:07 -05:00
|
|
|
match t.node {
|
2016-02-08 09:53:21 -06:00
|
|
|
ast::TyKind::Path(_, ref path) => {
|
2016-02-29 04:51:05 -06:00
|
|
|
if let Some(id) = self.lookup_type_ref(t.id) {
|
|
|
|
let sub_span = self.span.sub_span_for_type_name(t.span);
|
|
|
|
if !self.span.filter_generated(sub_span, t.span) {
|
|
|
|
self.dumper.type_ref(t.span, TypeRefData {
|
|
|
|
span: sub_span.expect("No span found for type ref"),
|
|
|
|
ref_id: Some(id),
|
|
|
|
scope: self.cur_scope,
|
|
|
|
qualname: String::new()
|
|
|
|
}.normalize(&self.tcx));
|
2015-09-01 22:37:07 -05:00
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
self.write_sub_paths_truncated(path, false);
|
|
|
|
|
|
|
|
visit::walk_path(self, path);
|
2015-09-01 22:37:07 -05:00
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
_ => visit::walk_ty(self, t),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_expr(&mut self, ex: &ast::Expr) {
|
2016-01-29 01:22:55 -06:00
|
|
|
self.process_macro_use(ex.span, ex.id);
|
2015-05-04 05:33:07 -05:00
|
|
|
match ex.node {
|
2016-02-08 09:05:05 -06:00
|
|
|
ast::ExprKind::Call(ref _f, ref _args) => {
|
2015-05-04 05:33:07 -05:00
|
|
|
// Don't need to do anything for function calls,
|
|
|
|
// because just walking the callee path does what we want.
|
|
|
|
visit::walk_expr(self, ex);
|
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ast::ExprKind::Path(_, ref path) => {
|
2015-07-07 21:30:18 -05:00
|
|
|
self.process_path(ex.id, path, None);
|
2015-05-04 05:33:07 -05:00
|
|
|
visit::walk_expr(self, ex);
|
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ast::ExprKind::Struct(ref path, ref fields, ref base) => {
|
2015-09-24 23:03:28 -05:00
|
|
|
let hir_expr = lower_expr(self.save_ctxt.lcx, ex);
|
2015-07-31 02:04:06 -05:00
|
|
|
let adt = self.tcx.expr_ty(&hir_expr).ty_adt_def().unwrap();
|
|
|
|
let def = self.tcx.resolve_expr(&hir_expr);
|
2015-09-27 15:20:49 -05:00
|
|
|
self.process_struct_lit(ex, path, fields, adt.variant_of_def(def), base)
|
2015-08-02 14:52:50 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ast::ExprKind::MethodCall(_, _, ref args) => self.process_method_call(ex, args),
|
|
|
|
ast::ExprKind::Field(ref sub_ex, _) => {
|
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);
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(field_data.span), ex.span) {
|
|
|
|
self.dumper.variable_ref(ex.span, field_data.normalize(&self.tcx));
|
|
|
|
}
|
2015-06-14 17:06:01 -05:00
|
|
|
}
|
2015-09-01 22:37:07 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ast::ExprKind::TupField(ref sub_ex, idx) => {
|
2016-02-09 14:24:11 -06:00
|
|
|
self.visit_expr(&sub_ex);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
2015-09-24 23:03:28 -05:00
|
|
|
let hir_node = lower_expr(self.save_ctxt.lcx, sub_ex);
|
2015-07-31 02:04:06 -05:00
|
|
|
let ty = &self.tcx.expr_ty_adjusted(&hir_node).sty;
|
2015-05-04 05:33:07 -05:00
|
|
|
match *ty {
|
2015-07-20 14:13:36 -05:00
|
|
|
ty::TyStruct(def, _) => {
|
2015-08-02 14:52:50 -05:00
|
|
|
let sub_span = self.span.sub_span_after_token(ex.span, token::Dot);
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(sub_span, ex.span) {
|
|
|
|
self.dumper.variable_ref(ex.span, VariableRefData {
|
|
|
|
span: sub_span.expect("No span found for var ref"),
|
|
|
|
ref_id: def.struct_variant().fields[idx.node].did,
|
|
|
|
scope: self.cur_scope,
|
|
|
|
name: String::new()
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2015-06-11 18:21:46 -05:00
|
|
|
ty::TyTuple(_) => {}
|
2015-05-04 05:33:07 -05:00
|
|
|
_ => self.sess.span_bug(ex.span,
|
2015-09-27 15:20:49 -05:00
|
|
|
&format!("Expected struct or tuple type, found {:?}",
|
|
|
|
ty)),
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2015-09-01 22:37:07 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ast::ExprKind::Closure(_, ref decl, ref body) => {
|
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 {
|
2016-02-09 14:24:11 -06:00
|
|
|
self.visit_ty(&arg.ty);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
2016-02-08 08:04:11 -06:00
|
|
|
if let ast::FunctionRetTy::Ty(ref ret_ty) = decl.output {
|
2016-02-09 14:24:11 -06:00
|
|
|
self.visit_ty(&ret_ty);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// walk the body
|
2016-02-09 14:24:11 -06:00
|
|
|
self.nest(ex.id, |v| v.visit_block(&body));
|
2015-09-01 22:37:07 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ast::ExprKind::ForLoop(ref pattern, ref subexpression, ref block, _) |
|
|
|
|
ast::ExprKind::WhileLet(ref pattern, ref subexpression, ref block, _) => {
|
2015-09-27 22:24:08 -05:00
|
|
|
let value = self.span.snippet(mk_sp(ex.span.lo, subexpression.span.hi));
|
|
|
|
self.process_var_decl(pattern, value);
|
|
|
|
visit::walk_expr(self, subexpression);
|
|
|
|
visit::walk_block(self, block);
|
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ast::ExprKind::IfLet(ref pattern, ref subexpression, ref block, ref opt_else) => {
|
2015-09-29 20:56:19 -05:00
|
|
|
let value = self.span.snippet(mk_sp(ex.span.lo, subexpression.span.hi));
|
|
|
|
self.process_var_decl(pattern, value);
|
|
|
|
visit::walk_expr(self, subexpression);
|
|
|
|
visit::walk_block(self, block);
|
|
|
|
opt_else.as_ref().map(|el| visit::walk_expr(self, el));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
_ => {
|
|
|
|
visit::walk_expr(self, ex)
|
2015-05-10 15:35:08 -05:00
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-29 01:22:55 -06:00
|
|
|
fn visit_mac(&mut self, mac: &ast::Mac) {
|
|
|
|
// These shouldn't exist in the AST at this point, log a span bug.
|
|
|
|
self.sess.span_bug(mac.span, "macro invocation should have been expanded out of AST");
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_pat(&mut self, p: &ast::Pat) {
|
2016-01-29 01:22:55 -06:00
|
|
|
self.process_macro_use(p.span, p.id);
|
2015-05-04 05:33:07 -05:00
|
|
|
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![];
|
2015-07-07 21:30:18 -05:00
|
|
|
|
2015-05-04 05:33:07 -05:00
|
|
|
// 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,
|
2015-09-27 15:20:49 -05:00
|
|
|
&format!("def_map has no key for {} in visit_arm", id));
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
let def = def_map.get(&id).unwrap().full_def();
|
|
|
|
match def {
|
2016-01-20 13:31:10 -06:00
|
|
|
Def::Local(_, id) => {
|
2016-02-09 10:44:47 -06:00
|
|
|
let value = if immut == ast::Mutability::Immutable {
|
2015-05-04 05:33:07 -05:00
|
|
|
self.span.snippet(p.span).to_string()
|
|
|
|
} else {
|
|
|
|
"<mutable>".to_string()
|
|
|
|
};
|
|
|
|
|
2015-09-27 15:20:49 -05:00
|
|
|
assert!(p.segments.len() == 1,
|
|
|
|
"qualified path for local variable def in arm");
|
2016-02-29 04:51:05 -06:00
|
|
|
if !self.span.filter_generated(Some(p.span), p.span) {
|
|
|
|
self.dumper.variable(p.span, VariableData {
|
|
|
|
span: p.span,
|
|
|
|
id: id,
|
|
|
|
name: path_to_string(p),
|
|
|
|
qualname: format!("{}${}", path_to_string(p), id),
|
|
|
|
value: value,
|
|
|
|
type_value: String::new(),
|
|
|
|
scope: 0
|
|
|
|
}.normalize(&self.tcx));
|
|
|
|
}
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2016-01-20 13:31:10 -06:00
|
|
|
Def::Variant(..) | Def::Enum(..) |
|
|
|
|
Def::TyAlias(..) | Def::Struct(..) => {
|
2015-05-04 05:33:07 -05:00
|
|
|
paths_to_process.push((id, p.clone(), Some(ref_kind)))
|
|
|
|
}
|
|
|
|
// FIXME(nrc) what are these doing here?
|
2016-01-20 13:31:10 -06:00
|
|
|
Def::Static(_, _) |
|
|
|
|
Def::Const(..) |
|
|
|
|
Def::AssociatedConst(..) => {}
|
2015-05-04 05:33:07 -05:00
|
|
|
_ => error!("unexpected definition kind when processing collected paths: {:?}",
|
2015-09-01 22:37:07 -05:00
|
|
|
def),
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|
2015-07-07 21:30:18 -05:00
|
|
|
|
2015-05-04 05:33:07 -05:00
|
|
|
for &(id, ref path, ref_kind) in &paths_to_process {
|
2015-07-07 21:30:18 -05:00
|
|
|
self.process_path(id, path, ref_kind);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(self, visit_expr, &arm.guard);
|
2015-07-07 21:30:18 -05:00
|
|
|
self.visit_expr(&arm.body);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_stmt(&mut self, s: &ast::Stmt) {
|
2016-01-29 01:22:55 -06:00
|
|
|
let id = s.node.id();
|
|
|
|
self.process_macro_use(s.span, id.unwrap());
|
2015-05-04 05:33:07 -05:00
|
|
|
visit::walk_stmt(self, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_local(&mut self, l: &ast::Local) {
|
2016-01-29 01:22:55 -06:00
|
|
|
self.process_macro_use(l.span, l.id);
|
2015-05-04 05:33:07 -05:00
|
|
|
let value = self.span.snippet(l.span);
|
2015-09-27 22:24:08 -05:00
|
|
|
self.process_var_decl(&l.pat, value);
|
2015-05-04 05:33:07 -05:00
|
|
|
|
|
|
|
// Just walk the initialiser and type (don't want to walk the pattern again).
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(self, visit_ty, &l.ty);
|
|
|
|
walk_list!(self, visit_expr, &l.init);
|
2015-05-04 05:33:07 -05:00
|
|
|
}
|
|
|
|
}
|