Skip to content

Commit 3164c07

Browse files
committed
---
yaml --- r: 31725 b: refs/heads/dist-snap c: 5ce3281 h: refs/heads/master i: 31723: 26a7d28 v: v3
1 parent fb1159b commit 3164c07

File tree

13 files changed

+117
-35
lines changed

13 files changed

+117
-35
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: 8c95feda3961efaffe4461d775b029f92a1744c4
10+
refs/heads/dist-snap: 5ce3281a624c0620f1b6f4e21c15e4a6a17a1dc5
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ type variant_arg = {ty: @ty, id: node_id};
636636
#[auto_serialize]
637637
enum variant_kind {
638638
tuple_variant_kind(~[variant_arg]),
639-
struct_variant_kind
639+
struct_variant_kind(@struct_def)
640640
}
641641

642642
#[auto_serialize]

branches/dist-snap/src/libsyntax/ext/auto_serialize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ fn deser_enum(cx: ext_ctxt, tps: deser_tps_map, e_name: ast::ident,
912912
}
913913
};
914914
}
915-
ast::struct_variant_kind =>
915+
ast::struct_variant_kind(*) =>
916916
fail ~"struct variants unimplemented"
917917
}
918918

branches/dist-snap/src/libsyntax/fold.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,21 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
549549
tuple_variant_kind(variant_args) =>
550550
kind = tuple_variant_kind(vec::map(variant_args,
551551
fold_variant_arg)),
552-
struct_variant_kind =>
553-
kind = struct_variant_kind
552+
struct_variant_kind(struct_def) => {
553+
let dtor = do option::map(struct_def.dtor) |dtor| {
554+
let dtor_body = fld.fold_block(dtor.node.body);
555+
let dtor_id = fld.new_id(dtor.node.id);
556+
{node: {body: dtor_body,
557+
id: dtor_id with dtor.node}
558+
with dtor}};
559+
kind = struct_variant_kind(@{
560+
traits: ~[],
561+
members: vec::map(struct_def.members,
562+
|x| fld.fold_class_item(x)),
563+
ctor: none,
564+
dtor: dtor
565+
})
566+
}
554567
}
555568

556569
let fold_attribute = |x| fold_attribute_(x, fld);

branches/dist-snap/src/libsyntax/parse/parser.rs

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,21 @@ import ast::{_mod, add, alt_check, alt_exhaustive, arg, arm, attribute,
4343
match_nonterminal, match_seq, match_tok, method, mode, mt, mul,
4444
mutability, neg, noreturn, not, pat, pat_box, pat_enum,
4545
pat_ident, pat_lit, pat_range, pat_rec, pat_struct, pat_tup,
46-
pat_uniq,
47-
pat_wild, path, private, proto, proto_bare, proto_block,
48-
proto_box, proto_uniq, provided, public, pure_fn, purity,
49-
re_anon, re_named, region, rem, required, ret_style, return_val,
50-
self_ty, shl, shr, stmt, stmt_decl, stmt_expr, stmt_semi,
51-
subtract, sty_box, sty_by_ref, sty_region, sty_static,
52-
sty_uniq, sty_value,
53-
token_tree, trait_method, trait_ref, tt_delim, tt_seq, tt_tok,
46+
pat_uniq, pat_wild, path, private, proto, proto_bare,
47+
proto_block, proto_box, proto_uniq, provided, public, pure_fn,
48+
purity, re_anon, re_named, region, rem, required, ret_style,
49+
return_val, self_ty, shl, shr, stmt, stmt_decl, stmt_expr,
50+
stmt_semi, struct_variant_kind, subtract, sty_box, sty_by_ref,
51+
sty_region, sty_static, sty_uniq, sty_value, token_tree,
52+
trait_method, trait_ref, tt_delim, tt_seq, tt_tok,
5453
tt_nonterminal, ty, ty_, ty_bot, ty_box, ty_field, ty_fn,
5554
ty_infer, ty_mac, ty_method, ty_nil, ty_param, ty_param_bound,
56-
ty_path, ty_ptr,
57-
ty_rec, ty_rptr, ty_tup, ty_u32, ty_uniq, ty_vec,
58-
ty_fixed_length, tuple_variant_kind,
59-
unchecked_blk, uniq, unsafe_blk, unsafe_fn,
60-
variant, view_item, view_item_, view_item_export,
61-
view_item_import, view_item_use, view_path, view_path_glob,
62-
view_path_list, view_path_simple, visibility, vstore, vstore_box,
63-
vstore_fixed, vstore_slice, vstore_uniq};
55+
ty_path, ty_ptr, ty_rec, ty_rptr, ty_tup, ty_u32, ty_uniq,
56+
ty_vec, ty_fixed_length, tuple_variant_kind, unchecked_blk, uniq,
57+
unsafe_blk, unsafe_fn, variant, view_item, view_item_,
58+
view_item_export, view_item_import, view_item_use, view_path,
59+
view_path_glob, view_path_list, view_path_simple, visibility,
60+
vstore, vstore_box, vstore_fixed, vstore_slice, vstore_uniq};
6461

6562
export file_type;
6663
export parser;
@@ -2877,7 +2874,57 @@ class parser {
28772874
let vis = self.parse_visibility();
28782875
let ident = self.parse_value_ident();
28792876
let mut args = ~[], disr_expr = none;
2880-
if self.token == token::LPAREN {
2877+
let kind;
2878+
if self.eat(token::LBRACE) {
2879+
// Parse a struct variant.
2880+
all_nullary = false;
2881+
let path = self.ident_to_path_tys(ident, ty_params);
2882+
let mut the_dtor: option<(blk, ~[attribute], codemap::span)> =
2883+
none;
2884+
let mut ms: ~[@class_member] = ~[];
2885+
while self.token != token::RBRACE {
2886+
match self.parse_class_item(path) {
2887+
ctor_decl(*) => {
2888+
self.span_fatal(copy self.span,
2889+
~"deprecated explicit \
2890+
constructors are not allowed \
2891+
here");
2892+
}
2893+
dtor_decl(blk, attrs, s) => {
2894+
match the_dtor {
2895+
some((_, _, s_first)) => {
2896+
self.span_note(s, ~"duplicate destructor \
2897+
declaration");
2898+
self.span_fatal(copy s_first,
2899+
~"first destructor \
2900+
declared here");
2901+
}
2902+
none => {
2903+
the_dtor = some((blk, attrs, s));
2904+
}
2905+
}
2906+
}
2907+
members(mms) =>
2908+
ms = vec::append(ms, mms)
2909+
}
2910+
}
2911+
self.bump();
2912+
let mut actual_dtor = do option::map(the_dtor) |dtor| {
2913+
let (d_body, d_attrs, d_s) = dtor;
2914+
{node: {id: self.get_id(),
2915+
attrs: d_attrs,
2916+
self_id: self.get_id(),
2917+
body: d_body},
2918+
span: d_s}
2919+
};
2920+
2921+
kind = struct_variant_kind(@{
2922+
traits: ~[],
2923+
members: ms,
2924+
ctor: none,
2925+
dtor: actual_dtor
2926+
});
2927+
} else if self.token == token::LPAREN {
28812928
all_nullary = false;
28822929
let arg_tys = self.parse_unspanned_seq(
28832930
token::LPAREN, token::RPAREN,
@@ -2886,13 +2933,17 @@ class parser {
28862933
for arg_tys.each |ty| {
28872934
vec::push(args, {ty: ty, id: self.get_id()});
28882935
}
2936+
kind = tuple_variant_kind(args);
28892937
} else if self.eat(token::EQ) {
28902938
have_disr = true;
28912939
disr_expr = some(self.parse_expr());
2940+
kind = tuple_variant_kind(args);
2941+
} else {
2942+
kind = tuple_variant_kind(~[]);
28922943
}
28932944

28942945
let vr = {name: ident, attrs: variant_attrs,
2895-
kind: tuple_variant_kind(args), id: self.get_id(),
2946+
kind: kind, id: self.get_id(),
28962947
disr_expr: disr_expr, vis: vis};
28972948
vec::push(variants, spanned(vlo, self.last_span.hi, vr));
28982949

branches/dist-snap/src/libsyntax/print/pprust.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,9 @@ fn print_tt(s: ps, tt: ast::token_tree) {
694694
}
695695

696696
fn print_variant(s: ps, v: ast::variant) {
697-
word(s.s, *v.node.name);
698697
match v.node.kind {
699698
ast::tuple_variant_kind(args) => {
699+
word(s.s, *v.node.name);
700700
if vec::len(args) > 0u {
701701
popen(s);
702702
fn print_variant_arg(s: ps, arg: ast::variant_arg) {
@@ -706,7 +706,10 @@ fn print_variant(s: ps, v: ast::variant) {
706706
pclose(s);
707707
}
708708
}
709-
ast::struct_variant_kind => {}
709+
ast::struct_variant_kind(struct_def) => {
710+
head(s, ~"");
711+
print_struct(s, struct_def, ~[], v.node.name, v.span);
712+
}
710713
}
711714
match v.node.disr_expr {
712715
some(d) => {

branches/dist-snap/src/libsyntax/visit.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,13 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
140140
v.visit_ty_params(tps, e, v);
141141
for variants.each |vr| {
142142
match vr.node.kind {
143-
tuple_variant_kind(variant_args) =>
144-
for variant_args.each |va| { v.visit_ty(va.ty, e, v); },
145-
struct_variant_kind => {}
143+
tuple_variant_kind(variant_args) => {
144+
for variant_args.each |va| { v.visit_ty(va.ty, e, v); }
145+
}
146+
struct_variant_kind(struct_def) => {
147+
v.visit_struct_def(struct_def, vr.node.name, tps,
148+
vr.node.id, e, v);
149+
}
146150
}
147151
}
148152
}

branches/dist-snap/src/rustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
398398
if args.len() > 0 && ty_params.len() == 0 => {
399399
encode_symbol(ecx, ebml_w, variant.node.id);
400400
}
401-
ast::tuple_variant_kind(_) | ast::struct_variant_kind => {}
401+
ast::tuple_variant_kind(_) | ast::struct_variant_kind(_) => {}
402402
}
403403
encode_discriminant(ecx, ebml_w, variant.node.id);
404404
if vi[i].disr_val != disr_val {

branches/dist-snap/src/rustc/middle/trans/base.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,7 +2187,8 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id,
21872187
this_tv.disr_val, (*tvs).len() == 1u,
21882188
psubsts, d);
21892189
}
2190-
ast::struct_variant_kind => {}
2190+
ast::struct_variant_kind(_) =>
2191+
ccx.tcx.sess.bug(~"can't monomorphize struct variants")
21912192
}
21922193
d
21932194
}
@@ -4894,9 +4895,13 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
48944895
vi[i].disr_val, degen,
48954896
none, llfn);
48964897
}
4897-
ast::tuple_variant_kind(_) | ast::struct_variant_kind => {
4898+
ast::tuple_variant_kind(_) => {
48984899
// Nothing to do.
48994900
}
4901+
ast::struct_variant_kind(struct_def) => {
4902+
trans_struct_def(ccx, struct_def, tps, path,
4903+
variant.node.name, variant.node.id);
4904+
}
49004905
}
49014906
i += 1;
49024907
}
@@ -5210,7 +5215,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
52105215
}
52115216
};
52125217
}
5213-
ast::struct_variant_kind => {
5218+
ast::struct_variant_kind(_) => {
52145219
fail ~"struct unexpected in get_item_val"
52155220
}
52165221
}

branches/dist-snap/src/rustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2868,7 +2868,7 @@ fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[variant_info] {
28682868
disr_val: disr_val
28692869
}
28702870
}
2871-
ast::struct_variant_kind =>
2871+
ast::struct_variant_kind(_) =>
28722872
fail ~"struct variant kinds unimpl in enum_variants"
28732873
}
28742874
})

branches/dist-snap/src/rustc/middle/typeck/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,7 @@ fn check_enum_variants(ccx: @crate_ctxt,
20812081
match v.node.kind {
20822082
ast::tuple_variant_kind(args) if args.len() > 0u =>
20832083
arg_tys = ty::ty_fn_args(ctor_ty).map(|a| a.ty),
2084-
ast::tuple_variant_kind(_) | ast::struct_variant_kind =>
2084+
ast::tuple_variant_kind(_) | ast::struct_variant_kind(_) =>
20852085
arg_tys = ~[]
20862086
};
20872087
vec::push(variants, @{args: arg_tys, ctor_ty: ctor_ty,

branches/dist-snap/src/rustc/middle/typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn get_enum_variant_types(ccx: @crate_ctxt,
131131
output: enum_ty,
132132
ret_style: ast::return_val});
133133
}
134-
ast::tuple_variant_kind(_) | ast::struct_variant_kind =>
134+
ast::tuple_variant_kind(_) | ast::struct_variant_kind(_) =>
135135
result_ty = enum_ty
136136
};
137137
let tpt = {bounds: ty_param_bounds(ccx, ty_params),
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
enum Foo {
2+
Bar { x: int; },
3+
Baz { y: int; }
4+
}
5+
6+
fn main() { }

0 commit comments

Comments
 (0)