1
Fork 0

Update rustdoc_ng to new ast naming

This commit is contained in:
Corey Richardson 2013-09-05 10:14:35 -04:00
parent 136900fdbb
commit be2f85e24f
3 changed files with 64 additions and 83 deletions

View file

@ -657,7 +657,7 @@ impl Clean<VariantKind> for ast::variant_kind {
} }
} }
impl Clean<~str> for syntax::codemap::span { impl Clean<~str> for syntax::codemap::Span {
fn clean(&self) -> ~str { fn clean(&self) -> ~str {
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess.codemap; let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess.codemap;
cm.span_to_str(*self) cm.span_to_str(*self)
@ -697,7 +697,7 @@ fn path_to_str(p: &ast::Path) -> ~str {
s s
} }
impl Clean<~str> for ast::ident { impl Clean<~str> for ast::Ident {
fn clean(&self) -> ~str { fn clean(&self) -> ~str {
its(self).to_owned() its(self).to_owned()
} }
@ -779,15 +779,13 @@ impl Clean<Item> for doctree::Static {
pub enum Mutability { pub enum Mutability {
Mutable, Mutable,
Immutable, Immutable,
Const,
} }
impl Clean<Mutability> for ast::mutability { impl Clean<Mutability> for ast::Mutability {
fn clean(&self) -> Mutability { fn clean(&self) -> Mutability {
match self { match self {
&ast::m_mutbl => Mutable, &ast::MutMutable => Mutable,
&ast::m_imm => Immutable, &ast::MutImmutable => Immutable,
&ast::m_const => Const
} }
} }
} }
@ -885,7 +883,7 @@ trait ToSource {
fn to_src(&self) -> ~str; fn to_src(&self) -> ~str;
} }
impl ToSource for syntax::codemap::span { impl ToSource for syntax::codemap::Span {
fn to_src(&self) -> ~str { fn to_src(&self) -> ~str {
debug!("converting span %s to snippet", self.clean()); debug!("converting span %s to snippet", self.clean());
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess.codemap.clone(); let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess.codemap.clone();
@ -912,23 +910,23 @@ fn lit_to_str(lit: &ast::lit) -> ~str {
} }
} }
fn name_from_pat(p: &ast::pat) -> ~str { fn name_from_pat(p: &ast::Pat) -> ~str {
use syntax::ast::*; use syntax::ast::*;
match p.node { match p.node {
pat_wild => ~"_", PatWild => ~"_",
pat_ident(_, ref p, _) => path_to_str(p), PatIdent(_, ref p, _) => path_to_str(p),
pat_enum(ref p, _) => path_to_str(p), PatEnum(ref p, _) => path_to_str(p),
pat_struct(*) => fail!("tried to get argument name from pat_struct, \ PatStruct(*) => fail!("tried to get argument name from pat_struct, \
which is not allowed in function arguments"), which is not allowed in function arguments"),
pat_tup(*) => ~"(tuple arg NYI)", PatTup(*) => ~"(tuple arg NYI)",
pat_box(p) => name_from_pat(p), PatBox(p) => name_from_pat(p),
pat_uniq(p) => name_from_pat(p), PatUniq(p) => name_from_pat(p),
pat_region(p) => name_from_pat(p), PatRegion(p) => name_from_pat(p),
pat_lit(*) => fail!("tried to get argument name from pat_lit, \ PatLit(*) => fail!("tried to get argument name from pat_lit, \
which is not allowed in function arguments"), which is not allowed in function arguments"),
pat_range(*) => fail!("tried to get argument name from pat_range, \ PatRange(*) => fail!("tried to get argument name from pat_range, \
which is not allowed in function arguments"), which is not allowed in function arguments"),
pat_vec(*) => fail!("tried to get argument name from pat_vec, \ PatVec(*) => fail!("tried to get argument name from pat_vec, \
which is not allowed in function arguments") which is not allowed in function arguments")
} }
} }
@ -945,23 +943,6 @@ fn remove_comment_tags(s: &str) -> ~str {
} }
} }
/*fn collapse_docs(attrs: ~[Attribute]) -> ~[Attribute] {
let mut docstr = ~"";
for at in attrs.iter() {
match *at {
//XXX how should these be separated?
NameValue(~"doc", ref s) => docstr.push_str(fmt!("%s ", clean_comment_body(s.clone()))),
_ => ()
}
}
let mut a = attrs.iter().filter(|&a| match a {
&NameValue(~"doc", _) => false,
_ => true
}).map(|x| x.clone()).collect::<~[Attribute]>();
a.push(NameValue(~"doc", docstr.trim().to_owned()));
a
}*/
/// Given a Type, resolve it using the def_map /// Given a Type, resolve it using the def_map
fn resolve_type(t: &Type) -> Type { fn resolve_type(t: &Type) -> Type {
use syntax::ast::*; use syntax::ast::*;
@ -984,21 +965,21 @@ fn resolve_type(t: &Type) -> Type {
}; };
let def_id = match *d { let def_id = match *d {
def_fn(i, _) => i, DefFn(i, _) => i,
def_self(i, _) | def_self_ty(i) => return Self(i), DefSelf(i, _) | DefSelfTy(i) => return Self(i),
def_ty(i) => i, DefTy(i) => i,
def_trait(i) => { DefTrait(i) => {
debug!("saw def_trait in def_to_id"); debug!("saw DefTrait in def_to_id");
i i
}, },
def_prim_ty(p) => match p { DefPrimTy(p) => match p {
ty_str => return String, ty_str => return String,
ty_bool => return Bool, ty_bool => return Bool,
_ => return Primitive(p) _ => return Primitive(p)
}, },
def_ty_param(i, _) => return Generic(i.node), DefTyParam(i, _) => return Generic(i.node),
def_struct(i) => i, DefStruct(i) => i,
def_typaram_binder(i) => { DefTyParamBinder(i) => {
debug!("found a typaram_binder, what is it? %d", i); debug!("found a typaram_binder, what is it? %d", i);
return TyParamBinder(i); return TyParamBinder(i);
}, },
@ -1011,10 +992,10 @@ fn resolve_type(t: &Type) -> Type {
let mut ty = ~""; let mut ty = ~"";
do csearch::each_path(sess.cstore, def_id.crate) |pathstr, deflike, _vis| { do csearch::each_path(sess.cstore, def_id.crate) |pathstr, deflike, _vis| {
match deflike { match deflike {
decoder::dl_def(di) => { decoder::DlDef(di) => {
let d2 = match di { let d2 = match di {
def_fn(i, _) | def_ty(i) | def_trait(i) | DefFn(i, _) | DefTy(i) | DefTrait(i) |
def_struct(i) | def_mod(i) => Some(i), DefStruct(i) | DefMod(i) => Some(i),
_ => None, _ => None,
}; };
if d2.is_some() { if d2.is_some() {
@ -1023,10 +1004,10 @@ fn resolve_type(t: &Type) -> Type {
debug!("found external def: %?", di); debug!("found external def: %?", di);
path = pathstr.to_owned(); path = pathstr.to_owned();
ty = match di { ty = match di {
def_fn(*) => ~"fn", DefFn(*) => ~"fn",
def_ty(*) => ~"enum", DefTy(*) => ~"enum",
def_trait(*) => ~"trait", DefTrait(*) => ~"trait",
def_prim_ty(p) => match p { DefPrimTy(p) => match p {
ty_str => ~"str", ty_str => ~"str",
ty_bool => ~"bool", ty_bool => ~"bool",
ty_int(t) => match t.to_str() { ty_int(t) => match t.to_str() {
@ -1036,9 +1017,9 @@ fn resolve_type(t: &Type) -> Type {
ty_uint(t) => t.to_str(), ty_uint(t) => t.to_str(),
ty_float(t) => t.to_str() ty_float(t) => t.to_str()
}, },
def_ty_param(*) => ~"generic", DefTyParam(*) => ~"generic",
def_struct(*) => ~"struct", DefStruct(*) => ~"struct",
def_typaram_binder(*) => ~"typaram_binder", DefTyParamBinder(*) => ~"typaram_binder",
x => fail!("resolved external maps to a weird def %?", x), x => fail!("resolved external maps to a weird def %?", x),
}; };

View file

@ -2,14 +2,14 @@
//! manner (and with prettier names) before cleaning. //! manner (and with prettier names) before cleaning.
use syntax; use syntax;
use syntax::codemap::span; use syntax::codemap::Span;
use syntax::ast; use syntax::ast;
use syntax::ast::{ident, NodeId}; use syntax::ast::{Ident, NodeId};
pub struct Module { pub struct Module {
name: Option<ident>, name: Option<Ident>,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
where: span, where: Span,
structs: ~[Struct], structs: ~[Struct],
enums: ~[Enum], enums: ~[Enum],
fns: ~[Function], fns: ~[Function],
@ -24,7 +24,7 @@ pub struct Module {
} }
impl Module { impl Module {
pub fn new(name: Option<ident>) -> Module { pub fn new(name: Option<Ident>) -> Module {
Module { Module {
name : name, name : name,
id: 0, id: 0,
@ -65,11 +65,11 @@ pub struct Struct {
vis: ast::visibility, vis: ast::visibility,
id: NodeId, id: NodeId,
struct_type: StructType, struct_type: StructType,
name: ident, name: Ident,
generics: ast::Generics, generics: ast::Generics,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
fields: ~[@ast::struct_field], fields: ~[@ast::struct_field],
where: span, where: Span,
} }
pub struct Enum { pub struct Enum {
@ -78,58 +78,58 @@ pub struct Enum {
generics: ast::Generics, generics: ast::Generics,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
id: NodeId, id: NodeId,
where: span, where: Span,
name: ident, name: Ident,
} }
pub struct Variant { pub struct Variant {
name: ident, name: Ident,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
kind: ast::variant_kind, kind: ast::variant_kind,
id: ast::NodeId, id: ast::NodeId,
vis: ast::visibility, vis: ast::visibility,
where: span, where: Span,
} }
pub struct Function { pub struct Function {
decl: ast::fn_decl, decl: ast::fn_decl,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
id: NodeId, id: NodeId,
name: ident, name: Ident,
vis: ast::visibility, vis: ast::visibility,
where: span, where: Span,
generics: ast::Generics, generics: ast::Generics,
} }
pub struct Typedef { pub struct Typedef {
ty: ast::Ty, ty: ast::Ty,
gen: ast::Generics, gen: ast::Generics,
name: ast::ident, name: Ident,
id: ast::NodeId, id: ast::NodeId,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
where: span, where: Span,
vis: ast::visibility, vis: ast::visibility,
} }
pub struct Static { pub struct Static {
type_: ast::Ty, type_: ast::Ty,
mutability: ast::mutability, mutability: ast::Mutability,
expr: @ast::expr, expr: @ast::Expr,
name: ast::ident, name: Ident,
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
vis: ast::visibility, vis: ast::visibility,
id: ast::NodeId, id: ast::NodeId,
where: span, where: Span,
} }
pub struct Trait { pub struct Trait {
name: ast::ident, name: Ident,
methods: ~[ast::trait_method], //should be TraitMethod methods: ~[ast::trait_method], //should be TraitMethod
generics: ast::Generics, generics: ast::Generics,
parents: ~[ast::trait_ref], parents: ~[ast::trait_ref],
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
id: ast::NodeId, id: ast::NodeId,
where: span, where: Span,
vis: ast::visibility, vis: ast::visibility,
} }
@ -139,7 +139,7 @@ pub struct Impl {
for_: ast::Ty, for_: ast::Ty,
methods: ~[@ast::method], methods: ~[@ast::method],
attrs: ~[ast::Attribute], attrs: ~[ast::Attribute],
where: span, where: Span,
vis: ast::visibility, vis: ast::visibility,
id: ast::NodeId, id: ast::NodeId,
} }

View file

@ -3,7 +3,7 @@
use syntax::abi::AbiSet; use syntax::abi::AbiSet;
use syntax::{ast, ast_map}; use syntax::{ast, ast_map};
use syntax::codemap::span; use syntax::codemap::Span;
use doctree::*; use doctree::*;
use std::local_data; use std::local_data;
@ -79,7 +79,7 @@ impl RustdocVisitor {
} }
} }
fn visit_mod_contents(span: span, attrs: ~[ast::Attribute], vis: fn visit_mod_contents(span: Span, attrs: ~[ast::Attribute], vis:
ast::visibility, id: ast::NodeId, m: &ast::_mod) -> Module { ast::visibility, id: ast::NodeId, m: &ast::_mod) -> Module {
let am = local_data::get(super::ctxtkey, |x| *x.unwrap()).tycx.items; let am = local_data::get(super::ctxtkey, |x| *x.unwrap()).tycx.items;
let name = match am.find(&id) { let name = match am.find(&id) {