2
2
import syntax:: { ast, ast_util, codemap} ;
3
3
import syntax:: ast:: * ;
4
4
import ast:: { ident, fn_ident, def, def_id, node_id} ;
5
- import syntax:: ast_util:: { local_def, def_id_of_def, is_exported } ;
5
+ import syntax:: ast_util:: { local_def, def_id_of_def} ;
6
6
7
+ import front:: attr;
7
8
import metadata:: { csearch, cstore} ;
8
9
import driver:: session:: session;
9
10
import util:: common:: * ;
@@ -143,6 +144,7 @@ type env =
143
144
mutable reported: [ { ident: str , sc : scope } ] ,
144
145
mutable ignored_imports: [ node_id ] ,
145
146
mutable current_tp: option:: t < uint > ,
147
+ mutable resolve_unexported: bool ,
146
148
sess : session } ;
147
149
148
150
@@ -170,6 +172,7 @@ fn resolve_crate(sess: session, amap: ast_map::map, crate: @ast::crate) ->
170
172
mutable reported: [ ] ,
171
173
mutable ignored_imports: [ ] ,
172
174
mutable current_tp: none,
175
+ mutable resolve_unexported: false ,
173
176
sess: sess} ;
174
177
map_crate ( e, crate ) ;
175
178
resolve_imports ( * e) ;
@@ -231,7 +234,7 @@ fn map_crate(e: @env, c: @ast::crate) {
231
234
path
232
235
}
233
236
fn index_i ( e : @env , i : @ast:: item , sc : scopes , v : vt < scopes > ) {
234
- visit_item_with_scope ( i, sc, v) ;
237
+ visit_item_with_scope ( e , i, sc, v) ;
235
238
alt i. node {
236
239
ast:: item_mod ( md) {
237
240
e. mod_map . insert ( i. id ,
@@ -257,7 +260,7 @@ fn map_crate(e: @env, c: @ast::crate) {
257
260
let v_link_glob =
258
261
@{ visit_view_item : bind link_glob( e, _, _, _) ,
259
262
visit_block: visit_block_with_scope,
260
- visit_item: visit_item_with_scope
263
+ visit_item: bind visit_item_with_scope ( e , _ , _ , _ )
261
264
with * visit:: default_visitor :: < scopes > ( ) } ;
262
265
visit:: visit_crate ( * c, cons ( scope_crate, @nil) ,
263
266
visit:: mk_vt ( v_link_glob) ) ;
@@ -331,7 +334,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
331
334
e. used_imports . track = true ;
332
335
let v =
333
336
@{ visit_native_item: visit_native_item_with_scope,
334
- visit_item: visit_item_with_scope,
337
+ visit_item: bind visit_item_with_scope ( e , _ , _ , _ ) ,
335
338
visit_block: visit_block_with_scope,
336
339
visit_decl: visit_decl_with_scope,
337
340
visit_arm: visit_arm_with_scope,
@@ -413,7 +416,17 @@ fn resolve_names(e: @env, c: @ast::crate) {
413
416
414
417
415
418
// Visit helper functions
416
- fn visit_item_with_scope ( i : @ast:: item , sc : scopes , v : vt < scopes > ) {
419
+ fn visit_item_with_scope ( e : @env , i : @ast:: item , sc : scopes , v : vt < scopes > ) {
420
+
421
+ // Some magic here. Items with the !resolve_unexported attribute
422
+ // cause us to consider every name to be exported when resolving their
423
+ // contents. This is used to allow the test runner to run unexported
424
+ // tests.
425
+ let old_resolve_unexported = e. resolve_unexported ;
426
+ e. resolve_unexported |=
427
+ attr:: contains_name ( attr:: attr_metas ( i. attrs ) ,
428
+ "!resolve_unexported" ) ;
429
+
417
430
let sc = cons ( scope_item ( i) , @sc) ;
418
431
alt i. node {
419
432
ast:: item_impl ( tps, ifce, sty, methods) {
@@ -436,6 +449,8 @@ fn visit_item_with_scope(i: @ast::item, sc: scopes, v: vt<scopes>) {
436
449
}
437
450
_ { visit : : visit_item ( i, sc, v) ; }
438
451
}
452
+
453
+ e. resolve_unexported = old_resolve_unexported;
439
454
}
440
455
441
456
fn visit_native_item_with_scope ( ni : @ast:: native_item , sc : scopes ,
@@ -1187,10 +1202,14 @@ fn lookup_in_local_native_mod(e: env, node_id: node_id, sp: span, id: ident,
1187
1202
ret lookup_in_local_mod ( e, node_id, sp, id, ns, inside) ;
1188
1203
}
1189
1204
1205
+ fn is_exported ( e : env , i : ident , m : _mod ) -> bool {
1206
+ ast_util:: is_exported ( i, m) || e. resolve_unexported
1207
+ }
1208
+
1190
1209
fn lookup_in_local_mod ( e : env , node_id : node_id , sp : span , id : ident ,
1191
1210
ns : namespace , dr : dir ) -> option:: t < def > {
1192
1211
let info = e. mod_map . get ( node_id) ;
1193
- if dr == outside && !is_exported ( id, option:: get ( info. m ) ) {
1212
+ if dr == outside && !is_exported ( e , id, option:: get ( info. m ) ) {
1194
1213
// if we're in a native mod, then dr==inside, so info.m is some _mod
1195
1214
ret none :: < def > ; // name is not visible
1196
1215
}
@@ -1792,7 +1811,10 @@ fn find_impls_in_item(e: env, i: @ast::item, &impls: [@_impl],
1792
1811
alt i. node {
1793
1812
ast:: item_impl ( _, ifce, _, mthds) {
1794
1813
if alt name { some ( n) { n == i. ident } _ { true } } &&
1795
- alt ck_exports { some( m) { is_exported ( i. ident , m) } _ { true } } {
1814
+ alt ck_exports {
1815
+ some( m) { is_exported ( e, i. ident , m) }
1816
+ _ { true }
1817
+ } {
1796
1818
impls += [ @{ did: local_def ( i. id ) ,
1797
1819
iface_did: alt ifce {
1798
1820
some( @{ node : ast:: ty_path ( _, id) , _} ) {
0 commit comments