1
Fork 0

Update rustdoc_ng to syntax and metadata changes

This commit is contained in:
Corey Richardson 2013-09-12 15:11:06 -04:00
parent be2f85e24f
commit c1d977a638
4 changed files with 54 additions and 57 deletions

View file

@ -3,7 +3,6 @@
use its = syntax::parse::token::ident_to_str; use its = syntax::parse::token::ident_to_str;
use rustc::metadata::{csearch,decoder,cstore};
use syntax; use syntax;
use syntax::ast; use syntax::ast;
@ -666,17 +665,32 @@ impl Clean<~str> for syntax::codemap::Span {
#[deriving(Clone, Encodable, Decodable)] #[deriving(Clone, Encodable, Decodable)]
pub struct Path { pub struct Path {
name: ~str, global: bool,
lifetime: Option<Lifetime>, segments: ~[PathSegment],
typarams: ~[Type]
} }
impl Clean<Path> for ast::Path { impl Clean<Path> for ast::Path {
fn clean(&self) -> Path { fn clean(&self) -> Path {
Path { Path {
name: path_to_str(self), global: self.global,
lifetime: self.rp.clean(), segments: self.segments.clean()
typarams: self.types.clean(), }
}
}
#[deriving(Clone, Encodable, Decodable)]
pub struct PathSegment {
name: ~str,
lifetime: Option<Lifetime>,
types: ~[Type],
}
impl Clean<PathSegment> for ast::PathSegment {
fn clean(&self) -> PathSegment {
PathSegment {
name: self.identifier.clean(),
lifetime: self.lifetime.clean(),
types: self.types.clean()
} }
} }
} }
@ -686,7 +700,7 @@ fn path_to_str(p: &ast::Path) -> ~str {
let mut s = ~""; let mut s = ~"";
let mut first = true; let mut first = true;
for i in p.idents.iter().map(|x| interner_get(x.name)) { for i in p.segments.iter().map(|x| interner_get(x.identifier.name)) {
if !first || p.global { if !first || p.global {
s.push_str("::"); s.push_str("::");
} else { } else {
@ -899,7 +913,7 @@ impl ToSource for syntax::codemap::Span {
fn lit_to_str(lit: &ast::lit) -> ~str { fn lit_to_str(lit: &ast::lit) -> ~str {
match lit.node { match lit.node {
ast::lit_str(st) => st.to_owned(), ast::lit_str(st) => st.to_owned(),
ast::lit_int(ch, ast::ty_char) => ~"'" + ch.to_str() + "'", ast::lit_char(c) => ~"'" + std::char::from_u32(c).unwrap().to_str() + "'",
ast::lit_int(i, _t) => i.to_str(), ast::lit_int(i, _t) => i.to_str(),
ast::lit_uint(u, _t) => u.to_str(), ast::lit_uint(u, _t) => u.to_str(),
ast::lit_int_unsuffixed(i) => i.to_str(), ast::lit_int_unsuffixed(i) => i.to_str(),
@ -966,7 +980,7 @@ fn resolve_type(t: &Type) -> Type {
let def_id = match *d { let def_id = match *d {
DefFn(i, _) => i, DefFn(i, _) => i,
DefSelf(i, _) | DefSelfTy(i) => return Self(i), DefSelf(i) | DefSelfTy(i) => return Self(i),
DefTy(i) => i, DefTy(i) => i,
DefTrait(i) => { DefTrait(i) => {
debug!("saw DefTrait in def_to_id"); debug!("saw DefTrait in def_to_id");
@ -987,23 +1001,13 @@ fn resolve_type(t: &Type) -> Type {
}; };
if def_id.crate != ast::CRATE_NODE_ID { if def_id.crate != ast::CRATE_NODE_ID {
use rustc::metadata::decoder::*;
let sess = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess; let sess = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess;
let mut path = ~""; let cratedata = ::rustc::metadata::cstore::get_crate_data(sess.cstore, def_id.crate);
let mut ty = ~""; let doc = lookup_item(def_id.node, cratedata.data);
do csearch::each_path(sess.cstore, def_id.crate) |pathstr, deflike, _vis| { let path = syntax::ast_map::path_to_str_with_sep(item_path(doc), "::", sess.intr());
match deflike { let ty = match def_like_to_def(item_to_def_like(doc, def_id, def_id.crate)) {
decoder::DlDef(di) => {
let d2 = match di {
DefFn(i, _) | DefTy(i) | DefTrait(i) |
DefStruct(i) | DefMod(i) => Some(i),
_ => None,
};
if d2.is_some() {
let d2 = d2.unwrap();
if def_id.node == d2.node {
debug!("found external def: %?", di);
path = pathstr.to_owned();
ty = match di {
DefFn(*) => ~"fn", DefFn(*) => ~"fn",
DefTy(*) => ~"enum", DefTy(*) => ~"enum",
DefTrait(*) => ~"trait", DefTrait(*) => ~"trait",
@ -1015,22 +1019,15 @@ fn resolve_type(t: &Type) -> Type {
s => s s => s
}, },
ty_uint(t) => t.to_str(), ty_uint(t) => t.to_str(),
ty_float(t) => t.to_str() ty_float(t) => t.to_str(),
ty_char => ~"char",
}, },
DefTyParam(*) => ~"generic", DefTyParam(*) => ~"generic",
DefStruct(*) => ~"struct", DefStruct(*) => ~"struct",
DefTyParamBinder(*) => ~"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),
}; };
let cname = cratedata.name.to_owned();
}
}
},
_ => (),
};
true
};
let cname = cstore::get_crate_data(sess.cstore, def_id.crate).name.to_owned();
External(cname + "::" + path, ty) External(cname + "::" + path, ty)
} else { } else {
ResolvedPath {path: path.clone(), typarams: tpbs.clone(), id: def_id.node} ResolvedPath {path: path.clone(), typarams: tpbs.clone(), id: def_id.node}

View file

@ -42,7 +42,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: ~[Path]) -> DocContext {
syntax::diagnostic::emit, syntax::diagnostic::emit,
span_diagnostic_handler); span_diagnostic_handler);
let mut cfg = build_configuration(sess, @"rustdoc_ng", &input); let mut cfg = build_configuration(sess);
cfg.push(@dummy_spanned(ast::MetaWord(@"stage2"))); cfg.push(@dummy_spanned(ast::MetaWord(@"stage2")));
let mut crate = phase_1_parse_input(sess, cfg.clone(), &input); let mut crate = phase_1_parse_input(sess, cfg.clone(), &input);

View file

@ -1,6 +1,6 @@
use std; use std;
use clean::*; use clean::*;
use std::iterator::Extendable; use std::iter::Extendable;
pub trait DocFolder { pub trait DocFolder {
fn fold_item(&mut self, item: Item) -> Option<Item> { fn fold_item(&mut self, item: Item) -> Option<Item> {