diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e2248aa7b25..0a2fb19c356 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2000-08-18 Nathan Sidwell + + * cp-tree.h (enum_name_string): Remove prototype. + (report_case_error): Remove prototype. + * cp/typeck2.c (enum_name_string): Remove. + (report_case_error): Remove. + * error.c (dump_expr): Deal with enum values directly. + Correctly negate integer constant. + 2000-08-17 Nathan Sidwell * inc/cxxabi.h (__cxa_vec_new2, __cxa_vec_new3): Declare. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1f21995c5df..5dba2e39472 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4643,8 +4643,6 @@ extern tree build_scoped_ref PARAMS ((tree, tree)); extern tree build_x_arrow PARAMS ((tree)); extern tree build_m_component_ref PARAMS ((tree, tree)); extern tree build_functional_cast PARAMS ((tree, tree)); -extern char *enum_name_string PARAMS ((tree, tree)); -extern void report_case_error PARAMS ((int, tree, tree, tree)); extern void check_for_new_type PARAMS ((const char *, flagged_type_tree)); extern tree add_exception_specifier PARAMS ((tree, tree, int)); diff --git a/gcc/cp/error.c b/gcc/cp/error.c index fb8ff389eec..b8063b34d11 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -1469,8 +1469,23 @@ dump_expr (t, flags) /* If it's an enum, output its tag, rather than its value. */ if (TREE_CODE (type) == ENUMERAL_TYPE) { - const char *p = enum_name_string (t, type); - OB_PUTCP (p); + tree values = TYPE_VALUES (type); + + for (; values; + values = TREE_CHAIN (values)) + if (tree_int_cst_equal (TREE_VALUE (values), t)) + break; + + if (values) + OB_PUTID (TREE_PURPOSE (values)); + else + { + /* Value must have been cast. */ + OB_PUTC ('('); + dump_type (type, flags); + OB_PUTC (')'); + goto do_int; + } } else if (type == boolean_type_node) { @@ -1485,30 +1500,35 @@ dump_expr (t, flags) dump_char (tree_low_cst (t, 0)); OB_PUTC ('\''); } - else if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (t) - != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1))) - { - tree val = t; - - if (tree_int_cst_sgn (val) < 0) - { - OB_PUTC ('-'); - val = build_int_2 (~TREE_INT_CST_LOW (val), - -TREE_INT_CST_HIGH (val)); - } - /* Would "%x%0*x" or "%x%*0x" get zero-padding on all - systems? */ - { - static char format[10]; /* "%x%09999x\0" */ - if (!format[0]) - sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4); - sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val), - TREE_INT_CST_LOW (val)); - OB_PUTCP (digit_buffer); - } - } else - OB_PUTI (TREE_INT_CST_LOW (t)); + { + do_int: + if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (t) + != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1))) + { + tree val = t; + + if (tree_int_cst_sgn (val) < 0) + { + OB_PUTC ('-'); + val = build_int_2 (-TREE_INT_CST_LOW (val), + ~TREE_INT_CST_HIGH (val) + + !TREE_INT_CST_LOW (val)); + } + /* Would "%x%0*x" or "%x%*0x" get zero-padding on all + systems? */ + { + static char format[10]; /* "%x%09999x\0" */ + if (!format[0]) + sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4); + sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val), + TREE_INT_CST_LOW (val)); + OB_PUTCP (digit_buffer); + } + } + else + OB_PUTI (TREE_INT_CST_LOW (t)); + } } break; diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index b2e6221c834..fecd227f174 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1209,138 +1209,6 @@ build_functional_cast (exp, parms) return build_cplus_new (type, exp); } -/* Return the character string for the name that encodes the - enumeral value VALUE in the domain TYPE. */ - -char * -enum_name_string (value, type) - tree value; - tree type; -{ - register tree values = TYPE_VALUES (type); - - my_friendly_assert (TREE_CODE (type) == ENUMERAL_TYPE, 324); - - while (values && ! tree_int_cst_equal (TREE_VALUE (values), value)) - values = TREE_CHAIN (values); - - if (values == NULL_TREE) - { - char *buf = (char *) oballoc (16 + TYPE_NAME_LENGTH (type)); - - /* Value must have been cast. */ - sprintf (buf, "(enum %s)%ld", - TYPE_NAME_STRING (type), (long) TREE_INT_CST_LOW (value)); - return buf; - } - return IDENTIFIER_POINTER (TREE_PURPOSE (values)); -} - -#if 0 -/* Print out a language-specific error message for - (Pascal) case or (C) switch statements. - CODE tells what sort of message to print. - TYPE is the type of the switch index expression. - NEW is the new value that we were trying to add. - OLD is the old value that stopped us from adding it. */ - -void -report_case_error (code, type, new_value, old_value) - int code; - tree type; - tree new_value, old_value; -{ - if (code == 1) - { - if (new_value) - error ("case label not within a switch statement"); - else - error ("default label not within a switch statement"); - } - else if (code == 2) - { - if (new_value == 0) - { - error ("multiple default labels in one switch"); - return; - } - if (TREE_CODE (new_value) == RANGE_EXPR) - if (TREE_CODE (old_value) == RANGE_EXPR) - { - char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type))); - if (TREE_CODE (type) == ENUMERAL_TYPE) - sprintf (buf, "overlapping ranges [%s..%s], [%s..%s] in case expression", - enum_name_string (TREE_OPERAND (new_value, 0), type), - enum_name_string (TREE_OPERAND (new_value, 1), type), - enum_name_string (TREE_OPERAND (old_value, 0), type), - enum_name_string (TREE_OPERAND (old_value, 1), type)); - else - sprintf (buf, "overlapping ranges [%d..%d], [%d..%d] in case expression", - TREE_INT_CST_LOW (TREE_OPERAND (new_value, 0)), - TREE_INT_CST_LOW (TREE_OPERAND (new_value, 1)), - TREE_INT_CST_LOW (TREE_OPERAND (old_value, 0)), - TREE_INT_CST_LOW (TREE_OPERAND (old_value, 1))); - error (buf); - } - else - { - char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type))); - if (TREE_CODE (type) == ENUMERAL_TYPE) - sprintf (buf, "range [%s..%s] includes element `%s' in case expression", - enum_name_string (TREE_OPERAND (new_value, 0), type), - enum_name_string (TREE_OPERAND (new_value, 1), type), - enum_name_string (old_value, type)); - else - sprintf (buf, "range [%d..%d] includes (%d) in case expression", - TREE_INT_CST_LOW (TREE_OPERAND (new_value, 0)), - TREE_INT_CST_LOW (TREE_OPERAND (new_value, 1)), - TREE_INT_CST_LOW (old_value)); - error (buf); - } - else if (TREE_CODE (old_value) == RANGE_EXPR) - { - char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type))); - if (TREE_CODE (type) == ENUMERAL_TYPE) - sprintf (buf, "range [%s..%s] includes element `%s' in case expression", - enum_name_string (TREE_OPERAND (old_value, 0), type), - enum_name_string (TREE_OPERAND (old_value, 1), type), - enum_name_string (new_value, type)); - else - sprintf (buf, "range [%d..%d] includes (%d) in case expression", - TREE_INT_CST_LOW (TREE_OPERAND (old_value, 0)), - TREE_INT_CST_LOW (TREE_OPERAND (old_value, 1)), - TREE_INT_CST_LOW (new_value)); - error (buf); - } - else - { - if (TREE_CODE (type) == ENUMERAL_TYPE) - error ("duplicate label `%s' in switch statement", - enum_name_string (new_value, type)); - else - error ("duplicate label (%d) in switch statement", - TREE_INT_CST_LOW (new_value)); - } - } - else if (code == 3) - { - if (TREE_CODE (type) == ENUMERAL_TYPE) - warning ("case value out of range for enum %s", - TYPE_NAME_STRING (type)); - else - warning ("case value out of range"); - } - else if (code == 4) - { - if (TREE_CODE (type) == ENUMERAL_TYPE) - error ("range values `%s' and `%s' reversed", - enum_name_string (new_value, type), - enum_name_string (old_value, type)); - else - error ("range values reversed"); - } -} -#endif /* Complain about defining new types in inappropriate places. We give an exception for C-style casts, to accommodate GNU C stylings. */