From a176426f3573d5eceb4f60caf01a291ab778e475 Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis <gdr@integrable-solutions.net> Date: Fri, 30 Dec 2005 17:27:28 +0000 Subject: [PATCH] c-pretty-print.h (struct c_pretty_print_info): Add new member "constant". 2005-12-30 Gabriel Dos Reis <gdr@integrable-solutions.net> * c-pretty-print.h (struct c_pretty_print_info): Add new member "constant". (pp_constant): New macro. * c-pretty-print.c (pp_c_pretty_printer_init): Set pp->constant. cp/ 2005-12-30 Gabriel Dos Reis <gdr@integrable-solutions.net> * cxx-pretty-print.c (pp_cxx_constant): New. Print string-literal in parens if input program says so. (pp_cxx_primary_expression): Hand off constant printing to pp_cxx_constant. (pp_cxx_pretty_printer_init): Set pp->c_base.constant. (pp_cxx_expression): Use pp_cxx_constant for literals. * error.c (dump_expr): Use pp_constant for literals. From-SVN: r109176 --- gcc/ChangeLog | 7 +++++++ gcc/c-pretty-print.c | 1 + gcc/c-pretty-print.h | 3 +++ gcc/cp/ChangeLog | 10 ++++++++++ gcc/cp/cxx-pretty-print.c | 30 +++++++++++++++++++++++++++--- gcc/cp/error.c | 11 ++--------- 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a62178dd9971..22e6673eadcf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2005-12-30 Gabriel Dos Reis <gdr@integrable-solutions.net> + + * c-pretty-print.h (struct c_pretty_print_info): Add new member + "constant". + (pp_constant): New macro. + * c-pretty-print.c (pp_c_pretty_printer_init): Set pp->constant. + 2005-12-30 John David Anglin <dave.anglin@nrc-cnrc.gc.ca> PR fortran/25586 diff --git a/gcc/c-pretty-print.c b/gcc/c-pretty-print.c index 058d3b9644c2..516022340ca9 100644 --- a/gcc/c-pretty-print.c +++ b/gcc/c-pretty-print.c @@ -2001,6 +2001,7 @@ pp_c_pretty_printer_init (c_pretty_printer *pp) 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; diff --git a/gcc/c-pretty-print.h b/gcc/c-pretty-print.h index 0f9d46a86e75..14cb670c7edb 100644 --- a/gcc/c-pretty-print.h +++ b/gcc/c-pretty-print.h @@ -80,6 +80,7 @@ struct c_pretty_print_info c_pretty_print_fn statement; + c_pretty_print_fn constant; c_pretty_print_fn id_expression; c_pretty_print_fn primary_expression; c_pretty_print_fn postfix_expression; @@ -129,6 +130,8 @@ struct c_pretty_print_info #define pp_statement(PPI, S) \ pp_c_base (PPI)->statement (pp_c_base (PPI), S) +#define pp_constant(PP, E) \ + pp_c_base (PP)->constant (pp_c_base (PP), E) #define pp_id_expression(PP, E) \ pp_c_base (PP)->id_expression (pp_c_base (PP), E) #define pp_primary_expression(PPI, E) \ diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7391d15018fd..c895ce58f862 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2005-12-30 Gabriel Dos Reis <gdr@integrable-solutions.net> + + * cxx-pretty-print.c (pp_cxx_constant): New. Print + string-literal in parens if input program says so. + (pp_cxx_primary_expression): Hand off constant printing to + pp_cxx_constant. + (pp_cxx_pretty_printer_init): Set pp->c_base.constant. + (pp_cxx_expression): Use pp_cxx_constant for literals. + * error.c (dump_expr): Use pp_constant for literals. + 2005-12-29 Nathan Sidwell <nathan@codesourcery.com> * method.c (make_thunk): Don't set comdat_linkage here. diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index cdaf470ce26e..43fbe2b3bfa0 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -292,6 +292,29 @@ pp_cxx_qualified_id (cxx_pretty_printer *pp, tree t) } } + +static void +pp_cxx_constant (cxx_pretty_printer *pp, tree t) +{ + switch (TREE_CODE (t)) + { + case STRING_CST: + { + const bool in_parens = PAREN_STRING_LITERAL_P (t); + if (in_parens) + pp_cxx_left_paren (pp); + pp_c_constant (pp_c_base (pp), t); + if (in_parens) + pp_cxx_right_paren (pp); + } + break; + + default: + pp_c_constant (pp_c_base (pp), t); + break; + } +} + /* id-expression: unqualified-id qualified-id */ @@ -321,10 +344,10 @@ pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t) { switch (TREE_CODE (t)) { - case STRING_CST: case INTEGER_CST: case REAL_CST: - pp_c_constant (pp_c_base (pp), t); + case STRING_CST: + pp_cxx_constant (pp, t); break; case BASELINK: @@ -848,7 +871,7 @@ pp_cxx_expression (cxx_pretty_printer *pp, tree t) case STRING_CST: case INTEGER_CST: case REAL_CST: - pp_c_constant (pp_c_base (pp), t); + pp_cxx_constant (pp, t); break; case RESULT_DECL: @@ -1961,6 +1984,7 @@ pp_cxx_pretty_printer_init (cxx_pretty_printer *pp) /* pp->c_base.statement = (pp_fun) pp_cxx_statement; */ + pp->c_base.constant = (pp_fun) pp_cxx_constant; pp->c_base.id_expression = (pp_fun) pp_cxx_id_expression; pp->c_base.primary_expression = (pp_fun) pp_cxx_primary_expression; pp->c_base.postfix_expression = (pp_fun) pp_cxx_postfix_expression; diff --git a/gcc/cp/error.c b/gcc/cp/error.c index be0ee5968eed..d2ee9c509d7c 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -1318,17 +1318,10 @@ dump_expr (tree t, int flags) dump_decl (t, (flags & ~TFF_DECL_SPECIFIERS) | TFF_NO_FUNCTION_ARGUMENTS); break; - case STRING_CST: - if (PAREN_STRING_LITERAL_P (t)) - pp_cxx_left_paren (cxx_pp); - pp_c_constant (pp_c_base (cxx_pp), t); - if (PAREN_STRING_LITERAL_P (t)) - pp_cxx_right_paren (cxx_pp); - break; - case INTEGER_CST: case REAL_CST: - pp_c_constant (pp_c_base (cxx_pp), t); + case STRING_CST: + pp_constant (cxx_pp, t); break; case THROW_EXPR: -- GitLab