diff mbox

[Google,4.6] Backport C++ canonicalization patch (issue6297080)

Message ID 20120612155832.D95D4160C6E@sterling.mtv.corp.google.com
State New
Headers show

Commit Message

Sterling Augustine June 12, 2012, 3:58 p.m. UTC
The enclosed patch for Google 4.6 backports the final pubnames-canonicalization
patch from top of trunk.  It differs slightly from the earlier one because
google/4.6 had an earlier implementation already present.

OK for Google 4.6?

Sterling

2012-06-11  Sterling Augustine  <saugustine@google.com>

	* gcc/c-family/c-pretty-print.h: Adjust pp_c_pretty_print_flags enum.
	* gcc/cp/error.c (decl_as_dwarf_string, lang_decl_dwarf_name): New
	functions.
	* gcc/cp/cp-lang.c (cxx_dwarf_name): Call them.
	* gcc/cp/cp-tree.h: Declare them.


--
This patch is available for review at http://codereview.appspot.com/6297080

Comments

Diego Novillo June 12, 2012, 4:36 p.m. UTC | #1
On 12-06-12 11:58 , Sterling Augustine wrote:

> +/* 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;
> +}

Would it make sense to factor common code in decl_as_dwarf_string()?

OK, otherwise.


Diego.
Sterling Augustine June 12, 2012, 4:57 p.m. UTC | #2
On Tue, Jun 12, 2012 at 9:36 AM, Diego Novillo <dnovillo@google.com> wrote:
> On 12-06-12 11:58 , Sterling Augustine wrote:
>
>> +/* 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;
>> +}
>
>
> Would it make sense to factor common code in decl_as_dwarf_string()?

The wrapper code is the same, but the internal call is
not--"lang_decl_name" and "decl_as_string" return different strings,
and their interface is different so it wouldn't be easy to pass a
function pointer.

So, I'm not sure how you would combine the code without it getting more ugly.

Sterling
Diego Novillo June 12, 2012, 4:58 p.m. UTC | #3
On 12-06-12 12:57 , Sterling Augustine wrote:

> The wrapper code is the same, but the internal call is
> not--"lang_decl_name" and "decl_as_string" return different strings,
> and their interface is different so it wouldn't be easy to pass a
> function pointer.
>
> So, I'm not sure how you would combine the code without it getting more ugly.

Ah, you're right.  I missed that.  In any case, that's fine.  The code 
is short enough.


Thanks.  Diego.
diff mbox

Patch

Index: gcc/c-family/c-pretty-print.h
===================================================================
--- gcc/c-family/c-pretty-print.h	(revision 188405)
+++ gcc/c-family/c-pretty-print.h	(working copy)
@@ -30,8 +30,8 @@ 
 typedef enum
   {
      pp_c_flag_abstract = 1 << 1,
-     pp_c_flag_last_bit = 2,
-     pp_c_flag_gnu_v3 = 4
+     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 188405)
+++ gcc/cp/error.c	(working copy)
@@ -2459,7 +2459,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 ();
@@ -2479,6 +2494,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 *
Index: gcc/cp/cp-lang.c
===================================================================
--- gcc/cp/cp-lang.c	(revision 188405)
+++ gcc/cp/cp-lang.c	(working copy)
@@ -183,17 +183,11 @@ 
       && (ANON_AGGRNAME_P (DECL_NAME (t)) || LAMBDANAME_P (DECL_NAME (t))))
     return NULL;
   if (verbosity >= 2)
-    return decl_as_string (t,
+    return decl_as_dwarf_string (t,
 			   TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME
-			   | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
-                           | TFF_MATCH_GNU_V3_DEMANGLER);
+                                 | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
 
-  /* 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);
+  return lang_decl_dwarf_name (t, verbosity, false);
 }
 
 static enum classify_record
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 188405)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -4913,8 +4913,10 @@ 
 extern const char *type_as_string_translate	(tree, int);
 extern const char *decl_as_string		(tree, int);
 extern const char *decl_as_string_translate	(tree, int);
+extern const char *decl_as_dwarf_string		(tree, int);
 extern const char *expr_as_string		(tree, int);
 extern const char *lang_decl_name		(tree, int, bool);
+extern const char *lang_decl_dwarf_name		(tree, int, bool);
 extern const char *language_to_string		(enum languages);
 extern const char *class_key_or_enum_as_string	(tree);
 extern void print_instantiation_context		(void);