/* 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)
{
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)))
+ else
{
- tree val = t;
-
- if (tree_int_cst_sgn (val) < 0)
+ do_int:
+ if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (t)
+ != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
{
- OB_PUTC ('-');
- val = build_int_2 (~TREE_INT_CST_LOW (val),
- -TREE_INT_CST_HIGH (val));
+ 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);
+ }
}
- /* 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));
}
- else
- OB_PUTI (TREE_INT_CST_LOW (t));
}
break;
return build_cplus_new (type, exp);
}
\f
-/* 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. */