pub scope: NodeId,
pub variants: Vec<NodeId>,
pub visibility: Visibility,
+ pub docs: String,
}
/// Data for extern crates.
pub value: String,
pub visibility: Visibility,
pub parent: Option<NodeId>,
+ pub docs: String,
}
/// Data about a function call.
pub span: Span,
pub name: String,
pub qualname: String,
+ pub docs: String,
}
/// Data about a macro use.
pub value: String,
pub decl_id: Option<DefId>,
pub visibility: Visibility,
+ pub docs: String,
}
/// Data for modules.
pub filename: String,
pub items: Vec<NodeId>,
pub visibility: Visibility,
+ pub docs: String,
}
/// Data for a reference to a module.
pub value: String,
pub fields: Vec<NodeId>,
pub visibility: Visibility,
+ pub docs: String,
}
#[derive(Debug, RustcEncodable)]
pub value: String,
pub scope: NodeId,
pub parent: Option<NodeId>,
+ pub docs: String,
}
#[derive(Debug, RustcEncodable)]
pub value: String,
pub items: Vec<NodeId>,
pub visibility: Visibility,
+ pub docs: String,
}
#[derive(Debug, RustcEncodable)]
pub value: String,
pub scope: NodeId,
pub parent: Option<NodeId>,
+ pub docs: String,
}
/// Data for a typedef.
pub value: String,
pub visibility: Visibility,
pub parent: Option<NodeId>,
+ pub docs: String,
}
/// Data for a reference to a type or trait.
pub value: String,
pub type_value: String,
pub visibility: Visibility,
+ pub docs: String,
}
#[derive(Debug, RustcEncodable)]
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::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;
scope: 0,
parent: None,
visibility: Visibility::Inherited,
+ docs: String::new(),
}.lower(self.tcx));
}
}
id: ast::NodeId,
name: ast::Name,
vis: Visibility,
+ attrs: &[Attribute],
span: Span) {
debug!("process_method: {}:{}", id, name);
value: sig_str,
decl_id: decl_id,
visibility: vis,
+ docs: docs_for_attrs(attrs),
}.lower(self.tcx));
}
value: String::new(),
visibility: Visibility::Inherited,
parent: None,
+ docs: String::new(),
}.lower(self.tcx));
}
}
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);
scope: self.cur_scope,
parent: Some(parent_id),
visibility: vis,
+ docs: docs_for_attrs(attrs),
}.lower(self.tcx));
}
value: val,
fields: fields,
visibility: From::from(&item.vis),
+ docs: docs_for_attrs(&item.attrs),
}.lower(self.tcx));
}
value: val,
scope: enum_data.scope,
parent: Some(item.id),
+ docs: docs_for_attrs(&variant.node.attrs),
}.lower(self.tcx));
}
}
value: val,
scope: enum_data.scope,
parent: Some(item.id),
+ docs: docs_for_attrs(&variant.node.attrs),
}.lower(self.tcx));
}
}
value: val,
items: methods.iter().map(|i| i.id).collect(),
visibility: From::from(&item.vis),
+ docs: docs_for_attrs(&item.attrs),
}.lower(self.tcx));
}
scope: 0,
parent: None,
visibility: Visibility::Inherited,
+ docs: String::new(),
}.lower(self.tcx));
}
}
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));
}
}
qualname: qualname,
scope: data.scope,
callee_span: data.callee_span,
- imported: data.imported
+ imported: data.imported,
}.lower(self.tcx));
}
}
&ty,
&expr,
trait_id,
- Visibility::Public);
+ Visibility::Public,
+ &trait_item.attrs);
}
ast::TraitItemKind::Method(ref sig, ref body) => {
self.process_method(sig,
trait_item.id,
trait_item.ident.name,
Visibility::Public,
+ &trait_item.attrs,
trait_item.span);
}
ast::TraitItemKind::Const(_, None) |
&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,
impl_item.id,
impl_item.ident.name,
From::from(&impl_item.vis),
+ &impl_item.attrs,
impl_item.span);
}
ast::ImplItemKind::Type(_) |
value: value,
visibility: From::from(&item.vis),
parent: None,
+ docs: docs_for_attrs(&item.attrs),
}.lower(self.tcx));
}
scope: 0,
parent: None,
visibility: Visibility::Inherited,
+ docs: String::new(),
}.lower(self.tcx));
}
}
pub scope: DefId,
pub variants: Vec<DefId>,
pub visibility: Visibility,
+ pub docs: String,
}
impl Lower for data::EnumData {
scope: make_def_id(self.scope, &tcx.map),
variants: self.variants.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility,
+ docs: self.docs,
}
}
}
pub value: String,
pub visibility: Visibility,
pub parent: Option<DefId>,
+ pub docs: String,
}
impl Lower for data::FunctionData {
value: self.value,
visibility: self.visibility,
parent: self.parent.map(|id| make_def_id(id, &tcx.map)),
+ docs: self.docs,
}
}
}
pub span: SpanData,
pub name: String,
pub qualname: String,
+ pub docs: String,
}
impl Lower for data::MacroData {
span: SpanData::from_span(self.span, tcx.sess.codemap()),
name: self.name,
qualname: self.qualname,
+ docs: self.docs,
}
}
}
pub value: String,
pub decl_id: Option<DefId>,
pub visibility: Visibility,
- pub parent: Option<DefId>
+ pub parent: Option<DefId>,
+ pub docs: String,
}
impl Lower for data::MethodData {
decl_id: self.decl_id,
visibility: self.visibility,
parent: Some(make_def_id(self.scope, &tcx.map)),
+ docs: self.docs,
}
}
}
pub filename: String,
pub items: Vec<DefId>,
pub visibility: Visibility,
+ pub docs: String,
}
impl Lower for data::ModData {
filename: self.filename,
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility,
+ docs: self.docs,
}
}
}
pub value: String,
pub fields: Vec<DefId>,
pub visibility: Visibility,
+ pub docs: String,
}
impl Lower for data::StructData {
value: self.value,
fields: self.fields.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility,
+ docs: self.docs,
}
}
}
pub value: String,
pub scope: DefId,
pub parent: Option<DefId>,
+ pub docs: String,
}
impl Lower for data::StructVariantData {
value: self.value,
scope: make_def_id(self.scope, &tcx.map),
parent: self.parent.map(|id| make_def_id(id, &tcx.map)),
+ docs: self.docs,
}
}
}
pub value: String,
pub items: Vec<DefId>,
pub visibility: Visibility,
+ pub docs: String,
}
impl Lower for data::TraitData {
value: self.value,
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility,
+ docs: self.docs,
}
}
}
pub value: String,
pub scope: DefId,
pub parent: Option<DefId>,
+ pub docs: String,
}
impl Lower for data::TupleVariantData {
value: self.value,
scope: make_def_id(self.scope, &tcx.map),
parent: self.parent.map(|id| make_def_id(id, &tcx.map)),
+ docs: self.docs,
}
}
}
pub value: String,
pub visibility: Visibility,
pub parent: Option<DefId>,
+ pub docs: String,
}
impl Lower for data::TypeDefData {
value: self.value,
visibility: self.visibility,
parent: self.parent.map(|id| make_def_id(id, &tcx.map)),
+ docs: self.docs,
}
}
}
pub type_value: String,
pub parent: Option<DefId>,
pub visibility: Visibility,
+ pub docs: String,
}
impl Lower for data::VariableData {
type_value: self.type_value,
parent: self.parent.map(|id| make_def_id(id, &tcx.map)),
visibility: self.visibility,
+ docs: self.docs,
}
}
}
parent: Option<Id>,
children: Vec<Id>,
decl_id: Option<Id>,
+ docs: String,
}
#[derive(Debug, RustcEncodable)]
parent: None,
children: data.variants.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
+ docs: data.docs,
}),
_ => None,
}
parent: data.parent.map(|id| From::from(id)),
children: vec![],
decl_id: None,
+ docs: data.docs,
})
}
}
parent: data.parent.map(|id| From::from(id)),
children: vec![],
decl_id: None,
+ docs: data.docs,
})
}
}
parent: None,
children: data.fields.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
+ docs: data.docs,
}),
_ => None,
}
children: data.items.into_iter().map(|id| From::from(id)).collect(),
parent: None,
decl_id: None,
+ docs: data.docs,
}),
_ => None,
}
children: vec![],
parent: data.parent.map(|id| From::from(id)),
decl_id: None,
+ docs: data.docs,
}),
_ => None,
}
children: vec![],
parent: data.parent.map(|id| From::from(id)),
decl_id: data.decl_id.map(|id| From::from(id)),
+ docs: data.docs,
}),
_ => None,
}
children: vec![],
parent: None,
decl_id: None,
+ docs: data.docs,
})
}
}
children: data.items.into_iter().map(|id| From::from(id)).collect(),
parent: None,
decl_id: None,
+ docs: data.docs,
}),
_ => None,
}
children: vec![],
parent: data.parent.map(|id| From::from(id)),
decl_id: None,
+ docs: String::new(),
}),
_ => None,
}
children: vec![],
parent: data.parent.map(|id| From::from(id)),
decl_id: None,
+ docs: data.docs,
}),
_ => None,
}
value: String,
children: Vec<Id>,
decl_id: Option<Id>,
+ docs: String,
}
#[derive(Debug, RustcEncodable)]
value: data.value,
children: data.variants.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
+ docs: data.docs,
}
}
}
value: data.value,
children: vec![],
decl_id: None,
+ docs: data.docs,
}
}
}
value: data.value,
children: vec![],
decl_id: None,
+ docs: data.docs,
}
}
}
value: data.value,
children: data.fields.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
+ docs: data.docs,
}
}
}
value: data.value,
children: data.items.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
+ docs: data.docs,
}
}
}
value: data.value,
children: vec![],
decl_id: None,
+ docs: data.docs,
}
}
}
value: data.value,
children: vec![],
decl_id: data.decl_id.map(|id| From::from(id)),
+ docs: data.docs,
}
}
}
value: String::new(),
children: vec![],
decl_id: None,
+ docs: data.docs,
}
}
}
value: data.filename,
children: data.items.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
+ docs: data.docs,
}
}
}
value: data.value,
children: vec![],
decl_id: None,
+ docs: String::new(),
}
}
}
value: data.value,
children: vec![],
decl_id: None,
+ docs: data.docs,
}
}
}
extern crate serialize as rustc_serialize;
extern crate syntax_pos;
+
mod csv_dumper;
mod json_api_dumper;
mod json_dumper;
use std::fs::{self, File};
use std::path::{Path, PathBuf};
-use syntax::ast::{self, NodeId, PatKind};
-use syntax::parse::token::{self, keywords};
+use syntax::ast::{self, NodeId, PatKind, Attribute};
+use syntax::parse::token::{self, keywords, InternedString};
use syntax::visit::{self, Visitor};
use syntax::print::pprust::{ty_to_string, arg_to_string};
use syntax::codemap::MacroAttribute;
value: make_signature(decl, generics),
visibility: From::from(&item.vis),
parent: None,
+ docs: docs_for_attrs(&item.attrs),
}))
}
ast::ItemKind::Static(ref typ, mt, ref expr) => {
value: value,
type_value: ty_to_string(&typ),
visibility: From::from(&item.vis),
+ docs: docs_for_attrs(&item.attrs),
}))
}
ast::ItemKind::Const(ref typ, ref expr) => {
value: self.span_utils.snippet(expr.span),
type_value: ty_to_string(&typ),
visibility: From::from(&item.vis),
+ docs: docs_for_attrs(&item.attrs),
}))
}
ast::ItemKind::Mod(ref m) => {
filename: filename,
items: m.items.iter().map(|i| i.id).collect(),
visibility: From::from(&item.vis),
+ docs: docs_for_attrs(&item.attrs),
}))
}
ast::ItemKind::Enum(ref def, _) => {
scope: self.enclosing_scope(item.id),
variants: def.variants.iter().map(|v| v.node.data.id()).collect(),
visibility: From::from(&item.vis),
+ docs: docs_for_attrs(&item.attrs),
}))
}
ast::ItemKind::Impl(_, _, _, ref trait_ref, ref typ, _) => {
value: "".to_owned(),
type_value: typ,
visibility: From::from(&field.vis),
+ docs: docs_for_attrs(&field.attrs),
})
} else {
None
name: ast::Name, span: Span) -> Option<FunctionData> {
// The qualname for a method is the trait name or name of the struct in an impl in
// which the method is declared in, followed by the method's name.
- let (qualname, vis) = match self.tcx.impl_of_method(self.tcx.map.local_def_id(id)) {
+ let (qualname, vis, docs) = match self.tcx.impl_of_method(self.tcx.map.local_def_id(id)) {
Some(impl_id) => match self.tcx.map.get_if_local(impl_id) {
Some(NodeItem(item)) => {
match item.node {
result.push_str(&self.tcx.item_path_str(def_id));
}
result.push_str(">");
- (result, From::from(&item.vis))
+ (result, From::from(&item.vis), docs_for_attrs(&item.attrs))
}
_ => {
span_bug!(span,
Some(def_id) => {
match self.tcx.map.get_if_local(def_id) {
Some(NodeItem(item)) => {
- (format!("::{}", self.tcx.item_path_str(def_id)), From::from(&item.vis))
+ (format!("::{}", self.tcx.item_path_str(def_id)),
+ From::from(&item.vis),
+ docs_for_attrs(&item.attrs))
}
r => {
span_bug!(span,
value: String::new(),
visibility: vis,
parent: Some(parent_scope),
+ docs: docs,
})
}
}
}
+
+fn docs_for_attrs(attrs: &[Attribute]) -> String {
+ let doc = InternedString::new("doc");
+ let mut result = String::new();
+
+ for attr in attrs {
+ if attr.name() == doc {
+ if let Some(ref val) = attr.value_str() {
+ result.push_str(val);
+ result.push('\n');
+ }
+ }
+ }
+
+ result
+}
+
#[derive(Clone, Copy, Debug)]
pub enum Format {
Csv,