1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2020, 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
;
32 with Namet
; use Namet
;
33 with Nlists
; use Nlists
;
35 with Output
; use Output
;
36 with Sem_Aux
; use Sem_Aux
;
37 with Sem_Eval
; use Sem_Eval
;
38 with Sinfo
; use Sinfo
;
39 with Sinput
; use Sinput
;
40 with Snames
; use Snames
;
41 with Stringt
; use Stringt
;
44 with Uname
; use Uname
;
45 with Urealp
; use Urealp
;
47 with Ada
.Unchecked_Conversion
;
51 package body Repinfo
is
53 SSU
: Pos
renames Ttypes
.System_Storage_Unit
;
54 -- Value for Storage_Unit
56 ---------------------------------------
57 -- Representation of GCC Expressions --
58 ---------------------------------------
60 -- A table internal to this unit is used to hold the values of back
61 -- annotated expressions.
63 -- Node values are stored as Uint values using the negative of the node
64 -- index in this table. Constants appear as non-negative Uint values.
66 type Exp_Node
is record
68 Op1
: Node_Ref_Or_Val
;
69 Op2
: Node_Ref_Or_Val
;
70 Op3
: Node_Ref_Or_Val
;
73 -- The following representation clause ensures that the above record
74 -- has no holes. We do this so that when instances of this record are
75 -- written, we do not write uninitialized values to the file.
77 for Exp_Node
use record
78 Expr
at 0 range 0 .. 31;
79 Op1
at 4 range 0 .. 31;
80 Op2
at 8 range 0 .. 31;
81 Op3
at 12 range 0 .. 31;
84 for Exp_Node
'Size use 16 * 8;
85 -- This ensures that we did not leave out any fields
87 package Rep_Table
is new Table
.Table
(
88 Table_Component_Type
=> Exp_Node
,
89 Table_Index_Type
=> Nat
,
91 Table_Initial
=> Alloc
.Rep_Table_Initial
,
92 Table_Increment
=> Alloc
.Rep_Table_Increment
,
93 Table_Name
=> "BE_Rep_Table");
95 --------------------------------------------------------------
96 -- Representation of Front-End Dynamic Size/Offset Entities --
97 --------------------------------------------------------------
99 package Dynamic_SO_Entity_Table
is new Table
.Table
(
100 Table_Component_Type
=> Entity_Id
,
101 Table_Index_Type
=> Nat
,
102 Table_Low_Bound
=> 1,
103 Table_Initial
=> Alloc
.Rep_Table_Initial
,
104 Table_Increment
=> Alloc
.Rep_Table_Increment
,
105 Table_Name
=> "FE_Rep_Table");
107 Unit_Casing
: Casing_Type
;
108 -- Identifier casing for current unit. This is set by List_Rep_Info for
109 -- each unit, before calling subprograms which may read it.
111 Need_Separator
: Boolean;
112 -- Set True if a separator is needed before outputting any information for
113 -- the current entity.
115 ------------------------------
116 -- Set of Relevant Entities --
117 ------------------------------
119 Relevant_Entities_Size
: constant := 4093;
120 -- Number of headers in hash table
122 subtype Entity_Header_Num
is Integer range 0 .. Relevant_Entities_Size
- 1;
123 -- Range of headers in hash table
125 function Entity_Hash
(Id
: Entity_Id
) return Entity_Header_Num
;
126 -- Simple hash function for Entity_Ids
128 package Relevant_Entities
is new GNAT
.Htable
.Simple_HTable
129 (Header_Num
=> Entity_Header_Num
,
135 -- Hash table to record which compiler-generated entities are relevant
137 -----------------------
138 -- Local Subprograms --
139 -----------------------
141 function Back_End_Layout
return Boolean;
142 -- Test for layout mode, True = back end, False = front end. This function
143 -- is used rather than checking the configuration parameter because we do
144 -- not want Repinfo to depend on Targparm.
146 procedure List_Entities
148 Bytes_Big_Endian
: Boolean;
149 In_Subprogram
: Boolean := False);
150 -- This procedure lists the entities associated with the entity E, starting
151 -- with the First_Entity and using the Next_Entity link. If a nested
152 -- package is found, entities within the package are recursively processed.
153 -- When recursing within a subprogram body, Is_Subprogram suppresses
154 -- duplicate information about signature.
156 procedure List_Name
(Ent
: Entity_Id
);
157 -- List name of entity Ent in appropriate case. The name is listed with
158 -- full qualification up to but not including the compilation unit name.
160 procedure List_Array_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean);
161 -- List representation info for array type Ent
163 procedure List_Common_Type_Info
(Ent
: Entity_Id
);
164 -- List common type info (name, size, alignment) for type Ent
166 procedure List_Linker_Section
(Ent
: Entity_Id
);
167 -- List linker section for Ent (caller has checked that Ent is an entity
168 -- for which the Linker_Section_Pragma field is defined).
170 procedure List_Location
(Ent
: Entity_Id
);
171 -- List location information for Ent
173 procedure List_Object_Info
(Ent
: Entity_Id
);
174 -- List representation info for object Ent
176 procedure List_Record_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean);
177 -- List representation info for record type Ent
179 procedure List_Scalar_Storage_Order
181 Bytes_Big_Endian
: Boolean);
182 -- List scalar storage order information for record or array type Ent.
183 -- Also includes bit order information for record types, if necessary.
185 procedure List_Subprogram_Info
(Ent
: Entity_Id
);
186 -- List subprogram info for subprogram Ent
188 procedure List_Type_Info
(Ent
: Entity_Id
);
189 -- List type info for type Ent
191 function Rep_Not_Constant
(Val
: Node_Ref_Or_Val
) return Boolean;
192 -- Returns True if Val represents a variable value, and False if it
193 -- represents a value that is fixed at compile time.
195 procedure Spaces
(N
: Natural);
196 -- Output given number of spaces
198 procedure Write_Info_Line
(S
: String);
199 -- Routine to write a line to Repinfo output file. This routine is passed
200 -- as a special output procedure to Output.Set_Special_Output. Note that
201 -- Write_Info_Line is called with an EOL character at the end of each line,
202 -- as per the Output spec, but the internal call to the appropriate routine
203 -- in Osint requires that the end of line sequence be stripped off.
205 procedure Write_Mechanism
(M
: Mechanism_Type
);
206 -- Writes symbolic string for mechanism represented by M
208 procedure Write_Separator
;
209 -- Called before outputting anything for an entity. Ensures that
210 -- a separator precedes the output for a particular entity.
212 procedure Write_Unknown_Val
;
213 -- Writes symbolic string for an unknown or non-representable value
215 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False);
216 -- Given a representation value, write it out. No_Uint values or values
217 -- dependent on discriminants are written as two question marks. If the
218 -- flag Paren is set, then the output is surrounded in parentheses if it is
219 -- other than a simple value.
221 ---------------------
222 -- Back_End_Layout --
223 ---------------------
225 function Back_End_Layout
return Boolean is
227 -- We have back-end layout if the back end has made any entries in the
228 -- table of GCC expressions, otherwise we have front-end layout.
230 return Rep_Table
.Last
> 0;
233 ------------------------
234 -- Create_Discrim_Ref --
235 ------------------------
237 function Create_Discrim_Ref
(Discr
: Entity_Id
) return Node_Ref
is
240 (Expr
=> Discrim_Val
,
241 Op1
=> Discriminant_Number
(Discr
));
242 end Create_Discrim_Ref
;
244 ---------------------------
245 -- Create_Dynamic_SO_Ref --
246 ---------------------------
248 function Create_Dynamic_SO_Ref
(E
: Entity_Id
) return Dynamic_SO_Ref
is
250 Dynamic_SO_Entity_Table
.Append
(E
);
251 return UI_From_Int
(-Dynamic_SO_Entity_Table
.Last
);
252 end Create_Dynamic_SO_Ref
;
260 Op1
: Node_Ref_Or_Val
;
261 Op2
: Node_Ref_Or_Val
:= No_Uint
;
262 Op3
: Node_Ref_Or_Val
:= No_Uint
) return Node_Ref
270 return UI_From_Int
(-Rep_Table
.Last
);
277 function Entity_Hash
(Id
: Entity_Id
) return Entity_Header_Num
is
279 return Entity_Header_Num
(Id
mod Relevant_Entities_Size
);
282 ---------------------------
283 -- Get_Dynamic_SO_Entity --
284 ---------------------------
286 function Get_Dynamic_SO_Entity
(U
: Dynamic_SO_Ref
) return Entity_Id
is
288 return Dynamic_SO_Entity_Table
.Table
(-UI_To_Int
(U
));
289 end Get_Dynamic_SO_Entity
;
291 -----------------------
292 -- Is_Dynamic_SO_Ref --
293 -----------------------
295 function Is_Dynamic_SO_Ref
(U
: SO_Ref
) return Boolean is
298 end Is_Dynamic_SO_Ref
;
300 ----------------------
301 -- Is_Static_SO_Ref --
302 ----------------------
304 function Is_Static_SO_Ref
(U
: SO_Ref
) return Boolean is
307 end Is_Static_SO_Ref
;
313 procedure lgx
(U
: Node_Ref_Or_Val
) is
315 List_GCC_Expression
(U
);
319 ----------------------
320 -- List_Array_Info --
321 ----------------------
323 procedure List_Array_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean) is
327 if List_Representation_Info_To_JSON
then
331 List_Common_Type_Info
(Ent
);
333 if List_Representation_Info_To_JSON
then
335 Write_Str
(" ""Component_Size"": ");
336 Write_Val
(Component_Size
(Ent
));
340 Write_Str
("'Component_Size use ");
341 Write_Val
(Component_Size
(Ent
));
345 List_Scalar_Storage_Order
(Ent
, Bytes_Big_Endian
);
347 List_Linker_Section
(Ent
);
349 if List_Representation_Info_To_JSON
then
354 -- The component type is relevant for an array
356 if List_Representation_Info
= 4
357 and then Is_Itype
(Component_Type
(Base_Type
(Ent
)))
359 Relevant_Entities
.Set
(Component_Type
(Base_Type
(Ent
)), True);
363 ---------------------------
364 -- List_Common_Type_Info --
365 ---------------------------
367 procedure List_Common_Type_Info
(Ent
: Entity_Id
) is
369 if List_Representation_Info_To_JSON
then
370 Write_Str
(" ""name"": """);
376 -- Do not list size info for unconstrained arrays, not meaningful
378 if Is_Array_Type
(Ent
) and then not Is_Constrained
(Ent
) then
382 -- If Esize and RM_Size are the same, list as Size. This is a common
383 -- case, which we may as well list in simple form.
385 if Esize
(Ent
) = RM_Size
(Ent
) then
386 if List_Representation_Info_To_JSON
then
387 Write_Str
(" ""Size"": ");
388 Write_Val
(Esize
(Ent
));
393 Write_Str
("'Size use ");
394 Write_Val
(Esize
(Ent
));
398 -- Otherwise list size values separately
401 if List_Representation_Info_To_JSON
then
402 Write_Str
(" ""Object_Size"": ");
403 Write_Val
(Esize
(Ent
));
406 Write_Str
(" ""Value_Size"": ");
407 Write_Val
(RM_Size
(Ent
));
413 Write_Str
("'Object_Size use ");
414 Write_Val
(Esize
(Ent
));
419 Write_Str
("'Value_Size use ");
420 Write_Val
(RM_Size
(Ent
));
426 if List_Representation_Info_To_JSON
then
427 Write_Str
(" ""Alignment"": ");
428 Write_Val
(Alignment
(Ent
));
432 Write_Str
("'Alignment use ");
433 Write_Val
(Alignment
(Ent
));
436 end List_Common_Type_Info
;
442 procedure List_Entities
444 Bytes_Big_Endian
: Boolean;
445 In_Subprogram
: Boolean := False)
450 function Find_Declaration
(E
: Entity_Id
) return Node_Id
;
451 -- Utility to retrieve declaration node for entity in the
452 -- case of package bodies and subprograms.
454 ----------------------
455 -- Find_Declaration --
456 ----------------------
458 function Find_Declaration
(E
: Entity_Id
) return Node_Id
is
464 and then Nkind
(Decl
) /= N_Package_Body
465 and then Nkind
(Decl
) /= N_Subprogram_Declaration
466 and then Nkind
(Decl
) /= N_Subprogram_Body
468 Decl
:= Parent
(Decl
);
472 end Find_Declaration
;
474 -- Start of processing for List_Entities
477 -- List entity if we have one, and it is not a renaming declaration.
478 -- For renamings, we don't get proper information, and really it makes
479 -- sense to restrict the output to the renamed entity.
482 and then Nkind
(Declaration_Node
(Ent
)) not in N_Renaming_Declaration
483 and then not Is_Ignored_Ghost_Entity
(Ent
)
485 -- If entity is a subprogram and we are listing mechanisms,
486 -- then we need to list mechanisms for this entity. We skip this
487 -- if it is a nested subprogram, as the information has already
488 -- been produced when listing the enclosing scope.
490 if List_Representation_Info_Mechanisms
491 and then (Is_Subprogram
(Ent
)
492 or else Ekind
(Ent
) = E_Entry
493 or else Ekind
(Ent
) = E_Entry_Family
)
494 and then not In_Subprogram
496 List_Subprogram_Info
(Ent
);
499 E
:= First_Entity
(Ent
);
500 while Present
(E
) loop
501 -- We list entities that come from source (excluding private or
502 -- incomplete types or deferred constants, for which we will list
503 -- the information for the full view). If requested, we also list
504 -- relevant entities that have been generated when processing the
505 -- original entities coming from source. But if debug flag A is
506 -- set, then all entities are listed.
508 if ((Comes_From_Source
(E
)
509 or else (Ekind
(E
) = E_Block
511 Nkind
(Parent
(E
)) = N_Implicit_Label_Declaration
513 Comes_From_Source
(Label_Construct
(Parent
(E
)))))
514 and then not Is_Incomplete_Or_Private_Type
(E
)
515 and then not (Ekind
(E
) = E_Constant
516 and then Present
(Full_View
(E
))))
517 or else (List_Representation_Info
= 4
518 and then Relevant_Entities
.Get
(E
))
519 or else Debug_Flag_AA
521 if Is_Subprogram
(E
) then
522 if List_Representation_Info_Mechanisms
then
523 List_Subprogram_Info
(E
);
526 -- Recurse into entities local to subprogram
528 List_Entities
(E
, Bytes_Big_Endian
, True);
530 elsif Ekind
(E
) in E_Entry
534 if List_Representation_Info_Mechanisms
then
535 List_Subprogram_Info
(E
);
538 elsif Is_Record_Type
(E
) then
539 if List_Representation_Info
>= 1 then
540 List_Record_Info
(E
, Bytes_Big_Endian
);
543 -- Recurse into entities local to a record type
545 if List_Representation_Info
= 4 then
546 List_Entities
(E
, Bytes_Big_Endian
, False);
549 elsif Is_Array_Type
(E
) then
550 if List_Representation_Info
>= 1 then
551 List_Array_Info
(E
, Bytes_Big_Endian
);
554 elsif Is_Type
(E
) then
555 if List_Representation_Info
>= 2 then
559 -- Note that formals are not annotated so we skip them here
561 elsif Ekind
(E
) in E_Constant
565 if List_Representation_Info
>= 2 then
566 List_Object_Info
(E
);
570 -- Recurse into nested package, but not if they are package
571 -- renamings (in particular renamings of the enclosing package,
572 -- as for some Java bindings and for generic instances).
574 if Ekind
(E
) = E_Package
then
575 if No
(Renamed_Object
(E
)) then
576 List_Entities
(E
, Bytes_Big_Endian
);
579 -- Recurse into bodies
581 elsif Ekind
(E
) in E_Package_Body
588 List_Entities
(E
, Bytes_Big_Endian
);
590 -- Recurse into blocks
592 elsif Ekind
(E
) = E_Block
then
593 List_Entities
(E
, Bytes_Big_Endian
);
600 -- For a package body, the entities of the visible subprograms are
601 -- declared in the corresponding spec. Iterate over its entities in
602 -- order to handle properly the subprogram bodies. Skip bodies in
603 -- subunits, which are listed independently.
605 if Ekind
(Ent
) = E_Package_Body
606 and then Present
(Corresponding_Spec
(Find_Declaration
(Ent
)))
608 E
:= First_Entity
(Corresponding_Spec
(Find_Declaration
(Ent
)));
609 while Present
(E
) loop
612 Nkind
(Find_Declaration
(E
)) = N_Subprogram_Declaration
614 Body_E
:= Corresponding_Body
(Find_Declaration
(E
));
618 Nkind
(Parent
(Find_Declaration
(Body_E
))) /= N_Subunit
620 List_Entities
(Body_E
, Bytes_Big_Endian
);
630 -------------------------
631 -- List_GCC_Expression --
632 -------------------------
634 procedure List_GCC_Expression
(U
: Node_Ref_Or_Val
) is
636 procedure Print_Expr
(Val
: Node_Ref_Or_Val
);
637 -- Internal recursive procedure to print expression
643 procedure Print_Expr
(Val
: Node_Ref_Or_Val
) is
646 UI_Write
(Val
, Decimal
);
650 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
652 procedure Unop
(S
: String);
653 -- Output text for unary operator with S being operator name
655 procedure Binop
(S
: String);
656 -- Output text for binary operator with S being operator name
662 procedure Unop
(S
: String) is
664 if List_Representation_Info_To_JSON
then
665 Write_Str
("{ ""code"": """);
666 if S
(S
'Last) = ' ' then
667 Write_Str
(S
(S
'First .. S
'Last - 1));
671 Write_Str
(""", ""operands"": [ ");
672 Print_Expr
(Node
.Op1
);
676 Print_Expr
(Node
.Op1
);
684 procedure Binop
(S
: String) is
686 if List_Representation_Info_To_JSON
then
687 Write_Str
("{ ""code"": """);
688 Write_Str
(S
(S
'First + 1 .. S
'Last - 1));
689 Write_Str
(""", ""operands"": [ ");
690 Print_Expr
(Node
.Op1
);
692 Print_Expr
(Node
.Op2
);
696 Print_Expr
(Node
.Op1
);
698 Print_Expr
(Node
.Op2
);
703 -- Start of processing for Print_Expr
708 if List_Representation_Info_To_JSON
then
709 Write_Str
("{ ""code"": ""?<>""");
710 Write_Str
(", ""operands"": [ ");
711 Print_Expr
(Node
.Op1
);
713 Print_Expr
(Node
.Op2
);
715 Print_Expr
(Node
.Op3
);
719 Print_Expr
(Node
.Op1
);
720 Write_Str
(" then ");
721 Print_Expr
(Node
.Op2
);
722 Write_Str
(" else ");
723 Print_Expr
(Node
.Op3
);
736 when Trunc_Div_Expr
=>
739 when Ceil_Div_Expr
=>
742 when Floor_Div_Expr
=>
745 when Trunc_Mod_Expr
=>
748 when Ceil_Mod_Expr
=>
751 when Floor_Mod_Expr
=>
754 when Exact_Div_Expr
=>
769 when Truth_And_Expr
=>
772 when Truth_Or_Expr
=>
775 when Truth_Xor_Expr
=>
778 when Truth_Not_Expr
=>
812 -- Start of processing for List_GCC_Expression
820 end List_GCC_Expression
;
822 -------------------------
823 -- List_Linker_Section --
824 -------------------------
826 procedure List_Linker_Section
(Ent
: Entity_Id
) is
831 if Present
(Linker_Section_Pragma
(Ent
)) then
832 Args
:= Pragma_Argument_Associations
(Linker_Section_Pragma
(Ent
));
833 Sect
:= Expr_Value_S
(Get_Pragma_Arg
(Last
(Args
)));
835 if List_Representation_Info_To_JSON
then
837 Write_Str
(" ""Linker_Section"": """);
839 Write_Str
("pragma Linker_Section (");
844 pragma Assert
(Nkind
(Sect
) = N_String_Literal
);
845 String_To_Name_Buffer
(Strval
(Sect
));
846 Write_Str
(Name_Buffer
(1 .. Name_Len
));
848 if not List_Representation_Info_To_JSON
then
852 end List_Linker_Section
;
858 procedure List_Location
(Ent
: Entity_Id
) is
860 pragma Assert
(List_Representation_Info_To_JSON
);
861 Write_Str
(" ""location"": """);
862 Write_Location
(Sloc
(Ent
));
870 procedure List_Name
(Ent
: Entity_Id
) is
874 -- List the qualified name recursively, except
875 -- at compilation unit level in default mode.
877 if Is_Compilation_Unit
(Ent
) then
879 elsif not Is_Compilation_Unit
(Scope
(Ent
))
880 or else List_Representation_Info_To_JSON
882 List_Name
(Scope
(Ent
));
886 Get_Unqualified_Decoded_Name_String
(Chars
(Ent
));
887 Set_Casing
(Unit_Casing
);
889 -- The name of operators needs to be properly escaped for JSON
891 for J
in 1 .. Name_Len
loop
892 C
:= Name_Buffer
(J
);
893 if C
= '"' and then List_Representation_Info_To_JSON
then
900 ---------------------
901 -- List_Object_Info --
902 ---------------------
904 procedure List_Object_Info
(Ent
: Entity_Id
) is
908 if List_Representation_Info_To_JSON
then
911 Write_Str
(" ""name"": """);
916 Write_Str
(" ""Size"": ");
917 Write_Val
(Esize
(Ent
));
920 Write_Str
(" ""Alignment"": ");
921 Write_Val
(Alignment
(Ent
));
923 List_Linker_Section
(Ent
);
930 Write_Str
("'Size use ");
931 Write_Val
(Esize
(Ent
));
936 Write_Str
("'Alignment use ");
937 Write_Val
(Alignment
(Ent
));
940 List_Linker_Section
(Ent
);
943 -- The type is relevant for an object
945 if List_Representation_Info
= 4 and then Is_Itype
(Etype
(Ent
)) then
946 Relevant_Entities
.Set
(Etype
(Ent
), True);
948 end List_Object_Info
;
950 ----------------------
951 -- List_Record_Info --
952 ----------------------
954 procedure List_Record_Info
(Ent
: Entity_Id
; Bytes_Big_Endian
: Boolean) is
955 procedure Compute_Max_Length
957 Starting_Position
: Uint
:= Uint_0
;
958 Starting_First_Bit
: Uint
:= Uint_0
;
959 Prefix_Length
: Natural := 0);
960 -- Internal recursive procedure to compute the max length
962 procedure List_Component_Layout
964 Starting_Position
: Uint
:= Uint_0
;
965 Starting_First_Bit
: Uint
:= Uint_0
;
966 Prefix
: String := "";
967 Indent
: Natural := 0);
968 -- Procedure to display the layout of a single component
970 procedure List_Record_Layout
972 Starting_Position
: Uint
:= Uint_0
;
973 Starting_First_Bit
: Uint
:= Uint_0
;
974 Prefix
: String := "");
975 -- Internal recursive procedure to display the layout
977 procedure List_Structural_Record_Layout
979 Outer_Ent
: Entity_Id
;
980 Variant
: Node_Id
:= Empty
;
981 Indent
: Natural := 0);
982 -- Internal recursive procedure to display the structural layout
984 Incomplete_Layout
: exception;
985 -- Exception raised if the layout is incomplete in -gnatc mode
987 Not_In_Extended_Main
: exception;
988 -- Exception raised when an ancestor is not declared in the main unit
990 Max_Name_Length
: Natural := 0;
991 Max_Spos_Length
: Natural := 0;
993 ------------------------
994 -- Compute_Max_Length --
995 ------------------------
997 procedure Compute_Max_Length
999 Starting_Position
: Uint
:= Uint_0
;
1000 Starting_First_Bit
: Uint
:= Uint_0
;
1001 Prefix_Length
: Natural := 0)
1006 Comp
:= First_Component_Or_Discriminant
(Ent
);
1007 while Present
(Comp
) loop
1009 -- Skip a completely hidden discriminant or a discriminant in an
1010 -- unchecked union (since it is not there).
1012 if Ekind
(Comp
) = E_Discriminant
1013 and then (Is_Completely_Hidden
(Comp
)
1014 or else Is_Unchecked_Union
(Ent
))
1019 -- Skip _Parent component in extension (to avoid overlap)
1021 if Chars
(Comp
) = Name_uParent
then
1028 Ctyp
: constant Entity_Id
:= Underlying_Type
(Etype
(Comp
));
1029 Bofs
: constant Uint
:= Component_Bit_Offset
(Comp
);
1035 Name_Length
: Natural;
1038 Get_Decoded_Name_String
(Chars
(Comp
));
1039 Name_Length
:= Prefix_Length
+ Name_Len
;
1041 if Rep_Not_Constant
(Bofs
) then
1043 -- If the record is not packed, then we know that all fields
1044 -- whose position is not specified have starting normalized
1045 -- bit position of zero.
1047 if Unknown_Normalized_First_Bit
(Comp
)
1048 and then not Is_Packed
(Ent
)
1050 Set_Normalized_First_Bit
(Comp
, Uint_0
);
1053 UI_Image_Length
:= 2; -- For "??" marker
1056 Fbit
:= Bofs
mod SSU
;
1058 -- Complete annotation in case not done
1060 if Unknown_Normalized_First_Bit
(Comp
) then
1061 Set_Normalized_Position
(Comp
, Npos
);
1062 Set_Normalized_First_Bit
(Comp
, Fbit
);
1065 Spos
:= Starting_Position
+ Npos
;
1066 Sbit
:= Starting_First_Bit
+ Fbit
;
1073 -- If extended information is requested, recurse fully into
1074 -- record components, i.e. skip the outer level.
1076 if List_Representation_Info_Extended
1077 and then Is_Record_Type
(Ctyp
)
1079 Compute_Max_Length
(Ctyp
, Spos
, Sbit
, Name_Length
+ 1);
1086 Max_Name_Length
:= Natural'Max (Max_Name_Length
, Name_Length
);
1088 Natural'Max (Max_Spos_Length
, UI_Image_Length
);
1092 Next_Component_Or_Discriminant
(Comp
);
1094 end Compute_Max_Length
;
1096 ---------------------------
1097 -- List_Component_Layout --
1098 ---------------------------
1100 procedure List_Component_Layout
1102 Starting_Position
: Uint
:= Uint_0
;
1103 Starting_First_Bit
: Uint
:= Uint_0
;
1104 Prefix
: String := "";
1105 Indent
: Natural := 0)
1107 Esiz
: constant Uint
:= Esize
(Ent
);
1108 Npos
: constant Uint
:= Normalized_Position
(Ent
);
1109 Fbit
: constant Uint
:= Normalized_First_Bit
(Ent
);
1115 if List_Representation_Info_To_JSON
then
1119 Write_Str
(" ""name"": """);
1121 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1123 if Ekind
(Ent
) = E_Discriminant
then
1125 Write_Str
(" ""discriminant"": ");
1126 UI_Write
(Discriminant_Number
(Ent
), Decimal
);
1130 Write_Str
(" ""Position"": ");
1134 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1135 Spaces
(Max_Name_Length
- Prefix
'Length - Name_Len
);
1139 if Known_Static_Normalized_Position
(Ent
) then
1140 Spos
:= Starting_Position
+ Npos
;
1141 Sbit
:= Starting_First_Bit
+ Fbit
;
1148 Spaces
(Max_Spos_Length
- UI_Image_Length
);
1149 Write_Str
(UI_Image_Buffer
(1 .. UI_Image_Length
));
1151 elsif Known_Normalized_Position
(Ent
)
1152 and then List_Representation_Info
>= 3
1154 Spaces
(Max_Spos_Length
- 2);
1156 if Starting_Position
/= Uint_0
then
1157 UI_Write
(Starting_Position
, Decimal
);
1167 if List_Representation_Info_To_JSON
then
1170 Write_Str
(" ""First_Bit"": ");
1172 Write_Str
(" range ");
1175 Sbit
:= Starting_First_Bit
+ Fbit
;
1181 UI_Write
(Sbit
, Decimal
);
1183 if List_Representation_Info_To_JSON
then
1186 Write_Str
(" ""Size"": ");
1191 -- Allowing Uint_0 here is an annoying special case. Really this
1192 -- should be a fine Esize value but currently it means unknown,
1193 -- except that we know after gigi has back annotated that a size
1194 -- of zero is real, since otherwise gigi back annotates using
1195 -- No_Uint as the value to indicate unknown.
1197 if (Esize
(Ent
) = Uint_0
or else Known_Static_Esize
(Ent
))
1198 and then Known_Static_Normalized_First_Bit
(Ent
)
1200 Lbit
:= Sbit
+ Esiz
- 1;
1202 if List_Representation_Info_To_JSON
then
1203 UI_Write
(Esiz
, Decimal
);
1205 if Lbit
>= 0 and then Lbit
< 10 then
1209 UI_Write
(Lbit
, Decimal
);
1212 -- The test for Esize (Ent) not Uint_0 here is an annoying special
1213 -- case. Officially a value of zero for Esize means unknown, but
1214 -- here we use the fact that we know that gigi annotates Esize with
1215 -- No_Uint, not Uint_0. Really everyone should use No_Uint???
1217 elsif List_Representation_Info
< 3
1218 or else (Esize
(Ent
) /= Uint_0
and then Unknown_Esize
(Ent
))
1222 -- List_Representation >= 3 and Known_Esize (Ent)
1225 Write_Val
(Esiz
, Paren
=> not List_Representation_Info_To_JSON
);
1227 -- If in front-end layout mode, then dynamic size is stored in
1228 -- storage units, so renormalize for output.
1230 if not Back_End_Layout
then
1235 -- Add appropriate first bit offset
1237 if not List_Representation_Info_To_JSON
then
1246 Write_Int
(UI_To_Int
(Sbit
) - 1);
1251 if List_Representation_Info_To_JSON
then
1259 -- The type is relevant for a component
1261 if List_Representation_Info
= 4 and then Is_Itype
(Etype
(Ent
)) then
1262 Relevant_Entities
.Set
(Etype
(Ent
), True);
1264 end List_Component_Layout
;
1266 ------------------------
1267 -- List_Record_Layout --
1268 ------------------------
1270 procedure List_Record_Layout
1272 Starting_Position
: Uint
:= Uint_0
;
1273 Starting_First_Bit
: Uint
:= Uint_0
;
1274 Prefix
: String := "")
1277 First
: Boolean := True;
1280 Comp
:= First_Component_Or_Discriminant
(Ent
);
1281 while Present
(Comp
) loop
1283 -- Skip a completely hidden discriminant or a discriminant in an
1284 -- unchecked union (since it is not there).
1286 if Ekind
(Comp
) = E_Discriminant
1287 and then (Is_Completely_Hidden
(Comp
)
1288 or else Is_Unchecked_Union
(Ent
))
1293 -- Skip _Parent component in extension (to avoid overlap)
1295 if Chars
(Comp
) = Name_uParent
then
1302 Ctyp
: constant Entity_Id
:= Underlying_Type
(Etype
(Comp
));
1303 Npos
: constant Uint
:= Normalized_Position
(Comp
);
1304 Fbit
: constant Uint
:= Normalized_First_Bit
(Comp
);
1309 Get_Decoded_Name_String
(Chars
(Comp
));
1310 Set_Casing
(Unit_Casing
);
1312 -- If extended information is requested, recurse fully into
1313 -- record components, i.e. skip the outer level.
1315 if List_Representation_Info_Extended
1316 and then Is_Record_Type
(Ctyp
)
1317 and then Known_Static_Normalized_Position
(Comp
)
1318 and then Known_Static_Normalized_First_Bit
(Comp
)
1320 Spos
:= Starting_Position
+ Npos
;
1321 Sbit
:= Starting_First_Bit
+ Fbit
;
1328 List_Record_Layout
(Ctyp
,
1329 Spos
, Sbit
, Prefix
& Name_Buffer
(1 .. Name_Len
) & ".");
1334 if List_Representation_Info_To_JSON
then
1343 List_Component_Layout
(Comp
,
1344 Starting_Position
, Starting_First_Bit
, Prefix
);
1348 Next_Component_Or_Discriminant
(Comp
);
1350 end List_Record_Layout
;
1352 -----------------------------------
1353 -- List_Structural_Record_Layout --
1354 -----------------------------------
1356 procedure List_Structural_Record_Layout
1358 Outer_Ent
: Entity_Id
;
1359 Variant
: Node_Id
:= Empty
;
1360 Indent
: Natural := 0)
1362 function Derived_Discriminant
(Disc
: Entity_Id
) return Entity_Id
;
1363 -- This function assumes that Outer_Ent is an extension of Ent.
1364 -- Disc is a discriminant of Ent that does not itself constrain a
1365 -- discriminant of the parent type of Ent. Return the discriminant
1366 -- of Outer_Ent that ultimately constrains Disc, if any.
1368 ----------------------------
1369 -- Derived_Discriminant --
1370 ----------------------------
1372 function Derived_Discriminant
(Disc
: Entity_Id
) return Entity_Id
is
1373 Corr_Disc
: Entity_Id
;
1374 Derived_Disc
: Entity_Id
;
1377 Derived_Disc
:= First_Discriminant
(Outer_Ent
);
1379 -- Loop over the discriminants of the extension
1381 while Present
(Derived_Disc
) loop
1383 -- Check if this discriminant constrains another discriminant.
1384 -- If so, find the ultimately constrained discriminant and
1385 -- compare with the original components in the base type.
1387 if Present
(Corresponding_Discriminant
(Derived_Disc
)) then
1388 Corr_Disc
:= Corresponding_Discriminant
(Derived_Disc
);
1390 while Present
(Corresponding_Discriminant
(Corr_Disc
)) loop
1391 Corr_Disc
:= Corresponding_Discriminant
(Corr_Disc
);
1394 if Original_Record_Component
(Corr_Disc
) =
1395 Original_Record_Component
(Disc
)
1397 return Derived_Disc
;
1401 Next_Discriminant
(Derived_Disc
);
1404 -- Disc is not constrained by a discriminant of Outer_Ent
1407 end Derived_Discriminant
;
1409 -- Local declarations
1412 Comp_List
: Node_Id
;
1413 First
: Boolean := True;
1416 -- Start of processing for List_Structural_Record_Layout
1419 -- If we are dealing with a variant, just process the components
1421 if Present
(Variant
) then
1422 Comp_List
:= Component_List
(Variant
);
1424 -- Otherwise, we are dealing with the full record and need to get
1425 -- to its definition in order to retrieve its structural layout.
1429 Definition
: Node_Id
:=
1430 Type_Definition
(Declaration_Node
(Ent
));
1432 Is_Extension
: constant Boolean :=
1433 Is_Tagged_Type
(Ent
)
1434 and then Nkind
(Definition
) =
1435 N_Derived_Type_Definition
;
1438 Listed_Disc
: Entity_Id
;
1439 Parent_Type
: Entity_Id
;
1442 -- If this is an extension, first list the layout of the parent
1443 -- and then proceed to the extension part, if any.
1445 if Is_Extension
then
1446 Parent_Type
:= Parent_Subtype
(Ent
);
1447 if No
(Parent_Type
) then
1448 raise Incomplete_Layout
;
1451 if Is_Private_Type
(Parent_Type
) then
1452 Parent_Type
:= Full_View
(Parent_Type
);
1453 pragma Assert
(Present
(Parent_Type
));
1456 Parent_Type
:= Base_Type
(Parent_Type
);
1457 if not In_Extended_Main_Source_Unit
(Parent_Type
) then
1458 raise Not_In_Extended_Main
;
1461 List_Structural_Record_Layout
(Parent_Type
, Outer_Ent
);
1464 if Present
(Record_Extension_Part
(Definition
)) then
1465 Definition
:= Record_Extension_Part
(Definition
);
1469 -- If the record has discriminants and is not an unchecked
1470 -- union, then display them now. Note that, even if this is
1471 -- a structural layout, we list the visible discriminants.
1473 if Has_Discriminants
(Ent
)
1474 and then not Is_Unchecked_Union
(Ent
)
1476 Disc
:= First_Discriminant
(Ent
);
1477 while Present
(Disc
) loop
1479 -- If this is a record extension and the discriminant is
1480 -- the renaming of another discriminant, skip it.
1483 and then Present
(Corresponding_Discriminant
(Disc
))
1488 -- If this is the parent type of an extension, retrieve
1489 -- the derived discriminant from the extension, if any.
1491 if Ent
/= Outer_Ent
then
1492 Listed_Disc
:= Derived_Discriminant
(Disc
);
1494 if No
(Listed_Disc
) then
1498 Listed_Disc
:= Disc
;
1501 Get_Decoded_Name_String
(Chars
(Listed_Disc
));
1502 Set_Casing
(Unit_Casing
);
1511 List_Component_Layout
(Listed_Disc
, Indent
=> Indent
);
1514 Next_Discriminant
(Disc
);
1518 Comp_List
:= Component_List
(Definition
);
1522 -- Bail out for the null record
1524 if No
(Comp_List
) then
1528 -- Now deal with the regular components, if any
1530 if Present
(Component_Items
(Comp_List
)) then
1531 Comp
:= First_Non_Pragma
(Component_Items
(Comp_List
));
1532 while Present
(Comp
) loop
1534 -- Skip _Parent component in extension (to avoid overlap)
1536 if Chars
(Defining_Identifier
(Comp
)) = Name_uParent
then
1540 Get_Decoded_Name_String
(Chars
(Defining_Identifier
(Comp
)));
1541 Set_Casing
(Unit_Casing
);
1550 List_Component_Layout
1551 (Defining_Identifier
(Comp
), Indent
=> Indent
);
1554 Next_Non_Pragma
(Comp
);
1558 -- We are done if there is no variant part
1560 if No
(Variant_Part
(Comp_List
)) then
1568 Write_Str
(" ""variant"" : [");
1570 -- Otherwise we recurse on each variant
1572 Var
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
1574 while Present
(Var
) loop
1585 Write_Str
(" ""present"": ");
1586 Write_Val
(Present_Expr
(Var
));
1589 Write_Str
(" ""record"": [");
1591 List_Structural_Record_Layout
(Ent
, Outer_Ent
, Var
, Indent
+ 4);
1598 Next_Non_Pragma
(Var
);
1600 end List_Structural_Record_Layout
;
1602 -- Start of processing for List_Record_Info
1607 if List_Representation_Info_To_JSON
then
1611 List_Common_Type_Info
(Ent
);
1613 -- First find out max line length and max starting position
1614 -- length, for the purpose of lining things up nicely.
1616 Compute_Max_Length
(Ent
);
1618 -- Then do actual output based on those values
1620 if List_Representation_Info_To_JSON
then
1622 Write_Str
(" ""record"": [");
1624 -- ??? We can output structural layout only for base types fully
1625 -- declared in the extended main source unit for the time being,
1626 -- because otherwise declarations might not be processed at all.
1628 if Is_Base_Type
(Ent
) then
1630 List_Structural_Record_Layout
(Ent
, Ent
);
1633 when Incomplete_Layout
1634 | Not_In_Extended_Main
1636 List_Record_Layout
(Ent
);
1639 raise Program_Error
;
1642 List_Record_Layout
(Ent
);
1650 Write_Line
(" use record");
1652 List_Record_Layout
(Ent
);
1654 Write_Line
("end record;");
1657 List_Scalar_Storage_Order
(Ent
, Bytes_Big_Endian
);
1659 List_Linker_Section
(Ent
);
1661 if List_Representation_Info_To_JSON
then
1666 -- The type is relevant for a record subtype
1668 if List_Representation_Info
= 4
1669 and then not Is_Base_Type
(Ent
)
1670 and then Is_Itype
(Etype
(Ent
))
1672 Relevant_Entities
.Set
(Etype
(Ent
), True);
1674 end List_Record_Info
;
1680 procedure List_Rep_Info
(Bytes_Big_Endian
: Boolean) is
1684 if List_Representation_Info
/= 0
1685 or else List_Representation_Info_Mechanisms
1687 -- For the normal case, we output a single JSON stream
1689 if not List_Representation_Info_To_File
1690 and then List_Representation_Info_To_JSON
1693 Need_Separator
:= False;
1696 for U
in Main_Unit
.. Last_Unit
loop
1697 if In_Extended_Main_Source_Unit
(Cunit_Entity
(U
)) then
1698 Unit_Casing
:= Identifier_Casing
(Source_Index
(U
));
1700 if List_Representation_Info
= 4 then
1701 Relevant_Entities
.Reset
;
1704 -- Normal case, list to standard output
1706 if not List_Representation_Info_To_File
then
1707 if not List_Representation_Info_To_JSON
then
1709 Write_Str
("Representation information for unit ");
1710 Write_Unit_Name
(Unit_Name
(U
));
1714 for J
in 1 .. Col
- 1 loop
1719 Need_Separator
:= True;
1722 List_Entities
(Cunit_Entity
(U
), Bytes_Big_Endian
);
1724 -- List representation information to file
1727 Create_Repinfo_File_Access
.all
1728 (Get_Name_String
(File_Name
(Source_Index
(U
))));
1729 Set_Special_Output
(Write_Info_Line
'Access);
1730 if List_Representation_Info_To_JSON
then
1733 Need_Separator
:= False;
1734 List_Entities
(Cunit_Entity
(U
), Bytes_Big_Endian
);
1735 if List_Representation_Info_To_JSON
then
1738 Cancel_Special_Output
;
1739 Close_Repinfo_File_Access
.all;
1744 if not List_Representation_Info_To_File
1745 and then List_Representation_Info_To_JSON
1752 -------------------------------
1753 -- List_Scalar_Storage_Order --
1754 -------------------------------
1756 procedure List_Scalar_Storage_Order
1758 Bytes_Big_Endian
: Boolean)
1760 procedure List_Attr
(Attr_Name
: String; Is_Reversed
: Boolean);
1761 -- Show attribute definition clause for Attr_Name (an endianness
1762 -- attribute), depending on whether or not the endianness is reversed
1763 -- compared to native endianness.
1769 procedure List_Attr
(Attr_Name
: String; Is_Reversed
: Boolean) is
1771 if List_Representation_Info_To_JSON
then
1774 Write_Str
(Attr_Name
);
1775 Write_Str
(""": ""System.");
1780 Write_Str
(Attr_Name
);
1781 Write_Str
(" use System.");
1784 if Bytes_Big_Endian
xor Is_Reversed
then
1790 Write_Str
("_Order_First");
1791 if List_Representation_Info_To_JSON
then
1798 List_SSO
: constant Boolean :=
1799 Has_Rep_Item
(Ent
, Name_Scalar_Storage_Order
)
1800 or else SSO_Set_Low_By_Default
(Ent
)
1801 or else SSO_Set_High_By_Default
(Ent
);
1802 -- Scalar_Storage_Order is displayed if specified explicitly or set by
1803 -- Default_Scalar_Storage_Order.
1805 -- Start of processing for List_Scalar_Storage_Order
1808 -- For record types, list Bit_Order if not default, or if SSO is shown
1810 -- Also, when -gnatR4 is in effect always list bit order and scalar
1811 -- storage order explicitly, so that you don't need to know the native
1812 -- endianness of the target for which the output was produced in order
1815 if Is_Record_Type
(Ent
)
1817 or else Reverse_Bit_Order
(Ent
)
1818 or else List_Representation_Info
= 4)
1820 List_Attr
("Bit_Order", Reverse_Bit_Order
(Ent
));
1823 -- List SSO if required. If not, then storage is supposed to be in
1826 if List_SSO
or else List_Representation_Info
= 4 then
1827 List_Attr
("Scalar_Storage_Order", Reverse_Storage_Order
(Ent
));
1829 pragma Assert
(not Reverse_Storage_Order
(Ent
));
1832 end List_Scalar_Storage_Order
;
1834 --------------------------
1835 -- List_Subprogram_Info --
1836 --------------------------
1838 procedure List_Subprogram_Info
(Ent
: Entity_Id
) is
1839 First
: Boolean := True;
1846 if List_Representation_Info_To_JSON
then
1848 Write_Str
(" ""name"": """);
1851 List_Location
(Ent
);
1853 Write_Str
(" ""Convention"": """);
1857 Write_Str
("function ");
1860 Write_Str
("operator ");
1863 Write_Str
("procedure ");
1865 when E_Subprogram_Type
=>
1866 Write_Str
("type ");
1871 Write_Str
("entry ");
1874 raise Program_Error
;
1878 Write_Str
(" declared at ");
1879 Write_Location
(Sloc
(Ent
));
1882 Write_Str
("convention : ");
1885 case Convention
(Ent
) is
1886 when Convention_Ada
=>
1889 when Convention_Ada_Pass_By_Copy
=>
1890 Write_Str
("Ada_Pass_By_Copy");
1892 when Convention_Ada_Pass_By_Reference
=>
1893 Write_Str
("Ada_Pass_By_Reference");
1895 when Convention_Intrinsic
=>
1896 Write_Str
("Intrinsic");
1898 when Convention_Entry
=>
1899 Write_Str
("Entry");
1901 when Convention_Protected
=>
1902 Write_Str
("Protected");
1904 when Convention_Assembler
=>
1905 Write_Str
("Assembler");
1907 when Convention_C
=>
1910 when Convention_C_Variadic
=>
1913 Convention_Id
'Pos (Convention
(Ent
)) -
1914 Convention_Id
'Pos (Convention_C_Variadic_0
);
1916 Write_Str
("C_Variadic_");
1921 pragma Assert
(N
< 10);
1922 Write_Char
(Character'Val (Character'Pos ('0') + N
));
1925 when Convention_COBOL
=>
1926 Write_Str
("COBOL");
1928 when Convention_CPP
=>
1931 when Convention_Fortran
=>
1932 Write_Str
("Fortran");
1934 when Convention_Stdcall
=>
1935 Write_Str
("Stdcall");
1937 when Convention_Stubbed
=>
1938 Write_Str
("Stubbed");
1941 if List_Representation_Info_To_JSON
then
1943 Write_Str
(" ""formal"": [");
1948 -- Find max length of formal name
1951 Form
:= First_Formal
(Ent
);
1952 while Present
(Form
) loop
1953 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
1955 if Name_Len
> Plen
then
1962 -- Output formals and mechanisms
1964 Form
:= First_Formal
(Ent
);
1965 while Present
(Form
) loop
1966 Get_Unqualified_Decoded_Name_String
(Chars
(Form
));
1967 Set_Casing
(Unit_Casing
);
1969 if List_Representation_Info_To_JSON
then
1978 Write_Str
(" ""name"": """);
1979 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1982 Write_Str
(" ""mechanism"": """);
1983 Write_Mechanism
(Mechanism
(Form
));
1987 while Name_Len
<= Plen
loop
1988 Name_Len
:= Name_Len
+ 1;
1989 Name_Buffer
(Name_Len
) := ' ';
1993 Write_Str
(Name_Buffer
(1 .. Plen
+ 1));
1994 Write_Str
(": passed by ");
1996 Write_Mechanism
(Mechanism
(Form
));
2003 if List_Representation_Info_To_JSON
then
2008 if Ekind
(Ent
) = E_Function
then
2009 if List_Representation_Info_To_JSON
then
2011 Write_Str
(" ""mechanism"": """);
2012 Write_Mechanism
(Mechanism
(Ent
));
2015 Write_Str
("returns by ");
2016 Write_Mechanism
(Mechanism
(Ent
));
2021 if not Is_Entry
(Ent
) then
2022 List_Linker_Section
(Ent
);
2025 if List_Representation_Info_To_JSON
then
2029 end List_Subprogram_Info
;
2031 --------------------
2032 -- List_Type_Info --
2033 --------------------
2035 procedure List_Type_Info
(Ent
: Entity_Id
) is
2039 if List_Representation_Info_To_JSON
then
2043 List_Common_Type_Info
(Ent
);
2045 -- Special stuff for fixed-point
2047 if Is_Fixed_Point_Type
(Ent
) then
2049 -- Write small (always a static constant)
2051 if List_Representation_Info_To_JSON
then
2053 Write_Str
(" ""Small"": ");
2054 UR_Write
(Small_Value
(Ent
));
2058 Write_Str
("'Small use ");
2059 UR_Write
(Small_Value
(Ent
));
2063 -- Write range if static
2066 R
: constant Node_Id
:= Scalar_Range
(Ent
);
2069 if Nkind
(Low_Bound
(R
)) = N_Real_Literal
2071 Nkind
(High_Bound
(R
)) = N_Real_Literal
2073 if List_Representation_Info_To_JSON
then
2075 Write_Str
(" ""Range"": [ ");
2076 UR_Write
(Realval
(Low_Bound
(R
)));
2078 UR_Write
(Realval
(High_Bound
(R
)));
2083 Write_Str
("'Range use ");
2084 UR_Write
(Realval
(Low_Bound
(R
)));
2086 UR_Write
(Realval
(High_Bound
(R
)));
2093 List_Linker_Section
(Ent
);
2095 if List_Representation_Info_To_JSON
then
2101 ----------------------
2102 -- Rep_Not_Constant --
2103 ----------------------
2105 function Rep_Not_Constant
(Val
: Node_Ref_Or_Val
) return Boolean is
2107 if Val
= No_Uint
or else Val
< 0 then
2112 end Rep_Not_Constant
;
2118 function Rep_Value
(Val
: Node_Ref_Or_Val
; D
: Discrim_List
) return Uint
is
2120 function B
(Val
: Boolean) return Uint
;
2121 -- Returns Uint_0 for False, Uint_1 for True
2123 function T
(Val
: Node_Ref_Or_Val
) return Boolean;
2124 -- Returns True for 0, False for any non-zero (i.e. True)
2126 function V
(Val
: Node_Ref_Or_Val
) return Uint
;
2127 -- Internal recursive routine to evaluate tree
2129 function W
(Val
: Uint
) return Word
;
2130 -- Convert Val to Word, assuming Val is always in the Int range. This
2131 -- is a helper function for the evaluation of bitwise expressions like
2132 -- Bit_And_Expr, for which there is no direct support in uintp. Uint
2133 -- values out of the Int range are expected to be seen in such
2134 -- expressions only with overflowing byte sizes around, introducing
2135 -- inherent unreliabilities in computations anyway.
2141 function B
(Val
: Boolean) return Uint
is
2154 function T
(Val
: Node_Ref_Or_Val
) return Boolean is
2167 function V
(Val
: Node_Ref_Or_Val
) return Uint
is
2176 Node
: Exp_Node
renames Rep_Table
.Table
(-UI_To_Int
(Val
));
2181 if T
(Node
.Op1
) then
2182 return V
(Node
.Op2
);
2184 return V
(Node
.Op3
);
2188 return V
(Node
.Op1
) + V
(Node
.Op2
);
2191 return V
(Node
.Op1
) - V
(Node
.Op2
);
2194 return V
(Node
.Op1
) * V
(Node
.Op2
);
2196 when Trunc_Div_Expr
=>
2197 return V
(Node
.Op1
) / V
(Node
.Op2
);
2199 when Ceil_Div_Expr
=>
2202 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
2204 when Floor_Div_Expr
=>
2207 (V
(Node
.Op1
) / UR_From_Uint
(V
(Node
.Op2
)));
2209 when Trunc_Mod_Expr
=>
2210 return V
(Node
.Op1
) rem V
(Node
.Op2
);
2212 when Floor_Mod_Expr
=>
2213 return V
(Node
.Op1
) mod V
(Node
.Op2
);
2215 when Ceil_Mod_Expr
=>
2218 Q
:= UR_Ceiling
(L
/ UR_From_Uint
(R
));
2221 when Exact_Div_Expr
=>
2222 return V
(Node
.Op1
) / V
(Node
.Op2
);
2225 return -V
(Node
.Op1
);
2228 return UI_Min
(V
(Node
.Op1
), V
(Node
.Op2
));
2231 return UI_Max
(V
(Node
.Op1
), V
(Node
.Op2
));
2234 return UI_Abs
(V
(Node
.Op1
));
2236 when Truth_And_Expr
=>
2237 return B
(T
(Node
.Op1
) and then T
(Node
.Op2
));
2239 when Truth_Or_Expr
=>
2240 return B
(T
(Node
.Op1
) or else T
(Node
.Op2
));
2242 when Truth_Xor_Expr
=>
2243 return B
(T
(Node
.Op1
) xor T
(Node
.Op2
));
2245 when Truth_Not_Expr
=>
2246 return B
(not T
(Node
.Op1
));
2248 when Bit_And_Expr
=>
2251 return UI_From_Int
(Int
(W
(L
) and W
(R
)));
2254 return B
(V
(Node
.Op1
) < V
(Node
.Op2
));
2257 return B
(V
(Node
.Op1
) <= V
(Node
.Op2
));
2260 return B
(V
(Node
.Op1
) > V
(Node
.Op2
));
2263 return B
(V
(Node
.Op1
) >= V
(Node
.Op2
));
2266 return B
(V
(Node
.Op1
) = V
(Node
.Op2
));
2269 return B
(V
(Node
.Op1
) /= V
(Node
.Op2
));
2273 Sub
: constant Int
:= UI_To_Int
(Node
.Op1
);
2275 pragma Assert
(Sub
in D
'Range);
2290 -- We use an unchecked conversion to map Int values to their Word
2291 -- bitwise equivalent, which we could not achieve with a normal type
2292 -- conversion for negative Ints. We want bitwise equivalents because W
2293 -- is used as a helper for bit operators like Bit_And_Expr, and can be
2294 -- called for negative Ints in the context of aligning expressions like
2295 -- X+Align & -Align.
2297 function W
(Val
: Uint
) return Word
is
2298 function To_Word
is new Ada
.Unchecked_Conversion
(Int
, Word
);
2300 return To_Word
(UI_To_Int
(Val
));
2303 -- Start of processing for Rep_Value
2306 if Val
= No_Uint
then
2318 procedure Spaces
(N
: Natural) is
2320 for J
in 1 .. N
loop
2325 ---------------------
2326 -- Write_Info_Line --
2327 ---------------------
2329 procedure Write_Info_Line
(S
: String) is
2331 Write_Repinfo_Line_Access
.all (S
(S
'First .. S
'Last - 1));
2332 end Write_Info_Line
;
2334 ---------------------
2335 -- Write_Mechanism --
2336 ---------------------
2338 procedure Write_Mechanism
(M
: Mechanism_Type
) is
2342 Write_Str
("default");
2348 Write_Str
("reference");
2351 raise Program_Error
;
2353 end Write_Mechanism
;
2355 ---------------------
2356 -- Write_Separator --
2357 ---------------------
2359 procedure Write_Separator
is
2361 if Need_Separator
then
2362 if List_Representation_Info_To_JSON
then
2368 Need_Separator
:= True;
2370 end Write_Separator
;
2372 -----------------------
2373 -- Write_Unknown_Val --
2374 -----------------------
2376 procedure Write_Unknown_Val
is
2378 if List_Representation_Info_To_JSON
then
2379 Write_Str
("""??""");
2383 end Write_Unknown_Val
;
2389 procedure Write_Val
(Val
: Node_Ref_Or_Val
; Paren
: Boolean := False) is
2391 if Rep_Not_Constant
(Val
) then
2392 if List_Representation_Info
< 3 or else Val
= No_Uint
then
2400 if Back_End_Layout
then
2401 List_GCC_Expression
(Val
);
2403 Write_Name_Decoded
(Chars
(Get_Dynamic_SO_Entity
(Val
)));
2412 UI_Write
(Val
, Decimal
);