+2019-07-09 Eric Botcazou <ebotcazou@adacore.com>
+
+ * repinfo.ads (JSON format): Adjust.
+ * repinfo.adb (Need_Blank_Line): Rename to...
+ (Need_Separator): ...this.
+ (Blank_Line): Rename to...
+ (Write_Separator): ...this and add JSON specific handling.
+ (List_Array_Info): Adjust to above renaming.
+ (List_Object_Info): Likewise.
+ (List_Record_Info): Likewise.
+ (List_Subprogram_Info): Likewise.
+ (List_Type_Info): Likewise.
+ (List_Entities): Do not set Need_Blank_Line.
+ (List_Rep_Info): Set Need_Separator and add JSON specific
+ handling. Output a single JSON stream in the normal case.
+
2019-07-09 Arnaud Charlet <charlet@adacore.com>
* doc/gnat_ugn/the_gnat_compilation_model.rst: Update doc on
-- Identifier casing for current unit. This is set by List_Rep_Info for
-- each unit, before calling subprograms which may read it.
- Need_Blank_Line : Boolean;
- -- Set True if a blank line is needed before outputting any information for
- -- the current entity. Set True when a new entity is processed, and false
- -- when the blank line is output.
+ Need_Separator : Boolean;
+ -- Set True if a separator is needed before outputting any information for
+ -- the current entity.
------------------------------
-- Set of Relevant Entities --
-- is used rather than checking the configuration parameter because we do
-- not want Repinfo to depend on Targparm (for ASIS)
- procedure Blank_Line;
- -- Called before outputting anything for an entity. Ensures that
- -- a blank line precedes the output for a particular entity.
-
procedure List_Entities
(Ent : Entity_Id;
Bytes_Big_Endian : Boolean;
procedure Write_Mechanism (M : Mechanism_Type);
-- Writes symbolic string for mechanism represented by M
+ procedure Write_Separator;
+ -- Called before outputting anything for an entity. Ensures that
+ -- a separator precedes the output for a particular entity.
+
procedure Write_Unknown_Val;
-- Writes symbolic string for an unknown or non-representable value
return Rep_Table.Last > 0;
end Back_End_Layout;
- ----------------
- -- Blank_Line --
- ----------------
-
- procedure Blank_Line is
- begin
- if Need_Blank_Line then
- Write_Eol;
- Need_Blank_Line := False;
- end if;
- end Blank_Line;
-
------------------------
-- Create_Discrim_Ref --
------------------------
procedure List_Array_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is
begin
- Blank_Line;
+ Write_Separator;
if List_Representation_Info_To_JSON then
Write_Line ("{");
or else Ekind (Ent) = E_Entry_Family)
and then not In_Subprogram
then
- Need_Blank_Line := True;
List_Subprogram_Info (Ent);
end if;
E := First_Entity (Ent);
while Present (E) loop
- Need_Blank_Line := True;
-
-- We list entities that come from source (excluding private or
-- incomplete types or deferred constants, for which we will list
-- the information for the full view). If requested, we also list
procedure List_Object_Info (Ent : Entity_Id) is
begin
- Blank_Line;
+ Write_Separator;
if List_Representation_Info_To_JSON then
Write_Line ("{");
-- Start of processing for List_Record_Info
begin
- Blank_Line;
+ Write_Separator;
if List_Representation_Info_To_JSON then
Write_Line ("{");
if List_Representation_Info /= 0
or else List_Representation_Info_Mechanisms
then
+ -- For the normal case, we output a single JSON stream
+
+ if not List_Representation_Info_To_File
+ and then List_Representation_Info_To_JSON
+ then
+ Write_Line ("[");
+ Need_Separator := False;
+ end if;
+
for U in Main_Unit .. Last_Unit loop
if In_Extended_Main_Source_Unit (Cunit_Entity (U)) then
Unit_Casing := Identifier_Casing (Source_Index (U));
end loop;
Write_Eol;
+ Need_Separator := True;
end if;
List_Entities (Cunit_Entity (U), Bytes_Big_Endian);
Create_Repinfo_File_Access.all
(Get_Name_String (File_Name (Source_Index (U))));
Set_Special_Output (Write_Info_Line'Access);
+ if List_Representation_Info_To_JSON then
+ Write_Line ("[");
+ end if;
+ Need_Separator := False;
List_Entities (Cunit_Entity (U), Bytes_Big_Endian);
+ if List_Representation_Info_To_JSON then
+ Write_Line ("]");
+ end if;
Cancel_Special_Output;
Close_Repinfo_File_Access.all;
end if;
end if;
end loop;
+
+ if not List_Representation_Info_To_File
+ and then List_Representation_Info_To_JSON
+ then
+ Write_Line ("]");
+ end if;
end if;
end List_Rep_Info;
Form : Entity_Id;
begin
- Blank_Line;
+ Write_Separator;
if List_Representation_Info_To_JSON then
Write_Line ("{");
procedure List_Type_Info (Ent : Entity_Id) is
begin
- Blank_Line;
+ Write_Separator;
if List_Representation_Info_To_JSON then
Write_Line ("{");
end case;
end Write_Mechanism;
+ ---------------------
+ -- Write_Separator --
+ ---------------------
+
+ procedure Write_Separator is
+ begin
+ if Need_Separator then
+ if List_Representation_Info_To_JSON then
+ Write_Line (",");
+ else
+ Write_Eol;
+ end if;
+ else
+ Need_Separator := True;
+ end if;
+ end Write_Separator;
+
-----------------------
-- Write_Unknown_Val --
-----------------------