@@ -15,11 +15,18 @@ use its = syntax::parse::token::ident_to_str;
15
15
16
16
use syntax;
17
17
use syntax:: ast;
18
+ use syntax:: ast_map;
18
19
use syntax:: ast_util;
19
20
use syntax:: attr;
20
21
use syntax:: attr:: AttributeMethods ;
21
22
23
+ use rustc:: metadata:: cstore;
24
+ use rustc:: metadata:: csearch;
25
+ use rustc:: metadata:: decoder;
26
+
22
27
use std;
28
+ use std:: hashmap:: HashMap ;
29
+
23
30
use doctree;
24
31
use visit_ast;
25
32
use std:: local_data;
@@ -61,19 +68,44 @@ impl<T: Clean<U>, U> Clean<~[U]> for syntax::opt_vec::OptVec<T> {
61
68
pub struct Crate {
62
69
name : ~str ,
63
70
module : Option < Item > ,
71
+ externs : HashMap < ast:: CrateNum , ExternalCrate > ,
64
72
}
65
73
66
74
impl Clean < Crate > for visit_ast:: RustdocVisitor {
67
75
fn clean ( & self ) -> Crate {
68
76
use syntax:: attr:: { find_linkage_metas, last_meta_item_value_str_by_name} ;
69
- let maybe_meta = last_meta_item_value_str_by_name ( find_linkage_metas ( self . attrs ) , "name" ) ;
77
+ let maybe_meta = last_meta_item_value_str_by_name (
78
+ find_linkage_metas ( self . attrs ) , "name" ) ;
79
+ let cx = local_data:: get ( super :: ctxtkey, |x| * x. unwrap ( ) ) ;
80
+
81
+ let mut externs = HashMap :: new ( ) ;
82
+ do cstore:: iter_crate_data ( cx. sess . cstore ) |n, meta| {
83
+ externs. insert ( n, meta. clean ( ) ) ;
84
+ }
70
85
71
86
Crate {
72
87
name : match maybe_meta {
73
88
Some ( x) => x. to_owned ( ) ,
74
- None => fail2 ! ( "rustdoc_ng requires a \\ #[link(name=\" foo\" )] crate attribute" ) ,
89
+ None => fail2 ! ( "rustdoc requires a \\ #[link(name=\" foo\" )] \
90
+ crate attribute") ,
75
91
} ,
76
92
module : Some ( self . module . clean ( ) ) ,
93
+ externs : externs,
94
+ }
95
+ }
96
+ }
97
+
98
+ #[ deriving( Clone , Encodable , Decodable ) ]
99
+ pub struct ExternalCrate {
100
+ name : ~str ,
101
+ attrs : ~[ Attribute ] ,
102
+ }
103
+
104
+ impl Clean < ExternalCrate > for cstore:: crate_metadata {
105
+ fn clean ( & self ) -> ExternalCrate {
106
+ ExternalCrate {
107
+ name : self . name . to_owned ( ) ,
108
+ attrs : decoder:: get_crate_attributes ( self . data ) . clean ( )
77
109
}
78
110
}
79
111
}
@@ -542,7 +574,15 @@ pub enum Type {
542
574
ResolvedPath {
543
575
path : Path ,
544
576
typarams : Option < ~[ TyParamBound ] > ,
545
- did : ast:: DefId
577
+ id : ast:: NodeId ,
578
+ } ,
579
+ /// Same as above, but only external variants
580
+ ExternalPath {
581
+ path : Path ,
582
+ typarams : Option < ~[ TyParamBound ] > ,
583
+ fqn : ~[ ~str ] ,
584
+ kind : TypeKind ,
585
+ crate : ast : : CrateNum ,
546
586
} ,
547
587
// I have no idea how to usefully use this.
548
588
TyParamBinder ( ast:: NodeId ) ,
@@ -572,6 +612,14 @@ pub enum Type {
572
612
// region, raw, other boxes, mutable
573
613
}
574
614
615
+ #[ deriving( Clone , Encodable , Decodable ) ]
616
+ pub enum TypeKind {
617
+ TypeStruct ,
618
+ TypeEnum ,
619
+ TypeTrait ,
620
+ TypeFunction ,
621
+ }
622
+
575
623
impl Clean < Type > for ast:: Ty {
576
624
fn clean ( & self ) -> Type {
577
625
use syntax:: ast:: * ;
@@ -1099,26 +1147,12 @@ fn name_from_pat(p: &ast::Pat) -> ~str {
1099
1147
}
1100
1148
}
1101
1149
1102
- fn remove_comment_tags ( s : & str ) -> ~str {
1103
- if s. starts_with ( "/" ) {
1104
- match s. slice ( 0 , 3 ) {
1105
- & "///" => return s. slice ( 3 , s. len ( ) ) . trim ( ) . to_owned ( ) ,
1106
- & "/**" | & "/*!" => return s. slice ( 3 , s. len ( ) - 2 ) . trim ( ) . to_owned ( ) ,
1107
- _ => return s. trim ( ) . to_owned ( )
1108
- }
1109
- } else {
1110
- return s. to_owned ( ) ;
1111
- }
1112
- }
1113
-
1114
1150
/// Given a Type, resolve it using the def_map
1115
1151
fn resolve_type ( path : Path , tpbs : Option < ~[ TyParamBound ] > ,
1116
1152
id : ast:: NodeId ) -> Type {
1117
- use syntax:: ast:: * ;
1118
-
1119
- let dm = local_data:: get ( super :: ctxtkey, |x| * x. unwrap ( ) ) . tycx . def_map ;
1153
+ let cx = local_data:: get ( super :: ctxtkey, |x| * x. unwrap ( ) ) ;
1120
1154
debug2 ! ( "searching for {:?} in defmap" , id) ;
1121
- let d = match dm . find ( & id) {
1155
+ let d = match cx . tycx . def_map . find ( & id) {
1122
1156
Some ( k) => k,
1123
1157
None => {
1124
1158
let ctxt = local_data:: get ( super :: ctxtkey, |x| * x. unwrap ( ) ) ;
@@ -1128,28 +1162,41 @@ fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>,
1128
1162
}
1129
1163
} ;
1130
1164
1131
- let def_id = match * d {
1132
- DefFn ( i, _) => i ,
1133
- DefSelf ( i) | DefSelfTy ( i) => return Self ( i) ,
1134
- DefTy ( i) => i ,
1135
- DefTrait ( i) => {
1165
+ let ( def_id, kind ) = match * d {
1166
+ ast :: DefFn ( i, _) => ( i , TypeFunction ) ,
1167
+ ast :: DefSelf ( i) | ast :: DefSelfTy ( i) => return Self ( i) ,
1168
+ ast :: DefTy ( i) => ( i , TypeEnum ) ,
1169
+ ast :: DefTrait ( i) => {
1136
1170
debug2 ! ( "saw DefTrait in def_to_id" ) ;
1137
- i
1171
+ ( i , TypeTrait )
1138
1172
} ,
1139
- DefPrimTy ( p) => match p {
1140
- ty_str => return String ,
1141
- ty_bool => return Bool ,
1173
+ ast :: DefPrimTy ( p) => match p {
1174
+ ast :: ty_str => return String ,
1175
+ ast :: ty_bool => return Bool ,
1142
1176
_ => return Primitive ( p)
1143
1177
} ,
1144
- DefTyParam ( i, _) => return Generic ( i. node ) ,
1145
- DefStruct ( i) => i ,
1146
- DefTyParamBinder ( i) => {
1178
+ ast :: DefTyParam ( i, _) => return Generic ( i. node ) ,
1179
+ ast :: DefStruct ( i) => ( i , TypeStruct ) ,
1180
+ ast :: DefTyParamBinder ( i) => {
1147
1181
debug2 ! ( "found a typaram_binder, what is it? {}" , i) ;
1148
1182
return TyParamBinder ( i) ;
1149
1183
} ,
1150
1184
x => fail2 ! ( "resolved type maps to a weird def {:?}" , x) ,
1151
1185
} ;
1152
- ResolvedPath { path : path, typarams : tpbs, did : def_id }
1186
+ if ast_util:: is_local ( def_id) {
1187
+ ResolvedPath { path : path, typarams : tpbs, id : def_id. node }
1188
+ } else {
1189
+ let fqn = csearch:: get_item_path ( cx. tycx , def_id) ;
1190
+ let fqn = fqn. move_iter ( ) . map ( |i| {
1191
+ match i {
1192
+ ast_map:: path_mod( id) |
1193
+ ast_map:: path_name( id) |
1194
+ ast_map:: path_pretty_name( id, _) => id. clean ( )
1195
+ }
1196
+ } ) . to_owned_vec ( ) ;
1197
+ ExternalPath { path : path, typarams : tpbs, fqn : fqn, kind : kind,
1198
+ crate : def_id. crate }
1199
+ }
1153
1200
}
1154
1201
1155
1202
fn resolve_use_source ( path : Path , id : ast:: NodeId ) -> ImportSource {
0 commit comments