@@ -14,8 +14,10 @@ export get_symbol;
14
14
export get_tag_variants;
15
15
export get_type;
16
16
export get_type_param_count;
17
+ export get_impl_iface;
17
18
export lookup_def;
18
19
export lookup_item_name;
20
+ export get_impl_iface;
19
21
export resolve_path;
20
22
export get_crate_attributes;
21
23
export list_crate_metadata;
@@ -24,7 +26,7 @@ export get_crate_deps;
24
26
export get_crate_hash;
25
27
export external_resolver;
26
28
export get_impls_for_mod;
27
- export lookup_impl_methods ;
29
+ export get_iface_methods ;
28
30
// A function that takes a def_id relative to the crate being searched and
29
31
// returns a def_id relative to the compilation environment, i.e. if we hit a
30
32
// def_id for an item defined in another crate, somebody needs to figure out
@@ -103,16 +105,42 @@ fn parse_external_def_id(this_cnum: ast::crate_num,
103
105
} else { ret extres ( external_def_id) ; }
104
106
}
105
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
+
106
115
fn item_type ( item : ebml:: doc , this_cnum : ast:: crate_num , tcx : ty:: ctxt ,
107
116
extres : external_resolver ) -> ty:: t {
108
- let tp = ebml:: get_doc ( item, tag_items_data_item_type) ;
109
- let def_parser = bind parse_external_def_id ( this_cnum, extres, _) ;
110
- let t = parse_ty_data ( item. data , this_cnum, tp. start , tp. end - tp. start ,
111
- def_parser, tcx) ;
117
+ let t = doc_type ( item, this_cnum, tcx, extres) ;
112
118
if family_names_type ( item_family ( item) ) {
113
- t = ty:: mk_named ( tcx, t, @item_name ( item) ) ;
119
+ ty:: mk_named ( tcx, t, @item_name ( item) )
120
+ } else { t }
121
+ }
122
+
123
+ fn item_impl_iface ( item : ebml:: doc , this_cnum : ast:: crate_num , tcx : ty:: ctxt ,
124
+ extres : external_resolver ) -> option:: t < ty:: t > {
125
+ let result = none;
126
+ ebml:: tagged_docs ( item, tag_impl_iface) { |ity|
127
+ let def_parser = bind parse_external_def_id ( this_cnum, extres, _) ;
128
+ let t = parse_ty_data ( ity. data , this_cnum, ity. start , def_parser,
129
+ tcx) ;
130
+ result = some ( t) ;
131
+ }
132
+ result
133
+ }
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) ) ;
114
142
}
115
- t
143
+ result
116
144
}
117
145
118
146
fn item_ty_param_bounds ( item : ebml:: doc , this_cnum : ast:: crate_num ,
@@ -121,8 +149,8 @@ fn item_ty_param_bounds(item: ebml::doc, this_cnum: ast::crate_num,
121
149
let bounds = [ ] ;
122
150
let def_parser = bind parse_external_def_id ( this_cnum, extres, _) ;
123
151
ebml:: tagged_docs ( item, tag_items_data_item_ty_param_bounds) { |p|
124
- bounds += [ tydecode:: parse_bounds_data ( @ebml :: doc_data ( p ) , this_cnum ,
125
- def_parser, tcx) ] ;
152
+ bounds += [ tydecode:: parse_bounds_data ( p . data , p . start ,
153
+ this_cnum , def_parser, tcx) ] ;
126
154
}
127
155
@bounds
128
156
}
@@ -197,18 +225,17 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
197
225
tid = { crate : cnum, node: tid. node } ;
198
226
ast:: def_variant ( tid, did)
199
227
}
228
+ 'I' { ast:: def_ty ( did) }
200
229
} ;
201
230
ret def;
202
231
}
203
232
204
233
fn get_type ( data : @[ u8 ] , def : ast:: def_id , tcx : ty:: ctxt ,
205
234
extres : external_resolver ) -> ty:: ty_param_bounds_and_ty {
206
- let this_cnum = def. crate ;
207
- let node_id = def. node ;
208
- let item = lookup_item ( node_id, data) ;
209
- 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) ;
210
237
let tp_bounds = if family_has_type_params ( item_family ( item) ) {
211
- item_ty_param_bounds ( item, this_cnum , tcx, extres)
238
+ item_ty_param_bounds ( item, def . crate , tcx, extres)
212
239
} else { @[ ] } ;
213
240
ret { bounds : tp_bounds, ty : t} ;
214
241
}
@@ -217,6 +244,11 @@ fn get_type_param_count(data: @[u8], id: ast::node_id) -> uint {
217
244
item_ty_param_count ( lookup_item ( id, data) )
218
245
}
219
246
247
+ fn get_impl_iface ( data : @[ u8 ] , def : ast:: def_id , tcx : ty:: ctxt ,
248
+ extres : external_resolver ) -> option:: t < ty:: t > {
249
+ item_impl_iface ( lookup_item ( def. node , data) , def. crate , tcx, extres)
250
+ }
251
+
220
252
fn get_symbol ( data : @[ u8 ] , id : ast:: node_id ) -> str {
221
253
ret item_symbol ( lookup_item ( id, data) ) ;
222
254
}
@@ -245,52 +277,59 @@ fn get_tag_variants(_data: @[u8], def: ast::def_id, tcx: ty::ctxt,
245
277
ret infos;
246
278
}
247
279
248
- fn get_impls_for_mod ( data : @[ u8 ] , node : ast:: node_id , cnum : ast:: crate_num )
249
- -> [ ast:: def_id ] {
250
- let mod_item = lookup_item ( node, data) , result = [ ] ;
251
- ebml:: tagged_docs ( mod_item, tag_mod_impl) { |doc|
252
- let did = parse_def_id ( ebml:: doc_data ( doc) ) ;
253
- result += [ { crate : cnum with did} ] ;
254
- }
255
- result
256
- }
257
-
258
- 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 )
259
281
-> [ @middle:: resolve:: method_info ] {
260
- let impl_item = lookup_item ( node, data) , rslt = [ ] ;
261
- let base_tps = item_ty_param_count ( impl_item) ;
262
- ebml:: tagged_docs ( impl_item, tag_impl_method) { |doc|
282
+ let rslt = [ ] ;
283
+ ebml:: tagged_docs ( item, tag_item_method) { |doc|
263
284
let m_did = parse_def_id ( ebml:: doc_data ( doc) ) ;
264
285
let mth_item = lookup_item ( m_did. node , data) ;
265
- rslt += [ @{ did : { crate : cnum , node : m_did. node } ,
286
+ rslt += [ @{ did: m_did,
266
287
n_tps: item_ty_param_count ( mth_item) - base_tps,
267
288
ident: item_name ( mth_item) } ] ;
268
289
}
269
290
rslt
270
291
}
271
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
+ }
272
323
273
324
fn family_has_type_params ( fam_ch : u8 ) -> bool {
274
- ret alt fam_ch as char {
275
- 'c' { false }
276
- 'f' { true }
277
- 'u' { true }
278
- 'p' { true }
279
- 'F' { true }
280
- 'U' { true }
281
- 'P' { true }
282
- 'y' { true }
283
- 't' { true }
284
- 'T' { false }
285
- 'm' { false }
286
- 'n' { false }
287
- 'v' { true }
288
- 'i' { true }
289
- } ;
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
+ }
290
329
}
291
330
292
331
fn family_names_type ( fam_ch : u8 ) -> bool {
293
- alt fam_ch as char { 'y' | 't' { true } _ { false } }
332
+ alt fam_ch as char { 'y' | 't' | 'I' { true } _ { false } }
294
333
}
295
334
296
335
fn read_path ( d : ebml:: doc ) -> { path: str , pos: uint} {
@@ -321,6 +360,8 @@ fn item_family_to_str(fam: u8) -> str {
321
360
'm' { ret "mod" ; }
322
361
'n' { ret "native mod" ; }
323
362
'v' { ret "tag" ; }
363
+ 'i' { ret "impl" ; }
364
+ 'I' { ret "iface" ; }
324
365
}
325
366
}
326
367
0 commit comments