1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Einfo
.Entities
; use Einfo
.Entities
;
30 with Einfo
.Utils
; use Einfo
.Utils
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Disp
; use Exp_Disp
;
34 with Exp_Tss
; use Exp_Tss
;
35 with Exp_Util
; use Exp_Util
;
36 with Freeze
; use Freeze
;
37 with Ghost
; use Ghost
;
38 with Impunit
; use Impunit
;
40 with Lib
.Load
; use Lib
.Load
;
41 with Lib
.Xref
; use Lib
.Xref
;
42 with Namet
; use Namet
;
43 with Namet
.Sp
; use Namet
.Sp
;
44 with Nlists
; use Nlists
;
45 with Nmake
; use Nmake
;
47 with Output
; use Output
;
48 with Restrict
; use Restrict
;
49 with Rident
; use Rident
;
50 with Rtsfind
; use Rtsfind
;
52 with Sem_Aux
; use Sem_Aux
;
53 with Sem_Cat
; use Sem_Cat
;
54 with Sem_Ch3
; use Sem_Ch3
;
55 with Sem_Ch4
; use Sem_Ch4
;
56 with Sem_Ch6
; use Sem_Ch6
;
57 with Sem_Ch10
; use Sem_Ch10
;
58 with Sem_Ch12
; use Sem_Ch12
;
59 with Sem_Ch13
; use Sem_Ch13
;
60 with Sem_Dim
; use Sem_Dim
;
61 with Sem_Disp
; use Sem_Disp
;
62 with Sem_Dist
; use Sem_Dist
;
63 with Sem_Elab
; use Sem_Elab
;
64 with Sem_Eval
; use Sem_Eval
;
65 with Sem_Prag
; use Sem_Prag
;
66 with Sem_Res
; use Sem_Res
;
67 with Sem_Util
; use Sem_Util
;
68 with Sem_Type
; use Sem_Type
;
69 with Stand
; use Stand
;
70 with Sinfo
; use Sinfo
;
71 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
72 with Sinfo
.Utils
; use Sinfo
.Utils
;
73 with Sinfo
.CN
; use Sinfo
.CN
;
74 with Snames
; use Snames
;
77 with Tbuild
; use Tbuild
;
78 with Uintp
; use Uintp
;
79 with Warnsw
; use Warnsw
;
81 package body Sem_Ch8
is
83 ------------------------------------
84 -- Visibility and Name Resolution --
85 ------------------------------------
87 -- This package handles name resolution and the collection of possible
88 -- interpretations for overloaded names, prior to overload resolution.
90 -- Name resolution is the process that establishes a mapping between source
91 -- identifiers and the entities they denote at each point in the program.
92 -- Each entity is represented by a defining occurrence. Each identifier
93 -- that denotes an entity points to the corresponding defining occurrence.
94 -- This is the entity of the applied occurrence. Each occurrence holds
95 -- an index into the names table, where source identifiers are stored.
97 -- Each entry in the names table for an identifier or designator uses the
98 -- Info pointer to hold a link to the currently visible entity that has
99 -- this name (see subprograms Get_Name_Entity_Id and Set_Name_Entity_Id
100 -- in package Sem_Util). The visibility is initialized at the beginning of
101 -- semantic processing to make entities in package Standard immediately
102 -- visible. The visibility table is used in a more subtle way when
103 -- compiling subunits (see below).
105 -- Entities that have the same name (i.e. homonyms) are chained. In the
106 -- case of overloaded entities, this chain holds all the possible meanings
107 -- of a given identifier. The process of overload resolution uses type
108 -- information to select from this chain the unique meaning of a given
111 -- Entities are also chained in their scope, through the Next_Entity link.
112 -- As a consequence, the name space is organized as a sparse matrix, where
113 -- each row corresponds to a scope, and each column to a source identifier.
114 -- Open scopes, that is to say scopes currently being compiled, have their
115 -- corresponding rows of entities in order, innermost scope first.
117 -- The scopes of packages that are mentioned in context clauses appear in
118 -- no particular order, interspersed among open scopes. This is because
119 -- in the course of analyzing the context of a compilation, a package
120 -- declaration is first an open scope, and subsequently an element of the
121 -- context. If subunits or child units are present, a parent unit may
122 -- appear under various guises at various times in the compilation.
124 -- When the compilation of the innermost scope is complete, the entities
125 -- defined therein are no longer visible. If the scope is not a package
126 -- declaration, these entities are never visible subsequently, and can be
127 -- removed from visibility chains. If the scope is a package declaration,
128 -- its visible declarations may still be accessible. Therefore the entities
129 -- defined in such a scope are left on the visibility chains, and only
130 -- their visibility (immediately visibility or potential use-visibility)
133 -- The ordering of homonyms on their chain does not necessarily follow
134 -- the order of their corresponding scopes on the scope stack. For
135 -- example, if package P and the enclosing scope both contain entities
136 -- named E, then when compiling the package body the chain for E will
137 -- hold the global entity first, and the local one (corresponding to
138 -- the current inner scope) next. As a result, name resolution routines
139 -- do not assume any relative ordering of the homonym chains, either
140 -- for scope nesting or to order of appearance of context clauses.
142 -- When compiling a child unit, entities in the parent scope are always
143 -- immediately visible. When compiling the body of a child unit, private
144 -- entities in the parent must also be made immediately visible. There
145 -- are separate routines to make the visible and private declarations
146 -- visible at various times (see package Sem_Ch7).
148 -- +--------+ +-----+
149 -- | In use |-------->| EU1 |-------------------------->
150 -- +--------+ +-----+
152 -- +--------+ +-----+ +-----+
153 -- | Stand. |---------------->| ES1 |--------------->| ES2 |--->
154 -- +--------+ +-----+ +-----+
156 -- +---------+ | +-----+
157 -- | with'ed |------------------------------>| EW2 |--->
158 -- +---------+ | +-----+
160 -- +--------+ +-----+ +-----+
161 -- | Scope2 |---------------->| E12 |--------------->| E22 |--->
162 -- +--------+ +-----+ +-----+
164 -- +--------+ +-----+ +-----+
165 -- | Scope1 |---------------->| E11 |--------------->| E12 |--->
166 -- +--------+ +-----+ +-----+
170 -- | | with'ed |----------------------------------------->
174 -- (innermost first) | |
175 -- +----------------------------+
176 -- Names table => | Id1 | | | | Id2 |
177 -- +----------------------------+
179 -- Name resolution must deal with several syntactic forms: simple names,
180 -- qualified names, indexed names, and various forms of calls.
182 -- Each identifier points to an entry in the names table. The resolution
183 -- of a simple name consists in traversing the homonym chain, starting
184 -- from the names table. If an entry is immediately visible, it is the one
185 -- designated by the identifier. If only potentially use-visible entities
186 -- are on the chain, we must verify that they do not hide each other. If
187 -- the entity we find is overloadable, we collect all other overloadable
188 -- entities on the chain as long as they are not hidden.
190 -- To resolve expanded names, we must find the entity at the intersection
191 -- of the entity chain for the scope (the prefix) and the homonym chain
192 -- for the selector. In general, homonym chains will be much shorter than
193 -- entity chains, so it is preferable to start from the names table as
194 -- well. If the entity found is overloadable, we must collect all other
195 -- interpretations that are defined in the scope denoted by the prefix.
197 -- For records, protected types, and tasks, their local entities are
198 -- removed from visibility chains on exit from the corresponding scope.
199 -- From the outside, these entities are always accessed by selected
200 -- notation, and the entity chain for the record type, protected type,
201 -- etc. is traversed sequentially in order to find the designated entity.
203 -- The discriminants of a type and the operations of a protected type or
204 -- task are unchained on exit from the first view of the type, (such as
205 -- a private or incomplete type declaration, or a protected type speci-
206 -- fication) and re-chained when compiling the second view.
208 -- In the case of operators, we do not make operators on derived types
209 -- explicit. As a result, the notation P."+" may denote either a user-
210 -- defined function with name "+", or else an implicit declaration of the
211 -- operator "+" in package P. The resolution of expanded names always
212 -- tries to resolve an operator name as such an implicitly defined entity,
213 -- in addition to looking for explicit declarations.
215 -- All forms of names that denote entities (simple names, expanded names,
216 -- character literals in some cases) have a Entity attribute, which
217 -- identifies the entity denoted by the name.
219 ---------------------
220 -- The Scope Stack --
221 ---------------------
223 -- The Scope stack keeps track of the scopes currently been compiled.
224 -- Every entity that contains declarations (including records) is placed
225 -- on the scope stack while it is being processed, and removed at the end.
226 -- Whenever a non-package scope is exited, the entities defined therein
227 -- are removed from the visibility table, so that entities in outer scopes
228 -- become visible (see previous description). On entry to Sem, the scope
229 -- stack only contains the package Standard. As usual, subunits complicate
230 -- this picture ever so slightly.
232 -- The Rtsfind mechanism can force a call to Semantics while another
233 -- compilation is in progress. The unit retrieved by Rtsfind must be
234 -- compiled in its own context, and has no access to the visibility of
235 -- the unit currently being compiled. The procedures Save_Scope_Stack and
236 -- Restore_Scope_Stack make entities in current open scopes invisible
237 -- before compiling the retrieved unit, and restore the compilation
238 -- environment afterwards.
240 ------------------------
241 -- Compiling subunits --
242 ------------------------
244 -- Subunits must be compiled in the environment of the corresponding stub,
245 -- that is to say with the same visibility into the parent (and its
246 -- context) that is available at the point of the stub declaration, but
247 -- with the additional visibility provided by the context clause of the
248 -- subunit itself. As a result, compilation of a subunit forces compilation
249 -- of the parent (see description in lib-). At the point of the stub
250 -- declaration, Analyze is called recursively to compile the proper body of
251 -- the subunit, but without reinitializing the names table, nor the scope
252 -- stack (i.e. standard is not pushed on the stack). In this fashion the
253 -- context of the subunit is added to the context of the parent, and the
254 -- subunit is compiled in the correct environment. Note that in the course
255 -- of processing the context of a subunit, Standard will appear twice on
256 -- the scope stack: once for the parent of the subunit, and once for the
257 -- unit in the context clause being compiled. However, the two sets of
258 -- entities are not linked by homonym chains, so that the compilation of
259 -- any context unit happens in a fresh visibility environment.
261 -------------------------------
262 -- Processing of USE Clauses --
263 -------------------------------
265 -- Every defining occurrence has a flag indicating if it is potentially use
266 -- visible. Resolution of simple names examines this flag. The processing
267 -- of use clauses consists in setting this flag on all visible entities
268 -- defined in the corresponding package. On exit from the scope of the use
269 -- clause, the corresponding flag must be reset. However, a package may
270 -- appear in several nested use clauses (pathological but legal, alas)
271 -- which forces us to use a slightly more involved scheme:
273 -- a) The defining occurrence for a package holds a flag -In_Use- to
274 -- indicate that it is currently in the scope of a use clause. If a
275 -- redundant use clause is encountered, then the corresponding occurrence
276 -- of the package name is flagged -Redundant_Use-.
278 -- b) On exit from a scope, the use clauses in its declarative part are
279 -- scanned. The visibility flag is reset in all entities declared in
280 -- package named in a use clause, as long as the package is not flagged
281 -- as being in a redundant use clause (in which case the outer use
282 -- clause is still in effect, and the direct visibility of its entities
283 -- must be retained).
285 -- Note that entities are not removed from their homonym chains on exit
286 -- from the package specification. A subsequent use clause does not need
287 -- to rechain the visible entities, but only to establish their direct
290 -----------------------------------
291 -- Handling private declarations --
292 -----------------------------------
294 -- The principle that each entity has a single defining occurrence clashes
295 -- with the presence of two separate definitions for private types: the
296 -- first is the private type declaration, and second is the full type
297 -- declaration. It is important that all references to the type point to
298 -- the same defining occurrence, namely the first one. To enforce the two
299 -- separate views of the entity, the corresponding information is swapped
300 -- between the two declarations. Outside of the package, the defining
301 -- occurrence only contains the private declaration information, while in
302 -- the private part and the body of the package the defining occurrence
303 -- contains the full declaration. To simplify the swap, the defining
304 -- occurrence that currently holds the private declaration points to the
305 -- full declaration. During semantic processing the defining occurrence
306 -- also points to a list of private dependents, that is to say access types
307 -- or composite types whose designated types or component types are
308 -- subtypes or derived types of the private type in question. After the
309 -- full declaration has been seen, the private dependents are updated to
310 -- indicate that they have full definitions.
312 ------------------------------------
313 -- Handling of Undefined Messages --
314 ------------------------------------
316 -- In normal mode, only the first use of an undefined identifier generates
317 -- a message. The table Urefs is used to record error messages that have
318 -- been issued so that second and subsequent ones do not generate further
319 -- messages. However, the second reference causes text to be added to the
320 -- original undefined message noting "(more references follow)". The
321 -- full error list option (-gnatf) forces messages to be generated for
322 -- every reference and disconnects the use of this table.
324 type Uref_Entry
is record
326 -- Node for identifier for which original message was posted. The
327 -- Chars field of this identifier is used to detect later references
328 -- to the same identifier.
331 -- Records error message Id of original undefined message. Reset to
332 -- No_Error_Msg after the second occurrence, where it is used to add
333 -- text to the original message as described above.
336 -- Set if the message is not visible rather than undefined
339 -- Records location of error message. Used to make sure that we do
340 -- not consider a, b : undefined as two separate instances, which
341 -- would otherwise happen, since the parser converts this sequence
342 -- to a : undefined; b : undefined.
346 package Urefs
is new Table
.Table
(
347 Table_Component_Type
=> Uref_Entry
,
348 Table_Index_Type
=> Nat
,
349 Table_Low_Bound
=> 1,
351 Table_Increment
=> 100,
352 Table_Name
=> "Urefs");
354 Candidate_Renaming
: Entity_Id
;
355 -- Holds a candidate interpretation that appears in a subprogram renaming
356 -- declaration and does not match the given specification, but matches at
357 -- least on the first formal. Allows better error message when given
358 -- specification omits defaulted parameters, a common error.
360 -----------------------
361 -- Local Subprograms --
362 -----------------------
364 procedure Analyze_Generic_Renaming
367 -- Common processing for all three kinds of generic renaming declarations.
368 -- Enter new name and indicate that it renames the generic unit.
370 procedure Analyze_Renamed_Character
374 -- Renamed entity is given by a character literal, which must belong
375 -- to the return type of the new entity. Is_Body indicates whether the
376 -- declaration is a renaming_as_body. If the original declaration has
377 -- already been frozen (because of an intervening body, e.g.) the body of
378 -- the function must be built now. The same applies to the following
379 -- various renaming procedures.
381 procedure Analyze_Renamed_Dereference
385 -- Renamed entity is given by an explicit dereference. Prefix must be a
386 -- conformant access_to_subprogram type.
388 procedure Analyze_Renamed_Entry
392 -- If the renamed entity in a subprogram renaming is an entry or protected
393 -- subprogram, build a body for the new entity whose only statement is a
394 -- call to the renamed entity.
396 procedure Analyze_Renamed_Family_Member
400 -- Used when the renamed entity is an indexed component. The prefix must
401 -- denote an entry family.
403 procedure Analyze_Renamed_Primitive_Operation
407 -- If the renamed entity in a subprogram renaming is a primitive operation
408 -- or a class-wide operation in prefix form, save the target object,
409 -- which must be added to the list of actuals in any subsequent call.
410 -- The renaming operation is intrinsic because the compiler must in
411 -- fact generate a wrapper for it (6.3.1 (10 1/2)).
413 procedure Attribute_Renaming
(N
: Node_Id
);
414 -- Analyze renaming of attribute as subprogram. The renaming declaration N
415 -- is rewritten as a subprogram body that returns the attribute reference
416 -- applied to the formals of the function.
418 procedure Set_Entity_Or_Discriminal
(N
: Node_Id
; E
: Entity_Id
);
419 -- Set Entity, with style check if need be. For a discriminant reference,
420 -- replace by the corresponding discriminal, i.e. the parameter of the
421 -- initialization procedure that corresponds to the discriminant.
423 procedure Check_Frozen_Renaming
(N
: Node_Id
; Subp
: Entity_Id
);
424 -- A renaming_as_body may occur after the entity of the original decla-
425 -- ration has been frozen. In that case, the body of the new entity must
426 -- be built now, because the usual mechanism of building the renamed
427 -- body at the point of freezing will not work. Subp is the subprogram
428 -- for which N provides the Renaming_As_Body.
430 procedure Check_In_Previous_With_Clause
(N
, Nam
: Node_Id
);
431 -- N is a use_package clause and Nam the package name, or N is a use_type
432 -- clause and Nam is the prefix of the type name. In either case, verify
433 -- that the package is visible at that point in the context: either it
434 -- appears in a previous with_clause, or because it is a fully qualified
435 -- name and the root ancestor appears in a previous with_clause.
437 procedure Check_Library_Unit_Renaming
(N
: Node_Id
; Old_E
: Entity_Id
);
438 -- Verify that the entity in a renaming declaration that is a library unit
439 -- is itself a library unit and not a nested unit or subunit. Also check
440 -- that if the renaming is a child unit of a generic parent, then the
441 -- renamed unit must also be a child unit of that parent. Finally, verify
442 -- that a renamed generic unit is not an implicit child declared within
443 -- an instance of the parent.
445 procedure Chain_Use_Clause
(N
: Node_Id
);
446 -- Chain use clause onto list of uses clauses headed by First_Use_Clause in
447 -- the proper scope table entry. This is usually the current scope, but it
448 -- will be an inner scope when installing the use clauses of the private
449 -- declarations of a parent unit prior to compiling the private part of a
450 -- child unit. This chain is traversed when installing/removing use clauses
451 -- when compiling a subunit or instantiating a generic body on the fly,
452 -- when it is necessary to save and restore full environments.
454 function Enclosing_Instance
return Entity_Id
;
455 -- In an instance nested within another one, several semantic checks are
456 -- unnecessary because the legality of the nested instance has been checked
457 -- in the enclosing generic unit. This applies in particular to legality
458 -- checks on actuals for formal subprograms of the inner instance, which
459 -- are checked as subprogram renamings, and may be complicated by confusion
460 -- in private/full views. This function returns the instance enclosing the
461 -- current one if there is such, else it returns Empty.
463 -- If the renaming determines the entity for the default of a formal
464 -- subprogram nested within another instance, choose the innermost
465 -- candidate. This is because if the formal has a box, and we are within
466 -- an enclosing instance where some candidate interpretations are local
467 -- to this enclosing instance, we know that the default was properly
468 -- resolved when analyzing the generic, so we prefer the local
469 -- candidates to those that are external. This is not always the case
470 -- but is a reasonable heuristic on the use of nested generics. The
471 -- proper solution requires a full renaming model.
473 function Entity_Of_Unit
(U
: Node_Id
) return Entity_Id
;
474 -- Return the appropriate entity for determining which unit has a deeper
475 -- scope: the defining entity for U, unless U is a package instance, in
476 -- which case we retrieve the entity of the instance spec.
478 procedure Error_Missing_With_Of_Known_Unit
(Pkg
: Node_Id
);
479 -- Display an error message denoting a "with" is missing for a given known
480 -- package Pkg with its full path name.
482 procedure Find_Expanded_Name
(N
: Node_Id
);
483 -- The input is a selected component known to be an expanded name. Verify
484 -- legality of selector given the scope denoted by prefix, and change node
485 -- N into a expanded name with a properly set Entity field.
487 function Find_First_Use
(Use_Clause
: Node_Id
) return Node_Id
;
488 -- Find the most previous use clause (that is, the first one to appear in
489 -- the source) by traversing the previous clause chain that exists in both
490 -- N_Use_Package_Clause nodes and N_Use_Type_Clause nodes.
492 function Find_Renamed_Entity
496 Is_Actual
: Boolean := False) return Entity_Id
;
497 -- Find the renamed entity that corresponds to the given parameter profile
498 -- in a subprogram renaming declaration. The renamed entity may be an
499 -- operator, a subprogram, an entry, or a protected operation. Is_Actual
500 -- indicates that the renaming is the one generated for an actual subpro-
501 -- gram in an instance, for which special visibility checks apply.
503 function Has_Implicit_Character_Literal
(N
: Node_Id
) return Boolean;
504 -- Find a type derived from Character or Wide_Character in the prefix of N.
505 -- Used to resolved qualified names whose selector is a character literal.
507 function Has_Private_With
(E
: Entity_Id
) return Boolean;
508 -- Ada 2005 (AI-262): Determines if the current compilation unit has a
509 -- private with on E.
511 function Has_Components
(Typ
: Entity_Id
) return Boolean;
512 -- Determine if given type has components, i.e. is either a record type or
513 -- type or a type that has discriminants.
515 function Has_Implicit_Operator
(N
: Node_Id
) return Boolean;
516 -- N is an expanded name whose selector is an operator name (e.g. P."+").
517 -- Determine if N denotes an operator implicitly declared in prefix P: P's
518 -- declarative part contains an implicit declaration of an operator if it
519 -- has a declaration of a type to which one of the predefined operators
520 -- apply. The existence of this routine is an implementation artifact. A
521 -- more straightforward but more space-consuming choice would be to make
522 -- all inherited operators explicit in the symbol table.
524 procedure Inherit_Renamed_Profile
(New_S
: Entity_Id
; Old_S
: Entity_Id
);
525 -- A subprogram defined by a renaming declaration inherits the parameter
526 -- profile of the renamed entity. The subtypes given in the subprogram
527 -- specification are discarded and replaced with those of the renamed
528 -- subprogram, which are then used to recheck the default values.
530 function Most_Descendant_Use_Clause
531 (Clause1
: Entity_Id
;
532 Clause2
: Entity_Id
) return Entity_Id
;
533 -- Determine which use clause parameter is the most descendant in terms of
536 procedure Premature_Usage
(N
: Node_Id
);
537 -- Diagnose usage of an entity before it is visible
539 function Is_Self_Hidden
(E
: Entity_Id
) return Boolean;
540 -- True within a declaration if it is hidden from all visibility by itself
541 -- (see RM-8.3(16-18)). This is mostly just "not Is_Not_Self_Hidden", but
542 -- we need to check for E_Void in case of errors.
544 procedure Use_One_Package
546 Pack_Name
: Entity_Id
:= Empty
;
547 Force
: Boolean := False);
548 -- Make visible entities declared in package P potentially use-visible
549 -- in the current context. Also used in the analysis of subunits, when
550 -- re-installing use clauses of parent units. N is the use_clause that
551 -- names P (and possibly other packages).
553 procedure Use_One_Type
555 Installed
: Boolean := False;
556 Force
: Boolean := False);
557 -- Id is the subtype mark from a use_type_clause. This procedure makes
558 -- the primitive operators of the type potentially use-visible. The
559 -- boolean flag Installed indicates that the clause is being reinstalled
560 -- after previous analysis, and primitive operations are already chained
561 -- on the Used_Operations list of the clause.
563 procedure Write_Info
;
564 -- Write debugging information on entities declared in current scope
566 --------------------------------
567 -- Analyze_Exception_Renaming --
568 --------------------------------
570 -- The language only allows a single identifier, but the tree holds an
571 -- identifier list. The parser has already issued an error message if
572 -- there is more than one element in the list.
574 procedure Analyze_Exception_Renaming
(N
: Node_Id
) is
575 Id
: constant Entity_Id
:= Defining_Entity
(N
);
576 Nam
: constant Node_Id
:= Name
(N
);
582 Mutate_Ekind
(Id
, E_Exception
);
583 Set_Etype
(Id
, Standard_Exception_Type
);
584 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
586 if Is_Entity_Name
(Nam
)
587 and then Present
(Entity
(Nam
))
588 and then Ekind
(Entity
(Nam
)) = E_Exception
590 if Present
(Renamed_Entity
(Entity
(Nam
))) then
591 Set_Renamed_Entity
(Id
, Renamed_Entity
(Entity
(Nam
)));
593 Set_Renamed_Entity
(Id
, Entity
(Nam
));
596 -- The exception renaming declaration may become Ghost if it renames
599 Mark_Ghost_Renaming
(N
, Entity
(Nam
));
601 Error_Msg_N
("invalid exception name in renaming", Nam
);
604 -- Implementation-defined aspect specifications can appear in a renaming
605 -- declaration, but not language-defined ones. The call to procedure
606 -- Analyze_Aspect_Specifications will take care of this error check.
608 if Has_Aspects
(N
) then
609 Analyze_Aspect_Specifications
(N
, Id
);
611 end Analyze_Exception_Renaming
;
613 ---------------------------
614 -- Analyze_Expanded_Name --
615 ---------------------------
617 procedure Analyze_Expanded_Name
(N
: Node_Id
) is
619 -- If the entity pointer is already set, this is an internal node, or a
620 -- node that is analyzed more than once, after a tree modification. In
621 -- such a case there is no resolution to perform, just set the type. In
622 -- either case, start by analyzing the prefix.
624 Analyze
(Prefix
(N
));
626 if Present
(Entity
(N
)) then
627 if Is_Type
(Entity
(N
)) then
628 Set_Etype
(N
, Entity
(N
));
630 Set_Etype
(N
, Etype
(Entity
(N
)));
634 Find_Expanded_Name
(N
);
637 -- In either case, propagate dimension of entity to expanded name
639 Analyze_Dimension
(N
);
640 end Analyze_Expanded_Name
;
642 ---------------------------------------
643 -- Analyze_Generic_Function_Renaming --
644 ---------------------------------------
646 procedure Analyze_Generic_Function_Renaming
(N
: Node_Id
) is
648 Analyze_Generic_Renaming
(N
, E_Generic_Function
);
649 end Analyze_Generic_Function_Renaming
;
651 --------------------------------------
652 -- Analyze_Generic_Package_Renaming --
653 --------------------------------------
655 procedure Analyze_Generic_Package_Renaming
(N
: Node_Id
) is
657 -- Test for the Text_IO special unit case here, since we may be renaming
658 -- one of the subpackages of Text_IO, then join common routine.
660 Check_Text_IO_Special_Unit
(Name
(N
));
662 Analyze_Generic_Renaming
(N
, E_Generic_Package
);
663 end Analyze_Generic_Package_Renaming
;
665 ----------------------------------------
666 -- Analyze_Generic_Procedure_Renaming --
667 ----------------------------------------
669 procedure Analyze_Generic_Procedure_Renaming
(N
: Node_Id
) is
671 Analyze_Generic_Renaming
(N
, E_Generic_Procedure
);
672 end Analyze_Generic_Procedure_Renaming
;
674 ------------------------------
675 -- Analyze_Generic_Renaming --
676 ------------------------------
678 procedure Analyze_Generic_Renaming
682 New_P
: constant Entity_Id
:= Defining_Entity
(N
);
683 Inst
: Boolean := False;
687 if Name
(N
) = Error
then
691 Generate_Definition
(New_P
);
693 if Current_Scope
/= Standard_Standard
then
694 Set_Is_Pure
(New_P
, Is_Pure
(Current_Scope
));
697 if Nkind
(Name
(N
)) = N_Selected_Component
then
698 Check_Generic_Child_Unit
(Name
(N
), Inst
);
703 if not Is_Entity_Name
(Name
(N
)) then
704 Error_Msg_N
("expect entity name in renaming declaration", Name
(N
));
707 Old_P
:= Entity
(Name
(N
));
711 Mutate_Ekind
(New_P
, K
);
713 if Etype
(Old_P
) = Any_Type
then
716 elsif Ekind
(Old_P
) /= K
then
717 Error_Msg_N
("invalid generic unit name", Name
(N
));
720 if Present
(Renamed_Entity
(Old_P
)) then
721 Set_Renamed_Entity
(New_P
, Renamed_Entity
(Old_P
));
723 Set_Renamed_Entity
(New_P
, Old_P
);
726 -- The generic renaming declaration may become Ghost if it renames a
729 Mark_Ghost_Renaming
(N
, Old_P
);
731 Set_Is_Pure
(New_P
, Is_Pure
(Old_P
));
732 Set_Is_Preelaborated
(New_P
, Is_Preelaborated
(Old_P
));
734 Set_Etype
(New_P
, Etype
(Old_P
));
735 Set_Has_Completion
(New_P
);
737 if In_Open_Scopes
(Old_P
) then
738 Error_Msg_N
("within its scope, generic denotes its instance", N
);
741 -- For subprograms, propagate the Intrinsic flag, to allow, e.g.
742 -- renamings and subsequent instantiations of Unchecked_Conversion.
744 if Is_Generic_Subprogram
(Old_P
) then
745 Set_Is_Intrinsic_Subprogram
746 (New_P
, Is_Intrinsic_Subprogram
(Old_P
));
749 Check_Library_Unit_Renaming
(N
, Old_P
);
752 -- Implementation-defined aspect specifications can appear in a renaming
753 -- declaration, but not language-defined ones. The call to procedure
754 -- Analyze_Aspect_Specifications will take care of this error check.
756 if Has_Aspects
(N
) then
757 Analyze_Aspect_Specifications
(N
, New_P
);
759 end Analyze_Generic_Renaming
;
761 -----------------------------
762 -- Analyze_Object_Renaming --
763 -----------------------------
765 procedure Analyze_Object_Renaming
(N
: Node_Id
) is
766 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
767 Loc
: constant Source_Ptr
:= Sloc
(N
);
768 Nam
: constant Node_Id
:= Name
(N
);
769 Is_Object_Ref
: Boolean;
775 procedure Check_Constrained_Object
;
776 -- If the nominal type is unconstrained but the renamed object is
777 -- constrained, as can happen with renaming an explicit dereference or
778 -- a function return, build a constrained subtype from the object. If
779 -- the renaming is for a formal in an accept statement, the analysis
780 -- has already established its actual subtype. This is only relevant
781 -- if the renamed object is an explicit dereference.
783 function Get_Object_Name
(Nod
: Node_Id
) return Node_Id
;
784 -- Obtain the name of the object from node Nod which is being renamed by
785 -- the object renaming declaration N.
787 function Find_Raise_Node
(N
: Node_Id
) return Traverse_Result
;
788 -- Process one node in search for N_Raise_xxx_Error nodes.
789 -- Return Abandon if found, OK otherwise.
791 ---------------------
792 -- Find_Raise_Node --
793 ---------------------
795 function Find_Raise_Node
(N
: Node_Id
) return Traverse_Result
is
797 if Nkind
(N
) in N_Raise_xxx_Error
then
804 ------------------------
805 -- No_Raise_xxx_Error --
806 ------------------------
808 function No_Raise_xxx_Error
is new Traverse_Func
(Find_Raise_Node
);
809 -- Traverse tree to look for a N_Raise_xxx_Error node and returns
810 -- Abandon if so and OK if none found.
812 ------------------------------
813 -- Check_Constrained_Object --
814 ------------------------------
816 procedure Check_Constrained_Object
is
817 Typ
: constant Entity_Id
:= Etype
(Nam
);
819 Loop_Scheme
: Node_Id
;
822 if Nkind
(Nam
) in N_Function_Call | N_Explicit_Dereference
823 and then Is_Composite_Type
(Typ
)
824 and then not Is_Constrained
(Typ
)
825 and then not Has_Unknown_Discriminants
(Typ
)
826 and then Expander_Active
828 -- If Actual_Subtype is already set, nothing to do
830 if Ekind
(Id
) in E_Variable | E_Constant
831 and then Present
(Actual_Subtype
(Id
))
835 -- A renaming of an unchecked union has no actual subtype
837 elsif Is_Unchecked_Union
(Typ
) then
840 -- If a record is limited its size is invariant. This is the case
841 -- in particular with record types with an access discriminant
842 -- that are used in iterators. This is an optimization, but it
843 -- also prevents typing anomalies when the prefix is further
846 -- Note that we cannot just use the Is_Limited_Record flag because
847 -- it does not apply to records with limited components, for which
848 -- this syntactic flag is not set, but whose size is also fixed.
850 -- Note also that we need to build the constrained subtype for an
851 -- array in order to make the bounds explicit in most cases, but
852 -- not if the object comes from an extended return statement, as
853 -- this would create dangling references to them later on.
855 elsif Is_Limited_Type
(Typ
)
856 and then (not Is_Array_Type
(Typ
) or else Is_Return_Object
(Id
))
861 Subt
:= Make_Temporary
(Loc
, 'T');
862 Remove_Side_Effects
(Nam
);
864 Make_Subtype_Declaration
(Loc
,
865 Defining_Identifier
=> Subt
,
866 Subtype_Indication
=>
867 Make_Subtype_From_Expr
(Nam
, Typ
)));
868 Rewrite
(Subtype_Mark
(N
), New_Occurrence_Of
(Subt
, Loc
));
869 Set_Etype
(Nam
, Subt
);
871 -- Suppress discriminant checks on this subtype if the original
872 -- type has defaulted discriminants and Id is a "for of" loop
875 if Has_Defaulted_Discriminants
(Typ
)
876 and then Nkind
(Original_Node
(Parent
(N
))) = N_Loop_Statement
878 Loop_Scheme
:= Iteration_Scheme
(Original_Node
(Parent
(N
)));
880 if Present
(Loop_Scheme
)
881 and then Present
(Iterator_Specification
(Loop_Scheme
))
884 (Iterator_Specification
(Loop_Scheme
)) = Id
886 Set_Checks_May_Be_Suppressed
(Subt
);
887 Push_Local_Suppress_Stack_Entry
889 Check
=> Discriminant_Check
,
894 -- Freeze subtype at once, to prevent order of elaboration
895 -- issues in the backend. The renamed object exists, so its
896 -- type is already frozen in any case.
898 Freeze_Before
(N
, Subt
);
901 end Check_Constrained_Object
;
903 ---------------------
904 -- Get_Object_Name --
905 ---------------------
907 function Get_Object_Name
(Nod
: Node_Id
) return Node_Id
is
912 while Present
(Obj_Nam
) loop
913 case Nkind
(Obj_Nam
) is
914 when N_Attribute_Reference
915 | N_Explicit_Dereference
916 | N_Indexed_Component
919 Obj_Nam
:= Prefix
(Obj_Nam
);
921 when N_Selected_Component
=>
922 Obj_Nam
:= Selector_Name
(Obj_Nam
);
924 when N_Qualified_Expression | N_Type_Conversion
=>
925 Obj_Nam
:= Expression
(Obj_Nam
);
935 -- Start of processing for Analyze_Object_Renaming
942 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
945 -- The renaming of a component that depends on a discriminant requires
946 -- an actual subtype, because in subsequent use of the object Gigi will
947 -- be unable to locate the actual bounds. This explicit step is required
948 -- when the renaming is generated in removing side effects of an
949 -- already-analyzed expression.
951 if Nkind
(Nam
) = N_Selected_Component
and then Analyzed
(Nam
) then
953 -- The object renaming declaration may become Ghost if it renames a
956 if Is_Entity_Name
(Nam
) then
957 Mark_Ghost_Renaming
(N
, Entity
(Nam
));
961 Dec
:= Build_Actual_Subtype_Of_Component
(Etype
(Nam
), Nam
);
963 if Present
(Dec
) then
964 Insert_Action
(N
, Dec
);
965 T
:= Defining_Identifier
(Dec
);
968 elsif Present
(Subtype_Mark
(N
))
969 or else No
(Access_Definition
(N
))
971 if Present
(Subtype_Mark
(N
)) then
972 Find_Type
(Subtype_Mark
(N
));
973 T
:= Entity
(Subtype_Mark
(N
));
976 -- AI12-0275: Case of object renaming without a subtype_mark
981 -- Normal case of no overloading in object name
983 if not Is_Overloaded
(Nam
) then
985 -- Catch error cases (such as attempting to rename a procedure
986 -- or package) using the shorthand form.
989 or else Etype
(Nam
) = Standard_Void_Type
992 ("object name or value expected in renaming", Nam
);
994 Mutate_Ekind
(Id
, E_Variable
);
995 Set_Etype
(Id
, Any_Type
);
1003 -- Case of overloaded name, which will be illegal if there's more
1004 -- than one acceptable interpretation (such as overloaded function
1016 -- More than one candidate interpretation is available
1018 -- Remove procedure calls, which syntactically cannot appear
1019 -- in this context, but which cannot be removed by type
1020 -- checking, because the context does not impose a type.
1022 Get_First_Interp
(Nam
, I
, It
);
1023 while Present
(It
.Typ
) loop
1024 if It
.Typ
= Standard_Void_Type
then
1028 Get_Next_Interp
(I
, It
);
1031 Get_First_Interp
(Nam
, I
, It
);
1035 -- If there's no type present, we have an error case (such
1036 -- as overloaded procedures named in the object renaming).
1040 ("object name or value expected in renaming", Nam
);
1042 Mutate_Ekind
(Id
, E_Variable
);
1043 Set_Etype
(Id
, Any_Type
);
1048 Get_Next_Interp
(I
, It
);
1050 if Present
(It
.Typ
) then
1052 It1
:= Disambiguate
(Nam
, I1
, I
, Any_Type
);
1054 if It1
= No_Interp
then
1055 Error_Msg_N
("ambiguous name in object renaming", Nam
);
1057 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
1058 Error_Msg_N
("\\possible interpretation#!", Nam
);
1060 Error_Msg_Sloc
:= Sloc
(Nam1
);
1061 Error_Msg_N
("\\possible interpretation#!", Nam
);
1067 Set_Etype
(Nam
, It1
.Typ
);
1072 if Etype
(Nam
) = Standard_Exception_Type
then
1074 ("exception requires a subtype mark in renaming", Nam
);
1079 -- The object renaming declaration may become Ghost if it renames a
1082 if Is_Entity_Name
(Nam
) then
1083 Mark_Ghost_Renaming
(N
, Entity
(Nam
));
1086 -- Check against AI12-0401 here before Resolve may rewrite Nam and
1087 -- potentially generate spurious warnings.
1089 -- In the case where the object_name is a qualified_expression with
1090 -- a nominal subtype T and whose expression is a name that denotes
1092 -- * if T is an elementary subtype, then:
1093 -- * Q shall be a constant other than a dereference of an access
1095 -- * the nominal subtype of Q shall be statically compatible with
1097 -- * T shall statically match the base subtype of its type if
1098 -- scalar, or the first subtype of its type if an access type.
1099 -- * if T is a composite subtype, then Q shall be known to be
1100 -- constrained or T shall statically match the first subtype of
1103 if Nkind
(Nam
) = N_Qualified_Expression
1104 and then Is_Object_Reference
(Expression
(Nam
))
1106 Q
:= Expression
(Nam
);
1108 if (Is_Elementary_Type
(T
)
1110 not ((not Is_Variable
(Q
)
1111 and then Nkind
(Q
) /= N_Explicit_Dereference
)
1112 or else Subtypes_Statically_Compatible
(Etype
(Q
), T
)
1113 or else (Is_Scalar_Type
(T
)
1114 and then Subtypes_Statically_Match
1116 or else (Is_Access_Type
(T
)
1117 and then Subtypes_Statically_Match
1118 (T
, First_Subtype
(T
)))))
1119 or else (Is_Composite_Type
(T
)
1122 -- If Q is an aggregate, Is_Constrained may not be set
1123 -- yet and its type may not be resolved yet.
1124 -- This doesn't quite correspond to the complex notion
1125 -- of "known to be constrained" but this is good enough
1126 -- for a rule which is in any case too complex.
1128 not (Is_Constrained
(Etype
(Q
))
1129 or else Nkind
(Q
) = N_Aggregate
1130 or else Subtypes_Statically_Match
1131 (T
, First_Subtype
(T
))))
1134 ("subtype of renamed qualified expression does not " &
1135 "statically match", N
);
1142 -- If the renamed object is a function call of a limited type,
1143 -- the expansion of the renaming is complicated by the presence
1144 -- of various temporaries and subtypes that capture constraints
1145 -- of the renamed object. Rewrite node as an object declaration,
1146 -- whose expansion is simpler. Given that the object is limited
1147 -- there is no copy involved and no performance hit.
1149 if Nkind
(Nam
) = N_Function_Call
1150 and then Is_Limited_View
(Etype
(Nam
))
1151 and then not Is_Constrained
(Etype
(Nam
))
1152 and then Comes_From_Source
(N
)
1155 Mutate_Ekind
(Id
, E_Constant
);
1157 Make_Object_Declaration
(Loc
,
1158 Defining_Identifier
=> Id
,
1159 Constant_Present
=> True,
1160 Object_Definition
=> New_Occurrence_Of
(Etype
(Nam
), Loc
),
1161 Expression
=> Relocate_Node
(Nam
)));
1165 -- Ada 2012 (AI05-149): Reject renaming of an anonymous access object
1166 -- when renaming declaration has a named access type. The Ada 2012
1167 -- coverage rules allow an anonymous access type in the context of
1168 -- an expected named general access type, but the renaming rules
1169 -- require the types to be the same. (An exception is when the type
1170 -- of the renaming is also an anonymous access type, which can only
1171 -- happen due to a renaming created by the expander.)
1173 if Nkind
(Nam
) = N_Type_Conversion
1174 and then not Comes_From_Source
(Nam
)
1175 and then Is_Anonymous_Access_Type
(Etype
(Expression
(Nam
)))
1176 and then not Is_Anonymous_Access_Type
(T
)
1179 ("cannot rename anonymous access object "
1180 & "as a named access type", Expression
(Nam
), T
);
1183 -- Check that a class-wide object is not being renamed as an object
1184 -- of a specific type. The test for access types is needed to exclude
1185 -- cases where the renamed object is a dynamically tagged access
1186 -- result, such as occurs in certain expansions.
1188 if Is_Tagged_Type
(T
) then
1189 Check_Dynamically_Tagged_Expression
1195 -- Ada 2005 (AI-230/AI-254): Access renaming
1197 else pragma Assert
(Present
(Access_Definition
(N
)));
1201 N
=> Access_Definition
(N
));
1205 -- The object renaming declaration may become Ghost if it renames a
1208 if Is_Entity_Name
(Nam
) then
1209 Mark_Ghost_Renaming
(N
, Entity
(Nam
));
1212 -- Ada 2005 AI05-105: if the declaration has an anonymous access
1213 -- type, the renamed object must also have an anonymous type, and
1214 -- this is a name resolution rule. This was implicit in the last part
1215 -- of the first sentence in 8.5.1(3/2), and is made explicit by this
1218 if not Is_Overloaded
(Nam
) then
1219 if Ekind
(Etype
(Nam
)) /= Ekind
(T
) then
1221 ("expect anonymous access type in object renaming", N
);
1228 Typ
: Entity_Id
:= Empty
;
1229 Seen
: Boolean := False;
1232 Get_First_Interp
(Nam
, I
, It
);
1233 while Present
(It
.Typ
) loop
1235 -- Renaming is ambiguous if more than one candidate
1236 -- interpretation is type-conformant with the context.
1238 if Ekind
(It
.Typ
) = Ekind
(T
) then
1239 if Ekind
(T
) = E_Anonymous_Access_Subprogram_Type
1242 (Designated_Type
(T
), Designated_Type
(It
.Typ
))
1248 ("ambiguous expression in renaming", Nam
);
1251 elsif Ekind
(T
) = E_Anonymous_Access_Type
1253 Covers
(Designated_Type
(T
), Designated_Type
(It
.Typ
))
1259 ("ambiguous expression in renaming", Nam
);
1263 if Covers
(T
, It
.Typ
) then
1265 Set_Etype
(Nam
, Typ
);
1266 Set_Is_Overloaded
(Nam
, False);
1270 Get_Next_Interp
(I
, It
);
1277 -- Do not perform the legality checks below when the resolution of
1278 -- the renaming name failed because the associated type is Any_Type.
1280 if Etype
(Nam
) = Any_Type
then
1283 -- Ada 2005 (AI-231): In the case where the type is defined by an
1284 -- access_definition, the renamed entity shall be of an access-to-
1285 -- constant type if and only if the access_definition defines an
1286 -- access-to-constant type. ARM 8.5.1(4)
1288 elsif Constant_Present
(Access_Definition
(N
))
1289 and then not Is_Access_Constant
(Etype
(Nam
))
1292 ("(Ada 2005): the renamed object is not access-to-constant "
1293 & "(RM 8.5.1(6))", N
);
1295 elsif not Constant_Present
(Access_Definition
(N
))
1296 and then Is_Access_Constant
(Etype
(Nam
))
1299 ("(Ada 2005): the renamed object is not access-to-variable "
1300 & "(RM 8.5.1(6))", N
);
1303 if Is_Access_Subprogram_Type
(Etype
(Nam
)) then
1304 Check_Subtype_Conformant
1305 (Designated_Type
(T
), Designated_Type
(Etype
(Nam
)));
1307 elsif not Subtypes_Statically_Match
1308 (Designated_Type
(T
),
1309 Available_View
(Designated_Type
(Etype
(Nam
))))
1312 ("subtype of renamed object does not statically match", N
);
1316 -- Special processing for renaming function return object. Some errors
1317 -- and warnings are produced only for calls that come from source.
1319 if Nkind
(Nam
) = N_Function_Call
then
1322 -- Usage is illegal in Ada 83, but renamings are also introduced
1323 -- during expansion, and error does not apply to those.
1326 if Comes_From_Source
(N
) then
1328 ("(Ada 83) cannot rename function return object", Nam
);
1331 -- In Ada 95, warn for odd case of renaming parameterless function
1332 -- call if this is not a limited type (where this is useful).
1335 if Warn_On_Object_Renames_Function
1336 and then No
(Parameter_Associations
(Nam
))
1337 and then not Is_Limited_Type
(Etype
(Nam
))
1338 and then Comes_From_Source
(Nam
)
1341 ("renaming function result object is suspicious?.r?", Nam
);
1343 ("\function & will be called only once?.r?", Nam
,
1344 Entity
(Name
(Nam
)));
1345 Error_Msg_N
-- CODEFIX
1346 ("\suggest using an initialized constant object "
1347 & "instead?.r?", Nam
);
1352 Check_Constrained_Object
;
1354 -- An object renaming requires an exact match of the type. Class-wide
1355 -- matching is not allowed.
1357 if Is_Class_Wide_Type
(T
)
1358 and then Base_Type
(Etype
(Nam
)) /= Base_Type
(T
)
1360 Wrong_Type
(Nam
, T
);
1363 -- We must search for an actual subtype here so that the bounds of
1364 -- objects of unconstrained types don't get dropped on the floor - such
1365 -- as with renamings of formal parameters.
1367 T2
:= Get_Actual_Subtype_If_Available
(Nam
);
1369 -- Ada 2005 (AI-326): Handle wrong use of incomplete type
1371 if Nkind
(Nam
) = N_Explicit_Dereference
1372 and then Ekind
(Etype
(T2
)) = E_Incomplete_Type
1374 Error_Msg_NE
("invalid use of incomplete type&", Id
, T2
);
1377 elsif Ekind
(Etype
(T
)) = E_Incomplete_Type
then
1378 Error_Msg_NE
("invalid use of incomplete type&", Id
, T
);
1382 if Ada_Version
>= Ada_2005
and then Nkind
(Nam
) in N_Has_Entity
then
1384 Nam_Ent
: constant Entity_Id
:= Entity
(Get_Object_Name
(Nam
));
1385 Nam_Decl
: constant Node_Id
:= Declaration_Node
(Nam_Ent
);
1388 if Has_Null_Exclusion
(N
)
1389 and then not Has_Null_Exclusion
(Nam_Decl
)
1391 -- Ada 2005 (AI-423): If the object name denotes a generic
1392 -- formal object of a generic unit G, and the object renaming
1393 -- declaration occurs within the body of G or within the body
1394 -- of a generic unit declared within the declarative region
1395 -- of G, then the declaration of the formal object of G must
1396 -- have a null exclusion or a null-excluding subtype.
1398 if Is_Formal_Object
(Nam_Ent
)
1399 and then In_Generic_Scope
(Id
)
1401 if not Can_Never_Be_Null
(Etype
(Nam_Ent
)) then
1403 ("object does not exclude `NULL` "
1404 & "(RM 8.5.1(4.6/2))", N
);
1406 elsif In_Package_Body
(Scope
(Id
)) then
1408 ("formal object does not have a null exclusion"
1409 & "(RM 8.5.1(4.6/2))", N
);
1412 -- Ada 2005 (AI-423): Otherwise, the subtype of the object name
1413 -- shall exclude null.
1415 elsif not Can_Never_Be_Null
(Etype
(Nam_Ent
)) then
1417 ("object does not exclude `NULL` "
1418 & "(RM 8.5.1(4.6/2))", N
);
1420 -- An instance is illegal if it contains a renaming that
1421 -- excludes null, and the actual does not. The renaming
1422 -- declaration has already indicated that the declaration
1423 -- of the renamed actual in the instance will raise
1424 -- constraint_error.
1426 elsif Nkind
(Nam_Decl
) = N_Object_Declaration
1427 and then In_Instance
1429 Present
(Corresponding_Generic_Association
(Nam_Decl
))
1430 and then Nkind
(Expression
(Nam_Decl
)) =
1431 N_Raise_Constraint_Error
1434 ("actual does not exclude `NULL` (RM 8.5.1(4.6/2))", N
);
1436 -- Finally, if there is a null exclusion, the subtype mark
1437 -- must not be null-excluding.
1439 elsif No
(Access_Definition
(N
))
1440 and then Can_Never_Be_Null
(T
)
1443 ("`NOT NULL` not allowed (& already excludes null)",
1448 elsif Can_Never_Be_Null
(T
)
1449 and then not Can_Never_Be_Null
(Etype
(Nam_Ent
))
1452 ("object does not exclude `NULL` (RM 8.5.1(4.6/2))", N
);
1454 elsif Has_Null_Exclusion
(N
)
1455 and then No
(Access_Definition
(N
))
1456 and then Can_Never_Be_Null
(T
)
1459 ("`NOT NULL` not allowed (& already excludes null)", N
, T
);
1464 -- Set the Ekind of the entity, unless it has been set already, as is
1465 -- the case for the iteration object over a container with no variable
1466 -- indexing. In that case it's been marked as a constant, and we do not
1467 -- want to change it to a variable.
1469 if Ekind
(Id
) /= E_Constant
then
1470 Mutate_Ekind
(Id
, E_Variable
);
1473 Reinit_Object_Size_Align
(Id
);
1475 -- If N comes from source then check that the original node is an
1476 -- object reference since there may have been several rewritting and
1477 -- folding. Do not do this for N_Function_Call or N_Explicit_Dereference
1478 -- which might correspond to rewrites of e.g. N_Selected_Component
1479 -- (for example Object.Method rewriting).
1480 -- If N does not come from source then assume the tree is properly
1481 -- formed and accept any object reference. In such cases we do support
1482 -- more cases of renamings anyway, so the actual check on which renaming
1483 -- is valid is better left to the code generator as a last sanity
1486 if Comes_From_Source
(N
) then
1487 if Nkind
(Nam
) in N_Function_Call | N_Explicit_Dereference
then
1488 Is_Object_Ref
:= Is_Object_Reference
(Nam
);
1490 Is_Object_Ref
:= Is_Object_Reference
(Original_Node
(Nam
));
1493 Is_Object_Ref
:= True;
1496 if T
= Any_Type
or else Etype
(Nam
) = Any_Type
then
1499 -- Verify that the renamed entity is an object or function call
1501 elsif Is_Object_Ref
then
1502 if Comes_From_Source
(N
) then
1503 if Is_Dependent_Component_Of_Mutable_Object
(Nam
) then
1505 ("illegal renaming of discriminant-dependent component", Nam
);
1508 -- If the renaming comes from source and the renamed object is a
1509 -- dereference, then mark the prefix as needing debug information,
1510 -- since it might have been rewritten hence internally generated
1511 -- and Debug_Renaming_Declaration will link the renaming to it.
1513 if Nkind
(Nam
) = N_Explicit_Dereference
1514 and then Is_Entity_Name
(Prefix
(Nam
))
1516 Set_Debug_Info_Needed
(Entity
(Prefix
(Nam
)));
1520 -- Weird but legal, equivalent to renaming a function call. Illegal
1521 -- if the literal is the result of constant-folding an attribute
1522 -- reference that is not a function.
1524 elsif Is_Entity_Name
(Nam
)
1525 and then Ekind
(Entity
(Nam
)) = E_Enumeration_Literal
1526 and then Nkind
(Original_Node
(Nam
)) /= N_Attribute_Reference
1530 -- A named number can only be renamed without a subtype mark
1532 elsif Nkind
(Nam
) in N_Real_Literal | N_Integer_Literal
1533 and then Present
(Subtype_Mark
(N
))
1534 and then Present
(Original_Entity
(Nam
))
1536 Error_Msg_N
("incompatible types in renaming", Nam
);
1538 -- AI12-0383: Names that denote values can be renamed.
1539 -- Ignore (accept) N_Raise_xxx_Error nodes in this context.
1541 elsif No_Raise_xxx_Error
(Nam
) = OK
then
1542 Error_Msg_Ada_2022_Feature
("value in renaming", Sloc
(Nam
));
1547 if not Is_Variable
(Nam
) then
1548 Mutate_Ekind
(Id
, E_Constant
);
1549 Set_Never_Set_In_Source
(Id
, True);
1550 Set_Is_True_Constant
(Id
, True);
1553 -- The entity of the renaming declaration needs to reflect whether the
1554 -- renamed object is atomic, independent, volatile or VFA. These flags
1555 -- are set on the renamed object in the RM legality sense.
1557 Set_Is_Atomic
(Id
, Is_Atomic_Object
(Nam
));
1558 Set_Is_Independent
(Id
, Is_Independent_Object
(Nam
));
1559 Set_Is_Volatile
(Id
, Is_Volatile_Object_Ref
(Nam
));
1560 Set_Is_Volatile_Full_Access
1561 (Id
, Is_Volatile_Full_Access_Object_Ref
(Nam
));
1563 -- Treat as volatile if we just set the Volatile flag
1567 -- Or if we are renaming an entity which was marked this way
1569 -- Are there more cases, e.g. X(J) where X is Treat_As_Volatile ???
1571 or else (Is_Entity_Name
(Nam
)
1572 and then Treat_As_Volatile
(Entity
(Nam
)))
1574 Set_Treat_As_Volatile
(Id
, True);
1577 -- Now make the link to the renamed object
1579 Set_Renamed_Object
(Id
, Nam
);
1581 -- Implementation-defined aspect specifications can appear in a renaming
1582 -- declaration, but not language-defined ones. The call to procedure
1583 -- Analyze_Aspect_Specifications will take care of this error check.
1585 if Has_Aspects
(N
) then
1586 Analyze_Aspect_Specifications
(N
, Id
);
1589 -- Deal with dimensions
1591 Analyze_Dimension
(N
);
1592 end Analyze_Object_Renaming
;
1594 ------------------------------
1595 -- Analyze_Package_Renaming --
1596 ------------------------------
1598 procedure Analyze_Package_Renaming
(N
: Node_Id
) is
1599 New_P
: constant Entity_Id
:= Defining_Entity
(N
);
1604 if Name
(N
) = Error
then
1608 -- Check for Text_IO special units (we may be renaming a Text_IO child),
1609 -- but make sure not to catch renamings generated for package instances
1610 -- that have nothing to do with them but are nevertheless homonyms.
1612 if Is_Entity_Name
(Name
(N
))
1613 and then Present
(Entity
(Name
(N
)))
1614 and then Is_Generic_Instance
(Entity
(Name
(N
)))
1618 Check_Text_IO_Special_Unit
(Name
(N
));
1621 if Current_Scope
/= Standard_Standard
then
1622 Set_Is_Pure
(New_P
, Is_Pure
(Current_Scope
));
1628 if Is_Entity_Name
(Name
(N
)) then
1629 Old_P
:= Entity
(Name
(N
));
1634 if Etype
(Old_P
) = Any_Type
then
1635 Error_Msg_N
("expect package name in renaming", Name
(N
));
1637 elsif Ekind
(Old_P
) /= E_Package
1638 and then not (Ekind
(Old_P
) = E_Generic_Package
1639 and then In_Open_Scopes
(Old_P
))
1641 if Ekind
(Old_P
) = E_Generic_Package
then
1643 ("generic package cannot be renamed as a package", Name
(N
));
1645 Error_Msg_Sloc
:= Sloc
(Old_P
);
1647 ("expect package name in renaming, found& declared#",
1651 -- Set basic attributes to minimize cascaded errors
1653 Mutate_Ekind
(New_P
, E_Package
);
1654 Set_Etype
(New_P
, Standard_Void_Type
);
1656 elsif Present
(Renamed_Entity
(Old_P
))
1657 and then (From_Limited_With
(Renamed_Entity
(Old_P
))
1658 or else Has_Limited_View
(Renamed_Entity
(Old_P
)))
1660 Unit_Is_Visible
(Cunit
(Get_Source_Unit
(Renamed_Entity
(Old_P
))))
1663 ("renaming of limited view of package & not usable in this context"
1664 & " (RM 8.5.3(3.1/2))", Name
(N
), Renamed_Entity
(Old_P
));
1666 -- Set basic attributes to minimize cascaded errors
1668 Mutate_Ekind
(New_P
, E_Package
);
1669 Set_Etype
(New_P
, Standard_Void_Type
);
1671 -- Here for OK package renaming
1674 -- Entities in the old package are accessible through the renaming
1675 -- entity. The simplest implementation is to have both packages share
1678 Mutate_Ekind
(New_P
, E_Package
);
1679 Set_Etype
(New_P
, Standard_Void_Type
);
1681 if Present
(Renamed_Entity
(Old_P
)) then
1682 Set_Renamed_Entity
(New_P
, Renamed_Entity
(Old_P
));
1684 Set_Renamed_Entity
(New_P
, Old_P
);
1687 -- The package renaming declaration may become Ghost if it renames a
1690 Mark_Ghost_Renaming
(N
, Old_P
);
1692 Set_Has_Completion
(New_P
);
1693 Set_First_Entity
(New_P
, First_Entity
(Old_P
));
1694 Set_Last_Entity
(New_P
, Last_Entity
(Old_P
));
1695 Set_First_Private_Entity
(New_P
, First_Private_Entity
(Old_P
));
1696 Check_Library_Unit_Renaming
(N
, Old_P
);
1697 Generate_Reference
(Old_P
, Name
(N
));
1699 -- If the renaming is in the visible part of a package, then we set
1700 -- Renamed_In_Spec for the renamed package, to prevent giving
1701 -- warnings about no entities referenced. Such a warning would be
1702 -- overenthusiastic, since clients can see entities in the renamed
1703 -- package via the visible package renaming.
1706 Ent
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
1708 if Ekind
(Ent
) = E_Package
1709 and then not In_Private_Part
(Ent
)
1710 and then In_Extended_Main_Source_Unit
(N
)
1711 and then Ekind
(Old_P
) = E_Package
1713 Set_Renamed_In_Spec
(Old_P
);
1717 -- If this is the renaming declaration of a package instantiation
1718 -- within itself, it is the declaration that ends the list of actuals
1719 -- for the instantiation. At this point, the subtypes that rename
1720 -- the actuals are flagged as generic, to avoid spurious ambiguities
1721 -- if the actuals for two distinct formals happen to coincide. If
1722 -- the actual is a private type, the subtype has a private completion
1723 -- that is flagged in the same fashion.
1725 -- Resolution is identical to what is was in the original generic.
1726 -- On exit from the generic instance, these are turned into regular
1727 -- subtypes again, so they are compatible with types in their class.
1729 if not Is_Generic_Instance
(Old_P
) then
1732 Spec
:= Specification
(Unit_Declaration_Node
(Old_P
));
1735 if Nkind
(Spec
) = N_Package_Specification
1736 and then Present
(Generic_Parent
(Spec
))
1737 and then Old_P
= Current_Scope
1738 and then Chars
(New_P
) = Chars
(Generic_Parent
(Spec
))
1744 E
:= First_Entity
(Old_P
);
1745 while Present
(E
) and then E
/= New_P
loop
1747 and then Nkind
(Parent
(E
)) = N_Subtype_Declaration
1749 Set_Is_Generic_Actual_Type
(E
);
1751 if Is_Private_Type
(E
)
1752 and then Present
(Full_View
(E
))
1754 Set_Is_Generic_Actual_Type
(Full_View
(E
));
1764 -- Implementation-defined aspect specifications can appear in a renaming
1765 -- declaration, but not language-defined ones. The call to procedure
1766 -- Analyze_Aspect_Specifications will take care of this error check.
1768 if Has_Aspects
(N
) then
1769 Analyze_Aspect_Specifications
(N
, New_P
);
1771 end Analyze_Package_Renaming
;
1773 -------------------------------
1774 -- Analyze_Renamed_Character --
1775 -------------------------------
1777 procedure Analyze_Renamed_Character
1782 C
: constant Node_Id
:= Name
(N
);
1785 if Ekind
(New_S
) = E_Function
then
1786 Resolve
(C
, Etype
(New_S
));
1789 Check_Frozen_Renaming
(N
, New_S
);
1793 Error_Msg_N
("character literal can only be renamed as function", N
);
1795 end Analyze_Renamed_Character
;
1797 ---------------------------------
1798 -- Analyze_Renamed_Dereference --
1799 ---------------------------------
1801 procedure Analyze_Renamed_Dereference
1806 Nam
: constant Node_Id
:= Name
(N
);
1807 P
: constant Node_Id
:= Prefix
(Nam
);
1813 if not Is_Overloaded
(P
) then
1814 if Ekind
(Etype
(Nam
)) /= E_Subprogram_Type
1815 or else not Type_Conformant
(Etype
(Nam
), New_S
)
1817 Error_Msg_N
("designated type does not match specification", P
);
1826 Get_First_Interp
(Nam
, Ind
, It
);
1828 while Present
(It
.Nam
) loop
1830 if Ekind
(It
.Nam
) = E_Subprogram_Type
1831 and then Type_Conformant
(It
.Nam
, New_S
)
1833 if Typ
/= Any_Id
then
1834 Error_Msg_N
("ambiguous renaming", P
);
1841 Get_Next_Interp
(Ind
, It
);
1844 if Typ
= Any_Type
then
1845 Error_Msg_N
("designated type does not match specification", P
);
1850 Check_Frozen_Renaming
(N
, New_S
);
1854 end Analyze_Renamed_Dereference
;
1856 ---------------------------
1857 -- Analyze_Renamed_Entry --
1858 ---------------------------
1860 procedure Analyze_Renamed_Entry
1865 Nam
: constant Node_Id
:= Name
(N
);
1866 Sel
: constant Node_Id
:= Selector_Name
(Nam
);
1867 Is_Actual
: constant Boolean := Present
(Corresponding_Formal_Spec
(N
));
1871 if Entity
(Sel
) = Any_Id
then
1873 -- Selector is undefined on prefix. Error emitted already
1875 Set_Has_Completion
(New_S
);
1879 -- Otherwise find renamed entity and build body of New_S as a call to it
1881 Old_S
:= Find_Renamed_Entity
(N
, Selector_Name
(Nam
), New_S
);
1883 if Old_S
= Any_Id
then
1884 Error_Msg_N
("no subprogram or entry matches specification", N
);
1887 Check_Subtype_Conformant
(New_S
, Old_S
, N
);
1888 Generate_Reference
(New_S
, Defining_Entity
(N
), 'b');
1889 Style
.Check_Identifier
(Defining_Entity
(N
), New_S
);
1892 -- Only mode conformance required for a renaming_as_declaration
1894 Check_Mode_Conformant
(New_S
, Old_S
, N
);
1897 Inherit_Renamed_Profile
(New_S
, Old_S
);
1899 -- The prefix can be an arbitrary expression that yields a task or
1900 -- protected object, so it must be resolved.
1902 if Is_Access_Type
(Etype
(Prefix
(Nam
))) then
1903 Insert_Explicit_Dereference
(Prefix
(Nam
));
1905 Resolve
(Prefix
(Nam
), Scope
(Old_S
));
1908 Set_Convention
(New_S
, Convention
(Old_S
));
1909 Set_Has_Completion
(New_S
, Inside_A_Generic
);
1911 -- AI05-0225: If the renamed entity is a procedure or entry of a
1912 -- protected object, the target object must be a variable.
1914 if Is_Protected_Type
(Scope
(Old_S
))
1915 and then Ekind
(New_S
) = E_Procedure
1916 and then not Is_Variable
(Prefix
(Nam
))
1920 ("target object of protected operation used as actual for "
1921 & "formal procedure must be a variable", Nam
);
1924 ("target object of protected operation renamed as procedure, "
1925 & "must be a variable", Nam
);
1930 Check_Frozen_Renaming
(N
, New_S
);
1932 end Analyze_Renamed_Entry
;
1934 -----------------------------------
1935 -- Analyze_Renamed_Family_Member --
1936 -----------------------------------
1938 procedure Analyze_Renamed_Family_Member
1943 Nam
: constant Node_Id
:= Name
(N
);
1944 P
: constant Node_Id
:= Prefix
(Nam
);
1948 if (Is_Entity_Name
(P
) and then Ekind
(Entity
(P
)) = E_Entry_Family
)
1949 or else (Nkind
(P
) = N_Selected_Component
1950 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
)
1952 if Is_Entity_Name
(P
) then
1953 Old_S
:= Entity
(P
);
1955 Old_S
:= Entity
(Selector_Name
(P
));
1958 if not Entity_Matches_Spec
(Old_S
, New_S
) then
1959 Error_Msg_N
("entry family does not match specification", N
);
1962 Check_Subtype_Conformant
(New_S
, Old_S
, N
);
1963 Generate_Reference
(New_S
, Defining_Entity
(N
), 'b');
1964 Style
.Check_Identifier
(Defining_Entity
(N
), New_S
);
1968 Error_Msg_N
("no entry family matches specification", N
);
1971 Set_Has_Completion
(New_S
, Inside_A_Generic
);
1974 Check_Frozen_Renaming
(N
, New_S
);
1976 end Analyze_Renamed_Family_Member
;
1978 -----------------------------------------
1979 -- Analyze_Renamed_Primitive_Operation --
1980 -----------------------------------------
1982 procedure Analyze_Renamed_Primitive_Operation
1992 Ctyp
: Conformance_Type
) return Boolean;
1993 -- Verify that the signatures of the renamed entity and the new entity
1994 -- match. The first formal of the renamed entity is skipped because it
1995 -- is the target object in any subsequent call.
2003 Ctyp
: Conformance_Type
) return Boolean
2009 if Ekind
(Subp
) /= Ekind
(New_S
) then
2013 Old_F
:= Next_Formal
(First_Formal
(Subp
));
2014 New_F
:= First_Formal
(New_S
);
2015 while Present
(Old_F
) and then Present
(New_F
) loop
2016 if not Conforming_Types
(Etype
(Old_F
), Etype
(New_F
), Ctyp
) then
2020 if Ctyp
>= Mode_Conformant
2021 and then Ekind
(Old_F
) /= Ekind
(New_F
)
2026 Next_Formal
(New_F
);
2027 Next_Formal
(Old_F
);
2033 -- Start of processing for Analyze_Renamed_Primitive_Operation
2036 if not Is_Overloaded
(Selector_Name
(Name
(N
))) then
2037 Old_S
:= Entity
(Selector_Name
(Name
(N
)));
2039 if not Conforms
(Old_S
, Type_Conformant
) then
2044 -- Find the operation that matches the given signature
2052 Get_First_Interp
(Selector_Name
(Name
(N
)), Ind
, It
);
2054 while Present
(It
.Nam
) loop
2055 if Conforms
(It
.Nam
, Type_Conformant
) then
2059 Get_Next_Interp
(Ind
, It
);
2064 if Old_S
= Any_Id
then
2065 Error_Msg_N
("no subprogram or entry matches specification", N
);
2069 if not Conforms
(Old_S
, Subtype_Conformant
) then
2070 Error_Msg_N
("subtype conformance error in renaming", N
);
2073 Generate_Reference
(New_S
, Defining_Entity
(N
), 'b');
2074 Style
.Check_Identifier
(Defining_Entity
(N
), New_S
);
2077 -- Only mode conformance required for a renaming_as_declaration
2079 if not Conforms
(Old_S
, Mode_Conformant
) then
2080 Error_Msg_N
("mode conformance error in renaming", N
);
2083 -- AI12-0204: The prefix of a prefixed view that is renamed or
2084 -- passed as a formal subprogram must be renamable as an object.
2086 Nam
:= Prefix
(Name
(N
));
2088 if Is_Object_Reference
(Nam
) then
2089 if Is_Dependent_Component_Of_Mutable_Object
(Nam
) then
2091 ("illegal renaming of discriminant-dependent component",
2095 Error_Msg_N
("expect object name in renaming", Nam
);
2098 -- Enforce the rule given in (RM 6.3.1 (10.1/2)): a prefixed
2099 -- view of a subprogram is intrinsic, because the compiler has
2100 -- to generate a wrapper for any call to it. If the name in a
2101 -- subprogram renaming is a prefixed view, the entity is thus
2102 -- intrinsic, and 'Access cannot be applied to it.
2104 Set_Convention
(New_S
, Convention_Intrinsic
);
2107 -- Inherit_Renamed_Profile (New_S, Old_S);
2109 -- The prefix can be an arbitrary expression that yields an
2110 -- object, so it must be resolved.
2112 Resolve
(Prefix
(Name
(N
)));
2114 end Analyze_Renamed_Primitive_Operation
;
2116 ---------------------------------
2117 -- Analyze_Subprogram_Renaming --
2118 ---------------------------------
2120 procedure Analyze_Subprogram_Renaming
(N
: Node_Id
) is
2121 Formal_Spec
: constant Entity_Id
:= Corresponding_Formal_Spec
(N
);
2122 Is_Actual
: constant Boolean := Present
(Formal_Spec
);
2123 Nam
: constant Node_Id
:= Name
(N
);
2124 Save_AV
: constant Ada_Version_Type
:= Ada_Version
;
2125 Save_AVP
: constant Node_Id
:= Ada_Version_Pragma
;
2126 Save_AV_Exp
: constant Ada_Version_Type
:= Ada_Version_Explicit
;
2127 Spec
: constant Node_Id
:= Specification
(N
);
2129 Old_S
: Entity_Id
:= Empty
;
2130 Rename_Spec
: Entity_Id
;
2132 procedure Check_Null_Exclusion
2135 -- Ada 2005 (AI-423): Given renaming Ren of subprogram Sub, check the
2136 -- following AI rules:
2138 -- If Ren denotes a generic formal object of a generic unit G, and the
2139 -- renaming (or instantiation containing the actual) occurs within the
2140 -- body of G or within the body of a generic unit declared within the
2141 -- declarative region of G, then the corresponding parameter of G
2142 -- shall have a null_exclusion; Otherwise the subtype of the Sub's
2143 -- formal parameter shall exclude null.
2145 -- Similarly for its return profile.
2147 procedure Check_SPARK_Primitive_Operation
(Subp_Id
: Entity_Id
);
2148 -- Ensure that a SPARK renaming denoted by its entity Subp_Id does not
2149 -- declare a primitive operation of a tagged type (SPARK RM 6.1.1(3)).
2151 procedure Freeze_Actual_Profile
;
2152 -- In Ada 2012, enforce the freezing rule concerning formal incomplete
2153 -- types: a callable entity freezes its profile, unless it has an
2154 -- incomplete untagged formal (RM 13.14(10.2/3)).
2156 function Has_Class_Wide_Actual
return Boolean;
2157 -- Ada 2012 (AI05-071, AI05-0131) and Ada 2022 (AI12-0165): True if N is
2158 -- the renaming for a defaulted formal subprogram where the actual for
2159 -- the controlling formal type is class-wide.
2161 procedure Handle_Instance_With_Class_Wide_Type
2162 (Inst_Node
: Node_Id
;
2164 Wrapped_Prim
: out Entity_Id
;
2165 Wrap_Id
: out Entity_Id
);
2166 -- Ada 2012 (AI05-0071), Ada 2022 (AI12-0165): when the actual type
2167 -- of an instantiation is a class-wide type T'Class we may need to
2168 -- wrap a primitive operation of T; this routine looks for a suitable
2169 -- primitive to be wrapped and (if the wrapper is required) returns the
2170 -- Id of the wrapped primitive and the Id of the built wrapper. Ren_Id
2171 -- is the defining entity for the renamed subprogram specification.
2173 function Original_Subprogram
(Subp
: Entity_Id
) return Entity_Id
;
2174 -- Find renamed entity when the declaration is a renaming_as_body and
2175 -- the renamed entity may itself be a renaming_as_body. Used to enforce
2176 -- rule that a renaming_as_body is illegal if the declaration occurs
2177 -- before the subprogram it completes is frozen, and renaming indirectly
2178 -- renames the subprogram itself.(Defect Report 8652/0027).
2180 --------------------------
2181 -- Check_Null_Exclusion --
2182 --------------------------
2184 procedure Check_Null_Exclusion
2188 Ren_Formal
: Entity_Id
;
2189 Sub_Formal
: Entity_Id
;
2191 function Null_Exclusion_Mismatch
2192 (Renaming
: Entity_Id
; Renamed
: Entity_Id
) return Boolean;
2193 -- Return True if there is a null exclusion mismatch between
2194 -- Renaming and Renamed, False otherwise.
2196 -----------------------------
2197 -- Null_Exclusion_Mismatch --
2198 -----------------------------
2200 function Null_Exclusion_Mismatch
2201 (Renaming
: Entity_Id
; Renamed
: Entity_Id
) return Boolean is
2203 return Has_Null_Exclusion
(Parent
(Renaming
))
2205 not (Has_Null_Exclusion
(Parent
(Renamed
))
2206 or else (Can_Never_Be_Null
(Etype
(Renamed
))
2208 (Is_Formal_Subprogram
(Sub
)
2209 and then In_Generic_Body
(Current_Scope
))));
2210 end Null_Exclusion_Mismatch
;
2215 Ren_Formal
:= First_Formal
(Ren
);
2216 Sub_Formal
:= First_Formal
(Sub
);
2217 while Present
(Ren_Formal
) and then Present
(Sub_Formal
) loop
2218 if Null_Exclusion_Mismatch
(Ren_Formal
, Sub_Formal
) then
2219 Error_Msg_Sloc
:= Sloc
(Sub_Formal
);
2221 ("`NOT NULL` required for parameter &#",
2222 Ren_Formal
, Sub_Formal
);
2225 Next_Formal
(Ren_Formal
);
2226 Next_Formal
(Sub_Formal
);
2229 -- Return profile check
2231 if Nkind
(Parent
(Ren
)) = N_Function_Specification
2232 and then Nkind
(Parent
(Sub
)) = N_Function_Specification
2233 and then Null_Exclusion_Mismatch
(Ren
, Sub
)
2235 Error_Msg_Sloc
:= Sloc
(Sub
);
2236 Error_Msg_N
("return must specify `NOT NULL`#", Ren
);
2238 end Check_Null_Exclusion
;
2240 -------------------------------------
2241 -- Check_SPARK_Primitive_Operation --
2242 -------------------------------------
2244 procedure Check_SPARK_Primitive_Operation
(Subp_Id
: Entity_Id
) is
2245 Prag
: constant Node_Id
:= SPARK_Pragma
(Subp_Id
);
2249 -- Nothing to do when the subprogram is not subject to SPARK_Mode On
2250 -- because this check applies to SPARK code only.
2252 if not (Present
(Prag
)
2253 and then Get_SPARK_Mode_From_Annotation
(Prag
) = On
)
2257 -- Nothing to do when the subprogram is not a primitive operation
2259 elsif not Is_Primitive
(Subp_Id
) then
2263 Typ
:= Find_Dispatching_Type
(Subp_Id
);
2265 -- Nothing to do when the subprogram is a primitive operation of an
2272 -- At this point a renaming declaration introduces a new primitive
2273 -- operation for a tagged type.
2275 Error_Msg_Node_2
:= Typ
;
2277 ("subprogram renaming & cannot declare primitive for type & "
2278 & "(SPARK RM 6.1.1(3))", N
, Subp_Id
);
2279 end Check_SPARK_Primitive_Operation
;
2281 ---------------------------
2282 -- Freeze_Actual_Profile --
2283 ---------------------------
2285 procedure Freeze_Actual_Profile
is
2287 Has_Untagged_Inc
: Boolean;
2288 Instantiation_Node
: constant Node_Id
:= Parent
(N
);
2291 if Ada_Version
>= Ada_2012
then
2292 F
:= First_Formal
(Formal_Spec
);
2293 Has_Untagged_Inc
:= False;
2294 while Present
(F
) loop
2295 if Ekind
(Etype
(F
)) = E_Incomplete_Type
2296 and then not Is_Tagged_Type
(Etype
(F
))
2298 Has_Untagged_Inc
:= True;
2305 if Ekind
(Formal_Spec
) = E_Function
2306 and then not Is_Tagged_Type
(Etype
(Formal_Spec
))
2308 Has_Untagged_Inc
:= True;
2311 if not Has_Untagged_Inc
then
2312 F
:= First_Formal
(Old_S
);
2313 while Present
(F
) loop
2314 Freeze_Before
(Instantiation_Node
, Etype
(F
));
2316 if Is_Incomplete_Or_Private_Type
(Etype
(F
))
2317 and then No
(Underlying_Type
(Etype
(F
)))
2319 -- Exclude generic types, or types derived from them.
2320 -- They will be frozen in the enclosing instance.
2322 if Is_Generic_Type
(Etype
(F
))
2323 or else Is_Generic_Type
(Root_Type
(Etype
(F
)))
2327 -- A limited view of a type declared elsewhere needs no
2328 -- freezing actions.
2330 elsif From_Limited_With
(Etype
(F
)) then
2335 ("type& must be frozen before this point",
2336 Instantiation_Node
, Etype
(F
));
2344 end Freeze_Actual_Profile
;
2346 ---------------------------
2347 -- Has_Class_Wide_Actual --
2348 ---------------------------
2350 function Has_Class_Wide_Actual
return Boolean is
2352 Formal_Typ
: Entity_Id
;
2356 Formal
:= First_Formal
(Formal_Spec
);
2357 while Present
(Formal
) loop
2358 Formal_Typ
:= Etype
(Formal
);
2360 if Has_Unknown_Discriminants
(Formal_Typ
)
2361 and then not Is_Class_Wide_Type
(Formal_Typ
)
2362 and then Is_Class_Wide_Type
(Get_Instance_Of
(Formal_Typ
))
2367 Next_Formal
(Formal
);
2372 end Has_Class_Wide_Actual
;
2374 ------------------------------------------
2375 -- Handle_Instance_With_Class_Wide_Type --
2376 ------------------------------------------
2378 procedure Handle_Instance_With_Class_Wide_Type
2379 (Inst_Node
: Node_Id
;
2381 Wrapped_Prim
: out Entity_Id
;
2382 Wrap_Id
: out Entity_Id
)
2384 procedure Build_Class_Wide_Wrapper
2385 (Ren_Id
: Entity_Id
;
2386 Prim_Op
: Entity_Id
;
2387 Wrap_Id
: out Entity_Id
);
2388 -- Build a wrapper for the renaming Ren_Id of subprogram Prim_Op.
2390 procedure Find_Suitable_Candidate
2391 (Prim_Op
: out Entity_Id
;
2392 Is_CW_Prim
: out Boolean);
2393 -- Look for a suitable primitive to be wrapped (Prim_Op); Is_CW_Prim
2394 -- indicates that the found candidate is a class-wide primitive (to
2395 -- help the caller decide if the wrapper is required).
2397 ------------------------------
2398 -- Build_Class_Wide_Wrapper --
2399 ------------------------------
2401 procedure Build_Class_Wide_Wrapper
2402 (Ren_Id
: Entity_Id
;
2403 Prim_Op
: Entity_Id
;
2404 Wrap_Id
: out Entity_Id
)
2406 Loc
: constant Source_Ptr
:= Sloc
(N
);
2409 (Subp_Id
: Entity_Id
;
2410 Params
: List_Id
) return Node_Id
;
2411 -- Create a dispatching call to invoke routine Subp_Id with
2412 -- actuals built from the parameter specifications of list Params.
2414 function Build_Expr_Fun_Call
2415 (Subp_Id
: Entity_Id
;
2416 Params
: List_Id
) return Node_Id
;
2417 -- Create a dispatching call to invoke function Subp_Id with
2418 -- actuals built from the parameter specifications of list Params.
2419 -- Directly return the call, so that it can be used inside an
2420 -- expression function. This is a requirement of GNATprove mode.
2422 function Build_Spec
(Subp_Id
: Entity_Id
) return Node_Id
;
2423 -- Create a subprogram specification based on the subprogram
2424 -- profile of Subp_Id.
2431 (Subp_Id
: Entity_Id
;
2432 Params
: List_Id
) return Node_Id
2434 Actuals
: constant List_Id
:= New_List
;
2435 Call_Ref
: constant Node_Id
:= New_Occurrence_Of
(Subp_Id
, Loc
);
2439 -- Build the actual parameters of the call
2441 Formal
:= First
(Params
);
2442 while Present
(Formal
) loop
2444 Make_Identifier
(Loc
,
2445 Chars
(Defining_Identifier
(Formal
))));
2450 -- return Subp_Id (Actuals);
2452 if Ekind
(Subp_Id
) in E_Function | E_Operator
then
2454 Make_Simple_Return_Statement
(Loc
,
2456 Make_Function_Call
(Loc
,
2458 Parameter_Associations
=> Actuals
));
2461 -- Subp_Id (Actuals);
2465 Make_Procedure_Call_Statement
(Loc
,
2467 Parameter_Associations
=> Actuals
);
2471 -------------------------
2472 -- Build_Expr_Fun_Call --
2473 -------------------------
2475 function Build_Expr_Fun_Call
2476 (Subp_Id
: Entity_Id
;
2477 Params
: List_Id
) return Node_Id
2479 Actuals
: constant List_Id
:= New_List
;
2480 Call_Ref
: constant Node_Id
:= New_Occurrence_Of
(Subp_Id
, Loc
);
2484 pragma Assert
(Ekind
(Subp_Id
) in E_Function | E_Operator
);
2486 -- Build the actual parameters of the call
2488 Formal
:= First
(Params
);
2489 while Present
(Formal
) loop
2491 Make_Identifier
(Loc
,
2492 Chars
(Defining_Identifier
(Formal
))));
2497 -- Subp_Id (Actuals);
2500 Make_Function_Call
(Loc
,
2502 Parameter_Associations
=> Actuals
);
2503 end Build_Expr_Fun_Call
;
2509 function Build_Spec
(Subp_Id
: Entity_Id
) return Node_Id
is
2510 Params
: constant List_Id
:= Copy_Parameter_List
(Subp_Id
);
2511 Spec_Id
: constant Entity_Id
:=
2512 Make_Defining_Identifier
(Loc
,
2513 New_External_Name
(Chars
(Subp_Id
), 'R'));
2516 if Ekind
(Formal_Spec
) = E_Procedure
then
2518 Make_Procedure_Specification
(Loc
,
2519 Defining_Unit_Name
=> Spec_Id
,
2520 Parameter_Specifications
=> Params
);
2523 Make_Function_Specification
(Loc
,
2524 Defining_Unit_Name
=> Spec_Id
,
2525 Parameter_Specifications
=> Params
,
2526 Result_Definition
=>
2527 New_Copy_Tree
(Result_Definition
(Spec
)));
2533 Body_Decl
: Node_Id
;
2534 Spec_Decl
: Node_Id
;
2537 -- Start of processing for Build_Class_Wide_Wrapper
2540 pragma Assert
(not Error_Posted
(Nam
));
2542 -- Step 1: Create the declaration and the body of the wrapper,
2543 -- insert all the pieces into the tree.
2545 -- In GNATprove mode, create a function wrapper in the form of an
2546 -- expression function, so that an implicit postcondition relating
2547 -- the result of calling the wrapper function and the result of
2548 -- the dispatching call to the wrapped function is known during
2552 and then Ekind
(Ren_Id
) in E_Function | E_Operator
2554 New_Spec
:= Build_Spec
(Ren_Id
);
2556 Make_Expression_Function
(Loc
,
2557 Specification
=> New_Spec
,
2560 (Subp_Id
=> Prim_Op
,
2561 Params
=> Parameter_Specifications
(New_Spec
)));
2563 Wrap_Id
:= Defining_Entity
(Body_Decl
);
2565 -- Otherwise, create separate spec and body for the subprogram
2569 Make_Subprogram_Declaration
(Loc
,
2570 Specification
=> Build_Spec
(Ren_Id
));
2571 Insert_Before_And_Analyze
(N
, Spec_Decl
);
2573 Wrap_Id
:= Defining_Entity
(Spec_Decl
);
2576 Make_Subprogram_Body
(Loc
,
2577 Specification
=> Build_Spec
(Ren_Id
),
2578 Declarations
=> New_List
,
2579 Handled_Statement_Sequence
=>
2580 Make_Handled_Sequence_Of_Statements
(Loc
,
2581 Statements
=> New_List
(
2583 (Subp_Id
=> Prim_Op
,
2585 Parameter_Specifications
2586 (Specification
(Spec_Decl
))))));
2588 Set_Corresponding_Body
(Spec_Decl
, Defining_Entity
(Body_Decl
));
2591 Set_Is_Class_Wide_Wrapper
(Wrap_Id
);
2593 -- If the operator carries an Eliminated pragma, indicate that
2594 -- the wrapper is also to be eliminated, to prevent spurious
2595 -- errors when using gnatelim on programs that include box-
2596 -- defaulted initialization of equality operators.
2598 Set_Is_Eliminated
(Wrap_Id
, Is_Eliminated
(Prim_Op
));
2600 -- In GNATprove mode, insert the body in the tree for analysis
2602 if GNATprove_Mode
then
2603 Insert_Before_And_Analyze
(N
, Body_Decl
);
2606 -- The generated body does not freeze and must be analyzed when
2607 -- the class-wide wrapper is frozen. The body is only needed if
2608 -- expansion is enabled.
2610 if Expander_Active
then
2611 Append_Freeze_Action
(Wrap_Id
, Body_Decl
);
2614 -- Step 2: The subprogram renaming aliases the wrapper
2616 Rewrite
(Name
(N
), New_Occurrence_Of
(Wrap_Id
, Loc
));
2617 end Build_Class_Wide_Wrapper
;
2619 -----------------------------
2620 -- Find_Suitable_Candidate --
2621 -----------------------------
2623 procedure Find_Suitable_Candidate
2624 (Prim_Op
: out Entity_Id
;
2625 Is_CW_Prim
: out Boolean)
2627 Loc
: constant Source_Ptr
:= Sloc
(N
);
2629 function Find_Primitive
(Typ
: Entity_Id
) return Entity_Id
;
2630 -- Find a primitive subprogram of type Typ which matches the
2631 -- profile of the renaming declaration.
2633 procedure Interpretation_Error
(Subp_Id
: Entity_Id
);
2634 -- Emit a continuation error message suggesting subprogram Subp_Id
2635 -- as a possible interpretation.
2637 function Is_Intrinsic_Equality
2638 (Subp_Id
: Entity_Id
) return Boolean;
2639 -- Determine whether subprogram Subp_Id denotes the intrinsic "="
2642 function Is_Suitable_Candidate
2643 (Subp_Id
: Entity_Id
) return Boolean;
2644 -- Determine whether subprogram Subp_Id is a suitable candidate
2645 -- for the role of a wrapped subprogram.
2647 --------------------
2648 -- Find_Primitive --
2649 --------------------
2651 function Find_Primitive
(Typ
: Entity_Id
) return Entity_Id
is
2652 procedure Replace_Parameter_Types
(Spec
: Node_Id
);
2653 -- Given a specification Spec, replace all class-wide parameter
2654 -- types with reference to type Typ.
2656 -----------------------------
2657 -- Replace_Parameter_Types --
2658 -----------------------------
2660 procedure Replace_Parameter_Types
(Spec
: Node_Id
) is
2662 Formal_Id
: Entity_Id
;
2663 Formal_Typ
: Node_Id
;
2666 Formal
:= First
(Parameter_Specifications
(Spec
));
2667 while Present
(Formal
) loop
2668 Formal_Id
:= Defining_Identifier
(Formal
);
2669 Formal_Typ
:= Parameter_Type
(Formal
);
2671 -- Create a new entity for each class-wide formal to
2672 -- prevent aliasing with the original renaming. Replace
2673 -- the type of such a parameter with the candidate type.
2675 if Nkind
(Formal_Typ
) = N_Identifier
2676 and then Is_Class_Wide_Type
(Etype
(Formal_Typ
))
2678 Set_Defining_Identifier
(Formal
,
2679 Make_Defining_Identifier
(Loc
, Chars
(Formal_Id
)));
2681 Set_Parameter_Type
(Formal
,
2682 New_Occurrence_Of
(Typ
, Loc
));
2687 end Replace_Parameter_Types
;
2691 Alt_Ren
: constant Node_Id
:= New_Copy_Tree
(N
);
2692 Alt_Nam
: constant Node_Id
:= Name
(Alt_Ren
);
2693 Alt_Spec
: constant Node_Id
:= Specification
(Alt_Ren
);
2694 Subp_Id
: Entity_Id
;
2696 -- Start of processing for Find_Primitive
2699 -- Each attempt to find a suitable primitive of a particular
2700 -- type operates on its own copy of the original renaming.
2701 -- As a result the original renaming is kept decoration and
2702 -- side-effect free.
2704 -- Inherit the overloaded status of the renamed subprogram name
2706 if Is_Overloaded
(Nam
) then
2707 Set_Is_Overloaded
(Alt_Nam
);
2708 Save_Interps
(Nam
, Alt_Nam
);
2711 -- The copied renaming is hidden from visibility to prevent the
2712 -- pollution of the enclosing context.
2714 Set_Defining_Unit_Name
(Alt_Spec
, Make_Temporary
(Loc
, 'R'));
2716 -- The types of all class-wide parameters must be changed to
2717 -- the candidate type.
2719 Replace_Parameter_Types
(Alt_Spec
);
2721 -- Try to find a suitable primitive that matches the altered
2722 -- profile of the renaming specification.
2727 Nam
=> Name
(Alt_Ren
),
2728 New_S
=> Analyze_Subprogram_Specification
(Alt_Spec
),
2729 Is_Actual
=> Is_Actual
);
2731 -- Do not return Any_Id if the resolution of the altered
2732 -- profile failed as this complicates further checks on
2733 -- the caller side; return Empty instead.
2735 if Subp_Id
= Any_Id
then
2742 --------------------------
2743 -- Interpretation_Error --
2744 --------------------------
2746 procedure Interpretation_Error
(Subp_Id
: Entity_Id
) is
2748 Error_Msg_Sloc
:= Sloc
(Subp_Id
);
2750 if Is_Internal
(Subp_Id
) then
2752 ("\\possible interpretation: predefined & #",
2756 ("\\possible interpretation: & defined #",
2759 end Interpretation_Error
;
2761 ---------------------------
2762 -- Is_Intrinsic_Equality --
2763 ---------------------------
2765 function Is_Intrinsic_Equality
(Subp_Id
: Entity_Id
) return Boolean
2769 Ekind
(Subp_Id
) = E_Operator
2770 and then Chars
(Subp_Id
) = Name_Op_Eq
2771 and then Is_Intrinsic_Subprogram
(Subp_Id
);
2772 end Is_Intrinsic_Equality
;
2774 ---------------------------
2775 -- Is_Suitable_Candidate --
2776 ---------------------------
2778 function Is_Suitable_Candidate
(Subp_Id
: Entity_Id
) return Boolean
2781 if No
(Subp_Id
) then
2784 -- An intrinsic subprogram is never a good candidate. This
2785 -- is an indication of a missing primitive, either defined
2786 -- directly or inherited from a parent tagged type.
2788 elsif Is_Intrinsic_Subprogram
(Subp_Id
) then
2794 end Is_Suitable_Candidate
;
2798 Actual_Typ
: Entity_Id
:= Empty
;
2799 -- The actual class-wide type for Formal_Typ
2801 CW_Prim_OK
: Boolean;
2802 CW_Prim_Op
: Entity_Id
;
2803 -- The class-wide subprogram (if available) that corresponds to
2804 -- the renamed generic formal subprogram.
2806 Formal_Typ
: Entity_Id
:= Empty
;
2807 -- The generic formal type with unknown discriminants
2809 Root_Prim_OK
: Boolean;
2810 Root_Prim_Op
: Entity_Id
;
2811 -- The root type primitive (if available) that corresponds to the
2812 -- renamed generic formal subprogram.
2814 Root_Typ
: Entity_Id
:= Empty
;
2815 -- The root type of Actual_Typ
2819 -- Start of processing for Find_Suitable_Candidate
2822 pragma Assert
(not Error_Posted
(Nam
));
2825 Is_CW_Prim
:= False;
2827 -- Analyze the renamed name, but do not resolve it. The resolution
2828 -- is completed once a suitable subprogram is found.
2832 -- When the renamed name denotes the intrinsic operator equals,
2833 -- the name must be treated as overloaded. This allows for a
2834 -- potential match against the root type's predefined equality
2837 if Is_Intrinsic_Equality
(Entity
(Nam
)) then
2838 Set_Is_Overloaded
(Nam
);
2839 Collect_Interps
(Nam
);
2842 -- Step 1: Find the generic formal type and its corresponding
2843 -- class-wide actual type from the renamed generic formal
2846 Formal
:= First_Formal
(Formal_Spec
);
2847 while Present
(Formal
) loop
2848 if Has_Unknown_Discriminants
(Etype
(Formal
))
2849 and then not Is_Class_Wide_Type
(Etype
(Formal
))
2850 and then Is_Class_Wide_Type
(Get_Instance_Of
(Etype
(Formal
)))
2852 Formal_Typ
:= Etype
(Formal
);
2853 Actual_Typ
:= Base_Type
(Get_Instance_Of
(Formal_Typ
));
2854 Root_Typ
:= Root_Type
(Actual_Typ
);
2858 Next_Formal
(Formal
);
2861 -- The specification of the generic formal subprogram should
2862 -- always contain a formal type with unknown discriminants whose
2863 -- actual is a class-wide type; otherwise this indicates a failure
2864 -- in function Has_Class_Wide_Actual.
2866 pragma Assert
(Present
(Formal_Typ
));
2868 -- Step 2: Find the proper class-wide subprogram or primitive
2869 -- that corresponds to the renamed generic formal subprogram.
2871 CW_Prim_Op
:= Find_Primitive
(Actual_Typ
);
2872 CW_Prim_OK
:= Is_Suitable_Candidate
(CW_Prim_Op
);
2873 Root_Prim_Op
:= Find_Primitive
(Root_Typ
);
2874 Root_Prim_OK
:= Is_Suitable_Candidate
(Root_Prim_Op
);
2876 -- The class-wide actual type has two subprograms that correspond
2877 -- to the renamed generic formal subprogram:
2879 -- with procedure Prim_Op (Param : Formal_Typ);
2881 -- procedure Prim_Op (Param : Actual_Typ); -- may be inherited
2882 -- procedure Prim_Op (Param : Actual_Typ'Class);
2884 -- Even though the declaration of the two subprograms is legal, a
2885 -- call to either one is ambiguous and therefore illegal.
2887 if CW_Prim_OK
and Root_Prim_OK
then
2889 -- A user-defined primitive has precedence over a predefined
2892 if Is_Internal
(CW_Prim_Op
)
2893 and then not Is_Internal
(Root_Prim_Op
)
2895 Prim_Op
:= Root_Prim_Op
;
2897 elsif Is_Internal
(Root_Prim_Op
)
2898 and then not Is_Internal
(CW_Prim_Op
)
2900 Prim_Op
:= CW_Prim_Op
;
2903 elsif CW_Prim_Op
= Root_Prim_Op
then
2904 Prim_Op
:= Root_Prim_Op
;
2906 -- The two subprograms are legal but the class-wide subprogram
2907 -- is a class-wide wrapper built for a previous instantiation;
2908 -- the wrapper has precedence.
2910 elsif Present
(Alias
(CW_Prim_Op
))
2911 and then Is_Class_Wide_Wrapper
(Ultimate_Alias
(CW_Prim_Op
))
2913 Prim_Op
:= CW_Prim_Op
;
2916 -- Otherwise both candidate subprograms are user-defined and
2921 ("ambiguous actual for generic subprogram &",
2923 Interpretation_Error
(Root_Prim_Op
);
2924 Interpretation_Error
(CW_Prim_Op
);
2928 elsif CW_Prim_OK
and not Root_Prim_OK
then
2929 Prim_Op
:= CW_Prim_Op
;
2932 elsif not CW_Prim_OK
and Root_Prim_OK
then
2933 Prim_Op
:= Root_Prim_Op
;
2935 -- An intrinsic equality may act as a suitable candidate in the
2936 -- case of a null type extension where the parent's equality
2937 -- is hidden. A call to an intrinsic equality is expanded as
2940 elsif Present
(Root_Prim_Op
)
2941 and then Is_Intrinsic_Equality
(Root_Prim_Op
)
2943 Prim_Op
:= Root_Prim_Op
;
2945 -- Otherwise there are no candidate subprograms. Let the caller
2946 -- diagnose the error.
2952 -- At this point resolution has taken place and the name is no
2953 -- longer overloaded. Mark the primitive as referenced.
2955 Set_Is_Overloaded
(Name
(N
), False);
2956 Set_Referenced
(Prim_Op
);
2957 end Find_Suitable_Candidate
;
2961 Is_CW_Prim
: Boolean;
2963 -- Start of processing for Handle_Instance_With_Class_Wide_Type
2966 Wrapped_Prim
:= Empty
;
2969 -- Ada 2012 (AI05-0071): A generic/instance scenario involving a
2970 -- formal type with unknown discriminants and a generic primitive
2971 -- operation of the said type with a box require special processing
2972 -- when the actual is a class-wide type:
2975 -- type Formal_Typ (<>) is private;
2976 -- with procedure Prim_Op (Param : Formal_Typ) is <>;
2977 -- package Gen is ...
2979 -- package Inst is new Gen (Actual_Typ'Class);
2981 -- In this case the general renaming mechanism used in the prologue
2982 -- of an instance no longer applies:
2984 -- procedure Prim_Op (Param : Formal_Typ) renames Prim_Op;
2986 -- The above is replaced the following wrapper/renaming combination:
2988 -- procedure Wrapper (Param : Formal_Typ) is -- wrapper
2990 -- Prim_Op (Param); -- primitive
2993 -- procedure Prim_Op (Param : Formal_Typ) renames Wrapper;
2995 -- This transformation applies only if there is no explicit visible
2996 -- class-wide operation at the point of the instantiation. Ren_Id is
2997 -- the entity of the renaming declaration. When the transformation
2998 -- applies, Wrapped_Prim is the entity of the wrapped primitive.
3000 if Box_Present
(Inst_Node
) then
3001 Find_Suitable_Candidate
3002 (Prim_Op
=> Wrapped_Prim
,
3003 Is_CW_Prim
=> Is_CW_Prim
);
3005 if Present
(Wrapped_Prim
) then
3006 if not Is_CW_Prim
then
3007 Build_Class_Wide_Wrapper
(Ren_Id
, Wrapped_Prim
, Wrap_Id
);
3009 -- Small optimization: When the candidate is a class-wide
3010 -- subprogram we don't build the wrapper; we modify the
3011 -- renaming declaration to directly map the actual to the
3012 -- generic formal and discard the candidate.
3015 Rewrite
(Nam
, New_Occurrence_Of
(Wrapped_Prim
, Sloc
(N
)));
3016 Wrapped_Prim
:= Empty
;
3020 -- Ada 2022 (AI12-0165, RM 12.6(8.5/3)): The actual subprogram for a
3021 -- formal_abstract_subprogram_declaration shall be:
3022 -- a) a dispatching operation of the controlling type; or
3023 -- b) if the controlling type is a formal type, and the actual
3024 -- type corresponding to that formal type is a specific type T,
3025 -- a dispatching operation of type T; or
3026 -- c) if the controlling type is a formal type, and the actual
3027 -- type is a class-wide type T'Class, an implicitly declared
3028 -- subprogram corresponding to a primitive operation of type T.
3030 elsif Nkind
(Inst_Node
) = N_Formal_Abstract_Subprogram_Declaration
3031 and then Is_Entity_Name
(Nam
)
3033 Find_Suitable_Candidate
3034 (Prim_Op
=> Wrapped_Prim
,
3035 Is_CW_Prim
=> Is_CW_Prim
);
3037 if Present
(Wrapped_Prim
) then
3039 -- Cases (a) and (b); see previous description.
3041 if not Is_CW_Prim
then
3042 Build_Class_Wide_Wrapper
(Ren_Id
, Wrapped_Prim
, Wrap_Id
);
3044 -- Case (c); see previous description.
3046 -- Implicit operations of T'Class for subtype declarations
3047 -- are built by Derive_Subprogram, and their Alias attribute
3048 -- references the primitive operation of T.
3050 elsif not Comes_From_Source
(Wrapped_Prim
)
3051 and then Nkind
(Parent
(Wrapped_Prim
)) = N_Subtype_Declaration
3052 and then Present
(Alias
(Wrapped_Prim
))
3054 -- We don't need to build the wrapper; we modify the
3055 -- renaming declaration to directly map the actual to
3056 -- the generic formal and discard the candidate.
3059 New_Occurrence_Of
(Alias
(Wrapped_Prim
), Sloc
(N
)));
3060 Wrapped_Prim
:= Empty
;
3062 -- Legality rules do not apply; discard the candidate.
3065 Wrapped_Prim
:= Empty
;
3069 end Handle_Instance_With_Class_Wide_Type
;
3071 -------------------------
3072 -- Original_Subprogram --
3073 -------------------------
3075 function Original_Subprogram
(Subp
: Entity_Id
) return Entity_Id
is
3076 Orig_Decl
: Node_Id
;
3077 Orig_Subp
: Entity_Id
;
3080 -- First case: renamed entity is itself a renaming
3082 if Present
(Alias
(Subp
)) then
3083 return Alias
(Subp
);
3085 elsif Nkind
(Unit_Declaration_Node
(Subp
)) = N_Subprogram_Declaration
3086 and then Present
(Corresponding_Body
(Unit_Declaration_Node
(Subp
)))
3088 -- Check if renamed entity is a renaming_as_body
3091 Unit_Declaration_Node
3092 (Corresponding_Body
(Unit_Declaration_Node
(Subp
)));
3094 if Nkind
(Orig_Decl
) = N_Subprogram_Renaming_Declaration
then
3095 Orig_Subp
:= Entity
(Name
(Orig_Decl
));
3097 if Orig_Subp
= Rename_Spec
then
3099 -- Circularity detected
3104 return (Original_Subprogram
(Orig_Subp
));
3112 end Original_Subprogram
;
3116 CW_Actual
: constant Boolean := Has_Class_Wide_Actual
;
3117 -- Ada 2012 (AI05-071, AI05-0131) and Ada 2022 (AI12-0165): True if the
3118 -- renaming is for a defaulted formal subprogram when the actual for a
3119 -- related formal type is class-wide.
3121 Inst_Node
: Node_Id
:= Empty
;
3122 New_S
: Entity_Id
:= Empty
;
3123 Wrapped_Prim
: Entity_Id
:= Empty
;
3125 -- Start of processing for Analyze_Subprogram_Renaming
3128 -- We must test for the attribute renaming case before the Analyze
3129 -- call because otherwise Sem_Attr will complain that the attribute
3130 -- is missing an argument when it is analyzed.
3132 if Nkind
(Nam
) = N_Attribute_Reference
then
3134 -- In the case of an abstract formal subprogram association, rewrite
3135 -- an actual given by a stream or Put_Image attribute as the name of
3136 -- the corresponding stream or Put_Image primitive of the type.
3138 -- In a generic context the stream and Put_Image operations are not
3139 -- generated, and this must be treated as a normal attribute
3140 -- reference, to be expanded in subsequent instantiations.
3143 and then Is_Abstract_Subprogram
(Formal_Spec
)
3144 and then Expander_Active
3147 Prefix_Type
: constant Entity_Id
:= Entity
(Prefix
(Nam
));
3151 -- The class-wide forms of the stream and Put_Image attributes
3152 -- are not primitive dispatching operations (even though they
3153 -- internally dispatch).
3155 if Is_Class_Wide_Type
(Prefix_Type
) then
3157 ("attribute must be a primitive dispatching operation",
3162 -- Retrieve the primitive subprogram associated with the
3163 -- attribute. This can only be a stream attribute, since those
3164 -- are the only ones that are dispatching (and the actual for
3165 -- an abstract formal subprogram must be dispatching
3168 case Attribute_Name
(Nam
) is
3171 Find_Optional_Prim_Op
(Prefix_Type
, TSS_Stream_Input
);
3175 Find_Optional_Prim_Op
(Prefix_Type
, TSS_Stream_Output
);
3179 Find_Optional_Prim_Op
(Prefix_Type
, TSS_Stream_Read
);
3183 Find_Optional_Prim_Op
(Prefix_Type
, TSS_Stream_Write
);
3185 when Name_Put_Image
=>
3187 Find_Optional_Prim_Op
(Prefix_Type
, TSS_Put_Image
);
3191 ("attribute must be a primitive dispatching operation",
3196 -- If no stream operation was found, and the type is limited,
3197 -- the user should have defined one. This rule does not apply
3201 and then Attribute_Name
(Nam
) /= Name_Put_Image
3203 if Is_Limited_Type
(Prefix_Type
) then
3205 ("stream operation not defined for type&",
3209 -- Otherwise, compiler should have generated default
3212 raise Program_Error
;
3216 -- Rewrite the attribute into the name of its corresponding
3217 -- primitive dispatching subprogram. We can then proceed with
3218 -- the usual processing for subprogram renamings.
3221 Prim_Name
: constant Node_Id
:=
3222 Make_Identifier
(Sloc
(Nam
),
3223 Chars
=> Chars
(Prim
));
3225 Set_Entity
(Prim_Name
, Prim
);
3226 Rewrite
(Nam
, Prim_Name
);
3231 -- Normal processing for a renaming of an attribute
3234 Attribute_Renaming
(N
);
3239 -- Check whether this declaration corresponds to the instantiation of a
3240 -- formal subprogram.
3242 -- If this is an instantiation, the corresponding actual is frozen and
3243 -- error messages can be made more precise. If this is a default
3244 -- subprogram, the entity is already established in the generic, and is
3245 -- not retrieved by visibility. If it is a default with a box, the
3246 -- candidate interpretations, if any, have been collected when building
3247 -- the renaming declaration. If overloaded, the proper interpretation is
3248 -- determined in Find_Renamed_Entity. If the entity is an operator,
3249 -- Find_Renamed_Entity applies additional visibility checks.
3252 Inst_Node
:= Unit_Declaration_Node
(Formal_Spec
);
3254 -- Ada 2012 (AI05-0071) and Ada 2022 (AI12-0165): when the actual
3255 -- type is a class-wide type T'Class we may need to wrap a primitive
3256 -- operation of T. Search for the wrapped primitive and (if required)
3257 -- build a wrapper whose body consists of a dispatching call to the
3258 -- wrapped primitive of T, with its formal parameters as the actual
3261 if CW_Actual
and then
3263 -- Ada 2012 (AI05-0071): Check whether the renaming is for a
3264 -- defaulted actual subprogram with a class-wide actual.
3266 (Box_Present
(Inst_Node
)
3270 -- Ada 2022 (AI12-0165): Check whether the renaming is for a formal
3271 -- abstract subprogram declaration with a class-wide actual.
3273 (Nkind
(Inst_Node
) = N_Formal_Abstract_Subprogram_Declaration
3274 and then Is_Entity_Name
(Nam
)))
3276 New_S
:= Analyze_Subprogram_Specification
(Spec
);
3278 -- Do not attempt to build the wrapper if the renaming is in error
3280 if not Error_Posted
(Nam
) then
3281 Handle_Instance_With_Class_Wide_Type
3282 (Inst_Node
=> Inst_Node
,
3284 Wrapped_Prim
=> Wrapped_Prim
,
3287 -- If several candidates were found, then we reported the
3288 -- ambiguity; stop processing the renaming declaration to
3289 -- avoid reporting further (spurious) errors.
3291 if Error_Posted
(Spec
) then
3298 if Present
(Wrapped_Prim
) then
3300 -- When the wrapper is built, the subprogram renaming aliases
3305 pragma Assert
(Old_S
= Entity
(Nam
)
3306 and then Is_Class_Wide_Wrapper
(Old_S
));
3308 -- The subprogram renaming declaration may become Ghost if it
3309 -- renames a wrapper of a Ghost entity.
3311 Mark_Ghost_Renaming
(N
, Wrapped_Prim
);
3313 elsif Is_Entity_Name
(Nam
)
3314 and then Present
(Entity
(Nam
))
3315 and then not Comes_From_Source
(Nam
)
3316 and then not Is_Overloaded
(Nam
)
3318 Old_S
:= Entity
(Nam
);
3320 -- The subprogram renaming declaration may become Ghost if it
3321 -- renames a Ghost entity.
3323 Mark_Ghost_Renaming
(N
, Old_S
);
3325 New_S
:= Analyze_Subprogram_Specification
(Spec
);
3329 if Ekind
(Old_S
) = E_Operator
then
3333 if Box_Present
(Inst_Node
) then
3334 Old_S
:= Find_Renamed_Entity
(N
, Name
(N
), New_S
, Is_Actual
);
3336 -- If there is an immediately visible homonym of the operator
3337 -- and the declaration has a default, this is worth a warning
3338 -- because the user probably did not intend to get the pre-
3339 -- defined operator, visible in the generic declaration. To
3340 -- find if there is an intended candidate, analyze the renaming
3341 -- again in the current context.
3343 elsif Scope
(Old_S
) = Standard_Standard
3344 and then Present
(Default_Name
(Inst_Node
))
3347 Decl
: constant Node_Id
:= New_Copy_Tree
(N
);
3351 Set_Entity
(Name
(Decl
), Empty
);
3352 Analyze
(Name
(Decl
));
3354 Find_Renamed_Entity
(Decl
, Name
(Decl
), New_S
, True);
3357 and then In_Open_Scopes
(Scope
(Hidden
))
3358 and then Is_Immediately_Visible
(Hidden
)
3359 and then Comes_From_Source
(Hidden
)
3360 and then Hidden
/= Old_S
3362 Error_Msg_Sloc
:= Sloc
(Hidden
);
3364 ("default subprogram is resolved in the generic "
3365 & "declaration (RM 12.6(17))??", N
);
3366 Error_Msg_NE
("\and will not use & #??", N
, Hidden
);
3375 -- The subprogram renaming declaration may become Ghost if it
3376 -- renames a Ghost entity.
3378 if Is_Entity_Name
(Nam
) then
3379 Mark_Ghost_Renaming
(N
, Entity
(Nam
));
3382 New_S
:= Analyze_Subprogram_Specification
(Spec
);
3386 -- Renamed entity must be analyzed first, to avoid being hidden by
3387 -- new name (which might be the same in a generic instance).
3391 -- The subprogram renaming declaration may become Ghost if it renames
3394 if Is_Entity_Name
(Nam
) then
3395 Mark_Ghost_Renaming
(N
, Entity
(Nam
));
3398 -- The renaming defines a new overloaded entity, which is analyzed
3399 -- like a subprogram declaration.
3401 New_S
:= Analyze_Subprogram_Specification
(Spec
);
3404 if Current_Scope
/= Standard_Standard
then
3405 Set_Is_Pure
(New_S
, Is_Pure
(Current_Scope
));
3408 -- Set SPARK mode from current context
3410 Set_SPARK_Pragma
(New_S
, SPARK_Mode_Pragma
);
3411 Set_SPARK_Pragma_Inherited
(New_S
);
3413 Rename_Spec
:= Find_Corresponding_Spec
(N
);
3415 -- Case of Renaming_As_Body
3417 if Present
(Rename_Spec
) then
3418 Check_Previous_Null_Procedure
(N
, Rename_Spec
);
3420 -- Renaming declaration is the completion of the declaration of
3421 -- Rename_Spec. We build an actual body for it at the freezing point.
3423 Set_Corresponding_Spec
(N
, Rename_Spec
);
3425 -- Deal with special case of stream functions of abstract types
3428 if Nkind
(Unit_Declaration_Node
(Rename_Spec
)) =
3429 N_Abstract_Subprogram_Declaration
3431 -- Input stream functions are abstract if the object type is
3432 -- abstract. Similarly, all default stream functions for an
3433 -- interface type are abstract. However, these subprograms may
3434 -- receive explicit declarations in representation clauses, making
3435 -- the attribute subprograms usable as defaults in subsequent
3437 -- In this case we rewrite the declaration to make the subprogram
3438 -- non-abstract. We remove the previous declaration, and insert
3439 -- the new one at the point of the renaming, to prevent premature
3440 -- access to unfrozen types. The new declaration reuses the
3441 -- specification of the previous one, and must not be analyzed.
3444 (Is_Primitive
(Entity
(Nam
))
3446 Is_Abstract_Type
(Find_Dispatching_Type
(Entity
(Nam
))));
3448 Old_Decl
: constant Node_Id
:=
3449 Unit_Declaration_Node
(Rename_Spec
);
3450 New_Decl
: constant Node_Id
:=
3451 Make_Subprogram_Declaration
(Sloc
(N
),
3453 Relocate_Node
(Specification
(Old_Decl
)));
3456 Insert_After
(N
, New_Decl
);
3457 Set_Is_Abstract_Subprogram
(Rename_Spec
, False);
3458 Set_Analyzed
(New_Decl
);
3462 Set_Corresponding_Body
(Unit_Declaration_Node
(Rename_Spec
), New_S
);
3464 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3465 Error_Msg_N
("(Ada 83) renaming cannot serve as a body", N
);
3468 Set_Convention
(New_S
, Convention
(Rename_Spec
));
3469 Check_Fully_Conformant
(New_S
, Rename_Spec
);
3470 Set_Public_Status
(New_S
);
3472 if No_Return
(Rename_Spec
)
3473 and then not No_Return
(Entity
(Nam
))
3476 ("renamed subprogram & must be No_Return", N
, Entity
(Nam
));
3478 ("\since renaming subprogram is No_Return (RM 6.5.1(7/2))", N
);
3481 -- The specification does not introduce new formals, but only
3482 -- repeats the formals of the original subprogram declaration.
3483 -- For cross-reference purposes, and for refactoring tools, we
3484 -- treat the formals of the renaming declaration as body formals.
3486 Reference_Body_Formals
(Rename_Spec
, New_S
);
3488 -- Indicate that the entity in the declaration functions like the
3489 -- corresponding body, and is not a new entity. The body will be
3490 -- constructed later at the freeze point, so indicate that the
3491 -- completion has not been seen yet.
3493 Reinit_Field_To_Zero
(New_S
, F_Has_Out_Or_In_Out_Parameter
,
3494 Old_Ekind
=> (E_Function | E_Procedure
=> True, others => False));
3495 Reinit_Field_To_Zero
(New_S
, F_Needs_No_Actuals
);
3496 Reinit_Field_To_Zero
(New_S
, F_Is_Predicate_Function
);
3497 Reinit_Field_To_Zero
(New_S
, F_Protected_Subprogram
);
3498 Reinit_Field_To_Zero
(New_S
, F_Is_Inlined_Always
);
3499 Reinit_Field_To_Zero
(New_S
, F_Is_Generic_Actual_Subprogram
);
3500 Mutate_Ekind
(New_S
, E_Subprogram_Body
);
3501 New_S
:= Rename_Spec
;
3502 Set_Has_Completion
(Rename_Spec
, False);
3504 -- Ada 2005: check overriding indicator
3506 if Present
(Overridden_Operation
(Rename_Spec
)) then
3507 if Must_Not_Override
(Specification
(N
)) then
3509 ("subprogram& overrides inherited operation",
3513 and then not Must_Override
(Specification
(N
))
3515 Style
.Missing_Overriding
(N
, Rename_Spec
);
3518 elsif Must_Override
(Specification
(N
))
3519 and then not Can_Override_Operator
(Rename_Spec
)
3521 Error_Msg_NE
("subprogram& is not overriding", N
, Rename_Spec
);
3524 -- AI12-0132: a renames-as-body freezes the expression of any
3525 -- expression function that it renames.
3527 if Is_Entity_Name
(Nam
)
3528 and then Is_Expression_Function
(Entity
(Nam
))
3529 and then not Inside_A_Generic
3532 (Def_Id
=> Entity
(Nam
),
3533 Typ
=> Etype
(Entity
(Nam
)),
3536 (Original_Node
(Unit_Declaration_Node
(Entity
(Nam
)))),
3540 -- Normal subprogram renaming (not renaming as body)
3543 Generate_Definition
(New_S
);
3544 New_Overloaded_Entity
(New_S
);
3546 if not (Is_Entity_Name
(Nam
)
3547 and then Is_Intrinsic_Subprogram
(Entity
(Nam
)))
3549 Check_Delayed_Subprogram
(New_S
);
3552 -- Verify that a SPARK renaming does not declare a primitive
3553 -- operation of a tagged type.
3555 Check_SPARK_Primitive_Operation
(New_S
);
3558 -- There is no need for elaboration checks on the new entity, which may
3559 -- be called before the next freezing point where the body will appear.
3560 -- Elaboration checks refer to the real entity, not the one created by
3561 -- the renaming declaration.
3563 Set_Kill_Elaboration_Checks
(New_S
, True);
3565 -- If we had a previous error, indicate a completion is present to stop
3566 -- junk cascaded messages, but don't take any further action.
3568 if Etype
(Nam
) = Any_Type
then
3569 Set_Has_Completion
(New_S
);
3572 -- Case where name has the form of a selected component
3574 elsif Nkind
(Nam
) = N_Selected_Component
then
3576 -- A name which has the form A.B can designate an entry of task A, a
3577 -- protected operation of protected object A, or finally a primitive
3578 -- operation of object A. In the later case, A is an object of some
3579 -- tagged type, or an access type that denotes one such. To further
3580 -- distinguish these cases, note that the scope of a task entry or
3581 -- protected operation is type of the prefix.
3583 -- The prefix could be an overloaded function call that returns both
3584 -- kinds of operations. This overloading pathology is left to the
3585 -- dedicated reader ???
3588 T
: constant Entity_Id
:= Etype
(Prefix
(Nam
));
3596 and then Is_Tagged_Type
(Designated_Type
(T
))))
3597 and then Scope
(Entity
(Selector_Name
(Nam
))) /= T
3599 Analyze_Renamed_Primitive_Operation
3600 (N
, New_S
, Present
(Rename_Spec
));
3604 -- Renamed entity is an entry or protected operation. For those
3605 -- cases an explicit body is built (at the point of freezing of
3606 -- this entity) that contains a call to the renamed entity.
3608 -- This is not allowed for renaming as body if the renamed
3609 -- spec is already frozen (see RM 8.5.4(5) for details).
3611 if Present
(Rename_Spec
) and then Is_Frozen
(Rename_Spec
) then
3613 ("renaming-as-body cannot rename entry as subprogram", N
);
3615 ("\since & is already frozen (RM 8.5.4(5))",
3618 Analyze_Renamed_Entry
(N
, New_S
, Present
(Rename_Spec
));
3625 -- Case where name is an explicit dereference X.all
3627 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
3629 -- Renamed entity is designated by access_to_subprogram expression.
3630 -- Must build body to encapsulate call, as in the entry case.
3632 Analyze_Renamed_Dereference
(N
, New_S
, Present
(Rename_Spec
));
3635 -- Indexed component
3637 elsif Nkind
(Nam
) = N_Indexed_Component
then
3638 Analyze_Renamed_Family_Member
(N
, New_S
, Present
(Rename_Spec
));
3641 -- Character literal
3643 elsif Nkind
(Nam
) = N_Character_Literal
then
3644 Analyze_Renamed_Character
(N
, New_S
, Present
(Rename_Spec
));
3647 -- Only remaining case is where we have a non-entity name, or a renaming
3648 -- of some other non-overloadable entity.
3650 elsif not Is_Entity_Name
(Nam
)
3651 or else not Is_Overloadable
(Entity
(Nam
))
3653 -- Do not mention the renaming if it comes from an instance
3655 if not Is_Actual
then
3656 Error_Msg_N
("expect valid subprogram name in renaming", N
);
3658 Error_Msg_NE
("no visible subprogram for formal&", N
, Nam
);
3664 -- Find the renamed entity that matches the given specification. Disable
3665 -- Ada_83 because there is no requirement of full conformance between
3666 -- renamed entity and new entity, even though the same circuit is used.
3668 -- This is a bit of an odd case, which introduces a really irregular use
3669 -- of Ada_Version[_Explicit]. Would be nice to find cleaner way to do
3672 Ada_Version
:= Ada_Version_Type
'Max (Ada_Version
, Ada_95
);
3673 Ada_Version_Pragma
:= Empty
;
3674 Ada_Version_Explicit
:= Ada_Version
;
3677 Old_S
:= Find_Renamed_Entity
(N
, Name
(N
), New_S
, Is_Actual
);
3679 -- The visible operation may be an inherited abstract operation that
3680 -- was overridden in the private part, in which case a call will
3681 -- dispatch to the overriding operation. Use the overriding one in
3682 -- the renaming declaration, to prevent spurious errors below.
3684 if Is_Overloadable
(Old_S
)
3685 and then Is_Abstract_Subprogram
(Old_S
)
3686 and then No
(DTC_Entity
(Old_S
))
3687 and then Present
(Alias
(Old_S
))
3688 and then not Is_Abstract_Subprogram
(Alias
(Old_S
))
3689 and then Present
(Overridden_Operation
(Alias
(Old_S
)))
3691 Old_S
:= Alias
(Old_S
);
3694 -- When the renamed subprogram is overloaded and used as an actual
3695 -- of a generic, its entity is set to the first available homonym.
3696 -- We must first disambiguate the name, then set the proper entity.
3698 if Is_Actual
and then Is_Overloaded
(Nam
) then
3699 Set_Entity
(Nam
, Old_S
);
3703 -- Most common case: subprogram renames subprogram. No body is generated
3704 -- in this case, so we must indicate the declaration is complete as is.
3705 -- and inherit various attributes of the renamed subprogram.
3707 if No
(Rename_Spec
) then
3708 Set_Has_Completion
(New_S
);
3709 Set_Is_Imported
(New_S
, Is_Imported
(Entity
(Nam
)));
3710 Set_Is_Pure
(New_S
, Is_Pure
(Entity
(Nam
)));
3711 Set_Is_Preelaborated
(New_S
, Is_Preelaborated
(Entity
(Nam
)));
3713 -- Ada 2005 (AI-423): Check the consistency of null exclusions
3714 -- between a subprogram and its correct renaming.
3716 -- Note: the Any_Id check is a guard that prevents compiler crashes
3717 -- when performing a null exclusion check between a renaming and a
3718 -- renamed subprogram that has been found to be illegal.
3720 if Ada_Version
>= Ada_2005
and then Entity
(Nam
) /= Any_Id
then
3721 Check_Null_Exclusion
3723 Sub
=> Entity
(Nam
));
3726 -- Enforce the Ada 2005 rule that the renamed entity cannot require
3727 -- overriding. The flag Requires_Overriding is set very selectively
3728 -- and misses some other illegal cases. The additional conditions
3729 -- checked below are sufficient but not necessary ???
3731 -- The rule does not apply to the renaming generated for an actual
3732 -- subprogram in an instance.
3737 -- Guard against previous errors, and omit renamings of predefined
3740 elsif Ekind
(Old_S
) not in E_Function | E_Procedure
then
3743 elsif Requires_Overriding
(Old_S
)
3745 (Is_Abstract_Subprogram
(Old_S
)
3746 and then Present
(Find_Dispatching_Type
(Old_S
))
3747 and then not Is_Abstract_Type
(Find_Dispatching_Type
(Old_S
)))
3750 ("renamed entity cannot be subprogram that requires overriding "
3751 & "(RM 8.5.4 (5.1))", N
);
3755 Prev
: constant Entity_Id
:= Overridden_Operation
(New_S
);
3759 (Has_Non_Trivial_Precondition
(Prev
)
3760 or else Has_Non_Trivial_Precondition
(Old_S
))
3763 ("conflicting inherited classwide preconditions in renaming "
3764 & "of& (RM 6.1.1 (17)", N
, Old_S
);
3769 if Old_S
/= Any_Id
then
3770 if Is_Actual
and then From_Default
(N
) then
3772 -- This is an implicit reference to the default actual
3774 Generate_Reference
(Old_S
, Nam
, Typ
=> 'i', Force
=> True);
3777 Generate_Reference
(Old_S
, Nam
);
3780 Check_Internal_Protected_Use
(N
, Old_S
);
3782 -- For a renaming-as-body, require subtype conformance, but if the
3783 -- declaration being completed has not been frozen, then inherit the
3784 -- convention of the renamed subprogram prior to checking conformance
3785 -- (unless the renaming has an explicit convention established; the
3786 -- rule stated in the RM doesn't seem to address this ???).
3788 if Present
(Rename_Spec
) then
3789 Generate_Reference
(Rename_Spec
, Defining_Entity
(Spec
), 'b');
3790 Style
.Check_Identifier
(Defining_Entity
(Spec
), Rename_Spec
);
3792 if not Is_Frozen
(Rename_Spec
) then
3793 if not Has_Convention_Pragma
(Rename_Spec
) then
3794 Set_Convention
(New_S
, Convention
(Old_S
));
3797 if Ekind
(Old_S
) /= E_Operator
then
3798 Check_Mode_Conformant
(New_S
, Old_S
, Spec
);
3801 if Original_Subprogram
(Old_S
) = Rename_Spec
then
3802 Error_Msg_N
("unfrozen subprogram cannot rename itself", N
);
3804 Check_Formal_Subprogram_Conformance
(New_S
, Old_S
, Spec
);
3807 Check_Subtype_Conformant
(New_S
, Old_S
, Spec
);
3810 Check_Frozen_Renaming
(N
, Rename_Spec
);
3812 -- Check explicitly that renamed entity is not intrinsic, because
3813 -- in a generic the renamed body is not built. In this case,
3814 -- the renaming_as_body is a completion.
3816 if Inside_A_Generic
then
3817 if Is_Frozen
(Rename_Spec
)
3818 and then Is_Intrinsic_Subprogram
(Old_S
)
3821 ("subprogram in renaming_as_body cannot be intrinsic",
3825 Set_Has_Completion
(Rename_Spec
);
3828 elsif Ekind
(Old_S
) /= E_Operator
then
3830 -- If this a defaulted subprogram for a class-wide actual there is
3831 -- no check for mode conformance, given that the signatures don't
3832 -- match (the source mentions T but the actual mentions T'Class).
3837 -- No need for a redundant error message if this is a nested
3838 -- instance, unless the current instantiation (of a child unit)
3839 -- is a compilation unit, which is not analyzed when the parent
3840 -- generic is analyzed.
3843 or else No
(Enclosing_Instance
)
3844 or else Is_Compilation_Unit
(Current_Scope
)
3846 Check_Mode_Conformant
(New_S
, Old_S
);
3850 if No
(Rename_Spec
) then
3852 -- The parameter profile of the new entity is that of the renamed
3853 -- entity: the subtypes given in the specification are irrelevant.
3855 Inherit_Renamed_Profile
(New_S
, Old_S
);
3857 -- A call to the subprogram is transformed into a call to the
3858 -- renamed entity. This is transitive if the renamed entity is
3859 -- itself a renaming.
3861 if Present
(Alias
(Old_S
)) then
3862 Set_Alias
(New_S
, Alias
(Old_S
));
3864 Set_Alias
(New_S
, Old_S
);
3867 -- Note that we do not set Is_Intrinsic_Subprogram if we have a
3868 -- renaming as body, since the entity in this case is not an
3869 -- intrinsic (it calls an intrinsic, but we have a real body for
3870 -- this call, and it is in this body that the required intrinsic
3871 -- processing will take place).
3873 -- Also, if this is a renaming of inequality, the renamed operator
3874 -- is intrinsic, but what matters is the corresponding equality
3875 -- operator, which may be user-defined.
3877 Set_Is_Intrinsic_Subprogram
3879 Is_Intrinsic_Subprogram
(Old_S
)
3881 (Chars
(Old_S
) /= Name_Op_Ne
3882 or else Ekind
(Old_S
) = E_Operator
3883 or else Is_Intrinsic_Subprogram
3884 (Corresponding_Equality
(Old_S
))));
3886 if Ekind
(Alias
(New_S
)) = E_Operator
then
3887 Set_Has_Delayed_Freeze
(New_S
, False);
3890 -- If the renaming corresponds to an association for an abstract
3891 -- formal subprogram, then various attributes must be set to
3892 -- indicate that the renaming is an abstract dispatching operation
3893 -- with a controlling type.
3895 -- Skip this decoration when the renaming corresponds to an
3896 -- association with class-wide wrapper (see above) because such
3897 -- wrapper is neither abstract nor a dispatching operation (its
3898 -- body has the dispatching call to the wrapped primitive).
3901 and then Is_Abstract_Subprogram
(Formal_Spec
)
3902 and then No
(Wrapped_Prim
)
3905 -- Mark the renaming as abstract here, so Find_Dispatching_Type
3906 -- see it as corresponding to a generic association for a
3907 -- formal abstract subprogram
3909 Set_Is_Abstract_Subprogram
(New_S
);
3912 New_S_Ctrl_Type
: constant Entity_Id
:=
3913 Find_Dispatching_Type
(New_S
);
3914 Old_S_Ctrl_Type
: constant Entity_Id
:=
3915 Find_Dispatching_Type
(Old_S
);
3919 -- The actual must match the (instance of the) formal,
3920 -- and must be a controlling type.
3922 if Old_S_Ctrl_Type
/= New_S_Ctrl_Type
3923 or else No
(New_S_Ctrl_Type
)
3925 if No
(New_S_Ctrl_Type
) then
3927 ("actual must be dispatching subprogram", Nam
);
3930 ("actual must be dispatching subprogram for type&",
3931 Nam
, New_S_Ctrl_Type
);
3935 Set_Is_Dispatching_Operation
(New_S
);
3936 Check_Controlling_Formals
(New_S_Ctrl_Type
, New_S
);
3938 -- If the actual in the formal subprogram is itself a
3939 -- formal abstract subprogram association, there's no
3940 -- dispatch table component or position to inherit.
3942 if Present
(DTC_Entity
(Old_S
)) then
3943 Set_DTC_Entity
(New_S
, DTC_Entity
(Old_S
));
3944 Set_DT_Position_Value
(New_S
, DT_Position
(Old_S
));
3954 -- The following is illegal, because F hides whatever other F may
3956 -- function F (...) renames F;
3959 or else (Nkind
(Nam
) /= N_Expanded_Name
3960 and then Chars
(Old_S
) = Chars
(New_S
))
3962 Error_Msg_N
("subprogram cannot rename itself", N
);
3964 -- This is illegal even if we use a selector:
3965 -- function F (...) renames Pkg.F;
3966 -- because F is still hidden.
3968 elsif Nkind
(Nam
) = N_Expanded_Name
3969 and then Entity
(Prefix
(Nam
)) = Current_Scope
3970 and then Chars
(Selector_Name
(Nam
)) = Chars
(New_S
)
3972 -- This is an error, but we overlook the error and accept the
3973 -- renaming if the special Overriding_Renamings mode is in effect.
3975 if not Overriding_Renamings
then
3977 ("implicit operation& is not visible (RM 8.3 (15))",
3981 -- Check whether an expanded name used for the renamed subprogram
3982 -- begins with the same name as the renaming itself, and if so,
3983 -- issue an error about the prefix being hidden by the renaming.
3984 -- We exclude generic instances from this checking, since such
3985 -- normally illegal renamings can be constructed when expanding
3988 elsif Nkind
(Nam
) = N_Expanded_Name
and then not In_Instance
then
3990 function Ult_Expanded_Prefix
(N
: Node_Id
) return Node_Id
is
3991 (if Nkind
(N
) /= N_Expanded_Name
3993 else Ult_Expanded_Prefix
(Prefix
(N
)));
3994 -- Returns the ultimate prefix of an expanded name
3997 if Chars
(Entity
(Ult_Expanded_Prefix
(Nam
))) = Chars
(New_S
)
3999 Error_Msg_Sloc
:= Sloc
(N
);
4001 ("& is hidden by declaration#", Nam
, New_S
);
4006 Set_Convention
(New_S
, Convention
(Old_S
));
4008 if Is_Abstract_Subprogram
(Old_S
) then
4009 if Present
(Rename_Spec
) then
4011 ("a renaming-as-body cannot rename an abstract subprogram",
4013 Set_Has_Completion
(Rename_Spec
);
4015 Set_Is_Abstract_Subprogram
(New_S
);
4019 Check_Library_Unit_Renaming
(N
, Old_S
);
4021 -- Pathological case: procedure renames entry in the scope of its
4022 -- task. Entry is given by simple name, but body must be built for
4023 -- procedure. Of course if called it will deadlock.
4025 if Ekind
(Old_S
) = E_Entry
then
4026 Set_Has_Completion
(New_S
, False);
4027 Set_Alias
(New_S
, Empty
);
4030 -- Do not freeze the renaming nor the renamed entity when the context
4031 -- is an enclosing generic. Freezing is an expansion activity, and in
4032 -- addition the renamed entity may depend on the generic formals of
4033 -- the enclosing generic.
4035 if Is_Actual
and not Inside_A_Generic
then
4036 Freeze_Before
(N
, Old_S
);
4037 Freeze_Actual_Profile
;
4038 Set_Has_Delayed_Freeze
(New_S
, False);
4039 Freeze_Before
(N
, New_S
);
4041 if (Ekind
(Old_S
) = E_Procedure
or else Ekind
(Old_S
) = E_Function
)
4042 and then not Is_Abstract_Subprogram
(Formal_Spec
)
4044 -- An abstract subprogram is only allowed as an actual in the
4045 -- case where the formal subprogram is also abstract.
4047 if Is_Abstract_Subprogram
(Old_S
) then
4049 ("abstract subprogram not allowed as generic actual", Nam
);
4052 -- AI12-0412: A primitive of an abstract type with Pre'Class
4053 -- or Post'Class aspects specified with nonstatic expressions
4054 -- is not allowed as actual for a nonabstract formal subprogram
4055 -- (see RM 6.1.1(18.2/5).
4057 if Is_Dispatching_Operation
(Old_S
)
4059 Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post
(Old_S
)
4062 ("primitive of abstract type with nonstatic class-wide "
4063 & "pre/postconditions not allowed as actual",
4070 -- A common error is to assume that implicit operators for types are
4071 -- defined in Standard, or in the scope of a subtype. In those cases
4072 -- where the renamed entity is given with an expanded name, it is
4073 -- worth mentioning that operators for the type are not declared in
4074 -- the scope given by the prefix.
4076 if Nkind
(Nam
) = N_Expanded_Name
4077 and then Nkind
(Selector_Name
(Nam
)) = N_Operator_Symbol
4078 and then Scope
(Entity
(Nam
)) = Standard_Standard
4081 T
: constant Entity_Id
:=
4082 Base_Type
(Etype
(First_Formal
(New_S
)));
4084 Error_Msg_Node_2
:= Prefix
(Nam
);
4086 ("operator for type& is not declared in&", Prefix
(Nam
), T
);
4091 ("no visible subprogram matches the specification for&",
4095 if Present
(Candidate_Renaming
) then
4102 F1
:= First_Formal
(Candidate_Renaming
);
4103 F2
:= First_Formal
(New_S
);
4104 T1
:= First_Subtype
(Etype
(F1
));
4105 while Present
(F1
) and then Present
(F2
) loop
4110 if Present
(F1
) and then Present
(Default_Value
(F1
)) then
4111 if Present
(Next_Formal
(F1
)) then
4113 ("\missing specification for & and other formals with "
4114 & "defaults", Spec
, F1
);
4116 Error_Msg_NE
("\missing specification for &", Spec
, F1
);
4120 if Nkind
(Nam
) = N_Operator_Symbol
4121 and then From_Default
(N
)
4123 Error_Msg_Node_2
:= T1
;
4125 ("default & on & is not directly visible", Nam
, Nam
);
4131 -- Ada 2005 AI 404: if the new subprogram is dispatching, verify that
4132 -- controlling access parameters are known non-null for the renamed
4133 -- subprogram. Test also applies to a subprogram instantiation that
4134 -- is dispatching. Test is skipped if some previous error was detected
4135 -- that set Old_S to Any_Id.
4137 if Ada_Version
>= Ada_2005
4138 and then Old_S
/= Any_Id
4139 and then not Is_Dispatching_Operation
(Old_S
)
4140 and then Is_Dispatching_Operation
(New_S
)
4147 Old_F
:= First_Formal
(Old_S
);
4148 New_F
:= First_Formal
(New_S
);
4149 while Present
(Old_F
) loop
4150 if Ekind
(Etype
(Old_F
)) = E_Anonymous_Access_Type
4151 and then Is_Controlling_Formal
(New_F
)
4152 and then not Can_Never_Be_Null
(Old_F
)
4154 Error_Msg_N
("access parameter is controlling,", New_F
);
4156 ("\corresponding parameter of& must be explicitly null "
4157 & "excluding", New_F
, Old_S
);
4160 Next_Formal
(Old_F
);
4161 Next_Formal
(New_F
);
4166 -- A useful warning, suggested by Ada Bug Finder (Ada-Europe 2005)
4167 -- is to warn if an operator is being renamed as a different operator.
4168 -- If the operator is predefined, examine the kind of the entity, not
4169 -- the abbreviated declaration in Standard.
4171 if Comes_From_Source
(N
)
4172 and then Present
(Old_S
)
4173 and then (Nkind
(Old_S
) = N_Defining_Operator_Symbol
4174 or else Ekind
(Old_S
) = E_Operator
)
4175 and then Nkind
(New_S
) = N_Defining_Operator_Symbol
4176 and then Chars
(Old_S
) /= Chars
(New_S
)
4179 ("& is being renamed as a different operator??", N
, Old_S
);
4182 -- Check for renaming of obsolescent subprogram
4184 Check_Obsolescent_2005_Entity
(Entity
(Nam
), Nam
);
4186 -- Another warning or some utility: if the new subprogram as the same
4187 -- name as the old one, the old one is not hidden by an outer homograph,
4188 -- the new one is not a public symbol, and the old one is otherwise
4189 -- directly visible, the renaming is superfluous.
4191 if Chars
(Old_S
) = Chars
(New_S
)
4192 and then Comes_From_Source
(N
)
4193 and then Scope
(Old_S
) /= Standard_Standard
4194 and then Warn_On_Redundant_Constructs
4195 and then (Is_Immediately_Visible
(Old_S
)
4196 or else Is_Potentially_Use_Visible
(Old_S
))
4197 and then Is_Overloadable
(Current_Scope
)
4198 and then Chars
(Current_Scope
) /= Chars
(Old_S
)
4201 ("redundant renaming, entity is directly visible?r?", Name
(N
));
4204 -- Implementation-defined aspect specifications can appear in a renaming
4205 -- declaration, but not language-defined ones. The call to procedure
4206 -- Analyze_Aspect_Specifications will take care of this error check.
4208 if Has_Aspects
(N
) then
4209 Analyze_Aspect_Specifications
(N
, New_S
);
4215 and then Has_Yield_Aspect
(Formal_Spec
)
4216 and then not Has_Yield_Aspect
(Old_S
)
4218 Error_Msg_Name_1
:= Name_Yield
;
4220 ("actual subprogram& must have aspect% to match formal", Name
(N
));
4223 Ada_Version
:= Save_AV
;
4224 Ada_Version_Pragma
:= Save_AVP
;
4225 Ada_Version_Explicit
:= Save_AV_Exp
;
4227 -- Check if we are looking at an Ada 2012 defaulted formal subprogram
4228 -- and mark any use_package_clauses that affect the visibility of the
4229 -- implicit generic actual.
4231 -- Also, we may be looking at an internal renaming of a user-defined
4232 -- subprogram created for a generic formal subprogram association,
4233 -- which will also have to be marked here. This can occur when the
4234 -- corresponding formal subprogram contains references to other generic
4237 if Is_Generic_Actual_Subprogram
(New_S
)
4238 and then (Is_Intrinsic_Subprogram
(New_S
)
4239 or else From_Default
(N
)
4240 or else Nkind
(N
) = N_Subprogram_Renaming_Declaration
)
4242 Mark_Use_Clauses
(New_S
);
4244 -- Handle overloaded subprograms
4246 if Present
(Alias
(New_S
)) then
4247 Mark_Use_Clauses
(Alias
(New_S
));
4250 end Analyze_Subprogram_Renaming
;
4252 -------------------------
4253 -- Analyze_Use_Package --
4254 -------------------------
4256 -- Resolve the package names in the use clause, and make all the visible
4257 -- entities defined in the package potentially use-visible. If the package
4258 -- is already in use from a previous use clause, its visible entities are
4259 -- already use-visible. In that case, mark the occurrence as a redundant
4260 -- use. If the package is an open scope, i.e. if the use clause occurs
4261 -- within the package itself, ignore it.
4263 procedure Analyze_Use_Package
(N
: Node_Id
; Chain
: Boolean := True) is
4264 procedure Analyze_Package_Name
(Clause
: Node_Id
);
4265 -- Perform analysis on a package name from a use_package_clause
4267 procedure Analyze_Package_Name_List
(Head_Clause
: Node_Id
);
4268 -- Similar to Analyze_Package_Name but iterates over all the names
4271 --------------------------
4272 -- Analyze_Package_Name --
4273 --------------------------
4275 procedure Analyze_Package_Name
(Clause
: Node_Id
) is
4276 Pack
: constant Node_Id
:= Name
(Clause
);
4280 pragma Assert
(Nkind
(Clause
) = N_Use_Package_Clause
);
4283 -- Verify that the package standard is not directly named in a
4284 -- use_package_clause.
4286 if Nkind
(Parent
(Clause
)) = N_Compilation_Unit
4287 and then Nkind
(Pack
) = N_Expanded_Name
4289 Pref
:= Prefix
(Pack
);
4291 while Nkind
(Pref
) = N_Expanded_Name
loop
4292 Pref
:= Prefix
(Pref
);
4295 if Entity
(Pref
) = Standard_Standard
then
4297 ("predefined package Standard cannot appear in a context "
4301 end Analyze_Package_Name
;
4303 -------------------------------
4304 -- Analyze_Package_Name_List --
4305 -------------------------------
4307 procedure Analyze_Package_Name_List
(Head_Clause
: Node_Id
) is
4311 -- Due to the way source use clauses are split during parsing we are
4312 -- forced to simply iterate through all entities in scope until the
4313 -- clause representing the last name in the list is found.
4315 Curr
:= Head_Clause
;
4316 while Present
(Curr
) loop
4317 Analyze_Package_Name
(Curr
);
4319 -- Stop iterating over the names in the use clause when we are at
4322 exit when not More_Ids
(Curr
) and then Prev_Ids
(Curr
);
4325 end Analyze_Package_Name_List
;
4331 -- Start of processing for Analyze_Use_Package
4334 Set_Hidden_By_Use_Clause
(N
, No_Elist
);
4336 -- Use clause not allowed in a spec of a predefined package declaration
4337 -- except that packages whose file name starts a-n are OK (these are
4338 -- children of Ada.Numerics, which are never loaded by Rtsfind).
4340 if Is_Predefined_Unit
(Current_Sem_Unit
)
4341 and then Get_Name_String
4342 (Unit_File_Name
(Current_Sem_Unit
)) (1 .. 3) /= "a-n"
4343 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
4344 N_Package_Declaration
4346 Error_Msg_N
("use clause not allowed in predefined spec", N
);
4349 -- Loop through all package names from the original use clause in
4350 -- order to analyze referenced packages. A use_package_clause with only
4351 -- one name does not have More_Ids or Prev_Ids set, while a clause with
4352 -- More_Ids only starts the chain produced by the parser.
4354 if not More_Ids
(N
) and then not Prev_Ids
(N
) then
4355 Analyze_Package_Name
(N
);
4357 elsif More_Ids
(N
) and then not Prev_Ids
(N
) then
4358 Analyze_Package_Name_List
(N
);
4361 if not Is_Entity_Name
(Name
(N
)) then
4362 Error_Msg_N
("& is not a package", Name
(N
));
4368 Chain_Use_Clause
(N
);
4371 Pack
:= Entity
(Name
(N
));
4373 -- There are many cases where scopes are manipulated during analysis, so
4374 -- check that Pack's current use clause has not already been chained
4375 -- before setting its previous use clause.
4377 if Ekind
(Pack
) = E_Package
4378 and then Present
(Current_Use_Clause
(Pack
))
4379 and then Current_Use_Clause
(Pack
) /= N
4380 and then No
(Prev_Use_Clause
(N
))
4381 and then Prev_Use_Clause
(Current_Use_Clause
(Pack
)) /= N
4383 Set_Prev_Use_Clause
(N
, Current_Use_Clause
(Pack
));
4386 -- Mark all entities as potentially use visible
4388 if Ekind
(Pack
) /= E_Package
and then Etype
(Pack
) /= Any_Type
then
4389 if Ekind
(Pack
) = E_Generic_Package
then
4390 Error_Msg_N
-- CODEFIX
4391 ("a generic package is not allowed in a use clause", Name
(N
));
4393 elsif Is_Generic_Subprogram
(Pack
) then
4394 Error_Msg_N
-- CODEFIX
4395 ("a generic subprogram is not allowed in a use clause",
4398 elsif Is_Subprogram
(Pack
) then
4399 Error_Msg_N
-- CODEFIX
4400 ("a subprogram is not allowed in a use clause", Name
(N
));
4403 Error_Msg_N
("& is not allowed in a use clause", Name
(N
));
4407 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
4408 Check_In_Previous_With_Clause
(N
, Name
(N
));
4411 Use_One_Package
(N
, Name
(N
));
4414 Mark_Ghost_Clause
(N
);
4415 end Analyze_Use_Package
;
4417 ----------------------
4418 -- Analyze_Use_Type --
4419 ----------------------
4421 procedure Analyze_Use_Type
(N
: Node_Id
; Chain
: Boolean := True) is
4426 Set_Hidden_By_Use_Clause
(N
, No_Elist
);
4428 -- Chain clause to list of use clauses in current scope when flagged
4431 Chain_Use_Clause
(N
);
4434 -- Obtain the base type of the type denoted within the use_type_clause's
4437 Id
:= Subtype_Mark
(N
);
4439 E
:= Base_Type
(Entity
(Id
));
4441 -- There are many cases where a use_type_clause may be reanalyzed due to
4442 -- manipulation of the scope stack so we much guard against those cases
4443 -- here, otherwise, we must add the new use_type_clause to the previous
4444 -- use_type_clause chain in order to mark redundant use_type_clauses as
4445 -- used. When the redundant use-type clauses appear in a parent unit and
4446 -- a child unit we must prevent a circularity in the chain that would
4447 -- otherwise result from the separate steps of analysis and installation
4448 -- of the parent context.
4450 if Present
(Current_Use_Clause
(E
))
4451 and then Current_Use_Clause
(E
) /= N
4452 and then Prev_Use_Clause
(Current_Use_Clause
(E
)) /= N
4453 and then No
(Prev_Use_Clause
(N
))
4455 Set_Prev_Use_Clause
(N
, Current_Use_Clause
(E
));
4458 -- If the Used_Operations list is already initialized, the clause has
4459 -- been analyzed previously, and it is being reinstalled, for example
4460 -- when the clause appears in a package spec and we are compiling the
4461 -- corresponding package body. In that case, make the entities on the
4462 -- existing list use_visible, and mark the corresponding types In_Use.
4464 if Present
(Used_Operations
(N
)) then
4469 Use_One_Type
(Subtype_Mark
(N
), Installed
=> True);
4471 Elmt
:= First_Elmt
(Used_Operations
(N
));
4472 while Present
(Elmt
) loop
4473 Set_Is_Potentially_Use_Visible
(Node
(Elmt
));
4481 -- Otherwise, create new list and attach to it the operations that are
4482 -- made use-visible by the clause.
4484 Set_Used_Operations
(N
, New_Elmt_List
);
4487 if E
/= Any_Type
then
4490 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
4491 if Nkind
(Id
) = N_Identifier
then
4492 Error_Msg_N
("type is not directly visible", Id
);
4494 elsif Is_Child_Unit
(Scope
(E
))
4495 and then Scope
(E
) /= System_Aux_Id
4497 Check_In_Previous_With_Clause
(N
, Prefix
(Id
));
4502 -- If the use_type_clause appears in a compilation unit context,
4503 -- check whether it comes from a unit that may appear in a
4504 -- limited_with_clause, for a better error message.
4506 if Nkind
(Parent
(N
)) = N_Compilation_Unit
4507 and then Nkind
(Id
) /= N_Identifier
4513 function Mentioned
(Nam
: Node_Id
) return Boolean;
4514 -- Check whether the prefix of expanded name for the type
4515 -- appears in the prefix of some limited_with_clause.
4521 function Mentioned
(Nam
: Node_Id
) return Boolean is
4523 return Nkind
(Name
(Item
)) = N_Selected_Component
4524 and then Chars
(Prefix
(Name
(Item
))) = Chars
(Nam
);
4528 Pref
:= Prefix
(Id
);
4529 Item
:= First
(Context_Items
(Parent
(N
)));
4530 while Present
(Item
) and then Item
/= N
loop
4531 if Nkind
(Item
) = N_With_Clause
4532 and then Limited_Present
(Item
)
4533 and then Mentioned
(Pref
)
4536 (Get_Msg_Id
, "premature usage of incomplete type");
4545 Mark_Ghost_Clause
(N
);
4546 end Analyze_Use_Type
;
4548 ------------------------
4549 -- Attribute_Renaming --
4550 ------------------------
4552 procedure Attribute_Renaming
(N
: Node_Id
) is
4553 Loc
: constant Source_Ptr
:= Sloc
(N
);
4554 Nam
: constant Node_Id
:= Name
(N
);
4555 Spec
: constant Node_Id
:= Specification
(N
);
4556 New_S
: constant Entity_Id
:= Defining_Unit_Name
(Spec
);
4557 Aname
: constant Name_Id
:= Attribute_Name
(Nam
);
4559 Form_Num
: Nat
:= 0;
4560 Expr_List
: List_Id
:= No_List
;
4562 Attr_Node
: Node_Id
;
4563 Body_Node
: Node_Id
;
4564 Param_Spec
: Node_Id
;
4567 Generate_Definition
(New_S
);
4569 -- This procedure is called in the context of subprogram renaming, and
4570 -- thus the attribute must be one that is a subprogram. All of those
4571 -- have at least one formal parameter, with the exceptions of the GNAT
4572 -- attribute 'Img, which GNAT treats as renameable.
4574 if Is_Empty_List
(Parameter_Specifications
(Spec
)) then
4575 if Aname
/= Name_Img
then
4577 ("subprogram renaming an attribute must have formals", N
);
4582 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
4583 while Present
(Param_Spec
) loop
4584 Form_Num
:= Form_Num
+ 1;
4586 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
4587 Find_Type
(Parameter_Type
(Param_Spec
));
4589 -- The profile of the new entity denotes the base type (s) of
4590 -- the types given in the specification. For access parameters
4591 -- there are no subtypes involved.
4593 Rewrite
(Parameter_Type
(Param_Spec
),
4595 (Base_Type
(Entity
(Parameter_Type
(Param_Spec
))), Loc
));
4598 if No
(Expr_List
) then
4599 Expr_List
:= New_List
;
4602 Append_To
(Expr_List
,
4603 Make_Identifier
(Loc
,
4604 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
4606 -- The expressions in the attribute reference are not freeze
4607 -- points. Neither is the attribute as a whole, see below.
4609 Set_Must_Not_Freeze
(Last
(Expr_List
));
4614 -- Immediate error if too many formals. Other mismatches in number or
4615 -- types of parameters are detected when we analyze the body of the
4616 -- subprogram that we construct.
4618 if Form_Num
> 2 then
4619 Error_Msg_N
("too many formals for attribute", N
);
4621 -- Error if the attribute reference has expressions that look like
4622 -- formal parameters.
4624 elsif Present
(Expressions
(Nam
)) then
4625 Error_Msg_N
("illegal expressions in attribute reference", Nam
);
4627 elsif Aname
in Name_Compose | Name_Exponent | Name_Leading_Part |
4628 Name_Pos | Name_Round | Name_Scaling |
4631 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
4632 and then Present
(Corresponding_Formal_Spec
(N
))
4635 ("generic actual cannot be attribute involving universal type",
4639 ("attribute involving a universal type cannot be renamed",
4644 -- Rewrite attribute node to have a list of expressions corresponding to
4645 -- the subprogram formals. A renaming declaration is not a freeze point,
4646 -- and the analysis of the attribute reference should not freeze the
4647 -- type of the prefix. We use the original node in the renaming so that
4648 -- its source location is preserved, and checks on stream attributes are
4649 -- properly applied.
4651 Attr_Node
:= Relocate_Node
(Nam
);
4652 Set_Expressions
(Attr_Node
, Expr_List
);
4654 Set_Must_Not_Freeze
(Attr_Node
);
4655 Set_Must_Not_Freeze
(Prefix
(Nam
));
4657 -- Case of renaming a function
4659 if Nkind
(Spec
) = N_Function_Specification
then
4660 if Is_Procedure_Attribute_Name
(Aname
) then
4661 Error_Msg_N
("attribute can only be renamed as procedure", Nam
);
4665 Find_Type
(Result_Definition
(Spec
));
4666 Rewrite
(Result_Definition
(Spec
),
4668 (Base_Type
(Entity
(Result_Definition
(Spec
))), Loc
));
4671 Make_Subprogram_Body
(Loc
,
4672 Specification
=> Spec
,
4673 Declarations
=> New_List
,
4674 Handled_Statement_Sequence
=>
4675 Make_Handled_Sequence_Of_Statements
(Loc
,
4676 Statements
=> New_List
(
4677 Make_Simple_Return_Statement
(Loc
,
4678 Expression
=> Attr_Node
))));
4680 -- Case of renaming a procedure
4683 if not Is_Procedure_Attribute_Name
(Aname
) then
4684 Error_Msg_N
("attribute can only be renamed as function", Nam
);
4689 Make_Subprogram_Body
(Loc
,
4690 Specification
=> Spec
,
4691 Declarations
=> New_List
,
4692 Handled_Statement_Sequence
=>
4693 Make_Handled_Sequence_Of_Statements
(Loc
,
4694 Statements
=> New_List
(Attr_Node
)));
4697 -- Signal the ABE mechanism that the generated subprogram body has not
4698 -- ABE ramifications.
4700 Set_Was_Attribute_Reference
(Body_Node
);
4702 -- In case of tagged types we add the body of the generated function to
4703 -- the freezing actions of the type (because in the general case such
4704 -- type is still not frozen). We exclude from this processing generic
4705 -- formal subprograms found in instantiations.
4707 -- We must exclude restricted run-time libraries because
4708 -- entity AST_Handler is defined in package System.Aux_Dec which is not
4709 -- available in those platforms. Note that we cannot use the function
4710 -- Restricted_Profile (instead of Configurable_Run_Time_Mode) because
4711 -- the ZFP run-time library is not defined as a profile, and we do not
4712 -- want to deal with AST_Handler in ZFP mode.
4714 if not Configurable_Run_Time_Mode
4715 and then No
(Corresponding_Formal_Spec
(N
))
4716 and then not Is_RTE
(Etype
(Nam
), RE_AST_Handler
)
4719 P
: constant Node_Id
:= Prefix
(Nam
);
4722 -- The prefix of 'Img is an object that is evaluated for each call
4723 -- of the function that renames it.
4725 if Aname
= Name_Img
then
4726 Preanalyze_And_Resolve
(P
);
4728 -- For all other attribute renamings, the prefix is a subtype
4734 -- If the target type is not yet frozen, add the body to the
4735 -- actions to be elaborated at freeze time.
4737 if Is_Tagged_Type
(Etype
(P
))
4738 and then In_Open_Scopes
(Scope
(Etype
(P
)))
4740 Append_Freeze_Action
(Etype
(P
), Body_Node
);
4742 Rewrite
(N
, Body_Node
);
4744 Set_Etype
(New_S
, Base_Type
(Etype
(New_S
)));
4748 -- Generic formal subprograms or AST_Handler renaming
4751 Rewrite
(N
, Body_Node
);
4753 Set_Etype
(New_S
, Base_Type
(Etype
(New_S
)));
4756 if Is_Compilation_Unit
(New_S
) then
4758 ("a library unit can only rename another library unit", N
);
4761 -- We suppress elaboration warnings for the resulting entity, since
4762 -- clearly they are not needed, and more particularly, in the case
4763 -- of a generic formal subprogram, the resulting entity can appear
4764 -- after the instantiation itself, and thus look like a bogus case
4765 -- of access before elaboration.
4767 if Legacy_Elaboration_Checks
then
4768 Set_Suppress_Elaboration_Warnings
(New_S
);
4770 end Attribute_Renaming
;
4772 ----------------------
4773 -- Chain_Use_Clause --
4774 ----------------------
4776 procedure Chain_Use_Clause
(N
: Node_Id
) is
4777 Level
: Int
:= Scope_Stack
.Last
;
4783 if not Is_Compilation_Unit
(Current_Scope
)
4784 or else not Is_Child_Unit
(Current_Scope
)
4788 -- Common case for compilation unit
4790 elsif Defining_Entity
(Parent
(N
)) = Current_Scope
then
4794 -- If declaration appears in some other scope, it must be in some
4795 -- parent unit when compiling a child.
4797 Pack
:= Defining_Entity
(Parent
(N
));
4799 if not In_Open_Scopes
(Pack
) then
4802 -- If the use clause appears in an ancestor and we are in the
4803 -- private part of the immediate parent, the use clauses are
4804 -- already installed.
4806 elsif Pack
/= Scope
(Current_Scope
)
4807 and then In_Private_Part
(Scope
(Current_Scope
))
4812 -- Find entry for parent unit in scope stack
4814 while Scope_Stack
.Table
(Level
).Entity
/= Pack
loop
4820 Set_Next_Use_Clause
(N
,
4821 Scope_Stack
.Table
(Level
).First_Use_Clause
);
4822 Scope_Stack
.Table
(Level
).First_Use_Clause
:= N
;
4823 end Chain_Use_Clause
;
4825 ---------------------------
4826 -- Check_Frozen_Renaming --
4827 ---------------------------
4829 procedure Check_Frozen_Renaming
(N
: Node_Id
; Subp
: Entity_Id
) is
4834 if Is_Frozen
(Subp
) and then not Has_Completion
(Subp
) then
4837 (Parent
(Declaration_Node
(Subp
)), Defining_Entity
(N
));
4839 if Is_Entity_Name
(Name
(N
)) then
4840 Old_S
:= Entity
(Name
(N
));
4842 if not Is_Frozen
(Old_S
)
4843 and then Operating_Mode
/= Check_Semantics
4845 Append_Freeze_Action
(Old_S
, B_Node
);
4847 Insert_After
(N
, B_Node
);
4851 if Is_Intrinsic_Subprogram
(Old_S
)
4852 and then not In_Instance
4853 and then not Relaxed_RM_Semantics
4856 ("subprogram used in renaming_as_body cannot be intrinsic",
4861 Insert_After
(N
, B_Node
);
4865 end Check_Frozen_Renaming
;
4867 -------------------------------
4868 -- Set_Entity_Or_Discriminal --
4869 -------------------------------
4871 procedure Set_Entity_Or_Discriminal
(N
: Node_Id
; E
: Entity_Id
) is
4875 -- If the entity is not a discriminant, or else expansion is disabled,
4876 -- simply set the entity.
4878 if not In_Spec_Expression
4879 or else Ekind
(E
) /= E_Discriminant
4880 or else Inside_A_Generic
4882 Set_Entity_With_Checks
(N
, E
);
4884 -- The replacement of a discriminant by the corresponding discriminal
4885 -- is not done for a task discriminant that appears in a default
4886 -- expression of an entry parameter. See Exp_Ch2.Expand_Discriminant
4887 -- for details on their handling.
4889 elsif Is_Concurrent_Type
(Scope
(E
)) then
4892 and then Nkind
(P
) not in
4893 N_Parameter_Specification | N_Component_Declaration
4899 and then Nkind
(P
) = N_Parameter_Specification
4903 -- Don't replace a non-qualified discriminant in strict preanalysis
4904 -- mode since it can lead to errors during full analysis when the
4905 -- discriminant gets referenced later.
4907 -- This can occur in situations where a protected type contains
4908 -- an expression function which references a non-prefixed
4912 and then Preanalysis_Active
4913 and then Inside_Preanalysis_Without_Freezing
= 0
4918 Set_Entity
(N
, Discriminal
(E
));
4921 -- Otherwise, this is a discriminant in a context in which
4922 -- it is a reference to the corresponding parameter of the
4923 -- init proc for the enclosing type.
4926 Set_Entity
(N
, Discriminal
(E
));
4928 end Set_Entity_Or_Discriminal
;
4930 -----------------------------------
4931 -- Check_In_Previous_With_Clause --
4932 -----------------------------------
4934 procedure Check_In_Previous_With_Clause
(N
, Nam
: Node_Id
) is
4935 Pack
: constant Entity_Id
:= Entity
(Original_Node
(Nam
));
4940 Item
:= First
(Context_Items
(Parent
(N
)));
4941 while Present
(Item
) and then Item
/= N
loop
4942 if Nkind
(Item
) = N_With_Clause
4944 -- Protect the frontend against previous critical errors
4946 and then Nkind
(Name
(Item
)) /= N_Selected_Component
4947 and then Entity
(Name
(Item
)) = Pack
4951 -- Find root library unit in with_clause
4953 while Nkind
(Par
) = N_Expanded_Name
loop
4954 Par
:= Prefix
(Par
);
4957 if Is_Child_Unit
(Entity
(Original_Node
(Par
))) then
4958 Error_Msg_NE
("& is not directly visible", Par
, Entity
(Par
));
4967 -- On exit, package is not mentioned in a previous with_clause.
4968 -- Check if its prefix is.
4970 if Nkind
(Nam
) = N_Expanded_Name
then
4971 Check_In_Previous_With_Clause
(N
, Prefix
(Nam
));
4973 elsif Pack
/= Any_Id
then
4974 Error_Msg_NE
("& is not visible", Nam
, Pack
);
4976 end Check_In_Previous_With_Clause
;
4978 ---------------------------------
4979 -- Check_Library_Unit_Renaming --
4980 ---------------------------------
4982 procedure Check_Library_Unit_Renaming
(N
: Node_Id
; Old_E
: Entity_Id
) is
4986 if Nkind
(Parent
(N
)) /= N_Compilation_Unit
then
4989 -- Check for library unit. Note that we used to check for the scope
4990 -- being Standard here, but that was wrong for Standard itself.
4992 elsif not Is_Compilation_Unit
(Old_E
)
4993 and then not Is_Child_Unit
(Old_E
)
4995 Error_Msg_N
("renamed unit must be a library unit", Name
(N
));
4997 -- Entities defined in Standard (operators and boolean literals) cannot
4998 -- be renamed as library units.
5000 elsif Scope
(Old_E
) = Standard_Standard
5001 and then Sloc
(Old_E
) = Standard_Location
5003 Error_Msg_N
("renamed unit must be a library unit", Name
(N
));
5005 elsif Present
(Parent_Spec
(N
))
5006 and then Nkind
(Unit
(Parent_Spec
(N
))) = N_Generic_Package_Declaration
5007 and then not Is_Child_Unit
(Old_E
)
5010 ("renamed unit must be a child unit of generic parent", Name
(N
));
5012 elsif Nkind
(N
) in N_Generic_Renaming_Declaration
5013 and then Nkind
(Name
(N
)) = N_Expanded_Name
5014 and then Is_Generic_Instance
(Entity
(Prefix
(Name
(N
))))
5015 and then Is_Generic_Unit
(Old_E
)
5018 ("renamed generic unit must be a library unit", Name
(N
));
5020 elsif Is_Package_Or_Generic_Package
(Old_E
) then
5022 -- Inherit categorization flags
5024 New_E
:= Defining_Entity
(N
);
5025 Set_Is_Pure
(New_E
, Is_Pure
(Old_E
));
5026 Set_Is_Preelaborated
(New_E
, Is_Preelaborated
(Old_E
));
5027 Set_Is_Remote_Call_Interface
(New_E
,
5028 Is_Remote_Call_Interface
(Old_E
));
5029 Set_Is_Remote_Types
(New_E
, Is_Remote_Types
(Old_E
));
5030 Set_Is_Shared_Passive
(New_E
, Is_Shared_Passive
(Old_E
));
5032 end Check_Library_Unit_Renaming
;
5034 ------------------------
5035 -- Enclosing_Instance --
5036 ------------------------
5038 function Enclosing_Instance
return Entity_Id
is
5042 if not Is_Generic_Instance
(Current_Scope
) then
5046 S
:= Scope
(Current_Scope
);
5047 while S
/= Standard_Standard
loop
5048 if Is_Generic_Instance
(S
) then
5056 end Enclosing_Instance
;
5062 procedure End_Scope
is
5068 Id
:= First_Entity
(Current_Scope
);
5069 while Present
(Id
) loop
5070 -- An entity in the current scope is not necessarily the first one
5071 -- on its homonym chain. Find its predecessor if any,
5072 -- If it is an internal entity, it will not be in the visibility
5073 -- chain altogether, and there is nothing to unchain.
5075 if Id
/= Current_Entity
(Id
) then
5076 Prev
:= Current_Entity
(Id
);
5077 while Present
(Prev
)
5078 and then Homonym
(Prev
) /= Id
5080 Prev
:= Homonym
(Prev
);
5083 -- Skip to end of loop if Id is not in the visibility chain
5093 Set_Is_Immediately_Visible
(Id
, False);
5095 Outer
:= Homonym
(Id
);
5096 while Present
(Outer
) and then Scope
(Outer
) = Current_Scope
loop
5097 Outer
:= Homonym
(Outer
);
5100 -- Reset homonym link of other entities, but do not modify link
5101 -- between entities in current scope, so that the back-end can have
5102 -- a proper count of local overloadings.
5105 Set_Name_Entity_Id
(Chars
(Id
), Outer
);
5107 elsif Scope
(Prev
) /= Scope
(Id
) then
5108 Set_Homonym
(Prev
, Outer
);
5115 -- If the scope generated freeze actions, place them before the
5116 -- current declaration and analyze them. Type declarations and
5117 -- the bodies of initialization procedures can generate such nodes.
5118 -- We follow the parent chain until we reach a list node, which is
5119 -- the enclosing list of declarations. If the list appears within
5120 -- a protected definition, move freeze nodes outside the protected
5124 (Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
)
5128 L
: constant List_Id
:= Scope_Stack
.Table
5129 (Scope_Stack
.Last
).Pending_Freeze_Actions
;
5132 if Is_Itype
(Current_Scope
) then
5133 Decl
:= Associated_Node_For_Itype
(Current_Scope
);
5135 Decl
:= Parent
(Current_Scope
);
5140 while not Is_List_Member
(Decl
)
5141 or else Nkind
(Parent
(Decl
)) in N_Protected_Definition
5144 Decl
:= Parent
(Decl
);
5147 Insert_List_Before_And_Analyze
(Decl
, L
);
5155 ---------------------
5156 -- End_Use_Clauses --
5157 ---------------------
5159 procedure End_Use_Clauses
(Clause
: Node_Id
) is
5163 -- Remove use_type_clauses first, because they affect the visibility of
5164 -- operators in subsequent used packages.
5167 while Present
(U
) loop
5168 if Nkind
(U
) = N_Use_Type_Clause
then
5172 Next_Use_Clause
(U
);
5176 while Present
(U
) loop
5177 if Nkind
(U
) = N_Use_Package_Clause
then
5178 End_Use_Package
(U
);
5181 Next_Use_Clause
(U
);
5183 end End_Use_Clauses
;
5185 ---------------------
5186 -- End_Use_Package --
5187 ---------------------
5189 procedure End_Use_Package
(N
: Node_Id
) is
5191 Pack_Name
: Node_Id
;
5195 function Is_Primitive_Operator_In_Use
5197 F
: Entity_Id
) return Boolean;
5198 -- Check whether Op is a primitive operator of a use-visible type
5200 ----------------------------------
5201 -- Is_Primitive_Operator_In_Use --
5202 ----------------------------------
5204 function Is_Primitive_Operator_In_Use
5206 F
: Entity_Id
) return Boolean
5208 T
: constant Entity_Id
:= Base_Type
(Etype
(F
));
5210 return In_Use
(T
) and then Scope
(T
) = Scope
(Op
);
5211 end Is_Primitive_Operator_In_Use
;
5213 -- Start of processing for End_Use_Package
5216 Pack_Name
:= Name
(N
);
5218 -- Test that Pack_Name actually denotes a package before processing
5220 if Is_Entity_Name
(Pack_Name
)
5221 and then Ekind
(Entity
(Pack_Name
)) = E_Package
5223 Pack
:= Entity
(Pack_Name
);
5225 if In_Open_Scopes
(Pack
) then
5228 elsif not Redundant_Use
(Pack_Name
) then
5229 Set_In_Use
(Pack
, False);
5230 Set_Current_Use_Clause
(Pack
, Empty
);
5232 Id
:= First_Entity
(Pack
);
5233 while Present
(Id
) loop
5235 -- Preserve use-visibility of operators that are primitive
5236 -- operators of a type that is use-visible through an active
5239 if Nkind
(Id
) = N_Defining_Operator_Symbol
5241 (Is_Primitive_Operator_In_Use
(Id
, First_Formal
(Id
))
5243 (Present
(Next_Formal
(First_Formal
(Id
)))
5245 Is_Primitive_Operator_In_Use
5246 (Id
, Next_Formal
(First_Formal
(Id
)))))
5250 Set_Is_Potentially_Use_Visible
(Id
, False);
5253 if Is_Private_Type
(Id
)
5254 and then Present
(Full_View
(Id
))
5256 Set_Is_Potentially_Use_Visible
(Full_View
(Id
), False);
5262 if Present
(Renamed_Entity
(Pack
)) then
5263 Set_In_Use
(Renamed_Entity
(Pack
), False);
5264 Set_Current_Use_Clause
(Renamed_Entity
(Pack
), Empty
);
5267 if Chars
(Pack
) = Name_System
5268 and then Scope
(Pack
) = Standard_Standard
5269 and then Present_System_Aux
5271 Id
:= First_Entity
(System_Aux_Id
);
5272 while Present
(Id
) loop
5273 Set_Is_Potentially_Use_Visible
(Id
, False);
5275 if Is_Private_Type
(Id
)
5276 and then Present
(Full_View
(Id
))
5278 Set_Is_Potentially_Use_Visible
(Full_View
(Id
), False);
5284 Set_In_Use
(System_Aux_Id
, False);
5287 Set_Redundant_Use
(Pack_Name
, False);
5291 if Present
(Hidden_By_Use_Clause
(N
)) then
5292 Elmt
:= First_Elmt
(Hidden_By_Use_Clause
(N
));
5293 while Present
(Elmt
) loop
5295 E
: constant Entity_Id
:= Node
(Elmt
);
5298 -- Reset either Use_Visibility or Direct_Visibility, depending
5299 -- on how the entity was hidden by the use clause.
5301 if In_Use
(Scope
(E
))
5302 and then Used_As_Generic_Actual
(Scope
(E
))
5304 Set_Is_Potentially_Use_Visible
(Node
(Elmt
));
5306 Set_Is_Immediately_Visible
(Node
(Elmt
));
5313 Set_Hidden_By_Use_Clause
(N
, No_Elist
);
5315 end End_Use_Package
;
5321 procedure End_Use_Type
(N
: Node_Id
) is
5326 -- Start of processing for End_Use_Type
5329 Id
:= Subtype_Mark
(N
);
5331 -- A call to Rtsfind may occur while analyzing a use_type_clause, in
5332 -- which case the type marks are not resolved yet, so guard against that
5335 if Is_Entity_Name
(Id
) and then Present
(Entity
(Id
)) then
5338 if T
= Any_Type
or else From_Limited_With
(T
) then
5341 -- Note that the use_type_clause may mention a subtype of the type
5342 -- whose primitive operations have been made visible. Here as
5343 -- elsewhere, it is the base type that matters for visibility.
5345 elsif In_Open_Scopes
(Scope
(Base_Type
(T
))) then
5348 elsif not Redundant_Use
(Id
) then
5349 Set_In_Use
(T
, False);
5350 Set_In_Use
(Base_Type
(T
), False);
5351 Set_Current_Use_Clause
(T
, Empty
);
5352 Set_Current_Use_Clause
(Base_Type
(T
), Empty
);
5354 -- See Use_One_Type for the rationale. This is a bit on the naive
5355 -- side, but should be good enough in practice.
5357 if Is_Tagged_Type
(T
) then
5358 Set_In_Use
(Class_Wide_Type
(T
), False);
5363 if Is_Empty_Elmt_List
(Used_Operations
(N
)) then
5367 Elmt
:= First_Elmt
(Used_Operations
(N
));
5368 while Present
(Elmt
) loop
5369 Set_Is_Potentially_Use_Visible
(Node
(Elmt
), False);
5375 --------------------
5376 -- Entity_Of_Unit --
5377 --------------------
5379 function Entity_Of_Unit
(U
: Node_Id
) return Entity_Id
is
5381 if Nkind
(U
) = N_Package_Instantiation
and then Analyzed
(U
) then
5382 return Defining_Entity
(Instance_Spec
(U
));
5384 return Defining_Entity
(U
);
5388 --------------------------------------
5389 -- Error_Missing_With_Of_Known_Unit --
5390 --------------------------------------
5392 procedure Error_Missing_With_Of_Known_Unit
(Pkg
: Node_Id
) is
5393 Selectors
: array (1 .. 6) of Node_Id
;
5394 -- Contains the chars of the full package name up to maximum number
5395 -- allowed as per Errout.Error_Msg_Name_# variables.
5397 Count
: Integer := Selectors
'First;
5398 -- Count of selector names forming the full package name
5400 Current_Pkg
: Node_Id
:= Parent
(Pkg
);
5403 Selectors
(Count
) := Pkg
;
5405 -- Gather all the selectors we can display
5407 while Nkind
(Current_Pkg
) = N_Selected_Component
5408 and then Is_Known_Unit
(Current_Pkg
)
5409 and then Count
< Selectors
'Length
5412 Selectors
(Count
) := Selector_Name
(Current_Pkg
);
5413 Current_Pkg
:= Parent
(Current_Pkg
);
5416 -- Display the error message based on the number of selectors found
5420 Error_Msg_Node_1
:= Selectors
(1);
5421 Error_Msg_N
-- CODEFIX
5422 ("\\missing `WITH &;`", Pkg
);
5424 Error_Msg_Node_1
:= Selectors
(1);
5425 Error_Msg_Node_2
:= Selectors
(2);
5426 Error_Msg_N
-- CODEFIX
5427 ("\\missing `WITH &.&;`", Pkg
);
5429 Error_Msg_Node_1
:= Selectors
(1);
5430 Error_Msg_Node_2
:= Selectors
(2);
5431 Error_Msg_Node_3
:= Selectors
(3);
5432 Error_Msg_N
-- CODEFIX
5433 ("\\missing `WITH &.&.&;`", Pkg
);
5435 Error_Msg_Node_1
:= Selectors
(1);
5436 Error_Msg_Node_2
:= Selectors
(2);
5437 Error_Msg_Node_3
:= Selectors
(3);
5438 Error_Msg_Node_3
:= Selectors
(4);
5439 Error_Msg_N
-- CODEFIX
5440 ("\\missing `WITH &.&.&.&;`", Pkg
);
5442 Error_Msg_Node_1
:= Selectors
(1);
5443 Error_Msg_Node_2
:= Selectors
(2);
5444 Error_Msg_Node_3
:= Selectors
(3);
5445 Error_Msg_Node_3
:= Selectors
(4);
5446 Error_Msg_Node_3
:= Selectors
(5);
5447 Error_Msg_N
-- CODEFIX
5448 ("\\missing `WITH &.&.&.&.&;`", Pkg
);
5450 Error_Msg_Node_1
:= Selectors
(1);
5451 Error_Msg_Node_2
:= Selectors
(2);
5452 Error_Msg_Node_3
:= Selectors
(3);
5453 Error_Msg_Node_4
:= Selectors
(4);
5454 Error_Msg_Node_5
:= Selectors
(5);
5455 Error_Msg_Node_6
:= Selectors
(6);
5456 Error_Msg_N
-- CODEFIX
5457 ("\\missing `WITH &.&.&.&.&.&;`", Pkg
);
5459 raise Program_Error
;
5461 end Error_Missing_With_Of_Known_Unit
;
5463 --------------------
5464 -- Is_Self_Hidden --
5465 --------------------
5467 function Is_Self_Hidden
(E
: Entity_Id
) return Boolean is
5469 if Is_Not_Self_Hidden
(E
) then
5470 return Ekind
(E
) = E_Void
;
5476 ----------------------
5477 -- Find_Direct_Name --
5478 ----------------------
5480 procedure Find_Direct_Name
(N
: Node_Id
) is
5485 Homonyms
: Entity_Id
;
5486 -- Saves start of homonym chain
5488 Inst
: Entity_Id
:= Empty
;
5489 -- Enclosing instance, if any
5491 Nvis_Entity
: Boolean;
5492 -- Set True to indicate that there is at least one entity on the homonym
5493 -- chain which, while not visible, is visible enough from the user point
5494 -- of view to warrant an error message of "not visible" rather than
5497 Nvis_Is_Private_Subprg
: Boolean := False;
5498 -- Ada 2005 (AI-262): Set True to indicate that a form of Beaujolais
5499 -- effect concerning library subprograms has been detected. Used to
5500 -- generate the precise error message.
5502 function From_Actual_Package
(E
: Entity_Id
) return Boolean;
5503 -- Returns true if the entity is an actual for a package that is itself
5504 -- an actual for a formal package of the current instance. Such an
5505 -- entity requires special handling because it may be use-visible but
5506 -- hides directly visible entities defined outside the instance, because
5507 -- the corresponding formal did so in the generic.
5509 function Is_Actual_Parameter
return Boolean;
5510 -- This function checks if the node N is an identifier that is an actual
5511 -- parameter of a procedure call. If so it returns True, otherwise it
5512 -- return False. The reason for this check is that at this stage we do
5513 -- not know what procedure is being called if the procedure might be
5514 -- overloaded, so it is premature to go setting referenced flags or
5515 -- making calls to Generate_Reference. We will wait till Resolve_Actuals
5516 -- for that processing.
5517 -- Note: there is a similar routine Sem_Util.Is_Actual_Parameter, but
5518 -- it works for both function and procedure calls, while here we are
5519 -- only concerned with procedure calls (and with entry calls as well,
5520 -- but they are parsed as procedure calls and only later rewritten to
5523 function Known_But_Invisible
(E
: Entity_Id
) return Boolean;
5524 -- This function determines whether a reference to the entity E, which
5525 -- is not visible, can reasonably be considered to be known to the
5526 -- writer of the reference. This is a heuristic test, used only for
5527 -- the purposes of figuring out whether we prefer to complain that an
5528 -- entity is undefined or invisible (and identify the declaration of
5529 -- the invisible entity in the latter case). The point here is that we
5530 -- don't want to complain that something is invisible and then point to
5531 -- something entirely mysterious to the writer.
5533 procedure Nvis_Messages
;
5534 -- Called if there are no visible entries for N, but there is at least
5535 -- one non-directly visible, or hidden declaration. This procedure
5536 -- outputs an appropriate set of error messages.
5538 procedure Undefined
(Nvis
: Boolean);
5539 -- This function is called if the current node has no corresponding
5540 -- visible entity or entities. The value set in Msg indicates whether
5541 -- an error message was generated (multiple error messages for the
5542 -- same variable are generally suppressed, see body for details).
5543 -- Msg is True if an error message was generated, False if not. This
5544 -- value is used by the caller to determine whether or not to output
5545 -- additional messages where appropriate. The parameter is set False
5546 -- to get the message "X is undefined", and True to get the message
5547 -- "X is not visible".
5549 -------------------------
5550 -- From_Actual_Package --
5551 -------------------------
5553 function From_Actual_Package
(E
: Entity_Id
) return Boolean is
5554 Scop
: constant Entity_Id
:= Scope
(E
);
5555 -- Declared scope of candidate entity
5557 function Declared_In_Actual
(Pack
: Entity_Id
) return Boolean;
5558 -- Recursive function that does the work and examines actuals of
5559 -- actual packages of current instance.
5561 ------------------------
5562 -- Declared_In_Actual --
5563 ------------------------
5565 function Declared_In_Actual
(Pack
: Entity_Id
) return Boolean is
5566 pragma Assert
(Ekind
(Pack
) = E_Package
);
5569 if No
(Associated_Formal_Package
(Pack
)) then
5573 Act
:= First_Entity
(Pack
);
5574 while Present
(Act
) loop
5575 if Renamed_Entity
(Pack
) = Scop
then
5578 -- Check for end of list of actuals
5580 elsif Ekind
(Act
) = E_Package
5581 and then Renamed_Entity
(Act
) = Pack
5585 elsif Ekind
(Act
) = E_Package
5586 and then Declared_In_Actual
(Act
)
5596 end Declared_In_Actual
;
5602 -- Start of processing for From_Actual_Package
5605 if not In_Instance
then
5609 Inst
:= Current_Scope
;
5610 while Present
(Inst
)
5611 and then Ekind
(Inst
) /= E_Package
5612 and then not Is_Generic_Instance
(Inst
)
5614 Inst
:= Scope
(Inst
);
5621 Act
:= First_Entity
(Inst
);
5622 while Present
(Act
) loop
5623 if Ekind
(Act
) = E_Package
5624 and then Declared_In_Actual
(Act
)
5634 end From_Actual_Package
;
5636 -------------------------
5637 -- Is_Actual_Parameter --
5638 -------------------------
5640 function Is_Actual_Parameter
return Boolean is
5642 if Nkind
(N
) = N_Identifier
then
5643 case Nkind
(Parent
(N
)) is
5644 when N_Procedure_Call_Statement
=>
5645 return Is_List_Member
(N
)
5646 and then List_Containing
(N
) =
5647 Parameter_Associations
(Parent
(N
));
5649 when N_Parameter_Association
=>
5650 return N
= Explicit_Actual_Parameter
(Parent
(N
))
5651 and then Nkind
(Parent
(Parent
(N
))) =
5652 N_Procedure_Call_Statement
;
5660 end Is_Actual_Parameter
;
5662 -------------------------
5663 -- Known_But_Invisible --
5664 -------------------------
5666 function Known_But_Invisible
(E
: Entity_Id
) return Boolean is
5667 Fname
: File_Name_Type
;
5670 -- Entities in Standard are always considered to be known
5672 if Sloc
(E
) <= Standard_Location
then
5675 -- An entity that does not come from source is always considered
5676 -- to be unknown, since it is an artifact of code expansion.
5678 elsif not Comes_From_Source
(E
) then
5682 -- Here we have an entity that is not from package Standard, and
5683 -- which comes from Source. See if it comes from an internal file.
5685 Fname
:= Unit_File_Name
(Get_Source_Unit
(E
));
5687 -- Case of from internal file
5689 if In_Internal_Unit
(E
) then
5691 -- Private part entities in internal files are never considered
5692 -- to be known to the writer of normal application code.
5694 if Is_Hidden
(E
) then
5698 -- Entities from System packages other than System and
5699 -- System.Storage_Elements are not considered to be known.
5700 -- System.Auxxxx files are also considered known to the user.
5702 -- Should refine this at some point to generally distinguish
5703 -- between known and unknown internal files ???
5705 Get_Name_String
(Fname
);
5710 Name_Buffer
(1 .. 2) /= "s-"
5712 Name_Buffer
(3 .. 8) = "stoele"
5714 Name_Buffer
(3 .. 5) = "aux";
5716 -- If not an internal file, then entity is definitely known, even if
5717 -- it is in a private part (the message generated will note that it
5718 -- is in a private part).
5723 end Known_But_Invisible
;
5729 procedure Nvis_Messages
is
5730 Comp_Unit
: Node_Id
;
5732 Found
: Boolean := False;
5733 Hidden
: Boolean := False;
5737 -- Ada 2005 (AI-262): Generate a precise error concerning the
5738 -- Beaujolais effect that was previously detected
5740 if Nvis_Is_Private_Subprg
then
5742 pragma Assert
(Nkind
(E2
) = N_Defining_Identifier
5743 and then Ekind
(E2
) = E_Function
5744 and then Scope
(E2
) = Standard_Standard
5745 and then Has_Private_With
(E2
));
5747 -- Find the sloc corresponding to the private with'ed unit
5749 Comp_Unit
:= Cunit
(Current_Sem_Unit
);
5750 Error_Msg_Sloc
:= No_Location
;
5752 Item
:= First
(Context_Items
(Comp_Unit
));
5753 while Present
(Item
) loop
5754 if Nkind
(Item
) = N_With_Clause
5755 and then Private_Present
(Item
)
5756 and then Entity
(Name
(Item
)) = E2
5758 Error_Msg_Sloc
:= Sloc
(Item
);
5765 pragma Assert
(Error_Msg_Sloc
/= No_Location
);
5767 Error_Msg_N
("(Ada 2005): hidden by private with clause #", N
);
5771 Undefined
(Nvis
=> True);
5775 -- First loop does hidden declarations
5778 while Present
(Ent
) loop
5779 if Is_Potentially_Use_Visible
(Ent
) then
5781 Error_Msg_N
-- CODEFIX
5782 ("multiple use clauses cause hiding!", N
);
5786 Error_Msg_Sloc
:= Sloc
(Ent
);
5787 Error_Msg_N
-- CODEFIX
5788 ("hidden declaration#!", N
);
5791 Ent
:= Homonym
(Ent
);
5794 -- If we found hidden declarations, then that's enough, don't
5795 -- bother looking for non-visible declarations as well.
5801 -- Second loop does non-directly visible declarations
5804 while Present
(Ent
) loop
5805 if not Is_Potentially_Use_Visible
(Ent
) then
5807 -- Do not bother the user with unknown entities
5809 if not Known_But_Invisible
(Ent
) then
5813 Error_Msg_Sloc
:= Sloc
(Ent
);
5815 -- Output message noting that there is a non-visible
5816 -- declaration, distinguishing the private part case.
5818 if Is_Hidden
(Ent
) then
5819 Error_Msg_N
("non-visible (private) declaration#!", N
);
5821 -- If the entity is declared in a generic package, it
5822 -- cannot be visible, so there is no point in adding it
5823 -- to the list of candidates if another homograph from a
5824 -- non-generic package has been seen.
5826 elsif Ekind
(Scope
(Ent
)) = E_Generic_Package
5832 -- When the entity comes from a generic instance the
5833 -- normal error message machinery will give the line
5834 -- number of the generic package and the location of
5835 -- the generic instance, but not the name of the
5838 -- So, in order to give more descriptive error messages
5839 -- in this case, we include the name of the generic
5842 if Is_Generic_Instance
(Scope
(Ent
)) then
5843 Error_Msg_Name_1
:= Chars
(Scope
(Ent
));
5844 Error_Msg_N
-- CODEFIX
5845 ("non-visible declaration from %#!", N
);
5847 -- Otherwise print the message normally
5850 Error_Msg_N
-- CODEFIX
5851 ("non-visible declaration#!", N
);
5854 if Ekind
(Scope
(Ent
)) /= E_Generic_Package
then
5858 if Is_Compilation_Unit
(Ent
)
5860 Nkind
(Parent
(Parent
(N
))) = N_Use_Package_Clause
5862 Error_Msg_Qual_Level
:= 99;
5863 Error_Msg_NE
-- CODEFIX
5864 ("\\missing `WITH &;`", N
, Ent
);
5865 Error_Msg_Qual_Level
:= 0;
5868 if Ekind
(Ent
) = E_Discriminant
5869 and then Present
(Corresponding_Discriminant
(Ent
))
5870 and then Scope
(Corresponding_Discriminant
(Ent
)) =
5874 ("inherited discriminant not allowed here" &
5875 " (RM 3.8 (12), 3.8.1 (6))!", N
);
5879 -- Set entity and its containing package as referenced. We
5880 -- can't be sure of this, but this seems a better choice
5881 -- to avoid unused entity messages.
5883 if Comes_From_Source
(Ent
) then
5884 Set_Referenced
(Ent
);
5885 Set_Referenced
(Cunit_Entity
(Get_Source_Unit
(Ent
)));
5890 Ent
:= Homonym
(Ent
);
5899 procedure Undefined
(Nvis
: Boolean) is
5900 Emsg
: Error_Msg_Id
;
5903 -- We should never find an undefined internal name. If we do, then
5904 -- see if we have previous errors. If so, ignore on the grounds that
5905 -- it is probably a cascaded message (e.g. a block label from a badly
5906 -- formed block). If no previous errors, then we have a real internal
5907 -- error of some kind so raise an exception.
5909 if Is_Internal_Name
(Chars
(N
)) then
5910 if Total_Errors_Detected
/= 0 then
5913 raise Program_Error
;
5917 -- A very specialized error check, if the undefined variable is
5918 -- a case tag, and the case type is an enumeration type, check
5919 -- for a possible misspelling, and if so, modify the identifier
5921 -- Named aggregate should also be handled similarly ???
5923 if Nkind
(N
) = N_Identifier
5924 and then Nkind
(Parent
(N
)) = N_Case_Statement_Alternative
5927 Case_Stm
: constant Node_Id
:= Parent
(Parent
(N
));
5928 Case_Typ
: constant Entity_Id
:= Etype
(Expression
(Case_Stm
));
5933 if Is_Enumeration_Type
(Case_Typ
)
5934 and then not Is_Standard_Character_Type
(Case_Typ
)
5936 Lit
:= First_Literal
(Case_Typ
);
5937 Get_Name_String
(Chars
(Lit
));
5939 if Chars
(Lit
) /= Chars
(N
)
5940 and then Is_Bad_Spelling_Of
(Chars
(N
), Chars
(Lit
))
5942 Error_Msg_Node_2
:= Lit
;
5943 Error_Msg_N
-- CODEFIX
5944 ("& is undefined, assume misspelling of &", N
);
5945 Rewrite
(N
, New_Occurrence_Of
(Lit
, Sloc
(N
)));
5954 -- Normal processing
5956 Set_Entity
(N
, Any_Id
);
5957 Set_Etype
(N
, Any_Type
);
5959 -- We use the table Urefs to keep track of entities for which we
5960 -- have issued errors for undefined references. Multiple errors
5961 -- for a single name are normally suppressed, however we modify
5962 -- the error message to alert the programmer to this effect.
5964 for J
in Urefs
.First
.. Urefs
.Last
loop
5965 if Chars
(N
) = Chars
(Urefs
.Table
(J
).Node
) then
5966 if Urefs
.Table
(J
).Err
/= No_Error_Msg
5967 and then Sloc
(N
) /= Urefs
.Table
(J
).Loc
5969 Error_Msg_Node_1
:= Urefs
.Table
(J
).Node
;
5971 if Urefs
.Table
(J
).Nvis
then
5972 Change_Error_Text
(Urefs
.Table
(J
).Err
,
5973 "& is not visible (more references follow)");
5975 Change_Error_Text
(Urefs
.Table
(J
).Err
,
5976 "& is undefined (more references follow)");
5979 Urefs
.Table
(J
).Err
:= No_Error_Msg
;
5982 -- Although we will set Msg False, and thus suppress the
5983 -- message, we also set Error_Posted True, to avoid any
5984 -- cascaded messages resulting from the undefined reference.
5987 Set_Error_Posted
(N
);
5992 -- If entry not found, this is first undefined occurrence
5995 Error_Msg_N
("& is not visible!", N
);
5999 Error_Msg_N
("& is undefined!", N
);
6002 -- A very bizarre special check, if the undefined identifier
6003 -- is Put or Put_Line, then add a special error message (since
6004 -- this is a very common error for beginners to make).
6006 if Chars
(N
) in Name_Put | Name_Put_Line
then
6007 Error_Msg_N
-- CODEFIX
6008 ("\\possible missing `WITH Ada.Text_'I'O; " &
6009 "USE Ada.Text_'I'O`!", N
);
6011 -- Another special check if N is the prefix of a selected
6012 -- component which is a known unit: add message complaining
6013 -- about missing with for this unit.
6015 elsif Nkind
(Parent
(N
)) = N_Selected_Component
6016 and then N
= Prefix
(Parent
(N
))
6017 and then Is_Known_Unit
(Parent
(N
))
6019 Error_Missing_With_Of_Known_Unit
(N
);
6022 -- Now check for possible misspellings
6026 Ematch
: Entity_Id
:= Empty
;
6028 for Nam
in First_Name_Id
.. Last_Name_Id
loop
6029 E
:= Get_Name_Entity_Id
(Nam
);
6032 and then (Is_Immediately_Visible
(E
)
6034 Is_Potentially_Use_Visible
(E
))
6036 if Is_Bad_Spelling_Of
(Chars
(N
), Nam
) then
6043 if Present
(Ematch
) then
6044 Error_Msg_NE
-- CODEFIX
6045 ("\possible misspelling of&", N
, Ematch
);
6050 -- Make entry in undefined references table unless the full errors
6051 -- switch is set, in which case by refraining from generating the
6052 -- table entry we guarantee that we get an error message for every
6053 -- undefined reference. The entry is not added if we are ignoring
6056 if not All_Errors_Mode
6057 and then Ignore_Errors_Enable
= 0
6058 and then not Get_Ignore_Errors
6072 Nested_Inst
: Entity_Id
:= Empty
;
6073 -- The entity of a nested instance which appears within Inst (if any)
6075 -- Start of processing for Find_Direct_Name
6078 -- If the entity pointer is already set, this is an internal node, or
6079 -- a node that is analyzed more than once, after a tree modification.
6080 -- In such a case there is no resolution to perform, just set the type.
6082 if Present
(Entity
(N
)) then
6083 if Is_Type
(Entity
(N
)) then
6084 Set_Etype
(N
, Entity
(N
));
6088 Entyp
: constant Entity_Id
:= Etype
(Entity
(N
));
6091 -- One special case here. If the Etype field is already set,
6092 -- and references the packed array type corresponding to the
6093 -- etype of the referenced entity, then leave it alone. This
6094 -- happens for trees generated from Exp_Pakd, where expressions
6095 -- can be deliberately "mis-typed" to the packed array type.
6097 if Is_Packed_Array
(Entyp
)
6098 and then Present
(Etype
(N
))
6099 and then Etype
(N
) = Packed_Array_Impl_Type
(Entyp
)
6103 -- If not that special case, then just reset the Etype
6106 Set_Etype
(N
, Entyp
);
6111 -- Although the marking of use clauses happens at the end of
6112 -- Find_Direct_Name, a certain case where a generic actual satisfies
6113 -- a use clause must be checked here due to how the generic machinery
6114 -- handles the analysis of said actuals.
6117 and then Nkind
(Parent
(N
)) = N_Generic_Association
6119 Mark_Use_Clauses
(Entity
(N
));
6125 -- Preserve relevant elaboration-related attributes of the context which
6126 -- are no longer available or very expensive to recompute once analysis,
6127 -- resolution, and expansion are over.
6129 if Nkind
(N
) = N_Identifier
then
6130 Mark_Elaboration_Attributes
6137 -- Here if Entity pointer was not set, we need full visibility analysis
6138 -- First we generate debugging output if the debug E flag is set.
6140 if Debug_Flag_E
then
6141 Write_Str
("Looking for ");
6142 Write_Name
(Chars
(N
));
6146 Homonyms
:= Current_Entity
(N
);
6147 Nvis_Entity
:= False;
6150 while Present
(E
) loop
6152 -- If entity is immediately visible or potentially use visible, then
6153 -- process the entity and we are done.
6155 if Is_Immediately_Visible
(E
) then
6156 goto Immediately_Visible_Entity
;
6158 elsif Is_Potentially_Use_Visible
(E
) then
6159 goto Potentially_Use_Visible_Entity
;
6161 -- Note if a known but invisible entity encountered
6163 elsif Known_But_Invisible
(E
) then
6164 Nvis_Entity
:= True;
6167 -- Move to next entity in chain and continue search
6172 -- If no entries on homonym chain that were potentially visible,
6173 -- and no entities reasonably considered as non-visible, then
6174 -- we have a plain undefined reference, with no additional
6175 -- explanation required.
6177 if not Nvis_Entity
then
6178 Undefined
(Nvis
=> False);
6180 -- Otherwise there is at least one entry on the homonym chain that
6181 -- is reasonably considered as being known and non-visible.
6189 -- Processing for a potentially use visible entry found. We must search
6190 -- the rest of the homonym chain for two reasons. First, if there is a
6191 -- directly visible entry, then none of the potentially use-visible
6192 -- entities are directly visible (RM 8.4(10)). Second, we need to check
6193 -- for the case of multiple potentially use-visible entries hiding one
6194 -- another and as a result being non-directly visible (RM 8.4(11)).
6196 <<Potentially_Use_Visible_Entity
>> declare
6197 Only_One_Visible
: Boolean := True;
6198 All_Overloadable
: Boolean := Is_Overloadable
(E
);
6202 while Present
(E2
) loop
6203 if Is_Immediately_Visible
(E2
) then
6205 -- If the use-visible entity comes from the actual for a
6206 -- formal package, it hides a directly visible entity from
6207 -- outside the instance.
6209 if From_Actual_Package
(E
)
6210 and then Scope_Depth
(Scope
(E2
)) < Scope_Depth
(Inst
)
6215 goto Immediately_Visible_Entity
;
6218 elsif Is_Potentially_Use_Visible
(E2
) then
6219 Only_One_Visible
:= False;
6220 All_Overloadable
:= All_Overloadable
and Is_Overloadable
(E2
);
6222 -- Ada 2005 (AI-262): Protect against a form of Beaujolais effect
6223 -- that can occur in private_with clauses. Example:
6226 -- private with B; package A is
6227 -- package C is function B return Integer;
6229 -- V1 : Integer := B;
6230 -- private function B return Integer;
6231 -- V2 : Integer := B;
6234 -- V1 resolves to A.B, but V2 resolves to library unit B
6236 elsif Ekind
(E2
) = E_Function
6237 and then Scope
(E2
) = Standard_Standard
6238 and then Has_Private_With
(E2
)
6240 Only_One_Visible
:= False;
6241 All_Overloadable
:= False;
6242 Nvis_Is_Private_Subprg
:= True;
6249 -- On falling through this loop, we have checked that there are no
6250 -- immediately visible entities. Only_One_Visible is set if exactly
6251 -- one potentially use visible entity exists. All_Overloadable is
6252 -- set if all the potentially use visible entities are overloadable.
6253 -- The condition for legality is that either there is one potentially
6254 -- use visible entity, or if there is more than one, then all of them
6255 -- are overloadable.
6257 if Only_One_Visible
or All_Overloadable
then
6260 -- If there is more than one potentially use-visible entity and at
6261 -- least one of them non-overloadable, we have an error (RM 8.4(11)).
6262 -- Note that E points to the first such entity on the homonym list.
6265 -- If one of the entities is declared in an actual package, it
6266 -- was visible in the generic, and takes precedence over other
6267 -- entities that are potentially use-visible. The same applies
6268 -- if the entity is declared in a local instantiation of the
6269 -- current instance.
6273 -- Find the current instance
6275 Inst
:= Current_Scope
;
6276 while Present
(Inst
) and then Inst
/= Standard_Standard
loop
6277 if Is_Generic_Instance
(Inst
) then
6281 Inst
:= Scope
(Inst
);
6284 -- Reexamine the candidate entities, giving priority to those
6285 -- that were visible within the generic.
6288 while Present
(E2
) loop
6289 Nested_Inst
:= Nearest_Enclosing_Instance
(E2
);
6291 -- The entity is declared within an actual package, or in a
6292 -- nested instance. The ">=" accounts for the case where the
6293 -- current instance and the nested instance are the same.
6295 if From_Actual_Package
(E2
)
6296 or else (Present
(Nested_Inst
)
6297 and then Scope_Depth
(Nested_Inst
) >=
6310 elsif Is_Predefined_Unit
(Current_Sem_Unit
) then
6311 -- A use clause in the body of a system file creates conflict
6312 -- with some entity in a user scope, while rtsfind is active.
6313 -- Keep only the entity coming from another predefined unit.
6316 while Present
(E2
) loop
6317 if In_Predefined_Unit
(E2
) then
6325 -- Entity must exist because predefined unit is correct
6327 raise Program_Error
;
6336 -- Come here with E set to the first immediately visible entity on
6337 -- the homonym chain. This is the one we want unless there is another
6338 -- immediately visible entity further on in the chain for an inner
6339 -- scope (RM 8.3(8)).
6341 <<Immediately_Visible_Entity
>> declare
6346 -- Find scope level of initial entity. When compiling through
6347 -- Rtsfind, the previous context is not completely invisible, and
6348 -- an outer entity may appear on the chain, whose scope is below
6349 -- the entry for Standard that delimits the current scope stack.
6350 -- Indicate that the level for this spurious entry is outside of
6351 -- the current scope stack.
6353 Level
:= Scope_Stack
.Last
;
6355 Scop
:= Scope_Stack
.Table
(Level
).Entity
;
6356 exit when Scop
= Scope
(E
);
6358 exit when Scop
= Standard_Standard
;
6361 -- Now search remainder of homonym chain for more inner entry
6362 -- If the entity is Standard itself, it has no scope, and we
6363 -- compare it with the stack entry directly.
6366 while Present
(E2
) loop
6367 if Is_Immediately_Visible
(E2
) then
6369 -- If a generic package contains a local declaration that
6370 -- has the same name as the generic, there may be a visibility
6371 -- conflict in an instance, where the local declaration must
6372 -- also hide the name of the corresponding package renaming.
6373 -- We check explicitly for a package declared by a renaming,
6374 -- whose renamed entity is an instance that is on the scope
6375 -- stack, and that contains a homonym in the same scope. Once
6376 -- we have found it, we know that the package renaming is not
6377 -- immediately visible, and that the identifier denotes the
6378 -- other entity (and its homonyms if overloaded).
6380 if Scope
(E
) = Scope
(E2
)
6381 and then Ekind
(E
) = E_Package
6382 and then Present
(Renamed_Entity
(E
))
6383 and then Is_Generic_Instance
(Renamed_Entity
(E
))
6384 and then In_Open_Scopes
(Renamed_Entity
(E
))
6385 and then Comes_From_Source
(N
)
6387 Set_Is_Immediately_Visible
(E
, False);
6391 for J
in Level
+ 1 .. Scope_Stack
.Last
loop
6392 if Scope_Stack
.Table
(J
).Entity
= Scope
(E2
)
6393 or else Scope_Stack
.Table
(J
).Entity
= E2
6406 -- At the end of that loop, E is the innermost immediately
6407 -- visible entity, so we are all set.
6410 -- Come here with entity found, and stored in E
6414 -- Check violation of No_Wide_Characters restriction
6416 Check_Wide_Character_Restriction
(E
, N
);
6418 -- When distribution features are available (Get_PCS_Name /=
6419 -- Name_No_DSA), a remote access-to-subprogram type is converted
6420 -- into a record type holding whatever information is needed to
6421 -- perform a remote call on an RCI subprogram. In that case we
6422 -- rewrite any occurrence of the RAS type into the equivalent record
6423 -- type here. 'Access attribute references and RAS dereferences are
6424 -- then implemented using specific TSSs. However when distribution is
6425 -- not available (case of Get_PCS_Name = Name_No_DSA), we bypass the
6426 -- generation of these TSSs, and we must keep the RAS type in its
6427 -- original access-to-subprogram form (since all calls through a
6428 -- value of such type will be local anyway in the absence of a PCS).
6430 if Comes_From_Source
(N
)
6431 and then Is_Remote_Access_To_Subprogram_Type
(E
)
6432 and then Ekind
(E
) = E_Access_Subprogram_Type
6433 and then Expander_Active
6434 and then Get_PCS_Name
/= Name_No_DSA
6436 Rewrite
(N
, New_Occurrence_Of
(Equivalent_Type
(E
), Sloc
(N
)));
6440 -- Set the entity. Note that the reason we call Set_Entity for the
6441 -- overloadable case, as opposed to Set_Entity_With_Checks is
6442 -- that in the overloaded case, the initial call can set the wrong
6443 -- homonym. The call that sets the right homonym is in Sem_Res and
6444 -- that call does use Set_Entity_With_Checks, so we don't miss
6447 if Is_Overloadable
(E
) then
6450 Set_Entity_With_Checks
(N
, E
);
6456 Set_Etype
(N
, Get_Full_View
(Etype
(E
)));
6459 if Debug_Flag_E
then
6460 Write_Str
(" found ");
6461 Write_Entity_Info
(E
, " ");
6464 if Is_Self_Hidden
(E
)
6466 (not Is_Record_Type
(Current_Scope
)
6467 or else Nkind
(Parent
(N
)) /= N_Pragma_Argument_Association
)
6469 Premature_Usage
(N
);
6471 -- If the entity is overloadable, collect all interpretations of the
6472 -- name for subsequent overload resolution. We optimize a bit here to
6473 -- do this only if we have an overloadable entity that is not on its
6474 -- own on the homonym chain.
6476 elsif Is_Overloadable
(E
)
6477 and then (Present
(Homonym
(E
)) or else Current_Entity
(N
) /= E
)
6479 Collect_Interps
(N
);
6481 -- If no homonyms were visible, the entity is unambiguous
6483 if not Is_Overloaded
(N
) then
6484 if not Is_Actual_Parameter
then
6485 Generate_Reference
(E
, N
);
6489 -- Case of non-overloadable entity, set the entity providing that
6490 -- we do not have the case of a discriminant reference within a
6491 -- default expression. Such references are replaced with the
6492 -- corresponding discriminal, which is the formal corresponding to
6493 -- to the discriminant in the initialization procedure.
6496 -- Entity is unambiguous, indicate that it is referenced here
6498 -- For a renaming of an object, always generate simple reference,
6499 -- we don't try to keep track of assignments in this case, except
6500 -- in SPARK mode where renamings are traversed for generating
6501 -- local effects of subprograms.
6504 and then Present
(Renamed_Object
(E
))
6505 and then not GNATprove_Mode
6507 Generate_Reference
(E
, N
);
6509 -- If the renamed entity is a private protected component,
6510 -- reference the original component as well. This needs to be
6511 -- done because the private renamings are installed before any
6512 -- analysis has occurred. Reference to a private component will
6513 -- resolve to the renaming and the original component will be
6514 -- left unreferenced, hence the following.
6516 if Is_Prival
(E
) then
6517 Generate_Reference
(Prival_Link
(E
), N
);
6520 -- One odd case is that we do not want to set the Referenced flag
6521 -- if the entity is a label, and the identifier is the label in
6522 -- the source, since this is not a reference from the point of
6523 -- view of the user.
6525 elsif Nkind
(Parent
(N
)) = N_Label
then
6527 R
: constant Boolean := Referenced
(E
);
6530 -- Generate reference unless this is an actual parameter
6531 -- (see comment below).
6533 if not Is_Actual_Parameter
then
6534 Generate_Reference
(E
, N
);
6535 Set_Referenced
(E
, R
);
6539 -- Normal case, not a label: generate reference
6542 if not Is_Actual_Parameter
then
6544 -- Package or generic package is always a simple reference
6546 if Is_Package_Or_Generic_Package
(E
) then
6547 Generate_Reference
(E
, N
, 'r');
6549 -- Else see if we have a left hand side
6552 case Known_To_Be_Assigned
(N
, Only_LHS
=> True) is
6554 Generate_Reference
(E
, N
, 'm');
6557 Generate_Reference
(E
, N
, 'r');
6564 Set_Entity_Or_Discriminal
(N
, E
);
6566 -- The name may designate a generalized reference, in which case
6567 -- the dereference interpretation will be included. Context is
6568 -- one in which a name is legal.
6570 if Ada_Version
>= Ada_2012
6572 (Nkind
(Parent
(N
)) in N_Subexpr
6573 or else Nkind
(Parent
(N
)) in N_Assignment_Statement
6574 | N_Object_Declaration
6575 | N_Parameter_Association
)
6577 Check_Implicit_Dereference
(N
, Etype
(E
));
6582 -- Mark relevant use-type and use-package clauses as effective if the
6583 -- node in question is not overloaded and therefore does not require
6586 -- Note: Generic actual subprograms do not follow the normal resolution
6587 -- path, so ignore the fact that they are overloaded and mark them
6590 if Nkind
(N
) not in N_Subexpr
or else not Is_Overloaded
(N
) then
6591 Mark_Use_Clauses
(N
);
6594 -- Come here with entity set
6597 Check_Restriction_No_Use_Of_Entity
(N
);
6599 -- Annotate the tree by creating a variable reference marker in case the
6600 -- original variable reference is folded or optimized away. The variable
6601 -- reference marker is automatically saved for later examination by the
6602 -- ABE Processing phase. Variable references which act as actuals in a
6603 -- call require special processing and are left to Resolve_Actuals. The
6604 -- reference is a write when it appears on the left hand side of an
6607 if Needs_Variable_Reference_Marker
(N
=> N
, Calls_OK
=> False) then
6609 Is_Assignment_LHS
: constant Boolean := Known_To_Be_Assigned
(N
);
6612 Build_Variable_Reference_Marker
6614 Read
=> not Is_Assignment_LHS
,
6615 Write
=> Is_Assignment_LHS
);
6618 end Find_Direct_Name
;
6620 ------------------------
6621 -- Find_Expanded_Name --
6622 ------------------------
6624 -- This routine searches the homonym chain of the entity until it finds
6625 -- an entity declared in the scope denoted by the prefix. If the entity
6626 -- is private, it may nevertheless be immediately visible, if we are in
6627 -- the scope of its declaration.
6629 procedure Find_Expanded_Name
(N
: Node_Id
) is
6630 function In_Abstract_View_Pragma
(Nod
: Node_Id
) return Boolean;
6631 -- Determine whether expanded name Nod appears within a pragma which is
6632 -- a suitable context for an abstract view of a state or variable. The
6633 -- following pragmas fall in this category:
6640 -- In addition, pragma Abstract_State is also considered suitable even
6641 -- though it is an illegal context for an abstract view as this allows
6642 -- for proper resolution of abstract views of variables. This illegal
6643 -- context is later flagged in the analysis of indicator Part_Of.
6645 -----------------------------
6646 -- In_Abstract_View_Pragma --
6647 -----------------------------
6649 function In_Abstract_View_Pragma
(Nod
: Node_Id
) return Boolean is
6653 -- Climb the parent chain looking for a pragma
6656 while Present
(Par
) loop
6657 if Nkind
(Par
) = N_Pragma
then
6658 if Pragma_Name_Unmapped
(Par
)
6659 in Name_Abstract_State
6663 | Name_Refined_Depends
6664 | Name_Refined_Global
6668 -- Otherwise the pragma is not a legal context for an abstract
6675 -- Prevent the search from going too far
6677 elsif Is_Body_Or_Package_Declaration
(Par
) then
6681 Par
:= Parent
(Par
);
6685 end In_Abstract_View_Pragma
;
6689 Selector
: constant Node_Id
:= Selector_Name
(N
);
6691 Candidate
: Entity_Id
:= Empty
;
6695 -- Start of processing for Find_Expanded_Name
6698 P_Name
:= Entity
(Prefix
(N
));
6700 -- If the prefix is a renamed package, look for the entity in the
6701 -- original package.
6703 if Ekind
(P_Name
) = E_Package
6704 and then Present
(Renamed_Entity
(P_Name
))
6706 P_Name
:= Renamed_Entity
(P_Name
);
6708 if From_Limited_With
(P_Name
)
6709 and then not Unit_Is_Visible
(Cunit
(Get_Source_Unit
(P_Name
)))
6712 ("renaming of limited view of package & not usable in this"
6713 & " context (RM 8.5.3(3.1/2))", Prefix
(N
), P_Name
);
6715 elsif Has_Limited_View
(P_Name
)
6716 and then not Unit_Is_Visible
(Cunit
(Get_Source_Unit
(P_Name
)))
6717 and then not Is_Visible_Through_Renamings
(P_Name
)
6720 ("renaming of limited view of package & not usable in this"
6721 & " context (RM 8.5.3(3.1/2))", Prefix
(N
), P_Name
);
6724 -- Rewrite node with entity field pointing to renamed object
6726 Rewrite
(Prefix
(N
), New_Copy
(Prefix
(N
)));
6727 Set_Entity
(Prefix
(N
), P_Name
);
6729 -- If the prefix is an object of a concurrent type, look for
6730 -- the entity in the associated task or protected type.
6732 elsif Is_Concurrent_Type
(Etype
(P_Name
)) then
6733 P_Name
:= Etype
(P_Name
);
6736 Id
:= Current_Entity
(Selector
);
6739 Is_New_Candidate
: Boolean;
6742 while Present
(Id
) loop
6743 if Scope
(Id
) = P_Name
then
6745 Is_New_Candidate
:= True;
6747 -- Handle abstract views of states and variables. These are
6748 -- acceptable candidates only when the reference to the view
6749 -- appears in certain pragmas.
6751 if Ekind
(Id
) = E_Abstract_State
6752 and then From_Limited_With
(Id
)
6753 and then Present
(Non_Limited_View
(Id
))
6755 if In_Abstract_View_Pragma
(N
) then
6756 Candidate
:= Non_Limited_View
(Id
);
6757 Is_New_Candidate
:= True;
6759 -- Hide the candidate because it is not used in a proper
6764 Is_New_Candidate
:= False;
6768 -- Ada 2005 (AI-217): Handle shadow entities associated with
6769 -- types declared in limited-withed nested packages. We don't need
6770 -- to handle E_Incomplete_Subtype entities because the entities
6771 -- in the limited view are always E_Incomplete_Type and
6772 -- E_Class_Wide_Type entities (see Build_Limited_Views).
6774 -- Regarding the expression used to evaluate the scope, it
6775 -- is important to note that the limited view also has shadow
6776 -- entities associated nested packages. For this reason the
6777 -- correct scope of the entity is the scope of the real entity.
6778 -- The non-limited view may itself be incomplete, in which case
6779 -- get the full view if available.
6781 elsif Ekind
(Id
) in E_Incomplete_Type | E_Class_Wide_Type
6782 and then From_Limited_With
(Id
)
6783 and then Present
(Non_Limited_View
(Id
))
6784 and then Scope
(Non_Limited_View
(Id
)) = P_Name
6786 Candidate
:= Get_Full_View
(Non_Limited_View
(Id
));
6787 Is_New_Candidate
:= True;
6789 -- Handle special case where the prefix is a renaming of a shadow
6790 -- package which is visible. Required to avoid reporting spurious
6793 elsif Ekind
(P_Name
) = E_Package
6794 and then From_Limited_With
(P_Name
)
6795 and then not From_Limited_With
(Id
)
6796 and then Sloc
(Scope
(Id
)) = Sloc
(P_Name
)
6797 and then Unit_Is_Visible
(Cunit
(Get_Source_Unit
(P_Name
)))
6799 Candidate
:= Get_Full_View
(Id
);
6800 Is_New_Candidate
:= True;
6802 -- An unusual case arises with a fully qualified name for an
6803 -- entity local to a generic child unit package, within an
6804 -- instantiation of that package. The name of the unit now
6805 -- denotes the renaming created within the instance. This is
6806 -- only relevant in an instance body, see below.
6808 elsif Is_Generic_Instance
(Scope
(Id
))
6809 and then In_Open_Scopes
(Scope
(Id
))
6810 and then In_Instance_Body
6811 and then Ekind
(Scope
(Id
)) = E_Package
6812 and then Ekind
(Id
) = E_Package
6813 and then Renamed_Entity
(Id
) = Scope
(Id
)
6814 and then Is_Immediately_Visible
(P_Name
)
6816 Is_New_Candidate
:= True;
6819 Is_New_Candidate
:= False;
6822 if Is_New_Candidate
then
6824 -- If entity is a child unit, either it is a visible child of
6825 -- the prefix, or we are in the body of a generic prefix, as
6826 -- will happen when a child unit is instantiated in the body
6827 -- of a generic parent. This is because the instance body does
6828 -- not restore the full compilation context, given that all
6829 -- non-local references have been captured.
6831 if Is_Child_Unit
(Id
) or else P_Name
= Standard_Standard
then
6832 exit when Is_Visible_Lib_Unit
(Id
)
6833 or else (Is_Child_Unit
(Id
)
6834 and then In_Open_Scopes
(Scope
(Id
))
6835 and then In_Instance_Body
);
6837 exit when not Is_Hidden
(Id
);
6840 exit when Is_Immediately_Visible
(Id
);
6848 and then Ekind
(P_Name
) in E_Procedure | E_Function
6849 and then Is_Generic_Instance
(P_Name
)
6851 -- Expanded name denotes entity in (instance of) generic subprogram.
6852 -- The entity may be in the subprogram instance, or may denote one of
6853 -- the formals, which is declared in the enclosing wrapper package.
6855 P_Name
:= Scope
(P_Name
);
6857 Id
:= Current_Entity
(Selector
);
6858 while Present
(Id
) loop
6859 exit when Scope
(Id
) = P_Name
;
6864 if No
(Id
) or else Chars
(Id
) /= Chars
(Selector
) then
6865 Set_Etype
(N
, Any_Type
);
6867 -- If we are looking for an entity defined in System, try to find it
6868 -- in the child package that may have been provided as an extension
6869 -- to System. The Extend_System pragma will have supplied the name of
6870 -- the extension, which may have to be loaded.
6872 if Chars
(P_Name
) = Name_System
6873 and then Scope
(P_Name
) = Standard_Standard
6874 and then Present
(System_Extend_Unit
)
6875 and then Present_System_Aux
(N
)
6877 Set_Entity
(Prefix
(N
), System_Aux_Id
);
6878 Find_Expanded_Name
(N
);
6881 -- There is an implicit instance of the predefined operator in
6882 -- the given scope. The operator entity is defined in Standard.
6883 -- Has_Implicit_Operator makes the node into an Expanded_Name.
6885 elsif Nkind
(Selector
) = N_Operator_Symbol
6886 and then Has_Implicit_Operator
(N
)
6890 -- If there is no literal defined in the scope denoted by the
6891 -- prefix, the literal may belong to (a type derived from)
6892 -- Standard_Character, for which we have no explicit literals.
6894 elsif Nkind
(Selector
) = N_Character_Literal
6895 and then Has_Implicit_Character_Literal
(N
)
6900 -- If the prefix is a single concurrent object, use its name in
6901 -- the error message, rather than that of the anonymous type.
6903 if Is_Concurrent_Type
(P_Name
)
6904 and then Is_Internal_Name
(Chars
(P_Name
))
6906 Error_Msg_Node_2
:= Entity
(Prefix
(N
));
6908 Error_Msg_Node_2
:= P_Name
;
6911 if P_Name
= System_Aux_Id
then
6912 P_Name
:= Scope
(P_Name
);
6913 Set_Entity
(Prefix
(N
), P_Name
);
6916 if Present
(Candidate
) then
6918 -- If we know that the unit is a child unit we can give a more
6919 -- accurate error message.
6921 if Is_Child_Unit
(Candidate
) then
6923 -- If the candidate is a private child unit and we are in
6924 -- the visible part of a public unit, specialize the error
6925 -- message. There might be a private with_clause for it,
6926 -- but it is not currently active.
6928 if Is_Private_Descendant
(Candidate
)
6929 and then Ekind
(Current_Scope
) = E_Package
6930 and then not In_Private_Part
(Current_Scope
)
6931 and then not Is_Private_Descendant
(Current_Scope
)
6934 ("private child unit& is not visible here", Selector
);
6936 -- Normal case where we have a missing with for a child unit
6939 Error_Msg_Qual_Level
:= 99;
6940 Error_Msg_NE
-- CODEFIX
6941 ("missing `WITH &;`", Selector
, Candidate
);
6942 Error_Msg_Qual_Level
:= 0;
6945 -- Here we don't know that this is a child unit
6948 Error_Msg_NE
("& is not a visible entity of&", N
, Selector
);
6952 -- Within the instantiation of a child unit, the prefix may
6953 -- denote the parent instance, but the selector has the name
6954 -- of the original child. That is to say, when A.B appears
6955 -- within an instantiation of generic child unit B, the scope
6956 -- stack includes an instance of A (P_Name) and an instance
6957 -- of B under some other name. We scan the scope to find this
6958 -- child instance, which is the desired entity.
6959 -- Note that the parent may itself be a child instance, if
6960 -- the reference is of the form A.B.C, in which case A.B has
6961 -- already been rewritten with the proper entity.
6963 if In_Open_Scopes
(P_Name
)
6964 and then Is_Generic_Instance
(P_Name
)
6967 Gen_Par
: constant Entity_Id
:=
6968 Generic_Parent
(Specification
6969 (Unit_Declaration_Node
(P_Name
)));
6970 S
: Entity_Id
:= Current_Scope
;
6974 for J
in reverse 0 .. Scope_Stack
.Last
loop
6975 S
:= Scope_Stack
.Table
(J
).Entity
;
6977 exit when S
= Standard_Standard
;
6979 if Ekind
(S
) in E_Function | E_Package | E_Procedure
6982 Generic_Parent
(Specification
6983 (Unit_Declaration_Node
(S
)));
6985 -- Check that P is a generic child of the generic
6986 -- parent of the prefix.
6989 and then Chars
(P
) = Chars
(Selector
)
6990 and then Scope
(P
) = Gen_Par
7001 -- If this is a selection from Ada, System or Interfaces, then
7002 -- we assume a missing with for the corresponding package.
7004 if Is_Known_Unit
(N
)
7005 and then not (Present
(Entity
(Prefix
(N
)))
7006 and then Scope
(Entity
(Prefix
(N
))) /=
7009 if not Error_Posted
(N
) then
7011 ("& is not a visible entity of&", Prefix
(N
), Selector
);
7012 Error_Missing_With_Of_Known_Unit
(Prefix
(N
));
7015 -- If this is a selection from a dummy package, then suppress
7016 -- the error message, of course the entity is missing if the
7017 -- package is missing.
7019 elsif Sloc
(Error_Msg_Node_2
) = No_Location
then
7022 -- Here we have the case of an undefined component
7025 -- The prefix may hide a homonym in the context that
7026 -- declares the desired entity. This error can use a
7027 -- specialized message.
7029 if In_Open_Scopes
(P_Name
) then
7031 H
: constant Entity_Id
:= Homonym
(P_Name
);
7035 and then Is_Compilation_Unit
(H
)
7037 (Is_Immediately_Visible
(H
)
7038 or else Is_Visible_Lib_Unit
(H
))
7040 Id
:= First_Entity
(H
);
7041 while Present
(Id
) loop
7042 if Chars
(Id
) = Chars
(Selector
) then
7043 Error_Msg_Qual_Level
:= 99;
7044 Error_Msg_Name_1
:= Chars
(Selector
);
7046 ("% not declared in&", N
, P_Name
);
7048 ("\use fully qualified name starting with "
7049 & "Standard to make& visible", N
, H
);
7050 Error_Msg_Qual_Level
:= 0;
7058 -- If not found, standard error message
7060 Error_Msg_NE
("& not declared in&", N
, Selector
);
7066 -- Might be worth specializing the case when the prefix
7067 -- is a limited view.
7068 -- ... not declared in limited view of...
7070 Error_Msg_NE
("& not declared in&", N
, Selector
);
7073 -- Check for misspelling of some entity in prefix
7075 Id
:= First_Entity
(P_Name
);
7076 while Present
(Id
) loop
7077 if Is_Bad_Spelling_Of
(Chars
(Id
), Chars
(Selector
))
7078 and then not Is_Internal_Name
(Chars
(Id
))
7080 Error_Msg_NE
-- CODEFIX
7081 ("possible misspelling of&", Selector
, Id
);
7088 -- Specialize the message if this may be an instantiation
7089 -- of a child unit that was not mentioned in the context.
7091 if Nkind
(Parent
(N
)) = N_Package_Instantiation
7092 and then Is_Generic_Instance
(Entity
(Prefix
(N
)))
7093 and then Is_Compilation_Unit
7094 (Generic_Parent
(Parent
(Entity
(Prefix
(N
)))))
7096 Error_Msg_Node_2
:= Selector
;
7097 Error_Msg_N
-- CODEFIX
7098 ("\missing `WITH &.&;`", Prefix
(N
));
7108 if Comes_From_Source
(N
)
7109 and then Is_Remote_Access_To_Subprogram_Type
(Id
)
7110 and then Ekind
(Id
) = E_Access_Subprogram_Type
7111 and then Present
(Equivalent_Type
(Id
))
7113 -- If we are not actually generating distribution code (i.e. the
7114 -- current PCS is the dummy non-distributed version), then the
7115 -- Equivalent_Type will be missing, and Id should be treated as
7116 -- a regular access-to-subprogram type.
7118 Id
:= Equivalent_Type
(Id
);
7119 Set_Chars
(Selector
, Chars
(Id
));
7122 -- Ada 2005 (AI-50217): Check usage of entities in limited withed units
7124 if Ekind
(P_Name
) = E_Package
and then From_Limited_With
(P_Name
) then
7125 if From_Limited_With
(Id
)
7126 or else Is_Type
(Id
)
7127 or else Ekind
(Id
) = E_Package
7132 ("limited withed package can only be used to access incomplete "
7137 if Is_Task_Type
(P_Name
)
7138 and then ((Ekind
(Id
) = E_Entry
7139 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
)
7141 (Ekind
(Id
) = E_Entry_Family
7143 Nkind
(Parent
(Parent
(N
))) /= N_Attribute_Reference
))
7145 -- If both the task type and the entry are in scope, this may still
7146 -- be the expanded name of an entry formal.
7148 if In_Open_Scopes
(Id
)
7149 and then Nkind
(Parent
(N
)) = N_Selected_Component
7154 -- It is an entry call after all, either to the current task
7155 -- (which will deadlock) or to an enclosing task.
7157 Analyze_Selected_Component
(N
);
7163 when N_Selected_Component
=>
7164 Reinit_Field_To_Zero
(N
, F_Is_Prefixed_Call
);
7165 Change_Selected_Component_To_Expanded_Name
(N
);
7167 when N_Expanded_Name
=>
7171 pragma Assert
(False);
7174 -- Preserve relevant elaboration-related attributes of the context which
7175 -- are no longer available or very expensive to recompute once analysis,
7176 -- resolution, and expansion are over.
7178 Mark_Elaboration_Attributes
7184 -- Set appropriate type
7186 if Is_Type
(Id
) then
7189 Set_Etype
(N
, Get_Full_View
(Etype
(Id
)));
7192 -- Do style check and generate reference, but skip both steps if this
7193 -- entity has homonyms, since we may not have the right homonym set yet.
7194 -- The proper homonym will be set during the resolve phase.
7196 if Has_Homonym
(Id
) then
7200 Set_Entity_Or_Discriminal
(N
, Id
);
7202 case Known_To_Be_Assigned
(N
, Only_LHS
=> True) is
7204 Generate_Reference
(Id
, N
, 'm');
7207 Generate_Reference
(Id
, N
, 'r');
7212 -- Check for violation of No_Wide_Characters
7214 Check_Wide_Character_Restriction
(Id
, N
);
7216 if Is_Self_Hidden
(Id
) then
7217 Premature_Usage
(N
);
7219 elsif Is_Overloadable
(Id
) and then Present
(Homonym
(Id
)) then
7221 H
: Entity_Id
:= Homonym
(Id
);
7224 while Present
(H
) loop
7225 if Scope
(H
) = Scope
(Id
)
7226 and then (not Is_Hidden
(H
)
7227 or else Is_Immediately_Visible
(H
))
7229 Collect_Interps
(N
);
7236 -- If an extension of System is present, collect possible explicit
7237 -- overloadings declared in the extension.
7239 if Chars
(P_Name
) = Name_System
7240 and then Scope
(P_Name
) = Standard_Standard
7241 and then Present
(System_Extend_Unit
)
7242 and then Present_System_Aux
(N
)
7244 H
:= Current_Entity
(Id
);
7246 while Present
(H
) loop
7247 if Scope
(H
) = System_Aux_Id
then
7248 Add_One_Interp
(N
, H
, Etype
(H
));
7257 if Nkind
(Selector_Name
(N
)) = N_Operator_Symbol
7258 and then Scope
(Id
) /= Standard_Standard
7260 -- In addition to user-defined operators in the given scope, there
7261 -- may be an implicit instance of the predefined operator. The
7262 -- operator (defined in Standard) is found in Has_Implicit_Operator,
7263 -- and added to the interpretations. Procedure Add_One_Interp will
7264 -- determine which hides which.
7266 if Has_Implicit_Operator
(N
) then
7271 -- If there is a single interpretation for N we can generate a
7272 -- reference to the unique entity found.
7274 if Is_Overloadable
(Id
) and then not Is_Overloaded
(N
) then
7275 Generate_Reference
(Id
, N
);
7278 -- Mark relevant use-type and use-package clauses as effective if the
7279 -- node in question is not overloaded and therefore does not require
7282 if Nkind
(N
) not in N_Subexpr
or else not Is_Overloaded
(N
) then
7283 Mark_Use_Clauses
(N
);
7286 Check_Restriction_No_Use_Of_Entity
(N
);
7288 -- Annotate the tree by creating a variable reference marker in case the
7289 -- original variable reference is folded or optimized away. The variable
7290 -- reference marker is automatically saved for later examination by the
7291 -- ABE Processing phase. Variable references which act as actuals in a
7292 -- call require special processing and are left to Resolve_Actuals. The
7293 -- reference is a write when it appears on the left hand side of an
7296 if Needs_Variable_Reference_Marker
7301 Is_Assignment_LHS
: constant Boolean := Known_To_Be_Assigned
(N
);
7304 Build_Variable_Reference_Marker
7306 Read
=> not Is_Assignment_LHS
,
7307 Write
=> Is_Assignment_LHS
);
7310 end Find_Expanded_Name
;
7312 --------------------
7313 -- Find_First_Use --
7314 --------------------
7316 function Find_First_Use
(Use_Clause
: Node_Id
) return Node_Id
is
7320 -- Loop through the Prev_Use_Clause chain
7323 while Present
(Prev_Use_Clause
(Curr
)) loop
7324 Curr
:= Prev_Use_Clause
(Curr
);
7330 -------------------------
7331 -- Find_Renamed_Entity --
7332 -------------------------
7334 function Find_Renamed_Entity
7338 Is_Actual
: Boolean := False) return Entity_Id
7341 I1
: Interp_Index
:= 0; -- Suppress junk warnings
7347 function Find_Nearer_Entity
7350 Old2_S
: Entity_Id
) return Entity_Id
;
7351 -- Determine whether one of Old_S1 and Old_S2 is nearer to New_S than
7352 -- the other, and return it if so. Return Empty otherwise. We use this
7353 -- in conjunction with Inherit_Renamed_Profile to simplify later type
7354 -- disambiguation for actual subprograms in instances.
7356 function Is_Visible_Operation
(Op
: Entity_Id
) return Boolean;
7357 -- If the renamed entity is an implicit operator, check whether it is
7358 -- visible because its operand type is properly visible. This check
7359 -- applies to explicit renamed entities that appear in the source in a
7360 -- renaming declaration or a formal subprogram instance, but not to
7361 -- default generic actuals with a name.
7363 function Report_Overload
return Entity_Id
;
7364 -- List possible interpretations, and specialize message in the
7365 -- case of a generic actual.
7367 function Within
(Inner
, Outer
: Entity_Id
) return Boolean;
7368 -- Determine whether a candidate subprogram is defined within the
7369 -- enclosing instance. If yes, it has precedence over outer candidates.
7371 --------------------------
7372 -- Find_Nearer_Entity --
7373 --------------------------
7375 function Find_Nearer_Entity
7378 Old2_S
: Entity_Id
) return Entity_Id
7386 New_F
:= First_Formal
(New_S
);
7387 Old1_F
:= First_Formal
(Old1_S
);
7388 Old2_F
:= First_Formal
(Old2_S
);
7390 -- The criterion is whether the type of the formals of one of Old1_S
7391 -- and Old2_S is an ancestor subtype of the type of the corresponding
7392 -- formals of New_S while the other is not (we already know that they
7393 -- are all subtypes of the same base type).
7395 -- This makes it possible to find the more correct renamed entity in
7396 -- the case of a generic instantiation nested in an enclosing one for
7397 -- which different formal types get the same actual type, which will
7398 -- in turn make it possible for Inherit_Renamed_Profile to preserve
7399 -- types on formal parameters and ultimately simplify disambiguation.
7401 -- Consider the follow package G:
7404 -- type Item_T is private;
7405 -- with function Compare (L, R: Item_T) return Boolean is <>;
7407 -- type Bound_T is private;
7408 -- with function Compare (L, R : Bound_T) return Boolean is <>;
7413 -- package body G is
7414 -- package My_Inner is Inner_G (Bound_T);
7418 -- with the following package Inner_G:
7421 -- type T is private;
7422 -- with function Compare (L, R: T) return Boolean is <>;
7423 -- package Inner_G is
7424 -- function "<" (L, R: T) return Boolean is (Compare (L, R));
7427 -- If G is instantiated on the same actual type with a single Compare
7431 -- function Compare (L, R : T) return Boolean;
7432 -- package My_G is new (T, T);
7434 -- then the renaming generated for Compare in the inner instantiation
7435 -- is ambiguous: it can rename either of the renamings generated for
7436 -- the outer instantiation. Now if the first one is picked up, then
7437 -- the subtypes of the formal parameters of the renaming will not be
7438 -- preserved in Inherit_Renamed_Profile because they are subtypes of
7439 -- the Bound_T formal type and not of the Item_T formal type, so we
7440 -- need to arrange for the second one to be picked up instead.
7442 while Present
(New_F
) loop
7443 if Etype
(Old1_F
) /= Etype
(Old2_F
) then
7444 Anc_T
:= Ancestor_Subtype
(Etype
(New_F
));
7446 if Etype
(Old1_F
) = Anc_T
then
7448 elsif Etype
(Old2_F
) = Anc_T
then
7453 Next_Formal
(New_F
);
7454 Next_Formal
(Old1_F
);
7455 Next_Formal
(Old2_F
);
7458 pragma Assert
(No
(Old1_F
));
7459 pragma Assert
(No
(Old2_F
));
7462 end Find_Nearer_Entity
;
7464 --------------------------
7465 -- Is_Visible_Operation --
7466 --------------------------
7468 function Is_Visible_Operation
(Op
: Entity_Id
) return Boolean is
7474 if Ekind
(Op
) /= E_Operator
7475 or else Scope
(Op
) /= Standard_Standard
7476 or else (In_Instance
7477 and then (not Is_Actual
7478 or else Present
(Enclosing_Instance
)))
7483 -- For a fixed point type operator, check the resulting type,
7484 -- because it may be a mixed mode integer * fixed operation.
7486 if Present
(Next_Formal
(First_Formal
(New_S
)))
7487 and then Is_Fixed_Point_Type
(Etype
(New_S
))
7489 Typ
:= Etype
(New_S
);
7491 Typ
:= Etype
(First_Formal
(New_S
));
7494 Btyp
:= Base_Type
(Typ
);
7496 if Nkind
(Nam
) /= N_Expanded_Name
then
7497 return (In_Open_Scopes
(Scope
(Btyp
))
7498 or else Is_Potentially_Use_Visible
(Btyp
)
7499 or else In_Use
(Btyp
)
7500 or else In_Use
(Scope
(Btyp
)));
7503 Scop
:= Entity
(Prefix
(Nam
));
7505 if Ekind
(Scop
) = E_Package
7506 and then Present
(Renamed_Entity
(Scop
))
7508 Scop
:= Renamed_Entity
(Scop
);
7511 -- Operator is visible if prefix of expanded name denotes
7512 -- scope of type, or else type is defined in System_Aux
7513 -- and the prefix denotes System.
7515 return Scope
(Btyp
) = Scop
7516 or else (Scope
(Btyp
) = System_Aux_Id
7517 and then Scope
(Scope
(Btyp
)) = Scop
);
7520 end Is_Visible_Operation
;
7526 function Within
(Inner
, Outer
: Entity_Id
) return Boolean is
7530 Sc
:= Scope
(Inner
);
7531 while Sc
/= Standard_Standard
loop
7542 ---------------------
7543 -- Report_Overload --
7544 ---------------------
7546 function Report_Overload
return Entity_Id
is
7549 Error_Msg_NE
-- CODEFIX
7550 ("ambiguous actual subprogram&, " &
7551 "possible interpretations:", N
, Nam
);
7553 Error_Msg_N
-- CODEFIX
7554 ("ambiguous subprogram, " &
7555 "possible interpretations:", N
);
7558 List_Interps
(Nam
, N
);
7560 end Report_Overload
;
7562 -- Start of processing for Find_Renamed_Entity
7566 Candidate_Renaming
:= Empty
;
7568 if Is_Overloaded
(Nam
) then
7569 Get_First_Interp
(Nam
, Ind
, It
);
7570 while Present
(It
.Nam
) loop
7571 if Entity_Matches_Spec
(It
.Nam
, New_S
)
7572 and then Is_Visible_Operation
(It
.Nam
)
7574 if Old_S
/= Any_Id
then
7576 -- Note: The call to Disambiguate only happens if a
7577 -- previous interpretation was found, in which case I1
7578 -- has received a value.
7580 It1
:= Disambiguate
(Nam
, I1
, Ind
, Etype
(Old_S
));
7582 if It1
= No_Interp
then
7583 Inst
:= Enclosing_Instance
;
7585 if Present
(Inst
) then
7586 if Within
(It
.Nam
, Inst
) then
7587 if Within
(Old_S
, Inst
) then
7589 It_D
: constant Uint
:=
7590 Scope_Depth_Default_0
(It
.Nam
);
7591 Old_D
: constant Uint
:=
7592 Scope_Depth_Default_0
(Old_S
);
7595 -- Choose the innermost subprogram, which
7596 -- would hide the outer one in the generic.
7598 if Old_D
> It_D
then
7600 elsif It_D
> Old_D
then
7604 -- Otherwise, if we can determine that one
7605 -- of the entities is nearer to the renaming
7606 -- than the other, choose it. If not, then
7607 -- return the newer one as done historically.
7610 Find_Nearer_Entity
(New_S
, Old_S
, It
.Nam
);
7611 if Present
(N_Ent
) then
7619 elsif Within
(Old_S
, Inst
) then
7623 return Report_Overload
;
7626 -- If not within an instance, ambiguity is real
7629 return Report_Overload
;
7643 Present
(First_Formal
(It
.Nam
))
7644 and then Present
(First_Formal
(New_S
))
7645 and then Base_Type
(Etype
(First_Formal
(It
.Nam
))) =
7646 Base_Type
(Etype
(First_Formal
(New_S
)))
7648 Candidate_Renaming
:= It
.Nam
;
7651 Get_Next_Interp
(Ind
, It
);
7654 Set_Entity
(Nam
, Old_S
);
7656 if Old_S
/= Any_Id
then
7657 Set_Is_Overloaded
(Nam
, False);
7660 -- Non-overloaded case
7664 and then Present
(Enclosing_Instance
)
7665 and then Entity_Matches_Spec
(Entity
(Nam
), New_S
)
7667 Old_S
:= Entity
(Nam
);
7669 elsif Entity_Matches_Spec
(Entity
(Nam
), New_S
) then
7670 Candidate_Renaming
:= New_S
;
7672 if Is_Visible_Operation
(Entity
(Nam
)) then
7673 Old_S
:= Entity
(Nam
);
7676 elsif Present
(First_Formal
(Entity
(Nam
)))
7677 and then Present
(First_Formal
(New_S
))
7678 and then Base_Type
(Etype
(First_Formal
(Entity
(Nam
)))) =
7679 Base_Type
(Etype
(First_Formal
(New_S
)))
7681 Candidate_Renaming
:= Entity
(Nam
);
7686 end Find_Renamed_Entity
;
7688 -----------------------------
7689 -- Find_Selected_Component --
7690 -----------------------------
7692 procedure Find_Selected_Component
(N
: Node_Id
) is
7693 P
: constant Node_Id
:= Prefix
(N
);
7696 -- Entity denoted by prefix
7703 function Available_Subtype
return Boolean;
7704 -- A small optimization: if the prefix is constrained and the component
7705 -- is an array type we may already have a usable subtype for it, so we
7706 -- can use it rather than generating a new one, because the bounds
7707 -- will be the values of the discriminants and not discriminant refs.
7708 -- This simplifies value tracing in GNATprove. For consistency, both
7709 -- the entity name and the subtype come from the constrained component.
7711 -- This is only used in GNATprove mode: when generating code it may be
7712 -- necessary to create an itype in the scope of use of the selected
7713 -- component, e.g. in the context of a expanded record equality.
7715 function Is_Reference_In_Subunit
return Boolean;
7716 -- In a subunit, the scope depth is not a proper measure of hiding,
7717 -- because the context of the proper body may itself hide entities in
7718 -- parent units. This rare case requires inspecting the tree directly
7719 -- because the proper body is inserted in the main unit and its context
7720 -- is simply added to that of the parent.
7722 -----------------------
7723 -- Available_Subtype --
7724 -----------------------
7726 function Available_Subtype
return Boolean is
7730 if GNATprove_Mode
then
7731 Comp
:= First_Entity
(Etype
(P
));
7732 while Present
(Comp
) loop
7733 if Chars
(Comp
) = Chars
(Selector_Name
(N
)) then
7734 Set_Etype
(N
, Etype
(Comp
));
7735 Set_Entity
(Selector_Name
(N
), Comp
);
7736 Set_Etype
(Selector_Name
(N
), Etype
(Comp
));
7740 Next_Component
(Comp
);
7745 end Available_Subtype
;
7747 -----------------------------
7748 -- Is_Reference_In_Subunit --
7749 -----------------------------
7751 function Is_Reference_In_Subunit
return Boolean is
7753 Comp_Unit
: Node_Id
;
7757 while Present
(Comp_Unit
)
7758 and then Nkind
(Comp_Unit
) /= N_Compilation_Unit
7760 Comp_Unit
:= Parent
(Comp_Unit
);
7763 if No
(Comp_Unit
) or else Nkind
(Unit
(Comp_Unit
)) /= N_Subunit
then
7767 -- Now check whether the package is in the context of the subunit
7769 Clause
:= First
(Context_Items
(Comp_Unit
));
7770 while Present
(Clause
) loop
7771 if Nkind
(Clause
) = N_With_Clause
7772 and then Entity
(Name
(Clause
)) = P_Name
7781 end Is_Reference_In_Subunit
;
7783 -- Start of processing for Find_Selected_Component
7788 if Nkind
(P
) = N_Error
then
7792 -- If the selector already has an entity, the node has been constructed
7793 -- in the course of expansion, and is known to be valid. Do not verify
7794 -- that it is defined for the type (it may be a private component used
7795 -- in the expansion of record equality).
7797 if Present
(Entity
(Selector_Name
(N
))) then
7798 if No
(Etype
(N
)) or else Etype
(N
) = Any_Type
then
7800 Sel_Name
: constant Node_Id
:= Selector_Name
(N
);
7801 Selector
: constant Entity_Id
:= Entity
(Sel_Name
);
7805 Set_Etype
(Sel_Name
, Etype
(Selector
));
7807 if not Is_Entity_Name
(P
) then
7811 -- Build an actual subtype except for the first parameter
7812 -- of an init proc, where this actual subtype is by
7813 -- definition incorrect, since the object is uninitialized
7814 -- (and does not even have defined discriminants etc.)
7816 if Is_Entity_Name
(P
)
7817 and then Ekind
(Entity
(P
)) = E_Function
7819 Nam
:= New_Copy
(P
);
7821 if Is_Overloaded
(P
) then
7822 Save_Interps
(P
, Nam
);
7825 Rewrite
(P
, Make_Function_Call
(Sloc
(P
), Name
=> Nam
));
7827 Analyze_Selected_Component
(N
);
7830 elsif Ekind
(Selector
) = E_Component
7831 and then (not Is_Entity_Name
(P
)
7832 or else Chars
(Entity
(P
)) /= Name_uInit
)
7834 -- Check if we already have an available subtype we can use
7836 if Ekind
(Etype
(P
)) = E_Record_Subtype
7837 and then Nkind
(Parent
(Etype
(P
))) = N_Subtype_Declaration
7838 and then Is_Array_Type
(Etype
(Selector
))
7839 and then not Is_Packed
(Etype
(Selector
))
7840 and then Available_Subtype
7844 -- Do not build the subtype when referencing components of
7845 -- dispatch table wrappers. Required to avoid generating
7846 -- elaboration code with HI runtimes.
7848 elsif Is_RTE
(Scope
(Selector
), RE_Dispatch_Table_Wrapper
)
7850 Is_RTE
(Scope
(Selector
), RE_No_Dispatch_Table_Wrapper
)
7855 Build_Actual_Subtype_Of_Component
7856 (Etype
(Selector
), N
);
7863 if No
(C_Etype
) then
7864 C_Etype
:= Etype
(Selector
);
7866 Insert_Action
(N
, C_Etype
);
7867 C_Etype
:= Defining_Identifier
(C_Etype
);
7870 Set_Etype
(N
, C_Etype
);
7873 -- If the selected component appears within a default expression
7874 -- and it has an actual subtype, the preanalysis has not yet
7875 -- completed its analysis, because Insert_Actions is disabled in
7876 -- that context. Within the init proc of the enclosing type we
7877 -- must complete this analysis, if an actual subtype was created.
7879 elsif Inside_Init_Proc
then
7881 Typ
: constant Entity_Id
:= Etype
(N
);
7882 Decl
: constant Node_Id
:= Declaration_Node
(Typ
);
7884 if Nkind
(Decl
) = N_Subtype_Declaration
7885 and then not Analyzed
(Decl
)
7886 and then Is_List_Member
(Decl
)
7887 and then No
(Parent
(Decl
))
7890 Insert_Action
(N
, Decl
);
7897 elsif Is_Entity_Name
(P
) then
7898 P_Name
:= Entity
(P
);
7900 -- The prefix may denote an enclosing type which is the completion
7901 -- of an incomplete type declaration.
7903 if Is_Type
(P_Name
) then
7904 Set_Entity
(P
, Get_Full_View
(P_Name
));
7905 Set_Etype
(P
, Entity
(P
));
7906 P_Name
:= Entity
(P
);
7909 P_Type
:= Base_Type
(Etype
(P
));
7911 if Debug_Flag_E
then
7912 Write_Str
("Found prefix type to be ");
7913 Write_Entity_Info
(P_Type
, " "); Write_Eol
;
7916 -- If the prefix's type is an access type, get to the record type
7918 if Is_Access_Type
(P_Type
) then
7919 P_Type
:= Implicitly_Designated_Type
(P_Type
);
7922 -- First check for components of a record object (not the result of
7923 -- a call, which is handled below). This also covers the case where
7924 -- the extension feature that supports the prefixed form of calls
7925 -- for primitives of untagged types is enabled (excluding concurrent
7926 -- cases, which are handled further below).
7929 and then (Has_Components
(P_Type
)
7930 or else (Core_Extensions_Allowed
7931 and then not Is_Concurrent_Type
(P_Type
)))
7932 and then not Is_Overloadable
(P_Name
)
7933 and then not Is_Type
(P_Name
)
7935 -- Selected component of record. Type checking will validate
7936 -- name of selector.
7938 -- ??? Could we rewrite an implicit dereference into an explicit
7941 Analyze_Selected_Component
(N
);
7943 -- Reference to type name in predicate/invariant expression
7945 elsif Is_Concurrent_Type
(P_Type
)
7946 and then not In_Open_Scopes
(P_Name
)
7947 and then (not Is_Concurrent_Type
(Etype
(P_Name
))
7948 or else not In_Open_Scopes
(Etype
(P_Name
)))
7950 -- Call to protected operation or entry. Type checking is
7951 -- needed on the prefix.
7953 Analyze_Selected_Component
(N
);
7955 elsif (In_Open_Scopes
(P_Name
)
7956 and then Ekind
(P_Name
) /= E_Void
7957 and then not Is_Overloadable
(P_Name
))
7958 or else (Is_Concurrent_Type
(Etype
(P_Name
))
7959 and then In_Open_Scopes
(Etype
(P_Name
)))
7961 -- Prefix denotes an enclosing loop, block, or task, i.e. an
7962 -- enclosing construct that is not a subprogram or accept.
7964 -- A special case: a protected body may call an operation
7965 -- on an external object of the same type, in which case it
7966 -- is not an expanded name. If the prefix is the type itself,
7967 -- or the context is a single synchronized object it can only
7968 -- be interpreted as an expanded name.
7970 if Is_Concurrent_Type
(Etype
(P_Name
)) then
7972 or else Present
(Anonymous_Object
(Etype
(P_Name
)))
7974 Find_Expanded_Name
(N
);
7977 Analyze_Selected_Component
(N
);
7982 Find_Expanded_Name
(N
);
7985 elsif Ekind
(P_Name
) = E_Package
then
7986 Find_Expanded_Name
(N
);
7988 elsif Is_Overloadable
(P_Name
) then
7990 -- The subprogram may be a renaming (of an enclosing scope) as
7991 -- in the case of the name of the generic within an instantiation.
7993 if Ekind
(P_Name
) in E_Procedure | E_Function
7994 and then Present
(Alias
(P_Name
))
7995 and then Is_Generic_Instance
(Alias
(P_Name
))
7997 P_Name
:= Alias
(P_Name
);
8000 if Is_Overloaded
(P
) then
8002 -- The prefix must resolve to a unique enclosing construct
8005 Found
: Boolean := False;
8010 Get_First_Interp
(P
, Ind
, It
);
8011 while Present
(It
.Nam
) loop
8012 if In_Open_Scopes
(It
.Nam
) then
8015 "prefix must be unique enclosing scope", N
);
8016 Set_Entity
(N
, Any_Id
);
8017 Set_Etype
(N
, Any_Type
);
8026 Get_Next_Interp
(Ind
, It
);
8031 if In_Open_Scopes
(P_Name
) then
8032 Set_Entity
(P
, P_Name
);
8033 Set_Is_Overloaded
(P
, False);
8034 Find_Expanded_Name
(N
);
8037 -- If no interpretation as an expanded name is possible, it
8038 -- must be a selected component of a record returned by a
8039 -- function call. Reformat prefix as a function call, the rest
8040 -- is done by type resolution.
8042 -- Error if the prefix is procedure or entry, as is P.X
8044 if Ekind
(P_Name
) /= E_Function
8046 (not Is_Overloaded
(P
)
8047 or else Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
)
8049 -- Prefix may mention a package that is hidden by a local
8050 -- declaration: let the user know. Scan the full homonym
8051 -- chain, the candidate package may be anywhere on it.
8053 if Present
(Homonym
(Current_Entity
(P_Name
))) then
8054 P_Name
:= Current_Entity
(P_Name
);
8056 while Present
(P_Name
) loop
8057 exit when Ekind
(P_Name
) = E_Package
;
8058 P_Name
:= Homonym
(P_Name
);
8061 if Present
(P_Name
) then
8062 if not Is_Reference_In_Subunit
then
8063 Error_Msg_Sloc
:= Sloc
(Entity
(Prefix
(N
)));
8065 ("package& is hidden by declaration#", N
, P_Name
);
8068 Set_Entity
(Prefix
(N
), P_Name
);
8069 Find_Expanded_Name
(N
);
8073 P_Name
:= Entity
(Prefix
(N
));
8078 ("invalid prefix in selected component&", N
, P_Name
);
8079 Change_Selected_Component_To_Expanded_Name
(N
);
8080 Set_Entity
(N
, Any_Id
);
8081 Set_Etype
(N
, Any_Type
);
8083 -- Here we have a function call, so do the reformatting
8086 Nam
:= New_Copy
(P
);
8087 Save_Interps
(P
, Nam
);
8089 -- We use Replace here because this is one of those cases
8090 -- where the parser has missclassified the node, and we fix
8091 -- things up and then do the semantic analysis on the fixed
8092 -- up node. Normally we do this using one of the Sinfo.CN
8093 -- routines, but this is too tricky for that.
8095 -- Note that using Rewrite would be wrong, because we would
8096 -- have a tree where the original node is unanalyzed.
8099 Make_Function_Call
(Sloc
(P
), Name
=> Nam
));
8101 -- Now analyze the reformatted node
8105 -- If the prefix is illegal after this transformation, there
8106 -- may be visibility errors on the prefix. The safest is to
8107 -- treat the selected component as an error.
8109 if Error_Posted
(P
) then
8110 Set_Etype
(N
, Any_Type
);
8114 Analyze_Selected_Component
(N
);
8119 -- Remaining cases generate various error messages
8122 -- Format node as expanded name, to avoid cascaded errors
8124 Change_Selected_Component_To_Expanded_Name
(N
);
8125 Set_Entity
(N
, Any_Id
);
8126 Set_Etype
(N
, Any_Type
);
8128 -- Issue error message, but avoid this if error issued already.
8129 -- Use identifier of prefix if one is available.
8131 if P_Name
= Any_Id
then
8134 -- It is not an error if the prefix is the current instance of
8135 -- type name, e.g. the expression of a type aspect, when it is
8136 -- analyzed within a generic unit. We still have to verify that a
8137 -- component of that name exists, and decorate the node
8140 elsif Is_Entity_Name
(P
) and then Is_Current_Instance
(P
) then
8145 Comp
:= First_Entity
(Entity
(P
));
8146 while Present
(Comp
) loop
8147 if Chars
(Comp
) = Chars
(Selector_Name
(N
)) then
8148 Set_Entity
(N
, Comp
);
8149 Set_Etype
(N
, Etype
(Comp
));
8150 Set_Entity
(Selector_Name
(N
), Comp
);
8151 Set_Etype
(Selector_Name
(N
), Etype
(Comp
));
8159 elsif Is_Self_Hidden
(P_Name
) then
8160 Premature_Usage
(P
);
8162 elsif Ekind
(P_Name
) = E_Generic_Package
then
8163 Error_Msg_N
("prefix must not be a generic package", N
);
8164 Error_Msg_N
("\use package instantiation as prefix instead", N
);
8166 elsif Nkind
(P
) /= N_Attribute_Reference
then
8168 -- This may have been meant as a prefixed call to a primitive
8169 -- of an untagged type. If it is a function call check type of
8170 -- its first formal and add explanation.
8173 F
: constant Entity_Id
:=
8174 Current_Entity
(Selector_Name
(N
));
8177 and then Is_Overloadable
(F
)
8178 and then Present
(First_Entity
(F
))
8179 and then not Is_Tagged_Type
(Etype
(First_Entity
(F
)))
8182 ("prefixed call is only allowed for objects of a "
8183 & "tagged type unless -gnatX is used", N
);
8185 if not Core_Extensions_Allowed
8187 Try_Object_Operation
(N
, Allow_Extensions
=> True)
8190 ("\using -gnatX would make the prefixed call legal",
8196 Error_Msg_N
("invalid prefix in selected component&", P
);
8198 if Is_Incomplete_Type
(P_Type
)
8199 and then Is_Access_Type
(Etype
(P
))
8202 ("\dereference must not be of an incomplete type "
8203 & "(RM 3.10.1)", P
);
8207 Error_Msg_N
("invalid prefix in selected component", P
);
8211 -- If prefix is not the name of an entity, it must be an expression,
8212 -- whose type is appropriate for a record. This is determined by
8215 Analyze_Selected_Component
(N
);
8218 Analyze_Dimension
(N
);
8219 end Find_Selected_Component
;
8225 procedure Find_Type
(N
: Node_Id
) is
8235 elsif Nkind
(N
) = N_Attribute_Reference
then
8237 -- Class attribute. This is not valid in Ada 83 mode, but we do not
8238 -- need to enforce that at this point, since the declaration of the
8239 -- tagged type in the prefix would have been flagged already.
8241 if Attribute_Name
(N
) = Name_Class
then
8242 Check_Restriction
(No_Dispatch
, N
);
8243 Find_Type
(Prefix
(N
));
8245 -- Propagate error from bad prefix
8247 if Etype
(Prefix
(N
)) = Any_Type
then
8248 Set_Entity
(N
, Any_Type
);
8249 Set_Etype
(N
, Any_Type
);
8253 T
:= Base_Type
(Entity
(Prefix
(N
)));
8255 -- Case where type is not known to be tagged. Its appearance in
8256 -- the prefix of the 'Class attribute indicates that the full view
8259 if not Is_Tagged_Type
(T
) then
8260 if Ekind
(T
) = E_Incomplete_Type
then
8262 -- It is legal to denote the class type of an incomplete
8263 -- type. The full type will have to be tagged, of course.
8264 -- In Ada 2005 this usage is declared obsolescent, so we
8265 -- warn accordingly. This usage is only legal if the type
8266 -- is completed in the current scope, and not for a limited
8269 if Ada_Version
>= Ada_2005
then
8271 -- Test whether the Available_View of a limited type view
8272 -- is tagged, since the limited view may not be marked as
8273 -- tagged if the type itself has an untagged incomplete
8274 -- type view in its package.
8276 if From_Limited_With
(T
)
8277 and then not Is_Tagged_Type
(Available_View
(T
))
8280 ("prefix of Class attribute must be tagged", N
);
8281 Set_Etype
(N
, Any_Type
);
8282 Set_Entity
(N
, Any_Type
);
8286 if Restriction_Check_Required
(No_Obsolescent_Features
)
8289 (No_Obsolescent_Features
, Prefix
(N
));
8292 if Warn_On_Obsolescent_Feature
then
8294 ("applying ''Class to an untagged incomplete type"
8295 & " is an obsolescent feature (RM J.11)?r?", N
);
8300 Set_Is_Tagged_Type
(T
);
8301 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
8302 Make_Class_Wide_Type
(T
);
8303 Set_Entity
(N
, Class_Wide_Type
(T
));
8304 Set_Etype
(N
, Class_Wide_Type
(T
));
8306 elsif Ekind
(T
) = E_Private_Type
8307 and then not Is_Generic_Type
(T
)
8308 and then In_Private_Part
(Scope
(T
))
8310 -- The Class attribute can be applied to an untagged private
8311 -- type fulfilled by a tagged type prior to the full type
8312 -- declaration (but only within the parent package's private
8313 -- part). Create the class-wide type now and check that the
8314 -- full type is tagged later during its analysis. Note that
8315 -- we do not mark the private type as tagged, unlike the
8316 -- case of incomplete types, because the type must still
8317 -- appear untagged to outside units.
8319 if No
(Class_Wide_Type
(T
)) then
8320 Make_Class_Wide_Type
(T
);
8323 Set_Entity
(N
, Class_Wide_Type
(T
));
8324 Set_Etype
(N
, Class_Wide_Type
(T
));
8327 -- Should we introduce a type Any_Tagged and use Wrong_Type
8328 -- here, it would be a bit more consistent???
8331 ("tagged type required, found}",
8332 Prefix
(N
), First_Subtype
(T
));
8333 Set_Entity
(N
, Any_Type
);
8337 -- Case of tagged type
8340 if Is_Concurrent_Type
(T
) then
8341 if No
(Corresponding_Record_Type
(Entity
(Prefix
(N
)))) then
8343 -- Previous error. Create a class-wide type for the
8344 -- synchronized type itself, with minimal semantic
8345 -- attributes, to catch other errors in some ACATS tests.
8347 pragma Assert
(Serious_Errors_Detected
/= 0);
8348 Make_Class_Wide_Type
(T
);
8349 C
:= Class_Wide_Type
(T
);
8350 Set_First_Entity
(C
, First_Entity
(T
));
8353 C
:= Class_Wide_Type
8354 (Corresponding_Record_Type
(Entity
(Prefix
(N
))));
8358 C
:= Class_Wide_Type
(Entity
(Prefix
(N
)));
8361 Set_Entity_With_Checks
(N
, C
);
8362 Generate_Reference
(C
, N
);
8366 -- Base attribute, not allowed in Ada 83
8368 elsif Attribute_Name
(N
) = Name_Base
then
8369 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
8371 ("(Ada 83) Base attribute not allowed in subtype mark", N
);
8374 Find_Type
(Prefix
(N
));
8375 Typ
:= Entity
(Prefix
(N
));
8377 if Ada_Version
>= Ada_95
8378 and then not Is_Scalar_Type
(Typ
)
8379 and then not Is_Generic_Type
(Typ
)
8382 ("prefix of Base attribute must be scalar type",
8385 elsif Warn_On_Redundant_Constructs
8386 and then Base_Type
(Typ
) = Typ
8388 Error_Msg_NE
-- CODEFIX
8389 ("redundant attribute, & is its own base type?r?", N
, Typ
);
8392 T
:= Base_Type
(Typ
);
8394 -- Rewrite attribute reference with type itself (see similar
8395 -- processing in Analyze_Attribute, case Base). Preserve prefix
8396 -- if present, for other legality checks.
8398 if Nkind
(Prefix
(N
)) = N_Expanded_Name
then
8400 Make_Expanded_Name
(Sloc
(N
),
8402 Prefix
=> New_Copy
(Prefix
(Prefix
(N
))),
8403 Selector_Name
=> New_Occurrence_Of
(T
, Sloc
(N
))));
8406 Rewrite
(N
, New_Occurrence_Of
(T
, Sloc
(N
)));
8413 elsif Attribute_Name
(N
) = Name_Stub_Type
then
8415 -- This is handled in Analyze_Attribute
8419 -- All other attributes are invalid in a subtype mark
8422 Error_Msg_N
("invalid attribute in subtype mark", N
);
8428 if Is_Entity_Name
(N
) then
8429 T_Name
:= Entity
(N
);
8431 Error_Msg_N
("subtype mark required in this context", N
);
8432 Set_Etype
(N
, Any_Type
);
8436 if T_Name
= Any_Id
or else Etype
(N
) = Any_Type
then
8438 -- Undefined id. Make it into a valid type
8440 Set_Entity
(N
, Any_Type
);
8442 elsif not Is_Type
(T_Name
)
8443 and then T_Name
/= Standard_Void_Type
8445 Error_Msg_Sloc
:= Sloc
(T_Name
);
8446 Error_Msg_N
("subtype mark required in this context", N
);
8447 Error_Msg_NE
("\\found & declared#", N
, T_Name
);
8448 Set_Entity
(N
, Any_Type
);
8451 -- If the type is an incomplete type created to handle
8452 -- anonymous access components of a record type, then the
8453 -- incomplete type is the visible entity and subsequent
8454 -- references will point to it. Mark the original full
8455 -- type as referenced, to prevent spurious warnings.
8457 if Is_Incomplete_Type
(T_Name
)
8458 and then Present
(Full_View
(T_Name
))
8459 and then not Comes_From_Source
(T_Name
)
8461 Set_Referenced
(Full_View
(T_Name
));
8464 T_Name
:= Get_Full_View
(T_Name
);
8466 -- Ada 2005 (AI-251, AI-50217): Handle interfaces visible through
8467 -- limited-with clauses
8469 if From_Limited_With
(T_Name
)
8470 and then Is_Incomplete_Type
(T_Name
)
8471 and then Present
(Non_Limited_View
(T_Name
))
8472 and then Is_Interface
(Non_Limited_View
(T_Name
))
8474 T_Name
:= Non_Limited_View
(T_Name
);
8477 if In_Open_Scopes
(T_Name
) then
8478 if Ekind
(Base_Type
(T_Name
)) = E_Task_Type
then
8480 -- In Ada 2005, a task name can be used in an access
8481 -- definition within its own body.
8483 if Ada_Version
>= Ada_2005
8484 and then Nkind
(Parent
(N
)) = N_Access_Definition
8486 Set_Entity
(N
, T_Name
);
8487 Set_Etype
(N
, T_Name
);
8492 ("task type cannot be used as type mark " &
8493 "within its own spec or body", N
);
8496 elsif Ekind
(Base_Type
(T_Name
)) = E_Protected_Type
then
8498 -- In Ada 2005, a protected name can be used in an access
8499 -- definition within its own body.
8501 if Ada_Version
>= Ada_2005
8502 and then Nkind
(Parent
(N
)) = N_Access_Definition
8504 Set_Entity
(N
, T_Name
);
8505 Set_Etype
(N
, T_Name
);
8510 ("protected type cannot be used as type mark " &
8511 "within its own spec or body", N
);
8515 Error_Msg_N
("type declaration cannot refer to itself", N
);
8518 Set_Etype
(N
, Any_Type
);
8519 Set_Entity
(N
, Any_Type
);
8520 Set_Error_Posted
(T_Name
);
8524 Set_Entity
(N
, T_Name
);
8525 Set_Etype
(N
, T_Name
);
8529 if Present
(Etype
(N
)) and then Comes_From_Source
(N
) then
8530 if Is_Fixed_Point_Type
(Etype
(N
)) then
8531 Check_Restriction
(No_Fixed_Point
, N
);
8532 elsif Is_Floating_Point_Type
(Etype
(N
)) then
8533 Check_Restriction
(No_Floating_Point
, N
);
8536 -- A Ghost type must appear in a specific context
8538 if Is_Ghost_Entity
(Etype
(N
)) then
8539 Check_Ghost_Context
(Etype
(N
), N
);
8544 --------------------
8545 -- Has_Components --
8546 --------------------
8548 function Has_Components
(Typ
: Entity_Id
) return Boolean is
8550 return Is_Record_Type
(Typ
)
8551 or else (Is_Private_Type
(Typ
) and then Has_Discriminants
(Typ
))
8552 or else (Is_Task_Type
(Typ
) and then Has_Discriminants
(Typ
))
8553 or else (Is_Incomplete_Type
(Typ
)
8554 and then From_Limited_With
(Typ
)
8555 and then Is_Record_Type
(Available_View
(Typ
)));
8558 ------------------------------------
8559 -- Has_Implicit_Character_Literal --
8560 ------------------------------------
8562 function Has_Implicit_Character_Literal
(N
: Node_Id
) return Boolean is
8564 Found
: Boolean := False;
8565 P
: constant Entity_Id
:= Entity
(Prefix
(N
));
8566 Priv_Id
: Entity_Id
:= Empty
;
8569 if Ekind
(P
) = E_Package
and then not In_Open_Scopes
(P
) then
8570 Priv_Id
:= First_Private_Entity
(P
);
8573 if P
= Standard_Standard
then
8574 Change_Selected_Component_To_Expanded_Name
(N
);
8575 Rewrite
(N
, Selector_Name
(N
));
8577 Set_Etype
(Original_Node
(N
), Standard_Character
);
8581 Id
:= First_Entity
(P
);
8582 while Present
(Id
) and then Id
/= Priv_Id
loop
8583 if Is_Standard_Character_Type
(Id
) and then Is_Base_Type
(Id
) then
8585 -- We replace the node with the literal itself, resolve as a
8586 -- character, and set the type correctly.
8589 Change_Selected_Component_To_Expanded_Name
(N
);
8590 Rewrite
(N
, Selector_Name
(N
));
8593 Set_Etype
(Original_Node
(N
), Id
);
8597 -- More than one type derived from Character in given scope.
8598 -- Collect all possible interpretations.
8600 Add_One_Interp
(N
, Id
, Id
);
8608 end Has_Implicit_Character_Literal
;
8610 ----------------------
8611 -- Has_Private_With --
8612 ----------------------
8614 function Has_Private_With
(E
: Entity_Id
) return Boolean is
8615 Comp_Unit
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
8619 Item
:= First
(Context_Items
(Comp_Unit
));
8620 while Present
(Item
) loop
8621 if Nkind
(Item
) = N_With_Clause
8622 and then Private_Present
(Item
)
8623 and then Entity
(Name
(Item
)) = E
8632 end Has_Private_With
;
8634 ---------------------------
8635 -- Has_Implicit_Operator --
8636 ---------------------------
8638 function Has_Implicit_Operator
(N
: Node_Id
) return Boolean is
8639 Op_Id
: constant Name_Id
:= Chars
(Selector_Name
(N
));
8640 P
: constant Entity_Id
:= Entity
(Prefix
(N
));
8642 Priv_Id
: Entity_Id
:= Empty
;
8644 procedure Add_Implicit_Operator
8646 Op_Type
: Entity_Id
:= Empty
);
8647 -- Add implicit interpretation to node N, using the type for which a
8648 -- predefined operator exists. If the operator yields a boolean type,
8649 -- the Operand_Type is implicitly referenced by the operator, and a
8650 -- reference to it must be generated.
8652 ---------------------------
8653 -- Add_Implicit_Operator --
8654 ---------------------------
8656 procedure Add_Implicit_Operator
8658 Op_Type
: Entity_Id
:= Empty
)
8660 Predef_Op
: Entity_Id
;
8663 Predef_Op
:= Current_Entity
(Selector_Name
(N
));
8664 while Present
(Predef_Op
)
8665 and then Scope
(Predef_Op
) /= Standard_Standard
8667 Predef_Op
:= Homonym
(Predef_Op
);
8670 if Nkind
(N
) = N_Selected_Component
then
8671 Change_Selected_Component_To_Expanded_Name
(N
);
8674 -- If the context is an unanalyzed function call, determine whether
8675 -- a binary or unary interpretation is required.
8677 if Nkind
(Parent
(N
)) = N_Indexed_Component
then
8679 Is_Binary_Call
: constant Boolean :=
8681 (Next
(First
(Expressions
(Parent
(N
)))));
8682 Is_Binary_Op
: constant Boolean :=
8684 (Predef_Op
) /= Last_Entity
(Predef_Op
);
8685 Predef_Op2
: constant Entity_Id
:= Homonym
(Predef_Op
);
8688 if Is_Binary_Call
then
8689 if Is_Binary_Op
then
8690 Add_One_Interp
(N
, Predef_Op
, T
);
8692 Add_One_Interp
(N
, Predef_Op2
, T
);
8695 if not Is_Binary_Op
then
8696 Add_One_Interp
(N
, Predef_Op
, T
);
8698 -- Predef_Op2 may be empty in case of previous errors
8700 elsif Present
(Predef_Op2
) then
8701 Add_One_Interp
(N
, Predef_Op2
, T
);
8707 Add_One_Interp
(N
, Predef_Op
, T
);
8709 -- For operators with unary and binary interpretations, if
8710 -- context is not a call, add both
8712 if Present
(Homonym
(Predef_Op
)) then
8713 Add_One_Interp
(N
, Homonym
(Predef_Op
), T
);
8717 -- The node is a reference to a predefined operator, and
8718 -- an implicit reference to the type of its operands.
8720 if Present
(Op_Type
) then
8721 Generate_Operator_Reference
(N
, Op_Type
);
8723 Generate_Operator_Reference
(N
, T
);
8725 end Add_Implicit_Operator
;
8727 -- Start of processing for Has_Implicit_Operator
8730 if Ekind
(P
) = E_Package
and then not In_Open_Scopes
(P
) then
8731 Priv_Id
:= First_Private_Entity
(P
);
8734 Id
:= First_Entity
(P
);
8738 -- Boolean operators: an implicit declaration exists if the scope
8739 -- contains a declaration for a derived Boolean type, or for an
8740 -- array of Boolean type.
8747 while Id
/= Priv_Id
loop
8749 and then Valid_Boolean_Arg
(Id
)
8750 and then Is_Base_Type
(Id
)
8752 Add_Implicit_Operator
(Id
);
8759 -- Equality: look for any non-limited type (result is Boolean)
8764 while Id
/= Priv_Id
loop
8766 and then Valid_Equality_Arg
(Id
)
8767 and then Is_Base_Type
(Id
)
8769 Add_Implicit_Operator
(Standard_Boolean
, Id
);
8776 -- Comparison operators: scalar type, or array of scalar
8783 while Id
/= Priv_Id
loop
8785 and then Valid_Comparison_Arg
(Id
)
8786 and then Is_Base_Type
(Id
)
8788 Add_Implicit_Operator
(Standard_Boolean
, Id
);
8795 -- Arithmetic operators: any numeric type
8806 while Id
/= Priv_Id
loop
8807 if Is_Numeric_Type
(Id
) and then Is_Base_Type
(Id
) then
8808 Add_Implicit_Operator
(Id
);
8815 -- Concatenation: any one-dimensional array type
8817 when Name_Op_Concat
=>
8818 while Id
/= Priv_Id
loop
8819 if Is_Array_Type
(Id
)
8820 and then Number_Dimensions
(Id
) = 1
8821 and then Is_Base_Type
(Id
)
8823 Add_Implicit_Operator
(Id
);
8830 -- What is the others condition here? Should we be using a
8831 -- subtype of Name_Id that would restrict to operators ???
8837 -- If we fall through, then we do not have an implicit operator
8840 end Has_Implicit_Operator
;
8842 -----------------------------------
8843 -- Has_Loop_In_Inner_Open_Scopes --
8844 -----------------------------------
8846 function Has_Loop_In_Inner_Open_Scopes
(S
: Entity_Id
) return Boolean is
8848 -- Several scope stacks are maintained by Scope_Stack. The base of the
8849 -- currently active scope stack is denoted by the Is_Active_Stack_Base
8850 -- flag in the scope stack entry. Note that the scope stacks used to
8851 -- simply be delimited implicitly by the presence of Standard_Standard
8852 -- at their base, but there now are cases where this is not sufficient
8853 -- because Standard_Standard actually may appear in the middle of the
8854 -- active set of scopes.
8856 for J
in reverse 0 .. Scope_Stack
.Last
loop
8858 -- S was reached without seing a loop scope first
8860 if Scope_Stack
.Table
(J
).Entity
= S
then
8863 -- S was not yet reached, so it contains at least one inner loop
8865 elsif Ekind
(Scope_Stack
.Table
(J
).Entity
) = E_Loop
then
8869 -- Check Is_Active_Stack_Base to tell us when to stop, as there are
8870 -- cases where Standard_Standard appears in the middle of the active
8871 -- set of scopes. This affects the declaration and overriding of
8872 -- private inherited operations in instantiations of generic child
8875 pragma Assert
(not Scope_Stack
.Table
(J
).Is_Active_Stack_Base
);
8878 raise Program_Error
; -- unreachable
8879 end Has_Loop_In_Inner_Open_Scopes
;
8881 --------------------
8882 -- In_Open_Scopes --
8883 --------------------
8885 function In_Open_Scopes
(S
: Entity_Id
) return Boolean is
8887 -- Several scope stacks are maintained by Scope_Stack. The base of the
8888 -- currently active scope stack is denoted by the Is_Active_Stack_Base
8889 -- flag in the scope stack entry. Note that the scope stacks used to
8890 -- simply be delimited implicitly by the presence of Standard_Standard
8891 -- at their base, but there now are cases where this is not sufficient
8892 -- because Standard_Standard actually may appear in the middle of the
8893 -- active set of scopes.
8895 for J
in reverse 0 .. Scope_Stack
.Last
loop
8896 if Scope_Stack
.Table
(J
).Entity
= S
then
8900 -- Check Is_Active_Stack_Base to tell us when to stop, as there are
8901 -- cases where Standard_Standard appears in the middle of the active
8902 -- set of scopes. This affects the declaration and overriding of
8903 -- private inherited operations in instantiations of generic child
8906 exit when Scope_Stack
.Table
(J
).Is_Active_Stack_Base
;
8912 -----------------------------
8913 -- Inherit_Renamed_Profile --
8914 -----------------------------
8916 procedure Inherit_Renamed_Profile
(New_S
: Entity_Id
; Old_S
: Entity_Id
) is
8923 if Ekind
(Old_S
) = E_Operator
then
8924 New_F
:= First_Formal
(New_S
);
8926 while Present
(New_F
) loop
8927 Set_Etype
(New_F
, Base_Type
(Etype
(New_F
)));
8928 Next_Formal
(New_F
);
8931 Set_Etype
(New_S
, Base_Type
(Etype
(New_S
)));
8934 New_F
:= First_Formal
(New_S
);
8935 Old_F
:= First_Formal
(Old_S
);
8937 while Present
(New_F
) loop
8938 New_T
:= Etype
(New_F
);
8939 Old_T
:= Etype
(Old_F
);
8941 -- If the new type is a renaming of the old one, as is the case
8942 -- for actuals in instances, retain its name, to simplify later
8945 if Nkind
(Parent
(New_T
)) = N_Subtype_Declaration
8946 and then Is_Entity_Name
(Subtype_Indication
(Parent
(New_T
)))
8947 and then Entity
(Subtype_Indication
(Parent
(New_T
))) = Old_T
8951 Set_Etype
(New_F
, Old_T
);
8954 Next_Formal
(New_F
);
8955 Next_Formal
(Old_F
);
8958 pragma Assert
(No
(Old_F
));
8960 if Ekind
(Old_S
) in E_Function | E_Enumeration_Literal
then
8961 Set_Etype
(New_S
, Etype
(Old_S
));
8964 end Inherit_Renamed_Profile
;
8970 procedure Initialize
is
8975 -------------------------
8976 -- Install_Use_Clauses --
8977 -------------------------
8979 procedure Install_Use_Clauses
8981 Force_Installation
: Boolean := False)
8987 while Present
(U
) loop
8989 -- Case of USE package
8991 if Nkind
(U
) = N_Use_Package_Clause
then
8992 Use_One_Package
(U
, Name
(U
), True);
8997 Use_One_Type
(Subtype_Mark
(U
), Force
=> Force_Installation
);
9001 Next_Use_Clause
(U
);
9003 end Install_Use_Clauses
;
9005 ----------------------
9006 -- Mark_Use_Clauses --
9007 ----------------------
9009 procedure Mark_Use_Clauses
(Id
: Node_Or_Entity_Id
) is
9010 procedure Mark_Parameters
(Call
: Entity_Id
);
9011 -- Perform use_type_clause marking for all parameters in a subprogram
9012 -- or operator call.
9014 procedure Mark_Use_Package
(Pak
: Entity_Id
);
9015 -- Move up the Prev_Use_Clause chain for packages denoted by Pak -
9016 -- marking each clause in the chain as effective in the process.
9018 procedure Mark_Use_Type
(E
: Entity_Id
);
9019 -- Similar to Do_Use_Package_Marking except we move up the
9020 -- Prev_Use_Clause chain for the type denoted by E.
9022 ---------------------
9023 -- Mark_Parameters --
9024 ---------------------
9026 procedure Mark_Parameters
(Call
: Entity_Id
) is
9030 -- Move through all of the formals
9032 Curr
:= First_Formal
(Call
);
9033 while Present
(Curr
) loop
9034 Mark_Use_Type
(Curr
);
9039 -- Handle the return type
9041 Mark_Use_Type
(Call
);
9042 end Mark_Parameters
;
9044 ----------------------
9045 -- Mark_Use_Package --
9046 ----------------------
9048 procedure Mark_Use_Package
(Pak
: Entity_Id
) is
9052 -- Ignore cases where the scope of the type is not a package (e.g.
9053 -- Standard_Standard).
9055 if Ekind
(Pak
) /= E_Package
then
9059 Curr
:= Current_Use_Clause
(Pak
);
9060 while Present
(Curr
)
9061 and then not Is_Effective_Use_Clause
(Curr
)
9063 -- We need to mark the previous use clauses as effective, but
9064 -- each use clause may in turn render other use_package_clauses
9065 -- effective. Additionally, it is possible to have a parent
9066 -- package renamed as a child of itself so we must check the
9067 -- prefix entity is not the same as the package we are marking.
9069 if Nkind
(Name
(Curr
)) /= N_Identifier
9070 and then Present
(Prefix
(Name
(Curr
)))
9071 and then Entity
(Prefix
(Name
(Curr
))) /= Pak
9073 Mark_Use_Package
(Entity
(Prefix
(Name
(Curr
))));
9075 -- It is also possible to have a child package without a prefix
9076 -- that relies on a previous use_package_clause.
9078 elsif Nkind
(Name
(Curr
)) = N_Identifier
9079 and then Is_Child_Unit
(Entity
(Name
(Curr
)))
9081 Mark_Use_Package
(Scope
(Entity
(Name
(Curr
))));
9084 -- Mark the use_package_clause as effective and move up the chain
9086 Set_Is_Effective_Use_Clause
(Curr
);
9088 Curr
:= Prev_Use_Clause
(Curr
);
9090 end Mark_Use_Package
;
9096 procedure Mark_Use_Type
(E
: Entity_Id
) is
9101 -- Ignore void types and unresolved string literals and primitives
9103 if Nkind
(E
) = N_String_Literal
9104 or else Nkind
(Etype
(E
)) not in N_Entity
9105 or else not Is_Type
(Etype
(E
))
9110 -- Primitives with class-wide operands might additionally render
9111 -- their base type's use_clauses effective - so do a recursive check
9114 Base
:= Base_Type
(Etype
(E
));
9116 if Ekind
(Base
) = E_Class_Wide_Type
then
9117 Mark_Use_Type
(Base
);
9120 -- The package containing the type or operator function being used
9121 -- may be in use as well, so mark any use_package_clauses for it as
9122 -- effective. There are also additional sanity checks performed here
9123 -- for ignoring previous errors.
9125 Mark_Use_Package
(Scope
(Base
));
9127 if Nkind
(E
) in N_Op
9128 and then Present
(Entity
(E
))
9129 and then Present
(Scope
(Entity
(E
)))
9131 Mark_Use_Package
(Scope
(Entity
(E
)));
9134 Curr
:= Current_Use_Clause
(Base
);
9135 while Present
(Curr
)
9136 and then not Is_Effective_Use_Clause
(Curr
)
9138 -- Current use_type_clause may render other use_package_clauses
9141 if Nkind
(Subtype_Mark
(Curr
)) /= N_Identifier
9142 and then Present
(Prefix
(Subtype_Mark
(Curr
)))
9144 Mark_Use_Package
(Entity
(Prefix
(Subtype_Mark
(Curr
))));
9147 -- Mark the use_type_clause as effective and move up the chain
9149 Set_Is_Effective_Use_Clause
(Curr
);
9151 Curr
:= Prev_Use_Clause
(Curr
);
9155 -- Start of processing for Mark_Use_Clauses
9158 -- Use clauses in and of themselves do not count as a "use" of a
9161 if Nkind
(Parent
(Id
)) in N_Use_Package_Clause | N_Use_Type_Clause
then
9167 if Nkind
(Id
) in N_Entity
then
9169 -- Mark the entity's package
9171 if Is_Potentially_Use_Visible
(Id
) then
9172 Mark_Use_Package
(Scope
(Id
));
9175 -- Mark enumeration literals
9177 if Ekind
(Id
) = E_Enumeration_Literal
then
9182 elsif (Is_Overloadable
(Id
)
9183 or else Is_Generic_Subprogram
(Id
))
9184 and then (Is_Potentially_Use_Visible
(Id
)
9185 or else Is_Intrinsic_Subprogram
(Id
)
9186 or else (Ekind
(Id
) in E_Function | E_Procedure
9187 and then Is_Generic_Actual_Subprogram
(Id
)))
9189 Mark_Parameters
(Id
);
9197 if Nkind
(Id
) in N_Op
then
9199 -- At this point the left operand may not be resolved if we are
9200 -- encountering multiple operators next to eachother in an
9203 if Nkind
(Id
) in N_Binary_Op
9204 and then not (Nkind
(Left_Opnd
(Id
)) in N_Op
)
9206 Mark_Use_Type
(Left_Opnd
(Id
));
9209 Mark_Use_Type
(Right_Opnd
(Id
));
9212 -- Mark entity identifiers
9214 elsif Nkind
(Id
) in N_Has_Entity
9215 and then (Is_Potentially_Use_Visible
(Entity
(Id
))
9216 or else (Is_Generic_Instance
(Entity
(Id
))
9217 and then Is_Immediately_Visible
(Entity
(Id
))))
9219 -- Ignore fully qualified names as they do not count as a "use" of
9222 if Nkind
(Id
) in N_Identifier | N_Operator_Symbol
9223 or else (Present
(Prefix
(Id
))
9224 and then Scope
(Entity
(Id
)) /= Entity
(Prefix
(Id
)))
9226 Mark_Use_Clauses
(Entity
(Id
));
9230 end Mark_Use_Clauses
;
9232 --------------------------------
9233 -- Most_Descendant_Use_Clause --
9234 --------------------------------
9236 function Most_Descendant_Use_Clause
9237 (Clause1
: Entity_Id
;
9238 Clause2
: Entity_Id
) return Entity_Id
9240 function Determine_Package_Scope
(Clause
: Node_Id
) return Entity_Id
;
9241 -- Given a use clause, determine which package it belongs to
9243 -----------------------------
9244 -- Determine_Package_Scope --
9245 -----------------------------
9247 function Determine_Package_Scope
(Clause
: Node_Id
) return Entity_Id
is
9249 -- Check if the clause appears in the context area
9251 -- Note we cannot employ Enclosing_Packge for use clauses within
9252 -- context clauses since they are not actually "enclosed."
9254 if Nkind
(Parent
(Clause
)) = N_Compilation_Unit
then
9255 return Entity_Of_Unit
(Unit
(Parent
(Clause
)));
9258 -- Otherwise, obtain the enclosing package normally
9260 return Enclosing_Package
(Clause
);
9261 end Determine_Package_Scope
;
9266 -- Start of processing for Most_Descendant_Use_Clause
9269 if Clause1
= Clause2
then
9273 -- We determine which one is the most descendant by the scope distance
9274 -- to the ultimate parent unit.
9276 Scope1
:= Determine_Package_Scope
(Clause1
);
9277 Scope2
:= Determine_Package_Scope
(Clause2
);
9278 while Scope1
/= Standard_Standard
9279 and then Scope2
/= Standard_Standard
9281 Scope1
:= Scope
(Scope1
);
9282 Scope2
:= Scope
(Scope2
);
9286 elsif No
(Scope2
) then
9291 if Scope1
= Standard_Standard
then
9296 end Most_Descendant_Use_Clause
;
9302 procedure Pop_Scope
is
9303 SST
: Scope_Stack_Entry
renames Scope_Stack
.Table
(Scope_Stack
.Last
);
9304 S
: constant Entity_Id
:= SST
.Entity
;
9307 if Debug_Flag_E
then
9311 -- Set Default_Storage_Pool field of the library unit if necessary
9313 if Is_Package_Or_Generic_Package
(S
)
9315 Nkind
(Parent
(Unit_Declaration_Node
(S
))) = N_Compilation_Unit
9318 Aux
: constant Node_Id
:=
9319 Aux_Decls_Node
(Parent
(Unit_Declaration_Node
(S
)));
9321 if No
(Default_Storage_Pool
(Aux
)) then
9322 Set_Default_Storage_Pool
(Aux
, Default_Pool
);
9327 Scope_Suppress
:= SST
.Save_Scope_Suppress
;
9328 Local_Suppress_Stack_Top
:= SST
.Save_Local_Suppress_Stack_Top
;
9329 Check_Policy_List
:= SST
.Save_Check_Policy_List
;
9330 Default_Pool
:= SST
.Save_Default_Storage_Pool
;
9331 No_Tagged_Streams
:= SST
.Save_No_Tagged_Streams
;
9332 SPARK_Mode
:= SST
.Save_SPARK_Mode
;
9333 SPARK_Mode_Pragma
:= SST
.Save_SPARK_Mode_Pragma
;
9334 Default_SSO
:= SST
.Save_Default_SSO
;
9335 Uneval_Old
:= SST
.Save_Uneval_Old
;
9337 if Debug_Flag_W
then
9338 Write_Str
("<-- exiting scope: ");
9339 Write_Name
(Chars
(Current_Scope
));
9340 Write_Str
(", Depth=");
9341 Write_Int
(Int
(Scope_Stack
.Last
));
9345 End_Use_Clauses
(SST
.First_Use_Clause
);
9347 -- If the actions to be wrapped are still there they will get lost
9348 -- causing incomplete code to be generated. It is better to abort in
9349 -- this case (and we do the abort even with assertions off since the
9350 -- penalty is incorrect code generation).
9352 if SST
.Actions_To_Be_Wrapped
/= Scope_Actions
'(others => No_List) then
9353 raise Program_Error;
9356 -- Free last subprogram name if allocated, and pop scope
9358 Free (SST.Last_Subprogram_Name);
9359 Scope_Stack.Decrement_Last;
9366 procedure Push_Scope (S : Entity_Id) is
9367 E : constant Entity_Id := Scope (S);
9369 function Component_Alignment_Default return Component_Alignment_Kind;
9370 -- Return Component_Alignment_Kind for the newly-pushed scope.
9372 function Component_Alignment_Default return Component_Alignment_Kind is
9374 -- Each new scope pushed onto the scope stack inherits the component
9375 -- alignment of the previous scope. This emulates the "visibility"
9376 -- semantics of pragma Component_Alignment.
9378 if Scope_Stack.Last > Scope_Stack.First then
9379 return Scope_Stack.Table
9380 (Scope_Stack.Last - 1).Component_Alignment_Default;
9382 -- Otherwise, this is the first scope being pushed on the scope
9383 -- stack. Inherit the component alignment from the configuration
9384 -- form of pragma Component_Alignment (if any).
9387 return Configuration_Component_Alignment;
9389 end Component_Alignment_Default;
9392 if Ekind (S) = E_Void then
9395 -- Set scope depth if not a nonconcurrent type, and we have not yet set
9396 -- the scope depth. This means that we have the first occurrence of the
9397 -- scope, and this is where the depth is set.
9399 elsif (not Is_Type (S) or else Is_Concurrent_Type (S))
9400 and then not Scope_Depth_Set (S)
9402 if S = Standard_Standard then
9403 Set_Scope_Depth_Value (S, Uint_0);
9405 elsif Is_Child_Unit (S) then
9406 Set_Scope_Depth_Value (S, Uint_1);
9408 elsif not Is_Record_Type (Current_Scope) then
9409 if Scope_Depth_Set (Current_Scope) then
9410 if Ekind (S) = E_Loop then
9411 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope));
9413 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope) + 1);
9419 Scope_Stack.Increment_Last;
9421 Scope_Stack.Table (Scope_Stack.Last) :=
9423 Save_Scope_Suppress => Scope_Suppress,
9424 Save_Local_Suppress_Stack_Top => Local_Suppress_Stack_Top,
9425 Save_Check_Policy_List => Check_Policy_List,
9426 Save_Default_Storage_Pool => Default_Pool,
9427 Save_No_Tagged_Streams => No_Tagged_Streams,
9428 Save_SPARK_Mode => SPARK_Mode,
9429 Save_SPARK_Mode_Pragma => SPARK_Mode_Pragma,
9430 Save_Default_SSO => Default_SSO,
9431 Save_Uneval_Old => Uneval_Old,
9432 Component_Alignment_Default => Component_Alignment_Default,
9433 Last_Subprogram_Name => null,
9434 Is_Transient => False,
9435 Node_To_Be_Wrapped => Empty,
9436 Pending_Freeze_Actions => No_List,
9437 Actions_To_Be_Wrapped => (others => No_List),
9438 First_Use_Clause => Empty,
9439 Is_Active_Stack_Base => False,
9440 Previous_Visibility => False,
9441 Locked_Shared_Objects => No_Elist);
9443 if Debug_Flag_W then
9444 Write_Str ("--> new scope: ");
9445 Write_Name (Chars (Current_Scope));
9446 Write_Str (", Id=");
9447 Write_Int (Int (Current_Scope));
9448 Write_Str (", Depth=");
9449 Write_Int (Int (Scope_Stack.Last));
9453 -- Deal with copying flags from the previous scope to this one. This is
9454 -- not necessary if either scope is standard, or if the new scope is a
9457 if S /= Standard_Standard
9458 and then Scope (S) /= Standard_Standard
9459 and then not Is_Child_Unit (S)
9461 if Nkind (E) not in N_Entity then
9465 -- Copy categorization flags from Scope (S) to S, this is not done
9466 -- when Scope (S) is Standard_Standard since propagation is from
9467 -- library unit entity inwards. Copy other relevant attributes as
9468 -- well (Discard_Names in particular).
9470 -- We only propagate inwards for library level entities,
9471 -- inner level subprograms do not inherit the categorization.
9473 if Is_Library_Level_Entity (S) then
9474 Set_Is_Preelaborated (S, Is_Preelaborated (E));
9475 Set_Is_Shared_Passive (S, Is_Shared_Passive (E));
9476 Set_Discard_Names (S, Discard_Names (E));
9477 Set_Suppress_Value_Tracking_On_Call
9478 (S, Suppress_Value_Tracking_On_Call (E));
9479 Set_Categorization_From_Scope (E => S, Scop => E);
9483 if Is_Child_Unit (S)
9484 and then Present (E)
9485 and then Is_Package_Or_Generic_Package (E)
9487 Nkind (Parent (Unit_Declaration_Node (E))) = N_Compilation_Unit
9490 Aux : constant Node_Id :=
9491 Aux_Decls_Node (Parent (Unit_Declaration_Node (E)));
9493 if Present (Default_Storage_Pool (Aux)) then
9494 Default_Pool := Default_Storage_Pool (Aux);
9500 ---------------------
9501 -- Premature_Usage --
9502 ---------------------
9504 procedure Premature_Usage (N : Node_Id) is
9505 Kind : constant Node_Kind := Nkind (Parent (Entity (N)));
9506 E : Entity_Id := Entity (N);
9509 -- Within an instance, the analysis of the actual for a formal object
9510 -- does not see the name of the object itself. This is significant only
9511 -- if the object is an aggregate, where its analysis does not do any
9512 -- name resolution on component associations. (see 4717-008). In such a
9513 -- case, look for the visible homonym on the chain.
9515 if In_Instance and then Present (Homonym (E)) then
9517 while Present (E) and then not In_Open_Scopes (Scope (E)) loop
9523 Set_Etype (N, Etype (E));
9529 when N_Component_Declaration =>
9531 ("component&! cannot be used before end of record declaration",
9534 when N_Parameter_Specification =>
9536 ("formal parameter&! cannot be used before end of specification",
9539 when N_Discriminant_Specification =>
9541 ("discriminant&! cannot be used before end of discriminant part",
9544 when N_Procedure_Specification | N_Function_Specification =>
9546 ("subprogram&! cannot be used before end of its declaration",
9549 when N_Full_Type_Declaration | N_Subtype_Declaration =>
9551 ("type& cannot be used before end of its declaration!", N);
9555 ("object& cannot be used before end of its declaration!", N);
9557 -- If the premature reference appears as the expression in its own
9558 -- declaration, rewrite it to prevent compiler loops in subsequent
9559 -- uses of this mangled declaration in address clauses.
9561 if Nkind (Parent (N)) = N_Object_Declaration then
9562 Set_Entity (N, Any_Id);
9565 end Premature_Usage;
9567 ------------------------
9568 -- Present_System_Aux --
9569 ------------------------
9571 function Present_System_Aux (N : Node_Id := Empty) return Boolean is
9573 Aux_Name : Unit_Name_Type;
9574 Unum : Unit_Number_Type;
9579 function Find_System (C_Unit : Node_Id) return Entity_Id;
9580 -- Scan context clause of compilation unit to find with_clause
9587 function Find_System (C_Unit : Node_Id) return Entity_Id is
9588 With_Clause : Node_Id;
9591 With_Clause := First (Context_Items (C_Unit));
9592 while Present (With_Clause) loop
9593 if (Nkind (With_Clause) = N_With_Clause
9594 and then Chars (Name (With_Clause)) = Name_System)
9595 and then Comes_From_Source (With_Clause)
9606 -- Start of processing for Present_System_Aux
9609 -- The child unit may have been loaded and analyzed already
9611 if Present (System_Aux_Id) then
9614 -- If no previous pragma for System.Aux, nothing to load
9616 elsif No (System_Extend_Unit) then
9619 -- Use the unit name given in the pragma to retrieve the unit.
9620 -- Verify that System itself appears in the context clause of the
9621 -- current compilation. If System is not present, an error will
9622 -- have been reported already.
9625 With_Sys := Find_System (Cunit (Current_Sem_Unit));
9627 The_Unit := Unit (Cunit (Current_Sem_Unit));
9631 (Nkind (The_Unit) = N_Package_Body
9632 or else (Nkind (The_Unit) = N_Subprogram_Body
9633 and then not Acts_As_Spec (Cunit (Current_Sem_Unit))))
9635 With_Sys := Find_System (Library_Unit (Cunit (Current_Sem_Unit)));
9638 if No (With_Sys) and then Present (N) then
9640 -- If we are compiling a subunit, we need to examine its
9641 -- context as well (Current_Sem_Unit is the parent unit);
9643 The_Unit := Parent (N);
9644 while Nkind (The_Unit) /= N_Compilation_Unit loop
9645 The_Unit := Parent (The_Unit);
9648 if Nkind (Unit (The_Unit)) = N_Subunit then
9649 With_Sys := Find_System (The_Unit);
9653 if No (With_Sys) then
9657 Loc := Sloc (With_Sys);
9658 Get_Name_String (Chars (Expression (System_Extend_Unit)));
9659 Name_Buffer (8 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
9660 Name_Buffer (1 .. 7) := "system.";
9661 Name_Buffer (Name_Len + 8) := '%';
9662 Name_Buffer (Name_Len + 9) := 's
';
9663 Name_Len := Name_Len + 9;
9664 Aux_Name := Name_Find;
9668 (Load_Name => Aux_Name,
9671 Error_Node => With_Sys);
9673 if Unum /= No_Unit then
9674 Semantics (Cunit (Unum));
9676 Defining_Entity (Specification (Unit (Cunit (Unum))));
9679 Make_With_Clause (Loc,
9681 Make_Expanded_Name (Loc,
9682 Chars => Chars (System_Aux_Id),
9684 New_Occurrence_Of (Scope (System_Aux_Id), Loc),
9685 Selector_Name => New_Occurrence_Of (System_Aux_Id, Loc)));
9687 Set_Entity (Name (Withn), System_Aux_Id);
9689 Set_Corresponding_Spec (Withn, System_Aux_Id);
9690 Set_First_Name (Withn);
9691 Set_Implicit_With (Withn);
9692 Set_Library_Unit (Withn, Cunit (Unum));
9694 Insert_After (With_Sys, Withn);
9695 Mark_Rewrite_Insertion (Withn);
9696 Set_Context_Installed (Withn);
9700 -- Here if unit load failed
9703 Error_Msg_Name_1 := Name_System;
9704 Error_Msg_Name_2 := Chars (Expression (System_Extend_Unit));
9706 ("extension package `%.%` does not exist",
9707 Opt.System_Extend_Unit);
9711 end Present_System_Aux;
9713 -------------------------
9714 -- Restore_Scope_Stack --
9715 -------------------------
9717 procedure Restore_Scope_Stack
9719 Handle_Use : Boolean := True)
9721 SS_Last : constant Int := Scope_Stack.Last;
9725 -- Restore visibility of previous scope stack, if any, using the list
9726 -- we saved (we use Remove, since this list will not be used again).
9729 Elmt := First_Elmt (List);
9730 exit when Elmt = No_Elmt;
9731 Set_Is_Immediately_Visible (Node (Elmt));
9732 Remove_Elmt (List, Elmt);
9735 -- Restore use clauses
9737 if SS_Last >= Scope_Stack.First
9738 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
9742 (Scope_Stack.Table (SS_Last).First_Use_Clause,
9743 Force_Installation => True);
9745 end Restore_Scope_Stack;
9747 ----------------------
9748 -- Save_Scope_Stack --
9749 ----------------------
9751 -- Save_Scope_Stack/Restore_Scope_Stack were originally designed to avoid
9752 -- consuming any memory. That is, Save_Scope_Stack took care of removing
9753 -- from immediate visibility entities and Restore_Scope_Stack took care
9754 -- of restoring their visibility analyzing the context of each entity. The
9755 -- problem of such approach is that it was fragile and caused unexpected
9756 -- visibility problems, and indeed one test was found where there was a
9759 -- Furthermore, the following experiment was carried out:
9761 -- - Save_Scope_Stack was modified to store in an Elist1 all those
9762 -- entities whose attribute Is_Immediately_Visible is modified
9763 -- from True to False.
9765 -- - Restore_Scope_Stack was modified to store in another Elist2
9766 -- all the entities whose attribute Is_Immediately_Visible is
9767 -- modified from False to True.
9769 -- - Extra code was added to verify that all the elements of Elist1
9770 -- are found in Elist2
9772 -- This test shows that there may be more occurrences of this problem which
9773 -- have not yet been detected. As a result, we replaced that approach by
9774 -- the current one in which Save_Scope_Stack returns the list of entities
9775 -- whose visibility is changed, and that list is passed to Restore_Scope_
9776 -- Stack to undo that change. This approach is simpler and safer, although
9777 -- it consumes more memory.
9779 function Save_Scope_Stack (Handle_Use : Boolean := True) return Elist_Id is
9780 Result : constant Elist_Id := New_Elmt_List;
9783 SS_Last : constant Int := Scope_Stack.Last;
9785 procedure Remove_From_Visibility (E : Entity_Id);
9786 -- If E is immediately visible then append it to the result and remove
9787 -- it temporarily from visibility.
9789 ----------------------------
9790 -- Remove_From_Visibility --
9791 ----------------------------
9793 procedure Remove_From_Visibility (E : Entity_Id) is
9795 if Is_Immediately_Visible (E) then
9796 Append_Elmt (E, Result);
9797 Set_Is_Immediately_Visible (E, False);
9799 end Remove_From_Visibility;
9801 -- Start of processing for Save_Scope_Stack
9804 if SS_Last >= Scope_Stack.First
9805 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
9808 End_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
9811 -- If the call is from within a compilation unit, as when called from
9812 -- Rtsfind, make current entries in scope stack invisible while we
9813 -- analyze the new unit.
9815 for J in reverse 0 .. SS_Last loop
9816 exit when Scope_Stack.Table (J).Entity = Standard_Standard
9817 or else No (Scope_Stack.Table (J).Entity);
9819 S := Scope_Stack.Table (J).Entity;
9821 Remove_From_Visibility (S);
9823 E := First_Entity (S);
9824 while Present (E) loop
9825 Remove_From_Visibility (E);
9833 end Save_Scope_Stack;
9839 procedure Set_Use (L : List_Id) is
9844 while Present (Decl) loop
9845 if Nkind (Decl) = N_Use_Package_Clause then
9846 Chain_Use_Clause (Decl);
9847 Use_One_Package (Decl, Name (Decl));
9849 elsif Nkind (Decl) = N_Use_Type_Clause then
9850 Chain_Use_Clause (Decl);
9851 Use_One_Type (Subtype_Mark (Decl));
9859 -----------------------------
9860 -- Update_Use_Clause_Chain --
9861 -----------------------------
9863 procedure Update_Use_Clause_Chain is
9865 procedure Update_Chain_In_Scope (Level : Int);
9866 -- Iterate through one level in the scope stack verifying each use-type
9867 -- clause within said level is used then reset the Current_Use_Clause
9868 -- to a redundant use clause outside of the current ending scope if such
9871 ---------------------------
9872 -- Update_Chain_In_Scope --
9873 ---------------------------
9875 procedure Update_Chain_In_Scope (Level : Int) is
9880 -- Loop through all use clauses within the scope dictated by Level
9882 Curr := Scope_Stack.Table (Level).First_Use_Clause;
9883 while Present (Curr) loop
9885 -- Retrieve the subtype mark or name within the current current
9888 if Nkind (Curr) = N_Use_Type_Clause then
9889 N := Subtype_Mark (Curr);
9894 -- If warnings for unreferenced entities are enabled and the
9895 -- current use clause has not been marked effective.
9897 if Check_Unreferenced
9898 and then Comes_From_Source (Curr)
9899 and then not Is_Effective_Use_Clause (Curr)
9900 and then not In_Instance
9901 and then not In_Inlined_Body
9903 -- We are dealing with a potentially unused use_package_clause
9905 if Nkind (Curr) = N_Use_Package_Clause then
9907 -- Renamings and formal subprograms may cause the associated
9908 -- node to be marked as effective instead of the original.
9910 if not (Present (Associated_Node (N))
9913 (Associated_Node (N)))
9914 and then Is_Effective_Use_Clause
9916 (Associated_Node (N))))
9918 Error_Msg_Node_1 := Entity (N);
9920 ("use clause for package & has no effect?u?",
9924 -- We are dealing with an unused use_type_clause
9927 Error_Msg_Node_1 := Etype (N);
9929 ("use clause for } has no effect?u?", Curr, Etype (N));
9933 -- Verify that we haven't already processed a redundant
9934 -- use_type_clause within the same scope before we move the
9935 -- current use clause up to a previous one for type T.
9937 if Present (Prev_Use_Clause (Curr)) then
9938 Set_Current_Use_Clause (Entity (N), Prev_Use_Clause (Curr));
9941 Next_Use_Clause (Curr);
9943 end Update_Chain_In_Scope;
9945 -- Start of processing for Update_Use_Clause_Chain
9948 Update_Chain_In_Scope (Scope_Stack.Last);
9950 -- Deal with use clauses within the context area if the current
9951 -- scope is a compilation unit.
9953 if Is_Compilation_Unit (Current_Scope)
9954 and then Sloc (Scope_Stack.Table
9955 (Scope_Stack.Last - 1).Entity) = Standard_Location
9957 Update_Chain_In_Scope (Scope_Stack.Last - 1);
9959 end Update_Use_Clause_Chain;
9961 ---------------------
9962 -- Use_One_Package --
9963 ---------------------
9965 procedure Use_One_Package
9967 Pack_Name : Entity_Id := Empty;
9968 Force : Boolean := False)
9970 procedure Note_Redundant_Use (Clause : Node_Id);
9971 -- Mark the name in a use clause as redundant if the corresponding
9972 -- entity is already use-visible. Emit a warning if the use clause comes
9973 -- from source and the proper warnings are enabled.
9975 ------------------------
9976 -- Note_Redundant_Use --
9977 ------------------------
9979 procedure Note_Redundant_Use (Clause : Node_Id) is
9980 Decl : constant Node_Id := Parent (Clause);
9981 Pack_Name : constant Entity_Id := Entity (Clause);
9983 Cur_Use : Node_Id := Current_Use_Clause (Pack_Name);
9984 Prev_Use : Node_Id := Empty;
9985 Redundant : Node_Id := Empty;
9986 -- The Use_Clause which is actually redundant. In the simplest case
9987 -- it is Pack itself, but when we compile a body we install its
9988 -- context before that of its spec, in which case it is the
9989 -- use_clause in the spec that will appear to be redundant, and we
9990 -- want the warning to be placed on the body. Similar complications
9991 -- appear when the redundancy is between a child unit and one of its
9995 -- Could be renamed...
9997 if No (Cur_Use) then
9998 Cur_Use := Current_Use_Clause (Renamed_Entity (Pack_Name));
10001 Set_Redundant_Use (Clause, True);
10003 -- Do not check for redundant use if clause is generated, or in an
10004 -- instance, or in a predefined unit to avoid misleading warnings
10005 -- that may occur as part of a rtsfind load.
10007 if not Comes_From_Source (Clause)
10008 or else In_Instance
10009 or else not Warn_On_Redundant_Constructs
10010 or else Is_Predefined_Unit (Current_Sem_Unit)
10015 if not Is_Compilation_Unit (Current_Scope) then
10017 -- If the use_clause is in an inner scope, it is made redundant by
10018 -- some clause in the current context, with one exception: If we
10019 -- are compiling a nested package body, and the use_clause comes
10020 -- from then corresponding spec, the clause is not necessarily
10021 -- fully redundant, so we should not warn. If a warning was
10022 -- warranted, it would have been given when the spec was
10025 if Nkind (Parent (Decl)) = N_Package_Specification then
10027 Package_Spec_Entity : constant Entity_Id :=
10028 Defining_Unit_Name (Parent (Decl));
10030 if In_Package_Body (Package_Spec_Entity) then
10036 Redundant := Clause;
10037 Prev_Use := Cur_Use;
10039 elsif Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body then
10041 Cur_Unit : constant Unit_Number_Type :=
10042 Get_Source_Unit (Cur_Use);
10043 New_Unit : constant Unit_Number_Type :=
10044 Get_Source_Unit (Clause);
10049 if Cur_Unit = New_Unit then
10051 -- Redundant clause in same body
10053 Redundant := Clause;
10054 Prev_Use := Cur_Use;
10056 elsif Cur_Unit = Current_Sem_Unit then
10058 -- If the new clause is not in the current unit it has been
10059 -- analyzed first, and it makes the other one redundant.
10060 -- However, if the new clause appears in a subunit, Cur_Unit
10061 -- is still the parent, and in that case the redundant one
10062 -- is the one appearing in the subunit.
10064 if Nkind (Unit (Cunit (New_Unit))) = N_Subunit then
10065 Redundant := Clause;
10066 Prev_Use := Cur_Use;
10068 -- Most common case: redundant clause in body, original
10069 -- clause in spec. Current scope is spec entity.
10071 elsif Current_Scope = Cunit_Entity (Current_Sem_Unit) then
10072 Redundant := Cur_Use;
10073 Prev_Use := Clause;
10076 -- The new clause may appear in an unrelated unit, when
10077 -- the parents of a generic are being installed prior to
10078 -- instantiation. In this case there must be no warning.
10079 -- We detect this case by checking whether the current
10080 -- top of the stack is related to the current
10083 Scop := Current_Scope;
10084 while Present (Scop)
10085 and then Scop /= Standard_Standard
10087 if Is_Compilation_Unit (Scop)
10088 and then not Is_Child_Unit (Scop)
10092 elsif Scop = Cunit_Entity (Current_Sem_Unit) then
10096 Scop := Scope (Scop);
10099 Redundant := Cur_Use;
10100 Prev_Use := Clause;
10103 elsif New_Unit = Current_Sem_Unit then
10104 Redundant := Clause;
10105 Prev_Use := Cur_Use;
10108 -- Neither is the current unit, so they appear in parent or
10109 -- sibling units. Warning will be emitted elsewhere.
10115 elsif Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
10116 and then Present (Parent_Spec (Unit (Cunit (Current_Sem_Unit))))
10118 -- Use_clause is in child unit of current unit, and the child unit
10119 -- appears in the context of the body of the parent, so it has
10120 -- been installed first, even though it is the redundant one.
10121 -- Depending on their placement in the context, the visible or the
10122 -- private parts of the two units, either might appear as
10123 -- redundant, but the message has to be on the current unit.
10125 if Get_Source_Unit (Cur_Use) = Current_Sem_Unit then
10126 Redundant := Cur_Use;
10127 Prev_Use := Clause;
10129 Redundant := Clause;
10130 Prev_Use := Cur_Use;
10133 -- If the new use clause appears in the private part of a parent
10134 -- unit it may appear to be redundant w.r.t. a use clause in a
10135 -- child unit, but the previous use clause was needed in the
10136 -- visible part of the child, and no warning should be emitted.
10138 if Nkind (Parent (Decl)) = N_Package_Specification
10139 and then List_Containing (Decl) =
10140 Private_Declarations (Parent (Decl))
10143 Par : constant Entity_Id :=
10144 Defining_Entity (Parent (Decl));
10145 Spec : constant Node_Id :=
10146 Specification (Unit (Cunit (Current_Sem_Unit)));
10147 Cur_List : constant List_Id := List_Containing (Cur_Use);
10150 if Is_Compilation_Unit (Par)
10151 and then Par /= Cunit_Entity (Current_Sem_Unit)
10153 if Cur_List = Context_Items (Cunit (Current_Sem_Unit))
10154 or else Cur_List = Visible_Declarations (Spec)
10162 -- Finally, if the current use clause is in the context then the
10163 -- clause is redundant when it is nested within the unit.
10165 elsif Nkind (Parent (Cur_Use)) = N_Compilation_Unit
10166 and then Nkind (Parent (Parent (Clause))) /= N_Compilation_Unit
10167 and then Get_Source_Unit (Cur_Use) = Get_Source_Unit (Clause)
10169 Redundant := Clause;
10170 Prev_Use := Cur_Use;
10173 if Present (Redundant) and then Parent (Redundant) /= Prev_Use then
10175 -- Make sure we are looking at most-descendant use_package_clause
10176 -- by traversing the chain with Find_First_Use and then verifying
10177 -- there is no scope manipulation via Most_Descendant_Use_Clause.
10179 if Nkind (Prev_Use) = N_Use_Package_Clause
10181 (Nkind (Parent (Prev_Use)) /= N_Compilation_Unit
10182 or else Most_Descendant_Use_Clause
10183 (Prev_Use, Find_First_Use (Prev_Use)) /= Prev_Use)
10185 Prev_Use := Find_First_Use (Prev_Use);
10188 Error_Msg_Sloc := Sloc (Prev_Use);
10189 Error_Msg_NE -- CODEFIX
10190 ("& is already use-visible through previous use_clause #?r?",
10191 Redundant, Pack_Name);
10193 end Note_Redundant_Use;
10197 Current_Instance : Entity_Id := Empty;
10201 Private_With_OK : Boolean := False;
10202 Real_P : Entity_Id;
10204 -- Start of processing for Use_One_Package
10207 -- Use_One_Package may have been called recursively to handle an
10208 -- implicit use for a auxiliary system package, so set P accordingly
10209 -- and skip redundancy checks.
10211 if No (Pack_Name) and then Present_System_Aux (N) then
10212 P := System_Aux_Id;
10214 -- Check for redundant use_package_clauses
10217 -- Ignore cases where we are dealing with a non user defined package
10218 -- like Standard_Standard or something other than a valid package.
10220 if not Is_Entity_Name (Pack_Name)
10221 or else No (Entity (Pack_Name))
10222 or else Ekind (Entity (Pack_Name)) /= E_Package
10227 -- When a renaming exists we must check it for redundancy. The
10228 -- original package would have already been seen at this point.
10230 if Present (Renamed_Entity (Entity (Pack_Name))) then
10231 P := Renamed_Entity (Entity (Pack_Name));
10233 P := Entity (Pack_Name);
10236 -- Check for redundant clauses then set the current use clause for
10237 -- P if were are not "forcing" an installation from a scope
10238 -- reinstallation that is done throughout analysis for various
10242 Note_Redundant_Use (Pack_Name);
10245 Set_Current_Use_Clause (P, N);
10250 -- Warn about detected redundant clauses
10253 and then In_Open_Scopes (P)
10254 and then not Is_Hidden_Open_Scope (P)
10256 if Warn_On_Redundant_Constructs and then P = Current_Scope then
10257 Error_Msg_NE -- CODEFIX
10258 ("& is already use-visible within itself?r?",
10265 -- Set P back to the non-renamed package so that visibility of the
10266 -- entities within the package can be properly set below.
10268 P := Entity (Pack_Name);
10272 Set_Current_Use_Clause (P, N);
10274 -- Ada 2005 (AI-50217): Check restriction
10276 if From_Limited_With (P) then
10277 Error_Msg_N ("limited withed package cannot appear in use clause", N);
10280 -- Find enclosing instance, if any
10282 if In_Instance then
10283 Current_Instance := Current_Scope;
10284 while not Is_Generic_Instance (Current_Instance) loop
10285 Current_Instance := Scope (Current_Instance);
10288 if No (Hidden_By_Use_Clause (N)) then
10289 Set_Hidden_By_Use_Clause (N, New_Elmt_List);
10293 -- If unit is a package renaming, indicate that the renamed package is
10294 -- also in use (the flags on both entities must remain consistent, and a
10295 -- subsequent use of either of them should be recognized as redundant).
10297 if Present (Renamed_Entity (P)) then
10298 Set_In_Use (Renamed_Entity (P));
10299 Set_Current_Use_Clause (Renamed_Entity (P), N);
10300 Real_P := Renamed_Entity (P);
10305 -- Ada 2005 (AI-262): Check the use_clause of a private withed package
10306 -- found in the private part of a package specification
10308 if In_Private_Part (Current_Scope)
10309 and then Has_Private_With (P)
10310 and then Is_Child_Unit (Current_Scope)
10311 and then Is_Child_Unit (P)
10312 and then Is_Ancestor_Package (Scope (Current_Scope), P)
10314 Private_With_OK := True;
10317 -- Loop through entities in one package making them potentially
10320 Id := First_Entity (P);
10322 and then (Id /= First_Private_Entity (P)
10323 or else Private_With_OK) -- Ada 2005 (AI-262)
10325 Prev := Current_Entity (Id);
10326 while Present (Prev) loop
10327 if Is_Immediately_Visible (Prev)
10328 and then (not Is_Overloadable (Prev)
10329 or else not Is_Overloadable (Id)
10330 or else Type_Conformant (Id, Prev))
10332 if No (Current_Instance) then
10334 -- Potentially use-visible entity remains hidden
10336 if Warn_On_Hiding then
10337 Warn_On_Hiding_Entity (N, Hidden => Id, Visible => Prev,
10338 On_Use_Clause => True);
10341 goto Next_Usable_Entity;
10343 -- A use clause within an instance hides outer global entities,
10344 -- which are not used to resolve local entities in the
10345 -- instance. Note that the predefined entities in Standard
10346 -- could not have been hidden in the generic by a use clause,
10347 -- and therefore remain visible. Other compilation units whose
10348 -- entities appear in Standard must be hidden in an instance.
10350 -- To determine whether an entity is external to the instance
10351 -- we compare the scope depth of its scope with that of the
10352 -- current instance. However, a generic actual of a subprogram
10353 -- instance is declared in the wrapper package but will not be
10354 -- hidden by a use-visible entity. similarly, an entity that is
10355 -- declared in an enclosing instance will not be hidden by an
10356 -- an entity declared in a generic actual, which can only have
10357 -- been use-visible in the generic and will not have hidden the
10358 -- entity in the generic parent.
10360 -- If Id is called Standard, the predefined package with the
10361 -- same name is in the homonym chain. It has to be ignored
10362 -- because it has no defined scope (being the only entity in
10363 -- the system with this mandated behavior).
10365 elsif not Is_Hidden (Id)
10366 and then Present (Scope (Prev))
10367 and then not Is_Wrapper_Package (Scope (Prev))
10368 and then Scope_Depth (Scope (Prev)) <
10369 Scope_Depth (Current_Instance)
10370 and then (Scope (Prev) /= Standard_Standard
10371 or else Sloc (Prev) > Standard_Location)
10373 if In_Open_Scopes (Scope (Prev))
10374 and then Is_Generic_Instance (Scope (Prev))
10375 and then Present (Associated_Formal_Package (P))
10380 Set_Is_Potentially_Use_Visible (Id);
10381 Set_Is_Immediately_Visible (Prev, False);
10382 Append_Elmt (Prev, Hidden_By_Use_Clause (N));
10386 -- A user-defined operator is not use-visible if the predefined
10387 -- operator for the type is immediately visible, which is the case
10388 -- if the type of the operand is in an open scope. This does not
10389 -- apply to user-defined operators that have operands of different
10390 -- types, because the predefined mixed mode operations (multiply
10391 -- and divide) apply to universal types and do not hide anything.
10393 elsif Ekind (Prev) = E_Operator
10394 and then Operator_Matches_Spec (Prev, Id)
10395 and then In_Open_Scopes
10396 (Scope (Base_Type (Etype (First_Formal (Id)))))
10397 and then (No (Next_Formal (First_Formal (Id)))
10398 or else Etype (First_Formal (Id)) =
10399 Etype (Next_Formal (First_Formal (Id)))
10400 or else Chars (Prev) = Name_Op_Expon)
10402 goto Next_Usable_Entity;
10404 -- In an instance, two homonyms may become use_visible through the
10405 -- actuals of distinct formal packages. In the generic, only the
10406 -- current one would have been visible, so make the other one
10407 -- not use_visible.
10409 -- In certain pathological cases it is possible that unrelated
10410 -- homonyms from distinct formal packages may exist in an
10411 -- uninstalled scope. We must test for that here.
10413 elsif Present (Current_Instance)
10414 and then Is_Potentially_Use_Visible (Prev)
10415 and then not Is_Overloadable (Prev)
10416 and then Scope (Id) /= Scope (Prev)
10417 and then Used_As_Generic_Actual (Scope (Prev))
10418 and then Used_As_Generic_Actual (Scope (Id))
10419 and then Is_List_Member (Scope (Prev))
10420 and then not In_Same_List (Current_Use_Clause (Scope (Prev)),
10421 Current_Use_Clause (Scope (Id)))
10423 Set_Is_Potentially_Use_Visible (Prev, False);
10424 Append_Elmt (Prev, Hidden_By_Use_Clause (N));
10427 Prev := Homonym (Prev);
10430 -- On exit, we know entity is not hidden, unless it is private
10432 if not Is_Hidden (Id)
10433 and then (not Is_Child_Unit (Id) or else Is_Visible_Lib_Unit (Id))
10435 Set_Is_Potentially_Use_Visible (Id);
10437 if Is_Private_Type (Id) and then Present (Full_View (Id)) then
10438 Set_Is_Potentially_Use_Visible (Full_View (Id));
10442 <<Next_Usable_Entity>>
10446 -- Child units are also made use-visible by a use clause, but they may
10447 -- appear after all visible declarations in the parent entity list.
10449 while Present (Id) loop
10450 if Is_Child_Unit (Id) and then Is_Visible_Lib_Unit (Id) then
10451 Set_Is_Potentially_Use_Visible (Id);
10457 if Chars (Real_P) = Name_System
10458 and then Scope (Real_P) = Standard_Standard
10459 and then Present_System_Aux (N)
10461 Use_One_Package (N);
10463 end Use_One_Package;
10469 procedure Use_One_Type
10471 Installed : Boolean := False;
10472 Force : Boolean := False)
10474 function Spec_Reloaded_For_Body return Boolean;
10475 -- Determine whether the compilation unit is a package body and the use
10476 -- type clause is in the spec of the same package. Even though the spec
10477 -- was analyzed first, its context is reloaded when analysing the body.
10479 procedure Use_Class_Wide_Operations (Typ : Entity_Id);
10480 -- AI05-150: if the use_type_clause carries the "all" qualifier,
10481 -- class-wide operations of ancestor types are use-visible if the
10482 -- ancestor type is visible.
10484 ----------------------------
10485 -- Spec_Reloaded_For_Body --
10486 ----------------------------
10488 function Spec_Reloaded_For_Body return Boolean is
10490 if Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body then
10492 Spec : constant Node_Id :=
10493 Parent (List_Containing (Parent (Id)));
10496 -- Check whether type is declared in a package specification,
10497 -- and current unit is the corresponding package body. The
10498 -- use clauses themselves may be within a nested package.
10501 Nkind (Spec) = N_Package_Specification
10502 and then In_Same_Source_Unit
10503 (Corresponding_Body (Parent (Spec)),
10504 Cunit_Entity (Current_Sem_Unit));
10509 end Spec_Reloaded_For_Body;
10511 -------------------------------
10512 -- Use_Class_Wide_Operations --
10513 -------------------------------
10515 procedure Use_Class_Wide_Operations (Typ : Entity_Id) is
10516 function Is_Class_Wide_Operation_Of
10518 T : Entity_Id) return Boolean;
10519 -- Determine whether a subprogram has a class-wide parameter or
10520 -- result that is T'Class.
10522 ---------------------------------
10523 -- Is_Class_Wide_Operation_Of --
10524 ---------------------------------
10526 function Is_Class_Wide_Operation_Of
10528 T : Entity_Id) return Boolean
10530 Formal : Entity_Id;
10533 Formal := First_Formal (Op);
10534 while Present (Formal) loop
10535 if Etype (Formal) = Class_Wide_Type (T) then
10539 Next_Formal (Formal);
10542 if Etype (Op) = Class_Wide_Type (T) then
10547 end Is_Class_Wide_Operation_Of;
10554 -- Start of processing for Use_Class_Wide_Operations
10557 Scop := Scope (Typ);
10558 if not Is_Hidden (Scop) then
10559 Ent := First_Entity (Scop);
10560 while Present (Ent) loop
10561 if Is_Overloadable (Ent)
10562 and then Is_Class_Wide_Operation_Of (Ent, Typ)
10563 and then not Is_Potentially_Use_Visible (Ent)
10565 Set_Is_Potentially_Use_Visible (Ent);
10566 Append_Elmt (Ent, Used_Operations (Parent (Id)));
10573 if Is_Derived_Type (Typ) then
10574 Use_Class_Wide_Operations (Etype (Base_Type (Typ)));
10576 end Use_Class_Wide_Operations;
10581 Is_Known_Used : Boolean;
10582 Op_List : Elist_Id;
10585 -- Start of processing for Use_One_Type
10588 if Entity (Id) = Any_Type then
10592 -- It is the type determined by the subtype mark (8.4(8)) whose
10593 -- operations become potentially use-visible.
10595 T := Base_Type (Entity (Id));
10597 -- Either the type itself is used, the package where it is declared is
10598 -- in use or the entity is declared in the current package, thus
10603 and then ((Present (Current_Use_Clause (T))
10604 and then All_Present (Current_Use_Clause (T)))
10605 or else not All_Present (Parent (Id))))
10606 or else In_Use (Scope (T))
10607 or else Scope (T) = Current_Scope;
10609 Set_Redundant_Use (Id,
10610 Is_Known_Used or else Is_Potentially_Use_Visible (T));
10612 if Ekind (T) = E_Incomplete_Type then
10613 Error_Msg_N ("premature usage of incomplete type", Id);
10615 elsif In_Open_Scopes (Scope (T)) then
10618 -- A limited view cannot appear in a use_type_clause. However, an access
10619 -- type whose designated type is limited has the flag but is not itself
10620 -- a limited view unless we only have a limited view of its enclosing
10623 elsif From_Limited_With (T) and then From_Limited_With (Scope (T)) then
10625 ("incomplete type from limited view cannot appear in use clause",
10628 -- If the use clause is redundant, Used_Operations will usually be
10629 -- empty, but we need to set it to empty here in one case: If we are
10630 -- instantiating a generic library unit, then we install the ancestors
10631 -- of that unit in the scope stack, which involves reprocessing use
10632 -- clauses in those ancestors. Such a use clause will typically have a
10633 -- nonempty Used_Operations unless it was redundant in the generic unit,
10634 -- even if it is redundant at the place of the instantiation.
10636 elsif Redundant_Use (Id) then
10637 Set_Used_Operations (Parent (Id), New_Elmt_List);
10639 -- If the subtype mark designates a subtype in a different package,
10640 -- we have to check that the parent type is visible, otherwise the
10641 -- use_type_clause is a no-op. Not clear how to do that???
10644 Set_Current_Use_Clause (T, Parent (Id));
10647 -- If T is tagged, primitive operators on class-wide operands are
10648 -- also deemed available. Note that this is really necessary only
10649 -- in semantics-only mode, because the primitive operators are not
10650 -- fully constructed in this mode, but we do it in all modes for the
10651 -- sake of uniformity, as this should not matter in practice.
10653 if Is_Tagged_Type (T) then
10654 Set_In_Use (Class_Wide_Type (T));
10657 -- Iterate over primitive operations of the type. If an operation is
10658 -- already use_visible, it is the result of a previous use_clause,
10659 -- and already appears on the corresponding entity chain. If the
10660 -- clause is being reinstalled, operations are already use-visible.
10666 Op_List := Collect_Primitive_Operations (T);
10667 Elmt := First_Elmt (Op_List);
10668 while Present (Elmt) loop
10669 if (Nkind (Node (Elmt)) = N_Defining_Operator_Symbol
10670 or else Chars (Node (Elmt)) in Any_Operator_Name)
10671 and then not Is_Hidden (Node (Elmt))
10672 and then not Is_Potentially_Use_Visible (Node (Elmt))
10674 Set_Is_Potentially_Use_Visible (Node (Elmt));
10675 Append_Elmt (Node (Elmt), Used_Operations (Parent (Id)));
10677 elsif Ada_Version >= Ada_2012
10678 and then All_Present (Parent (Id))
10679 and then not Is_Hidden (Node (Elmt))
10680 and then not Is_Potentially_Use_Visible (Node (Elmt))
10682 Set_Is_Potentially_Use_Visible (Node (Elmt));
10683 Append_Elmt (Node (Elmt), Used_Operations (Parent (Id)));
10690 if Ada_Version >= Ada_2012
10691 and then All_Present (Parent (Id))
10692 and then Is_Tagged_Type (T)
10694 Use_Class_Wide_Operations (T);
10698 -- If warning on redundant constructs, check for unnecessary WITH
10701 and then Warn_On_Redundant_Constructs
10702 and then Is_Known_Used
10704 -- with P; with P; use P;
10705 -- package P is package X is package body X is
10706 -- type T ... use P.T;
10708 -- The compilation unit is the body of X. GNAT first compiles the
10709 -- spec of X, then proceeds to the body. At that point P is marked
10710 -- as use visible. The analysis then reinstalls the spec along with
10711 -- its context. The use clause P.T is now recognized as redundant,
10712 -- but in the wrong context. Do not emit a warning in such cases.
10713 -- Do not emit a warning either if we are in an instance, there is
10714 -- no redundancy between an outer use_clause and one that appears
10715 -- within the generic.
10717 and then not Spec_Reloaded_For_Body
10718 and then not In_Instance
10719 and then not In_Inlined_Body
10721 -- The type already has a use clause
10725 -- Case where we know the current use clause for the type
10727 if Present (Current_Use_Clause (T)) then
10728 Use_Clause_Known : declare
10729 Clause1 : constant Node_Id :=
10730 Find_First_Use (Current_Use_Clause (T));
10731 Clause2 : constant Node_Id := Parent (Id);
10738 -- Start of processing for Use_Clause_Known
10741 -- If the unit is a subprogram body that acts as spec, the
10742 -- context clause is shared with the constructed subprogram
10743 -- spec. Clearly there is no redundancy.
10745 if Clause1 = Clause2 then
10749 Unit1 := Unit (Enclosing_Comp_Unit_Node (Clause1));
10750 Unit2 := Unit (Enclosing_Comp_Unit_Node (Clause2));
10752 -- If both clauses are on same unit, or one is the body of
10753 -- the other, or one of them is in a subunit, report
10754 -- redundancy on the later one.
10757 or else Nkind (Unit1) = N_Subunit
10759 (Nkind (Unit2) in N_Package_Body | N_Subprogram_Body
10760 and then Nkind (Unit1) /= Nkind (Unit2)
10761 and then Nkind (Unit1) /= N_Subunit)
10763 Error_Msg_Sloc := Sloc (Clause1);
10764 Error_Msg_NE -- CODEFIX
10765 ("& is already use-visible through previous "
10766 & "use_type_clause #?r?", Clause2, T);
10770 -- If there is a redundant use_type_clause in a child unit
10771 -- determine which of the units is more deeply nested. If a
10772 -- unit is a package instance, retrieve the entity and its
10773 -- scope from the instance spec.
10775 Ent1 := Entity_Of_Unit (Unit1);
10776 Ent2 := Entity_Of_Unit (Unit2);
10778 -- When the scope of both units' entities are
10779 -- Standard_Standard then neither Unit1 or Unit2 are child
10780 -- units - so return in that case.
10782 if Scope
(Ent1
) = Standard_Standard
10783 and then Scope
(Ent2
) = Standard_Standard
10787 -- Otherwise, determine if one of the units is not a child
10789 elsif Scope
(Ent2
) = Standard_Standard
then
10790 Error_Msg_Sloc
:= Sloc
(Clause2
);
10793 elsif Scope
(Ent1
) = Standard_Standard
then
10794 Error_Msg_Sloc
:= Sloc
(Id
);
10797 -- If both units are child units, we determine which one is
10798 -- the descendant by the scope distance to the ultimate
10807 S1
:= Scope
(Ent1
);
10808 S2
:= Scope
(Ent2
);
10810 and then Present
(S2
)
10811 and then S1
/= Standard_Standard
10812 and then S2
/= Standard_Standard
10818 if S1
= Standard_Standard
then
10819 Error_Msg_Sloc
:= Sloc
(Id
);
10822 Error_Msg_Sloc
:= Sloc
(Clause2
);
10828 if Parent
(Id
) /= Err_No
then
10829 if Most_Descendant_Use_Clause
10830 (Err_No
, Parent
(Id
)) = Parent
(Id
)
10832 Error_Msg_Sloc
:= Sloc
(Err_No
);
10833 Err_No
:= Parent
(Id
);
10836 Error_Msg_NE
-- CODEFIX
10837 ("& is already use-visible through previous "
10838 & "use_type_clause #?r?", Err_No
, Id
);
10840 end Use_Clause_Known
;
10842 -- Here Current_Use_Clause is not set for T, so we do not have the
10843 -- location information available.
10846 Error_Msg_NE
-- CODEFIX
10847 ("& is already use-visible through previous "
10848 & "use_type_clause?r?", Id
, T
);
10851 -- The package where T is declared is already used
10853 elsif In_Use
(Scope
(T
)) then
10854 -- Due to expansion of contracts we could be attempting to issue
10855 -- a spurious warning - so verify there is a previous use clause.
10857 if Current_Use_Clause
(Scope
(T
)) /=
10858 Find_First_Use
(Current_Use_Clause
(Scope
(T
)))
10861 Sloc
(Find_First_Use
(Current_Use_Clause
(Scope
(T
))));
10862 Error_Msg_NE
-- CODEFIX
10863 ("& is already use-visible through package use clause #?r?",
10867 -- The current scope is the package where T is declared
10870 Error_Msg_Node_2
:= Scope
(T
);
10871 Error_Msg_NE
-- CODEFIX
10872 ("& is already use-visible inside package &?r?", Id
, T
);
10881 procedure Write_Info
is
10882 Id
: Entity_Id
:= First_Entity
(Current_Scope
);
10885 -- No point in dumping standard entities
10887 if Current_Scope
= Standard_Standard
then
10891 Write_Str
("========================================================");
10893 Write_Str
(" Defined Entities in ");
10894 Write_Name
(Chars
(Current_Scope
));
10896 Write_Str
("========================================================");
10900 Write_Str
("-- none --");
10904 while Present
(Id
) loop
10905 Write_Entity_Info
(Id
, " ");
10910 if Scope
(Current_Scope
) = Standard_Standard
then
10912 -- Print information on the current unit itself
10914 Write_Entity_Info
(Current_Scope
, " ");
10927 for J
in reverse 1 .. Scope_Stack
.Last
loop
10928 S
:= Scope_Stack
.Table
(J
).Entity
;
10929 Write_Int
(Int
(S
));
10930 Write_Str
(" === ");
10931 Write_Name
(Chars
(S
));
10940 procedure we
(S
: Entity_Id
) is
10943 E
:= First_Entity
(S
);
10944 while Present
(E
) loop
10945 Write_Int
(Int
(E
));
10946 Write_Str
(" === ");
10947 Write_Name
(Chars
(E
));