@@ -19,7 +19,8 @@ use metadata::csearch::{ProvidedTraitMethodInfo, StaticMethodInfo};
19
19
use metadata:: csearch;
20
20
use metadata:: cstore;
21
21
use metadata:: decoder;
22
- use metadata:: tydecode:: { parse_ty_data, parse_def_id, parse_bounds_data} ;
22
+ use metadata:: tydecode:: { parse_ty_data, parse_def_id, parse_bounds_data,
23
+ parse_bare_fn_ty_data} ;
23
24
use middle:: { ty, resolve} ;
24
25
25
26
use core:: hash:: HashUtil ;
@@ -229,6 +230,12 @@ fn doc_type(doc: ebml::Doc, tcx: ty::ctxt, cdata: cmd) -> ty::t {
229
230
|_, did| translate_def_id(cdata, did))
230
231
}
231
232
233
+ fn doc_method_fty(doc: ebml::Doc, tcx: ty::ctxt, cdata: cmd) -> ty::BareFnTy {
234
+ let tp = reader::get_doc(doc, tag_item_method_fty);
235
+ parse_bare_fn_ty_data(tp.data, cdata.cnum, tp.start, tcx,
236
+ |_, did| translate_def_id(cdata, did))
237
+ }
238
+
232
239
pub fn item_type(item_id: ast::def_id, item: ebml::Doc,
233
240
tcx: ty::ctxt, cdata: cmd) -> ty::t {
234
241
let t = doc_type(item, tcx, cdata);
@@ -247,10 +254,11 @@ fn item_impl_traits(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd) -> ~[ty::t] {
247
254
results
248
255
}
249
256
250
- fn item_ty_param_bounds(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd)
257
+ fn item_ty_param_bounds(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd,
258
+ tag: uint)
251
259
-> @~[ty::param_bounds] {
252
260
let mut bounds = ~[];
253
- for reader::tagged_docs(item, tag_items_data_item_ty_param_bounds ) |p| {
261
+ for reader::tagged_docs(item, tag ) |p| {
254
262
let bd = parse_bounds_data(p.data, p.start, cdata.cnum, tcx,
255
263
|_, did| translate_def_id(cdata, did));
256
264
bounds.push(bd);
@@ -338,7 +346,8 @@ fn item_to_def_like(item: ebml::Doc, did: ast::def_id, cnum: ast::crate_num)
338
346
let enum_did = item_reqd_and_translated_parent_item(cnum, item);
339
347
dl_def(ast::def_variant(enum_did, did))
340
348
}
341
- Trait | Enum => dl_def(ast::def_ty(did)),
349
+ Trait => dl_def(ast::def_trait(did)),
350
+ Enum => dl_def(ast::def_ty(did)),
342
351
Impl => dl_impl(did),
343
352
PublicField | PrivateField | InheritedField => dl_field,
344
353
}
@@ -359,7 +368,7 @@ pub fn get_type(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
359
368
let t = item_type(ast::def_id { crate: cdata.cnum, node: id }, item, tcx,
360
369
cdata);
361
370
let tp_bounds = if family_has_type_params(item_family(item)) {
362
- item_ty_param_bounds(item, tcx, cdata)
371
+ item_ty_param_bounds(item, tcx, cdata, tag_items_data_item_ty_param_bounds )
363
372
} else { @~[] };
364
373
let rp = item_ty_region_param(item);
365
374
ty::ty_param_bounds_and_ty {
@@ -690,36 +699,46 @@ pub fn get_impls_for_mod(intr: @ident_interner,
690
699
@result
691
700
}
692
701
693
- /* Works for both classes and traits */
694
- pub fn get_trait_methods ( intr : @ident_interner , cdata : cmd , id : ast:: node_id ,
695
- tcx : ty:: ctxt ) -> @~[ ty:: method ] {
702
+ pub fn get_method_name_and_self_ty (
703
+ intr : @ident_interner ,
704
+ cdata : cmd ,
705
+ id : ast:: node_id ) -> ( ast:: ident , ast:: self_ty_ )
706
+ {
707
+ let method_doc = lookup_item ( id, cdata. data ) ;
708
+ let name = item_name ( intr, method_doc) ;
709
+ let self_ty = get_self_ty ( method_doc) ;
710
+ ( name, self_ty)
711
+ }
712
+
713
+ pub fn get_method ( intr : @ident_interner , cdata : cmd , id : ast:: node_id ,
714
+ tcx : ty:: ctxt ) -> ty:: method
715
+ {
716
+ let method_doc = lookup_item ( id, cdata. data ) ;
717
+ let bounds = item_ty_param_bounds ( method_doc, tcx, cdata,
718
+ tag_item_method_tps) ;
719
+ let name = item_name ( intr, method_doc) ;
720
+ let def_id = item_def_id ( method_doc, cdata) ;
721
+ let fty = doc_method_fty ( method_doc, tcx, cdata) ;
722
+ let self_ty = get_self_ty ( method_doc) ;
723
+ ty:: method {
724
+ ident : name,
725
+ tps : bounds,
726
+ fty : fty,
727
+ self_ty : self_ty,
728
+ vis : ast:: public,
729
+ def_id : def_id
730
+ }
731
+ }
732
+
733
+ pub fn get_trait_method_def_ids ( cdata : cmd ,
734
+ id : ast:: node_id ) -> ~[ ast:: def_id ] {
696
735
let data = cdata. data ;
697
736
let item = lookup_item ( id, data) ;
698
737
let mut result = ~[ ] ;
699
738
for reader:: tagged_docs( item, tag_item_trait_method) |mth| {
700
- let bounds = item_ty_param_bounds ( mth, tcx, cdata) ;
701
- let name = item_name ( intr, mth) ;
702
- let ty = doc_type ( mth, tcx, cdata) ;
703
- let def_id = item_def_id ( mth, cdata) ;
704
- let fty = match ty:: get ( ty) . sty {
705
- ty:: ty_bare_fn( ref f) => copy * f,
706
- _ => {
707
- tcx. diag . handler ( ) . bug (
708
- ~"get_trait_methods: id has non-function type") ;
709
- }
710
- } ;
711
- let self_ty = get_self_ty ( mth) ;
712
- result. push ( ty:: method {
713
- ident : name,
714
- tps : bounds,
715
- fty : fty,
716
- self_ty : self_ty,
717
- vis : ast:: public,
718
- def_id : def_id
719
- } ) ;
739
+ result. push ( item_def_id ( mth, cdata) ) ;
720
740
}
721
- debug ! ( "get_trait_methods: }" ) ;
722
- @result
741
+ result
723
742
}
724
743
725
744
pub fn get_provided_trait_methods ( intr : @ident_interner , cdata : cmd ,
@@ -734,7 +753,8 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
734
753
735
754
let did = item_def_id ( mth, cdata) ;
736
755
737
- let bounds = item_ty_param_bounds ( mth, tcx, cdata) ;
756
+ let bounds = item_ty_param_bounds ( mth, tcx, cdata,
757
+ tag_items_data_item_ty_param_bounds) ;
738
758
let name = item_name ( intr, mth) ;
739
759
let ty = doc_type ( mth, tcx, cdata) ;
740
760
@@ -777,26 +797,6 @@ pub fn get_supertraits(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
777
797
return results;
778
798
}
779
799
780
- // If the item in question is a trait, returns its set of methods and
781
- // their self types. Otherwise, returns none. This overlaps in an
782
- // annoying way with get_trait_methods.
783
- pub fn get_method_names_if_trait ( intr : @ident_interner , cdata : cmd ,
784
- node_id : ast:: node_id )
785
- -> Option < ~[ ( ast:: ident , ast:: self_ty_ ) ] > {
786
-
787
- let item = lookup_item ( node_id, cdata. data ) ;
788
- if item_family ( item) != Trait {
789
- return None ;
790
- }
791
-
792
- let mut resulting_methods = ~[ ] ;
793
- for reader:: tagged_docs( item, tag_item_trait_method) |method| {
794
- resulting_methods. push (
795
- ( item_name ( intr, method) , get_self_ty ( method) ) ) ;
796
- }
797
- return Some ( resulting_methods) ;
798
- }
799
-
800
800
pub fn get_type_name_if_impl ( intr : @ident_interner ,
801
801
cdata : cmd ,
802
802
node_id : ast:: node_id ) -> Option < ast:: ident > {
0 commit comments