public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2012] [Ada] Print JSON continuation messages as separate messages
@ 2021-07-05 13:13 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-07-05 13:13 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:243573ff080ed436d8cd9a3273e509ee436434d9

commit r12-2012-g243573ff080ed436d8cd9a3273e509ee436434d9
Author: Ghjuvan Lacambre <lacambre@adacore.com>
Date:   Fri Apr 23 16:02:19 2021 +0200

    [Ada] Print JSON continuation messages as separate messages
    
    gcc/ada/
    
            * errout.adb (Output_JSON_Message): Recursively call
            Output_JSON_Message for continuation messages instead of
            appending their content to the initial message.

Diff:
---
 gcc/ada/errout.adb | 39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index 8fd20760c34..0122304da6f 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -2079,6 +2079,9 @@ package body Errout is
 
    procedure Output_JSON_Message (Error_Id : Error_Msg_Id) is
 
+      function Is_Continuation (E : Error_Msg_Id) return Boolean;
+      --  Return True if E is a continuation message.
+
       procedure Write_JSON_Escaped_String (Str : String_Ptr);
       --  Write each character of Str, taking care of preceding each quote and
       --  backslash with a backslash. Note that this escaping differs from what
@@ -2099,6 +2102,15 @@ package body Errout is
       --  Span.Last are different from Span.Ptr, they will be printed as JSON
       --  locations under the names "start" and "finish".
 
+      -----------------------
+      --  Is_Continuation  --
+      -----------------------
+
+      function Is_Continuation (E : Error_Msg_Id) return Boolean is
+      begin
+         return E <= Last_Error_Msg and then Errors.Table (E).Msg_Cont;
+      end Is_Continuation;
+
       -------------------------------
       -- Write_JSON_Escaped_String --
       -------------------------------
@@ -2155,6 +2167,10 @@ package body Errout is
 
       E : Error_Msg_Id := Error_Id;
 
+      Print_Continuations : constant Boolean := not Is_Continuation (E);
+      --  Do not print continuations messages as children of the current
+      --  message if the current message is a continuation message.
+
    --  Start of processing for Output_JSON_Message
 
    begin
@@ -2186,18 +2202,27 @@ package body Errout is
 
       Write_Str ("],""message"":""");
       Write_JSON_Escaped_String (Errors.Table (E).Text);
-
-      --  Print message continuations if present
+      Write_Str ("""");
 
       E := E + 1;
 
-      while E <= Last_Error_Msg and then Errors.Table (E).Msg_Cont loop
-         Write_Str (", ");
-         Write_JSON_Escaped_String (Errors.Table (E).Text);
+      if Print_Continuations and then Is_Continuation (E) then
+
+         Write_Str (",""children"": [");
+         Output_JSON_Message (E);
          E := E + 1;
-      end loop;
 
-      Write_Str ("""}");
+         while Is_Continuation (E) loop
+            Write_Str (", ");
+            Output_JSON_Message (E);
+            E := E + 1;
+         end loop;
+
+         Write_Str ("]");
+
+      end if;
+
+      Write_Str ("}");
    end Output_JSON_Message;
 
    ---------------------


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-05 13:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-05 13:13 [gcc r12-2012] [Ada] Print JSON continuation messages as separate messages Pierre-Marie de Rodat

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).