Cleanups to previous commits for issue #1393.

This commit is contained in:
Kevin Atkinson 2012-01-10 18:33:26 -07:00 committed by Marijn Haverbeke
parent 175196bbb8
commit 44352df57c
6 changed files with 11 additions and 9 deletions

View File

@ -174,7 +174,7 @@ export type_is_tup_like;
export type_is_str; export type_is_str;
export type_is_unique; export type_is_unique;
export type_is_tag; export type_is_tag;
export type_is_enum_like; export type_is_c_like_enum;
export type_structurally_contains_uniques; export type_structurally_contains_uniques;
export type_autoderef; export type_autoderef;
export type_param; export type_param;
@ -1274,7 +1274,7 @@ fn type_is_tag(cx: ctxt, ty: t) -> bool {
// Whether a type is enum like, that is a tag type with only nullary // Whether a type is enum like, that is a tag type with only nullary
// constructors // constructors
fn type_is_enum_like(cx: ctxt, ty: t) -> bool { fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool {
alt struct(cx, ty) { alt struct(cx, ty) {
ty_tag(did, tps) { ty_tag(did, tps) {
let variants = tag_variants(cx, did); let variants = tag_variants(cx, did);

View File

@ -211,9 +211,9 @@ fn type_is_scalar(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool {
ret ty::type_is_scalar(fcx.ccx.tcx, typ_s); ret ty::type_is_scalar(fcx.ccx.tcx, typ_s);
} }
fn type_is_enum_like(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool { fn type_is_c_like_enum(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ); let typ_s = structurally_resolved_type(fcx, sp, typ);
ret ty::type_is_enum_like(fcx.ccx.tcx, typ_s); ret ty::type_is_c_like_enum(fcx.ccx.tcx, typ_s);
} }
// Parses the programmer's textual representation of a type into our internal // Parses the programmer's textual representation of a type into our internal
@ -2216,7 +2216,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
ty::ty_iface(_, _) {} ty::ty_iface(_, _) {}
_ { _ {
let t_1_is_scalar = type_is_scalar(fcx, expr.span, t_1); let t_1_is_scalar = type_is_scalar(fcx, expr.span, t_1);
if type_is_enum_like(fcx,expr.span,t_e) && t_1_is_scalar { if type_is_c_like_enum(fcx,expr.span,t_e) && t_1_is_scalar {
/* this case is allowed */ /* this case is allowed */
} else if !(type_is_scalar(fcx,expr.span,t_e) && t_1_is_scalar) { } else if !(type_is_scalar(fcx,expr.span,t_e) && t_1_is_scalar) {
// FIXME there are more forms of cast to support, eventually. // FIXME there are more forms of cast to support, eventually.

View File

@ -245,6 +245,8 @@ tag const_val {
const_str(str); const_str(str);
} }
// FIXME (#1417): any function that uses this function should likely be moved
// into the middle end
fn eval_const_expr(e: @expr) -> const_val { fn eval_const_expr(e: @expr) -> const_val {
fn fromb(b: bool) -> const_val { const_int(b as i64) } fn fromb(b: bool) -> const_val { const_int(b as i64) }
alt e.node { alt e.node {

View File

@ -473,9 +473,9 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
let (de, dv) = alt v.disr_expr { let (de, dv) = alt v.disr_expr {
some(e) { some(e) {
let de = fld.fold_expr(e); let de = fld.fold_expr(e);
// FIXME (#1417): see parser.rs
let dv = alt syntax::ast_util::eval_const_expr(e) { let dv = alt syntax::ast_util::eval_const_expr(e) {
ast_util::const_int(val) { ast_util::const_int(val) {
// FIXME (#1417): check that value is in range
val as int val as int
} }
}; };

View File

@ -2117,7 +2117,7 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
// probably be doing." (See issue #1417) // probably be doing." (See issue #1417)
alt syntax::ast_util::eval_const_expr(e) { alt syntax::ast_util::eval_const_expr(e) {
syntax::ast_util::const_int(val) { syntax::ast_util::const_int(val) {
// FIXME (#1417): check that value is in range // FIXME: check that value is in range
disr_val = val as int; disr_val = val as int;
} }
} }
@ -2148,7 +2148,7 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
} }
let hi = p.get_hi_pos(); let hi = p.get_hi_pos();
if (have_disr && !all_nullary) { if (have_disr && !all_nullary) {
p.fatal("discriminator values can only be used with enum-like tag"); p.fatal("discriminator values can only be used with a c-like enum");
} }
p.bump(); p.bump();
ret mk_item(p, lo, hi, id, ast::item_tag(variants, ty_params), attrs); ret mk_item(p, lo, hi, id, ast::item_tag(variants, ty_params), attrs);

View File

@ -1,4 +1,4 @@
//error-pattern: discriminator values can only be used with enum-like tag //error-pattern: discriminator values can only be used with a c-like enum
// black and white have the same discriminator value ... // black and white have the same discriminator value ...
tag color { tag color {