1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 ------------------------------------------------------------------------------
28 with Atree
; use Atree
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
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 Rtsfind
; use Rtsfind
;
47 with Sem_Ch3
; use Sem_Ch3
;
48 with Sem_Ch4
; use Sem_Ch4
;
49 with Sem_Ch6
; use Sem_Ch6
;
50 with Sem_Ch12
; use Sem_Ch12
;
51 with Sem_Res
; use Sem_Res
;
52 with Sem_Util
; use Sem_Util
;
53 with Sem_Type
; use Sem_Type
;
54 with Stand
; use Stand
;
55 with Sinfo
; use Sinfo
;
56 with Sinfo
.CN
; use Sinfo
.CN
;
57 with Snames
; use Snames
;
58 with Style
; use Style
;
60 with Tbuild
; use Tbuild
;
61 with Uintp
; use Uintp
;
63 with GNAT
.Spelling_Checker
; use GNAT
.Spelling_Checker
;
65 package body Sem_Ch8
is
67 ------------------------------------
68 -- Visibility and Name Resolution --
69 ------------------------------------
71 -- This package handles name resolution and the collection of
72 -- interpretations for overloaded names, prior to overload resolution.
74 -- Name resolution is the process that establishes a mapping between source
75 -- identifiers and the entities they denote at each point in the program.
76 -- Each entity is represented by a defining occurrence. Each identifier
77 -- that denotes an entity points to the corresponding defining occurrence.
78 -- This is the entity of the applied occurrence. Each occurrence holds
79 -- an index into the names table, where source identifiers are stored.
81 -- Each entry in the names table for an identifier or designator uses the
82 -- Info pointer to hold a link to the currently visible entity that has
83 -- this name (see subprograms Get_Name_Entity_Id and Set_Name_Entity_Id
84 -- in package Sem_Util). The visibility is initialized at the beginning of
85 -- semantic processing to make entities in package Standard immediately
86 -- visible. The visibility table is used in a more subtle way when
87 -- compiling subunits (see below).
89 -- Entities that have the same name (i.e. homonyms) are chained. In the
90 -- case of overloaded entities, this chain holds all the possible meanings
91 -- of a given identifier. The process of overload resolution uses type
92 -- information to select from this chain the unique meaning of a given
95 -- Entities are also chained in their scope, through the Next_Entity link.
96 -- As a consequence, the name space is organized as a sparse matrix, where
97 -- each row corresponds to a scope, and each column to a source identifier.
98 -- Open scopes, that is to say scopes currently being compiled, have their
99 -- corresponding rows of entities in order, innermost scope first.
101 -- The scopes of packages that are mentioned in context clauses appear in
102 -- no particular order, interspersed among open scopes. This is because
103 -- in the course of analyzing the context of a compilation, a package
104 -- declaration is first an open scope, and subsequently an element of the
105 -- context. If subunits or child units are present, a parent unit may
106 -- appear under various guises at various times in the compilation.
108 -- When the compilation of the innermost scope is complete, the entities
109 -- defined therein are no longer visible. If the scope is not a package
110 -- declaration, these entities are never visible subsequently, and can be
111 -- removed from visibility chains. If the scope is a package declaration,
112 -- its visible declarations may still be accessible. Therefore the entities
113 -- defined in such a scope are left on the visibility chains, and only
114 -- their visibility (immediately visibility or potential use-visibility)
117 -- The ordering of homonyms on their chain does not necessarily follow
118 -- the order of their corresponding scopes on the scope stack. For
119 -- example, if package P and the enclosing scope both contain entities
120 -- named E, then when compiling the package body the chain for E will
121 -- hold the global entity first, and the local one (corresponding to
122 -- the current inner scope) next. As a result, name resolution routines
123 -- do not assume any relative ordering of the homonym chains, either
124 -- for scope nesting or to order of appearance of context clauses.
126 -- When compiling a child unit, entities in the parent scope are always
127 -- immediately visible. When compiling the body of a child unit, private
128 -- entities in the parent must also be made immediately visible. There
129 -- are separate routines to make the visible and private declarations
130 -- visible at various times (see package Sem_Ch7).
132 -- +--------+ +-----+
133 -- | In use |-------->| EU1 |-------------------------->
134 -- +--------+ +-----+
136 -- +--------+ +-----+ +-----+
137 -- | Stand. |---------------->| ES1 |--------------->| ES2 |--->
138 -- +--------+ +-----+ +-----+
140 -- +---------+ | +-----+
141 -- | with'ed |------------------------------>| EW2 |--->
142 -- +---------+ | +-----+
144 -- +--------+ +-----+ +-----+
145 -- | Scope2 |---------------->| E12 |--------------->| E22 |--->
146 -- +--------+ +-----+ +-----+
148 -- +--------+ +-----+ +-----+
149 -- | Scope1 |---------------->| E11 |--------------->| E12 |--->
150 -- +--------+ +-----+ +-----+
154 -- | | with'ed |----------------------------------------->
158 -- (innermost first) | |
159 -- +----------------------------+
160 -- Names table => | Id1 | | | | Id2 |
161 -- +----------------------------+
163 -- Name resolution must deal with several syntactic forms: simple names,
164 -- qualified names, indexed names, and various forms of calls.
166 -- Each identifier points to an entry in the names table. The resolution
167 -- of a simple name consists in traversing the homonym chain, starting
168 -- from the names table. If an entry is immediately visible, it is the one
169 -- designated by the identifier. If only potemtially use-visible entities
170 -- are on the chain, we must verify that they do not hide each other. If
171 -- the entity we find is overloadable, we collect all other overloadable
172 -- entities on the chain as long as they are not hidden.
174 -- To resolve expanded names, we must find the entity at the intersection
175 -- of the entity chain for the scope (the prefix) and the homonym chain
176 -- for the selector. In general, homonym chains will be much shorter than
177 -- entity chains, so it is preferable to start from the names table as
178 -- well. If the entity found is overloadable, we must collect all other
179 -- interpretations that are defined in the scope denoted by the prefix.
181 -- For records, protected types, and tasks, their local entities are
182 -- removed from visibility chains on exit from the corresponding scope.
183 -- From the outside, these entities are always accessed by selected
184 -- notation, and the entity chain for the record type, protected type,
185 -- etc. is traversed sequentially in order to find the designated entity.
187 -- The discriminants of a type and the operations of a protected type or
188 -- task are unchained on exit from the first view of the type, (such as
189 -- a private or incomplete type declaration, or a protected type speci-
190 -- fication) and rechained when compiling the second view.
192 -- In the case of operators, we do not make operators on derived types
193 -- explicit. As a result, the notation P."+" may denote either a user-
194 -- defined function with name "+", or else an implicit declaration of the
195 -- operator "+" in package P. The resolution of expanded names always
196 -- tries to resolve an operator name as such an implicitly defined entity,
197 -- in addition to looking for explicit declarations.
199 -- All forms of names that denote entities (simple names, expanded names,
200 -- character literals in some cases) have a Entity attribute, which
201 -- identifies the entity denoted by the name.
203 ---------------------
204 -- The Scope Stack --
205 ---------------------
207 -- The Scope stack keeps track of the scopes currently been compiled.
208 -- Every entity that contains declarations (including records) is placed
209 -- on the scope stack while it is being processed, and removed at the end.
210 -- Whenever a non-package scope is exited, the entities defined therein
211 -- are removed from the visibility table, so that entities in outer scopes
212 -- become visible (see previous description). On entry to Sem, the scope
213 -- stack only contains the package Standard. As usual, subunits complicate
214 -- this picture ever so slightly.
216 -- The Rtsfind mechanism can force a call to Semantics while another
217 -- compilation is in progress. The unit retrieved by Rtsfind must be
218 -- compiled in its own context, and has no access to the visibility of
219 -- the unit currently being compiled. The procedures Save_Scope_Stack and
220 -- Restore_Scope_Stack make entities in current open scopes invisible
221 -- before compiling the retrieved unit, and restore the compilation
222 -- environment afterwards.
224 ------------------------
225 -- Compiling subunits --
226 ------------------------
228 -- Subunits must be compiled in the environment of the corresponding
229 -- stub, that is to say with the same visibility into the parent (and its
230 -- context) that is available at the point of the stub declaration, but
231 -- with the additional visibility provided by the context clause of the
232 -- subunit itself. As a result, compilation of a subunit forces compilation
233 -- of the parent (see description in lib-). At the point of the stub
234 -- declaration, Analyze is called recursively to compile the proper body
235 -- of the subunit, but without reinitializing the names table, nor the
236 -- scope stack (i.e. standard is not pushed on the stack). In this fashion
237 -- the context of the subunit is added to the context of the parent, and
238 -- the subunit is compiled in the correct environment. Note that in the
239 -- course of processing the context of a subunit, Standard will appear
240 -- twice on the scope stack: once for the parent of the subunit, and
241 -- once for the unit in the context clause being compiled. However, the
242 -- two sets of entities are not linked by homonym chains, so that the
243 -- compilation of any context unit happens in a fresh visibility
246 -------------------------------
247 -- Processing of USE Clauses --
248 -------------------------------
250 -- Every defining occurrence has a flag indicating if it is potentially use
251 -- visible. Resolution of simple names examines this flag. The processing
252 -- of use clauses consists in setting this flag on all visible entities
253 -- defined in the corresponding package. On exit from the scope of the use
254 -- clause, the corresponding flag must be reset. However, a package may
255 -- appear in several nested use clauses (pathological but legal, alas!)
256 -- which forces us to use a slightly more involved scheme:
258 -- a) The defining occurrence for a package holds a flag -In_Use- to
259 -- indicate that it is currently in the scope of a use clause. If a
260 -- redundant use clause is encountered, then the corresponding occurrence
261 -- of the package name is flagged -Redundant_Use-.
263 -- b) On exit from a scope, the use clauses in its declarative part are
264 -- scanned. The visibility flag is reset in all entities declared in
265 -- package named in a use clause, as long as the package is not flagged
266 -- as being in a redundant use clause (in which case the outer use
267 -- clause is still in effect, and the direct visibility of its entities
268 -- must be retained).
270 -- Note that entities are not removed from their homonym chains on exit
271 -- from the package specification. A subsequent use clause does not need
272 -- to rechain the visible entities, but only to establish their direct
275 -----------------------------------
276 -- Handling private declarations --
277 -----------------------------------
279 -- The principle that each entity has a single defining occurrence clashes
280 -- with the presence of two separate definitions for private types: the
281 -- first is the private type declaration, and second is the full type
282 -- declaration. It is important that all references to the type point to
283 -- the same defining occurrence, namely the first one. To enforce the two
284 -- separate views of the entity, the corresponding information is swapped
285 -- between the two declarations. Outside of the package, the defining
286 -- occurrence only contains the private declaration information, while in
287 -- the private part and the body of the package the defining occurrence
288 -- contains the full declaration. To simplify the swap, the defining
289 -- occurrence that currently holds the private declaration points to the
290 -- full declaration. During semantic processing the defining occurrence
291 -- also points to a list of private dependents, that is to say access
292 -- types or composite types whose designated types or component types are
293 -- subtypes or derived types of the private type in question. After the
294 -- full declaration has been seen, the private dependents are updated to
295 -- indicate that they have full definitions.
297 ------------------------------------
298 -- Handling of Undefined Messages --
299 ------------------------------------
301 -- In normal mode, only the first use of an undefined identifier generates
302 -- a message. The table Urefs is used to record error messages that have
303 -- been issued so that second and subsequent ones do not generate further
304 -- messages. However, the second reference causes text to be added to the
305 -- original undefined message noting "(more references follow)". The
306 -- full error list option (-gnatf) forces messages to be generated for
307 -- every reference and disconnects the use of this table.
309 type Uref_Entry
is record
311 -- Node for identifier for which original message was posted. The
312 -- Chars field of this identifier is used to detect later references
313 -- to the same identifier.
316 -- Records error message Id of original undefined message. Reset to
317 -- No_Error_Msg after the second occurrence, where it is used to add
318 -- text to the original message as described above.
321 -- Set if the message is not visible rather than undefined
324 -- Records location of error message. Used to make sure that we do
325 -- not consider a, b : undefined as two separate instances, which
326 -- would otherwise happen, since the parser converts this sequence
327 -- to a : undefined; b : undefined.
331 package Urefs
is new Table
.Table
(
332 Table_Component_Type
=> Uref_Entry
,
333 Table_Index_Type
=> Nat
,
334 Table_Low_Bound
=> 1,
336 Table_Increment
=> 100,
337 Table_Name
=> "Urefs");
339 Candidate_Renaming
: Entity_Id
;
340 -- Holds a candidate interpretation that appears in a subprogram renaming
341 -- declaration and does not match the given specification, but matches at
342 -- least on the first formal. Allows better error message when given
343 -- specification omits defaulted parameters, a common error.
345 -----------------------
346 -- Local Subprograms --
347 -----------------------
349 procedure Analyze_Generic_Renaming
352 -- Common processing for all three kinds of generic renaming declarations.
353 -- Enter new name and indicate that it renames the generic unit.
355 procedure Analyze_Renamed_Character
359 -- Renamed entity is given by a character literal, which must belong
360 -- to the return type of the new entity. Is_Body indicates whether the
361 -- declaration is a renaming_as_body. If the original declaration has
362 -- already been frozen (because of an intervening body, e.g.) the body of
363 -- the function must be built now. The same applies to the following
364 -- various renaming procedures.
366 procedure Analyze_Renamed_Dereference
370 -- Renamed entity is given by an explicit dereference. Prefix must be a
371 -- conformant access_to_subprogram type.
373 procedure Analyze_Renamed_Entry
377 -- If the renamed entity in a subprogram renaming is an entry or protected
378 -- subprogram, build a body for the new entity whose only statement is a
379 -- call to the renamed entity.
381 procedure Analyze_Renamed_Family_Member
385 -- Used when the renamed entity is an indexed component. The prefix must
386 -- denote an entry family.
388 procedure Attribute_Renaming
(N
: Node_Id
);
389 -- Analyze renaming of attribute as function. The renaming declaration N
390 -- is rewritten as a function body that returns the attribute reference
391 -- applied to the formals of the function.
393 procedure Check_Frozen_Renaming
(N
: Node_Id
; Subp
: Entity_Id
);
394 -- A renaming_as_body may occur after the entity of the original decla-
395 -- ration has been frozen. In that case, the body of the new entity must
396 -- be built now, because the usual mechanism of building the renamed
397 -- body at the point of freezing will not work. Subp is the subprogram
398 -- for which N provides the Renaming_As_Body.
400 procedure Check_Library_Unit_Renaming
(N
: Node_Id
; Old_E
: Entity_Id
);
401 -- Verify that the entity in a renaming declaration that is a library unit
402 -- is itself a library unit and not a nested unit or subunit. Also check
403 -- that if the renaming is a child unit of a generic parent, then the
404 -- renamed unit must also be a child unit of that parent. Finally, verify
405 -- that a renamed generic unit is not an implicit child declared within
406 -- an instance of the parent.
408 procedure Chain_Use_Clause
(N
: Node_Id
);
409 -- Chain use clause onto list of uses clauses headed by First_Use_Clause
410 -- in the top scope table entry.
412 function Has_Implicit_Character_Literal
(N
: Node_Id
) return Boolean;
413 -- Find a type derived from Character or Wide_Character in the prefix of N.
414 -- Used to resolved qualified names whose selector is a character literal.
416 function Find_Renamed_Entity
420 Is_Actual
: Boolean := False) return Entity_Id
;
421 -- Find the renamed entity that corresponds to the given parameter profile
422 -- in a subprogram renaming declaration. The renamed entity may be an
423 -- operator, a subprogram, an entry, or a protected operation. Is_Actual
424 -- indicates that the renaming is the one generated for an actual subpro-
425 -- gram in an instance, for which special visibility checks apply.
427 procedure Inherit_Renamed_Profile
(New_S
: Entity_Id
; Old_S
: Entity_Id
);
428 -- A subprogram defined by a renaming declaration inherits the parameter
429 -- profile of the renamed entity. The subtypes given in the subprogram
430 -- specification are discarded and replaced with those of the renamed
431 -- subprogram, which are then used to recheck the default values.
433 procedure Premature_Usage
(N
: Node_Id
);
434 -- Diagnose usage of an entity before it is visible.
436 procedure Write_Info
;
437 -- Write debugging information on entities declared in current scope
439 procedure Write_Scopes
;
440 pragma Warnings
(Off
, Write_Scopes
);
441 -- Debugging information: dump all entities on scope stack
443 --------------------------------
444 -- Analyze_Exception_Renaming --
445 --------------------------------
447 -- The language only allows a single identifier, but the tree holds
448 -- an identifier list. The parser has already issued an error message
449 -- if there is more than one element in the list.
451 procedure Analyze_Exception_Renaming
(N
: Node_Id
) is
452 Id
: constant Node_Id
:= Defining_Identifier
(N
);
453 Nam
: constant Node_Id
:= Name
(N
);
459 Set_Ekind
(Id
, E_Exception
);
460 Set_Exception_Code
(Id
, Uint_0
);
461 Set_Etype
(Id
, Standard_Exception_Type
);
462 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
464 if not Is_Entity_Name
(Nam
) or else
465 Ekind
(Entity
(Nam
)) /= E_Exception
467 Error_Msg_N
("invalid exception name in renaming", Nam
);
469 if Present
(Renamed_Object
(Entity
(Nam
))) then
470 Set_Renamed_Object
(Id
, Renamed_Object
(Entity
(Nam
)));
472 Set_Renamed_Object
(Id
, Entity
(Nam
));
475 end Analyze_Exception_Renaming
;
477 ---------------------------
478 -- Analyze_Expanded_Name --
479 ---------------------------
481 procedure Analyze_Expanded_Name
(N
: Node_Id
) is
483 -- If the entity pointer is already set, this is an internal node, or
484 -- a node that is analyzed more than once, after a tree modification.
485 -- In such a case there is no resolution to perform, just set the type.
486 -- For completeness, analyze prefix as well.
488 if Present
(Entity
(N
)) then
489 if Is_Type
(Entity
(N
)) then
490 Set_Etype
(N
, Entity
(N
));
492 Set_Etype
(N
, Etype
(Entity
(N
)));
495 Analyze
(Prefix
(N
));
498 Find_Expanded_Name
(N
);
500 end Analyze_Expanded_Name
;
502 ----------------------------------------
503 -- Analyze_Generic_Function_Renaming --
504 ----------------------------------------
506 procedure Analyze_Generic_Function_Renaming
(N
: Node_Id
) is
508 Analyze_Generic_Renaming
(N
, E_Generic_Function
);
509 end Analyze_Generic_Function_Renaming
;
511 ---------------------------------------
512 -- Analyze_Generic_Package_Renaming --
513 ---------------------------------------
515 procedure Analyze_Generic_Package_Renaming
(N
: Node_Id
) is
517 -- Apply the Text_IO Kludge here, since we may be renaming
518 -- one of the subpackages of Text_IO, then join common routine.
520 Text_IO_Kludge
(Name
(N
));
522 Analyze_Generic_Renaming
(N
, E_Generic_Package
);
523 end Analyze_Generic_Package_Renaming
;
525 -----------------------------------------
526 -- Analyze_Generic_Procedure_Renaming --
527 -----------------------------------------
529 procedure Analyze_Generic_Procedure_Renaming
(N
: Node_Id
) is
531 Analyze_Generic_Renaming
(N
, E_Generic_Procedure
);
532 end Analyze_Generic_Procedure_Renaming
;
534 ------------------------------
535 -- Analyze_Generic_Renaming --
536 ------------------------------
538 procedure Analyze_Generic_Renaming
542 New_P
: Entity_Id
:= Defining_Entity
(N
);
544 Inst
: Boolean := False; -- prevent junk warning
547 if Name
(N
) = Error
then
551 Generate_Definition
(New_P
);
553 if Current_Scope
/= Standard_Standard
then
554 Set_Is_Pure
(New_P
, Is_Pure
(Current_Scope
));
557 if Nkind
(Name
(N
)) = N_Selected_Component
then
558 Check_Generic_Child_Unit
(Name
(N
), Inst
);
563 if not Is_Entity_Name
(Name
(N
)) then
564 Error_Msg_N
("expect entity name in renaming declaration", Name
(N
));
567 Old_P
:= Entity
(Name
(N
));
571 Set_Ekind
(New_P
, K
);
573 if Etype
(Old_P
) = Any_Type
then
576 elsif Ekind
(Old_P
) /= K
then
577 Error_Msg_N
("invalid generic unit name", Name
(N
));
580 if Present
(Renamed_Object
(Old_P
)) then
581 Set_Renamed_Object
(New_P
, Renamed_Object
(Old_P
));
583 Set_Renamed_Object
(New_P
, Old_P
);
586 Set_Etype
(New_P
, Etype
(Old_P
));
587 Set_Has_Completion
(New_P
);
589 if In_Open_Scopes
(Old_P
) then
590 Error_Msg_N
("within its scope, generic denotes its instance", N
);
593 Check_Library_Unit_Renaming
(N
, Old_P
);
596 end Analyze_Generic_Renaming
;
598 -----------------------------
599 -- Analyze_Object_Renaming --
600 -----------------------------
602 procedure Analyze_Object_Renaming
(N
: Node_Id
) is
603 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
605 Nam
: constant Node_Id
:= Name
(N
);
606 S
: constant Entity_Id
:= Subtype_Mark
(N
);
615 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
618 -- The renaming of a component that depends on a discriminant
619 -- requires an actual subtype, because in subsequent use of the object
620 -- Gigi will be unable to locate the actual bounds. This explicit step
621 -- is required when the renaming is generated in removing side effects
622 -- of an already-analyzed expression.
624 if Nkind
(Nam
) = N_Selected_Component
625 and then Analyzed
(Nam
)
628 Dec
:= Build_Actual_Subtype_Of_Component
(Etype
(Nam
), Nam
);
630 if Present
(Dec
) then
631 Insert_Action
(N
, Dec
);
632 T
:= Defining_Identifier
(Dec
);
639 Analyze_And_Resolve
(Nam
, T
);
642 -- An object renaming requires an exact match of the type;
643 -- class-wide matching is not allowed.
645 if Is_Class_Wide_Type
(T
)
646 and then Base_Type
(Etype
(Nam
)) /= Base_Type
(T
)
652 Set_Ekind
(Id
, E_Variable
);
653 Init_Size_Align
(Id
);
655 if T
= Any_Type
or else Etype
(Nam
) = Any_Type
then
658 -- Verify that the renamed entity is an object or a function call.
659 -- It may have been rewritten in several ways.
661 elsif Is_Object_Reference
(Nam
) then
663 if Comes_From_Source
(N
)
664 and then Is_Dependent_Component_Of_Mutable_Object
(Nam
)
667 ("illegal renaming of discriminant-dependent component", Nam
);
672 -- A static function call may have been folded into a literal
674 elsif Nkind
(Original_Node
(Nam
)) = N_Function_Call
676 -- When expansion is disabled, attribute reference is not
677 -- rewritten as function call. Otherwise it may be rewritten
678 -- as a conversion, so check original node.
680 or else (Nkind
(Original_Node
(Nam
)) = N_Attribute_Reference
681 and then Is_Function_Attribute_Name
682 (Attribute_Name
(Original_Node
(Nam
))))
684 -- Weird but legal, equivalent to renaming a function call.
686 or else (Is_Entity_Name
(Nam
)
687 and then Ekind
(Entity
(Nam
)) = E_Enumeration_Literal
)
689 or else (Nkind
(Nam
) = N_Type_Conversion
690 and then Is_Tagged_Type
(Entity
(Subtype_Mark
(Nam
))))
695 if Nkind
(Nam
) = N_Type_Conversion
then
697 ("renaming of conversion only allowed for tagged types", Nam
);
700 Error_Msg_N
("expect object name in renaming", Nam
);
707 if not Is_Variable
(Nam
) then
708 Set_Ekind
(Id
, E_Constant
);
709 Set_Not_Source_Assigned
(Id
, True);
710 Set_Is_True_Constant
(Id
, True);
713 Set_Renamed_Object
(Id
, Nam
);
714 end Analyze_Object_Renaming
;
716 ------------------------------
717 -- Analyze_Package_Renaming --
718 ------------------------------
720 procedure Analyze_Package_Renaming
(N
: Node_Id
) is
721 New_P
: constant Entity_Id
:= Defining_Entity
(N
);
726 if Name
(N
) = Error
then
730 -- Apply Text_IO kludge here, since we may be renaming one of
731 -- the children of Text_IO
733 Text_IO_Kludge
(Name
(N
));
735 if Current_Scope
/= Standard_Standard
then
736 Set_Is_Pure
(New_P
, Is_Pure
(Current_Scope
));
741 if Is_Entity_Name
(Name
(N
)) then
742 Old_P
:= Entity
(Name
(N
));
747 if Etype
(Old_P
) = Any_Type
then
749 ("expect package name in renaming", Name
(N
));
751 elsif Ekind
(Old_P
) /= E_Package
752 and then not (Ekind
(Old_P
) = E_Generic_Package
753 and then In_Open_Scopes
(Old_P
))
755 if Ekind
(Old_P
) = E_Generic_Package
then
757 ("generic package cannot be renamed as a package", Name
(N
));
759 Error_Msg_Sloc
:= Sloc
(Old_P
);
761 ("expect package name in renaming, found& declared#",
765 -- Set basic attributes to minimize cascaded errors.
767 Set_Ekind
(New_P
, E_Package
);
768 Set_Etype
(New_P
, Standard_Void_Type
);
770 elsif Ekind
(Old_P
) = E_Package
771 and then From_With_Type
(Old_P
)
773 Error_Msg_N
("imported package cannot be renamed", Name
(N
));
776 -- Entities in the old package are accessible through the
777 -- renaming entity. The simplest implementation is to have
778 -- both packages share the entity list.
780 Set_Ekind
(New_P
, E_Package
);
781 Set_Etype
(New_P
, Standard_Void_Type
);
783 if Present
(Renamed_Object
(Old_P
)) then
784 Set_Renamed_Object
(New_P
, Renamed_Object
(Old_P
));
786 Set_Renamed_Object
(New_P
, Old_P
);
789 Set_Has_Completion
(New_P
);
791 Set_First_Entity
(New_P
, First_Entity
(Old_P
));
792 Set_Last_Entity
(New_P
, Last_Entity
(Old_P
));
793 Set_First_Private_Entity
(New_P
, First_Private_Entity
(Old_P
));
794 Check_Library_Unit_Renaming
(N
, Old_P
);
795 Generate_Reference
(Old_P
, Name
(N
));
797 -- If this is the renaming declaration of a package instantiation
798 -- within itself, it is the declaration that ends the list of actuals
799 -- for the instantiation. At this point, the subtypes that rename
800 -- the actuals are flagged as generic, to avoid spurious ambiguities
801 -- if the actuals for two distinct formals happen to coincide. If
802 -- the actual is a private type, the subtype has a private completion
803 -- that is flagged in the same fashion.
805 -- Resolution is identical to what is was in the original generic.
806 -- On exit from the generic instance, these are turned into regular
807 -- subtypes again, so they are compatible with types in their class.
809 if not Is_Generic_Instance
(Old_P
) then
812 Spec
:= Specification
(Unit_Declaration_Node
(Old_P
));
815 if Nkind
(Spec
) = N_Package_Specification
816 and then Present
(Generic_Parent
(Spec
))
817 and then Old_P
= Current_Scope
818 and then Chars
(New_P
) = Chars
(Generic_Parent
(Spec
))
821 E
: Entity_Id
:= First_Entity
(Old_P
);
827 and then Nkind
(Parent
(E
)) = N_Subtype_Declaration
829 Set_Is_Generic_Actual_Type
(E
);
831 if Is_Private_Type
(E
)
832 and then Present
(Full_View
(E
))
834 Set_Is_Generic_Actual_Type
(Full_View
(E
));
844 end Analyze_Package_Renaming
;
846 -------------------------------
847 -- Analyze_Renamed_Character --
848 -------------------------------
850 procedure Analyze_Renamed_Character
855 C
: constant Node_Id
:= Name
(N
);
858 if Ekind
(New_S
) = E_Function
then
859 Resolve
(C
, Etype
(New_S
));
862 Check_Frozen_Renaming
(N
, New_S
);
866 Error_Msg_N
("character literal can only be renamed as function", N
);
868 end Analyze_Renamed_Character
;
870 ---------------------------------
871 -- Analyze_Renamed_Dereference --
872 ---------------------------------
874 procedure Analyze_Renamed_Dereference
879 Nam
: constant Node_Id
:= Name
(N
);
880 P
: constant Node_Id
:= Prefix
(Nam
);
886 if not Is_Overloaded
(P
) then
888 if Ekind
(Etype
(Nam
)) /= E_Subprogram_Type
889 or else not Type_Conformant
(Etype
(Nam
), New_S
) then
890 Error_Msg_N
("designated type does not match specification", P
);
892 Resolve
(P
, Etype
(P
));
899 Get_First_Interp
(Nam
, I
, It
);
901 while Present
(It
.Nam
) loop
903 if Ekind
(It
.Nam
) = E_Subprogram_Type
904 and then Type_Conformant
(It
.Nam
, New_S
) then
906 if Typ
/= Any_Id
then
907 Error_Msg_N
("ambiguous renaming", P
);
914 Get_Next_Interp
(I
, It
);
917 if Typ
= Any_Type
then
918 Error_Msg_N
("designated type does not match specification", P
);
923 Check_Frozen_Renaming
(N
, New_S
);
927 end Analyze_Renamed_Dereference
;
929 ---------------------------
930 -- Analyze_Renamed_Entry --
931 ---------------------------
933 procedure Analyze_Renamed_Entry
938 Nam
: Node_Id
:= Name
(N
);
939 Sel
: Node_Id
:= Selector_Name
(Nam
);
943 if Entity
(Sel
) = Any_Id
then
945 -- Selector is undefined on prefix. Error emitted already.
947 Set_Has_Completion
(New_S
);
951 -- Otherwise, find renamed entity, and build body of New_S as a call
954 Old_S
:= Find_Renamed_Entity
(N
, Selector_Name
(Nam
), New_S
);
956 if Old_S
= Any_Id
then
957 Error_Msg_N
(" no subprogram or entry matches specification", N
);
960 Check_Subtype_Conformant
(New_S
, Old_S
, N
);
961 Generate_Reference
(New_S
, Defining_Entity
(N
), 'b');
962 Style
.Check_Identifier
(Defining_Entity
(N
), New_S
);
965 Inherit_Renamed_Profile
(New_S
, Old_S
);
968 Set_Convention
(New_S
, Convention
(Old_S
));
969 Set_Has_Completion
(New_S
, Inside_A_Generic
);
972 Check_Frozen_Renaming
(N
, New_S
);
974 end Analyze_Renamed_Entry
;
976 -----------------------------------
977 -- Analyze_Renamed_Family_Member --
978 -----------------------------------
980 procedure Analyze_Renamed_Family_Member
985 Nam
: Node_Id
:= Name
(N
);
986 P
: Node_Id
:= Prefix
(Nam
);
990 if (Is_Entity_Name
(P
) and then Ekind
(Entity
(P
)) = E_Entry_Family
)
991 or else (Nkind
(P
) = N_Selected_Component
993 Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
)
995 if Is_Entity_Name
(P
) then
998 Old_S
:= Entity
(Selector_Name
(P
));
1001 if not Entity_Matches_Spec
(Old_S
, New_S
) then
1002 Error_Msg_N
("entry family does not match specification", N
);
1005 Check_Subtype_Conformant
(New_S
, Old_S
, N
);
1006 Generate_Reference
(New_S
, Defining_Entity
(N
), 'b');
1007 Style
.Check_Identifier
(Defining_Entity
(N
), New_S
);
1010 Error_Msg_N
("no entry family matches specification", N
);
1013 Set_Has_Completion
(New_S
, Inside_A_Generic
);
1016 Check_Frozen_Renaming
(N
, New_S
);
1018 end Analyze_Renamed_Family_Member
;
1020 ---------------------------------
1021 -- Analyze_Subprogram_Renaming --
1022 ---------------------------------
1024 procedure Analyze_Subprogram_Renaming
(N
: Node_Id
) is
1025 Nam
: Node_Id
:= Name
(N
);
1026 Spec
: constant Node_Id
:= Specification
(N
);
1028 Old_S
: Entity_Id
:= Empty
;
1029 Rename_Spec
: Entity_Id
;
1030 Is_Actual
: Boolean := False;
1031 Inst_Node
: Node_Id
:= Empty
;
1032 Save_83
: Boolean := Ada_83
;
1034 function Original_Subprogram
(Subp
: Entity_Id
) return Entity_Id
;
1035 -- Find renamed entity when the declaration is a renaming_as_body
1036 -- and the renamed entity may itself be a renaming_as_body. Used to
1037 -- enforce rule that a renaming_as_body is illegal if the declaration
1038 -- occurs before the subprogram it completes is frozen, and renaming
1039 -- indirectly renames the subprogram itself.(Defect Report 8652/0027).
1041 -------------------------
1042 -- Original_Subprogram --
1043 -------------------------
1045 function Original_Subprogram
(Subp
: Entity_Id
) return Entity_Id
is
1046 Orig_Decl
: Node_Id
;
1047 Orig_Subp
: Entity_Id
;
1050 -- First case: renamed entity is itself a renaming
1052 if Present
(Alias
(Subp
)) then
1053 return Alias
(Subp
);
1056 Nkind
(Unit_Declaration_Node
(Subp
)) = N_Subprogram_Declaration
1058 (Corresponding_Body
(Unit_Declaration_Node
(Subp
)))
1060 -- Check if renamed entity is a renaming_as_body
1063 Unit_Declaration_Node
1064 (Corresponding_Body
(Unit_Declaration_Node
(Subp
)));
1066 if Nkind
(Orig_Decl
) = N_Subprogram_Renaming_Declaration
then
1067 Orig_Subp
:= Entity
(Name
(Orig_Decl
));
1069 if Orig_Subp
= Rename_Spec
then
1071 -- Circularity detected.
1076 return (Original_Subprogram
(Orig_Subp
));
1084 end Original_Subprogram
;
1086 -- Start of procesing for Analyze_Subprogram_Renaming
1089 -- We must test for the attribute renaming case before the Analyze
1090 -- call because otherwise Sem_Attr will complain that the attribute
1091 -- is missing an argument when it is analyzed.
1093 if Nkind
(Nam
) = N_Attribute_Reference
then
1094 Attribute_Renaming
(N
);
1098 -- Check whether this declaration corresponds to the instantiation
1099 -- of a formal subprogram. This is indicated by the presence of a
1100 -- Corresponding_Spec that is the instantiation declaration.
1102 -- If this is an instantiation, the corresponding actual is frozen
1103 -- and error messages can be made more precise. If this is a default
1104 -- subprogram, the entity is already established in the generic, and
1105 -- is not retrieved by visibility. If it is a default with a box, the
1106 -- candidate interpretations, if any, have been collected when building
1107 -- the renaming declaration. If overloaded, the proper interpretation
1108 -- is determined in Find_Renamed_Entity. If the entity is an operator,
1109 -- Find_Renamed_Entity applies additional visibility checks.
1111 if Present
(Corresponding_Spec
(N
)) then
1113 Inst_Node
:= Corresponding_Spec
(N
);
1115 if Is_Entity_Name
(Nam
)
1116 and then Present
(Entity
(Nam
))
1117 and then not Comes_From_Source
(Nam
)
1118 and then not Is_Overloaded
(Nam
)
1120 Old_S
:= Entity
(Nam
);
1121 New_S
:= Analyze_Spec
(Spec
);
1123 if Ekind
(Entity
(Nam
)) = E_Operator
1124 and then Box_Present
(Corresponding_Spec
(N
))
1126 Old_S
:= Find_Renamed_Entity
(N
, Name
(N
), New_S
, Is_Actual
);
1131 New_S
:= Analyze_Spec
(Spec
);
1134 Set_Corresponding_Spec
(N
, Empty
);
1137 -- Renamed entity must be analyzed first, to avoid being hidden by
1138 -- new name (which might be the same in a generic instance).
1142 -- The renaming defines a new overloaded entity, which is analyzed
1143 -- like a subprogram declaration.
1145 New_S
:= Analyze_Spec
(Spec
);
1148 if Current_Scope
/= Standard_Standard
then
1149 Set_Is_Pure
(New_S
, Is_Pure
(Current_Scope
));
1152 Rename_Spec
:= Find_Corresponding_Spec
(N
);
1154 if Present
(Rename_Spec
) then
1156 -- Renaming_As_Body. Renaming declaration is the completion of
1157 -- the declaration of Rename_Spec. We will build an actual body
1158 -- for it at the freezing point.
1160 Set_Corresponding_Spec
(N
, Rename_Spec
);
1161 Set_Corresponding_Body
(Unit_Declaration_Node
(Rename_Spec
), New_S
);
1163 -- The body is created when the entity is frozen. If the context
1164 -- is generic, freeze_all is not invoked, so we need to indicate
1165 -- that the entity has a completion.
1167 Set_Has_Completion
(Rename_Spec
, Inside_A_Generic
);
1169 if Ada_83
and then Comes_From_Source
(N
) then
1170 Error_Msg_N
("(Ada 83) renaming cannot serve as a body", N
);
1173 Set_Convention
(New_S
, Convention
(Rename_Spec
));
1174 Check_Fully_Conformant
(New_S
, Rename_Spec
);
1175 Set_Public_Status
(New_S
);
1177 -- Indicate that the entity in the declaration functions like
1178 -- the corresponding body, and is not a new entity.
1180 Set_Ekind
(New_S
, E_Subprogram_Body
);
1181 New_S
:= Rename_Spec
;
1184 Generate_Definition
(New_S
);
1185 New_Overloaded_Entity
(New_S
);
1186 if Is_Entity_Name
(Nam
)
1187 and then Is_Intrinsic_Subprogram
(Entity
(Nam
))
1191 Check_Delayed_Subprogram
(New_S
);
1195 -- There is no need for elaboration checks on the new entity, which
1196 -- may be called before the next freezing point where the body will
1199 Set_Suppress_Elaboration_Checks
(New_S
, True);
1201 if Etype
(Nam
) = Any_Type
then
1202 Set_Has_Completion
(New_S
);
1205 elsif Nkind
(Nam
) = N_Selected_Component
then
1207 -- Renamed entity is an entry or protected subprogram. For those
1208 -- cases an explicit body is built (at the point of freezing of
1209 -- this entity) that contains a call to the renamed entity.
1211 Analyze_Renamed_Entry
(N
, New_S
, Present
(Rename_Spec
));
1214 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
1216 -- Renamed entity is designated by access_to_subprogram expression.
1217 -- Must build body to encapsulate call, as in the entry case.
1219 Analyze_Renamed_Dereference
(N
, New_S
, Present
(Rename_Spec
));
1222 elsif Nkind
(Nam
) = N_Indexed_Component
then
1223 Analyze_Renamed_Family_Member
(N
, New_S
, Present
(Rename_Spec
));
1226 elsif Nkind
(Nam
) = N_Character_Literal
then
1227 Analyze_Renamed_Character
(N
, New_S
, Present
(Rename_Spec
));
1230 elsif (not Is_Entity_Name
(Nam
)
1231 and then Nkind
(Nam
) /= N_Operator_Symbol
)
1232 or else not Is_Overloadable
(Entity
(Nam
))
1234 Error_Msg_N
("expect valid subprogram name in renaming", N
);
1239 -- Most common case: subprogram renames subprogram. No body is
1240 -- generated in this case, so we must indicate that the declaration
1241 -- is complete as is.
1243 if No
(Rename_Spec
) then
1244 Set_Has_Completion
(New_S
);
1247 -- Find the renamed entity that matches the given specification.
1248 -- Disable Ada_83 because there is no requirement of full conformance
1249 -- between renamed entity and new entity, even though the same circuit
1255 Old_S
:= Find_Renamed_Entity
(N
, Name
(N
), New_S
, Is_Actual
);
1258 if Old_S
/= Any_Id
then
1261 and then Box_Present
(Inst_Node
)
1263 -- This is an implicit reference to the default actual
1265 Generate_Reference
(Old_S
, Nam
, Typ
=> 'i', Force
=> True);
1267 Generate_Reference
(Old_S
, Nam
);
1270 -- For a renaming-as-body, require subtype conformance,
1271 -- but if the declaration being completed has not been
1272 -- frozen, then inherit the convention of the renamed
1273 -- subprogram prior to checking conformance (unless the
1274 -- renaming has an explicit convention established; the
1275 -- rule stated in the RM doesn't seem to address this ???).
1277 if Present
(Rename_Spec
) then
1278 Generate_Reference
(Rename_Spec
, Defining_Entity
(Spec
), 'b');
1279 Style
.Check_Identifier
(Defining_Entity
(Spec
), Rename_Spec
);
1281 if not Is_Frozen
(Rename_Spec
) then
1282 if not Has_Convention_Pragma
(Rename_Spec
) then
1283 Set_Convention
(New_S
, Convention
(Old_S
));
1286 if Ekind
(Old_S
) /= E_Operator
then
1287 Check_Mode_Conformant
(New_S
, Old_S
, Spec
);
1290 if Original_Subprogram
(Old_S
) = Rename_Spec
then
1291 Error_Msg_N
("unfrozen subprogram cannot rename itself ", N
);
1294 Check_Subtype_Conformant
(New_S
, Old_S
, Spec
);
1297 Check_Frozen_Renaming
(N
, Rename_Spec
);
1299 elsif Ekind
(Old_S
) /= E_Operator
then
1300 Check_Mode_Conformant
(New_S
, Old_S
);
1303 and then Error_Posted
(New_S
)
1305 Error_Msg_NE
("invalid actual subprogram: & #!", N
, Old_S
);
1309 if No
(Rename_Spec
) then
1311 -- The parameter profile of the new entity is that of the renamed
1312 -- entity: the subtypes given in the specification are irrelevant.
1314 Inherit_Renamed_Profile
(New_S
, Old_S
);
1316 -- A call to the subprogram is transformed into a call to the
1317 -- renamed entity. This is transitive if the renamed entity is
1318 -- itself a renaming.
1320 if Present
(Alias
(Old_S
)) then
1321 Set_Alias
(New_S
, Alias
(Old_S
));
1323 Set_Alias
(New_S
, Old_S
);
1326 -- Note that we do not set Is_Instrinsic_Subprogram if we have
1327 -- a renaming as body, since the entity in this case is not an
1328 -- intrinsic (it calls an intrinsic, but we have a real body
1329 -- for this call, and it is in this body that the required
1330 -- intrinsic processing will take place).
1332 Set_Is_Intrinsic_Subprogram
1333 (New_S
, Is_Intrinsic_Subprogram
(Old_S
));
1335 if Ekind
(Alias
(New_S
)) = E_Operator
then
1336 Set_Has_Delayed_Freeze
(New_S
, False);
1342 and then (Old_S
= New_S
1343 or else (Nkind
(Nam
) /= N_Expanded_Name
1344 and then Chars
(Old_S
) = Chars
(New_S
)))
1346 Error_Msg_N
("subprogram cannot rename itself", N
);
1349 Set_Convention
(New_S
, Convention
(Old_S
));
1350 Set_Is_Abstract
(New_S
, Is_Abstract
(Old_S
));
1351 Check_Library_Unit_Renaming
(N
, Old_S
);
1353 -- Pathological case: procedure renames entry in the scope of
1354 -- its task. Entry is given by simple name, but body must be built
1355 -- for procedure. Of course if called it will deadlock.
1357 if Ekind
(Old_S
) = E_Entry
then
1358 Set_Has_Completion
(New_S
, False);
1359 Set_Alias
(New_S
, Empty
);
1363 Freeze_Before
(N
, Old_S
);
1364 Set_Has_Delayed_Freeze
(New_S
, False);
1365 Freeze_Before
(N
, New_S
);
1367 if (Ekind
(Old_S
) = E_Procedure
or else Ekind
(Old_S
) = E_Function
)
1368 and then Is_Abstract
(Old_S
)
1371 ("abstract subprogram not allowed as generic actual", Nam
);
1376 -- A common error is to assume that implicit operators for types
1377 -- are defined in Standard, or in the scope of a subtype. In those
1378 -- cases where the renamed entity is given with an expanded name,
1379 -- it is worth mentioning that operators for the type are not
1380 -- declared in the scope given by the prefix.
1382 if Nkind
(Nam
) = N_Expanded_Name
1383 and then Nkind
(Selector_Name
(Nam
)) = N_Operator_Symbol
1384 and then Scope
(Entity
(Nam
)) = Standard_Standard
1387 T
: constant Entity_Id
:=
1388 Base_Type
(Etype
(First_Formal
(New_S
)));
1391 Error_Msg_Node_2
:= Prefix
(Nam
);
1392 Error_Msg_NE
("\operator for type& is not declared in&",
1397 ("no visible subprogram matches the specification for&",
1401 if Present
(Candidate_Renaming
) then
1407 F1
:= First_Formal
(Candidate_Renaming
);
1408 F2
:= First_Formal
(New_S
);
1410 while Present
(F1
) and then Present
(F2
) loop
1415 if Present
(F1
) and then Present
(Default_Value
(F1
)) then
1416 if Present
(Next_Formal
(F1
)) then
1418 ("\missing specification for &" &
1419 " and other formals with defaults", Spec
, F1
);
1422 ("\missing specification for &", Spec
, F1
);
1430 end Analyze_Subprogram_Renaming
;
1432 -------------------------
1433 -- Analyze_Use_Package --
1434 -------------------------
1436 -- Resolve the package names in the use clause, and make all the visible
1437 -- entities defined in the package potentially use-visible. If the package
1438 -- is already in use from a previous use clause, its visible entities are
1439 -- already use-visible. In that case, mark the occurrence as a redundant
1440 -- use. If the package is an open scope, i.e. if the use clause occurs
1441 -- within the package itself, ignore it.
1443 procedure Analyze_Use_Package
(N
: Node_Id
) is
1444 Pack_Name
: Node_Id
;
1447 function In_Previous_With_Clause
return Boolean;
1448 -- For use clauses in a context clause, the indicated package may
1449 -- be visible and yet illegal, if it did not appear in a previous
1452 -----------------------------
1453 -- In_Previous_With_Clause --
1454 -----------------------------
1456 function In_Previous_With_Clause
return Boolean is
1460 Item
:= First
(Context_Items
(Parent
(N
)));
1462 while Present
(Item
)
1465 if Nkind
(Item
) = N_With_Clause
1466 and then Entity
(Name
(Item
)) = Pack
1475 end In_Previous_With_Clause
;
1477 -- Start of processing for Analyze_Use_Package
1480 Set_Hidden_By_Use_Clause
(N
, No_Elist
);
1482 -- Use clause is not allowed in a spec of a predefined package
1483 -- declaration except that packages whose file name starts a-n
1484 -- are OK (these are children of Ada.Numerics, and such packages
1485 -- are never loaded by Rtsfind).
1487 if Is_Predefined_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
1488 and then Name_Buffer
(1 .. 3) /= "a-n"
1490 Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) = N_Package_Declaration
1492 Error_Msg_N
("use clause not allowed in predefined spec", N
);
1495 -- Chain clause to list of use clauses in current scope.
1497 if Nkind
(Parent
(N
)) /= N_Compilation_Unit
then
1498 Chain_Use_Clause
(N
);
1501 -- Loop through package names to identify referenced packages
1503 Pack_Name
:= First
(Names
(N
));
1505 while Present
(Pack_Name
) loop
1506 Analyze
(Pack_Name
);
1508 if Nkind
(Parent
(N
)) = N_Compilation_Unit
1509 and then Nkind
(Pack_Name
) = N_Expanded_Name
1512 Pref
: Node_Id
:= Prefix
(Pack_Name
);
1515 while Nkind
(Pref
) = N_Expanded_Name
loop
1516 Pref
:= Prefix
(Pref
);
1519 if Entity
(Pref
) = Standard_Standard
then
1521 ("predefined package Standard cannot appear"
1522 & " in a context clause", Pref
);
1530 -- Loop through package names to mark all entities as potentially
1533 Pack_Name
:= First
(Names
(N
));
1535 while Present
(Pack_Name
) loop
1537 if Is_Entity_Name
(Pack_Name
) then
1538 Pack
:= Entity
(Pack_Name
);
1540 if Ekind
(Pack
) /= E_Package
1541 and then Etype
(Pack
) /= Any_Type
1543 if Ekind
(Pack
) = E_Generic_Package
then
1545 ("a generic package is not allowed in a use clause",
1548 Error_Msg_N
("& is not a usable package", Pack_Name
);
1551 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
1552 and then Nkind
(Pack_Name
) /= N_Expanded_Name
1553 and then not In_Previous_With_Clause
1555 Error_Msg_N
("package is not directly visible", Pack_Name
);
1557 elsif Applicable_Use
(Pack_Name
) then
1558 Use_One_Package
(Pack
, N
);
1565 end Analyze_Use_Package
;
1567 ----------------------
1568 -- Analyze_Use_Type --
1569 ----------------------
1571 procedure Analyze_Use_Type
(N
: Node_Id
) is
1575 Set_Hidden_By_Use_Clause
(N
, No_Elist
);
1577 -- Chain clause to list of use clauses in current scope.
1579 if Nkind
(Parent
(N
)) /= N_Compilation_Unit
then
1580 Chain_Use_Clause
(N
);
1583 Id
:= First
(Subtype_Marks
(N
));
1585 while Present
(Id
) loop
1588 if Entity
(Id
) /= Any_Type
then
1594 end Analyze_Use_Type
;
1596 --------------------
1597 -- Applicable_Use --
1598 --------------------
1600 function Applicable_Use
(Pack_Name
: Node_Id
) return Boolean is
1601 Pack
: constant Entity_Id
:= Entity
(Pack_Name
);
1604 if In_Open_Scopes
(Pack
) then
1607 elsif In_Use
(Pack
) then
1608 Set_Redundant_Use
(Pack_Name
, True);
1611 elsif Present
(Renamed_Object
(Pack
))
1612 and then In_Use
(Renamed_Object
(Pack
))
1614 Set_Redundant_Use
(Pack_Name
, True);
1622 ------------------------
1623 -- Attribute_Renaming --
1624 ------------------------
1626 procedure Attribute_Renaming
(N
: Node_Id
) is
1627 Loc
: constant Source_Ptr
:= Sloc
(N
);
1628 Nam
: constant Node_Id
:= Name
(N
);
1629 Spec
: constant Node_Id
:= Specification
(N
);
1630 New_S
: constant Entity_Id
:= Defining_Unit_Name
(Spec
);
1631 Aname
: constant Name_Id
:= Attribute_Name
(Nam
);
1633 Form_Num
: Nat
:= 0;
1634 Expr_List
: List_Id
:= No_List
;
1636 Attr_Node
: Node_Id
;
1637 Body_Node
: Node_Id
;
1638 Param_Spec
: Node_Id
;
1641 Generate_Definition
(New_S
);
1643 -- This procedure is called in the context of subprogram renaming,
1644 -- and thus the attribute must be one that is a subprogram. All of
1645 -- those have at least one formal parameter, with the singular
1646 -- exception of AST_Entry (which is a real oddity, it is odd that
1647 -- this can be renamed at all!)
1649 if not Is_Non_Empty_List
(Parameter_Specifications
(Spec
)) then
1650 if Aname
/= Name_AST_Entry
then
1652 ("subprogram renaming an attribute must have formals", N
);
1657 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
1659 while Present
(Param_Spec
) loop
1660 Form_Num
:= Form_Num
+ 1;
1662 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
1663 Find_Type
(Parameter_Type
(Param_Spec
));
1665 -- The profile of the new entity denotes the base type (s) of
1666 -- the types given in the specification. For access parameters
1667 -- there are no subtypes involved.
1669 Rewrite
(Parameter_Type
(Param_Spec
),
1671 (Base_Type
(Entity
(Parameter_Type
(Param_Spec
))), Loc
));
1674 if No
(Expr_List
) then
1675 Expr_List
:= New_List
;
1678 Append_To
(Expr_List
,
1679 Make_Identifier
(Loc
,
1680 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
1686 -- Immediate error if too many formals. Other mismatches in numbers
1687 -- of number of types of parameters are detected when we analyze the
1688 -- body of the subprogram that we construct.
1690 if Form_Num
> 2 then
1691 Error_Msg_N
("too many formals for attribute", N
);
1694 Aname
= Name_Compose
or else
1695 Aname
= Name_Exponent
or else
1696 Aname
= Name_Leading_Part
or else
1697 Aname
= Name_Pos
or else
1698 Aname
= Name_Round
or else
1699 Aname
= Name_Scaling
or else
1702 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
1703 and then Present
(Corresponding_Spec
(N
))
1704 and then Nkind
(Corresponding_Spec
(N
)) =
1705 N_Formal_Subprogram_Declaration
1708 ("generic actual cannot be attribute involving universal type",
1712 ("attribute involving a universal type cannot be renamed",
1717 -- AST_Entry is an odd case. It doesn't really make much sense to
1718 -- allow it to be renamed, but that's the DEC rule, so we have to
1719 -- do it right. The point is that the AST_Entry call should be made
1720 -- now, and what the function will return is the returned value.
1722 -- Note that there is no Expr_List in this case anyway
1724 if Aname
= Name_AST_Entry
then
1731 Ent
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
1734 Make_Object_Declaration
(Loc
,
1735 Defining_Identifier
=> Ent
,
1736 Object_Definition
=>
1737 New_Occurrence_Of
(RTE
(RE_AST_Handler
), Loc
),
1739 Constant_Present
=> True);
1741 Set_Assignment_OK
(Decl
, True);
1742 Insert_Action
(N
, Decl
);
1743 Attr_Node
:= Make_Identifier
(Loc
, Chars
(Ent
));
1746 -- For all other attributes, we rewrite the attribute node to have
1747 -- a list of expressions corresponding to the subprogram formals.
1748 -- A renaming declaration is not a freeze point, and the analysis of
1749 -- the attribute reference should not freeze the type of the prefix.
1753 Make_Attribute_Reference
(Loc
,
1754 Prefix
=> Prefix
(Nam
),
1755 Attribute_Name
=> Aname
,
1756 Expressions
=> Expr_List
);
1758 Set_Must_Not_Freeze
(Attr_Node
);
1759 Set_Must_Not_Freeze
(Prefix
(Nam
));
1762 -- Case of renaming a function
1764 if Nkind
(Spec
) = N_Function_Specification
then
1766 if Is_Procedure_Attribute_Name
(Aname
) then
1767 Error_Msg_N
("attribute can only be renamed as procedure", Nam
);
1771 Find_Type
(Subtype_Mark
(Spec
));
1772 Rewrite
(Subtype_Mark
(Spec
),
1773 New_Reference_To
(Base_Type
(Entity
(Subtype_Mark
(Spec
))), Loc
));
1776 Make_Subprogram_Body
(Loc
,
1777 Specification
=> Spec
,
1778 Declarations
=> New_List
,
1779 Handled_Statement_Sequence
=>
1780 Make_Handled_Sequence_Of_Statements
(Loc
,
1781 Statements
=> New_List
(
1782 Make_Return_Statement
(Loc
,
1783 Expression
=> Attr_Node
))));
1785 -- Case of renaming a procedure
1788 if not Is_Procedure_Attribute_Name
(Aname
) then
1789 Error_Msg_N
("attribute can only be renamed as function", Nam
);
1794 Make_Subprogram_Body
(Loc
,
1795 Specification
=> Spec
,
1796 Declarations
=> New_List
,
1797 Handled_Statement_Sequence
=>
1798 Make_Handled_Sequence_Of_Statements
(Loc
,
1799 Statements
=> New_List
(Attr_Node
)));
1802 Rewrite
(N
, Body_Node
);
1805 Set_Etype
(New_S
, Base_Type
(Etype
(New_S
)));
1807 -- We suppress elaboration warnings for the resulting entity, since
1808 -- clearly they are not needed, and more particularly, in the case
1809 -- of a generic formal subprogram, the resulting entity can appear
1810 -- after the instantiation itself, and thus look like a bogus case
1811 -- of access before elaboration.
1813 Set_Suppress_Elaboration_Warnings
(New_S
);
1815 end Attribute_Renaming
;
1817 ----------------------
1818 -- Chain_Use_Clause --
1819 ----------------------
1821 procedure Chain_Use_Clause
(N
: Node_Id
) is
1823 Set_Next_Use_Clause
(N
,
1824 Scope_Stack
.Table
(Scope_Stack
.Last
).First_Use_Clause
);
1825 Scope_Stack
.Table
(Scope_Stack
.Last
).First_Use_Clause
:= N
;
1826 end Chain_Use_Clause
;
1828 ----------------------------
1829 -- Check_Frozen_Renaming --
1830 ----------------------------
1832 procedure Check_Frozen_Renaming
(N
: Node_Id
; Subp
: Entity_Id
) is
1838 and then not Has_Completion
(Subp
)
1842 (Parent
(Declaration_Node
(Subp
)), Defining_Entity
(N
));
1844 if Is_Entity_Name
(Name
(N
)) then
1845 Old_S
:= Entity
(Name
(N
));
1847 if not Is_Frozen
(Old_S
) then
1848 Ensure_Freeze_Node
(Old_S
);
1849 if No
(Actions
(Freeze_Node
(Old_S
))) then
1850 Set_Actions
(Freeze_Node
(Old_S
), New_List
(B_Node
));
1852 Append
(B_Node
, Actions
(Freeze_Node
(Old_S
)));
1855 Insert_After
(N
, B_Node
);
1859 if Is_Intrinsic_Subprogram
(Old_S
)
1860 and then not In_Instance
1863 ("subprogram used in renaming_as_body cannot be intrinsic",
1868 Insert_After
(N
, B_Node
);
1872 end Check_Frozen_Renaming
;
1874 ---------------------------------
1875 -- Check_Library_Unit_Renaming --
1876 ---------------------------------
1878 procedure Check_Library_Unit_Renaming
(N
: Node_Id
; Old_E
: Entity_Id
) is
1882 if Nkind
(Parent
(N
)) /= N_Compilation_Unit
then
1885 elsif Scope
(Old_E
) /= Standard_Standard
1886 and then not Is_Child_Unit
(Old_E
)
1888 Error_Msg_N
("renamed unit must be a library unit", Name
(N
));
1890 elsif Present
(Parent_Spec
(N
))
1891 and then Nkind
(Unit
(Parent_Spec
(N
))) = N_Generic_Package_Declaration
1892 and then not Is_Child_Unit
(Old_E
)
1895 ("renamed unit must be a child unit of generic parent", Name
(N
));
1897 elsif Nkind
(N
) in N_Generic_Renaming_Declaration
1898 and then Nkind
(Name
(N
)) = N_Expanded_Name
1899 and then Is_Generic_Instance
(Entity
(Prefix
(Name
(N
))))
1900 and then Is_Generic_Unit
(Old_E
)
1903 ("renamed generic unit must be a library unit", Name
(N
));
1905 elsif Ekind
(Old_E
) = E_Package
1906 or else Ekind
(Old_E
) = E_Generic_Package
1908 -- Inherit categorization flags
1910 New_E
:= Defining_Entity
(N
);
1911 Set_Is_Pure
(New_E
, Is_Pure
(Old_E
));
1912 Set_Is_Preelaborated
(New_E
, Is_Preelaborated
(Old_E
));
1913 Set_Is_Remote_Call_Interface
(New_E
,
1914 Is_Remote_Call_Interface
(Old_E
));
1915 Set_Is_Remote_Types
(New_E
, Is_Remote_Types
(Old_E
));
1916 Set_Is_Shared_Passive
(New_E
, Is_Shared_Passive
(Old_E
));
1918 end Check_Library_Unit_Renaming
;
1924 procedure End_Scope
is
1930 Id
:= First_Entity
(Current_Scope
);
1932 while Present
(Id
) loop
1933 -- An entity in the current scope is not necessarily the first one
1934 -- on its homonym chain. Find its predecessor if any,
1935 -- If it is an internal entity, it will not be in the visibility
1936 -- chain altogether, and there is nothing to unchain.
1938 if Id
/= Current_Entity
(Id
) then
1939 Prev
:= Current_Entity
(Id
);
1940 while Present
(Prev
)
1941 and then Present
(Homonym
(Prev
))
1942 and then Homonym
(Prev
) /= Id
1944 Prev
:= Homonym
(Prev
);
1947 -- Skip to end of loop if Id is not in the visibility chain
1949 if No
(Prev
) or else Homonym
(Prev
) /= Id
then
1957 Outer
:= Homonym
(Id
);
1958 Set_Is_Immediately_Visible
(Id
, False);
1960 while Present
(Outer
) and then Scope
(Outer
) = Current_Scope
loop
1961 Outer
:= Homonym
(Outer
);
1964 -- Reset homonym link of other entities, but do not modify link
1965 -- between entities in current scope, so that the back-end can have
1966 -- a proper count of local overloadings.
1969 Set_Name_Entity_Id
(Chars
(Id
), Outer
);
1971 elsif Scope
(Prev
) /= Scope
(Id
) then
1972 Set_Homonym
(Prev
, Outer
);
1979 -- If the scope generated freeze actions, place them before the
1980 -- current declaration and analyze them. Type declarations and
1981 -- the bodies of initialization procedures can generate such nodes.
1982 -- We follow the parent chain until we reach a list node, which is
1983 -- the enclosing list of declarations. If the list appears within
1984 -- a protected definition, move freeze nodes outside the protected
1988 (Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
)
1992 L
: constant List_Id
:= Scope_Stack
.Table
1993 (Scope_Stack
.Last
).Pending_Freeze_Actions
;
1996 if Is_Itype
(Current_Scope
) then
1997 Decl
:= Associated_Node_For_Itype
(Current_Scope
);
1999 Decl
:= Parent
(Current_Scope
);
2004 while not (Is_List_Member
(Decl
))
2005 or else Nkind
(Parent
(Decl
)) = N_Protected_Definition
2006 or else Nkind
(Parent
(Decl
)) = N_Task_Definition
2008 Decl
:= Parent
(Decl
);
2011 Insert_List_Before_And_Analyze
(Decl
, L
);
2020 ---------------------
2021 -- End_Use_Clauses --
2022 ---------------------
2024 procedure End_Use_Clauses
(Clause
: Node_Id
) is
2025 U
: Node_Id
:= Clause
;
2028 while Present
(U
) loop
2029 if Nkind
(U
) = N_Use_Package_Clause
then
2030 End_Use_Package
(U
);
2031 elsif Nkind
(U
) = N_Use_Type_Clause
then
2035 Next_Use_Clause
(U
);
2037 end End_Use_Clauses
;
2039 ---------------------
2040 -- End_Use_Package --
2041 ---------------------
2043 procedure End_Use_Package
(N
: Node_Id
) is
2044 Pack_Name
: Node_Id
;
2050 Pack_Name
:= First
(Names
(N
));
2052 while Present
(Pack_Name
) loop
2053 Pack
:= Entity
(Pack_Name
);
2055 if Ekind
(Pack
) = E_Package
then
2057 if In_Open_Scopes
(Pack
) then
2060 elsif not Redundant_Use
(Pack_Name
) then
2061 Set_In_Use
(Pack
, False);
2062 Id
:= First_Entity
(Pack
);
2064 while Present
(Id
) loop
2066 -- Preserve use-visibility of operators whose formals have
2067 -- a type that is use_visible thanks to a previous use_type
2070 if Nkind
(Id
) = N_Defining_Operator_Symbol
2072 (In_Use
(Etype
(First_Formal
(Id
)))
2074 (Present
(Next_Formal
(First_Formal
(Id
)))
2075 and then In_Use
(Etype
(Next_Formal
2076 (First_Formal
(Id
))))))
2081 Set_Is_Potentially_Use_Visible
(Id
, False);
2084 if Is_Private_Type
(Id
)
2085 and then Present
(Full_View
(Id
))
2087 Set_Is_Potentially_Use_Visible
(Full_View
(Id
), False);
2093 if Present
(Renamed_Object
(Pack
)) then
2094 Set_In_Use
(Renamed_Object
(Pack
), False);
2097 if Chars
(Pack
) = Name_System
2098 and then Scope
(Pack
) = Standard_Standard
2099 and then Present_System_Aux
2101 Id
:= First_Entity
(System_Aux_Id
);
2103 while Present
(Id
) loop
2104 Set_Is_Potentially_Use_Visible
(Id
, False);
2106 if Is_Private_Type
(Id
)
2107 and then Present
(Full_View
(Id
))
2109 Set_Is_Potentially_Use_Visible
(Full_View
(Id
), False);
2115 Set_In_Use
(System_Aux_Id
, False);
2119 Set_Redundant_Use
(Pack_Name
, False);
2127 if Present
(Hidden_By_Use_Clause
(N
)) then
2128 Elmt
:= First_Elmt
(Hidden_By_Use_Clause
(N
));
2130 while Present
(Elmt
) loop
2131 Set_Is_Immediately_Visible
(Node
(Elmt
));
2135 Set_Hidden_By_Use_Clause
(N
, No_Elist
);
2137 end End_Use_Package
;
2143 procedure End_Use_Type
(N
: Node_Id
) is
2150 Id
:= First
(Subtype_Marks
(N
));
2152 while Present
(Id
) loop
2155 if T
= Any_Type
then
2158 -- Note that the use_Type clause may mention a subtype of the
2159 -- type whose primitive operations have been made visible. Here
2160 -- as elsewhere, it is the base type that matters for visibility.
2162 elsif In_Open_Scopes
(Scope
(Base_Type
(T
))) then
2165 elsif not Redundant_Use
(Id
) then
2166 Set_In_Use
(T
, False);
2167 Set_In_Use
(Base_Type
(T
), False);
2168 Op_List
:= Collect_Primitive_Operations
(T
);
2169 Elmt
:= First_Elmt
(Op_List
);
2171 while Present
(Elmt
) loop
2173 if Nkind
(Node
(Elmt
)) = N_Defining_Operator_Symbol
then
2174 Set_Is_Potentially_Use_Visible
(Node
(Elmt
), False);
2185 ----------------------
2186 -- Find_Direct_Name --
2187 ----------------------
2189 procedure Find_Direct_Name
(N
: Node_Id
) is
2194 Inst
: Entity_Id
:= Empty
;
2195 -- Enclosing instance, if any.
2197 Homonyms
: Entity_Id
;
2198 -- Saves start of homonym chain
2200 Nvis_Entity
: Boolean;
2201 -- Set True to indicate that at there is at least one entity on the
2202 -- homonym chain which, while not visible, is visible enough from the
2203 -- user point of view to warrant an error message of "not visible"
2204 -- rather than undefined.
2206 function From_Actual_Package
(E
: Entity_Id
) return Boolean;
2207 -- Returns true if the entity is declared in a package that is
2208 -- an actual for a formal package of the current instance. Such an
2209 -- entity requires special handling because it may be use-visible
2210 -- but hides directly visible entities defined outside the instance.
2212 function Known_But_Invisible
(E
: Entity_Id
) return Boolean;
2213 -- This function determines whether the entity E (which is not
2214 -- visible) can reasonably be considered to be known to the writer
2215 -- of the reference. This is a heuristic test, used only for the
2216 -- purposes of figuring out whether we prefer to complain that an
2217 -- entity is undefined or invisible (and identify the declaration
2218 -- of the invisible entity in the latter case). The point here is
2219 -- that we don't want to complain that something is invisible and
2220 -- then point to something entirely mysterious to the writer.
2222 procedure Nvis_Messages
;
2223 -- Called if there are no visible entries for N, but there is at least
2224 -- one non-directly visible, or hidden declaration. This procedure
2225 -- outputs an appropriate set of error messages.
2227 procedure Undefined
(Nvis
: Boolean);
2228 -- This function is called if the current node has no corresponding
2229 -- visible entity or entities. The value set in Msg indicates whether
2230 -- an error message was generated (multiple error messages for the
2231 -- same variable are generally suppressed, see body for details).
2232 -- Msg is True if an error message was generated, False if not. This
2233 -- value is used by the caller to determine whether or not to output
2234 -- additional messages where appropriate. The parameter is set False
2235 -- to get the message "X is undefined", and True to get the message
2236 -- "X is not visible".
2238 -------------------------
2239 -- From_Actual_Package --
2240 -------------------------
2242 function From_Actual_Package
(E
: Entity_Id
) return Boolean is
2243 Scop
: constant Entity_Id
:= Scope
(E
);
2247 if not In_Instance
then
2250 Inst
:= Current_Scope
;
2252 while Present
(Inst
)
2253 and then Ekind
(Inst
) /= E_Package
2254 and then not Is_Generic_Instance
(Inst
)
2256 Inst
:= Scope
(Inst
);
2263 Act
:= First_Entity
(Inst
);
2265 while Present
(Act
) loop
2266 if Ekind
(Act
) = E_Package
then
2268 -- Check for end of actuals list
2270 if Renamed_Object
(Act
) = Inst
then
2273 elsif Present
(Associated_Formal_Package
(Act
))
2274 and then Renamed_Object
(Act
) = Scop
2276 -- Entity comes from (instance of) formal package
2291 end From_Actual_Package
;
2293 -------------------------
2294 -- Known_But_Invisible --
2295 -------------------------
2297 function Known_But_Invisible
(E
: Entity_Id
) return Boolean is
2298 Fname
: File_Name_Type
;
2301 -- Entities in Standard are always considered to be known
2303 if Sloc
(E
) <= Standard_Location
then
2306 -- An entity that does not come from source is always considered
2307 -- to be unknown, since it is an artifact of code expansion.
2309 elsif not Comes_From_Source
(E
) then
2312 -- In gnat internal mode, we consider all entities known
2314 elsif GNAT_Mode
then
2318 -- Here we have an entity that is not from package Standard, and
2319 -- which comes from Source. See if it comes from an internal file.
2321 Fname
:= Unit_File_Name
(Get_Source_Unit
(E
));
2323 -- Case of from internal file
2325 if Is_Internal_File_Name
(Fname
) then
2327 -- Private part entities in internal files are never considered
2328 -- to be known to the writer of normal application code.
2330 if Is_Hidden
(E
) then
2334 -- Entities from System packages other than System and
2335 -- System.Storage_Elements are not considered to be known.
2336 -- System.Auxxxx files are also considered known to the user.
2338 -- Should refine this at some point to generally distinguish
2339 -- between known and unknown internal files ???
2341 Get_Name_String
(Fname
);
2346 Name_Buffer
(1 .. 2) /= "s-"
2348 Name_Buffer
(3 .. 8) = "stoele"
2350 Name_Buffer
(3 .. 5) = "aux";
2352 -- If not an internal file, then entity is definitely known,
2353 -- even if it is in a private part (the message generated will
2354 -- note that it is in a private part)
2359 end Known_But_Invisible
;
2365 procedure Nvis_Messages
is
2367 Hidden
: Boolean := False;
2370 Undefined
(Nvis
=> True);
2374 -- First loop does hidden declarations
2377 while Present
(Ent
) loop
2378 if Is_Potentially_Use_Visible
(Ent
) then
2381 Error_Msg_N
("multiple use clauses cause hiding!", N
);
2385 Error_Msg_Sloc
:= Sloc
(Ent
);
2386 Error_Msg_N
("hidden declaration#!", N
);
2389 Ent
:= Homonym
(Ent
);
2392 -- If we found hidden declarations, then that's enough, don't
2393 -- bother looking for non-visible declarations as well.
2399 -- Second loop does non-directly visible declarations
2402 while Present
(Ent
) loop
2403 if not Is_Potentially_Use_Visible
(Ent
) then
2405 -- Do not bother the user with unknown entities
2407 if not Known_But_Invisible
(Ent
) then
2411 Error_Msg_Sloc
:= Sloc
(Ent
);
2413 -- Output message noting that there is a non-visible
2414 -- declaration, distinguishing the private part case.
2416 if Is_Hidden
(Ent
) then
2417 Error_Msg_N
("non-visible (private) declaration#!", N
);
2419 Error_Msg_N
("non-visible declaration#!", N
);
2422 -- Set entity and its containing package as referenced. We
2423 -- can't be sure of this, but this seems a better choice
2424 -- to avoid unused entity messages.
2426 if Comes_From_Source
(Ent
) then
2427 Set_Referenced
(Ent
);
2428 Set_Referenced
(Cunit_Entity
(Get_Source_Unit
(Ent
)));
2433 Ent
:= Homonym
(Ent
);
2443 procedure Undefined
(Nvis
: Boolean) is
2444 Emsg
: Error_Msg_Id
;
2447 -- A very specialized error check, if the undefined variable is
2448 -- a case tag, and the case type is an enumeration type, check
2449 -- for a possible misspelling, and if so, modify the identifier
2451 -- Named aggregate should also be handled similarly ???
2453 if Nkind
(N
) = N_Identifier
2454 and then Nkind
(Parent
(N
)) = N_Case_Statement_Alternative
2456 Get_Name_String
(Chars
(N
));
2459 Case_Str
: constant String := Name_Buffer
(1 .. Name_Len
);
2460 Case_Stm
: constant Node_Id
:= Parent
(Parent
(N
));
2461 Case_Typ
: constant Entity_Id
:= Etype
(Expression
(Case_Stm
));
2466 if Is_Enumeration_Type
(Case_Typ
)
2467 and then Case_Typ
/= Standard_Character
2468 and then Case_Typ
/= Standard_Wide_Character
2470 Lit
:= First_Literal
(Case_Typ
);
2471 Get_Name_String
(Chars
(Lit
));
2473 if Chars
(Lit
) /= Chars
(N
)
2474 and then Is_Bad_Spelling_Of
2475 (Case_Str
, Name_Buffer
(1 .. Name_Len
))
2477 Error_Msg_Node_2
:= Lit
;
2479 ("& is undefined, assume misspelling of &", N
);
2480 Rewrite
(N
, New_Occurrence_Of
(Lit
, Sloc
(N
)));
2484 Lit
:= Next_Literal
(Lit
);
2489 -- Normal processing
2491 Set_Entity
(N
, Any_Id
);
2492 Set_Etype
(N
, Any_Type
);
2494 -- We use the table Urefs to keep track of entities for which we
2495 -- have issued errors for undefined references. Multiple errors
2496 -- for a single name are normally suppressed, however we modify
2497 -- the error message to alert the programmer to this effect.
2499 for J
in Urefs
.First
.. Urefs
.Last
loop
2500 if Chars
(N
) = Chars
(Urefs
.Table
(J
).Node
) then
2501 if Urefs
.Table
(J
).Err
/= No_Error_Msg
2502 and then Sloc
(N
) /= Urefs
.Table
(J
).Loc
2504 Error_Msg_Node_1
:= Urefs
.Table
(J
).Node
;
2506 if Urefs
.Table
(J
).Nvis
then
2507 Change_Error_Text
(Urefs
.Table
(J
).Err
,
2508 "& is not visible (more references follow)");
2510 Change_Error_Text
(Urefs
.Table
(J
).Err
,
2511 "& is undefined (more references follow)");
2514 Urefs
.Table
(J
).Err
:= No_Error_Msg
;
2517 -- Although we will set Msg False, and thus suppress the
2518 -- message, we also set Error_Posted True, to avoid any
2519 -- cascaded messages resulting from the undefined reference.
2522 Set_Error_Posted
(N
, True);
2527 -- If entry not found, this is first undefined occurrence
2530 Error_Msg_N
("& is not visible!", N
);
2534 Error_Msg_N
("& is undefined!", N
);
2537 -- A very bizarre special check, if the undefined identifier
2538 -- is put or put_line, then add a special error message (since
2539 -- this is a very common error for beginners to make).
2541 if Chars
(N
) = Name_Put
or else Chars
(N
) = Name_Put_Line
then
2542 Error_Msg_N
("\possible missing with of 'Text_'I'O!", N
);
2545 -- Now check for possible misspellings
2547 Get_Name_String
(Chars
(N
));
2551 Ematch
: Entity_Id
:= Empty
;
2553 Last_Name_Id
: constant Name_Id
:=
2554 Name_Id
(Nat
(First_Name_Id
) +
2555 Name_Entries_Count
- 1);
2557 S
: constant String (1 .. Name_Len
) :=
2558 Name_Buffer
(1 .. Name_Len
);
2561 for N
in First_Name_Id
.. Last_Name_Id
loop
2562 E
:= Get_Name_Entity_Id
(N
);
2565 and then (Is_Immediately_Visible
(E
)
2567 Is_Potentially_Use_Visible
(E
))
2569 Get_Name_String
(N
);
2571 if Is_Bad_Spelling_Of
2572 (Name_Buffer
(1 .. Name_Len
), S
)
2580 if Present
(Ematch
) then
2581 Error_Msg_NE
("\possible misspelling of&", N
, Ematch
);
2586 -- Make entry in undefined references table unless the full
2587 -- errors switch is set, in which case by refraining from
2588 -- generating the table entry, we guarantee that we get an
2589 -- error message for every undefined reference.
2591 if not All_Errors_Mode
then
2592 Urefs
.Increment_Last
;
2593 Urefs
.Table
(Urefs
.Last
).Node
:= N
;
2594 Urefs
.Table
(Urefs
.Last
).Err
:= Emsg
;
2595 Urefs
.Table
(Urefs
.Last
).Nvis
:= Nvis
;
2596 Urefs
.Table
(Urefs
.Last
).Loc
:= Sloc
(N
);
2602 -- Start of processing for Find_Direct_Name
2605 -- If the entity pointer is already set, this is an internal node, or
2606 -- a node that is analyzed more than once, after a tree modification.
2607 -- In such a case there is no resolution to perform, just set the type.
2609 if Present
(Entity
(N
)) then
2610 if Is_Type
(Entity
(N
)) then
2611 Set_Etype
(N
, Entity
(N
));
2615 Entyp
: constant Entity_Id
:= Etype
(Entity
(N
));
2618 -- One special case here. If the Etype field is already set,
2619 -- and references the packed array type corresponding to the
2620 -- etype of the referenced entity, then leave it alone. This
2621 -- happens for trees generated from Exp_Pakd, where expressions
2622 -- can be deliberately "mis-typed" to the packed array type.
2624 if Is_Array_Type
(Entyp
)
2625 and then Is_Packed
(Entyp
)
2626 and then Present
(Etype
(N
))
2627 and then Etype
(N
) = Packed_Array_Type
(Entyp
)
2631 -- If not that special case, then just reset the Etype
2634 Set_Etype
(N
, Etype
(Entity
(N
)));
2642 -- Here if Entity pointer was not set, we need full visibility analysis
2643 -- First we generate debugging output if the debug E flag is set.
2645 if Debug_Flag_E
then
2646 Write_Str
("Looking for ");
2647 Write_Name
(Chars
(N
));
2651 Homonyms
:= Current_Entity
(N
);
2652 Nvis_Entity
:= False;
2655 while Present
(E
) loop
2657 -- If entity is immediately visible or potentially use
2658 -- visible, then process the entity and we are done.
2660 if Is_Immediately_Visible
(E
) then
2661 goto Immediately_Visible_Entity
;
2663 elsif Is_Potentially_Use_Visible
(E
) then
2664 goto Potentially_Use_Visible_Entity
;
2666 -- Note if a known but invisible entity encountered
2668 elsif Known_But_Invisible
(E
) then
2669 Nvis_Entity
:= True;
2672 -- Move to next entity in chain and continue search
2677 -- If no entries on homonym chain that were potentially visible,
2678 -- and no entities reasonably considered as non-visible, then
2679 -- we have a plain undefined reference, with no additional
2680 -- explanation required!
2682 if not Nvis_Entity
then
2683 Undefined
(Nvis
=> False);
2686 -- Otherwise there is at least one entry on the homonym chain that
2687 -- is reasonably considered as being known and non-visible.
2694 -- Processing for a potentially use visible entry found. We must search
2695 -- the rest of the homonym chain for two reasons. First, if there is a
2696 -- directly visible entry, then none of the potentially use-visible
2697 -- entities are directly visible (RM 8.4(10)). Second, we need to check
2698 -- for the case of multiple potentially use-visible entries hiding one
2699 -- another and as a result being non-directly visible (RM 8.4(11)).
2701 <<Potentially_Use_Visible_Entity
>> declare
2702 Only_One_Visible
: Boolean := True;
2703 All_Overloadable
: Boolean := Is_Overloadable
(E
);
2708 while Present
(E2
) loop
2709 if Is_Immediately_Visible
(E2
) then
2711 -- If the use-visible entity comes from the actual for a
2712 -- formal package, it hides a directly visible entity from
2713 -- outside the instance.
2715 if From_Actual_Package
(E
)
2716 and then Scope_Depth
(E2
) < Scope_Depth
(Inst
)
2721 goto Immediately_Visible_Entity
;
2724 elsif Is_Potentially_Use_Visible
(E2
) then
2725 Only_One_Visible
:= False;
2726 All_Overloadable
:= All_Overloadable
and Is_Overloadable
(E2
);
2732 -- On falling through this loop, we have checked that there are no
2733 -- immediately visible entities. Only_One_Visible is set if exactly
2734 -- one potentially use visible entity exists. All_Overloadable is
2735 -- set if all the potentially use visible entities are overloadable.
2736 -- The condition for legality is that either there is one potentially
2737 -- use visible entity, or if there is more than one, then all of them
2738 -- are overloadable.
2740 if Only_One_Visible
or All_Overloadable
then
2743 -- If there is more than one potentially use-visible entity and at
2744 -- least one of them non-overloadable, we have an error (RM 8.4(11).
2745 -- Note that E points to the first such entity on the homonym list.
2746 -- Special case: if one of the entities is declared in an actual
2747 -- package, it was visible in the generic, and takes precedence over
2748 -- other entities that are potentially use-visible.
2754 while Present
(E2
) loop
2755 if Is_Generic_Instance
(Scope
(E2
)) then
2773 -- Come here with E set to the first immediately visible entity on
2774 -- the homonym chain. This is the one we want unless there is another
2775 -- immediately visible entity further on in the chain for a more
2776 -- inner scope (RM 8.3(8)).
2778 <<Immediately_Visible_Entity
>> declare
2783 -- Find scope level of initial entity. When compiling through
2784 -- Rtsfind, the previous context is not completely invisible, and
2785 -- an outer entity may appear on the chain, whose scope is below
2786 -- the entry for Standard that delimits the current scope stack.
2787 -- Indicate that the level for this spurious entry is outside of
2788 -- the current scope stack.
2790 Level
:= Scope_Stack
.Last
;
2792 Scop
:= Scope_Stack
.Table
(Level
).Entity
;
2793 exit when Scop
= Scope
(E
);
2795 exit when Scop
= Standard_Standard
;
2798 -- Now search remainder of homonym chain for more inner entry
2799 -- If the entity is Standard itself, it has no scope, and we
2800 -- compare it with the stack entry directly.
2803 while Present
(E2
) loop
2804 if Is_Immediately_Visible
(E2
) then
2805 for J
in Level
+ 1 .. Scope_Stack
.Last
loop
2806 if Scope_Stack
.Table
(J
).Entity
= Scope
(E2
)
2807 or else Scope_Stack
.Table
(J
).Entity
= E2
2819 -- At the end of that loop, E is the innermost immediately
2820 -- visible entity, so we are all set.
2823 -- Come here with entity found, and stored in E
2827 if Comes_From_Source
(N
)
2828 and then Is_Remote_Access_To_Subprogram_Type
(E
)
2829 and then Expander_Active
2832 New_Occurrence_Of
(Equivalent_Type
(E
), Sloc
(N
)));
2837 -- Why no Style_Check here???
2842 Set_Etype
(N
, Get_Full_View
(Etype
(E
)));
2845 if Debug_Flag_E
then
2846 Write_Str
(" found ");
2847 Write_Entity_Info
(E
, " ");
2850 -- If the Ekind of the entity is Void, it means that all homonyms
2851 -- are hidden from all visibility (RM 8.3(5,14-20)). However, this
2852 -- test is skipped if the current scope is a record and the name is
2853 -- a pragma argument expression (case of Atomic and Volatile pragmas
2854 -- and possibly other similar pragmas added later, which are allowed
2855 -- to reference components in the current record).
2857 if Ekind
(E
) = E_Void
2859 (not Is_Record_Type
(Current_Scope
)
2860 or else Nkind
(Parent
(N
)) /= N_Pragma_Argument_Association
)
2862 Premature_Usage
(N
);
2864 -- If the entity is overloadable, collect all interpretations
2865 -- of the name for subsequent overload resolution. We optimize
2866 -- a bit here to do this only if we have an overloadable entity
2867 -- that is not on its own on the homonym chain.
2869 elsif Is_Overloadable
(E
)
2870 and then (Present
(Homonym
(E
)) or else Current_Entity
(N
) /= E
)
2872 Collect_Interps
(N
);
2874 -- If no homonyms were visible, the entity is unambiguous.
2876 if not Is_Overloaded
(N
) then
2877 Generate_Reference
(E
, N
);
2880 -- Case of non-overloadable entity, set the entity providing that
2881 -- we do not have the case of a discriminant reference within a
2882 -- default expression. Such references are replaced with the
2883 -- corresponding discriminal, which is the formal corresponding to
2884 -- to the discriminant in the initialization procedure.
2886 -- This replacement must not be done if we are currently processing
2887 -- a generic spec or body.
2889 -- The replacement is not done either for a task discriminant that
2890 -- appears in a default expression of an entry parameter. See
2891 -- Expand_Discriminant in exp_ch2 for details on their handling.
2894 -- Entity is unambiguous, indicate that it is referenced here
2895 -- One slightly odd case is that we do not want to set the
2896 -- Referenced flag if the entity is a label, and the identifier
2897 -- is the label in the source, since this is not a reference
2898 -- from the point of view of the user
2900 if Nkind
(Parent
(N
)) = N_Label
then
2902 R
: constant Boolean := Referenced
(E
);
2905 Generate_Reference
(E
, N
);
2906 Set_Referenced
(E
, R
);
2910 Generate_Reference
(E
, N
);
2913 if not In_Default_Expression
2914 or else Ekind
(E
) /= E_Discriminant
2915 or else Inside_A_Generic
2917 Set_Entity_With_Style_Check
(N
, E
);
2919 elsif Is_Concurrent_Type
(Scope
(E
)) then
2921 P
: Node_Id
:= Parent
(N
);
2925 and then Nkind
(P
) /= N_Parameter_Specification
2926 and then Nkind
(P
) /= N_Component_Declaration
2932 and then Nkind
(P
) = N_Parameter_Specification
2936 Set_Entity
(N
, Discriminal
(E
));
2941 Set_Entity
(N
, Discriminal
(E
));
2945 end Find_Direct_Name
;
2947 ------------------------
2948 -- Find_Expanded_Name --
2949 ------------------------
2951 -- This routine searches the homonym chain of the entity until it finds
2952 -- an entity declared in the scope denoted by the prefix. If the entity
2953 -- is private, it may nevertheless be immediately visible, if we are in
2954 -- the scope of its declaration.
2956 procedure Find_Expanded_Name
(N
: Node_Id
) is
2957 Selector
: constant Node_Id
:= Selector_Name
(N
);
2958 Candidate
: Entity_Id
:= Empty
;
2964 P_Name
:= Entity
(Prefix
(N
));
2967 -- If the prefix is a renamed package, look for the entity
2968 -- in the original package.
2970 if Ekind
(P_Name
) = E_Package
2971 and then Present
(Renamed_Object
(P_Name
))
2973 P_Name
:= Renamed_Object
(P_Name
);
2975 -- Rewrite node with entity field pointing to renamed object
2977 Rewrite
(Prefix
(N
), New_Copy
(Prefix
(N
)));
2978 Set_Entity
(Prefix
(N
), P_Name
);
2980 -- If the prefix is an object of a concurrent type, look for
2981 -- the entity in the associated task or protected type.
2983 elsif Is_Concurrent_Type
(Etype
(P_Name
)) then
2984 P_Name
:= Etype
(P_Name
);
2987 Id
:= Current_Entity
(Selector
);
2989 while Present
(Id
) loop
2991 if Scope
(Id
) = P_Name
then
2994 if Is_Child_Unit
(Id
) then
2996 (Is_Visible_Child_Unit
(Id
)
2997 or else Is_Immediately_Visible
(Id
));
3001 (not Is_Hidden
(Id
) or else Is_Immediately_Visible
(Id
));
3009 and then (Ekind
(P_Name
) = E_Procedure
3011 Ekind
(P_Name
) = E_Function
)
3012 and then Is_Generic_Instance
(P_Name
)
3014 -- Expanded name denotes entity in (instance of) generic subprogram.
3015 -- The entity may be in the subprogram instance, or may denote one of
3016 -- the formals, which is declared in the enclosing wrapper package.
3018 P_Name
:= Scope
(P_Name
);
3019 Id
:= Current_Entity
(Selector
);
3021 while Present
(Id
) loop
3022 exit when Scope
(Id
) = P_Name
;
3027 if No
(Id
) or else Chars
(Id
) /= Chars
(Selector
) then
3029 Set_Etype
(N
, Any_Type
);
3031 -- If we are looking for an entity defined in System, try to
3032 -- find it in the child package that may have been provided as
3033 -- an extension to System. The Extend_System pragma will have
3034 -- supplied the name of the extension, which may have to be loaded.
3036 if Chars
(P_Name
) = Name_System
3037 and then Scope
(P_Name
) = Standard_Standard
3038 and then Present
(System_Extend_Pragma_Arg
)
3039 and then Present_System_Aux
(N
)
3041 Set_Entity
(Prefix
(N
), System_Aux_Id
);
3042 Find_Expanded_Name
(N
);
3045 elsif (Nkind
(Selector
) = N_Operator_Symbol
3046 and then Has_Implicit_Operator
(N
))
3048 -- There is an implicit instance of the predefined operator in
3049 -- the given scope. The operator entity is defined in Standard.
3050 -- Has_Implicit_Operator makes the node into an Expanded_Name.
3054 elsif Nkind
(Selector
) = N_Character_Literal
3055 and then Has_Implicit_Character_Literal
(N
)
3057 -- If there is no literal defined in the scope denoted by the
3058 -- prefix, the literal may belong to (a type derived from)
3059 -- Standard_Character, for which we have no explicit literals.
3064 -- If the prefix is a single concurrent object, use its
3065 -- name in the error message, rather than that of the
3068 if Is_Concurrent_Type
(P_Name
)
3069 and then Is_Internal_Name
(Chars
(P_Name
))
3071 Error_Msg_Node_2
:= Entity
(Prefix
(N
));
3073 Error_Msg_Node_2
:= P_Name
;
3076 if P_Name
= System_Aux_Id
then
3077 P_Name
:= Scope
(P_Name
);
3078 Set_Entity
(Prefix
(N
), P_Name
);
3081 if Present
(Candidate
) then
3083 if Is_Child_Unit
(Candidate
) then
3085 ("missing with_clause for child unit &", Selector
);
3087 Error_Msg_NE
("& is not a visible entity of&", N
, Selector
);
3091 -- Within the instantiation of a child unit, the prefix may
3092 -- denote the parent instance, but the selector has the
3093 -- name of the original child. Find whether we are within
3094 -- the corresponding instance, and get the proper entity, which
3095 -- can only be an enclosing scope.
3098 and then In_Open_Scopes
(P_Name
)
3099 and then Is_Generic_Instance
(P_Name
)
3102 S
: Entity_Id
:= Current_Scope
;
3106 for J
in reverse 0 .. Scope_Stack
.Last
loop
3107 S
:= Scope_Stack
.Table
(J
).Entity
;
3109 exit when S
= Standard_Standard
;
3111 if Ekind
(S
) = E_Function
3112 or else Ekind
(S
) = E_Package
3113 or else Ekind
(S
) = E_Procedure
3115 P
:= Generic_Parent
(Specification
3116 (Unit_Declaration_Node
(S
)));
3119 and then Chars
(Scope
(P
)) = Chars
(O_Name
)
3120 and then Chars
(P
) = Chars
(Selector
)
3131 if (Chars
(P_Name
) = Name_Ada
3132 and then Scope
(P_Name
) = Standard_Standard
)
3134 Error_Msg_Node_2
:= Selector
;
3136 ("\missing with for `&.&`", N
, P_Name
);
3138 -- If this is a selection from a dummy package, then
3139 -- suppress the error message, of course the entity
3140 -- is missing if the package is missing!
3142 elsif Sloc
(Error_Msg_Node_2
) = No_Location
then
3145 -- Here we have the case of an undefined component
3149 Error_Msg_NE
("& not declared in&", N
, Selector
);
3151 -- Check for misspelling of some entity in prefix.
3153 Id
:= First_Entity
(P_Name
);
3154 Get_Name_String
(Chars
(Selector
));
3157 S
: constant String (1 .. Name_Len
) :=
3158 Name_Buffer
(1 .. Name_Len
);
3160 while Present
(Id
) loop
3161 Get_Name_String
(Chars
(Id
));
3162 if Is_Bad_Spelling_Of
3163 (Name_Buffer
(1 .. Name_Len
), S
)
3164 and then not Is_Internal_Name
(Chars
(Id
))
3167 ("possible misspelling of&", Selector
, Id
);
3175 -- Specialize the message if this may be an instantiation
3176 -- of a child unit that was not mentioned in the context.
3178 if Nkind
(Parent
(N
)) = N_Package_Instantiation
3179 and then Is_Generic_Instance
(Entity
(Prefix
(N
)))
3180 and then Is_Compilation_Unit
3181 (Generic_Parent
(Parent
(Entity
(Prefix
(N
)))))
3184 ("\possible missing with clause on child unit&",
3195 if Comes_From_Source
(N
)
3196 and then Is_Remote_Access_To_Subprogram_Type
(Id
)
3198 Id
:= Equivalent_Type
(Id
);
3199 Set_Chars
(Selector
, Chars
(Id
));
3202 if Ekind
(P_Name
) = E_Package
3203 and then From_With_Type
(P_Name
)
3205 if From_With_Type
(Id
)
3206 or else (Ekind
(Id
) = E_Package
and then From_With_Type
(Id
))
3211 ("imported package can only be used to access imported type",
3216 if Is_Task_Type
(P_Name
)
3217 and then ((Ekind
(Id
) = E_Entry
3218 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
)
3220 (Ekind
(Id
) = E_Entry_Family
3222 Nkind
(Parent
(Parent
(N
))) /= N_Attribute_Reference
))
3224 -- It is an entry call after all, either to the current task
3225 -- (which will deadlock) or to an enclosing task.
3227 Analyze_Selected_Component
(N
);
3231 Change_Selected_Component_To_Expanded_Name
(N
);
3233 -- Do style check and generate reference, but skip both steps if this
3234 -- entity has homonyms, since we may not have the right homonym set
3235 -- yet. The proper homonym will be set during the resolve phase.
3237 if Has_Homonym
(Id
) then
3240 Set_Entity_With_Style_Check
(N
, Id
);
3241 Generate_Reference
(Id
, N
);
3244 if Is_Type
(Id
) then
3247 Set_Etype
(N
, Get_Full_View
(Etype
(Id
)));
3250 -- If the Ekind of the entity is Void, it means that all homonyms
3251 -- are hidden from all visibility (RM 8.3(5,14-20)).
3253 if Ekind
(Id
) = E_Void
then
3254 Premature_Usage
(N
);
3256 elsif Is_Overloadable
(Id
)
3257 and then Present
(Homonym
(Id
))
3260 H
: Entity_Id
:= Homonym
(Id
);
3263 while Present
(H
) loop
3264 if Scope
(H
) = Scope
(Id
) then
3265 Collect_Interps
(N
);
3274 if Nkind
(Selector_Name
(N
)) = N_Operator_Symbol
3275 and then Scope
(Id
) /= Standard_Standard
3277 -- In addition to user-defined operators in the given scope,
3278 -- there may be an implicit instance of the predefined
3279 -- operator. The operator (defined in Standard) is found
3280 -- in Has_Implicit_Operator, and added to the interpretations.
3281 -- Procedure Add_One_Interp will determine which hides which.
3283 if Has_Implicit_Operator
(N
) then
3287 end Find_Expanded_Name
;
3289 -------------------------
3290 -- Find_Renamed_Entity --
3291 -------------------------
3293 function Find_Renamed_Entity
3297 Is_Actual
: Boolean := False) return Entity_Id
3300 I1
: Interp_Index
:= 0; -- Suppress junk warnings
3306 function Enclosing_Instance
return Entity_Id
;
3307 -- If the renaming determines the entity for the default of a formal
3308 -- subprogram nested within another instance, choose the innermost
3309 -- candidate. This is because if the formal has a box, and we are within
3310 -- an enclosing instance where some candidate interpretations are local
3311 -- to this enclosing instance, we know that the default was properly
3312 -- resolved when analyzing the generic, so we prefer the local
3313 -- candidates to those that are external. This is not always the case
3314 -- but is a reasonable heuristic on the use of nested generics.
3315 -- The proper solution requires a full renaming model.
3317 function Within
(Inner
, Outer
: Entity_Id
) return Boolean;
3318 -- Determine whether a candidate subprogram is defined within
3319 -- the enclosing instance. If yes, it has precedence over outer
3322 function Is_Visible_Operation
(Op
: Entity_Id
) return Boolean;
3323 -- If the renamed entity is an implicit operator, check whether it is
3324 -- visible because its operand type is properly visible. This
3325 -- check applies to explicit renamed entities that appear in the
3326 -- source in a renaming declaration or a formal subprogram instance,
3327 -- but not to default generic actuals with a name.
3329 ------------------------
3330 -- Enclosing_Instance --
3331 ------------------------
3333 function Enclosing_Instance
return Entity_Id
is
3337 if not Is_Generic_Instance
(Current_Scope
)
3338 and then not Is_Actual
3343 S
:= Scope
(Current_Scope
);
3345 while S
/= Standard_Standard
loop
3347 if Is_Generic_Instance
(S
) then
3355 end Enclosing_Instance
;
3357 --------------------------
3358 -- Is_Visible_Operation --
3359 --------------------------
3361 function Is_Visible_Operation
(Op
: Entity_Id
) return Boolean is
3367 if Ekind
(Op
) /= E_Operator
3368 or else Scope
(Op
) /= Standard_Standard
3369 or else (In_Instance
3372 or else Present
(Enclosing_Instance
)))
3377 -- For a fixed point type operator, check the resulting type,
3378 -- because it may be a mixed mode integer * fixed operation.
3380 if Present
(Next_Formal
(First_Formal
(New_S
)))
3381 and then Is_Fixed_Point_Type
(Etype
(New_S
))
3383 Typ
:= Etype
(New_S
);
3385 Typ
:= Etype
(First_Formal
(New_S
));
3388 Btyp
:= Base_Type
(Typ
);
3390 if Nkind
(Nam
) /= N_Expanded_Name
then
3391 return (In_Open_Scopes
(Scope
(Btyp
))
3392 or else Is_Potentially_Use_Visible
(Btyp
)
3393 or else In_Use
(Btyp
)
3394 or else In_Use
(Scope
(Btyp
)));
3397 Scop
:= Entity
(Prefix
(Nam
));
3399 if Ekind
(Scop
) = E_Package
3400 and then Present
(Renamed_Object
(Scop
))
3402 Scop
:= Renamed_Object
(Scop
);
3405 -- Operator is visible if prefix of expanded name denotes
3406 -- scope of type, or else type type is defined in System_Aux
3407 -- and the prefix denotes System.
3409 return Scope
(Btyp
) = Scop
3410 or else (Scope
(Btyp
) = System_Aux_Id
3411 and then Scope
(Scope
(Btyp
)) = Scop
);
3414 end Is_Visible_Operation
;
3420 function Within
(Inner
, Outer
: Entity_Id
) return Boolean is
3421 Sc
: Entity_Id
:= Scope
(Inner
);
3424 while Sc
/= Standard_Standard
loop
3436 -- Start of processing for Find_Renamed_Entry
3440 Candidate_Renaming
:= Empty
;
3442 if not Is_Overloaded
(Nam
) then
3443 if Entity_Matches_Spec
(Entity
(Nam
), New_S
)
3444 and then Is_Visible_Operation
(Entity
(Nam
))
3446 Old_S
:= Entity
(Nam
);
3449 Present
(First_Formal
(Entity
(Nam
)))
3450 and then Present
(First_Formal
(New_S
))
3451 and then (Base_Type
(Etype
(First_Formal
(Entity
(Nam
))))
3452 = Base_Type
(Etype
(First_Formal
(New_S
))))
3454 Candidate_Renaming
:= Entity
(Nam
);
3458 Get_First_Interp
(Nam
, I
, It
);
3460 while Present
(It
.Nam
) loop
3462 if Entity_Matches_Spec
(It
.Nam
, New_S
)
3463 and then Is_Visible_Operation
(It
.Nam
)
3465 if Old_S
/= Any_Id
then
3467 -- Note: The call to Disambiguate only happens if a
3468 -- previous interpretation was found, in which case I1
3469 -- has received a value.
3471 It1
:= Disambiguate
(Nam
, I1
, I
, Etype
(Old_S
));
3473 if It1
= No_Interp
then
3475 Inst
:= Enclosing_Instance
;
3477 if Present
(Inst
) then
3479 if Within
(It
.Nam
, Inst
) then
3482 elsif Within
(Old_S
, Inst
) then
3486 Error_Msg_N
("ambiguous renaming", N
);
3491 Error_Msg_N
("ambiguous renaming", N
);
3506 Present
(First_Formal
(It
.Nam
))
3507 and then Present
(First_Formal
(New_S
))
3508 and then (Base_Type
(Etype
(First_Formal
(It
.Nam
)))
3509 = Base_Type
(Etype
(First_Formal
(New_S
))))
3511 Candidate_Renaming
:= It
.Nam
;
3514 Get_Next_Interp
(I
, It
);
3517 Set_Entity
(Nam
, Old_S
);
3518 Set_Is_Overloaded
(Nam
, False);
3522 end Find_Renamed_Entity
;
3524 -----------------------------
3525 -- Find_Selected_Component --
3526 -----------------------------
3528 procedure Find_Selected_Component
(N
: Node_Id
) is
3529 P
: Node_Id
:= Prefix
(N
);
3532 -- Entity denoted by prefix
3542 if Nkind
(P
) = N_Error
then
3545 -- If the selector already has an entity, the node has been
3546 -- constructed in the course of expansion, and is known to be
3547 -- valid. Do not verify that it is defined for the type (it may
3548 -- be a private component used in the expansion of record equality).
3550 elsif Present
(Entity
(Selector_Name
(N
))) then
3553 or else Etype
(N
) = Any_Type
3556 Sel_Name
: Node_Id
:= Selector_Name
(N
);
3557 Selector
: Entity_Id
:= Entity
(Sel_Name
);
3561 Set_Etype
(Sel_Name
, Etype
(Selector
));
3563 if not Is_Entity_Name
(P
) then
3564 Resolve
(P
, Etype
(P
));
3567 -- Build an actual subtype except for the first parameter
3568 -- of an init_proc, where this actual subtype is by
3569 -- definition incorrect, since the object is uninitialized
3570 -- (and does not even have defined discriminants etc.)
3572 if Is_Entity_Name
(P
)
3573 and then Ekind
(Entity
(P
)) = E_Function
3575 Nam
:= New_Copy
(P
);
3577 if Is_Overloaded
(P
) then
3578 Save_Interps
(P
, Nam
);
3582 Make_Function_Call
(Sloc
(P
), Name
=> Nam
));
3584 Analyze_Selected_Component
(N
);
3587 elsif Ekind
(Selector
) = E_Component
3588 and then (not Is_Entity_Name
(P
)
3589 or else Chars
(Entity
(P
)) /= Name_uInit
)
3592 Build_Actual_Subtype_Of_Component
(
3593 Etype
(Selector
), N
);
3598 if No
(C_Etype
) then
3599 C_Etype
:= Etype
(Selector
);
3601 Insert_Action
(N
, C_Etype
);
3602 C_Etype
:= Defining_Identifier
(C_Etype
);
3605 Set_Etype
(N
, C_Etype
);
3608 -- If this is the name of an entry or protected operation, and
3609 -- the prefix is an access type, insert an explicit dereference,
3610 -- so that entry calls are treated uniformly.
3612 if Is_Access_Type
(Etype
(P
))
3613 and then Is_Concurrent_Type
(Designated_Type
(Etype
(P
)))
3617 Make_Explicit_Dereference
(Sloc
(P
),
3618 Prefix
=> Relocate_Node
(P
));
3621 Set_Etype
(P
, Designated_Type
(Etype
(Prefix
(P
))));
3625 -- If the selected component appears within a default expression
3626 -- and it has an actual subtype, the pre-analysis has not yet
3627 -- completed its analysis, because Insert_Actions is disabled in
3628 -- that context. Within the init_proc of the enclosing type we
3629 -- must complete this analysis, if an actual subtype was created.
3631 elsif Inside_Init_Proc
then
3633 Typ
: constant Entity_Id
:= Etype
(N
);
3634 Decl
: constant Node_Id
:= Declaration_Node
(Typ
);
3637 if Nkind
(Decl
) = N_Subtype_Declaration
3638 and then not Analyzed
(Decl
)
3639 and then Is_List_Member
(Decl
)
3640 and then No
(Parent
(Decl
))
3643 Insert_Action
(N
, Decl
);
3650 elsif Is_Entity_Name
(P
) then
3651 P_Name
:= Entity
(P
);
3653 -- The prefix may denote an enclosing type which is the completion
3654 -- of an incomplete type declaration.
3656 if Is_Type
(P_Name
) then
3657 Set_Entity
(P
, Get_Full_View
(P_Name
));
3658 Set_Etype
(P
, Entity
(P
));
3659 P_Name
:= Entity
(P
);
3662 P_Type
:= Base_Type
(Etype
(P
));
3664 if Debug_Flag_E
then
3665 Write_Str
("Found prefix type to be ");
3666 Write_Entity_Info
(P_Type
, " "); Write_Eol
;
3669 -- First check for components of a record object (not the
3670 -- result of a call, which is handled below).
3672 if Is_Appropriate_For_Record
(P_Type
)
3673 and then not Is_Overloadable
(P_Name
)
3674 and then not Is_Type
(P_Name
)
3676 -- Selected component of record. Type checking will validate
3677 -- name of selector.
3679 Analyze_Selected_Component
(N
);
3681 elsif Is_Appropriate_For_Entry_Prefix
(P_Type
)
3682 and then not In_Open_Scopes
(P_Name
)
3683 and then (not Is_Concurrent_Type
(Etype
(P_Name
))
3684 or else not In_Open_Scopes
(Etype
(P_Name
)))
3686 -- Call to protected operation or entry. Type checking is
3687 -- needed on the prefix.
3689 Analyze_Selected_Component
(N
);
3691 elsif (In_Open_Scopes
(P_Name
)
3692 and then Ekind
(P_Name
) /= E_Void
3693 and then not Is_Overloadable
(P_Name
))
3694 or else (Is_Concurrent_Type
(Etype
(P_Name
))
3695 and then In_Open_Scopes
(Etype
(P_Name
)))
3697 -- Prefix denotes an enclosing loop, block, or task, i.e. an
3698 -- enclosing construct that is not a subprogram or accept.
3700 Find_Expanded_Name
(N
);
3702 elsif Ekind
(P_Name
) = E_Package
then
3703 Find_Expanded_Name
(N
);
3705 elsif Is_Overloadable
(P_Name
) then
3707 -- The subprogram may be a renaming (of an enclosing scope) as
3708 -- in the case of the name of the generic within an instantiation.
3710 if (Ekind
(P_Name
) = E_Procedure
3711 or else Ekind
(P_Name
) = E_Function
)
3712 and then Present
(Alias
(P_Name
))
3713 and then Is_Generic_Instance
(Alias
(P_Name
))
3715 P_Name
:= Alias
(P_Name
);
3718 if Is_Overloaded
(P
) then
3720 -- The prefix must resolve to a unique enclosing construct.
3723 Found
: Boolean := False;
3728 Get_First_Interp
(P
, I
, It
);
3730 while Present
(It
.Nam
) loop
3732 if In_Open_Scopes
(It
.Nam
) then
3735 "prefix must be unique enclosing scope", N
);
3736 Set_Entity
(N
, Any_Id
);
3737 Set_Etype
(N
, Any_Type
);
3746 Get_Next_Interp
(I
, It
);
3751 if In_Open_Scopes
(P_Name
) then
3752 Set_Entity
(P
, P_Name
);
3753 Set_Is_Overloaded
(P
, False);
3754 Find_Expanded_Name
(N
);
3757 -- If no interpretation as an expanded name is possible, it
3758 -- must be a selected component of a record returned by a
3759 -- function call. Reformat prefix as a function call, the
3760 -- rest is done by type resolution. If the prefix is a
3761 -- procedure or entry, as is P.X; this is an error.
3763 if Ekind
(P_Name
) /= E_Function
3764 and then (not Is_Overloaded
(P
)
3766 Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
)
3769 -- Prefix may mention a package that is hidden by a local
3770 -- declaration: let the user know. Scan the full homonym
3771 -- chain, the candidate package may be anywhere on it.
3773 if Present
(Homonym
(Current_Entity
(P_Name
))) then
3775 P_Name
:= Current_Entity
(P_Name
);
3777 while Present
(P_Name
) loop
3778 exit when Ekind
(P_Name
) = E_Package
;
3779 P_Name
:= Homonym
(P_Name
);
3782 if Present
(P_Name
) then
3783 Error_Msg_Sloc
:= Sloc
(Entity
(Prefix
(N
)));
3786 ("package& is hidden by declaration#",
3789 Set_Entity
(Prefix
(N
), P_Name
);
3790 Find_Expanded_Name
(N
);
3793 P_Name
:= Entity
(Prefix
(N
));
3798 ("invalid prefix in selected component&", N
, P_Name
);
3799 Change_Selected_Component_To_Expanded_Name
(N
);
3800 Set_Entity
(N
, Any_Id
);
3801 Set_Etype
(N
, Any_Type
);
3804 Nam
:= New_Copy
(P
);
3805 Save_Interps
(P
, Nam
);
3807 Make_Function_Call
(Sloc
(P
), Name
=> Nam
));
3809 Analyze_Selected_Component
(N
);
3813 -- Remaining cases generate various error messages
3816 -- Format node as expanded name, to avoid cascaded errors
3818 Change_Node
(N
, N_Expanded_Name
);
3820 Set_Entity
(N
, Any_Id
);
3821 Set_Etype
(N
, Any_Type
);
3823 -- Set_Selector_Name (N, Empty); ????
3825 -- Issue error message, but avoid this if error issued already.
3826 -- Use identifier of prefix if one is available.
3828 if P_Name
= Any_Id
then
3831 elsif Ekind
(P_Name
) = E_Void
then
3832 Premature_Usage
(P
);
3834 elsif Nkind
(P
) /= N_Attribute_Reference
then
3836 "invalid prefix in selected component&", P
);
3840 "invalid prefix in selected component", P
);
3845 -- If prefix is not the name of an entity, it must be an expression,
3846 -- whose type is appropriate for a record. This is determined by
3849 Analyze_Selected_Component
(N
);
3851 end Find_Selected_Component
;
3857 procedure Find_Type
(N
: Node_Id
) is
3867 elsif Nkind
(N
) = N_Attribute_Reference
then
3869 -- Class attribute. This is only valid in Ada 95 mode, but we don't
3870 -- do a check, since the tagged type referenced could only exist if
3871 -- we were in 95 mode when it was declared (or, if we were in Ada
3872 -- 83 mode, then an error message would already have been issued).
3874 if Attribute_Name
(N
) = Name_Class
then
3875 Check_Restriction
(No_Dispatch
, N
);
3876 Find_Type
(Prefix
(N
));
3878 -- Propagate error from bad prefix
3880 if Etype
(Prefix
(N
)) = Any_Type
then
3881 Set_Entity
(N
, Any_Type
);
3882 Set_Etype
(N
, Any_Type
);
3886 T
:= Base_Type
(Entity
(Prefix
(N
)));
3888 -- Case of non-tagged type
3890 if not Is_Tagged_Type
(T
) then
3891 if Ekind
(T
) = E_Incomplete_Type
then
3893 -- It is legal to denote the class type of an incomplete
3894 -- type. The full type will have to be tagged, of course.
3896 Set_Is_Tagged_Type
(T
);
3897 Make_Class_Wide_Type
(T
);
3898 Set_Entity
(N
, Class_Wide_Type
(T
));
3899 Set_Etype
(N
, Class_Wide_Type
(T
));
3901 elsif Ekind
(T
) = E_Private_Type
3902 and then not Is_Generic_Type
(T
)
3903 and then In_Private_Part
(Scope
(T
))
3905 -- The Class attribute can be applied to an untagged
3906 -- private type fulfilled by a tagged type prior to
3907 -- the full type declaration (but only within the
3908 -- parent package's private part). Create the class-wide
3909 -- type now and check that the full type is tagged
3910 -- later during its analysis. Note that we do not
3911 -- mark the private type as tagged, unlike the case
3912 -- of incomplete types, because the type must still
3913 -- appear untagged to outside units.
3915 if not Present
(Class_Wide_Type
(T
)) then
3916 Make_Class_Wide_Type
(T
);
3919 Set_Entity
(N
, Class_Wide_Type
(T
));
3920 Set_Etype
(N
, Class_Wide_Type
(T
));
3923 -- Should we introduce a type Any_Tagged and use
3924 -- Wrong_Type here, it would be a bit more consistent???
3927 ("tagged type required, found}",
3928 Prefix
(N
), First_Subtype
(T
));
3929 Set_Entity
(N
, Any_Type
);
3933 -- Case of tagged type
3936 C
:= Class_Wide_Type
(Entity
(Prefix
(N
)));
3937 Set_Entity_With_Style_Check
(N
, C
);
3938 Generate_Reference
(C
, N
);
3941 if From_With_Type
(C
)
3942 and then Nkind
(Parent
(N
)) /= N_Access_Definition
3943 and then not Analyzed
(T
)
3946 ("imported class-wide type can only be used" &
3947 " for access parameters", N
);
3951 -- Base attribute, allowed in Ada 95 mode only
3953 elsif Attribute_Name
(N
) = Name_Base
then
3954 if Ada_83
and then Comes_From_Source
(N
) then
3956 ("(Ada 83) Base attribute not allowed in subtype mark", N
);
3959 Find_Type
(Prefix
(N
));
3960 Typ
:= Entity
(Prefix
(N
));
3962 if Sloc
(Typ
) = Standard_Location
3963 and then Base_Type
(Typ
) = Typ
3964 and then Warn_On_Redundant_Constructs
3967 ("?redudant attribute, & is its own base type", N
, Typ
);
3970 T
:= Base_Type
(Typ
);
3974 -- Rewrite attribute reference with type itself (see similar
3975 -- processing in Analyze_Attribute, case Base)
3978 New_Reference_To
(Entity
(N
), Sloc
(N
)));
3982 -- All other attributes are invalid in a subtype mark
3985 Error_Msg_N
("invalid attribute in subtype mark", N
);
3991 if Is_Entity_Name
(N
) then
3992 T_Name
:= Entity
(N
);
3994 Error_Msg_N
("subtype mark required in this context", N
);
3995 Set_Etype
(N
, Any_Type
);
3999 if T_Name
= Any_Id
or else Etype
(N
) = Any_Type
then
4001 -- Undefined id. Make it into a valid type
4003 Set_Entity
(N
, Any_Type
);
4005 elsif not Is_Type
(T_Name
)
4006 and then T_Name
/= Standard_Void_Type
4008 Error_Msg_Sloc
:= Sloc
(T_Name
);
4009 Error_Msg_N
("subtype mark required in this context", N
);
4010 Error_Msg_NE
("\found & declared#", N
, T_Name
);
4011 Set_Entity
(N
, Any_Type
);
4014 T_Name
:= Get_Full_View
(T_Name
);
4016 if In_Open_Scopes
(T_Name
) then
4017 if Ekind
(Base_Type
(T_Name
)) = E_Task_Type
then
4018 Error_Msg_N
("task type cannot be used as type mark " &
4019 "within its own body", N
);
4021 Error_Msg_N
("type declaration cannot refer to itself", N
);
4024 Set_Etype
(N
, Any_Type
);
4025 Set_Entity
(N
, Any_Type
);
4026 Set_Error_Posted
(T_Name
);
4030 Set_Entity
(N
, T_Name
);
4031 Set_Etype
(N
, T_Name
);
4035 if Present
(Etype
(N
)) and then Comes_From_Source
(N
) then
4036 if Is_Fixed_Point_Type
(Etype
(N
)) then
4037 Check_Restriction
(No_Fixed_Point
, N
);
4038 elsif Is_Floating_Point_Type
(Etype
(N
)) then
4039 Check_Restriction
(No_Floating_Point
, N
);
4048 function Get_Full_View
(T_Name
: Entity_Id
) return Entity_Id
is
4050 if (Ekind
(T_Name
) = E_Incomplete_Type
4051 and then Present
(Full_View
(T_Name
)))
4053 return Full_View
(T_Name
);
4055 elsif Is_Class_Wide_Type
(T_Name
)
4056 and then Ekind
(Root_Type
(T_Name
)) = E_Incomplete_Type
4057 and then Present
(Full_View
(Root_Type
(T_Name
)))
4059 return Class_Wide_Type
(Full_View
(Root_Type
(T_Name
)));
4066 ------------------------------------
4067 -- Has_Implicit_Character_Literal --
4068 ------------------------------------
4070 function Has_Implicit_Character_Literal
(N
: Node_Id
) return Boolean is
4072 Found
: Boolean := False;
4073 P
: constant Entity_Id
:= Entity
(Prefix
(N
));
4074 Priv_Id
: Entity_Id
:= Empty
;
4077 if Ekind
(P
) = E_Package
4078 and then not In_Open_Scopes
(P
)
4080 Priv_Id
:= First_Private_Entity
(P
);
4083 if P
= Standard_Standard
then
4084 Change_Selected_Component_To_Expanded_Name
(N
);
4085 Rewrite
(N
, Selector_Name
(N
));
4087 Set_Etype
(Original_Node
(N
), Standard_Character
);
4091 Id
:= First_Entity
(P
);
4094 and then Id
/= Priv_Id
4096 if Is_Character_Type
(Id
)
4097 and then (Root_Type
(Id
) = Standard_Character
4098 or else Root_Type
(Id
) = Standard_Wide_Character
)
4099 and then Id
= Base_Type
(Id
)
4101 -- We replace the node with the literal itself, resolve as a
4102 -- character, and set the type correctly.
4105 Change_Selected_Component_To_Expanded_Name
(N
);
4106 Rewrite
(N
, Selector_Name
(N
));
4109 Set_Etype
(Original_Node
(N
), Id
);
4113 -- More than one type derived from Character in given scope.
4114 -- Collect all possible interpretations.
4116 Add_One_Interp
(N
, Id
, Id
);
4124 end Has_Implicit_Character_Literal
;
4126 ---------------------------
4127 -- Has_Implicit_Operator --
4128 ---------------------------
4130 function Has_Implicit_Operator
(N
: Node_Id
) return Boolean is
4131 Op_Id
: constant Name_Id
:= Chars
(Selector_Name
(N
));
4132 P
: constant Entity_Id
:= Entity
(Prefix
(N
));
4134 Priv_Id
: Entity_Id
:= Empty
;
4136 procedure Add_Implicit_Operator
(T
: Entity_Id
);
4137 -- Add implicit interpretation to node N, using the type for which
4138 -- a predefined operator exists.
4140 ---------------------------
4141 -- Add_Implicit_Operator --
4142 ---------------------------
4144 procedure Add_Implicit_Operator
(T
: Entity_Id
) is
4145 Predef_Op
: Entity_Id
;
4148 Predef_Op
:= Current_Entity
(Selector_Name
(N
));
4150 while Present
(Predef_Op
)
4151 and then Scope
(Predef_Op
) /= Standard_Standard
4153 Predef_Op
:= Homonym
(Predef_Op
);
4156 if Nkind
(N
) = N_Selected_Component
then
4157 Change_Selected_Component_To_Expanded_Name
(N
);
4160 Add_One_Interp
(N
, Predef_Op
, T
);
4162 -- For operators with unary and binary interpretations, add both
4164 if Present
(Homonym
(Predef_Op
)) then
4165 Add_One_Interp
(N
, Homonym
(Predef_Op
), T
);
4167 end Add_Implicit_Operator
;
4169 -- Start of processing for Has_Implicit_Operator
4173 if Ekind
(P
) = E_Package
4174 and then not In_Open_Scopes
(P
)
4176 Priv_Id
:= First_Private_Entity
(P
);
4179 Id
:= First_Entity
(P
);
4183 -- Boolean operators: an implicit declaration exists if the scope
4184 -- contains a declaration for a derived Boolean type, or for an
4185 -- array of Boolean type.
4187 when Name_Op_And | Name_Op_Not | Name_Op_Or | Name_Op_Xor
=>
4189 while Id
/= Priv_Id
loop
4191 if Valid_Boolean_Arg
(Id
)
4192 and then Id
= Base_Type
(Id
)
4194 Add_Implicit_Operator
(Id
);
4201 -- Equality: look for any non-limited type. Result is Boolean.
4203 when Name_Op_Eq | Name_Op_Ne
=>
4205 while Id
/= Priv_Id
loop
4208 and then not Is_Limited_Type
(Id
)
4209 and then Id
= Base_Type
(Id
)
4211 Add_Implicit_Operator
(Standard_Boolean
);
4218 -- Comparison operators: scalar type, or array of scalar.
4220 when Name_Op_Lt | Name_Op_Le | Name_Op_Gt | Name_Op_Ge
=>
4222 while Id
/= Priv_Id
loop
4223 if (Is_Scalar_Type
(Id
)
4224 or else (Is_Array_Type
(Id
)
4225 and then Is_Scalar_Type
(Component_Type
(Id
))))
4226 and then Id
= Base_Type
(Id
)
4228 Add_Implicit_Operator
(Standard_Boolean
);
4235 -- Arithmetic operators: any numeric type
4246 while Id
/= Priv_Id
loop
4247 if Is_Numeric_Type
(Id
)
4248 and then Id
= Base_Type
(Id
)
4250 Add_Implicit_Operator
(Id
);
4257 -- Concatenation: any one-dimensional array type
4259 when Name_Op_Concat
=>
4261 while Id
/= Priv_Id
loop
4262 if Is_Array_Type
(Id
) and then Number_Dimensions
(Id
) = 1
4263 and then Id
= Base_Type
(Id
)
4265 Add_Implicit_Operator
(Id
);
4272 -- What is the others condition here? Should we be using a
4273 -- subtype of Name_Id that would restrict to operators ???
4275 when others => null;
4279 -- If we fall through, then we do not have an implicit operator
4283 end Has_Implicit_Operator
;
4285 --------------------
4286 -- In_Open_Scopes --
4287 --------------------
4289 function In_Open_Scopes
(S
: Entity_Id
) return Boolean is
4291 -- Since there are several scope stacks maintained by Scope_Stack each
4292 -- delineated by Standard (see comments by definition of Scope_Stack)
4293 -- it is necessary to end the search when Standard is reached.
4295 for J
in reverse 0 .. Scope_Stack
.Last
loop
4296 if Scope_Stack
.Table
(J
).Entity
= S
then
4300 -- We need Is_Active_Stack_Base to tell us when to stop rather
4301 -- than checking for Standard_Standard because there are cases
4302 -- where Standard_Standard appears in the middle of the active
4303 -- set of scopes. This affects the declaration and overriding
4304 -- of private inherited operations in instantiations of generic
4307 exit when Scope_Stack
.Table
(J
).Is_Active_Stack_Base
;
4313 -----------------------------
4314 -- Inherit_Renamed_Profile --
4315 -----------------------------
4317 procedure Inherit_Renamed_Profile
(New_S
: Entity_Id
; Old_S
: Entity_Id
) is
4324 if Ekind
(Old_S
) = E_Operator
then
4326 New_F
:= First_Formal
(New_S
);
4328 while Present
(New_F
) loop
4329 Set_Etype
(New_F
, Base_Type
(Etype
(New_F
)));
4330 Next_Formal
(New_F
);
4333 Set_Etype
(New_S
, Base_Type
(Etype
(New_S
)));
4336 New_F
:= First_Formal
(New_S
);
4337 Old_F
:= First_Formal
(Old_S
);
4339 while Present
(New_F
) loop
4340 New_T
:= Etype
(New_F
);
4341 Old_T
:= Etype
(Old_F
);
4343 -- If the new type is a renaming of the old one, as is the
4344 -- case for actuals in instances, retain its name, to simplify
4345 -- later disambiguation.
4347 if Nkind
(Parent
(New_T
)) = N_Subtype_Declaration
4348 and then Is_Entity_Name
(Subtype_Indication
(Parent
(New_T
)))
4349 and then Entity
(Subtype_Indication
(Parent
(New_T
))) = Old_T
4353 Set_Etype
(New_F
, Old_T
);
4356 Next_Formal
(New_F
);
4357 Next_Formal
(Old_F
);
4360 if Ekind
(Old_S
) = E_Function
4361 or else Ekind
(Old_S
) = E_Enumeration_Literal
4363 Set_Etype
(New_S
, Etype
(Old_S
));
4366 end Inherit_Renamed_Profile
;
4372 procedure Initialize
is
4377 -------------------------
4378 -- Install_Use_Clauses --
4379 -------------------------
4381 procedure Install_Use_Clauses
(Clause
: Node_Id
) is
4382 U
: Node_Id
:= Clause
;
4387 while Present
(U
) loop
4389 -- Case of USE package
4391 if Nkind
(U
) = N_Use_Package_Clause
then
4392 P
:= First
(Names
(U
));
4394 while Present
(P
) loop
4397 if Ekind
(Id
) = E_Package
then
4400 Set_Redundant_Use
(P
, True);
4402 elsif Present
(Renamed_Object
(Id
))
4403 and then In_Use
(Renamed_Object
(Id
))
4405 Set_Redundant_Use
(P
, True);
4408 Use_One_Package
(Id
, U
);
4418 P
:= First
(Subtype_Marks
(U
));
4420 while Present
(P
) loop
4422 if Entity
(P
) /= Any_Type
then
4430 Next_Use_Clause
(U
);
4432 end Install_Use_Clauses
;
4434 -------------------------------------
4435 -- Is_Appropriate_For_Entry_Prefix --
4436 -------------------------------------
4438 function Is_Appropriate_For_Entry_Prefix
(T
: Entity_Id
) return Boolean is
4439 P_Type
: Entity_Id
:= T
;
4442 if Is_Access_Type
(P_Type
) then
4443 P_Type
:= Designated_Type
(P_Type
);
4446 return Is_Task_Type
(P_Type
) or else Is_Protected_Type
(P_Type
);
4447 end Is_Appropriate_For_Entry_Prefix
;
4449 -------------------------------
4450 -- Is_Appropriate_For_Record --
4451 -------------------------------
4453 function Is_Appropriate_For_Record
4457 function Has_Components
(T1
: Entity_Id
) return Boolean;
4458 -- Determine if given type has components (i.e. is either a record
4459 -- type or a type that has discriminants).
4461 function Has_Components
(T1
: Entity_Id
) return Boolean is
4463 return Is_Record_Type
(T1
)
4464 or else (Is_Private_Type
(T1
) and then Has_Discriminants
(T1
))
4465 or else (Is_Task_Type
(T1
) and then Has_Discriminants
(T1
));
4468 -- Start of processing for Is_Appropriate_For_Record
4473 and then (Has_Components
(T
)
4474 or else (Is_Access_Type
(T
)
4476 Has_Components
(Designated_Type
(T
))));
4477 end Is_Appropriate_For_Record
;
4483 procedure New_Scope
(S
: Entity_Id
) is
4487 if Ekind
(S
) = E_Void
then
4490 -- Set scope depth if not a non-concurrent type, and we have not
4491 -- yet set the scope depth. This means that we have the first
4492 -- occurrence of the scope, and this is where the depth is set.
4494 elsif (not Is_Type
(S
) or else Is_Concurrent_Type
(S
))
4495 and then not Scope_Depth_Set
(S
)
4497 if S
= Standard_Standard
then
4498 Set_Scope_Depth_Value
(S
, Uint_0
);
4500 elsif Is_Child_Unit
(S
) then
4501 Set_Scope_Depth_Value
(S
, Uint_1
);
4503 elsif not Is_Record_Type
(Current_Scope
) then
4504 if Ekind
(S
) = E_Loop
then
4505 Set_Scope_Depth_Value
(S
, Scope_Depth
(Current_Scope
));
4507 Set_Scope_Depth_Value
(S
, Scope_Depth
(Current_Scope
) + 1);
4512 Scope_Stack
.Increment_Last
;
4514 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
:= S
;
4516 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
4519 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Entity_Suppress
:=
4520 Entity_Suppress
.Last
;
4522 if Scope_Stack
.Last
> Scope_Stack
.First
then
4523 Scope_Stack
.Table
(Scope_Stack
.Last
).Component_Alignment_Default
:=
4524 Scope_Stack
.Table
(Scope_Stack
.Last
- 1).Component_Alignment_Default
;
4527 Scope_Stack
.Table
(Scope_Stack
.Last
).Last_Subprogram_Name
:= null;
4528 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= False;
4529 Scope_Stack
.Table
(Scope_Stack
.Last
).Node_To_Be_Wrapped
:= Empty
;
4530 Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
:= No_List
;
4532 (Scope_Stack
.Last
).Actions_To_Be_Wrapped_Before
:= No_List
;
4534 (Scope_Stack
.Last
).Actions_To_Be_Wrapped_After
:= No_List
;
4535 Scope_Stack
.Table
(Scope_Stack
.Last
).First_Use_Clause
:= Empty
;
4536 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Active_Stack_Base
:= False;
4538 if Debug_Flag_W
then
4539 Write_Str
("--> new scope: ");
4540 Write_Name
(Chars
(Current_Scope
));
4541 Write_Str
(", Id=");
4542 Write_Int
(Int
(Current_Scope
));
4543 Write_Str
(", Depth=");
4544 Write_Int
(Int
(Scope_Stack
.Last
));
4548 -- Copy from Scope (S) the categorization flags to S, this is not
4549 -- done in case Scope (S) is Standard_Standard since propagation
4550 -- is from library unit entity inwards.
4552 if S
/= Standard_Standard
4553 and then Scope
(S
) /= Standard_Standard
4554 and then not Is_Child_Unit
(S
)
4558 if Nkind
(E
) not in N_Entity
then
4562 -- We only propagate inwards for library level entities,
4563 -- inner level subprograms do not inherit the categorization.
4565 if Is_Library_Level_Entity
(S
) then
4566 Set_Is_Pure
(S
, Is_Pure
(E
));
4567 Set_Is_Preelaborated
(S
, Is_Preelaborated
(E
));
4568 Set_Is_Remote_Call_Interface
(S
, Is_Remote_Call_Interface
(E
));
4569 Set_Is_Remote_Types
(S
, Is_Remote_Types
(E
));
4570 Set_Is_Shared_Passive
(S
, Is_Shared_Passive
(E
));
4579 procedure Pop_Scope
is
4583 if Debug_Flag_E
then
4588 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
;
4590 while Entity_Suppress
.Last
>
4591 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Entity_Suppress
4593 E
:= Entity_Suppress
.Table
(Entity_Suppress
.Last
).Entity
;
4595 case Entity_Suppress
.Table
(Entity_Suppress
.Last
).Check
is
4597 when Access_Check
=>
4598 Set_Suppress_Access_Checks
(E
, False);
4600 when Accessibility_Check
=>
4601 Set_Suppress_Accessibility_Checks
(E
, False);
4603 when Discriminant_Check
=>
4604 Set_Suppress_Discriminant_Checks
(E
, False);
4606 when Division_Check
=>
4607 Set_Suppress_Division_Checks
(E
, False);
4609 when Elaboration_Check
=>
4610 Set_Suppress_Elaboration_Checks
(E
, False);
4613 Set_Suppress_Index_Checks
(E
, False);
4615 when Length_Check
=>
4616 Set_Suppress_Length_Checks
(E
, False);
4618 when Overflow_Check
=>
4619 Set_Suppress_Overflow_Checks
(E
, False);
4622 Set_Suppress_Range_Checks
(E
, False);
4624 when Storage_Check
=>
4625 Set_Suppress_Storage_Checks
(E
, False);
4628 Set_Suppress_Tag_Checks
(E
, False);
4630 -- All_Checks should not appear here (since it is entered as a
4631 -- series of its separate checks). Bomb if it is encountered
4634 raise Program_Error
;
4637 Entity_Suppress
.Decrement_Last
;
4640 if Debug_Flag_W
then
4641 Write_Str
("--> exiting scope: ");
4642 Write_Name
(Chars
(Current_Scope
));
4643 Write_Str
(", Depth=");
4644 Write_Int
(Int
(Scope_Stack
.Last
));
4648 End_Use_Clauses
(Scope_Stack
.Table
(Scope_Stack
.Last
).First_Use_Clause
);
4650 -- If the actions to be wrapped are still there they will get lost
4651 -- causing incomplete code to be generated. It is better to abort in
4654 pragma Assert
(Scope_Stack
.Table
4655 (Scope_Stack
.Last
).Actions_To_Be_Wrapped_Before
= No_List
);
4657 pragma Assert
(Scope_Stack
.Table
4658 (Scope_Stack
.Last
).Actions_To_Be_Wrapped_After
= No_List
);
4660 -- Free last subprogram name if allocated, and pop scope
4662 Free
(Scope_Stack
.Table
(Scope_Stack
.Last
).Last_Subprogram_Name
);
4663 Scope_Stack
.Decrement_Last
;
4666 ---------------------
4667 -- Premature_Usage --
4668 ---------------------
4670 procedure Premature_Usage
(N
: Node_Id
) is
4671 Kind
: Node_Kind
:= Nkind
(Parent
(Entity
(N
)));
4672 E
: Entity_Id
:= Entity
(N
);
4675 -- Within an instance, the analysis of the actual for a formal object
4676 -- does not see the name of the object itself. This is significant
4677 -- only if the object is an aggregate, where its analysis does not do
4678 -- any name resolution on component associations. (see 4717-008). In
4679 -- such a case, look for the visible homonym on the chain.
4682 and then Present
(Homonym
(E
))
4687 and then not In_Open_Scopes
(Scope
(E
))
4694 Set_Etype
(N
, Etype
(E
));
4699 if Kind
= N_Component_Declaration
then
4701 ("component&! cannot be used before end of record declaration", N
);
4703 elsif Kind
= N_Parameter_Specification
then
4705 ("formal parameter&! cannot be used before end of specification",
4708 elsif Kind
= N_Discriminant_Specification
then
4710 ("discriminant&! cannot be used before end of discriminant part",
4713 elsif Kind
= N_Procedure_Specification
4714 or else Kind
= N_Function_Specification
4717 ("subprogram&! cannot be used before end of its declaration",
4721 ("object& cannot be used before end of its declaration!", N
);
4723 end Premature_Usage
;
4725 ------------------------
4726 -- Present_System_Aux --
4727 ------------------------
4729 function Present_System_Aux
(N
: Node_Id
:= Empty
) return Boolean is
4732 Unum
: Unit_Number_Type
;
4737 function Find_System
(C_Unit
: Node_Id
) return Entity_Id
;
4738 -- Scan context clause of compilation unit to find a with_clause
4741 function Find_System
(C_Unit
: Node_Id
) return Entity_Id
is
4742 With_Clause
: Node_Id
;
4745 With_Clause
:= First
(Context_Items
(C_Unit
));
4747 while Present
(With_Clause
) loop
4748 if (Nkind
(With_Clause
) = N_With_Clause
4749 and then Chars
(Name
(With_Clause
)) = Name_System
)
4750 and then Comes_From_Source
(With_Clause
)
4761 -- Start of processing for Present_System_Aux
4764 -- The child unit may have been loaded and analyzed already.
4766 if Present
(System_Aux_Id
) then
4769 -- If no previous pragma for System.Aux, nothing to load
4771 elsif No
(System_Extend_Pragma_Arg
) then
4774 -- Use the unit name given in the pragma to retrieve the unit.
4775 -- Verify that System itself appears in the context clause of the
4776 -- current compilation. If System is not present, an error will
4777 -- have been reported already.
4780 With_Sys
:= Find_System
(Cunit
(Current_Sem_Unit
));
4782 The_Unit
:= Unit
(Cunit
(Current_Sem_Unit
));
4785 and then (Nkind
(The_Unit
) = N_Package_Body
4786 or else (Nkind
(The_Unit
) = N_Subprogram_Body
4787 and then not Acts_As_Spec
(Cunit
(Current_Sem_Unit
))))
4789 With_Sys
:= Find_System
(Library_Unit
(Cunit
(Current_Sem_Unit
)));
4793 and then Present
(N
)
4795 -- If we are compiling a subunit, we need to examine its
4796 -- context as well (Current_Sem_Unit is the parent unit);
4798 The_Unit
:= Parent
(N
);
4800 while Nkind
(The_Unit
) /= N_Compilation_Unit
loop
4801 The_Unit
:= Parent
(The_Unit
);
4804 if Nkind
(Unit
(The_Unit
)) = N_Subunit
then
4805 With_Sys
:= Find_System
(The_Unit
);
4809 if No
(With_Sys
) then
4813 Loc
:= Sloc
(With_Sys
);
4814 Get_Name_String
(Chars
(Expression
(System_Extend_Pragma_Arg
)));
4815 Name_Buffer
(8 .. Name_Len
+ 7) := Name_Buffer
(1 .. Name_Len
);
4816 Name_Buffer
(1 .. 7) := "system.";
4817 Name_Buffer
(Name_Len
+ 8) := '%';
4818 Name_Buffer
(Name_Len
+ 9) := 's';
4819 Name_Len
:= Name_Len
+ 9;
4820 Aux_Name
:= Name_Find
;
4824 (Load_Name
=> Aux_Name
,
4827 Error_Node
=> With_Sys
);
4829 if Unum
/= No_Unit
then
4830 Semantics
(Cunit
(Unum
));
4832 Defining_Entity
(Specification
(Unit
(Cunit
(Unum
))));
4834 Withn
:= Make_With_Clause
(Loc
,
4836 Make_Expanded_Name
(Loc
,
4837 Chars
=> Chars
(System_Aux_Id
),
4839 New_Reference_To
(Scope
(System_Aux_Id
), Loc
),
4841 New_Reference_To
(System_Aux_Id
, Loc
)));
4843 Set_Entity
(Name
(Withn
), System_Aux_Id
);
4845 Set_Library_Unit
(Withn
, Cunit
(Unum
));
4846 Set_Corresponding_Spec
(Withn
, System_Aux_Id
);
4847 Set_First_Name
(Withn
, True);
4848 Set_Implicit_With
(Withn
, True);
4850 Insert_After
(With_Sys
, Withn
);
4851 Mark_Rewrite_Insertion
(Withn
);
4852 Set_Context_Installed
(Withn
);
4856 -- Here if unit load failed
4859 Error_Msg_Name_1
:= Name_System
;
4860 Error_Msg_Name_2
:= Chars
(Expression
(System_Extend_Pragma_Arg
));
4862 ("extension package `%.%` does not exist",
4863 Opt
.System_Extend_Pragma_Arg
);
4867 end Present_System_Aux
;
4869 -------------------------
4870 -- Restore_Scope_Stack --
4871 -------------------------
4873 procedure Restore_Scope_Stack
is
4876 Comp_Unit
: Node_Id
;
4877 In_Child
: Boolean := False;
4878 Full_Vis
: Boolean := True;
4881 -- Restore visibility of previous scope stack, if any.
4883 for J
in reverse 0 .. Scope_Stack
.Last
loop
4884 exit when Scope_Stack
.Table
(J
).Entity
= Standard_Standard
4885 or else No
(Scope_Stack
.Table
(J
).Entity
);
4887 S
:= Scope_Stack
.Table
(J
).Entity
;
4889 if not Is_Hidden_Open_Scope
(S
) then
4891 -- If the parent scope is hidden, its entities are hidden as
4892 -- well, unless the entity is the instantiation currently
4895 if not Is_Hidden_Open_Scope
(Scope
(S
))
4896 or else not Analyzed
(Parent
(S
))
4897 or else Scope
(S
) = Standard_Standard
4899 Set_Is_Immediately_Visible
(S
, True);
4902 E
:= First_Entity
(S
);
4904 while Present
(E
) loop
4905 if Is_Child_Unit
(E
) then
4906 Set_Is_Immediately_Visible
(E
,
4907 Is_Visible_Child_Unit
(E
) or else In_Open_Scopes
(E
));
4909 Set_Is_Immediately_Visible
(E
, True);
4914 if not Full_Vis
then
4915 exit when E
= First_Private_Entity
(S
);
4919 -- The visibility of child units (siblings of current compilation)
4920 -- must be restored in any case. Their declarations may appear
4921 -- after the private part of the parent.
4924 and then Present
(E
)
4926 while Present
(E
) loop
4927 if Is_Child_Unit
(E
) then
4928 Set_Is_Immediately_Visible
(E
,
4929 Is_Visible_Child_Unit
(E
) or else In_Open_Scopes
(E
));
4937 if Is_Child_Unit
(S
)
4938 and not In_Child
-- check only for current unit.
4942 -- restore visibility of parents according to whether the child
4943 -- is private and whether we are in its visible part.
4945 Comp_Unit
:= Parent
(Unit_Declaration_Node
(S
));
4947 if Nkind
(Comp_Unit
) = N_Compilation_Unit
4948 and then Private_Present
(Comp_Unit
)
4952 elsif (Ekind
(S
) = E_Package
4953 or else Ekind
(S
) = E_Generic_Package
)
4954 and then (In_Private_Part
(S
)
4955 or else In_Package_Body
(S
))
4959 elsif (Ekind
(S
) = E_Procedure
4960 or else Ekind
(S
) = E_Function
)
4961 and then Has_Completion
(S
)
4971 end Restore_Scope_Stack
;
4973 ----------------------
4974 -- Save_Scope_Stack --
4975 ----------------------
4977 procedure Save_Scope_Stack
is
4980 SS_Last
: constant Int
:= Scope_Stack
.Last
;
4983 if SS_Last
>= Scope_Stack
.First
4984 and then Scope_Stack
.Table
(SS_Last
).Entity
/= Standard_Standard
4987 -- If the call is from within a compilation unit, as when
4988 -- called from Rtsfind, make current entries in scope stack
4989 -- invisible while we analyze the new unit.
4991 for J
in reverse 0 .. SS_Last
loop
4992 exit when Scope_Stack
.Table
(J
).Entity
= Standard_Standard
4993 or else No
(Scope_Stack
.Table
(J
).Entity
);
4995 S
:= Scope_Stack
.Table
(J
).Entity
;
4996 Set_Is_Immediately_Visible
(S
, False);
4997 E
:= First_Entity
(S
);
4999 while Present
(E
) loop
5000 Set_Is_Immediately_Visible
(E
, False);
5006 end Save_Scope_Stack
;
5012 procedure Set_Use
(L
: List_Id
) is
5014 Pack_Name
: Node_Id
;
5022 while Present
(Decl
) loop
5023 if Nkind
(Decl
) = N_Use_Package_Clause
then
5024 Chain_Use_Clause
(Decl
);
5025 Pack_Name
:= First
(Names
(Decl
));
5027 while Present
(Pack_Name
) loop
5028 Pack
:= Entity
(Pack_Name
);
5030 if Ekind
(Pack
) = E_Package
5031 and then Applicable_Use
(Pack_Name
)
5033 Use_One_Package
(Pack
, Decl
);
5039 elsif Nkind
(Decl
) = N_Use_Type_Clause
then
5040 Chain_Use_Clause
(Decl
);
5041 Id
:= First
(Subtype_Marks
(Decl
));
5043 while Present
(Id
) loop
5044 if Entity
(Id
) /= Any_Type
then
5057 ---------------------
5058 -- Use_One_Package --
5059 ---------------------
5061 procedure Use_One_Package
(P
: Entity_Id
; N
: Node_Id
) is
5064 Current_Instance
: Entity_Id
:= Empty
;
5068 if Ekind
(P
) /= E_Package
then
5074 if From_With_Type
(P
) then
5075 Error_Msg_N
("imported package cannot appear in use clause", N
);
5078 -- Find enclosing instance, if any.
5081 Current_Instance
:= Current_Scope
;
5083 while not Is_Generic_Instance
(Current_Instance
) loop
5084 Current_Instance
:= Scope
(Current_Instance
);
5087 if No
(Hidden_By_Use_Clause
(N
)) then
5088 Set_Hidden_By_Use_Clause
(N
, New_Elmt_List
);
5092 -- If unit is a package renaming, indicate that the renamed
5093 -- package is also in use (the flags on both entities must
5094 -- remain consistent, and a subsequent use of either of them
5095 -- should be recognized as redundant).
5097 if Present
(Renamed_Object
(P
)) then
5098 Set_In_Use
(Renamed_Object
(P
));
5099 Real_P
:= Renamed_Object
(P
);
5104 -- Loop through entities in one package making them potentially
5107 Id
:= First_Entity
(P
);
5109 and then Id
/= First_Private_Entity
(P
)
5111 Prev
:= Current_Entity
(Id
);
5113 while Present
(Prev
) loop
5114 if Is_Immediately_Visible
(Prev
)
5115 and then (not Is_Overloadable
(Prev
)
5116 or else not Is_Overloadable
(Id
)
5117 or else (Type_Conformant
(Id
, Prev
)))
5119 if No
(Current_Instance
) then
5121 -- Potentially use-visible entity remains hidden
5123 goto Next_Usable_Entity
;
5125 -- A use clause within an instance hides outer global
5126 -- entities, which are not used to resolve local entities
5127 -- in the instance. Note that the predefined entities in
5128 -- Standard could not have been hidden in the generic by
5129 -- a use clause, and therefore remain visible. Other
5130 -- compilation units whose entities appear in Standard must
5131 -- be hidden in an instance.
5133 -- To determine whether an entity is external to the instance
5134 -- we compare the scope depth of its scope with that of the
5135 -- current instance. However, a generic actual of a subprogram
5136 -- instance is declared in the wrapper package but will not be
5137 -- hidden by a use-visible entity.
5139 elsif not Is_Hidden
(Id
)
5140 and then not Is_Wrapper_Package
(Scope
(Prev
))
5141 and then Scope_Depth
(Scope
(Prev
)) <
5142 Scope_Depth
(Current_Instance
)
5143 and then (Scope
(Prev
) /= Standard_Standard
5144 or else Sloc
(Prev
) > Standard_Location
)
5146 Set_Is_Potentially_Use_Visible
(Id
);
5147 Set_Is_Immediately_Visible
(Prev
, False);
5148 Append_Elmt
(Prev
, Hidden_By_Use_Clause
(N
));
5151 -- A user-defined operator is not use-visible if the
5152 -- predefined operator for the type is immediately visible,
5153 -- which is the case if the type of the operand is in an open
5154 -- scope. This does not apply to user-defined operators that
5155 -- have operands of different types, because the predefined
5156 -- mixed mode operations (multiplication and division) apply to
5157 -- universal types and do not hide anything.
5159 elsif Ekind
(Prev
) = E_Operator
5160 and then Operator_Matches_Spec
(Prev
, Id
)
5161 and then In_Open_Scopes
5162 (Scope
(Base_Type
(Etype
(First_Formal
(Id
)))))
5163 and then (No
(Next_Formal
(First_Formal
(Id
)))
5164 or else Etype
(First_Formal
(Id
))
5165 = Etype
(Next_Formal
(First_Formal
(Id
)))
5166 or else Chars
(Prev
) = Name_Op_Expon
)
5168 goto Next_Usable_Entity
;
5171 Prev
:= Homonym
(Prev
);
5174 -- On exit, we know entity is not hidden, unless it is private.
5176 if not Is_Hidden
(Id
)
5177 and then ((not Is_Child_Unit
(Id
))
5178 or else Is_Visible_Child_Unit
(Id
))
5180 Set_Is_Potentially_Use_Visible
(Id
);
5182 if Is_Private_Type
(Id
)
5183 and then Present
(Full_View
(Id
))
5185 Set_Is_Potentially_Use_Visible
(Full_View
(Id
));
5189 <<Next_Usable_Entity
>>
5193 -- Child units are also made use-visible by a use clause, but they
5194 -- may appear after all visible declarations in the parent entity list.
5196 while Present
(Id
) loop
5198 if Is_Child_Unit
(Id
)
5199 and then Is_Visible_Child_Unit
(Id
)
5201 Set_Is_Potentially_Use_Visible
(Id
);
5207 if Chars
(Real_P
) = Name_System
5208 and then Scope
(Real_P
) = Standard_Standard
5209 and then Present_System_Aux
(N
)
5211 Use_One_Package
(System_Aux_Id
, N
);
5214 end Use_One_Package
;
5220 procedure Use_One_Type
(Id
: Node_Id
) is
5226 -- It is the type determined by the subtype mark (8.4(8)) whose
5227 -- operations become potentially use-visible.
5229 T
:= Base_Type
(Entity
(Id
));
5231 -- Save current visibility status of type, before setting.
5234 (Id
, In_Use
(T
) or else Is_Potentially_Use_Visible
(T
));
5236 if In_Open_Scopes
(Scope
(T
)) then
5239 elsif not Redundant_Use
(Id
) then
5241 Op_List
:= Collect_Primitive_Operations
(T
);
5242 Elmt
:= First_Elmt
(Op_List
);
5244 while Present
(Elmt
) loop
5246 if (Nkind
(Node
(Elmt
)) = N_Defining_Operator_Symbol
5247 or else Chars
(Node
(Elmt
)) in Any_Operator_Name
)
5248 and then not Is_Hidden
(Node
(Elmt
))
5250 Set_Is_Potentially_Use_Visible
(Node
(Elmt
));
5262 procedure Write_Info
is
5263 Id
: Entity_Id
:= First_Entity
(Current_Scope
);
5266 -- No point in dumping standard entities
5268 if Current_Scope
= Standard_Standard
then
5272 Write_Str
("========================================================");
5274 Write_Str
(" Defined Entities in ");
5275 Write_Name
(Chars
(Current_Scope
));
5277 Write_Str
("========================================================");
5281 Write_Str
("-- none --");
5285 while Present
(Id
) loop
5286 Write_Entity_Info
(Id
, " ");
5291 if Scope
(Current_Scope
) = Standard_Standard
then
5293 -- Print information on the current unit itself
5295 Write_Entity_Info
(Current_Scope
, " ");
5305 procedure Write_Scopes
is
5309 for J
in reverse 1 .. Scope_Stack
.Last
loop
5310 S
:= Scope_Stack
.Table
(J
).Entity
;
5311 Write_Int
(Int
(S
));
5312 Write_Str
(" === ");
5313 Write_Name
(Chars
(S
));