Skip to content

Commit

Permalink
save-analysis: add docs data
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Sep 6, 2016
1 parent 987b475 commit 68d29cb
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 13 deletions.
11 changes: 11 additions & 0 deletions src/librustc_save_analysis/data.rs
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
33 changes: 26 additions & 7 deletions src/librustc_save_analysis/dump_visitor.rs
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 @@ -1429,6 +1447,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
scope: 0,
parent: None,
visibility: Visibility::Inherited,
docs: String::new(),
}.lower(self.tcx));
}
}
Expand Down

0 comments on commit 68d29cb

Please sign in to comment.