@@ -6586,6 +6586,10 @@ fn decl_native_fn_and_pair(@crate_ctxt ccx,
6586
6586
}
6587
6587
6588
6588
type walk_ctxt = rec( mutable vec[ str] path) ;
6589
+ fn new_walk_ctxt( ) -> @walk_ctxt {
6590
+ let vec[ str ] path = vec( ) ;
6591
+ ret @rec( mutable path=path) ;
6592
+ }
6589
6593
6590
6594
fn enter_item( @walk_ctxt cx, @ast. item item) {
6591
6595
alt ( item. node) {
@@ -6679,9 +6683,7 @@ fn collect_item_2(@crate_ctxt ccx, @walk_ctxt wcx, @ast.item i) {
6679
6683
}
6680
6684
6681
6685
fn collect_items ( @crate_ctxt ccx , @ast. crate crate) {
6682
- let vec[ str] path = vec ( ) ;
6683
- auto wcx = @rec ( mutable path=path) ;
6684
-
6686
+ auto wcx = new_walk_ctxt ( ) ;
6685
6687
auto visitor0 = walk. default_visitor ( ) ;
6686
6688
auto visitor1 = rec ( visit_native_item_pre =
6687
6689
bind collect_native_item ( ccx, wcx, _) ,
@@ -6695,14 +6697,14 @@ fn collect_items(@crate_ctxt ccx, @ast.crate crate) {
6695
6697
walk. walk_crate ( visitor2, * crate ) ;
6696
6698
}
6697
6699
6698
- fn collect_tag_ctor ( & @local_ctxt cx , @ast. item i ) -> @local_ctxt {
6700
+ fn collect_tag_ctor ( @crate_ctxt ccx , @walk_ctxt wcx , @ast. item i ) {
6701
+ enter_item ( wcx, i) ;
6699
6702
6700
6703
alt ( i. node ) {
6701
-
6702
6704
case ( ast. item_tag ( _, ?variants, ?tps, _, _) ) {
6703
6705
for ( ast. variant variant in variants) {
6704
6706
if ( _vec. len [ ast. variant_arg ] ( variant. node . args ) != 0 u) {
6705
- decl_fn_and_pair ( cx . ccx , cx . path + vec ( variant. node . name ) ,
6707
+ decl_fn_and_pair ( ccx, wcx . path + vec ( variant. node . name ) ,
6706
6708
"tag" , tps, variant. node . ann ,
6707
6709
variant. node . id ) ;
6708
6710
}
@@ -6711,23 +6713,21 @@ fn collect_tag_ctor(&@local_ctxt cx, @ast.item i) -> @local_ctxt {
6711
6713
6712
6714
case ( _) { /* fall through */ }
6713
6715
}
6714
- ret cx;
6715
6716
}
6716
6717
6717
- fn collect_tag_ctors ( @local_ctxt cx , @ast. crate crate) {
6718
-
6719
- let fold. ast_fold[ @local_ctxt] fld =
6720
- fold. new_identity_fold [ @local_ctxt] ( ) ;
6721
-
6722
- fld = @rec ( update_env_for_item = bind collect_tag_ctor ( _, _)
6723
- with * fld ) ;
6724
-
6725
- fold. fold_crate [ @local_ctxt] ( cx, fld, crate ) ;
6718
+ fn collect_tag_ctors ( @crate_ctxt ccx , @ast. crate crate) {
6719
+ auto wcx = new_walk_ctxt ( ) ;
6720
+ auto visitor = rec ( visit_item_pre = bind collect_tag_ctor ( ccx, wcx, _) ,
6721
+ visit_item_post = bind leave_item ( wcx, _)
6722
+ with walk. default_visitor ( ) ) ;
6723
+ walk. walk_crate ( visitor, * crate ) ;
6726
6724
}
6727
6725
6728
6726
// The constant translation pass.
6729
6727
6730
- fn trans_constant ( & @local_ctxt cx , @ast. item it ) -> @local_ctxt {
6728
+ fn trans_constant ( @crate_ctxt ccx , @walk_ctxt wcx , @ast. item it ) {
6729
+ enter_item ( wcx, it) ;
6730
+
6731
6731
alt ( it. node ) {
6732
6732
case ( ast. item_tag ( ?ident, ?variants, _, ?tag_id, _) ) {
6733
6733
auto i = 0 u;
@@ -6737,17 +6737,17 @@ fn trans_constant(&@local_ctxt cx, @ast.item it) -> @local_ctxt {
6737
6737
6738
6738
auto discrim_val = C_int ( i as int ) ;
6739
6739
6740
- auto s = mangle_name_by_seq ( cx . ccx , cx . path ,
6740
+ auto s = mangle_name_by_seq ( ccx, wcx . path ,
6741
6741
#fmt ( "_rust_tag_discrim_%s_%u" ,
6742
6742
ident, i) ) ;
6743
- auto discrim_gvar = llvm. LLVMAddGlobal ( cx . ccx . llmod , T_int ( ) ,
6743
+ auto discrim_gvar = llvm. LLVMAddGlobal ( ccx. llmod , T_int ( ) ,
6744
6744
_str. buf ( s) ) ;
6745
6745
6746
6746
llvm. LLVMSetInitializer ( discrim_gvar, discrim_val) ;
6747
6747
llvm. LLVMSetGlobalConstant ( discrim_gvar, True ) ;
6748
6748
6749
- cx . ccx . discrims . insert ( variant. node . id , discrim_gvar) ;
6750
- cx . ccx . discrim_symbols . insert ( variant. node . id , s) ;
6749
+ ccx. discrims . insert ( variant. node . id , discrim_gvar) ;
6750
+ ccx. discrim_symbols . insert ( variant. node . id , s) ;
6751
6751
6752
6752
i += 1 u;
6753
6753
}
@@ -6757,27 +6757,22 @@ fn trans_constant(&@local_ctxt cx, @ast.item it) -> @local_ctxt {
6757
6757
// FIXME: The whole expr-translation system needs cloning to deal
6758
6758
// with consts.
6759
6759
auto v = C_int ( 1 ) ;
6760
- cx . ccx . item_ids . insert ( cid, v) ;
6761
- auto s = mangle_name_by_type ( cx . ccx , cx . path + vec ( name) ,
6762
- node_ann_type ( cx . ccx , ann) ) ;
6763
- cx . ccx . item_symbols . insert ( cid, s) ;
6760
+ ccx. item_ids . insert ( cid, v) ;
6761
+ auto s = mangle_name_by_type ( ccx, wcx . path + vec ( name) ,
6762
+ node_ann_type ( ccx, ann) ) ;
6763
+ ccx. item_symbols . insert ( cid, s) ;
6764
6764
}
6765
6765
6766
- case ( _) {
6767
- // empty
6768
- }
6766
+ case ( _) { }
6769
6767
}
6770
-
6771
- ret cx;
6772
6768
}
6773
6769
6774
- fn trans_constants ( @local_ctxt cx , @ast. crate crate) {
6775
- let fold. ast_fold[ @local_ctxt] fld =
6776
- fold. new_identity_fold [ @local_ctxt] ( ) ;
6777
-
6778
- fld = @rec ( update_env_for_item = bind trans_constant ( _, _) with * fld) ;
6779
-
6780
- fold. fold_crate [ @local_ctxt] ( cx, fld, crate ) ;
6770
+ fn trans_constants ( @crate_ctxt ccx , @ast. crate crate) {
6771
+ auto wcx = new_walk_ctxt ( ) ;
6772
+ auto visitor = rec ( visit_item_pre = bind trans_constant ( ccx, wcx, _) ,
6773
+ visit_item_post = bind leave_item ( wcx, _)
6774
+ with walk. default_visitor ( ) ) ;
6775
+ walk. walk_crate ( visitor, * crate ) ;
6781
6776
}
6782
6777
6783
6778
@@ -7517,8 +7512,8 @@ fn trans_crate(session.session sess, @ast.crate crate,
7517
7512
create_typedefs ( ccx) ;
7518
7513
7519
7514
collect_items ( ccx, crate ) ;
7520
- collect_tag_ctors ( cx , crate ) ;
7521
- trans_constants ( cx , crate ) ;
7515
+ collect_tag_ctors ( ccx , crate ) ;
7516
+ trans_constants ( ccx , crate ) ;
7522
7517
trans_mod ( cx, crate . node. module ) ;
7523
7518
trans_vec_append_glue ( cx) ;
7524
7519
auto crate_map = create_crate_map ( ccx) ;
0 commit comments