From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 12:32:00 -0000 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-Type: multipart/mixed; boundary="YiEDa0DAkWCtVeE4" 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-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-08/txt/msg02538.txt.bz2 --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 2603 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. --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=difs Content-length: 878 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 --YiEDa0DAkWCtVeE4--