From patchwork Mon Jan 23 09:44:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 137326 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 08E0BB6FB9 for ; Mon, 23 Jan 2012 20:45: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=1327916708; 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=VPrklmAgf1DIrBs9gi5c Hkp3izE=; b=bnnJXI01S7B14pX+GlzNxX7sKYmWM5yI+NLIm24D1p58IHpc50tq 7dePSjY16KKp/jHi+MhyZJEezFhSv/KJbwOd3FLK66znioGM76seg0+0Q8/RgFl/ +eBTjNeYkRDpxFZoYitksukSmam424bC6hWtoU5ramVbpl+oMwHJ6rc= 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=dxlXizAhPOP3uLGekVfzZlazDEJP2bit+Lad1L+fuS6MEM1uyvDFvYIrPrbO2Y KpG90pDrlCVI2hatvGpo66+XfDRlsz2PR8Y3gI4+DIHrBDglv2pYYJI2eJxxvkaS CBMYYNzDbhXH1wX7dhp+Ifef+uDcYkPSZWVqEaRWtqT6k=; Received: (qmail 10096 invoked by alias); 23 Jan 2012 09:44:59 -0000 Received: (qmail 10080 invoked by uid 22791); 23 Jan 2012 09:44:58 -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; Mon, 23 Jan 2012 09:44:45 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 7D70F2BAC51; Mon, 23 Jan 2012 04:44:44 -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 t6GKvr7f8oYu; Mon, 23 Jan 2012 04:44:44 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 6469D2BABF0; Mon, 23 Jan 2012 04:44:44 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id 62BF792BF6; Mon, 23 Jan 2012 04:44:44 -0500 (EST) Date: Mon, 23 Jan 2012 04:44:44 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Vincent Pucci Subject: [Ada] issue in ASIS with aspects Message-ID: <20120123094444.GA15146@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 Generation of analysis information for precondition and postcondition boolean expressions appearing in the spec of a generic subprogram declaration in ASIS mode. Tested on x86_64-pc-linux-gnu, committed on trunk 2012-01-23 Vincent Pucci * sem_ch12.adb (Analyze_Generic_Subprogram_Declaration): Call to Make_Aspect_For_PPC_In_Gen_Sub_Decl added in ASIS mode. * sem_prag.adb, sem_prag.ads (Make_Aspect_For_PPC_In_Gen_Sub_Decl): New routine. In ASIS mode, convert any PPC pragmas into aspects in generic subprogram declaration in order to enable the analysis of PPC boolean expressions. Index: sem_prag.adb =================================================================== --- sem_prag.adb (revision 183420) +++ sem_prag.adb (working copy) @@ -7991,8 +7991,9 @@ -- Normally the analysis that follows will freeze the subprogram -- being called. However, if the call is to a null procedure, -- we want to freeze it before creating the block, because the - -- analysis that follows may be done with expansion disabled, and - -- and the body will not be generated, leading to spurious errors. + -- analysis that follows may be done with expansion disabled, in + -- which case the body will not be generated, leading to spurious + -- errors. if Nkind (Call) = N_Procedure_Call_Statement and then Is_Entity_Name (Name (Call)) @@ -15242,6 +15243,82 @@ end if; end Is_Pragma_String_Literal; + ----------------------------------------- + -- Make_Aspect_For_PPC_In_Gen_Sub_Decl -- + ----------------------------------------- + + -- Convert any PPC and pragmas that appear within a generic subprogram + -- declaration into aspect. + + procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is + Aspects : constant List_Id := New_List; + Loc : constant Source_Ptr := Sloc (Decl); + Or_Decl : constant Node_Id := Original_Node (Decl); + Aspect : Node_Id; + Original_Aspects : List_Id; + -- To capture global references, a copy of the created aspects must be + -- inserted in the original tree. + + Prag : Node_Id; + Prag_Arg_Ass : Node_Id; + Prag_Id : Pragma_Id; + + begin + Prag := Next (Decl); + + -- Check for any PPC pragmas that appear within Decl + + while Nkind (Prag) = N_Pragma loop + Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag))); + + case Prag_Id is + when Pragma_Postcondition | Pragma_Precondition => + Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag)); + + -- Make an aspect from any PPC pragma + + Aspect := + Make_Aspect_Specification (Loc, + Identifier => + Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))), + Expression => Expression (Prag_Arg_Ass)); + + Append (Aspect, Aspects); + + -- Set the pragma node analyzed to avoid any further analysis + + Set_Analyzed (Prag, True); + + when others => null; + end case; + + Next (Prag); + end loop; + + -- Set all new aspects into the generic declaration node + + if Is_Non_Empty_List (Aspects) then + -- Create the list of aspects which will be inserted in the original + -- tree. + + Original_Aspects := Copy_Separate_List (Aspects); + + -- Check if Decl already has aspects + -- Attach the new lists of aspects to both the generic copy and the + -- original tree. + + if Has_Aspects (Decl) then + Append_List (Aspects, Aspect_Specifications (Decl)); + Append_List (Original_Aspects, Aspect_Specifications (Or_Decl)); + else + Set_Parent (Aspects, Decl); + Set_Aspect_Specifications (Decl, Aspects); + Set_Parent (Original_Aspects, Or_Decl); + Set_Aspect_Specifications (Or_Decl, Original_Aspects); + end if; + end if; + end Make_Aspect_For_PPC_In_Gen_Sub_Decl; + ------------------------ -- Preanalyze_TC_Args -- ------------------------ Index: sem_prag.ads =================================================================== --- sem_prag.ads (revision 183406) +++ sem_prag.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- -- @@ -110,6 +110,13 @@ -- length, and then returns True. If it is not of the correct form, then an -- appropriate error message is posted, and False is returned. + procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id); + -- This routine makes aspects from precondition or postcondition pragmas + -- that appear within a generic subprogram declaration. Decl is the generic + -- subprogram declaration node. + -- Note that the aspects are attached to the generic copy and also to the + -- orginal tree. + procedure Process_Compilation_Unit_Pragmas (N : Node_Id); -- Called at the start of processing compilation unit N to deal with any -- special issues regarding pragmas. In particular, we have to deal with Index: sem_ch12.adb =================================================================== --- sem_ch12.adb (revision 183420) +++ sem_ch12.adb (working copy) @@ -59,6 +59,7 @@ with Sem_Elab; use Sem_Elab; with Sem_Elim; use Sem_Elim; with Sem_Eval; use Sem_Eval; +with Sem_Prag; use Sem_Prag; with Sem_Res; use Sem_Res; with Sem_Type; use Sem_Type; with Sem_Util; use Sem_Util; @@ -3082,6 +3083,15 @@ end; end if; + -- For ASIS purposes, convert any postcondition, precondition pragmas + -- into aspects, if N is not a compilation unit by itself, in order to + -- enable the analysis of expressions inside the corresponding PPC + -- pragmas. + + if ASIS_Mode and then Is_List_Member (N) then + Make_Aspect_For_PPC_In_Gen_Sub_Decl (N); + end if; + Spec := Specification (N); Id := Defining_Entity (Spec); Generate_Definition (Id); @@ -4662,7 +4672,8 @@ end if; Generate_Definition (Act_Decl_Id); - Set_Contract (Anon_Id, Make_Contract (Sloc (Anon_Id))); -- ??? needed? + -- Set_Contract (Anon_Id, Make_Contract (Sloc (Anon_Id))); + -- ??? needed? Set_Contract (Act_Decl_Id, Make_Contract (Sloc (Act_Decl_Id))); -- Inherit all inlining-related flags which apply to the generic in