@@ -26,7 +26,7 @@ export get_crate_deps;
26
26
export get_crate_hash;
27
27
export external_resolver;
28
28
export get_impls_for_mod;
29
- export lookup_impl_methods ;
29
+ export get_iface_methods ;
30
30
// A function that takes a def_id relative to the crate being searched and
31
31
// returns a def_id relative to the compilation environment, i.e. if we hit a
32
32
// def_id for an item defined in another crate, somebody needs to figure out
@@ -105,38 +105,52 @@ fn parse_external_def_id(this_cnum: ast::crate_num,
105
105
} else { ret extres ( external_def_id) ; }
106
106
}
107
107
108
+ fn doc_type ( doc : ebml:: doc , this_cnum : ast:: crate_num , tcx : ty:: ctxt ,
109
+ extres : external_resolver ) -> ty:: t {
110
+ let tp = ebml:: get_doc ( doc, tag_items_data_item_type) ;
111
+ let def_parser = bind parse_external_def_id ( this_cnum, extres, _) ;
112
+ parse_ty_data ( tp. data , this_cnum, tp. start , def_parser, tcx)
113
+ }
114
+
108
115
fn item_type ( item : ebml:: doc , this_cnum : ast:: crate_num , tcx : ty:: ctxt ,
109
116
extres : external_resolver ) -> ty:: t {
110
- let tp = ebml:: get_doc ( item, tag_items_data_item_type) ;
111
- let def_parser = bind parse_external_def_id ( this_cnum, extres, _) ;
112
- let t = parse_ty_data ( item. data , this_cnum, tp. start , tp. end - tp. start ,
113
- def_parser, tcx) ;
117
+ let t = doc_type ( item, this_cnum, tcx, extres) ;
114
118
if family_names_type ( item_family ( item) ) {
115
- t = ty:: mk_named ( tcx, t, @item_name ( item) ) ;
116
- }
117
- t
119
+ ty:: mk_named ( tcx, t, @item_name ( item) )
120
+ } else { t }
118
121
}
119
122
120
123
fn item_impl_iface ( item : ebml:: doc , this_cnum : ast:: crate_num , tcx : ty:: ctxt ,
121
124
extres : external_resolver ) -> option:: t < ty:: t > {
122
125
let result = none;
123
126
ebml:: tagged_docs ( item, tag_impl_iface) { |ity|
124
127
let def_parser = bind parse_external_def_id ( this_cnum, extres, _) ;
125
- let t = parse_ty_data ( ity. data , this_cnum, ity. start ,
126
- ity . end - ity . start , def_parser , tcx) ;
128
+ let t = parse_ty_data ( ity. data , this_cnum, ity. start , def_parser ,
129
+ tcx) ;
127
130
result = some ( t) ;
128
131
}
129
132
result
130
133
}
131
134
135
+ fn item_impl_iface_did ( item : ebml:: doc , this_cnum : ast:: crate_num ,
136
+ extres : external_resolver )
137
+ -> option:: t < ast:: def_id > {
138
+ let result = none;
139
+ ebml:: tagged_docs ( item, tag_impl_iface_did) { |doc|
140
+ let s = str:: unsafe_from_bytes ( ebml:: doc_data ( doc) ) ;
141
+ result = some ( parse_external_def_id ( this_cnum, extres, s) ) ;
142
+ }
143
+ result
144
+ }
145
+
132
146
fn item_ty_param_bounds ( item : ebml:: doc , this_cnum : ast:: crate_num ,
133
147
tcx : ty:: ctxt , extres : external_resolver )
134
148
-> @[ ty:: param_bounds ] {
135
149
let bounds = [ ] ;
136
150
let def_parser = bind parse_external_def_id ( this_cnum, extres, _) ;
137
151
ebml:: tagged_docs ( item, tag_items_data_item_ty_param_bounds) { |p|
138
- bounds += [ tydecode:: parse_bounds_data ( @ebml :: doc_data ( p ) , this_cnum ,
139
- def_parser, tcx) ] ;
152
+ bounds += [ tydecode:: parse_bounds_data ( p . data , p . start ,
153
+ this_cnum , def_parser, tcx) ] ;
140
154
}
141
155
@bounds
142
156
}
@@ -211,18 +225,17 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
211
225
tid = { crate : cnum, node: tid. node } ;
212
226
ast:: def_variant ( tid, did)
213
227
}
228
+ 'I' { ast:: def_ty ( did) }
214
229
} ;
215
230
ret def;
216
231
}
217
232
218
233
fn get_type ( data : @[ u8 ] , def : ast:: def_id , tcx : ty:: ctxt ,
219
234
extres : external_resolver ) -> ty:: ty_param_bounds_and_ty {
220
- let this_cnum = def. crate ;
221
- let node_id = def. node ;
222
- let item = lookup_item ( node_id, data) ;
223
- let t = item_type ( item, this_cnum, tcx, extres) ;
235
+ let item = lookup_item ( def. node , data) ;
236
+ let t = item_type ( item, def. crate , tcx, extres) ;
224
237
let tp_bounds = if family_has_type_params ( item_family ( item) ) {
225
- item_ty_param_bounds ( item, this_cnum , tcx, extres)
238
+ item_ty_param_bounds ( item, def . crate , tcx, extres)
226
239
} else { @[ ] } ;
227
240
ret { bounds : tp_bounds, ty : t} ;
228
241
}
@@ -264,51 +277,59 @@ fn get_tag_variants(_data: @[u8], def: ast::def_id, tcx: ty::ctxt,
264
277
ret infos;
265
278
}
266
279
267
- fn get_impls_for_mod ( data : @[ u8 ] , node : ast:: node_id , cnum : ast:: crate_num )
268
- -> [ ast:: def_id ] {
269
- let mod_item = lookup_item ( node, data) , result = [ ] ;
270
- ebml:: tagged_docs ( mod_item, tag_mod_impl) { |doc|
271
- let did = parse_def_id ( ebml:: doc_data ( doc) ) ;
272
- result += [ { crate : cnum with did} ] ;
273
- }
274
- result
275
- }
276
-
277
- fn lookup_impl_methods ( data : @[ u8 ] , node : ast:: node_id , cnum : ast:: crate_num )
280
+ fn item_impl_methods ( data : @[ u8 ] , item : ebml:: doc , base_tps : uint )
278
281
-> [ @middle:: resolve:: method_info ] {
279
- let impl_item = lookup_item ( node, data) , rslt = [ ] ;
280
- let base_tps = item_ty_param_count ( impl_item) ;
281
- ebml:: tagged_docs ( impl_item, tag_impl_method) { |doc|
282
+ let rslt = [ ] ;
283
+ ebml:: tagged_docs ( item, tag_item_method) { |doc|
282
284
let m_did = parse_def_id ( ebml:: doc_data ( doc) ) ;
283
285
let mth_item = lookup_item ( m_did. node , data) ;
284
- rslt += [ @{ did : { crate : cnum , node : m_did. node } ,
286
+ rslt += [ @{ did: m_did,
285
287
n_tps: item_ty_param_count ( mth_item) - base_tps,
286
288
ident: item_name ( mth_item) } ] ;
287
289
}
288
290
rslt
289
291
}
290
292
293
+ fn get_impls_for_mod ( data : @[ u8 ] , m_def : ast:: def_id ,
294
+ name : option:: t < ast:: ident > , extres : external_resolver )
295
+ -> @[ @middle:: resolve:: _impl ] {
296
+ let mod_item = lookup_item ( m_def. node , data) , result = [ ] ;
297
+ ebml:: tagged_docs ( mod_item, tag_mod_impl) { |doc|
298
+ let did = parse_external_def_id (
299
+ m_def. crate , extres, str:: unsafe_from_bytes ( ebml:: doc_data ( doc) ) ) ;
300
+ let item = lookup_item ( did. node , data) , nm = item_name ( item) ;
301
+ if alt name { some ( n) { n == nm } none. { true } } {
302
+ let base_tps = item_ty_param_count ( doc) ;
303
+ let i_did = item_impl_iface_did ( item, m_def. crate , extres) ;
304
+ result += [ @{ did: did, iface_did: i_did, ident: nm,
305
+ methods: item_impl_methods ( data, doc, base_tps) } ] ;
306
+ }
307
+ }
308
+ @result
309
+ }
310
+
311
+ fn get_iface_methods ( data : @[ u8 ] , def : ast:: def_id , tcx : ty:: ctxt ,
312
+ extres : external_resolver ) -> @[ ty:: method ] {
313
+ let item = lookup_item ( def. node , data) , result = [ ] ;
314
+ ebml:: tagged_docs ( item, tag_item_method) { |mth|
315
+ let bounds = item_ty_param_bounds ( mth, def. crate , tcx, extres) ;
316
+ let name = item_name ( mth) ;
317
+ let ty = doc_type ( mth, def. crate , tcx, extres) ;
318
+ let fty = alt ty:: struct ( tcx, ty) { ty:: ty_fn ( f) { f } } ;
319
+ result += [ { ident: name, tps: bounds, fty: fty} ] ;
320
+ }
321
+ @result
322
+ }
323
+
291
324
fn family_has_type_params ( fam_ch : u8 ) -> bool {
292
- ret alt fam_ch as char {
293
- 'c' { false }
294
- 'f' { true }
295
- 'u' { true }
296
- 'p' { true }
297
- 'F' { true }
298
- 'U' { true }
299
- 'P' { true }
300
- 'y' { true }
301
- 't' { true }
302
- 'T' { false }
303
- 'm' { false }
304
- 'n' { false }
305
- 'v' { true }
306
- 'i' { true }
307
- } ;
325
+ alt fam_ch as char {
326
+ 'c' | 'T' | 'm' | 'n' { false }
327
+ 'f' | 'u' | 'p' | 'F' | 'U' | 'P' | 'y' | 't' | 'v' | 'i' | 'I' { true }
328
+ }
308
329
}
309
330
310
331
fn family_names_type ( fam_ch : u8 ) -> bool {
311
- alt fam_ch as char { 'y' | 't' { true } _ { false } }
332
+ alt fam_ch as char { 'y' | 't' | 'I' { true } _ { false } }
312
333
}
313
334
314
335
fn read_path ( d : ebml:: doc ) -> { path: str , pos: uint} {
@@ -339,6 +360,8 @@ fn item_family_to_str(fam: u8) -> str {
339
360
'm' { ret "mod" ; }
340
361
'n' { ret "native mod" ; }
341
362
'v' { ret "tag" ; }
363
+ 'i' { ret "impl" ; }
364
+ 'I' { ret "iface" ; }
342
365
}
343
366
}
344
367
0 commit comments