* gcc.dg/Wtrampolines.c: XFAIL AIX.
[official-gcc.git] / gcc / ada / exp_dbug.adb
blob71454509216001fe7f9199a586d2113e2ea4bf29
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ D B U G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1996-2016, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
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;
32 with Opt; use Opt;
33 with Output; use Output;
34 with Sem_Aux; use Sem_Aux;
35 with Sem_Eval; use Sem_Eval;
36 with Sem_Util; use Sem_Util;
37 with Sinfo; use Sinfo;
38 with Stand; use Stand;
39 with Stringt; use Stringt;
40 with Table;
41 with Tbuild; use Tbuild;
42 with Urealp; use Urealp;
44 package body Exp_Dbug is
46 -- The following table is used to queue up the entities passed as
47 -- arguments to Qualify_Entity_Names for later processing when
48 -- Qualify_All_Entity_Names is called.
50 package Name_Qualify_Units is new Table.Table (
51 Table_Component_Type => Node_Id,
52 Table_Index_Type => Nat,
53 Table_Low_Bound => 1,
54 Table_Initial => Alloc.Name_Qualify_Units_Initial,
55 Table_Increment => Alloc.Name_Qualify_Units_Increment,
56 Table_Name => "Name_Qualify_Units");
58 --------------------------------
59 -- Use of Qualification Flags --
60 --------------------------------
62 -- There are two flags used to keep track of qualification of entities
64 -- Has_Fully_Qualified_Name
65 -- Has_Qualified_Name
67 -- The difference between these is as follows. Has_Qualified_Name is
68 -- set to indicate that the name has been qualified as required by the
69 -- spec of this package. As described there, this may involve the full
70 -- qualification for the name, but for some entities, notably procedure
71 -- local variables, this full qualification is not required.
73 -- The flag Has_Fully_Qualified_Name is set if indeed the name has been
74 -- fully qualified in the Ada sense. If Has_Fully_Qualified_Name is set,
75 -- then Has_Qualified_Name is also set, but the other way round is not
76 -- the case.
78 -- Consider the following example:
80 -- with ...
81 -- procedure X is
82 -- B : Ddd.Ttt;
83 -- procedure Y is ..
85 -- Here B is a procedure local variable, so it does not need fully
86 -- qualification. The flag Has_Qualified_Name will be set on the
87 -- first attempt to qualify B, to indicate that the job is done
88 -- and need not be redone.
90 -- But Y is qualified as x__y, since procedures are always fully
91 -- qualified, so the first time that an attempt is made to qualify
92 -- the name y, it will be replaced by x__y, and both flags are set.
94 -- Why the two flags? Well there are cases where we derive type names
95 -- from object names. As noted in the spec, type names are always
96 -- fully qualified. Suppose for example that the backend has to build
97 -- a padded type for variable B. then it will construct the PAD name
98 -- from B, but it requires full qualification, so the fully qualified
99 -- type name will be x__b___PAD. The two flags allow the circuit for
100 -- building this name to realize efficiently that b needs further
101 -- qualification.
103 --------------------
104 -- Homonym_Suffix --
105 --------------------
107 -- The string defined here (and its associated length) is used to gather
108 -- the homonym string that will be appended to Name_Buffer when the name
109 -- is complete. Strip_Suffixes appends to this string as does
110 -- Append_Homonym_Number, and Output_Homonym_Numbers_Suffix appends the
111 -- string to the end of Name_Buffer.
113 Homonym_Numbers : String (1 .. 256);
114 Homonym_Len : Natural := 0;
116 ----------------------
117 -- Local Procedures --
118 ----------------------
120 procedure Add_Uint_To_Buffer (U : Uint);
121 -- Add image of universal integer to Name_Buffer, updating Name_Len
123 procedure Add_Real_To_Buffer (U : Ureal);
124 -- Add nnn_ddd to Name_Buffer, where nnn and ddd are integer values of
125 -- the normalized numerator and denominator of the given real value.
127 procedure Append_Homonym_Number (E : Entity_Id);
128 -- If the entity E has homonyms in the same scope, then make an entry
129 -- in the Homonym_Numbers array, bumping Homonym_Count accordingly.
131 function Bounds_Match_Size (E : Entity_Id) return Boolean;
132 -- Determine whether the bounds of E match the size of the type. This is
133 -- used to determine whether encoding is required for a discrete type.
135 function Is_Handled_Scale_Factor (U : Ureal) return Boolean;
136 -- The argument U is the Small_Value of a fixed-point type. This function
137 -- determines whether the back-end can handle this scale factor. When it
138 -- cannot, we have to output a GNAT encoding for the corresponding type.
140 procedure Output_Homonym_Numbers_Suffix;
141 -- If homonym numbers are stored, then output them into Name_Buffer
143 procedure Prepend_String_To_Buffer (S : String);
144 -- Prepend given string to the contents of the string buffer, updating
145 -- the value in Name_Len (i.e. string is added at start of buffer).
147 procedure Prepend_Uint_To_Buffer (U : Uint);
148 -- Prepend image of universal integer to Name_Buffer, updating Name_Len
150 procedure Qualify_Entity_Name (Ent : Entity_Id);
151 -- If not already done, replaces the Chars field of the given entity
152 -- with the appropriate fully qualified name.
154 procedure Reset_Buffers;
155 -- Reset the contents of Name_Buffer and Homonym_Numbers by setting their
156 -- respective lengths to zero.
158 procedure Strip_Suffixes (BNPE_Suffix_Found : in out Boolean);
159 -- Given an qualified entity name in Name_Buffer, remove any plain X or
160 -- X{nb} qualification suffix. The contents of Name_Buffer is not changed
161 -- but Name_Len may be adjusted on return to remove the suffix. If a
162 -- BNPE suffix is found and stripped, then BNPE_Suffix_Found is set to
163 -- True. If no suffix is found, then BNPE_Suffix_Found is not modified.
164 -- This routine also searches for a homonym suffix, and if one is found
165 -- it is also stripped, and the entries are added to the global homonym
166 -- list (Homonym_Numbers) so that they can later be put back.
168 ------------------------
169 -- Add_Real_To_Buffer --
170 ------------------------
172 procedure Add_Real_To_Buffer (U : Ureal) is
173 begin
174 Add_Uint_To_Buffer (Norm_Num (U));
175 Add_Str_To_Name_Buffer ("_");
176 Add_Uint_To_Buffer (Norm_Den (U));
177 end Add_Real_To_Buffer;
179 ------------------------
180 -- Add_Uint_To_Buffer --
181 ------------------------
183 procedure Add_Uint_To_Buffer (U : Uint) is
184 begin
185 if U < 0 then
186 Add_Uint_To_Buffer (-U);
187 Add_Char_To_Name_Buffer ('m');
188 else
189 UI_Image (U, Decimal);
190 Add_Str_To_Name_Buffer (UI_Image_Buffer (1 .. UI_Image_Length));
191 end if;
192 end Add_Uint_To_Buffer;
194 ---------------------------
195 -- Append_Homonym_Number --
196 ---------------------------
198 procedure Append_Homonym_Number (E : Entity_Id) is
200 procedure Add_Nat_To_H (Nr : Nat);
201 -- Little procedure to append Nr to Homonym_Numbers
203 ------------------
204 -- Add_Nat_To_H --
205 ------------------
207 procedure Add_Nat_To_H (Nr : Nat) is
208 begin
209 if Nr >= 10 then
210 Add_Nat_To_H (Nr / 10);
211 end if;
213 Homonym_Len := Homonym_Len + 1;
214 Homonym_Numbers (Homonym_Len) :=
215 Character'Val (Nr mod 10 + Character'Pos ('0'));
216 end Add_Nat_To_H;
218 -- Start of processing for Append_Homonym_Number
220 begin
221 if Has_Homonym (E) then
222 declare
223 H : Entity_Id := Homonym (E);
224 Nr : Nat := 1;
226 begin
227 while Present (H) loop
228 if Scope (H) = Scope (E) then
229 Nr := Nr + 1;
230 end if;
232 H := Homonym (H);
233 end loop;
235 if Homonym_Len > 0 then
236 Homonym_Len := Homonym_Len + 1;
237 Homonym_Numbers (Homonym_Len) := '_';
238 end if;
240 Add_Nat_To_H (Nr);
241 end;
242 end if;
243 end Append_Homonym_Number;
245 -----------------------
246 -- Bounds_Match_Size --
247 -----------------------
249 function Bounds_Match_Size (E : Entity_Id) return Boolean is
250 Siz : Uint;
252 begin
253 if not Is_OK_Static_Subtype (E) then
254 return False;
256 elsif Is_Integer_Type (E)
257 and then Subtypes_Statically_Match (E, Base_Type (E))
258 then
259 return True;
261 -- Here we check if the static bounds match the natural size, which is
262 -- the size passed through with the debugging information. This is the
263 -- Esize rounded up to 8, 16, 32 or 64 as appropriate.
265 else
266 declare
267 Umark : constant Uintp.Save_Mark := Uintp.Mark;
268 Result : Boolean;
270 begin
271 if Esize (E) <= 8 then
272 Siz := Uint_8;
273 elsif Esize (E) <= 16 then
274 Siz := Uint_16;
275 elsif Esize (E) <= 32 then
276 Siz := Uint_32;
277 else
278 Siz := Uint_64;
279 end if;
281 if Is_Modular_Integer_Type (E) or else Is_Enumeration_Type (E) then
282 Result :=
283 Expr_Rep_Value (Type_Low_Bound (E)) = 0
284 and then
285 2 ** Siz - Expr_Rep_Value (Type_High_Bound (E)) = 1;
287 else
288 Result :=
289 Expr_Rep_Value (Type_Low_Bound (E)) + 2 ** (Siz - 1) = 0
290 and then
291 2 ** (Siz - 1) - Expr_Rep_Value (Type_High_Bound (E)) = 1;
292 end if;
294 Release (Umark);
295 return Result;
296 end;
297 end if;
298 end Bounds_Match_Size;
300 --------------------------------
301 -- Debug_Renaming_Declaration --
302 --------------------------------
304 function Debug_Renaming_Declaration (N : Node_Id) return Node_Id is
305 Loc : constant Source_Ptr := Sloc (N);
306 Ent : constant Node_Id := Defining_Entity (N);
307 Nam : constant Node_Id := Name (N);
308 Ren : Node_Id;
309 Typ : Entity_Id;
310 Obj : Entity_Id;
311 Res : Node_Id;
313 Enable : Boolean := Nkind (N) = N_Package_Renaming_Declaration;
314 -- By default, we do not generate an encoding for renaming. This is
315 -- however done (in which case this is set to True) in a few cases:
316 -- - when a package is renamed,
317 -- - when the renaming involves a packed array,
318 -- - when the renaming involves a packed record.
320 procedure Enable_If_Packed_Array (N : Node_Id);
321 -- Enable encoding generation if N is a packed array
323 function Output_Subscript (N : Node_Id; S : String) return Boolean;
324 -- Outputs a single subscript value as ?nnn (subscript is compile time
325 -- known value with value nnn) or as ?e (subscript is local constant
326 -- with name e), where S supplies the proper string to use for ?.
327 -- Returns False if the subscript is not of an appropriate type to
328 -- output in one of these two forms. The result is prepended to the
329 -- name stored in Name_Buffer.
331 ----------------------------
332 -- Enable_If_Packed_Array --
333 ----------------------------
335 procedure Enable_If_Packed_Array (N : Node_Id) is
336 T : constant Entity_Id := Underlying_Type (Etype (N));
337 begin
338 Enable :=
339 Enable or else (Ekind (T) in Array_Kind
340 and then Present (Packed_Array_Impl_Type (T)));
341 end Enable_If_Packed_Array;
343 ----------------------
344 -- Output_Subscript --
345 ----------------------
347 function Output_Subscript (N : Node_Id; S : String) return Boolean is
348 begin
349 if Compile_Time_Known_Value (N) then
350 Prepend_Uint_To_Buffer (Expr_Value (N));
352 elsif Nkind (N) = N_Identifier
353 and then Scope (Entity (N)) = Scope (Ent)
354 and then Ekind (Entity (N)) = E_Constant
355 then
356 Prepend_String_To_Buffer (Get_Name_String (Chars (Entity (N))));
358 else
359 return False;
360 end if;
362 Prepend_String_To_Buffer (S);
363 return True;
364 end Output_Subscript;
366 -- Start of processing for Debug_Renaming_Declaration
368 begin
369 if not Comes_From_Source (N)
370 and then not Needs_Debug_Info (Ent)
371 then
372 return Empty;
373 end if;
375 -- Get renamed entity and compute suffix
377 Name_Len := 0;
378 Ren := Nam;
379 loop
380 case Nkind (Ren) is
382 when N_Identifier =>
383 exit;
385 when N_Expanded_Name =>
387 -- The entity field for an N_Expanded_Name is on the expanded
388 -- name node itself, so we are done here too.
390 exit;
392 when N_Selected_Component =>
393 declare
394 First_Bit : constant Uint :=
395 Normalized_First_Bit (Entity (Selector_Name (Ren)));
396 begin
397 Enable :=
398 (Enable
399 or else Is_Packed (Underlying_Type (Etype (Prefix (Ren))))
400 or else (First_Bit /= No_Uint
401 and then First_Bit /= Uint_0));
402 end;
403 Prepend_String_To_Buffer
404 (Get_Name_String (Chars (Selector_Name (Ren))));
405 Prepend_String_To_Buffer ("XR");
406 Ren := Prefix (Ren);
408 when N_Indexed_Component =>
409 declare
410 X : Node_Id;
412 begin
413 Enable_If_Packed_Array (Prefix (Ren));
415 X := Last (Expressions (Ren));
416 while Present (X) loop
417 if not Output_Subscript (X, "XS") then
418 Set_Materialize_Entity (Ent);
419 return Empty;
420 end if;
422 Prev (X);
423 end loop;
424 end;
426 Ren := Prefix (Ren);
428 when N_Slice =>
429 Enable_If_Packed_Array (Prefix (Ren));
430 Typ := Etype (First_Index (Etype (Nam)));
432 if not Output_Subscript (Type_High_Bound (Typ), "XS") then
433 Set_Materialize_Entity (Ent);
434 return Empty;
435 end if;
437 if not Output_Subscript (Type_Low_Bound (Typ), "XL") then
438 Set_Materialize_Entity (Ent);
439 return Empty;
440 end if;
442 Ren := Prefix (Ren);
444 when N_Explicit_Dereference =>
445 Prepend_String_To_Buffer ("XA");
446 Ren := Prefix (Ren);
448 -- For now, anything else simply results in no translation
450 when others =>
451 Set_Materialize_Entity (Ent);
452 return Empty;
453 end case;
454 end loop;
456 -- If we found no reason here to emit an encoding, stop now
458 if not Enable then
459 Set_Materialize_Entity (Ent);
460 return Empty;
461 end if;
463 Prepend_String_To_Buffer ("___XE");
465 -- Include the designation of the form of renaming
467 case Nkind (N) is
468 when N_Object_Renaming_Declaration =>
469 Prepend_String_To_Buffer ("___XR");
471 when N_Exception_Renaming_Declaration =>
472 Prepend_String_To_Buffer ("___XRE");
474 when N_Package_Renaming_Declaration =>
475 Prepend_String_To_Buffer ("___XRP");
477 when others =>
478 return Empty;
479 end case;
481 -- Add the name of the renaming entity to the front
483 Prepend_String_To_Buffer (Get_Name_String (Chars (Ent)));
485 -- If it is a child unit create a fully qualified name, to disambiguate
486 -- multiple child units with the same name and different parents.
488 if Nkind (N) = N_Package_Renaming_Declaration
489 and then Is_Child_Unit (Ent)
490 then
491 Prepend_String_To_Buffer ("__");
492 Prepend_String_To_Buffer
493 (Get_Name_String (Chars (Scope (Ent))));
494 end if;
496 -- Create the special object whose name is the debug encoding for the
497 -- renaming declaration.
499 -- For now, the object name contains the suffix encoding for the renamed
500 -- object, but not the name of the leading entity. The object is linked
501 -- the renamed entity using the Debug_Renaming_Link field. Then the
502 -- Qualify_Entity_Name procedure uses this link to create the proper
503 -- fully qualified name.
505 -- The reason we do things this way is that we really need to copy the
506 -- qualification of the renamed entity, and it is really much easier to
507 -- do this after the renamed entity has itself been fully qualified.
509 Obj := Make_Defining_Identifier (Loc, Chars => Name_Enter);
510 Res :=
511 Make_Object_Declaration (Loc,
512 Defining_Identifier => Obj,
513 Object_Definition => New_Occurrence_Of
514 (Standard_Debug_Renaming_Type, Loc));
516 Set_Debug_Renaming_Link (Obj, Entity (Ren));
518 Set_Debug_Info_Needed (Obj);
520 -- The renamed entity may be a temporary, e.g. the result of an
521 -- implicit dereference in an iterator. Indicate that the temporary
522 -- itself requires debug information. If the renamed entity comes
523 -- from source this is a no-op.
525 Set_Debug_Info_Needed (Entity (Ren));
527 -- Mark the object as internal so that it won't be initialized when
528 -- pragma Initialize_Scalars or Normalize_Scalars is in use.
530 Set_Is_Internal (Obj);
532 return Res;
534 -- If we get an exception, just figure it is a case that we cannot
535 -- successfully handle using our current approach, since this is
536 -- only for debugging, no need to take the compilation with us.
538 exception
539 when others =>
540 return Make_Null_Statement (Loc);
541 end Debug_Renaming_Declaration;
543 -----------------------------
544 -- Is_Handled_Scale_Factor --
545 -----------------------------
547 function Is_Handled_Scale_Factor (U : Ureal) return Boolean is
548 begin
549 -- Keep in sync with gigi (see E_*_Fixed_Point_Type handling in
550 -- decl.c:gnat_to_gnu_entity).
552 if UI_Eq (Numerator (U), Uint_1) then
553 if Rbase (U) = 2 or else Rbase (U) = 10 then
554 return True;
555 end if;
556 end if;
558 return
559 (UI_Is_In_Int_Range (Norm_Num (U))
560 and then
561 UI_Is_In_Int_Range (Norm_Den (U)));
562 end Is_Handled_Scale_Factor;
564 ----------------------
565 -- Get_Encoded_Name --
566 ----------------------
568 -- Note: see spec for details on encodings
570 procedure Get_Encoded_Name (E : Entity_Id) is
571 Has_Suffix : Boolean;
573 begin
574 -- If not generating code, there is no need to create encoded names, and
575 -- problems when the back-end is called to annotate types without full
576 -- code generation. See comments in Get_External_Name for additional
577 -- details.
579 -- However we do create encoded names if the back end is active, even
580 -- if Operating_Mode got reset. Otherwise any serious error reported
581 -- by the backend calling Error_Msg changes the Compilation_Mode to
582 -- Check_Semantics, which disables the functionality of this routine,
583 -- causing the generation of spurious additional errors.
585 -- Couldn't we just test Original_Operating_Mode here? ???
587 if Operating_Mode /= Generate_Code and then not Generating_Code then
588 return;
589 end if;
591 Get_Name_String (Chars (E));
593 -- Nothing to do if we do not have a type
595 if not Is_Type (E)
597 -- Or if this is an enumeration base type
599 or else (Is_Enumeration_Type (E) and then Is_Base_Type (E))
601 -- Or if this is a dummy type for a renaming
603 or else (Name_Len >= 3 and then
604 Name_Buffer (Name_Len - 2 .. Name_Len) = "_XR")
606 or else (Name_Len >= 4 and then
607 (Name_Buffer (Name_Len - 3 .. Name_Len) = "_XRE"
608 or else
609 Name_Buffer (Name_Len - 3 .. Name_Len) = "_XRP"))
611 -- For all these cases, just return the name unchanged
613 then
614 Name_Buffer (Name_Len + 1) := ASCII.NUL;
615 return;
616 end if;
618 Has_Suffix := True;
620 -- Fixed-point case: generate GNAT encodings when asked to or when we
621 -- know the back-end will not be able to handle the scale factor.
623 if Is_Fixed_Point_Type (E)
624 and then (GNAT_Encodings /= DWARF_GNAT_Encodings_Minimal
625 or else not Is_Handled_Scale_Factor (Small_Value (E)))
626 then
627 Get_External_Name (E, True, "XF_");
628 Add_Real_To_Buffer (Delta_Value (E));
630 if Small_Value (E) /= Delta_Value (E) then
631 Add_Str_To_Name_Buffer ("_");
632 Add_Real_To_Buffer (Small_Value (E));
633 end if;
635 -- Discrete case where bounds do not match size. Not necessary if we can
636 -- emit standard DWARF.
638 elsif GNAT_Encodings /= DWARF_GNAT_Encodings_Minimal
639 and then Is_Discrete_Type (E)
640 and then not Bounds_Match_Size (E)
641 then
642 declare
643 Lo : constant Node_Id := Type_Low_Bound (E);
644 Hi : constant Node_Id := Type_High_Bound (E);
646 Lo_Con : constant Boolean := Compile_Time_Known_Value (Lo);
647 Hi_Con : constant Boolean := Compile_Time_Known_Value (Hi);
649 Lo_Discr : constant Boolean :=
650 Nkind (Lo) = N_Identifier
651 and then Ekind (Entity (Lo)) = E_Discriminant;
653 Hi_Discr : constant Boolean :=
654 Nkind (Hi) = N_Identifier
655 and then Ekind (Entity (Hi)) = E_Discriminant;
657 Lo_Encode : constant Boolean := Lo_Con or Lo_Discr;
658 Hi_Encode : constant Boolean := Hi_Con or Hi_Discr;
660 Biased : constant Boolean := Has_Biased_Representation (E);
662 begin
663 if Biased then
664 Get_External_Name (E, True, "XB");
665 else
666 Get_External_Name (E, True, "XD");
667 end if;
669 if Lo_Encode or Hi_Encode then
670 if Biased then
671 Add_Str_To_Name_Buffer ("_");
672 else
673 if Lo_Encode then
674 if Hi_Encode then
675 Add_Str_To_Name_Buffer ("LU_");
676 else
677 Add_Str_To_Name_Buffer ("L_");
678 end if;
679 else
680 Add_Str_To_Name_Buffer ("U_");
681 end if;
682 end if;
684 if Lo_Con then
685 Add_Uint_To_Buffer (Expr_Rep_Value (Lo));
686 elsif Lo_Discr then
687 Get_Name_String_And_Append (Chars (Entity (Lo)));
688 end if;
690 if Lo_Encode and Hi_Encode then
691 Add_Str_To_Name_Buffer ("__");
692 end if;
694 if Hi_Con then
695 Add_Uint_To_Buffer (Expr_Rep_Value (Hi));
696 elsif Hi_Discr then
697 Get_Name_String_And_Append (Chars (Entity (Hi)));
698 end if;
699 end if;
700 end;
702 -- For all other cases, the encoded name is the normal type name
704 else
705 Has_Suffix := False;
706 Get_External_Name (E);
707 end if;
709 if Debug_Flag_B and then Has_Suffix then
710 Write_Str ("**** type ");
711 Write_Name (Chars (E));
712 Write_Str (" is encoded as ");
713 Write_Str (Name_Buffer (1 .. Name_Len));
714 Write_Eol;
715 end if;
717 Name_Buffer (Name_Len + 1) := ASCII.NUL;
718 end Get_Encoded_Name;
720 -----------------------
721 -- Get_External_Name --
722 -----------------------
724 procedure Get_External_Name
725 (Entity : Entity_Id;
726 Has_Suffix : Boolean := False;
727 Suffix : String := "")
729 procedure Get_Qualified_Name_And_Append (Entity : Entity_Id);
730 -- Appends fully qualified name of given entity to Name_Buffer
732 -----------------------------------
733 -- Get_Qualified_Name_And_Append --
734 -----------------------------------
736 procedure Get_Qualified_Name_And_Append (Entity : Entity_Id) is
737 begin
738 -- If the entity is a compilation unit, its scope is Standard,
739 -- there is no outer scope, and the no further qualification
740 -- is required.
742 -- If the front end has already computed a fully qualified name,
743 -- then it is also the case that no further qualification is
744 -- required.
746 if Present (Scope (Scope (Entity)))
747 and then not Has_Fully_Qualified_Name (Entity)
748 then
749 Get_Qualified_Name_And_Append (Scope (Entity));
750 Add_Str_To_Name_Buffer ("__");
751 Get_Name_String_And_Append (Chars (Entity));
752 Append_Homonym_Number (Entity);
754 else
755 Get_Name_String_And_Append (Chars (Entity));
756 end if;
757 end Get_Qualified_Name_And_Append;
759 -- Local variables
761 E : Entity_Id := Entity;
763 -- Start of processing for Get_External_Name
765 begin
766 -- If we are not in code generation mode, this procedure may still be
767 -- called from Back_End (more specifically - from gigi for doing type
768 -- representation annotation or some representation-specific checks).
769 -- But in this mode there is no need to mess with external names.
771 -- Furthermore, the call causes difficulties in this case because the
772 -- string representing the homonym number is not correctly reset as a
773 -- part of the call to Output_Homonym_Numbers_Suffix (which is not
774 -- called in gigi).
776 if Operating_Mode /= Generate_Code then
777 return;
778 end if;
780 Reset_Buffers;
782 -- If this is a child unit, we want the child
784 if Nkind (E) = N_Defining_Program_Unit_Name then
785 E := Defining_Identifier (Entity);
786 end if;
788 -- Case of interface name being used
790 if Ekind_In (E, E_Constant,
791 E_Exception,
792 E_Function,
793 E_Procedure,
794 E_Variable)
795 and then Present (Interface_Name (E))
796 and then No (Address_Clause (E))
797 and then not Has_Suffix
798 then
799 Add_String_To_Name_Buffer (Strval (Interface_Name (E)));
801 -- All other cases besides the interface name case
803 else
804 -- If this is a library level subprogram (i.e. a subprogram that is a
805 -- compilation unit other than a subunit), then we prepend _ada_ to
806 -- ensure distinctions required as described in the spec.
808 -- Check explicitly for child units, because those are not flagged
809 -- as Compilation_Units by lib. Should they be ???
811 if Is_Subprogram (E)
812 and then (Is_Compilation_Unit (E) or Is_Child_Unit (E))
813 and then not Has_Suffix
814 then
815 Add_Str_To_Name_Buffer ("_ada_");
816 end if;
818 -- If the entity is a subprogram instance that is not a compilation
819 -- unit, generate the name of the original Ada entity, which is the
820 -- one gdb needs.
822 if Is_Generic_Instance (E)
823 and then Is_Subprogram (E)
824 and then not Is_Compilation_Unit (Scope (E))
825 and then Ekind_In (Scope (E), E_Package, E_Package_Body)
826 and then Present (Related_Instance (Scope (E)))
827 then
828 E := Related_Instance (Scope (E));
829 end if;
831 Get_Qualified_Name_And_Append (E);
832 end if;
834 if Has_Suffix then
835 Add_Str_To_Name_Buffer ("___");
836 Add_Str_To_Name_Buffer (Suffix);
837 end if;
839 Name_Buffer (Name_Len + 1) := ASCII.NUL;
840 end Get_External_Name;
842 --------------------------
843 -- Get_Variant_Encoding --
844 --------------------------
846 procedure Get_Variant_Encoding (V : Node_Id) is
847 Choice : Node_Id;
849 procedure Choice_Val (Typ : Character; Choice : Node_Id);
850 -- Output encoded value for a single choice value. Typ is the key
851 -- character ('S', 'F', or 'T') that precedes the choice value.
853 ----------------
854 -- Choice_Val --
855 ----------------
857 procedure Choice_Val (Typ : Character; Choice : Node_Id) is
858 begin
859 if Nkind (Choice) = N_Integer_Literal then
860 Add_Char_To_Name_Buffer (Typ);
861 Add_Uint_To_Buffer (Intval (Choice));
863 -- Character literal with no entity present (this is the case
864 -- Standard.Character or Standard.Wide_Character as root type)
866 elsif Nkind (Choice) = N_Character_Literal
867 and then No (Entity (Choice))
868 then
869 Add_Char_To_Name_Buffer (Typ);
870 Add_Uint_To_Buffer (Char_Literal_Value (Choice));
872 else
873 declare
874 Ent : constant Entity_Id := Entity (Choice);
876 begin
877 if Ekind (Ent) = E_Enumeration_Literal then
878 Add_Char_To_Name_Buffer (Typ);
879 Add_Uint_To_Buffer (Enumeration_Rep (Ent));
881 else
882 pragma Assert (Ekind (Ent) = E_Constant);
883 Choice_Val (Typ, Constant_Value (Ent));
884 end if;
885 end;
886 end if;
887 end Choice_Val;
889 -- Start of processing for Get_Variant_Encoding
891 begin
892 Name_Len := 0;
894 Choice := First (Discrete_Choices (V));
895 while Present (Choice) loop
896 if Nkind (Choice) = N_Others_Choice then
897 Add_Char_To_Name_Buffer ('O');
899 elsif Nkind (Choice) = N_Range then
900 Choice_Val ('R', Low_Bound (Choice));
901 Choice_Val ('T', High_Bound (Choice));
903 elsif Is_Entity_Name (Choice)
904 and then Is_Type (Entity (Choice))
905 then
906 Choice_Val ('R', Type_Low_Bound (Entity (Choice)));
907 Choice_Val ('T', Type_High_Bound (Entity (Choice)));
909 elsif Nkind (Choice) = N_Subtype_Indication then
910 declare
911 Rang : constant Node_Id :=
912 Range_Expression (Constraint (Choice));
913 begin
914 Choice_Val ('R', Low_Bound (Rang));
915 Choice_Val ('T', High_Bound (Rang));
916 end;
918 else
919 Choice_Val ('S', Choice);
920 end if;
922 Next (Choice);
923 end loop;
925 Name_Buffer (Name_Len + 1) := ASCII.NUL;
927 if Debug_Flag_B then
928 declare
929 VP : constant Node_Id := Parent (V); -- Variant_Part
930 CL : constant Node_Id := Parent (VP); -- Component_List
931 RD : constant Node_Id := Parent (CL); -- Record_Definition
932 FT : constant Node_Id := Parent (RD); -- Full_Type_Declaration
934 begin
935 Write_Str ("**** variant for type ");
936 Write_Name (Chars (Defining_Identifier (FT)));
937 Write_Str (" is encoded as ");
938 Write_Str (Name_Buffer (1 .. Name_Len));
939 Write_Eol;
940 end;
941 end if;
942 end Get_Variant_Encoding;
944 -----------------------------------------
945 -- Build_Subprogram_Instance_Renamings --
946 -----------------------------------------
948 procedure Build_Subprogram_Instance_Renamings
949 (N : Node_Id;
950 Wrapper : Entity_Id)
952 Loc : Source_Ptr;
953 Decl : Node_Id;
954 E : Entity_Id;
956 begin
957 E := First_Entity (Wrapper);
958 while Present (E) loop
959 if Nkind (Parent (E)) = N_Object_Declaration
960 and then Is_Elementary_Type (Etype (E))
961 then
962 Loc := Sloc (Expression (Parent (E)));
963 Decl := Make_Object_Renaming_Declaration (Loc,
964 Defining_Identifier =>
965 Make_Defining_Identifier (Loc, Chars (E)),
966 Subtype_Mark => New_Occurrence_Of (Etype (E), Loc),
967 Name => New_Occurrence_Of (E, Loc));
969 Append (Decl, Declarations (N));
970 Set_Needs_Debug_Info (Defining_Identifier (Decl));
971 end if;
973 Next_Entity (E);
974 end loop;
975 end Build_Subprogram_Instance_Renamings;
977 ------------------------------------
978 -- Get_Secondary_DT_External_Name --
979 ------------------------------------
981 procedure Get_Secondary_DT_External_Name
982 (Typ : Entity_Id;
983 Ancestor_Typ : Entity_Id;
984 Suffix_Index : Int)
986 begin
987 Get_External_Name (Typ);
989 if Ancestor_Typ /= Typ then
990 declare
991 Len : constant Natural := Name_Len;
992 Save_Str : constant String (1 .. Name_Len)
993 := Name_Buffer (1 .. Name_Len);
994 begin
995 Get_External_Name (Ancestor_Typ);
997 -- Append the extended name of the ancestor to the
998 -- extended name of Typ
1000 Name_Buffer (Len + 2 .. Len + Name_Len + 1) :=
1001 Name_Buffer (1 .. Name_Len);
1002 Name_Buffer (1 .. Len) := Save_Str;
1003 Name_Buffer (Len + 1) := '_';
1004 Name_Len := Len + Name_Len + 1;
1005 end;
1006 end if;
1008 Add_Nat_To_Name_Buffer (Suffix_Index);
1009 end Get_Secondary_DT_External_Name;
1011 ---------------------------------
1012 -- Make_Packed_Array_Impl_Type_Name --
1013 ---------------------------------
1015 function Make_Packed_Array_Impl_Type_Name
1016 (Typ : Entity_Id;
1017 Csize : Uint)
1018 return Name_Id
1020 begin
1021 Get_Name_String (Chars (Typ));
1022 Add_Str_To_Name_Buffer ("___XP");
1023 Add_Uint_To_Buffer (Csize);
1024 return Name_Find;
1025 end Make_Packed_Array_Impl_Type_Name;
1027 -----------------------------------
1028 -- Output_Homonym_Numbers_Suffix --
1029 -----------------------------------
1031 procedure Output_Homonym_Numbers_Suffix is
1032 J : Natural;
1034 begin
1035 if Homonym_Len > 0 then
1037 -- Check for all 1's, in which case we do not output
1039 J := 1;
1040 loop
1041 exit when Homonym_Numbers (J) /= '1';
1043 -- If we reached end of string we do not output
1045 if J = Homonym_Len then
1046 Homonym_Len := 0;
1047 return;
1048 end if;
1050 exit when Homonym_Numbers (J + 1) /= '_';
1051 J := J + 2;
1052 end loop;
1054 -- If we exit the loop then suffix must be output
1056 Add_Str_To_Name_Buffer ("__");
1057 Add_Str_To_Name_Buffer (Homonym_Numbers (1 .. Homonym_Len));
1058 Homonym_Len := 0;
1059 end if;
1060 end Output_Homonym_Numbers_Suffix;
1062 ------------------------------
1063 -- Prepend_String_To_Buffer --
1064 ------------------------------
1066 procedure Prepend_String_To_Buffer (S : String) is
1067 N : constant Integer := S'Length;
1068 begin
1069 Name_Buffer (1 + N .. Name_Len + N) := Name_Buffer (1 .. Name_Len);
1070 Name_Buffer (1 .. N) := S;
1071 Name_Len := Name_Len + N;
1072 end Prepend_String_To_Buffer;
1074 ----------------------------
1075 -- Prepend_Uint_To_Buffer --
1076 ----------------------------
1078 procedure Prepend_Uint_To_Buffer (U : Uint) is
1079 begin
1080 if U < 0 then
1081 Prepend_String_To_Buffer ("m");
1082 Prepend_Uint_To_Buffer (-U);
1083 else
1084 UI_Image (U, Decimal);
1085 Prepend_String_To_Buffer (UI_Image_Buffer (1 .. UI_Image_Length));
1086 end if;
1087 end Prepend_Uint_To_Buffer;
1089 ------------------------------
1090 -- Qualify_All_Entity_Names --
1091 ------------------------------
1093 procedure Qualify_All_Entity_Names is
1094 E : Entity_Id;
1095 Ent : Entity_Id;
1096 Nod : Node_Id;
1098 begin
1099 for J in Name_Qualify_Units.First .. Name_Qualify_Units.Last loop
1100 Nod := Name_Qualify_Units.Table (J);
1102 -- When a scoping construct is ignored Ghost, it is rewritten as
1103 -- a null statement. Skip such constructs as they no longer carry
1104 -- names.
1106 if Nkind (Nod) = N_Null_Statement then
1107 goto Continue;
1108 end if;
1110 E := Defining_Entity (Nod);
1111 Reset_Buffers;
1112 Qualify_Entity_Name (E);
1114 -- Normally entities in the qualification list are scopes, but in the
1115 -- case of a library-level package renaming there is an associated
1116 -- variable that encodes the debugger name and that variable is
1117 -- entered in the list since it occurs in the Aux_Decls list of the
1118 -- compilation and doesn't have a normal scope.
1120 if Ekind (E) /= E_Variable then
1121 Ent := First_Entity (E);
1122 while Present (Ent) loop
1123 Reset_Buffers;
1124 Qualify_Entity_Name (Ent);
1125 Next_Entity (Ent);
1127 -- There are odd cases where Last_Entity (E) = E. This happens
1128 -- in the case of renaming of packages. This test avoids
1129 -- getting stuck in such cases.
1131 exit when Ent = E;
1132 end loop;
1133 end if;
1135 <<Continue>>
1136 null;
1137 end loop;
1138 end Qualify_All_Entity_Names;
1140 -------------------------
1141 -- Qualify_Entity_Name --
1142 -------------------------
1144 procedure Qualify_Entity_Name (Ent : Entity_Id) is
1146 Full_Qualify_Name : String (1 .. Name_Buffer'Length);
1147 Full_Qualify_Len : Natural := 0;
1148 -- Used to accumulate fully qualified name of subprogram
1150 procedure Fully_Qualify_Name (E : Entity_Id);
1151 -- Used to qualify a subprogram or type name, where full
1152 -- qualification up to Standard is always used. Name is set
1153 -- in Full_Qualify_Name with the length in Full_Qualify_Len.
1154 -- Note that this routine does not prepend the _ada_ string
1155 -- required for library subprograms (this is done in the back end).
1157 function Is_BNPE (S : Entity_Id) return Boolean;
1158 -- Determines if S is a BNPE, i.e. Body-Nested Package Entity, which
1159 -- is defined to be a package which is immediately nested within a
1160 -- package body.
1162 function Qualify_Needed (S : Entity_Id) return Boolean;
1163 -- Given a scope, determines if the scope is to be included in the
1164 -- fully qualified name, True if so, False if not. Blocks and loops
1165 -- are excluded from a qualified name.
1167 procedure Set_BNPE_Suffix (E : Entity_Id);
1168 -- Recursive routine to append the BNPE qualification suffix. Works
1169 -- from right to left with E being the current entity in the list.
1170 -- The result does NOT have the trailing n's and trailing b stripped.
1171 -- The caller must do this required stripping.
1173 procedure Set_Entity_Name (E : Entity_Id);
1174 -- Internal recursive routine that does most of the work. This routine
1175 -- leaves the result sitting in Name_Buffer and Name_Len.
1177 BNPE_Suffix_Needed : Boolean := False;
1178 -- Set true if a body-nested package entity suffix is required
1180 Save_Chars : constant Name_Id := Chars (Ent);
1181 -- Save original name
1183 ------------------------
1184 -- Fully_Qualify_Name --
1185 ------------------------
1187 procedure Fully_Qualify_Name (E : Entity_Id) is
1188 Discard : Boolean := False;
1190 begin
1191 -- Ignore empty entry (can happen in error cases)
1193 if No (E) then
1194 return;
1196 -- If this we are qualifying entities local to a generic instance,
1197 -- use the name of the original instantiation, not that of the
1198 -- anonymous subprogram in the wrapper package, so that gdb doesn't
1199 -- have to know about these.
1201 elsif Is_Generic_Instance (E)
1202 and then Is_Subprogram (E)
1203 and then not Comes_From_Source (E)
1204 and then not Is_Compilation_Unit (Scope (E))
1205 then
1206 Fully_Qualify_Name (Related_Instance (Scope (E)));
1207 return;
1208 end if;
1210 -- If we reached fully qualified name, then just copy it
1212 if Has_Fully_Qualified_Name (E) then
1213 Get_Name_String (Chars (E));
1214 Strip_Suffixes (Discard);
1215 Full_Qualify_Name (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
1216 Full_Qualify_Len := Name_Len;
1217 Set_Has_Fully_Qualified_Name (Ent);
1219 -- Case of non-fully qualified name
1221 else
1222 if Scope (E) = Standard_Standard then
1223 Set_Has_Fully_Qualified_Name (Ent);
1224 else
1225 Fully_Qualify_Name (Scope (E));
1226 Full_Qualify_Name (Full_Qualify_Len + 1) := '_';
1227 Full_Qualify_Name (Full_Qualify_Len + 2) := '_';
1228 Full_Qualify_Len := Full_Qualify_Len + 2;
1229 end if;
1231 if Has_Qualified_Name (E) then
1232 Get_Unqualified_Name_String (Chars (E));
1233 else
1234 Get_Name_String (Chars (E));
1235 end if;
1237 -- Here we do one step of the qualification
1239 Full_Qualify_Name
1240 (Full_Qualify_Len + 1 .. Full_Qualify_Len + Name_Len) :=
1241 Name_Buffer (1 .. Name_Len);
1242 Full_Qualify_Len := Full_Qualify_Len + Name_Len;
1243 Append_Homonym_Number (E);
1244 end if;
1246 if Is_BNPE (E) then
1247 BNPE_Suffix_Needed := True;
1248 end if;
1249 end Fully_Qualify_Name;
1251 -------------
1252 -- Is_BNPE --
1253 -------------
1255 function Is_BNPE (S : Entity_Id) return Boolean is
1256 begin
1257 return Ekind (S) = E_Package and then Is_Package_Body_Entity (S);
1258 end Is_BNPE;
1260 --------------------
1261 -- Qualify_Needed --
1262 --------------------
1264 function Qualify_Needed (S : Entity_Id) return Boolean is
1265 begin
1266 -- If we got all the way to Standard, then we have certainly
1267 -- fully qualified the name, so set the flag appropriately,
1268 -- and then return False, since we are most certainly done.
1270 if S = Standard_Standard then
1271 Set_Has_Fully_Qualified_Name (Ent, True);
1272 return False;
1274 -- Otherwise figure out if further qualification is required
1276 else
1277 return Is_Subprogram (Ent)
1278 or else Ekind (Ent) = E_Subprogram_Body
1279 or else (Ekind (S) /= E_Block
1280 and then Ekind (S) /= E_Loop
1281 and then not Is_Dynamic_Scope (S));
1282 end if;
1283 end Qualify_Needed;
1285 ---------------------
1286 -- Set_BNPE_Suffix --
1287 ---------------------
1289 procedure Set_BNPE_Suffix (E : Entity_Id) is
1290 S : constant Entity_Id := Scope (E);
1292 begin
1293 if Qualify_Needed (S) then
1294 Set_BNPE_Suffix (S);
1296 if Is_BNPE (E) then
1297 Add_Char_To_Name_Buffer ('b');
1298 else
1299 Add_Char_To_Name_Buffer ('n');
1300 end if;
1302 else
1303 Add_Char_To_Name_Buffer ('X');
1304 end if;
1305 end Set_BNPE_Suffix;
1307 ---------------------
1308 -- Set_Entity_Name --
1309 ---------------------
1311 procedure Set_Entity_Name (E : Entity_Id) is
1312 S : constant Entity_Id := Scope (E);
1314 begin
1315 -- If we reach an already qualified name, just take the encoding
1316 -- except that we strip the package body suffixes, since these
1317 -- will be separately put on later.
1319 if Has_Qualified_Name (E) then
1320 Get_Name_String_And_Append (Chars (E));
1321 Strip_Suffixes (BNPE_Suffix_Needed);
1323 -- If the top level name we are adding is itself fully
1324 -- qualified, then that means that the name that we are
1325 -- preparing for the Fully_Qualify_Name call will also
1326 -- generate a fully qualified name.
1328 if Has_Fully_Qualified_Name (E) then
1329 Set_Has_Fully_Qualified_Name (Ent);
1330 end if;
1332 -- Case where upper level name is not encoded yet
1334 else
1335 -- Recurse if further qualification required
1337 if Qualify_Needed (S) then
1338 Set_Entity_Name (S);
1339 Add_Str_To_Name_Buffer ("__");
1340 end if;
1342 -- Otherwise get name and note if it is a BNPE
1344 Get_Name_String_And_Append (Chars (E));
1346 if Is_BNPE (E) then
1347 BNPE_Suffix_Needed := True;
1348 end if;
1350 Append_Homonym_Number (E);
1351 end if;
1352 end Set_Entity_Name;
1354 -- Start of processing for Qualify_Entity_Name
1356 begin
1357 if Has_Qualified_Name (Ent) then
1358 return;
1360 -- In formal verification mode, simply append a suffix for homonyms.
1361 -- We used to qualify entity names as full expansion does, but this was
1362 -- removed as this prevents the verification back-end from using a short
1363 -- name for debugging and user interaction. The verification back-end
1364 -- already takes care of qualifying names when needed. Still mark the
1365 -- name as being qualified, as Qualify_Entity_Name may be called more
1366 -- than once on the same entity.
1368 elsif GNATprove_Mode then
1369 if Has_Homonym (Ent) then
1370 Get_Name_String (Chars (Ent));
1371 Append_Homonym_Number (Ent);
1372 Output_Homonym_Numbers_Suffix;
1373 Set_Chars (Ent, Name_Enter);
1374 end if;
1376 Set_Has_Qualified_Name (Ent);
1377 return;
1379 -- If the entity is a variable encoding the debug name for an object
1380 -- renaming, then the qualified name of the entity associated with the
1381 -- renamed object can now be incorporated in the debug name.
1383 elsif Ekind (Ent) = E_Variable
1384 and then Present (Debug_Renaming_Link (Ent))
1385 then
1386 Name_Len := 0;
1387 Qualify_Entity_Name (Debug_Renaming_Link (Ent));
1388 Get_Name_String (Chars (Ent));
1390 -- Retrieve the now-qualified name of the renamed entity and insert
1391 -- it in the middle of the name, just preceding the suffix encoding
1392 -- describing the renamed object.
1394 declare
1395 Renamed_Id : constant String :=
1396 Get_Name_String (Chars (Debug_Renaming_Link (Ent)));
1397 Insert_Len : constant Integer := Renamed_Id'Length + 1;
1398 Index : Natural := Name_Len - 3;
1400 begin
1401 -- Loop backwards through the name to find the start of the "___"
1402 -- sequence associated with the suffix.
1404 while Index >= Name_Buffer'First
1405 and then (Name_Buffer (Index + 1) /= '_'
1406 or else Name_Buffer (Index + 2) /= '_'
1407 or else Name_Buffer (Index + 3) /= '_')
1408 loop
1409 Index := Index - 1;
1410 end loop;
1412 pragma Assert (Name_Buffer (Index + 1 .. Index + 3) = "___");
1414 -- Insert an underscore separator and the entity name just in
1415 -- front of the suffix.
1417 Name_Buffer (Index + 1 + Insert_Len .. Name_Len + Insert_Len) :=
1418 Name_Buffer (Index + 1 .. Name_Len);
1419 Name_Buffer (Index + 1) := '_';
1420 Name_Buffer (Index + 2 .. Index + Insert_Len) := Renamed_Id;
1421 Name_Len := Name_Len + Insert_Len;
1422 end;
1424 -- Reset the name of the variable to the new name that includes the
1425 -- name of the renamed entity.
1427 Set_Chars (Ent, Name_Enter);
1429 -- If the entity needs qualification by its scope then develop it
1430 -- here, add the variable's name, and again reset the entity name.
1432 if Qualify_Needed (Scope (Ent)) then
1433 Name_Len := 0;
1434 Set_Entity_Name (Scope (Ent));
1435 Add_Str_To_Name_Buffer ("__");
1437 Get_Name_String_And_Append (Chars (Ent));
1439 Set_Chars (Ent, Name_Enter);
1440 end if;
1442 Set_Has_Qualified_Name (Ent);
1443 return;
1445 elsif Is_Subprogram (Ent)
1446 or else Ekind (Ent) = E_Subprogram_Body
1447 or else Is_Type (Ent)
1448 then
1449 Fully_Qualify_Name (Ent);
1450 Name_Len := Full_Qualify_Len;
1451 Name_Buffer (1 .. Name_Len) := Full_Qualify_Name (1 .. Name_Len);
1453 -- Qualification needed for enumeration literals when generating C code
1454 -- (to simplify their management in the backend).
1456 elsif Generate_C_Code
1457 and then Ekind (Ent) = E_Enumeration_Literal
1458 and then Scope (Ultimate_Alias (Ent)) /= Standard_Standard
1459 then
1460 Fully_Qualify_Name (Ent);
1461 Name_Len := Full_Qualify_Len;
1462 Name_Buffer (1 .. Name_Len) := Full_Qualify_Name (1 .. Name_Len);
1464 elsif Qualify_Needed (Scope (Ent)) then
1465 Name_Len := 0;
1466 Set_Entity_Name (Ent);
1468 else
1469 Set_Has_Qualified_Name (Ent);
1471 -- If a variable is hidden by a subsequent loop variable, qualify
1472 -- the name of that loop variable to prevent visibility issues when
1473 -- translating to C. Note that gdb probably never handled properly
1474 -- this accidental hiding, given that loops are not scopes at
1475 -- runtime. We also qualify a name if it hides an outer homonym,
1476 -- and both are declared in blocks.
1478 if Modify_Tree_For_C and then Ekind (Ent) = E_Variable then
1479 if Present (Hiding_Loop_Variable (Ent)) then
1480 declare
1481 Var : constant Entity_Id := Hiding_Loop_Variable (Ent);
1483 begin
1484 Set_Entity_Name (Var);
1485 Add_Str_To_Name_Buffer ("L");
1486 Set_Chars (Var, Name_Enter);
1487 end;
1489 elsif Present (Homonym (Ent))
1490 and then Ekind (Scope (Ent)) = E_Block
1491 and then Ekind (Scope (Homonym (Ent))) = E_Block
1492 then
1493 Set_Entity_Name (Ent);
1494 Add_Str_To_Name_Buffer ("B");
1495 Set_Chars (Ent, Name_Enter);
1496 end if;
1497 end if;
1499 return;
1500 end if;
1502 -- Fall through with a fully qualified name in Name_Buffer/Name_Len
1504 Output_Homonym_Numbers_Suffix;
1506 -- Add body-nested package suffix if required
1508 if BNPE_Suffix_Needed
1509 and then Ekind (Ent) /= E_Enumeration_Literal
1510 then
1511 Set_BNPE_Suffix (Ent);
1513 -- Strip trailing n's and last trailing b as required. note that
1514 -- we know there is at least one b, or no suffix would be generated.
1516 while Name_Buffer (Name_Len) = 'n' loop
1517 Name_Len := Name_Len - 1;
1518 end loop;
1520 Name_Len := Name_Len - 1;
1521 end if;
1523 Set_Chars (Ent, Name_Enter);
1524 Set_Has_Qualified_Name (Ent);
1526 if Debug_Flag_BB then
1527 Write_Str ("*** ");
1528 Write_Name (Save_Chars);
1529 Write_Str (" qualified as ");
1530 Write_Name (Chars (Ent));
1531 Write_Eol;
1532 end if;
1533 end Qualify_Entity_Name;
1535 --------------------------
1536 -- Qualify_Entity_Names --
1537 --------------------------
1539 procedure Qualify_Entity_Names (N : Node_Id) is
1540 begin
1541 Name_Qualify_Units.Append (N);
1542 end Qualify_Entity_Names;
1544 -------------------
1545 -- Reset_Buffers --
1546 -------------------
1548 procedure Reset_Buffers is
1549 begin
1550 Name_Len := 0;
1551 Homonym_Len := 0;
1552 end Reset_Buffers;
1554 --------------------
1555 -- Strip_Suffixes --
1556 --------------------
1558 procedure Strip_Suffixes (BNPE_Suffix_Found : in out Boolean) is
1559 SL : Natural;
1561 pragma Warnings (Off, BNPE_Suffix_Found);
1562 -- Since this procedure only ever sets the flag
1564 begin
1565 -- Search for and strip BNPE suffix
1567 for J in reverse 2 .. Name_Len loop
1568 if Name_Buffer (J) = 'X' then
1569 Name_Len := J - 1;
1570 BNPE_Suffix_Found := True;
1571 exit;
1572 end if;
1574 exit when Name_Buffer (J) /= 'b' and then Name_Buffer (J) /= 'n';
1575 end loop;
1577 -- Search for and strip homonym numbers suffix
1579 for J in reverse 2 .. Name_Len - 2 loop
1580 if Name_Buffer (J) = '_'
1581 and then Name_Buffer (J + 1) = '_'
1582 then
1583 if Name_Buffer (J + 2) in '0' .. '9' then
1584 if Homonym_Len > 0 then
1585 Homonym_Len := Homonym_Len + 1;
1586 Homonym_Numbers (Homonym_Len) := '-';
1587 end if;
1589 SL := Name_Len - (J + 1);
1591 Homonym_Numbers (Homonym_Len + 1 .. Homonym_Len + SL) :=
1592 Name_Buffer (J + 2 .. Name_Len);
1593 Name_Len := J - 1;
1594 Homonym_Len := Homonym_Len + SL;
1595 end if;
1597 exit;
1598 end if;
1599 end loop;
1600 end Strip_Suffixes;
1602 end Exp_Dbug;