1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Tss
; use Exp_Tss
;
33 with Exp_Util
; use Exp_Util
;
34 with Fname
; use Fname
;
35 with Freeze
; use Freeze
;
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
441 -- private with on E.
443 procedure Find_Expanded_Name
(N
: Node_Id
);
444 -- Selected component is known to be expanded name. Verify legality
445 -- of selector given the scope denoted by prefix.
447 function Find_Renamed_Entity
451 Is_Actual
: Boolean := False) return Entity_Id
;
452 -- Find the renamed entity that corresponds to the given parameter profile
453 -- in a subprogram renaming declaration. The renamed entity may be an
454 -- operator, a subprogram, an entry, or a protected operation. Is_Actual
455 -- indicates that the renaming is the one generated for an actual subpro-
456 -- gram in an instance, for which special visibility checks apply.
458 function Has_Implicit_Operator
(N
: Node_Id
) return Boolean;
459 -- N is an expanded name whose selector is an operator name (eg P."+").
460 -- 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_Is_Pure
(New_P
, Is_Pure
(Old_P
));
650 Set_Is_Preelaborated
(New_P
, Is_Preelaborated
(Old_P
));
652 Set_Etype
(New_P
, Etype
(Old_P
));
653 Set_Has_Completion
(New_P
);
655 if In_Open_Scopes
(Old_P
) then
656 Error_Msg_N
("within its scope, generic denotes its instance", N
);
659 Check_Library_Unit_Renaming
(N
, Old_P
);
661 end Analyze_Generic_Renaming
;
663 -----------------------------
664 -- Analyze_Object_Renaming --
665 -----------------------------
667 procedure Analyze_Object_Renaming
(N
: Node_Id
) is
668 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
670 Nam
: constant Node_Id
:= Name
(N
);
674 function In_Generic_Scope
(E
: Entity_Id
) return Boolean;
675 -- Determine whether entity E is inside a generic cope
677 ----------------------
678 -- In_Generic_Scope --
679 ----------------------
681 function In_Generic_Scope
(E
: Entity_Id
) return Boolean is
686 while Present
(S
) and then S
/= Standard_Standard
loop
687 if Is_Generic_Unit
(S
) then
695 end In_Generic_Scope
;
697 -- Start of processing for Analyze_Object_Renaming
704 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
707 -- The renaming of a component that depends on a discriminant
708 -- requires an actual subtype, because in subsequent use of the object
709 -- Gigi will be unable to locate the actual bounds. This explicit step
710 -- is required when the renaming is generated in removing side effects
711 -- of an already-analyzed expression.
713 if Nkind
(Nam
) = N_Selected_Component
714 and then Analyzed
(Nam
)
717 Dec
:= Build_Actual_Subtype_Of_Component
(Etype
(Nam
), Nam
);
719 if Present
(Dec
) then
720 Insert_Action
(N
, Dec
);
721 T
:= Defining_Identifier
(Dec
);
725 elsif Present
(Subtype_Mark
(N
)) then
726 Find_Type
(Subtype_Mark
(N
));
727 T
:= Entity
(Subtype_Mark
(N
));
728 Analyze_And_Resolve
(Nam
, T
);
730 -- Ada 2005 (AI-230/AI-254): Access renaming
732 else pragma Assert
(Present
(Access_Definition
(N
)));
733 T
:= Access_Definition
735 N
=> Access_Definition
(N
));
737 Analyze_And_Resolve
(Nam
, T
);
739 -- Ada 2005 (AI-231): "In the case where the type is defined by an
740 -- access_definition, the renamed entity shall be of an access-to-
741 -- constant type if and only if the access_definition defines an
742 -- access-to-constant type" ARM 8.5.1(4)
744 if Constant_Present
(Access_Definition
(N
))
745 and then not Is_Access_Constant
(Etype
(Nam
))
747 Error_Msg_N
("(Ada 2005): the renamed object is not "
748 & "access-to-constant ('R'M 8.5.1(6))", N
);
752 -- An object renaming requires an exact match of the type;
753 -- class-wide matching is not allowed.
755 if Is_Class_Wide_Type
(T
)
756 and then Base_Type
(Etype
(Nam
)) /= Base_Type
(T
)
763 -- (Ada 2005: AI-326): Handle wrong use of incomplete type
765 if Nkind
(Nam
) = N_Explicit_Dereference
766 and then Ekind
(Etype
(T2
)) = E_Incomplete_Type
768 Error_Msg_N
("invalid use of incomplete type", Id
);
774 if Ada_Version
>= Ada_05
775 and then Nkind
(Nam
) = N_Attribute_Reference
776 and then Attribute_Name
(Nam
) = Name_Priority
780 elsif Ada_Version
>= Ada_05
781 and then Nkind
(Nam
) in N_Has_Entity
784 Error_Node
: Node_Id
;
787 Subtyp_Decl
: Node_Id
;
790 if Nkind
(Nam
) = N_Attribute_Reference
then
791 Nam_Ent
:= Entity
(Prefix
(Nam
));
793 Nam_Ent
:= Entity
(Nam
);
796 Nam_Decl
:= Parent
(Nam_Ent
);
797 Subtyp_Decl
:= Parent
(Etype
(Nam_Ent
));
799 if Has_Null_Exclusion
(N
)
800 and then not Has_Null_Exclusion
(Nam_Decl
)
802 -- Ada 2005 (AI-423): If the object name denotes a generic
803 -- formal object of a generic unit G, and the object renaming
804 -- declaration occurs within the body of G or within the body
805 -- of a generic unit declared within the declarative region
806 -- of G, then the declaration of the formal object of G shall
807 -- have a null exclusion.
809 if Is_Formal_Object
(Nam_Ent
)
810 and then In_Generic_Scope
(Id
)
812 if Present
(Subtype_Mark
(Nam_Decl
)) then
813 Error_Node
:= Subtype_Mark
(Nam_Decl
);
816 (Ada_Version
>= Ada_05
817 and then Present
(Access_Definition
(Nam_Decl
)));
819 Error_Node
:= Access_Definition
(Nam_Decl
);
822 Error_Msg_N
("null-exclusion required in formal " &
823 "object declaration", Error_Node
);
825 -- Ada 2005 (AI-423): Otherwise, the subtype of the object
826 -- name shall exclude null.
828 elsif Nkind
(Subtyp_Decl
) = N_Subtype_Declaration
829 and then not Has_Null_Exclusion
(Subtyp_Decl
)
831 Error_Msg_N
("subtype must have null-exclusion",
838 Set_Ekind
(Id
, E_Variable
);
839 Init_Size_Align
(Id
);
841 if T
= Any_Type
or else Etype
(Nam
) = Any_Type
then
844 -- Verify that the renamed entity is an object or a function call. It
845 -- may have been rewritten in several ways.
847 elsif Is_Object_Reference
(Nam
) then
848 if Comes_From_Source
(N
)
849 and then Is_Dependent_Component_Of_Mutable_Object
(Nam
)
852 ("illegal renaming of discriminant-dependent component", Nam
);
857 -- A static function call may have been folded into a literal
859 elsif Nkind
(Original_Node
(Nam
)) = N_Function_Call
861 -- When expansion is disabled, attribute reference is not
862 -- rewritten as function call. Otherwise it may be rewritten
863 -- as a conversion, so check original node.
865 or else (Nkind
(Original_Node
(Nam
)) = N_Attribute_Reference
866 and then Is_Function_Attribute_Name
867 (Attribute_Name
(Original_Node
(Nam
))))
869 -- Weird but legal, equivalent to renaming a function call.
870 -- Illegal if the literal is the result of constant-folding an
871 -- attribute reference that is not a function.
873 or else (Is_Entity_Name
(Nam
)
874 and then Ekind
(Entity
(Nam
)) = E_Enumeration_Literal
876 Nkind
(Original_Node
(Nam
)) /= N_Attribute_Reference
)
878 or else (Nkind
(Nam
) = N_Type_Conversion
879 and then Is_Tagged_Type
(Entity
(Subtype_Mark
(Nam
))))
883 elsif Nkind
(Nam
) = N_Type_Conversion
then
885 ("renaming of conversion only allowed for tagged types", Nam
);
889 elsif Ada_Version
>= Ada_05
890 and then Nkind
(Nam
) = N_Attribute_Reference
891 and then Attribute_Name
(Nam
) = Name_Priority
896 Error_Msg_N
("expect object name in renaming", Nam
);
901 if not Is_Variable
(Nam
) then
902 Set_Ekind
(Id
, E_Constant
);
903 Set_Never_Set_In_Source
(Id
, True);
904 Set_Is_True_Constant
(Id
, True);
907 Set_Renamed_Object
(Id
, Nam
);
908 end Analyze_Object_Renaming
;
910 ------------------------------
911 -- Analyze_Package_Renaming --
912 ------------------------------
914 procedure Analyze_Package_Renaming
(N
: Node_Id
) is
915 New_P
: constant Entity_Id
:= Defining_Entity
(N
);
920 if Name
(N
) = Error
then
924 -- Apply Text_IO kludge here, since we may be renaming one of the
925 -- children of Text_IO
927 Text_IO_Kludge
(Name
(N
));
929 if Current_Scope
/= Standard_Standard
then
930 Set_Is_Pure
(New_P
, Is_Pure
(Current_Scope
));
935 if Is_Entity_Name
(Name
(N
)) then
936 Old_P
:= Entity
(Name
(N
));
941 if Etype
(Old_P
) = Any_Type
then
943 ("expect package name in renaming", Name
(N
));
945 elsif Ekind
(Old_P
) /= E_Package
946 and then not (Ekind
(Old_P
) = E_Generic_Package
947 and then In_Open_Scopes
(Old_P
))
949 if Ekind
(Old_P
) = E_Generic_Package
then
951 ("generic package cannot be renamed as a package", Name
(N
));
953 Error_Msg_Sloc
:= Sloc
(Old_P
);
955 ("expect package name in renaming, found& declared#",
959 -- Set basic attributes to minimize cascaded errors
961 Set_Ekind
(New_P
, E_Package
);
962 Set_Etype
(New_P
, Standard_Void_Type
);
965 -- Entities in the old package are accessible through the renaming
966 -- entity. The simplest implementation is to have both packages share
969 Set_Ekind
(New_P
, E_Package
);
970 Set_Etype
(New_P
, Standard_Void_Type
);
972 if Present
(Renamed_Object
(Old_P
)) then
973 Set_Renamed_Object
(New_P
, Renamed_Object
(Old_P
));
975 Set_Renamed_Object
(New_P
, Old_P
);
978 Set_Has_Completion
(New_P
);
980 Set_First_Entity
(New_P
, First_Entity
(Old_P
));
981 Set_Last_Entity
(New_P
, Last_Entity
(Old_P
));
982 Set_First_Private_Entity
(New_P
, First_Private_Entity
(Old_P
));
983 Check_Library_Unit_Renaming
(N
, Old_P
);
984 Generate_Reference
(Old_P
, Name
(N
));
986 -- If this is the renaming declaration of a package instantiation
987 -- within itself, it is the declaration that ends the list of actuals
988 -- for the instantiation. At this point, the subtypes that rename
989 -- the actuals are flagged as generic, to avoid spurious ambiguities
990 -- if the actuals for two distinct formals happen to coincide. If
991 -- the actual is a private type, the subtype has a private completion
992 -- that is flagged in the same fashion.
994 -- Resolution is identical to what is was in the original generic.
995 -- On exit from the generic instance, these are turned into regular
996 -- subtypes again, so they are compatible with types in their class.
998 if not Is_Generic_Instance
(Old_P
) then
1001 Spec
:= Specification
(Unit_Declaration_Node
(Old_P
));
1004 if Nkind
(Spec
) = N_Package_Specification
1005 and then Present
(Generic_Parent
(Spec
))
1006 and then Old_P
= Current_Scope
1007 and then Chars
(New_P
) = Chars
(Generic_Parent
(Spec
))
1010 E
: Entity_Id
:= First_Entity
(Old_P
);
1016 and then Nkind
(Parent
(E
)) = N_Subtype_Declaration
1018 Set_Is_Generic_Actual_Type
(E
);
1020 if Is_Private_Type
(E
)
1021 and then Present
(Full_View
(E
))
1023 Set_Is_Generic_Actual_Type
(Full_View
(E
));
1033 end Analyze_Package_Renaming
;
1035 -------------------------------
1036 -- Analyze_Renamed_Character --
1037 -------------------------------
1039 procedure Analyze_Renamed_Character
1044 C
: constant Node_Id
:= Name
(N
);
1047 if Ekind
(New_S
) = E_Function
then
1048 Resolve
(C
, Etype
(New_S
));
1051 Check_Frozen_Renaming
(N
, New_S
);
1055 Error_Msg_N
("character literal can only be renamed as function", N
);
1057 end Analyze_Renamed_Character
;
1059 ---------------------------------
1060 -- Analyze_Renamed_Dereference --
1061 ---------------------------------
1063 procedure Analyze_Renamed_Dereference
1068 Nam
: constant Node_Id
:= Name
(N
);
1069 P
: constant Node_Id
:= Prefix
(Nam
);
1075 if not Is_Overloaded
(P
) then
1076 if Ekind
(Etype
(Nam
)) /= E_Subprogram_Type
1077 or else not Type_Conformant
(Etype
(Nam
), New_S
) then
1078 Error_Msg_N
("designated type does not match specification", P
);
1087 Get_First_Interp
(Nam
, Ind
, It
);
1089 while Present
(It
.Nam
) loop
1091 if Ekind
(It
.Nam
) = E_Subprogram_Type
1092 and then Type_Conformant
(It
.Nam
, New_S
) then
1094 if Typ
/= Any_Id
then
1095 Error_Msg_N
("ambiguous renaming", P
);
1102 Get_Next_Interp
(Ind
, It
);
1105 if Typ
= Any_Type
then
1106 Error_Msg_N
("designated type does not match specification", P
);
1111 Check_Frozen_Renaming
(N
, New_S
);
1115 end Analyze_Renamed_Dereference
;
1117 ---------------------------
1118 -- Analyze_Renamed_Entry --
1119 ---------------------------
1121 procedure Analyze_Renamed_Entry
1126 Nam
: constant Node_Id
:= Name
(N
);
1127 Sel
: constant Node_Id
:= Selector_Name
(Nam
);
1131 if Entity
(Sel
) = Any_Id
then
1133 -- Selector is undefined on prefix. Error emitted already
1135 Set_Has_Completion
(New_S
);
1139 -- Otherwise, find renamed entity, and build body of New_S as a call
1142 Old_S
:= Find_Renamed_Entity
(N
, Selector_Name
(Nam
), New_S
);
1144 if Old_S
= Any_Id
then
1145 Error_Msg_N
(" no subprogram or entry matches specification", N
);
1148 Check_Subtype_Conformant
(New_S
, Old_S
, N
);
1149 Generate_Reference
(New_S
, Defining_Entity
(N
), 'b');
1150 Style
.Check_Identifier
(Defining_Entity
(N
), New_S
);
1153 -- Only mode conformance required for a renaming_as_declaration
1155 Check_Mode_Conformant
(New_S
, Old_S
, N
);
1158 Inherit_Renamed_Profile
(New_S
, Old_S
);
1161 Set_Convention
(New_S
, Convention
(Old_S
));
1162 Set_Has_Completion
(New_S
, Inside_A_Generic
);
1165 Check_Frozen_Renaming
(N
, New_S
);
1167 end Analyze_Renamed_Entry
;
1169 -----------------------------------
1170 -- Analyze_Renamed_Family_Member --
1171 -----------------------------------
1173 procedure Analyze_Renamed_Family_Member
1178 Nam
: constant Node_Id
:= Name
(N
);
1179 P
: constant Node_Id
:= Prefix
(Nam
);
1183 if (Is_Entity_Name
(P
) and then Ekind
(Entity
(P
)) = E_Entry_Family
)
1184 or else (Nkind
(P
) = N_Selected_Component
1186 Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
)
1188 if Is_Entity_Name
(P
) then
1189 Old_S
:= Entity
(P
);
1191 Old_S
:= Entity
(Selector_Name
(P
));
1194 if not Entity_Matches_Spec
(Old_S
, New_S
) then
1195 Error_Msg_N
("entry family does not match specification", N
);
1198 Check_Subtype_Conformant
(New_S
, Old_S
, N
);
1199 Generate_Reference
(New_S
, Defining_Entity
(N
), 'b');
1200 Style
.Check_Identifier
(Defining_Entity
(N
), New_S
);
1203 Error_Msg_N
("no entry family matches specification", N
);
1206 Set_Has_Completion
(New_S
, Inside_A_Generic
);
1209 Check_Frozen_Renaming
(N
, New_S
);
1211 end Analyze_Renamed_Family_Member
;
1213 ---------------------------------
1214 -- Analyze_Subprogram_Renaming --
1215 ---------------------------------
1217 procedure Analyze_Subprogram_Renaming
(N
: Node_Id
) is
1218 Formal_Spec
: constant Node_Id
:= Corresponding_Formal_Spec
(N
);
1219 Is_Actual
: constant Boolean := Present
(Formal_Spec
);
1220 Inst_Node
: Node_Id
:= Empty
;
1221 Nam
: constant Node_Id
:= Name
(N
);
1223 Old_S
: Entity_Id
:= Empty
;
1224 Rename_Spec
: Entity_Id
;
1225 Save_AV
: constant Ada_Version_Type
:= Ada_Version
;
1226 Save_AV_Exp
: constant Ada_Version_Type
:= Ada_Version_Explicit
;
1227 Spec
: constant Node_Id
:= Specification
(N
);
1229 procedure Check_Null_Exclusion
1232 -- Ada 2005 (AI-423): Given renaming Ren of subprogram Sub, check the
1233 -- following AI rules:
1234 -- o If Ren is a renaming of a formal subprogram and one of its
1235 -- parameters has a null exclusion, then the corresponding formal
1236 -- in Sub must also have one. Otherwise the subtype of the Sub's
1237 -- formal parameter must exclude null.
1238 -- o If Ren is a renaming of a formal function and its retrun
1239 -- profile has a null exclusion, then Sub's return profile must
1240 -- have one. Otherwise the subtype of Sub's return profile must
1243 function Original_Subprogram
(Subp
: Entity_Id
) return Entity_Id
;
1244 -- Find renamed entity when the declaration is a renaming_as_body
1245 -- and the renamed entity may itself be a renaming_as_body. Used to
1246 -- enforce rule that a renaming_as_body is illegal if the declaration
1247 -- occurs before the subprogram it completes is frozen, and renaming
1248 -- indirectly renames the subprogram itself.(Defect Report 8652/0027).
1250 --------------------------
1251 -- Check_Null_Exclusion --
1252 --------------------------
1254 procedure Check_Null_Exclusion
1258 Ren_Formal
: Entity_Id
:= First_Formal
(Ren
);
1259 Sub_Formal
: Entity_Id
:= First_Formal
(Sub
);
1264 while Present
(Ren_Formal
)
1265 and then Present
(Sub_Formal
)
1267 if Has_Null_Exclusion
(Parent
(Ren_Formal
))
1269 not (Has_Null_Exclusion
(Parent
(Sub_Formal
))
1270 or else Can_Never_Be_Null
(Etype
(Sub_Formal
)))
1272 Error_Msg_N
("null-exclusion required in parameter profile",
1273 Parent
(Sub_Formal
));
1276 Next_Formal
(Ren_Formal
);
1277 Next_Formal
(Sub_Formal
);
1280 -- Return profile check
1282 if Nkind
(Parent
(Ren
)) = N_Function_Specification
1283 and then Nkind
(Parent
(Sub
)) = N_Function_Specification
1284 and then Has_Null_Exclusion
(Parent
(Ren
))
1286 not (Has_Null_Exclusion
(Parent
(Sub
))
1287 or else Can_Never_Be_Null
(Etype
(Sub
)))
1289 Error_Msg_N
("null-exclusion required in return profile",
1290 Result_Definition
(Parent
(Sub
)));
1292 end Check_Null_Exclusion
;
1294 -------------------------
1295 -- Original_Subprogram --
1296 -------------------------
1298 function Original_Subprogram
(Subp
: Entity_Id
) return Entity_Id
is
1299 Orig_Decl
: Node_Id
;
1300 Orig_Subp
: Entity_Id
;
1303 -- First case: renamed entity is itself a renaming
1305 if Present
(Alias
(Subp
)) then
1306 return Alias
(Subp
);
1309 Nkind
(Unit_Declaration_Node
(Subp
)) = N_Subprogram_Declaration
1311 (Corresponding_Body
(Unit_Declaration_Node
(Subp
)))
1313 -- Check if renamed entity is a renaming_as_body
1316 Unit_Declaration_Node
1317 (Corresponding_Body
(Unit_Declaration_Node
(Subp
)));
1319 if Nkind
(Orig_Decl
) = N_Subprogram_Renaming_Declaration
then
1320 Orig_Subp
:= Entity
(Name
(Orig_Decl
));
1322 if Orig_Subp
= Rename_Spec
then
1324 -- Circularity detected
1329 return (Original_Subprogram
(Orig_Subp
));
1337 end Original_Subprogram
;
1339 -- Start of processing for Analyze_Subprogram_Renaming
1342 -- We must test for the attribute renaming case before the Analyze
1343 -- call because otherwise Sem_Attr will complain that the attribute
1344 -- is missing an argument when it is analyzed.
1346 if Nkind
(Nam
) = N_Attribute_Reference
then
1348 -- In the case of an abstract formal subprogram association,
1349 -- rewrite an actual given by a stream attribute as the name
1350 -- of the corresponding stream primitive of the type.
1352 -- In a generic context the stream operations are not generated,
1353 -- and this must be treated as a normal attribute reference, to
1354 -- be expanded in subsequent instantiations.
1356 if Is_Actual
and then Is_Abstract
(Formal_Spec
)
1357 and then Expander_Active
1360 Stream_Prim
: Entity_Id
;
1361 Prefix_Type
: constant Entity_Id
:= Entity
(Prefix
(Nam
));
1364 -- The class-wide forms of the stream attributes are not
1365 -- primitive dispatching operations (even though they
1366 -- internally dispatch to a stream attribute).
1368 if Is_Class_Wide_Type
(Prefix_Type
) then
1370 ("attribute must be a primitive dispatching operation",
1375 -- Retrieve the primitive subprogram associated with the
1376 -- attribute. This can only be a stream attribute, since
1377 -- those are the only ones that are dispatching (and the
1378 -- actual for an abstract formal subprogram must be a
1379 -- dispatching operation).
1381 case Attribute_Name
(Nam
) is
1384 Find_Prim_Op
(Prefix_Type
, TSS_Stream_Input
);
1387 Find_Prim_Op
(Prefix_Type
, TSS_Stream_Output
);
1390 Find_Prim_Op
(Prefix_Type
, TSS_Stream_Read
);
1393 Find_Prim_Op
(Prefix_Type
, TSS_Stream_Write
);
1396 ("attribute must be a primitive dispatching operation",
1401 -- Rewrite the attribute into the name of its corresponding
1402 -- primitive dispatching subprogram. We can then proceed with
1403 -- the usual processing for subprogram renamings.
1406 Prim_Name
: constant Node_Id
:=
1407 Make_Identifier
(Sloc
(Nam
),
1408 Chars
=> Chars
(Stream_Prim
));
1410 Set_Entity
(Prim_Name
, Stream_Prim
);
1411 Rewrite
(Nam
, Prim_Name
);
1416 -- Normal processing for a renaming of an attribute
1419 Attribute_Renaming
(N
);
1424 -- Check whether this declaration corresponds to the instantiation
1425 -- of a formal subprogram.
1427 -- If this is an instantiation, the corresponding actual is frozen
1428 -- and error messages can be made more precise. If this is a default
1429 -- subprogram, the entity is already established in the generic, and
1430 -- is not retrieved by visibility. If it is a default with a box, the
1431 -- candidate interpretations, if any, have been collected when building
1432 -- the renaming declaration. If overloaded, the proper interpretation
1433 -- is determined in Find_Renamed_Entity. If the entity is an operator,
1434 -- Find_Renamed_Entity applies additional visibility checks.
1437 Inst_Node
:= Unit_Declaration_Node
(Formal_Spec
);
1439 if Is_Entity_Name
(Nam
)
1440 and then Present
(Entity
(Nam
))
1441 and then not Comes_From_Source
(Nam
)
1442 and then not Is_Overloaded
(Nam
)
1444 Old_S
:= Entity
(Nam
);
1445 New_S
:= Analyze_Subprogram_Specification
(Spec
);
1449 if Ekind
(Entity
(Nam
)) = E_Operator
then
1453 if Box_Present
(Inst_Node
) then
1454 Old_S
:= Find_Renamed_Entity
(N
, Name
(N
), New_S
, Is_Actual
);
1456 -- If there is an immediately visible homonym of the operator
1457 -- and the declaration has a default, this is worth a warning
1458 -- because the user probably did not intend to get the pre-
1459 -- defined operator, visible in the generic declaration.
1460 -- To find if there is an intended candidate, analyze the
1461 -- renaming again in the current context.
1463 elsif Scope
(Old_S
) = Standard_Standard
1464 and then Present
(Default_Name
(Inst_Node
))
1467 Decl
: constant Node_Id
:= New_Copy_Tree
(N
);
1471 Set_Entity
(Name
(Decl
), Empty
);
1472 Analyze
(Name
(Decl
));
1474 Find_Renamed_Entity
(Decl
, Name
(Decl
), New_S
, True);
1477 and then In_Open_Scopes
(Scope
(Hidden
))
1478 and then Is_Immediately_Visible
(Hidden
)
1479 and then Comes_From_Source
(Hidden
)
1480 and then Hidden
/= Old_S
1482 Error_Msg_Sloc
:= Sloc
(Hidden
);
1483 Error_Msg_N
("?default subprogram is resolved " &
1484 "in the generic declaration " &
1485 "('R'M 12.6(17))", N
);
1486 Error_Msg_NE
("\?and will not use & #", N
, Hidden
);
1494 New_S
:= Analyze_Subprogram_Specification
(Spec
);
1498 -- Renamed entity must be analyzed first, to avoid being hidden by
1499 -- new name (which might be the same in a generic instance).
1503 -- The renaming defines a new overloaded entity, which is analyzed
1504 -- like a subprogram declaration.
1506 New_S
:= Analyze_Subprogram_Specification
(Spec
);
1509 if Current_Scope
/= Standard_Standard
then
1510 Set_Is_Pure
(New_S
, Is_Pure
(Current_Scope
));
1513 Rename_Spec
:= Find_Corresponding_Spec
(N
);
1515 if Present
(Rename_Spec
) then
1517 -- Renaming_As_Body. Renaming declaration is the completion of
1518 -- the declaration of Rename_Spec. We will build an actual body
1519 -- for it at the freezing point.
1521 Set_Corresponding_Spec
(N
, Rename_Spec
);
1522 if Nkind
(Unit_Declaration_Node
(Rename_Spec
)) =
1523 N_Abstract_Subprogram_Declaration
1525 -- Input and Output stream functions are abstract if the object
1526 -- type is abstract. However, these functions may receive explicit
1527 -- declarations in representation clauses, making the attribute
1528 -- subprograms usable as defaults in subsequent type extensions.
1529 -- In this case we rewrite the declaration to make the subprogram
1530 -- non-abstract. We remove the previous declaration, and insert
1531 -- the new one at the point of the renaming, to prevent premature
1532 -- access to unfrozen types. The new declaration reuses the
1533 -- specification of the previous one, and must not be analyzed.
1535 pragma Assert
(Is_TSS
(Rename_Spec
, TSS_Stream_Output
)
1536 or else Is_TSS
(Rename_Spec
, TSS_Stream_Input
));
1539 Old_Decl
: constant Node_Id
:=
1540 Unit_Declaration_Node
(Rename_Spec
);
1541 New_Decl
: constant Node_Id
:=
1542 Make_Subprogram_Declaration
(Sloc
(N
),
1544 Relocate_Node
(Specification
(Old_Decl
)));
1547 Insert_After
(N
, New_Decl
);
1548 Set_Is_Abstract
(Rename_Spec
, False);
1549 Set_Analyzed
(New_Decl
);
1553 Set_Corresponding_Body
(Unit_Declaration_Node
(Rename_Spec
), New_S
);
1555 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1556 Error_Msg_N
("(Ada 83) renaming cannot serve as a body", N
);
1559 Set_Convention
(New_S
, Convention
(Rename_Spec
));
1560 Check_Fully_Conformant
(New_S
, Rename_Spec
);
1561 Set_Public_Status
(New_S
);
1563 -- Indicate that the entity in the declaration functions like the
1564 -- corresponding body, and is not a new entity. The body will be
1565 -- constructed later at the freeze point, so indicate that the
1566 -- completion has not been seen yet.
1568 Set_Ekind
(New_S
, E_Subprogram_Body
);
1569 New_S
:= Rename_Spec
;
1570 Set_Has_Completion
(Rename_Spec
, False);
1572 -- Ada 2005: check overriding indicator
1574 if Must_Override
(Specification
(N
))
1575 and then not Is_Overriding_Operation
(Rename_Spec
)
1577 Error_Msg_NE
("subprogram& is not overriding", N
, Rename_Spec
);
1579 elsif Must_Not_Override
(Specification
(N
))
1580 and then Is_Overriding_Operation
(Rename_Spec
)
1583 ("subprogram& overrides inherited operation", N
, Rename_Spec
);
1587 Generate_Definition
(New_S
);
1588 New_Overloaded_Entity
(New_S
);
1590 if Is_Entity_Name
(Nam
)
1591 and then Is_Intrinsic_Subprogram
(Entity
(Nam
))
1595 Check_Delayed_Subprogram
(New_S
);
1599 -- There is no need for elaboration checks on the new entity, which may
1600 -- be called before the next freezing point where the body will appear.
1601 -- Elaboration checks refer to the real entity, not the one created by
1602 -- the renaming declaration.
1604 Set_Kill_Elaboration_Checks
(New_S
, True);
1606 if Etype
(Nam
) = Any_Type
then
1607 Set_Has_Completion
(New_S
);
1610 elsif Nkind
(Nam
) = N_Selected_Component
then
1612 -- Renamed entity is an entry or protected subprogram. For those
1613 -- cases an explicit body is built (at the point of freezing of this
1614 -- entity) that contains a call to the renamed entity.
1616 Analyze_Renamed_Entry
(N
, New_S
, Present
(Rename_Spec
));
1619 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
1621 -- Renamed entity is designated by access_to_subprogram expression.
1622 -- Must build body to encapsulate call, as in the entry case.
1624 Analyze_Renamed_Dereference
(N
, New_S
, Present
(Rename_Spec
));
1627 elsif Nkind
(Nam
) = N_Indexed_Component
then
1628 Analyze_Renamed_Family_Member
(N
, New_S
, Present
(Rename_Spec
));
1631 elsif Nkind
(Nam
) = N_Character_Literal
then
1632 Analyze_Renamed_Character
(N
, New_S
, Present
(Rename_Spec
));
1635 elsif (not Is_Entity_Name
(Nam
)
1636 and then Nkind
(Nam
) /= N_Operator_Symbol
)
1637 or else not Is_Overloadable
(Entity
(Nam
))
1639 Error_Msg_N
("expect valid subprogram name in renaming", N
);
1644 -- Most common case: subprogram renames subprogram. No body is generated
1645 -- in this case, so we must indicate the declaration is complete as is.
1647 if No
(Rename_Spec
) then
1648 Set_Has_Completion
(New_S
);
1649 Set_Is_Pure
(New_S
, Is_Pure
(Entity
(Nam
)));
1650 Set_Is_Preelaborated
(New_S
, Is_Preelaborated
(Entity
(Nam
)));
1652 -- Ada 2005 (AI-423): Check the consistency of null exclusions
1653 -- between a subprogram and its renaming.
1655 if Ada_Version
>= Ada_05
then
1656 Check_Null_Exclusion
1658 Sub
=> Entity
(Nam
));
1662 -- Find the renamed entity that matches the given specification. Disable
1663 -- Ada_83 because there is no requirement of full conformance between
1664 -- renamed entity and new entity, even though the same circuit is used.
1666 -- This is a bit of a kludge, which introduces a really irregular use of
1667 -- Ada_Version[_Explicit]. Would be nice to find cleaner way to do this
1670 Ada_Version
:= Ada_Version_Type
'Max (Ada_Version
, Ada_95
);
1671 Ada_Version_Explicit
:= Ada_Version
;
1674 Old_S
:= Find_Renamed_Entity
(N
, Name
(N
), New_S
, Is_Actual
);
1677 if Old_S
/= Any_Id
then
1679 and then From_Default
(N
)
1681 -- This is an implicit reference to the default actual
1683 Generate_Reference
(Old_S
, Nam
, Typ
=> 'i', Force
=> True);
1685 Generate_Reference
(Old_S
, Nam
);
1688 -- For a renaming-as-body, require subtype conformance, but if the
1689 -- declaration being completed has not been frozen, then inherit the
1690 -- convention of the renamed subprogram prior to checking conformance
1691 -- (unless the renaming has an explicit convention established; the
1692 -- rule stated in the RM doesn't seem to address this ???).
1694 if Present
(Rename_Spec
) then
1695 Generate_Reference
(Rename_Spec
, Defining_Entity
(Spec
), 'b');
1696 Style
.Check_Identifier
(Defining_Entity
(Spec
), Rename_Spec
);
1698 if not Is_Frozen
(Rename_Spec
) then
1699 if not Has_Convention_Pragma
(Rename_Spec
) then
1700 Set_Convention
(New_S
, Convention
(Old_S
));
1703 if Ekind
(Old_S
) /= E_Operator
then
1704 Check_Mode_Conformant
(New_S
, Old_S
, Spec
);
1707 if Original_Subprogram
(Old_S
) = Rename_Spec
then
1708 Error_Msg_N
("unfrozen subprogram cannot rename itself ", N
);
1711 Check_Subtype_Conformant
(New_S
, Old_S
, Spec
);
1714 Check_Frozen_Renaming
(N
, Rename_Spec
);
1716 -- Check explicitly that renamed entity is not intrinsic, because
1717 -- in in a generic the renamed body is not built. In this case,
1718 -- the renaming_as_body is a completion.
1720 if Inside_A_Generic
then
1721 if Is_Frozen
(Rename_Spec
)
1722 and then Is_Intrinsic_Subprogram
(Old_S
)
1725 ("subprogram in renaming_as_body cannot be intrinsic",
1729 Set_Has_Completion
(Rename_Spec
);
1732 elsif Ekind
(Old_S
) /= E_Operator
then
1733 Check_Mode_Conformant
(New_S
, Old_S
);
1736 and then Error_Posted
(New_S
)
1738 Error_Msg_NE
("invalid actual subprogram: & #!", N
, Old_S
);
1742 if No
(Rename_Spec
) then
1744 -- The parameter profile of the new entity is that of the renamed
1745 -- entity: the subtypes given in the specification are irrelevant.
1747 Inherit_Renamed_Profile
(New_S
, Old_S
);
1749 -- A call to the subprogram is transformed into a call to the
1750 -- renamed entity. This is transitive if the renamed entity is
1751 -- itself a renaming.
1753 if Present
(Alias
(Old_S
)) then
1754 Set_Alias
(New_S
, Alias
(Old_S
));
1756 Set_Alias
(New_S
, Old_S
);
1759 -- Note that we do not set Is_Intrinsic_Subprogram if we have a
1760 -- renaming as body, since the entity in this case is not an
1761 -- intrinsic (it calls an intrinsic, but we have a real body for
1762 -- this call, and it is in this body that the required intrinsic
1763 -- processing will take place).
1765 -- Also, if this is a renaming of inequality, the renamed operator
1766 -- is intrinsic, but what matters is the corresponding equality
1767 -- operator, which may be user-defined.
1769 Set_Is_Intrinsic_Subprogram
1771 Is_Intrinsic_Subprogram
(Old_S
)
1773 (Chars
(Old_S
) /= Name_Op_Ne
1774 or else Ekind
(Old_S
) = E_Operator
1776 Is_Intrinsic_Subprogram
1777 (Corresponding_Equality
(Old_S
))));
1779 if Ekind
(Alias
(New_S
)) = E_Operator
then
1780 Set_Has_Delayed_Freeze
(New_S
, False);
1783 -- If the renaming corresponds to an association for an abstract
1784 -- formal subprogram, then various attributes must be set to
1785 -- indicate that the renaming is an abstract dispatching operation
1786 -- with a controlling type.
1788 if Is_Actual
and then Is_Abstract
(Formal_Spec
) then
1789 -- Mark the renaming as abstract here, so Find_Dispatching_Type
1790 -- see it as corresponding to a generic association for a
1791 -- formal abstract subprogram
1793 Set_Is_Abstract
(New_S
);
1796 New_S_Ctrl_Type
: constant Entity_Id
:=
1797 Find_Dispatching_Type
(New_S
);
1798 Old_S_Ctrl_Type
: constant Entity_Id
:=
1799 Find_Dispatching_Type
(Old_S
);
1802 if Old_S_Ctrl_Type
/= New_S_Ctrl_Type
then
1804 ("actual must be dispatching subprogram for type&",
1805 Nam
, New_S_Ctrl_Type
);
1808 Set_Is_Dispatching_Operation
(New_S
);
1809 Check_Controlling_Formals
(New_S_Ctrl_Type
, New_S
);
1811 -- In the case where the actual in the formal subprogram
1812 -- is itself a formal abstract subprogram association,
1813 -- there's no dispatch table component or position to
1816 if Present
(DTC_Entity
(Old_S
)) then
1817 Set_DTC_Entity
(New_S
, DTC_Entity
(Old_S
));
1818 Set_DT_Position
(New_S
, DT_Position
(Old_S
));
1826 and then (Old_S
= New_S
1827 or else (Nkind
(Nam
) /= N_Expanded_Name
1828 and then Chars
(Old_S
) = Chars
(New_S
)))
1830 Error_Msg_N
("subprogram cannot rename itself", N
);
1833 Set_Convention
(New_S
, Convention
(Old_S
));
1834 Set_Is_Abstract
(New_S
, Is_Abstract
(Old_S
));
1835 Check_Library_Unit_Renaming
(N
, Old_S
);
1837 -- Pathological case: procedure renames entry in the scope of its
1838 -- task. Entry is given by simple name, but body must be built for
1839 -- procedure. Of course if called it will deadlock.
1841 if Ekind
(Old_S
) = E_Entry
then
1842 Set_Has_Completion
(New_S
, False);
1843 Set_Alias
(New_S
, Empty
);
1847 Freeze_Before
(N
, Old_S
);
1848 Set_Has_Delayed_Freeze
(New_S
, False);
1849 Freeze_Before
(N
, New_S
);
1851 -- An abstract subprogram is only allowed as an actual in the case
1852 -- where the formal subprogram is also abstract.
1854 if (Ekind
(Old_S
) = E_Procedure
or else Ekind
(Old_S
) = E_Function
)
1855 and then Is_Abstract
(Old_S
)
1856 and then not Is_Abstract
(Formal_Spec
)
1859 ("abstract subprogram not allowed as generic actual", Nam
);
1864 -- A common error is to assume that implicit operators for types are
1865 -- defined in Standard, or in the scope of a subtype. In those cases
1866 -- where the renamed entity is given with an expanded name, it is
1867 -- worth mentioning that operators for the type are not declared in
1868 -- the scope given by the prefix.
1870 if Nkind
(Nam
) = N_Expanded_Name
1871 and then Nkind
(Selector_Name
(Nam
)) = N_Operator_Symbol
1872 and then Scope
(Entity
(Nam
)) = Standard_Standard
1875 T
: constant Entity_Id
:=
1876 Base_Type
(Etype
(First_Formal
(New_S
)));
1879 Error_Msg_Node_2
:= Prefix
(Nam
);
1881 ("operator for type& is not declared in&", Prefix
(Nam
), T
);
1886 ("no visible subprogram matches the specification for&",
1890 if Present
(Candidate_Renaming
) then
1896 F1
:= First_Formal
(Candidate_Renaming
);
1897 F2
:= First_Formal
(New_S
);
1899 while Present
(F1
) and then Present
(F2
) loop
1904 if Present
(F1
) and then Present
(Default_Value
(F1
)) then
1905 if Present
(Next_Formal
(F1
)) then
1907 ("\missing specification for &" &
1908 " and other formals with defaults", Spec
, F1
);
1911 ("\missing specification for &", Spec
, F1
);
1918 -- Ada 2005 AI 404: if the new subprogram is dispatching, verify that
1919 -- controlling access parameters are known non-null for the renamed
1920 -- subprogram. Test also applies to a subprogram instantiation that
1921 -- is dispatching. Test is skipped if some previous error was detected
1922 -- that set Old_S to Any_Id.
1924 if Ada_Version
>= Ada_05
1925 and then Old_S
/= Any_Id
1926 and then not Is_Dispatching_Operation
(Old_S
)
1927 and then Is_Dispatching_Operation
(New_S
)
1934 Old_F
:= First_Formal
(Old_S
);
1935 New_F
:= First_Formal
(New_S
);
1936 while Present
(Old_F
) loop
1937 if Ekind
(Etype
(Old_F
)) = E_Anonymous_Access_Type
1938 and then Is_Controlling_Formal
(New_F
)
1939 and then not Can_Never_Be_Null
(Old_F
)
1941 Error_Msg_N
("access parameter is controlling,", New_F
);
1942 Error_Msg_NE
("\corresponding parameter of& " &
1943 " must be explicitly null excluding", New_F
, Old_S
);
1946 Next_Formal
(Old_F
);
1947 Next_Formal
(New_F
);
1952 -- A useful warning, suggested by Ada Bug Finder (Ada-Europe 2005)
1954 if Comes_From_Source
(N
)
1955 and then Present
(Old_S
)
1956 and then Nkind
(Old_S
) = N_Defining_Operator_Symbol
1957 and then Nkind
(New_S
) = N_Defining_Operator_Symbol
1958 and then Chars
(Old_S
) /= Chars
(New_S
)
1961 ("?& is being renamed as a different operator",
1965 Ada_Version
:= Save_AV
;
1966 Ada_Version_Explicit
:= Save_AV_Exp
;
1967 end Analyze_Subprogram_Renaming
;
1969 -------------------------
1970 -- Analyze_Use_Package --
1971 -------------------------
1973 -- Resolve the package names in the use clause, and make all the visible
1974 -- entities defined in the package potentially use-visible. If the package
1975 -- is already in use from a previous use clause, its visible entities are
1976 -- already use-visible. In that case, mark the occurrence as a redundant
1977 -- use. If the package is an open scope, i.e. if the use clause occurs
1978 -- within the package itself, ignore it.
1980 procedure Analyze_Use_Package
(N
: Node_Id
) is
1981 Pack_Name
: Node_Id
;
1984 -- Start of processing for Analyze_Use_Package
1987 Set_Hidden_By_Use_Clause
(N
, No_Elist
);
1989 -- Use clause is not allowed in a spec of a predefined package
1990 -- declaration except that packages whose file name starts a-n are OK
1991 -- (these are children of Ada.Numerics, and such packages are never
1992 -- loaded by Rtsfind).
1994 if Is_Predefined_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
1995 and then Name_Buffer
(1 .. 3) /= "a-n"
1997 Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Declaration
1999 Error_Msg_N
("use clause not allowed in predefined spec", N
);
2002 -- Chain clause to list of use clauses in current scope
2004 if Nkind
(Parent
(N
)) /= N_Compilation_Unit
then
2005 Chain_Use_Clause
(N
);
2008 -- Loop through package names to identify referenced packages
2010 Pack_Name
:= First
(Names
(N
));
2012 while Present
(Pack_Name
) loop
2013 Analyze
(Pack_Name
);
2015 if Nkind
(Parent
(N
)) = N_Compilation_Unit
2016 and then Nkind
(Pack_Name
) = N_Expanded_Name
2019 Pref
: Node_Id
:= Prefix
(Pack_Name
);
2022 while Nkind
(Pref
) = N_Expanded_Name
loop
2023 Pref
:= Prefix
(Pref
);
2026 if Entity
(Pref
) = Standard_Standard
then
2028 ("predefined package Standard cannot appear"
2029 & " in a context clause", Pref
);
2037 -- Loop through package names to mark all entities as potentially
2040 Pack_Name
:= First
(Names
(N
));
2042 while Present
(Pack_Name
) loop
2044 if Is_Entity_Name
(Pack_Name
) then
2045 Pack
:= Entity
(Pack_Name
);
2047 if Ekind
(Pack
) /= E_Package
2048 and then Etype
(Pack
) /= Any_Type
2050 if Ekind
(Pack
) = E_Generic_Package
then
2052 ("a generic package is not allowed in a use clause",
2055 Error_Msg_N
("& is not a usable package", Pack_Name
);
2059 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
2060 Check_In_Previous_With_Clause
(N
, Pack_Name
);
2063 if Applicable_Use
(Pack_Name
) then
2064 Use_One_Package
(Pack
, N
);
2072 end Analyze_Use_Package
;
2074 ----------------------
2075 -- Analyze_Use_Type --
2076 ----------------------
2078 procedure Analyze_Use_Type
(N
: Node_Id
) is
2082 Set_Hidden_By_Use_Clause
(N
, No_Elist
);
2084 -- Chain clause to list of use clauses in current scope
2086 if Nkind
(Parent
(N
)) /= N_Compilation_Unit
then
2087 Chain_Use_Clause
(N
);
2090 Id
:= First
(Subtype_Marks
(N
));
2092 while Present
(Id
) loop
2095 if Entity
(Id
) /= Any_Type
then
2098 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
2099 if Nkind
(Id
) = N_Identifier
then
2100 Error_Msg_N
("type is not directly visible", Id
);
2102 elsif Is_Child_Unit
(Scope
(Entity
(Id
)))
2103 and then Scope
(Entity
(Id
)) /= System_Aux_Id
2105 Check_In_Previous_With_Clause
(N
, Prefix
(Id
));
2112 end Analyze_Use_Type
;
2114 --------------------
2115 -- Applicable_Use --
2116 --------------------
2118 function Applicable_Use
(Pack_Name
: Node_Id
) return Boolean is
2119 Pack
: constant Entity_Id
:= Entity
(Pack_Name
);
2122 if In_Open_Scopes
(Pack
) then
2125 elsif In_Use
(Pack
) then
2126 Note_Redundant_Use
(Pack_Name
);
2129 elsif Present
(Renamed_Object
(Pack
))
2130 and then In_Use
(Renamed_Object
(Pack
))
2132 Note_Redundant_Use
(Pack_Name
);
2140 ------------------------
2141 -- Attribute_Renaming --
2142 ------------------------
2144 procedure Attribute_Renaming
(N
: Node_Id
) is
2145 Loc
: constant Source_Ptr
:= Sloc
(N
);
2146 Nam
: constant Node_Id
:= Name
(N
);
2147 Spec
: constant Node_Id
:= Specification
(N
);
2148 New_S
: constant Entity_Id
:= Defining_Unit_Name
(Spec
);
2149 Aname
: constant Name_Id
:= Attribute_Name
(Nam
);
2151 Form_Num
: Nat
:= 0;
2152 Expr_List
: List_Id
:= No_List
;
2154 Attr_Node
: Node_Id
;
2155 Body_Node
: Node_Id
;
2156 Param_Spec
: Node_Id
;
2159 Generate_Definition
(New_S
);
2161 -- This procedure is called in the context of subprogram renaming,
2162 -- and thus the attribute must be one that is a subprogram. All of
2163 -- those have at least one formal parameter, with the singular
2164 -- exception of AST_Entry (which is a real oddity, it is odd that
2165 -- this can be renamed at all!)
2167 if not Is_Non_Empty_List
(Parameter_Specifications
(Spec
)) then
2168 if Aname
/= Name_AST_Entry
then
2170 ("subprogram renaming an attribute must have formals", N
);
2175 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
2177 while Present
(Param_Spec
) loop
2178 Form_Num
:= Form_Num
+ 1;
2180 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
2181 Find_Type
(Parameter_Type
(Param_Spec
));
2183 -- The profile of the new entity denotes the base type (s) of
2184 -- the types given in the specification. For access parameters
2185 -- there are no subtypes involved.
2187 Rewrite
(Parameter_Type
(Param_Spec
),
2189 (Base_Type
(Entity
(Parameter_Type
(Param_Spec
))), Loc
));
2192 if No
(Expr_List
) then
2193 Expr_List
:= New_List
;
2196 Append_To
(Expr_List
,
2197 Make_Identifier
(Loc
,
2198 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
2200 -- The expressions in the attribute reference are not freeze
2201 -- points. Neither is the attribute as a whole, see below.
2203 Set_Must_Not_Freeze
(Last
(Expr_List
));
2208 -- Immediate error if too many formals. Other mismatches in numbers
2209 -- of number of types of parameters are detected when we analyze the
2210 -- body of the subprogram that we construct.
2212 if Form_Num
> 2 then
2213 Error_Msg_N
("too many formals for attribute", N
);
2215 -- Error if the attribute reference has expressions that look
2216 -- like formal parameters.
2218 elsif Present
(Expressions
(Nam
)) then
2219 Error_Msg_N
("illegal expressions in attribute reference", Nam
);
2222 Aname
= Name_Compose
or else
2223 Aname
= Name_Exponent
or else
2224 Aname
= Name_Leading_Part
or else
2225 Aname
= Name_Pos
or else
2226 Aname
= Name_Round
or else
2227 Aname
= Name_Scaling
or else
2230 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
2231 and then Present
(Corresponding_Formal_Spec
(N
))
2234 ("generic actual cannot be attribute involving universal type",
2238 ("attribute involving a universal type cannot be renamed",
2243 -- AST_Entry is an odd case. It doesn't really make much sense to
2244 -- allow it to be renamed, but that's the DEC rule, so we have to
2245 -- do it right. The point is that the AST_Entry call should be made
2246 -- now, and what the function will return is the returned value.
2248 -- Note that there is no Expr_List in this case anyway
2250 if Aname
= Name_AST_Entry
then
2257 Ent
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
2260 Make_Object_Declaration
(Loc
,
2261 Defining_Identifier
=> Ent
,
2262 Object_Definition
=>
2263 New_Occurrence_Of
(RTE
(RE_AST_Handler
), Loc
),
2265 Constant_Present
=> True);
2267 Set_Assignment_OK
(Decl
, True);
2268 Insert_Action
(N
, Decl
);
2269 Attr_Node
:= Make_Identifier
(Loc
, Chars
(Ent
));
2272 -- For all other attributes, we rewrite the attribute node to have
2273 -- a list of expressions corresponding to the subprogram formals.
2274 -- A renaming declaration is not a freeze point, and the analysis of
2275 -- the attribute reference should not freeze the type of the prefix.
2279 Make_Attribute_Reference
(Loc
,
2280 Prefix
=> Prefix
(Nam
),
2281 Attribute_Name
=> Aname
,
2282 Expressions
=> Expr_List
);
2284 Set_Must_Not_Freeze
(Attr_Node
);
2285 Set_Must_Not_Freeze
(Prefix
(Nam
));
2288 -- Case of renaming a function
2290 if Nkind
(Spec
) = N_Function_Specification
then
2292 if Is_Procedure_Attribute_Name
(Aname
) then
2293 Error_Msg_N
("attribute can only be renamed as procedure", Nam
);
2297 Find_Type
(Result_Definition
(Spec
));
2298 Rewrite
(Result_Definition
(Spec
),
2300 Base_Type
(Entity
(Result_Definition
(Spec
))), Loc
));
2303 Make_Subprogram_Body
(Loc
,
2304 Specification
=> Spec
,
2305 Declarations
=> New_List
,
2306 Handled_Statement_Sequence
=>
2307 Make_Handled_Sequence_Of_Statements
(Loc
,
2308 Statements
=> New_List
(
2309 Make_Return_Statement
(Loc
,
2310 Expression
=> Attr_Node
))));
2312 -- Case of renaming a procedure
2315 if not Is_Procedure_Attribute_Name
(Aname
) then
2316 Error_Msg_N
("attribute can only be renamed as function", Nam
);
2321 Make_Subprogram_Body
(Loc
,
2322 Specification
=> Spec
,
2323 Declarations
=> New_List
,
2324 Handled_Statement_Sequence
=>
2325 Make_Handled_Sequence_Of_Statements
(Loc
,
2326 Statements
=> New_List
(Attr_Node
)));
2329 Rewrite
(N
, Body_Node
);
2332 if Is_Compilation_Unit
(New_S
) then
2334 ("a library unit can only rename another library unit", N
);
2337 Set_Etype
(New_S
, Base_Type
(Etype
(New_S
)));
2339 -- We suppress elaboration warnings for the resulting entity, since
2340 -- clearly they are not needed, and more particularly, in the case
2341 -- of a generic formal subprogram, the resulting entity can appear
2342 -- after the instantiation itself, and thus look like a bogus case
2343 -- of access before elaboration.
2345 Set_Suppress_Elaboration_Warnings
(New_S
);
2347 end Attribute_Renaming
;
2349 ----------------------
2350 -- Chain_Use_Clause --
2351 ----------------------
2353 procedure Chain_Use_Clause
(N
: Node_Id
) is
2355 Level
: Int
:= Scope_Stack
.Last
;
2358 if not Is_Compilation_Unit
(Current_Scope
)
2359 or else not Is_Child_Unit
(Current_Scope
)
2361 null; -- Common case
2363 elsif Defining_Entity
(Parent
(N
)) = Current_Scope
then
2364 null; -- Common case for compilation unit
2367 -- If declaration appears in some other scope, it must be in some
2368 -- parent unit when compiling a child.
2370 Pack
:= Defining_Entity
(Parent
(N
));
2371 if not In_Open_Scopes
(Pack
) then
2372 null; -- default as well
2375 -- Find entry for parent unit in scope stack
2377 while Scope_Stack
.Table
(Level
).Entity
/= Pack
loop
2383 Set_Next_Use_Clause
(N
,
2384 Scope_Stack
.Table
(Level
).First_Use_Clause
);
2385 Scope_Stack
.Table
(Level
).First_Use_Clause
:= N
;
2386 end Chain_Use_Clause
;
2388 ---------------------------
2389 -- Check_Frozen_Renaming --
2390 ---------------------------
2392 procedure Check_Frozen_Renaming
(N
: Node_Id
; Subp
: Entity_Id
) is
2398 and then not Has_Completion
(Subp
)
2402 (Parent
(Declaration_Node
(Subp
)), Defining_Entity
(N
));
2404 if Is_Entity_Name
(Name
(N
)) then
2405 Old_S
:= Entity
(Name
(N
));
2407 if not Is_Frozen
(Old_S
)
2408 and then Operating_Mode
/= Check_Semantics
2410 Append_Freeze_Action
(Old_S
, B_Node
);
2412 Insert_After
(N
, B_Node
);
2416 if Is_Intrinsic_Subprogram
(Old_S
)
2417 and then not In_Instance
2420 ("subprogram used in renaming_as_body cannot be intrinsic",
2425 Insert_After
(N
, B_Node
);
2429 end Check_Frozen_Renaming
;
2431 -----------------------------------
2432 -- Check_In_Previous_With_Clause --
2433 -----------------------------------
2435 procedure Check_In_Previous_With_Clause
2439 Pack
: constant Entity_Id
:= Entity
(Original_Node
(Nam
));
2444 Item
:= First
(Context_Items
(Parent
(N
)));
2446 while Present
(Item
)
2449 if Nkind
(Item
) = N_With_Clause
2451 -- Protect the frontend against previously reported
2454 and then Nkind
(Name
(Item
)) /= N_Selected_Component
2455 and then Entity
(Name
(Item
)) = Pack
2459 -- Find root library unit in with_clause
2461 while Nkind
(Par
) = N_Expanded_Name
loop
2462 Par
:= Prefix
(Par
);
2465 if Is_Child_Unit
(Entity
(Original_Node
(Par
))) then
2467 ("& is not directly visible", Par
, Entity
(Par
));
2476 -- On exit, package is not mentioned in a previous with_clause.
2477 -- Check if its prefix is.
2479 if Nkind
(Nam
) = N_Expanded_Name
then
2480 Check_In_Previous_With_Clause
(N
, Prefix
(Nam
));
2482 elsif Pack
/= Any_Id
then
2483 Error_Msg_NE
("& is not visible", Nam
, Pack
);
2485 end Check_In_Previous_With_Clause
;
2487 ---------------------------------
2488 -- Check_Library_Unit_Renaming --
2489 ---------------------------------
2491 procedure Check_Library_Unit_Renaming
(N
: Node_Id
; Old_E
: Entity_Id
) is
2495 if Nkind
(Parent
(N
)) /= N_Compilation_Unit
then
2498 elsif Scope
(Old_E
) /= Standard_Standard
2499 and then not Is_Child_Unit
(Old_E
)
2501 Error_Msg_N
("renamed unit must be a library unit", Name
(N
));
2503 -- Entities defined in Standard (operators and boolean literals) cannot
2504 -- be renamed as library units.
2506 elsif Scope
(Old_E
) = Standard_Standard
2507 and then Sloc
(Old_E
) = Standard_Location
2509 Error_Msg_N
("renamed unit must be a library unit", Name
(N
));
2511 elsif Present
(Parent_Spec
(N
))
2512 and then Nkind
(Unit
(Parent_Spec
(N
))) = N_Generic_Package_Declaration
2513 and then not Is_Child_Unit
(Old_E
)
2516 ("renamed unit must be a child unit of generic parent", Name
(N
));
2518 elsif Nkind
(N
) in N_Generic_Renaming_Declaration
2519 and then Nkind
(Name
(N
)) = N_Expanded_Name
2520 and then Is_Generic_Instance
(Entity
(Prefix
(Name
(N
))))
2521 and then Is_Generic_Unit
(Old_E
)
2524 ("renamed generic unit must be a library unit", Name
(N
));
2526 elsif Ekind
(Old_E
) = E_Package
2527 or else Ekind
(Old_E
) = E_Generic_Package
2529 -- Inherit categorization flags
2531 New_E
:= Defining_Entity
(N
);
2532 Set_Is_Pure
(New_E
, Is_Pure
(Old_E
));
2533 Set_Is_Preelaborated
(New_E
, Is_Preelaborated
(Old_E
));
2534 Set_Is_Remote_Call_Interface
(New_E
,
2535 Is_Remote_Call_Interface
(Old_E
));
2536 Set_Is_Remote_Types
(New_E
, Is_Remote_Types
(Old_E
));
2537 Set_Is_Shared_Passive
(New_E
, Is_Shared_Passive
(Old_E
));
2539 end Check_Library_Unit_Renaming
;
2545 procedure End_Scope
is
2551 Id
:= First_Entity
(Current_Scope
);
2553 while Present
(Id
) loop
2554 -- An entity in the current scope is not necessarily the first one
2555 -- on its homonym chain. Find its predecessor if any,
2556 -- If it is an internal entity, it will not be in the visibility
2557 -- chain altogether, and there is nothing to unchain.
2559 if Id
/= Current_Entity
(Id
) then
2560 Prev
:= Current_Entity
(Id
);
2561 while Present
(Prev
)
2562 and then Present
(Homonym
(Prev
))
2563 and then Homonym
(Prev
) /= Id
2565 Prev
:= Homonym
(Prev
);
2568 -- Skip to end of loop if Id is not in the visibility chain
2570 if No
(Prev
) or else Homonym
(Prev
) /= Id
then
2578 Outer
:= Homonym
(Id
);
2579 Set_Is_Immediately_Visible
(Id
, False);
2581 while Present
(Outer
) and then Scope
(Outer
) = Current_Scope
loop
2582 Outer
:= Homonym
(Outer
);
2585 -- Reset homonym link of other entities, but do not modify link
2586 -- between entities in current scope, so that the back-end can have
2587 -- a proper count of local overloadings.
2590 Set_Name_Entity_Id
(Chars
(Id
), Outer
);
2592 elsif Scope
(Prev
) /= Scope
(Id
) then
2593 Set_Homonym
(Prev
, Outer
);
2600 -- If the scope generated freeze actions, place them before the
2601 -- current declaration and analyze them. Type declarations and
2602 -- the bodies of initialization procedures can generate such nodes.
2603 -- We follow the parent chain until we reach a list node, which is
2604 -- the enclosing list of declarations. If the list appears within
2605 -- a protected definition, move freeze nodes outside the protected
2609 (Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
)
2613 L
: constant List_Id
:= Scope_Stack
.Table
2614 (Scope_Stack
.Last
).Pending_Freeze_Actions
;
2617 if Is_Itype
(Current_Scope
) then
2618 Decl
:= Associated_Node_For_Itype
(Current_Scope
);
2620 Decl
:= Parent
(Current_Scope
);
2625 while not (Is_List_Member
(Decl
))
2626 or else Nkind
(Parent
(Decl
)) = N_Protected_Definition
2627 or else Nkind
(Parent
(Decl
)) = N_Task_Definition
2629 Decl
:= Parent
(Decl
);
2632 Insert_List_Before_And_Analyze
(Decl
, L
);
2641 ---------------------
2642 -- End_Use_Clauses --
2643 ---------------------
2645 procedure End_Use_Clauses
(Clause
: Node_Id
) is
2649 -- Remove Use_Type clauses first, because they affect the
2650 -- visibility of operators in subsequent used packages.
2653 while Present
(U
) loop
2654 if Nkind
(U
) = N_Use_Type_Clause
then
2658 Next_Use_Clause
(U
);
2662 while Present
(U
) loop
2663 if Nkind
(U
) = N_Use_Package_Clause
then
2664 End_Use_Package
(U
);
2667 Next_Use_Clause
(U
);
2669 end End_Use_Clauses
;
2671 ---------------------
2672 -- End_Use_Package --
2673 ---------------------
2675 procedure End_Use_Package
(N
: Node_Id
) is
2676 Pack_Name
: Node_Id
;
2681 function Is_Primitive_Operator
2683 F
: Entity_Id
) return Boolean;
2684 -- Check whether Op is a primitive operator of a use-visible type
2686 ---------------------------
2687 -- Is_Primitive_Operator --
2688 ---------------------------
2690 function Is_Primitive_Operator
2692 F
: Entity_Id
) return Boolean
2694 T
: constant Entity_Id
:= Etype
(F
);
2698 and then Scope
(T
) = Scope
(Op
);
2699 end Is_Primitive_Operator
;
2701 -- Start of processing for End_Use_Package
2704 Pack_Name
:= First
(Names
(N
));
2706 while Present
(Pack_Name
) loop
2707 Pack
:= Entity
(Pack_Name
);
2709 if Ekind
(Pack
) = E_Package
then
2711 if In_Open_Scopes
(Pack
) then
2714 elsif not Redundant_Use
(Pack_Name
) then
2715 Set_In_Use
(Pack
, False);
2716 Set_Current_Use_Clause
(Pack
, Empty
);
2717 Id
:= First_Entity
(Pack
);
2719 while Present
(Id
) loop
2721 -- Preserve use-visibility of operators that are primitive
2722 -- operators of a type that is use_visible through an active
2725 if Nkind
(Id
) = N_Defining_Operator_Symbol
2727 (Is_Primitive_Operator
(Id
, First_Formal
(Id
))
2729 (Present
(Next_Formal
(First_Formal
(Id
)))
2731 Is_Primitive_Operator
2732 (Id
, Next_Formal
(First_Formal
(Id
)))))
2737 Set_Is_Potentially_Use_Visible
(Id
, False);
2740 if Is_Private_Type
(Id
)
2741 and then Present
(Full_View
(Id
))
2743 Set_Is_Potentially_Use_Visible
(Full_View
(Id
), False);
2749 if Present
(Renamed_Object
(Pack
)) then
2750 Set_In_Use
(Renamed_Object
(Pack
), False);
2751 Set_Current_Use_Clause
(Renamed_Object
(Pack
), Empty
);
2754 if Chars
(Pack
) = Name_System
2755 and then Scope
(Pack
) = Standard_Standard
2756 and then Present_System_Aux
2758 Id
:= First_Entity
(System_Aux_Id
);
2760 while Present
(Id
) loop
2761 Set_Is_Potentially_Use_Visible
(Id
, False);
2763 if Is_Private_Type
(Id
)
2764 and then Present
(Full_View
(Id
))
2766 Set_Is_Potentially_Use_Visible
(Full_View
(Id
), False);
2772 Set_In_Use
(System_Aux_Id
, False);
2776 Set_Redundant_Use
(Pack_Name
, False);
2784 if Present
(Hidden_By_Use_Clause
(N
)) then
2785 Elmt
:= First_Elmt
(Hidden_By_Use_Clause
(N
));
2787 while Present
(Elmt
) loop
2788 Set_Is_Immediately_Visible
(Node
(Elmt
));
2792 Set_Hidden_By_Use_Clause
(N
, No_Elist
);
2794 end End_Use_Package
;
2800 procedure End_Use_Type
(N
: Node_Id
) is
2807 Id
:= First
(Subtype_Marks
(N
));
2809 while Present
(Id
) loop
2811 -- A call to rtsfind may occur while analyzing a use_type clause,
2812 -- in which case the type marks are not resolved yet, and there is
2813 -- nothing to remove.
2815 if not Is_Entity_Name
(Id
)
2816 or else No
(Entity
(Id
))
2824 or else From_With_Type
(T
)
2828 -- Note that the use_Type clause may mention a subtype of the
2829 -- type whose primitive operations have been made visible. Here
2830 -- as elsewhere, it is the base type that matters for visibility.
2832 elsif In_Open_Scopes
(Scope
(Base_Type
(T
))) then
2835 elsif not Redundant_Use
(Id
) then
2836 Set_In_Use
(T
, False);
2837 Set_In_Use
(Base_Type
(T
), False);
2838 Op_List
:= Collect_Primitive_Operations
(T
);
2839 Elmt
:= First_Elmt
(Op_List
);
2841 while Present
(Elmt
) loop
2843 if Nkind
(Node
(Elmt
)) = N_Defining_Operator_Symbol
then
2844 Set_Is_Potentially_Use_Visible
(Node
(Elmt
), False);
2856 ----------------------
2857 -- Find_Direct_Name --
2858 ----------------------
2860 procedure Find_Direct_Name
(N
: Node_Id
) is
2865 Inst
: Entity_Id
:= Empty
;
2866 -- Enclosing instance, if any
2868 Homonyms
: Entity_Id
;
2869 -- Saves start of homonym chain
2871 Nvis_Entity
: Boolean;
2872 -- Set True to indicate that at there is at least one entity on the
2873 -- homonym chain which, while not visible, is visible enough from the
2874 -- user point of view to warrant an error message of "not visible"
2875 -- rather than undefined.
2877 Nvis_Is_Private_Subprg
: Boolean := False;
2878 -- Ada 2005 (AI-262): Set True to indicate that a form of Beaujolais
2879 -- effect concerning library subprograms has been detected. Used to
2880 -- generate the precise error message.
2882 function From_Actual_Package
(E
: Entity_Id
) return Boolean;
2883 -- Returns true if the entity is declared in a package that is
2884 -- an actual for a formal package of the current instance. Such an
2885 -- entity requires special handling because it may be use-visible
2886 -- but hides directly visible entities defined outside the instance.
2888 function Known_But_Invisible
(E
: Entity_Id
) return Boolean;
2889 -- This function determines whether the entity E (which is not
2890 -- visible) can reasonably be considered to be known to the writer
2891 -- of the reference. This is a heuristic test, used only for the
2892 -- purposes of figuring out whether we prefer to complain that an
2893 -- entity is undefined or invisible (and identify the declaration
2894 -- of the invisible entity in the latter case). The point here is
2895 -- that we don't want to complain that something is invisible and
2896 -- then point to something entirely mysterious to the writer.
2898 procedure Nvis_Messages
;
2899 -- Called if there are no visible entries for N, but there is at least
2900 -- one non-directly visible, or hidden declaration. This procedure
2901 -- outputs an appropriate set of error messages.
2903 procedure Undefined
(Nvis
: Boolean);
2904 -- This function is called if the current node has no corresponding
2905 -- visible entity or entities. The value set in Msg indicates whether
2906 -- an error message was generated (multiple error messages for the
2907 -- same variable are generally suppressed, see body for details).
2908 -- Msg is True if an error message was generated, False if not. This
2909 -- value is used by the caller to determine whether or not to output
2910 -- additional messages where appropriate. The parameter is set False
2911 -- to get the message "X is undefined", and True to get the message
2912 -- "X is not visible".
2914 -------------------------
2915 -- From_Actual_Package --
2916 -------------------------
2918 function From_Actual_Package
(E
: Entity_Id
) return Boolean is
2919 Scop
: constant Entity_Id
:= Scope
(E
);
2923 if not In_Instance
then
2926 Inst
:= Current_Scope
;
2928 while Present
(Inst
)
2929 and then Ekind
(Inst
) /= E_Package
2930 and then not Is_Generic_Instance
(Inst
)
2932 Inst
:= Scope
(Inst
);
2939 Act
:= First_Entity
(Inst
);
2941 while Present
(Act
) loop
2942 if Ekind
(Act
) = E_Package
then
2944 -- Check for end of actuals list
2946 if Renamed_Object
(Act
) = Inst
then
2949 elsif Present
(Associated_Formal_Package
(Act
))
2950 and then Renamed_Object
(Act
) = Scop
2952 -- Entity comes from (instance of) formal package
2967 end From_Actual_Package
;
2969 -------------------------
2970 -- Known_But_Invisible --
2971 -------------------------
2973 function Known_But_Invisible
(E
: Entity_Id
) return Boolean is
2974 Fname
: File_Name_Type
;
2977 -- Entities in Standard are always considered to be known
2979 if Sloc
(E
) <= Standard_Location
then
2982 -- An entity that does not come from source is always considered
2983 -- to be unknown, since it is an artifact of code expansion.
2985 elsif not Comes_From_Source
(E
) then
2988 -- In gnat internal mode, we consider all entities known
2990 elsif GNAT_Mode
then
2994 -- Here we have an entity that is not from package Standard, and
2995 -- which comes from Source. See if it comes from an internal file.
2997 Fname
:= Unit_File_Name
(Get_Source_Unit
(E
));
2999 -- Case of from internal file
3001 if Is_Internal_File_Name
(Fname
) then
3003 -- Private part entities in internal files are never considered
3004 -- to be known to the writer of normal application code.
3006 if Is_Hidden
(E
) then
3010 -- Entities from System packages other than System and
3011 -- System.Storage_Elements are not considered to be known.
3012 -- System.Auxxxx files are also considered known to the user.
3014 -- Should refine this at some point to generally distinguish
3015 -- between known and unknown internal files ???
3017 Get_Name_String
(Fname
);
3022 Name_Buffer
(1 .. 2) /= "s-"
3024 Name_Buffer
(3 .. 8) = "stoele"
3026 Name_Buffer
(3 .. 5) = "aux";
3028 -- If not an internal file, then entity is definitely known,
3029 -- even if it is in a private part (the message generated will
3030 -- note that it is in a private part)
3035 end Known_But_Invisible
;
3041 procedure Nvis_Messages
is
3042 Comp_Unit
: Node_Id
;
3044 Hidden
: Boolean := False;
3048 -- Ada 2005 (AI-262): Generate a precise error concerning the
3049 -- Beaujolais effect that was previously detected
3051 if Nvis_Is_Private_Subprg
then
3053 pragma Assert
(Nkind
(E2
) = N_Defining_Identifier
3054 and then Ekind
(E2
) = E_Function
3055 and then Scope
(E2
) = Standard_Standard
3056 and then Has_Private_With
(E2
));
3058 -- Find the sloc corresponding to the private with'ed unit
3060 Comp_Unit
:= Cunit
(Current_Sem_Unit
);
3061 Item
:= First
(Context_Items
(Comp_Unit
));
3062 Error_Msg_Sloc
:= No_Location
;
3064 while Present
(Item
) loop
3065 if Nkind
(Item
) = N_With_Clause
3066 and then Private_Present
(Item
)
3067 and then Entity
(Name
(Item
)) = E2
3069 Error_Msg_Sloc
:= Sloc
(Item
);
3076 pragma Assert
(Error_Msg_Sloc
/= No_Location
);
3078 Error_Msg_N
("(Ada 2005): hidden by private with clause #", N
);
3082 Undefined
(Nvis
=> True);
3086 -- First loop does hidden declarations
3089 while Present
(Ent
) loop
3090 if Is_Potentially_Use_Visible
(Ent
) then
3093 Error_Msg_N
("multiple use clauses cause hiding!", N
);
3097 Error_Msg_Sloc
:= Sloc
(Ent
);
3098 Error_Msg_N
("hidden declaration#!", N
);
3101 Ent
:= Homonym
(Ent
);
3104 -- If we found hidden declarations, then that's enough, don't
3105 -- bother looking for non-visible declarations as well.
3111 -- Second loop does non-directly visible declarations
3114 while Present
(Ent
) loop
3115 if not Is_Potentially_Use_Visible
(Ent
) then
3117 -- Do not bother the user with unknown entities
3119 if not Known_But_Invisible
(Ent
) then
3123 Error_Msg_Sloc
:= Sloc
(Ent
);
3125 -- Output message noting that there is a non-visible
3126 -- declaration, distinguishing the private part case.
3128 if Is_Hidden
(Ent
) then
3129 Error_Msg_N
("non-visible (private) declaration#!", N
);
3131 Error_Msg_N
("non-visible declaration#!", N
);
3133 if Is_Compilation_Unit
(Ent
)
3135 Nkind
(Parent
(Parent
(N
))) = N_Use_Package_Clause
3138 ("\possible missing with_clause for&", N
, Ent
);
3142 -- Set entity and its containing package as referenced. We
3143 -- can't be sure of this, but this seems a better choice
3144 -- to avoid unused entity messages.
3146 if Comes_From_Source
(Ent
) then
3147 Set_Referenced
(Ent
);
3148 Set_Referenced
(Cunit_Entity
(Get_Source_Unit
(Ent
)));
3153 Ent
:= Homonym
(Ent
);
3163 procedure Undefined
(Nvis
: Boolean) is
3164 Emsg
: Error_Msg_Id
;
3167 -- We should never find an undefined internal name. If we do, then
3168 -- see if we have previous errors. If so, ignore on the grounds that
3169 -- it is probably a cascaded message (e.g. a block label from a badly
3170 -- formed block). If no previous errors, then we have a real internal
3171 -- error of some kind so raise an exception.
3173 if Is_Internal_Name
(Chars
(N
)) then
3174 if Total_Errors_Detected
/= 0 then
3177 raise Program_Error
;
3181 -- A very specialized error check, if the undefined variable is
3182 -- a case tag, and the case type is an enumeration type, check
3183 -- for a possible misspelling, and if so, modify the identifier
3185 -- Named aggregate should also be handled similarly ???
3187 if Nkind
(N
) = N_Identifier
3188 and then Nkind
(Parent
(N
)) = N_Case_Statement_Alternative
3190 Get_Name_String
(Chars
(N
));
3193 Case_Str
: constant String := Name_Buffer
(1 .. Name_Len
);
3194 Case_Stm
: constant Node_Id
:= Parent
(Parent
(N
));
3195 Case_Typ
: constant Entity_Id
:= Etype
(Expression
(Case_Stm
));
3196 Case_Rtp
: constant Entity_Id
:= Root_Type
(Case_Typ
);
3201 if Is_Enumeration_Type
(Case_Typ
)
3202 and then Case_Rtp
/= Standard_Character
3203 and then Case_Rtp
/= Standard_Wide_Character
3204 and then Case_Rtp
/= Standard_Wide_Wide_Character
3206 Lit
:= First_Literal
(Case_Typ
);
3207 Get_Name_String
(Chars
(Lit
));
3209 if Chars
(Lit
) /= Chars
(N
)
3210 and then Is_Bad_Spelling_Of
3211 (Case_Str
, Name_Buffer
(1 .. Name_Len
))
3213 Error_Msg_Node_2
:= Lit
;
3215 ("& is undefined, assume misspelling of &", N
);
3216 Rewrite
(N
, New_Occurrence_Of
(Lit
, Sloc
(N
)));
3220 Lit
:= Next_Literal
(Lit
);
3225 -- Normal processing
3227 Set_Entity
(N
, Any_Id
);
3228 Set_Etype
(N
, Any_Type
);
3230 -- We use the table Urefs to keep track of entities for which we
3231 -- have issued errors for undefined references. Multiple errors
3232 -- for a single name are normally suppressed, however we modify
3233 -- the error message to alert the programmer to this effect.
3235 for J
in Urefs
.First
.. Urefs
.Last
loop
3236 if Chars
(N
) = Chars
(Urefs
.Table
(J
).Node
) then
3237 if Urefs
.Table
(J
).Err
/= No_Error_Msg
3238 and then Sloc
(N
) /= Urefs
.Table
(J
).Loc
3240 Error_Msg_Node_1
:= Urefs
.Table
(J
).Node
;
3242 if Urefs
.Table
(J
).Nvis
then
3243 Change_Error_Text
(Urefs
.Table
(J
).Err
,
3244 "& is not visible (more references follow)");
3246 Change_Error_Text
(Urefs
.Table
(J
).Err
,
3247 "& is undefined (more references follow)");
3250 Urefs
.Table
(J
).Err
:= No_Error_Msg
;
3253 -- Although we will set Msg False, and thus suppress the
3254 -- message, we also set Error_Posted True, to avoid any
3255 -- cascaded messages resulting from the undefined reference.
3258 Set_Error_Posted
(N
, True);
3263 -- If entry not found, this is first undefined occurrence
3266 Error_Msg_N
("& is not visible!", N
);
3270 Error_Msg_N
("& is undefined!", N
);
3273 -- A very bizarre special check, if the undefined identifier
3274 -- is put or put_line, then add a special error message (since
3275 -- this is a very common error for beginners to make).
3277 if Chars
(N
) = Name_Put
or else Chars
(N
) = Name_Put_Line
then
3278 Error_Msg_N
("\possible missing with of 'Text_'I'O!", N
);
3281 -- Now check for possible misspellings
3283 Get_Name_String
(Chars
(N
));
3287 Ematch
: Entity_Id
:= Empty
;
3289 Last_Name_Id
: constant Name_Id
:=
3290 Name_Id
(Nat
(First_Name_Id
) +
3291 Name_Entries_Count
- 1);
3293 S
: constant String (1 .. Name_Len
) :=
3294 Name_Buffer
(1 .. Name_Len
);
3297 for N
in First_Name_Id
.. Last_Name_Id
loop
3298 E
:= Get_Name_Entity_Id
(N
);
3301 and then (Is_Immediately_Visible
(E
)
3303 Is_Potentially_Use_Visible
(E
))
3305 Get_Name_String
(N
);
3307 if Is_Bad_Spelling_Of
3308 (S
, Name_Buffer
(1 .. Name_Len
))
3316 if Present
(Ematch
) then
3317 Error_Msg_NE
("\possible misspelling of&", N
, Ematch
);
3322 -- Make entry in undefined references table unless the full
3323 -- errors switch is set, in which case by refraining from
3324 -- generating the table entry, we guarantee that we get an
3325 -- error message for every undefined reference.
3327 if not All_Errors_Mode
then
3328 Urefs
.Increment_Last
;
3329 Urefs
.Table
(Urefs
.Last
).Node
:= N
;
3330 Urefs
.Table
(Urefs
.Last
).Err
:= Emsg
;
3331 Urefs
.Table
(Urefs
.Last
).Nvis
:= Nvis
;
3332 Urefs
.Table
(Urefs
.Last
).Loc
:= Sloc
(N
);
3338 -- Start of processing for Find_Direct_Name
3341 -- If the entity pointer is already set, this is an internal node, or
3342 -- a node that is analyzed more than once, after a tree modification.
3343 -- In such a case there is no resolution to perform, just set the type.
3345 if Present
(Entity
(N
)) then
3346 if Is_Type
(Entity
(N
)) then
3347 Set_Etype
(N
, Entity
(N
));
3351 Entyp
: constant Entity_Id
:= Etype
(Entity
(N
));
3354 -- One special case here. If the Etype field is already set,
3355 -- and references the packed array type corresponding to the
3356 -- etype of the referenced entity, then leave it alone. This
3357 -- happens for trees generated from Exp_Pakd, where expressions
3358 -- can be deliberately "mis-typed" to the packed array type.
3360 if Is_Array_Type
(Entyp
)
3361 and then Is_Packed
(Entyp
)
3362 and then Present
(Etype
(N
))
3363 and then Etype
(N
) = Packed_Array_Type
(Entyp
)
3367 -- If not that special case, then just reset the Etype
3370 Set_Etype
(N
, Etype
(Entity
(N
)));
3378 -- Here if Entity pointer was not set, we need full visibility analysis
3379 -- First we generate debugging output if the debug E flag is set.
3381 if Debug_Flag_E
then
3382 Write_Str
("Looking for ");
3383 Write_Name
(Chars
(N
));
3387 Homonyms
:= Current_Entity
(N
);
3388 Nvis_Entity
:= False;
3391 while Present
(E
) loop
3393 -- If entity is immediately visible or potentially use
3394 -- visible, then process the entity and we are done.
3396 if Is_Immediately_Visible
(E
) then
3397 goto Immediately_Visible_Entity
;
3399 elsif Is_Potentially_Use_Visible
(E
) then
3400 goto Potentially_Use_Visible_Entity
;
3402 -- Note if a known but invisible entity encountered
3404 elsif Known_But_Invisible
(E
) then
3405 Nvis_Entity
:= True;
3408 -- Move to next entity in chain and continue search
3413 -- If no entries on homonym chain that were potentially visible,
3414 -- and no entities reasonably considered as non-visible, then
3415 -- we have a plain undefined reference, with no additional
3416 -- explanation required!
3418 if not Nvis_Entity
then
3419 Undefined
(Nvis
=> False);
3421 -- Otherwise there is at least one entry on the homonym chain that
3422 -- is reasonably considered as being known and non-visible.
3430 -- Processing for a potentially use visible entry found. We must search
3431 -- the rest of the homonym chain for two reasons. First, if there is a
3432 -- directly visible entry, then none of the potentially use-visible
3433 -- entities are directly visible (RM 8.4(10)). Second, we need to check
3434 -- for the case of multiple potentially use-visible entries hiding one
3435 -- another and as a result being non-directly visible (RM 8.4(11)).
3437 <<Potentially_Use_Visible_Entity
>> declare
3438 Only_One_Visible
: Boolean := True;
3439 All_Overloadable
: Boolean := Is_Overloadable
(E
);
3444 while Present
(E2
) loop
3445 if Is_Immediately_Visible
(E2
) then
3447 -- If the use-visible entity comes from the actual for a
3448 -- formal package, it hides a directly visible entity from
3449 -- outside the instance.
3451 if From_Actual_Package
(E
)
3452 and then Scope_Depth
(E2
) < Scope_Depth
(Inst
)
3457 goto Immediately_Visible_Entity
;
3460 elsif Is_Potentially_Use_Visible
(E2
) then
3461 Only_One_Visible
:= False;
3462 All_Overloadable
:= All_Overloadable
and Is_Overloadable
(E2
);
3464 -- Ada 2005 (AI-262): Protect against a form of Beujolais effect
3465 -- that can occurr in private_with clauses. Example:
3468 -- private with B; package A is
3469 -- package C is function B return Integer;
3471 -- V1 : Integer := B;
3472 -- private function B return Integer;
3473 -- V2 : Integer := B;
3476 -- V1 resolves to A.B, but V2 resolves to library unit B
3478 elsif Ekind
(E2
) = E_Function
3479 and then Scope
(E2
) = Standard_Standard
3480 and then Has_Private_With
(E2
)
3482 Only_One_Visible
:= False;
3483 All_Overloadable
:= False;
3484 Nvis_Is_Private_Subprg
:= True;
3491 -- On falling through this loop, we have checked that there are no
3492 -- immediately visible entities. Only_One_Visible is set if exactly
3493 -- one potentially use visible entity exists. All_Overloadable is
3494 -- set if all the potentially use visible entities are overloadable.
3495 -- The condition for legality is that either there is one potentially
3496 -- use visible entity, or if there is more than one, then all of them
3497 -- are overloadable.
3499 if Only_One_Visible
or All_Overloadable
then
3502 -- If there is more than one potentially use-visible entity and at
3503 -- least one of them non-overloadable, we have an error (RM 8.4(11).
3504 -- Note that E points to the first such entity on the homonym list.
3505 -- Special case: if one of the entities is declared in an actual
3506 -- package, it was visible in the generic, and takes precedence over
3507 -- other entities that are potentially use-visible. Same if it is
3508 -- declared in a local instantiation of the current instance.
3512 Inst
:= Current_Scope
;
3514 -- Find current instance
3516 while Present
(Inst
)
3517 and then Inst
/= Standard_Standard
3519 if Is_Generic_Instance
(Inst
) then
3523 Inst
:= Scope
(Inst
);
3528 while Present
(E2
) loop
3529 if From_Actual_Package
(E2
)
3531 (Is_Generic_Instance
(Scope
(E2
))
3532 and then Scope_Depth
(Scope
(E2
)) > Scope_Depth
(Inst
))
3545 Is_Predefined_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
3547 -- A use-clause in the body of a system file creates conflict
3548 -- with some entity in a user scope, while rtsfind is active.
3549 -- Keep only the entity coming from another predefined unit.
3552 while Present
(E2
) loop
3553 if Is_Predefined_File_Name
3554 (Unit_File_Name
(Get_Source_Unit
(Sloc
(E2
))))
3563 -- Entity must exist because predefined unit is correct
3565 raise Program_Error
;
3574 -- Come here with E set to the first immediately visible entity on
3575 -- the homonym chain. This is the one we want unless there is another
3576 -- immediately visible entity further on in the chain for a more
3577 -- inner scope (RM 8.3(8)).
3579 <<Immediately_Visible_Entity
>> declare
3584 -- Find scope level of initial entity. When compiling through
3585 -- Rtsfind, the previous context is not completely invisible, and
3586 -- an outer entity may appear on the chain, whose scope is below
3587 -- the entry for Standard that delimits the current scope stack.
3588 -- Indicate that the level for this spurious entry is outside of
3589 -- the current scope stack.
3591 Level
:= Scope_Stack
.Last
;
3593 Scop
:= Scope_Stack
.Table
(Level
).Entity
;
3594 exit when Scop
= Scope
(E
);
3596 exit when Scop
= Standard_Standard
;
3599 -- Now search remainder of homonym chain for more inner entry
3600 -- If the entity is Standard itself, it has no scope, and we
3601 -- compare it with the stack entry directly.
3604 while Present
(E2
) loop
3605 if Is_Immediately_Visible
(E2
) then
3607 -- If a generic package contains a local declaration that
3608 -- has the same name as the generic, there may be a visibility
3609 -- conflict in an instance, where the local declaration must
3610 -- also hide the name of the corresponding package renaming.
3611 -- We check explicitly for a package declared by a renaming,
3612 -- whose renamed entity is an instance that is on the scope
3613 -- stack, and that contains a homonym in the same scope. Once
3614 -- we have found it, we know that the package renaming is not
3615 -- immediately visible, and that the identifier denotes the
3616 -- other entity (and its homonyms if overloaded).
3618 if Scope
(E
) = Scope
(E2
)
3619 and then Ekind
(E
) = E_Package
3620 and then Present
(Renamed_Object
(E
))
3621 and then Is_Generic_Instance
(Renamed_Object
(E
))
3622 and then In_Open_Scopes
(Renamed_Object
(E
))
3623 and then Comes_From_Source
(N
)
3625 Set_Is_Immediately_Visible
(E
, False);
3629 for J
in Level
+ 1 .. Scope_Stack
.Last
loop
3630 if Scope_Stack
.Table
(J
).Entity
= Scope
(E2
)
3631 or else Scope_Stack
.Table
(J
).Entity
= E2
3644 -- At the end of that loop, E is the innermost immediately
3645 -- visible entity, so we are all set.
3648 -- Come here with entity found, and stored in E
3652 if Comes_From_Source
(N
)
3653 and then Is_Remote_Access_To_Subprogram_Type
(E
)
3654 and then Expander_Active
3655 and then Get_PCS_Name
/= Name_No_DSA
3658 New_Occurrence_Of
(Equivalent_Type
(E
), Sloc
(N
)));
3663 -- Why no Style_Check here???
3668 Set_Etype
(N
, Get_Full_View
(Etype
(E
)));
3671 if Debug_Flag_E
then
3672 Write_Str
(" found ");
3673 Write_Entity_Info
(E
, " ");
3676 -- If the Ekind of the entity is Void, it means that all homonyms
3677 -- are hidden from all visibility (RM 8.3(5,14-20)). However, this
3678 -- test is skipped if the current scope is a record and the name is
3679 -- a pragma argument expression (case of Atomic and Volatile pragmas
3680 -- and possibly other similar pragmas added later, which are allowed
3681 -- to reference components in the current record).
3683 if Ekind
(E
) = E_Void
3685 (not Is_Record_Type
(Current_Scope
)
3686 or else Nkind
(Parent
(N
)) /= N_Pragma_Argument_Association
)
3688 Premature_Usage
(N
);
3690 -- If the entity is overloadable, collect all interpretations
3691 -- of the name for subsequent overload resolution. We optimize
3692 -- a bit here to do this only if we have an overloadable entity
3693 -- that is not on its own on the homonym chain.
3695 elsif Is_Overloadable
(E
)
3696 and then (Present
(Homonym
(E
)) or else Current_Entity
(N
) /= E
)
3698 Collect_Interps
(N
);
3700 -- If no homonyms were visible, the entity is unambiguous
3702 if not Is_Overloaded
(N
) then
3703 Generate_Reference
(E
, N
);
3706 -- Case of non-overloadable entity, set the entity providing that
3707 -- we do not have the case of a discriminant reference within a
3708 -- default expression. Such references are replaced with the
3709 -- corresponding discriminal, which is the formal corresponding to
3710 -- to the discriminant in the initialization procedure.
3713 -- Entity is unambiguous, indicate that it is referenced here
3714 -- One slightly odd case is that we do not want to set the
3715 -- Referenced flag if the entity is a label, and the identifier
3716 -- is the label in the source, since this is not a reference
3717 -- from the point of view of the user
3719 if Nkind
(Parent
(N
)) = N_Label
then
3721 R
: constant Boolean := Referenced
(E
);
3724 Generate_Reference
(E
, N
);
3725 Set_Referenced
(E
, R
);
3728 -- Normal case, not a label. Generate reference
3731 Generate_Reference
(E
, N
);
3734 -- Set Entity, with style check if need be. If this is a
3735 -- discriminant reference, it must be replaced by the
3736 -- corresponding discriminal, that is to say the parameter
3737 -- of the initialization procedure that corresponds to the
3738 -- discriminant. If this replacement is being performed, there
3739 -- is no style check to perform.
3741 -- This replacement must not be done if we are currently
3742 -- processing a generic spec or body, because the discriminal
3743 -- has not been not generated in this case.
3745 if not In_Default_Expression
3746 or else Ekind
(E
) /= E_Discriminant
3747 or else Inside_A_Generic
3749 Set_Entity_With_Style_Check
(N
, E
);
3751 -- The replacement is not done either for a task discriminant that
3752 -- appears in a default expression of an entry parameter. See
3753 -- Expand_Discriminant in exp_ch2 for details on their handling.
3755 elsif Is_Concurrent_Type
(Scope
(E
)) then
3757 P
: Node_Id
:= Parent
(N
);
3761 and then Nkind
(P
) /= N_Parameter_Specification
3762 and then Nkind
(P
) /= N_Component_Declaration
3768 and then Nkind
(P
) = N_Parameter_Specification
3772 Set_Entity
(N
, Discriminal
(E
));
3776 -- Otherwise, this is a discriminant in a context in which
3777 -- it is a reference to the corresponding parameter of the
3778 -- init proc for the enclosing type.
3781 Set_Entity
(N
, Discriminal
(E
));
3785 end Find_Direct_Name
;
3787 ------------------------
3788 -- Find_Expanded_Name --
3789 ------------------------
3791 -- This routine searches the homonym chain of the entity until it finds
3792 -- an entity declared in the scope denoted by the prefix. If the entity
3793 -- is private, it may nevertheless be immediately visible, if we are in
3794 -- the scope of its declaration.
3796 procedure Find_Expanded_Name
(N
: Node_Id
) is
3797 Selector
: constant Node_Id
:= Selector_Name
(N
);
3798 Candidate
: Entity_Id
:= Empty
;
3804 P_Name
:= Entity
(Prefix
(N
));
3807 -- If the prefix is a renamed package, look for the entity
3808 -- in the original package.
3810 if Ekind
(P_Name
) = E_Package
3811 and then Present
(Renamed_Object
(P_Name
))
3813 P_Name
:= Renamed_Object
(P_Name
);
3815 -- Rewrite node with entity field pointing to renamed object
3817 Rewrite
(Prefix
(N
), New_Copy
(Prefix
(N
)));
3818 Set_Entity
(Prefix
(N
), P_Name
);
3820 -- If the prefix is an object of a concurrent type, look for
3821 -- the entity in the associated task or protected type.
3823 elsif Is_Concurrent_Type
(Etype
(P_Name
)) then
3824 P_Name
:= Etype
(P_Name
);
3827 Id
:= Current_Entity
(Selector
);
3830 Is_New_Candidate
: Boolean;
3833 while Present
(Id
) loop
3834 if Scope
(Id
) = P_Name
then
3836 Is_New_Candidate
:= True;
3838 -- Ada 2005 (AI-217): Handle shadow entities associated with types
3839 -- declared in limited-withed nested packages. We don't need to
3840 -- handle E_Incomplete_Subtype entities because the entities in
3841 -- the limited view are always E_Incomplete_Type entities (see
3842 -- Build_Limited_Views). Regarding the expression used to evaluate
3843 -- the scope, it is important to note that the limited view also
3844 -- has shadow entities associated nested packages. For this reason
3845 -- the correct scope of the entity is the scope of the real entity
3847 elsif From_With_Type
(Id
)
3848 and then Is_Type
(Id
)
3849 and then Ekind
(Id
) = E_Incomplete_Type
3850 and then Present
(Non_Limited_View
(Id
))
3851 and then Scope
(Non_Limited_View
(Id
)) = P_Name
3853 Candidate
:= Non_Limited_View
(Id
);
3854 Is_New_Candidate
:= True;
3857 Is_New_Candidate
:= False;
3860 if Is_New_Candidate
then
3861 if Is_Child_Unit
(Id
) then
3862 exit when Is_Visible_Child_Unit
(Id
)
3863 or else Is_Immediately_Visible
(Id
);
3866 exit when not Is_Hidden
(Id
)
3867 or else Is_Immediately_Visible
(Id
);
3876 and then (Ekind
(P_Name
) = E_Procedure
3878 Ekind
(P_Name
) = E_Function
)
3879 and then Is_Generic_Instance
(P_Name
)
3881 -- Expanded name denotes entity in (instance of) generic subprogram.
3882 -- The entity may be in the subprogram instance, or may denote one of
3883 -- the formals, which is declared in the enclosing wrapper package.
3885 P_Name
:= Scope
(P_Name
);
3887 Id
:= Current_Entity
(Selector
);
3888 while Present
(Id
) loop
3889 exit when Scope
(Id
) = P_Name
;
3894 if No
(Id
) or else Chars
(Id
) /= Chars
(Selector
) then
3895 Set_Etype
(N
, Any_Type
);
3897 -- If we are looking for an entity defined in System, try to
3898 -- find it in the child package that may have been provided as
3899 -- an extension to System. The Extend_System pragma will have
3900 -- supplied the name of the extension, which may have to be loaded.
3902 if Chars
(P_Name
) = Name_System
3903 and then Scope
(P_Name
) = Standard_Standard
3904 and then Present
(System_Extend_Unit
)
3905 and then Present_System_Aux
(N
)
3907 Set_Entity
(Prefix
(N
), System_Aux_Id
);
3908 Find_Expanded_Name
(N
);
3911 elsif Nkind
(Selector
) = N_Operator_Symbol
3912 and then Has_Implicit_Operator
(N
)
3914 -- There is an implicit instance of the predefined operator in
3915 -- the given scope. The operator entity is defined in Standard.
3916 -- Has_Implicit_Operator makes the node into an Expanded_Name.
3920 elsif Nkind
(Selector
) = N_Character_Literal
3921 and then Has_Implicit_Character_Literal
(N
)
3923 -- If there is no literal defined in the scope denoted by the
3924 -- prefix, the literal may belong to (a type derived from)
3925 -- Standard_Character, for which we have no explicit literals.
3930 -- If the prefix is a single concurrent object, use its
3931 -- name in the error message, rather than that of the
3934 if Is_Concurrent_Type
(P_Name
)
3935 and then Is_Internal_Name
(Chars
(P_Name
))
3937 Error_Msg_Node_2
:= Entity
(Prefix
(N
));
3939 Error_Msg_Node_2
:= P_Name
;
3942 if P_Name
= System_Aux_Id
then
3943 P_Name
:= Scope
(P_Name
);
3944 Set_Entity
(Prefix
(N
), P_Name
);
3947 if Present
(Candidate
) then
3949 if Is_Child_Unit
(Candidate
) then
3951 -- If the candidate is a private child unit and we are
3952 -- in the visible part of a public unit, specialize the
3953 -- error message. There might be a private with_clause for
3954 -- it, but it is not currently active.
3956 if Is_Private_Descendant
(Candidate
)
3957 and then Ekind
(Current_Scope
) = E_Package
3958 and then not In_Private_Part
(Current_Scope
)
3959 and then not Is_Private_Descendant
(Current_Scope
)
3961 Error_Msg_N
("private child unit& is not visible here",
3965 ("missing with_clause for child unit &", Selector
);
3968 Error_Msg_NE
("& is not a visible entity of&", N
, Selector
);
3972 -- Within the instantiation of a child unit, the prefix may
3973 -- denote the parent instance, but the selector has the
3974 -- name of the original child. Find whether we are within
3975 -- the corresponding instance, and get the proper entity, which
3976 -- can only be an enclosing scope.
3979 and then In_Open_Scopes
(P_Name
)
3980 and then Is_Generic_Instance
(P_Name
)
3983 S
: Entity_Id
:= Current_Scope
;
3987 for J
in reverse 0 .. Scope_Stack
.Last
loop
3988 S
:= Scope_Stack
.Table
(J
).Entity
;
3990 exit when S
= Standard_Standard
;
3992 if Ekind
(S
) = E_Function
3993 or else Ekind
(S
) = E_Package
3994 or else Ekind
(S
) = E_Procedure
3996 P
:= Generic_Parent
(Specification
3997 (Unit_Declaration_Node
(S
)));
4000 and then Chars
(Scope
(P
)) = Chars
(O_Name
)
4001 and then Chars
(P
) = Chars
(Selector
)
4012 if Chars
(P_Name
) = Name_Ada
4013 and then Scope
(P_Name
) = Standard_Standard
4015 Error_Msg_Node_2
:= Selector
;
4016 Error_Msg_NE
("missing with for `&.&`", N
, P_Name
);
4018 -- If this is a selection from a dummy package, then
4019 -- suppress the error message, of course the entity
4020 -- is missing if the package is missing!
4022 elsif Sloc
(Error_Msg_Node_2
) = No_Location
then
4025 -- Here we have the case of an undefined component
4029 Error_Msg_NE
("& not declared in&", N
, Selector
);
4031 -- Check for misspelling of some entity in prefix
4033 Id
:= First_Entity
(P_Name
);
4034 Get_Name_String
(Chars
(Selector
));
4037 S
: constant String (1 .. Name_Len
) :=
4038 Name_Buffer
(1 .. Name_Len
);
4040 while Present
(Id
) loop
4041 Get_Name_String
(Chars
(Id
));
4042 if Is_Bad_Spelling_Of
4043 (Name_Buffer
(1 .. Name_Len
), S
)
4044 and then not Is_Internal_Name
(Chars
(Id
))
4047 ("possible misspelling of&", Selector
, Id
);
4055 -- Specialize the message if this may be an instantiation
4056 -- of a child unit that was not mentioned in the context.
4058 if Nkind
(Parent
(N
)) = N_Package_Instantiation
4059 and then Is_Generic_Instance
(Entity
(Prefix
(N
)))
4060 and then Is_Compilation_Unit
4061 (Generic_Parent
(Parent
(Entity
(Prefix
(N
)))))
4064 ("\possible missing with clause on child unit&",
4075 if Comes_From_Source
(N
)
4076 and then Is_Remote_Access_To_Subprogram_Type
(Id
)
4077 and then Present
(Equivalent_Type
(Id
))
4079 -- If we are not actually generating distribution code (i.e.
4080 -- the current PCS is the dummy non-distributed version), then
4081 -- the Equivalent_Type will be missing, and Id should be treated
4082 -- as a regular access-to-subprogram type.
4084 Id
:= Equivalent_Type
(Id
);
4085 Set_Chars
(Selector
, Chars
(Id
));
4088 -- Ada 2005 (AI-50217): Check usage of entities in limited withed units
4090 if Ekind
(P_Name
) = E_Package
4091 and then From_With_Type
(P_Name
)
4093 if From_With_Type
(Id
)
4094 or else Is_Type
(Id
)
4095 or else Ekind
(Id
) = E_Package
4100 ("limited withed package can only be used to access "
4101 & " incomplete types",
4106 if Is_Task_Type
(P_Name
)
4107 and then ((Ekind
(Id
) = E_Entry
4108 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
)
4110 (Ekind
(Id
) = E_Entry_Family
4112 Nkind
(Parent
(Parent
(N
))) /= N_Attribute_Reference
))
4114 -- It is an entry call after all, either to the current task
4115 -- (which will deadlock) or to an enclosing task.
4117 Analyze_Selected_Component
(N
);
4121 Change_Selected_Component_To_Expanded_Name
(N
);
4123 -- Do style check and generate reference, but skip both steps if this
4124 -- entity has homonyms, since we may not have the right homonym set
4125 -- yet. The proper homonym will be set during the resolve phase.
4127 if Has_Homonym
(Id
) then
4130 Set_Entity_With_Style_Check
(N
, Id
);
4131 Generate_Reference
(Id
, N
);
4134 if Is_Type
(Id
) then
4137 Set_Etype
(N
, Get_Full_View
(Etype
(Id
)));
4140 -- If the Ekind of the entity is Void, it means that all homonyms
4141 -- are hidden from all visibility (RM 8.3(5,14-20)).
4143 if Ekind
(Id
) = E_Void
then
4144 Premature_Usage
(N
);
4146 elsif Is_Overloadable
(Id
)
4147 and then Present
(Homonym
(Id
))
4150 H
: Entity_Id
:= Homonym
(Id
);
4153 while Present
(H
) loop
4154 if Scope
(H
) = Scope
(Id
)
4157 or else Is_Immediately_Visible
(H
))
4159 Collect_Interps
(N
);
4166 -- If an extension of System is present, collect possible
4167 -- explicit overloadings declared in the extension.
4169 if Chars
(P_Name
) = Name_System
4170 and then Scope
(P_Name
) = Standard_Standard
4171 and then Present
(System_Extend_Unit
)
4172 and then Present_System_Aux
(N
)
4174 H
:= Current_Entity
(Id
);
4176 while Present
(H
) loop
4177 if Scope
(H
) = System_Aux_Id
then
4178 Add_One_Interp
(N
, H
, Etype
(H
));
4187 if Nkind
(Selector_Name
(N
)) = N_Operator_Symbol
4188 and then Scope
(Id
) /= Standard_Standard
4190 -- In addition to user-defined operators in the given scope,
4191 -- there may be an implicit instance of the predefined
4192 -- operator. The operator (defined in Standard) is found
4193 -- in Has_Implicit_Operator, and added to the interpretations.
4194 -- Procedure Add_One_Interp will determine which hides which.
4196 if Has_Implicit_Operator
(N
) then
4200 end Find_Expanded_Name
;
4202 -------------------------
4203 -- Find_Renamed_Entity --
4204 -------------------------
4206 function Find_Renamed_Entity
4210 Is_Actual
: Boolean := False) return Entity_Id
4213 I1
: Interp_Index
:= 0; -- Suppress junk warnings
4219 function Enclosing_Instance
return Entity_Id
;
4220 -- If the renaming determines the entity for the default of a formal
4221 -- subprogram nested within another instance, choose the innermost
4222 -- candidate. This is because if the formal has a box, and we are within
4223 -- an enclosing instance where some candidate interpretations are local
4224 -- to this enclosing instance, we know that the default was properly
4225 -- resolved when analyzing the generic, so we prefer the local
4226 -- candidates to those that are external. This is not always the case
4227 -- but is a reasonable heuristic on the use of nested generics.
4228 -- The proper solution requires a full renaming model.
4230 function Is_Visible_Operation
(Op
: Entity_Id
) return Boolean;
4231 -- If the renamed entity is an implicit operator, check whether it is
4232 -- visible because its operand type is properly visible. This
4233 -- check applies to explicit renamed entities that appear in the
4234 -- source in a renaming declaration or a formal subprogram instance,
4235 -- but not to default generic actuals with a name.
4237 function Report_Overload
return Entity_Id
;
4238 -- List possible interpretations, and specialize message in the
4239 -- case of a generic actual.
4241 function Within
(Inner
, Outer
: Entity_Id
) return Boolean;
4242 -- Determine whether a candidate subprogram is defined within
4243 -- the enclosing instance. If yes, it has precedence over outer
4246 ------------------------
4247 -- Enclosing_Instance --
4248 ------------------------
4250 function Enclosing_Instance
return Entity_Id
is
4254 if not Is_Generic_Instance
(Current_Scope
)
4255 and then not Is_Actual
4260 S
:= Scope
(Current_Scope
);
4262 while S
/= Standard_Standard
loop
4264 if Is_Generic_Instance
(S
) then
4272 end Enclosing_Instance
;
4274 --------------------------
4275 -- Is_Visible_Operation --
4276 --------------------------
4278 function Is_Visible_Operation
(Op
: Entity_Id
) return Boolean is
4284 if Ekind
(Op
) /= E_Operator
4285 or else Scope
(Op
) /= Standard_Standard
4286 or else (In_Instance
4289 or else Present
(Enclosing_Instance
)))
4294 -- For a fixed point type operator, check the resulting type,
4295 -- because it may be a mixed mode integer * fixed operation.
4297 if Present
(Next_Formal
(First_Formal
(New_S
)))
4298 and then Is_Fixed_Point_Type
(Etype
(New_S
))
4300 Typ
:= Etype
(New_S
);
4302 Typ
:= Etype
(First_Formal
(New_S
));
4305 Btyp
:= Base_Type
(Typ
);
4307 if Nkind
(Nam
) /= N_Expanded_Name
then
4308 return (In_Open_Scopes
(Scope
(Btyp
))
4309 or else Is_Potentially_Use_Visible
(Btyp
)
4310 or else In_Use
(Btyp
)
4311 or else In_Use
(Scope
(Btyp
)));
4314 Scop
:= Entity
(Prefix
(Nam
));
4316 if Ekind
(Scop
) = E_Package
4317 and then Present
(Renamed_Object
(Scop
))
4319 Scop
:= Renamed_Object
(Scop
);
4322 -- Operator is visible if prefix of expanded name denotes
4323 -- scope of type, or else type type is defined in System_Aux
4324 -- and the prefix denotes System.
4326 return Scope
(Btyp
) = Scop
4327 or else (Scope
(Btyp
) = System_Aux_Id
4328 and then Scope
(Scope
(Btyp
)) = Scop
);
4331 end Is_Visible_Operation
;
4337 function Within
(Inner
, Outer
: Entity_Id
) return Boolean is
4338 Sc
: Entity_Id
:= Scope
(Inner
);
4341 while Sc
/= Standard_Standard
loop
4352 ---------------------
4353 -- Report_Overload --
4354 ---------------------
4356 function Report_Overload
return Entity_Id
is
4360 ("ambiguous actual subprogram&, " &
4361 "possible interpretations:", N
, Nam
);
4364 ("ambiguous subprogram, " &
4365 "possible interpretations:", N
);
4368 List_Interps
(Nam
, N
);
4370 end Report_Overload
;
4372 -- Start of processing for Find_Renamed_Entry
4376 Candidate_Renaming
:= Empty
;
4378 if not Is_Overloaded
(Nam
) then
4379 if Entity_Matches_Spec
(Entity
(Nam
), New_S
)
4380 and then Is_Visible_Operation
(Entity
(Nam
))
4382 Old_S
:= Entity
(Nam
);
4385 Present
(First_Formal
(Entity
(Nam
)))
4386 and then Present
(First_Formal
(New_S
))
4387 and then (Base_Type
(Etype
(First_Formal
(Entity
(Nam
))))
4388 = Base_Type
(Etype
(First_Formal
(New_S
))))
4390 Candidate_Renaming
:= Entity
(Nam
);
4394 Get_First_Interp
(Nam
, Ind
, It
);
4396 while Present
(It
.Nam
) loop
4398 if Entity_Matches_Spec
(It
.Nam
, New_S
)
4399 and then Is_Visible_Operation
(It
.Nam
)
4401 if Old_S
/= Any_Id
then
4403 -- Note: The call to Disambiguate only happens if a
4404 -- previous interpretation was found, in which case I1
4405 -- has received a value.
4407 It1
:= Disambiguate
(Nam
, I1
, Ind
, Etype
(Old_S
));
4409 if It1
= No_Interp
then
4411 Inst
:= Enclosing_Instance
;
4413 if Present
(Inst
) then
4415 if Within
(It
.Nam
, Inst
) then
4418 elsif Within
(Old_S
, Inst
) then
4422 return Report_Overload
;
4426 return Report_Overload
;
4440 Present
(First_Formal
(It
.Nam
))
4441 and then Present
(First_Formal
(New_S
))
4442 and then (Base_Type
(Etype
(First_Formal
(It
.Nam
)))
4443 = Base_Type
(Etype
(First_Formal
(New_S
))))
4445 Candidate_Renaming
:= It
.Nam
;
4448 Get_Next_Interp
(Ind
, It
);
4451 Set_Entity
(Nam
, Old_S
);
4452 Set_Is_Overloaded
(Nam
, False);
4456 end Find_Renamed_Entity
;
4458 -----------------------------
4459 -- Find_Selected_Component --
4460 -----------------------------
4462 procedure Find_Selected_Component
(N
: Node_Id
) is
4463 P
: constant Node_Id
:= Prefix
(N
);
4466 -- Entity denoted by prefix
4476 if Nkind
(P
) = N_Error
then
4479 -- If the selector already has an entity, the node has been
4480 -- constructed in the course of expansion, and is known to be
4481 -- valid. Do not verify that it is defined for the type (it may
4482 -- be a private component used in the expansion of record equality).
4484 elsif Present
(Entity
(Selector_Name
(N
))) then
4487 or else Etype
(N
) = Any_Type
4490 Sel_Name
: constant Node_Id
:= Selector_Name
(N
);
4491 Selector
: constant Entity_Id
:= Entity
(Sel_Name
);
4495 Set_Etype
(Sel_Name
, Etype
(Selector
));
4497 if not Is_Entity_Name
(P
) then
4501 -- Build an actual subtype except for the first parameter
4502 -- of an init proc, where this actual subtype is by
4503 -- definition incorrect, since the object is uninitialized
4504 -- (and does not even have defined discriminants etc.)
4506 if Is_Entity_Name
(P
)
4507 and then Ekind
(Entity
(P
)) = E_Function
4509 Nam
:= New_Copy
(P
);
4511 if Is_Overloaded
(P
) then
4512 Save_Interps
(P
, Nam
);
4516 Make_Function_Call
(Sloc
(P
), Name
=> Nam
));
4518 Analyze_Selected_Component
(N
);
4521 elsif Ekind
(Selector
) = E_Component
4522 and then (not Is_Entity_Name
(P
)
4523 or else Chars
(Entity
(P
)) /= Name_uInit
)
4526 Build_Actual_Subtype_Of_Component
(
4527 Etype
(Selector
), N
);
4532 if No
(C_Etype
) then
4533 C_Etype
:= Etype
(Selector
);
4535 Insert_Action
(N
, C_Etype
);
4536 C_Etype
:= Defining_Identifier
(C_Etype
);
4539 Set_Etype
(N
, C_Etype
);
4542 -- If this is the name of an entry or protected operation, and
4543 -- the prefix is an access type, insert an explicit dereference,
4544 -- so that entry calls are treated uniformly.
4546 if Is_Access_Type
(Etype
(P
))
4547 and then Is_Concurrent_Type
(Designated_Type
(Etype
(P
)))
4550 New_P
: constant Node_Id
:=
4551 Make_Explicit_Dereference
(Sloc
(P
),
4552 Prefix
=> Relocate_Node
(P
));
4555 Set_Etype
(P
, Designated_Type
(Etype
(Prefix
(P
))));
4559 -- If the selected component appears within a default expression
4560 -- and it has an actual subtype, the pre-analysis has not yet
4561 -- completed its analysis, because Insert_Actions is disabled in
4562 -- that context. Within the init proc of the enclosing type we
4563 -- must complete this analysis, if an actual subtype was created.
4565 elsif Inside_Init_Proc
then
4567 Typ
: constant Entity_Id
:= Etype
(N
);
4568 Decl
: constant Node_Id
:= Declaration_Node
(Typ
);
4571 if Nkind
(Decl
) = N_Subtype_Declaration
4572 and then not Analyzed
(Decl
)
4573 and then Is_List_Member
(Decl
)
4574 and then No
(Parent
(Decl
))
4577 Insert_Action
(N
, Decl
);
4584 elsif Is_Entity_Name
(P
) then
4585 P_Name
:= Entity
(P
);
4587 -- The prefix may denote an enclosing type which is the completion
4588 -- of an incomplete type declaration.
4590 if Is_Type
(P_Name
) then
4591 Set_Entity
(P
, Get_Full_View
(P_Name
));
4592 Set_Etype
(P
, Entity
(P
));
4593 P_Name
:= Entity
(P
);
4596 P_Type
:= Base_Type
(Etype
(P
));
4598 if Debug_Flag_E
then
4599 Write_Str
("Found prefix type to be ");
4600 Write_Entity_Info
(P_Type
, " "); Write_Eol
;
4603 -- First check for components of a record object (not the
4604 -- result of a call, which is handled below).
4606 if Is_Appropriate_For_Record
(P_Type
)
4607 and then not Is_Overloadable
(P_Name
)
4608 and then not Is_Type
(P_Name
)
4610 -- Selected component of record. Type checking will validate
4611 -- name of selector.
4613 Analyze_Selected_Component
(N
);
4615 elsif Is_Appropriate_For_Entry_Prefix
(P_Type
)
4616 and then not In_Open_Scopes
(P_Name
)
4617 and then (not Is_Concurrent_Type
(Etype
(P_Name
))
4618 or else not In_Open_Scopes
(Etype
(P_Name
)))
4620 -- Call to protected operation or entry. Type checking is
4621 -- needed on the prefix.
4623 Analyze_Selected_Component
(N
);
4625 elsif (In_Open_Scopes
(P_Name
)
4626 and then Ekind
(P_Name
) /= E_Void
4627 and then not Is_Overloadable
(P_Name
))
4628 or else (Is_Concurrent_Type
(Etype
(P_Name
))
4629 and then In_Open_Scopes
(Etype
(P_Name
)))
4631 -- Prefix denotes an enclosing loop, block, or task, i.e. an
4632 -- enclosing construct that is not a subprogram or accept.
4634 Find_Expanded_Name
(N
);
4636 elsif Ekind
(P_Name
) = E_Package
then
4637 Find_Expanded_Name
(N
);
4639 elsif Is_Overloadable
(P_Name
) then
4641 -- The subprogram may be a renaming (of an enclosing scope) as
4642 -- in the case of the name of the generic within an instantiation.
4644 if (Ekind
(P_Name
) = E_Procedure
4645 or else Ekind
(P_Name
) = E_Function
)
4646 and then Present
(Alias
(P_Name
))
4647 and then Is_Generic_Instance
(Alias
(P_Name
))
4649 P_Name
:= Alias
(P_Name
);
4652 if Is_Overloaded
(P
) then
4654 -- The prefix must resolve to a unique enclosing construct
4657 Found
: Boolean := False;
4662 Get_First_Interp
(P
, Ind
, It
);
4664 while Present
(It
.Nam
) loop
4666 if In_Open_Scopes
(It
.Nam
) then
4669 "prefix must be unique enclosing scope", N
);
4670 Set_Entity
(N
, Any_Id
);
4671 Set_Etype
(N
, Any_Type
);
4680 Get_Next_Interp
(Ind
, It
);
4685 if In_Open_Scopes
(P_Name
) then
4686 Set_Entity
(P
, P_Name
);
4687 Set_Is_Overloaded
(P
, False);
4688 Find_Expanded_Name
(N
);
4691 -- If no interpretation as an expanded name is possible, it
4692 -- must be a selected component of a record returned by a
4693 -- function call. Reformat prefix as a function call, the
4694 -- rest is done by type resolution. If the prefix is a
4695 -- procedure or entry, as is P.X; this is an error.
4697 if Ekind
(P_Name
) /= E_Function
4698 and then (not Is_Overloaded
(P
)
4700 Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
)
4703 -- Prefix may mention a package that is hidden by a local
4704 -- declaration: let the user know. Scan the full homonym
4705 -- chain, the candidate package may be anywhere on it.
4707 if Present
(Homonym
(Current_Entity
(P_Name
))) then
4709 P_Name
:= Current_Entity
(P_Name
);
4711 while Present
(P_Name
) loop
4712 exit when Ekind
(P_Name
) = E_Package
;
4713 P_Name
:= Homonym
(P_Name
);
4716 if Present
(P_Name
) then
4717 Error_Msg_Sloc
:= Sloc
(Entity
(Prefix
(N
)));
4720 ("package& is hidden by declaration#",
4723 Set_Entity
(Prefix
(N
), P_Name
);
4724 Find_Expanded_Name
(N
);
4727 P_Name
:= Entity
(Prefix
(N
));
4732 ("invalid prefix in selected component&", N
, P_Name
);
4733 Change_Selected_Component_To_Expanded_Name
(N
);
4734 Set_Entity
(N
, Any_Id
);
4735 Set_Etype
(N
, Any_Type
);
4738 Nam
:= New_Copy
(P
);
4739 Save_Interps
(P
, Nam
);
4741 Make_Function_Call
(Sloc
(P
), Name
=> Nam
));
4743 Analyze_Selected_Component
(N
);
4747 -- Remaining cases generate various error messages
4750 -- Format node as expanded name, to avoid cascaded errors
4752 Change_Selected_Component_To_Expanded_Name
(N
);
4753 Set_Entity
(N
, Any_Id
);
4754 Set_Etype
(N
, Any_Type
);
4756 -- Issue error message, but avoid this if error issued already.
4757 -- Use identifier of prefix if one is available.
4759 if P_Name
= Any_Id
then
4762 elsif Ekind
(P_Name
) = E_Void
then
4763 Premature_Usage
(P
);
4765 elsif Nkind
(P
) /= N_Attribute_Reference
then
4767 "invalid prefix in selected component&", P
);
4769 if Is_Access_Type
(P_Type
)
4770 and then Ekind
(Designated_Type
(P_Type
)) = E_Incomplete_Type
4773 ("\dereference must not be of an incomplete type " &
4774 "('R'M 3.10.1)", P
);
4779 "invalid prefix in selected component", P
);
4784 -- If prefix is not the name of an entity, it must be an expression,
4785 -- whose type is appropriate for a record. This is determined by
4788 Analyze_Selected_Component
(N
);
4790 end Find_Selected_Component
;
4796 procedure Find_Type
(N
: Node_Id
) is
4806 elsif Nkind
(N
) = N_Attribute_Reference
then
4808 -- Class attribute. This is only valid in Ada 95 mode, but we don't
4809 -- do a check, since the tagged type referenced could only exist if
4810 -- we were in 95 mode when it was declared (or, if we were in Ada
4811 -- 83 mode, then an error message would already have been issued).
4813 if Attribute_Name
(N
) = Name_Class
then
4814 Check_Restriction
(No_Dispatch
, N
);
4815 Find_Type
(Prefix
(N
));
4817 -- Propagate error from bad prefix
4819 if Etype
(Prefix
(N
)) = Any_Type
then
4820 Set_Entity
(N
, Any_Type
);
4821 Set_Etype
(N
, Any_Type
);
4825 T
:= Base_Type
(Entity
(Prefix
(N
)));
4827 -- Case type is not known to be tagged. Its appearance in
4828 -- the prefix of the 'Class attribute indicates that the full
4829 -- view will be tagged.
4831 if not Is_Tagged_Type
(T
) then
4832 if Ekind
(T
) = E_Incomplete_Type
then
4834 -- It is legal to denote the class type of an incomplete
4835 -- type. The full type will have to be tagged, of course.
4837 Set_Is_Tagged_Type
(T
);
4838 Set_Primitive_Operations
(T
, New_Elmt_List
);
4839 Make_Class_Wide_Type
(T
);
4840 Set_Entity
(N
, Class_Wide_Type
(T
));
4841 Set_Etype
(N
, Class_Wide_Type
(T
));
4843 elsif Ekind
(T
) = E_Private_Type
4844 and then not Is_Generic_Type
(T
)
4845 and then In_Private_Part
(Scope
(T
))
4847 -- The Class attribute can be applied to an untagged
4848 -- private type fulfilled by a tagged type prior to
4849 -- the full type declaration (but only within the
4850 -- parent package's private part). Create the class-wide
4851 -- type now and check that the full type is tagged
4852 -- later during its analysis. Note that we do not
4853 -- mark the private type as tagged, unlike the case
4854 -- of incomplete types, because the type must still
4855 -- appear untagged to outside units.
4857 if No
(Class_Wide_Type
(T
)) then
4858 Make_Class_Wide_Type
(T
);
4861 Set_Entity
(N
, Class_Wide_Type
(T
));
4862 Set_Etype
(N
, Class_Wide_Type
(T
));
4865 -- Should we introduce a type Any_Tagged and use
4866 -- Wrong_Type here, it would be a bit more consistent???
4869 ("tagged type required, found}",
4870 Prefix
(N
), First_Subtype
(T
));
4871 Set_Entity
(N
, Any_Type
);
4875 -- Case of tagged type
4878 if Is_Concurrent_Type
(T
) then
4879 if No
(Corresponding_Record_Type
(Entity
(Prefix
(N
)))) then
4881 -- Previous error. Use current type, which at least
4882 -- provides some operations.
4884 C
:= Entity
(Prefix
(N
));
4887 C
:= Class_Wide_Type
4888 (Corresponding_Record_Type
(Entity
(Prefix
(N
))));
4892 C
:= Class_Wide_Type
(Entity
(Prefix
(N
)));
4895 Set_Entity_With_Style_Check
(N
, C
);
4896 Generate_Reference
(C
, N
);
4900 -- Base attribute, not allowed in Ada 83
4902 elsif Attribute_Name
(N
) = Name_Base
then
4903 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4905 ("(Ada 83) Base attribute not allowed in subtype mark", N
);
4908 Find_Type
(Prefix
(N
));
4909 Typ
:= Entity
(Prefix
(N
));
4911 if Ada_Version
>= Ada_95
4912 and then not Is_Scalar_Type
(Typ
)
4913 and then not Is_Generic_Type
(Typ
)
4916 ("prefix of Base attribute must be scalar type",
4919 elsif Sloc
(Typ
) = Standard_Location
4920 and then Base_Type
(Typ
) = Typ
4921 and then Warn_On_Redundant_Constructs
4924 ("?redudant attribute, & is its own base type", N
, Typ
);
4927 T
:= Base_Type
(Typ
);
4929 -- Rewrite attribute reference with type itself (see similar
4930 -- processing in Analyze_Attribute, case Base). Preserve
4931 -- prefix if present, for other legality checks.
4933 if Nkind
(Prefix
(N
)) = N_Expanded_Name
then
4935 Make_Expanded_Name
(Sloc
(N
),
4936 Chars
=> Chars
(Entity
(N
)),
4937 Prefix
=> New_Copy
(Prefix
(Prefix
(N
))),
4939 New_Reference_To
(Entity
(N
), Sloc
(N
))));
4943 New_Reference_To
(Entity
(N
), Sloc
(N
)));
4950 elsif Attribute_Name
(N
) = Name_Stub_Type
then
4952 -- This is handled in Analyze_Attribute
4956 -- All other attributes are invalid in a subtype mark
4959 Error_Msg_N
("invalid attribute in subtype mark", N
);
4965 if Is_Entity_Name
(N
) then
4966 T_Name
:= Entity
(N
);
4968 Error_Msg_N
("subtype mark required in this context", N
);
4969 Set_Etype
(N
, Any_Type
);
4973 if T_Name
= Any_Id
or else Etype
(N
) = Any_Type
then
4975 -- Undefined id. Make it into a valid type
4977 Set_Entity
(N
, Any_Type
);
4979 elsif not Is_Type
(T_Name
)
4980 and then T_Name
/= Standard_Void_Type
4982 Error_Msg_Sloc
:= Sloc
(T_Name
);
4983 Error_Msg_N
("subtype mark required in this context", N
);
4984 Error_Msg_NE
("\\found & declared#", N
, T_Name
);
4985 Set_Entity
(N
, Any_Type
);
4988 T_Name
:= Get_Full_View
(T_Name
);
4990 if In_Open_Scopes
(T_Name
) then
4991 if Ekind
(Base_Type
(T_Name
)) = E_Task_Type
then
4993 -- In Ada 2005, a task name can be used in an access
4994 -- definition within its own body.
4996 if Ada_Version
>= Ada_05
4997 and then Nkind
(Parent
(N
)) = N_Access_Definition
4999 Set_Entity
(N
, T_Name
);
5000 Set_Etype
(N
, T_Name
);
5005 ("task type cannot be used as type mark " &
5006 "within its own body", N
);
5009 Error_Msg_N
("type declaration cannot refer to itself", N
);
5012 Set_Etype
(N
, Any_Type
);
5013 Set_Entity
(N
, Any_Type
);
5014 Set_Error_Posted
(T_Name
);
5018 Set_Entity
(N
, T_Name
);
5019 Set_Etype
(N
, T_Name
);
5023 if Present
(Etype
(N
)) and then Comes_From_Source
(N
) then
5024 if Is_Fixed_Point_Type
(Etype
(N
)) then
5025 Check_Restriction
(No_Fixed_Point
, N
);
5026 elsif Is_Floating_Point_Type
(Etype
(N
)) then
5027 Check_Restriction
(No_Floating_Point
, N
);
5036 function Get_Full_View
(T_Name
: Entity_Id
) return Entity_Id
is
5038 if Ekind
(T_Name
) = E_Incomplete_Type
5039 and then Present
(Full_View
(T_Name
))
5041 return Full_View
(T_Name
);
5043 elsif Is_Class_Wide_Type
(T_Name
)
5044 and then Ekind
(Root_Type
(T_Name
)) = E_Incomplete_Type
5045 and then Present
(Full_View
(Root_Type
(T_Name
)))
5047 return Class_Wide_Type
(Full_View
(Root_Type
(T_Name
)));
5054 ------------------------------------
5055 -- Has_Implicit_Character_Literal --
5056 ------------------------------------
5058 function Has_Implicit_Character_Literal
(N
: Node_Id
) return Boolean is
5060 Found
: Boolean := False;
5061 P
: constant Entity_Id
:= Entity
(Prefix
(N
));
5062 Priv_Id
: Entity_Id
:= Empty
;
5065 if Ekind
(P
) = E_Package
5066 and then not In_Open_Scopes
(P
)
5068 Priv_Id
:= First_Private_Entity
(P
);
5071 if P
= Standard_Standard
then
5072 Change_Selected_Component_To_Expanded_Name
(N
);
5073 Rewrite
(N
, Selector_Name
(N
));
5075 Set_Etype
(Original_Node
(N
), Standard_Character
);
5079 Id
:= First_Entity
(P
);
5082 and then Id
/= Priv_Id
5084 if Is_Character_Type
(Id
)
5085 and then (Root_Type
(Id
) = Standard_Character
5086 or else Root_Type
(Id
) = Standard_Wide_Character
5087 or else Root_Type
(Id
) = Standard_Wide_Wide_Character
)
5088 and then Id
= Base_Type
(Id
)
5090 -- We replace the node with the literal itself, resolve as a
5091 -- character, and set the type correctly.
5094 Change_Selected_Component_To_Expanded_Name
(N
);
5095 Rewrite
(N
, Selector_Name
(N
));
5098 Set_Etype
(Original_Node
(N
), Id
);
5102 -- More than one type derived from Character in given scope.
5103 -- Collect all possible interpretations.
5105 Add_One_Interp
(N
, Id
, Id
);
5113 end Has_Implicit_Character_Literal
;
5115 ----------------------
5116 -- Has_Private_With --
5117 ----------------------
5119 function Has_Private_With
(E
: Entity_Id
) return Boolean is
5120 Comp_Unit
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
5124 Item
:= First
(Context_Items
(Comp_Unit
));
5125 while Present
(Item
) loop
5126 if Nkind
(Item
) = N_With_Clause
5127 and then Private_Present
(Item
)
5128 and then Entity
(Name
(Item
)) = E
5137 end Has_Private_With
;
5139 ---------------------------
5140 -- Has_Implicit_Operator --
5141 ---------------------------
5143 function Has_Implicit_Operator
(N
: Node_Id
) return Boolean is
5144 Op_Id
: constant Name_Id
:= Chars
(Selector_Name
(N
));
5145 P
: constant Entity_Id
:= Entity
(Prefix
(N
));
5147 Priv_Id
: Entity_Id
:= Empty
;
5149 procedure Add_Implicit_Operator
5151 Op_Type
: Entity_Id
:= Empty
);
5152 -- Add implicit interpretation to node N, using the type for which
5153 -- a predefined operator exists. If the operator yields a boolean
5154 -- type, the Operand_Type is implicitly referenced by the operator,
5155 -- and a reference to it must be generated.
5157 ---------------------------
5158 -- Add_Implicit_Operator --
5159 ---------------------------
5161 procedure Add_Implicit_Operator
5163 Op_Type
: Entity_Id
:= Empty
)
5165 Predef_Op
: Entity_Id
;
5168 Predef_Op
:= Current_Entity
(Selector_Name
(N
));
5170 while Present
(Predef_Op
)
5171 and then Scope
(Predef_Op
) /= Standard_Standard
5173 Predef_Op
:= Homonym
(Predef_Op
);
5176 if Nkind
(N
) = N_Selected_Component
then
5177 Change_Selected_Component_To_Expanded_Name
(N
);
5180 Add_One_Interp
(N
, Predef_Op
, T
);
5182 -- For operators with unary and binary interpretations, add both
5184 if Present
(Homonym
(Predef_Op
)) then
5185 Add_One_Interp
(N
, Homonym
(Predef_Op
), T
);
5188 -- The node is a reference to a predefined operator, and
5189 -- an implicit reference to the type of its operands.
5191 if Present
(Op_Type
) then
5192 Generate_Operator_Reference
(N
, Op_Type
);
5194 Generate_Operator_Reference
(N
, T
);
5196 end Add_Implicit_Operator
;
5198 -- Start of processing for Has_Implicit_Operator
5202 if Ekind
(P
) = E_Package
5203 and then not In_Open_Scopes
(P
)
5205 Priv_Id
:= First_Private_Entity
(P
);
5208 Id
:= First_Entity
(P
);
5212 -- Boolean operators: an implicit declaration exists if the scope
5213 -- contains a declaration for a derived Boolean type, or for an
5214 -- array of Boolean type.
5216 when Name_Op_And | Name_Op_Not | Name_Op_Or | Name_Op_Xor
=>
5218 while Id
/= Priv_Id
loop
5220 if Valid_Boolean_Arg
(Id
)
5221 and then Id
= Base_Type
(Id
)
5223 Add_Implicit_Operator
(Id
);
5230 -- Equality: look for any non-limited type (result is Boolean)
5232 when Name_Op_Eq | Name_Op_Ne
=>
5234 while Id
/= Priv_Id
loop
5237 and then not Is_Limited_Type
(Id
)
5238 and then Id
= Base_Type
(Id
)
5240 Add_Implicit_Operator
(Standard_Boolean
, Id
);
5247 -- Comparison operators: scalar type, or array of scalar
5249 when Name_Op_Lt | Name_Op_Le | Name_Op_Gt | Name_Op_Ge
=>
5251 while Id
/= Priv_Id
loop
5252 if (Is_Scalar_Type
(Id
)
5253 or else (Is_Array_Type
(Id
)
5254 and then Is_Scalar_Type
(Component_Type
(Id
))))
5255 and then Id
= Base_Type
(Id
)
5257 Add_Implicit_Operator
(Standard_Boolean
, Id
);
5264 -- Arithmetic operators: any numeric type
5275 while Id
/= Priv_Id
loop
5276 if Is_Numeric_Type
(Id
)
5277 and then Id
= Base_Type
(Id
)
5279 Add_Implicit_Operator
(Id
);
5286 -- Concatenation: any one-dimensional array type
5288 when Name_Op_Concat
=>
5290 while Id
/= Priv_Id
loop
5291 if Is_Array_Type
(Id
) and then Number_Dimensions
(Id
) = 1
5292 and then Id
= Base_Type
(Id
)
5294 Add_Implicit_Operator
(Id
);
5301 -- What is the others condition here? Should we be using a
5302 -- subtype of Name_Id that would restrict to operators ???
5304 when others => null;
5308 -- If we fall through, then we do not have an implicit operator
5312 end Has_Implicit_Operator
;
5314 --------------------
5315 -- In_Open_Scopes --
5316 --------------------
5318 function In_Open_Scopes
(S
: Entity_Id
) return Boolean is
5320 -- Several scope stacks are maintained by Scope_Stack. The base of the
5321 -- currently active scope stack is denoted by the Is_Active_Stack_Base
5322 -- flag in the scope stack entry. Note that the scope stacks used to
5323 -- simply be delimited implicitly by the presence of Standard_Standard
5324 -- at their base, but there now are cases where this is not sufficient
5325 -- because Standard_Standard actually may appear in the middle of the
5326 -- active set of scopes.
5328 for J
in reverse 0 .. Scope_Stack
.Last
loop
5329 if Scope_Stack
.Table
(J
).Entity
= S
then
5333 -- Check Is_Active_Stack_Base to tell us when to stop, as there are
5334 -- cases where Standard_Standard appears in the middle of the active
5335 -- set of scopes. This affects the declaration and overriding of
5336 -- private inherited operations in instantiations of generic child
5339 exit when Scope_Stack
.Table
(J
).Is_Active_Stack_Base
;
5345 -----------------------------
5346 -- Inherit_Renamed_Profile --
5347 -----------------------------
5349 procedure Inherit_Renamed_Profile
(New_S
: Entity_Id
; Old_S
: Entity_Id
) is
5356 if Ekind
(Old_S
) = E_Operator
then
5358 New_F
:= First_Formal
(New_S
);
5360 while Present
(New_F
) loop
5361 Set_Etype
(New_F
, Base_Type
(Etype
(New_F
)));
5362 Next_Formal
(New_F
);
5365 Set_Etype
(New_S
, Base_Type
(Etype
(New_S
)));
5368 New_F
:= First_Formal
(New_S
);
5369 Old_F
:= First_Formal
(Old_S
);
5371 while Present
(New_F
) loop
5372 New_T
:= Etype
(New_F
);
5373 Old_T
:= Etype
(Old_F
);
5375 -- If the new type is a renaming of the old one, as is the
5376 -- case for actuals in instances, retain its name, to simplify
5377 -- later disambiguation.
5379 if Nkind
(Parent
(New_T
)) = N_Subtype_Declaration
5380 and then Is_Entity_Name
(Subtype_Indication
(Parent
(New_T
)))
5381 and then Entity
(Subtype_Indication
(Parent
(New_T
))) = Old_T
5385 Set_Etype
(New_F
, Old_T
);
5388 Next_Formal
(New_F
);
5389 Next_Formal
(Old_F
);
5392 if Ekind
(Old_S
) = E_Function
5393 or else Ekind
(Old_S
) = E_Enumeration_Literal
5395 Set_Etype
(New_S
, Etype
(Old_S
));
5398 end Inherit_Renamed_Profile
;
5404 procedure Initialize
is
5409 -------------------------
5410 -- Install_Use_Clauses --
5411 -------------------------
5413 procedure Install_Use_Clauses
5415 Force_Installation
: Boolean := False)
5417 U
: Node_Id
:= Clause
;
5422 while Present
(U
) loop
5424 -- Case of USE package
5426 if Nkind
(U
) = N_Use_Package_Clause
then
5427 P
:= First
(Names
(U
));
5429 while Present
(P
) loop
5432 if Ekind
(Id
) = E_Package
then
5435 Note_Redundant_Use
(P
);
5437 elsif Present
(Renamed_Object
(Id
))
5438 and then In_Use
(Renamed_Object
(Id
))
5440 Note_Redundant_Use
(P
);
5442 elsif Force_Installation
or else Applicable_Use
(P
) then
5443 Use_One_Package
(Id
, U
);
5454 P
:= First
(Subtype_Marks
(U
));
5456 while Present
(P
) loop
5457 if not Is_Entity_Name
(P
)
5458 or else No
(Entity
(P
))
5462 elsif Entity
(P
) /= Any_Type
then
5470 Next_Use_Clause
(U
);
5472 end Install_Use_Clauses
;
5474 -------------------------------------
5475 -- Is_Appropriate_For_Entry_Prefix --
5476 -------------------------------------
5478 function Is_Appropriate_For_Entry_Prefix
(T
: Entity_Id
) return Boolean is
5479 P_Type
: Entity_Id
:= T
;
5482 if Is_Access_Type
(P_Type
) then
5483 P_Type
:= Designated_Type
(P_Type
);
5486 return Is_Task_Type
(P_Type
) or else Is_Protected_Type
(P_Type
);
5487 end Is_Appropriate_For_Entry_Prefix
;
5489 -------------------------------
5490 -- Is_Appropriate_For_Record --
5491 -------------------------------
5493 function Is_Appropriate_For_Record
(T
: Entity_Id
) return Boolean is
5495 function Has_Components
(T1
: Entity_Id
) return Boolean;
5496 -- Determine if given type has components (i.e. is either a record
5497 -- type or a type that has discriminants).
5499 function Has_Components
(T1
: Entity_Id
) return Boolean is
5501 return Is_Record_Type
(T1
)
5502 or else (Is_Private_Type
(T1
) and then Has_Discriminants
(T1
))
5503 or else (Is_Task_Type
(T1
) and then Has_Discriminants
(T1
));
5506 -- Start of processing for Is_Appropriate_For_Record
5511 and then (Has_Components
(T
)
5512 or else (Is_Access_Type
(T
)
5514 Has_Components
(Designated_Type
(T
))));
5515 end Is_Appropriate_For_Record
;
5521 procedure New_Scope
(S
: Entity_Id
) is
5525 if Ekind
(S
) = E_Void
then
5528 -- Set scope depth if not a non-concurrent type, and we have not
5529 -- yet set the scope depth. This means that we have the first
5530 -- occurrence of the scope, and this is where the depth is set.
5532 elsif (not Is_Type
(S
) or else Is_Concurrent_Type
(S
))
5533 and then not Scope_Depth_Set
(S
)
5535 if S
= Standard_Standard
then
5536 Set_Scope_Depth_Value
(S
, Uint_0
);
5538 elsif Is_Child_Unit
(S
) then
5539 Set_Scope_Depth_Value
(S
, Uint_1
);
5541 elsif not Is_Record_Type
(Current_Scope
) then
5542 if Ekind
(S
) = E_Loop
then
5543 Set_Scope_Depth_Value
(S
, Scope_Depth
(Current_Scope
));
5545 Set_Scope_Depth_Value
(S
, Scope_Depth
(Current_Scope
) + 1);
5550 Scope_Stack
.Increment_Last
;
5553 SST
: Scope_Stack_Entry
renames Scope_Stack
.Table
(Scope_Stack
.Last
);
5557 SST
.Save_Scope_Suppress
:= Scope_Suppress
;
5558 SST
.Save_Local_Entity_Suppress
:= Local_Entity_Suppress
.Last
;
5560 if Scope_Stack
.Last
> Scope_Stack
.First
then
5561 SST
.Component_Alignment_Default
:= Scope_Stack
.Table
5562 (Scope_Stack
.Last
- 1).
5563 Component_Alignment_Default
;
5566 SST
.Last_Subprogram_Name
:= null;
5567 SST
.Is_Transient
:= False;
5568 SST
.Node_To_Be_Wrapped
:= Empty
;
5569 SST
.Pending_Freeze_Actions
:= No_List
;
5570 SST
.Actions_To_Be_Wrapped_Before
:= No_List
;
5571 SST
.Actions_To_Be_Wrapped_After
:= No_List
;
5572 SST
.First_Use_Clause
:= Empty
;
5573 SST
.Is_Active_Stack_Base
:= False;
5574 SST
.Previous_Visibility
:= False;
5577 if Debug_Flag_W
then
5578 Write_Str
("--> new scope: ");
5579 Write_Name
(Chars
(Current_Scope
));
5580 Write_Str
(", Id=");
5581 Write_Int
(Int
(Current_Scope
));
5582 Write_Str
(", Depth=");
5583 Write_Int
(Int
(Scope_Stack
.Last
));
5587 -- Copy from Scope (S) the categorization flags to S, this is not
5588 -- done in case Scope (S) is Standard_Standard since propagation
5589 -- is from library unit entity inwards.
5591 if S
/= Standard_Standard
5592 and then Scope
(S
) /= Standard_Standard
5593 and then not Is_Child_Unit
(S
)
5597 if Nkind
(E
) not in N_Entity
then
5601 -- We only propagate inwards for library level entities,
5602 -- inner level subprograms do not inherit the categorization.
5604 if Is_Library_Level_Entity
(S
) then
5605 Set_Is_Preelaborated
(S
, Is_Preelaborated
(E
));
5606 Set_Is_Shared_Passive
(S
, Is_Shared_Passive
(E
));
5607 Set_Categorization_From_Scope
(E
=> S
, Scop
=> E
);
5612 ------------------------
5613 -- Note_Redundant_Use --
5614 ------------------------
5616 procedure Note_Redundant_Use
(Clause
: Node_Id
) is
5617 Pack_Name
: constant Entity_Id
:= Entity
(Clause
);
5618 Cur_Use
: constant Node_Id
:= Current_Use_Clause
(Pack_Name
);
5619 Decl
: constant Node_Id
:= Parent
(Clause
);
5621 Prev_Use
: Node_Id
:= Empty
;
5622 Redundant
: Node_Id
:= Empty
;
5623 -- The Use_Clause which is actually redundant. In the simplest case
5624 -- it is Pack itself, but when we compile a body we install its
5625 -- context before that of its spec, in which case it is the use_clause
5626 -- in the spec that will appear to be redundant, and we want the
5627 -- warning to be placed on the body. Similar complications appear when
5628 -- the redundancy is between a child unit and one of its ancestors.
5631 Set_Redundant_Use
(Clause
, True);
5633 if not Comes_From_Source
(Clause
)
5635 or else not Warn_On_Redundant_Constructs
5640 if not Is_Compilation_Unit
(Current_Scope
) then
5642 -- If the use_clause is in an inner scope, it is made redundant
5643 -- by some clause in the current context, with one exception:
5644 -- If we're compiling a nested package body, and the use_clause
5645 -- comes from the corresponding spec, the clause is not necessarily
5646 -- fully redundant, so we should not warn. If a warning was
5647 -- warranted, it would have been given when the spec was processed.
5649 if Nkind
(Parent
(Decl
)) = N_Package_Specification
then
5651 Package_Spec_Entity
: constant Entity_Id
:=
5652 Defining_Unit_Name
(Parent
(Decl
));
5654 if In_Package_Body
(Package_Spec_Entity
) then
5660 Redundant
:= Clause
;
5661 Prev_Use
:= Cur_Use
;
5663 elsif Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Body
then
5665 Cur_Unit
: constant Unit_Number_Type
:= Get_Source_Unit
(Cur_Use
);
5666 New_Unit
: constant Unit_Number_Type
:= Get_Source_Unit
(Clause
);
5670 if Cur_Unit
= New_Unit
then
5672 -- Redundant clause in same body
5674 Redundant
:= Clause
;
5675 Prev_Use
:= Cur_Use
;
5677 elsif Cur_Unit
= Current_Sem_Unit
then
5679 -- If the new clause is not in the current unit it has been
5680 -- analyzed first, and it makes the other one redundant.
5681 -- However, if the new clause appears in a subunit, Cur_Unit
5682 -- is still the parent, and in that case the redundant one
5683 -- is the one appearing in the subunit.
5685 if Nkind
(Unit
(Cunit
(New_Unit
))) = N_Subunit
then
5686 Redundant
:= Clause
;
5687 Prev_Use
:= Cur_Use
;
5689 -- Most common case: redundant clause in body,
5690 -- original clause in spec. Current scope is spec entity.
5695 Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
))))
5697 Redundant
:= Cur_Use
;
5701 -- The new clause may appear in an unrelated unit, when
5702 -- the parents of a generic are being installed prior to
5703 -- instantiation. In this case there must be no warning.
5704 -- We detect this case by checking whether the current top
5705 -- of the stack is related to the current compilation.
5707 Scop
:= Current_Scope
;
5708 while Present
(Scop
)
5709 and then Scop
/= Standard_Standard
5711 if Is_Compilation_Unit
(Scop
)
5712 and then not Is_Child_Unit
(Scop
)
5716 elsif Scop
= Cunit_Entity
(Current_Sem_Unit
) then
5720 Scop
:= Scope
(Scop
);
5723 Redundant
:= Cur_Use
;
5727 elsif New_Unit
= Current_Sem_Unit
then
5728 Redundant
:= Clause
;
5729 Prev_Use
:= Cur_Use
;
5732 -- Neither is the current unit, so they appear in parent or
5733 -- sibling units. Warning will be emitted elsewhere.
5739 elsif Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Declaration
5740 and then Present
(Parent_Spec
(Unit
(Cunit
(Current_Sem_Unit
))))
5742 -- Use_clause is in child unit of current unit, and the child
5743 -- unit appears in the context of the body of the parent, so it
5744 -- has been installed first, even though it is the redundant one.
5745 -- Depending on their placement in the context, the visible or the
5746 -- private parts of the two units, either might appear as redundant,
5747 -- but the message has to be on the current unit.
5749 if Get_Source_Unit
(Cur_Use
) = Current_Sem_Unit
then
5750 Redundant
:= Cur_Use
;
5753 Redundant
:= Clause
;
5754 Prev_Use
:= Cur_Use
;
5757 -- If the new use clause appears in the private part of a parent unit
5758 -- it may appear to be redudant w.r.t. a use clause in a child unit,
5759 -- but the previous use clause was needed in the visible part of the
5760 -- child, and no warning should be emitted.
5762 if Nkind
(Parent
(Decl
)) = N_Package_Specification
5764 List_Containing
(Decl
) = Private_Declarations
(Parent
(Decl
))
5767 Par
: constant Entity_Id
:= Defining_Entity
(Parent
(Decl
));
5768 Spec
: constant Node_Id
:=
5769 Specification
(Unit
(Cunit
(Current_Sem_Unit
)));
5772 if Is_Compilation_Unit
(Par
)
5773 and then Par
/= Cunit_Entity
(Current_Sem_Unit
)
5774 and then Parent
(Cur_Use
) = Spec
5776 List_Containing
(Cur_Use
) = Visible_Declarations
(Spec
)
5787 if Present
(Redundant
) then
5788 Error_Msg_Sloc
:= Sloc
(Prev_Use
);
5790 "& is already use_visible through declaration #?",
5791 Redundant
, Pack_Name
);
5793 end Note_Redundant_Use
;
5799 procedure Pop_Scope
is
5800 SST
: Scope_Stack_Entry
renames Scope_Stack
.Table
(Scope_Stack
.Last
);
5803 if Debug_Flag_E
then
5807 Scope_Suppress
:= SST
.Save_Scope_Suppress
;
5808 Local_Entity_Suppress
.Set_Last
(SST
.Save_Local_Entity_Suppress
);
5810 if Debug_Flag_W
then
5811 Write_Str
("--> exiting scope: ");
5812 Write_Name
(Chars
(Current_Scope
));
5813 Write_Str
(", Depth=");
5814 Write_Int
(Int
(Scope_Stack
.Last
));
5818 End_Use_Clauses
(SST
.First_Use_Clause
);
5820 -- If the actions to be wrapped are still there they will get lost
5821 -- causing incomplete code to be generated. It is better to abort in
5822 -- this case (and we do the abort even with assertions off since the
5823 -- penalty is incorrect code generation)
5825 if SST
.Actions_To_Be_Wrapped_Before
/= No_List
5827 SST
.Actions_To_Be_Wrapped_After
/= No_List
5832 -- Free last subprogram name if allocated, and pop scope
5834 Free
(SST
.Last_Subprogram_Name
);
5835 Scope_Stack
.Decrement_Last
;
5838 ---------------------
5839 -- Premature_Usage --
5840 ---------------------
5842 procedure Premature_Usage
(N
: Node_Id
) is
5843 Kind
: constant Node_Kind
:= Nkind
(Parent
(Entity
(N
)));
5844 E
: Entity_Id
:= Entity
(N
);
5847 -- Within an instance, the analysis of the actual for a formal object
5848 -- does not see the name of the object itself. This is significant
5849 -- only if the object is an aggregate, where its analysis does not do
5850 -- any name resolution on component associations. (see 4717-008). In
5851 -- such a case, look for the visible homonym on the chain.
5854 and then Present
(Homonym
(E
))
5859 and then not In_Open_Scopes
(Scope
(E
))
5866 Set_Etype
(N
, Etype
(E
));
5871 if Kind
= N_Component_Declaration
then
5873 ("component&! cannot be used before end of record declaration", N
);
5875 elsif Kind
= N_Parameter_Specification
then
5877 ("formal parameter&! cannot be used before end of specification",
5880 elsif Kind
= N_Discriminant_Specification
then
5882 ("discriminant&! cannot be used before end of discriminant part",
5885 elsif Kind
= N_Procedure_Specification
5886 or else Kind
= N_Function_Specification
5889 ("subprogram&! cannot be used before end of its declaration",
5893 ("object& cannot be used before end of its declaration!", N
);
5895 end Premature_Usage
;
5897 ------------------------
5898 -- Present_System_Aux --
5899 ------------------------
5901 function Present_System_Aux
(N
: Node_Id
:= Empty
) return Boolean is
5904 Unum
: Unit_Number_Type
;
5909 function Find_System
(C_Unit
: Node_Id
) return Entity_Id
;
5910 -- Scan context clause of compilation unit to find a with_clause
5917 function Find_System
(C_Unit
: Node_Id
) return Entity_Id
is
5918 With_Clause
: Node_Id
;
5921 With_Clause
:= First
(Context_Items
(C_Unit
));
5923 while Present
(With_Clause
) loop
5924 if (Nkind
(With_Clause
) = N_With_Clause
5925 and then Chars
(Name
(With_Clause
)) = Name_System
)
5926 and then Comes_From_Source
(With_Clause
)
5937 -- Start of processing for Present_System_Aux
5940 -- The child unit may have been loaded and analyzed already
5942 if Present
(System_Aux_Id
) then
5945 -- If no previous pragma for System.Aux, nothing to load
5947 elsif No
(System_Extend_Unit
) then
5950 -- Use the unit name given in the pragma to retrieve the unit.
5951 -- Verify that System itself appears in the context clause of the
5952 -- current compilation. If System is not present, an error will
5953 -- have been reported already.
5956 With_Sys
:= Find_System
(Cunit
(Current_Sem_Unit
));
5958 The_Unit
:= Unit
(Cunit
(Current_Sem_Unit
));
5961 and then (Nkind
(The_Unit
) = N_Package_Body
5962 or else (Nkind
(The_Unit
) = N_Subprogram_Body
5963 and then not Acts_As_Spec
(Cunit
(Current_Sem_Unit
))))
5965 With_Sys
:= Find_System
(Library_Unit
(Cunit
(Current_Sem_Unit
)));
5969 and then Present
(N
)
5971 -- If we are compiling a subunit, we need to examine its
5972 -- context as well (Current_Sem_Unit is the parent unit);
5974 The_Unit
:= Parent
(N
);
5976 while Nkind
(The_Unit
) /= N_Compilation_Unit
loop
5977 The_Unit
:= Parent
(The_Unit
);
5980 if Nkind
(Unit
(The_Unit
)) = N_Subunit
then
5981 With_Sys
:= Find_System
(The_Unit
);
5985 if No
(With_Sys
) then
5989 Loc
:= Sloc
(With_Sys
);
5990 Get_Name_String
(Chars
(Expression
(System_Extend_Unit
)));
5991 Name_Buffer
(8 .. Name_Len
+ 7) := Name_Buffer
(1 .. Name_Len
);
5992 Name_Buffer
(1 .. 7) := "system.";
5993 Name_Buffer
(Name_Len
+ 8) := '%';
5994 Name_Buffer
(Name_Len
+ 9) := 's';
5995 Name_Len
:= Name_Len
+ 9;
5996 Aux_Name
:= Name_Find
;
6000 (Load_Name
=> Aux_Name
,
6003 Error_Node
=> With_Sys
);
6005 if Unum
/= No_Unit
then
6006 Semantics
(Cunit
(Unum
));
6008 Defining_Entity
(Specification
(Unit
(Cunit
(Unum
))));
6010 Withn
:= Make_With_Clause
(Loc
,
6012 Make_Expanded_Name
(Loc
,
6013 Chars
=> Chars
(System_Aux_Id
),
6015 New_Reference_To
(Scope
(System_Aux_Id
), Loc
),
6017 New_Reference_To
(System_Aux_Id
, Loc
)));
6019 Set_Entity
(Name
(Withn
), System_Aux_Id
);
6021 Set_Library_Unit
(Withn
, Cunit
(Unum
));
6022 Set_Corresponding_Spec
(Withn
, System_Aux_Id
);
6023 Set_First_Name
(Withn
, True);
6024 Set_Implicit_With
(Withn
, True);
6026 Insert_After
(With_Sys
, Withn
);
6027 Mark_Rewrite_Insertion
(Withn
);
6028 Set_Context_Installed
(Withn
);
6032 -- Here if unit load failed
6035 Error_Msg_Name_1
:= Name_System
;
6036 Error_Msg_Name_2
:= Chars
(Expression
(System_Extend_Unit
));
6038 ("extension package `%.%` does not exist",
6039 Opt
.System_Extend_Unit
);
6043 end Present_System_Aux
;
6045 -------------------------
6046 -- Restore_Scope_Stack --
6047 -------------------------
6049 procedure Restore_Scope_Stack
(Handle_Use
: Boolean := True) is
6052 Comp_Unit
: Node_Id
;
6053 In_Child
: Boolean := False;
6054 Full_Vis
: Boolean := True;
6055 SS_Last
: constant Int
:= Scope_Stack
.Last
;
6058 -- Restore visibility of previous scope stack, if any
6060 for J
in reverse 0 .. Scope_Stack
.Last
loop
6061 exit when Scope_Stack
.Table
(J
).Entity
= Standard_Standard
6062 or else No
(Scope_Stack
.Table
(J
).Entity
);
6064 S
:= Scope_Stack
.Table
(J
).Entity
;
6066 if not Is_Hidden_Open_Scope
(S
) then
6068 -- If the parent scope is hidden, its entities are hidden as
6069 -- well, unless the entity is the instantiation currently
6072 if not Is_Hidden_Open_Scope
(Scope
(S
))
6073 or else not Analyzed
(Parent
(S
))
6074 or else Scope
(S
) = Standard_Standard
6076 Set_Is_Immediately_Visible
(S
, True);
6079 E
:= First_Entity
(S
);
6081 while Present
(E
) loop
6082 if Is_Child_Unit
(E
) then
6083 Set_Is_Immediately_Visible
(E
,
6084 Is_Visible_Child_Unit
(E
) or else In_Open_Scopes
(E
));
6086 Set_Is_Immediately_Visible
(E
, True);
6091 if not Full_Vis
then
6092 exit when E
= First_Private_Entity
(S
);
6096 -- The visibility of child units (siblings of current compilation)
6097 -- must be restored in any case. Their declarations may appear
6098 -- after the private part of the parent.
6101 and then Present
(E
)
6103 while Present
(E
) loop
6104 if Is_Child_Unit
(E
) then
6105 Set_Is_Immediately_Visible
(E
,
6106 Is_Visible_Child_Unit
(E
) or else In_Open_Scopes
(E
));
6114 if Is_Child_Unit
(S
)
6115 and not In_Child
-- check only for current unit.
6119 -- restore visibility of parents according to whether the child
6120 -- is private and whether we are in its visible part.
6122 Comp_Unit
:= Parent
(Unit_Declaration_Node
(S
));
6124 if Nkind
(Comp_Unit
) = N_Compilation_Unit
6125 and then Private_Present
(Comp_Unit
)
6129 elsif (Ekind
(S
) = E_Package
6130 or else Ekind
(S
) = E_Generic_Package
)
6131 and then (In_Private_Part
(S
)
6132 or else In_Package_Body
(S
))
6136 elsif (Ekind
(S
) = E_Procedure
6137 or else Ekind
(S
) = E_Function
)
6138 and then Has_Completion
(S
)
6149 if SS_Last
>= Scope_Stack
.First
6150 and then Scope_Stack
.Table
(SS_Last
).Entity
/= Standard_Standard
6153 Install_Use_Clauses
(Scope_Stack
.Table
(SS_Last
).First_Use_Clause
);
6155 end Restore_Scope_Stack
;
6157 ----------------------
6158 -- Save_Scope_Stack --
6159 ----------------------
6161 procedure Save_Scope_Stack
(Handle_Use
: Boolean := True) is
6164 SS_Last
: constant Int
:= Scope_Stack
.Last
;
6167 if SS_Last
>= Scope_Stack
.First
6168 and then Scope_Stack
.Table
(SS_Last
).Entity
/= Standard_Standard
6171 End_Use_Clauses
(Scope_Stack
.Table
(SS_Last
).First_Use_Clause
);
6174 -- If the call is from within a compilation unit, as when
6175 -- called from Rtsfind, make current entries in scope stack
6176 -- invisible while we analyze the new unit.
6178 for J
in reverse 0 .. SS_Last
loop
6179 exit when Scope_Stack
.Table
(J
).Entity
= Standard_Standard
6180 or else No
(Scope_Stack
.Table
(J
).Entity
);
6182 S
:= Scope_Stack
.Table
(J
).Entity
;
6183 Set_Is_Immediately_Visible
(S
, False);
6184 E
:= First_Entity
(S
);
6186 while Present
(E
) loop
6187 Set_Is_Immediately_Visible
(E
, False);
6193 end Save_Scope_Stack
;
6199 procedure Set_Use
(L
: List_Id
) is
6201 Pack_Name
: Node_Id
;
6209 while Present
(Decl
) loop
6210 if Nkind
(Decl
) = N_Use_Package_Clause
then
6211 Chain_Use_Clause
(Decl
);
6212 Pack_Name
:= First
(Names
(Decl
));
6214 while Present
(Pack_Name
) loop
6215 Pack
:= Entity
(Pack_Name
);
6217 if Ekind
(Pack
) = E_Package
6218 and then Applicable_Use
(Pack_Name
)
6220 Use_One_Package
(Pack
, Decl
);
6226 elsif Nkind
(Decl
) = N_Use_Type_Clause
then
6227 Chain_Use_Clause
(Decl
);
6228 Id
:= First
(Subtype_Marks
(Decl
));
6230 while Present
(Id
) loop
6231 if Entity
(Id
) /= Any_Type
then
6244 ---------------------
6245 -- Use_One_Package --
6246 ---------------------
6248 procedure Use_One_Package
(P
: Entity_Id
; N
: Node_Id
) is
6251 Current_Instance
: Entity_Id
:= Empty
;
6253 Private_With_OK
: Boolean := False;
6256 if Ekind
(P
) /= E_Package
then
6261 Set_Current_Use_Clause
(P
, N
);
6263 -- Ada 2005 (AI-50217): Check restriction
6265 if From_With_Type
(P
) then
6266 Error_Msg_N
("limited withed package cannot appear in use clause", N
);
6269 -- Find enclosing instance, if any
6272 Current_Instance
:= Current_Scope
;
6274 while not Is_Generic_Instance
(Current_Instance
) loop
6275 Current_Instance
:= Scope
(Current_Instance
);
6278 if No
(Hidden_By_Use_Clause
(N
)) then
6279 Set_Hidden_By_Use_Clause
(N
, New_Elmt_List
);
6283 -- If unit is a package renaming, indicate that the renamed
6284 -- package is also in use (the flags on both entities must
6285 -- remain consistent, and a subsequent use of either of them
6286 -- should be recognized as redundant).
6288 if Present
(Renamed_Object
(P
)) then
6289 Set_In_Use
(Renamed_Object
(P
));
6290 Set_Current_Use_Clause
(Renamed_Object
(P
), N
);
6291 Real_P
:= Renamed_Object
(P
);
6296 -- Ada 2005 (AI-262): Check the use_clause of a private withed package
6297 -- found in the private part of a package specification
6299 if In_Private_Part
(Current_Scope
)
6300 and then Has_Private_With
(P
)
6301 and then Is_Child_Unit
(Current_Scope
)
6302 and then Is_Child_Unit
(P
)
6303 and then Is_Ancestor_Package
(Scope
(Current_Scope
), P
)
6305 Private_With_OK
:= True;
6308 -- Loop through entities in one package making them potentially
6311 Id
:= First_Entity
(P
);
6313 and then (Id
/= First_Private_Entity
(P
)
6314 or else Private_With_OK
) -- Ada 2005 (AI-262)
6316 Prev
:= Current_Entity
(Id
);
6318 while Present
(Prev
) loop
6319 if Is_Immediately_Visible
(Prev
)
6320 and then (not Is_Overloadable
(Prev
)
6321 or else not Is_Overloadable
(Id
)
6322 or else (Type_Conformant
(Id
, Prev
)))
6324 if No
(Current_Instance
) then
6326 -- Potentially use-visible entity remains hidden
6328 goto Next_Usable_Entity
;
6330 -- A use clause within an instance hides outer global
6331 -- entities, which are not used to resolve local entities
6332 -- in the instance. Note that the predefined entities in
6333 -- Standard could not have been hidden in the generic by
6334 -- a use clause, and therefore remain visible. Other
6335 -- compilation units whose entities appear in Standard must
6336 -- be hidden in an instance.
6338 -- To determine whether an entity is external to the instance
6339 -- we compare the scope depth of its scope with that of the
6340 -- current instance. However, a generic actual of a subprogram
6341 -- instance is declared in the wrapper package but will not be
6342 -- hidden by a use-visible entity.
6344 -- If Id is called Standard, the predefined package with the
6345 -- same name is in the homonym chain. It has to be ignored
6346 -- because it has no defined scope (being the only entity in
6347 -- the system with this mandated behavior).
6349 elsif not Is_Hidden
(Id
)
6350 and then Present
(Scope
(Prev
))
6351 and then not Is_Wrapper_Package
(Scope
(Prev
))
6352 and then Scope_Depth
(Scope
(Prev
)) <
6353 Scope_Depth
(Current_Instance
)
6354 and then (Scope
(Prev
) /= Standard_Standard
6355 or else Sloc
(Prev
) > Standard_Location
)
6357 Set_Is_Potentially_Use_Visible
(Id
);
6358 Set_Is_Immediately_Visible
(Prev
, False);
6359 Append_Elmt
(Prev
, Hidden_By_Use_Clause
(N
));
6362 -- A user-defined operator is not use-visible if the
6363 -- predefined operator for the type is immediately visible,
6364 -- which is the case if the type of the operand is in an open
6365 -- scope. This does not apply to user-defined operators that
6366 -- have operands of different types, because the predefined
6367 -- mixed mode operations (multiplication and division) apply to
6368 -- universal types and do not hide anything.
6370 elsif Ekind
(Prev
) = E_Operator
6371 and then Operator_Matches_Spec
(Prev
, Id
)
6372 and then In_Open_Scopes
6373 (Scope
(Base_Type
(Etype
(First_Formal
(Id
)))))
6374 and then (No
(Next_Formal
(First_Formal
(Id
)))
6375 or else Etype
(First_Formal
(Id
))
6376 = Etype
(Next_Formal
(First_Formal
(Id
)))
6377 or else Chars
(Prev
) = Name_Op_Expon
)
6379 goto Next_Usable_Entity
;
6382 Prev
:= Homonym
(Prev
);
6385 -- On exit, we know entity is not hidden, unless it is private
6387 if not Is_Hidden
(Id
)
6388 and then ((not Is_Child_Unit
(Id
))
6389 or else Is_Visible_Child_Unit
(Id
))
6391 Set_Is_Potentially_Use_Visible
(Id
);
6393 if Is_Private_Type
(Id
)
6394 and then Present
(Full_View
(Id
))
6396 Set_Is_Potentially_Use_Visible
(Full_View
(Id
));
6400 <<Next_Usable_Entity
>>
6404 -- Child units are also made use-visible by a use clause, but they
6405 -- may appear after all visible declarations in the parent entity list.
6407 while Present
(Id
) loop
6409 if Is_Child_Unit
(Id
)
6410 and then Is_Visible_Child_Unit
(Id
)
6412 Set_Is_Potentially_Use_Visible
(Id
);
6418 if Chars
(Real_P
) = Name_System
6419 and then Scope
(Real_P
) = Standard_Standard
6420 and then Present_System_Aux
(N
)
6422 Use_One_Package
(System_Aux_Id
, N
);
6425 end Use_One_Package
;
6431 procedure Use_One_Type
(Id
: Node_Id
) is
6437 -- It is the type determined by the subtype mark (8.4(8)) whose
6438 -- operations become potentially use-visible.
6440 T
:= Base_Type
(Entity
(Id
));
6445 or else Is_Potentially_Use_Visible
(T
)
6446 or else In_Use
(Scope
(T
)));
6448 if In_Open_Scopes
(Scope
(T
)) then
6451 elsif From_With_Type
(T
) then
6453 ("incomplete type from limited view "
6454 & "cannot appear in use clause", Id
);
6456 -- If the subtype mark designates a subtype in a different package,
6457 -- we have to check that the parent type is visible, otherwise the
6458 -- use type clause is a noop. Not clear how to do that???
6460 elsif not Redundant_Use
(Id
) then
6462 Op_List
:= Collect_Primitive_Operations
(T
);
6463 Elmt
:= First_Elmt
(Op_List
);
6465 while Present
(Elmt
) loop
6467 if (Nkind
(Node
(Elmt
)) = N_Defining_Operator_Symbol
6468 or else Chars
(Node
(Elmt
)) in Any_Operator_Name
)
6469 and then not Is_Hidden
(Node
(Elmt
))
6471 Set_Is_Potentially_Use_Visible
(Node
(Elmt
));
6483 procedure Write_Info
is
6484 Id
: Entity_Id
:= First_Entity
(Current_Scope
);
6487 -- No point in dumping standard entities
6489 if Current_Scope
= Standard_Standard
then
6493 Write_Str
("========================================================");
6495 Write_Str
(" Defined Entities in ");
6496 Write_Name
(Chars
(Current_Scope
));
6498 Write_Str
("========================================================");
6502 Write_Str
("-- none --");
6506 while Present
(Id
) loop
6507 Write_Entity_Info
(Id
, " ");
6512 if Scope
(Current_Scope
) = Standard_Standard
then
6514 -- Print information on the current unit itself
6516 Write_Entity_Info
(Current_Scope
, " ");
6526 procedure Write_Scopes
is
6530 for J
in reverse 1 .. Scope_Stack
.Last
loop
6531 S
:= Scope_Stack
.Table
(J
).Entity
;
6532 Write_Int
(Int
(S
));
6533 Write_Str
(" === ");
6534 Write_Name
(Chars
(S
));