1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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 -- Complete analysis of the subtype mark in any case, for ASIS use.
726 if Present (Subtype_Mark (N)) then
727 Find_Type (Subtype_Mark (N));
730 elsif Present (Subtype_Mark (N)) then
731 Find_Type (Subtype_Mark (N));
732 T := Entity (Subtype_Mark (N));
735 if Nkind (Nam) = N_Type_Conversion
736 and then not Is_Tagged_Type (T)
739 ("renaming of conversion only allowed for tagged types", Nam);
744 -- Ada 2005 (AI-230/AI-254): Access renaming
746 else pragma Assert (Present (Access_Definition (N)));
747 T := Access_Definition
749 N => Access_Definition (N));
751 Analyze_And_Resolve (Nam, T);
753 -- Ada 2005 (AI-231): "In the case where the type is defined by an
754 -- access_definition, the renamed entity shall be of an access-to-
755 -- constant type if and only if the access_definition defines an
756 -- access-to-constant type" ARM 8.5.1(4)
758 if Constant_Present (Access_Definition (N))
759 and then not Is_Access_Constant (Etype (Nam))
761 Error_Msg_N ("(Ada 2005): the renamed object is not "
762 & "access-to-constant ('R'M 8.5.1(6))", N);
766 -- Special processing for renaming function return object
768 if Nkind (Nam) = N_Function_Call
769 and then Comes_From_Source (Nam)
773 -- Usage is illegal in Ada 83
777 ("(Ada 83) cannot rename function return object", Nam);
779 -- In Ada 95, warn for odd case of renaming parameterless function
780 -- call if this is not a limited type (where this is useful)
783 if Warn_On_Object_Renames_Function
784 and then No (Parameter_Associations (Nam))
785 and then not Is_Limited_Type (Etype (Nam))
788 ("?renaming function result object is suspicious",
791 ("\?function & will be called only once",
792 Nam, Entity (Name (Nam)));
794 ("\?suggest using an initialized constant object instead",
800 -- An object renaming requires an exact match of the type. Class-wide
801 -- matching is not allowed.
803 if Is_Class_Wide_Type (T)
804 and then Base_Type (Etype (Nam)) /= Base_Type (T)
811 -- (Ada 2005: AI-326): Handle wrong use of incomplete type
813 if Nkind (Nam) = N_Explicit_Dereference
814 and then Ekind (Etype (T2)) = E_Incomplete_Type
816 Error_Msg_N ("invalid use of incomplete type", Id);
822 if Ada_Version >= Ada_05
823 and then Nkind (Nam) = N_Attribute_Reference
824 and then Attribute_Name (Nam) = Name_Priority
828 elsif Ada_Version >= Ada_05
829 and then Nkind (Nam) in N_Has_Entity
832 Error_Node : Node_Id;
835 Subtyp_Decl : Node_Id;
838 if Nkind (Nam) = N_Attribute_Reference then
839 Nam_Ent := Entity (Prefix (Nam));
841 Nam_Ent := Entity (Nam);
844 Nam_Decl := Parent (Nam_Ent);
845 Subtyp_Decl := Parent (Etype (Nam_Ent));
847 if Has_Null_Exclusion (N)
848 and then not Has_Null_Exclusion (Nam_Decl)
850 -- Ada 2005 (AI-423): If the object name denotes a generic
851 -- formal object of a generic unit G, and the object renaming
852 -- declaration occurs within the body of G or within the body
853 -- of a generic unit declared within the declarative region
854 -- of G, then the declaration of the formal object of G must
855 -- have a null exclusion.
857 if Is_Formal_Object (Nam_Ent)
858 and then In_Generic_Scope (Id)
860 if Present (Subtype_Mark (Nam_Decl)) then
861 Error_Node := Subtype_Mark (Nam_Decl);
864 (Ada_Version >= Ada_05
865 and then Present (Access_Definition (Nam_Decl)));
867 Error_Node := Access_Definition (Nam_Decl);
871 ("`NOT NULL` required in formal object declaration",
873 Error_Msg_Sloc := Sloc (N);
875 ("\because of renaming at# ('R'M 8.5.4(4))", Error_Node);
877 -- Ada 2005 (AI-423): Otherwise, the subtype of the object name
878 -- shall exclude null.
880 elsif Nkind (Subtyp_Decl) = N_Subtype_Declaration
881 and then not Has_Null_Exclusion (Subtyp_Decl)
884 ("`NOT NULL` required for subtype & ('R'M 8.5.1(4.6/2))",
885 Defining_Identifier (Subtyp_Decl));
891 Set_Ekind (Id, E_Variable);
892 Init_Size_Align (Id);
894 if T = Any_Type or else Etype (Nam) = Any_Type then
897 -- Verify that the renamed entity is an object or a function call. It
898 -- may have been rewritten in several ways.
900 elsif Is_Object_Reference (Nam) then
901 if Comes_From_Source (N)
902 and then Is_Dependent_Component_Of_Mutable_Object (Nam)
905 ("illegal renaming of discriminant-dependent component", Nam);
910 -- A static function call may have been folded into a literal
912 elsif Nkind (Original_Node (Nam)) = N_Function_Call
914 -- When expansion is disabled, attribute reference is not
915 -- rewritten as function call. Otherwise it may be rewritten
916 -- as a conversion, so check original node.
918 or else (Nkind (Original_Node (Nam)) = N_Attribute_Reference
919 and then Is_Function_Attribute_Name
920 (Attribute_Name (Original_Node (Nam))))
922 -- Weird but legal, equivalent to renaming a function call.
923 -- Illegal if the literal is the result of constant-folding an
924 -- attribute reference that is not a function.
926 or else (Is_Entity_Name (Nam)
927 and then Ekind (Entity (Nam)) = E_Enumeration_Literal
929 Nkind (Original_Node (Nam)) /= N_Attribute_Reference)
931 or else (Nkind (Nam) = N_Type_Conversion
932 and then Is_Tagged_Type (Entity (Subtype_Mark (Nam))))
936 elsif Nkind (Nam) = N_Type_Conversion then
938 ("renaming of conversion only allowed for tagged types", Nam);
942 elsif Ada_Version >= Ada_05
943 and then Nkind (Nam) = N_Attribute_Reference
944 and then Attribute_Name (Nam) = Name_Priority
949 Error_Msg_N ("expect object name in renaming", Nam);
954 if not Is_Variable (Nam) then
955 Set_Ekind (Id, E_Constant);
956 Set_Never_Set_In_Source (Id, True);
957 Set_Is_True_Constant (Id, True);
960 Set_Renamed_Object (Id, Nam);
961 end Analyze_Object_Renaming;
963 ------------------------------
964 -- Analyze_Package_Renaming --
965 ------------------------------
967 procedure Analyze_Package_Renaming (N : Node_Id) is
968 New_P : constant Entity_Id := Defining_Entity (N);
973 if Name (N) = Error then
977 -- Apply Text_IO kludge here, since we may be renaming one of the
978 -- children of Text_IO
980 Text_IO_Kludge (Name (N));
982 if Current_Scope /= Standard_Standard then
983 Set_Is_Pure (New_P, Is_Pure (Current_Scope));
989 if Is_Entity_Name (Name (N)) then
990 Old_P := Entity (Name (N));
995 if Etype (Old_P) = Any_Type then
997 ("expect package name in renaming", Name (N));
999 elsif Ekind (Old_P) /= E_Package
1000 and then not (Ekind (Old_P) = E_Generic_Package
1001 and then In_Open_Scopes (Old_P))
1003 if Ekind (Old_P) = E_Generic_Package then
1005 ("generic package cannot be renamed as a package", Name (N));
1007 Error_Msg_Sloc := Sloc (Old_P);
1009 ("expect package name in renaming, found& declared#",
1013 -- Set basic attributes to minimize cascaded errors
1015 Set_Ekind (New_P, E_Package);
1016 Set_Etype (New_P, Standard_Void_Type);
1019 -- Entities in the old package are accessible through the renaming
1020 -- entity. The simplest implementation is to have both packages share
1023 Set_Ekind (New_P, E_Package);
1024 Set_Etype (New_P, Standard_Void_Type);
1026 if Present (Renamed_Object (Old_P)) then
1027 Set_Renamed_Object (New_P, Renamed_Object (Old_P));
1029 Set_Renamed_Object (New_P, Old_P);
1032 Set_Has_Completion (New_P);
1034 Set_First_Entity (New_P, First_Entity (Old_P));
1035 Set_Last_Entity (New_P, Last_Entity (Old_P));
1036 Set_First_Private_Entity (New_P, First_Private_Entity (Old_P));
1037 Check_Library_Unit_Renaming (N, Old_P);
1038 Generate_Reference (Old_P, Name (N));
1040 -- If this is the renaming declaration of a package instantiation
1041 -- within itself, it is the declaration that ends the list of actuals
1042 -- for the instantiation. At this point, the subtypes that rename
1043 -- the actuals are flagged as generic, to avoid spurious ambiguities
1044 -- if the actuals for two distinct formals happen to coincide. If
1045 -- the actual is a private type, the subtype has a private completion
1046 -- that is flagged in the same fashion.
1048 -- Resolution is identical to what is was in the original generic.
1049 -- On exit from the generic instance, these are turned into regular
1050 -- subtypes again, so they are compatible with types in their class.
1052 if not Is_Generic_Instance (Old_P) then
1055 Spec := Specification (Unit_Declaration_Node (Old_P));
1058 if Nkind (Spec) = N_Package_Specification
1059 and then Present (Generic_Parent (Spec))
1060 and then Old_P = Current_Scope
1061 and then Chars (New_P) = Chars (Generic_Parent (Spec))
1067 E := First_Entity (Old_P);
1072 and then Nkind (Parent (E)) = N_Subtype_Declaration
1074 Set_Is_Generic_Actual_Type (E);
1076 if Is_Private_Type (E)
1077 and then Present (Full_View (E))
1079 Set_Is_Generic_Actual_Type (Full_View (E));
1089 end Analyze_Package_Renaming;
1091 -------------------------------
1092 -- Analyze_Renamed_Character --
1093 -------------------------------
1095 procedure Analyze_Renamed_Character
1100 C : constant Node_Id := Name (N);
1103 if Ekind (New_S) = E_Function then
1104 Resolve (C, Etype (New_S));
1107 Check_Frozen_Renaming (N, New_S);
1111 Error_Msg_N ("character literal can only be renamed as function", N);
1113 end Analyze_Renamed_Character;
1115 ---------------------------------
1116 -- Analyze_Renamed_Dereference --
1117 ---------------------------------
1119 procedure Analyze_Renamed_Dereference
1124 Nam : constant Node_Id := Name (N);
1125 P : constant Node_Id := Prefix (Nam);
1131 if not Is_Overloaded (P) then
1132 if Ekind (Etype (Nam)) /= E_Subprogram_Type
1133 or else not Type_Conformant (Etype (Nam), New_S) then
1134 Error_Msg_N ("designated type does not match specification", P);
1143 Get_First_Interp (Nam, Ind, It);
1145 while Present (It.Nam) loop
1147 if Ekind (It.Nam) = E_Subprogram_Type
1148 and then Type_Conformant (It.Nam, New_S) then
1150 if Typ /= Any_Id then
1151 Error_Msg_N ("ambiguous renaming", P);
1158 Get_Next_Interp (Ind, It);
1161 if Typ = Any_Type then
1162 Error_Msg_N ("designated type does not match specification", P);
1167 Check_Frozen_Renaming (N, New_S);
1171 end Analyze_Renamed_Dereference;
1173 ---------------------------
1174 -- Analyze_Renamed_Entry --
1175 ---------------------------
1177 procedure Analyze_Renamed_Entry
1182 Nam : constant Node_Id := Name (N);
1183 Sel : constant Node_Id := Selector_Name (Nam);
1187 if Entity (Sel) = Any_Id then
1189 -- Selector is undefined on prefix. Error emitted already
1191 Set_Has_Completion (New_S);
1195 -- Otherwise find renamed entity and build body of New_S as a call to it
1197 Old_S := Find_Renamed_Entity (N, Selector_Name (Nam), New_S);
1199 if Old_S = Any_Id then
1200 Error_Msg_N (" no subprogram or entry matches specification", N);
1203 Check_Subtype_Conformant (New_S, Old_S, N);
1204 Generate_Reference (New_S, Defining_Entity (N), 'b');
1205 Style.Check_Identifier (Defining_Entity (N), New_S);
1208 -- Only mode conformance required for a renaming_as_declaration
1210 Check_Mode_Conformant (New_S, Old_S, N);
1213 Inherit_Renamed_Profile (New_S, Old_S);
1216 Set_Convention (New_S, Convention (Old_S));
1217 Set_Has_Completion (New_S, Inside_A_Generic);
1220 Check_Frozen_Renaming (N, New_S);
1222 end Analyze_Renamed_Entry;
1224 -----------------------------------
1225 -- Analyze_Renamed_Family_Member --
1226 -----------------------------------
1228 procedure Analyze_Renamed_Family_Member
1233 Nam : constant Node_Id := Name (N);
1234 P : constant Node_Id := Prefix (Nam);
1238 if (Is_Entity_Name (P) and then Ekind (Entity (P)) = E_Entry_Family)
1239 or else (Nkind (P) = N_Selected_Component
1241 Ekind (Entity (Selector_Name (P))) = E_Entry_Family)
1243 if Is_Entity_Name (P) then
1244 Old_S := Entity (P);
1246 Old_S := Entity (Selector_Name (P));
1249 if not Entity_Matches_Spec (Old_S, New_S) then
1250 Error_Msg_N ("entry family does not match specification", N);
1253 Check_Subtype_Conformant (New_S, Old_S, N);
1254 Generate_Reference (New_S, Defining_Entity (N), 'b');
1255 Style.Check_Identifier (Defining_Entity (N), New_S);
1259 Error_Msg_N ("no entry family matches specification", N);
1262 Set_Has_Completion (New_S, Inside_A_Generic);
1265 Check_Frozen_Renaming (N, New_S);
1267 end Analyze_Renamed_Family_Member;
1269 ---------------------------------
1270 -- Analyze_Subprogram_Renaming --
1271 ---------------------------------
1273 procedure Analyze_Subprogram_Renaming (N : Node_Id) is
1274 Formal_Spec : constant Node_Id := Corresponding_Formal_Spec (N);
1275 Is_Actual : constant Boolean := Present (Formal_Spec);
1276 Inst_Node : Node_Id := Empty;
1277 Nam : constant Node_Id := Name (N);
1279 Old_S : Entity_Id := Empty;
1280 Rename_Spec : Entity_Id;
1281 Save_AV : constant Ada_Version_Type := Ada_Version;
1282 Save_AV_Exp : constant Ada_Version_Type := Ada_Version_Explicit;
1283 Spec : constant Node_Id := Specification (N);
1285 procedure Check_Null_Exclusion
1288 -- Ada 2005 (AI-423): Given renaming Ren of subprogram Sub, check the
1289 -- following AI rules:
1291 -- If Ren is a renaming of a formal subprogram and one of its
1292 -- parameters has a null exclusion, then the corresponding formal
1293 -- in Sub must also have one. Otherwise the subtype of the Sub's
1294 -- formal parameter must exclude null.
1296 -- If Ren is a renaming of a formal function and its retrun
1297 -- profile has a null exclusion, then Sub's return profile must
1298 -- have one. Otherwise the subtype of Sub's return profile must
1301 function Original_Subprogram (Subp : Entity_Id) return Entity_Id;
1302 -- Find renamed entity when the declaration is a renaming_as_body and
1303 -- the renamed entity may itself be a renaming_as_body. Used to enforce
1304 -- rule that a renaming_as_body is illegal if the declaration occurs
1305 -- before the subprogram it completes is frozen, and renaming indirectly
1306 -- renames the subprogram itself.(Defect Report 8652/0027).
1308 --------------------------
1309 -- Check_Null_Exclusion --
1310 --------------------------
1312 procedure Check_Null_Exclusion
1316 Ren_Formal : Entity_Id;
1317 Sub_Formal : Entity_Id;
1322 Ren_Formal := First_Formal (Ren);
1323 Sub_Formal := First_Formal (Sub);
1324 while Present (Ren_Formal)
1325 and then Present (Sub_Formal)
1327 if Has_Null_Exclusion (Parent (Ren_Formal))
1329 not (Has_Null_Exclusion (Parent (Sub_Formal))
1330 or else Can_Never_Be_Null (Etype (Sub_Formal)))
1333 ("`NOT NULL` required for parameter &",
1334 Parent (Sub_Formal), Sub_Formal);
1337 Next_Formal (Ren_Formal);
1338 Next_Formal (Sub_Formal);
1341 -- Return profile check
1343 if Nkind (Parent (Ren)) = N_Function_Specification
1344 and then Nkind (Parent (Sub)) = N_Function_Specification
1345 and then Has_Null_Exclusion (Parent (Ren))
1347 not (Has_Null_Exclusion (Parent (Sub))
1348 or else Can_Never_Be_Null (Etype (Sub)))
1351 ("return must specify `NOT NULL`",
1352 Result_Definition (Parent (Sub)));
1354 end Check_Null_Exclusion;
1356 -------------------------
1357 -- Original_Subprogram --
1358 -------------------------
1360 function Original_Subprogram (Subp : Entity_Id) return Entity_Id is
1361 Orig_Decl : Node_Id;
1362 Orig_Subp : Entity_Id;
1365 -- First case: renamed entity is itself a renaming
1367 if Present (Alias (Subp)) then
1368 return Alias (Subp);
1371 Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration
1373 (Corresponding_Body (Unit_Declaration_Node (Subp)))
1375 -- Check if renamed entity is a renaming_as_body
1378 Unit_Declaration_Node
1379 (Corresponding_Body (Unit_Declaration_Node (Subp)));
1381 if Nkind (Orig_Decl) = N_Subprogram_Renaming_Declaration then
1382 Orig_Subp := Entity (Name (Orig_Decl));
1384 if Orig_Subp = Rename_Spec then
1386 -- Circularity detected
1391 return (Original_Subprogram (Orig_Subp));
1399 end Original_Subprogram;
1401 -- Start of processing for Analyze_Subprogram_Renaming
1404 -- We must test for the attribute renaming case before the Analyze
1405 -- call because otherwise Sem_Attr will complain that the attribute
1406 -- is missing an argument when it is analyzed.
1408 if Nkind (Nam) = N_Attribute_Reference then
1410 -- In the case of an abstract formal subprogram association, rewrite
1411 -- an actual given by a stream attribute as the name of the
1412 -- corresponding stream primitive of the type.
1414 -- In a generic context the stream operations are not generated, and
1415 -- this must be treated as a normal attribute reference, to be
1416 -- expanded in subsequent instantiations.
1418 if Is_Actual and then Is_Abstract_Subprogram (Formal_Spec)
1419 and then Expander_Active
1422 Stream_Prim : Entity_Id;
1423 Prefix_Type : constant Entity_Id := Entity (Prefix (Nam));
1426 -- The class-wide forms of the stream attributes are not
1427 -- primitive dispatching operations (even though they
1428 -- internally dispatch to a stream attribute).
1430 if Is_Class_Wide_Type (Prefix_Type) then
1432 ("attribute must be a primitive dispatching operation",
1437 -- Retrieve the primitive subprogram associated with the
1438 -- attribute. This can only be a stream attribute, since those
1439 -- are the only ones that are dispatching (and the actual for
1440 -- an abstract formal subprogram must be dispatching
1443 case Attribute_Name (Nam) is
1446 Find_Prim_Op (Prefix_Type, TSS_Stream_Input);
1449 Find_Prim_Op (Prefix_Type, TSS_Stream_Output);
1452 Find_Prim_Op (Prefix_Type, TSS_Stream_Read);
1455 Find_Prim_Op (Prefix_Type, TSS_Stream_Write);
1458 ("attribute must be a primitive dispatching operation",
1463 -- Rewrite the attribute into the name of its corresponding
1464 -- primitive dispatching subprogram. We can then proceed with
1465 -- the usual processing for subprogram renamings.
1468 Prim_Name : constant Node_Id :=
1469 Make_Identifier (Sloc (Nam),
1470 Chars => Chars (Stream_Prim));
1472 Set_Entity (Prim_Name, Stream_Prim);
1473 Rewrite (Nam, Prim_Name);
1478 -- Normal processing for a renaming of an attribute
1481 Attribute_Renaming (N);
1486 -- Check whether this declaration corresponds to the instantiation
1487 -- of a formal subprogram.
1489 -- If this is an instantiation, the corresponding actual is frozen and
1490 -- error messages can be made more precise. If this is a default
1491 -- subprogram, the entity is already established in the generic, and is
1492 -- not retrieved by visibility. If it is a default with a box, the
1493 -- candidate interpretations, if any, have been collected when building
1494 -- the renaming declaration. If overloaded, the proper interpretation is
1495 -- determined in Find_Renamed_Entity. If the entity is an operator,
1496 -- Find_Renamed_Entity applies additional visibility checks.
1499 Inst_Node := Unit_Declaration_Node (Formal_Spec);
1501 if Is_Entity_Name (Nam)
1502 and then Present (Entity (Nam))
1503 and then not Comes_From_Source (Nam)
1504 and then not Is_Overloaded (Nam)
1506 Old_S := Entity (Nam);
1507 New_S := Analyze_Subprogram_Specification (Spec);
1511 if Ekind (Entity (Nam)) = E_Operator then
1515 if Box_Present (Inst_Node) then
1516 Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
1518 -- If there is an immediately visible homonym of the operator
1519 -- and the declaration has a default, this is worth a warning
1520 -- because the user probably did not intend to get the pre-
1521 -- defined operator, visible in the generic declaration. To
1522 -- find if there is an intended candidate, analyze the renaming
1523 -- again in the current context.
1525 elsif Scope (Old_S) = Standard_Standard
1526 and then Present (Default_Name (Inst_Node))
1529 Decl : constant Node_Id := New_Copy_Tree (N);
1533 Set_Entity (Name (Decl), Empty);
1534 Analyze (Name (Decl));
1536 Find_Renamed_Entity (Decl, Name (Decl), New_S, True);
1539 and then In_Open_Scopes (Scope (Hidden))
1540 and then Is_Immediately_Visible (Hidden)
1541 and then Comes_From_Source (Hidden)
1542 and then Hidden /= Old_S
1544 Error_Msg_Sloc := Sloc (Hidden);
1545 Error_Msg_N ("?default subprogram is resolved " &
1546 "in the generic declaration " &
1547 "('R'M 12.6(17))", N);
1548 Error_Msg_NE ("\?and will not use & #", N, Hidden);
1556 New_S := Analyze_Subprogram_Specification (Spec);
1560 -- Renamed entity must be analyzed first, to avoid being hidden by
1561 -- new name (which might be the same in a generic instance).
1565 -- The renaming defines a new overloaded entity, which is analyzed
1566 -- like a subprogram declaration.
1568 New_S := Analyze_Subprogram_Specification (Spec);
1571 if Current_Scope /= Standard_Standard then
1572 Set_Is_Pure (New_S, Is_Pure (Current_Scope));
1575 Rename_Spec := Find_Corresponding_Spec (N);
1577 if Present (Rename_Spec) then
1579 -- Renaming_As_Body. Renaming declaration is the completion of
1580 -- the declaration of Rename_Spec. We will build an actual body
1581 -- for it at the freezing point.
1583 Set_Corresponding_Spec (N, Rename_Spec);
1585 if Nkind (Unit_Declaration_Node (Rename_Spec)) =
1586 N_Abstract_Subprogram_Declaration
1588 -- Input and Output stream functions are abstract if the object
1589 -- type is abstract. However, these functions may receive explicit
1590 -- declarations in representation clauses, making the attribute
1591 -- subprograms usable as defaults in subsequent type extensions.
1592 -- In this case we rewrite the declaration to make the subprogram
1593 -- non-abstract. We remove the previous declaration, and insert
1594 -- the new one at the point of the renaming, to prevent premature
1595 -- access to unfrozen types. The new declaration reuses the
1596 -- specification of the previous one, and must not be analyzed.
1598 pragma Assert (Is_TSS (Rename_Spec, TSS_Stream_Output)
1599 or else Is_TSS (Rename_Spec, TSS_Stream_Input));
1602 Old_Decl : constant Node_Id :=
1603 Unit_Declaration_Node (Rename_Spec);
1604 New_Decl : constant Node_Id :=
1605 Make_Subprogram_Declaration (Sloc (N),
1607 Relocate_Node (Specification (Old_Decl)));
1610 Insert_After (N, New_Decl);
1611 Set_Is_Abstract_Subprogram (Rename_Spec, False);
1612 Set_Analyzed (New_Decl);
1616 Set_Corresponding_Body (Unit_Declaration_Node (Rename_Spec), New_S);
1618 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
1619 Error_Msg_N ("(Ada 83) renaming cannot serve as a body", N);
1622 Set_Convention (New_S, Convention (Rename_Spec));
1623 Check_Fully_Conformant (New_S, Rename_Spec);
1624 Set_Public_Status (New_S);
1626 -- Indicate that the entity in the declaration functions like the
1627 -- corresponding body, and is not a new entity. The body will be
1628 -- constructed later at the freeze point, so indicate that the
1629 -- completion has not been seen yet.
1631 Set_Ekind (New_S, E_Subprogram_Body);
1632 New_S := Rename_Spec;
1633 Set_Has_Completion (Rename_Spec, False);
1635 -- Ada 2005: check overriding indicator
1637 if Must_Override (Specification (N))
1638 and then not Is_Overriding_Operation (Rename_Spec)
1640 Error_Msg_NE ("subprogram& is not overriding", N, Rename_Spec);
1642 elsif Must_Not_Override (Specification (N))
1643 and then Is_Overriding_Operation (Rename_Spec)
1646 ("subprogram& overrides inherited operation", N, Rename_Spec);
1650 Generate_Definition (New_S);
1651 New_Overloaded_Entity (New_S);
1653 if Is_Entity_Name (Nam)
1654 and then Is_Intrinsic_Subprogram (Entity (Nam))
1658 Check_Delayed_Subprogram (New_S);
1662 -- There is no need for elaboration checks on the new entity, which may
1663 -- be called before the next freezing point where the body will appear.
1664 -- Elaboration checks refer to the real entity, not the one created by
1665 -- the renaming declaration.
1667 Set_Kill_Elaboration_Checks (New_S, True);
1669 if Etype (Nam) = Any_Type then
1670 Set_Has_Completion (New_S);
1673 elsif Nkind (Nam) = N_Selected_Component then
1675 -- Renamed entity is an entry or protected subprogram. For those
1676 -- cases an explicit body is built (at the point of freezing of this
1677 -- entity) that contains a call to the renamed entity.
1679 Analyze_Renamed_Entry (N, New_S, Present (Rename_Spec));
1682 elsif Nkind (Nam) = N_Explicit_Dereference then
1684 -- Renamed entity is designated by access_to_subprogram expression.
1685 -- Must build body to encapsulate call, as in the entry case.
1687 Analyze_Renamed_Dereference (N, New_S, Present (Rename_Spec));
1690 elsif Nkind (Nam) = N_Indexed_Component then
1691 Analyze_Renamed_Family_Member (N, New_S, Present (Rename_Spec));
1694 elsif Nkind (Nam) = N_Character_Literal then
1695 Analyze_Renamed_Character (N, New_S, Present (Rename_Spec));
1698 elsif (not Is_Entity_Name (Nam)
1699 and then Nkind (Nam) /= N_Operator_Symbol)
1700 or else not Is_Overloadable (Entity (Nam))
1702 Error_Msg_N ("expect valid subprogram name in renaming", N);
1706 -- Most common case: subprogram renames subprogram. No body is generated
1707 -- in this case, so we must indicate the declaration is complete as is.
1709 if No (Rename_Spec) then
1710 Set_Has_Completion (New_S);
1711 Set_Is_Pure (New_S, Is_Pure (Entity (Nam)));
1712 Set_Is_Preelaborated (New_S, Is_Preelaborated (Entity (Nam)));
1714 -- Ada 2005 (AI-423): Check the consistency of null exclusions
1715 -- between a subprogram and its renaming.
1717 if Ada_Version >= Ada_05 then
1718 Check_Null_Exclusion
1720 Sub => Entity (Nam));
1724 -- Find the renamed entity that matches the given specification. Disable
1725 -- Ada_83 because there is no requirement of full conformance between
1726 -- renamed entity and new entity, even though the same circuit is used.
1728 -- This is a bit of a kludge, which introduces a really irregular use of
1729 -- Ada_Version[_Explicit]. Would be nice to find cleaner way to do this
1732 Ada_Version := Ada_Version_Type'Max (Ada_Version, Ada_95);
1733 Ada_Version_Explicit := Ada_Version;
1736 Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
1739 if Old_S /= Any_Id then
1741 and then From_Default (N)
1743 -- This is an implicit reference to the default actual
1745 Generate_Reference (Old_S, Nam, Typ => 'i', Force => True);
1747 Generate_Reference (Old_S, Nam);
1750 -- For a renaming-as-body, require subtype conformance, but if the
1751 -- declaration being completed has not been frozen, then inherit the
1752 -- convention of the renamed subprogram prior to checking conformance
1753 -- (unless the renaming has an explicit convention established; the
1754 -- rule stated in the RM doesn't seem to address this ???).
1756 if Present (Rename_Spec) then
1757 Generate_Reference (Rename_Spec, Defining_Entity (Spec), 'b');
1758 Style.Check_Identifier (Defining_Entity (Spec), Rename_Spec);
1760 if not Is_Frozen (Rename_Spec) then
1761 if not Has_Convention_Pragma (Rename_Spec) then
1762 Set_Convention (New_S, Convention (Old_S));
1765 if Ekind (Old_S) /= E_Operator then
1766 Check_Mode_Conformant (New_S, Old_S, Spec);
1769 if Original_Subprogram (Old_S) = Rename_Spec then
1770 Error_Msg_N ("unfrozen subprogram cannot rename itself ", N);
1773 Check_Subtype_Conformant (New_S, Old_S, Spec);
1776 Check_Frozen_Renaming (N, Rename_Spec);
1778 -- Check explicitly that renamed entity is not intrinsic, because
1779 -- in in a generic the renamed body is not built. In this case,
1780 -- the renaming_as_body is a completion.
1782 if Inside_A_Generic then
1783 if Is_Frozen (Rename_Spec)
1784 and then Is_Intrinsic_Subprogram (Old_S)
1787 ("subprogram in renaming_as_body cannot be intrinsic",
1791 Set_Has_Completion (Rename_Spec);
1794 elsif Ekind (Old_S) /= E_Operator then
1795 Check_Mode_Conformant (New_S, Old_S);
1798 and then Error_Posted (New_S)
1800 Error_Msg_NE ("invalid actual subprogram: & #!", N, Old_S);
1804 if No (Rename_Spec) then
1806 -- The parameter profile of the new entity is that of the renamed
1807 -- entity: the subtypes given in the specification are irrelevant.
1809 Inherit_Renamed_Profile (New_S, Old_S);
1811 -- A call to the subprogram is transformed into a call to the
1812 -- renamed entity. This is transitive if the renamed entity is
1813 -- itself a renaming.
1815 if Present (Alias (Old_S)) then
1816 Set_Alias (New_S, Alias (Old_S));
1818 Set_Alias (New_S, Old_S);
1821 -- Note that we do not set Is_Intrinsic_Subprogram if we have a
1822 -- renaming as body, since the entity in this case is not an
1823 -- intrinsic (it calls an intrinsic, but we have a real body for
1824 -- this call, and it is in this body that the required intrinsic
1825 -- processing will take place).
1827 -- Also, if this is a renaming of inequality, the renamed operator
1828 -- is intrinsic, but what matters is the corresponding equality
1829 -- operator, which may be user-defined.
1831 Set_Is_Intrinsic_Subprogram
1833 Is_Intrinsic_Subprogram (Old_S)
1835 (Chars (Old_S) /= Name_Op_Ne
1836 or else Ekind (Old_S) = E_Operator
1838 Is_Intrinsic_Subprogram
1839 (Corresponding_Equality (Old_S))));
1841 if Ekind (Alias (New_S)) = E_Operator then
1842 Set_Has_Delayed_Freeze (New_S, False);
1845 -- If the renaming corresponds to an association for an abstract
1846 -- formal subprogram, then various attributes must be set to
1847 -- indicate that the renaming is an abstract dispatching operation
1848 -- with a controlling type.
1850 if Is_Actual and then Is_Abstract_Subprogram (Formal_Spec) then
1852 -- Mark the renaming as abstract here, so Find_Dispatching_Type
1853 -- see it as corresponding to a generic association for a
1854 -- formal abstract subprogram
1856 Set_Is_Abstract_Subprogram (New_S);
1859 New_S_Ctrl_Type : constant Entity_Id :=
1860 Find_Dispatching_Type (New_S);
1861 Old_S_Ctrl_Type : constant Entity_Id :=
1862 Find_Dispatching_Type (Old_S);
1865 if Old_S_Ctrl_Type /= New_S_Ctrl_Type then
1867 ("actual must be dispatching subprogram for type&",
1868 Nam, New_S_Ctrl_Type);
1871 Set_Is_Dispatching_Operation (New_S);
1872 Check_Controlling_Formals (New_S_Ctrl_Type, New_S);
1874 -- If the actual in the formal subprogram is itself a
1875 -- formal abstract subprogram association, there's no
1876 -- dispatch table component or position to inherit.
1878 if Present (DTC_Entity (Old_S)) then
1879 Set_DTC_Entity (New_S, DTC_Entity (Old_S));
1880 Set_DT_Position (New_S, DT_Position (Old_S));
1888 and then (Old_S = New_S
1889 or else (Nkind (Nam) /= N_Expanded_Name
1890 and then Chars (Old_S) = Chars (New_S)))
1892 Error_Msg_N ("subprogram cannot rename itself", N);
1895 Set_Convention (New_S, Convention (Old_S));
1897 if Is_Abstract_Subprogram (Old_S) then
1898 if Present (Rename_Spec) then
1900 ("a renaming-as-body cannot rename an abstract subprogram",
1902 Set_Has_Completion (Rename_Spec);
1904 Set_Is_Abstract_Subprogram (New_S);
1908 Check_Library_Unit_Renaming (N, Old_S);
1910 -- Pathological case: procedure renames entry in the scope of its
1911 -- task. Entry is given by simple name, but body must be built for
1912 -- procedure. Of course if called it will deadlock.
1914 if Ekind (Old_S) = E_Entry then
1915 Set_Has_Completion (New_S, False);
1916 Set_Alias (New_S, Empty);
1920 Freeze_Before (N, Old_S);
1921 Set_Has_Delayed_Freeze (New_S, False);
1922 Freeze_Before (N, New_S);
1924 -- An abstract subprogram is only allowed as an actual in the case
1925 -- where the formal subprogram is also abstract.
1927 if (Ekind (Old_S) = E_Procedure or else Ekind (Old_S) = E_Function)
1928 and then Is_Abstract_Subprogram (Old_S)
1929 and then not Is_Abstract_Subprogram (Formal_Spec)
1932 ("abstract subprogram not allowed as generic actual", Nam);
1937 -- A common error is to assume that implicit operators for types are
1938 -- defined in Standard, or in the scope of a subtype. In those cases
1939 -- where the renamed entity is given with an expanded name, it is
1940 -- worth mentioning that operators for the type are not declared in
1941 -- the scope given by the prefix.
1943 if Nkind (Nam) = N_Expanded_Name
1944 and then Nkind (Selector_Name (Nam)) = N_Operator_Symbol
1945 and then Scope (Entity (Nam)) = Standard_Standard
1948 T : constant Entity_Id :=
1949 Base_Type (Etype (First_Formal (New_S)));
1951 Error_Msg_Node_2 := Prefix (Nam);
1953 ("operator for type& is not declared in&", Prefix (Nam), T);
1958 ("no visible subprogram matches the specification for&",
1962 if Present (Candidate_Renaming) then
1968 F1 := First_Formal (Candidate_Renaming);
1969 F2 := First_Formal (New_S);
1971 while Present (F1) and then Present (F2) loop
1976 if Present (F1) and then Present (Default_Value (F1)) then
1977 if Present (Next_Formal (F1)) then
1979 ("\missing specification for &" &
1980 " and other formals with defaults", Spec, F1);
1983 ("\missing specification for &", Spec, F1);
1990 -- Ada 2005 AI 404: if the new subprogram is dispatching, verify that
1991 -- controlling access parameters are known non-null for the renamed
1992 -- subprogram. Test also applies to a subprogram instantiation that
1993 -- is dispatching. Test is skipped if some previous error was detected
1994 -- that set Old_S to Any_Id.
1996 if Ada_Version >= Ada_05
1997 and then Old_S /= Any_Id
1998 and then not Is_Dispatching_Operation (Old_S)
1999 and then Is_Dispatching_Operation (New_S)
2006 Old_F := First_Formal (Old_S);
2007 New_F := First_Formal (New_S);
2008 while Present (Old_F) loop
2009 if Ekind (Etype (Old_F)) = E_Anonymous_Access_Type
2010 and then Is_Controlling_Formal (New_F)
2011 and then not Can_Never_Be_Null (Old_F)
2013 Error_Msg_N ("access parameter is controlling,", New_F);
2015 ("\corresponding parameter of& "
2016 & "must be explicitly null excluding", New_F, Old_S);
2019 Next_Formal (Old_F);
2020 Next_Formal (New_F);
2025 -- A useful warning, suggested by Ada Bug Finder (Ada-Europe 2005)
2027 if Comes_From_Source (N)
2028 and then Present (Old_S)
2029 and then Nkind (Old_S) = N_Defining_Operator_Symbol
2030 and then Nkind (New_S) = N_Defining_Operator_Symbol
2031 and then Chars (Old_S) /= Chars (New_S)
2034 ("?& is being renamed as a different operator",
2038 Ada_Version := Save_AV;
2039 Ada_Version_Explicit := Save_AV_Exp;
2040 end Analyze_Subprogram_Renaming;
2042 -------------------------
2043 -- Analyze_Use_Package --
2044 -------------------------
2046 -- Resolve the package names in the use clause, and make all the visible
2047 -- entities defined in the package potentially use-visible. If the package
2048 -- is already in use from a previous use clause, its visible entities are
2049 -- already use-visible. In that case, mark the occurrence as a redundant
2050 -- use. If the package is an open scope, i.e. if the use clause occurs
2051 -- within the package itself, ignore it.
2053 procedure Analyze_Use_Package (N : Node_Id) is
2054 Pack_Name : Node_Id;
2057 -- Start of processing for Analyze_Use_Package
2060 Set_Hidden_By_Use_Clause (N, No_Elist);
2062 -- Use clause is not allowed in a spec of a predefined package
2063 -- declaration except that packages whose file name starts a-n are OK
2064 -- (these are children of Ada.Numerics, and such packages are never
2065 -- loaded by Rtsfind).
2067 if Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
2068 and then Name_Buffer (1 .. 3) /= "a-n"
2070 Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
2072 Error_Msg_N ("use clause not allowed in predefined spec", N);
2075 -- Chain clause to list of use clauses in current scope
2077 if Nkind (Parent (N)) /= N_Compilation_Unit then
2078 Chain_Use_Clause (N);
2081 -- Loop through package names to identify referenced packages
2083 Pack_Name := First (Names (N));
2084 while Present (Pack_Name) loop
2085 Analyze (Pack_Name);
2087 if Nkind (Parent (N)) = N_Compilation_Unit
2088 and then Nkind (Pack_Name) = N_Expanded_Name
2094 Pref := Prefix (Pack_Name);
2095 while Nkind (Pref) = N_Expanded_Name loop
2096 Pref := Prefix (Pref);
2099 if Entity (Pref) = Standard_Standard then
2101 ("predefined package Standard cannot appear"
2102 & " in a context clause", Pref);
2110 -- Loop through package names to mark all entities as potentially
2113 Pack_Name := First (Names (N));
2114 while Present (Pack_Name) loop
2115 if Is_Entity_Name (Pack_Name) then
2116 Pack := Entity (Pack_Name);
2118 if Ekind (Pack) /= E_Package
2119 and then Etype (Pack) /= Any_Type
2121 if Ekind (Pack) = E_Generic_Package then
2123 ("a generic package is not allowed in a use clause",
2126 Error_Msg_N ("& is not a usable package", Pack_Name);
2130 if Nkind (Parent (N)) = N_Compilation_Unit then
2131 Check_In_Previous_With_Clause (N, Pack_Name);
2134 if Applicable_Use (Pack_Name) then
2135 Use_One_Package (Pack, N);
2142 end Analyze_Use_Package;
2144 ----------------------
2145 -- Analyze_Use_Type --
2146 ----------------------
2148 procedure Analyze_Use_Type (N : Node_Id) is
2152 Set_Hidden_By_Use_Clause (N, No_Elist);
2154 -- Chain clause to list of use clauses in current scope
2156 if Nkind (Parent (N)) /= N_Compilation_Unit then
2157 Chain_Use_Clause (N);
2160 Id := First (Subtype_Marks (N));
2161 while Present (Id) loop
2164 if Entity (Id) /= Any_Type then
2167 if Nkind (Parent (N)) = N_Compilation_Unit then
2168 if Nkind (Id) = N_Identifier then
2169 Error_Msg_N ("type is not directly visible", Id);
2171 elsif Is_Child_Unit (Scope (Entity (Id)))
2172 and then Scope (Entity (Id)) /= System_Aux_Id
2174 Check_In_Previous_With_Clause (N, Prefix (Id));
2181 end Analyze_Use_Type;
2183 --------------------
2184 -- Applicable_Use --
2185 --------------------
2187 function Applicable_Use (Pack_Name : Node_Id) return Boolean is
2188 Pack : constant Entity_Id := Entity (Pack_Name);
2191 if In_Open_Scopes (Pack) then
2194 elsif In_Use (Pack) then
2195 Note_Redundant_Use (Pack_Name);
2198 elsif Present (Renamed_Object (Pack))
2199 and then In_Use (Renamed_Object (Pack))
2201 Note_Redundant_Use (Pack_Name);
2209 ------------------------
2210 -- Attribute_Renaming --
2211 ------------------------
2213 procedure Attribute_Renaming (N : Node_Id) is
2214 Loc : constant Source_Ptr := Sloc (N);
2215 Nam : constant Node_Id := Name (N);
2216 Spec : constant Node_Id := Specification (N);
2217 New_S : constant Entity_Id := Defining_Unit_Name (Spec);
2218 Aname : constant Name_Id := Attribute_Name (Nam);
2220 Form_Num : Nat := 0;
2221 Expr_List : List_Id := No_List;
2223 Attr_Node : Node_Id;
2224 Body_Node : Node_Id;
2225 Param_Spec : Node_Id;
2228 Generate_Definition (New_S);
2230 -- This procedure is called in the context of subprogram renaming,
2231 -- and thus the attribute must be one that is a subprogram. All of
2232 -- those have at least one formal parameter, with the singular
2233 -- exception of AST_Entry (which is a real oddity, it is odd that
2234 -- this can be renamed at all!)
2236 if not Is_Non_Empty_List (Parameter_Specifications (Spec)) then
2237 if Aname /= Name_AST_Entry then
2239 ("subprogram renaming an attribute must have formals", N);
2244 Param_Spec := First (Parameter_Specifications (Spec));
2245 while Present (Param_Spec) loop
2246 Form_Num := Form_Num + 1;
2248 if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
2249 Find_Type (Parameter_Type (Param_Spec));
2251 -- The profile of the new entity denotes the base type (s) of
2252 -- the types given in the specification. For access parameters
2253 -- there are no subtypes involved.
2255 Rewrite (Parameter_Type (Param_Spec),
2257 (Base_Type (Entity (Parameter_Type (Param_Spec))), Loc));
2260 if No (Expr_List) then
2261 Expr_List := New_List;
2264 Append_To (Expr_List,
2265 Make_Identifier (Loc,
2266 Chars => Chars (Defining_Identifier (Param_Spec))));
2268 -- The expressions in the attribute reference are not freeze
2269 -- points. Neither is the attribute as a whole, see below.
2271 Set_Must_Not_Freeze (Last (Expr_List));
2276 -- Immediate error if too many formals. Other mismatches in numbers
2277 -- of number of types of parameters are detected when we analyze the
2278 -- body of the subprogram that we construct.
2280 if Form_Num > 2 then
2281 Error_Msg_N ("too many formals for attribute", N);
2283 -- Error if the attribute reference has expressions that look
2284 -- like formal parameters.
2286 elsif Present (Expressions (Nam)) then
2287 Error_Msg_N ("illegal expressions in attribute reference", Nam);
2290 Aname = Name_Compose or else
2291 Aname = Name_Exponent or else
2292 Aname = Name_Leading_Part or else
2293 Aname = Name_Pos or else
2294 Aname = Name_Round or else
2295 Aname = Name_Scaling or else
2298 if Nkind (N) = N_Subprogram_Renaming_Declaration
2299 and then Present (Corresponding_Formal_Spec (N))
2302 ("generic actual cannot be attribute involving universal type",
2306 ("attribute involving a universal type cannot be renamed",
2311 -- AST_Entry is an odd case. It doesn't really make much sense to
2312 -- allow it to be renamed, but that's the DEC rule, so we have to
2313 -- do it right. The point is that the AST_Entry call should be made
2314 -- now, and what the function will return is the returned value.
2316 -- Note that there is no Expr_List in this case anyway
2318 if Aname = Name_AST_Entry then
2324 Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
2327 Make_Object_Declaration (Loc,
2328 Defining_Identifier => Ent,
2329 Object_Definition =>
2330 New_Occurrence_Of (RTE (RE_AST_Handler), Loc),
2332 Constant_Present => True);
2334 Set_Assignment_OK (Decl, True);
2335 Insert_Action (N, Decl);
2336 Attr_Node := Make_Identifier (Loc, Chars (Ent));
2339 -- For all other attributes, we rewrite the attribute node to have
2340 -- a list of expressions corresponding to the subprogram formals.
2341 -- A renaming declaration is not a freeze point, and the analysis of
2342 -- the attribute reference should not freeze the type of the prefix.
2346 Make_Attribute_Reference (Loc,
2347 Prefix => Prefix (Nam),
2348 Attribute_Name => Aname,
2349 Expressions => Expr_List);
2351 Set_Must_Not_Freeze (Attr_Node);
2352 Set_Must_Not_Freeze (Prefix (Nam));
2355 -- Case of renaming a function
2357 if Nkind (Spec) = N_Function_Specification then
2358 if Is_Procedure_Attribute_Name (Aname) then
2359 Error_Msg_N ("attribute can only be renamed as procedure", Nam);
2363 Find_Type (Result_Definition (Spec));
2364 Rewrite (Result_Definition (Spec),
2366 Base_Type (Entity (Result_Definition (Spec))), Loc));
2369 Make_Subprogram_Body (Loc,
2370 Specification => Spec,
2371 Declarations => New_List,
2372 Handled_Statement_Sequence =>
2373 Make_Handled_Sequence_Of_Statements (Loc,
2374 Statements => New_List (
2375 Make_Return_Statement (Loc,
2376 Expression => Attr_Node))));
2378 -- Case of renaming a procedure
2381 if not Is_Procedure_Attribute_Name (Aname) then
2382 Error_Msg_N ("attribute can only be renamed as function", Nam);
2387 Make_Subprogram_Body (Loc,
2388 Specification => Spec,
2389 Declarations => New_List,
2390 Handled_Statement_Sequence =>
2391 Make_Handled_Sequence_Of_Statements (Loc,
2392 Statements => New_List (Attr_Node)));
2395 -- In case of tagged types we add the body of the generated function to
2396 -- the freezing actions of the type (because in the general case such
2397 -- type is still not frozen). We exclude from this processing generic
2398 -- formal subprograms found in instantiations and AST_Entry renamings.
2400 if not Present (Corresponding_Formal_Spec (N))
2401 and then Etype (Nam) /= RTE (RE_AST_Handler)
2404 P : constant Entity_Id := Prefix (Nam);
2409 if Is_Tagged_Type (Etype (P)) then
2410 Ensure_Freeze_Node (Etype (P));
2411 Append_Freeze_Action (Etype (P), Body_Node);
2413 Rewrite (N, Body_Node);
2415 Set_Etype (New_S, Base_Type (Etype (New_S)));
2419 -- Generic formal subprograms or AST_Handler renaming
2422 Rewrite (N, Body_Node);
2424 Set_Etype (New_S, Base_Type (Etype (New_S)));
2427 if Is_Compilation_Unit (New_S) then
2429 ("a library unit can only rename another library unit", N);
2432 -- We suppress elaboration warnings for the resulting entity, since
2433 -- clearly they are not needed, and more particularly, in the case
2434 -- of a generic formal subprogram, the resulting entity can appear
2435 -- after the instantiation itself, and thus look like a bogus case
2436 -- of access before elaboration.
2438 Set_Suppress_Elaboration_Warnings (New_S);
2440 end Attribute_Renaming;
2442 ----------------------
2443 -- Chain_Use_Clause --
2444 ----------------------
2446 procedure Chain_Use_Clause (N : Node_Id) is
2448 Level : Int := Scope_Stack.Last;
2451 if not Is_Compilation_Unit (Current_Scope)
2452 or else not Is_Child_Unit (Current_Scope)
2454 null; -- Common case
2456 elsif Defining_Entity (Parent (N)) = Current_Scope then
2457 null; -- Common case for compilation unit
2460 -- If declaration appears in some other scope, it must be in some
2461 -- parent unit when compiling a child.
2463 Pack := Defining_Entity (Parent (N));
2464 if not In_Open_Scopes (Pack) then
2465 null; -- default as well
2468 -- Find entry for parent unit in scope stack
2470 while Scope_Stack.Table (Level).Entity /= Pack loop
2476 Set_Next_Use_Clause (N,
2477 Scope_Stack.Table (Level).First_Use_Clause);
2478 Scope_Stack.Table (Level).First_Use_Clause := N;
2479 end Chain_Use_Clause;
2481 ---------------------------
2482 -- Check_Frozen_Renaming --
2483 ---------------------------
2485 procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id) is
2491 and then not Has_Completion (Subp)
2495 (Parent (Declaration_Node (Subp)), Defining_Entity (N));
2497 if Is_Entity_Name (Name (N)) then
2498 Old_S := Entity (Name (N));
2500 if not Is_Frozen (Old_S)
2501 and then Operating_Mode /= Check_Semantics
2503 Append_Freeze_Action (Old_S, B_Node);
2505 Insert_After (N, B_Node);
2509 if Is_Intrinsic_Subprogram (Old_S)
2510 and then not In_Instance
2513 ("subprogram used in renaming_as_body cannot be intrinsic",
2518 Insert_After (N, B_Node);
2522 end Check_Frozen_Renaming;
2524 -----------------------------------
2525 -- Check_In_Previous_With_Clause --
2526 -----------------------------------
2528 procedure Check_In_Previous_With_Clause
2532 Pack : constant Entity_Id := Entity (Original_Node (Nam));
2537 Item := First (Context_Items (Parent (N)));
2539 while Present (Item)
2542 if Nkind (Item) = N_With_Clause
2544 -- Protect the frontend against previous critical errors
2546 and then Nkind (Name (Item)) /= N_Selected_Component
2547 and then Entity (Name (Item)) = Pack
2551 -- Find root library unit in with_clause
2553 while Nkind (Par) = N_Expanded_Name loop
2554 Par := Prefix (Par);
2557 if Is_Child_Unit (Entity (Original_Node (Par))) then
2559 ("& is not directly visible", Par, Entity (Par));
2568 -- On exit, package is not mentioned in a previous with_clause.
2569 -- Check if its prefix is.
2571 if Nkind (Nam) = N_Expanded_Name then
2572 Check_In_Previous_With_Clause (N, Prefix (Nam));
2574 elsif Pack /= Any_Id then
2575 Error_Msg_NE ("& is not visible", Nam, Pack);
2577 end Check_In_Previous_With_Clause;
2579 ---------------------------------
2580 -- Check_Library_Unit_Renaming --
2581 ---------------------------------
2583 procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id) is
2587 if Nkind (Parent (N)) /= N_Compilation_Unit then
2590 -- Check for library unit. Note that we used to check for the scope
2591 -- being Standard here, but that was wrong for Standard itself.
2593 elsif not Is_Compilation_Unit (Old_E)
2594 and then not Is_Child_Unit (Old_E)
2596 Error_Msg_N ("renamed unit must be a library unit", Name (N));
2598 -- Entities defined in Standard (operators and boolean literals) cannot
2599 -- be renamed as library units.
2601 elsif Scope (Old_E) = Standard_Standard
2602 and then Sloc (Old_E) = Standard_Location
2604 Error_Msg_N ("renamed unit must be a library unit", Name (N));
2606 elsif Present (Parent_Spec (N))
2607 and then Nkind (Unit (Parent_Spec (N))) = N_Generic_Package_Declaration
2608 and then not Is_Child_Unit (Old_E)
2611 ("renamed unit must be a child unit of generic parent", Name (N));
2613 elsif Nkind (N) in N_Generic_Renaming_Declaration
2614 and then Nkind (Name (N)) = N_Expanded_Name
2615 and then Is_Generic_Instance (Entity (Prefix (Name (N))))
2616 and then Is_Generic_Unit (Old_E)
2619 ("renamed generic unit must be a library unit", Name (N));
2621 elsif Ekind (Old_E) = E_Package
2622 or else Ekind (Old_E) = E_Generic_Package
2624 -- Inherit categorization flags
2626 New_E := Defining_Entity (N);
2627 Set_Is_Pure (New_E, Is_Pure (Old_E));
2628 Set_Is_Preelaborated (New_E, Is_Preelaborated (Old_E));
2629 Set_Is_Remote_Call_Interface (New_E,
2630 Is_Remote_Call_Interface (Old_E));
2631 Set_Is_Remote_Types (New_E, Is_Remote_Types (Old_E));
2632 Set_Is_Shared_Passive (New_E, Is_Shared_Passive (Old_E));
2634 end Check_Library_Unit_Renaming;
2640 procedure End_Scope is
2646 Id := First_Entity (Current_Scope);
2647 while Present (Id) loop
2648 -- An entity in the current scope is not necessarily the first one
2649 -- on its homonym chain. Find its predecessor if any,
2650 -- If it is an internal entity, it will not be in the visibility
2651 -- chain altogether, and there is nothing to unchain.
2653 if Id /= Current_Entity (Id) then
2654 Prev := Current_Entity (Id);
2655 while Present (Prev)
2656 and then Present (Homonym (Prev))
2657 and then Homonym (Prev) /= Id
2659 Prev := Homonym (Prev);
2662 -- Skip to end of loop if Id is not in the visibility chain
2664 if No (Prev) or else Homonym (Prev) /= Id then
2672 Set_Is_Immediately_Visible (Id, False);
2674 Outer := Homonym (Id);
2675 while Present (Outer) and then Scope (Outer) = Current_Scope loop
2676 Outer := Homonym (Outer);
2679 -- Reset homonym link of other entities, but do not modify link
2680 -- between entities in current scope, so that the back-end can have
2681 -- a proper count of local overloadings.
2684 Set_Name_Entity_Id (Chars (Id), Outer);
2686 elsif Scope (Prev) /= Scope (Id) then
2687 Set_Homonym (Prev, Outer);
2694 -- If the scope generated freeze actions, place them before the
2695 -- current declaration and analyze them. Type declarations and
2696 -- the bodies of initialization procedures can generate such nodes.
2697 -- We follow the parent chain until we reach a list node, which is
2698 -- the enclosing list of declarations. If the list appears within
2699 -- a protected definition, move freeze nodes outside the protected
2703 (Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions)
2707 L : constant List_Id := Scope_Stack.Table
2708 (Scope_Stack.Last).Pending_Freeze_Actions;
2711 if Is_Itype (Current_Scope) then
2712 Decl := Associated_Node_For_Itype (Current_Scope);
2714 Decl := Parent (Current_Scope);
2719 while not (Is_List_Member (Decl))
2720 or else Nkind (Parent (Decl)) = N_Protected_Definition
2721 or else Nkind (Parent (Decl)) = N_Task_Definition
2723 Decl := Parent (Decl);
2726 Insert_List_Before_And_Analyze (Decl, L);
2735 ---------------------
2736 -- End_Use_Clauses --
2737 ---------------------
2739 procedure End_Use_Clauses (Clause : Node_Id) is
2743 -- Remove Use_Type clauses first, because they affect the
2744 -- visibility of operators in subsequent used packages.
2747 while Present (U) loop
2748 if Nkind (U) = N_Use_Type_Clause then
2752 Next_Use_Clause (U);
2756 while Present (U) loop
2757 if Nkind (U) = N_Use_Package_Clause then
2758 End_Use_Package (U);
2761 Next_Use_Clause (U);
2763 end End_Use_Clauses;
2765 ---------------------
2766 -- End_Use_Package --
2767 ---------------------
2769 procedure End_Use_Package (N : Node_Id) is
2770 Pack_Name : Node_Id;
2775 function Is_Primitive_Operator
2777 F : Entity_Id) return Boolean;
2778 -- Check whether Op is a primitive operator of a use-visible type
2780 ---------------------------
2781 -- Is_Primitive_Operator --
2782 ---------------------------
2784 function Is_Primitive_Operator
2786 F : Entity_Id) return Boolean
2788 T : constant Entity_Id := Etype (F);
2791 and then Scope (T) = Scope (Op);
2792 end Is_Primitive_Operator;
2794 -- Start of processing for End_Use_Package
2797 Pack_Name := First (Names (N));
2798 while Present (Pack_Name) loop
2799 Pack := Entity (Pack_Name);
2801 if Ekind (Pack) = E_Package then
2802 if In_Open_Scopes (Pack) then
2805 elsif not Redundant_Use (Pack_Name) then
2806 Set_In_Use (Pack, False);
2807 Set_Current_Use_Clause (Pack, Empty);
2809 Id := First_Entity (Pack);
2810 while Present (Id) loop
2812 -- Preserve use-visibility of operators that are primitive
2813 -- operators of a type that is use_visible through an active
2816 if Nkind (Id) = N_Defining_Operator_Symbol
2818 (Is_Primitive_Operator (Id, First_Formal (Id))
2820 (Present (Next_Formal (First_Formal (Id)))
2822 Is_Primitive_Operator
2823 (Id, Next_Formal (First_Formal (Id)))))
2828 Set_Is_Potentially_Use_Visible (Id, False);
2831 if Is_Private_Type (Id)
2832 and then Present (Full_View (Id))
2834 Set_Is_Potentially_Use_Visible (Full_View (Id), False);
2840 if Present (Renamed_Object (Pack)) then
2841 Set_In_Use (Renamed_Object (Pack), False);
2842 Set_Current_Use_Clause (Renamed_Object (Pack), Empty);
2845 if Chars (Pack) = Name_System
2846 and then Scope (Pack) = Standard_Standard
2847 and then Present_System_Aux
2849 Id := First_Entity (System_Aux_Id);
2850 while Present (Id) loop
2851 Set_Is_Potentially_Use_Visible (Id, False);
2853 if Is_Private_Type (Id)
2854 and then Present (Full_View (Id))
2856 Set_Is_Potentially_Use_Visible (Full_View (Id), False);
2862 Set_In_Use (System_Aux_Id, False);
2866 Set_Redundant_Use (Pack_Name, False);
2873 if Present (Hidden_By_Use_Clause (N)) then
2874 Elmt := First_Elmt (Hidden_By_Use_Clause (N));
2875 while Present (Elmt) loop
2876 Set_Is_Immediately_Visible (Node (Elmt));
2880 Set_Hidden_By_Use_Clause (N, No_Elist);
2882 end End_Use_Package;
2888 procedure End_Use_Type (N : Node_Id) is
2895 Id := First (Subtype_Marks (N));
2896 while Present (Id) loop
2898 -- A call to rtsfind may occur while analyzing a use_type clause,
2899 -- in which case the type marks are not resolved yet, and there is
2900 -- nothing to remove.
2902 if not Is_Entity_Name (Id)
2903 or else No (Entity (Id))
2911 or else From_With_Type (T)
2915 -- Note that the use_Type clause may mention a subtype of the type
2916 -- whose primitive operations have been made visible. Here as
2917 -- elsewhere, it is the base type that matters for visibility.
2919 elsif In_Open_Scopes (Scope (Base_Type (T))) then
2922 elsif not Redundant_Use (Id) then
2923 Set_In_Use (T, False);
2924 Set_In_Use (Base_Type (T), False);
2925 Op_List := Collect_Primitive_Operations (T);
2927 Elmt := First_Elmt (Op_List);
2928 while Present (Elmt) loop
2929 if Nkind (Node (Elmt)) = N_Defining_Operator_Symbol then
2930 Set_Is_Potentially_Use_Visible (Node (Elmt), False);
2942 ----------------------
2943 -- Find_Direct_Name --
2944 ----------------------
2946 procedure Find_Direct_Name (N : Node_Id) is
2951 Inst : Entity_Id := Empty;
2952 -- Enclosing instance, if any
2954 Homonyms : Entity_Id;
2955 -- Saves start of homonym chain
2957 Nvis_Entity : Boolean;
2958 -- Set True to indicate that at there is at least one entity on the
2959 -- homonym chain which, while not visible, is visible enough from the
2960 -- user point of view to warrant an error message of "not visible"
2961 -- rather than undefined.
2963 Nvis_Is_Private_Subprg : Boolean := False;
2964 -- Ada 2005 (AI-262): Set True to indicate that a form of Beaujolais
2965 -- effect concerning library subprograms has been detected. Used to
2966 -- generate the precise error message.
2968 function From_Actual_Package (E : Entity_Id) return Boolean;
2969 -- Returns true if the entity is declared in a package that is
2970 -- an actual for a formal package of the current instance. Such an
2971 -- entity requires special handling because it may be use-visible
2972 -- but hides directly visible entities defined outside the instance.
2974 function Known_But_Invisible (E : Entity_Id) return Boolean;
2975 -- This function determines whether the entity E (which is not
2976 -- visible) can reasonably be considered to be known to the writer
2977 -- of the reference. This is a heuristic test, used only for the
2978 -- purposes of figuring out whether we prefer to complain that an
2979 -- entity is undefined or invisible (and identify the declaration
2980 -- of the invisible entity in the latter case). The point here is
2981 -- that we don't want to complain that something is invisible and
2982 -- then point to something entirely mysterious to the writer.
2984 procedure Nvis_Messages;
2985 -- Called if there are no visible entries for N, but there is at least
2986 -- one non-directly visible, or hidden declaration. This procedure
2987 -- outputs an appropriate set of error messages.
2989 procedure Undefined (Nvis : Boolean);
2990 -- This function is called if the current node has no corresponding
2991 -- visible entity or entities. The value set in Msg indicates whether
2992 -- an error message was generated (multiple error messages for the
2993 -- same variable are generally suppressed, see body for details).
2994 -- Msg is True if an error message was generated, False if not. This
2995 -- value is used by the caller to determine whether or not to output
2996 -- additional messages where appropriate. The parameter is set False
2997 -- to get the message "X is undefined", and True to get the message
2998 -- "X is not visible".
3000 -------------------------
3001 -- From_Actual_Package --
3002 -------------------------
3004 function From_Actual_Package (E : Entity_Id) return Boolean is
3005 Scop : constant Entity_Id := Scope (E);
3009 if not In_Instance then
3012 Inst := Current_Scope;
3013 while Present (Inst)
3014 and then Ekind (Inst) /= E_Package
3015 and then not Is_Generic_Instance (Inst)
3017 Inst := Scope (Inst);
3024 Act := First_Entity (Inst);
3025 while Present (Act) loop
3026 if Ekind (Act) = E_Package then
3028 -- Check for end of actuals list
3030 if Renamed_Object (Act) = Inst then
3033 elsif Present (Associated_Formal_Package (Act))
3034 and then Renamed_Object (Act) = Scop
3036 -- Entity comes from (instance of) formal package
3051 end From_Actual_Package;
3053 -------------------------
3054 -- Known_But_Invisible --
3055 -------------------------
3057 function Known_But_Invisible (E : Entity_Id) return Boolean is
3058 Fname : File_Name_Type;
3061 -- Entities in Standard are always considered to be known
3063 if Sloc (E) <= Standard_Location then
3066 -- An entity that does not come from source is always considered
3067 -- to be unknown, since it is an artifact of code expansion.
3069 elsif not Comes_From_Source (E) then
3072 -- In gnat internal mode, we consider all entities known
3074 elsif GNAT_Mode then
3078 -- Here we have an entity that is not from package Standard, and
3079 -- which comes from Source. See if it comes from an internal file.
3081 Fname := Unit_File_Name (Get_Source_Unit (E));
3083 -- Case of from internal file
3085 if Is_Internal_File_Name (Fname) then
3087 -- Private part entities in internal files are never considered
3088 -- to be known to the writer of normal application code.
3090 if Is_Hidden (E) then
3094 -- Entities from System packages other than System and
3095 -- System.Storage_Elements are not considered to be known.
3096 -- System.Auxxxx files are also considered known to the user.
3098 -- Should refine this at some point to generally distinguish
3099 -- between known and unknown internal files ???
3101 Get_Name_String (Fname);
3106 Name_Buffer (1 .. 2) /= "s-"
3108 Name_Buffer (3 .. 8) = "stoele"
3110 Name_Buffer (3 .. 5) = "aux";
3112 -- If not an internal file, then entity is definitely known,
3113 -- even if it is in a private part (the message generated will
3114 -- note that it is in a private part)
3119 end Known_But_Invisible;
3125 procedure Nvis_Messages is
3126 Comp_Unit : Node_Id;
3128 Hidden : Boolean := False;
3132 -- Ada 2005 (AI-262): Generate a precise error concerning the
3133 -- Beaujolais effect that was previously detected
3135 if Nvis_Is_Private_Subprg then
3137 pragma Assert (Nkind (E2) = N_Defining_Identifier
3138 and then Ekind (E2) = E_Function
3139 and then Scope (E2) = Standard_Standard
3140 and then Has_Private_With (E2));
3142 -- Find the sloc corresponding to the private with'ed unit
3144 Comp_Unit := Cunit (Current_Sem_Unit);
3145 Error_Msg_Sloc := No_Location;
3147 Item := First (Context_Items (Comp_Unit));
3148 while Present (Item) loop
3149 if Nkind (Item) = N_With_Clause
3150 and then Private_Present (Item)
3151 and then Entity (Name (Item)) = E2
3153 Error_Msg_Sloc := Sloc (Item);
3160 pragma Assert (Error_Msg_Sloc /= No_Location);
3162 Error_Msg_N ("(Ada 2005): hidden by private with clause #", N);
3166 Undefined (Nvis => True);
3170 -- First loop does hidden declarations
3173 while Present (Ent) loop
3174 if Is_Potentially_Use_Visible (Ent) then
3176 Error_Msg_N ("multiple use clauses cause hiding!", N);
3180 Error_Msg_Sloc := Sloc (Ent);
3181 Error_Msg_N ("hidden declaration#!", N);
3184 Ent := Homonym (Ent);
3187 -- If we found hidden declarations, then that's enough, don't
3188 -- bother looking for non-visible declarations as well.
3194 -- Second loop does non-directly visible declarations
3197 while Present (Ent) loop
3198 if not Is_Potentially_Use_Visible (Ent) then
3200 -- Do not bother the user with unknown entities
3202 if not Known_But_Invisible (Ent) then
3206 Error_Msg_Sloc := Sloc (Ent);
3208 -- Output message noting that there is a non-visible
3209 -- declaration, distinguishing the private part case.
3211 if Is_Hidden (Ent) then
3212 Error_Msg_N ("non-visible (private) declaration#!", N);
3214 Error_Msg_N ("non-visible declaration#!", N);
3216 if Is_Compilation_Unit (Ent)
3218 Nkind (Parent (Parent (N))) = N_Use_Package_Clause
3220 Error_Msg_Qual_Level := 99;
3221 Error_Msg_NE ("\\missing `WITH &;`", N, Ent);
3222 Error_Msg_Qual_Level := 0;
3226 -- Set entity and its containing package as referenced. We
3227 -- can't be sure of this, but this seems a better choice
3228 -- to avoid unused entity messages.
3230 if Comes_From_Source (Ent) then
3231 Set_Referenced (Ent);
3232 Set_Referenced (Cunit_Entity (Get_Source_Unit (Ent)));
3237 Ent := Homonym (Ent);
3246 procedure Undefined (Nvis : Boolean) is
3247 Emsg : Error_Msg_Id;
3250 -- We should never find an undefined internal name. If we do, then
3251 -- see if we have previous errors. If so, ignore on the grounds that
3252 -- it is probably a cascaded message (e.g. a block label from a badly
3253 -- formed block). If no previous errors, then we have a real internal
3254 -- error of some kind so raise an exception.
3256 if Is_Internal_Name (Chars (N)) then
3257 if Total_Errors_Detected /= 0 then
3260 raise Program_Error;
3264 -- A very specialized error check, if the undefined variable is
3265 -- a case tag, and the case type is an enumeration type, check
3266 -- for a possible misspelling, and if so, modify the identifier
3268 -- Named aggregate should also be handled similarly ???
3270 if Nkind (N) = N_Identifier
3271 and then Nkind (Parent (N)) = N_Case_Statement_Alternative
3273 Get_Name_String (Chars (N));
3276 Case_Str : constant String := Name_Buffer (1 .. Name_Len);
3277 Case_Stm : constant Node_Id := Parent (Parent (N));
3278 Case_Typ : constant Entity_Id := Etype (Expression (Case_Stm));
3279 Case_Rtp : constant Entity_Id := Root_Type (Case_Typ);
3284 if Is_Enumeration_Type (Case_Typ)
3285 and then Case_Rtp /= Standard_Character
3286 and then Case_Rtp /= Standard_Wide_Character
3287 and then Case_Rtp /= Standard_Wide_Wide_Character
3289 Lit := First_Literal (Case_Typ);
3290 Get_Name_String (Chars (Lit));
3292 if Chars (Lit) /= Chars (N)
3293 and then Is_Bad_Spelling_Of
3294 (Case_Str, Name_Buffer (1 .. Name_Len))
3296 Error_Msg_Node_2 := Lit;
3298 ("& is undefined, assume misspelling of &", N);
3299 Rewrite (N, New_Occurrence_Of (Lit, Sloc (N)));
3303 Lit := Next_Literal (Lit);
3308 -- Normal processing
3310 Set_Entity (N, Any_Id);
3311 Set_Etype (N, Any_Type);
3313 -- We use the table Urefs to keep track of entities for which we
3314 -- have issued errors for undefined references. Multiple errors
3315 -- for a single name are normally suppressed, however we modify
3316 -- the error message to alert the programmer to this effect.
3318 for J in Urefs.First .. Urefs.Last loop
3319 if Chars (N) = Chars (Urefs.Table (J).Node) then
3320 if Urefs.Table (J).Err /= No_Error_Msg
3321 and then Sloc (N) /= Urefs.Table (J).Loc
3323 Error_Msg_Node_1 := Urefs.Table (J).Node;
3325 if Urefs.Table (J).Nvis then
3326 Change_Error_Text (Urefs.Table (J).Err,
3327 "& is not visible (more references follow)");
3329 Change_Error_Text (Urefs.Table (J).Err,
3330 "& is undefined (more references follow)");
3333 Urefs.Table (J).Err := No_Error_Msg;
3336 -- Although we will set Msg False, and thus suppress the
3337 -- message, we also set Error_Posted True, to avoid any
3338 -- cascaded messages resulting from the undefined reference.
3341 Set_Error_Posted (N, True);
3346 -- If entry not found, this is first undefined occurrence
3349 Error_Msg_N ("& is not visible!", N);
3353 Error_Msg_N ("& is undefined!", N);
3356 -- A very bizarre special check, if the undefined identifier
3357 -- is put or put_line, then add a special error message (since
3358 -- this is a very common error for beginners to make).
3360 if Chars (N) = Name_Put or else Chars (N) = Name_Put_Line then
3362 ("\\possible missing `WITH Ada.Text_'I'O; " &
3363 "USE Ada.Text_'I'O`!", N);
3365 -- Another special check if N is the prefix of a selected
3366 -- component which is a known unit, add message complaining
3367 -- about missing with for this unit.
3369 elsif Nkind (Parent (N)) = N_Selected_Component
3370 and then N = Prefix (Parent (N))
3371 and then Is_Known_Unit (Parent (N))
3373 Error_Msg_Node_2 := Selector_Name (Parent (N));
3374 Error_Msg_N ("\\missing `WITH &.&;`", Prefix (Parent (N)));
3377 -- Now check for possible misspellings
3379 Get_Name_String (Chars (N));
3383 Ematch : Entity_Id := Empty;
3385 Last_Name_Id : constant Name_Id :=
3386 Name_Id (Nat (First_Name_Id) +
3387 Name_Entries_Count - 1);
3389 S : constant String (1 .. Name_Len) :=
3390 Name_Buffer (1 .. Name_Len);
3393 for N in First_Name_Id .. Last_Name_Id loop
3394 E := Get_Name_Entity_Id (N);
3397 and then (Is_Immediately_Visible (E)
3399 Is_Potentially_Use_Visible (E))
3401 Get_Name_String (N);
3403 if Is_Bad_Spelling_Of
3404 (S, Name_Buffer (1 .. Name_Len))
3412 if Present (Ematch) then
3413 Error_Msg_NE ("\possible misspelling of&", N, Ematch);
3418 -- Make entry in undefined references table unless the full errors
3419 -- switch is set, in which case by refraining from generating the
3420 -- table entry, we guarantee that we get an error message for every
3421 -- undefined reference.
3423 if not All_Errors_Mode then
3424 Urefs.Increment_Last;
3425 Urefs.Table (Urefs.Last).Node := N;
3426 Urefs.Table (Urefs.Last).Err := Emsg;
3427 Urefs.Table (Urefs.Last).Nvis := Nvis;
3428 Urefs.Table (Urefs.Last).Loc := Sloc (N);
3434 -- Start of processing for Find_Direct_Name
3437 -- If the entity pointer is already set, this is an internal node, or
3438 -- a node that is analyzed more than once, after a tree modification.
3439 -- In such a case there is no resolution to perform, just set the type.
3441 if Present (Entity (N)) then
3442 if Is_Type (Entity (N)) then
3443 Set_Etype (N, Entity (N));
3447 Entyp : constant Entity_Id := Etype (Entity (N));
3450 -- One special case here. If the Etype field is already set,
3451 -- and references the packed array type corresponding to the
3452 -- etype of the referenced entity, then leave it alone. This
3453 -- happens for trees generated from Exp_Pakd, where expressions
3454 -- can be deliberately "mis-typed" to the packed array type.
3456 if Is_Array_Type (Entyp)
3457 and then Is_Packed (Entyp)
3458 and then Present (Etype (N))
3459 and then Etype (N) = Packed_Array_Type (Entyp)
3463 -- If not that special case, then just reset the Etype
3466 Set_Etype (N, Etype (Entity (N)));
3474 -- Here if Entity pointer was not set, we need full visibility analysis
3475 -- First we generate debugging output if the debug E flag is set.
3477 if Debug_Flag_E then
3478 Write_Str ("Looking for ");
3479 Write_Name (Chars (N));
3483 Homonyms := Current_Entity (N);
3484 Nvis_Entity := False;
3487 while Present (E) loop
3489 -- If entity is immediately visible or potentially use
3490 -- visible, then process the entity and we are done.
3492 if Is_Immediately_Visible (E) then
3493 goto Immediately_Visible_Entity;
3495 elsif Is_Potentially_Use_Visible (E) then
3496 goto Potentially_Use_Visible_Entity;
3498 -- Note if a known but invisible entity encountered
3500 elsif Known_But_Invisible (E) then
3501 Nvis_Entity := True;
3504 -- Move to next entity in chain and continue search
3509 -- If no entries on homonym chain that were potentially visible,
3510 -- and no entities reasonably considered as non-visible, then
3511 -- we have a plain undefined reference, with no additional
3512 -- explanation required!
3514 if not Nvis_Entity then
3515 Undefined (Nvis => False);
3517 -- Otherwise there is at least one entry on the homonym chain that
3518 -- is reasonably considered as being known and non-visible.
3526 -- Processing for a potentially use visible entry found. We must search
3527 -- the rest of the homonym chain for two reasons. First, if there is a
3528 -- directly visible entry, then none of the potentially use-visible
3529 -- entities are directly visible (RM 8.4(10)). Second, we need to check
3530 -- for the case of multiple potentially use-visible entries hiding one
3531 -- another and as a result being non-directly visible (RM 8.4(11)).
3533 <<Potentially_Use_Visible_Entity>> declare
3534 Only_One_Visible : Boolean := True;
3535 All_Overloadable : Boolean := Is_Overloadable (E);
3539 while Present (E2) loop
3540 if Is_Immediately_Visible (E2) then
3542 -- If the use-visible entity comes from the actual for a
3543 -- formal package, it hides a directly visible entity from
3544 -- outside the instance.
3546 if From_Actual_Package (E)
3547 and then Scope_Depth (E2) < Scope_Depth (Inst)
3552 goto Immediately_Visible_Entity;
3555 elsif Is_Potentially_Use_Visible (E2) then
3556 Only_One_Visible := False;
3557 All_Overloadable := All_Overloadable and Is_Overloadable (E2);
3559 -- Ada 2005 (AI-262): Protect against a form of Beujolais effect
3560 -- that can occurr in private_with clauses. Example:
3563 -- private with B; package A is
3564 -- package C is function B return Integer;
3566 -- V1 : Integer := B;
3567 -- private function B return Integer;
3568 -- V2 : Integer := B;
3571 -- V1 resolves to A.B, but V2 resolves to library unit B
3573 elsif Ekind (E2) = E_Function
3574 and then Scope (E2) = Standard_Standard
3575 and then Has_Private_With (E2)
3577 Only_One_Visible := False;
3578 All_Overloadable := False;
3579 Nvis_Is_Private_Subprg := True;
3586 -- On falling through this loop, we have checked that there are no
3587 -- immediately visible entities. Only_One_Visible is set if exactly
3588 -- one potentially use visible entity exists. All_Overloadable is
3589 -- set if all the potentially use visible entities are overloadable.
3590 -- The condition for legality is that either there is one potentially
3591 -- use visible entity, or if there is more than one, then all of them
3592 -- are overloadable.
3594 if Only_One_Visible or All_Overloadable then
3597 -- If there is more than one potentially use-visible entity and at
3598 -- least one of them non-overloadable, we have an error (RM 8.4(11).
3599 -- Note that E points to the first such entity on the homonym list.
3600 -- Special case: if one of the entities is declared in an actual
3601 -- package, it was visible in the generic, and takes precedence over
3602 -- other entities that are potentially use-visible. Same if it is
3603 -- declared in a local instantiation of the current instance.
3608 -- Find current instance
3610 Inst := Current_Scope;
3611 while Present (Inst)
3612 and then Inst /= Standard_Standard
3614 if Is_Generic_Instance (Inst) then
3618 Inst := Scope (Inst);
3622 while Present (E2) loop
3623 if From_Actual_Package (E2)
3625 (Is_Generic_Instance (Scope (E2))
3626 and then Scope_Depth (Scope (E2)) > Scope_Depth (Inst))
3639 Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
3641 -- A use-clause in the body of a system file creates conflict
3642 -- with some entity in a user scope, while rtsfind is active.
3643 -- Keep only the entity coming from another predefined unit.
3646 while Present (E2) loop
3647 if Is_Predefined_File_Name
3648 (Unit_File_Name (Get_Source_Unit (Sloc (E2))))
3657 -- Entity must exist because predefined unit is correct
3659 raise Program_Error;
3668 -- Come here with E set to the first immediately visible entity on
3669 -- the homonym chain. This is the one we want unless there is another
3670 -- immediately visible entity further on in the chain for a more
3671 -- inner scope (RM 8.3(8)).
3673 <<Immediately_Visible_Entity>> declare
3678 -- Find scope level of initial entity. When compiling through
3679 -- Rtsfind, the previous context is not completely invisible, and
3680 -- an outer entity may appear on the chain, whose scope is below
3681 -- the entry for Standard that delimits the current scope stack.
3682 -- Indicate that the level for this spurious entry is outside of
3683 -- the current scope stack.
3685 Level := Scope_Stack.Last;
3687 Scop := Scope_Stack.Table (Level).Entity;
3688 exit when Scop = Scope (E);
3690 exit when Scop = Standard_Standard;
3693 -- Now search remainder of homonym chain for more inner entry
3694 -- If the entity is Standard itself, it has no scope, and we
3695 -- compare it with the stack entry directly.
3698 while Present (E2) loop
3699 if Is_Immediately_Visible (E2) then
3701 -- If a generic package contains a local declaration that
3702 -- has the same name as the generic, there may be a visibility
3703 -- conflict in an instance, where the local declaration must
3704 -- also hide the name of the corresponding package renaming.
3705 -- We check explicitly for a package declared by a renaming,
3706 -- whose renamed entity is an instance that is on the scope
3707 -- stack, and that contains a homonym in the same scope. Once
3708 -- we have found it, we know that the package renaming is not
3709 -- immediately visible, and that the identifier denotes the
3710 -- other entity (and its homonyms if overloaded).
3712 if Scope (E) = Scope (E2)
3713 and then Ekind (E) = E_Package
3714 and then Present (Renamed_Object (E))
3715 and then Is_Generic_Instance (Renamed_Object (E))
3716 and then In_Open_Scopes (Renamed_Object (E))
3717 and then Comes_From_Source (N)
3719 Set_Is_Immediately_Visible (E, False);
3723 for J in Level + 1 .. Scope_Stack.Last loop
3724 if Scope_Stack.Table (J).Entity = Scope (E2)
3725 or else Scope_Stack.Table (J).Entity = E2
3738 -- At the end of that loop, E is the innermost immediately
3739 -- visible entity, so we are all set.
3742 -- Come here with entity found, and stored in E
3746 if Comes_From_Source (N)
3747 and then Is_Remote_Access_To_Subprogram_Type (E)
3748 and then Expander_Active
3749 and then Get_PCS_Name /= Name_No_DSA
3752 New_Occurrence_Of (Equivalent_Type (E), Sloc (N)));
3757 -- Why no Style_Check here???
3762 Set_Etype (N, Get_Full_View (Etype (E)));
3765 if Debug_Flag_E then
3766 Write_Str (" found ");
3767 Write_Entity_Info (E, " ");
3770 -- If the Ekind of the entity is Void, it means that all homonyms
3771 -- are hidden from all visibility (RM 8.3(5,14-20)). However, this
3772 -- test is skipped if the current scope is a record and the name is
3773 -- a pragma argument expression (case of Atomic and Volatile pragmas
3774 -- and possibly other similar pragmas added later, which are allowed
3775 -- to reference components in the current record).
3777 if Ekind (E) = E_Void
3779 (not Is_Record_Type (Current_Scope)
3780 or else Nkind (Parent (N)) /= N_Pragma_Argument_Association)
3782 Premature_Usage (N);
3784 -- If the entity is overloadable, collect all interpretations of the
3785 -- name for subsequent overload resolution. We optimize a bit here to
3786 -- do this only if we have an overloadable entity that is not on its
3787 -- own on the homonym chain.
3789 elsif Is_Overloadable (E)
3790 and then (Present (Homonym (E)) or else Current_Entity (N) /= E)
3792 Collect_Interps (N);
3794 -- If no homonyms were visible, the entity is unambiguous
3796 if not Is_Overloaded (N) then
3797 Generate_Reference (E, N);
3800 -- Case of non-overloadable entity, set the entity providing that
3801 -- we do not have the case of a discriminant reference within a
3802 -- default expression. Such references are replaced with the
3803 -- corresponding discriminal, which is the formal corresponding to
3804 -- to the discriminant in the initialization procedure.
3807 -- Entity is unambiguous, indicate that it is referenced here One
3808 -- slightly odd case is that we do not want to set the Referenced
3809 -- flag if the entity is a label, and the identifier is the label
3810 -- in the source, since this is not a reference from the point of
3813 if Nkind (Parent (N)) = N_Label then
3815 R : constant Boolean := Referenced (E);
3818 Generate_Reference (E, N);
3819 Set_Referenced (E, R);
3822 -- Normal case, not a label. Generate reference
3825 Generate_Reference (E, N);
3826 Check_Nested_Access (E);
3829 -- Set Entity, with style check if need be. For a discriminant
3830 -- reference, replace by the corresponding discriminal, i.e. the
3831 -- parameter of the initialization procedure that corresponds to
3832 -- the discriminant. If this replacement is being performed, there
3833 -- is no style check to perform.
3835 -- This replacement must not be done if we are currently
3836 -- processing a generic spec or body, because the discriminal
3837 -- has not been not generated in this case.
3839 if not In_Default_Expression
3840 or else Ekind (E) /= E_Discriminant
3841 or else Inside_A_Generic
3843 Set_Entity_With_Style_Check (N, E);
3845 -- The replacement is not done either for a task discriminant that
3846 -- appears in a default expression of an entry parameter. See
3847 -- Expand_Discriminant in exp_ch2 for details on their handling.
3849 elsif Is_Concurrent_Type (Scope (E)) then
3856 and then Nkind (P) /= N_Parameter_Specification
3857 and then Nkind (P) /= N_Component_Declaration
3863 and then Nkind (P) = N_Parameter_Specification
3867 Set_Entity (N, Discriminal (E));
3871 -- Otherwise, this is a discriminant in a context in which
3872 -- it is a reference to the corresponding parameter of the
3873 -- init proc for the enclosing type.
3876 Set_Entity (N, Discriminal (E));
3880 end Find_Direct_Name;
3882 ------------------------
3883 -- Find_Expanded_Name --
3884 ------------------------
3886 -- This routine searches the homonym chain of the entity until it finds
3887 -- an entity declared in the scope denoted by the prefix. If the entity
3888 -- is private, it may nevertheless be immediately visible, if we are in
3889 -- the scope of its declaration.
3891 procedure Find_Expanded_Name (N : Node_Id) is
3892 Selector : constant Node_Id := Selector_Name (N);
3893 Candidate : Entity_Id := Empty;
3899 P_Name := Entity (Prefix (N));
3902 -- If the prefix is a renamed package, look for the entity
3903 -- in the original package.
3905 if Ekind (P_Name) = E_Package
3906 and then Present (Renamed_Object (P_Name))
3908 P_Name := Renamed_Object (P_Name);
3910 -- Rewrite node with entity field pointing to renamed object
3912 Rewrite (Prefix (N), New_Copy (Prefix (N)));
3913 Set_Entity (Prefix (N), P_Name);
3915 -- If the prefix is an object of a concurrent type, look for
3916 -- the entity in the associated task or protected type.
3918 elsif Is_Concurrent_Type (Etype (P_Name)) then
3919 P_Name := Etype (P_Name);
3922 Id := Current_Entity (Selector);
3925 Is_New_Candidate : Boolean;
3928 while Present (Id) loop
3929 if Scope (Id) = P_Name then
3931 Is_New_Candidate := True;
3933 -- Ada 2005 (AI-217): Handle shadow entities associated with types
3934 -- declared in limited-withed nested packages. We don't need to
3935 -- handle E_Incomplete_Subtype entities because the entities in
3936 -- the limited view are always E_Incomplete_Type entities (see
3937 -- Build_Limited_Views). Regarding the expression used to evaluate
3938 -- the scope, it is important to note that the limited view also
3939 -- has shadow entities associated nested packages. For this reason
3940 -- the correct scope of the entity is the scope of the real entity
3942 elsif From_With_Type (Id)
3943 and then Is_Type (Id)
3944 and then Ekind (Id) = E_Incomplete_Type
3945 and then Present (Non_Limited_View (Id))
3946 and then Scope (Non_Limited_View (Id)) = P_Name
3948 Candidate := Non_Limited_View (Id);
3949 Is_New_Candidate := True;
3952 Is_New_Candidate := False;
3955 if Is_New_Candidate then
3956 if Is_Child_Unit (Id) then
3957 exit when Is_Visible_Child_Unit (Id)
3958 or else Is_Immediately_Visible (Id);
3961 exit when not Is_Hidden (Id)
3962 or else Is_Immediately_Visible (Id);
3971 and then (Ekind (P_Name) = E_Procedure
3973 Ekind (P_Name) = E_Function)
3974 and then Is_Generic_Instance (P_Name)
3976 -- Expanded name denotes entity in (instance of) generic subprogram.
3977 -- The entity may be in the subprogram instance, or may denote one of
3978 -- the formals, which is declared in the enclosing wrapper package.
3980 P_Name := Scope (P_Name);
3982 Id := Current_Entity (Selector);
3983 while Present (Id) loop
3984 exit when Scope (Id) = P_Name;
3989 if No (Id) or else Chars (Id) /= Chars (Selector) then
3990 Set_Etype (N, Any_Type);
3992 -- If we are looking for an entity defined in System, try to
3993 -- find it in the child package that may have been provided as
3994 -- an extension to System. The Extend_System pragma will have
3995 -- supplied the name of the extension, which may have to be loaded.
3997 if Chars (P_Name) = Name_System
3998 and then Scope (P_Name) = Standard_Standard
3999 and then Present (System_Extend_Unit)
4000 and then Present_System_Aux (N)
4002 Set_Entity (Prefix (N), System_Aux_Id);
4003 Find_Expanded_Name (N);
4006 elsif Nkind (Selector) = N_Operator_Symbol
4007 and then Has_Implicit_Operator (N)
4009 -- There is an implicit instance of the predefined operator in
4010 -- the given scope. The operator entity is defined in Standard.
4011 -- Has_Implicit_Operator makes the node into an Expanded_Name.
4015 elsif Nkind (Selector) = N_Character_Literal
4016 and then Has_Implicit_Character_Literal (N)
4018 -- If there is no literal defined in the scope denoted by the
4019 -- prefix, the literal may belong to (a type derived from)
4020 -- Standard_Character, for which we have no explicit literals.
4025 -- If the prefix is a single concurrent object, use its
4026 -- name in the error message, rather than that of the
4029 if Is_Concurrent_Type (P_Name)
4030 and then Is_Internal_Name (Chars (P_Name))
4032 Error_Msg_Node_2 := Entity (Prefix (N));
4034 Error_Msg_Node_2 := P_Name;
4037 if P_Name = System_Aux_Id then
4038 P_Name := Scope (P_Name);
4039 Set_Entity (Prefix (N), P_Name);
4042 if Present (Candidate) then
4044 -- If we know that the unit is a child unit we can give a more
4045 -- accurate error message.
4047 if Is_Child_Unit (Candidate) then
4049 -- If the candidate is a private child unit and we are in
4050 -- the visible part of a public unit, specialize the error
4051 -- message. There might be a private with_clause for it,
4052 -- but it is not currently active.
4054 if Is_Private_Descendant (Candidate)
4055 and then Ekind (Current_Scope) = E_Package
4056 and then not In_Private_Part (Current_Scope)
4057 and then not Is_Private_Descendant (Current_Scope)
4059 Error_Msg_N ("private child unit& is not visible here",
4062 -- Normal case where we have a missing with for a child unit
4065 Error_Msg_Qual_Level := 99;
4066 Error_Msg_NE ("missing `WITH &;`", Selector, Candidate);
4067 Error_Msg_Qual_Level := 0;
4070 -- Here we don't know that this is a child unit
4073 Error_Msg_NE ("& is not a visible entity of&", N, Selector);
4077 -- Within the instantiation of a child unit, the prefix may
4078 -- denote the parent instance, but the selector has the name
4079 -- of the original child. Find whether we are within the
4080 -- corresponding instance, and get the proper entity, which
4081 -- can only be an enclosing scope.
4084 and then In_Open_Scopes (P_Name)
4085 and then Is_Generic_Instance (P_Name)
4088 S : Entity_Id := Current_Scope;
4092 for J in reverse 0 .. Scope_Stack.Last loop
4093 S := Scope_Stack.Table (J).Entity;
4095 exit when S = Standard_Standard;
4097 if Ekind (S) = E_Function
4098 or else Ekind (S) = E_Package
4099 or else Ekind (S) = E_Procedure
4101 P := Generic_Parent (Specification
4102 (Unit_Declaration_Node (S)));
4105 and then Chars (Scope (P)) = Chars (O_Name)
4106 and then Chars (P) = Chars (Selector)
4117 -- If this is a selection from Ada, System or Interfaces, then
4118 -- we assume a missing with for the corresponding package.
4120 if Is_Known_Unit (N) then
4121 if not Error_Posted (N) then
4122 Error_Msg_Node_2 := Selector;
4123 Error_Msg_N ("missing `WITH &.&;`", Prefix (N));
4126 -- If this is a selection from a dummy package, then suppress
4127 -- the error message, of course the entity is missing if the
4128 -- package is missing!
4130 elsif Sloc (Error_Msg_Node_2) = No_Location then
4133 -- Here we have the case of an undefined component
4136 Error_Msg_NE ("& not declared in&", N, Selector);
4138 -- Check for misspelling of some entity in prefix
4140 Id := First_Entity (P_Name);
4141 Get_Name_String (Chars (Selector));
4144 S : constant String (1 .. Name_Len) :=
4145 Name_Buffer (1 .. Name_Len);
4147 while Present (Id) loop
4148 Get_Name_String (Chars (Id));
4149 if Is_Bad_Spelling_Of
4150 (Name_Buffer (1 .. Name_Len), S)
4151 and then not Is_Internal_Name (Chars (Id))
4154 ("possible misspelling of&", Selector, Id);
4162 -- Specialize the message if this may be an instantiation
4163 -- of a child unit that was not mentioned in the context.
4165 if Nkind (Parent (N)) = N_Package_Instantiation
4166 and then Is_Generic_Instance (Entity (Prefix (N)))
4167 and then Is_Compilation_Unit
4168 (Generic_Parent (Parent (Entity (Prefix (N)))))
4170 Error_Msg_Node_2 := Selector;
4171 Error_Msg_N ("\missing `WITH &.&;`", Prefix (N));
4181 if Comes_From_Source (N)
4182 and then Is_Remote_Access_To_Subprogram_Type (Id)
4183 and then Present (Equivalent_Type (Id))
4185 -- If we are not actually generating distribution code (i.e. the
4186 -- current PCS is the dummy non-distributed version), then the
4187 -- Equivalent_Type will be missing, and Id should be treated as
4188 -- a regular access-to-subprogram type.
4190 Id := Equivalent_Type (Id);
4191 Set_Chars (Selector, Chars (Id));
4194 -- Ada 2005 (AI-50217): Check usage of entities in limited withed units
4196 if Ekind (P_Name) = E_Package
4197 and then From_With_Type (P_Name)
4199 if From_With_Type (Id)
4200 or else Is_Type (Id)
4201 or else Ekind (Id) = E_Package
4206 ("limited withed package can only be used to access "
4207 & " incomplete types",
4212 if Is_Task_Type (P_Name)
4213 and then ((Ekind (Id) = E_Entry
4214 and then Nkind (Parent (N)) /= N_Attribute_Reference)
4216 (Ekind (Id) = E_Entry_Family
4218 Nkind (Parent (Parent (N))) /= N_Attribute_Reference))
4220 -- It is an entry call after all, either to the current task (which
4221 -- will deadlock) or to an enclosing task.
4223 Analyze_Selected_Component (N);
4227 Change_Selected_Component_To_Expanded_Name (N);
4229 -- Do style check and generate reference, but skip both steps if this
4230 -- entity has homonyms, since we may not have the right homonym set yet.
4231 -- The proper homonym will be set during the resolve phase.
4233 if Has_Homonym (Id) then
4236 Set_Entity_With_Style_Check (N, Id);
4237 Generate_Reference (Id, N);
4240 if Is_Type (Id) then
4243 Set_Etype (N, Get_Full_View (Etype (Id)));
4246 -- If the Ekind of the entity is Void, it means that all homonyms are
4247 -- hidden from all visibility (RM 8.3(5,14-20)).
4249 if Ekind (Id) = E_Void then
4250 Premature_Usage (N);
4252 elsif Is_Overloadable (Id)
4253 and then Present (Homonym (Id))
4256 H : Entity_Id := Homonym (Id);
4259 while Present (H) loop
4260 if Scope (H) = Scope (Id)
4263 or else Is_Immediately_Visible (H))
4265 Collect_Interps (N);
4272 -- If an extension of System is present, collect possible explicit
4273 -- overloadings declared in the extension.
4275 if Chars (P_Name) = Name_System
4276 and then Scope (P_Name) = Standard_Standard
4277 and then Present (System_Extend_Unit)
4278 and then Present_System_Aux (N)
4280 H := Current_Entity (Id);
4282 while Present (H) loop
4283 if Scope (H) = System_Aux_Id then
4284 Add_One_Interp (N, H, Etype (H));
4293 if Nkind (Selector_Name (N)) = N_Operator_Symbol
4294 and then Scope (Id) /= Standard_Standard
4296 -- In addition to user-defined operators in the given scope, there
4297 -- may be an implicit instance of the predefined operator. The
4298 -- operator (defined in Standard) is found in Has_Implicit_Operator,
4299 -- and added to the interpretations. Procedure Add_One_Interp will
4300 -- determine which hides which.
4302 if Has_Implicit_Operator (N) then
4306 end Find_Expanded_Name;
4308 -------------------------
4309 -- Find_Renamed_Entity --
4310 -------------------------
4312 function Find_Renamed_Entity
4316 Is_Actual : Boolean := False) return Entity_Id
4319 I1 : Interp_Index := 0; -- Suppress junk warnings
4325 function Enclosing_Instance return Entity_Id;
4326 -- If the renaming determines the entity for the default of a formal
4327 -- subprogram nested within another instance, choose the innermost
4328 -- candidate. This is because if the formal has a box, and we are within
4329 -- an enclosing instance where some candidate interpretations are local
4330 -- to this enclosing instance, we know that the default was properly
4331 -- resolved when analyzing the generic, so we prefer the local
4332 -- candidates to those that are external. This is not always the case
4333 -- but is a reasonable heuristic on the use of nested generics. The
4334 -- proper solution requires a full renaming model.
4336 function Is_Visible_Operation (Op : Entity_Id) return Boolean;
4337 -- If the renamed entity is an implicit operator, check whether it is
4338 -- visible because its operand type is properly visible. This check
4339 -- applies to explicit renamed entities that appear in the source in a
4340 -- renaming declaration or a formal subprogram instance, but not to
4341 -- default generic actuals with a name.
4343 function Report_Overload return Entity_Id;
4344 -- List possible interpretations, and specialize message in the
4345 -- case of a generic actual.
4347 function Within (Inner, Outer : Entity_Id) return Boolean;
4348 -- Determine whether a candidate subprogram is defined within the
4349 -- enclosing instance. If yes, it has precedence over outer candidates.
4351 ------------------------
4352 -- Enclosing_Instance --
4353 ------------------------
4355 function Enclosing_Instance return Entity_Id is
4359 if not Is_Generic_Instance (Current_Scope)
4360 and then not Is_Actual
4365 S := Scope (Current_Scope);
4366 while S /= Standard_Standard loop
4367 if Is_Generic_Instance (S) then
4375 end Enclosing_Instance;
4377 --------------------------
4378 -- Is_Visible_Operation --
4379 --------------------------
4381 function Is_Visible_Operation (Op : Entity_Id) return Boolean is
4387 if Ekind (Op) /= E_Operator
4388 or else Scope (Op) /= Standard_Standard
4389 or else (In_Instance
4392 or else Present (Enclosing_Instance)))
4397 -- For a fixed point type operator, check the resulting type,
4398 -- because it may be a mixed mode integer * fixed operation.
4400 if Present (Next_Formal (First_Formal (New_S)))
4401 and then Is_Fixed_Point_Type (Etype (New_S))
4403 Typ := Etype (New_S);
4405 Typ := Etype (First_Formal (New_S));
4408 Btyp := Base_Type (Typ);
4410 if Nkind (Nam) /= N_Expanded_Name then
4411 return (In_Open_Scopes (Scope (Btyp))
4412 or else Is_Potentially_Use_Visible (Btyp)
4413 or else In_Use (Btyp)
4414 or else In_Use (Scope (Btyp)));
4417 Scop := Entity (Prefix (Nam));
4419 if Ekind (Scop) = E_Package
4420 and then Present (Renamed_Object (Scop))
4422 Scop := Renamed_Object (Scop);
4425 -- Operator is visible if prefix of expanded name denotes
4426 -- scope of type, or else type type is defined in System_Aux
4427 -- and the prefix denotes System.
4429 return Scope (Btyp) = Scop
4430 or else (Scope (Btyp) = System_Aux_Id
4431 and then Scope (Scope (Btyp)) = Scop);
4434 end Is_Visible_Operation;
4440 function Within (Inner, Outer : Entity_Id) return Boolean is
4444 Sc := Scope (Inner);
4445 while Sc /= Standard_Standard loop
4456 ---------------------
4457 -- Report_Overload --
4458 ---------------------
4460 function Report_Overload return Entity_Id is
4464 ("ambiguous actual subprogram&, " &
4465 "possible interpretations:", N, Nam);
4468 ("ambiguous subprogram, " &
4469 "possible interpretations:", N);
4472 List_Interps (Nam, N);
4474 end Report_Overload;
4476 -- Start of processing for Find_Renamed_Entry
4480 Candidate_Renaming := Empty;
4482 if not Is_Overloaded (Nam) then
4483 if Entity_Matches_Spec (Entity (Nam), New_S)
4484 and then Is_Visible_Operation (Entity (Nam))
4486 Old_S := Entity (Nam);
4489 Present (First_Formal (Entity (Nam)))
4490 and then Present (First_Formal (New_S))
4491 and then (Base_Type (Etype (First_Formal (Entity (Nam))))
4492 = Base_Type (Etype (First_Formal (New_S))))
4494 Candidate_Renaming := Entity (Nam);
4498 Get_First_Interp (Nam, Ind, It);
4499 while Present (It.Nam) loop
4500 if Entity_Matches_Spec (It.Nam, New_S)
4501 and then Is_Visible_Operation (It.Nam)
4503 if Old_S /= Any_Id then
4505 -- Note: The call to Disambiguate only happens if a
4506 -- previous interpretation was found, in which case I1
4507 -- has received a value.
4509 It1 := Disambiguate (Nam, I1, Ind, Etype (Old_S));
4511 if It1 = No_Interp then
4512 Inst := Enclosing_Instance;
4514 if Present (Inst) then
4515 if Within (It.Nam, Inst) then
4517 elsif Within (Old_S, Inst) then
4520 return Report_Overload;
4524 return Report_Overload;
4538 Present (First_Formal (It.Nam))
4539 and then Present (First_Formal (New_S))
4540 and then (Base_Type (Etype (First_Formal (It.Nam)))
4541 = Base_Type (Etype (First_Formal (New_S))))
4543 Candidate_Renaming := It.Nam;
4546 Get_Next_Interp (Ind, It);
4549 Set_Entity (Nam, Old_S);
4550 Set_Is_Overloaded (Nam, False);
4554 end Find_Renamed_Entity;
4556 -----------------------------
4557 -- Find_Selected_Component --
4558 -----------------------------
4560 procedure Find_Selected_Component (N : Node_Id) is
4561 P : constant Node_Id := Prefix (N);
4564 -- Entity denoted by prefix
4574 if Nkind (P) = N_Error then
4577 -- If the selector already has an entity, the node has been constructed
4578 -- in the course of expansion, and is known to be valid. Do not verify
4579 -- that it is defined for the type (it may be a private component used
4580 -- in the expansion of record equality).
4582 elsif Present (Entity (Selector_Name (N))) then
4585 or else Etype (N) = Any_Type
4588 Sel_Name : constant Node_Id := Selector_Name (N);
4589 Selector : constant Entity_Id := Entity (Sel_Name);
4593 Set_Etype (Sel_Name, Etype (Selector));
4595 if not Is_Entity_Name (P) then
4599 -- Build an actual subtype except for the first parameter
4600 -- of an init proc, where this actual subtype is by
4601 -- definition incorrect, since the object is uninitialized
4602 -- (and does not even have defined discriminants etc.)
4604 if Is_Entity_Name (P)
4605 and then Ekind (Entity (P)) = E_Function
4607 Nam := New_Copy (P);
4609 if Is_Overloaded (P) then
4610 Save_Interps (P, Nam);
4614 Make_Function_Call (Sloc (P), Name => Nam));
4616 Analyze_Selected_Component (N);
4619 elsif Ekind (Selector) = E_Component
4620 and then (not Is_Entity_Name (P)
4621 or else Chars (Entity (P)) /= Name_uInit)
4624 Build_Actual_Subtype_Of_Component (
4625 Etype (Selector), N);
4630 if No (C_Etype) then
4631 C_Etype := Etype (Selector);
4633 Insert_Action (N, C_Etype);
4634 C_Etype := Defining_Identifier (C_Etype);
4637 Set_Etype (N, C_Etype);
4640 -- If this is the name of an entry or protected operation, and
4641 -- the prefix is an access type, insert an explicit dereference,
4642 -- so that entry calls are treated uniformly.
4644 if Is_Access_Type (Etype (P))
4645 and then Is_Concurrent_Type (Designated_Type (Etype (P)))
4648 New_P : constant Node_Id :=
4649 Make_Explicit_Dereference (Sloc (P),
4650 Prefix => Relocate_Node (P));
4653 Set_Etype (P, Designated_Type (Etype (Prefix (P))));
4657 -- If the selected component appears within a default expression
4658 -- and it has an actual subtype, the pre-analysis has not yet
4659 -- completed its analysis, because Insert_Actions is disabled in
4660 -- that context. Within the init proc of the enclosing type we
4661 -- must complete this analysis, if an actual subtype was created.
4663 elsif Inside_Init_Proc then
4665 Typ : constant Entity_Id := Etype (N);
4666 Decl : constant Node_Id := Declaration_Node (Typ);
4668 if Nkind (Decl) = N_Subtype_Declaration
4669 and then not Analyzed (Decl)
4670 and then Is_List_Member (Decl)
4671 and then No (Parent (Decl))
4674 Insert_Action (N, Decl);
4681 elsif Is_Entity_Name (P) then
4682 P_Name := Entity (P);
4684 -- The prefix may denote an enclosing type which is the completion
4685 -- of an incomplete type declaration.
4687 if Is_Type (P_Name) then
4688 Set_Entity (P, Get_Full_View (P_Name));
4689 Set_Etype (P, Entity (P));
4690 P_Name := Entity (P);
4693 P_Type := Base_Type (Etype (P));
4695 if Debug_Flag_E then
4696 Write_Str ("Found prefix type to be ");
4697 Write_Entity_Info (P_Type, " "); Write_Eol;
4700 -- First check for components of a record object (not the
4701 -- result of a call, which is handled below).
4703 if Is_Appropriate_For_Record (P_Type)
4704 and then not Is_Overloadable (P_Name)
4705 and then not Is_Type (P_Name)
4707 -- Selected component of record. Type checking will validate
4708 -- name of selector.
4710 Analyze_Selected_Component (N);
4712 elsif Is_Appropriate_For_Entry_Prefix (P_Type)
4713 and then not In_Open_Scopes (P_Name)
4714 and then (not Is_Concurrent_Type (Etype (P_Name))
4715 or else not In_Open_Scopes (Etype (P_Name)))
4717 -- Call to protected operation or entry. Type checking is
4718 -- needed on the prefix.
4720 Analyze_Selected_Component (N);
4722 elsif (In_Open_Scopes (P_Name)
4723 and then Ekind (P_Name) /= E_Void
4724 and then not Is_Overloadable (P_Name))
4725 or else (Is_Concurrent_Type (Etype (P_Name))
4726 and then In_Open_Scopes (Etype (P_Name)))
4728 -- Prefix denotes an enclosing loop, block, or task, i.e. an
4729 -- enclosing construct that is not a subprogram or accept.
4731 Find_Expanded_Name (N);
4733 elsif Ekind (P_Name) = E_Package then
4734 Find_Expanded_Name (N);
4736 elsif Is_Overloadable (P_Name) then
4738 -- The subprogram may be a renaming (of an enclosing scope) as
4739 -- in the case of the name of the generic within an instantiation.
4741 if (Ekind (P_Name) = E_Procedure
4742 or else Ekind (P_Name) = E_Function)
4743 and then Present (Alias (P_Name))
4744 and then Is_Generic_Instance (Alias (P_Name))
4746 P_Name := Alias (P_Name);
4749 if Is_Overloaded (P) then
4751 -- The prefix must resolve to a unique enclosing construct
4754 Found : Boolean := False;
4759 Get_First_Interp (P, Ind, It);
4760 while Present (It.Nam) loop
4761 if In_Open_Scopes (It.Nam) then
4764 "prefix must be unique enclosing scope", N);
4765 Set_Entity (N, Any_Id);
4766 Set_Etype (N, Any_Type);
4775 Get_Next_Interp (Ind, It);
4780 if In_Open_Scopes (P_Name) then
4781 Set_Entity (P, P_Name);
4782 Set_Is_Overloaded (P, False);
4783 Find_Expanded_Name (N);
4786 -- If no interpretation as an expanded name is possible, it
4787 -- must be a selected component of a record returned by a
4788 -- function call. Reformat prefix as a function call, the rest
4789 -- is done by type resolution. If the prefix is procedure or
4790 -- entry, as is P.X; this is an error.
4792 if Ekind (P_Name) /= E_Function
4793 and then (not Is_Overloaded (P)
4795 Nkind (Parent (N)) = N_Procedure_Call_Statement)
4797 -- Prefix may mention a package that is hidden by a local
4798 -- declaration: let the user know. Scan the full homonym
4799 -- chain, the candidate package may be anywhere on it.
4801 if Present (Homonym (Current_Entity (P_Name))) then
4803 P_Name := Current_Entity (P_Name);
4805 while Present (P_Name) loop
4806 exit when Ekind (P_Name) = E_Package;
4807 P_Name := Homonym (P_Name);
4810 if Present (P_Name) then
4811 Error_Msg_Sloc := Sloc (Entity (Prefix (N)));
4814 ("package& is hidden by declaration#",
4817 Set_Entity (Prefix (N), P_Name);
4818 Find_Expanded_Name (N);
4821 P_Name := Entity (Prefix (N));
4826 ("invalid prefix in selected component&", N, P_Name);
4827 Change_Selected_Component_To_Expanded_Name (N);
4828 Set_Entity (N, Any_Id);
4829 Set_Etype (N, Any_Type);
4832 Nam := New_Copy (P);
4833 Save_Interps (P, Nam);
4835 Make_Function_Call (Sloc (P), Name => Nam));
4837 Analyze_Selected_Component (N);
4841 -- Remaining cases generate various error messages
4844 -- Format node as expanded name, to avoid cascaded errors
4846 Change_Selected_Component_To_Expanded_Name (N);
4847 Set_Entity (N, Any_Id);
4848 Set_Etype (N, Any_Type);
4850 -- Issue error message, but avoid this if error issued already.
4851 -- Use identifier of prefix if one is available.
4853 if P_Name = Any_Id then
4856 elsif Ekind (P_Name) = E_Void then
4857 Premature_Usage (P);
4859 elsif Nkind (P) /= N_Attribute_Reference then
4861 "invalid prefix in selected component&", P);
4863 if Is_Access_Type (P_Type)
4864 and then Ekind (Designated_Type (P_Type)) = E_Incomplete_Type
4867 ("\dereference must not be of an incomplete type " &
4868 "('R'M 3.10.1)", P);
4873 "invalid prefix in selected component", P);
4878 -- If prefix is not the name of an entity, it must be an expression,
4879 -- whose type is appropriate for a record. This is determined by
4882 Analyze_Selected_Component (N);
4884 end Find_Selected_Component;
4890 procedure Find_Type (N : Node_Id) is
4900 elsif Nkind (N) = N_Attribute_Reference then
4902 -- Class attribute. This is only valid in Ada 95 mode, but we don't
4903 -- do a check, since the tagged type referenced could only exist if
4904 -- we were in 95 mode when it was declared (or, if we were in Ada
4905 -- 83 mode, then an error message would already have been issued).
4907 if Attribute_Name (N) = Name_Class then
4908 Check_Restriction (No_Dispatch, N);
4909 Find_Type (Prefix (N));
4911 -- Propagate error from bad prefix
4913 if Etype (Prefix (N)) = Any_Type then
4914 Set_Entity (N, Any_Type);
4915 Set_Etype (N, Any_Type);
4919 T := Base_Type (Entity (Prefix (N)));
4921 -- Case type is not known to be tagged. Its appearance in the
4922 -- prefix of the 'Class attribute indicates that the full view
4925 if not Is_Tagged_Type (T) then
4926 if Ekind (T) = E_Incomplete_Type then
4928 -- It is legal to denote the class type of an incomplete
4929 -- type. The full type will have to be tagged, of course.
4931 Set_Is_Tagged_Type (T);
4932 Set_Primitive_Operations (T, New_Elmt_List);
4933 Make_Class_Wide_Type (T);
4934 Set_Entity (N, Class_Wide_Type (T));
4935 Set_Etype (N, Class_Wide_Type (T));
4937 elsif Ekind (T) = E_Private_Type
4938 and then not Is_Generic_Type (T)
4939 and then In_Private_Part (Scope (T))
4941 -- The Class attribute can be applied to an untagged private
4942 -- type fulfilled by a tagged type prior to the full type
4943 -- declaration (but only within the parent package's private
4944 -- part). Create the class-wide type now and check that the
4945 -- full type is tagged later during its analysis. Note that
4946 -- we do not mark the private type as tagged, unlike the
4947 -- case of incomplete types, because the type must still
4948 -- appear untagged to outside units.
4950 if No (Class_Wide_Type (T)) then
4951 Make_Class_Wide_Type (T);
4954 Set_Entity (N, Class_Wide_Type (T));
4955 Set_Etype (N, Class_Wide_Type (T));
4958 -- Should we introduce a type Any_Tagged and use Wrong_Type
4959 -- here, it would be a bit more consistent???
4962 ("tagged type required, found}",
4963 Prefix (N), First_Subtype (T));
4964 Set_Entity (N, Any_Type);
4968 -- Case of tagged type
4971 if Is_Concurrent_Type (T) then
4972 if No (Corresponding_Record_Type (Entity (Prefix (N)))) then
4974 -- Previous error. Use current type, which at least
4975 -- provides some operations.
4977 C := Entity (Prefix (N));
4980 C := Class_Wide_Type
4981 (Corresponding_Record_Type (Entity (Prefix (N))));
4985 C := Class_Wide_Type (Entity (Prefix (N)));
4988 Set_Entity_With_Style_Check (N, C);
4989 Generate_Reference (C, N);
4993 -- Base attribute, not allowed in Ada 83
4995 elsif Attribute_Name (N) = Name_Base then
4996 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
4998 ("(Ada 83) Base attribute not allowed in subtype mark", N);
5001 Find_Type (Prefix (N));
5002 Typ := Entity (Prefix (N));
5004 if Ada_Version >= Ada_95
5005 and then not Is_Scalar_Type (Typ)
5006 and then not Is_Generic_Type (Typ)
5009 ("prefix of Base attribute must be scalar type",
5012 elsif Sloc (Typ) = Standard_Location
5013 and then Base_Type (Typ) = Typ
5014 and then Warn_On_Redundant_Constructs
5017 ("?redudant attribute, & is its own base type", N, Typ);
5020 T := Base_Type (Typ);
5022 -- Rewrite attribute reference with type itself (see similar
5023 -- processing in Analyze_Attribute, case Base). Preserve
5024 -- prefix if present, for other legality checks.
5026 if Nkind (Prefix (N)) = N_Expanded_Name then
5028 Make_Expanded_Name (Sloc (N),
5029 Chars => Chars (Entity (N)),
5030 Prefix => New_Copy (Prefix (Prefix (N))),
5032 New_Reference_To (Entity (N), Sloc (N))));
5036 New_Reference_To (Entity (N), Sloc (N)));
5043 elsif Attribute_Name (N) = Name_Stub_Type then
5045 -- This is handled in Analyze_Attribute
5049 -- All other attributes are invalid in a subtype mark
5052 Error_Msg_N ("invalid attribute in subtype mark", N);
5058 if Is_Entity_Name (N) then
5059 T_Name := Entity (N);
5061 Error_Msg_N ("subtype mark required in this context", N);
5062 Set_Etype (N, Any_Type);
5066 if T_Name = Any_Id or else Etype (N) = Any_Type then
5068 -- Undefined id. Make it into a valid type
5070 Set_Entity (N, Any_Type);
5072 elsif not Is_Type (T_Name)
5073 and then T_Name /= Standard_Void_Type
5075 Error_Msg_Sloc := Sloc (T_Name);
5076 Error_Msg_N ("subtype mark required in this context", N);
5077 Error_Msg_NE ("\\found & declared#", N, T_Name);
5078 Set_Entity (N, Any_Type);
5081 T_Name := Get_Full_View (T_Name);
5083 if In_Open_Scopes (T_Name) then
5084 if Ekind (Base_Type (T_Name)) = E_Task_Type then
5086 -- In Ada 2005, a task name can be used in an access
5087 -- definition within its own body.
5089 if Ada_Version >= Ada_05
5090 and then Nkind (Parent (N)) = N_Access_Definition
5092 Set_Entity (N, T_Name);
5093 Set_Etype (N, T_Name);
5098 ("task type cannot be used as type mark " &
5099 "within its own spec or body", N);
5102 elsif Ekind (Base_Type (T_Name)) = E_Protected_Type then
5104 -- In Ada 2005, a protected name can be used in an access
5105 -- definition within its own body.
5107 if Ada_Version >= Ada_05
5108 and then Nkind (Parent (N)) = N_Access_Definition
5110 Set_Entity (N, T_Name);
5111 Set_Etype (N, T_Name);
5116 ("protected type cannot be used as type mark " &
5117 "within its own spec or body", N);
5121 Error_Msg_N ("type declaration cannot refer to itself", N);
5124 Set_Etype (N, Any_Type);
5125 Set_Entity (N, Any_Type);
5126 Set_Error_Posted (T_Name);
5130 Set_Entity (N, T_Name);
5131 Set_Etype (N, T_Name);
5135 if Present (Etype (N)) and then Comes_From_Source (N) then
5136 if Is_Fixed_Point_Type (Etype (N)) then
5137 Check_Restriction (No_Fixed_Point, N);
5138 elsif Is_Floating_Point_Type (Etype (N)) then
5139 Check_Restriction (No_Floating_Point, N);
5148 function Get_Full_View (T_Name : Entity_Id) return Entity_Id is
5150 if Ekind (T_Name) = E_Incomplete_Type
5151 and then Present (Full_View (T_Name))
5153 return Full_View (T_Name);
5155 elsif Is_Class_Wide_Type (T_Name)
5156 and then Ekind (Root_Type (T_Name)) = E_Incomplete_Type
5157 and then Present (Full_View (Root_Type (T_Name)))
5159 return Class_Wide_Type (Full_View (Root_Type (T_Name)));
5166 ------------------------------------
5167 -- Has_Implicit_Character_Literal --
5168 ------------------------------------
5170 function Has_Implicit_Character_Literal (N : Node_Id) return Boolean is
5172 Found : Boolean := False;
5173 P : constant Entity_Id := Entity (Prefix (N));
5174 Priv_Id : Entity_Id := Empty;
5177 if Ekind (P) = E_Package
5178 and then not In_Open_Scopes (P)
5180 Priv_Id := First_Private_Entity (P);
5183 if P = Standard_Standard then
5184 Change_Selected_Component_To_Expanded_Name (N);
5185 Rewrite (N, Selector_Name (N));
5187 Set_Etype (Original_Node (N), Standard_Character);
5191 Id := First_Entity (P);
5194 and then Id /= Priv_Id
5196 if Is_Character_Type (Id)
5197 and then (Root_Type (Id) = Standard_Character
5198 or else Root_Type (Id) = Standard_Wide_Character
5199 or else Root_Type (Id) = Standard_Wide_Wide_Character)
5200 and then Id = Base_Type (Id)
5202 -- We replace the node with the literal itself, resolve as a
5203 -- character, and set the type correctly.
5206 Change_Selected_Component_To_Expanded_Name (N);
5207 Rewrite (N, Selector_Name (N));
5210 Set_Etype (Original_Node (N), Id);
5214 -- More than one type derived from Character in given scope.
5215 -- Collect all possible interpretations.
5217 Add_One_Interp (N, Id, Id);
5225 end Has_Implicit_Character_Literal;
5227 ----------------------
5228 -- Has_Private_With --
5229 ----------------------
5231 function Has_Private_With (E : Entity_Id) return Boolean is
5232 Comp_Unit : constant Node_Id := Cunit (Current_Sem_Unit);
5236 Item := First (Context_Items (Comp_Unit));
5237 while Present (Item) loop
5238 if Nkind (Item) = N_With_Clause
5239 and then Private_Present (Item)
5240 and then Entity (Name (Item)) = E
5249 end Has_Private_With;
5251 ---------------------------
5252 -- Has_Implicit_Operator --
5253 ---------------------------
5255 function Has_Implicit_Operator (N : Node_Id) return Boolean is
5256 Op_Id : constant Name_Id := Chars (Selector_Name (N));
5257 P : constant Entity_Id := Entity (Prefix (N));
5259 Priv_Id : Entity_Id := Empty;
5261 procedure Add_Implicit_Operator
5263 Op_Type : Entity_Id := Empty);
5264 -- Add implicit interpretation to node N, using the type for which a
5265 -- predefined operator exists. If the operator yields a boolean type,
5266 -- the Operand_Type is implicitly referenced by the operator, and a
5267 -- reference to it must be generated.
5269 ---------------------------
5270 -- Add_Implicit_Operator --
5271 ---------------------------
5273 procedure Add_Implicit_Operator
5275 Op_Type : Entity_Id := Empty)
5277 Predef_Op : Entity_Id;
5280 Predef_Op := Current_Entity (Selector_Name (N));
5282 while Present (Predef_Op)
5283 and then Scope (Predef_Op) /= Standard_Standard
5285 Predef_Op := Homonym (Predef_Op);
5288 if Nkind (N) = N_Selected_Component then
5289 Change_Selected_Component_To_Expanded_Name (N);
5292 Add_One_Interp (N, Predef_Op, T);
5294 -- For operators with unary and binary interpretations, add both
5296 if Present (Homonym (Predef_Op)) then
5297 Add_One_Interp (N, Homonym (Predef_Op), T);
5300 -- The node is a reference to a predefined operator, and
5301 -- an implicit reference to the type of its operands.
5303 if Present (Op_Type) then
5304 Generate_Operator_Reference (N, Op_Type);
5306 Generate_Operator_Reference (N, T);
5308 end Add_Implicit_Operator;
5310 -- Start of processing for Has_Implicit_Operator
5313 if Ekind (P) = E_Package
5314 and then not In_Open_Scopes (P)
5316 Priv_Id := First_Private_Entity (P);
5319 Id := First_Entity (P);
5323 -- Boolean operators: an implicit declaration exists if the scope
5324 -- contains a declaration for a derived Boolean type, or for an
5325 -- array of Boolean type.
5327 when Name_Op_And | Name_Op_Not | Name_Op_Or | Name_Op_Xor =>
5328 while Id /= Priv_Id loop
5329 if Valid_Boolean_Arg (Id)
5330 and then Id = Base_Type (Id)
5332 Add_Implicit_Operator (Id);
5339 -- Equality: look for any non-limited type (result is Boolean)
5341 when Name_Op_Eq | Name_Op_Ne =>
5342 while Id /= Priv_Id loop
5344 and then not Is_Limited_Type (Id)
5345 and then Id = Base_Type (Id)
5347 Add_Implicit_Operator (Standard_Boolean, Id);
5354 -- Comparison operators: scalar type, or array of scalar
5356 when Name_Op_Lt | Name_Op_Le | Name_Op_Gt | Name_Op_Ge =>
5357 while Id /= Priv_Id loop
5358 if (Is_Scalar_Type (Id)
5359 or else (Is_Array_Type (Id)
5360 and then Is_Scalar_Type (Component_Type (Id))))
5361 and then Id = Base_Type (Id)
5363 Add_Implicit_Operator (Standard_Boolean, Id);
5370 -- Arithmetic operators: any numeric type
5380 while Id /= Priv_Id loop
5381 if Is_Numeric_Type (Id)
5382 and then Id = Base_Type (Id)
5384 Add_Implicit_Operator (Id);
5391 -- Concatenation: any one-dimensional array type
5393 when Name_Op_Concat =>
5394 while Id /= Priv_Id loop
5395 if Is_Array_Type (Id) and then Number_Dimensions (Id) = 1
5396 and then Id = Base_Type (Id)
5398 Add_Implicit_Operator (Id);
5405 -- What is the others condition here? Should we be using a
5406 -- subtype of Name_Id that would restrict to operators ???
5408 when others => null;
5411 -- If we fall through, then we do not have an implicit operator
5415 end Has_Implicit_Operator;
5417 --------------------
5418 -- In_Open_Scopes --
5419 --------------------
5421 function In_Open_Scopes (S : Entity_Id) return Boolean is
5423 -- Several scope stacks are maintained by Scope_Stack. The base of the
5424 -- currently active scope stack is denoted by the Is_Active_Stack_Base
5425 -- flag in the scope stack entry. Note that the scope stacks used to
5426 -- simply be delimited implicitly by the presence of Standard_Standard
5427 -- at their base, but there now are cases where this is not sufficient
5428 -- because Standard_Standard actually may appear in the middle of the
5429 -- active set of scopes.
5431 for J in reverse 0 .. Scope_Stack.Last loop
5432 if Scope_Stack.Table (J).Entity = S then
5436 -- Check Is_Active_Stack_Base to tell us when to stop, as there are
5437 -- cases where Standard_Standard appears in the middle of the active
5438 -- set of scopes. This affects the declaration and overriding of
5439 -- private inherited operations in instantiations of generic child
5442 exit when Scope_Stack.Table (J).Is_Active_Stack_Base;
5448 -----------------------------
5449 -- Inherit_Renamed_Profile --
5450 -----------------------------
5452 procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id) is
5459 if Ekind (Old_S) = E_Operator then
5460 New_F := First_Formal (New_S);
5462 while Present (New_F) loop
5463 Set_Etype (New_F, Base_Type (Etype (New_F)));
5464 Next_Formal (New_F);
5467 Set_Etype (New_S, Base_Type (Etype (New_S)));
5470 New_F := First_Formal (New_S);
5471 Old_F := First_Formal (Old_S);
5473 while Present (New_F) loop
5474 New_T := Etype (New_F);
5475 Old_T := Etype (Old_F);
5477 -- If the new type is a renaming of the old one, as is the
5478 -- case for actuals in instances, retain its name, to simplify
5479 -- later disambiguation.
5481 if Nkind (Parent (New_T)) = N_Subtype_Declaration
5482 and then Is_Entity_Name (Subtype_Indication (Parent (New_T)))
5483 and then Entity (Subtype_Indication (Parent (New_T))) = Old_T
5487 Set_Etype (New_F, Old_T);
5490 Next_Formal (New_F);
5491 Next_Formal (Old_F);
5494 if Ekind (Old_S) = E_Function
5495 or else Ekind (Old_S) = E_Enumeration_Literal
5497 Set_Etype (New_S, Etype (Old_S));
5500 end Inherit_Renamed_Profile;
5506 procedure Initialize is
5511 -------------------------
5512 -- Install_Use_Clauses --
5513 -------------------------
5515 procedure Install_Use_Clauses
5517 Force_Installation : Boolean := False)
5525 while Present (U) loop
5527 -- Case of USE package
5529 if Nkind (U) = N_Use_Package_Clause then
5530 P := First (Names (U));
5531 while Present (P) loop
5534 if Ekind (Id) = E_Package then
5536 Note_Redundant_Use (P);
5538 elsif Present (Renamed_Object (Id))
5539 and then In_Use (Renamed_Object (Id))
5541 Note_Redundant_Use (P);
5543 elsif Force_Installation or else Applicable_Use (P) then
5544 Use_One_Package (Id, U);
5555 P := First (Subtype_Marks (U));
5556 while Present (P) loop
5557 if not Is_Entity_Name (P)
5558 or else No (Entity (P))
5562 elsif Entity (P) /= Any_Type then
5570 Next_Use_Clause (U);
5572 end Install_Use_Clauses;
5574 -------------------------------------
5575 -- Is_Appropriate_For_Entry_Prefix --
5576 -------------------------------------
5578 function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean is
5579 P_Type : Entity_Id := T;
5582 if Is_Access_Type (P_Type) then
5583 P_Type := Designated_Type (P_Type);
5586 return Is_Task_Type (P_Type) or else Is_Protected_Type (P_Type);
5587 end Is_Appropriate_For_Entry_Prefix;
5589 -------------------------------
5590 -- Is_Appropriate_For_Record --
5591 -------------------------------
5593 function Is_Appropriate_For_Record (T : Entity_Id) return Boolean is
5595 function Has_Components (T1 : Entity_Id) return Boolean;
5596 -- Determine if given type has components (i.e. is either a record
5597 -- type or a type that has discriminants).
5599 --------------------
5600 -- Has_Components --
5601 --------------------
5603 function Has_Components (T1 : Entity_Id) return Boolean is
5605 return Is_Record_Type (T1)
5606 or else (Is_Private_Type (T1) and then Has_Discriminants (T1))
5607 or else (Is_Task_Type (T1) and then Has_Discriminants (T1))
5608 or else (Is_Incomplete_Type (T1)
5609 and then From_With_Type (T1)
5610 and then Present (Non_Limited_View (T1))
5611 and then Is_Record_Type (Non_Limited_View (T1)));
5614 -- Start of processing for Is_Appropriate_For_Record
5619 and then (Has_Components (T)
5620 or else (Is_Access_Type (T)
5621 and then Has_Components (Designated_Type (T))));
5622 end Is_Appropriate_For_Record;
5624 ------------------------
5625 -- Note_Redundant_Use --
5626 ------------------------
5628 procedure Note_Redundant_Use (Clause : Node_Id) is
5629 Pack_Name : constant Entity_Id := Entity (Clause);
5630 Cur_Use : constant Node_Id := Current_Use_Clause (Pack_Name);
5631 Decl : constant Node_Id := Parent (Clause);
5633 Prev_Use : Node_Id := Empty;
5634 Redundant : Node_Id := Empty;
5635 -- The Use_Clause which is actually redundant. In the simplest case
5636 -- it is Pack itself, but when we compile a body we install its
5637 -- context before that of its spec, in which case it is the use_clause
5638 -- in the spec that will appear to be redundant, and we want the
5639 -- warning to be placed on the body. Similar complications appear when
5640 -- the redundancy is between a child unit and one of its ancestors.
5643 Set_Redundant_Use (Clause, True);
5645 if not Comes_From_Source (Clause)
5647 or else not Warn_On_Redundant_Constructs
5652 if not Is_Compilation_Unit (Current_Scope) then
5654 -- If the use_clause is in an inner scope, it is made redundant
5655 -- by some clause in the current context, with one exception:
5656 -- If we're compiling a nested package body, and the use_clause
5657 -- comes from the corresponding spec, the clause is not necessarily
5658 -- fully redundant, so we should not warn. If a warning was
5659 -- warranted, it would have been given when the spec was processed.
5661 if Nkind (Parent (Decl)) = N_Package_Specification then
5663 Package_Spec_Entity : constant Entity_Id :=
5664 Defining_Unit_Name (Parent (Decl));
5666 if In_Package_Body (Package_Spec_Entity) then
5672 Redundant := Clause;
5673 Prev_Use := Cur_Use;
5675 elsif Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body then
5677 Cur_Unit : constant Unit_Number_Type := Get_Source_Unit (Cur_Use);
5678 New_Unit : constant Unit_Number_Type := Get_Source_Unit (Clause);
5682 if Cur_Unit = New_Unit then
5684 -- Redundant clause in same body
5686 Redundant := Clause;
5687 Prev_Use := Cur_Use;
5689 elsif Cur_Unit = Current_Sem_Unit then
5691 -- If the new clause is not in the current unit it has been
5692 -- analyzed first, and it makes the other one redundant.
5693 -- However, if the new clause appears in a subunit, Cur_Unit
5694 -- is still the parent, and in that case the redundant one
5695 -- is the one appearing in the subunit.
5697 if Nkind (Unit (Cunit (New_Unit))) = N_Subunit then
5698 Redundant := Clause;
5699 Prev_Use := Cur_Use;
5701 -- Most common case: redundant clause in body,
5702 -- original clause in spec. Current scope is spec entity.
5707 Unit (Library_Unit (Cunit (Current_Sem_Unit))))
5709 Redundant := Cur_Use;
5713 -- The new clause may appear in an unrelated unit, when
5714 -- the parents of a generic are being installed prior to
5715 -- instantiation. In this case there must be no warning.
5716 -- We detect this case by checking whether the current top
5717 -- of the stack is related to the current compilation.
5719 Scop := Current_Scope;
5720 while Present (Scop)
5721 and then Scop /= Standard_Standard
5723 if Is_Compilation_Unit (Scop)
5724 and then not Is_Child_Unit (Scop)
5728 elsif Scop = Cunit_Entity (Current_Sem_Unit) then
5732 Scop := Scope (Scop);
5735 Redundant := Cur_Use;
5739 elsif New_Unit = Current_Sem_Unit then
5740 Redundant := Clause;
5741 Prev_Use := Cur_Use;
5744 -- Neither is the current unit, so they appear in parent or
5745 -- sibling units. Warning will be emitted elsewhere.
5751 elsif Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
5752 and then Present (Parent_Spec (Unit (Cunit (Current_Sem_Unit))))
5754 -- Use_clause is in child unit of current unit, and the child
5755 -- unit appears in the context of the body of the parent, so it
5756 -- has been installed first, even though it is the redundant one.
5757 -- Depending on their placement in the context, the visible or the
5758 -- private parts of the two units, either might appear as redundant,
5759 -- but the message has to be on the current unit.
5761 if Get_Source_Unit (Cur_Use) = Current_Sem_Unit then
5762 Redundant := Cur_Use;
5765 Redundant := Clause;
5766 Prev_Use := Cur_Use;
5769 -- If the new use clause appears in the private part of a parent unit
5770 -- it may appear to be redudant w.r.t. a use clause in a child unit,
5771 -- but the previous use clause was needed in the visible part of the
5772 -- child, and no warning should be emitted.
5774 if Nkind (Parent (Decl)) = N_Package_Specification
5776 List_Containing (Decl) = Private_Declarations (Parent (Decl))
5779 Par : constant Entity_Id := Defining_Entity (Parent (Decl));
5780 Spec : constant Node_Id :=
5781 Specification (Unit (Cunit (Current_Sem_Unit)));
5784 if Is_Compilation_Unit (Par)
5785 and then Par /= Cunit_Entity (Current_Sem_Unit)
5786 and then Parent (Cur_Use) = Spec
5788 List_Containing (Cur_Use) = Visible_Declarations (Spec)
5799 if Present (Redundant) then
5800 Error_Msg_Sloc := Sloc (Prev_Use);
5802 "& is already use_visible through declaration #?",
5803 Redundant, Pack_Name);
5805 end Note_Redundant_Use;
5811 procedure Pop_Scope is
5812 SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
5815 if Debug_Flag_E then
5819 Scope_Suppress := SST.Save_Scope_Suppress;
5820 Local_Entity_Suppress.Set_Last (SST.Save_Local_Entity_Suppress);
5822 if Debug_Flag_W then
5823 Write_Str ("--> exiting scope: ");
5824 Write_Name (Chars (Current_Scope));
5825 Write_Str (", Depth=");
5826 Write_Int (Int (Scope_Stack.Last));
5830 End_Use_Clauses (SST.First_Use_Clause);
5832 -- If the actions to be wrapped are still there they will get lost
5833 -- causing incomplete code to be generated. It is better to abort in
5834 -- this case (and we do the abort even with assertions off since the
5835 -- penalty is incorrect code generation)
5837 if SST.Actions_To_Be_Wrapped_Before /= No_List
5839 SST.Actions_To_Be_Wrapped_After /= No_List
5844 -- Free last subprogram name if allocated, and pop scope
5846 Free (SST.Last_Subprogram_Name);
5847 Scope_Stack.Decrement_Last;
5854 procedure Push_Scope (S : Entity_Id) is
5858 if Ekind (S) = E_Void then
5861 -- Set scope depth if not a non-concurrent type, and we have not
5862 -- yet set the scope depth. This means that we have the first
5863 -- occurrence of the scope, and this is where the depth is set.
5865 elsif (not Is_Type (S) or else Is_Concurrent_Type (S))
5866 and then not Scope_Depth_Set (S)
5868 if S = Standard_Standard then
5869 Set_Scope_Depth_Value (S, Uint_0);
5871 elsif Is_Child_Unit (S) then
5872 Set_Scope_Depth_Value (S, Uint_1);
5874 elsif not Is_Record_Type (Current_Scope) then
5875 if Ekind (S) = E_Loop then
5876 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope));
5878 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope) + 1);
5883 Scope_Stack.Increment_Last;
5886 SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
5890 SST.Save_Scope_Suppress := Scope_Suppress;
5891 SST.Save_Local_Entity_Suppress := Local_Entity_Suppress.Last;
5893 if Scope_Stack.Last > Scope_Stack.First then
5894 SST.Component_Alignment_Default := Scope_Stack.Table
5895 (Scope_Stack.Last - 1).
5896 Component_Alignment_Default;
5899 SST.Last_Subprogram_Name := null;
5900 SST.Is_Transient := False;
5901 SST.Node_To_Be_Wrapped := Empty;
5902 SST.Pending_Freeze_Actions := No_List;
5903 SST.Actions_To_Be_Wrapped_Before := No_List;
5904 SST.Actions_To_Be_Wrapped_After := No_List;
5905 SST.First_Use_Clause := Empty;
5906 SST.Is_Active_Stack_Base := False;
5907 SST.Previous_Visibility := False;
5910 if Debug_Flag_W then
5911 Write_Str ("--> new scope: ");
5912 Write_Name (Chars (Current_Scope));
5913 Write_Str (", Id=");
5914 Write_Int (Int (Current_Scope));
5915 Write_Str (", Depth=");
5916 Write_Int (Int (Scope_Stack.Last));
5920 -- Deal with copying flags from the previous scope to this one. This
5921 -- is not necessary if either scope is standard, or if the new scope
5924 if S /= Standard_Standard
5925 and then Scope (S) /= Standard_Standard
5926 and then not Is_Child_Unit (S)
5930 if Nkind (E) not in N_Entity then
5934 -- Copy categorization flags from Scope (S) to S, this is not done
5935 -- when Scope (S) is Standard_Standard since propagation is from
5936 -- library unit entity inwards. Copy other relevant attributes as
5937 -- well (Discard_Names in particular).
5939 -- We only propagate inwards for library level entities,
5940 -- inner level subprograms do not inherit the categorization.
5942 if Is_Library_Level_Entity (S) then
5943 Set_Is_Preelaborated (S, Is_Preelaborated (E));
5944 Set_Is_Shared_Passive (S, Is_Shared_Passive (E));
5945 Set_Discard_Names (S, Discard_Names (E));
5946 Set_Suppress_Value_Tracking_On_Call
5947 (S, Suppress_Value_Tracking_On_Call (E));
5948 Set_Categorization_From_Scope (E => S, Scop => E);
5953 ---------------------
5954 -- Premature_Usage --
5955 ---------------------
5957 procedure Premature_Usage (N : Node_Id) is
5958 Kind : constant Node_Kind := Nkind (Parent (Entity (N)));
5959 E : Entity_Id := Entity (N);
5962 -- Within an instance, the analysis of the actual for a formal object
5963 -- does not see the name of the object itself. This is significant only
5964 -- if the object is an aggregate, where its analysis does not do any
5965 -- name resolution on component associations. (see 4717-008). In such a
5966 -- case, look for the visible homonym on the chain.
5969 and then Present (Homonym (E))
5974 and then not In_Open_Scopes (Scope (E))
5981 Set_Etype (N, Etype (E));
5986 if Kind = N_Component_Declaration then
5988 ("component&! cannot be used before end of record declaration", N);
5990 elsif Kind = N_Parameter_Specification then
5992 ("formal parameter&! cannot be used before end of specification",
5995 elsif Kind = N_Discriminant_Specification then
5997 ("discriminant&! cannot be used before end of discriminant part",
6000 elsif Kind = N_Procedure_Specification
6001 or else Kind = N_Function_Specification
6004 ("subprogram&! cannot be used before end of its declaration",
6008 ("object& cannot be used before end of its declaration!", N);
6010 end Premature_Usage;
6012 ------------------------
6013 -- Present_System_Aux --
6014 ------------------------
6016 function Present_System_Aux (N : Node_Id := Empty) return Boolean is
6018 Aux_Name : Unit_Name_Type;
6019 Unum : Unit_Number_Type;
6024 function Find_System (C_Unit : Node_Id) return Entity_Id;
6025 -- Scan context clause of compilation unit to find with_clause
6032 function Find_System (C_Unit : Node_Id) return Entity_Id is
6033 With_Clause : Node_Id;
6036 With_Clause := First (Context_Items (C_Unit));
6037 while Present (With_Clause) loop
6038 if (Nkind (With_Clause) = N_With_Clause
6039 and then Chars (Name (With_Clause)) = Name_System)
6040 and then Comes_From_Source (With_Clause)
6051 -- Start of processing for Present_System_Aux
6054 -- The child unit may have been loaded and analyzed already
6056 if Present (System_Aux_Id) then
6059 -- If no previous pragma for System.Aux, nothing to load
6061 elsif No (System_Extend_Unit) then
6064 -- Use the unit name given in the pragma to retrieve the unit.
6065 -- Verify that System itself appears in the context clause of the
6066 -- current compilation. If System is not present, an error will
6067 -- have been reported already.
6070 With_Sys := Find_System (Cunit (Current_Sem_Unit));
6072 The_Unit := Unit (Cunit (Current_Sem_Unit));
6075 and then (Nkind (The_Unit) = N_Package_Body
6076 or else (Nkind (The_Unit) = N_Subprogram_Body
6077 and then not Acts_As_Spec (Cunit (Current_Sem_Unit))))
6079 With_Sys := Find_System (Library_Unit (Cunit (Current_Sem_Unit)));
6083 and then Present (N)
6085 -- If we are compiling a subunit, we need to examine its
6086 -- context as well (Current_Sem_Unit is the parent unit);
6088 The_Unit := Parent (N);
6090 while Nkind (The_Unit) /= N_Compilation_Unit loop
6091 The_Unit := Parent (The_Unit);
6094 if Nkind (Unit (The_Unit)) = N_Subunit then
6095 With_Sys := Find_System (The_Unit);
6099 if No (With_Sys) then
6103 Loc := Sloc (With_Sys);
6104 Get_Name_String (Chars (Expression (System_Extend_Unit)));
6105 Name_Buffer (8 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
6106 Name_Buffer (1 .. 7) := "system.";
6107 Name_Buffer (Name_Len + 8) := '%';
6108 Name_Buffer (Name_Len + 9) := 's';
6109 Name_Len := Name_Len + 9;
6110 Aux_Name := Name_Find;
6114 (Load_Name => Aux_Name,
6117 Error_Node => With_Sys);
6119 if Unum /= No_Unit then
6120 Semantics (Cunit (Unum));
6122 Defining_Entity (Specification (Unit (Cunit (Unum))));
6125 Make_With_Clause (Loc,
6127 Make_Expanded_Name (Loc,
6128 Chars => Chars (System_Aux_Id),
6129 Prefix => New_Reference_To (Scope (System_Aux_Id), Loc),
6130 Selector_Name => New_Reference_To (System_Aux_Id, Loc)));
6132 Set_Entity (Name (Withn), System_Aux_Id);
6134 Set_Library_Unit (Withn, Cunit (Unum));
6135 Set_Corresponding_Spec (Withn, System_Aux_Id);
6136 Set_First_Name (Withn, True);
6137 Set_Implicit_With (Withn, True);
6139 Insert_After (With_Sys, Withn);
6140 Mark_Rewrite_Insertion (Withn);
6141 Set_Context_Installed (Withn);
6145 -- Here if unit load failed
6148 Error_Msg_Name_1 := Name_System;
6149 Error_Msg_Name_2 := Chars (Expression (System_Extend_Unit));
6151 ("extension package `%.%` does not exist",
6152 Opt.System_Extend_Unit);
6156 end Present_System_Aux;
6158 -------------------------
6159 -- Restore_Scope_Stack --
6160 -------------------------
6162 procedure Restore_Scope_Stack (Handle_Use : Boolean := True) is
6165 Comp_Unit : Node_Id;
6166 In_Child : Boolean := False;
6167 Full_Vis : Boolean := True;
6168 SS_Last : constant Int := Scope_Stack.Last;
6171 -- Restore visibility of previous scope stack, if any
6173 for J in reverse 0 .. Scope_Stack.Last loop
6174 exit when Scope_Stack.Table (J).Entity = Standard_Standard
6175 or else No (Scope_Stack.Table (J).Entity);
6177 S := Scope_Stack.Table (J).Entity;
6179 if not Is_Hidden_Open_Scope (S) then
6181 -- If the parent scope is hidden, its entities are hidden as
6182 -- well, unless the entity is the instantiation currently
6185 if not Is_Hidden_Open_Scope (Scope (S))
6186 or else not Analyzed (Parent (S))
6187 or else Scope (S) = Standard_Standard
6189 Set_Is_Immediately_Visible (S, True);
6192 E := First_Entity (S);
6193 while Present (E) loop
6194 if Is_Child_Unit (E) then
6195 Set_Is_Immediately_Visible (E,
6196 Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
6198 Set_Is_Immediately_Visible (E, True);
6203 if not Full_Vis then
6204 exit when E = First_Private_Entity (S);
6208 -- The visibility of child units (siblings of current compilation)
6209 -- must be restored in any case. Their declarations may appear
6210 -- after the private part of the parent.
6212 if not Full_Vis then
6213 while Present (E) loop
6214 if Is_Child_Unit (E) then
6215 Set_Is_Immediately_Visible (E,
6216 Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
6224 if Is_Child_Unit (S)
6225 and not In_Child -- check only for current unit
6229 -- Restore visibility of parents according to whether the child
6230 -- is private and whether we are in its visible part.
6232 Comp_Unit := Parent (Unit_Declaration_Node (S));
6234 if Nkind (Comp_Unit) = N_Compilation_Unit
6235 and then Private_Present (Comp_Unit)
6239 elsif (Ekind (S) = E_Package
6240 or else Ekind (S) = E_Generic_Package)
6241 and then (In_Private_Part (S)
6242 or else In_Package_Body (S))
6246 elsif (Ekind (S) = E_Procedure
6247 or else Ekind (S) = E_Function)
6248 and then Has_Completion (S)
6259 if SS_Last >= Scope_Stack.First
6260 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
6263 Install_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
6265 end Restore_Scope_Stack;
6267 ----------------------
6268 -- Save_Scope_Stack --
6269 ----------------------
6271 procedure Save_Scope_Stack (Handle_Use : Boolean := True) is
6274 SS_Last : constant Int := Scope_Stack.Last;
6277 if SS_Last >= Scope_Stack.First
6278 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
6281 End_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
6284 -- If the call is from within a compilation unit, as when called from
6285 -- Rtsfind, make current entries in scope stack invisible while we
6286 -- analyze the new unit.
6288 for J in reverse 0 .. SS_Last loop
6289 exit when Scope_Stack.Table (J).Entity = Standard_Standard
6290 or else No (Scope_Stack.Table (J).Entity);
6292 S := Scope_Stack.Table (J).Entity;
6293 Set_Is_Immediately_Visible (S, False);
6295 E := First_Entity (S);
6296 while Present (E) loop
6297 Set_Is_Immediately_Visible (E, False);
6303 end Save_Scope_Stack;
6309 procedure Set_Use (L : List_Id) is
6311 Pack_Name : Node_Id;
6318 while Present (Decl) loop
6319 if Nkind (Decl) = N_Use_Package_Clause then
6320 Chain_Use_Clause (Decl);
6322 Pack_Name := First (Names (Decl));
6323 while Present (Pack_Name) loop
6324 Pack := Entity (Pack_Name);
6326 if Ekind (Pack) = E_Package
6327 and then Applicable_Use (Pack_Name)
6329 Use_One_Package (Pack, Decl);
6335 elsif Nkind (Decl) = N_Use_Type_Clause then
6336 Chain_Use_Clause (Decl);
6338 Id := First (Subtype_Marks (Decl));
6339 while Present (Id) loop
6340 if Entity (Id) /= Any_Type then
6353 ---------------------
6354 -- Use_One_Package --
6355 ---------------------
6357 procedure Use_One_Package (P : Entity_Id; N : Node_Id) is
6360 Current_Instance : Entity_Id := Empty;
6362 Private_With_OK : Boolean := False;
6365 if Ekind (P) /= E_Package then
6370 Set_Current_Use_Clause (P, N);
6372 -- Ada 2005 (AI-50217): Check restriction
6374 if From_With_Type (P) then
6375 Error_Msg_N ("limited withed package cannot appear in use clause", N);
6378 -- Find enclosing instance, if any
6381 Current_Instance := Current_Scope;
6382 while not Is_Generic_Instance (Current_Instance) loop
6383 Current_Instance := Scope (Current_Instance);
6386 if No (Hidden_By_Use_Clause (N)) then
6387 Set_Hidden_By_Use_Clause (N, New_Elmt_List);
6391 -- If unit is a package renaming, indicate that the renamed
6392 -- package is also in use (the flags on both entities must
6393 -- remain consistent, and a subsequent use of either of them
6394 -- should be recognized as redundant).
6396 if Present (Renamed_Object (P)) then
6397 Set_In_Use (Renamed_Object (P));
6398 Set_Current_Use_Clause (Renamed_Object (P), N);
6399 Real_P := Renamed_Object (P);
6404 -- Ada 2005 (AI-262): Check the use_clause of a private withed package
6405 -- found in the private part of a package specification
6407 if In_Private_Part (Current_Scope)
6408 and then Has_Private_With (P)
6409 and then Is_Child_Unit (Current_Scope)
6410 and then Is_Child_Unit (P)
6411 and then Is_Ancestor_Package (Scope (Current_Scope), P)
6413 Private_With_OK := True;
6416 -- Loop through entities in one package making them potentially
6419 Id := First_Entity (P);
6421 and then (Id /= First_Private_Entity (P)
6422 or else Private_With_OK) -- Ada 2005 (AI-262)
6424 Prev := Current_Entity (Id);
6425 while Present (Prev) loop
6426 if Is_Immediately_Visible (Prev)
6427 and then (not Is_Overloadable (Prev)
6428 or else not Is_Overloadable (Id)
6429 or else (Type_Conformant (Id, Prev)))
6431 if No (Current_Instance) then
6433 -- Potentially use-visible entity remains hidden
6435 goto Next_Usable_Entity;
6437 -- A use clause within an instance hides outer global entities,
6438 -- which are not used to resolve local entities in the
6439 -- instance. Note that the predefined entities in Standard
6440 -- could not have been hidden in the generic by a use clause,
6441 -- and therefore remain visible. Other compilation units whose
6442 -- entities appear in Standard must be hidden in an instance.
6444 -- To determine whether an entity is external to the instance
6445 -- we compare the scope depth of its scope with that of the
6446 -- current instance. However, a generic actual of a subprogram
6447 -- instance is declared in the wrapper package but will not be
6448 -- hidden by a use-visible entity.
6450 -- If Id is called Standard, the predefined package with the
6451 -- same name is in the homonym chain. It has to be ignored
6452 -- because it has no defined scope (being the only entity in
6453 -- the system with this mandated behavior).
6455 elsif not Is_Hidden (Id)
6456 and then Present (Scope (Prev))
6457 and then not Is_Wrapper_Package (Scope (Prev))
6458 and then Scope_Depth (Scope (Prev)) <
6459 Scope_Depth (Current_Instance)
6460 and then (Scope (Prev) /= Standard_Standard
6461 or else Sloc (Prev) > Standard_Location)
6463 Set_Is_Potentially_Use_Visible (Id);
6464 Set_Is_Immediately_Visible (Prev, False);
6465 Append_Elmt (Prev, Hidden_By_Use_Clause (N));
6468 -- A user-defined operator is not use-visible if the predefined
6469 -- operator for the type is immediately visible, which is the case
6470 -- if the type of the operand is in an open scope. This does not
6471 -- apply to user-defined operators that have operands of different
6472 -- types, because the predefined mixed mode operations (multiply
6473 -- and divide) apply to universal types and do not hide anything.
6475 elsif Ekind (Prev) = E_Operator
6476 and then Operator_Matches_Spec (Prev, Id)
6477 and then In_Open_Scopes
6478 (Scope (Base_Type (Etype (First_Formal (Id)))))
6479 and then (No (Next_Formal (First_Formal (Id)))
6480 or else Etype (First_Formal (Id))
6481 = Etype (Next_Formal (First_Formal (Id)))
6482 or else Chars (Prev) = Name_Op_Expon)
6484 goto Next_Usable_Entity;
6487 Prev := Homonym (Prev);
6490 -- On exit, we know entity is not hidden, unless it is private
6492 if not Is_Hidden (Id)
6493 and then ((not Is_Child_Unit (Id))
6494 or else Is_Visible_Child_Unit (Id))
6496 Set_Is_Potentially_Use_Visible (Id);
6498 if Is_Private_Type (Id)
6499 and then Present (Full_View (Id))
6501 Set_Is_Potentially_Use_Visible (Full_View (Id));
6505 <<Next_Usable_Entity>>
6509 -- Child units are also made use-visible by a use clause, but they may
6510 -- appear after all visible declarations in the parent entity list.
6512 while Present (Id) loop
6513 if Is_Child_Unit (Id)
6514 and then Is_Visible_Child_Unit (Id)
6516 Set_Is_Potentially_Use_Visible (Id);
6522 if Chars (Real_P) = Name_System
6523 and then Scope (Real_P) = Standard_Standard
6524 and then Present_System_Aux (N)
6526 Use_One_Package (System_Aux_Id, N);
6529 end Use_One_Package;
6535 procedure Use_One_Type (Id : Node_Id) is
6541 -- It is the type determined by the subtype mark (8.4(8)) whose
6542 -- operations become potentially use-visible.
6544 T := Base_Type (Entity (Id));
6549 or else Is_Potentially_Use_Visible (T)
6550 or else In_Use (Scope (T)));
6552 if In_Open_Scopes (Scope (T)) then
6555 elsif From_With_Type (T) then
6557 ("incomplete type from limited view "
6558 & "cannot appear in use clause", Id);
6560 -- If the subtype mark designates a subtype in a different package,
6561 -- we have to check that the parent type is visible, otherwise the
6562 -- use type clause is a noop. Not clear how to do that???
6564 elsif not Redundant_Use (Id) then
6566 Op_List := Collect_Primitive_Operations (T);
6568 Elmt := First_Elmt (Op_List);
6569 while Present (Elmt) loop
6570 if (Nkind (Node (Elmt)) = N_Defining_Operator_Symbol
6571 or else Chars (Node (Elmt)) in Any_Operator_Name)
6572 and then not Is_Hidden (Node (Elmt))
6574 Set_Is_Potentially_Use_Visible (Node (Elmt));
6586 procedure Write_Info is
6587 Id : Entity_Id := First_Entity (Current_Scope);
6590 -- No point in dumping standard entities
6592 if Current_Scope = Standard_Standard then
6596 Write_Str ("========================================================");
6598 Write_Str (" Defined Entities in ");
6599 Write_Name (Chars (Current_Scope));
6601 Write_Str ("========================================================");
6605 Write_Str ("-- none --");
6609 while Present (Id) loop
6610 Write_Entity_Info (Id, " ");
6615 if Scope (Current_Scope) = Standard_Standard then
6617 -- Print information on the current unit itself
6619 Write_Entity_Info (Current_Scope, " ");
6629 procedure Write_Scopes is
6632 for J in reverse 1 .. Scope_Stack.Last loop
6633 S := Scope_Stack.Table (J).Entity;
6634 Write_Int (Int (S));
6635 Write_Str (" === ");
6636 Write_Name (Chars (S));