3
3
4
4
use its = syntax:: parse:: token:: ident_to_str;
5
5
6
- use rustc:: metadata:: { csearch, decoder, cstore} ;
7
6
use syntax;
8
7
use syntax:: ast;
9
8
@@ -500,7 +499,7 @@ impl Clean<Type> for ast::Ty {
500
499
let t = match self . node {
501
500
ty_nil => Unit ,
502
501
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) =>
504
503
BorrowedRef { lifetime : l. clean ( ) , mutability : m. mutbl . clean ( ) ,
505
504
type_ : ~resolve_type ( & m. ty . clean ( ) ) } ,
506
505
ty_box( ref m) => Managed ( m. mutbl . clean ( ) , ~resolve_type ( & m. ty . clean ( ) ) ) ,
@@ -666,17 +665,32 @@ impl Clean<~str> for syntax::codemap::Span {
666
665
667
666
#[ deriving( Clone , Encodable , Decodable ) ]
668
667
pub struct Path {
669
- name : ~str ,
670
- lifetime : Option < Lifetime > ,
671
- typarams : ~[ Type ]
668
+ global : bool ,
669
+ segments : ~[ PathSegment ] ,
672
670
}
673
671
674
672
impl Clean < Path > for ast:: Path {
675
673
fn clean ( & self ) -> Path {
676
674
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 ( )
680
694
}
681
695
}
682
696
}
@@ -686,7 +700,7 @@ fn path_to_str(p: &ast::Path) -> ~str {
686
700
687
701
let mut s = ~"";
688
702
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 ) ) {
690
704
if !first || p. global {
691
705
s. push_str ( "::" ) ;
692
706
} else {
@@ -899,7 +913,7 @@ impl ToSource for syntax::codemap::Span {
899
913
fn lit_to_str( lit : & ast:: lit ) -> ~str {
900
914
match lit. node {
901
915
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 ( ) + "'" ,
903
917
ast:: lit_int( i, _t) => i. to_str ( ) ,
904
918
ast:: lit_uint( u, _t) => u. to_str ( ) ,
905
919
ast:: lit_int_unsuffixed( i) => i. to_str ( ) ,
@@ -966,7 +980,7 @@ fn resolve_type(t: &Type) -> Type {
966
980
967
981
let def_id = match * d {
968
982
DefFn ( i, _) => i,
969
- DefSelf ( i, _ ) | DefSelfTy ( i) => return Self ( i) ,
983
+ DefSelf ( i) | DefSelfTy ( i) => return Self ( i) ,
970
984
DefTy ( i) => i,
971
985
DefTrait ( i) => {
972
986
debug ! ( "saw DefTrait in def_to_id" ) ;
@@ -979,58 +993,41 @@ fn resolve_type(t: &Type) -> Type {
979
993
} ,
980
994
DefTyParam ( i, _) => return Generic ( i. node ) ,
981
995
DefStruct ( i) => i,
982
- DefTyParamBinder ( i) => {
996
+ DefTyParamBinder ( i) => {
983
997
debug ! ( "found a typaram_binder, what is it? %d" , i) ;
984
998
return TyParamBinder ( i) ;
985
999
} ,
986
1000
x => fail ! ( "resolved type maps to a weird def %?" , x) ,
987
1001
} ;
988
1002
989
1003
if def_id. crate != ast:: CRATE_NODE_ID {
1004
+ use rustc:: metadata:: decoder:: * ;
1005
+
990
1006
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
1028
1020
} ,
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) ,
1032
1029
} ;
1033
- let cname = cstore :: get_crate_data ( sess . cstore , def_id . crate ) . name . to_owned ( ) ;
1030
+ let cname = cratedata . name . to_owned ( ) ;
1034
1031
External ( cname + "::" + path, ty)
1035
1032
} else {
1036
1033
ResolvedPath { path : path. clone ( ) , typarams : tpbs. clone ( ) , id : def_id. node }
0 commit comments