1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1996-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. 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 Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Exp_Util
; use Exp_Util
;
31 with Nlists
; use Nlists
;
32 with Nmake
; use Nmake
;
34 with Output
; use Output
;
35 with Sem_Aux
; use Sem_Aux
;
36 with Sem_Eval
; use Sem_Eval
;
37 with Sem_Util
; use Sem_Util
;
38 with Sinfo
; use Sinfo
;
39 with Stand
; use Stand
;
40 with Stringt
; use Stringt
;
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
223 if Homonym_Len
> 0 then
224 Homonym_Len
:= Homonym_Len
+ 1;
225 Homonym_Numbers
(Homonym_Len
) := '_';
228 Add_Nat_To_H
(Homonym_Number
(E
));
230 end Append_Homonym_Number
;
232 -----------------------
233 -- Bounds_Match_Size --
234 -----------------------
236 function Bounds_Match_Size
(E
: Entity_Id
) return Boolean is
240 if not Is_OK_Static_Subtype
(E
) then
243 elsif Is_Integer_Type
(E
)
244 and then Subtypes_Statically_Match
(E
, Base_Type
(E
))
248 -- Here we check if the static bounds match the natural size, which is
249 -- the size passed through with the debugging information. This is the
250 -- Esize rounded up to 8, 16, 32 or 64 as appropriate.
254 Umark
: constant Uintp
.Save_Mark
:= Uintp
.Mark
;
258 if Esize
(E
) <= 8 then
260 elsif Esize
(E
) <= 16 then
262 elsif Esize
(E
) <= 32 then
268 if Is_Modular_Integer_Type
(E
) or else Is_Enumeration_Type
(E
) then
270 Expr_Rep_Value
(Type_Low_Bound
(E
)) = 0
272 2 ** Siz
- Expr_Rep_Value
(Type_High_Bound
(E
)) = 1;
276 Expr_Rep_Value
(Type_Low_Bound
(E
)) + 2 ** (Siz
- 1) = 0
278 2 ** (Siz
- 1) - Expr_Rep_Value
(Type_High_Bound
(E
)) = 1;
285 end Bounds_Match_Size
;
287 --------------------------------
288 -- Debug_Renaming_Declaration --
289 --------------------------------
291 function Debug_Renaming_Declaration
(N
: Node_Id
) return Node_Id
is
292 Loc
: constant Source_Ptr
:= Sloc
(N
);
293 Ent
: constant Node_Id
:= Defining_Entity
(N
);
294 Nam
: constant Node_Id
:= Name
(N
);
300 Enable
: Boolean := Nkind
(N
) = N_Package_Renaming_Declaration
;
301 -- By default, we do not generate an encoding for renaming. This is
302 -- however done (in which case this is set to True) in a few cases:
303 -- - when a package is renamed,
304 -- - when the renaming involves a packed array,
305 -- - when the renaming involves a packed record.
307 Last_Is_Indexed_Comp
: Boolean := False;
308 -- Whether the last subscript value was an indexed component access (XS)
310 procedure Enable_If_Packed_Array
(N
: Node_Id
);
311 -- Enable encoding generation if N is a packed array
313 function Output_Subscript
(N
: Node_Id
; S
: String) return Boolean;
314 -- Outputs a single subscript value as ?nnn (subscript is compile time
315 -- known value with value nnn) or as ?e (subscript is local constant
316 -- with name e), where S supplies the proper string to use for ?.
317 -- Returns False if the subscript is not of an appropriate type to
318 -- output in one of these two forms. The result is prepended to the
319 -- name stored in Name_Buffer.
321 function Scope_Contains
(Sc
: Node_Id
; Ent
: Entity_Id
) return Boolean;
322 -- Return whether Ent belong to the Sc scope
324 ----------------------------
325 -- Enable_If_Packed_Array --
326 ----------------------------
328 procedure Enable_If_Packed_Array
(N
: Node_Id
) is
329 T
: constant Entity_Id
:= Underlying_Type
(Etype
(N
));
335 (Ekind
(T
) in Array_Kind
336 and then Present
(Packed_Array_Impl_Type
(T
)));
337 end Enable_If_Packed_Array
;
339 ----------------------
340 -- Output_Subscript --
341 ----------------------
343 function Output_Subscript
(N
: Node_Id
; S
: String) return Boolean is
345 if Compile_Time_Known_Value
(N
) then
346 Prepend_Uint_To_Buffer
(Expr_Value
(N
));
348 elsif Nkind
(N
) = N_Identifier
349 and then Scope_Contains
(Scope
(Entity
(N
)), Ent
)
350 and then (Ekind
(Entity
(N
)) = E_Constant
351 or else Ekind
(Entity
(N
)) = E_In_Parameter
)
353 Prepend_String_To_Buffer
(Get_Name_String
(Chars
(Entity
(N
))));
359 Prepend_String_To_Buffer
(S
);
361 end Output_Subscript
;
367 function Scope_Contains
(Sc
: Node_Id
; Ent
: Entity_Id
) return Boolean is
368 Cur
: Node_Id
:= Scope
(Ent
);
371 while Present
(Cur
) loop
382 -- Start of processing for Debug_Renaming_Declaration
385 if not Comes_From_Source
(N
) and then not Needs_Debug_Info
(Ent
) then
389 -- Get renamed entity and compute suffix
394 -- The expression that designates the renamed object is sometimes
395 -- expanded into bit-wise operations. We want to work instead on
396 -- array/record components accesses, so try to analyze the unexpanded
399 Ren
:= Original_Node
(Ren
);
405 if not Present
(Renamed_Object
(Entity
(Ren
))) then
409 -- This is a renaming of a renaming: traverse until the final
410 -- renaming to see if anything is packed along the way.
412 Ren
:= Renamed_Object
(Entity
(Ren
));
414 when N_Selected_Component
=>
416 Sel_Id
: constant Entity_Id
:=
417 Entity
(Selector_Name
(Ren
));
421 -- If the renaming involves a call to a primitive function,
422 -- we are out of the scope of renaming encodings. We will
423 -- very likely create a variable to hold the renamed value
424 -- anyway, so the renaming entity will be available in
427 exit when not Ekind_In
(Sel_Id
, E_Component
, E_Discriminant
);
429 First_Bit
:= Normalized_First_Bit
(Sel_Id
);
433 (Underlying_Type
(Etype
(Prefix
(Ren
))))
434 or else (First_Bit
/= No_Uint
435 and then First_Bit
/= Uint_0
);
438 Prepend_String_To_Buffer
439 (Get_Name_String
(Chars
(Selector_Name
(Ren
))));
440 Prepend_String_To_Buffer
("XR");
442 Last_Is_Indexed_Comp
:= False;
444 when N_Indexed_Component
=>
449 Enable_If_Packed_Array
(Prefix
(Ren
));
451 X
:= Last
(Expressions
(Ren
));
452 while Present
(X
) loop
453 if not Output_Subscript
(X
, "XS") then
454 Set_Materialize_Entity
(Ent
);
459 Last_Is_Indexed_Comp
:= True;
467 -- Assuming X is an array:
473 -- GDB cannot handle packed array slices, so avoid describing
474 -- the slice if we can avoid it.
476 if not Last_Is_Indexed_Comp
then
477 Enable_If_Packed_Array
(Prefix
(Ren
));
478 Typ
:= Etype
(First_Index
(Etype
(Ren
)));
480 if not Output_Subscript
(Type_High_Bound
(Typ
), "XS") then
481 Set_Materialize_Entity
(Ent
);
485 if not Output_Subscript
(Type_Low_Bound
(Typ
), "XL") then
486 Set_Materialize_Entity
(Ent
);
490 Last_Is_Indexed_Comp
:= False;
495 when N_Explicit_Dereference
=>
496 Prepend_String_To_Buffer
("XA");
498 Last_Is_Indexed_Comp
:= False;
500 -- For now, anything else simply results in no translation
503 Set_Materialize_Entity
(Ent
);
508 -- If we found no reason here to emit an encoding, stop now
511 Set_Materialize_Entity
(Ent
);
515 Prepend_String_To_Buffer
("___XE");
517 -- Include the designation of the form of renaming
520 when N_Object_Renaming_Declaration
=>
521 Prepend_String_To_Buffer
("___XR");
523 when N_Exception_Renaming_Declaration
=>
524 Prepend_String_To_Buffer
("___XRE");
526 when N_Package_Renaming_Declaration
=>
527 Prepend_String_To_Buffer
("___XRP");
533 -- Add the name of the renaming entity to the front
535 Prepend_String_To_Buffer
(Get_Name_String
(Chars
(Ent
)));
537 -- If it is a child unit create a fully qualified name, to disambiguate
538 -- multiple child units with the same name and different parents.
540 if Nkind
(N
) = N_Package_Renaming_Declaration
541 and then Is_Child_Unit
(Ent
)
543 Prepend_String_To_Buffer
("__");
544 Prepend_String_To_Buffer
545 (Get_Name_String
(Chars
(Scope
(Ent
))));
548 -- Create the special object whose name is the debug encoding for the
549 -- renaming declaration.
551 -- For now, the object name contains the suffix encoding for the renamed
552 -- object, but not the name of the leading entity. The object is linked
553 -- the renamed entity using the Debug_Renaming_Link field. Then the
554 -- Qualify_Entity_Name procedure uses this link to create the proper
555 -- fully qualified name.
557 -- The reason we do things this way is that we really need to copy the
558 -- qualification of the renamed entity, and it is really much easier to
559 -- do this after the renamed entity has itself been fully qualified.
561 Obj
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Enter
);
563 Make_Object_Declaration
(Loc
,
564 Defining_Identifier
=> Obj
,
565 Object_Definition
=> New_Occurrence_Of
566 (Standard_Debug_Renaming_Type
, Loc
));
568 Set_Debug_Renaming_Link
(Obj
, Entity
(Ren
));
570 Set_Debug_Info_Needed
(Obj
);
572 -- The renamed entity may be a temporary, e.g. the result of an
573 -- implicit dereference in an iterator. Indicate that the temporary
574 -- itself requires debug information. If the renamed entity comes
575 -- from source this is a no-op.
577 Set_Debug_Info_Needed
(Entity
(Ren
));
579 -- Mark the object as internal so that it won't be initialized when
580 -- pragma Initialize_Scalars or Normalize_Scalars is in use.
582 Set_Is_Internal
(Obj
);
586 -- If we get an exception, just figure it is a case that we cannot
587 -- successfully handle using our current approach, since this is
588 -- only for debugging, no need to take the compilation with us.
592 return Make_Null_Statement
(Loc
);
593 end Debug_Renaming_Declaration
;
595 -----------------------------
596 -- Is_Handled_Scale_Factor --
597 -----------------------------
599 function Is_Handled_Scale_Factor
(U
: Ureal
) return Boolean is
601 -- Keep in sync with gigi (see E_*_Fixed_Point_Type handling in
602 -- decl.c:gnat_to_gnu_entity).
604 if UI_Eq
(Numerator
(U
), Uint_1
) then
605 if Rbase
(U
) = 2 or else Rbase
(U
) = 10 then
611 (UI_Is_In_Int_Range
(Norm_Num
(U
))
613 UI_Is_In_Int_Range
(Norm_Den
(U
)));
614 end Is_Handled_Scale_Factor
;
616 ----------------------
617 -- Get_Encoded_Name --
618 ----------------------
620 -- Note: see spec for details on encodings
622 procedure Get_Encoded_Name
(E
: Entity_Id
) is
623 Has_Suffix
: Boolean;
626 -- If not generating code, there is no need to create encoded names, and
627 -- problems when the back-end is called to annotate types without full
628 -- code generation. See comments in Get_External_Name for additional
631 -- However we do create encoded names if the back end is active, even
632 -- if Operating_Mode got reset. Otherwise any serious error reported
633 -- by the backend calling Error_Msg changes the Compilation_Mode to
634 -- Check_Semantics, which disables the functionality of this routine,
635 -- causing the generation of spurious additional errors.
637 -- Couldn't we just test Original_Operating_Mode here? ???
639 if Operating_Mode
/= Generate_Code
and then not Generating_Code
then
643 Get_Name_String
(Chars
(E
));
645 -- Nothing to do if we do not have a type
649 -- Or if this is an enumeration base type
651 or else (Is_Enumeration_Type
(E
) and then Is_Base_Type
(E
))
653 -- Or if this is a dummy type for a renaming
655 or else (Name_Len
>= 3 and then
656 Name_Buffer
(Name_Len
- 2 .. Name_Len
) = "_XR")
658 or else (Name_Len
>= 4 and then
659 (Name_Buffer
(Name_Len
- 3 .. Name_Len
) = "_XRE"
661 Name_Buffer
(Name_Len
- 3 .. Name_Len
) = "_XRP"))
663 -- For all these cases, just return the name unchanged
666 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
672 -- Fixed-point case: generate GNAT encodings when asked to or when we
673 -- know the back-end will not be able to handle the scale factor.
675 if Is_Fixed_Point_Type
(E
)
676 and then (GNAT_Encodings
/= DWARF_GNAT_Encodings_Minimal
677 or else not Is_Handled_Scale_Factor
(Small_Value
(E
)))
679 Get_External_Name
(E
, True, "XF_");
680 Add_Real_To_Buffer
(Delta_Value
(E
));
682 if Small_Value
(E
) /= Delta_Value
(E
) then
683 Add_Str_To_Name_Buffer
("_");
684 Add_Real_To_Buffer
(Small_Value
(E
));
687 -- Discrete case where bounds do not match size. Not necessary if we can
688 -- emit standard DWARF.
690 elsif GNAT_Encodings
/= DWARF_GNAT_Encodings_Minimal
691 and then Is_Discrete_Type
(E
)
692 and then not Bounds_Match_Size
(E
)
695 Lo
: constant Node_Id
:= Type_Low_Bound
(E
);
696 Hi
: constant Node_Id
:= Type_High_Bound
(E
);
698 Lo_Con
: constant Boolean := Compile_Time_Known_Value
(Lo
);
699 Hi_Con
: constant Boolean := Compile_Time_Known_Value
(Hi
);
701 Lo_Discr
: constant Boolean :=
702 Nkind
(Lo
) = N_Identifier
703 and then Ekind
(Entity
(Lo
)) = E_Discriminant
;
705 Hi_Discr
: constant Boolean :=
706 Nkind
(Hi
) = N_Identifier
707 and then Ekind
(Entity
(Hi
)) = E_Discriminant
;
709 Lo_Encode
: constant Boolean := Lo_Con
or Lo_Discr
;
710 Hi_Encode
: constant Boolean := Hi_Con
or Hi_Discr
;
712 Biased
: constant Boolean := Has_Biased_Representation
(E
);
716 Get_External_Name
(E
, True, "XB");
718 Get_External_Name
(E
, True, "XD");
721 if Lo_Encode
or Hi_Encode
then
723 Add_Str_To_Name_Buffer
("_");
727 Add_Str_To_Name_Buffer
("LU_");
729 Add_Str_To_Name_Buffer
("L_");
732 Add_Str_To_Name_Buffer
("U_");
737 Add_Uint_To_Buffer
(Expr_Rep_Value
(Lo
));
739 Get_Name_String_And_Append
(Chars
(Entity
(Lo
)));
742 if Lo_Encode
and Hi_Encode
then
743 Add_Str_To_Name_Buffer
("__");
747 Add_Uint_To_Buffer
(Expr_Rep_Value
(Hi
));
749 Get_Name_String_And_Append
(Chars
(Entity
(Hi
)));
754 -- For all other cases, the encoded name is the normal type name
758 Get_External_Name
(E
);
761 if Debug_Flag_B
and then Has_Suffix
then
762 Write_Str
("**** type ");
763 Write_Name
(Chars
(E
));
764 Write_Str
(" is encoded as ");
765 Write_Str
(Name_Buffer
(1 .. Name_Len
));
769 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
770 end Get_Encoded_Name
;
772 -----------------------
773 -- Get_External_Name --
774 -----------------------
776 procedure Get_External_Name
778 Has_Suffix
: Boolean := False;
779 Suffix
: String := "")
781 procedure Get_Qualified_Name_And_Append
(Entity
: Entity_Id
);
782 -- Appends fully qualified name of given entity to Name_Buffer
784 -----------------------------------
785 -- Get_Qualified_Name_And_Append --
786 -----------------------------------
788 procedure Get_Qualified_Name_And_Append
(Entity
: Entity_Id
) is
790 -- If the entity is a compilation unit, its scope is Standard,
791 -- there is no outer scope, and the no further qualification
794 -- If the front end has already computed a fully qualified name,
795 -- then it is also the case that no further qualification is
798 if Present
(Scope
(Scope
(Entity
)))
799 and then not Has_Fully_Qualified_Name
(Entity
)
801 Get_Qualified_Name_And_Append
(Scope
(Entity
));
802 Add_Str_To_Name_Buffer
("__");
803 Get_Name_String_And_Append
(Chars
(Entity
));
804 Append_Homonym_Number
(Entity
);
807 Get_Name_String_And_Append
(Chars
(Entity
));
809 end Get_Qualified_Name_And_Append
;
813 E
: Entity_Id
:= Entity
;
815 -- Start of processing for Get_External_Name
818 -- If we are not in code generation mode, this procedure may still be
819 -- called from Back_End (more specifically - from gigi for doing type
820 -- representation annotation or some representation-specific checks).
821 -- But in this mode there is no need to mess with external names.
823 -- Furthermore, the call causes difficulties in this case because the
824 -- string representing the homonym number is not correctly reset as a
825 -- part of the call to Output_Homonym_Numbers_Suffix (which is not
828 if Operating_Mode
/= Generate_Code
then
834 -- If this is a child unit, we want the child
836 if Nkind
(E
) = N_Defining_Program_Unit_Name
then
837 E
:= Defining_Identifier
(Entity
);
840 -- Case of interface name being used
842 if Ekind_In
(E
, E_Constant
,
847 and then Present
(Interface_Name
(E
))
848 and then No
(Address_Clause
(E
))
849 and then not Has_Suffix
851 Append
(Global_Name_Buffer
, Strval
(Interface_Name
(E
)));
853 -- All other cases besides the interface name case
856 -- If this is a library level subprogram (i.e. a subprogram that is a
857 -- compilation unit other than a subunit), then we prepend _ada_ to
858 -- ensure distinctions required as described in the spec.
860 -- Check explicitly for child units, because those are not flagged
861 -- as Compilation_Units by lib. Should they be ???
864 and then (Is_Compilation_Unit
(E
) or Is_Child_Unit
(E
))
865 and then not Has_Suffix
867 Add_Str_To_Name_Buffer
("_ada_");
870 -- If the entity is a subprogram instance that is not a compilation
871 -- unit, generate the name of the original Ada entity, which is the
874 if Is_Generic_Instance
(E
)
875 and then Is_Subprogram
(E
)
876 and then not Is_Compilation_Unit
(Scope
(E
))
877 and then Ekind_In
(Scope
(E
), E_Package
, E_Package_Body
)
878 and then Present
(Related_Instance
(Scope
(E
)))
880 E
:= Related_Instance
(Scope
(E
));
883 Get_Qualified_Name_And_Append
(E
);
887 Add_Str_To_Name_Buffer
("___");
888 Add_Str_To_Name_Buffer
(Suffix
);
891 -- Add a special prefix to distinguish Ghost entities. In Ignored Ghost
892 -- mode, these entities should not leak in the "living" space and they
893 -- should be removed by the compiler in a post-processing pass. Thus,
894 -- the prefix allows anyone to check that the final executable indeed
895 -- does not contain such entities, in such a case. Do not insert this
896 -- prefix for compilation units, whose name is used as a basis for the
897 -- name of the generated elaboration procedure and (when appropriate)
898 -- the executable produced. Only insert this prefix once, for Ghost
899 -- entities declared inside other Ghost entities. Three leading
900 -- underscores are used so that "___ghost_" is a unique substring of
901 -- names produced for Ghost entities, while "__ghost_" can appear in
902 -- names of entities inside a child/local package called "Ghost".
904 -- The compiler-generated finalizer for an enabled Ghost unit is treated
905 -- specially, as its name must be known to the binder, which has no
906 -- knowledge of Ghost status. In that case, the finalizer is not marked
907 -- as Ghost so that no prefix is added. Note that the special ___ghost_
908 -- prefix is retained when the Ghost unit is ignored, which still allows
909 -- inspecting the final executable for the presence of an ignored Ghost
910 -- finalizer procedure.
912 if Is_Ghost_Entity
(E
)
913 and then not Is_Compilation_Unit
(E
)
914 and then (Name_Len
< 9
915 or else Name_Buffer
(1 .. 9) /= "___ghost_")
917 Insert_Str_In_Name_Buffer
("___ghost_", 1);
920 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
921 end Get_External_Name
;
923 --------------------------
924 -- Get_Variant_Encoding --
925 --------------------------
927 procedure Get_Variant_Encoding
(V
: Node_Id
) is
930 procedure Choice_Val
(Typ
: Character; Choice
: Node_Id
);
931 -- Output encoded value for a single choice value. Typ is the key
932 -- character ('S', 'F', or 'T') that precedes the choice value.
938 procedure Choice_Val
(Typ
: Character; Choice
: Node_Id
) is
940 if Nkind
(Choice
) = N_Integer_Literal
then
941 Add_Char_To_Name_Buffer
(Typ
);
942 Add_Uint_To_Buffer
(Intval
(Choice
));
944 -- Character literal with no entity present (this is the case
945 -- Standard.Character or Standard.Wide_Character as root type)
947 elsif Nkind
(Choice
) = N_Character_Literal
948 and then No
(Entity
(Choice
))
950 Add_Char_To_Name_Buffer
(Typ
);
951 Add_Uint_To_Buffer
(Char_Literal_Value
(Choice
));
955 Ent
: constant Entity_Id
:= Entity
(Choice
);
958 if Ekind
(Ent
) = E_Enumeration_Literal
then
959 Add_Char_To_Name_Buffer
(Typ
);
960 Add_Uint_To_Buffer
(Enumeration_Rep
(Ent
));
963 pragma Assert
(Ekind
(Ent
) = E_Constant
);
964 Choice_Val
(Typ
, Constant_Value
(Ent
));
970 -- Start of processing for Get_Variant_Encoding
975 Choice
:= First
(Discrete_Choices
(V
));
976 while Present
(Choice
) loop
977 if Nkind
(Choice
) = N_Others_Choice
then
978 Add_Char_To_Name_Buffer
('O');
980 elsif Nkind
(Choice
) = N_Range
then
981 Choice_Val
('R', Low_Bound
(Choice
));
982 Choice_Val
('T', High_Bound
(Choice
));
984 elsif Is_Entity_Name
(Choice
)
985 and then Is_Type
(Entity
(Choice
))
987 Choice_Val
('R', Type_Low_Bound
(Entity
(Choice
)));
988 Choice_Val
('T', Type_High_Bound
(Entity
(Choice
)));
990 elsif Nkind
(Choice
) = N_Subtype_Indication
then
992 Rang
: constant Node_Id
:=
993 Range_Expression
(Constraint
(Choice
));
995 Choice_Val
('R', Low_Bound
(Rang
));
996 Choice_Val
('T', High_Bound
(Rang
));
1000 Choice_Val
('S', Choice
);
1006 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
1008 if Debug_Flag_B
then
1010 VP
: constant Node_Id
:= Parent
(V
); -- Variant_Part
1011 CL
: constant Node_Id
:= Parent
(VP
); -- Component_List
1012 RD
: constant Node_Id
:= Parent
(CL
); -- Record_Definition
1013 FT
: constant Node_Id
:= Parent
(RD
); -- Full_Type_Declaration
1016 Write_Str
("**** variant for type ");
1017 Write_Name
(Chars
(Defining_Identifier
(FT
)));
1018 Write_Str
(" is encoded as ");
1019 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1023 end Get_Variant_Encoding
;
1025 -----------------------------------------
1026 -- Build_Subprogram_Instance_Renamings --
1027 -----------------------------------------
1029 procedure Build_Subprogram_Instance_Renamings
1031 Wrapper
: Entity_Id
)
1038 E
:= First_Entity
(Wrapper
);
1039 while Present
(E
) loop
1040 if Nkind
(Parent
(E
)) = N_Object_Declaration
1041 and then Is_Elementary_Type
(Etype
(E
))
1043 Loc
:= Sloc
(Expression
(Parent
(E
)));
1044 Decl
:= Make_Object_Renaming_Declaration
(Loc
,
1045 Defining_Identifier
=>
1046 Make_Defining_Identifier
(Loc
, Chars
(E
)),
1047 Subtype_Mark
=> New_Occurrence_Of
(Etype
(E
), Loc
),
1048 Name
=> New_Occurrence_Of
(E
, Loc
));
1050 Append
(Decl
, Declarations
(N
));
1051 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
1056 end Build_Subprogram_Instance_Renamings
;
1058 ------------------------------------
1059 -- Get_Secondary_DT_External_Name --
1060 ------------------------------------
1062 procedure Get_Secondary_DT_External_Name
1064 Ancestor_Typ
: Entity_Id
;
1068 Get_External_Name
(Typ
);
1070 if Ancestor_Typ
/= Typ
then
1072 Len
: constant Natural := Name_Len
;
1073 Save_Str
: constant String (1 .. Name_Len
)
1074 := Name_Buffer
(1 .. Name_Len
);
1076 Get_External_Name
(Ancestor_Typ
);
1078 -- Append the extended name of the ancestor to the
1079 -- extended name of Typ
1081 Name_Buffer
(Len
+ 2 .. Len
+ Name_Len
+ 1) :=
1082 Name_Buffer
(1 .. Name_Len
);
1083 Name_Buffer
(1 .. Len
) := Save_Str
;
1084 Name_Buffer
(Len
+ 1) := '_';
1085 Name_Len
:= Len
+ Name_Len
+ 1;
1089 Add_Nat_To_Name_Buffer
(Suffix_Index
);
1090 end Get_Secondary_DT_External_Name
;
1092 ---------------------------------
1093 -- Make_Packed_Array_Impl_Type_Name --
1094 ---------------------------------
1096 function Make_Packed_Array_Impl_Type_Name
1102 Get_Name_String
(Chars
(Typ
));
1103 Add_Str_To_Name_Buffer
("___XP");
1104 Add_Uint_To_Buffer
(Csize
);
1106 end Make_Packed_Array_Impl_Type_Name
;
1108 -----------------------------------
1109 -- Output_Homonym_Numbers_Suffix --
1110 -----------------------------------
1112 procedure Output_Homonym_Numbers_Suffix
is
1116 if Homonym_Len
> 0 then
1118 -- Check for all 1's, in which case we do not output
1122 exit when Homonym_Numbers
(J
) /= '1';
1124 -- If we reached end of string we do not output
1126 if J
= Homonym_Len
then
1131 exit when Homonym_Numbers
(J
+ 1) /= '_';
1135 -- If we exit the loop then suffix must be output
1137 Add_Str_To_Name_Buffer
("__");
1138 Add_Str_To_Name_Buffer
(Homonym_Numbers
(1 .. Homonym_Len
));
1141 end Output_Homonym_Numbers_Suffix
;
1143 ------------------------------
1144 -- Prepend_String_To_Buffer --
1145 ------------------------------
1147 procedure Prepend_String_To_Buffer
(S
: String) is
1148 N
: constant Integer := S
'Length;
1150 Name_Buffer
(1 + N
.. Name_Len
+ N
) := Name_Buffer
(1 .. Name_Len
);
1151 Name_Buffer
(1 .. N
) := S
;
1152 Name_Len
:= Name_Len
+ N
;
1153 end Prepend_String_To_Buffer
;
1155 ----------------------------
1156 -- Prepend_Uint_To_Buffer --
1157 ----------------------------
1159 procedure Prepend_Uint_To_Buffer
(U
: Uint
) is
1162 Prepend_String_To_Buffer
("m");
1163 Prepend_Uint_To_Buffer
(-U
);
1165 UI_Image
(U
, Decimal
);
1166 Prepend_String_To_Buffer
(UI_Image_Buffer
(1 .. UI_Image_Length
));
1168 end Prepend_Uint_To_Buffer
;
1170 ------------------------------
1171 -- Qualify_All_Entity_Names --
1172 ------------------------------
1174 procedure Qualify_All_Entity_Names
is
1180 for J
in Name_Qualify_Units
.First
.. Name_Qualify_Units
.Last
loop
1181 Nod
:= Name_Qualify_Units
.Table
(J
);
1183 -- When a scoping construct is ignored Ghost, it is rewritten as
1184 -- a null statement. Skip such constructs as they no longer carry
1187 if Nkind
(Nod
) = N_Null_Statement
then
1191 E
:= Defining_Entity
(Nod
);
1193 Qualify_Entity_Name
(E
);
1195 -- Normally entities in the qualification list are scopes, but in the
1196 -- case of a library-level package renaming there is an associated
1197 -- variable that encodes the debugger name and that variable is
1198 -- entered in the list since it occurs in the Aux_Decls list of the
1199 -- compilation and doesn't have a normal scope.
1201 if Ekind
(E
) /= E_Variable
then
1202 Ent
:= First_Entity
(E
);
1203 while Present
(Ent
) loop
1205 Qualify_Entity_Name
(Ent
);
1208 -- There are odd cases where Last_Entity (E) = E. This happens
1209 -- in the case of renaming of packages. This test avoids
1210 -- getting stuck in such cases.
1219 end Qualify_All_Entity_Names
;
1221 -------------------------
1222 -- Qualify_Entity_Name --
1223 -------------------------
1225 procedure Qualify_Entity_Name
(Ent
: Entity_Id
) is
1227 Full_Qualify_Name
: String (1 .. Name_Buffer
'Length);
1228 Full_Qualify_Len
: Natural := 0;
1229 -- Used to accumulate fully qualified name of subprogram
1231 procedure Fully_Qualify_Name
(E
: Entity_Id
);
1232 -- Used to qualify a subprogram or type name, where full
1233 -- qualification up to Standard is always used. Name is set
1234 -- in Full_Qualify_Name with the length in Full_Qualify_Len.
1235 -- Note that this routine does not prepend the _ada_ string
1236 -- required for library subprograms (this is done in the back end).
1238 function Is_BNPE
(S
: Entity_Id
) return Boolean;
1239 -- Determines if S is a BNPE, i.e. Body-Nested Package Entity, which
1240 -- is defined to be a package which is immediately nested within a
1243 function Qualify_Needed
(S
: Entity_Id
) return Boolean;
1244 -- Given a scope, determines if the scope is to be included in the
1245 -- fully qualified name, True if so, False if not. Blocks and loops
1246 -- are excluded from a qualified name.
1248 procedure Set_BNPE_Suffix
(E
: Entity_Id
);
1249 -- Recursive routine to append the BNPE qualification suffix. Works
1250 -- from right to left with E being the current entity in the list.
1251 -- The result does NOT have the trailing n's and trailing b stripped.
1252 -- The caller must do this required stripping.
1254 procedure Set_Entity_Name
(E
: Entity_Id
);
1255 -- Internal recursive routine that does most of the work. This routine
1256 -- leaves the result sitting in Name_Buffer and Name_Len.
1258 BNPE_Suffix_Needed
: Boolean := False;
1259 -- Set true if a body-nested package entity suffix is required
1261 Save_Chars
: constant Name_Id
:= Chars
(Ent
);
1262 -- Save original name
1264 ------------------------
1265 -- Fully_Qualify_Name --
1266 ------------------------
1268 procedure Fully_Qualify_Name
(E
: Entity_Id
) is
1269 Discard
: Boolean := False;
1272 -- Ignore empty entry (can happen in error cases)
1277 -- If this we are qualifying entities local to a generic instance,
1278 -- use the name of the original instantiation, not that of the
1279 -- anonymous subprogram in the wrapper package, so that gdb doesn't
1280 -- have to know about these.
1282 elsif Is_Generic_Instance
(E
)
1283 and then Is_Subprogram
(E
)
1284 and then not Comes_From_Source
(E
)
1285 and then not Is_Compilation_Unit
(Scope
(E
))
1287 Fully_Qualify_Name
(Related_Instance
(Scope
(E
)));
1291 -- If we reached fully qualified name, then just copy it
1293 if Has_Fully_Qualified_Name
(E
) then
1294 Get_Name_String
(Chars
(E
));
1295 Strip_Suffixes
(Discard
);
1296 Full_Qualify_Name
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
1297 Full_Qualify_Len
:= Name_Len
;
1298 Set_Has_Fully_Qualified_Name
(Ent
);
1300 -- Case of non-fully qualified name
1303 if Scope
(E
) = Standard_Standard
then
1304 Set_Has_Fully_Qualified_Name
(Ent
);
1306 Fully_Qualify_Name
(Scope
(E
));
1307 Full_Qualify_Name
(Full_Qualify_Len
+ 1) := '_';
1308 Full_Qualify_Name
(Full_Qualify_Len
+ 2) := '_';
1309 Full_Qualify_Len
:= Full_Qualify_Len
+ 2;
1312 if Has_Qualified_Name
(E
) then
1313 Get_Unqualified_Name_String
(Chars
(E
));
1315 Get_Name_String
(Chars
(E
));
1318 -- Here we do one step of the qualification
1321 (Full_Qualify_Len
+ 1 .. Full_Qualify_Len
+ Name_Len
) :=
1322 Name_Buffer
(1 .. Name_Len
);
1323 Full_Qualify_Len
:= Full_Qualify_Len
+ Name_Len
;
1324 Append_Homonym_Number
(E
);
1328 BNPE_Suffix_Needed
:= True;
1330 end Fully_Qualify_Name
;
1336 function Is_BNPE
(S
: Entity_Id
) return Boolean is
1338 return Ekind
(S
) = E_Package
and then Is_Package_Body_Entity
(S
);
1341 --------------------
1342 -- Qualify_Needed --
1343 --------------------
1345 function Qualify_Needed
(S
: Entity_Id
) return Boolean is
1347 -- If we got all the way to Standard, then we have certainly
1348 -- fully qualified the name, so set the flag appropriately,
1349 -- and then return False, since we are most certainly done.
1351 if S
= Standard_Standard
then
1352 Set_Has_Fully_Qualified_Name
(Ent
, True);
1355 -- Otherwise figure out if further qualification is required
1358 return Is_Subprogram
(Ent
)
1359 or else Ekind
(Ent
) = E_Subprogram_Body
1360 or else (Ekind
(S
) /= E_Block
1361 and then Ekind
(S
) /= E_Loop
1362 and then not Is_Dynamic_Scope
(S
));
1366 ---------------------
1367 -- Set_BNPE_Suffix --
1368 ---------------------
1370 procedure Set_BNPE_Suffix
(E
: Entity_Id
) is
1371 S
: constant Entity_Id
:= Scope
(E
);
1374 if Qualify_Needed
(S
) then
1375 Set_BNPE_Suffix
(S
);
1378 Add_Char_To_Name_Buffer
('b');
1380 Add_Char_To_Name_Buffer
('n');
1384 Add_Char_To_Name_Buffer
('X');
1386 end Set_BNPE_Suffix
;
1388 ---------------------
1389 -- Set_Entity_Name --
1390 ---------------------
1392 procedure Set_Entity_Name
(E
: Entity_Id
) is
1393 S
: constant Entity_Id
:= Scope
(E
);
1396 -- If we reach an already qualified name, just take the encoding
1397 -- except that we strip the package body suffixes, since these
1398 -- will be separately put on later.
1400 if Has_Qualified_Name
(E
) then
1401 Get_Name_String_And_Append
(Chars
(E
));
1402 Strip_Suffixes
(BNPE_Suffix_Needed
);
1404 -- If the top level name we are adding is itself fully
1405 -- qualified, then that means that the name that we are
1406 -- preparing for the Fully_Qualify_Name call will also
1407 -- generate a fully qualified name.
1409 if Has_Fully_Qualified_Name
(E
) then
1410 Set_Has_Fully_Qualified_Name
(Ent
);
1413 -- Case where upper level name is not encoded yet
1416 -- Recurse if further qualification required
1418 if Qualify_Needed
(S
) then
1419 Set_Entity_Name
(S
);
1420 Add_Str_To_Name_Buffer
("__");
1423 -- Otherwise get name and note if it is a BNPE
1425 Get_Name_String_And_Append
(Chars
(E
));
1428 BNPE_Suffix_Needed
:= True;
1431 Append_Homonym_Number
(E
);
1433 end Set_Entity_Name
;
1435 -- Start of processing for Qualify_Entity_Name
1438 if Has_Qualified_Name
(Ent
) then
1441 -- If the entity is a variable encoding the debug name for an object
1442 -- renaming, then the qualified name of the entity associated with the
1443 -- renamed object can now be incorporated in the debug name.
1445 elsif Ekind
(Ent
) = E_Variable
1446 and then Present
(Debug_Renaming_Link
(Ent
))
1449 Qualify_Entity_Name
(Debug_Renaming_Link
(Ent
));
1450 Get_Name_String
(Chars
(Ent
));
1452 -- Retrieve the now-qualified name of the renamed entity and insert
1453 -- it in the middle of the name, just preceding the suffix encoding
1454 -- describing the renamed object.
1457 Renamed_Id
: constant String :=
1458 Get_Name_String
(Chars
(Debug_Renaming_Link
(Ent
)));
1459 Insert_Len
: constant Integer := Renamed_Id
'Length + 1;
1460 Index
: Natural := Name_Len
- 3;
1463 -- Loop backwards through the name to find the start of the "___"
1464 -- sequence associated with the suffix.
1466 while Index
>= Name_Buffer
'First
1467 and then (Name_Buffer
(Index
+ 1) /= '_'
1468 or else Name_Buffer
(Index
+ 2) /= '_'
1469 or else Name_Buffer
(Index
+ 3) /= '_')
1474 pragma Assert
(Name_Buffer
(Index
+ 1 .. Index
+ 3) = "___");
1476 -- Insert an underscore separator and the entity name just in
1477 -- front of the suffix.
1479 Name_Buffer
(Index
+ 1 + Insert_Len
.. Name_Len
+ Insert_Len
) :=
1480 Name_Buffer
(Index
+ 1 .. Name_Len
);
1481 Name_Buffer
(Index
+ 1) := '_';
1482 Name_Buffer
(Index
+ 2 .. Index
+ Insert_Len
) := Renamed_Id
;
1483 Name_Len
:= Name_Len
+ Insert_Len
;
1486 -- Reset the name of the variable to the new name that includes the
1487 -- name of the renamed entity.
1489 Set_Chars
(Ent
, Name_Enter
);
1491 -- If the entity needs qualification by its scope then develop it
1492 -- here, add the variable's name, and again reset the entity name.
1494 if Qualify_Needed
(Scope
(Ent
)) then
1496 Set_Entity_Name
(Scope
(Ent
));
1497 Add_Str_To_Name_Buffer
("__");
1499 Get_Name_String_And_Append
(Chars
(Ent
));
1501 Set_Chars
(Ent
, Name_Enter
);
1504 Set_Has_Qualified_Name
(Ent
);
1507 elsif Is_Subprogram
(Ent
)
1508 or else Ekind
(Ent
) = E_Subprogram_Body
1509 or else Is_Type
(Ent
)
1510 or else Ekind
(Ent
) = E_Exception
1512 Fully_Qualify_Name
(Ent
);
1513 Name_Len
:= Full_Qualify_Len
;
1514 Name_Buffer
(1 .. Name_Len
) := Full_Qualify_Name
(1 .. Name_Len
);
1516 -- Qualification needed for enumeration literals when generating C code
1517 -- (to simplify their management in the backend).
1519 elsif Modify_Tree_For_C
1520 and then Ekind
(Ent
) = E_Enumeration_Literal
1521 and then Scope
(Ultimate_Alias
(Ent
)) /= Standard_Standard
1523 Fully_Qualify_Name
(Ent
);
1524 Name_Len
:= Full_Qualify_Len
;
1525 Name_Buffer
(1 .. Name_Len
) := Full_Qualify_Name
(1 .. Name_Len
);
1527 elsif Qualify_Needed
(Scope
(Ent
)) then
1529 Set_Entity_Name
(Ent
);
1532 Set_Has_Qualified_Name
(Ent
);
1534 -- If a variable is hidden by a subsequent loop variable, qualify
1535 -- the name of that loop variable to prevent visibility issues when
1536 -- translating to C. Note that gdb probably never handled properly
1537 -- this accidental hiding, given that loops are not scopes at
1538 -- runtime. We also qualify a name if it hides an outer homonym,
1539 -- and both are declared in blocks.
1541 if Modify_Tree_For_C
and then Ekind
(Ent
) = E_Variable
then
1542 if Present
(Hiding_Loop_Variable
(Ent
)) then
1544 Var
: constant Entity_Id
:= Hiding_Loop_Variable
(Ent
);
1547 Set_Entity_Name
(Var
);
1548 Add_Str_To_Name_Buffer
("L");
1549 Set_Chars
(Var
, Name_Enter
);
1552 elsif Present
(Homonym
(Ent
))
1553 and then Ekind
(Scope
(Ent
)) = E_Block
1554 and then Ekind
(Scope
(Homonym
(Ent
))) = E_Block
1556 Set_Entity_Name
(Ent
);
1557 Add_Str_To_Name_Buffer
("B");
1558 Set_Chars
(Ent
, Name_Enter
);
1565 -- Fall through with a fully qualified name in Name_Buffer/Name_Len
1567 Output_Homonym_Numbers_Suffix
;
1569 -- Add body-nested package suffix if required
1571 if BNPE_Suffix_Needed
1572 and then Ekind
(Ent
) /= E_Enumeration_Literal
1574 Set_BNPE_Suffix
(Ent
);
1576 -- Strip trailing n's and last trailing b as required. note that
1577 -- we know there is at least one b, or no suffix would be generated.
1579 while Name_Buffer
(Name_Len
) = 'n' loop
1580 Name_Len
:= Name_Len
- 1;
1583 Name_Len
:= Name_Len
- 1;
1586 Set_Chars
(Ent
, Name_Enter
);
1587 Set_Has_Qualified_Name
(Ent
);
1589 if Debug_Flag_BB
then
1591 Write_Name
(Save_Chars
);
1592 Write_Str
(" qualified as ");
1593 Write_Name
(Chars
(Ent
));
1596 end Qualify_Entity_Name
;
1598 --------------------------
1599 -- Qualify_Entity_Names --
1600 --------------------------
1602 procedure Qualify_Entity_Names
(N
: Node_Id
) is
1604 Name_Qualify_Units
.Append
(N
);
1605 end Qualify_Entity_Names
;
1611 procedure Reset_Buffers
is
1617 --------------------
1618 -- Strip_Suffixes --
1619 --------------------
1621 procedure Strip_Suffixes
(BNPE_Suffix_Found
: in out Boolean) is
1624 pragma Warnings
(Off
, BNPE_Suffix_Found
);
1625 -- Since this procedure only ever sets the flag
1628 -- Search for and strip BNPE suffix
1630 for J
in reverse 2 .. Name_Len
loop
1631 if Name_Buffer
(J
) = 'X' then
1633 BNPE_Suffix_Found
:= True;
1637 exit when Name_Buffer
(J
) /= 'b' and then Name_Buffer
(J
) /= 'n';
1640 -- Search for and strip homonym numbers suffix
1642 for J
in reverse 2 .. Name_Len
- 2 loop
1643 if Name_Buffer
(J
) = '_'
1644 and then Name_Buffer
(J
+ 1) = '_'
1646 if Name_Buffer
(J
+ 2) in '0' .. '9' then
1647 if Homonym_Len
> 0 then
1648 Homonym_Len
:= Homonym_Len
+ 1;
1649 Homonym_Numbers
(Homonym_Len
) := '-';
1652 SL
:= Name_Len
- (J
+ 1);
1654 Homonym_Numbers
(Homonym_Len
+ 1 .. Homonym_Len
+ SL
) :=
1655 Name_Buffer
(J
+ 2 .. Name_Len
);
1657 Homonym_Len
:= Homonym_Len
+ SL
;