1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with 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_Disp; use Sem_Disp;
53 with Sem_Res; use Sem_Res;
54 with Sem_Util; use Sem_Util;
55 with Sem_Type; use Sem_Type;
56 with Stand; use Stand;
57 with Sinfo; use Sinfo;
58 with Sinfo.CN; use Sinfo.CN;
59 with Snames; use Snames;
60 with Style; use Style;
62 with Tbuild; use Tbuild;
63 with Uintp; use Uintp;
65 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
67 package body Sem_Ch8 is
69 ------------------------------------
70 -- Visibility and Name Resolution --
71 ------------------------------------
73 -- This package handles name resolution and the collection of
74 -- interpretations for overloaded names, prior to overload resolution.
76 -- Name resolution is the process that establishes a mapping between source
77 -- identifiers and the entities they denote at each point in the program.
78 -- Each entity is represented by a defining occurrence. Each identifier
79 -- that denotes an entity points to the corresponding defining occurrence.
80 -- This is the entity of the applied occurrence. Each occurrence holds
81 -- an index into the names table, where source identifiers are stored.
83 -- Each entry in the names table for an identifier or designator uses the
84 -- Info pointer to hold a link to the currently visible entity that has
85 -- this name (see subprograms Get_Name_Entity_Id and Set_Name_Entity_Id
86 -- in package Sem_Util). The visibility is initialized at the beginning of
87 -- semantic processing to make entities in package Standard immediately
88 -- visible. The visibility table is used in a more subtle way when
89 -- compiling subunits (see below).
91 -- Entities that have the same name (i.e. homonyms) are chained. In the
92 -- case of overloaded entities, this chain holds all the possible meanings
93 -- of a given identifier. The process of overload resolution uses type
94 -- information to select from this chain the unique meaning of a given
97 -- Entities are also chained in their scope, through the Next_Entity link.
98 -- As a consequence, the name space is organized as a sparse matrix, where
99 -- each row corresponds to a scope, and each column to a source identifier.
100 -- Open scopes, that is to say scopes currently being compiled, have their
101 -- corresponding rows of entities in order, innermost scope first.
103 -- The scopes of packages that are mentioned in context clauses appear in
104 -- no particular order, interspersed among open scopes. This is because
105 -- in the course of analyzing the context of a compilation, a package
106 -- declaration is first an open scope, and subsequently an element of the
107 -- context. If subunits or child units are present, a parent unit may
108 -- appear under various guises at various times in the compilation.
110 -- When the compilation of the innermost scope is complete, the entities
111 -- defined therein are no longer visible. If the scope is not a package
112 -- declaration, these entities are never visible subsequently, and can be
113 -- removed from visibility chains. If the scope is a package declaration,
114 -- its visible declarations may still be accessible. Therefore the entities
115 -- defined in such a scope are left on the visibility chains, and only
116 -- their visibility (immediately visibility or potential use-visibility)
119 -- The ordering of homonyms on their chain does not necessarily follow
120 -- the order of their corresponding scopes on the scope stack. For
121 -- example, if package P and the enclosing scope both contain entities
122 -- named E, then when compiling the package body the chain for E will
123 -- hold the global entity first, and the local one (corresponding to
124 -- the current inner scope) next. As a result, name resolution routines
125 -- do not assume any relative ordering of the homonym chains, either
126 -- for scope nesting or to order of appearance of context clauses.
128 -- When compiling a child unit, entities in the parent scope are always
129 -- immediately visible. When compiling the body of a child unit, private
130 -- entities in the parent must also be made immediately visible. There
131 -- are separate routines to make the visible and private declarations
132 -- visible at various times (see package Sem_Ch7).
134 -- +--------+ +-----+
135 -- | In use |-------->| EU1 |-------------------------->
136 -- +--------+ +-----+
138 -- +--------+ +-----+ +-----+
139 -- | Stand. |---------------->| ES1 |--------------->| ES2 |--->
140 -- +--------+ +-----+ +-----+
142 -- +---------+ | +-----+
143 -- | with'ed |------------------------------>| EW2 |--->
144 -- +---------+ | +-----+
146 -- +--------+ +-----+ +-----+
147 -- | Scope2 |---------------->| E12 |--------------->| E22 |--->
148 -- +--------+ +-----+ +-----+
150 -- +--------+ +-----+ +-----+
151 -- | Scope1 |---------------->| E11 |--------------->| E12 |--->
152 -- +--------+ +-----+ +-----+
156 -- | | with'ed |----------------------------------------->
160 -- (innermost first) | |
161 -- +----------------------------+
162 -- Names table => | Id1 | | | | Id2 |
163 -- +----------------------------+
165 -- Name resolution must deal with several syntactic forms: simple names,
166 -- qualified names, indexed names, and various forms of calls.
168 -- Each identifier points to an entry in the names table. The resolution
169 -- of a simple name consists in traversing the homonym chain, starting
170 -- from the names table. If an entry is immediately visible, it is the one
171 -- designated by the identifier. If only potentially use-visible entities
172 -- are on the chain, we must verify that they do not hide each other. If
173 -- the entity we find is overloadable, we collect all other overloadable
174 -- entities on the chain as long as they are not hidden.
176 -- To resolve expanded names, we must find the entity at the intersection
177 -- of the entity chain for the scope (the prefix) and the homonym chain
178 -- for the selector. In general, homonym chains will be much shorter than
179 -- entity chains, so it is preferable to start from the names table as
180 -- well. If the entity found is overloadable, we must collect all other
181 -- interpretations that are defined in the scope denoted by the prefix.
183 -- For records, protected types, and tasks, their local entities are
184 -- removed from visibility chains on exit from the corresponding scope.
185 -- From the outside, these entities are always accessed by selected
186 -- notation, and the entity chain for the record type, protected type,
187 -- etc. is traversed sequentially in order to find the designated entity.
189 -- The discriminants of a type and the operations of a protected type or
190 -- task are unchained on exit from the first view of the type, (such as
191 -- a private or incomplete type declaration, or a protected type speci-
192 -- fication) and re-chained when compiling the second view.
194 -- In the case of operators, we do not make operators on derived types
195 -- explicit. As a result, the notation P."+" may denote either a user-
196 -- defined function with name "+", or else an implicit declaration of the
197 -- operator "+" in package P. The resolution of expanded names always
198 -- tries to resolve an operator name as such an implicitly defined entity,
199 -- in addition to looking for explicit declarations.
201 -- All forms of names that denote entities (simple names, expanded names,
202 -- character literals in some cases) have a Entity attribute, which
203 -- identifies the entity denoted by the name.
205 ---------------------
206 -- The Scope Stack --
207 ---------------------
209 -- The Scope stack keeps track of the scopes currently been compiled.
210 -- Every entity that contains declarations (including records) is placed
211 -- on the scope stack while it is being processed, and removed at the end.
212 -- Whenever a non-package scope is exited, the entities defined therein
213 -- are removed from the visibility table, so that entities in outer scopes
214 -- become visible (see previous description). On entry to Sem, the scope
215 -- stack only contains the package Standard. As usual, subunits complicate
216 -- this picture ever so slightly.
218 -- The Rtsfind mechanism can force a call to Semantics while another
219 -- compilation is in progress. The unit retrieved by Rtsfind must be
220 -- compiled in its own context, and has no access to the visibility of
221 -- the unit currently being compiled. The procedures Save_Scope_Stack and
222 -- Restore_Scope_Stack make entities in current open scopes invisible
223 -- before compiling the retrieved unit, and restore the compilation
224 -- environment afterwards.
226 ------------------------
227 -- Compiling subunits --
228 ------------------------
230 -- Subunits must be compiled in the environment of the corresponding
231 -- stub, that is to say with the same visibility into the parent (and its
232 -- context) that is available at the point of the stub declaration, but
233 -- with the additional visibility provided by the context clause of the
234 -- subunit itself. As a result, compilation of a subunit forces compilation
235 -- of the parent (see description in lib-). At the point of the stub
236 -- declaration, Analyze is called recursively to compile the proper body
237 -- of the subunit, but without reinitializing the names table, nor the
238 -- scope stack (i.e. standard is not pushed on the stack). In this fashion
239 -- the context of the subunit is added to the context of the parent, and
240 -- the subunit is compiled in the correct environment. Note that in the
241 -- course of processing the context of a subunit, Standard will appear
242 -- twice on the scope stack: once for the parent of the subunit, and
243 -- once for the unit in the context clause being compiled. However, the
244 -- two sets of entities are not linked by homonym chains, so that the
245 -- compilation of any context unit happens in a fresh visibility
248 -------------------------------
249 -- Processing of USE Clauses --
250 -------------------------------
252 -- Every defining occurrence has a flag indicating if it is potentially use
253 -- visible. Resolution of simple names examines this flag. The processing
254 -- of use clauses consists in setting this flag on all visible entities
255 -- defined in the corresponding package. On exit from the scope of the use
256 -- clause, the corresponding flag must be reset. However, a package may
257 -- appear in several nested use clauses (pathological but legal, alas!)
258 -- which forces us to use a slightly more involved scheme:
260 -- a) The defining occurrence for a package holds a flag -In_Use- to
261 -- indicate that it is currently in the scope of a use clause. If a
262 -- redundant use clause is encountered, then the corresponding occurrence
263 -- of the package name is flagged -Redundant_Use-.
265 -- b) On exit from a scope, the use clauses in its declarative part are
266 -- scanned. The visibility flag is reset in all entities declared in
267 -- package named in a use clause, as long as the package is not flagged
268 -- as being in a redundant use clause (in which case the outer use
269 -- clause is still in effect, and the direct visibility of its entities
270 -- must be retained).
272 -- Note that entities are not removed from their homonym chains on exit
273 -- from the package specification. A subsequent use clause does not need
274 -- to rechain the visible entities, but only to establish their direct
277 -----------------------------------
278 -- Handling private declarations --
279 -----------------------------------
281 -- The principle that each entity has a single defining occurrence clashes
282 -- with the presence of two separate definitions for private types: the
283 -- first is the private type declaration, and second is the full type
284 -- declaration. It is important that all references to the type point to
285 -- the same defining occurrence, namely the first one. To enforce the two
286 -- separate views of the entity, the corresponding information is swapped
287 -- between the two declarations. Outside of the package, the defining
288 -- occurrence only contains the private declaration information, while in
289 -- the private part and the body of the package the defining occurrence
290 -- contains the full declaration. To simplify the swap, the defining
291 -- occurrence that currently holds the private declaration points to the
292 -- full declaration. During semantic processing the defining occurrence
293 -- also points to a list of private dependents, that is to say access
294 -- types or composite types whose designated types or component types are
295 -- subtypes or derived types of the private type in question. After the
296 -- full declaration has been seen, the private dependents are updated to
297 -- indicate that they have full definitions.
299 ------------------------------------
300 -- Handling of Undefined Messages --
301 ------------------------------------
303 -- In normal mode, only the first use of an undefined identifier generates
304 -- a message. The table Urefs is used to record error messages that have
305 -- been issued so that second and subsequent ones do not generate further
306 -- messages. However, the second reference causes text to be added to the
307 -- original undefined message noting "(more references follow)". The
308 -- full error list option (-gnatf) forces messages to be generated for
309 -- every reference and disconnects the use of this table.
311 type Uref_Entry is record
313 -- Node for identifier for which original message was posted. The
314 -- Chars field of this identifier is used to detect later references
315 -- to the same identifier.
318 -- Records error message Id of original undefined message. Reset to
319 -- No_Error_Msg after the second occurrence, where it is used to add
320 -- text to the original message as described above.
323 -- Set if the message is not visible rather than undefined
326 -- Records location of error message. Used to make sure that we do
327 -- not consider a, b : undefined as two separate instances, which
328 -- would otherwise happen, since the parser converts this sequence
329 -- to a : undefined; b : undefined.
333 package Urefs is new Table.Table (
334 Table_Component_Type => Uref_Entry,
335 Table_Index_Type => Nat,
336 Table_Low_Bound => 1,
338 Table_Increment => 100,
339 Table_Name => "Urefs");
341 Candidate_Renaming : Entity_Id;
342 -- Holds a candidate interpretation that appears in a subprogram renaming
343 -- declaration and does not match the given specification, but matches at
344 -- least on the first formal. Allows better error message when given
345 -- specification omits defaulted parameters, a common error.
347 -----------------------
348 -- Local Subprograms --
349 -----------------------
351 procedure Analyze_Generic_Renaming
354 -- Common processing for all three kinds of generic renaming declarations.
355 -- Enter new name and indicate that it renames the generic unit.
357 procedure Analyze_Renamed_Character
361 -- Renamed entity is given by a character literal, which must belong
362 -- to the return type of the new entity. Is_Body indicates whether the
363 -- declaration is a renaming_as_body. If the original declaration has
364 -- already been frozen (because of an intervening body, e.g.) the body of
365 -- the function must be built now. The same applies to the following
366 -- various renaming procedures.
368 procedure Analyze_Renamed_Dereference
372 -- Renamed entity is given by an explicit dereference. Prefix must be a
373 -- conformant access_to_subprogram type.
375 procedure Analyze_Renamed_Entry
379 -- If the renamed entity in a subprogram renaming is an entry or protected
380 -- subprogram, build a body for the new entity whose only statement is a
381 -- call to the renamed entity.
383 procedure Analyze_Renamed_Family_Member
387 -- Used when the renamed entity is an indexed component. The prefix must
388 -- denote an entry family.
390 function Applicable_Use (Pack_Name : Node_Id) return Boolean;
391 -- Common code to Use_One_Package and Set_Use, to determine whether
392 -- use clause must be processed. Pack_Name is an entity name that
393 -- references the package in question.
395 procedure Attribute_Renaming (N : Node_Id);
396 -- Analyze renaming of attribute as function. The renaming declaration N
397 -- is rewritten as a function body that returns the attribute reference
398 -- applied to the formals of the function.
400 procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id);
401 -- A renaming_as_body may occur after the entity of the original decla-
402 -- ration has been frozen. In that case, the body of the new entity must
403 -- be built now, because the usual mechanism of building the renamed
404 -- body at the point of freezing will not work. Subp is the subprogram
405 -- for which N provides the Renaming_As_Body.
407 procedure Check_In_Previous_With_Clause
410 -- N is a use_package clause and Nam the package name, or N is a use_type
411 -- clause and Nam is the prefix of the type name. In either case, verify
412 -- that the package is visible at that point in the context: either it
413 -- appears in a previous with_clause, or because it is a fully qualified
414 -- name and the root ancestor appears in a previous with_clause.
416 procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id);
417 -- Verify that the entity in a renaming declaration that is a library unit
418 -- is itself a library unit and not a nested unit or subunit. Also check
419 -- that if the renaming is a child unit of a generic parent, then the
420 -- renamed unit must also be a child unit of that parent. Finally, verify
421 -- that a renamed generic unit is not an implicit child declared within
422 -- an instance of the parent.
424 procedure Chain_Use_Clause (N : Node_Id);
425 -- Chain use clause onto list of uses clauses headed by First_Use_Clause
426 -- in the top scope table entry.
428 function Has_Implicit_Character_Literal (N : Node_Id) return Boolean;
429 -- Find a type derived from Character or Wide_Character in the prefix of N.
430 -- Used to resolved qualified names whose selector is a character literal.
432 function Has_Private_With (E : Entity_Id) return Boolean;
433 -- Ada 2005 (AI-262): Determines if the current compilation unit has a
436 procedure Find_Expanded_Name (N : Node_Id);
437 -- Selected component is known to be expanded name. Verify legality
438 -- of selector given the scope denoted by prefix.
440 function Find_Renamed_Entity
444 Is_Actual : Boolean := False) return Entity_Id;
445 -- Find the renamed entity that corresponds to the given parameter profile
446 -- in a subprogram renaming declaration. The renamed entity may be an
447 -- operator, a subprogram, an entry, or a protected operation. Is_Actual
448 -- indicates that the renaming is the one generated for an actual subpro-
449 -- gram in an instance, for which special visibility checks apply.
451 function Has_Implicit_Operator (N : Node_Id) return Boolean;
452 -- N is an expanded name whose selector is an operator name (eg P."+").
453 -- A declarative part contains an implicit declaration of an operator
454 -- if it has a declaration of a type to which one of the predefined
455 -- operators apply. The existence of this routine is an artifact of
456 -- our implementation: a more straightforward but more space-consuming
457 -- choice would be to make all inherited operators explicit in the
460 procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id);
461 -- A subprogram defined by a renaming declaration inherits the parameter
462 -- profile of the renamed entity. The subtypes given in the subprogram
463 -- specification are discarded and replaced with those of the renamed
464 -- subprogram, which are then used to recheck the default values.
466 function Is_Appropriate_For_Record (T : Entity_Id) return Boolean;
467 -- Prefix is appropriate for record if it is of a record type, or
468 -- an access to such.
470 function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean;
471 -- True if it is of a task type, a protected type, or else an access
472 -- to one of these types.
474 procedure Premature_Usage (N : Node_Id);
475 -- Diagnose usage of an entity before it is visible
477 procedure Use_One_Package (P : Entity_Id; N : Node_Id);
478 -- Make visible entities declared in package P potentially use-visible
479 -- in the current context. Also used in the analysis of subunits, when
480 -- re-installing use clauses of parent units. N is the use_clause that
481 -- names P (and possibly other packages).
483 procedure Use_One_Type (Id : Node_Id);
484 -- Id is the subtype mark from a use type clause. This procedure makes
485 -- the primitive operators of the type potentially use-visible.
487 procedure Write_Info;
488 -- Write debugging information on entities declared in current scope
490 procedure Write_Scopes;
491 pragma Warnings (Off, Write_Scopes);
492 -- Debugging information: dump all entities on scope stack
494 --------------------------------
495 -- Analyze_Exception_Renaming --
496 --------------------------------
498 -- The language only allows a single identifier, but the tree holds
499 -- an identifier list. The parser has already issued an error message
500 -- if there is more than one element in the list.
502 procedure Analyze_Exception_Renaming (N : Node_Id) is
503 Id : constant Node_Id := Defining_Identifier (N);
504 Nam : constant Node_Id := Name (N);
510 Set_Ekind (Id, E_Exception);
511 Set_Exception_Code (Id, Uint_0);
512 Set_Etype (Id, Standard_Exception_Type);
513 Set_Is_Pure (Id, Is_Pure (Current_Scope));
515 if not Is_Entity_Name (Nam) or else
516 Ekind (Entity (Nam)) /= E_Exception
518 Error_Msg_N ("invalid exception name in renaming", Nam);
520 if Present (Renamed_Object (Entity (Nam))) then
521 Set_Renamed_Object (Id, Renamed_Object (Entity (Nam)));
523 Set_Renamed_Object (Id, Entity (Nam));
526 end Analyze_Exception_Renaming;
528 ---------------------------
529 -- Analyze_Expanded_Name --
530 ---------------------------
532 procedure Analyze_Expanded_Name (N : Node_Id) is
534 -- If the entity pointer is already set, this is an internal node, or
535 -- a node that is analyzed more than once, after a tree modification.
536 -- In such a case there is no resolution to perform, just set the type.
537 -- For completeness, analyze prefix as well.
539 if Present (Entity (N)) then
540 if Is_Type (Entity (N)) then
541 Set_Etype (N, Entity (N));
543 Set_Etype (N, Etype (Entity (N)));
546 Analyze (Prefix (N));
549 Find_Expanded_Name (N);
551 end Analyze_Expanded_Name;
553 ---------------------------------------
554 -- Analyze_Generic_Function_Renaming --
555 ---------------------------------------
557 procedure Analyze_Generic_Function_Renaming (N : Node_Id) is
559 Analyze_Generic_Renaming (N, E_Generic_Function);
560 end Analyze_Generic_Function_Renaming;
562 --------------------------------------
563 -- Analyze_Generic_Package_Renaming --
564 --------------------------------------
566 procedure Analyze_Generic_Package_Renaming (N : Node_Id) is
568 -- Apply the Text_IO Kludge here, since we may be renaming
569 -- one of the subpackages of Text_IO, then join common routine.
571 Text_IO_Kludge (Name (N));
573 Analyze_Generic_Renaming (N, E_Generic_Package);
574 end Analyze_Generic_Package_Renaming;
576 ----------------------------------------
577 -- Analyze_Generic_Procedure_Renaming --
578 ----------------------------------------
580 procedure Analyze_Generic_Procedure_Renaming (N : Node_Id) is
582 Analyze_Generic_Renaming (N, E_Generic_Procedure);
583 end Analyze_Generic_Procedure_Renaming;
585 ------------------------------
586 -- Analyze_Generic_Renaming --
587 ------------------------------
589 procedure Analyze_Generic_Renaming
593 New_P : constant Entity_Id := Defining_Entity (N);
595 Inst : Boolean := False; -- prevent junk warning
598 if Name (N) = Error then
602 Generate_Definition (New_P);
604 if Current_Scope /= Standard_Standard then
605 Set_Is_Pure (New_P, Is_Pure (Current_Scope));
608 if Nkind (Name (N)) = N_Selected_Component then
609 Check_Generic_Child_Unit (Name (N), Inst);
614 if not Is_Entity_Name (Name (N)) then
615 Error_Msg_N ("expect entity name in renaming declaration", Name (N));
618 Old_P := Entity (Name (N));
622 Set_Ekind (New_P, K);
624 if Etype (Old_P) = Any_Type then
627 elsif Ekind (Old_P) /= K then
628 Error_Msg_N ("invalid generic unit name", Name (N));
631 if Present (Renamed_Object (Old_P)) then
632 Set_Renamed_Object (New_P, Renamed_Object (Old_P));
634 Set_Renamed_Object (New_P, Old_P);
637 Set_Etype (New_P, Etype (Old_P));
638 Set_Has_Completion (New_P);
640 if In_Open_Scopes (Old_P) then
641 Error_Msg_N ("within its scope, generic denotes its instance", N);
644 Check_Library_Unit_Renaming (N, Old_P);
647 end Analyze_Generic_Renaming;
649 -----------------------------
650 -- Analyze_Object_Renaming --
651 -----------------------------
653 procedure Analyze_Object_Renaming (N : Node_Id) is
654 Id : constant Entity_Id := Defining_Identifier (N);
656 Nam : constant Node_Id := Name (N);
665 Set_Is_Pure (Id, Is_Pure (Current_Scope));
668 -- The renaming of a component that depends on a discriminant
669 -- requires an actual subtype, because in subsequent use of the object
670 -- Gigi will be unable to locate the actual bounds. This explicit step
671 -- is required when the renaming is generated in removing side effects
672 -- of an already-analyzed expression.
674 if Nkind (Nam) = N_Selected_Component
675 and then Analyzed (Nam)
678 Dec := Build_Actual_Subtype_Of_Component (Etype (Nam), Nam);
680 if Present (Dec) then
681 Insert_Action (N, Dec);
682 T := Defining_Identifier (Dec);
686 elsif Present (Subtype_Mark (N)) then
687 Find_Type (Subtype_Mark (N));
688 T := Entity (Subtype_Mark (N));
689 Analyze_And_Resolve (Nam, T);
691 -- Ada 2005 (AI-230/AI-254): Access renaming
693 else pragma Assert (Present (Access_Definition (N)));
694 T := Access_Definition
696 N => Access_Definition (N));
698 Analyze_And_Resolve (Nam, T);
700 -- Ada 2005 (AI-231): "In the case where the type is defined by an
701 -- access_definition, the renamed entity shall be of an access-to-
702 -- constant type if and only if the access_definition defines an
703 -- access-to-constant type" ARM 8.5.1(4)
705 if Constant_Present (Access_Definition (N))
706 and then not Is_Access_Constant (Etype (Nam))
708 Error_Msg_N ("(Ada 2005): the renamed object is not "
709 & "access-to-constant ('R'M 8.5.1(6))", N);
711 elsif Null_Exclusion_Present (Access_Definition (N)) then
712 Error_Msg_N ("(Ada 2005): null-excluding attribute ignored "
713 & "('R'M 8.5.1(6))?", N);
717 -- An object renaming requires an exact match of the type;
718 -- class-wide matching is not allowed.
720 if Is_Class_Wide_Type (T)
721 and then Base_Type (Etype (Nam)) /= Base_Type (T)
727 Set_Ekind (Id, E_Variable);
728 Init_Size_Align (Id);
730 if T = Any_Type or else Etype (Nam) = Any_Type then
733 -- Verify that the renamed entity is an object or a function call.
734 -- It may have been rewritten in several ways.
736 elsif Is_Object_Reference (Nam) then
737 if Comes_From_Source (N)
738 and then Is_Dependent_Component_Of_Mutable_Object (Nam)
741 ("illegal renaming of discriminant-dependent component", Nam);
746 -- A static function call may have been folded into a literal
748 elsif Nkind (Original_Node (Nam)) = N_Function_Call
750 -- When expansion is disabled, attribute reference is not
751 -- rewritten as function call. Otherwise it may be rewritten
752 -- as a conversion, so check original node.
754 or else (Nkind (Original_Node (Nam)) = N_Attribute_Reference
755 and then Is_Function_Attribute_Name
756 (Attribute_Name (Original_Node (Nam))))
758 -- Weird but legal, equivalent to renaming a function call
760 or else (Is_Entity_Name (Nam)
761 and then Ekind (Entity (Nam)) = E_Enumeration_Literal)
763 or else (Nkind (Nam) = N_Type_Conversion
764 and then Is_Tagged_Type (Entity (Subtype_Mark (Nam))))
769 if Nkind (Nam) = N_Type_Conversion then
771 ("renaming of conversion only allowed for tagged types", Nam);
774 Error_Msg_N ("expect object name in renaming", Nam);
780 if not Is_Variable (Nam) then
781 Set_Ekind (Id, E_Constant);
782 Set_Never_Set_In_Source (Id, True);
783 Set_Is_True_Constant (Id, True);
786 Set_Renamed_Object (Id, Nam);
787 end Analyze_Object_Renaming;
789 ------------------------------
790 -- Analyze_Package_Renaming --
791 ------------------------------
793 procedure Analyze_Package_Renaming (N : Node_Id) is
794 New_P : constant Entity_Id := Defining_Entity (N);
799 if Name (N) = Error then
803 -- Apply Text_IO kludge here, since we may be renaming one of
804 -- the children of Text_IO
806 Text_IO_Kludge (Name (N));
808 if Current_Scope /= Standard_Standard then
809 Set_Is_Pure (New_P, Is_Pure (Current_Scope));
814 if Is_Entity_Name (Name (N)) then
815 Old_P := Entity (Name (N));
820 if Etype (Old_P) = Any_Type then
822 ("expect package name in renaming", Name (N));
824 -- Ada 2005 (AI-50217): Limited withed packages can not be renamed
826 elsif Ekind (Old_P) = E_Package
827 and then From_With_Type (Old_P)
830 ("limited withed package cannot be renamed", Name (N));
832 elsif Ekind (Old_P) /= E_Package
833 and then not (Ekind (Old_P) = E_Generic_Package
834 and then In_Open_Scopes (Old_P))
836 if Ekind (Old_P) = E_Generic_Package then
838 ("generic package cannot be renamed as a package", Name (N));
840 Error_Msg_Sloc := Sloc (Old_P);
842 ("expect package name in renaming, found& declared#",
846 -- Set basic attributes to minimize cascaded errors
848 Set_Ekind (New_P, E_Package);
849 Set_Etype (New_P, Standard_Void_Type);
852 -- Entities in the old package are accessible through the
853 -- renaming entity. The simplest implementation is to have
854 -- both packages share the entity list.
856 Set_Ekind (New_P, E_Package);
857 Set_Etype (New_P, Standard_Void_Type);
859 if Present (Renamed_Object (Old_P)) then
860 Set_Renamed_Object (New_P, Renamed_Object (Old_P));
862 Set_Renamed_Object (New_P, Old_P);
865 Set_Has_Completion (New_P);
867 Set_First_Entity (New_P, First_Entity (Old_P));
868 Set_Last_Entity (New_P, Last_Entity (Old_P));
869 Set_First_Private_Entity (New_P, First_Private_Entity (Old_P));
870 Check_Library_Unit_Renaming (N, Old_P);
871 Generate_Reference (Old_P, Name (N));
873 -- If this is the renaming declaration of a package instantiation
874 -- within itself, it is the declaration that ends the list of actuals
875 -- for the instantiation. At this point, the subtypes that rename
876 -- the actuals are flagged as generic, to avoid spurious ambiguities
877 -- if the actuals for two distinct formals happen to coincide. If
878 -- the actual is a private type, the subtype has a private completion
879 -- that is flagged in the same fashion.
881 -- Resolution is identical to what is was in the original generic.
882 -- On exit from the generic instance, these are turned into regular
883 -- subtypes again, so they are compatible with types in their class.
885 if not Is_Generic_Instance (Old_P) then
888 Spec := Specification (Unit_Declaration_Node (Old_P));
891 if Nkind (Spec) = N_Package_Specification
892 and then Present (Generic_Parent (Spec))
893 and then Old_P = Current_Scope
894 and then Chars (New_P) = Chars (Generic_Parent (Spec))
897 E : Entity_Id := First_Entity (Old_P);
903 and then Nkind (Parent (E)) = N_Subtype_Declaration
905 Set_Is_Generic_Actual_Type (E);
907 if Is_Private_Type (E)
908 and then Present (Full_View (E))
910 Set_Is_Generic_Actual_Type (Full_View (E));
920 end Analyze_Package_Renaming;
922 -------------------------------
923 -- Analyze_Renamed_Character --
924 -------------------------------
926 procedure Analyze_Renamed_Character
931 C : constant Node_Id := Name (N);
934 if Ekind (New_S) = E_Function then
935 Resolve (C, Etype (New_S));
938 Check_Frozen_Renaming (N, New_S);
942 Error_Msg_N ("character literal can only be renamed as function", N);
944 end Analyze_Renamed_Character;
946 ---------------------------------
947 -- Analyze_Renamed_Dereference --
948 ---------------------------------
950 procedure Analyze_Renamed_Dereference
955 Nam : constant Node_Id := Name (N);
956 P : constant Node_Id := Prefix (Nam);
962 if not Is_Overloaded (P) then
963 if Ekind (Etype (Nam)) /= E_Subprogram_Type
964 or else not Type_Conformant (Etype (Nam), New_S) then
965 Error_Msg_N ("designated type does not match specification", P);
974 Get_First_Interp (Nam, Ind, It);
976 while Present (It.Nam) loop
978 if Ekind (It.Nam) = E_Subprogram_Type
979 and then Type_Conformant (It.Nam, New_S) then
981 if Typ /= Any_Id then
982 Error_Msg_N ("ambiguous renaming", P);
989 Get_Next_Interp (Ind, It);
992 if Typ = Any_Type then
993 Error_Msg_N ("designated type does not match specification", P);
998 Check_Frozen_Renaming (N, New_S);
1002 end Analyze_Renamed_Dereference;
1004 ---------------------------
1005 -- Analyze_Renamed_Entry --
1006 ---------------------------
1008 procedure Analyze_Renamed_Entry
1013 Nam : constant Node_Id := Name (N);
1014 Sel : constant Node_Id := Selector_Name (Nam);
1018 if Entity (Sel) = Any_Id then
1020 -- Selector is undefined on prefix. Error emitted already
1022 Set_Has_Completion (New_S);
1026 -- Otherwise, find renamed entity, and build body of New_S as a call
1029 Old_S := Find_Renamed_Entity (N, Selector_Name (Nam), New_S);
1031 if Old_S = Any_Id then
1032 Error_Msg_N (" no subprogram or entry matches specification", N);
1035 Check_Subtype_Conformant (New_S, Old_S, N);
1036 Generate_Reference (New_S, Defining_Entity (N), 'b');
1037 Style.Check_Identifier (Defining_Entity (N), New_S);
1040 Inherit_Renamed_Profile (New_S, Old_S);
1043 Set_Convention (New_S, Convention (Old_S));
1044 Set_Has_Completion (New_S, Inside_A_Generic);
1047 Check_Frozen_Renaming (N, New_S);
1049 end Analyze_Renamed_Entry;
1051 -----------------------------------
1052 -- Analyze_Renamed_Family_Member --
1053 -----------------------------------
1055 procedure Analyze_Renamed_Family_Member
1060 Nam : constant Node_Id := Name (N);
1061 P : constant Node_Id := Prefix (Nam);
1065 if (Is_Entity_Name (P) and then Ekind (Entity (P)) = E_Entry_Family)
1066 or else (Nkind (P) = N_Selected_Component
1068 Ekind (Entity (Selector_Name (P))) = E_Entry_Family)
1070 if Is_Entity_Name (P) then
1071 Old_S := Entity (P);
1073 Old_S := Entity (Selector_Name (P));
1076 if not Entity_Matches_Spec (Old_S, New_S) then
1077 Error_Msg_N ("entry family does not match specification", N);
1080 Check_Subtype_Conformant (New_S, Old_S, N);
1081 Generate_Reference (New_S, Defining_Entity (N), 'b');
1082 Style.Check_Identifier (Defining_Entity (N), New_S);
1085 Error_Msg_N ("no entry family matches specification", N);
1088 Set_Has_Completion (New_S, Inside_A_Generic);
1091 Check_Frozen_Renaming (N, New_S);
1093 end Analyze_Renamed_Family_Member;
1095 ---------------------------------
1096 -- Analyze_Subprogram_Renaming --
1097 ---------------------------------
1099 procedure Analyze_Subprogram_Renaming (N : Node_Id) is
1100 Spec : constant Node_Id := Specification (N);
1101 Save_AV : constant Ada_Version_Type := Ada_Version;
1102 Nam : constant Node_Id := Name (N);
1104 Old_S : Entity_Id := Empty;
1105 Rename_Spec : Entity_Id;
1106 Is_Actual : Boolean := False;
1107 Inst_Node : Node_Id := Empty;
1109 function Original_Subprogram (Subp : Entity_Id) return Entity_Id;
1110 -- Find renamed entity when the declaration is a renaming_as_body
1111 -- and the renamed entity may itself be a renaming_as_body. Used to
1112 -- enforce rule that a renaming_as_body is illegal if the declaration
1113 -- occurs before the subprogram it completes is frozen, and renaming
1114 -- indirectly renames the subprogram itself.(Defect Report 8652/0027).
1116 -------------------------
1117 -- Original_Subprogram --
1118 -------------------------
1120 function Original_Subprogram (Subp : Entity_Id) return Entity_Id is
1121 Orig_Decl : Node_Id;
1122 Orig_Subp : Entity_Id;
1125 -- First case: renamed entity is itself a renaming
1127 if Present (Alias (Subp)) then
1128 return Alias (Subp);
1131 Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration
1133 (Corresponding_Body (Unit_Declaration_Node (Subp)))
1135 -- Check if renamed entity is a renaming_as_body
1138 Unit_Declaration_Node
1139 (Corresponding_Body (Unit_Declaration_Node (Subp)));
1141 if Nkind (Orig_Decl) = N_Subprogram_Renaming_Declaration then
1142 Orig_Subp := Entity (Name (Orig_Decl));
1144 if Orig_Subp = Rename_Spec then
1146 -- Circularity detected
1151 return (Original_Subprogram (Orig_Subp));
1159 end Original_Subprogram;
1161 -- Start of processing for Analyze_Subprogram_Renaming
1164 -- We must test for the attribute renaming case before the Analyze
1165 -- call because otherwise Sem_Attr will complain that the attribute
1166 -- is missing an argument when it is analyzed.
1168 if Nkind (Nam) = N_Attribute_Reference then
1169 Attribute_Renaming (N);
1173 -- Check whether this declaration corresponds to the instantiation
1174 -- of a formal subprogram.
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_Formal_Spec (N)) then
1187 Inst_Node := Unit_Declaration_Node (Corresponding_Formal_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);
1248 -- Renamed entity must be analyzed first, to avoid being hidden by
1249 -- new name (which might be the same in a generic instance).
1253 -- The renaming defines a new overloaded entity, which is analyzed
1254 -- like a subprogram declaration.
1256 New_S := Analyze_Subprogram_Specification (Spec);
1259 if Current_Scope /= Standard_Standard then
1260 Set_Is_Pure (New_S, Is_Pure (Current_Scope));
1263 Rename_Spec := Find_Corresponding_Spec (N);
1265 if Present (Rename_Spec) then
1267 -- Renaming_As_Body. Renaming declaration is the completion of
1268 -- the declaration of Rename_Spec. We will build an actual body
1269 -- for it at the freezing point.
1271 Set_Corresponding_Spec (N, Rename_Spec);
1272 Set_Corresponding_Body (Unit_Declaration_Node (Rename_Spec), New_S);
1274 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
1275 Error_Msg_N ("(Ada 83) renaming cannot serve as a body", N);
1278 Set_Convention (New_S, Convention (Rename_Spec));
1279 Check_Fully_Conformant (New_S, Rename_Spec);
1280 Set_Public_Status (New_S);
1282 -- Indicate that the entity in the declaration functions like
1283 -- the corresponding body, and is not a new entity. The body will
1284 -- be constructed later at the freeze point, so indicate that
1285 -- the completion has not been seen yet.
1287 Set_Ekind (New_S, E_Subprogram_Body);
1288 New_S := Rename_Spec;
1289 Set_Has_Completion (Rename_Spec, False);
1292 Generate_Definition (New_S);
1293 New_Overloaded_Entity (New_S);
1294 if Is_Entity_Name (Nam)
1295 and then Is_Intrinsic_Subprogram (Entity (Nam))
1299 Check_Delayed_Subprogram (New_S);
1303 -- There is no need for elaboration checks on the new entity, which
1304 -- may be called before the next freezing point where the body will
1305 -- appear. Elaboration checks refer to the real entity, not the one
1306 -- created by the renaming declaration.
1308 Set_Kill_Elaboration_Checks (New_S, True);
1310 if Etype (Nam) = Any_Type then
1311 Set_Has_Completion (New_S);
1314 elsif Nkind (Nam) = N_Selected_Component then
1316 -- Renamed entity is an entry or protected subprogram. For those
1317 -- cases an explicit body is built (at the point of freezing of
1318 -- this entity) that contains a call to the renamed entity.
1320 Analyze_Renamed_Entry (N, New_S, Present (Rename_Spec));
1323 elsif Nkind (Nam) = N_Explicit_Dereference then
1325 -- Renamed entity is designated by access_to_subprogram expression.
1326 -- Must build body to encapsulate call, as in the entry case.
1328 Analyze_Renamed_Dereference (N, New_S, Present (Rename_Spec));
1331 elsif Nkind (Nam) = N_Indexed_Component then
1332 Analyze_Renamed_Family_Member (N, New_S, Present (Rename_Spec));
1335 elsif Nkind (Nam) = N_Character_Literal then
1336 Analyze_Renamed_Character (N, New_S, Present (Rename_Spec));
1339 elsif (not Is_Entity_Name (Nam)
1340 and then Nkind (Nam) /= N_Operator_Symbol)
1341 or else not Is_Overloadable (Entity (Nam))
1343 Error_Msg_N ("expect valid subprogram name in renaming", N);
1348 -- Most common case: subprogram renames subprogram. No body is
1349 -- generated in this case, so we must indicate that the declaration
1350 -- is complete as is.
1352 if No (Rename_Spec) then
1353 Set_Has_Completion (New_S);
1356 -- Find the renamed entity that matches the given specification.
1357 -- Disable Ada_83 because there is no requirement of full conformance
1358 -- between renamed entity and new entity, even though the same circuit
1361 Ada_Version := Ada_Version_Type'Max (Ada_Version, Ada_95);
1364 Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
1367 if Old_S /= Any_Id then
1369 and then From_Default (N)
1371 -- This is an implicit reference to the default actual
1373 Generate_Reference (Old_S, Nam, Typ => 'i', Force => True);
1375 Generate_Reference (Old_S, Nam);
1378 -- For a renaming-as-body, require subtype conformance,
1379 -- but if the declaration being completed has not been
1380 -- frozen, then inherit the convention of the renamed
1381 -- subprogram prior to checking conformance (unless the
1382 -- renaming has an explicit convention established; the
1383 -- rule stated in the RM doesn't seem to address this ???).
1385 if Present (Rename_Spec) then
1386 Generate_Reference (Rename_Spec, Defining_Entity (Spec), 'b');
1387 Style.Check_Identifier (Defining_Entity (Spec), Rename_Spec);
1389 if not Is_Frozen (Rename_Spec) then
1390 if not Has_Convention_Pragma (Rename_Spec) then
1391 Set_Convention (New_S, Convention (Old_S));
1394 if Ekind (Old_S) /= E_Operator then
1395 Check_Mode_Conformant (New_S, Old_S, Spec);
1398 if Original_Subprogram (Old_S) = Rename_Spec then
1399 Error_Msg_N ("unfrozen subprogram cannot rename itself ", N);
1402 Check_Subtype_Conformant (New_S, Old_S, Spec);
1405 Check_Frozen_Renaming (N, Rename_Spec);
1407 -- Check explicitly that renamed entity is not intrinsic, because
1408 -- in in a generic the renamed body is not built. In this case,
1409 -- the renaming_as_body is a completion.
1411 if Inside_A_Generic then
1412 if Is_Frozen (Rename_Spec)
1413 and then Is_Intrinsic_Subprogram (Old_S)
1416 ("subprogram in renaming_as_body cannot be intrinsic",
1420 Set_Has_Completion (Rename_Spec);
1423 elsif Ekind (Old_S) /= E_Operator then
1424 Check_Mode_Conformant (New_S, Old_S);
1427 and then Error_Posted (New_S)
1429 Error_Msg_NE ("invalid actual subprogram: & #!", N, Old_S);
1433 if No (Rename_Spec) then
1435 -- The parameter profile of the new entity is that of the renamed
1436 -- entity: the subtypes given in the specification are irrelevant.
1438 Inherit_Renamed_Profile (New_S, Old_S);
1440 -- A call to the subprogram is transformed into a call to the
1441 -- renamed entity. This is transitive if the renamed entity is
1442 -- itself a renaming.
1444 if Present (Alias (Old_S)) then
1445 Set_Alias (New_S, Alias (Old_S));
1447 Set_Alias (New_S, Old_S);
1450 -- Note that we do not set Is_Intrinsic_Subprogram if we have
1451 -- a renaming as body, since the entity in this case is not an
1452 -- intrinsic (it calls an intrinsic, but we have a real body
1453 -- for this call, and it is in this body that the required
1454 -- intrinsic processing will take place).
1456 -- Also, if this is a renaming of inequality, the renamed
1457 -- operator is intrinsic, but what matters is the corresponding
1458 -- equality operator, which may be user-defined.
1460 Set_Is_Intrinsic_Subprogram
1462 Is_Intrinsic_Subprogram (Old_S)
1464 (Chars (Old_S) /= Name_Op_Ne
1465 or else Ekind (Old_S) = E_Operator
1467 Is_Intrinsic_Subprogram
1468 (Corresponding_Equality (Old_S))));
1470 if Ekind (Alias (New_S)) = E_Operator then
1471 Set_Has_Delayed_Freeze (New_S, False);
1474 -- If the renaming corresponds to an association for an abstract
1475 -- formal subprogram, then various attributes must be set to
1476 -- indicate that the renaming is an abstract dispatching operation
1477 -- with a controlling type.
1480 and then Is_Abstract (Corresponding_Formal_Spec (N))
1482 -- Mark the renaming as abstract here, so Find_Dispatching_Type
1483 -- see it as corresponding to a generic association for a
1484 -- formal abstract subprogram
1486 Set_Is_Abstract (New_S);
1489 New_S_Ctrl_Type : constant Entity_Id :=
1490 Find_Dispatching_Type (New_S);
1491 Old_S_Ctrl_Type : constant Entity_Id :=
1492 Find_Dispatching_Type (Old_S);
1495 if Old_S_Ctrl_Type /= New_S_Ctrl_Type then
1497 ("actual must be dispatching subprogram for type&",
1498 Nam, New_S_Ctrl_Type);
1501 Set_Is_Dispatching_Operation (New_S);
1502 Check_Controlling_Formals (New_S_Ctrl_Type, New_S);
1504 -- In the case where the actual in the formal subprogram
1505 -- is itself a formal abstract subprogram association,
1506 -- there's no dispatch table component or position to
1509 if Present (DTC_Entity (Old_S)) then
1510 Set_DTC_Entity (New_S, DTC_Entity (Old_S));
1511 Set_DT_Position (New_S, DT_Position (Old_S));
1519 and then (Old_S = New_S
1520 or else (Nkind (Nam) /= N_Expanded_Name
1521 and then Chars (Old_S) = Chars (New_S)))
1523 Error_Msg_N ("subprogram cannot rename itself", N);
1526 Set_Convention (New_S, Convention (Old_S));
1527 Set_Is_Abstract (New_S, Is_Abstract (Old_S));
1528 Check_Library_Unit_Renaming (N, Old_S);
1530 -- Pathological case: procedure renames entry in the scope of
1531 -- its task. Entry is given by simple name, but body must be built
1532 -- for procedure. Of course if called it will deadlock.
1534 if Ekind (Old_S) = E_Entry then
1535 Set_Has_Completion (New_S, False);
1536 Set_Alias (New_S, Empty);
1540 Freeze_Before (N, Old_S);
1541 Set_Has_Delayed_Freeze (New_S, False);
1542 Freeze_Before (N, New_S);
1544 -- An abstract subprogram is only allowed as an actual in the case
1545 -- where the formal subprogram is also abstract.
1547 if (Ekind (Old_S) = E_Procedure or else Ekind (Old_S) = E_Function)
1548 and then Is_Abstract (Old_S)
1549 and then not Is_Abstract (Corresponding_Formal_Spec (N))
1552 ("abstract subprogram not allowed as generic actual", Nam);
1557 -- A common error is to assume that implicit operators for types
1558 -- are defined in Standard, or in the scope of a subtype. In those
1559 -- cases where the renamed entity is given with an expanded name,
1560 -- it is worth mentioning that operators for the type are not
1561 -- declared in the scope given by the prefix.
1563 if Nkind (Nam) = N_Expanded_Name
1564 and then Nkind (Selector_Name (Nam)) = N_Operator_Symbol
1565 and then Scope (Entity (Nam)) = Standard_Standard
1568 T : constant Entity_Id :=
1569 Base_Type (Etype (First_Formal (New_S)));
1572 Error_Msg_Node_2 := Prefix (Nam);
1574 ("operator for type& is not declared in&", Prefix (Nam), T);
1579 ("no visible subprogram matches the specification for&",
1583 if Present (Candidate_Renaming) then
1589 F1 := First_Formal (Candidate_Renaming);
1590 F2 := First_Formal (New_S);
1592 while Present (F1) and then Present (F2) loop
1597 if Present (F1) and then Present (Default_Value (F1)) then
1598 if Present (Next_Formal (F1)) then
1600 ("\missing specification for &" &
1601 " and other formals with defaults", Spec, F1);
1604 ("\missing specification for &", Spec, F1);
1611 Ada_Version := Save_AV;
1612 end Analyze_Subprogram_Renaming;
1614 -------------------------
1615 -- Analyze_Use_Package --
1616 -------------------------
1618 -- Resolve the package names in the use clause, and make all the visible
1619 -- entities defined in the package potentially use-visible. If the package
1620 -- is already in use from a previous use clause, its visible entities are
1621 -- already use-visible. In that case, mark the occurrence as a redundant
1622 -- use. If the package is an open scope, i.e. if the use clause occurs
1623 -- within the package itself, ignore it.
1625 procedure Analyze_Use_Package (N : Node_Id) is
1626 Pack_Name : Node_Id;
1629 -- Start of processing for Analyze_Use_Package
1632 Set_Hidden_By_Use_Clause (N, No_Elist);
1634 -- Use clause is not allowed in a spec of a predefined package
1635 -- declaration except that packages whose file name starts a-n
1636 -- are OK (these are children of Ada.Numerics, and such packages
1637 -- are never loaded by Rtsfind).
1639 if Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
1640 and then Name_Buffer (1 .. 3) /= "a-n"
1642 Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
1644 Error_Msg_N ("use clause not allowed in predefined spec", N);
1647 -- Chain clause to list of use clauses in current scope
1649 if Nkind (Parent (N)) /= N_Compilation_Unit then
1650 Chain_Use_Clause (N);
1653 -- Loop through package names to identify referenced packages
1655 Pack_Name := First (Names (N));
1657 while Present (Pack_Name) loop
1658 Analyze (Pack_Name);
1660 if Nkind (Parent (N)) = N_Compilation_Unit
1661 and then Nkind (Pack_Name) = N_Expanded_Name
1664 Pref : Node_Id := Prefix (Pack_Name);
1667 while Nkind (Pref) = N_Expanded_Name loop
1668 Pref := Prefix (Pref);
1671 if Entity (Pref) = Standard_Standard then
1673 ("predefined package Standard cannot appear"
1674 & " in a context clause", Pref);
1682 -- Loop through package names to mark all entities as potentially
1685 Pack_Name := First (Names (N));
1687 while Present (Pack_Name) loop
1689 if Is_Entity_Name (Pack_Name) then
1690 Pack := Entity (Pack_Name);
1692 if Ekind (Pack) /= E_Package
1693 and then Etype (Pack) /= Any_Type
1695 if Ekind (Pack) = E_Generic_Package then
1697 ("a generic package is not allowed in a use clause",
1700 Error_Msg_N ("& is not a usable package", Pack_Name);
1704 if Nkind (Parent (N)) = N_Compilation_Unit then
1705 Check_In_Previous_With_Clause (N, Pack_Name);
1708 if Applicable_Use (Pack_Name) then
1709 Use_One_Package (Pack, N);
1717 end Analyze_Use_Package;
1719 ----------------------
1720 -- Analyze_Use_Type --
1721 ----------------------
1723 procedure Analyze_Use_Type (N : Node_Id) is
1727 Set_Hidden_By_Use_Clause (N, No_Elist);
1729 -- Chain clause to list of use clauses in current scope
1731 if Nkind (Parent (N)) /= N_Compilation_Unit then
1732 Chain_Use_Clause (N);
1735 Id := First (Subtype_Marks (N));
1737 while Present (Id) loop
1740 if Entity (Id) /= Any_Type then
1743 if Nkind (Parent (N)) = N_Compilation_Unit then
1744 if Nkind (Id) = N_Identifier then
1745 Error_Msg_N ("Type is not directly visible", Id);
1747 elsif Is_Child_Unit (Scope (Entity (Id)))
1748 and then Scope (Entity (Id)) /= System_Aux_Id
1750 Check_In_Previous_With_Clause (N, Prefix (Id));
1757 end Analyze_Use_Type;
1759 --------------------
1760 -- Applicable_Use --
1761 --------------------
1763 function Applicable_Use (Pack_Name : Node_Id) return Boolean is
1764 Pack : constant Entity_Id := Entity (Pack_Name);
1767 if In_Open_Scopes (Pack) then
1770 elsif In_Use (Pack) then
1771 Set_Redundant_Use (Pack_Name, True);
1774 elsif Present (Renamed_Object (Pack))
1775 and then In_Use (Renamed_Object (Pack))
1777 Set_Redundant_Use (Pack_Name, True);
1785 ------------------------
1786 -- Attribute_Renaming --
1787 ------------------------
1789 procedure Attribute_Renaming (N : Node_Id) is
1790 Loc : constant Source_Ptr := Sloc (N);
1791 Nam : constant Node_Id := Name (N);
1792 Spec : constant Node_Id := Specification (N);
1793 New_S : constant Entity_Id := Defining_Unit_Name (Spec);
1794 Aname : constant Name_Id := Attribute_Name (Nam);
1796 Form_Num : Nat := 0;
1797 Expr_List : List_Id := No_List;
1799 Attr_Node : Node_Id;
1800 Body_Node : Node_Id;
1801 Param_Spec : Node_Id;
1804 Generate_Definition (New_S);
1806 -- This procedure is called in the context of subprogram renaming,
1807 -- and thus the attribute must be one that is a subprogram. All of
1808 -- those have at least one formal parameter, with the singular
1809 -- exception of AST_Entry (which is a real oddity, it is odd that
1810 -- this can be renamed at all!)
1812 if not Is_Non_Empty_List (Parameter_Specifications (Spec)) then
1813 if Aname /= Name_AST_Entry then
1815 ("subprogram renaming an attribute must have formals", N);
1820 Param_Spec := First (Parameter_Specifications (Spec));
1822 while Present (Param_Spec) loop
1823 Form_Num := Form_Num + 1;
1825 if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
1826 Find_Type (Parameter_Type (Param_Spec));
1828 -- The profile of the new entity denotes the base type (s) of
1829 -- the types given in the specification. For access parameters
1830 -- there are no subtypes involved.
1832 Rewrite (Parameter_Type (Param_Spec),
1834 (Base_Type (Entity (Parameter_Type (Param_Spec))), Loc));
1837 if No (Expr_List) then
1838 Expr_List := New_List;
1841 Append_To (Expr_List,
1842 Make_Identifier (Loc,
1843 Chars => Chars (Defining_Identifier (Param_Spec))));
1845 -- The expressions in the attribute reference are not freeze
1846 -- points. Neither is the attribute as a whole, see below.
1848 Set_Must_Not_Freeze (Last (Expr_List));
1853 -- Immediate error if too many formals. Other mismatches in numbers
1854 -- of number of types of parameters are detected when we analyze the
1855 -- body of the subprogram that we construct.
1857 if Form_Num > 2 then
1858 Error_Msg_N ("too many formals for attribute", N);
1860 -- Error if the attribute reference has expressions that look
1861 -- like formal parameters.
1863 elsif Present (Expressions (Nam)) then
1864 Error_Msg_N ("illegal expressions in attribute reference", Nam);
1867 Aname = Name_Compose or else
1868 Aname = Name_Exponent or else
1869 Aname = Name_Leading_Part or else
1870 Aname = Name_Pos or else
1871 Aname = Name_Round or else
1872 Aname = Name_Scaling or else
1875 if Nkind (N) = N_Subprogram_Renaming_Declaration
1876 and then Present (Corresponding_Formal_Spec (N))
1879 ("generic actual cannot be attribute involving universal type",
1883 ("attribute involving a universal type cannot be renamed",
1888 -- AST_Entry is an odd case. It doesn't really make much sense to
1889 -- allow it to be renamed, but that's the DEC rule, so we have to
1890 -- do it right. The point is that the AST_Entry call should be made
1891 -- now, and what the function will return is the returned value.
1893 -- Note that there is no Expr_List in this case anyway
1895 if Aname = Name_AST_Entry then
1902 Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
1905 Make_Object_Declaration (Loc,
1906 Defining_Identifier => Ent,
1907 Object_Definition =>
1908 New_Occurrence_Of (RTE (RE_AST_Handler), Loc),
1910 Constant_Present => True);
1912 Set_Assignment_OK (Decl, True);
1913 Insert_Action (N, Decl);
1914 Attr_Node := Make_Identifier (Loc, Chars (Ent));
1917 -- For all other attributes, we rewrite the attribute node to have
1918 -- a list of expressions corresponding to the subprogram formals.
1919 -- A renaming declaration is not a freeze point, and the analysis of
1920 -- the attribute reference should not freeze the type of the prefix.
1924 Make_Attribute_Reference (Loc,
1925 Prefix => Prefix (Nam),
1926 Attribute_Name => Aname,
1927 Expressions => Expr_List);
1929 Set_Must_Not_Freeze (Attr_Node);
1930 Set_Must_Not_Freeze (Prefix (Nam));
1933 -- Case of renaming a function
1935 if Nkind (Spec) = N_Function_Specification then
1937 if Is_Procedure_Attribute_Name (Aname) then
1938 Error_Msg_N ("attribute can only be renamed as procedure", Nam);
1942 Find_Type (Subtype_Mark (Spec));
1943 Rewrite (Subtype_Mark (Spec),
1944 New_Reference_To (Base_Type (Entity (Subtype_Mark (Spec))), Loc));
1947 Make_Subprogram_Body (Loc,
1948 Specification => Spec,
1949 Declarations => New_List,
1950 Handled_Statement_Sequence =>
1951 Make_Handled_Sequence_Of_Statements (Loc,
1952 Statements => New_List (
1953 Make_Return_Statement (Loc,
1954 Expression => Attr_Node))));
1956 -- Case of renaming a procedure
1959 if not Is_Procedure_Attribute_Name (Aname) then
1960 Error_Msg_N ("attribute can only be renamed as function", Nam);
1965 Make_Subprogram_Body (Loc,
1966 Specification => Spec,
1967 Declarations => New_List,
1968 Handled_Statement_Sequence =>
1969 Make_Handled_Sequence_Of_Statements (Loc,
1970 Statements => New_List (Attr_Node)));
1973 Rewrite (N, Body_Node);
1976 if Is_Compilation_Unit (New_S) then
1978 ("a library unit can only rename another library unit", N);
1981 Set_Etype (New_S, Base_Type (Etype (New_S)));
1983 -- We suppress elaboration warnings for the resulting entity, since
1984 -- clearly they are not needed, and more particularly, in the case
1985 -- of a generic formal subprogram, the resulting entity can appear
1986 -- after the instantiation itself, and thus look like a bogus case
1987 -- of access before elaboration.
1989 Set_Suppress_Elaboration_Warnings (New_S);
1991 end Attribute_Renaming;
1993 ----------------------
1994 -- Chain_Use_Clause --
1995 ----------------------
1997 procedure Chain_Use_Clause (N : Node_Id) is
1999 Set_Next_Use_Clause (N,
2000 Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause);
2001 Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause := N;
2002 end Chain_Use_Clause;
2004 ---------------------------
2005 -- Check_Frozen_Renaming --
2006 ---------------------------
2008 procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id) is
2014 and then not Has_Completion (Subp)
2018 (Parent (Declaration_Node (Subp)), Defining_Entity (N));
2020 if Is_Entity_Name (Name (N)) then
2021 Old_S := Entity (Name (N));
2023 if not Is_Frozen (Old_S)
2024 and then Operating_Mode /= Check_Semantics
2026 Append_Freeze_Action (Old_S, B_Node);
2028 Insert_After (N, B_Node);
2032 if Is_Intrinsic_Subprogram (Old_S)
2033 and then not In_Instance
2036 ("subprogram used in renaming_as_body cannot be intrinsic",
2041 Insert_After (N, B_Node);
2045 end Check_Frozen_Renaming;
2047 -----------------------------------
2048 -- Check_In_Previous_With_Clause --
2049 -----------------------------------
2051 procedure Check_In_Previous_With_Clause
2055 Pack : constant Entity_Id := Entity (Original_Node (Nam));
2060 Item := First (Context_Items (Parent (N)));
2062 while Present (Item)
2065 if Nkind (Item) = N_With_Clause
2066 and then Entity (Name (Item)) = Pack
2070 -- Find root library unit in with_clause
2072 while Nkind (Par) = N_Expanded_Name loop
2073 Par := Prefix (Par);
2076 if Is_Child_Unit (Entity (Original_Node (Par))) then
2078 ("& is not directly visible", Par, Entity (Par));
2087 -- On exit, package is not mentioned in a previous with_clause.
2088 -- Check if its prefix is.
2090 if Nkind (Nam) = N_Expanded_Name then
2091 Check_In_Previous_With_Clause (N, Prefix (Nam));
2093 elsif Pack /= Any_Id then
2094 Error_Msg_NE ("& is not visible", Nam, Pack);
2096 end Check_In_Previous_With_Clause;
2098 ---------------------------------
2099 -- Check_Library_Unit_Renaming --
2100 ---------------------------------
2102 procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id) is
2106 if Nkind (Parent (N)) /= N_Compilation_Unit then
2109 elsif Scope (Old_E) /= Standard_Standard
2110 and then not Is_Child_Unit (Old_E)
2112 Error_Msg_N ("renamed unit must be a library unit", Name (N));
2114 -- Entities defined in Standard (operators and boolean literals) cannot
2115 -- be renamed as library units.
2117 elsif Scope (Old_E) = Standard_Standard
2118 and then Sloc (Old_E) = Standard_Location
2120 Error_Msg_N ("renamed unit must be a library unit", Name (N));
2122 elsif Present (Parent_Spec (N))
2123 and then Nkind (Unit (Parent_Spec (N))) = N_Generic_Package_Declaration
2124 and then not Is_Child_Unit (Old_E)
2127 ("renamed unit must be a child unit of generic parent", Name (N));
2129 elsif Nkind (N) in N_Generic_Renaming_Declaration
2130 and then Nkind (Name (N)) = N_Expanded_Name
2131 and then Is_Generic_Instance (Entity (Prefix (Name (N))))
2132 and then Is_Generic_Unit (Old_E)
2135 ("renamed generic unit must be a library unit", Name (N));
2137 elsif Ekind (Old_E) = E_Package
2138 or else Ekind (Old_E) = E_Generic_Package
2140 -- Inherit categorization flags
2142 New_E := Defining_Entity (N);
2143 Set_Is_Pure (New_E, Is_Pure (Old_E));
2144 Set_Is_Preelaborated (New_E, Is_Preelaborated (Old_E));
2145 Set_Is_Remote_Call_Interface (New_E,
2146 Is_Remote_Call_Interface (Old_E));
2147 Set_Is_Remote_Types (New_E, Is_Remote_Types (Old_E));
2148 Set_Is_Shared_Passive (New_E, Is_Shared_Passive (Old_E));
2150 end Check_Library_Unit_Renaming;
2156 procedure End_Scope is
2162 Id := First_Entity (Current_Scope);
2164 while Present (Id) loop
2165 -- An entity in the current scope is not necessarily the first one
2166 -- on its homonym chain. Find its predecessor if any,
2167 -- If it is an internal entity, it will not be in the visibility
2168 -- chain altogether, and there is nothing to unchain.
2170 if Id /= Current_Entity (Id) then
2171 Prev := Current_Entity (Id);
2172 while Present (Prev)
2173 and then Present (Homonym (Prev))
2174 and then Homonym (Prev) /= Id
2176 Prev := Homonym (Prev);
2179 -- Skip to end of loop if Id is not in the visibility chain
2181 if No (Prev) or else Homonym (Prev) /= Id then
2189 Outer := Homonym (Id);
2190 Set_Is_Immediately_Visible (Id, False);
2192 while Present (Outer) and then Scope (Outer) = Current_Scope loop
2193 Outer := Homonym (Outer);
2196 -- Reset homonym link of other entities, but do not modify link
2197 -- between entities in current scope, so that the back-end can have
2198 -- a proper count of local overloadings.
2201 Set_Name_Entity_Id (Chars (Id), Outer);
2203 elsif Scope (Prev) /= Scope (Id) then
2204 Set_Homonym (Prev, Outer);
2211 -- If the scope generated freeze actions, place them before the
2212 -- current declaration and analyze them. Type declarations and
2213 -- the bodies of initialization procedures can generate such nodes.
2214 -- We follow the parent chain until we reach a list node, which is
2215 -- the enclosing list of declarations. If the list appears within
2216 -- a protected definition, move freeze nodes outside the protected
2220 (Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions)
2224 L : constant List_Id := Scope_Stack.Table
2225 (Scope_Stack.Last).Pending_Freeze_Actions;
2228 if Is_Itype (Current_Scope) then
2229 Decl := Associated_Node_For_Itype (Current_Scope);
2231 Decl := Parent (Current_Scope);
2236 while not (Is_List_Member (Decl))
2237 or else Nkind (Parent (Decl)) = N_Protected_Definition
2238 or else Nkind (Parent (Decl)) = N_Task_Definition
2240 Decl := Parent (Decl);
2243 Insert_List_Before_And_Analyze (Decl, L);
2252 ---------------------
2253 -- End_Use_Clauses --
2254 ---------------------
2256 procedure End_Use_Clauses (Clause : Node_Id) is
2260 -- Remove Use_Type clauses first, because they affect the
2261 -- visibility of operators in subsequent used packages.
2264 while Present (U) loop
2265 if Nkind (U) = N_Use_Type_Clause then
2269 Next_Use_Clause (U);
2273 while Present (U) loop
2274 if Nkind (U) = N_Use_Package_Clause then
2275 End_Use_Package (U);
2278 Next_Use_Clause (U);
2280 end End_Use_Clauses;
2282 ---------------------
2283 -- End_Use_Package --
2284 ---------------------
2286 procedure End_Use_Package (N : Node_Id) is
2287 Pack_Name : Node_Id;
2292 function Is_Primitive_Operator
2294 F : Entity_Id) return Boolean;
2295 -- Check whether Op is a primitive operator of a use-visible type
2297 ---------------------------
2298 -- Is_Primitive_Operator --
2299 ---------------------------
2301 function Is_Primitive_Operator
2303 F : Entity_Id) return Boolean
2305 T : constant Entity_Id := Etype (F);
2309 and then Scope (T) = Scope (Op);
2310 end Is_Primitive_Operator;
2312 -- Start of processing for End_Use_Package
2315 Pack_Name := First (Names (N));
2317 while Present (Pack_Name) loop
2318 Pack := Entity (Pack_Name);
2320 if Ekind (Pack) = E_Package then
2322 if In_Open_Scopes (Pack) then
2325 elsif not Redundant_Use (Pack_Name) then
2326 Set_In_Use (Pack, False);
2327 Id := First_Entity (Pack);
2329 while Present (Id) loop
2331 -- Preserve use-visibility of operators that are primitive
2332 -- operators of a type that is use_visible through an active
2335 if Nkind (Id) = N_Defining_Operator_Symbol
2337 (Is_Primitive_Operator (Id, First_Formal (Id))
2339 (Present (Next_Formal (First_Formal (Id)))
2341 Is_Primitive_Operator
2342 (Id, Next_Formal (First_Formal (Id)))))
2347 Set_Is_Potentially_Use_Visible (Id, False);
2350 if Is_Private_Type (Id)
2351 and then Present (Full_View (Id))
2353 Set_Is_Potentially_Use_Visible (Full_View (Id), False);
2359 if Present (Renamed_Object (Pack)) then
2360 Set_In_Use (Renamed_Object (Pack), False);
2363 if Chars (Pack) = Name_System
2364 and then Scope (Pack) = Standard_Standard
2365 and then Present_System_Aux
2367 Id := First_Entity (System_Aux_Id);
2369 while Present (Id) loop
2370 Set_Is_Potentially_Use_Visible (Id, False);
2372 if Is_Private_Type (Id)
2373 and then Present (Full_View (Id))
2375 Set_Is_Potentially_Use_Visible (Full_View (Id), False);
2381 Set_In_Use (System_Aux_Id, False);
2385 Set_Redundant_Use (Pack_Name, False);
2393 if Present (Hidden_By_Use_Clause (N)) then
2394 Elmt := First_Elmt (Hidden_By_Use_Clause (N));
2396 while Present (Elmt) loop
2397 Set_Is_Immediately_Visible (Node (Elmt));
2401 Set_Hidden_By_Use_Clause (N, No_Elist);
2403 end End_Use_Package;
2409 procedure End_Use_Type (N : Node_Id) is
2416 Id := First (Subtype_Marks (N));
2418 while Present (Id) loop
2420 -- A call to rtsfind may occur while analyzing a use_type clause,
2421 -- in which case the type marks are not resolved yet, and there is
2422 -- nothing to remove.
2424 if not Is_Entity_Name (Id)
2425 or else No (Entity (Id))
2432 if T = Any_Type then
2435 -- Note that the use_Type clause may mention a subtype of the
2436 -- type whose primitive operations have been made visible. Here
2437 -- as elsewhere, it is the base type that matters for visibility.
2439 elsif In_Open_Scopes (Scope (Base_Type (T))) then
2442 elsif not Redundant_Use (Id) then
2443 Set_In_Use (T, False);
2444 Set_In_Use (Base_Type (T), False);
2445 Op_List := Collect_Primitive_Operations (T);
2446 Elmt := First_Elmt (Op_List);
2448 while Present (Elmt) loop
2450 if Nkind (Node (Elmt)) = N_Defining_Operator_Symbol then
2451 Set_Is_Potentially_Use_Visible (Node (Elmt), False);
2463 ----------------------
2464 -- Find_Direct_Name --
2465 ----------------------
2467 procedure Find_Direct_Name (N : Node_Id) is
2472 Inst : Entity_Id := Empty;
2473 -- Enclosing instance, if any
2475 Homonyms : Entity_Id;
2476 -- Saves start of homonym chain
2478 Nvis_Entity : Boolean;
2479 -- Set True to indicate that at there is at least one entity on the
2480 -- homonym chain which, while not visible, is visible enough from the
2481 -- user point of view to warrant an error message of "not visible"
2482 -- rather than undefined.
2484 Nvis_Is_Private_Subprg : Boolean := False;
2485 -- Ada 2005 (AI-262): Set True to indicate that a form of Beaujolais
2486 -- effect concerning library subprograms has been detected. Used to
2487 -- generate the precise error message.
2489 function From_Actual_Package (E : Entity_Id) return Boolean;
2490 -- Returns true if the entity is declared in a package that is
2491 -- an actual for a formal package of the current instance. Such an
2492 -- entity requires special handling because it may be use-visible
2493 -- but hides directly visible entities defined outside the instance.
2495 function Known_But_Invisible (E : Entity_Id) return Boolean;
2496 -- This function determines whether the entity E (which is not
2497 -- visible) can reasonably be considered to be known to the writer
2498 -- of the reference. This is a heuristic test, used only for the
2499 -- purposes of figuring out whether we prefer to complain that an
2500 -- entity is undefined or invisible (and identify the declaration
2501 -- of the invisible entity in the latter case). The point here is
2502 -- that we don't want to complain that something is invisible and
2503 -- then point to something entirely mysterious to the writer.
2505 procedure Nvis_Messages;
2506 -- Called if there are no visible entries for N, but there is at least
2507 -- one non-directly visible, or hidden declaration. This procedure
2508 -- outputs an appropriate set of error messages.
2510 procedure Undefined (Nvis : Boolean);
2511 -- This function is called if the current node has no corresponding
2512 -- visible entity or entities. The value set in Msg indicates whether
2513 -- an error message was generated (multiple error messages for the
2514 -- same variable are generally suppressed, see body for details).
2515 -- Msg is True if an error message was generated, False if not. This
2516 -- value is used by the caller to determine whether or not to output
2517 -- additional messages where appropriate. The parameter is set False
2518 -- to get the message "X is undefined", and True to get the message
2519 -- "X is not visible".
2521 -------------------------
2522 -- From_Actual_Package --
2523 -------------------------
2525 function From_Actual_Package (E : Entity_Id) return Boolean is
2526 Scop : constant Entity_Id := Scope (E);
2530 if not In_Instance then
2533 Inst := Current_Scope;
2535 while Present (Inst)
2536 and then Ekind (Inst) /= E_Package
2537 and then not Is_Generic_Instance (Inst)
2539 Inst := Scope (Inst);
2546 Act := First_Entity (Inst);
2548 while Present (Act) loop
2549 if Ekind (Act) = E_Package then
2551 -- Check for end of actuals list
2553 if Renamed_Object (Act) = Inst then
2556 elsif Present (Associated_Formal_Package (Act))
2557 and then Renamed_Object (Act) = Scop
2559 -- Entity comes from (instance of) formal package
2574 end From_Actual_Package;
2576 -------------------------
2577 -- Known_But_Invisible --
2578 -------------------------
2580 function Known_But_Invisible (E : Entity_Id) return Boolean is
2581 Fname : File_Name_Type;
2584 -- Entities in Standard are always considered to be known
2586 if Sloc (E) <= Standard_Location then
2589 -- An entity that does not come from source is always considered
2590 -- to be unknown, since it is an artifact of code expansion.
2592 elsif not Comes_From_Source (E) then
2595 -- In gnat internal mode, we consider all entities known
2597 elsif GNAT_Mode then
2601 -- Here we have an entity that is not from package Standard, and
2602 -- which comes from Source. See if it comes from an internal file.
2604 Fname := Unit_File_Name (Get_Source_Unit (E));
2606 -- Case of from internal file
2608 if Is_Internal_File_Name (Fname) then
2610 -- Private part entities in internal files are never considered
2611 -- to be known to the writer of normal application code.
2613 if Is_Hidden (E) then
2617 -- Entities from System packages other than System and
2618 -- System.Storage_Elements are not considered to be known.
2619 -- System.Auxxxx files are also considered known to the user.
2621 -- Should refine this at some point to generally distinguish
2622 -- between known and unknown internal files ???
2624 Get_Name_String (Fname);
2629 Name_Buffer (1 .. 2) /= "s-"
2631 Name_Buffer (3 .. 8) = "stoele"
2633 Name_Buffer (3 .. 5) = "aux";
2635 -- If not an internal file, then entity is definitely known,
2636 -- even if it is in a private part (the message generated will
2637 -- note that it is in a private part)
2642 end Known_But_Invisible;
2648 procedure Nvis_Messages is
2649 Comp_Unit : Node_Id;
2651 Hidden : Boolean := False;
2655 -- Ada 2005 (AI-262): Generate a precise error concerning the
2656 -- Beaujolais effect that was previously detected
2658 if Nvis_Is_Private_Subprg then
2660 pragma Assert (Nkind (E2) = N_Defining_Identifier
2661 and then Ekind (E2) = E_Function
2662 and then Scope (E2) = Standard_Standard
2663 and then Has_Private_With (E2));
2665 -- Find the sloc corresponding to the private with'ed unit
2667 Comp_Unit := Cunit (Current_Sem_Unit);
2668 Item := First (Context_Items (Comp_Unit));
2669 Error_Msg_Sloc := No_Location;
2671 while Present (Item) loop
2672 if Nkind (Item) = N_With_Clause
2673 and then Private_Present (Item)
2674 and then Entity (Name (Item)) = E2
2676 Error_Msg_Sloc := Sloc (Item);
2683 pragma Assert (Error_Msg_Sloc /= No_Location);
2685 Error_Msg_N ("(Ada 2005): hidden by private with clause #", N);
2689 Undefined (Nvis => True);
2693 -- First loop does hidden declarations
2696 while Present (Ent) loop
2697 if Is_Potentially_Use_Visible (Ent) then
2700 Error_Msg_N ("multiple use clauses cause hiding!", N);
2704 Error_Msg_Sloc := Sloc (Ent);
2705 Error_Msg_N ("hidden declaration#!", N);
2708 Ent := Homonym (Ent);
2711 -- If we found hidden declarations, then that's enough, don't
2712 -- bother looking for non-visible declarations as well.
2718 -- Second loop does non-directly visible declarations
2721 while Present (Ent) loop
2722 if not Is_Potentially_Use_Visible (Ent) then
2724 -- Do not bother the user with unknown entities
2726 if not Known_But_Invisible (Ent) then
2730 Error_Msg_Sloc := Sloc (Ent);
2732 -- Output message noting that there is a non-visible
2733 -- declaration, distinguishing the private part case.
2735 if Is_Hidden (Ent) then
2736 Error_Msg_N ("non-visible (private) declaration#!", N);
2738 Error_Msg_N ("non-visible declaration#!", N);
2740 if Is_Compilation_Unit (Ent)
2742 Nkind (Parent (Parent (N))) = N_Use_Package_Clause
2745 ("\possibly missing with_clause for&", N, Ent);
2749 -- Set entity and its containing package as referenced. We
2750 -- can't be sure of this, but this seems a better choice
2751 -- to avoid unused entity messages.
2753 if Comes_From_Source (Ent) then
2754 Set_Referenced (Ent);
2755 Set_Referenced (Cunit_Entity (Get_Source_Unit (Ent)));
2760 Ent := Homonym (Ent);
2770 procedure Undefined (Nvis : Boolean) is
2771 Emsg : Error_Msg_Id;
2774 -- We should never find an undefined internal name. If we do, then
2775 -- see if we have previous errors. If so, ignore on the grounds that
2776 -- it is probably a cascaded message (e.g. a block label from a badly
2777 -- formed block). If no previous errors, then we have a real internal
2778 -- error of some kind so raise an exception.
2780 if Is_Internal_Name (Chars (N)) then
2781 if Total_Errors_Detected /= 0 then
2784 raise Program_Error;
2788 -- A very specialized error check, if the undefined variable is
2789 -- a case tag, and the case type is an enumeration type, check
2790 -- for a possible misspelling, and if so, modify the identifier
2792 -- Named aggregate should also be handled similarly ???
2794 if Nkind (N) = N_Identifier
2795 and then Nkind (Parent (N)) = N_Case_Statement_Alternative
2797 Get_Name_String (Chars (N));
2800 Case_Str : constant String := Name_Buffer (1 .. Name_Len);
2801 Case_Stm : constant Node_Id := Parent (Parent (N));
2802 Case_Typ : constant Entity_Id := Etype (Expression (Case_Stm));
2807 if Is_Enumeration_Type (Case_Typ)
2808 and then Case_Typ /= Standard_Character
2809 and then Case_Typ /= Standard_Wide_Character
2810 and then Case_Typ /= Standard_Wide_Wide_Character
2812 Lit := First_Literal (Case_Typ);
2813 Get_Name_String (Chars (Lit));
2815 if Chars (Lit) /= Chars (N)
2816 and then Is_Bad_Spelling_Of
2817 (Case_Str, Name_Buffer (1 .. Name_Len))
2819 Error_Msg_Node_2 := Lit;
2821 ("& is undefined, assume misspelling of &", N);
2822 Rewrite (N, New_Occurrence_Of (Lit, Sloc (N)));
2826 Lit := Next_Literal (Lit);
2831 -- Normal processing
2833 Set_Entity (N, Any_Id);
2834 Set_Etype (N, Any_Type);
2836 -- We use the table Urefs to keep track of entities for which we
2837 -- have issued errors for undefined references. Multiple errors
2838 -- for a single name are normally suppressed, however we modify
2839 -- the error message to alert the programmer to this effect.
2841 for J in Urefs.First .. Urefs.Last loop
2842 if Chars (N) = Chars (Urefs.Table (J).Node) then
2843 if Urefs.Table (J).Err /= No_Error_Msg
2844 and then Sloc (N) /= Urefs.Table (J).Loc
2846 Error_Msg_Node_1 := Urefs.Table (J).Node;
2848 if Urefs.Table (J).Nvis then
2849 Change_Error_Text (Urefs.Table (J).Err,
2850 "& is not visible (more references follow)");
2852 Change_Error_Text (Urefs.Table (J).Err,
2853 "& is undefined (more references follow)");
2856 Urefs.Table (J).Err := No_Error_Msg;
2859 -- Although we will set Msg False, and thus suppress the
2860 -- message, we also set Error_Posted True, to avoid any
2861 -- cascaded messages resulting from the undefined reference.
2864 Set_Error_Posted (N, True);
2869 -- If entry not found, this is first undefined occurrence
2872 Error_Msg_N ("& is not visible!", N);
2876 Error_Msg_N ("& is undefined!", N);
2879 -- A very bizarre special check, if the undefined identifier
2880 -- is put or put_line, then add a special error message (since
2881 -- this is a very common error for beginners to make).
2883 if Chars (N) = Name_Put or else Chars (N) = Name_Put_Line then
2884 Error_Msg_N ("\possible missing with of 'Text_'I'O!", N);
2887 -- Now check for possible misspellings
2889 Get_Name_String (Chars (N));
2893 Ematch : Entity_Id := Empty;
2895 Last_Name_Id : constant Name_Id :=
2896 Name_Id (Nat (First_Name_Id) +
2897 Name_Entries_Count - 1);
2899 S : constant String (1 .. Name_Len) :=
2900 Name_Buffer (1 .. Name_Len);
2903 for N in First_Name_Id .. Last_Name_Id loop
2904 E := Get_Name_Entity_Id (N);
2907 and then (Is_Immediately_Visible (E)
2909 Is_Potentially_Use_Visible (E))
2911 Get_Name_String (N);
2913 if Is_Bad_Spelling_Of
2914 (Name_Buffer (1 .. Name_Len), S)
2922 if Present (Ematch) then
2923 Error_Msg_NE ("\possible misspelling of&", N, Ematch);
2928 -- Make entry in undefined references table unless the full
2929 -- errors switch is set, in which case by refraining from
2930 -- generating the table entry, we guarantee that we get an
2931 -- error message for every undefined reference.
2933 if not All_Errors_Mode then
2934 Urefs.Increment_Last;
2935 Urefs.Table (Urefs.Last).Node := N;
2936 Urefs.Table (Urefs.Last).Err := Emsg;
2937 Urefs.Table (Urefs.Last).Nvis := Nvis;
2938 Urefs.Table (Urefs.Last).Loc := Sloc (N);
2944 -- Start of processing for Find_Direct_Name
2947 -- If the entity pointer is already set, this is an internal node, or
2948 -- a node that is analyzed more than once, after a tree modification.
2949 -- In such a case there is no resolution to perform, just set the type.
2951 if Present (Entity (N)) then
2952 if Is_Type (Entity (N)) then
2953 Set_Etype (N, Entity (N));
2957 Entyp : constant Entity_Id := Etype (Entity (N));
2960 -- One special case here. If the Etype field is already set,
2961 -- and references the packed array type corresponding to the
2962 -- etype of the referenced entity, then leave it alone. This
2963 -- happens for trees generated from Exp_Pakd, where expressions
2964 -- can be deliberately "mis-typed" to the packed array type.
2966 if Is_Array_Type (Entyp)
2967 and then Is_Packed (Entyp)
2968 and then Present (Etype (N))
2969 and then Etype (N) = Packed_Array_Type (Entyp)
2973 -- If not that special case, then just reset the Etype
2976 Set_Etype (N, Etype (Entity (N)));
2984 -- Here if Entity pointer was not set, we need full visibility analysis
2985 -- First we generate debugging output if the debug E flag is set.
2987 if Debug_Flag_E then
2988 Write_Str ("Looking for ");
2989 Write_Name (Chars (N));
2993 Homonyms := Current_Entity (N);
2994 Nvis_Entity := False;
2997 while Present (E) loop
2999 -- If entity is immediately visible or potentially use
3000 -- visible, then process the entity and we are done.
3002 if Is_Immediately_Visible (E) then
3003 goto Immediately_Visible_Entity;
3005 elsif Is_Potentially_Use_Visible (E) then
3006 goto Potentially_Use_Visible_Entity;
3008 -- Note if a known but invisible entity encountered
3010 elsif Known_But_Invisible (E) then
3011 Nvis_Entity := True;
3014 -- Move to next entity in chain and continue search
3019 -- If no entries on homonym chain that were potentially visible,
3020 -- and no entities reasonably considered as non-visible, then
3021 -- we have a plain undefined reference, with no additional
3022 -- explanation required!
3024 if not Nvis_Entity then
3025 Undefined (Nvis => False);
3027 -- Otherwise there is at least one entry on the homonym chain that
3028 -- is reasonably considered as being known and non-visible.
3036 -- Processing for a potentially use visible entry found. We must search
3037 -- the rest of the homonym chain for two reasons. First, if there is a
3038 -- directly visible entry, then none of the potentially use-visible
3039 -- entities are directly visible (RM 8.4(10)). Second, we need to check
3040 -- for the case of multiple potentially use-visible entries hiding one
3041 -- another and as a result being non-directly visible (RM 8.4(11)).
3043 <<Potentially_Use_Visible_Entity>> declare
3044 Only_One_Visible : Boolean := True;
3045 All_Overloadable : Boolean := Is_Overloadable (E);
3050 while Present (E2) loop
3051 if Is_Immediately_Visible (E2) then
3053 -- If the use-visible entity comes from the actual for a
3054 -- formal package, it hides a directly visible entity from
3055 -- outside the instance.
3057 if From_Actual_Package (E)
3058 and then Scope_Depth (E2) < Scope_Depth (Inst)
3063 goto Immediately_Visible_Entity;
3066 elsif Is_Potentially_Use_Visible (E2) then
3067 Only_One_Visible := False;
3068 All_Overloadable := All_Overloadable and Is_Overloadable (E2);
3070 -- Ada 2005 (AI-262): Protect against a form of Beujolais effect
3071 -- that can occurr in private_with clauses. Example:
3074 -- private with B; package A is
3075 -- package C is function B return Integer;
3077 -- V1 : Integer := B;
3078 -- private function B return Integer;
3079 -- V2 : Integer := B;
3082 -- V1 resolves to A.B, but V2 resolves to library unit B
3084 elsif Ekind (E2) = E_Function
3085 and then Scope (E2) = Standard_Standard
3086 and then Has_Private_With (E2)
3088 Only_One_Visible := False;
3089 All_Overloadable := False;
3090 Nvis_Is_Private_Subprg := True;
3097 -- On falling through this loop, we have checked that there are no
3098 -- immediately visible entities. Only_One_Visible is set if exactly
3099 -- one potentially use visible entity exists. All_Overloadable is
3100 -- set if all the potentially use visible entities are overloadable.
3101 -- The condition for legality is that either there is one potentially
3102 -- use visible entity, or if there is more than one, then all of them
3103 -- are overloadable.
3105 if Only_One_Visible or All_Overloadable then
3108 -- If there is more than one potentially use-visible entity and at
3109 -- least one of them non-overloadable, we have an error (RM 8.4(11).
3110 -- Note that E points to the first such entity on the homonym list.
3111 -- Special case: if one of the entities is declared in an actual
3112 -- package, it was visible in the generic, and takes precedence over
3113 -- other entities that are potentially use-visible. Same if it is
3114 -- declared in a local instantiation of the current instance.
3118 Inst := Current_Scope;
3120 -- Find current instance
3122 while Present (Inst)
3123 and then Inst /= Standard_Standard
3125 if Is_Generic_Instance (Inst) then
3129 Inst := Scope (Inst);
3134 while Present (E2) loop
3135 if From_Actual_Package (E2)
3137 (Is_Generic_Instance (Scope (E2))
3138 and then Scope_Depth (Scope (E2)) > Scope_Depth (Inst))
3151 Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
3153 -- A use-clause in the body of a system file creates a
3154 -- conflict with some entity in a user scope, while rtsfind
3155 -- is active. Keep only the entity that comes from another
3159 while Present (E2) loop
3160 if Is_Predefined_File_Name
3161 (Unit_File_Name (Get_Source_Unit (Sloc (E2))))
3170 -- Entity must exist because predefined unit is correct.
3172 raise Program_Error;
3181 -- Come here with E set to the first immediately visible entity on
3182 -- the homonym chain. This is the one we want unless there is another
3183 -- immediately visible entity further on in the chain for a more
3184 -- inner scope (RM 8.3(8)).
3186 <<Immediately_Visible_Entity>> declare
3191 -- Find scope level of initial entity. When compiling through
3192 -- Rtsfind, the previous context is not completely invisible, and
3193 -- an outer entity may appear on the chain, whose scope is below
3194 -- the entry for Standard that delimits the current scope stack.
3195 -- Indicate that the level for this spurious entry is outside of
3196 -- the current scope stack.
3198 Level := Scope_Stack.Last;
3200 Scop := Scope_Stack.Table (Level).Entity;
3201 exit when Scop = Scope (E);
3203 exit when Scop = Standard_Standard;
3206 -- Now search remainder of homonym chain for more inner entry
3207 -- If the entity is Standard itself, it has no scope, and we
3208 -- compare it with the stack entry directly.
3211 while Present (E2) loop
3212 if Is_Immediately_Visible (E2) then
3213 for J in Level + 1 .. Scope_Stack.Last loop
3214 if Scope_Stack.Table (J).Entity = Scope (E2)
3215 or else Scope_Stack.Table (J).Entity = E2
3227 -- At the end of that loop, E is the innermost immediately
3228 -- visible entity, so we are all set.
3231 -- Come here with entity found, and stored in E
3235 if Comes_From_Source (N)
3236 and then Is_Remote_Access_To_Subprogram_Type (E)
3237 and then Expander_Active
3240 New_Occurrence_Of (Equivalent_Type (E), Sloc (N)));
3245 -- Why no Style_Check here???
3250 Set_Etype (N, Get_Full_View (Etype (E)));
3253 if Debug_Flag_E then
3254 Write_Str (" found ");
3255 Write_Entity_Info (E, " ");
3258 -- If the Ekind of the entity is Void, it means that all homonyms
3259 -- are hidden from all visibility (RM 8.3(5,14-20)). However, this
3260 -- test is skipped if the current scope is a record and the name is
3261 -- a pragma argument expression (case of Atomic and Volatile pragmas
3262 -- and possibly other similar pragmas added later, which are allowed
3263 -- to reference components in the current record).
3265 if Ekind (E) = E_Void
3267 (not Is_Record_Type (Current_Scope)
3268 or else Nkind (Parent (N)) /= N_Pragma_Argument_Association)
3270 Premature_Usage (N);
3272 -- If the entity is overloadable, collect all interpretations
3273 -- of the name for subsequent overload resolution. We optimize
3274 -- a bit here to do this only if we have an overloadable entity
3275 -- that is not on its own on the homonym chain.
3277 elsif Is_Overloadable (E)
3278 and then (Present (Homonym (E)) or else Current_Entity (N) /= E)
3280 Collect_Interps (N);
3282 -- If no homonyms were visible, the entity is unambiguous
3284 if not Is_Overloaded (N) then
3285 Generate_Reference (E, N);
3288 -- Case of non-overloadable entity, set the entity providing that
3289 -- we do not have the case of a discriminant reference within a
3290 -- default expression. Such references are replaced with the
3291 -- corresponding discriminal, which is the formal corresponding to
3292 -- to the discriminant in the initialization procedure.
3295 -- Entity is unambiguous, indicate that it is referenced here
3296 -- One slightly odd case is that we do not want to set the
3297 -- Referenced flag if the entity is a label, and the identifier
3298 -- is the label in the source, since this is not a reference
3299 -- from the point of view of the user
3301 if Nkind (Parent (N)) = N_Label then
3303 R : constant Boolean := Referenced (E);
3306 Generate_Reference (E, N);
3307 Set_Referenced (E, R);
3310 -- Normal case, not a label. Generate reference
3313 Generate_Reference (E, N);
3316 -- Set Entity, with style check if need be. If this is a
3317 -- discriminant reference, it must be replaced by the
3318 -- corresponding discriminal, that is to say the parameter
3319 -- of the initialization procedure that corresponds to the
3320 -- discriminant. If this replacement is being performed, there
3321 -- is no style check to perform.
3323 -- This replacement must not be done if we are currently
3324 -- processing a generic spec or body, because the discriminal
3325 -- has not been not generated in this case.
3327 if not In_Default_Expression
3328 or else Ekind (E) /= E_Discriminant
3329 or else Inside_A_Generic
3331 Set_Entity_With_Style_Check (N, E);
3333 -- The replacement is not done either for a task discriminant that
3334 -- appears in a default expression of an entry parameter. See
3335 -- Expand_Discriminant in exp_ch2 for details on their handling.
3337 elsif Is_Concurrent_Type (Scope (E)) then
3339 P : Node_Id := Parent (N);
3343 and then Nkind (P) /= N_Parameter_Specification
3344 and then Nkind (P) /= N_Component_Declaration
3350 and then Nkind (P) = N_Parameter_Specification
3354 Set_Entity (N, Discriminal (E));
3358 -- Otherwise, this is a discriminant in a context in which
3359 -- it is a reference to the corresponding parameter of the
3360 -- init proc for the enclosing type.
3363 Set_Entity (N, Discriminal (E));
3367 end Find_Direct_Name;
3369 ------------------------
3370 -- Find_Expanded_Name --
3371 ------------------------
3373 -- This routine searches the homonym chain of the entity until it finds
3374 -- an entity declared in the scope denoted by the prefix. If the entity
3375 -- is private, it may nevertheless be immediately visible, if we are in
3376 -- the scope of its declaration.
3378 procedure Find_Expanded_Name (N : Node_Id) is
3379 Selector : constant Node_Id := Selector_Name (N);
3380 Candidate : Entity_Id := Empty;
3386 P_Name := Entity (Prefix (N));
3389 -- If the prefix is a renamed package, look for the entity
3390 -- in the original package.
3392 if Ekind (P_Name) = E_Package
3393 and then Present (Renamed_Object (P_Name))
3395 P_Name := Renamed_Object (P_Name);
3397 -- Rewrite node with entity field pointing to renamed object
3399 Rewrite (Prefix (N), New_Copy (Prefix (N)));
3400 Set_Entity (Prefix (N), P_Name);
3402 -- If the prefix is an object of a concurrent type, look for
3403 -- the entity in the associated task or protected type.
3405 elsif Is_Concurrent_Type (Etype (P_Name)) then
3406 P_Name := Etype (P_Name);
3409 Id := Current_Entity (Selector);
3411 while Present (Id) loop
3413 if Scope (Id) = P_Name then
3416 if Is_Child_Unit (Id) then
3417 exit when Is_Visible_Child_Unit (Id)
3418 or else Is_Immediately_Visible (Id);
3421 exit when not Is_Hidden (Id)
3422 or else Is_Immediately_Visible (Id);
3430 and then (Ekind (P_Name) = E_Procedure
3432 Ekind (P_Name) = E_Function)
3433 and then Is_Generic_Instance (P_Name)
3435 -- Expanded name denotes entity in (instance of) generic subprogram.
3436 -- The entity may be in the subprogram instance, or may denote one of
3437 -- the formals, which is declared in the enclosing wrapper package.
3439 P_Name := Scope (P_Name);
3441 Id := Current_Entity (Selector);
3442 while Present (Id) loop
3443 exit when Scope (Id) = P_Name;
3448 if No (Id) or else Chars (Id) /= Chars (Selector) then
3449 Set_Etype (N, Any_Type);
3451 -- If we are looking for an entity defined in System, try to
3452 -- find it in the child package that may have been provided as
3453 -- an extension to System. The Extend_System pragma will have
3454 -- supplied the name of the extension, which may have to be loaded.
3456 if Chars (P_Name) = Name_System
3457 and then Scope (P_Name) = Standard_Standard
3458 and then Present (System_Extend_Unit)
3459 and then Present_System_Aux (N)
3461 Set_Entity (Prefix (N), System_Aux_Id);
3462 Find_Expanded_Name (N);
3465 elsif Nkind (Selector) = N_Operator_Symbol
3466 and then Has_Implicit_Operator (N)
3468 -- There is an implicit instance of the predefined operator in
3469 -- the given scope. The operator entity is defined in Standard.
3470 -- Has_Implicit_Operator makes the node into an Expanded_Name.
3474 elsif Nkind (Selector) = N_Character_Literal
3475 and then Has_Implicit_Character_Literal (N)
3477 -- If there is no literal defined in the scope denoted by the
3478 -- prefix, the literal may belong to (a type derived from)
3479 -- Standard_Character, for which we have no explicit literals.
3484 -- If the prefix is a single concurrent object, use its
3485 -- name in the error message, rather than that of the
3488 if Is_Concurrent_Type (P_Name)
3489 and then Is_Internal_Name (Chars (P_Name))
3491 Error_Msg_Node_2 := Entity (Prefix (N));
3493 Error_Msg_Node_2 := P_Name;
3496 if P_Name = System_Aux_Id then
3497 P_Name := Scope (P_Name);
3498 Set_Entity (Prefix (N), P_Name);
3501 if Present (Candidate) then
3503 if Is_Child_Unit (Candidate) then
3505 ("missing with_clause for child unit &", Selector);
3507 Error_Msg_NE ("& is not a visible entity of&", N, Selector);
3511 -- Within the instantiation of a child unit, the prefix may
3512 -- denote the parent instance, but the selector has the
3513 -- name of the original child. Find whether we are within
3514 -- the corresponding instance, and get the proper entity, which
3515 -- can only be an enclosing scope.
3518 and then In_Open_Scopes (P_Name)
3519 and then Is_Generic_Instance (P_Name)
3522 S : Entity_Id := Current_Scope;
3526 for J in reverse 0 .. Scope_Stack.Last loop
3527 S := Scope_Stack.Table (J).Entity;
3529 exit when S = Standard_Standard;
3531 if Ekind (S) = E_Function
3532 or else Ekind (S) = E_Package
3533 or else Ekind (S) = E_Procedure
3535 P := Generic_Parent (Specification
3536 (Unit_Declaration_Node (S)));
3539 and then Chars (Scope (P)) = Chars (O_Name)
3540 and then Chars (P) = Chars (Selector)
3551 if Chars (P_Name) = Name_Ada
3552 and then Scope (P_Name) = Standard_Standard
3554 Error_Msg_Node_2 := Selector;
3555 Error_Msg_NE ("missing with for `&.&`", N, P_Name);
3557 -- If this is a selection from a dummy package, then
3558 -- suppress the error message, of course the entity
3559 -- is missing if the package is missing!
3561 elsif Sloc (Error_Msg_Node_2) = No_Location then
3564 -- Here we have the case of an undefined component
3568 Error_Msg_NE ("& not declared in&", N, Selector);
3570 -- Check for misspelling of some entity in prefix
3572 Id := First_Entity (P_Name);
3573 Get_Name_String (Chars (Selector));
3576 S : constant String (1 .. Name_Len) :=
3577 Name_Buffer (1 .. Name_Len);
3579 while Present (Id) loop
3580 Get_Name_String (Chars (Id));
3581 if Is_Bad_Spelling_Of
3582 (Name_Buffer (1 .. Name_Len), S)
3583 and then not Is_Internal_Name (Chars (Id))
3586 ("possible misspelling of&", Selector, Id);
3594 -- Specialize the message if this may be an instantiation
3595 -- of a child unit that was not mentioned in the context.
3597 if Nkind (Parent (N)) = N_Package_Instantiation
3598 and then Is_Generic_Instance (Entity (Prefix (N)))
3599 and then Is_Compilation_Unit
3600 (Generic_Parent (Parent (Entity (Prefix (N)))))
3603 ("\possible missing with clause on child unit&",
3614 if Comes_From_Source (N)
3615 and then Is_Remote_Access_To_Subprogram_Type (Id)
3617 Id := Equivalent_Type (Id);
3618 Set_Chars (Selector, Chars (Id));
3621 -- Ada 2005 (AI-50217): Check usage of entities in limited withed units
3623 if Ekind (P_Name) = E_Package
3624 and then From_With_Type (P_Name)
3626 if From_With_Type (Id)
3627 or else Is_Type (Id)
3628 or else Ekind (Id) = E_Package
3633 ("limited withed package can only be used to access "
3634 & " incomplete types",
3639 if Is_Task_Type (P_Name)
3640 and then ((Ekind (Id) = E_Entry
3641 and then Nkind (Parent (N)) /= N_Attribute_Reference)
3643 (Ekind (Id) = E_Entry_Family
3645 Nkind (Parent (Parent (N))) /= N_Attribute_Reference))
3647 -- It is an entry call after all, either to the current task
3648 -- (which will deadlock) or to an enclosing task.
3650 Analyze_Selected_Component (N);
3654 Change_Selected_Component_To_Expanded_Name (N);
3656 -- Do style check and generate reference, but skip both steps if this
3657 -- entity has homonyms, since we may not have the right homonym set
3658 -- yet. The proper homonym will be set during the resolve phase.
3660 if Has_Homonym (Id) then
3663 Set_Entity_With_Style_Check (N, Id);
3664 Generate_Reference (Id, N);
3667 if Is_Type (Id) then
3670 Set_Etype (N, Get_Full_View (Etype (Id)));
3673 -- If the Ekind of the entity is Void, it means that all homonyms
3674 -- are hidden from all visibility (RM 8.3(5,14-20)).
3676 if Ekind (Id) = E_Void then
3677 Premature_Usage (N);
3679 elsif Is_Overloadable (Id)
3680 and then Present (Homonym (Id))
3683 H : Entity_Id := Homonym (Id);
3686 while Present (H) loop
3687 if Scope (H) = Scope (Id)
3690 or else Is_Immediately_Visible (H))
3692 Collect_Interps (N);
3699 -- If an extension of System is present, collect possible
3700 -- explicit overloadings declared in the extension.
3702 if Chars (P_Name) = Name_System
3703 and then Scope (P_Name) = Standard_Standard
3704 and then Present (System_Extend_Unit)
3705 and then Present_System_Aux (N)
3707 H := Current_Entity (Id);
3709 while Present (H) loop
3710 if Scope (H) = System_Aux_Id then
3711 Add_One_Interp (N, H, Etype (H));
3720 if Nkind (Selector_Name (N)) = N_Operator_Symbol
3721 and then Scope (Id) /= Standard_Standard
3723 -- In addition to user-defined operators in the given scope,
3724 -- there may be an implicit instance of the predefined
3725 -- operator. The operator (defined in Standard) is found
3726 -- in Has_Implicit_Operator, and added to the interpretations.
3727 -- Procedure Add_One_Interp will determine which hides which.
3729 if Has_Implicit_Operator (N) then
3733 end Find_Expanded_Name;
3735 -------------------------
3736 -- Find_Renamed_Entity --
3737 -------------------------
3739 function Find_Renamed_Entity
3743 Is_Actual : Boolean := False) return Entity_Id
3746 I1 : Interp_Index := 0; -- Suppress junk warnings
3752 function Enclosing_Instance return Entity_Id;
3753 -- If the renaming determines the entity for the default of a formal
3754 -- subprogram nested within another instance, choose the innermost
3755 -- candidate. This is because if the formal has a box, and we are within
3756 -- an enclosing instance where some candidate interpretations are local
3757 -- to this enclosing instance, we know that the default was properly
3758 -- resolved when analyzing the generic, so we prefer the local
3759 -- candidates to those that are external. This is not always the case
3760 -- but is a reasonable heuristic on the use of nested generics.
3761 -- The proper solution requires a full renaming model.
3763 function Within (Inner, Outer : Entity_Id) return Boolean;
3764 -- Determine whether a candidate subprogram is defined within
3765 -- the enclosing instance. If yes, it has precedence over outer
3768 function Is_Visible_Operation (Op : Entity_Id) return Boolean;
3769 -- If the renamed entity is an implicit operator, check whether it is
3770 -- visible because its operand type is properly visible. This
3771 -- check applies to explicit renamed entities that appear in the
3772 -- source in a renaming declaration or a formal subprogram instance,
3773 -- but not to default generic actuals with a name.
3775 ------------------------
3776 -- Enclosing_Instance --
3777 ------------------------
3779 function Enclosing_Instance return Entity_Id is
3783 if not Is_Generic_Instance (Current_Scope)
3784 and then not Is_Actual
3789 S := Scope (Current_Scope);
3791 while S /= Standard_Standard loop
3793 if Is_Generic_Instance (S) then
3801 end Enclosing_Instance;
3803 --------------------------
3804 -- Is_Visible_Operation --
3805 --------------------------
3807 function Is_Visible_Operation (Op : Entity_Id) return Boolean is
3813 if Ekind (Op) /= E_Operator
3814 or else Scope (Op) /= Standard_Standard
3815 or else (In_Instance
3818 or else Present (Enclosing_Instance)))
3823 -- For a fixed point type operator, check the resulting type,
3824 -- because it may be a mixed mode integer * fixed operation.
3826 if Present (Next_Formal (First_Formal (New_S)))
3827 and then Is_Fixed_Point_Type (Etype (New_S))
3829 Typ := Etype (New_S);
3831 Typ := Etype (First_Formal (New_S));
3834 Btyp := Base_Type (Typ);
3836 if Nkind (Nam) /= N_Expanded_Name then
3837 return (In_Open_Scopes (Scope (Btyp))
3838 or else Is_Potentially_Use_Visible (Btyp)
3839 or else In_Use (Btyp)
3840 or else In_Use (Scope (Btyp)));
3843 Scop := Entity (Prefix (Nam));
3845 if Ekind (Scop) = E_Package
3846 and then Present (Renamed_Object (Scop))
3848 Scop := Renamed_Object (Scop);
3851 -- Operator is visible if prefix of expanded name denotes
3852 -- scope of type, or else type type is defined in System_Aux
3853 -- and the prefix denotes System.
3855 return Scope (Btyp) = Scop
3856 or else (Scope (Btyp) = System_Aux_Id
3857 and then Scope (Scope (Btyp)) = Scop);
3860 end Is_Visible_Operation;
3866 function Within (Inner, Outer : Entity_Id) return Boolean is
3867 Sc : Entity_Id := Scope (Inner);
3870 while Sc /= Standard_Standard loop
3882 function Report_Overload return Entity_Id;
3883 -- List possible interpretations, and specialize message in the
3884 -- case of a generic actual.
3886 function Report_Overload return Entity_Id is
3890 ("ambiguous actual subprogram&, " &
3891 "possible interpretations: ", N, Nam);
3894 ("ambiguous subprogram, " &
3895 "possible interpretations: ", N);
3898 List_Interps (Nam, N);
3900 end Report_Overload;
3902 -- Start of processing for Find_Renamed_Entry
3906 Candidate_Renaming := Empty;
3908 if not Is_Overloaded (Nam) then
3909 if Entity_Matches_Spec (Entity (Nam), New_S)
3910 and then Is_Visible_Operation (Entity (Nam))
3912 Old_S := Entity (Nam);
3915 Present (First_Formal (Entity (Nam)))
3916 and then Present (First_Formal (New_S))
3917 and then (Base_Type (Etype (First_Formal (Entity (Nam))))
3918 = Base_Type (Etype (First_Formal (New_S))))
3920 Candidate_Renaming := Entity (Nam);
3924 Get_First_Interp (Nam, Ind, It);
3926 while Present (It.Nam) loop
3928 if Entity_Matches_Spec (It.Nam, New_S)
3929 and then Is_Visible_Operation (It.Nam)
3931 if Old_S /= Any_Id then
3933 -- Note: The call to Disambiguate only happens if a
3934 -- previous interpretation was found, in which case I1
3935 -- has received a value.
3937 It1 := Disambiguate (Nam, I1, Ind, Etype (Old_S));
3939 if It1 = No_Interp then
3941 Inst := Enclosing_Instance;
3943 if Present (Inst) then
3945 if Within (It.Nam, Inst) then
3948 elsif Within (Old_S, Inst) then
3952 return Report_Overload;
3956 return Report_Overload;
3970 Present (First_Formal (It.Nam))
3971 and then Present (First_Formal (New_S))
3972 and then (Base_Type (Etype (First_Formal (It.Nam)))
3973 = Base_Type (Etype (First_Formal (New_S))))
3975 Candidate_Renaming := It.Nam;
3978 Get_Next_Interp (Ind, It);
3981 Set_Entity (Nam, Old_S);
3982 Set_Is_Overloaded (Nam, False);
3986 end Find_Renamed_Entity;
3988 -----------------------------
3989 -- Find_Selected_Component --
3990 -----------------------------
3992 procedure Find_Selected_Component (N : Node_Id) is
3993 P : constant Node_Id := Prefix (N);
3996 -- Entity denoted by prefix
4006 if Nkind (P) = N_Error then
4009 -- If the selector already has an entity, the node has been
4010 -- constructed in the course of expansion, and is known to be
4011 -- valid. Do not verify that it is defined for the type (it may
4012 -- be a private component used in the expansion of record equality).
4014 elsif Present (Entity (Selector_Name (N))) then
4017 or else Etype (N) = Any_Type
4020 Sel_Name : constant Node_Id := Selector_Name (N);
4021 Selector : constant Entity_Id := Entity (Sel_Name);
4025 Set_Etype (Sel_Name, Etype (Selector));
4027 if not Is_Entity_Name (P) then
4031 -- Build an actual subtype except for the first parameter
4032 -- of an init proc, where this actual subtype is by
4033 -- definition incorrect, since the object is uninitialized
4034 -- (and does not even have defined discriminants etc.)
4036 if Is_Entity_Name (P)
4037 and then Ekind (Entity (P)) = E_Function
4039 Nam := New_Copy (P);
4041 if Is_Overloaded (P) then
4042 Save_Interps (P, Nam);
4046 Make_Function_Call (Sloc (P), Name => Nam));
4048 Analyze_Selected_Component (N);
4051 elsif Ekind (Selector) = E_Component
4052 and then (not Is_Entity_Name (P)
4053 or else Chars (Entity (P)) /= Name_uInit)
4056 Build_Actual_Subtype_Of_Component (
4057 Etype (Selector), N);
4062 if No (C_Etype) then
4063 C_Etype := Etype (Selector);
4065 Insert_Action (N, C_Etype);
4066 C_Etype := Defining_Identifier (C_Etype);
4069 Set_Etype (N, C_Etype);
4072 -- If this is the name of an entry or protected operation, and
4073 -- the prefix is an access type, insert an explicit dereference,
4074 -- so that entry calls are treated uniformly.
4076 if Is_Access_Type (Etype (P))
4077 and then Is_Concurrent_Type (Designated_Type (Etype (P)))
4080 New_P : constant Node_Id :=
4081 Make_Explicit_Dereference (Sloc (P),
4082 Prefix => Relocate_Node (P));
4085 Set_Etype (P, Designated_Type (Etype (Prefix (P))));
4089 -- If the selected component appears within a default expression
4090 -- and it has an actual subtype, the pre-analysis has not yet
4091 -- completed its analysis, because Insert_Actions is disabled in
4092 -- that context. Within the init proc of the enclosing type we
4093 -- must complete this analysis, if an actual subtype was created.
4095 elsif Inside_Init_Proc then
4097 Typ : constant Entity_Id := Etype (N);
4098 Decl : constant Node_Id := Declaration_Node (Typ);
4101 if Nkind (Decl) = N_Subtype_Declaration
4102 and then not Analyzed (Decl)
4103 and then Is_List_Member (Decl)
4104 and then No (Parent (Decl))
4107 Insert_Action (N, Decl);
4114 elsif Is_Entity_Name (P) then
4115 P_Name := Entity (P);
4117 -- The prefix may denote an enclosing type which is the completion
4118 -- of an incomplete type declaration.
4120 if Is_Type (P_Name) then
4121 Set_Entity (P, Get_Full_View (P_Name));
4122 Set_Etype (P, Entity (P));
4123 P_Name := Entity (P);
4126 P_Type := Base_Type (Etype (P));
4128 if Debug_Flag_E then
4129 Write_Str ("Found prefix type to be ");
4130 Write_Entity_Info (P_Type, " "); Write_Eol;
4133 -- First check for components of a record object (not the
4134 -- result of a call, which is handled below).
4136 if Is_Appropriate_For_Record (P_Type)
4137 and then not Is_Overloadable (P_Name)
4138 and then not Is_Type (P_Name)
4140 -- Selected component of record. Type checking will validate
4141 -- name of selector.
4143 Analyze_Selected_Component (N);
4145 elsif Is_Appropriate_For_Entry_Prefix (P_Type)
4146 and then not In_Open_Scopes (P_Name)
4147 and then (not Is_Concurrent_Type (Etype (P_Name))
4148 or else not In_Open_Scopes (Etype (P_Name)))
4150 -- Call to protected operation or entry. Type checking is
4151 -- needed on the prefix.
4153 Analyze_Selected_Component (N);
4155 elsif (In_Open_Scopes (P_Name)
4156 and then Ekind (P_Name) /= E_Void
4157 and then not Is_Overloadable (P_Name))
4158 or else (Is_Concurrent_Type (Etype (P_Name))
4159 and then In_Open_Scopes (Etype (P_Name)))
4161 -- Prefix denotes an enclosing loop, block, or task, i.e. an
4162 -- enclosing construct that is not a subprogram or accept.
4164 Find_Expanded_Name (N);
4166 elsif Ekind (P_Name) = E_Package then
4167 Find_Expanded_Name (N);
4169 elsif Is_Overloadable (P_Name) then
4171 -- The subprogram may be a renaming (of an enclosing scope) as
4172 -- in the case of the name of the generic within an instantiation.
4174 if (Ekind (P_Name) = E_Procedure
4175 or else Ekind (P_Name) = E_Function)
4176 and then Present (Alias (P_Name))
4177 and then Is_Generic_Instance (Alias (P_Name))
4179 P_Name := Alias (P_Name);
4182 if Is_Overloaded (P) then
4184 -- The prefix must resolve to a unique enclosing construct
4187 Found : Boolean := False;
4192 Get_First_Interp (P, Ind, It);
4194 while Present (It.Nam) loop
4196 if In_Open_Scopes (It.Nam) then
4199 "prefix must be unique enclosing scope", N);
4200 Set_Entity (N, Any_Id);
4201 Set_Etype (N, Any_Type);
4210 Get_Next_Interp (Ind, It);
4215 if In_Open_Scopes (P_Name) then
4216 Set_Entity (P, P_Name);
4217 Set_Is_Overloaded (P, False);
4218 Find_Expanded_Name (N);
4221 -- If no interpretation as an expanded name is possible, it
4222 -- must be a selected component of a record returned by a
4223 -- function call. Reformat prefix as a function call, the
4224 -- rest is done by type resolution. If the prefix is a
4225 -- procedure or entry, as is P.X; this is an error.
4227 if Ekind (P_Name) /= E_Function
4228 and then (not Is_Overloaded (P)
4230 Nkind (Parent (N)) = N_Procedure_Call_Statement)
4233 -- Prefix may mention a package that is hidden by a local
4234 -- declaration: let the user know. Scan the full homonym
4235 -- chain, the candidate package may be anywhere on it.
4237 if Present (Homonym (Current_Entity (P_Name))) then
4239 P_Name := Current_Entity (P_Name);
4241 while Present (P_Name) loop
4242 exit when Ekind (P_Name) = E_Package;
4243 P_Name := Homonym (P_Name);
4246 if Present (P_Name) then
4247 Error_Msg_Sloc := Sloc (Entity (Prefix (N)));
4250 ("package& is hidden by declaration#",
4253 Set_Entity (Prefix (N), P_Name);
4254 Find_Expanded_Name (N);
4257 P_Name := Entity (Prefix (N));
4262 ("invalid prefix in selected component&", N, P_Name);
4263 Change_Selected_Component_To_Expanded_Name (N);
4264 Set_Entity (N, Any_Id);
4265 Set_Etype (N, Any_Type);
4268 Nam := New_Copy (P);
4269 Save_Interps (P, Nam);
4271 Make_Function_Call (Sloc (P), Name => Nam));
4273 Analyze_Selected_Component (N);
4277 -- Remaining cases generate various error messages
4280 -- Format node as expanded name, to avoid cascaded errors
4282 Change_Selected_Component_To_Expanded_Name (N);
4283 Set_Entity (N, Any_Id);
4284 Set_Etype (N, Any_Type);
4286 -- Issue error message, but avoid this if error issued already.
4287 -- Use identifier of prefix if one is available.
4289 if P_Name = Any_Id then
4292 elsif Ekind (P_Name) = E_Void then
4293 Premature_Usage (P);
4295 elsif Nkind (P) /= N_Attribute_Reference then
4297 "invalid prefix in selected component&", P);
4299 if Is_Access_Type (P_Type)
4300 and then Ekind (Designated_Type (P_Type)) = E_Incomplete_Type
4303 ("\dereference must not be of an incomplete type " &
4304 "('R'M 3.10.1)", P);
4309 "invalid prefix in selected component", P);
4314 -- If prefix is not the name of an entity, it must be an expression,
4315 -- whose type is appropriate for a record. This is determined by
4318 Analyze_Selected_Component (N);
4320 end Find_Selected_Component;
4326 procedure Find_Type (N : Node_Id) is
4336 elsif Nkind (N) = N_Attribute_Reference then
4338 -- Class attribute. This is only valid in Ada 95 mode, but we don't
4339 -- do a check, since the tagged type referenced could only exist if
4340 -- we were in 95 mode when it was declared (or, if we were in Ada
4341 -- 83 mode, then an error message would already have been issued).
4343 if Attribute_Name (N) = Name_Class then
4344 Check_Restriction (No_Dispatch, N);
4345 Find_Type (Prefix (N));
4347 -- Propagate error from bad prefix
4349 if Etype (Prefix (N)) = Any_Type then
4350 Set_Entity (N, Any_Type);
4351 Set_Etype (N, Any_Type);
4355 T := Base_Type (Entity (Prefix (N)));
4357 -- Case of non-tagged type
4359 if not Is_Tagged_Type (T) then
4360 if Ekind (T) = E_Incomplete_Type then
4362 -- It is legal to denote the class type of an incomplete
4363 -- type. The full type will have to be tagged, of course.
4365 Set_Is_Tagged_Type (T);
4366 Make_Class_Wide_Type (T);
4367 Set_Entity (N, Class_Wide_Type (T));
4368 Set_Etype (N, Class_Wide_Type (T));
4370 elsif Ekind (T) = E_Private_Type
4371 and then not Is_Generic_Type (T)
4372 and then In_Private_Part (Scope (T))
4374 -- The Class attribute can be applied to an untagged
4375 -- private type fulfilled by a tagged type prior to
4376 -- the full type declaration (but only within the
4377 -- parent package's private part). Create the class-wide
4378 -- type now and check that the full type is tagged
4379 -- later during its analysis. Note that we do not
4380 -- mark the private type as tagged, unlike the case
4381 -- of incomplete types, because the type must still
4382 -- appear untagged to outside units.
4384 if not Present (Class_Wide_Type (T)) then
4385 Make_Class_Wide_Type (T);
4388 Set_Entity (N, Class_Wide_Type (T));
4389 Set_Etype (N, Class_Wide_Type (T));
4392 -- Should we introduce a type Any_Tagged and use
4393 -- Wrong_Type here, it would be a bit more consistent???
4396 ("tagged type required, found}",
4397 Prefix (N), First_Subtype (T));
4398 Set_Entity (N, Any_Type);
4402 -- Case of tagged type
4405 C := Class_Wide_Type (Entity (Prefix (N)));
4406 Set_Entity_With_Style_Check (N, C);
4407 Generate_Reference (C, N);
4411 -- Base attribute, not allowed in Ada 83
4413 elsif Attribute_Name (N) = Name_Base then
4414 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
4416 ("(Ada 83) Base attribute not allowed in subtype mark", N);
4419 Find_Type (Prefix (N));
4420 Typ := Entity (Prefix (N));
4422 if Ada_Version >= Ada_95
4423 and then not Is_Scalar_Type (Typ)
4424 and then not Is_Generic_Type (Typ)
4427 ("prefix of Base attribute must be scalar type",
4430 elsif Sloc (Typ) = Standard_Location
4431 and then Base_Type (Typ) = Typ
4432 and then Warn_On_Redundant_Constructs
4435 ("?redudant attribute, & is its own base type", N, Typ);
4438 T := Base_Type (Typ);
4440 -- Rewrite attribute reference with type itself (see similar
4441 -- processing in Analyze_Attribute, case Base). Preserve
4442 -- prefix if present, for other legality checks.
4444 if Nkind (Prefix (N)) = N_Expanded_Name then
4446 Make_Expanded_Name (Sloc (N),
4447 Chars => Chars (Entity (N)),
4448 Prefix => New_Copy (Prefix (Prefix (N))),
4450 New_Reference_To (Entity (N), Sloc (N))));
4454 New_Reference_To (Entity (N), Sloc (N)));
4461 -- All other attributes are invalid in a subtype mark
4464 Error_Msg_N ("invalid attribute in subtype mark", N);
4470 if Is_Entity_Name (N) then
4471 T_Name := Entity (N);
4473 Error_Msg_N ("subtype mark required in this context", N);
4474 Set_Etype (N, Any_Type);
4478 if T_Name = Any_Id or else Etype (N) = Any_Type then
4480 -- Undefined id. Make it into a valid type
4482 Set_Entity (N, Any_Type);
4484 elsif not Is_Type (T_Name)
4485 and then T_Name /= Standard_Void_Type
4487 Error_Msg_Sloc := Sloc (T_Name);
4488 Error_Msg_N ("subtype mark required in this context", N);
4489 Error_Msg_NE ("\found & declared#", N, T_Name);
4490 Set_Entity (N, Any_Type);
4493 T_Name := Get_Full_View (T_Name);
4495 if In_Open_Scopes (T_Name) then
4496 if Ekind (Base_Type (T_Name)) = E_Task_Type then
4497 Error_Msg_N ("task type cannot be used as type mark " &
4498 "within its own body", N);
4500 Error_Msg_N ("type declaration cannot refer to itself", N);
4503 Set_Etype (N, Any_Type);
4504 Set_Entity (N, Any_Type);
4505 Set_Error_Posted (T_Name);
4509 Set_Entity (N, T_Name);
4510 Set_Etype (N, T_Name);
4514 if Present (Etype (N)) and then Comes_From_Source (N) then
4515 if Is_Fixed_Point_Type (Etype (N)) then
4516 Check_Restriction (No_Fixed_Point, N);
4517 elsif Is_Floating_Point_Type (Etype (N)) then
4518 Check_Restriction (No_Floating_Point, N);
4527 function Get_Full_View (T_Name : Entity_Id) return Entity_Id is
4529 if Ekind (T_Name) = E_Incomplete_Type
4530 and then Present (Full_View (T_Name))
4532 return Full_View (T_Name);
4534 elsif Is_Class_Wide_Type (T_Name)
4535 and then Ekind (Root_Type (T_Name)) = E_Incomplete_Type
4536 and then Present (Full_View (Root_Type (T_Name)))
4538 return Class_Wide_Type (Full_View (Root_Type (T_Name)));
4545 ------------------------------------
4546 -- Has_Implicit_Character_Literal --
4547 ------------------------------------
4549 function Has_Implicit_Character_Literal (N : Node_Id) return Boolean is
4551 Found : Boolean := False;
4552 P : constant Entity_Id := Entity (Prefix (N));
4553 Priv_Id : Entity_Id := Empty;
4556 if Ekind (P) = E_Package
4557 and then not In_Open_Scopes (P)
4559 Priv_Id := First_Private_Entity (P);
4562 if P = Standard_Standard then
4563 Change_Selected_Component_To_Expanded_Name (N);
4564 Rewrite (N, Selector_Name (N));
4566 Set_Etype (Original_Node (N), Standard_Character);
4570 Id := First_Entity (P);
4573 and then Id /= Priv_Id
4575 if Is_Character_Type (Id)
4576 and then (Root_Type (Id) = Standard_Character
4577 or else Root_Type (Id) = Standard_Wide_Character
4578 or else Root_Type (Id) = Standard_Wide_Wide_Character)
4579 and then Id = Base_Type (Id)
4581 -- We replace the node with the literal itself, resolve as a
4582 -- character, and set the type correctly.
4585 Change_Selected_Component_To_Expanded_Name (N);
4586 Rewrite (N, Selector_Name (N));
4589 Set_Etype (Original_Node (N), Id);
4593 -- More than one type derived from Character in given scope.
4594 -- Collect all possible interpretations.
4596 Add_One_Interp (N, Id, Id);
4604 end Has_Implicit_Character_Literal;
4606 ----------------------
4607 -- Has_Private_With --
4608 ----------------------
4610 function Has_Private_With (E : Entity_Id) return Boolean is
4611 Comp_Unit : constant Node_Id := Cunit (Current_Sem_Unit);
4615 Item := First (Context_Items (Comp_Unit));
4616 while Present (Item) loop
4617 if Nkind (Item) = N_With_Clause
4618 and then Private_Present (Item)
4619 and then Entity (Name (Item)) = E
4628 end Has_Private_With;
4630 ---------------------------
4631 -- Has_Implicit_Operator --
4632 ---------------------------
4634 function Has_Implicit_Operator (N : Node_Id) return Boolean is
4635 Op_Id : constant Name_Id := Chars (Selector_Name (N));
4636 P : constant Entity_Id := Entity (Prefix (N));
4638 Priv_Id : Entity_Id := Empty;
4640 procedure Add_Implicit_Operator
4642 Op_Type : Entity_Id := Empty);
4643 -- Add implicit interpretation to node N, using the type for which
4644 -- a predefined operator exists. If the operator yields a boolean
4645 -- type, the Operand_Type is implicitly referenced by the operator,
4646 -- and a reference to it must be generated.
4648 ---------------------------
4649 -- Add_Implicit_Operator --
4650 ---------------------------
4652 procedure Add_Implicit_Operator
4654 Op_Type : Entity_Id := Empty)
4656 Predef_Op : Entity_Id;
4659 Predef_Op := Current_Entity (Selector_Name (N));
4661 while Present (Predef_Op)
4662 and then Scope (Predef_Op) /= Standard_Standard
4664 Predef_Op := Homonym (Predef_Op);
4667 if Nkind (N) = N_Selected_Component then
4668 Change_Selected_Component_To_Expanded_Name (N);
4671 Add_One_Interp (N, Predef_Op, T);
4673 -- For operators with unary and binary interpretations, add both
4675 if Present (Homonym (Predef_Op)) then
4676 Add_One_Interp (N, Homonym (Predef_Op), T);
4679 -- The node is a reference to a predefined operator, and
4680 -- an implicit reference to the type of its operands.
4682 if Present (Op_Type) then
4683 Generate_Operator_Reference (N, Op_Type);
4685 Generate_Operator_Reference (N, T);
4687 end Add_Implicit_Operator;
4689 -- Start of processing for Has_Implicit_Operator
4693 if Ekind (P) = E_Package
4694 and then not In_Open_Scopes (P)
4696 Priv_Id := First_Private_Entity (P);
4699 Id := First_Entity (P);
4703 -- Boolean operators: an implicit declaration exists if the scope
4704 -- contains a declaration for a derived Boolean type, or for an
4705 -- array of Boolean type.
4707 when Name_Op_And | Name_Op_Not | Name_Op_Or | Name_Op_Xor =>
4709 while Id /= Priv_Id loop
4711 if Valid_Boolean_Arg (Id)
4712 and then Id = Base_Type (Id)
4714 Add_Implicit_Operator (Id);
4721 -- Equality: look for any non-limited type (result is Boolean)
4723 when Name_Op_Eq | Name_Op_Ne =>
4725 while Id /= Priv_Id loop
4728 and then not Is_Limited_Type (Id)
4729 and then Id = Base_Type (Id)
4731 Add_Implicit_Operator (Standard_Boolean, Id);
4738 -- Comparison operators: scalar type, or array of scalar
4740 when Name_Op_Lt | Name_Op_Le | Name_Op_Gt | Name_Op_Ge =>
4742 while Id /= Priv_Id loop
4743 if (Is_Scalar_Type (Id)
4744 or else (Is_Array_Type (Id)
4745 and then Is_Scalar_Type (Component_Type (Id))))
4746 and then Id = Base_Type (Id)
4748 Add_Implicit_Operator (Standard_Boolean, Id);
4755 -- Arithmetic operators: any numeric type
4766 while Id /= Priv_Id loop
4767 if Is_Numeric_Type (Id)
4768 and then Id = Base_Type (Id)
4770 Add_Implicit_Operator (Id);
4777 -- Concatenation: any one-dimensional array type
4779 when Name_Op_Concat =>
4781 while Id /= Priv_Id loop
4782 if Is_Array_Type (Id) and then Number_Dimensions (Id) = 1
4783 and then Id = Base_Type (Id)
4785 Add_Implicit_Operator (Id);
4792 -- What is the others condition here? Should we be using a
4793 -- subtype of Name_Id that would restrict to operators ???
4795 when others => null;
4799 -- If we fall through, then we do not have an implicit operator
4803 end Has_Implicit_Operator;
4805 --------------------
4806 -- In_Open_Scopes --
4807 --------------------
4809 function In_Open_Scopes (S : Entity_Id) return Boolean is
4811 -- Since there are several scope stacks maintained by Scope_Stack each
4812 -- delineated by Standard (see comments by definition of Scope_Stack)
4813 -- it is necessary to end the search when Standard is reached.
4815 for J in reverse 0 .. Scope_Stack.Last loop
4816 if Scope_Stack.Table (J).Entity = S then
4820 -- We need Is_Active_Stack_Base to tell us when to stop rather
4821 -- than checking for Standard_Standard because there are cases
4822 -- where Standard_Standard appears in the middle of the active
4823 -- set of scopes. This affects the declaration and overriding
4824 -- of private inherited operations in instantiations of generic
4827 exit when Scope_Stack.Table (J).Is_Active_Stack_Base;
4833 -----------------------------
4834 -- Inherit_Renamed_Profile --
4835 -----------------------------
4837 procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id) is
4844 if Ekind (Old_S) = E_Operator then
4846 New_F := First_Formal (New_S);
4848 while Present (New_F) loop
4849 Set_Etype (New_F, Base_Type (Etype (New_F)));
4850 Next_Formal (New_F);
4853 Set_Etype (New_S, Base_Type (Etype (New_S)));
4856 New_F := First_Formal (New_S);
4857 Old_F := First_Formal (Old_S);
4859 while Present (New_F) loop
4860 New_T := Etype (New_F);
4861 Old_T := Etype (Old_F);
4863 -- If the new type is a renaming of the old one, as is the
4864 -- case for actuals in instances, retain its name, to simplify
4865 -- later disambiguation.
4867 if Nkind (Parent (New_T)) = N_Subtype_Declaration
4868 and then Is_Entity_Name (Subtype_Indication (Parent (New_T)))
4869 and then Entity (Subtype_Indication (Parent (New_T))) = Old_T
4873 Set_Etype (New_F, Old_T);
4876 Next_Formal (New_F);
4877 Next_Formal (Old_F);
4880 if Ekind (Old_S) = E_Function
4881 or else Ekind (Old_S) = E_Enumeration_Literal
4883 Set_Etype (New_S, Etype (Old_S));
4886 end Inherit_Renamed_Profile;
4892 procedure Initialize is
4897 -------------------------
4898 -- Install_Use_Clauses --
4899 -------------------------
4901 procedure Install_Use_Clauses
4903 Force_Installation : Boolean := False)
4905 U : Node_Id := Clause;
4910 while Present (U) loop
4912 -- Case of USE package
4914 if Nkind (U) = N_Use_Package_Clause then
4915 P := First (Names (U));
4917 while Present (P) loop
4920 if Ekind (Id) = E_Package then
4923 Set_Redundant_Use (P, True);
4925 elsif Present (Renamed_Object (Id))
4926 and then In_Use (Renamed_Object (Id))
4928 Set_Redundant_Use (P, True);
4930 elsif Force_Installation or else Applicable_Use (P) then
4931 Use_One_Package (Id, U);
4942 P := First (Subtype_Marks (U));
4944 while Present (P) loop
4945 if not Is_Entity_Name (P)
4946 or else No (Entity (P))
4950 elsif Entity (P) /= Any_Type then
4958 Next_Use_Clause (U);
4960 end Install_Use_Clauses;
4962 -------------------------------------
4963 -- Is_Appropriate_For_Entry_Prefix --
4964 -------------------------------------
4966 function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean is
4967 P_Type : Entity_Id := T;
4970 if Is_Access_Type (P_Type) then
4971 P_Type := Designated_Type (P_Type);
4974 return Is_Task_Type (P_Type) or else Is_Protected_Type (P_Type);
4975 end Is_Appropriate_For_Entry_Prefix;
4977 -------------------------------
4978 -- Is_Appropriate_For_Record --
4979 -------------------------------
4981 function Is_Appropriate_For_Record (T : Entity_Id) return Boolean is
4983 function Has_Components (T1 : Entity_Id) return Boolean;
4984 -- Determine if given type has components (i.e. is either a record
4985 -- type or a type that has discriminants).
4987 function Has_Components (T1 : Entity_Id) return Boolean is
4989 return Is_Record_Type (T1)
4990 or else (Is_Private_Type (T1) and then Has_Discriminants (T1))
4991 or else (Is_Task_Type (T1) and then Has_Discriminants (T1));
4994 -- Start of processing for Is_Appropriate_For_Record
4999 and then (Has_Components (T)
5000 or else (Is_Access_Type (T)
5002 Has_Components (Designated_Type (T))));
5003 end Is_Appropriate_For_Record;
5009 procedure New_Scope (S : Entity_Id) is
5013 if Ekind (S) = E_Void then
5016 -- Set scope depth if not a non-concurrent type, and we have not
5017 -- yet set the scope depth. This means that we have the first
5018 -- occurrence of the scope, and this is where the depth is set.
5020 elsif (not Is_Type (S) or else Is_Concurrent_Type (S))
5021 and then not Scope_Depth_Set (S)
5023 if S = Standard_Standard then
5024 Set_Scope_Depth_Value (S, Uint_0);
5026 elsif Is_Child_Unit (S) then
5027 Set_Scope_Depth_Value (S, Uint_1);
5029 elsif not Is_Record_Type (Current_Scope) then
5030 if Ekind (S) = E_Loop then
5031 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope));
5033 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope) + 1);
5038 Scope_Stack.Increment_Last;
5041 SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
5045 SST.Save_Scope_Suppress := Scope_Suppress;
5046 SST.Save_Local_Entity_Suppress := Local_Entity_Suppress.Last;
5048 if Scope_Stack.Last > Scope_Stack.First then
5049 SST.Component_Alignment_Default := Scope_Stack.Table
5050 (Scope_Stack.Last - 1).
5051 Component_Alignment_Default;
5054 SST.Last_Subprogram_Name := null;
5055 SST.Is_Transient := False;
5056 SST.Node_To_Be_Wrapped := Empty;
5057 SST.Pending_Freeze_Actions := No_List;
5058 SST.Actions_To_Be_Wrapped_Before := No_List;
5059 SST.Actions_To_Be_Wrapped_After := No_List;
5060 SST.First_Use_Clause := Empty;
5061 SST.Is_Active_Stack_Base := False;
5064 if Debug_Flag_W then
5065 Write_Str ("--> new scope: ");
5066 Write_Name (Chars (Current_Scope));
5067 Write_Str (", Id=");
5068 Write_Int (Int (Current_Scope));
5069 Write_Str (", Depth=");
5070 Write_Int (Int (Scope_Stack.Last));
5074 -- Copy from Scope (S) the categorization flags to S, this is not
5075 -- done in case Scope (S) is Standard_Standard since propagation
5076 -- is from library unit entity inwards.
5078 if S /= Standard_Standard
5079 and then Scope (S) /= Standard_Standard
5080 and then not Is_Child_Unit (S)
5084 if Nkind (E) not in N_Entity then
5088 -- We only propagate inwards for library level entities,
5089 -- inner level subprograms do not inherit the categorization.
5091 if Is_Library_Level_Entity (S) then
5092 Set_Is_Preelaborated (S, Is_Preelaborated (E));
5093 Set_Is_Shared_Passive (S, Is_Shared_Passive (E));
5094 Set_Categorization_From_Scope (E => S, Scop => E);
5103 procedure Pop_Scope is
5104 SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
5107 if Debug_Flag_E then
5111 Scope_Suppress := SST.Save_Scope_Suppress;
5112 Local_Entity_Suppress.Set_Last (SST.Save_Local_Entity_Suppress);
5114 if Debug_Flag_W then
5115 Write_Str ("--> exiting scope: ");
5116 Write_Name (Chars (Current_Scope));
5117 Write_Str (", Depth=");
5118 Write_Int (Int (Scope_Stack.Last));
5122 End_Use_Clauses (SST.First_Use_Clause);
5124 -- If the actions to be wrapped are still there they will get lost
5125 -- causing incomplete code to be generated. It is better to abort in
5126 -- this case (and we do the abort even with assertions off since the
5127 -- penalty is incorrect code generation)
5129 if SST.Actions_To_Be_Wrapped_Before /= No_List
5131 SST.Actions_To_Be_Wrapped_After /= No_List
5136 -- Free last subprogram name if allocated, and pop scope
5138 Free (SST.Last_Subprogram_Name);
5139 Scope_Stack.Decrement_Last;
5142 ---------------------
5143 -- Premature_Usage --
5144 ---------------------
5146 procedure Premature_Usage (N : Node_Id) is
5147 Kind : constant Node_Kind := Nkind (Parent (Entity (N)));
5148 E : Entity_Id := Entity (N);
5151 -- Within an instance, the analysis of the actual for a formal object
5152 -- does not see the name of the object itself. This is significant
5153 -- only if the object is an aggregate, where its analysis does not do
5154 -- any name resolution on component associations. (see 4717-008). In
5155 -- such a case, look for the visible homonym on the chain.
5158 and then Present (Homonym (E))
5163 and then not In_Open_Scopes (Scope (E))
5170 Set_Etype (N, Etype (E));
5175 if Kind = N_Component_Declaration then
5177 ("component&! cannot be used before end of record declaration", N);
5179 elsif Kind = N_Parameter_Specification then
5181 ("formal parameter&! cannot be used before end of specification",
5184 elsif Kind = N_Discriminant_Specification then
5186 ("discriminant&! cannot be used before end of discriminant part",
5189 elsif Kind = N_Procedure_Specification
5190 or else Kind = N_Function_Specification
5193 ("subprogram&! cannot be used before end of its declaration",
5197 ("object& cannot be used before end of its declaration!", N);
5199 end Premature_Usage;
5201 ------------------------
5202 -- Present_System_Aux --
5203 ------------------------
5205 function Present_System_Aux (N : Node_Id := Empty) return Boolean is
5208 Unum : Unit_Number_Type;
5213 function Find_System (C_Unit : Node_Id) return Entity_Id;
5214 -- Scan context clause of compilation unit to find a with_clause
5221 function Find_System (C_Unit : Node_Id) return Entity_Id is
5222 With_Clause : Node_Id;
5225 With_Clause := First (Context_Items (C_Unit));
5227 while Present (With_Clause) loop
5228 if (Nkind (With_Clause) = N_With_Clause
5229 and then Chars (Name (With_Clause)) = Name_System)
5230 and then Comes_From_Source (With_Clause)
5241 -- Start of processing for Present_System_Aux
5244 -- The child unit may have been loaded and analyzed already
5246 if Present (System_Aux_Id) then
5249 -- If no previous pragma for System.Aux, nothing to load
5251 elsif No (System_Extend_Unit) then
5254 -- Use the unit name given in the pragma to retrieve the unit.
5255 -- Verify that System itself appears in the context clause of the
5256 -- current compilation. If System is not present, an error will
5257 -- have been reported already.
5260 With_Sys := Find_System (Cunit (Current_Sem_Unit));
5262 The_Unit := Unit (Cunit (Current_Sem_Unit));
5265 and then (Nkind (The_Unit) = N_Package_Body
5266 or else (Nkind (The_Unit) = N_Subprogram_Body
5267 and then not Acts_As_Spec (Cunit (Current_Sem_Unit))))
5269 With_Sys := Find_System (Library_Unit (Cunit (Current_Sem_Unit)));
5273 and then Present (N)
5275 -- If we are compiling a subunit, we need to examine its
5276 -- context as well (Current_Sem_Unit is the parent unit);
5278 The_Unit := Parent (N);
5280 while Nkind (The_Unit) /= N_Compilation_Unit loop
5281 The_Unit := Parent (The_Unit);
5284 if Nkind (Unit (The_Unit)) = N_Subunit then
5285 With_Sys := Find_System (The_Unit);
5289 if No (With_Sys) then
5293 Loc := Sloc (With_Sys);
5294 Get_Name_String (Chars (Expression (System_Extend_Unit)));
5295 Name_Buffer (8 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
5296 Name_Buffer (1 .. 7) := "system.";
5297 Name_Buffer (Name_Len + 8) := '%';
5298 Name_Buffer (Name_Len + 9) := 's';
5299 Name_Len := Name_Len + 9;
5300 Aux_Name := Name_Find;
5304 (Load_Name => Aux_Name,
5307 Error_Node => With_Sys);
5309 if Unum /= No_Unit then
5310 Semantics (Cunit (Unum));
5312 Defining_Entity (Specification (Unit (Cunit (Unum))));
5314 Withn := Make_With_Clause (Loc,
5316 Make_Expanded_Name (Loc,
5317 Chars => Chars (System_Aux_Id),
5319 New_Reference_To (Scope (System_Aux_Id), Loc),
5321 New_Reference_To (System_Aux_Id, Loc)));
5323 Set_Entity (Name (Withn), System_Aux_Id);
5325 Set_Library_Unit (Withn, Cunit (Unum));
5326 Set_Corresponding_Spec (Withn, System_Aux_Id);
5327 Set_First_Name (Withn, True);
5328 Set_Implicit_With (Withn, True);
5330 Insert_After (With_Sys, Withn);
5331 Mark_Rewrite_Insertion (Withn);
5332 Set_Context_Installed (Withn);
5336 -- Here if unit load failed
5339 Error_Msg_Name_1 := Name_System;
5340 Error_Msg_Name_2 := Chars (Expression (System_Extend_Unit));
5342 ("extension package `%.%` does not exist",
5343 Opt.System_Extend_Unit);
5347 end Present_System_Aux;
5349 -------------------------
5350 -- Restore_Scope_Stack --
5351 -------------------------
5353 procedure Restore_Scope_Stack (Handle_Use : Boolean := True) is
5356 Comp_Unit : Node_Id;
5357 In_Child : Boolean := False;
5358 Full_Vis : Boolean := True;
5359 SS_Last : constant Int := Scope_Stack.Last;
5362 -- Restore visibility of previous scope stack, if any
5364 for J in reverse 0 .. Scope_Stack.Last loop
5365 exit when Scope_Stack.Table (J).Entity = Standard_Standard
5366 or else No (Scope_Stack.Table (J).Entity);
5368 S := Scope_Stack.Table (J).Entity;
5370 if not Is_Hidden_Open_Scope (S) then
5372 -- If the parent scope is hidden, its entities are hidden as
5373 -- well, unless the entity is the instantiation currently
5376 if not Is_Hidden_Open_Scope (Scope (S))
5377 or else not Analyzed (Parent (S))
5378 or else Scope (S) = Standard_Standard
5380 Set_Is_Immediately_Visible (S, True);
5383 E := First_Entity (S);
5385 while Present (E) loop
5386 if Is_Child_Unit (E) then
5387 Set_Is_Immediately_Visible (E,
5388 Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
5390 Set_Is_Immediately_Visible (E, True);
5395 if not Full_Vis then
5396 exit when E = First_Private_Entity (S);
5400 -- The visibility of child units (siblings of current compilation)
5401 -- must be restored in any case. Their declarations may appear
5402 -- after the private part of the parent.
5405 and then Present (E)
5407 while Present (E) loop
5408 if Is_Child_Unit (E) then
5409 Set_Is_Immediately_Visible (E,
5410 Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
5418 if Is_Child_Unit (S)
5419 and not In_Child -- check only for current unit.
5423 -- restore visibility of parents according to whether the child
5424 -- is private and whether we are in its visible part.
5426 Comp_Unit := Parent (Unit_Declaration_Node (S));
5428 if Nkind (Comp_Unit) = N_Compilation_Unit
5429 and then Private_Present (Comp_Unit)
5433 elsif (Ekind (S) = E_Package
5434 or else Ekind (S) = E_Generic_Package)
5435 and then (In_Private_Part (S)
5436 or else In_Package_Body (S))
5440 elsif (Ekind (S) = E_Procedure
5441 or else Ekind (S) = E_Function)
5442 and then Has_Completion (S)
5453 if SS_Last >= Scope_Stack.First
5454 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
5457 Install_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
5459 end Restore_Scope_Stack;
5461 ----------------------
5462 -- Save_Scope_Stack --
5463 ----------------------
5465 procedure Save_Scope_Stack (Handle_Use : Boolean := True) is
5468 SS_Last : constant Int := Scope_Stack.Last;
5471 if SS_Last >= Scope_Stack.First
5472 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
5475 End_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
5478 -- If the call is from within a compilation unit, as when
5479 -- called from Rtsfind, make current entries in scope stack
5480 -- invisible while we analyze the new unit.
5482 for J in reverse 0 .. SS_Last loop
5483 exit when Scope_Stack.Table (J).Entity = Standard_Standard
5484 or else No (Scope_Stack.Table (J).Entity);
5486 S := Scope_Stack.Table (J).Entity;
5487 Set_Is_Immediately_Visible (S, False);
5488 E := First_Entity (S);
5490 while Present (E) loop
5491 Set_Is_Immediately_Visible (E, False);
5497 end Save_Scope_Stack;
5503 procedure Set_Use (L : List_Id) is
5505 Pack_Name : Node_Id;
5513 while Present (Decl) loop
5514 if Nkind (Decl) = N_Use_Package_Clause then
5515 Chain_Use_Clause (Decl);
5516 Pack_Name := First (Names (Decl));
5518 while Present (Pack_Name) loop
5519 Pack := Entity (Pack_Name);
5521 if Ekind (Pack) = E_Package
5522 and then Applicable_Use (Pack_Name)
5524 Use_One_Package (Pack, Decl);
5530 elsif Nkind (Decl) = N_Use_Type_Clause then
5531 Chain_Use_Clause (Decl);
5532 Id := First (Subtype_Marks (Decl));
5534 while Present (Id) loop
5535 if Entity (Id) /= Any_Type then
5548 ---------------------
5549 -- Use_One_Package --
5550 ---------------------
5552 procedure Use_One_Package (P : Entity_Id; N : Node_Id) is
5555 Current_Instance : Entity_Id := Empty;
5557 Private_With_OK : Boolean := False;
5560 if Ekind (P) /= E_Package then
5566 -- Ada 2005 (AI-50217): Check restriction
5568 if From_With_Type (P) then
5569 Error_Msg_N ("limited withed package cannot appear in use clause", N);
5572 -- Find enclosing instance, if any
5575 Current_Instance := Current_Scope;
5577 while not Is_Generic_Instance (Current_Instance) loop
5578 Current_Instance := Scope (Current_Instance);
5581 if No (Hidden_By_Use_Clause (N)) then
5582 Set_Hidden_By_Use_Clause (N, New_Elmt_List);
5586 -- If unit is a package renaming, indicate that the renamed
5587 -- package is also in use (the flags on both entities must
5588 -- remain consistent, and a subsequent use of either of them
5589 -- should be recognized as redundant).
5591 if Present (Renamed_Object (P)) then
5592 Set_In_Use (Renamed_Object (P));
5593 Real_P := Renamed_Object (P);
5598 -- Ada 2005 (AI-262): Check the use_clause of a private withed package
5599 -- found in the private part of a package specification
5601 if In_Private_Part (Current_Scope)
5602 and then Has_Private_With (P)
5603 and then Is_Child_Unit (Current_Scope)
5604 and then Is_Child_Unit (P)
5605 and then Is_Ancestor_Package (Scope (Current_Scope), P)
5607 Private_With_OK := True;
5610 -- Loop through entities in one package making them potentially
5613 Id := First_Entity (P);
5615 and then (Id /= First_Private_Entity (P)
5616 or else Private_With_OK) -- Ada 2005 (AI-262)
5618 Prev := Current_Entity (Id);
5620 while Present (Prev) loop
5621 if Is_Immediately_Visible (Prev)
5622 and then (not Is_Overloadable (Prev)
5623 or else not Is_Overloadable (Id)
5624 or else (Type_Conformant (Id, Prev)))
5626 if No (Current_Instance) then
5628 -- Potentially use-visible entity remains hidden
5630 goto Next_Usable_Entity;
5632 -- A use clause within an instance hides outer global
5633 -- entities, which are not used to resolve local entities
5634 -- in the instance. Note that the predefined entities in
5635 -- Standard could not have been hidden in the generic by
5636 -- a use clause, and therefore remain visible. Other
5637 -- compilation units whose entities appear in Standard must
5638 -- be hidden in an instance.
5640 -- To determine whether an entity is external to the instance
5641 -- we compare the scope depth of its scope with that of the
5642 -- current instance. However, a generic actual of a subprogram
5643 -- instance is declared in the wrapper package but will not be
5644 -- hidden by a use-visible entity.
5646 -- If Id is called Standard, the predefined package with the
5647 -- same name is in the homonym chain. It has to be ignored
5648 -- because it has no defined scope (being the only entity in
5649 -- the system with this mandated behavior).
5651 elsif not Is_Hidden (Id)
5652 and then Present (Scope (Prev))
5653 and then not Is_Wrapper_Package (Scope (Prev))
5654 and then Scope_Depth (Scope (Prev)) <
5655 Scope_Depth (Current_Instance)
5656 and then (Scope (Prev) /= Standard_Standard
5657 or else Sloc (Prev) > Standard_Location)
5659 Set_Is_Potentially_Use_Visible (Id);
5660 Set_Is_Immediately_Visible (Prev, False);
5661 Append_Elmt (Prev, Hidden_By_Use_Clause (N));
5664 -- A user-defined operator is not use-visible if the
5665 -- predefined operator for the type is immediately visible,
5666 -- which is the case if the type of the operand is in an open
5667 -- scope. This does not apply to user-defined operators that
5668 -- have operands of different types, because the predefined
5669 -- mixed mode operations (multiplication and division) apply to
5670 -- universal types and do not hide anything.
5672 elsif Ekind (Prev) = E_Operator
5673 and then Operator_Matches_Spec (Prev, Id)
5674 and then In_Open_Scopes
5675 (Scope (Base_Type (Etype (First_Formal (Id)))))
5676 and then (No (Next_Formal (First_Formal (Id)))
5677 or else Etype (First_Formal (Id))
5678 = Etype (Next_Formal (First_Formal (Id)))
5679 or else Chars (Prev) = Name_Op_Expon)
5681 goto Next_Usable_Entity;
5684 Prev := Homonym (Prev);
5687 -- On exit, we know entity is not hidden, unless it is private
5689 if not Is_Hidden (Id)
5690 and then ((not Is_Child_Unit (Id))
5691 or else Is_Visible_Child_Unit (Id))
5693 Set_Is_Potentially_Use_Visible (Id);
5695 if Is_Private_Type (Id)
5696 and then Present (Full_View (Id))
5698 Set_Is_Potentially_Use_Visible (Full_View (Id));
5702 <<Next_Usable_Entity>>
5706 -- Child units are also made use-visible by a use clause, but they
5707 -- may appear after all visible declarations in the parent entity list.
5709 while Present (Id) loop
5711 if Is_Child_Unit (Id)
5712 and then Is_Visible_Child_Unit (Id)
5714 Set_Is_Potentially_Use_Visible (Id);
5720 if Chars (Real_P) = Name_System
5721 and then Scope (Real_P) = Standard_Standard
5722 and then Present_System_Aux (N)
5724 Use_One_Package (System_Aux_Id, N);
5727 end Use_One_Package;
5733 procedure Use_One_Type (Id : Node_Id) is
5739 -- It is the type determined by the subtype mark (8.4(8)) whose
5740 -- operations become potentially use-visible.
5742 T := Base_Type (Entity (Id));
5747 or else Is_Potentially_Use_Visible (T)
5748 or else In_Use (Scope (T)));
5750 if In_Open_Scopes (Scope (T)) then
5753 -- If the subtype mark designates a subtype in a different package,
5754 -- we have to check that the parent type is visible, otherwise the
5755 -- use type clause is a noop. Not clear how to do that???
5757 elsif not Redundant_Use (Id) then
5759 Op_List := Collect_Primitive_Operations (T);
5760 Elmt := First_Elmt (Op_List);
5762 while Present (Elmt) loop
5764 if (Nkind (Node (Elmt)) = N_Defining_Operator_Symbol
5765 or else Chars (Node (Elmt)) in Any_Operator_Name)
5766 and then not Is_Hidden (Node (Elmt))
5768 Set_Is_Potentially_Use_Visible (Node (Elmt));
5780 procedure Write_Info is
5781 Id : Entity_Id := First_Entity (Current_Scope);
5784 -- No point in dumping standard entities
5786 if Current_Scope = Standard_Standard then
5790 Write_Str ("========================================================");
5792 Write_Str (" Defined Entities in ");
5793 Write_Name (Chars (Current_Scope));
5795 Write_Str ("========================================================");
5799 Write_Str ("-- none --");
5803 while Present (Id) loop
5804 Write_Entity_Info (Id, " ");
5809 if Scope (Current_Scope) = Standard_Standard then
5811 -- Print information on the current unit itself
5813 Write_Entity_Info (Current_Scope, " ");
5823 procedure Write_Scopes is
5827 for J in reverse 1 .. Scope_Stack.Last loop
5828 S := Scope_Stack.Table (J).Entity;
5829 Write_Int (Int (S));
5830 Write_Str (" === ");
5831 Write_Name (Chars (S));