Re: [C++ Patch] Produce canonical names for debug info without changing normal pretty-printing (issue6215052)

2012-06-06 Thread Sterling Augustine
On Wed, Jun 6, 2012 at 3:49 PM, Steven Bosscher stevenb@gmail.com wrote:
 On Mon, Jun 4, 2012 at 7:53 PM, Sterling Augustine
 saugust...@google.com wrote:
 On Fri, Jun 1, 2012 at 4:38 PM, Gabriel Dos Reis
 g...@integrable-solutions.net wrote:
 On Fri, Jun 1, 2012 at 6:07 PM, Sterling Augustine
 saugust...@google.com wrote:
 After finding yet another bug in the previous patch dealing with 
 pretty-printing
 decls for dwarf in canonical form, I have figured out a way to do it that 
 is
 less invasive and much cleaner.

 This updated patch simply wraps the two entry points into the decl pretty-
 printer called from cxx_dwarf_name with new functions that set the
 appropriate flag on the pretty printer. This is much cleaner and avoids
 the need for translating flags for C++ pretty-printing into standard C
 pretty printing flags.

 OK for mainline?

 OK.

 Thanks! Committed as posted.

 With a wrong ChangeLog:

        * gcc/c-family/c-pretty-print.h (pp_c_flag_gnu_v3): New enumerator.
        * gcc/c-family/c-pretty-print.c (pp_c_specifier_qualifier_list): Check
        it at both the start and end of the function.
        * gcc/cp/error.c (dump_decl): Check pp_c_flag_gnu_v3.
        (decl_as_dwarf_string, lang_decl_dwarf_name): New functions.
        (lang_decl_name): Handle namespace decls.
        * gcc/cp/cp-tree.h: Declare decl_as_dwarf_string, lang_decl_dwarf_name.
        * gcc/cp/cp-lang.c: Call them.

 Changes for files in gcc/ go in gcc/ChangeLog.
 Changes for files in gcc/cp go in gcc/cp/ChangeLog.
 Changes for files in gcc/c-family go in gcc/c-family/ChangeLog.

 The path is not pre-fixed. So:

 c-family/
        * c-pretty-print.h (pp_c_flag_gnu_v3): New enumerator.
        * c-pretty-print.c (pp_c_specifier_qualifier_list): Check
        it at both the start and end of the function.

 cp/
        * error.c (dump_decl): Check pp_c_flag_gnu_v3.
        (decl_as_dwarf_string, lang_decl_dwarf_name): New functions.
        (lang_decl_name): Handle namespace decls.
        * cp-tree.h: Declare decl_as_dwarf_string, lang_decl_dwarf_name.
        * cp-lang.c: Call them.

 Can you please fix this?
 You don't have to post such patches for review.

Fixes committed as you recomend.

FWIW, the original entries were generated with contrib/mklog. Someone
may want to fix it to do the right thing in this case.


Re: [C++ Patch] Produce canonical names for debug info without changing normal pretty-printing (issue6215052)

2012-06-06 Thread Gabriel Dos Reis
On Wed, Jun 6, 2012 at 6:07 PM, Sterling Augustine
saugust...@google.com wrote:
 On Wed, Jun 6, 2012 at 3:49 PM, Steven Bosscher stevenb@gmail.com wrote:
 On Mon, Jun 4, 2012 at 7:53 PM, Sterling Augustine
 saugust...@google.com wrote:
 On Fri, Jun 1, 2012 at 4:38 PM, Gabriel Dos Reis
 g...@integrable-solutions.net wrote:
 On Fri, Jun 1, 2012 at 6:07 PM, Sterling Augustine
 saugust...@google.com wrote:
 After finding yet another bug in the previous patch dealing with 
 pretty-printing
 decls for dwarf in canonical form, I have figured out a way to do it that 
 is
 less invasive and much cleaner.

 This updated patch simply wraps the two entry points into the decl pretty-
 printer called from cxx_dwarf_name with new functions that set the
 appropriate flag on the pretty printer. This is much cleaner and avoids
 the need for translating flags for C++ pretty-printing into standard C
 pretty printing flags.

 OK for mainline?

 OK.

 Thanks! Committed as posted.

 With a wrong ChangeLog:

        * gcc/c-family/c-pretty-print.h (pp_c_flag_gnu_v3): New enumerator.
        * gcc/c-family/c-pretty-print.c (pp_c_specifier_qualifier_list): Check
        it at both the start and end of the function.
        * gcc/cp/error.c (dump_decl): Check pp_c_flag_gnu_v3.
        (decl_as_dwarf_string, lang_decl_dwarf_name): New functions.
        (lang_decl_name): Handle namespace decls.
        * gcc/cp/cp-tree.h: Declare decl_as_dwarf_string, 
 lang_decl_dwarf_name.
        * gcc/cp/cp-lang.c: Call them.

 Changes for files in gcc/ go in gcc/ChangeLog.
 Changes for files in gcc/cp go in gcc/cp/ChangeLog.
 Changes for files in gcc/c-family go in gcc/c-family/ChangeLog.

 The path is not pre-fixed. So:

 c-family/
        * c-pretty-print.h (pp_c_flag_gnu_v3): New enumerator.
        * c-pretty-print.c (pp_c_specifier_qualifier_list): Check
        it at both the start and end of the function.

 cp/
        * error.c (dump_decl): Check pp_c_flag_gnu_v3.
        (decl_as_dwarf_string, lang_decl_dwarf_name): New functions.
        (lang_decl_name): Handle namespace decls.
        * cp-tree.h: Declare decl_as_dwarf_string, lang_decl_dwarf_name.
        * cp-lang.c: Call them.

 Can you please fix this?
 You don't have to post such patches for review.

 Fixes committed as you recomend.

 FWIW, the original entries were generated with contrib/mklog. Someone
 may want to fix it to do the right thing in this case.

My understanding is that it was designed for branches, which has different
ChangeLog entry policies.  This is trunk.


Re: [C++ Patch] Produce canonical names for debug info without changing normal pretty-printing (issue6215052)

2012-06-04 Thread Sterling Augustine
On Fri, Jun 1, 2012 at 4:38 PM, Gabriel Dos Reis
g...@integrable-solutions.net wrote:
 On Fri, Jun 1, 2012 at 6:07 PM, Sterling Augustine
 saugust...@google.com wrote:
 After finding yet another bug in the previous patch dealing with 
 pretty-printing
 decls for dwarf in canonical form, I have figured out a way to do it that is
 less invasive and much cleaner.

 This updated patch simply wraps the two entry points into the decl pretty-
 printer called from cxx_dwarf_name with new functions that set the
 appropriate flag on the pretty printer. This is much cleaner and avoids
 the need for translating flags for C++ pretty-printing into standard C
 pretty printing flags.

 OK for mainline?

 OK.

Thanks! Committed as posted.

Sterling


[C++ Patch] Produce canonical names for debug info without changing normal pretty-printing (issue6215052)

2012-06-01 Thread Sterling Augustine
After finding yet another bug in the previous patch dealing with pretty-printing
decls for dwarf in canonical form, I have figured out a way to do it that is
less invasive and much cleaner.

This updated patch simply wraps the two entry points into the decl pretty-
printer called from cxx_dwarf_name with new functions that set the
appropriate flag on the pretty printer. This is much cleaner and avoids
the need for translating flags for C++ pretty-printing into standard C
pretty printing flags.

OK for mainline?

Sterling

2012-06-01   Sterling Augustine  saugust...@google.com

* gcc/c-family/c-pretty-print.h (pp_c_flag_gnu_v3): New enumerator.
* gcc/c-family/c-pretty-print.c (pp_c_specifier_qualifier_list): Check
it at both the start and end of the function.
* gcc/cp/error.c (dump_decl): Check pp_c_flag_gnu_v3.
(decl_as_dwarf_string, lang_decl_dwarf_name): New functions.
(lang_decl_name): Handle namespace decls.
* gcc/cp/cp-tree.h: Declare decl_as_dwarf_string, lang_decl_dwarf_name.
* gcc/cp/cp-lang.c: Call them.

Index: gcc/c-family/c-pretty-print.c
===
--- gcc/c-family/c-pretty-print.c   (revision 188034)
+++ gcc/c-family/c-pretty-print.c   (working copy)
@@ -446,7 +446,7 @@
 {
   const enum tree_code code = TREE_CODE (t);
 
-  if (TREE_CODE (t) != POINTER_TYPE)
+  if (!(pp-flags  pp_c_flag_gnu_v3)  code != POINTER_TYPE)
 pp_c_type_qualifier_list (pp, t);
   switch (code)
 {
@@ -494,6 +494,8 @@
   pp_simple_type_specifier (pp, t);
   break;
 }
+  if ((pp-flags  pp_c_flag_gnu_v3)  code != POINTER_TYPE)
+pp_c_type_qualifier_list (pp, t);
 }
 
 /* parameter-type-list:
Index: gcc/c-family/c-pretty-print.h
===
--- gcc/c-family/c-pretty-print.h   (revision 188034)
+++ gcc/c-family/c-pretty-print.h   (working copy)
@@ -30,7 +30,8 @@
 typedef enum
   {
  pp_c_flag_abstract = 1  1,
- pp_c_flag_last_bit = 2
+ pp_c_flag_gnu_v3 = 1  2,
+ pp_c_flag_last_bit = 3
   } pp_c_pretty_print_flags;
 
 
Index: gcc/cp/error.c
===
--- gcc/cp/error.c  (revision 188034)
+++ gcc/cp/error.c  (working copy)
@@ -1028,7 +1028,12 @@
dump_scope (CP_DECL_CONTEXT (t), flags);
  flags = ~TFF_UNQUALIFIED_NAME;
  if (DECL_NAME (t) == NULL_TREE)
-   pp_cxx_ws_string (cxx_pp, M_({anonymous}));
+{
+  if (!(pp_c_base (cxx_pp)-flags  pp_c_flag_gnu_v3))
+pp_cxx_ws_string (cxx_pp, M_({anonymous}));
+  else
+pp_cxx_ws_string (cxx_pp, M_((anonymous namespace)));
+}
  else
pp_cxx_tree_identifier (cxx_pp, DECL_NAME (t));
}
@@ -2556,7 +2561,22 @@
   return pp_formatted_text (cxx_pp);
 }
 
+/* Wrap decl_as_string with options appropriate for dwarf.  */
+
 const char *
+decl_as_dwarf_string (tree decl, int flags)
+{
+  const char *name;
+  /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the 
flag
+ here will be adequate to get the desired behaviour.  */
+  pp_c_base (cxx_pp)-flags |= pp_c_flag_gnu_v3;
+  name = decl_as_string (decl, flags);
+  /* Subsequent calls to the pretty printer shouldn't use this style.  */
+  pp_c_base (cxx_pp)-flags = ~pp_c_flag_gnu_v3;
+  return name;
+}
+
+const char *
 decl_as_string (tree decl, int flags)
 {
   reinit_cxx_pp ();
@@ -2573,6 +2593,21 @@
   return pp_formatted_text (cxx_pp);
 }
 
+/* Wrap lang_decl_name with options appropriate for dwarf.  */
+
+const char *
+lang_decl_dwarf_name (tree decl, int v, bool translate)
+{
+  const char *name;
+  /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the 
flag
+ here will be adequate to get the desired behaviour.  */
+  pp_c_base (cxx_pp)-flags |= pp_c_flag_gnu_v3;
+  name = lang_decl_name (decl, v, translate);
+  /* Subsequent calls to the pretty printer shouldn't use this style.  */
+  pp_c_base (cxx_pp)-flags = ~pp_c_flag_gnu_v3;
+  return name;
+}
+
 /* Generate the three forms of printable names for cxx_printable_name.  */
 
 const char *
@@ -2596,6 +2631,9 @@
 
   if (TREE_CODE (decl) == FUNCTION_DECL)
 dump_function_name (decl, TFF_PLAIN_IDENTIFIER);
+  else if ((DECL_NAME (decl) == NULL_TREE)
+TREE_CODE (decl) == NAMESPACE_DECL)
+dump_decl (decl, TFF_PLAIN_IDENTIFIER);
   else
 dump_decl (DECL_NAME (decl), TFF_PLAIN_IDENTIFIER);
 
Index: gcc/cp/cp-lang.c
===
--- gcc/cp/cp-lang.c(revision 188034)
+++ gcc/cp/cp-lang.c(working copy)
@@ -118,11 +118,11 @@
(ANON_AGGRNAME_P (DECL_NAME (t)) || LAMBDANAME_P (DECL_NAME (t
 return NULL;
   if (verbosity = 2)
-return decl_as_string (t,
-  TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME
-  

Re: [C++ Patch] Produce canonical names for debug info without changing normal pretty-printing (issue6215052)

2012-06-01 Thread Gabriel Dos Reis
On Fri, Jun 1, 2012 at 6:07 PM, Sterling Augustine
saugust...@google.com wrote:
 After finding yet another bug in the previous patch dealing with 
 pretty-printing
 decls for dwarf in canonical form, I have figured out a way to do it that is
 less invasive and much cleaner.

 This updated patch simply wraps the two entry points into the decl pretty-
 printer called from cxx_dwarf_name with new functions that set the
 appropriate flag on the pretty printer. This is much cleaner and avoids
 the need for translating flags for C++ pretty-printing into standard C
 pretty printing flags.

 OK for mainline?

OK.


Re: [C++ Patch] Produce canonical names for debug info without changing normal pretty-printing (issue6215052)

2012-05-30 Thread Gabriel Dos Reis
On Tue, May 29, 2012 at 5:32 PM, Sterling Augustine
saugust...@google.com wrote:

 Index: gcc/c-family/c-pretty-print.h
 ===
 --- gcc/c-family/c-pretty-print.h       (revision 187603)
 +++ gcc/c-family/c-pretty-print.h       (working copy)
 @@ -30,7 +30,8 @@ along with GCC; see the file COPYING3.  If not see
  typedef enum
   {
      pp_c_flag_abstract = 1  1,
 -     pp_c_flag_last_bit = 2
 +     pp_c_flag_last_bit = 2,
 +     pp_c_flag_gnu_v3 = 4

last bit should really be last bit.  That means the value for
pp_c_flags_last_bits
should be 1  2 with the new addition.


Re: [C++ Patch] Produce canonical names for debug info without changing normal pretty-printing (issue6215052)

2012-05-30 Thread Sterling Augustine
On Wed, May 30, 2012 at 2:15 PM, Gabriel Dos Reis
g...@integrable-solutions.net wrote:
 On Tue, May 29, 2012 at 5:32 PM, Sterling Augustine
 saugust...@google.com wrote:

 Index: gcc/c-family/c-pretty-print.h
 ===
 --- gcc/c-family/c-pretty-print.h       (revision 187603)
 +++ gcc/c-family/c-pretty-print.h       (working copy)
 @@ -30,7 +30,8 @@ along with GCC; see the file COPYING3.  If not see
  typedef enum
   {
      pp_c_flag_abstract = 1  1,
 -     pp_c_flag_last_bit = 2
 +     pp_c_flag_last_bit = 2,
 +     pp_c_flag_gnu_v3 = 4

 last bit should really be last bit.  That means the value for
 pp_c_flags_last_bits
 should be 1  2 with the new addition.

Good catch. There is a single use of pp_c_flag_last_bit in
cxx-pretty-printer.h to define the first C++ flag like so:

 pp_cxx_flag_default_argument = 1  pp_c_flag_last_bit


So shouldn't the enum look like this?

typedef enum
  {
 pp_c_flag_abstract = 1  1,
 pp_c_flag_gnu_v3 = 1  2,
 pp_c_flag_last_bit = 3
  } pp_c_pretty_print_flags;

Thanks,

Sterling


Re: [C++ Patch] Produce canonical names for debug info without changing normal pretty-printing (issue6215052)

2012-05-30 Thread Gabriel Dos Reis
On Wed, May 30, 2012 at 4:40 PM, Sterling Augustine
saugust...@google.com wrote:
 On Wed, May 30, 2012 at 2:15 PM, Gabriel Dos Reis
 g...@integrable-solutions.net wrote:
 On Tue, May 29, 2012 at 5:32 PM, Sterling Augustine
 saugust...@google.com wrote:

 Index: gcc/c-family/c-pretty-print.h
 ===
 --- gcc/c-family/c-pretty-print.h       (revision 187603)
 +++ gcc/c-family/c-pretty-print.h       (working copy)
 @@ -30,7 +30,8 @@ along with GCC; see the file COPYING3.  If not see
  typedef enum
   {
      pp_c_flag_abstract = 1  1,
 -     pp_c_flag_last_bit = 2
 +     pp_c_flag_last_bit = 2,
 +     pp_c_flag_gnu_v3 = 4

 last bit should really be last bit.  That means the value for
 pp_c_flags_last_bits
 should be 1  2 with the new addition.

 Good catch. There is a single use of pp_c_flag_last_bit in
 cxx-pretty-printer.h to define the first C++ flag like so:

  pp_cxx_flag_default_argument = 1  pp_c_flag_last_bit


 So shouldn't the enum look like this?

 typedef enum
  {
     pp_c_flag_abstract = 1  1,
     pp_c_flag_gnu_v3 = 1  2,
     pp_c_flag_last_bit = 3
  } pp_c_pretty_print_flags;

 Thanks,

 Sterling

Yes, you are absolutely right.

-- Gaby


Re: [C++ Patch] Produce canonical names for debug info without changing normal pretty-printing (issue6215052)

2012-05-29 Thread Sterling Augustine
On Wed, May 16, 2012 at 1:03 PM, Sterling Augustine
saugust...@google.com wrote:
 This patch adds new flags and defines such that the C++ decl pretty printer
 prints both canonical dwarf names for decls without perturbing normal error
 message output.

 It addresses the issues with the earlier patches submitted as:

 http://gcc.gnu.org/ml/gcc-patches/2012-05/msg00516.html
 http://gcc.gnu.org/ml/gcc-patches/2012-05/msg00512.html

 Which are withdrawn.

 This patch requires no changes to the testsuite and does not produce
 visible changes to gcc's output except to dwarf consumers, which will now
 all agree on the names of functions.

 Tested with a full bootstrap.

 OK for mainline?

 Sterling



 2012-05-16   Sterling Augustine  saugust...@google.com

        * gcc/c-family/c-pretty-print.h (pp_c_flag_gnu_v3): New enumerator.
        * gcc/c-family/c-pretty-print.c (pp_c_specifier_qualifier_list): Check
        it at both the start and end of the function.
        * gcc/cp/cp-tree.h (TFF_MATCH_GNU_V3_DEMANGLER): Define and comment.
        * gcc/cp/error.c (dump_decl): Print appropriate string for anonymous
        namespace based on pp_c_flag_gnu_v3.
        (decl_as_string): Set cxx_pp-flags based on 
 TFF_MATCH_GNU_V3_DEMANGLER.
        (lang_decl_name): Handle unnamed namespace decls.
        * gcc/cp/cp-lang.c (cxx_dwarf_name): Call decl_as_string for namespace
        decls.

 Index: gcc/c-family/c-pretty-print.c
 ===
 --- gcc/c-family/c-pretty-print.c       (revision 187603)
 +++ gcc/c-family/c-pretty-print.c       (working copy)
 @@ -446,8 +446,9 @@ pp_c_specifier_qualifier_list (c_pretty_printer *p
  {
   const enum tree_code code = TREE_CODE (t);

 -  if (TREE_CODE (t) != POINTER_TYPE)
 +  if (!(pp-flags  pp_c_flag_gnu_v3)  TREE_CODE (t) != POINTER_TYPE)
     pp_c_type_qualifier_list (pp, t);
 +
   switch (code)
     {
     case REFERENCE_TYPE:
 @@ -494,6 +495,8 @@ pp_c_specifier_qualifier_list (c_pretty_printer *p
       pp_simple_type_specifier (pp, t);
       break;
     }
 +  if ((pp-flags  pp_c_flag_gnu_v3)  TREE_CODE (t) != POINTER_TYPE)
 +    pp_c_type_qualifier_list (pp, t);
  }

  /* parameter-type-list:
 Index: gcc/c-family/c-pretty-print.h
 ===
 --- gcc/c-family/c-pretty-print.h       (revision 187603)
 +++ gcc/c-family/c-pretty-print.h       (working copy)
 @@ -30,7 +30,8 @@ along with GCC; see the file COPYING3.  If not see
  typedef enum
   {
      pp_c_flag_abstract = 1  1,
 -     pp_c_flag_last_bit = 2
 +     pp_c_flag_last_bit = 2,
 +     pp_c_flag_gnu_v3 = 4
   } pp_c_pretty_print_flags;


 Index: gcc/cp/error.c
 ===
 --- gcc/cp/error.c      (revision 187603)
 +++ gcc/cp/error.c      (working copy)
 @@ -1028,7 +1028,12 @@ dump_decl (tree t, int flags)
            dump_scope (CP_DECL_CONTEXT (t), flags);
          flags = ~TFF_UNQUALIFIED_NAME;
          if (DECL_NAME (t) == NULL_TREE)
 -           pp_cxx_ws_string (cxx_pp, M_({anonymous}));
 +            {
 +              if (!(pp_c_base (cxx_pp)-flags  pp_c_flag_gnu_v3))
 +                pp_cxx_ws_string (cxx_pp, M_({anonymous}));
 +              else
 +                pp_cxx_ws_string (cxx_pp, M_((anonymous namespace)));
 +            }
          else
            pp_cxx_tree_identifier (cxx_pp, DECL_NAME (t));
        }
 @@ -2561,6 +2566,8 @@ decl_as_string (tree decl, int flags)
  {
   reinit_cxx_pp ();
   pp_translate_identifiers (cxx_pp) = false;
 +  if (flags  TFF_MATCH_GNU_V3_DEMANGLER)
 +    pp_c_base (cxx_pp)-flags |= pp_c_flag_gnu_v3;
   dump_decl (decl, flags);
   return pp_formatted_text (cxx_pp);
  }
 @@ -2596,6 +2603,9 @@ lang_decl_name (tree decl, int v, bool translate)

   if (TREE_CODE (decl) == FUNCTION_DECL)
     dump_function_name (decl, TFF_PLAIN_IDENTIFIER);
 +  else if ((DECL_NAME (decl) == NULL_TREE)
 +            TREE_CODE (decl) == NAMESPACE_DECL)
 +    dump_decl (decl, TFF_PLAIN_IDENTIFIER);
   else
     dump_decl (DECL_NAME (decl), TFF_PLAIN_IDENTIFIER);

 Index: gcc/cp/cp-lang.c
 ===
 --- gcc/cp/cp-lang.c    (revision 187603)
 +++ gcc/cp/cp-lang.c    (working copy)
 @@ -120,8 +120,14 @@ cxx_dwarf_name (tree t, int verbosity)
   if (verbosity = 2)
     return decl_as_string (t,
                           TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME
 -                          | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
 +                          | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
 +                           | TFF_MATCH_GNU_V3_DEMANGLER);

 +  /* decl_as_string handles namespaces--especially anonymous ones--more
 +     appropriately for debugging than cxx_printable_name.  But
 +     cxx_printable_name handles templates and global ctors and dtors better. 
  */
 +  if (TREE_CODE (t) == NAMESPACE_DECL)
 +    return decl_as_string (t, 

Re: [C++ Patch] Produce canonical names for debug info without changing normal pretty-printing (issue6215052)

2012-05-21 Thread Sterling Augustine
On Wed, May 16, 2012 at 1:03 PM, Sterling Augustine
saugust...@google.com wrote:
 This patch adds new flags and defines such that the C++ decl pretty printer
 prints both canonical dwarf names for decls without perturbing normal error
 message output.

 It addresses the issues with the earlier patches submitted as:

 http://gcc.gnu.org/ml/gcc-patches/2012-05/msg00516.html
 http://gcc.gnu.org/ml/gcc-patches/2012-05/msg00512.html

 Which are withdrawn.

 This patch requires no changes to the testsuite and does not produce
 visible changes to gcc's output except to dwarf consumers, which will now
 all agree on the names of functions.

 Tested with a full bootstrap.

 OK for mainline?

 Sterling



 2012-05-16   Sterling Augustine  saugust...@google.com

        * gcc/c-family/c-pretty-print.h (pp_c_flag_gnu_v3): New enumerator.
        * gcc/c-family/c-pretty-print.c (pp_c_specifier_qualifier_list): Check
        it at both the start and end of the function.
        * gcc/cp/cp-tree.h (TFF_MATCH_GNU_V3_DEMANGLER): Define and comment.
        * gcc/cp/error.c (dump_decl): Print appropriate string for anonymous
        namespace based on pp_c_flag_gnu_v3.
        (decl_as_string): Set cxx_pp-flags based on 
 TFF_MATCH_GNU_V3_DEMANGLER.
        (lang_decl_name): Handle unnamed namespace decls.
        * gcc/cp/cp-lang.c (cxx_dwarf_name): Call decl_as_string for namespace
        decls.

 Index: gcc/c-family/c-pretty-print.c
 ===
 --- gcc/c-family/c-pretty-print.c       (revision 187603)
 +++ gcc/c-family/c-pretty-print.c       (working copy)
 @@ -446,8 +446,9 @@ pp_c_specifier_qualifier_list (c_pretty_printer *p
  {
   const enum tree_code code = TREE_CODE (t);

 -  if (TREE_CODE (t) != POINTER_TYPE)
 +  if (!(pp-flags  pp_c_flag_gnu_v3)  TREE_CODE (t) != POINTER_TYPE)
     pp_c_type_qualifier_list (pp, t);
 +
   switch (code)
     {
     case REFERENCE_TYPE:
 @@ -494,6 +495,8 @@ pp_c_specifier_qualifier_list (c_pretty_printer *p
       pp_simple_type_specifier (pp, t);
       break;
     }
 +  if ((pp-flags  pp_c_flag_gnu_v3)  TREE_CODE (t) != POINTER_TYPE)
 +    pp_c_type_qualifier_list (pp, t);
  }

  /* parameter-type-list:
 Index: gcc/c-family/c-pretty-print.h
 ===
 --- gcc/c-family/c-pretty-print.h       (revision 187603)
 +++ gcc/c-family/c-pretty-print.h       (working copy)
 @@ -30,7 +30,8 @@ along with GCC; see the file COPYING3.  If not see
  typedef enum
   {
      pp_c_flag_abstract = 1  1,
 -     pp_c_flag_last_bit = 2
 +     pp_c_flag_last_bit = 2,
 +     pp_c_flag_gnu_v3 = 4
   } pp_c_pretty_print_flags;


 Index: gcc/cp/error.c
 ===
 --- gcc/cp/error.c      (revision 187603)
 +++ gcc/cp/error.c      (working copy)
 @@ -1028,7 +1028,12 @@ dump_decl (tree t, int flags)
            dump_scope (CP_DECL_CONTEXT (t), flags);
          flags = ~TFF_UNQUALIFIED_NAME;
          if (DECL_NAME (t) == NULL_TREE)
 -           pp_cxx_ws_string (cxx_pp, M_({anonymous}));
 +            {
 +              if (!(pp_c_base (cxx_pp)-flags  pp_c_flag_gnu_v3))
 +                pp_cxx_ws_string (cxx_pp, M_({anonymous}));
 +              else
 +                pp_cxx_ws_string (cxx_pp, M_((anonymous namespace)));
 +            }
          else
            pp_cxx_tree_identifier (cxx_pp, DECL_NAME (t));
        }
 @@ -2561,6 +2566,8 @@ decl_as_string (tree decl, int flags)
  {
   reinit_cxx_pp ();
   pp_translate_identifiers (cxx_pp) = false;
 +  if (flags  TFF_MATCH_GNU_V3_DEMANGLER)
 +    pp_c_base (cxx_pp)-flags |= pp_c_flag_gnu_v3;
   dump_decl (decl, flags);
   return pp_formatted_text (cxx_pp);
  }
 @@ -2596,6 +2603,9 @@ lang_decl_name (tree decl, int v, bool translate)

   if (TREE_CODE (decl) == FUNCTION_DECL)
     dump_function_name (decl, TFF_PLAIN_IDENTIFIER);
 +  else if ((DECL_NAME (decl) == NULL_TREE)
 +            TREE_CODE (decl) == NAMESPACE_DECL)
 +    dump_decl (decl, TFF_PLAIN_IDENTIFIER);
   else
     dump_decl (DECL_NAME (decl), TFF_PLAIN_IDENTIFIER);

 Index: gcc/cp/cp-lang.c
 ===
 --- gcc/cp/cp-lang.c    (revision 187603)
 +++ gcc/cp/cp-lang.c    (working copy)
 @@ -120,8 +120,14 @@ cxx_dwarf_name (tree t, int verbosity)
   if (verbosity = 2)
     return decl_as_string (t,
                           TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME
 -                          | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
 +                          | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
 +                           | TFF_MATCH_GNU_V3_DEMANGLER);

 +  /* decl_as_string handles namespaces--especially anonymous ones--more
 +     appropriately for debugging than cxx_printable_name.  But
 +     cxx_printable_name handles templates and global ctors and dtors better. 
  */
 +  if (TREE_CODE (t) == NAMESPACE_DECL)
 +    return decl_as_string (t, 

[C++ Patch] Produce canonical names for debug info without changing normal pretty-printing (issue6215052)

2012-05-16 Thread Sterling Augustine
This patch adds new flags and defines such that the C++ decl pretty printer
prints both canonical dwarf names for decls without perturbing normal error
message output.

It addresses the issues with the earlier patches submitted as:

http://gcc.gnu.org/ml/gcc-patches/2012-05/msg00516.html
http://gcc.gnu.org/ml/gcc-patches/2012-05/msg00512.html

Which are withdrawn.

This patch requires no changes to the testsuite and does not produce
visible changes to gcc's output except to dwarf consumers, which will now
all agree on the names of functions.

Tested with a full bootstrap.

OK for mainline?

Sterling



2012-05-16   Sterling Augustine  saugust...@google.com

* gcc/c-family/c-pretty-print.h (pp_c_flag_gnu_v3): New enumerator.
* gcc/c-family/c-pretty-print.c (pp_c_specifier_qualifier_list): Check
it at both the start and end of the function.
* gcc/cp/cp-tree.h (TFF_MATCH_GNU_V3_DEMANGLER): Define and comment.
* gcc/cp/error.c (dump_decl): Print appropriate string for anonymous
namespace based on pp_c_flag_gnu_v3.
(decl_as_string): Set cxx_pp-flags based on TFF_MATCH_GNU_V3_DEMANGLER.
(lang_decl_name): Handle unnamed namespace decls.
* gcc/cp/cp-lang.c (cxx_dwarf_name): Call decl_as_string for namespace
decls.

Index: gcc/c-family/c-pretty-print.c
===
--- gcc/c-family/c-pretty-print.c   (revision 187603)
+++ gcc/c-family/c-pretty-print.c   (working copy)
@@ -446,8 +446,9 @@ pp_c_specifier_qualifier_list (c_pretty_printer *p
 {
   const enum tree_code code = TREE_CODE (t);
 
-  if (TREE_CODE (t) != POINTER_TYPE)
+  if (!(pp-flags  pp_c_flag_gnu_v3)  TREE_CODE (t) != POINTER_TYPE)
 pp_c_type_qualifier_list (pp, t);
+
   switch (code)
 {
 case REFERENCE_TYPE:
@@ -494,6 +495,8 @@ pp_c_specifier_qualifier_list (c_pretty_printer *p
   pp_simple_type_specifier (pp, t);
   break;
 }
+  if ((pp-flags  pp_c_flag_gnu_v3)  TREE_CODE (t) != POINTER_TYPE)
+pp_c_type_qualifier_list (pp, t);
 }
 
 /* parameter-type-list:
Index: gcc/c-family/c-pretty-print.h
===
--- gcc/c-family/c-pretty-print.h   (revision 187603)
+++ gcc/c-family/c-pretty-print.h   (working copy)
@@ -30,7 +30,8 @@ along with GCC; see the file COPYING3.  If not see
 typedef enum
   {
  pp_c_flag_abstract = 1  1,
- pp_c_flag_last_bit = 2
+ pp_c_flag_last_bit = 2,
+ pp_c_flag_gnu_v3 = 4
   } pp_c_pretty_print_flags;
 
 
Index: gcc/cp/error.c
===
--- gcc/cp/error.c  (revision 187603)
+++ gcc/cp/error.c  (working copy)
@@ -1028,7 +1028,12 @@ dump_decl (tree t, int flags)
dump_scope (CP_DECL_CONTEXT (t), flags);
  flags = ~TFF_UNQUALIFIED_NAME;
  if (DECL_NAME (t) == NULL_TREE)
-   pp_cxx_ws_string (cxx_pp, M_({anonymous}));
+{
+  if (!(pp_c_base (cxx_pp)-flags  pp_c_flag_gnu_v3))
+pp_cxx_ws_string (cxx_pp, M_({anonymous}));
+  else
+pp_cxx_ws_string (cxx_pp, M_((anonymous namespace)));
+}
  else
pp_cxx_tree_identifier (cxx_pp, DECL_NAME (t));
}
@@ -2561,6 +2566,8 @@ decl_as_string (tree decl, int flags)
 {
   reinit_cxx_pp ();
   pp_translate_identifiers (cxx_pp) = false;
+  if (flags  TFF_MATCH_GNU_V3_DEMANGLER)
+pp_c_base (cxx_pp)-flags |= pp_c_flag_gnu_v3;
   dump_decl (decl, flags);
   return pp_formatted_text (cxx_pp);
 }
@@ -2596,6 +2603,9 @@ lang_decl_name (tree decl, int v, bool translate)
 
   if (TREE_CODE (decl) == FUNCTION_DECL)
 dump_function_name (decl, TFF_PLAIN_IDENTIFIER);
+  else if ((DECL_NAME (decl) == NULL_TREE)
+TREE_CODE (decl) == NAMESPACE_DECL)
+dump_decl (decl, TFF_PLAIN_IDENTIFIER);
   else
 dump_decl (DECL_NAME (decl), TFF_PLAIN_IDENTIFIER);
 
Index: gcc/cp/cp-lang.c
===
--- gcc/cp/cp-lang.c(revision 187603)
+++ gcc/cp/cp-lang.c(working copy)
@@ -120,8 +120,14 @@ cxx_dwarf_name (tree t, int verbosity)
   if (verbosity = 2)
 return decl_as_string (t,
   TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME
-  | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
+  | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
+   | TFF_MATCH_GNU_V3_DEMANGLER);
 
+  /* decl_as_string handles namespaces--especially anonymous ones--more
+ appropriately for debugging than cxx_printable_name.  But
+ cxx_printable_name handles templates and global ctors and dtors better.  
*/
+  if (TREE_CODE (t) == NAMESPACE_DECL)
+return decl_as_string (t, TFF_MATCH_GNU_V3_DEMANGLER);
   return cxx_printable_name (t, verbosity);
 }
 
Index: gcc/cp/cp-tree.h