about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2013-09-12 15:11:06 -0400
committerCorey Richardson <corey@octayn.net>2013-09-16 07:26:50 -0400
commitc1d977a638064e3ad8c1343d4b146e99607525ba (patch)
tree67b1ebfdc7fabf9343b37d99b8ed5ec699dbafb7
parentbe2f85e24f50e365de76af2bff8e33e848f8f1d1 (diff)
downloadrust-c1d977a638064e3ad8c1343d4b146e99607525ba.tar.gz
rust-c1d977a638064e3ad8c1343d4b146e99607525ba.zip
Update rustdoc_ng to syntax and metadata changes
-rw-r--r--src/rustdoc_ng/clean.rs103
-rw-r--r--src/rustdoc_ng/core.rs2
-rw-r--r--src/rustdoc_ng/fold.rs2
-rw-r--r--src/rustdoc_ng/passes.rs4
4 files changed, 54 insertions, 57 deletions
diff --git a/src/rustdoc_ng/clean.rs b/src/rustdoc_ng/clean.rs
index fefd679e20b..aae3be7001a 100644
--- a/src/rustdoc_ng/clean.rs
+++ b/src/rustdoc_ng/clean.rs
@@ -3,7 +3,6 @@
 
 use its = syntax::parse::token::ident_to_str;
 
-use rustc::metadata::{csearch,decoder,cstore};
 use syntax;
 use syntax::ast;
 
@@ -500,7 +499,7 @@ impl Clean<Type> for ast::Ty {
         let t = match self.node {
             ty_nil => Unit,
             ty_ptr(ref m) =>  RawPointer(m.mutbl.clean(), ~resolve_type(&m.ty.clean())),
-            ty_rptr(ref l, ref m) => 
+            ty_rptr(ref l, ref m) =>
                 BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(),
                              type_: ~resolve_type(&m.ty.clean())},
             ty_box(ref m) => Managed(m.mutbl.clean(), ~resolve_type(&m.ty.clean())),
@@ -666,17 +665,32 @@ impl Clean<~str> for syntax::codemap::Span {
 
 #[deriving(Clone, Encodable, Decodable)]
 pub struct Path {
-    name: ~str,
-    lifetime: Option<Lifetime>,
-    typarams: ~[Type]
+    global: bool,
+    segments: ~[PathSegment],
 }
 
 impl Clean<Path> for ast::Path {
     fn clean(&self) -> Path {
         Path {
-            name: path_to_str(self),
-            lifetime: self.rp.clean(),
-            typarams: self.types.clean(),
+            global: self.global,
+            segments: self.segments.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 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 {
             s.push_str("::");
         } else {
@@ -899,7 +913,7 @@ impl ToSource for syntax::codemap::Span {
 fn lit_to_str(lit: &ast::lit) -> ~str {
     match lit.node {
         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_uint(u, _t) => u.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 {
         DefFn(i, _) => i,
-        DefSelf(i, _) | DefSelfTy(i) => return Self(i),
+        DefSelf(i) | DefSelfTy(i) => return Self(i),
         DefTy(i) => i,
         DefTrait(i) => {
             debug!("saw DefTrait in def_to_id");
@@ -979,7 +993,7 @@ fn resolve_type(t: &Type) -> Type {
         },
         DefTyParam(i, _) => return Generic(i.node),
         DefStruct(i) => i,
-        DefTyParamBinder(i) => { 
+        DefTyParamBinder(i) => {
             debug!("found a typaram_binder, what is it? %d", i);
             return TyParamBinder(i);
         },
@@ -987,50 +1001,33 @@ fn resolve_type(t: &Type) -> Type {
     };
 
     if def_id.crate != ast::CRATE_NODE_ID {
+        use rustc::metadata::decoder::*;
+
         let sess = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess;
-        let mut path = ~"";
-        let mut ty = ~"";
-        do csearch::each_path(sess.cstore, def_id.crate) |pathstr, deflike, _vis| {
-            match deflike {
-                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",
-                                DefTy(*) => ~"enum",
-                                DefTrait(*) => ~"trait",
-                                DefPrimTy(p) => match p {
-                                    ty_str => ~"str",
-                                    ty_bool => ~"bool",
-                                    ty_int(t) => match t.to_str() {
-                                        ~"" => ~"i",
-                                        s => s
-                                    },
-                                    ty_uint(t) => t.to_str(),
-                                    ty_float(t) => t.to_str()
-                                },
-                                DefTyParam(*) => ~"generic",
-                                DefStruct(*) => ~"struct",
-                                DefTyParamBinder(*) => ~"typaram_binder",
-                                x => fail!("resolved external maps to a weird def %?", x),
-                            };
-
-                        }
-                    }
+        let cratedata = ::rustc::metadata::cstore::get_crate_data(sess.cstore, def_id.crate);
+        let doc = lookup_item(def_id.node, cratedata.data);
+        let path = syntax::ast_map::path_to_str_with_sep(item_path(doc), "::", sess.intr());
+        let ty = match def_like_to_def(item_to_def_like(doc, def_id, def_id.crate)) {
+            DefFn(*) => ~"fn",
+            DefTy(*) => ~"enum",
+            DefTrait(*) => ~"trait",
+            DefPrimTy(p) => match p {
+                ty_str => ~"str",
+                ty_bool => ~"bool",
+                ty_int(t) => match t.to_str() {
+                    ~"" => ~"i",
+                    s => s
                 },
-                _ => (),
-            };
-            true
+                ty_uint(t) => t.to_str(),
+                ty_float(t) => t.to_str(),
+                ty_char => ~"char",
+            },
+            DefTyParam(*) => ~"generic",
+            DefStruct(*) => ~"struct",
+            DefTyParamBinder(*) => ~"typaram_binder",
+            x => fail!("resolved external maps to a weird def %?", x),
         };
-        let cname = cstore::get_crate_data(sess.cstore, def_id.crate).name.to_owned();
+        let cname = cratedata.name.to_owned();
         External(cname + "::" + path, ty)
     } else {
         ResolvedPath {path: path.clone(), typarams: tpbs.clone(), id: def_id.node}
diff --git a/src/rustdoc_ng/core.rs b/src/rustdoc_ng/core.rs
index 8e12dbdce4d..0a948bd73eb 100644
--- a/src/rustdoc_ng/core.rs
+++ b/src/rustdoc_ng/core.rs
@@ -42,7 +42,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: ~[Path]) -> DocContext {
                                                   syntax::diagnostic::emit,
                                                   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")));
 
     let mut crate = phase_1_parse_input(sess, cfg.clone(), &input);
diff --git a/src/rustdoc_ng/fold.rs b/src/rustdoc_ng/fold.rs
index 740e434f465..e3ce6e80ae4 100644
--- a/src/rustdoc_ng/fold.rs
+++ b/src/rustdoc_ng/fold.rs
@@ -1,6 +1,6 @@
 use std;
 use clean::*;
-use std::iterator::Extendable;
+use std::iter::Extendable;
 
 pub trait DocFolder {
     fn fold_item(&mut self, item: Item) -> Option<Item> {
diff --git a/src/rustdoc_ng/passes.rs b/src/rustdoc_ng/passes.rs
index 73f94ef0f27..30fa0f56a43 100644
--- a/src/rustdoc_ng/passes.rs
+++ b/src/rustdoc_ng/passes.rs
@@ -173,7 +173,7 @@ fn clean_comment_body(s: ~str) -> ~str {
         1 => return lines[0].slice_from(2).trim().to_owned(),
         _ => (),
     }
-            
+
     let mut ol = std::vec::with_capacity(lines.len());
     for line in lines.clone().move_iter() {
         // replace meaningless things with a single newline
@@ -184,7 +184,7 @@ fn clean_comment_body(s: ~str) -> ~str {
         }
     }
     let li = longest_common_prefix(ol.clone());
-    
+
     let x = ol.iter()
          .filter(|x| { debug!("cleaning line: %s", **x); true })
          .map(|x| if x.len() == 0 { ~"" } else { x.slice_chars(li, x.char_len()).to_owned() })