1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1996-2005 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Alloc
; use Alloc
;
28 with Atree
; use Atree
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Namet
; use Namet
;
32 with Nlists
; use Nlists
;
33 with Nmake
; use Nmake
;
35 with Output
; use Output
;
36 with Sem_Eval
; use Sem_Eval
;
37 with Sem_Util
; use Sem_Util
;
38 with Sinfo
; use Sinfo
;
39 with Snames
; use Snames
;
40 with Stand
; use Stand
;
41 with Stringt
; use Stringt
;
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
109 -- gather the homonym string that will be appended to Name_Buffer
110 -- when the name is complete. Strip_Suffixes appends to this string
111 -- as does Append_Homonym_Number, and Output_Homonym_Numbers_Suffix
112 -- appends the 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 procedure Output_Homonym_Numbers_Suffix
;
137 -- If homonym numbers are stored, then output them into Name_Buffer.
139 procedure Prepend_String_To_Buffer
(S
: String);
140 -- Prepend given string to the contents of the string buffer, updating
141 -- the value in Name_Len (i.e. string is added at start of buffer).
143 procedure Prepend_Uint_To_Buffer
(U
: Uint
);
144 -- Prepend image of universal integer to Name_Buffer, updating Name_Len
146 procedure Qualify_Entity_Name
(Ent
: Entity_Id
);
147 -- If not already done, replaces the Chars field of the given entity
148 -- with the appropriate fully qualified name.
150 procedure Strip_Suffixes
(BNPE_Suffix_Found
: in out Boolean);
151 -- Given an qualified entity name in Name_Buffer, remove any plain X or
152 -- X{nb} qualification suffix. The contents of Name_Buffer is not changed
153 -- but Name_Len may be adjusted on return to remove the suffix. If a
154 -- BNPE suffix is found and stripped, then BNPE_Suffix_Found is set to
155 -- True. If no suffix is found, then BNPE_Suffix_Found is not modified.
156 -- This routine also searches for a homonym suffix, and if one is found
157 -- it is also stripped, and the entries are added to the global homonym
158 -- list (Homonym_Numbers) so that they can later be put back.
160 ------------------------
161 -- Add_Real_To_Buffer --
162 ------------------------
164 procedure Add_Real_To_Buffer
(U
: Ureal
) is
166 Add_Uint_To_Buffer
(Norm_Num
(U
));
167 Add_Str_To_Name_Buffer
("_");
168 Add_Uint_To_Buffer
(Norm_Den
(U
));
169 end Add_Real_To_Buffer
;
171 ------------------------
172 -- Add_Uint_To_Buffer --
173 ------------------------
175 procedure Add_Uint_To_Buffer
(U
: Uint
) is
178 Add_Uint_To_Buffer
(-U
);
179 Add_Char_To_Name_Buffer
('m');
181 UI_Image
(U
, Decimal
);
182 Add_Str_To_Name_Buffer
(UI_Image_Buffer
(1 .. UI_Image_Length
));
184 end Add_Uint_To_Buffer
;
186 ---------------------------
187 -- Append_Homonym_Number --
188 ---------------------------
190 procedure Append_Homonym_Number
(E
: Entity_Id
) is
192 procedure Add_Nat_To_H
(Nr
: Nat
);
193 -- Little procedure to append Nr to Homonym_Numbers
199 procedure Add_Nat_To_H
(Nr
: Nat
) is
202 Add_Nat_To_H
(Nr
/ 10);
205 Homonym_Len
:= Homonym_Len
+ 1;
206 Homonym_Numbers
(Homonym_Len
) :=
207 Character'Val (Nr
mod 10 + Character'Pos ('0'));
210 -- Start of processing for Append_Homonym_Number
213 if Has_Homonym
(E
) then
215 H
: Entity_Id
:= Homonym
(E
);
219 while Present
(H
) loop
220 if Scope
(H
) = Scope
(E
) then
227 if Homonym_Len
> 0 then
228 Homonym_Len
:= Homonym_Len
+ 1;
229 Homonym_Numbers
(Homonym_Len
) := '_';
235 end Append_Homonym_Number
;
237 -----------------------
238 -- Bounds_Match_Size --
239 -----------------------
241 function Bounds_Match_Size
(E
: Entity_Id
) return Boolean is
245 if not Is_OK_Static_Subtype
(E
) then
248 elsif Is_Integer_Type
(E
)
249 and then Subtypes_Statically_Match
(E
, Base_Type
(E
))
253 -- Here we check if the static bounds match the natural size, which
254 -- is the size passed through with the debugging information. This
255 -- is the Esize rounded up to 8, 16, 32 or 64 as appropriate.
259 Umark
: constant Uintp
.Save_Mark
:= Uintp
.Mark
;
263 if Esize
(E
) <= 8 then
265 elsif Esize
(E
) <= 16 then
267 elsif Esize
(E
) <= 32 then
273 if Is_Modular_Integer_Type
(E
) or else Is_Enumeration_Type
(E
) then
275 Expr_Rep_Value
(Type_Low_Bound
(E
)) = 0
277 2 ** Siz
- Expr_Rep_Value
(Type_High_Bound
(E
)) = 1;
281 Expr_Rep_Value
(Type_Low_Bound
(E
)) + 2 ** (Siz
- 1) = 0
283 2 ** (Siz
- 1) - Expr_Rep_Value
(Type_High_Bound
(E
)) = 1;
290 end Bounds_Match_Size
;
292 --------------------------------
293 -- Debug_Renaming_Declaration --
294 --------------------------------
296 function Debug_Renaming_Declaration
(N
: Node_Id
) return Node_Id
is
297 Loc
: constant Source_Ptr
:= Sloc
(N
);
298 Ent
: constant Node_Id
:= Defining_Entity
(N
);
299 Nam
: constant Node_Id
:= Name
(N
);
307 function Output_Subscript
(N
: Node_Id
; S
: String) return Boolean;
308 -- Outputs a single subscript value as ?nnn (subscript is compile
309 -- time known value with value nnn) or as ?e (subscript is local
310 -- constant with name e), where S supplies the proper string to
311 -- use for ?. Returns False if the subscript is not of an appropriate
312 -- type to output in one of these two forms. The result is prepended
313 -- to the name stored in Name_Buffer.
315 ----------------------
316 -- Output_Subscript --
317 ----------------------
319 function Output_Subscript
(N
: Node_Id
; S
: String) return Boolean is
321 if Compile_Time_Known_Value
(N
) then
322 Prepend_Uint_To_Buffer
(Expr_Value
(N
));
324 elsif Nkind
(N
) = N_Identifier
325 and then Scope
(Entity
(N
)) = Scope
(Ent
)
326 and then Ekind
(Entity
(N
)) = E_Constant
328 Prepend_String_To_Buffer
(Get_Name_String
(Chars
(Entity
(N
))));
334 Prepend_String_To_Buffer
(S
);
336 end Output_Subscript
;
338 -- Start of processing for Debug_Renaming_Declaration
341 if not Comes_From_Source
(N
)
342 and then not Needs_Debug_Info
(Ent
)
347 -- Prepare entity name for type declaration
349 Get_Name_String
(Chars
(Ent
));
352 when N_Object_Renaming_Declaration
=>
353 Add_Str_To_Name_Buffer
("___XR");
355 when N_Exception_Renaming_Declaration
=>
356 Add_Str_To_Name_Buffer
("___XRE");
358 when N_Package_Renaming_Declaration
=>
359 Add_Str_To_Name_Buffer
("___XRP");
361 -- If it is a child unit create a fully qualified name,
362 -- to disambiguate multiple child units with the same
363 -- name and different parents.
365 if Is_Child_Unit
(Ent
) then
366 Prepend_String_To_Buffer
("__");
367 Prepend_String_To_Buffer
368 (Get_Name_String
(Chars
(Scope
(Ent
))));
377 -- Get renamed entity and compute suffix
387 when N_Expanded_Name
=>
389 -- The entity field for an N_Expanded_Name is on the
390 -- expanded name node itself, so we are done here too.
394 when N_Selected_Component
=>
395 Prepend_String_To_Buffer
396 (Get_Name_String
(Chars
(Selector_Name
(Ren
))));
397 Prepend_String_To_Buffer
("XR");
400 when N_Indexed_Component
=>
402 X
: Node_Id
:= Last
(Expressions
(Ren
));
405 while Present
(X
) loop
406 if not Output_Subscript
(X
, "XS") then
407 Set_Materialize_Entity
(Ent
);
419 Typ
:= Etype
(First_Index
(Etype
(Nam
)));
421 if not Output_Subscript
(Type_High_Bound
(Typ
), "XS") then
422 Set_Materialize_Entity
(Ent
);
426 if not Output_Subscript
(Type_Low_Bound
(Typ
), "XL") then
427 Set_Materialize_Entity
(Ent
);
433 when N_Explicit_Dereference
=>
434 Prepend_String_To_Buffer
("XA");
437 -- For now, anything else simply results in no translation
440 Set_Materialize_Entity
(Ent
);
445 Prepend_String_To_Buffer
("___XE");
447 -- For now, the literal name contains only the suffix. The Entity_Id
448 -- value for the name is used to create a link from this literal name
449 -- to the renamed entity using the Debug_Renaming_Link field. Then the
450 -- Qualify_Entity_Name procedure uses this link to create the proper
451 -- fully qualified name.
453 -- The reason we do things this way is that we really need to copy the
454 -- qualification of the renamed entity, and it is really much easier to
455 -- do this after the renamed entity has itself been fully qualified.
457 Lit
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Enter
);
458 Set_Debug_Renaming_Link
(Lit
, Entity
(Ren
));
460 -- Return the appropriate enumeration type
462 Def
:= Make_Defining_Identifier
(Loc
, Chars
=> Rnm
);
464 Make_Full_Type_Declaration
(Loc
,
465 Defining_Identifier
=> Def
,
467 Make_Enumeration_Type_Definition
(Loc
,
468 Literals
=> New_List
(Lit
)));
470 Set_Needs_Debug_Info
(Def
);
471 Set_Needs_Debug_Info
(Lit
);
473 Set_Discard_Names
(Defining_Identifier
(Res
));
476 -- If we get an exception, just figure it is a case that we cannot
477 -- successfully handle using our current approach, since this is
478 -- only for debugging, no need to take the compilation with us!
482 return Make_Null_Statement
(Loc
);
483 end Debug_Renaming_Declaration
;
485 ----------------------
486 -- Get_Encoded_Name --
487 ----------------------
489 -- Note: see spec for details on encodings
491 procedure Get_Encoded_Name
(E
: Entity_Id
) is
492 Has_Suffix
: Boolean;
495 Get_Name_String
(Chars
(E
));
497 -- Nothing to do if we do not have a type
501 -- Or if this is an enumeration base type
503 or else (Is_Enumeration_Type
(E
)
504 and then E
= Base_Type
(E
))
506 -- Or if this is a dummy type for a renaming
508 or else (Name_Len
>= 3 and then
509 Name_Buffer
(Name_Len
- 2 .. Name_Len
) = "_XR")
511 or else (Name_Len
>= 4 and then
512 (Name_Buffer
(Name_Len
- 3 .. Name_Len
) = "_XRE"
514 Name_Buffer
(Name_Len
- 3 .. Name_Len
) = "_XRP"))
516 -- For all these cases, just return the name unchanged
519 Name_Buffer
(Name_Len
+ 1) := ASCII
.Nul
;
527 if Is_Fixed_Point_Type
(E
) then
528 Get_External_Name_With_Suffix
(E
, "XF_");
529 Add_Real_To_Buffer
(Delta_Value
(E
));
531 if Small_Value
(E
) /= Delta_Value
(E
) then
532 Add_Str_To_Name_Buffer
("_");
533 Add_Real_To_Buffer
(Small_Value
(E
));
536 -- Vax floating-point case
538 elsif Vax_Float
(E
) then
540 if Digits_Value
(Base_Type
(E
)) = 6 then
541 Get_External_Name_With_Suffix
(E
, "XFF");
543 elsif Digits_Value
(Base_Type
(E
)) = 9 then
544 Get_External_Name_With_Suffix
(E
, "XFF");
547 pragma Assert
(Digits_Value
(Base_Type
(E
)) = 15);
548 Get_External_Name_With_Suffix
(E
, "XFG");
551 -- Discrete case where bounds do not match size
553 elsif Is_Discrete_Type
(E
)
554 and then not Bounds_Match_Size
(E
)
556 if Has_Biased_Representation
(E
) then
557 Get_External_Name_With_Suffix
(E
, "XB");
559 Get_External_Name_With_Suffix
(E
, "XD");
563 Lo
: constant Node_Id
:= Type_Low_Bound
(E
);
564 Hi
: constant Node_Id
:= Type_High_Bound
(E
);
566 Lo_Con
: constant Boolean := Compile_Time_Known_Value
(Lo
);
567 Hi_Con
: constant Boolean := Compile_Time_Known_Value
(Hi
);
569 Lo_Discr
: constant Boolean :=
570 Nkind
(Lo
) = N_Identifier
572 Ekind
(Entity
(Lo
)) = E_Discriminant
;
574 Hi_Discr
: constant Boolean :=
575 Nkind
(Hi
) = N_Identifier
577 Ekind
(Entity
(Hi
)) = E_Discriminant
;
579 Lo_Encode
: constant Boolean := Lo_Con
or Lo_Discr
;
580 Hi_Encode
: constant Boolean := Hi_Con
or Hi_Discr
;
583 if Lo_Encode
or Hi_Encode
then
586 Add_Str_To_Name_Buffer
("LU_");
588 Add_Str_To_Name_Buffer
("L_");
591 Add_Str_To_Name_Buffer
("U_");
595 Add_Uint_To_Buffer
(Expr_Rep_Value
(Lo
));
597 Get_Name_String_And_Append
(Chars
(Entity
(Lo
)));
600 if Lo_Encode
and Hi_Encode
then
601 Add_Str_To_Name_Buffer
("__");
605 Add_Uint_To_Buffer
(Expr_Rep_Value
(Hi
));
607 Get_Name_String_And_Append
(Chars
(Entity
(Hi
)));
612 -- For all other cases, the encoded name is the normal type name
616 Get_External_Name
(E
, Has_Suffix
);
619 if Debug_Flag_B
and then Has_Suffix
then
620 Write_Str
("**** type ");
621 Write_Name
(Chars
(E
));
622 Write_Str
(" is encoded as ");
623 Write_Str
(Name_Buffer
(1 .. Name_Len
));
627 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
628 end Get_Encoded_Name
;
630 -----------------------
631 -- Get_External_Name --
632 -----------------------
634 procedure Get_External_Name
(Entity
: Entity_Id
; Has_Suffix
: Boolean) is
635 E
: Entity_Id
:= Entity
;
638 procedure Get_Qualified_Name_And_Append
(Entity
: Entity_Id
);
639 -- Appends fully qualified name of given entity to Name_Buffer
641 -----------------------------------
642 -- Get_Qualified_Name_And_Append --
643 -----------------------------------
645 procedure Get_Qualified_Name_And_Append
(Entity
: Entity_Id
) is
647 -- If the entity is a compilation unit, its scope is Standard,
648 -- there is no outer scope, and the no further qualification
651 -- If the front end has already computed a fully qualified name,
652 -- then it is also the case that no further qualification is
655 if Present
(Scope
(Scope
(Entity
)))
656 and then not Has_Fully_Qualified_Name
(Entity
)
658 Get_Qualified_Name_And_Append
(Scope
(Entity
));
659 Add_Str_To_Name_Buffer
("__");
660 Get_Name_String_And_Append
(Chars
(Entity
));
661 Append_Homonym_Number
(Entity
);
664 Get_Name_String_And_Append
(Chars
(Entity
));
667 end Get_Qualified_Name_And_Append
;
669 -- Start of processing for Get_External_Name
674 -- If this is a child unit, we want the child
676 if Nkind
(E
) = N_Defining_Program_Unit_Name
then
677 E
:= Defining_Identifier
(Entity
);
682 -- Case of interface name being used
684 if (Kind
= E_Procedure
or else
685 Kind
= E_Function
or else
686 Kind
= E_Constant
or else
687 Kind
= E_Variable
or else
689 and then Present
(Interface_Name
(E
))
690 and then No
(Address_Clause
(E
))
691 and then not Has_Suffix
693 Add_String_To_Name_Buffer
(Strval
(Interface_Name
(E
)));
695 -- All other cases besides the interface name case
698 -- If this is a library level subprogram (i.e. a subprogram that is a
699 -- compilation unit other than a subunit), then we prepend _ada_ to
700 -- ensure distinctions required as described in the spec.
701 -- Check explicitly for child units, because those are not flagged
702 -- as Compilation_Units by lib. Should they be ???
705 and then (Is_Compilation_Unit
(E
) or Is_Child_Unit
(E
))
706 and then not Has_Suffix
708 Add_Str_To_Name_Buffer
("_ada_");
711 -- If the entity is a subprogram instance that is not a compilation
712 -- unit, generate the name of the original Ada entity, which is the
715 if Is_Generic_Instance
(E
)
716 and then Is_Subprogram
(E
)
717 and then not Is_Compilation_Unit
(Scope
(E
))
718 and then (Ekind
(Scope
(E
)) = E_Package
720 Ekind
(Scope
(E
)) = E_Package_Body
)
721 and then Present
(Related_Instance
(Scope
(E
)))
723 E
:= Related_Instance
(Scope
(E
));
726 Get_Qualified_Name_And_Append
(E
);
729 Name_Buffer
(Name_Len
+ 1) := ASCII
.Nul
;
730 end Get_External_Name
;
732 -----------------------------------
733 -- Get_External_Name_With_Suffix --
734 -----------------------------------
736 procedure Get_External_Name_With_Suffix
740 Has_Suffix
: constant Boolean := (Suffix
/= "");
741 use type Opt
.Operating_Mode_Type
;
744 if Opt
.Operating_Mode
/= Opt
.Generate_Code
then
746 -- If we are not in code generation mode, we still may call this
747 -- procedure from Back_End (more specifically - from gigi for doing
748 -- type representation annotation or some representation-specific
749 -- checks). But in this mode there is no need to mess with external
750 -- names. Furthermore, the call causes difficulties in this case
751 -- because the string representing the homonym number is not
752 -- correctly reset as a part of the call to
753 -- Output_Homonym_Numbers_Suffix (which is not called in gigi)
758 Get_External_Name
(Entity
, Has_Suffix
);
761 Add_Str_To_Name_Buffer
("___");
762 Add_Str_To_Name_Buffer
(Suffix
);
764 Name_Buffer
(Name_Len
+ 1) := ASCII
.Nul
;
766 end Get_External_Name_With_Suffix
;
768 --------------------------
769 -- Get_Variant_Encoding --
770 --------------------------
772 procedure Get_Variant_Encoding
(V
: Node_Id
) is
775 procedure Choice_Val
(Typ
: Character; Choice
: Node_Id
);
776 -- Output encoded value for a single choice value. Typ is the key
777 -- character ('S', 'F', or 'T') that precedes the choice value.
783 procedure Choice_Val
(Typ
: Character; Choice
: Node_Id
) is
785 Add_Char_To_Name_Buffer
(Typ
);
787 if Nkind
(Choice
) = N_Integer_Literal
then
788 Add_Uint_To_Buffer
(Intval
(Choice
));
790 -- Character literal with no entity present (this is the case
791 -- Standard.Character or Standard.Wide_Character as root type)
793 elsif Nkind
(Choice
) = N_Character_Literal
794 and then No
(Entity
(Choice
))
796 Add_Uint_To_Buffer
(Char_Literal_Value
(Choice
));
800 Ent
: constant Entity_Id
:= Entity
(Choice
);
803 if Ekind
(Ent
) = E_Enumeration_Literal
then
804 Add_Uint_To_Buffer
(Enumeration_Rep
(Ent
));
807 pragma Assert
(Ekind
(Ent
) = E_Constant
);
808 Choice_Val
(Typ
, Constant_Value
(Ent
));
814 -- Start of processing for Get_Variant_Encoding
819 Choice
:= First
(Discrete_Choices
(V
));
820 while Present
(Choice
) loop
821 if Nkind
(Choice
) = N_Others_Choice
then
822 Add_Char_To_Name_Buffer
('O');
824 elsif Nkind
(Choice
) = N_Range
then
825 Choice_Val
('R', Low_Bound
(Choice
));
826 Choice_Val
('T', High_Bound
(Choice
));
828 elsif Is_Entity_Name
(Choice
)
829 and then Is_Type
(Entity
(Choice
))
831 Choice_Val
('R', Type_Low_Bound
(Entity
(Choice
)));
832 Choice_Val
('T', Type_High_Bound
(Entity
(Choice
)));
834 elsif Nkind
(Choice
) = N_Subtype_Indication
then
836 Rang
: constant Node_Id
:=
837 Range_Expression
(Constraint
(Choice
));
839 Choice_Val
('R', Low_Bound
(Rang
));
840 Choice_Val
('T', High_Bound
(Rang
));
844 Choice_Val
('S', Choice
);
850 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
854 VP
: constant Node_Id
:= Parent
(V
); -- Variant_Part
855 CL
: constant Node_Id
:= Parent
(VP
); -- Component_List
856 RD
: constant Node_Id
:= Parent
(CL
); -- Record_Definition
857 FT
: constant Node_Id
:= Parent
(RD
); -- Full_Type_Declaration
860 Write_Str
("**** variant for type ");
861 Write_Name
(Chars
(Defining_Identifier
(FT
)));
862 Write_Str
(" is encoded as ");
863 Write_Str
(Name_Buffer
(1 .. Name_Len
));
867 end Get_Variant_Encoding
;
869 ---------------------------------
870 -- Make_Packed_Array_Type_Name --
871 ---------------------------------
873 function Make_Packed_Array_Type_Name
879 Get_Name_String
(Chars
(Typ
));
880 Add_Str_To_Name_Buffer
("___XP");
881 Add_Uint_To_Buffer
(Csize
);
883 end Make_Packed_Array_Type_Name
;
885 -----------------------------------
886 -- Output_Homonym_Numbers_Suffix --
887 -----------------------------------
889 procedure Output_Homonym_Numbers_Suffix
is
893 if Homonym_Len
> 0 then
895 -- Check for all 1's, in which case we do not output
899 exit when Homonym_Numbers
(J
) /= '1';
901 -- If we reached end of string we do not output
903 if J
= Homonym_Len
then
908 exit when Homonym_Numbers
(J
+ 1) /= '_';
912 -- If we exit the loop then suffix must be output
914 Add_Str_To_Name_Buffer
("__");
915 Add_Str_To_Name_Buffer
(Homonym_Numbers
(1 .. Homonym_Len
));
918 end Output_Homonym_Numbers_Suffix
;
920 ------------------------------
921 -- Prepend_String_To_Buffer --
922 ------------------------------
924 procedure Prepend_String_To_Buffer
(S
: String) is
925 N
: constant Integer := S
'Length;
927 Name_Buffer
(1 + N
.. Name_Len
+ N
) := Name_Buffer
(1 .. Name_Len
);
928 Name_Buffer
(1 .. N
) := S
;
929 Name_Len
:= Name_Len
+ N
;
930 end Prepend_String_To_Buffer
;
932 ----------------------------
933 -- Prepend_Uint_To_Buffer --
934 ----------------------------
936 procedure Prepend_Uint_To_Buffer
(U
: Uint
) is
939 Prepend_String_To_Buffer
("m");
940 Prepend_Uint_To_Buffer
(-U
);
942 UI_Image
(U
, Decimal
);
943 Prepend_String_To_Buffer
(UI_Image_Buffer
(1 .. UI_Image_Length
));
945 end Prepend_Uint_To_Buffer
;
947 ------------------------------
948 -- Qualify_All_Entity_Names --
949 ------------------------------
951 procedure Qualify_All_Entity_Names
is
956 for J
in Name_Qualify_Units
.First
.. Name_Qualify_Units
.Last
loop
957 E
:= Defining_Entity
(Name_Qualify_Units
.Table
(J
));
958 Qualify_Entity_Name
(E
);
960 Ent
:= First_Entity
(E
);
961 while Present
(Ent
) loop
962 Qualify_Entity_Name
(Ent
);
965 -- There are odd cases where Last_Entity (E) = E. This happens
966 -- in the case of renaming of packages. This test avoids getting
967 -- stuck in such cases.
972 end Qualify_All_Entity_Names
;
974 -------------------------
975 -- Qualify_Entity_Name --
976 -------------------------
978 procedure Qualify_Entity_Name
(Ent
: Entity_Id
) is
980 Full_Qualify_Name
: String (1 .. Name_Buffer
'Length);
981 Full_Qualify_Len
: Natural := 0;
982 -- Used to accumulate fully qualified name of subprogram
984 procedure Fully_Qualify_Name
(E
: Entity_Id
);
985 -- Used to qualify a subprogram or type name, where full
986 -- qualification up to Standard is always used. Name is set
987 -- in Full_Qualify_Name with the length in Full_Qualify_Len.
988 -- Note that this routine does not prepend the _ada_ string
989 -- required for library subprograms (this is done in the back end).
991 function Is_BNPE
(S
: Entity_Id
) return Boolean;
992 -- Determines if S is a BNPE, i.e. Body-Nested Package Entity, which
993 -- is defined to be a package which is immediately nested within a
996 function Qualify_Needed
(S
: Entity_Id
) return Boolean;
997 -- Given a scope, determines if the scope is to be included in the
998 -- fully qualified name, True if so, False if not.
1000 procedure Set_BNPE_Suffix
(E
: Entity_Id
);
1001 -- Recursive routine to append the BNPE qualification suffix. Works
1002 -- from right to left with E being the current entity in the list.
1003 -- The result does NOT have the trailing n's and trailing b stripped.
1004 -- The caller must do this required stripping.
1006 procedure Set_Entity_Name
(E
: Entity_Id
);
1007 -- Internal recursive routine that does most of the work. This routine
1008 -- leaves the result sitting in Name_Buffer and Name_Len.
1010 BNPE_Suffix_Needed
: Boolean := False;
1011 -- Set true if a body-nested package entity suffix is required
1013 Save_Chars
: constant Name_Id
:= Chars
(Ent
);
1014 -- Save original name
1016 ------------------------
1017 -- Fully_Qualify_Name --
1018 ------------------------
1020 procedure Fully_Qualify_Name
(E
: Entity_Id
) is
1021 Discard
: Boolean := False;
1024 -- Ignore empty entry (can happen in error cases)
1029 -- If this we are qualifying entities local to a generic
1030 -- instance, use the name of the original instantiation,
1031 -- not that of the anonymous subprogram in the wrapper
1032 -- package, so that gdb doesn't have to know about these.
1034 elsif Is_Generic_Instance
(E
)
1035 and then Is_Subprogram
(E
)
1036 and then not Comes_From_Source
(E
)
1037 and then not Is_Compilation_Unit
(Scope
(E
))
1039 Fully_Qualify_Name
(Related_Instance
(Scope
(E
)));
1043 -- If we reached fully qualified name, then just copy it
1045 if Has_Fully_Qualified_Name
(E
) then
1046 Get_Name_String
(Chars
(E
));
1047 Strip_Suffixes
(Discard
);
1048 Full_Qualify_Name
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
1049 Full_Qualify_Len
:= Name_Len
;
1050 Set_Has_Fully_Qualified_Name
(Ent
);
1052 -- Case of non-fully qualified name
1055 if Scope
(E
) = Standard_Standard
then
1056 Set_Has_Fully_Qualified_Name
(Ent
);
1058 Fully_Qualify_Name
(Scope
(E
));
1059 Full_Qualify_Name
(Full_Qualify_Len
+ 1) := '_';
1060 Full_Qualify_Name
(Full_Qualify_Len
+ 2) := '_';
1061 Full_Qualify_Len
:= Full_Qualify_Len
+ 2;
1064 if Has_Qualified_Name
(E
) then
1065 Get_Unqualified_Name_String
(Chars
(E
));
1067 Get_Name_String
(Chars
(E
));
1070 -- A special check here, we never add internal block or loop
1071 -- names, since they intefere with debugging. We identify these
1072 -- by the fact that they start with an upper case B or L.
1073 -- But do add these if what we are qualifying is a __clean
1074 -- procedure since those need to be made unique.
1076 if (Name_Buffer
(1) = 'B' or else Name_Buffer
(1) = 'L')
1077 and then (not Debug_Flag_VV
)
1078 and then Full_Qualify_Len
> 2
1079 and then Chars
(Ent
) /= Name_uClean
1081 Full_Qualify_Len
:= Full_Qualify_Len
- 2;
1085 (Full_Qualify_Len
+ 1 .. Full_Qualify_Len
+ Name_Len
) :=
1086 Name_Buffer
(1 .. Name_Len
);
1087 Full_Qualify_Len
:= Full_Qualify_Len
+ Name_Len
;
1088 Append_Homonym_Number
(E
);
1093 BNPE_Suffix_Needed
:= True;
1095 end Fully_Qualify_Name
;
1101 function Is_BNPE
(S
: Entity_Id
) return Boolean is
1104 Ekind
(S
) = E_Package
1105 and then Is_Package_Body_Entity
(S
);
1108 --------------------
1109 -- Qualify_Needed --
1110 --------------------
1112 function Qualify_Needed
(S
: Entity_Id
) return Boolean is
1114 -- If we got all the way to Standard, then we have certainly
1115 -- fully qualified the name, so set the flag appropriately,
1116 -- and then return False, since we are most certainly done!
1118 if S
= Standard_Standard
then
1119 Set_Has_Fully_Qualified_Name
(Ent
, True);
1122 -- Otherwise figure out if further qualification is required
1128 Ekind
(Ent
) = E_Subprogram_Body
1130 (Ekind
(S
) /= E_Block
1131 and then not Is_Dynamic_Scope
(S
));
1135 ---------------------
1136 -- Set_BNPE_Suffix --
1137 ---------------------
1139 procedure Set_BNPE_Suffix
(E
: Entity_Id
) is
1140 S
: constant Entity_Id
:= Scope
(E
);
1143 if Qualify_Needed
(S
) then
1144 Set_BNPE_Suffix
(S
);
1147 Add_Char_To_Name_Buffer
('b');
1149 Add_Char_To_Name_Buffer
('n');
1153 Add_Char_To_Name_Buffer
('X');
1156 end Set_BNPE_Suffix
;
1158 ---------------------
1159 -- Set_Entity_Name --
1160 ---------------------
1162 procedure Set_Entity_Name
(E
: Entity_Id
) is
1163 S
: constant Entity_Id
:= Scope
(E
);
1166 -- If we reach an already qualified name, just take the encoding
1167 -- except that we strip the package body suffixes, since these
1168 -- will be separately put on later.
1170 if Has_Qualified_Name
(E
) then
1171 Get_Name_String_And_Append
(Chars
(E
));
1172 Strip_Suffixes
(BNPE_Suffix_Needed
);
1174 -- If the top level name we are adding is itself fully
1175 -- qualified, then that means that the name that we are
1176 -- preparing for the Fully_Qualify_Name call will also
1177 -- generate a fully qualified name.
1179 if Has_Fully_Qualified_Name
(E
) then
1180 Set_Has_Fully_Qualified_Name
(Ent
);
1183 -- Case where upper level name is not encoded yet
1186 -- Recurse if further qualification required
1188 if Qualify_Needed
(S
) then
1189 Set_Entity_Name
(S
);
1190 Add_Str_To_Name_Buffer
("__");
1193 -- Otherwise get name and note if it is a NPBE
1195 Get_Name_String_And_Append
(Chars
(E
));
1198 BNPE_Suffix_Needed
:= True;
1201 Append_Homonym_Number
(E
);
1203 end Set_Entity_Name
;
1205 -- Start of processing for Qualify_Entity_Name
1208 if Has_Qualified_Name
(Ent
) then
1211 -- Here is where we create the proper link for renaming
1213 elsif Ekind
(Ent
) = E_Enumeration_Literal
1214 and then Present
(Debug_Renaming_Link
(Ent
))
1217 Qualify_Entity_Name
(Debug_Renaming_Link
(Ent
));
1218 Get_Name_String
(Chars
(Ent
));
1219 Prepend_String_To_Buffer
1220 (Get_Name_String
(Chars
(Debug_Renaming_Link
(Ent
))));
1221 Set_Chars
(Ent
, Name_Enter
);
1222 Set_Has_Qualified_Name
(Ent
);
1225 elsif Is_Subprogram
(Ent
)
1226 or else Ekind
(Ent
) = E_Subprogram_Body
1227 or else Is_Type
(Ent
)
1229 Fully_Qualify_Name
(Ent
);
1230 Name_Len
:= Full_Qualify_Len
;
1231 Name_Buffer
(1 .. Name_Len
) := Full_Qualify_Name
(1 .. Name_Len
);
1233 elsif Qualify_Needed
(Scope
(Ent
)) then
1235 Set_Entity_Name
(Ent
);
1238 Set_Has_Qualified_Name
(Ent
);
1242 -- Fall through with a fully qualified name in Name_Buffer/Name_Len
1244 Output_Homonym_Numbers_Suffix
;
1246 -- Add body-nested package suffix if required
1248 if BNPE_Suffix_Needed
1249 and then Ekind
(Ent
) /= E_Enumeration_Literal
1251 Set_BNPE_Suffix
(Ent
);
1253 -- Strip trailing n's and last trailing b as required. note that
1254 -- we know there is at least one b, or no suffix would be generated.
1256 while Name_Buffer
(Name_Len
) = 'n' loop
1257 Name_Len
:= Name_Len
- 1;
1260 Name_Len
:= Name_Len
- 1;
1263 Set_Chars
(Ent
, Name_Enter
);
1264 Set_Has_Qualified_Name
(Ent
);
1266 if Debug_Flag_BB
then
1268 Write_Name
(Save_Chars
);
1269 Write_Str
(" qualified as ");
1270 Write_Name
(Chars
(Ent
));
1273 end Qualify_Entity_Name
;
1275 --------------------------
1276 -- Qualify_Entity_Names --
1277 --------------------------
1279 procedure Qualify_Entity_Names
(N
: Node_Id
) is
1281 Name_Qualify_Units
.Append
(N
);
1282 end Qualify_Entity_Names
;
1284 --------------------
1285 -- Strip_Suffixes --
1286 --------------------
1288 procedure Strip_Suffixes
(BNPE_Suffix_Found
: in out Boolean) is
1292 -- Search for and strip BNPE suffix
1294 for J
in reverse 2 .. Name_Len
loop
1295 if Name_Buffer
(J
) = 'X' then
1297 BNPE_Suffix_Found
:= True;
1301 exit when Name_Buffer
(J
) /= 'b' and then Name_Buffer
(J
) /= 'n';
1304 -- Search for and strip homonym numbers suffix
1306 for J
in reverse 2 .. Name_Len
- 2 loop
1307 if Name_Buffer
(J
) = '_'
1308 and then Name_Buffer
(J
+ 1) = '_'
1310 if Name_Buffer
(J
+ 2) in '0' .. '9' then
1311 if Homonym_Len
> 0 then
1312 Homonym_Len
:= Homonym_Len
+ 1;
1313 Homonym_Numbers
(Homonym_Len
) := '-';
1316 SL
:= Name_Len
- (J
+ 1);
1318 Homonym_Numbers
(Homonym_Len
+ 1 .. Homonym_Len
+ SL
) :=
1319 Name_Buffer
(J
+ 2 .. Name_Len
);
1321 Homonym_Len
:= Homonym_Len
+ SL
;