@@ -46,6 +46,7 @@ use syntax::ast_map;
4646use syntax:: ast_util:: * ;
4747use syntax:: attr;
4848use syntax:: diagnostic:: span_handler;
49+ use syntax:: parse:: token:: special_idents;
4950use syntax:: print:: pprust;
5051use syntax:: { ast_util, visit} ;
5152use syntax;
@@ -328,7 +329,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Encoder,
328329 // Encode info about all the module children.
329330 for md. items. each |item| {
330331 match item. node {
331- item_impl( * ) | item_struct ( * ) => {
332+ item_impl( * ) => {
332333 let ( ident, did) = ( item. ident , item. id ) ;
333334 debug ! ( "(encoding info for module) ... encoding impl %s \
334335 (%?/%?)",
@@ -432,25 +433,28 @@ fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Encoder,
432433 /* We encode both private and public fields -- need to include
433434 private fields to get the offsets right */
434435 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 ( ) ;
454458 }
455459 /*bad*/ copy * index
456460}
@@ -481,6 +485,28 @@ fn encode_info_for_ctor(ecx: @encode_ctxt, ebml_w: writer::Encoder,
481485 ebml_w. end_tag ( ) ;
482486}
483487
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+
484510fn encode_info_for_method ( ecx : @encode_ctxt ,
485511 ebml_w : writer:: Encoder ,
486512 impl_path : & [ ast_map:: path_elt ] ,
@@ -674,6 +700,24 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
674700 encode_family(ebml_w, 'S');
675701 encode_type_param_bounds(ebml_w, ecx, tps);
676702 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+
677721 encode_name(ecx, ebml_w, item.ident);
678722 encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
679723 encode_region_param(ecx, ebml_w, item);
@@ -697,7 +741,11 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Encoder,
697741 encode_def_id(ebml_w, local_def(f.node.id));
698742 ebml_w.end_tag();
699743 }
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+ }
701749 }
702750 }
703751
0 commit comments