From patchwork Fri Nov 13 13:14:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 544276 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2646A14142D for ; Sat, 14 Nov 2015 00:15:25 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Ogo/3p+J; dkim-atps=neutral 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:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=xbPDWXYuUJzqbmEVkyKUjnzzJKp9fZaaw4E1VjGLmG3dvb4pU0 KuAEJsKxOyKKxcBBwzAlLASkX00HGQQs1WwXClOj19tEzhVY0usCi04bEglhzhQw e5XosqlJYKapo0LDW9V5Sr/f8OdjpSAD/J1nL+XysPRg+bb5XRJyTBUvQ= 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:cc:subject:message-id:mime-version:content-type; s= default; bh=xgZy/ewxGQyUDYyctIoqYWC4JL4=; b=Ogo/3p+JrluKtw222r8B g/vB0PmKVOyo5I3f+hVpSCbjC2jUBjciKfiNRr3PhfuV5VCwnIDtanLid8vaJDJa ZbnPztice+iK0ghuIukFY/CJE1yomfbKkb6aJ+PUTSY8T8wntCkI2XLvcZ5P3WkU L/FHpMHu6fkyd7Pc1s+sy04= Received: (qmail 125281 invoked by alias); 13 Nov 2015 13:15:04 -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 125246 invoked by uid 89); 13 Nov 2015 13:15:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=AWL, BAYES_50, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 13 Nov 2015 13:15:00 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 75AC52957E; Fri, 13 Nov 2015 08:14:58 -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 uab71cA0rO8Z; Fri, 13 Nov 2015 08:14:58 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 65B292944B; Fri, 13 Nov 2015 08:14:58 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4192) id 626AF1A0; Fri, 13 Nov 2015 08:14:58 -0500 (EST) Date: Fri, 13 Nov 2015 08:14:58 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Handling of overloaded indexing functions Message-ID: <20151113131458.GA20127@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This patch completes the handling of generalized indexing in the presence of multiple indexing functions, when a derived type overrides inherited ones and defines new constant and variable indexing functions. Test in ACATS 4.0F C416A02 Tested on x86_64-pc-linux-gnu, committed on trunk 2015-11-13 Ed Schonberg * sem_ch4.adb (Indicate_Name_And_Type): If the analysis of one interpretation succeeds, set type of name in call, for completeness. (Try_Container_Indexing): If there are multiple indexing functions, collect possible interpretations that are compatible with given parameters, and add implicit dereference types when present. * sem_util.adb (Build_Explicit_Dereference): If the expression is an overloaded function call use the given discriminant to resolve the call, and set properly the type of the call and of the resulting dereference. Index: sem_util.adb =================================================================== --- sem_util.adb (revision 230305) +++ sem_util.adb (working copy) @@ -1732,6 +1732,8 @@ Disc : Entity_Id) is Loc : constant Source_Ptr := Sloc (Expr); + I : Interp_Index; + It : Interp; begin -- An entity of a type with a reference aspect is overloaded with @@ -1744,6 +1746,29 @@ Set_Etype (Expr, Etype (Entity (Expr))); elsif Nkind (Expr) = N_Function_Call then + + -- If the name of the indexing function is overloaded, locate the one + -- whose return type has an implicit dereference on the desired + -- discriminant, and set entity and type of function call. + + if Is_Overloaded (Name (Expr)) then + Get_First_Interp (Name (Expr), I, It); + + while Present (It.Nam) loop + if Ekind ((It.Typ)) = E_Record_Type + and then First_Entity ((It.Typ)) = Disc + then + Set_Entity (Name (Expr), It.Nam); + Set_Etype (Name (Expr), Etype (It.Nam)); + exit; + end if; + + Get_Next_Interp (I, It); + end loop; + end if; + + -- Set type of call from resolved function name. + Set_Etype (Expr, Etype (Name (Expr))); end if; Index: sem_ch4.adb =================================================================== --- sem_ch4.adb (revision 230314) +++ sem_ch4.adb (working copy) @@ -3073,6 +3073,7 @@ if not Is_Type (Nam) then if Is_Entity_Name (Name (N)) then Set_Entity (Name (N), Nam); + Set_Etype (Name (N), Etype (Nam)); elsif Nkind (Name (N)) = N_Selected_Component then Set_Entity (Selector_Name (Name (N)), Nam); @@ -7456,6 +7457,9 @@ end if; else + -- If there are multiple indexing functions, build a function call + -- and analyze it for each of the possible interpretations. + Indexing := Make_Function_Call (Loc, Name => @@ -7464,6 +7468,8 @@ Set_Parent (Indexing, Parent (N)); Set_Generalized_Indexing (N, Indexing); + Set_Etype (N, Any_Type); + Set_Etype (Name (Indexing), Any_Type); declare I : Interp_Index; @@ -7473,21 +7479,24 @@ begin Get_First_Interp (Func_Name, I, It); Set_Etype (Indexing, Any_Type); + while Present (It.Nam) loop Analyze_One_Call (Indexing, It.Nam, False, Success); if Success then - Set_Etype (Name (Indexing), It.Typ); - Set_Entity (Name (Indexing), It.Nam); - Set_Etype (N, Etype (Indexing)); - -- Add implicit dereference interpretation + -- Function in current interpretation is a valid candidate. + -- Its result type is also a potential type for the + -- original Indexed_Component node. + Add_One_Interp (Name (Indexing), It.Nam, It.Typ); + Add_One_Interp (N, It.Nam, It.Typ); + + -- Add implicit dereference interpretation to original node + if Has_Discriminants (Etype (It.Nam)) then Check_Implicit_Dereference (N, Etype (It.Nam)); end if; - - exit; end if; Get_Next_Interp (I, It);