1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Debug; use Debug;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Exp_Tss; use Exp_Tss;
32 with Exp_Util; use Exp_Util;
33 with Fname; use Fname;
34 with Freeze; use Freeze;
35 with Impunit; use Impunit;
37 with Lib.Load; use Lib.Load;
38 with Lib.Xref; use Lib.Xref;
39 with Namet; use Namet;
40 with Namet.Sp; use Namet.Sp;
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_Aux; use Sem_Aux;
50 with Sem_Cat; use Sem_Cat;
51 with Sem_Ch3; use Sem_Ch3;
52 with Sem_Ch4; use Sem_Ch4;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch12; use Sem_Ch12;
55 with Sem_Disp; use Sem_Disp;
56 with Sem_Dist; use Sem_Dist;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Res; use Sem_Res;
59 with Sem_Util; use Sem_Util;
60 with Sem_Type; use Sem_Type;
61 with Stand; use Stand;
62 with Sinfo; use Sinfo;
63 with Sinfo.CN; use Sinfo.CN;
64 with Snames; use Snames;
65 with Style; use Style;
67 with Targparm; use Targparm;
68 with Tbuild; use Tbuild;
69 with Uintp; use Uintp;
71 package body Sem_Ch8 is
73 ------------------------------------
74 -- Visibility and Name Resolution --
75 ------------------------------------
77 -- This package handles name resolution and the collection of
78 -- interpretations for overloaded names, prior to overload resolution.
80 -- Name resolution is the process that establishes a mapping between source
81 -- identifiers and the entities they denote at each point in the program.
82 -- Each entity is represented by a defining occurrence. Each identifier
83 -- that denotes an entity points to the corresponding defining occurrence.
84 -- This is the entity of the applied occurrence. Each occurrence holds
85 -- an index into the names table, where source identifiers are stored.
87 -- Each entry in the names table for an identifier or designator uses the
88 -- Info pointer to hold a link to the currently visible entity that has
89 -- this name (see subprograms Get_Name_Entity_Id and Set_Name_Entity_Id
90 -- in package Sem_Util). The visibility is initialized at the beginning of
91 -- semantic processing to make entities in package Standard immediately
92 -- visible. The visibility table is used in a more subtle way when
93 -- compiling subunits (see below).
95 -- Entities that have the same name (i.e. homonyms) are chained. In the
96 -- case of overloaded entities, this chain holds all the possible meanings
97 -- of a given identifier. The process of overload resolution uses type
98 -- information to select from this chain the unique meaning of a given
101 -- Entities are also chained in their scope, through the Next_Entity link.
102 -- As a consequence, the name space is organized as a sparse matrix, where
103 -- each row corresponds to a scope, and each column to a source identifier.
104 -- Open scopes, that is to say scopes currently being compiled, have their
105 -- corresponding rows of entities in order, innermost scope first.
107 -- The scopes of packages that are mentioned in context clauses appear in
108 -- no particular order, interspersed among open scopes. This is because
109 -- in the course of analyzing the context of a compilation, a package
110 -- declaration is first an open scope, and subsequently an element of the
111 -- context. If subunits or child units are present, a parent unit may
112 -- appear under various guises at various times in the compilation.
114 -- When the compilation of the innermost scope is complete, the entities
115 -- defined therein are no longer visible. If the scope is not a package
116 -- declaration, these entities are never visible subsequently, and can be
117 -- removed from visibility chains. If the scope is a package declaration,
118 -- its visible declarations may still be accessible. Therefore the entities
119 -- defined in such a scope are left on the visibility chains, and only
120 -- their visibility (immediately visibility or potential use-visibility)
123 -- The ordering of homonyms on their chain does not necessarily follow
124 -- the order of their corresponding scopes on the scope stack. For
125 -- example, if package P and the enclosing scope both contain entities
126 -- named E, then when compiling the package body the chain for E will
127 -- hold the global entity first, and the local one (corresponding to
128 -- the current inner scope) next. As a result, name resolution routines
129 -- do not assume any relative ordering of the homonym chains, either
130 -- for scope nesting or to order of appearance of context clauses.
132 -- When compiling a child unit, entities in the parent scope are always
133 -- immediately visible. When compiling the body of a child unit, private
134 -- entities in the parent must also be made immediately visible. There
135 -- are separate routines to make the visible and private declarations
136 -- visible at various times (see package Sem_Ch7).
138 -- +--------+ +-----+
139 -- | In use |-------->| EU1 |-------------------------->
140 -- +--------+ +-----+
142 -- +--------+ +-----+ +-----+
143 -- | Stand. |---------------->| ES1 |--------------->| ES2 |--->
144 -- +--------+ +-----+ +-----+
146 -- +---------+ | +-----+
147 -- | with'ed |------------------------------>| EW2 |--->
148 -- +---------+ | +-----+
150 -- +--------+ +-----+ +-----+
151 -- | Scope2 |---------------->| E12 |--------------->| E22 |--->
152 -- +--------+ +-----+ +-----+
154 -- +--------+ +-----+ +-----+
155 -- | Scope1 |---------------->| E11 |--------------->| E12 |--->
156 -- +--------+ +-----+ +-----+
160 -- | | with'ed |----------------------------------------->
164 -- (innermost first) | |
165 -- +----------------------------+
166 -- Names table => | Id1 | | | | Id2 |
167 -- +----------------------------+
169 -- Name resolution must deal with several syntactic forms: simple names,
170 -- qualified names, indexed names, and various forms of calls.
172 -- Each identifier points to an entry in the names table. The resolution
173 -- of a simple name consists in traversing the homonym chain, starting
174 -- from the names table. If an entry is immediately visible, it is the one
175 -- designated by the identifier. If only potentially use-visible entities
176 -- are on the chain, we must verify that they do not hide each other. If
177 -- the entity we find is overloadable, we collect all other overloadable
178 -- entities on the chain as long as they are not hidden.
180 -- To resolve expanded names, we must find the entity at the intersection
181 -- of the entity chain for the scope (the prefix) and the homonym chain
182 -- for the selector. In general, homonym chains will be much shorter than
183 -- entity chains, so it is preferable to start from the names table as
184 -- well. If the entity found is overloadable, we must collect all other
185 -- interpretations that are defined in the scope denoted by the prefix.
187 -- For records, protected types, and tasks, their local entities are
188 -- removed from visibility chains on exit from the corresponding scope.
189 -- From the outside, these entities are always accessed by selected
190 -- notation, and the entity chain for the record type, protected type,
191 -- etc. is traversed sequentially in order to find the designated entity.
193 -- The discriminants of a type and the operations of a protected type or
194 -- task are unchained on exit from the first view of the type, (such as
195 -- a private or incomplete type declaration, or a protected type speci-
196 -- fication) and re-chained when compiling the second view.
198 -- In the case of operators, we do not make operators on derived types
199 -- explicit. As a result, the notation P."+" may denote either a user-
200 -- defined function with name "+", or else an implicit declaration of the
201 -- operator "+" in package P. The resolution of expanded names always
202 -- tries to resolve an operator name as such an implicitly defined entity,
203 -- in addition to looking for explicit declarations.
205 -- All forms of names that denote entities (simple names, expanded names,
206 -- character literals in some cases) have a Entity attribute, which
207 -- identifies the entity denoted by the name.
209 ---------------------
210 -- The Scope Stack --
211 ---------------------
213 -- The Scope stack keeps track of the scopes currently been compiled.
214 -- Every entity that contains declarations (including records) is placed
215 -- on the scope stack while it is being processed, and removed at the end.
216 -- Whenever a non-package scope is exited, the entities defined therein
217 -- are removed from the visibility table, so that entities in outer scopes
218 -- become visible (see previous description). On entry to Sem, the scope
219 -- stack only contains the package Standard. As usual, subunits complicate
220 -- this picture ever so slightly.
222 -- The Rtsfind mechanism can force a call to Semantics while another
223 -- compilation is in progress. The unit retrieved by Rtsfind must be
224 -- compiled in its own context, and has no access to the visibility of
225 -- the unit currently being compiled. The procedures Save_Scope_Stack and
226 -- Restore_Scope_Stack make entities in current open scopes invisible
227 -- before compiling the retrieved unit, and restore the compilation
228 -- environment afterwards.
230 ------------------------
231 -- Compiling subunits --
232 ------------------------
234 -- Subunits must be compiled in the environment of the corresponding stub,
235 -- that is to say with the same visibility into the parent (and its
236 -- context) that is available at the point of the stub declaration, but
237 -- with the additional visibility provided by the context clause of the
238 -- subunit itself. As a result, compilation of a subunit forces compilation
239 -- of the parent (see description in lib-). At the point of the stub
240 -- declaration, Analyze is called recursively to compile the proper body of
241 -- the subunit, but without reinitializing the names table, nor the scope
242 -- stack (i.e. standard is not pushed on the stack). In this fashion the
243 -- context of the subunit is added to the context of the parent, and the
244 -- subunit is compiled in the correct environment. Note that in the course
245 -- of processing the context of a subunit, Standard will appear twice on
246 -- the scope stack: once for the parent of the subunit, and once for the
247 -- unit in the context clause being compiled. However, the two sets of
248 -- entities are not linked by homonym chains, so that the compilation of
249 -- any context unit happens in a fresh visibility environment.
251 -------------------------------
252 -- Processing of USE Clauses --
253 -------------------------------
255 -- Every defining occurrence has a flag indicating if it is potentially use
256 -- visible. Resolution of simple names examines this flag. The processing
257 -- of use clauses consists in setting this flag on all visible entities
258 -- defined in the corresponding package. On exit from the scope of the use
259 -- clause, the corresponding flag must be reset. However, a package may
260 -- appear in several nested use clauses (pathological but legal, alas!)
261 -- which forces us to use a slightly more involved scheme:
263 -- a) The defining occurrence for a package holds a flag -In_Use- to
264 -- indicate that it is currently in the scope of a use clause. If a
265 -- redundant use clause is encountered, then the corresponding occurrence
266 -- of the package name is flagged -Redundant_Use-.
268 -- b) On exit from a scope, the use clauses in its declarative part are
269 -- scanned. The visibility flag is reset in all entities declared in
270 -- package named in a use clause, as long as the package is not flagged
271 -- as being in a redundant use clause (in which case the outer use
272 -- clause is still in effect, and the direct visibility of its entities
273 -- must be retained).
275 -- Note that entities are not removed from their homonym chains on exit
276 -- from the package specification. A subsequent use clause does not need
277 -- to rechain the visible entities, but only to establish their direct
280 -----------------------------------
281 -- Handling private declarations --
282 -----------------------------------
284 -- The principle that each entity has a single defining occurrence clashes
285 -- with the presence of two separate definitions for private types: the
286 -- first is the private type declaration, and second is the full type
287 -- declaration. It is important that all references to the type point to
288 -- the same defining occurrence, namely the first one. To enforce the two
289 -- separate views of the entity, the corresponding information is swapped
290 -- between the two declarations. Outside of the package, the defining
291 -- occurrence only contains the private declaration information, while in
292 -- the private part and the body of the package the defining occurrence
293 -- contains the full declaration. To simplify the swap, the defining
294 -- occurrence that currently holds the private declaration points to the
295 -- full declaration. During semantic processing the defining occurrence
296 -- also points to a list of private dependents, that is to say access types
297 -- or composite types whose designated types or component types are
298 -- subtypes or derived types of the private type in question. After the
299 -- full declaration has been seen, the private dependents are updated to
300 -- indicate that they have full definitions.
302 ------------------------------------
303 -- Handling of Undefined Messages --
304 ------------------------------------
306 -- In normal mode, only the first use of an undefined identifier generates
307 -- a message. The table Urefs is used to record error messages that have
308 -- been issued so that second and subsequent ones do not generate further
309 -- messages. However, the second reference causes text to be added to the
310 -- original undefined message noting "(more references follow)". The
311 -- full error list option (-gnatf) forces messages to be generated for
312 -- every reference and disconnects the use of this table.
314 type Uref_Entry is record
316 -- Node for identifier for which original message was posted. The
317 -- Chars field of this identifier is used to detect later references
318 -- to the same identifier.
321 -- Records error message Id of original undefined message. Reset to
322 -- No_Error_Msg after the second occurrence, where it is used to add
323 -- text to the original message as described above.
326 -- Set if the message is not visible rather than undefined
329 -- Records location of error message. Used to make sure that we do
330 -- not consider a, b : undefined as two separate instances, which
331 -- would otherwise happen, since the parser converts this sequence
332 -- to a : undefined; b : undefined.
336 package Urefs is new Table.Table (
337 Table_Component_Type => Uref_Entry,
338 Table_Index_Type => Nat,
339 Table_Low_Bound => 1,
341 Table_Increment => 100,
342 Table_Name => "Urefs");
344 Candidate_Renaming : Entity_Id;
345 -- Holds a candidate interpretation that appears in a subprogram renaming
346 -- declaration and does not match the given specification, but matches at
347 -- least on the first formal. Allows better error message when given
348 -- specification omits defaulted parameters, a common error.
350 -----------------------
351 -- Local Subprograms --
352 -----------------------
354 procedure Analyze_Generic_Renaming
357 -- Common processing for all three kinds of generic renaming declarations.
358 -- Enter new name and indicate that it renames the generic unit.
360 procedure Analyze_Renamed_Character
364 -- Renamed entity is given by a character literal, which must belong
365 -- to the return type of the new entity. Is_Body indicates whether the
366 -- declaration is a renaming_as_body. If the original declaration has
367 -- already been frozen (because of an intervening body, e.g.) the body of
368 -- the function must be built now. The same applies to the following
369 -- various renaming procedures.
371 procedure Analyze_Renamed_Dereference
375 -- Renamed entity is given by an explicit dereference. Prefix must be a
376 -- conformant access_to_subprogram type.
378 procedure Analyze_Renamed_Entry
382 -- If the renamed entity in a subprogram renaming is an entry or protected
383 -- subprogram, build a body for the new entity whose only statement is a
384 -- call to the renamed entity.
386 procedure Analyze_Renamed_Family_Member
390 -- Used when the renamed entity is an indexed component. The prefix must
391 -- denote an entry family.
393 procedure Analyze_Renamed_Primitive_Operation
397 -- If the renamed entity in a subprogram renaming is a primitive operation
398 -- or a class-wide operation in prefix form, save the target object, which
399 -- must be added to the list of actuals in any subsequent call.
401 function Applicable_Use (Pack_Name : Node_Id) return Boolean;
402 -- Common code to Use_One_Package and Set_Use, to determine whether use
403 -- clause must be processed. Pack_Name is an entity name that references
404 -- the package in question.
406 procedure Attribute_Renaming (N : Node_Id);
407 -- Analyze renaming of attribute as subprogram. The renaming declaration N
408 -- is rewritten as a subprogram body that returns the attribute reference
409 -- applied to the formals of the function.
411 procedure Set_Entity_Or_Discriminal (N : Node_Id; E : Entity_Id);
412 -- Set Entity, with style check if need be. For a discriminant reference,
413 -- replace by the corresponding discriminal, i.e. the parameter of the
414 -- initialization procedure that corresponds to the discriminant.
416 procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id);
417 -- A renaming_as_body may occur after the entity of the original decla-
418 -- ration has been frozen. In that case, the body of the new entity must
419 -- be built now, because the usual mechanism of building the renamed
420 -- body at the point of freezing will not work. Subp is the subprogram
421 -- for which N provides the Renaming_As_Body.
423 procedure Check_In_Previous_With_Clause
426 -- N is a use_package clause and Nam the package name, or N is a use_type
427 -- clause and Nam is the prefix of the type name. In either case, verify
428 -- that the package is visible at that point in the context: either it
429 -- appears in a previous with_clause, or because it is a fully qualified
430 -- name and the root ancestor appears in a previous with_clause.
432 procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id);
433 -- Verify that the entity in a renaming declaration that is a library unit
434 -- is itself a library unit and not a nested unit or subunit. Also check
435 -- that if the renaming is a child unit of a generic parent, then the
436 -- renamed unit must also be a child unit of that parent. Finally, verify
437 -- that a renamed generic unit is not an implicit child declared within
438 -- an instance of the parent.
440 procedure Chain_Use_Clause (N : Node_Id);
441 -- Chain use clause onto list of uses clauses headed by First_Use_Clause in
442 -- the proper scope table entry. This is usually the current scope, but it
443 -- will be an inner scope when installing the use clauses of the private
444 -- declarations of a parent unit prior to compiling the private part of a
445 -- child unit. This chain is traversed when installing/removing use clauses
446 -- when compiling a subunit or instantiating a generic body on the fly,
447 -- when it is necessary to save and restore full environments.
449 function Has_Implicit_Character_Literal (N : Node_Id) return Boolean;
450 -- Find a type derived from Character or Wide_Character in the prefix of N.
451 -- Used to resolved qualified names whose selector is a character literal.
453 function Has_Private_With (E : Entity_Id) return Boolean;
454 -- Ada 2005 (AI-262): Determines if the current compilation unit has a
455 -- private with on E.
457 procedure Find_Expanded_Name (N : Node_Id);
458 -- The input is a selected component known to be an expanded name. Verify
459 -- legality of selector given the scope denoted by prefix, and change node
460 -- N into a expanded name with a properly set Entity field.
462 function Find_Renamed_Entity
466 Is_Actual : Boolean := False) return Entity_Id;
467 -- Find the renamed entity that corresponds to the given parameter profile
468 -- in a subprogram renaming declaration. The renamed entity may be an
469 -- operator, a subprogram, an entry, or a protected operation. Is_Actual
470 -- indicates that the renaming is the one generated for an actual subpro-
471 -- gram in an instance, for which special visibility checks apply.
473 function Has_Implicit_Operator (N : Node_Id) return Boolean;
474 -- N is an expanded name whose selector is an operator name (e.g. P."+").
475 -- declarative part contains an implicit declaration of an operator if it
476 -- has a declaration of a type to which one of the predefined operators
477 -- apply. The existence of this routine is an implementation artifact. A
478 -- more straightforward but more space-consuming choice would be to make
479 -- all inherited operators explicit in the symbol table.
481 procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id);
482 -- A subprogram defined by a renaming declaration inherits the parameter
483 -- profile of the renamed entity. The subtypes given in the subprogram
484 -- specification are discarded and replaced with those of the renamed
485 -- subprogram, which are then used to recheck the default values.
487 function Is_Appropriate_For_Record (T : Entity_Id) return Boolean;
488 -- Prefix is appropriate for record if it is of a record type, or an access
491 function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean;
492 -- True if it is of a task type, a protected type, or else an access to one
495 procedure Note_Redundant_Use (Clause : Node_Id);
496 -- Mark the name in a use clause as redundant if the corresponding entity
497 -- is already use-visible. Emit a warning if the use clause comes from
498 -- source and the proper warnings are enabled.
500 procedure Premature_Usage (N : Node_Id);
501 -- Diagnose usage of an entity before it is visible
503 procedure Use_One_Package (P : Entity_Id; N : Node_Id);
504 -- Make visible entities declared in package P potentially use-visible
505 -- in the current context. Also used in the analysis of subunits, when
506 -- re-installing use clauses of parent units. N is the use_clause that
507 -- names P (and possibly other packages).
509 procedure Use_One_Type (Id : Node_Id; Installed : Boolean := False);
510 -- Id is the subtype mark from a use type clause. This procedure makes
511 -- the primitive operators of the type potentially use-visible. The
512 -- boolean flag Installed indicates that the clause is being reinstalled
513 -- after previous analysis, and primitive operations are already chained
514 -- on the Used_Operations list of the clause.
516 procedure Write_Info;
517 -- Write debugging information on entities declared in current scope
519 --------------------------------
520 -- Analyze_Exception_Renaming --
521 --------------------------------
523 -- The language only allows a single identifier, but the tree holds an
524 -- identifier list. The parser has already issued an error message if
525 -- there is more than one element in the list.
527 procedure Analyze_Exception_Renaming (N : Node_Id) is
528 Id : constant Node_Id := Defining_Identifier (N);
529 Nam : constant Node_Id := Name (N);
532 -- Exception renaming is not allowed in SPARK or ALFA
534 if Formal_Verification_Mode then
535 Error_Msg_F ("|~~exception renaming is not allowed", N);
538 -- Proceed with analysis
543 Set_Ekind (Id, E_Exception);
544 Set_Exception_Code (Id, Uint_0);
545 Set_Etype (Id, Standard_Exception_Type);
546 Set_Is_Pure (Id, Is_Pure (Current_Scope));
548 if not Is_Entity_Name (Nam) or else
549 Ekind (Entity (Nam)) /= E_Exception
551 Error_Msg_N ("invalid exception name in renaming", Nam);
553 if Present (Renamed_Object (Entity (Nam))) then
554 Set_Renamed_Object (Id, Renamed_Object (Entity (Nam)));
556 Set_Renamed_Object (Id, Entity (Nam));
559 end Analyze_Exception_Renaming;
561 ---------------------------
562 -- Analyze_Expanded_Name --
563 ---------------------------
565 procedure Analyze_Expanded_Name (N : Node_Id) is
567 -- If the entity pointer is already set, this is an internal node, or a
568 -- node that is analyzed more than once, after a tree modification. In
569 -- such a case there is no resolution to perform, just set the type. For
570 -- completeness, analyze prefix as well.
572 if Present (Entity (N)) then
573 if Is_Type (Entity (N)) then
574 Set_Etype (N, Entity (N));
576 Set_Etype (N, Etype (Entity (N)));
579 Analyze (Prefix (N));
582 Find_Expanded_Name (N);
584 end Analyze_Expanded_Name;
586 ---------------------------------------
587 -- Analyze_Generic_Function_Renaming --
588 ---------------------------------------
590 procedure Analyze_Generic_Function_Renaming (N : Node_Id) is
592 Analyze_Generic_Renaming (N, E_Generic_Function);
593 end Analyze_Generic_Function_Renaming;
595 --------------------------------------
596 -- Analyze_Generic_Package_Renaming --
597 --------------------------------------
599 procedure Analyze_Generic_Package_Renaming (N : Node_Id) is
601 -- Apply the Text_IO Kludge here, since we may be renaming one of the
602 -- subpackages of Text_IO, then join common routine.
604 Text_IO_Kludge (Name (N));
606 Analyze_Generic_Renaming (N, E_Generic_Package);
607 end Analyze_Generic_Package_Renaming;
609 ----------------------------------------
610 -- Analyze_Generic_Procedure_Renaming --
611 ----------------------------------------
613 procedure Analyze_Generic_Procedure_Renaming (N : Node_Id) is
615 Analyze_Generic_Renaming (N, E_Generic_Procedure);
616 end Analyze_Generic_Procedure_Renaming;
618 ------------------------------
619 -- Analyze_Generic_Renaming --
620 ------------------------------
622 procedure Analyze_Generic_Renaming
626 New_P : constant Entity_Id := Defining_Entity (N);
628 Inst : Boolean := False; -- prevent junk warning
631 -- Generic renaming is not allowed in SPARK or ALFA
633 if Formal_Verification_Mode then
634 Error_Msg_F ("|~~generic renaming is not allowed", N);
637 -- Proceed with analysis
639 if Name (N) = Error then
643 Generate_Definition (New_P);
645 if Current_Scope /= Standard_Standard then
646 Set_Is_Pure (New_P, Is_Pure (Current_Scope));
649 if Nkind (Name (N)) = N_Selected_Component then
650 Check_Generic_Child_Unit (Name (N), Inst);
655 if not Is_Entity_Name (Name (N)) then
656 Error_Msg_N ("expect entity name in renaming declaration", Name (N));
659 Old_P := Entity (Name (N));
663 Set_Ekind (New_P, K);
665 if Etype (Old_P) = Any_Type then
668 elsif Ekind (Old_P) /= K then
669 Error_Msg_N ("invalid generic unit name", Name (N));
672 if Present (Renamed_Object (Old_P)) then
673 Set_Renamed_Object (New_P, Renamed_Object (Old_P));
675 Set_Renamed_Object (New_P, Old_P);
678 Set_Is_Pure (New_P, Is_Pure (Old_P));
679 Set_Is_Preelaborated (New_P, Is_Preelaborated (Old_P));
681 Set_Etype (New_P, Etype (Old_P));
682 Set_Has_Completion (New_P);
684 if In_Open_Scopes (Old_P) then
685 Error_Msg_N ("within its scope, generic denotes its instance", N);
688 Check_Library_Unit_Renaming (N, Old_P);
690 end Analyze_Generic_Renaming;
692 -----------------------------
693 -- Analyze_Object_Renaming --
694 -----------------------------
696 procedure Analyze_Object_Renaming (N : Node_Id) is
697 Id : constant Entity_Id := Defining_Identifier (N);
699 Nam : constant Node_Id := Name (N);
703 function In_Generic_Scope (E : Entity_Id) return Boolean;
704 -- Determine whether entity E is inside a generic cope
706 ----------------------
707 -- In_Generic_Scope --
708 ----------------------
710 function In_Generic_Scope (E : Entity_Id) return Boolean is
715 while Present (S) and then S /= Standard_Standard loop
716 if Is_Generic_Unit (S) then
724 end In_Generic_Scope;
726 -- Start of processing for Analyze_Object_Renaming
729 -- Object renaming is not allowed in SPARK or ALFA
731 if Formal_Verification_Mode then
732 Error_Msg_F ("|~~object renaming is not allowed", N);
735 -- Proceed with analysis
741 Set_Is_Pure (Id, Is_Pure (Current_Scope));
744 -- The renaming of a component that depends on a discriminant requires
745 -- an actual subtype, because in subsequent use of the object Gigi will
746 -- be unable to locate the actual bounds. This explicit step is required
747 -- when the renaming is generated in removing side effects of an
748 -- already-analyzed expression.
750 if Nkind (Nam) = N_Selected_Component
751 and then Analyzed (Nam)
754 Dec := Build_Actual_Subtype_Of_Component (Etype (Nam), Nam);
756 if Present (Dec) then
757 Insert_Action (N, Dec);
758 T := Defining_Identifier (Dec);
762 -- Complete analysis of the subtype mark in any case, for ASIS use
764 if Present (Subtype_Mark (N)) then
765 Find_Type (Subtype_Mark (N));
768 elsif Present (Subtype_Mark (N)) then
769 Find_Type (Subtype_Mark (N));
770 T := Entity (Subtype_Mark (N));
773 if Nkind (Nam) = N_Type_Conversion
774 and then not Is_Tagged_Type (T)
777 ("renaming of conversion only allowed for tagged types", Nam);
782 -- Check that a class-wide object is not being renamed as an object
783 -- of a specific type. The test for access types is needed to exclude
784 -- cases where the renamed object is a dynamically tagged access
785 -- result, such as occurs in certain expansions.
787 if Is_Tagged_Type (T) then
788 Check_Dynamically_Tagged_Expression
794 -- Ada 2005 (AI-230/AI-254): Access renaming
796 else pragma Assert (Present (Access_Definition (N)));
797 T := Access_Definition
799 N => Access_Definition (N));
803 -- Ada 2005 AI05-105: if the declaration has an anonymous access
804 -- type, the renamed object must also have an anonymous type, and
805 -- this is a name resolution rule. This was implicit in the last
806 -- part of the first sentence in 8.5.1.(3/2), and is made explicit
807 -- by this recent AI.
809 if not Is_Overloaded (Nam) then
810 if Ekind (Etype (Nam)) /= Ekind (T) then
812 ("expect anonymous access type in object renaming", N);
819 Typ : Entity_Id := Empty;
820 Seen : Boolean := False;
823 Get_First_Interp (Nam, I, It);
824 while Present (It.Typ) loop
826 -- Renaming is ambiguous if more than one candidate
827 -- interpretation is type-conformant with the context.
829 if Ekind (It.Typ) = Ekind (T) then
830 if Ekind (T) = E_Anonymous_Access_Subprogram_Type
833 (Designated_Type (T), Designated_Type (It.Typ))
839 ("ambiguous expression in renaming", Nam);
842 elsif Ekind (T) = E_Anonymous_Access_Type
844 Covers (Designated_Type (T), Designated_Type (It.Typ))
850 ("ambiguous expression in renaming", Nam);
854 if Covers (T, It.Typ) then
856 Set_Etype (Nam, Typ);
857 Set_Is_Overloaded (Nam, False);
861 Get_Next_Interp (I, It);
868 -- Ada 2005 (AI-231): "In the case where the type is defined by an
869 -- access_definition, the renamed entity shall be of an access-to-
870 -- constant type if and only if the access_definition defines an
871 -- access-to-constant type" ARM 8.5.1(4)
873 if Constant_Present (Access_Definition (N))
874 and then not Is_Access_Constant (Etype (Nam))
876 Error_Msg_N ("(Ada 2005): the renamed object is not "
877 & "access-to-constant (RM 8.5.1(6))", N);
879 elsif not Constant_Present (Access_Definition (N))
880 and then Is_Access_Constant (Etype (Nam))
882 Error_Msg_N ("(Ada 2005): the renamed object is not "
883 & "access-to-variable (RM 8.5.1(6))", N);
886 if Is_Access_Subprogram_Type (Etype (Nam)) then
887 Check_Subtype_Conformant
888 (Designated_Type (T), Designated_Type (Etype (Nam)));
890 elsif not Subtypes_Statically_Match
891 (Designated_Type (T), Designated_Type (Etype (Nam)))
894 ("subtype of renamed object does not statically match", N);
898 -- Special processing for renaming function return object. Some errors
899 -- and warnings are produced only for calls that come from source.
901 if Nkind (Nam) = N_Function_Call then
904 -- Usage is illegal in Ada 83
907 if Comes_From_Source (Nam) then
909 ("(Ada 83) cannot rename function return object", Nam);
912 -- In Ada 95, warn for odd case of renaming parameterless function
913 -- call if this is not a limited type (where this is useful).
916 if Warn_On_Object_Renames_Function
917 and then No (Parameter_Associations (Nam))
918 and then not Is_Limited_Type (Etype (Nam))
919 and then Comes_From_Source (Nam)
922 ("?renaming function result object is suspicious", Nam);
924 ("\?function & will be called only once", Nam,
925 Entity (Name (Nam)));
926 Error_Msg_N -- CODEFIX
927 ("\?suggest using an initialized constant object instead",
931 -- If the function call returns an unconstrained type, we must
932 -- build a constrained subtype for the new entity, in a way
933 -- similar to what is done for an object declaration with an
934 -- unconstrained nominal type.
936 if Is_Composite_Type (Etype (Nam))
937 and then not Is_Constrained (Etype (Nam))
938 and then not Has_Unknown_Discriminants (Etype (Nam))
939 and then Expander_Active
942 Loc : constant Source_Ptr := Sloc (N);
943 Subt : constant Entity_Id := Make_Temporary (Loc, 'T');
945 Remove_Side_Effects (Nam);
947 Make_Subtype_Declaration (Loc,
948 Defining_Identifier => Subt,
949 Subtype_Indication =>
950 Make_Subtype_From_Expr (Nam, Etype (Nam))));
951 Rewrite (Subtype_Mark (N), New_Occurrence_Of (Subt, Loc));
952 Set_Etype (Nam, Subt);
958 -- An object renaming requires an exact match of the type. Class-wide
959 -- matching is not allowed.
961 if Is_Class_Wide_Type (T)
962 and then Base_Type (Etype (Nam)) /= Base_Type (T)
969 -- (Ada 2005: AI-326): Handle wrong use of incomplete type
971 if Nkind (Nam) = N_Explicit_Dereference
972 and then Ekind (Etype (T2)) = E_Incomplete_Type
974 Error_Msg_NE ("invalid use of incomplete type&", Id, T2);
977 elsif Ekind (Etype (T)) = E_Incomplete_Type then
978 Error_Msg_NE ("invalid use of incomplete type&", Id, T);
984 if Ada_Version >= Ada_2005
985 and then Nkind (Nam) = N_Attribute_Reference
986 and then Attribute_Name (Nam) = Name_Priority
990 elsif Ada_Version >= Ada_2005
991 and then Nkind (Nam) in N_Has_Entity
998 if Nkind (Nam) = N_Attribute_Reference then
999 Nam_Ent := Entity (Prefix (Nam));
1001 Nam_Ent := Entity (Nam);
1004 Nam_Decl := Parent (Nam_Ent);
1006 if Has_Null_Exclusion (N)
1007 and then not Has_Null_Exclusion (Nam_Decl)
1009 -- Ada 2005 (AI-423): If the object name denotes a generic
1010 -- formal object of a generic unit G, and the object renaming
1011 -- declaration occurs within the body of G or within the body
1012 -- of a generic unit declared within the declarative region
1013 -- of G, then the declaration of the formal object of G must
1014 -- have a null exclusion or a null-excluding subtype.
1016 if Is_Formal_Object (Nam_Ent)
1017 and then In_Generic_Scope (Id)
1019 if not Can_Never_Be_Null (Etype (Nam_Ent)) then
1021 ("renamed formal does not exclude `NULL` "
1022 & "(RM 8.5.1(4.6/2))", N);
1024 elsif In_Package_Body (Scope (Id)) then
1026 ("formal object does not have a null exclusion"
1027 & "(RM 8.5.1(4.6/2))", N);
1030 -- Ada 2005 (AI-423): Otherwise, the subtype of the object name
1031 -- shall exclude null.
1033 elsif not Can_Never_Be_Null (Etype (Nam_Ent)) then
1035 ("renamed object does not exclude `NULL` "
1036 & "(RM 8.5.1(4.6/2))", N);
1038 -- An instance is illegal if it contains a renaming that
1039 -- excludes null, and the actual does not. The renaming
1040 -- declaration has already indicated that the declaration
1041 -- of the renamed actual in the instance will raise
1042 -- constraint_error.
1044 elsif Nkind (Nam_Decl) = N_Object_Declaration
1045 and then In_Instance
1047 (Corresponding_Generic_Association (Nam_Decl))
1048 and then Nkind (Expression (Nam_Decl))
1049 = N_Raise_Constraint_Error
1052 ("renamed actual does not exclude `NULL` "
1053 & "(RM 8.5.1(4.6/2))", N);
1055 -- Finally, if there is a null exclusion, the subtype mark
1056 -- must not be null-excluding.
1058 elsif No (Access_Definition (N))
1059 and then Can_Never_Be_Null (T)
1062 ("`NOT NULL` not allowed (& already excludes null)",
1067 elsif Can_Never_Be_Null (T)
1068 and then not Can_Never_Be_Null (Etype (Nam_Ent))
1071 ("renamed object does not exclude `NULL` "
1072 & "(RM 8.5.1(4.6/2))", N);
1074 elsif Has_Null_Exclusion (N)
1075 and then No (Access_Definition (N))
1076 and then Can_Never_Be_Null (T)
1079 ("`NOT NULL` not allowed (& already excludes null)", N, T);
1084 Set_Ekind (Id, E_Variable);
1085 Init_Size_Align (Id);
1087 if T = Any_Type or else Etype (Nam) = Any_Type then
1090 -- Verify that the renamed entity is an object or a function call. It
1091 -- may have been rewritten in several ways.
1093 elsif Is_Object_Reference (Nam) then
1094 if Comes_From_Source (N)
1095 and then Is_Dependent_Component_Of_Mutable_Object (Nam)
1098 ("illegal renaming of discriminant-dependent component", Nam);
1101 -- A static function call may have been folded into a literal
1103 elsif Nkind (Original_Node (Nam)) = N_Function_Call
1105 -- When expansion is disabled, attribute reference is not
1106 -- rewritten as function call. Otherwise it may be rewritten
1107 -- as a conversion, so check original node.
1109 or else (Nkind (Original_Node (Nam)) = N_Attribute_Reference
1110 and then Is_Function_Attribute_Name
1111 (Attribute_Name (Original_Node (Nam))))
1113 -- Weird but legal, equivalent to renaming a function call.
1114 -- Illegal if the literal is the result of constant-folding an
1115 -- attribute reference that is not a function.
1117 or else (Is_Entity_Name (Nam)
1118 and then Ekind (Entity (Nam)) = E_Enumeration_Literal
1120 Nkind (Original_Node (Nam)) /= N_Attribute_Reference)
1122 or else (Nkind (Nam) = N_Type_Conversion
1123 and then Is_Tagged_Type (Entity (Subtype_Mark (Nam))))
1127 elsif Nkind (Nam) = N_Type_Conversion then
1129 ("renaming of conversion only allowed for tagged types", Nam);
1131 -- Ada 2005 (AI-327)
1133 elsif Ada_Version >= Ada_2005
1134 and then Nkind (Nam) = N_Attribute_Reference
1135 and then Attribute_Name (Nam) = Name_Priority
1139 -- Allow internally generated x'Reference expression
1141 elsif Nkind (Nam) = N_Reference then
1145 Error_Msg_N ("expect object name in renaming", Nam);
1150 if not Is_Variable (Nam) then
1151 Set_Ekind (Id, E_Constant);
1152 Set_Never_Set_In_Source (Id, True);
1153 Set_Is_True_Constant (Id, True);
1156 Set_Renamed_Object (Id, Nam);
1157 end Analyze_Object_Renaming;
1159 ------------------------------
1160 -- Analyze_Package_Renaming --
1161 ------------------------------
1163 procedure Analyze_Package_Renaming (N : Node_Id) is
1164 New_P : constant Entity_Id := Defining_Entity (N);
1169 if Name (N) = Error then
1173 -- Apply Text_IO kludge here since we may be renaming a child of Text_IO
1175 Text_IO_Kludge (Name (N));
1177 if Current_Scope /= Standard_Standard then
1178 Set_Is_Pure (New_P, Is_Pure (Current_Scope));
1184 if Is_Entity_Name (Name (N)) then
1185 Old_P := Entity (Name (N));
1190 if Etype (Old_P) = Any_Type then
1191 Error_Msg_N ("expect package name in renaming", Name (N));
1193 elsif Ekind (Old_P) /= E_Package
1194 and then not (Ekind (Old_P) = E_Generic_Package
1195 and then In_Open_Scopes (Old_P))
1197 if Ekind (Old_P) = E_Generic_Package then
1199 ("generic package cannot be renamed as a package", Name (N));
1201 Error_Msg_Sloc := Sloc (Old_P);
1203 ("expect package name in renaming, found& declared#",
1207 -- Set basic attributes to minimize cascaded errors
1209 Set_Ekind (New_P, E_Package);
1210 Set_Etype (New_P, Standard_Void_Type);
1212 -- Here for OK package renaming
1215 -- Entities in the old package are accessible through the renaming
1216 -- entity. The simplest implementation is to have both packages share
1219 Set_Ekind (New_P, E_Package);
1220 Set_Etype (New_P, Standard_Void_Type);
1222 if Present (Renamed_Object (Old_P)) then
1223 Set_Renamed_Object (New_P, Renamed_Object (Old_P));
1225 Set_Renamed_Object (New_P, Old_P);
1228 Set_Has_Completion (New_P);
1230 Set_First_Entity (New_P, First_Entity (Old_P));
1231 Set_Last_Entity (New_P, Last_Entity (Old_P));
1232 Set_First_Private_Entity (New_P, First_Private_Entity (Old_P));
1233 Check_Library_Unit_Renaming (N, Old_P);
1234 Generate_Reference (Old_P, Name (N));
1236 -- If the renaming is in the visible part of a package, then we set
1237 -- Renamed_In_Spec for the renamed package, to prevent giving
1238 -- warnings about no entities referenced. Such a warning would be
1239 -- overenthusiastic, since clients can see entities in the renamed
1240 -- package via the visible package renaming.
1243 Ent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
1245 if Ekind (Ent) = E_Package
1246 and then not In_Private_Part (Ent)
1247 and then In_Extended_Main_Source_Unit (N)
1248 and then Ekind (Old_P) = E_Package
1250 Set_Renamed_In_Spec (Old_P);
1254 -- If this is the renaming declaration of a package instantiation
1255 -- within itself, it is the declaration that ends the list of actuals
1256 -- for the instantiation. At this point, the subtypes that rename
1257 -- the actuals are flagged as generic, to avoid spurious ambiguities
1258 -- if the actuals for two distinct formals happen to coincide. If
1259 -- the actual is a private type, the subtype has a private completion
1260 -- that is flagged in the same fashion.
1262 -- Resolution is identical to what is was in the original generic.
1263 -- On exit from the generic instance, these are turned into regular
1264 -- subtypes again, so they are compatible with types in their class.
1266 if not Is_Generic_Instance (Old_P) then
1269 Spec := Specification (Unit_Declaration_Node (Old_P));
1272 if Nkind (Spec) = N_Package_Specification
1273 and then Present (Generic_Parent (Spec))
1274 and then Old_P = Current_Scope
1275 and then Chars (New_P) = Chars (Generic_Parent (Spec))
1281 E := First_Entity (Old_P);
1286 and then Nkind (Parent (E)) = N_Subtype_Declaration
1288 Set_Is_Generic_Actual_Type (E);
1290 if Is_Private_Type (E)
1291 and then Present (Full_View (E))
1293 Set_Is_Generic_Actual_Type (Full_View (E));
1302 end Analyze_Package_Renaming;
1304 -------------------------------
1305 -- Analyze_Renamed_Character --
1306 -------------------------------
1308 procedure Analyze_Renamed_Character
1313 C : constant Node_Id := Name (N);
1316 if Ekind (New_S) = E_Function then
1317 Resolve (C, Etype (New_S));
1320 Check_Frozen_Renaming (N, New_S);
1324 Error_Msg_N ("character literal can only be renamed as function", N);
1326 end Analyze_Renamed_Character;
1328 ---------------------------------
1329 -- Analyze_Renamed_Dereference --
1330 ---------------------------------
1332 procedure Analyze_Renamed_Dereference
1337 Nam : constant Node_Id := Name (N);
1338 P : constant Node_Id := Prefix (Nam);
1344 if not Is_Overloaded (P) then
1345 if Ekind (Etype (Nam)) /= E_Subprogram_Type
1346 or else not Type_Conformant (Etype (Nam), New_S)
1348 Error_Msg_N ("designated type does not match specification", P);
1357 Get_First_Interp (Nam, Ind, It);
1359 while Present (It.Nam) loop
1361 if Ekind (It.Nam) = E_Subprogram_Type
1362 and then Type_Conformant (It.Nam, New_S)
1364 if Typ /= Any_Id then
1365 Error_Msg_N ("ambiguous renaming", P);
1372 Get_Next_Interp (Ind, It);
1375 if Typ = Any_Type then
1376 Error_Msg_N ("designated type does not match specification", P);
1381 Check_Frozen_Renaming (N, New_S);
1385 end Analyze_Renamed_Dereference;
1387 ---------------------------
1388 -- Analyze_Renamed_Entry --
1389 ---------------------------
1391 procedure Analyze_Renamed_Entry
1396 Nam : constant Node_Id := Name (N);
1397 Sel : constant Node_Id := Selector_Name (Nam);
1401 if Entity (Sel) = Any_Id then
1403 -- Selector is undefined on prefix. Error emitted already
1405 Set_Has_Completion (New_S);
1409 -- Otherwise find renamed entity and build body of New_S as a call to it
1411 Old_S := Find_Renamed_Entity (N, Selector_Name (Nam), New_S);
1413 if Old_S = Any_Id then
1414 Error_Msg_N (" no subprogram or entry matches specification", N);
1417 Check_Subtype_Conformant (New_S, Old_S, N);
1418 Generate_Reference (New_S, Defining_Entity (N), 'b');
1419 Style.Check_Identifier (Defining_Entity (N), New_S);
1422 -- Only mode conformance required for a renaming_as_declaration
1424 Check_Mode_Conformant (New_S, Old_S, N);
1427 Inherit_Renamed_Profile (New_S, Old_S);
1429 -- The prefix can be an arbitrary expression that yields a task type,
1430 -- so it must be resolved.
1432 Resolve (Prefix (Nam), Scope (Old_S));
1435 Set_Convention (New_S, Convention (Old_S));
1436 Set_Has_Completion (New_S, Inside_A_Generic);
1439 Check_Frozen_Renaming (N, New_S);
1441 end Analyze_Renamed_Entry;
1443 -----------------------------------
1444 -- Analyze_Renamed_Family_Member --
1445 -----------------------------------
1447 procedure Analyze_Renamed_Family_Member
1452 Nam : constant Node_Id := Name (N);
1453 P : constant Node_Id := Prefix (Nam);
1457 if (Is_Entity_Name (P) and then Ekind (Entity (P)) = E_Entry_Family)
1458 or else (Nkind (P) = N_Selected_Component
1460 Ekind (Entity (Selector_Name (P))) = E_Entry_Family)
1462 if Is_Entity_Name (P) then
1463 Old_S := Entity (P);
1465 Old_S := Entity (Selector_Name (P));
1468 if not Entity_Matches_Spec (Old_S, New_S) then
1469 Error_Msg_N ("entry family does not match specification", N);
1472 Check_Subtype_Conformant (New_S, Old_S, N);
1473 Generate_Reference (New_S, Defining_Entity (N), 'b');
1474 Style.Check_Identifier (Defining_Entity (N), New_S);
1478 Error_Msg_N ("no entry family matches specification", N);
1481 Set_Has_Completion (New_S, Inside_A_Generic);
1484 Check_Frozen_Renaming (N, New_S);
1486 end Analyze_Renamed_Family_Member;
1488 -----------------------------------------
1489 -- Analyze_Renamed_Primitive_Operation --
1490 -----------------------------------------
1492 procedure Analyze_Renamed_Primitive_Operation
1501 Ctyp : Conformance_Type) return Boolean;
1502 -- Verify that the signatures of the renamed entity and the new entity
1503 -- match. The first formal of the renamed entity is skipped because it
1504 -- is the target object in any subsequent call.
1508 Ctyp : Conformance_Type) return Boolean
1514 if Ekind (Subp) /= Ekind (New_S) then
1518 Old_F := Next_Formal (First_Formal (Subp));
1519 New_F := First_Formal (New_S);
1520 while Present (Old_F) and then Present (New_F) loop
1521 if not Conforming_Types (Etype (Old_F), Etype (New_F), Ctyp) then
1525 if Ctyp >= Mode_Conformant
1526 and then Ekind (Old_F) /= Ekind (New_F)
1531 Next_Formal (New_F);
1532 Next_Formal (Old_F);
1539 if not Is_Overloaded (Selector_Name (Name (N))) then
1540 Old_S := Entity (Selector_Name (Name (N)));
1542 if not Conforms (Old_S, Type_Conformant) then
1547 -- Find the operation that matches the given signature
1555 Get_First_Interp (Selector_Name (Name (N)), Ind, It);
1557 while Present (It.Nam) loop
1558 if Conforms (It.Nam, Type_Conformant) then
1562 Get_Next_Interp (Ind, It);
1567 if Old_S = Any_Id then
1568 Error_Msg_N (" no subprogram or entry matches specification", N);
1572 if not Conforms (Old_S, Subtype_Conformant) then
1573 Error_Msg_N ("subtype conformance error in renaming", N);
1576 Generate_Reference (New_S, Defining_Entity (N), 'b');
1577 Style.Check_Identifier (Defining_Entity (N), New_S);
1580 -- Only mode conformance required for a renaming_as_declaration
1582 if not Conforms (Old_S, Mode_Conformant) then
1583 Error_Msg_N ("mode conformance error in renaming", N);
1587 -- Inherit_Renamed_Profile (New_S, Old_S);
1589 -- The prefix can be an arbitrary expression that yields an
1590 -- object, so it must be resolved.
1592 Resolve (Prefix (Name (N)));
1594 end Analyze_Renamed_Primitive_Operation;
1596 ---------------------------------
1597 -- Analyze_Subprogram_Renaming --
1598 ---------------------------------
1600 procedure Analyze_Subprogram_Renaming (N : Node_Id) is
1601 Formal_Spec : constant Node_Id := Corresponding_Formal_Spec (N);
1602 Is_Actual : constant Boolean := Present (Formal_Spec);
1603 Inst_Node : Node_Id := Empty;
1604 Nam : constant Node_Id := Name (N);
1606 Old_S : Entity_Id := Empty;
1607 Rename_Spec : Entity_Id;
1608 Save_AV : constant Ada_Version_Type := Ada_Version;
1609 Save_AV_Exp : constant Ada_Version_Type := Ada_Version_Explicit;
1610 Spec : constant Node_Id := Specification (N);
1612 procedure Check_Null_Exclusion
1615 -- Ada 2005 (AI-423): Given renaming Ren of subprogram Sub, check the
1616 -- following AI rules:
1618 -- If Ren is a renaming of a formal subprogram and one of its
1619 -- parameters has a null exclusion, then the corresponding formal
1620 -- in Sub must also have one. Otherwise the subtype of the Sub's
1621 -- formal parameter must exclude null.
1623 -- If Ren is a renaming of a formal function and its return
1624 -- profile has a null exclusion, then Sub's return profile must
1625 -- have one. Otherwise the subtype of Sub's return profile must
1628 function Original_Subprogram (Subp : Entity_Id) return Entity_Id;
1629 -- Find renamed entity when the declaration is a renaming_as_body and
1630 -- the renamed entity may itself be a renaming_as_body. Used to enforce
1631 -- rule that a renaming_as_body is illegal if the declaration occurs
1632 -- before the subprogram it completes is frozen, and renaming indirectly
1633 -- renames the subprogram itself.(Defect Report 8652/0027).
1635 --------------------------
1636 -- Check_Null_Exclusion --
1637 --------------------------
1639 procedure Check_Null_Exclusion
1643 Ren_Formal : Entity_Id;
1644 Sub_Formal : Entity_Id;
1649 Ren_Formal := First_Formal (Ren);
1650 Sub_Formal := First_Formal (Sub);
1651 while Present (Ren_Formal)
1652 and then Present (Sub_Formal)
1654 if Has_Null_Exclusion (Parent (Ren_Formal))
1656 not (Has_Null_Exclusion (Parent (Sub_Formal))
1657 or else Can_Never_Be_Null (Etype (Sub_Formal)))
1660 ("`NOT NULL` required for parameter &",
1661 Parent (Sub_Formal), Sub_Formal);
1664 Next_Formal (Ren_Formal);
1665 Next_Formal (Sub_Formal);
1668 -- Return profile check
1670 if Nkind (Parent (Ren)) = N_Function_Specification
1671 and then Nkind (Parent (Sub)) = N_Function_Specification
1672 and then Has_Null_Exclusion (Parent (Ren))
1674 not (Has_Null_Exclusion (Parent (Sub))
1675 or else Can_Never_Be_Null (Etype (Sub)))
1678 ("return must specify `NOT NULL`",
1679 Result_Definition (Parent (Sub)));
1681 end Check_Null_Exclusion;
1683 -------------------------
1684 -- Original_Subprogram --
1685 -------------------------
1687 function Original_Subprogram (Subp : Entity_Id) return Entity_Id is
1688 Orig_Decl : Node_Id;
1689 Orig_Subp : Entity_Id;
1692 -- First case: renamed entity is itself a renaming
1694 if Present (Alias (Subp)) then
1695 return Alias (Subp);
1698 Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration
1700 (Corresponding_Body (Unit_Declaration_Node (Subp)))
1702 -- Check if renamed entity is a renaming_as_body
1705 Unit_Declaration_Node
1706 (Corresponding_Body (Unit_Declaration_Node (Subp)));
1708 if Nkind (Orig_Decl) = N_Subprogram_Renaming_Declaration then
1709 Orig_Subp := Entity (Name (Orig_Decl));
1711 if Orig_Subp = Rename_Spec then
1713 -- Circularity detected
1718 return (Original_Subprogram (Orig_Subp));
1726 end Original_Subprogram;
1728 -- Start of processing for Analyze_Subprogram_Renaming
1731 -- We must test for the attribute renaming case before the Analyze
1732 -- call because otherwise Sem_Attr will complain that the attribute
1733 -- is missing an argument when it is analyzed.
1735 if Nkind (Nam) = N_Attribute_Reference then
1737 -- In the case of an abstract formal subprogram association, rewrite
1738 -- an actual given by a stream attribute as the name of the
1739 -- corresponding stream primitive of the type.
1741 -- In a generic context the stream operations are not generated, and
1742 -- this must be treated as a normal attribute reference, to be
1743 -- expanded in subsequent instantiations.
1745 if Is_Actual and then Is_Abstract_Subprogram (Formal_Spec)
1746 and then Expander_Active
1749 Stream_Prim : Entity_Id;
1750 Prefix_Type : constant Entity_Id := Entity (Prefix (Nam));
1753 -- The class-wide forms of the stream attributes are not
1754 -- primitive dispatching operations (even though they
1755 -- internally dispatch to a stream attribute).
1757 if Is_Class_Wide_Type (Prefix_Type) then
1759 ("attribute must be a primitive dispatching operation",
1764 -- Retrieve the primitive subprogram associated with the
1765 -- attribute. This can only be a stream attribute, since those
1766 -- are the only ones that are dispatching (and the actual for
1767 -- an abstract formal subprogram must be dispatching
1771 case Attribute_Name (Nam) is
1774 Find_Prim_Op (Prefix_Type, TSS_Stream_Input);
1777 Find_Prim_Op (Prefix_Type, TSS_Stream_Output);
1780 Find_Prim_Op (Prefix_Type, TSS_Stream_Read);
1783 Find_Prim_Op (Prefix_Type, TSS_Stream_Write);
1786 ("attribute must be a primitive"
1787 & " dispatching operation", Nam);
1793 -- If no operation was found, and the type is limited,
1794 -- the user should have defined one.
1796 when Program_Error =>
1797 if Is_Limited_Type (Prefix_Type) then
1799 ("stream operation not defined for type&",
1803 -- Otherwise, compiler should have generated default
1810 -- Rewrite the attribute into the name of its corresponding
1811 -- primitive dispatching subprogram. We can then proceed with
1812 -- the usual processing for subprogram renamings.
1815 Prim_Name : constant Node_Id :=
1816 Make_Identifier (Sloc (Nam),
1817 Chars => Chars (Stream_Prim));
1819 Set_Entity (Prim_Name, Stream_Prim);
1820 Rewrite (Nam, Prim_Name);
1825 -- Normal processing for a renaming of an attribute
1828 Attribute_Renaming (N);
1833 -- Check whether this declaration corresponds to the instantiation
1834 -- of a formal subprogram.
1836 -- If this is an instantiation, the corresponding actual is frozen and
1837 -- error messages can be made more precise. If this is a default
1838 -- subprogram, the entity is already established in the generic, and is
1839 -- not retrieved by visibility. If it is a default with a box, the
1840 -- candidate interpretations, if any, have been collected when building
1841 -- the renaming declaration. If overloaded, the proper interpretation is
1842 -- determined in Find_Renamed_Entity. If the entity is an operator,
1843 -- Find_Renamed_Entity applies additional visibility checks.
1846 Inst_Node := Unit_Declaration_Node (Formal_Spec);
1848 if Is_Entity_Name (Nam)
1849 and then Present (Entity (Nam))
1850 and then not Comes_From_Source (Nam)
1851 and then not Is_Overloaded (Nam)
1853 Old_S := Entity (Nam);
1854 New_S := Analyze_Subprogram_Specification (Spec);
1858 if Ekind (Entity (Nam)) = E_Operator then
1862 if Box_Present (Inst_Node) then
1863 Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
1865 -- If there is an immediately visible homonym of the operator
1866 -- and the declaration has a default, this is worth a warning
1867 -- because the user probably did not intend to get the pre-
1868 -- defined operator, visible in the generic declaration. To
1869 -- find if there is an intended candidate, analyze the renaming
1870 -- again in the current context.
1872 elsif Scope (Old_S) = Standard_Standard
1873 and then Present (Default_Name (Inst_Node))
1876 Decl : constant Node_Id := New_Copy_Tree (N);
1880 Set_Entity (Name (Decl), Empty);
1881 Analyze (Name (Decl));
1883 Find_Renamed_Entity (Decl, Name (Decl), New_S, True);
1886 and then In_Open_Scopes (Scope (Hidden))
1887 and then Is_Immediately_Visible (Hidden)
1888 and then Comes_From_Source (Hidden)
1889 and then Hidden /= Old_S
1891 Error_Msg_Sloc := Sloc (Hidden);
1892 Error_Msg_N ("?default subprogram is resolved " &
1893 "in the generic declaration " &
1894 "(RM 12.6(17))", N);
1895 Error_Msg_NE ("\?and will not use & #", N, Hidden);
1903 New_S := Analyze_Subprogram_Specification (Spec);
1907 -- Renamed entity must be analyzed first, to avoid being hidden by
1908 -- new name (which might be the same in a generic instance).
1912 -- The renaming defines a new overloaded entity, which is analyzed
1913 -- like a subprogram declaration.
1915 New_S := Analyze_Subprogram_Specification (Spec);
1918 if Current_Scope /= Standard_Standard then
1919 Set_Is_Pure (New_S, Is_Pure (Current_Scope));
1922 Rename_Spec := Find_Corresponding_Spec (N);
1924 -- Case of Renaming_As_Body
1926 if Present (Rename_Spec) then
1928 -- Renaming declaration is the completion of the declaration of
1929 -- Rename_Spec. We build an actual body for it at the freezing point.
1931 Set_Corresponding_Spec (N, Rename_Spec);
1933 -- Deal with special case of stream functions of abstract types
1936 if Nkind (Unit_Declaration_Node (Rename_Spec)) =
1937 N_Abstract_Subprogram_Declaration
1939 -- Input stream functions are abstract if the object type is
1940 -- abstract. Similarly, all default stream functions for an
1941 -- interface type are abstract. However, these subprograms may
1942 -- receive explicit declarations in representation clauses, making
1943 -- the attribute subprograms usable as defaults in subsequent
1945 -- In this case we rewrite the declaration to make the subprogram
1946 -- non-abstract. We remove the previous declaration, and insert
1947 -- the new one at the point of the renaming, to prevent premature
1948 -- access to unfrozen types. The new declaration reuses the
1949 -- specification of the previous one, and must not be analyzed.
1952 (Is_Primitive (Entity (Nam))
1954 Is_Abstract_Type (Find_Dispatching_Type (Entity (Nam))));
1956 Old_Decl : constant Node_Id :=
1957 Unit_Declaration_Node (Rename_Spec);
1958 New_Decl : constant Node_Id :=
1959 Make_Subprogram_Declaration (Sloc (N),
1961 Relocate_Node (Specification (Old_Decl)));
1964 Insert_After (N, New_Decl);
1965 Set_Is_Abstract_Subprogram (Rename_Spec, False);
1966 Set_Analyzed (New_Decl);
1970 Set_Corresponding_Body (Unit_Declaration_Node (Rename_Spec), New_S);
1972 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
1973 Error_Msg_N ("(Ada 83) renaming cannot serve as a body", N);
1976 Set_Convention (New_S, Convention (Rename_Spec));
1977 Check_Fully_Conformant (New_S, Rename_Spec);
1978 Set_Public_Status (New_S);
1980 -- The specification does not introduce new formals, but only
1981 -- repeats the formals of the original subprogram declaration.
1982 -- For cross-reference purposes, and for refactoring tools, we
1983 -- treat the formals of the renaming declaration as body formals.
1985 Reference_Body_Formals (Rename_Spec, New_S);
1987 -- Indicate that the entity in the declaration functions like the
1988 -- corresponding body, and is not a new entity. The body will be
1989 -- constructed later at the freeze point, so indicate that the
1990 -- completion has not been seen yet.
1992 Set_Ekind (New_S, E_Subprogram_Body);
1993 New_S := Rename_Spec;
1994 Set_Has_Completion (Rename_Spec, False);
1996 -- Ada 2005: check overriding indicator
1998 if Present (Overridden_Operation (Rename_Spec)) then
1999 if Must_Not_Override (Specification (N)) then
2001 ("subprogram& overrides inherited operation",
2004 Style_Check and then not Must_Override (Specification (N))
2006 Style.Missing_Overriding (N, Rename_Spec);
2009 elsif Must_Override (Specification (N)) then
2010 Error_Msg_NE ("subprogram& is not overriding", N, Rename_Spec);
2013 -- Normal subprogram renaming (not renaming as body)
2016 Generate_Definition (New_S);
2017 New_Overloaded_Entity (New_S);
2019 if Is_Entity_Name (Nam)
2020 and then Is_Intrinsic_Subprogram (Entity (Nam))
2024 Check_Delayed_Subprogram (New_S);
2028 -- There is no need for elaboration checks on the new entity, which may
2029 -- be called before the next freezing point where the body will appear.
2030 -- Elaboration checks refer to the real entity, not the one created by
2031 -- the renaming declaration.
2033 Set_Kill_Elaboration_Checks (New_S, True);
2035 if Etype (Nam) = Any_Type then
2036 Set_Has_Completion (New_S);
2039 elsif Nkind (Nam) = N_Selected_Component then
2041 -- A prefix of the form A.B can designate an entry of task A, a
2042 -- protected operation of protected object A, or finally a primitive
2043 -- operation of object A. In the later case, A is an object of some
2044 -- tagged type, or an access type that denotes one such. To further
2045 -- distinguish these cases, note that the scope of a task entry or
2046 -- protected operation is type of the prefix.
2048 -- The prefix could be an overloaded function call that returns both
2049 -- kinds of operations. This overloading pathology is left to the
2050 -- dedicated reader ???
2053 T : constant Entity_Id := Etype (Prefix (Nam));
2062 Is_Tagged_Type (Designated_Type (T))))
2063 and then Scope (Entity (Selector_Name (Nam))) /= T
2065 Analyze_Renamed_Primitive_Operation
2066 (N, New_S, Present (Rename_Spec));
2070 -- Renamed entity is an entry or protected operation. For those
2071 -- cases an explicit body is built (at the point of freezing of
2072 -- this entity) that contains a call to the renamed entity.
2074 -- This is not allowed for renaming as body if the renamed
2075 -- spec is already frozen (see RM 8.5.4(5) for details).
2077 if Present (Rename_Spec)
2078 and then Is_Frozen (Rename_Spec)
2081 ("renaming-as-body cannot rename entry as subprogram", N);
2083 ("\since & is already frozen (RM 8.5.4(5))",
2086 Analyze_Renamed_Entry (N, New_S, Present (Rename_Spec));
2093 elsif Nkind (Nam) = N_Explicit_Dereference then
2095 -- Renamed entity is designated by access_to_subprogram expression.
2096 -- Must build body to encapsulate call, as in the entry case.
2098 Analyze_Renamed_Dereference (N, New_S, Present (Rename_Spec));
2101 elsif Nkind (Nam) = N_Indexed_Component then
2102 Analyze_Renamed_Family_Member (N, New_S, Present (Rename_Spec));
2105 elsif Nkind (Nam) = N_Character_Literal then
2106 Analyze_Renamed_Character (N, New_S, Present (Rename_Spec));
2109 elsif not Is_Entity_Name (Nam)
2110 or else not Is_Overloadable (Entity (Nam))
2112 Error_Msg_N ("expect valid subprogram name in renaming", N);
2116 -- Find the renamed entity that matches the given specification. Disable
2117 -- Ada_83 because there is no requirement of full conformance between
2118 -- renamed entity and new entity, even though the same circuit is used.
2120 -- This is a bit of a kludge, which introduces a really irregular use of
2121 -- Ada_Version[_Explicit]. Would be nice to find cleaner way to do this
2124 Ada_Version := Ada_Version_Type'Max (Ada_Version, Ada_95);
2125 Ada_Version_Explicit := Ada_Version;
2128 Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
2130 -- The visible operation may be an inherited abstract operation that
2131 -- was overridden in the private part, in which case a call will
2132 -- dispatch to the overriding operation. Use the overriding one in
2133 -- the renaming declaration, to prevent spurious errors below.
2135 if Is_Overloadable (Old_S)
2136 and then Is_Abstract_Subprogram (Old_S)
2137 and then No (DTC_Entity (Old_S))
2138 and then Present (Alias (Old_S))
2139 and then not Is_Abstract_Subprogram (Alias (Old_S))
2140 and then Present (Overridden_Operation (Alias (Old_S)))
2142 Old_S := Alias (Old_S);
2145 -- When the renamed subprogram is overloaded and used as an actual
2146 -- of a generic, its entity is set to the first available homonym.
2147 -- We must first disambiguate the name, then set the proper entity.
2150 and then Is_Overloaded (Nam)
2152 Set_Entity (Nam, Old_S);
2156 -- Most common case: subprogram renames subprogram. No body is generated
2157 -- in this case, so we must indicate the declaration is complete as is.
2158 -- and inherit various attributes of the renamed subprogram.
2160 if No (Rename_Spec) then
2161 Set_Has_Completion (New_S);
2162 Set_Is_Imported (New_S, Is_Imported (Entity (Nam)));
2163 Set_Is_Pure (New_S, Is_Pure (Entity (Nam)));
2164 Set_Is_Preelaborated (New_S, Is_Preelaborated (Entity (Nam)));
2166 -- Ada 2005 (AI-423): Check the consistency of null exclusions
2167 -- between a subprogram and its correct renaming.
2169 -- Note: the Any_Id check is a guard that prevents compiler crashes
2170 -- when performing a null exclusion check between a renaming and a
2171 -- renamed subprogram that has been found to be illegal.
2173 if Ada_Version >= Ada_2005
2174 and then Entity (Nam) /= Any_Id
2176 Check_Null_Exclusion
2178 Sub => Entity (Nam));
2181 -- Enforce the Ada 2005 rule that the renamed entity cannot require
2182 -- overriding. The flag Requires_Overriding is set very selectively
2183 -- and misses some other illegal cases. The additional conditions
2184 -- checked below are sufficient but not necessary ???
2186 -- The rule does not apply to the renaming generated for an actual
2187 -- subprogram in an instance.
2192 -- Guard against previous errors, and omit renamings of predefined
2195 elsif not Ekind_In (Old_S, E_Function, E_Procedure) then
2198 elsif Requires_Overriding (Old_S)
2200 (Is_Abstract_Subprogram (Old_S)
2201 and then Present (Find_Dispatching_Type (Old_S))
2203 not Is_Abstract_Type (Find_Dispatching_Type (Old_S)))
2206 ("renamed entity cannot be "
2207 & "subprogram that requires overriding (RM 8.5.4 (5.1))", N);
2211 if Old_S /= Any_Id then
2213 and then From_Default (N)
2215 -- This is an implicit reference to the default actual
2217 Generate_Reference (Old_S, Nam, Typ => 'i', Force => True);
2219 Generate_Reference (Old_S, Nam);
2222 -- For a renaming-as-body, require subtype conformance, but if the
2223 -- declaration being completed has not been frozen, then inherit the
2224 -- convention of the renamed subprogram prior to checking conformance
2225 -- (unless the renaming has an explicit convention established; the
2226 -- rule stated in the RM doesn't seem to address this ???).
2228 if Present (Rename_Spec) then
2229 Generate_Reference (Rename_Spec, Defining_Entity (Spec), 'b');
2230 Style.Check_Identifier (Defining_Entity (Spec), Rename_Spec);
2232 if not Is_Frozen (Rename_Spec) then
2233 if not Has_Convention_Pragma (Rename_Spec) then
2234 Set_Convention (New_S, Convention (Old_S));
2237 if Ekind (Old_S) /= E_Operator then
2238 Check_Mode_Conformant (New_S, Old_S, Spec);
2241 if Original_Subprogram (Old_S) = Rename_Spec then
2242 Error_Msg_N ("unfrozen subprogram cannot rename itself ", N);
2245 Check_Subtype_Conformant (New_S, Old_S, Spec);
2248 Check_Frozen_Renaming (N, Rename_Spec);
2250 -- Check explicitly that renamed entity is not intrinsic, because
2251 -- in a generic the renamed body is not built. In this case,
2252 -- the renaming_as_body is a completion.
2254 if Inside_A_Generic then
2255 if Is_Frozen (Rename_Spec)
2256 and then Is_Intrinsic_Subprogram (Old_S)
2259 ("subprogram in renaming_as_body cannot be intrinsic",
2263 Set_Has_Completion (Rename_Spec);
2266 elsif Ekind (Old_S) /= E_Operator then
2267 Check_Mode_Conformant (New_S, Old_S);
2270 and then Error_Posted (New_S)
2272 Error_Msg_NE ("invalid actual subprogram: & #!", N, Old_S);
2276 if No (Rename_Spec) then
2278 -- The parameter profile of the new entity is that of the renamed
2279 -- entity: the subtypes given in the specification are irrelevant.
2281 Inherit_Renamed_Profile (New_S, Old_S);
2283 -- A call to the subprogram is transformed into a call to the
2284 -- renamed entity. This is transitive if the renamed entity is
2285 -- itself a renaming.
2287 if Present (Alias (Old_S)) then
2288 Set_Alias (New_S, Alias (Old_S));
2290 Set_Alias (New_S, Old_S);
2293 -- Note that we do not set Is_Intrinsic_Subprogram if we have a
2294 -- renaming as body, since the entity in this case is not an
2295 -- intrinsic (it calls an intrinsic, but we have a real body for
2296 -- this call, and it is in this body that the required intrinsic
2297 -- processing will take place).
2299 -- Also, if this is a renaming of inequality, the renamed operator
2300 -- is intrinsic, but what matters is the corresponding equality
2301 -- operator, which may be user-defined.
2303 Set_Is_Intrinsic_Subprogram
2305 Is_Intrinsic_Subprogram (Old_S)
2307 (Chars (Old_S) /= Name_Op_Ne
2308 or else Ekind (Old_S) = E_Operator
2310 Is_Intrinsic_Subprogram
2311 (Corresponding_Equality (Old_S))));
2313 if Ekind (Alias (New_S)) = E_Operator then
2314 Set_Has_Delayed_Freeze (New_S, False);
2317 -- If the renaming corresponds to an association for an abstract
2318 -- formal subprogram, then various attributes must be set to
2319 -- indicate that the renaming is an abstract dispatching operation
2320 -- with a controlling type.
2322 if Is_Actual and then Is_Abstract_Subprogram (Formal_Spec) then
2324 -- Mark the renaming as abstract here, so Find_Dispatching_Type
2325 -- see it as corresponding to a generic association for a
2326 -- formal abstract subprogram
2328 Set_Is_Abstract_Subprogram (New_S);
2331 New_S_Ctrl_Type : constant Entity_Id :=
2332 Find_Dispatching_Type (New_S);
2333 Old_S_Ctrl_Type : constant Entity_Id :=
2334 Find_Dispatching_Type (Old_S);
2337 if Old_S_Ctrl_Type /= New_S_Ctrl_Type then
2339 ("actual must be dispatching subprogram for type&",
2340 Nam, New_S_Ctrl_Type);
2343 Set_Is_Dispatching_Operation (New_S);
2344 Check_Controlling_Formals (New_S_Ctrl_Type, New_S);
2346 -- If the actual in the formal subprogram is itself a
2347 -- formal abstract subprogram association, there's no
2348 -- dispatch table component or position to inherit.
2350 if Present (DTC_Entity (Old_S)) then
2351 Set_DTC_Entity (New_S, DTC_Entity (Old_S));
2352 Set_DT_Position (New_S, DT_Position (Old_S));
2360 and then (Old_S = New_S
2361 or else (Nkind (Nam) /= N_Expanded_Name
2362 and then Chars (Old_S) = Chars (New_S)))
2364 Error_Msg_N ("subprogram cannot rename itself", N);
2367 Set_Convention (New_S, Convention (Old_S));
2369 if Is_Abstract_Subprogram (Old_S) then
2370 if Present (Rename_Spec) then
2372 ("a renaming-as-body cannot rename an abstract subprogram",
2374 Set_Has_Completion (Rename_Spec);
2376 Set_Is_Abstract_Subprogram (New_S);
2380 Check_Library_Unit_Renaming (N, Old_S);
2382 -- Pathological case: procedure renames entry in the scope of its
2383 -- task. Entry is given by simple name, but body must be built for
2384 -- procedure. Of course if called it will deadlock.
2386 if Ekind (Old_S) = E_Entry then
2387 Set_Has_Completion (New_S, False);
2388 Set_Alias (New_S, Empty);
2392 Freeze_Before (N, Old_S);
2393 Set_Has_Delayed_Freeze (New_S, False);
2394 Freeze_Before (N, New_S);
2396 -- An abstract subprogram is only allowed as an actual in the case
2397 -- where the formal subprogram is also abstract.
2399 if (Ekind (Old_S) = E_Procedure or else Ekind (Old_S) = E_Function)
2400 and then Is_Abstract_Subprogram (Old_S)
2401 and then not Is_Abstract_Subprogram (Formal_Spec)
2404 ("abstract subprogram not allowed as generic actual", Nam);
2409 -- A common error is to assume that implicit operators for types are
2410 -- defined in Standard, or in the scope of a subtype. In those cases
2411 -- where the renamed entity is given with an expanded name, it is
2412 -- worth mentioning that operators for the type are not declared in
2413 -- the scope given by the prefix.
2415 if Nkind (Nam) = N_Expanded_Name
2416 and then Nkind (Selector_Name (Nam)) = N_Operator_Symbol
2417 and then Scope (Entity (Nam)) = Standard_Standard
2420 T : constant Entity_Id :=
2421 Base_Type (Etype (First_Formal (New_S)));
2423 Error_Msg_Node_2 := Prefix (Nam);
2425 ("operator for type& is not declared in&", Prefix (Nam), T);
2430 ("no visible subprogram matches the specification for&",
2434 if Present (Candidate_Renaming) then
2441 F1 := First_Formal (Candidate_Renaming);
2442 F2 := First_Formal (New_S);
2443 T1 := First_Subtype (Etype (F1));
2445 while Present (F1) and then Present (F2) loop
2450 if Present (F1) and then Present (Default_Value (F1)) then
2451 if Present (Next_Formal (F1)) then
2453 ("\missing specification for &" &
2454 " and other formals with defaults", Spec, F1);
2457 ("\missing specification for &", Spec, F1);
2461 if Nkind (Nam) = N_Operator_Symbol
2462 and then From_Default (N)
2464 Error_Msg_Node_2 := T1;
2466 ("default & on & is not directly visible",
2473 -- Ada 2005 AI 404: if the new subprogram is dispatching, verify that
2474 -- controlling access parameters are known non-null for the renamed
2475 -- subprogram. Test also applies to a subprogram instantiation that
2476 -- is dispatching. Test is skipped if some previous error was detected
2477 -- that set Old_S to Any_Id.
2479 if Ada_Version >= Ada_2005
2480 and then Old_S /= Any_Id
2481 and then not Is_Dispatching_Operation (Old_S)
2482 and then Is_Dispatching_Operation (New_S)
2489 Old_F := First_Formal (Old_S);
2490 New_F := First_Formal (New_S);
2491 while Present (Old_F) loop
2492 if Ekind (Etype (Old_F)) = E_Anonymous_Access_Type
2493 and then Is_Controlling_Formal (New_F)
2494 and then not Can_Never_Be_Null (Old_F)
2496 Error_Msg_N ("access parameter is controlling,", New_F);
2498 ("\corresponding parameter of& "
2499 & "must be explicitly null excluding", New_F, Old_S);
2502 Next_Formal (Old_F);
2503 Next_Formal (New_F);
2508 -- A useful warning, suggested by Ada Bug Finder (Ada-Europe 2005)
2509 -- is to warn if an operator is being renamed as a different operator.
2510 -- If the operator is predefined, examine the kind of the entity, not
2511 -- the abbreviated declaration in Standard.
2513 if Comes_From_Source (N)
2514 and then Present (Old_S)
2516 (Nkind (Old_S) = N_Defining_Operator_Symbol
2517 or else Ekind (Old_S) = E_Operator)
2518 and then Nkind (New_S) = N_Defining_Operator_Symbol
2519 and then Chars (Old_S) /= Chars (New_S)
2522 ("?& is being renamed as a different operator", N, Old_S);
2525 -- Check for renaming of obsolescent subprogram
2527 Check_Obsolescent_2005_Entity (Entity (Nam), Nam);
2529 -- Another warning or some utility: if the new subprogram as the same
2530 -- name as the old one, the old one is not hidden by an outer homograph,
2531 -- the new one is not a public symbol, and the old one is otherwise
2532 -- directly visible, the renaming is superfluous.
2534 if Chars (Old_S) = Chars (New_S)
2535 and then Comes_From_Source (N)
2536 and then Scope (Old_S) /= Standard_Standard
2537 and then Warn_On_Redundant_Constructs
2539 (Is_Immediately_Visible (Old_S)
2540 or else Is_Potentially_Use_Visible (Old_S))
2541 and then Is_Overloadable (Current_Scope)
2542 and then Chars (Current_Scope) /= Chars (Old_S)
2545 ("?redundant renaming, entity is directly visible", Name (N));
2548 Ada_Version := Save_AV;
2549 Ada_Version_Explicit := Save_AV_Exp;
2550 end Analyze_Subprogram_Renaming;
2552 -------------------------
2553 -- Analyze_Use_Package --
2554 -------------------------
2556 -- Resolve the package names in the use clause, and make all the visible
2557 -- entities defined in the package potentially use-visible. If the package
2558 -- is already in use from a previous use clause, its visible entities are
2559 -- already use-visible. In that case, mark the occurrence as a redundant
2560 -- use. If the package is an open scope, i.e. if the use clause occurs
2561 -- within the package itself, ignore it.
2563 procedure Analyze_Use_Package (N : Node_Id) is
2564 Pack_Name : Node_Id;
2567 -- Start of processing for Analyze_Use_Package
2570 -- Use package is not allowed in SPARK or ALFA
2572 if Formal_Verification_Mode then
2573 Error_Msg_F ("|~~use clause is not allowed", N);
2577 -- Proceed with analysis
2579 Set_Hidden_By_Use_Clause (N, No_Elist);
2581 -- Use clause is not allowed in a spec of a predefined package
2582 -- declaration except that packages whose file name starts a-n are OK
2583 -- (these are children of Ada.Numerics, and such packages are never
2584 -- loaded by Rtsfind).
2586 if Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
2587 and then Name_Buffer (1 .. 3) /= "a-n"
2589 Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
2591 Error_Msg_N ("use clause not allowed in predefined spec", N);
2594 -- Chain clause to list of use clauses in current scope
2596 if Nkind (Parent (N)) /= N_Compilation_Unit then
2597 Chain_Use_Clause (N);
2600 -- Loop through package names to identify referenced packages
2602 Pack_Name := First (Names (N));
2603 while Present (Pack_Name) loop
2604 Analyze (Pack_Name);
2606 if Nkind (Parent (N)) = N_Compilation_Unit
2607 and then Nkind (Pack_Name) = N_Expanded_Name
2613 Pref := Prefix (Pack_Name);
2614 while Nkind (Pref) = N_Expanded_Name loop
2615 Pref := Prefix (Pref);
2618 if Entity (Pref) = Standard_Standard then
2620 ("predefined package Standard cannot appear"
2621 & " in a context clause", Pref);
2629 -- Loop through package names to mark all entities as potentially
2632 Pack_Name := First (Names (N));
2633 while Present (Pack_Name) loop
2634 if Is_Entity_Name (Pack_Name) then
2635 Pack := Entity (Pack_Name);
2637 if Ekind (Pack) /= E_Package
2638 and then Etype (Pack) /= Any_Type
2640 if Ekind (Pack) = E_Generic_Package then
2641 Error_Msg_N -- CODEFIX
2642 ("a generic package is not allowed in a use clause",
2645 Error_Msg_N ("& is not a usable package", Pack_Name);
2649 if Nkind (Parent (N)) = N_Compilation_Unit then
2650 Check_In_Previous_With_Clause (N, Pack_Name);
2653 if Applicable_Use (Pack_Name) then
2654 Use_One_Package (Pack, N);
2658 -- Report error because name denotes something other than a package
2661 Error_Msg_N ("& is not a package", Pack_Name);
2666 end Analyze_Use_Package;
2668 ----------------------
2669 -- Analyze_Use_Type --
2670 ----------------------
2672 procedure Analyze_Use_Type (N : Node_Id) is
2677 Set_Hidden_By_Use_Clause (N, No_Elist);
2679 -- Chain clause to list of use clauses in current scope
2681 if Nkind (Parent (N)) /= N_Compilation_Unit then
2682 Chain_Use_Clause (N);
2685 -- If the Used_Operations list is already initialized, the clause has
2686 -- been analyzed previously, and it is begin reinstalled, for example
2687 -- when the clause appears in a package spec and we are compiling the
2688 -- corresponding package body. In that case, make the entities on the
2689 -- existing list use_visible, and mark the corresponding types In_Use.
2691 if Present (Used_Operations (N)) then
2697 Mark := First (Subtype_Marks (N));
2698 while Present (Mark) loop
2699 Use_One_Type (Mark, Installed => True);
2703 Elmt := First_Elmt (Used_Operations (N));
2704 while Present (Elmt) loop
2705 Set_Is_Potentially_Use_Visible (Node (Elmt));
2713 -- Otherwise, create new list and attach to it the operations that
2714 -- are made use-visible by the clause.
2716 Set_Used_Operations (N, New_Elmt_List);
2717 Id := First (Subtype_Marks (N));
2718 while Present (Id) loop
2722 if E /= Any_Type then
2725 if Nkind (Parent (N)) = N_Compilation_Unit then
2726 if Nkind (Id) = N_Identifier then
2727 Error_Msg_N ("type is not directly visible", Id);
2729 elsif Is_Child_Unit (Scope (E))
2730 and then Scope (E) /= System_Aux_Id
2732 Check_In_Previous_With_Clause (N, Prefix (Id));
2737 -- If the use_type_clause appears in a compilation unit context,
2738 -- check whether it comes from a unit that may appear in a
2739 -- limited_with_clause, for a better error message.
2741 if Nkind (Parent (N)) = N_Compilation_Unit
2742 and then Nkind (Id) /= N_Identifier
2748 function Mentioned (Nam : Node_Id) return Boolean;
2749 -- Check whether the prefix of expanded name for the type
2750 -- appears in the prefix of some limited_with_clause.
2756 function Mentioned (Nam : Node_Id) return Boolean is
2758 return Nkind (Name (Item)) = N_Selected_Component
2760 Chars (Prefix (Name (Item))) = Chars (Nam);
2764 Pref := Prefix (Id);
2765 Item := First (Context_Items (Parent (N)));
2767 while Present (Item) and then Item /= N loop
2768 if Nkind (Item) = N_With_Clause
2769 and then Limited_Present (Item)
2770 and then Mentioned (Pref)
2773 (Get_Msg_Id, "premature usage of incomplete type");
2784 end Analyze_Use_Type;
2786 --------------------
2787 -- Applicable_Use --
2788 --------------------
2790 function Applicable_Use (Pack_Name : Node_Id) return Boolean is
2791 Pack : constant Entity_Id := Entity (Pack_Name);
2794 if In_Open_Scopes (Pack) then
2795 if Warn_On_Redundant_Constructs
2796 and then Pack = Current_Scope
2798 Error_Msg_NE -- CODEFIX
2799 ("& is already use-visible within itself?", Pack_Name, Pack);
2804 elsif In_Use (Pack) then
2805 Note_Redundant_Use (Pack_Name);
2808 elsif Present (Renamed_Object (Pack))
2809 and then In_Use (Renamed_Object (Pack))
2811 Note_Redundant_Use (Pack_Name);
2819 ------------------------
2820 -- Attribute_Renaming --
2821 ------------------------
2823 procedure Attribute_Renaming (N : Node_Id) is
2824 Loc : constant Source_Ptr := Sloc (N);
2825 Nam : constant Node_Id := Name (N);
2826 Spec : constant Node_Id := Specification (N);
2827 New_S : constant Entity_Id := Defining_Unit_Name (Spec);
2828 Aname : constant Name_Id := Attribute_Name (Nam);
2830 Form_Num : Nat := 0;
2831 Expr_List : List_Id := No_List;
2833 Attr_Node : Node_Id;
2834 Body_Node : Node_Id;
2835 Param_Spec : Node_Id;
2838 Generate_Definition (New_S);
2840 -- This procedure is called in the context of subprogram renaming, and
2841 -- thus the attribute must be one that is a subprogram. All of those
2842 -- have at least one formal parameter, with the singular exception of
2843 -- AST_Entry (which is a real oddity, it is odd that this can be renamed
2846 if not Is_Non_Empty_List (Parameter_Specifications (Spec)) then
2847 if Aname /= Name_AST_Entry then
2849 ("subprogram renaming an attribute must have formals", N);
2854 Param_Spec := First (Parameter_Specifications (Spec));
2855 while Present (Param_Spec) loop
2856 Form_Num := Form_Num + 1;
2858 if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
2859 Find_Type (Parameter_Type (Param_Spec));
2861 -- The profile of the new entity denotes the base type (s) of
2862 -- the types given in the specification. For access parameters
2863 -- there are no subtypes involved.
2865 Rewrite (Parameter_Type (Param_Spec),
2867 (Base_Type (Entity (Parameter_Type (Param_Spec))), Loc));
2870 if No (Expr_List) then
2871 Expr_List := New_List;
2874 Append_To (Expr_List,
2875 Make_Identifier (Loc,
2876 Chars => Chars (Defining_Identifier (Param_Spec))));
2878 -- The expressions in the attribute reference are not freeze
2879 -- points. Neither is the attribute as a whole, see below.
2881 Set_Must_Not_Freeze (Last (Expr_List));
2886 -- Immediate error if too many formals. Other mismatches in number or
2887 -- types of parameters are detected when we analyze the body of the
2888 -- subprogram that we construct.
2890 if Form_Num > 2 then
2891 Error_Msg_N ("too many formals for attribute", N);
2893 -- Error if the attribute reference has expressions that look like
2894 -- formal parameters.
2896 elsif Present (Expressions (Nam)) then
2897 Error_Msg_N ("illegal expressions in attribute reference", Nam);
2900 Aname = Name_Compose or else
2901 Aname = Name_Exponent or else
2902 Aname = Name_Leading_Part or else
2903 Aname = Name_Pos or else
2904 Aname = Name_Round or else
2905 Aname = Name_Scaling or else
2908 if Nkind (N) = N_Subprogram_Renaming_Declaration
2909 and then Present (Corresponding_Formal_Spec (N))
2912 ("generic actual cannot be attribute involving universal type",
2916 ("attribute involving a universal type cannot be renamed",
2921 -- AST_Entry is an odd case. It doesn't really make much sense to allow
2922 -- it to be renamed, but that's the DEC rule, so we have to do it right.
2923 -- The point is that the AST_Entry call should be made now, and what the
2924 -- function will return is the returned value.
2926 -- Note that there is no Expr_List in this case anyway
2928 if Aname = Name_AST_Entry then
2930 Ent : constant Entity_Id := Make_Temporary (Loc, 'R', Nam);
2935 Make_Object_Declaration (Loc,
2936 Defining_Identifier => Ent,
2937 Object_Definition =>
2938 New_Occurrence_Of (RTE (RE_AST_Handler), Loc),
2940 Constant_Present => True);
2942 Set_Assignment_OK (Decl, True);
2943 Insert_Action (N, Decl);
2944 Attr_Node := Make_Identifier (Loc, Chars (Ent));
2947 -- For all other attributes, we rewrite the attribute node to have
2948 -- a list of expressions corresponding to the subprogram formals.
2949 -- A renaming declaration is not a freeze point, and the analysis of
2950 -- the attribute reference should not freeze the type of the prefix.
2954 Make_Attribute_Reference (Loc,
2955 Prefix => Prefix (Nam),
2956 Attribute_Name => Aname,
2957 Expressions => Expr_List);
2959 Set_Must_Not_Freeze (Attr_Node);
2960 Set_Must_Not_Freeze (Prefix (Nam));
2963 -- Case of renaming a function
2965 if Nkind (Spec) = N_Function_Specification then
2966 if Is_Procedure_Attribute_Name (Aname) then
2967 Error_Msg_N ("attribute can only be renamed as procedure", Nam);
2971 Find_Type (Result_Definition (Spec));
2972 Rewrite (Result_Definition (Spec),
2974 Base_Type (Entity (Result_Definition (Spec))), Loc));
2977 Make_Subprogram_Body (Loc,
2978 Specification => Spec,
2979 Declarations => New_List,
2980 Handled_Statement_Sequence =>
2981 Make_Handled_Sequence_Of_Statements (Loc,
2982 Statements => New_List (
2983 Make_Simple_Return_Statement (Loc,
2984 Expression => Attr_Node))));
2986 -- Case of renaming a procedure
2989 if not Is_Procedure_Attribute_Name (Aname) then
2990 Error_Msg_N ("attribute can only be renamed as function", Nam);
2995 Make_Subprogram_Body (Loc,
2996 Specification => Spec,
2997 Declarations => New_List,
2998 Handled_Statement_Sequence =>
2999 Make_Handled_Sequence_Of_Statements (Loc,
3000 Statements => New_List (Attr_Node)));
3003 -- In case of tagged types we add the body of the generated function to
3004 -- the freezing actions of the type (because in the general case such
3005 -- type is still not frozen). We exclude from this processing generic
3006 -- formal subprograms found in instantiations and AST_Entry renamings.
3008 -- We must exclude VM targets because entity AST_Handler is defined in
3009 -- package System.Aux_Dec which is not available in those platforms.
3011 if VM_Target = No_VM
3012 and then not Present (Corresponding_Formal_Spec (N))
3013 and then Etype (Nam) /= RTE (RE_AST_Handler)
3016 P : constant Entity_Id := Prefix (Nam);
3021 if Is_Tagged_Type (Etype (P)) then
3022 Ensure_Freeze_Node (Etype (P));
3023 Append_Freeze_Action (Etype (P), Body_Node);
3025 Rewrite (N, Body_Node);
3027 Set_Etype (New_S, Base_Type (Etype (New_S)));
3031 -- Generic formal subprograms or AST_Handler renaming
3034 Rewrite (N, Body_Node);
3036 Set_Etype (New_S, Base_Type (Etype (New_S)));
3039 if Is_Compilation_Unit (New_S) then
3041 ("a library unit can only rename another library unit", N);
3044 -- We suppress elaboration warnings for the resulting entity, since
3045 -- clearly they are not needed, and more particularly, in the case
3046 -- of a generic formal subprogram, the resulting entity can appear
3047 -- after the instantiation itself, and thus look like a bogus case
3048 -- of access before elaboration.
3050 Set_Suppress_Elaboration_Warnings (New_S);
3052 end Attribute_Renaming;
3054 ----------------------
3055 -- Chain_Use_Clause --
3056 ----------------------
3058 procedure Chain_Use_Clause (N : Node_Id) is
3060 Level : Int := Scope_Stack.Last;
3063 if not Is_Compilation_Unit (Current_Scope)
3064 or else not Is_Child_Unit (Current_Scope)
3066 null; -- Common case
3068 elsif Defining_Entity (Parent (N)) = Current_Scope then
3069 null; -- Common case for compilation unit
3072 -- If declaration appears in some other scope, it must be in some
3073 -- parent unit when compiling a child.
3075 Pack := Defining_Entity (Parent (N));
3076 if not In_Open_Scopes (Pack) then
3077 null; -- default as well
3080 -- Find entry for parent unit in scope stack
3082 while Scope_Stack.Table (Level).Entity /= Pack loop
3088 Set_Next_Use_Clause (N,
3089 Scope_Stack.Table (Level).First_Use_Clause);
3090 Scope_Stack.Table (Level).First_Use_Clause := N;
3091 end Chain_Use_Clause;
3093 ---------------------------
3094 -- Check_Frozen_Renaming --
3095 ---------------------------
3097 procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id) is
3103 and then not Has_Completion (Subp)
3107 (Parent (Declaration_Node (Subp)), Defining_Entity (N));
3109 if Is_Entity_Name (Name (N)) then
3110 Old_S := Entity (Name (N));
3112 if not Is_Frozen (Old_S)
3113 and then Operating_Mode /= Check_Semantics
3115 Append_Freeze_Action (Old_S, B_Node);
3117 Insert_After (N, B_Node);
3121 if Is_Intrinsic_Subprogram (Old_S)
3122 and then not In_Instance
3125 ("subprogram used in renaming_as_body cannot be intrinsic",
3130 Insert_After (N, B_Node);
3134 end Check_Frozen_Renaming;
3136 -------------------------------
3137 -- Set_Entity_Or_Discriminal --
3138 -------------------------------
3140 procedure Set_Entity_Or_Discriminal (N : Node_Id; E : Entity_Id) is
3144 -- If the entity is not a discriminant, or else expansion is disabled,
3145 -- simply set the entity.
3147 if not In_Spec_Expression
3148 or else Ekind (E) /= E_Discriminant
3149 or else Inside_A_Generic
3151 Set_Entity_With_Style_Check (N, E);
3153 -- The replacement of a discriminant by the corresponding discriminal
3154 -- is not done for a task discriminant that appears in a default
3155 -- expression of an entry parameter. See Exp_Ch2.Expand_Discriminant
3156 -- for details on their handling.
3158 elsif Is_Concurrent_Type (Scope (E)) then
3162 and then not Nkind_In (P, N_Parameter_Specification,
3163 N_Component_Declaration)
3169 and then Nkind (P) = N_Parameter_Specification
3174 Set_Entity (N, Discriminal (E));
3177 -- Otherwise, this is a discriminant in a context in which
3178 -- it is a reference to the corresponding parameter of the
3179 -- init proc for the enclosing type.
3182 Set_Entity (N, Discriminal (E));
3184 end Set_Entity_Or_Discriminal;
3186 -----------------------------------
3187 -- Check_In_Previous_With_Clause --
3188 -----------------------------------
3190 procedure Check_In_Previous_With_Clause
3194 Pack : constant Entity_Id := Entity (Original_Node (Nam));
3199 Item := First (Context_Items (Parent (N)));
3201 while Present (Item)
3204 if Nkind (Item) = N_With_Clause
3206 -- Protect the frontend against previous critical errors
3208 and then Nkind (Name (Item)) /= N_Selected_Component
3209 and then Entity (Name (Item)) = Pack
3213 -- Find root library unit in with_clause
3215 while Nkind (Par) = N_Expanded_Name loop
3216 Par := Prefix (Par);
3219 if Is_Child_Unit (Entity (Original_Node (Par))) then
3220 Error_Msg_NE ("& is not directly visible", Par, Entity (Par));
3229 -- On exit, package is not mentioned in a previous with_clause.
3230 -- Check if its prefix is.
3232 if Nkind (Nam) = N_Expanded_Name then
3233 Check_In_Previous_With_Clause (N, Prefix (Nam));
3235 elsif Pack /= Any_Id then
3236 Error_Msg_NE ("& is not visible", Nam, Pack);
3238 end Check_In_Previous_With_Clause;
3240 ---------------------------------
3241 -- Check_Library_Unit_Renaming --
3242 ---------------------------------
3244 procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id) is
3248 if Nkind (Parent (N)) /= N_Compilation_Unit then
3251 -- Check for library unit. Note that we used to check for the scope
3252 -- being Standard here, but that was wrong for Standard itself.
3254 elsif not Is_Compilation_Unit (Old_E)
3255 and then not Is_Child_Unit (Old_E)
3257 Error_Msg_N ("renamed unit must be a library unit", Name (N));
3259 -- Entities defined in Standard (operators and boolean literals) cannot
3260 -- be renamed as library units.
3262 elsif Scope (Old_E) = Standard_Standard
3263 and then Sloc (Old_E) = Standard_Location
3265 Error_Msg_N ("renamed unit must be a library unit", Name (N));
3267 elsif Present (Parent_Spec (N))
3268 and then Nkind (Unit (Parent_Spec (N))) = N_Generic_Package_Declaration
3269 and then not Is_Child_Unit (Old_E)
3272 ("renamed unit must be a child unit of generic parent", Name (N));
3274 elsif Nkind (N) in N_Generic_Renaming_Declaration
3275 and then Nkind (Name (N)) = N_Expanded_Name
3276 and then Is_Generic_Instance (Entity (Prefix (Name (N))))
3277 and then Is_Generic_Unit (Old_E)
3280 ("renamed generic unit must be a library unit", Name (N));
3282 elsif Is_Package_Or_Generic_Package (Old_E) then
3284 -- Inherit categorization flags
3286 New_E := Defining_Entity (N);
3287 Set_Is_Pure (New_E, Is_Pure (Old_E));
3288 Set_Is_Preelaborated (New_E, Is_Preelaborated (Old_E));
3289 Set_Is_Remote_Call_Interface (New_E,
3290 Is_Remote_Call_Interface (Old_E));
3291 Set_Is_Remote_Types (New_E, Is_Remote_Types (Old_E));
3292 Set_Is_Shared_Passive (New_E, Is_Shared_Passive (Old_E));
3294 end Check_Library_Unit_Renaming;
3300 procedure End_Scope is
3306 Id := First_Entity (Current_Scope);
3307 while Present (Id) loop
3308 -- An entity in the current scope is not necessarily the first one
3309 -- on its homonym chain. Find its predecessor if any,
3310 -- If it is an internal entity, it will not be in the visibility
3311 -- chain altogether, and there is nothing to unchain.
3313 if Id /= Current_Entity (Id) then
3314 Prev := Current_Entity (Id);
3315 while Present (Prev)
3316 and then Present (Homonym (Prev))
3317 and then Homonym (Prev) /= Id
3319 Prev := Homonym (Prev);
3322 -- Skip to end of loop if Id is not in the visibility chain
3324 if No (Prev) or else Homonym (Prev) /= Id then
3332 Set_Is_Immediately_Visible (Id, False);
3334 Outer := Homonym (Id);
3335 while Present (Outer) and then Scope (Outer) = Current_Scope loop
3336 Outer := Homonym (Outer);
3339 -- Reset homonym link of other entities, but do not modify link
3340 -- between entities in current scope, so that the back-end can have
3341 -- a proper count of local overloadings.
3344 Set_Name_Entity_Id (Chars (Id), Outer);
3346 elsif Scope (Prev) /= Scope (Id) then
3347 Set_Homonym (Prev, Outer);
3354 -- If the scope generated freeze actions, place them before the
3355 -- current declaration and analyze them. Type declarations and
3356 -- the bodies of initialization procedures can generate such nodes.
3357 -- We follow the parent chain until we reach a list node, which is
3358 -- the enclosing list of declarations. If the list appears within
3359 -- a protected definition, move freeze nodes outside the protected
3363 (Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions)
3367 L : constant List_Id := Scope_Stack.Table
3368 (Scope_Stack.Last).Pending_Freeze_Actions;
3371 if Is_Itype (Current_Scope) then
3372 Decl := Associated_Node_For_Itype (Current_Scope);
3374 Decl := Parent (Current_Scope);
3379 while not (Is_List_Member (Decl))
3380 or else Nkind_In (Parent (Decl), N_Protected_Definition,
3383 Decl := Parent (Decl);
3386 Insert_List_Before_And_Analyze (Decl, L);
3395 ---------------------
3396 -- End_Use_Clauses --
3397 ---------------------
3399 procedure End_Use_Clauses (Clause : Node_Id) is
3403 -- Remove Use_Type clauses first, because they affect the
3404 -- visibility of operators in subsequent used packages.
3407 while Present (U) loop
3408 if Nkind (U) = N_Use_Type_Clause then
3412 Next_Use_Clause (U);
3416 while Present (U) loop
3417 if Nkind (U) = N_Use_Package_Clause then
3418 End_Use_Package (U);
3421 Next_Use_Clause (U);
3423 end End_Use_Clauses;
3425 ---------------------
3426 -- End_Use_Package --
3427 ---------------------
3429 procedure End_Use_Package (N : Node_Id) is
3430 Pack_Name : Node_Id;
3435 function Is_Primitive_Operator_In_Use
3437 F : Entity_Id) return Boolean;
3438 -- Check whether Op is a primitive operator of a use-visible type
3440 ----------------------------------
3441 -- Is_Primitive_Operator_In_Use --
3442 ----------------------------------
3444 function Is_Primitive_Operator_In_Use
3446 F : Entity_Id) return Boolean
3448 T : constant Entity_Id := Etype (F);
3451 or else Present (Current_Use_Clause (Base_Type (T))))
3452 and then Scope (T) = Scope (Op);
3453 end Is_Primitive_Operator_In_Use;
3455 -- Start of processing for End_Use_Package
3458 Pack_Name := First (Names (N));
3459 while Present (Pack_Name) loop
3461 -- Test that Pack_Name actually denotes a package before processing
3463 if Is_Entity_Name (Pack_Name)
3464 and then Ekind (Entity (Pack_Name)) = E_Package
3466 Pack := Entity (Pack_Name);
3468 if In_Open_Scopes (Pack) then
3471 elsif not Redundant_Use (Pack_Name) then
3472 Set_In_Use (Pack, False);
3473 Set_Current_Use_Clause (Pack, Empty);
3475 Id := First_Entity (Pack);
3476 while Present (Id) loop
3478 -- Preserve use-visibility of operators that are primitive
3479 -- operators of a type that is use-visible through an active
3482 if Nkind (Id) = N_Defining_Operator_Symbol
3484 (Is_Primitive_Operator_In_Use
3485 (Id, First_Formal (Id))
3487 (Present (Next_Formal (First_Formal (Id)))
3489 Is_Primitive_Operator_In_Use
3490 (Id, Next_Formal (First_Formal (Id)))))
3495 Set_Is_Potentially_Use_Visible (Id, False);
3498 if Is_Private_Type (Id)
3499 and then Present (Full_View (Id))
3501 Set_Is_Potentially_Use_Visible (Full_View (Id), False);
3507 if Present (Renamed_Object (Pack)) then
3508 Set_In_Use (Renamed_Object (Pack), False);
3509 Set_Current_Use_Clause (Renamed_Object (Pack), Empty);
3512 if Chars (Pack) = Name_System
3513 and then Scope (Pack) = Standard_Standard
3514 and then Present_System_Aux
3516 Id := First_Entity (System_Aux_Id);
3517 while Present (Id) loop
3518 Set_Is_Potentially_Use_Visible (Id, False);
3520 if Is_Private_Type (Id)
3521 and then Present (Full_View (Id))
3523 Set_Is_Potentially_Use_Visible (Full_View (Id), False);
3529 Set_In_Use (System_Aux_Id, False);
3533 Set_Redundant_Use (Pack_Name, False);
3540 if Present (Hidden_By_Use_Clause (N)) then
3541 Elmt := First_Elmt (Hidden_By_Use_Clause (N));
3542 while Present (Elmt) loop
3544 E : constant Entity_Id := Node (Elmt);
3547 -- Reset either Use_Visibility or Direct_Visibility, depending
3548 -- on how the entity was hidden by the use clause.
3550 if In_Use (Scope (E))
3551 and then Used_As_Generic_Actual (Scope (E))
3553 Set_Is_Potentially_Use_Visible (Node (Elmt));
3555 Set_Is_Immediately_Visible (Node (Elmt));
3562 Set_Hidden_By_Use_Clause (N, No_Elist);
3564 end End_Use_Package;
3570 procedure End_Use_Type (N : Node_Id) is
3575 -- Start of processing for End_Use_Type
3578 Id := First (Subtype_Marks (N));
3579 while Present (Id) loop
3581 -- A call to Rtsfind may occur while analyzing a use_type clause,
3582 -- in which case the type marks are not resolved yet, and there is
3583 -- nothing to remove.
3585 if not Is_Entity_Name (Id) or else No (Entity (Id)) then
3591 if T = Any_Type or else From_With_Type (T) then
3594 -- Note that the use_type clause may mention a subtype of the type
3595 -- whose primitive operations have been made visible. Here as
3596 -- elsewhere, it is the base type that matters for visibility.
3598 elsif In_Open_Scopes (Scope (Base_Type (T))) then
3601 elsif not Redundant_Use (Id) then
3602 Set_In_Use (T, False);
3603 Set_In_Use (Base_Type (T), False);
3604 Set_Current_Use_Clause (T, Empty);
3605 Set_Current_Use_Clause (Base_Type (T), Empty);
3612 if Is_Empty_Elmt_List (Used_Operations (N)) then
3616 Elmt := First_Elmt (Used_Operations (N));
3617 while Present (Elmt) loop
3618 Set_Is_Potentially_Use_Visible (Node (Elmt), False);
3624 ----------------------
3625 -- Find_Direct_Name --
3626 ----------------------
3628 procedure Find_Direct_Name (N : Node_Id) is
3633 Inst : Entity_Id := Empty;
3634 -- Enclosing instance, if any
3636 Homonyms : Entity_Id;
3637 -- Saves start of homonym chain
3639 Nvis_Entity : Boolean;
3640 -- Set True to indicate that there is at least one entity on the homonym
3641 -- chain which, while not visible, is visible enough from the user point
3642 -- of view to warrant an error message of "not visible" rather than
3645 Nvis_Is_Private_Subprg : Boolean := False;
3646 -- Ada 2005 (AI-262): Set True to indicate that a form of Beaujolais
3647 -- effect concerning library subprograms has been detected. Used to
3648 -- generate the precise error message.
3650 function From_Actual_Package (E : Entity_Id) return Boolean;
3651 -- Returns true if the entity is declared in a package that is
3652 -- an actual for a formal package of the current instance. Such an
3653 -- entity requires special handling because it may be use-visible
3654 -- but hides directly visible entities defined outside the instance.
3656 function Is_Actual_Parameter return Boolean;
3657 -- This function checks if the node N is an identifier that is an actual
3658 -- parameter of a procedure call. If so it returns True, otherwise it
3659 -- return False. The reason for this check is that at this stage we do
3660 -- not know what procedure is being called if the procedure might be
3661 -- overloaded, so it is premature to go setting referenced flags or
3662 -- making calls to Generate_Reference. We will wait till Resolve_Actuals
3663 -- for that processing
3665 function Known_But_Invisible (E : Entity_Id) return Boolean;
3666 -- This function determines whether the entity E (which is not
3667 -- visible) can reasonably be considered to be known to the writer
3668 -- of the reference. This is a heuristic test, used only for the
3669 -- purposes of figuring out whether we prefer to complain that an
3670 -- entity is undefined or invisible (and identify the declaration
3671 -- of the invisible entity in the latter case). The point here is
3672 -- that we don't want to complain that something is invisible and
3673 -- then point to something entirely mysterious to the writer.
3675 procedure Nvis_Messages;
3676 -- Called if there are no visible entries for N, but there is at least
3677 -- one non-directly visible, or hidden declaration. This procedure
3678 -- outputs an appropriate set of error messages.
3680 procedure Undefined (Nvis : Boolean);
3681 -- This function is called if the current node has no corresponding
3682 -- visible entity or entities. The value set in Msg indicates whether
3683 -- an error message was generated (multiple error messages for the
3684 -- same variable are generally suppressed, see body for details).
3685 -- Msg is True if an error message was generated, False if not. This
3686 -- value is used by the caller to determine whether or not to output
3687 -- additional messages where appropriate. The parameter is set False
3688 -- to get the message "X is undefined", and True to get the message
3689 -- "X is not visible".
3691 -------------------------
3692 -- From_Actual_Package --
3693 -------------------------
3695 function From_Actual_Package (E : Entity_Id) return Boolean is
3696 Scop : constant Entity_Id := Scope (E);
3700 if not In_Instance then
3703 Inst := Current_Scope;
3704 while Present (Inst)
3705 and then Ekind (Inst) /= E_Package
3706 and then not Is_Generic_Instance (Inst)
3708 Inst := Scope (Inst);
3715 Act := First_Entity (Inst);
3716 while Present (Act) loop
3717 if Ekind (Act) = E_Package then
3719 -- Check for end of actuals list
3721 if Renamed_Object (Act) = Inst then
3724 elsif Present (Associated_Formal_Package (Act))
3725 and then Renamed_Object (Act) = Scop
3727 -- Entity comes from (instance of) formal package
3742 end From_Actual_Package;
3744 -------------------------
3745 -- Is_Actual_Parameter --
3746 -------------------------
3748 function Is_Actual_Parameter return Boolean is
3751 Nkind (N) = N_Identifier
3753 (Nkind (Parent (N)) = N_Procedure_Call_Statement
3755 (Nkind (Parent (N)) = N_Parameter_Association
3756 and then N = Explicit_Actual_Parameter (Parent (N))
3757 and then Nkind (Parent (Parent (N))) =
3758 N_Procedure_Call_Statement));
3759 end Is_Actual_Parameter;
3761 -------------------------
3762 -- Known_But_Invisible --
3763 -------------------------
3765 function Known_But_Invisible (E : Entity_Id) return Boolean is
3766 Fname : File_Name_Type;
3769 -- Entities in Standard are always considered to be known
3771 if Sloc (E) <= Standard_Location then
3774 -- An entity that does not come from source is always considered
3775 -- to be unknown, since it is an artifact of code expansion.
3777 elsif not Comes_From_Source (E) then
3780 -- In gnat internal mode, we consider all entities known
3782 elsif GNAT_Mode then
3786 -- Here we have an entity that is not from package Standard, and
3787 -- which comes from Source. See if it comes from an internal file.
3789 Fname := Unit_File_Name (Get_Source_Unit (E));
3791 -- Case of from internal file
3793 if Is_Internal_File_Name (Fname) then
3795 -- Private part entities in internal files are never considered
3796 -- to be known to the writer of normal application code.
3798 if Is_Hidden (E) then
3802 -- Entities from System packages other than System and
3803 -- System.Storage_Elements are not considered to be known.
3804 -- System.Auxxxx files are also considered known to the user.
3806 -- Should refine this at some point to generally distinguish
3807 -- between known and unknown internal files ???
3809 Get_Name_String (Fname);
3814 Name_Buffer (1 .. 2) /= "s-"
3816 Name_Buffer (3 .. 8) = "stoele"
3818 Name_Buffer (3 .. 5) = "aux";
3820 -- If not an internal file, then entity is definitely known,
3821 -- even if it is in a private part (the message generated will
3822 -- note that it is in a private part)
3827 end Known_But_Invisible;
3833 procedure Nvis_Messages is
3834 Comp_Unit : Node_Id;
3836 Found : Boolean := False;
3837 Hidden : Boolean := False;
3841 -- Ada 2005 (AI-262): Generate a precise error concerning the
3842 -- Beaujolais effect that was previously detected
3844 if Nvis_Is_Private_Subprg then
3846 pragma Assert (Nkind (E2) = N_Defining_Identifier
3847 and then Ekind (E2) = E_Function
3848 and then Scope (E2) = Standard_Standard
3849 and then Has_Private_With (E2));
3851 -- Find the sloc corresponding to the private with'ed unit
3853 Comp_Unit := Cunit (Current_Sem_Unit);
3854 Error_Msg_Sloc := No_Location;
3856 Item := First (Context_Items (Comp_Unit));
3857 while Present (Item) loop
3858 if Nkind (Item) = N_With_Clause
3859 and then Private_Present (Item)
3860 and then Entity (Name (Item)) = E2
3862 Error_Msg_Sloc := Sloc (Item);
3869 pragma Assert (Error_Msg_Sloc /= No_Location);
3871 Error_Msg_N ("(Ada 2005): hidden by private with clause #", N);
3875 Undefined (Nvis => True);
3879 -- First loop does hidden declarations
3882 while Present (Ent) loop
3883 if Is_Potentially_Use_Visible (Ent) then
3885 Error_Msg_N -- CODEFIX
3886 ("multiple use clauses cause hiding!", N);
3890 Error_Msg_Sloc := Sloc (Ent);
3891 Error_Msg_N -- CODEFIX
3892 ("hidden declaration#!", N);
3895 Ent := Homonym (Ent);
3898 -- If we found hidden declarations, then that's enough, don't
3899 -- bother looking for non-visible declarations as well.
3905 -- Second loop does non-directly visible declarations
3908 while Present (Ent) loop
3909 if not Is_Potentially_Use_Visible (Ent) then
3911 -- Do not bother the user with unknown entities
3913 if not Known_But_Invisible (Ent) then
3917 Error_Msg_Sloc := Sloc (Ent);
3919 -- Output message noting that there is a non-visible
3920 -- declaration, distinguishing the private part case.
3922 if Is_Hidden (Ent) then
3923 Error_Msg_N ("non-visible (private) declaration#!", N);
3925 -- If the entity is declared in a generic package, it
3926 -- cannot be visible, so there is no point in adding it
3927 -- to the list of candidates if another homograph from a
3928 -- non-generic package has been seen.
3930 elsif Ekind (Scope (Ent)) = E_Generic_Package
3936 Error_Msg_N -- CODEFIX
3937 ("non-visible declaration#!", N);
3939 if Ekind (Scope (Ent)) /= E_Generic_Package then
3943 if Is_Compilation_Unit (Ent)
3945 Nkind (Parent (Parent (N))) = N_Use_Package_Clause
3947 Error_Msg_Qual_Level := 99;
3948 Error_Msg_NE -- CODEFIX
3949 ("\\missing `WITH &;`", N, Ent);
3950 Error_Msg_Qual_Level := 0;
3953 if Ekind (Ent) = E_Discriminant
3954 and then Present (Corresponding_Discriminant (Ent))
3955 and then Scope (Corresponding_Discriminant (Ent)) =
3959 ("inherited discriminant not allowed here" &
3960 " (RM 3.8 (12), 3.8.1 (6))!", N);
3964 -- Set entity and its containing package as referenced. We
3965 -- can't be sure of this, but this seems a better choice
3966 -- to avoid unused entity messages.
3968 if Comes_From_Source (Ent) then
3969 Set_Referenced (Ent);
3970 Set_Referenced (Cunit_Entity (Get_Source_Unit (Ent)));
3975 Ent := Homonym (Ent);
3984 procedure Undefined (Nvis : Boolean) is
3985 Emsg : Error_Msg_Id;
3988 -- We should never find an undefined internal name. If we do, then
3989 -- see if we have previous errors. If so, ignore on the grounds that
3990 -- it is probably a cascaded message (e.g. a block label from a badly
3991 -- formed block). If no previous errors, then we have a real internal
3992 -- error of some kind so raise an exception.
3994 if Is_Internal_Name (Chars (N)) then
3995 if Total_Errors_Detected /= 0 then
3998 raise Program_Error;
4002 -- A very specialized error check, if the undefined variable is
4003 -- a case tag, and the case type is an enumeration type, check
4004 -- for a possible misspelling, and if so, modify the identifier
4006 -- Named aggregate should also be handled similarly ???
4008 if Nkind (N) = N_Identifier
4009 and then Nkind (Parent (N)) = N_Case_Statement_Alternative
4012 Case_Stm : constant Node_Id := Parent (Parent (N));
4013 Case_Typ : constant Entity_Id := Etype (Expression (Case_Stm));
4018 if Is_Enumeration_Type (Case_Typ)
4019 and then not Is_Standard_Character_Type (Case_Typ)
4021 Lit := First_Literal (Case_Typ);
4022 Get_Name_String (Chars (Lit));
4024 if Chars (Lit) /= Chars (N)
4025 and then Is_Bad_Spelling_Of (Chars (N), Chars (Lit)) then
4026 Error_Msg_Node_2 := Lit;
4027 Error_Msg_N -- CODEFIX
4028 ("& is undefined, assume misspelling of &", N);
4029 Rewrite (N, New_Occurrence_Of (Lit, Sloc (N)));
4033 Lit := Next_Literal (Lit);
4038 -- Normal processing
4040 Set_Entity (N, Any_Id);
4041 Set_Etype (N, Any_Type);
4043 -- We use the table Urefs to keep track of entities for which we
4044 -- have issued errors for undefined references. Multiple errors
4045 -- for a single name are normally suppressed, however we modify
4046 -- the error message to alert the programmer to this effect.
4048 for J in Urefs.First .. Urefs.Last loop
4049 if Chars (N) = Chars (Urefs.Table (J).Node) then
4050 if Urefs.Table (J).Err /= No_Error_Msg
4051 and then Sloc (N) /= Urefs.Table (J).Loc
4053 Error_Msg_Node_1 := Urefs.Table (J).Node;
4055 if Urefs.Table (J).Nvis then
4056 Change_Error_Text (Urefs.Table (J).Err,
4057 "& is not visible (more references follow)");
4059 Change_Error_Text (Urefs.Table (J).Err,
4060 "& is undefined (more references follow)");
4063 Urefs.Table (J).Err := No_Error_Msg;
4066 -- Although we will set Msg False, and thus suppress the
4067 -- message, we also set Error_Posted True, to avoid any
4068 -- cascaded messages resulting from the undefined reference.
4071 Set_Error_Posted (N, True);
4076 -- If entry not found, this is first undefined occurrence
4079 Error_Msg_N ("& is not visible!", N);
4083 Error_Msg_N ("& is undefined!", N);
4086 -- A very bizarre special check, if the undefined identifier
4087 -- is put or put_line, then add a special error message (since
4088 -- this is a very common error for beginners to make).
4090 if Chars (N) = Name_Put or else Chars (N) = Name_Put_Line then
4091 Error_Msg_N -- CODEFIX
4092 ("\\possible missing `WITH Ada.Text_'I'O; " &
4093 "USE Ada.Text_'I'O`!", N);
4095 -- Another special check if N is the prefix of a selected
4096 -- component which is a known unit, add message complaining
4097 -- about missing with for this unit.
4099 elsif Nkind (Parent (N)) = N_Selected_Component
4100 and then N = Prefix (Parent (N))
4101 and then Is_Known_Unit (Parent (N))
4103 Error_Msg_Node_2 := Selector_Name (Parent (N));
4104 Error_Msg_N -- CODEFIX
4105 ("\\missing `WITH &.&;`", Prefix (Parent (N)));
4108 -- Now check for possible misspellings
4112 Ematch : Entity_Id := Empty;
4114 Last_Name_Id : constant Name_Id :=
4115 Name_Id (Nat (First_Name_Id) +
4116 Name_Entries_Count - 1);
4119 for Nam in First_Name_Id .. Last_Name_Id loop
4120 E := Get_Name_Entity_Id (Nam);
4123 and then (Is_Immediately_Visible (E)
4125 Is_Potentially_Use_Visible (E))
4127 if Is_Bad_Spelling_Of (Chars (N), Nam) then
4134 if Present (Ematch) then
4135 Error_Msg_NE -- CODEFIX
4136 ("\possible misspelling of&", N, Ematch);
4141 -- Make entry in undefined references table unless the full errors
4142 -- switch is set, in which case by refraining from generating the
4143 -- table entry, we guarantee that we get an error message for every
4144 -- undefined reference.
4146 if not All_Errors_Mode then
4157 -- Start of processing for Find_Direct_Name
4160 -- If the entity pointer is already set, this is an internal node, or
4161 -- a node that is analyzed more than once, after a tree modification.
4162 -- In such a case there is no resolution to perform, just set the type.
4164 if Present (Entity (N)) then
4165 if Is_Type (Entity (N)) then
4166 Set_Etype (N, Entity (N));
4170 Entyp : constant Entity_Id := Etype (Entity (N));
4173 -- One special case here. If the Etype field is already set,
4174 -- and references the packed array type corresponding to the
4175 -- etype of the referenced entity, then leave it alone. This
4176 -- happens for trees generated from Exp_Pakd, where expressions
4177 -- can be deliberately "mis-typed" to the packed array type.
4179 if Is_Array_Type (Entyp)
4180 and then Is_Packed (Entyp)
4181 and then Present (Etype (N))
4182 and then Etype (N) = Packed_Array_Type (Entyp)
4186 -- If not that special case, then just reset the Etype
4189 Set_Etype (N, Etype (Entity (N)));
4197 -- Here if Entity pointer was not set, we need full visibility analysis
4198 -- First we generate debugging output if the debug E flag is set.
4200 if Debug_Flag_E then
4201 Write_Str ("Looking for ");
4202 Write_Name (Chars (N));
4206 Homonyms := Current_Entity (N);
4207 Nvis_Entity := False;
4210 while Present (E) loop
4212 -- If entity is immediately visible or potentially use visible, then
4213 -- process the entity and we are done.
4215 if Is_Immediately_Visible (E) then
4216 goto Immediately_Visible_Entity;
4218 elsif Is_Potentially_Use_Visible (E) then
4219 goto Potentially_Use_Visible_Entity;
4221 -- Note if a known but invisible entity encountered
4223 elsif Known_But_Invisible (E) then
4224 Nvis_Entity := True;
4227 -- Move to next entity in chain and continue search
4232 -- If no entries on homonym chain that were potentially visible,
4233 -- and no entities reasonably considered as non-visible, then
4234 -- we have a plain undefined reference, with no additional
4235 -- explanation required!
4237 if not Nvis_Entity then
4238 Undefined (Nvis => False);
4240 -- Otherwise there is at least one entry on the homonym chain that
4241 -- is reasonably considered as being known and non-visible.
4249 -- Processing for a potentially use visible entry found. We must search
4250 -- the rest of the homonym chain for two reasons. First, if there is a
4251 -- directly visible entry, then none of the potentially use-visible
4252 -- entities are directly visible (RM 8.4(10)). Second, we need to check
4253 -- for the case of multiple potentially use-visible entries hiding one
4254 -- another and as a result being non-directly visible (RM 8.4(11)).
4256 <<Potentially_Use_Visible_Entity>> declare
4257 Only_One_Visible : Boolean := True;
4258 All_Overloadable : Boolean := Is_Overloadable (E);
4262 while Present (E2) loop
4263 if Is_Immediately_Visible (E2) then
4265 -- If the use-visible entity comes from the actual for a
4266 -- formal package, it hides a directly visible entity from
4267 -- outside the instance.
4269 if From_Actual_Package (E)
4270 and then Scope_Depth (E2) < Scope_Depth (Inst)
4275 goto Immediately_Visible_Entity;
4278 elsif Is_Potentially_Use_Visible (E2) then
4279 Only_One_Visible := False;
4280 All_Overloadable := All_Overloadable and Is_Overloadable (E2);
4282 -- Ada 2005 (AI-262): Protect against a form of Beaujolais effect
4283 -- that can occur in private_with clauses. Example:
4286 -- private with B; package A is
4287 -- package C is function B return Integer;
4289 -- V1 : Integer := B;
4290 -- private function B return Integer;
4291 -- V2 : Integer := B;
4294 -- V1 resolves to A.B, but V2 resolves to library unit B
4296 elsif Ekind (E2) = E_Function
4297 and then Scope (E2) = Standard_Standard
4298 and then Has_Private_With (E2)
4300 Only_One_Visible := False;
4301 All_Overloadable := False;
4302 Nvis_Is_Private_Subprg := True;
4309 -- On falling through this loop, we have checked that there are no
4310 -- immediately visible entities. Only_One_Visible is set if exactly
4311 -- one potentially use visible entity exists. All_Overloadable is
4312 -- set if all the potentially use visible entities are overloadable.
4313 -- The condition for legality is that either there is one potentially
4314 -- use visible entity, or if there is more than one, then all of them
4315 -- are overloadable.
4317 if Only_One_Visible or All_Overloadable then
4320 -- If there is more than one potentially use-visible entity and at
4321 -- least one of them non-overloadable, we have an error (RM 8.4(11).
4322 -- Note that E points to the first such entity on the homonym list.
4323 -- Special case: if one of the entities is declared in an actual
4324 -- package, it was visible in the generic, and takes precedence over
4325 -- other entities that are potentially use-visible. Same if it is
4326 -- declared in a local instantiation of the current instance.
4331 -- Find current instance
4333 Inst := Current_Scope;
4334 while Present (Inst)
4335 and then Inst /= Standard_Standard
4337 if Is_Generic_Instance (Inst) then
4341 Inst := Scope (Inst);
4345 while Present (E2) loop
4346 if From_Actual_Package (E2)
4348 (Is_Generic_Instance (Scope (E2))
4349 and then Scope_Depth (Scope (E2)) > Scope_Depth (Inst))
4362 Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
4364 -- A use-clause in the body of a system file creates conflict
4365 -- with some entity in a user scope, while rtsfind is active.
4366 -- Keep only the entity coming from another predefined unit.
4369 while Present (E2) loop
4370 if Is_Predefined_File_Name
4371 (Unit_File_Name (Get_Source_Unit (Sloc (E2))))
4380 -- Entity must exist because predefined unit is correct
4382 raise Program_Error;
4391 -- Come here with E set to the first immediately visible entity on
4392 -- the homonym chain. This is the one we want unless there is another
4393 -- immediately visible entity further on in the chain for an inner
4394 -- scope (RM 8.3(8)).
4396 <<Immediately_Visible_Entity>> declare
4401 -- Find scope level of initial entity. When compiling through
4402 -- Rtsfind, the previous context is not completely invisible, and
4403 -- an outer entity may appear on the chain, whose scope is below
4404 -- the entry for Standard that delimits the current scope stack.
4405 -- Indicate that the level for this spurious entry is outside of
4406 -- the current scope stack.
4408 Level := Scope_Stack.Last;
4410 Scop := Scope_Stack.Table (Level).Entity;
4411 exit when Scop = Scope (E);
4413 exit when Scop = Standard_Standard;
4416 -- Now search remainder of homonym chain for more inner entry
4417 -- If the entity is Standard itself, it has no scope, and we
4418 -- compare it with the stack entry directly.
4421 while Present (E2) loop
4422 if Is_Immediately_Visible (E2) then
4424 -- If a generic package contains a local declaration that
4425 -- has the same name as the generic, there may be a visibility
4426 -- conflict in an instance, where the local declaration must
4427 -- also hide the name of the corresponding package renaming.
4428 -- We check explicitly for a package declared by a renaming,
4429 -- whose renamed entity is an instance that is on the scope
4430 -- stack, and that contains a homonym in the same scope. Once
4431 -- we have found it, we know that the package renaming is not
4432 -- immediately visible, and that the identifier denotes the
4433 -- other entity (and its homonyms if overloaded).
4435 if Scope (E) = Scope (E2)
4436 and then Ekind (E) = E_Package
4437 and then Present (Renamed_Object (E))
4438 and then Is_Generic_Instance (Renamed_Object (E))
4439 and then In_Open_Scopes (Renamed_Object (E))
4440 and then Comes_From_Source (N)
4442 Set_Is_Immediately_Visible (E, False);
4446 for J in Level + 1 .. Scope_Stack.Last loop
4447 if Scope_Stack.Table (J).Entity = Scope (E2)
4448 or else Scope_Stack.Table (J).Entity = E2
4461 -- At the end of that loop, E is the innermost immediately
4462 -- visible entity, so we are all set.
4465 -- Come here with entity found, and stored in E
4469 -- Check violation of No_Wide_Characters restriction
4471 Check_Wide_Character_Restriction (E, N);
4473 -- When distribution features are available (Get_PCS_Name /=
4474 -- Name_No_DSA), a remote access-to-subprogram type is converted
4475 -- into a record type holding whatever information is needed to
4476 -- perform a remote call on an RCI subprogram. In that case we
4477 -- rewrite any occurrence of the RAS type into the equivalent record
4478 -- type here. 'Access attribute references and RAS dereferences are
4479 -- then implemented using specific TSSs. However when distribution is
4480 -- not available (case of Get_PCS_Name = Name_No_DSA), we bypass the
4481 -- generation of these TSSs, and we must keep the RAS type in its
4482 -- original access-to-subprogram form (since all calls through a
4483 -- value of such type will be local anyway in the absence of a PCS).
4485 if Comes_From_Source (N)
4486 and then Is_Remote_Access_To_Subprogram_Type (E)
4487 and then Expander_Active
4488 and then Get_PCS_Name /= Name_No_DSA
4491 New_Occurrence_Of (Equivalent_Type (E), Sloc (N)));
4495 -- Set the entity. Note that the reason we call Set_Entity for the
4496 -- overloadable case, as opposed to Set_Entity_With_Style_Check is
4497 -- that in the overloaded case, the initial call can set the wrong
4498 -- homonym. The call that sets the right homonym is in Sem_Res and
4499 -- that call does use Set_Entity_With_Style_Check, so we don't miss
4502 if Is_Overloadable (E) then
4505 Set_Entity_With_Style_Check (N, E);
4511 Set_Etype (N, Get_Full_View (Etype (E)));
4514 if Debug_Flag_E then
4515 Write_Str (" found ");
4516 Write_Entity_Info (E, " ");
4519 -- If the Ekind of the entity is Void, it means that all homonyms
4520 -- are hidden from all visibility (RM 8.3(5,14-20)). However, this
4521 -- test is skipped if the current scope is a record and the name is
4522 -- a pragma argument expression (case of Atomic and Volatile pragmas
4523 -- and possibly other similar pragmas added later, which are allowed
4524 -- to reference components in the current record).
4526 if Ekind (E) = E_Void
4528 (not Is_Record_Type (Current_Scope)
4529 or else Nkind (Parent (N)) /= N_Pragma_Argument_Association)
4531 Premature_Usage (N);
4533 -- If the entity is overloadable, collect all interpretations of the
4534 -- name for subsequent overload resolution. We optimize a bit here to
4535 -- do this only if we have an overloadable entity that is not on its
4536 -- own on the homonym chain.
4538 elsif Is_Overloadable (E)
4539 and then (Present (Homonym (E)) or else Current_Entity (N) /= E)
4541 Collect_Interps (N);
4543 -- If no homonyms were visible, the entity is unambiguous
4545 if not Is_Overloaded (N) then
4546 if not Is_Actual_Parameter then
4547 Generate_Reference (E, N);
4551 -- Case of non-overloadable entity, set the entity providing that
4552 -- we do not have the case of a discriminant reference within a
4553 -- default expression. Such references are replaced with the
4554 -- corresponding discriminal, which is the formal corresponding to
4555 -- to the discriminant in the initialization procedure.
4558 -- Entity is unambiguous, indicate that it is referenced here
4560 -- For a renaming of an object, always generate simple reference,
4561 -- we don't try to keep track of assignments in this case.
4563 if Is_Object (E) and then Present (Renamed_Object (E)) then
4564 Generate_Reference (E, N);
4566 -- If the renamed entity is a private protected component,
4567 -- reference the original component as well. This needs to be
4568 -- done because the private renamings are installed before any
4569 -- analysis has occurred. Reference to a private component will
4570 -- resolve to the renaming and the original component will be
4571 -- left unreferenced, hence the following.
4573 if Is_Prival (E) then
4574 Generate_Reference (Prival_Link (E), N);
4577 -- One odd case is that we do not want to set the Referenced flag
4578 -- if the entity is a label, and the identifier is the label in
4579 -- the source, since this is not a reference from the point of
4580 -- view of the user.
4582 elsif Nkind (Parent (N)) = N_Label then
4584 R : constant Boolean := Referenced (E);
4587 -- Generate reference unless this is an actual parameter
4588 -- (see comment below)
4590 if Is_Actual_Parameter then
4591 Generate_Reference (E, N);
4592 Set_Referenced (E, R);
4596 -- Normal case, not a label: generate reference
4598 -- ??? It is too early to generate a reference here even if the
4599 -- entity is unambiguous, because the tree is not sufficiently
4600 -- typed at this point for Generate_Reference to determine
4601 -- whether this reference modifies the denoted object (because
4602 -- implicit dereferences cannot be identified prior to full type
4605 -- The Is_Actual_Parameter routine takes care of one of these
4606 -- cases but there are others probably ???
4608 -- If the entity is the LHS of an assignment, and is a variable
4609 -- (rather than a package prefix), we can mark it as a
4610 -- modification right away, to avoid duplicate references.
4613 if not Is_Actual_Parameter then
4615 and then Ekind (E) /= E_Package
4616 and then Ekind (E) /= E_Generic_Package
4618 Generate_Reference (E, N, 'm');
4620 Generate_Reference (E, N);
4624 Check_Nested_Access (E);
4627 Set_Entity_Or_Discriminal (N, E);
4630 end Find_Direct_Name;
4632 ------------------------
4633 -- Find_Expanded_Name --
4634 ------------------------
4636 -- This routine searches the homonym chain of the entity until it finds
4637 -- an entity declared in the scope denoted by the prefix. If the entity
4638 -- is private, it may nevertheless be immediately visible, if we are in
4639 -- the scope of its declaration.
4641 procedure Find_Expanded_Name (N : Node_Id) is
4642 Selector : constant Node_Id := Selector_Name (N);
4643 Candidate : Entity_Id := Empty;
4649 P_Name := Entity (Prefix (N));
4652 -- If the prefix is a renamed package, look for the entity in the
4653 -- original package.
4655 if Ekind (P_Name) = E_Package
4656 and then Present (Renamed_Object (P_Name))
4658 P_Name := Renamed_Object (P_Name);
4660 -- Rewrite node with entity field pointing to renamed object
4662 Rewrite (Prefix (N), New_Copy (Prefix (N)));
4663 Set_Entity (Prefix (N), P_Name);
4665 -- If the prefix is an object of a concurrent type, look for
4666 -- the entity in the associated task or protected type.
4668 elsif Is_Concurrent_Type (Etype (P_Name)) then
4669 P_Name := Etype (P_Name);
4672 Id := Current_Entity (Selector);
4675 Is_New_Candidate : Boolean;
4678 while Present (Id) loop
4679 if Scope (Id) = P_Name then
4681 Is_New_Candidate := True;
4683 -- Ada 2005 (AI-217): Handle shadow entities associated with types
4684 -- declared in limited-withed nested packages. We don't need to
4685 -- handle E_Incomplete_Subtype entities because the entities in
4686 -- the limited view are always E_Incomplete_Type entities (see
4687 -- Build_Limited_Views). Regarding the expression used to evaluate
4688 -- the scope, it is important to note that the limited view also
4689 -- has shadow entities associated nested packages. For this reason
4690 -- the correct scope of the entity is the scope of the real entity
4691 -- The non-limited view may itself be incomplete, in which case
4692 -- get the full view if available.
4694 elsif From_With_Type (Id)
4695 and then Is_Type (Id)
4696 and then Ekind (Id) = E_Incomplete_Type
4697 and then Present (Non_Limited_View (Id))
4698 and then Scope (Non_Limited_View (Id)) = P_Name
4700 Candidate := Get_Full_View (Non_Limited_View (Id));
4701 Is_New_Candidate := True;
4704 Is_New_Candidate := False;
4707 if Is_New_Candidate then
4708 if Is_Child_Unit (Id) then
4709 exit when Is_Visible_Child_Unit (Id)
4710 or else Is_Immediately_Visible (Id);
4713 exit when not Is_Hidden (Id)
4714 or else Is_Immediately_Visible (Id);
4723 and then (Ekind (P_Name) = E_Procedure
4725 Ekind (P_Name) = E_Function)
4726 and then Is_Generic_Instance (P_Name)
4728 -- Expanded name denotes entity in (instance of) generic subprogram.
4729 -- The entity may be in the subprogram instance, or may denote one of
4730 -- the formals, which is declared in the enclosing wrapper package.
4732 P_Name := Scope (P_Name);
4734 Id := Current_Entity (Selector);
4735 while Present (Id) loop
4736 exit when Scope (Id) = P_Name;
4741 if No (Id) or else Chars (Id) /= Chars (Selector) then
4742 Set_Etype (N, Any_Type);
4744 -- If we are looking for an entity defined in System, try to find it
4745 -- in the child package that may have been provided as an extension
4746 -- to System. The Extend_System pragma will have supplied the name of
4747 -- the extension, which may have to be loaded.
4749 if Chars (P_Name) = Name_System
4750 and then Scope (P_Name) = Standard_Standard
4751 and then Present (System_Extend_Unit)
4752 and then Present_System_Aux (N)
4754 Set_Entity (Prefix (N), System_Aux_Id);
4755 Find_Expanded_Name (N);
4758 elsif Nkind (Selector) = N_Operator_Symbol
4759 and then Has_Implicit_Operator (N)
4761 -- There is an implicit instance of the predefined operator in
4762 -- the given scope. The operator entity is defined in Standard.
4763 -- Has_Implicit_Operator makes the node into an Expanded_Name.
4767 elsif Nkind (Selector) = N_Character_Literal
4768 and then Has_Implicit_Character_Literal (N)
4770 -- If there is no literal defined in the scope denoted by the
4771 -- prefix, the literal may belong to (a type derived from)
4772 -- Standard_Character, for which we have no explicit literals.
4777 -- If the prefix is a single concurrent object, use its name in
4778 -- the error message, rather than that of the anonymous type.
4780 if Is_Concurrent_Type (P_Name)
4781 and then Is_Internal_Name (Chars (P_Name))
4783 Error_Msg_Node_2 := Entity (Prefix (N));
4785 Error_Msg_Node_2 := P_Name;
4788 if P_Name = System_Aux_Id then
4789 P_Name := Scope (P_Name);
4790 Set_Entity (Prefix (N), P_Name);
4793 if Present (Candidate) then
4795 -- If we know that the unit is a child unit we can give a more
4796 -- accurate error message.
4798 if Is_Child_Unit (Candidate) then
4800 -- If the candidate is a private child unit and we are in
4801 -- the visible part of a public unit, specialize the error
4802 -- message. There might be a private with_clause for it,
4803 -- but it is not currently active.
4805 if Is_Private_Descendant (Candidate)
4806 and then Ekind (Current_Scope) = E_Package
4807 and then not In_Private_Part (Current_Scope)
4808 and then not Is_Private_Descendant (Current_Scope)
4810 Error_Msg_N ("private child unit& is not visible here",
4813 -- Normal case where we have a missing with for a child unit
4816 Error_Msg_Qual_Level := 99;
4817 Error_Msg_NE -- CODEFIX
4818 ("missing `WITH &;`", Selector, Candidate);
4819 Error_Msg_Qual_Level := 0;
4822 -- Here we don't know that this is a child unit
4825 Error_Msg_NE ("& is not a visible entity of&", N, Selector);
4829 -- Within the instantiation of a child unit, the prefix may
4830 -- denote the parent instance, but the selector has the name
4831 -- of the original child. Find whether we are within the
4832 -- corresponding instance, and get the proper entity, which
4833 -- can only be an enclosing scope.
4836 and then In_Open_Scopes (P_Name)
4837 and then Is_Generic_Instance (P_Name)
4840 S : Entity_Id := Current_Scope;
4844 for J in reverse 0 .. Scope_Stack.Last loop
4845 S := Scope_Stack.Table (J).Entity;
4847 exit when S = Standard_Standard;
4849 if Ekind_In (S, E_Function,
4853 P := Generic_Parent (Specification
4854 (Unit_Declaration_Node (S)));
4857 and then Chars (Scope (P)) = Chars (O_Name)
4858 and then Chars (P) = Chars (Selector)
4869 -- If this is a selection from Ada, System or Interfaces, then
4870 -- we assume a missing with for the corresponding package.
4872 if Is_Known_Unit (N) then
4873 if not Error_Posted (N) then
4874 Error_Msg_Node_2 := Selector;
4875 Error_Msg_N -- CODEFIX
4876 ("missing `WITH &.&;`", Prefix (N));
4879 -- If this is a selection from a dummy package, then suppress
4880 -- the error message, of course the entity is missing if the
4881 -- package is missing!
4883 elsif Sloc (Error_Msg_Node_2) = No_Location then
4886 -- Here we have the case of an undefined component
4890 -- The prefix may hide a homonym in the context that
4891 -- declares the desired entity. This error can use a
4892 -- specialized message.
4894 if In_Open_Scopes (P_Name)
4895 and then Present (Homonym (P_Name))
4896 and then Is_Compilation_Unit (Homonym (P_Name))
4898 (Is_Immediately_Visible (Homonym (P_Name))
4899 or else Is_Visible_Child_Unit (Homonym (P_Name)))
4902 H : constant Entity_Id := Homonym (P_Name);
4905 Id := First_Entity (H);
4906 while Present (Id) loop
4907 if Chars (Id) = Chars (Selector) then
4908 Error_Msg_Qual_Level := 99;
4909 Error_Msg_Name_1 := Chars (Selector);
4911 ("% not declared in&", N, P_Name);
4913 ("\use fully qualified name starting with"
4914 & " Standard to make& visible", N, H);
4915 Error_Msg_Qual_Level := 0;
4922 -- If not found, standard error message.
4924 Error_Msg_NE ("& not declared in&", N, Selector);
4930 Error_Msg_NE ("& not declared in&", N, Selector);
4933 -- Check for misspelling of some entity in prefix
4935 Id := First_Entity (P_Name);
4936 while Present (Id) loop
4937 if Is_Bad_Spelling_Of (Chars (Id), Chars (Selector))
4938 and then not Is_Internal_Name (Chars (Id))
4940 Error_Msg_NE -- CODEFIX
4941 ("possible misspelling of&", Selector, Id);
4948 -- Specialize the message if this may be an instantiation
4949 -- of a child unit that was not mentioned in the context.
4951 if Nkind (Parent (N)) = N_Package_Instantiation
4952 and then Is_Generic_Instance (Entity (Prefix (N)))
4953 and then Is_Compilation_Unit
4954 (Generic_Parent (Parent (Entity (Prefix (N)))))
4956 Error_Msg_Node_2 := Selector;
4957 Error_Msg_N -- CODEFIX
4958 ("\missing `WITH &.&;`", Prefix (N));
4968 if Comes_From_Source (N)
4969 and then Is_Remote_Access_To_Subprogram_Type (Id)
4970 and then Present (Equivalent_Type (Id))
4972 -- If we are not actually generating distribution code (i.e. the
4973 -- current PCS is the dummy non-distributed version), then the
4974 -- Equivalent_Type will be missing, and Id should be treated as
4975 -- a regular access-to-subprogram type.
4977 Id := Equivalent_Type (Id);
4978 Set_Chars (Selector, Chars (Id));
4981 -- Ada 2005 (AI-50217): Check usage of entities in limited withed units
4983 if Ekind (P_Name) = E_Package
4984 and then From_With_Type (P_Name)
4986 if From_With_Type (Id)
4987 or else Is_Type (Id)
4988 or else Ekind (Id) = E_Package
4993 ("limited withed package can only be used to access "
4994 & "incomplete types",
4999 if Is_Task_Type (P_Name)
5000 and then ((Ekind (Id) = E_Entry
5001 and then Nkind (Parent (N)) /= N_Attribute_Reference)
5003 (Ekind (Id) = E_Entry_Family
5005 Nkind (Parent (Parent (N))) /= N_Attribute_Reference))
5007 -- It is an entry call after all, either to the current task (which
5008 -- will deadlock) or to an enclosing task.
5010 Analyze_Selected_Component (N);
5014 Change_Selected_Component_To_Expanded_Name (N);
5016 -- Do style check and generate reference, but skip both steps if this
5017 -- entity has homonyms, since we may not have the right homonym set yet.
5018 -- The proper homonym will be set during the resolve phase.
5020 if Has_Homonym (Id) then
5023 Set_Entity_Or_Discriminal (N, Id);
5026 Generate_Reference (Id, N, 'm');
5028 Generate_Reference (Id, N);
5032 if Is_Type (Id) then
5035 Set_Etype (N, Get_Full_View (Etype (Id)));
5038 -- Check for violation of No_Wide_Characters
5040 Check_Wide_Character_Restriction (Id, N);
5042 -- If the Ekind of the entity is Void, it means that all homonyms are
5043 -- hidden from all visibility (RM 8.3(5,14-20)).
5045 if Ekind (Id) = E_Void then
5046 Premature_Usage (N);
5048 elsif Is_Overloadable (Id)
5049 and then Present (Homonym (Id))
5052 H : Entity_Id := Homonym (Id);
5055 while Present (H) loop
5056 if Scope (H) = Scope (Id)
5059 or else Is_Immediately_Visible (H))
5061 Collect_Interps (N);
5068 -- If an extension of System is present, collect possible explicit
5069 -- overloadings declared in the extension.
5071 if Chars (P_Name) = Name_System
5072 and then Scope (P_Name) = Standard_Standard
5073 and then Present (System_Extend_Unit)
5074 and then Present_System_Aux (N)
5076 H := Current_Entity (Id);
5078 while Present (H) loop
5079 if Scope (H) = System_Aux_Id then
5080 Add_One_Interp (N, H, Etype (H));
5089 if Nkind (Selector_Name (N)) = N_Operator_Symbol
5090 and then Scope (Id) /= Standard_Standard
5092 -- In addition to user-defined operators in the given scope, there
5093 -- may be an implicit instance of the predefined operator. The
5094 -- operator (defined in Standard) is found in Has_Implicit_Operator,
5095 -- and added to the interpretations. Procedure Add_One_Interp will
5096 -- determine which hides which.
5098 if Has_Implicit_Operator (N) then
5102 end Find_Expanded_Name;
5104 -------------------------
5105 -- Find_Renamed_Entity --
5106 -------------------------
5108 function Find_Renamed_Entity
5112 Is_Actual : Boolean := False) return Entity_Id
5115 I1 : Interp_Index := 0; -- Suppress junk warnings
5121 function Enclosing_Instance return Entity_Id;
5122 -- If the renaming determines the entity for the default of a formal
5123 -- subprogram nested within another instance, choose the innermost
5124 -- candidate. This is because if the formal has a box, and we are within
5125 -- an enclosing instance where some candidate interpretations are local
5126 -- to this enclosing instance, we know that the default was properly
5127 -- resolved when analyzing the generic, so we prefer the local
5128 -- candidates to those that are external. This is not always the case
5129 -- but is a reasonable heuristic on the use of nested generics. The
5130 -- proper solution requires a full renaming model.
5132 function Is_Visible_Operation (Op : Entity_Id) return Boolean;
5133 -- If the renamed entity is an implicit operator, check whether it is
5134 -- visible because its operand type is properly visible. This check
5135 -- applies to explicit renamed entities that appear in the source in a
5136 -- renaming declaration or a formal subprogram instance, but not to
5137 -- default generic actuals with a name.
5139 function Report_Overload return Entity_Id;
5140 -- List possible interpretations, and specialize message in the
5141 -- case of a generic actual.
5143 function Within (Inner, Outer : Entity_Id) return Boolean;
5144 -- Determine whether a candidate subprogram is defined within the
5145 -- enclosing instance. If yes, it has precedence over outer candidates.
5147 ------------------------
5148 -- Enclosing_Instance --
5149 ------------------------
5151 function Enclosing_Instance return Entity_Id is
5155 if not Is_Generic_Instance (Current_Scope)
5156 and then not Is_Actual
5161 S := Scope (Current_Scope);
5162 while S /= Standard_Standard loop
5163 if Is_Generic_Instance (S) then
5171 end Enclosing_Instance;
5173 --------------------------
5174 -- Is_Visible_Operation --
5175 --------------------------
5177 function Is_Visible_Operation (Op : Entity_Id) return Boolean is
5183 if Ekind (Op) /= E_Operator
5184 or else Scope (Op) /= Standard_Standard
5185 or else (In_Instance
5188 or else Present (Enclosing_Instance)))
5193 -- For a fixed point type operator, check the resulting type,
5194 -- because it may be a mixed mode integer * fixed operation.
5196 if Present (Next_Formal (First_Formal (New_S)))
5197 and then Is_Fixed_Point_Type (Etype (New_S))
5199 Typ := Etype (New_S);
5201 Typ := Etype (First_Formal (New_S));
5204 Btyp := Base_Type (Typ);
5206 if Nkind (Nam) /= N_Expanded_Name then
5207 return (In_Open_Scopes (Scope (Btyp))
5208 or else Is_Potentially_Use_Visible (Btyp)
5209 or else In_Use (Btyp)
5210 or else In_Use (Scope (Btyp)));
5213 Scop := Entity (Prefix (Nam));
5215 if Ekind (Scop) = E_Package
5216 and then Present (Renamed_Object (Scop))
5218 Scop := Renamed_Object (Scop);
5221 -- Operator is visible if prefix of expanded name denotes
5222 -- scope of type, or else type is defined in System_Aux
5223 -- and the prefix denotes System.
5225 return Scope (Btyp) = Scop
5226 or else (Scope (Btyp) = System_Aux_Id
5227 and then Scope (Scope (Btyp)) = Scop);
5230 end Is_Visible_Operation;
5236 function Within (Inner, Outer : Entity_Id) return Boolean is
5240 Sc := Scope (Inner);
5241 while Sc /= Standard_Standard loop
5252 ---------------------
5253 -- Report_Overload --
5254 ---------------------
5256 function Report_Overload return Entity_Id is
5259 Error_Msg_NE -- CODEFIX
5260 ("ambiguous actual subprogram&, " &
5261 "possible interpretations:", N, Nam);
5263 Error_Msg_N -- CODEFIX
5264 ("ambiguous subprogram, " &
5265 "possible interpretations:", N);
5268 List_Interps (Nam, N);
5270 end Report_Overload;
5272 -- Start of processing for Find_Renamed_Entry
5276 Candidate_Renaming := Empty;
5278 if not Is_Overloaded (Nam) then
5279 if Entity_Matches_Spec (Entity (Nam), New_S) then
5280 Candidate_Renaming := New_S;
5282 if Is_Visible_Operation (Entity (Nam)) then
5283 Old_S := Entity (Nam);
5287 Present (First_Formal (Entity (Nam)))
5288 and then Present (First_Formal (New_S))
5289 and then (Base_Type (Etype (First_Formal (Entity (Nam))))
5290 = Base_Type (Etype (First_Formal (New_S))))
5292 Candidate_Renaming := Entity (Nam);
5296 Get_First_Interp (Nam, Ind, It);
5297 while Present (It.Nam) loop
5298 if Entity_Matches_Spec (It.Nam, New_S)
5299 and then Is_Visible_Operation (It.Nam)
5301 if Old_S /= Any_Id then
5303 -- Note: The call to Disambiguate only happens if a
5304 -- previous interpretation was found, in which case I1
5305 -- has received a value.
5307 It1 := Disambiguate (Nam, I1, Ind, Etype (Old_S));
5309 if It1 = No_Interp then
5310 Inst := Enclosing_Instance;
5312 if Present (Inst) then
5313 if Within (It.Nam, Inst) then
5315 elsif Within (Old_S, Inst) then
5318 return Report_Overload;
5322 return Report_Overload;
5336 Present (First_Formal (It.Nam))
5337 and then Present (First_Formal (New_S))
5338 and then (Base_Type (Etype (First_Formal (It.Nam)))
5339 = Base_Type (Etype (First_Formal (New_S))))
5341 Candidate_Renaming := It.Nam;
5344 Get_Next_Interp (Ind, It);
5347 Set_Entity (Nam, Old_S);
5348 Set_Is_Overloaded (Nam, False);
5352 end Find_Renamed_Entity;
5354 -----------------------------
5355 -- Find_Selected_Component --
5356 -----------------------------
5358 procedure Find_Selected_Component (N : Node_Id) is
5359 P : constant Node_Id := Prefix (N);
5362 -- Entity denoted by prefix
5372 if Nkind (P) = N_Error then
5375 -- If the selector already has an entity, the node has been constructed
5376 -- in the course of expansion, and is known to be valid. Do not verify
5377 -- that it is defined for the type (it may be a private component used
5378 -- in the expansion of record equality).
5380 elsif Present (Entity (Selector_Name (N))) then
5382 or else Etype (N) = Any_Type
5385 Sel_Name : constant Node_Id := Selector_Name (N);
5386 Selector : constant Entity_Id := Entity (Sel_Name);
5390 Set_Etype (Sel_Name, Etype (Selector));
5392 if not Is_Entity_Name (P) then
5396 -- Build an actual subtype except for the first parameter
5397 -- of an init proc, where this actual subtype is by
5398 -- definition incorrect, since the object is uninitialized
5399 -- (and does not even have defined discriminants etc.)
5401 if Is_Entity_Name (P)
5402 and then Ekind (Entity (P)) = E_Function
5404 Nam := New_Copy (P);
5406 if Is_Overloaded (P) then
5407 Save_Interps (P, Nam);
5411 Make_Function_Call (Sloc (P), Name => Nam));
5413 Analyze_Selected_Component (N);
5416 elsif Ekind (Selector) = E_Component
5417 and then (not Is_Entity_Name (P)
5418 or else Chars (Entity (P)) /= Name_uInit)
5420 -- Do not build the subtype when referencing components of
5421 -- dispatch table wrappers. Required to avoid generating
5422 -- elaboration code with HI runtimes.
5424 if RTU_Loaded (Ada_Tags)
5425 and then RTE_Available (RE_Dispatch_Table_Wrapper)
5426 and then Scope (Selector) = RTE (RE_Dispatch_Table_Wrapper)
5430 elsif RTU_Loaded (Ada_Tags)
5431 and then RTE_Available (RE_No_Dispatch_Table_Wrapper)
5432 and then Scope (Selector)
5433 = RTE (RE_No_Dispatch_Table_Wrapper)
5439 Build_Actual_Subtype_Of_Component (
5440 Etype (Selector), N);
5447 if No (C_Etype) then
5448 C_Etype := Etype (Selector);
5450 Insert_Action (N, C_Etype);
5451 C_Etype := Defining_Identifier (C_Etype);
5454 Set_Etype (N, C_Etype);
5457 -- If this is the name of an entry or protected operation, and
5458 -- the prefix is an access type, insert an explicit dereference,
5459 -- so that entry calls are treated uniformly.
5461 if Is_Access_Type (Etype (P))
5462 and then Is_Concurrent_Type (Designated_Type (Etype (P)))
5465 New_P : constant Node_Id :=
5466 Make_Explicit_Dereference (Sloc (P),
5467 Prefix => Relocate_Node (P));
5470 Set_Etype (P, Designated_Type (Etype (Prefix (P))));
5474 -- If the selected component appears within a default expression
5475 -- and it has an actual subtype, the pre-analysis has not yet
5476 -- completed its analysis, because Insert_Actions is disabled in
5477 -- that context. Within the init proc of the enclosing type we
5478 -- must complete this analysis, if an actual subtype was created.
5480 elsif Inside_Init_Proc then
5482 Typ : constant Entity_Id := Etype (N);
5483 Decl : constant Node_Id := Declaration_Node (Typ);
5485 if Nkind (Decl) = N_Subtype_Declaration
5486 and then not Analyzed (Decl)
5487 and then Is_List_Member (Decl)
5488 and then No (Parent (Decl))
5491 Insert_Action (N, Decl);
5498 elsif Is_Entity_Name (P) then
5499 P_Name := Entity (P);
5501 -- Selector name is restricted in SPARK
5504 if Is_Subprogram (P_Name) then
5506 ("|~~prefix of expanded name cannot be a subprogram", P);
5507 elsif Ekind (P_Name) = E_Loop then
5509 ("|~~prefix of expanded name cannot be a loop statement", P);
5513 -- The prefix may denote an enclosing type which is the completion
5514 -- of an incomplete type declaration.
5516 if Is_Type (P_Name) then
5517 Set_Entity (P, Get_Full_View (P_Name));
5518 Set_Etype (P, Entity (P));
5519 P_Name := Entity (P);
5522 P_Type := Base_Type (Etype (P));
5524 if Debug_Flag_E then
5525 Write_Str ("Found prefix type to be ");
5526 Write_Entity_Info (P_Type, " "); Write_Eol;
5529 -- First check for components of a record object (not the
5530 -- result of a call, which is handled below).
5532 if Is_Appropriate_For_Record (P_Type)
5533 and then not Is_Overloadable (P_Name)
5534 and then not Is_Type (P_Name)
5536 -- Selected component of record. Type checking will validate
5537 -- name of selector.
5538 -- ??? could we rewrite an implicit dereference into an explicit
5541 Analyze_Selected_Component (N);
5543 -- Reference to type name in predicate/invariant expression
5545 elsif Is_Appropriate_For_Entry_Prefix (P_Type)
5546 and then not In_Open_Scopes (P_Name)
5547 and then (not Is_Concurrent_Type (Etype (P_Name))
5548 or else not In_Open_Scopes (Etype (P_Name)))
5550 -- Call to protected operation or entry. Type checking is
5551 -- needed on the prefix.
5553 Analyze_Selected_Component (N);
5555 elsif (In_Open_Scopes (P_Name)
5556 and then Ekind (P_Name) /= E_Void
5557 and then not Is_Overloadable (P_Name))
5558 or else (Is_Concurrent_Type (Etype (P_Name))
5559 and then In_Open_Scopes (Etype (P_Name)))
5561 -- Prefix denotes an enclosing loop, block, or task, i.e. an
5562 -- enclosing construct that is not a subprogram or accept.
5564 Find_Expanded_Name (N);
5566 elsif Ekind (P_Name) = E_Package then
5567 Find_Expanded_Name (N);
5569 elsif Is_Overloadable (P_Name) then
5571 -- The subprogram may be a renaming (of an enclosing scope) as
5572 -- in the case of the name of the generic within an instantiation.
5574 if Ekind_In (P_Name, E_Procedure, E_Function)
5575 and then Present (Alias (P_Name))
5576 and then Is_Generic_Instance (Alias (P_Name))
5578 P_Name := Alias (P_Name);
5581 if Is_Overloaded (P) then
5583 -- The prefix must resolve to a unique enclosing construct
5586 Found : Boolean := False;
5591 Get_First_Interp (P, Ind, It);
5592 while Present (It.Nam) loop
5593 if In_Open_Scopes (It.Nam) then
5596 "prefix must be unique enclosing scope", N);
5597 Set_Entity (N, Any_Id);
5598 Set_Etype (N, Any_Type);
5607 Get_Next_Interp (Ind, It);
5612 if In_Open_Scopes (P_Name) then
5613 Set_Entity (P, P_Name);
5614 Set_Is_Overloaded (P, False);
5615 Find_Expanded_Name (N);
5618 -- If no interpretation as an expanded name is possible, it
5619 -- must be a selected component of a record returned by a
5620 -- function call. Reformat prefix as a function call, the rest
5621 -- is done by type resolution. If the prefix is procedure or
5622 -- entry, as is P.X; this is an error.
5624 if Ekind (P_Name) /= E_Function
5625 and then (not Is_Overloaded (P)
5627 Nkind (Parent (N)) = N_Procedure_Call_Statement)
5629 -- Prefix may mention a package that is hidden by a local
5630 -- declaration: let the user know. Scan the full homonym
5631 -- chain, the candidate package may be anywhere on it.
5633 if Present (Homonym (Current_Entity (P_Name))) then
5635 P_Name := Current_Entity (P_Name);
5637 while Present (P_Name) loop
5638 exit when Ekind (P_Name) = E_Package;
5639 P_Name := Homonym (P_Name);
5642 if Present (P_Name) then
5643 Error_Msg_Sloc := Sloc (Entity (Prefix (N)));
5646 ("package& is hidden by declaration#",
5649 Set_Entity (Prefix (N), P_Name);
5650 Find_Expanded_Name (N);
5653 P_Name := Entity (Prefix (N));
5658 ("invalid prefix in selected component&", N, P_Name);
5659 Change_Selected_Component_To_Expanded_Name (N);
5660 Set_Entity (N, Any_Id);
5661 Set_Etype (N, Any_Type);
5664 Nam := New_Copy (P);
5665 Save_Interps (P, Nam);
5667 Make_Function_Call (Sloc (P), Name => Nam));
5669 Analyze_Selected_Component (N);
5673 -- Remaining cases generate various error messages
5676 -- Format node as expanded name, to avoid cascaded errors
5678 Change_Selected_Component_To_Expanded_Name (N);
5679 Set_Entity (N, Any_Id);
5680 Set_Etype (N, Any_Type);
5682 -- Issue error message, but avoid this if error issued already.
5683 -- Use identifier of prefix if one is available.
5685 if P_Name = Any_Id then
5688 elsif Ekind (P_Name) = E_Void then
5689 Premature_Usage (P);
5691 elsif Nkind (P) /= N_Attribute_Reference then
5693 "invalid prefix in selected component&", P);
5695 if Is_Access_Type (P_Type)
5696 and then Ekind (Designated_Type (P_Type)) = E_Incomplete_Type
5699 ("\dereference must not be of an incomplete type " &
5705 "invalid prefix in selected component", P);
5710 -- If prefix is not the name of an entity, it must be an expression,
5711 -- whose type is appropriate for a record. This is determined by
5714 Analyze_Selected_Component (N);
5716 end Find_Selected_Component;
5722 procedure Find_Type (N : Node_Id) is
5732 elsif Nkind (N) = N_Attribute_Reference then
5734 -- Class attribute. This is not valid in Ada 83 mode, but we do not
5735 -- need to enforce that at this point, since the declaration of the
5736 -- tagged type in the prefix would have been flagged already.
5738 if Attribute_Name (N) = Name_Class then
5739 Check_Restriction (No_Dispatch, N);
5740 Find_Type (Prefix (N));
5742 -- Propagate error from bad prefix
5744 if Etype (Prefix (N)) = Any_Type then
5745 Set_Entity (N, Any_Type);
5746 Set_Etype (N, Any_Type);
5750 T := Base_Type (Entity (Prefix (N)));
5752 -- Case where type is not known to be tagged. Its appearance in
5753 -- the prefix of the 'Class attribute indicates that the full view
5756 if not Is_Tagged_Type (T) then
5757 if Ekind (T) = E_Incomplete_Type then
5759 -- It is legal to denote the class type of an incomplete
5760 -- type. The full type will have to be tagged, of course.
5761 -- In Ada 2005 this usage is declared obsolescent, so we
5762 -- warn accordingly. This usage is only legal if the type
5763 -- is completed in the current scope, and not for a limited
5766 if not Is_Tagged_Type (T)
5767 and then Ada_Version >= Ada_2005
5769 if From_With_Type (T) then
5771 ("prefix of Class attribute must be tagged", N);
5772 Set_Etype (N, Any_Type);
5773 Set_Entity (N, Any_Type);
5776 -- ??? This test is temporarily disabled (always False)
5777 -- because it causes an unwanted warning on GNAT sources
5778 -- (built with -gnatg, which includes Warn_On_Obsolescent_
5779 -- Feature). Once this issue is cleared in the sources, it
5782 elsif Warn_On_Obsolescent_Feature
5786 ("applying 'Class to an untagged incomplete type"
5787 & " is an obsolescent feature (RM J.11)", N);
5791 Set_Is_Tagged_Type (T);
5792 Set_Direct_Primitive_Operations (T, New_Elmt_List);
5793 Make_Class_Wide_Type (T);
5794 Set_Entity (N, Class_Wide_Type (T));
5795 Set_Etype (N, Class_Wide_Type (T));
5797 elsif Ekind (T) = E_Private_Type
5798 and then not Is_Generic_Type (T)
5799 and then In_Private_Part (Scope (T))
5801 -- The Class attribute can be applied to an untagged private
5802 -- type fulfilled by a tagged type prior to the full type
5803 -- declaration (but only within the parent package's private
5804 -- part). Create the class-wide type now and check that the
5805 -- full type is tagged later during its analysis. Note that
5806 -- we do not mark the private type as tagged, unlike the
5807 -- case of incomplete types, because the type must still
5808 -- appear untagged to outside units.
5810 if No (Class_Wide_Type (T)) then
5811 Make_Class_Wide_Type (T);
5814 Set_Entity (N, Class_Wide_Type (T));
5815 Set_Etype (N, Class_Wide_Type (T));
5818 -- Should we introduce a type Any_Tagged and use Wrong_Type
5819 -- here, it would be a bit more consistent???
5822 ("tagged type required, found}",
5823 Prefix (N), First_Subtype (T));
5824 Set_Entity (N, Any_Type);
5828 -- Case of tagged type
5831 if Is_Concurrent_Type (T) then
5832 if No (Corresponding_Record_Type (Entity (Prefix (N)))) then
5834 -- Previous error. Use current type, which at least
5835 -- provides some operations.
5837 C := Entity (Prefix (N));
5840 C := Class_Wide_Type
5841 (Corresponding_Record_Type (Entity (Prefix (N))));
5845 C := Class_Wide_Type (Entity (Prefix (N)));
5848 Set_Entity_With_Style_Check (N, C);
5849 Generate_Reference (C, N);
5853 -- Base attribute, not allowed in Ada 83
5855 elsif Attribute_Name (N) = Name_Base then
5856 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
5858 ("(Ada 83) Base attribute not allowed in subtype mark", N);
5861 Find_Type (Prefix (N));
5862 Typ := Entity (Prefix (N));
5864 if Ada_Version >= Ada_95
5865 and then not Is_Scalar_Type (Typ)
5866 and then not Is_Generic_Type (Typ)
5869 ("prefix of Base attribute must be scalar type",
5872 elsif Warn_On_Redundant_Constructs
5873 and then Base_Type (Typ) = Typ
5875 Error_Msg_NE -- CODEFIX
5876 ("?redundant attribute, & is its own base type", N, Typ);
5879 T := Base_Type (Typ);
5881 -- Rewrite attribute reference with type itself (see similar
5882 -- processing in Analyze_Attribute, case Base). Preserve prefix
5883 -- if present, for other legality checks.
5885 if Nkind (Prefix (N)) = N_Expanded_Name then
5887 Make_Expanded_Name (Sloc (N),
5889 Prefix => New_Copy (Prefix (Prefix (N))),
5890 Selector_Name => New_Reference_To (T, Sloc (N))));
5893 Rewrite (N, New_Reference_To (T, Sloc (N)));
5900 elsif Attribute_Name (N) = Name_Stub_Type then
5902 -- This is handled in Analyze_Attribute
5906 -- All other attributes are invalid in a subtype mark
5909 Error_Msg_N ("invalid attribute in subtype mark", N);
5915 if Is_Entity_Name (N) then
5916 T_Name := Entity (N);
5918 Error_Msg_N ("subtype mark required in this context", N);
5919 Set_Etype (N, Any_Type);
5923 if T_Name = Any_Id or else Etype (N) = Any_Type then
5925 -- Undefined id. Make it into a valid type
5927 Set_Entity (N, Any_Type);
5929 elsif not Is_Type (T_Name)
5930 and then T_Name /= Standard_Void_Type
5932 Error_Msg_Sloc := Sloc (T_Name);
5933 Error_Msg_N ("subtype mark required in this context", N);
5934 Error_Msg_NE ("\\found & declared#", N, T_Name);
5935 Set_Entity (N, Any_Type);
5938 -- If the type is an incomplete type created to handle
5939 -- anonymous access components of a record type, then the
5940 -- incomplete type is the visible entity and subsequent
5941 -- references will point to it. Mark the original full
5942 -- type as referenced, to prevent spurious warnings.
5944 if Is_Incomplete_Type (T_Name)
5945 and then Present (Full_View (T_Name))
5946 and then not Comes_From_Source (T_Name)
5948 Set_Referenced (Full_View (T_Name));
5951 T_Name := Get_Full_View (T_Name);
5953 -- Ada 2005 (AI-251, AI-50217): Handle interfaces visible through
5954 -- limited-with clauses
5956 if From_With_Type (T_Name)
5957 and then Ekind (T_Name) in Incomplete_Kind
5958 and then Present (Non_Limited_View (T_Name))
5959 and then Is_Interface (Non_Limited_View (T_Name))
5961 T_Name := Non_Limited_View (T_Name);
5964 if In_Open_Scopes (T_Name) then
5965 if Ekind (Base_Type (T_Name)) = E_Task_Type then
5967 -- In Ada 2005, a task name can be used in an access
5968 -- definition within its own body. It cannot be used
5969 -- in the discriminant part of the task declaration,
5970 -- nor anywhere else in the declaration because entries
5971 -- cannot have access parameters.
5973 if Ada_Version >= Ada_2005
5974 and then Nkind (Parent (N)) = N_Access_Definition
5976 Set_Entity (N, T_Name);
5977 Set_Etype (N, T_Name);
5979 if Has_Completion (T_Name) then
5984 ("task type cannot be used as type mark " &
5985 "within its own declaration", N);
5990 ("task type cannot be used as type mark " &
5991 "within its own spec or body", N);
5994 elsif Ekind (Base_Type (T_Name)) = E_Protected_Type then
5996 -- In Ada 2005, a protected name can be used in an access
5997 -- definition within its own body.
5999 if Ada_Version >= Ada_2005
6000 and then Nkind (Parent (N)) = N_Access_Definition
6002 Set_Entity (N, T_Name);
6003 Set_Etype (N, T_Name);
6008 ("protected type cannot be used as type mark " &
6009 "within its own spec or body", N);
6013 Error_Msg_N ("type declaration cannot refer to itself", N);
6016 Set_Etype (N, Any_Type);
6017 Set_Entity (N, Any_Type);
6018 Set_Error_Posted (T_Name);
6022 Set_Entity (N, T_Name);
6023 Set_Etype (N, T_Name);
6027 if Present (Etype (N)) and then Comes_From_Source (N) then
6028 if Is_Fixed_Point_Type (Etype (N)) then
6029 Check_Restriction (No_Fixed_Point, N);
6030 elsif Is_Floating_Point_Type (Etype (N)) then
6031 Check_Restriction (No_Floating_Point, N);
6036 ------------------------------------
6037 -- Has_Implicit_Character_Literal --
6038 ------------------------------------
6040 function Has_Implicit_Character_Literal (N : Node_Id) return Boolean is
6042 Found : Boolean := False;
6043 P : constant Entity_Id := Entity (Prefix (N));
6044 Priv_Id : Entity_Id := Empty;
6047 if Ekind (P) = E_Package
6048 and then not In_Open_Scopes (P)
6050 Priv_Id := First_Private_Entity (P);
6053 if P = Standard_Standard then
6054 Change_Selected_Component_To_Expanded_Name (N);
6055 Rewrite (N, Selector_Name (N));
6057 Set_Etype (Original_Node (N), Standard_Character);
6061 Id := First_Entity (P);
6063 and then Id /= Priv_Id
6065 if Is_Standard_Character_Type (Id) and then Is_Base_Type (Id) then
6067 -- We replace the node with the literal itself, resolve as a
6068 -- character, and set the type correctly.
6071 Change_Selected_Component_To_Expanded_Name (N);
6072 Rewrite (N, Selector_Name (N));
6075 Set_Etype (Original_Node (N), Id);
6079 -- More than one type derived from Character in given scope.
6080 -- Collect all possible interpretations.
6082 Add_One_Interp (N, Id, Id);
6090 end Has_Implicit_Character_Literal;
6092 ----------------------
6093 -- Has_Private_With --
6094 ----------------------
6096 function Has_Private_With (E : Entity_Id) return Boolean is
6097 Comp_Unit : constant Node_Id := Cunit (Current_Sem_Unit);
6101 Item := First (Context_Items (Comp_Unit));
6102 while Present (Item) loop
6103 if Nkind (Item) = N_With_Clause
6104 and then Private_Present (Item)
6105 and then Entity (Name (Item)) = E
6114 end Has_Private_With;
6116 ---------------------------
6117 -- Has_Implicit_Operator --
6118 ---------------------------
6120 function Has_Implicit_Operator (N : Node_Id) return Boolean is
6121 Op_Id : constant Name_Id := Chars (Selector_Name (N));
6122 P : constant Entity_Id := Entity (Prefix (N));
6124 Priv_Id : Entity_Id := Empty;
6126 procedure Add_Implicit_Operator
6128 Op_Type : Entity_Id := Empty);
6129 -- Add implicit interpretation to node N, using the type for which a
6130 -- predefined operator exists. If the operator yields a boolean type,
6131 -- the Operand_Type is implicitly referenced by the operator, and a
6132 -- reference to it must be generated.
6134 ---------------------------
6135 -- Add_Implicit_Operator --
6136 ---------------------------
6138 procedure Add_Implicit_Operator
6140 Op_Type : Entity_Id := Empty)
6142 Predef_Op : Entity_Id;
6145 Predef_Op := Current_Entity (Selector_Name (N));
6147 while Present (Predef_Op)
6148 and then Scope (Predef_Op) /= Standard_Standard
6150 Predef_Op := Homonym (Predef_Op);
6153 if Nkind (N) = N_Selected_Component then
6154 Change_Selected_Component_To_Expanded_Name (N);
6157 -- If the context is an unanalyzed function call, determine whether
6158 -- a binary or unary interpretation is required.
6160 if Nkind (Parent (N)) = N_Indexed_Component then
6162 Is_Binary_Call : constant Boolean :=
6164 (Next (First (Expressions (Parent (N)))));
6165 Is_Binary_Op : constant Boolean :=
6167 (Predef_Op) /= Last_Entity (Predef_Op);
6168 Predef_Op2 : constant Entity_Id := Homonym (Predef_Op);
6171 if Is_Binary_Call then
6172 if Is_Binary_Op then
6173 Add_One_Interp (N, Predef_Op, T);
6175 Add_One_Interp (N, Predef_Op2, T);
6179 if not Is_Binary_Op then
6180 Add_One_Interp (N, Predef_Op, T);
6182 Add_One_Interp (N, Predef_Op2, T);
6188 Add_One_Interp (N, Predef_Op, T);
6190 -- For operators with unary and binary interpretations, if
6191 -- context is not a call, add both
6193 if Present (Homonym (Predef_Op)) then
6194 Add_One_Interp (N, Homonym (Predef_Op), T);
6198 -- The node is a reference to a predefined operator, and
6199 -- an implicit reference to the type of its operands.
6201 if Present (Op_Type) then
6202 Generate_Operator_Reference (N, Op_Type);
6204 Generate_Operator_Reference (N, T);
6206 end Add_Implicit_Operator;
6208 -- Start of processing for Has_Implicit_Operator
6211 if Ekind (P) = E_Package
6212 and then not In_Open_Scopes (P)
6214 Priv_Id := First_Private_Entity (P);
6217 Id := First_Entity (P);
6221 -- Boolean operators: an implicit declaration exists if the scope
6222 -- contains a declaration for a derived Boolean type, or for an
6223 -- array of Boolean type.
6225 when Name_Op_And | Name_Op_Not | Name_Op_Or | Name_Op_Xor =>
6226 while Id /= Priv_Id loop
6227 if Valid_Boolean_Arg (Id) and then Is_Base_Type (Id) then
6228 Add_Implicit_Operator (Id);
6235 -- Equality: look for any non-limited type (result is Boolean)
6237 when Name_Op_Eq | Name_Op_Ne =>
6238 while Id /= Priv_Id loop
6240 and then not Is_Limited_Type (Id)
6241 and then Is_Base_Type (Id)
6243 Add_Implicit_Operator (Standard_Boolean, Id);
6250 -- Comparison operators: scalar type, or array of scalar
6252 when Name_Op_Lt | Name_Op_Le | Name_Op_Gt | Name_Op_Ge =>
6253 while Id /= Priv_Id loop
6254 if (Is_Scalar_Type (Id)
6255 or else (Is_Array_Type (Id)
6256 and then Is_Scalar_Type (Component_Type (Id))))
6257 and then Is_Base_Type (Id)
6259 Add_Implicit_Operator (Standard_Boolean, Id);
6266 -- Arithmetic operators: any numeric type
6276 while Id /= Priv_Id loop
6277 if Is_Numeric_Type (Id) and then Is_Base_Type (Id) then
6278 Add_Implicit_Operator (Id);
6285 -- Concatenation: any one-dimensional array type
6287 when Name_Op_Concat =>
6288 while Id /= Priv_Id loop
6289 if Is_Array_Type (Id)
6290 and then Number_Dimensions (Id) = 1
6291 and then Is_Base_Type (Id)
6293 Add_Implicit_Operator (Id);
6300 -- What is the others condition here? Should we be using a
6301 -- subtype of Name_Id that would restrict to operators ???
6303 when others => null;
6306 -- If we fall through, then we do not have an implicit operator
6310 end Has_Implicit_Operator;
6312 -----------------------------------
6313 -- Has_Loop_In_Inner_Open_Scopes --
6314 -----------------------------------
6316 function Has_Loop_In_Inner_Open_Scopes (S : Entity_Id) return Boolean is
6318 -- Several scope stacks are maintained by Scope_Stack. The base of the
6319 -- currently active scope stack is denoted by the Is_Active_Stack_Base
6320 -- flag in the scope stack entry. Note that the scope stacks used to
6321 -- simply be delimited implicitly by the presence of Standard_Standard
6322 -- at their base, but there now are cases where this is not sufficient
6323 -- because Standard_Standard actually may appear in the middle of the
6324 -- active set of scopes.
6326 for J in reverse 0 .. Scope_Stack.Last loop
6328 -- S was reached without seing a loop scope first
6330 if Scope_Stack.Table (J).Entity = S then
6333 -- S was not yet reached, so it contains at least one inner loop
6335 elsif Ekind (Scope_Stack.Table (J).Entity) = E_Loop then
6339 -- Check Is_Active_Stack_Base to tell us when to stop, as there are
6340 -- cases where Standard_Standard appears in the middle of the active
6341 -- set of scopes. This affects the declaration and overriding of
6342 -- private inherited operations in instantiations of generic child
6345 pragma Assert (not Scope_Stack.Table (J).Is_Active_Stack_Base);
6348 raise Program_Error; -- unreachable
6349 end Has_Loop_In_Inner_Open_Scopes;
6351 --------------------
6352 -- In_Open_Scopes --
6353 --------------------
6355 function In_Open_Scopes (S : Entity_Id) return Boolean is
6357 -- Several scope stacks are maintained by Scope_Stack. The base of the
6358 -- currently active scope stack is denoted by the Is_Active_Stack_Base
6359 -- flag in the scope stack entry. Note that the scope stacks used to
6360 -- simply be delimited implicitly by the presence of Standard_Standard
6361 -- at their base, but there now are cases where this is not sufficient
6362 -- because Standard_Standard actually may appear in the middle of the
6363 -- active set of scopes.
6365 for J in reverse 0 .. Scope_Stack.Last loop
6366 if Scope_Stack.Table (J).Entity = S then
6370 -- Check Is_Active_Stack_Base to tell us when to stop, as there are
6371 -- cases where Standard_Standard appears in the middle of the active
6372 -- set of scopes. This affects the declaration and overriding of
6373 -- private inherited operations in instantiations of generic child
6376 exit when Scope_Stack.Table (J).Is_Active_Stack_Base;
6382 -----------------------------
6383 -- Inherit_Renamed_Profile --
6384 -----------------------------
6386 procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id) is
6393 if Ekind (Old_S) = E_Operator then
6394 New_F := First_Formal (New_S);
6396 while Present (New_F) loop
6397 Set_Etype (New_F, Base_Type (Etype (New_F)));
6398 Next_Formal (New_F);
6401 Set_Etype (New_S, Base_Type (Etype (New_S)));
6404 New_F := First_Formal (New_S);
6405 Old_F := First_Formal (Old_S);
6407 while Present (New_F) loop
6408 New_T := Etype (New_F);
6409 Old_T := Etype (Old_F);
6411 -- If the new type is a renaming of the old one, as is the
6412 -- case for actuals in instances, retain its name, to simplify
6413 -- later disambiguation.
6415 if Nkind (Parent (New_T)) = N_Subtype_Declaration
6416 and then Is_Entity_Name (Subtype_Indication (Parent (New_T)))
6417 and then Entity (Subtype_Indication (Parent (New_T))) = Old_T
6421 Set_Etype (New_F, Old_T);
6424 Next_Formal (New_F);
6425 Next_Formal (Old_F);
6428 if Ekind_In (Old_S, E_Function, E_Enumeration_Literal) then
6429 Set_Etype (New_S, Etype (Old_S));
6432 end Inherit_Renamed_Profile;
6438 procedure Initialize is
6443 -------------------------
6444 -- Install_Use_Clauses --
6445 -------------------------
6447 procedure Install_Use_Clauses
6449 Force_Installation : Boolean := False)
6457 while Present (U) loop
6459 -- Case of USE package
6461 if Nkind (U) = N_Use_Package_Clause then
6462 P := First (Names (U));
6463 while Present (P) loop
6466 if Ekind (Id) = E_Package then
6468 Note_Redundant_Use (P);
6470 elsif Present (Renamed_Object (Id))
6471 and then In_Use (Renamed_Object (Id))
6473 Note_Redundant_Use (P);
6475 elsif Force_Installation or else Applicable_Use (P) then
6476 Use_One_Package (Id, U);
6487 P := First (Subtype_Marks (U));
6488 while Present (P) loop
6489 if not Is_Entity_Name (P)
6490 or else No (Entity (P))
6494 elsif Entity (P) /= Any_Type then
6502 Next_Use_Clause (U);
6504 end Install_Use_Clauses;
6506 -------------------------------------
6507 -- Is_Appropriate_For_Entry_Prefix --
6508 -------------------------------------
6510 function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean is
6511 P_Type : Entity_Id := T;
6514 if Is_Access_Type (P_Type) then
6515 P_Type := Designated_Type (P_Type);
6518 return Is_Task_Type (P_Type) or else Is_Protected_Type (P_Type);
6519 end Is_Appropriate_For_Entry_Prefix;
6521 -------------------------------
6522 -- Is_Appropriate_For_Record --
6523 -------------------------------
6525 function Is_Appropriate_For_Record (T : Entity_Id) return Boolean is
6527 function Has_Components (T1 : Entity_Id) return Boolean;
6528 -- Determine if given type has components (i.e. is either a record
6529 -- type or a type that has discriminants).
6531 --------------------
6532 -- Has_Components --
6533 --------------------
6535 function Has_Components (T1 : Entity_Id) return Boolean is
6537 return Is_Record_Type (T1)
6538 or else (Is_Private_Type (T1) and then Has_Discriminants (T1))
6539 or else (Is_Task_Type (T1) and then Has_Discriminants (T1))
6540 or else (Is_Incomplete_Type (T1)
6541 and then From_With_Type (T1)
6542 and then Present (Non_Limited_View (T1))
6543 and then Is_Record_Type
6544 (Get_Full_View (Non_Limited_View (T1))));
6547 -- Start of processing for Is_Appropriate_For_Record
6552 and then (Has_Components (T)
6553 or else (Is_Access_Type (T)
6554 and then Has_Components (Designated_Type (T))));
6555 end Is_Appropriate_For_Record;
6557 ------------------------
6558 -- Note_Redundant_Use --
6559 ------------------------
6561 procedure Note_Redundant_Use (Clause : Node_Id) is
6562 Pack_Name : constant Entity_Id := Entity (Clause);
6563 Cur_Use : constant Node_Id := Current_Use_Clause (Pack_Name);
6564 Decl : constant Node_Id := Parent (Clause);
6566 Prev_Use : Node_Id := Empty;
6567 Redundant : Node_Id := Empty;
6568 -- The Use_Clause which is actually redundant. In the simplest case it
6569 -- is Pack itself, but when we compile a body we install its context
6570 -- before that of its spec, in which case it is the use_clause in the
6571 -- spec that will appear to be redundant, and we want the warning to be
6572 -- placed on the body. Similar complications appear when the redundancy
6573 -- is between a child unit and one of its ancestors.
6576 Set_Redundant_Use (Clause, True);
6578 if not Comes_From_Source (Clause)
6580 or else not Warn_On_Redundant_Constructs
6585 if not Is_Compilation_Unit (Current_Scope) then
6587 -- If the use_clause is in an inner scope, it is made redundant by
6588 -- some clause in the current context, with one exception: If we're
6589 -- compiling a nested package body, and the use_clause comes from the
6590 -- corresponding spec, the clause is not necessarily fully redundant,
6591 -- so we should not warn. If a warning was warranted, it would have
6592 -- been given when the spec was processed.
6594 if Nkind (Parent (Decl)) = N_Package_Specification then
6596 Package_Spec_Entity : constant Entity_Id :=
6597 Defining_Unit_Name (Parent (Decl));
6599 if In_Package_Body (Package_Spec_Entity) then
6605 Redundant := Clause;
6606 Prev_Use := Cur_Use;
6608 elsif Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body then
6610 Cur_Unit : constant Unit_Number_Type := Get_Source_Unit (Cur_Use);
6611 New_Unit : constant Unit_Number_Type := Get_Source_Unit (Clause);
6615 if Cur_Unit = New_Unit then
6617 -- Redundant clause in same body
6619 Redundant := Clause;
6620 Prev_Use := Cur_Use;
6622 elsif Cur_Unit = Current_Sem_Unit then
6624 -- If the new clause is not in the current unit it has been
6625 -- analyzed first, and it makes the other one redundant.
6626 -- However, if the new clause appears in a subunit, Cur_Unit
6627 -- is still the parent, and in that case the redundant one
6628 -- is the one appearing in the subunit.
6630 if Nkind (Unit (Cunit (New_Unit))) = N_Subunit then
6631 Redundant := Clause;
6632 Prev_Use := Cur_Use;
6634 -- Most common case: redundant clause in body,
6635 -- original clause in spec. Current scope is spec entity.
6640 Unit (Library_Unit (Cunit (Current_Sem_Unit))))
6642 Redundant := Cur_Use;
6646 -- The new clause may appear in an unrelated unit, when
6647 -- the parents of a generic are being installed prior to
6648 -- instantiation. In this case there must be no warning.
6649 -- We detect this case by checking whether the current top
6650 -- of the stack is related to the current compilation.
6652 Scop := Current_Scope;
6653 while Present (Scop)
6654 and then Scop /= Standard_Standard
6656 if Is_Compilation_Unit (Scop)
6657 and then not Is_Child_Unit (Scop)
6661 elsif Scop = Cunit_Entity (Current_Sem_Unit) then
6665 Scop := Scope (Scop);
6668 Redundant := Cur_Use;
6672 elsif New_Unit = Current_Sem_Unit then
6673 Redundant := Clause;
6674 Prev_Use := Cur_Use;
6677 -- Neither is the current unit, so they appear in parent or
6678 -- sibling units. Warning will be emitted elsewhere.
6684 elsif Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
6685 and then Present (Parent_Spec (Unit (Cunit (Current_Sem_Unit))))
6687 -- Use_clause is in child unit of current unit, and the child unit
6688 -- appears in the context of the body of the parent, so it has been
6689 -- installed first, even though it is the redundant one. Depending on
6690 -- their placement in the context, the visible or the private parts
6691 -- of the two units, either might appear as redundant, but the
6692 -- message has to be on the current unit.
6694 if Get_Source_Unit (Cur_Use) = Current_Sem_Unit then
6695 Redundant := Cur_Use;
6698 Redundant := Clause;
6699 Prev_Use := Cur_Use;
6702 -- If the new use clause appears in the private part of a parent unit
6703 -- it may appear to be redundant w.r.t. a use clause in a child unit,
6704 -- but the previous use clause was needed in the visible part of the
6705 -- child, and no warning should be emitted.
6707 if Nkind (Parent (Decl)) = N_Package_Specification
6709 List_Containing (Decl) = Private_Declarations (Parent (Decl))
6712 Par : constant Entity_Id := Defining_Entity (Parent (Decl));
6713 Spec : constant Node_Id :=
6714 Specification (Unit (Cunit (Current_Sem_Unit)));
6717 if Is_Compilation_Unit (Par)
6718 and then Par /= Cunit_Entity (Current_Sem_Unit)
6719 and then Parent (Cur_Use) = Spec
6721 List_Containing (Cur_Use) = Visible_Declarations (Spec)
6728 -- Finally, if the current use clause is in the context then
6729 -- the clause is redundant when it is nested within the unit.
6731 elsif Nkind (Parent (Cur_Use)) = N_Compilation_Unit
6732 and then Nkind (Parent (Parent (Clause))) /= N_Compilation_Unit
6733 and then Get_Source_Unit (Cur_Use) = Get_Source_Unit (Clause)
6735 Redundant := Clause;
6736 Prev_Use := Cur_Use;
6742 if Present (Redundant) then
6743 Error_Msg_Sloc := Sloc (Prev_Use);
6744 Error_Msg_NE -- CODEFIX
6745 ("& is already use-visible through previous use clause #?",
6746 Redundant, Pack_Name);
6748 end Note_Redundant_Use;
6754 procedure Pop_Scope is
6755 SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
6756 S : constant Entity_Id := SST.Entity;
6759 if Debug_Flag_E then
6763 -- Set Default_Storage_Pool field of the library unit if necessary
6765 if Ekind_In (S, E_Package, E_Generic_Package)
6767 Nkind (Parent (Unit_Declaration_Node (S))) = N_Compilation_Unit
6770 Aux : constant Node_Id :=
6771 Aux_Decls_Node (Parent (Unit_Declaration_Node (S)));
6773 if No (Default_Storage_Pool (Aux)) then
6774 Set_Default_Storage_Pool (Aux, Default_Pool);
6779 Scope_Suppress := SST.Save_Scope_Suppress;
6780 Local_Suppress_Stack_Top := SST.Save_Local_Suppress_Stack_Top;
6781 Check_Policy_List := SST.Save_Check_Policy_List;
6782 Default_Pool := SST.Save_Default_Storage_Pool;
6784 if Debug_Flag_W then
6785 Write_Str ("<-- exiting scope: ");
6786 Write_Name (Chars (Current_Scope));
6787 Write_Str (", Depth=");
6788 Write_Int (Int (Scope_Stack.Last));
6792 End_Use_Clauses (SST.First_Use_Clause);
6794 -- If the actions to be wrapped are still there they will get lost
6795 -- causing incomplete code to be generated. It is better to abort in
6796 -- this case (and we do the abort even with assertions off since the
6797 -- penalty is incorrect code generation)
6799 if SST.Actions_To_Be_Wrapped_Before /= No_List
6801 SST.Actions_To_Be_Wrapped_After /= No_List
6803 raise Program_Error;
6806 -- Free last subprogram name if allocated, and pop scope
6808 Free (SST.Last_Subprogram_Name);
6809 Scope_Stack.Decrement_Last;
6816 procedure Push_Scope (S : Entity_Id) is
6817 E : constant Entity_Id := Scope (S);
6820 if Ekind (S) = E_Void then
6823 -- Set scope depth if not a non-concurrent type, and we have not yet set
6824 -- the scope depth. This means that we have the first occurrence of the
6825 -- scope, and this is where the depth is set.
6827 elsif (not Is_Type (S) or else Is_Concurrent_Type (S))
6828 and then not Scope_Depth_Set (S)
6830 if S = Standard_Standard then
6831 Set_Scope_Depth_Value (S, Uint_0);
6833 elsif Is_Child_Unit (S) then
6834 Set_Scope_Depth_Value (S, Uint_1);
6836 elsif not Is_Record_Type (Current_Scope) then
6837 if Ekind (S) = E_Loop then
6838 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope));
6840 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope) + 1);
6845 Scope_Stack.Increment_Last;
6848 SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
6852 SST.Save_Scope_Suppress := Scope_Suppress;
6853 SST.Save_Local_Suppress_Stack_Top := Local_Suppress_Stack_Top;
6854 SST.Save_Check_Policy_List := Check_Policy_List;
6855 SST.Save_Default_Storage_Pool := Default_Pool;
6857 if Scope_Stack.Last > Scope_Stack.First then
6858 SST.Component_Alignment_Default := Scope_Stack.Table
6859 (Scope_Stack.Last - 1).
6860 Component_Alignment_Default;
6863 SST.Last_Subprogram_Name := null;
6864 SST.Is_Transient := False;
6865 SST.Node_To_Be_Wrapped := Empty;
6866 SST.Pending_Freeze_Actions := No_List;
6867 SST.Actions_To_Be_Wrapped_Before := No_List;
6868 SST.Actions_To_Be_Wrapped_After := No_List;
6869 SST.First_Use_Clause := Empty;
6870 SST.Is_Active_Stack_Base := False;
6871 SST.Previous_Visibility := False;
6874 if Debug_Flag_W then
6875 Write_Str ("--> new scope: ");
6876 Write_Name (Chars (Current_Scope));
6877 Write_Str (", Id=");
6878 Write_Int (Int (Current_Scope));
6879 Write_Str (", Depth=");
6880 Write_Int (Int (Scope_Stack.Last));
6884 -- Deal with copying flags from the previous scope to this one. This is
6885 -- not necessary if either scope is standard, or if the new scope is a
6888 if S /= Standard_Standard
6889 and then Scope (S) /= Standard_Standard
6890 and then not Is_Child_Unit (S)
6892 if Nkind (E) not in N_Entity then
6896 -- Copy categorization flags from Scope (S) to S, this is not done
6897 -- when Scope (S) is Standard_Standard since propagation is from
6898 -- library unit entity inwards. Copy other relevant attributes as
6899 -- well (Discard_Names in particular).
6901 -- We only propagate inwards for library level entities,
6902 -- inner level subprograms do not inherit the categorization.
6904 if Is_Library_Level_Entity (S) then
6905 Set_Is_Preelaborated (S, Is_Preelaborated (E));
6906 Set_Is_Shared_Passive (S, Is_Shared_Passive (E));
6907 Set_Discard_Names (S, Discard_Names (E));
6908 Set_Suppress_Value_Tracking_On_Call
6909 (S, Suppress_Value_Tracking_On_Call (E));
6910 Set_Categorization_From_Scope (E => S, Scop => E);
6914 if Is_Child_Unit (S)
6915 and then Present (E)
6916 and then Ekind_In (E, E_Package, E_Generic_Package)
6918 Nkind (Parent (Unit_Declaration_Node (E))) = N_Compilation_Unit
6921 Aux : constant Node_Id :=
6922 Aux_Decls_Node (Parent (Unit_Declaration_Node (E)));
6924 if Present (Default_Storage_Pool (Aux)) then
6925 Default_Pool := Default_Storage_Pool (Aux);
6931 ---------------------
6932 -- Premature_Usage --
6933 ---------------------
6935 procedure Premature_Usage (N : Node_Id) is
6936 Kind : constant Node_Kind := Nkind (Parent (Entity (N)));
6937 E : Entity_Id := Entity (N);
6940 -- Within an instance, the analysis of the actual for a formal object
6941 -- does not see the name of the object itself. This is significant only
6942 -- if the object is an aggregate, where its analysis does not do any
6943 -- name resolution on component associations. (see 4717-008). In such a
6944 -- case, look for the visible homonym on the chain.
6947 and then Present (Homonym (E))
6952 and then not In_Open_Scopes (Scope (E))
6959 Set_Etype (N, Etype (E));
6964 if Kind = N_Component_Declaration then
6966 ("component&! cannot be used before end of record declaration", N);
6968 elsif Kind = N_Parameter_Specification then
6970 ("formal parameter&! cannot be used before end of specification",
6973 elsif Kind = N_Discriminant_Specification then
6975 ("discriminant&! cannot be used before end of discriminant part",
6978 elsif Kind = N_Procedure_Specification
6979 or else Kind = N_Function_Specification
6982 ("subprogram&! cannot be used before end of its declaration",
6985 elsif Kind = N_Full_Type_Declaration then
6987 ("type& cannot be used before end of its declaration!", N);
6991 ("object& cannot be used before end of its declaration!", N);
6993 end Premature_Usage;
6995 ------------------------
6996 -- Present_System_Aux --
6997 ------------------------
6999 function Present_System_Aux (N : Node_Id := Empty) return Boolean is
7001 Aux_Name : Unit_Name_Type;
7002 Unum : Unit_Number_Type;
7007 function Find_System (C_Unit : Node_Id) return Entity_Id;
7008 -- Scan context clause of compilation unit to find with_clause
7015 function Find_System (C_Unit : Node_Id) return Entity_Id is
7016 With_Clause : Node_Id;
7019 With_Clause := First (Context_Items (C_Unit));
7020 while Present (With_Clause) loop
7021 if (Nkind (With_Clause) = N_With_Clause
7022 and then Chars (Name (With_Clause)) = Name_System)
7023 and then Comes_From_Source (With_Clause)
7034 -- Start of processing for Present_System_Aux
7037 -- The child unit may have been loaded and analyzed already
7039 if Present (System_Aux_Id) then
7042 -- If no previous pragma for System.Aux, nothing to load
7044 elsif No (System_Extend_Unit) then
7047 -- Use the unit name given in the pragma to retrieve the unit.
7048 -- Verify that System itself appears in the context clause of the
7049 -- current compilation. If System is not present, an error will
7050 -- have been reported already.
7053 With_Sys := Find_System (Cunit (Current_Sem_Unit));
7055 The_Unit := Unit (Cunit (Current_Sem_Unit));
7059 (Nkind (The_Unit) = N_Package_Body
7060 or else (Nkind (The_Unit) = N_Subprogram_Body
7062 not Acts_As_Spec (Cunit (Current_Sem_Unit))))
7064 With_Sys := Find_System (Library_Unit (Cunit (Current_Sem_Unit)));
7068 and then Present (N)
7070 -- If we are compiling a subunit, we need to examine its
7071 -- context as well (Current_Sem_Unit is the parent unit);
7073 The_Unit := Parent (N);
7074 while Nkind (The_Unit) /= N_Compilation_Unit loop
7075 The_Unit := Parent (The_Unit);
7078 if Nkind (Unit (The_Unit)) = N_Subunit then
7079 With_Sys := Find_System (The_Unit);
7083 if No (With_Sys) then
7087 Loc := Sloc (With_Sys);
7088 Get_Name_String (Chars (Expression (System_Extend_Unit)));
7089 Name_Buffer (8 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
7090 Name_Buffer (1 .. 7) := "system.";
7091 Name_Buffer (Name_Len + 8) := '%';
7092 Name_Buffer (Name_Len + 9) := 's';
7093 Name_Len := Name_Len + 9;
7094 Aux_Name := Name_Find;
7098 (Load_Name => Aux_Name,
7101 Error_Node => With_Sys);
7103 if Unum /= No_Unit then
7104 Semantics (Cunit (Unum));
7106 Defining_Entity (Specification (Unit (Cunit (Unum))));
7109 Make_With_Clause (Loc,
7111 Make_Expanded_Name (Loc,
7112 Chars => Chars (System_Aux_Id),
7113 Prefix => New_Reference_To (Scope (System_Aux_Id), Loc),
7114 Selector_Name => New_Reference_To (System_Aux_Id, Loc)));
7116 Set_Entity (Name (Withn), System_Aux_Id);
7118 Set_Library_Unit (Withn, Cunit (Unum));
7119 Set_Corresponding_Spec (Withn, System_Aux_Id);
7120 Set_First_Name (Withn, True);
7121 Set_Implicit_With (Withn, True);
7123 Insert_After (With_Sys, Withn);
7124 Mark_Rewrite_Insertion (Withn);
7125 Set_Context_Installed (Withn);
7129 -- Here if unit load failed
7132 Error_Msg_Name_1 := Name_System;
7133 Error_Msg_Name_2 := Chars (Expression (System_Extend_Unit));
7135 ("extension package `%.%` does not exist",
7136 Opt.System_Extend_Unit);
7140 end Present_System_Aux;
7142 -------------------------
7143 -- Restore_Scope_Stack --
7144 -------------------------
7146 procedure Restore_Scope_Stack (Handle_Use : Boolean := True) is
7149 Comp_Unit : Node_Id;
7150 In_Child : Boolean := False;
7151 Full_Vis : Boolean := True;
7152 SS_Last : constant Int := Scope_Stack.Last;
7155 -- Restore visibility of previous scope stack, if any
7157 for J in reverse 0 .. Scope_Stack.Last loop
7158 exit when Scope_Stack.Table (J).Entity = Standard_Standard
7159 or else No (Scope_Stack.Table (J).Entity);
7161 S := Scope_Stack.Table (J).Entity;
7163 if not Is_Hidden_Open_Scope (S) then
7165 -- If the parent scope is hidden, its entities are hidden as
7166 -- well, unless the entity is the instantiation currently
7169 if not Is_Hidden_Open_Scope (Scope (S))
7170 or else not Analyzed (Parent (S))
7171 or else Scope (S) = Standard_Standard
7173 Set_Is_Immediately_Visible (S, True);
7176 E := First_Entity (S);
7177 while Present (E) loop
7178 if Is_Child_Unit (E) then
7179 if not From_With_Type (E) then
7180 Set_Is_Immediately_Visible (E,
7181 Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
7185 (Nkind (Parent (E)) = N_Defining_Program_Unit_Name
7187 Nkind (Parent (Parent (E))) = N_Package_Specification);
7188 Set_Is_Immediately_Visible (E,
7189 Limited_View_Installed (Parent (Parent (E))));
7192 Set_Is_Immediately_Visible (E, True);
7198 and then Is_Package_Or_Generic_Package (S)
7200 -- We are in the visible part of the package scope
7202 exit when E = First_Private_Entity (S);
7206 -- The visibility of child units (siblings of current compilation)
7207 -- must be restored in any case. Their declarations may appear
7208 -- after the private part of the parent.
7210 if not Full_Vis then
7211 while Present (E) loop
7212 if Is_Child_Unit (E) then
7213 Set_Is_Immediately_Visible (E,
7214 Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
7222 if Is_Child_Unit (S)
7223 and not In_Child -- check only for current unit
7227 -- Restore visibility of parents according to whether the child
7228 -- is private and whether we are in its visible part.
7230 Comp_Unit := Parent (Unit_Declaration_Node (S));
7232 if Nkind (Comp_Unit) = N_Compilation_Unit
7233 and then Private_Present (Comp_Unit)
7237 elsif Is_Package_Or_Generic_Package (S)
7238 and then (In_Private_Part (S) or else In_Package_Body (S))
7242 -- if S is the scope of some instance (which has already been
7243 -- seen on the stack) it does not affect the visibility of
7246 elsif Is_Hidden_Open_Scope (S) then
7249 elsif (Ekind (S) = E_Procedure
7250 or else Ekind (S) = E_Function)
7251 and then Has_Completion (S)
7262 if SS_Last >= Scope_Stack.First
7263 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
7266 Install_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
7268 end Restore_Scope_Stack;
7270 ----------------------
7271 -- Save_Scope_Stack --
7272 ----------------------
7274 procedure Save_Scope_Stack (Handle_Use : Boolean := True) is
7277 SS_Last : constant Int := Scope_Stack.Last;
7280 if SS_Last >= Scope_Stack.First
7281 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
7284 End_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
7287 -- If the call is from within a compilation unit, as when called from
7288 -- Rtsfind, make current entries in scope stack invisible while we
7289 -- analyze the new unit.
7291 for J in reverse 0 .. SS_Last loop
7292 exit when Scope_Stack.Table (J).Entity = Standard_Standard
7293 or else No (Scope_Stack.Table (J).Entity);
7295 S := Scope_Stack.Table (J).Entity;
7296 Set_Is_Immediately_Visible (S, False);
7298 E := First_Entity (S);
7299 while Present (E) loop
7300 Set_Is_Immediately_Visible (E, False);
7306 end Save_Scope_Stack;
7312 procedure Set_Use (L : List_Id) is
7314 Pack_Name : Node_Id;
7321 while Present (Decl) loop
7322 if Nkind (Decl) = N_Use_Package_Clause then
7323 Chain_Use_Clause (Decl);
7325 Pack_Name := First (Names (Decl));
7326 while Present (Pack_Name) loop
7327 Pack := Entity (Pack_Name);
7329 if Ekind (Pack) = E_Package
7330 and then Applicable_Use (Pack_Name)
7332 Use_One_Package (Pack, Decl);
7338 elsif Nkind (Decl) = N_Use_Type_Clause then
7339 Chain_Use_Clause (Decl);
7341 Id := First (Subtype_Marks (Decl));
7342 while Present (Id) loop
7343 if Entity (Id) /= Any_Type then
7356 ---------------------
7357 -- Use_One_Package --
7358 ---------------------
7360 procedure Use_One_Package (P : Entity_Id; N : Node_Id) is
7363 Current_Instance : Entity_Id := Empty;
7365 Private_With_OK : Boolean := False;
7368 if Ekind (P) /= E_Package then
7373 Set_Current_Use_Clause (P, N);
7375 -- Ada 2005 (AI-50217): Check restriction
7377 if From_With_Type (P) then
7378 Error_Msg_N ("limited withed package cannot appear in use clause", N);
7381 -- Find enclosing instance, if any
7384 Current_Instance := Current_Scope;
7385 while not Is_Generic_Instance (Current_Instance) loop
7386 Current_Instance := Scope (Current_Instance);
7389 if No (Hidden_By_Use_Clause (N)) then
7390 Set_Hidden_By_Use_Clause (N, New_Elmt_List);
7394 -- If unit is a package renaming, indicate that the renamed
7395 -- package is also in use (the flags on both entities must
7396 -- remain consistent, and a subsequent use of either of them
7397 -- should be recognized as redundant).
7399 if Present (Renamed_Object (P)) then
7400 Set_In_Use (Renamed_Object (P));
7401 Set_Current_Use_Clause (Renamed_Object (P), N);
7402 Real_P := Renamed_Object (P);
7407 -- Ada 2005 (AI-262): Check the use_clause of a private withed package
7408 -- found in the private part of a package specification
7410 if In_Private_Part (Current_Scope)
7411 and then Has_Private_With (P)
7412 and then Is_Child_Unit (Current_Scope)
7413 and then Is_Child_Unit (P)
7414 and then Is_Ancestor_Package (Scope (Current_Scope), P)
7416 Private_With_OK := True;
7419 -- Loop through entities in one package making them potentially
7422 Id := First_Entity (P);
7424 and then (Id /= First_Private_Entity (P)
7425 or else Private_With_OK) -- Ada 2005 (AI-262)
7427 Prev := Current_Entity (Id);
7428 while Present (Prev) loop
7429 if Is_Immediately_Visible (Prev)
7430 and then (not Is_Overloadable (Prev)
7431 or else not Is_Overloadable (Id)
7432 or else (Type_Conformant (Id, Prev)))
7434 if No (Current_Instance) then
7436 -- Potentially use-visible entity remains hidden
7438 goto Next_Usable_Entity;
7440 -- A use clause within an instance hides outer global entities,
7441 -- which are not used to resolve local entities in the
7442 -- instance. Note that the predefined entities in Standard
7443 -- could not have been hidden in the generic by a use clause,
7444 -- and therefore remain visible. Other compilation units whose
7445 -- entities appear in Standard must be hidden in an instance.
7447 -- To determine whether an entity is external to the instance
7448 -- we compare the scope depth of its scope with that of the
7449 -- current instance. However, a generic actual of a subprogram
7450 -- instance is declared in the wrapper package but will not be
7451 -- hidden by a use-visible entity. similarly, an entity that is
7452 -- declared in an enclosing instance will not be hidden by an
7453 -- an entity declared in a generic actual, which can only have
7454 -- been use-visible in the generic and will not have hidden the
7455 -- entity in the generic parent.
7457 -- If Id is called Standard, the predefined package with the
7458 -- same name is in the homonym chain. It has to be ignored
7459 -- because it has no defined scope (being the only entity in
7460 -- the system with this mandated behavior).
7462 elsif not Is_Hidden (Id)
7463 and then Present (Scope (Prev))
7464 and then not Is_Wrapper_Package (Scope (Prev))
7465 and then Scope_Depth (Scope (Prev)) <
7466 Scope_Depth (Current_Instance)
7467 and then (Scope (Prev) /= Standard_Standard
7468 or else Sloc (Prev) > Standard_Location)
7470 if In_Open_Scopes (Scope (Prev))
7471 and then Is_Generic_Instance (Scope (Prev))
7472 and then Present (Associated_Formal_Package (P))
7477 Set_Is_Potentially_Use_Visible (Id);
7478 Set_Is_Immediately_Visible (Prev, False);
7479 Append_Elmt (Prev, Hidden_By_Use_Clause (N));
7483 -- A user-defined operator is not use-visible if the predefined
7484 -- operator for the type is immediately visible, which is the case
7485 -- if the type of the operand is in an open scope. This does not
7486 -- apply to user-defined operators that have operands of different
7487 -- types, because the predefined mixed mode operations (multiply
7488 -- and divide) apply to universal types and do not hide anything.
7490 elsif Ekind (Prev) = E_Operator
7491 and then Operator_Matches_Spec (Prev, Id)
7492 and then In_Open_Scopes
7493 (Scope (Base_Type (Etype (First_Formal (Id)))))
7494 and then (No (Next_Formal (First_Formal (Id)))
7495 or else Etype (First_Formal (Id))
7496 = Etype (Next_Formal (First_Formal (Id)))
7497 or else Chars (Prev) = Name_Op_Expon)
7499 goto Next_Usable_Entity;
7501 -- In an instance, two homonyms may become use_visible through the
7502 -- actuals of distinct formal packages. In the generic, only the
7503 -- current one would have been visible, so make the other one
7506 elsif Present (Current_Instance)
7507 and then Is_Potentially_Use_Visible (Prev)
7508 and then not Is_Overloadable (Prev)
7509 and then Scope (Id) /= Scope (Prev)
7510 and then Used_As_Generic_Actual (Scope (Prev))
7511 and then Used_As_Generic_Actual (Scope (Id))
7512 and then not In_Same_List (Current_Use_Clause (Scope (Prev)),
7513 Current_Use_Clause (Scope (Id)))
7515 Set_Is_Potentially_Use_Visible (Prev, False);
7516 Append_Elmt (Prev, Hidden_By_Use_Clause (N));
7519 Prev := Homonym (Prev);
7522 -- On exit, we know entity is not hidden, unless it is private
7524 if not Is_Hidden (Id)
7525 and then ((not Is_Child_Unit (Id))
7526 or else Is_Visible_Child_Unit (Id))
7528 Set_Is_Potentially_Use_Visible (Id);
7530 if Is_Private_Type (Id)
7531 and then Present (Full_View (Id))
7533 Set_Is_Potentially_Use_Visible (Full_View (Id));
7537 <<Next_Usable_Entity>>
7541 -- Child units are also made use-visible by a use clause, but they may
7542 -- appear after all visible declarations in the parent entity list.
7544 while Present (Id) loop
7545 if Is_Child_Unit (Id)
7546 and then Is_Visible_Child_Unit (Id)
7548 Set_Is_Potentially_Use_Visible (Id);
7554 if Chars (Real_P) = Name_System
7555 and then Scope (Real_P) = Standard_Standard
7556 and then Present_System_Aux (N)
7558 Use_One_Package (System_Aux_Id, N);
7561 end Use_One_Package;
7567 procedure Use_One_Type (Id : Node_Id; Installed : Boolean := False) is
7569 Is_Known_Used : Boolean;
7573 function Spec_Reloaded_For_Body return Boolean;
7574 -- Determine whether the compilation unit is a package body and the use
7575 -- type clause is in the spec of the same package. Even though the spec
7576 -- was analyzed first, its context is reloaded when analysing the body.
7578 procedure Use_Class_Wide_Operations (Typ : Entity_Id);
7579 -- AI05-150: if the use_type_clause carries the "all" qualifier,
7580 -- class-wide operations of ancestor types are use-visible if the
7581 -- ancestor type is visible.
7583 ----------------------------
7584 -- Spec_Reloaded_For_Body --
7585 ----------------------------
7587 function Spec_Reloaded_For_Body return Boolean is
7589 if Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body then
7591 Spec : constant Node_Id :=
7592 Parent (List_Containing (Parent (Id)));
7595 Nkind (Spec) = N_Package_Specification
7596 and then Corresponding_Body (Parent (Spec)) =
7597 Cunit_Entity (Current_Sem_Unit);
7602 end Spec_Reloaded_For_Body;
7604 -------------------------------
7605 -- Use_Class_Wide_Operations --
7606 -------------------------------
7608 procedure Use_Class_Wide_Operations (Typ : Entity_Id) is
7612 function Is_Class_Wide_Operation_Of
7614 T : Entity_Id) return Boolean;
7615 -- Determine whether a subprogram has a class-wide parameter or
7616 -- result that is T'Class.
7618 ---------------------------------
7619 -- Is_Class_Wide_Operation_Of --
7620 ---------------------------------
7622 function Is_Class_Wide_Operation_Of
7624 T : Entity_Id) return Boolean
7629 Formal := First_Formal (Op);
7630 while Present (Formal) loop
7631 if Etype (Formal) = Class_Wide_Type (T) then
7634 Next_Formal (Formal);
7637 if Etype (Op) = Class_Wide_Type (T) then
7642 end Is_Class_Wide_Operation_Of;
7644 -- Start of processing for Use_Class_Wide_Operations
7647 Scop := Scope (Typ);
7648 if not Is_Hidden (Scop) then
7649 Ent := First_Entity (Scop);
7650 while Present (Ent) loop
7651 if Is_Overloadable (Ent)
7652 and then Is_Class_Wide_Operation_Of (Ent, Typ)
7653 and then not Is_Potentially_Use_Visible (Ent)
7655 Set_Is_Potentially_Use_Visible (Ent);
7656 Append_Elmt (Ent, Used_Operations (Parent (Id)));
7663 if Is_Derived_Type (Typ) then
7664 Use_Class_Wide_Operations (Etype (Base_Type (Typ)));
7666 end Use_Class_Wide_Operations;
7668 -- Start of processing for Use_One_Type;
7671 -- It is the type determined by the subtype mark (8.4(8)) whose
7672 -- operations become potentially use-visible.
7674 T := Base_Type (Entity (Id));
7676 -- Either the type itself is used, the package where it is declared
7677 -- is in use or the entity is declared in the current package, thus
7682 or else In_Use (Scope (T))
7683 or else Scope (T) = Current_Scope;
7685 Set_Redundant_Use (Id,
7686 Is_Known_Used or else Is_Potentially_Use_Visible (T));
7688 if Ekind (T) = E_Incomplete_Type then
7689 Error_Msg_N ("premature usage of incomplete type", Id);
7691 elsif In_Open_Scopes (Scope (T)) then
7694 -- A limited view cannot appear in a use_type clause. However, an access
7695 -- type whose designated type is limited has the flag but is not itself
7696 -- a limited view unless we only have a limited view of its enclosing
7699 elsif From_With_Type (T)
7700 and then From_With_Type (Scope (T))
7703 ("incomplete type from limited view "
7704 & "cannot appear in use clause", Id);
7706 -- If the subtype mark designates a subtype in a different package,
7707 -- we have to check that the parent type is visible, otherwise the
7708 -- use type clause is a noop. Not clear how to do that???
7710 elsif not Redundant_Use (Id) then
7713 -- If T is tagged, primitive operators on class-wide operands
7714 -- are also available.
7716 if Is_Tagged_Type (T) then
7717 Set_In_Use (Class_Wide_Type (T));
7720 Set_Current_Use_Clause (T, Parent (Id));
7722 -- Iterate over primitive operations of the type. If an operation is
7723 -- already use_visible, it is the result of a previous use_clause,
7724 -- and already appears on the corresponding entity chain. If the
7725 -- clause is being reinstalled, operations are already use-visible.
7731 Op_List := Collect_Primitive_Operations (T);
7732 Elmt := First_Elmt (Op_List);
7733 while Present (Elmt) loop
7734 if (Nkind (Node (Elmt)) = N_Defining_Operator_Symbol
7735 or else Chars (Node (Elmt)) in Any_Operator_Name)
7736 and then not Is_Hidden (Node (Elmt))
7737 and then not Is_Potentially_Use_Visible (Node (Elmt))
7739 Set_Is_Potentially_Use_Visible (Node (Elmt));
7740 Append_Elmt (Node (Elmt), Used_Operations (Parent (Id)));
7742 elsif Ada_Version >= Ada_2012
7743 and then All_Present (Parent (Id))
7744 and then not Is_Hidden (Node (Elmt))
7745 and then not Is_Potentially_Use_Visible (Node (Elmt))
7747 Set_Is_Potentially_Use_Visible (Node (Elmt));
7748 Append_Elmt (Node (Elmt), Used_Operations (Parent (Id)));
7755 if Ada_Version >= Ada_2012
7756 and then All_Present (Parent (Id))
7757 and then Is_Tagged_Type (T)
7759 Use_Class_Wide_Operations (T);
7763 -- If warning on redundant constructs, check for unnecessary WITH
7765 if Warn_On_Redundant_Constructs
7766 and then Is_Known_Used
7768 -- with P; with P; use P;
7769 -- package P is package X is package body X is
7770 -- type T ... use P.T;
7772 -- The compilation unit is the body of X. GNAT first compiles the
7773 -- spec of X, then proceeds to the body. At that point P is marked
7774 -- as use visible. The analysis then reinstalls the spec along with
7775 -- its context. The use clause P.T is now recognized as redundant,
7776 -- but in the wrong context. Do not emit a warning in such cases.
7777 -- Do not emit a warning either if we are in an instance, there is
7778 -- no redundancy between an outer use_clause and one that appears
7779 -- within the generic.
7781 and then not Spec_Reloaded_For_Body
7782 and then not In_Instance
7784 -- The type already has a use clause
7788 -- Case where we know the current use clause for the type
7790 if Present (Current_Use_Clause (T)) then
7791 Use_Clause_Known : declare
7792 Clause1 : constant Node_Id := Parent (Id);
7793 Clause2 : constant Node_Id := Current_Use_Clause (T);
7800 function Entity_Of_Unit (U : Node_Id) return Entity_Id;
7801 -- Return the appropriate entity for determining which unit
7802 -- has a deeper scope: the defining entity for U, unless U
7803 -- is a package instance, in which case we retrieve the
7804 -- entity of the instance spec.
7806 --------------------
7807 -- Entity_Of_Unit --
7808 --------------------
7810 function Entity_Of_Unit (U : Node_Id) return Entity_Id is
7812 if Nkind (U) = N_Package_Instantiation
7813 and then Analyzed (U)
7815 return Defining_Entity (Instance_Spec (U));
7817 return Defining_Entity (U);
7821 -- Start of processing for Use_Clause_Known
7824 -- If both current use type clause and the use type clause
7825 -- for the type are at the compilation unit level, one of
7826 -- the units must be an ancestor of the other, and the
7827 -- warning belongs on the descendant.
7829 if Nkind (Parent (Clause1)) = N_Compilation_Unit
7831 Nkind (Parent (Clause2)) = N_Compilation_Unit
7834 -- If the unit is a subprogram body that acts as spec,
7835 -- the context clause is shared with the constructed
7836 -- subprogram spec. Clearly there is no redundancy.
7838 if Clause1 = Clause2 then
7842 Unit1 := Unit (Parent (Clause1));
7843 Unit2 := Unit (Parent (Clause2));
7845 -- If both clauses are on same unit, or one is the body
7846 -- of the other, or one of them is in a subunit, report
7847 -- redundancy on the later one.
7849 if Unit1 = Unit2 then
7850 Error_Msg_Sloc := Sloc (Current_Use_Clause (T));
7851 Error_Msg_NE -- CODEFIX
7852 ("& is already use-visible through previous "
7853 & "use_type_clause #?", Clause1, T);
7856 elsif Nkind (Unit1) = N_Subunit then
7857 Error_Msg_Sloc := Sloc (Current_Use_Clause (T));
7858 Error_Msg_NE -- CODEFIX
7859 ("& is already use-visible through previous "
7860 & "use_type_clause #?", Clause1, T);
7863 elsif Nkind_In (Unit2, N_Package_Body, N_Subprogram_Body)
7864 and then Nkind (Unit1) /= Nkind (Unit2)
7865 and then Nkind (Unit1) /= N_Subunit
7867 Error_Msg_Sloc := Sloc (Clause1);
7868 Error_Msg_NE -- CODEFIX
7869 ("& is already use-visible through previous "
7870 & "use_type_clause #?", Current_Use_Clause (T), T);
7874 -- There is a redundant use type clause in a child unit.
7875 -- Determine which of the units is more deeply nested.
7876 -- If a unit is a package instance, retrieve the entity
7877 -- and its scope from the instance spec.
7879 Ent1 := Entity_Of_Unit (Unit1);
7880 Ent2 := Entity_Of_Unit (Unit2);
7882 if Scope (Ent2) = Standard_Standard then
7883 Error_Msg_Sloc := Sloc (Current_Use_Clause (T));
7886 elsif Scope (Ent1) = Standard_Standard then
7887 Error_Msg_Sloc := Sloc (Id);
7890 -- If both units are child units, we determine which one
7891 -- is the descendant by the scope distance to the
7892 -- ultimate parent unit.
7902 and then Present (S2)
7903 and then S1 /= Standard_Standard
7904 and then S2 /= Standard_Standard
7910 if S1 = Standard_Standard then
7911 Error_Msg_Sloc := Sloc (Id);
7914 Error_Msg_Sloc := Sloc (Current_Use_Clause (T));
7920 Error_Msg_NE -- CODEFIX
7921 ("& is already use-visible through previous "
7922 & "use_type_clause #?", Err_No, Id);
7924 -- Case where current use type clause and the use type
7925 -- clause for the type are not both at the compilation unit
7926 -- level. In this case we don't have location information.
7929 Error_Msg_NE -- CODEFIX
7930 ("& is already use-visible through previous "
7931 & "use type clause?", Id, T);
7933 end Use_Clause_Known;
7935 -- Here if Current_Use_Clause is not set for T, another case
7936 -- where we do not have the location information available.
7939 Error_Msg_NE -- CODEFIX
7940 ("& is already use-visible through previous "
7941 & "use type clause?", Id, T);
7944 -- The package where T is declared is already used
7946 elsif In_Use (Scope (T)) then
7947 Error_Msg_Sloc := Sloc (Current_Use_Clause (Scope (T)));
7948 Error_Msg_NE -- CODEFIX
7949 ("& is already use-visible through package use clause #?",
7952 -- The current scope is the package where T is declared
7955 Error_Msg_Node_2 := Scope (T);
7956 Error_Msg_NE -- CODEFIX
7957 ("& is already use-visible inside package &?", Id, T);
7966 procedure Write_Info is
7967 Id : Entity_Id := First_Entity (Current_Scope);
7970 -- No point in dumping standard entities
7972 if Current_Scope = Standard_Standard then
7976 Write_Str ("========================================================");
7978 Write_Str (" Defined Entities in ");
7979 Write_Name (Chars (Current_Scope));
7981 Write_Str ("========================================================");
7985 Write_Str ("-- none --");
7989 while Present (Id) loop
7990 Write_Entity_Info (Id, " ");
7995 if Scope (Current_Scope) = Standard_Standard then
7997 -- Print information on the current unit itself
7999 Write_Entity_Info (Current_Scope, " ");
8012 for J in reverse 1 .. Scope_Stack.Last loop
8013 S := Scope_Stack.Table (J).Entity;
8014 Write_Int (Int (S));
8015 Write_Str (" === ");
8016 Write_Name (Chars (S));