From patchwork Mon Oct 1 08:33:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 188240 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 C441B2C00E5 for ; Mon, 1 Oct 2012 18:33:34 +1000 (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=1349685216; 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=cWdqfh/2gyNQLLcNlZiw UkPihMk=; b=TiiXMqh+whxIdGn5N/qlVt5idl+BzLDprTAd4ab+WAA2gYQipUTt lqcUp4eplQeKBPHbxATgiB+E0wSQZ/0OqsWqTz1EqDPo3/HEXjqAE5AkOpm/AVpG ICM4pLR59hiUAmF2eaqL68JP1pNuvOHvF/EFOJz8fkrzCR18pzhLLLI= 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=WO9vaaUsDJY6MdhBInCNKyllHaaCqfACUxqFShfRta/XM+VWTk+q/3zFedb+2f jhNfvEA88hMVpSUMzHrzuV2V+UjwnX798kJKcdG81/119PP3BGRBZZ7bMb2mcL72 iKgF+voiWFCfmyLp3DGgFasn1CMpoL0e1xF+8L8entUHY=; Received: (qmail 5067 invoked by alias); 1 Oct 2012 08:33:24 -0000 Received: (qmail 5041 invoked by uid 22791); 1 Oct 2012 08:33:19 -0000 X-SWARE-Spam-Status: No, hits=-1.9 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; Mon, 01 Oct 2012 08:33:14 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 94FDC1C7664; Mon, 1 Oct 2012 04:33:13 -0400 (EDT) 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 Fol2x9Ullumm; Mon, 1 Oct 2012 04:33:13 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 741B21C765C; Mon, 1 Oct 2012 04:33:13 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 7350F3FF09; Mon, 1 Oct 2012 04:33:13 -0400 (EDT) Date: Mon, 1 Oct 2012 04:33:13 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Yannick Moy Subject: [Ada] Set the flag In_Assertion_Expr during analysis of assertion expressions Message-ID: <20121001083313.GA32134@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 In_Assertion_Expr should be non-zero during analysis of assertion expressions, even for preanalysis of these expressions. So wrap the call to Preanalyze_Spec_Expression to provide proper increment/decrement of the flag for assertion expressions. Tested on x86_64-pc-linux-gnu, committed on trunk 2012-10-01 Yannick Moy * sem_ch13.adb (Add_Invariants): Analyze the invariant expression as an assertion expression. * sem_ch3.adb / sem_ch3.ads (Preanalyze_Assert_Expression): New procedure that wraps a call to Preanalyze_Spec_Expression for assertion expressions, so that In_Assertion_Expr can be properly adjusted. * sem_prag.adb (Analyze_PPC_In_Decl_Part Check_Precondition_Postcondition Preanalyze_CTC_Args): Call the new Preanalyze_Assert_Expression. Index: sem_ch3.adb =================================================================== --- sem_ch3.adb (revision 191888) +++ sem_ch3.adb (working copy) @@ -19306,6 +19306,17 @@ end if; end Check_Anonymous_Access_Components; + ---------------------------------- + -- Preanalyze_Assert_Expression -- + ---------------------------------- + + procedure Preanalyze_Assert_Expression (N : Node_Id; T : Entity_Id) is + begin + In_Assertion_Expr := In_Assertion_Expr + 1; + Preanalyze_Spec_Expression (N, T); + In_Assertion_Expr := In_Assertion_Expr - 1; + end Preanalyze_Assert_Expression; + -------------------------------- -- Preanalyze_Spec_Expression -- -------------------------------- Index: sem_ch3.ads =================================================================== --- sem_ch3.ads (revision 191888) +++ sem_ch3.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- 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- -- @@ -246,6 +246,10 @@ -- This mechanism is also used for aspect specifications that have an -- expression parameter that needs similar preanalysis. + procedure Preanalyze_Assert_Expression (N : Node_Id; T : Entity_Id); + -- Wrapper on Preanalyze_Spec_Expression for assertion expressions, so that + -- In_Assertion_Expr can be properly adjusted. + procedure Process_Full_View (N : Node_Id; Full_T, Priv_T : Entity_Id); -- Process some semantic actions when the full view of a private type is -- encountered and analyzed. The first action is to create the full views Index: sem_prag.adb =================================================================== --- sem_prag.adb (revision 191897) +++ sem_prag.adb (working copy) @@ -286,9 +286,7 @@ -- Preanalyze the boolean expression, we treat this as a spec expression -- (i.e. similar to a default expression). - In_Assertion_Expr := In_Assertion_Expr + 1; - Preanalyze_Spec_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean); - In_Assertion_Expr := In_Assertion_Expr - 1; + Preanalyze_Assert_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean); -- In ASIS mode, for a pragma generated from a source aspect, also -- analyze the original aspect expression. @@ -296,7 +294,7 @@ if ASIS_Mode and then Present (Corresponding_Aspect (N)) then - Preanalyze_Spec_Expression + Preanalyze_Assert_Expression (Expression (Corresponding_Aspect (N)), Standard_Boolean); end if; @@ -2178,7 +2176,7 @@ then -- Analyze pragma expression for correctness and for ASIS use - Preanalyze_Spec_Expression + Preanalyze_Assert_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean); -- In ASIS mode, for a pragma generated from a source aspect, @@ -2187,7 +2185,7 @@ if ASIS_Mode and then Present (Corresponding_Aspect (N)) then - Preanalyze_Spec_Expression + Preanalyze_Assert_Expression (Expression (Corresponding_Aspect (N)), Standard_Boolean); end if; end if; @@ -6773,7 +6771,8 @@ -- pragma Check (Assertion, condition [, msg]); - -- So rewrite pragma in this manner, and analyze the result + -- So rewrite pragma in this manner, transfer the message + -- argument if present, and analyze the result Expr := Get_Pragma_Arg (Arg1); Newa := New_List ( @@ -6785,8 +6784,7 @@ if Arg_Count > 1 then Check_Optional_Identifier (Arg2, Name_Message); - Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String); - Append_To (Newa, Relocate_Node (Arg2)); + Append_To (Newa, New_Copy_Tree (Arg2)); end if; Rewrite (N, @@ -15532,27 +15530,27 @@ -- expressions (i.e. similar to a default expression). if Present (Arg_Req) then - Preanalyze_Spec_Expression + Preanalyze_Assert_Expression (Get_Pragma_Arg (Arg_Req), Standard_Boolean); -- In ASIS mode, for a pragma generated from a source aspect, also -- analyze the original aspect expression. if ASIS_Mode and then Present (Corresponding_Aspect (N)) then - Preanalyze_Spec_Expression + Preanalyze_Assert_Expression (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean); end if; end if; if Present (Arg_Ens) then - Preanalyze_Spec_Expression + Preanalyze_Assert_Expression (Get_Pragma_Arg (Arg_Ens), Standard_Boolean); -- In ASIS mode, for a pragma generated from a source aspect, also -- analyze the original aspect expression. if ASIS_Mode and then Present (Corresponding_Aspect (N)) then - Preanalyze_Spec_Expression + Preanalyze_Assert_Expression (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean); end if; end if; Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 191890) +++ sem_ch13.adb (working copy) @@ -5058,7 +5058,7 @@ -- at the end of the private part and has the wrong visibility. Set_Parent (Exp, N); - Preanalyze_Spec_Expression (Exp, Standard_Boolean); + Preanalyze_Assert_Expression (Exp, Standard_Boolean); -- Build first two arguments for Check pragma