From patchwork Tue Nov 8 08:42:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 16945 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2572320wru; Tue, 8 Nov 2022 00:51:54 -0800 (PST) X-Google-Smtp-Source: AMsMyM6DhrABkFIKflhUYwsbkOJ+wA2LOltY6BPQMQHEd3BJs8A01khIsKbdDTJMNo5xFV85VcaE X-Received: by 2002:a17:907:ea7:b0:7ad:c3b7:ca52 with SMTP id ho39-20020a1709070ea700b007adc3b7ca52mr47130081ejc.626.1667897514087; Tue, 08 Nov 2022 00:51:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667897514; cv=none; d=google.com; s=arc-20160816; b=yML/jWo4HiC+j5rz3eDvMq458XLPQt+DBJ+H+aC53L+ze3D2CjFwyDAYcZ7zbGVJiP wrbeFF+l06v6c5j3ez9jiwv1HW33WH/yUiCEozVU8gpquIR5+y67PCR8VcG2u0jZLeja +lob+IUIfrrLE/2jzZqNbk8jF5PiFE6yNYummJJIZNlFAHXrhIXCQSWjCUx4ZKMhkCZi 7fxqFsvdL6KcFQpPB2oECsINuZSYMiMOHswmj9RPn7FUug1zm1VL412HiFsqgc3MD9Dr fNzMHMfI+0gNJo8wpLmyz3K2poySE9PaeWEqKbEc9eCo3UaGy/Ec6Rf1b695YzhygIXb EaSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=i8HretHSoPqggVhhHgHqAQmxxD2TyrbwoNr+ASDRjak=; b=Yg2D2DjpIlVWpNAfhO7UwKQ8kIGooc5rqXngSGc2tG6MH19C782PJ4X73si8AnLzpg v8nrzgSeyLwm0jC3HeEH7Gy3tWe5SUW5Tp6hYSKVQ1mrDlr90Nu1xSUI2SrTyy4hM4yS 2Lse20nWMuLKeq9yQ2xRlogKvz3YHWaP2WuK8z5F69aUVDGIB0NGK+n+mMRFQFkYOpOT oPKFueUHAeitF4SqdihDZAXR5eA+f9rCLJYyLFO+j0laIh0aII3PZGIa5JuuhfZrFJ9r LYuyti10BbfdCdZI8VWvuntTOxe/FqQ3KbPdVVyoWhDXtgJ2gmj3oFyBZ/lHjlUr7YsQ TH4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vRpu9Ky5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gt16-20020a1709072d9000b0078e1d1d6005si13011103ejc.23.2022.11.08.00.51.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 00:51:54 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vRpu9Ky5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6BB82385414C for ; Tue, 8 Nov 2022 08:49:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6BB82385414C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667897373; bh=i8HretHSoPqggVhhHgHqAQmxxD2TyrbwoNr+ASDRjak=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=vRpu9Ky5kRVZUDnXi0zgVFZSsCZUBwmpOpR5Ysgl2Mzgg3o9ULG44t9rmFHz91kVS j8THOZF8ujiGiIPck6SaBiUZGbsB48Xz6CVINWa3r4pgZv6wix5AygtziB6n2stD4t yps410t4M2/QuBItGOolB1u1rYiV8GbQp/YianC8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 210A33857837 for ; Tue, 8 Nov 2022 08:42:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 210A33857837 Received: by mail-wr1-x433.google.com with SMTP id l14so19821178wrw.2 for ; Tue, 08 Nov 2022 00:42:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=i8HretHSoPqggVhhHgHqAQmxxD2TyrbwoNr+ASDRjak=; b=gnJCN9XeOERaaRhxpiBbLrgTqWiP4hSRGsWu0aDCobx33Az+lLl5N3/Q8Sl6PpJ7bs j8dbtqcetkZS909+TeYV8sdV+w89fURCl2ooyAzc6gna4l4zaGypVX1XWNywpcsfSghl g1+nxfBLXSeW9HMQcmYPb/c0tCxI+xaMQaET/RaHQ4iDX8rw7eLttLvBwcroNQ/zClIK 6m+lEP8Te2ko870xTXue3QO50S2D59KsMJsKVzNe8eweqysJuMot7olP26A4Q7vkF8Ae vf3r+L0qKWKxAabR70+OyhWEyh4f8Vdnsn1H0kuFuP+3mBBZhRWVx1N0TU+WWJfiUkoI p3rA== X-Gm-Message-State: ACrzQf2D0T2ED0WQTzg4imlVR98a4Foz102Rt6RUIVcdgZ5M3iASgmna ClmRtkgvKWjK9B1Bnhukn3hGh+yTux5u7w== X-Received: by 2002:a05:6000:15cd:b0:236:9701:7bad with SMTP id y13-20020a05600015cd00b0023697017badmr33954484wry.679.1667896945885; Tue, 08 Nov 2022 00:42:25 -0800 (PST) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id bu24-20020a056000079800b00228a6ce17b4sm9807786wrb.37.2022.11.08.00.42.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 00:42:25 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Fix expansion of 'Wide_Image and 'Wide_Wide_Image on composite types Date: Tue, 8 Nov 2022 09:42:22 +0100 Message-Id: <20221108084222.301318-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748917304053207025?= X-GMAIL-MSGID: =?utf-8?q?1748917304053207025?= From: Piotr Trojanek Attributes Wide_Image and Wide_Wide_Image applied to composite types are now expanded just like attribute Image. gcc/ada/ * exp_imgv.adb (Expand_Wide_Image_Attribute): Handle just like attribute Image. (Expand_Wide_Wide_Image_Attribute): Likewise. * exp_put_image.adb (Build_Image_Call): Adapt to also work for Wide and Wide_Wide attributes. * exp_put_image.ads (Build_Image_Call): Update comment. * rtsfind.ads (RE_Id): Support wide variants of Get. (RE_Unit_Table): Likewise. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_imgv.adb | 19 +++++++++++++++++++ gcc/ada/exp_put_image.adb | 29 +++++++++++++++++++++++++---- gcc/ada/exp_put_image.ads | 6 +++--- gcc/ada/rtsfind.ads | 4 ++++ 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb index f2043f525d5..398e4771c14 100644 --- a/gcc/ada/exp_imgv.adb +++ b/gcc/ada/exp_imgv.adb @@ -1842,6 +1842,15 @@ package body Exp_Imgv is return; end if; + -- If Image should be transformed using Put_Image, then do so. See + -- Exp_Put_Image for details. + + if Exp_Put_Image.Image_Should_Call_Put_Image (N) then + Rewrite (N, Exp_Put_Image.Build_Image_Call (N)); + Analyze_And_Resolve (N, Standard_Wide_String, Suppress => All_Checks); + return; + end if; + Rtyp := Root_Type (Entity (Pref)); Insert_Actions (N, New_List ( @@ -1942,6 +1951,16 @@ package body Exp_Imgv is return; end if; + -- If Image should be transformed using Put_Image, then do so. See + -- Exp_Put_Image for details. + + if Exp_Put_Image.Image_Should_Call_Put_Image (N) then + Rewrite (N, Exp_Put_Image.Build_Image_Call (N)); + Analyze_And_Resolve + (N, Standard_Wide_Wide_String, Suppress => All_Checks); + return; + end if; + Rtyp := Root_Type (Entity (Pref)); Insert_Actions (N, New_List ( diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb index c489ad41fd1..f90f0206f27 100644 --- a/gcc/ada/exp_put_image.adb +++ b/gcc/ada/exp_put_image.adb @@ -1058,12 +1058,14 @@ package body Exp_Put_Image is ---------------------- function Build_Image_Call (N : Node_Id) return Node_Id is - -- For T'Image (X) Generate an Expression_With_Actions node: + -- For T'[[Wide_]Wide_]Image (X) Generate an Expression_With_Actions + -- node: -- -- do -- S : Buffer; -- U_Type'Put_Image (S, X); - -- Result : constant String := Get (S); + -- Result : constant [[Wide_]Wide_]String := + -- [[Wide_[Wide_]]Get (S); -- Destroy (S); -- in Result end -- @@ -1091,14 +1093,33 @@ package body Exp_Put_Image is Image_Prefix)); Result_Entity : constant Entity_Id := Make_Temporary (Loc, 'R'); + + subtype Image_Name_Id is Name_Id with Static_Predicate => + Image_Name_Id in Name_Image | Name_Wide_Image | Name_Wide_Wide_Image; + -- Attribute names that will be mapped to the corresponding result types + -- and functions. + + Attribute_Name_Id : constant Name_Id := Attribute_Name (N); + + Result_Typ : constant Entity_Id := + (case Image_Name_Id'(Attribute_Name_Id) is + when Name_Image => Stand.Standard_String, + when Name_Wide_Image => Stand.Standard_Wide_String, + when Name_Wide_Wide_Image => Stand.Standard_Wide_Wide_String); + Get_Func_Id : constant RE_Id := + (case Image_Name_Id'(Attribute_Name_Id) is + when Name_Image => RE_Get, + when Name_Wide_Image => RE_Wide_Get, + when Name_Wide_Wide_Image => RE_Wide_Wide_Get); + Result_Decl : constant Node_Id := Make_Object_Declaration (Loc, Defining_Identifier => Result_Entity, Object_Definition => - New_Occurrence_Of (Stand.Standard_String, Loc), + New_Occurrence_Of (Result_Typ, Loc), Expression => Make_Function_Call (Loc, - Name => New_Occurrence_Of (RTE (RE_Get), Loc), + Name => New_Occurrence_Of (RTE (Get_Func_Id), Loc), Parameter_Associations => New_List ( New_Occurrence_Of (Sink_Entity, Loc)))); Actions : List_Id; diff --git a/gcc/ada/exp_put_image.ads b/gcc/ada/exp_put_image.ads index b2b65aa2374..d4055d10b96 100644 --- a/gcc/ada/exp_put_image.ads +++ b/gcc/ada/exp_put_image.ads @@ -91,9 +91,9 @@ package Exp_Put_Image is -- T'Image. function Build_Image_Call (N : Node_Id) return Node_Id; - -- N is a call to T'Image, and this translates it into the appropriate code - -- to call T'Put_Image into a buffer and then extract the string from the - -- buffer. + -- N is a call to T'[[Wide_]Wide_]Image, and this translates it into the + -- appropriate code to call T'Put_Image into a buffer and then extract the + -- [[wide] wide] string from the buffer. procedure Preload_Root_Buffer_Type (Compilation_Unit : Node_Id); -- Call RTE (RE_Root_Buffer_Type) if necessary, to load the packages diff --git a/gcc/ada/rtsfind.ads b/gcc/ada/rtsfind.ads index 24aca2cf6b6..ce49e2df149 100644 --- a/gcc/ada/rtsfind.ads +++ b/gcc/ada/rtsfind.ads @@ -609,6 +609,8 @@ package Rtsfind is RE_Buffer_Type, -- Ada.Strings.Text_Buffers.Unbounded RE_Get, -- Ada.Strings.Text_Buffers.Unbounded + RE_Wide_Get, -- Ada.Strings.Text_Buffers.Unbounded + RE_Wide_Wide_Get, -- Ada.Strings.Text_Buffers.Unbounded RE_Wait_For_Release, -- Ada.Synchronous_Barriers @@ -2245,6 +2247,8 @@ package Rtsfind is RE_Buffer_Type => Ada_Strings_Text_Buffers_Unbounded, RE_Get => Ada_Strings_Text_Buffers_Unbounded, + RE_Wide_Get => Ada_Strings_Text_Buffers_Unbounded, + RE_Wide_Wide_Get => Ada_Strings_Text_Buffers_Unbounded, RE_Wait_For_Release => Ada_Synchronous_Barriers,