Export all enum variants by default; new syntax for selectively exporting variants

See issue 1426 for details. Now, the semantics of "export t;" where t is a tag are
to export all of t's variants as well. "export t{};" exports t but not its
variants, while "export t{a, b, c};" exports only variants a, b, c of t.

To do:
- documentation
- there's currently no checking that a, b, c are actually variants of t in the
 above example
- there's also no checking that t is an enum type, in the second two examples above
- change the modules listed in issue 1426 that should have the old export
semantics to use the t{} syntax

I deleted the test export-no-tag-variants since we're doing the opposite now,
and other tests cover the same behavior.
This commit is contained in:
Tim Chevalier 2012-01-22 21:09:43 -08:00
parent e515999324
commit 9dc59e1506
10 changed files with 89 additions and 63 deletions

View file

@ -113,12 +113,16 @@ fn float_ty_to_str(t: float_ty) -> str {
fn is_exported(i: ident, m: _mod) -> bool {
let nonlocal = true;
let parent_tag : option<ident> = none;
for it: @item in m.items {
if it.ident == i { nonlocal = false; }
alt it.node {
item_tag(variants, _) {
for v: variant in variants {
if v.node.name == i { nonlocal = false; }
if v.node.name == i {
nonlocal = false;
parent_tag = some(it.ident);
}
}
}
_ { }
@ -129,9 +133,28 @@ fn is_exported(i: ident, m: _mod) -> bool {
for vi: @view_item in m.view_items {
alt vi.node {
view_item_export(ids, _) {
for id in ids { if str::eq(i, id) { ret true; } }
// If any of ids is a tag, we want to consider
// all the variants to be exported
for id in ids {
if str::eq(i, id) { ret true; }
alt parent_tag {
some(parent_tag_id) {
if str::eq(id, parent_tag_id) { ret true; }
}
_ { }
}
}
count += 1u;
}
view_item_export_tag_none(id, _) {
if str::eq(i, id) { ret true; }
count += 1u;
}
view_item_export_tag_some(id, ids, _) {
if str::eq(i, id) { ret true; }
for id in ids { if str::eq(i, id.node.name) { ret true; } }
count += 1u;
}
_ {/* fall through */ }
}
}