This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
tidy cp/cxx-pretty-print.c
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: gcc-patches at gcc dot gnu dot org
- Date: 30 Dec 2005 18:31:54 +0100
- Subject: tidy cp/cxx-pretty-print.c
when the more accurate pretty-printing of C++ string literals was
added, it should have gone at the obvious place, not cp/error.c. We
should move away from adding to that file.
regtested on an i686-pc-linux-gnu. Applied to mainline.
-- Gaby
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.
*** c-pretty-print.c (revision 109178)
--- c-pretty-print.c (local)
*************** pp_c_pretty_printer_init (c_pretty_print
*** 2001,2006 ****
--- 2001,2007 ----
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;
*** c-pretty-print.h (revision 109178)
--- c-pretty-print.h (local)
*************** struct c_pretty_print_info
*** 80,85 ****
--- 80,86 ----
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;
*************** struct c_pretty_print_info
*** 129,134 ****
--- 130,137 ----
#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) \
*** cp/cxx-pretty-print.c (revision 109178)
--- cp/cxx-pretty-print.c (local)
*************** pp_cxx_qualified_id (cxx_pretty_printer
*** 292,297 ****
--- 292,320 ----
}
}
+
+ 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 */
*************** pp_cxx_primary_expression (cxx_pretty_pr
*** 321,330 ****
{
switch (TREE_CODE (t))
{
- case STRING_CST:
case INTEGER_CST:
case REAL_CST:
! pp_c_constant (pp_c_base (pp), t);
break;
case BASELINK:
--- 344,353 ----
{
switch (TREE_CODE (t))
{
case INTEGER_CST:
case REAL_CST:
! case STRING_CST:
! pp_cxx_constant (pp, t);
break;
case BASELINK:
*************** pp_cxx_expression (cxx_pretty_printer *p
*** 848,854 ****
case STRING_CST:
case INTEGER_CST:
case REAL_CST:
! pp_c_constant (pp_c_base (pp), t);
break;
case RESULT_DECL:
--- 871,877 ----
case STRING_CST:
case INTEGER_CST:
case REAL_CST:
! pp_cxx_constant (pp, t);
break;
case RESULT_DECL:
*************** pp_cxx_pretty_printer_init (cxx_pretty_p
*** 1961,1966 ****
--- 1984,1990 ----
/* 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;
*** cp/error.c (revision 109178)
--- cp/error.c (local)
*************** dump_expr (tree t, int flags)
*** 1318,1334 ****
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);
break;
case THROW_EXPR:
--- 1318,1327 ----
dump_decl (t, (flags & ~TFF_DECL_SPECIFIERS) | TFF_NO_FUNCTION_ARGUMENTS);
break;
case INTEGER_CST:
case REAL_CST:
! case STRING_CST:
! pp_constant (cxx_pp, t);
break;
case THROW_EXPR: