From patchwork Mon May 9 09:30:28 2022 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: 1628464 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=nUJaWz29; 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kxbvx4wprz9sGJ for ; Mon, 9 May 2022 19:48:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 38ABB38485A1 for ; Mon, 9 May 2022 09:48:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38ABB38485A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652089707; bh=5gmHOiTt5G22SXR458pzxKvtgPl3sseBObatvUNaW7Q=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=nUJaWz29zTnF+k7bJm2SGqqu9GHYIRQ0ExvgQtHp1rU0Vk7X82jem/ks/xi/cAY8H Gsv3ql7RJeNagEsuZ9i+AsRzjFBXgn5ZlHjYUR6fOO6gnjEGOjZrcKYmdRfmK8XlWS ux7HJ2a2I2FhR2eVs1cr3KmfF3DdrXakinmV61ag= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 9C6873856264 for ; Mon, 9 May 2022 09:30:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9C6873856264 Received: by mail-wm1-x32c.google.com with SMTP id v64-20020a1cac43000000b0038cfd1b3a6dso10380152wme.5 for ; Mon, 09 May 2022 02:30:30 -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=5gmHOiTt5G22SXR458pzxKvtgPl3sseBObatvUNaW7Q=; b=2NXk5Ga1MGbbNcbqDWsC13GtrGvMUW/aI4eXuEetYe8pq/UlCiEpLDs/wuHDnUxgSL wCNMbVHmzI0CTR08OhOWY4p3qM7fTgolOV3bkNDentDtGZVlvNCv3c6qw66eNFrAFfzn 8gbCfrsfWexvhUl15ocndfkGRIUS6ci+sq/2m9BySULnB1VeVZxb8PMzznThp/aI2NSH 31Tvu9CbMaVe6Srd2Q2Nz4MyG2eTF3Nv18DLhpX0HQtBDDm5E9mkikFbf0ps12XL+74B Y7byEIb90h92dUxkmyj4/Tnortbwdo+GC1beKGpVD2UIytRpNZvr630Ve+nKVmNV4rFH gL8A== X-Gm-Message-State: AOAM532TznAJWFF+x35MRVckZO7lkexApo2z6qTM+AywTfBjFhvm+ia/ ATyG6M3pHrl/G34fthGztMWI4Ax4DGefBw== X-Google-Smtp-Source: ABdhPJxR9xqByV7Iiw98D2305knN1GRYKfSfJZPh41DOSlSeM3M/erWYd6xC+ScofXj5q60Odrjq0w== X-Received: by 2002:a05:600c:3ba5:b0:394:6a82:8dbe with SMTP id n37-20020a05600c3ba500b003946a828dbemr14378654wms.185.1652088629380; Mon, 09 May 2022 02:30:29 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id l15-20020a05600012cf00b0020c547f75easm10832086wrx.101.2022.05.09.02.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 02:30:28 -0700 (PDT) Date: Mon, 9 May 2022 09:30:28 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Improve error messages to include full package name Message-ID: <20220509093028.GA3184411@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: Justin Squirek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch improves error messages in the compiler so that missing 'with' error messages show the complete package name instead of a limited number of selectors. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * err_vars.ads: Add new error message names and nodes. * erroutc.adb (Set_Msg_Insertion_Name, Set_Msg_Insertion_Name_Literal): Likewise. * errout.adb (Set_Msg_Insertion_Node): Likewise. * errout.ads: Likewise. * exp_disp.adb (Check_Premature_Freezing): Modify setting of Error_Msg_Node_2 to occur directly before Error_Msg call where applicable. * sem_ch8.adb (Error_Missing_With_Of_Known_Unit): Added to handle the printing of full package names of known units. (Undefined, Find_Expanded_Name): Replace error printing with call to Error_Missing_With_Of_Known_Unit. diff --git a/gcc/ada/err_vars.ads b/gcc/ada/err_vars.ads --- a/gcc/ada/err_vars.ads +++ b/gcc/ada/err_vars.ads @@ -100,6 +100,11 @@ package Err_Vars is -- -- Some of these are initialized below, because they are read before being -- set by clients. + -- + -- Would it be desirable to use arrays (with element renamings) here + -- instead of individual variables, at least for the Error_Msg_Name_N and + -- Error_Msg_Node_N ??? This would allow simplifying existing code in some + -- cases (see errout.adb). Error_Msg_Col : Column_Number; -- Column for @ insertion character in message @@ -116,6 +121,9 @@ package Err_Vars is Error_Msg_Name_1 : Name_Id; Error_Msg_Name_2 : Name_Id := No_Name; Error_Msg_Name_3 : Name_Id := No_Name; + Error_Msg_Name_4 : Name_Id := No_Name; + Error_Msg_Name_5 : Name_Id := No_Name; + Error_Msg_Name_6 : Name_Id := No_Name; -- Name_Id values for % insertion characters in message Error_Msg_File_1 : File_Name_Type; @@ -129,6 +137,10 @@ package Err_Vars is Error_Msg_Node_1 : Node_Id; Error_Msg_Node_2 : Node_Id := Empty; + Error_Msg_Node_3 : Node_Id := Empty; + Error_Msg_Node_4 : Node_Id := Empty; + Error_Msg_Node_5 : Node_Id := Empty; + Error_Msg_Node_6 : Node_Id := Empty; -- Node_Id values for & insertion characters in message Error_Msg_Warn : Boolean; diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb --- a/gcc/ada/errout.adb +++ b/gcc/ada/errout.adb @@ -3578,10 +3578,14 @@ package body Errout is end if; end if; - -- The following assignment ensures that a second ampersand insertion - -- character will correspond to the Error_Msg_Node_2 parameter. + -- The following assignment ensures that further ampersand insertion + -- characters will correspond to the Error_Msg_Node_# parameter. Error_Msg_Node_1 := Error_Msg_Node_2; + Error_Msg_Node_2 := Error_Msg_Node_3; + Error_Msg_Node_3 := Error_Msg_Node_4; + Error_Msg_Node_4 := Error_Msg_Node_5; + Error_Msg_Node_5 := Error_Msg_Node_6; end Set_Msg_Insertion_Node; -------------------------------------- diff --git a/gcc/ada/errout.ads b/gcc/ada/errout.ads --- a/gcc/ada/errout.ads +++ b/gcc/ada/errout.ads @@ -468,6 +468,9 @@ package Errout is Error_Msg_Name_1 : Name_Id renames Err_Vars.Error_Msg_Name_1; Error_Msg_Name_2 : Name_Id renames Err_Vars.Error_Msg_Name_2; Error_Msg_Name_3 : Name_Id renames Err_Vars.Error_Msg_Name_3; + Error_Msg_Name_4 : Name_Id renames Err_Vars.Error_Msg_Name_4; + Error_Msg_Name_5 : Name_Id renames Err_Vars.Error_Msg_Name_5; + Error_Msg_Name_6 : Name_Id renames Err_Vars.Error_Msg_Name_6; -- Name_Id values for % insertion characters in message Error_Msg_File_1 : File_Name_Type renames Err_Vars.Error_Msg_File_1; @@ -481,6 +484,10 @@ package Errout is Error_Msg_Node_1 : Node_Id renames Err_Vars.Error_Msg_Node_1; Error_Msg_Node_2 : Node_Id renames Err_Vars.Error_Msg_Node_2; + Error_Msg_Node_3 : Node_Id renames Err_Vars.Error_Msg_Node_3; + Error_Msg_Node_4 : Node_Id renames Err_Vars.Error_Msg_Node_4; + Error_Msg_Node_5 : Node_Id renames Err_Vars.Error_Msg_Node_5; + Error_Msg_Node_6 : Node_Id renames Err_Vars.Error_Msg_Node_6; -- Node_Id values for & insertion characters in message Error_Msg_Qual_Level : Nat renames Err_Vars.Error_Msg_Qual_Level; diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb --- a/gcc/ada/erroutc.adb +++ b/gcc/ada/erroutc.adb @@ -1319,12 +1319,15 @@ package body Erroutc is end if; end if; - -- The following assignments ensure that the second and third percent - -- insertion characters will correspond to the Error_Msg_Name_2 and - -- Error_Msg_Name_3 as required. + -- The following assignments ensure that other percent insertion + -- characters will correspond to their appropriate Error_Msg_Name_# + -- values as required. Error_Msg_Name_1 := Error_Msg_Name_2; Error_Msg_Name_2 := Error_Msg_Name_3; + Error_Msg_Name_3 := Error_Msg_Name_4; + Error_Msg_Name_4 := Error_Msg_Name_5; + Error_Msg_Name_5 := Error_Msg_Name_6; end Set_Msg_Insertion_Name; ------------------------------------ @@ -1348,12 +1351,15 @@ package body Erroutc is Set_Msg_Quote; end if; - -- The following assignments ensure that the second and third % or %% - -- insertion characters will correspond to the Error_Msg_Name_2 and - -- Error_Msg_Name_3 values. + -- The following assignments ensure that other percent insertion + -- characters will correspond to their appropriate Error_Msg_Name_# + -- values as required. Error_Msg_Name_1 := Error_Msg_Name_2; Error_Msg_Name_2 := Error_Msg_Name_3; + Error_Msg_Name_3 := Error_Msg_Name_4; + Error_Msg_Name_4 := Error_Msg_Name_5; + Error_Msg_Name_5 := Error_Msg_Name_6; end Set_Msg_Insertion_Name_Literal; ------------------------------------- diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb --- a/gcc/ada/exp_disp.adb +++ b/gcc/ada/exp_disp.adb @@ -3817,11 +3817,11 @@ package body Exp_Disp is and then not Is_Actual_For_Formal_Incomplete_Type (Comp) then Error_Msg_Sloc := Sloc (Subp); - Error_Msg_Node_2 := Subp; - Error_Msg_Name_1 := Chars (Tagged_Type); Error_Msg_NE ("declaration must appear after completion of type &", N, Comp); + Error_Msg_Node_2 := Subp; + Error_Msg_Name_1 := Chars (Tagged_Type); Error_Msg_NE ("\which is a component of untagged type& in the profile " & "of primitive & of type % that is frozen by the " diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -474,6 +474,10 @@ package body Sem_Ch8 is -- scope: the defining entity for U, unless U is a package instance, in -- which case we retrieve the entity of the instance spec. + procedure Error_Missing_With_Of_Known_Unit (Pkg : Node_Id); + -- Display an error message denoting a "with" is missing for a given known + -- package Pkg with its full path name. + procedure Find_Expanded_Name (N : Node_Id); -- The input is a selected component known to be an expanded name. Verify -- legality of selector given the scope denoted by prefix, and change node @@ -5334,6 +5338,81 @@ package body Sem_Ch8 is end if; end Entity_Of_Unit; + -------------------------------------- + -- Error_Missing_With_Of_Known_Unit -- + -------------------------------------- + + procedure Error_Missing_With_Of_Known_Unit (Pkg : Node_Id) is + Selectors : array (1 .. 6) of Node_Id; + -- Contains the chars of the full package name up to maximum number + -- allowed as per Errout.Error_Msg_Name_# variables. + + Count : Integer := Selectors'First; + -- Count of selector names forming the full package name + + Current_Pkg : Node_Id := Parent (Pkg); + + begin + Selectors (Count) := Pkg; + + -- Gather all the selectors we can display + + while Nkind (Current_Pkg) = N_Selected_Component + and then Is_Known_Unit (Current_Pkg) + and then Count < Selectors'Length + loop + Count := Count + 1; + Selectors (Count) := Selector_Name (Current_Pkg); + Current_Pkg := Parent (Current_Pkg); + end loop; + + -- Display the error message based on the number of selectors found + + case Count is + when 1 => + Error_Msg_Node_1 := Selectors (1); + Error_Msg_N -- CODEFIX + ("\\missing `WITH &;`", Pkg); + when 2 => + Error_Msg_Node_1 := Selectors (1); + Error_Msg_Node_2 := Selectors (2); + Error_Msg_N -- CODEFIX + ("\\missing `WITH &.&;`", Pkg); + when 3 => + Error_Msg_Node_1 := Selectors (1); + Error_Msg_Node_2 := Selectors (2); + Error_Msg_Node_3 := Selectors (3); + Error_Msg_N -- CODEFIX + ("\\missing `WITH &.&.&;`", Pkg); + when 4 => + Error_Msg_Node_1 := Selectors (1); + Error_Msg_Node_2 := Selectors (2); + Error_Msg_Node_3 := Selectors (3); + Error_Msg_Node_3 := Selectors (4); + Error_Msg_N -- CODEFIX + ("\\missing `WITH &.&.&.&;`", Pkg); + when 5 => + Error_Msg_Node_1 := Selectors (1); + Error_Msg_Node_2 := Selectors (2); + Error_Msg_Node_3 := Selectors (3); + Error_Msg_Node_3 := Selectors (4); + Error_Msg_Node_3 := Selectors (5); + Error_Msg_N -- CODEFIX + ("\\missing `WITH &.&.&.&.&;`", Pkg); + when 6 => + Error_Msg_Node_1 := Selectors (1); + Error_Msg_Node_2 := Selectors (2); + Error_Msg_Node_3 := Selectors (3); + Error_Msg_Node_4 := Selectors (4); + Error_Msg_Node_5 := Selectors (5); + Error_Msg_Node_6 := Selectors (6); + Error_Msg_N -- CODEFIX + ("\\missing `WITH &.&.&.&.&.&;`", Pkg); + when others => + raise Program_Error; + end case; + end Error_Missing_With_Of_Known_Unit; + ---------------------- -- Find_Direct_Name -- ---------------------- @@ -5877,25 +5956,7 @@ package body Sem_Ch8 is and then N = Prefix (Parent (N)) and then Is_Known_Unit (Parent (N)) then - declare - P : Node_Id := Parent (N); - begin - Error_Msg_Name_1 := Chars (N); - Error_Msg_Name_2 := Chars (Selector_Name (P)); - - if Nkind (Parent (P)) = N_Selected_Component - and then Is_Known_Unit (Parent (P)) - then - P := Parent (P); - Error_Msg_Name_3 := Chars (Selector_Name (P)); - Error_Msg_N -- CODEFIX - ("\\missing `WITH %.%.%;`", N); - - else - Error_Msg_N -- CODEFIX - ("\\missing `WITH %.%;`", N); - end if; - end; + Error_Missing_With_Of_Known_Unit (N); end if; -- Now check for possible misspellings @@ -6910,9 +6971,7 @@ package body Sem_Ch8 is Standard_Standard) then if not Error_Posted (N) then - Error_Msg_Node_2 := Selector; - Error_Msg_N -- CODEFIX - ("missing `WITH &.&;`", Prefix (N)); + Error_Missing_With_Of_Known_Unit (Prefix (N)); end if; -- If this is a selection from a dummy package, then suppress