From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id 23AC53954C76 for ; Thu, 2 Jun 2022 09:09:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 23AC53954C76 Received: by mail-ed1-x531.google.com with SMTP id fd25so5431575edb.3 for ; Thu, 02 Jun 2022 02:09:06 -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=iRCOle7TqZQm27ToXPblaU49ymMF15gU5qFK/aEH/pk=; b=779CS3U+6YcJE/Sc25masEM+P2pMISXdJsA6rEkPoCNVaBT4WkLiRZJdmT2zTXVQvW S/lI+bWI1znvEx5LHXtDZktuQE5Jziq5tpCkwOf4mRFcLBkaQhtsdx6e+65+4HGrvro2 k/25DMoUFFAXwFjpovuEYw4EEn/dEoZDHc4bC8yVIx32Wljn0qJeQqa+xdUqEf0E/DWk WP7EjYtx5riOqHNmPWbqcYkEwbrPt1+JeJlxFrp9pqOyvkqGNKRplVu72YbCaLFD8+Ti 6s9fSACKJYFeWZHZ/de9jY33xJDt0bpNJE5jkinwOkv0D4chnYAAHN1/d3zfvBkF00sn AWzg== X-Gm-Message-State: AOAM5338mknYihNcJDgeagEtcfX03d+H8xe16+f2lAK/kVeyEJOvrCjo 6UbyUfNOYRoo6U+XnMW7dkEc+YlPqJNGZQ== X-Google-Smtp-Source: ABdhPJwKVlQ6De8pDjtBM1Se10Dl+uqI4MDO86FluVQEhI090xSvUqNPdrgeIbZDgEEcijFyGX5COA== X-Received: by 2002:a05:6402:4311:b0:42b:5f80:4526 with SMTP id m17-20020a056402431100b0042b5f804526mr4193572edc.126.1654160944892; Thu, 02 Jun 2022 02:09:04 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id cz20-20020a0564021cb400b0042dd85bd23bsm2137077edb.55.2022.06.02.02.09.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 02:09:04 -0700 (PDT) Date: Thu, 2 Jun 2022 09:09:03 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Ghjuvan Lacambre Subject: [Ada] Add precise subprogram identification to -fdiagnostics-format=json Message-ID: <20220602090903.GA1010812@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="vkogqOf2sHV7VnPd" Content-Disposition: inline X-Spam-Status: No, score=-13.2 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, T_SCC_BODY_TEXT_LINE, WEIRD_QUOTING 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-List-Received-Date: Thu, 02 Jun 2022 09:09:07 -0000 --vkogqOf2sHV7VnPd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This commit adds information allowing identification of the subprogram surrounding the message emitted by gnat when using -gnatdJ along with -fdiagnostics-format=json. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * errout.adb (Write_JSON_Span): Add subprogram name to emitted JSON. --vkogqOf2sHV7VnPd Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb --- a/gcc/ada/errout.adb +++ b/gcc/ada/errout.adb @@ -2097,11 +2097,14 @@ package body Errout is -- Write Sptr as a JSON location, an object containing a file attribute, -- a line number and a column number. - procedure Write_JSON_Span (Span : Source_Span); - -- Write Span as a JSON span, an object containing a "caret" attribute - -- whose value is the JSON location of Span.Ptr. If Span.First and - -- Span.Last are different from Span.Ptr, they will be printed as JSON + procedure Write_JSON_Span (Error : Error_Msg_Object); + -- Write Error as a JSON span, an object containing a "caret" attribute + -- whose value is the JSON location of Error.Sptr.Ptr. If Sptr.First and + -- Sptr.Last are different from Sptr.Ptr, they will be printed as JSON -- locations under the names "start" and "finish". + -- When Include_Subprogram_In_Messages is true (-gnatdJ) an additional, + -- non-standard, attribute named "subprogram" will be added, allowing + -- precisely identifying the subprogram surrounding the span. ----------------------- -- Is_Continuation -- @@ -2162,7 +2165,8 @@ package body Errout is -- Write_JSON_Span -- --------------------- - procedure Write_JSON_Span (Span : Source_Span) is + procedure Write_JSON_Span (Error : Error_Msg_Object) is + Span : constant Source_Span := Error.Sptr; begin Write_Str ("{""caret"":"); Write_JSON_Location (Span.Ptr); @@ -2177,6 +2181,11 @@ package body Errout is Write_JSON_Location (Span.Last); end if; + if Include_Subprogram_In_Messages then + Write_Str + (",""subprogram"":""" & Subprogram_Name_Ptr (Error.Node) & """"); + end if; + Write_Str ("}"); end Write_JSON_Span; @@ -2210,7 +2219,7 @@ package body Errout is -- Print message location Write_Str (",""locations"":["); - Write_JSON_Span (Errors.Table (E).Sptr); + Write_JSON_Span (Errors.Table (E)); if Errors.Table (E).Optr /= Errors.Table (E).Sptr.Ptr then Write_Str (",{""caret"":"); --vkogqOf2sHV7VnPd--