@@ -15,9 +15,9 @@ use syntax::ast::{Crate, NodeId, item, item_fn};
15
15
use syntax:: ast_map;
16
16
use syntax:: attr;
17
17
use syntax:: codemap:: span;
18
- use syntax:: oldvisit:: { default_visitor, mk_vt, vt, Visitor , visit_crate} ;
19
- use syntax:: oldvisit:: { visit_item} ;
20
18
use syntax:: parse:: token:: special_idents;
19
+ use syntax:: visit:: Visitor ;
20
+ use syntax:: visit;
21
21
use std:: util;
22
22
23
23
struct EntryContext {
@@ -39,8 +39,6 @@ struct EntryContext {
39
39
non_main_fns : ~[ ( NodeId , span ) ] ,
40
40
}
41
41
42
- type EntryVisitor = vt < @mut EntryContext > ;
43
-
44
42
pub fn find_entry_point ( session : Session , crate : & Crate , ast_map : ast_map:: map ) {
45
43
46
44
// FIXME #4404 android JNI hacks
@@ -56,75 +54,72 @@ pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::map)
56
54
return
57
55
}
58
56
59
- let ctxt = @ mut EntryContext {
57
+ let mut ctxt = EntryContext {
60
58
session : session,
61
59
ast_map : ast_map,
62
60
main_fn : None ,
63
61
attr_main_fn : None ,
64
62
start_fn : None ,
65
63
non_main_fns : ~[ ] ,
66
64
} ;
67
-
68
- visit_crate ( crate , ( ctxt, mk_vt ( @Visitor {
69
- visit_item : |item, ( ctxt, visitor) | find_item ( item, ctxt, visitor) ,
70
- .. * default_visitor ( )
71
- } ) ) ) ;
72
-
73
- configure_main ( ctxt) ;
65
+ visit:: walk_crate ( & mut ctxt, crate , ( ) ) ;
66
+ configure_main ( & mut ctxt) ;
74
67
}
75
68
76
- fn find_item ( item : @item, ctxt : @mut EntryContext , visitor : EntryVisitor ) {
77
- match item. node {
78
- item_fn( * ) => {
79
- if item. ident == special_idents:: main {
80
- match ctxt. ast_map . find ( & item. id ) {
81
- Some ( & ast_map:: node_item( _, path) ) => {
82
- if path. len ( ) == 0 {
83
- // This is a top-level function so can be 'main'
84
- if ctxt. main_fn . is_none ( ) {
85
- ctxt. main_fn = Some ( ( item. id , item. span ) ) ;
69
+ impl Visitor < ( ) > for EntryContext {
70
+ fn visit_item ( & mut self , item : @item, _: ( ) ) {
71
+ match item. node {
72
+ item_fn( * ) => {
73
+ if item. ident == special_idents:: main {
74
+ match self . ast_map . find ( & item. id ) {
75
+ Some ( & ast_map:: node_item( _, path) ) => {
76
+ if path. len ( ) == 0 {
77
+ // This is a top-level function so can be
78
+ // 'main'
79
+ if self . main_fn . is_none ( ) {
80
+ self . main_fn = Some ( ( item. id , item. span ) ) ;
81
+ } else {
82
+ self . session . span_err (
83
+ item. span ,
84
+ "multiple 'main' functions" ) ;
85
+ }
86
86
} else {
87
- ctxt. session . span_err (
88
- item. span ,
89
- "multiple 'main' functions" ) ;
87
+ // This isn't main
88
+ self . non_main_fns . push ( ( item. id , item. span ) ) ;
90
89
}
91
- } else {
92
- // This isn't main
93
- ctxt. non_main_fns . push ( ( item. id , item. span ) ) ;
94
90
}
91
+ _ => util:: unreachable ( )
95
92
}
96
- _ => util:: unreachable ( )
97
93
}
98
- }
99
94
100
- if attr:: contains_name ( item. attrs , "main" ) {
101
- if ctxt. attr_main_fn . is_none ( ) {
102
- ctxt. attr_main_fn = Some ( ( item. id , item. span ) ) ;
103
- } else {
104
- ctxt. session . span_err (
105
- item. span ,
106
- "multiple 'main' functions" ) ;
95
+ if attr:: contains_name ( item. attrs , "main" ) {
96
+ if self . attr_main_fn . is_none ( ) {
97
+ self . attr_main_fn = Some ( ( item. id , item. span ) ) ;
98
+ } else {
99
+ self . session . span_err (
100
+ item. span ,
101
+ "multiple 'main' functions" ) ;
102
+ }
107
103
}
108
- }
109
104
110
- if attr:: contains_name ( item. attrs , "start" ) {
111
- if ctxt. start_fn . is_none ( ) {
112
- ctxt. start_fn = Some ( ( item. id , item. span ) ) ;
113
- } else {
114
- ctxt. session . span_err (
115
- item. span ,
116
- "multiple 'start' functions" ) ;
105
+ if attr:: contains_name ( item. attrs , "start" ) {
106
+ if self . start_fn . is_none ( ) {
107
+ self . start_fn = Some ( ( item. id , item. span ) ) ;
108
+ } else {
109
+ self . session . span_err (
110
+ item. span ,
111
+ "multiple 'start' functions" ) ;
112
+ }
117
113
}
118
114
}
115
+ _ => ( )
119
116
}
120
- _ => ( )
121
- }
122
117
123
- visit_item ( item, ( ctxt, visitor) ) ;
118
+ visit:: walk_item ( self , item, ( ) ) ;
119
+ }
124
120
}
125
121
126
- fn configure_main ( ctxt : @mut EntryContext ) {
127
- let this = & mut * ctxt;
122
+ fn configure_main ( this : & mut EntryContext ) {
128
123
if this. start_fn . is_some ( ) {
129
124
* this. session . entry_fn = this. start_fn ;
130
125
* this. session . entry_type = Some ( session:: EntryStart ) ;
0 commit comments