@@ -36,6 +36,7 @@ import back::abi;
36
36
import back:: upcall;
37
37
38
38
import middle:: ty:: pat_ty;
39
+ import visit:: vt;
39
40
40
41
import util:: common;
41
42
import util:: common:: istr;
@@ -7960,50 +7961,22 @@ fn decl_native_fn_and_pair(&@crate_ctxt ccx,
7960
7961
finish_fn( fcx, lltop) ;
7961
7962
}
7962
7963
7963
- type walk_ctxt = rec( mutable vec[ str] path) ;
7964
- fn new_walk_ctxt( ) -> @walk_ctxt {
7965
- let vec[ str ] path = [ ] ;
7966
- ret @rec( mutable path=path) ;
7967
- }
7968
-
7969
- fn enter_item( @walk_ctxt cx, & @ast:: item item) {
7970
- alt ( item. node) {
7971
- case ( ast:: item_fn( ?name, _, _, _, _) ) {
7972
- vec:: push[ str ] ( cx. path, name) ;
7973
- }
7974
- case ( ast:: item_obj( ?name, _, _, _, _) ) {
7975
- vec:: push[ str ] ( cx. path, name) ;
7976
- }
7977
- case ( ast:: item_mod( ?name, _, _) ) {
7978
- vec:: push[ str ] ( cx. path, name) ;
7979
- }
7980
- case ( _) { }
7981
- }
7982
- }
7983
-
7984
- fn leave_item( @walk_ctxt cx, & @ast:: item item) {
7964
+ fn item_path( & @ast:: item item) -> vec[ str] {
7985
7965
alt ( item. node) {
7986
- case ( ast:: item_fn( _, _, _, _, _) ) {
7987
- vec:: pop[ str ] ( cx. path) ;
7988
- }
7989
- case ( ast:: item_obj( _, _, _, _, _) ) {
7990
- vec:: pop[ str ] ( cx. path) ;
7991
- }
7992
- case ( ast:: item_mod( _, _, _) ) {
7993
- vec:: pop[ str ] ( cx. path) ;
7994
- }
7995
- case ( _) { }
7966
+ case ( ast:: item_fn( ?name, _, _, _, _) ) { ret [ name] ; }
7967
+ case ( ast:: item_obj( ?name, _, _, _, _) ) { ret [ name] ; }
7968
+ case ( ast:: item_mod( ?name, _, _) ) { ret [ name] ; }
7969
+ case ( _) { ret [ ] ; }
7996
7970
}
7997
7971
}
7998
7972
7999
- fn collect_native_item( & @crate_ctxt ccx, @walk_ctxt wcx ,
8000
- & @ast :: native_item i ) {
7973
+ fn collect_native_item( @crate_ctxt ccx, & @ast :: native_item i ,
7974
+ & vec [ str ] pt , & vt [ vec [ str ] ] v ) {
8001
7975
alt ( i. node) {
8002
7976
case ( ast:: native_item_fn( ?name, _, _, _, ?fid, ?ann) ) {
8003
7977
ccx. native_items. insert( fid, i) ;
8004
7978
if ( !ccx. obj_methods. contains_key( fid) ) {
8005
- decl_native_fn_and_pair( ccx, i. span, wcx. path,
8006
- name, ann, fid) ;
7979
+ decl_native_fn_and_pair( ccx, i. span, pt, name, ann, fid) ;
8007
7980
}
8008
7981
}
8009
7982
case ( ast:: native_item_ty( _, ?tid) ) {
@@ -8012,9 +7985,9 @@ fn collect_native_item(&@crate_ctxt ccx, @walk_ctxt wcx,
8012
7985
}
8013
7986
}
8014
7987
8015
- fn collect_item_1( & @crate_ctxt ccx, @walk_ctxt wcx , & @ast:: item i) {
8016
- enter_item ( wcx , i ) ;
8017
-
7988
+ fn collect_item_1( @crate_ctxt ccx, & @ast:: item i,
7989
+ & vec [ str ] pt , & vt [ vec [ str ] ] v ) {
7990
+ visit :: visit_item ( i , pt + item_path ( i ) , v ) ;
8018
7991
alt ( i. node) {
8019
7992
case ( ast:: item_const( ?name, _, _, ?cid, ?ann) ) {
8020
7993
auto typ = node_ann_type( ccx, ann) ;
@@ -8041,19 +8014,20 @@ fn collect_item_1(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item i) {
8041
8014
}
8042
8015
}
8043
8016
8044
- fn collect_item_2( & @crate_ctxt ccx, @walk_ctxt wcx, & @ast:: item i) {
8045
- enter_item( wcx, i) ;
8046
-
8017
+ fn collect_item_2( & @crate_ctxt ccx, & @ast:: item i,
8018
+ & vec[ str ] pt, & vt[ vec[ str ] ] v) {
8019
+ auto new_pt = pt + item_path( i) ;
8020
+ visit:: visit_item( i, new_pt, v) ;
8047
8021
alt ( i. node) {
8048
8022
case ( ast:: item_fn( ?name, ?f, ?tps, ?fid, ?ann) ) {
8049
8023
ccx. items. insert( fid, i) ;
8050
8024
if ( !ccx. obj_methods. contains_key( fid) ) {
8051
- decl_fn_and_pair( ccx, i. span, wcx . path , "fn ", tps, ann, fid) ;
8025
+ decl_fn_and_pair( ccx, i. span, new_pt , "fn ", tps, ann, fid) ;
8052
8026
}
8053
8027
}
8054
8028
case ( ast:: item_obj( ?name, ?ob, ?tps, ?oid, ?ann) ) {
8055
8029
ccx. items. insert( oid. ctor, i) ;
8056
- decl_fn_and_pair( ccx, i. span, wcx . path ,
8030
+ decl_fn_and_pair( ccx, i. span, new_pt ,
8057
8031
"obj_ctor", tps, ann, oid. ctor) ;
8058
8032
for ( @ast:: method m in ob. methods ) {
8059
8033
ccx. obj_methods . insert ( m. node . id , ( ) ) ;
@@ -8064,29 +8038,28 @@ fn collect_item_2(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item i) {
8064
8038
}
8065
8039
8066
8040
fn collect_items( & @crate_ctxt ccx, @ast:: crate crate) {
8067
- auto wcx = new_walk_ctxt ( ) ;
8068
- auto visitor0 = walk:: default_visitor ( ) ;
8069
- auto visitor1 = rec ( visit_native_item_pre =
8070
- bind collect_native_item ( ccx , wcx , _) ,
8071
- visit_item_pre = bind collect_item_1 ( ccx , wcx , _) ,
8072
- visit_item_post = bind leave_item( wcx, _)
8073
- with visitor0 ) ;
8074
- auto visitor2 = rec ( visit_item_pre = bind collect_item_2 ( ccx , wcx , _) ,
8075
- visit_item_post = bind leave_item( wcx, _)
8076
- with visitor0 ) ;
8077
- walk:: walk_crate ( visitor1 , * crate) ;
8078
- walk:: walk_crate ( visitor2 , * crate) ;
8079
- }
8080
-
8081
- fn collect_tag_ctor( & @crate_ctxt ccx, @walk_ctxt wcx, & @ast:: item i) {
8082
- enter_item( wcx, i) ;
8041
+ auto visitor0 = visit:: default_visitor ( ) ;
8042
+ auto visitor1 = @rec ( visit_native_item =
8043
+ bind collect_native_item ( ccx , _, _, _) ,
8044
+ visit_item = bind collect_item_1( ccx, _, _, _)
8045
+ with * visitor0 ) ;
8046
+ auto visitor2 = @rec ( visit_item = bind collect_item_2( ccx, _, _, _)
8047
+ with * visitor0 ) ;
8048
+ visit:: visit_crate ( * crate, [ ] , visit:: vtor ( visitor1 ) ) ;
8049
+ visit:: visit_crate ( * crate, [ ] , visit:: vtor ( visitor2 ) ) ;
8050
+ }
8051
+
8052
+ fn collect_tag_ctor ( @crate_ctxt ccx , & @ast:: item i,
8053
+ & vec[ str] pt , & vt[ vec[ str] ] v ) {
8054
+ auto new_pt = pt + item_path ( i ) ;
8055
+ visit:: visit_item ( i , new_pt , v ) ;
8083
8056
8084
8057
alt ( i. node ) {
8085
8058
case ( ast:: item_tag ( _, ?variants , ?tps , _, _) ) {
8086
8059
for ( ast:: variant variant in variants ) {
8087
8060
if ( vec:: len [ ast:: variant_arg ] ( variant . node. args) != 0 u ) {
8088
8061
decl_fn_and_pair ( ccx , i. span ,
8089
- wcx . path + [ variant. node. name] ,
8062
+ new_pt + [ variant . node. name] ,
8090
8063
"tag" , tps , variant . node. ann,
8091
8064
variant . node. id) ;
8092
8065
}
@@ -8098,17 +8071,17 @@ fn collect_tag_ctor(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item i) {
8098
8071
}
8099
8072
8100
8073
fn collect_tag_ctors ( & @crate_ctxt ccx , @ast:: crate crate) {
8101
- auto wcx = new_walk_ctxt( ) ;
8102
- auto visitor = rec( visit_item_pre = bind collect_tag_ctor( ccx, wcx, _) ,
8103
- visit_item_post = bind leave_item( wcx, _)
8104
- with walk:: default_visitor( ) ) ;
8105
- walk:: walk_crate ( visitor , * crate) ;
8074
+ auto visitor = @rec ( visit_item = bind collect_tag_ctor( ccx, _, _, _)
8075
+ with * visit:: default_visitor ( ) ) ;
8076
+ visit:: visit_crate ( * crate, [ ] , visit:: vtor ( visitor ) ) ;
8106
8077
}
8107
8078
8108
8079
// The constant translation pass.
8109
8080
8110
- fn trans_constant( & @crate_ctxt ccx, @walk_ctxt wcx, & @ast:: item it) {
8111
- enter_item( wcx, it) ;
8081
+ fn trans_constant ( @crate_ctxt ccx , & @ast:: item it,
8082
+ & vec[ str] pt , & vt[ vec[ str] ] v ) {
8083
+ auto new_pt = pt + item_path ( it ) ;
8084
+ visit:: visit_item ( it , new_pt , v ) ;
8112
8085
8113
8086
alt ( it. node ) {
8114
8087
case ( ast:: item_tag ( ?ident , ?variants , _, ?tag_id , _) ) {
@@ -8119,7 +8092,7 @@ fn trans_constant(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item it) {
8119
8092
8120
8093
auto discrim_val = C_int ( i as int ) ;
8121
8094
8122
- auto p = wcx . path + [ ident, variant. node . name , "discrim" ] ;
8095
+ auto p = new_pt + [ ident, variant. node . name , "discrim" ] ;
8123
8096
auto s = mangle_exported_name ( ccx, p, ty:: mk_int ( ccx. tcx ) ) ;
8124
8097
auto discrim_gvar = llvm:: LLVMAddGlobal ( ccx. llmod , T_int ( ) ,
8125
8098
str:: buf ( s) ) ;
@@ -8139,7 +8112,7 @@ fn trans_constant(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item it) {
8139
8112
// with consts.
8140
8113
auto v = C_int ( 1 ) ;
8141
8114
ccx. item_ids . insert ( cid, v) ;
8142
- auto s = mangle_exported_name ( ccx, wcx . path + [ name] ,
8115
+ auto s = mangle_exported_name ( ccx, new_pt + [ name] ,
8143
8116
node_ann_type ( ccx, ann) ) ;
8144
8117
ccx. item_symbols . insert ( cid, s) ;
8145
8118
}
@@ -8149,11 +8122,9 @@ fn trans_constant(&@crate_ctxt ccx, @walk_ctxt wcx, &@ast::item it) {
8149
8122
}
8150
8123
8151
8124
fn trans_constants( & @crate_ctxt ccx, @ast:: crate crate) {
8152
- auto wcx = new_walk_ctxt ( ) ;
8153
- auto visitor = rec ( visit_item_pre = bind trans_constant ( ccx , wcx , _) ,
8154
- visit_item_post = bind leave_item( wcx, _)
8155
- with walk:: default_visitor ( ) ) ;
8156
- walk:: walk_crate ( visitor , * crate) ;
8125
+ auto visitor = @rec ( visit_item = bind trans_constant( ccx, _, _, _)
8126
+ with * visit:: default_visitor ( ) ) ;
8127
+ visit:: visit_crate ( * crate, [ ] , visit:: vtor ( visitor ) ) ;
8157
8128
}
8158
8129
8159
8130
0 commit comments