From patchwork Fri Jul 5 09:23:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 257061 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id C9E4E2C0089 for ; Fri, 5 Jul 2013 19:23:23 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=GbRfEd3vn13YqOFRAQMofpBQwD5L6LtFJL/FToT47Eta4oyoA0GXb TlELlljy6mU0wTnY60wUQuWNatgvX9qH4a5D4QkGPpCqv4+IxSfpv0WJBfRtkwul Q/vxEOvNSh6ZX/jQk1d57OrseJtnNGXfK0DiwNGIm9x/hPhMds1Nl8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=ko5DqBMwt5K2o4icTLnzZuHzyZg=; b=xbZSuH86Uvy0bXgUtojj KiZKZvUZJkzKZ6msCNP+Afr4+59e9sXZVq5qk8NA1Tj+yo4I529OSwZe2AqwmrTv 4fpzaNbPBSmLqTh36q9FUgVt1qNSvtwB717jyPk2p94uXMizl6ISdaRNONTqt5OB hy0NhMnmGwRu9U072xF6IbE= Received: (qmail 22215 invoked by alias); 5 Jul 2013 09:23:16 -0000 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 Received: (qmail 22205 invoked by uid 89); 5 Jul 2013 09:23:15 -0000 X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL, BAYES_50, RCVD_IN_HOSTKARMA_NO autolearn=ham version=3.3.1 Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 05 Jul 2013 09:23:12 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 394A21C65C4 for ; Fri, 5 Jul 2013 05:23:11 -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 F8nK8CcIv0Xq for ; Fri, 5 Jul 2013 05:23:11 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 1E5F01C6591 for ; Fri, 5 Jul 2013 05:23:11 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 172A63FB31; Fri, 5 Jul 2013 05:23:11 -0400 (EDT) Date: Fri, 5 Jul 2013 05:23:11 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Subject: [Ada] Function calls in prefixed form in preconditions in generics Message-ID: <20130705092311.GA12937@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Found: No A construct of the form Obj.F (X => Expr) is parsed as a function call because of the parameter association, before the prefix is analyzed and the construct possibly rewritten as a call to F with controlling argument Obj. In a generic context, if such a call appears in a precondition, and given the delay in its elaboration, it may be copied before analysis. In that case, there is no entity attached to the prefix. The following must compile and execute quietly: gnatmake -q -gnat12a main main --- with Gen2; procedure Main is type Things is (This, That); package IP is new Gen2 (A => Things); begin null; end main; --- with Gen1; generic type A is(<>); package Gen2 is package P is new Gen1 (A => A); end Gen2; --- generic type A is(<>); package Gen1 is type T is abstract tagged private; function F(X:in out T'class; Y: Integer) return boolean; procedure Proc(X:in out T'class; Y:Integer) with pre=>X.F(Y=>1); private type T is abstract tagged record Z:A; end record; end Gen1; --- package body Gen1 is function F(X:in out T'class; Y: Integer) return boolean is begin return True; end; procedure Proc(X:in out T'class; Y:Integer) is begin null; end; end Gen1; Tested on x86_64-pc-linux-gnu, committed on trunk 2013-07-05 Ed Schonberg * sem_ch12.adb (Copy_Generic_Node): Check that name in function call is a valid entity name before preserving entity in generic copy. Index: sem_ch12.adb =================================================================== --- sem_ch12.adb (revision 200688) +++ sem_ch12.adb (working copy) @@ -6577,7 +6577,13 @@ Set_Entity (New_N, Entity (Assoc)); Check_Private_View (N); - elsif Nkind (Assoc) = N_Function_Call then + -- The name in the call may be a selected component if the + -- call has not been analyzed yet, as may be the case for + -- pre/post conditions in a generic unit. + + elsif Nkind (Assoc) = N_Function_Call + and then Is_Entity_Name (Name (Assoc)) + then Set_Entity (New_N, Entity (Name (Assoc))); elsif Nkind_In (Assoc, N_Defining_Identifier,