提交 2e119698 编写于 作者: P Patrick Walton

rustc: Add def ids to variant arguments so we can turn them into function arguments later

上级 0c19c8e1
......@@ -198,7 +198,8 @@
type _mod = rec(vec[@item] items,
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_];
tag item_ {
......
......@@ -1271,19 +1271,19 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
case (token.IDENT(?name)) {
p.bump();
auto args;
let vec[ast.variant_arg] args = vec();
alt (p.peek()) {
case (token.LPAREN) {
auto f = parse_ty;
auto tys = parse_seq[@ast.ty](token.LPAREN,
token.RPAREN,
some(token.COMMA),
f, p);
args = tys.node;
}
case (_) {
args = vec();
auto arg_tys = parse_seq[@ast.ty](token.LPAREN,
token.RPAREN,
some(token.COMMA),
f, p);
for (@ast.ty ty in arg_tys.node) {
args += vec(rec(ty=ty, id=p.next_def_id()));
}
}
case (_) { /* empty */ }
}
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)) {
let vec[ast.variant] new_variants = vec();
for (ast.variant v in variants) {
let vec[@ast.ty] new_args = vec();
for (@ast.ty t in v.args) {
new_args += vec(fold_ty[ENV](env_, fld, t));
let vec[ast.variant_arg] new_args = vec();
for (ast.variant_arg va in v.args) {
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,
ann=v.ann);
......
......@@ -1861,7 +1861,7 @@ fn is_terminated(@block_ctxt cx) -> bool {
fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
&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
}
......@@ -1951,7 +1951,7 @@ fn resolve_tag_types_for_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
for (ast.variant variant in variants) {
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 align = llvm.LLVMPreferredAlignmentOfType(cx.td.lltd,
llvariantty);
......
......@@ -418,7 +418,7 @@ fn get_tag_variant_types(@hashmap[ast.def_id,@ast.item] id_to_ty_item,
// Nullary tag constructors get turned into constants; n-ary tag
// constructors get turned into functions.
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));
} else {
// As above, tell ast_ty_to_ty() that trans_ty_item_to_ty()
......@@ -427,8 +427,8 @@ fn get_tag_variant_types(@hashmap[ast.def_id,@ast.item] id_to_ty_item,
item_to_ty, _);
let vec[arg] args = vec();
for (@ast.ty arg_ast_ty in variant.args) {
auto arg_ty = ast_ty_to_ty(f, arg_ast_ty);
for (ast.variant_arg va in variant.args) {
auto arg_ty = ast_ty_to_ty(f, va.ty);
args += vec(rec(mode=ast.alias, ty=arg_ty));
}
result_ty = plain_ty(ty_fn(args, plain_ty(ty_tag(tag_id))));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册