From patchwork Wed Aug 31 09:43:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 112491 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 81C8DB6F7F for ; Wed, 31 Aug 2011 19:43:26 +1000 (EST) Received: (qmail 7697 invoked by alias); 31 Aug 2011 09:43:23 -0000 Received: (qmail 7681 invoked by uid 22791); 31 Aug 2011 09:43:22 -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; Wed, 31 Aug 2011 09:43:07 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id DFD032BB271; Wed, 31 Aug 2011 05:43:06 -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 xyJdlliFGbaF; Wed, 31 Aug 2011 05:43:06 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id C2D2B2BB26E; Wed, 31 Aug 2011 05:43:06 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id C0A3D3FEE8; Wed, 31 Aug 2011 05:43:06 -0400 (EDT) Date: Wed, 31 Aug 2011 05:43:06 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Implementation of aspects within generic units Message-ID: <20110831094306.GA25125@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 If a declaration within a generic unit has aspects, the capture of references within the aspect expressions has to be done in a separate step because the aspect specificatios are not directly attached to the tree for the declaration. The following must compile quietly: gcc -c -gnat12 -gnata ml.ads with Ml_Type; with Generic_Matrix; package Ml is subtype T_Int32 is Ml_Type.T_Int32; subtype T_Float32 is Ml_Type.T_Float32; package M32 is new Generic_Matrix(G_Float => T_Float32); type T_Matrix32 is new M32.G_Matrix; subtype Range2 is T_Int32 range 0 .. 1; subtype Range3 is T_Int32 range 0 .. 2; end Ml; --- package Ml_Type is type T_Int32 is range (-2 ** 31) .. (2 ** 31 - 1); type T_Float32 is digits 6 range -3.40282E+38 .. 3.40282E+38; end Ml_Type; --- with Ml_Type; generic type G_Float is digits <>; package Generic_Matrix is type G_Matrix is array (Ml_Type.T_Int32 range <>, Ml_Type.T_Int32 range <>) of G_Float; function "+" (Left, Right : G_Matrix) return G_Matrix; function "-" (Left, Right : G_Matrix) return G_Matrix with Pre => (Left'Length (1) = Right'Length (1) and then Left'Length (2) = Right'Length (2) ); end Generic_Matrix; --- package body Generic_Matrix is function "+" (Left, Right : G_Matrix) return G_Matrix is Res : G_Matrix(Left'Range(1), Left'Range(2)); begin if Left'Length (1) /= Right'Length (1) or else Left'Length (2) /= Right'Length (2) then raise Constraint_Error with "matrices are of different dimension in elementwise operation"; end if; for I in Res'Range(1) loop for J in Res'Range(2) loop Res(I,J) := Left(I,J) + Right(I,J); end loop; end loop; return Res; end "+"; function "-" (Left, Right : G_Matrix) return G_Matrix is Res : G_Matrix(Left'Range(1), Left'Range(2)); begin for I in Res'Range(1) loop for J in Res'Range(2) loop Res(I,J) := Left(I,J) - Right(I,J); end loop; end loop; return Res; end "-"; end Generic_Matrix; Tested on x86_64-pc-linux-gnu, committed on trunk 2011-08-31 Ed Schonberg * sem_ch12.adb (Save_References): If the node has aspects, save references within the corresponding expressions in a separate step, because the aspects are not directly in the tree for the declaration to which they belong. Index: sem_ch12.adb =================================================================== --- sem_ch12.adb (revision 178372) +++ sem_ch12.adb (working copy) @@ -12737,6 +12737,23 @@ end if; end; end if; + + -- If a node has aspects, references within their expressions must + -- be saved separately, given that they are not directly in the + -- tree. + + if Has_Aspects (N) then + declare + Aspect : Node_Id; + + begin + Aspect := First (Aspect_Specifications (N)); + while Present (Aspect) loop + Save_Global_References (Expression (Aspect)); + Next (Aspect); + end loop; + end; + end if; end Save_References; -- Start of processing for Save_Global_References