rustc: Add a definition ID to tag patterns
This commit is contained in:
parent
1cdf42dd63
commit
38ba0e6917
3 changed files with 11 additions and 8 deletions
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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](_,_,_),
|
||||
|
|
Loading…
Reference in a new issue