From patchwork Mon Oct 4 08:48:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1536022 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=e92vr4LS; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HNFQq3qXwz9t0k for ; Mon, 4 Oct 2021 20:14:26 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68B853858C3A for ; Mon, 4 Oct 2021 09:14:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68B853858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633338864; bh=l/teYR02+h591InnbOGEh7gVMex6Mla6FXd7tj99Zak=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=e92vr4LSJN8KqS7UusbMHdng+K9qikgGsrdaXLjfeTWxj2FUcDaPy1be+chWYDYlm GBl/4+33dbyY2DIzk9jIbh36LSOmi7XXBtGq8P2zs2K9XGymiPNJsZ2iX6iTk2jMt+ b3GUtC8y+mVLe7D3eUNf6yYpMsNcsjAetozUbrHw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id EAD68385843B for ; Mon, 4 Oct 2021 08:48:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EAD68385843B Received: by mail-lf1-x131.google.com with SMTP id y26so68701070lfa.11 for ; Mon, 04 Oct 2021 01:48:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=l/teYR02+h591InnbOGEh7gVMex6Mla6FXd7tj99Zak=; b=Zx9JM/u4wKtCah28ntn6WPvR/Q4a3dS4b295kaJbYBnsjIAIVNGcU4EpPfF5SnhUii PwzhxEM1rrqEuCM4oMlwUw9XkhGVqX3DiBkbaaFyhTaTYJH/P8ASc18kWohcHpKuTSnX mrSVh1LQZNniG8s+0R6EJdbVQkXMwZMJTIFauUxzWdaFECmaNrXyBguBb/GGzh5rzGnV zoNmJEZjDWyrTZk1CHwLKOcx8Nv8HIXRZdBXQObzC2puXALSgliJxDCWAwJ4xFXZIiTH ekcKjgooOY+0ZvlPmoMuZiGUq9jR9InlIWBGDs7iUuCugS60t7z7zduHCsVLvJbfWx2a D++w== X-Gm-Message-State: AOAM531pnC48nDSyK1b7DY2ytjcapS8eukMdRn7NV43fg7YpBMHFXKVK zKz2a+mdJlFLSp35KTEU/pI2wMNgMk4I0w== X-Google-Smtp-Source: ABdhPJxMBteNCraG0DY1UuNWloKnlnXslgtsXWfl7I8Hb1tCMB9oep4pbte4qFgLqHJHIkVkIMI0Kw== X-Received: by 2002:a05:651c:a10:: with SMTP id k16mr15078737ljq.308.1633337305824; Mon, 04 Oct 2021 01:48:25 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id d4sm1542879ljl.98.2021.10.04.01.48.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Oct 2021 01:48:25 -0700 (PDT) Date: Mon, 4 Oct 2021 08:48:24 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Handle properly user_defined literals given by operators. Message-ID: <20211004084824.GA1539708@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.1 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Ed Schonberg Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch expands the implementation of aspects Integer_Literal, Real_Literal and String_Literal, so that the value of the aspect, which must be a function name, can be specified by an Operator_Symbol. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch6.adb (Analyze_Operator_Symbol): Recognize strings as operator names when they are the value of one of the Ada2022 aspects for User_Defined_Literals. * sem_ch13.adb (Analyze_One_Aspect): Handle an aspect value given by an Operator_Name. (Validate_Literal_Aspect): Call Analyze_Operator_Symbol when needed. diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -2991,7 +2991,15 @@ package body Sem_Ch13 is -- Copy expression for later processing by the procedures -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations] - Set_Entity (Id, New_Copy_Tree (Expr)); + -- The expression may be a subprogram name, and can + -- be an operator name that appears as a string, but + -- requires its own analysis procedure (see sem_ch6). + + if Nkind (Expr) = N_Operator_Symbol then + Set_Entity (Id, Expr); + else + Set_Entity (Id, New_Copy_Tree (Expr)); + end if; -- Set Delay_Required as appropriate to aspect @@ -16668,7 +16676,15 @@ package body Sem_Ch13 is end if; if not Overloaded and then not Present (Entity (Func_Name)) then - Analyze (Func_Name); + -- The aspect is specified by a subprogram name, which + -- may be an operator name given originally by a string. + + if Is_Operator_Name (Chars (Func_Name)) then + Analyze_Operator_Symbol (Func_Name); + else + Analyze (Func_Name); + end if; + Overloaded := Is_Overloaded (Func_Name); end if; diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -2126,8 +2126,15 @@ package body Sem_Ch6 is and then Attribute_Name (Par) /= Name_Value) or else (Nkind (Maybe_Aspect_Spec) = N_Aspect_Specification and then Get_Aspect_Id (Maybe_Aspect_Spec) - -- include other aspects here ??? - in Aspect_Stable_Properties | Aspect_Aggregate) + + -- Include aspects that can be specified by a + -- subprogram name, which can be an operator. + + in Aspect_Stable_Properties + | Aspect_Integer_Literal + | Aspect_Real_Literal + | Aspect_String_Literal + | Aspect_Aggregate) then Find_Direct_Name (N);