@@ -146,12 +146,15 @@ type env =
146
146
// since export restrictions should only be applied for the former.
147
147
enum dir { inside, outside, }
148
148
149
- // There are two types of ns_value enum: "definitely a enum";
150
- // and "any value". This is so that lookup can behave differently
151
- // when looking up a variable name that's not yet in scope to check
152
- // if it's already bound to a enum.
153
- enum namespace { ns_val( ns_value_type ) , ns_type, ns_module, }
154
- enum ns_value_type { ns_an_enum, ns_any_value, }
149
+ // There are two types of ns_value enum: "definitely a enum"; and "enum or
150
+ // other value". This is so that lookup can behave differently when looking up
151
+ // a variable name that's not yet in scope to check if it's already bound to a
152
+ // enum.
153
+ enum namespace { ns_val( enumness ) , ns_type, ns_module, }
154
+ enum enumness {
155
+ definite_enum,
156
+ value_or_enum
157
+ }
155
158
156
159
fn resolve_crate ( sess : session , amap : ast_map:: map , crate : @ast:: crate ) ->
157
160
{ def_map : def_map , exp_map : exp_map , impl_map : impl_map } {
@@ -372,7 +375,7 @@ fn check_unused_imports(e: @env) {
372
375
373
376
fn resolve_capture_item ( e : @env , sc : scopes , & & cap_item: @ast:: capture_item ) {
374
377
let dcur = lookup_in_scope_strict (
375
- * e, sc, cap_item. span , cap_item. name , ns_val ( ns_any_value ) ) ;
378
+ * e, sc, cap_item. span , cap_item. name , ns_val ( value_or_enum ) ) ;
376
379
maybe_insert ( e, cap_item. id , dcur) ;
377
380
}
378
381
@@ -409,7 +412,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
409
412
ast:: expr_path ( p) {
410
413
maybe_insert ( e, exp. id ,
411
414
lookup_path_strict ( * e, sc, exp. span , p. node ,
412
- ns_val ( ns_any_value ) ) ) ;
415
+ ns_val ( value_or_enum ) ) ) ;
413
416
}
414
417
ast:: expr_fn ( _, _, _, cap_clause) {
415
418
let rci = bind resolve_capture_item ( e, sc, _) ;
@@ -446,14 +449,14 @@ fn resolve_names(e: @env, c: @ast::crate) {
446
449
fn walk_constr ( e : @env , p : @ast:: path , sp : span , id : node_id , sc : scopes ,
447
450
_v : vt < scopes > ) {
448
451
maybe_insert ( e, id, lookup_path_strict ( * e, sc,
449
- sp, p. node , ns_val ( ns_any_value ) ) ) ;
452
+ sp, p. node , ns_val ( value_or_enum ) ) ) ;
450
453
}
451
454
fn walk_pat ( e : @env , pat : @ast:: pat , sc : scopes , v : vt < scopes > ) {
452
455
visit:: visit_pat ( pat, sc, v) ;
453
456
alt pat. node {
454
457
ast:: pat_enum ( p, _) {
455
458
alt lookup_path_strict ( * e, sc, p. span , p. node ,
456
- ns_val ( ns_any_value ) ) {
459
+ ns_val ( value_or_enum ) ) {
457
460
some ( fnd@ast:: def_variant ( _, _) ) {
458
461
e. def_map . insert ( pat. id , fnd) ;
459
462
}
@@ -468,7 +471,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
468
471
variable a refers to a nullary enum. */
469
472
ast:: pat_ident ( p, none) {
470
473
alt lookup_in_scope ( * e, sc, p. span , path_to_ident ( p) ,
471
- ns_val ( ns_an_enum ) ) {
474
+ ns_val ( definite_enum ) ) {
472
475
some ( fnd@ast:: def_variant ( _, _) ) {
473
476
e. def_map . insert ( pat. id , fnd) ;
474
477
}
@@ -624,11 +627,11 @@ fn visit_local_with_scope(e: @env, loc: @local, sc:scopes, v:vt<scopes>) {
624
627
// a single identifier unambiguous (does the pattern "foo" refer
625
628
// to enum foo, or is it binding a new name foo?)
626
629
alt loc. node . pat . node {
627
- pat_ident ( an_ident, _) {
628
- // Be sure to pass ns_an_enum to lookup_in_scope so that
630
+ pat_ident ( an_ident, _) {
631
+ // Be sure to pass definite_enum to lookup_in_scope so that
629
632
// if this is a name that's being shadowed, we don't die
630
633
alt lookup_in_scope ( * e, sc, loc. span ,
631
- path_to_ident ( an_ident) , ns_val ( ns_an_enum ) ) {
634
+ path_to_ident ( an_ident) , ns_val ( definite_enum ) ) {
632
635
some ( ast:: def_variant ( enum_id, variant_id) ) {
633
636
// Declaration shadows a enum that's in scope.
634
637
// That's an error.
@@ -676,7 +679,7 @@ fn follow_import(e: env, sc: scopes, path: [ident], sp: span) ->
676
679
677
680
fn resolve_constr ( e : @env , c : @ast:: constr , sc : scopes , _v : vt < scopes > ) {
678
681
alt lookup_path_strict ( * e, sc, c. span , c. node . path . node ,
679
- ns_val ( ns_any_value ) ) {
682
+ ns_val ( value_or_enum ) ) {
680
683
some ( d@ast:: def_fn ( _, ast:: pure_fn) ) {
681
684
e. def_map . insert ( c. node . id , d) ;
682
685
}
@@ -694,7 +697,7 @@ fn resolve_import(e: env, defid: ast::def_id, name: ast::ident,
694
697
fn register ( e : env , id : node_id , cx : ctxt , sp : codemap:: span ,
695
698
name : ast:: ident , lookup : fn ( namespace ) -> option < def > ,
696
699
impls : [ @_impl ] ) {
697
- let val = lookup ( ns_val ( ns_any_value ) ) , typ = lookup ( ns_type) ,
700
+ let val = lookup ( ns_val ( value_or_enum ) ) , typ = lookup ( ns_type) ,
698
701
md = lookup ( ns_module) ;
699
702
if is_none ( val) && is_none ( typ) && is_none ( md) &&
700
703
vec:: len ( impls) == 0 u {
@@ -806,8 +809,8 @@ fn ns_name(ns: namespace) -> str {
806
809
ns_type { "typename" }
807
810
ns_val ( v) {
808
811
alt ( v) {
809
- ns_any_value { "name" }
810
- ns_an_enum { "enum" }
812
+ value_or_enum { "name" }
813
+ definite_enum { "enum" }
811
814
}
812
815
}
813
816
ns_module { "modulename" }
@@ -1007,11 +1010,11 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
1007
1010
if ns == ns_type {
1008
1011
ret lookup_in_ty_params ( e, name, tps) ;
1009
1012
}
1010
- if ns == ns_val ( ns_any_value ) && name == it. ident {
1013
+ if ns == ns_val ( value_or_enum ) && name == it. ident {
1011
1014
ret some ( ast:: def_fn ( local_def ( ctor_id) ,
1012
1015
ast:: impure_fn) ) ;
1013
1016
}
1014
- if ns == ns_val ( ns_any_value ) {
1017
+ if ns == ns_val ( value_or_enum ) {
1015
1018
ret lookup_in_class ( local_def ( it. id ) ,
1016
1019
members, name) ;
1017
1020
}
@@ -1022,7 +1025,7 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
1022
1025
}
1023
1026
}
1024
1027
scope_method ( id, tps) {
1025
- if ( name == "self" && ns == ns_val ( ns_any_value ) ) {
1028
+ if ( name == "self" && ns == ns_val ( value_or_enum ) ) {
1026
1029
ret some ( ast:: def_self ( local_def ( id) ) ) ;
1027
1030
} else if ns == ns_type {
1028
1031
ret lookup_in_ty_params ( e, name, tps) ;
@@ -1044,7 +1047,7 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
1044
1047
ret lookup_in_fn ( e, name, decl, ty_params, ns) ;
1045
1048
}
1046
1049
scope_loop ( local) {
1047
- if ns == ns_val ( ns_any_value ) {
1050
+ if ns == ns_val ( value_or_enum ) {
1048
1051
alt lookup_in_pat ( e, name, local. node . pat ) {
1049
1052
some ( did) { ret some ( ast:: def_binding ( did) ) ; }
1050
1053
_ { }
@@ -1055,7 +1058,7 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
1055
1058
ret lookup_in_block ( e, name, sp, b. node , * pos, * loc, ns) ;
1056
1059
}
1057
1060
scope_arm ( a) {
1058
- if ns == ns_val ( ns_any_value ) {
1061
+ if ns == ns_val ( value_or_enum ) {
1059
1062
alt lookup_in_pat ( e, name, a. pats [ 0 ] ) {
1060
1063
some ( did) { ret some ( ast:: def_binding ( did) ) ; }
1061
1064
_ { ret none; }
@@ -1089,7 +1092,7 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
1089
1092
/* If we were looking for a enum, at this point
1090
1093
we know it's bound to a non-enum value, and
1091
1094
we can return none instead of failing */
1092
- ns_an_enum { ret none; }
1095
+ definite_enum { ret none; }
1093
1096
_ { "attempted dynamic environment-capture" }
1094
1097
}
1095
1098
}
@@ -1150,7 +1153,7 @@ fn lookup_in_fn(e: env, name: ident, decl: ast::fn_decl,
1150
1153
ty_params : [ ast:: ty_param ] ,
1151
1154
ns : namespace ) -> option < def > {
1152
1155
alt ns {
1153
- ns_val( ns_any_value ) {
1156
+ ns_val( value_or_enum ) {
1154
1157
for a: ast:: arg in decl. inputs {
1155
1158
if str:: eq ( a. ident , name) {
1156
1159
ret some ( ast:: def_arg ( local_def ( a. id ) , a. mode ) ) ;
@@ -1202,7 +1205,7 @@ fn lookup_in_block(e: env, name: ident, sp: span, b: ast::blk_, pos: uint,
1202
1205
while j > 0 u {
1203
1206
j -= 1 u;
1204
1207
let loc = locs[ j] ;
1205
- if ns == ns_val ( ns_any_value )
1208
+ if ns == ns_val ( value_or_enum )
1206
1209
&& ( i < pos || j < loc_pos) {
1207
1210
alt lookup_in_pat ( e, name, loc. node . pat ) {
1208
1211
some ( did) {
@@ -1292,11 +1295,11 @@ fn lookup_in_block(e: env, name: ident, sp: span, b: ast::blk_, pos: uint,
1292
1295
fn found_def_item ( i : @ast:: item , ns : namespace ) -> option < def > {
1293
1296
alt i. node {
1294
1297
ast:: item_const ( _, _) {
1295
- if ns == ns_val ( ns_any_value ) {
1298
+ if ns == ns_val ( value_or_enum ) {
1296
1299
ret some ( ast:: def_const ( local_def ( i. id ) ) ) ; }
1297
1300
}
1298
1301
ast:: item_fn ( decl, _, _) {
1299
- if ns == ns_val ( ns_any_value ) {
1302
+ if ns == ns_val ( value_or_enum ) {
1300
1303
ret some ( ast:: def_fn ( local_def ( i. id ) , decl. purity ) ) ;
1301
1304
}
1302
1305
}
@@ -1311,7 +1314,7 @@ fn found_def_item(i: @ast::item, ns: namespace) -> option<def> {
1311
1314
}
1312
1315
ast:: item_res ( _, _, _, _, ctor_id) {
1313
1316
alt ns {
1314
- ns_val( ns_any_value ) {
1317
+ ns_val( value_or_enum ) {
1315
1318
ret some ( ast:: def_fn ( local_def ( ctor_id) , ast:: impure_fn) ) ;
1316
1319
}
1317
1320
ns_type { ret some( ast:: def_ty ( local_def ( i. id ) ) ) ; }
@@ -1470,7 +1473,7 @@ fn lookup_in_globs(e: env, globs: [glob_imp_def], sp: span, id: ident,
1470
1473
if vec:: len ( matches) == 0 u {
1471
1474
ret none;
1472
1475
}
1473
- else if vec:: len ( matches) == 1 u || ns == ns_val ( ns_an_enum ) {
1476
+ else if vec:: len ( matches) == 1 u || ns == ns_val ( definite_enum ) {
1474
1477
ret some ( matches[ 0 ] . def ) ;
1475
1478
} else {
1476
1479
for match: glob_imp_def in matches {
@@ -1489,8 +1492,11 @@ fn lookup_glob_in_mod(e: env, info: @indexed_mod, sp: span, id: ident,
1489
1492
if !info. glob_imported_names . contains_key ( id) {
1490
1493
info. glob_imported_names . insert ( id, glob_resolving ( sp) ) ;
1491
1494
// kludge
1492
- let val_ns = if wanted_ns == ns_val ( ns_an_enum) { ns_val ( ns_an_enum) }
1493
- else { ns_val ( ns_any_value) } ;
1495
+ let val_ns = if wanted_ns == ns_val ( definite_enum) {
1496
+ ns_val ( definite_enum)
1497
+ } else {
1498
+ ns_val ( value_or_enum)
1499
+ } ;
1494
1500
let globs = info. glob_imports ;
1495
1501
let val = lookup_in_globs ( e, globs, sp, id, val_ns, dr) ;
1496
1502
let typ = lookup_in_globs ( e, globs, sp, id, ns_type, dr) ;
@@ -1532,7 +1538,7 @@ fn lookup_in_mie(e: env, mie: mod_index_entry, ns: namespace) ->
1532
1538
mie_native_item ( native_item) {
1533
1539
alt native_item. node {
1534
1540
ast:: native_item_fn ( decl, _) {
1535
- if ns == ns_val ( ns_any_value ) {
1541
+ if ns == ns_val ( value_or_enum ) {
1536
1542
ret some ( ast:: def_fn ( local_def ( native_item. id ) ,
1537
1543
decl. purity ) ) ;
1538
1544
}
@@ -1655,12 +1661,12 @@ fn index_nmod(md: ast::native_mod) -> mod_index {
1655
1661
// External lookups
1656
1662
fn ns_for_def ( d : def ) -> namespace {
1657
1663
alt d {
1658
- ast : : def_variant ( _, _) { ns_val ( ns_an_enum ) }
1664
+ ast : : def_variant ( _, _) { ns_val ( definite_enum ) }
1659
1665
ast:: def_fn ( _, _) | ast:: def_self ( _) |
1660
1666
ast:: def_const ( _) | ast:: def_arg ( _, _) | ast:: def_local ( _) |
1661
1667
ast:: def_upvar ( _, _, _) | ast:: def_self ( _) |
1662
1668
ast:: def_class_field ( _, _) | ast:: def_class_method ( _, _)
1663
- { ns_val ( ns_any_value ) }
1669
+ { ns_val ( value_or_enum ) }
1664
1670
ast:: def_mod ( _) | ast:: def_native_mod ( _) { ns_module }
1665
1671
ast:: def_ty ( _) | ast:: def_binding ( _) | ast:: def_use ( _) |
1666
1672
ast:: def_ty_param ( _, _) | ast:: def_prim_ty ( _) | ast:: def_class ( _)
@@ -1672,7 +1678,7 @@ fn ns_for_def(d: def) -> namespace {
1672
1678
// a enum
1673
1679
fn ns_ok ( wanted : namespace , actual : namespace ) -> bool {
1674
1680
alt actual {
1675
- ns_val( ns_an_enum ) {
1681
+ ns_val( definite_enum ) {
1676
1682
alt wanted {
1677
1683
ns_val( _) { true }
1678
1684
_ { false }
@@ -1720,7 +1726,7 @@ fn check_mod_name(e: env, name: ident, entries: list<mod_index_entry>) {
1720
1726
while true {
1721
1727
alt entries {
1722
1728
cons( entry, rest) {
1723
- if !is_none ( lookup_in_mie ( e, entry, ns_val ( ns_any_value ) ) ) {
1729
+ if !is_none ( lookup_in_mie ( e, entry, ns_val ( value_or_enum ) ) ) {
1724
1730
if saw_value {
1725
1731
dup ( e, mie_span ( entry) , "" , name) ;
1726
1732
} else { saw_value = true ; }
@@ -1921,7 +1927,7 @@ fn check_exports(e: @env) {
1921
1927
let lookup =
1922
1928
bind lookup_glob_in_mod ( * e, info, sp, ident, _, inside) ;
1923
1929
let ( m, v, t) = ( lookup ( ns_module) ,
1924
- lookup ( ns_val ( ns_any_value ) ) ,
1930
+ lookup ( ns_val ( value_or_enum ) ) ,
1925
1931
lookup ( ns_type) ) ;
1926
1932
let full_path = path + ident;
1927
1933
maybe_add_reexport ( e, full_path, m) ;
0 commit comments