From 78ef5b895f933cc8a82486aec27d6e7ac7a5acae Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Thu, 4 Apr 2002 22:19:58 +0000 Subject: [PATCH] c-common.c (truthvalue_conversion): Rename, update. * c-common.c (truthvalue_conversion): Rename, update. * c-common.h (c_common_truthvalue_conversion): New. * c-convert.c (convert): Update. * c-lang.c (LANG_HOOKS_TRUTHVALUE_CONVERSION): Redefine. * c-parse.in (expr_no_commas, if_prefix, select_or_iter_stmt): Update. * c-typeck.c (build_binary_op, build_unary_op, build_conditional_expr): Update. * fold-const.c (constant_boolean_node, fold): Use langhook. * langhooks-def.h (LANGHOOK_INITIALIZER): Update. * langhooks.h (struct lang_hooks): New hook. * stmt.c (expand_decl_cleanup): Use langhook. * tree.h (truthvalue_conversion): Remove. ada: * gigi.h (truthvalue_conversion): Rename. * misc.c (LANG_HOOKS_TRUTHVALUE_CONVERSION): Redefine. * trans.c (tree_transform): Update. * utils2.c (truthvalue_conversion): Rename, update. (build_binary_op, build_unary_op): Update. cp: * cp-lang.c (LANG_HOOKS_TRUTHVALUE_CONVERSION): Redefine. * cvt.c: Update comment. * init.c (expand_cleanup_for_base): Update. * semantics.c (finish_parenthesized_expr): Update. * typeck.c (cp_truthvalue_conversion): Update. f: * com.c (LANG_HOOKS_TRUTHVALUE_CONVERSION): Redefine. (truthvalue_conversion): Rename. Update. Make static. (ffecom_truth_value): Update. java: * expr.c (truthvalue_conversion): Rename. Update. (expand_compare): Update. * java-tree.h (java_truthvalue_conversion): New. * lang.c (LANG_HOOKS_TRUTHVALUE_CONVERSION): Redefine. objc: * objc-lang.c (LANG_HOOKS_TRUTHVALUE_CONVERSION): Redefine. From-SVN: r51880 --- gcc/ada/ChangeLog | 8 ++++++++ gcc/ada/gigi.h | 2 +- gcc/ada/misc.c | 2 ++ gcc/ada/trans.c | 7 +++---- gcc/ada/utils2.c | 17 +++++++++-------- gcc/c-common.c | 29 +++++++++++++++-------------- gcc/c-common.h | 1 + gcc/c-convert.c | 9 +++++---- gcc/c-lang.c | 2 ++ gcc/c-parse.in | 28 +++++++++++++++++----------- gcc/c-typeck.c | 8 ++++---- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/cp-lang.c | 2 ++ gcc/cp/cvt.c | 2 +- gcc/cp/init.c | 2 +- gcc/cp/semantics.c | 2 +- gcc/cp/typeck.c | 7 ++++--- gcc/f/ChangeLog | 6 ++++++ gcc/f/com.c | 37 ++++++++++++++++++++----------------- gcc/fold-const.c | 6 +++--- gcc/java/ChangeLog | 7 +++++++ gcc/java/expr.c | 12 ++++++------ gcc/java/java-tree.h | 1 + gcc/java/lang.c | 2 ++ gcc/langhooks-def.h | 1 + gcc/langhooks.h | 13 +++++++++++++ gcc/objc/objc-lang.c | 2 ++ gcc/stmt.c | 2 +- gcc/tree.h | 1 - 29 files changed, 146 insertions(+), 80 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 1e89ad8f16e9..23ad1a99fbb3 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2002-04-04 Neil Booth + + * gigi.h (truthvalue_conversion): Rename. + * misc.c (LANG_HOOKS_TRUTHVALUE_CONVERSION): Redefine. + * trans.c (tree_transform): Update. + * utils2.c (truthvalue_conversion): Rename, update. + (build_binary_op, build_unary_op): Update. + 2002-04-04 Laurent Guerby * make.adb: Implement -margs, remove restriction about file name placement. diff --git a/gcc/ada/gigi.h b/gcc/ada/gigi.h index 7342117620f5..4819ac9f31bc 100644 --- a/gcc/ada/gigi.h +++ b/gcc/ada/gigi.h @@ -654,7 +654,7 @@ extern tree unchecked_convert PARAMS ((tree, tree)); The resulting type should always be the same as the input type. This function is simpler than the corresponding C version since the only possible operands will be things of Boolean type. */ -extern tree truthvalue_conversion PARAMS((tree)); +extern tree gnat_truthvalue_conversion PARAMS((tree)); /* Return the base type of TYPE. */ extern tree get_base_type PARAMS((tree)); diff --git a/gcc/ada/misc.c b/gcc/ada/misc.c index 520b02948ab0..1246d4b03d86 100644 --- a/gcc/ada/misc.c +++ b/gcc/ada/misc.c @@ -116,6 +116,8 @@ static rtx gnat_expand_expr PARAMS ((tree, rtx, enum machine_mode, #define LANG_HOOKS_EXPAND_EXPR gnat_expand_expr #undef LANG_HOOKS_MARK_ADDRESSABLE #define LANG_HOOKS_MARK_ADDRESSABLE gnat_mark_addressable +#undef LANG_HOOKS_TRUTHVALUE_CONVERSION +#define LANG_HOOKS_TRUTHVALUE_CONVERSION gnat_truthvalue_conversion #undef LANG_HOOKS_PRINT_DECL #define LANG_HOOKS_PRINT_DECL gnat_print_decl #undef LANG_HOOKS_PRINT_TYPE diff --git a/gcc/ada/trans.c b/gcc/ada/trans.c index 371f7f2be2b8..38ae69c99daf 100644 --- a/gcc/ada/trans.c +++ b/gcc/ada/trans.c @@ -1907,7 +1907,7 @@ tree_transform (gnat_node) gnu_result_type = get_unpadded_type (Etype (gnat_node)); gnu_result = build_cond_expr (gnu_result_type, - truthvalue_conversion (gnu_cond), + gnat_truthvalue_conversion (gnu_cond), gnu_true, gnu_false); } break; @@ -2411,9 +2411,8 @@ tree_transform (gnat_node) TREE_LOOP_ID (get_gnu_tree (Entity (Name (gnat_node)))); if (Present (Condition (gnat_node))) - gnu_cond - = invert_truthvalue - (truthvalue_conversion (gnat_to_gnu (Condition (gnat_node)))); + gnu_cond = invert_truthvalue (gnat_truthvalue_conversion + (gnat_to_gnu (Condition (gnat_node)))); set_lineno (gnat_node, 1); expand_exit_loop_if_false (loop_id, gnu_cond); diff --git a/gcc/ada/utils2.c b/gcc/ada/utils2.c index 0e8ada4041ae..6d76a4149ce2 100644 --- a/gcc/ada/utils2.c +++ b/gcc/ada/utils2.c @@ -66,7 +66,7 @@ static tree build_simple_component_ref PARAMS ((tree, tree, tree)); the only possible operands will be things of Boolean type. */ tree -truthvalue_conversion (expr) +gnat_truthvalue_conversion (expr) tree expr; { tree type = TREE_TYPE (expr); @@ -85,13 +85,14 @@ truthvalue_conversion (expr) case COND_EXPR: /* Distribute the conversion into the arms of a COND_EXPR. */ - return fold (build (COND_EXPR, type, TREE_OPERAND (expr, 0), - truthvalue_conversion (TREE_OPERAND (expr, 1)), - truthvalue_conversion (TREE_OPERAND (expr, 2)))); + return fold + (build (COND_EXPR, type, TREE_OPERAND (expr, 0), + gnat_truthvalue_conversion (TREE_OPERAND (expr, 1)), + gnat_truthvalue_conversion (TREE_OPERAND (expr, 2)))); case WITH_RECORD_EXPR: return build (WITH_RECORD_EXPR, type, - truthvalue_conversion (TREE_OPERAND (expr, 0)), + gnat_truthvalue_conversion (TREE_OPERAND (expr, 0)), TREE_OPERAND (expr, 1)); default: @@ -983,8 +984,8 @@ build_binary_op (op_code, result_type, left_operand, right_operand) case TRUTH_AND_EXPR: case TRUTH_OR_EXPR: case TRUTH_XOR_EXPR: - left_operand = truthvalue_conversion (left_operand); - right_operand = truthvalue_conversion (right_operand); + left_operand = gnat_truthvalue_conversion (left_operand); + right_operand = gnat_truthvalue_conversion (right_operand); goto common; case BIT_AND_EXPR: @@ -1115,7 +1116,7 @@ build_unary_op (op_code, result_type, operand) if (result_type != base_type) gigi_abort (508); - result = invert_truthvalue (truthvalue_conversion (operand)); + result = invert_truthvalue (gnat_truthvalue_conversion (operand)); break; case ATTR_ADDR_EXPR: diff --git a/gcc/c-common.c b/gcc/c-common.c index 04cd3c462e87..1c9f4a017547 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -1577,8 +1577,9 @@ min_precision (value, unsignedp) return log + 1 + ! unsignedp; } -/* Print an error message for invalid operands to arith operation CODE. - NOP_EXPR is used as a special case (see truthvalue_conversion). */ +/* Print an error message for invalid operands to arith operation + CODE. NOP_EXPR is used as a special case (see + c_common_truthvalue_conversion). */ void binary_op_error (code) @@ -2106,7 +2107,7 @@ pointer_int_sum (resultcode, ptrop, intop) The resulting type should always be `boolean_type_node'. */ tree -truthvalue_conversion (expr) +c_common_truthvalue_conversion (expr) tree expr; { if (TREE_CODE (expr) == ERROR_MARK) @@ -2172,8 +2173,8 @@ truthvalue_conversion (expr) case COMPLEX_EXPR: return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)) ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), - truthvalue_conversion (TREE_OPERAND (expr, 0)), - truthvalue_conversion (TREE_OPERAND (expr, 1)), + c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)), + c_common_truthvalue_conversion (TREE_OPERAND (expr, 1)), 0); case NEGATE_EXPR: @@ -2181,7 +2182,7 @@ truthvalue_conversion (expr) case FLOAT_EXPR: case FFS_EXPR: /* These don't change whether an object is non-zero or zero. */ - return truthvalue_conversion (TREE_OPERAND (expr, 0)); + return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)); case LROTATE_EXPR: case RROTATE_EXPR: @@ -2189,15 +2190,15 @@ truthvalue_conversion (expr) 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), - truthvalue_conversion (TREE_OPERAND (expr, 0))); + c_common_truthvalue_conversion (TREE_OPERAND (expr, 0))); else - return truthvalue_conversion (TREE_OPERAND (expr, 0)); + 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), - truthvalue_conversion (TREE_OPERAND (expr, 1)), - truthvalue_conversion (TREE_OPERAND (expr, 2)))); + c_common_truthvalue_conversion (TREE_OPERAND (expr, 1)), + c_common_truthvalue_conversion (TREE_OPERAND (expr, 2)))); case CONVERT_EXPR: /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE, @@ -2210,7 +2211,7 @@ truthvalue_conversion (expr) /* If this is widening the argument, we can ignore it. */ if (TYPE_PRECISION (TREE_TYPE (expr)) >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0)))) - return truthvalue_conversion (TREE_OPERAND (expr, 0)); + return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)); break; case MINUS_EXPR: @@ -2255,12 +2256,12 @@ truthvalue_conversion (expr) if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE) { - tree tem = save_expr (expr); + tree t = save_expr (expr); return (build_binary_op ((TREE_SIDE_EFFECTS (expr) ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), - truthvalue_conversion (build_unary_op (REALPART_EXPR, tem, 0)), - truthvalue_conversion (build_unary_op (IMAGPART_EXPR, tem, 0)), + c_common_truthvalue_conversion (build_unary_op (REALPART_EXPR, t, 0)), + c_common_truthvalue_conversion (build_unary_op (IMAGPART_EXPR, t, 0)), 0)); } diff --git a/gcc/c-common.h b/gcc/c-common.h index cb49b529e80c..462e5bd79338 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -513,6 +513,7 @@ extern tree c_common_type_for_size PARAMS ((unsigned int, int)); extern tree c_common_unsigned_type PARAMS ((tree)); extern tree c_common_signed_type PARAMS ((tree)); extern tree c_common_signed_or_unsigned_type PARAMS ((int, tree)); +extern tree c_common_truthvalue_conversion PARAMS ((tree)); extern void c_apply_type_quals_to_decl PARAMS ((int, tree)); extern tree c_sizeof PARAMS ((tree)); extern tree c_alignof PARAMS ((tree)); diff --git a/gcc/c-convert.c b/gcc/c-convert.c index 947c79bcadb3..b38eab2dbabb 100644 --- a/gcc/c-convert.c +++ b/gcc/c-convert.c @@ -42,7 +42,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA Here is a list of all the functions that assume that widening and narrowing is always done with a NOP_EXPR: In convert.c, convert_to_integer. - In c-typeck.c, build_binary_op (boolean ops), and truthvalue_conversion. + In c-typeck.c, build_binary_op (boolean ops), and + c_common_truthvalue_conversion. In expr.c: expand_expr, for operands of a MULT_EXPR. In fold-const.c: fold. In tree.c: get_narrower and get_unwidened. */ @@ -90,9 +91,9 @@ convert (type, expr) return fold (convert_to_integer (type, e)); if (code == BOOLEAN_TYPE) { - tree t = truthvalue_conversion (expr); - /* If truthvalue_conversion returns a NOP_EXPR, we must fold it here - to avoid infinite recursion between fold () and convert (). */ + tree t = c_common_truthvalue_conversion (expr); + /* If it returns a NOP_EXPR, we must fold it here to avoid + infinite recursion between fold () and convert (). */ if (TREE_CODE (t) == NOP_EXPR) return fold (build1 (NOP_EXPR, type, TREE_OPERAND (t, 0))); else diff --git a/gcc/c-lang.c b/gcc/c-lang.c index f11dce4a892b..57d81968fe46 100644 --- a/gcc/c-lang.c +++ b/gcc/c-lang.c @@ -58,6 +58,8 @@ static void c_post_options PARAMS ((void)); #define LANG_HOOKS_MARK_ADDRESSABLE c_mark_addressable #undef LANG_HOOKS_PARSE_FILE #define LANG_HOOKS_PARSE_FILE c_common_parse_file +#undef LANG_HOOKS_TRUTHVALUE_CONVERSION +#define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion #undef LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES #define LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES c_insert_default_attributes #undef LANG_HOOKS_FINISH_INCOMPLETE_DECL diff --git a/gcc/c-parse.in b/gcc/c-parse.in index fa56bfcfce75..e6d61378b9bd 100644 --- a/gcc/c-parse.in +++ b/gcc/c-parse.in @@ -566,19 +566,22 @@ expr_no_commas: | expr_no_commas '^' expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas ANDAND - { $1 = truthvalue_conversion (default_conversion ($1)); + { $1 = c_common_truthvalue_conversion + (default_conversion ($1)); skip_evaluation += $1 == boolean_false_node; } expr_no_commas { skip_evaluation -= $1 == boolean_false_node; $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); } | expr_no_commas OROR - { $1 = truthvalue_conversion (default_conversion ($1)); + { $1 = c_common_truthvalue_conversion + (default_conversion ($1)); skip_evaluation += $1 == boolean_true_node; } expr_no_commas { skip_evaluation -= $1 == boolean_true_node; $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); } | expr_no_commas '?' - { $1 = truthvalue_conversion (default_conversion ($1)); + { $1 = c_common_truthvalue_conversion + (default_conversion ($1)); skip_evaluation += $1 == boolean_false_node; } expr ':' { skip_evaluation += (($1 == boolean_true_node) @@ -591,7 +594,8 @@ expr_no_commas: pedwarn ("ISO C forbids omitting the middle term of a ?: expression"); /* Make sure first operand is calculated only once. */ $2 = save_expr ($1); - $1 = truthvalue_conversion (default_conversion ($2)); + $1 = c_common_truthvalue_conversion + (default_conversion ($2)); skip_evaluation += $1 == boolean_true_node; } ':' expr_no_commas { skip_evaluation -= $1 == boolean_true_node; @@ -606,7 +610,8 @@ expr_no_commas: | expr_no_commas ASSIGN expr_no_commas { char class; $$ = build_modify_expr ($1, $2, $3); - /* This inhibits warnings in truthvalue_conversion. */ + /* This inhibits warnings in + c_common_truthvalue_conversion. */ class = TREE_CODE_CLASS (TREE_CODE ($$)); if (IS_EXPR_CODE_CLASS (class)) C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); @@ -2189,7 +2194,7 @@ if_prefix: IF { $$ = c_begin_if_stmt (); } '(' expr ')' - { c_expand_start_cond (truthvalue_conversion ($4), + { c_expand_start_cond (c_common_truthvalue_conversion ($4), compstmt_count,$2); $$ = stmt_count; if_stmt_file = $-2; @@ -2301,15 +2306,15 @@ select_or_iter_stmt: { stmt_count++; $$ = c_begin_while_stmt (); } '(' expr ')' - { $4 = truthvalue_conversion ($4); - c_finish_while_stmt_cond (truthvalue_conversion ($4), - $2); + { $4 = c_common_truthvalue_conversion ($4); + c_finish_while_stmt_cond + (c_common_truthvalue_conversion ($4), $2); $$ = add_stmt ($2); } c99_block_lineno_labeled_stmt { RECHAIN_STMTS ($6, WHILE_BODY ($6)); } | do_stmt_start '(' expr ')' ';' - { DO_COND ($1) = truthvalue_conversion ($3); } + { DO_COND ($1) = c_common_truthvalue_conversion ($3); } | do_stmt_start error { } | FOR @@ -2321,7 +2326,8 @@ select_or_iter_stmt: RECHAIN_STMTS ($2, FOR_INIT_STMT ($2)); } xexpr ';' { if ($6) - FOR_COND ($2) = truthvalue_conversion ($6); } + FOR_COND ($2) + = c_common_truthvalue_conversion ($6); } xexpr ')' { FOR_EXPR ($2) = $9; } c99_block_lineno_labeled_stmt diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 7bca9aad5fe5..91abd80a4ba4 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -2084,8 +2084,8 @@ build_binary_op (code, orig_op0, orig_op1, convert_p) but that does not mean the operands should be converted to ints! */ result_type = integer_type_node; - op0 = truthvalue_conversion (op0); - op1 = truthvalue_conversion (op1); + op0 = c_common_truthvalue_conversion (op0); + op1 = c_common_truthvalue_conversion (op1); converted = 1; } break; @@ -2801,7 +2801,7 @@ build_unary_op (code, xarg, flag) error ("wrong type argument to unary exclamation mark"); return error_mark_node; } - arg = truthvalue_conversion (arg); + arg = c_common_truthvalue_conversion (arg); return invert_truthvalue (arg); case NOP_EXPR: @@ -3365,7 +3365,7 @@ build_conditional_expr (ifexp, op1, op2) tree result_type = NULL; tree orig_op1 = op1, orig_op2 = op2; - ifexp = truthvalue_conversion (default_conversion (ifexp)); + ifexp = c_common_truthvalue_conversion (default_conversion (ifexp)); #if 0 /* Produces wrong result if within sizeof. */ /* Don't promote the operands separately if they promote diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 756d2b30c631..cd2e9193ef0c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2002-04-04 Neil Booth + + * cp-lang.c (LANG_HOOKS_TRUTHVALUE_CONVERSION): Redefine. + * cvt.c: Update comment. + * init.c (expand_cleanup_for_base): Update. + * semantics.c (finish_parenthesized_expr): Update. + * typeck.c (cp_truthvalue_conversion): Update. + 2002-04-04 Jason Merrill * semantics.c (finish_eh_cleanup): New fn. diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c index 3c086ca81a86..0292719d341a 100644 --- a/gcc/cp/cp-lang.c +++ b/gcc/cp/cp-lang.c @@ -62,6 +62,8 @@ static bool cxx_warn_unused_global_decl PARAMS ((tree)); #define LANG_HOOKS_UNSAVE_EXPR_NOW cxx_unsave_expr_now #undef LANG_HOOKS_MAYBE_BUILD_CLEANUP #define LANG_HOOKS_MAYBE_BUILD_CLEANUP cxx_maybe_build_cleanup +#undef LANG_HOOKS_TRUTHVALUE_CONVERSION +#define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion #undef LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES #define LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES cxx_insert_default_attributes #undef LANG_HOOKS_MARK_TREE diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index d934df03de50..d0f9945fdaf3 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -52,7 +52,7 @@ static void warn_ref_binding PARAMS ((tree, tree, tree)); narrowing is always done with a NOP_EXPR: In convert.c, convert_to_integer. In c-typeck.c, build_binary_op_nodefault (boolean ops), - and truthvalue_conversion. + and c_common_truthvalue_conversion. In expr.c: expand_expr, for operands of a MULT_EXPR. In fold-const.c: fold. In tree.c: get_narrower and get_unwidened. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 8b7e1f239a43..57b3dba4658f 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -841,7 +841,7 @@ expand_cleanup_for_base (binfo, flag) (current_class_ref, binfo, base_dtor_identifier, NULL_TREE)); if (flag) expr = fold (build (COND_EXPR, void_type_node, - truthvalue_conversion (flag), + c_common_truthvalue_conversion (flag), expr, integer_zero_node)); finish_eh_cleanup (expr); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index ee609f453633..39f9567d0636 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1140,7 +1140,7 @@ finish_parenthesized_expr (expr) tree expr; { if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (expr)))) - /* This inhibits warnings in truthvalue_conversion. */ + /* This inhibits warnings in c_common_truthvalue_conversion. */ C_SET_EXP_ORIGINAL_CODE (expr, ERROR_MARK); if (TREE_CODE (expr) == OFFSET_REF) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 7596d297f4a8..593e2bb7efac 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4191,8 +4191,9 @@ build_x_unary_op (code, xarg) return exp; } -/* Like truthvalue_conversion, but handle pointer-to-member constants, where - a null value is represented by an INTEGER_CST of -1. */ +/* Like c_common_truthvalue_conversion, but handle pointer-to-member + constants, where a null value is represented by an INTEGER_CST of + -1. */ tree cp_truthvalue_conversion (expr) @@ -4202,7 +4203,7 @@ cp_truthvalue_conversion (expr) if (TYPE_PTRMEM_P (type)) return build_binary_op (NE_EXPR, expr, integer_zero_node, 1); else - return truthvalue_conversion (expr); + return c_common_truthvalue_conversion (expr); } /* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */ diff --git a/gcc/f/ChangeLog b/gcc/f/ChangeLog index e0fbdcde40f5..d522ff853b44 100644 --- a/gcc/f/ChangeLog +++ b/gcc/f/ChangeLog @@ -1,3 +1,9 @@ +Thu Apr 4 23:29:48 2002 Neil Booth + + * com.c (LANG_HOOKS_TRUTHVALUE_CONVERSION): Redefine. + (truthvalue_conversion): Rename. Update. Make static. + (ffecom_truth_value): Update. + Mon Apr 1 21:39:36 2002 Neil Booth * com.c (LANG_HOOKS_MARK_ADDRESSABLE): Redefine. diff --git a/gcc/f/com.c b/gcc/f/com.c index 97d245aa4a04..f99c209c7387 100644 --- a/gcc/f/com.c +++ b/gcc/f/com.c @@ -267,6 +267,7 @@ static tree ffe_unsigned_type PARAMS ((tree)); static tree ffe_signed_type PARAMS ((tree)); static tree ffe_signed_or_unsigned_type PARAMS ((int, tree)); static bool ffe_mark_addressable PARAMS ((tree)); +static tree ffe_truthvalue_conversion PARAMS ((tree)); static void ffecom_init_decl_processing PARAMS ((void)); static tree ffecom_arglist_expr_ (const char *argstring, ffebld args); static tree ffecom_widest_expr_type_ (ffebld list); @@ -13012,7 +13013,7 @@ ffecom_temp_label () tree ffecom_truth_value (tree expr) { - return truthvalue_conversion (expr); + return ffe_truthvalue_conversion (expr); } /* Return the inversion of a truth value (the inversion of what @@ -14236,6 +14237,8 @@ static void ffe_mark_tree (tree); #define LANG_HOOKS_DECL_PRINTABLE_NAME ffe_printable_name #undef LANG_HOOKS_PRINT_ERROR_FUNCTION #define LANG_HOOKS_PRINT_ERROR_FUNCTION ffe_print_error_function +#undef LANG_HOOKS_TRUTHVALUE_CONVERSION +#define LANG_HOOKS_TRUTHVALUE_CONVERSION ffe_truthvalue_conversion #undef LANG_HOOKS_TYPE_FOR_MODE #define LANG_HOOKS_TYPE_FOR_MODE ffe_type_for_mode @@ -14841,8 +14844,8 @@ ffe_signed_type (type) The resulting type should always be `integer_type_node'. */ -tree -truthvalue_conversion (expr) +static tree +ffe_truthvalue_conversion (expr) tree expr; { if (TREE_CODE (expr) == ERROR_MARK) @@ -14919,15 +14922,15 @@ truthvalue_conversion (expr) return ffecom_2 ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)) ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), integer_type_node, - truthvalue_conversion (TREE_OPERAND (expr, 0)), - truthvalue_conversion (TREE_OPERAND (expr, 1))); + ffe_truthvalue_conversion (TREE_OPERAND (expr, 0)), + ffe_truthvalue_conversion (TREE_OPERAND (expr, 1))); case NEGATE_EXPR: case ABS_EXPR: case FLOAT_EXPR: case FFS_EXPR: /* These don't change whether an object is non-zero or zero. */ - return truthvalue_conversion (TREE_OPERAND (expr, 0)); + return ffe_truthvalue_conversion (TREE_OPERAND (expr, 0)); case LROTATE_EXPR: case RROTATE_EXPR: @@ -14935,15 +14938,15 @@ truthvalue_conversion (expr) we can't ignore them if their second arg has side-effects. */ if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))) return build (COMPOUND_EXPR, integer_type_node, TREE_OPERAND (expr, 1), - truthvalue_conversion (TREE_OPERAND (expr, 0))); + ffe_truthvalue_conversion (TREE_OPERAND (expr, 0))); else - return truthvalue_conversion (TREE_OPERAND (expr, 0)); + return ffe_truthvalue_conversion (TREE_OPERAND (expr, 0)); case COND_EXPR: /* Distribute the conversion into the arms of a COND_EXPR. */ return fold (build (COND_EXPR, integer_type_node, TREE_OPERAND (expr, 0), - truthvalue_conversion (TREE_OPERAND (expr, 1)), - truthvalue_conversion (TREE_OPERAND (expr, 2)))); + ffe_truthvalue_conversion (TREE_OPERAND (expr, 1)), + ffe_truthvalue_conversion (TREE_OPERAND (expr, 2)))); case CONVERT_EXPR: /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE, @@ -14956,7 +14959,7 @@ truthvalue_conversion (expr) /* If this is widening the argument, we can ignore it. */ if (TYPE_PRECISION (TREE_TYPE (expr)) >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0)))) - return truthvalue_conversion (TREE_OPERAND (expr, 0)); + return ffe_truthvalue_conversion (TREE_OPERAND (expr, 0)); break; case MINUS_EXPR: @@ -15001,12 +15004,12 @@ truthvalue_conversion (expr) ((TREE_SIDE_EFFECTS (expr) ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), integer_type_node, - truthvalue_conversion (ffecom_1 (REALPART_EXPR, - TREE_TYPE (TREE_TYPE (expr)), - expr)), - truthvalue_conversion (ffecom_1 (IMAGPART_EXPR, - TREE_TYPE (TREE_TYPE (expr)), - expr)))); + ffe_truthvalue_conversion (ffecom_1 (REALPART_EXPR, + TREE_TYPE (TREE_TYPE (expr)), + expr)), + ffe_truthvalue_conversion (ffecom_1 (IMAGPART_EXPR, + TREE_TYPE (TREE_TYPE (expr)), + expr)))); return ffecom_2 (NE_EXPR, integer_type_node, expr, diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 26bdd668bd28..10a92fe412b9 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4139,8 +4139,8 @@ constant_boolean_node (value, type) if (type == integer_type_node) return value ? integer_one_node : integer_zero_node; else if (TREE_CODE (type) == BOOLEAN_TYPE) - return truthvalue_conversion (value ? integer_one_node : - integer_zero_node); + return (*lang_hooks.truthvalue_conversion) (value ? integer_one_node : + integer_zero_node); else { tree t = build_int_2 (value, 0); @@ -6405,7 +6405,7 @@ fold (expr) TREE_TYPE (t1) = type; if (TREE_CODE (type) == BOOLEAN_TYPE) - return truthvalue_conversion (t1); + return (*lang_hooks.truthvalue_conversion) (t1); return t1; case COND_EXPR: diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 8b5ef4ebac78..ae7090115283 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,10 @@ +2002-04-04 Neil Booth + + * expr.c (truthvalue_conversion): Rename. Update. + (expand_compare): Update. + * java-tree.h (java_truthvalue_conversion): New. + * lang.c (LANG_HOOKS_TRUTHVALUE_CONVERSION): Redefine. + 2002-04-01 Neil Booth * java-tree.h (java_mark_addressable): New. diff --git a/gcc/java/expr.c b/gcc/java/expr.c index a4ecfb077c88..bba81d5e6833 100644 --- a/gcc/java/expr.c +++ b/gcc/java/expr.c @@ -152,7 +152,7 @@ init_expr_processing() } tree -truthvalue_conversion (expr) +java_truthvalue_conversion (expr) tree expr; { /* It is simpler and generates better code to have only TRUTH_*_EXPR @@ -183,19 +183,19 @@ truthvalue_conversion (expr) case FLOAT_EXPR: case FFS_EXPR: /* These don't change whether an object is non-zero or zero. */ - return truthvalue_conversion (TREE_OPERAND (expr, 0)); + return java_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), - truthvalue_conversion (TREE_OPERAND (expr, 1)), - truthvalue_conversion (TREE_OPERAND (expr, 2)))); + java_truthvalue_conversion (TREE_OPERAND (expr, 1)), + java_truthvalue_conversion (TREE_OPERAND (expr, 2)))); case NOP_EXPR: /* If this is widening the argument, we can ignore it. */ if (TYPE_PRECISION (TREE_TYPE (expr)) >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0)))) - return truthvalue_conversion (TREE_OPERAND (expr, 0)); + return java_truthvalue_conversion (TREE_OPERAND (expr, 0)); /* fall through to default */ default: @@ -1656,7 +1656,7 @@ expand_compare (condition, value1, value2, target_pc) { tree target = lookup_label (target_pc); tree cond = fold (build (condition, boolean_type_node, value1, value2)); - expand_start_cond (truthvalue_conversion (cond), 0); + expand_start_cond (java_truthvalue_conversion (cond), 0); expand_goto (target); expand_end_cond (); } diff --git a/gcc/java/java-tree.h b/gcc/java/java-tree.h index ae26b61cda18..84a2afb76ca7 100644 --- a/gcc/java/java-tree.h +++ b/gcc/java/java-tree.h @@ -1045,6 +1045,7 @@ extern tree java_type_for_size PARAMS ((unsigned int, int)); extern tree java_unsigned_type PARAMS ((tree)); extern tree java_signed_type PARAMS ((tree)); extern tree java_signed_or_unsigned_type PARAMS ((int, tree)); +extern tree java_truthvalue_conversion PARAMS ((tree)); extern void add_assume_compiled PARAMS ((const char *, int)); extern tree lookup_class PARAMS ((tree)); extern tree lookup_java_constructor PARAMS ((tree, tree)); diff --git a/gcc/java/lang.c b/gcc/java/lang.c index 53e11beaed30..dbd41ee03c13 100644 --- a/gcc/java/lang.c +++ b/gcc/java/lang.c @@ -233,6 +233,8 @@ static int dependency_tracking = 0; #define LANG_HOOKS_MARK_ADDRESSABLE java_mark_addressable #undef LANG_HOOKS_EXPAND_EXPR #define LANG_HOOKS_EXPAND_EXPR java_expand_expr +#undef LANG_HOOKS_TRUTHVALUE_CONVERSION +#define LANG_HOOKS_TRUTHVALUE_CONVERSION java_truthvalue_conversion #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL java_dup_lang_specific_decl #undef LANG_HOOKS_DECL_PRINTABLE_NAME diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h index d073ddf56cab..3ad37f8f2f56 100644 --- a/gcc/langhooks-def.h +++ b/gcc/langhooks-def.h @@ -204,6 +204,7 @@ int lhd_tree_dump_type_quals PARAMS ((tree)); LANG_HOOKS_GET_ALIAS_SET, \ LANG_HOOKS_EXPAND_CONSTANT, \ LANG_HOOKS_EXPAND_EXPR, \ + LANG_HOOKS_TRUTHVALUE_CONVERSION, \ LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES, \ LANG_HOOKS_SAFE_FROM_P, \ LANG_HOOKS_FINISH_INCOMPLETE_DECL, \ diff --git a/gcc/langhooks.h b/gcc/langhooks.h index 83e2e5abdb9f..2a50aa78fa70 100644 --- a/gcc/langhooks.h +++ b/gcc/langhooks.h @@ -200,6 +200,19 @@ struct lang_hooks Fourth argument is actually an enum expand_modifier. */ rtx (*expand_expr) PARAMS ((tree, rtx, enum machine_mode, int)); + /* Prepare expr to be an argument of a TRUTH_NOT_EXPR or other logical + operation. + + 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, integer_zero_node, 1), + but we optimize comparisons, &&, ||, and !. + + The result should be an expression of boolean type (if not an + error_mark_node). */ + tree (*truthvalue_conversion) PARAMS ((tree)); + /* Possibly apply default attributes to a function (represented by a FUNCTION_DECL). */ void (*insert_default_attributes) PARAMS ((tree)); diff --git a/gcc/objc/objc-lang.c b/gcc/objc/objc-lang.c index b1194324f79c..6649d723e973 100644 --- a/gcc/objc/objc-lang.c +++ b/gcc/objc/objc-lang.c @@ -52,6 +52,8 @@ static void objc_post_options PARAMS ((void)); #define LANG_HOOKS_EXPAND_EXPR c_expand_expr #undef LANG_HOOKS_MARK_ADDRESSABLE #define LANG_HOOKS_MARK_ADDRESSABLE c_mark_addressable +#undef LANG_HOOKS_TRUTHVALUE_CONVERSION +#define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion #undef LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES #define LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES c_insert_default_attributes #undef LANG_HOOKS_FINISH_INCOMPLETE_DECL diff --git a/gcc/stmt.c b/gcc/stmt.c index 2e8aeb628c67..4f0cb1795476 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -4119,7 +4119,7 @@ expand_decl_cleanup (decl, cleanup) /* Conditionalize the cleanup. */ cleanup = build (COND_EXPR, void_type_node, - truthvalue_conversion (cond), + (*lang_hooks.truthvalue_conversion) (cond), cleanup, integer_zero_node); cleanup = fold (cleanup); diff --git a/gcc/tree.h b/gcc/tree.h index 950463f63727..d0646b8042ab 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -2946,7 +2946,6 @@ extern int lang_attribute_common; /* In front end. */ extern void incomplete_type_error PARAMS ((tree, tree)); -extern tree truthvalue_conversion PARAMS ((tree)); /* In integrate.c */ extern void save_for_inline PARAMS ((tree));