From patchwork Fri Oct 22 09:15:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 68815 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 9C5A1100AC4 for ; Fri, 22 Oct 2010 20:15:33 +1100 (EST) Received: (qmail 27198 invoked by alias); 22 Oct 2010 09:15:27 -0000 Received: (qmail 27129 invoked by uid 22791); 22 Oct 2010 09:15:25 -0000 X-SWARE-Spam-Status: No, hits=-1.5 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; Fri, 22 Oct 2010 09:15:17 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 9D020CB01EF; Fri, 22 Oct 2010 11:15:15 +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 1QqvKPOCvamx; Fri, 22 Oct 2010 11:15:15 +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 8B0A9CB01D6; Fri, 22 Oct 2010 11:15:15 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 6F0DDD9BB4; Fri, 22 Oct 2010 11:15:15 +0200 (CEST) Date: Fri, 22 Oct 2010 11:15:15 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Parent_Unit_Names and unit renaming declarations Message-ID: <20101022091515.GA4436@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 If the parent unit name that appears in a with_clause denotes a renaming declaration, the parser has already retrieved the renamed unit in order to obtain the real library unit denoted by the clause. If the parent unit nsme is a simple name we set its entity to be the renamed unit. If the parent unit name is itself a child unit, the prefix of its name is irrelevant to subsequent visibility, and we replace it directly with a reference to the renamed unit. Compiling and executing main.adb below must yield; P2 P2.Sub P2 P2.Sub ----- with Root.P1; with Root.P1.Sub; with P3; procedure Main is begin Root.P1.Proc; Root.P1.Sub.Proc; P3.Run; end Main; --- package Root is procedure proc; end Root; --- package P2 is procedure Proc; end P2; --- package P3 is procedure Run; end P3; --- with P2; package Root.P1 renames P2; --- with Ada.Text_IO; package body P2.Sub is procedure Proc is begin Ada.Text_IO.Put_Line ("P2.Sub"); end Proc; end P2.Sub; --- package P2.Sub is procedure Proc; end P2.Sub; --- with Ada.Text_IO; package body P2 is procedure Proc is begin Ada.Text_IO.Put_Line ("P2"); end Proc; end P2; --- with Root.P1; with Root.P1.Sub; package body P3 is procedure Run is begin Root.P1.Proc; Root.P1.Sub.Proc; end Run; end P3; --- with Ada.Text_IO; package body Root is procedure Proc is begin Ada.Text_IO.Put_Line ("Root"); end Proc; end Root; --- Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-22 Ed Schonberg * sem_ch10.adb (Analyze_With_Clause): If the parent_unit_name in a with clause is a child unit that denotes a renaming, replace the parent_unit_name with a reference to the renamed unit, because the prefix is irrelevant to subsequent visibility.. Index: sem_ch10.adb =================================================================== --- sem_ch10.adb (revision 165803) +++ sem_ch10.adb (working copy) @@ -2556,6 +2556,22 @@ package body Sem_Ch10 is Par_Name := Scope (E_Name); while Nkind (Pref) = N_Selected_Component loop Change_Selected_Component_To_Expanded_Name (Pref); + + if Present (Entity (Selector_Name (Pref))) + and then + Present (Renamed_Entity (Entity (Selector_Name (Pref)))) + and then Entity (Selector_Name (Pref)) /= Par_Name + then + + -- The prefix is a child unit that denotes a renaming + -- declaration. Replace the prefix directly with the renamed + -- unit, because the rest of the prefix is irrelevant to the + -- visibility of the real unit. + + Rewrite (Pref, New_Occurrence_Of (Par_Name, Sloc (Pref))); + exit; + end if; + Set_Entity_With_Style_Check (Pref, Par_Name); Generate_Reference (Par_Name, Pref);