c-objc-common.c (c_tree_printer): Tidy.

c/
	* c-objc-common.c (c_tree_printer): Tidy.
c-family/
	* c-pretty-print.h (c_pretty_printer::type_id): Now a virtual
	member function.
	(c_pretty_printer::storage_class_specifier): Likewise.
	(c_pretty_printer::initializer): Likewise.
	(pp_declaration): Remove.
	(pp_declaration_specifiers): Likewise.
	(pp_abstract_declarator): Likewise.
	(pp_declarator): Likewise.
	(pp_type_id): Likewise.
	(pp_statement): Likewise.
	(pp_constant): Likewise.
	(pp_id_expression): Likewise.
	(pp_primary_expression): Likewise.
	(pp_unary_expression): Likewise.
	(pp_multiplicative_expression): Likewise.
	(pp_conditional_expression): Likewise.
	(pp_assignment_expression): Likewise.
	(pp_expression): Likewise.
	(pp_c_type_id): Likewise.
	(pp_c_storage_class_specifier): Likewise.
	* c-pretty-print.c (pp_c_type_cast): Tidy.
	(pp_c_pointer): Likewise.
	(pp_c_type_specifier): Likewise.
	(pp_c_parameter_type_list): Likewise.
	(pp_c_function_definition): Likewise.
	(pp_c_init_declarator): Likewise.
	(pp_c_initializer_list): Likewise.
	(pp_c_constructor_elts): Likewise.
	(c_pretty_printer::direct_abstract_declarator): Likewise.
	(c_pretty_printer::declaration_specifiers): Likewise.
	(c_pretty_printer::primary_expression): Likewise.
	(c_pretty_printer::postfix_expression): Likewise.
	(c_pretty_printer::type_id): Rename from pp_c_type_id.
	(c_pretty_printer::storage_class_specifier): Rename from
	pp_c_storage_class_specifier.
	(c_pretty_printer::initializer): Rename from pp_c_initializer.
	(c_pretty_printer::c_pretty_printer): Do not assign to type_id,
	storage_class_specifier, initializer, offset_list, flags.

cp/
	* cxx-pretty-print.h (cxx_pretty_printer::type_id): Declare as
	overrider.
	* cxx-pretty-print.c (pp_cxx_storage_class_specifier): Remove.
	(pp_cxx_userdef_literal): Tidy.
	(pp_cxx_template_argument_list): Likewise.
	(pp_cxx_typeid_expression): Likewise.
	(pp_cxx_offsetof_expression_1): Likewise.
	(cxx_pretty_printer::postfix_expression): Likewise.
	(cxx_pretty_printer::unary_expression): Likewise.
	(cxx_pretty_printer::statement): Likewise.
	(cxx_pretty_printer::type_id): Rename from pp_cxx_type_id.
	(c_pretty_printer::cxx_pretty_printer): Do not assign to type_id.
	* error.c (dump_decl): Tidy.
	(dump_expr): Likewise.

From-SVN: r202203
This commit is contained in:
Gabriel Dos Reis 2013-09-03 09:52:19 +00:00 committed by Gabriel Dos Reis
parent fa3bf4cec9
commit 20059c8b38
9 changed files with 193 additions and 165 deletions

View File

@ -1,3 +1,44 @@
2013-09-03 Gabriel Dos Reis <gdr@integrable-solutions.net>
* c-pretty-print.h (c_pretty_printer::type_id): Now a virtual
member function.
(c_pretty_printer::storage_class_specifier): Likewise.
(c_pretty_printer::initializer): Likewise.
(pp_declaration): Remove.
(pp_declaration_specifiers): Likewise.
(pp_abstract_declarator): Likewise.
(pp_declarator): Likewise.
(pp_type_id): Likewise.
(pp_statement): Likewise.
(pp_constant): Likewise.
(pp_id_expression): Likewise.
(pp_primary_expression): Likewise.
(pp_unary_expression): Likewise.
(pp_multiplicative_expression): Likewise.
(pp_conditional_expression): Likewise.
(pp_assignment_expression): Likewise.
(pp_expression): Likewise.
(pp_c_type_id): Likewise.
(pp_c_storage_class_specifier): Likewise.
* c-pretty-print.c (pp_c_type_cast): Tidy.
(pp_c_pointer): Likewise.
(pp_c_type_specifier): Likewise.
(pp_c_parameter_type_list): Likewise.
(pp_c_function_definition): Likewise.
(pp_c_init_declarator): Likewise.
(pp_c_initializer_list): Likewise.
(pp_c_constructor_elts): Likewise.
(c_pretty_printer::direct_abstract_declarator): Likewise.
(c_pretty_printer::declaration_specifiers): Likewise.
(c_pretty_printer::primary_expression): Likewise.
(c_pretty_printer::postfix_expression): Likewise.
(c_pretty_printer::type_id): Rename from pp_c_type_id.
(c_pretty_printer::storage_class_specifier): Rename from
pp_c_storage_class_specifier.
(c_pretty_printer::initializer): Rename from pp_c_initializer.
(c_pretty_printer::c_pretty_printer): Do not assign to type_id,
storage_class_specifier, initializer, offset_list, flags.
2013-08-30 Marek Polacek <polacek@redhat.com>
* c-ubsan.c: New file.

View File

@ -208,7 +208,7 @@ static void
pp_c_type_cast (c_pretty_printer *pp, tree t)
{
pp_c_left_paren (pp);
pp_type_id (pp, t);
pp->type_id (t);
pp_c_right_paren (pp);
}
@ -296,7 +296,7 @@ pp_c_pointer (c_pretty_printer *pp, tree t)
/* ??? This node is now in GENERIC and so shouldn't be here. But
we'll fix that later. */
case DECL_EXPR:
pp_declaration (pp, DECL_EXPR_DECL (t));
pp->declaration (DECL_EXPR_DECL (t));
pp_needs_newline (pp) = true;
break;
@ -393,7 +393,7 @@ pp_c_type_specifier (c_pretty_printer *pp, tree t)
case TYPE_DECL:
if (DECL_NAME (t))
pp_id_expression (pp, t);
pp->id_expression (t);
else
pp->translate_string ("<typedef-error>");
break;
@ -411,7 +411,7 @@ pp_c_type_specifier (c_pretty_printer *pp, tree t)
pp->translate_string ("<tag-error>");
if (TYPE_NAME (t))
pp_id_expression (pp, TYPE_NAME (t));
pp->id_expression (TYPE_NAME (t));
else
pp->translate_string ("<anonymous>");
break;
@ -431,7 +431,7 @@ pp_c_type_specifier (c_pretty_printer *pp, tree t)
function declarations, this routine prints not just the
specifier-qualifier-list of such entities or types of such entities,
but also the 'pointer' production part of their declarators. The
remaining part is done by pp_declarator or pp_abstract_declarator. */
remaining part is done by declarator() or abstract_declarator(). */
void
pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree t)
@ -518,12 +518,12 @@ pp_c_parameter_type_list (c_pretty_printer *pp, tree t)
if (!first)
pp_separate_with (pp, ',');
first = false;
pp_declaration_specifiers
(pp, want_parm_decl ? parms : TREE_VALUE (parms));
pp->declaration_specifiers
(want_parm_decl ? parms : TREE_VALUE (parms));
if (want_parm_decl)
pp_declarator (pp, parms);
pp->declarator (parms);
else
pp_abstract_declarator (pp, TREE_VALUE (parms));
pp->abstract_declarator (TREE_VALUE (parms));
}
}
pp_c_right_paren (pp);
@ -577,8 +577,8 @@ c_pretty_printer::direct_abstract_declarator (tree t)
if (host_integerp (maxval, 0))
pp_wide_integer (this, tree_low_cst (maxval, 0) + 1);
else
pp_expression (this, fold_build2 (PLUS_EXPR, type, maxval,
build_int_cst (type, 1)));
expression (fold_build2 (PLUS_EXPR, type, maxval,
build_int_cst (type, 1)));
}
pp_c_right_bracket (this);
direct_abstract_declarator (TREE_TYPE (t));
@ -608,10 +608,10 @@ c_pretty_printer::direct_abstract_declarator (tree t)
specifier-qualifier-list abstract-declarator(opt) */
void
pp_c_type_id (c_pretty_printer *pp, tree t)
c_pretty_printer::type_id (tree t)
{
pp_c_specifier_qualifier_list (pp, t);
pp_abstract_declarator (pp, t);
pp_c_specifier_qualifier_list (this, t);
abstract_declarator (t);
}
/* storage-class-specifier:
@ -622,16 +622,16 @@ pp_c_type_id (c_pretty_printer *pp, tree t)
register */
void
pp_c_storage_class_specifier (c_pretty_printer *pp, tree t)
c_pretty_printer::storage_class_specifier (tree t)
{
if (TREE_CODE (t) == TYPE_DECL)
pp_c_ws_string (pp, "typedef");
pp_c_ws_string (this, "typedef");
else if (DECL_P (t))
{
if (DECL_REGISTER (t))
pp_c_ws_string (pp, "register");
pp_c_ws_string (this, "register");
else if (TREE_STATIC (t) && TREE_CODE (t) == VAR_DECL)
pp_c_ws_string (pp, "static");
pp_c_ws_string (this, "static");
}
}
@ -654,8 +654,8 @@ c_pretty_printer::function_specifier (tree t)
void
c_pretty_printer::declaration_specifiers (tree t)
{
pp_storage_class_specifier (this, t);
pp_function_specifier (this, t);
storage_class_specifier (t);
function_specifier (t);
pp_c_specifier_qualifier_list (this, DECL_P (t) ? TREE_TYPE (t) : t);
}
@ -743,7 +743,7 @@ c_pretty_printer::declarator (tree t)
case FUNCTION_TYPE:
case FUNCTION_DECL:
case TYPE_DECL:
pp_direct_declarator (this, t);
direct_declarator (t);
break;
@ -834,8 +834,8 @@ pp_c_attributes_display (c_pretty_printer *pp, tree a)
void
pp_c_function_definition (c_pretty_printer *pp, tree t)
{
pp_declaration_specifiers (pp, t);
pp_declarator (pp, t);
pp->declaration_specifiers (t);
pp->declarator (t);
pp_needs_newline (pp) = true;
pp->statement (DECL_SAVED_TREE (t));
pp_newline_and_flush (pp);
@ -997,7 +997,7 @@ pp_c_enumeration_constant (c_pretty_printer *pp, tree e)
;
if (value != NULL_TREE)
pp_id_expression (pp, TREE_PURPOSE (value));
pp->id_expression (TREE_PURPOSE (value));
else
{
/* Value must have been cast. */
@ -1097,7 +1097,7 @@ pp_c_complex_expr (c_pretty_printer *pp, tree e)
== TREE_OPERAND (TREE_OPERAND (imagexpr, 0), 0))
{
pp_c_type_cast (pp, type);
pp_expression (pp, TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0));
pp->expression (TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0));
return;
}
@ -1108,7 +1108,7 @@ pp_c_complex_expr (c_pretty_printer *pp, tree e)
pp_c_type_cast (pp, type);
if (TREE_CODE (realexpr) == NOP_EXPR)
realexpr = TREE_OPERAND (realexpr, 0);
pp_expression (pp, realexpr);
pp->expression (realexpr);
return;
}
@ -1248,7 +1248,7 @@ c_pretty_printer::primary_expression (tree e)
primary_expression (TREE_OPERAND (e, 0));
pp_separate_with (this, ',');
pp_ampersand (this);
pp_initializer (this, TREE_OPERAND (e, 1));
initializer (TREE_OPERAND (e, 1));
if (TREE_OPERAND (e, 2))
{
pp_separate_with (this, ',');
@ -1260,7 +1260,7 @@ c_pretty_printer::primary_expression (tree e)
default:
/* FIXME: Make sure we won't get into an infinite loop. */
pp_c_left_paren (this);
pp_expression (this, e);
expression (e);
pp_c_right_paren (this);
break;
}
@ -1272,13 +1272,13 @@ c_pretty_printer::primary_expression (tree e)
{ initializer-list }
{ initializer-list , } */
static void
pp_c_initializer (c_pretty_printer *pp, tree e)
void
c_pretty_printer::initializer (tree e)
{
if (TREE_CODE (e) == CONSTRUCTOR)
pp_c_brace_enclosed_initializer_list (pp, e);
pp_c_brace_enclosed_initializer_list (this, e);
else
pp_expression (pp, e);
expression (e);
}
/* init-declarator:
@ -1288,7 +1288,7 @@ pp_c_initializer (c_pretty_printer *pp, tree e)
void
pp_c_init_declarator (c_pretty_printer *pp, tree t)
{
pp_declarator (pp, t);
pp->declarator (t);
/* We don't want to output function definitions here. There are handled
elsewhere (and the syntactic form is bogus anyway). */
if (TREE_CODE (t) != FUNCTION_DECL && DECL_INITIAL (t))
@ -1301,7 +1301,7 @@ pp_c_init_declarator (c_pretty_printer *pp, tree t)
if (TREE_CODE (init) == TREE_LIST)
{
pp_c_left_paren (pp);
pp_expression (pp, TREE_VALUE (init));
pp->expression (TREE_VALUE (init));
pp_right_paren (pp);
}
else
@ -1309,7 +1309,7 @@ pp_c_init_declarator (c_pretty_printer *pp, tree t)
pp_space (pp);
pp_equal (pp);
pp_space (pp);
pp_c_initializer (pp, init);
pp->initializer (init);
}
}
}
@ -1353,19 +1353,19 @@ pp_c_initializer_list (c_pretty_printer *pp, tree e)
if (code == RECORD_TYPE || code == UNION_TYPE)
{
pp_c_dot (pp);
pp_primary_expression (pp, TREE_PURPOSE (init));
pp->primary_expression (TREE_PURPOSE (init));
}
else
{
pp_c_left_bracket (pp);
if (TREE_PURPOSE (init))
pp_constant (pp, TREE_PURPOSE (init));
pp->constant (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));
pp->initializer (TREE_VALUE (init));
if (TREE_CHAIN (init))
pp_separate_with (pp, ',');
}
@ -1380,7 +1380,7 @@ pp_c_initializer_list (c_pretty_printer *pp, tree e)
{
if (i > 0)
pp_separate_with (pp, ',');
pp_expression (pp, VECTOR_CST_ELT (e, i));
pp->expression (VECTOR_CST_ELT (e, i));
}
}
else
@ -1391,9 +1391,9 @@ pp_c_initializer_list (c_pretty_printer *pp, tree e)
if (TREE_CODE (e) == COMPLEX_CST || TREE_CODE (e) == COMPLEX_EXPR)
{
const bool cst = TREE_CODE (e) == COMPLEX_CST;
pp_expression (pp, cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0));
pp->expression (cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0));
pp_separate_with (pp, ',');
pp_expression (pp, cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1));
pp->expression (cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1));
}
else
break;
@ -1474,18 +1474,18 @@ c_pretty_printer::postfix_expression (tree e)
case ARRAY_REF:
postfix_expression (TREE_OPERAND (e, 0));
pp_c_left_bracket (this);
pp_expression (this, TREE_OPERAND (e, 1));
expression (TREE_OPERAND (e, 1));
pp_c_right_bracket (this);
break;
case ARRAY_NOTATION_REF:
postfix_expression (ARRAY_NOTATION_ARRAY (e));
pp_c_left_bracket (this);
pp_expression (this, ARRAY_NOTATION_START (e));
expression (ARRAY_NOTATION_START (e));
pp_colon (this);
pp_expression (this, ARRAY_NOTATION_LENGTH (e));
expression (ARRAY_NOTATION_LENGTH (e));
pp_colon (this);
pp_expression (this, ARRAY_NOTATION_STRIDE (e));
expression (ARRAY_NOTATION_STRIDE (e));
pp_c_right_bracket (this);
break;
@ -1497,7 +1497,7 @@ c_pretty_printer::postfix_expression (tree e)
pp_c_left_paren (this);
FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
{
pp_expression (this, arg);
expression (arg);
if (more_call_expr_args_p (&iter))
pp_separate_with (this, ',');
}
@ -1555,16 +1555,16 @@ c_pretty_printer::postfix_expression (tree e)
two_args_fun:
pp_c_left_paren (this);
pp_expression (this, TREE_OPERAND (e, 0));
expression (TREE_OPERAND (e, 0));
pp_separate_with (this, ',');
pp_expression (this, TREE_OPERAND (e, 1));
expression (TREE_OPERAND (e, 1));
pp_c_right_paren (this);
break;
case ABS_EXPR:
pp_c_ws_string (this, "__builtin_abs");
pp_c_left_paren (this);
pp_expression (this, TREE_OPERAND (e, 0));
expression (TREE_OPERAND (e, 0));
pp_c_right_paren (this);
break;
@ -1581,7 +1581,7 @@ c_pretty_printer::postfix_expression (tree e)
postfix_expression (object);
pp_c_dot (this);
}
pp_expression (this, TREE_OPERAND (e, 1));
expression (TREE_OPERAND (e, 1));
}
break;
@ -1599,11 +1599,11 @@ c_pretty_printer::postfix_expression (tree e)
{
pp_c_left_paren (this);
pp_c_left_paren (this);
pp_type_id (this, type);
type_id (type);
pp_c_star (this);
pp_c_right_paren (this);
pp_c_ampersand (this);
pp_expression (this, TREE_OPERAND (e, 0));
expression (TREE_OPERAND (e, 0));
pp_c_right_paren (this);
pp_c_left_bracket (this);
pp_wide_integer (this, bitpos / size);
@ -1632,7 +1632,7 @@ c_pretty_printer::postfix_expression (tree e)
e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e));
/* Fall through. */
case CONSTRUCTOR:
pp_initializer (this, e);
initializer (e);
break;
case VA_ARG_EXPR:
@ -1640,7 +1640,7 @@ c_pretty_printer::postfix_expression (tree e)
pp_c_left_paren (this);
assignment_expression (TREE_OPERAND (e, 0));
pp_separate_with (this, ',');
pp_type_id (this, TREE_TYPE (e));
type_id (TREE_TYPE (e));
pp_c_right_paren (this);
break;
@ -1665,7 +1665,7 @@ pp_c_expression_list (c_pretty_printer *pp, tree e)
{
for (; e != NULL_TREE; e = TREE_CHAIN (e))
{
pp_expression (pp, TREE_VALUE (e));
pp->expression (TREE_VALUE (e));
if (TREE_CHAIN (e))
pp_separate_with (pp, ',');
}
@ -1681,7 +1681,7 @@ pp_c_constructor_elts (c_pretty_printer *pp, vec<constructor_elt, va_gc> *v)
FOR_EACH_CONSTRUCTOR_VALUE (v, ix, value)
{
pp_expression (pp, value);
pp->expression (value);
if (ix != vec_safe_length (v) - 1)
pp_separate_with (pp, ',');
}
@ -1806,7 +1806,7 @@ pp_c_cast_expression (c_pretty_printer *pp, tree e)
break;
default:
pp_unary_expression (pp, e);
pp->unary_expression (e);
}
}
@ -1864,11 +1864,11 @@ pp_c_additive_expression (c_pretty_printer *pp, tree e)
else
pp_minus (pp);
pp_c_whitespace (pp);
pp_multiplicative_expression (pp, TREE_OPERAND (e, 1));
pp->multiplicative_expression (TREE_OPERAND (e, 1));
break;
default:
pp_multiplicative_expression (pp, e);
pp->multiplicative_expression (e);
break;
}
}
@ -2075,7 +2075,7 @@ c_pretty_printer::conditional_expression (tree e)
pp_c_whitespace (this);
pp_question (this);
pp_c_whitespace (this);
pp_expression (this, TREE_OPERAND (e, 1));
expression (TREE_OPERAND (e, 1));
pp_c_whitespace (this);
pp_colon (this);
pp_c_whitespace (this);
@ -2103,7 +2103,7 @@ c_pretty_printer::assignment_expression (tree e)
pp_c_whitespace (this);
pp_equal (this);
pp_space (this);
pp_expression (this, TREE_OPERAND (e, 1));
expression (TREE_OPERAND (e, 1));
}
else
conditional_expression (e);
@ -2116,8 +2116,8 @@ c_pretty_printer::assignment_expression (tree e)
Implementation note: instead of going through the usual recursion
chain, I take the liberty of dispatching nodes to the appropriate
functions. This makes some redundancy, but it worths it. That also
prevents a possible infinite recursion between pp_primary_expression ()
and pp_expression (). */
prevents a possible infinite recursion between primary_expression ()
and expression (). */
void
c_pretty_printer::expression (tree e)
@ -2321,18 +2321,14 @@ c_pretty_printer::statement (tree stmt)
/* Initialize the PRETTY-PRINTER for handling C codes. */
c_pretty_printer::c_pretty_printer ()
: pretty_printer ()
: pretty_printer (),
offset_list (),
flags ()
{
offset_list = 0;
flags = 0;
type_specifier_seq = pp_c_specifier_qualifier_list;
ptr_operator = pp_c_pointer;
parameter_list = pp_c_parameter_type_list;
type_id = pp_c_type_id;
simple_type_specifier = pp_c_type_specifier;
storage_class_specifier = pp_c_storage_class_specifier;
initializer = pp_c_initializer;
}

View File

@ -64,15 +64,19 @@ struct c_pretty_printer : pretty_printer
virtual void assignment_expression (tree);
virtual void expression (tree);
virtual void type_id (tree);
virtual void statement (tree);
virtual void declaration (tree);
virtual void declaration_specifiers (tree);
virtual void function_specifier (tree);
virtual void storage_class_specifier (tree);
virtual void declarator (tree);
virtual void direct_declarator (tree);
virtual void abstract_declarator (tree);
virtual void direct_abstract_declarator (tree);
virtual void initializer (tree);
/* Points to the first element of an array of offset-list.
Not used yet. */
int *offset_list;
@ -84,45 +88,16 @@ struct c_pretty_printer : pretty_printer
c_pretty_print_fn type_specifier_seq;
c_pretty_print_fn ptr_operator;
c_pretty_print_fn parameter_list;
c_pretty_print_fn type_id;
c_pretty_print_fn simple_type_specifier;
c_pretty_print_fn storage_class_specifier;
c_pretty_print_fn initializer;
};
#define pp_c_tree_identifier(PPI, ID) \
pp_c_identifier (PPI, IDENTIFIER_POINTER (ID))
#define pp_declaration(PP, T) (PP)->declaration (T)
#define pp_declaration_specifiers(PP, D) \
(PP)->declaration_specifiers (D)
#define pp_abstract_declarator(PP, D) (PP)->abstract_declarator (D)
#define pp_type_specifier_seq(PP, D) (PP)->type_specifier_seq (PP, D)
#define pp_declarator(PP, D) (PP)->declarator (D)
#define pp_direct_declarator(PP, D) (PP)->direct_declarator (D)
#define pp_ptr_operator(PP, D) (PP)->ptr_operator (PP, D)
#define pp_parameter_list(PP, T) (PP)->parameter_list (PP, T)
#define pp_type_id(PP, D) (PP)->type_id (PP, D)
#define pp_simple_type_specifier(PP, T) (PP)->simple_type_specifier (PP, T)
#define pp_function_specifier(PP, D) (PP)->function_specifier (D)
#define pp_storage_class_specifier(PP, D) \
(PP)->storage_class_specifier (PP, D);
#define pp_statement(PP, S) (PP)->statement (PP, S)
#define pp_constant(PP, E) (PP)->constant (E)
#define pp_id_expression(PP, E) (PP)->id_expression (E)
#define pp_primary_expression(PP, E) (PP)->primary_expression (E)
#define pp_postfix_expression(PP, E) (PP)->postfix_expression (E)
#define pp_unary_expression(PP, E) (PP)->unary_expression (E)
#define pp_initializer(PP, E) (PP)->initializer (PP, E)
#define pp_multiplicative_expression(PP, E) \
(PP)->multiplicative_expression (E)
#define pp_conditional_expression(PP, E) (PP)->conditional_expression (E)
#define pp_assignment_expression(PP, E) (PP)->assignment_expression (E)
#define pp_expression(PP, E) (PP)->expression (E)
void pp_c_whitespace (c_pretty_printer *);
void pp_c_left_paren (c_pretty_printer *);
@ -149,9 +124,7 @@ void pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type);
void pp_c_type_qualifier_list (c_pretty_printer *, tree);
void pp_c_parameter_type_list (c_pretty_printer *, tree);
void pp_c_specifier_qualifier_list (c_pretty_printer *, tree);
void pp_c_type_id (c_pretty_printer *, tree);
void pp_c_type_specifier (c_pretty_printer *, tree);
void pp_c_storage_class_specifier (c_pretty_printer *, tree);
/* Expressions. */
void pp_c_logical_or_expression (c_pretty_printer *, tree);
void pp_c_expression_list (c_pretty_printer *, tree);

View File

@ -1,3 +1,7 @@
2013-09-03 Gabriel Dos Reis <gdr@integrable-solutions.net>
* c-objc-common.c (c_tree_printer): Tidy.
2013-08-30 Marek Polacek <polacek@redhat.com>
* c-typeck.c (build_binary_op): Add division by zero and shift

View File

@ -120,7 +120,7 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
t = DECL_DEBUG_EXPR (t);
if (!DECL_P (t))
{
pp_expression (cpp, t);
cpp->expression (t);
return true;
}
}
@ -143,12 +143,12 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
if (DECL_NAME (name))
pp_identifier (cpp, lang_hooks.decl_printable_name (name, 2));
else
pp_type_id (cpp, t);
cpp->type_id (t);
return true;
}
else
{
pp_type_id (cpp, t);
cpp->type_id (t);
return true;
}
break;
@ -157,7 +157,7 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
if (TREE_CODE (t) == IDENTIFIER_NODE)
pp_identifier (cpp, IDENTIFIER_POINTER (t));
else
pp_expression (cpp, t);
cpp->expression (t);
return true;
case 'V':

View File

@ -1,3 +1,20 @@
2013-09-03 Gabriel Dos Reis <gdr@integrable-solutions.net>
* cxx-pretty-print.h (cxx_pretty_printer::type_id): Declare as
overrider.
* cxx-pretty-print.c (pp_cxx_storage_class_specifier): Remove.
(pp_cxx_userdef_literal): Tidy.
(pp_cxx_template_argument_list): Likewise.
(pp_cxx_typeid_expression): Likewise.
(pp_cxx_offsetof_expression_1): Likewise.
(cxx_pretty_printer::postfix_expression): Likewise.
(cxx_pretty_printer::unary_expression): Likewise.
(cxx_pretty_printer::statement): Likewise.
(cxx_pretty_printer::type_id): Rename from pp_cxx_type_id.
(c_pretty_printer::cxx_pretty_printer): Do not assign to type_id.
* error.c (dump_decl): Tidy.
(dump_expr): Likewise.
2013-09-02 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/21682, implement DR 565

View File

@ -33,7 +33,6 @@ static void pp_cxx_qualified_id (cxx_pretty_printer *, tree);
static void pp_cxx_template_argument_list (cxx_pretty_printer *, tree);
static void pp_cxx_type_specifier_seq (cxx_pretty_printer *, tree);
static void pp_cxx_ptr_operator (cxx_pretty_printer *, tree);
static void pp_cxx_type_id (cxx_pretty_printer *, tree);
static void pp_cxx_parameter_declaration_clause (cxx_pretty_printer *, tree);
static void pp_cxx_template_parameter (cxx_pretty_printer *, tree);
static void pp_cxx_cast_expression (cxx_pretty_printer *, tree);
@ -51,8 +50,6 @@ pp_cxx_nonconsecutive_character (cxx_pretty_printer *pp, int c)
pp->padding = pp_none;
}
#define pp_cxx_storage_class_specifier(PP, T) \
pp_c_storage_class_specifier (PP, T)
#define pp_cxx_expression_list(PP, T) \
pp_c_expression_list (PP, T)
#define pp_cxx_space_for_pointer_operator(PP, T) \
@ -362,8 +359,8 @@ cxx_pretty_printer::id_expression (tree t)
void
pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t)
{
pp_constant (pp, USERDEF_LITERAL_VALUE (t));
pp_id_expression (pp, USERDEF_LITERAL_SUFFIX_ID (t));
pp->constant (USERDEF_LITERAL_VALUE (t));
pp->id_expression (USERDEF_LITERAL_SUFFIX_ID (t));
}
@ -601,7 +598,7 @@ cxx_pretty_printer::postfix_expression (tree t)
else
pp_cxx_ws_string (this, "const_cast");
pp_cxx_begin_template_argument_list (this);
pp_cxx_type_id (this, TREE_TYPE (t));
type_id (TREE_TYPE (t));
pp_cxx_end_template_argument_list (this);
pp_left_paren (this);
expression (TREE_OPERAND (t, 0));
@ -609,7 +606,7 @@ cxx_pretty_printer::postfix_expression (tree t)
break;
case EMPTY_CLASS_EXPR:
pp_cxx_type_id (this, TREE_TYPE (t));
type_id (TREE_TYPE (t));
pp_left_paren (this);
pp_right_paren (this);
break;
@ -684,7 +681,7 @@ pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
MINUS_EXPR, integer_type_node,
TREE_OPERAND (type, 1),
integer_one_node)));
pp_cxx_type_id (pp, type);
pp->type_id (type);
if (init)
{
pp_left_paren (pp);
@ -693,7 +690,7 @@ pp_cxx_new_expression (cxx_pretty_printer *pp, tree t)
else if (init == void_zero_node)
; /* OK, empty initializer list. */
else
pp_expression (pp, init);
pp->expression (init);
pp_right_paren (pp);
}
break;
@ -776,7 +773,7 @@ cxx_pretty_printer::unary_expression (tree t)
pp_cxx_whitespace (this);
pp_cxx_left_paren (this);
if (TYPE_P (TREE_OPERAND (t, 0)))
pp_cxx_type_id (this, TREE_OPERAND (t, 0));
type_id (TREE_OPERAND (t, 0));
else
unary_expression (TREE_OPERAND (t, 0));
pp_cxx_right_paren (this);
@ -790,13 +787,13 @@ cxx_pretty_printer::unary_expression (tree t)
if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t))
{
pp_cxx_left_paren (this);
pp_cxx_type_id (this, TREE_TYPE (TREE_OPERAND (t, 0)));
type_id (TREE_TYPE (TREE_OPERAND (t, 0)));
pp_cxx_right_paren (this);
}
else if (TYPE_P (TREE_OPERAND (t, 0)))
{
pp_cxx_left_paren (this);
pp_cxx_type_id (this, TREE_OPERAND (t, 0));
type_id (TREE_OPERAND (t, 0));
pp_cxx_right_paren (this);
}
else
@ -807,7 +804,7 @@ cxx_pretty_printer::unary_expression (tree t)
pp_cxx_ws_string (this, "@encode");
pp_cxx_whitespace (this);
pp_cxx_left_paren (this);
pp_cxx_type_id (this, TREE_OPERAND (t, 0));
type_id (TREE_OPERAND (t, 0));
pp_cxx_right_paren (this);
break;
@ -841,7 +838,7 @@ pp_cxx_cast_expression (cxx_pretty_printer *pp, tree t)
{
case CAST_EXPR:
case IMPLICIT_CONV_EXPR:
pp_cxx_type_id (pp, TREE_TYPE (t));
pp->type_id (TREE_TYPE (t));
pp_cxx_call_argument_list (pp, TREE_OPERAND (t, 0));
break;
@ -1214,7 +1211,7 @@ cxx_pretty_printer::declaration_specifiers (tree t)
case PARM_DECL:
case CONST_DECL:
case FIELD_DECL:
pp_cxx_storage_class_specifier (this, t);
storage_class_specifier (t);
declaration_specifiers (TREE_TYPE (t));
break;
@ -1315,7 +1312,7 @@ pp_cxx_type_specifier_seq (cxx_pretty_printer *pp, tree t)
case DECLTYPE_TYPE:
pp_cxx_ws_string (pp, "decltype");
pp_cxx_left_paren (pp);
pp_expression (pp, DECLTYPE_TYPE_EXPR (t));
pp->expression (DECLTYPE_TYPE_EXPR (t));
pp_cxx_right_paren (pp);
break;
@ -1406,9 +1403,9 @@ pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
{
pp->declaration_specifiers (t);
if (TYPE_P (t))
pp_abstract_declarator (pp, t);
pp->abstract_declarator (t);
else
pp_declarator (pp, t);
pp->declarator (t);
}
/* parameter-declaration-clause:
@ -1444,7 +1441,7 @@ pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
pp_cxx_whitespace (pp);
pp_equal (pp);
pp_cxx_whitespace (pp);
pp_assignment_expression (pp, TREE_PURPOSE (types));
pp->assignment_expression (TREE_PURPOSE (types));
}
}
pp_cxx_right_paren (pp);
@ -1473,7 +1470,7 @@ pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
if (DEFERRED_NOEXCEPT_SPEC_P (ex_spec))
pp_cxx_ws_string (pp, "<uninstantiated>");
else
pp_expression (pp, TREE_PURPOSE (ex_spec));
pp->expression (TREE_PURPOSE (ex_spec));
pp_cxx_right_paren (pp);
return;
}
@ -1501,7 +1498,7 @@ pp_cxx_exception_specification (cxx_pretty_printer *pp, tree t)
else
need_comma = true;
pp_cxx_type_id (pp, type);
pp->type_id (type);
}
}
pp_cxx_right_paren (pp);
@ -1602,9 +1599,9 @@ pp_cxx_ctor_initializer (cxx_pretty_printer *pp, tree t)
bool is_pack = PACK_EXPANSION_P (purpose);
if (is_pack)
pp_primary_expression (pp, PACK_EXPANSION_PATTERN (purpose));
pp->primary_expression (PACK_EXPANSION_PATTERN (purpose));
else
pp_primary_expression (pp, purpose);
pp->primary_expression (purpose);
pp_cxx_call_argument_list (pp, TREE_VALUE (t));
if (is_pack)
pp_cxx_ws_string (pp, "...");
@ -1622,7 +1619,7 @@ pp_cxx_function_definition (cxx_pretty_printer *pp, tree t)
{
tree saved_scope = pp->enclosing_scope;
pp->declaration_specifiers (t);
pp_declarator (pp, t);
pp->declarator (t);
pp_needs_newline (pp) = true;
pp->enclosing_scope = DECL_CONTEXT (t);
if (DECL_SAVED_TREE (t))
@ -1700,11 +1697,11 @@ cxx_pretty_printer::direct_abstract_declarator (tree t)
/* type-id:
type-specifier-seq abstract-declarator(opt) */
static void
pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
void
cxx_pretty_printer::type_id (tree t)
{
pp_flags saved_flags = pp->flags;
pp->flags |= pp_c_flag_abstract;
pp_flags saved_flags = flags;
flags |= pp_c_flag_abstract;
switch (TREE_CODE (t))
{
@ -1723,20 +1720,20 @@ pp_cxx_type_id (cxx_pretty_printer *pp, tree t)
case UNDERLYING_TYPE:
case DECLTYPE_TYPE:
case TEMPLATE_ID_EXPR:
pp_cxx_type_specifier_seq (pp, t);
pp_cxx_type_specifier_seq (this, t);
break;
case TYPE_PACK_EXPANSION:
pp_cxx_type_id (pp, PACK_EXPANSION_PATTERN (t));
pp_cxx_ws_string (pp, "...");
type_id (PACK_EXPANSION_PATTERN (t));
pp_cxx_ws_string (this, "...");
break;
default:
pp_c_type_id (pp, t);
c_pretty_printer::type_id (t);
break;
}
pp->flags = saved_flags;
flags = saved_flags;
}
/* template-argument-list:
@ -1780,9 +1777,9 @@ pp_cxx_template_argument_list (cxx_pretty_printer *pp, tree t)
if (TYPE_P (arg) || (TREE_CODE (arg) == TEMPLATE_DECL
&& TYPE_P (DECL_TEMPLATE_RESULT (arg))))
pp_cxx_type_id (pp, arg);
pp->type_id (arg);
else
pp_expression (pp, arg);
pp->expression (arg);
}
}
}
@ -1794,9 +1791,9 @@ pp_cxx_exception_declaration (cxx_pretty_printer *pp, tree t)
t = DECL_EXPR_DECL (t);
pp_cxx_type_specifier_seq (pp, t);
if (TYPE_P (t))
pp_abstract_declarator (pp, t);
pp->abstract_declarator (t);
else
pp_declarator (pp, t);
pp->declarator (t);
}
/* Statements. */
@ -1871,7 +1868,7 @@ cxx_pretty_printer::statement (tree t)
pp_cxx_ws_string (this, "if");
pp_cxx_whitespace (this);
pp_cxx_left_paren (this);
pp_expression (this, IF_COND (t));
expression (IF_COND (t));
pp_cxx_right_paren (this);
pp_newline_and_indent (this, 2);
statement (THEN_CLAUSE (t));
@ -1894,7 +1891,7 @@ cxx_pretty_printer::statement (tree t)
pp_cxx_ws_string (this, "switch");
pp_space (this);
pp_cxx_left_paren (this);
pp_expression (this, SWITCH_STMT_COND (t));
expression (SWITCH_STMT_COND (t));
pp_cxx_right_paren (this);
pp_indentation (this) += 3;
pp_needs_newline (this) = true;
@ -1911,7 +1908,7 @@ cxx_pretty_printer::statement (tree t)
pp_cxx_ws_string (this, "while");
pp_space (this);
pp_cxx_left_paren (this);
pp_expression (this, WHILE_COND (t));
expression (WHILE_COND (t));
pp_cxx_right_paren (this);
pp_newline_and_indent (this, 3);
statement (WHILE_BODY (t));
@ -1927,7 +1924,7 @@ cxx_pretty_printer::statement (tree t)
pp_cxx_ws_string (this, "while");
pp_space (this);
pp_cxx_left_paren (this);
pp_expression (this, DO_COND (t));
expression (DO_COND (t));
pp_cxx_right_paren (this);
pp_cxx_semicolon (this);
pp_needs_newline (this) = true;
@ -1944,12 +1941,12 @@ cxx_pretty_printer::statement (tree t)
pp_needs_newline (this) = false;
pp_cxx_whitespace (this);
if (FOR_COND (t))
pp_expression (this, FOR_COND (t));
expression (FOR_COND (t));
pp_cxx_semicolon (this);
pp_needs_newline (this) = false;
pp_cxx_whitespace (this);
if (FOR_EXPR (t))
pp_expression (this, FOR_EXPR (t));
expression (FOR_EXPR (t));
pp_cxx_right_paren (this);
pp_newline_and_indent (this, 3);
statement (FOR_BODY (t));
@ -1988,7 +1985,7 @@ cxx_pretty_printer::statement (tree t)
/* expression-statement:
expression(opt) ; */
case EXPR_STMT:
pp_expression (this, EXPR_STMT_EXPR (t));
expression (EXPR_STMT_EXPR (t));
pp_cxx_semicolon (this);
pp_needs_newline (this) = true;
break;
@ -2271,9 +2268,9 @@ pp_cxx_typeid_expression (cxx_pretty_printer *pp, tree t)
pp_cxx_ws_string (pp, "typeid");
pp_cxx_left_paren (pp);
if (TYPE_P (t))
pp_cxx_type_id (pp, t);
pp->type_id (t);
else
pp_expression (pp, t);
pp->expression (t);
pp_cxx_right_paren (pp);
}
@ -2282,9 +2279,9 @@ pp_cxx_va_arg_expression (cxx_pretty_printer *pp, tree t)
{
pp_cxx_ws_string (pp, "va_arg");
pp_cxx_left_paren (pp);
pp_assignment_expression (pp, TREE_OPERAND (t, 0));
pp->assignment_expression (TREE_OPERAND (t, 0));
pp_cxx_separate_with (pp, ',');
pp_cxx_type_id (pp, TREE_TYPE (t));
pp->type_id (TREE_TYPE (t));
pp_cxx_right_paren (pp);
}
@ -2297,7 +2294,7 @@ pp_cxx_offsetof_expression_1 (cxx_pretty_printer *pp, tree t)
if (TREE_CODE (TREE_OPERAND (t, 0)) == STATIC_CAST_EXPR
&& POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
{
pp_cxx_type_id (pp, TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))));
pp->type_id (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))));
pp_cxx_separate_with (pp, ',');
return true;
}
@ -2307,13 +2304,13 @@ pp_cxx_offsetof_expression_1 (cxx_pretty_printer *pp, tree t)
return false;
if (TREE_CODE (TREE_OPERAND (t, 0)) != ARROW_EXPR)
pp_cxx_dot (pp);
pp_expression (pp, TREE_OPERAND (t, 1));
pp->expression (TREE_OPERAND (t, 1));
return true;
case ARRAY_REF:
if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
return false;
pp_left_bracket (pp);
pp_expression (pp, TREE_OPERAND (t, 1));
pp->expression (TREE_OPERAND (t, 1));
pp_right_bracket (pp);
return true;
default:
@ -2327,7 +2324,7 @@ pp_cxx_offsetof_expression (cxx_pretty_printer *pp, tree t)
pp_cxx_ws_string (pp, "offsetof");
pp_cxx_left_paren (pp);
if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
pp_expression (pp, TREE_OPERAND (t, 0));
pp->expression (TREE_OPERAND (t, 0));
pp_cxx_right_paren (pp);
}
@ -2407,12 +2404,12 @@ pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t)
}
pp_cxx_left_paren (pp);
pp_cxx_type_id (pp, TRAIT_EXPR_TYPE1 (t));
pp->type_id (TRAIT_EXPR_TYPE1 (t));
if (kind == CPTK_IS_BASE_OF || kind == CPTK_IS_CONVERTIBLE_TO)
{
pp_cxx_separate_with (pp, ',');
pp_cxx_type_id (pp, TRAIT_EXPR_TYPE2 (t));
pp->type_id (TRAIT_EXPR_TYPE2 (t));
}
pp_cxx_right_paren (pp);
@ -2430,6 +2427,5 @@ cxx_pretty_printer::cxx_pretty_printer ()
type_specifier_seq = (pp_fun) pp_cxx_type_specifier_seq;
parameter_list = (pp_fun) pp_cxx_parameter_declaration_clause;
type_id = (pp_fun) pp_cxx_type_id;
simple_type_specifier = (pp_fun) pp_cxx_simple_type_specifier;
}

View File

@ -42,6 +42,7 @@ struct cxx_pretty_printer : c_pretty_printer
void conditional_expression (tree);
void assignment_expression (tree);
void expression (tree);
void type_id (tree);
void statement (tree);
void declaration (tree);
void declaration_specifiers (tree);

View File

@ -1212,7 +1212,7 @@ dump_decl (cxx_pretty_printer *pp, tree t, int flags)
if (flags & TFF_DECL_SPECIFIERS)
pp->declaration (t);
else
pp_type_id (pp, t);
pp->type_id (t);
break;
case UNBOUND_CLASS_TEMPLATE:
@ -1908,7 +1908,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
case REAL_CST:
case STRING_CST:
case COMPLEX_CST:
pp_constant (pp, t);
pp->constant (t);
break;
case USERDEF_LITERAL:
@ -2538,7 +2538,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
case TYPENAME_TYPE:
/* We get here when we want to print a dependent type as an
id-expression, without any disambiguator decoration. */
pp_id_expression (pp, t);
pp->id_expression (t);
break;
case TEMPLATE_TYPE_PARM:
@ -2588,7 +2588,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
case BIT_FIELD_REF:
case FIX_TRUNC_EXPR:
case FLOAT_EXPR:
pp_expression (pp, t);
pp->expression (t);
break;
case TRUTH_AND_EXPR:
@ -2596,7 +2596,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
case TRUTH_XOR_EXPR:
if (flags & TFF_EXPR_IN_PARENS)
pp_cxx_left_paren (pp);
pp_expression (pp, t);
pp->expression (t);
if (flags & TFF_EXPR_IN_PARENS)
pp_cxx_right_paren (pp);
break;