From patchwork Mon Jun 21 14:17:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 56322 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 7E38FB6EE9 for ; Tue, 22 Jun 2010 00:18:00 +1000 (EST) Received: (qmail 666 invoked by alias); 21 Jun 2010 14:17:55 -0000 Received: (qmail 637 invoked by uid 22791); 21 Jun 2010 14:17:52 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL, BAYES_05, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 21 Jun 2010 14:17:45 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id D34FF290014; Mon, 21 Jun 2010 16:17:45 +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 PC4AN5Z8Ouyw; Mon, 21 Jun 2010 16:17:45 +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 BFBD3290012; Mon, 21 Jun 2010 16:17:45 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id B83F3D9A01; Mon, 21 Jun 2010 16:17:45 +0200 (CEST) Date: Mon, 21 Jun 2010 16:17:45 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Vincent Celier Subject: [Ada] gnatbind -R may list several times the same source Message-ID: <20100621141745.GA23496@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 When gnatbind is invoked with switch -R, there are circumstances when the same source is listed. This patch suppresses all duplicates in the list. Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-21 Vincent Celier * gnatbind.adb: Suppress dupicates when listing the sources in the closure (switch -R). Index: gnatbind.adb =================================================================== --- gnatbind.adb (revision 161073) +++ gnatbind.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2010, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -45,6 +45,7 @@ with Rident; use Rident; with Snames; with Switch; use Switch; with Switch.B; use Switch.B; +with Table; with Targparm; use Targparm; with Types; use Types; @@ -815,55 +816,97 @@ begin -- sources) if -R was used. if List_Closure then - if not Zero_Formatting then - Write_Eol; - Write_Str ("REFERENCED SOURCES"); - Write_Eol; - end if; + declare + package Sources is new Table.Table + (Table_Component_Type => File_Name_Type, + Table_Index_Type => Natural, + Table_Low_Bound => 1, + Table_Initial => 10, + Table_Increment => 100, + Table_Name => "Gnatbind.Sources"); + -- Table to record the sources in the closure, to avoid + -- dupications. + + Source : File_Name_Type; + + function Put_In_Sources (S : File_Name_Type) return Boolean; + -- Check if S is already in table Sources and put in Sources + -- if it is not. Return False if the source is already in + -- Sources, and True if it is added. + + -------------------- + -- Put_In_Sources -- + -------------------- + + function Put_In_Sources (S : File_Name_Type) + return Boolean + is + begin + for J in 1 .. Sources.Last loop + if Sources.Table (J) = S then + return False; + end if; + end loop; - for J in reverse Elab_Order.First .. Elab_Order.Last loop + Sources.Append (S); + return True; + end Put_In_Sources; - -- Do not include the sources of the runtime + begin + if not Zero_Formatting then + Write_Eol; + Write_Str ("REFERENCED SOURCES"); + Write_Eol; + end if; - if not Is_Internal_File_Name - (Units.Table (Elab_Order.Table (J)).Sfile) - then - if not Zero_Formatting then - Write_Str (" "); + for J in reverse Elab_Order.First .. Elab_Order.Last loop + + Source := Units.Table (Elab_Order.Table (J)).Sfile; + + -- Do not include the sources of the runtime and do not + -- include the same source several times. + + if Put_In_Sources (Source) + and then not Is_Internal_File_Name (Source) + then + if not Zero_Formatting then + Write_Str (" "); + end if; + + Write_Str (Get_Name_String (Source)); + Write_Eol; end if; + end loop; - Write_Str - (Get_Name_String - (Units.Table (Elab_Order.Table (J)).Sfile)); - Write_Eol; - end if; - end loop; + -- Subunits do not appear in the elaboration table because + -- they are subsumed by their parent units, but we need to + -- list them for other tools. For now they are listed after + -- other files, rather than right after their parent, since + -- there is no easy link between the elaboration table and + -- the ALIs table ??? As subunits may appear repeatedly in + -- the list, if the parent unit appears in the context of + -- several units in the closure, duplicates are suppressed. + + for J in Sdep.First .. Sdep.Last loop + Source := Sdep.Table (J).Sfile; + + if Sdep.Table (J).Subunit_Name /= No_Name + and then Put_In_Sources (Source) + and then not Is_Internal_File_Name (Source) + then + if not Zero_Formatting then + Write_Str (" "); + end if; - -- Subunits do not appear in the elaboration table because they - -- are subsumed by their parent units, but we need to list them - -- for other tools. For now they are listed after other files, - -- rather than right after their parent, since there is no easy - -- link between the elaboration table and the ALIs table ??? - -- Note also that subunits may appear repeatedly in the list, - -- if the parent unit appears in the context of several units - -- in the closure. - - for J in Sdep.First .. Sdep.Last loop - if Sdep.Table (J).Subunit_Name /= No_Name - and then not Is_Internal_File_Name (Sdep.Table (J).Sfile) - then - if not Zero_Formatting then - Write_Str (" "); + Write_Str (Get_Name_String (Source)); + Write_Eol; end if; + end loop; - Write_Str (Get_Name_String (Sdep.Table (J).Sfile)); + if not Zero_Formatting then Write_Eol; end if; - end loop; - - if not Zero_Formatting then - Write_Eol; - end if; + end; end if; end if; end if;