1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2019, 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
362 ---------------------------
363 -- List_Common_Type_Info --
364 ---------------------------
366 procedure List_Common_Type_Info (Ent : Entity_Id) is
368 if List_Representation_Info_To_JSON then
369 Write_Str (" ""name"": """);
375 -- Do not list size info for unconstrained arrays, not meaningful
377 if Is_Array_Type (Ent) and then not Is_Constrained (Ent) then
381 -- If Esize and RM_Size are the same, list as Size. This is a common
382 -- case, which we may as well list in simple form.
384 if Esize (Ent) = RM_Size (Ent) then
385 if List_Representation_Info_To_JSON then
386 Write_Str (" ""Size"": ");
387 Write_Val (Esize (Ent));
392 Write_Str ("'Size use ");
393 Write_Val (Esize (Ent));
397 -- Otherwise list size values separately
400 if List_Representation_Info_To_JSON then
401 Write_Str (" ""Object_Size"": ");
402 Write_Val (Esize (Ent));
405 Write_Str (" ""Value_Size"": ");
406 Write_Val (RM_Size (Ent));
412 Write_Str ("'Object_Size use ");
413 Write_Val (Esize (Ent));
418 Write_Str ("'Value_Size use ");
419 Write_Val (RM_Size (Ent));
425 if List_Representation_Info_To_JSON then
426 Write_Str (" ""Alignment"": ");
427 Write_Val (Alignment (Ent));
431 Write_Str ("'Alignment use ");
432 Write_Val (Alignment (Ent));
435 end List_Common_Type_Info;
441 procedure List_Entities
443 Bytes_Big_Endian : Boolean;
444 In_Subprogram : Boolean := False)
449 function Find_Declaration (E : Entity_Id) return Node_Id;
450 -- Utility to retrieve declaration node for entity in the
451 -- case of package bodies and subprograms.
453 ----------------------
454 -- Find_Declaration --
455 ----------------------
457 function Find_Declaration (E : Entity_Id) return Node_Id is
463 and then Nkind (Decl) /= N_Package_Body
464 and then Nkind (Decl) /= N_Subprogram_Declaration
465 and then Nkind (Decl) /= N_Subprogram_Body
467 Decl := Parent (Decl);
471 end Find_Declaration;
473 -- Start of processing for List_Entities
476 -- List entity if we have one, and it is not a renaming declaration.
477 -- For renamings, we don't get proper information, and really it makes
478 -- sense to restrict the output to the renamed entity.
481 and then Nkind (Declaration_Node (Ent)) not in N_Renaming_Declaration
482 and then not Is_Ignored_Ghost_Entity (Ent)
484 -- If entity is a subprogram and we are listing mechanisms,
485 -- then we need to list mechanisms for this entity. We skip this
486 -- if it is a nested subprogram, as the information has already
487 -- been produced when listing the enclosing scope.
489 if List_Representation_Info_Mechanisms
490 and then (Is_Subprogram (Ent)
491 or else Ekind (Ent) = E_Entry
492 or else Ekind (Ent) = E_Entry_Family)
493 and then not In_Subprogram
495 List_Subprogram_Info (Ent);
498 E := First_Entity (Ent);
499 while Present (E) loop
500 -- We list entities that come from source (excluding private or
501 -- incomplete types or deferred constants, for which we will list
502 -- the information for the full view). If requested, we also list
503 -- relevant entities that have been generated when processing the
504 -- original entities coming from source. But if debug flag A is
505 -- set, then all entities are listed.
507 if ((Comes_From_Source (E)
508 or else (Ekind (E) = E_Block
510 Nkind (Parent (E)) = N_Implicit_Label_Declaration
512 Comes_From_Source (Label_Construct (Parent (E)))))
513 and then not Is_Incomplete_Or_Private_Type (E)
514 and then not (Ekind (E) = E_Constant
515 and then Present (Full_View (E))))
516 or else (List_Representation_Info = 4
517 and then Relevant_Entities.Get (E))
518 or else Debug_Flag_AA
520 if Is_Subprogram (E) then
521 if List_Representation_Info_Mechanisms then
522 List_Subprogram_Info (E);
525 -- Recurse into entities local to subprogram
527 List_Entities (E, Bytes_Big_Endian, True);
529 elsif Ekind_In (E, E_Entry,
533 if List_Representation_Info_Mechanisms then
534 List_Subprogram_Info (E);
537 elsif Is_Record_Type (E) then
538 if List_Representation_Info >= 1 then
539 List_Record_Info (E, Bytes_Big_Endian);
542 elsif Is_Array_Type (E) then
543 if List_Representation_Info >= 1 then
544 List_Array_Info (E, Bytes_Big_Endian);
547 -- The component type is relevant for an array
549 if List_Representation_Info = 4
550 and then Is_Itype (Component_Type (Base_Type (E)))
552 Relevant_Entities.Set
553 (Component_Type (Base_Type (E)), True);
556 elsif Is_Type (E) then
557 if List_Representation_Info >= 2 then
561 -- Note that formals are not annotated so we skip them here
563 elsif Ekind_In (E, E_Constant,
567 -- The type is relevant for an object
569 if List_Representation_Info = 4 and then Is_Itype (Etype (E))
571 Relevant_Entities.Set (Etype (E), True);
574 if List_Representation_Info >= 2 then
575 List_Object_Info (E);
579 -- Recurse into nested package, but not if they are package
580 -- renamings (in particular renamings of the enclosing package,
581 -- as for some Java bindings and for generic instances).
583 if Ekind (E) = E_Package then
584 if No (Renamed_Object (E)) then
585 List_Entities (E, Bytes_Big_Endian);
588 -- Recurse into bodies
590 elsif Ekind_In (E, E_Package_Body,
597 List_Entities (E, Bytes_Big_Endian);
599 -- Recurse into blocks
601 elsif Ekind (E) = E_Block then
602 List_Entities (E, Bytes_Big_Endian);
606 E := Next_Entity (E);
609 -- For a package body, the entities of the visible subprograms are
610 -- declared in the corresponding spec. Iterate over its entities in
611 -- order to handle properly the subprogram bodies. Skip bodies in
612 -- subunits, which are listed independently.
614 if Ekind (Ent) = E_Package_Body
615 and then Present (Corresponding_Spec (Find_Declaration (Ent)))
617 E := First_Entity (Corresponding_Spec (Find_Declaration (Ent)));
618 while Present (E) loop
621 Nkind (Find_Declaration (E)) = N_Subprogram_Declaration
623 Body_E := Corresponding_Body (Find_Declaration (E));
627 Nkind (Parent (Find_Declaration (Body_E))) /= N_Subunit
629 List_Entities (Body_E, Bytes_Big_Endian);
639 -------------------------
640 -- List_GCC_Expression --
641 -------------------------
643 procedure List_GCC_Expression (U : Node_Ref_Or_Val) is
645 procedure Print_Expr (Val : Node_Ref_Or_Val);
646 -- Internal recursive procedure to print expression
652 procedure Print_Expr (Val : Node_Ref_Or_Val) is
655 UI_Write (Val, Decimal);
659 Node : Exp_Node renames Rep_Table.Table (-UI_To_Int (Val));
661 procedure Unop (S : String);
662 -- Output text for unary operator with S being operator name
664 procedure Binop (S : String);
665 -- Output text for binary operator with S being operator name
671 procedure Unop (S : String) is
673 if List_Representation_Info_To_JSON then
674 Write_Str ("{ ""code"": """);
675 if S (S'Last) = ' ' then
676 Write_Str (S (S'First .. S'Last - 1));
680 Write_Str (""", ""operands"": [ ");
681 Print_Expr (Node.Op1);
685 Print_Expr (Node.Op1);
693 procedure Binop (S : String) is
695 if List_Representation_Info_To_JSON then
696 Write_Str ("{ ""code"": """);
697 Write_Str (S (S'First + 1 .. S'Last - 1));
698 Write_Str (""", ""operands"": [ ");
699 Print_Expr (Node.Op1);
701 Print_Expr (Node.Op2);
705 Print_Expr (Node.Op1);
707 Print_Expr (Node.Op2);
712 -- Start of processing for Print_Expr
717 if List_Representation_Info_To_JSON then
718 Write_Str ("{ ""code"": ""?<>""");
719 Write_Str (", ""operands"": [ ");
720 Print_Expr (Node.Op1);
722 Print_Expr (Node.Op2);
724 Print_Expr (Node.Op3);
728 Print_Expr (Node.Op1);
729 Write_Str (" then ");
730 Print_Expr (Node.Op2);
731 Write_Str (" else ");
732 Print_Expr (Node.Op3);
745 when Trunc_Div_Expr =>
748 when Ceil_Div_Expr =>
751 when Floor_Div_Expr =>
754 when Trunc_Mod_Expr =>
757 when Ceil_Mod_Expr =>
760 when Floor_Mod_Expr =>
763 when Exact_Div_Expr =>
778 when Truth_And_Expr =>
781 when Truth_Or_Expr =>
784 when Truth_Xor_Expr =>
787 when Truth_Not_Expr =>
821 -- Start of processing for List_GCC_Expression
829 end List_GCC_Expression;
831 -------------------------
832 -- List_Linker_Section --
833 -------------------------
835 procedure List_Linker_Section (Ent : Entity_Id) is
836 function Expr_Value_S (N : Node_Id) return Node_Id;
837 -- Returns the folded value of the expression. This function is called
838 -- in instances where it has already been determined that the expression
839 -- is static or its value is known at compile time. This version is used
840 -- for string types and returns the corresponding N_String_Literal node.
841 -- NOTE: This is an exact copy of Sem_Eval.Expr_Value_S. Licensing stops
842 -- Repinfo from within Sem_Eval. Once ASIS is removed, and the licenses
843 -- are modified, Repinfo should be able to rely on Sem_Eval.
849 function Expr_Value_S (N : Node_Id) return Node_Id is
851 if Nkind (N) = N_String_Literal then
854 pragma Assert (Ekind (Entity (N)) = E_Constant);
855 return Expr_Value_S (Constant_Value (Entity (N)));
864 -- Start of processing for List_Linker_Section
867 if Present (Linker_Section_Pragma (Ent)) then
868 Args := Pragma_Argument_Associations (Linker_Section_Pragma (Ent));
869 Sect := Expr_Value_S (Get_Pragma_Arg (Last (Args)));
871 if List_Representation_Info_To_JSON then
873 Write_Str (" ""Linker_Section"": """);
875 Write_Str ("pragma Linker_Section (");
880 pragma Assert (Nkind (Sect) = N_String_Literal);
881 String_To_Name_Buffer (Strval (Sect));
882 Write_Str (Name_Buffer (1 .. Name_Len));
884 if not List_Representation_Info_To_JSON then
888 end List_Linker_Section;
894 procedure List_Location (Ent : Entity_Id) is
896 pragma Assert (List_Representation_Info_To_JSON);
897 Write_Str (" ""location"": """);
898 Write_Location (Sloc (Ent));
906 procedure List_Name (Ent : Entity_Id) is
910 -- List the qualified name recursively, except
911 -- at compilation unit level in default mode.
913 if Is_Compilation_Unit (Ent) then
915 elsif not Is_Compilation_Unit (Scope (Ent))
916 or else List_Representation_Info_To_JSON
918 List_Name (Scope (Ent));
922 Get_Unqualified_Decoded_Name_String (Chars (Ent));
923 Set_Casing (Unit_Casing);
925 -- The name of operators needs to be properly escaped for JSON
927 for J in 1 .. Name_Len loop
928 C := Name_Buffer (J);
929 if C = '"' and then List_Representation_Info_To_JSON then
936 ---------------------
937 -- List_Object_Info --
938 ---------------------
940 procedure List_Object_Info (Ent : Entity_Id) is
944 if List_Representation_Info_To_JSON then
947 Write_Str (" ""name"": """);
952 Write_Str (" ""Size"": ");
953 Write_Val (Esize (Ent));
956 Write_Str (" ""Alignment"": ");
957 Write_Val (Alignment (Ent));
959 List_Linker_Section (Ent);
966 Write_Str ("'Size use ");
967 Write_Val (Esize (Ent));
972 Write_Str ("'Alignment use ");
973 Write_Val (Alignment (Ent));
976 List_Linker_Section (Ent);
978 end List_Object_Info;
980 ----------------------
981 -- List_Record_Info --
982 ----------------------
984 procedure List_Record_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is
985 procedure Compute_Max_Length
987 Starting_Position : Uint := Uint_0;
988 Starting_First_Bit : Uint := Uint_0;
989 Prefix_Length : Natural := 0);
990 -- Internal recursive procedure to compute the max length
992 procedure List_Component_Layout
994 Starting_Position : Uint := Uint_0;
995 Starting_First_Bit : Uint := Uint_0;
996 Prefix : String := "";
997 Indent : Natural := 0);
998 -- Procedure to display the layout of a single component
1000 procedure List_Record_Layout
1002 Starting_Position : Uint := Uint_0;
1003 Starting_First_Bit : Uint := Uint_0;
1004 Prefix : String := "");
1005 -- Internal recursive procedure to display the layout
1007 procedure List_Structural_Record_Layout
1009 Outer_Ent : Entity_Id;
1010 Variant : Node_Id := Empty;
1011 Indent : Natural := 0);
1012 -- Internal recursive procedure to display the structural layout
1014 Incomplete_Layout : exception;
1015 -- Exception raised if the layout is incomplete in -gnatc mode
1017 Not_In_Extended_Main : exception;
1018 -- Exception raised when an ancestor is not declared in the main unit
1020 Max_Name_Length : Natural := 0;
1021 Max_Spos_Length : Natural := 0;
1023 ------------------------
1024 -- Compute_Max_Length --
1025 ------------------------
1027 procedure Compute_Max_Length
1029 Starting_Position : Uint := Uint_0;
1030 Starting_First_Bit : Uint := Uint_0;
1031 Prefix_Length : Natural := 0)
1036 Comp := First_Component_Or_Discriminant (Ent);
1037 while Present (Comp) loop
1039 -- Skip discriminant in unchecked union (since it is not there!)
1041 if Ekind (Comp) = E_Discriminant
1042 and then Is_Unchecked_Union (Ent)
1047 -- Skip _Parent component in extension (to avoid overlap)
1049 if Chars (Comp) = Name_uParent then
1056 Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp));
1057 Bofs : constant Uint := Component_Bit_Offset (Comp);
1063 Name_Length : Natural;
1066 Get_Decoded_Name_String (Chars (Comp));
1067 Name_Length := Prefix_Length + Name_Len;
1069 if Rep_Not_Constant (Bofs) then
1071 -- If the record is not packed, then we know that all fields
1072 -- whose position is not specified have starting normalized
1073 -- bit position of zero.
1075 if Unknown_Normalized_First_Bit (Comp)
1076 and then not Is_Packed (Ent)
1078 Set_Normalized_First_Bit (Comp, Uint_0);
1081 UI_Image_Length := 2; -- For "??" marker
1084 Fbit := Bofs mod SSU;
1086 -- Complete annotation in case not done
1088 if Unknown_Normalized_First_Bit (Comp) then
1089 Set_Normalized_Position (Comp, Npos);
1090 Set_Normalized_First_Bit (Comp, Fbit);
1093 Spos := Starting_Position + Npos;
1094 Sbit := Starting_First_Bit + Fbit;
1101 -- If extended information is requested, recurse fully into
1102 -- record components, i.e. skip the outer level.
1104 if List_Representation_Info_Extended
1105 and then Is_Record_Type (Ctyp)
1107 Compute_Max_Length (Ctyp, Spos, Sbit, Name_Length + 1);
1114 Max_Name_Length := Natural'Max (Max_Name_Length, Name_Length);
1116 Natural'Max (Max_Spos_Length, UI_Image_Length);
1120 Next_Component_Or_Discriminant (Comp);
1122 end Compute_Max_Length;
1124 ---------------------------
1125 -- List_Component_Layout --
1126 ---------------------------
1128 procedure List_Component_Layout
1130 Starting_Position : Uint := Uint_0;
1131 Starting_First_Bit : Uint := Uint_0;
1132 Prefix : String := "";
1133 Indent : Natural := 0)
1135 Esiz : constant Uint := Esize (Ent);
1136 Npos : constant Uint := Normalized_Position (Ent);
1137 Fbit : constant Uint := Normalized_First_Bit (Ent);
1143 if List_Representation_Info_To_JSON then
1147 Write_Str (" ""name"": """);
1149 Write_Str (Name_Buffer (1 .. Name_Len));
1151 if Ekind (Ent) = E_Discriminant then
1153 Write_Str (" ""discriminant"": ");
1154 UI_Write (Discriminant_Number (Ent), Decimal);
1158 Write_Str (" ""Position"": ");
1162 Write_Str (Name_Buffer (1 .. Name_Len));
1163 Spaces (Max_Name_Length - Prefix'Length - Name_Len);
1167 if Known_Static_Normalized_Position (Ent) then
1168 Spos := Starting_Position + Npos;
1169 Sbit := Starting_First_Bit + Fbit;
1176 Spaces (Max_Spos_Length - UI_Image_Length);
1177 Write_Str (UI_Image_Buffer (1 .. UI_Image_Length));
1179 elsif Known_Normalized_Position (Ent)
1180 and then List_Representation_Info >= 3
1182 Spaces (Max_Spos_Length - 2);
1184 if Starting_Position /= Uint_0 then
1185 UI_Write (Starting_Position, Decimal);
1195 if List_Representation_Info_To_JSON then
1198 Write_Str (" ""First_Bit"": ");
1200 Write_Str (" range ");
1203 Sbit := Starting_First_Bit + Fbit;
1209 UI_Write (Sbit, Decimal);
1211 if List_Representation_Info_To_JSON then
1214 Write_Str (" ""Size"": ");
1219 -- Allowing Uint_0 here is an annoying special case. Really this
1220 -- should be a fine Esize value but currently it means unknown,
1221 -- except that we know after gigi has back annotated that a size
1222 -- of zero is real, since otherwise gigi back annotates using
1223 -- No_Uint as the value to indicate unknown.
1225 if (Esize (Ent) = Uint_0 or else Known_Static_Esize (Ent))
1226 and then Known_Static_Normalized_First_Bit (Ent)
1228 Lbit := Sbit + Esiz - 1;
1230 if List_Representation_Info_To_JSON then
1231 UI_Write (Esiz, Decimal);
1233 if Lbit >= 0 and then Lbit < 10 then
1237 UI_Write (Lbit, Decimal);
1240 -- The test for Esize (Ent) not Uint_0 here is an annoying special
1241 -- case. Officially a value of zero for Esize means unknown, but
1242 -- here we use the fact that we know that gigi annotates Esize with
1243 -- No_Uint, not Uint_0. Really everyone should use No_Uint???
1245 elsif List_Representation_Info < 3
1246 or else (Esize (Ent) /= Uint_0 and then Unknown_Esize (Ent))
1250 -- List_Representation >= 3 and Known_Esize (Ent)
1253 Write_Val (Esiz, Paren => not List_Representation_Info_To_JSON);
1255 -- If in front-end layout mode, then dynamic size is stored in
1256 -- storage units, so renormalize for output.
1258 if not Back_End_Layout then
1263 -- Add appropriate first bit offset
1265 if not List_Representation_Info_To_JSON then
1274 Write_Int (UI_To_Int (Sbit) - 1);
1279 if List_Representation_Info_To_JSON then
1286 end List_Component_Layout;
1288 ------------------------
1289 -- List_Record_Layout --
1290 ------------------------
1292 procedure List_Record_Layout
1294 Starting_Position : Uint := Uint_0;
1295 Starting_First_Bit : Uint := Uint_0;
1296 Prefix : String := "")
1299 First : Boolean := True;
1302 Comp := First_Component_Or_Discriminant (Ent);
1303 while Present (Comp) loop
1305 -- Skip discriminant in unchecked union (since it is not there!)
1307 if Ekind (Comp) = E_Discriminant
1308 and then Is_Unchecked_Union (Ent)
1313 -- Skip _Parent component in extension (to avoid overlap)
1315 if Chars (Comp) = Name_uParent then
1322 Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp));
1323 Npos : constant Uint := Normalized_Position (Comp);
1324 Fbit : constant Uint := Normalized_First_Bit (Comp);
1329 Get_Decoded_Name_String (Chars (Comp));
1330 Set_Casing (Unit_Casing);
1332 -- If extended information is requested, recurse fully into
1333 -- record components, i.e. skip the outer level.
1335 if List_Representation_Info_Extended
1336 and then Is_Record_Type (Ctyp)
1337 and then Known_Static_Normalized_Position (Comp)
1338 and then Known_Static_Normalized_First_Bit (Comp)
1340 Spos := Starting_Position + Npos;
1341 Sbit := Starting_First_Bit + Fbit;
1348 List_Record_Layout (Ctyp,
1349 Spos, Sbit, Prefix & Name_Buffer (1 .. Name_Len) & ".");
1354 if List_Representation_Info_To_JSON then
1363 List_Component_Layout (Comp,
1364 Starting_Position, Starting_First_Bit, Prefix);
1368 Next_Component_Or_Discriminant (Comp);
1370 end List_Record_Layout;
1372 -----------------------------------
1373 -- List_Structural_Record_Layout --
1374 -----------------------------------
1376 procedure List_Structural_Record_Layout
1378 Outer_Ent : Entity_Id;
1379 Variant : Node_Id := Empty;
1380 Indent : Natural := 0)
1382 function Derived_Discriminant (Disc : Entity_Id) return Entity_Id;
1383 -- This function assumes that Outer_Ent is an extension of Ent.
1384 -- Disc is a discriminant of Ent that does not itself constrain a
1385 -- discriminant of the parent type of Ent. Return the discriminant
1386 -- of Outer_Ent that ultimately constrains Disc, if any.
1388 ----------------------------
1389 -- Derived_Discriminant --
1390 ----------------------------
1392 function Derived_Discriminant (Disc : Entity_Id) return Entity_Id is
1393 Corr_Disc : Entity_Id;
1394 Derived_Disc : Entity_Id;
1397 Derived_Disc := First_Stored_Discriminant (Outer_Ent);
1399 -- Loop over the discriminants of the extension
1401 while Present (Derived_Disc) loop
1403 -- Check if this discriminant constrains another discriminant.
1404 -- If so, find the ultimately constrained discriminant and
1405 -- compare with the original components in the base type.
1407 if Present (Corresponding_Discriminant (Derived_Disc)) then
1408 Corr_Disc := Corresponding_Discriminant (Derived_Disc);
1410 while Present (Corresponding_Discriminant (Corr_Disc)) loop
1411 Corr_Disc := Corresponding_Discriminant (Corr_Disc);
1414 if Original_Record_Component (Corr_Disc) =
1415 Original_Record_Component (Disc)
1417 return Derived_Disc;
1421 Next_Stored_Discriminant (Derived_Disc);
1424 -- Disc is not constrained by a discriminant of Outer_Ent
1427 end Derived_Discriminant;
1429 -- Local declarations
1432 Comp_List : Node_Id;
1433 First : Boolean := True;
1436 -- Start of processing for List_Structural_Record_Layout
1439 -- If we are dealing with a variant, just process the components
1441 if Present (Variant) then
1442 Comp_List := Component_List (Variant);
1444 -- Otherwise, we are dealing with the full record and need to get
1445 -- to its definition in order to retrieve its structural layout.
1449 Definition : Node_Id :=
1450 Type_Definition (Declaration_Node (Ent));
1452 Is_Extension : constant Boolean :=
1453 Is_Tagged_Type (Ent)
1454 and then Nkind (Definition) =
1455 N_Derived_Type_Definition;
1458 Listed_Disc : Entity_Id;
1459 Parent_Type : Entity_Id;
1462 -- If this is an extension, first list the layout of the parent
1463 -- and then proceed to the extension part, if any.
1465 if Is_Extension then
1466 Parent_Type := Parent_Subtype (Ent);
1467 if No (Parent_Type) then
1468 raise Incomplete_Layout;
1471 if Is_Private_Type (Parent_Type) then
1472 Parent_Type := Full_View (Parent_Type);
1473 pragma Assert (Present (Parent_Type));
1476 Parent_Type := Base_Type (Parent_Type);
1477 if not In_Extended_Main_Source_Unit (Parent_Type) then
1478 raise Not_In_Extended_Main;
1481 List_Structural_Record_Layout (Parent_Type, Outer_Ent);
1484 if Present (Record_Extension_Part (Definition)) then
1485 Definition := Record_Extension_Part (Definition);
1489 -- If the record has discriminants and is not an unchecked
1490 -- union, then display them now.
1492 if Has_Discriminants (Ent)
1493 and then not Is_Unchecked_Union (Ent)
1495 Disc := First_Stored_Discriminant (Ent);
1496 while Present (Disc) loop
1498 -- If this is a record extension and the discriminant is
1499 -- the renaming of another discriminant, skip it.
1502 and then Present (Corresponding_Discriminant (Disc))
1507 -- If this is the parent type of an extension, retrieve
1508 -- the derived discriminant from the extension, if any.
1510 if Ent /= Outer_Ent then
1511 Listed_Disc := Derived_Discriminant (Disc);
1513 if No (Listed_Disc) then
1517 Listed_Disc := Disc;
1520 Get_Decoded_Name_String (Chars (Listed_Disc));
1521 Set_Casing (Unit_Casing);
1530 List_Component_Layout (Listed_Disc, Indent => Indent);
1533 Next_Stored_Discriminant (Disc);
1537 Comp_List := Component_List (Definition);
1541 -- Bail out for the null record
1543 if No (Comp_List) then
1547 -- Now deal with the regular components, if any
1549 if Present (Component_Items (Comp_List)) then
1550 Comp := First_Non_Pragma (Component_Items (Comp_List));
1551 while Present (Comp) loop
1553 -- Skip _Parent component in extension (to avoid overlap)
1555 if Chars (Defining_Identifier (Comp)) = Name_uParent then
1559 Get_Decoded_Name_String (Chars (Defining_Identifier (Comp)));
1560 Set_Casing (Unit_Casing);
1569 List_Component_Layout
1570 (Defining_Identifier (Comp), Indent => Indent);
1573 Next_Non_Pragma (Comp);
1577 -- We are done if there is no variant part
1579 if No (Variant_Part (Comp_List)) then
1587 Write_Str (" ""variant"" : [");
1589 -- Otherwise we recurse on each variant
1591 Var := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
1593 while Present (Var) loop
1604 Write_Str (" ""present"": ");
1605 Write_Val (Present_Expr (Var));
1608 Write_Str (" ""record"": [");
1610 List_Structural_Record_Layout (Ent, Outer_Ent, Var, Indent + 4);
1617 Next_Non_Pragma (Var);
1619 end List_Structural_Record_Layout;
1621 -- Start of processing for List_Record_Info
1626 if List_Representation_Info_To_JSON then
1630 List_Common_Type_Info (Ent);
1632 -- First find out max line length and max starting position
1633 -- length, for the purpose of lining things up nicely.
1635 Compute_Max_Length (Ent);
1637 -- Then do actual output based on those values
1639 if List_Representation_Info_To_JSON then
1641 Write_Str (" ""record"": [");
1643 -- ??? We can output structural layout only for base types fully
1644 -- declared in the extended main source unit for the time being,
1645 -- because otherwise declarations might not be processed at all.
1647 if Is_Base_Type (Ent) then
1649 List_Structural_Record_Layout (Ent, Ent);
1652 when Incomplete_Layout
1653 | Not_In_Extended_Main
1655 List_Record_Layout (Ent);
1658 raise Program_Error;
1661 List_Record_Layout (Ent);
1669 Write_Line (" use record");
1671 List_Record_Layout (Ent);
1673 Write_Line ("end record;");
1676 List_Scalar_Storage_Order (Ent, Bytes_Big_Endian);
1678 List_Linker_Section (Ent);
1680 if List_Representation_Info_To_JSON then
1685 -- The type is relevant for a record subtype
1687 if List_Representation_Info = 4
1688 and then not Is_Base_Type (Ent)
1689 and then Is_Itype (Etype (Ent))
1691 Relevant_Entities.Set (Etype (Ent), True);
1693 end List_Record_Info;
1699 procedure List_Rep_Info (Bytes_Big_Endian : Boolean) is
1703 if List_Representation_Info /= 0
1704 or else List_Representation_Info_Mechanisms
1706 -- For the normal case, we output a single JSON stream
1708 if not List_Representation_Info_To_File
1709 and then List_Representation_Info_To_JSON
1712 Need_Separator := False;
1715 for U in Main_Unit .. Last_Unit loop
1716 if In_Extended_Main_Source_Unit (Cunit_Entity (U)) then
1717 Unit_Casing := Identifier_Casing (Source_Index (U));
1719 if List_Representation_Info = 4 then
1720 Relevant_Entities.Reset;
1723 -- Normal case, list to standard output
1725 if not List_Representation_Info_To_File then
1726 if not List_Representation_Info_To_JSON then
1728 Write_Str ("Representation information for unit ");
1729 Write_Unit_Name (Unit_Name (U));
1733 for J in 1 .. Col - 1 loop
1738 Need_Separator := True;
1741 List_Entities (Cunit_Entity (U), Bytes_Big_Endian);
1743 -- List representation information to file
1746 Create_Repinfo_File_Access.all
1747 (Get_Name_String (File_Name (Source_Index (U))));
1748 Set_Special_Output (Write_Info_Line'Access);
1749 if List_Representation_Info_To_JSON then
1752 Need_Separator := False;
1753 List_Entities (Cunit_Entity (U), Bytes_Big_Endian);
1754 if List_Representation_Info_To_JSON then
1757 Cancel_Special_Output;
1758 Close_Repinfo_File_Access.all;
1763 if not List_Representation_Info_To_File
1764 and then List_Representation_Info_To_JSON
1771 -------------------------------
1772 -- List_Scalar_Storage_Order --
1773 -------------------------------
1775 procedure List_Scalar_Storage_Order
1777 Bytes_Big_Endian : Boolean)
1779 procedure List_Attr (Attr_Name : String; Is_Reversed : Boolean);
1780 -- Show attribute definition clause for Attr_Name (an endianness
1781 -- attribute), depending on whether or not the endianness is reversed
1782 -- compared to native endianness.
1788 procedure List_Attr (Attr_Name : String; Is_Reversed : Boolean) is
1790 if List_Representation_Info_To_JSON then
1793 Write_Str (Attr_Name);
1794 Write_Str (""": ""System.");
1799 Write_Str (Attr_Name);
1800 Write_Str (" use System.");
1803 if Bytes_Big_Endian xor Is_Reversed then
1809 Write_Str ("_Order_First");
1810 if List_Representation_Info_To_JSON then
1817 List_SSO : constant Boolean :=
1818 Has_Rep_Item (Ent, Name_Scalar_Storage_Order)
1819 or else SSO_Set_Low_By_Default (Ent)
1820 or else SSO_Set_High_By_Default (Ent);
1821 -- Scalar_Storage_Order is displayed if specified explicitly or set by
1822 -- Default_Scalar_Storage_Order.
1824 -- Start of processing for List_Scalar_Storage_Order
1827 -- For record types, list Bit_Order if not default, or if SSO is shown
1829 -- Also, when -gnatR4 is in effect always list bit order and scalar
1830 -- storage order explicitly, so that you don't need to know the native
1831 -- endianness of the target for which the output was produced in order
1834 if Is_Record_Type (Ent)
1836 or else Reverse_Bit_Order (Ent)
1837 or else List_Representation_Info = 4)
1839 List_Attr ("Bit_Order", Reverse_Bit_Order (Ent));
1842 -- List SSO if required. If not, then storage is supposed to be in
1845 if List_SSO or else List_Representation_Info = 4 then
1846 List_Attr ("Scalar_Storage_Order", Reverse_Storage_Order (Ent));
1848 pragma Assert (not Reverse_Storage_Order (Ent));
1851 end List_Scalar_Storage_Order;
1853 --------------------------
1854 -- List_Subprogram_Info --
1855 --------------------------
1857 procedure List_Subprogram_Info (Ent : Entity_Id) is
1858 First : Boolean := True;
1865 if List_Representation_Info_To_JSON then
1867 Write_Str (" ""name"": """);
1870 List_Location (Ent);
1872 Write_Str (" ""Convention"": """);
1876 Write_Str ("function ");
1879 Write_Str ("operator ");
1882 Write_Str ("procedure ");
1884 when E_Subprogram_Type =>
1885 Write_Str ("type ");
1890 Write_Str ("entry ");
1893 raise Program_Error;
1897 Write_Str (" declared at ");
1898 Write_Location (Sloc (Ent));
1901 Write_Str ("convention : ");
1904 case Convention (Ent) is
1905 when Convention_Ada =>
1908 when Convention_Ada_Pass_By_Copy =>
1909 Write_Str ("Ada_Pass_By_Copy");
1911 when Convention_Ada_Pass_By_Reference =>
1912 Write_Str ("Ada_Pass_By_Reference");
1914 when Convention_Intrinsic =>
1915 Write_Str ("Intrinsic");
1917 when Convention_Entry =>
1918 Write_Str ("Entry");
1920 when Convention_Protected =>
1921 Write_Str ("Protected");
1923 when Convention_Assembler =>
1924 Write_Str ("Assembler");
1926 when Convention_C =>
1929 when Convention_COBOL =>
1930 Write_Str ("COBOL");
1932 when Convention_CPP =>
1935 when Convention_Fortran =>
1936 Write_Str ("Fortran");
1938 when Convention_Stdcall =>
1939 Write_Str ("Stdcall");
1941 when Convention_Stubbed =>
1942 Write_Str ("Stubbed");
1945 if List_Representation_Info_To_JSON then
1947 Write_Str (" ""formal"": [");
1952 -- Find max length of formal name
1955 Form := First_Formal (Ent);
1956 while Present (Form) loop
1957 Get_Unqualified_Decoded_Name_String (Chars (Form));
1959 if Name_Len > Plen then
1966 -- Output formals and mechanisms
1968 Form := First_Formal (Ent);
1969 while Present (Form) loop
1970 Get_Unqualified_Decoded_Name_String (Chars (Form));
1971 Set_Casing (Unit_Casing);
1973 if List_Representation_Info_To_JSON then
1982 Write_Str (" ""name"": """);
1983 Write_Str (Name_Buffer (1 .. Name_Len));
1986 Write_Str (" ""mechanism"": """);
1987 Write_Mechanism (Mechanism (Form));
1991 while Name_Len <= Plen loop
1992 Name_Len := Name_Len + 1;
1993 Name_Buffer (Name_Len) := ' ';
1997 Write_Str (Name_Buffer (1 .. Plen + 1));
1998 Write_Str (": passed by ");
2000 Write_Mechanism (Mechanism (Form));
2007 if List_Representation_Info_To_JSON then
2012 if Ekind (Ent) = E_Function then
2013 if List_Representation_Info_To_JSON then
2015 Write_Str (" ""mechanism"": """);
2016 Write_Mechanism (Mechanism (Ent));
2019 Write_Str ("returns by ");
2020 Write_Mechanism (Mechanism (Ent));
2025 if not Is_Entry (Ent) then
2026 List_Linker_Section (Ent);
2029 if List_Representation_Info_To_JSON then
2033 end List_Subprogram_Info;
2035 --------------------
2036 -- List_Type_Info --
2037 --------------------
2039 procedure List_Type_Info (Ent : Entity_Id) is
2043 if List_Representation_Info_To_JSON then
2047 List_Common_Type_Info (Ent);
2049 -- Special stuff for fixed-point
2051 if Is_Fixed_Point_Type (Ent) then
2053 -- Write small (always a static constant)
2055 if List_Representation_Info_To_JSON then
2057 Write_Str (" ""Small"": ");
2058 UR_Write (Small_Value (Ent));
2062 Write_Str ("'Small use ");
2063 UR_Write (Small_Value (Ent));
2067 -- Write range if static
2070 R : constant Node_Id := Scalar_Range (Ent);
2073 if Nkind (Low_Bound (R)) = N_Real_Literal
2075 Nkind (High_Bound (R)) = N_Real_Literal
2077 if List_Representation_Info_To_JSON then
2079 Write_Str (" ""Range"": [ ");
2080 UR_Write (Realval (Low_Bound (R)));
2082 UR_Write (Realval (High_Bound (R)));
2087 Write_Str ("'Range use ");
2088 UR_Write (Realval (Low_Bound (R)));
2090 UR_Write (Realval (High_Bound (R)));
2097 List_Linker_Section (Ent);
2099 if List_Representation_Info_To_JSON then
2105 ----------------------
2106 -- Rep_Not_Constant --
2107 ----------------------
2109 function Rep_Not_Constant (Val : Node_Ref_Or_Val) return Boolean is
2111 if Val = No_Uint or else Val < 0 then
2116 end Rep_Not_Constant;
2122 function Rep_Value (Val : Node_Ref_Or_Val; D : Discrim_List) return Uint is
2124 function B (Val : Boolean) return Uint;
2125 -- Returns Uint_0 for False, Uint_1 for True
2127 function T (Val : Node_Ref_Or_Val) return Boolean;
2128 -- Returns True for 0, False for any non-zero (i.e. True)
2130 function V (Val : Node_Ref_Or_Val) return Uint;
2131 -- Internal recursive routine to evaluate tree
2133 function W (Val : Uint) return Word;
2134 -- Convert Val to Word, assuming Val is always in the Int range. This
2135 -- is a helper function for the evaluation of bitwise expressions like
2136 -- Bit_And_Expr, for which there is no direct support in uintp. Uint
2137 -- values out of the Int range are expected to be seen in such
2138 -- expressions only with overflowing byte sizes around, introducing
2139 -- inherent unreliabilities in computations anyway.
2145 function B (Val : Boolean) return Uint is
2158 function T (Val : Node_Ref_Or_Val) return Boolean is
2171 function V (Val : Node_Ref_Or_Val) return Uint is
2180 Node : Exp_Node renames Rep_Table.Table (-UI_To_Int (Val));
2185 if T (Node.Op1) then
2186 return V (Node.Op2);
2188 return V (Node.Op3);
2192 return V (Node.Op1) + V (Node.Op2);
2195 return V (Node.Op1) - V (Node.Op2);
2198 return V (Node.Op1) * V (Node.Op2);
2200 when Trunc_Div_Expr =>
2201 return V (Node.Op1) / V (Node.Op2);
2203 when Ceil_Div_Expr =>
2206 (V (Node.Op1) / UR_From_Uint (V (Node.Op2)));
2208 when Floor_Div_Expr =>
2211 (V (Node.Op1) / UR_From_Uint (V (Node.Op2)));
2213 when Trunc_Mod_Expr =>
2214 return V (Node.Op1) rem V (Node.Op2);
2216 when Floor_Mod_Expr =>
2217 return V (Node.Op1) mod V (Node.Op2);
2219 when Ceil_Mod_Expr =>
2222 Q := UR_Ceiling (L / UR_From_Uint (R));
2225 when Exact_Div_Expr =>
2226 return V (Node.Op1) / V (Node.Op2);
2229 return -V (Node.Op1);
2232 return UI_Min (V (Node.Op1), V (Node.Op2));
2235 return UI_Max (V (Node.Op1), V (Node.Op2));
2238 return UI_Abs (V (Node.Op1));
2240 when Truth_And_Expr =>
2241 return B (T (Node.Op1) and then T (Node.Op2));
2243 when Truth_Or_Expr =>
2244 return B (T (Node.Op1) or else T (Node.Op2));
2246 when Truth_Xor_Expr =>
2247 return B (T (Node.Op1) xor T (Node.Op2));
2249 when Truth_Not_Expr =>
2250 return B (not T (Node.Op1));
2252 when Bit_And_Expr =>
2255 return UI_From_Int (Int (W (L) and W (R)));
2258 return B (V (Node.Op1) < V (Node.Op2));
2261 return B (V (Node.Op1) <= V (Node.Op2));
2264 return B (V (Node.Op1) > V (Node.Op2));
2267 return B (V (Node.Op1) >= V (Node.Op2));
2270 return B (V (Node.Op1) = V (Node.Op2));
2273 return B (V (Node.Op1) /= V (Node.Op2));
2277 Sub : constant Int := UI_To_Int (Node.Op1);
2279 pragma Assert (Sub in D'Range);
2294 -- We use an unchecked conversion to map Int values to their Word
2295 -- bitwise equivalent, which we could not achieve with a normal type
2296 -- conversion for negative Ints. We want bitwise equivalents because W
2297 -- is used as a helper for bit operators like Bit_And_Expr, and can be
2298 -- called for negative Ints in the context of aligning expressions like
2299 -- X+Align & -Align.
2301 function W (Val : Uint) return Word is
2302 function To_Word is new Ada.Unchecked_Conversion (Int, Word);
2304 return To_Word (UI_To_Int (Val));
2307 -- Start of processing for Rep_Value
2310 if Val = No_Uint then
2322 procedure Spaces (N : Natural) is
2324 for J in 1 .. N loop
2333 procedure Tree_Read is
2335 Rep_Table.Tree_Read;
2342 procedure Tree_Write is
2344 Rep_Table.Tree_Write;
2347 ---------------------
2348 -- Write_Info_Line --
2349 ---------------------
2351 procedure Write_Info_Line (S : String) is
2353 Write_Repinfo_Line_Access.all (S (S'First .. S'Last - 1));
2354 end Write_Info_Line;
2356 ---------------------
2357 -- Write_Mechanism --
2358 ---------------------
2360 procedure Write_Mechanism (M : Mechanism_Type) is
2364 Write_Str ("default");
2370 Write_Str ("reference");
2373 raise Program_Error;
2375 end Write_Mechanism;
2377 ---------------------
2378 -- Write_Separator --
2379 ---------------------
2381 procedure Write_Separator is
2383 if Need_Separator then
2384 if List_Representation_Info_To_JSON then
2390 Need_Separator := True;
2392 end Write_Separator;
2394 -----------------------
2395 -- Write_Unknown_Val --
2396 -----------------------
2398 procedure Write_Unknown_Val is
2400 if List_Representation_Info_To_JSON then
2401 Write_Str ("""??""");
2405 end Write_Unknown_Val;
2411 procedure Write_Val (Val : Node_Ref_Or_Val; Paren : Boolean := False) is
2413 if Rep_Not_Constant (Val) then
2414 if List_Representation_Info < 3 or else Val = No_Uint then
2422 if Back_End_Layout then
2423 List_GCC_Expression (Val);
2425 Write_Name_Decoded (Chars (Get_Dynamic_SO_Entity (Val)));
2434 UI_Write (Val, Decimal);