tree.h (boolean_type_node): Move from C/C++/Java frontends.

* 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/.
        * cp/decl.c: Just set truthvalue_* to boolean_*.
        * java/java-tree.h: Move boolean_type_node et al to the back end.

From-SVN: r69758
This commit is contained in:
Jason Merrill 2003-07-24 16:48:13 -04:00 committed by Jason Merrill
parent 6907ddd3ba
commit de7df9ebdc
13 changed files with 108 additions and 98 deletions

View File

@ -1,3 +1,17 @@
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

View File

@ -100,9 +100,9 @@ cpp_reader *parse_in; /* Declared in c-pragma.h. */
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;
@ -2258,40 +2258,40 @@ shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr,
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,
@ -2330,9 +2330,9 @@ shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr,
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");
}
@ -2404,7 +2404,7 @@ shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr,
&& ! 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:
@ -2413,7 +2413,7 @@ shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr,
&& ! 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:
@ -2434,7 +2434,7 @@ shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr,
*op0_ptr = convert (type, primop0);
*op1_ptr = convert (type, primop1);
*restype_ptr = boolean_type_node;
*restype_ptr = truthvalue_type_node;
return 0;
}
@ -2544,10 +2544,10 @@ pointer_int_sum (enum tree_code resultcode, tree ptrop, tree intop)
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)
@ -2562,15 +2562,15 @@ 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;
@ -2587,17 +2587,17 @@ c_common_truthvalue_conversion (tree expr)
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
@ -2607,10 +2607,10 @@ c_common_truthvalue_conversion (tree expr)
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))
@ -2632,14 +2632,14 @@ c_common_truthvalue_conversion (tree expr)
/* 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))));
@ -2683,9 +2683,9 @@ c_common_truthvalue_conversion (tree expr)
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:
@ -4418,7 +4418,7 @@ tree
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)

View File

@ -146,13 +146,10 @@ enum c_tree_index
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,
@ -192,13 +189,9 @@ struct c_common_identifier GTY(())
#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]

View File

@ -2295,21 +2295,14 @@ c_init_decl_processing (void)
c_common_nodes_and_builtins ();
boolean_type_node = integer_type_node;
boolean_true_node = integer_one_node;
boolean_false_node = integer_zero_node;
/* 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;
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;
/* 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);
@ -5033,7 +5026,7 @@ finish_struct (tree t, tree fieldlist, tree attributes)
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))
@ -5046,7 +5039,7 @@ finish_struct (tree t, tree fieldlist, tree attributes)
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)

View File

@ -578,26 +578,26 @@ expr_no_commas:
| 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)
@ -606,9 +606,9 @@ expr_no_commas:
$<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;

View File

@ -668,7 +668,7 @@ genrtl_switch_stmt (tree t)
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");

View File

@ -1,3 +1,7 @@
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.

View File

@ -6260,16 +6260,10 @@ cxx_init_decl_processing (void)
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);

View File

@ -1,3 +1,7 @@
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

View File

@ -287,8 +287,6 @@ enum java_tree_index
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,
@ -338,9 +336,6 @@ enum java_tree_index
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,
@ -457,9 +452,6 @@ extern GTY(()) tree java_global_trees[JTI_MAX];
#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 \
@ -556,12 +548,6 @@ extern GTY(()) tree java_global_trees[JTI_MAX];
#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]

View File

@ -1941,7 +1941,8 @@ set_sizetype (tree type)
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;

View File

@ -4754,6 +4754,16 @@ build_common_tree_nodes (int signed_char)
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));
@ -4784,6 +4794,9 @@ build_common_tree_nodes_2 (int short_double)
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);

View File

@ -1779,6 +1779,9 @@ enum tree_index
TI_BITSIZE_ONE,
TI_BITSIZE_UNIT,
TI_BOOLEAN_FALSE,
TI_BOOLEAN_TRUE,
TI_COMPLEX_INTEGER_TYPE,
TI_COMPLEX_FLOAT_TYPE,
TI_COMPLEX_DOUBLE_TYPE,
@ -1794,6 +1797,7 @@ enum tree_index
TI_SIZE_TYPE,
TI_PTRDIFF_TYPE,
TI_VA_LIST_TYPE,
TI_BOOLEAN_TYPE,
TI_VOID_LIST_NODE,
@ -1880,6 +1884,10 @@ extern GTY(()) tree global_trees[TI_MAX];
#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