@@ -63,37 +63,32 @@ export translate_def_id;
63
63
// what crate that's in and give us a def_id that makes sense for the current
64
64
// build.
65
65
66
- fn lookup_hash ( d : ebml:: doc , eq_fn : fn @ ( x : & [ u8 ] ) -> bool , hash : uint ) ->
67
- ~ [ ebml:: doc ] {
66
+ fn lookup_hash ( d : ebml:: doc , eq_fn : fn ( x : & [ u8 ] ) -> bool , hash : uint ) ->
67
+ option < ebml:: doc > {
68
68
let index = ebml:: get_doc ( d, tag_index) ;
69
69
let table = ebml:: get_doc ( index, tag_index_table) ;
70
70
let hash_pos = table. start + hash % 256 u * 4 u;
71
71
let pos = io:: u64_from_be_bytes ( * d. data , hash_pos, 4 u) as uint ;
72
72
let { tag: _ , doc : bucket } = ebml:: doc_at ( d. data , pos) ;
73
- // Awkward logic because we can't ret from foreach yet
74
73
75
- let mut result: ~[ ebml:: doc ] = ~[ ] ;
76
74
let belt = tag_index_buckets_bucket_elt;
77
- do ebml:: tagged_docs ( bucket, belt) |elt| {
75
+ for ebml:: tagged_docs( bucket, belt) |elt| {
78
76
let pos = io:: u64_from_be_bytes ( * elt. data , elt. start , 4 u) as uint ;
79
- // FIXME (#2880): use view here.
80
- if eq_fn ( vec:: slice :: < u8 > ( * elt. data , elt. start + 4 u, elt. end ) ) {
81
- vec:: push ( result, ebml:: doc_at ( d. data , pos) . doc ) ;
77
+ if eq_fn ( vec:: slice ( * elt. data , elt. start + 4 u, elt. end ) ) {
78
+ ret some ( ebml:: doc_at ( d. data , pos) . doc ) ;
82
79
}
83
80
} ;
84
- ret result ;
81
+ none
85
82
}
86
83
87
84
fn maybe_find_item ( item_id : int , items : ebml:: doc ) -> option < ebml:: doc > {
88
85
fn eq_item ( bytes : & [ u8 ] , item_id : int ) -> bool {
89
86
ret io:: u64_from_be_bytes ( vec:: slice ( bytes, 0 u, 4 u) , 0 u, 4 u) as int
90
87
== item_id;
91
88
}
92
- let eqer = |a| eq_item ( a, item_id) ;
93
- let found = lookup_hash ( items, eqer, hash_node_id ( item_id) ) ;
94
- if vec:: len ( found) == 0 u {
95
- ret option:: none :: < ebml:: doc > ;
96
- } else { ret option:: some :: < ebml:: doc > ( found[ 0 ] ) ; }
89
+ lookup_hash ( items,
90
+ |a| eq_item ( a, item_id) ,
91
+ hash_node_id ( item_id) )
97
92
}
98
93
99
94
fn find_item ( item_id : int , items : ebml:: doc ) -> ebml:: doc {
@@ -121,11 +116,10 @@ fn item_symbol(item: ebml::doc) -> ~str {
121
116
}
122
117
123
118
fn item_parent_item ( d : ebml:: doc ) -> option < ast:: def_id > {
124
- let mut found = none;
125
- do ebml:: tagged_docs ( d, tag_items_data_parent_item) |did| {
126
- found = some ( ebml:: with_doc_data ( did, |d| parse_def_id ( d) ) ) ;
119
+ for ebml:: tagged_docs( d, tag_items_data_parent_item) |did| {
120
+ ret some( ebml:: with_doc_data( did, |d| parse_def_id( d) ) ) ;
127
121
}
128
- found
122
+ none
129
123
}
130
124
131
125
// XXX: This has nothing to do with classes.
@@ -171,7 +165,7 @@ fn item_type(item_id: ast::def_id, item: ebml::doc,
171
165
172
166
fn item_impl_traits ( item : ebml:: doc , tcx : ty:: ctxt , cdata : cmd ) -> ~[ ty:: t ] {
173
167
let mut results = ~[ ] ;
174
- do ebml:: tagged_docs ( item, tag_impl_trait) |ity| {
168
+ for ebml:: tagged_docs( item, tag_impl_trait) |ity| {
175
169
vec:: push( results, doc_type( ity, tcx, cdata) ) ;
176
170
} ;
177
171
results
@@ -180,7 +174,7 @@ fn item_impl_traits(item: ebml::doc, tcx: ty::ctxt, cdata: cmd) -> ~[ty::t] {
180
174
fn item_ty_param_bounds ( item : ebml:: doc , tcx : ty:: ctxt , cdata : cmd )
181
175
-> @~[ ty:: param_bounds ] {
182
176
let mut bounds = ~[ ] ;
183
- do ebml:: tagged_docs ( item, tag_items_data_item_ty_param_bounds) |p| {
177
+ for ebml:: tagged_docs( item, tag_items_data_item_ty_param_bounds) |p| {
184
178
let bd = parse_bounds_data ( p. data , p. start , cdata. cnum , tcx, |did| {
185
179
translate_def_id ( cdata, did)
186
180
} ) ;
@@ -199,14 +193,14 @@ fn item_ty_region_param(item: ebml::doc) -> bool {
199
193
fn item_ty_param_count ( item : ebml:: doc ) -> uint {
200
194
let mut n = 0 u;
201
195
ebml:: tagged_docs ( item, tag_items_data_item_ty_param_bounds,
202
- |_p| n += 1 u ) ;
196
+ |_p| { n += 1 u; true } ) ;
203
197
n
204
198
}
205
199
206
200
fn enum_variant_ids ( item : ebml:: doc , cdata : cmd ) -> ~[ ast:: def_id ] {
207
201
let mut ids: ~[ ast:: def_id ] = ~[ ] ;
208
202
let v = tag_items_data_item_variant;
209
- do ebml:: tagged_docs ( item, v) |p| {
203
+ for ebml:: tagged_docs( item, v) |p| {
210
204
let ext = ebml:: with_doc_data ( p, |d| parse_def_id ( d) ) ;
211
205
vec:: push ( ids, { crate : cdata. cnum , node: ext. node } ) ;
212
206
} ;
@@ -254,7 +248,7 @@ fn item_path(item_doc: ebml::doc) -> ast_map::path {
254
248
let mut result = ~[ ] ;
255
249
vec:: reserve ( result, len) ;
256
250
257
- do ebml:: docs ( path_doc) |tag, elt_doc| {
251
+ for ebml:: docs( path_doc) |tag, elt_doc| {
258
252
if tag == tag_path_elt_mod {
259
253
let str = ebml:: doc_as_str ( elt_doc) ;
260
254
vec:: push ( result, ast_map:: path_mod ( @str) ) ;
@@ -342,7 +336,7 @@ fn get_impl_method(cdata: cmd, id: ast::node_id,
342
336
name : ast:: ident ) -> ast:: def_id {
343
337
let items = ebml:: get_doc ( ebml:: doc ( cdata. data ) , tag_items) ;
344
338
let mut found = none;
345
- do ebml:: tagged_docs ( find_item ( id, items) , tag_item_impl_method) |mid| {
339
+ for ebml:: tagged_docs( find_item( id, items) , tag_item_impl_method) |mid| {
346
340
let m_did = ebml:: with_doc_data ( mid, |d| parse_def_id ( d) ) ;
347
341
if item_name ( find_item ( m_did. node , items) ) == name {
348
342
found = some ( translate_def_id ( cdata, m_did) ) ;
@@ -359,7 +353,7 @@ fn get_class_method(cdata: cmd, id: ast::node_id,
359
353
some ( it) { it }
360
354
none { fail ( #fmt ( "get_class_method: class id not found \
361
355
when looking up method %s", * name) ) } } ;
362
- do ebml:: tagged_docs ( cls_items, tag_item_trait_method) |mid| {
356
+ for ebml:: tagged_docs( cls_items, tag_item_trait_method) |mid| {
363
357
let m_did = class_member_id ( mid, cdata) ;
364
358
if item_name ( mid) == name {
365
359
found = some ( m_did) ;
@@ -379,7 +373,7 @@ fn class_dtor(cdata: cmd, id: ast::node_id) -> option<ast::def_id> {
379
373
none { fail ( #fmt ( "class_dtor: class id not found \
380
374
when looking up dtor for %d", id) ) ; }
381
375
} ;
382
- do ebml:: tagged_docs ( cls_items, tag_item_dtor) |doc| {
376
+ for ebml:: tagged_docs( cls_items, tag_item_dtor) |doc| {
383
377
let doc1 = ebml:: get_doc ( doc, tag_def_id) ;
384
378
let did = ebml:: with_doc_data ( doc1, |d| parse_def_id ( d) ) ;
385
379
found = some ( translate_def_id ( cdata, did) ) ;
@@ -428,7 +422,7 @@ fn each_path(cdata: cmd, f: fn(path_entry) -> bool) {
428
422
let mut broken = false ;
429
423
430
424
// First, go through all the explicit items.
431
- do ebml:: tagged_docs ( items_data, tag_items_data_item) |item_doc| {
425
+ for ebml:: tagged_docs( items_data, tag_items_data_item) |item_doc| {
432
426
if !broken {
433
427
let name = ast_map:: path_to_str_with_sep ( item_path ( item_doc) ,
434
428
~":: ") ;
@@ -494,11 +488,11 @@ fn each_path(cdata: cmd, f: fn(path_entry) -> bool) {
494
488
}
495
489
}
496
490
497
- do ebml:: tagged_docs ( inner_paths, tag_paths_data_item) |path_doc| {
491
+ for ebml:: tagged_docs( inner_paths, tag_paths_data_item) |path_doc| {
498
492
g( cdata, items, path_doc, broken, f) ;
499
493
}
500
494
501
- do ebml:: tagged_docs ( inner_paths, tag_paths_foreign_path) |path_doc| {
495
+ for ebml:: tagged_docs( inner_paths, tag_paths_foreign_path) |path_doc| {
502
496
g( cdata, items, path_doc, broken, f) ;
503
497
}
504
498
}
@@ -577,7 +571,7 @@ type _impl = {did: ast::def_id, ident: ast::ident, methods: ~[@method_info]};
577
571
fn item_impl_methods ( cdata : cmd , item : ebml:: doc , base_tps : uint )
578
572
-> ~[ @method_info ] {
579
573
let mut rslt = ~[ ] ;
580
- do ebml:: tagged_docs ( item, tag_item_impl_method) |doc| {
574
+ for ebml:: tagged_docs( item, tag_item_impl_method) |doc| {
581
575
let m_did = ebml:: with_doc_data ( doc, |d| parse_def_id ( d) ) ;
582
576
let mth_item = lookup_item ( m_did. node , cdata. data ) ;
583
577
vec:: push ( rslt, @{ did: translate_def_id ( cdata, m_did) ,
@@ -597,7 +591,7 @@ fn get_impls_for_mod(cdata: cmd,
597
591
let data = cdata. data ;
598
592
let mod_item = lookup_item ( m_id, data) ;
599
593
let mut result = ~[ ] ;
600
- do ebml:: tagged_docs ( mod_item, tag_mod_impl) |doc| {
594
+ for ebml:: tagged_docs( mod_item, tag_mod_impl) |doc| {
601
595
let did = ebml:: with_doc_data ( doc, |d| parse_def_id ( d) ) ;
602
596
let local_did = translate_def_id ( cdata, did) ;
603
597
#debug ( "(get impls for mod) getting did %? for '%?'" ,
@@ -625,7 +619,7 @@ fn get_trait_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
625
619
let data = cdata. data ;
626
620
let item = lookup_item ( id, data) ;
627
621
let mut result = ~[ ] ;
628
- do ebml:: tagged_docs ( item, tag_item_trait_method) |mth| {
622
+ for ebml:: tagged_docs( item, tag_item_trait_method) |mth| {
629
623
let bounds = item_ty_param_bounds ( mth, tcx, cdata) ;
630
624
let name = item_name ( mth) ;
631
625
let ty = doc_type ( mth, tcx, cdata) ;
@@ -655,7 +649,7 @@ fn get_method_names_if_trait(cdata: cmd, node_id: ast::node_id)
655
649
}
656
650
657
651
let resulting_method_names = @dvec ( ) ;
658
- do ebml:: tagged_docs ( item, tag_item_trait_method) |method| {
652
+ for ebml:: tagged_docs( item, tag_item_trait_method) |method| {
659
653
( * resulting_method_names) . push ( item_name ( method) ) ;
660
654
}
661
655
ret some( resulting_method_names) ;
@@ -666,8 +660,8 @@ fn get_item_attrs(cdata: cmd,
666
660
f : fn ( ~[ @ast:: meta_item ] ) ) {
667
661
668
662
let item = lookup_item ( node_id, cdata. data ) ;
669
- do ebml:: tagged_docs ( item, tag_attributes) |attributes| {
670
- do ebml:: tagged_docs ( attributes, tag_attribute) |attribute| {
663
+ for ebml:: tagged_docs( item, tag_attributes) |attributes| {
664
+ for ebml:: tagged_docs( attributes, tag_attribute) |attribute| {
671
665
f( get_meta_items( attribute) ) ;
672
666
}
673
667
}
@@ -679,7 +673,7 @@ fn get_class_members(cdata: cmd, id: ast::node_id,
679
673
let data = cdata. data ;
680
674
let item = lookup_item ( id, data) ;
681
675
let mut result = ~[ ] ;
682
- do ebml:: tagged_docs ( item, tag_item_field) |an_item| {
676
+ for ebml:: tagged_docs( item, tag_item_field) |an_item| {
683
677
let f = item_family ( an_item) ;
684
678
if p ( f) {
685
679
let name = item_name ( an_item) ;
@@ -760,12 +754,12 @@ fn item_family_to_str(fam: char) -> ~str {
760
754
761
755
fn get_meta_items ( md : ebml:: doc ) -> ~[ @ast:: meta_item ] {
762
756
let mut items: ~[ @ast:: meta_item ] = ~[ ] ;
763
- do ebml:: tagged_docs ( md, tag_meta_item_word) |meta_item_doc| {
757
+ for ebml:: tagged_docs( md, tag_meta_item_word) |meta_item_doc| {
764
758
let nd = ebml:: get_doc ( meta_item_doc, tag_meta_item_name) ;
765
759
let n = str:: from_bytes ( ebml:: doc_data ( nd) ) ;
766
760
vec:: push ( items, attr:: mk_word_item ( @n) ) ;
767
761
} ;
768
- do ebml:: tagged_docs ( md, tag_meta_item_name_value) |meta_item_doc| {
762
+ for ebml:: tagged_docs( md, tag_meta_item_name_value) |meta_item_doc| {
769
763
let nd = ebml:: get_doc ( meta_item_doc, tag_meta_item_name) ;
770
764
let vd = ebml:: get_doc ( meta_item_doc, tag_meta_item_value) ;
771
765
let n = str:: from_bytes ( ebml:: doc_data ( nd) ) ;
@@ -774,7 +768,7 @@ fn get_meta_items(md: ebml::doc) -> ~[@ast::meta_item] {
774
768
// but currently the encoder just drops them
775
769
vec:: push ( items, attr:: mk_name_value_item_str ( @n, v) ) ;
776
770
} ;
777
- do ebml:: tagged_docs ( md, tag_meta_item_list) |meta_item_doc| {
771
+ for ebml:: tagged_docs( md, tag_meta_item_list) |meta_item_doc| {
778
772
let nd = ebml:: get_doc ( meta_item_doc, tag_meta_item_name) ;
779
773
let n = str:: from_bytes ( ebml:: doc_data ( nd) ) ;
780
774
let subitems = get_meta_items ( meta_item_doc) ;
@@ -787,7 +781,7 @@ fn get_attributes(md: ebml::doc) -> ~[ast::attribute] {
787
781
let mut attrs: ~[ ast:: attribute ] = ~[ ] ;
788
782
alt ebml:: maybe_get_doc ( md, tag_attributes) {
789
783
option:: some ( attrs_d) {
790
- do ebml:: tagged_docs ( attrs_d, tag_attribute) |attr_doc| {
784
+ for ebml:: tagged_docs( attrs_d, tag_attribute) |attr_doc| {
791
785
let meta_items = get_meta_items ( attr_doc) ;
792
786
// Currently it's only possible to have a single meta item on
793
787
// an attribute
@@ -835,7 +829,7 @@ fn get_crate_deps(data: @~[u8]) -> ~[crate_dep] {
835
829
fn docstr ( doc : ebml:: doc , tag_ : uint ) -> ~str {
836
830
str:: from_bytes ( ebml:: doc_data ( ebml:: get_doc ( doc, tag_) ) )
837
831
}
838
- do ebml:: tagged_docs ( depsdoc, tag_crate_dep) |depdoc| {
832
+ for ebml:: tagged_docs( depsdoc, tag_crate_dep) |depdoc| {
839
833
vec:: push( deps, { cnum: crate_num,
840
834
name: @docstr( depdoc, tag_crate_dep_name) ,
841
835
vers: @docstr( depdoc, tag_crate_dep_vers) ,
@@ -889,9 +883,9 @@ fn iter_crate_items(bytes: @~[u8], proc: fn(uint, ~str, ast::def_id)) {
889
883
let paths = ebml:: get_doc ( md, tag_paths) ;
890
884
let index = ebml:: get_doc ( paths, tag_index) ;
891
885
let bs = ebml:: get_doc ( index, tag_index_buckets) ;
892
- do ebml:: tagged_docs ( bs, tag_index_buckets_bucket) |bucket| {
886
+ for ebml:: tagged_docs( bs, tag_index_buckets_bucket) |bucket| {
893
887
let et = tag_index_buckets_bucket_elt;
894
- do ebml:: tagged_docs ( bucket, et) |elt| {
888
+ for ebml:: tagged_docs( bucket, et) |elt| {
895
889
let data = read_path ( elt) ;
896
890
let { tag: t , doc : def } = ebml:: doc_at ( bytes, data. pos ) ;
897
891
let did_doc = ebml:: get_doc ( def, tag_def_id) ;
0 commit comments