33
44use its = syntax:: parse:: token:: ident_to_str;
55
6- use rustc:: metadata:: { csearch, decoder, cstore} ;
76use syntax;
87use 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 ) ]
668667pub struct Path {
669- name : ~str ,
670- lifetime : Option < Lifetime > ,
671- typarams : ~[ Type ]
668+ global : bool ,
669+ segments : ~[ PathSegment ] ,
672670}
673671
674672impl 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 {
899913fn 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 }
0 commit comments