From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Ghjuvan Lacambre <lacambre@adacore.com>
Subject: [Ada] Add precise subprogram identification to -fdiagnostics-format=json
Date: Thu, 2 Jun 2022 09:09:03 +0000 [thread overview]
Message-ID: <20220602090903.GA1010812@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 300 bytes --]
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.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2250 bytes --]
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"":");
reply other threads:[~2022-06-02 9:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220602090903.GA1010812@adacore.com \
--to=derodat@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=lacambre@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).