1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2021, 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 procedure List_Entities
143 Bytes_Big_Endian : Boolean;
144 In_Subprogram : Boolean := False);
145 -- This procedure lists the entities associated with the entity E, starting
146 -- with the First_Entity and using the Next_Entity link. If a nested
147 -- package is found, entities within the package are recursively processed.
148 -- When recursing within a subprogram body, Is_Subprogram suppresses
149 -- duplicate information about signature.
151 procedure List_Name (Ent : Entity_Id);
152 -- List name of entity Ent in appropriate case. The name is listed with
153 -- full qualification up to but not including the compilation unit name.
155 procedure List_Array_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean);
156 -- List representation info for array type Ent
158 procedure List_Common_Type_Info (Ent : Entity_Id);
159 -- List common type info (name, size, alignment) for type Ent
161 procedure List_Linker_Section (Ent : Entity_Id);
162 -- List linker section for Ent (caller has checked that Ent is an entity
163 -- for which the Linker_Section_Pragma field is defined).
165 procedure List_Location (Ent : Entity_Id);
166 -- List location information for Ent
168 procedure List_Object_Info (Ent : Entity_Id);
169 -- List representation info for object Ent
171 procedure List_Record_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean);
172 -- List representation info for record type Ent
174 procedure List_Scalar_Storage_Order
176 Bytes_Big_Endian : Boolean);
177 -- List scalar storage order information for record or array type Ent.
178 -- Also includes bit order information for record types, if necessary.
180 procedure List_Subprogram_Info (Ent : Entity_Id);
181 -- List subprogram info for subprogram Ent
183 procedure List_Type_Info (Ent : Entity_Id);
184 -- List type info for type Ent
186 function Rep_Not_Constant (Val : Node_Ref_Or_Val) return Boolean;
187 -- Returns True if Val represents a variable value, and False if it
188 -- represents a value that is fixed at compile time.
190 procedure Spaces (N : Natural);
191 -- Output given number of spaces
193 procedure Write_Info_Line (S : String);
194 -- Routine to write a line to Repinfo output file. This routine is passed
195 -- as a special output procedure to Output.Set_Special_Output. Note that
196 -- Write_Info_Line is called with an EOL character at the end of each line,
197 -- as per the Output spec, but the internal call to the appropriate routine
198 -- in Osint requires that the end of line sequence be stripped off.
200 procedure Write_Mechanism (M : Mechanism_Type);
201 -- Writes symbolic string for mechanism represented by M
203 procedure Write_Separator;
204 -- Called before outputting anything for an entity. Ensures that
205 -- a separator precedes the output for a particular entity.
207 procedure Write_Unknown_Val;
208 -- Writes symbolic string for an unknown or non-representable value
210 procedure Write_Val (Val : Node_Ref_Or_Val; Paren : Boolean := False);
211 -- Given a representation value, write it out. No_Uint values or values
212 -- dependent on discriminants are written as two question marks. If the
213 -- flag Paren is set, then the output is surrounded in parentheses if it is
214 -- other than a simple value.
216 ------------------------
217 -- Create_Discrim_Ref --
218 ------------------------
220 function Create_Discrim_Ref (Discr : Entity_Id) return Node_Ref is
223 (Expr => Discrim_Val,
224 Op1 => Discriminant_Number (Discr));
225 end Create_Discrim_Ref;
227 ---------------------------
228 -- Create_Dynamic_SO_Ref --
229 ---------------------------
231 function Create_Dynamic_SO_Ref (E : Entity_Id) return Dynamic_SO_Ref is
233 Dynamic_SO_Entity_Table.Append (E);
234 return UI_From_Int (-Dynamic_SO_Entity_Table.Last);
235 end Create_Dynamic_SO_Ref;
243 Op1 : Node_Ref_Or_Val;
244 Op2 : Node_Ref_Or_Val := No_Uint;
245 Op3 : Node_Ref_Or_Val := No_Uint) return Node_Ref
253 return UI_From_Int (-Rep_Table.Last);
260 function Entity_Hash (Id : Entity_Id) return Entity_Header_Num is
262 return Entity_Header_Num (Id mod Relevant_Entities_Size);
265 ---------------------------
266 -- Get_Dynamic_SO_Entity --
267 ---------------------------
269 function Get_Dynamic_SO_Entity (U : Dynamic_SO_Ref) return Entity_Id is
271 return Dynamic_SO_Entity_Table.Table (-UI_To_Int (U));
272 end Get_Dynamic_SO_Entity;
274 -----------------------
275 -- Is_Dynamic_SO_Ref --
276 -----------------------
278 function Is_Dynamic_SO_Ref (U : SO_Ref) return Boolean is
281 end Is_Dynamic_SO_Ref;
283 ----------------------
284 -- Is_Static_SO_Ref --
285 ----------------------
287 function Is_Static_SO_Ref (U : SO_Ref) return Boolean is
290 end Is_Static_SO_Ref;
296 procedure lgx (U : Node_Ref_Or_Val) is
298 List_GCC_Expression (U);
302 ----------------------
303 -- List_Array_Info --
304 ----------------------
306 procedure List_Array_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is
310 if List_Representation_Info_To_JSON then
314 List_Common_Type_Info (Ent);
316 if List_Representation_Info_To_JSON then
318 Write_Str (" ""Component_Size"": ");
319 Write_Val (Component_Size (Ent));
323 Write_Str ("'Component_Size use ");
324 Write_Val (Component_Size (Ent));
328 List_Scalar_Storage_Order (Ent, Bytes_Big_Endian);
330 List_Linker_Section (Ent);
332 if List_Representation_Info_To_JSON then
337 -- The component type is relevant for an array
339 if List_Representation_Info = 4
340 and then Is_Itype (Component_Type (Base_Type (Ent)))
342 Relevant_Entities.Set (Component_Type (Base_Type (Ent)), True);
346 ---------------------------
347 -- List_Common_Type_Info --
348 ---------------------------
350 procedure List_Common_Type_Info (Ent : Entity_Id) is
352 if List_Representation_Info_To_JSON then
353 Write_Str (" ""name"": """);
359 -- Do not list size info for unconstrained arrays, not meaningful
361 if Is_Array_Type (Ent) and then not Is_Constrained (Ent) then
365 -- If Esize and RM_Size are the same, list as Size. This is a common
366 -- case, which we may as well list in simple form.
368 if Esize (Ent) = RM_Size (Ent) then
369 if List_Representation_Info_To_JSON then
370 Write_Str (" ""Size"": ");
371 Write_Val (Esize (Ent));
376 Write_Str ("'Size use ");
377 Write_Val (Esize (Ent));
381 -- Otherwise list size values separately
384 if List_Representation_Info_To_JSON then
385 Write_Str (" ""Object_Size"": ");
386 Write_Val (Esize (Ent));
389 Write_Str (" ""Value_Size"": ");
390 Write_Val (RM_Size (Ent));
396 Write_Str ("'Object_Size use ");
397 Write_Val (Esize (Ent));
402 Write_Str ("'Value_Size use ");
403 Write_Val (RM_Size (Ent));
409 if List_Representation_Info_To_JSON then
410 Write_Str (" ""Alignment"": ");
411 Write_Val (Alignment (Ent));
415 Write_Str ("'Alignment use ");
416 Write_Val (Alignment (Ent));
419 end List_Common_Type_Info;
425 procedure List_Entities
427 Bytes_Big_Endian : Boolean;
428 In_Subprogram : Boolean := False)
433 function Find_Declaration (E : Entity_Id) return Node_Id;
434 -- Utility to retrieve declaration node for entity in the
435 -- case of package bodies and subprograms.
437 ----------------------
438 -- Find_Declaration --
439 ----------------------
441 function Find_Declaration (E : Entity_Id) return Node_Id is
447 and then Nkind (Decl) /= N_Package_Body
448 and then Nkind (Decl) /= N_Subprogram_Declaration
449 and then Nkind (Decl) /= N_Subprogram_Body
451 Decl := Parent (Decl);
455 end Find_Declaration;
457 -- Start of processing for List_Entities
460 -- List entity if we have one, and it is not a renaming declaration.
461 -- For renamings, we don't get proper information, and really it makes
462 -- sense to restrict the output to the renamed entity.
465 and then Nkind (Declaration_Node (Ent)) not in N_Renaming_Declaration
466 and then not Is_Ignored_Ghost_Entity (Ent)
468 -- If entity is a subprogram and we are listing mechanisms,
469 -- then we need to list mechanisms for this entity. We skip this
470 -- if it is a nested subprogram, as the information has already
471 -- been produced when listing the enclosing scope.
473 if List_Representation_Info_Mechanisms
474 and then (Is_Subprogram (Ent)
475 or else Ekind (Ent) = E_Entry
476 or else Ekind (Ent) = E_Entry_Family)
477 and then not In_Subprogram
479 List_Subprogram_Info (Ent);
482 E := First_Entity (Ent);
483 while Present (E) loop
484 -- We list entities that come from source (excluding private or
485 -- incomplete types or deferred constants, for which we will list
486 -- the information for the full view). If requested, we also list
487 -- relevant entities that have been generated when processing the
488 -- original entities coming from source. But if debug flag A is
489 -- set, then all entities are listed.
491 if ((Comes_From_Source (E)
492 or else (Ekind (E) = E_Block
494 Nkind (Parent (E)) = N_Implicit_Label_Declaration
496 Comes_From_Source (Label_Construct (Parent (E)))))
497 and then not Is_Incomplete_Or_Private_Type (E)
498 and then not (Ekind (E) = E_Constant
499 and then Present (Full_View (E))))
500 or else (List_Representation_Info = 4
501 and then Relevant_Entities.Get (E))
502 or else Debug_Flag_AA
504 if Is_Subprogram (E) then
505 if List_Representation_Info_Mechanisms then
506 List_Subprogram_Info (E);
509 -- Recurse into entities local to subprogram
511 List_Entities (E, Bytes_Big_Endian, True);
513 elsif Ekind (E) in E_Entry
517 if List_Representation_Info_Mechanisms then
518 List_Subprogram_Info (E);
521 elsif Is_Record_Type (E) then
522 if List_Representation_Info >= 1 then
523 List_Record_Info (E, Bytes_Big_Endian);
526 -- Recurse into entities local to a record type
528 if List_Representation_Info = 4 then
529 List_Entities (E, Bytes_Big_Endian, False);
532 elsif Is_Array_Type (E) then
533 if List_Representation_Info >= 1 then
534 List_Array_Info (E, Bytes_Big_Endian);
537 elsif Is_Type (E) then
538 if List_Representation_Info >= 2 then
542 -- Note that formals are not annotated so we skip them here
544 elsif Ekind (E) in E_Constant
548 if List_Representation_Info >= 2 then
549 List_Object_Info (E);
553 -- Recurse into nested package, but not if they are package
554 -- renamings (in particular renamings of the enclosing package,
555 -- as for some Java bindings and for generic instances).
557 if Ekind (E) = E_Package then
558 if No (Renamed_Object (E)) then
559 List_Entities (E, Bytes_Big_Endian);
562 -- Recurse into bodies
564 elsif Ekind (E) in E_Package_Body
571 List_Entities (E, Bytes_Big_Endian);
573 -- Recurse into blocks
575 elsif Ekind (E) = E_Block then
576 List_Entities (E, Bytes_Big_Endian);
583 -- For a package body, the entities of the visible subprograms are
584 -- declared in the corresponding spec. Iterate over its entities in
585 -- order to handle properly the subprogram bodies. Skip bodies in
586 -- subunits, which are listed independently.
588 if Ekind (Ent) = E_Package_Body
589 and then Present (Corresponding_Spec (Find_Declaration (Ent)))
591 E := First_Entity (Corresponding_Spec (Find_Declaration (Ent)));
592 while Present (E) loop
595 Nkind (Find_Declaration (E)) = N_Subprogram_Declaration
597 Body_E := Corresponding_Body (Find_Declaration (E));
601 Nkind (Parent (Find_Declaration (Body_E))) /= N_Subunit
603 List_Entities (Body_E, Bytes_Big_Endian);
613 -------------------------
614 -- List_GCC_Expression --
615 -------------------------
617 procedure List_GCC_Expression (U : Node_Ref_Or_Val) is
619 procedure Print_Expr (Val : Node_Ref_Or_Val);
620 -- Internal recursive procedure to print expression
626 procedure Print_Expr (Val : Node_Ref_Or_Val) is
629 UI_Write (Val, Decimal);
633 Node : Exp_Node renames Rep_Table.Table (-UI_To_Int (Val));
635 procedure Unop (S : String);
636 -- Output text for unary operator with S being operator name
638 procedure Binop (S : String);
639 -- Output text for binary operator with S being operator name
645 procedure Unop (S : String) is
647 if List_Representation_Info_To_JSON then
648 Write_Str ("{ ""code"": """);
649 if S (S'Last) = ' ' then
650 Write_Str (S (S'First .. S'Last - 1));
654 Write_Str (""", ""operands"": [ ");
655 Print_Expr (Node.Op1);
659 Print_Expr (Node.Op1);
667 procedure Binop (S : String) is
669 if List_Representation_Info_To_JSON then
670 Write_Str ("{ ""code"": """);
671 Write_Str (S (S'First + 1 .. S'Last - 1));
672 Write_Str (""", ""operands"": [ ");
673 Print_Expr (Node.Op1);
675 Print_Expr (Node.Op2);
679 Print_Expr (Node.Op1);
681 Print_Expr (Node.Op2);
686 -- Start of processing for Print_Expr
691 if List_Representation_Info_To_JSON then
692 Write_Str ("{ ""code"": ""?<>""");
693 Write_Str (", ""operands"": [ ");
694 Print_Expr (Node.Op1);
696 Print_Expr (Node.Op2);
698 Print_Expr (Node.Op3);
702 Print_Expr (Node.Op1);
703 Write_Str (" then ");
704 Print_Expr (Node.Op2);
705 Write_Str (" else ");
706 Print_Expr (Node.Op3);
719 when Trunc_Div_Expr =>
722 when Ceil_Div_Expr =>
725 when Floor_Div_Expr =>
728 when Trunc_Mod_Expr =>
731 when Ceil_Mod_Expr =>
734 when Floor_Mod_Expr =>
737 when Exact_Div_Expr =>
752 when Truth_And_Expr =>
755 when Truth_Or_Expr =>
758 when Truth_Xor_Expr =>
761 when Truth_Not_Expr =>
795 -- Start of processing for List_GCC_Expression
803 end List_GCC_Expression;
805 -------------------------
806 -- List_Linker_Section --
807 -------------------------
809 procedure List_Linker_Section (Ent : Entity_Id) is
814 if Present (Linker_Section_Pragma (Ent)) then
815 Args := Pragma_Argument_Associations (Linker_Section_Pragma (Ent));
816 Sect := Expr_Value_S (Get_Pragma_Arg (Last (Args)));
818 if List_Representation_Info_To_JSON then
820 Write_Str (" ""Linker_Section"": """);
822 Write_Str ("pragma Linker_Section (");
827 pragma Assert (Nkind (Sect) = N_String_Literal);
828 String_To_Name_Buffer (Strval (Sect));
829 Write_Str (Name_Buffer (1 .. Name_Len));
831 if not List_Representation_Info_To_JSON then
835 end List_Linker_Section;
841 procedure List_Location (Ent : Entity_Id) is
843 pragma Assert (List_Representation_Info_To_JSON);
844 Write_Str (" ""location"": """);
845 Write_Location (Sloc (Ent));
853 procedure List_Name (Ent : Entity_Id) is
857 -- List the qualified name recursively, except
858 -- at compilation unit level in default mode.
860 if Is_Compilation_Unit (Ent) then
862 elsif not Is_Compilation_Unit (Scope (Ent))
863 or else List_Representation_Info_To_JSON
865 List_Name (Scope (Ent));
869 Get_Unqualified_Decoded_Name_String (Chars (Ent));
870 Set_Casing (Unit_Casing);
872 -- The name of operators needs to be properly escaped for JSON
874 for J in 1 .. Name_Len loop
875 C := Name_Buffer (J);
876 if C = '"' and then List_Representation_Info_To_JSON then
883 ---------------------
884 -- List_Object_Info --
885 ---------------------
887 procedure List_Object_Info (Ent : Entity_Id) is
891 if List_Representation_Info_To_JSON then
894 Write_Str (" ""name"": """);
899 Write_Str (" ""Size"": ");
900 Write_Val (Esize (Ent));
903 Write_Str (" ""Alignment"": ");
904 Write_Val (Alignment (Ent));
906 List_Linker_Section (Ent);
913 Write_Str ("'Size use ");
914 Write_Val (Esize (Ent));
919 Write_Str ("'Alignment use ");
920 Write_Val (Alignment (Ent));
923 List_Linker_Section (Ent);
926 -- The type is relevant for an object
928 if List_Representation_Info = 4 and then Is_Itype (Etype (Ent)) then
929 Relevant_Entities.Set (Etype (Ent), True);
931 end List_Object_Info;
933 ----------------------
934 -- List_Record_Info --
935 ----------------------
937 procedure List_Record_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is
938 procedure Compute_Max_Length
940 Starting_Position : Uint := Uint_0;
941 Starting_First_Bit : Uint := Uint_0;
942 Prefix_Length : Natural := 0);
943 -- Internal recursive procedure to compute the max length
945 procedure List_Component_Layout
947 Starting_Position : Uint := Uint_0;
948 Starting_First_Bit : Uint := Uint_0;
949 Prefix : String := "";
950 Indent : Natural := 0);
951 -- Procedure to display the layout of a single component
953 procedure List_Record_Layout
955 Starting_Position : Uint := Uint_0;
956 Starting_First_Bit : Uint := Uint_0;
957 Prefix : String := "");
958 -- Internal recursive procedure to display the layout
960 procedure List_Structural_Record_Layout
962 Outer_Ent : Entity_Id;
963 Variant : Node_Id := Empty;
964 Indent : Natural := 0);
965 -- Internal recursive procedure to display the structural layout
967 Incomplete_Layout : exception;
968 -- Exception raised if the layout is incomplete in -gnatc mode
970 Not_In_Extended_Main : exception;
971 -- Exception raised when an ancestor is not declared in the main unit
973 Max_Name_Length : Natural := 0;
974 Max_Spos_Length : Natural := 0;
976 ------------------------
977 -- Compute_Max_Length --
978 ------------------------
980 procedure Compute_Max_Length
982 Starting_Position : Uint := Uint_0;
983 Starting_First_Bit : Uint := Uint_0;
984 Prefix_Length : Natural := 0)
989 Comp := First_Component_Or_Discriminant (Ent);
990 while Present (Comp) loop
992 -- Skip a completely hidden discriminant or a discriminant in an
993 -- unchecked union (since it is not there).
995 if Ekind (Comp) = E_Discriminant
996 and then (Is_Completely_Hidden (Comp)
997 or else Is_Unchecked_Union (Ent))
1002 -- Skip _Parent component in extension (to avoid overlap)
1004 if Chars (Comp) = Name_uParent then
1011 Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp));
1012 Bofs : constant Uint := Component_Bit_Offset (Comp);
1018 Name_Length : Natural;
1021 Get_Decoded_Name_String (Chars (Comp));
1022 Name_Length := Prefix_Length + Name_Len;
1024 if Rep_Not_Constant (Bofs) then
1026 -- If the record is not packed, then we know that all fields
1027 -- whose position is not specified have starting normalized
1028 -- bit position of zero.
1030 if Unknown_Normalized_First_Bit (Comp)
1031 and then not Is_Packed (Ent)
1033 Set_Normalized_First_Bit (Comp, Uint_0);
1036 UI_Image_Length := 2; -- For "??" marker
1039 Fbit := Bofs mod SSU;
1041 -- Complete annotation in case not done
1043 if Unknown_Normalized_First_Bit (Comp) then
1044 Set_Normalized_Position (Comp, Npos);
1045 Set_Normalized_First_Bit (Comp, Fbit);
1048 Spos := Starting_Position + Npos;
1049 Sbit := Starting_First_Bit + Fbit;
1056 -- If extended information is requested, recurse fully into
1057 -- record components, i.e. skip the outer level.
1059 if List_Representation_Info_Extended
1060 and then Is_Record_Type (Ctyp)
1062 Compute_Max_Length (Ctyp, Spos, Sbit, Name_Length + 1);
1069 Max_Name_Length := Natural'Max (Max_Name_Length, Name_Length);
1071 Natural'Max (Max_Spos_Length, UI_Image_Length);
1075 Next_Component_Or_Discriminant (Comp);
1077 end Compute_Max_Length;
1079 ---------------------------
1080 -- List_Component_Layout --
1081 ---------------------------
1083 procedure List_Component_Layout
1085 Starting_Position : Uint := Uint_0;
1086 Starting_First_Bit : Uint := Uint_0;
1087 Prefix : String := "";
1088 Indent : Natural := 0)
1090 Esiz : constant Uint := Esize (Ent);
1091 Npos : constant Uint := Normalized_Position (Ent);
1092 Fbit : constant Uint := Normalized_First_Bit (Ent);
1098 if List_Representation_Info_To_JSON then
1102 Write_Str (" ""name"": """);
1104 Write_Str (Name_Buffer (1 .. Name_Len));
1106 if Ekind (Ent) = E_Discriminant then
1108 Write_Str (" ""discriminant"": ");
1109 UI_Write (Discriminant_Number (Ent), Decimal);
1113 Write_Str (" ""Position"": ");
1117 Write_Str (Name_Buffer (1 .. Name_Len));
1118 Spaces (Max_Name_Length - Prefix'Length - Name_Len);
1122 if Known_Static_Normalized_Position (Ent) then
1123 Spos := Starting_Position + Npos;
1124 Sbit := Starting_First_Bit + Fbit;
1131 Spaces (Max_Spos_Length - UI_Image_Length);
1132 Write_Str (UI_Image_Buffer (1 .. UI_Image_Length));
1134 elsif Known_Normalized_Position (Ent)
1135 and then List_Representation_Info >= 3
1137 Spaces (Max_Spos_Length - 2);
1139 if Starting_Position /= Uint_0 then
1140 UI_Write (Starting_Position, Decimal);
1150 if List_Representation_Info_To_JSON then
1153 Write_Str (" ""First_Bit"": ");
1155 Write_Str (" range ");
1158 Sbit := Starting_First_Bit + Fbit;
1164 UI_Write (Sbit, Decimal);
1166 if List_Representation_Info_To_JSON then
1169 Write_Str (" ""Size"": ");
1174 -- Allowing Uint_0 here is an annoying special case. Really this
1175 -- should be a fine Esize value but currently it means unknown,
1176 -- except that we know after gigi has back annotated that a size
1177 -- of zero is real, since otherwise gigi back annotates using
1178 -- No_Uint as the value to indicate unknown.
1180 if (Esize (Ent) = Uint_0 or else Known_Static_Esize (Ent))
1181 and then Known_Static_Normalized_First_Bit (Ent)
1183 Lbit := Sbit + Esiz - 1;
1185 if List_Representation_Info_To_JSON then
1186 UI_Write (Esiz, Decimal);
1188 if Lbit >= 0 and then Lbit < 10 then
1192 UI_Write (Lbit, Decimal);
1195 -- The test for Esize (Ent) not Uint_0 here is an annoying special
1196 -- case. Officially a value of zero for Esize means unknown, but
1197 -- here we use the fact that we know that gigi annotates Esize with
1198 -- No_Uint, not Uint_0. Really everyone should use No_Uint???
1200 elsif List_Representation_Info < 3
1201 or else (Esize (Ent) /= Uint_0 and then Unknown_Esize (Ent))
1205 -- List_Representation >= 3 and Known_Esize (Ent)
1208 Write_Val (Esiz, Paren => not List_Representation_Info_To_JSON);
1210 -- Add appropriate first bit offset
1212 if not List_Representation_Info_To_JSON then
1221 Write_Int (UI_To_Int (Sbit) - 1);
1226 if List_Representation_Info_To_JSON then
1234 -- The type is relevant for a component
1236 if List_Representation_Info = 4 and then Is_Itype (Etype (Ent)) then
1237 Relevant_Entities.Set (Etype (Ent), True);
1239 end List_Component_Layout;
1241 ------------------------
1242 -- List_Record_Layout --
1243 ------------------------
1245 procedure List_Record_Layout
1247 Starting_Position : Uint := Uint_0;
1248 Starting_First_Bit : Uint := Uint_0;
1249 Prefix : String := "")
1252 First : Boolean := True;
1255 Comp := First_Component_Or_Discriminant (Ent);
1256 while Present (Comp) loop
1258 -- Skip a completely hidden discriminant or a discriminant in an
1259 -- unchecked union (since it is not there).
1261 if Ekind (Comp) = E_Discriminant
1262 and then (Is_Completely_Hidden (Comp)
1263 or else Is_Unchecked_Union (Ent))
1268 -- Skip _Parent component in extension (to avoid overlap)
1270 if Chars (Comp) = Name_uParent then
1277 Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp));
1278 Npos : constant Uint := Normalized_Position (Comp);
1279 Fbit : constant Uint := Normalized_First_Bit (Comp);
1284 Get_Decoded_Name_String (Chars (Comp));
1285 Set_Casing (Unit_Casing);
1287 -- If extended information is requested, recurse fully into
1288 -- record components, i.e. skip the outer level.
1290 if List_Representation_Info_Extended
1291 and then Is_Record_Type (Ctyp)
1292 and then Known_Static_Normalized_Position (Comp)
1293 and then Known_Static_Normalized_First_Bit (Comp)
1295 Spos := Starting_Position + Npos;
1296 Sbit := Starting_First_Bit + Fbit;
1303 List_Record_Layout (Ctyp,
1304 Spos, Sbit, Prefix & Name_Buffer (1 .. Name_Len) & ".");
1309 if List_Representation_Info_To_JSON then
1318 List_Component_Layout (Comp,
1319 Starting_Position, Starting_First_Bit, Prefix);
1323 Next_Component_Or_Discriminant (Comp);
1325 end List_Record_Layout;
1327 -----------------------------------
1328 -- List_Structural_Record_Layout --
1329 -----------------------------------
1331 procedure List_Structural_Record_Layout
1333 Outer_Ent : Entity_Id;
1334 Variant : Node_Id := Empty;
1335 Indent : Natural := 0)
1337 function Derived_Discriminant (Disc : Entity_Id) return Entity_Id;
1338 -- This function assumes that Outer_Ent is an extension of Ent.
1339 -- Disc is a discriminant of Ent that does not itself constrain a
1340 -- discriminant of the parent type of Ent. Return the discriminant
1341 -- of Outer_Ent that ultimately constrains Disc, if any.
1343 ----------------------------
1344 -- Derived_Discriminant --
1345 ----------------------------
1347 function Derived_Discriminant (Disc : Entity_Id) return Entity_Id is
1348 Corr_Disc : Entity_Id;
1349 Derived_Disc : Entity_Id;
1352 Derived_Disc := First_Discriminant (Outer_Ent);
1354 -- Loop over the discriminants of the extension
1356 while Present (Derived_Disc) loop
1358 -- Check if this discriminant constrains another discriminant.
1359 -- If so, find the ultimately constrained discriminant and
1360 -- compare with the original components in the base type.
1362 if Present (Corresponding_Discriminant (Derived_Disc)) then
1363 Corr_Disc := Corresponding_Discriminant (Derived_Disc);
1365 while Present (Corresponding_Discriminant (Corr_Disc)) loop
1366 Corr_Disc := Corresponding_Discriminant (Corr_Disc);
1369 if Original_Record_Component (Corr_Disc) =
1370 Original_Record_Component (Disc)
1372 return Derived_Disc;
1376 Next_Discriminant (Derived_Disc);
1379 -- Disc is not constrained by a discriminant of Outer_Ent
1382 end Derived_Discriminant;
1384 -- Local declarations
1387 Comp_List : Node_Id;
1388 First : Boolean := True;
1391 -- Start of processing for List_Structural_Record_Layout
1394 -- If we are dealing with a variant, just process the components
1396 if Present (Variant) then
1397 Comp_List := Component_List (Variant);
1399 -- Otherwise, we are dealing with the full record and need to get
1400 -- to its definition in order to retrieve its structural layout.
1404 Definition : Node_Id :=
1405 Type_Definition (Declaration_Node (Ent));
1407 Is_Extension : constant Boolean :=
1408 Is_Tagged_Type (Ent)
1409 and then Nkind (Definition) =
1410 N_Derived_Type_Definition;
1413 Listed_Disc : Entity_Id;
1414 Parent_Type : Entity_Id;
1417 -- If this is an extension, first list the layout of the parent
1418 -- and then proceed to the extension part, if any.
1420 if Is_Extension then
1421 Parent_Type := Parent_Subtype (Ent);
1422 if No (Parent_Type) then
1423 raise Incomplete_Layout;
1426 if Is_Private_Type (Parent_Type) then
1427 Parent_Type := Full_View (Parent_Type);
1428 pragma Assert (Present (Parent_Type));
1431 Parent_Type := Base_Type (Parent_Type);
1432 if not In_Extended_Main_Source_Unit (Parent_Type) then
1433 raise Not_In_Extended_Main;
1436 List_Structural_Record_Layout (Parent_Type, Outer_Ent);
1439 if Present (Record_Extension_Part (Definition)) then
1440 Definition := Record_Extension_Part (Definition);
1444 -- If the record has discriminants and is not an unchecked
1445 -- union, then display them now. Note that, even if this is
1446 -- a structural layout, we list the visible discriminants.
1448 if Has_Discriminants (Ent)
1449 and then not Is_Unchecked_Union (Ent)
1451 Disc := First_Discriminant (Ent);
1452 while Present (Disc) loop
1454 -- If this is a record extension and the discriminant is
1455 -- the renaming of another discriminant, skip it.
1458 and then Present (Corresponding_Discriminant (Disc))
1463 -- If this is the parent type of an extension, retrieve
1464 -- the derived discriminant from the extension, if any.
1466 if Ent /= Outer_Ent then
1467 Listed_Disc := Derived_Discriminant (Disc);
1469 if No (Listed_Disc) then
1473 Listed_Disc := Disc;
1476 Get_Decoded_Name_String (Chars (Listed_Disc));
1477 Set_Casing (Unit_Casing);
1486 List_Component_Layout (Listed_Disc, Indent => Indent);
1489 Next_Discriminant (Disc);
1493 Comp_List := Component_List (Definition);
1497 -- Bail out for the null record
1499 if No (Comp_List) then
1503 -- Now deal with the regular components, if any
1505 if Present (Component_Items (Comp_List)) then
1506 Comp := First_Non_Pragma (Component_Items (Comp_List));
1507 while Present (Comp) loop
1509 -- Skip _Parent component in extension (to avoid overlap)
1511 if Chars (Defining_Identifier (Comp)) = Name_uParent then
1515 Get_Decoded_Name_String (Chars (Defining_Identifier (Comp)));
1516 Set_Casing (Unit_Casing);
1525 List_Component_Layout
1526 (Defining_Identifier (Comp), Indent => Indent);
1529 Next_Non_Pragma (Comp);
1533 -- We are done if there is no variant part
1535 if No (Variant_Part (Comp_List)) then
1543 Write_Str (" ""variant"" : [");
1545 -- Otherwise we recurse on each variant
1547 Var := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
1549 while Present (Var) loop
1560 Write_Str (" ""present"": ");
1561 Write_Val (Present_Expr (Var));
1564 Write_Str (" ""record"": [");
1566 List_Structural_Record_Layout (Ent, Outer_Ent, Var, Indent + 4);
1573 Next_Non_Pragma (Var);
1575 end List_Structural_Record_Layout;
1577 -- Start of processing for List_Record_Info
1582 if List_Representation_Info_To_JSON then
1586 List_Common_Type_Info (Ent);
1588 -- First find out max line length and max starting position
1589 -- length, for the purpose of lining things up nicely.
1591 Compute_Max_Length (Ent);
1593 -- Then do actual output based on those values
1595 if List_Representation_Info_To_JSON then
1597 Write_Str (" ""record"": [");
1599 -- ??? We can output structural layout only for base types fully
1600 -- declared in the extended main source unit for the time being,
1601 -- because otherwise declarations might not be processed at all.
1603 if Is_Base_Type (Ent) then
1605 List_Structural_Record_Layout (Ent, Ent);
1608 when Incomplete_Layout
1609 | Not_In_Extended_Main
1611 List_Record_Layout (Ent);
1614 raise Program_Error;
1617 List_Record_Layout (Ent);
1625 Write_Line (" use record");
1627 List_Record_Layout (Ent);
1629 Write_Line ("end record;");
1632 List_Scalar_Storage_Order (Ent, Bytes_Big_Endian);
1634 List_Linker_Section (Ent);
1636 if List_Representation_Info_To_JSON then
1641 -- The type is relevant for a record subtype
1643 if List_Representation_Info = 4
1644 and then not Is_Base_Type (Ent)
1645 and then Is_Itype (Etype (Ent))
1647 Relevant_Entities.Set (Etype (Ent), True);
1649 end List_Record_Info;
1655 procedure List_Rep_Info (Bytes_Big_Endian : Boolean) is
1659 if List_Representation_Info /= 0
1660 or else List_Representation_Info_Mechanisms
1662 -- For the normal case, we output a single JSON stream
1664 if not List_Representation_Info_To_File
1665 and then List_Representation_Info_To_JSON
1668 Need_Separator := False;
1671 for U in Main_Unit .. Last_Unit loop
1672 if In_Extended_Main_Source_Unit (Cunit_Entity (U)) then
1673 Unit_Casing := Identifier_Casing (Source_Index (U));
1675 if List_Representation_Info = 4 then
1676 Relevant_Entities.Reset;
1679 -- Normal case, list to standard output
1681 if not List_Representation_Info_To_File then
1682 if not List_Representation_Info_To_JSON then
1684 Write_Str ("Representation information for unit ");
1685 Write_Unit_Name (Unit_Name (U));
1689 for J in 1 .. Col - 1 loop
1694 Need_Separator := True;
1697 List_Entities (Cunit_Entity (U), Bytes_Big_Endian);
1699 -- List representation information to file
1702 Create_Repinfo_File_Access.all
1703 (Get_Name_String (File_Name (Source_Index (U))));
1704 Set_Special_Output (Write_Info_Line'Access);
1705 if List_Representation_Info_To_JSON then
1708 Need_Separator := False;
1709 List_Entities (Cunit_Entity (U), Bytes_Big_Endian);
1710 if List_Representation_Info_To_JSON then
1713 Cancel_Special_Output;
1714 Close_Repinfo_File_Access.all;
1719 if not List_Representation_Info_To_File
1720 and then List_Representation_Info_To_JSON
1727 -------------------------------
1728 -- List_Scalar_Storage_Order --
1729 -------------------------------
1731 procedure List_Scalar_Storage_Order
1733 Bytes_Big_Endian : Boolean)
1735 procedure List_Attr (Attr_Name : String; Is_Reversed : Boolean);
1736 -- Show attribute definition clause for Attr_Name (an endianness
1737 -- attribute), depending on whether or not the endianness is reversed
1738 -- compared to native endianness.
1744 procedure List_Attr (Attr_Name : String; Is_Reversed : Boolean) is
1746 if List_Representation_Info_To_JSON then
1749 Write_Str (Attr_Name);
1750 Write_Str (""": ""System.");
1755 Write_Str (Attr_Name);
1756 Write_Str (" use System.");
1759 if Bytes_Big_Endian xor Is_Reversed then
1765 Write_Str ("_Order_First");
1766 if List_Representation_Info_To_JSON then
1773 List_SSO : constant Boolean :=
1774 Has_Rep_Item (Ent, Name_Scalar_Storage_Order)
1775 or else SSO_Set_Low_By_Default (Ent)
1776 or else SSO_Set_High_By_Default (Ent);
1777 -- Scalar_Storage_Order is displayed if specified explicitly or set by
1778 -- Default_Scalar_Storage_Order.
1780 -- Start of processing for List_Scalar_Storage_Order
1783 -- For record types, list Bit_Order if not default, or if SSO is shown
1785 -- Also, when -gnatR4 is in effect always list bit order and scalar
1786 -- storage order explicitly, so that you don't need to know the native
1787 -- endianness of the target for which the output was produced in order
1790 if Is_Record_Type (Ent)
1792 or else Reverse_Bit_Order (Ent)
1793 or else List_Representation_Info = 4)
1795 List_Attr ("Bit_Order", Reverse_Bit_Order (Ent));
1798 -- List SSO if required. If not, then storage is supposed to be in
1801 if List_SSO or else List_Representation_Info = 4 then
1802 List_Attr ("Scalar_Storage_Order", Reverse_Storage_Order (Ent));
1804 pragma Assert (not Reverse_Storage_Order (Ent));
1807 end List_Scalar_Storage_Order;
1809 --------------------------
1810 -- List_Subprogram_Info --
1811 --------------------------
1813 procedure List_Subprogram_Info (Ent : Entity_Id) is
1814 First : Boolean := True;
1821 if List_Representation_Info_To_JSON then
1823 Write_Str (" ""name"": """);
1826 List_Location (Ent);
1828 Write_Str (" ""Convention"": """);
1832 Write_Str ("function ");
1835 Write_Str ("operator ");
1838 Write_Str ("procedure ");
1840 when E_Subprogram_Type =>
1841 Write_Str ("type ");
1846 Write_Str ("entry ");
1849 raise Program_Error;
1853 Write_Str (" declared at ");
1854 Write_Location (Sloc (Ent));
1857 Write_Str ("convention : ");
1860 case Convention (Ent) is
1861 when Convention_Ada =>
1864 when Convention_Ada_Pass_By_Copy =>
1865 Write_Str ("Ada_Pass_By_Copy");
1867 when Convention_Ada_Pass_By_Reference =>
1868 Write_Str ("Ada_Pass_By_Reference");
1870 when Convention_Intrinsic =>
1871 Write_Str ("Intrinsic");
1873 when Convention_Entry =>
1874 Write_Str ("Entry");
1876 when Convention_Protected =>
1877 Write_Str ("Protected");
1879 when Convention_Assembler =>
1880 Write_Str ("Assembler");
1882 when Convention_C =>
1885 when Convention_C_Variadic =>
1888 Convention_Id'Pos (Convention (Ent)) -
1889 Convention_Id'Pos (Convention_C_Variadic_0);
1891 Write_Str ("C_Variadic_");
1896 pragma Assert (N < 10);
1897 Write_Char (Character'Val (Character'Pos ('0') + N));
1900 when Convention_COBOL =>
1901 Write_Str ("COBOL");
1903 when Convention_CPP =>
1906 when Convention_Fortran =>
1907 Write_Str ("Fortran");
1909 when Convention_Stdcall =>
1910 Write_Str ("Stdcall");
1912 when Convention_Stubbed =>
1913 Write_Str ("Stubbed");
1916 if List_Representation_Info_To_JSON then
1918 Write_Str (" ""formal"": [");
1923 -- Find max length of formal name
1926 Form := First_Formal (Ent);
1927 while Present (Form) loop
1928 Get_Unqualified_Decoded_Name_String (Chars (Form));
1930 if Name_Len > Plen then
1937 -- Output formals and mechanisms
1939 Form := First_Formal (Ent);
1940 while Present (Form) loop
1941 Get_Unqualified_Decoded_Name_String (Chars (Form));
1942 Set_Casing (Unit_Casing);
1944 if List_Representation_Info_To_JSON then
1953 Write_Str (" ""name"": """);
1954 Write_Str (Name_Buffer (1 .. Name_Len));
1957 Write_Str (" ""mechanism"": """);
1958 Write_Mechanism (Mechanism (Form));
1962 while Name_Len <= Plen loop
1963 Name_Len := Name_Len + 1;
1964 Name_Buffer (Name_Len) := ' ';
1968 Write_Str (Name_Buffer (1 .. Plen + 1));
1969 Write_Str (": passed by ");
1971 Write_Mechanism (Mechanism (Form));
1978 if List_Representation_Info_To_JSON then
1983 if Ekind (Ent) = E_Function then
1984 if List_Representation_Info_To_JSON then
1986 Write_Str (" ""mechanism"": """);
1987 Write_Mechanism (Mechanism (Ent));
1990 Write_Str ("returns by ");
1991 Write_Mechanism (Mechanism (Ent));
1996 if not Is_Entry (Ent) then
1997 List_Linker_Section (Ent);
2000 if List_Representation_Info_To_JSON then
2004 end List_Subprogram_Info;
2006 --------------------
2007 -- List_Type_Info --
2008 --------------------
2010 procedure List_Type_Info (Ent : Entity_Id) is
2014 if List_Representation_Info_To_JSON then
2018 List_Common_Type_Info (Ent);
2020 -- Special stuff for fixed-point
2022 if Is_Fixed_Point_Type (Ent) then
2024 -- Write small (always a static constant)
2026 if List_Representation_Info_To_JSON then
2028 Write_Str (" ""Small"": ");
2029 UR_Write (Small_Value (Ent));
2033 Write_Str ("'Small use ");
2034 UR_Write (Small_Value (Ent));
2038 -- Write range if static
2041 R : constant Node_Id := Scalar_Range (Ent);
2044 if Nkind (Low_Bound (R)) = N_Real_Literal
2046 Nkind (High_Bound (R)) = N_Real_Literal
2048 if List_Representation_Info_To_JSON then
2050 Write_Str (" ""Range"": [ ");
2051 UR_Write (Realval (Low_Bound (R)));
2053 UR_Write (Realval (High_Bound (R)));
2058 Write_Str ("'Range use ");
2059 UR_Write (Realval (Low_Bound (R)));
2061 UR_Write (Realval (High_Bound (R)));
2068 List_Linker_Section (Ent);
2070 if List_Representation_Info_To_JSON then
2076 ----------------------
2077 -- Rep_Not_Constant --
2078 ----------------------
2080 function Rep_Not_Constant (Val : Node_Ref_Or_Val) return Boolean is
2082 if Val = No_Uint or else Val < 0 then
2087 end Rep_Not_Constant;
2093 function Rep_Value (Val : Node_Ref_Or_Val; D : Discrim_List) return Uint is
2095 function B (Val : Boolean) return Uint;
2096 -- Returns Uint_0 for False, Uint_1 for True
2098 function T (Val : Node_Ref_Or_Val) return Boolean;
2099 -- Returns True for 0, False for any non-zero (i.e. True)
2101 function V (Val : Node_Ref_Or_Val) return Uint;
2102 -- Internal recursive routine to evaluate tree
2104 function W (Val : Uint) return Word;
2105 -- Convert Val to Word, assuming Val is always in the Int range. This
2106 -- is a helper function for the evaluation of bitwise expressions like
2107 -- Bit_And_Expr, for which there is no direct support in uintp. Uint
2108 -- values out of the Int range are expected to be seen in such
2109 -- expressions only with overflowing byte sizes around, introducing
2110 -- inherent unreliabilities in computations anyway.
2116 function B (Val : Boolean) return Uint is
2129 function T (Val : Node_Ref_Or_Val) return Boolean is
2142 function V (Val : Node_Ref_Or_Val) return Uint is
2151 Node : Exp_Node renames Rep_Table.Table (-UI_To_Int (Val));
2156 if T (Node.Op1) then
2157 return V (Node.Op2);
2159 return V (Node.Op3);
2163 return V (Node.Op1) + V (Node.Op2);
2166 return V (Node.Op1) - V (Node.Op2);
2169 return V (Node.Op1) * V (Node.Op2);
2171 when Trunc_Div_Expr =>
2172 return V (Node.Op1) / V (Node.Op2);
2174 when Ceil_Div_Expr =>
2177 (V (Node.Op1) / UR_From_Uint (V (Node.Op2)));
2179 when Floor_Div_Expr =>
2182 (V (Node.Op1) / UR_From_Uint (V (Node.Op2)));
2184 when Trunc_Mod_Expr =>
2185 return V (Node.Op1) rem V (Node.Op2);
2187 when Floor_Mod_Expr =>
2188 return V (Node.Op1) mod V (Node.Op2);
2190 when Ceil_Mod_Expr =>
2193 Q := UR_Ceiling (L / UR_From_Uint (R));
2196 when Exact_Div_Expr =>
2197 return V (Node.Op1) / V (Node.Op2);
2200 return -V (Node.Op1);
2203 return UI_Min (V (Node.Op1), V (Node.Op2));
2206 return UI_Max (V (Node.Op1), V (Node.Op2));
2209 return UI_Abs (V (Node.Op1));
2211 when Truth_And_Expr =>
2212 return B (T (Node.Op1) and then T (Node.Op2));
2214 when Truth_Or_Expr =>
2215 return B (T (Node.Op1) or else T (Node.Op2));
2217 when Truth_Xor_Expr =>
2218 return B (T (Node.Op1) xor T (Node.Op2));
2220 when Truth_Not_Expr =>
2221 return B (not T (Node.Op1));
2223 when Bit_And_Expr =>
2226 return UI_From_Int (Int (W (L) and W (R)));
2229 return B (V (Node.Op1) < V (Node.Op2));
2232 return B (V (Node.Op1) <= V (Node.Op2));
2235 return B (V (Node.Op1) > V (Node.Op2));
2238 return B (V (Node.Op1) >= V (Node.Op2));
2241 return B (V (Node.Op1) = V (Node.Op2));
2244 return B (V (Node.Op1) /= V (Node.Op2));
2248 Sub : constant Int := UI_To_Int (Node.Op1);
2250 pragma Assert (Sub in D'Range);
2265 -- We use an unchecked conversion to map Int values to their Word
2266 -- bitwise equivalent, which we could not achieve with a normal type
2267 -- conversion for negative Ints. We want bitwise equivalents because W
2268 -- is used as a helper for bit operators like Bit_And_Expr, and can be
2269 -- called for negative Ints in the context of aligning expressions like
2270 -- X+Align & -Align.
2272 function W (Val : Uint) return Word is
2273 function To_Word is new Ada.Unchecked_Conversion (Int, Word);
2275 return To_Word (UI_To_Int (Val));
2278 -- Start of processing for Rep_Value
2281 if Val = No_Uint then
2293 procedure Spaces (N : Natural) is
2295 for J in 1 .. N loop
2300 ---------------------
2301 -- Write_Info_Line --
2302 ---------------------
2304 procedure Write_Info_Line (S : String) is
2306 Write_Repinfo_Line_Access.all (S (S'First .. S'Last - 1));
2307 end Write_Info_Line;
2309 ---------------------
2310 -- Write_Mechanism --
2311 ---------------------
2313 procedure Write_Mechanism (M : Mechanism_Type) is
2317 Write_Str ("default");
2323 Write_Str ("reference");
2326 raise Program_Error;
2328 end Write_Mechanism;
2330 ---------------------
2331 -- Write_Separator --
2332 ---------------------
2334 procedure Write_Separator is
2336 if Need_Separator then
2337 if List_Representation_Info_To_JSON then
2343 Need_Separator := True;
2345 end Write_Separator;
2347 -----------------------
2348 -- Write_Unknown_Val --
2349 -----------------------
2351 procedure Write_Unknown_Val is
2353 if List_Representation_Info_To_JSON then
2354 Write_Str ("""??""");
2358 end Write_Unknown_Val;
2364 procedure Write_Val (Val : Node_Ref_Or_Val; Paren : Boolean := False) is
2366 if Rep_Not_Constant (Val) then
2367 if List_Representation_Info < 3 or else Val = No_Uint then
2375 List_GCC_Expression (Val);
2383 UI_Write (Val, Decimal);