@@ -25,7 +25,8 @@ use syntax::codemap::{span, dummy_sp};
25
25
use syntax:: diagnostic:: span_handler;
26
26
use syntax:: parse:: token;
27
27
use syntax:: parse:: token:: ident_interner;
28
- use syntax:: oldvisit;
28
+ use syntax:: visit:: SimpleVisitor ;
29
+ use syntax:: visit;
29
30
30
31
// Traverses an AST, reading all the information about use'd crates and extern
31
32
// libraries necessary for later resolving, typechecking, linking, etc.
@@ -46,13 +47,11 @@ pub fn read_crates(diag: @mut span_handler,
46
47
next_crate_num : 1 ,
47
48
intr : intr
48
49
} ;
49
- let v =
50
- oldvisit:: mk_simple_visitor ( @oldvisit:: SimpleVisitor {
51
- visit_view_item : |a| visit_view_item ( e, a) ,
52
- visit_item : |a| visit_item ( e, a) ,
53
- .. * oldvisit:: default_simple_visitor ( ) } ) ;
54
- visit_crate ( e, crate ) ;
55
- oldvisit:: visit_crate ( crate , ( ( ) , v) ) ;
50
+ e. visit_crate ( crate ) ;
51
+ let mut visitor = visit:: SimpleVisitorVisitor {
52
+ simple_visitor : e as @mut SimpleVisitor ,
53
+ } ;
54
+ visit:: walk_crate ( & mut visitor, crate , ( ) ) ;
56
55
dump_crates ( * e. crate_cache ) ;
57
56
warn_if_multiple_versions ( e, diag, * e. crate_cache ) ;
58
57
}
@@ -115,103 +114,110 @@ struct Env {
115
114
intr : @ident_interner
116
115
}
117
116
118
- fn visit_crate ( e : & Env , c : & ast:: Crate ) {
119
- let cstore = e. cstore ;
117
+ impl Env {
118
+ fn visit_crate ( & self , c : & ast:: Crate ) {
119
+ let cstore = self . cstore ;
120
120
121
- for a in c. attrs . iter ( ) . filter ( |m| "link_args" == m. name ( ) ) {
122
- match a. value_str ( ) {
123
- Some ( ref linkarg) => {
124
- cstore:: add_used_link_args ( cstore, * linkarg) ;
125
- }
126
- None => { /* fallthrough */ }
121
+ for a in c. attrs . iter ( ) . filter ( |m| "link_args" == m. name ( ) ) {
122
+ match a. value_str ( ) {
123
+ Some ( ref linkarg) => {
124
+ cstore:: add_used_link_args ( cstore, * linkarg) ;
125
+ }
126
+ None => { /* fallthrough */ }
127
+ }
127
128
}
128
129
}
129
130
}
130
131
131
- fn visit_view_item ( e : @mut Env , i : & ast:: view_item ) {
132
- match i. node {
133
- ast:: view_item_extern_mod( ident, path_opt, ref meta_items, id) => {
134
- let ident = token:: ident_to_str ( & ident) ;
135
- let meta_items = match path_opt {
136
- None => meta_items. clone ( ) ,
137
- Some ( p) => {
138
- let p_path = Path ( p) ;
139
- match p_path. filestem ( ) {
140
- Some ( s) =>
141
- vec:: append (
142
- ~[ attr:: mk_name_value_item_str ( @"package_id", p) ,
143
- attr:: mk_name_value_item_str ( @"name", s. to_managed ( ) ) ] ,
144
- * meta_items) ,
145
- None => e. diag . span_bug ( i. span , "Bad package path in `extern mod` item" )
146
- }
147
- }
148
- } ;
149
- debug ! ( "resolving extern mod stmt. ident: %?, meta: %?" ,
150
- ident, meta_items) ;
151
- let cnum = resolve_crate ( e,
152
- ident,
153
- meta_items,
154
- @"",
155
- i. span ) ;
156
- cstore:: add_extern_mod_stmt_cnum ( e. cstore , id, cnum) ;
132
+
133
+ impl SimpleVisitor for Env {
134
+ fn visit_view_item ( & mut self , i : & ast:: view_item ) {
135
+ match i. node {
136
+ ast:: view_item_extern_mod( ident, path_opt, ref meta_items, id) => {
137
+ let ident = token:: ident_to_str ( & ident) ;
138
+ let meta_items = match path_opt {
139
+ None => meta_items. clone ( ) ,
140
+ Some ( p) => {
141
+ let p_path = Path ( p) ;
142
+ match p_path. filestem ( ) {
143
+ Some ( s) =>
144
+ vec:: append (
145
+ ~[ attr:: mk_name_value_item_str ( @"package_id", p) ,
146
+ attr:: mk_name_value_item_str ( @"name", s. to_managed ( ) ) ] ,
147
+ * meta_items) ,
148
+ None => self . diag . span_bug ( i. span , "Bad package path in `extern mod` item" )
149
+ }
150
+ }
151
+ } ;
152
+ debug ! ( "resolving extern mod stmt. ident: %?, meta: %?" ,
153
+ ident, meta_items) ;
154
+ let cnum = resolve_crate ( self ,
155
+ ident,
156
+ meta_items,
157
+ @"",
158
+ i. span ) ;
159
+ cstore:: add_extern_mod_stmt_cnum ( self . cstore , id, cnum) ;
160
+ }
161
+ _ => ( )
157
162
}
158
- _ => ( )
159
- }
160
- }
163
+ }
161
164
162
- fn visit_item ( e : & Env , i : @ast:: item ) {
163
- match i. node {
164
- ast:: item_foreign_mod( ref fm) => {
165
- if fm. abis . is_rust ( ) || fm. abis . is_intrinsic ( ) {
166
- return ;
167
- }
165
+ fn visit_item ( & mut self , i : @ast:: item ) {
166
+ match i. node {
167
+ ast:: item_foreign_mod( ref fm) => {
168
+ if fm. abis . is_rust ( ) || fm. abis . is_intrinsic ( ) {
169
+ return ;
170
+ }
168
171
169
- let cstore = e. cstore ;
170
- let mut already_added = false ;
171
- let link_args = i. attrs . iter ( )
172
- . filter_map ( |at| if "link_args" == at. name ( ) { Some ( at) } else { None } )
173
- . collect :: < ~[ & ast:: Attribute ] > ( ) ;
174
-
175
- match fm. sort {
176
- ast:: named => {
177
- let link_name = i. attrs . iter ( )
178
- . find ( |at| "link_name" == at. name ( ) )
179
- . chain ( |at| at. value_str ( ) ) ;
180
-
181
- let foreign_name = match link_name {
182
- Some ( nn) => {
183
- if nn. is_empty ( ) {
184
- e. diag . span_fatal (
185
- i. span ,
186
- "empty #[link_name] not allowed; use \
187
- #[nolink].") ;
172
+ let cstore = self . cstore ;
173
+ let mut already_added = false ;
174
+ let link_args = i. attrs . iter ( )
175
+ . filter_map ( |at| if "link_args" == at. name ( ) { Some ( at) } else { None } )
176
+ . collect :: < ~[ & ast:: Attribute ] > ( ) ;
177
+
178
+ match fm. sort {
179
+ ast:: named => {
180
+ let link_name = i. attrs . iter ( )
181
+ . find ( |at| "link_name" == at. name ( ) )
182
+ . chain ( |at| at. value_str ( ) ) ;
183
+
184
+ let foreign_name = match link_name {
185
+ Some ( nn) => {
186
+ if nn. is_empty ( ) {
187
+ self . diag . span_fatal (
188
+ i. span ,
189
+ "empty #[link_name] not allowed; use \
190
+ #[nolink].") ;
191
+ }
192
+ nn
188
193
}
189
- nn
190
- }
191
- None => token:: ident_to_str ( & i. ident )
192
- } ;
193
- if !attr:: contains_name ( i. attrs , "nolink" ) {
194
- already_added =
195
- !cstore:: add_used_library ( cstore, foreign_name) ;
196
- }
197
- if !link_args. is_empty ( ) && already_added {
198
- e. diag . span_fatal ( i. span , ~"library ' " + foreign_name +
199
- "' already added: can't specify link_args." ) ;
194
+ None => token:: ident_to_str ( & i. ident )
195
+ } ;
196
+ if !attr:: contains_name ( i. attrs , "nolink" ) {
197
+ already_added =
198
+ !cstore:: add_used_library ( cstore, foreign_name) ;
199
+ }
200
+ if !link_args. is_empty ( ) && already_added {
201
+ self . diag . span_fatal ( i. span , ~"library ' " +
202
+ foreign_name +
203
+ "' already added: can't specify \
204
+ link_args.") ;
205
+ }
200
206
}
207
+ ast:: anonymous => { /* do nothing */ }
201
208
}
202
- ast:: anonymous => { /* do nothing */ }
203
- }
204
209
205
- for m in link_args. iter ( ) {
206
- match m. value_str ( ) {
207
- Some ( linkarg) => {
208
- cstore:: add_used_link_args ( cstore, linkarg) ;
210
+ for m in link_args. iter ( ) {
211
+ match m. value_str ( ) {
212
+ Some ( linkarg) => {
213
+ cstore:: add_used_link_args ( cstore, linkarg) ;
214
+ }
215
+ None => { /* fallthrough */ }
209
216
}
210
- None => { /* fallthrough */ }
211
217
}
218
+ }
219
+ _ => { }
212
220
}
213
- }
214
- _ => { }
215
221
}
216
222
}
217
223
@@ -240,7 +246,7 @@ fn existing_match(e: &Env, metas: &[@ast::MetaItem], hash: &str)
240
246
return None ;
241
247
}
242
248
243
- fn resolve_crate ( e : @ mut Env ,
249
+ fn resolve_crate ( e : & mut Env ,
244
250
ident : @str ,
245
251
metas : ~[ @ast:: MetaItem ] ,
246
252
hash : @str ,
@@ -308,7 +314,7 @@ fn resolve_crate(e: @mut Env,
308
314
}
309
315
310
316
// Go through the crate metadata and load any crates that it references
311
- fn resolve_crate_deps ( e : @ mut Env , cdata : @~[ u8 ] ) -> cstore:: cnum_map {
317
+ fn resolve_crate_deps ( e : & mut Env , cdata : @~[ u8 ] ) -> cstore:: cnum_map {
312
318
debug ! ( "resolving deps of external crate" ) ;
313
319
// The map from crate numbers in the crate we're resolving to local crate
314
320
// numbers
0 commit comments