aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2010-12-12 16:30:34 -0800
committerPatrick Walton <[email protected]>2010-12-12 16:30:34 -0800
commit38ba0e691738981ef0b7302a3b03adbe264bb30d (patch)
tree3fc180ecece0f93564f9b54ca8da4a12937e6893
parentrustc: Propagate types for vector, tuple, record, assignment, and if expressi... (diff)
downloadrust-38ba0e691738981ef0b7302a3b03adbe264bb30d.tar.xz
rust-38ba0e691738981ef0b7302a3b03adbe264bb30d.zip
rustc: Add a definition ID to tag patterns
-rw-r--r--src/comp/front/ast.rs4
-rw-r--r--src/comp/front/parser.rs4
-rw-r--r--src/comp/middle/fold.rs11
3 files changed, 11 insertions, 8 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index 11db3eed..eb41f859 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -44,11 +44,13 @@ type block_ = rec(vec[@stmt] stmts,
option.t[@expr] expr,
hashmap[ident,uint] index);
+type variant_def = tup(def_id /* tag */, def_id /* variant */);
+
type pat = spanned[pat_];
tag pat_ {
pat_wild(ann);
pat_bind(ident, def_id, ann);
- pat_tag(ident, vec[@pat], ann);
+ pat_tag(ident, vec[@pat], option.t[variant_def], ann);
}
tag mutability {
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index decb28e1..a3b0462d 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -906,7 +906,7 @@ impure fn parse_pat(parser p) -> @ast.pat {
case (_) { args = vec(); }
}
- pat = ast.pat_tag(id, args, ast.ann_none);
+ pat = ast.pat_tag(id, args, none[ast.variant_def], ast.ann_none);
}
case (?tok) {
p.err("expected pattern but found " + token.to_str(tok));
@@ -1088,7 +1088,7 @@ fn index_arm(@ast.pat pat) -> hashmap[ast.ident,ast.def_id] {
alt (pat.node) {
case (ast.pat_bind(?i, ?def_id, _)) { index.insert(i, def_id); }
case (ast.pat_wild(_)) { /* empty */ }
- case (ast.pat_tag(_, ?pats, _)) {
+ case (ast.pat_tag(_, ?pats, _, _)) {
for (@ast.pat p in pats) {
do_index_arm(index, p);
}
diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs
index 521b433e..5a03bc88 100644
--- a/src/comp/middle/fold.rs
+++ b/src/comp/middle/fold.rs
@@ -149,6 +149,7 @@ type ast_fold[ENV] =
(fn(&ENV e, &span sp,
ident i, vec[@pat] args,
+ option.t[ast.variant_def] d,
ann a) -> @pat) fold_pat_tag,
@@ -344,12 +345,12 @@ fn fold_pat[ENV](&ENV env, ast_fold[ENV] fld, @ast.pat p) -> @ast.pat {
case (ast.pat_bind(?id, ?did, ?t)) {
ret fld.fold_pat_bind(env_, p.span, id, did, t);
}
- case (ast.pat_tag(?id, ?pats, ?t)) {
+ case (ast.pat_tag(?id, ?pats, ?d, ?t)) {
let vec[@ast.pat] ppats = vec();
for (@ast.pat pat in pats) {
ppats += vec(fold_pat(env_, fld, pat));
}
- ret fld.fold_pat_tag(env_, p.span, id, ppats, t);
+ ret fld.fold_pat_tag(env_, p.span, id, ppats, d, t);
}
}
}
@@ -864,8 +865,8 @@ fn identity_fold_pat_bind[ENV](&ENV e, &span sp, ident i, def_id did, ann a)
}
fn identity_fold_pat_tag[ENV](&ENV e, &span sp, ident i, vec[@pat] args,
- ann a) -> @pat {
- ret @respan(sp, ast.pat_tag(i, args, a));
+ option.t[ast.variant_def] d, ann a) -> @pat {
+ ret @respan(sp, ast.pat_tag(i, args, d, a));
}
@@ -1041,7 +1042,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_pat_wild = bind identity_fold_pat_wild[ENV](_,_,_),
fold_pat_bind = bind identity_fold_pat_bind[ENV](_,_,_,_,_),
- fold_pat_tag = bind identity_fold_pat_tag[ENV](_,_,_,_,_),
+ fold_pat_tag = bind identity_fold_pat_tag[ENV](_,_,_,_,_,_),
fold_stmt_decl = bind identity_fold_stmt_decl[ENV](_,_,_),
fold_stmt_ret = bind identity_fold_stmt_ret[ENV](_,_,_),