Skip to content

Commit c1d977a

Browse files
committed
Update rustdoc_ng to syntax and metadata changes
1 parent be2f85e commit c1d977a

File tree

4 files changed

+54
-57
lines changed

4 files changed

+54
-57
lines changed

src/rustdoc_ng/clean.rs

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
44
use its = syntax::parse::token::ident_to_str;
55

6-
use rustc::metadata::{csearch,decoder,cstore};
76
use syntax;
87
use syntax::ast;
98

@@ -500,7 +499,7 @@ impl Clean<Type> for ast::Ty {
500499
let t = match self.node {
501500
ty_nil => Unit,
502501
ty_ptr(ref m) => RawPointer(m.mutbl.clean(), ~resolve_type(&m.ty.clean())),
503-
ty_rptr(ref l, ref m) =>
502+
ty_rptr(ref l, ref m) =>
504503
BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(),
505504
type_: ~resolve_type(&m.ty.clean())},
506505
ty_box(ref m) => Managed(m.mutbl.clean(), ~resolve_type(&m.ty.clean())),
@@ -666,17 +665,32 @@ impl Clean<~str> for syntax::codemap::Span {
666665

667666
#[deriving(Clone, Encodable, Decodable)]
668667
pub struct Path {
669-
name: ~str,
670-
lifetime: Option<Lifetime>,
671-
typarams: ~[Type]
668+
global: bool,
669+
segments: ~[PathSegment],
672670
}
673671

674672
impl Clean<Path> for ast::Path {
675673
fn clean(&self) -> Path {
676674
Path {
677-
name: path_to_str(self),
678-
lifetime: self.rp.clean(),
679-
typarams: self.types.clean(),
675+
global: self.global,
676+
segments: self.segments.clean()
677+
}
678+
}
679+
}
680+
681+
#[deriving(Clone, Encodable, Decodable)]
682+
pub struct PathSegment {
683+
name: ~str,
684+
lifetime: Option<Lifetime>,
685+
types: ~[Type],
686+
}
687+
688+
impl Clean<PathSegment> for ast::PathSegment {
689+
fn clean(&self) -> PathSegment {
690+
PathSegment {
691+
name: self.identifier.clean(),
692+
lifetime: self.lifetime.clean(),
693+
types: self.types.clean()
680694
}
681695
}
682696
}
@@ -686,7 +700,7 @@ fn path_to_str(p: &ast::Path) -> ~str {
686700

687701
let mut s = ~"";
688702
let mut first = true;
689-
for i in p.idents.iter().map(|x| interner_get(x.name)) {
703+
for i in p.segments.iter().map(|x| interner_get(x.identifier.name)) {
690704
if !first || p.global {
691705
s.push_str("::");
692706
} else {
@@ -899,7 +913,7 @@ impl ToSource for syntax::codemap::Span {
899913
fn lit_to_str(lit: &ast::lit) -> ~str {
900914
match lit.node {
901915
ast::lit_str(st) => st.to_owned(),
902-
ast::lit_int(ch, ast::ty_char) => ~"'" + ch.to_str() + "'",
916+
ast::lit_char(c) => ~"'" + std::char::from_u32(c).unwrap().to_str() + "'",
903917
ast::lit_int(i, _t) => i.to_str(),
904918
ast::lit_uint(u, _t) => u.to_str(),
905919
ast::lit_int_unsuffixed(i) => i.to_str(),
@@ -966,7 +980,7 @@ fn resolve_type(t: &Type) -> Type {
966980

967981
let def_id = match *d {
968982
DefFn(i, _) => i,
969-
DefSelf(i, _) | DefSelfTy(i) => return Self(i),
983+
DefSelf(i) | DefSelfTy(i) => return Self(i),
970984
DefTy(i) => i,
971985
DefTrait(i) => {
972986
debug!("saw DefTrait in def_to_id");
@@ -979,58 +993,41 @@ fn resolve_type(t: &Type) -> Type {
979993
},
980994
DefTyParam(i, _) => return Generic(i.node),
981995
DefStruct(i) => i,
982-
DefTyParamBinder(i) => {
996+
DefTyParamBinder(i) => {
983997
debug!("found a typaram_binder, what is it? %d", i);
984998
return TyParamBinder(i);
985999
},
9861000
x => fail!("resolved type maps to a weird def %?", x),
9871001
};
9881002

9891003
if def_id.crate != ast::CRATE_NODE_ID {
1004+
use rustc::metadata::decoder::*;
1005+
9901006
let sess = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess;
991-
let mut path = ~"";
992-
let mut ty = ~"";
993-
do csearch::each_path(sess.cstore, def_id.crate) |pathstr, deflike, _vis| {
994-
match deflike {
995-
decoder::DlDef(di) => {
996-
let d2 = match di {
997-
DefFn(i, _) | DefTy(i) | DefTrait(i) |
998-
DefStruct(i) | DefMod(i) => Some(i),
999-
_ => None,
1000-
};
1001-
if d2.is_some() {
1002-
let d2 = d2.unwrap();
1003-
if def_id.node == d2.node {
1004-
debug!("found external def: %?", di);
1005-
path = pathstr.to_owned();
1006-
ty = match di {
1007-
DefFn(*) => ~"fn",
1008-
DefTy(*) => ~"enum",
1009-
DefTrait(*) => ~"trait",
1010-
DefPrimTy(p) => match p {
1011-
ty_str => ~"str",
1012-
ty_bool => ~"bool",
1013-
ty_int(t) => match t.to_str() {
1014-
~"" => ~"i",
1015-
s => s
1016-
},
1017-
ty_uint(t) => t.to_str(),
1018-
ty_float(t) => t.to_str()
1019-
},
1020-
DefTyParam(*) => ~"generic",
1021-
DefStruct(*) => ~"struct",
1022-
DefTyParamBinder(*) => ~"typaram_binder",
1023-
x => fail!("resolved external maps to a weird def %?", x),
1024-
};
1025-
1026-
}
1027-
}
1007+
let cratedata = ::rustc::metadata::cstore::get_crate_data(sess.cstore, def_id.crate);
1008+
let doc = lookup_item(def_id.node, cratedata.data);
1009+
let path = syntax::ast_map::path_to_str_with_sep(item_path(doc), "::", sess.intr());
1010+
let ty = match def_like_to_def(item_to_def_like(doc, def_id, def_id.crate)) {
1011+
DefFn(*) => ~"fn",
1012+
DefTy(*) => ~"enum",
1013+
DefTrait(*) => ~"trait",
1014+
DefPrimTy(p) => match p {
1015+
ty_str => ~"str",
1016+
ty_bool => ~"bool",
1017+
ty_int(t) => match t.to_str() {
1018+
~"" => ~"i",
1019+
s => s
10281020
},
1029-
_ => (),
1030-
};
1031-
true
1021+
ty_uint(t) => t.to_str(),
1022+
ty_float(t) => t.to_str(),
1023+
ty_char => ~"char",
1024+
},
1025+
DefTyParam(*) => ~"generic",
1026+
DefStruct(*) => ~"struct",
1027+
DefTyParamBinder(*) => ~"typaram_binder",
1028+
x => fail!("resolved external maps to a weird def %?", x),
10321029
};
1033-
let cname = cstore::get_crate_data(sess.cstore, def_id.crate).name.to_owned();
1030+
let cname = cratedata.name.to_owned();
10341031
External(cname + "::" + path, ty)
10351032
} else {
10361033
ResolvedPath {path: path.clone(), typarams: tpbs.clone(), id: def_id.node}

src/rustdoc_ng/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: ~[Path]) -> DocContext {
4242
syntax::diagnostic::emit,
4343
span_diagnostic_handler);
4444

45-
let mut cfg = build_configuration(sess, @"rustdoc_ng", &input);
45+
let mut cfg = build_configuration(sess);
4646
cfg.push(@dummy_spanned(ast::MetaWord(@"stage2")));
4747

4848
let mut crate = phase_1_parse_input(sess, cfg.clone(), &input);

src/rustdoc_ng/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std;
22
use clean::*;
3-
use std::iterator::Extendable;
3+
use std::iter::Extendable;
44

55
pub trait DocFolder {
66
fn fold_item(&mut self, item: Item) -> Option<Item> {

src/rustdoc_ng/passes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fn clean_comment_body(s: ~str) -> ~str {
173173
1 => return lines[0].slice_from(2).trim().to_owned(),
174174
_ => (),
175175
}
176-
176+
177177
let mut ol = std::vec::with_capacity(lines.len());
178178
for line in lines.clone().move_iter() {
179179
// replace meaningless things with a single newline
@@ -184,7 +184,7 @@ fn clean_comment_body(s: ~str) -> ~str {
184184
}
185185
}
186186
let li = longest_common_prefix(ol.clone());
187-
187+
188188
let x = ol.iter()
189189
.filter(|x| { debug!("cleaning line: %s", **x); true })
190190
.map(|x| if x.len() == 0 { ~"" } else { x.slice_chars(li, x.char_len()).to_owned() })

0 commit comments

Comments
 (0)