/* Subroutines common to both C and C++ pretty-printers.
- Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
+ Free Software Foundation, Inc.
Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
for more details.
You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING. If not, write to the Free
-Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA. */
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "real.h"
+#include "fixed-value.h"
#include "c-pretty-print.h"
#include "c-tree.h"
#include "tree-iterator.h"
{
tree pointee = strip_pointer_operator (TREE_TYPE (t));
if (TREE_CODE (pointee) != ARRAY_TYPE
- && TREE_CODE (pointee) != FUNCTION_TYPE)
- pp_c_whitespace (pp);
+ && TREE_CODE (pointee) != FUNCTION_TYPE)
+ pp_c_whitespace (pp);
}
}
void
pp_c_type_qualifier_list (c_pretty_printer *pp, tree t)
{
- int qualifiers;
+ int qualifiers;
+
+ if (!t || t == error_mark_node)
+ return;
if (!TYPE_P (t))
t = TREE_TYPE (t);
/* It is easier to handle C++ reference types here. */
case REFERENCE_TYPE:
if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
- pp_c_pointer (pp, TREE_TYPE (t));
+ pp_c_pointer (pp, TREE_TYPE (t));
if (TREE_CODE (t) == POINTER_TYPE)
- pp_c_star (pp);
+ pp_c_star (pp);
else
- pp_c_ampersand (pp);
+ pp_c_ampersand (pp);
pp_c_type_qualifier_list (pp, t);
break;
case VOID_TYPE:
case BOOLEAN_TYPE:
- case CHAR_TYPE:
case INTEGER_TYPE:
case REAL_TYPE:
+ case FIXED_POINT_TYPE:
if (TYPE_NAME (t))
{
t = TYPE_NAME (t);
else
{
int prec = TYPE_PRECISION (t);
- t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t));
+ if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t)))
+ t = c_common_type_for_mode (TYPE_MODE (t), TYPE_SATURATING (t));
+ else
+ t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t));
if (TYPE_NAME (t))
{
pp_c_type_specifier (pp, t);
case REAL_TYPE:
pp_string (pp, "<unnamed-float:");
break;
+ case FIXED_POINT_TYPE:
+ pp_string (pp, "<unnamed-fixed:");
+ break;
default:
gcc_unreachable ();
}
case REFERENCE_TYPE:
case POINTER_TYPE:
{
- /* Get the types-specifier of this type. */
- tree pointee = strip_pointer_operator (TREE_TYPE (t));
- pp_c_specifier_qualifier_list (pp, pointee);
- if (TREE_CODE (pointee) == ARRAY_TYPE
- || TREE_CODE (pointee) == FUNCTION_TYPE)
- {
- pp_c_whitespace (pp);
- pp_c_left_paren (pp);
- }
+ /* Get the types-specifier of this type. */
+ tree pointee = strip_pointer_operator (TREE_TYPE (t));
+ pp_c_specifier_qualifier_list (pp, pointee);
+ if (TREE_CODE (pointee) == ARRAY_TYPE
+ || TREE_CODE (pointee) == FUNCTION_TYPE)
+ {
+ pp_c_whitespace (pp);
+ pp_c_left_paren (pp);
+ }
else if (!c_dialect_cxx ())
pp_c_whitespace (pp);
- pp_ptr_operator (pp, t);
+ pp_ptr_operator (pp, t);
}
break;
case COMPLEX_TYPE:
pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
if (code == COMPLEX_TYPE)
- pp_c_identifier (pp, flag_isoc99 ? "_Complex" : "__complex__");
+ pp_c_identifier (pp, flag_isoc99 ? "_Complex" : "__complex__");
else if (code == VECTOR_TYPE)
- pp_c_identifier (pp, "__vector__");
+ pp_c_identifier (pp, "__vector__");
break;
default:
{
bool first = true;
for ( ; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
- {
- if (!first)
- pp_separate_with (pp, ',');
- first = false;
- pp_declaration_specifiers
- (pp, want_parm_decl ? parms : TREE_VALUE (parms));
- if (want_parm_decl)
- pp_declarator (pp, parms);
- else
- pp_abstract_declarator (pp, TREE_VALUE (parms));
- }
+ {
+ if (!first)
+ pp_separate_with (pp, ',');
+ first = false;
+ pp_declaration_specifiers
+ (pp, want_parm_decl ? parms : TREE_VALUE (parms));
+ if (want_parm_decl)
+ pp_declarator (pp, parms);
+ else
+ pp_abstract_declarator (pp, TREE_VALUE (parms));
+ }
}
pp_c_right_paren (pp);
}
if (TREE_CODE (t) == POINTER_TYPE)
{
if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
- || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
- pp_c_right_paren (pp);
+ || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
+ pp_c_right_paren (pp);
t = TREE_TYPE (t);
}
case ARRAY_TYPE:
pp_c_left_bracket (pp);
if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t)))
- pp_expression (pp, TYPE_MAX_VALUE (TYPE_DOMAIN (t)));
+ {
+ tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (t));
+ tree type = TREE_TYPE (maxval);
+
+ if (host_integerp (maxval, 0))
+ pp_wide_integer (pp, tree_low_cst (maxval, 0) + 1);
+ else
+ pp_expression (pp, fold_build2 (PLUS_EXPR, type, maxval,
+ build_int_cst (type, 1)));
+ }
pp_c_right_bracket (pp);
pp_direct_abstract_declarator (pp, TREE_TYPE (t));
break;
case BOOLEAN_TYPE:
case INTEGER_TYPE:
case REAL_TYPE:
+ case FIXED_POINT_TYPE:
case ENUMERAL_TYPE:
case RECORD_TYPE:
case UNION_TYPE:
else if (DECL_P (t))
{
if (DECL_REGISTER (t))
- pp_c_identifier (pp, "register");
+ pp_c_identifier (pp, "register");
else if (TREE_STATIC (t) && TREE_CODE (t) == VAR_DECL)
- pp_c_identifier (pp, "static");
+ pp_c_identifier (pp, "static");
}
}
pp_c_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
pp_c_tree_decl_identifier (pp, t);
if (pp_c_base (pp)->flags & pp_c_flag_abstract)
- pp_abstract_declarator (pp, TREE_TYPE (t));
+ pp_abstract_declarator (pp, TREE_TYPE (t));
else
- {
- pp_parameter_list (pp, t);
- pp_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t)));
- }
+ {
+ pp_parameter_list (pp, t);
+ pp_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t)));
+ }
break;
case INTEGER_TYPE:
case REAL_TYPE:
+ case FIXED_POINT_TYPE:
case ENUMERAL_TYPE:
case UNION_TYPE:
case RECORD_TYPE:
{
case INTEGER_TYPE:
case REAL_TYPE:
+ case FIXED_POINT_TYPE:
case ENUMERAL_TYPE:
case UNION_TYPE:
case RECORD_TYPE:
{
pp_tree_identifier (pp, TREE_PURPOSE (attributes));
if (TREE_VALUE (attributes))
- pp_c_call_argument_list (pp, TREE_VALUE (attributes));
+ pp_c_call_argument_list (pp, TREE_VALUE (attributes));
if (TREE_CHAIN (attributes))
pp_separate_with (pp, ',');
pp_wide_integer (pp, TREE_INT_CST_LOW (i));
else
{
+ unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (i);
+ HOST_WIDE_INT high = TREE_INT_CST_HIGH (i);
if (tree_int_cst_sgn (i) < 0)
- {
- pp_character (pp, '-');
- i = build_int_cst_wide (NULL_TREE,
- -TREE_INT_CST_LOW (i),
- ~TREE_INT_CST_HIGH (i)
- + !TREE_INT_CST_LOW (i));
- }
+ {
+ pp_character (pp, '-');
+ high = ~high + !low;
+ low = -low;
+ }
sprintf (pp_buffer (pp)->digit_buffer,
- HOST_WIDE_INT_PRINT_DOUBLE_HEX,
- TREE_INT_CST_HIGH (i), TREE_INT_CST_LOW (i));
+ HOST_WIDE_INT_PRINT_DOUBLE_HEX, high, low);
pp_string (pp, pp_buffer (pp)->digit_buffer);
}
if (TYPE_UNSIGNED (type))
if (type == long_integer_type_node || type == long_unsigned_type_node)
pp_character (pp, 'l');
else if (type == long_long_integer_type_node
- || type == long_long_unsigned_type_node)
+ || type == long_long_unsigned_type_node)
pp_string (pp, "ll");
}
pp_string (pp, "df");
}
+/* Print out a FIXED value as a decimal-floating-constant. */
+
+static void
+pp_c_fixed_constant (c_pretty_printer *pp, tree r)
+{
+ fixed_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_FIXED_CST (r),
+ sizeof (pp_buffer (pp)->digit_buffer));
+ pp_string (pp, pp_buffer(pp)->digit_buffer);
+}
+
/* Pretty-print a compound literal expression. GNU extensions include
vector constants. */
/* constant:
integer-constant
floating-constant
+ fixed-point-constant
enumeration-constant
character-constant */
{
case INTEGER_CST:
{
- tree type = TREE_TYPE (e);
- if (type == boolean_type_node)
- pp_c_bool_constant (pp, e);
- else if (type == char_type_node)
- pp_c_character_constant (pp, e);
- else if (TREE_CODE (type) == ENUMERAL_TYPE
- && pp_c_enumeration_constant (pp, e))
- ;
- else
- pp_c_integer_constant (pp, e);
+ tree type = TREE_TYPE (e);
+ if (type == boolean_type_node)
+ pp_c_bool_constant (pp, e);
+ else if (type == char_type_node)
+ pp_c_character_constant (pp, e);
+ else if (TREE_CODE (type) == ENUMERAL_TYPE
+ && pp_c_enumeration_constant (pp, e))
+ ;
+ else
+ pp_c_integer_constant (pp, e);
}
break;
pp_c_floating_constant (pp, e);
break;
+ case FIXED_CST:
+ pp_c_fixed_constant (pp, e);
+ break;
+
case STRING_CST:
pp_c_string_literal (pp, e);
break;
+ case COMPLEX_CST:
+ /* Sometimes, we are confused and we think a complex literal
+ is a constant. Such thing is a compound literal which
+ grammatically belongs to postifx-expr production. */
+ pp_c_compound_literal (pp, e);
+ break;
+
default:
pp_unsupported_tree (pp, e);
break;
case INTEGER_CST:
case REAL_CST:
+ case FIXED_CST:
case STRING_CST:
pp_c_constant (pp, e);
break;
{
tree init = DECL_INITIAL (t);
/* This C++ bit is handled here because it is easier to do so.
- In templates, the C++ parser builds a TREE_LIST for a
- direct-initialization; the TREE_PURPOSE is the variable to
- initialize and the TREE_VALUE is the initializer. */
+ In templates, the C++ parser builds a TREE_LIST for a
+ direct-initialization; the TREE_PURPOSE is the variable to
+ initialize and the TREE_VALUE is the initializer. */
if (TREE_CODE (init) == TREE_LIST)
- {
- pp_c_left_paren (pp);
- pp_expression (pp, TREE_VALUE (init));
- pp_right_paren (pp);
- }
+ {
+ pp_c_left_paren (pp);
+ pp_expression (pp, TREE_VALUE (init));
+ pp_right_paren (pp);
+ }
else
- {
- pp_space (pp);
- pp_equal (pp);
- pp_space (pp);
- pp_c_initializer (pp, init);
- }
+ {
+ pp_space (pp);
+ pp_equal (pp);
+ pp_space (pp);
+ pp_c_initializer (pp, init);
+ }
}
}
case UNION_TYPE:
case ARRAY_TYPE:
{
- tree init = TREE_OPERAND (e, 0);
- for (; init != NULL_TREE; init = TREE_CHAIN (init))
- {
- if (code == RECORD_TYPE || code == UNION_TYPE)
- {
- pp_c_dot (pp);
- pp_c_primary_expression (pp, TREE_PURPOSE (init));
- }
- else
- {
- pp_c_left_bracket (pp);
- if (TREE_PURPOSE (init))
- pp_c_constant (pp, TREE_PURPOSE (init));
- pp_c_right_bracket (pp);
- }
- pp_c_whitespace (pp);
- pp_equal (pp);
- pp_c_whitespace (pp);
- pp_initializer (pp, TREE_VALUE (init));
- if (TREE_CHAIN (init))
- pp_separate_with (pp, ',');
- }
+ tree init = TREE_OPERAND (e, 0);
+ for (; init != NULL_TREE; init = TREE_CHAIN (init))
+ {
+ if (code == RECORD_TYPE || code == UNION_TYPE)
+ {
+ pp_c_dot (pp);
+ pp_c_primary_expression (pp, TREE_PURPOSE (init));
+ }
+ else
+ {
+ pp_c_left_bracket (pp);
+ if (TREE_PURPOSE (init))
+ pp_c_constant (pp, TREE_PURPOSE (init));
+ pp_c_right_bracket (pp);
+ }
+ pp_c_whitespace (pp);
+ pp_equal (pp);
+ pp_c_whitespace (pp);
+ pp_initializer (pp, TREE_VALUE (init));
+ if (TREE_CHAIN (init))
+ pp_separate_with (pp, ',');
+ }
}
return;
case VECTOR_TYPE:
if (TREE_CODE (e) == VECTOR_CST)
- pp_c_expression_list (pp, TREE_VECTOR_CST_ELTS (e));
+ pp_c_expression_list (pp, TREE_VECTOR_CST_ELTS (e));
else if (TREE_CODE (e) == CONSTRUCTOR)
- pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e));
+ pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e));
else
- break;
+ break;
return;
case COMPLEX_TYPE:
break;
case CALL_EXPR:
- pp_postfix_expression (pp, TREE_OPERAND (e, 0));
- pp_c_call_argument_list (pp, TREE_OPERAND (e, 1));
- break;
+ {
+ call_expr_arg_iterator iter;
+ tree arg;
+ pp_postfix_expression (pp, CALL_EXPR_FN (e));
+ pp_c_left_paren (pp);
+ FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
+ {
+ pp_expression (pp, arg);
+ if (more_call_expr_args_p (&iter))
+ pp_separate_with (pp, ',');
+ }
+ pp_c_right_paren (pp);
+ break;
+ }
case UNORDERED_EXPR:
pp_c_identifier (pp, flag_isoc99
case ADDR_EXPR:
if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
- {
- pp_c_id_expression (pp, TREE_OPERAND (e, 0));
- break;
- }
+ {
+ pp_c_id_expression (pp, TREE_OPERAND (e, 0));
+ break;
+ }
/* else fall through. */
default:
}
}
-/* Print out an expression-list in parens, as in a function call. */
+/* Print out an expression-list in parens, as if it were the argument
+ list to a function. */
void
pp_c_call_argument_list (c_pretty_printer *pp, tree t)
enum tree_code code = TREE_CODE (e);
switch (code)
{
+ case POINTER_PLUS_EXPR:
case PLUS_EXPR:
case MINUS_EXPR:
pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
pp_c_whitespace (pp);
- if (code == PLUS_EXPR)
+ if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
pp_plus (pp);
else
pp_minus (pp);
static void
pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e)
{
- if (TREE_CODE (e) == BIT_XOR_EXPR)
+ if (TREE_CODE (e) == BIT_XOR_EXPR
+ || TREE_CODE (e) == TRUTH_XOR_EXPR)
{
pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
- pp_c_maybe_whitespace (pp);
+ if (TREE_CODE (e) == BIT_XOR_EXPR)
+ pp_c_maybe_whitespace (pp);
+ else
+ pp_c_whitespace (pp);
pp_carret (pp);
pp_c_whitespace (pp);
pp_c_and_expression (pp, TREE_OPERAND (e, 1));
static void
pp_c_logical_and_expression (c_pretty_printer *pp, tree e)
{
- if (TREE_CODE (e) == TRUTH_ANDIF_EXPR)
+ if (TREE_CODE (e) == TRUTH_ANDIF_EXPR
+ || TREE_CODE (e) == TRUTH_AND_EXPR)
{
pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0));
pp_c_whitespace (pp);
void
pp_c_logical_or_expression (c_pretty_printer *pp, tree e)
{
- if (TREE_CODE (e) == TRUTH_ORIF_EXPR)
+ if (TREE_CODE (e) == TRUTH_ORIF_EXPR
+ || TREE_CODE (e) == TRUTH_OR_EXPR)
{
pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
pp_c_whitespace (pp);
static void
pp_c_assignment_expression (c_pretty_printer *pp, tree e)
{
- if (TREE_CODE (e) == MODIFY_EXPR || TREE_CODE (e) == INIT_EXPR)
+ if (TREE_CODE (e) == MODIFY_EXPR
+ || TREE_CODE (e) == GIMPLE_MODIFY_STMT
+ || TREE_CODE (e) == INIT_EXPR)
{
- pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
+ pp_c_unary_expression (pp, GENERIC_TREE_OPERAND (e, 0));
pp_c_whitespace (pp);
pp_equal (pp);
pp_space (pp);
- pp_c_expression (pp, TREE_OPERAND (e, 1));
+ pp_c_expression (pp, GENERIC_TREE_OPERAND (e, 1));
}
else
pp_c_conditional_expression (pp, e);
pp_c_floating_constant (pp, e);
break;
+ case FIXED_CST:
+ pp_c_fixed_constant (pp, e);
+ break;
+
case STRING_CST:
pp_c_string_literal (pp, e);
break;
break;
case BIT_XOR_EXPR:
+ case TRUTH_XOR_EXPR:
pp_c_exclusive_or_expression (pp, e);
break;
break;
case TRUTH_ANDIF_EXPR:
+ case TRUTH_AND_EXPR:
pp_c_logical_and_expression (pp, e);
break;
case TRUTH_ORIF_EXPR:
+ case TRUTH_OR_EXPR:
pp_c_logical_or_expression (pp, e);
break;
pp_conditional_expression (pp, e);
break;
+ case POINTER_PLUS_EXPR:
case PLUS_EXPR:
case MINUS_EXPR:
pp_c_additive_expression (pp, e);
break;
case MODIFY_EXPR:
+ case GIMPLE_MODIFY_STMT:
case INIT_EXPR:
pp_assignment_expression (pp, e);
break;
pp->statement = pp_c_statement;
+ pp->constant = pp_c_constant;
pp->id_expression = pp_c_id_expression;
pp->primary_expression = pp_c_primary_expression;
pp->postfix_expression = pp_c_postfix_expression;