use rustc::metadata::csearch;
use rustc::metadata::decoder;
+use std::local_data;
+use std::strbuf::StrBuf;
use std;
use core;
use doctree;
use visit_ast;
-use std::local_data;
pub trait Clean<T> {
fn clean(&self) -> T;
#[deriving(Clone, Encodable, Decodable)]
pub struct Crate {
- name: ~str,
- module: Option<Item>,
- externs: Vec<(ast::CrateNum, ExternalCrate)> ,
+ pub name: ~str,
+ pub module: Option<Item>,
+ pub externs: Vec<(ast::CrateNum, ExternalCrate)>,
}
impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
#[deriving(Clone, Encodable, Decodable)]
pub struct ExternalCrate {
- name: ~str,
- attrs: Vec<Attribute> ,
+ pub name: ~str,
+ pub attrs: Vec<Attribute>,
}
impl Clean<ExternalCrate> for cstore::crate_metadata {
#[deriving(Clone, Encodable, Decodable)]
pub struct Item {
/// Stringified span
- source: Span,
+ pub source: Span,
/// Not everything has a name. E.g., impls
- name: Option<~str>,
- attrs: Vec<Attribute> ,
- inner: ItemEnum,
- visibility: Option<Visibility>,
- id: ast::NodeId,
+ pub name: Option<~str>,
+ pub attrs: Vec<Attribute> ,
+ pub inner: ItemEnum,
+ pub visibility: Option<Visibility>,
+ pub id: ast::NodeId,
}
impl Item {
StaticItem(Static),
TraitItem(Trait),
ImplItem(Impl),
+ /// `use` and `extern crate`
ViewItemItem(ViewItem),
+ /// A method signature only. Used for required methods in traits (ie,
+ /// non-default-methods).
TyMethodItem(TyMethod),
+ /// A method with a body.
MethodItem(Method),
StructFieldItem(StructField),
VariantItem(Variant),
+ /// `fn`s from an extern block
ForeignFunctionItem(Function),
+ /// `static`s from an extern block
ForeignStaticItem(Static),
MacroItem(Macro),
}
#[deriving(Clone, Encodable, Decodable)]
pub struct Module {
- items: Vec<Item> ,
- is_crate: bool,
+ pub items: Vec<Item>,
+ pub is_crate: bool,
}
impl Clean<Item> for doctree::Module {
let name = if self.name.is_some() {
self.name.unwrap().clean()
} else {
- ~""
+ "".to_owned()
};
let mut foreigns = Vec::new();
for subforeigns in self.foreigns.clean().move_iter() {
#[deriving(Clone, Encodable, Decodable)]
pub struct TyParam {
- name: ~str,
- id: ast::NodeId,
- bounds: Vec<TyParamBound> }
+ pub name: ~str,
+ pub id: ast::NodeId,
+ pub bounds: Vec<TyParamBound>,
+}
impl Clean<TyParam> for ast::TyParam {
fn clean(&self) -> TyParam {
// maybe use a Generic enum and use ~[Generic]?
#[deriving(Clone, Encodable, Decodable)]
pub struct Generics {
- lifetimes: Vec<Lifetime> ,
- type_params: Vec<TyParam> }
+ pub lifetimes: Vec<Lifetime>,
+ pub type_params: Vec<TyParam>,
+}
impl Clean<Generics> for ast::Generics {
fn clean(&self) -> Generics {
#[deriving(Clone, Encodable, Decodable)]
pub struct Method {
- generics: Generics,
- self_: SelfTy,
- purity: ast::Purity,
- decl: FnDecl,
+ pub generics: Generics,
+ pub self_: SelfTy,
+ pub fn_style: ast::FnStyle,
+ pub decl: FnDecl,
}
impl Clean<Item> for ast::Method {
inner: MethodItem(Method {
generics: self.generics.clean(),
self_: self.explicit_self.clean(),
- purity: self.purity.clone(),
+ fn_style: self.fn_style.clone(),
decl: decl,
}),
}
#[deriving(Clone, Encodable, Decodable)]
pub struct TyMethod {
- purity: ast::Purity,
- decl: FnDecl,
- generics: Generics,
- self_: SelfTy,
+ pub fn_style: ast::FnStyle,
+ pub decl: FnDecl,
+ pub generics: Generics,
+ pub self_: SelfTy,
}
impl Clean<Item> for ast::TypeMethod {
id: self.id,
visibility: None,
inner: TyMethodItem(TyMethod {
- purity: self.purity.clone(),
+ fn_style: self.fn_style.clone(),
decl: decl,
self_: self.explicit_self.clean(),
generics: self.generics.clean(),
#[deriving(Clone, Encodable, Decodable)]
pub struct Function {
- decl: FnDecl,
- generics: Generics,
- purity: ast::Purity,
+ pub decl: FnDecl,
+ pub generics: Generics,
+ pub fn_style: ast::FnStyle,
}
impl Clean<Item> for doctree::Function {
inner: FunctionItem(Function {
decl: self.decl.clean(),
generics: self.generics.clean(),
- purity: self.purity,
+ fn_style: self.fn_style,
}),
}
}
#[deriving(Clone, Encodable, Decodable)]
pub struct ClosureDecl {
- sigil: ast::Sigil,
- region: Option<Lifetime>,
- lifetimes: Vec<Lifetime> ,
- decl: FnDecl,
- onceness: ast::Onceness,
- purity: ast::Purity,
- bounds: Vec<TyParamBound> }
+ pub lifetimes: Vec<Lifetime>,
+ pub decl: FnDecl,
+ pub onceness: ast::Onceness,
+ pub fn_style: ast::FnStyle,
+ pub bounds: Vec<TyParamBound>,
+}
impl Clean<ClosureDecl> for ast::ClosureTy {
fn clean(&self) -> ClosureDecl {
ClosureDecl {
- sigil: self.sigil,
- region: self.region.clean(),
lifetimes: self.lifetimes.clean().move_iter().collect(),
decl: self.decl.clean(),
onceness: self.onceness,
- purity: self.purity,
+ fn_style: self.fn_style,
bounds: match self.bounds {
Some(ref x) => x.clean().move_iter().collect(),
None => Vec::new()
#[deriving(Clone, Encodable, Decodable)]
pub struct FnDecl {
- inputs: Arguments,
- output: Type,
- cf: RetStyle,
- attrs: Vec<Attribute> }
+ pub inputs: Arguments,
+ pub output: Type,
+ pub cf: RetStyle,
+ pub attrs: Vec<Attribute>,
+}
#[deriving(Clone, Encodable, Decodable)]
pub struct Arguments {
- values: Vec<Argument> ,
+ pub values: Vec<Argument>,
}
impl Clean<FnDecl> for ast::FnDecl {
#[deriving(Clone, Encodable, Decodable)]
pub struct Argument {
- type_: Type,
- name: ~str,
- id: ast::NodeId
+ pub type_: Type,
+ pub name: ~str,
+ pub id: ast::NodeId,
}
impl Clean<Argument> for ast::Arg {
#[deriving(Clone, Encodable, Decodable)]
pub struct Trait {
- methods: Vec<TraitMethod> ,
- generics: Generics,
- parents: Vec<Type> ,
+ pub methods: Vec<TraitMethod>,
+ pub generics: Generics,
+ pub parents: Vec<Type>,
}
impl Clean<Item> for doctree::Trait {
pub enum Type {
/// structs/enums/traits (anything that'd be an ast::TyPath)
ResolvedPath {
- path: Path,
- typarams: Option<Vec<TyParamBound> >,
- id: ast::NodeId,
+ pub path: Path,
+ pub typarams: Option<Vec<TyParamBound>>,
+ pub id: ast::NodeId,
},
/// Same as above, but only external variants
ExternalPath {
- path: Path,
- typarams: Option<Vec<TyParamBound> >,
- fqn: Vec<~str> ,
- kind: TypeKind,
- krate: ast::CrateNum,
+ pub path: Path,
+ pub typarams: Option<Vec<TyParamBound>>,
+ pub fqn: Vec<~str>,
+ pub kind: TypeKind,
+ pub krate: ast::CrateNum,
},
// I have no idea how to usefully use this.
TyParamBinder(ast::NodeId),
Self(ast::NodeId),
/// Primitives are just the fixed-size numeric types (plus int/uint/float), and char.
Primitive(ast::PrimTy),
- Closure(~ClosureDecl),
+ Closure(~ClosureDecl, Option<Lifetime>),
+ Proc(~ClosureDecl),
/// extern "ABI" fn
BareFunction(~BareFunctionDecl),
Tuple(Vec<Type> ),
Unique(~Type),
Managed(~Type),
RawPointer(Mutability, ~Type),
- BorrowedRef { lifetime: Option<Lifetime>, mutability: Mutability, type_: ~Type},
+ BorrowedRef {
+ pub lifetime: Option<Lifetime>,
+ pub mutability: Mutability,
+ pub type_: ~Type,
+ },
// region, raw, other boxes, mutable
}
tpbs.clean().map(|x| x.move_iter().collect()),
id)
}
- TyClosure(ref c) => Closure(~c.clean()),
+ TyClosure(ref c, region) => Closure(~c.clean(), region.clean()),
+ TyProc(ref c) => Proc(~c.clean()),
TyBareFn(ref barefn) => BareFunction(~barefn.clean()),
TyBot => Bottom,
ref x => fail!("Unimplemented type {:?}", x),
#[deriving(Clone, Encodable, Decodable)]
pub struct StructField {
- type_: Type,
+ pub type_: Type,
}
impl Clean<Item> for ast::StructField {
#[deriving(Clone, Encodable, Decodable)]
pub struct Struct {
- struct_type: doctree::StructType,
- generics: Generics,
- fields: Vec<Item> ,
- fields_stripped: bool,
+ pub struct_type: doctree::StructType,
+ pub generics: Generics,
+ pub fields: Vec<Item>,
+ pub fields_stripped: bool,
}
impl Clean<Item> for doctree::Struct {
/// only as a variant in an enum.
#[deriving(Clone, Encodable, Decodable)]
pub struct VariantStruct {
- struct_type: doctree::StructType,
- fields: Vec<Item> ,
- fields_stripped: bool,
+ pub struct_type: doctree::StructType,
+ pub fields: Vec<Item>,
+ pub fields_stripped: bool,
}
impl Clean<VariantStruct> for syntax::ast::StructDef {
#[deriving(Clone, Encodable, Decodable)]
pub struct Enum {
- variants: Vec<Item> ,
- generics: Generics,
- variants_stripped: bool,
+ pub variants: Vec<Item>,
+ pub generics: Generics,
+ pub variants_stripped: bool,
}
impl Clean<Item> for doctree::Enum {
#[deriving(Clone, Encodable, Decodable)]
pub struct Variant {
- kind: VariantKind,
+ pub kind: VariantKind,
}
impl Clean<Item> for doctree::Variant {
#[deriving(Clone, Encodable, Decodable)]
pub struct Span {
- filename: ~str,
- loline: uint,
- locol: uint,
- hiline: uint,
- hicol: uint,
+ pub filename: ~str,
+ pub loline: uint,
+ pub locol: uint,
+ pub hiline: uint,
+ pub hicol: uint,
}
impl Clean<Span> for syntax::codemap::Span {
#[deriving(Clone, Encodable, Decodable)]
pub struct Path {
- global: bool,
- segments: Vec<PathSegment> ,
+ pub global: bool,
+ pub segments: Vec<PathSegment>,
}
impl Clean<Path> for ast::Path {
#[deriving(Clone, Encodable, Decodable)]
pub struct PathSegment {
- name: ~str,
- lifetimes: Vec<Lifetime> ,
- types: Vec<Type> ,
+ pub name: ~str,
+ pub lifetimes: Vec<Lifetime>,
+ pub types: Vec<Type>,
}
impl Clean<PathSegment> for ast::PathSegment {
fn path_to_str(p: &ast::Path) -> ~str {
use syntax::parse::token;
- let mut s = ~"";
+ let mut s = StrBuf::new();
let mut first = true;
for i in p.segments.iter().map(|x| token::get_ident(x.identifier)) {
if !first || p.global {
}
s.push_str(i.get());
}
- s
+ s.into_owned()
}
impl Clean<~str> for ast::Ident {
#[deriving(Clone, Encodable, Decodable)]
pub struct Typedef {
- type_: Type,
- generics: Generics,
+ pub type_: Type,
+ pub generics: Generics,
}
impl Clean<Item> for doctree::Typedef {
#[deriving(Clone, Encodable, Decodable)]
pub struct BareFunctionDecl {
- purity: ast::Purity,
- generics: Generics,
- decl: FnDecl,
- abi: ~str
+ pub fn_style: ast::FnStyle,
+ pub generics: Generics,
+ pub decl: FnDecl,
+ pub abi: ~str,
}
impl Clean<BareFunctionDecl> for ast::BareFnTy {
fn clean(&self) -> BareFunctionDecl {
BareFunctionDecl {
- purity: self.purity,
+ fn_style: self.fn_style,
generics: Generics {
lifetimes: self.lifetimes.clean().move_iter().collect(),
type_params: Vec::new(),
},
decl: self.decl.clean(),
- abi: self.abis.to_str(),
+ abi: self.abi.to_str(),
}
}
}
#[deriving(Clone, Encodable, Decodable)]
pub struct Static {
- type_: Type,
- mutability: Mutability,
+ pub type_: Type,
+ pub mutability: Mutability,
/// It's useful to have the value of a static documented, but I have no
/// desire to represent expressions (that'd basically be all of the AST,
/// which is huge!). So, have a string.
- expr: ~str,
+ pub expr: ~str,
}
impl Clean<Item> for doctree::Static {
#[deriving(Clone, Encodable, Decodable)]
pub struct Impl {
- generics: Generics,
- trait_: Option<Type>,
- for_: Type,
- methods: Vec<Item> ,
+ pub generics: Generics,
+ pub trait_: Option<Type>,
+ pub for_: Type,
+ pub methods: Vec<Item>,
+ pub derived: bool,
}
impl Clean<Item> for doctree::Impl {
fn clean(&self) -> Item {
+ let mut derived = false;
+ for attr in self.attrs.iter() {
+ match attr.node.value.node {
+ ast::MetaWord(ref s) => {
+ if s.get() == "automatically_derived" {
+ derived = true;
+ }
+ }
+ _ => {}
+ }
+ }
Item {
name: None,
attrs: self.attrs.clean(),
trait_: self.trait_.clean(),
for_: self.for_.clean(),
methods: self.methods.clean(),
+ derived: derived,
}),
}
}
#[deriving(Clone, Encodable, Decodable)]
pub struct ViewItem {
- inner: ViewItemInner
+ pub inner: ViewItemInner,
}
impl Clean<Item> for ast::ViewItem {
#[deriving(Clone, Encodable, Decodable)]
pub struct ImportSource {
- path: Path,
- did: Option<ast::DefId>,
+ pub path: Path,
+ pub did: Option<ast::DefId>,
}
impl Clean<ViewPath> for ast::ViewPath {
#[deriving(Clone, Encodable, Decodable)]
pub struct ViewListIdent {
- name: ~str,
- source: Option<ast::DefId>,
+ pub name: ~str,
+ pub source: Option<ast::DefId>,
}
impl Clean<ViewListIdent> for ast::PathListIdent {
ForeignFunctionItem(Function {
decl: decl.clean(),
generics: generics.clean(),
- purity: ast::ExternFn,
+ fn_style: ast::ExternFn,
})
}
ast::ForeignItemStatic(ref ty, mutbl) => {
ForeignStaticItem(Static {
type_: ty.clean(),
mutability: if mutbl {Mutable} else {Immutable},
- expr: ~"",
+ expr: "".to_owned(),
})
}
};
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess().codemap().clone();
let sn = match cm.span_to_snippet(*self) {
Some(x) => x,
- None => ~""
+ None => "".to_owned()
};
debug!("got snippet {}", sn);
sn
match lit.node {
ast::LitStr(ref st, _) => st.get().to_owned(),
ast::LitBinary(ref data) => format!("{:?}", data.as_slice()),
- ast::LitChar(c) => ~"'" + std::char::from_u32(c).unwrap().to_str() + "'",
+ ast::LitChar(c) => "'".to_owned() + std::char::from_u32(c).unwrap().to_str() + "'",
ast::LitInt(i, _t) => i.to_str(),
ast::LitUint(u, _t) => u.to_str(),
ast::LitIntUnsuffixed(i) => i.to_str(),
ast::LitFloat(ref f, _t) => f.get().to_str(),
ast::LitFloatUnsuffixed(ref f) => f.get().to_str(),
ast::LitBool(b) => b.to_str(),
- ast::LitNil => ~"",
+ ast::LitNil => "".to_owned(),
}
}
debug!("Trying to get a name from pattern: {:?}", p);
match p.node {
- PatWild => ~"_",
- PatWildMulti => ~"..",
+ PatWild => "_".to_owned(),
+ PatWildMulti => "..".to_owned(),
PatIdent(_, ref p, _) => path_to_str(p),
PatEnum(ref p, _) => path_to_str(p),
PatStruct(..) => fail!("tried to get argument name from pat_struct, \
which is not allowed in function arguments"),
- PatTup(..) => ~"(tuple arg NYI)",
+ PatTup(..) => "(tuple arg NYI)".to_owned(),
PatUniq(p) => name_from_pat(p),
PatRegion(p) => name_from_pat(p),
PatLit(..) => {
warn!("tried to get argument name from PatLit, \
which is silly in function arguments");
- ~"()"
+ "()".to_owned()
},
PatRange(..) => fail!("tried to get argument name from PatRange, \
which is not allowed in function arguments"),
#[deriving(Clone, Encodable, Decodable)]
pub struct Macro {
- source: ~str,
+ pub source: ~str,
}
impl Clean<Item> for doctree::Macro {