Skip to content

save-analysis bits and pieces #36324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/librustc_save_analysis/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub struct EnumData {
pub scope: NodeId,
pub variants: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
}

/// Data for extern crates.
Expand Down Expand Up @@ -167,6 +168,7 @@ pub struct FunctionData {
pub value: String,
pub visibility: Visibility,
pub parent: Option<NodeId>,
pub docs: String,
}

/// Data about a function call.
Expand Down Expand Up @@ -213,6 +215,7 @@ pub struct MacroData {
pub span: Span,
pub name: String,
pub qualname: String,
pub docs: String,
}

/// Data about a macro use.
Expand Down Expand Up @@ -248,6 +251,7 @@ pub struct MethodData {
pub value: String,
pub decl_id: Option<DefId>,
pub visibility: Visibility,
pub docs: String,
}

/// Data for modules.
Expand All @@ -261,6 +265,7 @@ pub struct ModData {
pub filename: String,
pub items: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
}

/// Data for a reference to a module.
Expand All @@ -283,6 +288,7 @@ pub struct StructData {
pub value: String,
pub fields: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
}

#[derive(Debug, RustcEncodable)]
Expand All @@ -295,6 +301,7 @@ pub struct StructVariantData {
pub value: String,
pub scope: NodeId,
pub parent: Option<NodeId>,
pub docs: String,
}

#[derive(Debug, RustcEncodable)]
Expand All @@ -307,6 +314,7 @@ pub struct TraitData {
pub value: String,
pub items: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
}

#[derive(Debug, RustcEncodable)]
Expand All @@ -319,6 +327,7 @@ pub struct TupleVariantData {
pub value: String,
pub scope: NodeId,
pub parent: Option<NodeId>,
pub docs: String,
}

/// Data for a typedef.
Expand All @@ -331,6 +340,7 @@ pub struct TypeDefData {
pub value: String,
pub visibility: Visibility,
pub parent: Option<NodeId>,
pub docs: String,
}

/// Data for a reference to a type or trait.
Expand Down Expand Up @@ -374,6 +384,7 @@ pub struct VariableData {
pub value: String,
pub type_value: String,
pub visibility: Visibility,
pub docs: String,
}

#[derive(Debug, RustcEncodable)]
Expand Down
41 changes: 32 additions & 9 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ use rustc::ty::{self, TyCtxt, ImplOrTraitItem, ImplOrTraitItemContainer};
use std::collections::HashSet;
use std::hash::*;

use syntax::ast::{self, NodeId, PatKind};
use syntax::ast::{self, NodeId, PatKind, Attribute};
use syntax::parse::token::{self, keywords};
use syntax::visit::{self, Visitor};
use syntax::print::pprust::{path_to_string, ty_to_string, bounds_to_string, generics_to_string};
use syntax::ptr::P;
use syntax::codemap::Spanned;
use syntax_pos::*;

use super::{escape, generated_code, SaveContext, PathCollector};
use super::{escape, generated_code, SaveContext, PathCollector, docs_for_attrs};
use super::data::*;
use super::dump::Dump;
use super::external_data::Lower;
Expand Down Expand Up @@ -368,6 +368,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
scope: 0,
parent: None,
visibility: Visibility::Inherited,
docs: String::new(),
}.lower(self.tcx));
}
}
Expand All @@ -380,6 +381,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
id: ast::NodeId,
name: ast::Name,
vis: Visibility,
attrs: &[Attribute],
span: Span) {
debug!("process_method: {}:{}", id, name);

Expand Down Expand Up @@ -421,6 +423,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
value: sig_str,
decl_id: decl_id,
visibility: vis,
docs: docs_for_attrs(attrs),
}.lower(self.tcx));
}

Expand Down Expand Up @@ -491,6 +494,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
value: String::new(),
visibility: Visibility::Inherited,
parent: None,
docs: String::new(),
}.lower(self.tcx));
}
}
Expand Down Expand Up @@ -541,7 +545,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
typ: &ast::Ty,
expr: &ast::Expr,
parent_id: NodeId,
vis: Visibility) {
vis: Visibility,
attrs: &[Attribute]) {
let qualname = format!("::{}", self.tcx.node_path_str(id));

let sub_span = self.span.sub_span_after_keyword(span, keywords::Const);
Expand All @@ -558,6 +563,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
scope: self.cur_scope,
parent: Some(parent_id),
visibility: vis,
docs: docs_for_attrs(attrs),
}.lower(self.tcx));
}

Expand Down Expand Up @@ -600,6 +606,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
value: val,
fields: fields,
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
}.lower(self.tcx));
}

Expand Down Expand Up @@ -653,6 +660,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
value: val,
scope: enum_data.scope,
parent: Some(item.id),
docs: docs_for_attrs(&variant.node.attrs),
}.lower(self.tcx));
}
}
Expand All @@ -677,6 +685,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
value: val,
scope: enum_data.scope,
parent: Some(item.id),
docs: docs_for_attrs(&variant.node.attrs),
}.lower(self.tcx));
}
}
Expand Down Expand Up @@ -759,6 +768,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
value: val,
items: methods.iter().map(|i| i.id).collect(),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
}.lower(self.tcx));
}

Expand Down Expand Up @@ -1007,6 +1017,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
scope: 0,
parent: None,
visibility: Visibility::Inherited,
docs: String::new(),
}.lower(self.tcx));
}
}
Expand Down Expand Up @@ -1036,7 +1047,9 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
self.dumper.macro_data(MacroData {
span: sub_span,
name: data.name.clone(),
qualname: qualname.clone()
qualname: qualname.clone(),
// FIXME where do macro docs come from?
docs: String::new(),
}.lower(self.tcx));
}
}
Expand All @@ -1049,7 +1062,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
qualname: qualname,
scope: data.scope,
callee_span: data.callee_span,
imported: data.imported
imported: data.imported,
}.lower(self.tcx));
}
}
Expand All @@ -1065,14 +1078,16 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
&ty,
&expr,
trait_id,
Visibility::Public);
Visibility::Public,
&trait_item.attrs);
}
ast::TraitItemKind::Method(ref sig, ref body) => {
self.process_method(sig,
body.as_ref().map(|x| &**x),
trait_item.id,
trait_item.ident.name,
Visibility::Public,
&trait_item.attrs,
trait_item.span);
}
ast::TraitItemKind::Const(_, None) |
Expand All @@ -1091,14 +1106,16 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
&ty,
&expr,
impl_id,
From::from(&impl_item.vis));
From::from(&impl_item.vis),
&impl_item.attrs);
}
ast::ImplItemKind::Method(ref sig, ref body) => {
self.process_method(sig,
Some(body),
impl_item.id,
impl_item.ident.name,
From::from(&impl_item.vis),
&impl_item.attrs,
impl_item.span);
}
ast::ImplItemKind::Type(_) |
Expand Down Expand Up @@ -1240,6 +1257,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
value: value,
visibility: From::from(&item.vis),
parent: None,
docs: docs_for_attrs(&item.attrs),
}.lower(self.tcx));
}

Expand Down Expand Up @@ -1409,11 +1427,15 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
for &(id, ref p, immut, ref_kind) in &collector.collected_paths {
match self.tcx.expect_def(id) {
Def::Local(_, id) => {
let value = if immut == ast::Mutability::Immutable {
let mut value = if immut == ast::Mutability::Immutable {
self.span.snippet(p.span).to_string()
} else {
"<mutable>".to_string()
};
let typ = self.tcx.node_types()
.get(&id).map(|t| t.to_string()).unwrap_or(String::new());
value.push_str(": ");
value.push_str(&typ);

assert!(p.segments.len() == 1,
"qualified path for local variable def in arm");
Expand All @@ -1425,10 +1447,11 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
name: path_to_string(p),
qualname: format!("{}${}", path_to_string(p), id),
value: value,
type_value: String::new(),
type_value: typ,
scope: 0,
parent: None,
visibility: Visibility::Inherited,
docs: String::new(),
}.lower(self.tcx));
}
}
Expand Down
Loading