From patchwork Tue Oct 5 10:30:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 66815 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 4000EB6EEB for ; Tue, 5 Oct 2010 21:30:38 +1100 (EST) Received: (qmail 19406 invoked by alias); 5 Oct 2010 10:30:35 -0000 Received: (qmail 19396 invoked by uid 22791); 5 Oct 2010 10:30: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) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 05 Oct 2010 10:30:28 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 7242ACB0268; Tue, 5 Oct 2010 12:30:25 +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 zv2hceOv-6oc; Tue, 5 Oct 2010 12:30:25 +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 5F9F2CB024C; Tue, 5 Oct 2010 12:30:25 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 41BB7D9BB5; Tue, 5 Oct 2010 12:30:25 +0200 (CEST) Date: Tue, 5 Oct 2010 12:30:25 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Robert Dewar Subject: [Ada] Ada 2012 AI05-0163-1/01 Pragmas in place of null Message-ID: <20101005103025.GA18594@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 patch implements the recommendation of this AI, expected to become part of Ada 2012, to allow a statement sequence consisting only of pragmas. The following compiles silently with -gnat2012 -gnata -gnatws procedure PragmaForNull is X : Integer := 3; begin if X > 2 then pragma Assert (X = 4); end if; end; and generates the output: raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : pragmafornull.adb:5 Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-05 Robert Dewar * par-ch5.adb (Test_Statement_Required): Allow all pragmas in Ada 2012 mode. Index: par-ch5.adb =================================================================== --- par-ch5.adb (revision 164906) +++ par-ch5.adb (working copy) @@ -190,14 +190,40 @@ package body Ch5 is ----------------------------- procedure Test_Statement_Required is + function All_Pragmas return Boolean; + -- Return True if statement list is all pragmas + + ----------------- + -- All_Pragmas -- + ----------------- + + function All_Pragmas return Boolean is + S : Node_Id; + begin + S := First (Statement_List); + while Present (S) loop + if Nkind (S) /= N_Pragma then + return False; + else + Next (S); + end if; + end loop; + + return True; + end All_Pragmas; + + -- Start of processing for Test_Statement_Required + begin if Statement_Required then - -- Check no statement required after label in Ada 2012 + -- Check no statement required after label in Ada 2012, and that + -- it is OK to have nothing but pragmas in a statement sequence. if Ada_Version >= Ada_2012 and then not Is_Empty_List (Statement_List) - and then Nkind (Last (Statement_List)) = N_Label + and then (Nkind (Last (Statement_List)) = N_Label + or else All_Pragmas) then declare Null_Stm : constant Node_Id := @@ -207,6 +233,8 @@ package body Ch5 is Append_To (Statement_List, Null_Stm); end; + -- All pragmas is OK on + -- If not Ada 2012, or not special case above, give error message else