@@ -30,11 +30,10 @@ export list_file_metadata;
30
30
31
31
// Traverses an AST, reading all the information about use'd crates and native
32
32
// libraries necessary for later resolving, typechecking, linking, etc.
33
- fn read_crates ( session:: session sess, resolve :: crate_map crate_map ,
33
+ fn read_crates ( session:: session sess,
34
34
& ast:: crate crate) {
35
35
auto e =
36
36
@rec ( sess=sess,
37
- crate_map=crate_map,
38
37
crate_cache=@std:: map:: new_str_hash[ int] ( ) ,
39
38
library_search_paths=sess. get_opts ( ) . library_search_paths ,
40
39
mutable next_crate_num=1 ) ;
@@ -45,6 +44,55 @@ fn read_crates(session::session sess, resolve::crate_map crate_map,
45
44
walk:: walk_crate ( v, crate ) ;
46
45
}
47
46
47
+ type env =
48
+ @rec ( session:: session sess,
49
+ @hashmap[ str, int] crate_cache ,
50
+ vec[ str] library_search_paths ,
51
+ mutable int next_crate_num ) ;
52
+
53
+ fn visit_view_item ( env e, & @ast:: view_item i) {
54
+ alt ( i. node ) {
55
+ case ( ast:: view_item_use ( ?ident, ?meta_items, ?id) ) {
56
+ auto cnum;
57
+ if ( !e. crate_cache . contains_key ( ident) ) {
58
+ cnum = e. next_crate_num ;
59
+ load_library_crate ( e. sess , i. span , cnum, ident,
60
+ meta_items, e. library_search_paths ) ;
61
+ e. crate_cache . insert ( ident, e. next_crate_num ) ;
62
+ e. next_crate_num += 1 ;
63
+ } else { cnum = e. crate_cache . get ( ident) ; }
64
+ cstore:: add_use_stmt_cnum ( e. sess . get_cstore ( ) , id, cnum) ;
65
+ }
66
+ case ( _) { }
67
+ }
68
+ }
69
+
70
+ fn visit_item( env e, & @ast:: item i) {
71
+ alt ( i. node ) {
72
+ case ( ast:: item_native_mod ( ?m) ) {
73
+ if ( m. abi != ast:: native_abi_rust &&
74
+ m. abi != ast:: native_abi_cdecl) {
75
+ ret;
76
+ }
77
+ auto cstore = e. sess . get_cstore ( ) ;
78
+ if ( !cstore:: add_used_library ( cstore, m. native_name ) ) {
79
+ ret;
80
+ }
81
+ for ( ast:: attribute a in
82
+ attr:: find_attrs_by_name( i. attrs, "link_args" ) ) {
83
+ alt ( attr:: get_meta_item_value_str( attr:: attr_meta( a) ) ) {
84
+ case ( some( ?linkarg) ) {
85
+ cstore:: add_used_link_args( cstore, linkarg) ;
86
+ }
87
+ case ( none) { /* fallthrough */ }
88
+ }
89
+ }
90
+ }
91
+ case ( _) {
92
+ }
93
+ }
94
+ }
95
+
48
96
// A diagnostic function for dumping crate metadata to an output stream
49
97
fn list_file_metadata( str path, io:: writer out) {
50
98
alt ( get_metadata_section( path) ) {
@@ -178,55 +226,6 @@ fn load_library_crate(&session::session sess, span span, int cnum,
178
226
sess. span_fatal( span, #fmt( "can't find crate for '%s'" , ident) ) ;
179
227
}
180
228
181
- type env =
182
- @rec( session:: session sess,
183
- resolve:: crate_map crate_map,
184
- @hashmap[ str, int] crate_cache,
185
- vec[ str] library_search_paths,
186
- mutable int next_crate_num) ;
187
-
188
- fn visit_view_item( env e, & @ast:: view_item i) {
189
- alt ( i. node) {
190
- case ( ast:: view_item_use( ?ident, ?meta_items, ?id) ) {
191
- auto cnum;
192
- if ( !e. crate_cache. contains_key( ident) ) {
193
- cnum = e. next_crate_num;
194
- load_library_crate( e. sess, i. span, cnum, ident,
195
- meta_items, e. library_search_paths) ;
196
- e. crate_cache. insert( ident, e. next_crate_num) ;
197
- e. next_crate_num += 1 ;
198
- } else { cnum = e. crate_cache. get( ident) ; }
199
- e. crate_map. insert( id, cnum) ;
200
- }
201
- case ( _) { }
202
- }
203
- }
204
-
205
- fn visit_item( env e, & @ast:: item i) {
206
- alt ( i. node) {
207
- case ( ast:: item_native_mod( ?m) ) {
208
- if ( m. abi != ast:: native_abi_rust &&
209
- m. abi != ast:: native_abi_cdecl) {
210
- ret;
211
- }
212
- auto cstore = e. sess. get_cstore( ) ;
213
- if ( !cstore:: add_used_library( cstore, m. native_name) ) {
214
- ret;
215
- }
216
- for ( ast:: attribute a in
217
- attr:: find_attrs_by_name( i. attrs, "link_args" ) ) {
218
- alt ( attr:: get_meta_item_value_str( attr:: attr_meta( a) ) ) {
219
- case ( some( ?linkarg) ) {
220
- cstore:: add_used_link_args( cstore, linkarg) ;
221
- }
222
- case ( none) { /* fallthrough */ }
223
- }
224
- }
225
- }
226
- case ( _) {
227
- }
228
- }
229
- }
230
229
231
230
232
231
// Local Variables:
0 commit comments