2015-05-04 10:33:07 +00: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.
|
|
|
|
|
2017-06-08 02:45:15 +00:00
|
|
|
//! Write the output of rustc's analysis to an implementor of Dump.
|
2015-05-04 10:33:07 +00:00
|
|
|
//!
|
|
|
|
//! 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).
|
2018-04-08 02:21:50 +00:00
|
|
|
//! DumpVisitor walks the AST and processes it, and JsonDumper is used for
|
|
|
|
//! recording the output.
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2017-06-08 02:45:15 +00:00
|
|
|
use rustc::hir::def::Def as HirDef;
|
|
|
|
use rustc::hir::def_id::DefId;
|
2018-09-24 14:28:53 +00:00
|
|
|
use rustc::session::config::Input;
|
2017-06-08 02:45:15 +00:00
|
|
|
use rustc::ty::{self, TyCtxt};
|
2017-08-01 02:43:11 +00:00
|
|
|
use rustc_data_structures::fx::FxHashSet;
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2018-09-22 21:19:39 +00:00
|
|
|
use std::path::Path;
|
2018-09-11 14:39:07 +00:00
|
|
|
use std::env;
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
use syntax::ast::{self, Attribute, NodeId, PatKind, CRATE_NODE_ID};
|
2016-11-16 08:21:52 +00:00
|
|
|
use syntax::parse::token;
|
|
|
|
use syntax::symbol::keywords;
|
2015-05-04 10:33:07 +00:00
|
|
|
use syntax::visit::{self, Visitor};
|
2017-10-16 19:07:26 +00:00
|
|
|
use syntax::print::pprust::{
|
|
|
|
bounds_to_string,
|
|
|
|
generic_params_to_string,
|
|
|
|
path_to_string,
|
|
|
|
ty_to_string
|
|
|
|
};
|
2015-05-04 10:33:07 +00:00
|
|
|
use syntax::ptr::P;
|
2018-08-18 10:14:03 +00:00
|
|
|
use syntax::source_map::{Spanned, DUMMY_SP, respan};
|
2016-06-21 22:08:13 +00:00
|
|
|
use syntax_pos::*;
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
use {escape, generated_code, lower_attributes, PathCollector, SaveContext};
|
2017-11-14 22:17:09 +00:00
|
|
|
use json_dumper::{Access, DumpOutput, JsonDumper};
|
2017-05-31 03:59:48 +00:00
|
|
|
use span_utils::SpanUtils;
|
|
|
|
use sig;
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2018-09-24 14:38:54 +00:00
|
|
|
use rls_data::{CompilationOptions, CratePreludeData, Def, DefKind, GlobalCrateId, Import,
|
|
|
|
ImportKind, Ref, RefKind, Relation, RelationKind, SpanData};
|
2017-03-14 04:08:47 +00:00
|
|
|
|
2015-06-08 22:36:30 +00:00
|
|
|
macro_rules! down_cast_data {
|
2016-03-28 21:21:01 +00:00
|
|
|
($id:ident, $kind:ident, $sp:expr) => {
|
2015-06-08 22:36:30 +00:00
|
|
|
let $id = if let super::Data::$kind(data) = $id {
|
|
|
|
data
|
|
|
|
} else {
|
2016-03-28 21:21:01 +00:00
|
|
|
span_bug!($sp, "unexpected data kind: {:?}", $id);
|
2016-07-02 15:49:50 +00:00
|
|
|
};
|
2015-06-08 22:36:30 +00:00
|
|
|
};
|
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2017-11-16 20:59:27 +00:00
|
|
|
macro_rules! access_from {
|
2018-01-29 05:12:09 +00:00
|
|
|
($save_ctxt:expr, $vis:expr, $id:expr) => {
|
|
|
|
Access {
|
2018-07-06 20:18:38 +00:00
|
|
|
public: $vis.node.is_pub(),
|
2018-01-29 05:12:09 +00:00
|
|
|
reachable: $save_ctxt.analysis.access_levels.is_reachable($id),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-16 20:59:27 +00:00
|
|
|
($save_ctxt:expr, $item:expr) => {
|
|
|
|
Access {
|
2018-07-06 20:18:38 +00:00
|
|
|
public: $item.vis.node.is_pub(),
|
2017-11-16 20:59:27 +00:00
|
|
|
reachable: $save_ctxt.analysis.access_levels.is_reachable($item.id),
|
|
|
|
}
|
2018-01-29 05:12:09 +00:00
|
|
|
};
|
2017-11-16 20:59:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 23:52:09 +00:00
|
|
|
pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> {
|
2015-05-05 07:27:44 +00:00
|
|
|
save_ctxt: SaveContext<'l, 'tcx>,
|
2016-05-03 02:23:22 +00:00
|
|
|
tcx: TyCtxt<'l, 'tcx, 'tcx>,
|
2017-07-18 23:52:09 +00:00
|
|
|
dumper: &'ll mut JsonDumper<O>,
|
2015-05-04 10:33:07 +00:00
|
|
|
|
|
|
|
span: SpanUtils<'l>,
|
|
|
|
|
2015-09-02 03:37:07 +00:00
|
|
|
cur_scope: NodeId,
|
2016-01-29 07:22:55 +00: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.
|
2018-08-18 10:55:43 +00:00
|
|
|
// mac_defs: FxHashSet<Span>,
|
2017-08-01 02:43:11 +00:00
|
|
|
macro_calls: FxHashSet<Span>,
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 23:52:09 +00:00
|
|
|
impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
|
2017-11-07 21:43:05 +00:00
|
|
|
pub fn new(
|
|
|
|
save_ctxt: SaveContext<'l, 'tcx>,
|
|
|
|
dumper: &'ll mut JsonDumper<O>,
|
|
|
|
) -> DumpVisitor<'l, 'tcx, 'll, O> {
|
2016-10-29 10:19:59 +00:00
|
|
|
let span_utils = SpanUtils::new(&save_ctxt.tcx.sess);
|
2016-02-29 10:51:05 +00:00
|
|
|
DumpVisitor {
|
2016-10-29 10:19:59 +00:00
|
|
|
tcx: save_ctxt.tcx,
|
2017-08-07 05:54:09 +00:00
|
|
|
save_ctxt,
|
|
|
|
dumper,
|
2015-06-13 22:49:28 +00:00
|
|
|
span: span_utils.clone(),
|
2016-08-31 11:00:29 +00:00
|
|
|
cur_scope: CRATE_NODE_ID,
|
2018-08-18 10:55:43 +00:00
|
|
|
// mac_defs: FxHashSet::default(),
|
2018-10-16 08:44:26 +00:00
|
|
|
macro_calls: FxHashSet::default(),
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-06 19:54:24 +00:00
|
|
|
fn nest_scope<F>(&mut self, scope_id: NodeId, f: F)
|
2017-11-07 21:43:05 +00:00
|
|
|
where
|
|
|
|
F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, O>),
|
2015-05-05 06:46:09 +00:00
|
|
|
{
|
|
|
|
let parent_scope = self.cur_scope;
|
|
|
|
self.cur_scope = scope_id;
|
|
|
|
f(self);
|
|
|
|
self.cur_scope = parent_scope;
|
|
|
|
}
|
|
|
|
|
2017-01-06 19:54:24 +00:00
|
|
|
fn nest_tables<F>(&mut self, item_id: NodeId, f: F)
|
2017-11-07 21:43:05 +00:00
|
|
|
where
|
|
|
|
F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, O>),
|
2017-01-06 19:54:24 +00:00
|
|
|
{
|
2017-01-26 00:41:06 +00:00
|
|
|
let item_def_id = self.tcx.hir.local_def_id(item_id);
|
2017-04-28 13:52:56 +00:00
|
|
|
if self.tcx.has_typeck_tables(item_def_id) {
|
|
|
|
let tables = self.tcx.typeck_tables_of(item_def_id);
|
|
|
|
let old_tables = self.save_ctxt.tables;
|
|
|
|
self.save_ctxt.tables = tables;
|
|
|
|
f(self);
|
|
|
|
self.save_ctxt.tables = old_tables;
|
|
|
|
} else {
|
2017-05-03 16:18:04 +00:00
|
|
|
f(self);
|
2017-01-25 01:40:47 +00:00
|
|
|
}
|
2017-01-06 19:54:24 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 02:45:15 +00:00
|
|
|
fn span_from_span(&self, span: Span) -> SpanData {
|
|
|
|
self.save_ctxt.span_from_span(span)
|
|
|
|
}
|
|
|
|
|
2015-05-04 10:33:07 +00:00
|
|
|
pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) {
|
2015-11-03 21:16:06 +00:00
|
|
|
let source_file = self.tcx.sess.local_crate_source_file.as_ref();
|
2016-02-29 10:51:05 +00:00
|
|
|
let crate_root = source_file.map(|source_file| {
|
2017-04-24 17:01:19 +00:00
|
|
|
let source_file = Path::new(source_file);
|
2016-02-29 10:51:05 +00:00
|
|
|
match source_file.file_name() {
|
2018-09-03 12:31:57 +00:00
|
|
|
Some(_) => source_file.parent().unwrap().display(),
|
|
|
|
None => source_file.display(),
|
|
|
|
}.to_string()
|
2016-02-29 10:51:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
let data = CratePreludeData {
|
2017-10-15 21:27:17 +00:00
|
|
|
crate_id: GlobalCrateId {
|
|
|
|
name: name.into(),
|
2017-11-07 21:43:05 +00:00
|
|
|
disambiguator: self.tcx
|
|
|
|
.sess
|
|
|
|
.local_crate_disambiguator()
|
|
|
|
.to_fingerprint()
|
|
|
|
.as_value(),
|
2017-10-15 21:27:17 +00:00
|
|
|
},
|
2018-10-12 14:16:00 +00:00
|
|
|
crate_root: crate_root.unwrap_or_else(|| "<no source>".to_owned()),
|
2017-06-08 02:45:15 +00:00
|
|
|
external_crates: self.save_ctxt.get_external_crates(),
|
|
|
|
span: self.span_from_span(krate.span),
|
2016-02-29 10:51:05 +00:00
|
|
|
};
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2017-06-08 02:45:15 +00:00
|
|
|
self.dumper.crate_prelude(data);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2018-09-24 14:28:53 +00:00
|
|
|
pub fn dump_compilation_options(&mut self, input: &Input, crate_name: &str) {
|
|
|
|
// Apply possible `remap-path-prefix` remapping to the input source file
|
|
|
|
// (and don't include remapping args anymore)
|
|
|
|
let (program, arguments) = {
|
2018-09-11 14:39:07 +00:00
|
|
|
let remap_arg_indices = {
|
2018-10-16 08:44:26 +00:00
|
|
|
let mut indices = FxHashSet::default();
|
2018-09-24 14:28:53 +00:00
|
|
|
// Args are guaranteed to be valid UTF-8 (checked early)
|
2018-09-11 14:39:07 +00:00
|
|
|
for (i, e) in env::args().enumerate() {
|
|
|
|
if e.starts_with("--remap-path-prefix=") {
|
|
|
|
indices.insert(i);
|
|
|
|
} else if e == "--remap-path-prefix" {
|
|
|
|
indices.insert(i);
|
|
|
|
indices.insert(i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
indices
|
|
|
|
};
|
|
|
|
|
2018-09-24 14:28:53 +00:00
|
|
|
let mut args = env::args()
|
2018-09-11 14:39:07 +00:00
|
|
|
.enumerate()
|
|
|
|
.filter(|(i, _)| !remap_arg_indices.contains(i))
|
2018-09-24 14:28:53 +00:00
|
|
|
.map(|(_, arg)| {
|
|
|
|
match input {
|
|
|
|
Input::File(ref path) if path == Path::new(&arg) => {
|
|
|
|
let mapped = &self.tcx.sess.local_crate_source_file;
|
|
|
|
mapped
|
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.to_string_lossy()
|
|
|
|
.into()
|
|
|
|
},
|
|
|
|
_ => arg,
|
2018-09-11 14:39:07 +00:00
|
|
|
}
|
2018-09-24 14:28:53 +00:00
|
|
|
});
|
2018-09-11 14:39:07 +00:00
|
|
|
|
2018-09-24 14:28:53 +00:00
|
|
|
(args.next().unwrap(), args.collect())
|
2018-09-11 14:39:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let data = CompilationOptions {
|
2018-09-22 21:19:39 +00:00
|
|
|
directory: self.tcx.sess.working_dir.0.clone(),
|
2018-09-24 14:28:53 +00:00
|
|
|
program,
|
|
|
|
arguments,
|
2018-09-22 21:19:39 +00:00
|
|
|
output: self.save_ctxt.compilation_output(crate_name),
|
2018-09-11 14:39:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
self.dumper.compilation_opts(data);
|
|
|
|
}
|
|
|
|
|
2015-05-04 10:33:07 +00: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)> {
|
2016-12-05 03:51:11 +00:00
|
|
|
let segments = &path.segments[if path.is_global() { 1 } else { 0 }..];
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2017-08-12 15:48:24 +00:00
|
|
|
let mut result = Vec::with_capacity(segments.len());
|
2018-09-03 12:31:57 +00:00
|
|
|
let mut segs = Vec::with_capacity(segments.len());
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2017-08-12 15:48:24 +00:00
|
|
|
for (i, seg) in segments.iter().enumerate() {
|
2015-05-04 10:33:07 +00:00
|
|
|
segs.push(seg.clone());
|
2015-09-02 03:37:07 +00:00
|
|
|
let sub_path = ast::Path {
|
2018-03-19 00:54:56 +00:00
|
|
|
span: seg.ident.span, // span for the last segment
|
2015-09-02 03:37:07 +00:00
|
|
|
segments: segs,
|
|
|
|
};
|
2016-12-05 03:51:11 +00:00
|
|
|
let qualname = if i == 0 && path.is_global() {
|
2015-05-04 10:33:07 +00:00
|
|
|
format!("::{}", path_to_string(&sub_path))
|
|
|
|
} else {
|
|
|
|
path_to_string(&sub_path)
|
|
|
|
};
|
2018-03-19 00:54:56 +00:00
|
|
|
result.push((seg.ident.span, qualname));
|
2015-05-04 10:33:07 +00:00
|
|
|
segs = sub_path.segments;
|
|
|
|
}
|
|
|
|
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2016-12-05 03:51:11 +00:00
|
|
|
fn write_sub_paths(&mut self, path: &ast::Path) {
|
2015-05-04 10:33:07 +00:00
|
|
|
let sub_paths = self.process_path_prefixes(path);
|
2017-06-08 02:45:15 +00:00
|
|
|
for (span, _) in sub_paths {
|
|
|
|
let span = self.span_from_span(span);
|
|
|
|
self.dumper.dump_ref(Ref {
|
|
|
|
kind: RefKind::Mod,
|
|
|
|
span,
|
|
|
|
ref_id: ::null_id(),
|
|
|
|
});
|
2015-05-04 10:33:07 +00: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.
|
2016-12-05 03:51:11 +00:00
|
|
|
fn write_sub_paths_truncated(&mut self, path: &ast::Path) {
|
2015-05-04 10:33:07 +00:00
|
|
|
let sub_paths = self.process_path_prefixes(path);
|
|
|
|
let len = sub_paths.len();
|
|
|
|
if len <= 1 {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-08 02:45:15 +00:00
|
|
|
for (span, _) in sub_paths.into_iter().take(len - 1) {
|
|
|
|
let span = self.span_from_span(span);
|
|
|
|
self.dumper.dump_ref(Ref {
|
|
|
|
kind: RefKind::Mod,
|
|
|
|
span,
|
|
|
|
ref_id: ::null_id(),
|
|
|
|
});
|
2015-05-04 10:33:07 +00: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;
|
|
|
|
}
|
2017-11-07 21:43:05 +00:00
|
|
|
let sub_paths = &sub_paths[..(len - 1)];
|
2015-05-04 10:33:07 +00:00
|
|
|
|
|
|
|
// write the trait part of the sub-path
|
2017-11-07 21:43:05 +00:00
|
|
|
let (ref span, _) = sub_paths[len - 2];
|
2017-06-08 02:45:15 +00:00
|
|
|
let span = self.span_from_span(*span);
|
|
|
|
self.dumper.dump_ref(Ref {
|
|
|
|
kind: RefKind::Type,
|
|
|
|
ref_id: ::null_id(),
|
|
|
|
span,
|
|
|
|
});
|
2015-05-04 10:33:07 +00:00
|
|
|
|
|
|
|
// write the other sub-paths
|
|
|
|
if len <= 2 {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-07 21:43:05 +00:00
|
|
|
let sub_paths = &sub_paths[..len - 2];
|
2017-06-08 02:45:15 +00:00
|
|
|
for &(ref span, _) in sub_paths {
|
|
|
|
let span = self.span_from_span(*span);
|
|
|
|
self.dumper.dump_ref(Ref {
|
|
|
|
kind: RefKind::Mod,
|
|
|
|
span,
|
|
|
|
ref_id: ::null_id(),
|
|
|
|
});
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-14 21:51:46 +00:00
|
|
|
fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
|
2016-11-25 11:21:19 +00:00
|
|
|
match self.save_ctxt.get_path_def(ref_id) {
|
2017-06-08 02:45:15 +00:00
|
|
|
HirDef::PrimTy(..) | HirDef::SelfTy(..) | HirDef::Err => None,
|
2016-11-25 11:21:19 +00:00
|
|
|
def => Some(def.def_id()),
|
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn process_formals(&mut self, formals: &'l [ast::Arg], qualname: &str) {
|
2015-05-04 10:33:07 +00:00
|
|
|
for arg in formals {
|
2015-05-05 10:03:20 +00:00
|
|
|
self.visit_pat(&arg.pat);
|
|
|
|
let mut collector = PathCollector::new();
|
|
|
|
collector.visit_pat(&arg.pat);
|
2015-05-04 10:33:07 +00:00
|
|
|
let span_utils = self.span.clone();
|
2017-11-01 04:59:06 +00:00
|
|
|
|
2018-03-19 00:54:56 +00:00
|
|
|
for (id, ident, ..) in collector.collected_idents {
|
2017-08-07 12:43:43 +00:00
|
|
|
let hir_id = self.tcx.hir.node_to_hir_id(id);
|
|
|
|
let typ = match self.save_ctxt.tables.node_id_to_type_opt(hir_id) {
|
2016-11-23 05:47:07 +00:00
|
|
|
Some(s) => s.to_string(),
|
|
|
|
None => continue,
|
|
|
|
};
|
2018-03-19 00:54:56 +00:00
|
|
|
let sub_span = span_utils.span_for_last_ident(ident.span);
|
|
|
|
if !self.span.filter_generated(sub_span, ident.span) {
|
2017-06-08 02:45:15 +00:00
|
|
|
let id = ::id_from_node_id(id, &self.save_ctxt);
|
|
|
|
let span = self.span_from_span(sub_span.expect("No span found for variable"));
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
self.dumper.dump_def(
|
2017-11-14 22:17:09 +00:00
|
|
|
&Access {
|
|
|
|
public: false,
|
|
|
|
reachable: false,
|
|
|
|
},
|
2017-11-07 21:43:05 +00:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Local,
|
|
|
|
id,
|
|
|
|
span,
|
2018-03-19 00:54:56 +00:00
|
|
|
name: ident.to_string(),
|
|
|
|
qualname: format!("{}::{}", qualname, ident.to_string()),
|
2017-11-07 21:43:05 +00:00
|
|
|
value: typ,
|
|
|
|
parent: None,
|
|
|
|
children: vec![],
|
|
|
|
decl_id: None,
|
|
|
|
docs: String::new(),
|
|
|
|
sig: None,
|
|
|
|
attributes: vec![],
|
|
|
|
},
|
|
|
|
);
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
fn process_method(
|
|
|
|
&mut self,
|
|
|
|
sig: &'l ast::MethodSig,
|
|
|
|
body: Option<&'l ast::Block>,
|
|
|
|
id: ast::NodeId,
|
2018-06-10 19:24:24 +00:00
|
|
|
ident: ast::Ident,
|
2017-11-07 21:43:05 +00:00
|
|
|
generics: &'l ast::Generics,
|
|
|
|
vis: ast::Visibility,
|
|
|
|
span: Span,
|
|
|
|
) {
|
2018-06-10 19:24:24 +00:00
|
|
|
debug!("process_method: {}:{}", id, ident);
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2018-06-10 19:24:24 +00:00
|
|
|
if let Some(mut method_data) = self.save_ctxt.get_method_data(id, ident.name, span) {
|
2017-09-22 02:18:47 +00:00
|
|
|
let sig_str = ::make_signature(&sig.decl, &generics);
|
2016-01-21 22:58:09 +00:00
|
|
|
if body.is_some() {
|
2017-11-07 21:43:05 +00:00
|
|
|
self.nest_tables(
|
|
|
|
id,
|
|
|
|
|v| v.process_formals(&sig.decl.inputs, &method_data.qualname),
|
|
|
|
);
|
2016-01-21 22:58:09 +00:00
|
|
|
}
|
2016-06-16 10:28:39 +00:00
|
|
|
|
2017-09-22 02:18:47 +00:00
|
|
|
self.process_generic_params(&generics, span, &method_data.qualname, id);
|
2017-06-08 02:45:15 +00:00
|
|
|
|
|
|
|
method_data.value = sig_str;
|
2018-06-10 19:24:24 +00:00
|
|
|
method_data.sig = sig::method_signature(id, ident, generics, sig, &self.save_ctxt);
|
2018-01-29 05:12:09 +00:00
|
|
|
self.dumper.dump_def(&access_from!(self.save_ctxt, vis, id), method_data);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// walk arg and return types
|
|
|
|
for arg in &sig.decl.inputs {
|
|
|
|
self.visit_ty(&arg.ty);
|
|
|
|
}
|
|
|
|
|
2016-02-08 14:04:11 +00:00
|
|
|
if let ast::FunctionRetTy::Ty(ref ret_ty) = sig.decl.output {
|
2015-05-04 10:33:07 +00:00
|
|
|
self.visit_ty(ret_ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk the fn body
|
|
|
|
if let Some(body) = body {
|
2017-01-06 19:54:24 +00:00
|
|
|
self.nest_tables(id, |v| v.nest_scope(id, |v| v.visit_block(body)));
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-02 03:37:07 +00:00
|
|
|
fn process_struct_field_def(&mut self, field: &ast::StructField, parent_id: NodeId) {
|
2015-06-05 04:03:48 +00:00
|
|
|
let field_data = self.save_ctxt.get_field_data(field, parent_id);
|
2017-06-08 02:45:15 +00:00
|
|
|
if let Some(field_data) = field_data {
|
2017-11-16 20:59:27 +00:00
|
|
|
self.dumper.dump_def(&access_from!(self.save_ctxt, field), field_data);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dump generic params bindings, then visit_generics
|
2017-11-07 21:43:05 +00:00
|
|
|
fn process_generic_params(
|
|
|
|
&mut self,
|
|
|
|
generics: &'l ast::Generics,
|
|
|
|
full_span: Span,
|
|
|
|
prefix: &str,
|
|
|
|
id: NodeId,
|
|
|
|
) {
|
2017-10-16 19:07:26 +00:00
|
|
|
for param in &generics.params {
|
2018-05-26 18:16:21 +00:00
|
|
|
match param.kind {
|
2018-05-27 19:07:09 +00:00
|
|
|
ast::GenericParamKind::Lifetime { .. } => {}
|
|
|
|
ast::GenericParamKind::Type { .. } => {
|
2018-05-26 18:16:21 +00:00
|
|
|
let param_ss = param.ident.span;
|
|
|
|
let name = escape(self.span.snippet(param_ss));
|
|
|
|
// Append $id to name to make sure each one is unique.
|
|
|
|
let qualname = format!("{}::{}${}", prefix, name, id);
|
|
|
|
if !self.span.filter_generated(Some(param_ss), full_span) {
|
|
|
|
let id = ::id_from_node_id(param.id, &self.save_ctxt);
|
|
|
|
let span = self.span_from_span(param_ss);
|
2017-06-08 02:45:15 +00:00
|
|
|
|
2018-05-26 18:16:21 +00:00
|
|
|
self.dumper.dump_def(
|
|
|
|
&Access {
|
|
|
|
public: false,
|
|
|
|
reachable: false,
|
|
|
|
},
|
|
|
|
Def {
|
|
|
|
kind: DefKind::Type,
|
|
|
|
id,
|
|
|
|
span,
|
|
|
|
name,
|
|
|
|
qualname,
|
|
|
|
value: String::new(),
|
|
|
|
parent: None,
|
|
|
|
children: vec![],
|
|
|
|
decl_id: None,
|
|
|
|
docs: String::new(),
|
|
|
|
sig: None,
|
|
|
|
attributes: vec![],
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2017-10-16 19:07:26 +00:00
|
|
|
}
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
self.visit_generics(generics);
|
|
|
|
}
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
fn process_fn(
|
|
|
|
&mut self,
|
|
|
|
item: &'l ast::Item,
|
|
|
|
decl: &'l ast::FnDecl,
|
|
|
|
ty_params: &'l ast::Generics,
|
|
|
|
body: &'l ast::Block,
|
|
|
|
) {
|
2016-01-21 22:58:09 +00:00
|
|
|
if let Some(fn_data) = self.save_ctxt.get_item_data(item) {
|
2017-06-08 02:45:15 +00:00
|
|
|
down_cast_data!(fn_data, DefData, item.span);
|
2017-11-07 21:43:05 +00:00
|
|
|
self.nest_tables(
|
|
|
|
item.id,
|
|
|
|
|v| v.process_formals(&decl.inputs, &fn_data.qualname),
|
|
|
|
);
|
2016-01-21 22:58:09 +00:00
|
|
|
self.process_generic_params(ty_params, item.span, &fn_data.qualname, item.id);
|
2017-11-16 20:59:27 +00:00
|
|
|
self.dumper.dump_def(&access_from!(self.save_ctxt, item), fn_data);
|
2016-01-21 22:58:09 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
|
|
|
|
for arg in &decl.inputs {
|
2015-05-10 20:35:08 +00:00
|
|
|
self.visit_ty(&arg.ty);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 14:04:11 +00:00
|
|
|
if let ast::FunctionRetTy::Ty(ref ret_ty) = decl.output {
|
2015-05-10 20:35:08 +00:00
|
|
|
self.visit_ty(&ret_ty);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 19:54:24 +00:00
|
|
|
self.nest_tables(item.id, |v| v.nest_scope(item.id, |v| v.visit_block(&body)));
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
fn process_static_or_const_item(
|
|
|
|
&mut self,
|
|
|
|
item: &'l ast::Item,
|
|
|
|
typ: &'l ast::Ty,
|
|
|
|
expr: &'l ast::Expr,
|
|
|
|
) {
|
2017-08-07 15:44:01 +00:00
|
|
|
self.nest_tables(item.id, |v| {
|
|
|
|
if let Some(var_data) = v.save_ctxt.get_item_data(item) {
|
|
|
|
down_cast_data!(var_data, DefData, item.span);
|
2017-11-16 20:59:27 +00:00
|
|
|
v.dumper.dump_def(&access_from!(v.save_ctxt, item), var_data);
|
2017-08-07 15:44:01 +00:00
|
|
|
}
|
|
|
|
v.visit_ty(&typ);
|
|
|
|
v.visit_expr(expr);
|
|
|
|
});
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
fn process_assoc_const(
|
|
|
|
&mut self,
|
|
|
|
id: ast::NodeId,
|
|
|
|
name: ast::Name,
|
|
|
|
span: Span,
|
|
|
|
typ: &'l ast::Ty,
|
|
|
|
expr: Option<&'l ast::Expr>,
|
|
|
|
parent_id: DefId,
|
|
|
|
vis: ast::Visibility,
|
|
|
|
attrs: &'l [Attribute],
|
|
|
|
) {
|
2016-04-06 10:51:55 +00:00
|
|
|
let qualname = format!("::{}", self.tcx.node_path_str(id));
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2015-09-27 20:20:49 +00:00
|
|
|
let sub_span = self.span.sub_span_after_keyword(span, keywords::Const);
|
2015-05-10 20:35:08 +00:00
|
|
|
|
2016-02-29 10:51:05 +00:00
|
|
|
if !self.span.filter_generated(sub_span, span) {
|
2017-06-08 02:45:15 +00:00
|
|
|
let sig = sig::assoc_const_signature(id, name, typ, expr, &self.save_ctxt);
|
|
|
|
let span = self.span_from_span(sub_span.expect("No span found for variable"));
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
self.dumper.dump_def(
|
2018-01-29 05:12:09 +00:00
|
|
|
&access_from!(self.save_ctxt, vis, id),
|
2017-11-07 21:43:05 +00:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Const,
|
2017-11-14 22:17:09 +00:00
|
|
|
id: ::id_from_node_id(id, &self.save_ctxt),
|
2017-11-07 21:43:05 +00:00
|
|
|
span,
|
|
|
|
name: name.to_string(),
|
|
|
|
qualname,
|
|
|
|
value: ty_to_string(&typ),
|
|
|
|
parent: Some(::id_from_def_id(parent_id)),
|
|
|
|
children: vec![],
|
|
|
|
decl_id: None,
|
|
|
|
docs: self.save_ctxt.docs_for_attrs(attrs),
|
|
|
|
sig,
|
|
|
|
attributes: lower_attributes(attrs.to_owned(), &self.save_ctxt),
|
|
|
|
},
|
|
|
|
);
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
|
|
|
|
// walk type and init value
|
|
|
|
self.visit_ty(typ);
|
2017-06-06 00:19:54 +00:00
|
|
|
if let Some(expr) = expr {
|
|
|
|
self.visit_expr(expr);
|
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 20:46:39 +00:00
|
|
|
// FIXME tuple structs should generate tuple-specific data.
|
2017-11-07 21:43:05 +00:00
|
|
|
fn process_struct(
|
|
|
|
&mut self,
|
|
|
|
item: &'l ast::Item,
|
|
|
|
def: &'l ast::VariantData,
|
|
|
|
ty_params: &'l ast::Generics,
|
|
|
|
) {
|
2017-11-06 01:56:43 +00:00
|
|
|
debug!("process_struct {:?} {:?}", item, item.span);
|
2016-05-11 20:46:39 +00:00
|
|
|
let name = item.ident.to_string();
|
2016-04-06 10:51:55 +00:00
|
|
|
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2017-11-06 01:56:43 +00:00
|
|
|
let (kind, keyword) = match item.node {
|
|
|
|
ast::ItemKind::Struct(_, _) => (DefKind::Struct, keywords::Struct),
|
|
|
|
ast::ItemKind::Union(_, _) => (DefKind::Union, keywords::Union),
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let sub_span = self.span.sub_span_after_keyword(item.span, keyword);
|
|
|
|
let (value, fields) = match item.node {
|
|
|
|
ast::ItemKind::Struct(ast::VariantData::Struct(ref fields, _), _) |
|
|
|
|
ast::ItemKind::Union(ast::VariantData::Struct(ref fields, _), _) => {
|
|
|
|
let include_priv_fields = !self.save_ctxt.config.pub_only;
|
|
|
|
let fields_str = fields
|
|
|
|
.iter()
|
|
|
|
.enumerate()
|
|
|
|
.filter_map(|(i, f)| {
|
2018-07-06 20:18:38 +00:00
|
|
|
if include_priv_fields || f.vis.node.is_pub() {
|
2017-11-07 21:43:05 +00:00
|
|
|
f.ident
|
|
|
|
.map(|i| i.to_string())
|
|
|
|
.or_else(|| Some(i.to_string()))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2017-11-06 01:56:43 +00:00
|
|
|
})
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join(", ");
|
|
|
|
let value = format!("{} {{ {} }}", name, fields_str);
|
2017-11-07 21:43:05 +00:00
|
|
|
(
|
|
|
|
value,
|
|
|
|
fields
|
|
|
|
.iter()
|
|
|
|
.map(|f| ::id_from_node_id(f.id, &self.save_ctxt))
|
|
|
|
.collect(),
|
|
|
|
)
|
2017-11-06 01:56:43 +00:00
|
|
|
}
|
2017-11-07 21:43:05 +00:00
|
|
|
_ => (String::new(), vec![]),
|
2016-05-11 20:46:39 +00:00
|
|
|
};
|
|
|
|
|
2016-02-29 10:51:05 +00:00
|
|
|
if !self.span.filter_generated(sub_span, item.span) {
|
2017-06-08 02:45:15 +00:00
|
|
|
let span = self.span_from_span(sub_span.expect("No span found for struct"));
|
2017-11-07 21:43:05 +00:00
|
|
|
self.dumper.dump_def(
|
2017-11-16 20:59:27 +00:00
|
|
|
&access_from!(self.save_ctxt, item),
|
2017-11-07 21:43:05 +00:00
|
|
|
Def {
|
|
|
|
kind,
|
|
|
|
id: ::id_from_node_id(item.id, &self.save_ctxt),
|
|
|
|
span,
|
|
|
|
name,
|
|
|
|
qualname: qualname.clone(),
|
|
|
|
value,
|
|
|
|
parent: None,
|
|
|
|
children: fields,
|
|
|
|
decl_id: None,
|
|
|
|
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
|
|
|
sig: sig::item_signature(item, &self.save_ctxt),
|
|
|
|
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
|
|
|
|
},
|
|
|
|
);
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
|
|
|
|
2015-10-08 20:45:46 +00:00
|
|
|
for field in def.fields() {
|
2015-06-05 04:03:48 +00:00
|
|
|
self.process_struct_field_def(field, item.id);
|
2016-04-06 08:19:10 +00:00
|
|
|
self.visit_ty(&field.ty);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 19:21:49 +00:00
|
|
|
self.process_generic_params(ty_params, item.span, &qualname, item.id);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
fn process_enum(
|
|
|
|
&mut self,
|
|
|
|
item: &'l ast::Item,
|
|
|
|
enum_definition: &'l ast::EnumDef,
|
|
|
|
ty_params: &'l ast::Generics,
|
|
|
|
) {
|
2015-06-02 19:21:20 +00:00
|
|
|
let enum_data = self.save_ctxt.get_item_data(item);
|
2016-01-21 22:58:09 +00:00
|
|
|
let enum_data = match enum_data {
|
|
|
|
None => return,
|
|
|
|
Some(data) => data,
|
|
|
|
};
|
2017-06-08 02:45:15 +00:00
|
|
|
down_cast_data!(enum_data, DefData, item.span);
|
2015-06-08 22:36:30 +00:00
|
|
|
|
2017-11-16 20:59:27 +00:00
|
|
|
let access = access_from!(self.save_ctxt, item);
|
2017-11-14 22:17:09 +00:00
|
|
|
|
2015-06-08 22:36:30 +00:00
|
|
|
for variant in &enum_definition.variants {
|
2018-03-18 22:21:30 +00:00
|
|
|
let name = variant.node.ident.name.to_string();
|
2018-09-03 12:31:57 +00:00
|
|
|
let qualname = format!("{}::{}", enum_data.qualname, name);
|
2015-10-01 15:47:27 +00:00
|
|
|
|
2016-01-22 05:53:23 +00:00
|
|
|
match variant.node.data {
|
2016-05-11 20:46:39 +00:00
|
|
|
ast::VariantData::Struct(ref fields, _) => {
|
2016-02-29 10:51:05 +00:00
|
|
|
let sub_span = self.span.span_for_first_ident(variant.span);
|
2017-11-07 21:43:05 +00:00
|
|
|
let fields_str = fields
|
|
|
|
.iter()
|
|
|
|
.enumerate()
|
|
|
|
.map(|(i, f)| {
|
2018-10-12 14:16:00 +00:00
|
|
|
f.ident.map(|i| i.to_string()).unwrap_or_else(|| i.to_string())
|
2017-11-07 21:43:05 +00:00
|
|
|
})
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join(", ");
|
2017-06-08 02:45:15 +00:00
|
|
|
let value = format!("{}::{} {{ {} }}", enum_data.name, name, fields_str);
|
2016-02-29 10:51:05 +00:00
|
|
|
if !self.span.filter_generated(sub_span, variant.span) {
|
2017-11-07 21:43:05 +00:00
|
|
|
let span = self
|
|
|
|
.span_from_span(sub_span.expect("No span found for struct variant"));
|
2017-06-08 02:45:15 +00:00
|
|
|
let id = ::id_from_node_id(variant.node.data.id(), &self.save_ctxt);
|
|
|
|
let parent = Some(::id_from_node_id(item.id, &self.save_ctxt));
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
self.dumper.dump_def(
|
2017-11-14 22:17:09 +00:00
|
|
|
&access,
|
2017-11-07 21:43:05 +00:00
|
|
|
Def {
|
|
|
|
kind: DefKind::StructVariant,
|
|
|
|
id,
|
|
|
|
span,
|
|
|
|
name,
|
|
|
|
qualname,
|
|
|
|
value,
|
|
|
|
parent,
|
|
|
|
children: vec![],
|
|
|
|
decl_id: None,
|
|
|
|
docs: self.save_ctxt.docs_for_attrs(&variant.node.attrs),
|
|
|
|
sig: sig::variant_signature(variant, &self.save_ctxt),
|
|
|
|
attributes: lower_attributes(
|
|
|
|
variant.node.attrs.clone(),
|
|
|
|
&self.save_ctxt,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
);
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
2016-01-22 05:53:23 +00:00
|
|
|
}
|
2016-05-11 20:46:39 +00:00
|
|
|
ref v => {
|
2016-02-29 10:51:05 +00:00
|
|
|
let sub_span = self.span.span_for_first_ident(variant.span);
|
2017-06-08 02:45:15 +00:00
|
|
|
let mut value = format!("{}::{}", enum_data.name, name);
|
2016-05-11 20:46:39 +00:00
|
|
|
if let &ast::VariantData::Tuple(ref fields, _) = v {
|
2017-06-08 02:45:15 +00:00
|
|
|
value.push('(');
|
2017-11-07 21:43:05 +00:00
|
|
|
value.push_str(&fields
|
|
|
|
.iter()
|
|
|
|
.map(|f| ty_to_string(&f.ty))
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join(", "));
|
2017-06-08 02:45:15 +00:00
|
|
|
value.push(')');
|
2016-05-11 20:46:39 +00:00
|
|
|
}
|
2016-02-29 10:51:05 +00:00
|
|
|
if !self.span.filter_generated(sub_span, variant.span) {
|
2017-06-08 02:45:15 +00:00
|
|
|
let span =
|
|
|
|
self.span_from_span(sub_span.expect("No span found for tuple variant"));
|
|
|
|
let id = ::id_from_node_id(variant.node.data.id(), &self.save_ctxt);
|
|
|
|
let parent = Some(::id_from_node_id(item.id, &self.save_ctxt));
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
self.dumper.dump_def(
|
2017-11-14 22:17:09 +00:00
|
|
|
&access,
|
2017-11-07 21:43:05 +00:00
|
|
|
Def {
|
|
|
|
kind: DefKind::TupleVariant,
|
|
|
|
id,
|
|
|
|
span,
|
|
|
|
name,
|
|
|
|
qualname,
|
|
|
|
value,
|
|
|
|
parent,
|
|
|
|
children: vec![],
|
|
|
|
decl_id: None,
|
|
|
|
docs: self.save_ctxt.docs_for_attrs(&variant.node.attrs),
|
|
|
|
sig: sig::variant_signature(variant, &self.save_ctxt),
|
|
|
|
attributes: lower_attributes(
|
|
|
|
variant.node.attrs.clone(),
|
|
|
|
&self.save_ctxt,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
);
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
2016-01-22 05:53:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 15:47:27 +00:00
|
|
|
|
2015-10-08 20:45:46 +00:00
|
|
|
for field in variant.node.data.fields() {
|
2015-10-10 00:28:40 +00:00
|
|
|
self.process_struct_field_def(field, variant.node.data.id());
|
2016-04-06 08:19:10 +00:00
|
|
|
self.visit_ty(&field.ty);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_generic_params(ty_params, item.span, &enum_data.qualname, item.id);
|
2017-11-14 22:17:09 +00:00
|
|
|
self.dumper.dump_def(&access, enum_data);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
fn process_impl(
|
|
|
|
&mut self,
|
|
|
|
item: &'l ast::Item,
|
|
|
|
type_parameters: &'l ast::Generics,
|
|
|
|
trait_ref: &'l Option<ast::TraitRef>,
|
|
|
|
typ: &'l ast::Ty,
|
|
|
|
impl_items: &'l [ast::ImplItem],
|
|
|
|
) {
|
2016-01-21 22:58:09 +00:00
|
|
|
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
|
2018-02-02 07:29:59 +00:00
|
|
|
if let super::Data::RelationData(rel, imp) = impl_data {
|
|
|
|
self.dumper.dump_relation(rel);
|
|
|
|
self.dumper.dump_impl(imp);
|
|
|
|
} else {
|
|
|
|
span_bug!(item.span, "unexpected data kind: {:?}", impl_data);
|
|
|
|
}
|
2015-06-08 22:36:30 +00:00
|
|
|
}
|
2017-02-13 04:50:58 +00:00
|
|
|
self.visit_ty(&typ);
|
2017-01-10 03:09:13 +00:00
|
|
|
if let &Some(ref trait_ref) = trait_ref {
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_path(trait_ref.ref_id, &trait_ref.path);
|
2017-01-10 03:09:13 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
self.process_generic_params(type_parameters, item.span, "", item.id);
|
|
|
|
for impl_item in impl_items {
|
2017-01-26 00:41:06 +00:00
|
|
|
let map = &self.tcx.hir;
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_impl_item(impl_item, map.local_def_id(item.id));
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
fn process_trait(
|
|
|
|
&mut self,
|
|
|
|
item: &'l ast::Item,
|
|
|
|
generics: &'l ast::Generics,
|
2018-06-14 11:08:58 +00:00
|
|
|
trait_refs: &'l ast::GenericBounds,
|
2017-11-07 21:43:05 +00:00
|
|
|
methods: &'l [ast::TraitItem],
|
|
|
|
) {
|
2016-05-11 20:46:39 +00:00
|
|
|
let name = item.ident.to_string();
|
2016-04-06 10:51:55 +00:00
|
|
|
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
2016-05-11 20:46:39 +00:00
|
|
|
let mut val = name.clone();
|
2017-10-16 19:07:26 +00:00
|
|
|
if !generics.params.is_empty() {
|
|
|
|
val.push_str(&generic_params_to_string(&generics.params));
|
2016-05-11 20:46:39 +00:00
|
|
|
}
|
|
|
|
if !trait_refs.is_empty() {
|
|
|
|
val.push_str(": ");
|
|
|
|
val.push_str(&bounds_to_string(trait_refs));
|
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Trait);
|
2016-02-29 10:51:05 +00:00
|
|
|
if !self.span.filter_generated(sub_span, item.span) {
|
2017-06-08 02:45:15 +00:00
|
|
|
let id = ::id_from_node_id(item.id, &self.save_ctxt);
|
|
|
|
let span = self.span_from_span(sub_span.expect("No span found for trait"));
|
2017-11-07 21:43:05 +00:00
|
|
|
let children = methods
|
|
|
|
.iter()
|
|
|
|
.map(|i| ::id_from_node_id(i.id, &self.save_ctxt))
|
|
|
|
.collect();
|
|
|
|
self.dumper.dump_def(
|
2017-11-16 20:59:27 +00:00
|
|
|
&access_from!(self.save_ctxt, item),
|
2017-11-07 21:43:05 +00:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Trait,
|
|
|
|
id,
|
|
|
|
span,
|
|
|
|
name,
|
|
|
|
qualname: qualname.clone(),
|
|
|
|
value: val,
|
|
|
|
parent: None,
|
|
|
|
children,
|
|
|
|
decl_id: None,
|
|
|
|
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
|
|
|
sig: sig::item_signature(item, &self.save_ctxt),
|
|
|
|
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
|
|
|
|
},
|
|
|
|
);
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
|
|
|
|
// super-traits
|
2015-06-08 21:51:54 +00:00
|
|
|
for super_bound in trait_refs.iter() {
|
2015-05-04 10:33:07 +00:00
|
|
|
let trait_ref = match *super_bound {
|
2018-06-14 11:23:46 +00:00
|
|
|
ast::GenericBound::Trait(ref trait_ref, _) => trait_ref,
|
|
|
|
ast::GenericBound::Outlives(..) => continue,
|
2015-05-04 10:33:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let trait_ref = &trait_ref.trait_ref;
|
2016-09-14 21:51:46 +00:00
|
|
|
if let Some(id) = self.lookup_def_id(trait_ref.ref_id) {
|
2016-02-29 10:51:05 +00:00
|
|
|
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) {
|
2017-06-08 02:45:15 +00:00
|
|
|
let span = self.span_from_span(sub_span.expect("No span found for trait ref"));
|
|
|
|
self.dumper.dump_ref(Ref {
|
|
|
|
kind: RefKind::Type,
|
|
|
|
span,
|
|
|
|
ref_id: ::id_from_def_id(id),
|
|
|
|
});
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !self.span.filter_generated(sub_span, trait_ref.path.span) {
|
2017-06-08 02:45:15 +00:00
|
|
|
let sub_span = self.span_from_span(sub_span.expect("No span for inheritance"));
|
|
|
|
self.dumper.dump_relation(Relation {
|
|
|
|
kind: RelationKind::SuperTrait,
|
2016-02-29 10:51:05 +00:00
|
|
|
span: sub_span,
|
2017-06-08 02:45:15 +00:00
|
|
|
from: ::id_from_def_id(id),
|
|
|
|
to: ::id_from_node_id(item.id, &self.save_ctxt),
|
|
|
|
});
|
2015-09-02 03:37:07 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk generics and methods
|
2015-06-02 19:21:49 +00:00
|
|
|
self.process_generic_params(generics, item.span, &qualname, item.id);
|
2015-05-04 10:33:07 +00:00
|
|
|
for method in methods {
|
2017-01-26 00:41:06 +00:00
|
|
|
let map = &self.tcx.hir;
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_trait_item(method, map.local_def_id(item.id))
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-02 03:42:38 +00:00
|
|
|
// `item` is the module in question, represented as an item.
|
|
|
|
fn process_mod(&mut self, item: &ast::Item) {
|
2016-01-21 22:58:09 +00:00
|
|
|
if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
|
2017-06-08 02:45:15 +00:00
|
|
|
down_cast_data!(mod_data, DefData, item.span);
|
2017-11-16 20:59:27 +00:00
|
|
|
self.dumper.dump_def(&access_from!(self.save_ctxt, item), mod_data);
|
2016-01-21 22:58:09 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 20:46:06 +00:00
|
|
|
fn dump_path_ref(&mut self, id: NodeId, path: &ast::Path) {
|
|
|
|
let path_data = self.save_ctxt.get_path_data(id, path);
|
|
|
|
if let Some(path_data) = path_data {
|
|
|
|
self.dumper.dump_ref(path_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-01 04:59:06 +00:00
|
|
|
fn process_path(&mut self, id: NodeId, path: &'l ast::Path) {
|
2017-11-01 20:22:44 +00:00
|
|
|
debug!("process_path {:?}", path);
|
2017-11-07 20:46:06 +00:00
|
|
|
if generated_code(path.span) {
|
2015-07-08 02:30:18 +00:00
|
|
|
return;
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
2017-11-07 20:46:06 +00:00
|
|
|
self.dump_path_ref(id, path);
|
2015-07-08 02:30:18 +00:00
|
|
|
|
2018-02-23 17:48:54 +00:00
|
|
|
// Type arguments
|
2017-11-01 04:59:06 +00:00
|
|
|
for seg in &path.segments {
|
2018-05-16 11:57:45 +00:00
|
|
|
if let Some(ref generic_args) = seg.args {
|
|
|
|
match **generic_args {
|
2018-05-26 22:54:48 +00:00
|
|
|
ast::GenericArgs::AngleBracketed(ref data) => {
|
2018-06-22 23:33:03 +00:00
|
|
|
for arg in &data.args {
|
|
|
|
match arg {
|
|
|
|
ast::GenericArg::Type(ty) => self.visit_ty(ty),
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2018-05-26 22:54:48 +00:00
|
|
|
}
|
2018-02-13 11:32:37 +00:00
|
|
|
ast::GenericArgs::Parenthesized(ref data) => {
|
2017-11-01 04:59:06 +00:00
|
|
|
for t in &data.inputs {
|
|
|
|
self.visit_ty(t);
|
|
|
|
}
|
|
|
|
if let Some(ref t) = data.output {
|
|
|
|
self.visit_ty(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-08 02:30:18 +00:00
|
|
|
// Modules or types in the path prefix.
|
2016-11-25 11:21:19 +00:00
|
|
|
match self.save_ctxt.get_path_def(id) {
|
2017-06-08 02:45:15 +00:00
|
|
|
HirDef::Method(did) => {
|
2016-11-10 00:06:34 +00:00
|
|
|
let ti = self.tcx.associated_item(did);
|
|
|
|
if ti.kind == ty::AssociatedKind::Method && ti.method_has_self_argument {
|
|
|
|
self.write_sub_path_trait_truncated(path);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-08 02:45:15 +00:00
|
|
|
HirDef::Fn(..) |
|
|
|
|
HirDef::Const(..) |
|
|
|
|
HirDef::Static(..) |
|
|
|
|
HirDef::StructCtor(..) |
|
|
|
|
HirDef::VariantCtor(..) |
|
|
|
|
HirDef::AssociatedConst(..) |
|
|
|
|
HirDef::Local(..) |
|
|
|
|
HirDef::Upvar(..) |
|
|
|
|
HirDef::Struct(..) |
|
|
|
|
HirDef::Union(..) |
|
|
|
|
HirDef::Variant(..) |
|
|
|
|
HirDef::TyAlias(..) |
|
|
|
|
HirDef::AssociatedTy(..) => self.write_sub_paths_truncated(path),
|
2015-09-02 03:37:07 +00:00
|
|
|
_ => {}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
fn process_struct_lit(
|
|
|
|
&mut self,
|
|
|
|
ex: &'l ast::Expr,
|
|
|
|
path: &'l ast::Path,
|
|
|
|
fields: &'l [ast::Field],
|
|
|
|
variant: &'l ty::VariantDef,
|
|
|
|
base: &'l Option<P<ast::Expr>>,
|
|
|
|
) {
|
2016-12-05 03:51:11 +00:00
|
|
|
self.write_sub_paths_truncated(path);
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2015-06-14 22:06:01 +00:00
|
|
|
if let Some(struct_lit_data) = self.save_ctxt.get_expr_data(ex) {
|
2017-06-08 02:45:15 +00:00
|
|
|
down_cast_data!(struct_lit_data, RefData, ex.span);
|
|
|
|
if !generated_code(ex.span) {
|
|
|
|
self.dumper.dump_ref(struct_lit_data);
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
|
|
|
|
2015-06-14 22:06:01 +00:00
|
|
|
for field in fields {
|
2017-11-07 21:43:05 +00:00
|
|
|
if let Some(field_data) = self.save_ctxt.get_field_ref_data(field, variant) {
|
2017-06-08 02:45:15 +00:00
|
|
|
self.dumper.dump_ref(field_data);
|
2016-01-21 22:58:09 +00:00
|
|
|
}
|
2015-06-08 21:51:54 +00:00
|
|
|
|
2015-06-14 22:06:01 +00:00
|
|
|
self.visit_expr(&field.expr)
|
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
2015-06-08 21:51:54 +00:00
|
|
|
|
2015-09-28 11:26:26 +00:00
|
|
|
walk_list!(self, visit_expr, base);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
fn process_method_call(
|
|
|
|
&mut self,
|
|
|
|
ex: &'l ast::Expr,
|
|
|
|
seg: &'l ast::PathSegment,
|
|
|
|
args: &'l [P<ast::Expr>],
|
|
|
|
) {
|
2017-11-06 02:52:42 +00:00
|
|
|
debug!("process_method_call {:?} {:?}", ex, ex.span);
|
2016-02-29 10:51:05 +00:00
|
|
|
if let Some(mcd) = self.save_ctxt.get_expr_data(ex) {
|
2017-06-08 02:45:15 +00:00
|
|
|
down_cast_data!(mcd, RefData, ex.span);
|
|
|
|
if !generated_code(ex.span) {
|
|
|
|
self.dumper.dump_ref(mcd);
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
2015-07-06 23:42:43 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2017-11-01 20:22:44 +00:00
|
|
|
// Explicit types in the turbo-fish.
|
2018-05-16 11:57:45 +00:00
|
|
|
if let Some(ref generic_args) = seg.args {
|
|
|
|
if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
|
2018-06-22 23:33:03 +00:00
|
|
|
for arg in &data.args {
|
|
|
|
match arg {
|
|
|
|
ast::GenericArg::Type(ty) => self.visit_ty(ty),
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
2017-11-01 20:22:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-04 10:33:07 +00:00
|
|
|
// walk receiver and args
|
2015-09-28 11:26:26 +00:00
|
|
|
walk_list!(self, visit_expr, args);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn process_pat(&mut self, p: &'l ast::Pat) {
|
2015-05-04 10:33:07 +00:00
|
|
|
match p.node {
|
2017-01-10 03:09:13 +00:00
|
|
|
PatKind::Struct(ref _path, ref fields, _) => {
|
|
|
|
// FIXME do something with _path?
|
2017-08-07 12:43:43 +00:00
|
|
|
let hir_id = self.tcx.hir.node_to_hir_id(p.id);
|
|
|
|
let adt = match self.save_ctxt.tables.node_id_to_type_opt(hir_id) {
|
2016-11-23 05:47:07 +00:00
|
|
|
Some(ty) => ty.ty_adt_def().unwrap(),
|
|
|
|
None => {
|
|
|
|
visit::walk_pat(self, p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2016-11-25 11:21:19 +00:00
|
|
|
let variant = adt.variant_of_def(self.save_ctxt.get_path_def(p.id));
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2018-04-05 00:20:21 +00:00
|
|
|
for &Spanned { node: ref field, span } in fields {
|
2015-08-02 19:52:50 +00:00
|
|
|
let sub_span = self.span.span_for_first_ident(span);
|
2018-04-05 00:20:21 +00:00
|
|
|
if let Some(index) = self.tcx.find_field_index(field.ident, variant) {
|
2016-02-29 10:51:05 +00:00
|
|
|
if !self.span.filter_generated(sub_span, span) {
|
2017-06-08 02:45:15 +00:00
|
|
|
let span =
|
|
|
|
self.span_from_span(sub_span.expect("No span fund for var ref"));
|
|
|
|
self.dumper.dump_ref(Ref {
|
|
|
|
kind: RefKind::Variable,
|
|
|
|
span,
|
2018-04-05 00:20:21 +00:00
|
|
|
ref_id: ::id_from_def_id(variant.fields[index].did),
|
2017-06-08 02:45:15 +00:00
|
|
|
});
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
2015-08-02 19:52:50 +00:00
|
|
|
self.visit_pat(&field.pat);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-02 03:37:07 +00:00
|
|
|
_ => visit::walk_pat(self, p),
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-28 03:24:08 +00:00
|
|
|
|
2018-02-24 00:12:35 +00:00
|
|
|
fn process_var_decl_multi(&mut self, pats: &'l [P<ast::Pat>]) {
|
|
|
|
let mut collector = PathCollector::new();
|
|
|
|
for pattern in pats {
|
|
|
|
// collect paths from the arm's patterns
|
|
|
|
collector.visit_pat(&pattern);
|
|
|
|
self.visit_pat(&pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
// process collected paths
|
2018-03-19 00:54:56 +00:00
|
|
|
for (id, ident, immut) in collector.collected_idents {
|
2018-02-24 00:12:35 +00:00
|
|
|
match self.save_ctxt.get_path_def(id) {
|
|
|
|
HirDef::Local(id) => {
|
|
|
|
let mut value = if immut == ast::Mutability::Immutable {
|
2018-09-03 12:31:57 +00:00
|
|
|
self.span.snippet(ident.span)
|
2018-02-24 00:12:35 +00:00
|
|
|
} else {
|
2018-09-03 12:31:57 +00:00
|
|
|
"<mutable>".to_owned()
|
2018-02-24 00:12:35 +00:00
|
|
|
};
|
|
|
|
let hir_id = self.tcx.hir.node_to_hir_id(id);
|
|
|
|
let typ = self.save_ctxt
|
|
|
|
.tables
|
|
|
|
.node_id_to_type_opt(hir_id)
|
|
|
|
.map(|t| t.to_string())
|
2018-10-12 14:16:00 +00:00
|
|
|
.unwrap_or_default();
|
2018-02-24 00:12:35 +00:00
|
|
|
value.push_str(": ");
|
|
|
|
value.push_str(&typ);
|
|
|
|
|
2018-03-19 00:54:56 +00:00
|
|
|
if !self.span.filter_generated(Some(ident.span), ident.span) {
|
|
|
|
let qualname = format!("{}${}", ident.to_string(), id);
|
2018-02-24 00:12:35 +00:00
|
|
|
let id = ::id_from_node_id(id, &self.save_ctxt);
|
2018-03-19 00:54:56 +00:00
|
|
|
let span = self.span_from_span(ident.span);
|
2018-02-24 00:12:35 +00:00
|
|
|
|
|
|
|
self.dumper.dump_def(
|
|
|
|
&Access {
|
|
|
|
public: false,
|
|
|
|
reachable: false,
|
|
|
|
},
|
|
|
|
Def {
|
|
|
|
kind: DefKind::Local,
|
|
|
|
id,
|
|
|
|
span,
|
2018-03-19 00:54:56 +00:00
|
|
|
name: ident.to_string(),
|
2018-02-24 00:12:35 +00:00
|
|
|
qualname,
|
|
|
|
value: typ,
|
|
|
|
parent: None,
|
|
|
|
children: vec![],
|
|
|
|
decl_id: None,
|
|
|
|
docs: String::new(),
|
|
|
|
sig: None,
|
|
|
|
attributes: vec![],
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HirDef::StructCtor(..) |
|
|
|
|
HirDef::VariantCtor(..) |
|
|
|
|
HirDef::Const(..) |
|
|
|
|
HirDef::AssociatedConst(..) |
|
|
|
|
HirDef::Struct(..) |
|
|
|
|
HirDef::Variant(..) |
|
|
|
|
HirDef::TyAlias(..) |
|
|
|
|
HirDef::AssociatedTy(..) |
|
|
|
|
HirDef::SelfTy(..) => {
|
2018-03-19 00:54:56 +00:00
|
|
|
self.dump_path_ref(id, &ast::Path::from_ident(ident));
|
2018-02-24 00:12:35 +00:00
|
|
|
}
|
|
|
|
def => error!(
|
|
|
|
"unexpected definition kind when processing collected idents: {:?}",
|
|
|
|
def
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (id, ref path) in collector.collected_paths {
|
|
|
|
self.process_path(id, path);
|
|
|
|
}
|
|
|
|
}
|
2015-09-28 03:24:08 +00:00
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn process_var_decl(&mut self, p: &'l ast::Pat, value: String) {
|
2015-09-28 03:24:08 +00:00
|
|
|
// 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);
|
|
|
|
|
2018-03-19 00:54:56 +00:00
|
|
|
for (id, ident, immut) in collector.collected_idents {
|
2016-09-06 00:44:26 +00:00
|
|
|
let mut value = match immut {
|
|
|
|
ast::Mutability::Immutable => value.to_string(),
|
|
|
|
_ => String::new(),
|
2015-09-28 03:24:08 +00:00
|
|
|
};
|
2017-08-07 12:43:43 +00:00
|
|
|
let hir_id = self.tcx.hir.node_to_hir_id(id);
|
|
|
|
let typ = match self.save_ctxt.tables.node_id_to_type_opt(hir_id) {
|
2016-09-06 00:44:26 +00:00
|
|
|
Some(typ) => {
|
|
|
|
let typ = typ.to_string();
|
|
|
|
if !value.is_empty() {
|
|
|
|
value.push_str(": ");
|
|
|
|
}
|
|
|
|
value.push_str(&typ);
|
|
|
|
typ
|
|
|
|
}
|
|
|
|
None => String::new(),
|
|
|
|
};
|
|
|
|
|
2015-09-28 03:24:08 +00:00
|
|
|
// Get the span only for the name of the variable (I hope the path
|
|
|
|
// is only ever a variable name, but who knows?).
|
2018-03-19 00:54:56 +00:00
|
|
|
let sub_span = self.span.span_for_last_ident(ident.span);
|
2015-09-28 03:24:08 +00:00
|
|
|
// Rust uses the id of the pattern for var lookups, so we'll use it too.
|
2018-03-19 00:54:56 +00:00
|
|
|
if !self.span.filter_generated(sub_span, ident.span) {
|
|
|
|
let qualname = format!("{}${}", ident.to_string(), id);
|
2017-06-08 02:45:15 +00:00
|
|
|
let id = ::id_from_node_id(id, &self.save_ctxt);
|
|
|
|
let span = self.span_from_span(sub_span.expect("No span found for variable"));
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
self.dumper.dump_def(
|
2017-11-14 22:17:09 +00:00
|
|
|
&Access {
|
|
|
|
public: false,
|
|
|
|
reachable: false,
|
|
|
|
},
|
2017-11-07 21:43:05 +00:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Local,
|
|
|
|
id,
|
|
|
|
span,
|
2018-03-19 00:54:56 +00:00
|
|
|
name: ident.to_string(),
|
2017-11-07 21:43:05 +00:00
|
|
|
qualname,
|
|
|
|
value: typ,
|
|
|
|
parent: None,
|
|
|
|
children: vec![],
|
|
|
|
decl_id: None,
|
|
|
|
docs: String::new(),
|
|
|
|
sig: None,
|
|
|
|
attributes: vec![],
|
|
|
|
},
|
|
|
|
);
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
2015-09-28 03:24:08 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-29 07:22:55 +00: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.
|
2017-06-08 02:45:15 +00:00
|
|
|
fn process_macro_use(&mut self, span: Span) {
|
2017-07-25 06:46:14 +00:00
|
|
|
let source_span = span.source_callsite();
|
2018-09-03 12:31:57 +00:00
|
|
|
if !self.macro_calls.insert(source_span) {
|
2017-07-25 06:46:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-08 02:45:15 +00:00
|
|
|
let data = match self.save_ctxt.get_macro_use_data(span) {
|
2016-01-29 07:22:55 +00:00
|
|
|
None => return,
|
|
|
|
Some(data) => data,
|
|
|
|
};
|
2017-06-08 02:45:15 +00:00
|
|
|
|
2017-07-25 06:46:14 +00:00
|
|
|
self.dumper.macro_use(data);
|
|
|
|
|
2017-06-08 02:45:15 +00:00
|
|
|
// FIXME write the macro def
|
|
|
|
// let mut hasher = DefaultHasher::new();
|
|
|
|
// data.callee_span.hash(&mut hasher);
|
|
|
|
// let hash = hasher.finish();
|
|
|
|
// let qualname = format!("{}::{}", data.name, hash);
|
2016-01-29 07:22:55 +00:00
|
|
|
// Don't write macro definition for imported macros
|
2017-06-08 02:45:15 +00:00
|
|
|
// if !self.mac_defs.contains(&data.callee_span)
|
|
|
|
// && !data.imported {
|
|
|
|
// self.mac_defs.insert(data.callee_span);
|
|
|
|
// if let Some(sub_span) = self.span.span_for_macro_def_name(data.callee_span) {
|
|
|
|
// self.dumper.macro_data(MacroData {
|
|
|
|
// span: sub_span,
|
|
|
|
// name: data.name.clone(),
|
|
|
|
// qualname: qualname.clone(),
|
|
|
|
// // FIXME where do macro docs come from?
|
|
|
|
// docs: String::new(),
|
|
|
|
// }.lower(self.tcx));
|
|
|
|
// }
|
|
|
|
// }
|
2016-01-29 07:22:55 +00:00
|
|
|
}
|
2016-08-30 04:00:48 +00:00
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId) {
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_macro_use(trait_item.span);
|
2018-03-10 14:45:47 +00:00
|
|
|
let vis_span = trait_item.span.shrink_to_lo();
|
2016-08-30 04:00:48 +00:00
|
|
|
match trait_item.node {
|
2017-06-06 00:19:54 +00:00
|
|
|
ast::TraitItemKind::Const(ref ty, ref expr) => {
|
2017-11-07 21:43:05 +00:00
|
|
|
self.process_assoc_const(
|
|
|
|
trait_item.id,
|
|
|
|
trait_item.ident.name,
|
|
|
|
trait_item.span,
|
|
|
|
&ty,
|
|
|
|
expr.as_ref().map(|e| &**e),
|
|
|
|
trait_id,
|
2018-02-04 12:19:14 +00:00
|
|
|
respan(vis_span, ast::VisibilityKind::Public),
|
2017-11-07 21:43:05 +00:00
|
|
|
&trait_item.attrs,
|
|
|
|
);
|
2016-08-30 04:00:48 +00:00
|
|
|
}
|
|
|
|
ast::TraitItemKind::Method(ref sig, ref body) => {
|
2017-11-07 21:43:05 +00:00
|
|
|
self.process_method(
|
|
|
|
sig,
|
|
|
|
body.as_ref().map(|x| &**x),
|
|
|
|
trait_item.id,
|
|
|
|
trait_item.ident,
|
|
|
|
&trait_item.generics,
|
2018-02-04 12:19:14 +00:00
|
|
|
respan(vis_span, ast::VisibilityKind::Public),
|
2017-11-07 21:43:05 +00:00
|
|
|
trait_item.span,
|
|
|
|
);
|
2016-08-30 04:00:48 +00:00
|
|
|
}
|
2017-06-06 00:19:54 +00:00
|
|
|
ast::TraitItemKind::Type(ref bounds, ref default_ty) => {
|
2017-03-29 23:14:04 +00:00
|
|
|
// FIXME do something with _bounds (for type refs)
|
|
|
|
let name = trait_item.ident.name.to_string();
|
|
|
|
let qualname = format!("::{}", self.tcx.node_path_str(trait_item.id));
|
2017-11-07 21:43:05 +00:00
|
|
|
let sub_span = self.span
|
|
|
|
.sub_span_after_keyword(trait_item.span, keywords::Type);
|
2017-03-29 23:14:04 +00:00
|
|
|
|
|
|
|
if !self.span.filter_generated(sub_span, trait_item.span) {
|
2017-06-08 02:45:15 +00:00
|
|
|
let span = self.span_from_span(sub_span.expect("No span found for assoc type"));
|
|
|
|
let id = ::id_from_node_id(trait_item.id, &self.save_ctxt);
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
self.dumper.dump_def(
|
2017-11-14 22:17:09 +00:00
|
|
|
&Access {
|
|
|
|
public: true,
|
|
|
|
reachable: true,
|
|
|
|
},
|
2017-11-07 21:43:05 +00:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Type,
|
|
|
|
id,
|
|
|
|
span,
|
|
|
|
name,
|
|
|
|
qualname,
|
|
|
|
value: self.span.snippet(trait_item.span),
|
|
|
|
parent: Some(::id_from_def_id(trait_id)),
|
|
|
|
children: vec![],
|
|
|
|
decl_id: None,
|
|
|
|
docs: self.save_ctxt.docs_for_attrs(&trait_item.attrs),
|
|
|
|
sig: sig::assoc_type_signature(
|
|
|
|
trait_item.id,
|
|
|
|
trait_item.ident,
|
|
|
|
Some(bounds),
|
|
|
|
default_ty.as_ref().map(|ty| &**ty),
|
|
|
|
&self.save_ctxt,
|
|
|
|
),
|
|
|
|
attributes: lower_attributes(trait_item.attrs.clone(), &self.save_ctxt),
|
|
|
|
},
|
|
|
|
);
|
2017-03-29 23:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if let &Some(ref default_ty) = default_ty {
|
|
|
|
self.visit_ty(default_ty)
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 04:00:48 +00:00
|
|
|
ast::TraitItemKind::Macro(_) => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn process_impl_item(&mut self, impl_item: &'l ast::ImplItem, impl_id: DefId) {
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_macro_use(impl_item.span);
|
2016-08-30 04:00:48 +00:00
|
|
|
match impl_item.node {
|
|
|
|
ast::ImplItemKind::Const(ref ty, ref expr) => {
|
2017-11-07 21:43:05 +00:00
|
|
|
self.process_assoc_const(
|
|
|
|
impl_item.id,
|
|
|
|
impl_item.ident.name,
|
|
|
|
impl_item.span,
|
|
|
|
&ty,
|
|
|
|
Some(expr),
|
|
|
|
impl_id,
|
|
|
|
impl_item.vis.clone(),
|
|
|
|
&impl_item.attrs,
|
|
|
|
);
|
2016-08-30 04:00:48 +00:00
|
|
|
}
|
|
|
|
ast::ImplItemKind::Method(ref sig, ref body) => {
|
2017-11-07 21:43:05 +00:00
|
|
|
self.process_method(
|
|
|
|
sig,
|
|
|
|
Some(body),
|
|
|
|
impl_item.id,
|
|
|
|
impl_item.ident,
|
|
|
|
&impl_item.generics,
|
|
|
|
impl_item.vis.clone(),
|
|
|
|
impl_item.span,
|
|
|
|
);
|
2016-08-30 04:00:48 +00:00
|
|
|
}
|
2017-06-06 00:19:54 +00:00
|
|
|
ast::ImplItemKind::Type(ref ty) => {
|
|
|
|
// FIXME uses of the assoc type should ideally point to this
|
|
|
|
// 'def' and the name here should be a ref to the def in the
|
|
|
|
// trait.
|
|
|
|
self.visit_ty(ty)
|
|
|
|
}
|
2018-07-03 17:38:14 +00:00
|
|
|
ast::ImplItemKind::Existential(ref bounds) => {
|
|
|
|
// FIXME uses of the assoc type should ideally point to this
|
|
|
|
// 'def' and the name here should be a ref to the def in the
|
|
|
|
// trait.
|
|
|
|
for bound in bounds.iter() {
|
2018-07-17 09:21:26 +00:00
|
|
|
if let ast::GenericBound::Trait(trait_ref, _) = bound {
|
2018-07-03 17:38:14 +00:00
|
|
|
self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 04:00:48 +00:00
|
|
|
ast::ImplItemKind::Macro(_) => {}
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 21:04:00 +00:00
|
|
|
|
2017-12-15 02:19:17 +00:00
|
|
|
/// Dumps imports in a use tree recursively.
|
|
|
|
///
|
|
|
|
/// A use tree is an import that may contain nested braces (RFC 2128). The `use_tree` parameter
|
|
|
|
/// is the current use tree under scrutiny, while `id` and `prefix` are its corresponding node
|
|
|
|
/// id and path. `root_item` is the topmost use tree in the hierarchy.
|
|
|
|
///
|
|
|
|
/// If `use_tree` is a simple or glob import, it is dumped into the analysis data. Otherwise,
|
|
|
|
/// each child use tree is dumped recursively.
|
2017-09-26 21:04:00 +00:00
|
|
|
fn process_use_tree(&mut self,
|
|
|
|
use_tree: &'l ast::UseTree,
|
|
|
|
id: NodeId,
|
2017-12-04 20:59:49 +00:00
|
|
|
root_item: &'l ast::Item,
|
2017-09-26 21:04:00 +00:00
|
|
|
prefix: &ast::Path) {
|
|
|
|
let path = &use_tree.prefix;
|
2017-12-30 21:44:22 +00:00
|
|
|
|
|
|
|
// The access is calculated using the current tree ID, but with the root tree's visibility
|
|
|
|
// (since nested trees don't have their own visibility).
|
2018-01-29 05:12:09 +00:00
|
|
|
let access = access_from!(self.save_ctxt, root_item.vis, id);
|
2017-12-15 02:19:17 +00:00
|
|
|
|
|
|
|
// The parent def id of a given use tree is always the enclosing item.
|
2017-12-04 20:59:49 +00:00
|
|
|
let parent = self.save_ctxt.tcx.hir.opt_local_def_id(id)
|
|
|
|
.and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
|
|
|
|
.map(::id_from_def_id);
|
2017-09-26 21:04:00 +00:00
|
|
|
|
|
|
|
match use_tree.kind {
|
2018-03-09 15:58:44 +00:00
|
|
|
ast::UseTreeKind::Simple(..) => {
|
|
|
|
let ident = use_tree.ident();
|
2017-09-26 21:04:00 +00:00
|
|
|
let path = ast::Path {
|
|
|
|
segments: prefix.segments
|
|
|
|
.iter()
|
|
|
|
.chain(path.segments.iter())
|
|
|
|
.cloned()
|
|
|
|
.collect(),
|
|
|
|
span: path.span,
|
|
|
|
};
|
|
|
|
|
|
|
|
let sub_span = self.span.span_for_last_ident(path.span);
|
2018-05-15 08:34:17 +00:00
|
|
|
let alias_span = self.span.sub_span_after_keyword(use_tree.span, keywords::As);
|
|
|
|
let ref_id = self.lookup_def_id(id);
|
2017-09-26 21:04:00 +00:00
|
|
|
|
|
|
|
if !self.span.filter_generated(sub_span, path.span) {
|
2018-05-15 08:34:17 +00:00
|
|
|
let span = self.span_from_span(sub_span.expect("No span found for use"));
|
|
|
|
let alias_span = alias_span.map(|sp| self.span_from_span(sp));
|
2017-09-26 21:04:00 +00:00
|
|
|
self.dumper.import(&access, Import {
|
|
|
|
kind: ImportKind::Use,
|
2018-05-15 08:34:17 +00:00
|
|
|
ref_id: ref_id.map(|id| ::id_from_def_id(id)),
|
2017-09-26 21:04:00 +00:00
|
|
|
span,
|
2018-05-15 08:34:17 +00:00
|
|
|
alias_span,
|
2017-09-26 21:04:00 +00:00
|
|
|
name: ident.to_string(),
|
|
|
|
value: String::new(),
|
2017-12-04 20:59:49 +00:00
|
|
|
parent,
|
2017-09-26 21:04:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
self.write_sub_paths_truncated(&path);
|
|
|
|
}
|
|
|
|
ast::UseTreeKind::Glob => {
|
|
|
|
let path = ast::Path {
|
|
|
|
segments: prefix.segments
|
|
|
|
.iter()
|
|
|
|
.chain(path.segments.iter())
|
|
|
|
.cloned()
|
|
|
|
.collect(),
|
|
|
|
span: path.span,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make a comma-separated list of names of imported modules.
|
|
|
|
let glob_map = &self.save_ctxt.analysis.glob_map;
|
|
|
|
let glob_map = glob_map.as_ref().unwrap();
|
2018-07-26 15:11:10 +00:00
|
|
|
let names = if glob_map.contains_key(&id) {
|
|
|
|
glob_map.get(&id).unwrap().iter().map(|n| n.to_string()).collect()
|
|
|
|
} else {
|
|
|
|
Vec::new()
|
|
|
|
};
|
2017-09-26 21:04:00 +00:00
|
|
|
|
|
|
|
let sub_span = self.span.sub_span_of_token(use_tree.span,
|
|
|
|
token::BinOp(token::Star));
|
|
|
|
if !self.span.filter_generated(sub_span, use_tree.span) {
|
|
|
|
let span =
|
|
|
|
self.span_from_span(sub_span.expect("No span found for use glob"));
|
|
|
|
self.dumper.import(&access, Import {
|
|
|
|
kind: ImportKind::GlobUse,
|
|
|
|
ref_id: None,
|
|
|
|
span,
|
2018-05-15 08:34:17 +00:00
|
|
|
alias_span: None,
|
2017-09-26 21:04:00 +00:00
|
|
|
name: "*".to_owned(),
|
|
|
|
value: names.join(", "),
|
2017-12-04 20:59:49 +00:00
|
|
|
parent,
|
2017-09-26 21:04:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
self.write_sub_paths(&path);
|
|
|
|
}
|
|
|
|
ast::UseTreeKind::Nested(ref nested_items) => {
|
|
|
|
let prefix = ast::Path {
|
|
|
|
segments: prefix.segments
|
|
|
|
.iter()
|
|
|
|
.chain(path.segments.iter())
|
|
|
|
.cloned()
|
|
|
|
.collect(),
|
|
|
|
span: path.span,
|
|
|
|
};
|
|
|
|
for &(ref tree, id) in nested_items {
|
2017-12-04 20:59:49 +00:00
|
|
|
self.process_use_tree(tree, id, root_item, &prefix);
|
2017-09-26 21:04:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-30 22:10:57 +00:00
|
|
|
|
|
|
|
fn process_bounds(&mut self, bounds: &'l ast::GenericBounds) {
|
|
|
|
for bound in bounds {
|
|
|
|
if let ast::GenericBound::Trait(ref trait_ref, _) = *bound {
|
|
|
|
self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 23:52:09 +00:00
|
|
|
impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, O> {
|
2017-05-11 19:15:29 +00:00
|
|
|
fn visit_mod(&mut self, m: &'l ast::Mod, span: Span, attrs: &[ast::Attribute], id: NodeId) {
|
2017-05-11 05:45:27 +00:00
|
|
|
// Since we handle explicit modules ourselves in visit_item, this should
|
|
|
|
// only get called for the root module of a crate.
|
|
|
|
assert_eq!(id, ast::CRATE_NODE_ID);
|
|
|
|
|
|
|
|
let qualname = format!("::{}", self.tcx.node_path_str(id));
|
|
|
|
|
2018-08-18 10:14:09 +00:00
|
|
|
let cm = self.tcx.sess.source_map();
|
2017-05-11 05:45:27 +00:00
|
|
|
let filename = cm.span_to_filename(span);
|
2017-06-08 02:45:15 +00:00
|
|
|
let data_id = ::id_from_node_id(id, &self.save_ctxt);
|
2017-11-07 21:43:05 +00:00
|
|
|
let children = m.items
|
|
|
|
.iter()
|
|
|
|
.map(|i| ::id_from_node_id(i.id, &self.save_ctxt))
|
|
|
|
.collect();
|
2017-06-08 02:45:15 +00:00
|
|
|
let span = self.span_from_span(span);
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
self.dumper.dump_def(
|
2017-11-14 22:17:09 +00:00
|
|
|
&Access {
|
|
|
|
public: true,
|
|
|
|
reachable: true,
|
|
|
|
},
|
2017-11-07 21:43:05 +00:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Mod,
|
|
|
|
id: data_id,
|
|
|
|
name: String::new(),
|
|
|
|
qualname,
|
|
|
|
span,
|
2017-12-14 07:09:19 +00:00
|
|
|
value: filename.to_string(),
|
2017-11-07 21:43:05 +00:00
|
|
|
children,
|
|
|
|
parent: None,
|
|
|
|
decl_id: None,
|
|
|
|
docs: self.save_ctxt.docs_for_attrs(attrs),
|
|
|
|
sig: None,
|
|
|
|
attributes: lower_attributes(attrs.to_owned(), &self.save_ctxt),
|
|
|
|
},
|
|
|
|
);
|
2017-05-11 05:45:27 +00:00
|
|
|
self.nest_scope(id, |v| visit::walk_mod(v, m));
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn visit_item(&mut self, item: &'l ast::Item) {
|
2016-02-09 10:36:51 +00:00
|
|
|
use syntax::ast::ItemKind::*;
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_macro_use(item.span);
|
2015-05-04 10:33:07 +00:00
|
|
|
match item.node {
|
2017-09-26 21:04:00 +00:00
|
|
|
Use(ref use_tree) => {
|
|
|
|
let prefix = ast::Path {
|
|
|
|
segments: vec![],
|
|
|
|
span: DUMMY_SP,
|
|
|
|
};
|
|
|
|
self.process_use_tree(use_tree, item.id, item, &prefix);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
2017-06-08 02:45:15 +00:00
|
|
|
ExternCrate(_) => {
|
2015-05-04 10:33:07 +00:00
|
|
|
let alias_span = self.span.span_for_last_ident(item.span);
|
2016-02-29 10:51:05 +00:00
|
|
|
|
|
|
|
if !self.span.filter_generated(alias_span, item.span) {
|
2017-06-08 02:45:15 +00:00
|
|
|
let span =
|
|
|
|
self.span_from_span(alias_span.expect("No span found for extern crate"));
|
2017-12-15 02:23:20 +00:00
|
|
|
let parent = self.save_ctxt.tcx.hir.opt_local_def_id(item.id)
|
|
|
|
.and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
|
|
|
|
.map(::id_from_def_id);
|
2017-11-07 21:43:05 +00:00
|
|
|
self.dumper.import(
|
2017-11-14 22:17:09 +00:00
|
|
|
&Access {
|
|
|
|
public: false,
|
|
|
|
reachable: false,
|
|
|
|
},
|
2017-11-07 21:43:05 +00:00
|
|
|
Import {
|
|
|
|
kind: ImportKind::ExternCrate,
|
|
|
|
ref_id: None,
|
|
|
|
span,
|
2018-05-15 08:34:17 +00:00
|
|
|
alias_span: None,
|
2017-11-07 21:43:05 +00:00
|
|
|
name: item.ident.to_string(),
|
|
|
|
value: String::new(),
|
2017-12-15 02:23:20 +00:00
|
|
|
parent,
|
2017-11-07 21:43:05 +00:00
|
|
|
},
|
|
|
|
);
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
2017-11-07 21:43:05 +00:00
|
|
|
Fn(ref decl, .., ref ty_params, ref body) => {
|
|
|
|
self.process_fn(item, &decl, ty_params, &body)
|
|
|
|
}
|
|
|
|
Static(ref typ, _, ref expr) => self.process_static_or_const_item(item, typ, expr),
|
|
|
|
Const(ref typ, ref expr) => self.process_static_or_const_item(item, &typ, &expr),
|
2017-10-31 05:24:48 +00:00
|
|
|
Struct(ref def, ref ty_params) | Union(ref def, ref ty_params) => {
|
|
|
|
self.process_struct(item, def, ty_params)
|
|
|
|
}
|
2016-02-09 10:36:51 +00:00
|
|
|
Enum(ref def, ref ty_params) => self.process_enum(item, def, ty_params),
|
2017-11-07 21:43:05 +00:00
|
|
|
Impl(.., ref ty_params, ref trait_ref, ref typ, ref impl_items) => {
|
2015-09-27 20:20:49 +00:00
|
|
|
self.process_impl(item, ty_params, trait_ref, &typ, impl_items)
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
2017-11-07 21:43:05 +00:00
|
|
|
Trait(_, _, ref generics, ref trait_refs, ref methods) => {
|
|
|
|
self.process_trait(item, generics, trait_refs, methods)
|
|
|
|
}
|
2016-02-09 10:36:51 +00:00
|
|
|
Mod(ref m) => {
|
2015-05-25 22:35:53 +00:00
|
|
|
self.process_mod(item);
|
2017-01-06 19:54:24 +00:00
|
|
|
self.nest_scope(item.id, |v| visit::walk_mod(v, m));
|
2015-05-25 22:35:53 +00:00
|
|
|
}
|
2016-02-09 10:36:51 +00:00
|
|
|
Ty(ref ty, ref ty_params) => {
|
2016-04-06 10:51:55 +00:00
|
|
|
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
2016-02-09 20:24:11 +00:00
|
|
|
let value = ty_to_string(&ty);
|
2015-05-04 10:33:07 +00:00
|
|
|
let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Type);
|
2016-02-29 10:51:05 +00:00
|
|
|
if !self.span.filter_generated(sub_span, item.span) {
|
2017-06-08 02:45:15 +00:00
|
|
|
let span = self.span_from_span(sub_span.expect("No span found for typedef"));
|
|
|
|
let id = ::id_from_node_id(item.id, &self.save_ctxt);
|
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
self.dumper.dump_def(
|
2017-11-16 20:59:27 +00:00
|
|
|
&access_from!(self.save_ctxt, item),
|
2017-11-07 21:43:05 +00:00
|
|
|
Def {
|
|
|
|
kind: DefKind::Type,
|
|
|
|
id,
|
|
|
|
span,
|
|
|
|
name: item.ident.to_string(),
|
|
|
|
qualname: qualname.clone(),
|
|
|
|
value,
|
|
|
|
parent: None,
|
|
|
|
children: vec![],
|
|
|
|
decl_id: None,
|
|
|
|
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
|
|
|
sig: sig::item_signature(item, &self.save_ctxt),
|
|
|
|
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
|
|
|
|
},
|
|
|
|
);
|
2016-02-29 10:51:05 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
|
2016-02-09 20:24:11 +00:00
|
|
|
self.visit_ty(&ty);
|
2015-05-04 10:33:07 +00:00
|
|
|
self.process_generic_params(ty_params, item.span, &qualname, item.id);
|
2015-09-02 03:37:07 +00:00
|
|
|
}
|
2018-07-03 17:38:14 +00:00
|
|
|
Existential(ref _bounds, ref ty_params) => {
|
|
|
|
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
|
|
|
|
// FIXME do something with _bounds
|
|
|
|
let value = String::new();
|
|
|
|
let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Type);
|
|
|
|
if !self.span.filter_generated(sub_span, item.span) {
|
|
|
|
let span = self.span_from_span(sub_span.expect("No span found for typedef"));
|
|
|
|
let id = ::id_from_node_id(item.id, &self.save_ctxt);
|
|
|
|
|
|
|
|
self.dumper.dump_def(
|
|
|
|
&access_from!(self.save_ctxt, item),
|
|
|
|
Def {
|
|
|
|
kind: DefKind::Type,
|
|
|
|
id,
|
|
|
|
span,
|
|
|
|
name: item.ident.to_string(),
|
|
|
|
qualname: qualname.clone(),
|
|
|
|
value,
|
|
|
|
parent: None,
|
|
|
|
children: vec![],
|
|
|
|
decl_id: None,
|
|
|
|
docs: self.save_ctxt.docs_for_attrs(&item.attrs),
|
|
|
|
sig: sig::item_signature(item, &self.save_ctxt),
|
|
|
|
attributes: lower_attributes(item.attrs.clone(), &self.save_ctxt),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.process_generic_params(ty_params, item.span, &qualname, item.id);
|
|
|
|
}
|
2016-02-09 10:36:51 +00:00
|
|
|
Mac(_) => (),
|
2015-05-04 10:33:07 +00:00
|
|
|
_ => visit::walk_item(self, item),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn visit_generics(&mut self, generics: &'l ast::Generics) {
|
2018-06-22 23:33:03 +00:00
|
|
|
for param in &generics.params {
|
2018-08-30 22:10:57 +00:00
|
|
|
if let ast::GenericParamKind::Type { ref default, .. } = param.kind {
|
|
|
|
self.process_bounds(¶m.bounds);
|
|
|
|
if let Some(ref ty) = default {
|
|
|
|
self.visit_ty(&ty);
|
2018-05-27 15:56:01 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
2018-06-22 23:33:03 +00:00
|
|
|
}
|
2018-08-30 22:10:57 +00:00
|
|
|
for pred in &generics.where_clause.predicates {
|
|
|
|
if let ast::WherePredicate::BoundPredicate(ref wbp) = *pred {
|
|
|
|
self.process_bounds(&wbp.bounds);
|
|
|
|
self.visit_ty(&wbp.bounded_ty);
|
|
|
|
}
|
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn visit_ty(&mut self, t: &'l ast::Ty) {
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_macro_use(t.span);
|
2015-05-04 10:33:07 +00:00
|
|
|
match t.node {
|
2016-02-08 15:53:21 +00:00
|
|
|
ast::TyKind::Path(_, ref path) => {
|
2017-01-09 02:07:07 +00:00
|
|
|
if generated_code(t.span) {
|
2016-12-06 23:27:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-14 21:51:46 +00:00
|
|
|
if let Some(id) = self.lookup_def_id(t.id) {
|
2017-01-09 02:07:07 +00:00
|
|
|
if let Some(sub_span) = self.span.sub_span_for_type_name(t.span) {
|
2017-06-08 02:45:15 +00:00
|
|
|
let span = self.span_from_span(sub_span);
|
|
|
|
self.dumper.dump_ref(Ref {
|
|
|
|
kind: RefKind::Type,
|
|
|
|
span,
|
|
|
|
ref_id: ::id_from_def_id(id),
|
|
|
|
});
|
2017-01-09 02:07:07 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 03:51:11 +00:00
|
|
|
self.write_sub_paths_truncated(path);
|
2017-01-25 04:00:19 +00:00
|
|
|
visit::walk_path(self, path);
|
2015-09-02 03:37:07 +00:00
|
|
|
}
|
2017-01-06 19:54:24 +00:00
|
|
|
ast::TyKind::Array(ref element, ref length) => {
|
|
|
|
self.visit_ty(element);
|
2018-05-17 18:28:50 +00:00
|
|
|
self.nest_tables(length.id, |v| v.visit_expr(&length.value));
|
2017-01-06 19:54:24 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
_ => visit::walk_ty(self, t),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn visit_expr(&mut self, ex: &'l ast::Expr) {
|
2017-01-25 03:46:34 +00:00
|
|
|
debug!("visit_expr {:?}", ex.node);
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_macro_use(ex.span);
|
2015-05-04 10:33:07 +00:00
|
|
|
match ex.node {
|
2016-02-08 15:05:05 +00:00
|
|
|
ast::ExprKind::Struct(ref path, ref fields, ref base) => {
|
2017-01-26 00:41:06 +00:00
|
|
|
let hir_expr = self.save_ctxt.tcx.hir.expect_expr(ex.id);
|
2017-01-06 19:54:24 +00:00
|
|
|
let adt = match self.save_ctxt.tables.expr_ty_opt(&hir_expr) {
|
2017-07-24 01:54:38 +00:00
|
|
|
Some(ty) if ty.ty_adt_def().is_some() => ty.ty_adt_def().unwrap(),
|
|
|
|
_ => {
|
2016-11-23 05:47:07 +00:00
|
|
|
visit::walk_expr(self, ex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2016-11-25 11:21:19 +00:00
|
|
|
let def = self.save_ctxt.get_path_def(hir_expr.id);
|
2015-09-27 20:20:49 +00:00
|
|
|
self.process_struct_lit(ex, path, fields, adt.variant_of_def(def), base)
|
2015-08-02 19:52:50 +00:00
|
|
|
}
|
2017-11-01 20:22:44 +00:00
|
|
|
ast::ExprKind::MethodCall(ref seg, ref args) => self.process_method_call(ex, seg, args),
|
2016-02-08 15:05:05 +00:00
|
|
|
ast::ExprKind::Field(ref sub_ex, _) => {
|
2015-05-25 22:35:53 +00:00
|
|
|
self.visit_expr(&sub_ex);
|
|
|
|
|
2015-06-14 22:06:01 +00:00
|
|
|
if let Some(field_data) = self.save_ctxt.get_expr_data(ex) {
|
2017-06-08 02:45:15 +00:00
|
|
|
down_cast_data!(field_data, RefData, ex.span);
|
|
|
|
if !generated_code(ex.span) {
|
|
|
|
self.dumper.dump_ref(field_data);
|
2018-03-06 13:23:06 +00:00
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
2015-09-02 03:37:07 +00:00
|
|
|
}
|
2018-06-06 22:50:59 +00:00
|
|
|
ast::ExprKind::Closure(_, _, _, ref decl, ref body, _fn_decl_span) => {
|
2018-09-03 12:31:57 +00:00
|
|
|
let id = format!("${}", ex.id);
|
2015-05-04 10:33:07 +00:00
|
|
|
|
|
|
|
// walk arg and return types
|
|
|
|
for arg in &decl.inputs {
|
2016-02-09 20:24:11 +00:00
|
|
|
self.visit_ty(&arg.ty);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 14:04:11 +00:00
|
|
|
if let ast::FunctionRetTy::Ty(ref ret_ty) = decl.output {
|
2016-02-09 20:24:11 +00:00
|
|
|
self.visit_ty(&ret_ty);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// walk the body
|
2017-01-06 19:54:24 +00:00
|
|
|
self.nest_tables(ex.id, |v| {
|
|
|
|
v.process_formals(&decl.inputs, &id);
|
|
|
|
v.nest_scope(ex.id, |v| v.visit_expr(body))
|
|
|
|
});
|
2015-09-02 03:37:07 +00:00
|
|
|
}
|
2018-02-24 00:12:35 +00:00
|
|
|
ast::ExprKind::ForLoop(ref pattern, ref subexpression, ref block, _) => {
|
2016-05-11 20:46:39 +00:00
|
|
|
let value = self.span.snippet(subexpression.span);
|
2015-09-28 03:24:08 +00:00
|
|
|
self.process_var_decl(pattern, value);
|
2017-01-25 03:46:34 +00:00
|
|
|
debug!("for loop, walk sub-expr: {:?}", subexpression.node);
|
2017-11-02 01:35:39 +00:00
|
|
|
self.visit_expr(subexpression);
|
2015-09-28 03:24:08 +00:00
|
|
|
visit::walk_block(self, block);
|
|
|
|
}
|
2018-02-24 00:12:35 +00:00
|
|
|
ast::ExprKind::WhileLet(ref pats, ref subexpression, ref block, _) => {
|
|
|
|
self.process_var_decl_multi(pats);
|
|
|
|
debug!("for loop, walk sub-expr: {:?}", subexpression.node);
|
|
|
|
self.visit_expr(subexpression);
|
|
|
|
visit::walk_block(self, block);
|
|
|
|
}
|
|
|
|
ast::ExprKind::IfLet(ref pats, ref subexpression, ref block, ref opt_else) => {
|
|
|
|
self.process_var_decl_multi(pats);
|
2017-11-02 01:35:39 +00:00
|
|
|
self.visit_expr(subexpression);
|
2015-09-30 01:56:19 +00:00
|
|
|
visit::walk_block(self, block);
|
2017-11-02 01:35:39 +00:00
|
|
|
opt_else.as_ref().map(|el| self.visit_expr(el));
|
2015-09-30 01:56:19 +00:00
|
|
|
}
|
2017-01-06 19:54:24 +00:00
|
|
|
ast::ExprKind::Repeat(ref element, ref count) => {
|
|
|
|
self.visit_expr(element);
|
2018-05-17 18:28:50 +00:00
|
|
|
self.nest_tables(count.id, |v| v.visit_expr(&count.value));
|
2017-01-06 19:54:24 +00:00
|
|
|
}
|
2017-03-08 03:30:31 +00:00
|
|
|
// In particular, we take this branch for call and path expressions,
|
|
|
|
// where we'll index the idents involved just by continuing to walk.
|
2017-11-07 21:43:05 +00:00
|
|
|
_ => visit::walk_expr(self, ex),
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn visit_mac(&mut self, mac: &'l ast::Mac) {
|
2016-01-29 07:22:55 +00:00
|
|
|
// These shouldn't exist in the AST at this point, log a span bug.
|
2017-11-07 21:43:05 +00:00
|
|
|
span_bug!(
|
|
|
|
mac.span,
|
|
|
|
"macro invocation should have been expanded out of AST"
|
|
|
|
);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn visit_pat(&mut self, p: &'l ast::Pat) {
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_macro_use(p.span);
|
2015-05-04 10:33:07 +00:00
|
|
|
self.process_pat(p);
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn visit_arm(&mut self, arm: &'l ast::Arm) {
|
2018-02-24 00:12:35 +00:00
|
|
|
self.process_var_decl_multi(&arm.pats);
|
2018-08-30 04:18:11 +00:00
|
|
|
match arm.guard {
|
|
|
|
Some(ast::Guard::If(ref expr)) => self.visit_expr(expr),
|
|
|
|
_ => {}
|
|
|
|
}
|
2015-07-08 02:30:18 +00:00
|
|
|
self.visit_expr(&arm.body);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
|
|
|
|
2017-01-25 03:46:34 +00:00
|
|
|
fn visit_path(&mut self, p: &'l ast::Path, id: NodeId) {
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_path(id, p);
|
2017-01-25 03:46:34 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn visit_stmt(&mut self, s: &'l ast::Stmt) {
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_macro_use(s.span);
|
2015-05-04 10:33:07 +00:00
|
|
|
visit::walk_stmt(self, s)
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
fn visit_local(&mut self, l: &'l ast::Local) {
|
2017-06-08 02:45:15 +00:00
|
|
|
self.process_macro_use(l.span);
|
2017-11-07 21:43:05 +00:00
|
|
|
let value = l.init
|
|
|
|
.as_ref()
|
|
|
|
.map(|i| self.span.snippet(i.span))
|
2018-10-12 14:16:00 +00:00
|
|
|
.unwrap_or_default();
|
2015-09-28 03:24:08 +00:00
|
|
|
self.process_var_decl(&l.pat, value);
|
2015-05-04 10:33:07 +00:00
|
|
|
|
|
|
|
// Just walk the initialiser and type (don't want to walk the pattern again).
|
2015-09-28 11:26:26 +00:00
|
|
|
walk_list!(self, visit_ty, &l.ty);
|
|
|
|
walk_list!(self, visit_expr, &l.init);
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|
2017-03-08 05:04:30 +00:00
|
|
|
|
|
|
|
fn visit_foreign_item(&mut self, item: &'l ast::ForeignItem) {
|
2017-11-16 20:59:27 +00:00
|
|
|
let access = access_from!(self.save_ctxt, item);
|
2017-11-14 22:17:09 +00:00
|
|
|
|
2017-03-08 05:04:30 +00:00
|
|
|
match item.node {
|
|
|
|
ast::ForeignItemKind::Fn(ref decl, ref generics) => {
|
|
|
|
if let Some(fn_data) = self.save_ctxt.get_extern_item_data(item) {
|
2017-06-08 02:45:15 +00:00
|
|
|
down_cast_data!(fn_data, DefData, item.span);
|
2017-03-08 05:04:30 +00:00
|
|
|
|
2017-11-07 21:43:05 +00:00
|
|
|
self.nest_tables(
|
|
|
|
item.id,
|
|
|
|
|v| v.process_formals(&decl.inputs, &fn_data.qualname),
|
|
|
|
);
|
2017-03-08 05:04:30 +00:00
|
|
|
self.process_generic_params(generics, item.span, &fn_data.qualname, item.id);
|
2017-11-14 22:17:09 +00:00
|
|
|
self.dumper.dump_def(&access, fn_data);
|
2017-03-08 05:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for arg in &decl.inputs {
|
|
|
|
self.visit_ty(&arg.ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let ast::FunctionRetTy::Ty(ref ret_ty) = decl.output {
|
|
|
|
self.visit_ty(&ret_ty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast::ForeignItemKind::Static(ref ty, _) => {
|
|
|
|
if let Some(var_data) = self.save_ctxt.get_extern_item_data(item) {
|
2017-06-08 02:45:15 +00:00
|
|
|
down_cast_data!(var_data, DefData, item.span);
|
2017-11-14 22:17:09 +00:00
|
|
|
self.dumper.dump_def(&access, var_data);
|
2017-03-08 05:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.visit_ty(ty);
|
|
|
|
}
|
2017-09-03 18:53:58 +00:00
|
|
|
ast::ForeignItemKind::Ty => {
|
|
|
|
if let Some(var_data) = self.save_ctxt.get_extern_item_data(item) {
|
|
|
|
down_cast_data!(var_data, DefData, item.span);
|
2017-11-14 22:17:09 +00:00
|
|
|
self.dumper.dump_def(&access, var_data);
|
2017-09-03 18:53:58 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-11 02:16:26 +00:00
|
|
|
ast::ForeignItemKind::Macro(..) => {}
|
2017-03-08 05:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-04 10:33:07 +00:00
|
|
|
}
|