1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Util; use Exp_Util;
33 with Fname; use Fname;
34 with Freeze; use Freeze;
36 with Lib.Load; use Lib.Load;
37 with Lib.Xref; use Lib.Xref;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
42 with Output; use Output;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
45 with Rtsfind; use Rtsfind;
47 with Sem_Cat; use Sem_Cat;
48 with Sem_Ch3; use Sem_Ch3;
49 with Sem_Ch4; use Sem_Ch4;
50 with Sem_Ch6; use Sem_Ch6;
51 with Sem_Ch12; use Sem_Ch12;
52 with Sem_Res; use Sem_Res;
53 with Sem_Util; use Sem_Util;
54 with Sem_Type; use Sem_Type;
55 with Stand; use Stand;
56 with Sinfo; use Sinfo;
57 with Sinfo.CN; use Sinfo.CN;
58 with Snames; use Snames;
59 with Style; use Style;
61 with Tbuild; use Tbuild;
62 with Uintp; use Uintp;
64 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
66 package body Sem_Ch8 is
68 ------------------------------------
69 -- Visibility and Name Resolution --
70 ------------------------------------
72 -- This package handles name resolution and the collection of
73 -- interpretations for overloaded names, prior to overload resolution.
75 -- Name resolution is the process that establishes a mapping between source
76 -- identifiers and the entities they denote at each point in the program.
77 -- Each entity is represented by a defining occurrence. Each identifier
78 -- that denotes an entity points to the corresponding defining occurrence.
79 -- This is the entity of the applied occurrence. Each occurrence holds
80 -- an index into the names table, where source identifiers are stored.
82 -- Each entry in the names table for an identifier or designator uses the
83 -- Info pointer to hold a link to the currently visible entity that has
84 -- this name (see subprograms Get_Name_Entity_Id and Set_Name_Entity_Id
85 -- in package Sem_Util). The visibility is initialized at the beginning of
86 -- semantic processing to make entities in package Standard immediately
87 -- visible. The visibility table is used in a more subtle way when
88 -- compiling subunits (see below).
90 -- Entities that have the same name (i.e. homonyms) are chained. In the
91 -- case of overloaded entities, this chain holds all the possible meanings
92 -- of a given identifier. The process of overload resolution uses type
93 -- information to select from this chain the unique meaning of a given
96 -- Entities are also chained in their scope, through the Next_Entity link.
97 -- As a consequence, the name space is organized as a sparse matrix, where
98 -- each row corresponds to a scope, and each column to a source identifier.
99 -- Open scopes, that is to say scopes currently being compiled, have their
100 -- corresponding rows of entities in order, innermost scope first.
102 -- The scopes of packages that are mentioned in context clauses appear in
103 -- no particular order, interspersed among open scopes. This is because
104 -- in the course of analyzing the context of a compilation, a package
105 -- declaration is first an open scope, and subsequently an element of the
106 -- context. If subunits or child units are present, a parent unit may
107 -- appear under various guises at various times in the compilation.
109 -- When the compilation of the innermost scope is complete, the entities
110 -- defined therein are no longer visible. If the scope is not a package
111 -- declaration, these entities are never visible subsequently, and can be
112 -- removed from visibility chains. If the scope is a package declaration,
113 -- its visible declarations may still be accessible. Therefore the entities
114 -- defined in such a scope are left on the visibility chains, and only
115 -- their visibility (immediately visibility or potential use-visibility)
118 -- The ordering of homonyms on their chain does not necessarily follow
119 -- the order of their corresponding scopes on the scope stack. For
120 -- example, if package P and the enclosing scope both contain entities
121 -- named E, then when compiling the package body the chain for E will
122 -- hold the global entity first, and the local one (corresponding to
123 -- the current inner scope) next. As a result, name resolution routines
124 -- do not assume any relative ordering of the homonym chains, either
125 -- for scope nesting or to order of appearance of context clauses.
127 -- When compiling a child unit, entities in the parent scope are always
128 -- immediately visible. When compiling the body of a child unit, private
129 -- entities in the parent must also be made immediately visible. There
130 -- are separate routines to make the visible and private declarations
131 -- visible at various times (see package Sem_Ch7).
133 -- +--------+ +-----+
134 -- | In use |-------->| EU1 |-------------------------->
135 -- +--------+ +-----+
137 -- +--------+ +-----+ +-----+
138 -- | Stand. |---------------->| ES1 |--------------->| ES2 |--->
139 -- +--------+ +-----+ +-----+
141 -- +---------+ | +-----+
142 -- | with'ed |------------------------------>| EW2 |--->
143 -- +---------+ | +-----+
145 -- +--------+ +-----+ +-----+
146 -- | Scope2 |---------------->| E12 |--------------->| E22 |--->
147 -- +--------+ +-----+ +-----+
149 -- +--------+ +-----+ +-----+
150 -- | Scope1 |---------------->| E11 |--------------->| E12 |--->
151 -- +--------+ +-----+ +-----+
155 -- | | with'ed |----------------------------------------->
159 -- (innermost first) | |
160 -- +----------------------------+
161 -- Names table => | Id1 | | | | Id2 |
162 -- +----------------------------+
164 -- Name resolution must deal with several syntactic forms: simple names,
165 -- qualified names, indexed names, and various forms of calls.
167 -- Each identifier points to an entry in the names table. The resolution
168 -- of a simple name consists in traversing the homonym chain, starting
169 -- from the names table. If an entry is immediately visible, it is the one
170 -- designated by the identifier. If only potentially use-visible entities
171 -- are on the chain, we must verify that they do not hide each other. If
172 -- the entity we find is overloadable, we collect all other overloadable
173 -- entities on the chain as long as they are not hidden.
175 -- To resolve expanded names, we must find the entity at the intersection
176 -- of the entity chain for the scope (the prefix) and the homonym chain
177 -- for the selector. In general, homonym chains will be much shorter than
178 -- entity chains, so it is preferable to start from the names table as
179 -- well. If the entity found is overloadable, we must collect all other
180 -- interpretations that are defined in the scope denoted by the prefix.
182 -- For records, protected types, and tasks, their local entities are
183 -- removed from visibility chains on exit from the corresponding scope.
184 -- From the outside, these entities are always accessed by selected
185 -- notation, and the entity chain for the record type, protected type,
186 -- etc. is traversed sequentially in order to find the designated entity.
188 -- The discriminants of a type and the operations of a protected type or
189 -- task are unchained on exit from the first view of the type, (such as
190 -- a private or incomplete type declaration, or a protected type speci-
191 -- fication) and re-chained when compiling the second view.
193 -- In the case of operators, we do not make operators on derived types
194 -- explicit. As a result, the notation P."+" may denote either a user-
195 -- defined function with name "+", or else an implicit declaration of the
196 -- operator "+" in package P. The resolution of expanded names always
197 -- tries to resolve an operator name as such an implicitly defined entity,
198 -- in addition to looking for explicit declarations.
200 -- All forms of names that denote entities (simple names, expanded names,
201 -- character literals in some cases) have a Entity attribute, which
202 -- identifies the entity denoted by the name.
204 ---------------------
205 -- The Scope Stack --
206 ---------------------
208 -- The Scope stack keeps track of the scopes currently been compiled.
209 -- Every entity that contains declarations (including records) is placed
210 -- on the scope stack while it is being processed, and removed at the end.
211 -- Whenever a non-package scope is exited, the entities defined therein
212 -- are removed from the visibility table, so that entities in outer scopes
213 -- become visible (see previous description). On entry to Sem, the scope
214 -- stack only contains the package Standard. As usual, subunits complicate
215 -- this picture ever so slightly.
217 -- The Rtsfind mechanism can force a call to Semantics while another
218 -- compilation is in progress. The unit retrieved by Rtsfind must be
219 -- compiled in its own context, and has no access to the visibility of
220 -- the unit currently being compiled. The procedures Save_Scope_Stack and
221 -- Restore_Scope_Stack make entities in current open scopes invisible
222 -- before compiling the retrieved unit, and restore the compilation
223 -- environment afterwards.
225 ------------------------
226 -- Compiling subunits --
227 ------------------------
229 -- Subunits must be compiled in the environment of the corresponding
230 -- stub, that is to say with the same visibility into the parent (and its
231 -- context) that is available at the point of the stub declaration, but
232 -- with the additional visibility provided by the context clause of the
233 -- subunit itself. As a result, compilation of a subunit forces compilation
234 -- of the parent (see description in lib-). At the point of the stub
235 -- declaration, Analyze is called recursively to compile the proper body
236 -- of the subunit, but without reinitializing the names table, nor the
237 -- scope stack (i.e. standard is not pushed on the stack). In this fashion
238 -- the context of the subunit is added to the context of the parent, and
239 -- the subunit is compiled in the correct environment. Note that in the
240 -- course of processing the context of a subunit, Standard will appear
241 -- twice on the scope stack: once for the parent of the subunit, and
242 -- once for the unit in the context clause being compiled. However, the
243 -- two sets of entities are not linked by homonym chains, so that the
244 -- compilation of any context unit happens in a fresh visibility
247 -------------------------------
248 -- Processing of USE Clauses --
249 -------------------------------
251 -- Every defining occurrence has a flag indicating if it is potentially use
252 -- visible. Resolution of simple names examines this flag. The processing
253 -- of use clauses consists in setting this flag on all visible entities
254 -- defined in the corresponding package. On exit from the scope of the use
255 -- clause, the corresponding flag must be reset. However, a package may
256 -- appear in several nested use clauses (pathological but legal, alas!)
257 -- which forces us to use a slightly more involved scheme:
259 -- a) The defining occurrence for a package holds a flag -In_Use- to
260 -- indicate that it is currently in the scope of a use clause. If a
261 -- redundant use clause is encountered, then the corresponding occurrence
262 -- of the package name is flagged -Redundant_Use-.
264 -- b) On exit from a scope, the use clauses in its declarative part are
265 -- scanned. The visibility flag is reset in all entities declared in
266 -- package named in a use clause, as long as the package is not flagged
267 -- as being in a redundant use clause (in which case the outer use
268 -- clause is still in effect, and the direct visibility of its entities
269 -- must be retained).
271 -- Note that entities are not removed from their homonym chains on exit
272 -- from the package specification. A subsequent use clause does not need
273 -- to rechain the visible entities, but only to establish their direct
276 -----------------------------------
277 -- Handling private declarations --
278 -----------------------------------
280 -- The principle that each entity has a single defining occurrence clashes
281 -- with the presence of two separate definitions for private types: the
282 -- first is the private type declaration, and second is the full type
283 -- declaration. It is important that all references to the type point to
284 -- the same defining occurrence, namely the first one. To enforce the two
285 -- separate views of the entity, the corresponding information is swapped
286 -- between the two declarations. Outside of the package, the defining
287 -- occurrence only contains the private declaration information, while in
288 -- the private part and the body of the package the defining occurrence
289 -- contains the full declaration. To simplify the swap, the defining
290 -- occurrence that currently holds the private declaration points to the
291 -- full declaration. During semantic processing the defining occurrence
292 -- also points to a list of private dependents, that is to say access
293 -- types or composite types whose designated types or component types are
294 -- subtypes or derived types of the private type in question. After the
295 -- full declaration has been seen, the private dependents are updated to
296 -- indicate that they have full definitions.
298 ------------------------------------
299 -- Handling of Undefined Messages --
300 ------------------------------------
302 -- In normal mode, only the first use of an undefined identifier generates
303 -- a message. The table Urefs is used to record error messages that have
304 -- been issued so that second and subsequent ones do not generate further
305 -- messages. However, the second reference causes text to be added to the
306 -- original undefined message noting "(more references follow)". The
307 -- full error list option (-gnatf) forces messages to be generated for
308 -- every reference and disconnects the use of this table.
310 type Uref_Entry is record
312 -- Node for identifier for which original message was posted. The
313 -- Chars field of this identifier is used to detect later references
314 -- to the same identifier.
317 -- Records error message Id of original undefined message. Reset to
318 -- No_Error_Msg after the second occurrence, where it is used to add
319 -- text to the original message as described above.
322 -- Set if the message is not visible rather than undefined
325 -- Records location of error message. Used to make sure that we do
326 -- not consider a, b : undefined as two separate instances, which
327 -- would otherwise happen, since the parser converts this sequence
328 -- to a : undefined; b : undefined.
332 package Urefs is new Table.Table (
333 Table_Component_Type => Uref_Entry,
334 Table_Index_Type => Nat,
335 Table_Low_Bound => 1,
337 Table_Increment => 100,
338 Table_Name => "Urefs");
340 Candidate_Renaming : Entity_Id;
341 -- Holds a candidate interpretation that appears in a subprogram renaming
342 -- declaration and does not match the given specification, but matches at
343 -- least on the first formal. Allows better error message when given
344 -- specification omits defaulted parameters, a common error.
346 -----------------------
347 -- Local Subprograms --
348 -----------------------
350 procedure Analyze_Generic_Renaming
353 -- Common processing for all three kinds of generic renaming declarations.
354 -- Enter new name and indicate that it renames the generic unit.
356 procedure Analyze_Renamed_Character
360 -- Renamed entity is given by a character literal, which must belong
361 -- to the return type of the new entity. Is_Body indicates whether the
362 -- declaration is a renaming_as_body. If the original declaration has
363 -- already been frozen (because of an intervening body, e.g.) the body of
364 -- the function must be built now. The same applies to the following
365 -- various renaming procedures.
367 procedure Analyze_Renamed_Dereference
371 -- Renamed entity is given by an explicit dereference. Prefix must be a
372 -- conformant access_to_subprogram type.
374 procedure Analyze_Renamed_Entry
378 -- If the renamed entity in a subprogram renaming is an entry or protected
379 -- subprogram, build a body for the new entity whose only statement is a
380 -- call to the renamed entity.
382 procedure Analyze_Renamed_Family_Member
386 -- Used when the renamed entity is an indexed component. The prefix must
387 -- denote an entry family.
389 function Applicable_Use (Pack_Name : Node_Id) return Boolean;
390 -- Common code to Use_One_Package and Set_Use, to determine whether
391 -- use clause must be processed. Pack_Name is an entity name that
392 -- references the package in question.
394 procedure Attribute_Renaming (N : Node_Id);
395 -- Analyze renaming of attribute as function. The renaming declaration N
396 -- is rewritten as a function body that returns the attribute reference
397 -- applied to the formals of the function.
399 procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id);
400 -- A renaming_as_body may occur after the entity of the original decla-
401 -- ration has been frozen. In that case, the body of the new entity must
402 -- be built now, because the usual mechanism of building the renamed
403 -- body at the point of freezing will not work. Subp is the subprogram
404 -- for which N provides the Renaming_As_Body.
406 procedure Check_In_Previous_With_Clause
409 -- N is a use_package clause and Nam the package name, or N is a use_type
410 -- clause and Nam is the prefix of the type name. In either case, verify
411 -- that the package is visible at that point in the context: either it
412 -- appears in a previous with_clause, or because it is a fully qualified
413 -- name and the root ancestor appears in a previous with_clause.
415 procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id);
416 -- Verify that the entity in a renaming declaration that is a library unit
417 -- is itself a library unit and not a nested unit or subunit. Also check
418 -- that if the renaming is a child unit of a generic parent, then the
419 -- renamed unit must also be a child unit of that parent. Finally, verify
420 -- that a renamed generic unit is not an implicit child declared within
421 -- an instance of the parent.
423 procedure Chain_Use_Clause (N : Node_Id);
424 -- Chain use clause onto list of uses clauses headed by First_Use_Clause
425 -- in the top scope table entry.
427 function Has_Implicit_Character_Literal (N : Node_Id) return Boolean;
428 -- Find a type derived from Character or Wide_Character in the prefix of N.
429 -- Used to resolved qualified names whose selector is a character literal.
431 function Has_Private_With (E : Entity_Id) return Boolean;
432 -- Ada 0Y (AI-262): Determines if the current compilation unit has a
435 procedure Find_Expanded_Name (N : Node_Id);
436 -- Selected component is known to be expanded name. Verify legality
437 -- of selector given the scope denoted by prefix.
439 function Find_Renamed_Entity
443 Is_Actual : Boolean := False) return Entity_Id;
444 -- Find the renamed entity that corresponds to the given parameter profile
445 -- in a subprogram renaming declaration. The renamed entity may be an
446 -- operator, a subprogram, an entry, or a protected operation. Is_Actual
447 -- indicates that the renaming is the one generated for an actual subpro-
448 -- gram in an instance, for which special visibility checks apply.
450 function Has_Implicit_Operator (N : Node_Id) return Boolean;
451 -- N is an expanded name whose selector is an operator name (eg P."+").
452 -- A declarative part contains an implicit declaration of an operator
453 -- if it has a declaration of a type to which one of the predefined
454 -- operators apply. The existence of this routine is an artifact of
455 -- our implementation: a more straightforward but more space-consuming
456 -- choice would be to make all inherited operators explicit in the
459 procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id);
460 -- A subprogram defined by a renaming declaration inherits the parameter
461 -- profile of the renamed entity. The subtypes given in the subprogram
462 -- specification are discarded and replaced with those of the renamed
463 -- subprogram, which are then used to recheck the default values.
465 function Is_Appropriate_For_Record (T : Entity_Id) return Boolean;
466 -- Prefix is appropriate for record if it is of a record type, or
467 -- an access to such.
469 function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean;
470 -- True if it is of a task type, a protected type, or else an access
471 -- to one of these types.
473 procedure Premature_Usage (N : Node_Id);
474 -- Diagnose usage of an entity before it is visible.
476 procedure Use_One_Package (P : Entity_Id; N : Node_Id);
477 -- Make visible entities declared in package P potentially use-visible
478 -- in the current context. Also used in the analysis of subunits, when
479 -- re-installing use clauses of parent units. N is the use_clause that
480 -- names P (and possibly other packages).
482 procedure Use_One_Type (Id : Node_Id);
483 -- Id is the subtype mark from a use type clause. This procedure makes
484 -- the primitive operators of the type potentially use-visible.
486 procedure Write_Info;
487 -- Write debugging information on entities declared in current scope
489 procedure Write_Scopes;
490 pragma Warnings (Off, Write_Scopes);
491 -- Debugging information: dump all entities on scope stack
493 --------------------------------
494 -- Analyze_Exception_Renaming --
495 --------------------------------
497 -- The language only allows a single identifier, but the tree holds
498 -- an identifier list. The parser has already issued an error message
499 -- if there is more than one element in the list.
501 procedure Analyze_Exception_Renaming (N : Node_Id) is
502 Id : constant Node_Id := Defining_Identifier (N);
503 Nam : constant Node_Id := Name (N);
509 Set_Ekind (Id, E_Exception);
510 Set_Exception_Code (Id, Uint_0);
511 Set_Etype (Id, Standard_Exception_Type);
512 Set_Is_Pure (Id, Is_Pure (Current_Scope));
514 if not Is_Entity_Name (Nam) or else
515 Ekind (Entity (Nam)) /= E_Exception
517 Error_Msg_N ("invalid exception name in renaming", Nam);
519 if Present (Renamed_Object (Entity (Nam))) then
520 Set_Renamed_Object (Id, Renamed_Object (Entity (Nam)));
522 Set_Renamed_Object (Id, Entity (Nam));
525 end Analyze_Exception_Renaming;
527 ---------------------------
528 -- Analyze_Expanded_Name --
529 ---------------------------
531 procedure Analyze_Expanded_Name (N : Node_Id) is
533 -- If the entity pointer is already set, this is an internal node, or
534 -- a node that is analyzed more than once, after a tree modification.
535 -- In such a case there is no resolution to perform, just set the type.
536 -- For completeness, analyze prefix as well.
538 if Present (Entity (N)) then
539 if Is_Type (Entity (N)) then
540 Set_Etype (N, Entity (N));
542 Set_Etype (N, Etype (Entity (N)));
545 Analyze (Prefix (N));
548 Find_Expanded_Name (N);
550 end Analyze_Expanded_Name;
552 ----------------------------------------
553 -- Analyze_Generic_Function_Renaming --
554 ----------------------------------------
556 procedure Analyze_Generic_Function_Renaming (N : Node_Id) is
558 Analyze_Generic_Renaming (N, E_Generic_Function);
559 end Analyze_Generic_Function_Renaming;
561 ---------------------------------------
562 -- Analyze_Generic_Package_Renaming --
563 ---------------------------------------
565 procedure Analyze_Generic_Package_Renaming (N : Node_Id) is
567 -- Apply the Text_IO Kludge here, since we may be renaming
568 -- one of the subpackages of Text_IO, then join common routine.
570 Text_IO_Kludge (Name (N));
572 Analyze_Generic_Renaming (N, E_Generic_Package);
573 end Analyze_Generic_Package_Renaming;
575 -----------------------------------------
576 -- Analyze_Generic_Procedure_Renaming --
577 -----------------------------------------
579 procedure Analyze_Generic_Procedure_Renaming (N : Node_Id) is
581 Analyze_Generic_Renaming (N, E_Generic_Procedure);
582 end Analyze_Generic_Procedure_Renaming;
584 ------------------------------
585 -- Analyze_Generic_Renaming --
586 ------------------------------
588 procedure Analyze_Generic_Renaming
592 New_P : constant Entity_Id := Defining_Entity (N);
594 Inst : Boolean := False; -- prevent junk warning
597 if Name (N) = Error then
601 Generate_Definition (New_P);
603 if Current_Scope /= Standard_Standard then
604 Set_Is_Pure (New_P, Is_Pure (Current_Scope));
607 if Nkind (Name (N)) = N_Selected_Component then
608 Check_Generic_Child_Unit (Name (N), Inst);
613 if not Is_Entity_Name (Name (N)) then
614 Error_Msg_N ("expect entity name in renaming declaration", Name (N));
617 Old_P := Entity (Name (N));
621 Set_Ekind (New_P, K);
623 if Etype (Old_P) = Any_Type then
626 elsif Ekind (Old_P) /= K then
627 Error_Msg_N ("invalid generic unit name", Name (N));
630 if Present (Renamed_Object (Old_P)) then
631 Set_Renamed_Object (New_P, Renamed_Object (Old_P));
633 Set_Renamed_Object (New_P, Old_P);
636 Set_Etype (New_P, Etype (Old_P));
637 Set_Has_Completion (New_P);
639 if In_Open_Scopes (Old_P) then
640 Error_Msg_N ("within its scope, generic denotes its instance", N);
643 Check_Library_Unit_Renaming (N, Old_P);
646 end Analyze_Generic_Renaming;
648 -----------------------------
649 -- Analyze_Object_Renaming --
650 -----------------------------
652 procedure Analyze_Object_Renaming (N : Node_Id) is
653 Id : constant Entity_Id := Defining_Identifier (N);
655 Nam : constant Node_Id := Name (N);
664 Set_Is_Pure (Id, Is_Pure (Current_Scope));
667 -- The renaming of a component that depends on a discriminant
668 -- requires an actual subtype, because in subsequent use of the object
669 -- Gigi will be unable to locate the actual bounds. This explicit step
670 -- is required when the renaming is generated in removing side effects
671 -- of an already-analyzed expression.
673 if Nkind (Nam) = N_Selected_Component
674 and then Analyzed (Nam)
677 Dec := Build_Actual_Subtype_Of_Component (Etype (Nam), Nam);
679 if Present (Dec) then
680 Insert_Action (N, Dec);
681 T := Defining_Identifier (Dec);
685 elsif Present (Subtype_Mark (N)) then
686 Find_Type (Subtype_Mark (N));
687 T := Entity (Subtype_Mark (N));
688 Analyze_And_Resolve (Nam, T);
690 -- Ada 0Y (AI-230/AI-254): Access renaming
692 else pragma Assert (Present (Access_Definition (N)));
693 T := Access_Definition
695 N => Access_Definition (N));
697 Analyze_And_Resolve (Nam, T);
699 -- Ada 0Y (AI-231): "In the case where the type is defined by an
700 -- access_definition, the renamed entity shall be of an access-to-
701 -- constant type if and only if the access_definition defines an
702 -- access-to-constant type" ARM 8.5.1(4)
704 if Constant_Present (Access_Definition (N))
705 and then not Is_Access_Constant (Etype (Nam))
707 Error_Msg_N ("(Ada 0Y): the renamed object is not "
708 & "access-to-constant ('R'M 8.5.1(6))", N);
710 elsif Null_Exclusion_Present (Access_Definition (N)) then
711 Error_Msg_N ("(Ada 0Y): null-excluding attribute ignored "
712 & "('R'M 8.5.1(6))?", N);
716 -- An object renaming requires an exact match of the type;
717 -- class-wide matching is not allowed.
719 if Is_Class_Wide_Type (T)
720 and then Base_Type (Etype (Nam)) /= Base_Type (T)
726 Set_Ekind (Id, E_Variable);
727 Init_Size_Align (Id);
729 if T = Any_Type or else Etype (Nam) = Any_Type then
732 -- Verify that the renamed entity is an object or a function call.
733 -- It may have been rewritten in several ways.
735 elsif Is_Object_Reference (Nam) then
736 if Comes_From_Source (N)
737 and then Is_Dependent_Component_Of_Mutable_Object (Nam)
740 ("illegal renaming of discriminant-dependent component", Nam);
745 -- A static function call may have been folded into a literal
747 elsif Nkind (Original_Node (Nam)) = N_Function_Call
749 -- When expansion is disabled, attribute reference is not
750 -- rewritten as function call. Otherwise it may be rewritten
751 -- as a conversion, so check original node.
753 or else (Nkind (Original_Node (Nam)) = N_Attribute_Reference
754 and then Is_Function_Attribute_Name
755 (Attribute_Name (Original_Node (Nam))))
757 -- Weird but legal, equivalent to renaming a function call.
759 or else (Is_Entity_Name (Nam)
760 and then Ekind (Entity (Nam)) = E_Enumeration_Literal)
762 or else (Nkind (Nam) = N_Type_Conversion
763 and then Is_Tagged_Type (Entity (Subtype_Mark (Nam))))
768 if Nkind (Nam) = N_Type_Conversion then
770 ("renaming of conversion only allowed for tagged types", Nam);
773 Error_Msg_N ("expect object name in renaming", Nam);
779 if not Is_Variable (Nam) then
780 Set_Ekind (Id, E_Constant);
781 Set_Never_Set_In_Source (Id, True);
782 Set_Is_True_Constant (Id, True);
785 Set_Renamed_Object (Id, Nam);
786 end Analyze_Object_Renaming;
788 ------------------------------
789 -- Analyze_Package_Renaming --
790 ------------------------------
792 procedure Analyze_Package_Renaming (N : Node_Id) is
793 New_P : constant Entity_Id := Defining_Entity (N);
798 if Name (N) = Error then
802 -- Apply Text_IO kludge here, since we may be renaming one of
803 -- the children of Text_IO
805 Text_IO_Kludge (Name (N));
807 if Current_Scope /= Standard_Standard then
808 Set_Is_Pure (New_P, Is_Pure (Current_Scope));
813 if Is_Entity_Name (Name (N)) then
814 Old_P := Entity (Name (N));
819 if Etype (Old_P) = Any_Type then
821 ("expect package name in renaming", Name (N));
823 -- Ada 0Y (AI-50217): Limited withed packages can not be renamed
825 elsif Ekind (Old_P) = E_Package
826 and then From_With_Type (Old_P)
829 ("limited withed package cannot be renamed", Name (N));
831 elsif Ekind (Old_P) /= E_Package
832 and then not (Ekind (Old_P) = E_Generic_Package
833 and then In_Open_Scopes (Old_P))
835 if Ekind (Old_P) = E_Generic_Package then
837 ("generic package cannot be renamed as a package", Name (N));
839 Error_Msg_Sloc := Sloc (Old_P);
841 ("expect package name in renaming, found& declared#",
845 -- Set basic attributes to minimize cascaded errors.
847 Set_Ekind (New_P, E_Package);
848 Set_Etype (New_P, Standard_Void_Type);
851 -- Entities in the old package are accessible through the
852 -- renaming entity. The simplest implementation is to have
853 -- both packages share the entity list.
855 Set_Ekind (New_P, E_Package);
856 Set_Etype (New_P, Standard_Void_Type);
858 if Present (Renamed_Object (Old_P)) then
859 Set_Renamed_Object (New_P, Renamed_Object (Old_P));
861 Set_Renamed_Object (New_P, Old_P);
864 Set_Has_Completion (New_P);
866 Set_First_Entity (New_P, First_Entity (Old_P));
867 Set_Last_Entity (New_P, Last_Entity (Old_P));
868 Set_First_Private_Entity (New_P, First_Private_Entity (Old_P));
869 Check_Library_Unit_Renaming (N, Old_P);
870 Generate_Reference (Old_P, Name (N));
872 -- If this is the renaming declaration of a package instantiation
873 -- within itself, it is the declaration that ends the list of actuals
874 -- for the instantiation. At this point, the subtypes that rename
875 -- the actuals are flagged as generic, to avoid spurious ambiguities
876 -- if the actuals for two distinct formals happen to coincide. If
877 -- the actual is a private type, the subtype has a private completion
878 -- that is flagged in the same fashion.
880 -- Resolution is identical to what is was in the original generic.
881 -- On exit from the generic instance, these are turned into regular
882 -- subtypes again, so they are compatible with types in their class.
884 if not Is_Generic_Instance (Old_P) then
887 Spec := Specification (Unit_Declaration_Node (Old_P));
890 if Nkind (Spec) = N_Package_Specification
891 and then Present (Generic_Parent (Spec))
892 and then Old_P = Current_Scope
893 and then Chars (New_P) = Chars (Generic_Parent (Spec))
896 E : Entity_Id := First_Entity (Old_P);
902 and then Nkind (Parent (E)) = N_Subtype_Declaration
904 Set_Is_Generic_Actual_Type (E);
906 if Is_Private_Type (E)
907 and then Present (Full_View (E))
909 Set_Is_Generic_Actual_Type (Full_View (E));
919 end Analyze_Package_Renaming;
921 -------------------------------
922 -- Analyze_Renamed_Character --
923 -------------------------------
925 procedure Analyze_Renamed_Character
930 C : constant Node_Id := Name (N);
933 if Ekind (New_S) = E_Function then
934 Resolve (C, Etype (New_S));
937 Check_Frozen_Renaming (N, New_S);
941 Error_Msg_N ("character literal can only be renamed as function", N);
943 end Analyze_Renamed_Character;
945 ---------------------------------
946 -- Analyze_Renamed_Dereference --
947 ---------------------------------
949 procedure Analyze_Renamed_Dereference
954 Nam : constant Node_Id := Name (N);
955 P : constant Node_Id := Prefix (Nam);
961 if not Is_Overloaded (P) then
962 if Ekind (Etype (Nam)) /= E_Subprogram_Type
963 or else not Type_Conformant (Etype (Nam), New_S) then
964 Error_Msg_N ("designated type does not match specification", P);
973 Get_First_Interp (Nam, Ind, It);
975 while Present (It.Nam) loop
977 if Ekind (It.Nam) = E_Subprogram_Type
978 and then Type_Conformant (It.Nam, New_S) then
980 if Typ /= Any_Id then
981 Error_Msg_N ("ambiguous renaming", P);
988 Get_Next_Interp (Ind, It);
991 if Typ = Any_Type then
992 Error_Msg_N ("designated type does not match specification", P);
997 Check_Frozen_Renaming (N, New_S);
1001 end Analyze_Renamed_Dereference;
1003 ---------------------------
1004 -- Analyze_Renamed_Entry --
1005 ---------------------------
1007 procedure Analyze_Renamed_Entry
1012 Nam : constant Node_Id := Name (N);
1013 Sel : constant Node_Id := Selector_Name (Nam);
1017 if Entity (Sel) = Any_Id then
1019 -- Selector is undefined on prefix. Error emitted already.
1021 Set_Has_Completion (New_S);
1025 -- Otherwise, find renamed entity, and build body of New_S as a call
1028 Old_S := Find_Renamed_Entity (N, Selector_Name (Nam), New_S);
1030 if Old_S = Any_Id then
1031 Error_Msg_N (" no subprogram or entry matches specification", N);
1034 Check_Subtype_Conformant (New_S, Old_S, N);
1035 Generate_Reference (New_S, Defining_Entity (N), 'b');
1036 Style.Check_Identifier (Defining_Entity (N), New_S);
1039 Inherit_Renamed_Profile (New_S, Old_S);
1042 Set_Convention (New_S, Convention (Old_S));
1043 Set_Has_Completion (New_S, Inside_A_Generic);
1046 Check_Frozen_Renaming (N, New_S);
1048 end Analyze_Renamed_Entry;
1050 -----------------------------------
1051 -- Analyze_Renamed_Family_Member --
1052 -----------------------------------
1054 procedure Analyze_Renamed_Family_Member
1059 Nam : constant Node_Id := Name (N);
1060 P : constant Node_Id := Prefix (Nam);
1064 if (Is_Entity_Name (P) and then Ekind (Entity (P)) = E_Entry_Family)
1065 or else (Nkind (P) = N_Selected_Component
1067 Ekind (Entity (Selector_Name (P))) = E_Entry_Family)
1069 if Is_Entity_Name (P) then
1070 Old_S := Entity (P);
1072 Old_S := Entity (Selector_Name (P));
1075 if not Entity_Matches_Spec (Old_S, New_S) then
1076 Error_Msg_N ("entry family does not match specification", N);
1079 Check_Subtype_Conformant (New_S, Old_S, N);
1080 Generate_Reference (New_S, Defining_Entity (N), 'b');
1081 Style.Check_Identifier (Defining_Entity (N), New_S);
1084 Error_Msg_N ("no entry family matches specification", N);
1087 Set_Has_Completion (New_S, Inside_A_Generic);
1090 Check_Frozen_Renaming (N, New_S);
1092 end Analyze_Renamed_Family_Member;
1094 ---------------------------------
1095 -- Analyze_Subprogram_Renaming --
1096 ---------------------------------
1098 procedure Analyze_Subprogram_Renaming (N : Node_Id) is
1099 Spec : constant Node_Id := Specification (N);
1100 Save_83 : constant Boolean := Ada_83;
1101 Nam : constant Node_Id := Name (N);
1103 Old_S : Entity_Id := Empty;
1104 Rename_Spec : Entity_Id;
1105 Is_Actual : Boolean := False;
1106 Inst_Node : Node_Id := Empty;
1108 function Original_Subprogram (Subp : Entity_Id) return Entity_Id;
1109 -- Find renamed entity when the declaration is a renaming_as_body
1110 -- and the renamed entity may itself be a renaming_as_body. Used to
1111 -- enforce rule that a renaming_as_body is illegal if the declaration
1112 -- occurs before the subprogram it completes is frozen, and renaming
1113 -- indirectly renames the subprogram itself.(Defect Report 8652/0027).
1115 -------------------------
1116 -- Original_Subprogram --
1117 -------------------------
1119 function Original_Subprogram (Subp : Entity_Id) return Entity_Id is
1120 Orig_Decl : Node_Id;
1121 Orig_Subp : Entity_Id;
1124 -- First case: renamed entity is itself a renaming
1126 if Present (Alias (Subp)) then
1127 return Alias (Subp);
1130 Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration
1132 (Corresponding_Body (Unit_Declaration_Node (Subp)))
1134 -- Check if renamed entity is a renaming_as_body
1137 Unit_Declaration_Node
1138 (Corresponding_Body (Unit_Declaration_Node (Subp)));
1140 if Nkind (Orig_Decl) = N_Subprogram_Renaming_Declaration then
1141 Orig_Subp := Entity (Name (Orig_Decl));
1143 if Orig_Subp = Rename_Spec then
1145 -- Circularity detected.
1150 return (Original_Subprogram (Orig_Subp));
1158 end Original_Subprogram;
1160 -- Start of processing for Analyze_Subprogram_Renaming
1163 -- We must test for the attribute renaming case before the Analyze
1164 -- call because otherwise Sem_Attr will complain that the attribute
1165 -- is missing an argument when it is analyzed.
1167 if Nkind (Nam) = N_Attribute_Reference then
1168 Attribute_Renaming (N);
1172 -- Check whether this declaration corresponds to the instantiation
1173 -- of a formal subprogram. This is indicated by the presence of a
1174 -- Corresponding_Spec that is the instantiation declaration.
1176 -- If this is an instantiation, the corresponding actual is frozen
1177 -- and error messages can be made more precise. If this is a default
1178 -- subprogram, the entity is already established in the generic, and
1179 -- is not retrieved by visibility. If it is a default with a box, the
1180 -- candidate interpretations, if any, have been collected when building
1181 -- the renaming declaration. If overloaded, the proper interpretation
1182 -- is determined in Find_Renamed_Entity. If the entity is an operator,
1183 -- Find_Renamed_Entity applies additional visibility checks.
1185 if Present (Corresponding_Spec (N)) then
1187 Inst_Node := Unit_Declaration_Node (Corresponding_Spec (N));
1189 if Is_Entity_Name (Nam)
1190 and then Present (Entity (Nam))
1191 and then not Comes_From_Source (Nam)
1192 and then not Is_Overloaded (Nam)
1194 Old_S := Entity (Nam);
1195 New_S := Analyze_Subprogram_Specification (Spec);
1199 if Ekind (Entity (Nam)) = E_Operator then
1203 if Box_Present (Inst_Node) then
1204 Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
1206 -- If there is an immediately visible homonym of the operator
1207 -- and the declaration has a default, this is worth a warning
1208 -- because the user probably did not intend to get the pre-
1209 -- defined operator, visible in the generic declaration.
1210 -- To find if there is an intended candidate, analyze the
1211 -- renaming again in the current context.
1213 elsif Scope (Old_S) = Standard_Standard
1214 and then Present (Default_Name (Inst_Node))
1217 Decl : constant Node_Id := New_Copy_Tree (N);
1221 Set_Entity (Name (Decl), Empty);
1222 Analyze (Name (Decl));
1224 Find_Renamed_Entity (Decl, Name (Decl), New_S, True);
1227 and then In_Open_Scopes (Scope (Hidden))
1228 and then Is_Immediately_Visible (Hidden)
1229 and then Comes_From_Source (Hidden)
1230 and then Hidden /= Old_S
1232 Error_Msg_Sloc := Sloc (Hidden);
1233 Error_Msg_N ("?default subprogram is resolved " &
1234 "in the generic declaration " &
1235 "('R'M 12.6(17))", N);
1236 Error_Msg_NE ("\?and will not use & #", N, Hidden);
1244 New_S := Analyze_Subprogram_Specification (Spec);
1247 Set_Corresponding_Spec (N, Empty);
1250 -- Renamed entity must be analyzed first, to avoid being hidden by
1251 -- new name (which might be the same in a generic instance).
1255 -- The renaming defines a new overloaded entity, which is analyzed
1256 -- like a subprogram declaration.
1258 New_S := Analyze_Subprogram_Specification (Spec);
1261 if Current_Scope /= Standard_Standard then
1262 Set_Is_Pure (New_S, Is_Pure (Current_Scope));
1265 Rename_Spec := Find_Corresponding_Spec (N);
1267 if Present (Rename_Spec) then
1269 -- Renaming_As_Body. Renaming declaration is the completion of
1270 -- the declaration of Rename_Spec. We will build an actual body
1271 -- for it at the freezing point.
1273 Set_Corresponding_Spec (N, Rename_Spec);
1274 Set_Corresponding_Body (Unit_Declaration_Node (Rename_Spec), New_S);
1276 -- The body is created when the entity is frozen. If the context
1277 -- is generic, freeze_all is not invoked, so we need to indicate
1278 -- that the entity has a completion.
1280 Set_Has_Completion (Rename_Spec, Inside_A_Generic);
1282 if Ada_83 and then Comes_From_Source (N) then
1283 Error_Msg_N ("(Ada 83) renaming cannot serve as a body", N);
1286 Set_Convention (New_S, Convention (Rename_Spec));
1287 Check_Fully_Conformant (New_S, Rename_Spec);
1288 Set_Public_Status (New_S);
1290 -- Indicate that the entity in the declaration functions like
1291 -- the corresponding body, and is not a new entity.
1293 Set_Ekind (New_S, E_Subprogram_Body);
1294 New_S := Rename_Spec;
1297 Generate_Definition (New_S);
1298 New_Overloaded_Entity (New_S);
1299 if Is_Entity_Name (Nam)
1300 and then Is_Intrinsic_Subprogram (Entity (Nam))
1304 Check_Delayed_Subprogram (New_S);
1308 -- There is no need for elaboration checks on the new entity, which
1309 -- may be called before the next freezing point where the body will
1310 -- appear. Elaboration checks refer to the real entity, not the one
1311 -- created by the renaming declaration.
1313 Set_Kill_Elaboration_Checks (New_S, True);
1315 if Etype (Nam) = Any_Type then
1316 Set_Has_Completion (New_S);
1319 elsif Nkind (Nam) = N_Selected_Component then
1321 -- Renamed entity is an entry or protected subprogram. For those
1322 -- cases an explicit body is built (at the point of freezing of
1323 -- this entity) that contains a call to the renamed entity.
1325 Analyze_Renamed_Entry (N, New_S, Present (Rename_Spec));
1328 elsif Nkind (Nam) = N_Explicit_Dereference then
1330 -- Renamed entity is designated by access_to_subprogram expression.
1331 -- Must build body to encapsulate call, as in the entry case.
1333 Analyze_Renamed_Dereference (N, New_S, Present (Rename_Spec));
1336 elsif Nkind (Nam) = N_Indexed_Component then
1337 Analyze_Renamed_Family_Member (N, New_S, Present (Rename_Spec));
1340 elsif Nkind (Nam) = N_Character_Literal then
1341 Analyze_Renamed_Character (N, New_S, Present (Rename_Spec));
1344 elsif (not Is_Entity_Name (Nam)
1345 and then Nkind (Nam) /= N_Operator_Symbol)
1346 or else not Is_Overloadable (Entity (Nam))
1348 Error_Msg_N ("expect valid subprogram name in renaming", N);
1353 -- Most common case: subprogram renames subprogram. No body is
1354 -- generated in this case, so we must indicate that the declaration
1355 -- is complete as is.
1357 if No (Rename_Spec) then
1358 Set_Has_Completion (New_S);
1361 -- Find the renamed entity that matches the given specification.
1362 -- Disable Ada_83 because there is no requirement of full conformance
1363 -- between renamed entity and new entity, even though the same circuit
1369 Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
1372 if Old_S /= Any_Id then
1375 and then From_Default (N)
1377 -- This is an implicit reference to the default actual
1379 Generate_Reference (Old_S, Nam, Typ => 'i', Force => True);
1381 Generate_Reference (Old_S, Nam);
1384 -- For a renaming-as-body, require subtype conformance,
1385 -- but if the declaration being completed has not been
1386 -- frozen, then inherit the convention of the renamed
1387 -- subprogram prior to checking conformance (unless the
1388 -- renaming has an explicit convention established; the
1389 -- rule stated in the RM doesn't seem to address this ???).
1391 if Present (Rename_Spec) then
1392 Generate_Reference (Rename_Spec, Defining_Entity (Spec), 'b');
1393 Style.Check_Identifier (Defining_Entity (Spec), Rename_Spec);
1395 if not Is_Frozen (Rename_Spec) then
1396 if not Has_Convention_Pragma (Rename_Spec) then
1397 Set_Convention (New_S, Convention (Old_S));
1400 if Ekind (Old_S) /= E_Operator then
1401 Check_Mode_Conformant (New_S, Old_S, Spec);
1404 if Original_Subprogram (Old_S) = Rename_Spec then
1405 Error_Msg_N ("unfrozen subprogram cannot rename itself ", N);
1408 Check_Subtype_Conformant (New_S, Old_S, Spec);
1411 Check_Frozen_Renaming (N, Rename_Spec);
1413 elsif Ekind (Old_S) /= E_Operator then
1414 Check_Mode_Conformant (New_S, Old_S);
1417 and then Error_Posted (New_S)
1419 Error_Msg_NE ("invalid actual subprogram: & #!", N, Old_S);
1423 if No (Rename_Spec) then
1425 -- The parameter profile of the new entity is that of the renamed
1426 -- entity: the subtypes given in the specification are irrelevant.
1428 Inherit_Renamed_Profile (New_S, Old_S);
1430 -- A call to the subprogram is transformed into a call to the
1431 -- renamed entity. This is transitive if the renamed entity is
1432 -- itself a renaming.
1434 if Present (Alias (Old_S)) then
1435 Set_Alias (New_S, Alias (Old_S));
1437 Set_Alias (New_S, Old_S);
1440 -- Note that we do not set Is_Instrinsic_Subprogram if we have
1441 -- a renaming as body, since the entity in this case is not an
1442 -- intrinsic (it calls an intrinsic, but we have a real body
1443 -- for this call, and it is in this body that the required
1444 -- intrinsic processing will take place).
1446 -- Also, if this is a renaming of inequality, the renamed
1447 -- operator is intrinsic, but what matters is the corresponding
1448 -- equality operator, which may be user-defined.
1450 Set_Is_Intrinsic_Subprogram
1452 Is_Intrinsic_Subprogram (Old_S)
1454 (Chars (Old_S) /= Name_Op_Ne
1455 or else Ekind (Old_S) = E_Operator
1457 Is_Intrinsic_Subprogram
1458 (Corresponding_Equality (Old_S))));
1460 if Ekind (Alias (New_S)) = E_Operator then
1461 Set_Has_Delayed_Freeze (New_S, False);
1467 and then (Old_S = New_S
1468 or else (Nkind (Nam) /= N_Expanded_Name
1469 and then Chars (Old_S) = Chars (New_S)))
1471 Error_Msg_N ("subprogram cannot rename itself", N);
1474 Set_Convention (New_S, Convention (Old_S));
1475 Set_Is_Abstract (New_S, Is_Abstract (Old_S));
1476 Check_Library_Unit_Renaming (N, Old_S);
1478 -- Pathological case: procedure renames entry in the scope of
1479 -- its task. Entry is given by simple name, but body must be built
1480 -- for procedure. Of course if called it will deadlock.
1482 if Ekind (Old_S) = E_Entry then
1483 Set_Has_Completion (New_S, False);
1484 Set_Alias (New_S, Empty);
1488 Freeze_Before (N, Old_S);
1489 Set_Has_Delayed_Freeze (New_S, False);
1490 Freeze_Before (N, New_S);
1492 if (Ekind (Old_S) = E_Procedure or else Ekind (Old_S) = E_Function)
1493 and then Is_Abstract (Old_S)
1496 ("abstract subprogram not allowed as generic actual", Nam);
1501 -- A common error is to assume that implicit operators for types
1502 -- are defined in Standard, or in the scope of a subtype. In those
1503 -- cases where the renamed entity is given with an expanded name,
1504 -- it is worth mentioning that operators for the type are not
1505 -- declared in the scope given by the prefix.
1507 if Nkind (Nam) = N_Expanded_Name
1508 and then Nkind (Selector_Name (Nam)) = N_Operator_Symbol
1509 and then Scope (Entity (Nam)) = Standard_Standard
1512 T : constant Entity_Id :=
1513 Base_Type (Etype (First_Formal (New_S)));
1516 Error_Msg_Node_2 := Prefix (Nam);
1518 ("operator for type& is not declared in&", Prefix (Nam), T);
1523 ("no visible subprogram matches the specification for&",
1527 if Present (Candidate_Renaming) then
1533 F1 := First_Formal (Candidate_Renaming);
1534 F2 := First_Formal (New_S);
1536 while Present (F1) and then Present (F2) loop
1541 if Present (F1) and then Present (Default_Value (F1)) then
1542 if Present (Next_Formal (F1)) then
1544 ("\missing specification for &" &
1545 " and other formals with defaults", Spec, F1);
1548 ("\missing specification for &", Spec, F1);
1556 end Analyze_Subprogram_Renaming;
1558 -------------------------
1559 -- Analyze_Use_Package --
1560 -------------------------
1562 -- Resolve the package names in the use clause, and make all the visible
1563 -- entities defined in the package potentially use-visible. If the package
1564 -- is already in use from a previous use clause, its visible entities are
1565 -- already use-visible. In that case, mark the occurrence as a redundant
1566 -- use. If the package is an open scope, i.e. if the use clause occurs
1567 -- within the package itself, ignore it.
1569 procedure Analyze_Use_Package (N : Node_Id) is
1570 Pack_Name : Node_Id;
1573 -- Start of processing for Analyze_Use_Package
1576 Set_Hidden_By_Use_Clause (N, No_Elist);
1578 -- Use clause is not allowed in a spec of a predefined package
1579 -- declaration except that packages whose file name starts a-n
1580 -- are OK (these are children of Ada.Numerics, and such packages
1581 -- are never loaded by Rtsfind).
1583 if Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
1584 and then Name_Buffer (1 .. 3) /= "a-n"
1586 Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
1588 Error_Msg_N ("use clause not allowed in predefined spec", N);
1591 -- Chain clause to list of use clauses in current scope.
1593 if Nkind (Parent (N)) /= N_Compilation_Unit then
1594 Chain_Use_Clause (N);
1597 -- Loop through package names to identify referenced packages
1599 Pack_Name := First (Names (N));
1601 while Present (Pack_Name) loop
1602 Analyze (Pack_Name);
1604 if Nkind (Parent (N)) = N_Compilation_Unit
1605 and then Nkind (Pack_Name) = N_Expanded_Name
1608 Pref : Node_Id := Prefix (Pack_Name);
1611 while Nkind (Pref) = N_Expanded_Name loop
1612 Pref := Prefix (Pref);
1615 if Entity (Pref) = Standard_Standard then
1617 ("predefined package Standard cannot appear"
1618 & " in a context clause", Pref);
1626 -- Loop through package names to mark all entities as potentially
1629 Pack_Name := First (Names (N));
1631 while Present (Pack_Name) loop
1633 if Is_Entity_Name (Pack_Name) then
1634 Pack := Entity (Pack_Name);
1636 if Ekind (Pack) /= E_Package
1637 and then Etype (Pack) /= Any_Type
1639 if Ekind (Pack) = E_Generic_Package then
1641 ("a generic package is not allowed in a use clause",
1644 Error_Msg_N ("& is not a usable package", Pack_Name);
1648 if Nkind (Parent (N)) = N_Compilation_Unit then
1649 Check_In_Previous_With_Clause (N, Pack_Name);
1652 if Applicable_Use (Pack_Name) then
1653 Use_One_Package (Pack, N);
1661 end Analyze_Use_Package;
1663 ----------------------
1664 -- Analyze_Use_Type --
1665 ----------------------
1667 procedure Analyze_Use_Type (N : Node_Id) is
1671 Set_Hidden_By_Use_Clause (N, No_Elist);
1673 -- Chain clause to list of use clauses in current scope.
1675 if Nkind (Parent (N)) /= N_Compilation_Unit then
1676 Chain_Use_Clause (N);
1679 Id := First (Subtype_Marks (N));
1681 while Present (Id) loop
1684 if Entity (Id) /= Any_Type then
1687 if Nkind (Parent (N)) = N_Compilation_Unit then
1688 if Nkind (Id) = N_Identifier then
1689 Error_Msg_N ("Type is not directly visible", Id);
1691 elsif Is_Child_Unit (Scope (Entity (Id)))
1692 and then Scope (Entity (Id)) /= System_Aux_Id
1694 Check_In_Previous_With_Clause (N, Prefix (Id));
1701 end Analyze_Use_Type;
1703 --------------------
1704 -- Applicable_Use --
1705 --------------------
1707 function Applicable_Use (Pack_Name : Node_Id) return Boolean is
1708 Pack : constant Entity_Id := Entity (Pack_Name);
1711 if In_Open_Scopes (Pack) then
1714 elsif In_Use (Pack) then
1715 Set_Redundant_Use (Pack_Name, True);
1718 elsif Present (Renamed_Object (Pack))
1719 and then In_Use (Renamed_Object (Pack))
1721 Set_Redundant_Use (Pack_Name, True);
1729 ------------------------
1730 -- Attribute_Renaming --
1731 ------------------------
1733 procedure Attribute_Renaming (N : Node_Id) is
1734 Loc : constant Source_Ptr := Sloc (N);
1735 Nam : constant Node_Id := Name (N);
1736 Spec : constant Node_Id := Specification (N);
1737 New_S : constant Entity_Id := Defining_Unit_Name (Spec);
1738 Aname : constant Name_Id := Attribute_Name (Nam);
1740 Form_Num : Nat := 0;
1741 Expr_List : List_Id := No_List;
1743 Attr_Node : Node_Id;
1744 Body_Node : Node_Id;
1745 Param_Spec : Node_Id;
1748 Generate_Definition (New_S);
1750 -- This procedure is called in the context of subprogram renaming,
1751 -- and thus the attribute must be one that is a subprogram. All of
1752 -- those have at least one formal parameter, with the singular
1753 -- exception of AST_Entry (which is a real oddity, it is odd that
1754 -- this can be renamed at all!)
1756 if not Is_Non_Empty_List (Parameter_Specifications (Spec)) then
1757 if Aname /= Name_AST_Entry then
1759 ("subprogram renaming an attribute must have formals", N);
1764 Param_Spec := First (Parameter_Specifications (Spec));
1766 while Present (Param_Spec) loop
1767 Form_Num := Form_Num + 1;
1769 if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
1770 Find_Type (Parameter_Type (Param_Spec));
1772 -- The profile of the new entity denotes the base type (s) of
1773 -- the types given in the specification. For access parameters
1774 -- there are no subtypes involved.
1776 Rewrite (Parameter_Type (Param_Spec),
1778 (Base_Type (Entity (Parameter_Type (Param_Spec))), Loc));
1781 if No (Expr_List) then
1782 Expr_List := New_List;
1785 Append_To (Expr_List,
1786 Make_Identifier (Loc,
1787 Chars => Chars (Defining_Identifier (Param_Spec))));
1789 -- The expressions in the attribute reference are not freeze
1790 -- points. Neither is the attribute as a whole, see below.
1792 Set_Must_Not_Freeze (Last (Expr_List));
1797 -- Immediate error if too many formals. Other mismatches in numbers
1798 -- of number of types of parameters are detected when we analyze the
1799 -- body of the subprogram that we construct.
1801 if Form_Num > 2 then
1802 Error_Msg_N ("too many formals for attribute", N);
1805 Aname = Name_Compose or else
1806 Aname = Name_Exponent or else
1807 Aname = Name_Leading_Part or else
1808 Aname = Name_Pos or else
1809 Aname = Name_Round or else
1810 Aname = Name_Scaling or else
1813 if Nkind (N) = N_Subprogram_Renaming_Declaration
1814 and then Present (Corresponding_Spec (N))
1815 and then Nkind (Unit_Declaration_Node (Corresponding_Spec (N))) =
1816 N_Formal_Subprogram_Declaration
1819 ("generic actual cannot be attribute involving universal type",
1823 ("attribute involving a universal type cannot be renamed",
1828 -- AST_Entry is an odd case. It doesn't really make much sense to
1829 -- allow it to be renamed, but that's the DEC rule, so we have to
1830 -- do it right. The point is that the AST_Entry call should be made
1831 -- now, and what the function will return is the returned value.
1833 -- Note that there is no Expr_List in this case anyway
1835 if Aname = Name_AST_Entry then
1842 Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
1845 Make_Object_Declaration (Loc,
1846 Defining_Identifier => Ent,
1847 Object_Definition =>
1848 New_Occurrence_Of (RTE (RE_AST_Handler), Loc),
1850 Constant_Present => True);
1852 Set_Assignment_OK (Decl, True);
1853 Insert_Action (N, Decl);
1854 Attr_Node := Make_Identifier (Loc, Chars (Ent));
1857 -- For all other attributes, we rewrite the attribute node to have
1858 -- a list of expressions corresponding to the subprogram formals.
1859 -- A renaming declaration is not a freeze point, and the analysis of
1860 -- the attribute reference should not freeze the type of the prefix.
1864 Make_Attribute_Reference (Loc,
1865 Prefix => Prefix (Nam),
1866 Attribute_Name => Aname,
1867 Expressions => Expr_List);
1869 Set_Must_Not_Freeze (Attr_Node);
1870 Set_Must_Not_Freeze (Prefix (Nam));
1873 -- Case of renaming a function
1875 if Nkind (Spec) = N_Function_Specification then
1877 if Is_Procedure_Attribute_Name (Aname) then
1878 Error_Msg_N ("attribute can only be renamed as procedure", Nam);
1882 Find_Type (Subtype_Mark (Spec));
1883 Rewrite (Subtype_Mark (Spec),
1884 New_Reference_To (Base_Type (Entity (Subtype_Mark (Spec))), Loc));
1887 Make_Subprogram_Body (Loc,
1888 Specification => Spec,
1889 Declarations => New_List,
1890 Handled_Statement_Sequence =>
1891 Make_Handled_Sequence_Of_Statements (Loc,
1892 Statements => New_List (
1893 Make_Return_Statement (Loc,
1894 Expression => Attr_Node))));
1896 -- Case of renaming a procedure
1899 if not Is_Procedure_Attribute_Name (Aname) then
1900 Error_Msg_N ("attribute can only be renamed as function", Nam);
1905 Make_Subprogram_Body (Loc,
1906 Specification => Spec,
1907 Declarations => New_List,
1908 Handled_Statement_Sequence =>
1909 Make_Handled_Sequence_Of_Statements (Loc,
1910 Statements => New_List (Attr_Node)));
1913 Rewrite (N, Body_Node);
1916 Set_Etype (New_S, Base_Type (Etype (New_S)));
1918 -- We suppress elaboration warnings for the resulting entity, since
1919 -- clearly they are not needed, and more particularly, in the case
1920 -- of a generic formal subprogram, the resulting entity can appear
1921 -- after the instantiation itself, and thus look like a bogus case
1922 -- of access before elaboration.
1924 Set_Suppress_Elaboration_Warnings (New_S);
1926 end Attribute_Renaming;
1928 ----------------------
1929 -- Chain_Use_Clause --
1930 ----------------------
1932 procedure Chain_Use_Clause (N : Node_Id) is
1934 Set_Next_Use_Clause (N,
1935 Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause);
1936 Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause := N;
1937 end Chain_Use_Clause;
1939 ----------------------------
1940 -- Check_Frozen_Renaming --
1941 ----------------------------
1943 procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id) is
1949 and then not Has_Completion (Subp)
1953 (Parent (Declaration_Node (Subp)), Defining_Entity (N));
1955 if Is_Entity_Name (Name (N)) then
1956 Old_S := Entity (Name (N));
1958 if not Is_Frozen (Old_S)
1959 and then Operating_Mode /= Check_Semantics
1961 Append_Freeze_Action (Old_S, B_Node);
1963 Insert_After (N, B_Node);
1967 if Is_Intrinsic_Subprogram (Old_S)
1968 and then not In_Instance
1971 ("subprogram used in renaming_as_body cannot be intrinsic",
1976 Insert_After (N, B_Node);
1980 end Check_Frozen_Renaming;
1982 -----------------------------------
1983 -- Check_In_Previous_With_Clause --
1984 -----------------------------------
1986 procedure Check_In_Previous_With_Clause
1990 Pack : constant Entity_Id := Entity (Original_Node (Nam));
1995 Item := First (Context_Items (Parent (N)));
1997 while Present (Item)
2000 if Nkind (Item) = N_With_Clause
2001 and then Entity (Name (Item)) = Pack
2005 -- Find root library unit in with_clause.
2007 while Nkind (Par) = N_Expanded_Name loop
2008 Par := Prefix (Par);
2011 if Is_Child_Unit (Entity (Original_Node (Par))) then
2013 ("& is not directly visible", Par, Entity (Par));
2022 -- On exit, package is not mentioned in a previous with_clause.
2023 -- Check if its prefix is.
2025 if Nkind (Nam) = N_Expanded_Name then
2026 Check_In_Previous_With_Clause (N, Prefix (Nam));
2028 elsif Pack /= Any_Id then
2029 Error_Msg_NE ("& is not visible", Nam, Pack);
2031 end Check_In_Previous_With_Clause;
2033 ---------------------------------
2034 -- Check_Library_Unit_Renaming --
2035 ---------------------------------
2037 procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id) is
2041 if Nkind (Parent (N)) /= N_Compilation_Unit then
2044 elsif Scope (Old_E) /= Standard_Standard
2045 and then not Is_Child_Unit (Old_E)
2047 Error_Msg_N ("renamed unit must be a library unit", Name (N));
2049 elsif Present (Parent_Spec (N))
2050 and then Nkind (Unit (Parent_Spec (N))) = N_Generic_Package_Declaration
2051 and then not Is_Child_Unit (Old_E)
2054 ("renamed unit must be a child unit of generic parent", Name (N));
2056 elsif Nkind (N) in N_Generic_Renaming_Declaration
2057 and then Nkind (Name (N)) = N_Expanded_Name
2058 and then Is_Generic_Instance (Entity (Prefix (Name (N))))
2059 and then Is_Generic_Unit (Old_E)
2062 ("renamed generic unit must be a library unit", Name (N));
2064 elsif Ekind (Old_E) = E_Package
2065 or else Ekind (Old_E) = E_Generic_Package
2067 -- Inherit categorization flags
2069 New_E := Defining_Entity (N);
2070 Set_Is_Pure (New_E, Is_Pure (Old_E));
2071 Set_Is_Preelaborated (New_E, Is_Preelaborated (Old_E));
2072 Set_Is_Remote_Call_Interface (New_E,
2073 Is_Remote_Call_Interface (Old_E));
2074 Set_Is_Remote_Types (New_E, Is_Remote_Types (Old_E));
2075 Set_Is_Shared_Passive (New_E, Is_Shared_Passive (Old_E));
2077 end Check_Library_Unit_Renaming;
2083 procedure End_Scope is
2089 Id := First_Entity (Current_Scope);
2091 while Present (Id) loop
2092 -- An entity in the current scope is not necessarily the first one
2093 -- on its homonym chain. Find its predecessor if any,
2094 -- If it is an internal entity, it will not be in the visibility
2095 -- chain altogether, and there is nothing to unchain.
2097 if Id /= Current_Entity (Id) then
2098 Prev := Current_Entity (Id);
2099 while Present (Prev)
2100 and then Present (Homonym (Prev))
2101 and then Homonym (Prev) /= Id
2103 Prev := Homonym (Prev);
2106 -- Skip to end of loop if Id is not in the visibility chain
2108 if No (Prev) or else Homonym (Prev) /= Id then
2116 Outer := Homonym (Id);
2117 Set_Is_Immediately_Visible (Id, False);
2119 while Present (Outer) and then Scope (Outer) = Current_Scope loop
2120 Outer := Homonym (Outer);
2123 -- Reset homonym link of other entities, but do not modify link
2124 -- between entities in current scope, so that the back-end can have
2125 -- a proper count of local overloadings.
2128 Set_Name_Entity_Id (Chars (Id), Outer);
2130 elsif Scope (Prev) /= Scope (Id) then
2131 Set_Homonym (Prev, Outer);
2138 -- If the scope generated freeze actions, place them before the
2139 -- current declaration and analyze them. Type declarations and
2140 -- the bodies of initialization procedures can generate such nodes.
2141 -- We follow the parent chain until we reach a list node, which is
2142 -- the enclosing list of declarations. If the list appears within
2143 -- a protected definition, move freeze nodes outside the protected
2147 (Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions)
2151 L : constant List_Id := Scope_Stack.Table
2152 (Scope_Stack.Last).Pending_Freeze_Actions;
2155 if Is_Itype (Current_Scope) then
2156 Decl := Associated_Node_For_Itype (Current_Scope);
2158 Decl := Parent (Current_Scope);
2163 while not (Is_List_Member (Decl))
2164 or else Nkind (Parent (Decl)) = N_Protected_Definition
2165 or else Nkind (Parent (Decl)) = N_Task_Definition
2167 Decl := Parent (Decl);
2170 Insert_List_Before_And_Analyze (Decl, L);
2179 ---------------------
2180 -- End_Use_Clauses --
2181 ---------------------
2183 procedure End_Use_Clauses (Clause : Node_Id) is
2187 -- Remove Use_Type clauses first, because they affect the
2188 -- visibility of operators in subsequent used packages.
2191 while Present (U) loop
2192 if Nkind (U) = N_Use_Type_Clause then
2196 Next_Use_Clause (U);
2200 while Present (U) loop
2201 if Nkind (U) = N_Use_Package_Clause then
2202 End_Use_Package (U);
2205 Next_Use_Clause (U);
2207 end End_Use_Clauses;
2209 ---------------------
2210 -- End_Use_Package --
2211 ---------------------
2213 procedure End_Use_Package (N : Node_Id) is
2214 Pack_Name : Node_Id;
2219 function Is_Primitive_Operator
2221 F : Entity_Id) return Boolean;
2222 -- Check whether Op is a primitive operator of a use-visible type
2224 ---------------------------
2225 -- Is_Primitive_Operator --
2226 ---------------------------
2228 function Is_Primitive_Operator
2230 F : Entity_Id) return Boolean
2232 T : constant Entity_Id := Etype (F);
2236 and then Scope (T) = Scope (Op);
2237 end Is_Primitive_Operator;
2239 -- Start of processing for End_Use_Package
2242 Pack_Name := First (Names (N));
2244 while Present (Pack_Name) loop
2245 Pack := Entity (Pack_Name);
2247 if Ekind (Pack) = E_Package then
2249 if In_Open_Scopes (Pack) then
2252 elsif not Redundant_Use (Pack_Name) then
2253 Set_In_Use (Pack, False);
2254 Id := First_Entity (Pack);
2256 while Present (Id) loop
2258 -- Preserve use-visibility of operators that are primitive
2259 -- operators of a type that is use_visible through an active
2262 if Nkind (Id) = N_Defining_Operator_Symbol
2264 (Is_Primitive_Operator (Id, First_Formal (Id))
2266 (Present (Next_Formal (First_Formal (Id)))
2268 Is_Primitive_Operator
2269 (Id, Next_Formal (First_Formal (Id)))))
2274 Set_Is_Potentially_Use_Visible (Id, False);
2277 if Is_Private_Type (Id)
2278 and then Present (Full_View (Id))
2280 Set_Is_Potentially_Use_Visible (Full_View (Id), False);
2286 if Present (Renamed_Object (Pack)) then
2287 Set_In_Use (Renamed_Object (Pack), False);
2290 if Chars (Pack) = Name_System
2291 and then Scope (Pack) = Standard_Standard
2292 and then Present_System_Aux
2294 Id := First_Entity (System_Aux_Id);
2296 while Present (Id) loop
2297 Set_Is_Potentially_Use_Visible (Id, False);
2299 if Is_Private_Type (Id)
2300 and then Present (Full_View (Id))
2302 Set_Is_Potentially_Use_Visible (Full_View (Id), False);
2308 Set_In_Use (System_Aux_Id, False);
2312 Set_Redundant_Use (Pack_Name, False);
2320 if Present (Hidden_By_Use_Clause (N)) then
2321 Elmt := First_Elmt (Hidden_By_Use_Clause (N));
2323 while Present (Elmt) loop
2324 Set_Is_Immediately_Visible (Node (Elmt));
2328 Set_Hidden_By_Use_Clause (N, No_Elist);
2330 end End_Use_Package;
2336 procedure End_Use_Type (N : Node_Id) is
2343 Id := First (Subtype_Marks (N));
2345 while Present (Id) loop
2347 -- A call to rtsfind may occur while analyzing a use_type clause,
2348 -- in which case the type marks are not resolved yet, and there is
2349 -- nothing to remove.
2351 if not Is_Entity_Name (Id)
2352 or else No (Entity (Id))
2359 if T = Any_Type then
2362 -- Note that the use_Type clause may mention a subtype of the
2363 -- type whose primitive operations have been made visible. Here
2364 -- as elsewhere, it is the base type that matters for visibility.
2366 elsif In_Open_Scopes (Scope (Base_Type (T))) then
2369 elsif not Redundant_Use (Id) then
2370 Set_In_Use (T, False);
2371 Set_In_Use (Base_Type (T), False);
2372 Op_List := Collect_Primitive_Operations (T);
2373 Elmt := First_Elmt (Op_List);
2375 while Present (Elmt) loop
2377 if Nkind (Node (Elmt)) = N_Defining_Operator_Symbol then
2378 Set_Is_Potentially_Use_Visible (Node (Elmt), False);
2390 ----------------------
2391 -- Find_Direct_Name --
2392 ----------------------
2394 procedure Find_Direct_Name (N : Node_Id) is
2399 Inst : Entity_Id := Empty;
2400 -- Enclosing instance, if any.
2402 Homonyms : Entity_Id;
2403 -- Saves start of homonym chain
2405 Nvis_Entity : Boolean;
2406 -- Set True to indicate that at there is at least one entity on the
2407 -- homonym chain which, while not visible, is visible enough from the
2408 -- user point of view to warrant an error message of "not visible"
2409 -- rather than undefined.
2411 Nvis_Is_Private_Subprg : Boolean := False;
2412 -- Ada 0Y (AI-262): Set True to indicate that a form of Beaujolais
2413 -- effect concerning library subprograms has been detected. Used to
2414 -- generate the precise error message.
2416 function From_Actual_Package (E : Entity_Id) return Boolean;
2417 -- Returns true if the entity is declared in a package that is
2418 -- an actual for a formal package of the current instance. Such an
2419 -- entity requires special handling because it may be use-visible
2420 -- but hides directly visible entities defined outside the instance.
2422 function Known_But_Invisible (E : Entity_Id) return Boolean;
2423 -- This function determines whether the entity E (which is not
2424 -- visible) can reasonably be considered to be known to the writer
2425 -- of the reference. This is a heuristic test, used only for the
2426 -- purposes of figuring out whether we prefer to complain that an
2427 -- entity is undefined or invisible (and identify the declaration
2428 -- of the invisible entity in the latter case). The point here is
2429 -- that we don't want to complain that something is invisible and
2430 -- then point to something entirely mysterious to the writer.
2432 procedure Nvis_Messages;
2433 -- Called if there are no visible entries for N, but there is at least
2434 -- one non-directly visible, or hidden declaration. This procedure
2435 -- outputs an appropriate set of error messages.
2437 procedure Undefined (Nvis : Boolean);
2438 -- This function is called if the current node has no corresponding
2439 -- visible entity or entities. The value set in Msg indicates whether
2440 -- an error message was generated (multiple error messages for the
2441 -- same variable are generally suppressed, see body for details).
2442 -- Msg is True if an error message was generated, False if not. This
2443 -- value is used by the caller to determine whether or not to output
2444 -- additional messages where appropriate. The parameter is set False
2445 -- to get the message "X is undefined", and True to get the message
2446 -- "X is not visible".
2448 -------------------------
2449 -- From_Actual_Package --
2450 -------------------------
2452 function From_Actual_Package (E : Entity_Id) return Boolean is
2453 Scop : constant Entity_Id := Scope (E);
2457 if not In_Instance then
2460 Inst := Current_Scope;
2462 while Present (Inst)
2463 and then Ekind (Inst) /= E_Package
2464 and then not Is_Generic_Instance (Inst)
2466 Inst := Scope (Inst);
2473 Act := First_Entity (Inst);
2475 while Present (Act) loop
2476 if Ekind (Act) = E_Package then
2478 -- Check for end of actuals list
2480 if Renamed_Object (Act) = Inst then
2483 elsif Present (Associated_Formal_Package (Act))
2484 and then Renamed_Object (Act) = Scop
2486 -- Entity comes from (instance of) formal package
2501 end From_Actual_Package;
2503 -------------------------
2504 -- Known_But_Invisible --
2505 -------------------------
2507 function Known_But_Invisible (E : Entity_Id) return Boolean is
2508 Fname : File_Name_Type;
2511 -- Entities in Standard are always considered to be known
2513 if Sloc (E) <= Standard_Location then
2516 -- An entity that does not come from source is always considered
2517 -- to be unknown, since it is an artifact of code expansion.
2519 elsif not Comes_From_Source (E) then
2522 -- In gnat internal mode, we consider all entities known
2524 elsif GNAT_Mode then
2528 -- Here we have an entity that is not from package Standard, and
2529 -- which comes from Source. See if it comes from an internal file.
2531 Fname := Unit_File_Name (Get_Source_Unit (E));
2533 -- Case of from internal file
2535 if Is_Internal_File_Name (Fname) then
2537 -- Private part entities in internal files are never considered
2538 -- to be known to the writer of normal application code.
2540 if Is_Hidden (E) then
2544 -- Entities from System packages other than System and
2545 -- System.Storage_Elements are not considered to be known.
2546 -- System.Auxxxx files are also considered known to the user.
2548 -- Should refine this at some point to generally distinguish
2549 -- between known and unknown internal files ???
2551 Get_Name_String (Fname);
2556 Name_Buffer (1 .. 2) /= "s-"
2558 Name_Buffer (3 .. 8) = "stoele"
2560 Name_Buffer (3 .. 5) = "aux";
2562 -- If not an internal file, then entity is definitely known,
2563 -- even if it is in a private part (the message generated will
2564 -- note that it is in a private part)
2569 end Known_But_Invisible;
2575 procedure Nvis_Messages is
2576 Comp_Unit : Node_Id;
2578 Hidden : Boolean := False;
2582 -- Ada 0Y (AI-262): Generate a precise error concerning the
2583 -- Beaujolais effect that was previously detected
2585 if Nvis_Is_Private_Subprg then
2587 pragma Assert (Nkind (E2) = N_Defining_Identifier
2588 and then Ekind (E2) = E_Function
2589 and then Scope (E2) = Standard_Standard
2590 and then Has_Private_With (E2));
2592 -- Find the sloc corresponding to the private with'ed unit
2594 Comp_Unit := Cunit (Current_Sem_Unit);
2595 Item := First (Context_Items (Comp_Unit));
2596 Error_Msg_Sloc := No_Location;
2598 while Present (Item) loop
2599 if Nkind (Item) = N_With_Clause
2600 and then Private_Present (Item)
2601 and then Entity (Name (Item)) = E2
2603 Error_Msg_Sloc := Sloc (Item);
2610 pragma Assert (Error_Msg_Sloc /= No_Location);
2612 Error_Msg_N ("(Ada 0Y): hidden by private with clause #", N);
2616 Undefined (Nvis => True);
2620 -- First loop does hidden declarations
2623 while Present (Ent) loop
2624 if Is_Potentially_Use_Visible (Ent) then
2627 Error_Msg_N ("multiple use clauses cause hiding!", N);
2631 Error_Msg_Sloc := Sloc (Ent);
2632 Error_Msg_N ("hidden declaration#!", N);
2635 Ent := Homonym (Ent);
2638 -- If we found hidden declarations, then that's enough, don't
2639 -- bother looking for non-visible declarations as well.
2645 -- Second loop does non-directly visible declarations
2648 while Present (Ent) loop
2649 if not Is_Potentially_Use_Visible (Ent) then
2651 -- Do not bother the user with unknown entities
2653 if not Known_But_Invisible (Ent) then
2657 Error_Msg_Sloc := Sloc (Ent);
2659 -- Output message noting that there is a non-visible
2660 -- declaration, distinguishing the private part case.
2662 if Is_Hidden (Ent) then
2663 Error_Msg_N ("non-visible (private) declaration#!", N);
2665 Error_Msg_N ("non-visible declaration#!", N);
2667 if Is_Compilation_Unit (Ent)
2669 Nkind (Parent (Parent (N))) = N_Use_Package_Clause
2672 ("\possibly missing with_clause for&", N, Ent);
2676 -- Set entity and its containing package as referenced. We
2677 -- can't be sure of this, but this seems a better choice
2678 -- to avoid unused entity messages.
2680 if Comes_From_Source (Ent) then
2681 Set_Referenced (Ent);
2682 Set_Referenced (Cunit_Entity (Get_Source_Unit (Ent)));
2687 Ent := Homonym (Ent);
2697 procedure Undefined (Nvis : Boolean) is
2698 Emsg : Error_Msg_Id;
2701 -- We should never find an undefined internal name. If we do, then
2702 -- see if we have previous errors. If so, ignore on the grounds that
2703 -- it is probably a cascaded message (e.g. a block label from a badly
2704 -- formed block). If no previous errors, then we have a real internal
2705 -- error of some kind so raise an exception.
2707 if Is_Internal_Name (Chars (N)) then
2708 if Total_Errors_Detected /= 0 then
2711 raise Program_Error;
2715 -- A very specialized error check, if the undefined variable is
2716 -- a case tag, and the case type is an enumeration type, check
2717 -- for a possible misspelling, and if so, modify the identifier
2719 -- Named aggregate should also be handled similarly ???
2721 if Nkind (N) = N_Identifier
2722 and then Nkind (Parent (N)) = N_Case_Statement_Alternative
2724 Get_Name_String (Chars (N));
2727 Case_Str : constant String := Name_Buffer (1 .. Name_Len);
2728 Case_Stm : constant Node_Id := Parent (Parent (N));
2729 Case_Typ : constant Entity_Id := Etype (Expression (Case_Stm));
2734 if Is_Enumeration_Type (Case_Typ)
2735 and then Case_Typ /= Standard_Character
2736 and then Case_Typ /= Standard_Wide_Character
2738 Lit := First_Literal (Case_Typ);
2739 Get_Name_String (Chars (Lit));
2741 if Chars (Lit) /= Chars (N)
2742 and then Is_Bad_Spelling_Of
2743 (Case_Str, Name_Buffer (1 .. Name_Len))
2745 Error_Msg_Node_2 := Lit;
2747 ("& is undefined, assume misspelling of &", N);
2748 Rewrite (N, New_Occurrence_Of (Lit, Sloc (N)));
2752 Lit := Next_Literal (Lit);
2757 -- Normal processing
2759 Set_Entity (N, Any_Id);
2760 Set_Etype (N, Any_Type);
2762 -- We use the table Urefs to keep track of entities for which we
2763 -- have issued errors for undefined references. Multiple errors
2764 -- for a single name are normally suppressed, however we modify
2765 -- the error message to alert the programmer to this effect.
2767 for J in Urefs.First .. Urefs.Last loop
2768 if Chars (N) = Chars (Urefs.Table (J).Node) then
2769 if Urefs.Table (J).Err /= No_Error_Msg
2770 and then Sloc (N) /= Urefs.Table (J).Loc
2772 Error_Msg_Node_1 := Urefs.Table (J).Node;
2774 if Urefs.Table (J).Nvis then
2775 Change_Error_Text (Urefs.Table (J).Err,
2776 "& is not visible (more references follow)");
2778 Change_Error_Text (Urefs.Table (J).Err,
2779 "& is undefined (more references follow)");
2782 Urefs.Table (J).Err := No_Error_Msg;
2785 -- Although we will set Msg False, and thus suppress the
2786 -- message, we also set Error_Posted True, to avoid any
2787 -- cascaded messages resulting from the undefined reference.
2790 Set_Error_Posted (N, True);
2795 -- If entry not found, this is first undefined occurrence
2798 Error_Msg_N ("& is not visible!", N);
2802 Error_Msg_N ("& is undefined!", N);
2805 -- A very bizarre special check, if the undefined identifier
2806 -- is put or put_line, then add a special error message (since
2807 -- this is a very common error for beginners to make).
2809 if Chars (N) = Name_Put or else Chars (N) = Name_Put_Line then
2810 Error_Msg_N ("\possible missing with of 'Text_'I'O!", N);
2813 -- Now check for possible misspellings
2815 Get_Name_String (Chars (N));
2819 Ematch : Entity_Id := Empty;
2821 Last_Name_Id : constant Name_Id :=
2822 Name_Id (Nat (First_Name_Id) +
2823 Name_Entries_Count - 1);
2825 S : constant String (1 .. Name_Len) :=
2826 Name_Buffer (1 .. Name_Len);
2829 for N in First_Name_Id .. Last_Name_Id loop
2830 E := Get_Name_Entity_Id (N);
2833 and then (Is_Immediately_Visible (E)
2835 Is_Potentially_Use_Visible (E))
2837 Get_Name_String (N);
2839 if Is_Bad_Spelling_Of
2840 (Name_Buffer (1 .. Name_Len), S)
2848 if Present (Ematch) then
2849 Error_Msg_NE ("\possible misspelling of&", N, Ematch);
2854 -- Make entry in undefined references table unless the full
2855 -- errors switch is set, in which case by refraining from
2856 -- generating the table entry, we guarantee that we get an
2857 -- error message for every undefined reference.
2859 if not All_Errors_Mode then
2860 Urefs.Increment_Last;
2861 Urefs.Table (Urefs.Last).Node := N;
2862 Urefs.Table (Urefs.Last).Err := Emsg;
2863 Urefs.Table (Urefs.Last).Nvis := Nvis;
2864 Urefs.Table (Urefs.Last).Loc := Sloc (N);
2870 -- Start of processing for Find_Direct_Name
2873 -- If the entity pointer is already set, this is an internal node, or
2874 -- a node that is analyzed more than once, after a tree modification.
2875 -- In such a case there is no resolution to perform, just set the type.
2877 if Present (Entity (N)) then
2878 if Is_Type (Entity (N)) then
2879 Set_Etype (N, Entity (N));
2883 Entyp : constant Entity_Id := Etype (Entity (N));
2886 -- One special case here. If the Etype field is already set,
2887 -- and references the packed array type corresponding to the
2888 -- etype of the referenced entity, then leave it alone. This
2889 -- happens for trees generated from Exp_Pakd, where expressions
2890 -- can be deliberately "mis-typed" to the packed array type.
2892 if Is_Array_Type (Entyp)
2893 and then Is_Packed (Entyp)
2894 and then Present (Etype (N))
2895 and then Etype (N) = Packed_Array_Type (Entyp)
2899 -- If not that special case, then just reset the Etype
2902 Set_Etype (N, Etype (Entity (N)));
2910 -- Here if Entity pointer was not set, we need full visibility analysis
2911 -- First we generate debugging output if the debug E flag is set.
2913 if Debug_Flag_E then
2914 Write_Str ("Looking for ");
2915 Write_Name (Chars (N));
2919 Homonyms := Current_Entity (N);
2920 Nvis_Entity := False;
2923 while Present (E) loop
2925 -- If entity is immediately visible or potentially use
2926 -- visible, then process the entity and we are done.
2928 if Is_Immediately_Visible (E) then
2929 goto Immediately_Visible_Entity;
2931 elsif Is_Potentially_Use_Visible (E) then
2932 goto Potentially_Use_Visible_Entity;
2934 -- Note if a known but invisible entity encountered
2936 elsif Known_But_Invisible (E) then
2937 Nvis_Entity := True;
2940 -- Move to next entity in chain and continue search
2945 -- If no entries on homonym chain that were potentially visible,
2946 -- and no entities reasonably considered as non-visible, then
2947 -- we have a plain undefined reference, with no additional
2948 -- explanation required!
2950 if not Nvis_Entity then
2951 Undefined (Nvis => False);
2953 -- Otherwise there is at least one entry on the homonym chain that
2954 -- is reasonably considered as being known and non-visible.
2962 -- Processing for a potentially use visible entry found. We must search
2963 -- the rest of the homonym chain for two reasons. First, if there is a
2964 -- directly visible entry, then none of the potentially use-visible
2965 -- entities are directly visible (RM 8.4(10)). Second, we need to check
2966 -- for the case of multiple potentially use-visible entries hiding one
2967 -- another and as a result being non-directly visible (RM 8.4(11)).
2969 <<Potentially_Use_Visible_Entity>> declare
2970 Only_One_Visible : Boolean := True;
2971 All_Overloadable : Boolean := Is_Overloadable (E);
2976 while Present (E2) loop
2977 if Is_Immediately_Visible (E2) then
2979 -- If the use-visible entity comes from the actual for a
2980 -- formal package, it hides a directly visible entity from
2981 -- outside the instance.
2983 if From_Actual_Package (E)
2984 and then Scope_Depth (E2) < Scope_Depth (Inst)
2989 goto Immediately_Visible_Entity;
2992 elsif Is_Potentially_Use_Visible (E2) then
2993 Only_One_Visible := False;
2994 All_Overloadable := All_Overloadable and Is_Overloadable (E2);
2996 -- Ada 0Y (AI-262): Protect against a form of Beujolais effect
2997 -- that can occurr in private_with clauses. Example:
3000 -- private with B; package A is
3001 -- package C is function B return Integer;
3003 -- V1 : Integer := B;
3004 -- private function B return Integer;
3005 -- V2 : Integer := B;
3008 -- V1 resolves to A.B, but V2 resolves to library unit B.
3010 elsif Ekind (E2) = E_Function
3011 and then Scope (E2) = Standard_Standard
3012 and then Has_Private_With (E2)
3014 Only_One_Visible := False;
3015 All_Overloadable := False;
3016 Nvis_Is_Private_Subprg := True;
3023 -- On falling through this loop, we have checked that there are no
3024 -- immediately visible entities. Only_One_Visible is set if exactly
3025 -- one potentially use visible entity exists. All_Overloadable is
3026 -- set if all the potentially use visible entities are overloadable.
3027 -- The condition for legality is that either there is one potentially
3028 -- use visible entity, or if there is more than one, then all of them
3029 -- are overloadable.
3031 if Only_One_Visible or All_Overloadable then
3034 -- If there is more than one potentially use-visible entity and at
3035 -- least one of them non-overloadable, we have an error (RM 8.4(11).
3036 -- Note that E points to the first such entity on the homonym list.
3037 -- Special case: if one of the entities is declared in an actual
3038 -- package, it was visible in the generic, and takes precedence over
3039 -- other entities that are potentially use-visible. Same if it is
3040 -- declared in a local instantiation of the current instance.
3044 Inst := Current_Scope;
3046 -- Find current instance.
3048 while Present (Inst)
3049 and then Inst /= Standard_Standard
3051 if Is_Generic_Instance (Inst) then
3055 Inst := Scope (Inst);
3060 while Present (E2) loop
3061 if From_Actual_Package (E2)
3063 (Is_Generic_Instance (Scope (E2))
3064 and then Scope_Depth (Scope (E2)) > Scope_Depth (Inst))
3083 -- Come here with E set to the first immediately visible entity on
3084 -- the homonym chain. This is the one we want unless there is another
3085 -- immediately visible entity further on in the chain for a more
3086 -- inner scope (RM 8.3(8)).
3088 <<Immediately_Visible_Entity>> declare
3093 -- Find scope level of initial entity. When compiling through
3094 -- Rtsfind, the previous context is not completely invisible, and
3095 -- an outer entity may appear on the chain, whose scope is below
3096 -- the entry for Standard that delimits the current scope stack.
3097 -- Indicate that the level for this spurious entry is outside of
3098 -- the current scope stack.
3100 Level := Scope_Stack.Last;
3102 Scop := Scope_Stack.Table (Level).Entity;
3103 exit when Scop = Scope (E);
3105 exit when Scop = Standard_Standard;
3108 -- Now search remainder of homonym chain for more inner entry
3109 -- If the entity is Standard itself, it has no scope, and we
3110 -- compare it with the stack entry directly.
3113 while Present (E2) loop
3114 if Is_Immediately_Visible (E2) then
3115 for J in Level + 1 .. Scope_Stack.Last loop
3116 if Scope_Stack.Table (J).Entity = Scope (E2)
3117 or else Scope_Stack.Table (J).Entity = E2
3129 -- At the end of that loop, E is the innermost immediately
3130 -- visible entity, so we are all set.
3133 -- Come here with entity found, and stored in E
3137 if Comes_From_Source (N)
3138 and then Is_Remote_Access_To_Subprogram_Type (E)
3139 and then Expander_Active
3142 New_Occurrence_Of (Equivalent_Type (E), Sloc (N)));
3147 -- Why no Style_Check here???
3152 Set_Etype (N, Get_Full_View (Etype (E)));
3155 if Debug_Flag_E then
3156 Write_Str (" found ");
3157 Write_Entity_Info (E, " ");
3160 -- If the Ekind of the entity is Void, it means that all homonyms
3161 -- are hidden from all visibility (RM 8.3(5,14-20)). However, this
3162 -- test is skipped if the current scope is a record and the name is
3163 -- a pragma argument expression (case of Atomic and Volatile pragmas
3164 -- and possibly other similar pragmas added later, which are allowed
3165 -- to reference components in the current record).
3167 if Ekind (E) = E_Void
3169 (not Is_Record_Type (Current_Scope)
3170 or else Nkind (Parent (N)) /= N_Pragma_Argument_Association)
3172 Premature_Usage (N);
3174 -- If the entity is overloadable, collect all interpretations
3175 -- of the name for subsequent overload resolution. We optimize
3176 -- a bit here to do this only if we have an overloadable entity
3177 -- that is not on its own on the homonym chain.
3179 elsif Is_Overloadable (E)
3180 and then (Present (Homonym (E)) or else Current_Entity (N) /= E)
3182 Collect_Interps (N);
3184 -- If no homonyms were visible, the entity is unambiguous.
3186 if not Is_Overloaded (N) then
3187 Generate_Reference (E, N);
3190 -- Case of non-overloadable entity, set the entity providing that
3191 -- we do not have the case of a discriminant reference within a
3192 -- default expression. Such references are replaced with the
3193 -- corresponding discriminal, which is the formal corresponding to
3194 -- to the discriminant in the initialization procedure.
3197 -- Entity is unambiguous, indicate that it is referenced here
3198 -- One slightly odd case is that we do not want to set the
3199 -- Referenced flag if the entity is a label, and the identifier
3200 -- is the label in the source, since this is not a reference
3201 -- from the point of view of the user
3203 if Nkind (Parent (N)) = N_Label then
3205 R : constant Boolean := Referenced (E);
3208 Generate_Reference (E, N);
3209 Set_Referenced (E, R);
3212 -- Normal case, not a label. Generate reference.
3215 Generate_Reference (E, N);
3218 -- Set Entity, with style check if need be. If this is a
3219 -- discriminant reference, it must be replaced by the
3220 -- corresponding discriminal, that is to say the parameter
3221 -- of the initialization procedure that corresponds to the
3222 -- discriminant. If this replacement is being performed, there
3223 -- is no style check to perform.
3225 -- This replacement must not be done if we are currently
3226 -- processing a generic spec or body, because the discriminal
3227 -- has not been not generated in this case.
3229 if not In_Default_Expression
3230 or else Ekind (E) /= E_Discriminant
3231 or else Inside_A_Generic
3233 Set_Entity_With_Style_Check (N, E);
3235 -- The replacement is not done either for a task discriminant that
3236 -- appears in a default expression of an entry parameter. See
3237 -- Expand_Discriminant in exp_ch2 for details on their handling.
3239 elsif Is_Concurrent_Type (Scope (E)) then
3241 P : Node_Id := Parent (N);
3245 and then Nkind (P) /= N_Parameter_Specification
3246 and then Nkind (P) /= N_Component_Declaration
3252 and then Nkind (P) = N_Parameter_Specification
3256 Set_Entity (N, Discriminal (E));
3260 -- Otherwise, this is a discriminant in a context in which
3261 -- it is a reference to the corresponding parameter of the
3262 -- init proc for the enclosing type.
3265 Set_Entity (N, Discriminal (E));
3269 end Find_Direct_Name;
3271 ------------------------
3272 -- Find_Expanded_Name --
3273 ------------------------
3275 -- This routine searches the homonym chain of the entity until it finds
3276 -- an entity declared in the scope denoted by the prefix. If the entity
3277 -- is private, it may nevertheless be immediately visible, if we are in
3278 -- the scope of its declaration.
3280 procedure Find_Expanded_Name (N : Node_Id) is
3281 Selector : constant Node_Id := Selector_Name (N);
3282 Candidate : Entity_Id := Empty;
3288 P_Name := Entity (Prefix (N));
3291 -- If the prefix is a renamed package, look for the entity
3292 -- in the original package.
3294 if Ekind (P_Name) = E_Package
3295 and then Present (Renamed_Object (P_Name))
3297 P_Name := Renamed_Object (P_Name);
3299 -- Rewrite node with entity field pointing to renamed object
3301 Rewrite (Prefix (N), New_Copy (Prefix (N)));
3302 Set_Entity (Prefix (N), P_Name);
3304 -- If the prefix is an object of a concurrent type, look for
3305 -- the entity in the associated task or protected type.
3307 elsif Is_Concurrent_Type (Etype (P_Name)) then
3308 P_Name := Etype (P_Name);
3311 Id := Current_Entity (Selector);
3313 while Present (Id) loop
3315 if Scope (Id) = P_Name then
3318 if Is_Child_Unit (Id) then
3319 exit when Is_Visible_Child_Unit (Id)
3320 or else Is_Immediately_Visible (Id);
3323 exit when not Is_Hidden (Id)
3324 or else Is_Immediately_Visible (Id);
3332 and then (Ekind (P_Name) = E_Procedure
3334 Ekind (P_Name) = E_Function)
3335 and then Is_Generic_Instance (P_Name)
3337 -- Expanded name denotes entity in (instance of) generic subprogram.
3338 -- The entity may be in the subprogram instance, or may denote one of
3339 -- the formals, which is declared in the enclosing wrapper package.
3341 P_Name := Scope (P_Name);
3342 Id := Current_Entity (Selector);
3344 while Present (Id) loop
3345 exit when Scope (Id) = P_Name;
3350 if No (Id) or else Chars (Id) /= Chars (Selector) then
3352 Set_Etype (N, Any_Type);
3354 -- If we are looking for an entity defined in System, try to
3355 -- find it in the child package that may have been provided as
3356 -- an extension to System. The Extend_System pragma will have
3357 -- supplied the name of the extension, which may have to be loaded.
3359 if Chars (P_Name) = Name_System
3360 and then Scope (P_Name) = Standard_Standard
3361 and then Present (System_Extend_Unit)
3362 and then Present_System_Aux (N)
3364 Set_Entity (Prefix (N), System_Aux_Id);
3365 Find_Expanded_Name (N);
3368 elsif Nkind (Selector) = N_Operator_Symbol
3369 and then Has_Implicit_Operator (N)
3371 -- There is an implicit instance of the predefined operator in
3372 -- the given scope. The operator entity is defined in Standard.
3373 -- Has_Implicit_Operator makes the node into an Expanded_Name.
3377 elsif Nkind (Selector) = N_Character_Literal
3378 and then Has_Implicit_Character_Literal (N)
3380 -- If there is no literal defined in the scope denoted by the
3381 -- prefix, the literal may belong to (a type derived from)
3382 -- Standard_Character, for which we have no explicit literals.
3387 -- If the prefix is a single concurrent object, use its
3388 -- name in the error message, rather than that of the
3391 if Is_Concurrent_Type (P_Name)
3392 and then Is_Internal_Name (Chars (P_Name))
3394 Error_Msg_Node_2 := Entity (Prefix (N));
3396 Error_Msg_Node_2 := P_Name;
3399 if P_Name = System_Aux_Id then
3400 P_Name := Scope (P_Name);
3401 Set_Entity (Prefix (N), P_Name);
3404 if Present (Candidate) then
3406 if Is_Child_Unit (Candidate) then
3408 ("missing with_clause for child unit &", Selector);
3410 Error_Msg_NE ("& is not a visible entity of&", N, Selector);
3414 -- Within the instantiation of a child unit, the prefix may
3415 -- denote the parent instance, but the selector has the
3416 -- name of the original child. Find whether we are within
3417 -- the corresponding instance, and get the proper entity, which
3418 -- can only be an enclosing scope.
3421 and then In_Open_Scopes (P_Name)
3422 and then Is_Generic_Instance (P_Name)
3425 S : Entity_Id := Current_Scope;
3429 for J in reverse 0 .. Scope_Stack.Last loop
3430 S := Scope_Stack.Table (J).Entity;
3432 exit when S = Standard_Standard;
3434 if Ekind (S) = E_Function
3435 or else Ekind (S) = E_Package
3436 or else Ekind (S) = E_Procedure
3438 P := Generic_Parent (Specification
3439 (Unit_Declaration_Node (S)));
3442 and then Chars (Scope (P)) = Chars (O_Name)
3443 and then Chars (P) = Chars (Selector)
3454 if Chars (P_Name) = Name_Ada
3455 and then Scope (P_Name) = Standard_Standard
3457 Error_Msg_Node_2 := Selector;
3458 Error_Msg_NE ("missing with for `&.&`", N, P_Name);
3460 -- If this is a selection from a dummy package, then
3461 -- suppress the error message, of course the entity
3462 -- is missing if the package is missing!
3464 elsif Sloc (Error_Msg_Node_2) = No_Location then
3467 -- Here we have the case of an undefined component
3471 Error_Msg_NE ("& not declared in&", N, Selector);
3473 -- Check for misspelling of some entity in prefix.
3475 Id := First_Entity (P_Name);
3476 Get_Name_String (Chars (Selector));
3479 S : constant String (1 .. Name_Len) :=
3480 Name_Buffer (1 .. Name_Len);
3482 while Present (Id) loop
3483 Get_Name_String (Chars (Id));
3484 if Is_Bad_Spelling_Of
3485 (Name_Buffer (1 .. Name_Len), S)
3486 and then not Is_Internal_Name (Chars (Id))
3489 ("possible misspelling of&", Selector, Id);
3497 -- Specialize the message if this may be an instantiation
3498 -- of a child unit that was not mentioned in the context.
3500 if Nkind (Parent (N)) = N_Package_Instantiation
3501 and then Is_Generic_Instance (Entity (Prefix (N)))
3502 and then Is_Compilation_Unit
3503 (Generic_Parent (Parent (Entity (Prefix (N)))))
3506 ("\possible missing with clause on child unit&",
3517 if Comes_From_Source (N)
3518 and then Is_Remote_Access_To_Subprogram_Type (Id)
3520 Id := Equivalent_Type (Id);
3521 Set_Chars (Selector, Chars (Id));
3524 -- Ada 0Y (AI-50217): Check usage of entities in limited withed units
3526 if Ekind (P_Name) = E_Package
3527 and then From_With_Type (P_Name)
3529 if From_With_Type (Id)
3530 or else Is_Type (Id)
3531 or else Ekind (Id) = E_Package
3536 ("limited withed package can only be used to access "
3537 & " incomplete types",
3542 if Is_Task_Type (P_Name)
3543 and then ((Ekind (Id) = E_Entry
3544 and then Nkind (Parent (N)) /= N_Attribute_Reference)
3546 (Ekind (Id) = E_Entry_Family
3548 Nkind (Parent (Parent (N))) /= N_Attribute_Reference))
3550 -- It is an entry call after all, either to the current task
3551 -- (which will deadlock) or to an enclosing task.
3553 Analyze_Selected_Component (N);
3557 Change_Selected_Component_To_Expanded_Name (N);
3559 -- Do style check and generate reference, but skip both steps if this
3560 -- entity has homonyms, since we may not have the right homonym set
3561 -- yet. The proper homonym will be set during the resolve phase.
3563 if Has_Homonym (Id) then
3566 Set_Entity_With_Style_Check (N, Id);
3567 Generate_Reference (Id, N);
3570 if Is_Type (Id) then
3573 Set_Etype (N, Get_Full_View (Etype (Id)));
3576 -- If the Ekind of the entity is Void, it means that all homonyms
3577 -- are hidden from all visibility (RM 8.3(5,14-20)).
3579 if Ekind (Id) = E_Void then
3580 Premature_Usage (N);
3582 elsif Is_Overloadable (Id)
3583 and then Present (Homonym (Id))
3586 H : Entity_Id := Homonym (Id);
3589 while Present (H) loop
3590 if Scope (H) = Scope (Id) then
3591 Collect_Interps (N);
3598 -- If an extension of System is present, collect possible
3599 -- explicit overloadings declared in the extension.
3601 if Chars (P_Name) = Name_System
3602 and then Scope (P_Name) = Standard_Standard
3603 and then Present (System_Extend_Unit)
3604 and then Present_System_Aux (N)
3606 H := Current_Entity (Id);
3608 while Present (H) loop
3609 if Scope (H) = System_Aux_Id then
3610 Add_One_Interp (N, H, Etype (H));
3619 if Nkind (Selector_Name (N)) = N_Operator_Symbol
3620 and then Scope (Id) /= Standard_Standard
3622 -- In addition to user-defined operators in the given scope,
3623 -- there may be an implicit instance of the predefined
3624 -- operator. The operator (defined in Standard) is found
3625 -- in Has_Implicit_Operator, and added to the interpretations.
3626 -- Procedure Add_One_Interp will determine which hides which.
3628 if Has_Implicit_Operator (N) then
3632 end Find_Expanded_Name;
3634 -------------------------
3635 -- Find_Renamed_Entity --
3636 -------------------------
3638 function Find_Renamed_Entity
3642 Is_Actual : Boolean := False) return Entity_Id
3645 I1 : Interp_Index := 0; -- Suppress junk warnings
3651 function Enclosing_Instance return Entity_Id;
3652 -- If the renaming determines the entity for the default of a formal
3653 -- subprogram nested within another instance, choose the innermost
3654 -- candidate. This is because if the formal has a box, and we are within
3655 -- an enclosing instance where some candidate interpretations are local
3656 -- to this enclosing instance, we know that the default was properly
3657 -- resolved when analyzing the generic, so we prefer the local
3658 -- candidates to those that are external. This is not always the case
3659 -- but is a reasonable heuristic on the use of nested generics.
3660 -- The proper solution requires a full renaming model.
3662 function Within (Inner, Outer : Entity_Id) return Boolean;
3663 -- Determine whether a candidate subprogram is defined within
3664 -- the enclosing instance. If yes, it has precedence over outer
3667 function Is_Visible_Operation (Op : Entity_Id) return Boolean;
3668 -- If the renamed entity is an implicit operator, check whether it is
3669 -- visible because its operand type is properly visible. This
3670 -- check applies to explicit renamed entities that appear in the
3671 -- source in a renaming declaration or a formal subprogram instance,
3672 -- but not to default generic actuals with a name.
3674 ------------------------
3675 -- Enclosing_Instance --
3676 ------------------------
3678 function Enclosing_Instance return Entity_Id is
3682 if not Is_Generic_Instance (Current_Scope)
3683 and then not Is_Actual
3688 S := Scope (Current_Scope);
3690 while S /= Standard_Standard loop
3692 if Is_Generic_Instance (S) then
3700 end Enclosing_Instance;
3702 --------------------------
3703 -- Is_Visible_Operation --
3704 --------------------------
3706 function Is_Visible_Operation (Op : Entity_Id) return Boolean is
3712 if Ekind (Op) /= E_Operator
3713 or else Scope (Op) /= Standard_Standard
3714 or else (In_Instance
3717 or else Present (Enclosing_Instance)))
3722 -- For a fixed point type operator, check the resulting type,
3723 -- because it may be a mixed mode integer * fixed operation.
3725 if Present (Next_Formal (First_Formal (New_S)))
3726 and then Is_Fixed_Point_Type (Etype (New_S))
3728 Typ := Etype (New_S);
3730 Typ := Etype (First_Formal (New_S));
3733 Btyp := Base_Type (Typ);
3735 if Nkind (Nam) /= N_Expanded_Name then
3736 return (In_Open_Scopes (Scope (Btyp))
3737 or else Is_Potentially_Use_Visible (Btyp)
3738 or else In_Use (Btyp)
3739 or else In_Use (Scope (Btyp)));
3742 Scop := Entity (Prefix (Nam));
3744 if Ekind (Scop) = E_Package
3745 and then Present (Renamed_Object (Scop))
3747 Scop := Renamed_Object (Scop);
3750 -- Operator is visible if prefix of expanded name denotes
3751 -- scope of type, or else type type is defined in System_Aux
3752 -- and the prefix denotes System.
3754 return Scope (Btyp) = Scop
3755 or else (Scope (Btyp) = System_Aux_Id
3756 and then Scope (Scope (Btyp)) = Scop);
3759 end Is_Visible_Operation;
3765 function Within (Inner, Outer : Entity_Id) return Boolean is
3766 Sc : Entity_Id := Scope (Inner);
3769 while Sc /= Standard_Standard loop
3781 function Report_Overload return Entity_Id;
3782 -- List possible interpretations, and specialize message in the
3783 -- case of a generic actual.
3785 function Report_Overload return Entity_Id is
3789 ("ambiguous actual subprogram&, " &
3790 "possible interpretations: ", N, Nam);
3793 ("ambiguous subprogram, " &
3794 "possible interpretations: ", N);
3797 List_Interps (Nam, N);
3799 end Report_Overload;
3801 -- Start of processing for Find_Renamed_Entry
3805 Candidate_Renaming := Empty;
3807 if not Is_Overloaded (Nam) then
3808 if Entity_Matches_Spec (Entity (Nam), New_S)
3809 and then Is_Visible_Operation (Entity (Nam))
3811 Old_S := Entity (Nam);
3814 Present (First_Formal (Entity (Nam)))
3815 and then Present (First_Formal (New_S))
3816 and then (Base_Type (Etype (First_Formal (Entity (Nam))))
3817 = Base_Type (Etype (First_Formal (New_S))))
3819 Candidate_Renaming := Entity (Nam);
3823 Get_First_Interp (Nam, Ind, It);
3825 while Present (It.Nam) loop
3827 if Entity_Matches_Spec (It.Nam, New_S)
3828 and then Is_Visible_Operation (It.Nam)
3830 if Old_S /= Any_Id then
3832 -- Note: The call to Disambiguate only happens if a
3833 -- previous interpretation was found, in which case I1
3834 -- has received a value.
3836 It1 := Disambiguate (Nam, I1, Ind, Etype (Old_S));
3838 if It1 = No_Interp then
3840 Inst := Enclosing_Instance;
3842 if Present (Inst) then
3844 if Within (It.Nam, Inst) then
3847 elsif Within (Old_S, Inst) then
3851 return Report_Overload;
3855 return Report_Overload;
3869 Present (First_Formal (It.Nam))
3870 and then Present (First_Formal (New_S))
3871 and then (Base_Type (Etype (First_Formal (It.Nam)))
3872 = Base_Type (Etype (First_Formal (New_S))))
3874 Candidate_Renaming := It.Nam;
3877 Get_Next_Interp (Ind, It);
3880 Set_Entity (Nam, Old_S);
3881 Set_Is_Overloaded (Nam, False);
3885 end Find_Renamed_Entity;
3887 -----------------------------
3888 -- Find_Selected_Component --
3889 -----------------------------
3891 procedure Find_Selected_Component (N : Node_Id) is
3892 P : constant Node_Id := Prefix (N);
3895 -- Entity denoted by prefix
3905 if Nkind (P) = N_Error then
3908 -- If the selector already has an entity, the node has been
3909 -- constructed in the course of expansion, and is known to be
3910 -- valid. Do not verify that it is defined for the type (it may
3911 -- be a private component used in the expansion of record equality).
3913 elsif Present (Entity (Selector_Name (N))) then
3916 or else Etype (N) = Any_Type
3919 Sel_Name : constant Node_Id := Selector_Name (N);
3920 Selector : constant Entity_Id := Entity (Sel_Name);
3924 Set_Etype (Sel_Name, Etype (Selector));
3926 if not Is_Entity_Name (P) then
3930 -- Build an actual subtype except for the first parameter
3931 -- of an init proc, where this actual subtype is by
3932 -- definition incorrect, since the object is uninitialized
3933 -- (and does not even have defined discriminants etc.)
3935 if Is_Entity_Name (P)
3936 and then Ekind (Entity (P)) = E_Function
3938 Nam := New_Copy (P);
3940 if Is_Overloaded (P) then
3941 Save_Interps (P, Nam);
3945 Make_Function_Call (Sloc (P), Name => Nam));
3947 Analyze_Selected_Component (N);
3950 elsif Ekind (Selector) = E_Component
3951 and then (not Is_Entity_Name (P)
3952 or else Chars (Entity (P)) /= Name_uInit)
3955 Build_Actual_Subtype_Of_Component (
3956 Etype (Selector), N);
3961 if No (C_Etype) then
3962 C_Etype := Etype (Selector);
3964 Insert_Action (N, C_Etype);
3965 C_Etype := Defining_Identifier (C_Etype);
3968 Set_Etype (N, C_Etype);
3971 -- If this is the name of an entry or protected operation, and
3972 -- the prefix is an access type, insert an explicit dereference,
3973 -- so that entry calls are treated uniformly.
3975 if Is_Access_Type (Etype (P))
3976 and then Is_Concurrent_Type (Designated_Type (Etype (P)))
3979 New_P : constant Node_Id :=
3980 Make_Explicit_Dereference (Sloc (P),
3981 Prefix => Relocate_Node (P));
3984 Set_Etype (P, Designated_Type (Etype (Prefix (P))));
3988 -- If the selected component appears within a default expression
3989 -- and it has an actual subtype, the pre-analysis has not yet
3990 -- completed its analysis, because Insert_Actions is disabled in
3991 -- that context. Within the init proc of the enclosing type we
3992 -- must complete this analysis, if an actual subtype was created.
3994 elsif Inside_Init_Proc then
3996 Typ : constant Entity_Id := Etype (N);
3997 Decl : constant Node_Id := Declaration_Node (Typ);
4000 if Nkind (Decl) = N_Subtype_Declaration
4001 and then not Analyzed (Decl)
4002 and then Is_List_Member (Decl)
4003 and then No (Parent (Decl))
4006 Insert_Action (N, Decl);
4013 elsif Is_Entity_Name (P) then
4014 P_Name := Entity (P);
4016 -- The prefix may denote an enclosing type which is the completion
4017 -- of an incomplete type declaration.
4019 if Is_Type (P_Name) then
4020 Set_Entity (P, Get_Full_View (P_Name));
4021 Set_Etype (P, Entity (P));
4022 P_Name := Entity (P);
4025 P_Type := Base_Type (Etype (P));
4027 if Debug_Flag_E then
4028 Write_Str ("Found prefix type to be ");
4029 Write_Entity_Info (P_Type, " "); Write_Eol;
4032 -- First check for components of a record object (not the
4033 -- result of a call, which is handled below).
4035 if Is_Appropriate_For_Record (P_Type)
4036 and then not Is_Overloadable (P_Name)
4037 and then not Is_Type (P_Name)
4039 -- Selected component of record. Type checking will validate
4040 -- name of selector.
4042 Analyze_Selected_Component (N);
4044 elsif Is_Appropriate_For_Entry_Prefix (P_Type)
4045 and then not In_Open_Scopes (P_Name)
4046 and then (not Is_Concurrent_Type (Etype (P_Name))
4047 or else not In_Open_Scopes (Etype (P_Name)))
4049 -- Call to protected operation or entry. Type checking is
4050 -- needed on the prefix.
4052 Analyze_Selected_Component (N);
4054 elsif (In_Open_Scopes (P_Name)
4055 and then Ekind (P_Name) /= E_Void
4056 and then not Is_Overloadable (P_Name))
4057 or else (Is_Concurrent_Type (Etype (P_Name))
4058 and then In_Open_Scopes (Etype (P_Name)))
4060 -- Prefix denotes an enclosing loop, block, or task, i.e. an
4061 -- enclosing construct that is not a subprogram or accept.
4063 Find_Expanded_Name (N);
4065 elsif Ekind (P_Name) = E_Package then
4066 Find_Expanded_Name (N);
4068 elsif Is_Overloadable (P_Name) then
4070 -- The subprogram may be a renaming (of an enclosing scope) as
4071 -- in the case of the name of the generic within an instantiation.
4073 if (Ekind (P_Name) = E_Procedure
4074 or else Ekind (P_Name) = E_Function)
4075 and then Present (Alias (P_Name))
4076 and then Is_Generic_Instance (Alias (P_Name))
4078 P_Name := Alias (P_Name);
4081 if Is_Overloaded (P) then
4083 -- The prefix must resolve to a unique enclosing construct.
4086 Found : Boolean := False;
4091 Get_First_Interp (P, Ind, It);
4093 while Present (It.Nam) loop
4095 if In_Open_Scopes (It.Nam) then
4098 "prefix must be unique enclosing scope", N);
4099 Set_Entity (N, Any_Id);
4100 Set_Etype (N, Any_Type);
4109 Get_Next_Interp (Ind, It);
4114 if In_Open_Scopes (P_Name) then
4115 Set_Entity (P, P_Name);
4116 Set_Is_Overloaded (P, False);
4117 Find_Expanded_Name (N);
4120 -- If no interpretation as an expanded name is possible, it
4121 -- must be a selected component of a record returned by a
4122 -- function call. Reformat prefix as a function call, the
4123 -- rest is done by type resolution. If the prefix is a
4124 -- procedure or entry, as is P.X; this is an error.
4126 if Ekind (P_Name) /= E_Function
4127 and then (not Is_Overloaded (P)
4129 Nkind (Parent (N)) = N_Procedure_Call_Statement)
4132 -- Prefix may mention a package that is hidden by a local
4133 -- declaration: let the user know. Scan the full homonym
4134 -- chain, the candidate package may be anywhere on it.
4136 if Present (Homonym (Current_Entity (P_Name))) then
4138 P_Name := Current_Entity (P_Name);
4140 while Present (P_Name) loop
4141 exit when Ekind (P_Name) = E_Package;
4142 P_Name := Homonym (P_Name);
4145 if Present (P_Name) then
4146 Error_Msg_Sloc := Sloc (Entity (Prefix (N)));
4149 ("package& is hidden by declaration#",
4152 Set_Entity (Prefix (N), P_Name);
4153 Find_Expanded_Name (N);
4156 P_Name := Entity (Prefix (N));
4161 ("invalid prefix in selected component&", N, P_Name);
4162 Change_Selected_Component_To_Expanded_Name (N);
4163 Set_Entity (N, Any_Id);
4164 Set_Etype (N, Any_Type);
4167 Nam := New_Copy (P);
4168 Save_Interps (P, Nam);
4170 Make_Function_Call (Sloc (P), Name => Nam));
4172 Analyze_Selected_Component (N);
4176 -- Remaining cases generate various error messages
4179 -- Format node as expanded name, to avoid cascaded errors
4181 Change_Selected_Component_To_Expanded_Name (N);
4182 Set_Entity (N, Any_Id);
4183 Set_Etype (N, Any_Type);
4185 -- Issue error message, but avoid this if error issued already.
4186 -- Use identifier of prefix if one is available.
4188 if P_Name = Any_Id then
4191 elsif Ekind (P_Name) = E_Void then
4192 Premature_Usage (P);
4194 elsif Nkind (P) /= N_Attribute_Reference then
4196 "invalid prefix in selected component&", P);
4198 if Is_Access_Type (P_Type)
4199 and then Ekind (Designated_Type (P_Type)) = E_Incomplete_Type
4202 ("\dereference must not be of an incomplete type " &
4203 "('R'M 3.10.1)", P);
4208 "invalid prefix in selected component", P);
4213 -- If prefix is not the name of an entity, it must be an expression,
4214 -- whose type is appropriate for a record. This is determined by
4217 Analyze_Selected_Component (N);
4219 end Find_Selected_Component;
4225 procedure Find_Type (N : Node_Id) is
4235 elsif Nkind (N) = N_Attribute_Reference then
4237 -- Class attribute. This is only valid in Ada 95 mode, but we don't
4238 -- do a check, since the tagged type referenced could only exist if
4239 -- we were in 95 mode when it was declared (or, if we were in Ada
4240 -- 83 mode, then an error message would already have been issued).
4242 if Attribute_Name (N) = Name_Class then
4243 Check_Restriction (No_Dispatch, N);
4244 Find_Type (Prefix (N));
4246 -- Propagate error from bad prefix
4248 if Etype (Prefix (N)) = Any_Type then
4249 Set_Entity (N, Any_Type);
4250 Set_Etype (N, Any_Type);
4254 T := Base_Type (Entity (Prefix (N)));
4256 -- Case of non-tagged type
4258 if not Is_Tagged_Type (T) then
4259 if Ekind (T) = E_Incomplete_Type then
4261 -- It is legal to denote the class type of an incomplete
4262 -- type. The full type will have to be tagged, of course.
4264 Set_Is_Tagged_Type (T);
4265 Make_Class_Wide_Type (T);
4266 Set_Entity (N, Class_Wide_Type (T));
4267 Set_Etype (N, Class_Wide_Type (T));
4269 elsif Ekind (T) = E_Private_Type
4270 and then not Is_Generic_Type (T)
4271 and then In_Private_Part (Scope (T))
4273 -- The Class attribute can be applied to an untagged
4274 -- private type fulfilled by a tagged type prior to
4275 -- the full type declaration (but only within the
4276 -- parent package's private part). Create the class-wide
4277 -- type now and check that the full type is tagged
4278 -- later during its analysis. Note that we do not
4279 -- mark the private type as tagged, unlike the case
4280 -- of incomplete types, because the type must still
4281 -- appear untagged to outside units.
4283 if not Present (Class_Wide_Type (T)) then
4284 Make_Class_Wide_Type (T);
4287 Set_Entity (N, Class_Wide_Type (T));
4288 Set_Etype (N, Class_Wide_Type (T));
4291 -- Should we introduce a type Any_Tagged and use
4292 -- Wrong_Type here, it would be a bit more consistent???
4295 ("tagged type required, found}",
4296 Prefix (N), First_Subtype (T));
4297 Set_Entity (N, Any_Type);
4301 -- Case of tagged type
4304 C := Class_Wide_Type (Entity (Prefix (N)));
4305 Set_Entity_With_Style_Check (N, C);
4306 Generate_Reference (C, N);
4310 -- Base attribute, allowed in Ada 95 mode only
4312 elsif Attribute_Name (N) = Name_Base then
4313 if Ada_83 and then Comes_From_Source (N) then
4315 ("(Ada 83) Base attribute not allowed in subtype mark", N);
4318 Find_Type (Prefix (N));
4319 Typ := Entity (Prefix (N));
4322 and then not Is_Scalar_Type (Typ)
4323 and then not Is_Generic_Type (Typ)
4326 ("prefix of Base attribute must be scalar type", Typ);
4328 elsif Sloc (Typ) = Standard_Location
4329 and then Base_Type (Typ) = Typ
4330 and then Warn_On_Redundant_Constructs
4333 ("?redudant attribute, & is its own base type", N, Typ);
4336 T := Base_Type (Typ);
4338 -- Rewrite attribute reference with type itself (see similar
4339 -- processing in Analyze_Attribute, case Base). Preserve
4340 -- prefix if present, for other legality checks.
4342 if Nkind (Prefix (N)) = N_Expanded_Name then
4344 Make_Expanded_Name (Sloc (N),
4345 Chars => Chars (Entity (N)),
4346 Prefix => New_Copy (Prefix (Prefix (N))),
4348 New_Reference_To (Entity (N), Sloc (N))));
4352 New_Reference_To (Entity (N), Sloc (N)));
4359 -- All other attributes are invalid in a subtype mark
4362 Error_Msg_N ("invalid attribute in subtype mark", N);
4368 if Is_Entity_Name (N) then
4369 T_Name := Entity (N);
4371 Error_Msg_N ("subtype mark required in this context", N);
4372 Set_Etype (N, Any_Type);
4376 if T_Name = Any_Id or else Etype (N) = Any_Type then
4378 -- Undefined id. Make it into a valid type
4380 Set_Entity (N, Any_Type);
4382 elsif not Is_Type (T_Name)
4383 and then T_Name /= Standard_Void_Type
4385 Error_Msg_Sloc := Sloc (T_Name);
4386 Error_Msg_N ("subtype mark required in this context", N);
4387 Error_Msg_NE ("\found & declared#", N, T_Name);
4388 Set_Entity (N, Any_Type);
4391 T_Name := Get_Full_View (T_Name);
4393 if In_Open_Scopes (T_Name) then
4394 if Ekind (Base_Type (T_Name)) = E_Task_Type then
4395 Error_Msg_N ("task type cannot be used as type mark " &
4396 "within its own body", N);
4398 Error_Msg_N ("type declaration cannot refer to itself", N);
4401 Set_Etype (N, Any_Type);
4402 Set_Entity (N, Any_Type);
4403 Set_Error_Posted (T_Name);
4407 Set_Entity (N, T_Name);
4408 Set_Etype (N, T_Name);
4412 if Present (Etype (N)) and then Comes_From_Source (N) then
4413 if Is_Fixed_Point_Type (Etype (N)) then
4414 Check_Restriction (No_Fixed_Point, N);
4415 elsif Is_Floating_Point_Type (Etype (N)) then
4416 Check_Restriction (No_Floating_Point, N);
4425 function Get_Full_View (T_Name : Entity_Id) return Entity_Id is
4427 if Ekind (T_Name) = E_Incomplete_Type
4428 and then Present (Full_View (T_Name))
4430 return Full_View (T_Name);
4432 elsif Is_Class_Wide_Type (T_Name)
4433 and then Ekind (Root_Type (T_Name)) = E_Incomplete_Type
4434 and then Present (Full_View (Root_Type (T_Name)))
4436 return Class_Wide_Type (Full_View (Root_Type (T_Name)));
4443 ------------------------------------
4444 -- Has_Implicit_Character_Literal --
4445 ------------------------------------
4447 function Has_Implicit_Character_Literal (N : Node_Id) return Boolean is
4449 Found : Boolean := False;
4450 P : constant Entity_Id := Entity (Prefix (N));
4451 Priv_Id : Entity_Id := Empty;
4454 if Ekind (P) = E_Package
4455 and then not In_Open_Scopes (P)
4457 Priv_Id := First_Private_Entity (P);
4460 if P = Standard_Standard then
4461 Change_Selected_Component_To_Expanded_Name (N);
4462 Rewrite (N, Selector_Name (N));
4464 Set_Etype (Original_Node (N), Standard_Character);
4468 Id := First_Entity (P);
4471 and then Id /= Priv_Id
4473 if Is_Character_Type (Id)
4474 and then (Root_Type (Id) = Standard_Character
4475 or else Root_Type (Id) = Standard_Wide_Character)
4476 and then Id = Base_Type (Id)
4478 -- We replace the node with the literal itself, resolve as a
4479 -- character, and set the type correctly.
4482 Change_Selected_Component_To_Expanded_Name (N);
4483 Rewrite (N, Selector_Name (N));
4486 Set_Etype (Original_Node (N), Id);
4490 -- More than one type derived from Character in given scope.
4491 -- Collect all possible interpretations.
4493 Add_One_Interp (N, Id, Id);
4501 end Has_Implicit_Character_Literal;
4503 ----------------------
4504 -- Has_Private_With --
4505 ----------------------
4507 function Has_Private_With (E : Entity_Id) return Boolean is
4508 Comp_Unit : constant Node_Id := Cunit (Current_Sem_Unit);
4512 Item := First (Context_Items (Comp_Unit));
4513 while Present (Item) loop
4514 if Nkind (Item) = N_With_Clause
4515 and then Private_Present (Item)
4516 and then Entity (Name (Item)) = E
4525 end Has_Private_With;
4527 ---------------------------
4528 -- Has_Implicit_Operator --
4529 ---------------------------
4531 function Has_Implicit_Operator (N : Node_Id) return Boolean is
4532 Op_Id : constant Name_Id := Chars (Selector_Name (N));
4533 P : constant Entity_Id := Entity (Prefix (N));
4535 Priv_Id : Entity_Id := Empty;
4537 procedure Add_Implicit_Operator
4539 Op_Type : Entity_Id := Empty);
4540 -- Add implicit interpretation to node N, using the type for which
4541 -- a predefined operator exists. If the operator yields a boolean
4542 -- type, the Operand_Type is implicitly referenced by the operator,
4543 -- and a reference to it must be generated.
4545 ---------------------------
4546 -- Add_Implicit_Operator --
4547 ---------------------------
4549 procedure Add_Implicit_Operator
4551 Op_Type : Entity_Id := Empty)
4553 Predef_Op : Entity_Id;
4556 Predef_Op := Current_Entity (Selector_Name (N));
4558 while Present (Predef_Op)
4559 and then Scope (Predef_Op) /= Standard_Standard
4561 Predef_Op := Homonym (Predef_Op);
4564 if Nkind (N) = N_Selected_Component then
4565 Change_Selected_Component_To_Expanded_Name (N);
4568 Add_One_Interp (N, Predef_Op, T);
4570 -- For operators with unary and binary interpretations, add both
4572 if Present (Homonym (Predef_Op)) then
4573 Add_One_Interp (N, Homonym (Predef_Op), T);
4576 -- The node is a reference to a predefined operator, and
4577 -- an implicit reference to the type of its operands.
4579 if Present (Op_Type) then
4580 Generate_Operator_Reference (N, Op_Type);
4582 Generate_Operator_Reference (N, T);
4584 end Add_Implicit_Operator;
4586 -- Start of processing for Has_Implicit_Operator
4590 if Ekind (P) = E_Package
4591 and then not In_Open_Scopes (P)
4593 Priv_Id := First_Private_Entity (P);
4596 Id := First_Entity (P);
4600 -- Boolean operators: an implicit declaration exists if the scope
4601 -- contains a declaration for a derived Boolean type, or for an
4602 -- array of Boolean type.
4604 when Name_Op_And | Name_Op_Not | Name_Op_Or | Name_Op_Xor =>
4606 while Id /= Priv_Id loop
4608 if Valid_Boolean_Arg (Id)
4609 and then Id = Base_Type (Id)
4611 Add_Implicit_Operator (Id);
4618 -- Equality: look for any non-limited type. Result is Boolean.
4620 when Name_Op_Eq | Name_Op_Ne =>
4622 while Id /= Priv_Id loop
4625 and then not Is_Limited_Type (Id)
4626 and then Id = Base_Type (Id)
4628 Add_Implicit_Operator (Standard_Boolean, Id);
4635 -- Comparison operators: scalar type, or array of scalar.
4637 when Name_Op_Lt | Name_Op_Le | Name_Op_Gt | Name_Op_Ge =>
4639 while Id /= Priv_Id loop
4640 if (Is_Scalar_Type (Id)
4641 or else (Is_Array_Type (Id)
4642 and then Is_Scalar_Type (Component_Type (Id))))
4643 and then Id = Base_Type (Id)
4645 Add_Implicit_Operator (Standard_Boolean, Id);
4652 -- Arithmetic operators: any numeric type
4663 while Id /= Priv_Id loop
4664 if Is_Numeric_Type (Id)
4665 and then Id = Base_Type (Id)
4667 Add_Implicit_Operator (Id);
4674 -- Concatenation: any one-dimensional array type
4676 when Name_Op_Concat =>
4678 while Id /= Priv_Id loop
4679 if Is_Array_Type (Id) and then Number_Dimensions (Id) = 1
4680 and then Id = Base_Type (Id)
4682 Add_Implicit_Operator (Id);
4689 -- What is the others condition here? Should we be using a
4690 -- subtype of Name_Id that would restrict to operators ???
4692 when others => null;
4696 -- If we fall through, then we do not have an implicit operator
4700 end Has_Implicit_Operator;
4702 --------------------
4703 -- In_Open_Scopes --
4704 --------------------
4706 function In_Open_Scopes (S : Entity_Id) return Boolean is
4708 -- Since there are several scope stacks maintained by Scope_Stack each
4709 -- delineated by Standard (see comments by definition of Scope_Stack)
4710 -- it is necessary to end the search when Standard is reached.
4712 for J in reverse 0 .. Scope_Stack.Last loop
4713 if Scope_Stack.Table (J).Entity = S then
4717 -- We need Is_Active_Stack_Base to tell us when to stop rather
4718 -- than checking for Standard_Standard because there are cases
4719 -- where Standard_Standard appears in the middle of the active
4720 -- set of scopes. This affects the declaration and overriding
4721 -- of private inherited operations in instantiations of generic
4724 exit when Scope_Stack.Table (J).Is_Active_Stack_Base;
4730 -----------------------------
4731 -- Inherit_Renamed_Profile --
4732 -----------------------------
4734 procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id) is
4741 if Ekind (Old_S) = E_Operator then
4743 New_F := First_Formal (New_S);
4745 while Present (New_F) loop
4746 Set_Etype (New_F, Base_Type (Etype (New_F)));
4747 Next_Formal (New_F);
4750 Set_Etype (New_S, Base_Type (Etype (New_S)));
4753 New_F := First_Formal (New_S);
4754 Old_F := First_Formal (Old_S);
4756 while Present (New_F) loop
4757 New_T := Etype (New_F);
4758 Old_T := Etype (Old_F);
4760 -- If the new type is a renaming of the old one, as is the
4761 -- case for actuals in instances, retain its name, to simplify
4762 -- later disambiguation.
4764 if Nkind (Parent (New_T)) = N_Subtype_Declaration
4765 and then Is_Entity_Name (Subtype_Indication (Parent (New_T)))
4766 and then Entity (Subtype_Indication (Parent (New_T))) = Old_T
4770 Set_Etype (New_F, Old_T);
4773 Next_Formal (New_F);
4774 Next_Formal (Old_F);
4777 if Ekind (Old_S) = E_Function
4778 or else Ekind (Old_S) = E_Enumeration_Literal
4780 Set_Etype (New_S, Etype (Old_S));
4783 end Inherit_Renamed_Profile;
4789 procedure Initialize is
4794 -------------------------
4795 -- Install_Use_Clauses --
4796 -------------------------
4798 procedure Install_Use_Clauses (Clause : Node_Id) is
4799 U : Node_Id := Clause;
4804 while Present (U) loop
4806 -- Case of USE package
4808 if Nkind (U) = N_Use_Package_Clause then
4809 P := First (Names (U));
4811 while Present (P) loop
4814 if Ekind (Id) = E_Package then
4817 Set_Redundant_Use (P, True);
4819 elsif Present (Renamed_Object (Id))
4820 and then In_Use (Renamed_Object (Id))
4822 Set_Redundant_Use (P, True);
4825 Use_One_Package (Id, U);
4835 P := First (Subtype_Marks (U));
4837 while Present (P) loop
4838 if not Is_Entity_Name (P)
4839 or else No (Entity (P))
4843 elsif Entity (P) /= Any_Type then
4851 Next_Use_Clause (U);
4853 end Install_Use_Clauses;
4855 -------------------------------------
4856 -- Is_Appropriate_For_Entry_Prefix --
4857 -------------------------------------
4859 function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean is
4860 P_Type : Entity_Id := T;
4863 if Is_Access_Type (P_Type) then
4864 P_Type := Designated_Type (P_Type);
4867 return Is_Task_Type (P_Type) or else Is_Protected_Type (P_Type);
4868 end Is_Appropriate_For_Entry_Prefix;
4870 -------------------------------
4871 -- Is_Appropriate_For_Record --
4872 -------------------------------
4874 function Is_Appropriate_For_Record (T : Entity_Id) return Boolean is
4876 function Has_Components (T1 : Entity_Id) return Boolean;
4877 -- Determine if given type has components (i.e. is either a record
4878 -- type or a type that has discriminants).
4880 function Has_Components (T1 : Entity_Id) return Boolean is
4882 return Is_Record_Type (T1)
4883 or else (Is_Private_Type (T1) and then Has_Discriminants (T1))
4884 or else (Is_Task_Type (T1) and then Has_Discriminants (T1));
4887 -- Start of processing for Is_Appropriate_For_Record
4892 and then (Has_Components (T)
4893 or else (Is_Access_Type (T)
4895 Has_Components (Designated_Type (T))));
4896 end Is_Appropriate_For_Record;
4902 procedure New_Scope (S : Entity_Id) is
4906 if Ekind (S) = E_Void then
4909 -- Set scope depth if not a non-concurrent type, and we have not
4910 -- yet set the scope depth. This means that we have the first
4911 -- occurrence of the scope, and this is where the depth is set.
4913 elsif (not Is_Type (S) or else Is_Concurrent_Type (S))
4914 and then not Scope_Depth_Set (S)
4916 if S = Standard_Standard then
4917 Set_Scope_Depth_Value (S, Uint_0);
4919 elsif Is_Child_Unit (S) then
4920 Set_Scope_Depth_Value (S, Uint_1);
4922 elsif not Is_Record_Type (Current_Scope) then
4923 if Ekind (S) = E_Loop then
4924 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope));
4926 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope) + 1);
4931 Scope_Stack.Increment_Last;
4934 SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
4938 SST.Save_Scope_Suppress := Scope_Suppress;
4939 SST.Save_Local_Entity_Suppress := Local_Entity_Suppress.Last;
4941 if Scope_Stack.Last > Scope_Stack.First then
4942 SST.Component_Alignment_Default := Scope_Stack.Table
4943 (Scope_Stack.Last - 1).
4944 Component_Alignment_Default;
4947 SST.Last_Subprogram_Name := null;
4948 SST.Is_Transient := False;
4949 SST.Node_To_Be_Wrapped := Empty;
4950 SST.Pending_Freeze_Actions := No_List;
4951 SST.Actions_To_Be_Wrapped_Before := No_List;
4952 SST.Actions_To_Be_Wrapped_After := No_List;
4953 SST.First_Use_Clause := Empty;
4954 SST.Is_Active_Stack_Base := False;
4957 if Debug_Flag_W then
4958 Write_Str ("--> new scope: ");
4959 Write_Name (Chars (Current_Scope));
4960 Write_Str (", Id=");
4961 Write_Int (Int (Current_Scope));
4962 Write_Str (", Depth=");
4963 Write_Int (Int (Scope_Stack.Last));
4967 -- Copy from Scope (S) the categorization flags to S, this is not
4968 -- done in case Scope (S) is Standard_Standard since propagation
4969 -- is from library unit entity inwards.
4971 if S /= Standard_Standard
4972 and then Scope (S) /= Standard_Standard
4973 and then not Is_Child_Unit (S)
4977 if Nkind (E) not in N_Entity then
4981 -- We only propagate inwards for library level entities,
4982 -- inner level subprograms do not inherit the categorization.
4984 if Is_Library_Level_Entity (S) then
4985 Set_Is_Preelaborated (S, Is_Preelaborated (E));
4986 Set_Is_Shared_Passive (S, Is_Shared_Passive (E));
4987 Set_Categorization_From_Scope (E => S, Scop => E);
4996 procedure Pop_Scope is
4997 SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
5000 if Debug_Flag_E then
5004 Scope_Suppress := SST.Save_Scope_Suppress;
5005 Local_Entity_Suppress.Set_Last (SST.Save_Local_Entity_Suppress);
5007 if Debug_Flag_W then
5008 Write_Str ("--> exiting scope: ");
5009 Write_Name (Chars (Current_Scope));
5010 Write_Str (", Depth=");
5011 Write_Int (Int (Scope_Stack.Last));
5015 End_Use_Clauses (SST.First_Use_Clause);
5017 -- If the actions to be wrapped are still there they will get lost
5018 -- causing incomplete code to be generated. It is better to abort in
5019 -- this case (and we do the abort even with assertions off since the
5020 -- penalty is incorrect code generation)
5022 if SST.Actions_To_Be_Wrapped_Before /= No_List
5024 SST.Actions_To_Be_Wrapped_After /= No_List
5029 -- Free last subprogram name if allocated, and pop scope
5031 Free (SST.Last_Subprogram_Name);
5032 Scope_Stack.Decrement_Last;
5035 ---------------------
5036 -- Premature_Usage --
5037 ---------------------
5039 procedure Premature_Usage (N : Node_Id) is
5040 Kind : constant Node_Kind := Nkind (Parent (Entity (N)));
5041 E : Entity_Id := Entity (N);
5044 -- Within an instance, the analysis of the actual for a formal object
5045 -- does not see the name of the object itself. This is significant
5046 -- only if the object is an aggregate, where its analysis does not do
5047 -- any name resolution on component associations. (see 4717-008). In
5048 -- such a case, look for the visible homonym on the chain.
5051 and then Present (Homonym (E))
5056 and then not In_Open_Scopes (Scope (E))
5063 Set_Etype (N, Etype (E));
5068 if Kind = N_Component_Declaration then
5070 ("component&! cannot be used before end of record declaration", N);
5072 elsif Kind = N_Parameter_Specification then
5074 ("formal parameter&! cannot be used before end of specification",
5077 elsif Kind = N_Discriminant_Specification then
5079 ("discriminant&! cannot be used before end of discriminant part",
5082 elsif Kind = N_Procedure_Specification
5083 or else Kind = N_Function_Specification
5086 ("subprogram&! cannot be used before end of its declaration",
5090 ("object& cannot be used before end of its declaration!", N);
5092 end Premature_Usage;
5094 ------------------------
5095 -- Present_System_Aux --
5096 ------------------------
5098 function Present_System_Aux (N : Node_Id := Empty) return Boolean is
5101 Unum : Unit_Number_Type;
5106 function Find_System (C_Unit : Node_Id) return Entity_Id;
5107 -- Scan context clause of compilation unit to find a with_clause
5114 function Find_System (C_Unit : Node_Id) return Entity_Id is
5115 With_Clause : Node_Id;
5118 With_Clause := First (Context_Items (C_Unit));
5120 while Present (With_Clause) loop
5121 if (Nkind (With_Clause) = N_With_Clause
5122 and then Chars (Name (With_Clause)) = Name_System)
5123 and then Comes_From_Source (With_Clause)
5134 -- Start of processing for Present_System_Aux
5137 -- The child unit may have been loaded and analyzed already.
5139 if Present (System_Aux_Id) then
5142 -- If no previous pragma for System.Aux, nothing to load
5144 elsif No (System_Extend_Unit) then
5147 -- Use the unit name given in the pragma to retrieve the unit.
5148 -- Verify that System itself appears in the context clause of the
5149 -- current compilation. If System is not present, an error will
5150 -- have been reported already.
5153 With_Sys := Find_System (Cunit (Current_Sem_Unit));
5155 The_Unit := Unit (Cunit (Current_Sem_Unit));
5158 and then (Nkind (The_Unit) = N_Package_Body
5159 or else (Nkind (The_Unit) = N_Subprogram_Body
5160 and then not Acts_As_Spec (Cunit (Current_Sem_Unit))))
5162 With_Sys := Find_System (Library_Unit (Cunit (Current_Sem_Unit)));
5166 and then Present (N)
5168 -- If we are compiling a subunit, we need to examine its
5169 -- context as well (Current_Sem_Unit is the parent unit);
5171 The_Unit := Parent (N);
5173 while Nkind (The_Unit) /= N_Compilation_Unit loop
5174 The_Unit := Parent (The_Unit);
5177 if Nkind (Unit (The_Unit)) = N_Subunit then
5178 With_Sys := Find_System (The_Unit);
5182 if No (With_Sys) then
5186 Loc := Sloc (With_Sys);
5187 Get_Name_String (Chars (Expression (System_Extend_Unit)));
5188 Name_Buffer (8 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
5189 Name_Buffer (1 .. 7) := "system.";
5190 Name_Buffer (Name_Len + 8) := '%';
5191 Name_Buffer (Name_Len + 9) := 's';
5192 Name_Len := Name_Len + 9;
5193 Aux_Name := Name_Find;
5197 (Load_Name => Aux_Name,
5200 Error_Node => With_Sys);
5202 if Unum /= No_Unit then
5203 Semantics (Cunit (Unum));
5205 Defining_Entity (Specification (Unit (Cunit (Unum))));
5207 Withn := Make_With_Clause (Loc,
5209 Make_Expanded_Name (Loc,
5210 Chars => Chars (System_Aux_Id),
5212 New_Reference_To (Scope (System_Aux_Id), Loc),
5214 New_Reference_To (System_Aux_Id, Loc)));
5216 Set_Entity (Name (Withn), System_Aux_Id);
5218 Set_Library_Unit (Withn, Cunit (Unum));
5219 Set_Corresponding_Spec (Withn, System_Aux_Id);
5220 Set_First_Name (Withn, True);
5221 Set_Implicit_With (Withn, True);
5223 Insert_After (With_Sys, Withn);
5224 Mark_Rewrite_Insertion (Withn);
5225 Set_Context_Installed (Withn);
5229 -- Here if unit load failed
5232 Error_Msg_Name_1 := Name_System;
5233 Error_Msg_Name_2 := Chars (Expression (System_Extend_Unit));
5235 ("extension package `%.%` does not exist",
5236 Opt.System_Extend_Unit);
5240 end Present_System_Aux;
5242 -------------------------
5243 -- Restore_Scope_Stack --
5244 -------------------------
5246 procedure Restore_Scope_Stack (Handle_Use : Boolean := True) is
5249 Comp_Unit : Node_Id;
5250 In_Child : Boolean := False;
5251 Full_Vis : Boolean := True;
5252 SS_Last : constant Int := Scope_Stack.Last;
5255 -- Restore visibility of previous scope stack, if any.
5257 for J in reverse 0 .. Scope_Stack.Last loop
5258 exit when Scope_Stack.Table (J).Entity = Standard_Standard
5259 or else No (Scope_Stack.Table (J).Entity);
5261 S := Scope_Stack.Table (J).Entity;
5263 if not Is_Hidden_Open_Scope (S) then
5265 -- If the parent scope is hidden, its entities are hidden as
5266 -- well, unless the entity is the instantiation currently
5269 if not Is_Hidden_Open_Scope (Scope (S))
5270 or else not Analyzed (Parent (S))
5271 or else Scope (S) = Standard_Standard
5273 Set_Is_Immediately_Visible (S, True);
5276 E := First_Entity (S);
5278 while Present (E) loop
5279 if Is_Child_Unit (E) then
5280 Set_Is_Immediately_Visible (E,
5281 Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
5283 Set_Is_Immediately_Visible (E, True);
5288 if not Full_Vis then
5289 exit when E = First_Private_Entity (S);
5293 -- The visibility of child units (siblings of current compilation)
5294 -- must be restored in any case. Their declarations may appear
5295 -- after the private part of the parent.
5298 and then Present (E)
5300 while Present (E) loop
5301 if Is_Child_Unit (E) then
5302 Set_Is_Immediately_Visible (E,
5303 Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
5311 if Is_Child_Unit (S)
5312 and not In_Child -- check only for current unit.
5316 -- restore visibility of parents according to whether the child
5317 -- is private and whether we are in its visible part.
5319 Comp_Unit := Parent (Unit_Declaration_Node (S));
5321 if Nkind (Comp_Unit) = N_Compilation_Unit
5322 and then Private_Present (Comp_Unit)
5326 elsif (Ekind (S) = E_Package
5327 or else Ekind (S) = E_Generic_Package)
5328 and then (In_Private_Part (S)
5329 or else In_Package_Body (S))
5333 elsif (Ekind (S) = E_Procedure
5334 or else Ekind (S) = E_Function)
5335 and then Has_Completion (S)
5346 if SS_Last >= Scope_Stack.First
5347 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
5350 Install_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
5352 end Restore_Scope_Stack;
5354 ----------------------
5355 -- Save_Scope_Stack --
5356 ----------------------
5358 procedure Save_Scope_Stack (Handle_Use : Boolean := True) is
5361 SS_Last : constant Int := Scope_Stack.Last;
5364 if SS_Last >= Scope_Stack.First
5365 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
5368 End_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
5371 -- If the call is from within a compilation unit, as when
5372 -- called from Rtsfind, make current entries in scope stack
5373 -- invisible while we analyze the new unit.
5375 for J in reverse 0 .. SS_Last loop
5376 exit when Scope_Stack.Table (J).Entity = Standard_Standard
5377 or else No (Scope_Stack.Table (J).Entity);
5379 S := Scope_Stack.Table (J).Entity;
5380 Set_Is_Immediately_Visible (S, False);
5381 E := First_Entity (S);
5383 while Present (E) loop
5384 Set_Is_Immediately_Visible (E, False);
5390 end Save_Scope_Stack;
5396 procedure Set_Use (L : List_Id) is
5398 Pack_Name : Node_Id;
5406 while Present (Decl) loop
5407 if Nkind (Decl) = N_Use_Package_Clause then
5408 Chain_Use_Clause (Decl);
5409 Pack_Name := First (Names (Decl));
5411 while Present (Pack_Name) loop
5412 Pack := Entity (Pack_Name);
5414 if Ekind (Pack) = E_Package
5415 and then Applicable_Use (Pack_Name)
5417 Use_One_Package (Pack, Decl);
5423 elsif Nkind (Decl) = N_Use_Type_Clause then
5424 Chain_Use_Clause (Decl);
5425 Id := First (Subtype_Marks (Decl));
5427 while Present (Id) loop
5428 if Entity (Id) /= Any_Type then
5441 ---------------------
5442 -- Use_One_Package --
5443 ---------------------
5445 procedure Use_One_Package (P : Entity_Id; N : Node_Id) is
5448 Current_Instance : Entity_Id := Empty;
5450 Private_With_OK : Boolean := False;
5453 if Ekind (P) /= E_Package then
5459 -- Ada 0Y (AI-50217): Check restriction.
5461 if From_With_Type (P) then
5462 Error_Msg_N ("limited withed package cannot appear in use clause", N);
5465 -- Find enclosing instance, if any.
5468 Current_Instance := Current_Scope;
5470 while not Is_Generic_Instance (Current_Instance) loop
5471 Current_Instance := Scope (Current_Instance);
5474 if No (Hidden_By_Use_Clause (N)) then
5475 Set_Hidden_By_Use_Clause (N, New_Elmt_List);
5479 -- If unit is a package renaming, indicate that the renamed
5480 -- package is also in use (the flags on both entities must
5481 -- remain consistent, and a subsequent use of either of them
5482 -- should be recognized as redundant).
5484 if Present (Renamed_Object (P)) then
5485 Set_In_Use (Renamed_Object (P));
5486 Real_P := Renamed_Object (P);
5491 -- Ada 0Y (AI-262): Check the use_clause of a private withed package
5492 -- found in the private part of a package specification
5494 if In_Private_Part (Current_Scope)
5495 and then Has_Private_With (P)
5496 and then Is_Child_Unit (Current_Scope)
5497 and then Is_Child_Unit (P)
5498 and then Is_Ancestor_Package (Scope (Current_Scope), P)
5500 Private_With_OK := True;
5503 -- Loop through entities in one package making them potentially
5506 Id := First_Entity (P);
5508 and then (Id /= First_Private_Entity (P)
5509 or else Private_With_OK) -- Ada 0Y (AI-262)
5511 Prev := Current_Entity (Id);
5513 while Present (Prev) loop
5514 if Is_Immediately_Visible (Prev)
5515 and then (not Is_Overloadable (Prev)
5516 or else not Is_Overloadable (Id)
5517 or else (Type_Conformant (Id, Prev)))
5519 if No (Current_Instance) then
5521 -- Potentially use-visible entity remains hidden
5523 goto Next_Usable_Entity;
5525 -- A use clause within an instance hides outer global
5526 -- entities, which are not used to resolve local entities
5527 -- in the instance. Note that the predefined entities in
5528 -- Standard could not have been hidden in the generic by
5529 -- a use clause, and therefore remain visible. Other
5530 -- compilation units whose entities appear in Standard must
5531 -- be hidden in an instance.
5533 -- To determine whether an entity is external to the instance
5534 -- we compare the scope depth of its scope with that of the
5535 -- current instance. However, a generic actual of a subprogram
5536 -- instance is declared in the wrapper package but will not be
5537 -- hidden by a use-visible entity.
5539 elsif not Is_Hidden (Id)
5540 and then not Is_Wrapper_Package (Scope (Prev))
5541 and then Scope_Depth (Scope (Prev)) <
5542 Scope_Depth (Current_Instance)
5543 and then (Scope (Prev) /= Standard_Standard
5544 or else Sloc (Prev) > Standard_Location)
5546 Set_Is_Potentially_Use_Visible (Id);
5547 Set_Is_Immediately_Visible (Prev, False);
5548 Append_Elmt (Prev, Hidden_By_Use_Clause (N));
5551 -- A user-defined operator is not use-visible if the
5552 -- predefined operator for the type is immediately visible,
5553 -- which is the case if the type of the operand is in an open
5554 -- scope. This does not apply to user-defined operators that
5555 -- have operands of different types, because the predefined
5556 -- mixed mode operations (multiplication and division) apply to
5557 -- universal types and do not hide anything.
5559 elsif Ekind (Prev) = E_Operator
5560 and then Operator_Matches_Spec (Prev, Id)
5561 and then In_Open_Scopes
5562 (Scope (Base_Type (Etype (First_Formal (Id)))))
5563 and then (No (Next_Formal (First_Formal (Id)))
5564 or else Etype (First_Formal (Id))
5565 = Etype (Next_Formal (First_Formal (Id)))
5566 or else Chars (Prev) = Name_Op_Expon)
5568 goto Next_Usable_Entity;
5571 Prev := Homonym (Prev);
5574 -- On exit, we know entity is not hidden, unless it is private.
5576 if not Is_Hidden (Id)
5577 and then ((not Is_Child_Unit (Id))
5578 or else Is_Visible_Child_Unit (Id))
5580 Set_Is_Potentially_Use_Visible (Id);
5582 if Is_Private_Type (Id)
5583 and then Present (Full_View (Id))
5585 Set_Is_Potentially_Use_Visible (Full_View (Id));
5589 <<Next_Usable_Entity>>
5593 -- Child units are also made use-visible by a use clause, but they
5594 -- may appear after all visible declarations in the parent entity list.
5596 while Present (Id) loop
5598 if Is_Child_Unit (Id)
5599 and then Is_Visible_Child_Unit (Id)
5601 Set_Is_Potentially_Use_Visible (Id);
5607 if Chars (Real_P) = Name_System
5608 and then Scope (Real_P) = Standard_Standard
5609 and then Present_System_Aux (N)
5611 Use_One_Package (System_Aux_Id, N);
5614 end Use_One_Package;
5620 procedure Use_One_Type (Id : Node_Id) is
5626 -- It is the type determined by the subtype mark (8.4(8)) whose
5627 -- operations become potentially use-visible.
5629 T := Base_Type (Entity (Id));
5634 or else Is_Potentially_Use_Visible (T)
5635 or else In_Use (Scope (T)));
5637 if In_Open_Scopes (Scope (T)) then
5640 -- If the subtype mark designates a subtype in a different package,
5641 -- we have to check that the parent type is visible, otherwise the
5642 -- use type clause is a noop. Not clear how to do that???
5644 elsif not Redundant_Use (Id) then
5646 Op_List := Collect_Primitive_Operations (T);
5647 Elmt := First_Elmt (Op_List);
5649 while Present (Elmt) loop
5651 if (Nkind (Node (Elmt)) = N_Defining_Operator_Symbol
5652 or else Chars (Node (Elmt)) in Any_Operator_Name)
5653 and then not Is_Hidden (Node (Elmt))
5655 Set_Is_Potentially_Use_Visible (Node (Elmt));
5667 procedure Write_Info is
5668 Id : Entity_Id := First_Entity (Current_Scope);
5671 -- No point in dumping standard entities
5673 if Current_Scope = Standard_Standard then
5677 Write_Str ("========================================================");
5679 Write_Str (" Defined Entities in ");
5680 Write_Name (Chars (Current_Scope));
5682 Write_Str ("========================================================");
5686 Write_Str ("-- none --");
5690 while Present (Id) loop
5691 Write_Entity_Info (Id, " ");
5696 if Scope (Current_Scope) = Standard_Standard then
5698 -- Print information on the current unit itself
5700 Write_Entity_Info (Current_Scope, " ");
5710 procedure Write_Scopes is
5714 for J in reverse 1 .. Scope_Stack.Last loop
5715 S := Scope_Stack.Table (J).Entity;
5716 Write_Int (Int (S));
5717 Write_Str (" === ");
5718 Write_Name (Chars (S));