1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1996-2007, 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_Eval
; use Sem_Eval
;
35 with Sem_Util
; use Sem_Util
;
36 with Sinfo
; use Sinfo
;
37 with Stand
; use Stand
;
38 with Stringt
; use Stringt
;
40 with Tbuild
; use Tbuild
;
41 with Urealp
; use Urealp
;
43 package body Exp_Dbug
is
45 -- The following table is used to queue up the entities passed as
46 -- arguments to Qualify_Entity_Names for later processing when
47 -- Qualify_All_Entity_Names is called.
49 package Name_Qualify_Units
is new Table
.Table
(
50 Table_Component_Type
=> Node_Id
,
51 Table_Index_Type
=> Nat
,
53 Table_Initial
=> Alloc
.Name_Qualify_Units_Initial
,
54 Table_Increment
=> Alloc
.Name_Qualify_Units_Increment
,
55 Table_Name
=> "Name_Qualify_Units");
57 --------------------------------
58 -- Use of Qualification Flags --
59 --------------------------------
61 -- There are two flags used to keep track of qualification of entities
63 -- Has_Fully_Qualified_Name
66 -- The difference between these is as follows. Has_Qualified_Name is
67 -- set to indicate that the name has been qualified as required by the
68 -- spec of this package. As described there, this may involve the full
69 -- qualification for the name, but for some entities, notably procedure
70 -- local variables, this full qualification is not required.
72 -- The flag Has_Fully_Qualified_Name is set if indeed the name has been
73 -- fully qualified in the Ada sense. If Has_Fully_Qualified_Name is set,
74 -- then Has_Qualified_Name is also set, but the other way round is not
77 -- Consider the following example:
84 -- Here B is a procedure local variable, so it does not need fully
85 -- qualification. The flag Has_Qualified_Name will be set on the
86 -- first attempt to qualify B, to indicate that the job is done
87 -- and need not be redone.
89 -- But Y is qualified as x__y, since procedures are always fully
90 -- qualified, so the first time that an attempt is made to qualify
91 -- the name y, it will be replaced by x__y, and both flags are set.
93 -- Why the two flags? Well there are cases where we derive type names
94 -- from object names. As noted in the spec, type names are always
95 -- fully qualified. Suppose for example that the backend has to build
96 -- a padded type for variable B. then it will construct the PAD name
97 -- from B, but it requires full qualification, so the fully qualified
98 -- type name will be x__b___PAD. The two flags allow the circuit for
99 -- building this name to realize efficiently that b needs further
106 -- The string defined here (and its associated length) is used to
107 -- gather the homonym string that will be appended to Name_Buffer
108 -- when the name is complete. Strip_Suffixes appends to this string
109 -- as does Append_Homonym_Number, and Output_Homonym_Numbers_Suffix
110 -- appends the string to the end of Name_Buffer.
112 Homonym_Numbers
: String (1 .. 256);
113 Homonym_Len
: Natural := 0;
115 ----------------------
116 -- Local Procedures --
117 ----------------------
119 procedure Add_Uint_To_Buffer
(U
: Uint
);
120 -- Add image of universal integer to Name_Buffer, updating Name_Len
122 procedure Add_Real_To_Buffer
(U
: Ureal
);
123 -- Add nnn_ddd to Name_Buffer, where nnn and ddd are integer values of
124 -- the normalized numerator and denominator of the given real value.
126 procedure Append_Homonym_Number
(E
: Entity_Id
);
127 -- If the entity E has homonyms in the same scope, then make an entry
128 -- in the Homonym_Numbers array, bumping Homonym_Count accordingly.
130 function Bounds_Match_Size
(E
: Entity_Id
) return Boolean;
131 -- Determine whether the bounds of E match the size of the type. This is
132 -- used to determine whether encoding is required for a discrete type.
134 procedure Output_Homonym_Numbers_Suffix
;
135 -- If homonym numbers are stored, then output them into Name_Buffer
137 procedure Prepend_String_To_Buffer
(S
: String);
138 -- Prepend given string to the contents of the string buffer, updating
139 -- the value in Name_Len (i.e. string is added at start of buffer).
141 procedure Prepend_Uint_To_Buffer
(U
: Uint
);
142 -- Prepend image of universal integer to Name_Buffer, updating Name_Len
144 procedure Qualify_Entity_Name
(Ent
: Entity_Id
);
145 -- If not already done, replaces the Chars field of the given entity
146 -- with the appropriate fully qualified name.
148 procedure Strip_Suffixes
(BNPE_Suffix_Found
: in out Boolean);
149 -- Given an qualified entity name in Name_Buffer, remove any plain X or
150 -- X{nb} qualification suffix. The contents of Name_Buffer is not changed
151 -- but Name_Len may be adjusted on return to remove the suffix. If a
152 -- BNPE suffix is found and stripped, then BNPE_Suffix_Found is set to
153 -- True. If no suffix is found, then BNPE_Suffix_Found is not modified.
154 -- This routine also searches for a homonym suffix, and if one is found
155 -- it is also stripped, and the entries are added to the global homonym
156 -- list (Homonym_Numbers) so that they can later be put back.
158 ------------------------
159 -- Add_Real_To_Buffer --
160 ------------------------
162 procedure Add_Real_To_Buffer
(U
: Ureal
) is
164 Add_Uint_To_Buffer
(Norm_Num
(U
));
165 Add_Str_To_Name_Buffer
("_");
166 Add_Uint_To_Buffer
(Norm_Den
(U
));
167 end Add_Real_To_Buffer
;
169 ------------------------
170 -- Add_Uint_To_Buffer --
171 ------------------------
173 procedure Add_Uint_To_Buffer
(U
: Uint
) is
176 Add_Uint_To_Buffer
(-U
);
177 Add_Char_To_Name_Buffer
('m');
179 UI_Image
(U
, Decimal
);
180 Add_Str_To_Name_Buffer
(UI_Image_Buffer
(1 .. UI_Image_Length
));
182 end Add_Uint_To_Buffer
;
184 ---------------------------
185 -- Append_Homonym_Number --
186 ---------------------------
188 procedure Append_Homonym_Number
(E
: Entity_Id
) is
190 procedure Add_Nat_To_H
(Nr
: Nat
);
191 -- Little procedure to append Nr to Homonym_Numbers
197 procedure Add_Nat_To_H
(Nr
: Nat
) is
200 Add_Nat_To_H
(Nr
/ 10);
203 Homonym_Len
:= Homonym_Len
+ 1;
204 Homonym_Numbers
(Homonym_Len
) :=
205 Character'Val (Nr
mod 10 + Character'Pos ('0'));
208 -- Start of processing for Append_Homonym_Number
211 if Has_Homonym
(E
) then
213 H
: Entity_Id
:= Homonym
(E
);
217 while Present
(H
) loop
218 if Scope
(H
) = Scope
(E
) then
225 if Homonym_Len
> 0 then
226 Homonym_Len
:= Homonym_Len
+ 1;
227 Homonym_Numbers
(Homonym_Len
) := '_';
233 end Append_Homonym_Number
;
235 -----------------------
236 -- Bounds_Match_Size --
237 -----------------------
239 function Bounds_Match_Size
(E
: Entity_Id
) return Boolean is
243 if not Is_OK_Static_Subtype
(E
) then
246 elsif Is_Integer_Type
(E
)
247 and then Subtypes_Statically_Match
(E
, Base_Type
(E
))
251 -- Here we check if the static bounds match the natural size, which is
252 -- the size passed through with the debugging information. This is the
253 -- Esize rounded up to 8, 16, 32 or 64 as appropriate.
257 Umark
: constant Uintp
.Save_Mark
:= Uintp
.Mark
;
261 if Esize
(E
) <= 8 then
263 elsif Esize
(E
) <= 16 then
265 elsif Esize
(E
) <= 32 then
271 if Is_Modular_Integer_Type
(E
) or else Is_Enumeration_Type
(E
) then
273 Expr_Rep_Value
(Type_Low_Bound
(E
)) = 0
275 2 ** Siz
- Expr_Rep_Value
(Type_High_Bound
(E
)) = 1;
279 Expr_Rep_Value
(Type_Low_Bound
(E
)) + 2 ** (Siz
- 1) = 0
281 2 ** (Siz
- 1) - Expr_Rep_Value
(Type_High_Bound
(E
)) = 1;
288 end Bounds_Match_Size
;
290 --------------------------------
291 -- Debug_Renaming_Declaration --
292 --------------------------------
294 function Debug_Renaming_Declaration
(N
: Node_Id
) return Node_Id
is
295 Loc
: constant Source_Ptr
:= Sloc
(N
);
296 Ent
: constant Node_Id
:= Defining_Entity
(N
);
297 Nam
: constant Node_Id
:= Name
(N
);
303 function Output_Subscript
(N
: Node_Id
; S
: String) return Boolean;
304 -- Outputs a single subscript value as ?nnn (subscript is compile time
305 -- known value with value nnn) or as ?e (subscript is local constant
306 -- with name e), where S supplies the proper string to use for ?.
307 -- Returns False if the subscript is not of an appropriate type to
308 -- output in one of these two forms. The result is prepended to the
309 -- name stored in Name_Buffer.
311 ----------------------
312 -- Output_Subscript --
313 ----------------------
315 function Output_Subscript
(N
: Node_Id
; S
: String) return Boolean is
317 if Compile_Time_Known_Value
(N
) then
318 Prepend_Uint_To_Buffer
(Expr_Value
(N
));
320 elsif Nkind
(N
) = N_Identifier
321 and then Scope
(Entity
(N
)) = Scope
(Ent
)
322 and then Ekind
(Entity
(N
)) = E_Constant
324 Prepend_String_To_Buffer
(Get_Name_String
(Chars
(Entity
(N
))));
330 Prepend_String_To_Buffer
(S
);
332 end Output_Subscript
;
334 -- Start of processing for Debug_Renaming_Declaration
337 if not Comes_From_Source
(N
)
338 and then not Needs_Debug_Info
(Ent
)
343 -- Get renamed entity and compute suffix
353 when N_Expanded_Name
=>
355 -- The entity field for an N_Expanded_Name is on the expanded
356 -- name node itself, so we are done here too.
360 when N_Selected_Component
=>
361 Prepend_String_To_Buffer
362 (Get_Name_String
(Chars
(Selector_Name
(Ren
))));
363 Prepend_String_To_Buffer
("XR");
366 when N_Indexed_Component
=>
368 X
: Node_Id
:= Last
(Expressions
(Ren
));
371 while Present
(X
) loop
372 if not Output_Subscript
(X
, "XS") then
373 Set_Materialize_Entity
(Ent
);
385 Typ
:= Etype
(First_Index
(Etype
(Nam
)));
387 if not Output_Subscript
(Type_High_Bound
(Typ
), "XS") then
388 Set_Materialize_Entity
(Ent
);
392 if not Output_Subscript
(Type_Low_Bound
(Typ
), "XL") then
393 Set_Materialize_Entity
(Ent
);
399 when N_Explicit_Dereference
=>
400 Set_Materialize_Entity
(Ent
);
401 Prepend_String_To_Buffer
("XA");
404 -- For now, anything else simply results in no translation
407 Set_Materialize_Entity
(Ent
);
412 Prepend_String_To_Buffer
("___XE");
414 -- Include the designation of the form of renaming
417 when N_Object_Renaming_Declaration
=>
418 Prepend_String_To_Buffer
("___XR");
420 when N_Exception_Renaming_Declaration
=>
421 Prepend_String_To_Buffer
("___XRE");
423 when N_Package_Renaming_Declaration
=>
424 Prepend_String_To_Buffer
("___XRP");
430 -- Add the name of the renaming entity to the front
432 Prepend_String_To_Buffer
(Get_Name_String
(Chars
(Ent
)));
434 -- If it is a child unit create a fully qualified name, to disambiguate
435 -- multiple child units with the same name and different parents.
437 if Nkind
(N
) = N_Package_Renaming_Declaration
438 and then Is_Child_Unit
(Ent
)
440 Prepend_String_To_Buffer
("__");
441 Prepend_String_To_Buffer
442 (Get_Name_String
(Chars
(Scope
(Ent
))));
445 -- Create the special object whose name is the debug encoding for the
446 -- renaming declaration.
448 -- For now, the object name contains the suffix encoding for the renamed
449 -- object, but not the name of the leading entity. The object is linked
450 -- the renamed entity using the Debug_Renaming_Link field. Then the
451 -- Qualify_Entity_Name procedure uses this link to create the proper
452 -- fully qualified name.
454 -- The reason we do things this way is that we really need to copy the
455 -- qualification of the renamed entity, and it is really much easier to
456 -- do this after the renamed entity has itself been fully qualified.
458 Obj
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Enter
);
460 Make_Object_Declaration
(Loc
,
461 Defining_Identifier
=> Obj
,
462 Object_Definition
=> New_Reference_To
463 (Standard_Debug_Renaming_Type
, Loc
));
465 Set_Debug_Renaming_Link
(Obj
, Entity
(Ren
));
467 Set_Needs_Debug_Info
(Obj
);
469 -- Mark the object as internal so that it won't be initialized when
470 -- pragma Initialize_Scalars or Normalize_Scalars is in use.
472 Set_Is_Internal
(Obj
);
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 -- If not generating code, there is no need to create encoded names, and
496 -- problems when the back-end is called to annotate types without full
497 -- code generation. See comments in Get_External_Name_With_Suffix for
498 -- additional details.
500 -- However we do create encoded names if the back end is active, even
501 -- if Operating_Mode got reset. Otherwise any serious error reported
502 -- by the backend calling Error_Msg changes the Compilation_Mode to
503 -- Check_Semantics, which disables the functionality of this routine,
504 -- causing the generation of spurious additional errors.
506 -- Couldn't we just test Original_Operating_Mode here? ???
508 if Operating_Mode
/= Generate_Code
509 and then not Generating_Code
514 Get_Name_String
(Chars
(E
));
516 -- Nothing to do if we do not have a type
520 -- Or if this is an enumeration base type
522 or else (Is_Enumeration_Type
(E
)
523 and then E
= Base_Type
(E
))
525 -- Or if this is a dummy type for a renaming
527 or else (Name_Len
>= 3 and then
528 Name_Buffer
(Name_Len
- 2 .. Name_Len
) = "_XR")
530 or else (Name_Len
>= 4 and then
531 (Name_Buffer
(Name_Len
- 3 .. Name_Len
) = "_XRE"
533 Name_Buffer
(Name_Len
- 3 .. Name_Len
) = "_XRP"))
535 -- For all these cases, just return the name unchanged
538 Name_Buffer
(Name_Len
+ 1) := ASCII
.Nul
;
546 if Is_Fixed_Point_Type
(E
) then
547 Get_External_Name_With_Suffix
(E
, "XF_");
548 Add_Real_To_Buffer
(Delta_Value
(E
));
550 if Small_Value
(E
) /= Delta_Value
(E
) then
551 Add_Str_To_Name_Buffer
("_");
552 Add_Real_To_Buffer
(Small_Value
(E
));
555 -- Vax floating-point case
557 elsif Vax_Float
(E
) then
558 if Digits_Value
(Base_Type
(E
)) = 6 then
559 Get_External_Name_With_Suffix
(E
, "XFF");
561 elsif Digits_Value
(Base_Type
(E
)) = 9 then
562 Get_External_Name_With_Suffix
(E
, "XFF");
565 pragma Assert
(Digits_Value
(Base_Type
(E
)) = 15);
566 Get_External_Name_With_Suffix
(E
, "XFG");
569 -- Discrete case where bounds do not match size
571 elsif Is_Discrete_Type
(E
)
572 and then not Bounds_Match_Size
(E
)
575 Lo
: constant Node_Id
:= Type_Low_Bound
(E
);
576 Hi
: constant Node_Id
:= Type_High_Bound
(E
);
578 Lo_Con
: constant Boolean := Compile_Time_Known_Value
(Lo
);
579 Hi_Con
: constant Boolean := Compile_Time_Known_Value
(Hi
);
581 Lo_Discr
: constant Boolean :=
582 Nkind
(Lo
) = N_Identifier
584 Ekind
(Entity
(Lo
)) = E_Discriminant
;
586 Hi_Discr
: constant Boolean :=
587 Nkind
(Hi
) = N_Identifier
589 Ekind
(Entity
(Hi
)) = E_Discriminant
;
591 Lo_Encode
: constant Boolean := Lo_Con
or Lo_Discr
;
592 Hi_Encode
: constant Boolean := Hi_Con
or Hi_Discr
;
594 Biased
: constant Boolean := Has_Biased_Representation
(E
);
598 Get_External_Name_With_Suffix
(E
, "XB");
600 Get_External_Name_With_Suffix
(E
, "XD");
603 if Lo_Encode
or Hi_Encode
then
605 Add_Str_To_Name_Buffer
("_");
609 Add_Str_To_Name_Buffer
("LU_");
611 Add_Str_To_Name_Buffer
("L_");
614 Add_Str_To_Name_Buffer
("U_");
619 Add_Uint_To_Buffer
(Expr_Rep_Value
(Lo
));
621 Get_Name_String_And_Append
(Chars
(Entity
(Lo
)));
624 if Lo_Encode
and Hi_Encode
then
625 Add_Str_To_Name_Buffer
("__");
629 Add_Uint_To_Buffer
(Expr_Rep_Value
(Hi
));
631 Get_Name_String_And_Append
(Chars
(Entity
(Hi
)));
636 -- For all other cases, the encoded name is the normal type name
640 Get_External_Name
(E
, Has_Suffix
);
643 if Debug_Flag_B
and then Has_Suffix
then
644 Write_Str
("**** type ");
645 Write_Name
(Chars
(E
));
646 Write_Str
(" is encoded as ");
647 Write_Str
(Name_Buffer
(1 .. Name_Len
));
651 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
652 end Get_Encoded_Name
;
654 -----------------------
655 -- Get_External_Name --
656 -----------------------
658 procedure Get_External_Name
(Entity
: Entity_Id
; Has_Suffix
: Boolean) is
659 E
: Entity_Id
:= Entity
;
662 procedure Get_Qualified_Name_And_Append
(Entity
: Entity_Id
);
663 -- Appends fully qualified name of given entity to Name_Buffer
665 -----------------------------------
666 -- Get_Qualified_Name_And_Append --
667 -----------------------------------
669 procedure Get_Qualified_Name_And_Append
(Entity
: Entity_Id
) is
671 -- If the entity is a compilation unit, its scope is Standard,
672 -- there is no outer scope, and the no further qualification
675 -- If the front end has already computed a fully qualified name,
676 -- then it is also the case that no further qualification is
679 if Present
(Scope
(Scope
(Entity
)))
680 and then not Has_Fully_Qualified_Name
(Entity
)
682 Get_Qualified_Name_And_Append
(Scope
(Entity
));
683 Add_Str_To_Name_Buffer
("__");
684 Get_Name_String_And_Append
(Chars
(Entity
));
685 Append_Homonym_Number
(Entity
);
688 Get_Name_String_And_Append
(Chars
(Entity
));
690 end Get_Qualified_Name_And_Append
;
692 -- Start of processing for Get_External_Name
698 -- If this is a child unit, we want the child
700 if Nkind
(E
) = N_Defining_Program_Unit_Name
then
701 E
:= Defining_Identifier
(Entity
);
706 -- Case of interface name being used
708 if (Kind
= E_Procedure
or else
709 Kind
= E_Function
or else
710 Kind
= E_Constant
or else
711 Kind
= E_Variable
or else
713 and then Present
(Interface_Name
(E
))
714 and then No
(Address_Clause
(E
))
715 and then not Has_Suffix
717 Add_String_To_Name_Buffer
(Strval
(Interface_Name
(E
)));
719 -- All other cases besides the interface name case
722 -- If this is a library level subprogram (i.e. a subprogram that is a
723 -- compilation unit other than a subunit), then we prepend _ada_ to
724 -- ensure distinctions required as described in the spec.
726 -- Check explicitly for child units, because those are not flagged
727 -- as Compilation_Units by lib. Should they be ???
730 and then (Is_Compilation_Unit
(E
) or Is_Child_Unit
(E
))
731 and then not Has_Suffix
733 Add_Str_To_Name_Buffer
("_ada_");
736 -- If the entity is a subprogram instance that is not a compilation
737 -- unit, generate the name of the original Ada entity, which is the
740 if Is_Generic_Instance
(E
)
741 and then Is_Subprogram
(E
)
742 and then not Is_Compilation_Unit
(Scope
(E
))
743 and then (Ekind
(Scope
(E
)) = E_Package
745 Ekind
(Scope
(E
)) = E_Package_Body
)
746 and then Present
(Related_Instance
(Scope
(E
)))
748 E
:= Related_Instance
(Scope
(E
));
751 Get_Qualified_Name_And_Append
(E
);
754 Name_Buffer
(Name_Len
+ 1) := ASCII
.Nul
;
755 end Get_External_Name
;
757 -----------------------------------
758 -- Get_External_Name_With_Suffix --
759 -----------------------------------
761 procedure Get_External_Name_With_Suffix
765 Has_Suffix
: constant Boolean := (Suffix
/= "");
768 -- If we are not in code generation mode, this procedure may still be
769 -- called from Back_End (more specifically - from gigi for doing type
770 -- representation annotation or some representation-specific checks).
771 -- But in this mode there is no need to mess with external names.
773 -- Furthermore, the call causes difficulties in this case because the
774 -- string representing the homonym number is not correctly reset as a
775 -- part of the call to Output_Homonym_Numbers_Suffix (which is not
778 if Operating_Mode
/= Generate_Code
then
782 Get_External_Name
(Entity
, Has_Suffix
);
785 Add_Str_To_Name_Buffer
("___");
786 Add_Str_To_Name_Buffer
(Suffix
);
787 Name_Buffer
(Name_Len
+ 1) := ASCII
.Nul
;
789 end Get_External_Name_With_Suffix
;
791 --------------------------
792 -- Get_Variant_Encoding --
793 --------------------------
795 procedure Get_Variant_Encoding
(V
: Node_Id
) is
798 procedure Choice_Val
(Typ
: Character; Choice
: Node_Id
);
799 -- Output encoded value for a single choice value. Typ is the key
800 -- character ('S', 'F', or 'T') that precedes the choice value.
806 procedure Choice_Val
(Typ
: Character; Choice
: Node_Id
) is
808 if Nkind
(Choice
) = N_Integer_Literal
then
809 Add_Char_To_Name_Buffer
(Typ
);
810 Add_Uint_To_Buffer
(Intval
(Choice
));
812 -- Character literal with no entity present (this is the case
813 -- Standard.Character or Standard.Wide_Character as root type)
815 elsif Nkind
(Choice
) = N_Character_Literal
816 and then No
(Entity
(Choice
))
818 Add_Char_To_Name_Buffer
(Typ
);
819 Add_Uint_To_Buffer
(Char_Literal_Value
(Choice
));
823 Ent
: constant Entity_Id
:= Entity
(Choice
);
826 if Ekind
(Ent
) = E_Enumeration_Literal
then
827 Add_Char_To_Name_Buffer
(Typ
);
828 Add_Uint_To_Buffer
(Enumeration_Rep
(Ent
));
831 pragma Assert
(Ekind
(Ent
) = E_Constant
);
832 Choice_Val
(Typ
, Constant_Value
(Ent
));
838 -- Start of processing for Get_Variant_Encoding
843 Choice
:= First
(Discrete_Choices
(V
));
844 while Present
(Choice
) loop
845 if Nkind
(Choice
) = N_Others_Choice
then
846 Add_Char_To_Name_Buffer
('O');
848 elsif Nkind
(Choice
) = N_Range
then
849 Choice_Val
('R', Low_Bound
(Choice
));
850 Choice_Val
('T', High_Bound
(Choice
));
852 elsif Is_Entity_Name
(Choice
)
853 and then Is_Type
(Entity
(Choice
))
855 Choice_Val
('R', Type_Low_Bound
(Entity
(Choice
)));
856 Choice_Val
('T', Type_High_Bound
(Entity
(Choice
)));
858 elsif Nkind
(Choice
) = N_Subtype_Indication
then
860 Rang
: constant Node_Id
:=
861 Range_Expression
(Constraint
(Choice
));
863 Choice_Val
('R', Low_Bound
(Rang
));
864 Choice_Val
('T', High_Bound
(Rang
));
868 Choice_Val
('S', Choice
);
874 Name_Buffer
(Name_Len
+ 1) := ASCII
.NUL
;
878 VP
: constant Node_Id
:= Parent
(V
); -- Variant_Part
879 CL
: constant Node_Id
:= Parent
(VP
); -- Component_List
880 RD
: constant Node_Id
:= Parent
(CL
); -- Record_Definition
881 FT
: constant Node_Id
:= Parent
(RD
); -- Full_Type_Declaration
884 Write_Str
("**** variant for type ");
885 Write_Name
(Chars
(Defining_Identifier
(FT
)));
886 Write_Str
(" is encoded as ");
887 Write_Str
(Name_Buffer
(1 .. Name_Len
));
891 end Get_Variant_Encoding
;
893 ------------------------------------
894 -- Get_Secondary_DT_External_Name --
895 ------------------------------------
897 procedure Get_Secondary_DT_External_Name
899 Ancestor_Typ
: Entity_Id
;
903 Get_External_Name
(Typ
, Has_Suffix
=> False);
905 if Ancestor_Typ
/= Typ
then
907 Len
: constant Natural := Name_Len
;
908 Save_Str
: constant String (1 .. Name_Len
)
909 := Name_Buffer
(1 .. Name_Len
);
911 Get_External_Name
(Ancestor_Typ
, Has_Suffix
=> False);
913 -- Append the extended name of the ancestor to the
914 -- extended name of Typ
916 Name_Buffer
(Len
+ 2 .. Len
+ Name_Len
+ 1) :=
917 Name_Buffer
(1 .. Name_Len
);
918 Name_Buffer
(1 .. Len
) := Save_Str
;
919 Name_Buffer
(Len
+ 1) := '_';
920 Name_Len
:= Len
+ Name_Len
+ 1;
924 Add_Nat_To_Name_Buffer
(Suffix_Index
);
925 end Get_Secondary_DT_External_Name
;
927 ---------------------------------
928 -- Make_Packed_Array_Type_Name --
929 ---------------------------------
931 function Make_Packed_Array_Type_Name
937 Get_Name_String
(Chars
(Typ
));
938 Add_Str_To_Name_Buffer
("___XP");
939 Add_Uint_To_Buffer
(Csize
);
941 end Make_Packed_Array_Type_Name
;
943 -----------------------------------
944 -- Output_Homonym_Numbers_Suffix --
945 -----------------------------------
947 procedure Output_Homonym_Numbers_Suffix
is
951 if Homonym_Len
> 0 then
953 -- Check for all 1's, in which case we do not output
957 exit when Homonym_Numbers
(J
) /= '1';
959 -- If we reached end of string we do not output
961 if J
= Homonym_Len
then
966 exit when Homonym_Numbers
(J
+ 1) /= '_';
970 -- If we exit the loop then suffix must be output
972 Add_Str_To_Name_Buffer
("__");
973 Add_Str_To_Name_Buffer
(Homonym_Numbers
(1 .. Homonym_Len
));
976 end Output_Homonym_Numbers_Suffix
;
978 ------------------------------
979 -- Prepend_String_To_Buffer --
980 ------------------------------
982 procedure Prepend_String_To_Buffer
(S
: String) is
983 N
: constant Integer := S
'Length;
985 Name_Buffer
(1 + N
.. Name_Len
+ N
) := Name_Buffer
(1 .. Name_Len
);
986 Name_Buffer
(1 .. N
) := S
;
987 Name_Len
:= Name_Len
+ N
;
988 end Prepend_String_To_Buffer
;
990 ----------------------------
991 -- Prepend_Uint_To_Buffer --
992 ----------------------------
994 procedure Prepend_Uint_To_Buffer
(U
: Uint
) is
997 Prepend_String_To_Buffer
("m");
998 Prepend_Uint_To_Buffer
(-U
);
1000 UI_Image
(U
, Decimal
);
1001 Prepend_String_To_Buffer
(UI_Image_Buffer
(1 .. UI_Image_Length
));
1003 end Prepend_Uint_To_Buffer
;
1005 ------------------------------
1006 -- Qualify_All_Entity_Names --
1007 ------------------------------
1009 procedure Qualify_All_Entity_Names
is
1014 for J
in Name_Qualify_Units
.First
.. Name_Qualify_Units
.Last
loop
1015 E
:= Defining_Entity
(Name_Qualify_Units
.Table
(J
));
1016 Qualify_Entity_Name
(E
);
1018 -- Normally entities in the qualification list are scopes, but in the
1019 -- case of a library-level package renaming there is an associated
1020 -- variable that encodes the debugger name and that variable is
1021 -- entered in the list since it occurs in the Aux_Decls list of the
1022 -- compilation and doesn't have a normal scope.
1024 if Ekind
(E
) /= E_Variable
then
1025 Ent
:= First_Entity
(E
);
1026 while Present
(Ent
) loop
1027 Qualify_Entity_Name
(Ent
);
1030 -- There are odd cases where Last_Entity (E) = E. This happens
1031 -- in the case of renaming of packages. This test avoids
1032 -- getting stuck in such cases.
1038 end Qualify_All_Entity_Names
;
1040 -------------------------
1041 -- Qualify_Entity_Name --
1042 -------------------------
1044 procedure Qualify_Entity_Name
(Ent
: Entity_Id
) is
1046 Full_Qualify_Name
: String (1 .. Name_Buffer
'Length);
1047 Full_Qualify_Len
: Natural := 0;
1048 -- Used to accumulate fully qualified name of subprogram
1050 procedure Fully_Qualify_Name
(E
: Entity_Id
);
1051 -- Used to qualify a subprogram or type name, where full
1052 -- qualification up to Standard is always used. Name is set
1053 -- in Full_Qualify_Name with the length in Full_Qualify_Len.
1054 -- Note that this routine does not prepend the _ada_ string
1055 -- required for library subprograms (this is done in the back end).
1057 function Is_BNPE
(S
: Entity_Id
) return Boolean;
1058 -- Determines if S is a BNPE, i.e. Body-Nested Package Entity, which
1059 -- is defined to be a package which is immediately nested within a
1062 function Qualify_Needed
(S
: Entity_Id
) return Boolean;
1063 -- Given a scope, determines if the scope is to be included in the
1064 -- fully qualified name, True if so, False if not.
1066 procedure Set_BNPE_Suffix
(E
: Entity_Id
);
1067 -- Recursive routine to append the BNPE qualification suffix. Works
1068 -- from right to left with E being the current entity in the list.
1069 -- The result does NOT have the trailing n's and trailing b stripped.
1070 -- The caller must do this required stripping.
1072 procedure Set_Entity_Name
(E
: Entity_Id
);
1073 -- Internal recursive routine that does most of the work. This routine
1074 -- leaves the result sitting in Name_Buffer and Name_Len.
1076 BNPE_Suffix_Needed
: Boolean := False;
1077 -- Set true if a body-nested package entity suffix is required
1079 Save_Chars
: constant Name_Id
:= Chars
(Ent
);
1080 -- Save original name
1082 ------------------------
1083 -- Fully_Qualify_Name --
1084 ------------------------
1086 procedure Fully_Qualify_Name
(E
: Entity_Id
) is
1087 Discard
: Boolean := False;
1090 -- Ignore empty entry (can happen in error cases)
1095 -- If this we are qualifying entities local to a generic
1096 -- instance, use the name of the original instantiation,
1097 -- not that of the anonymous subprogram in the wrapper
1098 -- package, so that gdb doesn't have to know about these.
1100 elsif Is_Generic_Instance
(E
)
1101 and then Is_Subprogram
(E
)
1102 and then not Comes_From_Source
(E
)
1103 and then not Is_Compilation_Unit
(Scope
(E
))
1105 Fully_Qualify_Name
(Related_Instance
(Scope
(E
)));
1109 -- If we reached fully qualified name, then just copy it
1111 if Has_Fully_Qualified_Name
(E
) then
1112 Get_Name_String
(Chars
(E
));
1113 Strip_Suffixes
(Discard
);
1114 Full_Qualify_Name
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
1115 Full_Qualify_Len
:= Name_Len
;
1116 Set_Has_Fully_Qualified_Name
(Ent
);
1118 -- Case of non-fully qualified name
1121 if Scope
(E
) = Standard_Standard
then
1122 Set_Has_Fully_Qualified_Name
(Ent
);
1124 Fully_Qualify_Name
(Scope
(E
));
1125 Full_Qualify_Name
(Full_Qualify_Len
+ 1) := '_';
1126 Full_Qualify_Name
(Full_Qualify_Len
+ 2) := '_';
1127 Full_Qualify_Len
:= Full_Qualify_Len
+ 2;
1130 if Has_Qualified_Name
(E
) then
1131 Get_Unqualified_Name_String
(Chars
(E
));
1133 Get_Name_String
(Chars
(E
));
1136 -- Here we do one step of the qualification
1139 (Full_Qualify_Len
+ 1 .. Full_Qualify_Len
+ Name_Len
) :=
1140 Name_Buffer
(1 .. Name_Len
);
1141 Full_Qualify_Len
:= Full_Qualify_Len
+ Name_Len
;
1142 Append_Homonym_Number
(E
);
1146 BNPE_Suffix_Needed
:= True;
1148 end Fully_Qualify_Name
;
1154 function Is_BNPE
(S
: Entity_Id
) return Boolean is
1157 Ekind
(S
) = E_Package
1158 and then Is_Package_Body_Entity
(S
);
1161 --------------------
1162 -- Qualify_Needed --
1163 --------------------
1165 function Qualify_Needed
(S
: Entity_Id
) return Boolean is
1167 -- If we got all the way to Standard, then we have certainly
1168 -- fully qualified the name, so set the flag appropriately,
1169 -- and then return False, since we are most certainly done!
1171 if S
= Standard_Standard
then
1172 Set_Has_Fully_Qualified_Name
(Ent
, True);
1175 -- Otherwise figure out if further qualification is required
1181 Ekind
(Ent
) = E_Subprogram_Body
1183 (Ekind
(S
) /= E_Block
1184 and then not Is_Dynamic_Scope
(S
));
1188 ---------------------
1189 -- Set_BNPE_Suffix --
1190 ---------------------
1192 procedure Set_BNPE_Suffix
(E
: Entity_Id
) is
1193 S
: constant Entity_Id
:= Scope
(E
);
1196 if Qualify_Needed
(S
) then
1197 Set_BNPE_Suffix
(S
);
1200 Add_Char_To_Name_Buffer
('b');
1202 Add_Char_To_Name_Buffer
('n');
1206 Add_Char_To_Name_Buffer
('X');
1208 end Set_BNPE_Suffix
;
1210 ---------------------
1211 -- Set_Entity_Name --
1212 ---------------------
1214 procedure Set_Entity_Name
(E
: Entity_Id
) is
1215 S
: constant Entity_Id
:= Scope
(E
);
1218 -- If we reach an already qualified name, just take the encoding
1219 -- except that we strip the package body suffixes, since these
1220 -- will be separately put on later.
1222 if Has_Qualified_Name
(E
) then
1223 Get_Name_String_And_Append
(Chars
(E
));
1224 Strip_Suffixes
(BNPE_Suffix_Needed
);
1226 -- If the top level name we are adding is itself fully
1227 -- qualified, then that means that the name that we are
1228 -- preparing for the Fully_Qualify_Name call will also
1229 -- generate a fully qualified name.
1231 if Has_Fully_Qualified_Name
(E
) then
1232 Set_Has_Fully_Qualified_Name
(Ent
);
1235 -- Case where upper level name is not encoded yet
1238 -- Recurse if further qualification required
1240 if Qualify_Needed
(S
) then
1241 Set_Entity_Name
(S
);
1242 Add_Str_To_Name_Buffer
("__");
1245 -- Otherwise get name and note if it is a NPBE
1247 Get_Name_String_And_Append
(Chars
(E
));
1250 BNPE_Suffix_Needed
:= True;
1253 Append_Homonym_Number
(E
);
1255 end Set_Entity_Name
;
1257 -- Start of processing for Qualify_Entity_Name
1260 if Has_Qualified_Name
(Ent
) then
1263 -- If the entity is a variable encoding the debug name for an object
1264 -- renaming, then the qualified name of the entity associated with the
1265 -- renamed object can now be incorporated in the debug name.
1267 elsif Ekind
(Ent
) = E_Variable
1268 and then Present
(Debug_Renaming_Link
(Ent
))
1271 Qualify_Entity_Name
(Debug_Renaming_Link
(Ent
));
1272 Get_Name_String
(Chars
(Ent
));
1274 -- Retrieve the now-qualified name of the renamed entity and insert
1275 -- it in the middle of the name, just preceding the suffix encoding
1276 -- describing the renamed object.
1279 Renamed_Id
: constant String :=
1280 Get_Name_String
(Chars
(Debug_Renaming_Link
(Ent
)));
1281 Insert_Len
: constant Integer := Renamed_Id
'Length + 1;
1282 Index
: Natural := Name_Len
- 3;
1285 -- Loop backwards through the name to find the start of the "___"
1286 -- sequence associated with the suffix.
1288 while Index
>= Name_Buffer
'First
1289 and then (Name_Buffer
(Index
+ 1) /= '_'
1290 or else Name_Buffer
(Index
+ 2) /= '_'
1291 or else Name_Buffer
(Index
+ 3) /= '_')
1296 pragma Assert
(Name_Buffer
(Index
+ 1 .. Index
+ 3) = "___");
1298 -- Insert an underscore separator and the entity name just in
1299 -- front of the suffix.
1301 Name_Buffer
(Index
+ 1 + Insert_Len
.. Name_Len
+ Insert_Len
) :=
1302 Name_Buffer
(Index
+ 1 .. Name_Len
);
1303 Name_Buffer
(Index
+ 1) := '_';
1304 Name_Buffer
(Index
+ 2 .. Index
+ Insert_Len
) := Renamed_Id
;
1305 Name_Len
:= Name_Len
+ Insert_Len
;
1308 -- Reset the name of the variable to the new name that includes the
1309 -- name of the renamed entity.
1311 Set_Chars
(Ent
, Name_Enter
);
1313 -- If the entity needs qualification by its scope then develop it
1314 -- here, add the variable's name, and again reset the entity name.
1316 if Qualify_Needed
(Scope
(Ent
)) then
1318 Set_Entity_Name
(Scope
(Ent
));
1319 Add_Str_To_Name_Buffer
("__");
1321 Get_Name_String_And_Append
(Chars
(Ent
));
1323 Set_Chars
(Ent
, Name_Enter
);
1326 Set_Has_Qualified_Name
(Ent
);
1329 elsif Is_Subprogram
(Ent
)
1330 or else Ekind
(Ent
) = E_Subprogram_Body
1331 or else Is_Type
(Ent
)
1333 Fully_Qualify_Name
(Ent
);
1334 Name_Len
:= Full_Qualify_Len
;
1335 Name_Buffer
(1 .. Name_Len
) := Full_Qualify_Name
(1 .. Name_Len
);
1337 elsif Qualify_Needed
(Scope
(Ent
)) then
1339 Set_Entity_Name
(Ent
);
1342 Set_Has_Qualified_Name
(Ent
);
1346 -- Fall through with a fully qualified name in Name_Buffer/Name_Len
1348 Output_Homonym_Numbers_Suffix
;
1350 -- Add body-nested package suffix if required
1352 if BNPE_Suffix_Needed
1353 and then Ekind
(Ent
) /= E_Enumeration_Literal
1355 Set_BNPE_Suffix
(Ent
);
1357 -- Strip trailing n's and last trailing b as required. note that
1358 -- we know there is at least one b, or no suffix would be generated.
1360 while Name_Buffer
(Name_Len
) = 'n' loop
1361 Name_Len
:= Name_Len
- 1;
1364 Name_Len
:= Name_Len
- 1;
1367 Set_Chars
(Ent
, Name_Enter
);
1368 Set_Has_Qualified_Name
(Ent
);
1370 if Debug_Flag_BB
then
1372 Write_Name
(Save_Chars
);
1373 Write_Str
(" qualified as ");
1374 Write_Name
(Chars
(Ent
));
1377 end Qualify_Entity_Name
;
1379 --------------------------
1380 -- Qualify_Entity_Names --
1381 --------------------------
1383 procedure Qualify_Entity_Names
(N
: Node_Id
) is
1385 Name_Qualify_Units
.Append
(N
);
1386 end Qualify_Entity_Names
;
1388 --------------------
1389 -- Strip_Suffixes --
1390 --------------------
1392 procedure Strip_Suffixes
(BNPE_Suffix_Found
: in out Boolean) is
1395 pragma Warnings
(Off
, BNPE_Suffix_Found
);
1396 -- Since this procedure only ever sets the flag
1399 -- Search for and strip BNPE suffix
1401 for J
in reverse 2 .. Name_Len
loop
1402 if Name_Buffer
(J
) = 'X' then
1404 BNPE_Suffix_Found
:= True;
1408 exit when Name_Buffer
(J
) /= 'b' and then Name_Buffer
(J
) /= 'n';
1411 -- Search for and strip homonym numbers suffix
1413 for J
in reverse 2 .. Name_Len
- 2 loop
1414 if Name_Buffer
(J
) = '_'
1415 and then Name_Buffer
(J
+ 1) = '_'
1417 if Name_Buffer
(J
+ 2) in '0' .. '9' then
1418 if Homonym_Len
> 0 then
1419 Homonym_Len
:= Homonym_Len
+ 1;
1420 Homonym_Numbers
(Homonym_Len
) := '-';
1423 SL
:= Name_Len
- (J
+ 1);
1425 Homonym_Numbers
(Homonym_Len
+ 1 .. Homonym_Len
+ SL
) :=
1426 Name_Buffer
(J
+ 2 .. Name_Len
);
1428 Homonym_Len
:= Homonym_Len
+ SL
;