1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2003, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Util; use Exp_Util;
33 with Fname; use Fname;
34 with Freeze; use Freeze;
36 with Lib.Load; use Lib.Load;
37 with Lib.Xref; use Lib.Xref;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
42 with Output; use Output;
43 with Restrict; use Restrict;
44 with Rtsfind; use Rtsfind;
46 with Sem_Cat; use Sem_Cat;
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 potentially 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 re-chained 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 function Applicable_Use (Pack_Name : Node_Id) return Boolean;
389 -- Common code to Use_One_Package and Set_Use, to determine whether
390 -- use clause must be processed. Pack_Name is an entity name that
391 -- references the package in question.
393 procedure Attribute_Renaming (N : Node_Id);
394 -- Analyze renaming of attribute as function. The renaming declaration N
395 -- is rewritten as a function body that returns the attribute reference
396 -- applied to the formals of the function.
398 procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id);
399 -- A renaming_as_body may occur after the entity of the original decla-
400 -- ration has been frozen. In that case, the body of the new entity must
401 -- be built now, because the usual mechanism of building the renamed
402 -- body at the point of freezing will not work. Subp is the subprogram
403 -- for which N provides the Renaming_As_Body.
405 procedure Check_In_Previous_With_Clause
408 -- N is a use_package clause and Nam the package name, or N is a use_type
409 -- clause and Nam is the prefix of the type name. In either case, verify
410 -- that the package is visible at that point in the context: either it
411 -- appears in a previous with_clause, or because it is a fully qualified
412 -- name and the root ancestor appears in a previous with_clause.
414 procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id);
415 -- Verify that the entity in a renaming declaration that is a library unit
416 -- is itself a library unit and not a nested unit or subunit. Also check
417 -- that if the renaming is a child unit of a generic parent, then the
418 -- renamed unit must also be a child unit of that parent. Finally, verify
419 -- that a renamed generic unit is not an implicit child declared within
420 -- an instance of the parent.
422 procedure Chain_Use_Clause (N : Node_Id);
423 -- Chain use clause onto list of uses clauses headed by First_Use_Clause
424 -- in the top scope table entry.
426 function Has_Implicit_Character_Literal (N : Node_Id) return Boolean;
427 -- Find a type derived from Character or Wide_Character in the prefix of N.
428 -- Used to resolved qualified names whose selector is a character literal.
430 procedure Find_Expanded_Name (N : Node_Id);
431 -- Selected component is known to be expanded name. Verify legality
432 -- of selector given the scope denoted by prefix.
434 function Find_Renamed_Entity
438 Is_Actual : Boolean := False) return Entity_Id;
439 -- Find the renamed entity that corresponds to the given parameter profile
440 -- in a subprogram renaming declaration. The renamed entity may be an
441 -- operator, a subprogram, an entry, or a protected operation. Is_Actual
442 -- indicates that the renaming is the one generated for an actual subpro-
443 -- gram in an instance, for which special visibility checks apply.
445 function Has_Implicit_Operator (N : Node_Id) return Boolean;
446 -- N is an expanded name whose selector is an operator name (eg P."+").
447 -- A declarative part contains an implicit declaration of an operator
448 -- if it has a declaration of a type to which one of the predefined
449 -- operators apply. The existence of this routine is an artifact of
450 -- our implementation: a more straightforward but more space-consuming
451 -- choice would be to make all inherited operators explicit in the
454 procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id);
455 -- A subprogram defined by a renaming declaration inherits the parameter
456 -- profile of the renamed entity. The subtypes given in the subprogram
457 -- specification are discarded and replaced with those of the renamed
458 -- subprogram, which are then used to recheck the default values.
460 function Is_Appropriate_For_Record (T : Entity_Id) return Boolean;
461 -- Prefix is appropriate for record if it is of a record type, or
462 -- an access to such.
464 function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean;
465 -- True if it is of a task type, a protected type, or else an access
466 -- to one of these types.
468 procedure Premature_Usage (N : Node_Id);
469 -- Diagnose usage of an entity before it is visible.
471 procedure Use_One_Package (P : Entity_Id; N : Node_Id);
472 -- Make visible entities declared in package P potentially use-visible
473 -- in the current context. Also used in the analysis of subunits, when
474 -- re-installing use clauses of parent units. N is the use_clause that
475 -- names P (and possibly other packages).
477 procedure Use_One_Type (Id : Node_Id);
478 -- Id is the subtype mark from a use type clause. This procedure makes
479 -- the primitive operators of the type potentially use-visible.
481 procedure Write_Info;
482 -- Write debugging information on entities declared in current scope
484 procedure Write_Scopes;
485 pragma Warnings (Off, Write_Scopes);
486 -- Debugging information: dump all entities on scope stack
488 --------------------------------
489 -- Analyze_Exception_Renaming --
490 --------------------------------
492 -- The language only allows a single identifier, but the tree holds
493 -- an identifier list. The parser has already issued an error message
494 -- if there is more than one element in the list.
496 procedure Analyze_Exception_Renaming (N : Node_Id) is
497 Id : constant Node_Id := Defining_Identifier (N);
498 Nam : constant Node_Id := Name (N);
504 Set_Ekind (Id, E_Exception);
505 Set_Exception_Code (Id, Uint_0);
506 Set_Etype (Id, Standard_Exception_Type);
507 Set_Is_Pure (Id, Is_Pure (Current_Scope));
509 if not Is_Entity_Name (Nam) or else
510 Ekind (Entity (Nam)) /= E_Exception
512 Error_Msg_N ("invalid exception name in renaming", Nam);
514 if Present (Renamed_Object (Entity (Nam))) then
515 Set_Renamed_Object (Id, Renamed_Object (Entity (Nam)));
517 Set_Renamed_Object (Id, Entity (Nam));
520 end Analyze_Exception_Renaming;
522 ---------------------------
523 -- Analyze_Expanded_Name --
524 ---------------------------
526 procedure Analyze_Expanded_Name (N : Node_Id) is
528 -- If the entity pointer is already set, this is an internal node, or
529 -- a node that is analyzed more than once, after a tree modification.
530 -- In such a case there is no resolution to perform, just set the type.
531 -- For completeness, analyze prefix as well.
533 if Present (Entity (N)) then
534 if Is_Type (Entity (N)) then
535 Set_Etype (N, Entity (N));
537 Set_Etype (N, Etype (Entity (N)));
540 Analyze (Prefix (N));
543 Find_Expanded_Name (N);
545 end Analyze_Expanded_Name;
547 ----------------------------------------
548 -- Analyze_Generic_Function_Renaming --
549 ----------------------------------------
551 procedure Analyze_Generic_Function_Renaming (N : Node_Id) is
553 Analyze_Generic_Renaming (N, E_Generic_Function);
554 end Analyze_Generic_Function_Renaming;
556 ---------------------------------------
557 -- Analyze_Generic_Package_Renaming --
558 ---------------------------------------
560 procedure Analyze_Generic_Package_Renaming (N : Node_Id) is
562 -- Apply the Text_IO Kludge here, since we may be renaming
563 -- one of the subpackages of Text_IO, then join common routine.
565 Text_IO_Kludge (Name (N));
567 Analyze_Generic_Renaming (N, E_Generic_Package);
568 end Analyze_Generic_Package_Renaming;
570 -----------------------------------------
571 -- Analyze_Generic_Procedure_Renaming --
572 -----------------------------------------
574 procedure Analyze_Generic_Procedure_Renaming (N : Node_Id) is
576 Analyze_Generic_Renaming (N, E_Generic_Procedure);
577 end Analyze_Generic_Procedure_Renaming;
579 ------------------------------
580 -- Analyze_Generic_Renaming --
581 ------------------------------
583 procedure Analyze_Generic_Renaming
587 New_P : constant Entity_Id := Defining_Entity (N);
589 Inst : Boolean := False; -- prevent junk warning
592 if Name (N) = Error then
596 Generate_Definition (New_P);
598 if Current_Scope /= Standard_Standard then
599 Set_Is_Pure (New_P, Is_Pure (Current_Scope));
602 if Nkind (Name (N)) = N_Selected_Component then
603 Check_Generic_Child_Unit (Name (N), Inst);
608 if not Is_Entity_Name (Name (N)) then
609 Error_Msg_N ("expect entity name in renaming declaration", Name (N));
612 Old_P := Entity (Name (N));
616 Set_Ekind (New_P, K);
618 if Etype (Old_P) = Any_Type then
621 elsif Ekind (Old_P) /= K then
622 Error_Msg_N ("invalid generic unit name", Name (N));
625 if Present (Renamed_Object (Old_P)) then
626 Set_Renamed_Object (New_P, Renamed_Object (Old_P));
628 Set_Renamed_Object (New_P, Old_P);
631 Set_Etype (New_P, Etype (Old_P));
632 Set_Has_Completion (New_P);
634 if In_Open_Scopes (Old_P) then
635 Error_Msg_N ("within its scope, generic denotes its instance", N);
638 Check_Library_Unit_Renaming (N, Old_P);
641 end Analyze_Generic_Renaming;
643 -----------------------------
644 -- Analyze_Object_Renaming --
645 -----------------------------
647 procedure Analyze_Object_Renaming (N : Node_Id) is
648 Id : constant Entity_Id := Defining_Identifier (N);
650 Nam : constant Node_Id := Name (N);
651 S : constant Entity_Id := Subtype_Mark (N);
660 Set_Is_Pure (Id, Is_Pure (Current_Scope));
663 -- The renaming of a component that depends on a discriminant
664 -- requires an actual subtype, because in subsequent use of the object
665 -- Gigi will be unable to locate the actual bounds. This explicit step
666 -- is required when the renaming is generated in removing side effects
667 -- of an already-analyzed expression.
669 if Nkind (Nam) = N_Selected_Component
670 and then Analyzed (Nam)
673 Dec := Build_Actual_Subtype_Of_Component (Etype (Nam), Nam);
675 if Present (Dec) then
676 Insert_Action (N, Dec);
677 T := Defining_Identifier (Dec);
684 Analyze_And_Resolve (Nam, T);
687 -- An object renaming requires an exact match of the type;
688 -- class-wide matching is not allowed.
690 if Is_Class_Wide_Type (T)
691 and then Base_Type (Etype (Nam)) /= Base_Type (T)
697 Set_Ekind (Id, E_Variable);
698 Init_Size_Align (Id);
700 if T = Any_Type or else Etype (Nam) = Any_Type then
703 -- Verify that the renamed entity is an object or a function call.
704 -- It may have been rewritten in several ways.
706 elsif Is_Object_Reference (Nam) then
707 if Comes_From_Source (N)
708 and then Is_Dependent_Component_Of_Mutable_Object (Nam)
711 ("illegal renaming of discriminant-dependent component", Nam);
716 -- A static function call may have been folded into a literal
718 elsif Nkind (Original_Node (Nam)) = N_Function_Call
720 -- When expansion is disabled, attribute reference is not
721 -- rewritten as function call. Otherwise it may be rewritten
722 -- as a conversion, so check original node.
724 or else (Nkind (Original_Node (Nam)) = N_Attribute_Reference
725 and then Is_Function_Attribute_Name
726 (Attribute_Name (Original_Node (Nam))))
728 -- Weird but legal, equivalent to renaming a function call.
730 or else (Is_Entity_Name (Nam)
731 and then Ekind (Entity (Nam)) = E_Enumeration_Literal)
733 or else (Nkind (Nam) = N_Type_Conversion
734 and then Is_Tagged_Type (Entity (Subtype_Mark (Nam))))
739 if Nkind (Nam) = N_Type_Conversion then
741 ("renaming of conversion only allowed for tagged types", Nam);
744 Error_Msg_N ("expect object name in renaming", Nam);
751 if not Is_Variable (Nam) then
752 Set_Ekind (Id, E_Constant);
753 Set_Never_Set_In_Source (Id, True);
754 Set_Is_True_Constant (Id, True);
757 Set_Renamed_Object (Id, Nam);
758 end Analyze_Object_Renaming;
760 ------------------------------
761 -- Analyze_Package_Renaming --
762 ------------------------------
764 procedure Analyze_Package_Renaming (N : Node_Id) is
765 New_P : constant Entity_Id := Defining_Entity (N);
770 if Name (N) = Error then
774 -- Apply Text_IO kludge here, since we may be renaming one of
775 -- the children of Text_IO
777 Text_IO_Kludge (Name (N));
779 if Current_Scope /= Standard_Standard then
780 Set_Is_Pure (New_P, Is_Pure (Current_Scope));
785 if Is_Entity_Name (Name (N)) then
786 Old_P := Entity (Name (N));
791 if Etype (Old_P) = Any_Type then
793 ("expect package name in renaming", Name (N));
795 elsif Ekind (Old_P) /= E_Package
796 and then not (Ekind (Old_P) = E_Generic_Package
797 and then In_Open_Scopes (Old_P))
799 if Ekind (Old_P) = E_Generic_Package then
801 ("generic package cannot be renamed as a package", Name (N));
803 Error_Msg_Sloc := Sloc (Old_P);
805 ("expect package name in renaming, found& declared#",
809 -- Set basic attributes to minimize cascaded errors.
811 Set_Ekind (New_P, E_Package);
812 Set_Etype (New_P, Standard_Void_Type);
814 elsif Ekind (Old_P) = E_Package
815 and then From_With_Type (Old_P)
817 Error_Msg_N ("imported package cannot be renamed", Name (N));
820 -- Entities in the old package are accessible through the
821 -- renaming entity. The simplest implementation is to have
822 -- both packages share the entity list.
824 Set_Ekind (New_P, E_Package);
825 Set_Etype (New_P, Standard_Void_Type);
827 if Present (Renamed_Object (Old_P)) then
828 Set_Renamed_Object (New_P, Renamed_Object (Old_P));
830 Set_Renamed_Object (New_P, Old_P);
833 Set_Has_Completion (New_P);
835 Set_First_Entity (New_P, First_Entity (Old_P));
836 Set_Last_Entity (New_P, Last_Entity (Old_P));
837 Set_First_Private_Entity (New_P, First_Private_Entity (Old_P));
838 Check_Library_Unit_Renaming (N, Old_P);
839 Generate_Reference (Old_P, Name (N));
841 -- If this is the renaming declaration of a package instantiation
842 -- within itself, it is the declaration that ends the list of actuals
843 -- for the instantiation. At this point, the subtypes that rename
844 -- the actuals are flagged as generic, to avoid spurious ambiguities
845 -- if the actuals for two distinct formals happen to coincide. If
846 -- the actual is a private type, the subtype has a private completion
847 -- that is flagged in the same fashion.
849 -- Resolution is identical to what is was in the original generic.
850 -- On exit from the generic instance, these are turned into regular
851 -- subtypes again, so they are compatible with types in their class.
853 if not Is_Generic_Instance (Old_P) then
856 Spec := Specification (Unit_Declaration_Node (Old_P));
859 if Nkind (Spec) = N_Package_Specification
860 and then Present (Generic_Parent (Spec))
861 and then Old_P = Current_Scope
862 and then Chars (New_P) = Chars (Generic_Parent (Spec))
865 E : Entity_Id := First_Entity (Old_P);
871 and then Nkind (Parent (E)) = N_Subtype_Declaration
873 Set_Is_Generic_Actual_Type (E);
875 if Is_Private_Type (E)
876 and then Present (Full_View (E))
878 Set_Is_Generic_Actual_Type (Full_View (E));
888 end Analyze_Package_Renaming;
890 -------------------------------
891 -- Analyze_Renamed_Character --
892 -------------------------------
894 procedure Analyze_Renamed_Character
899 C : constant Node_Id := Name (N);
902 if Ekind (New_S) = E_Function then
903 Resolve (C, Etype (New_S));
906 Check_Frozen_Renaming (N, New_S);
910 Error_Msg_N ("character literal can only be renamed as function", N);
912 end Analyze_Renamed_Character;
914 ---------------------------------
915 -- Analyze_Renamed_Dereference --
916 ---------------------------------
918 procedure Analyze_Renamed_Dereference
923 Nam : constant Node_Id := Name (N);
924 P : constant Node_Id := Prefix (Nam);
930 if not Is_Overloaded (P) then
931 if Ekind (Etype (Nam)) /= E_Subprogram_Type
932 or else not Type_Conformant (Etype (Nam), New_S) then
933 Error_Msg_N ("designated type does not match specification", P);
942 Get_First_Interp (Nam, Ind, It);
944 while Present (It.Nam) loop
946 if Ekind (It.Nam) = E_Subprogram_Type
947 and then Type_Conformant (It.Nam, New_S) then
949 if Typ /= Any_Id then
950 Error_Msg_N ("ambiguous renaming", P);
957 Get_Next_Interp (Ind, It);
960 if Typ = Any_Type then
961 Error_Msg_N ("designated type does not match specification", P);
966 Check_Frozen_Renaming (N, New_S);
970 end Analyze_Renamed_Dereference;
972 ---------------------------
973 -- Analyze_Renamed_Entry --
974 ---------------------------
976 procedure Analyze_Renamed_Entry
981 Nam : constant Node_Id := Name (N);
982 Sel : constant Node_Id := Selector_Name (Nam);
986 if Entity (Sel) = Any_Id then
988 -- Selector is undefined on prefix. Error emitted already.
990 Set_Has_Completion (New_S);
994 -- Otherwise, find renamed entity, and build body of New_S as a call
997 Old_S := Find_Renamed_Entity (N, Selector_Name (Nam), New_S);
999 if Old_S = Any_Id then
1000 Error_Msg_N (" no subprogram or entry matches specification", N);
1003 Check_Subtype_Conformant (New_S, Old_S, N);
1004 Generate_Reference (New_S, Defining_Entity (N), 'b');
1005 Style.Check_Identifier (Defining_Entity (N), New_S);
1008 Inherit_Renamed_Profile (New_S, Old_S);
1011 Set_Convention (New_S, Convention (Old_S));
1012 Set_Has_Completion (New_S, Inside_A_Generic);
1015 Check_Frozen_Renaming (N, New_S);
1017 end Analyze_Renamed_Entry;
1019 -----------------------------------
1020 -- Analyze_Renamed_Family_Member --
1021 -----------------------------------
1023 procedure Analyze_Renamed_Family_Member
1028 Nam : constant Node_Id := Name (N);
1029 P : constant Node_Id := Prefix (Nam);
1033 if (Is_Entity_Name (P) and then Ekind (Entity (P)) = E_Entry_Family)
1034 or else (Nkind (P) = N_Selected_Component
1036 Ekind (Entity (Selector_Name (P))) = E_Entry_Family)
1038 if Is_Entity_Name (P) then
1039 Old_S := Entity (P);
1041 Old_S := Entity (Selector_Name (P));
1044 if not Entity_Matches_Spec (Old_S, New_S) then
1045 Error_Msg_N ("entry family does not match specification", N);
1048 Check_Subtype_Conformant (New_S, Old_S, N);
1049 Generate_Reference (New_S, Defining_Entity (N), 'b');
1050 Style.Check_Identifier (Defining_Entity (N), New_S);
1053 Error_Msg_N ("no entry family matches specification", N);
1056 Set_Has_Completion (New_S, Inside_A_Generic);
1059 Check_Frozen_Renaming (N, New_S);
1061 end Analyze_Renamed_Family_Member;
1063 ---------------------------------
1064 -- Analyze_Subprogram_Renaming --
1065 ---------------------------------
1067 procedure Analyze_Subprogram_Renaming (N : Node_Id) is
1068 Spec : constant Node_Id := Specification (N);
1069 Save_83 : constant Boolean := Ada_83;
1070 Nam : constant Node_Id := Name (N);
1072 Old_S : Entity_Id := Empty;
1073 Rename_Spec : Entity_Id;
1074 Is_Actual : Boolean := False;
1075 Inst_Node : Node_Id := Empty;
1077 function Original_Subprogram (Subp : Entity_Id) return Entity_Id;
1078 -- Find renamed entity when the declaration is a renaming_as_body
1079 -- and the renamed entity may itself be a renaming_as_body. Used to
1080 -- enforce rule that a renaming_as_body is illegal if the declaration
1081 -- occurs before the subprogram it completes is frozen, and renaming
1082 -- indirectly renames the subprogram itself.(Defect Report 8652/0027).
1084 -------------------------
1085 -- Original_Subprogram --
1086 -------------------------
1088 function Original_Subprogram (Subp : Entity_Id) return Entity_Id is
1089 Orig_Decl : Node_Id;
1090 Orig_Subp : Entity_Id;
1093 -- First case: renamed entity is itself a renaming
1095 if Present (Alias (Subp)) then
1096 return Alias (Subp);
1099 Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration
1101 (Corresponding_Body (Unit_Declaration_Node (Subp)))
1103 -- Check if renamed entity is a renaming_as_body
1106 Unit_Declaration_Node
1107 (Corresponding_Body (Unit_Declaration_Node (Subp)));
1109 if Nkind (Orig_Decl) = N_Subprogram_Renaming_Declaration then
1110 Orig_Subp := Entity (Name (Orig_Decl));
1112 if Orig_Subp = Rename_Spec then
1114 -- Circularity detected.
1119 return (Original_Subprogram (Orig_Subp));
1127 end Original_Subprogram;
1129 -- Start of processing for Analyze_Subprogram_Renaming
1132 -- We must test for the attribute renaming case before the Analyze
1133 -- call because otherwise Sem_Attr will complain that the attribute
1134 -- is missing an argument when it is analyzed.
1136 if Nkind (Nam) = N_Attribute_Reference then
1137 Attribute_Renaming (N);
1141 -- Check whether this declaration corresponds to the instantiation
1142 -- of a formal subprogram. This is indicated by the presence of a
1143 -- Corresponding_Spec that is the instantiation declaration.
1145 -- If this is an instantiation, the corresponding actual is frozen
1146 -- and error messages can be made more precise. If this is a default
1147 -- subprogram, the entity is already established in the generic, and
1148 -- is not retrieved by visibility. If it is a default with a box, the
1149 -- candidate interpretations, if any, have been collected when building
1150 -- the renaming declaration. If overloaded, the proper interpretation
1151 -- is determined in Find_Renamed_Entity. If the entity is an operator,
1152 -- Find_Renamed_Entity applies additional visibility checks.
1154 if Present (Corresponding_Spec (N)) then
1156 Inst_Node := Unit_Declaration_Node (Corresponding_Spec (N));
1158 if Is_Entity_Name (Nam)
1159 and then Present (Entity (Nam))
1160 and then not Comes_From_Source (Nam)
1161 and then not Is_Overloaded (Nam)
1163 Old_S := Entity (Nam);
1164 New_S := Analyze_Subprogram_Specification (Spec);
1166 if Ekind (Entity (Nam)) = E_Operator
1167 and then Box_Present (Inst_Node)
1169 Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
1174 New_S := Analyze_Subprogram_Specification (Spec);
1177 Set_Corresponding_Spec (N, Empty);
1180 -- Renamed entity must be analyzed first, to avoid being hidden by
1181 -- new name (which might be the same in a generic instance).
1185 -- The renaming defines a new overloaded entity, which is analyzed
1186 -- like a subprogram declaration.
1188 New_S := Analyze_Subprogram_Specification (Spec);
1191 if Current_Scope /= Standard_Standard then
1192 Set_Is_Pure (New_S, Is_Pure (Current_Scope));
1195 Rename_Spec := Find_Corresponding_Spec (N);
1197 if Present (Rename_Spec) then
1199 -- Renaming_As_Body. Renaming declaration is the completion of
1200 -- the declaration of Rename_Spec. We will build an actual body
1201 -- for it at the freezing point.
1203 Set_Corresponding_Spec (N, Rename_Spec);
1204 Set_Corresponding_Body (Unit_Declaration_Node (Rename_Spec), New_S);
1206 -- The body is created when the entity is frozen. If the context
1207 -- is generic, freeze_all is not invoked, so we need to indicate
1208 -- that the entity has a completion.
1210 Set_Has_Completion (Rename_Spec, Inside_A_Generic);
1212 if Ada_83 and then Comes_From_Source (N) then
1213 Error_Msg_N ("(Ada 83) renaming cannot serve as a body", N);
1216 Set_Convention (New_S, Convention (Rename_Spec));
1217 Check_Fully_Conformant (New_S, Rename_Spec);
1218 Set_Public_Status (New_S);
1220 -- Indicate that the entity in the declaration functions like
1221 -- the corresponding body, and is not a new entity.
1223 Set_Ekind (New_S, E_Subprogram_Body);
1224 New_S := Rename_Spec;
1227 Generate_Definition (New_S);
1228 New_Overloaded_Entity (New_S);
1229 if Is_Entity_Name (Nam)
1230 and then Is_Intrinsic_Subprogram (Entity (Nam))
1234 Check_Delayed_Subprogram (New_S);
1238 -- There is no need for elaboration checks on the new entity, which
1239 -- may be called before the next freezing point where the body will
1242 Set_Kill_Elaboration_Checks (New_S, True);
1244 if Etype (Nam) = Any_Type then
1245 Set_Has_Completion (New_S);
1248 elsif Nkind (Nam) = N_Selected_Component then
1250 -- Renamed entity is an entry or protected subprogram. For those
1251 -- cases an explicit body is built (at the point of freezing of
1252 -- this entity) that contains a call to the renamed entity.
1254 Analyze_Renamed_Entry (N, New_S, Present (Rename_Spec));
1257 elsif Nkind (Nam) = N_Explicit_Dereference then
1259 -- Renamed entity is designated by access_to_subprogram expression.
1260 -- Must build body to encapsulate call, as in the entry case.
1262 Analyze_Renamed_Dereference (N, New_S, Present (Rename_Spec));
1265 elsif Nkind (Nam) = N_Indexed_Component then
1266 Analyze_Renamed_Family_Member (N, New_S, Present (Rename_Spec));
1269 elsif Nkind (Nam) = N_Character_Literal then
1270 Analyze_Renamed_Character (N, New_S, Present (Rename_Spec));
1273 elsif (not Is_Entity_Name (Nam)
1274 and then Nkind (Nam) /= N_Operator_Symbol)
1275 or else not Is_Overloadable (Entity (Nam))
1277 Error_Msg_N ("expect valid subprogram name in renaming", N);
1282 -- Most common case: subprogram renames subprogram. No body is
1283 -- generated in this case, so we must indicate that the declaration
1284 -- is complete as is.
1286 if No (Rename_Spec) then
1287 Set_Has_Completion (New_S);
1290 -- Find the renamed entity that matches the given specification.
1291 -- Disable Ada_83 because there is no requirement of full conformance
1292 -- between renamed entity and new entity, even though the same circuit
1298 Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual);
1301 if Old_S /= Any_Id then
1304 and then Box_Present (Inst_Node)
1306 -- This is an implicit reference to the default actual
1308 Generate_Reference (Old_S, Nam, Typ => 'i', Force => True);
1310 Generate_Reference (Old_S, Nam);
1313 -- For a renaming-as-body, require subtype conformance,
1314 -- but if the declaration being completed has not been
1315 -- frozen, then inherit the convention of the renamed
1316 -- subprogram prior to checking conformance (unless the
1317 -- renaming has an explicit convention established; the
1318 -- rule stated in the RM doesn't seem to address this ???).
1320 if Present (Rename_Spec) then
1321 Generate_Reference (Rename_Spec, Defining_Entity (Spec), 'b');
1322 Style.Check_Identifier (Defining_Entity (Spec), Rename_Spec);
1324 if not Is_Frozen (Rename_Spec) then
1325 if not Has_Convention_Pragma (Rename_Spec) then
1326 Set_Convention (New_S, Convention (Old_S));
1329 if Ekind (Old_S) /= E_Operator then
1330 Check_Mode_Conformant (New_S, Old_S, Spec);
1333 if Original_Subprogram (Old_S) = Rename_Spec then
1334 Error_Msg_N ("unfrozen subprogram cannot rename itself ", N);
1337 Check_Subtype_Conformant (New_S, Old_S, Spec);
1340 Check_Frozen_Renaming (N, Rename_Spec);
1342 elsif Ekind (Old_S) /= E_Operator then
1343 Check_Mode_Conformant (New_S, Old_S);
1346 and then Error_Posted (New_S)
1348 Error_Msg_NE ("invalid actual subprogram: & #!", N, Old_S);
1352 if No (Rename_Spec) then
1354 -- The parameter profile of the new entity is that of the renamed
1355 -- entity: the subtypes given in the specification are irrelevant.
1357 Inherit_Renamed_Profile (New_S, Old_S);
1359 -- A call to the subprogram is transformed into a call to the
1360 -- renamed entity. This is transitive if the renamed entity is
1361 -- itself a renaming.
1363 if Present (Alias (Old_S)) then
1364 Set_Alias (New_S, Alias (Old_S));
1366 Set_Alias (New_S, Old_S);
1369 -- Note that we do not set Is_Instrinsic_Subprogram if we have
1370 -- a renaming as body, since the entity in this case is not an
1371 -- intrinsic (it calls an intrinsic, but we have a real body
1372 -- for this call, and it is in this body that the required
1373 -- intrinsic processing will take place).
1375 -- Also, if this is a renaming of inequality, the renamed
1376 -- operator is intrinsic, but what matters is the corresponding
1377 -- equality operator, which may be user-defined.
1379 Set_Is_Intrinsic_Subprogram
1381 Is_Intrinsic_Subprogram (Old_S)
1383 (Chars (Old_S) /= Name_Op_Ne
1384 or else Ekind (Old_S) = E_Operator
1386 Is_Intrinsic_Subprogram
1387 (Corresponding_Equality (Old_S))));
1389 if Ekind (Alias (New_S)) = E_Operator then
1390 Set_Has_Delayed_Freeze (New_S, False);
1396 and then (Old_S = New_S
1397 or else (Nkind (Nam) /= N_Expanded_Name
1398 and then Chars (Old_S) = Chars (New_S)))
1400 Error_Msg_N ("subprogram cannot rename itself", N);
1403 Set_Convention (New_S, Convention (Old_S));
1404 Set_Is_Abstract (New_S, Is_Abstract (Old_S));
1405 Check_Library_Unit_Renaming (N, Old_S);
1407 -- Pathological case: procedure renames entry in the scope of
1408 -- its task. Entry is given by simple name, but body must be built
1409 -- for procedure. Of course if called it will deadlock.
1411 if Ekind (Old_S) = E_Entry then
1412 Set_Has_Completion (New_S, False);
1413 Set_Alias (New_S, Empty);
1417 Freeze_Before (N, Old_S);
1418 Set_Has_Delayed_Freeze (New_S, False);
1419 Freeze_Before (N, New_S);
1421 if (Ekind (Old_S) = E_Procedure or else Ekind (Old_S) = E_Function)
1422 and then Is_Abstract (Old_S)
1425 ("abstract subprogram not allowed as generic actual", Nam);
1430 -- A common error is to assume that implicit operators for types
1431 -- are defined in Standard, or in the scope of a subtype. In those
1432 -- cases where the renamed entity is given with an expanded name,
1433 -- it is worth mentioning that operators for the type are not
1434 -- declared in the scope given by the prefix.
1436 if Nkind (Nam) = N_Expanded_Name
1437 and then Nkind (Selector_Name (Nam)) = N_Operator_Symbol
1438 and then Scope (Entity (Nam)) = Standard_Standard
1441 T : constant Entity_Id :=
1442 Base_Type (Etype (First_Formal (New_S)));
1445 Error_Msg_Node_2 := Prefix (Nam);
1447 ("operator for type& is not declared in&", Prefix (Nam), T);
1452 ("no visible subprogram matches the specification for&",
1456 if Present (Candidate_Renaming) then
1462 F1 := First_Formal (Candidate_Renaming);
1463 F2 := First_Formal (New_S);
1465 while Present (F1) and then Present (F2) loop
1470 if Present (F1) and then Present (Default_Value (F1)) then
1471 if Present (Next_Formal (F1)) then
1473 ("\missing specification for &" &
1474 " and other formals with defaults", Spec, F1);
1477 ("\missing specification for &", Spec, F1);
1485 end Analyze_Subprogram_Renaming;
1487 -------------------------
1488 -- Analyze_Use_Package --
1489 -------------------------
1491 -- Resolve the package names in the use clause, and make all the visible
1492 -- entities defined in the package potentially use-visible. If the package
1493 -- is already in use from a previous use clause, its visible entities are
1494 -- already use-visible. In that case, mark the occurrence as a redundant
1495 -- use. If the package is an open scope, i.e. if the use clause occurs
1496 -- within the package itself, ignore it.
1498 procedure Analyze_Use_Package (N : Node_Id) is
1499 Pack_Name : Node_Id;
1502 -- Start of processing for Analyze_Use_Package
1505 Set_Hidden_By_Use_Clause (N, No_Elist);
1507 -- Use clause is not allowed in a spec of a predefined package
1508 -- declaration except that packages whose file name starts a-n
1509 -- are OK (these are children of Ada.Numerics, and such packages
1510 -- are never loaded by Rtsfind).
1512 if Is_Predefined_File_Name (Unit_File_Name (Current_Sem_Unit))
1513 and then Name_Buffer (1 .. 3) /= "a-n"
1515 Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration
1517 Error_Msg_N ("use clause not allowed in predefined spec", N);
1520 -- Chain clause to list of use clauses in current scope.
1522 if Nkind (Parent (N)) /= N_Compilation_Unit then
1523 Chain_Use_Clause (N);
1526 -- Loop through package names to identify referenced packages
1528 Pack_Name := First (Names (N));
1530 while Present (Pack_Name) loop
1531 Analyze (Pack_Name);
1533 if Nkind (Parent (N)) = N_Compilation_Unit
1534 and then Nkind (Pack_Name) = N_Expanded_Name
1537 Pref : Node_Id := Prefix (Pack_Name);
1540 while Nkind (Pref) = N_Expanded_Name loop
1541 Pref := Prefix (Pref);
1544 if Entity (Pref) = Standard_Standard then
1546 ("predefined package Standard cannot appear"
1547 & " in a context clause", Pref);
1555 -- Loop through package names to mark all entities as potentially
1558 Pack_Name := First (Names (N));
1560 while Present (Pack_Name) loop
1562 if Is_Entity_Name (Pack_Name) then
1563 Pack := Entity (Pack_Name);
1565 if Ekind (Pack) /= E_Package
1566 and then Etype (Pack) /= Any_Type
1568 if Ekind (Pack) = E_Generic_Package then
1570 ("a generic package is not allowed in a use clause",
1573 Error_Msg_N ("& is not a usable package", Pack_Name);
1577 if Nkind (Parent (N)) = N_Compilation_Unit then
1578 Check_In_Previous_With_Clause (N, Pack_Name);
1581 if Applicable_Use (Pack_Name) then
1582 Use_One_Package (Pack, N);
1590 end Analyze_Use_Package;
1592 ----------------------
1593 -- Analyze_Use_Type --
1594 ----------------------
1596 procedure Analyze_Use_Type (N : Node_Id) is
1600 Set_Hidden_By_Use_Clause (N, No_Elist);
1602 -- Chain clause to list of use clauses in current scope.
1604 if Nkind (Parent (N)) /= N_Compilation_Unit then
1605 Chain_Use_Clause (N);
1608 Id := First (Subtype_Marks (N));
1610 while Present (Id) loop
1613 if Entity (Id) /= Any_Type then
1616 if Nkind (Parent (N)) = N_Compilation_Unit then
1617 if Nkind (Id) = N_Identifier then
1618 Error_Msg_N ("Type is not directly visible", Id);
1620 elsif Is_Child_Unit (Scope (Entity (Id)))
1621 and then Scope (Entity (Id)) /= System_Aux_Id
1623 Check_In_Previous_With_Clause (N, Prefix (Id));
1630 end Analyze_Use_Type;
1632 --------------------
1633 -- Applicable_Use --
1634 --------------------
1636 function Applicable_Use (Pack_Name : Node_Id) return Boolean is
1637 Pack : constant Entity_Id := Entity (Pack_Name);
1640 if In_Open_Scopes (Pack) then
1643 elsif In_Use (Pack) then
1644 Set_Redundant_Use (Pack_Name, True);
1647 elsif Present (Renamed_Object (Pack))
1648 and then In_Use (Renamed_Object (Pack))
1650 Set_Redundant_Use (Pack_Name, True);
1658 ------------------------
1659 -- Attribute_Renaming --
1660 ------------------------
1662 procedure Attribute_Renaming (N : Node_Id) is
1663 Loc : constant Source_Ptr := Sloc (N);
1664 Nam : constant Node_Id := Name (N);
1665 Spec : constant Node_Id := Specification (N);
1666 New_S : constant Entity_Id := Defining_Unit_Name (Spec);
1667 Aname : constant Name_Id := Attribute_Name (Nam);
1669 Form_Num : Nat := 0;
1670 Expr_List : List_Id := No_List;
1672 Attr_Node : Node_Id;
1673 Body_Node : Node_Id;
1674 Param_Spec : Node_Id;
1677 Generate_Definition (New_S);
1679 -- This procedure is called in the context of subprogram renaming,
1680 -- and thus the attribute must be one that is a subprogram. All of
1681 -- those have at least one formal parameter, with the singular
1682 -- exception of AST_Entry (which is a real oddity, it is odd that
1683 -- this can be renamed at all!)
1685 if not Is_Non_Empty_List (Parameter_Specifications (Spec)) then
1686 if Aname /= Name_AST_Entry then
1688 ("subprogram renaming an attribute must have formals", N);
1693 Param_Spec := First (Parameter_Specifications (Spec));
1695 while Present (Param_Spec) loop
1696 Form_Num := Form_Num + 1;
1698 if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
1699 Find_Type (Parameter_Type (Param_Spec));
1701 -- The profile of the new entity denotes the base type (s) of
1702 -- the types given in the specification. For access parameters
1703 -- there are no subtypes involved.
1705 Rewrite (Parameter_Type (Param_Spec),
1707 (Base_Type (Entity (Parameter_Type (Param_Spec))), Loc));
1710 if No (Expr_List) then
1711 Expr_List := New_List;
1714 Append_To (Expr_List,
1715 Make_Identifier (Loc,
1716 Chars => Chars (Defining_Identifier (Param_Spec))));
1718 -- The expressions in the attribute reference are not freeze
1719 -- points. Neither is the attribute as a whole, see below.
1721 Set_Must_Not_Freeze (Last (Expr_List));
1726 -- Immediate error if too many formals. Other mismatches in numbers
1727 -- of number of types of parameters are detected when we analyze the
1728 -- body of the subprogram that we construct.
1730 if Form_Num > 2 then
1731 Error_Msg_N ("too many formals for attribute", N);
1734 Aname = Name_Compose or else
1735 Aname = Name_Exponent or else
1736 Aname = Name_Leading_Part or else
1737 Aname = Name_Pos or else
1738 Aname = Name_Round or else
1739 Aname = Name_Scaling or else
1742 if Nkind (N) = N_Subprogram_Renaming_Declaration
1743 and then Present (Corresponding_Spec (N))
1744 and then Nkind (Unit_Declaration_Node (Corresponding_Spec (N))) =
1745 N_Formal_Subprogram_Declaration
1748 ("generic actual cannot be attribute involving universal type",
1752 ("attribute involving a universal type cannot be renamed",
1757 -- AST_Entry is an odd case. It doesn't really make much sense to
1758 -- allow it to be renamed, but that's the DEC rule, so we have to
1759 -- do it right. The point is that the AST_Entry call should be made
1760 -- now, and what the function will return is the returned value.
1762 -- Note that there is no Expr_List in this case anyway
1764 if Aname = Name_AST_Entry then
1771 Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
1774 Make_Object_Declaration (Loc,
1775 Defining_Identifier => Ent,
1776 Object_Definition =>
1777 New_Occurrence_Of (RTE (RE_AST_Handler), Loc),
1779 Constant_Present => True);
1781 Set_Assignment_OK (Decl, True);
1782 Insert_Action (N, Decl);
1783 Attr_Node := Make_Identifier (Loc, Chars (Ent));
1786 -- For all other attributes, we rewrite the attribute node to have
1787 -- a list of expressions corresponding to the subprogram formals.
1788 -- A renaming declaration is not a freeze point, and the analysis of
1789 -- the attribute reference should not freeze the type of the prefix.
1793 Make_Attribute_Reference (Loc,
1794 Prefix => Prefix (Nam),
1795 Attribute_Name => Aname,
1796 Expressions => Expr_List);
1798 Set_Must_Not_Freeze (Attr_Node);
1799 Set_Must_Not_Freeze (Prefix (Nam));
1802 -- Case of renaming a function
1804 if Nkind (Spec) = N_Function_Specification then
1806 if Is_Procedure_Attribute_Name (Aname) then
1807 Error_Msg_N ("attribute can only be renamed as procedure", Nam);
1811 Find_Type (Subtype_Mark (Spec));
1812 Rewrite (Subtype_Mark (Spec),
1813 New_Reference_To (Base_Type (Entity (Subtype_Mark (Spec))), Loc));
1816 Make_Subprogram_Body (Loc,
1817 Specification => Spec,
1818 Declarations => New_List,
1819 Handled_Statement_Sequence =>
1820 Make_Handled_Sequence_Of_Statements (Loc,
1821 Statements => New_List (
1822 Make_Return_Statement (Loc,
1823 Expression => Attr_Node))));
1825 -- Case of renaming a procedure
1828 if not Is_Procedure_Attribute_Name (Aname) then
1829 Error_Msg_N ("attribute can only be renamed as function", Nam);
1834 Make_Subprogram_Body (Loc,
1835 Specification => Spec,
1836 Declarations => New_List,
1837 Handled_Statement_Sequence =>
1838 Make_Handled_Sequence_Of_Statements (Loc,
1839 Statements => New_List (Attr_Node)));
1842 Rewrite (N, Body_Node);
1845 Set_Etype (New_S, Base_Type (Etype (New_S)));
1847 -- We suppress elaboration warnings for the resulting entity, since
1848 -- clearly they are not needed, and more particularly, in the case
1849 -- of a generic formal subprogram, the resulting entity can appear
1850 -- after the instantiation itself, and thus look like a bogus case
1851 -- of access before elaboration.
1853 Set_Suppress_Elaboration_Warnings (New_S);
1855 end Attribute_Renaming;
1857 ----------------------
1858 -- Chain_Use_Clause --
1859 ----------------------
1861 procedure Chain_Use_Clause (N : Node_Id) is
1863 Set_Next_Use_Clause (N,
1864 Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause);
1865 Scope_Stack.Table (Scope_Stack.Last).First_Use_Clause := N;
1866 end Chain_Use_Clause;
1868 ----------------------------
1869 -- Check_Frozen_Renaming --
1870 ----------------------------
1872 procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id) is
1878 and then not Has_Completion (Subp)
1882 (Parent (Declaration_Node (Subp)), Defining_Entity (N));
1884 if Is_Entity_Name (Name (N)) then
1885 Old_S := Entity (Name (N));
1887 if not Is_Frozen (Old_S)
1888 and then Operating_Mode /= Check_Semantics
1890 Append_Freeze_Action (Old_S, B_Node);
1892 Insert_After (N, B_Node);
1896 if Is_Intrinsic_Subprogram (Old_S)
1897 and then not In_Instance
1900 ("subprogram used in renaming_as_body cannot be intrinsic",
1905 Insert_After (N, B_Node);
1909 end Check_Frozen_Renaming;
1911 -----------------------------------
1912 -- Check_In_Previous_With_Clause --
1913 -----------------------------------
1915 procedure Check_In_Previous_With_Clause
1919 Pack : constant Entity_Id := Entity (Original_Node (Nam));
1924 Item := First (Context_Items (Parent (N)));
1926 while Present (Item)
1929 if Nkind (Item) = N_With_Clause
1930 and then Entity (Name (Item)) = Pack
1934 -- Find root library unit in with_clause.
1936 while Nkind (Par) = N_Expanded_Name loop
1937 Par := Prefix (Par);
1940 if Is_Child_Unit (Entity (Original_Node (Par))) then
1942 ("& is not directly visible", Par, Entity (Par));
1951 -- On exit, package is not mentioned in a previous with_clause.
1952 -- Check if its prefix is.
1954 if Nkind (Nam) = N_Expanded_Name then
1955 Check_In_Previous_With_Clause (N, Prefix (Nam));
1957 elsif Pack /= Any_Id then
1958 Error_Msg_NE ("& is not visible", Nam, Pack);
1960 end Check_In_Previous_With_Clause;
1962 ---------------------------------
1963 -- Check_Library_Unit_Renaming --
1964 ---------------------------------
1966 procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id) is
1970 if Nkind (Parent (N)) /= N_Compilation_Unit then
1973 elsif Scope (Old_E) /= Standard_Standard
1974 and then not Is_Child_Unit (Old_E)
1976 Error_Msg_N ("renamed unit must be a library unit", Name (N));
1978 elsif Present (Parent_Spec (N))
1979 and then Nkind (Unit (Parent_Spec (N))) = N_Generic_Package_Declaration
1980 and then not Is_Child_Unit (Old_E)
1983 ("renamed unit must be a child unit of generic parent", Name (N));
1985 elsif Nkind (N) in N_Generic_Renaming_Declaration
1986 and then Nkind (Name (N)) = N_Expanded_Name
1987 and then Is_Generic_Instance (Entity (Prefix (Name (N))))
1988 and then Is_Generic_Unit (Old_E)
1991 ("renamed generic unit must be a library unit", Name (N));
1993 elsif Ekind (Old_E) = E_Package
1994 or else Ekind (Old_E) = E_Generic_Package
1996 -- Inherit categorization flags
1998 New_E := Defining_Entity (N);
1999 Set_Is_Pure (New_E, Is_Pure (Old_E));
2000 Set_Is_Preelaborated (New_E, Is_Preelaborated (Old_E));
2001 Set_Is_Remote_Call_Interface (New_E,
2002 Is_Remote_Call_Interface (Old_E));
2003 Set_Is_Remote_Types (New_E, Is_Remote_Types (Old_E));
2004 Set_Is_Shared_Passive (New_E, Is_Shared_Passive (Old_E));
2006 end Check_Library_Unit_Renaming;
2012 procedure End_Scope is
2018 Id := First_Entity (Current_Scope);
2020 while Present (Id) loop
2021 -- An entity in the current scope is not necessarily the first one
2022 -- on its homonym chain. Find its predecessor if any,
2023 -- If it is an internal entity, it will not be in the visibility
2024 -- chain altogether, and there is nothing to unchain.
2026 if Id /= Current_Entity (Id) then
2027 Prev := Current_Entity (Id);
2028 while Present (Prev)
2029 and then Present (Homonym (Prev))
2030 and then Homonym (Prev) /= Id
2032 Prev := Homonym (Prev);
2035 -- Skip to end of loop if Id is not in the visibility chain
2037 if No (Prev) or else Homonym (Prev) /= Id then
2045 Outer := Homonym (Id);
2046 Set_Is_Immediately_Visible (Id, False);
2048 while Present (Outer) and then Scope (Outer) = Current_Scope loop
2049 Outer := Homonym (Outer);
2052 -- Reset homonym link of other entities, but do not modify link
2053 -- between entities in current scope, so that the back-end can have
2054 -- a proper count of local overloadings.
2057 Set_Name_Entity_Id (Chars (Id), Outer);
2059 elsif Scope (Prev) /= Scope (Id) then
2060 Set_Homonym (Prev, Outer);
2067 -- If the scope generated freeze actions, place them before the
2068 -- current declaration and analyze them. Type declarations and
2069 -- the bodies of initialization procedures can generate such nodes.
2070 -- We follow the parent chain until we reach a list node, which is
2071 -- the enclosing list of declarations. If the list appears within
2072 -- a protected definition, move freeze nodes outside the protected
2076 (Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions)
2080 L : constant List_Id := Scope_Stack.Table
2081 (Scope_Stack.Last).Pending_Freeze_Actions;
2084 if Is_Itype (Current_Scope) then
2085 Decl := Associated_Node_For_Itype (Current_Scope);
2087 Decl := Parent (Current_Scope);
2092 while not (Is_List_Member (Decl))
2093 or else Nkind (Parent (Decl)) = N_Protected_Definition
2094 or else Nkind (Parent (Decl)) = N_Task_Definition
2096 Decl := Parent (Decl);
2099 Insert_List_Before_And_Analyze (Decl, L);
2108 ---------------------
2109 -- End_Use_Clauses --
2110 ---------------------
2112 procedure End_Use_Clauses (Clause : Node_Id) is
2116 -- Remove Use_Type clauses first, because they affect the
2117 -- visibility of operators in subsequent used packages.
2120 while Present (U) loop
2121 if Nkind (U) = N_Use_Type_Clause then
2125 Next_Use_Clause (U);
2129 while Present (U) loop
2130 if Nkind (U) = N_Use_Package_Clause then
2131 End_Use_Package (U);
2134 Next_Use_Clause (U);
2136 end End_Use_Clauses;
2138 ---------------------
2139 -- End_Use_Package --
2140 ---------------------
2142 procedure End_Use_Package (N : Node_Id) is
2143 Pack_Name : Node_Id;
2148 function Is_Primitive_Operator
2152 -- Check whether Op is a primitive operator of a use-visible type
2154 ---------------------------
2155 -- Is_Primitive_Operator --
2156 ---------------------------
2158 function Is_Primitive_Operator
2163 T : constant Entity_Id := Etype (F);
2167 and then Scope (T) = Scope (Op);
2168 end Is_Primitive_Operator;
2170 -- Start of processing for End_Use_Package
2173 Pack_Name := First (Names (N));
2175 while Present (Pack_Name) loop
2176 Pack := Entity (Pack_Name);
2178 if Ekind (Pack) = E_Package then
2180 if In_Open_Scopes (Pack) then
2183 elsif not Redundant_Use (Pack_Name) then
2184 Set_In_Use (Pack, False);
2185 Id := First_Entity (Pack);
2187 while Present (Id) loop
2189 -- Preserve use-visibility of operators that are primitive
2190 -- operators of a type that is use_visible through an active
2193 if Nkind (Id) = N_Defining_Operator_Symbol
2195 (Is_Primitive_Operator (Id, First_Formal (Id))
2197 (Present (Next_Formal (First_Formal (Id)))
2199 Is_Primitive_Operator
2200 (Id, Next_Formal (First_Formal (Id)))))
2205 Set_Is_Potentially_Use_Visible (Id, False);
2208 if Is_Private_Type (Id)
2209 and then Present (Full_View (Id))
2211 Set_Is_Potentially_Use_Visible (Full_View (Id), False);
2217 if Present (Renamed_Object (Pack)) then
2218 Set_In_Use (Renamed_Object (Pack), False);
2221 if Chars (Pack) = Name_System
2222 and then Scope (Pack) = Standard_Standard
2223 and then Present_System_Aux
2225 Id := First_Entity (System_Aux_Id);
2227 while Present (Id) loop
2228 Set_Is_Potentially_Use_Visible (Id, False);
2230 if Is_Private_Type (Id)
2231 and then Present (Full_View (Id))
2233 Set_Is_Potentially_Use_Visible (Full_View (Id), False);
2239 Set_In_Use (System_Aux_Id, False);
2243 Set_Redundant_Use (Pack_Name, False);
2251 if Present (Hidden_By_Use_Clause (N)) then
2252 Elmt := First_Elmt (Hidden_By_Use_Clause (N));
2254 while Present (Elmt) loop
2255 Set_Is_Immediately_Visible (Node (Elmt));
2259 Set_Hidden_By_Use_Clause (N, No_Elist);
2261 end End_Use_Package;
2267 procedure End_Use_Type (N : Node_Id) is
2274 Id := First (Subtype_Marks (N));
2276 while Present (Id) loop
2278 -- A call to rtsfind may occur while analyzing a use_type clause,
2279 -- in which case the type marks are not resolved yet, and there is
2280 -- nothing to remove.
2282 if not Is_Entity_Name (Id)
2283 or else No (Entity (Id))
2290 if T = Any_Type then
2293 -- Note that the use_Type clause may mention a subtype of the
2294 -- type whose primitive operations have been made visible. Here
2295 -- as elsewhere, it is the base type that matters for visibility.
2297 elsif In_Open_Scopes (Scope (Base_Type (T))) then
2300 elsif not Redundant_Use (Id) then
2301 Set_In_Use (T, False);
2302 Set_In_Use (Base_Type (T), False);
2303 Op_List := Collect_Primitive_Operations (T);
2304 Elmt := First_Elmt (Op_List);
2306 while Present (Elmt) loop
2308 if Nkind (Node (Elmt)) = N_Defining_Operator_Symbol then
2309 Set_Is_Potentially_Use_Visible (Node (Elmt), False);
2321 ----------------------
2322 -- Find_Direct_Name --
2323 ----------------------
2325 procedure Find_Direct_Name (N : Node_Id) is
2330 Inst : Entity_Id := Empty;
2331 -- Enclosing instance, if any.
2333 Homonyms : Entity_Id;
2334 -- Saves start of homonym chain
2336 Nvis_Entity : Boolean;
2337 -- Set True to indicate that at there is at least one entity on the
2338 -- homonym chain which, while not visible, is visible enough from the
2339 -- user point of view to warrant an error message of "not visible"
2340 -- rather than undefined.
2342 function From_Actual_Package (E : Entity_Id) return Boolean;
2343 -- Returns true if the entity is declared in a package that is
2344 -- an actual for a formal package of the current instance. Such an
2345 -- entity requires special handling because it may be use-visible
2346 -- but hides directly visible entities defined outside the instance.
2348 function Known_But_Invisible (E : Entity_Id) return Boolean;
2349 -- This function determines whether the entity E (which is not
2350 -- visible) can reasonably be considered to be known to the writer
2351 -- of the reference. This is a heuristic test, used only for the
2352 -- purposes of figuring out whether we prefer to complain that an
2353 -- entity is undefined or invisible (and identify the declaration
2354 -- of the invisible entity in the latter case). The point here is
2355 -- that we don't want to complain that something is invisible and
2356 -- then point to something entirely mysterious to the writer.
2358 procedure Nvis_Messages;
2359 -- Called if there are no visible entries for N, but there is at least
2360 -- one non-directly visible, or hidden declaration. This procedure
2361 -- outputs an appropriate set of error messages.
2363 procedure Undefined (Nvis : Boolean);
2364 -- This function is called if the current node has no corresponding
2365 -- visible entity or entities. The value set in Msg indicates whether
2366 -- an error message was generated (multiple error messages for the
2367 -- same variable are generally suppressed, see body for details).
2368 -- Msg is True if an error message was generated, False if not. This
2369 -- value is used by the caller to determine whether or not to output
2370 -- additional messages where appropriate. The parameter is set False
2371 -- to get the message "X is undefined", and True to get the message
2372 -- "X is not visible".
2374 -------------------------
2375 -- From_Actual_Package --
2376 -------------------------
2378 function From_Actual_Package (E : Entity_Id) return Boolean is
2379 Scop : constant Entity_Id := Scope (E);
2383 if not In_Instance then
2386 Inst := Current_Scope;
2388 while Present (Inst)
2389 and then Ekind (Inst) /= E_Package
2390 and then not Is_Generic_Instance (Inst)
2392 Inst := Scope (Inst);
2399 Act := First_Entity (Inst);
2401 while Present (Act) loop
2402 if Ekind (Act) = E_Package then
2404 -- Check for end of actuals list
2406 if Renamed_Object (Act) = Inst then
2409 elsif Present (Associated_Formal_Package (Act))
2410 and then Renamed_Object (Act) = Scop
2412 -- Entity comes from (instance of) formal package
2427 end From_Actual_Package;
2429 -------------------------
2430 -- Known_But_Invisible --
2431 -------------------------
2433 function Known_But_Invisible (E : Entity_Id) return Boolean is
2434 Fname : File_Name_Type;
2437 -- Entities in Standard are always considered to be known
2439 if Sloc (E) <= Standard_Location then
2442 -- An entity that does not come from source is always considered
2443 -- to be unknown, since it is an artifact of code expansion.
2445 elsif not Comes_From_Source (E) then
2448 -- In gnat internal mode, we consider all entities known
2450 elsif GNAT_Mode then
2454 -- Here we have an entity that is not from package Standard, and
2455 -- which comes from Source. See if it comes from an internal file.
2457 Fname := Unit_File_Name (Get_Source_Unit (E));
2459 -- Case of from internal file
2461 if Is_Internal_File_Name (Fname) then
2463 -- Private part entities in internal files are never considered
2464 -- to be known to the writer of normal application code.
2466 if Is_Hidden (E) then
2470 -- Entities from System packages other than System and
2471 -- System.Storage_Elements are not considered to be known.
2472 -- System.Auxxxx files are also considered known to the user.
2474 -- Should refine this at some point to generally distinguish
2475 -- between known and unknown internal files ???
2477 Get_Name_String (Fname);
2482 Name_Buffer (1 .. 2) /= "s-"
2484 Name_Buffer (3 .. 8) = "stoele"
2486 Name_Buffer (3 .. 5) = "aux";
2488 -- If not an internal file, then entity is definitely known,
2489 -- even if it is in a private part (the message generated will
2490 -- note that it is in a private part)
2495 end Known_But_Invisible;
2501 procedure Nvis_Messages is
2503 Hidden : Boolean := False;
2506 Undefined (Nvis => True);
2510 -- First loop does hidden declarations
2513 while Present (Ent) loop
2514 if Is_Potentially_Use_Visible (Ent) then
2517 Error_Msg_N ("multiple use clauses cause hiding!", N);
2521 Error_Msg_Sloc := Sloc (Ent);
2522 Error_Msg_N ("hidden declaration#!", N);
2525 Ent := Homonym (Ent);
2528 -- If we found hidden declarations, then that's enough, don't
2529 -- bother looking for non-visible declarations as well.
2535 -- Second loop does non-directly visible declarations
2538 while Present (Ent) loop
2539 if not Is_Potentially_Use_Visible (Ent) then
2541 -- Do not bother the user with unknown entities
2543 if not Known_But_Invisible (Ent) then
2547 Error_Msg_Sloc := Sloc (Ent);
2549 -- Output message noting that there is a non-visible
2550 -- declaration, distinguishing the private part case.
2552 if Is_Hidden (Ent) then
2553 Error_Msg_N ("non-visible (private) declaration#!", N);
2555 Error_Msg_N ("non-visible declaration#!", N);
2557 if Is_Compilation_Unit (Ent)
2559 Nkind (Parent (Parent (N))) = N_Use_Package_Clause
2562 ("\possibly missing with_clause for&", N, Ent);
2566 -- Set entity and its containing package as referenced. We
2567 -- can't be sure of this, but this seems a better choice
2568 -- to avoid unused entity messages.
2570 if Comes_From_Source (Ent) then
2571 Set_Referenced (Ent);
2572 Set_Referenced (Cunit_Entity (Get_Source_Unit (Ent)));
2577 Ent := Homonym (Ent);
2587 procedure Undefined (Nvis : Boolean) is
2588 Emsg : Error_Msg_Id;
2591 -- We should never find an undefined internal name. If we do, then
2592 -- see if we have previous errors. If so, ignore on the grounds that
2593 -- it is probably a cascaded message (e.g. a block label from a badly
2594 -- formed block). If no previous errors, then we have a real internal
2595 -- error of some kind so raise an exception.
2597 if Is_Internal_Name (Chars (N)) then
2598 if Total_Errors_Detected /= 0 then
2601 raise Program_Error;
2605 -- A very specialized error check, if the undefined variable is
2606 -- a case tag, and the case type is an enumeration type, check
2607 -- for a possible misspelling, and if so, modify the identifier
2609 -- Named aggregate should also be handled similarly ???
2611 if Nkind (N) = N_Identifier
2612 and then Nkind (Parent (N)) = N_Case_Statement_Alternative
2614 Get_Name_String (Chars (N));
2617 Case_Str : constant String := Name_Buffer (1 .. Name_Len);
2618 Case_Stm : constant Node_Id := Parent (Parent (N));
2619 Case_Typ : constant Entity_Id := Etype (Expression (Case_Stm));
2624 if Is_Enumeration_Type (Case_Typ)
2625 and then Case_Typ /= Standard_Character
2626 and then Case_Typ /= Standard_Wide_Character
2628 Lit := First_Literal (Case_Typ);
2629 Get_Name_String (Chars (Lit));
2631 if Chars (Lit) /= Chars (N)
2632 and then Is_Bad_Spelling_Of
2633 (Case_Str, Name_Buffer (1 .. Name_Len))
2635 Error_Msg_Node_2 := Lit;
2637 ("& is undefined, assume misspelling of &", N);
2638 Rewrite (N, New_Occurrence_Of (Lit, Sloc (N)));
2642 Lit := Next_Literal (Lit);
2647 -- Normal processing
2649 Set_Entity (N, Any_Id);
2650 Set_Etype (N, Any_Type);
2652 -- We use the table Urefs to keep track of entities for which we
2653 -- have issued errors for undefined references. Multiple errors
2654 -- for a single name are normally suppressed, however we modify
2655 -- the error message to alert the programmer to this effect.
2657 for J in Urefs.First .. Urefs.Last loop
2658 if Chars (N) = Chars (Urefs.Table (J).Node) then
2659 if Urefs.Table (J).Err /= No_Error_Msg
2660 and then Sloc (N) /= Urefs.Table (J).Loc
2662 Error_Msg_Node_1 := Urefs.Table (J).Node;
2664 if Urefs.Table (J).Nvis then
2665 Change_Error_Text (Urefs.Table (J).Err,
2666 "& is not visible (more references follow)");
2668 Change_Error_Text (Urefs.Table (J).Err,
2669 "& is undefined (more references follow)");
2672 Urefs.Table (J).Err := No_Error_Msg;
2675 -- Although we will set Msg False, and thus suppress the
2676 -- message, we also set Error_Posted True, to avoid any
2677 -- cascaded messages resulting from the undefined reference.
2680 Set_Error_Posted (N, True);
2685 -- If entry not found, this is first undefined occurrence
2688 Error_Msg_N ("& is not visible!", N);
2692 Error_Msg_N ("& is undefined!", N);
2695 -- A very bizarre special check, if the undefined identifier
2696 -- is put or put_line, then add a special error message (since
2697 -- this is a very common error for beginners to make).
2699 if Chars (N) = Name_Put or else Chars (N) = Name_Put_Line then
2700 Error_Msg_N ("\possible missing with of 'Text_'I'O!", N);
2703 -- Now check for possible misspellings
2705 Get_Name_String (Chars (N));
2709 Ematch : Entity_Id := Empty;
2711 Last_Name_Id : constant Name_Id :=
2712 Name_Id (Nat (First_Name_Id) +
2713 Name_Entries_Count - 1);
2715 S : constant String (1 .. Name_Len) :=
2716 Name_Buffer (1 .. Name_Len);
2719 for N in First_Name_Id .. Last_Name_Id loop
2720 E := Get_Name_Entity_Id (N);
2723 and then (Is_Immediately_Visible (E)
2725 Is_Potentially_Use_Visible (E))
2727 Get_Name_String (N);
2729 if Is_Bad_Spelling_Of
2730 (Name_Buffer (1 .. Name_Len), S)
2738 if Present (Ematch) then
2739 Error_Msg_NE ("\possible misspelling of&", N, Ematch);
2744 -- Make entry in undefined references table unless the full
2745 -- errors switch is set, in which case by refraining from
2746 -- generating the table entry, we guarantee that we get an
2747 -- error message for every undefined reference.
2749 if not All_Errors_Mode then
2750 Urefs.Increment_Last;
2751 Urefs.Table (Urefs.Last).Node := N;
2752 Urefs.Table (Urefs.Last).Err := Emsg;
2753 Urefs.Table (Urefs.Last).Nvis := Nvis;
2754 Urefs.Table (Urefs.Last).Loc := Sloc (N);
2760 -- Start of processing for Find_Direct_Name
2763 -- If the entity pointer is already set, this is an internal node, or
2764 -- a node that is analyzed more than once, after a tree modification.
2765 -- In such a case there is no resolution to perform, just set the type.
2767 if Present (Entity (N)) then
2768 if Is_Type (Entity (N)) then
2769 Set_Etype (N, Entity (N));
2773 Entyp : constant Entity_Id := Etype (Entity (N));
2776 -- One special case here. If the Etype field is already set,
2777 -- and references the packed array type corresponding to the
2778 -- etype of the referenced entity, then leave it alone. This
2779 -- happens for trees generated from Exp_Pakd, where expressions
2780 -- can be deliberately "mis-typed" to the packed array type.
2782 if Is_Array_Type (Entyp)
2783 and then Is_Packed (Entyp)
2784 and then Present (Etype (N))
2785 and then Etype (N) = Packed_Array_Type (Entyp)
2789 -- If not that special case, then just reset the Etype
2792 Set_Etype (N, Etype (Entity (N)));
2800 -- Here if Entity pointer was not set, we need full visibility analysis
2801 -- First we generate debugging output if the debug E flag is set.
2803 if Debug_Flag_E then
2804 Write_Str ("Looking for ");
2805 Write_Name (Chars (N));
2809 Homonyms := Current_Entity (N);
2810 Nvis_Entity := False;
2813 while Present (E) loop
2815 -- If entity is immediately visible or potentially use
2816 -- visible, then process the entity and we are done.
2818 if Is_Immediately_Visible (E) then
2819 goto Immediately_Visible_Entity;
2821 elsif Is_Potentially_Use_Visible (E) then
2822 goto Potentially_Use_Visible_Entity;
2824 -- Note if a known but invisible entity encountered
2826 elsif Known_But_Invisible (E) then
2827 Nvis_Entity := True;
2830 -- Move to next entity in chain and continue search
2835 -- If no entries on homonym chain that were potentially visible,
2836 -- and no entities reasonably considered as non-visible, then
2837 -- we have a plain undefined reference, with no additional
2838 -- explanation required!
2840 if not Nvis_Entity then
2841 Undefined (Nvis => False);
2843 -- Otherwise there is at least one entry on the homonym chain that
2844 -- is reasonably considered as being known and non-visible.
2852 -- Processing for a potentially use visible entry found. We must search
2853 -- the rest of the homonym chain for two reasons. First, if there is a
2854 -- directly visible entry, then none of the potentially use-visible
2855 -- entities are directly visible (RM 8.4(10)). Second, we need to check
2856 -- for the case of multiple potentially use-visible entries hiding one
2857 -- another and as a result being non-directly visible (RM 8.4(11)).
2859 <<Potentially_Use_Visible_Entity>> declare
2860 Only_One_Visible : Boolean := True;
2861 All_Overloadable : Boolean := Is_Overloadable (E);
2866 while Present (E2) loop
2867 if Is_Immediately_Visible (E2) then
2869 -- If the use-visible entity comes from the actual for a
2870 -- formal package, it hides a directly visible entity from
2871 -- outside the instance.
2873 if From_Actual_Package (E)
2874 and then Scope_Depth (E2) < Scope_Depth (Inst)
2879 goto Immediately_Visible_Entity;
2882 elsif Is_Potentially_Use_Visible (E2) then
2883 Only_One_Visible := False;
2884 All_Overloadable := All_Overloadable and Is_Overloadable (E2);
2890 -- On falling through this loop, we have checked that there are no
2891 -- immediately visible entities. Only_One_Visible is set if exactly
2892 -- one potentially use visible entity exists. All_Overloadable is
2893 -- set if all the potentially use visible entities are overloadable.
2894 -- The condition for legality is that either there is one potentially
2895 -- use visible entity, or if there is more than one, then all of them
2896 -- are overloadable.
2898 if Only_One_Visible or All_Overloadable then
2901 -- If there is more than one potentially use-visible entity and at
2902 -- least one of them non-overloadable, we have an error (RM 8.4(11).
2903 -- Note that E points to the first such entity on the homonym list.
2904 -- Special case: if one of the entities is declared in an actual
2905 -- package, it was visible in the generic, and takes precedence over
2906 -- other entities that are potentially use-visible. Same if it is
2907 -- declared in a local instantiation of the current instance.
2911 Inst := Current_Scope;
2913 -- Find current instance.
2915 while Present (Inst)
2916 and then Inst /= Standard_Standard
2918 if Is_Generic_Instance (Inst) then
2922 Inst := Scope (Inst);
2927 while Present (E2) loop
2928 if From_Actual_Package (E2)
2930 (Is_Generic_Instance (Scope (E2))
2931 and then Scope_Depth (Scope (E2)) > Scope_Depth (Inst))
2950 -- Come here with E set to the first immediately visible entity on
2951 -- the homonym chain. This is the one we want unless there is another
2952 -- immediately visible entity further on in the chain for a more
2953 -- inner scope (RM 8.3(8)).
2955 <<Immediately_Visible_Entity>> declare
2960 -- Find scope level of initial entity. When compiling through
2961 -- Rtsfind, the previous context is not completely invisible, and
2962 -- an outer entity may appear on the chain, whose scope is below
2963 -- the entry for Standard that delimits the current scope stack.
2964 -- Indicate that the level for this spurious entry is outside of
2965 -- the current scope stack.
2967 Level := Scope_Stack.Last;
2969 Scop := Scope_Stack.Table (Level).Entity;
2970 exit when Scop = Scope (E);
2972 exit when Scop = Standard_Standard;
2975 -- Now search remainder of homonym chain for more inner entry
2976 -- If the entity is Standard itself, it has no scope, and we
2977 -- compare it with the stack entry directly.
2980 while Present (E2) loop
2981 if Is_Immediately_Visible (E2) then
2982 for J in Level + 1 .. Scope_Stack.Last loop
2983 if Scope_Stack.Table (J).Entity = Scope (E2)
2984 or else Scope_Stack.Table (J).Entity = E2
2996 -- At the end of that loop, E is the innermost immediately
2997 -- visible entity, so we are all set.
3000 -- Come here with entity found, and stored in E
3004 if Comes_From_Source (N)
3005 and then Is_Remote_Access_To_Subprogram_Type (E)
3006 and then Expander_Active
3009 New_Occurrence_Of (Equivalent_Type (E), Sloc (N)));
3014 -- Why no Style_Check here???
3019 Set_Etype (N, Get_Full_View (Etype (E)));
3022 if Debug_Flag_E then
3023 Write_Str (" found ");
3024 Write_Entity_Info (E, " ");
3027 -- If the Ekind of the entity is Void, it means that all homonyms
3028 -- are hidden from all visibility (RM 8.3(5,14-20)). However, this
3029 -- test is skipped if the current scope is a record and the name is
3030 -- a pragma argument expression (case of Atomic and Volatile pragmas
3031 -- and possibly other similar pragmas added later, which are allowed
3032 -- to reference components in the current record).
3034 if Ekind (E) = E_Void
3036 (not Is_Record_Type (Current_Scope)
3037 or else Nkind (Parent (N)) /= N_Pragma_Argument_Association)
3039 Premature_Usage (N);
3041 -- If the entity is overloadable, collect all interpretations
3042 -- of the name for subsequent overload resolution. We optimize
3043 -- a bit here to do this only if we have an overloadable entity
3044 -- that is not on its own on the homonym chain.
3046 elsif Is_Overloadable (E)
3047 and then (Present (Homonym (E)) or else Current_Entity (N) /= E)
3049 Collect_Interps (N);
3051 -- If no homonyms were visible, the entity is unambiguous.
3053 if not Is_Overloaded (N) then
3054 Generate_Reference (E, N);
3057 -- Case of non-overloadable entity, set the entity providing that
3058 -- we do not have the case of a discriminant reference within a
3059 -- default expression. Such references are replaced with the
3060 -- corresponding discriminal, which is the formal corresponding to
3061 -- to the discriminant in the initialization procedure.
3064 -- Entity is unambiguous, indicate that it is referenced here
3065 -- One slightly odd case is that we do not want to set the
3066 -- Referenced flag if the entity is a label, and the identifier
3067 -- is the label in the source, since this is not a reference
3068 -- from the point of view of the user
3070 if Nkind (Parent (N)) = N_Label then
3072 R : constant Boolean := Referenced (E);
3075 Generate_Reference (E, N);
3076 Set_Referenced (E, R);
3079 -- Normal case, not a label. Generate reference.
3082 Generate_Reference (E, N);
3085 -- Set Entity, with style check if need be. If this is a
3086 -- discriminant reference, it must be replaced by the
3087 -- corresponding discriminal, that is to say the parameter
3088 -- of the initialization procedure that corresponds to the
3089 -- discriminant. If this replacement is being performed, there
3090 -- is no style check to perform.
3092 -- This replacement must not be done if we are currently
3093 -- processing a generic spec or body, because the discriminal
3094 -- has not been not generated in this case.
3096 if not In_Default_Expression
3097 or else Ekind (E) /= E_Discriminant
3098 or else Inside_A_Generic
3100 Set_Entity_With_Style_Check (N, E);
3102 -- The replacement is not done either for a task discriminant that
3103 -- appears in a default expression of an entry parameter. See
3104 -- Expand_Discriminant in exp_ch2 for details on their handling.
3106 elsif Is_Concurrent_Type (Scope (E)) then
3108 P : Node_Id := Parent (N);
3112 and then Nkind (P) /= N_Parameter_Specification
3113 and then Nkind (P) /= N_Component_Declaration
3119 and then Nkind (P) = N_Parameter_Specification
3123 Set_Entity (N, Discriminal (E));
3127 -- Otherwise, this is a discriminant in a context in which
3128 -- it is a reference to the corresponding parameter of the
3129 -- init proc for the enclosing type.
3132 Set_Entity (N, Discriminal (E));
3136 end Find_Direct_Name;
3138 ------------------------
3139 -- Find_Expanded_Name --
3140 ------------------------
3142 -- This routine searches the homonym chain of the entity until it finds
3143 -- an entity declared in the scope denoted by the prefix. If the entity
3144 -- is private, it may nevertheless be immediately visible, if we are in
3145 -- the scope of its declaration.
3147 procedure Find_Expanded_Name (N : Node_Id) is
3148 Selector : constant Node_Id := Selector_Name (N);
3149 Candidate : Entity_Id := Empty;
3155 P_Name := Entity (Prefix (N));
3158 -- If the prefix is a renamed package, look for the entity
3159 -- in the original package.
3161 if Ekind (P_Name) = E_Package
3162 and then Present (Renamed_Object (P_Name))
3164 P_Name := Renamed_Object (P_Name);
3166 -- Rewrite node with entity field pointing to renamed object
3168 Rewrite (Prefix (N), New_Copy (Prefix (N)));
3169 Set_Entity (Prefix (N), P_Name);
3171 -- If the prefix is an object of a concurrent type, look for
3172 -- the entity in the associated task or protected type.
3174 elsif Is_Concurrent_Type (Etype (P_Name)) then
3175 P_Name := Etype (P_Name);
3178 Id := Current_Entity (Selector);
3180 while Present (Id) loop
3182 if Scope (Id) = P_Name then
3185 if Is_Child_Unit (Id) then
3186 exit when Is_Visible_Child_Unit (Id)
3187 or else Is_Immediately_Visible (Id);
3190 exit when not Is_Hidden (Id)
3191 or else Is_Immediately_Visible (Id);
3199 and then (Ekind (P_Name) = E_Procedure
3201 Ekind (P_Name) = E_Function)
3202 and then Is_Generic_Instance (P_Name)
3204 -- Expanded name denotes entity in (instance of) generic subprogram.
3205 -- The entity may be in the subprogram instance, or may denote one of
3206 -- the formals, which is declared in the enclosing wrapper package.
3208 P_Name := Scope (P_Name);
3209 Id := Current_Entity (Selector);
3211 while Present (Id) loop
3212 exit when Scope (Id) = P_Name;
3217 if No (Id) or else Chars (Id) /= Chars (Selector) then
3219 Set_Etype (N, Any_Type);
3221 -- If we are looking for an entity defined in System, try to
3222 -- find it in the child package that may have been provided as
3223 -- an extension to System. The Extend_System pragma will have
3224 -- supplied the name of the extension, which may have to be loaded.
3226 if Chars (P_Name) = Name_System
3227 and then Scope (P_Name) = Standard_Standard
3228 and then Present (System_Extend_Unit)
3229 and then Present_System_Aux (N)
3231 Set_Entity (Prefix (N), System_Aux_Id);
3232 Find_Expanded_Name (N);
3235 elsif Nkind (Selector) = N_Operator_Symbol
3236 and then Has_Implicit_Operator (N)
3238 -- There is an implicit instance of the predefined operator in
3239 -- the given scope. The operator entity is defined in Standard.
3240 -- Has_Implicit_Operator makes the node into an Expanded_Name.
3244 elsif Nkind (Selector) = N_Character_Literal
3245 and then Has_Implicit_Character_Literal (N)
3247 -- If there is no literal defined in the scope denoted by the
3248 -- prefix, the literal may belong to (a type derived from)
3249 -- Standard_Character, for which we have no explicit literals.
3254 -- If the prefix is a single concurrent object, use its
3255 -- name in the error message, rather than that of the
3258 if Is_Concurrent_Type (P_Name)
3259 and then Is_Internal_Name (Chars (P_Name))
3261 Error_Msg_Node_2 := Entity (Prefix (N));
3263 Error_Msg_Node_2 := P_Name;
3266 if P_Name = System_Aux_Id then
3267 P_Name := Scope (P_Name);
3268 Set_Entity (Prefix (N), P_Name);
3271 if Present (Candidate) then
3273 if Is_Child_Unit (Candidate) then
3275 ("missing with_clause for child unit &", Selector);
3277 Error_Msg_NE ("& is not a visible entity of&", N, Selector);
3281 -- Within the instantiation of a child unit, the prefix may
3282 -- denote the parent instance, but the selector has the
3283 -- name of the original child. Find whether we are within
3284 -- the corresponding instance, and get the proper entity, which
3285 -- can only be an enclosing scope.
3288 and then In_Open_Scopes (P_Name)
3289 and then Is_Generic_Instance (P_Name)
3292 S : Entity_Id := Current_Scope;
3296 for J in reverse 0 .. Scope_Stack.Last loop
3297 S := Scope_Stack.Table (J).Entity;
3299 exit when S = Standard_Standard;
3301 if Ekind (S) = E_Function
3302 or else Ekind (S) = E_Package
3303 or else Ekind (S) = E_Procedure
3305 P := Generic_Parent (Specification
3306 (Unit_Declaration_Node (S)));
3309 and then Chars (Scope (P)) = Chars (O_Name)
3310 and then Chars (P) = Chars (Selector)
3321 if Chars (P_Name) = Name_Ada
3322 and then Scope (P_Name) = Standard_Standard
3324 Error_Msg_Node_2 := Selector;
3325 Error_Msg_NE ("missing with for `&.&`", N, P_Name);
3327 -- If this is a selection from a dummy package, then
3328 -- suppress the error message, of course the entity
3329 -- is missing if the package is missing!
3331 elsif Sloc (Error_Msg_Node_2) = No_Location then
3334 -- Here we have the case of an undefined component
3338 Error_Msg_NE ("& not declared in&", N, Selector);
3340 -- Check for misspelling of some entity in prefix.
3342 Id := First_Entity (P_Name);
3343 Get_Name_String (Chars (Selector));
3346 S : constant String (1 .. Name_Len) :=
3347 Name_Buffer (1 .. Name_Len);
3349 while Present (Id) loop
3350 Get_Name_String (Chars (Id));
3351 if Is_Bad_Spelling_Of
3352 (Name_Buffer (1 .. Name_Len), S)
3353 and then not Is_Internal_Name (Chars (Id))
3356 ("possible misspelling of&", Selector, Id);
3364 -- Specialize the message if this may be an instantiation
3365 -- of a child unit that was not mentioned in the context.
3367 if Nkind (Parent (N)) = N_Package_Instantiation
3368 and then Is_Generic_Instance (Entity (Prefix (N)))
3369 and then Is_Compilation_Unit
3370 (Generic_Parent (Parent (Entity (Prefix (N)))))
3373 ("\possible missing with clause on child unit&",
3384 if Comes_From_Source (N)
3385 and then Is_Remote_Access_To_Subprogram_Type (Id)
3387 Id := Equivalent_Type (Id);
3388 Set_Chars (Selector, Chars (Id));
3391 if Ekind (P_Name) = E_Package
3392 and then From_With_Type (P_Name)
3394 if From_With_Type (Id)
3395 or else (Ekind (Id) = E_Package and then From_With_Type (Id))
3400 ("imported package can only be used to access imported type",
3405 if Is_Task_Type (P_Name)
3406 and then ((Ekind (Id) = E_Entry
3407 and then Nkind (Parent (N)) /= N_Attribute_Reference)
3409 (Ekind (Id) = E_Entry_Family
3411 Nkind (Parent (Parent (N))) /= N_Attribute_Reference))
3413 -- It is an entry call after all, either to the current task
3414 -- (which will deadlock) or to an enclosing task.
3416 Analyze_Selected_Component (N);
3420 Change_Selected_Component_To_Expanded_Name (N);
3422 -- Do style check and generate reference, but skip both steps if this
3423 -- entity has homonyms, since we may not have the right homonym set
3424 -- yet. The proper homonym will be set during the resolve phase.
3426 if Has_Homonym (Id) then
3429 Set_Entity_With_Style_Check (N, Id);
3430 Generate_Reference (Id, N);
3433 if Is_Type (Id) then
3436 Set_Etype (N, Get_Full_View (Etype (Id)));
3439 -- If the Ekind of the entity is Void, it means that all homonyms
3440 -- are hidden from all visibility (RM 8.3(5,14-20)).
3442 if Ekind (Id) = E_Void then
3443 Premature_Usage (N);
3445 elsif Is_Overloadable (Id)
3446 and then Present (Homonym (Id))
3449 H : Entity_Id := Homonym (Id);
3452 while Present (H) loop
3453 if Scope (H) = Scope (Id) then
3454 Collect_Interps (N);
3461 -- If an extension of System is present, collect possible
3462 -- explicit overloadings declared in the extension.
3464 if Chars (P_Name) = Name_System
3465 and then Scope (P_Name) = Standard_Standard
3466 and then Present (System_Extend_Unit)
3467 and then Present_System_Aux (N)
3469 H := Current_Entity (Id);
3471 while Present (H) loop
3472 if Scope (H) = System_Aux_Id then
3473 Add_One_Interp (N, H, Etype (H));
3482 if Nkind (Selector_Name (N)) = N_Operator_Symbol
3483 and then Scope (Id) /= Standard_Standard
3485 -- In addition to user-defined operators in the given scope,
3486 -- there may be an implicit instance of the predefined
3487 -- operator. The operator (defined in Standard) is found
3488 -- in Has_Implicit_Operator, and added to the interpretations.
3489 -- Procedure Add_One_Interp will determine which hides which.
3491 if Has_Implicit_Operator (N) then
3495 end Find_Expanded_Name;
3497 -------------------------
3498 -- Find_Renamed_Entity --
3499 -------------------------
3501 function Find_Renamed_Entity
3505 Is_Actual : Boolean := False) return Entity_Id
3508 I1 : Interp_Index := 0; -- Suppress junk warnings
3514 function Enclosing_Instance return Entity_Id;
3515 -- If the renaming determines the entity for the default of a formal
3516 -- subprogram nested within another instance, choose the innermost
3517 -- candidate. This is because if the formal has a box, and we are within
3518 -- an enclosing instance where some candidate interpretations are local
3519 -- to this enclosing instance, we know that the default was properly
3520 -- resolved when analyzing the generic, so we prefer the local
3521 -- candidates to those that are external. This is not always the case
3522 -- but is a reasonable heuristic on the use of nested generics.
3523 -- The proper solution requires a full renaming model.
3525 function Within (Inner, Outer : Entity_Id) return Boolean;
3526 -- Determine whether a candidate subprogram is defined within
3527 -- the enclosing instance. If yes, it has precedence over outer
3530 function Is_Visible_Operation (Op : Entity_Id) return Boolean;
3531 -- If the renamed entity is an implicit operator, check whether it is
3532 -- visible because its operand type is properly visible. This
3533 -- check applies to explicit renamed entities that appear in the
3534 -- source in a renaming declaration or a formal subprogram instance,
3535 -- but not to default generic actuals with a name.
3537 ------------------------
3538 -- Enclosing_Instance --
3539 ------------------------
3541 function Enclosing_Instance return Entity_Id is
3545 if not Is_Generic_Instance (Current_Scope)
3546 and then not Is_Actual
3551 S := Scope (Current_Scope);
3553 while S /= Standard_Standard loop
3555 if Is_Generic_Instance (S) then
3563 end Enclosing_Instance;
3565 --------------------------
3566 -- Is_Visible_Operation --
3567 --------------------------
3569 function Is_Visible_Operation (Op : Entity_Id) return Boolean is
3575 if Ekind (Op) /= E_Operator
3576 or else Scope (Op) /= Standard_Standard
3577 or else (In_Instance
3580 or else Present (Enclosing_Instance)))
3585 -- For a fixed point type operator, check the resulting type,
3586 -- because it may be a mixed mode integer * fixed operation.
3588 if Present (Next_Formal (First_Formal (New_S)))
3589 and then Is_Fixed_Point_Type (Etype (New_S))
3591 Typ := Etype (New_S);
3593 Typ := Etype (First_Formal (New_S));
3596 Btyp := Base_Type (Typ);
3598 if Nkind (Nam) /= N_Expanded_Name then
3599 return (In_Open_Scopes (Scope (Btyp))
3600 or else Is_Potentially_Use_Visible (Btyp)
3601 or else In_Use (Btyp)
3602 or else In_Use (Scope (Btyp)));
3605 Scop := Entity (Prefix (Nam));
3607 if Ekind (Scop) = E_Package
3608 and then Present (Renamed_Object (Scop))
3610 Scop := Renamed_Object (Scop);
3613 -- Operator is visible if prefix of expanded name denotes
3614 -- scope of type, or else type type is defined in System_Aux
3615 -- and the prefix denotes System.
3617 return Scope (Btyp) = Scop
3618 or else (Scope (Btyp) = System_Aux_Id
3619 and then Scope (Scope (Btyp)) = Scop);
3622 end Is_Visible_Operation;
3628 function Within (Inner, Outer : Entity_Id) return Boolean is
3629 Sc : Entity_Id := Scope (Inner);
3632 while Sc /= Standard_Standard loop
3644 function Report_Overload return Entity_Id;
3645 -- List possible interpretations, and specialize message in the
3646 -- case of a generic actual.
3648 function Report_Overload return Entity_Id is
3652 ("ambiguous actual subprogram&, " &
3653 "possible interpretations: ", N, Nam);
3656 ("ambiguous subprogram, " &
3657 "possible interpretations: ", N);
3660 List_Interps (Nam, N);
3662 end Report_Overload;
3664 -- Start of processing for Find_Renamed_Entry
3668 Candidate_Renaming := Empty;
3670 if not Is_Overloaded (Nam) then
3671 if Entity_Matches_Spec (Entity (Nam), New_S)
3672 and then Is_Visible_Operation (Entity (Nam))
3674 Old_S := Entity (Nam);
3677 Present (First_Formal (Entity (Nam)))
3678 and then Present (First_Formal (New_S))
3679 and then (Base_Type (Etype (First_Formal (Entity (Nam))))
3680 = Base_Type (Etype (First_Formal (New_S))))
3682 Candidate_Renaming := Entity (Nam);
3686 Get_First_Interp (Nam, Ind, It);
3688 while Present (It.Nam) loop
3690 if Entity_Matches_Spec (It.Nam, New_S)
3691 and then Is_Visible_Operation (It.Nam)
3693 if Old_S /= Any_Id then
3695 -- Note: The call to Disambiguate only happens if a
3696 -- previous interpretation was found, in which case I1
3697 -- has received a value.
3699 It1 := Disambiguate (Nam, I1, Ind, Etype (Old_S));
3701 if It1 = No_Interp then
3703 Inst := Enclosing_Instance;
3705 if Present (Inst) then
3707 if Within (It.Nam, Inst) then
3710 elsif Within (Old_S, Inst) then
3714 return Report_Overload;
3718 return Report_Overload;
3732 Present (First_Formal (It.Nam))
3733 and then Present (First_Formal (New_S))
3734 and then (Base_Type (Etype (First_Formal (It.Nam)))
3735 = Base_Type (Etype (First_Formal (New_S))))
3737 Candidate_Renaming := It.Nam;
3740 Get_Next_Interp (Ind, It);
3743 Set_Entity (Nam, Old_S);
3744 Set_Is_Overloaded (Nam, False);
3748 end Find_Renamed_Entity;
3750 -----------------------------
3751 -- Find_Selected_Component --
3752 -----------------------------
3754 procedure Find_Selected_Component (N : Node_Id) is
3755 P : constant Node_Id := Prefix (N);
3758 -- Entity denoted by prefix
3768 if Nkind (P) = N_Error then
3771 -- If the selector already has an entity, the node has been
3772 -- constructed in the course of expansion, and is known to be
3773 -- valid. Do not verify that it is defined for the type (it may
3774 -- be a private component used in the expansion of record equality).
3776 elsif Present (Entity (Selector_Name (N))) then
3779 or else Etype (N) = Any_Type
3782 Sel_Name : constant Node_Id := Selector_Name (N);
3783 Selector : constant Entity_Id := Entity (Sel_Name);
3787 Set_Etype (Sel_Name, Etype (Selector));
3789 if not Is_Entity_Name (P) then
3793 -- Build an actual subtype except for the first parameter
3794 -- of an init proc, where this actual subtype is by
3795 -- definition incorrect, since the object is uninitialized
3796 -- (and does not even have defined discriminants etc.)
3798 if Is_Entity_Name (P)
3799 and then Ekind (Entity (P)) = E_Function
3801 Nam := New_Copy (P);
3803 if Is_Overloaded (P) then
3804 Save_Interps (P, Nam);
3808 Make_Function_Call (Sloc (P), Name => Nam));
3810 Analyze_Selected_Component (N);
3813 elsif Ekind (Selector) = E_Component
3814 and then (not Is_Entity_Name (P)
3815 or else Chars (Entity (P)) /= Name_uInit)
3818 Build_Actual_Subtype_Of_Component (
3819 Etype (Selector), N);
3824 if No (C_Etype) then
3825 C_Etype := Etype (Selector);
3827 Insert_Action (N, C_Etype);
3828 C_Etype := Defining_Identifier (C_Etype);
3831 Set_Etype (N, C_Etype);
3834 -- If this is the name of an entry or protected operation, and
3835 -- the prefix is an access type, insert an explicit dereference,
3836 -- so that entry calls are treated uniformly.
3838 if Is_Access_Type (Etype (P))
3839 and then Is_Concurrent_Type (Designated_Type (Etype (P)))
3842 New_P : constant Node_Id :=
3843 Make_Explicit_Dereference (Sloc (P),
3844 Prefix => Relocate_Node (P));
3847 Set_Etype (P, Designated_Type (Etype (Prefix (P))));
3851 -- If the selected component appears within a default expression
3852 -- and it has an actual subtype, the pre-analysis has not yet
3853 -- completed its analysis, because Insert_Actions is disabled in
3854 -- that context. Within the init proc of the enclosing type we
3855 -- must complete this analysis, if an actual subtype was created.
3857 elsif Inside_Init_Proc then
3859 Typ : constant Entity_Id := Etype (N);
3860 Decl : constant Node_Id := Declaration_Node (Typ);
3863 if Nkind (Decl) = N_Subtype_Declaration
3864 and then not Analyzed (Decl)
3865 and then Is_List_Member (Decl)
3866 and then No (Parent (Decl))
3869 Insert_Action (N, Decl);
3876 elsif Is_Entity_Name (P) then
3877 P_Name := Entity (P);
3879 -- The prefix may denote an enclosing type which is the completion
3880 -- of an incomplete type declaration.
3882 if Is_Type (P_Name) then
3883 Set_Entity (P, Get_Full_View (P_Name));
3884 Set_Etype (P, Entity (P));
3885 P_Name := Entity (P);
3888 P_Type := Base_Type (Etype (P));
3890 if Debug_Flag_E then
3891 Write_Str ("Found prefix type to be ");
3892 Write_Entity_Info (P_Type, " "); Write_Eol;
3895 -- First check for components of a record object (not the
3896 -- result of a call, which is handled below).
3898 if Is_Appropriate_For_Record (P_Type)
3899 and then not Is_Overloadable (P_Name)
3900 and then not Is_Type (P_Name)
3902 -- Selected component of record. Type checking will validate
3903 -- name of selector.
3905 Analyze_Selected_Component (N);
3907 elsif Is_Appropriate_For_Entry_Prefix (P_Type)
3908 and then not In_Open_Scopes (P_Name)
3909 and then (not Is_Concurrent_Type (Etype (P_Name))
3910 or else not In_Open_Scopes (Etype (P_Name)))
3912 -- Call to protected operation or entry. Type checking is
3913 -- needed on the prefix.
3915 Analyze_Selected_Component (N);
3917 elsif (In_Open_Scopes (P_Name)
3918 and then Ekind (P_Name) /= E_Void
3919 and then not Is_Overloadable (P_Name))
3920 or else (Is_Concurrent_Type (Etype (P_Name))
3921 and then In_Open_Scopes (Etype (P_Name)))
3923 -- Prefix denotes an enclosing loop, block, or task, i.e. an
3924 -- enclosing construct that is not a subprogram or accept.
3926 Find_Expanded_Name (N);
3928 elsif Ekind (P_Name) = E_Package then
3929 Find_Expanded_Name (N);
3931 elsif Is_Overloadable (P_Name) then
3933 -- The subprogram may be a renaming (of an enclosing scope) as
3934 -- in the case of the name of the generic within an instantiation.
3936 if (Ekind (P_Name) = E_Procedure
3937 or else Ekind (P_Name) = E_Function)
3938 and then Present (Alias (P_Name))
3939 and then Is_Generic_Instance (Alias (P_Name))
3941 P_Name := Alias (P_Name);
3944 if Is_Overloaded (P) then
3946 -- The prefix must resolve to a unique enclosing construct.
3949 Found : Boolean := False;
3954 Get_First_Interp (P, Ind, It);
3956 while Present (It.Nam) loop
3958 if In_Open_Scopes (It.Nam) then
3961 "prefix must be unique enclosing scope", N);
3962 Set_Entity (N, Any_Id);
3963 Set_Etype (N, Any_Type);
3972 Get_Next_Interp (Ind, It);
3977 if In_Open_Scopes (P_Name) then
3978 Set_Entity (P, P_Name);
3979 Set_Is_Overloaded (P, False);
3980 Find_Expanded_Name (N);
3983 -- If no interpretation as an expanded name is possible, it
3984 -- must be a selected component of a record returned by a
3985 -- function call. Reformat prefix as a function call, the
3986 -- rest is done by type resolution. If the prefix is a
3987 -- procedure or entry, as is P.X; this is an error.
3989 if Ekind (P_Name) /= E_Function
3990 and then (not Is_Overloaded (P)
3992 Nkind (Parent (N)) = N_Procedure_Call_Statement)
3995 -- Prefix may mention a package that is hidden by a local
3996 -- declaration: let the user know. Scan the full homonym
3997 -- chain, the candidate package may be anywhere on it.
3999 if Present (Homonym (Current_Entity (P_Name))) then
4001 P_Name := Current_Entity (P_Name);
4003 while Present (P_Name) loop
4004 exit when Ekind (P_Name) = E_Package;
4005 P_Name := Homonym (P_Name);
4008 if Present (P_Name) then
4009 Error_Msg_Sloc := Sloc (Entity (Prefix (N)));
4012 ("package& is hidden by declaration#",
4015 Set_Entity (Prefix (N), P_Name);
4016 Find_Expanded_Name (N);
4019 P_Name := Entity (Prefix (N));
4024 ("invalid prefix in selected component&", N, P_Name);
4025 Change_Selected_Component_To_Expanded_Name (N);
4026 Set_Entity (N, Any_Id);
4027 Set_Etype (N, Any_Type);
4030 Nam := New_Copy (P);
4031 Save_Interps (P, Nam);
4033 Make_Function_Call (Sloc (P), Name => Nam));
4035 Analyze_Selected_Component (N);
4039 -- Remaining cases generate various error messages
4042 -- Format node as expanded name, to avoid cascaded errors
4044 Change_Selected_Component_To_Expanded_Name (N);
4045 Set_Entity (N, Any_Id);
4046 Set_Etype (N, Any_Type);
4048 -- Issue error message, but avoid this if error issued already.
4049 -- Use identifier of prefix if one is available.
4051 if P_Name = Any_Id then
4054 elsif Ekind (P_Name) = E_Void then
4055 Premature_Usage (P);
4057 elsif Nkind (P) /= N_Attribute_Reference then
4059 "invalid prefix in selected component&", P);
4063 "invalid prefix in selected component", P);
4068 -- If prefix is not the name of an entity, it must be an expression,
4069 -- whose type is appropriate for a record. This is determined by
4072 Analyze_Selected_Component (N);
4074 end Find_Selected_Component;
4080 procedure Find_Type (N : Node_Id) is
4090 elsif Nkind (N) = N_Attribute_Reference then
4092 -- Class attribute. This is only valid in Ada 95 mode, but we don't
4093 -- do a check, since the tagged type referenced could only exist if
4094 -- we were in 95 mode when it was declared (or, if we were in Ada
4095 -- 83 mode, then an error message would already have been issued).
4097 if Attribute_Name (N) = Name_Class then
4098 Check_Restriction (No_Dispatch, N);
4099 Find_Type (Prefix (N));
4101 -- Propagate error from bad prefix
4103 if Etype (Prefix (N)) = Any_Type then
4104 Set_Entity (N, Any_Type);
4105 Set_Etype (N, Any_Type);
4109 T := Base_Type (Entity (Prefix (N)));
4111 -- Case of non-tagged type
4113 if not Is_Tagged_Type (T) then
4114 if Ekind (T) = E_Incomplete_Type then
4116 -- It is legal to denote the class type of an incomplete
4117 -- type. The full type will have to be tagged, of course.
4119 Set_Is_Tagged_Type (T);
4120 Make_Class_Wide_Type (T);
4121 Set_Entity (N, Class_Wide_Type (T));
4122 Set_Etype (N, Class_Wide_Type (T));
4124 elsif Ekind (T) = E_Private_Type
4125 and then not Is_Generic_Type (T)
4126 and then In_Private_Part (Scope (T))
4128 -- The Class attribute can be applied to an untagged
4129 -- private type fulfilled by a tagged type prior to
4130 -- the full type declaration (but only within the
4131 -- parent package's private part). Create the class-wide
4132 -- type now and check that the full type is tagged
4133 -- later during its analysis. Note that we do not
4134 -- mark the private type as tagged, unlike the case
4135 -- of incomplete types, because the type must still
4136 -- appear untagged to outside units.
4138 if not Present (Class_Wide_Type (T)) then
4139 Make_Class_Wide_Type (T);
4142 Set_Entity (N, Class_Wide_Type (T));
4143 Set_Etype (N, Class_Wide_Type (T));
4146 -- Should we introduce a type Any_Tagged and use
4147 -- Wrong_Type here, it would be a bit more consistent???
4150 ("tagged type required, found}",
4151 Prefix (N), First_Subtype (T));
4152 Set_Entity (N, Any_Type);
4156 -- Case of tagged type
4159 C := Class_Wide_Type (Entity (Prefix (N)));
4160 Set_Entity_With_Style_Check (N, C);
4161 Generate_Reference (C, N);
4165 -- Base attribute, allowed in Ada 95 mode only
4167 elsif Attribute_Name (N) = Name_Base then
4168 if Ada_83 and then Comes_From_Source (N) then
4170 ("(Ada 83) Base attribute not allowed in subtype mark", N);
4173 Find_Type (Prefix (N));
4174 Typ := Entity (Prefix (N));
4177 and then not Is_Scalar_Type (Typ)
4178 and then not Is_Generic_Type (Typ)
4181 ("prefix of Base attribute must be scalar type", Typ);
4183 elsif Sloc (Typ) = Standard_Location
4184 and then Base_Type (Typ) = Typ
4185 and then Warn_On_Redundant_Constructs
4188 ("?redudant attribute, & is its own base type", N, Typ);
4191 T := Base_Type (Typ);
4193 -- Rewrite attribute reference with type itself (see similar
4194 -- processing in Analyze_Attribute, case Base). Preserve
4195 -- prefix if present, for other legality checks.
4197 if Nkind (Prefix (N)) = N_Expanded_Name then
4199 Make_Expanded_Name (Sloc (N),
4200 Chars => Chars (Entity (N)),
4201 Prefix => New_Copy (Prefix (Prefix (N))),
4203 New_Reference_To (Entity (N), Sloc (N))));
4207 New_Reference_To (Entity (N), Sloc (N)));
4214 -- All other attributes are invalid in a subtype mark
4217 Error_Msg_N ("invalid attribute in subtype mark", N);
4223 if Is_Entity_Name (N) then
4224 T_Name := Entity (N);
4226 Error_Msg_N ("subtype mark required in this context", N);
4227 Set_Etype (N, Any_Type);
4231 if T_Name = Any_Id or else Etype (N) = Any_Type then
4233 -- Undefined id. Make it into a valid type
4235 Set_Entity (N, Any_Type);
4237 elsif not Is_Type (T_Name)
4238 and then T_Name /= Standard_Void_Type
4240 Error_Msg_Sloc := Sloc (T_Name);
4241 Error_Msg_N ("subtype mark required in this context", N);
4242 Error_Msg_NE ("\found & declared#", N, T_Name);
4243 Set_Entity (N, Any_Type);
4246 T_Name := Get_Full_View (T_Name);
4248 if In_Open_Scopes (T_Name) then
4249 if Ekind (Base_Type (T_Name)) = E_Task_Type then
4250 Error_Msg_N ("task type cannot be used as type mark " &
4251 "within its own body", N);
4253 Error_Msg_N ("type declaration cannot refer to itself", N);
4256 Set_Etype (N, Any_Type);
4257 Set_Entity (N, Any_Type);
4258 Set_Error_Posted (T_Name);
4262 Set_Entity (N, T_Name);
4263 Set_Etype (N, T_Name);
4267 if Present (Etype (N)) and then Comes_From_Source (N) then
4268 if Is_Fixed_Point_Type (Etype (N)) then
4269 Check_Restriction (No_Fixed_Point, N);
4270 elsif Is_Floating_Point_Type (Etype (N)) then
4271 Check_Restriction (No_Floating_Point, N);
4280 function Get_Full_View (T_Name : Entity_Id) return Entity_Id is
4282 if Ekind (T_Name) = E_Incomplete_Type
4283 and then Present (Full_View (T_Name))
4285 return Full_View (T_Name);
4287 elsif Is_Class_Wide_Type (T_Name)
4288 and then Ekind (Root_Type (T_Name)) = E_Incomplete_Type
4289 and then Present (Full_View (Root_Type (T_Name)))
4291 return Class_Wide_Type (Full_View (Root_Type (T_Name)));
4298 ------------------------------------
4299 -- Has_Implicit_Character_Literal --
4300 ------------------------------------
4302 function Has_Implicit_Character_Literal (N : Node_Id) return Boolean is
4304 Found : Boolean := False;
4305 P : constant Entity_Id := Entity (Prefix (N));
4306 Priv_Id : Entity_Id := Empty;
4309 if Ekind (P) = E_Package
4310 and then not In_Open_Scopes (P)
4312 Priv_Id := First_Private_Entity (P);
4315 if P = Standard_Standard then
4316 Change_Selected_Component_To_Expanded_Name (N);
4317 Rewrite (N, Selector_Name (N));
4319 Set_Etype (Original_Node (N), Standard_Character);
4323 Id := First_Entity (P);
4326 and then Id /= Priv_Id
4328 if Is_Character_Type (Id)
4329 and then (Root_Type (Id) = Standard_Character
4330 or else Root_Type (Id) = Standard_Wide_Character)
4331 and then Id = Base_Type (Id)
4333 -- We replace the node with the literal itself, resolve as a
4334 -- character, and set the type correctly.
4337 Change_Selected_Component_To_Expanded_Name (N);
4338 Rewrite (N, Selector_Name (N));
4341 Set_Etype (Original_Node (N), Id);
4345 -- More than one type derived from Character in given scope.
4346 -- Collect all possible interpretations.
4348 Add_One_Interp (N, Id, Id);
4356 end Has_Implicit_Character_Literal;
4358 ---------------------------
4359 -- Has_Implicit_Operator --
4360 ---------------------------
4362 function Has_Implicit_Operator (N : Node_Id) return Boolean is
4363 Op_Id : constant Name_Id := Chars (Selector_Name (N));
4364 P : constant Entity_Id := Entity (Prefix (N));
4366 Priv_Id : Entity_Id := Empty;
4368 procedure Add_Implicit_Operator
4370 Op_Type : Entity_Id := Empty);
4371 -- Add implicit interpretation to node N, using the type for which
4372 -- a predefined operator exists. If the operator yields a boolean
4373 -- type, the Operand_Type is implicitly referenced by the operator,
4374 -- and a reference to it must be generated.
4376 ---------------------------
4377 -- Add_Implicit_Operator --
4378 ---------------------------
4380 procedure Add_Implicit_Operator
4382 Op_Type : Entity_Id := Empty)
4384 Predef_Op : Entity_Id;
4387 Predef_Op := Current_Entity (Selector_Name (N));
4389 while Present (Predef_Op)
4390 and then Scope (Predef_Op) /= Standard_Standard
4392 Predef_Op := Homonym (Predef_Op);
4395 if Nkind (N) = N_Selected_Component then
4396 Change_Selected_Component_To_Expanded_Name (N);
4399 Add_One_Interp (N, Predef_Op, T);
4401 -- For operators with unary and binary interpretations, add both
4403 if Present (Homonym (Predef_Op)) then
4404 Add_One_Interp (N, Homonym (Predef_Op), T);
4407 -- The node is a reference to a predefined operator, and
4408 -- an implicit reference to the type of its operands.
4410 if Present (Op_Type) then
4411 Generate_Operator_Reference (N, Op_Type);
4413 Generate_Operator_Reference (N, T);
4415 end Add_Implicit_Operator;
4417 -- Start of processing for Has_Implicit_Operator
4421 if Ekind (P) = E_Package
4422 and then not In_Open_Scopes (P)
4424 Priv_Id := First_Private_Entity (P);
4427 Id := First_Entity (P);
4431 -- Boolean operators: an implicit declaration exists if the scope
4432 -- contains a declaration for a derived Boolean type, or for an
4433 -- array of Boolean type.
4435 when Name_Op_And | Name_Op_Not | Name_Op_Or | Name_Op_Xor =>
4437 while Id /= Priv_Id loop
4439 if Valid_Boolean_Arg (Id)
4440 and then Id = Base_Type (Id)
4442 Add_Implicit_Operator (Id);
4449 -- Equality: look for any non-limited type. Result is Boolean.
4451 when Name_Op_Eq | Name_Op_Ne =>
4453 while Id /= Priv_Id loop
4456 and then not Is_Limited_Type (Id)
4457 and then Id = Base_Type (Id)
4459 Add_Implicit_Operator (Standard_Boolean, Id);
4466 -- Comparison operators: scalar type, or array of scalar.
4468 when Name_Op_Lt | Name_Op_Le | Name_Op_Gt | Name_Op_Ge =>
4470 while Id /= Priv_Id loop
4471 if (Is_Scalar_Type (Id)
4472 or else (Is_Array_Type (Id)
4473 and then Is_Scalar_Type (Component_Type (Id))))
4474 and then Id = Base_Type (Id)
4476 Add_Implicit_Operator (Standard_Boolean, Id);
4483 -- Arithmetic operators: any numeric type
4494 while Id /= Priv_Id loop
4495 if Is_Numeric_Type (Id)
4496 and then Id = Base_Type (Id)
4498 Add_Implicit_Operator (Id);
4505 -- Concatenation: any one-dimensional array type
4507 when Name_Op_Concat =>
4509 while Id /= Priv_Id loop
4510 if Is_Array_Type (Id) and then Number_Dimensions (Id) = 1
4511 and then Id = Base_Type (Id)
4513 Add_Implicit_Operator (Id);
4520 -- What is the others condition here? Should we be using a
4521 -- subtype of Name_Id that would restrict to operators ???
4523 when others => null;
4527 -- If we fall through, then we do not have an implicit operator
4531 end Has_Implicit_Operator;
4533 --------------------
4534 -- In_Open_Scopes --
4535 --------------------
4537 function In_Open_Scopes (S : Entity_Id) return Boolean is
4539 -- Since there are several scope stacks maintained by Scope_Stack each
4540 -- delineated by Standard (see comments by definition of Scope_Stack)
4541 -- it is necessary to end the search when Standard is reached.
4543 for J in reverse 0 .. Scope_Stack.Last loop
4544 if Scope_Stack.Table (J).Entity = S then
4548 -- We need Is_Active_Stack_Base to tell us when to stop rather
4549 -- than checking for Standard_Standard because there are cases
4550 -- where Standard_Standard appears in the middle of the active
4551 -- set of scopes. This affects the declaration and overriding
4552 -- of private inherited operations in instantiations of generic
4555 exit when Scope_Stack.Table (J).Is_Active_Stack_Base;
4561 -----------------------------
4562 -- Inherit_Renamed_Profile --
4563 -----------------------------
4565 procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id) is
4572 if Ekind (Old_S) = E_Operator then
4574 New_F := First_Formal (New_S);
4576 while Present (New_F) loop
4577 Set_Etype (New_F, Base_Type (Etype (New_F)));
4578 Next_Formal (New_F);
4581 Set_Etype (New_S, Base_Type (Etype (New_S)));
4584 New_F := First_Formal (New_S);
4585 Old_F := First_Formal (Old_S);
4587 while Present (New_F) loop
4588 New_T := Etype (New_F);
4589 Old_T := Etype (Old_F);
4591 -- If the new type is a renaming of the old one, as is the
4592 -- case for actuals in instances, retain its name, to simplify
4593 -- later disambiguation.
4595 if Nkind (Parent (New_T)) = N_Subtype_Declaration
4596 and then Is_Entity_Name (Subtype_Indication (Parent (New_T)))
4597 and then Entity (Subtype_Indication (Parent (New_T))) = Old_T
4601 Set_Etype (New_F, Old_T);
4604 Next_Formal (New_F);
4605 Next_Formal (Old_F);
4608 if Ekind (Old_S) = E_Function
4609 or else Ekind (Old_S) = E_Enumeration_Literal
4611 Set_Etype (New_S, Etype (Old_S));
4614 end Inherit_Renamed_Profile;
4620 procedure Initialize is
4625 -------------------------
4626 -- Install_Use_Clauses --
4627 -------------------------
4629 procedure Install_Use_Clauses (Clause : Node_Id) is
4630 U : Node_Id := Clause;
4635 while Present (U) loop
4637 -- Case of USE package
4639 if Nkind (U) = N_Use_Package_Clause then
4640 P := First (Names (U));
4642 while Present (P) loop
4645 if Ekind (Id) = E_Package then
4648 Set_Redundant_Use (P, True);
4650 elsif Present (Renamed_Object (Id))
4651 and then In_Use (Renamed_Object (Id))
4653 Set_Redundant_Use (P, True);
4656 Use_One_Package (Id, U);
4666 P := First (Subtype_Marks (U));
4668 while Present (P) loop
4669 if not Is_Entity_Name (P)
4670 or else No (Entity (P))
4674 elsif Entity (P) /= Any_Type then
4682 Next_Use_Clause (U);
4684 end Install_Use_Clauses;
4686 -------------------------------------
4687 -- Is_Appropriate_For_Entry_Prefix --
4688 -------------------------------------
4690 function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean is
4691 P_Type : Entity_Id := T;
4694 if Is_Access_Type (P_Type) then
4695 P_Type := Designated_Type (P_Type);
4698 return Is_Task_Type (P_Type) or else Is_Protected_Type (P_Type);
4699 end Is_Appropriate_For_Entry_Prefix;
4701 -------------------------------
4702 -- Is_Appropriate_For_Record --
4703 -------------------------------
4705 function Is_Appropriate_For_Record
4709 function Has_Components (T1 : Entity_Id) return Boolean;
4710 -- Determine if given type has components (i.e. is either a record
4711 -- type or a type that has discriminants).
4713 function Has_Components (T1 : Entity_Id) return Boolean is
4715 return Is_Record_Type (T1)
4716 or else (Is_Private_Type (T1) and then Has_Discriminants (T1))
4717 or else (Is_Task_Type (T1) and then Has_Discriminants (T1));
4720 -- Start of processing for Is_Appropriate_For_Record
4725 and then (Has_Components (T)
4726 or else (Is_Access_Type (T)
4728 Has_Components (Designated_Type (T))));
4729 end Is_Appropriate_For_Record;
4735 procedure New_Scope (S : Entity_Id) is
4739 if Ekind (S) = E_Void then
4742 -- Set scope depth if not a non-concurrent type, and we have not
4743 -- yet set the scope depth. This means that we have the first
4744 -- occurrence of the scope, and this is where the depth is set.
4746 elsif (not Is_Type (S) or else Is_Concurrent_Type (S))
4747 and then not Scope_Depth_Set (S)
4749 if S = Standard_Standard then
4750 Set_Scope_Depth_Value (S, Uint_0);
4752 elsif Is_Child_Unit (S) then
4753 Set_Scope_Depth_Value (S, Uint_1);
4755 elsif not Is_Record_Type (Current_Scope) then
4756 if Ekind (S) = E_Loop then
4757 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope));
4759 Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope) + 1);
4764 Scope_Stack.Increment_Last;
4767 SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
4771 SST.Save_Scope_Suppress := Scope_Suppress;
4772 SST.Save_Local_Entity_Suppress := Local_Entity_Suppress.Last;
4774 if Scope_Stack.Last > Scope_Stack.First then
4775 SST.Component_Alignment_Default := Scope_Stack.Table
4776 (Scope_Stack.Last - 1).
4777 Component_Alignment_Default;
4780 SST.Last_Subprogram_Name := null;
4781 SST.Is_Transient := False;
4782 SST.Node_To_Be_Wrapped := Empty;
4783 SST.Pending_Freeze_Actions := No_List;
4784 SST.Actions_To_Be_Wrapped_Before := No_List;
4785 SST.Actions_To_Be_Wrapped_After := No_List;
4786 SST.First_Use_Clause := Empty;
4787 SST.Is_Active_Stack_Base := False;
4790 if Debug_Flag_W then
4791 Write_Str ("--> new scope: ");
4792 Write_Name (Chars (Current_Scope));
4793 Write_Str (", Id=");
4794 Write_Int (Int (Current_Scope));
4795 Write_Str (", Depth=");
4796 Write_Int (Int (Scope_Stack.Last));
4800 -- Copy from Scope (S) the categorization flags to S, this is not
4801 -- done in case Scope (S) is Standard_Standard since propagation
4802 -- is from library unit entity inwards.
4804 if S /= Standard_Standard
4805 and then Scope (S) /= Standard_Standard
4806 and then not Is_Child_Unit (S)
4810 if Nkind (E) not in N_Entity then
4814 -- We only propagate inwards for library level entities,
4815 -- inner level subprograms do not inherit the categorization.
4817 if Is_Library_Level_Entity (S) then
4818 Set_Is_Preelaborated (S, Is_Preelaborated (E));
4819 Set_Is_Shared_Passive (S, Is_Shared_Passive (E));
4820 Set_Categorization_From_Scope (E => S, Scop => E);
4829 procedure Pop_Scope is
4830 SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last);
4833 if Debug_Flag_E then
4837 Scope_Suppress := SST.Save_Scope_Suppress;
4838 Local_Entity_Suppress.Set_Last (SST.Save_Local_Entity_Suppress);
4840 if Debug_Flag_W then
4841 Write_Str ("--> exiting scope: ");
4842 Write_Name (Chars (Current_Scope));
4843 Write_Str (", Depth=");
4844 Write_Int (Int (Scope_Stack.Last));
4848 End_Use_Clauses (SST.First_Use_Clause);
4850 -- If the actions to be wrapped are still there they will get lost
4851 -- causing incomplete code to be generated. It is better to abort in
4852 -- this case (and we do the abort even with assertions off since the
4853 -- penalty is incorrect code generation)
4855 if SST.Actions_To_Be_Wrapped_Before /= No_List
4857 SST.Actions_To_Be_Wrapped_After /= No_List
4862 -- Free last subprogram name if allocated, and pop scope
4864 Free (SST.Last_Subprogram_Name);
4865 Scope_Stack.Decrement_Last;
4868 ---------------------
4869 -- Premature_Usage --
4870 ---------------------
4872 procedure Premature_Usage (N : Node_Id) is
4873 Kind : constant Node_Kind := Nkind (Parent (Entity (N)));
4874 E : Entity_Id := Entity (N);
4877 -- Within an instance, the analysis of the actual for a formal object
4878 -- does not see the name of the object itself. This is significant
4879 -- only if the object is an aggregate, where its analysis does not do
4880 -- any name resolution on component associations. (see 4717-008). In
4881 -- such a case, look for the visible homonym on the chain.
4884 and then Present (Homonym (E))
4889 and then not In_Open_Scopes (Scope (E))
4896 Set_Etype (N, Etype (E));
4901 if Kind = N_Component_Declaration then
4903 ("component&! cannot be used before end of record declaration", N);
4905 elsif Kind = N_Parameter_Specification then
4907 ("formal parameter&! cannot be used before end of specification",
4910 elsif Kind = N_Discriminant_Specification then
4912 ("discriminant&! cannot be used before end of discriminant part",
4915 elsif Kind = N_Procedure_Specification
4916 or else Kind = N_Function_Specification
4919 ("subprogram&! cannot be used before end of its declaration",
4923 ("object& cannot be used before end of its declaration!", N);
4925 end Premature_Usage;
4927 ------------------------
4928 -- Present_System_Aux --
4929 ------------------------
4931 function Present_System_Aux (N : Node_Id := Empty) return Boolean is
4934 Unum : Unit_Number_Type;
4939 function Find_System (C_Unit : Node_Id) return Entity_Id;
4940 -- Scan context clause of compilation unit to find a with_clause
4943 function Find_System (C_Unit : Node_Id) return Entity_Id is
4944 With_Clause : Node_Id;
4947 With_Clause := First (Context_Items (C_Unit));
4949 while Present (With_Clause) loop
4950 if (Nkind (With_Clause) = N_With_Clause
4951 and then Chars (Name (With_Clause)) = Name_System)
4952 and then Comes_From_Source (With_Clause)
4963 -- Start of processing for Present_System_Aux
4966 -- The child unit may have been loaded and analyzed already.
4968 if Present (System_Aux_Id) then
4971 -- If no previous pragma for System.Aux, nothing to load
4973 elsif No (System_Extend_Unit) then
4976 -- Use the unit name given in the pragma to retrieve the unit.
4977 -- Verify that System itself appears in the context clause of the
4978 -- current compilation. If System is not present, an error will
4979 -- have been reported already.
4982 With_Sys := Find_System (Cunit (Current_Sem_Unit));
4984 The_Unit := Unit (Cunit (Current_Sem_Unit));
4987 and then (Nkind (The_Unit) = N_Package_Body
4988 or else (Nkind (The_Unit) = N_Subprogram_Body
4989 and then not Acts_As_Spec (Cunit (Current_Sem_Unit))))
4991 With_Sys := Find_System (Library_Unit (Cunit (Current_Sem_Unit)));
4995 and then Present (N)
4997 -- If we are compiling a subunit, we need to examine its
4998 -- context as well (Current_Sem_Unit is the parent unit);
5000 The_Unit := Parent (N);
5002 while Nkind (The_Unit) /= N_Compilation_Unit loop
5003 The_Unit := Parent (The_Unit);
5006 if Nkind (Unit (The_Unit)) = N_Subunit then
5007 With_Sys := Find_System (The_Unit);
5011 if No (With_Sys) then
5015 Loc := Sloc (With_Sys);
5016 Get_Name_String (Chars (Expression (System_Extend_Unit)));
5017 Name_Buffer (8 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
5018 Name_Buffer (1 .. 7) := "system.";
5019 Name_Buffer (Name_Len + 8) := '%';
5020 Name_Buffer (Name_Len + 9) := 's';
5021 Name_Len := Name_Len + 9;
5022 Aux_Name := Name_Find;
5026 (Load_Name => Aux_Name,
5029 Error_Node => With_Sys);
5031 if Unum /= No_Unit then
5032 Semantics (Cunit (Unum));
5034 Defining_Entity (Specification (Unit (Cunit (Unum))));
5036 Withn := Make_With_Clause (Loc,
5038 Make_Expanded_Name (Loc,
5039 Chars => Chars (System_Aux_Id),
5041 New_Reference_To (Scope (System_Aux_Id), Loc),
5043 New_Reference_To (System_Aux_Id, Loc)));
5045 Set_Entity (Name (Withn), System_Aux_Id);
5047 Set_Library_Unit (Withn, Cunit (Unum));
5048 Set_Corresponding_Spec (Withn, System_Aux_Id);
5049 Set_First_Name (Withn, True);
5050 Set_Implicit_With (Withn, True);
5052 Insert_After (With_Sys, Withn);
5053 Mark_Rewrite_Insertion (Withn);
5054 Set_Context_Installed (Withn);
5058 -- Here if unit load failed
5061 Error_Msg_Name_1 := Name_System;
5062 Error_Msg_Name_2 := Chars (Expression (System_Extend_Unit));
5064 ("extension package `%.%` does not exist",
5065 Opt.System_Extend_Unit);
5069 end Present_System_Aux;
5071 -------------------------
5072 -- Restore_Scope_Stack --
5073 -------------------------
5075 procedure Restore_Scope_Stack (Handle_Use : Boolean := True) is
5078 Comp_Unit : Node_Id;
5079 In_Child : Boolean := False;
5080 Full_Vis : Boolean := True;
5081 SS_Last : constant Int := Scope_Stack.Last;
5084 -- Restore visibility of previous scope stack, if any.
5086 for J in reverse 0 .. Scope_Stack.Last loop
5087 exit when Scope_Stack.Table (J).Entity = Standard_Standard
5088 or else No (Scope_Stack.Table (J).Entity);
5090 S := Scope_Stack.Table (J).Entity;
5092 if not Is_Hidden_Open_Scope (S) then
5094 -- If the parent scope is hidden, its entities are hidden as
5095 -- well, unless the entity is the instantiation currently
5098 if not Is_Hidden_Open_Scope (Scope (S))
5099 or else not Analyzed (Parent (S))
5100 or else Scope (S) = Standard_Standard
5102 Set_Is_Immediately_Visible (S, True);
5105 E := First_Entity (S);
5107 while Present (E) loop
5108 if Is_Child_Unit (E) then
5109 Set_Is_Immediately_Visible (E,
5110 Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
5112 Set_Is_Immediately_Visible (E, True);
5117 if not Full_Vis then
5118 exit when E = First_Private_Entity (S);
5122 -- The visibility of child units (siblings of current compilation)
5123 -- must be restored in any case. Their declarations may appear
5124 -- after the private part of the parent.
5127 and then Present (E)
5129 while Present (E) loop
5130 if Is_Child_Unit (E) then
5131 Set_Is_Immediately_Visible (E,
5132 Is_Visible_Child_Unit (E) or else In_Open_Scopes (E));
5140 if Is_Child_Unit (S)
5141 and not In_Child -- check only for current unit.
5145 -- restore visibility of parents according to whether the child
5146 -- is private and whether we are in its visible part.
5148 Comp_Unit := Parent (Unit_Declaration_Node (S));
5150 if Nkind (Comp_Unit) = N_Compilation_Unit
5151 and then Private_Present (Comp_Unit)
5155 elsif (Ekind (S) = E_Package
5156 or else Ekind (S) = E_Generic_Package)
5157 and then (In_Private_Part (S)
5158 or else In_Package_Body (S))
5162 elsif (Ekind (S) = E_Procedure
5163 or else Ekind (S) = E_Function)
5164 and then Has_Completion (S)
5175 if SS_Last >= Scope_Stack.First
5176 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
5179 Install_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
5181 end Restore_Scope_Stack;
5183 ----------------------
5184 -- Save_Scope_Stack --
5185 ----------------------
5187 procedure Save_Scope_Stack (Handle_Use : Boolean := True) is
5190 SS_Last : constant Int := Scope_Stack.Last;
5193 if SS_Last >= Scope_Stack.First
5194 and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard
5197 End_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause);
5200 -- If the call is from within a compilation unit, as when
5201 -- called from Rtsfind, make current entries in scope stack
5202 -- invisible while we analyze the new unit.
5204 for J in reverse 0 .. SS_Last loop
5205 exit when Scope_Stack.Table (J).Entity = Standard_Standard
5206 or else No (Scope_Stack.Table (J).Entity);
5208 S := Scope_Stack.Table (J).Entity;
5209 Set_Is_Immediately_Visible (S, False);
5210 E := First_Entity (S);
5212 while Present (E) loop
5213 Set_Is_Immediately_Visible (E, False);
5219 end Save_Scope_Stack;
5225 procedure Set_Use (L : List_Id) is
5227 Pack_Name : Node_Id;
5235 while Present (Decl) loop
5236 if Nkind (Decl) = N_Use_Package_Clause then
5237 Chain_Use_Clause (Decl);
5238 Pack_Name := First (Names (Decl));
5240 while Present (Pack_Name) loop
5241 Pack := Entity (Pack_Name);
5243 if Ekind (Pack) = E_Package
5244 and then Applicable_Use (Pack_Name)
5246 Use_One_Package (Pack, Decl);
5252 elsif Nkind (Decl) = N_Use_Type_Clause then
5253 Chain_Use_Clause (Decl);
5254 Id := First (Subtype_Marks (Decl));
5256 while Present (Id) loop
5257 if Entity (Id) /= Any_Type then
5270 ---------------------
5271 -- Use_One_Package --
5272 ---------------------
5274 procedure Use_One_Package (P : Entity_Id; N : Node_Id) is
5277 Current_Instance : Entity_Id := Empty;
5281 if Ekind (P) /= E_Package then
5287 if From_With_Type (P) then
5288 Error_Msg_N ("imported package cannot appear in use clause", N);
5291 -- Find enclosing instance, if any.
5294 Current_Instance := Current_Scope;
5296 while not Is_Generic_Instance (Current_Instance) loop
5297 Current_Instance := Scope (Current_Instance);
5300 if No (Hidden_By_Use_Clause (N)) then
5301 Set_Hidden_By_Use_Clause (N, New_Elmt_List);
5305 -- If unit is a package renaming, indicate that the renamed
5306 -- package is also in use (the flags on both entities must
5307 -- remain consistent, and a subsequent use of either of them
5308 -- should be recognized as redundant).
5310 if Present (Renamed_Object (P)) then
5311 Set_In_Use (Renamed_Object (P));
5312 Real_P := Renamed_Object (P);
5317 -- Loop through entities in one package making them potentially
5320 Id := First_Entity (P);
5322 and then Id /= First_Private_Entity (P)
5324 Prev := Current_Entity (Id);
5326 while Present (Prev) loop
5327 if Is_Immediately_Visible (Prev)
5328 and then (not Is_Overloadable (Prev)
5329 or else not Is_Overloadable (Id)
5330 or else (Type_Conformant (Id, Prev)))
5332 if No (Current_Instance) then
5334 -- Potentially use-visible entity remains hidden
5336 goto Next_Usable_Entity;
5338 -- A use clause within an instance hides outer global
5339 -- entities, which are not used to resolve local entities
5340 -- in the instance. Note that the predefined entities in
5341 -- Standard could not have been hidden in the generic by
5342 -- a use clause, and therefore remain visible. Other
5343 -- compilation units whose entities appear in Standard must
5344 -- be hidden in an instance.
5346 -- To determine whether an entity is external to the instance
5347 -- we compare the scope depth of its scope with that of the
5348 -- current instance. However, a generic actual of a subprogram
5349 -- instance is declared in the wrapper package but will not be
5350 -- hidden by a use-visible entity.
5352 elsif not Is_Hidden (Id)
5353 and then not Is_Wrapper_Package (Scope (Prev))
5354 and then Scope_Depth (Scope (Prev)) <
5355 Scope_Depth (Current_Instance)
5356 and then (Scope (Prev) /= Standard_Standard
5357 or else Sloc (Prev) > Standard_Location)
5359 Set_Is_Potentially_Use_Visible (Id);
5360 Set_Is_Immediately_Visible (Prev, False);
5361 Append_Elmt (Prev, Hidden_By_Use_Clause (N));
5364 -- A user-defined operator is not use-visible if the
5365 -- predefined operator for the type is immediately visible,
5366 -- which is the case if the type of the operand is in an open
5367 -- scope. This does not apply to user-defined operators that
5368 -- have operands of different types, because the predefined
5369 -- mixed mode operations (multiplication and division) apply to
5370 -- universal types and do not hide anything.
5372 elsif Ekind (Prev) = E_Operator
5373 and then Operator_Matches_Spec (Prev, Id)
5374 and then In_Open_Scopes
5375 (Scope (Base_Type (Etype (First_Formal (Id)))))
5376 and then (No (Next_Formal (First_Formal (Id)))
5377 or else Etype (First_Formal (Id))
5378 = Etype (Next_Formal (First_Formal (Id)))
5379 or else Chars (Prev) = Name_Op_Expon)
5381 goto Next_Usable_Entity;
5384 Prev := Homonym (Prev);
5387 -- On exit, we know entity is not hidden, unless it is private.
5389 if not Is_Hidden (Id)
5390 and then ((not Is_Child_Unit (Id))
5391 or else Is_Visible_Child_Unit (Id))
5393 Set_Is_Potentially_Use_Visible (Id);
5395 if Is_Private_Type (Id)
5396 and then Present (Full_View (Id))
5398 Set_Is_Potentially_Use_Visible (Full_View (Id));
5402 <<Next_Usable_Entity>>
5406 -- Child units are also made use-visible by a use clause, but they
5407 -- may appear after all visible declarations in the parent entity list.
5409 while Present (Id) loop
5411 if Is_Child_Unit (Id)
5412 and then Is_Visible_Child_Unit (Id)
5414 Set_Is_Potentially_Use_Visible (Id);
5420 if Chars (Real_P) = Name_System
5421 and then Scope (Real_P) = Standard_Standard
5422 and then Present_System_Aux (N)
5424 Use_One_Package (System_Aux_Id, N);
5427 end Use_One_Package;
5433 procedure Use_One_Type (Id : Node_Id) is
5439 -- It is the type determined by the subtype mark (8.4(8)) whose
5440 -- operations become potentially use-visible.
5442 T := Base_Type (Entity (Id));
5447 or else Is_Potentially_Use_Visible (T)
5448 or else In_Use (Scope (T)));
5450 if In_Open_Scopes (Scope (T)) then
5453 -- If the subtype mark designates a subtype in a different package,
5454 -- we have to check that the parent type is visible, otherwise the
5455 -- use type clause is a noop. Not clear how to do that???
5457 elsif not Redundant_Use (Id) then
5459 Op_List := Collect_Primitive_Operations (T);
5460 Elmt := First_Elmt (Op_List);
5462 while Present (Elmt) loop
5464 if (Nkind (Node (Elmt)) = N_Defining_Operator_Symbol
5465 or else Chars (Node (Elmt)) in Any_Operator_Name)
5466 and then not Is_Hidden (Node (Elmt))
5468 Set_Is_Potentially_Use_Visible (Node (Elmt));
5480 procedure Write_Info is
5481 Id : Entity_Id := First_Entity (Current_Scope);
5484 -- No point in dumping standard entities
5486 if Current_Scope = Standard_Standard then
5490 Write_Str ("========================================================");
5492 Write_Str (" Defined Entities in ");
5493 Write_Name (Chars (Current_Scope));
5495 Write_Str ("========================================================");
5499 Write_Str ("-- none --");
5503 while Present (Id) loop
5504 Write_Entity_Info (Id, " ");
5509 if Scope (Current_Scope) = Standard_Standard then
5511 -- Print information on the current unit itself
5513 Write_Entity_Info (Current_Scope, " ");
5523 procedure Write_Scopes is
5527 for J in reverse 1 .. Scope_Stack.Last loop
5528 S := Scope_Stack.Table (J).Entity;
5529 Write_Int (Int (S));
5530 Write_Str (" === ");
5531 Write_Name (Chars (S));