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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Debug; use Debug;
36 with Einfo; use Einfo;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
41 with Output; use Output;
42 with Sem_Aux; use Sem_Aux;
43 with Sinfo; use Sinfo;
44 with Sinput; use Sinput;
45 with Snames; use Snames;
46 with Stringt; use Stringt;
48 with Uname; use Uname;
49 with Urealp; use Urealp;
51 with Ada.Unchecked_Conversion;
55 package body Repinfo is
58 -- Value for Storage_Unit, we do not want to get this from TTypes, since
59 -- this introduces problematic dependencies in ASIS, and in any case this
60 -- value is assumed to be 8 for the implementation of the DDA.
62 ---------------------------------------
63 -- Representation of GCC Expressions --
64 ---------------------------------------
66 -- A table internal to this unit is used to hold the values of back
67 -- annotated expressions. This table is written out by -gnatt and read
68 -- back in for ASIS processing.
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 by Tree_Gen, 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 function Back_End_Layout return Boolean;
149 -- Test for layout mode, True = back end, False = front end. This function
150 -- is used rather than checking the configuration parameter because we do
151 -- not want Repinfo to depend on Targparm (for ASIS)
153 procedure List_Entities
155 Bytes_Big_Endian : Boolean;
156 In_Subprogram : Boolean := False);
157 -- This procedure lists the entities associated with the entity E, starting
158 -- with the First_Entity and using the Next_Entity link. If a nested
159 -- package is found, entities within the package are recursively processed.
160 -- When recursing within a subprogram body, Is_Subprogram suppresses
161 -- duplicate information about signature.
163 procedure List_Name (Ent : Entity_Id);
164 -- List name of entity Ent in appropriate case. The name is listed with
165 -- full qualification up to but not including the compilation unit name.
167 procedure List_Array_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean);
168 -- List representation info for array type Ent
170 procedure List_Common_Type_Info (Ent : Entity_Id);
171 -- List common type info (name, size, alignment) for type Ent
173 procedure List_Linker_Section (Ent : Entity_Id);
174 -- List linker section for Ent (caller has checked that Ent is an entity
175 -- for which the Linker_Section_Pragma field is defined).
177 procedure List_Location (Ent : Entity_Id);
178 -- List location information for Ent
180 procedure List_Object_Info (Ent : Entity_Id);
181 -- List representation info for object Ent
183 procedure List_Record_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean);
184 -- List representation info for record type Ent
186 procedure List_Scalar_Storage_Order
188 Bytes_Big_Endian : Boolean);
189 -- List scalar storage order information for record or array type Ent.
190 -- Also includes bit order information for record types, if necessary.
192 procedure List_Subprogram_Info (Ent : Entity_Id);
193 -- List subprogram info for subprogram Ent
195 procedure List_Type_Info (Ent : Entity_Id);
196 -- List type info for type Ent
198 function Rep_Not_Constant (Val : Node_Ref_Or_Val) return Boolean;
199 -- Returns True if Val represents a variable value, and False if it
200 -- represents a value that is fixed at compile time.
202 procedure Spaces (N : Natural);
203 -- Output given number of spaces
205 procedure Write_Info_Line (S : String);
206 -- Routine to write a line to Repinfo output file. This routine is passed
207 -- as a special output procedure to Output.Set_Special_Output. Note that
208 -- Write_Info_Line is called with an EOL character at the end of each line,
209 -- as per the Output spec, but the internal call to the appropriate routine
210 -- in Osint requires that the end of line sequence be stripped off.
212 procedure Write_Mechanism (M : Mechanism_Type);
213 -- Writes symbolic string for mechanism represented by M
215 procedure Write_Separator;
216 -- Called before outputting anything for an entity. Ensures that
217 -- a separator precedes the output for a particular entity.
219 procedure Write_Unknown_Val;
220 -- Writes symbolic string for an unknown or non-representable value
222 procedure Write_Val (Val : Node_Ref_Or_Val; Paren : Boolean := False);
223 -- Given a representation value, write it out. No_Uint values or values
224 -- dependent on discriminants are written as two question marks. If the
225 -- flag Paren is set, then the output is surrounded in parentheses if it is
226 -- other than a simple value.
228 ---------------------
229 -- Back_End_Layout --
230 ---------------------
232 function Back_End_Layout return Boolean is
234 -- We have back-end layout if the back end has made any entries in the
235 -- table of GCC expressions, otherwise we have front-end layout.
237 return Rep_Table.Last > 0;
240 ------------------------
241 -- Create_Discrim_Ref --
242 ------------------------
244 function Create_Discrim_Ref (Discr : Entity_Id) return Node_Ref is
247 (Expr => Discrim_Val,
248 Op1 => Discriminant_Number (Discr));
249 end Create_Discrim_Ref;
251 ---------------------------
252 -- Create_Dynamic_SO_Ref --
253 ---------------------------
255 function Create_Dynamic_SO_Ref (E : Entity_Id) return Dynamic_SO_Ref is
257 Dynamic_SO_Entity_Table.Append (E);
258 return UI_From_Int (-Dynamic_SO_Entity_Table.Last);
259 end Create_Dynamic_SO_Ref;
267 Op1 : Node_Ref_Or_Val;
268 Op2 : Node_Ref_Or_Val := No_Uint;
269 Op3 : Node_Ref_Or_Val := No_Uint) return Node_Ref
277 return UI_From_Int (-Rep_Table.Last);
284 function Entity_Hash (Id : Entity_Id) return Entity_Header_Num is
286 return Entity_Header_Num (Id mod Relevant_Entities_Size);
289 ---------------------------
290 -- Get_Dynamic_SO_Entity --
291 ---------------------------
293 function Get_Dynamic_SO_Entity (U : Dynamic_SO_Ref) return Entity_Id is
295 return Dynamic_SO_Entity_Table.Table (-UI_To_Int (U));
296 end Get_Dynamic_SO_Entity;
298 -----------------------
299 -- Is_Dynamic_SO_Ref --
300 -----------------------
302 function Is_Dynamic_SO_Ref (U : SO_Ref) return Boolean is
305 end Is_Dynamic_SO_Ref;
307 ----------------------
308 -- Is_Static_SO_Ref --
309 ----------------------
311 function Is_Static_SO_Ref (U : SO_Ref) return Boolean is
314 end Is_Static_SO_Ref;
320 procedure lgx (U : Node_Ref_Or_Val) is
322 List_GCC_Expression (U);
326 ----------------------
327 -- List_Array_Info --
328 ----------------------
330 procedure List_Array_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is
334 if List_Representation_Info_To_JSON then
338 List_Common_Type_Info (Ent);
340 if List_Representation_Info_To_JSON then
342 Write_Str (" ""Component_Size"": ");
343 Write_Val (Component_Size (Ent));
347 Write_Str ("'Component_Size use ");
348 Write_Val (Component_Size (Ent));
352 List_Scalar_Storage_Order (Ent, Bytes_Big_Endian);
354 List_Linker_Section (Ent);
356 if List_Representation_Info_To_JSON then
361 -- The component type is relevant for an array
363 if List_Representation_Info = 4
364 and then Is_Itype (Component_Type (Base_Type (Ent)))
366 Relevant_Entities.Set (Component_Type (Base_Type (Ent)), True);
370 ---------------------------
371 -- List_Common_Type_Info --
372 ---------------------------
374 procedure List_Common_Type_Info (Ent : Entity_Id) is
376 if List_Representation_Info_To_JSON then
377 Write_Str (" ""name"": """);
383 -- Do not list size info for unconstrained arrays, not meaningful
385 if Is_Array_Type (Ent) and then not Is_Constrained (Ent) then
389 -- If Esize and RM_Size are the same, list as Size. This is a common
390 -- case, which we may as well list in simple form.
392 if Esize (Ent) = RM_Size (Ent) then
393 if List_Representation_Info_To_JSON then
394 Write_Str (" ""Size"": ");
395 Write_Val (Esize (Ent));
400 Write_Str ("'Size use ");
401 Write_Val (Esize (Ent));
405 -- Otherwise list size values separately
408 if List_Representation_Info_To_JSON then
409 Write_Str (" ""Object_Size"": ");
410 Write_Val (Esize (Ent));
413 Write_Str (" ""Value_Size"": ");
414 Write_Val (RM_Size (Ent));
420 Write_Str ("'Object_Size use ");
421 Write_Val (Esize (Ent));
426 Write_Str ("'Value_Size use ");
427 Write_Val (RM_Size (Ent));
433 if List_Representation_Info_To_JSON then
434 Write_Str (" ""Alignment"": ");
435 Write_Val (Alignment (Ent));
439 Write_Str ("'Alignment use ");
440 Write_Val (Alignment (Ent));
443 end List_Common_Type_Info;
449 procedure List_Entities
451 Bytes_Big_Endian : Boolean;
452 In_Subprogram : Boolean := False)
457 function Find_Declaration (E : Entity_Id) return Node_Id;
458 -- Utility to retrieve declaration node for entity in the
459 -- case of package bodies and subprograms.
461 ----------------------
462 -- Find_Declaration --
463 ----------------------
465 function Find_Declaration (E : Entity_Id) return Node_Id is
471 and then Nkind (Decl) /= N_Package_Body
472 and then Nkind (Decl) /= N_Subprogram_Declaration
473 and then Nkind (Decl) /= N_Subprogram_Body
475 Decl := Parent (Decl);
479 end Find_Declaration;
481 -- Start of processing for List_Entities
484 -- List entity if we have one, and it is not a renaming declaration.
485 -- For renamings, we don't get proper information, and really it makes
486 -- sense to restrict the output to the renamed entity.
489 and then Nkind (Declaration_Node (Ent)) not in N_Renaming_Declaration
490 and then not Is_Ignored_Ghost_Entity (Ent)
492 -- If entity is a subprogram and we are listing mechanisms,
493 -- then we need to list mechanisms for this entity. We skip this
494 -- if it is a nested subprogram, as the information has already
495 -- been produced when listing the enclosing scope.
497 if List_Representation_Info_Mechanisms
498 and then (Is_Subprogram (Ent)
499 or else Ekind (Ent) = E_Entry
500 or else Ekind (Ent) = E_Entry_Family)
501 and then not In_Subprogram
503 List_Subprogram_Info (Ent);
506 E := First_Entity (Ent);
507 while Present (E) loop
508 -- We list entities that come from source (excluding private or
509 -- incomplete types or deferred constants, for which we will list
510 -- the information for the full view). If requested, we also list
511 -- relevant entities that have been generated when processing the
512 -- original entities coming from source. But if debug flag A is
513 -- set, then all entities are listed.
515 if ((Comes_From_Source (E)
516 or else (Ekind (E) = E_Block
518 Nkind (Parent (E)) = N_Implicit_Label_Declaration
520 Comes_From_Source (Label_Construct (Parent (E)))))
521 and then not Is_Incomplete_Or_Private_Type (E)
522 and then not (Ekind (E) = E_Constant
523 and then Present (Full_View (E))))
524 or else (List_Representation_Info = 4
525 and then Relevant_Entities.Get (E))
526 or else Debug_Flag_AA
528 if Is_Subprogram (E) then
529 if List_Representation_Info_Mechanisms then
530 List_Subprogram_Info (E);
533 -- Recurse into entities local to subprogram
535 List_Entities (E, Bytes_Big_Endian, True);
537 elsif Ekind_In (E, E_Entry,
541 if List_Representation_Info_Mechanisms then
542 List_Subprogram_Info (E);
545 elsif Is_Record_Type (E) then
546 if List_Representation_Info >= 1 then
547 List_Record_Info (E, Bytes_Big_Endian);
550 -- Recurse into entities local to a record type
552 if List_Representation_Info = 4 then
553 List_Entities (E, Bytes_Big_Endian, False);
556 elsif Is_Array_Type (E) then
557 if List_Representation_Info >= 1 then
558 List_Array_Info (E, Bytes_Big_Endian);
561 elsif Is_Type (E) then
562 if List_Representation_Info >= 2 then
566 -- Note that formals are not annotated so we skip them here
568 elsif Ekind_In (E, E_Constant,
572 if List_Representation_Info >= 2 then
573 List_Object_Info (E);
577 -- Recurse into nested package, but not if they are package
578 -- renamings (in particular renamings of the enclosing package,
579 -- as for some Java bindings and for generic instances).
581 if Ekind (E) = E_Package then
582 if No (Renamed_Object (E)) then
583 List_Entities (E, Bytes_Big_Endian);
586 -- Recurse into bodies
588 elsif Ekind_In (E, E_Package_Body,
595 List_Entities (E, Bytes_Big_Endian);
597 -- Recurse into blocks
599 elsif Ekind (E) = E_Block then
600 List_Entities (E, Bytes_Big_Endian);
604 E := Next_Entity (E);
607 -- For a package body, the entities of the visible subprograms are
608 -- declared in the corresponding spec. Iterate over its entities in
609 -- order to handle properly the subprogram bodies. Skip bodies in
610 -- subunits, which are listed independently.
612 if Ekind (Ent) = E_Package_Body
613 and then Present (Corresponding_Spec (Find_Declaration (Ent)))
615 E := First_Entity (Corresponding_Spec (Find_Declaration (Ent)));
616 while Present (E) loop
619 Nkind (Find_Declaration (E)) = N_Subprogram_Declaration
621 Body_E := Corresponding_Body (Find_Declaration (E));
625 Nkind (Parent (Find_Declaration (Body_E))) /= N_Subunit
627 List_Entities (Body_E, Bytes_Big_Endian);
637 -------------------------
638 -- List_GCC_Expression --
639 -------------------------
641 procedure List_GCC_Expression (U : Node_Ref_Or_Val) is
643 procedure Print_Expr (Val : Node_Ref_Or_Val);
644 -- Internal recursive procedure to print expression
650 procedure Print_Expr (Val : Node_Ref_Or_Val) is
653 UI_Write (Val, Decimal);
657 Node : Exp_Node renames Rep_Table.Table (-UI_To_Int (Val));
659 procedure Unop (S : String);
660 -- Output text for unary operator with S being operator name
662 procedure Binop (S : String);
663 -- Output text for binary operator with S being operator name
669 procedure Unop (S : String) is
671 if List_Representation_Info_To_JSON then
672 Write_Str ("{ ""code"": """);
673 if S (S'Last) = ' ' then
674 Write_Str (S (S'First .. S'Last - 1));
678 Write_Str (""", ""operands"": [ ");
679 Print_Expr (Node.Op1);
683 Print_Expr (Node.Op1);
691 procedure Binop (S : String) is
693 if List_Representation_Info_To_JSON then
694 Write_Str ("{ ""code"": """);
695 Write_Str (S (S'First + 1 .. S'Last - 1));
696 Write_Str (""", ""operands"": [ ");
697 Print_Expr (Node.Op1);
699 Print_Expr (Node.Op2);
703 Print_Expr (Node.Op1);
705 Print_Expr (Node.Op2);
710 -- Start of processing for Print_Expr
715 if List_Representation_Info_To_JSON then
716 Write_Str ("{ ""code"": ""?<>""");
717 Write_Str (", ""operands"": [ ");
718 Print_Expr (Node.Op1);
720 Print_Expr (Node.Op2);
722 Print_Expr (Node.Op3);
726 Print_Expr (Node.Op1);
727 Write_Str (" then ");
728 Print_Expr (Node.Op2);
729 Write_Str (" else ");
730 Print_Expr (Node.Op3);
743 when Trunc_Div_Expr =>
746 when Ceil_Div_Expr =>
749 when Floor_Div_Expr =>
752 when Trunc_Mod_Expr =>
755 when Ceil_Mod_Expr =>
758 when Floor_Mod_Expr =>
761 when Exact_Div_Expr =>
776 when Truth_And_Expr =>
779 when Truth_Or_Expr =>
782 when Truth_Xor_Expr =>
785 when Truth_Not_Expr =>
819 -- Start of processing for List_GCC_Expression
827 end List_GCC_Expression;
829 -------------------------
830 -- List_Linker_Section --
831 -------------------------
833 procedure List_Linker_Section (Ent : Entity_Id) is
834 function Expr_Value_S (N : Node_Id) return Node_Id;
835 -- Returns the folded value of the expression. This function is called
836 -- in instances where it has already been determined that the expression
837 -- is static or its value is known at compile time. This version is used
838 -- for string types and returns the corresponding N_String_Literal node.
839 -- NOTE: This is an exact copy of Sem_Eval.Expr_Value_S. Licensing stops
840 -- Repinfo from within Sem_Eval. Once ASIS is removed, and the licenses
841 -- are modified, Repinfo should be able to rely on Sem_Eval.
847 function Expr_Value_S (N : Node_Id) return Node_Id is
849 if Nkind (N) = N_String_Literal then
852 pragma Assert (Ekind (Entity (N)) = E_Constant);
853 return Expr_Value_S (Constant_Value (Entity (N)));
862 -- Start of processing for List_Linker_Section
865 if Present (Linker_Section_Pragma (Ent)) then
866 Args := Pragma_Argument_Associations (Linker_Section_Pragma (Ent));
867 Sect := Expr_Value_S (Get_Pragma_Arg (Last (Args)));
869 if List_Representation_Info_To_JSON then
871 Write_Str (" ""Linker_Section"": """);
873 Write_Str ("pragma Linker_Section (");
878 pragma Assert (Nkind (Sect) = N_String_Literal);
879 String_To_Name_Buffer (Strval (Sect));
880 Write_Str (Name_Buffer (1 .. Name_Len));
882 if not List_Representation_Info_To_JSON then
886 end List_Linker_Section;
892 procedure List_Location (Ent : Entity_Id) is
894 pragma Assert (List_Representation_Info_To_JSON);
895 Write_Str (" ""location"": """);
896 Write_Location (Sloc (Ent));
904 procedure List_Name (Ent : Entity_Id) is
908 -- List the qualified name recursively, except
909 -- at compilation unit level in default mode.
911 if Is_Compilation_Unit (Ent) then
913 elsif not Is_Compilation_Unit (Scope (Ent))
914 or else List_Representation_Info_To_JSON
916 List_Name (Scope (Ent));
920 Get_Unqualified_Decoded_Name_String (Chars (Ent));
921 Set_Casing (Unit_Casing);
923 -- The name of operators needs to be properly escaped for JSON
925 for J in 1 .. Name_Len loop
926 C := Name_Buffer (J);
927 if C = '"' and then List_Representation_Info_To_JSON then
934 ---------------------
935 -- List_Object_Info --
936 ---------------------
938 procedure List_Object_Info (Ent : Entity_Id) is
942 if List_Representation_Info_To_JSON then
945 Write_Str (" ""name"": """);
950 Write_Str (" ""Size"": ");
951 Write_Val (Esize (Ent));
954 Write_Str (" ""Alignment"": ");
955 Write_Val (Alignment (Ent));
957 List_Linker_Section (Ent);
964 Write_Str ("'Size use ");
965 Write_Val (Esize (Ent));
970 Write_Str ("'Alignment use ");
971 Write_Val (Alignment (Ent));
974 List_Linker_Section (Ent);
977 -- The type is relevant for an object
979 if List_Representation_Info = 4 and then Is_Itype (Etype (Ent)) then
980 Relevant_Entities.Set (Etype (Ent), True);
982 end List_Object_Info;
984 ----------------------
985 -- List_Record_Info --
986 ----------------------
988 procedure List_Record_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is
989 procedure Compute_Max_Length
991 Starting_Position : Uint := Uint_0;
992 Starting_First_Bit : Uint := Uint_0;
993 Prefix_Length : Natural := 0);
994 -- Internal recursive procedure to compute the max length
996 procedure List_Component_Layout
998 Starting_Position : Uint := Uint_0;
999 Starting_First_Bit : Uint := Uint_0;
1000 Prefix : String := "";
1001 Indent : Natural := 0);
1002 -- Procedure to display the layout of a single component
1004 procedure List_Record_Layout
1006 Starting_Position : Uint := Uint_0;
1007 Starting_First_Bit : Uint := Uint_0;
1008 Prefix : String := "");
1009 -- Internal recursive procedure to display the layout
1011 procedure List_Structural_Record_Layout
1013 Outer_Ent : Entity_Id;
1014 Variant : Node_Id := Empty;
1015 Indent : Natural := 0);
1016 -- Internal recursive procedure to display the structural layout
1018 Incomplete_Layout : exception;
1019 -- Exception raised if the layout is incomplete in -gnatc mode
1021 Not_In_Extended_Main : exception;
1022 -- Exception raised when an ancestor is not declared in the main unit
1024 Max_Name_Length : Natural := 0;
1025 Max_Spos_Length : Natural := 0;
1027 ------------------------
1028 -- Compute_Max_Length --
1029 ------------------------
1031 procedure Compute_Max_Length
1033 Starting_Position : Uint := Uint_0;
1034 Starting_First_Bit : Uint := Uint_0;
1035 Prefix_Length : Natural := 0)
1040 Comp := First_Component_Or_Discriminant (Ent);
1041 while Present (Comp) loop
1043 -- Skip discriminant in unchecked union (since it is not there!)
1045 if Ekind (Comp) = E_Discriminant
1046 and then Is_Unchecked_Union (Ent)
1051 -- Skip _Parent component in extension (to avoid overlap)
1053 if Chars (Comp) = Name_uParent then
1060 Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp));
1061 Bofs : constant Uint := Component_Bit_Offset (Comp);
1067 Name_Length : Natural;
1070 Get_Decoded_Name_String (Chars (Comp));
1071 Name_Length := Prefix_Length + Name_Len;
1073 if Rep_Not_Constant (Bofs) then
1075 -- If the record is not packed, then we know that all fields
1076 -- whose position is not specified have starting normalized
1077 -- bit position of zero.
1079 if Unknown_Normalized_First_Bit (Comp)
1080 and then not Is_Packed (Ent)
1082 Set_Normalized_First_Bit (Comp, Uint_0);
1085 UI_Image_Length := 2; -- For "??" marker
1088 Fbit := Bofs mod SSU;
1090 -- Complete annotation in case not done
1092 if Unknown_Normalized_First_Bit (Comp) then
1093 Set_Normalized_Position (Comp, Npos);
1094 Set_Normalized_First_Bit (Comp, Fbit);
1097 Spos := Starting_Position + Npos;
1098 Sbit := Starting_First_Bit + Fbit;
1105 -- If extended information is requested, recurse fully into
1106 -- record components, i.e. skip the outer level.
1108 if List_Representation_Info_Extended
1109 and then Is_Record_Type (Ctyp)
1111 Compute_Max_Length (Ctyp, Spos, Sbit, Name_Length + 1);
1118 Max_Name_Length := Natural'Max (Max_Name_Length, Name_Length);
1120 Natural'Max (Max_Spos_Length, UI_Image_Length);
1124 Next_Component_Or_Discriminant (Comp);
1126 end Compute_Max_Length;
1128 ---------------------------
1129 -- List_Component_Layout --
1130 ---------------------------
1132 procedure List_Component_Layout
1134 Starting_Position : Uint := Uint_0;
1135 Starting_First_Bit : Uint := Uint_0;
1136 Prefix : String := "";
1137 Indent : Natural := 0)
1139 Esiz : constant Uint := Esize (Ent);
1140 Npos : constant Uint := Normalized_Position (Ent);
1141 Fbit : constant Uint := Normalized_First_Bit (Ent);
1147 if List_Representation_Info_To_JSON then
1151 Write_Str (" ""name"": """);
1153 Write_Str (Name_Buffer (1 .. Name_Len));
1155 if Ekind (Ent) = E_Discriminant then
1157 Write_Str (" ""discriminant"": ");
1158 UI_Write (Discriminant_Number (Ent), Decimal);
1162 Write_Str (" ""Position"": ");
1166 Write_Str (Name_Buffer (1 .. Name_Len));
1167 Spaces (Max_Name_Length - Prefix'Length - Name_Len);
1171 if Known_Static_Normalized_Position (Ent) then
1172 Spos := Starting_Position + Npos;
1173 Sbit := Starting_First_Bit + Fbit;
1180 Spaces (Max_Spos_Length - UI_Image_Length);
1181 Write_Str (UI_Image_Buffer (1 .. UI_Image_Length));
1183 elsif Known_Normalized_Position (Ent)
1184 and then List_Representation_Info >= 3
1186 Spaces (Max_Spos_Length - 2);
1188 if Starting_Position /= Uint_0 then
1189 UI_Write (Starting_Position, Decimal);
1199 if List_Representation_Info_To_JSON then
1202 Write_Str (" ""First_Bit"": ");
1204 Write_Str (" range ");
1207 Sbit := Starting_First_Bit + Fbit;
1213 UI_Write (Sbit, Decimal);
1215 if List_Representation_Info_To_JSON then
1218 Write_Str (" ""Size"": ");
1223 -- Allowing Uint_0 here is an annoying special case. Really this
1224 -- should be a fine Esize value but currently it means unknown,
1225 -- except that we know after gigi has back annotated that a size
1226 -- of zero is real, since otherwise gigi back annotates using
1227 -- No_Uint as the value to indicate unknown.
1229 if (Esize (Ent) = Uint_0 or else Known_Static_Esize (Ent))
1230 and then Known_Static_Normalized_First_Bit (Ent)
1232 Lbit := Sbit + Esiz - 1;
1234 if List_Representation_Info_To_JSON then
1235 UI_Write (Esiz, Decimal);
1237 if Lbit >= 0 and then Lbit < 10 then
1241 UI_Write (Lbit, Decimal);
1244 -- The test for Esize (Ent) not Uint_0 here is an annoying special
1245 -- case. Officially a value of zero for Esize means unknown, but
1246 -- here we use the fact that we know that gigi annotates Esize with
1247 -- No_Uint, not Uint_0. Really everyone should use No_Uint???
1249 elsif List_Representation_Info < 3
1250 or else (Esize (Ent) /= Uint_0 and then Unknown_Esize (Ent))
1254 -- List_Representation >= 3 and Known_Esize (Ent)
1257 Write_Val (Esiz, Paren => not List_Representation_Info_To_JSON);
1259 -- If in front-end layout mode, then dynamic size is stored in
1260 -- storage units, so renormalize for output.
1262 if not Back_End_Layout then
1267 -- Add appropriate first bit offset
1269 if not List_Representation_Info_To_JSON then
1278 Write_Int (UI_To_Int (Sbit) - 1);
1283 if List_Representation_Info_To_JSON then
1291 -- The type is relevant for a component
1293 if List_Representation_Info = 4 and then Is_Itype (Etype (Ent)) then
1294 Relevant_Entities.Set (Etype (Ent), True);
1296 end List_Component_Layout;
1298 ------------------------
1299 -- List_Record_Layout --
1300 ------------------------
1302 procedure List_Record_Layout
1304 Starting_Position : Uint := Uint_0;
1305 Starting_First_Bit : Uint := Uint_0;
1306 Prefix : String := "")
1309 First : Boolean := True;
1312 Comp := First_Component_Or_Discriminant (Ent);
1313 while Present (Comp) loop
1315 -- Skip discriminant in unchecked union (since it is not there!)
1317 if Ekind (Comp) = E_Discriminant
1318 and then Is_Unchecked_Union (Ent)
1323 -- Skip _Parent component in extension (to avoid overlap)
1325 if Chars (Comp) = Name_uParent then
1332 Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp));
1333 Npos : constant Uint := Normalized_Position (Comp);
1334 Fbit : constant Uint := Normalized_First_Bit (Comp);
1339 Get_Decoded_Name_String (Chars (Comp));
1340 Set_Casing (Unit_Casing);
1342 -- If extended information is requested, recurse fully into
1343 -- record components, i.e. skip the outer level.
1345 if List_Representation_Info_Extended
1346 and then Is_Record_Type (Ctyp)
1347 and then Known_Static_Normalized_Position (Comp)
1348 and then Known_Static_Normalized_First_Bit (Comp)
1350 Spos := Starting_Position + Npos;
1351 Sbit := Starting_First_Bit + Fbit;
1358 List_Record_Layout (Ctyp,
1359 Spos, Sbit, Prefix & Name_Buffer (1 .. Name_Len) & ".");
1364 if List_Representation_Info_To_JSON then
1373 List_Component_Layout (Comp,
1374 Starting_Position, Starting_First_Bit, Prefix);
1378 Next_Component_Or_Discriminant (Comp);
1380 end List_Record_Layout;
1382 -----------------------------------
1383 -- List_Structural_Record_Layout --
1384 -----------------------------------
1386 procedure List_Structural_Record_Layout
1388 Outer_Ent : Entity_Id;
1389 Variant : Node_Id := Empty;
1390 Indent : Natural := 0)
1392 function Derived_Discriminant (Disc : Entity_Id) return Entity_Id;
1393 -- This function assumes that Outer_Ent is an extension of Ent.
1394 -- Disc is a discriminant of Ent that does not itself constrain a
1395 -- discriminant of the parent type of Ent. Return the discriminant
1396 -- of Outer_Ent that ultimately constrains Disc, if any.
1398 ----------------------------
1399 -- Derived_Discriminant --
1400 ----------------------------
1402 function Derived_Discriminant (Disc : Entity_Id) return Entity_Id is
1403 Corr_Disc : Entity_Id;
1404 Derived_Disc : Entity_Id;
1407 Derived_Disc := First_Stored_Discriminant (Outer_Ent);
1409 -- Loop over the discriminants of the extension
1411 while Present (Derived_Disc) loop
1413 -- Check if this discriminant constrains another discriminant.
1414 -- If so, find the ultimately constrained discriminant and
1415 -- compare with the original components in the base type.
1417 if Present (Corresponding_Discriminant (Derived_Disc)) then
1418 Corr_Disc := Corresponding_Discriminant (Derived_Disc);
1420 while Present (Corresponding_Discriminant (Corr_Disc)) loop
1421 Corr_Disc := Corresponding_Discriminant (Corr_Disc);
1424 if Original_Record_Component (Corr_Disc) =
1425 Original_Record_Component (Disc)
1427 return Derived_Disc;
1431 Next_Stored_Discriminant (Derived_Disc);
1434 -- Disc is not constrained by a discriminant of Outer_Ent
1437 end Derived_Discriminant;
1439 -- Local declarations
1442 Comp_List : Node_Id;
1443 First : Boolean := True;
1446 -- Start of processing for List_Structural_Record_Layout
1449 -- If we are dealing with a variant, just process the components
1451 if Present (Variant) then
1452 Comp_List := Component_List (Variant);
1454 -- Otherwise, we are dealing with the full record and need to get
1455 -- to its definition in order to retrieve its structural layout.
1459 Definition : Node_Id :=
1460 Type_Definition (Declaration_Node (Ent));
1462 Is_Extension : constant Boolean :=
1463 Is_Tagged_Type (Ent)
1464 and then Nkind (Definition) =
1465 N_Derived_Type_Definition;
1468 Listed_Disc : Entity_Id;
1469 Parent_Type : Entity_Id;
1472 -- If this is an extension, first list the layout of the parent
1473 -- and then proceed to the extension part, if any.
1475 if Is_Extension then
1476 Parent_Type := Parent_Subtype (Ent);
1477 if No (Parent_Type) then
1478 raise Incomplete_Layout;
1481 if Is_Private_Type (Parent_Type) then
1482 Parent_Type := Full_View (Parent_Type);
1483 pragma Assert (Present (Parent_Type));
1486 Parent_Type := Base_Type (Parent_Type);
1487 if not In_Extended_Main_Source_Unit (Parent_Type) then
1488 raise Not_In_Extended_Main;
1491 List_Structural_Record_Layout (Parent_Type, Outer_Ent);
1494 if Present (Record_Extension_Part (Definition)) then
1495 Definition := Record_Extension_Part (Definition);
1499 -- If the record has discriminants and is not an unchecked
1500 -- union, then display them now.
1502 if Has_Discriminants (Ent)
1503 and then not Is_Unchecked_Union (Ent)
1505 Disc := First_Stored_Discriminant (Ent);
1506 while Present (Disc) loop
1508 -- If this is a record extension and the discriminant is
1509 -- the renaming of another discriminant, skip it.
1512 and then Present (Corresponding_Discriminant (Disc))
1517 -- If this is the parent type of an extension, retrieve
1518 -- the derived discriminant from the extension, if any.
1520 if Ent /= Outer_Ent then
1521 Listed_Disc := Derived_Discriminant (Disc);
1523 if No (Listed_Disc) then
1527 Listed_Disc := Disc;
1530 Get_Decoded_Name_String (Chars (Listed_Disc));
1531 Set_Casing (Unit_Casing);
1540 List_Component_Layout (Listed_Disc, Indent => Indent);
1543 Next_Stored_Discriminant (Disc);
1547 Comp_List := Component_List (Definition);
1551 -- Bail out for the null record
1553 if No (Comp_List) then
1557 -- Now deal with the regular components, if any
1559 if Present (Component_Items (Comp_List)) then
1560 Comp := First_Non_Pragma (Component_Items (Comp_List));
1561 while Present (Comp) loop
1563 -- Skip _Parent component in extension (to avoid overlap)
1565 if Chars (Defining_Identifier (Comp)) = Name_uParent then
1569 Get_Decoded_Name_String (Chars (Defining_Identifier (Comp)));
1570 Set_Casing (Unit_Casing);
1579 List_Component_Layout
1580 (Defining_Identifier (Comp), Indent => Indent);
1583 Next_Non_Pragma (Comp);
1587 -- We are done if there is no variant part
1589 if No (Variant_Part (Comp_List)) then
1597 Write_Str (" ""variant"" : [");
1599 -- Otherwise we recurse on each variant
1601 Var := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
1603 while Present (Var) loop
1614 Write_Str (" ""present"": ");
1615 Write_Val (Present_Expr (Var));
1618 Write_Str (" ""record"": [");
1620 List_Structural_Record_Layout (Ent, Outer_Ent, Var, Indent + 4);
1627 Next_Non_Pragma (Var);
1629 end List_Structural_Record_Layout;
1631 -- Start of processing for List_Record_Info
1636 if List_Representation_Info_To_JSON then
1640 List_Common_Type_Info (Ent);
1642 -- First find out max line length and max starting position
1643 -- length, for the purpose of lining things up nicely.
1645 Compute_Max_Length (Ent);
1647 -- Then do actual output based on those values
1649 if List_Representation_Info_To_JSON then
1651 Write_Str (" ""record"": [");
1653 -- ??? We can output structural layout only for base types fully
1654 -- declared in the extended main source unit for the time being,
1655 -- because otherwise declarations might not be processed at all.
1657 if Is_Base_Type (Ent) then
1659 List_Structural_Record_Layout (Ent, Ent);
1662 when Incomplete_Layout
1663 | Not_In_Extended_Main
1665 List_Record_Layout (Ent);
1668 raise Program_Error;
1671 List_Record_Layout (Ent);
1679 Write_Line (" use record");
1681 List_Record_Layout (Ent);
1683 Write_Line ("end record;");
1686 List_Scalar_Storage_Order (Ent, Bytes_Big_Endian);
1688 List_Linker_Section (Ent);
1690 if List_Representation_Info_To_JSON then
1695 -- The type is relevant for a record subtype
1697 if List_Representation_Info = 4
1698 and then not Is_Base_Type (Ent)
1699 and then Is_Itype (Etype (Ent))
1701 Relevant_Entities.Set (Etype (Ent), True);
1703 end List_Record_Info;
1709 procedure List_Rep_Info (Bytes_Big_Endian : Boolean) is
1713 if List_Representation_Info /= 0
1714 or else List_Representation_Info_Mechanisms
1716 -- For the normal case, we output a single JSON stream
1718 if not List_Representation_Info_To_File
1719 and then List_Representation_Info_To_JSON
1722 Need_Separator := False;
1725 for U in Main_Unit .. Last_Unit loop
1726 if In_Extended_Main_Source_Unit (Cunit_Entity (U)) then
1727 Unit_Casing := Identifier_Casing (Source_Index (U));
1729 if List_Representation_Info = 4 then
1730 Relevant_Entities.Reset;
1733 -- Normal case, list to standard output
1735 if not List_Representation_Info_To_File then
1736 if not List_Representation_Info_To_JSON then
1738 Write_Str ("Representation information for unit ");
1739 Write_Unit_Name (Unit_Name (U));
1743 for J in 1 .. Col - 1 loop
1748 Need_Separator := True;
1751 List_Entities (Cunit_Entity (U), Bytes_Big_Endian);
1753 -- List representation information to file
1756 Create_Repinfo_File_Access.all
1757 (Get_Name_String (File_Name (Source_Index (U))));
1758 Set_Special_Output (Write_Info_Line'Access);
1759 if List_Representation_Info_To_JSON then
1762 Need_Separator := False;
1763 List_Entities (Cunit_Entity (U), Bytes_Big_Endian);
1764 if List_Representation_Info_To_JSON then
1767 Cancel_Special_Output;
1768 Close_Repinfo_File_Access.all;
1773 if not List_Representation_Info_To_File
1774 and then List_Representation_Info_To_JSON
1781 -------------------------------
1782 -- List_Scalar_Storage_Order --
1783 -------------------------------
1785 procedure List_Scalar_Storage_Order
1787 Bytes_Big_Endian : Boolean)
1789 procedure List_Attr (Attr_Name : String; Is_Reversed : Boolean);
1790 -- Show attribute definition clause for Attr_Name (an endianness
1791 -- attribute), depending on whether or not the endianness is reversed
1792 -- compared to native endianness.
1798 procedure List_Attr (Attr_Name : String; Is_Reversed : Boolean) is
1800 if List_Representation_Info_To_JSON then
1803 Write_Str (Attr_Name);
1804 Write_Str (""": ""System.");
1809 Write_Str (Attr_Name);
1810 Write_Str (" use System.");
1813 if Bytes_Big_Endian xor Is_Reversed then
1819 Write_Str ("_Order_First");
1820 if List_Representation_Info_To_JSON then
1827 List_SSO : constant Boolean :=
1828 Has_Rep_Item (Ent, Name_Scalar_Storage_Order)
1829 or else SSO_Set_Low_By_Default (Ent)
1830 or else SSO_Set_High_By_Default (Ent);
1831 -- Scalar_Storage_Order is displayed if specified explicitly or set by
1832 -- Default_Scalar_Storage_Order.
1834 -- Start of processing for List_Scalar_Storage_Order
1837 -- For record types, list Bit_Order if not default, or if SSO is shown
1839 -- Also, when -gnatR4 is in effect always list bit order and scalar
1840 -- storage order explicitly, so that you don't need to know the native
1841 -- endianness of the target for which the output was produced in order
1844 if Is_Record_Type (Ent)
1846 or else Reverse_Bit_Order (Ent)
1847 or else List_Representation_Info = 4)
1849 List_Attr ("Bit_Order", Reverse_Bit_Order (Ent));
1852 -- List SSO if required. If not, then storage is supposed to be in
1855 if List_SSO or else List_Representation_Info = 4 then
1856 List_Attr ("Scalar_Storage_Order", Reverse_Storage_Order (Ent));
1858 pragma Assert (not Reverse_Storage_Order (Ent));
1861 end List_Scalar_Storage_Order;
1863 --------------------------
1864 -- List_Subprogram_Info --
1865 --------------------------
1867 procedure List_Subprogram_Info (Ent : Entity_Id) is
1868 First : Boolean := True;
1875 if List_Representation_Info_To_JSON then
1877 Write_Str (" ""name"": """);
1880 List_Location (Ent);
1882 Write_Str (" ""Convention"": """);
1886 Write_Str ("function ");
1889 Write_Str ("operator ");
1892 Write_Str ("procedure ");
1894 when E_Subprogram_Type =>
1895 Write_Str ("type ");
1900 Write_Str ("entry ");
1903 raise Program_Error;
1907 Write_Str (" declared at ");
1908 Write_Location (Sloc (Ent));
1911 Write_Str ("convention : ");
1914 case Convention (Ent) is
1915 when Convention_Ada =>
1918 when Convention_Ada_Pass_By_Copy =>
1919 Write_Str ("Ada_Pass_By_Copy");
1921 when Convention_Ada_Pass_By_Reference =>
1922 Write_Str ("Ada_Pass_By_Reference");
1924 when Convention_Intrinsic =>
1925 Write_Str ("Intrinsic");
1927 when Convention_Entry =>
1928 Write_Str ("Entry");
1930 when Convention_Protected =>
1931 Write_Str ("Protected");
1933 when Convention_Assembler =>
1934 Write_Str ("Assembler");
1936 when Convention_C =>
1939 when Convention_COBOL =>
1940 Write_Str ("COBOL");
1942 when Convention_CPP =>
1945 when Convention_Fortran =>
1946 Write_Str ("Fortran");
1948 when Convention_Stdcall =>
1949 Write_Str ("Stdcall");
1951 when Convention_Stubbed =>
1952 Write_Str ("Stubbed");
1955 if List_Representation_Info_To_JSON then
1957 Write_Str (" ""formal"": [");
1962 -- Find max length of formal name
1965 Form := First_Formal (Ent);
1966 while Present (Form) loop
1967 Get_Unqualified_Decoded_Name_String (Chars (Form));
1969 if Name_Len > Plen then
1976 -- Output formals and mechanisms
1978 Form := First_Formal (Ent);
1979 while Present (Form) loop
1980 Get_Unqualified_Decoded_Name_String (Chars (Form));
1981 Set_Casing (Unit_Casing);
1983 if List_Representation_Info_To_JSON then
1992 Write_Str (" ""name"": """);
1993 Write_Str (Name_Buffer (1 .. Name_Len));
1996 Write_Str (" ""mechanism"": """);
1997 Write_Mechanism (Mechanism (Form));
2001 while Name_Len <= Plen loop
2002 Name_Len := Name_Len + 1;
2003 Name_Buffer (Name_Len) := ' ';
2007 Write_Str (Name_Buffer (1 .. Plen + 1));
2008 Write_Str (": passed by ");
2010 Write_Mechanism (Mechanism (Form));
2017 if List_Representation_Info_To_JSON then
2022 if Ekind (Ent) = E_Function then
2023 if List_Representation_Info_To_JSON then
2025 Write_Str (" ""mechanism"": """);
2026 Write_Mechanism (Mechanism (Ent));
2029 Write_Str ("returns by ");
2030 Write_Mechanism (Mechanism (Ent));
2035 if not Is_Entry (Ent) then
2036 List_Linker_Section (Ent);
2039 if List_Representation_Info_To_JSON then
2043 end List_Subprogram_Info;
2045 --------------------
2046 -- List_Type_Info --
2047 --------------------
2049 procedure List_Type_Info (Ent : Entity_Id) is
2053 if List_Representation_Info_To_JSON then
2057 List_Common_Type_Info (Ent);
2059 -- Special stuff for fixed-point
2061 if Is_Fixed_Point_Type (Ent) then
2063 -- Write small (always a static constant)
2065 if List_Representation_Info_To_JSON then
2067 Write_Str (" ""Small"": ");
2068 UR_Write (Small_Value (Ent));
2072 Write_Str ("'Small use ");
2073 UR_Write (Small_Value (Ent));
2077 -- Write range if static
2080 R : constant Node_Id := Scalar_Range (Ent);
2083 if Nkind (Low_Bound (R)) = N_Real_Literal
2085 Nkind (High_Bound (R)) = N_Real_Literal
2087 if List_Representation_Info_To_JSON then
2089 Write_Str (" ""Range"": [ ");
2090 UR_Write (Realval (Low_Bound (R)));
2092 UR_Write (Realval (High_Bound (R)));
2097 Write_Str ("'Range use ");
2098 UR_Write (Realval (Low_Bound (R)));
2100 UR_Write (Realval (High_Bound (R)));
2107 List_Linker_Section (Ent);
2109 if List_Representation_Info_To_JSON then
2115 ----------------------
2116 -- Rep_Not_Constant --
2117 ----------------------
2119 function Rep_Not_Constant (Val : Node_Ref_Or_Val) return Boolean is
2121 if Val = No_Uint or else Val < 0 then
2126 end Rep_Not_Constant;
2132 function Rep_Value (Val : Node_Ref_Or_Val; D : Discrim_List) return Uint is
2134 function B (Val : Boolean) return Uint;
2135 -- Returns Uint_0 for False, Uint_1 for True
2137 function T (Val : Node_Ref_Or_Val) return Boolean;
2138 -- Returns True for 0, False for any non-zero (i.e. True)
2140 function V (Val : Node_Ref_Or_Val) return Uint;
2141 -- Internal recursive routine to evaluate tree
2143 function W (Val : Uint) return Word;
2144 -- Convert Val to Word, assuming Val is always in the Int range. This
2145 -- is a helper function for the evaluation of bitwise expressions like
2146 -- Bit_And_Expr, for which there is no direct support in uintp. Uint
2147 -- values out of the Int range are expected to be seen in such
2148 -- expressions only with overflowing byte sizes around, introducing
2149 -- inherent unreliabilities in computations anyway.
2155 function B (Val : Boolean) return Uint is
2168 function T (Val : Node_Ref_Or_Val) return Boolean is
2181 function V (Val : Node_Ref_Or_Val) return Uint is
2190 Node : Exp_Node renames Rep_Table.Table (-UI_To_Int (Val));
2195 if T (Node.Op1) then
2196 return V (Node.Op2);
2198 return V (Node.Op3);
2202 return V (Node.Op1) + V (Node.Op2);
2205 return V (Node.Op1) - V (Node.Op2);
2208 return V (Node.Op1) * V (Node.Op2);
2210 when Trunc_Div_Expr =>
2211 return V (Node.Op1) / V (Node.Op2);
2213 when Ceil_Div_Expr =>
2216 (V (Node.Op1) / UR_From_Uint (V (Node.Op2)));
2218 when Floor_Div_Expr =>
2221 (V (Node.Op1) / UR_From_Uint (V (Node.Op2)));
2223 when Trunc_Mod_Expr =>
2224 return V (Node.Op1) rem V (Node.Op2);
2226 when Floor_Mod_Expr =>
2227 return V (Node.Op1) mod V (Node.Op2);
2229 when Ceil_Mod_Expr =>
2232 Q := UR_Ceiling (L / UR_From_Uint (R));
2235 when Exact_Div_Expr =>
2236 return V (Node.Op1) / V (Node.Op2);
2239 return -V (Node.Op1);
2242 return UI_Min (V (Node.Op1), V (Node.Op2));
2245 return UI_Max (V (Node.Op1), V (Node.Op2));
2248 return UI_Abs (V (Node.Op1));
2250 when Truth_And_Expr =>
2251 return B (T (Node.Op1) and then T (Node.Op2));
2253 when Truth_Or_Expr =>
2254 return B (T (Node.Op1) or else T (Node.Op2));
2256 when Truth_Xor_Expr =>
2257 return B (T (Node.Op1) xor T (Node.Op2));
2259 when Truth_Not_Expr =>
2260 return B (not T (Node.Op1));
2262 when Bit_And_Expr =>
2265 return UI_From_Int (Int (W (L) and W (R)));
2268 return B (V (Node.Op1) < V (Node.Op2));
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));
2287 Sub : constant Int := UI_To_Int (Node.Op1);
2289 pragma Assert (Sub in D'Range);
2304 -- We use an unchecked conversion to map Int values to their Word
2305 -- bitwise equivalent, which we could not achieve with a normal type
2306 -- conversion for negative Ints. We want bitwise equivalents because W
2307 -- is used as a helper for bit operators like Bit_And_Expr, and can be
2308 -- called for negative Ints in the context of aligning expressions like
2309 -- X+Align & -Align.
2311 function W (Val : Uint) return Word is
2312 function To_Word is new Ada.Unchecked_Conversion (Int, Word);
2314 return To_Word (UI_To_Int (Val));
2317 -- Start of processing for Rep_Value
2320 if Val = No_Uint then
2332 procedure Spaces (N : Natural) is
2334 for J in 1 .. N loop
2343 procedure Tree_Read is
2345 Rep_Table.Tree_Read;
2352 procedure Tree_Write is
2354 Rep_Table.Tree_Write;
2357 ---------------------
2358 -- Write_Info_Line --
2359 ---------------------
2361 procedure Write_Info_Line (S : String) is
2363 Write_Repinfo_Line_Access.all (S (S'First .. S'Last - 1));
2364 end Write_Info_Line;
2366 ---------------------
2367 -- Write_Mechanism --
2368 ---------------------
2370 procedure Write_Mechanism (M : Mechanism_Type) is
2374 Write_Str ("default");
2380 Write_Str ("reference");
2383 raise Program_Error;
2385 end Write_Mechanism;
2387 ---------------------
2388 -- Write_Separator --
2389 ---------------------
2391 procedure Write_Separator is
2393 if Need_Separator then
2394 if List_Representation_Info_To_JSON then
2400 Need_Separator := True;
2402 end Write_Separator;
2404 -----------------------
2405 -- Write_Unknown_Val --
2406 -----------------------
2408 procedure Write_Unknown_Val is
2410 if List_Representation_Info_To_JSON then
2411 Write_Str ("""??""");
2415 end Write_Unknown_Val;
2421 procedure Write_Val (Val : Node_Ref_Or_Val; Paren : Boolean := False) is
2423 if Rep_Not_Constant (Val) then
2424 if List_Representation_Info < 3 or else Val = No_Uint then
2432 if Back_End_Layout then
2433 List_GCC_Expression (Val);
2435 Write_Name_Decoded (Chars (Get_Dynamic_SO_Entity (Val)));
2444 UI_Write (Val, Decimal);