1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Tss
; use Exp_Tss
;
33 with Exp_Util
; use Exp_Util
;
34 with Fname
; use Fname
;
35 with Freeze
; use Freeze
;
37 with Lib
.Load
; use Lib
.Load
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Namet
; use Namet
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
43 with Output
; use Output
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Cat
; use Sem_Cat
;
49 with Sem_Ch3
; use Sem_Ch3
;
50 with Sem_Ch4
; use Sem_Ch4
;
51 with Sem_Ch6
; use Sem_Ch6
;
52 with Sem_Ch12
; use Sem_Ch12
;
53 with Sem_Disp
; use Sem_Disp
;
54 with Sem_Dist
; use Sem_Dist
;
55 with Sem_Res
; use Sem_Res
;
56 with Sem_Util
; use Sem_Util
;
57 with Sem_Type
; use Sem_Type
;
58 with Stand
; use Stand
;
59 with Sinfo
; use Sinfo
;
60 with Sinfo
.CN
; use Sinfo
.CN
;
61 with Snames
; use Snames
;
62 with Style
; use Style
;
64 with Tbuild
; use Tbuild
;
65 with Uintp
; use Uintp
;
67 with GNAT
.Spelling_Checker
; use GNAT
.Spelling_Checker
;
69 package body Sem_Ch8
is
71 ------------------------------------
72 -- Visibility and Name Resolution --
73 ------------------------------------
75 -- This package handles name resolution and the collection of
76 -- interpretations for overloaded names, prior to overload resolution.
78 -- Name resolution is the process that establishes a mapping between source
79 -- identifiers and the entities they denote at each point in the program.
80 -- Each entity is represented by a defining occurrence. Each identifier
81 -- that denotes an entity points to the corresponding defining occurrence.
82 -- This is the entity of the applied occurrence. Each occurrence holds
83 -- an index into the names table, where source identifiers are stored.
85 -- Each entry in the names table for an identifier or designator uses the
86 -- Info pointer to hold a link to the currently visible entity that has
87 -- this name (see subprograms Get_Name_Entity_Id and Set_Name_Entity_Id
88 -- in package Sem_Util). The visibility is initialized at the beginning of
89 -- semantic processing to make entities in package Standard immediately
90 -- visible. The visibility table is used in a more subtle way when
91 -- compiling subunits (see below).
93 -- Entities that have the same name (i.e. homonyms) are chained. In the
94 -- case of overloaded entities, this chain holds all the possible meanings
95 -- of a given identifier. The process of overload resolution uses type
96 -- information to select from this chain the unique meaning of a given
99 -- Entities are also chained in their scope, through the Next_Entity link.
100 -- As a consequence, the name space is organized as a sparse matrix, where
101 -- each row corresponds to a scope, and each column to a source identifier.
102 -- Open scopes, that is to say scopes currently being compiled, have their
103 -- corresponding rows of entities in order, innermost scope first.
105 -- The scopes of packages that are mentioned in context clauses appear in
106 -- no particular order, interspersed among open scopes. This is because
107 -- in the course of analyzing the context of a compilation, a package
108 -- declaration is first an open scope, and subsequently an element of the
109 -- context. If subunits or child units are present, a parent unit may
110 -- appear under various guises at various times in the compilation.
112 -- When the compilation of the innermost scope is complete, the entities
113 -- defined therein are no longer visible. If the scope is not a package
114 -- declaration, these entities are never visible subsequently, and can be
115 -- removed from visibility chains. If the scope is a package declaration,
116 -- its visible declarations may still be accessible. Therefore the entities
117 -- defined in such a scope are left on the visibility chains, and only
118 -- their visibility (immediately visibility or potential use-visibility)
121 -- The ordering of homonyms on their chain does not necessarily follow
122 -- the order of their corresponding scopes on the scope stack. For
123 -- example, if package P and the enclosing scope both contain entities
124 -- named E, then when compiling the package body the chain for E will
125 -- hold the global entity first, and the local one (corresponding to
126 -- the current inner scope) next. As a result, name resolution routines
127 -- do not assume any relative ordering of the homonym chains, either
128 -- for scope nesting or to order of appearance of context clauses.
130 -- When compiling a child unit, entities in the parent scope are always
131 -- immediately visible. When compiling the body of a child unit, private
132 -- entities in the parent must also be made immediately visible. There
133 -- are separate routines to make the visible and private declarations
134 -- visible at various times (see package Sem_Ch7).
136 -- +--------+ +-----+
137 -- | In use |-------->| EU1 |-------------------------->
138 -- +--------+ +-----+
140 -- +--------+ +-----+ +-----+
141 -- | Stand. |---------------->| ES1 |--------------->| ES2 |--->
142 -- +--------+ +-----+ +-----+
144 -- +---------+ | +-----+
145 -- | with'ed |------------------------------>| EW2 |--->
146 -- +---------+ | +-----+
148 -- +--------+ +-----+ +-----+
149 -- | Scope2 |---------------->| E12 |--------------->| E22 |--->
150 -- +--------+ +-----+ +-----+
152 -- +--------+ +-----+ +-----+
153 -- | Scope1 |---------------->| E11 |--------------->| E12 |--->
154 -- +--------+ +-----+ +-----+
158 -- | | with'ed |----------------------------------------->
162 -- (innermost first) | |
163 -- +----------------------------+
164 -- Names table => | Id1 | | | | Id2 |
165 -- +----------------------------+
167 -- Name resolution must deal with several syntactic forms: simple names,
168 -- qualified names, indexed names, and various forms of calls.
170 -- Each identifier points to an entry in the names table. The resolution
171 -- of a simple name consists in traversing the homonym chain, starting
172 -- from the names table. If an entry is immediately visible, it is the one
173 -- designated by the identifier. If only potentially use-visible entities
174 -- are on the chain, we must verify that they do not hide each other. If
175 -- the entity we find is overloadable, we collect all other overloadable
176 -- entities on the chain as long as they are not hidden.
178 -- To resolve expanded names, we must find the entity at the intersection
179 -- of the entity chain for the scope (the prefix) and the homonym chain
180 -- for the selector. In general, homonym chains will be much shorter than
181 -- entity chains, so it is preferable to start from the names table as
182 -- well. If the entity found is overloadable, we must collect all other
183 -- interpretations that are defined in the scope denoted by the prefix.
185 -- For records, protected types, and tasks, their local entities are
186 -- removed from visibility chains on exit from the corresponding scope.
187 -- From the outside, these entities are always accessed by selected
188 -- notation, and the entity chain for the record type, protected type,
189 -- etc. is traversed sequentially in order to find the designated entity.
191 -- The discriminants of a type and the operations of a protected type or
192 -- task are unchained on exit from the first view of the type, (such as
193 -- a private or incomplete type declaration, or a protected type speci-
194 -- fication) and re-chained when compiling the second view.
196 -- In the case of operators, we do not make operators on derived types
197 -- explicit. As a result, the notation P."+" may denote either a user-
198 -- defined function with name "+", or else an implicit declaration of the
199 -- operator "+" in package P. The resolution of expanded names always
200 -- tries to resolve an operator name as such an implicitly defined entity,
201 -- in addition to looking for explicit declarations.
203 -- All forms of names that denote entities (simple names, expanded names,
204 -- character literals in some cases) have a Entity attribute, which
205 -- identifies the entity denoted by the name.
207 ---------------------
208 -- The Scope Stack --
209 ---------------------
211 -- The Scope stack keeps track of the scopes currently been compiled.
212 -- Every entity that contains declarations (including records) is placed
213 -- on the scope stack while it is being processed, and removed at the end.
214 -- Whenever a non-package scope is exited, the entities defined therein
215 -- are removed from the visibility table, so that entities in outer scopes
216 -- become visible (see previous description). On entry to Sem, the scope
217 -- stack only contains the package Standard. As usual, subunits complicate
218 -- this picture ever so slightly.
220 -- The Rtsfind mechanism can force a call to Semantics while another
221 -- compilation is in progress. The unit retrieved by Rtsfind must be
222 -- compiled in its own context, and has no access to the visibility of
223 -- the unit currently being compiled. The procedures Save_Scope_Stack and
224 -- Restore_Scope_Stack make entities in current open scopes invisible
225 -- before compiling the retrieved unit, and restore the compilation
226 -- environment afterwards.
228 ------------------------
229 -- Compiling subunits --
230 ------------------------
232 -- Subunits must be compiled in the environment of the corresponding
233 -- stub, that is to say with the same visibility into the parent (and its
234 -- context) that is available at the point of the stub declaration, but
235 -- with the additional visibility provided by the context clause of the
236 -- subunit itself. As a result, compilation of a subunit forces compilation
237 -- of the parent (see description in lib-). At the point of the stub
238 -- declaration, Analyze is called recursively to compile the proper body
239 -- of the subunit, but without reinitializing the names table, nor the
240 -- scope stack (i.e. standard is not pushed on the stack). In this fashion
241 -- the context of the subunit is added to the context of the parent, and
242 -- the subunit is compiled in the correct environment. Note that in the
243 -- course of processing the context of a subunit, Standard will appear
244 -- twice on the scope stack: once for the parent of the subunit, and
245 -- once for the unit in the context clause being compiled. However, the
246 -- two sets of entities are not linked by homonym chains, so that the
247 -- compilation of any context unit happens in a fresh visibility
250 -------------------------------
251 -- Processing of USE Clauses --
252 -------------------------------
254 -- Every defining occurrence has a flag indicating if it is potentially use
255 -- visible. Resolution of simple names examines this flag. The processing
256 -- of use clauses consists in setting this flag on all visible entities
257 -- defined in the corresponding package. On exit from the scope of the use
258 -- clause, the corresponding flag must be reset. However, a package may
259 -- appear in several nested use clauses (pathological but legal, alas!)
260 -- which forces us to use a slightly more involved scheme:
262 -- a) The defining occurrence for a package holds a flag -In_Use- to
263 -- indicate that it is currently in the scope of a use clause. If a
264 -- redundant use clause is encountered, then the corresponding occurrence
265 -- of the package name is flagged -Redundant_Use-.
267 -- b) On exit from a scope, the use clauses in its declarative part are
268 -- scanned. The visibility flag is reset in all entities declared in
269 -- package named in a use clause, as long as the package is not flagged
270 -- as being in a redundant use clause (in which case the outer use
271 -- clause is still in effect, and the direct visibility of its entities
272 -- must be retained).
274 -- Note that entities are not removed from their homonym chains on exit
275 -- from the package specification. A subsequent use clause does not need
276 -- to rechain the visible entities, but only to establish their direct
279 -----------------------------------
280 -- Handling private declarations --
281 -----------------------------------
283 -- The principle that each entity has a single defining occurrence clashes
284 -- with the presence of two separate definitions for private types: the
285 -- first is the private type declaration, and second is the full type
286 -- declaration. It is important that all references to the type point to
287 -- the same defining occurrence, namely the first one. To enforce the two
288 -- separate views of the entity, the corresponding information is swapped
289 -- between the two declarations. Outside of the package, the defining
290 -- occurrence only contains the private declaration information, while in
291 -- the private part and the body of the package the defining occurrence
292 -- contains the full declaration. To simplify the swap, the defining
293 -- occurrence that currently holds the private declaration points to the
294 -- full declaration. During semantic processing the defining occurrence
295 -- also points to a list of private dependents, that is to say access
296 -- types or composite types whose designated types or component types are
297 -- subtypes or derived types of the private type in question. After the
298 -- full declaration has been seen, the private dependents are updated to
299 -- indicate that they have full definitions.
301 ------------------------------------
302 -- Handling of Undefined Messages --
303 ------------------------------------
305 -- In normal mode, only the first use of an undefined identifier generates
306 -- a message. The table Urefs is used to record error messages that have
307 -- been issued so that second and subsequent ones do not generate further
308 -- messages. However, the second reference causes text to be added to the
309 -- original undefined message noting "(more references follow)". The
310 -- full error list option (-gnatf) forces messages to be generated for
311 -- every reference and disconnects the use of this table.
313 type Uref_Entry
is record
315 -- Node for identifier for which original message was posted. The
316 -- Chars field of this identifier is used to detect later references
317 -- to the same identifier.
320 -- Records error message Id of original undefined message. Reset to
321 -- No_Error_Msg after the second occurrence, where it is used to add
322 -- text to the original message as described above.
325 -- Set if the message is not visible rather than undefined
328 -- Records location of error message. Used to make sure that we do
329 -- not consider a, b : undefined as two separate instances, which
330 -- would otherwise happen, since the parser converts this sequence
331 -- to a : undefined; b : undefined.
335 package Urefs
is new Table
.Table
(
336 Table_Component_Type
=> Uref_Entry
,
337 Table_Index_Type
=> Nat
,
338 Table_Low_Bound
=> 1,
340 Table_Increment
=> 100,
341 Table_Name
=> "Urefs");
343 Candidate_Renaming
: Entity_Id
;
344 -- Holds a candidate interpretation that appears in a subprogram renaming
345 -- declaration and does not match the given specification, but matches at
346 -- least on the first formal. Allows better error message when given
347 -- specification omits defaulted parameters, a common error.
349 -----------------------
350 -- Local Subprograms --
351 -----------------------
353 procedure Analyze_Generic_Renaming
356 -- Common processing for all three kinds of generic renaming declarations.
357 -- Enter new name and indicate that it renames the generic unit.
359 procedure Analyze_Renamed_Character
363 -- Renamed entity is given by a character literal, which must belong
364 -- to the return type of the new entity. Is_Body indicates whether the
365 -- declaration is a renaming_as_body. If the original declaration has
366 -- already been frozen (because of an intervening body, e.g.) the body of
367 -- the function must be built now. The same applies to the following
368 -- various renaming procedures.
370 procedure Analyze_Renamed_Dereference
374 -- Renamed entity is given by an explicit dereference. Prefix must be a
375 -- conformant access_to_subprogram type.
377 procedure Analyze_Renamed_Entry
381 -- If the renamed entity in a subprogram renaming is an entry or protected
382 -- subprogram, build a body for the new entity whose only statement is a
383 -- call to the renamed entity.
385 procedure Analyze_Renamed_Family_Member
389 -- Used when the renamed entity is an indexed component. The prefix must
390 -- denote an entry family.
392 function Applicable_Use
(Pack_Name
: Node_Id
) return Boolean;
393 -- Common code to Use_One_Package and Set_Use, to determine whether
394 -- use clause must be processed. Pack_Name is an entity name that
395 -- references the package in question.
397 procedure Attribute_Renaming
(N
: Node_Id
);
398 -- Analyze renaming of attribute as function. The renaming declaration N
399 -- is rewritten as a function body that returns the attribute reference
400 -- applied to the formals of the function.
402 procedure Check_Frozen_Renaming
(N
: Node_Id
; Subp
: Entity_Id
);
403 -- A renaming_as_body may occur after the entity of the original decla-
404 -- ration has been frozen. In that case, the body of the new entity must
405 -- be built now, because the usual mechanism of building the renamed
406 -- body at the point of freezing will not work. Subp is the subprogram
407 -- for which N provides the Renaming_As_Body.
409 procedure Check_In_Previous_With_Clause
412 -- N is a use_package clause and Nam the package name, or N is a use_type
413 -- clause and Nam is the prefix of the type name. In either case, verify
414 -- that the package is visible at that point in the context: either it
415 -- appears in a previous with_clause, or because it is a fully qualified
416 -- name and the root ancestor appears in a previous with_clause.
418 procedure Check_Library_Unit_Renaming
(N
: Node_Id
; Old_E
: Entity_Id
);
419 -- Verify that the entity in a renaming declaration that is a library unit
420 -- is itself a library unit and not a nested unit or subunit. Also check
421 -- that if the renaming is a child unit of a generic parent, then the
422 -- renamed unit must also be a child unit of that parent. Finally, verify
423 -- that a renamed generic unit is not an implicit child declared within
424 -- an instance of the parent.
426 procedure Chain_Use_Clause
(N
: Node_Id
);
427 -- Chain use clause onto list of uses clauses headed by First_Use_Clause in
428 -- the proper scope table entry. This is usually the current scope, but it
429 -- will be an inner scope when installing the use clauses of the private
430 -- declarations of a parent unit prior to compiling the private part of a
431 -- child unit. This chain is traversed when installing/removing use clauses
432 -- when compiling a subunit or instantiating a generic body on the fly,
433 -- when it is necessary to save and restore full environments.
435 function Has_Implicit_Character_Literal
(N
: Node_Id
) return Boolean;
436 -- Find a type derived from Character or Wide_Character in the prefix of N.
437 -- Used to resolved qualified names whose selector is a character literal.
439 function Has_Private_With
(E
: Entity_Id
) return Boolean;
440 -- Ada 2005 (AI-262): Determines if the current compilation unit has a
443 procedure Find_Expanded_Name
(N
: Node_Id
);
444 -- Selected component is known to be expanded name. Verify legality
445 -- of selector given the scope denoted by prefix.
447 function Find_Renamed_Entity
451 Is_Actual
: Boolean := False) return Entity_Id
;
452 -- Find the renamed entity that corresponds to the given parameter profile
453 -- in a subprogram renaming declaration. The renamed entity may be an
454 -- operator, a subprogram, an entry, or a protected operation. Is_Actual
455 -- indicates that the renaming is the one generated for an actual subpro-
456 -- gram in an instance, for which special visibility checks apply.
458 function Has_Implicit_Operator
(N
: Node_Id
) return Boolean;
459 -- N is an expanded name whose selector is an operator name (eg P."+").
460 -- A declarative part contains an implicit declaration of an operator
461 -- if it has a declaration of a type to which one of the predefined
462 -- operators apply. The existence of this routine is an artifact of
463 -- our implementation: a more straightforward but more space-consuming
464 -- choice would be to make all inherited operators explicit in the
467 procedure Inherit_Renamed_Profile
(New_S
: Entity_Id
; Old_S
: Entity_Id
);
468 -- A subprogram defined by a renaming declaration inherits the parameter
469 -- profile of the renamed entity. The subtypes given in the subprogram
470 -- specification are discarded and replaced with those of the renamed
471 -- subprogram, which are then used to recheck the default values.
473 function Is_Appropriate_For_Record
(T
: Entity_Id
) return Boolean;
474 -- Prefix is appropriate for record if it is of a record type, or
475 -- an access to such.
477 function Is_Appropriate_For_Entry_Prefix
(T
: Entity_Id
) return Boolean;
478 -- True if it is of a task type, a protected type, or else an access
479 -- to one of these types.
481 procedure Note_Redundant_Use
(Clause
: Node_Id
);
482 -- Mark the name in a use clause as redundant if the corresponding
483 -- entity is already use-visible. Emit a warning if the use clause
484 -- comes from source and the proper warnings are enabled.
486 procedure Premature_Usage
(N
: Node_Id
);
487 -- Diagnose usage of an entity before it is visible
489 procedure Use_One_Package
(P
: Entity_Id
; N
: Node_Id
);
490 -- Make visible entities declared in package P potentially use-visible
491 -- in the current context. Also used in the analysis of subunits, when
492 -- re-installing use clauses of parent units. N is the use_clause that
493 -- names P (and possibly other packages).
495 procedure Use_One_Type
(Id
: Node_Id
);
496 -- Id is the subtype mark from a use type clause. This procedure makes
497 -- the primitive operators of the type potentially use-visible.
499 procedure Write_Info
;
500 -- Write debugging information on entities declared in current scope
502 procedure Write_Scopes
;
503 pragma Warnings
(Off
, Write_Scopes
);
504 -- Debugging information: dump all entities on scope stack
506 --------------------------------
507 -- Analyze_Exception_Renaming --
508 --------------------------------
510 -- The language only allows a single identifier, but the tree holds
511 -- an identifier list. The parser has already issued an error message
512 -- if there is more than one element in the list.
514 procedure Analyze_Exception_Renaming
(N
: Node_Id
) is
515 Id
: constant Node_Id
:= Defining_Identifier
(N
);
516 Nam
: constant Node_Id
:= Name
(N
);
522 Set_Ekind
(Id
, E_Exception
);
523 Set_Exception_Code
(Id
, Uint_0
);
524 Set_Etype
(Id
, Standard_Exception_Type
);
525 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
527 if not Is_Entity_Name
(Nam
) or else
528 Ekind
(Entity
(Nam
)) /= E_Exception
530 Error_Msg_N
("invalid exception name in renaming", Nam
);
532 if Present
(Renamed_Object
(Entity
(Nam
))) then
533 Set_Renamed_Object
(Id
, Renamed_Object
(Entity
(Nam
)));
535 Set_Renamed_Object
(Id
, Entity
(Nam
));
538 end Analyze_Exception_Renaming
;
540 ---------------------------
541 -- Analyze_Expanded_Name --
542 ---------------------------
544 procedure Analyze_Expanded_Name
(N
: Node_Id
) is
546 -- If the entity pointer is already set, this is an internal node, or
547 -- a node that is analyzed more than once, after a tree modification.
548 -- In such a case there is no resolution to perform, just set the type.
549 -- For completeness, analyze prefix as well.
551 if Present
(Entity
(N
)) then
552 if Is_Type
(Entity
(N
)) then
553 Set_Etype
(N
, Entity
(N
));
555 Set_Etype
(N
, Etype
(Entity
(N
)));
558 Analyze
(Prefix
(N
));
561 Find_Expanded_Name
(N
);
563 end Analyze_Expanded_Name
;
565 ---------------------------------------
566 -- Analyze_Generic_Function_Renaming --
567 ---------------------------------------
569 procedure Analyze_Generic_Function_Renaming
(N
: Node_Id
) is
571 Analyze_Generic_Renaming
(N
, E_Generic_Function
);
572 end Analyze_Generic_Function_Renaming
;
574 --------------------------------------
575 -- Analyze_Generic_Package_Renaming --
576 --------------------------------------
578 procedure Analyze_Generic_Package_Renaming
(N
: Node_Id
) is
580 -- Apply the Text_IO Kludge here, since we may be renaming
581 -- one of the subpackages of Text_IO, then join common routine.
583 Text_IO_Kludge
(Name
(N
));
585 Analyze_Generic_Renaming
(N
, E_Generic_Package
);
586 end Analyze_Generic_Package_Renaming
;
588 ----------------------------------------
589 -- Analyze_Generic_Procedure_Renaming --
590 ----------------------------------------
592 procedure Analyze_Generic_Procedure_Renaming
(N
: Node_Id
) is
594 Analyze_Generic_Renaming
(N
, E_Generic_Procedure
);
595 end Analyze_Generic_Procedure_Renaming
;
597 ------------------------------
598 -- Analyze_Generic_Renaming --
599 ------------------------------
601 procedure Analyze_Generic_Renaming
605 New_P
: constant Entity_Id
:= Defining_Entity
(N
);
607 Inst
: Boolean := False; -- prevent junk warning
610 if Name
(N
) = Error
then
614 Generate_Definition
(New_P
);
616 if Current_Scope
/= Standard_Standard
then
617 Set_Is_Pure
(New_P
, Is_Pure
(Current_Scope
));
620 if Nkind
(Name
(N
)) = N_Selected_Component
then
621 Check_Generic_Child_Unit
(Name
(N
), Inst
);
626 if not Is_Entity_Name
(Name
(N
)) then
627 Error_Msg_N
("expect entity name in renaming declaration", Name
(N
));
630 Old_P
:= Entity
(Name
(N
));
634 Set_Ekind
(New_P
, K
);
636 if Etype
(Old_P
) = Any_Type
then
639 elsif Ekind
(Old_P
) /= K
then
640 Error_Msg_N
("invalid generic unit name", Name
(N
));
643 if Present
(Renamed_Object
(Old_P
)) then
644 Set_Renamed_Object
(New_P
, Renamed_Object
(Old_P
));
646 Set_Renamed_Object
(New_P
, Old_P
);
649 Set_Etype
(New_P
, Etype
(Old_P
));
650 Set_Has_Completion
(New_P
);
652 if In_Open_Scopes
(Old_P
) then
653 Error_Msg_N
("within its scope, generic denotes its instance", N
);
656 Check_Library_Unit_Renaming
(N
, Old_P
);
659 end Analyze_Generic_Renaming
;
661 -----------------------------
662 -- Analyze_Object_Renaming --
663 -----------------------------
665 procedure Analyze_Object_Renaming
(N
: Node_Id
) is
666 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
668 Nam
: constant Node_Id
:= Name
(N
);
677 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
680 -- The renaming of a component that depends on a discriminant
681 -- requires an actual subtype, because in subsequent use of the object
682 -- Gigi will be unable to locate the actual bounds. This explicit step
683 -- is required when the renaming is generated in removing side effects
684 -- of an already-analyzed expression.
686 if Nkind
(Nam
) = N_Selected_Component
687 and then Analyzed
(Nam
)
690 Dec
:= Build_Actual_Subtype_Of_Component
(Etype
(Nam
), Nam
);
692 if Present
(Dec
) then
693 Insert_Action
(N
, Dec
);
694 T
:= Defining_Identifier
(Dec
);
698 elsif Present
(Subtype_Mark
(N
)) then
699 Find_Type
(Subtype_Mark
(N
));
700 T
:= Entity
(Subtype_Mark
(N
));
701 Analyze_And_Resolve
(Nam
, T
);
703 -- Ada 2005 (AI-230/AI-254): Access renaming
705 else pragma Assert
(Present
(Access_Definition
(N
)));
706 T
:= Access_Definition
708 N
=> Access_Definition
(N
));
710 Analyze_And_Resolve
(Nam
, T
);
712 -- Ada 2005 (AI-231): "In the case where the type is defined by an
713 -- access_definition, the renamed entity shall be of an access-to-
714 -- constant type if and only if the access_definition defines an
715 -- access-to-constant type" ARM 8.5.1(4)
717 if Constant_Present
(Access_Definition
(N
))
718 and then not Is_Access_Constant
(Etype
(Nam
))
720 Error_Msg_N
("(Ada 2005): the renamed object is not "
721 & "access-to-constant ('R'M 8.5.1(6))", N
);
723 elsif Null_Exclusion_Present
(Access_Definition
(N
)) then
724 Error_Msg_N
("(Ada 2005): null-excluding attribute ignored "
725 & "('R'M 8.5.1(6))?", N
);
729 -- An object renaming requires an exact match of the type;
730 -- class-wide matching is not allowed.
732 if Is_Class_Wide_Type
(T
)
733 and then Base_Type
(Etype
(Nam
)) /= Base_Type
(T
)
740 -- (Ada 2005: AI-326): Handle wrong use of incomplete type
742 if Nkind
(Nam
) = N_Explicit_Dereference
743 and then Ekind
(Etype
(T2
)) = E_Incomplete_Type
745 Error_Msg_N
("invalid use of incomplete type", Id
);
749 Set_Ekind
(Id
, E_Variable
);
750 Init_Size_Align
(Id
);
752 if T
= Any_Type
or else Etype
(Nam
) = Any_Type
then
755 -- Verify that the renamed entity is an object or a function call.
756 -- It may have been rewritten in several ways.
758 elsif Is_Object_Reference
(Nam
) then
759 if Comes_From_Source
(N
)
760 and then Is_Dependent_Component_Of_Mutable_Object
(Nam
)
763 ("illegal renaming of discriminant-dependent component", Nam
);
768 -- A static function call may have been folded into a literal
770 elsif Nkind
(Original_Node
(Nam
)) = N_Function_Call
772 -- When expansion is disabled, attribute reference is not
773 -- rewritten as function call. Otherwise it may be rewritten
774 -- as a conversion, so check original node.
776 or else (Nkind
(Original_Node
(Nam
)) = N_Attribute_Reference
777 and then Is_Function_Attribute_Name
778 (Attribute_Name
(Original_Node
(Nam
))))
780 -- Weird but legal, equivalent to renaming a function call
781 -- Illegal if the literal is the result of constant-folding
782 -- an attribute reference that is not a function.
784 or else (Is_Entity_Name
(Nam
)
785 and then Ekind
(Entity
(Nam
)) = E_Enumeration_Literal
787 Nkind
(Original_Node
(Nam
)) /= N_Attribute_Reference
)
789 or else (Nkind
(Nam
) = N_Type_Conversion
790 and then Is_Tagged_Type
(Entity
(Subtype_Mark
(Nam
))))
795 if Nkind
(Nam
) = N_Type_Conversion
then
797 ("renaming of conversion only allowed for tagged types", Nam
);
800 Error_Msg_N
("expect object name in renaming", Nam
);
806 if not Is_Variable
(Nam
) then
807 Set_Ekind
(Id
, E_Constant
);
808 Set_Never_Set_In_Source
(Id
, True);
809 Set_Is_True_Constant
(Id
, True);
812 Set_Renamed_Object
(Id
, Nam
);
813 end Analyze_Object_Renaming
;
815 ------------------------------
816 -- Analyze_Package_Renaming --
817 ------------------------------
819 procedure Analyze_Package_Renaming
(N
: Node_Id
) is
820 New_P
: constant Entity_Id
:= Defining_Entity
(N
);
825 if Name
(N
) = Error
then
829 -- Apply Text_IO kludge here, since we may be renaming one of
830 -- the children of Text_IO
832 Text_IO_Kludge
(Name
(N
));
834 if Current_Scope
/= Standard_Standard
then
835 Set_Is_Pure
(New_P
, Is_Pure
(Current_Scope
));
840 if Is_Entity_Name
(Name
(N
)) then
841 Old_P
:= Entity
(Name
(N
));
846 if Etype
(Old_P
) = Any_Type
then
848 ("expect package name in renaming", Name
(N
));
850 -- Ada 2005 (AI-50217): Limited withed packages cannot be renamed
852 elsif Ekind
(Old_P
) = E_Package
853 and then From_With_Type
(Old_P
)
856 ("limited withed package cannot be renamed", Name
(N
));
858 elsif Ekind
(Old_P
) /= E_Package
859 and then not (Ekind
(Old_P
) = E_Generic_Package
860 and then In_Open_Scopes
(Old_P
))
862 if Ekind
(Old_P
) = E_Generic_Package
then
864 ("generic package cannot be renamed as a package", Name
(N
));
866 Error_Msg_Sloc
:= Sloc
(Old_P
);
868 ("expect package name in renaming, found& declared#",
872 -- Set basic attributes to minimize cascaded errors
874 Set_Ekind
(New_P
, E_Package
);
875 Set_Etype
(New_P
, Standard_Void_Type
);
878 -- Entities in the old package are accessible through the
879 -- renaming entity. The simplest implementation is to have
880 -- both packages share the entity list.
882 Set_Ekind
(New_P
, E_Package
);
883 Set_Etype
(New_P
, Standard_Void_Type
);
885 if Present
(Renamed_Object
(Old_P
)) then
886 Set_Renamed_Object
(New_P
, Renamed_Object
(Old_P
));
888 Set_Renamed_Object
(New_P
, Old_P
);
891 Set_Has_Completion
(New_P
);
893 Set_First_Entity
(New_P
, First_Entity
(Old_P
));
894 Set_Last_Entity
(New_P
, Last_Entity
(Old_P
));
895 Set_First_Private_Entity
(New_P
, First_Private_Entity
(Old_P
));
896 Check_Library_Unit_Renaming
(N
, Old_P
);
897 Generate_Reference
(Old_P
, Name
(N
));
899 -- If this is the renaming declaration of a package instantiation
900 -- within itself, it is the declaration that ends the list of actuals
901 -- for the instantiation. At this point, the subtypes that rename
902 -- the actuals are flagged as generic, to avoid spurious ambiguities
903 -- if the actuals for two distinct formals happen to coincide. If
904 -- the actual is a private type, the subtype has a private completion
905 -- that is flagged in the same fashion.
907 -- Resolution is identical to what is was in the original generic.
908 -- On exit from the generic instance, these are turned into regular
909 -- subtypes again, so they are compatible with types in their class.
911 if not Is_Generic_Instance
(Old_P
) then
914 Spec
:= Specification
(Unit_Declaration_Node
(Old_P
));
917 if Nkind
(Spec
) = N_Package_Specification
918 and then Present
(Generic_Parent
(Spec
))
919 and then Old_P
= Current_Scope
920 and then Chars
(New_P
) = Chars
(Generic_Parent
(Spec
))
923 E
: Entity_Id
:= First_Entity
(Old_P
);
929 and then Nkind
(Parent
(E
)) = N_Subtype_Declaration
931 Set_Is_Generic_Actual_Type
(E
);
933 if Is_Private_Type
(E
)
934 and then Present
(Full_View
(E
))
936 Set_Is_Generic_Actual_Type
(Full_View
(E
));
946 end Analyze_Package_Renaming
;
948 -------------------------------
949 -- Analyze_Renamed_Character --
950 -------------------------------
952 procedure Analyze_Renamed_Character
957 C
: constant Node_Id
:= Name
(N
);
960 if Ekind
(New_S
) = E_Function
then
961 Resolve
(C
, Etype
(New_S
));
964 Check_Frozen_Renaming
(N
, New_S
);
968 Error_Msg_N
("character literal can only be renamed as function", N
);
970 end Analyze_Renamed_Character
;
972 ---------------------------------
973 -- Analyze_Renamed_Dereference --
974 ---------------------------------
976 procedure Analyze_Renamed_Dereference
981 Nam
: constant Node_Id
:= Name
(N
);
982 P
: constant Node_Id
:= Prefix
(Nam
);
988 if not Is_Overloaded
(P
) then
989 if Ekind
(Etype
(Nam
)) /= E_Subprogram_Type
990 or else not Type_Conformant
(Etype
(Nam
), New_S
) then
991 Error_Msg_N
("designated type does not match specification", P
);
1000 Get_First_Interp
(Nam
, Ind
, It
);
1002 while Present
(It
.Nam
) loop
1004 if Ekind
(It
.Nam
) = E_Subprogram_Type
1005 and then Type_Conformant
(It
.Nam
, New_S
) then
1007 if Typ
/= Any_Id
then
1008 Error_Msg_N
("ambiguous renaming", P
);
1015 Get_Next_Interp
(Ind
, It
);
1018 if Typ
= Any_Type
then
1019 Error_Msg_N
("designated type does not match specification", P
);
1024 Check_Frozen_Renaming
(N
, New_S
);
1028 end Analyze_Renamed_Dereference
;
1030 ---------------------------
1031 -- Analyze_Renamed_Entry --
1032 ---------------------------
1034 procedure Analyze_Renamed_Entry
1039 Nam
: constant Node_Id
:= Name
(N
);
1040 Sel
: constant Node_Id
:= Selector_Name
(Nam
);
1044 if Entity
(Sel
) = Any_Id
then
1046 -- Selector is undefined on prefix. Error emitted already
1048 Set_Has_Completion
(New_S
);
1052 -- Otherwise, find renamed entity, and build body of New_S as a call
1055 Old_S
:= Find_Renamed_Entity
(N
, Selector_Name
(Nam
), New_S
);
1057 if Old_S
= Any_Id
then
1058 Error_Msg_N
(" no subprogram or entry matches specification", N
);
1061 Check_Subtype_Conformant
(New_S
, Old_S
, N
);
1062 Generate_Reference
(New_S
, Defining_Entity
(N
), 'b');
1063 Style
.Check_Identifier
(Defining_Entity
(N
), New_S
);
1066 -- Only mode conformance required for a renaming_as_declaration
1068 Check_Mode_Conformant
(New_S
, Old_S
, N
);
1071 Inherit_Renamed_Profile
(New_S
, Old_S
);
1074 Set_Convention
(New_S
, Convention
(Old_S
));
1075 Set_Has_Completion
(New_S
, Inside_A_Generic
);
1078 Check_Frozen_Renaming
(N
, New_S
);
1080 end Analyze_Renamed_Entry
;
1082 -----------------------------------
1083 -- Analyze_Renamed_Family_Member --
1084 -----------------------------------
1086 procedure Analyze_Renamed_Family_Member
1091 Nam
: constant Node_Id
:= Name
(N
);
1092 P
: constant Node_Id
:= Prefix
(Nam
);
1096 if (Is_Entity_Name
(P
) and then Ekind
(Entity
(P
)) = E_Entry_Family
)
1097 or else (Nkind
(P
) = N_Selected_Component
1099 Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
)
1101 if Is_Entity_Name
(P
) then
1102 Old_S
:= Entity
(P
);
1104 Old_S
:= Entity
(Selector_Name
(P
));
1107 if not Entity_Matches_Spec
(Old_S
, New_S
) then
1108 Error_Msg_N
("entry family does not match specification", N
);
1111 Check_Subtype_Conformant
(New_S
, Old_S
, N
);
1112 Generate_Reference
(New_S
, Defining_Entity
(N
), 'b');
1113 Style
.Check_Identifier
(Defining_Entity
(N
), New_S
);
1116 Error_Msg_N
("no entry family matches specification", N
);
1119 Set_Has_Completion
(New_S
, Inside_A_Generic
);
1122 Check_Frozen_Renaming
(N
, New_S
);
1124 end Analyze_Renamed_Family_Member
;
1126 ---------------------------------
1127 -- Analyze_Subprogram_Renaming --
1128 ---------------------------------
1130 procedure Analyze_Subprogram_Renaming
(N
: Node_Id
) is
1131 Spec
: constant Node_Id
:= Specification
(N
);
1132 Save_AV
: constant Ada_Version_Type
:= Ada_Version
;
1133 Save_AV_Exp
: constant Ada_Version_Type
:= Ada_Version_Explicit
;
1134 Nam
: constant Node_Id
:= Name
(N
);
1136 Old_S
: Entity_Id
:= Empty
;
1137 Rename_Spec
: Entity_Id
;
1138 Formal_Spec
: constant Node_Id
:= Corresponding_Formal_Spec
(N
);
1139 Is_Actual
: constant Boolean := Present
(Formal_Spec
);
1140 Inst_Node
: Node_Id
:= Empty
;
1142 function Original_Subprogram
(Subp
: Entity_Id
) return Entity_Id
;
1143 -- Find renamed entity when the declaration is a renaming_as_body
1144 -- and the renamed entity may itself be a renaming_as_body. Used to
1145 -- enforce rule that a renaming_as_body is illegal if the declaration
1146 -- occurs before the subprogram it completes is frozen, and renaming
1147 -- indirectly renames the subprogram itself.(Defect Report 8652/0027).
1149 -------------------------
1150 -- Original_Subprogram --
1151 -------------------------
1153 function Original_Subprogram
(Subp
: Entity_Id
) return Entity_Id
is
1154 Orig_Decl
: Node_Id
;
1155 Orig_Subp
: Entity_Id
;
1158 -- First case: renamed entity is itself a renaming
1160 if Present
(Alias
(Subp
)) then
1161 return Alias
(Subp
);
1164 Nkind
(Unit_Declaration_Node
(Subp
)) = N_Subprogram_Declaration
1166 (Corresponding_Body
(Unit_Declaration_Node
(Subp
)))
1168 -- Check if renamed entity is a renaming_as_body
1171 Unit_Declaration_Node
1172 (Corresponding_Body
(Unit_Declaration_Node
(Subp
)));
1174 if Nkind
(Orig_Decl
) = N_Subprogram_Renaming_Declaration
then
1175 Orig_Subp
:= Entity
(Name
(Orig_Decl
));
1177 if Orig_Subp
= Rename_Spec
then
1179 -- Circularity detected
1184 return (Original_Subprogram
(Orig_Subp
));
1192 end Original_Subprogram
;
1194 -- Start of processing for Analyze_Subprogram_Renaming
1197 -- We must test for the attribute renaming case before the Analyze
1198 -- call because otherwise Sem_Attr will complain that the attribute
1199 -- is missing an argument when it is analyzed.
1201 if Nkind
(Nam
) = N_Attribute_Reference
then
1203 -- In the case of an abstract formal subprogram association,
1204 -- rewrite an actual given by a stream attribute as the name
1205 -- of the corresponding stream primitive of the type.
1207 -- In a generic context the stream operations are not generated,
1208 -- and this must be treated as a normal attribute reference, to
1209 -- be expanded in subsequent instantiations.
1211 if Is_Actual
and then Is_Abstract
(Formal_Spec
)
1212 and then Expander_Active
1215 Stream_Prim
: Entity_Id
;
1216 Prefix_Type
: constant Entity_Id
:= Entity
(Prefix
(Nam
));
1219 -- The class-wide forms of the stream attributes are not
1220 -- primitive dispatching operations (even though they
1221 -- internally dispatch to a stream attribute).
1223 if Is_Class_Wide_Type
(Prefix_Type
) then
1225 ("attribute must be a primitive dispatching operation",
1230 -- Retrieve the primitive subprogram associated with the
1231 -- attribute. This can only be a stream attribute, since
1232 -- those are the only ones that are dispatching (and the
1233 -- actual for an abstract formal subprogram must be a
1234 -- dispatching operation).
1236 case Attribute_Name
(Nam
) is
1239 Find_Prim_Op
(Prefix_Type
, TSS_Stream_Input
);
1242 Find_Prim_Op
(Prefix_Type
, TSS_Stream_Output
);
1245 Find_Prim_Op
(Prefix_Type
, TSS_Stream_Read
);
1248 Find_Prim_Op
(Prefix_Type
, TSS_Stream_Write
);
1251 ("attribute must be a primitive dispatching operation",
1256 -- Rewrite the attribute into the name of its corresponding
1257 -- primitive dispatching subprogram. We can then proceed with
1258 -- the usual processing for subprogram renamings.
1261 Prim_Name
: constant Node_Id
:=
1262 Make_Identifier
(Sloc
(Nam
),
1263 Chars
=> Chars
(Stream_Prim
));
1265 Set_Entity
(Prim_Name
, Stream_Prim
);
1266 Rewrite
(Nam
, Prim_Name
);
1271 -- Normal processing for a renaming of an attribute
1274 Attribute_Renaming
(N
);
1279 -- Check whether this declaration corresponds to the instantiation
1280 -- of a formal subprogram.
1282 -- If this is an instantiation, the corresponding actual is frozen
1283 -- and error messages can be made more precise. If this is a default
1284 -- subprogram, the entity is already established in the generic, and
1285 -- is not retrieved by visibility. If it is a default with a box, the
1286 -- candidate interpretations, if any, have been collected when building
1287 -- the renaming declaration. If overloaded, the proper interpretation
1288 -- is determined in Find_Renamed_Entity. If the entity is an operator,
1289 -- Find_Renamed_Entity applies additional visibility checks.
1292 Inst_Node
:= Unit_Declaration_Node
(Formal_Spec
);
1294 if Is_Entity_Name
(Nam
)
1295 and then Present
(Entity
(Nam
))
1296 and then not Comes_From_Source
(Nam
)
1297 and then not Is_Overloaded
(Nam
)
1299 Old_S
:= Entity
(Nam
);
1300 New_S
:= Analyze_Subprogram_Specification
(Spec
);
1304 if Ekind
(Entity
(Nam
)) = E_Operator
then
1308 if Box_Present
(Inst_Node
) then
1309 Old_S
:= Find_Renamed_Entity
(N
, Name
(N
), New_S
, Is_Actual
);
1311 -- If there is an immediately visible homonym of the operator
1312 -- and the declaration has a default, this is worth a warning
1313 -- because the user probably did not intend to get the pre-
1314 -- defined operator, visible in the generic declaration.
1315 -- To find if there is an intended candidate, analyze the
1316 -- renaming again in the current context.
1318 elsif Scope
(Old_S
) = Standard_Standard
1319 and then Present
(Default_Name
(Inst_Node
))
1322 Decl
: constant Node_Id
:= New_Copy_Tree
(N
);
1326 Set_Entity
(Name
(Decl
), Empty
);
1327 Analyze
(Name
(Decl
));
1329 Find_Renamed_Entity
(Decl
, Name
(Decl
), New_S
, True);
1332 and then In_Open_Scopes
(Scope
(Hidden
))
1333 and then Is_Immediately_Visible
(Hidden
)
1334 and then Comes_From_Source
(Hidden
)
1335 and then Hidden
/= Old_S
1337 Error_Msg_Sloc
:= Sloc
(Hidden
);
1338 Error_Msg_N
("?default subprogram is resolved " &
1339 "in the generic declaration " &
1340 "('R'M 12.6(17))", N
);
1341 Error_Msg_NE
("\?and will not use & #", N
, Hidden
);
1349 New_S
:= Analyze_Subprogram_Specification
(Spec
);
1353 -- Renamed entity must be analyzed first, to avoid being hidden by
1354 -- new name (which might be the same in a generic instance).
1358 -- The renaming defines a new overloaded entity, which is analyzed
1359 -- like a subprogram declaration.
1361 New_S
:= Analyze_Subprogram_Specification
(Spec
);
1364 if Current_Scope
/= Standard_Standard
then
1365 Set_Is_Pure
(New_S
, Is_Pure
(Current_Scope
));
1368 Rename_Spec
:= Find_Corresponding_Spec
(N
);
1370 if Present
(Rename_Spec
) then
1372 -- Renaming_As_Body. Renaming declaration is the completion of
1373 -- the declaration of Rename_Spec. We will build an actual body
1374 -- for it at the freezing point.
1376 Set_Corresponding_Spec
(N
, Rename_Spec
);
1377 if Nkind
(Unit_Declaration_Node
(Rename_Spec
)) =
1378 N_Abstract_Subprogram_Declaration
1380 -- Input and Output stream functions are abstract if the object
1381 -- type is abstract. However, these functions may receive explicit
1382 -- declarations in representation clauses, making the attribute
1383 -- subprograms usable as defaults in subsequent type extensions.
1384 -- In this case we rewrite the declaration to make the subprogram
1385 -- non-abstract. We remove the previous declaration, and insert
1386 -- the new one at the point of the renaming, to prevent premature
1387 -- access to unfrozen types. The new declaration reuses the
1388 -- specification of the previous one, and must not be analyzed.
1390 pragma Assert
(Is_TSS
(Rename_Spec
, TSS_Stream_Output
)
1391 or else Is_TSS
(Rename_Spec
, TSS_Stream_Input
));
1394 Old_Decl
: constant Node_Id
:=
1395 Unit_Declaration_Node
(Rename_Spec
);
1396 New_Decl
: constant Node_Id
:=
1397 Make_Subprogram_Declaration
(Sloc
(N
),
1399 Relocate_Node
(Specification
(Old_Decl
)));
1402 Insert_After
(N
, New_Decl
);
1403 Set_Is_Abstract
(Rename_Spec
, False);
1404 Set_Analyzed
(New_Decl
);
1408 Set_Corresponding_Body
(Unit_Declaration_Node
(Rename_Spec
), New_S
);
1410 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1411 Error_Msg_N
("(Ada 83) renaming cannot serve as a body", N
);
1414 Set_Convention
(New_S
, Convention
(Rename_Spec
));
1415 Check_Fully_Conformant
(New_S
, Rename_Spec
);
1416 Set_Public_Status
(New_S
);
1418 -- Indicate that the entity in the declaration functions like the
1419 -- corresponding body, and is not a new entity. The body will be
1420 -- constructed later at the freeze point, so indicate that the
1421 -- completion has not been seen yet.
1423 Set_Ekind
(New_S
, E_Subprogram_Body
);
1424 New_S
:= Rename_Spec
;
1425 Set_Has_Completion
(Rename_Spec
, False);
1427 -- Ada 2005: check overriding indicator
1429 if Must_Override
(Specification
(N
))
1430 and then not Is_Overriding_Operation
(Rename_Spec
)
1432 Error_Msg_NE
("subprogram& is not overriding", N
, Rename_Spec
);
1434 elsif Must_Not_Override
(Specification
(N
))
1435 and then Is_Overriding_Operation
(Rename_Spec
)
1438 ("subprogram& overrides inherited operation", N
, Rename_Spec
);
1442 Generate_Definition
(New_S
);
1443 New_Overloaded_Entity
(New_S
);
1445 if Is_Entity_Name
(Nam
)
1446 and then Is_Intrinsic_Subprogram
(Entity
(Nam
))
1450 Check_Delayed_Subprogram
(New_S
);
1454 -- There is no need for elaboration checks on the new entity, which may
1455 -- be called before the next freezing point where the body will appear.
1456 -- Elaboration checks refer to the real entity, not the one created by
1457 -- the renaming declaration.
1459 Set_Kill_Elaboration_Checks
(New_S
, True);
1461 if Etype
(Nam
) = Any_Type
then
1462 Set_Has_Completion
(New_S
);
1465 elsif Nkind
(Nam
) = N_Selected_Component
then
1467 -- Renamed entity is an entry or protected subprogram. For those
1468 -- cases an explicit body is built (at the point of freezing of this
1469 -- entity) that contains a call to the renamed entity.
1471 Analyze_Renamed_Entry
(N
, New_S
, Present
(Rename_Spec
));
1474 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
1476 -- Renamed entity is designated by access_to_subprogram expression.
1477 -- Must build body to encapsulate call, as in the entry case.
1479 Analyze_Renamed_Dereference
(N
, New_S
, Present
(Rename_Spec
));
1482 elsif Nkind
(Nam
) = N_Indexed_Component
then
1483 Analyze_Renamed_Family_Member
(N
, New_S
, Present
(Rename_Spec
));
1486 elsif Nkind
(Nam
) = N_Character_Literal
then
1487 Analyze_Renamed_Character
(N
, New_S
, Present
(Rename_Spec
));
1490 elsif (not Is_Entity_Name
(Nam
)
1491 and then Nkind
(Nam
) /= N_Operator_Symbol
)
1492 or else not Is_Overloadable
(Entity
(Nam
))
1494 Error_Msg_N
("expect valid subprogram name in renaming", N
);
1499 -- Most common case: subprogram renames subprogram. No body is generated
1500 -- in this case, so we must indicate the declaration is complete as is.
1502 if No
(Rename_Spec
) then
1503 Set_Has_Completion
(New_S
);
1506 -- Find the renamed entity that matches the given specification. Disable
1507 -- Ada_83 because there is no requirement of full conformance between
1508 -- renamed entity and new entity, even though the same circuit is used.
1510 -- This is a bit of a kludge, which introduces a really irregular use of
1511 -- Ada_Version[_Explicit]. Would be nice to find cleaner way to do this
1514 Ada_Version
:= Ada_Version_Type
'Max (Ada_Version
, Ada_95
);
1515 Ada_Version_Explicit
:= Ada_Version
;
1518 Old_S
:= Find_Renamed_Entity
(N
, Name
(N
), New_S
, Is_Actual
);
1521 if Old_S
/= Any_Id
then
1523 and then From_Default
(N
)
1525 -- This is an implicit reference to the default actual
1527 Generate_Reference
(Old_S
, Nam
, Typ
=> 'i', Force
=> True);
1529 Generate_Reference
(Old_S
, Nam
);
1532 -- For a renaming-as-body, require subtype conformance, but if the
1533 -- declaration being completed has not been frozen, then inherit the
1534 -- convention of the renamed subprogram prior to checking conformance
1535 -- (unless the renaming has an explicit convention established; the
1536 -- rule stated in the RM doesn't seem to address this ???).
1538 if Present
(Rename_Spec
) then
1539 Generate_Reference
(Rename_Spec
, Defining_Entity
(Spec
), 'b');
1540 Style
.Check_Identifier
(Defining_Entity
(Spec
), Rename_Spec
);
1542 if not Is_Frozen
(Rename_Spec
) then
1543 if not Has_Convention_Pragma
(Rename_Spec
) then
1544 Set_Convention
(New_S
, Convention
(Old_S
));
1547 if Ekind
(Old_S
) /= E_Operator
then
1548 Check_Mode_Conformant
(New_S
, Old_S
, Spec
);
1551 if Original_Subprogram
(Old_S
) = Rename_Spec
then
1552 Error_Msg_N
("unfrozen subprogram cannot rename itself ", N
);
1555 Check_Subtype_Conformant
(New_S
, Old_S
, Spec
);
1558 Check_Frozen_Renaming
(N
, Rename_Spec
);
1560 -- Check explicitly that renamed entity is not intrinsic, because
1561 -- in in a generic the renamed body is not built. In this case,
1562 -- the renaming_as_body is a completion.
1564 if Inside_A_Generic
then
1565 if Is_Frozen
(Rename_Spec
)
1566 and then Is_Intrinsic_Subprogram
(Old_S
)
1569 ("subprogram in renaming_as_body cannot be intrinsic",
1573 Set_Has_Completion
(Rename_Spec
);
1576 elsif Ekind
(Old_S
) /= E_Operator
then
1577 Check_Mode_Conformant
(New_S
, Old_S
);
1580 and then Error_Posted
(New_S
)
1582 Error_Msg_NE
("invalid actual subprogram: & #!", N
, Old_S
);
1586 if No
(Rename_Spec
) then
1588 -- The parameter profile of the new entity is that of the renamed
1589 -- entity: the subtypes given in the specification are irrelevant.
1591 Inherit_Renamed_Profile
(New_S
, Old_S
);
1593 -- A call to the subprogram is transformed into a call to the
1594 -- renamed entity. This is transitive if the renamed entity is
1595 -- itself a renaming.
1597 if Present
(Alias
(Old_S
)) then
1598 Set_Alias
(New_S
, Alias
(Old_S
));
1600 Set_Alias
(New_S
, Old_S
);
1603 -- Note that we do not set Is_Intrinsic_Subprogram if we have a
1604 -- renaming as body, since the entity in this case is not an
1605 -- intrinsic (it calls an intrinsic, but we have a real body for
1606 -- this call, and it is in this body that the required intrinsic
1607 -- processing will take place).
1609 -- Also, if this is a renaming of inequality, the renamed operator
1610 -- is intrinsic, but what matters is the corresponding equality
1611 -- operator, which may be user-defined.
1613 Set_Is_Intrinsic_Subprogram
1615 Is_Intrinsic_Subprogram
(Old_S
)
1617 (Chars
(Old_S
) /= Name_Op_Ne
1618 or else Ekind
(Old_S
) = E_Operator
1620 Is_Intrinsic_Subprogram
1621 (Corresponding_Equality
(Old_S
))));
1623 if Ekind
(Alias
(New_S
)) = E_Operator
then
1624 Set_Has_Delayed_Freeze
(New_S
, False);
1627 -- If the renaming corresponds to an association for an abstract
1628 -- formal subprogram, then various attributes must be set to
1629 -- indicate that the renaming is an abstract dispatching operation
1630 -- with a controlling type.
1632 if Is_Actual
and then Is_Abstract
(Formal_Spec
) then
1633 -- Mark the renaming as abstract here, so Find_Dispatching_Type
1634 -- see it as corresponding to a generic association for a
1635 -- formal abstract subprogram
1637 Set_Is_Abstract
(New_S
);
1640 New_S_Ctrl_Type
: constant Entity_Id
:=
1641 Find_Dispatching_Type
(New_S
);
1642 Old_S_Ctrl_Type
: constant Entity_Id
:=
1643 Find_Dispatching_Type
(Old_S
);
1646 if Old_S_Ctrl_Type
/= New_S_Ctrl_Type
then
1648 ("actual must be dispatching subprogram for type&",
1649 Nam
, New_S_Ctrl_Type
);
1652 Set_Is_Dispatching_Operation
(New_S
);
1653 Check_Controlling_Formals
(New_S_Ctrl_Type
, New_S
);
1655 -- In the case where the actual in the formal subprogram
1656 -- is itself a formal abstract subprogram association,
1657 -- there's no dispatch table component or position to
1660 if Present
(DTC_Entity
(Old_S
)) then
1661 Set_DTC_Entity
(New_S
, DTC_Entity
(Old_S
));
1662 Set_DT_Position
(New_S
, DT_Position
(Old_S
));
1670 and then (Old_S
= New_S
1671 or else (Nkind
(Nam
) /= N_Expanded_Name
1672 and then Chars
(Old_S
) = Chars
(New_S
)))
1674 Error_Msg_N
("subprogram cannot rename itself", N
);
1677 Set_Convention
(New_S
, Convention
(Old_S
));
1678 Set_Is_Abstract
(New_S
, Is_Abstract
(Old_S
));
1679 Check_Library_Unit_Renaming
(N
, Old_S
);
1681 -- Pathological case: procedure renames entry in the scope of its
1682 -- task. Entry is given by simple name, but body must be built for
1683 -- procedure. Of course if called it will deadlock.
1685 if Ekind
(Old_S
) = E_Entry
then
1686 Set_Has_Completion
(New_S
, False);
1687 Set_Alias
(New_S
, Empty
);
1691 Freeze_Before
(N
, Old_S
);
1692 Set_Has_Delayed_Freeze
(New_S
, False);
1693 Freeze_Before
(N
, New_S
);
1695 -- An abstract subprogram is only allowed as an actual in the case
1696 -- where the formal subprogram is also abstract.
1698 if (Ekind
(Old_S
) = E_Procedure
or else Ekind
(Old_S
) = E_Function
)
1699 and then Is_Abstract
(Old_S
)
1700 and then not Is_Abstract
(Formal_Spec
)
1703 ("abstract subprogram not allowed as generic actual", Nam
);
1708 -- A common error is to assume that implicit operators for types are
1709 -- defined in Standard, or in the scope of a subtype. In those cases
1710 -- where the renamed entity is given with an expanded name, it is
1711 -- worth mentioning that operators for the type are not declared in
1712 -- the scope given by the prefix.
1714 if Nkind
(Nam
) = N_Expanded_Name
1715 and then Nkind
(Selector_Name
(Nam
)) = N_Operator_Symbol
1716 and then Scope
(Entity
(Nam
)) = Standard_Standard
1719 T
: constant Entity_Id
:=
1720 Base_Type
(Etype
(First_Formal
(New_S
)));
1723 Error_Msg_Node_2
:= Prefix
(Nam
);
1725 ("operator for type& is not declared in&", Prefix
(Nam
), T
);
1730 ("no visible subprogram matches the specification for&",
1734 if Present
(Candidate_Renaming
) then
1740 F1
:= First_Formal
(Candidate_Renaming
);
1741 F2
:= First_Formal
(New_S
);
1743 while Present
(F1
) and then Present
(F2
) loop
1748 if Present
(F1
) and then Present
(Default_Value
(F1
)) then
1749 if Present
(Next_Formal
(F1
)) then
1751 ("\missing specification for &" &
1752 " and other formals with defaults", Spec
, F1
);
1755 ("\missing specification for &", Spec
, F1
);
1762 -- Ada 2005 AI 404: if the new subprogram is dispatching, verify that
1763 -- controlling access parameters are known non-null for the renamed
1764 -- subprogram. Test also applies to a subprogram instantiation that
1767 if Ada_Version
>= Ada_05
1768 and then not Is_Dispatching_Operation
(Old_S
)
1769 and then Is_Dispatching_Operation
(New_S
)
1776 Old_F
:= First_Formal
(Old_S
);
1777 New_F
:= First_Formal
(New_S
);
1778 while Present
(Old_F
) loop
1779 if Ekind
(Etype
(Old_F
)) = E_Anonymous_Access_Type
1780 and then Is_Controlling_Formal
(New_F
)
1781 and then not Can_Never_Be_Null
(Old_F
)
1783 Error_Msg_N
("access parameter is controlling,", New_F
);
1784 Error_Msg_NE
("\corresponding parameter of& " &
1785 " must be explicitly null excluding", New_F
, Old_S
);
1788 Next_Formal
(Old_F
);
1789 Next_Formal
(New_F
);
1794 -- A useful warning, suggested by Ada Bug Finder (Ada-Europe 2005)
1796 if Comes_From_Source
(N
)
1797 and then Present
(Old_S
)
1798 and then Nkind
(Old_S
) = N_Defining_Operator_Symbol
1799 and then Nkind
(New_S
) = N_Defining_Operator_Symbol
1800 and then Chars
(Old_S
) /= Chars
(New_S
)
1803 ("?& is being renamed as a different operator",
1807 Ada_Version
:= Save_AV
;
1808 Ada_Version_Explicit
:= Save_AV_Exp
;
1809 end Analyze_Subprogram_Renaming
;
1811 -------------------------
1812 -- Analyze_Use_Package --
1813 -------------------------
1815 -- Resolve the package names in the use clause, and make all the visible
1816 -- entities defined in the package potentially use-visible. If the package
1817 -- is already in use from a previous use clause, its visible entities are
1818 -- already use-visible. In that case, mark the occurrence as a redundant
1819 -- use. If the package is an open scope, i.e. if the use clause occurs
1820 -- within the package itself, ignore it.
1822 procedure Analyze_Use_Package
(N
: Node_Id
) is
1823 Pack_Name
: Node_Id
;
1826 -- Start of processing for Analyze_Use_Package
1829 Set_Hidden_By_Use_Clause
(N
, No_Elist
);
1831 -- Use clause is not allowed in a spec of a predefined package
1832 -- declaration except that packages whose file name starts a-n are OK
1833 -- (these are children of Ada.Numerics, and such packages are never
1834 -- loaded by Rtsfind).
1836 if Is_Predefined_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
1837 and then Name_Buffer
(1 .. 3) /= "a-n"
1839 Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Declaration
1841 Error_Msg_N
("use clause not allowed in predefined spec", N
);
1844 -- Chain clause to list of use clauses in current scope
1846 if Nkind
(Parent
(N
)) /= N_Compilation_Unit
then
1847 Chain_Use_Clause
(N
);
1850 -- Loop through package names to identify referenced packages
1852 Pack_Name
:= First
(Names
(N
));
1854 while Present
(Pack_Name
) loop
1855 Analyze
(Pack_Name
);
1857 if Nkind
(Parent
(N
)) = N_Compilation_Unit
1858 and then Nkind
(Pack_Name
) = N_Expanded_Name
1861 Pref
: Node_Id
:= Prefix
(Pack_Name
);
1864 while Nkind
(Pref
) = N_Expanded_Name
loop
1865 Pref
:= Prefix
(Pref
);
1868 if Entity
(Pref
) = Standard_Standard
then
1870 ("predefined package Standard cannot appear"
1871 & " in a context clause", Pref
);
1879 -- Loop through package names to mark all entities as potentially
1882 Pack_Name
:= First
(Names
(N
));
1884 while Present
(Pack_Name
) loop
1886 if Is_Entity_Name
(Pack_Name
) then
1887 Pack
:= Entity
(Pack_Name
);
1889 if Ekind
(Pack
) /= E_Package
1890 and then Etype
(Pack
) /= Any_Type
1892 if Ekind
(Pack
) = E_Generic_Package
then
1894 ("a generic package is not allowed in a use clause",
1897 Error_Msg_N
("& is not a usable package", Pack_Name
);
1901 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1902 Check_In_Previous_With_Clause
(N
, Pack_Name
);
1905 if Applicable_Use
(Pack_Name
) then
1906 Use_One_Package
(Pack
, N
);
1914 end Analyze_Use_Package
;
1916 ----------------------
1917 -- Analyze_Use_Type --
1918 ----------------------
1920 procedure Analyze_Use_Type
(N
: Node_Id
) is
1924 Set_Hidden_By_Use_Clause
(N
, No_Elist
);
1926 -- Chain clause to list of use clauses in current scope
1928 if Nkind
(Parent
(N
)) /= N_Compilation_Unit
then
1929 Chain_Use_Clause
(N
);
1932 Id
:= First
(Subtype_Marks
(N
));
1934 while Present
(Id
) loop
1937 if Entity
(Id
) /= Any_Type
then
1940 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1941 if Nkind
(Id
) = N_Identifier
then
1942 Error_Msg_N
("type is not directly visible", Id
);
1944 elsif Is_Child_Unit
(Scope
(Entity
(Id
)))
1945 and then Scope
(Entity
(Id
)) /= System_Aux_Id
1947 Check_In_Previous_With_Clause
(N
, Prefix
(Id
));
1954 end Analyze_Use_Type
;
1956 --------------------
1957 -- Applicable_Use --
1958 --------------------
1960 function Applicable_Use
(Pack_Name
: Node_Id
) return Boolean is
1961 Pack
: constant Entity_Id
:= Entity
(Pack_Name
);
1964 if In_Open_Scopes
(Pack
) then
1967 elsif In_Use
(Pack
) then
1968 Note_Redundant_Use
(Pack_Name
);
1971 elsif Present
(Renamed_Object
(Pack
))
1972 and then In_Use
(Renamed_Object
(Pack
))
1974 Note_Redundant_Use
(Pack_Name
);
1982 ------------------------
1983 -- Attribute_Renaming --
1984 ------------------------
1986 procedure Attribute_Renaming
(N
: Node_Id
) is
1987 Loc
: constant Source_Ptr
:= Sloc
(N
);
1988 Nam
: constant Node_Id
:= Name
(N
);
1989 Spec
: constant Node_Id
:= Specification
(N
);
1990 New_S
: constant Entity_Id
:= Defining_Unit_Name
(Spec
);
1991 Aname
: constant Name_Id
:= Attribute_Name
(Nam
);
1993 Form_Num
: Nat
:= 0;
1994 Expr_List
: List_Id
:= No_List
;
1996 Attr_Node
: Node_Id
;
1997 Body_Node
: Node_Id
;
1998 Param_Spec
: Node_Id
;
2001 Generate_Definition
(New_S
);
2003 -- This procedure is called in the context of subprogram renaming,
2004 -- and thus the attribute must be one that is a subprogram. All of
2005 -- those have at least one formal parameter, with the singular
2006 -- exception of AST_Entry (which is a real oddity, it is odd that
2007 -- this can be renamed at all!)
2009 if not Is_Non_Empty_List
(Parameter_Specifications
(Spec
)) then
2010 if Aname
/= Name_AST_Entry
then
2012 ("subprogram renaming an attribute must have formals", N
);
2017 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
2019 while Present
(Param_Spec
) loop
2020 Form_Num
:= Form_Num
+ 1;
2022 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
2023 Find_Type
(Parameter_Type
(Param_Spec
));
2025 -- The profile of the new entity denotes the base type (s) of
2026 -- the types given in the specification. For access parameters
2027 -- there are no subtypes involved.
2029 Rewrite
(Parameter_Type
(Param_Spec
),
2031 (Base_Type
(Entity
(Parameter_Type
(Param_Spec
))), Loc
));
2034 if No
(Expr_List
) then
2035 Expr_List
:= New_List
;
2038 Append_To
(Expr_List
,
2039 Make_Identifier
(Loc
,
2040 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
2042 -- The expressions in the attribute reference are not freeze
2043 -- points. Neither is the attribute as a whole, see below.
2045 Set_Must_Not_Freeze
(Last
(Expr_List
));
2050 -- Immediate error if too many formals. Other mismatches in numbers
2051 -- of number of types of parameters are detected when we analyze the
2052 -- body of the subprogram that we construct.
2054 if Form_Num
> 2 then
2055 Error_Msg_N
("too many formals for attribute", N
);
2057 -- Error if the attribute reference has expressions that look
2058 -- like formal parameters.
2060 elsif Present
(Expressions
(Nam
)) then
2061 Error_Msg_N
("illegal expressions in attribute reference", Nam
);
2064 Aname
= Name_Compose
or else
2065 Aname
= Name_Exponent
or else
2066 Aname
= Name_Leading_Part
or else
2067 Aname
= Name_Pos
or else
2068 Aname
= Name_Round
or else
2069 Aname
= Name_Scaling
or else
2072 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
2073 and then Present
(Corresponding_Formal_Spec
(N
))
2076 ("generic actual cannot be attribute involving universal type",
2080 ("attribute involving a universal type cannot be renamed",
2085 -- AST_Entry is an odd case. It doesn't really make much sense to
2086 -- allow it to be renamed, but that's the DEC rule, so we have to
2087 -- do it right. The point is that the AST_Entry call should be made
2088 -- now, and what the function will return is the returned value.
2090 -- Note that there is no Expr_List in this case anyway
2092 if Aname
= Name_AST_Entry
then
2099 Ent
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
2102 Make_Object_Declaration
(Loc
,
2103 Defining_Identifier
=> Ent
,
2104 Object_Definition
=>
2105 New_Occurrence_Of
(RTE
(RE_AST_Handler
), Loc
),
2107 Constant_Present
=> True);
2109 Set_Assignment_OK
(Decl
, True);
2110 Insert_Action
(N
, Decl
);
2111 Attr_Node
:= Make_Identifier
(Loc
, Chars
(Ent
));
2114 -- For all other attributes, we rewrite the attribute node to have
2115 -- a list of expressions corresponding to the subprogram formals.
2116 -- A renaming declaration is not a freeze point, and the analysis of
2117 -- the attribute reference should not freeze the type of the prefix.
2121 Make_Attribute_Reference
(Loc
,
2122 Prefix
=> Prefix
(Nam
),
2123 Attribute_Name
=> Aname
,
2124 Expressions
=> Expr_List
);
2126 Set_Must_Not_Freeze
(Attr_Node
);
2127 Set_Must_Not_Freeze
(Prefix
(Nam
));
2130 -- Case of renaming a function
2132 if Nkind
(Spec
) = N_Function_Specification
then
2134 if Is_Procedure_Attribute_Name
(Aname
) then
2135 Error_Msg_N
("attribute can only be renamed as procedure", Nam
);
2139 Find_Type
(Result_Definition
(Spec
));
2140 Rewrite
(Result_Definition
(Spec
),
2142 Base_Type
(Entity
(Result_Definition
(Spec
))), Loc
));
2145 Make_Subprogram_Body
(Loc
,
2146 Specification
=> Spec
,
2147 Declarations
=> New_List
,
2148 Handled_Statement_Sequence
=>
2149 Make_Handled_Sequence_Of_Statements
(Loc
,
2150 Statements
=> New_List
(
2151 Make_Return_Statement
(Loc
,
2152 Expression
=> Attr_Node
))));
2154 -- Case of renaming a procedure
2157 if not Is_Procedure_Attribute_Name
(Aname
) then
2158 Error_Msg_N
("attribute can only be renamed as function", Nam
);
2163 Make_Subprogram_Body
(Loc
,
2164 Specification
=> Spec
,
2165 Declarations
=> New_List
,
2166 Handled_Statement_Sequence
=>
2167 Make_Handled_Sequence_Of_Statements
(Loc
,
2168 Statements
=> New_List
(Attr_Node
)));
2171 Rewrite
(N
, Body_Node
);
2174 if Is_Compilation_Unit
(New_S
) then
2176 ("a library unit can only rename another library unit", N
);
2179 Set_Etype
(New_S
, Base_Type
(Etype
(New_S
)));
2181 -- We suppress elaboration warnings for the resulting entity, since
2182 -- clearly they are not needed, and more particularly, in the case
2183 -- of a generic formal subprogram, the resulting entity can appear
2184 -- after the instantiation itself, and thus look like a bogus case
2185 -- of access before elaboration.
2187 Set_Suppress_Elaboration_Warnings
(New_S
);
2189 end Attribute_Renaming
;
2191 ----------------------
2192 -- Chain_Use_Clause --
2193 ----------------------
2195 procedure Chain_Use_Clause
(N
: Node_Id
) is
2197 Level
: Int
:= Scope_Stack
.Last
;
2200 if not Is_Compilation_Unit
(Current_Scope
)
2201 or else not Is_Child_Unit
(Current_Scope
)
2203 null; -- Common case
2205 elsif Defining_Entity
(Parent
(N
)) = Current_Scope
then
2206 null; -- Common case for compilation unit
2209 -- If declaration appears in some other scope, it must be in some
2210 -- parent unit when compiling a child.
2212 Pack
:= Defining_Entity
(Parent
(N
));
2213 if not In_Open_Scopes
(Pack
) then
2214 null; -- default as well
2217 -- Find entry for parent unit in scope stack
2219 while Scope_Stack
.Table
(Level
).Entity
/= Pack
loop
2225 Set_Next_Use_Clause
(N
,
2226 Scope_Stack
.Table
(Level
).First_Use_Clause
);
2227 Scope_Stack
.Table
(Level
).First_Use_Clause
:= N
;
2228 end Chain_Use_Clause
;
2230 ---------------------------
2231 -- Check_Frozen_Renaming --
2232 ---------------------------
2234 procedure Check_Frozen_Renaming
(N
: Node_Id
; Subp
: Entity_Id
) is
2240 and then not Has_Completion
(Subp
)
2244 (Parent
(Declaration_Node
(Subp
)), Defining_Entity
(N
));
2246 if Is_Entity_Name
(Name
(N
)) then
2247 Old_S
:= Entity
(Name
(N
));
2249 if not Is_Frozen
(Old_S
)
2250 and then Operating_Mode
/= Check_Semantics
2252 Append_Freeze_Action
(Old_S
, B_Node
);
2254 Insert_After
(N
, B_Node
);
2258 if Is_Intrinsic_Subprogram
(Old_S
)
2259 and then not In_Instance
2262 ("subprogram used in renaming_as_body cannot be intrinsic",
2267 Insert_After
(N
, B_Node
);
2271 end Check_Frozen_Renaming
;
2273 -----------------------------------
2274 -- Check_In_Previous_With_Clause --
2275 -----------------------------------
2277 procedure Check_In_Previous_With_Clause
2281 Pack
: constant Entity_Id
:= Entity
(Original_Node
(Nam
));
2286 Item
:= First
(Context_Items
(Parent
(N
)));
2288 while Present
(Item
)
2291 if Nkind
(Item
) = N_With_Clause
2293 -- Protect the frontend against previously reported
2296 and then Nkind
(Name
(Item
)) /= N_Selected_Component
2297 and then Entity
(Name
(Item
)) = Pack
2301 -- Find root library unit in with_clause
2303 while Nkind
(Par
) = N_Expanded_Name
loop
2304 Par
:= Prefix
(Par
);
2307 if Is_Child_Unit
(Entity
(Original_Node
(Par
))) then
2309 ("& is not directly visible", Par
, Entity
(Par
));
2318 -- On exit, package is not mentioned in a previous with_clause.
2319 -- Check if its prefix is.
2321 if Nkind
(Nam
) = N_Expanded_Name
then
2322 Check_In_Previous_With_Clause
(N
, Prefix
(Nam
));
2324 elsif Pack
/= Any_Id
then
2325 Error_Msg_NE
("& is not visible", Nam
, Pack
);
2327 end Check_In_Previous_With_Clause
;
2329 ---------------------------------
2330 -- Check_Library_Unit_Renaming --
2331 ---------------------------------
2333 procedure Check_Library_Unit_Renaming
(N
: Node_Id
; Old_E
: Entity_Id
) is
2337 if Nkind
(Parent
(N
)) /= N_Compilation_Unit
then
2340 elsif Scope
(Old_E
) /= Standard_Standard
2341 and then not Is_Child_Unit
(Old_E
)
2343 Error_Msg_N
("renamed unit must be a library unit", Name
(N
));
2345 -- Entities defined in Standard (operators and boolean literals) cannot
2346 -- be renamed as library units.
2348 elsif Scope
(Old_E
) = Standard_Standard
2349 and then Sloc
(Old_E
) = Standard_Location
2351 Error_Msg_N
("renamed unit must be a library unit", Name
(N
));
2353 elsif Present
(Parent_Spec
(N
))
2354 and then Nkind
(Unit
(Parent_Spec
(N
))) = N_Generic_Package_Declaration
2355 and then not Is_Child_Unit
(Old_E
)
2358 ("renamed unit must be a child unit of generic parent", Name
(N
));
2360 elsif Nkind
(N
) in N_Generic_Renaming_Declaration
2361 and then Nkind
(Name
(N
)) = N_Expanded_Name
2362 and then Is_Generic_Instance
(Entity
(Prefix
(Name
(N
))))
2363 and then Is_Generic_Unit
(Old_E
)
2366 ("renamed generic unit must be a library unit", Name
(N
));
2368 elsif Ekind
(Old_E
) = E_Package
2369 or else Ekind
(Old_E
) = E_Generic_Package
2371 -- Inherit categorization flags
2373 New_E
:= Defining_Entity
(N
);
2374 Set_Is_Pure
(New_E
, Is_Pure
(Old_E
));
2375 Set_Is_Preelaborated
(New_E
, Is_Preelaborated
(Old_E
));
2376 Set_Is_Remote_Call_Interface
(New_E
,
2377 Is_Remote_Call_Interface
(Old_E
));
2378 Set_Is_Remote_Types
(New_E
, Is_Remote_Types
(Old_E
));
2379 Set_Is_Shared_Passive
(New_E
, Is_Shared_Passive
(Old_E
));
2381 end Check_Library_Unit_Renaming
;
2387 procedure End_Scope
is
2393 Id
:= First_Entity
(Current_Scope
);
2395 while Present
(Id
) loop
2396 -- An entity in the current scope is not necessarily the first one
2397 -- on its homonym chain. Find its predecessor if any,
2398 -- If it is an internal entity, it will not be in the visibility
2399 -- chain altogether, and there is nothing to unchain.
2401 if Id
/= Current_Entity
(Id
) then
2402 Prev
:= Current_Entity
(Id
);
2403 while Present
(Prev
)
2404 and then Present
(Homonym
(Prev
))
2405 and then Homonym
(Prev
) /= Id
2407 Prev
:= Homonym
(Prev
);
2410 -- Skip to end of loop if Id is not in the visibility chain
2412 if No
(Prev
) or else Homonym
(Prev
) /= Id
then
2420 Outer
:= Homonym
(Id
);
2421 Set_Is_Immediately_Visible
(Id
, False);
2423 while Present
(Outer
) and then Scope
(Outer
) = Current_Scope
loop
2424 Outer
:= Homonym
(Outer
);
2427 -- Reset homonym link of other entities, but do not modify link
2428 -- between entities in current scope, so that the back-end can have
2429 -- a proper count of local overloadings.
2432 Set_Name_Entity_Id
(Chars
(Id
), Outer
);
2434 elsif Scope
(Prev
) /= Scope
(Id
) then
2435 Set_Homonym
(Prev
, Outer
);
2442 -- If the scope generated freeze actions, place them before the
2443 -- current declaration and analyze them. Type declarations and
2444 -- the bodies of initialization procedures can generate such nodes.
2445 -- We follow the parent chain until we reach a list node, which is
2446 -- the enclosing list of declarations. If the list appears within
2447 -- a protected definition, move freeze nodes outside the protected
2451 (Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
)
2455 L
: constant List_Id
:= Scope_Stack
.Table
2456 (Scope_Stack
.Last
).Pending_Freeze_Actions
;
2459 if Is_Itype
(Current_Scope
) then
2460 Decl
:= Associated_Node_For_Itype
(Current_Scope
);
2462 Decl
:= Parent
(Current_Scope
);
2467 while not (Is_List_Member
(Decl
))
2468 or else Nkind
(Parent
(Decl
)) = N_Protected_Definition
2469 or else Nkind
(Parent
(Decl
)) = N_Task_Definition
2471 Decl
:= Parent
(Decl
);
2474 Insert_List_Before_And_Analyze
(Decl
, L
);
2483 ---------------------
2484 -- End_Use_Clauses --
2485 ---------------------
2487 procedure End_Use_Clauses
(Clause
: Node_Id
) is
2491 -- Remove Use_Type clauses first, because they affect the
2492 -- visibility of operators in subsequent used packages.
2495 while Present
(U
) loop
2496 if Nkind
(U
) = N_Use_Type_Clause
then
2500 Next_Use_Clause
(U
);
2504 while Present
(U
) loop
2505 if Nkind
(U
) = N_Use_Package_Clause
then
2506 End_Use_Package
(U
);
2509 Next_Use_Clause
(U
);
2511 end End_Use_Clauses
;
2513 ---------------------
2514 -- End_Use_Package --
2515 ---------------------
2517 procedure End_Use_Package
(N
: Node_Id
) is
2518 Pack_Name
: Node_Id
;
2523 function Is_Primitive_Operator
2525 F
: Entity_Id
) return Boolean;
2526 -- Check whether Op is a primitive operator of a use-visible type
2528 ---------------------------
2529 -- Is_Primitive_Operator --
2530 ---------------------------
2532 function Is_Primitive_Operator
2534 F
: Entity_Id
) return Boolean
2536 T
: constant Entity_Id
:= Etype
(F
);
2540 and then Scope
(T
) = Scope
(Op
);
2541 end Is_Primitive_Operator
;
2543 -- Start of processing for End_Use_Package
2546 Pack_Name
:= First
(Names
(N
));
2548 while Present
(Pack_Name
) loop
2549 Pack
:= Entity
(Pack_Name
);
2551 if Ekind
(Pack
) = E_Package
then
2553 if In_Open_Scopes
(Pack
) then
2556 elsif not Redundant_Use
(Pack_Name
) then
2557 Set_In_Use
(Pack
, False);
2558 Set_Current_Use_Clause
(Pack
, Empty
);
2559 Id
:= First_Entity
(Pack
);
2561 while Present
(Id
) loop
2563 -- Preserve use-visibility of operators that are primitive
2564 -- operators of a type that is use_visible through an active
2567 if Nkind
(Id
) = N_Defining_Operator_Symbol
2569 (Is_Primitive_Operator
(Id
, First_Formal
(Id
))
2571 (Present
(Next_Formal
(First_Formal
(Id
)))
2573 Is_Primitive_Operator
2574 (Id
, Next_Formal
(First_Formal
(Id
)))))
2579 Set_Is_Potentially_Use_Visible
(Id
, False);
2582 if Is_Private_Type
(Id
)
2583 and then Present
(Full_View
(Id
))
2585 Set_Is_Potentially_Use_Visible
(Full_View
(Id
), False);
2591 if Present
(Renamed_Object
(Pack
)) then
2592 Set_In_Use
(Renamed_Object
(Pack
), False);
2593 Set_Current_Use_Clause
(Renamed_Object
(Pack
), Empty
);
2596 if Chars
(Pack
) = Name_System
2597 and then Scope
(Pack
) = Standard_Standard
2598 and then Present_System_Aux
2600 Id
:= First_Entity
(System_Aux_Id
);
2602 while Present
(Id
) loop
2603 Set_Is_Potentially_Use_Visible
(Id
, False);
2605 if Is_Private_Type
(Id
)
2606 and then Present
(Full_View
(Id
))
2608 Set_Is_Potentially_Use_Visible
(Full_View
(Id
), False);
2614 Set_In_Use
(System_Aux_Id
, False);
2618 Set_Redundant_Use
(Pack_Name
, False);
2626 if Present
(Hidden_By_Use_Clause
(N
)) then
2627 Elmt
:= First_Elmt
(Hidden_By_Use_Clause
(N
));
2629 while Present
(Elmt
) loop
2630 Set_Is_Immediately_Visible
(Node
(Elmt
));
2634 Set_Hidden_By_Use_Clause
(N
, No_Elist
);
2636 end End_Use_Package
;
2642 procedure End_Use_Type
(N
: Node_Id
) is
2649 Id
:= First
(Subtype_Marks
(N
));
2651 while Present
(Id
) loop
2653 -- A call to rtsfind may occur while analyzing a use_type clause,
2654 -- in which case the type marks are not resolved yet, and there is
2655 -- nothing to remove.
2657 if not Is_Entity_Name
(Id
)
2658 or else No
(Entity
(Id
))
2665 if T
= Any_Type
then
2668 -- Note that the use_Type clause may mention a subtype of the
2669 -- type whose primitive operations have been made visible. Here
2670 -- as elsewhere, it is the base type that matters for visibility.
2672 elsif In_Open_Scopes
(Scope
(Base_Type
(T
))) then
2675 elsif not Redundant_Use
(Id
) then
2676 Set_In_Use
(T
, False);
2677 Set_In_Use
(Base_Type
(T
), False);
2678 Op_List
:= Collect_Primitive_Operations
(T
);
2679 Elmt
:= First_Elmt
(Op_List
);
2681 while Present
(Elmt
) loop
2683 if Nkind
(Node
(Elmt
)) = N_Defining_Operator_Symbol
then
2684 Set_Is_Potentially_Use_Visible
(Node
(Elmt
), False);
2696 ----------------------
2697 -- Find_Direct_Name --
2698 ----------------------
2700 procedure Find_Direct_Name
(N
: Node_Id
) is
2705 Inst
: Entity_Id
:= Empty
;
2706 -- Enclosing instance, if any
2708 Homonyms
: Entity_Id
;
2709 -- Saves start of homonym chain
2711 Nvis_Entity
: Boolean;
2712 -- Set True to indicate that at there is at least one entity on the
2713 -- homonym chain which, while not visible, is visible enough from the
2714 -- user point of view to warrant an error message of "not visible"
2715 -- rather than undefined.
2717 Nvis_Is_Private_Subprg
: Boolean := False;
2718 -- Ada 2005 (AI-262): Set True to indicate that a form of Beaujolais
2719 -- effect concerning library subprograms has been detected. Used to
2720 -- generate the precise error message.
2722 function From_Actual_Package
(E
: Entity_Id
) return Boolean;
2723 -- Returns true if the entity is declared in a package that is
2724 -- an actual for a formal package of the current instance. Such an
2725 -- entity requires special handling because it may be use-visible
2726 -- but hides directly visible entities defined outside the instance.
2728 function Known_But_Invisible
(E
: Entity_Id
) return Boolean;
2729 -- This function determines whether the entity E (which is not
2730 -- visible) can reasonably be considered to be known to the writer
2731 -- of the reference. This is a heuristic test, used only for the
2732 -- purposes of figuring out whether we prefer to complain that an
2733 -- entity is undefined or invisible (and identify the declaration
2734 -- of the invisible entity in the latter case). The point here is
2735 -- that we don't want to complain that something is invisible and
2736 -- then point to something entirely mysterious to the writer.
2738 procedure Nvis_Messages
;
2739 -- Called if there are no visible entries for N, but there is at least
2740 -- one non-directly visible, or hidden declaration. This procedure
2741 -- outputs an appropriate set of error messages.
2743 procedure Undefined
(Nvis
: Boolean);
2744 -- This function is called if the current node has no corresponding
2745 -- visible entity or entities. The value set in Msg indicates whether
2746 -- an error message was generated (multiple error messages for the
2747 -- same variable are generally suppressed, see body for details).
2748 -- Msg is True if an error message was generated, False if not. This
2749 -- value is used by the caller to determine whether or not to output
2750 -- additional messages where appropriate. The parameter is set False
2751 -- to get the message "X is undefined", and True to get the message
2752 -- "X is not visible".
2754 -------------------------
2755 -- From_Actual_Package --
2756 -------------------------
2758 function From_Actual_Package
(E
: Entity_Id
) return Boolean is
2759 Scop
: constant Entity_Id
:= Scope
(E
);
2763 if not In_Instance
then
2766 Inst
:= Current_Scope
;
2768 while Present
(Inst
)
2769 and then Ekind
(Inst
) /= E_Package
2770 and then not Is_Generic_Instance
(Inst
)
2772 Inst
:= Scope
(Inst
);
2779 Act
:= First_Entity
(Inst
);
2781 while Present
(Act
) loop
2782 if Ekind
(Act
) = E_Package
then
2784 -- Check for end of actuals list
2786 if Renamed_Object
(Act
) = Inst
then
2789 elsif Present
(Associated_Formal_Package
(Act
))
2790 and then Renamed_Object
(Act
) = Scop
2792 -- Entity comes from (instance of) formal package
2807 end From_Actual_Package
;
2809 -------------------------
2810 -- Known_But_Invisible --
2811 -------------------------
2813 function Known_But_Invisible
(E
: Entity_Id
) return Boolean is
2814 Fname
: File_Name_Type
;
2817 -- Entities in Standard are always considered to be known
2819 if Sloc
(E
) <= Standard_Location
then
2822 -- An entity that does not come from source is always considered
2823 -- to be unknown, since it is an artifact of code expansion.
2825 elsif not Comes_From_Source
(E
) then
2828 -- In gnat internal mode, we consider all entities known
2830 elsif GNAT_Mode
then
2834 -- Here we have an entity that is not from package Standard, and
2835 -- which comes from Source. See if it comes from an internal file.
2837 Fname
:= Unit_File_Name
(Get_Source_Unit
(E
));
2839 -- Case of from internal file
2841 if Is_Internal_File_Name
(Fname
) then
2843 -- Private part entities in internal files are never considered
2844 -- to be known to the writer of normal application code.
2846 if Is_Hidden
(E
) then
2850 -- Entities from System packages other than System and
2851 -- System.Storage_Elements are not considered to be known.
2852 -- System.Auxxxx files are also considered known to the user.
2854 -- Should refine this at some point to generally distinguish
2855 -- between known and unknown internal files ???
2857 Get_Name_String
(Fname
);
2862 Name_Buffer
(1 .. 2) /= "s-"
2864 Name_Buffer
(3 .. 8) = "stoele"
2866 Name_Buffer
(3 .. 5) = "aux";
2868 -- If not an internal file, then entity is definitely known,
2869 -- even if it is in a private part (the message generated will
2870 -- note that it is in a private part)
2875 end Known_But_Invisible
;
2881 procedure Nvis_Messages
is
2882 Comp_Unit
: Node_Id
;
2884 Hidden
: Boolean := False;
2888 -- Ada 2005 (AI-262): Generate a precise error concerning the
2889 -- Beaujolais effect that was previously detected
2891 if Nvis_Is_Private_Subprg
then
2893 pragma Assert
(Nkind
(E2
) = N_Defining_Identifier
2894 and then Ekind
(E2
) = E_Function
2895 and then Scope
(E2
) = Standard_Standard
2896 and then Has_Private_With
(E2
));
2898 -- Find the sloc corresponding to the private with'ed unit
2900 Comp_Unit
:= Cunit
(Current_Sem_Unit
);
2901 Item
:= First
(Context_Items
(Comp_Unit
));
2902 Error_Msg_Sloc
:= No_Location
;
2904 while Present
(Item
) loop
2905 if Nkind
(Item
) = N_With_Clause
2906 and then Private_Present
(Item
)
2907 and then Entity
(Name
(Item
)) = E2
2909 Error_Msg_Sloc
:= Sloc
(Item
);
2916 pragma Assert
(Error_Msg_Sloc
/= No_Location
);
2918 Error_Msg_N
("(Ada 2005): hidden by private with clause #", N
);
2922 Undefined
(Nvis
=> True);
2926 -- First loop does hidden declarations
2929 while Present
(Ent
) loop
2930 if Is_Potentially_Use_Visible
(Ent
) then
2933 Error_Msg_N
("multiple use clauses cause hiding!", N
);
2937 Error_Msg_Sloc
:= Sloc
(Ent
);
2938 Error_Msg_N
("hidden declaration#!", N
);
2941 Ent
:= Homonym
(Ent
);
2944 -- If we found hidden declarations, then that's enough, don't
2945 -- bother looking for non-visible declarations as well.
2951 -- Second loop does non-directly visible declarations
2954 while Present
(Ent
) loop
2955 if not Is_Potentially_Use_Visible
(Ent
) then
2957 -- Do not bother the user with unknown entities
2959 if not Known_But_Invisible
(Ent
) then
2963 Error_Msg_Sloc
:= Sloc
(Ent
);
2965 -- Output message noting that there is a non-visible
2966 -- declaration, distinguishing the private part case.
2968 if Is_Hidden
(Ent
) then
2969 Error_Msg_N
("non-visible (private) declaration#!", N
);
2971 Error_Msg_N
("non-visible declaration#!", N
);
2973 if Is_Compilation_Unit
(Ent
)
2975 Nkind
(Parent
(Parent
(N
))) = N_Use_Package_Clause
2978 ("\possibly missing with_clause for&", N
, Ent
);
2982 -- Set entity and its containing package as referenced. We
2983 -- can't be sure of this, but this seems a better choice
2984 -- to avoid unused entity messages.
2986 if Comes_From_Source
(Ent
) then
2987 Set_Referenced
(Ent
);
2988 Set_Referenced
(Cunit_Entity
(Get_Source_Unit
(Ent
)));
2993 Ent
:= Homonym
(Ent
);
3003 procedure Undefined
(Nvis
: Boolean) is
3004 Emsg
: Error_Msg_Id
;
3007 -- We should never find an undefined internal name. If we do, then
3008 -- see if we have previous errors. If so, ignore on the grounds that
3009 -- it is probably a cascaded message (e.g. a block label from a badly
3010 -- formed block). If no previous errors, then we have a real internal
3011 -- error of some kind so raise an exception.
3013 if Is_Internal_Name
(Chars
(N
)) then
3014 if Total_Errors_Detected
/= 0 then
3017 raise Program_Error
;
3021 -- A very specialized error check, if the undefined variable is
3022 -- a case tag, and the case type is an enumeration type, check
3023 -- for a possible misspelling, and if so, modify the identifier
3025 -- Named aggregate should also be handled similarly ???
3027 if Nkind
(N
) = N_Identifier
3028 and then Nkind
(Parent
(N
)) = N_Case_Statement_Alternative
3030 Get_Name_String
(Chars
(N
));
3033 Case_Str
: constant String := Name_Buffer
(1 .. Name_Len
);
3034 Case_Stm
: constant Node_Id
:= Parent
(Parent
(N
));
3035 Case_Typ
: constant Entity_Id
:= Etype
(Expression
(Case_Stm
));
3036 Case_Rtp
: constant Entity_Id
:= Root_Type
(Case_Typ
);
3041 if Is_Enumeration_Type
(Case_Typ
)
3042 and then Case_Rtp
/= Standard_Character
3043 and then Case_Rtp
/= Standard_Wide_Character
3044 and then Case_Rtp
/= Standard_Wide_Wide_Character
3046 Lit
:= First_Literal
(Case_Typ
);
3047 Get_Name_String
(Chars
(Lit
));
3049 if Chars
(Lit
) /= Chars
(N
)
3050 and then Is_Bad_Spelling_Of
3051 (Case_Str
, Name_Buffer
(1 .. Name_Len
))
3053 Error_Msg_Node_2
:= Lit
;
3055 ("& is undefined, assume misspelling of &", N
);
3056 Rewrite
(N
, New_Occurrence_Of
(Lit
, Sloc
(N
)));
3060 Lit
:= Next_Literal
(Lit
);
3065 -- Normal processing
3067 Set_Entity
(N
, Any_Id
);
3068 Set_Etype
(N
, Any_Type
);
3070 -- We use the table Urefs to keep track of entities for which we
3071 -- have issued errors for undefined references. Multiple errors
3072 -- for a single name are normally suppressed, however we modify
3073 -- the error message to alert the programmer to this effect.
3075 for J
in Urefs
.First
.. Urefs
.Last
loop
3076 if Chars
(N
) = Chars
(Urefs
.Table
(J
).Node
) then
3077 if Urefs
.Table
(J
).Err
/= No_Error_Msg
3078 and then Sloc
(N
) /= Urefs
.Table
(J
).Loc
3080 Error_Msg_Node_1
:= Urefs
.Table
(J
).Node
;
3082 if Urefs
.Table
(J
).Nvis
then
3083 Change_Error_Text
(Urefs
.Table
(J
).Err
,
3084 "& is not visible (more references follow)");
3086 Change_Error_Text
(Urefs
.Table
(J
).Err
,
3087 "& is undefined (more references follow)");
3090 Urefs
.Table
(J
).Err
:= No_Error_Msg
;
3093 -- Although we will set Msg False, and thus suppress the
3094 -- message, we also set Error_Posted True, to avoid any
3095 -- cascaded messages resulting from the undefined reference.
3098 Set_Error_Posted
(N
, True);
3103 -- If entry not found, this is first undefined occurrence
3106 Error_Msg_N
("& is not visible!", N
);
3110 Error_Msg_N
("& is undefined!", N
);
3113 -- A very bizarre special check, if the undefined identifier
3114 -- is put or put_line, then add a special error message (since
3115 -- this is a very common error for beginners to make).
3117 if Chars
(N
) = Name_Put
or else Chars
(N
) = Name_Put_Line
then
3118 Error_Msg_N
("\possible missing with of 'Text_'I'O!", N
);
3121 -- Now check for possible misspellings
3123 Get_Name_String
(Chars
(N
));
3127 Ematch
: Entity_Id
:= Empty
;
3129 Last_Name_Id
: constant Name_Id
:=
3130 Name_Id
(Nat
(First_Name_Id
) +
3131 Name_Entries_Count
- 1);
3133 S
: constant String (1 .. Name_Len
) :=
3134 Name_Buffer
(1 .. Name_Len
);
3137 for N
in First_Name_Id
.. Last_Name_Id
loop
3138 E
:= Get_Name_Entity_Id
(N
);
3141 and then (Is_Immediately_Visible
(E
)
3143 Is_Potentially_Use_Visible
(E
))
3145 Get_Name_String
(N
);
3147 if Is_Bad_Spelling_Of
3148 (Name_Buffer
(1 .. Name_Len
), S
)
3156 if Present
(Ematch
) then
3157 Error_Msg_NE
("\possible misspelling of&", N
, Ematch
);
3162 -- Make entry in undefined references table unless the full
3163 -- errors switch is set, in which case by refraining from
3164 -- generating the table entry, we guarantee that we get an
3165 -- error message for every undefined reference.
3167 if not All_Errors_Mode
then
3168 Urefs
.Increment_Last
;
3169 Urefs
.Table
(Urefs
.Last
).Node
:= N
;
3170 Urefs
.Table
(Urefs
.Last
).Err
:= Emsg
;
3171 Urefs
.Table
(Urefs
.Last
).Nvis
:= Nvis
;
3172 Urefs
.Table
(Urefs
.Last
).Loc
:= Sloc
(N
);
3178 -- Start of processing for Find_Direct_Name
3181 -- If the entity pointer is already set, this is an internal node, or
3182 -- a node that is analyzed more than once, after a tree modification.
3183 -- In such a case there is no resolution to perform, just set the type.
3185 if Present
(Entity
(N
)) then
3186 if Is_Type
(Entity
(N
)) then
3187 Set_Etype
(N
, Entity
(N
));
3191 Entyp
: constant Entity_Id
:= Etype
(Entity
(N
));
3194 -- One special case here. If the Etype field is already set,
3195 -- and references the packed array type corresponding to the
3196 -- etype of the referenced entity, then leave it alone. This
3197 -- happens for trees generated from Exp_Pakd, where expressions
3198 -- can be deliberately "mis-typed" to the packed array type.
3200 if Is_Array_Type
(Entyp
)
3201 and then Is_Packed
(Entyp
)
3202 and then Present
(Etype
(N
))
3203 and then Etype
(N
) = Packed_Array_Type
(Entyp
)
3207 -- If not that special case, then just reset the Etype
3210 Set_Etype
(N
, Etype
(Entity
(N
)));
3218 -- Here if Entity pointer was not set, we need full visibility analysis
3219 -- First we generate debugging output if the debug E flag is set.
3221 if Debug_Flag_E
then
3222 Write_Str
("Looking for ");
3223 Write_Name
(Chars
(N
));
3227 Homonyms
:= Current_Entity
(N
);
3228 Nvis_Entity
:= False;
3231 while Present
(E
) loop
3233 -- If entity is immediately visible or potentially use
3234 -- visible, then process the entity and we are done.
3236 if Is_Immediately_Visible
(E
) then
3237 goto Immediately_Visible_Entity
;
3239 elsif Is_Potentially_Use_Visible
(E
) then
3240 goto Potentially_Use_Visible_Entity
;
3242 -- Note if a known but invisible entity encountered
3244 elsif Known_But_Invisible
(E
) then
3245 Nvis_Entity
:= True;
3248 -- Move to next entity in chain and continue search
3253 -- If no entries on homonym chain that were potentially visible,
3254 -- and no entities reasonably considered as non-visible, then
3255 -- we have a plain undefined reference, with no additional
3256 -- explanation required!
3258 if not Nvis_Entity
then
3259 Undefined
(Nvis
=> False);
3261 -- Otherwise there is at least one entry on the homonym chain that
3262 -- is reasonably considered as being known and non-visible.
3270 -- Processing for a potentially use visible entry found. We must search
3271 -- the rest of the homonym chain for two reasons. First, if there is a
3272 -- directly visible entry, then none of the potentially use-visible
3273 -- entities are directly visible (RM 8.4(10)). Second, we need to check
3274 -- for the case of multiple potentially use-visible entries hiding one
3275 -- another and as a result being non-directly visible (RM 8.4(11)).
3277 <<Potentially_Use_Visible_Entity
>> declare
3278 Only_One_Visible
: Boolean := True;
3279 All_Overloadable
: Boolean := Is_Overloadable
(E
);
3284 while Present
(E2
) loop
3285 if Is_Immediately_Visible
(E2
) then
3287 -- If the use-visible entity comes from the actual for a
3288 -- formal package, it hides a directly visible entity from
3289 -- outside the instance.
3291 if From_Actual_Package
(E
)
3292 and then Scope_Depth
(E2
) < Scope_Depth
(Inst
)
3297 goto Immediately_Visible_Entity
;
3300 elsif Is_Potentially_Use_Visible
(E2
) then
3301 Only_One_Visible
:= False;
3302 All_Overloadable
:= All_Overloadable
and Is_Overloadable
(E2
);
3304 -- Ada 2005 (AI-262): Protect against a form of Beujolais effect
3305 -- that can occurr in private_with clauses. Example:
3308 -- private with B; package A is
3309 -- package C is function B return Integer;
3311 -- V1 : Integer := B;
3312 -- private function B return Integer;
3313 -- V2 : Integer := B;
3316 -- V1 resolves to A.B, but V2 resolves to library unit B
3318 elsif Ekind
(E2
) = E_Function
3319 and then Scope
(E2
) = Standard_Standard
3320 and then Has_Private_With
(E2
)
3322 Only_One_Visible
:= False;
3323 All_Overloadable
:= False;
3324 Nvis_Is_Private_Subprg
:= True;
3331 -- On falling through this loop, we have checked that there are no
3332 -- immediately visible entities. Only_One_Visible is set if exactly
3333 -- one potentially use visible entity exists. All_Overloadable is
3334 -- set if all the potentially use visible entities are overloadable.
3335 -- The condition for legality is that either there is one potentially
3336 -- use visible entity, or if there is more than one, then all of them
3337 -- are overloadable.
3339 if Only_One_Visible
or All_Overloadable
then
3342 -- If there is more than one potentially use-visible entity and at
3343 -- least one of them non-overloadable, we have an error (RM 8.4(11).
3344 -- Note that E points to the first such entity on the homonym list.
3345 -- Special case: if one of the entities is declared in an actual
3346 -- package, it was visible in the generic, and takes precedence over
3347 -- other entities that are potentially use-visible. Same if it is
3348 -- declared in a local instantiation of the current instance.
3352 Inst
:= Current_Scope
;
3354 -- Find current instance
3356 while Present
(Inst
)
3357 and then Inst
/= Standard_Standard
3359 if Is_Generic_Instance
(Inst
) then
3363 Inst
:= Scope
(Inst
);
3368 while Present
(E2
) loop
3369 if From_Actual_Package
(E2
)
3371 (Is_Generic_Instance
(Scope
(E2
))
3372 and then Scope_Depth
(Scope
(E2
)) > Scope_Depth
(Inst
))
3385 Is_Predefined_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
3387 -- A use-clause in the body of a system file creates conflict
3388 -- with some entity in a user scope, while rtsfind is active.
3389 -- Keep only the entity coming from another predefined unit.
3392 while Present
(E2
) loop
3393 if Is_Predefined_File_Name
3394 (Unit_File_Name
(Get_Source_Unit
(Sloc
(E2
))))
3403 -- Entity must exist because predefined unit is correct
3405 raise Program_Error
;
3414 -- Come here with E set to the first immediately visible entity on
3415 -- the homonym chain. This is the one we want unless there is another
3416 -- immediately visible entity further on in the chain for a more
3417 -- inner scope (RM 8.3(8)).
3419 <<Immediately_Visible_Entity
>> declare
3424 -- Find scope level of initial entity. When compiling through
3425 -- Rtsfind, the previous context is not completely invisible, and
3426 -- an outer entity may appear on the chain, whose scope is below
3427 -- the entry for Standard that delimits the current scope stack.
3428 -- Indicate that the level for this spurious entry is outside of
3429 -- the current scope stack.
3431 Level
:= Scope_Stack
.Last
;
3433 Scop
:= Scope_Stack
.Table
(Level
).Entity
;
3434 exit when Scop
= Scope
(E
);
3436 exit when Scop
= Standard_Standard
;
3439 -- Now search remainder of homonym chain for more inner entry
3440 -- If the entity is Standard itself, it has no scope, and we
3441 -- compare it with the stack entry directly.
3444 while Present
(E2
) loop
3445 if Is_Immediately_Visible
(E2
) then
3447 -- If a generic package contains a local declaration that
3448 -- has the same name as the generic, there may be a visibility
3449 -- conflict in an instance, where the local declaration must
3450 -- also hide the name of the corresponding package renaming.
3451 -- We check explicitly for a package declared by a renaming,
3452 -- whose renamed entity is an instance that is on the scope
3453 -- stack, and that contains a homonym in the same scope. Once
3454 -- we have found it, we know that the package renaming is not
3455 -- immediately visible, and that the identifier denotes the
3456 -- other entity (and its homonyms if overloaded).
3458 if Scope
(E
) = Scope
(E2
)
3459 and then Ekind
(E
) = E_Package
3460 and then Present
(Renamed_Object
(E
))
3461 and then Is_Generic_Instance
(Renamed_Object
(E
))
3462 and then In_Open_Scopes
(Renamed_Object
(E
))
3463 and then Comes_From_Source
(N
)
3465 Set_Is_Immediately_Visible
(E
, False);
3469 for J
in Level
+ 1 .. Scope_Stack
.Last
loop
3470 if Scope_Stack
.Table
(J
).Entity
= Scope
(E2
)
3471 or else Scope_Stack
.Table
(J
).Entity
= E2
3484 -- At the end of that loop, E is the innermost immediately
3485 -- visible entity, so we are all set.
3488 -- Come here with entity found, and stored in E
3492 if Comes_From_Source
(N
)
3493 and then Is_Remote_Access_To_Subprogram_Type
(E
)
3494 and then Expander_Active
3495 and then Get_PCS_Name
/= Name_No_DSA
3498 New_Occurrence_Of
(Equivalent_Type
(E
), Sloc
(N
)));
3503 -- Why no Style_Check here???
3508 Set_Etype
(N
, Get_Full_View
(Etype
(E
)));
3511 if Debug_Flag_E
then
3512 Write_Str
(" found ");
3513 Write_Entity_Info
(E
, " ");
3516 -- If the Ekind of the entity is Void, it means that all homonyms
3517 -- are hidden from all visibility (RM 8.3(5,14-20)). However, this
3518 -- test is skipped if the current scope is a record and the name is
3519 -- a pragma argument expression (case of Atomic and Volatile pragmas
3520 -- and possibly other similar pragmas added later, which are allowed
3521 -- to reference components in the current record).
3523 if Ekind
(E
) = E_Void
3525 (not Is_Record_Type
(Current_Scope
)
3526 or else Nkind
(Parent
(N
)) /= N_Pragma_Argument_Association
)
3528 Premature_Usage
(N
);
3530 -- If the entity is overloadable, collect all interpretations
3531 -- of the name for subsequent overload resolution. We optimize
3532 -- a bit here to do this only if we have an overloadable entity
3533 -- that is not on its own on the homonym chain.
3535 elsif Is_Overloadable
(E
)
3536 and then (Present
(Homonym
(E
)) or else Current_Entity
(N
) /= E
)
3538 Collect_Interps
(N
);
3540 -- If no homonyms were visible, the entity is unambiguous
3542 if not Is_Overloaded
(N
) then
3543 Generate_Reference
(E
, N
);
3546 -- Case of non-overloadable entity, set the entity providing that
3547 -- we do not have the case of a discriminant reference within a
3548 -- default expression. Such references are replaced with the
3549 -- corresponding discriminal, which is the formal corresponding to
3550 -- to the discriminant in the initialization procedure.
3553 -- Entity is unambiguous, indicate that it is referenced here
3554 -- One slightly odd case is that we do not want to set the
3555 -- Referenced flag if the entity is a label, and the identifier
3556 -- is the label in the source, since this is not a reference
3557 -- from the point of view of the user
3559 if Nkind
(Parent
(N
)) = N_Label
then
3561 R
: constant Boolean := Referenced
(E
);
3564 Generate_Reference
(E
, N
);
3565 Set_Referenced
(E
, R
);
3568 -- Normal case, not a label. Generate reference
3571 Generate_Reference
(E
, N
);
3574 -- Set Entity, with style check if need be. If this is a
3575 -- discriminant reference, it must be replaced by the
3576 -- corresponding discriminal, that is to say the parameter
3577 -- of the initialization procedure that corresponds to the
3578 -- discriminant. If this replacement is being performed, there
3579 -- is no style check to perform.
3581 -- This replacement must not be done if we are currently
3582 -- processing a generic spec or body, because the discriminal
3583 -- has not been not generated in this case.
3585 if not In_Default_Expression
3586 or else Ekind
(E
) /= E_Discriminant
3587 or else Inside_A_Generic
3589 Set_Entity_With_Style_Check
(N
, E
);
3591 -- The replacement is not done either for a task discriminant that
3592 -- appears in a default expression of an entry parameter. See
3593 -- Expand_Discriminant in exp_ch2 for details on their handling.
3595 elsif Is_Concurrent_Type
(Scope
(E
)) then
3597 P
: Node_Id
:= Parent
(N
);
3601 and then Nkind
(P
) /= N_Parameter_Specification
3602 and then Nkind
(P
) /= N_Component_Declaration
3608 and then Nkind
(P
) = N_Parameter_Specification
3612 Set_Entity
(N
, Discriminal
(E
));
3616 -- Otherwise, this is a discriminant in a context in which
3617 -- it is a reference to the corresponding parameter of the
3618 -- init proc for the enclosing type.
3621 Set_Entity
(N
, Discriminal
(E
));
3625 end Find_Direct_Name
;
3627 ------------------------
3628 -- Find_Expanded_Name --
3629 ------------------------
3631 -- This routine searches the homonym chain of the entity until it finds
3632 -- an entity declared in the scope denoted by the prefix. If the entity
3633 -- is private, it may nevertheless be immediately visible, if we are in
3634 -- the scope of its declaration.
3636 procedure Find_Expanded_Name
(N
: Node_Id
) is
3637 Selector
: constant Node_Id
:= Selector_Name
(N
);
3638 Candidate
: Entity_Id
:= Empty
;
3644 P_Name
:= Entity
(Prefix
(N
));
3647 -- If the prefix is a renamed package, look for the entity
3648 -- in the original package.
3650 if Ekind
(P_Name
) = E_Package
3651 and then Present
(Renamed_Object
(P_Name
))
3653 P_Name
:= Renamed_Object
(P_Name
);
3655 -- Rewrite node with entity field pointing to renamed object
3657 Rewrite
(Prefix
(N
), New_Copy
(Prefix
(N
)));
3658 Set_Entity
(Prefix
(N
), P_Name
);
3660 -- If the prefix is an object of a concurrent type, look for
3661 -- the entity in the associated task or protected type.
3663 elsif Is_Concurrent_Type
(Etype
(P_Name
)) then
3664 P_Name
:= Etype
(P_Name
);
3667 Id
:= Current_Entity
(Selector
);
3669 while Present
(Id
) loop
3671 if Scope
(Id
) = P_Name
then
3674 if Is_Child_Unit
(Id
) then
3675 exit when Is_Visible_Child_Unit
(Id
)
3676 or else Is_Immediately_Visible
(Id
);
3679 exit when not Is_Hidden
(Id
)
3680 or else Is_Immediately_Visible
(Id
);
3688 and then (Ekind
(P_Name
) = E_Procedure
3690 Ekind
(P_Name
) = E_Function
)
3691 and then Is_Generic_Instance
(P_Name
)
3693 -- Expanded name denotes entity in (instance of) generic subprogram.
3694 -- The entity may be in the subprogram instance, or may denote one of
3695 -- the formals, which is declared in the enclosing wrapper package.
3697 P_Name
:= Scope
(P_Name
);
3699 Id
:= Current_Entity
(Selector
);
3700 while Present
(Id
) loop
3701 exit when Scope
(Id
) = P_Name
;
3706 if No
(Id
) or else Chars
(Id
) /= Chars
(Selector
) then
3707 Set_Etype
(N
, Any_Type
);
3709 -- If we are looking for an entity defined in System, try to
3710 -- find it in the child package that may have been provided as
3711 -- an extension to System. The Extend_System pragma will have
3712 -- supplied the name of the extension, which may have to be loaded.
3714 if Chars
(P_Name
) = Name_System
3715 and then Scope
(P_Name
) = Standard_Standard
3716 and then Present
(System_Extend_Unit
)
3717 and then Present_System_Aux
(N
)
3719 Set_Entity
(Prefix
(N
), System_Aux_Id
);
3720 Find_Expanded_Name
(N
);
3723 elsif Nkind
(Selector
) = N_Operator_Symbol
3724 and then Has_Implicit_Operator
(N
)
3726 -- There is an implicit instance of the predefined operator in
3727 -- the given scope. The operator entity is defined in Standard.
3728 -- Has_Implicit_Operator makes the node into an Expanded_Name.
3732 elsif Nkind
(Selector
) = N_Character_Literal
3733 and then Has_Implicit_Character_Literal
(N
)
3735 -- If there is no literal defined in the scope denoted by the
3736 -- prefix, the literal may belong to (a type derived from)
3737 -- Standard_Character, for which we have no explicit literals.
3742 -- If the prefix is a single concurrent object, use its
3743 -- name in the error message, rather than that of the
3746 if Is_Concurrent_Type
(P_Name
)
3747 and then Is_Internal_Name
(Chars
(P_Name
))
3749 Error_Msg_Node_2
:= Entity
(Prefix
(N
));
3751 Error_Msg_Node_2
:= P_Name
;
3754 if P_Name
= System_Aux_Id
then
3755 P_Name
:= Scope
(P_Name
);
3756 Set_Entity
(Prefix
(N
), P_Name
);
3759 if Present
(Candidate
) then
3761 if Is_Child_Unit
(Candidate
) then
3763 -- If the candidate is a private child unit and we are
3764 -- in the visible part of a public unit, specialize the
3765 -- error message. There might be a private with_clause for
3766 -- it, but it is not currently active.
3768 if Is_Private_Descendant
(Candidate
)
3769 and then Ekind
(Current_Scope
) = E_Package
3770 and then not In_Private_Part
(Current_Scope
)
3771 and then not Is_Private_Descendant
(Current_Scope
)
3773 Error_Msg_N
("private child unit& is not visible here",
3777 ("missing with_clause for child unit &", Selector
);
3780 Error_Msg_NE
("& is not a visible entity of&", N
, Selector
);
3784 -- Within the instantiation of a child unit, the prefix may
3785 -- denote the parent instance, but the selector has the
3786 -- name of the original child. Find whether we are within
3787 -- the corresponding instance, and get the proper entity, which
3788 -- can only be an enclosing scope.
3791 and then In_Open_Scopes
(P_Name
)
3792 and then Is_Generic_Instance
(P_Name
)
3795 S
: Entity_Id
:= Current_Scope
;
3799 for J
in reverse 0 .. Scope_Stack
.Last
loop
3800 S
:= Scope_Stack
.Table
(J
).Entity
;
3802 exit when S
= Standard_Standard
;
3804 if Ekind
(S
) = E_Function
3805 or else Ekind
(S
) = E_Package
3806 or else Ekind
(S
) = E_Procedure
3808 P
:= Generic_Parent
(Specification
3809 (Unit_Declaration_Node
(S
)));
3812 and then Chars
(Scope
(P
)) = Chars
(O_Name
)
3813 and then Chars
(P
) = Chars
(Selector
)
3824 if Chars
(P_Name
) = Name_Ada
3825 and then Scope
(P_Name
) = Standard_Standard
3827 Error_Msg_Node_2
:= Selector
;
3828 Error_Msg_NE
("missing with for `&.&`", N
, P_Name
);
3830 -- If this is a selection from a dummy package, then
3831 -- suppress the error message, of course the entity
3832 -- is missing if the package is missing!
3834 elsif Sloc
(Error_Msg_Node_2
) = No_Location
then
3837 -- Here we have the case of an undefined component
3841 Error_Msg_NE
("& not declared in&", N
, Selector
);
3843 -- Check for misspelling of some entity in prefix
3845 Id
:= First_Entity
(P_Name
);
3846 Get_Name_String
(Chars
(Selector
));
3849 S
: constant String (1 .. Name_Len
) :=
3850 Name_Buffer
(1 .. Name_Len
);
3852 while Present
(Id
) loop
3853 Get_Name_String
(Chars
(Id
));
3854 if Is_Bad_Spelling_Of
3855 (Name_Buffer
(1 .. Name_Len
), S
)
3856 and then not Is_Internal_Name
(Chars
(Id
))
3859 ("possible misspelling of&", Selector
, Id
);
3867 -- Specialize the message if this may be an instantiation
3868 -- of a child unit that was not mentioned in the context.
3870 if Nkind
(Parent
(N
)) = N_Package_Instantiation
3871 and then Is_Generic_Instance
(Entity
(Prefix
(N
)))
3872 and then Is_Compilation_Unit
3873 (Generic_Parent
(Parent
(Entity
(Prefix
(N
)))))
3876 ("\possible missing with clause on child unit&",
3887 if Comes_From_Source
(N
)
3888 and then Is_Remote_Access_To_Subprogram_Type
(Id
)
3889 and then Present
(Equivalent_Type
(Id
))
3891 -- If we are not actually generating distribution code (i.e.
3892 -- the current PCS is the dummy non-distributed version), then
3893 -- the Equivalent_Type will be missing, and Id should be treated
3894 -- as a regular access-to-subprogram type.
3896 Id
:= Equivalent_Type
(Id
);
3897 Set_Chars
(Selector
, Chars
(Id
));
3900 -- Ada 2005 (AI-50217): Check usage of entities in limited withed units
3902 if Ekind
(P_Name
) = E_Package
3903 and then From_With_Type
(P_Name
)
3905 if From_With_Type
(Id
)
3906 or else Is_Type
(Id
)
3907 or else Ekind
(Id
) = E_Package
3912 ("limited withed package can only be used to access "
3913 & " incomplete types",
3918 if Is_Task_Type
(P_Name
)
3919 and then ((Ekind
(Id
) = E_Entry
3920 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
)
3922 (Ekind
(Id
) = E_Entry_Family
3924 Nkind
(Parent
(Parent
(N
))) /= N_Attribute_Reference
))
3926 -- It is an entry call after all, either to the current task
3927 -- (which will deadlock) or to an enclosing task.
3929 Analyze_Selected_Component
(N
);
3933 Change_Selected_Component_To_Expanded_Name
(N
);
3935 -- Do style check and generate reference, but skip both steps if this
3936 -- entity has homonyms, since we may not have the right homonym set
3937 -- yet. The proper homonym will be set during the resolve phase.
3939 if Has_Homonym
(Id
) then
3942 Set_Entity_With_Style_Check
(N
, Id
);
3943 Generate_Reference
(Id
, N
);
3946 if Is_Type
(Id
) then
3949 Set_Etype
(N
, Get_Full_View
(Etype
(Id
)));
3952 -- If the Ekind of the entity is Void, it means that all homonyms
3953 -- are hidden from all visibility (RM 8.3(5,14-20)).
3955 if Ekind
(Id
) = E_Void
then
3956 Premature_Usage
(N
);
3958 elsif Is_Overloadable
(Id
)
3959 and then Present
(Homonym
(Id
))
3962 H
: Entity_Id
:= Homonym
(Id
);
3965 while Present
(H
) loop
3966 if Scope
(H
) = Scope
(Id
)
3969 or else Is_Immediately_Visible
(H
))
3971 Collect_Interps
(N
);
3978 -- If an extension of System is present, collect possible
3979 -- explicit overloadings declared in the extension.
3981 if Chars
(P_Name
) = Name_System
3982 and then Scope
(P_Name
) = Standard_Standard
3983 and then Present
(System_Extend_Unit
)
3984 and then Present_System_Aux
(N
)
3986 H
:= Current_Entity
(Id
);
3988 while Present
(H
) loop
3989 if Scope
(H
) = System_Aux_Id
then
3990 Add_One_Interp
(N
, H
, Etype
(H
));
3999 if Nkind
(Selector_Name
(N
)) = N_Operator_Symbol
4000 and then Scope
(Id
) /= Standard_Standard
4002 -- In addition to user-defined operators in the given scope,
4003 -- there may be an implicit instance of the predefined
4004 -- operator. The operator (defined in Standard) is found
4005 -- in Has_Implicit_Operator, and added to the interpretations.
4006 -- Procedure Add_One_Interp will determine which hides which.
4008 if Has_Implicit_Operator
(N
) then
4012 end Find_Expanded_Name
;
4014 -------------------------
4015 -- Find_Renamed_Entity --
4016 -------------------------
4018 function Find_Renamed_Entity
4022 Is_Actual
: Boolean := False) return Entity_Id
4025 I1
: Interp_Index
:= 0; -- Suppress junk warnings
4031 function Enclosing_Instance
return Entity_Id
;
4032 -- If the renaming determines the entity for the default of a formal
4033 -- subprogram nested within another instance, choose the innermost
4034 -- candidate. This is because if the formal has a box, and we are within
4035 -- an enclosing instance where some candidate interpretations are local
4036 -- to this enclosing instance, we know that the default was properly
4037 -- resolved when analyzing the generic, so we prefer the local
4038 -- candidates to those that are external. This is not always the case
4039 -- but is a reasonable heuristic on the use of nested generics.
4040 -- The proper solution requires a full renaming model.
4042 function Within
(Inner
, Outer
: Entity_Id
) return Boolean;
4043 -- Determine whether a candidate subprogram is defined within
4044 -- the enclosing instance. If yes, it has precedence over outer
4047 function Is_Visible_Operation
(Op
: Entity_Id
) return Boolean;
4048 -- If the renamed entity is an implicit operator, check whether it is
4049 -- visible because its operand type is properly visible. This
4050 -- check applies to explicit renamed entities that appear in the
4051 -- source in a renaming declaration or a formal subprogram instance,
4052 -- but not to default generic actuals with a name.
4054 ------------------------
4055 -- Enclosing_Instance --
4056 ------------------------
4058 function Enclosing_Instance
return Entity_Id
is
4062 if not Is_Generic_Instance
(Current_Scope
)
4063 and then not Is_Actual
4068 S
:= Scope
(Current_Scope
);
4070 while S
/= Standard_Standard
loop
4072 if Is_Generic_Instance
(S
) then
4080 end Enclosing_Instance
;
4082 --------------------------
4083 -- Is_Visible_Operation --
4084 --------------------------
4086 function Is_Visible_Operation
(Op
: Entity_Id
) return Boolean is
4092 if Ekind
(Op
) /= E_Operator
4093 or else Scope
(Op
) /= Standard_Standard
4094 or else (In_Instance
4097 or else Present
(Enclosing_Instance
)))
4102 -- For a fixed point type operator, check the resulting type,
4103 -- because it may be a mixed mode integer * fixed operation.
4105 if Present
(Next_Formal
(First_Formal
(New_S
)))
4106 and then Is_Fixed_Point_Type
(Etype
(New_S
))
4108 Typ
:= Etype
(New_S
);
4110 Typ
:= Etype
(First_Formal
(New_S
));
4113 Btyp
:= Base_Type
(Typ
);
4115 if Nkind
(Nam
) /= N_Expanded_Name
then
4116 return (In_Open_Scopes
(Scope
(Btyp
))
4117 or else Is_Potentially_Use_Visible
(Btyp
)
4118 or else In_Use
(Btyp
)
4119 or else In_Use
(Scope
(Btyp
)));
4122 Scop
:= Entity
(Prefix
(Nam
));
4124 if Ekind
(Scop
) = E_Package
4125 and then Present
(Renamed_Object
(Scop
))
4127 Scop
:= Renamed_Object
(Scop
);
4130 -- Operator is visible if prefix of expanded name denotes
4131 -- scope of type, or else type type is defined in System_Aux
4132 -- and the prefix denotes System.
4134 return Scope
(Btyp
) = Scop
4135 or else (Scope
(Btyp
) = System_Aux_Id
4136 and then Scope
(Scope
(Btyp
)) = Scop
);
4139 end Is_Visible_Operation
;
4145 function Within
(Inner
, Outer
: Entity_Id
) return Boolean is
4146 Sc
: Entity_Id
:= Scope
(Inner
);
4149 while Sc
/= Standard_Standard
loop
4161 function Report_Overload
return Entity_Id
;
4162 -- List possible interpretations, and specialize message in the
4163 -- case of a generic actual.
4165 function Report_Overload
return Entity_Id
is
4169 ("ambiguous actual subprogram&, " &
4170 "possible interpretations: ", N
, Nam
);
4173 ("ambiguous subprogram, " &
4174 "possible interpretations: ", N
);
4177 List_Interps
(Nam
, N
);
4179 end Report_Overload
;
4181 -- Start of processing for Find_Renamed_Entry
4185 Candidate_Renaming
:= Empty
;
4187 if not Is_Overloaded
(Nam
) then
4188 if Entity_Matches_Spec
(Entity
(Nam
), New_S
)
4189 and then Is_Visible_Operation
(Entity
(Nam
))
4191 Old_S
:= Entity
(Nam
);
4194 Present
(First_Formal
(Entity
(Nam
)))
4195 and then Present
(First_Formal
(New_S
))
4196 and then (Base_Type
(Etype
(First_Formal
(Entity
(Nam
))))
4197 = Base_Type
(Etype
(First_Formal
(New_S
))))
4199 Candidate_Renaming
:= Entity
(Nam
);
4203 Get_First_Interp
(Nam
, Ind
, It
);
4205 while Present
(It
.Nam
) loop
4207 if Entity_Matches_Spec
(It
.Nam
, New_S
)
4208 and then Is_Visible_Operation
(It
.Nam
)
4210 if Old_S
/= Any_Id
then
4212 -- Note: The call to Disambiguate only happens if a
4213 -- previous interpretation was found, in which case I1
4214 -- has received a value.
4216 It1
:= Disambiguate
(Nam
, I1
, Ind
, Etype
(Old_S
));
4218 if It1
= No_Interp
then
4220 Inst
:= Enclosing_Instance
;
4222 if Present
(Inst
) then
4224 if Within
(It
.Nam
, Inst
) then
4227 elsif Within
(Old_S
, Inst
) then
4231 return Report_Overload
;
4235 return Report_Overload
;
4249 Present
(First_Formal
(It
.Nam
))
4250 and then Present
(First_Formal
(New_S
))
4251 and then (Base_Type
(Etype
(First_Formal
(It
.Nam
)))
4252 = Base_Type
(Etype
(First_Formal
(New_S
))))
4254 Candidate_Renaming
:= It
.Nam
;
4257 Get_Next_Interp
(Ind
, It
);
4260 Set_Entity
(Nam
, Old_S
);
4261 Set_Is_Overloaded
(Nam
, False);
4265 end Find_Renamed_Entity
;
4267 -----------------------------
4268 -- Find_Selected_Component --
4269 -----------------------------
4271 procedure Find_Selected_Component
(N
: Node_Id
) is
4272 P
: constant Node_Id
:= Prefix
(N
);
4275 -- Entity denoted by prefix
4285 if Nkind
(P
) = N_Error
then
4288 -- If the selector already has an entity, the node has been
4289 -- constructed in the course of expansion, and is known to be
4290 -- valid. Do not verify that it is defined for the type (it may
4291 -- be a private component used in the expansion of record equality).
4293 elsif Present
(Entity
(Selector_Name
(N
))) then
4296 or else Etype
(N
) = Any_Type
4299 Sel_Name
: constant Node_Id
:= Selector_Name
(N
);
4300 Selector
: constant Entity_Id
:= Entity
(Sel_Name
);
4304 Set_Etype
(Sel_Name
, Etype
(Selector
));
4306 if not Is_Entity_Name
(P
) then
4310 -- Build an actual subtype except for the first parameter
4311 -- of an init proc, where this actual subtype is by
4312 -- definition incorrect, since the object is uninitialized
4313 -- (and does not even have defined discriminants etc.)
4315 if Is_Entity_Name
(P
)
4316 and then Ekind
(Entity
(P
)) = E_Function
4318 Nam
:= New_Copy
(P
);
4320 if Is_Overloaded
(P
) then
4321 Save_Interps
(P
, Nam
);
4325 Make_Function_Call
(Sloc
(P
), Name
=> Nam
));
4327 Analyze_Selected_Component
(N
);
4330 elsif Ekind
(Selector
) = E_Component
4331 and then (not Is_Entity_Name
(P
)
4332 or else Chars
(Entity
(P
)) /= Name_uInit
)
4335 Build_Actual_Subtype_Of_Component
(
4336 Etype
(Selector
), N
);
4341 if No
(C_Etype
) then
4342 C_Etype
:= Etype
(Selector
);
4344 Insert_Action
(N
, C_Etype
);
4345 C_Etype
:= Defining_Identifier
(C_Etype
);
4348 Set_Etype
(N
, C_Etype
);
4351 -- If this is the name of an entry or protected operation, and
4352 -- the prefix is an access type, insert an explicit dereference,
4353 -- so that entry calls are treated uniformly.
4355 if Is_Access_Type
(Etype
(P
))
4356 and then Is_Concurrent_Type
(Designated_Type
(Etype
(P
)))
4359 New_P
: constant Node_Id
:=
4360 Make_Explicit_Dereference
(Sloc
(P
),
4361 Prefix
=> Relocate_Node
(P
));
4364 Set_Etype
(P
, Designated_Type
(Etype
(Prefix
(P
))));
4368 -- If the selected component appears within a default expression
4369 -- and it has an actual subtype, the pre-analysis has not yet
4370 -- completed its analysis, because Insert_Actions is disabled in
4371 -- that context. Within the init proc of the enclosing type we
4372 -- must complete this analysis, if an actual subtype was created.
4374 elsif Inside_Init_Proc
then
4376 Typ
: constant Entity_Id
:= Etype
(N
);
4377 Decl
: constant Node_Id
:= Declaration_Node
(Typ
);
4380 if Nkind
(Decl
) = N_Subtype_Declaration
4381 and then not Analyzed
(Decl
)
4382 and then Is_List_Member
(Decl
)
4383 and then No
(Parent
(Decl
))
4386 Insert_Action
(N
, Decl
);
4393 elsif Is_Entity_Name
(P
) then
4394 P_Name
:= Entity
(P
);
4396 -- The prefix may denote an enclosing type which is the completion
4397 -- of an incomplete type declaration.
4399 if Is_Type
(P_Name
) then
4400 Set_Entity
(P
, Get_Full_View
(P_Name
));
4401 Set_Etype
(P
, Entity
(P
));
4402 P_Name
:= Entity
(P
);
4405 P_Type
:= Base_Type
(Etype
(P
));
4407 if Debug_Flag_E
then
4408 Write_Str
("Found prefix type to be ");
4409 Write_Entity_Info
(P_Type
, " "); Write_Eol
;
4412 -- First check for components of a record object (not the
4413 -- result of a call, which is handled below).
4415 if Is_Appropriate_For_Record
(P_Type
)
4416 and then not Is_Overloadable
(P_Name
)
4417 and then not Is_Type
(P_Name
)
4419 -- Selected component of record. Type checking will validate
4420 -- name of selector.
4422 Analyze_Selected_Component
(N
);
4424 elsif Is_Appropriate_For_Entry_Prefix
(P_Type
)
4425 and then not In_Open_Scopes
(P_Name
)
4426 and then (not Is_Concurrent_Type
(Etype
(P_Name
))
4427 or else not In_Open_Scopes
(Etype
(P_Name
)))
4429 -- Call to protected operation or entry. Type checking is
4430 -- needed on the prefix.
4432 Analyze_Selected_Component
(N
);
4434 elsif (In_Open_Scopes
(P_Name
)
4435 and then Ekind
(P_Name
) /= E_Void
4436 and then not Is_Overloadable
(P_Name
))
4437 or else (Is_Concurrent_Type
(Etype
(P_Name
))
4438 and then In_Open_Scopes
(Etype
(P_Name
)))
4440 -- Prefix denotes an enclosing loop, block, or task, i.e. an
4441 -- enclosing construct that is not a subprogram or accept.
4443 Find_Expanded_Name
(N
);
4445 elsif Ekind
(P_Name
) = E_Package
then
4446 Find_Expanded_Name
(N
);
4448 elsif Is_Overloadable
(P_Name
) then
4450 -- The subprogram may be a renaming (of an enclosing scope) as
4451 -- in the case of the name of the generic within an instantiation.
4453 if (Ekind
(P_Name
) = E_Procedure
4454 or else Ekind
(P_Name
) = E_Function
)
4455 and then Present
(Alias
(P_Name
))
4456 and then Is_Generic_Instance
(Alias
(P_Name
))
4458 P_Name
:= Alias
(P_Name
);
4461 if Is_Overloaded
(P
) then
4463 -- The prefix must resolve to a unique enclosing construct
4466 Found
: Boolean := False;
4471 Get_First_Interp
(P
, Ind
, It
);
4473 while Present
(It
.Nam
) loop
4475 if In_Open_Scopes
(It
.Nam
) then
4478 "prefix must be unique enclosing scope", N
);
4479 Set_Entity
(N
, Any_Id
);
4480 Set_Etype
(N
, Any_Type
);
4489 Get_Next_Interp
(Ind
, It
);
4494 if In_Open_Scopes
(P_Name
) then
4495 Set_Entity
(P
, P_Name
);
4496 Set_Is_Overloaded
(P
, False);
4497 Find_Expanded_Name
(N
);
4500 -- If no interpretation as an expanded name is possible, it
4501 -- must be a selected component of a record returned by a
4502 -- function call. Reformat prefix as a function call, the
4503 -- rest is done by type resolution. If the prefix is a
4504 -- procedure or entry, as is P.X; this is an error.
4506 if Ekind
(P_Name
) /= E_Function
4507 and then (not Is_Overloaded
(P
)
4509 Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
)
4512 -- Prefix may mention a package that is hidden by a local
4513 -- declaration: let the user know. Scan the full homonym
4514 -- chain, the candidate package may be anywhere on it.
4516 if Present
(Homonym
(Current_Entity
(P_Name
))) then
4518 P_Name
:= Current_Entity
(P_Name
);
4520 while Present
(P_Name
) loop
4521 exit when Ekind
(P_Name
) = E_Package
;
4522 P_Name
:= Homonym
(P_Name
);
4525 if Present
(P_Name
) then
4526 Error_Msg_Sloc
:= Sloc
(Entity
(Prefix
(N
)));
4529 ("package& is hidden by declaration#",
4532 Set_Entity
(Prefix
(N
), P_Name
);
4533 Find_Expanded_Name
(N
);
4536 P_Name
:= Entity
(Prefix
(N
));
4541 ("invalid prefix in selected component&", N
, P_Name
);
4542 Change_Selected_Component_To_Expanded_Name
(N
);
4543 Set_Entity
(N
, Any_Id
);
4544 Set_Etype
(N
, Any_Type
);
4547 Nam
:= New_Copy
(P
);
4548 Save_Interps
(P
, Nam
);
4550 Make_Function_Call
(Sloc
(P
), Name
=> Nam
));
4552 Analyze_Selected_Component
(N
);
4556 -- Remaining cases generate various error messages
4559 -- Format node as expanded name, to avoid cascaded errors
4561 Change_Selected_Component_To_Expanded_Name
(N
);
4562 Set_Entity
(N
, Any_Id
);
4563 Set_Etype
(N
, Any_Type
);
4565 -- Issue error message, but avoid this if error issued already.
4566 -- Use identifier of prefix if one is available.
4568 if P_Name
= Any_Id
then
4571 elsif Ekind
(P_Name
) = E_Void
then
4572 Premature_Usage
(P
);
4574 elsif Nkind
(P
) /= N_Attribute_Reference
then
4576 "invalid prefix in selected component&", P
);
4578 if Is_Access_Type
(P_Type
)
4579 and then Ekind
(Designated_Type
(P_Type
)) = E_Incomplete_Type
4582 ("\dereference must not be of an incomplete type " &
4583 "('R'M 3.10.1)", P
);
4588 "invalid prefix in selected component", P
);
4593 -- If prefix is not the name of an entity, it must be an expression,
4594 -- whose type is appropriate for a record. This is determined by
4597 Analyze_Selected_Component
(N
);
4599 end Find_Selected_Component
;
4605 procedure Find_Type
(N
: Node_Id
) is
4615 elsif Nkind
(N
) = N_Attribute_Reference
then
4617 -- Class attribute. This is only valid in Ada 95 mode, but we don't
4618 -- do a check, since the tagged type referenced could only exist if
4619 -- we were in 95 mode when it was declared (or, if we were in Ada
4620 -- 83 mode, then an error message would already have been issued).
4622 if Attribute_Name
(N
) = Name_Class
then
4623 Check_Restriction
(No_Dispatch
, N
);
4624 Find_Type
(Prefix
(N
));
4626 -- Propagate error from bad prefix
4628 if Etype
(Prefix
(N
)) = Any_Type
then
4629 Set_Entity
(N
, Any_Type
);
4630 Set_Etype
(N
, Any_Type
);
4634 T
:= Base_Type
(Entity
(Prefix
(N
)));
4636 -- Case type is not known to be tagged. Its appearance in
4637 -- the prefix of the 'Class attribute indicates that the full
4638 -- view will be tagged.
4640 if not Is_Tagged_Type
(T
) then
4641 if Ekind
(T
) = E_Incomplete_Type
then
4643 -- It is legal to denote the class type of an incomplete
4644 -- type. The full type will have to be tagged, of course.
4646 Set_Is_Tagged_Type
(T
);
4647 Set_Primitive_Operations
(T
, New_Elmt_List
);
4648 Make_Class_Wide_Type
(T
);
4649 Set_Entity
(N
, Class_Wide_Type
(T
));
4650 Set_Etype
(N
, Class_Wide_Type
(T
));
4652 elsif Ekind
(T
) = E_Private_Type
4653 and then not Is_Generic_Type
(T
)
4654 and then In_Private_Part
(Scope
(T
))
4656 -- The Class attribute can be applied to an untagged
4657 -- private type fulfilled by a tagged type prior to
4658 -- the full type declaration (but only within the
4659 -- parent package's private part). Create the class-wide
4660 -- type now and check that the full type is tagged
4661 -- later during its analysis. Note that we do not
4662 -- mark the private type as tagged, unlike the case
4663 -- of incomplete types, because the type must still
4664 -- appear untagged to outside units.
4666 if not Present
(Class_Wide_Type
(T
)) then
4667 Make_Class_Wide_Type
(T
);
4670 Set_Entity
(N
, Class_Wide_Type
(T
));
4671 Set_Etype
(N
, Class_Wide_Type
(T
));
4674 -- Should we introduce a type Any_Tagged and use
4675 -- Wrong_Type here, it would be a bit more consistent???
4678 ("tagged type required, found}",
4679 Prefix
(N
), First_Subtype
(T
));
4680 Set_Entity
(N
, Any_Type
);
4684 -- Case of tagged type
4687 C
:= Class_Wide_Type
(Entity
(Prefix
(N
)));
4688 Set_Entity_With_Style_Check
(N
, C
);
4689 Generate_Reference
(C
, N
);
4693 -- Base attribute, not allowed in Ada 83
4695 elsif Attribute_Name
(N
) = Name_Base
then
4696 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4698 ("(Ada 83) Base attribute not allowed in subtype mark", N
);
4701 Find_Type
(Prefix
(N
));
4702 Typ
:= Entity
(Prefix
(N
));
4704 if Ada_Version
>= Ada_95
4705 and then not Is_Scalar_Type
(Typ
)
4706 and then not Is_Generic_Type
(Typ
)
4709 ("prefix of Base attribute must be scalar type",
4712 elsif Sloc
(Typ
) = Standard_Location
4713 and then Base_Type
(Typ
) = Typ
4714 and then Warn_On_Redundant_Constructs
4717 ("?redudant attribute, & is its own base type", N
, Typ
);
4720 T
:= Base_Type
(Typ
);
4722 -- Rewrite attribute reference with type itself (see similar
4723 -- processing in Analyze_Attribute, case Base). Preserve
4724 -- prefix if present, for other legality checks.
4726 if Nkind
(Prefix
(N
)) = N_Expanded_Name
then
4728 Make_Expanded_Name
(Sloc
(N
),
4729 Chars
=> Chars
(Entity
(N
)),
4730 Prefix
=> New_Copy
(Prefix
(Prefix
(N
))),
4732 New_Reference_To
(Entity
(N
), Sloc
(N
))));
4736 New_Reference_To
(Entity
(N
), Sloc
(N
)));
4743 -- All other attributes are invalid in a subtype mark
4746 Error_Msg_N
("invalid attribute in subtype mark", N
);
4752 if Is_Entity_Name
(N
) then
4753 T_Name
:= Entity
(N
);
4755 Error_Msg_N
("subtype mark required in this context", N
);
4756 Set_Etype
(N
, Any_Type
);
4760 if T_Name
= Any_Id
or else Etype
(N
) = Any_Type
then
4762 -- Undefined id. Make it into a valid type
4764 Set_Entity
(N
, Any_Type
);
4766 elsif not Is_Type
(T_Name
)
4767 and then T_Name
/= Standard_Void_Type
4769 Error_Msg_Sloc
:= Sloc
(T_Name
);
4770 Error_Msg_N
("subtype mark required in this context", N
);
4771 Error_Msg_NE
("\found & declared#", N
, T_Name
);
4772 Set_Entity
(N
, Any_Type
);
4775 T_Name
:= Get_Full_View
(T_Name
);
4777 if In_Open_Scopes
(T_Name
) then
4778 if Ekind
(Base_Type
(T_Name
)) = E_Task_Type
then
4779 Error_Msg_N
("task type cannot be used as type mark " &
4780 "within its own body", N
);
4782 Error_Msg_N
("type declaration cannot refer to itself", N
);
4785 Set_Etype
(N
, Any_Type
);
4786 Set_Entity
(N
, Any_Type
);
4787 Set_Error_Posted
(T_Name
);
4791 Set_Entity
(N
, T_Name
);
4792 Set_Etype
(N
, T_Name
);
4796 if Present
(Etype
(N
)) and then Comes_From_Source
(N
) then
4797 if Is_Fixed_Point_Type
(Etype
(N
)) then
4798 Check_Restriction
(No_Fixed_Point
, N
);
4799 elsif Is_Floating_Point_Type
(Etype
(N
)) then
4800 Check_Restriction
(No_Floating_Point
, N
);
4809 function Get_Full_View
(T_Name
: Entity_Id
) return Entity_Id
is
4811 if Ekind
(T_Name
) = E_Incomplete_Type
4812 and then Present
(Full_View
(T_Name
))
4814 return Full_View
(T_Name
);
4816 elsif Is_Class_Wide_Type
(T_Name
)
4817 and then Ekind
(Root_Type
(T_Name
)) = E_Incomplete_Type
4818 and then Present
(Full_View
(Root_Type
(T_Name
)))
4820 return Class_Wide_Type
(Full_View
(Root_Type
(T_Name
)));
4827 ------------------------------------
4828 -- Has_Implicit_Character_Literal --
4829 ------------------------------------
4831 function Has_Implicit_Character_Literal
(N
: Node_Id
) return Boolean is
4833 Found
: Boolean := False;
4834 P
: constant Entity_Id
:= Entity
(Prefix
(N
));
4835 Priv_Id
: Entity_Id
:= Empty
;
4838 if Ekind
(P
) = E_Package
4839 and then not In_Open_Scopes
(P
)
4841 Priv_Id
:= First_Private_Entity
(P
);
4844 if P
= Standard_Standard
then
4845 Change_Selected_Component_To_Expanded_Name
(N
);
4846 Rewrite
(N
, Selector_Name
(N
));
4848 Set_Etype
(Original_Node
(N
), Standard_Character
);
4852 Id
:= First_Entity
(P
);
4855 and then Id
/= Priv_Id
4857 if Is_Character_Type
(Id
)
4858 and then (Root_Type
(Id
) = Standard_Character
4859 or else Root_Type
(Id
) = Standard_Wide_Character
4860 or else Root_Type
(Id
) = Standard_Wide_Wide_Character
)
4861 and then Id
= Base_Type
(Id
)
4863 -- We replace the node with the literal itself, resolve as a
4864 -- character, and set the type correctly.
4867 Change_Selected_Component_To_Expanded_Name
(N
);
4868 Rewrite
(N
, Selector_Name
(N
));
4871 Set_Etype
(Original_Node
(N
), Id
);
4875 -- More than one type derived from Character in given scope.
4876 -- Collect all possible interpretations.
4878 Add_One_Interp
(N
, Id
, Id
);
4886 end Has_Implicit_Character_Literal
;
4888 ----------------------
4889 -- Has_Private_With --
4890 ----------------------
4892 function Has_Private_With
(E
: Entity_Id
) return Boolean is
4893 Comp_Unit
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
4897 Item
:= First
(Context_Items
(Comp_Unit
));
4898 while Present
(Item
) loop
4899 if Nkind
(Item
) = N_With_Clause
4900 and then Private_Present
(Item
)
4901 and then Entity
(Name
(Item
)) = E
4910 end Has_Private_With
;
4912 ---------------------------
4913 -- Has_Implicit_Operator --
4914 ---------------------------
4916 function Has_Implicit_Operator
(N
: Node_Id
) return Boolean is
4917 Op_Id
: constant Name_Id
:= Chars
(Selector_Name
(N
));
4918 P
: constant Entity_Id
:= Entity
(Prefix
(N
));
4920 Priv_Id
: Entity_Id
:= Empty
;
4922 procedure Add_Implicit_Operator
4924 Op_Type
: Entity_Id
:= Empty
);
4925 -- Add implicit interpretation to node N, using the type for which
4926 -- a predefined operator exists. If the operator yields a boolean
4927 -- type, the Operand_Type is implicitly referenced by the operator,
4928 -- and a reference to it must be generated.
4930 ---------------------------
4931 -- Add_Implicit_Operator --
4932 ---------------------------
4934 procedure Add_Implicit_Operator
4936 Op_Type
: Entity_Id
:= Empty
)
4938 Predef_Op
: Entity_Id
;
4941 Predef_Op
:= Current_Entity
(Selector_Name
(N
));
4943 while Present
(Predef_Op
)
4944 and then Scope
(Predef_Op
) /= Standard_Standard
4946 Predef_Op
:= Homonym
(Predef_Op
);
4949 if Nkind
(N
) = N_Selected_Component
then
4950 Change_Selected_Component_To_Expanded_Name
(N
);
4953 Add_One_Interp
(N
, Predef_Op
, T
);
4955 -- For operators with unary and binary interpretations, add both
4957 if Present
(Homonym
(Predef_Op
)) then
4958 Add_One_Interp
(N
, Homonym
(Predef_Op
), T
);
4961 -- The node is a reference to a predefined operator, and
4962 -- an implicit reference to the type of its operands.
4964 if Present
(Op_Type
) then
4965 Generate_Operator_Reference
(N
, Op_Type
);
4967 Generate_Operator_Reference
(N
, T
);
4969 end Add_Implicit_Operator
;
4971 -- Start of processing for Has_Implicit_Operator
4975 if Ekind
(P
) = E_Package
4976 and then not In_Open_Scopes
(P
)
4978 Priv_Id
:= First_Private_Entity
(P
);
4981 Id
:= First_Entity
(P
);
4985 -- Boolean operators: an implicit declaration exists if the scope
4986 -- contains a declaration for a derived Boolean type, or for an
4987 -- array of Boolean type.
4989 when Name_Op_And | Name_Op_Not | Name_Op_Or | Name_Op_Xor
=>
4991 while Id
/= Priv_Id
loop
4993 if Valid_Boolean_Arg
(Id
)
4994 and then Id
= Base_Type
(Id
)
4996 Add_Implicit_Operator
(Id
);
5003 -- Equality: look for any non-limited type (result is Boolean)
5005 when Name_Op_Eq | Name_Op_Ne
=>
5007 while Id
/= Priv_Id
loop
5010 and then not Is_Limited_Type
(Id
)
5011 and then Id
= Base_Type
(Id
)
5013 Add_Implicit_Operator
(Standard_Boolean
, Id
);
5020 -- Comparison operators: scalar type, or array of scalar
5022 when Name_Op_Lt | Name_Op_Le | Name_Op_Gt | Name_Op_Ge
=>
5024 while Id
/= Priv_Id
loop
5025 if (Is_Scalar_Type
(Id
)
5026 or else (Is_Array_Type
(Id
)
5027 and then Is_Scalar_Type
(Component_Type
(Id
))))
5028 and then Id
= Base_Type
(Id
)
5030 Add_Implicit_Operator
(Standard_Boolean
, Id
);
5037 -- Arithmetic operators: any numeric type
5048 while Id
/= Priv_Id
loop
5049 if Is_Numeric_Type
(Id
)
5050 and then Id
= Base_Type
(Id
)
5052 Add_Implicit_Operator
(Id
);
5059 -- Concatenation: any one-dimensional array type
5061 when Name_Op_Concat
=>
5063 while Id
/= Priv_Id
loop
5064 if Is_Array_Type
(Id
) and then Number_Dimensions
(Id
) = 1
5065 and then Id
= Base_Type
(Id
)
5067 Add_Implicit_Operator
(Id
);
5074 -- What is the others condition here? Should we be using a
5075 -- subtype of Name_Id that would restrict to operators ???
5077 when others => null;
5081 -- If we fall through, then we do not have an implicit operator
5085 end Has_Implicit_Operator
;
5087 --------------------
5088 -- In_Open_Scopes --
5089 --------------------
5091 function In_Open_Scopes
(S
: Entity_Id
) return Boolean is
5093 -- Since there are several scope stacks maintained by Scope_Stack each
5094 -- delineated by Standard (see comments by definition of Scope_Stack)
5095 -- it is necessary to end the search when Standard is reached.
5097 for J
in reverse 0 .. Scope_Stack
.Last
loop
5098 if Scope_Stack
.Table
(J
).Entity
= S
then
5102 -- We need Is_Active_Stack_Base to tell us when to stop rather
5103 -- than checking for Standard_Standard because there are cases
5104 -- where Standard_Standard appears in the middle of the active
5105 -- set of scopes. This affects the declaration and overriding
5106 -- of private inherited operations in instantiations of generic
5109 exit when Scope_Stack
.Table
(J
).Is_Active_Stack_Base
;
5115 -----------------------------
5116 -- Inherit_Renamed_Profile --
5117 -----------------------------
5119 procedure Inherit_Renamed_Profile
(New_S
: Entity_Id
; Old_S
: Entity_Id
) is
5126 if Ekind
(Old_S
) = E_Operator
then
5128 New_F
:= First_Formal
(New_S
);
5130 while Present
(New_F
) loop
5131 Set_Etype
(New_F
, Base_Type
(Etype
(New_F
)));
5132 Next_Formal
(New_F
);
5135 Set_Etype
(New_S
, Base_Type
(Etype
(New_S
)));
5138 New_F
:= First_Formal
(New_S
);
5139 Old_F
:= First_Formal
(Old_S
);
5141 while Present
(New_F
) loop
5142 New_T
:= Etype
(New_F
);
5143 Old_T
:= Etype
(Old_F
);
5145 -- If the new type is a renaming of the old one, as is the
5146 -- case for actuals in instances, retain its name, to simplify
5147 -- later disambiguation.
5149 if Nkind
(Parent
(New_T
)) = N_Subtype_Declaration
5150 and then Is_Entity_Name
(Subtype_Indication
(Parent
(New_T
)))
5151 and then Entity
(Subtype_Indication
(Parent
(New_T
))) = Old_T
5155 Set_Etype
(New_F
, Old_T
);
5158 Next_Formal
(New_F
);
5159 Next_Formal
(Old_F
);
5162 if Ekind
(Old_S
) = E_Function
5163 or else Ekind
(Old_S
) = E_Enumeration_Literal
5165 Set_Etype
(New_S
, Etype
(Old_S
));
5168 end Inherit_Renamed_Profile
;
5174 procedure Initialize
is
5179 -------------------------
5180 -- Install_Use_Clauses --
5181 -------------------------
5183 procedure Install_Use_Clauses
5185 Force_Installation
: Boolean := False)
5187 U
: Node_Id
:= Clause
;
5192 while Present
(U
) loop
5194 -- Case of USE package
5196 if Nkind
(U
) = N_Use_Package_Clause
then
5197 P
:= First
(Names
(U
));
5199 while Present
(P
) loop
5202 if Ekind
(Id
) = E_Package
then
5205 Note_Redundant_Use
(P
);
5207 elsif Present
(Renamed_Object
(Id
))
5208 and then In_Use
(Renamed_Object
(Id
))
5210 Note_Redundant_Use
(P
);
5212 elsif Force_Installation
or else Applicable_Use
(P
) then
5213 Use_One_Package
(Id
, U
);
5224 P
:= First
(Subtype_Marks
(U
));
5226 while Present
(P
) loop
5227 if not Is_Entity_Name
(P
)
5228 or else No
(Entity
(P
))
5232 elsif Entity
(P
) /= Any_Type
then
5240 Next_Use_Clause
(U
);
5242 end Install_Use_Clauses
;
5244 -------------------------------------
5245 -- Is_Appropriate_For_Entry_Prefix --
5246 -------------------------------------
5248 function Is_Appropriate_For_Entry_Prefix
(T
: Entity_Id
) return Boolean is
5249 P_Type
: Entity_Id
:= T
;
5252 if Is_Access_Type
(P_Type
) then
5253 P_Type
:= Designated_Type
(P_Type
);
5256 return Is_Task_Type
(P_Type
) or else Is_Protected_Type
(P_Type
);
5257 end Is_Appropriate_For_Entry_Prefix
;
5259 -------------------------------
5260 -- Is_Appropriate_For_Record --
5261 -------------------------------
5263 function Is_Appropriate_For_Record
(T
: Entity_Id
) return Boolean is
5265 function Has_Components
(T1
: Entity_Id
) return Boolean;
5266 -- Determine if given type has components (i.e. is either a record
5267 -- type or a type that has discriminants).
5269 function Has_Components
(T1
: Entity_Id
) return Boolean is
5271 return Is_Record_Type
(T1
)
5272 or else (Is_Private_Type
(T1
) and then Has_Discriminants
(T1
))
5273 or else (Is_Task_Type
(T1
) and then Has_Discriminants
(T1
));
5276 -- Start of processing for Is_Appropriate_For_Record
5281 and then (Has_Components
(T
)
5282 or else (Is_Access_Type
(T
)
5284 Has_Components
(Designated_Type
(T
))));
5285 end Is_Appropriate_For_Record
;
5291 procedure New_Scope
(S
: Entity_Id
) is
5295 if Ekind
(S
) = E_Void
then
5298 -- Set scope depth if not a non-concurrent type, and we have not
5299 -- yet set the scope depth. This means that we have the first
5300 -- occurrence of the scope, and this is where the depth is set.
5302 elsif (not Is_Type
(S
) or else Is_Concurrent_Type
(S
))
5303 and then not Scope_Depth_Set
(S
)
5305 if S
= Standard_Standard
then
5306 Set_Scope_Depth_Value
(S
, Uint_0
);
5308 elsif Is_Child_Unit
(S
) then
5309 Set_Scope_Depth_Value
(S
, Uint_1
);
5311 elsif not Is_Record_Type
(Current_Scope
) then
5312 if Ekind
(S
) = E_Loop
then
5313 Set_Scope_Depth_Value
(S
, Scope_Depth
(Current_Scope
));
5315 Set_Scope_Depth_Value
(S
, Scope_Depth
(Current_Scope
) + 1);
5320 Scope_Stack
.Increment_Last
;
5323 SST
: Scope_Stack_Entry
renames Scope_Stack
.Table
(Scope_Stack
.Last
);
5327 SST
.Save_Scope_Suppress
:= Scope_Suppress
;
5328 SST
.Save_Local_Entity_Suppress
:= Local_Entity_Suppress
.Last
;
5330 if Scope_Stack
.Last
> Scope_Stack
.First
then
5331 SST
.Component_Alignment_Default
:= Scope_Stack
.Table
5332 (Scope_Stack
.Last
- 1).
5333 Component_Alignment_Default
;
5336 SST
.Last_Subprogram_Name
:= null;
5337 SST
.Is_Transient
:= False;
5338 SST
.Node_To_Be_Wrapped
:= Empty
;
5339 SST
.Pending_Freeze_Actions
:= No_List
;
5340 SST
.Actions_To_Be_Wrapped_Before
:= No_List
;
5341 SST
.Actions_To_Be_Wrapped_After
:= No_List
;
5342 SST
.First_Use_Clause
:= Empty
;
5343 SST
.Is_Active_Stack_Base
:= False;
5346 if Debug_Flag_W
then
5347 Write_Str
("--> new scope: ");
5348 Write_Name
(Chars
(Current_Scope
));
5349 Write_Str
(", Id=");
5350 Write_Int
(Int
(Current_Scope
));
5351 Write_Str
(", Depth=");
5352 Write_Int
(Int
(Scope_Stack
.Last
));
5356 -- Copy from Scope (S) the categorization flags to S, this is not
5357 -- done in case Scope (S) is Standard_Standard since propagation
5358 -- is from library unit entity inwards.
5360 if S
/= Standard_Standard
5361 and then Scope
(S
) /= Standard_Standard
5362 and then not Is_Child_Unit
(S
)
5366 if Nkind
(E
) not in N_Entity
then
5370 -- We only propagate inwards for library level entities,
5371 -- inner level subprograms do not inherit the categorization.
5373 if Is_Library_Level_Entity
(S
) then
5374 Set_Is_Preelaborated
(S
, Is_Preelaborated
(E
));
5375 Set_Is_Shared_Passive
(S
, Is_Shared_Passive
(E
));
5376 Set_Categorization_From_Scope
(E
=> S
, Scop
=> E
);
5381 ------------------------
5382 -- Note_Redundant_Use --
5383 ------------------------
5385 procedure Note_Redundant_Use
(Clause
: Node_Id
) is
5386 Pack_Name
: constant Entity_Id
:= Entity
(Clause
);
5387 Cur_Use
: constant Node_Id
:= Current_Use_Clause
(Pack_Name
);
5388 Decl
: constant Node_Id
:= Parent
(Clause
);
5390 Prev_Use
: Node_Id
:= Empty
;
5391 Redundant
: Node_Id
:= Empty
;
5392 -- The Use_Clause which is actually redundant. In the simplest case
5393 -- it is Pack itself, but when we compile a body we install its
5394 -- context before that of its spec, in which case it is the use_clause
5395 -- in the spec that will appear to be redundant, and we want the
5396 -- warning to be placed on the body. Similar complications appear when
5397 -- the redundancy is between a child unit and one of its ancestors.
5400 Set_Redundant_Use
(Clause
, True);
5402 if not Comes_From_Source
(Clause
)
5404 or else not Warn_On_Redundant_Constructs
5409 if not Is_Compilation_Unit
(Current_Scope
) then
5411 -- If the use_clause is in an inner scope, it is made redundant
5412 -- by some clause in the current context.
5414 Redundant
:= Clause
;
5415 Prev_Use
:= Cur_Use
;
5417 elsif Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
then
5419 Cur_Unit
: constant Unit_Number_Type
:= Get_Source_Unit
(Cur_Use
);
5420 New_Unit
: constant Unit_Number_Type
:= Get_Source_Unit
(Clause
);
5424 if Cur_Unit
= New_Unit
then
5426 -- Redundant clause in same body
5428 Redundant
:= Clause
;
5429 Prev_Use
:= Cur_Use
;
5431 elsif Cur_Unit
= Current_Sem_Unit
then
5433 -- If the new clause is not in the current unit it has been
5434 -- analyzed first, and it makes the other one redundant.
5435 -- However, if the new clause appears in a subunit, Cur_Unit
5436 -- is still the parent, and in that case the redundant one
5437 -- is the one appearing in the subunit.
5439 if Nkind
(Unit
(Cunit
(New_Unit
))) = N_Subunit
then
5440 Redundant
:= Clause
;
5441 Prev_Use
:= Cur_Use
;
5443 -- Most common case: redundant clause in body,
5444 -- original clause in spec. Current scope is spec entity.
5449 Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
))))
5451 Redundant
:= Cur_Use
;
5455 -- The new clause may appear in an unrelated unit, when
5456 -- the parents of a generic are being installed prior to
5457 -- instantiation. In this case there must be no warning.
5458 -- We detect this case by checking whether the current top
5459 -- of the stack is related to the current compilation.
5461 Scop
:= Current_Scope
;
5462 while Present
(Scop
)
5463 and then Scop
/= Standard_Standard
5465 if Is_Compilation_Unit
(Scop
)
5466 and then not Is_Child_Unit
(Scop
)
5470 elsif Scop
= Cunit_Entity
(Current_Sem_Unit
) then
5474 Scop
:= Scope
(Scop
);
5477 Redundant
:= Cur_Use
;
5481 elsif New_Unit
= Current_Sem_Unit
then
5482 Redundant
:= Clause
;
5483 Prev_Use
:= Cur_Use
;
5486 -- Neither is the current unit, so they appear in parent or
5487 -- sibling units. Warning will be emitted elsewhere.
5493 elsif Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Declaration
5494 and then Present
(Parent_Spec
(Unit
(Cunit
(Current_Sem_Unit
))))
5496 -- Use_clause is in child unit of current unit, and the child
5497 -- unit appears in the context of the body of the parent, so it
5498 -- has been installed first, even though it is the redundant one.
5499 -- Depending on their placement in the context, the visible or the
5500 -- private parts of the two units, either might appear as redundant,
5501 -- but the message has to be on the current unit.
5503 if Get_Source_Unit
(Cur_Use
) = Current_Sem_Unit
then
5504 Redundant
:= Cur_Use
;
5507 Redundant
:= Clause
;
5508 Prev_Use
:= Cur_Use
;
5511 -- If the new use clause appears in the private part of a parent unit
5512 -- it may appear to be redudant w.r.t. a use clause in a child unit,
5513 -- but the previous use clause was needed in the visible part of the
5514 -- child, and no warning should be emitted.
5516 if Nkind
(Parent
(Decl
)) = N_Package_Specification
5518 List_Containing
(Decl
) = Private_Declarations
(Parent
(Decl
))
5521 Par
: constant Entity_Id
:= Defining_Entity
(Parent
(Decl
));
5522 Spec
: constant Node_Id
:=
5523 Specification
(Unit
(Cunit
(Current_Sem_Unit
)));
5526 if Is_Compilation_Unit
(Par
)
5527 and then Par
/= Cunit_Entity
(Current_Sem_Unit
)
5528 and then Parent
(Cur_Use
) = Spec
5530 List_Containing
(Cur_Use
) = Visible_Declarations
(Spec
)
5541 if Present
(Redundant
) then
5542 Error_Msg_Sloc
:= Sloc
(Prev_Use
);
5544 "& is already use_visible through declaration #?",
5545 Redundant
, Pack_Name
);
5547 end Note_Redundant_Use
;
5553 procedure Pop_Scope
is
5554 SST
: Scope_Stack_Entry
renames Scope_Stack
.Table
(Scope_Stack
.Last
);
5557 if Debug_Flag_E
then
5561 Scope_Suppress
:= SST
.Save_Scope_Suppress
;
5562 Local_Entity_Suppress
.Set_Last
(SST
.Save_Local_Entity_Suppress
);
5564 if Debug_Flag_W
then
5565 Write_Str
("--> exiting scope: ");
5566 Write_Name
(Chars
(Current_Scope
));
5567 Write_Str
(", Depth=");
5568 Write_Int
(Int
(Scope_Stack
.Last
));
5572 End_Use_Clauses
(SST
.First_Use_Clause
);
5574 -- If the actions to be wrapped are still there they will get lost
5575 -- causing incomplete code to be generated. It is better to abort in
5576 -- this case (and we do the abort even with assertions off since the
5577 -- penalty is incorrect code generation)
5579 if SST
.Actions_To_Be_Wrapped_Before
/= No_List
5581 SST
.Actions_To_Be_Wrapped_After
/= No_List
5586 -- Free last subprogram name if allocated, and pop scope
5588 Free
(SST
.Last_Subprogram_Name
);
5589 Scope_Stack
.Decrement_Last
;
5592 ---------------------
5593 -- Premature_Usage --
5594 ---------------------
5596 procedure Premature_Usage
(N
: Node_Id
) is
5597 Kind
: constant Node_Kind
:= Nkind
(Parent
(Entity
(N
)));
5598 E
: Entity_Id
:= Entity
(N
);
5601 -- Within an instance, the analysis of the actual for a formal object
5602 -- does not see the name of the object itself. This is significant
5603 -- only if the object is an aggregate, where its analysis does not do
5604 -- any name resolution on component associations. (see 4717-008). In
5605 -- such a case, look for the visible homonym on the chain.
5608 and then Present
(Homonym
(E
))
5613 and then not In_Open_Scopes
(Scope
(E
))
5620 Set_Etype
(N
, Etype
(E
));
5625 if Kind
= N_Component_Declaration
then
5627 ("component&! cannot be used before end of record declaration", N
);
5629 elsif Kind
= N_Parameter_Specification
then
5631 ("formal parameter&! cannot be used before end of specification",
5634 elsif Kind
= N_Discriminant_Specification
then
5636 ("discriminant&! cannot be used before end of discriminant part",
5639 elsif Kind
= N_Procedure_Specification
5640 or else Kind
= N_Function_Specification
5643 ("subprogram&! cannot be used before end of its declaration",
5647 ("object& cannot be used before end of its declaration!", N
);
5649 end Premature_Usage
;
5651 ------------------------
5652 -- Present_System_Aux --
5653 ------------------------
5655 function Present_System_Aux
(N
: Node_Id
:= Empty
) return Boolean is
5658 Unum
: Unit_Number_Type
;
5663 function Find_System
(C_Unit
: Node_Id
) return Entity_Id
;
5664 -- Scan context clause of compilation unit to find a with_clause
5671 function Find_System
(C_Unit
: Node_Id
) return Entity_Id
is
5672 With_Clause
: Node_Id
;
5675 With_Clause
:= First
(Context_Items
(C_Unit
));
5677 while Present
(With_Clause
) loop
5678 if (Nkind
(With_Clause
) = N_With_Clause
5679 and then Chars
(Name
(With_Clause
)) = Name_System
)
5680 and then Comes_From_Source
(With_Clause
)
5691 -- Start of processing for Present_System_Aux
5694 -- The child unit may have been loaded and analyzed already
5696 if Present
(System_Aux_Id
) then
5699 -- If no previous pragma for System.Aux, nothing to load
5701 elsif No
(System_Extend_Unit
) then
5704 -- Use the unit name given in the pragma to retrieve the unit.
5705 -- Verify that System itself appears in the context clause of the
5706 -- current compilation. If System is not present, an error will
5707 -- have been reported already.
5710 With_Sys
:= Find_System
(Cunit
(Current_Sem_Unit
));
5712 The_Unit
:= Unit
(Cunit
(Current_Sem_Unit
));
5715 and then (Nkind
(The_Unit
) = N_Package_Body
5716 or else (Nkind
(The_Unit
) = N_Subprogram_Body
5717 and then not Acts_As_Spec
(Cunit
(Current_Sem_Unit
))))
5719 With_Sys
:= Find_System
(Library_Unit
(Cunit
(Current_Sem_Unit
)));
5723 and then Present
(N
)
5725 -- If we are compiling a subunit, we need to examine its
5726 -- context as well (Current_Sem_Unit is the parent unit);
5728 The_Unit
:= Parent
(N
);
5730 while Nkind
(The_Unit
) /= N_Compilation_Unit
loop
5731 The_Unit
:= Parent
(The_Unit
);
5734 if Nkind
(Unit
(The_Unit
)) = N_Subunit
then
5735 With_Sys
:= Find_System
(The_Unit
);
5739 if No
(With_Sys
) then
5743 Loc
:= Sloc
(With_Sys
);
5744 Get_Name_String
(Chars
(Expression
(System_Extend_Unit
)));
5745 Name_Buffer
(8 .. Name_Len
+ 7) := Name_Buffer
(1 .. Name_Len
);
5746 Name_Buffer
(1 .. 7) := "system.";
5747 Name_Buffer
(Name_Len
+ 8) := '%';
5748 Name_Buffer
(Name_Len
+ 9) := 's';
5749 Name_Len
:= Name_Len
+ 9;
5750 Aux_Name
:= Name_Find
;
5754 (Load_Name
=> Aux_Name
,
5757 Error_Node
=> With_Sys
);
5759 if Unum
/= No_Unit
then
5760 Semantics
(Cunit
(Unum
));
5762 Defining_Entity
(Specification
(Unit
(Cunit
(Unum
))));
5764 Withn
:= Make_With_Clause
(Loc
,
5766 Make_Expanded_Name
(Loc
,
5767 Chars
=> Chars
(System_Aux_Id
),
5769 New_Reference_To
(Scope
(System_Aux_Id
), Loc
),
5771 New_Reference_To
(System_Aux_Id
, Loc
)));
5773 Set_Entity
(Name
(Withn
), System_Aux_Id
);
5775 Set_Library_Unit
(Withn
, Cunit
(Unum
));
5776 Set_Corresponding_Spec
(Withn
, System_Aux_Id
);
5777 Set_First_Name
(Withn
, True);
5778 Set_Implicit_With
(Withn
, True);
5780 Insert_After
(With_Sys
, Withn
);
5781 Mark_Rewrite_Insertion
(Withn
);
5782 Set_Context_Installed
(Withn
);
5786 -- Here if unit load failed
5789 Error_Msg_Name_1
:= Name_System
;
5790 Error_Msg_Name_2
:= Chars
(Expression
(System_Extend_Unit
));
5792 ("extension package `%.%` does not exist",
5793 Opt
.System_Extend_Unit
);
5797 end Present_System_Aux
;
5799 -------------------------
5800 -- Restore_Scope_Stack --
5801 -------------------------
5803 procedure Restore_Scope_Stack
(Handle_Use
: Boolean := True) is
5806 Comp_Unit
: Node_Id
;
5807 In_Child
: Boolean := False;
5808 Full_Vis
: Boolean := True;
5809 SS_Last
: constant Int
:= Scope_Stack
.Last
;
5812 -- Restore visibility of previous scope stack, if any
5814 for J
in reverse 0 .. Scope_Stack
.Last
loop
5815 exit when Scope_Stack
.Table
(J
).Entity
= Standard_Standard
5816 or else No
(Scope_Stack
.Table
(J
).Entity
);
5818 S
:= Scope_Stack
.Table
(J
).Entity
;
5820 if not Is_Hidden_Open_Scope
(S
) then
5822 -- If the parent scope is hidden, its entities are hidden as
5823 -- well, unless the entity is the instantiation currently
5826 if not Is_Hidden_Open_Scope
(Scope
(S
))
5827 or else not Analyzed
(Parent
(S
))
5828 or else Scope
(S
) = Standard_Standard
5830 Set_Is_Immediately_Visible
(S
, True);
5833 E
:= First_Entity
(S
);
5835 while Present
(E
) loop
5836 if Is_Child_Unit
(E
) then
5837 Set_Is_Immediately_Visible
(E
,
5838 Is_Visible_Child_Unit
(E
) or else In_Open_Scopes
(E
));
5840 Set_Is_Immediately_Visible
(E
, True);
5845 if not Full_Vis
then
5846 exit when E
= First_Private_Entity
(S
);
5850 -- The visibility of child units (siblings of current compilation)
5851 -- must be restored in any case. Their declarations may appear
5852 -- after the private part of the parent.
5855 and then Present
(E
)
5857 while Present
(E
) loop
5858 if Is_Child_Unit
(E
) then
5859 Set_Is_Immediately_Visible
(E
,
5860 Is_Visible_Child_Unit
(E
) or else In_Open_Scopes
(E
));
5868 if Is_Child_Unit
(S
)
5869 and not In_Child
-- check only for current unit.
5873 -- restore visibility of parents according to whether the child
5874 -- is private and whether we are in its visible part.
5876 Comp_Unit
:= Parent
(Unit_Declaration_Node
(S
));
5878 if Nkind
(Comp_Unit
) = N_Compilation_Unit
5879 and then Private_Present
(Comp_Unit
)
5883 elsif (Ekind
(S
) = E_Package
5884 or else Ekind
(S
) = E_Generic_Package
)
5885 and then (In_Private_Part
(S
)
5886 or else In_Package_Body
(S
))
5890 elsif (Ekind
(S
) = E_Procedure
5891 or else Ekind
(S
) = E_Function
)
5892 and then Has_Completion
(S
)
5903 if SS_Last
>= Scope_Stack
.First
5904 and then Scope_Stack
.Table
(SS_Last
).Entity
/= Standard_Standard
5907 Install_Use_Clauses
(Scope_Stack
.Table
(SS_Last
).First_Use_Clause
);
5909 end Restore_Scope_Stack
;
5911 ----------------------
5912 -- Save_Scope_Stack --
5913 ----------------------
5915 procedure Save_Scope_Stack
(Handle_Use
: Boolean := True) is
5918 SS_Last
: constant Int
:= Scope_Stack
.Last
;
5921 if SS_Last
>= Scope_Stack
.First
5922 and then Scope_Stack
.Table
(SS_Last
).Entity
/= Standard_Standard
5925 End_Use_Clauses
(Scope_Stack
.Table
(SS_Last
).First_Use_Clause
);
5928 -- If the call is from within a compilation unit, as when
5929 -- called from Rtsfind, make current entries in scope stack
5930 -- invisible while we analyze the new unit.
5932 for J
in reverse 0 .. SS_Last
loop
5933 exit when Scope_Stack
.Table
(J
).Entity
= Standard_Standard
5934 or else No
(Scope_Stack
.Table
(J
).Entity
);
5936 S
:= Scope_Stack
.Table
(J
).Entity
;
5937 Set_Is_Immediately_Visible
(S
, False);
5938 E
:= First_Entity
(S
);
5940 while Present
(E
) loop
5941 Set_Is_Immediately_Visible
(E
, False);
5947 end Save_Scope_Stack
;
5953 procedure Set_Use
(L
: List_Id
) is
5955 Pack_Name
: Node_Id
;
5963 while Present
(Decl
) loop
5964 if Nkind
(Decl
) = N_Use_Package_Clause
then
5965 Chain_Use_Clause
(Decl
);
5966 Pack_Name
:= First
(Names
(Decl
));
5968 while Present
(Pack_Name
) loop
5969 Pack
:= Entity
(Pack_Name
);
5971 if Ekind
(Pack
) = E_Package
5972 and then Applicable_Use
(Pack_Name
)
5974 Use_One_Package
(Pack
, Decl
);
5980 elsif Nkind
(Decl
) = N_Use_Type_Clause
then
5981 Chain_Use_Clause
(Decl
);
5982 Id
:= First
(Subtype_Marks
(Decl
));
5984 while Present
(Id
) loop
5985 if Entity
(Id
) /= Any_Type
then
5998 ---------------------
5999 -- Use_One_Package --
6000 ---------------------
6002 procedure Use_One_Package
(P
: Entity_Id
; N
: Node_Id
) is
6005 Current_Instance
: Entity_Id
:= Empty
;
6007 Private_With_OK
: Boolean := False;
6010 if Ekind
(P
) /= E_Package
then
6015 Set_Current_Use_Clause
(P
, N
);
6017 -- Ada 2005 (AI-50217): Check restriction
6019 if From_With_Type
(P
) then
6020 Error_Msg_N
("limited withed package cannot appear in use clause", N
);
6023 -- Find enclosing instance, if any
6026 Current_Instance
:= Current_Scope
;
6028 while not Is_Generic_Instance
(Current_Instance
) loop
6029 Current_Instance
:= Scope
(Current_Instance
);
6032 if No
(Hidden_By_Use_Clause
(N
)) then
6033 Set_Hidden_By_Use_Clause
(N
, New_Elmt_List
);
6037 -- If unit is a package renaming, indicate that the renamed
6038 -- package is also in use (the flags on both entities must
6039 -- remain consistent, and a subsequent use of either of them
6040 -- should be recognized as redundant).
6042 if Present
(Renamed_Object
(P
)) then
6043 Set_In_Use
(Renamed_Object
(P
));
6044 Set_Current_Use_Clause
(Renamed_Object
(P
), N
);
6045 Real_P
:= Renamed_Object
(P
);
6050 -- Ada 2005 (AI-262): Check the use_clause of a private withed package
6051 -- found in the private part of a package specification
6053 if In_Private_Part
(Current_Scope
)
6054 and then Has_Private_With
(P
)
6055 and then Is_Child_Unit
(Current_Scope
)
6056 and then Is_Child_Unit
(P
)
6057 and then Is_Ancestor_Package
(Scope
(Current_Scope
), P
)
6059 Private_With_OK
:= True;
6062 -- Loop through entities in one package making them potentially
6065 Id
:= First_Entity
(P
);
6067 and then (Id
/= First_Private_Entity
(P
)
6068 or else Private_With_OK
) -- Ada 2005 (AI-262)
6070 Prev
:= Current_Entity
(Id
);
6072 while Present
(Prev
) loop
6073 if Is_Immediately_Visible
(Prev
)
6074 and then (not Is_Overloadable
(Prev
)
6075 or else not Is_Overloadable
(Id
)
6076 or else (Type_Conformant
(Id
, Prev
)))
6078 if No
(Current_Instance
) then
6080 -- Potentially use-visible entity remains hidden
6082 goto Next_Usable_Entity
;
6084 -- A use clause within an instance hides outer global
6085 -- entities, which are not used to resolve local entities
6086 -- in the instance. Note that the predefined entities in
6087 -- Standard could not have been hidden in the generic by
6088 -- a use clause, and therefore remain visible. Other
6089 -- compilation units whose entities appear in Standard must
6090 -- be hidden in an instance.
6092 -- To determine whether an entity is external to the instance
6093 -- we compare the scope depth of its scope with that of the
6094 -- current instance. However, a generic actual of a subprogram
6095 -- instance is declared in the wrapper package but will not be
6096 -- hidden by a use-visible entity.
6098 -- If Id is called Standard, the predefined package with the
6099 -- same name is in the homonym chain. It has to be ignored
6100 -- because it has no defined scope (being the only entity in
6101 -- the system with this mandated behavior).
6103 elsif not Is_Hidden
(Id
)
6104 and then Present
(Scope
(Prev
))
6105 and then not Is_Wrapper_Package
(Scope
(Prev
))
6106 and then Scope_Depth
(Scope
(Prev
)) <
6107 Scope_Depth
(Current_Instance
)
6108 and then (Scope
(Prev
) /= Standard_Standard
6109 or else Sloc
(Prev
) > Standard_Location
)
6111 Set_Is_Potentially_Use_Visible
(Id
);
6112 Set_Is_Immediately_Visible
(Prev
, False);
6113 Append_Elmt
(Prev
, Hidden_By_Use_Clause
(N
));
6116 -- A user-defined operator is not use-visible if the
6117 -- predefined operator for the type is immediately visible,
6118 -- which is the case if the type of the operand is in an open
6119 -- scope. This does not apply to user-defined operators that
6120 -- have operands of different types, because the predefined
6121 -- mixed mode operations (multiplication and division) apply to
6122 -- universal types and do not hide anything.
6124 elsif Ekind
(Prev
) = E_Operator
6125 and then Operator_Matches_Spec
(Prev
, Id
)
6126 and then In_Open_Scopes
6127 (Scope
(Base_Type
(Etype
(First_Formal
(Id
)))))
6128 and then (No
(Next_Formal
(First_Formal
(Id
)))
6129 or else Etype
(First_Formal
(Id
))
6130 = Etype
(Next_Formal
(First_Formal
(Id
)))
6131 or else Chars
(Prev
) = Name_Op_Expon
)
6133 goto Next_Usable_Entity
;
6136 Prev
:= Homonym
(Prev
);
6139 -- On exit, we know entity is not hidden, unless it is private
6141 if not Is_Hidden
(Id
)
6142 and then ((not Is_Child_Unit
(Id
))
6143 or else Is_Visible_Child_Unit
(Id
))
6145 Set_Is_Potentially_Use_Visible
(Id
);
6147 if Is_Private_Type
(Id
)
6148 and then Present
(Full_View
(Id
))
6150 Set_Is_Potentially_Use_Visible
(Full_View
(Id
));
6154 <<Next_Usable_Entity
>>
6158 -- Child units are also made use-visible by a use clause, but they
6159 -- may appear after all visible declarations in the parent entity list.
6161 while Present
(Id
) loop
6163 if Is_Child_Unit
(Id
)
6164 and then Is_Visible_Child_Unit
(Id
)
6166 Set_Is_Potentially_Use_Visible
(Id
);
6172 if Chars
(Real_P
) = Name_System
6173 and then Scope
(Real_P
) = Standard_Standard
6174 and then Present_System_Aux
(N
)
6176 Use_One_Package
(System_Aux_Id
, N
);
6179 end Use_One_Package
;
6185 procedure Use_One_Type
(Id
: Node_Id
) is
6191 -- It is the type determined by the subtype mark (8.4(8)) whose
6192 -- operations become potentially use-visible.
6194 T
:= Base_Type
(Entity
(Id
));
6199 or else Is_Potentially_Use_Visible
(T
)
6200 or else In_Use
(Scope
(T
)));
6202 if In_Open_Scopes
(Scope
(T
)) then
6205 -- If the subtype mark designates a subtype in a different package,
6206 -- we have to check that the parent type is visible, otherwise the
6207 -- use type clause is a noop. Not clear how to do that???
6209 elsif not Redundant_Use
(Id
) then
6211 Op_List
:= Collect_Primitive_Operations
(T
);
6212 Elmt
:= First_Elmt
(Op_List
);
6214 while Present
(Elmt
) loop
6216 if (Nkind
(Node
(Elmt
)) = N_Defining_Operator_Symbol
6217 or else Chars
(Node
(Elmt
)) in Any_Operator_Name
)
6218 and then not Is_Hidden
(Node
(Elmt
))
6220 Set_Is_Potentially_Use_Visible
(Node
(Elmt
));
6232 procedure Write_Info
is
6233 Id
: Entity_Id
:= First_Entity
(Current_Scope
);
6236 -- No point in dumping standard entities
6238 if Current_Scope
= Standard_Standard
then
6242 Write_Str
("========================================================");
6244 Write_Str
(" Defined Entities in ");
6245 Write_Name
(Chars
(Current_Scope
));
6247 Write_Str
("========================================================");
6251 Write_Str
("-- none --");
6255 while Present
(Id
) loop
6256 Write_Entity_Info
(Id
, " ");
6261 if Scope
(Current_Scope
) = Standard_Standard
then
6263 -- Print information on the current unit itself
6265 Write_Entity_Info
(Current_Scope
, " ");
6275 procedure Write_Scopes
is
6279 for J
in reverse 1 .. Scope_Stack
.Last
loop
6280 S
:= Scope_Stack
.Table
(J
).Entity
;
6281 Write_Int
(Int
(S
));
6282 Write_Str
(" === ");
6283 Write_Name
(Chars
(S
));