From patchwork Sat Dec 28 10:12:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 305549 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B126E2C0089 for ; Sat, 28 Dec 2013 21:13:23 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:mime-version:message-id:content-type; q=dns; s= default; b=j4EwskO3Xyn5XElf2JqmtT/Y0U0Ryhc6jTW92lIv/Xj3tztgJxrMM WuIyI0LLfs3Dd8JyrY8dLTcC7Pm13HO0P0/XF7pffz9HBK4siNL+19ekTKu5SDFp SO76s5cpFhWjj+R5YL46NvIegYC5tIo1Gu6ealePxy8Cxz/cgfQ7dk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:mime-version:message-id:content-type; s= default; bh=80lkN3gW+c5ZVUGI/Gs31YtCCO8=; b=ZizTeHEshKFJaDXOFit8 MatIa7Tdd7XT5oYPdR8k1t4Opc4pty2MyeB0ghhtRZ5oWB090VbwI3cZinTLk7CX vjqHvOLV7mXlEUo5fQTNUrMWF/sFtOTucdstjzMhT57FWuDggjdqy9Qs8vFfqrox 5HOPVNBlX2jlzRcMNH6adZg= Received: (qmail 30059 invoked by alias); 28 Dec 2013 10:13:16 -0000 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 Received: (qmail 30049 invoked by uid 89); 28 Dec 2013 10:13:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 28 Dec 2013 10:13:14 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id BFF0A26C1F36 for ; Sat, 28 Dec 2013 11:13:11 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6lWbRBu6B4wh for ; Sat, 28 Dec 2013 11:13:11 +0100 (CET) Received: from hermes.site (ADijon-653-1-165-19.w109-221.abo.wanadoo.fr [109.221.136.19]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 995E426C1E9D for ; Sat, 28 Dec 2013 11:13:11 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: Adjust -fdump-ada-spec after C++ decloning patch Date: Sat, 28 Dec 2013 11:12:13 +0100 User-Agent: KMail/1.13.5 (Linux/2.6.34.10-0.6-desktop; KDE/4.4.4; x86_64; ; ) MIME-Version: 1.0 Message-Id: <201312281112.13256.ebotcazou@adacore.com> The C++ decloning patch revealed that the -fdump-ada-spec code handling constructors and destructors was too fragile. This patch revamps it. Tested on x86_64-suse-linux, applied on the mainline. 2013-12-28 Eric Botcazou c-family/ * c-ada-spec.c (print_constructor): New function. (print_destructor): Retrieve the origin of the destructor. (print_ada_declaration): Revamp handling of constructors/destructors. Index: c-family/c-ada-spec.c =================================================================== --- c-family/c-ada-spec.c (revision 206166) +++ c-family/c-ada-spec.c (working copy) @@ -2521,20 +2521,34 @@ dump_nested_types (pretty_printer *buffe TREE_VISITED (t) = 1; } +/* Dump in BUFFER constructor spec corresponding to T. */ + +static void +print_constructor (pretty_printer *buffer, tree t) +{ + tree decl_name = DECL_NAME (DECL_ORIGIN (t)); + + pp_string (buffer, "New_"); + pp_ada_tree_identifier (buffer, decl_name, t, false); +} + /* Dump in BUFFER destructor spec corresponding to T. */ static void print_destructor (pretty_printer *buffer, tree t) { - const char *s = IDENTIFIER_POINTER (DECL_NAME (t)); + tree decl_name = DECL_NAME (DECL_ORIGIN (t)); + const char *s = IDENTIFIER_POINTER (decl_name); if (*s == '_') - for (s += 2; *s != ' '; s++) - pp_character (buffer, *s); + { + for (s += 2; *s != ' '; s++) + pp_character (buffer, *s); + } else { pp_string (buffer, "Delete_"); - pp_ada_tree_identifier (buffer, DECL_NAME (t), t, false); + pp_ada_tree_identifier (buffer, decl_name, t, false); } } @@ -2785,7 +2799,7 @@ print_ada_declaration (pretty_printer *b } else if (TREE_CODE (t) == FUNCTION_DECL) { - bool is_function = true, is_abstract_class = false; + bool is_function, is_abstract_class = false; bool is_method = TREE_CODE (TREE_TYPE (t)) == METHOD_TYPE; tree decl_name = DECL_NAME (t); int prev_in_function = in_function; @@ -2805,24 +2819,21 @@ print_ada_declaration (pretty_printer *b is_copy_constructor = cpp_check (t, IS_COPY_CONSTRUCTOR); } - /* Skip __comp_dtor destructor which is redundant with the '~class()' - destructor. */ - if (is_destructor - && !strncmp (IDENTIFIER_POINTER (decl_name), "__comp", 6)) - return 0; - /* Skip copy constructors: some are internal only, and those that are not cannot be called easily from Ada anyway. */ if (is_copy_constructor) return 0; - /* If this function has an entry in the dispatch table, we cannot - omit it. */ - if (!DECL_VINDEX (t) && *IDENTIFIER_POINTER (decl_name) == '_') + if (is_constructor || is_destructor) { - if (IDENTIFIER_POINTER (decl_name)[1] == '_') + /* Only consider constructors/destructors for complete objects. */ + if (strncmp (IDENTIFIER_POINTER (decl_name), "__comp", 6) != 0) return 0; + } + /* If this function has an entry in the vtable, we cannot omit it. */ + else if (!DECL_VINDEX (t) && *IDENTIFIER_POINTER (decl_name) == '_') + { INDENT (spc); pp_string (buffer, "-- skipped func "); pp_string (buffer, IDENTIFIER_POINTER (decl_name)); @@ -2832,19 +2843,22 @@ print_ada_declaration (pretty_printer *b if (need_indent) INDENT (spc); - if (is_constructor) - pp_string (buffer, "function New_"); - else if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (t)))) + if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (t))) && !is_constructor) { - is_function = false; pp_string (buffer, "procedure "); + is_function = false; } else - pp_string (buffer, "function "); + { + pp_string (buffer, "function "); + is_function = true; + } in_function = is_function; - if (is_destructor) + if (is_constructor) + print_constructor (buffer, t); + else if (is_destructor) print_destructor (buffer, t); else dump_ada_decl_name (buffer, t, false); @@ -2856,16 +2870,9 @@ print_ada_declaration (pretty_printer *b if (is_function) { pp_string (buffer, " return "); - - if (is_constructor) - { - dump_ada_decl_name (buffer, t, false); - } - else - { - dump_generic_ada_node - (buffer, TREE_TYPE (TREE_TYPE (t)), type, spc, false, true); - } + tree ret_type + = is_constructor ? DECL_CONTEXT (t) : TREE_TYPE (TREE_TYPE (t)); + dump_generic_ada_node (buffer, ret_type, type, spc, false, true); } if (is_constructor @@ -2877,7 +2884,7 @@ print_ada_declaration (pretty_printer *b for (tmp = TYPE_METHODS (type); tmp; tmp = TREE_CHAIN (tmp)) if (cpp_check (tmp, IS_ABSTRACT)) { - is_abstract_class = 1; + is_abstract_class = true; break; } } @@ -2896,8 +2903,8 @@ print_ada_declaration (pretty_printer *b if (is_constructor) { - pp_string (buffer, "pragma CPP_Constructor (New_"); - dump_ada_decl_name (buffer, t, false); + pp_string (buffer, "pragma CPP_Constructor ("); + print_constructor (buffer, t); pp_string (buffer, ", \""); pp_asm_name (buffer, t); pp_string (buffer, "\");");