1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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_Tss; use Exp_Tss;
33 with Exp_Util; use Exp_Util;
34 with Fname; use Fname;
35 with Freeze; use Freeze;
36 with Impunit; use Impunit;
38 with Lib.Load; use Lib.Load;
39 with Lib.Xref; use Lib.Xref;
40 with Namet; use Namet;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
44 with Output; use Output;
45 with Restrict; use Restrict;
46 with Rident; use Rident;
47 with Rtsfind; use Rtsfind;
49 with Sem_Cat; use Sem_Cat;
50 with Sem_Ch3; use Sem_Ch3;
51 with Sem_Ch4; use Sem_Ch4;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch12; use Sem_Ch12;
54 with Sem_Disp; use Sem_Disp;
55 with Sem_Dist; use Sem_Dist;
56 with Sem_Res; use Sem_Res;
57 with Sem_Util; use Sem_Util;
58 with Sem_Type; use Sem_Type;
59 with Stand; use Stand;
60 with Sinfo; use Sinfo;
61 with Sinfo.CN; use Sinfo.CN;
62 with Snames; use Snames;
63 with Style; use Style;
65 with Tbuild; use Tbuild;
66 with Uintp; use Uintp;
68 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
70 package body Sem_Ch8 is
72 ------------------------------------
73 -- Visibility and Name Resolution --
74 ------------------------------------
76 -- This package handles name resolution and the collection of
77 -- interpretations for overloaded names, prior to overload resolution.
79 -- Name resolution is the process that establishes a mapping between source
80 -- identifiers and the entities they denote at each point in the program.
81 -- Each entity is represented by a defining occurrence. Each identifier
82 -- that denotes an entity points to the corresponding defining occurrence.
83 -- This is the entity of the applied occurrence. Each occurrence holds
84 -- an index into the names table, where source identifiers are stored.
86 -- Each entry in the names table for an identifier or designator uses the
87 -- Info pointer to hold a link to the currently visible entity that has
88 -- this name (see subprograms Get_Name_Entity_Id and Set_Name_Entity_Id
89 -- in package Sem_Util). The visibility is initialized at the beginning of
90 -- semantic processing to make entities in package Standard immediately
91 -- visible. The visibility table is used in a more subtle way when
92 -- compiling subunits (see below).
94 -- Entities that have the same name (i.e. homonyms) are chained. In the
95 -- case of overloaded entities, this chain holds all the possible meanings
96 -- of a given identifier. The process of overload resolution uses type
97 -- information to select from this chain the unique meaning of a given
100 -- Entities are also chained in their scope, through the Next_Entity link.
101 -- As a consequence, the name space is organized as a sparse matrix, where
102 -- each row corresponds to a scope, and each column to a source identifier.
103 -- Open scopes, that is to say scopes currently being compiled, have their
104 -- corresponding rows of entities in order, innermost scope first.
106 -- The scopes of packages that are mentioned in context clauses appear in
107 -- no particular order, interspersed among open scopes. This is because
108 -- in the course of analyzing the context of a compilation, a package
109 -- declaration is first an open scope, and subsequently an element of the
110 -- context. If subunits or child units are present, a parent unit may
111 -- appear under various guises at various times in the compilation.
113 -- When the compilation of the innermost scope is complete, the entities
114 -- defined therein are no longer visible. If the scope is not a package
115 -- declaration, these entities are never visible subsequently, and can be
116 -- removed from visibility chains. If the scope is a package declaration,
117 -- its visible declarations may still be accessible. Therefore the entities
118 -- defined in such a scope are left on the visibility chains, and only
119 -- their visibility (immediately visibility or potential use-visibility)
122 -- The ordering of homonyms on their chain does not necessarily follow
123 -- the order of their corresponding scopes on the scope stack. For
124 -- example, if package P and the enclosing scope both contain entities
125 -- named E, then when compiling the package body the chain for E will
126 -- hold the global entity first, and the local one (corresponding to
127 -- the current inner scope) next. As a result, name resolution routines
128 -- do not assume any relative ordering of the homonym chains, either
129 -- for scope nesting or to order of appearance of context clauses.
131 -- When compiling a child unit, entities in the parent scope are always
132 -- immediately visible. When compiling the body of a child unit, private
133 -- entities in the parent must also be made immediately visible. There
134 -- are separate routines to make the visible and private declarations
135 -- visible at various times (see package Sem_Ch7).
137 -- +--------+ +-----+
138 -- | In use |-------->| EU1 |-------------------------->
139 -- +--------+ +-----+
141 -- +--------+ +-----+ +-----+
142 -- | Stand. |---------------->| ES1 |--------------->| ES2 |--->
143 -- +--------+ +-----+ +-----+
145 -- +---------+ | +-----+
146 -- | with'ed |------------------------------>| EW2 |--->
147 -- +---------+ | +-----+
149 -- +--------+ +-----+ +-----+
150 -- | Scope2 |---------------->| E12 |--------------->| E22 |--->
151 -- +--------+ +-----+ +-----+
153 -- +--------+ +-----+ +-----+
154 -- | Scope1 |---------------->| E11 |--------------->| E12 |--->
155 -- +--------+ +-----+ +-----+
159 -- | | with'ed |----------------------------------------->
163 -- (innermost first) | |
164 -- +----------------------------+
165 -- Names table => | Id1 | | | | Id2 |
166 -- +----------------------------+
168 -- Name resolution must deal with several syntactic forms: simple names,
169 -- qualified names, indexed names, and various forms of calls.
171 -- Each identifier points to an entry in the names table. The resolution
172 -- of a simple name consists in traversing the homonym chain, starting
173 -- from the names table. If an entry is immediately visible, it is the one
174 -- designated by the identifier. If only potentially use-visible entities
175 -- are on the chain, we must verify that they do not hide each other. If
176 -- the entity we find is overloadable, we collect all other overloadable
177 -- entities on the chain as long as they are not hidden.
179 -- To resolve expanded names, we must find the entity at the intersection
180 -- of the entity chain for the scope (the prefix) and the homonym chain
181 -- for the selector. In general, homonym chains will be much shorter than
182 -- entity chains, so it is preferable to start from the names table as
183 -- well. If the entity found is overloadable, we must collect all other
184 -- interpretations that are defined in the scope denoted by the prefix.
186 -- For records, protected types, and tasks, their local entities are
187 -- removed from visibility chains on exit from the corresponding scope.
188 -- From the outside, these entities are always accessed by selected
189 -- notation, and the entity chain for the record type, protected type,
190 -- etc. is traversed sequentially in order to find the designated entity.
192 -- The discriminants of a type and the operations of a protected type or
193 -- task are unchained on exit from the first view of the type, (such as
194 -- a private or incomplete type declaration, or a protected type speci-
195 -- fication) and re-chained when compiling the second view.
197 -- In the case of operators, we do not make operators on derived types
198 -- explicit. As a result, the notation P."+" may denote either a user-
199 -- defined function with name "+", or else an implicit declaration of the
200 -- operator "+" in package P. The resolution of expanded names always
201 -- tries to resolve an operator name as such an implicitly defined entity,
202 -- in addition to looking for explicit declarations.
204 -- All forms of names that denote entities (simple names, expanded names,
205 -- character literals in some cases) have a Entity attribute, which
206 -- identifies the entity denoted by the name.
208 ---------------------
209 -- The Scope Stack --
210 ---------------------
212 -- The Scope stack keeps track of the scopes currently been compiled.
213 -- Every entity that contains declarations (including records) is placed
214 -- on the scope stack while it is being processed, and removed at the end.
215 -- Whenever a non-package scope is exited, the entities defined therein
216 -- are removed from the visibility table, so that entities in outer scopes
217 -- become visible (see previous description). On entry to Sem, the scope
218 -- stack only contains the package Standard. As usual, subunits complicate
219 -- this picture ever so slightly.
221 -- The Rtsfind mechanism can force a call to Semantics while another
222 -- compilation is in progress. The unit retrieved by Rtsfind must be
223 -- compiled in its own context, and has no access to the visibility of
224 -- the unit currently being compiled. The procedures Save_Scope_Stack and
225 -- Restore_Scope_Stack make entities in current open scopes invisible
226 -- before compiling the retrieved unit, and restore the compilation
227 -- environment afterwards.
229 ------------------------
230 -- Compiling subunits --
231 ------------------------
233 -- Subunits must be compiled in the environment of the corresponding stub,
234 -- that is to say with the same visibility into the parent (and its
235 -- context) that is available at the point of the stub declaration, but
236 -- with the additional visibility provided by the context clause of the
237 -- subunit itself. As a result, compilation of a subunit forces compilation
238 -- of the parent (see description in lib-). At the point of the stub
239 -- declaration, Analyze is called recursively to compile the proper body of
240 -- the subunit, but without reinitializing the names table, nor the scope
241 -- stack (i.e. standard is not pushed on the stack). In this fashion the
242 -- context of the subunit is added to the context of the parent, and the
243 -- subunit is compiled in the correct environment. Note that in the course
244 -- of processing the context of a subunit, Standard will appear twice on
245 -- the scope stack: once for the parent of the subunit, and once for the
246 -- unit in the context clause being compiled. However, the two sets of
247 -- entities are not linked by homonym chains, so that the compilation of
248 -- any context unit happens in a fresh visibility environment.
250 -------------------------------
251 -- Processing of USE Clauses --
252 -------------------------------
254 -- Every defining occurrence has a flag indicating if it is potentially use
255 -- visible. Resolution of simple names examines this flag. The processing
256 -- of use clauses consists in setting this flag on all visible entities
257 -- defined in the corresponding package. On exit from the scope of the use
258 -- clause, the corresponding flag must be reset. However, a package may
259 -- appear in several nested use clauses (pathological but legal, alas!)
260 -- which forces us to use a slightly more involved scheme:
262 -- a) The defining occurrence for a package holds a flag -In_Use- to
263 -- indicate that it is currently in the scope of a use clause. If a
264 -- redundant use clause is encountered, then the corresponding occurrence
265 -- of the package name is flagged -Redundant_Use-.
267 -- b) On exit from a scope, the use clauses in its declarative part are
268 -- scanned. The visibility flag is reset in all entities declared in
269 -- package named in a use clause, as long as the package is not flagged
270 -- as being in a redundant use clause (in which case the outer use
271 -- clause is still in effect, and the direct visibility of its entities
272 -- must be retained).
274 -- Note that entities are not removed from their homonym chains on exit
275 -- from the package specification. A subsequent use clause does not need
276 -- to rechain the visible entities, but only to establish their direct
279 -----------------------------------
280 -- Handling private declarations --
281 -----------------------------------
283 -- The principle that each entity has a single defining occurrence clashes
284 -- with the presence of two separate definitions for private types: the
285 -- first is the private type declaration, and second is the full type
286 -- declaration. It is important that all references to the type point to
287 -- the same defining occurrence, namely the first one. To enforce the two
288 -- separate views of the entity, the corresponding information is swapped
289 -- between the two declarations. Outside of the package, the defining
290 -- occurrence only contains the private declaration information, while in
291 -- the private part and the body of the package the defining occurrence
292 -- contains the full declaration. To simplify the swap, the defining
293 -- occurrence that currently holds the private declaration points to the
294 -- full declaration. During semantic processing the defining occurrence
295 -- also points to a list of private dependents, that is to say access types
296 -- or composite types whose designated types or component types are
297 -- subtypes or derived types of the private type in question. After the
298 -- full declaration has been seen, the private dependents are updated to
299 -- indicate that they have full definitions.
301 ------------------------------------
302 -- Handling of Undefined Messages --
303 ------------------------------------
305 -- In normal mode, only the first use of an undefined identifier generates
306 -- a message. The table Urefs is used to record error messages that have
307 -- been issued so that second and subsequent ones do not generate further
308 -- messages. However, the second reference causes text to be added to the
309 -- original undefined message noting "(more references follow)". The
310 -- full error list option (-gnatf) forces messages to be generated for
311 -- every reference and disconnects the use of this table.
313 type Uref_Entry is record
315 -- Node for identifier for which original message was posted. The
316 -- Chars field of this identifier is used to detect later references
317 -- to the same identifier.
320 -- Records error message Id of original undefined message. Reset to
321 -- No_Error_Msg after the second occurrence, where it is used to add
322 -- text to the original message as described above.
325 -- Set if the message is not visible rather than undefined
328 -- Records location of error message. Used to make sure that we do
329 -- not consider a, b : undefined as two separate instances, which
330 -- would otherwise happen, since the parser converts this sequence
331 -- to a : undefined; b : undefined.
335 package Urefs is new Table.Table (
336 Table_Component_Type => Uref_Entry,
337 Table_Index_Type => Nat,
338 Table_Low_Bound => 1,
340 Table_Increment => 100,
341 Table_Name => "Urefs");
343 Candidate_Renaming : Entity_Id;
344 -- Holds a candidate interpretation that appears in a subprogram renaming
345 -- declaration and does not match the given specification, but matches at
346 -- least on the first formal. Allows better error message when given
347 -- specification omits defaulted parameters, a common error.
349 -----------------------
350 -- Local Subprograms --
351 -----------------------
353 procedure Analyze_Generic_Renaming
356 -- Common processing for all three kinds of generic renaming declarations.
357 -- Enter new name and indicate that it renames the generic unit.
359 procedure Analyze_Renamed_Character
363 -- Renamed entity is given by a character literal, which must belong
364 -- to the return type of the new entity. Is_Body indicates whether the
365 -- declaration is a renaming_as_body. If the original declaration has
366 -- already been frozen (because of an intervening body, e.g.) the body of
367 -- the function must be built now. The same applies to the following
368 -- various renaming procedures.
370 procedure Analyze_Renamed_Dereference
374 -- Renamed entity is given by an explicit dereference. Prefix must be a
375 -- conformant access_to_subprogram type.
377 procedure Analyze_Renamed_Entry
381 -- If the renamed entity in a subprogram renaming is an entry or protected
382 -- subprogram, build a body for the new entity whose only statement is a
383 -- call to the renamed entity.
385 procedure Analyze_Renamed_Family_Member
389 -- Used when the renamed entity is an indexed component. The prefix must
390 -- denote an entry family.
392 function Applicable_Use (Pack_Name : Node_Id) return Boolean;
393 -- Common code to Use_One_Package and Set_Use, to determine whether
394 -- use clause must be processed. Pack_Name is an entity name that
395 -- references the package in question.
397 procedure Attribute_Renaming (N : Node_Id);
398 -- Analyze renaming of attribute as function. The renaming declaration N
399 -- is rewritten as a function body that returns the attribute reference
400 -- applied to the formals of the function.
402 procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id);
403 -- A renaming_as_body may occur after the entity of the original decla-
404 -- ration has been frozen. In that case, the body of the new entity must
405 -- be built now, because the usual mechanism of building the renamed
406 -- body at the point of freezing will not work. Subp is the subprogram
407 -- for which N provides the Renaming_As_Body.
409 procedure Check_In_Previous_With_Clause
412 -- N is a use_package clause and Nam the package name, or N is a use_type
413 -- clause and Nam is the prefix of the type name. In either case, verify
414 -- that the package is visible at that point in the context: either it
415 -- appears in a previous with_clause, or because it is a fully qualified
416 -- name and the root ancestor appears in a previous with_clause.
418 procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id);
419 -- Verify that the entity in a renaming declaration that is a library unit
420 -- is itself a library unit and not a nested unit or subunit. Also check
421 -- that if the renaming is a child unit of a generic parent, then the
422 -- renamed unit must also be a child unit of that parent. Finally, verify
423 -- that a renamed generic unit is not an implicit child declared within
424 -- an instance of the parent.
426 procedure Chain_Use_Clause (N : Node_Id);
427 -- Chain use clause onto list of uses clauses headed by First_Use_Clause in
428 -- the proper scope table entry. This is usually the current scope, but it
429 -- will be an inner scope when installing the use clauses of the private
430 -- declarations of a parent unit prior to compiling the private part of a
431 -- child unit. This chain is traversed when installing/removing use clauses
432 -- when compiling a subunit or instantiating a generic body on the fly,
433 -- when it is necessary to save and restore full environments.
435 function Has_Implicit_Character_Literal (N : Node_Id) return Boolean;
436 -- Find a type derived from Character or Wide_Character in the prefix of N.
437 -- Used to resolved qualified names whose selector is a character literal.
439 function Has_Private_With (E : Entity_Id) return Boolean;
440 -- Ada 2005 (AI-262): Determines if the current compilation unit has a
441 -- private with on E.
443 procedure Find_Expanded_Name (N : Node_Id);
444 -- Selected component is known to be expanded name. Verify legality
445 -- of selector given the scope denoted by prefix.
447 function Find_Renamed_Entity
451 Is_Actual : Boolean := False) return Entity_Id;
452 -- Find the renamed entity that corresponds to the given parameter profile
453 -- in a subprogram renaming declaration. The renamed entity may be an
454 -- operator, a subprogram, an entry, or a protected operation. Is_Actual
455 -- indicates that the renaming is the one generated for an actual subpro-
456 -- gram in an instance, for which special visibility checks apply.
458 function Has_Implicit_Operator (N : Node_Id) return Boolean;
459 -- N is an expanded name whose selector is an operator name (eg P."+").
460 -- declarative part contains an implicit declaration of an operator if it
461 -- has a declaration of a type to which one of the predefined operators
462 -- apply. The existence of this routine is an implementation artifact. A
463 -- more straightforward but more space-consuming choice would be to make
464 -- all inherited operators explicit in the symbol table.
466 procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id);
467 -- A subprogram defined by a renaming declaration inherits the parameter
468 -- profile of the renamed entity. The subtypes given in the subprogram
469 -- specification are discarded and replaced with those of the renamed
470 -- subprogram, which are then used to recheck the default values.
472 function Is_Appropriate_For_Record (T : Entity_Id) return Boolean;
473 -- Prefix is appropriate for record if it is of a record type, or an access
476 function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean;
477 -- True if it is of a task type, a protected type, or else an access to one
480 procedure Note_Redundant_Use (Clause : Node_Id);
481 -- Mark the name in a use clause as redundant if the corresponding entity
482 -- is already use-visible. Emit a warning if the use clause comes from
483 -- source and the proper warnings are enabled.
485 procedure Premature_Usage (N : Node_Id);
486 -- Diagnose usage of an entity before it is visible
488 procedure Use_One_Package (P : Entity_Id; N : Node_Id);
489 -- Make visible entities declared in package P potentially use-visible
490 -- in the current context. Also used in the analysis of subunits, when
491 -- re-installing use clauses of parent units. N is the use_clause that
492 -- names P (and possibly other packages).
494 procedure Use_One_Type (Id : Node_Id);
495 -- Id is the subtype mark from a use type clause. This procedure makes
496 -- the primitive operators of the type potentially use-visible.
498 procedure Write_Info;
499 -- Write debugging information on entities declared in current scope
501 procedure Write_Scopes;
502 pragma Warnings (Off, Write_Scopes);
503 -- Debugging information: dump all entities on scope stack
505 --------------------------------
506 -- Analyze_Exception_Renaming --
507 --------------------------------
509 -- The language only allows a single identifier, but the tree holds an
510 -- identifier list. The parser has already issued an error message if
511 -- there is more than one element in the list.
513 procedure Analyze_Exception_Renaming (N : Node_Id) is
514 Id : constant Node_Id := Defining_Identifier (N);
515 Nam : constant Node_Id := Name (N);
521 Set_Ekind (Id, E_Exception);
522 Set_Exception_Code (Id, Uint_0);
523 Set_Etype (Id, Standard_Exception_Type);
524 Set_Is_Pure (Id, Is_Pure (Current_Scope));
526 if not Is_Entity_Name (Nam) or else
527 Ekind (Entity (Nam)) /= E_Exception
529 Error_Msg_N ("invalid exception name in renaming", Nam);
531 if Present (Renamed_Object (Entity (Nam))) then
532 Set_Renamed_Object (Id, Renamed_Object (Entity (Nam)));
534 Set_Renamed_Object (Id, Entity (Nam));
537 end Analyze_Exception_Renaming;
539 ---------------------------
540 -- Analyze_Expanded_Name --
541 ---------------------------
543 procedure Analyze_Expanded_Name (N : Node_Id) is
545 -- If the entity pointer is already set, this is an internal node, or a
546 -- node that is analyzed more than once, after a tree modification. In
547 -- such a case there is no resolution to perform, just set the type. For
548 -- completeness, analyze prefix as well.
550 if Present (Entity (N)) then
551 if Is_Type (Entity (N)) then
552 Set_Etype (N, Entity (N));
554 Set_Etype (N, Etype (Entity (N)));
557 Analyze (Prefix (N));
560 Find_Expanded_Name (N);
562 end Analyze_Expanded_Name;
564 ---------------------------------------
565 -- Analyze_Generic_Function_Renaming --
566 ---------------------------------------
568 procedure Analyze_Generic_Function_Renaming (N : Node_Id) is
570 Analyze_Generic_Renaming (N, E_Generic_Function);
571 end Analyze_Generic_Function_Renaming;
573 --------------------------------------
574 -- Analyze_Generic_Package_Renaming --
575 --------------------------------------
577 procedure Analyze_Generic_Package_Renaming (N : Node_Id) is
579 -- Apply the Text_IO Kludge here, since we may be renaming one of the
580 -- subpackages of Text_IO, then join common routine.
582 Text_IO_Kludge (Name (N));
584 Analyze_Generic_Renaming (N, E_Generic_Package);
585 end Analyze_Generic_Package_Renaming;
587 ----------------------------------------
588 -- Analyze_Generic_Procedure_Renaming --
589 ----------------------------------------
591 procedure Analyze_Generic_Procedure_Renaming (N : Node_Id) is
593 Analyze_Generic_Renaming (N, E_Generic_Procedure);
594 end Analyze_Generic_Procedure_Renaming;
596 ------------------------------
597 -- Analyze_Generic_Renaming --
598 ------------------------------
600 procedure Analyze_Generic_Renaming
604 New_P : constant Entity_Id := Defining_Entity (N);
606 Inst : Boolean := False; -- prevent junk warning
609 if Name (N) = Error then
613 Generate_Definition (New_P);
615 if Current_Scope /= Standard_Standard then
616 Set_Is_Pure (New_P, Is_Pure (Current_Scope));
619 if Nkind (Name (N)) = N_Selected_Component then
620 Check_Generic_Child_Unit (Name (N), Inst);
625 if not Is_Entity_Name (Name (N)) then
626 Error_Msg_N ("expect entity name in renaming declaration", Name (N));
629 Old_P := Entity (Name (N));
633 Set_Ekind (New_P, K);
635 if Etype (Old_P) = Any_Type then
638 elsif Ekind (Old_P) /= K then
639 Error_Msg_N ("invalid generic unit name", Name (N));
642 if Present (Renamed_Object (Old_P)) then
643 Set_Renamed_Object (New_P, Renamed_Object (Old_P));
645 Set_Renamed_Object (New_P, Old_P);
648 Set_Is_Pure (New_P, Is_Pure (Old_P));
649 Set_Is_Preelaborated (New_P, Is_Preelaborated (Old_P));
651 Set_Etype (New_P, Etype (Old_P));
652 Set_Has_Completion (New_P);
654 if In_Open_Scopes (Old_P) then
655 Error_Msg_N ("within its scope, generic denotes its instance", N);
658 Check_Library_Unit_Renaming (N, Old_P);
660 end Analyze_Generic_Renaming;
662 -----------------------------
663 -- Analyze_Object_Renaming --
664 -----------------------------
666 procedure Analyze_Object_Renaming (N : Node_Id) is
667 Id : constant Entity_Id := Defining_Identifier (N);
669 Nam : constant Node_Id := Name (N);
673 function In_Generic_Scope (E : Entity_Id) return Boolean;
674 -- Determine whether entity E is inside a generic cope
676 ----------------------
677 -- In_Generic_Scope --
678 ----------------------
680 function In_Generic_Scope (E : Entity_Id) return Boolean is
685 while Present (S) and then S /= Standard_Standard loop
686 if Is_Generic_Unit (S) then
694 end In_Generic_Scope;
696 -- Start of processing for Analyze_Object_Renaming
703 Set_Is_Pure (Id, Is_Pure (Current_Scope));
706 -- The renaming of a component that depends on a discriminant requires
707 -- an actual subtype, because in subsequent use of the object Gigi will
708 -- be unable to locate the actual bounds. This explicit step is required
709 -- when the renaming is generated in removing side effects of an
710 -- already-analyzed expression.
712 if Nkind (Nam) = N_Selected_Component
713 and then Analyzed (Nam)
716 Dec := Build_Actual_Subtype_Of_Component (Etype (Nam), Nam);
718 if Present (Dec) then
719 Insert_Action (N, Dec);
720 T := Defining_Identifier (Dec);
724 elsif Present (Subtype_Mark (N)) then
725 Find_Type (Subtype_Mark (N));
726 T := Entity (Subtype_Mark (N));
727 Analyze_And_Resolve (Nam, T);
729 -- Ada 2005 (AI-230/AI-254): Access renaming
731 else pragma Assert (Present (Access_Definition (N)));
732 T := Access_Definition
734 N => Access_Definition (N));
736 Analyze_And_Resolve (Nam, T);
738 -- Ada 2005 (AI-231): "In the case where the type is defined by an
739 -- access_definition, the renamed entity shall be of an access-to-
740 -- constant type if and only if the access_definition defines an
741 -- access-to-constant type" ARM 8.5.1(4)
743 if Constant_Present (Access_Definition (N))
744 and then not Is_Access_Constant (Etype (Nam))
746 Error_Msg_N ("(Ada 2005): the renamed object is not "
747 & "access-to-constant ('R'M 8.5.1(6))", N);
751 -- An object renaming requires an exact match of the type. Class-wide
752 -- matching is not allowed.
754 if Is_Class_Wide_Type (T)
755 and then Base_Type (Etype (Nam)) /= Base_Type (T)
762 -- (Ada 2005: AI-326): Handle wrong use of incomplete type
764 if Nkind (Nam) = N_Explicit_Dereference
765 and then Ekind (Etype (T2)) = E_Incomplete_Type
767 Error_Msg_N ("invalid use of incomplete type", Id);
773 if Ada_Version >= Ada_05
774 and then Nkind (Nam) = N_Attribute_Reference
775 and then Attribute_Name (Nam) = Name_Priority
779 elsif Ada_Version >= Ada_05
780 and then Nkind (Nam) in N_Has_Entity
783 Error_Node : Node_Id;
786 Subtyp_Decl : Node_Id;
789 if Nkind (Nam) = N_Attribute_Reference then
790 Nam_Ent := Entity (Prefix (Nam));
792 Nam_Ent := Entity (Nam);
795 Nam_Decl := Parent (Nam_Ent);
796 Subtyp_Decl := Parent (Etype (Nam_Ent));
798 if Has_Null_Exclusion (N)
799 and then not Has_Null_Exclusion (Nam_Decl)
801 -- Ada 2005 (AI-423): If the object name denotes a generic
802 -- formal object of a generic unit G, and the object renaming
803 -- declaration occurs within the body of G or within the body
804 -- of a generic unit declared within the declarative region
805 -- of G, then the declaration of the formal object of G shall
806 -- have a null exclusion.
808 if Is_Formal_Object (Nam_Ent)
809 and then In_Generic_Scope (Id)
811 if Present (Subtype_Mark (Nam_Decl)) then
812 Error_Node := Subtype_Mark (Nam_Decl);
815 (Ada_Version >= Ada_05
816 and then Present (Access_Definition (Nam_Decl)));
818 Error_Node := Access_Definition (Nam_Decl);
821 Error_Msg_N ("null-exclusion required in formal " &
822 "object declaration", Error_Node);
824 -- Ada 2005 (AI-423): Otherwise, the subtype of the object name
825 -- shall exclude null.
827 elsif Nkind (Subtyp_Decl) = N_Subtype_Declaration
828 and then not Has_Null_Exclusion (Subtyp_Decl)
830 Error_Msg_N ("subtype must have null-exclusion",
837 Set_Ekind (Id, E_Variable);
838 Init_Size_Align (Id);
840 if T = Any_Type or else Etype (Nam) = Any_Type then
843 -- Verify that the renamed entity is an object or a function call. It
844 -- may have been rewritten in several ways.
846 elsif Is_Object_Reference (Nam) then
847 if Comes_From_Source (N)
848 and then Is_Dependent_Component_Of_Mutable_Object (Nam)
851 ("illegal renaming of discriminant-dependent component", Nam);
856 -- A static function call may have been folded into a literal
858 elsif Nkind (Original_Node (Nam)) = N_Function_Call
860 -- When expansion is disabled, attribute reference is not
861 -- rewritten as function call. Otherwise it may be rewritten
862 -- as a conversion, so check original node.
864 or else (Nkind (Original_Node (Nam)) = N_Attribute_Reference
865 and then Is_Function_Attribute_Name
866 (Attribute_Name (Original_Node (Nam))))
868 -- Weird but legal, equivalent to renaming a function call.
869 -- Illegal if the literal is the result of constant-folding an
870 -- attribute reference that is not a function.
872 or else (Is_Entity_Name (Nam)
873 and then Ekind (Entity (Nam)) = E_Enumeration_Literal
875 Nkind (Original_Node (Nam)) /= N_Attribute_Reference)
877 or else (Nkind (Nam) = N_Type_Conversion
878 and then Is_Tagged_Type (Entity (Subtype_Mark (Nam))))
882 elsif Nkind (Nam) = N_Type_Conversion then
884 ("renaming of conversion only allowed for tagged types", Nam);
888 elsif Ada_Version >= Ada_05
889 and then Nkind (Nam) = N_Attribute_Reference
890 and then Attribute_Name (Nam) = Name_Priority
895 Error_Msg_N ("expect object name in renaming", Nam);
900 if not Is_Variable (Nam) then
901 Set_Ekind (Id, E_Constant);
902 Set_Never_Set_In_Source (Id, True);
903 Set_Is_True_Constant (Id, True);
906 Set_Renamed_Object (Id, Nam);
907 end Analyze_Object_Renaming;
909 ------------------------------
910 -- Analyze_Package_Renaming --
911 ------------------------------
913 procedure Analyze_Package_Renaming (N : Node_Id) is
914 New_P : constant Entity_Id := Defining_Entity (N);
919 if Name (N) = Error then
923 -- Apply Text_IO kludge here, since we may be renaming one of the
924 -- children of Text_IO
926 Text_IO_Kludge (Name (N));
928 if Current_Scope /= Standard_Standard then
929 Set_Is_Pure (New_P, Is_Pure (Current_Scope));
935 if Is_Entity_Name (Name (N)) then
936 Old_P := Entity (Name (N));
941 if Etype (Old_P) = Any_Type then
943 ("expect package name in renaming", Name (N));
945 elsif Ekind (Old_P) /= E_Package
946 and then not (Ekind (Old_P) = E_Generic_Package
947 and then In_Open_Scopes (Old_P))
949 if Ekind (Old_P) = E_Generic_Package then
951 ("generic package cannot be renamed as a package", Name (N));
953 Error_Msg_Sloc := Sloc (Old_P);
955 ("expect package name in renaming, found& declared#",
959 -- Set basic attributes to minimize cascaded errors
961 Set_Ekind (New_P, E_Package);
962 Set_Etype (New_P, Standard_Void_Type);
965 -- Entities in the old package are accessible through the renaming
966 -- entity. The simplest implementation is to have both packages share
969 Set_Ekind (New_P, E_Package);
970 Set_Etype (New_P, Standard_Void_Type);
972 if Present (Renamed_Object (Old_P)) then
973 Set_Renamed_Object (New_P, Renamed_Object (Old_P));
975 Set_Renamed_Object (New_P, Old_P);
978 Set_Has_Completion (New_P);
980 Set_First_Entity (New_P, First_Entity (Old_P));
981 Set_Last_Entity (New_P, Last_Entity (Old_P));
982 Set_First_Private_Entity (New_P, First_Private_Entity (Old_P));
983 Check_Library_Unit_Renaming (N, Old_P);
984 Generate_Reference (Old_P, Name (N));
986 -- If this is the renaming declaration of a package instantiation
987 -- within itself, it is the declaration that ends the list of actuals
988 -- for the instantiation. At this point, the subtypes that rename
989 -- the actuals are flagged as generic, to avoid spurious ambiguities
990 -- if the actuals for two distinct formals happen to coincide. If
991 -- the actual is a private type, the subtype has a private completion
992 -- that is flagged in the same fashion.
994 -- Resolution is identical to what is was in the original generic.
995 -- On exit from the generic instance, these are turned into regular
996 -- subtypes again, so they are compatible with types in their class.
998 if not Is_Generic_Instance (Old_P) then
1001 Spec := Specification (Unit_Declaration_Node (Old_P));
1004 if Nkind (Spec) = N_Package_Specification
1005 and then Present (Generic_Parent (Spec))
1006 and then Old_P = Current_Scope
1007 and then Chars (New_P) = Chars (Generic_Parent (Spec))
1013 E := First_Entity (Old_P);
1018 and then Nkind (Parent (E)) = N_Subtype_Declaration
1020 Set_Is_Generic_Actual_Type (E);
1022 if Is_Private_Type (E)
1023 and then Present (Full_View (E))
1025 Set_Is_Generic_Actual_Type (Full_View (E));
1035 end Analyze_Package_Renaming;
1037 -------------------------------
1038 -- Analyze_Renamed_Character --
1039 -------------------------------
1041 procedure Analyze_Renamed_Character
1046 C : constant Node_Id := Name (N);
1049 if Ekind (New_S) = E_Function then
1050 Resolve (C, Etype (New_S));
1053 Check_Frozen_Renaming (N, New_S);
1057 Error_Msg_N ("character literal can only be renamed as function", N);
1059 end Analyze_Renamed_Character;
1061 ---------------------------------
1062 -- Analyze_Renamed_Dereference --
1063 ---------------------------------
1065 procedure Analyze_Renamed_Dereference
1070 Nam : constant Node_Id := Name (N);
1071 P : constant Node_Id := Prefix (Nam);
1077 if not Is_Overloaded (P) then
1078 if Ekind (Etype (Nam)) /= E_Subprogram_Type
1079 or else not Type_Conformant (Etype (Nam), New_S) then
1080 Error_Msg_N ("designated type does not match specification", P);
1089 Get_First_Interp (Nam, Ind, It);
1091 while Present (It.Nam) loop
1093 if Ekind (It.Nam) = E_Subprogram_Type
1094 and then Type_Conformant (It.Nam, New_S) then
1096 if Typ /= Any_Id then
1097 Error_Msg_N ("ambiguous renaming", P);
1104 Get_Next_Interp (Ind, It);
1107 if Typ = Any_Type then
1108 Error_Msg_N ("designated type does not match specification", P);
1113 Check_Frozen_Renaming (N, New_S);
1117 end Analyze_Renamed_Dereference;
1119 ---------------------------
1120 -- Analyze_Renamed_Entry --
1121 ---------------------------
1123 procedure Analyze_Renamed_Entry
1128 Nam : constant Node_Id := Name (N);
1129 Sel : constant Node_Id := Selector_Name (Nam);
1133 if Entity (Sel) = Any_Id then
1135 -- Selector is undefined on prefix. Error emitted already
1137 Set_Has_Completion (New_S);
1141 -- Otherwise find renamed entity and build body of New_S as a call to it
1143 Old_S := Find_Renamed_Entity (N, Selector_Name (Nam), New_S);
1145 if Old_S = Any_Id then
1146 Error_Msg_N (" no subprogram or entry matches specification", N);
1149 Check_Subtype_Conformant (New_S, Old_S, N);
1150 Generate_Reference (New_S, Defining_Entity (N), 'b');
1151 Style.Check_Identifier (Defining_Entity (N), New_S);
1154 -- Only mode conformance required for a renaming_as_declaration
1156 Check_Mode_Conformant (New_S, Old_S, N);
1159 Inherit_Renamed_Profile (New_S, Old_S);
1162 Set_Convention (New_S, Convention (Old_S));
1163 Set_Has_Completion (New_S, Inside_A_Generic);
1166 Check_Frozen_Renaming (N, New_S);
1168 end Analyze_Renamed_Entry;
1170 -----------------------------------
1171 -- Analyze_Renamed_Family_Member --
1172 -----------------------------------
1174 procedure Analyze_Renamed_Family_Member
1179 Nam : constant Node_Id := Name (N);
1180 P : constant Node_Id := Prefix (Nam);
1184 if (Is_Entity_Name (P) and then Ekind (Entity (P)) = E_Entry_Family)
1185 or else (Nkind (P) = N_Selected_Component
1187 Ekind (Entity (Selector_Name (P))) = E_Entry_Family)
1189 if Is_Entity_Name (P) then
1190 Old_S := Entity (P);
1192 Old_S := Entity (Selector_Name (P));
1195 if not Entity_Matches_Spec (Old_S, New_S) then
1196 Error_Msg_N ("entry family does not match specification", N);
1199 Check_Subtype_Conformant (New_S, Old_S, N);
1200 Generate_Reference (New_S, Defining_Entity (N), 'b');
1201 Style.Check_Identifier (Defining_Entity (N), New_S);
1205 Error_Msg_N ("no entry family matches specification", N);
1208 Set_Has_Completion (New_S, Inside_A_Generic);
1211 Check_Frozen_Renaming (N, New_S);
1213 end Analyze_Renamed_Family_Member;
1215 ---------------------------------
1216 -- Analyze_Subprogram_Renaming --
1217 ---------------------------------
1219 procedure Analyze_Subprogram_Renaming (N : Node_Id) is
1220 Formal_Spec : constant Node_Id := Corresponding_Formal_Spec (N);
1221 Is_Actual : constant Boolean := Present (Formal_Spec);
1222 Inst_Node : Node_Id := Empty;
1223 Nam : constant Node_Id := Name (N);
1225 Old_S : Entity_Id := Empty;
1226 Rename_Spec : Entity_Id;
1227 Save_AV : constant Ada_Version_Type := Ada_Version;
1228 Save_AV_Exp : constant Ada_Version_Type := Ada_Version_Explicit;
1229 Spec : constant Node_Id := Specification (N);
1231 procedure Check_Null_Exclusion
1234 -- Ada 2005 (AI-423): Given renaming Ren of subprogram Sub, check the
1235 -- following AI rules:
1237 -- If Ren is a renaming of a formal subprogram and one of its
1238 -- parameters has a null exclusion, then the corresponding formal
1239 -- in Sub must also have one. Otherwise the subtype of the Sub's
1240 -- formal parameter must exclude null.
1242 -- If Ren is a renaming of a formal function and its retrun
1243 -- profile has a null exclusion, then Sub's return profile must
1244 -- have one. Otherwise the subtype of Sub's return profile must
1247 function Original_Subprogram (Subp : Entity_Id) return Entity_Id;
1248 -- Find renamed entity when the declaration is a renaming_as_body and
1249 -- the renamed entity may itself be a renaming_as_body. Used to enforce
1250 -- rule that a renaming_as_body is illegal if the declaration occurs
1251 -- before the subprogram it completes is frozen, and renaming indirectly
1252 -- renames the subprogram itself.(Defect Report 8652/0027).
1254 --------------------------
1255 -- Check_Null_Exclusion --
1256 --------------------------
1258 procedure Check_Null_Exclusion
1262 Ren_Formal : Entity_Id;
1263 Sub_Formal : Entity_Id;
1268 Ren_Formal := First_Formal (Ren);
1269 Sub_Formal := First_Formal (Sub);
1270 while Present (Ren_Formal)
1271 and then Present (Sub_Formal)
1273 if Has_Null_Exclusion (Parent (Ren_Formal))
1275 not (Has_Null_Exclusion (Parent (Sub_Formal))
1276 or else Can_Never_Be_Null (Etype (Sub_Formal)))
1278 Error_Msg_N ("null-exclusion required in parameter profile",
1279 Parent (Sub_Formal));
1282 Next_Formal (Ren_Formal);
1283 Next_Formal (Sub_Formal);
1286 -- Return profile check
1288 if Nkind (Parent (Ren)) = N_Function_Specification
1289 and then Nkind (Parent (Sub)) = N_Function_Specification
1290 and then Has_Null_Exclusion (Parent (Ren))
1292 not (Has_Null_Exclusion (Parent (Sub))
1293 or else Can_Never_Be_Null (Etype (Sub)))
1295 Error_Msg_N ("null-exclusion required in return profile",
1296 Result_Definition (Parent (Sub)));
1298 end Check_Null_Exclusion;
1300 -------------------------
1301 -- Original_Subprogram --
1302 -------------------------
1304 function Original_Subprogram (Subp : Entity_Id) return Entity_Id is
1305 Orig_Decl : Node_Id;
1306 Orig_Subp : Entity_Id;
1309 -- First case: renamed entity is itself a renaming
1311 if Present (Alias (Subp)) then
1312 return Alias (Subp);
1315 Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration
1317 (Corresponding_Body (Unit_Declaration_Node (Subp)))
1319 -- Check if renamed entity is a renaming_as_body
1322 Unit_Declaration_Node
1323 (Corresponding_Body (Unit_Declaration_Node (Subp)));
1325 if Nkind (Orig_Decl) = N_Subprogram_Renaming_Declaration then
1326 Orig_Subp := Entity (Name (Orig_Decl));
1328 if Orig_Subp = Rename_Spec then
1330 -- Circularity detected
1335 return (Original_Subprogram (Orig_Subp));
1343 end Original_Subprogram;
1345 -- Start of processing for Analyze_Subprogram_Renaming
1348 -- We must test for the attribute renaming case before the Analyze
1349 -- call because otherwise Sem_Attr will complain that the attribute
1350 -- is missing an argument when it is analyzed.
1352 if Nkind (Nam) = N_Attribute_Reference then
1354 -- In the case of an abstract formal subprogram association, rewrite
1355 -- an actual given by a stream attribute as the name of the
1356 -- corresponding stream primitive of the type.
1358 -- In a generic context the stream operations are not generated, and
1359 -- this must be treated as a normal attribute reference, to be
1360 -- expanded in subsequent instantiations.
1362 if Is_Actual and then Is_Abstract_Subprogram (Formal_Spec)
1363 and then Expander_Active
1366 Stream_Prim : Entity_Id;
1367 Prefix_Type : constant Entity_Id := Entity (Prefix (Nam));
1370 -- The class-wide forms of the stream attributes are not
1371 -- primitive dispatching operations (even though they
1372 -- internally dispatch to a stream attribute).
1374 if Is_Class_Wide_Type (Prefix_Type) then
1376 ("attribute must be a primitive dispatching operation",
1381 -- Retrieve the primitive subprogram associated with the
1382 -- attribute. This can only be a stream attribute, since those
1383 -- are the only ones that are dispatching (and the actual for
1384 -- an abstract formal subprogram must be dispatching
1387 case Attribute_Name (Nam) is
1390 Find_Prim_Op (Prefix_Type, TSS_Stream_Input);
1393 Find_Prim_Op (Prefix_Type, TSS_Stream_Output);
1396 Find_Prim_Op (Prefix_Type, TSS_Stream_Read);
1399 Find_Prim_Op (Prefix_Type, TSS_Stream_Write);
1402 ("attribute must be a primitive dispatching operation",
1407 -- Rewrite the attribute into the name of its corresponding
1408 -- primitive dispatching subprogram. We can then proceed with
1409 -- the usual processing for subprogram renamings.
1412 Prim_Name : constant Node_Id :=
1413 Make_Identifier (Sloc (Nam),
1414 Chars => Chars (Stream_Prim));
1416 Set_Entity (Prim_Name, Stream_Prim);
1417 Rewrite (Nam, Prim_Name);
1422 -- Normal processing for a renaming of an attribute
1425 Attribute_Renaming (N);
1430 -- Check whether this declaration corresponds to the instantiation
1431 -- of a formal subprogram.
1433 -- If this is an instantiation, the corresponding actual is frozen and
1434 -- error messages can be made more precise. If this is a default
1435 -- subprogram, the entity is already established in the generic, and is
1436 -- not retrieved by visibility. If it is a default with a box, the
1437 -- candidate interpretations, if any, have been collected when building
1438 -- the renaming declaration. If overloaded, the proper interpretation is
1439 -- determined in Find_Renamed_Entity. If the entity is an operator,
1440 -- Find_Renamed_Entity applies additional visibility checks.
1443 Inst_Node := Unit_Declaration_Node (Formal_Spec);
1445 if Is_Entity_Name (Nam)
1446 and then Present (Entity (Nam))
1447 and then not Comes_From_Source (Nam)
1448 and then not Is_Overloaded (Nam)
1450 Old_S := Entity (Nam);
1451 New_S := Analyze_Subprogram_Specification (Spec);
1455 if Ekind (Entity (Nam)) = E_Operator then
1459 if Box_Present (Inst_Node) then
1460 Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
1462 -- If there is an immediately visible homonym of the operator
1463 -- and the declaration has a default, this is worth a warning
1464 -- because the user probably did not intend to get the pre-
1465 -- defined operator, visible in the generic declaration. To
1466 -- find if there is an intended candidate, analyze the renaming
1467 -- again in the current context.
1469 elsif Scope (Old_S) = Standard_Standard
1470 and then Present (Default_Name (Inst_Node))
1473 Decl : constant Node_Id := New_Copy_Tree (N);
1477 Set_Entity (Name (Decl), Empty);
1478 Analyze (Name (Decl));
1480 Find_Renamed_Entity (Decl, Name (Decl), New_S, True);
1483 and then In_Open_Scopes (Scope (Hidden))
1484 and then Is_Immediately_Visible (Hidden)
1485 and then Comes_From_Source (Hidden)
1486 and then Hidden /= Old_S
1488 Error_Msg_Sloc := Sloc (Hidden);
1489 Error_Msg_N ("?default subprogram is resolved " &
1490 "in the generic declaration " &
1491 "('R'M 12.6(17))", N);
1492 Error_Msg_NE ("\?and will not use & #", N, Hidden);
1500 New_S := Analyze_Subprogram_Specification (Spec);
1504 -- Renamed entity must be analyzed first, to avoid being hidden by
1505 -- new name (which might be the same in a generic instance).
1509 -- The renaming defines a new overloaded entity, which is analyzed
1510 -- like a subprogram declaration.
1512 New_S := Analyze_Subprogram_Specification (Spec);
1515 if Current_Scope /= Standard_Standard then
1516 Set_Is_Pure (New_S, Is_Pure (Current_Scope));
1519 Rename_Spec := Find_Corresponding_Spec (N);
1521 if Present (Rename_Spec) then
1523 -- Renaming_As_Body. Renaming declaration is the completion of
1524 -- the declaration of Rename_Spec. We will build an actual body
1525 -- for it at the freezing point.
1527 Set_Corresponding_Spec (N, Rename_Spec);
1528 if Nkind (Unit_Declaration_Node (Rename_Spec)) =
1529 N_Abstract_Subprogram_Declaration
1531 -- Input and Output stream functions are abstract if the object
1532 -- type is abstract. However, these functions may receive explicit
1533 -- declarations in representation clauses, making the attribute
1534 -- subprograms usable as defaults in subsequent type extensions.
1535 -- In this case we rewrite the declaration to make the subprogram
1536 -- non-abstract. We remove the previous declaration, and insert
1537 -- the new one at the point of the renaming, to prevent premature
1538 -- access to unfrozen types. The new declaration reuses the
1539 -- specification of the previous one, and must not be analyzed.
1541 pragma Assert (Is_TSS (Rename_Spec, TSS_Stream_Output)
1542 or else Is_TSS (Rename_Spec, TSS_Stream_Input));
1545 Old_Decl : constant Node_Id :=
1546 Unit_Declaration_Node (Rename_Spec);
1547 New_Decl : constant Node_Id :=
1548 Make_Subprogram_Declaration (Sloc (N),
1550 Relocate_Node (Specification (Old_Decl)));
1553 Insert_After (N, New_Decl);
1554 Set_Is_Abstract_Subprogram (Rename_Spec, False);
1555 Set_Analyzed (New_Decl);
1559 Set_Corresponding_Body (Unit_Declaration_Node (Rename_Spec), New_S);
1561 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
1562 Error_Msg_N ("(Ada 83) renaming cannot serve as a body", N);
1565 Set_Convention (New_S, Convention (Rename_Spec));
1566 Check_Fully_Conformant (New_S, Rename_Spec);
1567 Set_Public_Status (New_S);
1569 -- Indicate that the entity in the declaration functions like the
1570 -- corresponding body, and is not a new entity. The body will be
1571 -- constructed later at the freeze point, so indicate that the
1572 -- completion has not been seen yet.
1574 Set_Ekind (New_S, E_Subprogram_Body);
1575 New_S := Rename_Spec;
1576 Set_Has_Completion (Rename_Spec, False);
1578 -- Ada 2005: check overriding indicator
1580 if Must_Override (Specification (N))
1581 and then not Is_Overriding_Operation (Rename_Spec)
1583 Error_Msg_NE ("subprogram& is not overriding", N, Rename_Spec);
1585 elsif Must_Not_Override (Specification (N))
1586 and then Is_Overriding_Operation (Rename_Spec)
1589 ("subprogram& overrides inherited operation", N, Rename_Spec);
1593 Generate_Definition (New_S);
1594 New_Overloaded_Entity (New_S);
1596 if Is_Entity_Name (Nam)
1597 and then Is_Intrinsic_Subprogram (Entity (Nam))
1601 Check_Delayed_Subprogram (New_S);
1605 -- There is no need for elaboration checks on the new entity, which may
1606 -- be called before the next freezing point where the body will appear.
1607 -- Elaboration checks refer to the real entity, not the one created by
1608 -- the renaming declaration.
1610 Set_Kill_Elaboration_Checks (New_S, True);
1612 if Etype (Nam) = Any_Type then
1613 Set_Has_Completion (New_S);
1616 elsif Nkind (Nam) = N_Selected_Component then
1618 -- Renamed entity is an entry or protected subprogram. For those
1619 -- cases an explicit body is built (at the point of freezing of this
1620 -- entity) that contains a call to the renamed entity.
1622 Analyze_Renamed_Entry (N, New_S, Present (Rename_Spec));
1625 elsif Nkind (Nam) = N_Explicit_Dereference then
1627 -- Renamed entity is designated by access_to_subprogram expression.
1628 -- Must build body to encapsulate call, as in the entry case.
1630 Analyze_Renamed_Dereference (N, New_S, Present (Rename_Spec));
1633 elsif Nkind (Nam) = N_Indexed_Component then
1634 Analyze_Renamed_Family_Member (N, New_S, Present (Rename_Spec));
1637 elsif Nkind (Nam) = N_Character_Literal then
1638 Analyze_Renamed_Character (N, New_S, Present (Rename_Spec));
1641 elsif (not Is_Entity_Name (Nam)
1642 and then Nkind (Nam) /= N_Operator_Symbol)
1643 or else not Is_Overloadable (Entity (Nam))
1645 Error_Msg_N ("expect valid subprogram name in renaming", N);
1649 -- Most common case: subprogram renames subprogram. No body is generated
1650 -- in this case, so we must indicate the declaration is complete as is.
1652 if No (Rename_Spec) then
1653 Set_Has_Completion (New_S);
1654 Set_Is_Pure (New_S, Is_Pure (Entity (Nam)));
1655 Set_Is_Preelaborated (New_S, Is_Preelaborated (Entity (Nam)));
1657 -- Ada 2005 (AI-423): Check the consistency of null exclusions
1658 -- between a subprogram and its renaming.
1660 if Ada_Version >= Ada_05 then
1661 Check_Null_Exclusion
1663 Sub => Entity (Nam));
1667 -- Find the renamed entity that matches the given specification. Disable
1668 -- Ada_83 because there is no requirement of full conformance between
1669 -- renamed entity and new entity, even though the same circuit is used.
1671 -- This is a bit of a kludge, which introduces a really irregular use of
1672 -- Ada_Version[_Explicit]. Would be nice to find cleaner way to do this
1675 Ada_Version := Ada_Version_Type'Max (Ada_Version, Ada_95);
1676 Ada_Version_Explicit := Ada_Version;
1679 Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
1682 if Old_S /= Any_Id then
1684 and then From_Default (N)
1686 -- This is an implicit reference to the default actual
1688 Generate_Reference (Old_S, Nam, Typ => 'i', Force => True);
1690 Generate_Reference (Old_S, Nam);
1693 -- For a renaming-as-body, require subtype conformance, but if the
1694 -- declaration being completed has not been frozen, then inherit the
1695 -- convention of the renamed subprogram prior to checking conformance
1696 -- (unless the renaming has an explicit convention established; the
1697 -- rule stated in the RM doesn't seem to address this ???).
1699 if Present (Rename_Spec) then
1700 Generate_Reference (Rename_Spec, Defining_Entity (Spec), 'b');
1701 Style.Check_Identifier (Defining_Entity (Spec), Rename_Spec);
1703 if not Is_Frozen (Rename_Spec) then
1704 if not Has_Convention_Pragma (Rename_Spec) then
1705 Set_Convention (New_S, Convention (Old_S));
1708 if Ekind (Old_S) /= E_Operator then
1709 Check_Mode_Conformant (New_S, Old_S, Spec);
1712 if Original_Subprogram (Old_S) = Rename_Spec then
1713 Error_Msg_N ("unfrozen subprogram cannot rename itself ", N);
1716 Check_Subtype_Conformant (New_S, Old_S, Spec);
1719 Check_Frozen_Renaming (N, Rename_Spec);
1721 -- Check explicitly that renamed entity is not intrinsic, because
1722 -- in in a generic the renamed body is not built. In this case,
1723 -- the renaming_as_body is a completion.
1725 if Inside_A_Generic then
1726 if Is_Frozen (Rename_Spec)
1727 and then Is_Intrinsic_Subprogram (Old_S)
1730 ("subprogram in renaming_as_body cannot be intrinsic",
1734 Set_Has_Completion (Rename_Spec);
1737 elsif Ekind (Old_S) /= E_Operator then
1738 Check_Mode_Conformant (New_S, Old_S);
1741 and then Error_Posted (New_S)
1743 Error_Msg_NE ("invalid actual subprogram: & #!", N, Old_S);
1747 if No (Rename_Spec) then
1749 -- The parameter profile of the new entity is that of the renamed
1750 -- entity: the subtypes given in the specification are irrelevant.
1752 Inherit_Renamed_Profile (New_S, Old_S);
1754 -- A call to the subprogram is transformed into a call to the
1755 -- renamed entity. This is transitive if the renamed entity is
1756 -- itself a renaming.
1758 if Present (Alias (Old_S)) then
1759 Set_Alias (New_S, Alias (Old_S));
1761 Set_Alias (New_S, Old_S);
1764 -- Note that we do not set Is_Intrinsic_Subprogram if we have a
1765 -- renaming as body, since the entity in this case is not an
1766 -- intrinsic (it calls an intrinsic, but we have a real body for
1767 -- this call, and it is in this body that the required intrinsic
1768 -- processing will take place).
1770 -- Also, if this is a renaming of inequality, the renamed operator
1771 -- is intrinsic, but what matters is the corresponding equality
1772 -- operator, which may be user-defined.
1774 Set_Is_Intrinsic_Subprogram
1776 Is_Intrinsic_Subprogram (Old_S)
1778 (Chars (Old_S) /= Name_Op_Ne
1779 or else Ekind (Old_S) = E_Operator
1781 Is_Intrinsic_Subprogram
1782 (Corresponding_Equality (Old_S))));
1784 if Ekind (Alias (New_S)) = E_Operator then
1785 Set_Has_Delayed_Freeze (New_S, False);
1788 -- If the renaming corresponds to an association for an abstract
1789 -- formal subprogram, then various attributes must be set to
1790 -- indicate that the renaming is an abstract dispatching operation
1791 -- with a controlling type.
1793 if Is_Actual and then Is_Abstract_Subprogram (Formal_Spec) then
1795 -- Mark the renaming as abstract here, so Find_Dispatching_Type
1796 -- see it as corresponding to a generic association for a
1797 -- formal abstract subprogram
1799 Set_Is_Abstract_Subprogram (New_S);
1802 New_S_Ctrl_Type : constant Entity_Id :=
1803 Find_Dispatching_Type (New_S);
1804 Old_S_Ctrl_Type : constant Entity_Id :=
1805 Find_Dispatching_Type (Old_S);
1808 if Old_S_Ctrl_Type /= New_S_Ctrl_Type then
1810 ("actual must be dispatching subprogram for type&",
1811 Nam, New_S_Ctrl_Type);
1814 Set_Is_Dispatching_Operation (New_S);
1815 Check_Controlling_Formals (New_S_Ctrl_Type, New_S);
1817 -- If the actual in the formal subprogram is itself a
1818 -- formal abstract subprogram association, there's no
1819 -- dispatch table component or position to inherit.
1821 if Present (DTC_Entity (Old_S)) then
1822 Set_DTC_Entity (New_S, DTC_Entity (Old_S));
1823 Set_DT_Position (New_S, DT_Position (Old_S));
1831 and then (Old_S = New_S
1832 or else (Nkind (Nam) /= N_Expanded_Name
1833 and then Chars (Old_S) = Chars (New_S)))
1835 Error_Msg_N ("subprogram cannot rename itself", N);
1838 Set_Convention (New_S, Convention (Old_S));
1840 if Is_Abstract_Subprogram (Old_S) then
1841 if Present (Rename_Spec) then
1843 ("a renaming-as-body cannot rename an abstract subprogram",
1845 Set_Has_Completion (Rename_Spec);
1847 Set_Is_Abstract_Subprogram (New_S);
1851 Check_Library_Unit_Renaming (N, Old_S);
1853 -- Pathological case: procedure renames entry in the scope of its
1854 -- task. Entry is given by simple name, but body must be built for
1855 -- procedure. Of course if called it will deadlock.
1857 if Ekind (Old_S) = E_Entry then
1858 Set_Has_Completion (New_S, False);
1859 Set_Alias (New_S, Empty);
1863 Freeze_Before (N, Old_S);
1864 Set_Has_Delayed_Freeze (New_S, False);
1865 Freeze_Before (N, New_S);
1867 -- An abstract subprogram is only allowed as an actual in the case
1868 -- where the formal subprogram is also abstract.
1870 if (Ekind (Old_S) = E_Procedure or else Ekind (Old_S) = E_Function)
1871 and then Is_Abstract_Subprogram (Old_S)
1872 and then not Is_Abstract_Subprogram (Formal_Spec)
1875 ("abstract subprogram not allowed as generic actual", Nam);
1880 -- A common error is to assume that implicit operators for types are
1881 -- defined in Standard, or in the scope of a subtype. In those cases
1882 -- where the renamed entity is given with an expanded name, it is
1883 -- worth mentioning that operators for the type are not declared in
1884 -- the scope given by the prefix.
1886 if Nkind (Nam) = N_Expanded_Name
1887 and then Nkind (Selector_Name (Nam)) = N_Operator_Symbol
1888 and then Scope (Entity (Nam)) = Standard_Standard
1891 T : constant Entity_Id :=
1892 Base_Type (Etype (First_Formal (New_S)));
1894 Error_Msg_Node_2 := Prefix (Nam);
1896 ("operator for type& is not declared in&", Prefix (Nam), T);
1901 ("no visible subprogram matches the specification for&",
1905 if Present (Candidate_Renaming) then
1911 F1 := First_Formal (Candidate_Renaming);
1912 F2 := First_Formal (New_S);
1914 while Present (F1) and then Present (F2) loop
1919 if Present (F1) and then Present (Default_Value (F1)) then
1920 if Present (Next_Formal (F1)) then
1922 ("\missing specification for &" &
1923 " and other formals with defaults", Spec, F1);
1926 ("\missing specification for &", Spec, F1);
1933 -- Ada 2005 AI 404: if the new subprogram is dispatching, verify that
1934 -- controlling access parameters are known non-null for the renamed
1935 -- subprogram. Test also applies to a subprogram instantiation that
1936 -- is dispatching. Test is skipped if some previous error was detected
1937 -- that set Old_S to Any_Id.
1939 if Ada_Version >= Ada_05
1940 and then Old_S /= Any_Id
1941 and then not Is_Dispatching_Operation (Old_S)
1942 and then Is_Dispatching_Operation (New_S)
1949 Old_F := First_Formal (Old_S);
1950 New_F := First_Formal (New_S);
1951 while Present (Old_F) loop
1952 if Ekind (Etype (Old_F)) = E_Anonymous_Access_Type
1953 and then Is_Controlling_Formal (New_F)
1954 and then not Can_Never_Be_Null (Old_F)
1956 Error_Msg_N ("access parameter is controlling,", New_F);
1957 Error_Msg_NE ("\corresponding parameter of& " &
1958 " must be explicitly null excluding", New_F, Old_S);
1961 Next_Formal (Old_F);
1962 Next_Formal (New_F);
1967 -- A useful warning, suggested by Ada Bug Finder (Ada-Europe 2005)
1969 if Comes_From_Source (N)
1970 and then Present (Old_S)
1971 and then Nkind (Old_S) = N_Defining_Operator_Symbol
1972 and then Nkind (New_S) = N_Defining_Operator_Symbol
1973 and then Chars (Old_S) /= Chars (New_S)
1976 ("?& is being renamed as a different operator",
1980 Ada_Version := Save_AV;
1981 Ada_Version_Explicit := Save_AV_Exp;
1982 end Analyze_Subprogram_Renaming;
1984 -------------------------
1985 -- Analyze_Use_Package --
1986 -------------------------
1988 -- Resolve the package names in the use clause, and make all the visible
1989 -- entities defined in the package potentially use-visible. If the package
1990 -- is already in use from a previous use clause, its visible entities are
1991 -- already use-visible. In that case, mark the occurrence as a redundant
1992 -- use. If the package is an open scope, i.e. if the use clause occurs
1993 -- within the package itself, ignore it.
1995 procedure Analyze_Use_Package (N : Node_Id) is
1996 Pack_Name : Node_Id;
1999 -- Start of processing for Analyze_Use_Package
2002 Set_Hidden_By_Use_Clause (N, No_Elist);
2004 -- Use clause is not allowed in a spec of a predefined package
2005 -- declaration except that packages whose file name starts a-n are OK
2006 -- (these are children of Ada.Numerics, and such packages are never
2007 -- loaded by Rtsfind).
2009 if Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
2010 and then Name_Buffer (1 .. 3) /= "a-n"
2012 Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
2014 Error_Msg_N ("use clause not allowed in predefined spec", N);
2017 -- Chain clause to list of use clauses in current scope
2019 if Nkind (Parent (N)) /= N_Compilation_Unit then
2020 Chain_Use_Clause (N);
2023 -- Loop through package names to identify referenced packages
2025 Pack_Name := First (Names (N));
2026 while Present (Pack_Name) loop
2027 Analyze (Pack_Name);
2029 if Nkind (Parent (N)) = N_Compilation_Unit
2030 and then Nkind (Pack_Name) = N_Expanded_Name
2036 Pref := Prefix (Pack_Name);
2037 while Nkind (Pref) = N_Expanded_Name loop
2038 Pref := Prefix (Pref);
2041 if Entity (Pref) = Standard_Standard then
2043 ("predefined package Standard cannot appear"
2044 & " in a context clause", Pref);
2052 -- Loop through package names to mark all entities as potentially
2055 Pack_Name := First (Names (N));
2056 while Present (Pack_Name) loop
2057 if Is_Entity_Name (Pack_Name) then
2058 Pack := Entity (Pack_Name);
2060 if Ekind (Pack) /= E_Package
2061 and then Etype (Pack) /= Any_Type
2063 if Ekind (Pack) = E_Generic_Package then
2065 ("a generic package is not allowed in a use clause",
2068 Error_Msg_N ("& is not a usable package", Pack_Name);
2072 if Nkind (Parent (N)) = N_Compilation_Unit then
2073 Check_In_Previous_With_Clause (N, Pack_Name);
2076 if Applicable_Use (Pack_Name) then
2077 Use_One_Package (Pack, N);
2084 end Analyze_Use_Package;
2086 ----------------------
2087 -- Analyze_Use_Type --
2088 ----------------------
2090 procedure Analyze_Use_Type (N : Node_Id) is
2094 Set_Hidden_By_Use_Clause (N, No_Elist);
2096 -- Chain clause to list of use clauses in current scope
2098 if Nkind (Parent (N)) /= N_Compilation_Unit then
2099 Chain_Use_Clause (N);
2102 Id := First (Subtype_Marks (N));
2103 while Present (Id) loop
2106 if Entity (Id) /= Any_Type then
2109 if Nkind (Parent (N)) = N_Compilation_Unit then
2110 if Nkind (Id) = N_Identifier then
2111 Error_Msg_N ("type is not directly visible", Id);
2113 elsif Is_Child_Unit (Scope (Entity (Id)))
2114 and then Scope (Entity (Id)) /= System_Aux_Id
2116 Check_In_Previous_With_Clause (N, Prefix (Id));
2123 end Analyze_Use_Type;
2125 --------------------
2126 -- Applicable_Use --
2127 --------------------
2129 function Applicable_Use (Pack_Name : Node_Id) return Boolean is
2130 Pack : constant Entity_Id := Entity (Pack_Name);
2133 if In_Open_Scopes (Pack) then
2136 elsif In_Use (Pack) then
2137 Note_Redundant_Use (Pack_Name);
2140 elsif Present (Renamed_Object (Pack))
2141 and then In_Use (Renamed_Object (Pack))
2143 Note_Redundant_Use (Pack_Name);
2151 ------------------------
2152 -- Attribute_Renaming --
2153 ------------------------
2155 procedure Attribute_Renaming (N : Node_Id) is
2156 Loc : constant Source_Ptr := Sloc (N);
2157 Nam : constant Node_Id := Name (N);
2158 Spec : constant Node_Id := Specification (N);
2159 New_S : constant Entity_Id := Defining_Unit_Name (Spec);
2160 Aname : constant Name_Id := Attribute_Name (Nam);
2162 Form_Num : Nat := 0;
2163 Expr_List : List_Id := No_List;
2165 Attr_Node : Node_Id;
2166 Body_Node : Node_Id;
2167 Param_Spec : Node_Id;
2170 Generate_Definition (New_S);
2172 -- This procedure is called in the context of subprogram renaming,
2173 -- and thus the attribute must be one that is a subprogram. All of
2174 -- those have at least one formal parameter, with the singular
2175 -- exception of AST_Entry (which is a real oddity, it is odd that
2176 -- this can be renamed at all!)
2178 if not Is_Non_Empty_List (Parameter_Specifications (Spec)) then
2179 if Aname /= Name_AST_Entry then
2181 ("subprogram renaming an attribute must have formals", N);
2186 Param_Spec := First (Parameter_Specifications (Spec));
2187 while Present (Param_Spec) loop
2188 Form_Num := Form_Num + 1;
2190 if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
2191 Find_Type (Parameter_Type (Param_Spec));
2193 -- The profile of the new entity denotes the base type (s) of
2194 -- the types given in the specification. For access parameters
2195 -- there are no subtypes involved.
2197 Rewrite (Parameter_Type (Param_Spec),
2199 (Base_Type (Entity (Parameter_Type (Param_Spec))), Loc));
2202 if No (Expr_List) then
2203 Expr_List := New_List;
2206 Append_To (Expr_List,
2207 Make_Identifier (Loc,
2208 Chars => Chars (Defining_Identifier (Param_Spec))));
2210 -- The expressions in the attribute reference are not freeze
2211 -- points. Neither is the attribute as a whole, see below.
2213 Set_Must_Not_Freeze (Last (Expr_List));
2218 -- Immediate error if too many formals. Other mismatches in numbers
2219 -- of number of types of parameters are detected when we analyze the
2220 -- body of the subprogram that we construct.
2222 if Form_Num > 2 then
2223 Error_Msg_N ("too many formals for attribute", N);
2225 -- Error if the attribute reference has expressions that look
2226 -- like formal parameters.
2228 elsif Present (Expressions (Nam)) then
2229 Error_Msg_N ("illegal expressions in attribute reference", Nam);
2232 Aname = Name_Compose or else
2233 Aname = Name_Exponent or else
2234 Aname = Name_Leading_Part or else
2235 Aname = Name_Pos or else
2236 Aname = Name_Round or else
2237 Aname = Name_Scaling or else
2240 if Nkind (N) = N_Subprogram_Renaming_Declaration
2241 and then Present (Corresponding_Formal_Spec (N))
2244 ("generic actual cannot be attribute involving universal type",
2248 ("attribute involving a universal type cannot be renamed",
2253 -- AST_Entry is an odd case. It doesn't really make much sense to
2254 -- allow it to be renamed, but that's the DEC rule, so we have to
2255 -- do it right. The point is that the AST_Entry call should be made
2256 -- now, and what the function will return is the returned value.
2258 -- Note that there is no Expr_List in this case anyway
2260 if Aname = Name_AST_Entry then
2266 Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
2269 Make_Object_Declaration (Loc,
2270 Defining_Identifier => Ent,
2271 Object_Definition =>
2272 New_Occurrence_Of (RTE (RE_AST_Handler), Loc),
2274 Constant_Present => True);
2276 Set_Assignment_OK (Decl, True);
2277 Insert_Action (N, Decl);
2278 Attr_Node := Make_Identifier (Loc, Chars (Ent));
2281 -- For all other attributes, we rewrite the attribute node to have
2282 -- a list of expressions corresponding to the subprogram formals.
2283 -- A renaming declaration is not a freeze point, and the analysis of
2284 -- the attribute reference should not freeze the type of the prefix.
2288 Make_Attribute_Reference (Loc,
2289 Prefix => Prefix (Nam),
2290 Attribute_Name => Aname,
2291 Expressions => Expr_List);
2293 Set_Must_Not_Freeze (Attr_Node);
2294 Set_Must_Not_Freeze (Prefix (Nam));
2297 -- Case of renaming a function
2299 if Nkind (Spec) = N_Function_Specification then
2300 if Is_Procedure_Attribute_Name (Aname) then
2301 Error_Msg_N ("attribute can only be renamed as procedure", Nam);
2305 Find_Type (Result_Definition (Spec));
2306 Rewrite (Result_Definition (Spec),
2308 Base_Type (Entity (Result_Definition (Spec))), Loc));
2311 Make_Subprogram_Body (Loc,
2312 Specification => Spec,
2313 Declarations => New_List,
2314 Handled_Statement_Sequence =>
2315 Make_Handled_Sequence_Of_Statements (Loc,
2316 Statements => New_List (
2317 Make_Return_Statement (Loc,
2318 Expression => Attr_Node))));
2320 -- Case of renaming a procedure
2323 if not Is_Procedure_Attribute_Name (Aname) then
2324 Error_Msg_N ("attribute can only be renamed as function", Nam);
2329 Make_Subprogram_Body (Loc,
2330 Specification => Spec,
2331 Declarations => New_List,
2332 Handled_Statement_Sequence =>
2333 Make_Handled_Sequence_Of_Statements (Loc,
2334 Statements => New_List (Attr_Node)));
2337 Rewrite (N, Body_Node);
2340 if Is_Compilation_Unit (New_S) then
2342 ("a library unit can only rename another library unit", N);
2345 Set_Etype (New_S, Base_Type (Etype (New_S)));
2347 -- We suppress elaboration warnings for the resulting entity, since
2348 -- clearly they are not needed, and more particularly, in the case
2349 -- of a generic formal subprogram, the resulting entity can appear
2350 -- after the instantiation itself, and thus look like a bogus case
2351 -- of access before elaboration.
2353 Set_Suppress_Elaboration_Warnings (New_S);
2355 end Attribute_Renaming;
2357 ----------------------
2358 -- Chain_Use_Clause --
2359 ----------------------
2361 procedure Chain_Use_Clause (N : Node_Id) is
2363 Level : Int := Scope_Stack.Last;
2366 if not Is_Compilation_Unit (Current_Scope)
2367 or else not Is_Child_Unit (Current_Scope)
2369 null; -- Common case
2371 elsif Defining_Entity (Parent (N)) = Current_Scope then
2372 null; -- Common case for compilation unit
2375 -- If declaration appears in some other scope, it must be in some
2376 -- parent unit when compiling a child.
2378 Pack := Defining_Entity (Parent (N));
2379 if not In_Open_Scopes (Pack) then
2380 null; -- default as well
2383 -- Find entry for parent unit in scope stack
2385 while Scope_Stack.Table (Level).Entity /= Pack loop
2391 Set_Next_Use_Clause (N,
2392 Scope_Stack.Table (Level).First_Use_Clause);
2393 Scope_Stack.Table (Level).First_Use_Clause := N;
2394 end Chain_Use_Clause;
2396 ---------------------------
2397 -- Check_Frozen_Renaming --
2398 ---------------------------
2400 procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id) is
2406 and then not Has_Completion (Subp)
2410 (Parent (Declaration_Node (Subp)), Defining_Entity (N));
2412 if Is_Entity_Name (Name (N)) then
2413 Old_S := Entity (Name (N));
2415 if not Is_Frozen (Old_S)
2416 and then Operating_Mode /= Check_Semantics
2418 Append_Freeze_Action (Old_S, B_Node);
2420 Insert_After (N, B_Node);
2424 if Is_Intrinsic_Subprogram (Old_S)
2425 and then not In_Instance
2428 ("subprogram used in renaming_as_body cannot be intrinsic",
2433 Insert_After (N, B_Node);
2437 end Check_Frozen_Renaming;
2439 -----------------------------------
2440 -- Check_In_Previous_With_Clause --
2441 -----------------------------------
2443 procedure Check_In_Previous_With_Clause
2447 Pack : constant Entity_Id := Entity (Original_Node (Nam));
2452 Item := First (Context_Items (Parent (N)));
2454 while Present (Item)
2457 if Nkind (Item) = N_With_Clause
2459 -- Protect the frontend against previous critical errors
2461 and then Nkind (Name (Item)) /= N_Selected_Component
2462 and then Entity (Name (Item)) = Pack
2466 -- Find root library unit in with_clause
2468 while Nkind (Par) = N_Expanded_Name loop
2469 Par := Prefix (Par);
2472 if Is_Child_Unit (Entity (Original_Node (Par))) then
2474 ("& is not directly visible", Par, Entity (Par));
2483 -- On exit, package is not mentioned in a previous with_clause.
2484 -- Check if its prefix is.
2486 if Nkind (Nam) = N_Expanded_Name then
2487 Check_In_Previous_With_Clause (N, Prefix (Nam));
2489 elsif Pack /= Any_Id then
2490 Error_Msg_NE ("& is not visible", Nam, Pack);
2492 end Check_In_Previous_With_Clause;
2494 ---------------------------------
2495 -- Check_Library_Unit_Renaming --
2496 ---------------------------------
2498 procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id) is
2502 if Nkind (Parent (N)) /= N_Compilation_Unit then
2505 elsif Scope (Old_E) /= Standard_Standard
2506 and then not Is_Child_Unit (Old_E)
2508 Error_Msg_N ("renamed unit must be a library unit", Name (N));
2510 -- Entities defined in Standard (operators and boolean literals) cannot
2511 -- be renamed as library units.
2513 elsif Scope (Old_E) = Standard_Standard
2514 and then Sloc (Old_E) = Standard_Location
2516 Error_Msg_N ("renamed unit must be a library unit", Name (N));
2518 elsif Present (Parent_Spec (N))
2519 and then Nkind (Unit (Parent_Spec (N))) = N_Generic_Package_Declaration
2520 and then not Is_Child_Unit (Old_E)
2523 ("renamed unit must be a child unit of generic parent", Name (N));
2525 elsif Nkind (N) in N_Generic_Renaming_Declaration
2526 and then Nkind (Name (N)) = N_Expanded_Name
2527 and then Is_Generic_Instance (Entity (Prefix (Name (N))))
2528 and then Is_Generic_Unit (Old_E)
2531 ("renamed generic unit must be a library unit", Name (N));
2533 elsif Ekind (Old_E) = E_Package
2534 or else Ekind (Old_E) = E_Generic_Package
2536 -- Inherit categorization flags
2538 New_E := Defining_Entity (N);
2539 Set_Is_Pure (New_E, Is_Pure (Old_E));
2540 Set_Is_Preelaborated (New_E, Is_Preelaborated (Old_E));
2541 Set_Is_Remote_Call_Interface (New_E,
2542 Is_Remote_Call_Interface (Old_E));
2543 Set_Is_Remote_Types (New_E, Is_Remote_Types (Old_E));
2544 Set_Is_Shared_Passive (New_E, Is_Shared_Passive (Old_E));
2546 end Check_Library_Unit_Renaming;
2552 procedure End_Scope is
2558 Id := First_Entity (Current_Scope);
2559 while Present (Id) loop
2560 -- An entity in the current scope is not necessarily the first one
2561 -- on its homonym chain. Find its predecessor if any,
2562 -- If it is an internal entity, it will not be in the visibility
2563 -- chain altogether, and there is nothing to unchain.
2565 if Id /= Current_Entity (Id) then
2566 Prev := Current_Entity (Id);
2567 while Present (Prev)
2568 and then Present (Homonym (Prev))
2569 and then Homonym (Prev) /= Id
2571 Prev := Homonym (Prev);
2574 -- Skip to end of loop if Id is not in the visibility chain
2576 if No (Prev) or else Homonym (Prev) /= Id then
2584 Set_Is_Immediately_Visible (Id, False);
2586 Outer := Homonym (Id);
2587 while Present (Outer) and then Scope (Outer) = Current_Scope loop
2588 Outer := Homonym (Outer);
2591 -- Reset homonym link of other entities, but do not modify link
2592 -- between entities in current scope, so that the back-end can have
2593 -- a proper count of local overloadings.
2596 Set_Name_Entity_Id (Chars (Id), Outer);
2598 elsif Scope (Prev) /= Scope (Id) then
2599 Set_Homonym (Prev, Outer);
2606 -- If the scope generated freeze actions, place them before the
2607 -- current declaration and analyze them. Type declarations and
2608 -- the bodies of initialization procedures can generate such nodes.
2609 -- We follow the parent chain until we reach a list node, which is
2610 -- the enclosing list of declarations. If the list appears within
2611 -- a protected definition, move freeze nodes outside the protected
2615 (Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions)
2619 L : constant List_Id := Scope_Stack.Table
2620 (Scope_Stack.Last).Pending_Freeze_Actions;
2623 if Is_Itype (Current_Scope) then
2624 Decl := Associated_Node_For_Itype (Current_Scope);
2626 Decl := Parent (Current_Scope);
2631 while not (Is_List_Member (Decl))
2632 or else Nkind (Parent (Decl)) = N_Protected_Definition
2633 or else Nkind (Parent (Decl)) = N_Task_Definition
2635 Decl := Parent (Decl);
2638 Insert_List_Before_And_Analyze (Decl, L);
2647 ---------------------
2648 -- End_Use_Clauses --
2649 ---------------------
2651 procedure End_Use_Clauses (Clause : Node_Id) is
2655 -- Remove Use_Type clauses first, because they affect the
2656 -- visibility of operators in subsequent used packages.
2659 while Present (U) loop
2660 if Nkind (U) = N_Use_Type_Clause then
2664 Next_Use_Clause (U);
2668 while Present (U) loop
2669 if Nkind (U) = N_Use_Package_Clause then
2670 End_Use_Package (U);
2673 Next_Use_Clause (U);
2675 end End_Use_Clauses;
2677 ---------------------
2678 -- End_Use_Package --
2679 ---------------------
2681 procedure End_Use_Package (N : Node_Id) is
2682 Pack_Name : Node_Id;
2687 function Is_Primitive_Operator
2689 F : Entity_Id) return Boolean;
2690 -- Check whether Op is a primitive operator of a use-visible type
2692 ---------------------------
2693 -- Is_Primitive_Operator --
2694 ---------------------------
2696 function Is_Primitive_Operator
2698 F : Entity_Id) return Boolean
2700 T : constant Entity_Id := Etype (F);
2703 and then Scope (T) = Scope (Op);
2704 end Is_Primitive_Operator;
2706 -- Start of processing for End_Use_Package
2709 Pack_Name := First (Names (N));
2710 while Present (Pack_Name) loop
2711 Pack := Entity (Pack_Name);
2713 if Ekind (Pack) = E_Package then
2714 if In_Open_Scopes (Pack) then
2717 elsif not Redundant_Use (Pack_Name) then
2718 Set_In_Use (Pack, False);
2719 Set_Current_Use_Clause (Pack, Empty);
2721 Id := First_Entity (Pack);
2722 while Present (Id) loop
2724 -- Preserve use-visibility of operators that are primitive
2725 -- operators of a type that is use_visible through an active
2728 if Nkind (Id) = N_Defining_Operator_Symbol
2730 (Is_Primitive_Operator (Id, First_Formal (Id))
2732 (Present (Next_Formal (First_Formal (Id)))
2734 Is_Primitive_Operator
2735 (Id, Next_Formal (First_Formal (Id)))))
2740 Set_Is_Potentially_Use_Visible (Id, False);
2743 if Is_Private_Type (Id)
2744 and then Present (Full_View (Id))
2746 Set_Is_Potentially_Use_Visible (Full_View (Id), False);
2752 if Present (Renamed_Object (Pack)) then
2753 Set_In_Use (Renamed_Object (Pack), False);
2754 Set_Current_Use_Clause (Renamed_Object (Pack), Empty);
2757 if Chars (Pack) = Name_System
2758 and then Scope (Pack) = Standard_Standard
2759 and then Present_System_Aux
2761 Id := First_Entity (System_Aux_Id);
2762 while Present (Id) loop
2763 Set_Is_Potentially_Use_Visible (Id, False);
2765 if Is_Private_Type (Id)
2766 and then Present (Full_View (Id))
2768 Set_Is_Potentially_Use_Visible (Full_View (Id), False);
2774 Set_In_Use (System_Aux_Id, False);
2778 Set_Redundant_Use (Pack_Name, False);
2785 if Present (Hidden_By_Use_Clause (N)) then
2786 Elmt := First_Elmt (Hidden_By_Use_Clause (N));
2787 while Present (Elmt) loop
2788 Set_Is_Immediately_Visible (Node (Elmt));
2792 Set_Hidden_By_Use_Clause (N, No_Elist);
2794 end End_Use_Package;
2800 procedure End_Use_Type (N : Node_Id) is
2807 Id := First (Subtype_Marks (N));
2808 while Present (Id) loop
2810 -- A call to rtsfind may occur while analyzing a use_type clause,
2811 -- in which case the type marks are not resolved yet, and there is
2812 -- nothing to remove.
2814 if not Is_Entity_Name (Id)
2815 or else No (Entity (Id))
2823 or else From_With_Type (T)
2827 -- Note that the use_Type clause may mention a subtype of the type
2828 -- whose primitive operations have been made visible. Here as
2829 -- elsewhere, it is the base type that matters for visibility.
2831 elsif In_Open_Scopes (Scope (Base_Type (T))) then
2834 elsif not Redundant_Use (Id) then
2835 Set_In_Use (T, False);
2836 Set_In_Use (Base_Type (T), False);
2837 Op_List := Collect_Primitive_Operations (T);
2839 Elmt := First_Elmt (Op_List);
2840 while Present (Elmt) loop
2841 if Nkind (Node (Elmt)) = N_Defining_Operator_Symbol then
2842 Set_Is_Potentially_Use_Visible (Node (Elmt), False);
2854 ----------------------
2855 -- Find_Direct_Name --
2856 ----------------------
2858 procedure Find_Direct_Name (N : Node_Id) is
2863 Inst : Entity_Id := Empty;
2864 -- Enclosing instance, if any
2866 Homonyms : Entity_Id;
2867 -- Saves start of homonym chain
2869 Nvis_Entity : Boolean;
2870 -- Set True to indicate that at there is at least one entity on the
2871 -- homonym chain which, while not visible, is visible enough from the
2872 -- user point of view to warrant an error message of "not visible"
2873 -- rather than undefined.
2875 Nvis_Is_Private_Subprg : Boolean := False;
2876 -- Ada 2005 (AI-262): Set True to indicate that a form of Beaujolais
2877 -- effect concerning library subprograms has been detected. Used to
2878 -- generate the precise error message.
2880 function From_Actual_Package (E : Entity_Id) return Boolean;
2881 -- Returns true if the entity is declared in a package that is
2882 -- an actual for a formal package of the current instance. Such an
2883 -- entity requires special handling because it may be use-visible
2884 -- but hides directly visible entities defined outside the instance.
2886 function Known_But_Invisible (E : Entity_Id) return Boolean;
2887 -- This function determines whether the entity E (which is not
2888 -- visible) can reasonably be considered to be known to the writer
2889 -- of the reference. This is a heuristic test, used only for the
2890 -- purposes of figuring out whether we prefer to complain that an
2891 -- entity is undefined or invisible (and identify the declaration
2892 -- of the invisible entity in the latter case). The point here is
2893 -- that we don't want to complain that something is invisible and
2894 -- then point to something entirely mysterious to the writer.
2896 procedure Nvis_Messages;
2897 -- Called if there are no visible entries for N, but there is at least
2898 -- one non-directly visible, or hidden declaration. This procedure
2899 -- outputs an appropriate set of error messages.
2901 procedure Undefined (Nvis : Boolean);
2902 -- This function is called if the current node has no corresponding
2903 -- visible entity or entities. The value set in Msg indicates whether
2904 -- an error message was generated (multiple error messages for the
2905 -- same variable are generally suppressed, see body for details).
2906 -- Msg is True if an error message was generated, False if not. This
2907 -- value is used by the caller to determine whether or not to output
2908 -- additional messages where appropriate. The parameter is set False
2909 -- to get the message "X is undefined", and True to get the message
2910 -- "X is not visible".
2912 -------------------------
2913 -- From_Actual_Package --
2914 -------------------------
2916 function From_Actual_Package (E : Entity_Id) return Boolean is
2917 Scop : constant Entity_Id := Scope (E);
2921 if not In_Instance then
2924 Inst := Current_Scope;
2925 while Present (Inst)
2926 and then Ekind (Inst) /= E_Package
2927 and then not Is_Generic_Instance (Inst)
2929 Inst := Scope (Inst);
2936 Act := First_Entity (Inst);
2937 while Present (Act) loop
2938 if Ekind (Act) = E_Package then
2940 -- Check for end of actuals list
2942 if Renamed_Object (Act) = Inst then
2945 elsif Present (Associated_Formal_Package (Act))
2946 and then Renamed_Object (Act) = Scop
2948 -- Entity comes from (instance of) formal package
2963 end From_Actual_Package;
2965 -------------------------
2966 -- Known_But_Invisible --
2967 -------------------------
2969 function Known_But_Invisible (E : Entity_Id) return Boolean is
2970 Fname : File_Name_Type;
2973 -- Entities in Standard are always considered to be known
2975 if Sloc (E) <= Standard_Location then
2978 -- An entity that does not come from source is always considered
2979 -- to be unknown, since it is an artifact of code expansion.
2981 elsif not Comes_From_Source (E) then
2984 -- In gnat internal mode, we consider all entities known
2986 elsif GNAT_Mode then
2990 -- Here we have an entity that is not from package Standard, and
2991 -- which comes from Source. See if it comes from an internal file.
2993 Fname := Unit_File_Name (Get_Source_Unit (E));
2995 -- Case of from internal file
2997 if Is_Internal_File_Name (Fname) then
2999 -- Private part entities in internal files are never considered
3000 -- to be known to the writer of normal application code.
3002 if Is_Hidden (E) then
3006 -- Entities from System packages other than System and
3007 -- System.Storage_Elements are not considered to be known.
3008 -- System.Auxxxx files are also considered known to the user.
3010 -- Should refine this at some point to generally distinguish
3011 -- between known and unknown internal files ???
3013 Get_Name_String (Fname);
3018 Name_Buffer (1 .. 2) /= "s-"
3020 Name_Buffer (3 .. 8) = "stoele"
3022 Name_Buffer (3 .. 5) = "aux";
3024 -- If not an internal file, then entity is definitely known,
3025 -- even if it is in a private part (the message generated will
3026 -- note that it is in a private part)
3031 end Known_But_Invisible;
3037 procedure Nvis_Messages is
3038 Comp_Unit : Node_Id;
3040 Hidden : Boolean := False;
3044 -- Ada 2005 (AI-262): Generate a precise error concerning the
3045 -- Beaujolais effect that was previously detected
3047 if Nvis_Is_Private_Subprg then
3049 pragma Assert (Nkind (E2) = N_Defining_Identifier
3050 and then Ekind (E2) = E_Function
3051 and then Scope (E2) = Standard_Standard
3052 and then Has_Private_With (E2));
3054 -- Find the sloc corresponding to the private with'ed unit
3056 Comp_Unit := Cunit (Current_Sem_Unit);
3057 Error_Msg_Sloc := No_Location;
3059 Item := First (Context_Items (Comp_Unit));
3060 while Present (Item) loop
3061 if Nkind (Item) = N_With_Clause
3062 and then Private_Present (Item)
3063 and then Entity (Name (Item)) = E2
3065 Error_Msg_Sloc := Sloc (Item);
3072 pragma Assert (Error_Msg_Sloc /= No_Location);
3074 Error_Msg_N ("(Ada 2005): hidden by private with clause #", N);
3078 Undefined (Nvis => True);
3082 -- First loop does hidden declarations
3085 while Present (Ent) loop
3086 if Is_Potentially_Use_Visible (Ent) then
3088 Error_Msg_N ("multiple use clauses cause hiding!", N);
3092 Error_Msg_Sloc := Sloc (Ent);
3093 Error_Msg_N ("hidden declaration#!", N);
3096 Ent := Homonym (Ent);
3099 -- If we found hidden declarations, then that's enough, don't
3100 -- bother looking for non-visible declarations as well.
3106 -- Second loop does non-directly visible declarations
3109 while Present (Ent) loop
3110 if not Is_Potentially_Use_Visible (Ent) then
3112 -- Do not bother the user with unknown entities
3114 if not Known_But_Invisible (Ent) then
3118 Error_Msg_Sloc := Sloc (Ent);
3120 -- Output message noting that there is a non-visible
3121 -- declaration, distinguishing the private part case.
3123 if Is_Hidden (Ent) then
3124 Error_Msg_N ("non-visible (private) declaration#!", N);
3126 Error_Msg_N ("non-visible declaration#!", N);
3128 if Is_Compilation_Unit (Ent)
3130 Nkind (Parent (Parent (N))) = N_Use_Package_Clause
3132 Error_Msg_Qual_Level := 99;
3133 Error_Msg_NE ("\\missing `WITH &;`", N, Ent);
3134 Error_Msg_Qual_Level := 0;
3138 -- Set entity and its containing package as referenced. We
3139 -- can't be sure of this, but this seems a better choice
3140 -- to avoid unused entity messages.
3142 if Comes_From_Source (Ent) then
3143 Set_Referenced (Ent);
3144 Set_Referenced (Cunit_Entity (Get_Source_Unit (Ent)));
3149 Ent := Homonym (Ent);
3158 procedure Undefined (Nvis : Boolean) is
3159 Emsg : Error_Msg_Id;
3162 -- We should never find an undefined internal name. If we do, then
3163 -- see if we have previous errors. If so, ignore on the grounds that
3164 -- it is probably a cascaded message (e.g. a block label from a badly
3165 -- formed block). If no previous errors, then we have a real internal
3166 -- error of some kind so raise an exception.
3168 if Is_Internal_Name (Chars (N)) then
3169 if Total_Errors_Detected /= 0 then
3172 raise Program_Error;
3176 -- A very specialized error check, if the undefined variable is
3177 -- a case tag, and the case type is an enumeration type, check
3178 -- for a possible misspelling, and if so, modify the identifier
3180 -- Named aggregate should also be handled similarly ???
3182 if Nkind (N) = N_Identifier
3183 and then Nkind (Parent (N)) = N_Case_Statement_Alternative
3185 Get_Name_String (Chars (N));
3188 Case_Str : constant String := Name_Buffer (1 .. Name_Len);
3189 Case_Stm : constant Node_Id := Parent (Parent (N));
3190 Case_Typ : constant Entity_Id := Etype (Expression (Case_Stm));
3191 Case_Rtp : constant Entity_Id := Root_Type (Case_Typ);
3196 if Is_Enumeration_Type (Case_Typ)
3197 and then Case_Rtp /= Standard_Character
3198 and then Case_Rtp /= Standard_Wide_Character
3199 and then Case_Rtp /= Standard_Wide_Wide_Character
3201 Lit := First_Literal (Case_Typ);
3202 Get_Name_String (Chars (Lit));
3204 if Chars (Lit) /= Chars (N)
3205 and then Is_Bad_Spelling_Of
3206 (Case_Str, Name_Buffer (1 .. Name_Len))
3208 Error_Msg_Node_2 := Lit;
3210 ("& is undefined, assume misspelling of &", N);
3211 Rewrite (N, New_Occurrence_Of (Lit, Sloc (N)));
3215 Lit := Next_Literal (Lit);
3220 -- Normal processing
3222 Set_Entity (N, Any_Id);
3223 Set_Etype (N, Any_Type);
3225 -- We use the table Urefs to keep track of entities for which we
3226 -- have issued errors for undefined references. Multiple errors
3227 -- for a single name are normally suppressed, however we modify
3228 -- the error message to alert the programmer to this effect.
3230 for J in Urefs.First .. Urefs.Last loop
3231 if Chars (N) = Chars (Urefs.Table (J).Node) then
3232 if Urefs.Table (J).Err /= No_Error_Msg
3233 and then Sloc (N) /= Urefs.Table (J).Loc
3235 Error_Msg_Node_1 := Urefs.Table (J).Node;
3237 if Urefs.Table (J).Nvis then
3238 Change_Error_Text (Urefs.Table (J).Err,
3239 "& is not visible (more references follow)");
3241 Change_Error_Text (Urefs.Table (J).Err,
3242 "& is undefined (more references follow)");
3245 Urefs.Table (J).Err := No_Error_Msg;
3248 -- Although we will set Msg False, and thus suppress the
3249 -- message, we also set Error_Posted True, to avoid any
3250 -- cascaded messages resulting from the undefined reference.
3253 Set_Error_Posted (N, True);
3258 -- If entry not found, this is first undefined occurrence
3261 Error_Msg_N ("& is not visible!", N);
3265 Error_Msg_N ("& is undefined!", N);
3268 -- A very bizarre special check, if the undefined identifier
3269 -- is put or put_line, then add a special error message (since
3270 -- this is a very common error for beginners to make).
3272 if Chars (N) = Name_Put or else Chars (N) = Name_Put_Line then
3274 ("\\possible missing `WITH Ada.Text_'I'O; " &
3275 "USE Ada.Text_'I'O`!", N);
3277 -- Another special check if N is the prefix of a selected
3278 -- component which is a known unit, add message complaining
3279 -- about missingw with for this unit.
3281 elsif Nkind (Parent (N)) = N_Selected_Component
3282 and then N = Prefix (Parent (N))
3283 and then Is_Known_Unit (Parent (N))
3285 Error_Msg_Node_2 := Selector_Name (Parent (N));
3286 Error_Msg_N ("\\missing `WITH &.&;`", Prefix (Parent (N)));
3289 -- Now check for possible misspellings
3291 Get_Name_String (Chars (N));
3295 Ematch : Entity_Id := Empty;
3297 Last_Name_Id : constant Name_Id :=
3298 Name_Id (Nat (First_Name_Id) +
3299 Name_Entries_Count - 1);
3301 S : constant String (1 .. Name_Len) :=
3302 Name_Buffer (1 .. Name_Len);
3305 for N in First_Name_Id .. Last_Name_Id loop
3306 E := Get_Name_Entity_Id (N);
3309 and then (Is_Immediately_Visible (E)
3311 Is_Potentially_Use_Visible (E))
3313 Get_Name_String (N);
3315 if Is_Bad_Spelling_Of
3316 (S, Name_Buffer (1 .. Name_Len))
3324 if Present (Ematch) then
3325 Error_Msg_NE ("\possible misspelling of&", N, Ematch);
3330 -- Make entry in undefined references table unless the full errors
3331 -- switch is set, in which case by refraining from generating the
3332 -- table entry, we guarantee that we get an error message for every
3333 -- undefined reference.
3335 if not All_Errors_Mode then
3336 Urefs.Increment_Last;
3337 Urefs.Table (Urefs.Last).Node := N;
3338 Urefs.Table (Urefs.Last).Err := Emsg;
3339 Urefs.Table (Urefs.Last).Nvis := Nvis;
3340 Urefs.Table (Urefs.Last).Loc := Sloc (N);
3346 -- Start of processing for Find_Direct_Name
3349 -- If the entity pointer is already set, this is an internal node, or
3350 -- a node that is analyzed more than once, after a tree modification.
3351 -- In such a case there is no resolution to perform, just set the type.
3353 if Present (Entity (N)) then
3354 if Is_Type (Entity (N)) then
3355 Set_Etype (N, Entity (N));
3359 Entyp : constant Entity_Id := Etype (Entity (N));
3362 -- One special case here. If the Etype field is already set,
3363 -- and references the packed array type corresponding to the
3364 -- etype of the referenced entity, then leave it alone. This
3365 -- happens for trees generated from Exp_Pakd, where expressions
3366 -- can be deliberately "mis-typed" to the packed array type.
3368 if Is_Array_Type (Entyp)
3369 and then Is_Packed (Entyp)
3370 and then Present (Etype (N))
3371 and then Etype (N) = Packed_Array_Type (Entyp)
3375 -- If not that special case, then just reset the Etype
3378 Set_Etype (N, Etype (Entity (N)));
3386 -- Here if Entity pointer was not set, we need full visibility analysis
3387 -- First we generate debugging output if the debug E flag is set.
3389 if Debug_Flag_E then
3390 Write_Str ("Looking for ");
3391 Write_Name (Chars (N));
3395 Homonyms := Current_Entity (N);
3396 Nvis_Entity := False;
3399 while Present (E) loop
3401 -- If entity is immediately visible or potentially use
3402 -- visible, then process the entity and we are done.
3404 if Is_Immediately_Visible (E) then
3405 goto Immediately_Visible_Entity;
3407 elsif Is_Potentially_Use_Visible (E) then
3408 goto Potentially_Use_Visible_Entity;
3410 -- Note if a known but invisible entity encountered
3412 elsif Known_But_Invisible (E) then
3413 Nvis_Entity := True;
3416 -- Move to next entity in chain and continue search
3421 -- If no entries on homonym chain that were potentially visible,
3422 -- and no entities reasonably considered as non-visible, then
3423 -- we have a plain undefined reference, with no additional
3424 -- explanation required!
3426 if not Nvis_Entity then
3427 Undefined (Nvis => False);
3429 -- Otherwise there is at least one entry on the homonym chain that
3430 -- is reasonably considered as being known and non-visible.
3438 -- Processing for a potentially use visible entry found. We must search
3439 -- the rest of the homonym chain for two reasons. First, if there is a
3440 -- directly visible entry, then none of the potentially use-visible
3441 -- entities are directly visible (RM 8.4(10)). Second, we need to check
3442 -- for the case of multiple potentially use-visible entries hiding one
3443 -- another and as a result being non-directly visible (RM 8.4(11)).
3445 <<Potentially_Use_Visible_Entity>> declare
3446 Only_One_Visible : Boolean := True;
3447 All_Overloadable : Boolean := Is_Overloadable (E);
3451 while Present (E2) loop
3452 if Is_Immediately_Visible (E2) then
3454 -- If the use-visible entity comes from the actual for a
3455 -- formal package, it hides a directly visible entity from
3456 -- outside the instance.
3458 if From_Actual_Package (E)
3459 and then Scope_Depth (E2) < Scope_Depth (Inst)
3464 goto Immediately_Visible_Entity;
3467 elsif Is_Potentially_Use_Visible (E2) then
3468 Only_One_Visible := False;
3469 All_Overloadable := All_Overloadable and Is_Overloadable (E2);
3471 -- Ada 2005 (AI-262): Protect against a form of Beujolais effect
3472 -- that can occurr in private_with clauses. Example:
3475 -- private with B; package A is
3476 -- package C is function B return Integer;
3478 -- V1 : Integer := B;
3479 -- private function B return Integer;
3480 -- V2 : Integer := B;
3483 -- V1 resolves to A.B, but V2 resolves to library unit B
3485 elsif Ekind (E2) = E_Function
3486 and then Scope (E2) = Standard_Standard
3487 and then Has_Private_With (E2)
3489 Only_One_Visible := False;
3490 All_Overloadable := False;
3491 Nvis_Is_Private_Subprg := True;
3498 -- On falling through this loop, we have checked that there are no
3499 -- immediately visible entities. Only_One_Visible is set if exactly
3500 -- one potentially use visible entity exists. All_Overloadable is
3501 -- set if all the potentially use visible entities are overloadable.
3502 -- The condition for legality is that either there is one potentially
3503 -- use visible entity, or if there is more than one, then all of them
3504 -- are overloadable.
3506 if Only_One_Visible or All_Overloadable then
3509 -- If there is more than one potentially use-visible entity and at
3510 -- least one of them non-overloadable, we have an error (RM 8.4(11).
3511 -- Note that E points to the first such entity on the homonym list.
3512 -- Special case: if one of the entities is declared in an actual
3513 -- package, it was visible in the generic, and takes precedence over
3514 -- other entities that are potentially use-visible. Same if it is
3515 -- declared in a local instantiation of the current instance.
3520 -- Find current instance
3522 Inst := Current_Scope;
3523 while Present (Inst)
3524 and then Inst /= Standard_Standard
3526 if Is_Generic_Instance (Inst) then
3530 Inst := Scope (Inst);
3534 while Present (E2) loop
3535 if From_Actual_Package (E2)
3537 (Is_Generic_Instance (Scope (E2))
3538 and then Scope_Depth (Scope (E2)) > Scope_Depth (Inst))
3551 Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
3553 -- A use-clause in the body of a system file creates conflict
3554 -- with some entity in a user scope, while rtsfind is active.
3555 -- Keep only the entity coming from another predefined unit.
3558 while Present (E2) loop
3559 if Is_Predefined_File_Name
3560 (Unit_File_Name (Get_Source_Unit (Sloc (E2))))
3569 -- Entity must exist because predefined unit is correct
3571 raise Program_Error;
3580 -- Come here with E set to the first immediately visible entity on
3581 -- the homonym chain. This is the one we want unless there is another
3582 -- immediately visible entity further on in the chain for a more
3583 -- inner scope (RM 8.3(8)).
3585 <<Immediately_Visible_Entity>> declare
3590 -- Find scope level of initial entity. When compiling through
3591 -- Rtsfind, the previous context is not completely invisible, and
3592 -- an outer entity may appear on the chain, whose scope is below
3593 -- the entry for Standard that delimits the current scope stack.
3594 -- Indicate that the level for this spurious entry is outside of
3595 -- the current scope stack.
3597 Level := Scope_Stack.Last;
3599 Scop := Scope_Stack.Table (Level).Entity;
3600 exit when Scop = Scope (E);
3602 exit when Scop = Standard_Standard;
3605 -- Now search remainder of homonym chain for more inner entry
3606 -- If the entity is Standard itself, it has no scope, and we
3607 -- compare it with the stack entry directly.
3610 while Present (E2) loop
3611 if Is_Immediately_Visible (E2) then
3613 -- If a generic package contains a local declaration that
3614 -- has the same name as the generic, there may be a visibility
3615 -- conflict in an instance, where the local declaration must
3616 -- also hide the name of the corresponding package renaming.
3617 -- We check explicitly for a package declared by a renaming,
3618 -- whose renamed entity is an instance that is on the scope
3619 -- stack, and that contains a homonym in the same scope. Once
3620 -- we have found it, we know that the package renaming is not
3621 -- immediately visible, and that the identifier denotes the
3622 -- other entity (and its homonyms if overloaded).
3624 if Scope (E) = Scope (E2)
3625 and then Ekind (E) = E_Package
3626 and then Present (Renamed_Object (E))
3627 and then Is_Generic_Instance (Renamed_Object (E))
3628 and then In_Open_Scopes (Renamed_Object (E))
3629 and then Comes_From_Source (N)
3631 Set_Is_Immediately_Visible (E, False);
3635 for J in Level + 1 .. Scope_Stack.Last loop
3636 if Scope_Stack.Table (J).Entity = Scope (E2)
3637 or else Scope_Stack.Table (J).Entity = E2
3650 -- At the end of that loop, E is the innermost immediately
3651 -- visible entity, so we are all set.
3654 -- Come here with entity found, and stored in E
3658 if Comes_From_Source (N)
3659 and then Is_Remote_Access_To_Subprogram_Type (E)
3660 and then Expander_Active
3661 and then Get_PCS_Name /= Name_No_DSA
3664 New_Occurrence_Of (Equivalent_Type (E), Sloc (N)));
3669 -- Why no Style_Check here???
3674 Set_Etype (N, Get_Full_View (Etype (E)));
3677 if Debug_Flag_E then
3678 Write_Str (" found ");
3679 Write_Entity_Info (E, " ");
3682 -- If the Ekind of the entity is Void, it means that all homonyms
3683 -- are hidden from all visibility (RM 8.3(5,14-20)). However, this
3684 -- test is skipped if the current scope is a record and the name is
3685 -- a pragma argument expression (case of Atomic and Volatile pragmas
3686 -- and possibly other similar pragmas added later, which are allowed
3687 -- to reference components in the current record).
3689 if Ekind (E) = E_Void
3691 (not Is_Record_Type (Current_Scope)
3692 or else Nkind (Parent (N)) /= N_Pragma_Argument_Association)
3694 Premature_Usage (N);
3696 -- If the entity is overloadable, collect all interpretations of the
3697 -- name for subsequent overload resolution. We optimize a bit here to
3698 -- do this only if we have an overloadable entity that is not on its
3699 -- own on the homonym chain.
3701 elsif Is_Overloadable (E)
3702 and then (Present (Homonym (E)) or else Current_Entity (N) /= E)
3704 Collect_Interps (N);
3706 -- If no homonyms were visible, the entity is unambiguous
3708 if not Is_Overloaded (N) then
3709 Generate_Reference (E, N);
3712 -- Case of non-overloadable entity, set the entity providing that
3713 -- we do not have the case of a discriminant reference within a
3714 -- default expression. Such references are replaced with the
3715 -- corresponding discriminal, which is the formal corresponding to
3716 -- to the discriminant in the initialization procedure.
3719 -- Entity is unambiguous, indicate that it is referenced here One
3720 -- slightly odd case is that we do not want to set the Referenced
3721 -- flag if the entity is a label, and the identifier is the label
3722 -- in the source, since this is not a reference from the point of
3725 if Nkind (Parent (N)) = N_Label then
3727 R : constant Boolean := Referenced (E);
3730 Generate_Reference (E, N);
3731 Set_Referenced (E, R);
3734 -- Normal case, not a label. Generate reference
3737 Generate_Reference (E, N);
3740 -- Set Entity, with style check if need be. For a discriminant
3741 -- reference, replace by the corresponding discriminal, i.e. the
3742 -- parameter of the initialization procedure that corresponds to
3743 -- the discriminant. If this replacement is being performed, there
3744 -- is no style check to perform.
3746 -- This replacement must not be done if we are currently
3747 -- processing a generic spec or body, because the discriminal
3748 -- has not been not generated in this case.
3750 if not In_Default_Expression
3751 or else Ekind (E) /= E_Discriminant
3752 or else Inside_A_Generic
3754 Set_Entity_With_Style_Check (N, E);
3756 -- The replacement is not done either for a task discriminant that
3757 -- appears in a default expression of an entry parameter. See
3758 -- Expand_Discriminant in exp_ch2 for details on their handling.
3760 elsif Is_Concurrent_Type (Scope (E)) then
3767 and then Nkind (P) /= N_Parameter_Specification
3768 and then Nkind (P) /= N_Component_Declaration
3774 and then Nkind (P) = N_Parameter_Specification
3778 Set_Entity (N, Discriminal (E));
3782 -- Otherwise, this is a discriminant in a context in which
3783 -- it is a reference to the corresponding parameter of the
3784 -- init proc for the enclosing type.
3787 Set_Entity (N, Discriminal (E));
3791 end Find_Direct_Name;
3793 ------------------------
3794 -- Find_Expanded_Name --
3795 ------------------------
3797 -- This routine searches the homonym chain of the entity until it finds
3798 -- an entity declared in the scope denoted by the prefix. If the entity
3799 -- is private, it may nevertheless be immediately visible, if we are in
3800 -- the scope of its declaration.
3802 procedure Find_Expanded_Name (N : Node_Id) is
3803 Selector : constant Node_Id := Selector_Name (N);
3804 Candidate : Entity_Id := Empty;
3810 P_Name := Entity (Prefix (N));
3813 -- If the prefix is a renamed package, look for the entity
3814 -- in the original package.
3816 if Ekind (P_Name) = E_Package
3817 and then Present (Renamed_Object (P_Name))
3819 P_Name := Renamed_Object (P_Name);
3821 -- Rewrite node with entity field pointing to renamed object
3823 Rewrite (Prefix (N), New_Copy (Prefix (N)));
3824 Set_Entity (Prefix (N), P_Name);
3826 -- If the prefix is an object of a concurrent type, look for
3827 -- the entity in the associated task or protected type.
3829 elsif Is_Concurrent_Type (Etype (P_Name)) then
3830 P_Name := Etype (P_Name);
3833 Id := Current_Entity (Selector);
3836 Is_New_Candidate : Boolean;
3839 while Present (Id) loop
3840 if Scope (Id) = P_Name then
3842 Is_New_Candidate := True;
3844 -- Ada 2005 (AI-217): Handle shadow entities associated with types
3845 -- declared in limited-withed nested packages. We don't need to
3846 -- handle E_Incomplete_Subtype entities because the entities in
3847 -- the limited view are always E_Incomplete_Type entities (see
3848 -- Build_Limited_Views). Regarding the expression used to evaluate
3849 -- the scope, it is important to note that the limited view also
3850 -- has shadow entities associated nested packages. For this reason
3851 -- the correct scope of the entity is the scope of the real entity
3853 elsif From_With_Type (Id)
3854 and then Is_Type (Id)
3855 and then Ekind (Id) = E_Incomplete_Type
3856 and then Present (Non_Limited_View (Id))
3857 and then Scope (Non_Limited_View (Id)) = P_Name
3859 Candidate := Non_Limited_View (Id);
3860 Is_New_Candidate := True;
3863 Is_New_Candidate := False;
3866 if Is_New_Candidate then
3867 if Is_Child_Unit (Id) then
3868 exit when Is_Visible_Child_Unit (Id)
3869 or else Is_Immediately_Visible (Id);
3872 exit when not Is_Hidden (Id)
3873 or else Is_Immediately_Visible (Id);
3882 and then (Ekind (P_Name) = E_Procedure
3884 Ekind (P_Name) = E_Function)
3885 and then Is_Generic_Instance (P_Name)
3887 -- Expanded name denotes entity in (instance of) generic subprogram.
3888 -- The entity may be in the subprogram instance, or may denote one of
3889 -- the formals, which is declared in the enclosing wrapper package.
3891 P_Name := Scope (P_Name);
3893 Id := Current_Entity (Selector);
3894 while Present (Id) loop
3895 exit when Scope (Id) = P_Name;
3900 if No (Id) or else Chars (Id) /= Chars (Selector) then
3901 Set_Etype (N, Any_Type);
3903 -- If we are looking for an entity defined in System, try to
3904 -- find it in the child package that may have been provided as
3905 -- an extension to System. The Extend_System pragma will have
3906 -- supplied the name of the extension, which may have to be loaded.
3908 if Chars (P_Name) = Name_System
3909 and then Scope (P_Name) = Standard_Standard
3910 and then Present (System_Extend_Unit)
3911 and then Present_System_Aux (N)
3913 Set_Entity (Prefix (N), System_Aux_Id);
3914 Find_Expanded_Name (N);
3917 elsif Nkind (Selector) = N_Operator_Symbol
3918 and then Has_Implicit_Operator (N)
3920 -- There is an implicit instance of the predefined operator in
3921 -- the given scope. The operator entity is defined in Standard.
3922 -- Has_Implicit_Operator makes the node into an Expanded_Name.
3926 elsif Nkind (Selector) = N_Character_Literal
3927 and then Has_Implicit_Character_Literal (N)
3929 -- If there is no literal defined in the scope denoted by the
3930 -- prefix, the literal may belong to (a type derived from)
3931 -- Standard_Character, for which we have no explicit literals.
3936 -- If the prefix is a single concurrent object, use its
3937 -- name in the error message, rather than that of the
3940 if Is_Concurrent_Type (P_Name)
3941 and then Is_Internal_Name (Chars (P_Name))
3943 Error_Msg_Node_2 := Entity (Prefix (N));
3945 Error_Msg_Node_2 := P_Name;
3948 if P_Name = System_Aux_Id then
3949 P_Name := Scope (P_Name);
3950 Set_Entity (Prefix (N), P_Name);
3953 if Present (Candidate) then
3955 -- If we know that the unit is a child unit we can give a more
3956 -- accurate error message.
3958 if Is_Child_Unit (Candidate) then
3960 -- If the candidate is a private child unit and we are in
3961 -- the visible part of a public unit, specialize the error
3962 -- message. There might be a private with_clause for it,
3963 -- but it is not currently active.
3965 if Is_Private_Descendant (Candidate)
3966 and then Ekind (Current_Scope) = E_Package
3967 and then not In_Private_Part (Current_Scope)
3968 and then not Is_Private_Descendant (Current_Scope)
3970 Error_Msg_N ("private child unit& is not visible here",
3973 -- Normal case where we have a missing with for a child unit
3976 Error_Msg_Qual_Level := 99;
3977 Error_Msg_NE ("missing `WITH &;`", Selector, Candidate);
3978 Error_Msg_Qual_Level := 0;
3981 -- Here we don't know that this is a child unit
3984 Error_Msg_NE ("& is not a visible entity of&", N, Selector);
3988 -- Within the instantiation of a child unit, the prefix may
3989 -- denote the parent instance, but the selector has the name
3990 -- of the original child. Find whether we are within the
3991 -- corresponding instance, and get the proper entity, which
3992 -- can only be an enclosing scope.
3995 and then In_Open_Scopes (P_Name)
3996 and then Is_Generic_Instance (P_Name)
3999 S : Entity_Id := Current_Scope;
4003 for J in reverse 0 .. Scope_Stack.Last loop
4004 S := Scope_Stack.Table (J).Entity;
4006 exit when S = Standard_Standard;
4008 if Ekind (S) = E_Function
4009 or else Ekind (S) = E_Package
4010 or else Ekind (S) = E_Procedure
4012 P := Generic_Parent (Specification
4013 (Unit_Declaration_Node (S)));
4016 and then Chars (Scope (P)) = Chars (O_Name)
4017 and then Chars (P) = Chars (Selector)
4028 -- If this is a selection from Ada, System or Interfaces, then
4029 -- we assume a missing with for the corresponding package.
4031 if Is_Known_Unit (N) then
4032 Error_Msg_Node_2 := Selector;
4033 Error_Msg_N ("missing `WITH &.&;`", Prefix (N));
4035 -- If this is a selection from a dummy package, then suppress
4036 -- the error message, of course the entity is missing if the
4037 -- package is missing!
4039 elsif Sloc (Error_Msg_Node_2) = No_Location then
4042 -- Here we have the case of an undefined component
4045 Error_Msg_NE ("& not declared in&", N, Selector);
4047 -- Check for misspelling of some entity in prefix
4049 Id := First_Entity (P_Name);
4050 Get_Name_String (Chars (Selector));
4053 S : constant String (1 .. Name_Len) :=
4054 Name_Buffer (1 .. Name_Len);
4056 while Present (Id) loop
4057 Get_Name_String (Chars (Id));
4058 if Is_Bad_Spelling_Of
4059 (Name_Buffer (1 .. Name_Len), S)
4060 and then not Is_Internal_Name (Chars (Id))
4063 ("possible misspelling of&", Selector, Id);
4071 -- Specialize the message if this may be an instantiation
4072 -- of a child unit that was not mentioned in the context.
4074 if Nkind (Parent (N)) = N_Package_Instantiation
4075 and then Is_Generic_Instance (Entity (Prefix (N)))
4076 and then Is_Compilation_Unit
4077 (Generic_Parent (Parent (Entity (Prefix (N)))))
4079 Error_Msg_Node_2 := Selector;
4080 Error_Msg_N ("\missing `WITH &.&;`", Prefix (N));
4090 if Comes_From_Source (N)
4091 and then Is_Remote_Access_To_Subprogram_Type (Id)
4092 and then Present (Equivalent_Type (Id))
4094 -- If we are not actually generating distribution code (i.e. the
4095 -- current PCS is the dummy non-distributed version), then the
4096 -- Equivalent_Type will be missing, and Id should be treated as
4097 -- a regular access-to-subprogram type.
4099 Id := Equivalent_Type (Id);
4100 Set_Chars (Selector, Chars (Id));
4103 -- Ada 2005 (AI-50217): Check usage of entities in limited withed units
4105 if Ekind (P_Name) = E_Package
4106 and then From_With_Type (P_Name)
4108 if From_With_Type (Id)
4109 or else Is_Type (Id)
4110 or else Ekind (Id) = E_Package
4115 ("limited withed package can only be used to access "
4116 & " incomplete types",
4121 if Is_Task_Type (P_Name)
4122 and then ((Ekind (Id) = E_Entry
4123 and then Nkind (Parent (N)) /= N_Attribute_Reference)
4125 (Ekind (Id) = E_Entry_Family
4127 Nkind (Parent (Parent (N))) /= N_Attribute_Reference))
4129 -- It is an entry call after all, either to the current task (which
4130 -- will deadlock) or to an enclosing task.
4132 Analyze_Selected_Component (N);
4136 Change_Selected_Component_To_Expanded_Name (N);
4138 -- Do style check and generate reference, but skip both steps if this
4139 -- entity has homonyms, since we may not have the right homonym set yet.
4140 -- The proper homonym will be set during the resolve phase.
4142 if Has_Homonym (Id) then
4145 Set_Entity_With_Style_Check (N, Id);
4146 Generate_Reference (Id, N);
4149 if Is_Type (Id) then
4152 Set_Etype (N, Get_Full_View (Etype (Id)));
4155 -- If the Ekind of the entity is Void, it means that all homonyms are
4156 -- hidden from all visibility (RM 8.3(5,14-20)).
4158 if Ekind (Id) = E_Void then
4159 Premature_Usage (N);
4161 elsif Is_Overloadable (Id)
4162 and then Present (Homonym (Id))
4165 H : Entity_Id := Homonym (Id);
4168 while Present (H) loop
4169 if Scope (H) = Scope (Id)
4172 or else Is_Immediately_Visible (H))
4174 Collect_Interps (N);
4181 -- If an extension of System is present, collect possible explicit
4182 -- overloadings declared in the extension.
4184 if Chars (P_Name) = Name_System
4185 and then Scope (P_Name) = Standard_Standard
4186 and then Present (System_Extend_Unit)
4187 and then Present_System_Aux (N)
4189 H := Current_Entity (Id);
4191 while Present (H) loop
4192 if Scope (H) = System_Aux_Id then
4193 Add_One_Interp (N, H, Etype (H));
4202 if Nkind (Selector_Name (N)) = N_Operator_Symbol
4203 and then Scope (Id) /= Standard_Standard
4205 -- In addition to user-defined operators in the given scope, there
4206 -- may be an implicit instance of the predefined operator. The
4207 -- operator (defined in Standard) is found in Has_Implicit_Operator,
4208 -- and added to the interpretations. Procedure Add_One_Interp will
4209 -- determine which hides which.
4211 if Has_Implicit_Operator (N) then
4215 end Find_Expanded_Name;
4217 -------------------------
4218 -- Find_Renamed_Entity --
4219 -------------------------
4221 function Find_Renamed_Entity
4225 Is_Actual : Boolean := False) return Entity_Id
4228 I1 : Interp_Index := 0; -- Suppress junk warnings
4234 function Enclosing_Instance return Entity_Id;
4235 -- If the renaming determines the entity for the default of a formal
4236 -- subprogram nested within another instance, choose the innermost
4237 -- candidate. This is because if the formal has a box, and we are within
4238 -- an enclosing instance where some candidate interpretations are local
4239 -- to this enclosing instance, we know that the default was properly
4240 -- resolved when analyzing the generic, so we prefer the local
4241 -- candidates to those that are external. This is not always the case
4242 -- but is a reasonable heuristic on the use of nested generics. The
4243 -- proper solution requires a full renaming model.
4245 function Is_Visible_Operation (Op : Entity_Id) return Boolean;
4246 -- If the renamed entity is an implicit operator, check whether it is
4247 -- visible because its operand type is properly visible. This check
4248 -- applies to explicit renamed entities that appear in the source in a
4249 -- renaming declaration or a formal subprogram instance, but not to
4250 -- default generic actuals with a name.
4252 function Report_Overload return Entity_Id;
4253 -- List possible interpretations, and specialize message in the
4254 -- case of a generic actual.
4256 function Within (Inner, Outer : Entity_Id) return Boolean;
4257 -- Determine whether a candidate subprogram is defined within the
4258 -- enclosing instance. If yes, it has precedence over outer candidates.
4260 ------------------------
4261 -- Enclosing_Instance --
4262 ------------------------
4264 function Enclosing_Instance return Entity_Id is
4268 if not Is_Generic_Instance (Current_Scope)
4269 and then not Is_Actual
4274 S := Scope (Current_Scope);
4275 while S /= Standard_Standard loop
4276 if Is_Generic_Instance (S) then
4284 end Enclosing_Instance;
4286 --------------------------
4287 -- Is_Visible_Operation --
4288 --------------------------
4290 function Is_Visible_Operation (Op : Entity_Id) return Boolean is
4296 if Ekind (Op) /= E_Operator
4297 or else Scope (Op) /= Standard_Standard
4298 or else (In_Instance
4301 or else Present (Enclosing_Instance)))
4306 -- For a fixed point type operator, check the resulting type,
4307 -- because it may be a mixed mode integer * fixed operation.
4309 if Present (Next_Formal (First_Formal (New_S)))
4310 and then Is_Fixed_Point_Type (Etype (New_S))
4312 Typ := Etype (New_S);
4314 Typ := Etype (First_Formal (New_S));
4317 Btyp := Base_Type (Typ);
4319 if Nkind (Nam) /= N_Expanded_Name then
4320 return (In_Open_Scopes (Scope (Btyp))
4321 or else Is_Potentially_Use_Visible (Btyp)
4322 or else In_Use (Btyp)
4323 or else In_Use (Scope (Btyp)));
4326 Scop := Entity (Prefix (Nam));
4328 if Ekind (Scop) = E_Package
4329 and then Present (Renamed_Object (Scop))
4331 Scop := Renamed_Object (Scop);
4334 -- Operator is visible if prefix of expanded name denotes
4335 -- scope of type, or else type type is defined in System_Aux
4336 -- and the prefix denotes System.
4338 return Scope (Btyp) = Scop
4339 or else (Scope (Btyp) = System_Aux_Id
4340 and then Scope (Scope (Btyp)) = Scop);
4343 end Is_Visible_Operation;
4349 function Within (Inner, Outer : Entity_Id) return Boolean is
4353 Sc := Scope (Inner);
4354 while Sc /= Standard_Standard loop
4365 ---------------------
4366 -- Report_Overload --
4367 ---------------------
4369 function Report_Overload return Entity_Id is
4373 ("ambiguous actual subprogram&, " &
4374 "possible interpretations:", N, Nam);
4377 ("ambiguous subprogram, " &
4378 "possible interpretations:", N);
4381 List_Interps (Nam, N);
4383 end Report_Overload;
4385 -- Start of processing for Find_Renamed_Entry
4389 Candidate_Renaming := Empty;
4391 if not Is_Overloaded (Nam) then
4392 if Entity_Matches_Spec (Entity (Nam), New_S)
4393 and then Is_Visible_Operation (Entity (Nam))
4395 Old_S := Entity (Nam);
4398 Present (First_Formal (Entity (Nam)))
4399 and then Present (First_Formal (New_S))
4400 and then (Base_Type (Etype (First_Formal (Entity (Nam))))
4401 = Base_Type (Etype (First_Formal (New_S))))
4403 Candidate_Renaming := Entity (Nam);
4407 Get_First_Interp (Nam, Ind, It);
4408 while Present (It.Nam) loop
4409 if Entity_Matches_Spec (It.Nam, New_S)
4410 and then Is_Visible_Operation (It.Nam)
4412 if Old_S /= Any_Id then
4414 -- Note: The call to Disambiguate only happens if a
4415 -- previous interpretation was found, in which case I1
4416 -- has received a value.
4418 It1 := Disambiguate (Nam, I1, Ind, Etype (Old_S));
4420 if It1 = No_Interp then
4421 Inst := Enclosing_Instance;
4423 if Present (Inst) then
4424 if Within (It.Nam, Inst) then
4426 elsif Within (Old_S, Inst) then
4429 return Report_Overload;
4433 return Report_Overload;
4447 Present (First_Formal (It.Nam))
4448 and then Present (First_Formal (New_S))
4449 and then (Base_Type (Etype (First_Formal (It.Nam)))
4450 = Base_Type (Etype (First_Formal (New_S))))
4452 Candidate_Renaming := It.Nam;
4455 Get_Next_Interp (Ind, It);
4458 Set_Entity (Nam, Old_S);
4459 Set_Is_Overloaded (Nam, False);
4463 end Find_Renamed_Entity;
4465 -----------------------------
4466 -- Find_Selected_Component --
4467 -----------------------------
4469 procedure Find_Selected_Component (N : Node_Id) is
4470 P : constant Node_Id := Prefix (N);
4473 -- Entity denoted by prefix
4483 if Nkind (P) = N_Error then
4486 -- If the selector already has an entity, the node has been constructed
4487 -- in the course of expansion, and is known to be valid. Do not verify
4488 -- that it is defined for the type (it may be a private component used
4489 -- in the expansion of record equality).
4491 elsif Present (Entity (Selector_Name (N))) then
4494 or else Etype (N) = Any_Type
4497 Sel_Name : constant Node_Id := Selector_Name (N);
4498 Selector : constant Entity_Id := Entity (Sel_Name);
4502 Set_Etype (Sel_Name, Etype (Selector));
4504 if not Is_Entity_Name (P) then
4508 -- Build an actual subtype except for the first parameter
4509 -- of an init proc, where this actual subtype is by
4510 -- definition incorrect, since the object is uninitialized
4511 -- (and does not even have defined discriminants etc.)
4513 if Is_Entity_Name (P)
4514 and then Ekind (Entity (P)) = E_Function
4516 Nam := New_Copy (P);
4518 if Is_Overloaded (P) then
4519 Save_Interps (P, Nam);
4523 Make_Function_Call (Sloc (P), Name => Nam));
4525 Analyze_Selected_Component (N);
4528 elsif Ekind (Selector) = E_Component
4529 and then (not Is_Entity_Name (P)
4530 or else Chars (Entity (P)) /= Name_uInit)
4533 Build_Actual_Subtype_Of_Component (
4534 Etype (Selector), N);
4539 if No (C_Etype) then
4540 C_Etype := Etype (Selector);
4542 Insert_Action (N, C_Etype);
4543 C_Etype := Defining_Identifier (C_Etype);
4546 Set_Etype (N, C_Etype);
4549 -- If this is the name of an entry or protected operation, and
4550 -- the prefix is an access type, insert an explicit dereference,
4551 -- so that entry calls are treated uniformly.
4553 if Is_Access_Type (Etype (P))
4554 and then Is_Concurrent_Type (Designated_Type (Etype (P)))
4557 New_P : constant Node_Id :=
4558 Make_Explicit_Dereference (Sloc (P),
4559 Prefix => Relocate_Node (P));
4562 Set_Etype (P, Designated_Type (Etype (Prefix (P))));
4566 -- If the selected component appears within a default expression
4567 -- and it has an actual subtype, the pre-analysis has not yet
4568 -- completed its analysis, because Insert_Actions is disabled in
4569 -- that context. Within the init proc of the enclosing type we
4570 -- must complete this analysis, if an actual subtype was created.
4572 elsif Inside_Init_Proc then
4574 Typ : constant Entity_Id := Etype (N);
4575 Decl : constant Node_Id := Declaration_Node (Typ);
4577 if Nkind (Decl) = N_Subtype_Declaration
4578 and then not Analyzed (Decl)
4579 and then Is_List_Member (Decl)
4580 and then No (Parent (Decl))
4583 Insert_Action (N, Decl);
4590 elsif Is_Entity_Name (P) then
4591 P_Name := Entity (P);
4593 -- The prefix may denote an enclosing type which is the completion
4594 -- of an incomplete type declaration.
4596 if Is_Type (P_Name) then
4597 Set_Entity (P, Get_Full_View (P_Name));
4598 Set_Etype (P, Entity (P));
4599 P_Name := Entity (P);
4602 P_Type := Base_Type (Etype (P));
4604 if Debug_Flag_E then
4605 Write_Str ("Found prefix type to be ");
4606 Write_Entity_Info (P_Type, " "); Write_Eol;
4609 -- First check for components of a record object (not the
4610 -- result of a call, which is handled below).
4612 if Is_Appropriate_For_Record (P_Type)
4613 and then not Is_Overloadable (P_Name)
4614 and then not Is_Type (P_Name)
4616 -- Selected component of record. Type checking will validate
4617 -- name of selector.
4619 Analyze_Selected_Component (N);
4621 elsif Is_Appropriate_For_Entry_Prefix (P_Type)
4622 and then not In_Open_Scopes (P_Name)
4623 and then (not Is_Concurrent_Type (Etype (P_Name))
4624 or else not In_Open_Scopes (Etype (P_Name)))
4626 -- Call to protected operation or entry. Type checking is
4627 -- needed on the prefix.
4629 Analyze_Selected_Component (N);
4631 elsif (In_Open_Scopes (P_Name)
4632 and then Ekind (P_Name) /= E_Void
4633 and then not Is_Overloadable (P_Name))
4634 or else (Is_Concurrent_Type (Etype (P_Name))
4635 and then In_Open_Scopes (Etype (P_Name)))
4637 -- Prefix denotes an enclosing loop, block, or task, i.e. an
4638 -- enclosing construct that is not a subprogram or accept.
4640 Find_Expanded_Name (N);
4642 elsif Ekind (P_Name) = E_Package then
4643 Find_Expanded_Name (N);
4645 elsif Is_Overloadable (P_Name) then
4647 -- The subprogram may be a renaming (of an enclosing scope) as
4648 -- in the case of the name of the generic within an instantiation.
4650 if (Ekind (P_Name) = E_Procedure
4651 or else Ekind (P_Name) = E_Function)
4652 and then Present (Alias (P_Name))
4653 and then Is_Generic_Instance (Alias (P_Name))
4655 P_Name := Alias (P_Name);
4658 if Is_Overloaded (P) then
4660 -- The prefix must resolve to a unique enclosing construct
4663 Found : Boolean := False;
4668 Get_First_Interp (P, Ind, It);
4669 while Present (It.Nam) loop
4670 if In_Open_Scopes (It.Nam) then
4673 "prefix must be unique enclosing scope", N);
4674 Set_Entity (N, Any_Id);
4675 Set_Etype (N, Any_Type);
4684 Get_Next_Interp (Ind, It);
4689 if In_Open_Scopes (P_Name) then
4690 Set_Entity (P, P_Name);
4691 Set_Is_Overloaded (P, False);
4692 Find_Expanded_Name (N);
4695 -- If no interpretation as an expanded name is possible, it
4696 -- must be a selected component of a record returned by a
4697 -- function call. Reformat prefix as a function call, the rest
4698 -- is done by type resolution. If the prefix is procedure or
4699 -- entry, as is P.X; this is an error.
4701 if Ekind (P_Name) /= E_Function
4702 and then (not Is_Overloaded (P)
4704 Nkind (Parent (N)) = N_Procedure_Call_Statement)
4706 -- Prefix may mention a package that is hidden by a local
4707 -- declaration: let the user know. Scan the full homonym
4708 -- chain, the candidate package may be anywhere on it.
4710 if Present (Homonym (Current_Entity (P_Name))) then
4712 P_Name := Current_Entity (P_Name);
4714 while Present (P_Name) loop
4715 exit when Ekind (P_Name) = E_Package;
4716 P_Name := Homonym (P_Name);
4719 if Present (P_Name) then
4720 Error_Msg_Sloc := Sloc (Entity (Prefix (N)));
4723 ("package& is hidden by declaration#",
4726 Set_Entity (Prefix (N), P_Name);
4727 Find_Expanded_Name (N);
4730 P_Name := Entity (Prefix (N));
4735 ("invalid prefix in selected component&", N, P_Name);
4736 Change_Selected_Component_To_Expanded_Name (N);
4737 Set_Entity (N, Any_Id);
4738 Set_Etype (N, Any_Type);
4741 Nam := New_Copy (P);
4742 Save_Interps (P, Nam);
4744 Make_Function_Call (Sloc (P), Name => Nam));
4746 Analyze_Selected_Component (N);
4750 -- Remaining cases generate various error messages
4753 -- Format node as expanded name, to avoid cascaded errors
4755 Change_Selected_Component_To_Expanded_Name (N);
4756 Set_Entity (N, Any_Id);
4757 Set_Etype (N, Any_Type);
4759 -- Issue error message, but avoid this if error issued already.
4760 -- Use identifier of prefix if one is available.
4762 if P_Name = Any_Id then
4765 elsif Ekind (P_Name) = E_Void then
4766 Premature_Usage (P);
4768 elsif Nkind (P) /= N_Attribute_Reference then
4770 "invalid prefix in selected component&", P);
4772 if Is_Access_Type (P_Type)
4773 and then Ekind (Designated_Type (P_Type)) = E_Incomplete_Type
4776 ("\dereference must not be of an incomplete type " &
4777 "('R'M 3.10.1)", P);
4782 "invalid prefix in selected component", P);
4787 -- If prefix is not the name of an entity, it must be an expression,
4788 -- whose type is appropriate for a record. This is determined by
4791 Analyze_Selected_Component (N);
4793 end Find_Selected_Component;
4799 procedure Find_Type (N : Node_Id) is
4809 elsif Nkind (N) = N_Attribute_Reference then
4811 -- Class attribute. This is only valid in Ada 95 mode, but we don't
4812 -- do a check, since the tagged type referenced could only exist if
4813 -- we were in 95 mode when it was declared (or, if we were in Ada
4814 -- 83 mode, then an error message would already have been issued).
4816 if Attribute_Name (N) = Name_Class then
4817 Check_Restriction (No_Dispatch, N);
4818 Find_Type (Prefix (N));
4820 -- Propagate error from bad prefix
4822 if Etype (Prefix (N)) = Any_Type then
4823 Set_Entity (N, Any_Type);
4824 Set_Etype (N, Any_Type);
4828 T := Base_Type (Entity (Prefix (N)));
4830 -- Case type is not known to be tagged. Its appearance in the
4831 -- prefix of the 'Class attribute indicates that the full view
4834 if not Is_Tagged_Type (T) then
4835 if Ekind (T) = E_Incomplete_Type then
4837 -- It is legal to denote the class type of an incomplete
4838 -- type. The full type will have to be tagged, of course.
4840 Set_Is_Tagged_Type (T);
4841 Set_Primitive_Operations (T, New_Elmt_List);
4842 Make_Class_Wide_Type (T);
4843 Set_Entity (N, Class_Wide_Type (T));
4844 Set_Etype (N, Class_Wide_Type (T));
4846 elsif Ekind (T) = E_Private_Type
4847 and then not Is_Generic_Type (T)
4848 and then In_Private_Part (Scope (T))
4850 -- The Class attribute can be applied to an untagged private
4851 -- type fulfilled by a tagged type prior to the full type
4852 -- declaration (but only within the parent package's private
4853 -- part). Create the class-wide type now and check that the
4854 -- full type is tagged later during its analysis. Note that
4855 -- we do not mark the private type as tagged, unlike the
4856 -- case of incomplete types, because the type must still
4857 -- appear untagged to outside units.
4859 if No (Class_Wide_Type (T)) then
4860 Make_Class_Wide_Type (T);
4863 Set_Entity (N, Class_Wide_Type (T));
4864 Set_Etype (N, Class_Wide_Type (T));
4867 -- Should we introduce a type Any_Tagged and use Wrong_Type
4868 -- here, it would be a bit more consistent???
4871 ("tagged type required, found}",
4872 Prefix (N), First_Subtype (T));
4873 Set_Entity (N, Any_Type);
4877 -- Case of tagged type
4880 if Is_Concurrent_Type (T) then
4881 if No (Corresponding_Record_Type (Entity (Prefix (N)))) then
4883 -- Previous error. Use current type, which at least
4884 -- provides some operations.
4886 C := Entity (Prefix (N));
4889 C := Class_Wide_Type
4890 (Corresponding_Record_Type (Entity (Prefix (N))));
4894 C := Class_Wide_Type (Entity (Prefix (N)));
4897 Set_Entity_With_Style_Check (N, C);
4898 Generate_Reference (C, N);
4902 -- Base attribute, not allowed in Ada 83
4904 elsif Attribute_Name (N) = Name_Base then
4905 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
4907 ("(Ada 83) Base attribute not allowed in subtype mark", N);
4910 Find_Type (Prefix (N));
4911 Typ := Entity (Prefix (N));
4913 if Ada_Version >= Ada_95
4914 and then not Is_Scalar_Type (Typ)
4915 and then not Is_Generic_Type (Typ)
4918 ("prefix of Base attribute must be scalar type",
4921 elsif Sloc (Typ) = Standard_Location
4922 and then Base_Type (Typ) = Typ
4923 and then Warn_On_Redundant_Constructs
4926 ("?redudant attribute, & is its own base type", N, Typ);
4929 T := Base_Type (Typ);
4931 -- Rewrite attribute reference with type itself (see similar
4932 -- processing in Analyze_Attribute, case Base). Preserve
4933 -- prefix if present, for other legality checks.
4935 if Nkind (Prefix (N)) = N_Expanded_Name then
4937 Make_Expanded_Name (Sloc (N),
4938 Chars => Chars (Entity (N)),
4939 Prefix => New_Copy (Prefix (Prefix (N))),
4941 New_Reference_To (Entity (N), Sloc (N))));
4945 New_Reference_To (Entity (N), Sloc (N)));
4952 elsif Attribute_Name (N) = Name_Stub_Type then
4954 -- This is handled in Analyze_Attribute
4958 -- All other attributes are invalid in a subtype mark
4961 Error_Msg_N ("invalid attribute in subtype mark", N);
4967 if Is_Entity_Name (N) then
4968 T_Name := Entity (N);
4970 Error_Msg_N ("subtype mark required in this context", N);
4971 Set_Etype (N, Any_Type);
4975 if T_Name = Any_Id or else Etype (N) = Any_Type then
4977 -- Undefined id. Make it into a valid type
4979 Set_Entity (N, Any_Type);
4981 elsif not Is_Type (T_Name)
4982 and then T_Name /= Standard_Void_Type
4984 Error_Msg_Sloc := Sloc (T_Name);
4985 Error_Msg_N ("subtype mark required in this context", N);
4986 Error_Msg_NE ("\\found & declared#", N, T_Name);
4987 Set_Entity (N, Any_Type);
4990 T_Name := Get_Full_View (T_Name);
4992 if In_Open_Scopes (T_Name) then
4993 if Ekind (Base_Type (T_Name)) = E_Task_Type then
4995 -- In Ada 2005, a task name can be used in an access
4996 -- definition within its own body.
4998 if Ada_Version >= Ada_05
4999 and then Nkind (Parent (N)) = N_Access_Definition
5001 Set_Entity (N, T_Name);
5002 Set_Etype (N, T_Name);
5007 ("task type cannot be used as type mark " &
5008 "within its own body", N);
5011 Error_Msg_N ("type declaration cannot refer to itself", N);
5014 Set_Etype (N, Any_Type);
5015 Set_Entity (N, Any_Type);
5016 Set_Error_Posted (T_Name);
5020 Set_Entity (N, T_Name);
5021 Set_Etype (N, T_Name);
5025 if Present (Etype (N)) and then Comes_From_Source (N) then
5026 if Is_Fixed_Point_Type (Etype (N)) then
5027 Check_Restriction (No_Fixed_Point, N);
5028 elsif Is_Floating_Point_Type (Etype (N)) then
5029 Check_Restriction (No_Floating_Point, N);
5038 function Get_Full_View (T_Name : Entity_Id) return Entity_Id is
5040 if Ekind (T_Name) = E_Incomplete_Type
5041 and then Present (Full_View (T_Name))
5043 return Full_View (T_Name);
5045 elsif Is_Class_Wide_Type (T_Name)
5046 and then Ekind (Root_Type (T_Name)) = E_Incomplete_Type
5047 and then Present (Full_View (Root_Type (T_Name)))
5049 return Class_Wide_Type (Full_View (Root_Type (T_Name)));
5056 ------------------------------------
5057 -- Has_Implicit_Character_Literal --
5058 ------------------------------------
5060 function Has_Implicit_Character_Literal (N : Node_Id) return Boolean is
5062 Found : Boolean := False;
5063 P : constant Entity_Id := Entity (Prefix (N));
5064 Priv_Id : Entity_Id := Empty;
5067 if Ekind (P) = E_Package
5068 and then not In_Open_Scopes (P)
5070 Priv_Id := First_Private_Entity (P);
5073 if P = Standard_Standard then
5074 Change_Selected_Component_To_Expanded_Name (N);
5075 Rewrite (N, Selector_Name (N));
5077 Set_Etype (Original_Node (N), Standard_Character);
5081 Id := First_Entity (P);
5084 and then Id /= Priv_Id
5086 if Is_Character_Type (Id)
5087 and then (Root_Type (Id) = Standard_Character
5088 or else Root_Type (Id) = Standard_Wide_Character
5089 or else Root_Type (Id) = Standard_Wide_Wide_Character)
5090 and then Id = Base_Type (Id)
5092 -- We replace the node with the literal itself, resolve as a
5093 -- character, and set the type correctly.
5096 Change_Selected_Component_To_Expanded_Name (N);
5097 Rewrite (N, Selector_Name (N));
5100 Set_Etype (Original_Node (N), Id);
5104 -- More than one type derived from Character in given scope.
5105 -- Collect all possible interpretations.
5107 Add_One_Interp (N, Id, Id);
5115 end Has_Implicit_Character_Literal;
5117 ----------------------
5118 -- Has_Private_With --
5119 ----------------------
5121 function Has_Private_With (E : Entity_Id) return Boolean is
5122 Comp_Unit : constant Node_Id := Cunit (Current_Sem_Unit);
5126 Item := First (Context_Items (Comp_Unit));
5127 while Present (Item) loop
5128 if Nkind (Item) = N_With_Clause
5129 and then Private_Present (Item)
5130 and then Entity (Name (Item)) = E
5139 end Has_Private_With;
5141 ---------------------------
5142 -- Has_Implicit_Operator --
5143 ---------------------------
5145 function Has_Implicit_Operator (N : Node_Id) return Boolean is
5146 Op_Id : constant Name_Id := Chars (Selector_Name (N));
5147 P : constant Entity_Id := Entity (Prefix (N));
5149 Priv_Id : Entity_Id := Empty;
5151 procedure Add_Implicit_Operator
5153 Op_Type : Entity_Id := Empty);
5154 -- Add implicit interpretation to node N, using the type for which
5155 -- a predefined operator exists. If the operator yields a boolean
5156 -- type, the Operand_Type is implicitly referenced by the operator,
5157 -- and a reference to it must be generated.
5159 ---------------------------
5160 -- Add_Implicit_Operator --
5161 ---------------------------
5163 procedure Add_Implicit_Operator
5165 Op_Type : Entity_Id := Empty)
5167 Predef_Op : Entity_Id;
5170 Predef_Op := Current_Entity (Selector_Name (N));
5172 while Present (Predef_Op)
5173 and then Scope (Predef_Op) /= Standard_Standard
5175 Predef_Op := Homonym (Predef_Op);
5178 if Nkind (N) = N_Selected_Component then
5179 Change_Selected_Component_To_Expanded_Name (N);
5182 Add_One_Interp (N, Predef_Op, T);
5184 -- For operators with unary and binary interpretations, add both
5186 if Present (Homonym (Predef_Op)) then
5187 Add_One_Interp (N, Homonym (Predef_Op), T);
5190 -- The node is a reference to a predefined operator, and
5191 -- an implicit reference to the type of its operands.
5193 if Present (Op_Type) then
5194 Generate_Operator_Reference (N, Op_Type);
5196 Generate_Operator_Reference (N, T);
5198 end Add_Implicit_Operator;
5200 -- Start of processing for Has_Implicit_Operator
5203 if Ekind (P) = E_Package
5204 and then not In_Open_Scopes (P)
5206 Priv_Id := First_Private_Entity (P);
5209 Id := First_Entity (P);
5213 -- Boolean operators: an implicit declaration exists if the scope
5214 -- contains a declaration for a derived Boolean type, or for an
5215 -- array of Boolean type.
5217 when Name_Op_And | Name_Op_Not | Name_Op_Or | Name_Op_Xor =>
5218 while Id /= Priv_Id loop
5219 if Valid_Boolean_Arg (Id)
5220 and then Id = Base_Type (Id)
5222 Add_Implicit_Operator (Id);
5229 -- Equality: look for any non-limited type (result is Boolean)
5231 when Name_Op_Eq | Name_Op_Ne =>
5232 while Id /= Priv_Id loop
5234 and then not Is_Limited_Type (Id)
5235 and then Id = Base_Type (Id)
5237 Add_Implicit_Operator (Standard_Boolean, Id);
5244 -- Comparison operators: scalar type, or array of scalar
5246 when Name_Op_Lt | Name_Op_Le | Name_Op_Gt | Name_Op_Ge =>
5247 while Id /= Priv_Id loop
5248 if (Is_Scalar_Type (Id)
5249 or else (Is_Array_Type (Id)
5250 and then Is_Scalar_Type (Component_Type (Id))))
5251 and then Id = Base_Type (Id)
5253 Add_Implicit_Operator (Standard_Boolean, Id);
5260 -- Arithmetic operators: any numeric type
5270 while Id /= Priv_Id loop
5271 if Is_Numeric_Type (Id)
5272 and then Id = Base_Type (Id)
5274 Add_Implicit_Operator (Id);
5281 -- Concatenation: any one-dimensional array type
5283 when Name_Op_Concat =>
5284 while Id /= Priv_Id loop
5285 if Is_Array_Type (Id) and then Number_Dimensions (Id) = 1
5286 and then Id = Base_Type (Id)
5288 Add_Implicit_Operator (Id);
5295 -- What is the others condition here? Should we be using a
5296 -- subtype of Name_Id that would restrict to operators ???
5298 when others => null;
5301 -- If we fall through, then we do not have an implicit operator
5305 end Has_Implicit_Operator;
5307 --------------------
5308 -- In_Open_Scopes --
5309 --------------------
5311 function In_Open_Scopes (S : Entity_Id) return Boolean is
5313 -- Several scope stacks are maintained by Scope_Stack. The base of the
5314 -- currently active scope stack is denoted by the Is_Active_Stack_Base
5315 -- flag in the scope stack entry. Note that the scope stacks used to
5316 -- simply be delimited implicitly by the presence of Standard_Standard
5317 -- at their base, but there now are cases where this is not sufficient
5318 -- because Standard_Standard actually may appear in the middle of the
5319 -- active set of scopes.
5321 for J in reverse 0 .. Scope_Stack.Last loop
5322 if Scope_Stack.Table (J).Entity = S then
5326 -- Check Is_Active_Stack_Base to tell us when to stop, as there are
5327 -- cases where Standard_Standard appears in the middle of the active
5328 -- set of scopes. This affects the declaration and overriding of
5329 -- private inherited operations in instantiations of generic child
5332 exit when Scope_Stack.Table (J).Is_Active_Stack_Base;
5338 -----------------------------
5339 -- Inherit_Renamed_Profile --
5340 -----------------------------
5342 procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id) is
5349 if Ekind (Old_S) = E_Operator then
5350 New_F := First_Formal (New_S);
5352 while Present (New_F) loop
5353 Set_Etype (New_F, Base_Type (Etype (New_F)));
5354 Next_Formal (New_F);
5357 Set_Etype (New_S, Base_Type (Etype (New_S)));
5360 New_F := First_Formal (New_S);
5361 Old_F := First_Formal (Old_S);
5363 while Present (New_F) loop
5364 New_T := Etype (New_F);
5365 Old_T := Etype (Old_F);
5367 -- If the new type is a renaming of the old one, as is the
5368 -- case for actuals in instances, retain its name, to simplify
5369 -- later disambiguation.
5371 if Nkind (Parent (New_T)) = N_Subtype_Declaration
5372 and then Is_Entity_Name (Subtype_Indication (Parent (New_T)))
5373 and then Entity (Subtype_Indication (Parent (New_T))) = Old_T
5377 Set_Etype (New_F, Old_T);
5380 Next_Formal (New_F);
5381 Next_Formal (Old_F);
5384 if Ekind (Old_S) = E_Function
5385 or else Ekind (Old_S) = E_Enumeration_Literal
5387 Set_Etype (New_S, Etype (Old_S));
5390 end Inherit_Renamed_Profile;
5396 procedure Initialize is
5401 -------------------------
5402 -- Install_Use_Clauses --
5403 -------------------------
5405 procedure Install_Use_Clauses
5407 Force_Installation : Boolean := False)
5415 while Present (U) loop
5417 -- Case of USE package
5419 if Nkind (U) = N_Use_Package_Clause then
5420 P := First (Names (U));
5421 while Present (P) loop
5424 if Ekind (Id) = E_Package then
5426 Note_Redundant_Use (P);
5428 elsif Present (Renamed_Object (Id))
5429 and then In_Use (Renamed_Object (Id))
5431 Note_Redundant_Use (P);
5433 elsif Force_Installation or else Applicable_Use (P) then
5434 Use_One_Package (Id, U);
5445 P := First (Subtype_Marks (U));
5446 while Present (P) loop
5447 if not Is_Entity_Name (P)
5448 or else No (Entity (P))
5452 elsif Entity (P) /= Any_Type then
5460 Next_Use_Clause (U);
5462 end Install_Use_Clauses;
5464 -------------------------------------
5465 -- Is_Appropriate_For_Entry_Prefix --
5466 -------------------------------------
5468 function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean is
5469 P_Type : Entity_Id := T;
5472 if Is_Access_Type (P_Type) then
5473 P_Type := Designated_Type (P_Type);
5476 return Is_Task_Type (P_Type) or else Is_Protected_Type (P_Type);
5477 end Is_Appropriate_For_Entry_Prefix;
5479 -------------------------------
5480 -- Is_Appropriate_For_Record --
5481 -------------------------------
5483 function Is_Appropriate_For_Record (T : Entity_Id) return Boolean is
5485 function Has_Components (T1 : Entity_Id) return Boolean;
5486 -- Determine if given type has components (i.e. is either a record
5487 -- type or a type that has discriminants).
5489 --------------------
5490 -- Has_Components --
5491 --------------------
5493 function Has_Components (T1 : Entity_Id) return Boolean is
5495 return Is_Record_Type (T1)
5496 or else (Is_Private_Type (T1) and then Has_Discriminants (T1))
5497 or else (Is_Task_Type (T1) and then Has_Discriminants (T1))
5498 or else (Is_Incomplete_Type (T1)
5499 and then From_With_Type (T1)
5500 and then Present (Non_Limited_View (T1))
5501 and then Is_Record_Type (Non_Limited_View (T1)));
5504 -- Start of processing for Is_Appropriate_For_Record
5509 and then (Has_Components (T)
5510 or else (Is_Access_Type (T)
5511 and then Has_Components (Designated_Type (T))));
5512 end Is_Appropriate_For_Record;
5518 procedure New_Scope (S : Entity_Id) is
5522 if Ekind (S) = E_Void then
5525 -- Set scope depth if not a non-concurrent type, and we have not
5526 -- yet set the scope depth. This means that we have the first
5527 -- occurrence of the scope, and this is where the depth is set.
5529 elsif (not Is_Type (S) or else Is_Concurrent_Type (S))
5530 and then not Scope_Depth_Set (S)
5532 if S = Standard_Standard then
5533 Set_Scope_Depth_Value (S, Uint_0);
5535 elsif Is_Child_Unit (S) then
5536 Set_Scope_Depth_Value (S, Uint_1);
5538 elsif not Is_Record_Type (Current_Scope) then
5539 if Ekind (S) = E_Loop then
5540 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope));
5542 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope) + 1);
5547 Scope_Stack.Increment_Last;
5550 SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
5554 SST.Save_Scope_Suppress := Scope_Suppress;
5555 SST.Save_Local_Entity_Suppress := Local_Entity_Suppress.Last;
5557 if Scope_Stack.Last > Scope_Stack.First then
5558 SST.Component_Alignment_Default := Scope_Stack.Table
5559 (Scope_Stack.Last - 1).
5560 Component_Alignment_Default;
5563 SST.Last_Subprogram_Name := null;
5564 SST.Is_Transient := False;
5565 SST.Node_To_Be_Wrapped := Empty;
5566 SST.Pending_Freeze_Actions := No_List;
5567 SST.Actions_To_Be_Wrapped_Before := No_List;
5568 SST.Actions_To_Be_Wrapped_After := No_List;
5569 SST.First_Use_Clause := Empty;
5570 SST.Is_Active_Stack_Base := False;
5571 SST.Previous_Visibility := False;
5574 if Debug_Flag_W then
5575 Write_Str ("--> new scope: ");
5576 Write_Name (Chars (Current_Scope));
5577 Write_Str (", Id=");
5578 Write_Int (Int (Current_Scope));
5579 Write_Str (", Depth=");
5580 Write_Int (Int (Scope_Stack.Last));
5584 -- Copy from Scope (S) the categorization flags to S, this is not
5585 -- done in case Scope (S) is Standard_Standard since propagation
5586 -- is from library unit entity inwards.
5588 if S /= Standard_Standard
5589 and then Scope (S) /= Standard_Standard
5590 and then not Is_Child_Unit (S)
5594 if Nkind (E) not in N_Entity then
5598 -- We only propagate inwards for library level entities,
5599 -- inner level subprograms do not inherit the categorization.
5601 if Is_Library_Level_Entity (S) then
5602 Set_Is_Preelaborated (S, Is_Preelaborated (E));
5603 Set_Is_Shared_Passive (S, Is_Shared_Passive (E));
5604 Set_Categorization_From_Scope (E => S, Scop => E);
5609 ------------------------
5610 -- Note_Redundant_Use --
5611 ------------------------
5613 procedure Note_Redundant_Use (Clause : Node_Id) is
5614 Pack_Name : constant Entity_Id := Entity (Clause);
5615 Cur_Use : constant Node_Id := Current_Use_Clause (Pack_Name);
5616 Decl : constant Node_Id := Parent (Clause);
5618 Prev_Use : Node_Id := Empty;
5619 Redundant : Node_Id := Empty;
5620 -- The Use_Clause which is actually redundant. In the simplest case
5621 -- it is Pack itself, but when we compile a body we install its
5622 -- context before that of its spec, in which case it is the use_clause
5623 -- in the spec that will appear to be redundant, and we want the
5624 -- warning to be placed on the body. Similar complications appear when
5625 -- the redundancy is between a child unit and one of its ancestors.
5628 Set_Redundant_Use (Clause, True);
5630 if not Comes_From_Source (Clause)
5632 or else not Warn_On_Redundant_Constructs
5637 if not Is_Compilation_Unit (Current_Scope) then
5639 -- If the use_clause is in an inner scope, it is made redundant
5640 -- by some clause in the current context, with one exception:
5641 -- If we're compiling a nested package body, and the use_clause
5642 -- comes from the corresponding spec, the clause is not necessarily
5643 -- fully redundant, so we should not warn. If a warning was
5644 -- warranted, it would have been given when the spec was processed.
5646 if Nkind (Parent (Decl)) = N_Package_Specification then
5648 Package_Spec_Entity : constant Entity_Id :=
5649 Defining_Unit_Name (Parent (Decl));
5651 if In_Package_Body (Package_Spec_Entity) then
5657 Redundant := Clause;
5658 Prev_Use := Cur_Use;
5660 elsif Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body then
5662 Cur_Unit : constant Unit_Number_Type := Get_Source_Unit (Cur_Use);
5663 New_Unit : constant Unit_Number_Type := Get_Source_Unit (Clause);
5667 if Cur_Unit = New_Unit then
5669 -- Redundant clause in same body
5671 Redundant := Clause;
5672 Prev_Use := Cur_Use;
5674 elsif Cur_Unit = Current_Sem_Unit then
5676 -- If the new clause is not in the current unit it has been
5677 -- analyzed first, and it makes the other one redundant.
5678 -- However, if the new clause appears in a subunit, Cur_Unit
5679 -- is still the parent, and in that case the redundant one
5680 -- is the one appearing in the subunit.
5682 if Nkind (Unit (Cunit (New_Unit))) = N_Subunit then
5683 Redundant := Clause;
5684 Prev_Use := Cur_Use;
5686 -- Most common case: redundant clause in body,
5687 -- original clause in spec. Current scope is spec entity.
5692 Unit (Library_Unit (Cunit (Current_Sem_Unit))))
5694 Redundant := Cur_Use;
5698 -- The new clause may appear in an unrelated unit, when
5699 -- the parents of a generic are being installed prior to
5700 -- instantiation. In this case there must be no warning.
5701 -- We detect this case by checking whether the current top
5702 -- of the stack is related to the current compilation.
5704 Scop := Current_Scope;
5705 while Present (Scop)
5706 and then Scop /= Standard_Standard
5708 if Is_Compilation_Unit (Scop)
5709 and then not Is_Child_Unit (Scop)
5713 elsif Scop = Cunit_Entity (Current_Sem_Unit) then
5717 Scop := Scope (Scop);
5720 Redundant := Cur_Use;
5724 elsif New_Unit = Current_Sem_Unit then
5725 Redundant := Clause;
5726 Prev_Use := Cur_Use;
5729 -- Neither is the current unit, so they appear in parent or
5730 -- sibling units. Warning will be emitted elsewhere.
5736 elsif Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
5737 and then Present (Parent_Spec (Unit (Cunit (Current_Sem_Unit))))
5739 -- Use_clause is in child unit of current unit, and the child
5740 -- unit appears in the context of the body of the parent, so it
5741 -- has been installed first, even though it is the redundant one.
5742 -- Depending on their placement in the context, the visible or the
5743 -- private parts of the two units, either might appear as redundant,
5744 -- but the message has to be on the current unit.
5746 if Get_Source_Unit (Cur_Use) = Current_Sem_Unit then
5747 Redundant := Cur_Use;
5750 Redundant := Clause;
5751 Prev_Use := Cur_Use;
5754 -- If the new use clause appears in the private part of a parent unit
5755 -- it may appear to be redudant w.r.t. a use clause in a child unit,
5756 -- but the previous use clause was needed in the visible part of the
5757 -- child, and no warning should be emitted.
5759 if Nkind (Parent (Decl)) = N_Package_Specification
5761 List_Containing (Decl) = Private_Declarations (Parent (Decl))
5764 Par : constant Entity_Id := Defining_Entity (Parent (Decl));
5765 Spec : constant Node_Id :=
5766 Specification (Unit (Cunit (Current_Sem_Unit)));
5769 if Is_Compilation_Unit (Par)
5770 and then Par /= Cunit_Entity (Current_Sem_Unit)
5771 and then Parent (Cur_Use) = Spec
5773 List_Containing (Cur_Use) = Visible_Declarations (Spec)
5784 if Present (Redundant) then
5785 Error_Msg_Sloc := Sloc (Prev_Use);
5787 "& is already use_visible through declaration #?",
5788 Redundant, Pack_Name);
5790 end Note_Redundant_Use;
5796 procedure Pop_Scope is
5797 SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
5800 if Debug_Flag_E then
5804 Scope_Suppress := SST.Save_Scope_Suppress;
5805 Local_Entity_Suppress.Set_Last (SST.Save_Local_Entity_Suppress);
5807 if Debug_Flag_W then
5808 Write_Str ("--> exiting scope: ");
5809 Write_Name (Chars (Current_Scope));
5810 Write_Str (", Depth=");
5811 Write_Int (Int (Scope_Stack.Last));
5815 End_Use_Clauses (SST.First_Use_Clause);
5817 -- If the actions to be wrapped are still there they will get lost
5818 -- causing incomplete code to be generated. It is better to abort in
5819 -- this case (and we do the abort even with assertions off since the
5820 -- penalty is incorrect code generation)
5822 if SST.Actions_To_Be_Wrapped_Before /= No_List
5824 SST.Actions_To_Be_Wrapped_After /= No_List
5829 -- Free last subprogram name if allocated, and pop scope
5831 Free (SST.Last_Subprogram_Name);
5832 Scope_Stack.Decrement_Last;
5835 ---------------------
5836 -- Premature_Usage --
5837 ---------------------
5839 procedure Premature_Usage (N : Node_Id) is
5840 Kind : constant Node_Kind := Nkind (Parent (Entity (N)));
5841 E : Entity_Id := Entity (N);
5844 -- Within an instance, the analysis of the actual for a formal object
5845 -- does not see the name of the object itself. This is significant only
5846 -- if the object is an aggregate, where its analysis does not do any
5847 -- name resolution on component associations. (see 4717-008). In such a
5848 -- case, look for the visible homonym on the chain.
5851 and then Present (Homonym (E))
5856 and then not In_Open_Scopes (Scope (E))
5863 Set_Etype (N, Etype (E));
5868 if Kind = N_Component_Declaration then
5870 ("component&! cannot be used before end of record declaration", N);
5872 elsif Kind = N_Parameter_Specification then
5874 ("formal parameter&! cannot be used before end of specification",
5877 elsif Kind = N_Discriminant_Specification then
5879 ("discriminant&! cannot be used before end of discriminant part",
5882 elsif Kind = N_Procedure_Specification
5883 or else Kind = N_Function_Specification
5886 ("subprogram&! cannot be used before end of its declaration",
5890 ("object& cannot be used before end of its declaration!", N);
5892 end Premature_Usage;
5894 ------------------------
5895 -- Present_System_Aux --
5896 ------------------------
5898 function Present_System_Aux (N : Node_Id := Empty) return Boolean is
5901 Unum : Unit_Number_Type;
5906 function Find_System (C_Unit : Node_Id) return Entity_Id;
5907 -- Scan context clause of compilation unit to find with_clause
5914 function Find_System (C_Unit : Node_Id) return Entity_Id is
5915 With_Clause : Node_Id;
5918 With_Clause := First (Context_Items (C_Unit));
5919 while Present (With_Clause) loop
5920 if (Nkind (With_Clause) = N_With_Clause
5921 and then Chars (Name (With_Clause)) = Name_System)
5922 and then Comes_From_Source (With_Clause)
5933 -- Start of processing for Present_System_Aux
5936 -- The child unit may have been loaded and analyzed already
5938 if Present (System_Aux_Id) then
5941 -- If no previous pragma for System.Aux, nothing to load
5943 elsif No (System_Extend_Unit) then
5946 -- Use the unit name given in the pragma to retrieve the unit.
5947 -- Verify that System itself appears in the context clause of the
5948 -- current compilation. If System is not present, an error will
5949 -- have been reported already.
5952 With_Sys := Find_System (Cunit (Current_Sem_Unit));
5954 The_Unit := Unit (Cunit (Current_Sem_Unit));
5957 and then (Nkind (The_Unit) = N_Package_Body
5958 or else (Nkind (The_Unit) = N_Subprogram_Body
5959 and then not Acts_As_Spec (Cunit (Current_Sem_Unit))))
5961 With_Sys := Find_System (Library_Unit (Cunit (Current_Sem_Unit)));
5965 and then Present (N)
5967 -- If we are compiling a subunit, we need to examine its
5968 -- context as well (Current_Sem_Unit is the parent unit);
5970 The_Unit := Parent (N);
5972 while Nkind (The_Unit) /= N_Compilation_Unit loop
5973 The_Unit := Parent (The_Unit);
5976 if Nkind (Unit (The_Unit)) = N_Subunit then
5977 With_Sys := Find_System (The_Unit);
5981 if No (With_Sys) then
5985 Loc := Sloc (With_Sys);
5986 Get_Name_String (Chars (Expression (System_Extend_Unit)));
5987 Name_Buffer (8 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
5988 Name_Buffer (1 .. 7) := "system.";
5989 Name_Buffer (Name_Len + 8) := '%';
5990 Name_Buffer (Name_Len + 9) := 's';
5991 Name_Len := Name_Len + 9;
5992 Aux_Name := Name_Find;
5996 (Load_Name => Aux_Name,
5999 Error_Node => With_Sys);
6001 if Unum /= No_Unit then
6002 Semantics (Cunit (Unum));
6004 Defining_Entity (Specification (Unit (Cunit (Unum))));
6007 Make_With_Clause (Loc,
6009 Make_Expanded_Name (Loc,
6010 Chars => Chars (System_Aux_Id),
6011 Prefix => New_Reference_To (Scope (System_Aux_Id), Loc),
6012 Selector_Name => New_Reference_To (System_Aux_Id, Loc)));
6014 Set_Entity (Name (Withn), System_Aux_Id);
6016 Set_Library_Unit (Withn, Cunit (Unum));
6017 Set_Corresponding_Spec (Withn, System_Aux_Id);
6018 Set_First_Name (Withn, True);
6019 Set_Implicit_With (Withn, True);
6021 Insert_After (With_Sys, Withn);
6022 Mark_Rewrite_Insertion (Withn);
6023 Set_Context_Installed (Withn);
6027 -- Here if unit load failed
6030 Error_Msg_Name_1 := Name_System;
6031 Error_Msg_Name_2 := Chars (Expression (System_Extend_Unit));
6033 ("extension package `%.%` does not exist",
6034 Opt.System_Extend_Unit);
6038 end Present_System_Aux;
6040 -------------------------
6041 -- Restore_Scope_Stack --
6042 -------------------------
6044 procedure Restore_Scope_Stack (Handle_Use : Boolean := True) is
6047 Comp_Unit : Node_Id;
6048 In_Child : Boolean := False;
6049 Full_Vis : Boolean := True;
6050 SS_Last : constant Int := Scope_Stack.Last;
6053 -- Restore visibility of previous scope stack, if any
6055 for J in reverse 0 .. Scope_Stack.Last loop
6056 exit when Scope_Stack.Table (J).Entity = Standard_Standard
6057 or else No (Scope_Stack.Table (J).Entity);
6059 S := Scope_Stack.Table (J).Entity;
6061 if not Is_Hidden_Open_Scope (S) then
6063 -- If the parent scope is hidden, its entities are hidden as
6064 -- well, unless the entity is the instantiation currently
6067 if not Is_Hidden_Open_Scope (Scope (S))
6068 or else not Analyzed (Parent (S))
6069 or else Scope (S) = Standard_Standard
6071 Set_Is_Immediately_Visible (S, True);
6074 E := First_Entity (S);
6075 while Present (E) loop
6076 if Is_Child_Unit (E) then
6077 Set_Is_Immediately_Visible (E,
6078 Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
6080 Set_Is_Immediately_Visible (E, True);
6085 if not Full_Vis then
6086 exit when E = First_Private_Entity (S);
6090 -- The visibility of child units (siblings of current compilation)
6091 -- must be restored in any case. Their declarations may appear
6092 -- after the private part of the parent.
6094 if not Full_Vis then
6095 while Present (E) loop
6096 if Is_Child_Unit (E) then
6097 Set_Is_Immediately_Visible (E,
6098 Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
6106 if Is_Child_Unit (S)
6107 and not In_Child -- check only for current unit.
6111 -- restore visibility of parents according to whether the child
6112 -- is private and whether we are in its visible part.
6114 Comp_Unit := Parent (Unit_Declaration_Node (S));
6116 if Nkind (Comp_Unit) = N_Compilation_Unit
6117 and then Private_Present (Comp_Unit)
6121 elsif (Ekind (S) = E_Package
6122 or else Ekind (S) = E_Generic_Package)
6123 and then (In_Private_Part (S)
6124 or else In_Package_Body (S))
6128 elsif (Ekind (S) = E_Procedure
6129 or else Ekind (S) = E_Function)
6130 and then Has_Completion (S)
6141 if SS_Last >= Scope_Stack.First
6142 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
6145 Install_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
6147 end Restore_Scope_Stack;
6149 ----------------------
6150 -- Save_Scope_Stack --
6151 ----------------------
6153 procedure Save_Scope_Stack (Handle_Use : Boolean := True) is
6156 SS_Last : constant Int := Scope_Stack.Last;
6159 if SS_Last >= Scope_Stack.First
6160 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
6163 End_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
6166 -- If the call is from within a compilation unit, as when called from
6167 -- Rtsfind, make current entries in scope stack invisible while we
6168 -- analyze the new unit.
6170 for J in reverse 0 .. SS_Last loop
6171 exit when Scope_Stack.Table (J).Entity = Standard_Standard
6172 or else No (Scope_Stack.Table (J).Entity);
6174 S := Scope_Stack.Table (J).Entity;
6175 Set_Is_Immediately_Visible (S, False);
6177 E := First_Entity (S);
6178 while Present (E) loop
6179 Set_Is_Immediately_Visible (E, False);
6185 end Save_Scope_Stack;
6191 procedure Set_Use (L : List_Id) is
6193 Pack_Name : Node_Id;
6200 while Present (Decl) loop
6201 if Nkind (Decl) = N_Use_Package_Clause then
6202 Chain_Use_Clause (Decl);
6204 Pack_Name := First (Names (Decl));
6205 while Present (Pack_Name) loop
6206 Pack := Entity (Pack_Name);
6208 if Ekind (Pack) = E_Package
6209 and then Applicable_Use (Pack_Name)
6211 Use_One_Package (Pack, Decl);
6217 elsif Nkind (Decl) = N_Use_Type_Clause then
6218 Chain_Use_Clause (Decl);
6220 Id := First (Subtype_Marks (Decl));
6221 while Present (Id) loop
6222 if Entity (Id) /= Any_Type then
6235 ---------------------
6236 -- Use_One_Package --
6237 ---------------------
6239 procedure Use_One_Package (P : Entity_Id; N : Node_Id) is
6242 Current_Instance : Entity_Id := Empty;
6244 Private_With_OK : Boolean := False;
6247 if Ekind (P) /= E_Package then
6252 Set_Current_Use_Clause (P, N);
6254 -- Ada 2005 (AI-50217): Check restriction
6256 if From_With_Type (P) then
6257 Error_Msg_N ("limited withed package cannot appear in use clause", N);
6260 -- Find enclosing instance, if any
6263 Current_Instance := Current_Scope;
6264 while not Is_Generic_Instance (Current_Instance) loop
6265 Current_Instance := Scope (Current_Instance);
6268 if No (Hidden_By_Use_Clause (N)) then
6269 Set_Hidden_By_Use_Clause (N, New_Elmt_List);
6273 -- If unit is a package renaming, indicate that the renamed
6274 -- package is also in use (the flags on both entities must
6275 -- remain consistent, and a subsequent use of either of them
6276 -- should be recognized as redundant).
6278 if Present (Renamed_Object (P)) then
6279 Set_In_Use (Renamed_Object (P));
6280 Set_Current_Use_Clause (Renamed_Object (P), N);
6281 Real_P := Renamed_Object (P);
6286 -- Ada 2005 (AI-262): Check the use_clause of a private withed package
6287 -- found in the private part of a package specification
6289 if In_Private_Part (Current_Scope)
6290 and then Has_Private_With (P)
6291 and then Is_Child_Unit (Current_Scope)
6292 and then Is_Child_Unit (P)
6293 and then Is_Ancestor_Package (Scope (Current_Scope), P)
6295 Private_With_OK := True;
6298 -- Loop through entities in one package making them potentially
6301 Id := First_Entity (P);
6303 and then (Id /= First_Private_Entity (P)
6304 or else Private_With_OK) -- Ada 2005 (AI-262)
6306 Prev := Current_Entity (Id);
6307 while Present (Prev) loop
6308 if Is_Immediately_Visible (Prev)
6309 and then (not Is_Overloadable (Prev)
6310 or else not Is_Overloadable (Id)
6311 or else (Type_Conformant (Id, Prev)))
6313 if No (Current_Instance) then
6315 -- Potentially use-visible entity remains hidden
6317 goto Next_Usable_Entity;
6319 -- A use clause within an instance hides outer global entities,
6320 -- which are not used to resolve local entities in the
6321 -- instance. Note that the predefined entities in Standard
6322 -- could not have been hidden in the generic by a use clause,
6323 -- and therefore remain visible. Other compilation units whose
6324 -- entities appear in Standard must be hidden in an instance.
6326 -- To determine whether an entity is external to the instance
6327 -- we compare the scope depth of its scope with that of the
6328 -- current instance. However, a generic actual of a subprogram
6329 -- instance is declared in the wrapper package but will not be
6330 -- hidden by a use-visible entity.
6332 -- If Id is called Standard, the predefined package with the
6333 -- same name is in the homonym chain. It has to be ignored
6334 -- because it has no defined scope (being the only entity in
6335 -- the system with this mandated behavior).
6337 elsif not Is_Hidden (Id)
6338 and then Present (Scope (Prev))
6339 and then not Is_Wrapper_Package (Scope (Prev))
6340 and then Scope_Depth (Scope (Prev)) <
6341 Scope_Depth (Current_Instance)
6342 and then (Scope (Prev) /= Standard_Standard
6343 or else Sloc (Prev) > Standard_Location)
6345 Set_Is_Potentially_Use_Visible (Id);
6346 Set_Is_Immediately_Visible (Prev, False);
6347 Append_Elmt (Prev, Hidden_By_Use_Clause (N));
6350 -- A user-defined operator is not use-visible if the predefined
6351 -- operator for the type is immediately visible, which is the case
6352 -- if the type of the operand is in an open scope. This does not
6353 -- apply to user-defined operators that have operands of different
6354 -- types, because the predefined mixed mode operations (multiply
6355 -- and divide) apply to universal types and do not hide anything.
6357 elsif Ekind (Prev) = E_Operator
6358 and then Operator_Matches_Spec (Prev, Id)
6359 and then In_Open_Scopes
6360 (Scope (Base_Type (Etype (First_Formal (Id)))))
6361 and then (No (Next_Formal (First_Formal (Id)))
6362 or else Etype (First_Formal (Id))
6363 = Etype (Next_Formal (First_Formal (Id)))
6364 or else Chars (Prev) = Name_Op_Expon)
6366 goto Next_Usable_Entity;
6369 Prev := Homonym (Prev);
6372 -- On exit, we know entity is not hidden, unless it is private
6374 if not Is_Hidden (Id)
6375 and then ((not Is_Child_Unit (Id))
6376 or else Is_Visible_Child_Unit (Id))
6378 Set_Is_Potentially_Use_Visible (Id);
6380 if Is_Private_Type (Id)
6381 and then Present (Full_View (Id))
6383 Set_Is_Potentially_Use_Visible (Full_View (Id));
6387 <<Next_Usable_Entity>>
6391 -- Child units are also made use-visible by a use clause, but they may
6392 -- appear after all visible declarations in the parent entity list.
6394 while Present (Id) loop
6395 if Is_Child_Unit (Id)
6396 and then Is_Visible_Child_Unit (Id)
6398 Set_Is_Potentially_Use_Visible (Id);
6404 if Chars (Real_P) = Name_System
6405 and then Scope (Real_P) = Standard_Standard
6406 and then Present_System_Aux (N)
6408 Use_One_Package (System_Aux_Id, N);
6411 end Use_One_Package;
6417 procedure Use_One_Type (Id : Node_Id) is
6423 -- It is the type determined by the subtype mark (8.4(8)) whose
6424 -- operations become potentially use-visible.
6426 T := Base_Type (Entity (Id));
6431 or else Is_Potentially_Use_Visible (T)
6432 or else In_Use (Scope (T)));
6434 if In_Open_Scopes (Scope (T)) then
6437 elsif From_With_Type (T) then
6439 ("incomplete type from limited view "
6440 & "cannot appear in use clause", Id);
6442 -- If the subtype mark designates a subtype in a different package,
6443 -- we have to check that the parent type is visible, otherwise the
6444 -- use type clause is a noop. Not clear how to do that???
6446 elsif not Redundant_Use (Id) then
6448 Op_List := Collect_Primitive_Operations (T);
6450 Elmt := First_Elmt (Op_List);
6451 while Present (Elmt) loop
6452 if (Nkind (Node (Elmt)) = N_Defining_Operator_Symbol
6453 or else Chars (Node (Elmt)) in Any_Operator_Name)
6454 and then not Is_Hidden (Node (Elmt))
6456 Set_Is_Potentially_Use_Visible (Node (Elmt));
6468 procedure Write_Info is
6469 Id : Entity_Id := First_Entity (Current_Scope);
6472 -- No point in dumping standard entities
6474 if Current_Scope = Standard_Standard then
6478 Write_Str ("========================================================");
6480 Write_Str (" Defined Entities in ");
6481 Write_Name (Chars (Current_Scope));
6483 Write_Str ("========================================================");
6487 Write_Str ("-- none --");
6491 while Present (Id) loop
6492 Write_Entity_Info (Id, " ");
6497 if Scope (Current_Scope) = Standard_Standard then
6499 -- Print information on the current unit itself
6501 Write_Entity_Info (Current_Scope, " ");
6511 procedure Write_Scopes is
6514 for J in reverse 1 .. Scope_Stack.Last loop
6515 S := Scope_Stack.Table (J).Entity;
6516 Write_Int (Int (S));
6517 Write_Str (" === ");
6518 Write_Name (Chars (S));