@@ -6,7 +6,7 @@ import io::writer_util;
6
6
import ebml:: writer;
7
7
import syntax:: ast:: * ;
8
8
import syntax:: print:: pprust;
9
- import syntax:: ast_util;
9
+ import syntax:: { ast_util, visit } ;
10
10
import syntax:: ast_util:: local_def;
11
11
import common:: * ;
12
12
import middle:: trans:: common:: crate_ctxt;
@@ -249,13 +249,13 @@ fn encode_parent_item(ebml_w: ebml::writer, id: def_id) {
249
249
250
250
fn encode_enum_variant_info ( ecx : @encode_ctxt , ebml_w : ebml:: writer ,
251
251
id : node_id , variants : [ variant ] ,
252
- path : ast_map:: path , & index: [ entry < int > ] ,
252
+ path : ast_map:: path , index : @mutable [ entry < int > ] ,
253
253
ty_params : [ ty_param ] ) {
254
254
let disr_val = 0 ;
255
255
let i = 0 ;
256
256
let vi = ty:: enum_variants ( ecx. ccx . tcx , { crate : local_crate, node: id} ) ;
257
257
for variant: variant in variants {
258
- index += [ { val: variant. node . id , pos: ebml_w. writer . tell ( ) } ] ;
258
+ * index += [ { val: variant. node . id , pos: ebml_w. writer . tell ( ) } ] ;
259
259
ebml_w. start_tag ( tag_items_data_item) ;
260
260
encode_def_id ( ebml_w, local_def ( variant. node . id ) ) ;
261
261
encode_family ( ebml_w, 'v' ) ;
@@ -329,7 +329,7 @@ fn purity_fn_family(p: purity) -> char {
329
329
}
330
330
331
331
fn encode_info_for_item ( ecx : @encode_ctxt , ebml_w : ebml:: writer , item: @item,
332
- & index: [ entry < int > ] , path : ast_map:: path ) -> bool {
332
+ index : @mutable [ entry < int > ] , path : ast_map:: path ) {
333
333
334
334
fn should_inline ( attrs : [ attribute ] ) -> bool {
335
335
alt attr:: find_inline_attr ( attrs) {
@@ -340,7 +340,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
340
340
341
341
let tcx = ecx. ccx . tcx ;
342
342
let must_write = alt item. node { item_enum ( _, _) { true } _ { false } } ;
343
- if !must_write && !ecx. reachable . contains_key ( item. id ) { ret false ; }
343
+ if !must_write && !ecx. reachable . contains_key ( item. id ) { ret; }
344
+ * index += [ { val: item. id , pos: ebml_w. writer . tell ( ) } ] ;
344
345
345
346
alt item. node {
346
347
item_const ( _, _) {
@@ -419,7 +420,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
419
420
encode_path ( ebml_w, path, ast_map:: path_name ( item. ident ) ) ;
420
421
ebml_w. end_tag ( ) ;
421
422
422
- index += [ { val: ctor_id, pos: ebml_w. writer . tell ( ) } ] ;
423
+ * index += [ { val: ctor_id, pos: ebml_w. writer . tell ( ) } ] ;
423
424
ebml_w. start_tag ( tag_items_data_item) ;
424
425
encode_def_id ( ebml_w, local_def ( ctor_id) ) ;
425
426
encode_family ( ebml_w, 'f' ) ;
@@ -457,7 +458,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
457
458
458
459
let impl_path = path + [ ast_map:: path_name ( item. ident ) ] ;
459
460
for m in methods {
460
- index += [ { val: m. id , pos: ebml_w. writer . tell ( ) } ] ;
461
+ * index += [ { val: m. id , pos: ebml_w. writer . tell ( ) } ] ;
461
462
ebml_w. start_tag ( tag_items_data_item) ;
462
463
encode_def_id ( ebml_w, local_def ( m. id ) ) ;
463
464
encode_family ( ebml_w, purity_fn_family ( m. decl . purity ) ) ;
@@ -496,13 +497,15 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
496
497
ebml_w. end_tag ( ) ;
497
498
}
498
499
}
499
- ret true;
500
500
}
501
501
502
502
fn encode_info_for_native_item ( ecx : @encode_ctxt , ebml_w : ebml:: writer ,
503
- nitem : @native_item , path : ast_map:: path )
504
- -> bool {
505
- if !ecx. reachable . contains_key ( nitem. id ) { ret false ; }
503
+ nitem : @native_item ,
504
+ index : @mutable [ entry < int > ] ,
505
+ path : ast_map:: path ) {
506
+ if !ecx. reachable . contains_key ( nitem. id ) { ret; }
507
+ * index += [ { val: nitem. id , pos: ebml_w. writer . tell ( ) } ] ;
508
+
506
509
ebml_w. start_tag ( tag_items_data_item) ;
507
510
alt nitem. node {
508
511
native_item_fn ( fn_decl, tps) {
@@ -515,30 +518,35 @@ fn encode_info_for_native_item(ecx: @encode_ctxt, ebml_w: ebml::writer,
515
518
}
516
519
}
517
520
ebml_w. end_tag ( ) ;
518
- ret true;
519
521
}
520
522
521
523
fn encode_info_for_items ( ecx : @encode_ctxt , ebml_w : ebml:: writer ,
522
- crate_mod : _mod ) -> [ entry < int > ] {
523
- let index: [ entry < int > ] = [ ] ;
524
+ crate : @ crate ) -> [ entry < int > ] {
525
+ let index = @mutable [ ] ;
524
526
ebml_w. start_tag ( tag_items_data) ;
525
- index += [ { val: crate_node_id, pos: ebml_w. writer . tell ( ) } ] ;
526
- encode_info_for_mod ( ecx, ebml_w, crate_mod, crate_node_id, [ ] , "" ) ;
527
- ecx. ccx . tcx . items . items { |key, val|
528
- let where = ebml_w. writer . tell ( ) ;
529
- let written = alt val {
530
- middle : : ast_map:: node_item ( i, path) if i. id == key {
531
- encode_info_for_item ( ecx, ebml_w, i, index, * path)
532
- }
533
- middle:: ast_map:: node_native_item ( i, _, path) {
534
- encode_info_for_native_item ( ecx, ebml_w, i, * path)
535
- }
536
- _ { false }
537
- } ;
538
- if written { index += [ { val: key, pos: where } ] ; }
539
- } ;
527
+ * index += [ { val: crate_node_id, pos: ebml_w. writer . tell ( ) } ] ;
528
+ encode_info_for_mod ( ecx, ebml_w, crate . node. module ,
529
+ crate_node_id, [ ] , "" ) ;
530
+ visit:: visit_crate ( * crate , ( ) , visit:: mk_vt ( @{
531
+ visit_expr : { |_e, _cx, _v|} ,
532
+ visit_item: { |i, cx, v|
533
+ visit:: visit_item ( i, cx, v) ;
534
+ let path = alt check ecx. ccx . tcx . items . get ( i. id ) {
535
+ ast_map:: node_item ( _, pt) { pt }
536
+ } ;
537
+ encode_info_for_item( ecx, ebml_w, i, index, * path) ;
538
+ } ,
539
+ visit_native_item : { |ni, cx, v |
540
+ visit:: visit_native_item ( ni, cx, v) ;
541
+ let path = alt check ecx. ccx . tcx . items . get ( ni. id ) {
542
+ ast_map:: node_native_item ( _, _, pt) { pt }
543
+ } ;
544
+ encode_info_for_native_item ( ecx, ebml_w, ni, index, * path) ;
545
+ }
546
+ with * visit:: default_visitor ( )
547
+ } ) ) ;
540
548
ebml_w. end_tag ( ) ;
541
- ret index;
549
+ ret * index;
542
550
}
543
551
544
552
@@ -765,7 +773,7 @@ fn encode_metadata(cx: @crate_ctxt, crate: @crate) -> [u8] {
765
773
766
774
// Encode and index the items.
767
775
ebml_w. start_tag ( tag_items) ;
768
- let items_index = encode_info_for_items ( ecx, ebml_w, crate . node . module ) ;
776
+ let items_index = encode_info_for_items ( ecx, ebml_w, crate ) ;
769
777
let items_buckets = create_index ( items_index, hash_node_id) ;
770
778
encode_index ( ebml_w, items_buckets, write_int) ;
771
779
ebml_w. end_tag ( ) ;
0 commit comments