1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1996-2014, 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 ------------------------------------------------------------------------------
26 with Alloc
; use Alloc
;
27 with Atree
; use Atree
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Nlists
; use Nlists
;
31 with Nmake
; use Nmake
;
33 with Output
; use Output
;
34 with Sem_Aux
; use Sem_Aux
;
35 with Sem_Eval
; use Sem_Eval
;
36 with Sem_Util
; use Sem_Util
;
37 with Sinfo
; use Sinfo
;
38 with Stand
; use Stand
;
39 with Stringt
; use Stringt
;
41 with Targparm
; use Targparm
;
42 with Tbuild
; use Tbuild
;
43 with Urealp
; use Urealp
;
45 package body Exp_Dbug
is
47 -- The following table is used to queue up the entities passed as
48 -- arguments to Qualify_Entity_Names for later processing when
49 -- Qualify_All_Entity_Names is called.
51 package Name_Qualify_Units
is new Table
.Table
(
52 Table_Component_Type
=> Node_Id
,
53 Table_Index_Type
=> Nat
,
55 Table_Initial
=> Alloc
.Name_Qualify_Units_Initial
,
56 Table_Increment
=> Alloc
.Name_Qualify_Units_Increment
,
57 Table_Name
=> "Name_Qualify_Units");
59 --------------------------------
60 -- Use of Qualification Flags --
61 --------------------------------
63 -- There are two flags used to keep track of qualification of entities
65 -- Has_Fully_Qualified_Name
68 -- The difference between these is as follows. Has_Qualified_Name is
69 -- set to indicate that the name has been qualified as required by the
70 -- spec of this package. As described there, this may involve the full
71 -- qualification for the name, but for some entities, notably procedure
72 -- local variables, this full qualification is not required.
74 -- The flag Has_Fully_Qualified_Name is set if indeed the name has been
75 -- fully qualified in the Ada sense. If Has_Fully_Qualified_Name is set,
76 -- then Has_Qualified_Name is also set, but the other way round is not
79 -- Consider the following example:
86 -- Here B is a procedure local variable, so it does not need fully
87 -- qualification. The flag Has_Qualified_Name will be set on the
88 -- first attempt to qualify B, to indicate that the job is done
89 -- and need not be redone.
91 -- But Y is qualified as x__y, since procedures are always fully
92 -- qualified, so the first time that an attempt is made to qualify
93 -- the name y, it will be replaced by x__y, and both flags are set.
95 -- Why the two flags? Well there are cases where we derive type names
96 -- from object names. As noted in the spec, type names are always
97 -- fully qualified. Suppose for example that the backend has to build
98 -- a padded type for variable B. then it will construct the PAD name
99 -- from B, but it requires full qualification, so the fully qualified
100 -- type name will be x__b___PAD. The two flags allow the circuit for
101 -- building this name to realize efficiently that b needs further
108 -- The string defined here (and its associated length) is used to gather
109 -- the homonym string that will be appended to Name_Buffer when the name
110 -- is complete. Strip_Suffixes appends to this string as does
111 -- Append_Homonym_Number, and Output_Homonym_Numbers_Suffix appends the
112 -- string to the end of Name_Buffer.
114 Homonym_Numbers
: String (1 .. 256);
115 Homonym_Len
: Natural := 0;
117 ----------------------
118 -- Local Procedures --
119 ----------------------
121 procedure Add_Uint_To_Buffer
(U
: Uint
);
122 -- Add image of universal integer to Name_Buffer, updating Name_Len
124 procedure Add_Real_To_Buffer
(U
: Ureal
);
125 -- Add nnn_ddd to Name_Buffer, where nnn and ddd are integer values of
126 -- the normalized numerator and denominator of the given real value.
128 procedure Append_Homonym_Number
(E
: Entity_Id
);
129 -- If the entity E has homonyms in the same scope, then make an entry
130 -- in the Homonym_Numbers array, bumping Homonym_Count accordingly.
132 function Bounds_Match_Size
(E
: Entity_Id
) return Boolean;
133 -- Determine whether the bounds of E match the size of the type. This is
134 -- used to determine whether encoding is required for a discrete type.
136 function Is_Handled_Scale_Factor
(U
: Ureal
) return Boolean;
137 -- The argument U is the Small_Value of a fixed-point type. This function
138 -- determines whether the back-end can handle this scale factor. When it
139 -- cannot, we have to output a GNAT encoding for the corresponding type.
141 procedure Output_Homonym_Numbers_Suffix
;
142 -- If homonym numbers are stored, then output them into Name_Buffer
144 procedure Prepend_String_To_Buffer
(S
: String);
145 -- Prepend given string to the contents of the string buffer, updating
146 -- the value in Name_Len (i.e. string is added at start of buffer).
148 procedure Prepend_Uint_To_Buffer
(U
: Uint
);
149 -- Prepend image of universal integer to Name_Buffer, updating Name_Len
151 procedure Qualify_Entity_Name
(Ent
: Entity_Id
);
152 -- If not already done, replaces the Chars field of the given entity
153 -- with the appropriate fully qualified name.
155 procedure Reset_Buffers
;
156 -- Reset the contents of Name_Buffer and Homonym_Numbers by setting their
157 -- respective lengths to zero.
159 procedure Strip_Suffixes
(BNPE_Suffix_Found
: in out Boolean);
160 -- Given an qualified entity name in Name_Buffer, remove any plain X or
161 -- X{nb} qualification suffix. The contents of Name_Buffer is not changed
162 -- but Name_Len may be adjusted on return to remove the suffix. If a
163 -- BNPE suffix is found and stripped, then BNPE_Suffix_Found is set to
164 -- True. If no suffix is found, then BNPE_Suffix_Found is not modified.
165 -- This routine also searches for a homonym suffix, and if one is found
166 -- it is also stripped, and the entries are added to the global homonym
167 -- list (Homonym_Numbers) so that they can later be put back.
169 ------------------------
170 -- Add_Real_To_Buffer --
171 ------------------------
173 procedure Add_Real_To_Buffer
(U
: Ureal
) is
175 Add_Uint_To_Buffer
(Norm_Num
(U
));
176 Add_Str_To_Name_Buffer
("_");
177 Add_Uint_To_Buffer
(Norm_Den
(U
));
178 end Add_Real_To_Buffer
;
180 ------------------------
181 -- Add_Uint_To_Buffer --
182 ------------------------
184 procedure Add_Uint_To_Buffer
(U
: Uint
) is
187 Add_Uint_To_Buffer
(-U
);
188 Add_Char_To_Name_Buffer
('m');
190 UI_Image
(U
, Decimal
);
191 Add_Str_To_Name_Buffer
(UI_Image_Buffer
(1 .. UI_Image_Length
));
193 end Add_Uint_To_Buffer
;
195 ---------------------------
196 -- Append_Homonym_Number --
197 ---------------------------
199 procedure Append_Homonym_Number
(E
: Entity_Id
) is
201 procedure Add_Nat_To_H
(Nr
: Nat
);
202 -- Little procedure to append Nr to Homonym_Numbers
208 procedure Add_Nat_To_H
(Nr
: Nat
) is
211 Add_Nat_To_H
(Nr
/ 10);
214 Homonym_Len
:= Homonym_Len
+ 1;
215 Homonym_Numbers
(Homonym_Len
) :=
216 Character'Val (Nr
mod 10 + Character'Pos ('0'));
219 -- Start of processing for Append_Homonym_Number
222 if Has_Homonym
(E
) then
224 H
: Entity_Id
:= Homonym
(E
);
228 while Present
(H
) loop
229 if Scope
(H
) = Scope
(E
) then
236 if Homonym_Len
> 0 then
237 Homonym_Len
:= Homonym_Len
+ 1;
238 Homonym_Numbers
(Homonym_Len
) := '_';
244 end Append_Homonym_Number
;
246 -----------------------
247 -- Bounds_Match_Size --
248 -----------------------
250 function Bounds_Match_Size
(E
: Entity_Id
) return Boolean is
254 if not Is_OK_Static_Subtype
(E
) then
257 elsif Is_Integer_Type
(E
)
258 and then Subtypes_Statically_Match
(E
, Base_Type
(E
))
262 -- Here we check if the static bounds match the natural size, which is
263 -- the size passed through with the debugging information. This is the
264 -- Esize rounded up to 8, 16, 32 or 64 as appropriate.
268 Umark
: constant Uintp
.Save_Mark
:= Uintp
.Mark
;
272 if Esize
(E
) <= 8 then
274 elsif Esize
(E
) <= 16 then
276 elsif Esize
(E
) <= 32 then
282 if Is_Modular_Integer_Type
(E
) or else Is_Enumeration_Type
(E
) then
284 Expr_Rep_Value
(Type_Low_Bound
(E
)) = 0
286 2 ** Siz
- Expr_Rep_Value
(Type_High_Bound
(E
)) = 1;
290 Expr_Rep_Value
(Type_Low_Bound
(E
)) + 2 ** (Siz
- 1) = 0
292 2 ** (Siz
- 1) - Expr_Rep_Value
(Type_High_Bound
(E
)) = 1;
299 end Bounds_Match_Size
;
301 --------------------------------
302 -- Debug_Renaming_Declaration --
303 --------------------------------
305 function Debug_Renaming_Declaration
(N
: Node_Id
) return Node_Id
is
306 Loc
: constant Source_Ptr
:= Sloc
(N
);
307 Ent
: constant Node_Id
:= Defining_Entity
(N
);
308 Nam
: constant Node_Id
:= Name
(N
);
314 Enable
: Boolean := Nkind
(N
) = N_Package_Renaming_Declaration
;
315 -- By default, we do not generate an encoding for renaming. This is
316 -- however done (in which case this is set to True) in a few cases:
317 -- - when a package is renamed,
318 -- - when the renaming involves a packed array,
319 -- - when the renaming involves a packed record.
321 procedure Enable_If_Packed_Array
(N
: Node_Id
);
322 -- Enable encoding generation if N is a packed array
324 function Output_Subscript
(N
: Node_Id
; S
: String) return Boolean;
325 -- Outputs a single subscript value as ?nnn (subscript is compile time
326 -- known value with value nnn) or as ?e (subscript is local constant
327 -- with name e), where S supplies the proper string to use for ?.
328 -- Returns False if the subscript is not of an appropriate type to
329 -- output in one of these two forms. The result is prepended to the
330 -- name stored in Name_Buffer.
332 ----------------------------
333 -- Enable_If_Packed_Array --
334 ----------------------------
336 procedure Enable_If_Packed_Array
(N
: Node_Id
) is
337 T
: constant Entity_Id
:= Etype
(N
);
340 Enable
or else (Ekind
(T
) in Array_Kind
341 and then Present
(Packed_Array_Impl_Type
(T
)));
342 end Enable_If_Packed_Array
;
344 ----------------------
345 -- Output_Subscript --
346 ----------------------
348 function Output_Subscript
(N
: Node_Id
; S
: String) return Boolean is
350 if Compile_Time_Known_Value
(N
) then
351 Prepend_Uint_To_Buffer
(Expr_Value
(N
));
353 elsif Nkind
(N
) = N_Identifier
354 and then Scope
(Entity
(N
)) = Scope
(Ent
)
355 and then Ekind
(Entity
(N
)) = E_Constant
357 Prepend_String_To_Buffer
(Get_Name_String
(Chars
(Entity
(N
))));
363 Prepend_String_To_Buffer
(S
);
365 end Output_Subscript
;
367 -- Start of processing for Debug_Renaming_Declaration
370 if not Comes_From_Source
(N
)
371 and then not Needs_Debug_Info
(Ent
)
376 -- Do not output those local variables in VM case, as this does not
377 -- help debugging (they are just unused), and might lead to duplicated
378 -- local variable names.
380 if VM_Target
/= No_VM
then
384 -- Get renamed entity and compute suffix
394 when N_Expanded_Name
=>
396 -- The entity field for an N_Expanded_Name is on the expanded
397 -- name node itself, so we are done here too.
401 when N_Selected_Component
=>
402 Enable
:= Enable
or else Is_Packed
(Etype
(Prefix
(Ren
)));
403 Prepend_String_To_Buffer
404 (Get_Name_String
(Chars
(Selector_Name
(Ren
))));
405 Prepend_String_To_Buffer
("XR");
408 when N_Indexed_Component
=>
413 Enable_If_Packed_Array
(Prefix
(Ren
));
415 X
:= Last
(Expressions
(Ren
));
416 while Present
(X
) loop
417 if not Output_Subscript
(X
, "XS") then
418 Set_Materialize_Entity
(Ent
);
429 Enable_If_Packed_Array
(Prefix
(Ren
));
430 Typ
:= Etype
(First_Index
(Etype
(Nam
)));
432 if not Output_Subscript
(Type_High_Bound
(Typ
), "XS") then
433 Set_Materialize_Entity
(Ent
);
437 if not Output_Subscript
(Type_Low_Bound
(Typ
), "XL") then
438 Set_Materialize_Entity
(Ent
);
444 when N_Explicit_Dereference
=>
445 Prepend_String_To_Buffer
("XA");
448 -- For now, anything else simply results in no translation
451 Set_Materialize_Entity
(Ent
);
456 -- If we found no reason here to emit an encoding, stop now
459 Set_Materialize_Entity
(Ent
);
463 Prepend_String_To_Buffer
("___XE");
465 -- Include the designation of the form of renaming
468 when N_Object_Renaming_Declaration
=>
469 Prepend_String_To_Buffer
("___XR");
471 when N_Exception_Renaming_Declaration
=>
472 Prepend_String_To_Buffer
("___XRE");
474 when N_Package_Renaming_Declaration
=>
475 Prepend_String_To_Buffer
("___XRP");
481 -- Add the name of the renaming entity to the front
483 Prepend_String_To_Buffer
(Get_Name_String
(Chars
(Ent
)));
485 -- If it is a child unit create a fully qualified name, to disambiguate
486 -- multiple child units with the same name and different parents.
488 if Nkind
(N
) = N_Package_Renaming_Declaration
489 and then Is_Child_Unit
(Ent
)
491 Prepend_String_To_Buffer
("__");
492 Prepend_String_To_Buffer
493 (Get_Name_String
(Chars
(Scope
(Ent
))));
496 -- Create the special object whose name is the debug encoding for the
497 -- renaming declaration.
499 -- For now, the object name contains the suffix encoding for the renamed
500 -- object, but not the name of the leading entity. The object is linked
501 -- the renamed entity using the Debug_Renaming_Link field. Then the
502 -- Qualify_Entity_Name procedure uses this link to create the proper
503 -- fully qualified name.
505 -- The reason we do things this way is that we really need to copy the
506 -- qualification of the renamed entity, and it is really much easier to
507 -- do this after the renamed entity has itself been fully qualified.
509 Obj
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Enter
);
511 Make_Object_Declaration
(Loc
,
512 Defining_Identifier
=> Obj
,
513 Object_Definition
=> New_Occurrence_Of
514 (Standard_Debug_Renaming_Type
, Loc
));
516 Set_Debug_Renaming_Link
(Obj
, Entity
(Ren
));
518 Set_Debug_Info_Needed
(Obj
);
520 -- The renamed entity may be a temporary, e.g. the result of an
521 -- implicit dereference in an iterator. Indicate that the temporary
522 -- itself requires debug information. If the renamed entity comes
523 -- from source this is a no-op.
525 Set_Debug_Info_Needed
(Entity
(Ren
));
527 -- Mark the object as internal so that it won't be initialized when
528 -- pragma Initialize_Scalars or Normalize_Scalars is in use.
530 Set_Is_Internal
(Obj
);
534 -- If we get an exception, just figure it is a case that we cannot
535 -- successfully handle using our current approach, since this is
536 -- only for debugging, no need to take the compilation with us.
540 return Make_Null_Statement
(Loc
);
541 end Debug_Renaming_Declaration
;
543 -----------------------------
544 -- Is_Handled_Scale_Factor --
545 -----------------------------
547 function Is_Handled_Scale_Factor
(U
: Ureal
) return Boolean is
549 -- Keep in sync with gigi (see E_*_Fixed_Point_Type handling in
550 -- decl.c:gnat_to_gnu_entity).
552 if UI_Eq
(Numerator
(U
), Uint_1
) then
553 if Rbase
(U
) = 2 or else Rbase
(U
) = 10 then
559 (UI_Is_In_Int_Range
(Norm_Num
(U
))
561 UI_Is_In_Int_Range
(Norm_Den
(U
)));
562 end Is_Handled_Scale_Factor
;
564 ----------------------
565 -- Get_Encoded_Name --
566 ----------------------
568 -- Note: see spec for details on encodings
570 procedure Get_Encoded_Name
(E
: Entity_Id
) is
571 Has_Suffix
: Boolean;
574 -- If not generating code, there is no need to create encoded names, and
575 -- problems when the back-end is called to annotate types without full
576 -- code generation. See comments in Get_External_Name for additional
579 -- However we do create encoded names if the back end is active, even
580 -- if Operating_Mode got reset. Otherwise any serious error reported
581 -- by the backend calling Error_Msg changes the Compilation_Mode to
582 -- Check_Semantics, which disables the functionality of this routine,
583 -- causing the generation of spurious additional errors.
585 -- Couldn't we just test Original_Operating_Mode here? ???
587 if Operating_Mode
/= Generate_Code
588 and then not Generating_Code
593 Get_Name_String
(Chars
(E
));
595 -- Nothing to do if we do not have a type
599 -- Or if this is an enumeration base type
601 or else (Is_Enumeration_Type
(E
) and then Is_Base_Type
(E
))
603 -- Or if this is a dummy type for a renaming
605 or else (Name_Len
>= 3 and then
606 Name_Buffer
(Name_Len
- 2 .. Name_Len
) = "_XR")
608 or else (Name_Len
>= 4 and then
609 (Name_Buffer
(Name_Len
- 3 .. Name_Len
) = "_XRE"
611 Name_Buffer
(Name_Len
- 3 .. Name_Len
) = "_XRP"))
613 -- For all these cases, just return the name unchanged
616 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
622 -- Fixed-point case: generate GNAT encodings when asked to or when we
623 -- know the back-end will not be able to handle the scale factor.
625 if Is_Fixed_Point_Type
(E
)
626 and then (GNAT_Encodings
/= DWARF_GNAT_Encodings_Minimal
627 or else not Is_Handled_Scale_Factor
(Small_Value
(E
)))
629 Get_External_Name
(E
, True, "XF_");
630 Add_Real_To_Buffer
(Delta_Value
(E
));
632 if Small_Value
(E
) /= Delta_Value
(E
) then
633 Add_Str_To_Name_Buffer
("_");
634 Add_Real_To_Buffer
(Small_Value
(E
));
637 -- Discrete case where bounds do not match size. Match only biased
638 -- types when asked to output as little encodings as possible.
640 elsif ((GNAT_Encodings
/= DWARF_GNAT_Encodings_Minimal
641 and then Is_Discrete_Type
(E
))
643 (GNAT_Encodings
= DWARF_GNAT_Encodings_Minimal
644 and then Has_Biased_Representation
(E
)))
645 and then not Bounds_Match_Size
(E
)
648 Lo
: constant Node_Id
:= Type_Low_Bound
(E
);
649 Hi
: constant Node_Id
:= Type_High_Bound
(E
);
651 Lo_Con
: constant Boolean := Compile_Time_Known_Value
(Lo
);
652 Hi_Con
: constant Boolean := Compile_Time_Known_Value
(Hi
);
654 Lo_Discr
: constant Boolean :=
655 Nkind
(Lo
) = N_Identifier
656 and then Ekind
(Entity
(Lo
)) = E_Discriminant
;
658 Hi_Discr
: constant Boolean :=
659 Nkind
(Hi
) = N_Identifier
660 and then Ekind
(Entity
(Hi
)) = E_Discriminant
;
662 Lo_Encode
: constant Boolean := Lo_Con
or Lo_Discr
;
663 Hi_Encode
: constant Boolean := Hi_Con
or Hi_Discr
;
665 Biased
: constant Boolean := Has_Biased_Representation
(E
);
669 Get_External_Name
(E
, True, "XB");
671 Get_External_Name
(E
, True, "XD");
674 if Lo_Encode
or Hi_Encode
then
676 Add_Str_To_Name_Buffer
("_");
680 Add_Str_To_Name_Buffer
("LU_");
682 Add_Str_To_Name_Buffer
("L_");
685 Add_Str_To_Name_Buffer
("U_");
690 Add_Uint_To_Buffer
(Expr_Rep_Value
(Lo
));
692 Get_Name_String_And_Append
(Chars
(Entity
(Lo
)));
695 if Lo_Encode
and Hi_Encode
then
696 Add_Str_To_Name_Buffer
("__");
700 Add_Uint_To_Buffer
(Expr_Rep_Value
(Hi
));
702 Get_Name_String_And_Append
(Chars
(Entity
(Hi
)));
707 -- For all other cases, the encoded name is the normal type name
711 Get_External_Name
(E
);
714 if Debug_Flag_B
and then Has_Suffix
then
715 Write_Str
("**** type ");
716 Write_Name
(Chars
(E
));
717 Write_Str
(" is encoded as ");
718 Write_Str
(Name_Buffer
(1 .. Name_Len
));
722 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
723 end Get_Encoded_Name
;
725 -----------------------
726 -- Get_External_Name --
727 -----------------------
729 procedure Get_External_Name
731 Has_Suffix
: Boolean := False;
732 Suffix
: String := "")
734 E
: Entity_Id
:= Entity
;
737 procedure Get_Qualified_Name_And_Append
(Entity
: Entity_Id
);
738 -- Appends fully qualified name of given entity to Name_Buffer
740 -----------------------------------
741 -- Get_Qualified_Name_And_Append --
742 -----------------------------------
744 procedure Get_Qualified_Name_And_Append
(Entity
: Entity_Id
) is
746 -- If the entity is a compilation unit, its scope is Standard,
747 -- there is no outer scope, and the no further qualification
750 -- If the front end has already computed a fully qualified name,
751 -- then it is also the case that no further qualification is
754 if Present
(Scope
(Scope
(Entity
)))
755 and then not Has_Fully_Qualified_Name
(Entity
)
757 Get_Qualified_Name_And_Append
(Scope
(Entity
));
758 Add_Str_To_Name_Buffer
("__");
759 Get_Name_String_And_Append
(Chars
(Entity
));
760 Append_Homonym_Number
(Entity
);
763 Get_Name_String_And_Append
(Chars
(Entity
));
765 end Get_Qualified_Name_And_Append
;
767 -- Start of processing for Get_External_Name
770 -- If we are not in code generation mode, this procedure may still be
771 -- called from Back_End (more specifically - from gigi for doing type
772 -- representation annotation or some representation-specific checks).
773 -- But in this mode there is no need to mess with external names.
775 -- Furthermore, the call causes difficulties in this case because the
776 -- string representing the homonym number is not correctly reset as a
777 -- part of the call to Output_Homonym_Numbers_Suffix (which is not
780 if Operating_Mode
/= Generate_Code
then
786 -- If this is a child unit, we want the child
788 if Nkind
(E
) = N_Defining_Program_Unit_Name
then
789 E
:= Defining_Identifier
(Entity
);
794 -- Case of interface name being used
796 if (Kind
= E_Procedure
or else
797 Kind
= E_Function
or else
798 Kind
= E_Constant
or else
799 Kind
= E_Variable
or else
801 and then Present
(Interface_Name
(E
))
802 and then No
(Address_Clause
(E
))
803 and then not Has_Suffix
805 Add_String_To_Name_Buffer
(Strval
(Interface_Name
(E
)));
807 -- All other cases besides the interface name case
810 -- If this is a library level subprogram (i.e. a subprogram that is a
811 -- compilation unit other than a subunit), then we prepend _ada_ to
812 -- ensure distinctions required as described in the spec.
814 -- Check explicitly for child units, because those are not flagged
815 -- as Compilation_Units by lib. Should they be ???
818 and then (Is_Compilation_Unit
(E
) or Is_Child_Unit
(E
))
819 and then not Has_Suffix
821 Add_Str_To_Name_Buffer
("_ada_");
824 -- If the entity is a subprogram instance that is not a compilation
825 -- unit, generate the name of the original Ada entity, which is the
828 if Is_Generic_Instance
(E
)
829 and then Is_Subprogram
(E
)
830 and then not Is_Compilation_Unit
(Scope
(E
))
831 and then (Ekind
(Scope
(E
)) = E_Package
833 Ekind
(Scope
(E
)) = E_Package_Body
)
834 and then Present
(Related_Instance
(Scope
(E
)))
836 E
:= Related_Instance
(Scope
(E
));
839 Get_Qualified_Name_And_Append
(E
);
843 Add_Str_To_Name_Buffer
("___");
844 Add_Str_To_Name_Buffer
(Suffix
);
847 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
848 end Get_External_Name
;
850 --------------------------
851 -- Get_Variant_Encoding --
852 --------------------------
854 procedure Get_Variant_Encoding
(V
: Node_Id
) is
857 procedure Choice_Val
(Typ
: Character; Choice
: Node_Id
);
858 -- Output encoded value for a single choice value. Typ is the key
859 -- character ('S', 'F', or 'T') that precedes the choice value.
865 procedure Choice_Val
(Typ
: Character; Choice
: Node_Id
) is
867 if Nkind
(Choice
) = N_Integer_Literal
then
868 Add_Char_To_Name_Buffer
(Typ
);
869 Add_Uint_To_Buffer
(Intval
(Choice
));
871 -- Character literal with no entity present (this is the case
872 -- Standard.Character or Standard.Wide_Character as root type)
874 elsif Nkind
(Choice
) = N_Character_Literal
875 and then No
(Entity
(Choice
))
877 Add_Char_To_Name_Buffer
(Typ
);
878 Add_Uint_To_Buffer
(Char_Literal_Value
(Choice
));
882 Ent
: constant Entity_Id
:= Entity
(Choice
);
885 if Ekind
(Ent
) = E_Enumeration_Literal
then
886 Add_Char_To_Name_Buffer
(Typ
);
887 Add_Uint_To_Buffer
(Enumeration_Rep
(Ent
));
890 pragma Assert
(Ekind
(Ent
) = E_Constant
);
891 Choice_Val
(Typ
, Constant_Value
(Ent
));
897 -- Start of processing for Get_Variant_Encoding
902 Choice
:= First
(Discrete_Choices
(V
));
903 while Present
(Choice
) loop
904 if Nkind
(Choice
) = N_Others_Choice
then
905 Add_Char_To_Name_Buffer
('O');
907 elsif Nkind
(Choice
) = N_Range
then
908 Choice_Val
('R', Low_Bound
(Choice
));
909 Choice_Val
('T', High_Bound
(Choice
));
911 elsif Is_Entity_Name
(Choice
)
912 and then Is_Type
(Entity
(Choice
))
914 Choice_Val
('R', Type_Low_Bound
(Entity
(Choice
)));
915 Choice_Val
('T', Type_High_Bound
(Entity
(Choice
)));
917 elsif Nkind
(Choice
) = N_Subtype_Indication
then
919 Rang
: constant Node_Id
:=
920 Range_Expression
(Constraint
(Choice
));
922 Choice_Val
('R', Low_Bound
(Rang
));
923 Choice_Val
('T', High_Bound
(Rang
));
927 Choice_Val
('S', Choice
);
933 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
937 VP
: constant Node_Id
:= Parent
(V
); -- Variant_Part
938 CL
: constant Node_Id
:= Parent
(VP
); -- Component_List
939 RD
: constant Node_Id
:= Parent
(CL
); -- Record_Definition
940 FT
: constant Node_Id
:= Parent
(RD
); -- Full_Type_Declaration
943 Write_Str
("**** variant for type ");
944 Write_Name
(Chars
(Defining_Identifier
(FT
)));
945 Write_Str
(" is encoded as ");
946 Write_Str
(Name_Buffer
(1 .. Name_Len
));
950 end Get_Variant_Encoding
;
952 -----------------------------------------
953 -- Build_Subprogram_Instance_Renamings --
954 -----------------------------------------
956 procedure Build_Subprogram_Instance_Renamings
965 E
:= First_Entity
(Wrapper
);
966 while Present
(E
) loop
967 if Nkind
(Parent
(E
)) = N_Object_Declaration
968 and then Is_Elementary_Type
(Etype
(E
))
970 Loc
:= Sloc
(Expression
(Parent
(E
)));
971 Decl
:= Make_Object_Renaming_Declaration
(Loc
,
972 Defining_Identifier
=>
973 Make_Defining_Identifier
(Loc
, Chars
(E
)),
974 Subtype_Mark
=> New_Occurrence_Of
(Etype
(E
), Loc
),
975 Name
=> New_Occurrence_Of
(E
, Loc
));
977 Append
(Decl
, Declarations
(N
));
978 Set_Needs_Debug_Info
(Defining_Identifier
(Decl
));
983 end Build_Subprogram_Instance_Renamings
;
985 ------------------------------------
986 -- Get_Secondary_DT_External_Name --
987 ------------------------------------
989 procedure Get_Secondary_DT_External_Name
991 Ancestor_Typ
: Entity_Id
;
995 Get_External_Name
(Typ
);
997 if Ancestor_Typ
/= Typ
then
999 Len
: constant Natural := Name_Len
;
1000 Save_Str
: constant String (1 .. Name_Len
)
1001 := Name_Buffer
(1 .. Name_Len
);
1003 Get_External_Name
(Ancestor_Typ
);
1005 -- Append the extended name of the ancestor to the
1006 -- extended name of Typ
1008 Name_Buffer
(Len
+ 2 .. Len
+ Name_Len
+ 1) :=
1009 Name_Buffer
(1 .. Name_Len
);
1010 Name_Buffer
(1 .. Len
) := Save_Str
;
1011 Name_Buffer
(Len
+ 1) := '_';
1012 Name_Len
:= Len
+ Name_Len
+ 1;
1016 Add_Nat_To_Name_Buffer
(Suffix_Index
);
1017 end Get_Secondary_DT_External_Name
;
1019 ---------------------------------
1020 -- Make_Packed_Array_Impl_Type_Name --
1021 ---------------------------------
1023 function Make_Packed_Array_Impl_Type_Name
1029 Get_Name_String
(Chars
(Typ
));
1030 Add_Str_To_Name_Buffer
("___XP");
1031 Add_Uint_To_Buffer
(Csize
);
1033 end Make_Packed_Array_Impl_Type_Name
;
1035 -----------------------------------
1036 -- Output_Homonym_Numbers_Suffix --
1037 -----------------------------------
1039 procedure Output_Homonym_Numbers_Suffix
is
1043 if Homonym_Len
> 0 then
1045 -- Check for all 1's, in which case we do not output
1049 exit when Homonym_Numbers
(J
) /= '1';
1051 -- If we reached end of string we do not output
1053 if J
= Homonym_Len
then
1058 exit when Homonym_Numbers
(J
+ 1) /= '_';
1062 -- If we exit the loop then suffix must be output
1064 Add_Str_To_Name_Buffer
("__");
1065 Add_Str_To_Name_Buffer
(Homonym_Numbers
(1 .. Homonym_Len
));
1068 end Output_Homonym_Numbers_Suffix
;
1070 ------------------------------
1071 -- Prepend_String_To_Buffer --
1072 ------------------------------
1074 procedure Prepend_String_To_Buffer
(S
: String) is
1075 N
: constant Integer := S
'Length;
1077 Name_Buffer
(1 + N
.. Name_Len
+ N
) := Name_Buffer
(1 .. Name_Len
);
1078 Name_Buffer
(1 .. N
) := S
;
1079 Name_Len
:= Name_Len
+ N
;
1080 end Prepend_String_To_Buffer
;
1082 ----------------------------
1083 -- Prepend_Uint_To_Buffer --
1084 ----------------------------
1086 procedure Prepend_Uint_To_Buffer
(U
: Uint
) is
1089 Prepend_String_To_Buffer
("m");
1090 Prepend_Uint_To_Buffer
(-U
);
1092 UI_Image
(U
, Decimal
);
1093 Prepend_String_To_Buffer
(UI_Image_Buffer
(1 .. UI_Image_Length
));
1095 end Prepend_Uint_To_Buffer
;
1097 ------------------------------
1098 -- Qualify_All_Entity_Names --
1099 ------------------------------
1101 procedure Qualify_All_Entity_Names
is
1106 for J
in Name_Qualify_Units
.First
.. Name_Qualify_Units
.Last
loop
1107 E
:= Defining_Entity
(Name_Qualify_Units
.Table
(J
));
1109 Qualify_Entity_Name
(E
);
1111 -- Normally entities in the qualification list are scopes, but in the
1112 -- case of a library-level package renaming there is an associated
1113 -- variable that encodes the debugger name and that variable is
1114 -- entered in the list since it occurs in the Aux_Decls list of the
1115 -- compilation and doesn't have a normal scope.
1117 if Ekind
(E
) /= E_Variable
then
1118 Ent
:= First_Entity
(E
);
1119 while Present
(Ent
) loop
1121 Qualify_Entity_Name
(Ent
);
1124 -- There are odd cases where Last_Entity (E) = E. This happens
1125 -- in the case of renaming of packages. This test avoids
1126 -- getting stuck in such cases.
1132 end Qualify_All_Entity_Names
;
1134 -------------------------
1135 -- Qualify_Entity_Name --
1136 -------------------------
1138 procedure Qualify_Entity_Name
(Ent
: Entity_Id
) is
1140 Full_Qualify_Name
: String (1 .. Name_Buffer
'Length);
1141 Full_Qualify_Len
: Natural := 0;
1142 -- Used to accumulate fully qualified name of subprogram
1144 procedure Fully_Qualify_Name
(E
: Entity_Id
);
1145 -- Used to qualify a subprogram or type name, where full
1146 -- qualification up to Standard is always used. Name is set
1147 -- in Full_Qualify_Name with the length in Full_Qualify_Len.
1148 -- Note that this routine does not prepend the _ada_ string
1149 -- required for library subprograms (this is done in the back end).
1151 function Is_BNPE
(S
: Entity_Id
) return Boolean;
1152 -- Determines if S is a BNPE, i.e. Body-Nested Package Entity, which
1153 -- is defined to be a package which is immediately nested within a
1156 function Qualify_Needed
(S
: Entity_Id
) return Boolean;
1157 -- Given a scope, determines if the scope is to be included in the
1158 -- fully qualified name, True if so, False if not. Blocks and loops
1159 -- are excluded from a qualified name.
1161 procedure Set_BNPE_Suffix
(E
: Entity_Id
);
1162 -- Recursive routine to append the BNPE qualification suffix. Works
1163 -- from right to left with E being the current entity in the list.
1164 -- The result does NOT have the trailing n's and trailing b stripped.
1165 -- The caller must do this required stripping.
1167 procedure Set_Entity_Name
(E
: Entity_Id
);
1168 -- Internal recursive routine that does most of the work. This routine
1169 -- leaves the result sitting in Name_Buffer and Name_Len.
1171 BNPE_Suffix_Needed
: Boolean := False;
1172 -- Set true if a body-nested package entity suffix is required
1174 Save_Chars
: constant Name_Id
:= Chars
(Ent
);
1175 -- Save original name
1177 ------------------------
1178 -- Fully_Qualify_Name --
1179 ------------------------
1181 procedure Fully_Qualify_Name
(E
: Entity_Id
) is
1182 Discard
: Boolean := False;
1185 -- Ignore empty entry (can happen in error cases)
1190 -- If this we are qualifying entities local to a generic instance,
1191 -- use the name of the original instantiation, not that of the
1192 -- anonymous subprogram in the wrapper package, so that gdb doesn't
1193 -- have to know about these.
1195 elsif Is_Generic_Instance
(E
)
1196 and then Is_Subprogram
(E
)
1197 and then not Comes_From_Source
(E
)
1198 and then not Is_Compilation_Unit
(Scope
(E
))
1200 Fully_Qualify_Name
(Related_Instance
(Scope
(E
)));
1204 -- If we reached fully qualified name, then just copy it
1206 if Has_Fully_Qualified_Name
(E
) then
1207 Get_Name_String
(Chars
(E
));
1208 Strip_Suffixes
(Discard
);
1209 Full_Qualify_Name
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
1210 Full_Qualify_Len
:= Name_Len
;
1211 Set_Has_Fully_Qualified_Name
(Ent
);
1213 -- Case of non-fully qualified name
1216 if Scope
(E
) = Standard_Standard
then
1217 Set_Has_Fully_Qualified_Name
(Ent
);
1219 Fully_Qualify_Name
(Scope
(E
));
1220 Full_Qualify_Name
(Full_Qualify_Len
+ 1) := '_';
1221 Full_Qualify_Name
(Full_Qualify_Len
+ 2) := '_';
1222 Full_Qualify_Len
:= Full_Qualify_Len
+ 2;
1225 if Has_Qualified_Name
(E
) then
1226 Get_Unqualified_Name_String
(Chars
(E
));
1228 Get_Name_String
(Chars
(E
));
1231 -- Here we do one step of the qualification
1234 (Full_Qualify_Len
+ 1 .. Full_Qualify_Len
+ Name_Len
) :=
1235 Name_Buffer
(1 .. Name_Len
);
1236 Full_Qualify_Len
:= Full_Qualify_Len
+ Name_Len
;
1237 Append_Homonym_Number
(E
);
1241 BNPE_Suffix_Needed
:= True;
1243 end Fully_Qualify_Name
;
1249 function Is_BNPE
(S
: Entity_Id
) return Boolean is
1251 return Ekind
(S
) = E_Package
and then Is_Package_Body_Entity
(S
);
1254 --------------------
1255 -- Qualify_Needed --
1256 --------------------
1258 function Qualify_Needed
(S
: Entity_Id
) return Boolean is
1260 -- If we got all the way to Standard, then we have certainly
1261 -- fully qualified the name, so set the flag appropriately,
1262 -- and then return False, since we are most certainly done.
1264 if S
= Standard_Standard
then
1265 Set_Has_Fully_Qualified_Name
(Ent
, True);
1268 -- Otherwise figure out if further qualification is required
1271 return Is_Subprogram
(Ent
)
1272 or else Ekind
(Ent
) = E_Subprogram_Body
1273 or else (Ekind
(S
) /= E_Block
1274 and then Ekind
(S
) /= E_Loop
1275 and then not Is_Dynamic_Scope
(S
));
1279 ---------------------
1280 -- Set_BNPE_Suffix --
1281 ---------------------
1283 procedure Set_BNPE_Suffix
(E
: Entity_Id
) is
1284 S
: constant Entity_Id
:= Scope
(E
);
1287 if Qualify_Needed
(S
) then
1288 Set_BNPE_Suffix
(S
);
1291 Add_Char_To_Name_Buffer
('b');
1293 Add_Char_To_Name_Buffer
('n');
1297 Add_Char_To_Name_Buffer
('X');
1299 end Set_BNPE_Suffix
;
1301 ---------------------
1302 -- Set_Entity_Name --
1303 ---------------------
1305 procedure Set_Entity_Name
(E
: Entity_Id
) is
1306 S
: constant Entity_Id
:= Scope
(E
);
1309 -- If we reach an already qualified name, just take the encoding
1310 -- except that we strip the package body suffixes, since these
1311 -- will be separately put on later.
1313 if Has_Qualified_Name
(E
) then
1314 Get_Name_String_And_Append
(Chars
(E
));
1315 Strip_Suffixes
(BNPE_Suffix_Needed
);
1317 -- If the top level name we are adding is itself fully
1318 -- qualified, then that means that the name that we are
1319 -- preparing for the Fully_Qualify_Name call will also
1320 -- generate a fully qualified name.
1322 if Has_Fully_Qualified_Name
(E
) then
1323 Set_Has_Fully_Qualified_Name
(Ent
);
1326 -- Case where upper level name is not encoded yet
1329 -- Recurse if further qualification required
1331 if Qualify_Needed
(S
) then
1332 Set_Entity_Name
(S
);
1333 Add_Str_To_Name_Buffer
("__");
1336 -- Otherwise get name and note if it is a BNPE
1338 Get_Name_String_And_Append
(Chars
(E
));
1341 BNPE_Suffix_Needed
:= True;
1344 Append_Homonym_Number
(E
);
1346 end Set_Entity_Name
;
1348 -- Start of processing for Qualify_Entity_Name
1351 if Has_Qualified_Name
(Ent
) then
1354 -- In formal verification mode, simply append a suffix for homonyms.
1355 -- We used to qualify entity names as full expansion does, but this was
1356 -- removed as this prevents the verification back-end from using a short
1357 -- name for debugging and user interaction. The verification back-end
1358 -- already takes care of qualifying names when needed. Still mark the
1359 -- name as being qualified, as Qualify_Entity_Name may be called more
1360 -- than once on the same entity.
1362 elsif GNATprove_Mode
then
1363 if Has_Homonym
(Ent
) then
1364 Get_Name_String
(Chars
(Ent
));
1365 Append_Homonym_Number
(Ent
);
1366 Output_Homonym_Numbers_Suffix
;
1367 Set_Chars
(Ent
, Name_Enter
);
1370 Set_Has_Qualified_Name
(Ent
);
1373 -- If the entity is a variable encoding the debug name for an object
1374 -- renaming, then the qualified name of the entity associated with the
1375 -- renamed object can now be incorporated in the debug name.
1377 elsif Ekind
(Ent
) = E_Variable
1378 and then Present
(Debug_Renaming_Link
(Ent
))
1381 Qualify_Entity_Name
(Debug_Renaming_Link
(Ent
));
1382 Get_Name_String
(Chars
(Ent
));
1384 -- Retrieve the now-qualified name of the renamed entity and insert
1385 -- it in the middle of the name, just preceding the suffix encoding
1386 -- describing the renamed object.
1389 Renamed_Id
: constant String :=
1390 Get_Name_String
(Chars
(Debug_Renaming_Link
(Ent
)));
1391 Insert_Len
: constant Integer := Renamed_Id
'Length + 1;
1392 Index
: Natural := Name_Len
- 3;
1395 -- Loop backwards through the name to find the start of the "___"
1396 -- sequence associated with the suffix.
1398 while Index
>= Name_Buffer
'First
1399 and then (Name_Buffer
(Index
+ 1) /= '_'
1400 or else Name_Buffer
(Index
+ 2) /= '_'
1401 or else Name_Buffer
(Index
+ 3) /= '_')
1406 pragma Assert
(Name_Buffer
(Index
+ 1 .. Index
+ 3) = "___");
1408 -- Insert an underscore separator and the entity name just in
1409 -- front of the suffix.
1411 Name_Buffer
(Index
+ 1 + Insert_Len
.. Name_Len
+ Insert_Len
) :=
1412 Name_Buffer
(Index
+ 1 .. Name_Len
);
1413 Name_Buffer
(Index
+ 1) := '_';
1414 Name_Buffer
(Index
+ 2 .. Index
+ Insert_Len
) := Renamed_Id
;
1415 Name_Len
:= Name_Len
+ Insert_Len
;
1418 -- Reset the name of the variable to the new name that includes the
1419 -- name of the renamed entity.
1421 Set_Chars
(Ent
, Name_Enter
);
1423 -- If the entity needs qualification by its scope then develop it
1424 -- here, add the variable's name, and again reset the entity name.
1426 if Qualify_Needed
(Scope
(Ent
)) then
1428 Set_Entity_Name
(Scope
(Ent
));
1429 Add_Str_To_Name_Buffer
("__");
1431 Get_Name_String_And_Append
(Chars
(Ent
));
1433 Set_Chars
(Ent
, Name_Enter
);
1436 Set_Has_Qualified_Name
(Ent
);
1439 elsif Is_Subprogram
(Ent
)
1440 or else Ekind
(Ent
) = E_Subprogram_Body
1441 or else Is_Type
(Ent
)
1443 Fully_Qualify_Name
(Ent
);
1444 Name_Len
:= Full_Qualify_Len
;
1445 Name_Buffer
(1 .. Name_Len
) := Full_Qualify_Name
(1 .. Name_Len
);
1447 elsif Qualify_Needed
(Scope
(Ent
)) then
1449 Set_Entity_Name
(Ent
);
1452 Set_Has_Qualified_Name
(Ent
);
1456 -- Fall through with a fully qualified name in Name_Buffer/Name_Len
1458 Output_Homonym_Numbers_Suffix
;
1460 -- Add body-nested package suffix if required
1462 if BNPE_Suffix_Needed
1463 and then Ekind
(Ent
) /= E_Enumeration_Literal
1465 Set_BNPE_Suffix
(Ent
);
1467 -- Strip trailing n's and last trailing b as required. note that
1468 -- we know there is at least one b, or no suffix would be generated.
1470 while Name_Buffer
(Name_Len
) = 'n' loop
1471 Name_Len
:= Name_Len
- 1;
1474 Name_Len
:= Name_Len
- 1;
1477 Set_Chars
(Ent
, Name_Enter
);
1478 Set_Has_Qualified_Name
(Ent
);
1480 if Debug_Flag_BB
then
1482 Write_Name
(Save_Chars
);
1483 Write_Str
(" qualified as ");
1484 Write_Name
(Chars
(Ent
));
1487 end Qualify_Entity_Name
;
1489 --------------------------
1490 -- Qualify_Entity_Names --
1491 --------------------------
1493 procedure Qualify_Entity_Names
(N
: Node_Id
) is
1495 Name_Qualify_Units
.Append
(N
);
1496 end Qualify_Entity_Names
;
1502 procedure Reset_Buffers
is
1508 --------------------
1509 -- Strip_Suffixes --
1510 --------------------
1512 procedure Strip_Suffixes
(BNPE_Suffix_Found
: in out Boolean) is
1515 pragma Warnings
(Off
, BNPE_Suffix_Found
);
1516 -- Since this procedure only ever sets the flag
1519 -- Search for and strip BNPE suffix
1521 for J
in reverse 2 .. Name_Len
loop
1522 if Name_Buffer
(J
) = 'X' then
1524 BNPE_Suffix_Found
:= True;
1528 exit when Name_Buffer
(J
) /= 'b' and then Name_Buffer
(J
) /= 'n';
1531 -- Search for and strip homonym numbers suffix
1533 for J
in reverse 2 .. Name_Len
- 2 loop
1534 if Name_Buffer
(J
) = '_'
1535 and then Name_Buffer
(J
+ 1) = '_'
1537 if Name_Buffer
(J
+ 2) in '0' .. '9' then
1538 if Homonym_Len
> 0 then
1539 Homonym_Len
:= Homonym_Len
+ 1;
1540 Homonym_Numbers
(Homonym_Len
) := '-';
1543 SL
:= Name_Len
- (J
+ 1);
1545 Homonym_Numbers
(Homonym_Len
+ 1 .. Homonym_Len
+ SL
) :=
1546 Name_Buffer
(J
+ 2 .. Name_Len
);
1548 Homonym_Len
:= Homonym_Len
+ SL
;