]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix printing boolean attributes in the SARIF report
authorViljar Indus <indus@adacore.com>
Tue, 26 Nov 2024 12:10:46 +0000 (14:10 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 6 Jan 2025 09:14:47 +0000 (10:14 +0100)
Boolean attributes should have the value true or false
without any quotes.

gcc/ada/ChangeLog:

* diagnostics-json_utils.adb: Add new method
Write_Boolean_Attribute.
* diagnostics-json_utils.ads: Likewise.
* diagnostics-sarif_emitter.adb (Print_Invocations): print
the executionSuccesful property value without extra quotes.

gcc/ada/diagnostics-json_utils.adb
gcc/ada/diagnostics-json_utils.ads
gcc/ada/diagnostics-sarif_emitter.adb

index 30263b0b3ca6ba8bf9b332c0cf972a1654d7f6c1..a05a097012c4ed6cd9d1338cefcba9a7d78f8f1b 100644 (file)
@@ -64,6 +64,17 @@ package body Diagnostics.JSON_Utils is
       end if;
    end NL_And_Indent;
 
+   -----------------------------
+   -- Write_Boolean_Attribute --
+   -----------------------------
+
+   procedure Write_Boolean_Attribute (Name : String; Value : Boolean) is
+
+   begin
+      Write_Str ("""" & Name & """" & ": ");
+      Write_Str (if Value then "true" else "false");
+   end Write_Boolean_Attribute;
+
    -------------------------
    -- Write_Int_Attribute --
    -------------------------
index 1fc6c0e315d6e5caeeff5ab3e3b98da8f73dc685..f496b7acbb81047f1483f0eed1be94ab3d54ef91 100644 (file)
@@ -49,6 +49,11 @@ package Diagnostics.JSON_Utils is
    procedure NL_And_Indent;
    --  Print a new line
 
+   procedure Write_Boolean_Attribute (Name : String; Value : Boolean);
+   --  Write a JSON attribute with a boolean value.
+   --
+   --  The value is either 'true' or 'false' without any quotes
+
    procedure Write_Int_Attribute (Name : String; Value : Int);
 
    procedure Write_JSON_Escaped_String (Str : String);
@@ -62,6 +67,9 @@ package Diagnostics.JSON_Utils is
    --  we choose to use the UTF-8 representation instead.
 
    procedure Write_String_Attribute (Name : String; Value : String);
-   --  Write a JSON attribute with a string value
+   --  Write a JSON attribute with a string value.
+   --
+   --  The Value is surrounded by double quotes ("") and the special characters
+   --  within the string are escaped.
 
 end Diagnostics.JSON_Utils;
index f0be97d1a1ea7c0953ed775dc93b6bc804896306..bdab412befd827cabac606e676fbd2cefbe48429 100644 (file)
@@ -632,9 +632,7 @@ package body Diagnostics.SARIF_Emitter is
 
       --  Print executionSuccessful
 
-      Write_String_Attribute
-        ("executionSuccessful",
-         (if Compilation_Errors then "false" else "true"));
+      Write_Boolean_Attribute ("executionSuccessful", Compilation_Errors);
 
       End_Block;
       NL_And_Indent;