From patchwork Thu Oct 28 08:59:26 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 69444 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 EC0C5B70D4 for ; Thu, 28 Oct 2010 19:59:39 +1100 (EST) Received: (qmail 17384 invoked by alias); 28 Oct 2010 08:59:36 -0000 Received: (qmail 17374 invoked by uid 22791); 28 Oct 2010 08:59:35 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 28 Oct 2010 08:59:30 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 4E478CB0290; Thu, 28 Oct 2010 10:59:27 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4Ox8R9XpX-sT; Thu, 28 Oct 2010 10:59:27 +0200 (CEST) Received: from saumur.act-europe.fr (saumur.act-europe.fr [10.10.0.183]) by mel.act-europe.fr (Postfix) with ESMTP id 1B027CB025D; Thu, 28 Oct 2010 10:59:26 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id A741BD9BB4; Thu, 28 Oct 2010 10:59:26 +0200 (CEST) Date: Thu, 28 Oct 2010 10:59:26 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org, joseph@codesourcery.com Subject: [C patch] fix reference to classes with -fdump-ada-spec Message-ID: <20101028085926.GA18090@adacore.com> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.9i X-IsSubscribed: yes 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 This is a patch that fixes class references across header files when generate Ada specs via -fdump-ada-spec. Consider the following code: -- f1.hh #ifndef F1 #define F1 class c1 { c1(); ~c1(); }; #endif -- f2.hh #include "f1.hh" class c2{ c1 *data; c2(); ~c2(); }; Prior to this change, we would generate incorrect references to c1, missing the c1_Class prefix: << package f2_hh is package Class_c2 is type c2 is limited record data : access f1_hh.c1; -- f2.hh:4 end record; >> With this patch we now generate: << package f2_hh is package Class_c2 is type c2 is limited record data : access f1_hh.Class_c1.c1; -- f2.hh:4 end record; >> This is fixed by using the same test used to decide whether to create a nested package for classes, factorized in a new function separate_class_package and called in pp_ada_tree_identifier and print_ada_declaration. Tested on x86_64-pc-linux-gnu, OK for trunk? c-family: 2010-10-28 Arnaud Charlet Matthew Gingell * c-ada-spec.c (separate_class_package): New function. (pp_ada_tree_identifier): Prefix references to C++ classes with the name of their enclosing package. (print_ada_declaration): Use separate_class_package. --- c-ada-spec.c (revision 166026) +++ c-ada-spec.c (working copy) @@ -51,6 +51,7 @@ static void dump_ada_withs (FILE *); static void dump_ads (const char *, void (*)(const char *), int (*)(tree, cpp_operation)); static char *to_ada_name (const char *, int *); +static bool separate_class_package (tree); #define LOCATION_COL(LOC) ((expand_location (LOC)).column) @@ -1152,6 +1153,23 @@ to_ada_name (const char *name, int *spac return s; } +/* Return true if DECL refers to a C++ class type for which a + separate enclosing package has been or should be generated. */ + +static bool +separate_class_package (tree decl) +{ + if (decl) + { + tree type = TREE_TYPE (decl); + return type + && TREE_CODE (type) == RECORD_TYPE + && (TYPE_METHODS (type) || has_static_fields (type)); + } + else + return false; +} + static bool package_prefix = true; /* Dump in BUFFER the name of an identifier NODE of type TYPE, following Ada @@ -1209,7 +1227,15 @@ pp_ada_tree_identifier (pretty_printer * default: break; } - } + + if (separate_class_package (decl)) + { + pp_string (buffer, "Class_"); + pp_string (buffer, s); + pp_string (buffer, "."); + } + + } } } @@ -2607,8 +2633,7 @@ print_ada_declaration (pretty_printer *b { dump_nested_types (buffer, t, t, false, cpp_check, spc); - if (TYPE_METHODS (TREE_TYPE (t)) - || has_static_fields (TREE_TYPE (t))) + if (separate_class_package (t)) { is_class = true; pp_string (buffer, "package Class_");