From patchwork Fri Jun 1 23:07:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sterling Augustine X-Patchwork-Id: 162383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 48A17B6FBE for ; Sat, 2 Jun 2012 09:08:13 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1339196894; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:Received:To:Subject:Message-Id:Date: From:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=2CGVLq+ hi3f/F/f2RvFIIIufMYA=; b=F7XYssYFOYfMP7pGBxYwzF181hBwB//SGT7FiA1 ydsTWSg1mVgXvCROqeGp5v5ocSNs0pRLPJyiUTF3h4w6rg+xPV/VoKeEXFtfG0bw sbcVPUk2wKlRqrad40iCAUZbIZaqe36MO7GwMiwBcS6FxupZ5RyZKrUL+ZvI5I/N jlXw= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:Received:Received:Received:To:Subject:Message-Id:Date:From:X-Gm-Message-State:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=CDMBbJ4l9o6KeYJa2odugthPWUcs8w+CJFSYWNKRxHCQRWpj+mhUls9BHdHgP9 eFGwK9WP6YjRE1Cj8qYr0P4Je19O/8pWTKNE0jWrHDcfljwGuc6e/5Z3XZvtJz1d YywG4kfY9n7MitIU4wKwa+KwbF38lT0tpoLlFoJ59mv5c=; Received: (qmail 13634 invoked by alias); 1 Jun 2012 23:08:09 -0000 Received: (qmail 13623 invoked by uid 22791); 1 Jun 2012 23:08:07 -0000 X-SWARE-Spam-Status: No, hits=-4.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_CX, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-we0-f201.google.com (HELO mail-we0-f201.google.com) (74.125.82.201) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jun 2012 23:07:54 +0000 Received: by wefh52 with SMTP id h52so151379wef.2 for ; Fri, 01 Jun 2012 16:07:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=to:subject:message-id:date:from:x-gm-message-state; bh=nIPKoMLKU7Z2UwMJKJOD+6mjqiylGq9eCkNYehqGkYo=; b=Tkn8Xdwb6L5h7FSyv4n7Wkcem73r0crCTIWO+wfxH0Ii7l//XxlLCe5sETlpkvUVo4 3AuElGbipn0YllIAQiZKkEW8B08FHQi8kA84IhlGinGw4SNGnsn7JR878oQsspLK20tI At33S3KftZ01DeC4ultCf3mYMAmk9Fby+YbwAknt00eG45PKSEcSoDRzHAYOst8yjzjO JM63kJr4PijQSJw4kVVtcIeAEw6RNuStWRq8j4rvMLlm+A4niNi/RqZCenIriEsh+ngP zkEybSyH24d7rPBQkinplIV9z3iMqp1C9c9gkV3MNpnptReRhuAIgR+5es629Vghyfox U7DQ== Received: by 10.14.101.2 with SMTP id a2mr1674508eeg.6.1338592073127; Fri, 01 Jun 2012 16:07:53 -0700 (PDT) Received: by 10.14.101.2 with SMTP id a2mr1674500eeg.6.1338592073009; Fri, 01 Jun 2012 16:07:53 -0700 (PDT) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id b16si3271508eeg.3.2012.06.01.16.07.53 (version=TLSv1/SSLv3 cipher=AES128-SHA); Fri, 01 Jun 2012 16:07:53 -0700 (PDT) Received: from sterling.mtv.corp.google.com (sterling.mtv.corp.google.com [172.18.111.14]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id A72EA20004E; Fri, 1 Jun 2012 16:07:52 -0700 (PDT) Received: by sterling.mtv.corp.google.com (Postfix, from userid 135279) id E0FEB160730; Fri, 1 Jun 2012 16:07:51 -0700 (PDT) To: reply@codereview.appspotmail.com, gdr@integrable-solutions.net, gcc-patches@gcc.gnu.org Subject: [C++ Patch] Produce canonical names for debug info without changing normal pretty-printing (issue6215052) Message-Id: <20120601230751.E0FEB160730@sterling.mtv.corp.google.com> Date: Fri, 1 Jun 2012 16:07:51 -0700 (PDT) From: saugustine@google.com (Sterling Augustine) X-Gm-Message-State: ALoCoQm2f4CmZVEWGMANMbJlOj2/+3HEN+q9/wKtVjdotYtHz1RO7QLrh//atM5aUP/snPB3NC+mwO7sGHx9nMRYrierk+dU4r7T4OfYJpmgJ528W25uDlp4W2Z1WpXMHx29ntlmstFhfAW7xGlLbB+a//54GQTKRw== Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 * 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. --- This patch is available for review at http://codereview.appspot.com/6215052 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 - | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS); + return decl_as_dwarf_string (t, + TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME + | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS); - 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 188034) +++ gcc/cp/cp-tree.h (working copy) @@ -5169,8 +5169,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);