| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- D I A G N O S T I C S . J S O N _ U T I L S -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- |
| 17 |
-- for more details. You should have received a copy of the GNU General -- |
| 18 |
-- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
| 19 |
-- http://www.gnu.org/licenses for a complete copy of the license. -- |
| 20 |
-- -- |
| 21 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 22 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 23 |
-- -- |
| 24 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
package Diagnostics.JSON_Utils is |
| 27 |
|
| 28 |
JSON_FORMATTING : constant Boolean := True; |
| 29 |
-- Adds newlines and indentation to the output JSON. |
| 30 |
-- |
| 31 |
-- NOTE: This flag could be associated with the gcc switch: |
| 32 |
-- '-fno-diagnostics-json-formatting' |
| 33 |
|
| 34 |
INDENT_SIZE : constant := 2; |
| 35 |
-- The number of spaces to indent each level of the JSON output. |
| 36 |
|
| 37 |
Indent_Level : Natural := 0; |
| 38 |
-- The current indentation level. |
| 39 |
|
| 40 |
procedure Begin_Block; |
| 41 |
-- Increase the indentation level by one |
| 42 |
|
| 43 |
procedure End_Block; |
| 44 |
-- Decrease the indentation level by one |
| 45 |
|
| 46 |
procedure Indent; |
| 47 |
-- Print the indentation for the line |
| 48 |
|
| 49 |
procedure NL_And_Indent; |
| 50 |
-- Print a new line |
| 51 |
|
| 52 |
procedure Write_Boolean_Attribute (Name : String; Value : Boolean); |
| 53 |
-- Write a JSON attribute with a boolean value. |
| 54 |
-- |
| 55 |
-- The value is either 'true' or 'false' without any quotes |
| 56 |
|
| 57 |
procedure Write_Int_Attribute (Name : String; Value : Int); |
| 58 |
|
| 59 |
procedure Write_JSON_Escaped_String (Str : String); |
| 60 |
-- Write each character of Str, taking care of preceding each quote and |
| 61 |
-- backslash with a backslash. Note that this escaping differs from what |
| 62 |
-- GCC does. |
| 63 |
-- |
| 64 |
-- Indeed, the JSON specification mandates encoding wide characters |
| 65 |
-- either as their direct UTF-8 representation or as their escaped |
| 66 |
-- UTF-16 surrogate pairs representation. GCC seems to prefer escaping - |
| 67 |
-- we choose to use the UTF-8 representation instead. |
| 68 |
|
| 69 |
procedure Write_String_Attribute (Name : String; Value : String); |
| 70 |
-- Write a JSON attribute with a string value. |
| 71 |
-- |
| 72 |
-- The Value is surrounded by double quotes ("") and the special characters |
| 73 |
-- within the string are escaped. |
| 74 |
|
| 75 |
end Diagnostics.JSON_Utils; |