librustc: Remove common fields and nested enums from the language

This commit is contained in:
Patrick Walton 2013-03-28 11:29:21 -07:00
parent 09dc38eda5
commit 0a002d79b4
19 changed files with 36 additions and 159 deletions

View File

@ -286,8 +286,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder,
if args.len() > 0 && generics.ty_params.len() == 0 => {
encode_symbol(ecx, ebml_w, variant.node.id);
}
ast::tuple_variant_kind(_) | ast::struct_variant_kind(_) |
ast::enum_variant_kind(_) => {}
ast::tuple_variant_kind(_) | ast::struct_variant_kind(_) => {}
}
encode_discriminant(ecx, ebml_w, variant.node.id);
if vi[i].disr_val != disr_val {

View File

@ -37,7 +37,7 @@
use syntax::ast::{expr_fn_block, expr_index, expr_method_call, expr_path};
use syntax::ast::{def_prim_ty, def_region, def_self, def_ty, def_ty_param};
use syntax::ast::{def_upvar, def_use, def_variant, div, eq};
use syntax::ast::{enum_variant_kind, expr, expr_again, expr_assign_op};
use syntax::ast::{expr, expr_again, expr_assign_op};
use syntax::ast::{expr_index, expr_loop};
use syntax::ast::{expr_path, expr_struct, expr_unary, fn_decl};
use syntax::ast::{foreign_item, foreign_item_const, foreign_item_fn, ge};
@ -1383,16 +1383,6 @@ fn build_reduced_graph_for_variant(@mut self,
variant.span);
self.structs.insert(local_def(variant.node.id));
}
enum_variant_kind(ref enum_definition) => {
child.define_type(privacy,
def_ty(local_def(variant.node.id)),
variant.span);
for (*enum_definition).variants.each |variant| {
self.build_reduced_graph_for_variant(*variant, item_id,
parent_privacy,
parent, visitor);
}
}
}
}

View File

@ -2051,14 +2051,6 @@ pub fn trans_enum_def(ccx: @CrateContext, enum_definition: ast::enum_def,
trans_struct_def(ccx, struct_def, path,
variant.node.id);
}
ast::enum_variant_kind(ref enum_definition) => {
trans_enum_def(ccx,
*enum_definition,
id,
path,
vi,
&mut *i);
}
}
}
}
@ -2513,9 +2505,6 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
ast::struct_variant_kind(_) => {
fail!(~"struct variant kind unexpected in get_item_val")
}
ast::enum_variant_kind(_) => {
fail!(~"enum variant kind unexpected in get_item_val")
}
}
set_inline_hint(llfn);
llfn

View File

@ -204,8 +204,6 @@ pub fn monomorphic_fn(ccx: @CrateContext,
}
ast::struct_variant_kind(_) =>
ccx.tcx.sess.bug(~"can't monomorphize struct variants"),
ast::enum_variant_kind(_) =>
ccx.tcx.sess.bug(~"can't monomorphize enum variants")
}
d
}

View File

@ -3873,9 +3873,6 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
ast::struct_variant_kind(_) => {
fail!(~"struct variant kinds unimpl in enum_variants")
}
ast::enum_variant_kind(_) => {
fail!(~"enum variant kinds unimpl in enum_variants")
}
}
})
}

View File

@ -3066,16 +3066,6 @@ fn do_check(ccx: @mut CrateCtxt,
ccx.tcx, local_def(v.node.id)).map(|cf|
ty::node_id_to_type(ccx.tcx, cf.id.node)));
}
ast::enum_variant_kind(_) => {
arg_tys = None;
do_check(ccx,
sp,
vs,
id,
&mut *disr_vals,
&mut *disr_val,
&mut *variants);
}
}
match arg_tys {

View File

@ -202,15 +202,6 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt,
|f| ty::node_id_to_type(ccx.tcx, f.node.id));
result_ty = Some(ty::mk_ctor_fn(tcx, input_tys, enum_ty));
}
ast::enum_variant_kind(ref enum_definition) => {
get_enum_variant_types(ccx,
enum_ty,
enum_definition.variants,
generics,
rp);
result_ty = None;
}
};
match result_ty {

View File

@ -1078,7 +1078,6 @@ pub struct variant_arg {
pub enum variant_kind {
tuple_variant_kind(~[variant_arg]),
struct_variant_kind(@struct_def),
enum_variant_kind(enum_def)
}
#[auto_encode]
@ -1086,7 +1085,6 @@ pub enum variant_kind {
#[deriving(Eq)]
pub struct enum_def {
variants: ~[variant],
common: Option<@struct_def>,
}
#[auto_encode]

View File

@ -990,8 +990,6 @@ fn mk_enum_ser_body(
),
ast::struct_variant_kind(*) =>
fail!(~"struct variants unimplemented"),
ast::enum_variant_kind(*) =>
fail!(~"enum variants unimplemented"),
}
};
@ -1089,8 +1087,6 @@ fn mk_enum_deser_body(
},
ast::struct_variant_kind(*) =>
fail!(~"struct variants unimplemented"),
ast::enum_variant_kind(*) =>
fail!(~"enum variants unimplemented")
};
let pat = @ast::pat {

View File

@ -12,7 +12,7 @@
use ast;
use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
use ast::{expr, expr_match, ident, impure_fn, item, item_};
use ast::{item_enum, item_impl, item_struct, Generics};
use ast::{m_imm, meta_item, method};
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};

View File

@ -12,7 +12,7 @@
use ast;
use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
use ast::{expr, expr_match, ident, impure_fn, item, item_};
use ast::{item_enum, item_impl, item_struct, Generics};
use ast::{m_imm, meta_item, method};
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};

View File

@ -12,7 +12,7 @@
use ast;
use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
use ast::{expr, expr_match, ident, impure_fn, item, item_};
use ast::{item_enum, item_impl, item_struct, Generics};
use ast::{m_imm, meta_item, method};
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};

View File

@ -15,7 +15,7 @@
use ast;
use ast::{TraitTyParamBound, Ty, and, bind_by_ref, binop, deref, enum_def};
use ast::{enum_variant_kind, expr, expr_match, ident, impure_fn, item, item_};
use ast::{expr, expr_match, ident, impure_fn, item, item_};
use ast::{item_enum, item_impl, item_struct, Generics};
use ast::{m_imm, meta_item, method};
use ast::{named_field, or, pat, pat_ident, pat_wild, public, pure_fn};
@ -283,9 +283,6 @@ pub fn create_enum_variant_pattern(cx: @ext_ctxt,
build::mk_pat_struct(cx, span, matching_path, field_pats)
}
enum_variant_kind(*) => {
cx.span_unimpl(span, ~"enum variants for `deriving`");
}
}
}
@ -293,9 +290,6 @@ pub fn variant_arg_count(cx: @ext_ctxt, span: span, variant: &variant) -> uint {
match variant.node.kind {
tuple_variant_kind(ref args) => args.len(),
struct_variant_kind(ref struct_def) => struct_def.fields.len(),
enum_variant_kind(*) => {
cx.span_bug(span, ~"variant_arg_count: enum variants deprecated")
}
}
}

View File

@ -238,7 +238,7 @@ fn to_type_decls(&self, cx: @ext_ctxt) -> ~[@ast::item] {
cx.item_enum_poly(
name,
self.span,
ast::enum_def { variants: items_msg, common: None },
ast::enum_def { variants: items_msg },
cx.strip_bounds(&self.generics)
)
]

View File

@ -257,9 +257,6 @@ pub fn noop_fold_item_underscore(i: &item_, fld: @ast_fold) -> item_ {
variants: do enum_definition.variants.map |x| {
fld.fold_variant(x)
},
common: do enum_definition.common.map |x| {
fold_struct_def(*x, fld)
}
},
fold_generics(generics, fld))
}
@ -682,17 +679,6 @@ fn fold_variant_arg_(va: variant_arg, fld: @ast_fold) -> variant_arg {
ctor_id: struct_def.ctor_id.map(|c| fld.new_id(*c))
})
}
enum_variant_kind(ref enum_definition) => {
let variants = do (*enum_definition).variants.map |x| {
fld.fold_variant(x)
};
let common = do (*enum_definition).common.map |x| {
fold_struct_def(*x, fld)
};
kind = enum_variant_kind(
ast::enum_def { variants: variants, common: common }
);
}
}
let fold_attribute = |x| fold_attribute_(x, fld);

View File

@ -19,7 +19,7 @@
use ast::{bind_by_copy, bitand, bitor, bitxor, blk};
use ast::{blk_check_mode, box, by_copy, by_ref};
use ast::{crate, crate_cfg, decl, decl_item};
use ast::{decl_local, default_blk, deref, div, enum_def, enum_variant_kind};
use ast::{decl_local, default_blk, deref, div, enum_def};
use ast::{expl, expr, expr_, expr_addr_of, expr_match, expr_again};
use ast::{expr_assign, expr_assign_op, expr_binary, expr_block};
use ast::{expr_break, expr_call, expr_cast, expr_copy, expr_do_body};
@ -3788,63 +3788,42 @@ fn parse_struct_def(&self) -> @struct_def {
fn parse_enum_def(&self, generics: &ast::Generics) -> enum_def {
let mut variants = ~[];
let mut all_nullary = true, have_disr = false;
let mut common_fields = None;
while *self.token != token::RBRACE {
let variant_attrs = self.parse_outer_attributes();
let vlo = self.span.lo;
// Is this a common field declaration?
if self.eat_keyword(&~"struct") {
if common_fields.is_some() {
self.fatal(~"duplicate declaration of shared fields");
}
self.expect(&token::LBRACE);
common_fields = Some(self.parse_struct_def());
loop;
}
let vis = self.parse_visibility();
// Is this a nested enum declaration?
let ident, needs_comma, kind;
let mut args = ~[], disr_expr = None;
if self.eat_keyword(&~"enum") {
ident = self.parse_ident();
self.expect(&token::LBRACE);
let nested_enum_def = self.parse_enum_def(generics);
kind = enum_variant_kind(nested_enum_def);
needs_comma = false;
} else {
ident = self.parse_ident();
if self.eat(&token::LBRACE) {
// Parse a struct variant.
all_nullary = false;
kind = struct_variant_kind(self.parse_struct_def());
} else if *self.token == token::LPAREN {
all_nullary = false;
let arg_tys = self.parse_unspanned_seq(
&token::LPAREN,
&token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
|p| p.parse_ty(false)
);
for arg_tys.each |ty| {
args.push(ast::variant_arg {
ty: *ty,
id: self.get_id(),
});
}
kind = tuple_variant_kind(args);
} else if self.eat(&token::EQ) {
have_disr = true;
disr_expr = Some(self.parse_expr());
kind = tuple_variant_kind(args);
} else {
kind = tuple_variant_kind(~[]);
ident = self.parse_ident();
if self.eat(&token::LBRACE) {
// Parse a struct variant.
all_nullary = false;
kind = struct_variant_kind(self.parse_struct_def());
} else if *self.token == token::LPAREN {
all_nullary = false;
let arg_tys = self.parse_unspanned_seq(
&token::LPAREN,
&token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
|p| p.parse_ty(false)
);
for arg_tys.each |ty| {
args.push(ast::variant_arg {
ty: *ty,
id: self.get_id(),
});
}
needs_comma = true;
kind = tuple_variant_kind(args);
} else if self.eat(&token::EQ) {
have_disr = true;
disr_expr = Some(self.parse_expr());
kind = tuple_variant_kind(args);
} else {
kind = tuple_variant_kind(~[]);
}
needs_comma = true;
let vr = ast::variant_ {
name: ident,
@ -3864,7 +3843,7 @@ fn parse_enum_def(&self, generics: &ast::Generics) -> enum_def {
enum");
}
ast::enum_def { variants: variants, common: common_fields }
ast::enum_def { variants: variants }
}
fn parse_item_enum(&self) -> item_info {
@ -3892,7 +3871,7 @@ fn parse_item_enum(&self) -> item_info {
return (
id,
item_enum(
ast::enum_def { variants: ~[variant], common: None },
ast::enum_def { variants: ~[variant] },
generics),
None
);

View File

@ -785,9 +785,6 @@ fn print_variant_arg(s: @ps, arg: ast::variant_arg) {
let generics = ast_util::empty_generics();
print_struct(s, struct_def, &generics, v.node.name, v.span);
}
ast::enum_variant_kind(ref enum_definition) => {
print_variants(s, (*enum_definition).variants, v.span);
}
}
match v.node.disr_expr {
Some(d) => {

View File

@ -215,9 +215,6 @@ pub fn visit_enum_def<E>(enum_definition: ast::enum_def,
(v.visit_struct_def)(struct_def, vr.node.name, tps,
vr.node.id, e, v);
}
enum_variant_kind(ref enum_definition) => {
visit_enum_def((*enum_definition), tps, e, v);
}
}
// Visit the disr expr if it exists
for vr.node.disr_expr.each |ex| { (v.visit_expr)(*ex, e, v) }

View File

@ -1,24 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum Foo {
struct {
x: int,
y: int,
}
Bar(int),
Baz(int)
}
pub fn main() {
let x = Bar(3);
}