rustc: Add def ids to variant arguments so we can turn them into function arguments later
This commit is contained in:
parent
0c19c8e18f
commit
2e119698b7
5 changed files with 20 additions and 18 deletions
|
@ -198,7 +198,8 @@ tag mod_index_entry {
|
||||||
type _mod = rec(vec[@item] items,
|
type _mod = rec(vec[@item] items,
|
||||||
hashmap[ident,mod_index_entry] index);
|
hashmap[ident,mod_index_entry] index);
|
||||||
|
|
||||||
type variant = rec(str name, vec[@ty] args, def_id id, ann ann);
|
type variant_arg = rec(@ty ty, def_id id);
|
||||||
|
type variant = rec(str name, vec[variant_arg] args, def_id id, ann ann);
|
||||||
|
|
||||||
type item = spanned[item_];
|
type item = spanned[item_];
|
||||||
tag item_ {
|
tag item_ {
|
||||||
|
|
|
@ -1271,19 +1271,19 @@ impure fn parse_item_tag(parser p) -> @ast.item {
|
||||||
case (token.IDENT(?name)) {
|
case (token.IDENT(?name)) {
|
||||||
p.bump();
|
p.bump();
|
||||||
|
|
||||||
auto args;
|
let vec[ast.variant_arg] args = vec();
|
||||||
alt (p.peek()) {
|
alt (p.peek()) {
|
||||||
case (token.LPAREN) {
|
case (token.LPAREN) {
|
||||||
auto f = parse_ty;
|
auto f = parse_ty;
|
||||||
auto tys = parse_seq[@ast.ty](token.LPAREN,
|
auto arg_tys = parse_seq[@ast.ty](token.LPAREN,
|
||||||
token.RPAREN,
|
token.RPAREN,
|
||||||
some(token.COMMA),
|
some(token.COMMA),
|
||||||
f, p);
|
f, p);
|
||||||
args = tys.node;
|
for (@ast.ty ty in arg_tys.node) {
|
||||||
|
args += vec(rec(ty=ty, id=p.next_def_id()));
|
||||||
}
|
}
|
||||||
case (_) {
|
|
||||||
args = vec();
|
|
||||||
}
|
}
|
||||||
|
case (_) { /* empty */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(p, token.SEMI);
|
expect(p, token.SEMI);
|
||||||
|
|
|
@ -602,9 +602,10 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
|
||||||
case (ast.item_tag(?ident, ?variants, ?ty_params, ?id)) {
|
case (ast.item_tag(?ident, ?variants, ?ty_params, ?id)) {
|
||||||
let vec[ast.variant] new_variants = vec();
|
let vec[ast.variant] new_variants = vec();
|
||||||
for (ast.variant v in variants) {
|
for (ast.variant v in variants) {
|
||||||
let vec[@ast.ty] new_args = vec();
|
let vec[ast.variant_arg] new_args = vec();
|
||||||
for (@ast.ty t in v.args) {
|
for (ast.variant_arg va in v.args) {
|
||||||
new_args += vec(fold_ty[ENV](env_, fld, t));
|
auto new_ty = fold_ty[ENV](env_, fld, va.ty);
|
||||||
|
new_args += vec(rec(ty=new_ty, id=va.id));
|
||||||
}
|
}
|
||||||
new_variants += rec(name=v.name, args=new_args, id=v.id,
|
new_variants += rec(name=v.name, args=new_args, id=v.id,
|
||||||
ann=v.ann);
|
ann=v.ann);
|
||||||
|
|
|
@ -1861,7 +1861,7 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
|
||||||
|
|
||||||
fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
|
fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
|
||||||
&ast.variant variant) {
|
&ast.variant variant) {
|
||||||
if (_vec.len[@ast.ty](variant.args) == 0u) {
|
if (_vec.len[ast.variant_arg](variant.args) == 0u) {
|
||||||
ret; // nullary constructors are just constants
|
ret; // nullary constructors are just constants
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1951,7 +1951,7 @@ fn resolve_tag_types_for_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
|
||||||
|
|
||||||
for (ast.variant variant in variants) {
|
for (ast.variant variant in variants) {
|
||||||
auto arity_info;
|
auto arity_info;
|
||||||
if (_vec.len[@ast.ty](variant.args) > 0u) {
|
if (_vec.len[ast.variant_arg](variant.args) > 0u) {
|
||||||
auto llvariantty = type_of_variant(cx, variant);
|
auto llvariantty = type_of_variant(cx, variant);
|
||||||
auto align = llvm.LLVMPreferredAlignmentOfType(cx.td.lltd,
|
auto align = llvm.LLVMPreferredAlignmentOfType(cx.td.lltd,
|
||||||
llvariantty);
|
llvariantty);
|
||||||
|
|
|
@ -418,7 +418,7 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
|
||||||
// Nullary tag constructors get turned into constants; n-ary tag
|
// Nullary tag constructors get turned into constants; n-ary tag
|
||||||
// constructors get turned into functions.
|
// constructors get turned into functions.
|
||||||
auto result_ty;
|
auto result_ty;
|
||||||
if (_vec.len[@ast.ty](variant.args) == 0u) {
|
if (_vec.len[ast.variant_arg](variant.args) == 0u) {
|
||||||
result_ty = plain_ty(ty_tag(tag_id));
|
result_ty = plain_ty(ty_tag(tag_id));
|
||||||
} else {
|
} else {
|
||||||
// As above, tell ast_ty_to_ty() that trans_ty_item_to_ty()
|
// As above, tell ast_ty_to_ty() that trans_ty_item_to_ty()
|
||||||
|
@ -427,8 +427,8 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
|
||||||
item_to_ty, _);
|
item_to_ty, _);
|
||||||
|
|
||||||
let vec[arg] args = vec();
|
let vec[arg] args = vec();
|
||||||
for (@ast.ty arg_ast_ty in variant.args) {
|
for (ast.variant_arg va in variant.args) {
|
||||||
auto arg_ty = ast_ty_to_ty(f, arg_ast_ty);
|
auto arg_ty = ast_ty_to_ty(f, va.ty);
|
||||||
args += vec(rec(mode=ast.alias, ty=arg_ty));
|
args += vec(rec(mode=ast.alias, ty=arg_ty));
|
||||||
}
|
}
|
||||||
result_ty = plain_ty(ty_fn(args, plain_ty(ty_tag(tag_id))));
|
result_ty = plain_ty(ty_fn(args, plain_ty(ty_tag(tag_id))));
|
||||||
|
|
Loading…
Reference in a new issue