From patchwork Wed Feb 22 14:07:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 142465 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 5E9E0B6FAA for ; Thu, 23 Feb 2012 01:07:54 +1100 (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=1330524476; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=7oNOorQn+IdXpcMevVik cvxpgBM=; b=B8ui20MTC5sFXJyNlkpcCt1mJc1baOFlrpNkd1G2Z0J5pj/YP7iQ M7cle4qwcoi3RkDw/DppFU0jT+P3cImxLObq8AsrW4xw5yQqkwW0RFkGGGaJojmR GeUqPtCXW9LH0UFqzs94ZgYleO1Z+k794rqw4eHw4+dZ5qlM9hk6tD8= 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:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=enO0eu+4a5xNbXuTnjEQWUGTFgPHmIIe/tA+MiUp/OX+tBeKUS8nkOfhpEzid1 63hG5XG/QraD9a/VbYy9OTJ1lYkfjMziElXeqjxsIAtreypRUnwCaBo1ochxpM/P X7ei7g/J67ymPDJaut4UeqtY4Iy9OUQ4cAKHF8wjQeheM=; Received: (qmail 20784 invoked by alias); 22 Feb 2012 14:07:45 -0000 Received: (qmail 20759 invoked by uid 22791); 22 Feb 2012 14:07:42 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 22 Feb 2012 14:07:09 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id C075F1C6BD5; Wed, 22 Feb 2012 09:07:07 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id RJHt9cK42xbR; Wed, 22 Feb 2012 09:07:07 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id A8A901C6BD4; Wed, 22 Feb 2012 09:07:07 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id A71A53FEE8; Wed, 22 Feb 2012 09:07:07 -0500 (EST) Date: Wed, 22 Feb 2012 09:07:07 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Handling of library unit renamings in with_clauses Message-ID: <20120222140707.GA15500@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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 A library unit name that is a renaming can appear in the name of a with_clause. When it is the prefix of a name, an implicit with_clause must be created for it, as well as for the unit it renames. So if R renames A, and we have a with_clause on R.B (where B is a child unit of A) we need with_clauses on both R an A (both of which can themselves be child units). This is because R may be used as a prefix within the current unit, and because A is needed to retrieve A.B. This patch fixes a bug in the handling of such with_clauses, and simplifies the processing by creating the with_clause for R when processing the with_clause for R.B at load time, before any analysis has taken place. The following must compile quietly: gcc -c with_child.ads --- package Orig_Parent is end Orig_Parent; --- package Orig_Parent.Child is end Orig_Parent.Child; --- function Orig_Parent.Child.Grandchild return Integer; --- package Renam_Parent is end Renam_Parent; --- with Orig_Parent.Child; package Renam_Parent.Child renames Orig_Parent.Child; --- with Renam_Parent.Child.Grandchild; package With_Child is X : Integer := Renam_Parent.Child.Grandchild; end With_Child; Tested on x86_64-pc-linux-gnu, committed on trunk 2012-02-22 Ed Schonberg * lib-load.adb (Load_Unit): If the prefix of the name in a with-clause is a renaming, add a with-clause on the original unit. * sem_ch10.adb (Build_Unit_Name): Remove code made obsolete by new handling of renamings in with-clauses. Index: lib-load.adb =================================================================== --- lib-load.adb (revision 184470) +++ lib-load.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2011, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2012, 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- -- @@ -406,9 +406,25 @@ New_Child (Load_Name, Get_Unit_Name (Name (Unit (Cunit (Unump))))); + -- If the load is for a with_clause, for visibility purposes both + -- the renamed entity and renaming one must be available in the + -- current unit: the renamed one in order to retrieve the child + -- unit, and the original one because it may be used as a prefix + -- in the body of the current unit. We add an explicit with_clause + -- for the original parent so that the renaming declaration is + -- properly loaded and analyzed. + + if Present (With_Node) then + Insert_After (With_Node, + Make_With_Clause (Sloc (With_Node), + Name => Copy_Separate_Tree (Prefix (Name (With_Node))))); + end if; + -- Save the renaming entity, to establish its visibility when -- installing the context. The implicit with is on this entity, - -- not on the package it renames. + -- not on the package it renames. This is somewhat redundant given + -- the with_clause just created, but it simplifies subsequent + -- expansion of the current with_clause. Optimizable ??? if Nkind (Error_Node) = N_With_Clause and then Nkind (Name (Error_Node)) = N_Selected_Component Index: sem_ch10.adb =================================================================== --- sem_ch10.adb (revision 184470) +++ sem_ch10.adb (working copy) @@ -2936,33 +2936,12 @@ function Build_Unit_Name (Nam : Node_Id) return Node_Id is Ent : Entity_Id; - Renaming : Entity_Id; Result : Node_Id; begin if Nkind (Nam) = N_Identifier then + return New_Occurrence_Of (Entity (Nam), Loc); - -- If the parent unit P in the name of the with_clause for P.Q is - -- a renaming of package R, then the entity of the parent is set - -- to R, but the identifier retains Chars (P) to be consistent - -- with the source (see details in lib-load). However the implicit - -- with_clause for the parent must make the entity for P visible, - -- because P.Q may be used as a prefix within the current unit. - -- The entity for P is the current_entity with that name, because - -- the package renaming declaration for it has just been analyzed. - -- Note that this case can only happen if P.Q has already appeared - -- in a previous with_clause in a related unit, such as the - -- library body of the current unit. - - if Chars (Nam) /= Chars (Entity (Nam)) then - Renaming := Current_Entity (Nam); - pragma Assert (Renamed_Entity (Renaming) = Entity (Nam)); - return New_Occurrence_Of (Renaming, Loc); - - else - return New_Occurrence_Of (Entity (Nam), Loc); - end if; - else Ent := Entity (Nam);