From patchwork Wed Feb 6 10:24:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 218534 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 C613F2C02C2 for ; Wed, 6 Feb 2013 21:25:05 +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=1360751106; 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=WdxRsl1vsYB51i+51ZU6 I3vCTYs=; b=xFFltcxeQa6IataSe81qddwmB5sEUFl7XkmaRRmJyrskx0nV0fVp zWMAcAOrX+M0X58RCSgoS+B7yxnwQmLPpWX+COiqPLID+gJriadN0e4iV2uTBk1E oK/9As0QtHOWNxIwOFSJQG9wXDax0PIhfFyI+qcSnyPeYG043yohSvU= 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=iWXWyOXLrAjpuFyag2H/SpeW8nVUiNxlNZh4ldLNjKmFVV90Jr4uJvCrqk9OXB 011yzUVynboGueD8pqfkqdaKq99iitvhyqQ2Q72SmftFQOI93dUJdbqyGNPpV2Bg 3K01s36zpYSc+35/nIVcPpn9rIxWrjLGZ/lAj5AaoqxBU=; Received: (qmail 31484 invoked by alias); 6 Feb 2013 10:24:45 -0000 Received: (qmail 31433 invoked by uid 22791); 6 Feb 2013 10:24:44 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_NO 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, 06 Feb 2013 10:24:39 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 581992E612; Wed, 6 Feb 2013 05:24:38 -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 AW5OXBfI0F2l; Wed, 6 Feb 2013 05:24:38 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 396B32E1C3; Wed, 6 Feb 2013 05:24:38 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id 390543FF09; Wed, 6 Feb 2013 05:24:38 -0500 (EST) Date: Wed, 6 Feb 2013 05:24:38 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Implement Rational profile to support non-standard renaming declarations Message-ID: <20130206102438.GA25551@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 We introduce the profile Rational and the corresponding pragma to support legacy Rational code that accepts subprogram renaming declarations that are not conformant to the RM. The following program, compiled with -gnatc, must generate the message: ren.ads:12:51: subprogram cannot rename itself The program must compile quietly if the pragma is uncommented. --- -- pragma Rational; package Ren is package P is type T is null record; function F (Obj : T) return integer; end P; use P; type DT is new T; package RR renames Ren; function F (New_Parameter : DT) return Integer renames RR.F; end; Tested on x86_64-pc-linux-gnu, committed on trunk 2013-02-06 Ed Schonberg * snames.ads-tmpl: Add Name_Rational and pragma Rational. * par-prag.adb: Recognize pragma Rational. * opt.ads (Rational_Profile): flag to control compatibility mode with Rational compiler. * sem_ch8.adb (Analyze_Subprogram_Renaming): When Rational profile is enable, accept renaming declarations where the new subprogram and the renamed entity have the same name. * sem_prag.adb (analyze_pragma): Add pragma Rational, and recognize Rational as a profile. Index: sem_prag.adb =================================================================== --- sem_prag.adb (revision 195788) +++ sem_prag.adb (working copy) @@ -13859,7 +13859,7 @@ -- pragma Profile (profile_IDENTIFIER); - -- profile_IDENTIFIER => Restricted | Ravenscar + -- profile_IDENTIFIER => Restricted | Ravenscar | Rational when Pragma_Profile => Ada_2005_Pragma; @@ -13879,6 +13879,9 @@ (Restricted, N, Warn => Treat_Restrictions_As_Warnings); + elsif Chars (Argx) = Name_Rational then + Rational_Profile := True; + elsif Chars (Argx) = Name_No_Implementation_Extensions then Set_Profile_Restrictions (No_Implementation_Extensions, @@ -14275,6 +14278,15 @@ end if; end; + -------------- + -- Rational -- + -------------- + + -- pragma Rational, for compatibility with foreign compiler + + when Pragma_Rational => + Rational_Profile := True; + ----------------------- -- Relative_Deadline -- ----------------------- @@ -16599,6 +16611,7 @@ Pragma_Pure_12 => -1, Pragma_Pure_Function => -1, Pragma_Queuing_Policy => -1, + Pragma_Rational => -1, Pragma_Ravenscar => -1, Pragma_Relative_Deadline => -1, Pragma_Remote_Access_Type => -1, Index: par-prag.adb =================================================================== --- par-prag.adb (revision 195784) +++ par-prag.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2012, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2013, 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- -- @@ -1245,6 +1245,7 @@ Pragma_Remote_Call_Interface | Pragma_Remote_Types | Pragma_Restricted_Run_Time | + Pragma_Rational | Pragma_Ravenscar | Pragma_Reviewable | Pragma_Share_Generic | Index: sem_ch8.adb =================================================================== --- sem_ch8.adb (revision 195784) +++ sem_ch8.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2012, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2013, 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- -- @@ -2804,18 +2804,25 @@ end if; end if; - if not Is_Actual - and then (Old_S = New_S - or else - (Nkind (Nam) /= N_Expanded_Name - and then Chars (Old_S) = Chars (New_S)) - or else - (Nkind (Nam) = N_Expanded_Name - and then Entity (Prefix (Nam)) = Current_Scope - and then - Chars (Selector_Name (Nam)) = Chars (New_S))) + if Is_Actual then + null; + + -- The following is illegal, because F hides whatever other F may + -- be around: + -- function F (..) renames F; + + elsif Old_S = New_S + or else (Nkind (Nam) /= N_Expanded_Name + and then Chars (Old_S) = Chars (New_S)) then Error_Msg_N ("subprogram cannot rename itself", N); + + elsif Nkind (Nam) = N_Expanded_Name + and then Entity (Prefix (Nam)) = Current_Scope + and then Chars (Selector_Name (Nam)) = Chars (New_S) + and then not Rational_Profile + then + Error_Msg_N ("subprogram cannot rename itself", N); end if; Set_Convention (New_S, Convention (Old_S)); Index: opt.ads =================================================================== --- opt.ads (revision 195784) +++ opt.ads (working copy) @@ -1181,6 +1181,10 @@ -- Set to True if the tool should not have any output if there are no -- errors or warnings. + Rational_Profile : Boolean := False; + -- GNAT + -- Set to True to enable compatibility mode with Rational compiler. + Replace_In_Comments : Boolean := False; -- GNATPREP -- Set to True if -C switch used Index: snames.ads-tmpl =================================================================== --- snames.ads-tmpl (revision 195784) +++ snames.ads-tmpl (working copy) @@ -6,7 +6,7 @@ -- -- -- T e m p l a t e -- -- -- --- Copyright (C) 1992-2012, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2013, 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- -- @@ -422,6 +422,7 @@ Name_Profile_Warnings : constant Name_Id := N + $; -- GNAT Name_Propagate_Exceptions : constant Name_Id := N + $; -- GNAT Name_Queuing_Policy : constant Name_Id := N + $; + Name_Rational : constant Name_Id := N + $; -- GNAT Name_Ravenscar : constant Name_Id := N + $; -- GNAT Name_Restricted_Run_Time : constant Name_Id := N + $; -- GNAT Name_Restrictions : constant Name_Id := N + $; @@ -1717,6 +1718,7 @@ Pragma_Profile_Warnings, Pragma_Propagate_Exceptions, Pragma_Queuing_Policy, + Pragma_Rational, Pragma_Ravenscar, Pragma_Restricted_Run_Time, Pragma_Restrictions,