2014-12-12 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / ada / exp_dbug.adb
blob80bf4ed235a77b3aeb6b62626e9ce38de96ffaa6
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-2014, 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 Targparm; use Targparm;
42 with Tbuild; use Tbuild;
43 with Urealp; use Urealp;
45 package body Exp_Dbug is
47 -- The following table is used to queue up the entities passed as
48 -- arguments to Qualify_Entity_Names for later processing when
49 -- Qualify_All_Entity_Names is called.
51 package Name_Qualify_Units is new Table.Table (
52 Table_Component_Type => Node_Id,
53 Table_Index_Type => Nat,
54 Table_Low_Bound => 1,
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
66 -- Has_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
77 -- the case.
79 -- Consider the following example:
81 -- with ...
82 -- procedure X is
83 -- B : Ddd.Ttt;
84 -- procedure Y is ..
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
102 -- qualification.
104 --------------------
105 -- Homonym_Suffix --
106 --------------------
108 -- The string defined here (and its associated length) is used to gather
109 -- the homonym string that will be appended to Name_Buffer when the name
110 -- is complete. Strip_Suffixes appends to this string as does
111 -- Append_Homonym_Number, and Output_Homonym_Numbers_Suffix appends the
112 -- string to the end of Name_Buffer.
114 Homonym_Numbers : String (1 .. 256);
115 Homonym_Len : Natural := 0;
117 ----------------------
118 -- Local Procedures --
119 ----------------------
121 procedure Add_Uint_To_Buffer (U : Uint);
122 -- Add image of universal integer to Name_Buffer, updating Name_Len
124 procedure Add_Real_To_Buffer (U : Ureal);
125 -- Add nnn_ddd to Name_Buffer, where nnn and ddd are integer values of
126 -- the normalized numerator and denominator of the given real value.
128 procedure Append_Homonym_Number (E : Entity_Id);
129 -- If the entity E has homonyms in the same scope, then make an entry
130 -- in the Homonym_Numbers array, bumping Homonym_Count accordingly.
132 function Bounds_Match_Size (E : Entity_Id) return Boolean;
133 -- Determine whether the bounds of E match the size of the type. This is
134 -- used to determine whether encoding is required for a discrete type.
136 function Is_Handled_Scale_Factor (U : Ureal) return Boolean;
137 -- The argument U is the Small_Value of a fixed-point type. This function
138 -- determines whether the back-end can handle this scale factor. When it
139 -- cannot, we have to output a GNAT encoding for the corresponding type.
141 procedure Output_Homonym_Numbers_Suffix;
142 -- If homonym numbers are stored, then output them into Name_Buffer
144 procedure Prepend_String_To_Buffer (S : String);
145 -- Prepend given string to the contents of the string buffer, updating
146 -- the value in Name_Len (i.e. string is added at start of buffer).
148 procedure Prepend_Uint_To_Buffer (U : Uint);
149 -- Prepend image of universal integer to Name_Buffer, updating Name_Len
151 procedure Qualify_Entity_Name (Ent : Entity_Id);
152 -- If not already done, replaces the Chars field of the given entity
153 -- with the appropriate fully qualified name.
155 procedure Reset_Buffers;
156 -- Reset the contents of Name_Buffer and Homonym_Numbers by setting their
157 -- respective lengths to zero.
159 procedure Strip_Suffixes (BNPE_Suffix_Found : in out Boolean);
160 -- Given an qualified entity name in Name_Buffer, remove any plain X or
161 -- X{nb} qualification suffix. The contents of Name_Buffer is not changed
162 -- but Name_Len may be adjusted on return to remove the suffix. If a
163 -- BNPE suffix is found and stripped, then BNPE_Suffix_Found is set to
164 -- True. If no suffix is found, then BNPE_Suffix_Found is not modified.
165 -- This routine also searches for a homonym suffix, and if one is found
166 -- it is also stripped, and the entries are added to the global homonym
167 -- list (Homonym_Numbers) so that they can later be put back.
169 ------------------------
170 -- Add_Real_To_Buffer --
171 ------------------------
173 procedure Add_Real_To_Buffer (U : Ureal) is
174 begin
175 Add_Uint_To_Buffer (Norm_Num (U));
176 Add_Str_To_Name_Buffer ("_");
177 Add_Uint_To_Buffer (Norm_Den (U));
178 end Add_Real_To_Buffer;
180 ------------------------
181 -- Add_Uint_To_Buffer --
182 ------------------------
184 procedure Add_Uint_To_Buffer (U : Uint) is
185 begin
186 if U < 0 then
187 Add_Uint_To_Buffer (-U);
188 Add_Char_To_Name_Buffer ('m');
189 else
190 UI_Image (U, Decimal);
191 Add_Str_To_Name_Buffer (UI_Image_Buffer (1 .. UI_Image_Length));
192 end if;
193 end Add_Uint_To_Buffer;
195 ---------------------------
196 -- Append_Homonym_Number --
197 ---------------------------
199 procedure Append_Homonym_Number (E : Entity_Id) is
201 procedure Add_Nat_To_H (Nr : Nat);
202 -- Little procedure to append Nr to Homonym_Numbers
204 ------------------
205 -- Add_Nat_To_H --
206 ------------------
208 procedure Add_Nat_To_H (Nr : Nat) is
209 begin
210 if Nr >= 10 then
211 Add_Nat_To_H (Nr / 10);
212 end if;
214 Homonym_Len := Homonym_Len + 1;
215 Homonym_Numbers (Homonym_Len) :=
216 Character'Val (Nr mod 10 + Character'Pos ('0'));
217 end Add_Nat_To_H;
219 -- Start of processing for Append_Homonym_Number
221 begin
222 if Has_Homonym (E) then
223 declare
224 H : Entity_Id := Homonym (E);
225 Nr : Nat := 1;
227 begin
228 while Present (H) loop
229 if Scope (H) = Scope (E) then
230 Nr := Nr + 1;
231 end if;
233 H := Homonym (H);
234 end loop;
236 if Homonym_Len > 0 then
237 Homonym_Len := Homonym_Len + 1;
238 Homonym_Numbers (Homonym_Len) := '_';
239 end if;
241 Add_Nat_To_H (Nr);
242 end;
243 end if;
244 end Append_Homonym_Number;
246 -----------------------
247 -- Bounds_Match_Size --
248 -----------------------
250 function Bounds_Match_Size (E : Entity_Id) return Boolean is
251 Siz : Uint;
253 begin
254 if not Is_OK_Static_Subtype (E) then
255 return False;
257 elsif Is_Integer_Type (E)
258 and then Subtypes_Statically_Match (E, Base_Type (E))
259 then
260 return True;
262 -- Here we check if the static bounds match the natural size, which is
263 -- the size passed through with the debugging information. This is the
264 -- Esize rounded up to 8, 16, 32 or 64 as appropriate.
266 else
267 declare
268 Umark : constant Uintp.Save_Mark := Uintp.Mark;
269 Result : Boolean;
271 begin
272 if Esize (E) <= 8 then
273 Siz := Uint_8;
274 elsif Esize (E) <= 16 then
275 Siz := Uint_16;
276 elsif Esize (E) <= 32 then
277 Siz := Uint_32;
278 else
279 Siz := Uint_64;
280 end if;
282 if Is_Modular_Integer_Type (E) or else Is_Enumeration_Type (E) then
283 Result :=
284 Expr_Rep_Value (Type_Low_Bound (E)) = 0
285 and then
286 2 ** Siz - Expr_Rep_Value (Type_High_Bound (E)) = 1;
288 else
289 Result :=
290 Expr_Rep_Value (Type_Low_Bound (E)) + 2 ** (Siz - 1) = 0
291 and then
292 2 ** (Siz - 1) - Expr_Rep_Value (Type_High_Bound (E)) = 1;
293 end if;
295 Release (Umark);
296 return Result;
297 end;
298 end if;
299 end Bounds_Match_Size;
301 --------------------------------
302 -- Debug_Renaming_Declaration --
303 --------------------------------
305 function Debug_Renaming_Declaration (N : Node_Id) return Node_Id is
306 Loc : constant Source_Ptr := Sloc (N);
307 Ent : constant Node_Id := Defining_Entity (N);
308 Nam : constant Node_Id := Name (N);
309 Ren : Node_Id;
310 Typ : Entity_Id;
311 Obj : Entity_Id;
312 Res : Node_Id;
314 Enable : Boolean := Nkind (N) = N_Package_Renaming_Declaration;
315 -- By default, we do not generate an encoding for renaming. This is
316 -- however done (in which case this is set to True) in a few cases:
317 -- - when a package is renamed,
318 -- - when the renaming involves a packed array,
319 -- - when the renaming involves a packed record.
321 procedure Enable_If_Packed_Array (N : Node_Id);
322 -- Enable encoding generation if N is a packed array
324 function Output_Subscript (N : Node_Id; S : String) return Boolean;
325 -- Outputs a single subscript value as ?nnn (subscript is compile time
326 -- known value with value nnn) or as ?e (subscript is local constant
327 -- with name e), where S supplies the proper string to use for ?.
328 -- Returns False if the subscript is not of an appropriate type to
329 -- output in one of these two forms. The result is prepended to the
330 -- name stored in Name_Buffer.
332 ----------------------------
333 -- Enable_If_Packed_Array --
334 ----------------------------
336 procedure Enable_If_Packed_Array (N : Node_Id) is
337 T : constant Entity_Id := Etype (N);
338 begin
339 Enable :=
340 Enable or else (Ekind (T) in Array_Kind
341 and then Present (Packed_Array_Impl_Type (T)));
342 end Enable_If_Packed_Array;
344 ----------------------
345 -- Output_Subscript --
346 ----------------------
348 function Output_Subscript (N : Node_Id; S : String) return Boolean is
349 begin
350 if Compile_Time_Known_Value (N) then
351 Prepend_Uint_To_Buffer (Expr_Value (N));
353 elsif Nkind (N) = N_Identifier
354 and then Scope (Entity (N)) = Scope (Ent)
355 and then Ekind (Entity (N)) = E_Constant
356 then
357 Prepend_String_To_Buffer (Get_Name_String (Chars (Entity (N))));
359 else
360 return False;
361 end if;
363 Prepend_String_To_Buffer (S);
364 return True;
365 end Output_Subscript;
367 -- Start of processing for Debug_Renaming_Declaration
369 begin
370 if not Comes_From_Source (N)
371 and then not Needs_Debug_Info (Ent)
372 then
373 return Empty;
374 end if;
376 -- Do not output those local variables in VM case, as this does not
377 -- help debugging (they are just unused), and might lead to duplicated
378 -- local variable names.
380 if VM_Target /= No_VM then
381 return Empty;
382 end if;
384 -- Get renamed entity and compute suffix
386 Name_Len := 0;
387 Ren := Nam;
388 loop
389 case Nkind (Ren) is
391 when N_Identifier =>
392 exit;
394 when N_Expanded_Name =>
396 -- The entity field for an N_Expanded_Name is on the expanded
397 -- name node itself, so we are done here too.
399 exit;
401 when N_Selected_Component =>
402 Enable := Enable or else Is_Packed (Etype (Prefix (Ren)));
403 Prepend_String_To_Buffer
404 (Get_Name_String (Chars (Selector_Name (Ren))));
405 Prepend_String_To_Buffer ("XR");
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
588 and then not Generating_Code
589 then
590 return;
591 end if;
593 Get_Name_String (Chars (E));
595 -- Nothing to do if we do not have a type
597 if not Is_Type (E)
599 -- Or if this is an enumeration base type
601 or else (Is_Enumeration_Type (E) and then Is_Base_Type (E))
603 -- Or if this is a dummy type for a renaming
605 or else (Name_Len >= 3 and then
606 Name_Buffer (Name_Len - 2 .. Name_Len) = "_XR")
608 or else (Name_Len >= 4 and then
609 (Name_Buffer (Name_Len - 3 .. Name_Len) = "_XRE"
610 or else
611 Name_Buffer (Name_Len - 3 .. Name_Len) = "_XRP"))
613 -- For all these cases, just return the name unchanged
615 then
616 Name_Buffer (Name_Len + 1) := ASCII.NUL;
617 return;
618 end if;
620 Has_Suffix := True;
622 -- Fixed-point case: generate GNAT encodings when asked to or when we
623 -- know the back-end will not be able to handle the scale factor.
625 if Is_Fixed_Point_Type (E)
626 and then (GNAT_Encodings /= DWARF_GNAT_Encodings_Minimal
627 or else not Is_Handled_Scale_Factor (Small_Value (E)))
628 then
629 Get_External_Name (E, True, "XF_");
630 Add_Real_To_Buffer (Delta_Value (E));
632 if Small_Value (E) /= Delta_Value (E) then
633 Add_Str_To_Name_Buffer ("_");
634 Add_Real_To_Buffer (Small_Value (E));
635 end if;
637 -- Discrete case where bounds do not match size. Match only biased
638 -- types when asked to output as little encodings as possible.
640 elsif ((GNAT_Encodings /= DWARF_GNAT_Encodings_Minimal
641 and then Is_Discrete_Type (E))
642 or else
643 (GNAT_Encodings = DWARF_GNAT_Encodings_Minimal
644 and then Has_Biased_Representation (E)))
645 and then not Bounds_Match_Size (E)
646 then
647 declare
648 Lo : constant Node_Id := Type_Low_Bound (E);
649 Hi : constant Node_Id := Type_High_Bound (E);
651 Lo_Con : constant Boolean := Compile_Time_Known_Value (Lo);
652 Hi_Con : constant Boolean := Compile_Time_Known_Value (Hi);
654 Lo_Discr : constant Boolean :=
655 Nkind (Lo) = N_Identifier
656 and then Ekind (Entity (Lo)) = E_Discriminant;
658 Hi_Discr : constant Boolean :=
659 Nkind (Hi) = N_Identifier
660 and then Ekind (Entity (Hi)) = E_Discriminant;
662 Lo_Encode : constant Boolean := Lo_Con or Lo_Discr;
663 Hi_Encode : constant Boolean := Hi_Con or Hi_Discr;
665 Biased : constant Boolean := Has_Biased_Representation (E);
667 begin
668 if Biased then
669 Get_External_Name (E, True, "XB");
670 else
671 Get_External_Name (E, True, "XD");
672 end if;
674 if Lo_Encode or Hi_Encode then
675 if Biased then
676 Add_Str_To_Name_Buffer ("_");
677 else
678 if Lo_Encode then
679 if Hi_Encode then
680 Add_Str_To_Name_Buffer ("LU_");
681 else
682 Add_Str_To_Name_Buffer ("L_");
683 end if;
684 else
685 Add_Str_To_Name_Buffer ("U_");
686 end if;
687 end if;
689 if Lo_Con then
690 Add_Uint_To_Buffer (Expr_Rep_Value (Lo));
691 elsif Lo_Discr then
692 Get_Name_String_And_Append (Chars (Entity (Lo)));
693 end if;
695 if Lo_Encode and Hi_Encode then
696 Add_Str_To_Name_Buffer ("__");
697 end if;
699 if Hi_Con then
700 Add_Uint_To_Buffer (Expr_Rep_Value (Hi));
701 elsif Hi_Discr then
702 Get_Name_String_And_Append (Chars (Entity (Hi)));
703 end if;
704 end if;
705 end;
707 -- For all other cases, the encoded name is the normal type name
709 else
710 Has_Suffix := False;
711 Get_External_Name (E);
712 end if;
714 if Debug_Flag_B and then Has_Suffix then
715 Write_Str ("**** type ");
716 Write_Name (Chars (E));
717 Write_Str (" is encoded as ");
718 Write_Str (Name_Buffer (1 .. Name_Len));
719 Write_Eol;
720 end if;
722 Name_Buffer (Name_Len + 1) := ASCII.NUL;
723 end Get_Encoded_Name;
725 -----------------------
726 -- Get_External_Name --
727 -----------------------
729 procedure Get_External_Name
730 (Entity : Entity_Id;
731 Has_Suffix : Boolean := False;
732 Suffix : String := "")
734 E : Entity_Id := Entity;
735 Kind : Entity_Kind;
737 procedure Get_Qualified_Name_And_Append (Entity : Entity_Id);
738 -- Appends fully qualified name of given entity to Name_Buffer
740 -----------------------------------
741 -- Get_Qualified_Name_And_Append --
742 -----------------------------------
744 procedure Get_Qualified_Name_And_Append (Entity : Entity_Id) is
745 begin
746 -- If the entity is a compilation unit, its scope is Standard,
747 -- there is no outer scope, and the no further qualification
748 -- is required.
750 -- If the front end has already computed a fully qualified name,
751 -- then it is also the case that no further qualification is
752 -- required.
754 if Present (Scope (Scope (Entity)))
755 and then not Has_Fully_Qualified_Name (Entity)
756 then
757 Get_Qualified_Name_And_Append (Scope (Entity));
758 Add_Str_To_Name_Buffer ("__");
759 Get_Name_String_And_Append (Chars (Entity));
760 Append_Homonym_Number (Entity);
762 else
763 Get_Name_String_And_Append (Chars (Entity));
764 end if;
765 end Get_Qualified_Name_And_Append;
767 -- Start of processing for Get_External_Name
769 begin
770 -- If we are not in code generation mode, this procedure may still be
771 -- called from Back_End (more specifically - from gigi for doing type
772 -- representation annotation or some representation-specific checks).
773 -- But in this mode there is no need to mess with external names.
775 -- Furthermore, the call causes difficulties in this case because the
776 -- string representing the homonym number is not correctly reset as a
777 -- part of the call to Output_Homonym_Numbers_Suffix (which is not
778 -- called in gigi).
780 if Operating_Mode /= Generate_Code then
781 return;
782 end if;
784 Reset_Buffers;
786 -- If this is a child unit, we want the child
788 if Nkind (E) = N_Defining_Program_Unit_Name then
789 E := Defining_Identifier (Entity);
790 end if;
792 Kind := Ekind (E);
794 -- Case of interface name being used
796 if (Kind = E_Procedure or else
797 Kind = E_Function or else
798 Kind = E_Constant or else
799 Kind = E_Variable or else
800 Kind = E_Exception)
801 and then Present (Interface_Name (E))
802 and then No (Address_Clause (E))
803 and then not Has_Suffix
804 then
805 Add_String_To_Name_Buffer (Strval (Interface_Name (E)));
807 -- All other cases besides the interface name case
809 else
810 -- If this is a library level subprogram (i.e. a subprogram that is a
811 -- compilation unit other than a subunit), then we prepend _ada_ to
812 -- ensure distinctions required as described in the spec.
814 -- Check explicitly for child units, because those are not flagged
815 -- as Compilation_Units by lib. Should they be ???
817 if Is_Subprogram (E)
818 and then (Is_Compilation_Unit (E) or Is_Child_Unit (E))
819 and then not Has_Suffix
820 then
821 Add_Str_To_Name_Buffer ("_ada_");
822 end if;
824 -- If the entity is a subprogram instance that is not a compilation
825 -- unit, generate the name of the original Ada entity, which is the
826 -- one gdb needs.
828 if Is_Generic_Instance (E)
829 and then Is_Subprogram (E)
830 and then not Is_Compilation_Unit (Scope (E))
831 and then (Ekind (Scope (E)) = E_Package
832 or else
833 Ekind (Scope (E)) = E_Package_Body)
834 and then Present (Related_Instance (Scope (E)))
835 then
836 E := Related_Instance (Scope (E));
837 end if;
839 Get_Qualified_Name_And_Append (E);
840 end if;
842 if Has_Suffix then
843 Add_Str_To_Name_Buffer ("___");
844 Add_Str_To_Name_Buffer (Suffix);
845 end if;
847 Name_Buffer (Name_Len + 1) := ASCII.NUL;
848 end Get_External_Name;
850 --------------------------
851 -- Get_Variant_Encoding --
852 --------------------------
854 procedure Get_Variant_Encoding (V : Node_Id) is
855 Choice : Node_Id;
857 procedure Choice_Val (Typ : Character; Choice : Node_Id);
858 -- Output encoded value for a single choice value. Typ is the key
859 -- character ('S', 'F', or 'T') that precedes the choice value.
861 ----------------
862 -- Choice_Val --
863 ----------------
865 procedure Choice_Val (Typ : Character; Choice : Node_Id) is
866 begin
867 if Nkind (Choice) = N_Integer_Literal then
868 Add_Char_To_Name_Buffer (Typ);
869 Add_Uint_To_Buffer (Intval (Choice));
871 -- Character literal with no entity present (this is the case
872 -- Standard.Character or Standard.Wide_Character as root type)
874 elsif Nkind (Choice) = N_Character_Literal
875 and then No (Entity (Choice))
876 then
877 Add_Char_To_Name_Buffer (Typ);
878 Add_Uint_To_Buffer (Char_Literal_Value (Choice));
880 else
881 declare
882 Ent : constant Entity_Id := Entity (Choice);
884 begin
885 if Ekind (Ent) = E_Enumeration_Literal then
886 Add_Char_To_Name_Buffer (Typ);
887 Add_Uint_To_Buffer (Enumeration_Rep (Ent));
889 else
890 pragma Assert (Ekind (Ent) = E_Constant);
891 Choice_Val (Typ, Constant_Value (Ent));
892 end if;
893 end;
894 end if;
895 end Choice_Val;
897 -- Start of processing for Get_Variant_Encoding
899 begin
900 Name_Len := 0;
902 Choice := First (Discrete_Choices (V));
903 while Present (Choice) loop
904 if Nkind (Choice) = N_Others_Choice then
905 Add_Char_To_Name_Buffer ('O');
907 elsif Nkind (Choice) = N_Range then
908 Choice_Val ('R', Low_Bound (Choice));
909 Choice_Val ('T', High_Bound (Choice));
911 elsif Is_Entity_Name (Choice)
912 and then Is_Type (Entity (Choice))
913 then
914 Choice_Val ('R', Type_Low_Bound (Entity (Choice)));
915 Choice_Val ('T', Type_High_Bound (Entity (Choice)));
917 elsif Nkind (Choice) = N_Subtype_Indication then
918 declare
919 Rang : constant Node_Id :=
920 Range_Expression (Constraint (Choice));
921 begin
922 Choice_Val ('R', Low_Bound (Rang));
923 Choice_Val ('T', High_Bound (Rang));
924 end;
926 else
927 Choice_Val ('S', Choice);
928 end if;
930 Next (Choice);
931 end loop;
933 Name_Buffer (Name_Len + 1) := ASCII.NUL;
935 if Debug_Flag_B then
936 declare
937 VP : constant Node_Id := Parent (V); -- Variant_Part
938 CL : constant Node_Id := Parent (VP); -- Component_List
939 RD : constant Node_Id := Parent (CL); -- Record_Definition
940 FT : constant Node_Id := Parent (RD); -- Full_Type_Declaration
942 begin
943 Write_Str ("**** variant for type ");
944 Write_Name (Chars (Defining_Identifier (FT)));
945 Write_Str (" is encoded as ");
946 Write_Str (Name_Buffer (1 .. Name_Len));
947 Write_Eol;
948 end;
949 end if;
950 end Get_Variant_Encoding;
952 -----------------------------------------
953 -- Build_Subprogram_Instance_Renamings --
954 -----------------------------------------
956 procedure Build_Subprogram_Instance_Renamings
957 (N : Node_Id;
958 Wrapper : Entity_Id)
960 Loc : Source_Ptr;
961 Decl : Node_Id;
962 E : Entity_Id;
964 begin
965 E := First_Entity (Wrapper);
966 while Present (E) loop
967 if Nkind (Parent (E)) = N_Object_Declaration
968 and then Is_Elementary_Type (Etype (E))
969 then
970 Loc := Sloc (Expression (Parent (E)));
971 Decl := Make_Object_Renaming_Declaration (Loc,
972 Defining_Identifier =>
973 Make_Defining_Identifier (Loc, Chars (E)),
974 Subtype_Mark => New_Occurrence_Of (Etype (E), Loc),
975 Name => New_Occurrence_Of (E, Loc));
977 Append (Decl, Declarations (N));
978 Set_Needs_Debug_Info (Defining_Identifier (Decl));
979 end if;
981 Next_Entity (E);
982 end loop;
983 end Build_Subprogram_Instance_Renamings;
985 ------------------------------------
986 -- Get_Secondary_DT_External_Name --
987 ------------------------------------
989 procedure Get_Secondary_DT_External_Name
990 (Typ : Entity_Id;
991 Ancestor_Typ : Entity_Id;
992 Suffix_Index : Int)
994 begin
995 Get_External_Name (Typ);
997 if Ancestor_Typ /= Typ then
998 declare
999 Len : constant Natural := Name_Len;
1000 Save_Str : constant String (1 .. Name_Len)
1001 := Name_Buffer (1 .. Name_Len);
1002 begin
1003 Get_External_Name (Ancestor_Typ);
1005 -- Append the extended name of the ancestor to the
1006 -- extended name of Typ
1008 Name_Buffer (Len + 2 .. Len + Name_Len + 1) :=
1009 Name_Buffer (1 .. Name_Len);
1010 Name_Buffer (1 .. Len) := Save_Str;
1011 Name_Buffer (Len + 1) := '_';
1012 Name_Len := Len + Name_Len + 1;
1013 end;
1014 end if;
1016 Add_Nat_To_Name_Buffer (Suffix_Index);
1017 end Get_Secondary_DT_External_Name;
1019 ---------------------------------
1020 -- Make_Packed_Array_Impl_Type_Name --
1021 ---------------------------------
1023 function Make_Packed_Array_Impl_Type_Name
1024 (Typ : Entity_Id;
1025 Csize : Uint)
1026 return Name_Id
1028 begin
1029 Get_Name_String (Chars (Typ));
1030 Add_Str_To_Name_Buffer ("___XP");
1031 Add_Uint_To_Buffer (Csize);
1032 return Name_Find;
1033 end Make_Packed_Array_Impl_Type_Name;
1035 -----------------------------------
1036 -- Output_Homonym_Numbers_Suffix --
1037 -----------------------------------
1039 procedure Output_Homonym_Numbers_Suffix is
1040 J : Natural;
1042 begin
1043 if Homonym_Len > 0 then
1045 -- Check for all 1's, in which case we do not output
1047 J := 1;
1048 loop
1049 exit when Homonym_Numbers (J) /= '1';
1051 -- If we reached end of string we do not output
1053 if J = Homonym_Len then
1054 Homonym_Len := 0;
1055 return;
1056 end if;
1058 exit when Homonym_Numbers (J + 1) /= '_';
1059 J := J + 2;
1060 end loop;
1062 -- If we exit the loop then suffix must be output
1064 Add_Str_To_Name_Buffer ("__");
1065 Add_Str_To_Name_Buffer (Homonym_Numbers (1 .. Homonym_Len));
1066 Homonym_Len := 0;
1067 end if;
1068 end Output_Homonym_Numbers_Suffix;
1070 ------------------------------
1071 -- Prepend_String_To_Buffer --
1072 ------------------------------
1074 procedure Prepend_String_To_Buffer (S : String) is
1075 N : constant Integer := S'Length;
1076 begin
1077 Name_Buffer (1 + N .. Name_Len + N) := Name_Buffer (1 .. Name_Len);
1078 Name_Buffer (1 .. N) := S;
1079 Name_Len := Name_Len + N;
1080 end Prepend_String_To_Buffer;
1082 ----------------------------
1083 -- Prepend_Uint_To_Buffer --
1084 ----------------------------
1086 procedure Prepend_Uint_To_Buffer (U : Uint) is
1087 begin
1088 if U < 0 then
1089 Prepend_String_To_Buffer ("m");
1090 Prepend_Uint_To_Buffer (-U);
1091 else
1092 UI_Image (U, Decimal);
1093 Prepend_String_To_Buffer (UI_Image_Buffer (1 .. UI_Image_Length));
1094 end if;
1095 end Prepend_Uint_To_Buffer;
1097 ------------------------------
1098 -- Qualify_All_Entity_Names --
1099 ------------------------------
1101 procedure Qualify_All_Entity_Names is
1102 E : Entity_Id;
1103 Ent : Entity_Id;
1105 begin
1106 for J in Name_Qualify_Units.First .. Name_Qualify_Units.Last loop
1107 E := Defining_Entity (Name_Qualify_Units.Table (J));
1108 Reset_Buffers;
1109 Qualify_Entity_Name (E);
1111 -- Normally entities in the qualification list are scopes, but in the
1112 -- case of a library-level package renaming there is an associated
1113 -- variable that encodes the debugger name and that variable is
1114 -- entered in the list since it occurs in the Aux_Decls list of the
1115 -- compilation and doesn't have a normal scope.
1117 if Ekind (E) /= E_Variable then
1118 Ent := First_Entity (E);
1119 while Present (Ent) loop
1120 Reset_Buffers;
1121 Qualify_Entity_Name (Ent);
1122 Next_Entity (Ent);
1124 -- There are odd cases where Last_Entity (E) = E. This happens
1125 -- in the case of renaming of packages. This test avoids
1126 -- getting stuck in such cases.
1128 exit when Ent = E;
1129 end loop;
1130 end if;
1131 end loop;
1132 end Qualify_All_Entity_Names;
1134 -------------------------
1135 -- Qualify_Entity_Name --
1136 -------------------------
1138 procedure Qualify_Entity_Name (Ent : Entity_Id) is
1140 Full_Qualify_Name : String (1 .. Name_Buffer'Length);
1141 Full_Qualify_Len : Natural := 0;
1142 -- Used to accumulate fully qualified name of subprogram
1144 procedure Fully_Qualify_Name (E : Entity_Id);
1145 -- Used to qualify a subprogram or type name, where full
1146 -- qualification up to Standard is always used. Name is set
1147 -- in Full_Qualify_Name with the length in Full_Qualify_Len.
1148 -- Note that this routine does not prepend the _ada_ string
1149 -- required for library subprograms (this is done in the back end).
1151 function Is_BNPE (S : Entity_Id) return Boolean;
1152 -- Determines if S is a BNPE, i.e. Body-Nested Package Entity, which
1153 -- is defined to be a package which is immediately nested within a
1154 -- package body.
1156 function Qualify_Needed (S : Entity_Id) return Boolean;
1157 -- Given a scope, determines if the scope is to be included in the
1158 -- fully qualified name, True if so, False if not. Blocks and loops
1159 -- are excluded from a qualified name.
1161 procedure Set_BNPE_Suffix (E : Entity_Id);
1162 -- Recursive routine to append the BNPE qualification suffix. Works
1163 -- from right to left with E being the current entity in the list.
1164 -- The result does NOT have the trailing n's and trailing b stripped.
1165 -- The caller must do this required stripping.
1167 procedure Set_Entity_Name (E : Entity_Id);
1168 -- Internal recursive routine that does most of the work. This routine
1169 -- leaves the result sitting in Name_Buffer and Name_Len.
1171 BNPE_Suffix_Needed : Boolean := False;
1172 -- Set true if a body-nested package entity suffix is required
1174 Save_Chars : constant Name_Id := Chars (Ent);
1175 -- Save original name
1177 ------------------------
1178 -- Fully_Qualify_Name --
1179 ------------------------
1181 procedure Fully_Qualify_Name (E : Entity_Id) is
1182 Discard : Boolean := False;
1184 begin
1185 -- Ignore empty entry (can happen in error cases)
1187 if No (E) then
1188 return;
1190 -- If this we are qualifying entities local to a generic instance,
1191 -- use the name of the original instantiation, not that of the
1192 -- anonymous subprogram in the wrapper package, so that gdb doesn't
1193 -- have to know about these.
1195 elsif Is_Generic_Instance (E)
1196 and then Is_Subprogram (E)
1197 and then not Comes_From_Source (E)
1198 and then not Is_Compilation_Unit (Scope (E))
1199 then
1200 Fully_Qualify_Name (Related_Instance (Scope (E)));
1201 return;
1202 end if;
1204 -- If we reached fully qualified name, then just copy it
1206 if Has_Fully_Qualified_Name (E) then
1207 Get_Name_String (Chars (E));
1208 Strip_Suffixes (Discard);
1209 Full_Qualify_Name (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
1210 Full_Qualify_Len := Name_Len;
1211 Set_Has_Fully_Qualified_Name (Ent);
1213 -- Case of non-fully qualified name
1215 else
1216 if Scope (E) = Standard_Standard then
1217 Set_Has_Fully_Qualified_Name (Ent);
1218 else
1219 Fully_Qualify_Name (Scope (E));
1220 Full_Qualify_Name (Full_Qualify_Len + 1) := '_';
1221 Full_Qualify_Name (Full_Qualify_Len + 2) := '_';
1222 Full_Qualify_Len := Full_Qualify_Len + 2;
1223 end if;
1225 if Has_Qualified_Name (E) then
1226 Get_Unqualified_Name_String (Chars (E));
1227 else
1228 Get_Name_String (Chars (E));
1229 end if;
1231 -- Here we do one step of the qualification
1233 Full_Qualify_Name
1234 (Full_Qualify_Len + 1 .. Full_Qualify_Len + Name_Len) :=
1235 Name_Buffer (1 .. Name_Len);
1236 Full_Qualify_Len := Full_Qualify_Len + Name_Len;
1237 Append_Homonym_Number (E);
1238 end if;
1240 if Is_BNPE (E) then
1241 BNPE_Suffix_Needed := True;
1242 end if;
1243 end Fully_Qualify_Name;
1245 -------------
1246 -- Is_BNPE --
1247 -------------
1249 function Is_BNPE (S : Entity_Id) return Boolean is
1250 begin
1251 return Ekind (S) = E_Package and then Is_Package_Body_Entity (S);
1252 end Is_BNPE;
1254 --------------------
1255 -- Qualify_Needed --
1256 --------------------
1258 function Qualify_Needed (S : Entity_Id) return Boolean is
1259 begin
1260 -- If we got all the way to Standard, then we have certainly
1261 -- fully qualified the name, so set the flag appropriately,
1262 -- and then return False, since we are most certainly done.
1264 if S = Standard_Standard then
1265 Set_Has_Fully_Qualified_Name (Ent, True);
1266 return False;
1268 -- Otherwise figure out if further qualification is required
1270 else
1271 return Is_Subprogram (Ent)
1272 or else Ekind (Ent) = E_Subprogram_Body
1273 or else (Ekind (S) /= E_Block
1274 and then Ekind (S) /= E_Loop
1275 and then not Is_Dynamic_Scope (S));
1276 end if;
1277 end Qualify_Needed;
1279 ---------------------
1280 -- Set_BNPE_Suffix --
1281 ---------------------
1283 procedure Set_BNPE_Suffix (E : Entity_Id) is
1284 S : constant Entity_Id := Scope (E);
1286 begin
1287 if Qualify_Needed (S) then
1288 Set_BNPE_Suffix (S);
1290 if Is_BNPE (E) then
1291 Add_Char_To_Name_Buffer ('b');
1292 else
1293 Add_Char_To_Name_Buffer ('n');
1294 end if;
1296 else
1297 Add_Char_To_Name_Buffer ('X');
1298 end if;
1299 end Set_BNPE_Suffix;
1301 ---------------------
1302 -- Set_Entity_Name --
1303 ---------------------
1305 procedure Set_Entity_Name (E : Entity_Id) is
1306 S : constant Entity_Id := Scope (E);
1308 begin
1309 -- If we reach an already qualified name, just take the encoding
1310 -- except that we strip the package body suffixes, since these
1311 -- will be separately put on later.
1313 if Has_Qualified_Name (E) then
1314 Get_Name_String_And_Append (Chars (E));
1315 Strip_Suffixes (BNPE_Suffix_Needed);
1317 -- If the top level name we are adding is itself fully
1318 -- qualified, then that means that the name that we are
1319 -- preparing for the Fully_Qualify_Name call will also
1320 -- generate a fully qualified name.
1322 if Has_Fully_Qualified_Name (E) then
1323 Set_Has_Fully_Qualified_Name (Ent);
1324 end if;
1326 -- Case where upper level name is not encoded yet
1328 else
1329 -- Recurse if further qualification required
1331 if Qualify_Needed (S) then
1332 Set_Entity_Name (S);
1333 Add_Str_To_Name_Buffer ("__");
1334 end if;
1336 -- Otherwise get name and note if it is a BNPE
1338 Get_Name_String_And_Append (Chars (E));
1340 if Is_BNPE (E) then
1341 BNPE_Suffix_Needed := True;
1342 end if;
1344 Append_Homonym_Number (E);
1345 end if;
1346 end Set_Entity_Name;
1348 -- Start of processing for Qualify_Entity_Name
1350 begin
1351 if Has_Qualified_Name (Ent) then
1352 return;
1354 -- In formal verification mode, simply append a suffix for homonyms.
1355 -- We used to qualify entity names as full expansion does, but this was
1356 -- removed as this prevents the verification back-end from using a short
1357 -- name for debugging and user interaction. The verification back-end
1358 -- already takes care of qualifying names when needed. Still mark the
1359 -- name as being qualified, as Qualify_Entity_Name may be called more
1360 -- than once on the same entity.
1362 elsif GNATprove_Mode then
1363 if Has_Homonym (Ent) then
1364 Get_Name_String (Chars (Ent));
1365 Append_Homonym_Number (Ent);
1366 Output_Homonym_Numbers_Suffix;
1367 Set_Chars (Ent, Name_Enter);
1368 end if;
1370 Set_Has_Qualified_Name (Ent);
1371 return;
1373 -- If the entity is a variable encoding the debug name for an object
1374 -- renaming, then the qualified name of the entity associated with the
1375 -- renamed object can now be incorporated in the debug name.
1377 elsif Ekind (Ent) = E_Variable
1378 and then Present (Debug_Renaming_Link (Ent))
1379 then
1380 Name_Len := 0;
1381 Qualify_Entity_Name (Debug_Renaming_Link (Ent));
1382 Get_Name_String (Chars (Ent));
1384 -- Retrieve the now-qualified name of the renamed entity and insert
1385 -- it in the middle of the name, just preceding the suffix encoding
1386 -- describing the renamed object.
1388 declare
1389 Renamed_Id : constant String :=
1390 Get_Name_String (Chars (Debug_Renaming_Link (Ent)));
1391 Insert_Len : constant Integer := Renamed_Id'Length + 1;
1392 Index : Natural := Name_Len - 3;
1394 begin
1395 -- Loop backwards through the name to find the start of the "___"
1396 -- sequence associated with the suffix.
1398 while Index >= Name_Buffer'First
1399 and then (Name_Buffer (Index + 1) /= '_'
1400 or else Name_Buffer (Index + 2) /= '_'
1401 or else Name_Buffer (Index + 3) /= '_')
1402 loop
1403 Index := Index - 1;
1404 end loop;
1406 pragma Assert (Name_Buffer (Index + 1 .. Index + 3) = "___");
1408 -- Insert an underscore separator and the entity name just in
1409 -- front of the suffix.
1411 Name_Buffer (Index + 1 + Insert_Len .. Name_Len + Insert_Len) :=
1412 Name_Buffer (Index + 1 .. Name_Len);
1413 Name_Buffer (Index + 1) := '_';
1414 Name_Buffer (Index + 2 .. Index + Insert_Len) := Renamed_Id;
1415 Name_Len := Name_Len + Insert_Len;
1416 end;
1418 -- Reset the name of the variable to the new name that includes the
1419 -- name of the renamed entity.
1421 Set_Chars (Ent, Name_Enter);
1423 -- If the entity needs qualification by its scope then develop it
1424 -- here, add the variable's name, and again reset the entity name.
1426 if Qualify_Needed (Scope (Ent)) then
1427 Name_Len := 0;
1428 Set_Entity_Name (Scope (Ent));
1429 Add_Str_To_Name_Buffer ("__");
1431 Get_Name_String_And_Append (Chars (Ent));
1433 Set_Chars (Ent, Name_Enter);
1434 end if;
1436 Set_Has_Qualified_Name (Ent);
1437 return;
1439 elsif Is_Subprogram (Ent)
1440 or else Ekind (Ent) = E_Subprogram_Body
1441 or else Is_Type (Ent)
1442 then
1443 Fully_Qualify_Name (Ent);
1444 Name_Len := Full_Qualify_Len;
1445 Name_Buffer (1 .. Name_Len) := Full_Qualify_Name (1 .. Name_Len);
1447 elsif Qualify_Needed (Scope (Ent)) then
1448 Name_Len := 0;
1449 Set_Entity_Name (Ent);
1451 else
1452 Set_Has_Qualified_Name (Ent);
1453 return;
1454 end if;
1456 -- Fall through with a fully qualified name in Name_Buffer/Name_Len
1458 Output_Homonym_Numbers_Suffix;
1460 -- Add body-nested package suffix if required
1462 if BNPE_Suffix_Needed
1463 and then Ekind (Ent) /= E_Enumeration_Literal
1464 then
1465 Set_BNPE_Suffix (Ent);
1467 -- Strip trailing n's and last trailing b as required. note that
1468 -- we know there is at least one b, or no suffix would be generated.
1470 while Name_Buffer (Name_Len) = 'n' loop
1471 Name_Len := Name_Len - 1;
1472 end loop;
1474 Name_Len := Name_Len - 1;
1475 end if;
1477 Set_Chars (Ent, Name_Enter);
1478 Set_Has_Qualified_Name (Ent);
1480 if Debug_Flag_BB then
1481 Write_Str ("*** ");
1482 Write_Name (Save_Chars);
1483 Write_Str (" qualified as ");
1484 Write_Name (Chars (Ent));
1485 Write_Eol;
1486 end if;
1487 end Qualify_Entity_Name;
1489 --------------------------
1490 -- Qualify_Entity_Names --
1491 --------------------------
1493 procedure Qualify_Entity_Names (N : Node_Id) is
1494 begin
1495 Name_Qualify_Units.Append (N);
1496 end Qualify_Entity_Names;
1498 -------------------
1499 -- Reset_Buffers --
1500 -------------------
1502 procedure Reset_Buffers is
1503 begin
1504 Name_Len := 0;
1505 Homonym_Len := 0;
1506 end Reset_Buffers;
1508 --------------------
1509 -- Strip_Suffixes --
1510 --------------------
1512 procedure Strip_Suffixes (BNPE_Suffix_Found : in out Boolean) is
1513 SL : Natural;
1515 pragma Warnings (Off, BNPE_Suffix_Found);
1516 -- Since this procedure only ever sets the flag
1518 begin
1519 -- Search for and strip BNPE suffix
1521 for J in reverse 2 .. Name_Len loop
1522 if Name_Buffer (J) = 'X' then
1523 Name_Len := J - 1;
1524 BNPE_Suffix_Found := True;
1525 exit;
1526 end if;
1528 exit when Name_Buffer (J) /= 'b' and then Name_Buffer (J) /= 'n';
1529 end loop;
1531 -- Search for and strip homonym numbers suffix
1533 for J in reverse 2 .. Name_Len - 2 loop
1534 if Name_Buffer (J) = '_'
1535 and then Name_Buffer (J + 1) = '_'
1536 then
1537 if Name_Buffer (J + 2) in '0' .. '9' then
1538 if Homonym_Len > 0 then
1539 Homonym_Len := Homonym_Len + 1;
1540 Homonym_Numbers (Homonym_Len) := '-';
1541 end if;
1543 SL := Name_Len - (J + 1);
1545 Homonym_Numbers (Homonym_Len + 1 .. Homonym_Len + SL) :=
1546 Name_Buffer (J + 2 .. Name_Len);
1547 Name_Len := J - 1;
1548 Homonym_Len := Homonym_Len + SL;
1549 end if;
1551 exit;
1552 end if;
1553 end loop;
1554 end Strip_Suffixes;
1556 end Exp_Dbug;