+2003-07-24 Jason Merrill <jason@redhat.com>
+
+ * tree.h (boolean_type_node): Move from C/C++/Java frontends.
+ (boolean_true_node, boolean_false_node): Likewise.
+ (enum tree_index): Add TI_BOOLEAN_{TYPE,FALSE,TRUE}.
+ * tree.c (build_common_tree_nodes): Init boolean_type_node.
+ (build_common_tree_nodes_2): Init boolean_{true,false}_node.
+ * stor-layout.c (set_sizetype): Handle an early BOOLEAN_TYPE.
+ * c-common.h (truthvalue_type_node): Renamed from boolean_type_node.
+ (truthvalue_true_node): Renamed from boolean_true_node.
+ (truthvalue_false_node): Renamed from boolean_false_node.
+ * c-decl.c: Just set truthvalue_* to integer_*.
+ * c-*.[ch]: s/boolean/truthvalue/. s/c_bool/boolean/.
+
2003-07-24 Roger Sayle <roger@eyesopen.com>
* c-decl.c (match_builtin_function_types): New subroutine of
tree long_unsigned_type_node;
tree long_long_unsigned_type_node;
- tree boolean_type_node;
- tree boolean_false_node;
- tree boolean_true_node;
+ tree truthvalue_type_node;
+ tree truthvalue_false_node;
+ tree truthvalue_true_node;
tree ptrdiff_type_node;
if (code == NE_EXPR)
{
if (max_lt || min_gt)
- val = boolean_true_node;
+ val = truthvalue_true_node;
}
else if (code == EQ_EXPR)
{
if (max_lt || min_gt)
- val = boolean_false_node;
+ val = truthvalue_false_node;
}
else if (code == LT_EXPR)
{
if (max_lt)
- val = boolean_true_node;
+ val = truthvalue_true_node;
if (!min_lt)
- val = boolean_false_node;
+ val = truthvalue_false_node;
}
else if (code == GT_EXPR)
{
if (min_gt)
- val = boolean_true_node;
+ val = truthvalue_true_node;
if (!max_gt)
- val = boolean_false_node;
+ val = truthvalue_false_node;
}
else if (code == LE_EXPR)
{
if (!max_gt)
- val = boolean_true_node;
+ val = truthvalue_true_node;
if (min_gt)
- val = boolean_false_node;
+ val = truthvalue_false_node;
}
else if (code == GE_EXPR)
{
if (!min_lt)
- val = boolean_true_node;
+ val = truthvalue_true_node;
if (max_lt)
- val = boolean_false_node;
+ val = truthvalue_false_node;
}
/* If primop0 was sign-extended and unsigned comparison specd,
if (TREE_CODE (primop0) != INTEGER_CST)
{
- if (val == boolean_false_node)
+ if (val == truthvalue_false_node)
warning ("comparison is always false due to limited range of data type");
- if (val == boolean_true_node)
+ if (val == truthvalue_true_node)
warning ("comparison is always true due to limited range of data type");
}
&& ! TREE_OVERFLOW (convert (c_common_signed_type (type),
primop0))))
warning ("comparison of unsigned expression >= 0 is always true");
- value = boolean_true_node;
+ value = truthvalue_true_node;
break;
case LT_EXPR:
&& ! TREE_OVERFLOW (convert (c_common_signed_type (type),
primop0))))
warning ("comparison of unsigned expression < 0 is always false");
- value = boolean_false_node;
+ value = truthvalue_false_node;
break;
default:
*op0_ptr = convert (type, primop0);
*op1_ptr = convert (type, primop1);
- *restype_ptr = boolean_type_node;
+ *restype_ptr = truthvalue_type_node;
return 0;
}
This preparation consists of taking the ordinary
representation of an expression expr and producing a valid tree
boolean expression describing whether expr is nonzero. We could
- simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
+ simply always do build_binary_op (NE_EXPR, expr, truthvalue_false_node, 1),
but we optimize comparisons, &&, ||, and !.
- The resulting type should always be `boolean_type_node'. */
+ The resulting type should always be `truthvalue_type_node'. */
tree
c_common_truthvalue_conversion (tree expr)
{
case RECORD_TYPE:
error ("struct type value used where scalar is required");
- return boolean_false_node;
+ return truthvalue_false_node;
case UNION_TYPE:
error ("union type value used where scalar is required");
- return boolean_false_node;
+ return truthvalue_false_node;
case ARRAY_TYPE:
error ("array type value used where scalar is required");
- return boolean_false_node;
+ return truthvalue_false_node;
default:
break;
case TRUTH_OR_EXPR:
case TRUTH_XOR_EXPR:
case TRUTH_NOT_EXPR:
- TREE_TYPE (expr) = boolean_type_node;
+ TREE_TYPE (expr) = truthvalue_type_node;
return expr;
case ERROR_MARK:
return expr;
case INTEGER_CST:
- return integer_zerop (expr) ? boolean_false_node : boolean_true_node;
+ return integer_zerop (expr) ? truthvalue_false_node : truthvalue_true_node;
case REAL_CST:
- return real_zerop (expr) ? boolean_false_node : boolean_true_node;
+ return real_zerop (expr) ? truthvalue_false_node : truthvalue_true_node;
case ADDR_EXPR:
/* If we are taking the address of an external decl, it might be zero
break;
if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0)))
- return build (COMPOUND_EXPR, boolean_type_node,
- TREE_OPERAND (expr, 0), boolean_true_node);
+ return build (COMPOUND_EXPR, truthvalue_type_node,
+ TREE_OPERAND (expr, 0), truthvalue_true_node);
else
- return boolean_true_node;
+ return truthvalue_true_node;
case COMPLEX_EXPR:
return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
/* These don't change whether an object is zero or nonzero, but
we can't ignore them if their second arg has side-effects. */
if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
- return build (COMPOUND_EXPR, boolean_type_node, TREE_OPERAND (expr, 1),
+ return build (COMPOUND_EXPR, truthvalue_type_node, TREE_OPERAND (expr, 1),
c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)));
else
return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0));
case COND_EXPR:
/* Distribute the conversion into the arms of a COND_EXPR. */
- return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
+ return fold (build (COND_EXPR, truthvalue_type_node, TREE_OPERAND (expr, 0),
c_common_truthvalue_conversion (TREE_OPERAND (expr, 1)),
c_common_truthvalue_conversion (TREE_OPERAND (expr, 2))));
case BIT_AND_EXPR:
if (integer_onep (TREE_OPERAND (expr, 1))
- && TREE_TYPE (expr) != boolean_type_node)
+ && TREE_TYPE (expr) != truthvalue_type_node)
/* Using convert here would cause infinite recursion. */
- return build1 (NOP_EXPR, boolean_type_node, expr);
+ return build1 (NOP_EXPR, truthvalue_type_node, expr);
break;
case MODIFY_EXPR:
boolean_increment (enum tree_code code, tree arg)
{
tree val;
- tree true_res = (c_dialect_cxx () ? boolean_true_node : c_bool_true_node);
+ tree true_res = boolean_true_node;
arg = stabilize_reference (arg);
switch (code)
CTI_CONST_STRING_TYPE,
/* Type for boolean expressions (bool in C++, int in C). */
- CTI_BOOLEAN_TYPE,
- CTI_BOOLEAN_TRUE,
- CTI_BOOLEAN_FALSE,
- /* C99's _Bool type. */
- CTI_C_BOOL_TYPE,
- CTI_C_BOOL_TRUE,
- CTI_C_BOOL_FALSE,
+ CTI_TRUTHVALUE_TYPE,
+ CTI_TRUTHVALUE_TRUE,
+ CTI_TRUTHVALUE_FALSE,
+
CTI_DEFAULT_FUNCTION_TYPE,
CTI_G77_INTEGER_TYPE,
#define widest_integer_literal_type_node c_global_trees[CTI_WIDEST_INT_LIT_TYPE]
#define widest_unsigned_literal_type_node c_global_trees[CTI_WIDEST_UINT_LIT_TYPE]
-#define boolean_type_node c_global_trees[CTI_BOOLEAN_TYPE]
-#define boolean_true_node c_global_trees[CTI_BOOLEAN_TRUE]
-#define boolean_false_node c_global_trees[CTI_BOOLEAN_FALSE]
-
-#define c_bool_type_node c_global_trees[CTI_C_BOOL_TYPE]
-#define c_bool_true_node c_global_trees[CTI_C_BOOL_TRUE]
-#define c_bool_false_node c_global_trees[CTI_C_BOOL_FALSE]
+#define truthvalue_type_node c_global_trees[CTI_TRUTHVALUE_TYPE]
+#define truthvalue_true_node c_global_trees[CTI_TRUTHVALUE_TRUE]
+#define truthvalue_false_node c_global_trees[CTI_TRUTHVALUE_FALSE]
#define char_array_type_node c_global_trees[CTI_CHAR_ARRAY_TYPE]
#define wchar_array_type_node c_global_trees[CTI_WCHAR_ARRAY_TYPE]
c_common_nodes_and_builtins ();
- boolean_type_node = integer_type_node;
- boolean_true_node = integer_one_node;
- boolean_false_node = integer_zero_node;
-
- c_bool_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
- TREE_SET_CODE (c_bool_type_node, BOOLEAN_TYPE);
- TYPE_MAX_VALUE (c_bool_type_node) = build_int_2 (1, 0);
- TREE_TYPE (TYPE_MAX_VALUE (c_bool_type_node)) = c_bool_type_node;
- TYPE_PRECISION (c_bool_type_node) = 1;
+ /* In C, comparisons and TRUTH_* expressions have type int. */
+ truthvalue_type_node = integer_type_node;
+ truthvalue_true_node = integer_one_node;
+ truthvalue_false_node = integer_zero_node;
+
+ /* Even in C99, which has a real boolean type. */
pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"),
- c_bool_type_node));
- c_bool_false_node = build_int_2 (0, 0);
- TREE_TYPE (c_bool_false_node) = c_bool_type_node;
- c_bool_true_node = build_int_2 (1, 0);
- TREE_TYPE (c_bool_true_node) = c_bool_type_node;
+ boolean_type_node));
endlink = void_list_node;
ptr_ftype_void = build_function_type (ptr_type_node, endlink);
if (DECL_INITIAL (x) && pedantic
&& TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node
&& TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node
- && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != c_bool_type_node
+ && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != boolean_type_node
/* Accept an enum that's equivalent to int or unsigned int. */
&& !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
&& (TYPE_PRECISION (TREE_TYPE (x))
if (DECL_INITIAL (x))
{
int max_width
- = (TYPE_MAIN_VARIANT (TREE_TYPE (x)) == c_bool_type_node
+ = (TYPE_MAIN_VARIANT (TREE_TYPE (x)) == boolean_type_node
? CHAR_TYPE_SIZE : TYPE_PRECISION (TREE_TYPE (x)));
if (tree_int_cst_sgn (DECL_INITIAL (x)) < 0)
| expr_no_commas ANDAND
{ $1 = c_common_truthvalue_conversion
(default_conversion ($1));
- skip_evaluation += $1 == boolean_false_node; }
+ skip_evaluation += $1 == truthvalue_false_node; }
expr_no_commas
- { skip_evaluation -= $1 == boolean_false_node;
+ { skip_evaluation -= $1 == truthvalue_false_node;
$$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
| expr_no_commas OROR
{ $1 = c_common_truthvalue_conversion
(default_conversion ($1));
- skip_evaluation += $1 == boolean_true_node; }
+ skip_evaluation += $1 == truthvalue_true_node; }
expr_no_commas
- { skip_evaluation -= $1 == boolean_true_node;
+ { skip_evaluation -= $1 == truthvalue_true_node;
$$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
| expr_no_commas '?'
{ $1 = c_common_truthvalue_conversion
(default_conversion ($1));
- skip_evaluation += $1 == boolean_false_node; }
+ skip_evaluation += $1 == truthvalue_false_node; }
expr ':'
- { skip_evaluation += (($1 == boolean_true_node)
- - ($1 == boolean_false_node)); }
+ { skip_evaluation += (($1 == truthvalue_true_node)
+ - ($1 == truthvalue_false_node)); }
expr_no_commas
- { skip_evaluation -= $1 == boolean_true_node;
+ { skip_evaluation -= $1 == truthvalue_true_node;
$$ = build_conditional_expr ($1, $4, $7); }
| expr_no_commas '?'
{ if (pedantic)
$<ttype>2 = save_expr ($1);
$1 = c_common_truthvalue_conversion
(default_conversion ($<ttype>2));
- skip_evaluation += $1 == boolean_true_node; }
+ skip_evaluation += $1 == truthvalue_true_node; }
':' expr_no_commas
- { skip_evaluation -= $1 == boolean_true_node;
+ { skip_evaluation -= $1 == truthvalue_true_node;
$$ = build_conditional_expr ($1, $<ttype>2, $5); }
| expr_no_commas '=' expr_no_commas
{ char class;
if (cond == error_mark_node)
/* The code is in error, but we don't want expand_end_case to
crash. */
- cond = boolean_false_node;
+ cond = truthvalue_false_node;
emit_line_note (input_location);
expand_start_case (1, cond, TREE_TYPE (cond), "switch statement");
+2003-07-24 Jason Merrill <jason@redhat.com>
+
+ * decl.c: Just set truthvalue_* to boolean_*.
+
2003-07-24 Nathan Sidwell <nathan@codesourcery.com>
* decl.c (reshape_init): Remove unreachable code.
integer_three_node = build_int_2 (3, 0);
TREE_TYPE (integer_three_node) = integer_type_node;
- boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
- TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
- TYPE_MAX_VALUE (boolean_type_node) = build_int_2 (1, 0);
- TREE_TYPE (TYPE_MAX_VALUE (boolean_type_node)) = boolean_type_node;
- TYPE_PRECISION (boolean_type_node) = 1;
record_builtin_type (RID_BOOL, "bool", boolean_type_node);
- boolean_false_node = build_int_2 (0, 0);
- TREE_TYPE (boolean_false_node) = boolean_type_node;
- boolean_true_node = build_int_2 (1, 0);
- TREE_TYPE (boolean_true_node) = boolean_type_node;
+ truthvalue_type_node = boolean_type_node;
+ truthvalue_false_node = boolean_false_node;
+ truthvalue_true_node = boolean_true_node;
empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
+2003-07-24 Jason Merrill <jason@redhat.com>
+
+ * java-tree.h: Move boolean_type_node et al to the back end.
+
2003-07-19 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* class.c java-tree.h jcf-write.c jvspec.c: Remove unnecessary
JTI_DECIMAL_INT_MAX_NODE,
JTI_DECIMAL_LONG_MAX_NODE,
- JTI_BOOLEAN_TYPE_NODE,
-
JTI_OBJECT_TYPE_NODE,
JTI_UNQUALIFIED_OBJECT_ID_NODE,
JTI_OBJECT_PTR_TYPE_NODE,
JTI_RETURN_ADDRESS_TYPE_NODE,
- JTI_BOOLEAN_TRUE_NODE,
- JTI_BOOLEAN_FALSE_NODE,
-
JTI_LONG_ZERO_NODE,
JTI_FLOAT_ZERO_NODE,
JTI_DOUBLE_ZERO_NODE,
#define decimal_long_max \
java_global_trees[JTI_DECIMAL_LONG_MAX_NODE]
-#define boolean_type_node \
- java_global_trees[JTI_BOOLEAN_TYPE_NODE]
-
#define object_type_node \
java_global_trees[JTI_OBJECT_TYPE_NODE]
#define unqualified_object_id_node \
#define return_address_type_node \
java_global_trees[JTI_RETURN_ADDRESS_TYPE_NODE]
-/* Nodes for boolean constants TRUE and FALSE. */
-#define boolean_true_node \
- java_global_trees[JTI_BOOLEAN_TRUE_NODE]
-#define boolean_false_node \
- java_global_trees[JTI_BOOLEAN_FALSE_NODE]
-
/* Integer constants not declared in tree.h. */
#define long_zero_node \
java_global_trees[JTI_LONG_ZERO_NODE]
for the sizes in them. */
for (t = early_type_list; t != 0; t = TREE_CHAIN (t))
{
- if (TREE_CODE (TREE_VALUE (t)) != INTEGER_TYPE)
+ if (TREE_CODE (TREE_VALUE (t)) != INTEGER_TYPE
+ && TREE_CODE (TREE_VALUE (t)) != BOOLEAN_TYPE)
abort ();
TREE_TYPE (TYPE_SIZE (TREE_VALUE (t))) = bitsizetype;
long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
+ /* Define a boolean type. This type only represents boolean values but
+ may be larger than char depending on the value of BOOL_TYPE_SIZE.
+ Front ends which want to override this size (i.e. Java) can redefine
+ boolean_type_node before calling build_common_tree_nodes_2. */
+ boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
+ TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
+ TYPE_MAX_VALUE (boolean_type_node) = build_int_2 (1, 0);
+ TREE_TYPE (TYPE_MAX_VALUE (boolean_type_node)) = boolean_type_node;
+ TYPE_PRECISION (boolean_type_node) = 1;
+
intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
bitsize_one_node = bitsize_int (1);
bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
+ boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
+ boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
+
void_type_node = make_node (VOID_TYPE);
layout_type (void_type_node);
TI_BITSIZE_ONE,
TI_BITSIZE_UNIT,
+ TI_BOOLEAN_FALSE,
+ TI_BOOLEAN_TRUE,
+
TI_COMPLEX_INTEGER_TYPE,
TI_COMPLEX_FLOAT_TYPE,
TI_COMPLEX_DOUBLE_TYPE,
TI_SIZE_TYPE,
TI_PTRDIFF_TYPE,
TI_VA_LIST_TYPE,
+ TI_BOOLEAN_TYPE,
TI_VOID_LIST_NODE,
#define ptrdiff_type_node global_trees[TI_PTRDIFF_TYPE]
#define va_list_type_node global_trees[TI_VA_LIST_TYPE]
+#define boolean_type_node global_trees[TI_BOOLEAN_TYPE]
+#define boolean_false_node global_trees[TI_BOOLEAN_FALSE]
+#define boolean_true_node global_trees[TI_BOOLEAN_TRUE]
+
/* The node that should be placed at the end of a parameter list to
indicate that the function does not take a variable number of
arguments. The TREE_VALUE will be void_type_node and there will be