@@ -46,6 +46,7 @@ use syntax::ast_map;
46
46
use syntax:: ast_util:: * ;
47
47
use syntax:: attr;
48
48
use syntax:: diagnostic:: span_handler;
49
+ use syntax:: parse:: token:: special_idents;
49
50
use syntax:: print:: pprust;
50
51
use syntax:: { ast_util, visit} ;
51
52
use syntax;
@@ -328,7 +329,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder,
328
329
// Encode info about all the module children.
329
330
for md. items. each |item| {
330
331
match item. node {
331
- item_impl( * ) | item_struct ( * ) => {
332
+ item_impl( * ) => {
332
333
let ( ident, did) = ( item. ident , item. id ) ;
333
334
debug ! ( "(encoding info for module) ... encoding impl %s \
334
335
(%?/%?)",
@@ -432,25 +433,28 @@ fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Encoder,
432
433
/* We encode both private and public fields -- need to include
433
434
private fields to get the offsets right */
434
435
for fields. each |field| {
435
- match field. node . kind {
436
- named_field( nm, mt, vis) => {
437
- let id = field. node . id ;
438
- index. push ( { val: id, pos: ebml_w. writer . tell ( ) } ) ;
439
- global_index. push ( { val: id,
440
- pos: ebml_w. writer . tell ( ) } ) ;
441
- ebml_w. start_tag ( tag_items_data_item) ;
442
- debug ! ( "encode_info_for_struct: doing %s %d" ,
443
- tcx. sess. str_of( nm) , id) ;
444
- encode_visibility ( ebml_w, vis) ;
445
- encode_name ( ecx, ebml_w, nm) ;
446
- encode_path ( ecx, ebml_w, path, ast_map:: path_name ( nm) ) ;
447
- encode_type ( ecx, ebml_w, node_id_to_type ( tcx, id) ) ;
448
- encode_mutability ( ebml_w, mt) ;
449
- encode_def_id ( ebml_w, local_def ( id) ) ;
450
- ebml_w. end_tag ( ) ;
451
- }
452
- unnamed_field => { }
453
- }
436
+ let ( nm, mt, vis) = match field. node . kind {
437
+ named_field( nm, mt, vis) => ( nm, mt, vis) ,
438
+ unnamed_field => (
439
+ special_idents:: unnamed_field,
440
+ struct_immutable,
441
+ inherited
442
+ )
443
+ } ;
444
+
445
+ let id = field. node . id ;
446
+ index. push ( { val: id, pos: ebml_w. writer . tell ( ) } ) ;
447
+ global_index. push ( { val: id, pos: ebml_w. writer . tell ( ) } ) ;
448
+ ebml_w. start_tag ( tag_items_data_item) ;
449
+ debug ! ( "encode_info_for_struct: doing %s %d" ,
450
+ tcx. sess. str_of( nm) , id) ;
451
+ encode_visibility ( ebml_w, vis) ;
452
+ encode_name ( ecx, ebml_w, nm) ;
453
+ encode_path ( ecx, ebml_w, path, ast_map:: path_name ( nm) ) ;
454
+ encode_type ( ecx, ebml_w, node_id_to_type ( tcx, id) ) ;
455
+ encode_mutability ( ebml_w, mt) ;
456
+ encode_def_id ( ebml_w, local_def ( id) ) ;
457
+ ebml_w. end_tag ( ) ;
454
458
}
455
459
/*bad*/ copy * index
456
460
}
@@ -481,6 +485,28 @@ fn encode_info_for_ctor(ecx: @encode_ctxt, ebml_w: writer::Encoder,
481
485
ebml_w. end_tag ( ) ;
482
486
}
483
487
488
+ fn encode_info_for_struct_ctor ( ecx : @encode_ctxt ,
489
+ ebml_w : writer:: Encoder ,
490
+ path : & [ ast_map:: path_elt ] ,
491
+ name : ast:: ident ,
492
+ ctor_id : node_id ,
493
+ index : @mut ~[ entry < int > ] ) {
494
+ index. push ( { val: ctor_id, pos: ebml_w. writer . tell ( ) } ) ;
495
+
496
+ ebml_w. start_tag ( tag_items_data_item) ;
497
+ encode_def_id ( ebml_w, local_def ( ctor_id) ) ;
498
+ encode_family ( ebml_w, 'f' ) ;
499
+ encode_name ( ecx, ebml_w, name) ;
500
+ encode_type ( ecx, ebml_w, node_id_to_type ( ecx. tcx , ctor_id) ) ;
501
+ encode_path ( ecx, ebml_w, path, ast_map:: path_name ( name) ) ;
502
+
503
+ if ecx. item_symbols . contains_key ( & ctor_id) {
504
+ encode_symbol ( ecx, ebml_w, ctor_id) ;
505
+ }
506
+
507
+ ebml_w. end_tag ( ) ;
508
+ }
509
+
484
510
fn encode_info_for_method ( ecx : @encode_ctxt ,
485
511
ebml_w : writer:: Encoder ,
486
512
impl_path : & [ ast_map:: path_elt ] ,
@@ -674,6 +700,24 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
674
700
encode_family(ebml_w, 'S');
675
701
encode_type_param_bounds(ebml_w, ecx, tps);
676
702
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
703
+
704
+ // If this is a tuple- or enum-like struct, encode the type of the
705
+ // constructor.
706
+ if struct_def.fields.len() > 0 &&
707
+ struct_def.fields[0].node.kind == ast::unnamed_field {
708
+ let ctor_id = match struct_def.ctor_id {
709
+ Some(ctor_id) => ctor_id,
710
+ None => ecx.tcx.sess.bug(~" struct def didn' t have ctor id"),
711
+ };
712
+
713
+ encode_info_for_struct_ctor(ecx,
714
+ ebml_w,
715
+ path,
716
+ item.ident,
717
+ ctor_id,
718
+ index);
719
+ }
720
+
677
721
encode_name(ecx, ebml_w, item.ident);
678
722
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
679
723
encode_region_param(ecx, ebml_w, item);
@@ -697,7 +741,11 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
697
741
encode_def_id(ebml_w, local_def(f.node.id));
698
742
ebml_w.end_tag();
699
743
}
700
- unnamed_field => {}
744
+ unnamed_field => {
745
+ ebml_w.start_tag(tag_item_unnamed_field);
746
+ encode_def_id(ebml_w, local_def(f.node.id));
747
+ ebml_w.end_tag();
748
+ }
701
749
}
702
750
}
703
751
0 commit comments