1
1
// Metadata encoding
2
2
3
+ import util:: ppaux:: ty_to_str;
4
+
3
5
import std:: { ebml, map, list} ;
4
6
import std:: map:: hashmap;
5
7
import io:: writer_util;
@@ -197,6 +199,12 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
197
199
}
198
200
}
199
201
202
+ fn encode_iface_ref( ebml_w: ebml:: writer, ecx: @encode_ctxt, t: @iface_ref) {
203
+ ebml_w. start_tag( tag_impl_iface) ;
204
+ encode_type( ecx, ebml_w, node_id_to_type( ecx. ccx. tcx, t. id) ) ;
205
+ ebml_w. end_tag( ) ;
206
+ }
207
+
200
208
fn encode_item_paths( ebml_w: ebml:: writer, ecx: @encode_ctxt, crate : @crate )
201
209
-> [ entry < str > ] {
202
210
let mut index: [ entry < str > ] = [ ] ;
@@ -361,12 +369,52 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod,
361
369
list:: cons( impls, @list:: nil) {
362
370
for vec:: each( * impls) { |i|
363
371
if ast_util:: is_exported( i. ident, md) {
364
- ebml_w. wr_tagged_str( tag_mod_impl, def_to_str( i. did) ) ;
365
- }
366
- }
372
+ ebml_w. start_tag( tag_mod_impl) ;
373
+ /* If did stands for an iface
374
+ ref, we need to map it to its parent class */
375
+ ebml_w. start_tag( tag_mod_impl_use) ;
376
+ let iface_ty = alt ecx. ccx. tcx. items. get( i. did. node) {
377
+ ast_map:: node_item( it @@{ node : cl@item_class( * ) , _} , _) {
378
+ ebml_w. wr_str( def_to_str( local_def( it. id) ) ) ;
379
+ some( ty:: lookup_item_type( ecx. ccx. tcx, i. did) . ty)
380
+ }
381
+ ast_map:: node_item( @{ node: item_impl( _, _,
382
+ some( ifce) , _, _) , _} , _) {
383
+ ebml_w. wr_str( def_to_str( i. did) ) ;
384
+ some( ty:: node_id_to_type( ecx. ccx. tcx, ifce. id) )
385
+ }
386
+ _ {
387
+ ebml_w. wr_str( def_to_str( i. did) ) ; none
388
+ }
389
+ } ;
390
+ ebml_w. end_tag( ) ;
391
+
392
+ /*
393
+ /* Write the iface did if it exists */
394
+ option::iter(iface_ty) {|i|
395
+ alt ty::get(i).struct {
396
+ ty::ty_iface(did, tys) {
397
+ // FIXME: tys?
398
+ ebml_w.start_tag(tag_mod_impl_iface);
399
+ ebml_w.wr_str(def_to_str(did));
400
+ ebml_w.end_tag();
401
+
402
+ }
403
+ t {
404
+ ecx.ccx.tcx.sess.bug(#fmt("Expected item to implement \
405
+ an iface, but found %s",
406
+ util::ppaux::ty_to_str(ecx.ccx.tcx, i)));
407
+ }
408
+ }}
409
+ */
410
+ ebml_w. end_tag( ) ;
411
+ } // if
412
+ } // for
413
+ } // list::cons alt
414
+ _ {
415
+ ecx. ccx. tcx. sess. bug( #fmt( "encode_info_for_mod: empty impl_map \
416
+ entry for %?", path) ) ;
367
417
}
368
- _ { ecx. ccx. tcx. sess. bug( #fmt( "encode_info_for_mod: empty impl_map \
369
- entry for %?", path) ) ; }
370
418
}
371
419
encode_path( ebml_w, path, ast_map:: path_mod( name) ) ;
372
420
ebml_w. end_tag( ) ;
@@ -571,7 +619,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
571
619
encode_enum_variant_info( ecx, ebml_w, item. id, variants,
572
620
path, index, tps) ;
573
621
}
574
- item_class( tps, _ifaces , items, ctor, rp) {
622
+ item_class( tps, ifaces , items, ctor, rp) {
575
623
/* First, encode the fields and methods
576
624
These come first because we need to write them to make
577
625
the index, and the index needs to be in the item for the
@@ -589,7 +637,9 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
589
637
encode_name( ebml_w, item. ident) ;
590
638
encode_path( ebml_w, path, ast_map:: path_name( item. ident) ) ;
591
639
encode_region_param( ebml_w, rp) ;
592
- /* FIXME: encode ifaces */
640
+ for ifaces. each { |t|
641
+ encode_iface_ref( ebml_w, ecx, t) ;
642
+ }
593
643
/* Encode def_ids for each field and method
594
644
for methods, write all the stuff get_iface_method
595
645
needs to know*/
@@ -605,14 +655,21 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
605
655
alt m. privacy {
606
656
priv { /* do nothing */ }
607
657
pub {
608
- ebml_w. start_tag( tag_item_method) ;
609
- #debug( "Writing %s %d" , m. ident, m. id) ;
658
+ /* Write the info that's needed when viewing this class
659
+ as an iface */
660
+ ebml_w. start_tag( tag_item_iface_method) ;
610
661
encode_family( ebml_w, purity_fn_family( m. decl. purity) ) ;
611
662
encode_name( ebml_w, m. ident) ;
612
663
encode_type_param_bounds( ebml_w, ecx, tps + m. tps) ;
613
664
encode_type( ecx, ebml_w, node_id_to_type( tcx, m. id) ) ;
614
665
encode_def_id( ebml_w, local_def( m. id) ) ;
615
666
ebml_w. end_tag( ) ;
667
+ /* Write the info that's needed when viewing this class
668
+ as an impl (just the method def_id) */
669
+ ebml_w. start_tag( tag_item_impl_method) ;
670
+ ebml_w. writer. write( str:: bytes( def_to_str( local_def( m. id) ) ) ) ;
671
+ ebml_w. end_tag( ) ;
672
+
616
673
}
617
674
}
618
675
}
@@ -659,19 +716,13 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
659
716
encode_type( ecx, ebml_w, node_id_to_type( tcx, item. id) ) ;
660
717
encode_name( ebml_w, item. ident) ;
661
718
for methods. each { |m|
662
- ebml_w. start_tag( tag_item_method ) ;
719
+ ebml_w. start_tag( tag_item_impl_method ) ;
663
720
ebml_w. writer. write( str:: bytes( def_to_str( local_def( m. id) ) ) ) ;
664
721
ebml_w. end_tag( ) ;
665
722
}
666
- alt ifce {
667
- some( t) {
668
- let i_ty = ty:: node_id_to_type( tcx, t. id) ;
669
- ebml_w. start_tag( tag_impl_iface) ;
670
- write_type( ecx, ebml_w, i_ty) ;
671
- ebml_w. end_tag( ) ;
672
- }
673
- _ { }
674
- }
723
+ option:: iter( ifce) { |t|
724
+ encode_iface_ref( ebml_w, ecx, t)
725
+ } ;
675
726
encode_path( ebml_w, path, ast_map:: path_name( item. ident) ) ;
676
727
ebml_w. end_tag( ) ;
677
728
@@ -693,7 +744,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
693
744
encode_name( ebml_w, item. ident) ;
694
745
let mut i = 0 u;
695
746
for vec:: each( * ty:: iface_methods( tcx, local_def( item. id) ) ) { |mty|
696
- ebml_w. start_tag( tag_item_method ) ;
747
+ ebml_w. start_tag( tag_item_iface_method ) ;
697
748
encode_name( ebml_w, mty. ident) ;
698
749
encode_type_param_bounds( ebml_w, ecx, ms[ i] . tps) ;
699
750
encode_type( ecx, ebml_w, ty:: mk_fn( tcx, mty. fty) ) ;
0 commit comments