1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2023, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Casing
; use Casing
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Einfo
.Entities
; use Einfo
.Entities
;
32 with Einfo
.Utils
; use Einfo
.Utils
;
34 with Namet
; use Namet
;
35 with Nlists
; use Nlists
;
37 with Output
; use Output
;
38 with Osint
.C
; use Osint
.C
;
39 with Sem_Aux
; use Sem_Aux
;
40 with Sem_Eval
; use Sem_Eval
;
42 with Sinfo
; use Sinfo
;
43 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
44 with Sinfo
.Utils
; use Sinfo
.Utils
;
45 with Sinput
; use Sinput
;
46 with Snames
; use Snames
;
47 with Stand
; use Stand
;
48 with Stringt
; use Stringt
;
51 with Uname
; use Uname
;
52 with Urealp
; use Urealp
;
54 with Ada
.Unchecked_Conversion
;
58 package body Repinfo
is
60 SSU
: Pos
renames Ttypes
.System_Storage_Unit
;
61 -- Value for Storage_Unit
63 ---------------------------------------
64 -- Representation of GCC Expressions --
65 ---------------------------------------
67 -- A table internal to this unit is used to hold the values of back
68 -- annotated expressions.
70 -- Node values are stored as Uint values using the negative of the node
71 -- index in this table. Constants appear as non-negative Uint values.
73 type Exp_Node
is record
75 Op1
: Node_Ref_Or_Val
;
76 Op2
: Node_Ref_Or_Val
;
77 Op3
: Node_Ref_Or_Val
;
80 -- The following representation clause ensures that the above record
81 -- has no holes. We do this so that when instances of this record are
82 -- written, we do not write uninitialized values to the file.
84 for Exp_Node
use record
85 Expr
at 0 range 0 .. 31;
86 Op1
at 4 range 0 .. 31;
87 Op2
at 8 range 0 .. 31;
88 Op3
at 12 range 0 .. 31;
91 for Exp_Node
'Size use 16 * 8;
92 -- This ensures that we did not leave out any fields
94 package Rep_Table
is new Table
.Table
(
95 Table_Component_Type
=> Exp_Node
,
96 Table_Index_Type
=> Nat
,
98 Table_Initial
=> Alloc
.Rep_Table_Initial
,
99 Table_Increment
=> Alloc
.Rep_Table_Increment
,
100 Table_Name
=> "BE_Rep_Table");
102 --------------------------------------------------------------
103 -- Representation of Front-End Dynamic Size/Offset Entities --
104 --------------------------------------------------------------
106 package Dynamic_SO_Entity_Table
is new Table
.Table
(
107 Table_Component_Type
=> Entity_Id
,
108 Table_Index_Type
=> Nat
,
109 Table_Low_Bound
=> 1,
110 Table_Initial
=> Alloc
.Rep_Table_Initial
,
111 Table_Increment
=> Alloc
.Rep_Table_Increment
,
112 Table_Name
=> "FE_Rep_Table");
114 Unit_Casing
: Casing_Type
;
115 -- Identifier casing for current unit. This is set by List_Rep_Info for
116 -- each unit, before calling subprograms which may read it.
118 Need_Separator
: Boolean;
119 -- Set True if a separator is needed before outputting any information for
120 -- the current entity.
122 ------------------------------
123 -- Set of Relevant Entities --
124 ------------------------------
126 Relevant_Entities_Size
: constant := 4093;
127 -- Number of headers in hash table
129 subtype Entity_Header_Num
is Integer range 0 .. Relevant_Entities_Size
- 1;
130 -- Range of headers in hash table
132 function Entity_Hash
(Id
: Entity_Id
) return Entity_Header_Num
;
133 -- Simple hash function for Entity_Ids
135 package Relevant_Entities
is new GNAT
.Htable
.Simple_HTable
136 (Header_Num
=> Entity_Header_Num
,
142 -- Hash table to record which compiler-generated entities are relevant
144 -----------------------
145 -- Local Subprograms --
146 -----------------------
148 procedure List_Entities
150 Bytes_Big_Endian
: Boolean;
151 In_Subprogram
: Boolean := False);
152 -- This procedure lists the entities associated with the entity E, starting
153 -- with the First_Entity and using the Next_Entity link. If a nested
154 -- package is found, entities within the package are recursively processed.
155 -- When recursing within a subprogram body, Is_Subprogram suppresses
156 -- duplicate information about signature.
158 procedure List_Name
(Ent
: Entity_Id
);
159 -- List name of entity Ent in appropriate case. The name is listed with
160 -- full qualification up to but not including the compilation unit name.
162 procedure List_Array_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean);
163 -- List representation info for array type Ent
165 procedure List_Common_Type_Info
(Ent
: Entity_Id
);
166 -- List common type info (name, size, alignment) for type Ent
168 procedure List_Linker_Section
(Ent
: Entity_Id
);
169 -- List linker section for Ent (caller has checked that Ent is an entity
170 -- for which the Linker_Section_Pragma field is defined).
172 procedure List_Location
(Ent
: Entity_Id
);
173 -- List location information for Ent
175 procedure List_Object_Info
(Ent
: Entity_Id
);
176 -- List representation info for object Ent
178 procedure List_Record_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean);
179 -- List representation info for record type Ent
181 procedure List_Scalar_Storage_Order
183 Bytes_Big_Endian
: Boolean);
184 -- List scalar storage order information for record or array type Ent.
185 -- Also includes bit order information for record types, if necessary.
187 procedure List_Subprogram_Info
(Ent
: Entity_Id
);
188 -- List subprogram info for subprogram Ent
190 procedure List_Type_Info
(Ent
: Entity_Id
);
191 -- List type info for type Ent
193 function Compile_Time_Known_Rep
(Val
: Node_Ref_Or_Val
) return Boolean;
194 -- Returns True if Val represents a representation value that is known at
197 procedure Spaces
(N
: Natural);
198 -- Output given number of spaces
200 procedure Write_Info_Line
(S
: String);
201 -- Routine to write a line to Repinfo output file. This routine is passed
202 -- as a special output procedure to Output.Set_Special_Output. Note that
203 -- Write_Info_Line is called with an EOL character at the end of each line,
204 -- as per the Output spec, but the internal call to the appropriate routine
205 -- in Osint requires that the end of line sequence be stripped off.
207 procedure Write_Mechanism
(M
: Mechanism_Type
);
208 -- Writes symbolic string for mechanism represented by M
210 procedure Write_Separator
;
211 -- Called before outputting anything for an entity. Ensures that
212 -- a separator precedes the output for a particular entity.
214 procedure Write_Unknown_Val
;
215 -- Writes symbolic string for an unknown or non-representable value
217 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False);
218 -- Given a representation value, write it out. No_Uint values or values
219 -- dependent on discriminants are written as two question marks. If the
220 -- flag Paren is set, then the output is surrounded in parentheses if it is
221 -- other than a simple value.
223 ------------------------
224 -- Create_Discrim_Ref --
225 ------------------------
227 function Create_Discrim_Ref
(Discr
: Entity_Id
) return Node_Ref
is
230 (Expr
=> Discrim_Val
,
231 Op1
=> Discriminant_Number
(Discr
));
232 end Create_Discrim_Ref
;
234 ---------------------------
235 -- Create_Dynamic_SO_Ref --
236 ---------------------------
238 function Create_Dynamic_SO_Ref
(E
: Entity_Id
) return Dynamic_SO_Ref
is
240 Dynamic_SO_Entity_Table
.Append
(E
);
241 return UI_From_Int
(-Dynamic_SO_Entity_Table
.Last
);
242 end Create_Dynamic_SO_Ref
;
250 Op1
: Node_Ref_Or_Val
;
251 Op2
: Node_Ref_Or_Val
:= No_Uint
;
252 Op3
: Node_Ref_Or_Val
:= No_Uint
) return Node_Ref
260 return UI_From_Int
(-Rep_Table
.Last
);
267 function Entity_Hash
(Id
: Entity_Id
) return Entity_Header_Num
is
269 return Entity_Header_Num
(Id
mod Relevant_Entities_Size
);
272 ---------------------------
273 -- Get_Dynamic_SO_Entity --
274 ---------------------------
276 function Get_Dynamic_SO_Entity
(U
: Dynamic_SO_Ref
) return Entity_Id
is
278 return Dynamic_SO_Entity_Table
.Table
(-UI_To_Int
(U
));
279 end Get_Dynamic_SO_Entity
;
281 -----------------------
282 -- Is_Dynamic_SO_Ref --
283 -----------------------
285 function Is_Dynamic_SO_Ref
(U
: SO_Ref
) return Boolean is
288 end Is_Dynamic_SO_Ref
;
290 ----------------------
291 -- Is_Static_SO_Ref --
292 ----------------------
294 function Is_Static_SO_Ref
(U
: SO_Ref
) return Boolean is
297 end Is_Static_SO_Ref
;
303 procedure lgx
(U
: Node_Ref_Or_Val
) is
305 List_GCC_Expression
(U
);
309 ----------------------
310 -- List_Array_Info --
311 ----------------------
313 procedure List_Array_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean) is
317 if List_Representation_Info_To_JSON
then
321 List_Common_Type_Info
(Ent
);
323 if List_Representation_Info_To_JSON
then
325 Write_Str
(" ""Component_Size"": ");
326 Write_Val
(Component_Size
(Ent
));
330 Write_Str
("'Component_Size use ");
331 Write_Val
(Component_Size
(Ent
));
335 List_Scalar_Storage_Order
(Ent
, Bytes_Big_Endian
);
337 List_Linker_Section
(Ent
);
339 if List_Representation_Info_To_JSON
then
344 -- The component type is relevant for an array
346 if List_Representation_Info
= 4
347 and then Is_Itype
(Component_Type
(Base_Type
(Ent
)))
349 Relevant_Entities
.Set
(Component_Type
(Base_Type
(Ent
)), True);
353 ---------------------------
354 -- List_Common_Type_Info --
355 ---------------------------
357 procedure List_Common_Type_Info
(Ent
: Entity_Id
) is
359 if List_Representation_Info_To_JSON
then
360 Write_Str
(" ""name"": """);
366 -- Do not list size info for unconstrained arrays, not meaningful
368 if Is_Array_Type
(Ent
) and then not Is_Constrained
(Ent
) then
372 if Known_Esize
(Ent
) and then Known_RM_Size
(Ent
) then
373 -- If Esize and RM_Size are the same, list as Size. This is a
374 -- common case, which we may as well list in simple form.
376 if Esize
(Ent
) = RM_Size
(Ent
) then
377 if List_Representation_Info_To_JSON
then
378 Write_Str
(" ""Size"": ");
379 Write_Val
(Esize
(Ent
));
384 Write_Str
("'Size use ");
385 Write_Val
(Esize
(Ent
));
389 -- Otherwise list size values separately
392 if List_Representation_Info_To_JSON
then
393 Write_Str
(" ""Object_Size"": ");
394 Write_Val
(Esize
(Ent
));
397 Write_Str
(" ""Value_Size"": ");
398 Write_Val
(RM_Size
(Ent
));
404 Write_Str
("'Object_Size use ");
405 Write_Val
(Esize
(Ent
));
410 Write_Str
("'Value_Size use ");
411 Write_Val
(RM_Size
(Ent
));
418 if Known_Alignment
(Ent
) then
419 if List_Representation_Info_To_JSON
then
420 Write_Str
(" ""Alignment"": ");
421 Write_Val
(Alignment
(Ent
));
425 Write_Str
("'Alignment use ");
426 Write_Val
(Alignment
(Ent
));
430 -- Alignment is not always set for task, protected, and class-wide
431 -- types. Representation aspects are not computed for types in a
436 (Is_Concurrent_Type
(Ent
) or else
437 Is_Class_Wide_Type
(Ent
) or else
438 Sem_Util
.In_Generic_Scope
(Ent
));
440 end List_Common_Type_Info
;
446 procedure List_Entities
448 Bytes_Big_Endian
: Boolean;
449 In_Subprogram
: Boolean := False)
454 function Find_Declaration
(E
: Entity_Id
) return Node_Id
;
455 -- Utility to retrieve declaration node for entity in the
456 -- case of package bodies and subprograms.
458 ----------------------
459 -- Find_Declaration --
460 ----------------------
462 function Find_Declaration
(E
: Entity_Id
) return Node_Id
is
468 and then Nkind
(Decl
) /= N_Package_Body
469 and then Nkind
(Decl
) /= N_Subprogram_Declaration
470 and then Nkind
(Decl
) /= N_Subprogram_Body
472 Decl
:= Parent
(Decl
);
476 end Find_Declaration
;
478 -- Start of processing for List_Entities
481 -- List entity if we have one, and it is not a renaming declaration.
482 -- For renamings, we don't get proper information, and really it makes
483 -- sense to restrict the output to the renamed entity.
486 and then Nkind
(Declaration_Node
(Ent
)) not in N_Renaming_Declaration
487 and then not Is_Ignored_Ghost_Entity
(Ent
)
489 -- If entity is a subprogram and we are listing mechanisms,
490 -- then we need to list mechanisms for this entity. We skip this
491 -- if it is a nested subprogram, as the information has already
492 -- been produced when listing the enclosing scope.
494 if List_Representation_Info_Mechanisms
495 and then Is_Subprogram_Or_Entry
(Ent
)
496 and then not In_Subprogram
498 List_Subprogram_Info
(Ent
);
501 E
:= First_Entity
(Ent
);
502 while Present
(E
) loop
503 -- We list entities that come from source (excluding private or
504 -- incomplete types or deferred constants, for which we will list
505 -- the information for the full view). If requested, we also list
506 -- relevant entities that have been generated when processing the
507 -- original entities coming from source. But if debug flag A is
508 -- set, then all entities are listed.
510 if ((Comes_From_Source
(E
)
511 or else (Ekind
(E
) = E_Block
513 Nkind
(Parent
(E
)) = N_Implicit_Label_Declaration
515 Comes_From_Source
(Label_Construct
(Parent
(E
)))))
516 and then not Is_Incomplete_Or_Private_Type
(E
)
517 and then not (Ekind
(E
) = E_Constant
518 and then Present
(Full_View
(E
))))
519 or else (List_Representation_Info
= 4
520 and then Relevant_Entities
.Get
(E
))
521 or else Debug_Flag_AA
523 if Is_Subprogram
(E
) then
524 if List_Representation_Info_Mechanisms
then
525 List_Subprogram_Info
(E
);
528 -- Recurse into entities local to subprogram
530 List_Entities
(E
, Bytes_Big_Endian
, True);
532 elsif Ekind
(E
) in E_Entry
536 if List_Representation_Info_Mechanisms
then
537 List_Subprogram_Info
(E
);
540 elsif Is_Record_Type
(E
) then
541 if List_Representation_Info
>= 1 then
542 List_Record_Info
(E
, Bytes_Big_Endian
);
544 -- Recurse into entities local to a record type
546 if List_Representation_Info
= 4 then
547 List_Entities
(E
, Bytes_Big_Endian
, False);
551 elsif Is_Array_Type
(E
) then
552 if List_Representation_Info
>= 1 then
553 List_Array_Info
(E
, Bytes_Big_Endian
);
556 elsif Is_Type
(E
) then
557 if List_Representation_Info
>= 2 then
561 -- Note that formals are not annotated so we skip them here
563 elsif Ekind
(E
) in E_Constant
567 if List_Representation_Info
>= 2 then
568 List_Object_Info
(E
);
572 -- Recurse into nested package, but not child packages, and not
573 -- nested package renamings (in particular renamings of the
574 -- enclosing package, as for some Java bindings and for generic
577 if Ekind
(E
) = E_Package
then
578 if No
(Renamed_Entity
(E
)) and then not Is_Child_Unit
(E
)
580 List_Entities
(E
, Bytes_Big_Endian
);
583 -- Recurse into bodies
585 elsif Ekind
(E
) in E_Package_Body
592 List_Entities
(E
, Bytes_Big_Endian
);
594 -- Recurse into blocks
596 elsif Ekind
(E
) = E_Block
then
597 List_Entities
(E
, Bytes_Big_Endian
);
604 -- For a package body, the entities of the visible subprograms are
605 -- declared in the corresponding spec. Iterate over its entities in
606 -- order to handle properly the subprogram bodies. Skip bodies in
607 -- subunits, which are listed independently.
609 if Ekind
(Ent
) = E_Package_Body
610 and then Present
(Corresponding_Spec
(Find_Declaration
(Ent
)))
612 E
:= First_Entity
(Corresponding_Spec
(Find_Declaration
(Ent
)));
613 while Present
(E
) loop
616 Nkind
(Find_Declaration
(E
)) = N_Subprogram_Declaration
618 Body_E
:= Corresponding_Body
(Find_Declaration
(E
));
622 Nkind
(Parent
(Find_Declaration
(Body_E
))) /= N_Subunit
624 List_Entities
(Body_E
, Bytes_Big_Endian
);
634 -------------------------
635 -- List_GCC_Expression --
636 -------------------------
638 procedure List_GCC_Expression
(U
: Node_Ref_Or_Val
) is
640 procedure Print_Expr
(Val
: Node_Ref_Or_Val
);
641 -- Internal recursive procedure to print expression
647 procedure Print_Expr
(Val
: Node_Ref_Or_Val
) is
650 UI_Write
(Val
, Decimal
);
654 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
656 procedure Unop
(S
: String);
657 -- Output text for unary operator with S being operator name
659 procedure Binop
(S
: String);
660 -- Output text for binary operator with S being operator name
666 procedure Unop
(S
: String) is
668 if List_Representation_Info_To_JSON
then
669 Write_Str
("{ ""code"": """);
670 if S
(S
'Last) = ' ' then
671 Write_Str
(S
(S
'First .. S
'Last - 1));
675 Write_Str
(""", ""operands"": [ ");
676 Print_Expr
(Node
.Op1
);
680 Print_Expr
(Node
.Op1
);
688 procedure Binop
(S
: String) is
690 if List_Representation_Info_To_JSON
then
691 Write_Str
("{ ""code"": """);
692 Write_Str
(S
(S
'First + 1 .. S
'Last - 1));
693 Write_Str
(""", ""operands"": [ ");
694 Print_Expr
(Node
.Op1
);
696 Print_Expr
(Node
.Op2
);
700 Print_Expr
(Node
.Op1
);
702 Print_Expr
(Node
.Op2
);
707 -- Start of processing for Print_Expr
712 if List_Representation_Info_To_JSON
then
713 Write_Str
("{ ""code"": ""?<>""");
714 Write_Str
(", ""operands"": [ ");
715 Print_Expr
(Node
.Op1
);
717 Print_Expr
(Node
.Op2
);
719 Print_Expr
(Node
.Op3
);
723 Print_Expr
(Node
.Op1
);
724 Write_Str
(" then ");
725 Print_Expr
(Node
.Op2
);
726 Write_Str
(" else ");
727 Print_Expr
(Node
.Op3
);
740 when Trunc_Div_Expr
=>
743 when Ceil_Div_Expr
=>
746 when Floor_Div_Expr
=>
749 when Trunc_Mod_Expr
=>
752 when Ceil_Mod_Expr
=>
755 when Floor_Mod_Expr
=>
758 when Exact_Div_Expr
=>
773 when Truth_And_Expr
=>
776 when Truth_Or_Expr
=>
779 when Truth_Xor_Expr
=>
782 when Truth_Not_Expr
=>
816 -- Start of processing for List_GCC_Expression
824 end List_GCC_Expression
;
826 -------------------------
827 -- List_Linker_Section --
828 -------------------------
830 procedure List_Linker_Section
(Ent
: Entity_Id
) is
835 if Present
(Linker_Section_Pragma
(Ent
)) then
836 Args
:= Pragma_Argument_Associations
(Linker_Section_Pragma
(Ent
));
837 Sect
:= Expr_Value_S
(Get_Pragma_Arg
(Last
(Args
)));
839 if List_Representation_Info_To_JSON
then
841 Write_Str
(" ""Linker_Section"": """);
843 Write_Str
("pragma Linker_Section (");
848 pragma Assert
(Nkind
(Sect
) = N_String_Literal
);
849 String_To_Name_Buffer
(Strval
(Sect
));
850 Write_Str
(Name_Buffer
(1 .. Name_Len
));
852 if not List_Representation_Info_To_JSON
then
856 end List_Linker_Section
;
862 procedure List_Location
(Ent
: Entity_Id
) is
864 pragma Assert
(List_Representation_Info_To_JSON
);
865 Write_Str
(" ""location"": """);
866 Write_Location
(Sloc
(Ent
));
874 procedure List_Name
(Ent
: Entity_Id
) is
878 -- In JSON mode, we recurse up to Standard. This is also valid in
879 -- default mode where we recurse up to the first compilation unit and
880 -- should not get to Standard.
882 if Scope
(Ent
) = Standard_Standard
then
884 elsif not Is_Compilation_Unit
(Scope
(Ent
))
885 or else List_Representation_Info_To_JSON
887 List_Name
(Scope
(Ent
));
891 Get_Unqualified_Decoded_Name_String
(Chars
(Ent
));
892 Set_Casing
(Unit_Casing
);
894 -- The name of operators needs to be properly escaped for JSON
896 for J
in 1 .. Name_Len
loop
897 C
:= Name_Buffer
(J
);
898 if C
= '"' and then List_Representation_Info_To_JSON
then
905 ---------------------
906 -- List_Object_Info --
907 ---------------------
909 procedure List_Object_Info
(Ent
: Entity_Id
) is
911 -- If size and alignment have not been computed (e.g. if we are in a
912 -- generic unit, or if the back end is not being run), don't try to
915 pragma Assert
(Known_Esize
(Ent
) = Known_Alignment
(Ent
));
916 if not Known_Alignment
(Ent
) then
922 if List_Representation_Info_To_JSON
then
925 Write_Str
(" ""name"": """);
930 Write_Str
(" ""Size"": ");
931 Write_Val
(Esize
(Ent
));
934 Write_Str
(" ""Alignment"": ");
935 Write_Val
(Alignment
(Ent
));
937 List_Linker_Section
(Ent
);
944 Write_Str
("'Size use ");
945 Write_Val
(Esize
(Ent
));
950 Write_Str
("'Alignment use ");
951 Write_Val
(Alignment
(Ent
));
954 List_Linker_Section
(Ent
);
957 -- The type is relevant for an object
959 if List_Representation_Info
= 4 and then Is_Itype
(Etype
(Ent
)) then
960 Relevant_Entities
.Set
(Etype
(Ent
), True);
962 end List_Object_Info
;
964 ----------------------
965 -- List_Record_Info --
966 ----------------------
968 procedure List_Record_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean) is
969 procedure Compute_Max_Length
971 Starting_Position
: Uint
:= Uint_0
;
972 Starting_First_Bit
: Uint
:= Uint_0
;
973 Prefix_Length
: Natural := 0);
974 -- Internal recursive procedure to compute the max length
976 procedure List_Component_Layout
978 Starting_Position
: Uint
:= Uint_0
;
979 Starting_First_Bit
: Uint
:= Uint_0
;
980 Prefix
: String := "";
981 Indent
: Natural := 0);
982 -- Procedure to display the layout of a single component
984 procedure List_Record_Layout
986 Starting_Position
: Uint
:= Uint_0
;
987 Starting_First_Bit
: Uint
:= Uint_0
;
988 Prefix
: String := "");
989 -- Internal recursive procedure to display the layout
991 procedure List_Structural_Record_Layout
994 Ext_Level
: Nat
:= 0;
995 Variant
: Node_Id
:= Empty
;
996 Indent
: Natural := 0);
997 -- Internal recursive procedure to display the structural layout.
998 -- If Ext_Ent is not equal to Ent, it is an extension of Ent and
999 -- Ext_Level is the number of successive extensions between them.
1000 -- If Variant is present, it's for a variant in the variant part
1001 -- instead of the common part of Ent. Indent is the indentation.
1003 Incomplete_Layout
: exception;
1004 -- Exception raised if the layout is incomplete in -gnatc mode
1006 Not_In_Extended_Main
: exception;
1007 -- Exception raised when an ancestor is not declared in the main unit
1009 Max_Name_Length
: Natural := 0;
1010 Max_Spos_Length
: Natural := 0;
1012 ------------------------
1013 -- Compute_Max_Length --
1014 ------------------------
1016 procedure Compute_Max_Length
1018 Starting_Position
: Uint
:= Uint_0
;
1019 Starting_First_Bit
: Uint
:= Uint_0
;
1020 Prefix_Length
: Natural := 0)
1025 Comp
:= First_Component_Or_Discriminant
(Ent
);
1026 while Present
(Comp
) loop
1028 -- Skip a completely hidden discriminant or a discriminant in an
1029 -- unchecked union (since it is not there).
1031 if Ekind
(Comp
) = E_Discriminant
1032 and then (Is_Completely_Hidden
(Comp
)
1033 or else Is_Unchecked_Union
(Ent
))
1038 -- Skip _Parent component in extension (to avoid overlap)
1040 if Chars
(Comp
) = Name_uParent
then
1047 Ctyp
: constant Entity_Id
:= Underlying_Type
(Etype
(Comp
));
1048 Bofs
: constant Uint
:= Component_Bit_Offset
(Comp
);
1054 Name_Length
: Natural;
1057 Get_Decoded_Name_String
(Chars
(Comp
));
1058 Name_Length
:= Prefix_Length
+ Name_Len
;
1060 if Compile_Time_Known_Rep
(Bofs
) then
1062 Fbit
:= Bofs
mod SSU
;
1064 -- Complete annotation in case not done
1066 if not Known_Normalized_First_Bit
(Comp
) then
1067 Set_Normalized_Position
(Comp
, Npos
);
1068 Set_Normalized_First_Bit
(Comp
, Fbit
);
1071 Spos
:= Starting_Position
+ Npos
;
1072 Sbit
:= Starting_First_Bit
+ Fbit
;
1079 -- If extended information is requested, recurse fully into
1080 -- record components, i.e. skip the outer level.
1082 if List_Representation_Info_Extended
1083 and then Is_Record_Type
(Ctyp
)
1085 Compute_Max_Length
(Ctyp
, Spos
, Sbit
, Name_Length
+ 1);
1091 -- If the record is not packed, then we know that all fields
1092 -- whose position is not specified have starting normalized
1093 -- bit position of zero.
1095 if not Known_Normalized_First_Bit
(Comp
)
1096 and then not Is_Packed
(Ent
)
1098 Set_Normalized_First_Bit
(Comp
, Uint_0
);
1101 UI_Image_Length
:= 2; -- For "??" marker
1104 Max_Name_Length
:= Natural'Max (Max_Name_Length
, Name_Length
);
1106 Natural'Max (Max_Spos_Length
, UI_Image_Length
);
1110 Next_Component_Or_Discriminant
(Comp
);
1112 end Compute_Max_Length
;
1114 ---------------------------
1115 -- List_Component_Layout --
1116 ---------------------------
1118 procedure List_Component_Layout
1120 Starting_Position
: Uint
:= Uint_0
;
1121 Starting_First_Bit
: Uint
:= Uint_0
;
1122 Prefix
: String := "";
1123 Indent
: Natural := 0)
1125 Esiz
: constant Uint
:= Esize
(Ent
);
1126 Npos
: constant Uint
:= Normalized_Position
(Ent
);
1127 Fbit
: constant Uint
:= Normalized_First_Bit
(Ent
);
1129 Sbit
: Uint
:= No_Uint
;
1133 if List_Representation_Info_To_JSON
then
1137 Write_Str
(" ""name"": """);
1139 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1141 if Ekind
(Ent
) = E_Discriminant
then
1143 Write_Str
(" ""discriminant"": ");
1144 UI_Write
(Discriminant_Number
(Ent
), Decimal
);
1148 Write_Str
(" ""Position"": ");
1152 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1153 Spaces
(Max_Name_Length
- Prefix
'Length - Name_Len
);
1157 if Known_Static_Normalized_Position
(Ent
) then
1158 Spos
:= Starting_Position
+ Npos
;
1159 Sbit
:= Starting_First_Bit
+ Fbit
;
1166 Spaces
(Max_Spos_Length
- UI_Image_Length
);
1167 Write_Str
(UI_Image_Buffer
(1 .. UI_Image_Length
));
1169 elsif Known_Normalized_Position
(Ent
)
1170 and then List_Representation_Info
>= 3
1172 Spaces
(Max_Spos_Length
- 2);
1174 if Starting_Position
/= Uint_0
then
1175 UI_Write
(Starting_Position
, Decimal
);
1185 if List_Representation_Info_To_JSON
then
1188 Write_Str
(" ""First_Bit"": ");
1190 Write_Str
(" range ");
1193 if Known_Static_Normalized_First_Bit
(Ent
) then
1194 Sbit
:= Starting_First_Bit
+ Fbit
;
1200 UI_Write
(Sbit
, Decimal
);
1205 if List_Representation_Info_To_JSON
then
1208 Write_Str
(" ""Size"": ");
1213 if Known_Static_Esize
(Ent
)
1214 and then Known_Static_Normalized_First_Bit
(Ent
)
1216 Lbit
:= Sbit
+ Esiz
- 1;
1218 if List_Representation_Info_To_JSON
then
1219 UI_Write
(Esiz
, Decimal
);
1221 if Lbit
>= 0 and then Lbit
< 10 then
1225 UI_Write
(Lbit
, Decimal
);
1228 elsif List_Representation_Info
< 3 or else not Known_Esize
(Ent
) then
1231 -- List_Representation >= 3 and Known_Esize (Ent)
1234 Write_Val
(Esiz
, Paren
=> not List_Representation_Info_To_JSON
);
1236 -- Add appropriate first bit offset
1238 if not List_Representation_Info_To_JSON
then
1247 Write_Int
(UI_To_Int
(Sbit
) - 1);
1252 if List_Representation_Info_To_JSON
then
1260 -- The type is relevant for a component
1262 if List_Representation_Info
= 4 and then Is_Itype
(Etype
(Ent
)) then
1263 Relevant_Entities
.Set
(Etype
(Ent
), True);
1265 end List_Component_Layout
;
1267 ------------------------
1268 -- List_Record_Layout --
1269 ------------------------
1271 procedure List_Record_Layout
1273 Starting_Position
: Uint
:= Uint_0
;
1274 Starting_First_Bit
: Uint
:= Uint_0
;
1275 Prefix
: String := "")
1278 First
: Boolean := True;
1281 Comp
:= First_Component_Or_Discriminant
(Ent
);
1282 while Present
(Comp
) loop
1284 -- Skip a completely hidden discriminant or a discriminant in an
1285 -- unchecked union (since it is not there).
1287 if Ekind
(Comp
) = E_Discriminant
1288 and then (Is_Completely_Hidden
(Comp
)
1289 or else Is_Unchecked_Union
(Ent
))
1294 -- Skip _Parent component in extension (to avoid overlap)
1296 if Chars
(Comp
) = Name_uParent
then
1303 Ctyp
: constant Entity_Id
:= Underlying_Type
(Etype
(Comp
));
1304 Npos
: constant Uint
:= Normalized_Position
(Comp
);
1305 Fbit
: constant Uint
:= Normalized_First_Bit
(Comp
);
1310 Get_Decoded_Name_String
(Chars
(Comp
));
1311 Set_Casing
(Unit_Casing
);
1313 -- If extended information is requested, recurse fully into
1314 -- record components, i.e. skip the outer level.
1316 if List_Representation_Info_Extended
1317 and then Is_Record_Type
(Ctyp
)
1318 and then Known_Static_Normalized_Position
(Comp
)
1319 and then Known_Static_Normalized_First_Bit
(Comp
)
1321 Spos
:= Starting_Position
+ Npos
;
1322 Sbit
:= Starting_First_Bit
+ Fbit
;
1329 List_Record_Layout
(Ctyp
,
1330 Spos
, Sbit
, Prefix
& Name_Buffer
(1 .. Name_Len
) & ".");
1335 if List_Representation_Info_To_JSON
then
1344 -- The Parent_Subtype in an extension is not back-annotated
1346 List_Component_Layout
(
1347 (if Known_Normalized_Position
(Comp
)
1349 else Original_Record_Component
(Comp
)),
1350 Starting_Position
, Starting_First_Bit
, Prefix
);
1354 Next_Component_Or_Discriminant
(Comp
);
1356 end List_Record_Layout
;
1358 -----------------------------------
1359 -- List_Structural_Record_Layout --
1360 -----------------------------------
1362 procedure List_Structural_Record_Layout
1364 Ext_Ent
: Entity_Id
;
1365 Ext_Level
: Nat
:= 0;
1366 Variant
: Node_Id
:= Empty
;
1367 Indent
: Natural := 0)
1369 function Derived_Discriminant
(Disc
: Entity_Id
) return Entity_Id
;
1370 -- This function assumes that Ext_Ent is an extension of Ent.
1371 -- Disc is a discriminant of Ent that does not itself constrain a
1372 -- discriminant of the parent type of Ent. Return the discriminant
1373 -- of Ext_Ent that ultimately constrains Disc, if any.
1375 ----------------------------
1376 -- Derived_Discriminant --
1377 ----------------------------
1379 function Derived_Discriminant
(Disc
: Entity_Id
) return Entity_Id
is
1380 Corr_Disc
: Entity_Id
;
1381 Derived_Disc
: Entity_Id
;
1384 Derived_Disc
:= First_Discriminant
(Ext_Ent
);
1386 -- Loop over the discriminants of the extension
1388 while Present
(Derived_Disc
) loop
1390 -- Check if this discriminant constrains another discriminant.
1391 -- If so, find the ultimately constrained discriminant and
1392 -- compare with the original components in the base type.
1394 if Present
(Corresponding_Discriminant
(Derived_Disc
)) then
1395 Corr_Disc
:= Corresponding_Discriminant
(Derived_Disc
);
1397 while Present
(Corresponding_Discriminant
(Corr_Disc
)) loop
1398 Corr_Disc
:= Corresponding_Discriminant
(Corr_Disc
);
1401 if Original_Record_Component
(Corr_Disc
) =
1402 Original_Record_Component
(Disc
)
1404 return Derived_Disc
;
1408 Next_Discriminant
(Derived_Disc
);
1411 -- Disc is not constrained by a discriminant of Ext_Ent
1414 end Derived_Discriminant
;
1416 -- Local declarations
1419 Comp_List
: Node_Id
;
1420 First
: Boolean := True;
1423 -- Start of processing for List_Structural_Record_Layout
1426 -- If we are dealing with a variant, just process the components
1428 if Present
(Variant
) then
1429 Comp_List
:= Component_List
(Variant
);
1431 -- Otherwise, we are dealing with the full record and need to get
1432 -- to its definition in order to retrieve its structural layout.
1436 Definition
: Node_Id
:=
1437 Type_Definition
(Declaration_Node
(Ent
));
1439 Is_Extension
: constant Boolean :=
1440 Is_Tagged_Type
(Ent
)
1441 and then Nkind
(Definition
) =
1442 N_Derived_Type_Definition
;
1445 Listed_Disc
: Entity_Id
;
1446 Parent_Type
: Entity_Id
;
1449 -- If this is an extension, first list the layout of the parent
1450 -- and then proceed to the extension part, if any.
1452 if Is_Extension
then
1453 Parent_Type
:= Parent_Subtype
(Ent
);
1454 if No
(Parent_Type
) then
1455 raise Incomplete_Layout
;
1458 if Is_Private_Type
(Parent_Type
) then
1459 Parent_Type
:= Full_View
(Parent_Type
);
1460 pragma Assert
(Present
(Parent_Type
));
1463 -- Do not list variants if one of them has been selected
1465 if Has_Static_Discriminants
(Parent_Type
) then
1466 List_Record_Layout
(Parent_Type
);
1469 Parent_Type
:= Base_Type
(Parent_Type
);
1470 if not In_Extended_Main_Source_Unit
(Parent_Type
) then
1471 raise Not_In_Extended_Main
;
1474 List_Structural_Record_Layout
1475 (Parent_Type
, Ext_Ent
, Ext_Level
+ 1);
1480 if Present
(Record_Extension_Part
(Definition
)) then
1481 Definition
:= Record_Extension_Part
(Definition
);
1485 -- If the record has discriminants and is not an unchecked
1486 -- union, then display them now. Note that, even if this is
1487 -- a structural layout, we list the visible discriminants.
1489 if Has_Discriminants
(Ent
)
1490 and then not Is_Unchecked_Union
(Ent
)
1492 Disc
:= First_Discriminant
(Ent
);
1493 while Present
(Disc
) loop
1495 -- If this is a record extension and the discriminant is
1496 -- the renaming of another discriminant, skip it.
1499 and then Present
(Corresponding_Discriminant
(Disc
))
1504 -- If this is the parent type of an extension, retrieve
1505 -- the derived discriminant from the extension, if any.
1507 if Ent
/= Ext_Ent
then
1508 Listed_Disc
:= Derived_Discriminant
(Disc
);
1510 if No
(Listed_Disc
) then
1514 Listed_Disc
:= Disc
;
1517 Get_Decoded_Name_String
(Chars
(Listed_Disc
));
1518 Set_Casing
(Unit_Casing
);
1527 List_Component_Layout
(Listed_Disc
, Indent
=> Indent
);
1530 Next_Discriminant
(Disc
);
1534 Comp_List
:= Component_List
(Definition
);
1538 -- Bail out for the null record
1540 if No
(Comp_List
) then
1544 -- Now deal with the regular components, if any
1546 if Present
(Component_Items
(Comp_List
)) then
1547 Comp
:= First_Non_Pragma
(Component_Items
(Comp_List
));
1548 while Present
(Comp
) loop
1550 -- Skip _Parent component in extension (to avoid overlap)
1552 if Chars
(Defining_Identifier
(Comp
)) = Name_uParent
then
1556 Get_Decoded_Name_String
(Chars
(Defining_Identifier
(Comp
)));
1557 Set_Casing
(Unit_Casing
);
1566 List_Component_Layout
1567 (Defining_Identifier
(Comp
), Indent
=> Indent
);
1570 Next_Non_Pragma
(Comp
);
1574 -- We are done if there is no variant part
1576 if No
(Variant_Part
(Comp_List
)) then
1585 for J
in 1 .. Ext_Level
loop
1586 Write_Str
("parent_");
1588 Write_Str
("variant"" : [");
1590 -- Otherwise we recurse on each variant
1592 Var
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
1594 while Present
(Var
) loop
1605 Write_Str
(" ""present"": ");
1606 Write_Val
(Present_Expr
(Var
));
1609 Write_Str
(" ""record"": [");
1611 List_Structural_Record_Layout
1612 (Ent
, Ext_Ent
, Ext_Level
, Var
, Indent
+ 4);
1619 Next_Non_Pragma
(Var
);
1621 end List_Structural_Record_Layout
;
1623 -- Start of processing for List_Record_Info
1628 if List_Representation_Info_To_JSON
then
1632 List_Common_Type_Info
(Ent
);
1634 -- First find out max line length and max starting position
1635 -- length, for the purpose of lining things up nicely.
1637 Compute_Max_Length
(Ent
);
1639 -- Then do actual output based on those values
1641 if List_Representation_Info_To_JSON
then
1643 Write_Str
(" ""record"": [");
1645 -- ??? We can output structural layout only for base types fully
1646 -- declared in the extended main source unit for the time being,
1647 -- because otherwise declarations might not be processed at all.
1649 if Is_Base_Type
(Ent
) then
1651 List_Structural_Record_Layout
(Ent
, Ent
);
1654 when Incomplete_Layout
1655 | Not_In_Extended_Main
1657 List_Record_Layout
(Ent
);
1660 raise Program_Error
;
1663 List_Record_Layout
(Ent
);
1671 Write_Line
(" use record");
1673 List_Record_Layout
(Ent
);
1675 Write_Line
("end record;");
1678 List_Scalar_Storage_Order
(Ent
, Bytes_Big_Endian
);
1680 List_Linker_Section
(Ent
);
1682 if List_Representation_Info_To_JSON
then
1687 -- The type is relevant for a record subtype
1689 if List_Representation_Info
= 4
1690 and then not Is_Base_Type
(Ent
)
1691 and then Is_Itype
(Etype
(Ent
))
1693 Relevant_Entities
.Set
(Etype
(Ent
), True);
1695 end List_Record_Info
;
1701 procedure List_Rep_Info
(Bytes_Big_Endian
: Boolean) is
1705 if List_Representation_Info
/= 0
1706 or else List_Representation_Info_Mechanisms
1708 -- For the normal case, we output a single JSON stream
1710 if not List_Representation_Info_To_File
1711 and then List_Representation_Info_To_JSON
1714 Need_Separator
:= False;
1717 for U
in Main_Unit
.. Last_Unit
loop
1718 if In_Extended_Main_Source_Unit
(Cunit_Entity
(U
)) then
1719 Unit_Casing
:= Identifier_Casing
(Source_Index
(U
));
1721 if List_Representation_Info
= 4 then
1722 Relevant_Entities
.Reset
;
1725 -- Normal case, list to standard output
1727 if not List_Representation_Info_To_File
then
1728 if not List_Representation_Info_To_JSON
then
1730 Write_Str
("Representation information for unit ");
1731 Write_Unit_Name
(Unit_Name
(U
));
1735 for J
in 1 .. Col
- 1 loop
1740 Need_Separator
:= True;
1743 List_Entities
(Cunit_Entity
(U
), Bytes_Big_Endian
);
1745 -- List representation information to file
1749 (Get_Name_String
(File_Name
(Source_Index
(U
))));
1750 Set_Special_Output
(Write_Info_Line
'Access);
1751 if List_Representation_Info_To_JSON
then
1754 Need_Separator
:= False;
1755 List_Entities
(Cunit_Entity
(U
), Bytes_Big_Endian
);
1756 if List_Representation_Info_To_JSON
then
1759 Cancel_Special_Output
;
1765 if not List_Representation_Info_To_File
1766 and then List_Representation_Info_To_JSON
1773 -------------------------------
1774 -- List_Scalar_Storage_Order --
1775 -------------------------------
1777 procedure List_Scalar_Storage_Order
1779 Bytes_Big_Endian
: Boolean)
1781 procedure List_Attr
(Attr_Name
: String; Is_Reversed
: Boolean);
1782 -- Show attribute definition clause for Attr_Name (an endianness
1783 -- attribute), depending on whether or not the endianness is reversed
1784 -- compared to native endianness.
1790 procedure List_Attr
(Attr_Name
: String; Is_Reversed
: Boolean) is
1792 if List_Representation_Info_To_JSON
then
1795 Write_Str
(Attr_Name
);
1796 Write_Str
(""": ""System.");
1801 Write_Str
(Attr_Name
);
1802 Write_Str
(" use System.");
1805 if Bytes_Big_Endian
xor Is_Reversed
then
1811 Write_Str
("_Order_First");
1812 if List_Representation_Info_To_JSON
then
1819 List_SSO
: constant Boolean :=
1820 Has_Rep_Item
(Ent
, Name_Scalar_Storage_Order
)
1821 or else SSO_Set_Low_By_Default
(Ent
)
1822 or else SSO_Set_High_By_Default
(Ent
);
1823 -- Scalar_Storage_Order is displayed if specified explicitly or set by
1824 -- Default_Scalar_Storage_Order.
1826 -- Start of processing for List_Scalar_Storage_Order
1829 -- For record types, list Bit_Order if not default, or if SSO is shown
1831 -- Also, when -gnatR4 is in effect always list bit order and scalar
1832 -- storage order explicitly, so that you don't need to know the native
1833 -- endianness of the target for which the output was produced in order
1836 if Is_Record_Type
(Ent
)
1838 or else Reverse_Bit_Order
(Ent
)
1839 or else List_Representation_Info
= 4)
1841 List_Attr
("Bit_Order", Reverse_Bit_Order
(Ent
));
1844 -- List SSO if required. If not, then storage is supposed to be in
1847 if List_SSO
or else List_Representation_Info
= 4 then
1848 List_Attr
("Scalar_Storage_Order", Reverse_Storage_Order
(Ent
));
1850 pragma Assert
(not Reverse_Storage_Order
(Ent
));
1853 end List_Scalar_Storage_Order
;
1855 --------------------------
1856 -- List_Subprogram_Info --
1857 --------------------------
1859 procedure List_Subprogram_Info
(Ent
: Entity_Id
) is
1860 First
: Boolean := True;
1867 if List_Representation_Info_To_JSON
then
1869 Write_Str
(" ""name"": """);
1872 List_Location
(Ent
);
1874 Write_Str
(" ""Convention"": """);
1878 Write_Str
("function ");
1881 Write_Str
("operator ");
1884 Write_Str
("procedure ");
1886 when E_Subprogram_Type
=>
1887 Write_Str
("type ");
1892 Write_Str
("entry ");
1895 raise Program_Error
;
1899 Write_Str
(" declared at ");
1900 Write_Location
(Sloc
(Ent
));
1903 Write_Str
("convention : ");
1906 case Convention
(Ent
) is
1907 when Convention_Ada
=>
1910 when Convention_Ada_Pass_By_Copy
=>
1911 Write_Str
("Ada_Pass_By_Copy");
1913 when Convention_Ada_Pass_By_Reference
=>
1914 Write_Str
("Ada_Pass_By_Reference");
1916 when Convention_Intrinsic
=>
1917 Write_Str
("Intrinsic");
1919 when Convention_Entry
=>
1920 Write_Str
("Entry");
1922 when Convention_Protected
=>
1923 Write_Str
("Protected");
1925 when Convention_Assembler
=>
1926 Write_Str
("Assembler");
1928 when Convention_C
=>
1931 when Convention_C_Variadic
=>
1934 Convention_Id
'Pos (Convention
(Ent
)) -
1935 Convention_Id
'Pos (Convention_C_Variadic_0
);
1937 Write_Str
("C_Variadic_");
1942 pragma Assert
(N
< 10);
1943 Write_Char
(Character'Val (Character'Pos ('0') + N
));
1946 when Convention_COBOL
=>
1947 Write_Str
("COBOL");
1949 when Convention_CPP
=>
1952 when Convention_Fortran
=>
1953 Write_Str
("Fortran");
1955 when Convention_Stdcall
=>
1956 Write_Str
("Stdcall");
1958 when Convention_Stubbed
=>
1959 Write_Str
("Stubbed");
1962 if List_Representation_Info_To_JSON
then
1964 Write_Str
(" ""formal"": [");
1969 -- Find max length of formal name
1972 Form
:= First_Formal
(Ent
);
1973 while Present
(Form
) loop
1974 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
1976 if Name_Len
> Plen
then
1983 -- Output formals and mechanisms
1985 Form
:= First_Formal
(Ent
);
1986 while Present
(Form
) loop
1987 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
1988 Set_Casing
(Unit_Casing
);
1990 if List_Representation_Info_To_JSON
then
1999 Write_Str
(" ""name"": """);
2000 Write_Str
(Name_Buffer
(1 .. Name_Len
));
2003 Write_Str
(" ""mechanism"": """);
2004 Write_Mechanism
(Mechanism
(Form
));
2008 while Name_Len
<= Plen
loop
2009 Name_Len
:= Name_Len
+ 1;
2010 Name_Buffer
(Name_Len
) := ' ';
2014 Write_Str
(Name_Buffer
(1 .. Plen
+ 1));
2015 Write_Str
(": passed by ");
2017 Write_Mechanism
(Mechanism
(Form
));
2024 if List_Representation_Info_To_JSON
then
2029 if Ekind
(Ent
) = E_Function
then
2030 if List_Representation_Info_To_JSON
then
2032 Write_Str
(" ""mechanism"": """);
2033 Write_Mechanism
(Mechanism
(Ent
));
2036 Write_Str
("returns by ");
2037 Write_Mechanism
(Mechanism
(Ent
));
2042 if not Is_Entry
(Ent
) then
2043 List_Linker_Section
(Ent
);
2046 if List_Representation_Info_To_JSON
then
2050 end List_Subprogram_Info
;
2052 --------------------
2053 -- List_Type_Info --
2054 --------------------
2056 procedure List_Type_Info
(Ent
: Entity_Id
) is
2060 if List_Representation_Info_To_JSON
then
2064 List_Common_Type_Info
(Ent
);
2066 -- Special stuff for fixed-point
2068 if Is_Fixed_Point_Type
(Ent
) then
2070 -- Write small (always a static constant)
2072 if List_Representation_Info_To_JSON
then
2074 Write_Str
(" ""Small"": ");
2075 UR_Write_To_JSON
(Small_Value
(Ent
));
2079 Write_Str
("'Small use ");
2080 UR_Write
(Small_Value
(Ent
));
2084 -- Write range if static
2087 R
: constant Node_Id
:= Scalar_Range
(Ent
);
2090 if Nkind
(Low_Bound
(R
)) = N_Real_Literal
2092 Nkind
(High_Bound
(R
)) = N_Real_Literal
2094 if List_Representation_Info_To_JSON
then
2096 Write_Str
(" ""Range"": [ ");
2097 UR_Write_To_JSON
(Realval
(Low_Bound
(R
)));
2099 UR_Write_To_JSON
(Realval
(High_Bound
(R
)));
2104 Write_Str
("'Range use ");
2105 UR_Write
(Realval
(Low_Bound
(R
)));
2107 UR_Write
(Realval
(High_Bound
(R
)));
2114 List_Linker_Section
(Ent
);
2116 if List_Representation_Info_To_JSON
then
2122 ----------------------------
2123 -- Compile_Time_Known_Rep --
2124 ----------------------------
2126 function Compile_Time_Known_Rep
(Val
: Node_Ref_Or_Val
) return Boolean is
2128 return Present
(Val
) and then Val
>= 0;
2129 end Compile_Time_Known_Rep
;
2135 function Rep_Value
(Val
: Node_Ref_Or_Val
; D
: Discrim_List
) return Uint
is
2137 function B
(Val
: Boolean) return Ubool
;
2138 -- Returns Uint_0 for False, Uint_1 for True
2140 function T
(Val
: Node_Ref_Or_Val
) return Boolean;
2141 -- Returns True for 0, False for any non-zero (i.e. True)
2143 function V
(Val
: Node_Ref_Or_Val
) return Uint
;
2144 -- Internal recursive routine to evaluate tree
2146 function W
(Val
: Uint
) return Word
;
2147 -- Convert Val to Word, assuming Val is always in the Int range. This
2148 -- is a helper function for the evaluation of bitwise expressions like
2149 -- Bit_And_Expr, for which there is no direct support in uintp. Uint
2150 -- values out of the Int range are expected to be seen in such
2151 -- expressions only with overflowing byte sizes around, introducing
2152 -- inherent unreliabilities in computations anyway.
2158 function B
(Val
: Boolean) return Ubool
is
2171 function T
(Val
: Node_Ref_Or_Val
) return Boolean is
2184 function V
(Val
: Node_Ref_Or_Val
) return Uint
is
2193 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
2198 if T
(Node
.Op1
) then
2199 return V
(Node
.Op2
);
2201 return V
(Node
.Op3
);
2205 return V
(Node
.Op1
) + V
(Node
.Op2
);
2208 return V
(Node
.Op1
) - V
(Node
.Op2
);
2211 return V
(Node
.Op1
) * V
(Node
.Op2
);
2213 when Trunc_Div_Expr
=>
2214 return V
(Node
.Op1
) / V
(Node
.Op2
);
2216 when Ceil_Div_Expr
=>
2219 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
2221 when Floor_Div_Expr
=>
2224 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
2226 when Trunc_Mod_Expr
=>
2227 return V
(Node
.Op1
) rem V
(Node
.Op2
);
2229 when Floor_Mod_Expr
=>
2230 return V
(Node
.Op1
) mod V
(Node
.Op2
);
2232 when Ceil_Mod_Expr
=>
2235 Q
:= UR_Ceiling
(L
/ UR_From_Uint
(R
));
2238 when Exact_Div_Expr
=>
2239 return V
(Node
.Op1
) / V
(Node
.Op2
);
2242 return -V
(Node
.Op1
);
2245 return UI_Min
(V
(Node
.Op1
), V
(Node
.Op2
));
2248 return UI_Max
(V
(Node
.Op1
), V
(Node
.Op2
));
2251 return UI_Abs
(V
(Node
.Op1
));
2253 when Truth_And_Expr
=>
2254 return B
(T
(Node
.Op1
) and then T
(Node
.Op2
));
2256 when Truth_Or_Expr
=>
2257 return B
(T
(Node
.Op1
) or else T
(Node
.Op2
));
2259 when Truth_Xor_Expr
=>
2260 return B
(T
(Node
.Op1
) xor T
(Node
.Op2
));
2262 when Truth_Not_Expr
=>
2263 return B
(not T
(Node
.Op1
));
2265 when Bit_And_Expr
=>
2268 return UI_From_Int
(Int
(W
(L
) and W
(R
)));
2271 return B
(V
(Node
.Op1
) < V
(Node
.Op2
));
2274 return B
(V
(Node
.Op1
) <= V
(Node
.Op2
));
2277 return B
(V
(Node
.Op1
) > V
(Node
.Op2
));
2280 return B
(V
(Node
.Op1
) >= V
(Node
.Op2
));
2283 return B
(V
(Node
.Op1
) = V
(Node
.Op2
));
2286 return B
(V
(Node
.Op1
) /= V
(Node
.Op2
));
2290 Sub
: constant Int
:= UI_To_Int
(Node
.Op1
);
2292 pragma Assert
(Sub
in D
'Range);
2307 -- We use an unchecked conversion to map Int values to their Word
2308 -- bitwise equivalent, which we could not achieve with a normal type
2309 -- conversion for negative Ints. We want bitwise equivalents because W
2310 -- is used as a helper for bit operators like Bit_And_Expr, and can be
2311 -- called for negative Ints in the context of aligning expressions like
2312 -- X+Align & -Align.
2314 function W
(Val
: Uint
) return Word
is
2315 function To_Word
is new Ada
.Unchecked_Conversion
(Int
, Word
);
2317 return To_Word
(UI_To_Int
(Val
));
2320 -- Start of processing for Rep_Value
2335 procedure Spaces
(N
: Natural) is
2337 for J
in 1 .. N
loop
2342 ---------------------
2343 -- Write_Info_Line --
2344 ---------------------
2346 procedure Write_Info_Line
(S
: String) is
2348 Write_Repinfo_Line
(S
(S
'First .. S
'Last - 1));
2349 end Write_Info_Line
;
2351 ---------------------
2352 -- Write_Mechanism --
2353 ---------------------
2355 procedure Write_Mechanism
(M
: Mechanism_Type
) is
2359 Write_Str
("default");
2365 Write_Str
("reference");
2368 raise Program_Error
;
2370 end Write_Mechanism
;
2372 ---------------------
2373 -- Write_Separator --
2374 ---------------------
2376 procedure Write_Separator
is
2378 if Need_Separator
then
2379 if List_Representation_Info_To_JSON
then
2385 Need_Separator
:= True;
2387 end Write_Separator
;
2389 -----------------------
2390 -- Write_Unknown_Val --
2391 -----------------------
2393 procedure Write_Unknown_Val
is
2395 if List_Representation_Info_To_JSON
then
2396 Write_Str
("""??""");
2400 end Write_Unknown_Val
;
2406 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False) is
2408 if Compile_Time_Known_Rep
(Val
) then
2409 UI_Write
(Val
, Decimal
);
2410 elsif List_Representation_Info
< 3 or else No
(Val
) then
2417 List_GCC_Expression
(Val
);