]>
Commit | Line | Data |
---|---|---|
996ae0b0 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
d4129bfa | 5 | -- S E M _ C H 8 -- |
996ae0b0 RK |
6 | -- -- |
7 | -- B o d y -- | |
8 | -- -- | |
522aa6ee | 9 | -- Copyright (C) 1992-2017, Free Software Foundation, Inc. -- |
996ae0b0 RK |
10 | -- -- |
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- -- | |
b5c84c3c | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
996ae0b0 RK |
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 -- | |
b5c84c3c RD |
18 | -- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
19 | -- http://www.gnu.org/licenses for a complete copy of the license. -- | |
996ae0b0 RK |
20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
996ae0b0 RK |
23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
26 | with Atree; use Atree; | |
27 | with Debug; use Debug; | |
28 | with Einfo; use Einfo; | |
29 | with Elists; use Elists; | |
30 | with Errout; use Errout; | |
024d33d8 | 31 | with Exp_Disp; use Exp_Disp; |
d239991f | 32 | with Exp_Tss; use Exp_Tss; |
996ae0b0 | 33 | with Exp_Util; use Exp_Util; |
996ae0b0 | 34 | with Freeze; use Freeze; |
8636f52f | 35 | with Ghost; use Ghost; |
16ca248a | 36 | with Impunit; use Impunit; |
996ae0b0 RK |
37 | with Lib; use Lib; |
38 | with Lib.Load; use Lib.Load; | |
39 | with Lib.Xref; use Lib.Xref; | |
40 | with Namet; use Namet; | |
294ccb21 | 41 | with Namet.Sp; use Namet.Sp; |
996ae0b0 RK |
42 | with Nlists; use Nlists; |
43 | with Nmake; use Nmake; | |
44 | with Opt; use Opt; | |
45 | with Output; use Output; | |
46 | with Restrict; use Restrict; | |
6e937c1c | 47 | with Rident; use Rident; |
996ae0b0 RK |
48 | with Rtsfind; use Rtsfind; |
49 | with Sem; use Sem; | |
a4100e55 | 50 | with Sem_Aux; use Sem_Aux; |
fbf5a39b | 51 | with Sem_Cat; use Sem_Cat; |
996ae0b0 RK |
52 | with Sem_Ch3; use Sem_Ch3; |
53 | with Sem_Ch4; use Sem_Ch4; | |
54 | with Sem_Ch6; use Sem_Ch6; | |
55 | with Sem_Ch12; use Sem_Ch12; | |
ef992452 | 56 | with Sem_Ch13; use Sem_Ch13; |
dec6faf1 | 57 | with Sem_Dim; use Sem_Dim; |
82c80734 | 58 | with Sem_Disp; use Sem_Disp; |
a77842bd | 59 | with Sem_Dist; use Sem_Dist; |
90e491a7 | 60 | with Sem_Elab; use Sem_Elab; |
a2dc5812 | 61 | with Sem_Eval; use Sem_Eval; |
996ae0b0 RK |
62 | with Sem_Res; use Sem_Res; |
63 | with Sem_Util; use Sem_Util; | |
64 | with Sem_Type; use Sem_Type; | |
65 | with Stand; use Stand; | |
66 | with Sinfo; use Sinfo; | |
67 | with Sinfo.CN; use Sinfo.CN; | |
68 | with Snames; use Snames; | |
851e9f19 | 69 | with Style; |
996ae0b0 RK |
70 | with Table; |
71 | with Tbuild; use Tbuild; | |
72 | with Uintp; use Uintp; | |
73 | ||
996ae0b0 RK |
74 | package body Sem_Ch8 is |
75 | ||
76 | ------------------------------------ | |
77 | -- Visibility and Name Resolution -- | |
78 | ------------------------------------ | |
79 | ||
2c1b72d7 | 80 | -- This package handles name resolution and the collection of possible |
996ae0b0 RK |
81 | -- interpretations for overloaded names, prior to overload resolution. |
82 | ||
83 | -- Name resolution is the process that establishes a mapping between source | |
84 | -- identifiers and the entities they denote at each point in the program. | |
85 | -- Each entity is represented by a defining occurrence. Each identifier | |
86 | -- that denotes an entity points to the corresponding defining occurrence. | |
87 | -- This is the entity of the applied occurrence. Each occurrence holds | |
88 | -- an index into the names table, where source identifiers are stored. | |
89 | ||
90 | -- Each entry in the names table for an identifier or designator uses the | |
91 | -- Info pointer to hold a link to the currently visible entity that has | |
92 | -- this name (see subprograms Get_Name_Entity_Id and Set_Name_Entity_Id | |
93 | -- in package Sem_Util). The visibility is initialized at the beginning of | |
94 | -- semantic processing to make entities in package Standard immediately | |
95 | -- visible. The visibility table is used in a more subtle way when | |
96 | -- compiling subunits (see below). | |
97 | ||
98 | -- Entities that have the same name (i.e. homonyms) are chained. In the | |
99 | -- case of overloaded entities, this chain holds all the possible meanings | |
100 | -- of a given identifier. The process of overload resolution uses type | |
101 | -- information to select from this chain the unique meaning of a given | |
102 | -- identifier. | |
103 | ||
104 | -- Entities are also chained in their scope, through the Next_Entity link. | |
105 | -- As a consequence, the name space is organized as a sparse matrix, where | |
106 | -- each row corresponds to a scope, and each column to a source identifier. | |
107 | -- Open scopes, that is to say scopes currently being compiled, have their | |
108 | -- corresponding rows of entities in order, innermost scope first. | |
109 | ||
21d7ef70 | 110 | -- The scopes of packages that are mentioned in context clauses appear in |
996ae0b0 RK |
111 | -- no particular order, interspersed among open scopes. This is because |
112 | -- in the course of analyzing the context of a compilation, a package | |
113 | -- declaration is first an open scope, and subsequently an element of the | |
114 | -- context. If subunits or child units are present, a parent unit may | |
115 | -- appear under various guises at various times in the compilation. | |
116 | ||
117 | -- When the compilation of the innermost scope is complete, the entities | |
118 | -- defined therein are no longer visible. If the scope is not a package | |
119 | -- declaration, these entities are never visible subsequently, and can be | |
120 | -- removed from visibility chains. If the scope is a package declaration, | |
121 | -- its visible declarations may still be accessible. Therefore the entities | |
122 | -- defined in such a scope are left on the visibility chains, and only | |
123 | -- their visibility (immediately visibility or potential use-visibility) | |
124 | -- is affected. | |
125 | ||
126 | -- The ordering of homonyms on their chain does not necessarily follow | |
127 | -- the order of their corresponding scopes on the scope stack. For | |
128 | -- example, if package P and the enclosing scope both contain entities | |
129 | -- named E, then when compiling the package body the chain for E will | |
130 | -- hold the global entity first, and the local one (corresponding to | |
131 | -- the current inner scope) next. As a result, name resolution routines | |
132 | -- do not assume any relative ordering of the homonym chains, either | |
133 | -- for scope nesting or to order of appearance of context clauses. | |
134 | ||
135 | -- When compiling a child unit, entities in the parent scope are always | |
136 | -- immediately visible. When compiling the body of a child unit, private | |
137 | -- entities in the parent must also be made immediately visible. There | |
138 | -- are separate routines to make the visible and private declarations | |
139 | -- visible at various times (see package Sem_Ch7). | |
140 | ||
141 | -- +--------+ +-----+ | |
142 | -- | In use |-------->| EU1 |--------------------------> | |
143 | -- +--------+ +-----+ | |
144 | -- | | | |
145 | -- +--------+ +-----+ +-----+ | |
146 | -- | Stand. |---------------->| ES1 |--------------->| ES2 |---> | |
147 | -- +--------+ +-----+ +-----+ | |
148 | -- | | | |
149 | -- +---------+ | +-----+ | |
150 | -- | with'ed |------------------------------>| EW2 |---> | |
151 | -- +---------+ | +-----+ | |
152 | -- | | | |
153 | -- +--------+ +-----+ +-----+ | |
154 | -- | Scope2 |---------------->| E12 |--------------->| E22 |---> | |
155 | -- +--------+ +-----+ +-----+ | |
156 | -- | | | |
157 | -- +--------+ +-----+ +-----+ | |
158 | -- | Scope1 |---------------->| E11 |--------------->| E12 |---> | |
159 | -- +--------+ +-----+ +-----+ | |
160 | -- ^ | | | |
161 | -- | | | | |
162 | -- | +---------+ | | | |
163 | -- | | with'ed |-----------------------------------------> | |
164 | -- | +---------+ | | | |
165 | -- | | | | |
166 | -- Scope stack | | | |
167 | -- (innermost first) | | | |
168 | -- +----------------------------+ | |
169 | -- Names table => | Id1 | | | | Id2 | | |
170 | -- +----------------------------+ | |
171 | ||
172 | -- Name resolution must deal with several syntactic forms: simple names, | |
173 | -- qualified names, indexed names, and various forms of calls. | |
174 | ||
175 | -- Each identifier points to an entry in the names table. The resolution | |
176 | -- of a simple name consists in traversing the homonym chain, starting | |
177 | -- from the names table. If an entry is immediately visible, it is the one | |
fbf5a39b | 178 | -- designated by the identifier. If only potentially use-visible entities |
996ae0b0 RK |
179 | -- are on the chain, we must verify that they do not hide each other. If |
180 | -- the entity we find is overloadable, we collect all other overloadable | |
181 | -- entities on the chain as long as they are not hidden. | |
182 | -- | |
183 | -- To resolve expanded names, we must find the entity at the intersection | |
184 | -- of the entity chain for the scope (the prefix) and the homonym chain | |
185 | -- for the selector. In general, homonym chains will be much shorter than | |
186 | -- entity chains, so it is preferable to start from the names table as | |
187 | -- well. If the entity found is overloadable, we must collect all other | |
188 | -- interpretations that are defined in the scope denoted by the prefix. | |
189 | ||
190 | -- For records, protected types, and tasks, their local entities are | |
191 | -- removed from visibility chains on exit from the corresponding scope. | |
192 | -- From the outside, these entities are always accessed by selected | |
193 | -- notation, and the entity chain for the record type, protected type, | |
21d7ef70 | 194 | -- etc. is traversed sequentially in order to find the designated entity. |
996ae0b0 RK |
195 | |
196 | -- The discriminants of a type and the operations of a protected type or | |
197 | -- task are unchained on exit from the first view of the type, (such as | |
198 | -- a private or incomplete type declaration, or a protected type speci- | |
fbf5a39b | 199 | -- fication) and re-chained when compiling the second view. |
996ae0b0 RK |
200 | |
201 | -- In the case of operators, we do not make operators on derived types | |
202 | -- explicit. As a result, the notation P."+" may denote either a user- | |
203 | -- defined function with name "+", or else an implicit declaration of the | |
204 | -- operator "+" in package P. The resolution of expanded names always | |
205 | -- tries to resolve an operator name as such an implicitly defined entity, | |
206 | -- in addition to looking for explicit declarations. | |
207 | ||
208 | -- All forms of names that denote entities (simple names, expanded names, | |
209 | -- character literals in some cases) have a Entity attribute, which | |
210 | -- identifies the entity denoted by the name. | |
211 | ||
212 | --------------------- | |
213 | -- The Scope Stack -- | |
214 | --------------------- | |
215 | ||
216 | -- The Scope stack keeps track of the scopes currently been compiled. | |
217 | -- Every entity that contains declarations (including records) is placed | |
218 | -- on the scope stack while it is being processed, and removed at the end. | |
219 | -- Whenever a non-package scope is exited, the entities defined therein | |
220 | -- are removed from the visibility table, so that entities in outer scopes | |
221 | -- become visible (see previous description). On entry to Sem, the scope | |
222 | -- stack only contains the package Standard. As usual, subunits complicate | |
223 | -- this picture ever so slightly. | |
224 | ||
225 | -- The Rtsfind mechanism can force a call to Semantics while another | |
226 | -- compilation is in progress. The unit retrieved by Rtsfind must be | |
21d7ef70 | 227 | -- compiled in its own context, and has no access to the visibility of |
996ae0b0 RK |
228 | -- the unit currently being compiled. The procedures Save_Scope_Stack and |
229 | -- Restore_Scope_Stack make entities in current open scopes invisible | |
230 | -- before compiling the retrieved unit, and restore the compilation | |
231 | -- environment afterwards. | |
232 | ||
233 | ------------------------ | |
234 | -- Compiling subunits -- | |
235 | ------------------------ | |
236 | ||
16ca248a ES |
237 | -- Subunits must be compiled in the environment of the corresponding stub, |
238 | -- that is to say with the same visibility into the parent (and its | |
996ae0b0 RK |
239 | -- context) that is available at the point of the stub declaration, but |
240 | -- with the additional visibility provided by the context clause of the | |
241 | -- subunit itself. As a result, compilation of a subunit forces compilation | |
242 | -- of the parent (see description in lib-). At the point of the stub | |
16ca248a ES |
243 | -- declaration, Analyze is called recursively to compile the proper body of |
244 | -- the subunit, but without reinitializing the names table, nor the scope | |
245 | -- stack (i.e. standard is not pushed on the stack). In this fashion the | |
246 | -- context of the subunit is added to the context of the parent, and the | |
247 | -- subunit is compiled in the correct environment. Note that in the course | |
248 | -- of processing the context of a subunit, Standard will appear twice on | |
249 | -- the scope stack: once for the parent of the subunit, and once for the | |
250 | -- unit in the context clause being compiled. However, the two sets of | |
251 | -- entities are not linked by homonym chains, so that the compilation of | |
252 | -- any context unit happens in a fresh visibility environment. | |
996ae0b0 RK |
253 | |
254 | ------------------------------- | |
255 | -- Processing of USE Clauses -- | |
256 | ------------------------------- | |
257 | ||
258 | -- Every defining occurrence has a flag indicating if it is potentially use | |
259 | -- visible. Resolution of simple names examines this flag. The processing | |
260 | -- of use clauses consists in setting this flag on all visible entities | |
261 | -- defined in the corresponding package. On exit from the scope of the use | |
262 | -- clause, the corresponding flag must be reset. However, a package may | |
a90bd866 | 263 | -- appear in several nested use clauses (pathological but legal, alas) |
996ae0b0 RK |
264 | -- which forces us to use a slightly more involved scheme: |
265 | ||
266 | -- a) The defining occurrence for a package holds a flag -In_Use- to | |
267 | -- indicate that it is currently in the scope of a use clause. If a | |
44d6a706 | 268 | -- redundant use clause is encountered, then the corresponding occurrence |
996ae0b0 RK |
269 | -- of the package name is flagged -Redundant_Use-. |
270 | ||
271 | -- b) On exit from a scope, the use clauses in its declarative part are | |
272 | -- scanned. The visibility flag is reset in all entities declared in | |
273 | -- package named in a use clause, as long as the package is not flagged | |
274 | -- as being in a redundant use clause (in which case the outer use | |
275 | -- clause is still in effect, and the direct visibility of its entities | |
276 | -- must be retained). | |
277 | ||
278 | -- Note that entities are not removed from their homonym chains on exit | |
279 | -- from the package specification. A subsequent use clause does not need | |
280 | -- to rechain the visible entities, but only to establish their direct | |
281 | -- visibility. | |
282 | ||
283 | ----------------------------------- | |
284 | -- Handling private declarations -- | |
285 | ----------------------------------- | |
286 | ||
287 | -- The principle that each entity has a single defining occurrence clashes | |
288 | -- with the presence of two separate definitions for private types: the | |
289 | -- first is the private type declaration, and second is the full type | |
290 | -- declaration. It is important that all references to the type point to | |
44d6a706 | 291 | -- the same defining occurrence, namely the first one. To enforce the two |
996ae0b0 RK |
292 | -- separate views of the entity, the corresponding information is swapped |
293 | -- between the two declarations. Outside of the package, the defining | |
44d6a706 | 294 | -- occurrence only contains the private declaration information, while in |
996ae0b0 RK |
295 | -- the private part and the body of the package the defining occurrence |
296 | -- contains the full declaration. To simplify the swap, the defining | |
297 | -- occurrence that currently holds the private declaration points to the | |
44d6a706 | 298 | -- full declaration. During semantic processing the defining occurrence |
16ca248a ES |
299 | -- also points to a list of private dependents, that is to say access types |
300 | -- or composite types whose designated types or component types are | |
996ae0b0 RK |
301 | -- subtypes or derived types of the private type in question. After the |
302 | -- full declaration has been seen, the private dependents are updated to | |
303 | -- indicate that they have full definitions. | |
304 | ||
305 | ------------------------------------ | |
306 | -- Handling of Undefined Messages -- | |
307 | ------------------------------------ | |
308 | ||
309 | -- In normal mode, only the first use of an undefined identifier generates | |
310 | -- a message. The table Urefs is used to record error messages that have | |
311 | -- been issued so that second and subsequent ones do not generate further | |
312 | -- messages. However, the second reference causes text to be added to the | |
313 | -- original undefined message noting "(more references follow)". The | |
314 | -- full error list option (-gnatf) forces messages to be generated for | |
315 | -- every reference and disconnects the use of this table. | |
316 | ||
317 | type Uref_Entry is record | |
318 | Node : Node_Id; | |
319 | -- Node for identifier for which original message was posted. The | |
320 | -- Chars field of this identifier is used to detect later references | |
321 | -- to the same identifier. | |
322 | ||
323 | Err : Error_Msg_Id; | |
324 | -- Records error message Id of original undefined message. Reset to | |
325 | -- No_Error_Msg after the second occurrence, where it is used to add | |
326 | -- text to the original message as described above. | |
327 | ||
328 | Nvis : Boolean; | |
329 | -- Set if the message is not visible rather than undefined | |
330 | ||
331 | Loc : Source_Ptr; | |
332 | -- Records location of error message. Used to make sure that we do | |
333 | -- not consider a, b : undefined as two separate instances, which | |
334 | -- would otherwise happen, since the parser converts this sequence | |
335 | -- to a : undefined; b : undefined. | |
336 | ||
337 | end record; | |
338 | ||
339 | package Urefs is new Table.Table ( | |
340 | Table_Component_Type => Uref_Entry, | |
341 | Table_Index_Type => Nat, | |
342 | Table_Low_Bound => 1, | |
343 | Table_Initial => 10, | |
344 | Table_Increment => 100, | |
345 | Table_Name => "Urefs"); | |
346 | ||
347 | Candidate_Renaming : Entity_Id; | |
348 | -- Holds a candidate interpretation that appears in a subprogram renaming | |
349 | -- declaration and does not match the given specification, but matches at | |
350 | -- least on the first formal. Allows better error message when given | |
351 | -- specification omits defaulted parameters, a common error. | |
352 | ||
353 | ----------------------- | |
354 | -- Local Subprograms -- | |
355 | ----------------------- | |
356 | ||
357 | procedure Analyze_Generic_Renaming | |
358 | (N : Node_Id; | |
359 | K : Entity_Kind); | |
360 | -- Common processing for all three kinds of generic renaming declarations. | |
361 | -- Enter new name and indicate that it renames the generic unit. | |
362 | ||
363 | procedure Analyze_Renamed_Character | |
364 | (N : Node_Id; | |
365 | New_S : Entity_Id; | |
366 | Is_Body : Boolean); | |
367 | -- Renamed entity is given by a character literal, which must belong | |
368 | -- to the return type of the new entity. Is_Body indicates whether the | |
369 | -- declaration is a renaming_as_body. If the original declaration has | |
370 | -- already been frozen (because of an intervening body, e.g.) the body of | |
371 | -- the function must be built now. The same applies to the following | |
372 | -- various renaming procedures. | |
373 | ||
374 | procedure Analyze_Renamed_Dereference | |
375 | (N : Node_Id; | |
376 | New_S : Entity_Id; | |
377 | Is_Body : Boolean); | |
378 | -- Renamed entity is given by an explicit dereference. Prefix must be a | |
379 | -- conformant access_to_subprogram type. | |
380 | ||
381 | procedure Analyze_Renamed_Entry | |
382 | (N : Node_Id; | |
383 | New_S : Entity_Id; | |
384 | Is_Body : Boolean); | |
385 | -- If the renamed entity in a subprogram renaming is an entry or protected | |
386 | -- subprogram, build a body for the new entity whose only statement is a | |
387 | -- call to the renamed entity. | |
388 | ||
389 | procedure Analyze_Renamed_Family_Member | |
390 | (N : Node_Id; | |
391 | New_S : Entity_Id; | |
392 | Is_Body : Boolean); | |
393 | -- Used when the renamed entity is an indexed component. The prefix must | |
394 | -- denote an entry family. | |
395 | ||
294ccb21 RD |
396 | procedure Analyze_Renamed_Primitive_Operation |
397 | (N : Node_Id; | |
398 | New_S : Entity_Id; | |
399 | Is_Body : Boolean); | |
400 | -- If the renamed entity in a subprogram renaming is a primitive operation | |
c5d00db0 AC |
401 | -- or a class-wide operation in prefix form, save the target object, |
402 | -- which must be added to the list of actuals in any subsequent call. | |
403 | -- The renaming operation is intrinsic because the compiler must in | |
404 | -- fact generate a wrapper for it (6.3.1 (10 1/2)). | |
294ccb21 | 405 | |
996ae0b0 | 406 | procedure Attribute_Renaming (N : Node_Id); |
4c8a5bb8 AC |
407 | -- Analyze renaming of attribute as subprogram. The renaming declaration N |
408 | -- is rewritten as a subprogram body that returns the attribute reference | |
996ae0b0 RK |
409 | -- applied to the formals of the function. |
410 | ||
4c484f40 | 411 | procedure Set_Entity_Or_Discriminal (N : Node_Id; E : Entity_Id); |
c42bfef2 RD |
412 | -- Set Entity, with style check if need be. For a discriminant reference, |
413 | -- replace by the corresponding discriminal, i.e. the parameter of the | |
414 | -- initialization procedure that corresponds to the discriminant. | |
4c484f40 | 415 | |
996ae0b0 RK |
416 | procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id); |
417 | -- A renaming_as_body may occur after the entity of the original decla- | |
418 | -- ration has been frozen. In that case, the body of the new entity must | |
419 | -- be built now, because the usual mechanism of building the renamed | |
420 | -- body at the point of freezing will not work. Subp is the subprogram | |
421 | -- for which N provides the Renaming_As_Body. | |
422 | ||
fbf5a39b AC |
423 | procedure Check_In_Previous_With_Clause |
424 | (N : Node_Id; | |
425 | Nam : Node_Id); | |
426 | -- N is a use_package clause and Nam the package name, or N is a use_type | |
427 | -- clause and Nam is the prefix of the type name. In either case, verify | |
428 | -- that the package is visible at that point in the context: either it | |
429 | -- appears in a previous with_clause, or because it is a fully qualified | |
430 | -- name and the root ancestor appears in a previous with_clause. | |
431 | ||
996ae0b0 RK |
432 | procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id); |
433 | -- Verify that the entity in a renaming declaration that is a library unit | |
434 | -- is itself a library unit and not a nested unit or subunit. Also check | |
435 | -- that if the renaming is a child unit of a generic parent, then the | |
436 | -- renamed unit must also be a child unit of that parent. Finally, verify | |
437 | -- that a renamed generic unit is not an implicit child declared within | |
438 | -- an instance of the parent. | |
439 | ||
440 | procedure Chain_Use_Clause (N : Node_Id); | |
d4810530 ES |
441 | -- Chain use clause onto list of uses clauses headed by First_Use_Clause in |
442 | -- the proper scope table entry. This is usually the current scope, but it | |
443 | -- will be an inner scope when installing the use clauses of the private | |
444 | -- declarations of a parent unit prior to compiling the private part of a | |
445 | -- child unit. This chain is traversed when installing/removing use clauses | |
446 | -- when compiling a subunit or instantiating a generic body on the fly, | |
447 | -- when it is necessary to save and restore full environments. | |
996ae0b0 | 448 | |
ac7d724d ES |
449 | function Enclosing_Instance return Entity_Id; |
450 | -- In an instance nested within another one, several semantic checks are | |
451 | -- unnecessary because the legality of the nested instance has been checked | |
452 | -- in the enclosing generic unit. This applies in particular to legality | |
453 | -- checks on actuals for formal subprograms of the inner instance, which | |
454 | -- are checked as subprogram renamings, and may be complicated by confusion | |
455 | -- in private/full views. This function returns the instance enclosing the | |
456 | -- current one if there is such, else it returns Empty. | |
457 | -- | |
458 | -- If the renaming determines the entity for the default of a formal | |
459 | -- subprogram nested within another instance, choose the innermost | |
460 | -- candidate. This is because if the formal has a box, and we are within | |
461 | -- an enclosing instance where some candidate interpretations are local | |
462 | -- to this enclosing instance, we know that the default was properly | |
463 | -- resolved when analyzing the generic, so we prefer the local | |
464 | -- candidates to those that are external. This is not always the case | |
465 | -- but is a reasonable heuristic on the use of nested generics. The | |
466 | -- proper solution requires a full renaming model. | |
467 | ||
851e9f19 PMR |
468 | function Entity_Of_Unit (U : Node_Id) return Entity_Id; |
469 | -- Return the appropriate entity for determining which unit has a deeper | |
470 | -- scope: the defining entity for U, unless U is a package instance, in | |
471 | -- which case we retrieve the entity of the instance spec. | |
9bc856dd | 472 | |
fbf5a39b | 473 | procedure Find_Expanded_Name (N : Node_Id); |
1d801f21 | 474 | -- The input is a selected component known to be an expanded name. Verify |
30196a76 RD |
475 | -- legality of selector given the scope denoted by prefix, and change node |
476 | -- N into a expanded name with a properly set Entity field. | |
fbf5a39b | 477 | |
851e9f19 PMR |
478 | function Find_Most_Prev (Use_Clause : Node_Id) return Node_Id; |
479 | -- Find the most previous use clause (that is, the first one to appear in | |
480 | -- the source) by traversing the previous clause chain that exists in both | |
481 | -- N_Use_Package_Clause nodes and N_Use_Type_Clause nodes. | |
7f5e671b | 482 | -- ??? a better subprogram name is in order |
851e9f19 | 483 | |
996ae0b0 RK |
484 | function Find_Renamed_Entity |
485 | (N : Node_Id; | |
486 | Nam : Node_Id; | |
487 | New_S : Entity_Id; | |
488 | Is_Actual : Boolean := False) return Entity_Id; | |
489 | -- Find the renamed entity that corresponds to the given parameter profile | |
490 | -- in a subprogram renaming declaration. The renamed entity may be an | |
491 | -- operator, a subprogram, an entry, or a protected operation. Is_Actual | |
492 | -- indicates that the renaming is the one generated for an actual subpro- | |
493 | -- gram in an instance, for which special visibility checks apply. | |
494 | ||
851e9f19 PMR |
495 | function Has_Implicit_Character_Literal (N : Node_Id) return Boolean; |
496 | -- Find a type derived from Character or Wide_Character in the prefix of N. | |
497 | -- Used to resolved qualified names whose selector is a character literal. | |
498 | ||
499 | function Has_Private_With (E : Entity_Id) return Boolean; | |
500 | -- Ada 2005 (AI-262): Determines if the current compilation unit has a | |
501 | -- private with on E. | |
502 | ||
fbf5a39b | 503 | function Has_Implicit_Operator (N : Node_Id) return Boolean; |
f3d57416 | 504 | -- N is an expanded name whose selector is an operator name (e.g. P."+"). |
16ca248a ES |
505 | -- declarative part contains an implicit declaration of an operator if it |
506 | -- has a declaration of a type to which one of the predefined operators | |
507 | -- apply. The existence of this routine is an implementation artifact. A | |
508 | -- more straightforward but more space-consuming choice would be to make | |
509 | -- all inherited operators explicit in the symbol table. | |
fbf5a39b | 510 | |
996ae0b0 RK |
511 | procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id); |
512 | -- A subprogram defined by a renaming declaration inherits the parameter | |
513 | -- profile of the renamed entity. The subtypes given in the subprogram | |
514 | -- specification are discarded and replaced with those of the renamed | |
515 | -- subprogram, which are then used to recheck the default values. | |
516 | ||
fbf5a39b | 517 | function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean; |
16ca248a ES |
518 | -- True if it is of a task type, a protected type, or else an access to one |
519 | -- of these types. | |
fbf5a39b | 520 | |
851e9f19 PMR |
521 | function Is_Appropriate_For_Record (T : Entity_Id) return Boolean; |
522 | -- Prefix is appropriate for record if it is of a record type, or an access | |
523 | -- to such. | |
524 | ||
525 | function Most_Descendant_Use_Clause | |
526 | (Clause1 : Entity_Id; | |
527 | Clause2 : Entity_Id) return Entity_Id; | |
528 | -- Determine which use clause parameter is the most descendant in terms of | |
529 | -- scope. | |
7f5e671b | 530 | -- ??? a better subprogram name is in order |
d4810530 | 531 | |
996ae0b0 | 532 | procedure Premature_Usage (N : Node_Id); |
bc41faa2 | 533 | -- Diagnose usage of an entity before it is visible |
996ae0b0 | 534 | |
851e9f19 | 535 | procedure Use_One_Package |
7f5e671b PMR |
536 | (N : Node_Id; |
537 | Pack_Name : Entity_Id := Empty; | |
538 | Force : Boolean := False); | |
fbf5a39b AC |
539 | -- Make visible entities declared in package P potentially use-visible |
540 | -- in the current context. Also used in the analysis of subunits, when | |
541 | -- re-installing use clauses of parent units. N is the use_clause that | |
542 | -- names P (and possibly other packages). | |
543 | ||
851e9f19 | 544 | procedure Use_One_Type |
7f5e671b PMR |
545 | (Id : Node_Id; |
546 | Installed : Boolean := False; | |
547 | Force : Boolean := False); | |
851e9f19 | 548 | -- Id is the subtype mark from a use_type_clause. This procedure makes |
7ff2d234 AC |
549 | -- the primitive operators of the type potentially use-visible. The |
550 | -- boolean flag Installed indicates that the clause is being reinstalled | |
551 | -- after previous analysis, and primitive operations are already chained | |
552 | -- on the Used_Operations list of the clause. | |
fbf5a39b | 553 | |
996ae0b0 RK |
554 | procedure Write_Info; |
555 | -- Write debugging information on entities declared in current scope | |
556 | ||
996ae0b0 RK |
557 | -------------------------------- |
558 | -- Analyze_Exception_Renaming -- | |
559 | -------------------------------- | |
560 | ||
16ca248a ES |
561 | -- The language only allows a single identifier, but the tree holds an |
562 | -- identifier list. The parser has already issued an error message if | |
563 | -- there is more than one element in the list. | |
996ae0b0 RK |
564 | |
565 | procedure Analyze_Exception_Renaming (N : Node_Id) is | |
1af4455a HK |
566 | Id : constant Entity_Id := Defining_Entity (N); |
567 | Nam : constant Node_Id := Name (N); | |
996ae0b0 RK |
568 | |
569 | begin | |
ce5ba43a | 570 | Check_SPARK_05_Restriction ("exception renaming is not allowed", N); |
1d801f21 | 571 | |
996ae0b0 RK |
572 | Enter_Name (Id); |
573 | Analyze (Nam); | |
574 | ||
241ebe89 HK |
575 | Set_Ekind (Id, E_Exception); |
576 | Set_Etype (Id, Standard_Exception_Type); | |
577 | Set_Is_Pure (Id, Is_Pure (Current_Scope)); | |
996ae0b0 | 578 | |
241ebe89 HK |
579 | if Is_Entity_Name (Nam) |
580 | and then Present (Entity (Nam)) | |
581 | and then Ekind (Entity (Nam)) = E_Exception | |
996ae0b0 | 582 | then |
996ae0b0 RK |
583 | if Present (Renamed_Object (Entity (Nam))) then |
584 | Set_Renamed_Object (Id, Renamed_Object (Entity (Nam))); | |
585 | else | |
586 | Set_Renamed_Object (Id, Entity (Nam)); | |
587 | end if; | |
c5cec2fe | 588 | |
241ebe89 HK |
589 | -- The exception renaming declaration may become Ghost if it renames |
590 | -- a Ghost entity. | |
c5cec2fe | 591 | |
d65a80fd | 592 | Mark_Ghost_Renaming (N, Entity (Nam)); |
241ebe89 HK |
593 | else |
594 | Error_Msg_N ("invalid exception name in renaming", Nam); | |
996ae0b0 | 595 | end if; |
42f1d661 AC |
596 | |
597 | -- Implementation-defined aspect specifications can appear in a renaming | |
598 | -- declaration, but not language-defined ones. The call to procedure | |
599 | -- Analyze_Aspect_Specifications will take care of this error check. | |
600 | ||
601 | if Has_Aspects (N) then | |
602 | Analyze_Aspect_Specifications (N, Id); | |
603 | end if; | |
996ae0b0 RK |
604 | end Analyze_Exception_Renaming; |
605 | ||
606 | --------------------------- | |
607 | -- Analyze_Expanded_Name -- | |
608 | --------------------------- | |
609 | ||
610 | procedure Analyze_Expanded_Name (N : Node_Id) is | |
611 | begin | |
16ca248a ES |
612 | -- If the entity pointer is already set, this is an internal node, or a |
613 | -- node that is analyzed more than once, after a tree modification. In | |
cdabbb52 HK |
614 | -- such a case there is no resolution to perform, just set the type. In |
615 | -- either case, start by analyzing the prefix. | |
f6f40114 AC |
616 | |
617 | Analyze (Prefix (N)); | |
996ae0b0 RK |
618 | |
619 | if Present (Entity (N)) then | |
620 | if Is_Type (Entity (N)) then | |
621 | Set_Etype (N, Entity (N)); | |
622 | else | |
623 | Set_Etype (N, Etype (Entity (N))); | |
624 | end if; | |
625 | ||
996ae0b0 RK |
626 | else |
627 | Find_Expanded_Name (N); | |
628 | end if; | |
0929eaeb | 629 | |
b5f3c913 AC |
630 | -- In either case, propagate dimension of entity to expanded name |
631 | ||
0929eaeb | 632 | Analyze_Dimension (N); |
996ae0b0 RK |
633 | end Analyze_Expanded_Name; |
634 | ||
15ce9ca2 AC |
635 | --------------------------------------- |
636 | -- Analyze_Generic_Function_Renaming -- | |
637 | --------------------------------------- | |
996ae0b0 RK |
638 | |
639 | procedure Analyze_Generic_Function_Renaming (N : Node_Id) is | |
640 | begin | |
641 | Analyze_Generic_Renaming (N, E_Generic_Function); | |
642 | end Analyze_Generic_Function_Renaming; | |
643 | ||
15ce9ca2 AC |
644 | -------------------------------------- |
645 | -- Analyze_Generic_Package_Renaming -- | |
646 | -------------------------------------- | |
996ae0b0 RK |
647 | |
648 | procedure Analyze_Generic_Package_Renaming (N : Node_Id) is | |
649 | begin | |
e80f0cb0 RD |
650 | -- Test for the Text_IO special unit case here, since we may be renaming |
651 | -- one of the subpackages of Text_IO, then join common routine. | |
996ae0b0 | 652 | |
2bd67690 | 653 | Check_Text_IO_Special_Unit (Name (N)); |
996ae0b0 RK |
654 | |
655 | Analyze_Generic_Renaming (N, E_Generic_Package); | |
656 | end Analyze_Generic_Package_Renaming; | |
657 | ||
15ce9ca2 AC |
658 | ---------------------------------------- |
659 | -- Analyze_Generic_Procedure_Renaming -- | |
660 | ---------------------------------------- | |
996ae0b0 RK |
661 | |
662 | procedure Analyze_Generic_Procedure_Renaming (N : Node_Id) is | |
663 | begin | |
664 | Analyze_Generic_Renaming (N, E_Generic_Procedure); | |
665 | end Analyze_Generic_Procedure_Renaming; | |
666 | ||
667 | ------------------------------ | |
668 | -- Analyze_Generic_Renaming -- | |
669 | ------------------------------ | |
670 | ||
671 | procedure Analyze_Generic_Renaming | |
672 | (N : Node_Id; | |
673 | K : Entity_Kind) | |
674 | is | |
1af4455a | 675 | New_P : constant Entity_Id := Defining_Entity (N); |
ad4ba28b | 676 | Inst : Boolean := False; |
d65a80fd | 677 | Old_P : Entity_Id; |
996ae0b0 RK |
678 | |
679 | begin | |
ed4a1468 RD |
680 | if Name (N) = Error then |
681 | return; | |
682 | end if; | |
683 | ||
ce5ba43a | 684 | Check_SPARK_05_Restriction ("generic renaming is not allowed", N); |
fe5d3068 | 685 | |
996ae0b0 RK |
686 | Generate_Definition (New_P); |
687 | ||
688 | if Current_Scope /= Standard_Standard then | |
689 | Set_Is_Pure (New_P, Is_Pure (Current_Scope)); | |
690 | end if; | |
691 | ||
692 | if Nkind (Name (N)) = N_Selected_Component then | |
693 | Check_Generic_Child_Unit (Name (N), Inst); | |
694 | else | |
695 | Analyze (Name (N)); | |
696 | end if; | |
697 | ||
698 | if not Is_Entity_Name (Name (N)) then | |
699 | Error_Msg_N ("expect entity name in renaming declaration", Name (N)); | |
700 | Old_P := Any_Id; | |
701 | else | |
702 | Old_P := Entity (Name (N)); | |
703 | end if; | |
704 | ||
705 | Enter_Name (New_P); | |
706 | Set_Ekind (New_P, K); | |
707 | ||
708 | if Etype (Old_P) = Any_Type then | |
709 | null; | |
710 | ||
711 | elsif Ekind (Old_P) /= K then | |
712 | Error_Msg_N ("invalid generic unit name", Name (N)); | |
713 | ||
714 | else | |
715 | if Present (Renamed_Object (Old_P)) then | |
241ebe89 | 716 | Set_Renamed_Object (New_P, Renamed_Object (Old_P)); |
996ae0b0 RK |
717 | else |
718 | Set_Renamed_Object (New_P, Old_P); | |
719 | end if; | |
720 | ||
d65a80fd HK |
721 | -- The generic renaming declaration may become Ghost if it renames a |
722 | -- Ghost entity. | |
723 | ||
724 | Mark_Ghost_Renaming (N, Old_P); | |
725 | ||
923fa078 RD |
726 | Set_Is_Pure (New_P, Is_Pure (Old_P)); |
727 | Set_Is_Preelaborated (New_P, Is_Preelaborated (Old_P)); | |
728 | ||
996ae0b0 RK |
729 | Set_Etype (New_P, Etype (Old_P)); |
730 | Set_Has_Completion (New_P); | |
731 | ||
732 | if In_Open_Scopes (Old_P) then | |
733 | Error_Msg_N ("within its scope, generic denotes its instance", N); | |
734 | end if; | |
735 | ||
7b966a95 AC |
736 | -- For subprograms, propagate the Intrinsic flag, to allow, e.g. |
737 | -- renamings and subsequent instantiations of Unchecked_Conversion. | |
738 | ||
739 | if Ekind_In (Old_P, E_Generic_Function, E_Generic_Procedure) then | |
740 | Set_Is_Intrinsic_Subprogram | |
741 | (New_P, Is_Intrinsic_Subprogram (Old_P)); | |
742 | end if; | |
743 | ||
996ae0b0 RK |
744 | Check_Library_Unit_Renaming (N, Old_P); |
745 | end if; | |
42f1d661 AC |
746 | |
747 | -- Implementation-defined aspect specifications can appear in a renaming | |
748 | -- declaration, but not language-defined ones. The call to procedure | |
749 | -- Analyze_Aspect_Specifications will take care of this error check. | |
750 | ||
751 | if Has_Aspects (N) then | |
752 | Analyze_Aspect_Specifications (N, New_P); | |
753 | end if; | |
996ae0b0 RK |
754 | end Analyze_Generic_Renaming; |
755 | ||
756 | ----------------------------- | |
757 | -- Analyze_Object_Renaming -- | |
758 | ----------------------------- | |
759 | ||
760 | procedure Analyze_Object_Renaming (N : Node_Id) is | |
1378bf10 | 761 | Id : constant Entity_Id := Defining_Identifier (N); |
241ebe89 | 762 | Loc : constant Source_Ptr := Sloc (N); |
1378bf10 | 763 | Nam : constant Node_Id := Name (N); |
241ebe89 | 764 | Dec : Node_Id; |
996ae0b0 RK |
765 | T : Entity_Id; |
766 | T2 : Entity_Id; | |
767 | ||
3f5a8fee AC |
768 | procedure Check_Constrained_Object; |
769 | -- If the nominal type is unconstrained but the renamed object is | |
770 | -- constrained, as can happen with renaming an explicit dereference or | |
771 | -- a function return, build a constrained subtype from the object. If | |
772 | -- the renaming is for a formal in an accept statement, the analysis | |
773 | -- has already established its actual subtype. This is only relevant | |
774 | -- if the renamed object is an explicit dereference. | |
775 | ||
3f5a8fee AC |
776 | ------------------------------ |
777 | -- Check_Constrained_Object -- | |
778 | ------------------------------ | |
779 | ||
780 | procedure Check_Constrained_Object is | |
b887f1a0 | 781 | Typ : constant Entity_Id := Etype (Nam); |
3f5a8fee AC |
782 | Subt : Entity_Id; |
783 | ||
784 | begin | |
e917aec2 | 785 | if Nkind_In (Nam, N_Function_Call, N_Explicit_Dereference) |
3f5a8fee AC |
786 | and then Is_Composite_Type (Etype (Nam)) |
787 | and then not Is_Constrained (Etype (Nam)) | |
788 | and then not Has_Unknown_Discriminants (Etype (Nam)) | |
789 | and then Expander_Active | |
790 | then | |
e917aec2 | 791 | -- If Actual_Subtype is already set, nothing to do |
3f5a8fee | 792 | |
e917aec2 | 793 | if Ekind_In (Id, E_Variable, E_Constant) |
3f5a8fee AC |
794 | and then Present (Actual_Subtype (Id)) |
795 | then | |
796 | null; | |
797 | ||
42f1d661 | 798 | -- A renaming of an unchecked union has no actual subtype |
14848f57 | 799 | |
b887f1a0 | 800 | elsif Is_Unchecked_Union (Typ) then |
14848f57 AC |
801 | null; |
802 | ||
2780d174 AC |
803 | -- If a record is limited its size is invariant. This is the case |
804 | -- in particular with record types with an access discirminant | |
805 | -- that are used in iterators. This is an optimization, but it | |
806 | -- also prevents typing anomalies when the prefix is further | |
b887f1a0 | 807 | -- expanded. Limited types with discriminants are included. |
2780d174 | 808 | |
b887f1a0 | 809 | elsif Is_Limited_Record (Typ) |
150ac76e AC |
810 | or else |
811 | (Ekind (Typ) = E_Limited_Private_Type | |
812 | and then Has_Discriminants (Typ) | |
813 | and then Is_Access_Type (Etype (First_Discriminant (Typ)))) | |
b887f1a0 | 814 | then |
2780d174 AC |
815 | null; |
816 | ||
3f5a8fee AC |
817 | else |
818 | Subt := Make_Temporary (Loc, 'T'); | |
819 | Remove_Side_Effects (Nam); | |
820 | Insert_Action (N, | |
821 | Make_Subtype_Declaration (Loc, | |
822 | Defining_Identifier => Subt, | |
823 | Subtype_Indication => | |
b887f1a0 | 824 | Make_Subtype_From_Expr (Nam, Typ))); |
3f5a8fee AC |
825 | Rewrite (Subtype_Mark (N), New_Occurrence_Of (Subt, Loc)); |
826 | Set_Etype (Nam, Subt); | |
303fbb20 AC |
827 | |
828 | -- Freeze subtype at once, to prevent order of elaboration | |
829 | -- issues in the backend. The renamed object exists, so its | |
830 | -- type is already frozen in any case. | |
831 | ||
832 | Freeze_Before (N, Subt); | |
3f5a8fee AC |
833 | end if; |
834 | end if; | |
835 | end Check_Constrained_Object; | |
836 | ||
923fa078 RD |
837 | -- Start of processing for Analyze_Object_Renaming |
838 | ||
996ae0b0 | 839 | begin |
ed4a1468 RD |
840 | if Nam = Error then |
841 | return; | |
842 | end if; | |
843 | ||
ce5ba43a | 844 | Check_SPARK_05_Restriction ("object renaming is not allowed", N); |
fe5d3068 | 845 | |
996ae0b0 RK |
846 | Set_Is_Pure (Id, Is_Pure (Current_Scope)); |
847 | Enter_Name (Id); | |
848 | ||
16ca248a ES |
849 | -- The renaming of a component that depends on a discriminant requires |
850 | -- an actual subtype, because in subsequent use of the object Gigi will | |
851 | -- be unable to locate the actual bounds. This explicit step is required | |
852 | -- when the renaming is generated in removing side effects of an | |
853 | -- already-analyzed expression. | |
996ae0b0 | 854 | |
42f1d661 | 855 | if Nkind (Nam) = N_Selected_Component and then Analyzed (Nam) then |
d65a80fd HK |
856 | |
857 | -- The object renaming declaration may become Ghost if it renames a | |
858 | -- Ghost entity. | |
859 | ||
860 | if Is_Entity_Name (Nam) then | |
861 | Mark_Ghost_Renaming (N, Entity (Nam)); | |
862 | end if; | |
863 | ||
864 | T := Etype (Nam); | |
c5cec2fe | 865 | Dec := Build_Actual_Subtype_Of_Component (Etype (Nam), Nam); |
996ae0b0 RK |
866 | |
867 | if Present (Dec) then | |
868 | Insert_Action (N, Dec); | |
869 | T := Defining_Identifier (Dec); | |
870 | Set_Etype (Nam, T); | |
871 | end if; | |
872 | ||
11560bcc | 873 | -- Complete analysis of the subtype mark in any case, for ASIS use |
fbe627af RD |
874 | |
875 | if Present (Subtype_Mark (N)) then | |
876 | Find_Type (Subtype_Mark (N)); | |
877 | end if; | |
878 | ||
6e937c1c AC |
879 | elsif Present (Subtype_Mark (N)) then |
880 | Find_Type (Subtype_Mark (N)); | |
881 | T := Entity (Subtype_Mark (N)); | |
fbe627af RD |
882 | Analyze (Nam); |
883 | ||
d65a80fd HK |
884 | -- The object renaming declaration may become Ghost if it renames a |
885 | -- Ghost entity. | |
886 | ||
887 | if Is_Entity_Name (Nam) then | |
888 | Mark_Ghost_Renaming (N, Entity (Nam)); | |
889 | end if; | |
890 | ||
6cce2156 GD |
891 | -- Reject renamings of conversions unless the type is tagged, or |
892 | -- the conversion is implicit (which can occur for cases of anonymous | |
893 | -- access types in Ada 2012). | |
894 | ||
fbe627af | 895 | if Nkind (Nam) = N_Type_Conversion |
6cce2156 GD |
896 | and then Comes_From_Source (Nam) |
897 | and then not Is_Tagged_Type (T) | |
fbe627af RD |
898 | then |
899 | Error_Msg_N | |
900 | ("renaming of conversion only allowed for tagged types", Nam); | |
901 | end if; | |
902 | ||
903 | Resolve (Nam, T); | |
6e937c1c | 904 | |
1378bf10 AC |
905 | -- If the renamed object is a function call of a limited type, |
906 | -- the expansion of the renaming is complicated by the presence | |
907 | -- of various temporaries and subtypes that capture constraints | |
908 | -- of the renamed object. Rewrite node as an object declaration, | |
909 | -- whose expansion is simpler. Given that the object is limited | |
910 | -- there is no copy involved and no performance hit. | |
911 | ||
912 | if Nkind (Nam) = N_Function_Call | |
51245e2d | 913 | and then Is_Limited_View (Etype (Nam)) |
92db5dee | 914 | and then not Is_Constrained (Etype (Nam)) |
1378bf10 AC |
915 | and then Comes_From_Source (N) |
916 | then | |
917 | Set_Etype (Id, T); | |
918 | Set_Ekind (Id, E_Constant); | |
919 | Rewrite (N, | |
920 | Make_Object_Declaration (Loc, | |
921 | Defining_Identifier => Id, | |
922 | Constant_Present => True, | |
92db5dee | 923 | Object_Definition => New_Occurrence_Of (Etype (Nam), Loc), |
1378bf10 AC |
924 | Expression => Relocate_Node (Nam))); |
925 | return; | |
926 | end if; | |
927 | ||
6cce2156 GD |
928 | -- Ada 2012 (AI05-149): Reject renaming of an anonymous access object |
929 | -- when renaming declaration has a named access type. The Ada 2012 | |
930 | -- coverage rules allow an anonymous access type in the context of | |
931 | -- an expected named general access type, but the renaming rules | |
932 | -- require the types to be the same. (An exception is when the type | |
933 | -- of the renaming is also an anonymous access type, which can only | |
934 | -- happen due to a renaming created by the expander.) | |
935 | ||
936 | if Nkind (Nam) = N_Type_Conversion | |
937 | and then not Comes_From_Source (Nam) | |
938 | and then Ekind (Etype (Expression (Nam))) = E_Anonymous_Access_Type | |
939 | and then Ekind (T) /= E_Anonymous_Access_Type | |
940 | then | |
941 | Wrong_Type (Expression (Nam), T); -- Should we give better error??? | |
942 | end if; | |
943 | ||
7d823354 ES |
944 | -- Check that a class-wide object is not being renamed as an object |
945 | -- of a specific type. The test for access types is needed to exclude | |
946 | -- cases where the renamed object is a dynamically tagged access | |
947 | -- result, such as occurs in certain expansions. | |
948 | ||
4755cce9 JM |
949 | if Is_Tagged_Type (T) then |
950 | Check_Dynamically_Tagged_Expression | |
951 | (Expr => Nam, | |
952 | Typ => T, | |
953 | Related_Nod => N); | |
7d823354 ES |
954 | end if; |
955 | ||
0ab80019 | 956 | -- Ada 2005 (AI-230/AI-254): Access renaming |
6e937c1c | 957 | |
9bc856dd | 958 | else pragma Assert (Present (Access_Definition (N))); |
d65a80fd HK |
959 | T := |
960 | Access_Definition | |
961 | (Related_Nod => N, | |
962 | N => Access_Definition (N)); | |
35b7fa6a | 963 | |
f16d05d9 AC |
964 | Analyze (Nam); |
965 | ||
d65a80fd HK |
966 | -- The object renaming declaration may become Ghost if it renames a |
967 | -- Ghost entity. | |
968 | ||
969 | if Is_Entity_Name (Nam) then | |
970 | Mark_Ghost_Renaming (N, Entity (Nam)); | |
971 | end if; | |
972 | ||
f16d05d9 AC |
973 | -- Ada 2005 AI05-105: if the declaration has an anonymous access |
974 | -- type, the renamed object must also have an anonymous type, and | |
92db5dee AC |
975 | -- this is a name resolution rule. This was implicit in the last part |
976 | -- of the first sentence in 8.5.1(3/2), and is made explicit by this | |
977 | -- recent AI. | |
f16d05d9 AC |
978 | |
979 | if not Is_Overloaded (Nam) then | |
980 | if Ekind (Etype (Nam)) /= Ekind (T) then | |
981 | Error_Msg_N | |
a2dc5812 | 982 | ("expect anonymous access type in object renaming", N); |
f16d05d9 | 983 | end if; |
3c19e9be | 984 | |
f16d05d9 AC |
985 | else |
986 | declare | |
3c19e9be ES |
987 | I : Interp_Index; |
988 | It : Interp; | |
989 | Typ : Entity_Id := Empty; | |
e34ca162 | 990 | Seen : Boolean := False; |
f16d05d9 AC |
991 | |
992 | begin | |
993 | Get_First_Interp (Nam, I, It); | |
994 | while Present (It.Typ) loop | |
3c19e9be ES |
995 | |
996 | -- Renaming is ambiguous if more than one candidate | |
997 | -- interpretation is type-conformant with the context. | |
998 | ||
999 | if Ekind (It.Typ) = Ekind (T) then | |
1000 | if Ekind (T) = E_Anonymous_Access_Subprogram_Type | |
e34ca162 AC |
1001 | and then |
1002 | Type_Conformant | |
1003 | (Designated_Type (T), Designated_Type (It.Typ)) | |
f16d05d9 | 1004 | then |
3c19e9be ES |
1005 | if not Seen then |
1006 | Seen := True; | |
1007 | else | |
1008 | Error_Msg_N | |
1009 | ("ambiguous expression in renaming", Nam); | |
1010 | end if; | |
1011 | ||
1012 | elsif Ekind (T) = E_Anonymous_Access_Type | |
e34ca162 AC |
1013 | and then |
1014 | Covers (Designated_Type (T), Designated_Type (It.Typ)) | |
3c19e9be ES |
1015 | then |
1016 | if not Seen then | |
1017 | Seen := True; | |
1018 | else | |
1019 | Error_Msg_N | |
1020 | ("ambiguous expression in renaming", Nam); | |
1021 | end if; | |
1022 | end if; | |
1023 | ||
1024 | if Covers (T, It.Typ) then | |
f16d05d9 AC |
1025 | Typ := It.Typ; |
1026 | Set_Etype (Nam, Typ); | |
1027 | Set_Is_Overloaded (Nam, False); | |
1028 | end if; | |
f16d05d9 AC |
1029 | end if; |
1030 | ||
1031 | Get_Next_Interp (I, It); | |
1032 | end loop; | |
1033 | end; | |
1034 | end if; | |
1035 | ||
1036 | Resolve (Nam, T); | |
6e937c1c | 1037 | |
405b907c AC |
1038 | -- Do not perform the legality checks below when the resolution of |
1039 | -- the renaming name failed because the associated type is Any_Type. | |
1040 | ||
1041 | if Etype (Nam) = Any_Type then | |
1042 | null; | |
1043 | ||
d18bbd25 | 1044 | -- Ada 2005 (AI-231): In the case where the type is defined by an |
0fb2ea01 AC |
1045 | -- access_definition, the renamed entity shall be of an access-to- |
1046 | -- constant type if and only if the access_definition defines an | |
d18bbd25 | 1047 | -- access-to-constant type. ARM 8.5.1(4) |
35b7fa6a | 1048 | |
405b907c | 1049 | elsif Constant_Present (Access_Definition (N)) |
35b7fa6a AC |
1050 | and then not Is_Access_Constant (Etype (Nam)) |
1051 | then | |
405b907c | 1052 | Error_Msg_N |
d1aea5dd AC |
1053 | ("(Ada 2005): the renamed object is not access-to-constant " |
1054 | & "(RM 8.5.1(6))", N); | |
a2dc5812 AC |
1055 | |
1056 | elsif not Constant_Present (Access_Definition (N)) | |
1057 | and then Is_Access_Constant (Etype (Nam)) | |
1058 | then | |
405b907c AC |
1059 | Error_Msg_N |
1060 | ("(Ada 2005): the renamed object is not access-to-variable " | |
1061 | & "(RM 8.5.1(6))", N); | |
a2dc5812 AC |
1062 | end if; |
1063 | ||
1064 | if Is_Access_Subprogram_Type (Etype (Nam)) then | |
1065 | Check_Subtype_Conformant | |
1066 | (Designated_Type (T), Designated_Type (Etype (Nam))); | |
1067 | ||
1068 | elsif not Subtypes_Statically_Match | |
df3e68b1 HK |
1069 | (Designated_Type (T), |
1070 | Available_View (Designated_Type (Etype (Nam)))) | |
a2dc5812 AC |
1071 | then |
1072 | Error_Msg_N | |
1073 | ("subtype of renamed object does not statically match", N); | |
35b7fa6a | 1074 | end if; |
996ae0b0 RK |
1075 | end if; |
1076 | ||
426d2717 AC |
1077 | -- Special processing for renaming function return object. Some errors |
1078 | -- and warnings are produced only for calls that come from source. | |
fbe627af | 1079 | |
426d2717 | 1080 | if Nkind (Nam) = N_Function_Call then |
fbe627af RD |
1081 | case Ada_Version is |
1082 | ||
c05ba1f1 AC |
1083 | -- Usage is illegal in Ada 83, but renamings are also introduced |
1084 | -- during expansion, and error does not apply to those. | |
fbe627af RD |
1085 | |
1086 | when Ada_83 => | |
c05ba1f1 | 1087 | if Comes_From_Source (N) then |
426d2717 AC |
1088 | Error_Msg_N |
1089 | ("(Ada 83) cannot rename function return object", Nam); | |
1090 | end if; | |
fbe627af RD |
1091 | |
1092 | -- In Ada 95, warn for odd case of renaming parameterless function | |
426d2717 | 1093 | -- call if this is not a limited type (where this is useful). |
fbe627af RD |
1094 | |
1095 | when others => | |
1096 | if Warn_On_Object_Renames_Function | |
1097 | and then No (Parameter_Associations (Nam)) | |
1098 | and then not Is_Limited_Type (Etype (Nam)) | |
426d2717 | 1099 | and then Comes_From_Source (Nam) |
fbe627af RD |
1100 | then |
1101 | Error_Msg_N | |
dbfeb4fa | 1102 | ("renaming function result object is suspicious?R?", Nam); |
fbe627af | 1103 | Error_Msg_NE |
dbfeb4fa | 1104 | ("\function & will be called only once?R?", Nam, |
426d2717 | 1105 | Entity (Name (Nam))); |
ed2233dc | 1106 | Error_Msg_N -- CODEFIX |
cc0b3bac AC |
1107 | ("\suggest using an initialized constant object " |
1108 | & "instead?R?", Nam); | |
fbe627af RD |
1109 | end if; |
1110 | end case; | |
1111 | end if; | |
1112 | ||
3f5a8fee AC |
1113 | Check_Constrained_Object; |
1114 | ||
16ca248a ES |
1115 | -- An object renaming requires an exact match of the type. Class-wide |
1116 | -- matching is not allowed. | |
996ae0b0 RK |
1117 | |
1118 | if Is_Class_Wide_Type (T) | |
1119 | and then Base_Type (Etype (Nam)) /= Base_Type (T) | |
1120 | then | |
1121 | Wrong_Type (Nam, T); | |
1122 | end if; | |
1123 | ||
1124 | T2 := Etype (Nam); | |
4de287c4 | 1125 | |
92db5dee | 1126 | -- Ada 2005 (AI-326): Handle wrong use of incomplete type |
4de287c4 ES |
1127 | |
1128 | if Nkind (Nam) = N_Explicit_Dereference | |
1129 | and then Ekind (Etype (T2)) = E_Incomplete_Type | |
1130 | then | |
3c829e3c ES |
1131 | Error_Msg_NE ("invalid use of incomplete type&", Id, T2); |
1132 | return; | |
426d2717 | 1133 | |
3c829e3c ES |
1134 | elsif Ekind (Etype (T)) = E_Incomplete_Type then |
1135 | Error_Msg_NE ("invalid use of incomplete type&", Id, T); | |
4de287c4 ES |
1136 | return; |
1137 | end if; | |
1138 | ||
923fa078 RD |
1139 | -- Ada 2005 (AI-327) |
1140 | ||
0791fbe9 | 1141 | if Ada_Version >= Ada_2005 |
923fa078 RD |
1142 | and then Nkind (Nam) = N_Attribute_Reference |
1143 | and then Attribute_Name (Nam) = Name_Priority | |
1144 | then | |
1145 | null; | |
1146 | ||
ac7d724d | 1147 | elsif Ada_Version >= Ada_2005 and then Nkind (Nam) in N_Has_Entity then |
923fa078 | 1148 | declare |
426d2717 AC |
1149 | Nam_Decl : Node_Id; |
1150 | Nam_Ent : Entity_Id; | |
923fa078 RD |
1151 | |
1152 | begin | |
1153 | if Nkind (Nam) = N_Attribute_Reference then | |
1154 | Nam_Ent := Entity (Prefix (Nam)); | |
1155 | else | |
1156 | Nam_Ent := Entity (Nam); | |
1157 | end if; | |
1158 | ||
426d2717 | 1159 | Nam_Decl := Parent (Nam_Ent); |
923fa078 RD |
1160 | |
1161 | if Has_Null_Exclusion (N) | |
1162 | and then not Has_Null_Exclusion (Nam_Decl) | |
1163 | then | |
1164 | -- Ada 2005 (AI-423): If the object name denotes a generic | |
1165 | -- formal object of a generic unit G, and the object renaming | |
1166 | -- declaration occurs within the body of G or within the body | |
1167 | -- of a generic unit declared within the declarative region | |
fbe627af | 1168 | -- of G, then the declaration of the formal object of G must |
a3c39f83 | 1169 | -- have a null exclusion or a null-excluding subtype. |
923fa078 RD |
1170 | |
1171 | if Is_Formal_Object (Nam_Ent) | |
ac7d724d | 1172 | and then In_Generic_Scope (Id) |
923fa078 | 1173 | then |
a3c39f83 ES |
1174 | if not Can_Never_Be_Null (Etype (Nam_Ent)) then |
1175 | Error_Msg_N | |
1176 | ("renamed formal does not exclude `NULL` " | |
1177 | & "(RM 8.5.1(4.6/2))", N); | |
1178 | ||
1179 | elsif In_Package_Body (Scope (Id)) then | |
1180 | Error_Msg_N | |
1181 | ("formal object does not have a null exclusion" | |
1182 | & "(RM 8.5.1(4.6/2))", N); | |
1183 | end if; | |
923fa078 | 1184 | |
16ca248a ES |
1185 | -- Ada 2005 (AI-423): Otherwise, the subtype of the object name |
1186 | -- shall exclude null. | |
923fa078 | 1187 | |
21d27997 | 1188 | elsif not Can_Never_Be_Null (Etype (Nam_Ent)) then |
fbe627af | 1189 | Error_Msg_N |
21d27997 RD |
1190 | ("renamed object does not exclude `NULL` " |
1191 | & "(RM 8.5.1(4.6/2))", N); | |
aecf0203 | 1192 | |
a3c39f83 ES |
1193 | -- An instance is illegal if it contains a renaming that |
1194 | -- excludes null, and the actual does not. The renaming | |
1195 | -- declaration has already indicated that the declaration | |
1196 | -- of the renamed actual in the instance will raise | |
1197 | -- constraint_error. | |
1198 | ||
426d2717 | 1199 | elsif Nkind (Nam_Decl) = N_Object_Declaration |
a3c39f83 | 1200 | and then In_Instance |
ac7d724d ES |
1201 | and then |
1202 | Present (Corresponding_Generic_Association (Nam_Decl)) | |
1203 | and then Nkind (Expression (Nam_Decl)) = | |
1204 | N_Raise_Constraint_Error | |
a3c39f83 ES |
1205 | then |
1206 | Error_Msg_N | |
1207 | ("renamed actual does not exclude `NULL` " | |
1208 | & "(RM 8.5.1(4.6/2))", N); | |
1209 | ||
1210 | -- Finally, if there is a null exclusion, the subtype mark | |
1211 | -- must not be null-excluding. | |
1212 | ||
1213 | elsif No (Access_Definition (N)) | |
426d2717 | 1214 | and then Can_Never_Be_Null (T) |
a3c39f83 | 1215 | then |
aecf0203 | 1216 | Error_Msg_NE |
a3c39f83 ES |
1217 | ("`NOT NULL` not allowed (& already excludes null)", |
1218 | N, T); | |
fa961f76 | 1219 | |
923fa078 | 1220 | end if; |
fa961f76 | 1221 | |
a3c39f83 ES |
1222 | elsif Can_Never_Be_Null (T) |
1223 | and then not Can_Never_Be_Null (Etype (Nam_Ent)) | |
1224 | then | |
1225 | Error_Msg_N | |
1226 | ("renamed object does not exclude `NULL` " | |
1227 | & "(RM 8.5.1(4.6/2))", N); | |
1228 | ||
fa961f76 ES |
1229 | elsif Has_Null_Exclusion (N) |
1230 | and then No (Access_Definition (N)) | |
1231 | and then Can_Never_Be_Null (T) | |
1232 | then | |
1233 | Error_Msg_NE | |
1234 | ("`NOT NULL` not allowed (& already excludes null)", N, T); | |
923fa078 RD |
1235 | end if; |
1236 | end; | |
1237 | end if; | |
1238 | ||
2db5b47e AC |
1239 | -- Set the Ekind of the entity, unless it has been set already, as is |
1240 | -- the case for the iteration object over a container with no variable | |
3e247e58 RD |
1241 | -- indexing. In that case it's been marked as a constant, and we do not |
1242 | -- want to change it to a variable. | |
2db5b47e AC |
1243 | |
1244 | if Ekind (Id) /= E_Constant then | |
1245 | Set_Ekind (Id, E_Variable); | |
1246 | end if; | |
996c8821 RD |
1247 | |
1248 | -- Initialize the object size and alignment. Note that we used to call | |
1249 | -- Init_Size_Align here, but that's wrong for objects which have only | |
a90bd866 | 1250 | -- an Esize, not an RM_Size field. |
996c8821 | 1251 | |
d15f9422 | 1252 | Init_Object_Size_Align (Id); |
996ae0b0 RK |
1253 | |
1254 | if T = Any_Type or else Etype (Nam) = Any_Type then | |
1255 | return; | |
1256 | ||
923fa078 RD |
1257 | -- Verify that the renamed entity is an object or a function call. It |
1258 | -- may have been rewritten in several ways. | |
996ae0b0 RK |
1259 | |
1260 | elsif Is_Object_Reference (Nam) then | |
124092ee AC |
1261 | if Comes_From_Source (N) then |
1262 | if Is_Dependent_Component_Of_Mutable_Object (Nam) then | |
1263 | Error_Msg_N | |
1264 | ("illegal renaming of discriminant-dependent component", Nam); | |
1265 | end if; | |
1266 | ||
1267 | -- If the renaming comes from source and the renamed object is a | |
1268 | -- dereference, then mark the prefix as needing debug information, | |
1269 | -- since it might have been rewritten hence internally generated | |
1270 | -- and Debug_Renaming_Declaration will link the renaming to it. | |
1271 | ||
1272 | if Nkind (Nam) = N_Explicit_Dereference | |
1273 | and then Is_Entity_Name (Prefix (Nam)) | |
1274 | then | |
1275 | Set_Debug_Info_Needed (Entity (Prefix (Nam))); | |
1276 | end if; | |
996ae0b0 RK |
1277 | end if; |
1278 | ||
1279 | -- A static function call may have been folded into a literal | |
1280 | ||
1281 | elsif Nkind (Original_Node (Nam)) = N_Function_Call | |
1282 | ||
28e18b4f AC |
1283 | -- When expansion is disabled, attribute reference is not rewritten |
1284 | -- as function call. Otherwise it may be rewritten as a conversion, | |
1285 | -- so check original node. | |
996ae0b0 RK |
1286 | |
1287 | or else (Nkind (Original_Node (Nam)) = N_Attribute_Reference | |
1288 | and then Is_Function_Attribute_Name | |
294ccb21 | 1289 | (Attribute_Name (Original_Node (Nam)))) |
996ae0b0 | 1290 | |
28e18b4f AC |
1291 | -- Weird but legal, equivalent to renaming a function call. Illegal |
1292 | -- if the literal is the result of constant-folding an attribute | |
1293 | -- reference that is not a function. | |
996ae0b0 RK |
1294 | |
1295 | or else (Is_Entity_Name (Nam) | |
d4810530 ES |
1296 | and then Ekind (Entity (Nam)) = E_Enumeration_Literal |
1297 | and then | |
1298 | Nkind (Original_Node (Nam)) /= N_Attribute_Reference) | |
996ae0b0 RK |
1299 | |
1300 | or else (Nkind (Nam) = N_Type_Conversion | |
ac7d724d | 1301 | and then Is_Tagged_Type (Entity (Subtype_Mark (Nam)))) |
996ae0b0 RK |
1302 | then |
1303 | null; | |
1304 | ||
923fa078 RD |
1305 | elsif Nkind (Nam) = N_Type_Conversion then |
1306 | Error_Msg_N | |
1307 | ("renaming of conversion only allowed for tagged types", Nam); | |
996ae0b0 | 1308 | |
923fa078 RD |
1309 | -- Ada 2005 (AI-327) |
1310 | ||
0791fbe9 | 1311 | elsif Ada_Version >= Ada_2005 |
923fa078 RD |
1312 | and then Nkind (Nam) = N_Attribute_Reference |
1313 | and then Attribute_Name (Nam) = Name_Priority | |
1314 | then | |
1315 | null; | |
1316 | ||
c42e1b17 | 1317 | -- Allow internally generated x'Ref resulting in N_Reference node |
21d27997 RD |
1318 | |
1319 | elsif Nkind (Nam) = N_Reference then | |
1320 | null; | |
1321 | ||
923fa078 RD |
1322 | else |
1323 | Error_Msg_N ("expect object name in renaming", Nam); | |
996ae0b0 RK |
1324 | end if; |
1325 | ||
1326 | Set_Etype (Id, T2); | |
1327 | ||
1328 | if not Is_Variable (Nam) then | |
1329 | Set_Ekind (Id, E_Constant); | |
fbf5a39b | 1330 | Set_Never_Set_In_Source (Id, True); |
996ae0b0 RK |
1331 | Set_Is_True_Constant (Id, True); |
1332 | end if; | |
1333 | ||
28e18b4f AC |
1334 | -- The entity of the renaming declaration needs to reflect whether the |
1335 | -- renamed object is volatile. Is_Volatile is set if the renamed object | |
1336 | -- is volatile in the RM legality sense. | |
1337 | ||
1338 | Set_Is_Volatile (Id, Is_Volatile_Object (Nam)); | |
1339 | ||
c2cfccb1 | 1340 | -- Also copy settings of Atomic/Independent/Volatile_Full_Access |
6333ad3d AC |
1341 | |
1342 | if Is_Entity_Name (Nam) then | |
57abdadd EB |
1343 | Set_Is_Atomic (Id, Is_Atomic (Entity (Nam))); |
1344 | Set_Is_Independent (Id, Is_Independent (Entity (Nam))); | |
1345 | Set_Is_Volatile_Full_Access (Id, | |
1346 | Is_Volatile_Full_Access (Entity (Nam))); | |
6333ad3d AC |
1347 | end if; |
1348 | ||
28e18b4f AC |
1349 | -- Treat as volatile if we just set the Volatile flag |
1350 | ||
1351 | if Is_Volatile (Id) | |
1352 | ||
1353 | -- Or if we are renaming an entity which was marked this way | |
1354 | ||
1355 | -- Are there more cases, e.g. X(J) where X is Treat_As_Volatile ??? | |
1356 | ||
1357 | or else (Is_Entity_Name (Nam) | |
1358 | and then Treat_As_Volatile (Entity (Nam))) | |
1359 | then | |
1360 | Set_Treat_As_Volatile (Id, True); | |
1361 | end if; | |
1362 | ||
1363 | -- Now make the link to the renamed object | |
1364 | ||
996ae0b0 | 1365 | Set_Renamed_Object (Id, Nam); |
42f1d661 AC |
1366 | |
1367 | -- Implementation-defined aspect specifications can appear in a renaming | |
1368 | -- declaration, but not language-defined ones. The call to procedure | |
1369 | -- Analyze_Aspect_Specifications will take care of this error check. | |
1370 | ||
1371 | if Has_Aspects (N) then | |
1372 | Analyze_Aspect_Specifications (N, Id); | |
1373 | end if; | |
1374 | ||
1375 | -- Deal with dimensions | |
1376 | ||
dec6faf1 | 1377 | Analyze_Dimension (N); |
996ae0b0 RK |
1378 | end Analyze_Object_Renaming; |
1379 | ||
1380 | ------------------------------ | |
1381 | -- Analyze_Package_Renaming -- | |
1382 | ------------------------------ | |
1383 | ||
1384 | procedure Analyze_Package_Renaming (N : Node_Id) is | |
1385 | New_P : constant Entity_Id := Defining_Entity (N); | |
1386 | Old_P : Entity_Id; | |
1387 | Spec : Node_Id; | |
1388 | ||
1389 | begin | |
ed4a1468 RD |
1390 | if Name (N) = Error then |
1391 | return; | |
1392 | end if; | |
1393 | ||
e80f0cb0 | 1394 | -- Check for Text_IO special unit (we may be renaming a Text_IO child) |
996ae0b0 | 1395 | |
2bd67690 | 1396 | Check_Text_IO_Special_Unit (Name (N)); |
996ae0b0 RK |
1397 | |
1398 | if Current_Scope /= Standard_Standard then | |
1399 | Set_Is_Pure (New_P, Is_Pure (Current_Scope)); | |
1400 | end if; | |
1401 | ||
1402 | Enter_Name (New_P); | |
1403 | Analyze (Name (N)); | |
16ca248a | 1404 | |
996ae0b0 RK |
1405 | if Is_Entity_Name (Name (N)) then |
1406 | Old_P := Entity (Name (N)); | |
1407 | else | |
1408 | Old_P := Any_Id; | |
1409 | end if; | |
1410 | ||
1411 | if Etype (Old_P) = Any_Type then | |
426d2717 | 1412 | Error_Msg_N ("expect package name in renaming", Name (N)); |
657a9dd9 | 1413 | |
996ae0b0 RK |
1414 | elsif Ekind (Old_P) /= E_Package |
1415 | and then not (Ekind (Old_P) = E_Generic_Package | |
1416 | and then In_Open_Scopes (Old_P)) | |
1417 | then | |
1418 | if Ekind (Old_P) = E_Generic_Package then | |
1419 | Error_Msg_N | |
1420 | ("generic package cannot be renamed as a package", Name (N)); | |
1421 | else | |
1422 | Error_Msg_Sloc := Sloc (Old_P); | |
1423 | Error_Msg_NE | |
d65a80fd | 1424 | ("expect package name in renaming, found& declared#", |
996ae0b0 RK |
1425 | Name (N), Old_P); |
1426 | end if; | |
1427 | ||
bc41faa2 | 1428 | -- Set basic attributes to minimize cascaded errors |
996ae0b0 RK |
1429 | |
1430 | Set_Ekind (New_P, E_Package); | |
1431 | Set_Etype (New_P, Standard_Void_Type); | |
1432 | ||
294ccb21 RD |
1433 | -- Here for OK package renaming |
1434 | ||
996ae0b0 | 1435 | else |
923fa078 RD |
1436 | -- Entities in the old package are accessible through the renaming |
1437 | -- entity. The simplest implementation is to have both packages share | |
1438 | -- the entity list. | |
996ae0b0 RK |
1439 | |
1440 | Set_Ekind (New_P, E_Package); | |
1441 | Set_Etype (New_P, Standard_Void_Type); | |
1442 | ||
1443 | if Present (Renamed_Object (Old_P)) then | |
caa64a44 | 1444 | Set_Renamed_Object (New_P, Renamed_Object (Old_P)); |
996ae0b0 | 1445 | else |
4de287c4 | 1446 | Set_Renamed_Object (New_P, Old_P); |
996ae0b0 RK |
1447 | end if; |
1448 | ||
d65a80fd HK |
1449 | -- The package renaming declaration may become Ghost if it renames a |
1450 | -- Ghost entity. | |
1451 | ||
1452 | Mark_Ghost_Renaming (N, Old_P); | |
996ae0b0 | 1453 | |
d65a80fd HK |
1454 | Set_Has_Completion (New_P); |
1455 | Set_First_Entity (New_P, First_Entity (Old_P)); | |
1456 | Set_Last_Entity (New_P, Last_Entity (Old_P)); | |
996ae0b0 RK |
1457 | Set_First_Private_Entity (New_P, First_Private_Entity (Old_P)); |
1458 | Check_Library_Unit_Renaming (N, Old_P); | |
1459 | Generate_Reference (Old_P, Name (N)); | |
1460 | ||
294ccb21 | 1461 | -- If the renaming is in the visible part of a package, then we set |
7d823354 | 1462 | -- Renamed_In_Spec for the renamed package, to prevent giving |
294ccb21 RD |
1463 | -- warnings about no entities referenced. Such a warning would be |
1464 | -- overenthusiastic, since clients can see entities in the renamed | |
1465 | -- package via the visible package renaming. | |
1466 | ||
1467 | declare | |
1468 | Ent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit); | |
1469 | begin | |
1470 | if Ekind (Ent) = E_Package | |
1471 | and then not In_Private_Part (Ent) | |
1472 | and then In_Extended_Main_Source_Unit (N) | |
1473 | and then Ekind (Old_P) = E_Package | |
1474 | then | |
1475 | Set_Renamed_In_Spec (Old_P); | |
1476 | end if; | |
1477 | end; | |
1478 | ||
996ae0b0 RK |
1479 | -- If this is the renaming declaration of a package instantiation |
1480 | -- within itself, it is the declaration that ends the list of actuals | |
1481 | -- for the instantiation. At this point, the subtypes that rename | |
1482 | -- the actuals are flagged as generic, to avoid spurious ambiguities | |
1483 | -- if the actuals for two distinct formals happen to coincide. If | |
1484 | -- the actual is a private type, the subtype has a private completion | |
1485 | -- that is flagged in the same fashion. | |
1486 | ||
1487 | -- Resolution is identical to what is was in the original generic. | |
1488 | -- On exit from the generic instance, these are turned into regular | |
1489 | -- subtypes again, so they are compatible with types in their class. | |
1490 | ||
1491 | if not Is_Generic_Instance (Old_P) then | |
1492 | return; | |
1493 | else | |
1494 | Spec := Specification (Unit_Declaration_Node (Old_P)); | |
1495 | end if; | |
1496 | ||
1497 | if Nkind (Spec) = N_Package_Specification | |
1498 | and then Present (Generic_Parent (Spec)) | |
1499 | and then Old_P = Current_Scope | |
1500 | and then Chars (New_P) = Chars (Generic_Parent (Spec)) | |
1501 | then | |
1502 | declare | |
16ca248a ES |
1503 | E : Entity_Id; |
1504 | ||
996ae0b0 | 1505 | begin |
16ca248a | 1506 | E := First_Entity (Old_P); |
ac7d724d | 1507 | while Present (E) and then E /= New_P loop |
996ae0b0 RK |
1508 | if Is_Type (E) |
1509 | and then Nkind (Parent (E)) = N_Subtype_Declaration | |
1510 | then | |
1511 | Set_Is_Generic_Actual_Type (E); | |
1512 | ||
1513 | if Is_Private_Type (E) | |
1514 | and then Present (Full_View (E)) | |
1515 | then | |
1516 | Set_Is_Generic_Actual_Type (Full_View (E)); | |
1517 | end if; | |
1518 | end if; | |
1519 | ||
1520 | Next_Entity (E); | |
1521 | end loop; | |
1522 | end; | |
1523 | end if; | |
1524 | end if; | |
42f1d661 AC |
1525 | |
1526 | -- Implementation-defined aspect specifications can appear in a renaming | |
1527 | -- declaration, but not language-defined ones. The call to procedure | |
1528 | -- Analyze_Aspect_Specifications will take care of this error check. | |
1529 | ||
1530 | if Has_Aspects (N) then | |
1531 | Analyze_Aspect_Specifications (N, New_P); | |
1532 | end if; | |
996ae0b0 RK |
1533 | end Analyze_Package_Renaming; |
1534 | ||
1535 | ------------------------------- | |
1536 | -- Analyze_Renamed_Character -- | |
1537 | ------------------------------- | |
1538 | ||
1539 | procedure Analyze_Renamed_Character | |
1540 | (N : Node_Id; | |
1541 | New_S : Entity_Id; | |
1542 | Is_Body : Boolean) | |
1543 | is | |
1544 | C : constant Node_Id := Name (N); | |
1545 | ||
1546 | begin | |
1547 | if Ekind (New_S) = E_Function then | |
1548 | Resolve (C, Etype (New_S)); | |
1549 | ||
1550 | if Is_Body then | |
1551 | Check_Frozen_Renaming (N, New_S); | |
1552 | end if; | |
1553 | ||
1554 | else | |
1555 | Error_Msg_N ("character literal can only be renamed as function", N); | |
1556 | end if; | |
1557 | end Analyze_Renamed_Character; | |
1558 | ||
1559 | --------------------------------- | |
1560 | -- Analyze_Renamed_Dereference -- | |
1561 | --------------------------------- | |
1562 | ||
1563 | procedure Analyze_Renamed_Dereference | |
1564 | (N : Node_Id; | |
1565 | New_S : Entity_Id; | |
1566 | Is_Body : Boolean) | |
1567 | is | |
1568 | Nam : constant Node_Id := Name (N); | |
1569 | P : constant Node_Id := Prefix (Nam); | |
1570 | Typ : Entity_Id; | |
fbf5a39b | 1571 | Ind : Interp_Index; |
996ae0b0 RK |
1572 | It : Interp; |
1573 | ||
1574 | begin | |
1575 | if not Is_Overloaded (P) then | |
996ae0b0 | 1576 | if Ekind (Etype (Nam)) /= E_Subprogram_Type |
bce79204 AC |
1577 | or else not Type_Conformant (Etype (Nam), New_S) |
1578 | then | |
996ae0b0 RK |
1579 | Error_Msg_N ("designated type does not match specification", P); |
1580 | else | |
fbf5a39b | 1581 | Resolve (P); |
996ae0b0 RK |
1582 | end if; |
1583 | ||
1584 | return; | |
1585 | ||
1586 | else | |
1587 | Typ := Any_Type; | |
fbf5a39b | 1588 | Get_First_Interp (Nam, Ind, It); |
996ae0b0 RK |
1589 | |
1590 | while Present (It.Nam) loop | |
1591 | ||
1592 | if Ekind (It.Nam) = E_Subprogram_Type | |
bce79204 AC |
1593 | and then Type_Conformant (It.Nam, New_S) |
1594 | then | |
996ae0b0 RK |
1595 | if Typ /= Any_Id then |
1596 | Error_Msg_N ("ambiguous renaming", P); | |
1597 | return; | |
1598 | else | |
1599 | Typ := It.Nam; | |
1600 | end if; | |
1601 | end if; | |
1602 | ||
fbf5a39b | 1603 | Get_Next_Interp (Ind, It); |
996ae0b0 RK |
1604 | end loop; |
1605 | ||
1606 | if Typ = Any_Type then | |
1607 | Error_Msg_N ("designated type does not match specification", P); | |
1608 | else | |
1609 | Resolve (N, Typ); | |
1610 | ||
1611 | if Is_Body then | |
1612 | Check_Frozen_Renaming (N, New_S); | |
1613 | end if; | |
1614 | end if; | |
1615 | end if; | |
1616 | end Analyze_Renamed_Dereference; | |
1617 | ||
1618 | --------------------------- | |
1619 | -- Analyze_Renamed_Entry -- | |
1620 | --------------------------- | |
1621 | ||
1622 | procedure Analyze_Renamed_Entry | |
1623 | (N : Node_Id; | |
1624 | New_S : Entity_Id; | |
1625 | Is_Body : Boolean) | |
1626 | is | |
c92e8586 AC |
1627 | Nam : constant Node_Id := Name (N); |
1628 | Sel : constant Node_Id := Selector_Name (Nam); | |
1629 | Is_Actual : constant Boolean := Present (Corresponding_Formal_Spec (N)); | |
1630 | Old_S : Entity_Id; | |
996ae0b0 RK |
1631 | |
1632 | begin | |
1633 | if Entity (Sel) = Any_Id then | |
1634 | ||
bc41faa2 | 1635 | -- Selector is undefined on prefix. Error emitted already |
996ae0b0 RK |
1636 | |
1637 | Set_Has_Completion (New_S); | |
1638 | return; | |
1639 | end if; | |
1640 | ||
16ca248a | 1641 | -- Otherwise find renamed entity and build body of New_S as a call to it |
996ae0b0 RK |
1642 | |
1643 | Old_S := Find_Renamed_Entity (N, Selector_Name (Nam), New_S); | |
1644 | ||
1645 | if Old_S = Any_Id then | |
1646 | Error_Msg_N (" no subprogram or entry matches specification", N); | |
1647 | else | |
1648 | if Is_Body then | |
1649 | Check_Subtype_Conformant (New_S, Old_S, N); | |
1650 | Generate_Reference (New_S, Defining_Entity (N), 'b'); | |
1651 | Style.Check_Identifier (Defining_Entity (N), New_S); | |
725393ea ES |
1652 | |
1653 | else | |
d4810530 | 1654 | -- Only mode conformance required for a renaming_as_declaration |
725393ea ES |
1655 | |
1656 | Check_Mode_Conformant (New_S, Old_S, N); | |
996ae0b0 RK |
1657 | end if; |
1658 | ||
1659 | Inherit_Renamed_Profile (New_S, Old_S); | |
294ccb21 | 1660 | |
c92e8586 AC |
1661 | -- The prefix can be an arbitrary expression that yields a task or |
1662 | -- protected object, so it must be resolved. | |
294ccb21 RD |
1663 | |
1664 | Resolve (Prefix (Nam), Scope (Old_S)); | |
996ae0b0 RK |
1665 | end if; |
1666 | ||
1667 | Set_Convention (New_S, Convention (Old_S)); | |
1668 | Set_Has_Completion (New_S, Inside_A_Generic); | |
1669 | ||
c92e8586 AC |
1670 | -- AI05-0225: If the renamed entity is a procedure or entry of a |
1671 | -- protected object, the target object must be a variable. | |
1672 | ||
1673 | if Ekind (Scope (Old_S)) in Protected_Kind | |
1674 | and then Ekind (New_S) = E_Procedure | |
1675 | and then not Is_Variable (Prefix (Nam)) | |
1676 | then | |
1677 | if Is_Actual then | |
1678 | Error_Msg_N | |
1679 | ("target object of protected operation used as actual for " | |
1680 | & "formal procedure must be a variable", Nam); | |
1681 | else | |
1682 | Error_Msg_N | |
1683 | ("target object of protected operation renamed as procedure, " | |
1684 | & "must be a variable", Nam); | |
1685 | end if; | |
1686 | end if; | |
1687 | ||
996ae0b0 RK |
1688 | if Is_Body then |
1689 | Check_Frozen_Renaming (N, New_S); | |
1690 | end if; | |
1691 | end Analyze_Renamed_Entry; | |
1692 | ||
1693 | ----------------------------------- | |
1694 | -- Analyze_Renamed_Family_Member -- | |
1695 | ----------------------------------- | |
1696 | ||
1697 | procedure Analyze_Renamed_Family_Member | |
1698 | (N : Node_Id; | |
1699 | New_S : Entity_Id; | |
1700 | Is_Body : Boolean) | |
1701 | is | |
fbf5a39b AC |
1702 | Nam : constant Node_Id := Name (N); |
1703 | P : constant Node_Id := Prefix (Nam); | |
996ae0b0 RK |
1704 | Old_S : Entity_Id; |
1705 | ||
1706 | begin | |
1707 | if (Is_Entity_Name (P) and then Ekind (Entity (P)) = E_Entry_Family) | |
1708 | or else (Nkind (P) = N_Selected_Component | |
ac7d724d | 1709 | and then Ekind (Entity (Selector_Name (P))) = E_Entry_Family) |
996ae0b0 RK |
1710 | then |
1711 | if Is_Entity_Name (P) then | |
1712 | Old_S := Entity (P); | |
1713 | else | |
1714 | Old_S := Entity (Selector_Name (P)); | |
1715 | end if; | |
1716 | ||
1717 | if not Entity_Matches_Spec (Old_S, New_S) then | |
1718 | Error_Msg_N ("entry family does not match specification", N); | |
1719 | ||
1720 | elsif Is_Body then | |
1721 | Check_Subtype_Conformant (New_S, Old_S, N); | |
1722 | Generate_Reference (New_S, Defining_Entity (N), 'b'); | |
1723 | Style.Check_Identifier (Defining_Entity (N), New_S); | |
1724 | end if; | |
16ca248a | 1725 | |
996ae0b0 RK |
1726 | else |
1727 | Error_Msg_N ("no entry family matches specification", N); | |
1728 | end if; | |
1729 | ||
1730 | Set_Has_Completion (New_S, Inside_A_Generic); | |
1731 | ||
1732 | if Is_Body then | |
1733 | Check_Frozen_Renaming (N, New_S); | |
1734 | end if; | |
1735 | end Analyze_Renamed_Family_Member; | |
1736 | ||
294ccb21 RD |
1737 | ----------------------------------------- |
1738 | -- Analyze_Renamed_Primitive_Operation -- | |
1739 | ----------------------------------------- | |
1740 | ||
1741 | procedure Analyze_Renamed_Primitive_Operation | |
1742 | (N : Node_Id; | |
1743 | New_S : Entity_Id; | |
1744 | Is_Body : Boolean) | |
1745 | is | |
1746 | Old_S : Entity_Id; | |
1747 | ||
1748 | function Conforms | |
1749 | (Subp : Entity_Id; | |
1750 | Ctyp : Conformance_Type) return Boolean; | |
1751 | -- Verify that the signatures of the renamed entity and the new entity | |
1752 | -- match. The first formal of the renamed entity is skipped because it | |
1753 | -- is the target object in any subsequent call. | |
1754 | ||
c5d00db0 AC |
1755 | -------------- |
1756 | -- Conforms -- | |
1757 | -------------- | |
1758 | ||
294ccb21 RD |
1759 | function Conforms |
1760 | (Subp : Entity_Id; | |
1761 | Ctyp : Conformance_Type) return Boolean | |
1762 | is | |
1763 | Old_F : Entity_Id; | |
1764 | New_F : Entity_Id; | |
1765 | ||
1766 | begin | |
1767 | if Ekind (Subp) /= Ekind (New_S) then | |
1768 | return False; | |
1769 | end if; | |
1770 | ||
1771 | Old_F := Next_Formal (First_Formal (Subp)); | |
1772 | New_F := First_Formal (New_S); | |
1773 | while Present (Old_F) and then Present (New_F) loop | |
1774 | if not Conforming_Types (Etype (Old_F), Etype (New_F), Ctyp) then | |
1775 | return False; | |
1776 | end if; | |
1777 | ||
1778 | if Ctyp >= Mode_Conformant | |
1779 | and then Ekind (Old_F) /= Ekind (New_F) | |
1780 | then | |
1781 | return False; | |
1782 | end if; | |
1783 | ||
1784 | Next_Formal (New_F); | |
1785 | Next_Formal (Old_F); | |
1786 | end loop; | |
1787 | ||
1788 | return True; | |
1789 | end Conforms; | |
1790 | ||
c5d00db0 AC |
1791 | -- Start of processing for Analyze_Renamed_Primitive_Operation |
1792 | ||
294ccb21 RD |
1793 | begin |
1794 | if not Is_Overloaded (Selector_Name (Name (N))) then | |
1795 | Old_S := Entity (Selector_Name (Name (N))); | |
1796 | ||
1797 | if not Conforms (Old_S, Type_Conformant) then | |
1798 | Old_S := Any_Id; | |
1799 | end if; | |
1800 | ||
1801 | else | |
1802 | -- Find the operation that matches the given signature | |
1803 | ||
1804 | declare | |
1805 | It : Interp; | |
1806 | Ind : Interp_Index; | |
1807 | ||
1808 | begin | |
1809 | Old_S := Any_Id; | |
1810 | Get_First_Interp (Selector_Name (Name (N)), Ind, It); | |
1811 | ||
1812 | while Present (It.Nam) loop | |
1813 | if Conforms (It.Nam, Type_Conformant) then | |
1814 | Old_S := It.Nam; | |
1815 | end if; | |
1816 | ||
1817 | Get_Next_Interp (Ind, It); | |
1818 | end loop; | |
1819 | end; | |
1820 | end if; | |
1821 | ||
1822 | if Old_S = Any_Id then | |
1823 | Error_Msg_N (" no subprogram or entry matches specification", N); | |
1824 | ||
1825 | else | |
1826 | if Is_Body then | |
1827 | if not Conforms (Old_S, Subtype_Conformant) then | |
1828 | Error_Msg_N ("subtype conformance error in renaming", N); | |
1829 | end if; | |
1830 | ||
1831 | Generate_Reference (New_S, Defining_Entity (N), 'b'); | |
1832 | Style.Check_Identifier (Defining_Entity (N), New_S); | |
1833 | ||
1834 | else | |
1835 | -- Only mode conformance required for a renaming_as_declaration | |
1836 | ||
1837 | if not Conforms (Old_S, Mode_Conformant) then | |
1838 | Error_Msg_N ("mode conformance error in renaming", N); | |
1839 | end if; | |
c5d00db0 AC |
1840 | |
1841 | -- Enforce the rule given in (RM 6.3.1 (10.1/2)): a prefixed | |
1842 | -- view of a subprogram is intrinsic, because the compiler has | |
1843 | -- to generate a wrapper for any call to it. If the name in a | |
1844 | -- subprogram renaming is a prefixed view, the entity is thus | |
1845 | -- intrinsic, and 'Access cannot be applied to it. | |
1846 | ||
1847 | Set_Convention (New_S, Convention_Intrinsic); | |
294ccb21 RD |
1848 | end if; |
1849 | ||
1850 | -- Inherit_Renamed_Profile (New_S, Old_S); | |
1851 | ||
1852 | -- The prefix can be an arbitrary expression that yields an | |
1853 | -- object, so it must be resolved. | |
1854 | ||
1855 | Resolve (Prefix (Name (N))); | |
1856 | end if; | |
1857 | end Analyze_Renamed_Primitive_Operation; | |
1858 | ||
996ae0b0 RK |
1859 | --------------------------------- |
1860 | -- Analyze_Subprogram_Renaming -- | |
1861 | --------------------------------- | |
1862 | ||
1863 | procedure Analyze_Subprogram_Renaming (N : Node_Id) is | |
fc193526 HK |
1864 | Formal_Spec : constant Entity_Id := Corresponding_Formal_Spec (N); |
1865 | Is_Actual : constant Boolean := Present (Formal_Spec); | |
0ab80019 | 1866 | Nam : constant Node_Id := Name (N); |
923fa078 | 1867 | Save_AV : constant Ada_Version_Type := Ada_Version; |
fb620b37 | 1868 | Save_AVP : constant Node_Id := Ada_Version_Pragma; |
923fa078 RD |
1869 | Save_AV_Exp : constant Ada_Version_Type := Ada_Version_Explicit; |
1870 | Spec : constant Node_Id := Specification (N); | |
1871 | ||
fc193526 HK |
1872 | Old_S : Entity_Id := Empty; |
1873 | Rename_Spec : Entity_Id; | |
1874 | ||
1875 | procedure Build_Class_Wide_Wrapper | |
1876 | (Ren_Id : out Entity_Id; | |
1877 | Wrap_Id : out Entity_Id); | |
1878 | -- Ada 2012 (AI05-0071): A generic/instance scenario involving a formal | |
1879 | -- type with unknown discriminants and a generic primitive operation of | |
1880 | -- the said type with a box require special processing when the actual | |
1881 | -- is a class-wide type: | |
2feb1f84 | 1882 | -- |
fc193526 HK |
1883 | -- generic |
1884 | -- type Formal_Typ (<>) is private; | |
1885 | -- with procedure Prim_Op (Param : Formal_Typ) is <>; | |
1886 | -- package Gen is ... | |
2feb1f84 | 1887 | -- |
fc193526 | 1888 | -- package Inst is new Gen (Actual_Typ'Class); |
2feb1f84 | 1889 | -- |
fc193526 HK |
1890 | -- In this case the general renaming mechanism used in the prologue of |
1891 | -- an instance no longer applies: | |
2feb1f84 | 1892 | -- |
fc193526 | 1893 | -- procedure Prim_Op (Param : Formal_Typ) renames Prim_Op; |
2feb1f84 | 1894 | -- |
fc193526 | 1895 | -- The above is replaced the following wrapper/renaming combination: |
2feb1f84 | 1896 | -- |
6d0b56ad | 1897 | -- procedure Wrapper (Param : Formal_Typ) is -- wrapper |
fc193526 HK |
1898 | -- begin |
1899 | -- Prim_Op (Param); -- primitive | |
1900 | -- end Wrapper; | |
2feb1f84 | 1901 | -- |
6d0b56ad | 1902 | -- procedure Prim_Op (Param : Formal_Typ) renames Wrapper; |
2feb1f84 | 1903 | -- |
fc193526 HK |
1904 | -- This transformation applies only if there is no explicit visible |
1905 | -- class-wide operation at the point of the instantiation. Ren_Id is | |
66340e0e AC |
1906 | -- the entity of the renaming declaration. When the transformation |
1907 | -- applies, Wrap_Id is the entity of the generated class-wide wrapper | |
1908 | -- (or Any_Id). Otherwise, Wrap_Id is the entity of the class-wide | |
1909 | -- operation. | |
fc193526 | 1910 | |
923fa078 RD |
1911 | procedure Check_Null_Exclusion |
1912 | (Ren : Entity_Id; | |
1913 | Sub : Entity_Id); | |
1914 | -- Ada 2005 (AI-423): Given renaming Ren of subprogram Sub, check the | |
1915 | -- following AI rules: | |
16ca248a ES |
1916 | -- |
1917 | -- If Ren is a renaming of a formal subprogram and one of its | |
1918 | -- parameters has a null exclusion, then the corresponding formal | |
1919 | -- in Sub must also have one. Otherwise the subtype of the Sub's | |
1920 | -- formal parameter must exclude null. | |
1921 | -- | |
f3d57416 | 1922 | -- If Ren is a renaming of a formal function and its return |
16ca248a ES |
1923 | -- profile has a null exclusion, then Sub's return profile must |
1924 | -- have one. Otherwise the subtype of Sub's return profile must | |
1925 | -- exclude null. | |
996ae0b0 | 1926 | |
02e4edea AC |
1927 | procedure Freeze_Actual_Profile; |
1928 | -- In Ada 2012, enforce the freezing rule concerning formal incomplete | |
1929 | -- types: a callable entity freezes its profile, unless it has an | |
1930 | -- incomplete untagged formal (RM 13.14(10.2/3)). | |
1931 | ||
fc193526 HK |
1932 | function Has_Class_Wide_Actual return Boolean; |
1933 | -- Ada 2012 (AI05-071, AI05-0131): True if N is the renaming for a | |
1934 | -- defaulted formal subprogram where the actual for the controlling | |
1935 | -- formal type is class-wide. | |
1936 | ||
07fc65c4 | 1937 | function Original_Subprogram (Subp : Entity_Id) return Entity_Id; |
16ca248a ES |
1938 | -- Find renamed entity when the declaration is a renaming_as_body and |
1939 | -- the renamed entity may itself be a renaming_as_body. Used to enforce | |
1940 | -- rule that a renaming_as_body is illegal if the declaration occurs | |
1941 | -- before the subprogram it completes is frozen, and renaming indirectly | |
1942 | -- renames the subprogram itself.(Defect Report 8652/0027). | |
07fc65c4 | 1943 | |
fc193526 HK |
1944 | ------------------------------ |
1945 | -- Build_Class_Wide_Wrapper -- | |
1946 | ------------------------------ | |
1138cf59 | 1947 | |
fc193526 HK |
1948 | procedure Build_Class_Wide_Wrapper |
1949 | (Ren_Id : out Entity_Id; | |
1950 | Wrap_Id : out Entity_Id) | |
1951 | is | |
1138cf59 AC |
1952 | Loc : constant Source_Ptr := Sloc (N); |
1953 | ||
e4d04166 AC |
1954 | function Build_Call |
1955 | (Subp_Id : Entity_Id; | |
1956 | Params : List_Id) return Node_Id; | |
1957 | -- Create a dispatching call to invoke routine Subp_Id with actuals | |
1958 | -- built from the parameter specifications of list Params. | |
1959 | ||
27bb7941 AC |
1960 | function Build_Expr_Fun_Call |
1961 | (Subp_Id : Entity_Id; | |
1962 | Params : List_Id) return Node_Id; | |
1963 | -- Create a dispatching call to invoke function Subp_Id with actuals | |
1964 | -- built from the parameter specifications of list Params. Return | |
1965 | -- directly the call, so that it can be used inside an expression | |
1966 | -- function. This is a specificity of the GNATprove mode. | |
1967 | ||
fc193526 HK |
1968 | function Build_Spec (Subp_Id : Entity_Id) return Node_Id; |
1969 | -- Create a subprogram specification based on the subprogram profile | |
1970 | -- of Subp_Id. | |
1138cf59 | 1971 | |
fc193526 HK |
1972 | function Find_Primitive (Typ : Entity_Id) return Entity_Id; |
1973 | -- Find a primitive subprogram of type Typ which matches the profile | |
1974 | -- of the renaming declaration. | |
1138cf59 | 1975 | |
fc193526 HK |
1976 | procedure Interpretation_Error (Subp_Id : Entity_Id); |
1977 | -- Emit a continuation error message suggesting subprogram Subp_Id as | |
1978 | -- a possible interpretation. | |
1138cf59 | 1979 | |
b6621d10 AC |
1980 | function Is_Intrinsic_Equality (Subp_Id : Entity_Id) return Boolean; |
1981 | -- Determine whether subprogram Subp_Id denotes the intrinsic "=" | |
1982 | -- operator. | |
1983 | ||
1984 | function Is_Suitable_Candidate (Subp_Id : Entity_Id) return Boolean; | |
1985 | -- Determine whether subprogram Subp_Id is a suitable candidate for | |
1986 | -- the role of a wrapped subprogram. | |
1987 | ||
fc193526 HK |
1988 | ---------------- |
1989 | -- Build_Call -- | |
1990 | ---------------- | |
1991 | ||
1992 | function Build_Call | |
1993 | (Subp_Id : Entity_Id; | |
1994 | Params : List_Id) return Node_Id | |
1995 | is | |
1996 | Actuals : constant List_Id := New_List; | |
1997 | Call_Ref : constant Node_Id := New_Occurrence_Of (Subp_Id, Loc); | |
1998 | Formal : Node_Id; | |
1138cf59 AC |
1999 | |
2000 | begin | |
fc193526 HK |
2001 | -- Build the actual parameters of the call |
2002 | ||
2003 | Formal := First (Params); | |
2004 | while Present (Formal) loop | |
1138cf59 | 2005 | Append_To (Actuals, |
fc193526 | 2006 | Make_Identifier (Loc, Chars (Defining_Identifier (Formal)))); |
fc193526 | 2007 | Next (Formal); |
1138cf59 AC |
2008 | end loop; |
2009 | ||
fc193526 HK |
2010 | -- Generate: |
2011 | -- return Subp_Id (Actuals); | |
2012 | ||
2013 | if Ekind_In (Subp_Id, E_Function, E_Operator) then | |
2014 | return | |
2015 | Make_Simple_Return_Statement (Loc, | |
2016 | Expression => | |
2017 | Make_Function_Call (Loc, | |
2018 | Name => Call_Ref, | |
2019 | Parameter_Associations => Actuals)); | |
2020 | ||
2021 | -- Generate: | |
2022 | -- Subp_Id (Actuals); | |
2023 | ||
1138cf59 AC |
2024 | else |
2025 | return | |
2026 | Make_Procedure_Call_Statement (Loc, | |
fc193526 HK |
2027 | Name => Call_Ref, |
2028 | Parameter_Associations => Actuals); | |
1138cf59 | 2029 | end if; |
fc193526 | 2030 | end Build_Call; |
1138cf59 | 2031 | |
27bb7941 AC |
2032 | ------------------------- |
2033 | -- Build_Expr_Fun_Call -- | |
2034 | ------------------------- | |
2035 | ||
2036 | function Build_Expr_Fun_Call | |
2037 | (Subp_Id : Entity_Id; | |
2038 | Params : List_Id) return Node_Id | |
2039 | is | |
2040 | Actuals : constant List_Id := New_List; | |
2041 | Call_Ref : constant Node_Id := New_Occurrence_Of (Subp_Id, Loc); | |
2042 | Formal : Node_Id; | |
2043 | ||
2044 | begin | |
e4d04166 AC |
2045 | pragma Assert (Ekind_In (Subp_Id, E_Function, E_Operator)); |
2046 | ||
27bb7941 AC |
2047 | -- Build the actual parameters of the call |
2048 | ||
2049 | Formal := First (Params); | |
2050 | while Present (Formal) loop | |
2051 | Append_To (Actuals, | |
2052 | Make_Identifier (Loc, Chars (Defining_Identifier (Formal)))); | |
2053 | Next (Formal); | |
2054 | end loop; | |
2055 | ||
2056 | -- Generate: | |
2057 | -- Subp_Id (Actuals); | |
2058 | ||
e4d04166 AC |
2059 | return |
2060 | Make_Function_Call (Loc, | |
2061 | Name => Call_Ref, | |
2062 | Parameter_Associations => Actuals); | |
27bb7941 AC |
2063 | end Build_Expr_Fun_Call; |
2064 | ||
fc193526 HK |
2065 | ---------------- |
2066 | -- Build_Spec -- | |
2067 | ---------------- | |
1138cf59 | 2068 | |
fc193526 HK |
2069 | function Build_Spec (Subp_Id : Entity_Id) return Node_Id is |
2070 | Params : constant List_Id := Copy_Parameter_List (Subp_Id); | |
2071 | Spec_Id : constant Entity_Id := | |
6d0b56ad AC |
2072 | Make_Defining_Identifier (Loc, |
2073 | Chars => New_External_Name (Chars (Subp_Id), 'R')); | |
1138cf59 AC |
2074 | |
2075 | begin | |
fc193526 | 2076 | if Ekind (Formal_Spec) = E_Procedure then |
1138cf59 AC |
2077 | return |
2078 | Make_Procedure_Specification (Loc, | |
fc193526 HK |
2079 | Defining_Unit_Name => Spec_Id, |
2080 | Parameter_Specifications => Params); | |
1138cf59 AC |
2081 | else |
2082 | return | |
fc193526 HK |
2083 | Make_Function_Specification (Loc, |
2084 | Defining_Unit_Name => Spec_Id, | |
2085 | Parameter_Specifications => Params, | |
2086 | Result_Definition => | |
2087 | New_Copy_Tree (Result_Definition (Spec))); | |
1138cf59 | 2088 | end if; |
fc193526 HK |
2089 | end Build_Spec; |
2090 | ||
2091 | -------------------- | |
2092 | -- Find_Primitive -- | |
2093 | -------------------- | |
2094 | ||
2095 | function Find_Primitive (Typ : Entity_Id) return Entity_Id is | |
2096 | procedure Replace_Parameter_Types (Spec : Node_Id); | |
2097 | -- Given a specification Spec, replace all class-wide parameter | |
2098 | -- types with reference to type Typ. | |
1138cf59 | 2099 | |
fc193526 HK |
2100 | ----------------------------- |
2101 | -- Replace_Parameter_Types -- | |
2102 | ----------------------------- | |
2103 | ||
2104 | procedure Replace_Parameter_Types (Spec : Node_Id) is | |
2105 | Formal : Node_Id; | |
2106 | Formal_Id : Entity_Id; | |
2107 | Formal_Typ : Node_Id; | |
2108 | ||
2109 | begin | |
2110 | Formal := First (Parameter_Specifications (Spec)); | |
2111 | while Present (Formal) loop | |
2112 | Formal_Id := Defining_Identifier (Formal); | |
2113 | Formal_Typ := Parameter_Type (Formal); | |
2114 | ||
2115 | -- Create a new entity for each class-wide formal to prevent | |
2116 | -- aliasing with the original renaming. Replace the type of | |
2117 | -- such a parameter with the candidate type. | |
2118 | ||
2119 | if Nkind (Formal_Typ) = N_Identifier | |
2120 | and then Is_Class_Wide_Type (Etype (Formal_Typ)) | |
2121 | then | |
2122 | Set_Defining_Identifier (Formal, | |
2123 | Make_Defining_Identifier (Loc, Chars (Formal_Id))); | |
2124 | ||
2125 | Set_Parameter_Type (Formal, New_Occurrence_Of (Typ, Loc)); | |
2126 | end if; | |
2127 | ||
2128 | Next (Formal); | |
2129 | end loop; | |
2130 | end Replace_Parameter_Types; | |
2131 | ||
2132 | -- Local variables | |
2133 | ||
2134 | Alt_Ren : constant Node_Id := New_Copy_Tree (N); | |
2135 | Alt_Nam : constant Node_Id := Name (Alt_Ren); | |
2136 | Alt_Spec : constant Node_Id := Specification (Alt_Ren); | |
2137 | Subp_Id : Entity_Id; | |
2138 | ||
2139 | -- Start of processing for Find_Primitive | |
2140 | ||
2141 | begin | |
2142 | -- Each attempt to find a suitable primitive of a particular type | |
2143 | -- operates on its own copy of the original renaming. As a result | |
2144 | -- the original renaming is kept decoration and side-effect free. | |
2145 | ||
2146 | -- Inherit the overloaded status of the renamed subprogram name | |
2147 | ||
2148 | if Is_Overloaded (Nam) then | |
2149 | Set_Is_Overloaded (Alt_Nam); | |
2150 | Save_Interps (Nam, Alt_Nam); | |
2151 | end if; | |
2152 | ||
2153 | -- The copied renaming is hidden from visibility to prevent the | |
2154 | -- pollution of the enclosing context. | |
2155 | ||
2156 | Set_Defining_Unit_Name (Alt_Spec, Make_Temporary (Loc, 'R')); | |
2157 | ||
2158 | -- The types of all class-wide parameters must be changed to the | |
2159 | -- candidate type. | |
2160 | ||
2161 | Replace_Parameter_Types (Alt_Spec); | |
2162 | ||
2163 | -- Try to find a suitable primitive which matches the altered | |
2164 | -- profile of the renaming specification. | |
2165 | ||
2166 | Subp_Id := | |
2167 | Find_Renamed_Entity | |
2168 | (N => Alt_Ren, | |
2169 | Nam => Name (Alt_Ren), | |
2170 | New_S => Analyze_Subprogram_Specification (Alt_Spec), | |
2171 | Is_Actual => Is_Actual); | |
2172 | ||
2173 | -- Do not return Any_Id if the resolion of the altered profile | |
2174 | -- failed as this complicates further checks on the caller side, | |
2175 | -- return Empty instead. | |
2176 | ||
2177 | if Subp_Id = Any_Id then | |
2178 | return Empty; | |
2179 | else | |
2180 | return Subp_Id; | |
2181 | end if; | |
2182 | end Find_Primitive; | |
2183 | ||
2184 | -------------------------- | |
2185 | -- Interpretation_Error -- | |
2186 | -------------------------- | |
2187 | ||
2188 | procedure Interpretation_Error (Subp_Id : Entity_Id) is | |
2189 | begin | |
2190 | Error_Msg_Sloc := Sloc (Subp_Id); | |
b6621d10 AC |
2191 | |
2192 | if Is_Internal (Subp_Id) then | |
2193 | Error_Msg_NE | |
2194 | ("\\possible interpretation: predefined & #", | |
2195 | Spec, Formal_Spec); | |
2196 | else | |
2197 | Error_Msg_NE | |
2198 | ("\\possible interpretation: & defined #", Spec, Formal_Spec); | |
2199 | end if; | |
fc193526 HK |
2200 | end Interpretation_Error; |
2201 | ||
b6621d10 AC |
2202 | --------------------------- |
2203 | -- Is_Intrinsic_Equality -- | |
2204 | --------------------------- | |
2205 | ||
2206 | function Is_Intrinsic_Equality (Subp_Id : Entity_Id) return Boolean is | |
2207 | begin | |
2208 | return | |
2209 | Ekind (Subp_Id) = E_Operator | |
2210 | and then Chars (Subp_Id) = Name_Op_Eq | |
2211 | and then Is_Intrinsic_Subprogram (Subp_Id); | |
2212 | end Is_Intrinsic_Equality; | |
2213 | ||
2214 | --------------------------- | |
2215 | -- Is_Suitable_Candidate -- | |
2216 | --------------------------- | |
2217 | ||
2218 | function Is_Suitable_Candidate (Subp_Id : Entity_Id) return Boolean is | |
2219 | begin | |
2220 | if No (Subp_Id) then | |
2221 | return False; | |
2222 | ||
2223 | -- An intrinsic subprogram is never a good candidate. This is an | |
2224 | -- indication of a missing primitive, either defined directly or | |
2225 | -- inherited from a parent tagged type. | |
2226 | ||
2227 | elsif Is_Intrinsic_Subprogram (Subp_Id) then | |
2228 | return False; | |
2229 | ||
2230 | else | |
2231 | return True; | |
2232 | end if; | |
2233 | end Is_Suitable_Candidate; | |
2234 | ||
fc193526 HK |
2235 | -- Local variables |
2236 | ||
2237 | Actual_Typ : Entity_Id := Empty; | |
2238 | -- The actual class-wide type for Formal_Typ | |
2239 | ||
b6621d10 | 2240 | CW_Prim_OK : Boolean; |
fc193526 | 2241 | CW_Prim_Op : Entity_Id; |
b6621d10 AC |
2242 | -- The class-wide subprogram (if available) which corresponds to the |
2243 | -- renamed generic formal subprogram. | |
fc193526 HK |
2244 | |
2245 | Formal_Typ : Entity_Id := Empty; | |
b6621d10 | 2246 | -- The generic formal type with unknown discriminants |
fc193526 | 2247 | |
b6621d10 | 2248 | Root_Prim_OK : Boolean; |
fc193526 | 2249 | Root_Prim_Op : Entity_Id; |
b6621d10 AC |
2250 | -- The root type primitive (if available) which corresponds to the |
2251 | -- renamed generic formal subprogram. | |
2252 | ||
2253 | Root_Typ : Entity_Id := Empty; | |
2254 | -- The root type of Actual_Typ | |
fc193526 HK |
2255 | |
2256 | Body_Decl : Node_Id; | |
2257 | Formal : Node_Id; | |
2258 | Prim_Op : Entity_Id; | |
2259 | Spec_Decl : Node_Id; | |
27bb7941 | 2260 | New_Spec : Node_Id; |
fc193526 HK |
2261 | |
2262 | -- Start of processing for Build_Class_Wide_Wrapper | |
1138cf59 AC |
2263 | |
2264 | begin | |
fc193526 HK |
2265 | -- Analyze the specification of the renaming in case the generation |
2266 | -- of the class-wide wrapper fails. | |
2267 | ||
2268 | Ren_Id := Analyze_Subprogram_Specification (Spec); | |
2269 | Wrap_Id := Any_Id; | |
2270 | ||
2271 | -- Do not attempt to build a wrapper if the renaming is in error | |
2272 | ||
2273 | if Error_Posted (Nam) then | |
2274 | return; | |
2275 | end if; | |
2276 | ||
2277 | -- Analyze the renamed name, but do not resolve it. The resolution is | |
b6621d10 | 2278 | -- completed once a suitable subprogram is found. |
fc193526 HK |
2279 | |
2280 | Analyze (Nam); | |
2281 | ||
b6621d10 AC |
2282 | -- When the renamed name denotes the intrinsic operator equals, the |
2283 | -- name must be treated as overloaded. This allows for a potential | |
2284 | -- match against the root type's predefined equality function. | |
2285 | ||
2286 | if Is_Intrinsic_Equality (Entity (Nam)) then | |
2287 | Set_Is_Overloaded (Nam); | |
2288 | Collect_Interps (Nam); | |
2289 | end if; | |
2290 | ||
fc193526 HK |
2291 | -- Step 1: Find the generic formal type with unknown discriminants |
2292 | -- and its corresponding class-wide actual type from the renamed | |
2293 | -- generic formal subprogram. | |
2294 | ||
2295 | Formal := First_Formal (Formal_Spec); | |
2296 | while Present (Formal) loop | |
2297 | if Has_Unknown_Discriminants (Etype (Formal)) | |
2298 | and then not Is_Class_Wide_Type (Etype (Formal)) | |
2299 | and then Is_Class_Wide_Type (Get_Instance_Of (Etype (Formal))) | |
1138cf59 | 2300 | then |
fc193526 HK |
2301 | Formal_Typ := Etype (Formal); |
2302 | Actual_Typ := Get_Instance_Of (Formal_Typ); | |
b6621d10 | 2303 | Root_Typ := Etype (Actual_Typ); |
1138cf59 AC |
2304 | exit; |
2305 | end if; | |
2306 | ||
fc193526 | 2307 | Next_Formal (Formal); |
1138cf59 AC |
2308 | end loop; |
2309 | ||
fc193526 HK |
2310 | -- The specification of the generic formal subprogram should always |
2311 | -- contain a formal type with unknown discriminants whose actual is | |
2312 | -- a class-wide type, otherwise this indicates a failure in routine | |
2313 | -- Has_Class_Wide_Actual. | |
1138cf59 | 2314 | |
fc193526 | 2315 | pragma Assert (Present (Formal_Typ)); |
1138cf59 | 2316 | |
b6621d10 AC |
2317 | -- Step 2: Find the proper class-wide subprogram or primitive which |
2318 | -- corresponds to the renamed generic formal subprogram. | |
1138cf59 | 2319 | |
fc193526 | 2320 | CW_Prim_Op := Find_Primitive (Actual_Typ); |
b6621d10 AC |
2321 | CW_Prim_OK := Is_Suitable_Candidate (CW_Prim_Op); |
2322 | Root_Prim_Op := Find_Primitive (Root_Typ); | |
2323 | Root_Prim_OK := Is_Suitable_Candidate (Root_Prim_Op); | |
1138cf59 | 2324 | |
b6621d10 | 2325 | -- The class-wide actual type has two subprograms which correspond to |
fc193526 | 2326 | -- the renamed generic formal subprogram: |
1138cf59 | 2327 | |
fc193526 HK |
2328 | -- with procedure Prim_Op (Param : Formal_Typ); |
2329 | ||
2330 | -- procedure Prim_Op (Param : Actual_Typ); -- may be inherited | |
2331 | -- procedure Prim_Op (Param : Actual_Typ'Class); | |
2332 | ||
b6621d10 AC |
2333 | -- Even though the declaration of the two subprograms is legal, a |
2334 | -- call to either one is ambiguous and therefore illegal. | |
fc193526 | 2335 | |
b6621d10 | 2336 | if CW_Prim_OK and Root_Prim_OK then |
fc193526 | 2337 | |
b6621d10 | 2338 | -- A user-defined primitive has precedence over a predefined one |
fc193526 | 2339 | |
b6621d10 AC |
2340 | if Is_Internal (CW_Prim_Op) |
2341 | and then not Is_Internal (Root_Prim_Op) | |
fc193526 | 2342 | then |
fc193526 | 2343 | Prim_Op := Root_Prim_Op; |
1138cf59 | 2344 | |
b6621d10 AC |
2345 | elsif Is_Internal (Root_Prim_Op) |
2346 | and then not Is_Internal (CW_Prim_Op) | |
2347 | then | |
fc193526 | 2348 | Prim_Op := CW_Prim_Op; |
1138cf59 | 2349 | |
fc193526 HK |
2350 | elsif CW_Prim_Op = Root_Prim_Op then |
2351 | Prim_Op := Root_Prim_Op; | |
1138cf59 | 2352 | |
b6621d10 AC |
2353 | -- Otherwise both candidate subprograms are user-defined and |
2354 | -- ambiguous. | |
1138cf59 | 2355 | |
fc193526 HK |
2356 | else |
2357 | Error_Msg_NE | |
2358 | ("ambiguous actual for generic subprogram &", | |
b6621d10 | 2359 | Spec, Formal_Spec); |
fc193526 | 2360 | Interpretation_Error (Root_Prim_Op); |
b6621d10 | 2361 | Interpretation_Error (CW_Prim_Op); |
fc193526 | 2362 | return; |
f4f92d9d | 2363 | end if; |
1138cf59 | 2364 | |
b6621d10 | 2365 | elsif CW_Prim_OK and not Root_Prim_OK then |
fc193526 HK |
2366 | Prim_Op := CW_Prim_Op; |
2367 | ||
b6621d10 AC |
2368 | elsif not CW_Prim_OK and Root_Prim_OK then |
2369 | Prim_Op := Root_Prim_Op; | |
2370 | ||
2371 | -- An intrinsic equality may act as a suitable candidate in the case | |
2372 | -- of a null type extension where the parent's equality is hidden. A | |
2373 | -- call to an intrinsic equality is expanded as dispatching. | |
2374 | ||
2375 | elsif Present (Root_Prim_Op) | |
2376 | and then Is_Intrinsic_Equality (Root_Prim_Op) | |
2377 | then | |
fc193526 HK |
2378 | Prim_Op := Root_Prim_Op; |
2379 | ||
b6621d10 | 2380 | -- Otherwise there are no candidate subprograms. Let the caller |
fc193526 HK |
2381 | -- diagnose the error. |
2382 | ||
2383 | else | |
2384 | return; | |
2385 | end if; | |
2386 | ||
6d0b56ad AC |
2387 | -- At this point resolution has taken place and the name is no longer |
2388 | -- overloaded. Mark the primitive as referenced. | |
fc193526 | 2389 | |
6d0b56ad | 2390 | Set_Is_Overloaded (Name (N), False); |
ad5edba5 | 2391 | Set_Referenced (Prim_Op); |
fc193526 | 2392 | |
66340e0e AC |
2393 | -- Do not generate a wrapper when the only candidate is a class-wide |
2394 | -- subprogram. Instead modify the renaming to directly map the actual | |
2395 | -- to the generic formal. | |
2396 | ||
2397 | if CW_Prim_OK and then Prim_Op = CW_Prim_Op then | |
2398 | Wrap_Id := Prim_Op; | |
2399 | Rewrite (Nam, New_Occurrence_Of (Prim_Op, Loc)); | |
2400 | return; | |
2401 | end if; | |
2402 | ||
fc193526 HK |
2403 | -- Step 3: Create the declaration and the body of the wrapper, insert |
2404 | -- all the pieces into the tree. | |
2405 | ||
27bb7941 AC |
2406 | -- In GNATprove mode, create a function wrapper in the form of an |
2407 | -- expression function, so that an implicit postcondition relating | |
2408 | -- the result of calling the wrapper function and the result of the | |
2409 | -- dispatching call to the wrapped function is known during proof. | |
2410 | ||
2411 | if GNATprove_Mode | |
2412 | and then Ekind_In (Ren_Id, E_Function, E_Operator) | |
2413 | then | |
2414 | New_Spec := Build_Spec (Ren_Id); | |
2415 | Body_Decl := | |
2416 | Make_Expression_Function (Loc, | |
2417 | Specification => New_Spec, | |
e4d04166 AC |
2418 | Expression => |
2419 | Build_Expr_Fun_Call | |
2420 | (Subp_Id => Prim_Op, | |
2421 | Params => Parameter_Specifications (New_Spec))); | |
27bb7941 AC |
2422 | |
2423 | Wrap_Id := Defining_Entity (Body_Decl); | |
2424 | ||
2425 | -- Otherwise, create separate spec and body for the subprogram | |
2426 | ||
2427 | else | |
2428 | Spec_Decl := | |
2429 | Make_Subprogram_Declaration (Loc, | |
2430 | Specification => Build_Spec (Ren_Id)); | |
2431 | Insert_Before_And_Analyze (N, Spec_Decl); | |
2432 | ||
2433 | Wrap_Id := Defining_Entity (Spec_Decl); | |
2434 | ||
2435 | Body_Decl := | |
2436 | Make_Subprogram_Body (Loc, | |
2437 | Specification => Build_Spec (Ren_Id), | |
2438 | Declarations => New_List, | |
2439 | Handled_Statement_Sequence => | |
2440 | Make_Handled_Sequence_Of_Statements (Loc, | |
2441 | Statements => New_List ( | |
2442 | Build_Call | |
2443 | (Subp_Id => Prim_Op, | |
2444 | Params => | |
2445 | Parameter_Specifications | |
2446 | (Specification (Spec_Decl)))))); | |
2447 | ||
2448 | Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl)); | |
2449 | end if; | |
6d0b56ad AC |
2450 | |
2451 | -- If the operator carries an Eliminated pragma, indicate that the | |
2452 | -- wrapper is also to be eliminated, to prevent spurious error when | |
2453 | -- using gnatelim on programs that include box-initialization of | |
2454 | -- equality operators. | |
2455 | ||
6d0b56ad | 2456 | Set_Is_Eliminated (Wrap_Id, Is_Eliminated (Prim_Op)); |
fc193526 | 2457 | |
27bb7941 AC |
2458 | -- In GNATprove mode, insert the body in the tree for analysis |
2459 | ||
2460 | if GNATprove_Mode then | |
2461 | Insert_Before_And_Analyze (N, Body_Decl); | |
2462 | end if; | |
fc193526 | 2463 | |
fc193526 HK |
2464 | -- The generated body does not freeze and must be analyzed when the |
2465 | -- class-wide wrapper is frozen. The body is only needed if expansion | |
2466 | -- is enabled. | |
2467 | ||
2468 | if Expander_Active then | |
2469 | Append_Freeze_Action (Wrap_Id, Body_Decl); | |
1138cf59 AC |
2470 | end if; |
2471 | ||
6d0b56ad | 2472 | -- Step 4: The subprogram renaming aliases the wrapper |
1138cf59 | 2473 | |
6d0b56ad | 2474 | Rewrite (Nam, New_Occurrence_Of (Wrap_Id, Loc)); |
fc193526 | 2475 | end Build_Class_Wide_Wrapper; |
1138cf59 | 2476 | |
923fa078 RD |
2477 | -------------------------- |
2478 | -- Check_Null_Exclusion -- | |
2479 | -------------------------- | |
2480 | ||
2481 | procedure Check_Null_Exclusion | |
2482 | (Ren : Entity_Id; | |
2483 | Sub : Entity_Id) | |
2484 | is | |
16ca248a ES |
2485 | Ren_Formal : Entity_Id; |
2486 | Sub_Formal : Entity_Id; | |
923fa078 RD |
2487 | |
2488 | begin | |
2489 | -- Parameter check | |
2490 | ||
16ca248a ES |
2491 | Ren_Formal := First_Formal (Ren); |
2492 | Sub_Formal := First_Formal (Sub); | |
ac7d724d | 2493 | while Present (Ren_Formal) and then Present (Sub_Formal) loop |
923fa078 RD |
2494 | if Has_Null_Exclusion (Parent (Ren_Formal)) |
2495 | and then | |
2496 | not (Has_Null_Exclusion (Parent (Sub_Formal)) | |
ac7d724d | 2497 | or else Can_Never_Be_Null (Etype (Sub_Formal))) |
923fa078 | 2498 | then |
fbe627af RD |
2499 | Error_Msg_NE |
2500 | ("`NOT NULL` required for parameter &", | |
2501 | Parent (Sub_Formal), Sub_Formal); | |
923fa078 RD |
2502 | end if; |
2503 | ||
2504 | Next_Formal (Ren_Formal); | |
2505 | Next_Formal (Sub_Formal); | |
2506 | end loop; | |
2507 | ||
2508 | -- Return profile check | |
2509 | ||
2510 | if Nkind (Parent (Ren)) = N_Function_Specification | |
2511 | and then Nkind (Parent (Sub)) = N_Function_Specification | |
2512 | and then Has_Null_Exclusion (Parent (Ren)) | |
ac7d724d ES |
2513 | and then not (Has_Null_Exclusion (Parent (Sub)) |
2514 | or else Can_Never_Be_Null (Etype (Sub))) | |
923fa078 | 2515 | then |
fbe627af RD |
2516 | Error_Msg_N |
2517 | ("return must specify `NOT NULL`", | |
2518 | Result_Definition (Parent (Sub))); | |
923fa078 RD |
2519 | end if; |
2520 | end Check_Null_Exclusion; | |
2521 | ||
02e4edea AC |
2522 | --------------------------- |
2523 | -- Freeze_Actual_Profile -- | |
2524 | --------------------------- | |
2525 | ||
2526 | procedure Freeze_Actual_Profile is | |
2527 | F : Entity_Id; | |
2528 | Has_Untagged_Inc : Boolean; | |
2529 | Instantiation_Node : constant Node_Id := Parent (N); | |
2530 | ||
2531 | begin | |
2532 | if Ada_Version >= Ada_2012 then | |
2533 | F := First_Formal (Formal_Spec); | |
2534 | Has_Untagged_Inc := False; | |
2535 | while Present (F) loop | |
2536 | if Ekind (Etype (F)) = E_Incomplete_Type | |
2537 | and then not Is_Tagged_Type (Etype (F)) | |
2538 | then | |
2539 | Has_Untagged_Inc := True; | |
2540 | exit; | |
2541 | end if; | |
2542 | ||
2543 | F := Next_Formal (F); | |
2544 | end loop; | |
2545 | ||
2546 | if Ekind (Formal_Spec) = E_Function | |
598a56c0 | 2547 | and then not Is_Tagged_Type (Etype (Formal_Spec)) |
02e4edea AC |
2548 | then |
2549 | Has_Untagged_Inc := True; | |
2550 | end if; | |
2551 | ||
2552 | if not Has_Untagged_Inc then | |
2553 | F := First_Formal (Old_S); | |
2554 | while Present (F) loop | |
2555 | Freeze_Before (Instantiation_Node, Etype (F)); | |
2556 | ||
2557 | if Is_Incomplete_Or_Private_Type (Etype (F)) | |
2558 | and then No (Underlying_Type (Etype (F))) | |
02e4edea | 2559 | then |
6ee07c61 AC |
2560 | -- Exclude generic types, or types derived from them. |
2561 | -- They will be frozen in the enclosing instance. | |
2562 | ||
2563 | if Is_Generic_Type (Etype (F)) | |
2564 | or else Is_Generic_Type (Root_Type (Etype (F))) | |
2565 | then | |
2566 | null; | |
598a56c0 ES |
2567 | |
2568 | -- A limited view of a type declared elsewhere needs no | |
2569 | -- freezing actions. | |
2570 | ||
2571 | elsif From_Limited_With (Etype (F)) then | |
2572 | null; | |
2573 | ||
6ee07c61 AC |
2574 | else |
2575 | Error_Msg_NE | |
2576 | ("type& must be frozen before this point", | |
67a90476 | 2577 | Instantiation_Node, Etype (F)); |
6ee07c61 | 2578 | end if; |
02e4edea AC |
2579 | end if; |
2580 | ||
2581 | F := Next_Formal (F); | |
2582 | end loop; | |
2583 | end if; | |
2584 | end if; | |
2585 | end Freeze_Actual_Profile; | |
2586 | ||
fd3d2680 AC |
2587 | --------------------------- |
2588 | -- Has_Class_Wide_Actual -- | |
2589 | --------------------------- | |
2590 | ||
2591 | function Has_Class_Wide_Actual return Boolean is | |
fc193526 HK |
2592 | Formal : Entity_Id; |
2593 | Formal_Typ : Entity_Id; | |
fd3d2680 AC |
2594 | |
2595 | begin | |
fc193526 HK |
2596 | if Is_Actual then |
2597 | Formal := First_Formal (Formal_Spec); | |
2598 | while Present (Formal) loop | |
2599 | Formal_Typ := Etype (Formal); | |
2600 | ||
2601 | if Has_Unknown_Discriminants (Formal_Typ) | |
2602 | and then not Is_Class_Wide_Type (Formal_Typ) | |
2603 | and then Is_Class_Wide_Type (Get_Instance_Of (Formal_Typ)) | |
fd3d2680 AC |
2604 | then |
2605 | return True; | |
2606 | end if; | |
2607 | ||
fc193526 | 2608 | Next_Formal (Formal); |
fd3d2680 AC |
2609 | end loop; |
2610 | end if; | |
2611 | ||
2612 | return False; | |
2613 | end Has_Class_Wide_Actual; | |
2614 | ||
07fc65c4 GB |
2615 | ------------------------- |
2616 | -- Original_Subprogram -- | |
2617 | ------------------------- | |
2618 | ||
2619 | function Original_Subprogram (Subp : Entity_Id) return Entity_Id is | |
2620 | Orig_Decl : Node_Id; | |
2621 | Orig_Subp : Entity_Id; | |
2622 | ||
2623 | begin | |
2624 | -- First case: renamed entity is itself a renaming | |
2625 | ||
2626 | if Present (Alias (Subp)) then | |
2627 | return Alias (Subp); | |
2628 | ||
ac7d724d ES |
2629 | elsif Nkind (Unit_Declaration_Node (Subp)) = N_Subprogram_Declaration |
2630 | and then Present (Corresponding_Body (Unit_Declaration_Node (Subp))) | |
07fc65c4 GB |
2631 | then |
2632 | -- Check if renamed entity is a renaming_as_body | |
2633 | ||
2634 | Orig_Decl := | |
2635 | Unit_Declaration_Node | |
2636 | (Corresponding_Body (Unit_Declaration_Node (Subp))); | |
2637 | ||
2638 | if Nkind (Orig_Decl) = N_Subprogram_Renaming_Declaration then | |
2639 | Orig_Subp := Entity (Name (Orig_Decl)); | |
2640 | ||
2641 | if Orig_Subp = Rename_Spec then | |
2642 | ||
bc41faa2 | 2643 | -- Circularity detected |
07fc65c4 GB |
2644 | |
2645 | return Orig_Subp; | |
2646 | ||
2647 | else | |
2648 | return (Original_Subprogram (Orig_Subp)); | |
2649 | end if; | |
2650 | else | |
2651 | return Subp; | |
2652 | end if; | |
2653 | else | |
2654 | return Subp; | |
2655 | end if; | |
2656 | end Original_Subprogram; | |
2657 | ||
fc193526 HK |
2658 | -- Local variables |
2659 | ||
fd3d2680 AC |
2660 | CW_Actual : constant Boolean := Has_Class_Wide_Actual; |
2661 | -- Ada 2012 (AI05-071, AI05-0131): True if the renaming is for a | |
2662 | -- defaulted formal subprogram when the actual for a related formal | |
2663 | -- type is class-wide. | |
2664 | ||
1af4455a | 2665 | Inst_Node : Node_Id := Empty; |
fc193526 HK |
2666 | New_S : Entity_Id; |
2667 | ||
fbf5a39b | 2668 | -- Start of processing for Analyze_Subprogram_Renaming |
07fc65c4 | 2669 | |
996ae0b0 RK |
2670 | begin |
2671 | -- We must test for the attribute renaming case before the Analyze | |
2672 | -- call because otherwise Sem_Attr will complain that the attribute | |
2673 | -- is missing an argument when it is analyzed. | |
2674 | ||
2675 | if Nkind (Nam) = N_Attribute_Reference then | |
d239991f | 2676 | |
16ca248a ES |
2677 | -- In the case of an abstract formal subprogram association, rewrite |
2678 | -- an actual given by a stream attribute as the name of the | |
2679 | -- corresponding stream primitive of the type. | |
d239991f | 2680 | |
16ca248a ES |
2681 | -- In a generic context the stream operations are not generated, and |
2682 | -- this must be treated as a normal attribute reference, to be | |
2683 | -- expanded in subsequent instantiations. | |
d4810530 | 2684 | |
ac7d724d ES |
2685 | if Is_Actual |
2686 | and then Is_Abstract_Subprogram (Formal_Spec) | |
4460a9bc | 2687 | and then Expander_Active |
d4810530 | 2688 | then |
d239991f | 2689 | declare |
d239991f | 2690 | Prefix_Type : constant Entity_Id := Entity (Prefix (Nam)); |
d65a80fd | 2691 | Stream_Prim : Entity_Id; |
d239991f GD |
2692 | |
2693 | begin | |
2694 | -- The class-wide forms of the stream attributes are not | |
2695 | -- primitive dispatching operations (even though they | |
2696 | -- internally dispatch to a stream attribute). | |
2697 | ||
2698 | if Is_Class_Wide_Type (Prefix_Type) then | |
2699 | Error_Msg_N | |
2700 | ("attribute must be a primitive dispatching operation", | |
2701 | Nam); | |
2702 | return; | |
2703 | end if; | |
2704 | ||
2705 | -- Retrieve the primitive subprogram associated with the | |
16ca248a ES |
2706 | -- attribute. This can only be a stream attribute, since those |
2707 | -- are the only ones that are dispatching (and the actual for | |
2708 | -- an abstract formal subprogram must be dispatching | |
2709 | -- operation). | |
d239991f | 2710 | |
ca811241 | 2711 | case Attribute_Name (Nam) is |
d8f43ee6 | 2712 | when Name_Input => |
ca811241 BD |
2713 | Stream_Prim := |
2714 | Find_Optional_Prim_Op (Prefix_Type, TSS_Stream_Input); | |
d8f43ee6 | 2715 | |
ca811241 BD |
2716 | when Name_Output => |
2717 | Stream_Prim := | |
2718 | Find_Optional_Prim_Op (Prefix_Type, TSS_Stream_Output); | |
d8f43ee6 HK |
2719 | |
2720 | when Name_Read => | |
ca811241 BD |
2721 | Stream_Prim := |
2722 | Find_Optional_Prim_Op (Prefix_Type, TSS_Stream_Read); | |
d8f43ee6 HK |
2723 | |
2724 | when Name_Write => | |
ca811241 BD |
2725 | Stream_Prim := |
2726 | Find_Optional_Prim_Op (Prefix_Type, TSS_Stream_Write); | |
d8f43ee6 HK |
2727 | |
2728 | when others => | |
ca811241 | 2729 | Error_Msg_N |
d65a80fd HK |
2730 | ("attribute must be a primitive dispatching operation", |
2731 | Nam); | |
ca811241 BD |
2732 | return; |
2733 | end case; | |
6a4d72a6 | 2734 | |
d65a80fd HK |
2735 | -- If no operation was found, and the type is limited, the user |
2736 | -- should have defined one. | |
6a4d72a6 | 2737 | |
ca811241 BD |
2738 | if No (Stream_Prim) then |
2739 | if Is_Limited_Type (Prefix_Type) then | |
2740 | Error_Msg_NE | |
2741 | ("stream operation not defined for type&", | |
2742 | N, Prefix_Type); | |
2743 | return; | |
2744 | ||
2745 | -- Otherwise, compiler should have generated default | |
2746 | ||
2747 | else | |
2748 | raise Program_Error; | |
2749 | end if; | |
2750 | end if; | |
d239991f GD |
2751 | |
2752 | -- Rewrite the attribute into the name of its corresponding | |
2753 | -- primitive dispatching subprogram. We can then proceed with | |
2754 | -- the usual processing for subprogram renamings. | |
2755 | ||
2756 | declare | |
2757 | Prim_Name : constant Node_Id := | |
2758 | Make_Identifier (Sloc (Nam), | |
2759 | Chars => Chars (Stream_Prim)); | |
2760 | begin | |
2761 | Set_Entity (Prim_Name, Stream_Prim); | |
2762 | Rewrite (Nam, Prim_Name); | |
2763 | Analyze (Nam); | |
2764 | end; | |
2765 | end; | |
2766 | ||
2767 | -- Normal processing for a renaming of an attribute | |
2768 | ||
2769 | else | |
2770 | Attribute_Renaming (N); | |
2771 | return; | |
2772 | end if; | |
996ae0b0 RK |
2773 | end if; |
2774 | ||
d65a80fd HK |
2775 | -- Check whether this declaration corresponds to the instantiation of a |
2776 | -- formal subprogram. | |
996ae0b0 | 2777 | |
16ca248a ES |
2778 | -- If this is an instantiation, the corresponding actual is frozen and |
2779 | -- error messages can be made more precise. If this is a default | |
2780 | -- subprogram, the entity is already established in the generic, and is | |
2781 | -- not retrieved by visibility. If it is a default with a box, the | |
996ae0b0 | 2782 | -- candidate interpretations, if any, have been collected when building |
16ca248a ES |
2783 | -- the renaming declaration. If overloaded, the proper interpretation is |
2784 | -- determined in Find_Renamed_Entity. If the entity is an operator, | |
996ae0b0 RK |
2785 | -- Find_Renamed_Entity applies additional visibility checks. |
2786 | ||
d239991f GD |
2787 | if Is_Actual then |
2788 | Inst_Node := Unit_Declaration_Node (Formal_Spec); | |
996ae0b0 | 2789 | |
fd3d2680 AC |
2790 | -- Check whether the renaming is for a defaulted actual subprogram |
2791 | -- with a class-wide actual. | |
2792 | ||
1c85591c AC |
2793 | -- The class-wide wrapper is not needed in GNATprove_Mode and there |
2794 | -- is an external axiomatization on the package. | |
c3831524 AC |
2795 | |
2796 | if CW_Actual | |
d65a80fd HK |
2797 | and then Box_Present (Inst_Node) |
2798 | and then not | |
1c85591c AC |
2799 | (GNATprove_Mode |
2800 | and then | |
2801 | Present (Containing_Package_With_Ext_Axioms (Formal_Spec))) | |
c3831524 | 2802 | then |
fc193526 | 2803 | Build_Class_Wide_Wrapper (New_S, Old_S); |
fd3d2680 AC |
2804 | |
2805 | elsif Is_Entity_Name (Nam) | |
996ae0b0 RK |
2806 | and then Present (Entity (Nam)) |
2807 | and then not Comes_From_Source (Nam) | |
2808 | and then not Is_Overloaded (Nam) | |
2809 | then | |
2810 | Old_S := Entity (Nam); | |
d65a80fd HK |
2811 | |
2812 | -- The subprogram renaming declaration may become Ghost if it | |
2813 | -- renames a Ghost entity. | |
2814 | ||
2815 | Mark_Ghost_Renaming (N, Old_S); | |
2816 | ||
fbf5a39b | 2817 | New_S := Analyze_Subprogram_Specification (Spec); |
996ae0b0 | 2818 | |
2e071734 AC |
2819 | -- Operator case |
2820 | ||
d65a80fd | 2821 | if Ekind (Old_S) = E_Operator then |
2e071734 AC |
2822 | |
2823 | -- Box present | |
2824 | ||
2825 | if Box_Present (Inst_Node) then | |
2826 | Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual); | |
2827 | ||
2828 | -- If there is an immediately visible homonym of the operator | |
2829 | -- and the declaration has a default, this is worth a warning | |
2830 | -- because the user probably did not intend to get the pre- | |
16ca248a ES |
2831 | -- defined operator, visible in the generic declaration. To |
2832 | -- find if there is an intended candidate, analyze the renaming | |
2833 | -- again in the current context. | |
2e071734 AC |
2834 | |
2835 | elsif Scope (Old_S) = Standard_Standard | |
2836 | and then Present (Default_Name (Inst_Node)) | |
2837 | then | |
2838 | declare | |
2839 | Decl : constant Node_Id := New_Copy_Tree (N); | |
2840 | Hidden : Entity_Id; | |
2841 | ||
2842 | begin | |
2843 | Set_Entity (Name (Decl), Empty); | |
2844 | Analyze (Name (Decl)); | |
2845 | Hidden := | |
2846 | Find_Renamed_Entity (Decl, Name (Decl), New_S, True); | |
2847 | ||
2848 | if Present (Hidden) | |
2849 | and then In_Open_Scopes (Scope (Hidden)) | |
2850 | and then Is_Immediately_Visible (Hidden) | |
2851 | and then Comes_From_Source (Hidden) | |
923fa078 | 2852 | and then Hidden /= Old_S |
2e071734 AC |
2853 | then |
2854 | Error_Msg_Sloc := Sloc (Hidden); | |
d65a80fd HK |
2855 | Error_Msg_N |
2856 | ("default subprogram is resolved in the generic " | |
2857 | & "declaration (RM 12.6(17))??", N); | |
dbfeb4fa | 2858 | Error_Msg_NE ("\and will not use & #??", N, Hidden); |
2e071734 AC |
2859 | end if; |
2860 | end; | |
2861 | end if; | |
996ae0b0 RK |
2862 | end if; |
2863 | ||
2864 | else | |
2865 | Analyze (Nam); | |
d65a80fd HK |
2866 | |
2867 | -- The subprogram renaming declaration may become Ghost if it | |
2868 | -- renames a Ghost entity. | |
2869 | ||
2870 | if Is_Entity_Name (Nam) then | |
2871 | Mark_Ghost_Renaming (N, Entity (Nam)); | |
2872 | end if; | |
2873 | ||
fbf5a39b | 2874 | New_S := Analyze_Subprogram_Specification (Spec); |
996ae0b0 RK |
2875 | end if; |
2876 | ||
996ae0b0 RK |
2877 | else |
2878 | -- Renamed entity must be analyzed first, to avoid being hidden by | |
2879 | -- new name (which might be the same in a generic instance). | |
2880 | ||
2881 | Analyze (Nam); | |
2882 | ||
d65a80fd HK |
2883 | -- The subprogram renaming declaration may become Ghost if it renames |
2884 | -- a Ghost entity. | |
2885 | ||
2886 | if Is_Entity_Name (Nam) then | |
2887 | Mark_Ghost_Renaming (N, Entity (Nam)); | |
2888 | end if; | |
2889 | ||
996ae0b0 RK |
2890 | -- The renaming defines a new overloaded entity, which is analyzed |
2891 | -- like a subprogram declaration. | |
2892 | ||
fbf5a39b | 2893 | New_S := Analyze_Subprogram_Specification (Spec); |
996ae0b0 RK |
2894 | end if; |
2895 | ||
2896 | if Current_Scope /= Standard_Standard then | |
2897 | Set_Is_Pure (New_S, Is_Pure (Current_Scope)); | |
2898 | end if; | |
2899 | ||
74c10109 AC |
2900 | -- Set SPARK mode from current context |
2901 | ||
2902 | Set_SPARK_Pragma (New_S, SPARK_Mode_Pragma); | |
f145ece7 | 2903 | Set_SPARK_Pragma_Inherited (New_S); |
74c10109 | 2904 | |
996ae0b0 RK |
2905 | Rename_Spec := Find_Corresponding_Spec (N); |
2906 | ||
294ccb21 RD |
2907 | -- Case of Renaming_As_Body |
2908 | ||
996ae0b0 | 2909 | if Present (Rename_Spec) then |
8489c295 AC |
2910 | Check_Previous_Null_Procedure (N, Rename_Spec); |
2911 | ||
294ccb21 RD |
2912 | -- Renaming declaration is the completion of the declaration of |
2913 | -- Rename_Spec. We build an actual body for it at the freezing point. | |
996ae0b0 RK |
2914 | |
2915 | Set_Corresponding_Spec (N, Rename_Spec); | |
fbe627af | 2916 | |
ff81221b ES |
2917 | -- Deal with special case of stream functions of abstract types |
2918 | -- and interfaces. | |
294ccb21 | 2919 | |
d4810530 ES |
2920 | if Nkind (Unit_Declaration_Node (Rename_Spec)) = |
2921 | N_Abstract_Subprogram_Declaration | |
2922 | then | |
ff81221b ES |
2923 | -- Input stream functions are abstract if the object type is |
2924 | -- abstract. Similarly, all default stream functions for an | |
30783513 | 2925 | -- interface type are abstract. However, these subprograms may |
ff81221b ES |
2926 | -- receive explicit declarations in representation clauses, making |
2927 | -- the attribute subprograms usable as defaults in subsequent | |
2928 | -- type extensions. | |
d4810530 ES |
2929 | -- In this case we rewrite the declaration to make the subprogram |
2930 | -- non-abstract. We remove the previous declaration, and insert | |
2931 | -- the new one at the point of the renaming, to prevent premature | |
2932 | -- access to unfrozen types. The new declaration reuses the | |
2933 | -- specification of the previous one, and must not be analyzed. | |
2934 | ||
ff81221b ES |
2935 | pragma Assert |
2936 | (Is_Primitive (Entity (Nam)) | |
ac7d724d ES |
2937 | and then |
2938 | Is_Abstract_Type (Find_Dispatching_Type (Entity (Nam)))); | |
d4810530 ES |
2939 | declare |
2940 | Old_Decl : constant Node_Id := | |
2941 | Unit_Declaration_Node (Rename_Spec); | |
2942 | New_Decl : constant Node_Id := | |
2943 | Make_Subprogram_Declaration (Sloc (N), | |
2944 | Specification => | |
2945 | Relocate_Node (Specification (Old_Decl))); | |
2946 | begin | |
2947 | Remove (Old_Decl); | |
2948 | Insert_After (N, New_Decl); | |
16ca248a | 2949 | Set_Is_Abstract_Subprogram (Rename_Spec, False); |
d4810530 ES |
2950 | Set_Analyzed (New_Decl); |
2951 | end; | |
2952 | end if; | |
2953 | ||
996ae0b0 RK |
2954 | Set_Corresponding_Body (Unit_Declaration_Node (Rename_Spec), New_S); |
2955 | ||
0ab80019 | 2956 | if Ada_Version = Ada_83 and then Comes_From_Source (N) then |
996ae0b0 RK |
2957 | Error_Msg_N ("(Ada 83) renaming cannot serve as a body", N); |
2958 | end if; | |
2959 | ||
923fa078 | 2960 | Set_Convention (New_S, Convention (Rename_Spec)); |
996ae0b0 RK |
2961 | Check_Fully_Conformant (New_S, Rename_Spec); |
2962 | Set_Public_Status (New_S); | |
2963 | ||
e9238cc1 | 2964 | if No_Return (Rename_Spec) |
c99ab5f9 | 2965 | and then not No_Return (Entity (Nam)) |
e9238cc1 AC |
2966 | then |
2967 | Error_Msg_N ("renaming completes a No_Return procedure", N); | |
2968 | Error_Msg_N | |
2969 | ("\renamed procedure must be nonreturning (RM 6.5.1 (7/2))", N); | |
2970 | end if; | |
2971 | ||
294ccb21 RD |
2972 | -- The specification does not introduce new formals, but only |
2973 | -- repeats the formals of the original subprogram declaration. | |
2974 | -- For cross-reference purposes, and for refactoring tools, we | |
2975 | -- treat the formals of the renaming declaration as body formals. | |
2976 | ||
2977 | Reference_Body_Formals (Rename_Spec, New_S); | |
2978 | ||
4de287c4 ES |
2979 | -- Indicate that the entity in the declaration functions like the |
2980 | -- corresponding body, and is not a new entity. The body will be | |
2981 | -- constructed later at the freeze point, so indicate that the | |
2982 | -- completion has not been seen yet. | |
996ae0b0 RK |
2983 | |
2984 | Set_Ekind (New_S, E_Subprogram_Body); | |
2985 | New_S := Rename_Spec; | |
5eb10f25 | 2986 | Set_Has_Completion (Rename_Spec, False); |
996ae0b0 | 2987 | |
4de287c4 | 2988 | -- Ada 2005: check overriding indicator |
edd63e9b | 2989 | |
038140ed | 2990 | if Present (Overridden_Operation (Rename_Spec)) then |
235f4375 AC |
2991 | if Must_Not_Override (Specification (N)) then |
2992 | Error_Msg_NE | |
2993 | ("subprogram& overrides inherited operation", | |
2994 | N, Rename_Spec); | |
d65a80fd HK |
2995 | |
2996 | elsif Style_Check | |
2997 | and then not Must_Override (Specification (N)) | |
235f4375 AC |
2998 | then |
2999 | Style.Missing_Overriding (N, Rename_Spec); | |
3000 | end if; | |
edd63e9b | 3001 | |
235f4375 AC |
3002 | elsif Must_Override (Specification (N)) then |
3003 | Error_Msg_NE ("subprogram& is not overriding", N, Rename_Spec); | |
edd63e9b ES |
3004 | end if; |
3005 | ||
294ccb21 RD |
3006 | -- Normal subprogram renaming (not renaming as body) |
3007 | ||
996ae0b0 RK |
3008 | else |
3009 | Generate_Definition (New_S); | |
3010 | New_Overloaded_Entity (New_S); | |
edd63e9b | 3011 | |
996ae0b0 RK |
3012 | if Is_Entity_Name (Nam) |
3013 | and then Is_Intrinsic_Subprogram (Entity (Nam)) | |
3014 | then | |
3015 | null; | |
3016 | else | |
3017 | Check_Delayed_Subprogram (New_S); | |
3018 | end if; | |
3019 | end if; | |
3020 | ||
4de287c4 ES |
3021 | -- There is no need for elaboration checks on the new entity, which may |
3022 | -- be called before the next freezing point where the body will appear. | |
3023 | -- Elaboration checks refer to the real entity, not the one created by | |
3024 | -- the renaming declaration. | |
996ae0b0 | 3025 | |
ee6208f2 AC |
3026 | Set_Kill_Elaboration_Checks (New_S, True); |
3027 | ||
3028 | -- If we had a previous error, indicate a completely is present to stop | |
3029 | -- junk cascaded messages, but don't take any further action. | |
996ae0b0 RK |
3030 | |
3031 | if Etype (Nam) = Any_Type then | |
3032 | Set_Has_Completion (New_S); | |
3033 | return; | |
3034 | ||
ee6208f2 AC |
3035 | -- Case where name has the form of a selected component |
3036 | ||
996ae0b0 RK |
3037 | elsif Nkind (Nam) = N_Selected_Component then |
3038 | ||
ee6208f2 | 3039 | -- A name which has the form A.B can designate an entry of task A, a |
294ccb21 RD |
3040 | -- protected operation of protected object A, or finally a primitive |
3041 | -- operation of object A. In the later case, A is an object of some | |
3042 | -- tagged type, or an access type that denotes one such. To further | |
3043 | -- distinguish these cases, note that the scope of a task entry or | |
3044 | -- protected operation is type of the prefix. | |
996ae0b0 | 3045 | |
294ccb21 RD |
3046 | -- The prefix could be an overloaded function call that returns both |
3047 | -- kinds of operations. This overloading pathology is left to the | |
3048 | -- dedicated reader ??? | |
3049 | ||
3050 | declare | |
3051 | T : constant Entity_Id := Etype (Prefix (Nam)); | |
3052 | ||
3053 | begin | |
3054 | if Present (T) | |
3055 | and then | |
3056 | (Is_Tagged_Type (T) | |
3057 | or else | |
3058 | (Is_Access_Type (T) | |
ac7d724d | 3059 | and then Is_Tagged_Type (Designated_Type (T)))) |
294ccb21 RD |
3060 | and then Scope (Entity (Selector_Name (Nam))) /= T |
3061 | then | |
3062 | Analyze_Renamed_Primitive_Operation | |
3063 | (N, New_S, Present (Rename_Spec)); | |
3064 | return; | |
3065 | ||
3066 | else | |
3067 | -- Renamed entity is an entry or protected operation. For those | |
3068 | -- cases an explicit body is built (at the point of freezing of | |
3069 | -- this entity) that contains a call to the renamed entity. | |
3070 | ||
3071 | -- This is not allowed for renaming as body if the renamed | |
3072 | -- spec is already frozen (see RM 8.5.4(5) for details). | |
3073 | ||
ac7d724d | 3074 | if Present (Rename_Spec) and then Is_Frozen (Rename_Spec) then |
294ccb21 RD |
3075 | Error_Msg_N |
3076 | ("renaming-as-body cannot rename entry as subprogram", N); | |
3077 | Error_Msg_NE | |
3078 | ("\since & is already frozen (RM 8.5.4(5))", | |
3079 | N, Rename_Spec); | |
3080 | else | |
3081 | Analyze_Renamed_Entry (N, New_S, Present (Rename_Spec)); | |
3082 | end if; | |
3083 | ||
3084 | return; | |
3085 | end if; | |
3086 | end; | |
996ae0b0 | 3087 | |
ee6208f2 AC |
3088 | -- Case where name is an explicit dereference X.all |
3089 | ||
996ae0b0 RK |
3090 | elsif Nkind (Nam) = N_Explicit_Dereference then |
3091 | ||
3092 | -- Renamed entity is designated by access_to_subprogram expression. | |
3093 | -- Must build body to encapsulate call, as in the entry case. | |
3094 | ||
3095 | Analyze_Renamed_Dereference (N, New_S, Present (Rename_Spec)); | |
3096 | return; | |
3097 | ||
ee6208f2 AC |
3098 | -- Indexed component |
3099 | ||
996ae0b0 RK |
3100 | elsif Nkind (Nam) = N_Indexed_Component then |
3101 | Analyze_Renamed_Family_Member (N, New_S, Present (Rename_Spec)); | |
3102 | return; | |
3103 | ||
ee6208f2 AC |
3104 | -- Character literal |
3105 | ||
996ae0b0 RK |
3106 | elsif Nkind (Nam) = N_Character_Literal then |
3107 | Analyze_Renamed_Character (N, New_S, Present (Rename_Spec)); | |
3108 | return; | |
3109 | ||
fc193526 HK |
3110 | -- Only remaining case is where we have a non-entity name, or a renaming |
3111 | -- of some other non-overloadable entity. | |
ee6208f2 | 3112 | |
a3f2babd | 3113 | elsif not Is_Entity_Name (Nam) |
996ae0b0 RK |
3114 | or else not Is_Overloadable (Entity (Nam)) |
3115 | then | |
4674dd21 AC |
3116 | -- Do not mention the renaming if it comes from an instance |
3117 | ||
3118 | if not Is_Actual then | |
3119 | Error_Msg_N ("expect valid subprogram name in renaming", N); | |
4674dd21 AC |
3120 | else |
3121 | Error_Msg_NE ("no visible subprogram for formal&", N, Nam); | |
3122 | end if; | |
3123 | ||
996ae0b0 | 3124 | return; |
996ae0b0 RK |
3125 | end if; |
3126 | ||
11560bcc TQ |
3127 | -- Find the renamed entity that matches the given specification. Disable |
3128 | -- Ada_83 because there is no requirement of full conformance between | |
3129 | -- renamed entity and new entity, even though the same circuit is used. | |
3130 | ||
e80f0cb0 RD |
3131 | -- This is a bit of an odd case, which introduces a really irregular use |
3132 | -- of Ada_Version[_Explicit]. Would be nice to find cleaner way to do | |
3133 | -- this. ??? | |
11560bcc TQ |
3134 | |
3135 | Ada_Version := Ada_Version_Type'Max (Ada_Version, Ada_95); | |
fb620b37 | 3136 | Ada_Version_Pragma := Empty; |
11560bcc TQ |
3137 | Ada_Version_Explicit := Ada_Version; |
3138 | ||
3139 | if No (Old_S) then | |
3140 | Old_S := Find_Renamed_Entity (N, Name (N), New_S, Is_Actual); | |
3141 | ||
1366997b AC |
3142 | -- The visible operation may be an inherited abstract operation that |
3143 | -- was overridden in the private part, in which case a call will | |
3144 | -- dispatch to the overriding operation. Use the overriding one in | |
3145 | -- the renaming declaration, to prevent spurious errors below. | |
3146 | ||
3147 | if Is_Overloadable (Old_S) | |
3148 | and then Is_Abstract_Subprogram (Old_S) | |
3149 | and then No (DTC_Entity (Old_S)) | |
3150 | and then Present (Alias (Old_S)) | |
3151 | and then not Is_Abstract_Subprogram (Alias (Old_S)) | |
038140ed | 3152 | and then Present (Overridden_Operation (Alias (Old_S))) |
1366997b AC |
3153 | then |
3154 | Old_S := Alias (Old_S); | |
3155 | end if; | |
3156 | ||
11560bcc TQ |
3157 | -- When the renamed subprogram is overloaded and used as an actual |
3158 | -- of a generic, its entity is set to the first available homonym. | |
3159 | -- We must first disambiguate the name, then set the proper entity. | |
3160 | ||
1378bf10 | 3161 | if Is_Actual and then Is_Overloaded (Nam) then |
11560bcc TQ |
3162 | Set_Entity (Nam, Old_S); |
3163 | end if; | |
3164 | end if; | |
3165 | ||
4de287c4 ES |
3166 | -- Most common case: subprogram renames subprogram. No body is generated |
3167 | -- in this case, so we must indicate the declaration is complete as is. | |
b2c4d56d | 3168 | -- and inherit various attributes of the renamed subprogram. |
996ae0b0 RK |
3169 | |
3170 | if No (Rename_Spec) then | |
923fa078 | 3171 | Set_Has_Completion (New_S); |
b2c4d56d | 3172 | Set_Is_Imported (New_S, Is_Imported (Entity (Nam))); |
923fa078 RD |
3173 | Set_Is_Pure (New_S, Is_Pure (Entity (Nam))); |
3174 | Set_Is_Preelaborated (New_S, Is_Preelaborated (Entity (Nam))); | |
3175 | ||
3176 | -- Ada 2005 (AI-423): Check the consistency of null exclusions | |
11560bcc | 3177 | -- between a subprogram and its correct renaming. |
923fa078 | 3178 | |
11560bcc TQ |
3179 | -- Note: the Any_Id check is a guard that prevents compiler crashes |
3180 | -- when performing a null exclusion check between a renaming and a | |
3181 | -- renamed subprogram that has been found to be illegal. | |
3182 | ||
ac7d724d | 3183 | if Ada_Version >= Ada_2005 and then Entity (Nam) /= Any_Id then |
923fa078 RD |
3184 | Check_Null_Exclusion |
3185 | (Ren => New_S, | |
3186 | Sub => Entity (Nam)); | |
3187 | end if; | |
90067a15 ES |
3188 | |
3189 | -- Enforce the Ada 2005 rule that the renamed entity cannot require | |
3190 | -- overriding. The flag Requires_Overriding is set very selectively | |
3191 | -- and misses some other illegal cases. The additional conditions | |
3192 | -- checked below are sufficient but not necessary ??? | |
3193 | ||
3194 | -- The rule does not apply to the renaming generated for an actual | |
3195 | -- subprogram in an instance. | |
3196 | ||
3197 | if Is_Actual then | |
3198 | null; | |
3199 | ||
f3d57416 | 3200 | -- Guard against previous errors, and omit renamings of predefined |
90067a15 ES |
3201 | -- operators. |
3202 | ||
bce79204 | 3203 | elsif not Ekind_In (Old_S, E_Function, E_Procedure) then |
90067a15 ES |
3204 | null; |
3205 | ||
3206 | elsif Requires_Overriding (Old_S) | |
3207 | or else | |
3208 | (Is_Abstract_Subprogram (Old_S) | |
3209 | and then Present (Find_Dispatching_Type (Old_S)) | |
3210 | and then | |
3211 | not Is_Abstract_Type (Find_Dispatching_Type (Old_S))) | |
3212 | then | |
3213 | Error_Msg_N | |
d65a80fd HK |
3214 | ("renamed entity cannot be subprogram that requires overriding " |
3215 | & "(RM 8.5.4 (5.1))", N); | |
90067a15 | 3216 | end if; |
321c24f7 AC |
3217 | |
3218 | declare | |
3219 | Prev : constant Entity_Id := Overridden_Operation (New_S); | |
3220 | begin | |
3221 | if Present (Prev) | |
3222 | and then | |
8f34c90b AC |
3223 | (Has_Non_Trivial_Precondition (Prev) |
3224 | or else Has_Non_Trivial_Precondition (Old_S)) | |
321c24f7 | 3225 | then |
8f34c90b AC |
3226 | Error_Msg_NE |
3227 | ("conflicting inherited classwide preconditions in renaming " | |
3228 | & "of& (RM 6.1.1 (17)", N, Old_S); | |
321c24f7 AC |
3229 | end if; |
3230 | end; | |
996ae0b0 RK |
3231 | end if; |
3232 | ||
996ae0b0 | 3233 | if Old_S /= Any_Id then |
1378bf10 | 3234 | if Is_Actual and then From_Default (N) then |
ff4f0ed0 | 3235 | |
996ae0b0 RK |
3236 | -- This is an implicit reference to the default actual |
3237 | ||
3238 | Generate_Reference (Old_S, Nam, Typ => 'i', Force => True); | |
ff4f0ed0 | 3239 | |
996ae0b0 RK |
3240 | else |
3241 | Generate_Reference (Old_S, Nam); | |
3242 | end if; | |
3243 | ||
c92e8586 AC |
3244 | Check_Internal_Protected_Use (N, Old_S); |
3245 | ||
edd63e9b ES |
3246 | -- For a renaming-as-body, require subtype conformance, but if the |
3247 | -- declaration being completed has not been frozen, then inherit the | |
3248 | -- convention of the renamed subprogram prior to checking conformance | |
3249 | -- (unless the renaming has an explicit convention established; the | |
996ae0b0 RK |
3250 | -- rule stated in the RM doesn't seem to address this ???). |
3251 | ||
3252 | if Present (Rename_Spec) then | |
3253 | Generate_Reference (Rename_Spec, Defining_Entity (Spec), 'b'); | |
3254 | Style.Check_Identifier (Defining_Entity (Spec), Rename_Spec); | |
3255 | ||
07fc65c4 GB |
3256 | if not Is_Frozen (Rename_Spec) then |
3257 | if not Has_Convention_Pragma (Rename_Spec) then | |
3258 | Set_Convention (New_S, Convention (Old_S)); | |
3259 | end if; | |
3260 | ||
3261 | if Ekind (Old_S) /= E_Operator then | |
3262 | Check_Mode_Conformant (New_S, Old_S, Spec); | |
3263 | end if; | |
3264 | ||
3265 | if Original_Subprogram (Old_S) = Rename_Spec then | |
3266 | Error_Msg_N ("unfrozen subprogram cannot rename itself ", N); | |
3267 | end if; | |
3268 | else | |
3269 | Check_Subtype_Conformant (New_S, Old_S, Spec); | |
996ae0b0 RK |
3270 | end if; |
3271 | ||
3272 | Check_Frozen_Renaming (N, Rename_Spec); | |
996ae0b0 | 3273 | |
5eb10f25 | 3274 | -- Check explicitly that renamed entity is not intrinsic, because |
16b05213 | 3275 | -- in a generic the renamed body is not built. In this case, |
5eb10f25 ES |
3276 | -- the renaming_as_body is a completion. |
3277 | ||
3278 | if Inside_A_Generic then | |
3279 | if Is_Frozen (Rename_Spec) | |
3280 | and then Is_Intrinsic_Subprogram (Old_S) | |
3281 | then | |
3282 | Error_Msg_N | |
3283 | ("subprogram in renaming_as_body cannot be intrinsic", | |
d65a80fd | 3284 | Name (N)); |
5eb10f25 ES |
3285 | end if; |
3286 | ||
3287 | Set_Has_Completion (Rename_Spec); | |
3288 | end if; | |
3289 | ||
996ae0b0 | 3290 | elsif Ekind (Old_S) /= E_Operator then |
1138cf59 | 3291 | |
2ba431e5 YM |
3292 | -- If this a defaulted subprogram for a class-wide actual there is |
3293 | -- no check for mode conformance, given that the signatures don't | |
3e24afaa | 3294 | -- match (the source mentions T but the actual mentions T'Class). |
1138cf59 | 3295 | |
afc8324d | 3296 | if CW_Actual then |
1138cf59 | 3297 | null; |
ac7d724d | 3298 | elsif not Is_Actual or else No (Enclosing_Instance) then |
1138cf59 AC |
3299 | Check_Mode_Conformant (New_S, Old_S); |
3300 | end if; | |
996ae0b0 | 3301 | |
ac7d724d | 3302 | if Is_Actual and then Error_Posted (New_S) then |
996ae0b0 RK |
3303 | Error_Msg_NE ("invalid actual subprogram: & #!", N, Old_S); |
3304 | end if; | |
3305 | end if; | |
3306 | ||
3307 | if No (Rename_Spec) then | |
3308 | ||
3309 | -- The parameter profile of the new entity is that of the renamed | |
3310 | -- entity: the subtypes given in the specification are irrelevant. | |
3311 | ||
3312 | Inherit_Renamed_Profile (New_S, Old_S); | |
3313 | ||
3314 | -- A call to the subprogram is transformed into a call to the | |
3315 | -- renamed entity. This is transitive if the renamed entity is | |
3316 | -- itself a renaming. | |
3317 | ||
3318 | if Present (Alias (Old_S)) then | |
3319 | Set_Alias (New_S, Alias (Old_S)); | |
3320 | else | |
3321 | Set_Alias (New_S, Old_S); | |
3322 | end if; | |
3323 | ||
edd63e9b ES |
3324 | -- Note that we do not set Is_Intrinsic_Subprogram if we have a |
3325 | -- renaming as body, since the entity in this case is not an | |
3326 | -- intrinsic (it calls an intrinsic, but we have a real body for | |
3327 | -- this call, and it is in this body that the required intrinsic | |
3328 | -- processing will take place). | |
996ae0b0 | 3329 | |
edd63e9b ES |
3330 | -- Also, if this is a renaming of inequality, the renamed operator |
3331 | -- is intrinsic, but what matters is the corresponding equality | |
3332 | -- operator, which may be user-defined. | |
fbf5a39b | 3333 | |
996ae0b0 | 3334 | Set_Is_Intrinsic_Subprogram |
fbf5a39b | 3335 | (New_S, |
ac7d724d ES |
3336 | Is_Intrinsic_Subprogram (Old_S) |
3337 | and then | |
3338 | (Chars (Old_S) /= Name_Op_Ne | |
3339 | or else Ekind (Old_S) = E_Operator | |
3340 | or else Is_Intrinsic_Subprogram | |
3341 | (Corresponding_Equality (Old_S)))); | |
996ae0b0 RK |
3342 | |
3343 | if Ekind (Alias (New_S)) = E_Operator then | |
3344 | Set_Has_Delayed_Freeze (New_S, False); | |
3345 | end if; | |
3346 | ||
82c80734 RD |
3347 | -- If the renaming corresponds to an association for an abstract |
3348 | -- formal subprogram, then various attributes must be set to | |
3349 | -- indicate that the renaming is an abstract dispatching operation | |
3350 | -- with a controlling type. | |
3351 | ||
16ca248a ES |
3352 | if Is_Actual and then Is_Abstract_Subprogram (Formal_Spec) then |
3353 | ||
82c80734 RD |
3354 | -- Mark the renaming as abstract here, so Find_Dispatching_Type |
3355 | -- see it as corresponding to a generic association for a | |
3356 | -- formal abstract subprogram | |
3357 | ||
16ca248a | 3358 | Set_Is_Abstract_Subprogram (New_S); |
82c80734 RD |
3359 | |
3360 | declare | |
3361 | New_S_Ctrl_Type : constant Entity_Id := | |
3362 | Find_Dispatching_Type (New_S); | |
3363 | Old_S_Ctrl_Type : constant Entity_Id := | |
3364 | Find_Dispatching_Type (Old_S); | |
3365 | ||
3366 | begin | |
46ee0270 AC |
3367 | |
3368 | -- The actual must match the (instance of the) formal, | |
3369 | -- and must be a controlling type. | |
3370 | ||
3371 | if Old_S_Ctrl_Type /= New_S_Ctrl_Type | |
3372 | or else No (New_S_Ctrl_Type) | |
3373 | then | |
82c80734 RD |
3374 | Error_Msg_NE |
3375 | ("actual must be dispatching subprogram for type&", | |
3376 | Nam, New_S_Ctrl_Type); | |
3377 | ||
3378 | else | |
3379 | Set_Is_Dispatching_Operation (New_S); | |
3380 | Check_Controlling_Formals (New_S_Ctrl_Type, New_S); | |
3381 | ||
16ca248a ES |
3382 | -- If the actual in the formal subprogram is itself a |
3383 | -- formal abstract subprogram association, there's no | |
3384 | -- dispatch table component or position to inherit. | |
82c80734 RD |
3385 | |
3386 | if Present (DTC_Entity (Old_S)) then | |
3387 | Set_DTC_Entity (New_S, DTC_Entity (Old_S)); | |
024d33d8 | 3388 | Set_DT_Position_Value (New_S, DT_Position (Old_S)); |
82c80734 RD |
3389 | end if; |
3390 | end if; | |
3391 | end; | |
3392 | end if; | |
996ae0b0 RK |
3393 | end if; |
3394 | ||
c91dbd18 AC |
3395 | if Is_Actual then |
3396 | null; | |
3397 | ||
3398 | -- The following is illegal, because F hides whatever other F may | |
3399 | -- be around: | |
a1390a6e | 3400 | -- function F (...) renames F; |
c91dbd18 AC |
3401 | |
3402 | elsif Old_S = New_S | |
3403 | or else (Nkind (Nam) /= N_Expanded_Name | |
3404 | and then Chars (Old_S) = Chars (New_S)) | |
3405 | then | |
3406 | Error_Msg_N ("subprogram cannot rename itself", N); | |
3407 | ||
a1390a6e AC |
3408 | -- This is illegal even if we use a selector: |
3409 | -- function F (...) renames Pkg.F; | |
3410 | -- because F is still hidden. | |
3411 | ||
c91dbd18 AC |
3412 | elsif Nkind (Nam) = N_Expanded_Name |
3413 | and then Entity (Prefix (Nam)) = Current_Scope | |
3414 | and then Chars (Selector_Name (Nam)) = Chars (New_S) | |
996ae0b0 | 3415 | then |
354c3840 AC |
3416 | -- This is an error, but we overlook the error and accept the |
3417 | -- renaming if the special Overriding_Renamings mode is in effect. | |
9b7424a7 | 3418 | |
354c3840 | 3419 | if not Overriding_Renamings then |
9b7424a7 | 3420 | Error_Msg_NE |
354c3840 AC |
3421 | ("implicit operation& is not visible (RM 8.3 (15))", |
3422 | Nam, Old_S); | |
9b7424a7 | 3423 | end if; |
996ae0b0 RK |
3424 | end if; |
3425 | ||
3426 | Set_Convention (New_S, Convention (Old_S)); | |
16ca248a ES |
3427 | |
3428 | if Is_Abstract_Subprogram (Old_S) then | |
3429 | if Present (Rename_Spec) then | |
3430 | Error_Msg_N | |
3431 | ("a renaming-as-body cannot rename an abstract subprogram", | |
3432 | N); | |
3433 | Set_Has_Completion (Rename_Spec); | |
3434 | else | |
3435 | Set_Is_Abstract_Subprogram (New_S); | |
3436 | end if; | |
3437 | end if; | |
3438 | ||
996ae0b0 RK |
3439 | Check_Library_Unit_Renaming (N, Old_S); |
3440 | ||
edd63e9b ES |
3441 | -- Pathological case: procedure renames entry in the scope of its |
3442 | -- task. Entry is given by simple name, but body must be built for | |
3443 | -- procedure. Of course if called it will deadlock. | |
996ae0b0 RK |
3444 | |
3445 | if Ekind (Old_S) = E_Entry then | |
3446 | Set_Has_Completion (New_S, False); | |
3447 | Set_Alias (New_S, Empty); | |
3448 | end if; | |
3449 | ||
66340e0e AC |
3450 | -- Do not freeze the renaming nor the renamed entity when the context |
3451 | -- is an enclosing generic. Freezing is an expansion activity, and in | |
3452 | -- addition the renamed entity may depend on the generic formals of | |
3453 | -- the enclosing generic. | |
3454 | ||
851e9f19 | 3455 | if Is_Actual and not Inside_A_Generic then |
996ae0b0 | 3456 | Freeze_Before (N, Old_S); |
02e4edea | 3457 | Freeze_Actual_Profile; |
996ae0b0 RK |
3458 | Set_Has_Delayed_Freeze (New_S, False); |
3459 | Freeze_Before (N, New_S); | |
3460 | ||
82c80734 RD |
3461 | -- An abstract subprogram is only allowed as an actual in the case |
3462 | -- where the formal subprogram is also abstract. | |
3463 | ||
996ae0b0 | 3464 | if (Ekind (Old_S) = E_Procedure or else Ekind (Old_S) = E_Function) |
16ca248a ES |
3465 | and then Is_Abstract_Subprogram (Old_S) |
3466 | and then not Is_Abstract_Subprogram (Formal_Spec) | |
996ae0b0 RK |
3467 | then |
3468 | Error_Msg_N | |
3469 | ("abstract subprogram not allowed as generic actual", Nam); | |
3470 | end if; | |
3471 | end if; | |
3472 | ||
3473 | else | |
edd63e9b ES |
3474 | -- A common error is to assume that implicit operators for types are |
3475 | -- defined in Standard, or in the scope of a subtype. In those cases | |
3476 | -- where the renamed entity is given with an expanded name, it is | |
3477 | -- worth mentioning that operators for the type are not declared in | |
3478 | -- the scope given by the prefix. | |
996ae0b0 RK |
3479 | |
3480 | if Nkind (Nam) = N_Expanded_Name | |
3481 | and then Nkind (Selector_Name (Nam)) = N_Operator_Symbol | |
3482 | and then Scope (Entity (Nam)) = Standard_Standard | |
3483 | then | |
3484 | declare | |
3485 | T : constant Entity_Id := | |
3486 | Base_Type (Etype (First_Formal (New_S))); | |
996ae0b0 RK |
3487 | begin |
3488 | Error_Msg_Node_2 := Prefix (Nam); | |
fbf5a39b AC |
3489 | Error_Msg_NE |
3490 | ("operator for type& is not declared in&", Prefix (Nam), T); | |
996ae0b0 | 3491 | end; |
fbf5a39b | 3492 | |
996ae0b0 RK |
3493 | else |
3494 | Error_Msg_NE | |
3495 | ("no visible subprogram matches the specification for&", | |
3496 | Spec, New_S); | |
3497 | end if; | |
3498 | ||
3499 | if Present (Candidate_Renaming) then | |
3500 | declare | |
3501 | F1 : Entity_Id; | |
3502 | F2 : Entity_Id; | |
70b70ce8 | 3503 | T1 : Entity_Id; |
996ae0b0 RK |
3504 | |
3505 | begin | |
3506 | F1 := First_Formal (Candidate_Renaming); | |
3507 | F2 := First_Formal (New_S); | |
70b70ce8 | 3508 | T1 := First_Subtype (Etype (F1)); |
996ae0b0 RK |
3509 | while Present (F1) and then Present (F2) loop |
3510 | Next_Formal (F1); | |
3511 | Next_Formal (F2); | |
3512 | end loop; | |
3513 | ||
3514 | if Present (F1) and then Present (Default_Value (F1)) then | |
3515 | if Present (Next_Formal (F1)) then | |
3516 | Error_Msg_NE | |
241ebe89 HK |
3517 | ("\missing specification for & and other formals with " |
3518 | & "defaults", Spec, F1); | |
996ae0b0 | 3519 | else |
241ebe89 | 3520 | Error_Msg_NE ("\missing specification for &", Spec, F1); |
996ae0b0 RK |
3521 | end if; |
3522 | end if; | |
70b70ce8 AC |
3523 | |
3524 | if Nkind (Nam) = N_Operator_Symbol | |
3525 | and then From_Default (N) | |
3526 | then | |
3527 | Error_Msg_Node_2 := T1; | |
3528 | Error_Msg_NE | |
d65a80fd | 3529 | ("default & on & is not directly visible", Nam, Nam); |
70b70ce8 | 3530 | end if; |
996ae0b0 RK |
3531 | end; |
3532 | end if; | |
3533 | end if; | |
3534 | ||
edd63e9b ES |
3535 | -- Ada 2005 AI 404: if the new subprogram is dispatching, verify that |
3536 | -- controlling access parameters are known non-null for the renamed | |
3537 | -- subprogram. Test also applies to a subprogram instantiation that | |
cdc8c54c BD |
3538 | -- is dispatching. Test is skipped if some previous error was detected |
3539 | -- that set Old_S to Any_Id. | |
edd63e9b | 3540 | |
0791fbe9 | 3541 | if Ada_Version >= Ada_2005 |
cdc8c54c | 3542 | and then Old_S /= Any_Id |
edd63e9b ES |
3543 | and then not Is_Dispatching_Operation (Old_S) |
3544 | and then Is_Dispatching_Operation (New_S) | |
3545 | then | |
3546 | declare | |
3547 | Old_F : Entity_Id; | |
3548 | New_F : Entity_Id; | |
3549 | ||
3550 | begin | |
3551 | Old_F := First_Formal (Old_S); | |
3552 | New_F := First_Formal (New_S); | |
3553 | while Present (Old_F) loop | |
3554 | if Ekind (Etype (Old_F)) = E_Anonymous_Access_Type | |
3555 | and then Is_Controlling_Formal (New_F) | |
3556 | and then not Can_Never_Be_Null (Old_F) | |
3557 | then | |
3558 | Error_Msg_N ("access parameter is controlling,", New_F); | |
fbe627af | 3559 | Error_Msg_NE |
d65a80fd HK |
3560 | ("\corresponding parameter of& must be explicitly null " |
3561 | & "excluding", New_F, Old_S); | |
edd63e9b ES |
3562 | end if; |
3563 | ||
3564 | Next_Formal (Old_F); | |
3565 | Next_Formal (New_F); | |
3566 | end loop; | |
3567 | end; | |
3568 | end if; | |
3569 | ||
725393ea | 3570 | -- A useful warning, suggested by Ada Bug Finder (Ada-Europe 2005) |
b5c739f9 | 3571 | -- is to warn if an operator is being renamed as a different operator. |
880dabb5 AC |
3572 | -- If the operator is predefined, examine the kind of the entity, not |
3573 | -- the abbreviated declaration in Standard. | |
725393ea ES |
3574 | |
3575 | if Comes_From_Source (N) | |
3576 | and then Present (Old_S) | |
ac7d724d ES |
3577 | and then (Nkind (Old_S) = N_Defining_Operator_Symbol |
3578 | or else Ekind (Old_S) = E_Operator) | |
725393ea ES |
3579 | and then Nkind (New_S) = N_Defining_Operator_Symbol |
3580 | and then Chars (Old_S) /= Chars (New_S) | |
3581 | then | |
3582 | Error_Msg_NE | |
dbfeb4fa | 3583 | ("& is being renamed as a different operator??", N, Old_S); |
725393ea ES |
3584 | end if; |
3585 | ||
b5c739f9 RD |
3586 | -- Check for renaming of obsolescent subprogram |
3587 | ||
3588 | Check_Obsolescent_2005_Entity (Entity (Nam), Nam); | |
3589 | ||
11560bcc TQ |
3590 | -- Another warning or some utility: if the new subprogram as the same |
3591 | -- name as the old one, the old one is not hidden by an outer homograph, | |
3592 | -- the new one is not a public symbol, and the old one is otherwise | |
3593 | -- directly visible, the renaming is superfluous. | |
3594 | ||
3595 | if Chars (Old_S) = Chars (New_S) | |
3596 | and then Comes_From_Source (N) | |
3597 | and then Scope (Old_S) /= Standard_Standard | |
3598 | and then Warn_On_Redundant_Constructs | |
ac7d724d ES |
3599 | and then (Is_Immediately_Visible (Old_S) |
3600 | or else Is_Potentially_Use_Visible (Old_S)) | |
11560bcc TQ |
3601 | and then Is_Overloadable (Current_Scope) |
3602 | and then Chars (Current_Scope) /= Chars (Old_S) | |
3603 | then | |
3604 | Error_Msg_N | |
241ebe89 | 3605 | ("redundant renaming, entity is directly visible?r?", Name (N)); |
11560bcc TQ |
3606 | end if; |
3607 | ||
ef992452 | 3608 | -- Implementation-defined aspect specifications can appear in a renaming |
cc96a1b8 AC |
3609 | -- declaration, but not language-defined ones. The call to procedure |
3610 | -- Analyze_Aspect_Specifications will take care of this error check. | |
ef992452 AC |
3611 | |
3612 | if Has_Aspects (N) then | |
3613 | Analyze_Aspect_Specifications (N, New_S); | |
3614 | end if; | |
3615 | ||
0ab80019 | 3616 | Ada_Version := Save_AV; |
fb620b37 | 3617 | Ada_Version_Pragma := Save_AVP; |
edd63e9b | 3618 | Ada_Version_Explicit := Save_AV_Exp; |
948ed277 AC |
3619 | |
3620 | -- In GNATprove mode, the renamings of actual subprograms are replaced | |
3621 | -- with wrapper functions that make it easier to propagate axioms to the | |
a1954e97 AC |
3622 | -- points of call within an instance. Wrappers are generated if formal |
3623 | -- subprogram is subject to axiomatization. | |
948ed277 | 3624 | |
1a779058 AC |
3625 | -- The types in the wrapper profiles are obtained from (instances of) |
3626 | -- the types of the formal subprogram. | |
3627 | ||
948ed277 AC |
3628 | if Is_Actual |
3629 | and then GNATprove_Mode | |
a1954e97 | 3630 | and then Present (Containing_Package_With_Ext_Axioms (Formal_Spec)) |
948ed277 AC |
3631 | and then not Inside_A_Generic |
3632 | then | |
3633 | if Ekind (Old_S) = E_Function then | |
1a779058 | 3634 | Rewrite (N, Build_Function_Wrapper (Formal_Spec, Old_S)); |
948ed277 | 3635 | Analyze (N); |
fc6d9796 | 3636 | |
948ed277 | 3637 | elsif Ekind (Old_S) = E_Operator then |
fc6d9796 | 3638 | Rewrite (N, Build_Operator_Wrapper (Formal_Spec, Old_S)); |
948ed277 AC |
3639 | Analyze (N); |
3640 | end if; | |
3641 | end if; | |
851e9f19 PMR |
3642 | |
3643 | -- Check if we are looking at an Ada 2012 defaulted formal subprogram | |
3644 | -- and mark any use_package_clauses that affect the visibility of the | |
3645 | -- implicit generic actual. | |
3646 | ||
2e60feb5 PMR |
3647 | if Is_Generic_Actual_Subprogram (New_S) |
3648 | and then (Is_Intrinsic_Subprogram (New_S) or else From_Default (N)) | |
851e9f19 | 3649 | then |
2e60feb5 | 3650 | Mark_Use_Clauses (New_S); |
851e9f19 | 3651 | |
2e60feb5 | 3652 | -- Handle overloaded subprograms |
851e9f19 | 3653 | |
2e60feb5 PMR |
3654 | if Present (Alias (New_S)) then |
3655 | Mark_Use_Clauses (Alias (New_S)); | |
3656 | end if; | |
851e9f19 | 3657 | end if; |
996ae0b0 RK |
3658 | end Analyze_Subprogram_Renaming; |
3659 | ||
3660 | ------------------------- | |
3661 | -- Analyze_Use_Package -- | |
3662 | ------------------------- | |
3663 | ||
3664 | -- Resolve the package names in the use clause, and make all the visible | |
3665 | -- entities defined in the package potentially use-visible. If the package | |
3666 | -- is already in use from a previous use clause, its visible entities are | |
3667 | -- already use-visible. In that case, mark the occurrence as a redundant | |
3668 | -- use. If the package is an open scope, i.e. if the use clause occurs | |
3669 | -- within the package itself, ignore it. | |
3670 | ||
851e9f19 | 3671 | procedure Analyze_Use_Package (N : Node_Id; Chain : Boolean := True) is |
851e9f19 PMR |
3672 | procedure Analyze_Package_Name (Clause : Node_Id); |
3673 | -- Perform analysis on a package name from a use_package_clause | |
3674 | ||
3675 | procedure Analyze_Package_Name_List (Head_Clause : Node_Id); | |
3676 | -- Similar to Analyze_Package_Name but iterates over all the names | |
3677 | -- in a use clause. | |
3678 | ||
3679 | -------------------------- | |
3680 | -- Analyze_Package_Name -- | |
3681 | -------------------------- | |
3682 | ||
3683 | procedure Analyze_Package_Name (Clause : Node_Id) is | |
3684 | Pack : constant Node_Id := Name (Clause); | |
3685 | Pref : Node_Id; | |
3686 | ||
3687 | begin | |
3688 | pragma Assert (Nkind (Clause) = N_Use_Package_Clause); | |
3689 | Analyze (Pack); | |
3690 | ||
3691 | -- Verify that the package standard is not directly named in a | |
3692 | -- use_package_clause. | |
3693 | ||
3694 | if Nkind (Parent (Clause)) = N_Compilation_Unit | |
3695 | and then Nkind (Pack) = N_Expanded_Name | |
3696 | then | |
3697 | Pref := Prefix (Pack); | |
3698 | ||
3699 | while Nkind (Pref) = N_Expanded_Name loop | |
3700 | Pref := Prefix (Pref); | |
3701 | end loop; | |
3702 | ||
3703 | if Entity (Pref) = Standard_Standard then | |
3704 | Error_Msg_N | |
7f5e671b PMR |
3705 | ("predefined package Standard cannot appear in a context " |
3706 | & "clause", Pref); | |
851e9f19 PMR |
3707 | end if; |
3708 | end if; | |
3709 | end Analyze_Package_Name; | |
3710 | ||
3711 | ------------------------------- | |
3712 | -- Analyze_Package_Name_List -- | |
3713 | ------------------------------- | |
3714 | ||
3715 | procedure Analyze_Package_Name_List (Head_Clause : Node_Id) is | |
3716 | Curr : Node_Id; | |
3717 | ||
3718 | begin | |
3719 | -- Due to the way source use clauses are split during parsing we are | |
3720 | -- forced to simply iterate through all entities in scope until the | |
3721 | -- clause representing the last name in the list is found. | |
3722 | ||
3723 | Curr := Head_Clause; | |
3724 | while Present (Curr) loop | |
3725 | Analyze_Package_Name (Curr); | |
3726 | ||
3727 | -- Stop iterating over the names in the use clause when we are at | |
3728 | -- the last one. | |
3729 | ||
3730 | exit when not More_Ids (Curr) and then Prev_Ids (Curr); | |
3731 | Next (Curr); | |
3732 | end loop; | |
3733 | end Analyze_Package_Name_List; | |
3734 | ||
3735 | -- Local variables | |
3736 | ||
6e9e35e1 AC |
3737 | Ghost_Id : Entity_Id := Empty; |
3738 | Living_Id : Entity_Id := Empty; | |
996ae0b0 | 3739 | Pack : Entity_Id; |
851e9f19 PMR |
3740 | |
3741 | -- Start of processing for Analyze_Use_Package | |
996ae0b0 RK |
3742 | |
3743 | begin | |
ce5ba43a | 3744 | Check_SPARK_05_Restriction ("use clause is not allowed", N); |
1d801f21 | 3745 | |
996ae0b0 RK |
3746 | Set_Hidden_By_Use_Clause (N, No_Elist); |
3747 | ||
7394c8cc AC |
3748 | -- Use clause not allowed in a spec of a predefined package declaration |
3749 | -- except that packages whose file name starts a-n are OK (these are | |
3750 | -- children of Ada.Numerics, which are never loaded by Rtsfind). | |
996ae0b0 | 3751 | |
8ab31c0c | 3752 | if Is_Predefined_Unit (Current_Sem_Unit) |
b043ae01 | 3753 | and then Get_Name_String |
94d3a18d AC |
3754 | (Unit_File_Name (Current_Sem_Unit)) (1 .. 3) /= "a-n" |
3755 | and then Nkind (Unit (Cunit (Current_Sem_Unit))) = | |
3756 | N_Package_Declaration | |
996ae0b0 RK |
3757 | then |
3758 | Error_Msg_N ("use clause not allowed in predefined spec", N); | |
3759 | end if; | |
3760 | ||
851e9f19 PMR |
3761 | -- Loop through all package names from the original use clause in |
3762 | -- order to analyze referenced packages. A use_package_clause with only | |
3763 | -- one name does not have More_Ids or Prev_Ids set, while a clause with | |
3764 | -- More_Ids only starts the chain produced by the parser. | |
996ae0b0 | 3765 | |
851e9f19 PMR |
3766 | if not More_Ids (N) and then not Prev_Ids (N) then |
3767 | Analyze_Package_Name (N); | |
7f5e671b | 3768 | |
851e9f19 PMR |
3769 | elsif More_Ids (N) and then not Prev_Ids (N) then |
3770 | Analyze_Package_Name_List (N); | |
996ae0b0 RK |
3771 | end if; |
3772 | ||
851e9f19 PMR |
3773 | if not Is_Entity_Name (Name (N)) then |
3774 | Error_Msg_N ("& is not a package", Name (N)); | |
996ae0b0 | 3775 | |
851e9f19 PMR |
3776 | return; |
3777 | end if; | |
996ae0b0 | 3778 | |
851e9f19 PMR |
3779 | if Chain then |
3780 | Chain_Use_Clause (N); | |
3781 | end if; | |
996ae0b0 | 3782 | |
7f5e671b PMR |
3783 | Pack := Entity (Name (N)); |
3784 | ||
851e9f19 PMR |
3785 | -- There are many cases where scopes are manipulated during analysis, so |
3786 | -- check that Pack's current use clause has not already been chained | |
3787 | -- before setting its previous use clause. | |
996ae0b0 | 3788 | |
851e9f19 | 3789 | if Ekind (Pack) = E_Package |
ccd0ed95 PMR |
3790 | and then Present (Current_Use_Clause (Pack)) |
3791 | and then Current_Use_Clause (Pack) /= N | |
3792 | and then No (Prev_Use_Clause (N)) | |
3793 | and then Prev_Use_Clause (Current_Use_Clause (Pack)) /= N | |
851e9f19 PMR |
3794 | then |
3795 | Set_Prev_Use_Clause (N, Current_Use_Clause (Pack)); | |
3796 | end if; | |
996ae0b0 | 3797 | |
851e9f19 | 3798 | -- Mark all entities as potentially use visible. |
0566484a | 3799 | |
851e9f19 PMR |
3800 | if Ekind (Pack) /= E_Package and then Etype (Pack) /= Any_Type then |
3801 | if Ekind (Pack) = E_Generic_Package then | |
3802 | Error_Msg_N -- CODEFIX | |
7f5e671b | 3803 | ("a generic package is not allowed in a use clause", Name (N)); |
0566484a | 3804 | |
851e9f19 PMR |
3805 | elsif Ekind_In (Pack, E_Generic_Function, E_Generic_Package) |
3806 | then | |
3807 | Error_Msg_N -- CODEFIX | |
3808 | ("a generic subprogram is not allowed in a use clause", | |
3809 | Name (N)); | |
0566484a | 3810 | |
851e9f19 PMR |
3811 | elsif Ekind_In (Pack, E_Function, E_Procedure, E_Operator) then |
3812 | Error_Msg_N -- CODEFIX | |
7f5e671b | 3813 | ("a subprogram is not allowed in a use clause", Name (N)); |
996ae0b0 | 3814 | |
851e9f19 PMR |
3815 | else |
3816 | Error_Msg_N ("& is not allowed in a use clause", Name (N)); | |
3817 | end if; | |
996ae0b0 | 3818 | |
851e9f19 PMR |
3819 | else |
3820 | if Nkind (Parent (N)) = N_Compilation_Unit then | |
3821 | Check_In_Previous_With_Clause (N, Name (N)); | |
3822 | end if; | |
6e9e35e1 | 3823 | |
851e9f19 | 3824 | Use_One_Package (N, Name (N)); |
6e9e35e1 | 3825 | |
851e9f19 | 3826 | -- Capture the first Ghost package and the first living package |
6e9e35e1 | 3827 | |
851e9f19 PMR |
3828 | if Is_Entity_Name (Name (N)) then |
3829 | Pack := Entity (Name (N)); | |
6e9e35e1 | 3830 | |
851e9f19 PMR |
3831 | if Is_Ghost_Entity (Pack) then |
3832 | if No (Ghost_Id) then | |
3833 | Ghost_Id := Pack; | |
6e9e35e1 | 3834 | end if; |
462c31ef | 3835 | |
851e9f19 PMR |
3836 | elsif No (Living_Id) then |
3837 | Living_Id := Pack; | |
3838 | end if; | |
996ae0b0 | 3839 | end if; |
851e9f19 | 3840 | end if; |
996ae0b0 RK |
3841 | end Analyze_Use_Package; |
3842 | ||
3843 | ---------------------- | |
3844 | -- Analyze_Use_Type -- | |
3845 | ---------------------- | |
3846 | ||
851e9f19 PMR |
3847 | procedure Analyze_Use_Type (N : Node_Id; Chain : Boolean := True) is |
3848 | E : Entity_Id; | |
3849 | Id : Node_Id; | |
996ae0b0 RK |
3850 | |
3851 | begin | |
3852 | Set_Hidden_By_Use_Clause (N, No_Elist); | |
3853 | ||
851e9f19 | 3854 | -- Chain clause to list of use clauses in current scope when flagged |
996ae0b0 | 3855 | |
851e9f19 | 3856 | if Chain then |
996ae0b0 RK |
3857 | Chain_Use_Clause (N); |
3858 | end if; | |
3859 | ||
851e9f19 PMR |
3860 | -- Obtain the base type of the type denoted within the use_type_clause's |
3861 | -- subtype mark. | |
3862 | ||
3863 | Id := Subtype_Mark (N); | |
3864 | Find_Type (Id); | |
3865 | E := Base_Type (Entity (Id)); | |
3866 | ||
3867 | -- There are many cases where a use_type_clause may be reanalyzed due to | |
3868 | -- manipulation of the scope stack so we much guard against those cases | |
3869 | -- here, otherwise, we must add the new use_type_clause to the previous | |
3870 | -- use_type_clause chain in order to mark redundant use_type_clauses as | |
3871 | -- used. | |
3872 | ||
3873 | if Present (Current_Use_Clause (E)) | |
3874 | and then Current_Use_Clause (E) /= N | |
3875 | and then No (Prev_Use_Clause (N)) | |
3876 | then | |
3877 | Set_Prev_Use_Clause (N, Current_Use_Clause (E)); | |
3878 | end if; | |
3879 | ||
780d052e | 3880 | -- If the Used_Operations list is already initialized, the clause has |
b6e6a4e3 | 3881 | -- been analyzed previously, and it is being reinstalled, for example |
780d052e RD |
3882 | -- when the clause appears in a package spec and we are compiling the |
3883 | -- corresponding package body. In that case, make the entities on the | |
806f6d37 | 3884 | -- existing list use_visible, and mark the corresponding types In_Use. |
29efbb8c | 3885 | |
780d052e | 3886 | if Present (Used_Operations (N)) then |
29efbb8c ES |
3887 | declare |
3888 | Elmt : Elmt_Id; | |
806f6d37 | 3889 | |
29efbb8c | 3890 | begin |
851e9f19 | 3891 | Use_One_Type (Subtype_Mark (N), Installed => True); |
806f6d37 | 3892 | |
29efbb8c ES |
3893 | Elmt := First_Elmt (Used_Operations (N)); |
3894 | while Present (Elmt) loop | |
3895 | Set_Is_Potentially_Use_Visible (Node (Elmt)); | |
3896 | Next_Elmt (Elmt); | |
3897 | end loop; | |
3898 | end; | |
3899 | ||
3900 | return; | |
3901 | end if; | |
3902 | ||
cc0b3bac AC |
3903 | -- Otherwise, create new list and attach to it the operations that are |
3904 | -- made use-visible by the clause. | |
780d052e | 3905 | |
29efbb8c | 3906 | Set_Used_Operations (N, New_Elmt_List); |
851e9f19 | 3907 | E := Entity (Id); |
fbf5a39b | 3908 | |
851e9f19 PMR |
3909 | if E /= Any_Type then |
3910 | Use_One_Type (Id); | |
fbf5a39b | 3911 | |
851e9f19 PMR |
3912 | if Nkind (Parent (N)) = N_Compilation_Unit then |
3913 | if Nkind (Id) = N_Identifier then | |
3914 | Error_Msg_N ("type is not directly visible", Id); | |
ecc4ddde | 3915 | |
851e9f19 PMR |
3916 | elsif Is_Child_Unit (Scope (E)) |
3917 | and then Scope (E) /= System_Aux_Id | |
ecc4ddde | 3918 | then |
851e9f19 | 3919 | Check_In_Previous_With_Clause (N, Prefix (Id)); |
ecc4ddde | 3920 | end if; |
996ae0b0 RK |
3921 | end if; |
3922 | ||
851e9f19 PMR |
3923 | else |
3924 | -- If the use_type_clause appears in a compilation unit context, | |
3925 | -- check whether it comes from a unit that may appear in a | |
3926 | -- limited_with_clause, for a better error message. | |
6e9e35e1 | 3927 | |
851e9f19 PMR |
3928 | if Nkind (Parent (N)) = N_Compilation_Unit |
3929 | and then Nkind (Id) /= N_Identifier | |
3930 | then | |
3931 | declare | |
3932 | Item : Node_Id; | |
3933 | Pref : Node_Id; | |
6e9e35e1 | 3934 | |
851e9f19 PMR |
3935 | function Mentioned (Nam : Node_Id) return Boolean; |
3936 | -- Check whether the prefix of expanded name for the type | |
3937 | -- appears in the prefix of some limited_with_clause. | |
6e9e35e1 | 3938 | |
851e9f19 PMR |
3939 | --------------- |
3940 | -- Mentioned -- | |
3941 | --------------- | |
6e9e35e1 | 3942 | |
851e9f19 PMR |
3943 | function Mentioned (Nam : Node_Id) return Boolean is |
3944 | begin | |
3945 | return Nkind (Name (Item)) = N_Selected_Component | |
3946 | and then Chars (Prefix (Name (Item))) = Chars (Nam); | |
3947 | end Mentioned; | |
6e9e35e1 | 3948 | |
851e9f19 PMR |
3949 | begin |
3950 | Pref := Prefix (Id); | |
3951 | Item := First (Context_Items (Parent (N))); | |
3952 | while Present (Item) and then Item /= N loop | |
3953 | if Nkind (Item) = N_With_Clause | |
3954 | and then Limited_Present (Item) | |
3955 | and then Mentioned (Pref) | |
3956 | then | |
3957 | Change_Error_Text | |
3958 | (Get_Msg_Id, "premature usage of incomplete type"); | |
3959 | end if; | |
6e9e35e1 | 3960 | |
851e9f19 PMR |
3961 | Next (Item); |
3962 | end loop; | |
3963 | end; | |
3964 | end if; | |
6e9e35e1 AC |
3965 | end if; |
3966 | ||
3967 | Mark_Ghost_Clause (N); | |
996ae0b0 RK |
3968 | end Analyze_Use_Type; |
3969 | ||
996ae0b0 RK |
3970 | ------------------------ |
3971 | -- Attribute_Renaming -- | |
3972 | ------------------------ | |
3973 | ||
3974 | procedure Attribute_Renaming (N : Node_Id) is | |
8d80ff64 AC |
3975 | Loc : constant Source_Ptr := Sloc (N); |
3976 | Nam : constant Node_Id := Name (N); | |
3977 | Spec : constant Node_Id := Specification (N); | |
3978 | New_S : constant Entity_Id := Defining_Unit_Name (Spec); | |
3979 | Aname : constant Name_Id := Attribute_Name (Nam); | |
996ae0b0 | 3980 | |
8d80ff64 AC |
3981 | Form_Num : Nat := 0; |
3982 | Expr_List : List_Id := No_List; | |
996ae0b0 RK |
3983 | |
3984 | Attr_Node : Node_Id; | |
3985 | Body_Node : Node_Id; | |
3986 | Param_Spec : Node_Id; | |
3987 | ||
3988 | begin | |
3989 | Generate_Definition (New_S); | |
3990 | ||
4c8a5bb8 AC |
3991 | -- This procedure is called in the context of subprogram renaming, and |
3992 | -- thus the attribute must be one that is a subprogram. All of those | |
ba0c6e47 RD |
3993 | -- have at least one formal parameter, with the exceptions of the GNAT |
3994 | -- attribute 'Img, which GNAT treats as renameable. | |
996ae0b0 RK |
3995 | |
3996 | if not Is_Non_Empty_List (Parameter_Specifications (Spec)) then | |
ba0c6e47 | 3997 | if Aname /= Name_Img then |
996ae0b0 RK |
3998 | Error_Msg_N |
3999 | ("subprogram renaming an attribute must have formals", N); | |
4000 | return; | |
4001 | end if; | |
4002 | ||
4003 | else | |
4004 | Param_Spec := First (Parameter_Specifications (Spec)); | |
996ae0b0 RK |
4005 | while Present (Param_Spec) loop |
4006 | Form_Num := Form_Num + 1; | |
4007 | ||
4008 | if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then | |
4009 | Find_Type (Parameter_Type (Param_Spec)); | |
4010 | ||
4011 | -- The profile of the new entity denotes the base type (s) of | |
4012 | -- the types given in the specification. For access parameters | |
4013 | -- there are no subtypes involved. | |
4014 | ||
4015 | Rewrite (Parameter_Type (Param_Spec), | |
e4494292 | 4016 | New_Occurrence_Of |
8d80ff64 | 4017 | (Base_Type (Entity (Parameter_Type (Param_Spec))), Loc)); |
996ae0b0 RK |
4018 | end if; |
4019 | ||
4020 | if No (Expr_List) then | |
4021 | Expr_List := New_List; | |
4022 | end if; | |
4023 | ||
4024 | Append_To (Expr_List, | |
4025 | Make_Identifier (Loc, | |
4026 | Chars => Chars (Defining_Identifier (Param_Spec)))); | |
4027 | ||
fbf5a39b | 4028 | -- The expressions in the attribute reference are not freeze |
4c8a5bb8 | 4029 | -- points. Neither is the attribute as a whole, see below. |
fbf5a39b AC |
4030 | |
4031 | Set_Must_Not_Freeze (Last (Expr_List)); | |
996ae0b0 RK |
4032 | Next (Param_Spec); |
4033 | end loop; | |
4034 | end if; | |
4035 | ||
4c8a5bb8 AC |
4036 | -- Immediate error if too many formals. Other mismatches in number or |
4037 | -- types of parameters are detected when we analyze the body of the | |
4038 | -- subprogram that we construct. | |
996ae0b0 RK |
4039 | |
4040 | if Form_Num > 2 then | |
4041 | Error_Msg_N ("too many formals for attribute", N); | |
4042 | ||
4c8a5bb8 AC |
4043 | -- Error if the attribute reference has expressions that look like |
4044 | -- formal parameters. | |
0da2c8ac AC |
4045 | |
4046 | elsif Present (Expressions (Nam)) then | |
4047 | Error_Msg_N ("illegal expressions in attribute reference", Nam); | |
4048 | ||
996ae0b0 | 4049 | elsif |
b69cd36a AC |
4050 | Nam_In (Aname, Name_Compose, Name_Exponent, Name_Leading_Part, |
4051 | Name_Pos, Name_Round, Name_Scaling, | |
4052 | Name_Val) | |
996ae0b0 RK |
4053 | then |
4054 | if Nkind (N) = N_Subprogram_Renaming_Declaration | |
82c80734 | 4055 | and then Present (Corresponding_Formal_Spec (N)) |
996ae0b0 RK |
4056 | then |
4057 | Error_Msg_N | |
4058 | ("generic actual cannot be attribute involving universal type", | |
4059 | Nam); | |
4060 | else | |
4061 | Error_Msg_N | |
4062 | ("attribute involving a universal type cannot be renamed", | |
4063 | Nam); | |
4064 | end if; | |
4065 | end if; | |
4066 | ||
ba0c6e47 RD |
4067 | -- Rewrite attribute node to have a list of expressions corresponding to |
4068 | -- the subprogram formals. A renaming declaration is not a freeze point, | |
4069 | -- and the analysis of the attribute reference should not freeze the | |
4070 | -- type of the prefix. We use the original node in the renaming so that | |
4071 | -- its source location is preserved, and checks on stream attributes are | |
4072 | -- properly applied. | |
996ae0b0 | 4073 | |
ba0c6e47 RD |
4074 | Attr_Node := Relocate_Node (Nam); |
4075 | Set_Expressions (Attr_Node, Expr_List); | |
996ae0b0 | 4076 | |
ba0c6e47 RD |
4077 | Set_Must_Not_Freeze (Attr_Node); |
4078 | Set_Must_Not_Freeze (Prefix (Nam)); | |
996ae0b0 RK |
4079 | |
4080 | -- Case of renaming a function | |
4081 | ||
4082 | if Nkind (Spec) = N_Function_Specification then | |
996ae0b0 RK |
4083 | if Is_Procedure_Attribute_Name (Aname) then |
4084 | Error_Msg_N ("attribute can only be renamed as procedure", Nam); | |
4085 | return; | |
4086 | end if; | |
4087 | ||
725393ea ES |
4088 | Find_Type (Result_Definition (Spec)); |
4089 | Rewrite (Result_Definition (Spec), | |
e4494292 | 4090 | New_Occurrence_Of |
4bcf6815 | 4091 | (Base_Type (Entity (Result_Definition (Spec))), Loc)); |
996ae0b0 RK |
4092 | |
4093 | Body_Node := | |
4094 | Make_Subprogram_Body (Loc, | |
4095 | Specification => Spec, | |
4096 | Declarations => New_List, | |
4097 | Handled_Statement_Sequence => | |
4098 | Make_Handled_Sequence_Of_Statements (Loc, | |
4099 | Statements => New_List ( | |
11560bcc | 4100 | Make_Simple_Return_Statement (Loc, |
996ae0b0 RK |
4101 | Expression => Attr_Node)))); |
4102 | ||
4103 | -- Case of renaming a procedure | |
4104 | ||
4105 | else | |
4106 | if not Is_Procedure_Attribute_Name (Aname) then | |
4107 | Error_Msg_N ("attribute can only be renamed as function", Nam); | |
4108 | return; | |
4109 | end if; | |
4110 | ||
4111 | Body_Node := | |
4112 | Make_Subprogram_Body (Loc, | |
4113 | Specification => Spec, | |
4114 | Declarations => New_List, | |
4115 | Handled_Statement_Sequence => | |
4116 | Make_Handled_Sequence_Of_Statements (Loc, | |
4117 | Statements => New_List (Attr_Node))); | |
4118 | end if; | |
4119 | ||
90e491a7 PMR |
4120 | -- Signal the ABE mechanism that the generated subprogram body has not |
4121 | -- ABE ramifications. | |
4122 | ||
4123 | Set_Was_Attribute_Reference (Body_Node); | |
4124 | ||
fbe627af RD |
4125 | -- In case of tagged types we add the body of the generated function to |
4126 | -- the freezing actions of the type (because in the general case such | |
4127 | -- type is still not frozen). We exclude from this processing generic | |
ba0c6e47 | 4128 | -- formal subprograms found in instantiations. |
fbe627af | 4129 | |
535a8637 | 4130 | -- We must exclude restricted run-time libraries because |
6b81741c | 4131 | -- entity AST_Handler is defined in package System.Aux_Dec which is not |
9d1e0e72 JR |
4132 | -- available in those platforms. Note that we cannot use the function |
4133 | -- Restricted_Profile (instead of Configurable_Run_Time_Mode) because | |
4134 | -- the ZFP run-time library is not defined as a profile, and we do not | |
4135 | -- want to deal with AST_Handler in ZFP mode. | |
ddc1515a | 4136 | |
535a8637 | 4137 | if not Configurable_Run_Time_Mode |
ddc1515a | 4138 | and then not Present (Corresponding_Formal_Spec (N)) |
fbe627af RD |
4139 | and then Etype (Nam) /= RTE (RE_AST_Handler) |
4140 | then | |
4141 | declare | |
a530b8bb | 4142 | P : constant Node_Id := Prefix (Nam); |
fbe627af RD |
4143 | |
4144 | begin | |
8d80ff64 AC |
4145 | -- The prefix of 'Img is an object that is evaluated for each call |
4146 | -- of the function that renames it. | |
a530b8bb AC |
4147 | |
4148 | if Aname = Name_Img then | |
4149 | Preanalyze_And_Resolve (P); | |
4150 | ||
8d80ff64 | 4151 | -- For all other attribute renamings, the prefix is a subtype |
a530b8bb AC |
4152 | |
4153 | else | |
4154 | Find_Type (P); | |
4155 | end if; | |
fbe627af | 4156 | |
4bcf6815 AC |
4157 | -- If the target type is not yet frozen, add the body to the |
4158 | -- actions to be elaborated at freeze time. | |
4159 | ||
4160 | if Is_Tagged_Type (Etype (P)) | |
4161 | and then In_Open_Scopes (Scope (Etype (P))) | |
4162 | then | |
fbe627af RD |
4163 | Ensure_Freeze_Node (Etype (P)); |
4164 | Append_Freeze_Action (Etype (P), Body_Node); | |
4165 | else | |
4166 | Rewrite (N, Body_Node); | |
4167 | Analyze (N); | |
4168 | Set_Etype (New_S, Base_Type (Etype (New_S))); | |
4169 | end if; | |
4170 | end; | |
4171 | ||
4172 | -- Generic formal subprograms or AST_Handler renaming | |
4173 | ||
4174 | else | |
4175 | Rewrite (N, Body_Node); | |
4176 | Analyze (N); | |
4177 | Set_Etype (New_S, Base_Type (Etype (New_S))); | |
4178 | end if; | |
996ae0b0 | 4179 | |
615cbd95 AC |
4180 | if Is_Compilation_Unit (New_S) then |
4181 | Error_Msg_N | |
4182 | ("a library unit can only rename another library unit", N); | |
4183 | end if; | |
996ae0b0 RK |
4184 | end Attribute_Renaming; |
4185 | ||
4186 | ---------------------- | |
4187 | -- Chain_Use_Clause -- | |
4188 | ---------------------- | |
4189 | ||
4190 | procedure Chain_Use_Clause (N : Node_Id) is | |
d4810530 | 4191 | Level : Int := Scope_Stack.Last; |
7f5e671b | 4192 | Pack : Entity_Id; |
d4810530 | 4193 | |
996ae0b0 | 4194 | begin |
851e9f19 PMR |
4195 | -- Common case |
4196 | ||
d4810530 ES |
4197 | if not Is_Compilation_Unit (Current_Scope) |
4198 | or else not Is_Child_Unit (Current_Scope) | |
4199 | then | |
851e9f19 | 4200 | null; |
d4810530 | 4201 | |
851e9f19 PMR |
4202 | -- Common case for compilation unit |
4203 | ||
4204 | elsif Defining_Entity (N => Parent (N), | |
4205 | Empty_On_Errors => True) = Current_Scope | |
4206 | then | |
4207 | null; | |
d4810530 ES |
4208 | |
4209 | else | |
4210 | -- If declaration appears in some other scope, it must be in some | |
4211 | -- parent unit when compiling a child. | |
4212 | ||
851e9f19 | 4213 | Pack := Defining_Entity (Parent (N), Empty_On_Errors => True); |
7f5e671b | 4214 | |
d4810530 | 4215 | if not In_Open_Scopes (Pack) then |
851e9f19 | 4216 | null; |
d4810530 | 4217 | |
3830827c AC |
4218 | -- If the use clause appears in an ancestor and we are in the |
4219 | -- private part of the immediate parent, the use clauses are | |
4220 | -- already installed. | |
4221 | ||
4222 | elsif Pack /= Scope (Current_Scope) | |
4223 | and then In_Private_Part (Scope (Current_Scope)) | |
4224 | then | |
4225 | null; | |
4226 | ||
d4810530 ES |
4227 | else |
4228 | -- Find entry for parent unit in scope stack | |
4229 | ||
4230 | while Scope_Stack.Table (Level).Entity /= Pack loop | |
4231 | Level := Level - 1; | |
4232 | end loop; | |
4233 | end if; | |
4234 | end if; | |
4235 | ||
996ae0b0 | 4236 | Set_Next_Use_Clause (N, |
d4810530 ES |
4237 | Scope_Stack.Table (Level).First_Use_Clause); |
4238 | Scope_Stack.Table (Level).First_Use_Clause := N; | |
996ae0b0 RK |
4239 | end Chain_Use_Clause; |
4240 | ||
15ce9ca2 AC |
4241 | --------------------------- |
4242 | -- Check_Frozen_Renaming -- | |
4243 | --------------------------- | |
996ae0b0 RK |
4244 | |
4245 | procedure Check_Frozen_Renaming (N : Node_Id; Subp : Entity_Id) is | |
4246 | B_Node : Node_Id; | |
4247 | Old_S : Entity_Id; | |
4248 | ||
4249 | begin | |
ac7d724d | 4250 | if Is_Frozen (Subp) and then not Has_Completion (Subp) then |
996ae0b0 RK |
4251 | B_Node := |
4252 | Build_Renamed_Body | |
4253 | (Parent (Declaration_Node (Subp)), Defining_Entity (N)); | |
4254 | ||
4255 | if Is_Entity_Name (Name (N)) then | |
4256 | Old_S := Entity (Name (N)); | |
4257 | ||
fbf5a39b AC |
4258 | if not Is_Frozen (Old_S) |
4259 | and then Operating_Mode /= Check_Semantics | |
4260 | then | |
4261 | Append_Freeze_Action (Old_S, B_Node); | |
996ae0b0 RK |
4262 | else |
4263 | Insert_After (N, B_Node); | |
4264 | Analyze (B_Node); | |
4265 | end if; | |
4266 | ||
ac7d724d | 4267 | if Is_Intrinsic_Subprogram (Old_S) and then not In_Instance then |
996ae0b0 RK |
4268 | Error_Msg_N |
4269 | ("subprogram used in renaming_as_body cannot be intrinsic", | |
ac7d724d | 4270 | Name (N)); |
996ae0b0 RK |
4271 | end if; |
4272 | ||
4273 | else | |
4274 | Insert_After (N, B_Node); | |
4275 | Analyze (B_Node); | |
4276 | end if; | |
4277 | end if; | |
4278 | end Check_Frozen_Renaming; | |
4279 | ||
4c484f40 AC |
4280 | ------------------------------- |
4281 | -- Set_Entity_Or_Discriminal -- | |
4282 | ------------------------------- | |
4283 | ||
4284 | procedure Set_Entity_Or_Discriminal (N : Node_Id; E : Entity_Id) is | |
4285 | P : Node_Id; | |
4286 | ||
4287 | begin | |
4288 | -- If the entity is not a discriminant, or else expansion is disabled, | |
4289 | -- simply set the entity. | |
4290 | ||
4291 | if not In_Spec_Expression | |
4292 | or else Ekind (E) /= E_Discriminant | |
4293 | or else Inside_A_Generic | |
4294 | then | |
e7ba564f | 4295 | Set_Entity_With_Checks (N, E); |
4c484f40 AC |
4296 | |
4297 | -- The replacement of a discriminant by the corresponding discriminal | |
4298 | -- is not done for a task discriminant that appears in a default | |
8779dffa | 4299 | -- expression of an entry parameter. See Exp_Ch2.Expand_Discriminant |
4c484f40 AC |
4300 | -- for details on their handling. |
4301 | ||
4302 | elsif Is_Concurrent_Type (Scope (E)) then | |
4c484f40 AC |
4303 | P := Parent (N); |
4304 | while Present (P) | |
4305 | and then not Nkind_In (P, N_Parameter_Specification, | |
ac7d724d | 4306 | N_Component_Declaration) |
4c484f40 AC |
4307 | loop |
4308 | P := Parent (P); | |
4309 | end loop; | |
4310 | ||
4311 | if Present (P) | |
4312 | and then Nkind (P) = N_Parameter_Specification | |
4313 | then | |
4314 | null; | |
4315 | ||
4316 | else | |
4317 | Set_Entity (N, Discriminal (E)); | |
4318 | end if; | |
4319 | ||
4320 | -- Otherwise, this is a discriminant in a context in which | |
4321 | -- it is a reference to the corresponding parameter of the | |
4322 | -- init proc for the enclosing type. | |
4323 | ||
4324 | else | |
4325 | Set_Entity (N, Discriminal (E)); | |
4326 | end if; | |
4327 | end Set_Entity_Or_Discriminal; | |
4328 | ||
fbf5a39b AC |
4329 | ----------------------------------- |
4330 | -- Check_In_Previous_With_Clause -- | |
4331 | ----------------------------------- | |
4332 | ||
4333 | procedure Check_In_Previous_With_Clause | |
4334 | (N : Node_Id; | |
4335 | Nam : Entity_Id) | |
4336 | is | |
4337 | Pack : constant Entity_Id := Entity (Original_Node (Nam)); | |
4338 | Item : Node_Id; | |
4339 | Par : Node_Id; | |
4340 | ||
4341 | begin | |
4342 | Item := First (Context_Items (Parent (N))); | |
ac7d724d | 4343 | while Present (Item) and then Item /= N loop |
fbf5a39b | 4344 | if Nkind (Item) = N_With_Clause |
edd63e9b | 4345 | |
ac7d724d | 4346 | -- Protect the frontend against previous critical errors |
edd63e9b ES |
4347 | |
4348 | and then Nkind (Name (Item)) /= N_Selected_Component | |
fbf5a39b AC |
4349 | and then Entity (Name (Item)) = Pack |
4350 | then | |
4351 | Par := Nam; | |
4352 | ||
bc41faa2 | 4353 | -- Find root library unit in with_clause |
fbf5a39b AC |
4354 | |
4355 | while Nkind (Par) = N_Expanded_Name loop | |
4356 | Par := Prefix (Par); | |
4357 | end loop; | |
4358 | ||
4359 | if Is_Child_Unit (Entity (Original_Node (Par))) then | |
ed2233dc | 4360 | Error_Msg_NE ("& is not directly visible", Par, Entity (Par)); |
fbf5a39b AC |
4361 | else |
4362 | return; | |
4363 | end if; | |
4364 | end if; | |
4365 | ||
4366 | Next (Item); | |
4367 | end loop; | |
4368 | ||
4369 | -- On exit, package is not mentioned in a previous with_clause. | |
4370 | -- Check if its prefix is. | |
4371 | ||
4372 | if Nkind (Nam) = N_Expanded_Name then | |
4373 | Check_In_Previous_With_Clause (N, Prefix (Nam)); | |
4374 | ||
4375 | elsif Pack /= Any_Id then | |
4376 | Error_Msg_NE ("& is not visible", Nam, Pack); | |
4377 | end if; | |
4378 | end Check_In_Previous_With_Clause; | |
4379 | ||
996ae0b0 RK |
4380 | --------------------------------- |
4381 | -- Check_Library_Unit_Renaming -- | |
4382 | --------------------------------- | |
4383 | ||
4384 | procedure Check_Library_Unit_Renaming (N : Node_Id; Old_E : Entity_Id) is | |
4385 | New_E : Entity_Id; | |
4386 | ||
4387 | begin | |
4388 | if Nkind (Parent (N)) /= N_Compilation_Unit then | |
4389 | return; | |
4390 | ||
fbe627af RD |
4391 | -- Check for library unit. Note that we used to check for the scope |
4392 | -- being Standard here, but that was wrong for Standard itself. | |
4393 | ||
4394 | elsif not Is_Compilation_Unit (Old_E) | |
996ae0b0 RK |
4395 | and then not Is_Child_Unit (Old_E) |
4396 | then | |
4397 | Error_Msg_N ("renamed unit must be a library unit", Name (N)); | |
4398 | ||
615cbd95 AC |
4399 | -- Entities defined in Standard (operators and boolean literals) cannot |
4400 | -- be renamed as library units. | |
4401 | ||
4402 | elsif Scope (Old_E) = Standard_Standard | |
4403 | and then Sloc (Old_E) = Standard_Location | |
4404 | then | |
4405 | Error_Msg_N ("renamed unit must be a library unit", Name (N)); | |
4406 | ||
996ae0b0 RK |
4407 | elsif Present (Parent_Spec (N)) |
4408 | and then Nkind (Unit (Parent_Spec (N))) = N_Generic_Package_Declaration | |
4409 | and then not Is_Child_Unit (Old_E) | |
4410 | then | |
4411 | Error_Msg_N | |
4412 | ("renamed unit must be a child unit of generic parent", Name (N)); | |
4413 | ||
4414 | elsif Nkind (N) in N_Generic_Renaming_Declaration | |
ac7d724d ES |
4415 | and then Nkind (Name (N)) = N_Expanded_Name |
4416 | and then Is_Generic_Instance (Entity (Prefix (Name (N)))) | |
4417 | and then Is_Generic_Unit (Old_E) | |
996ae0b0 RK |
4418 | then |
4419 | Error_Msg_N | |
4420 | ("renamed generic unit must be a library unit", Name (N)); | |
4421 | ||
b9b2405f ST |
4422 | elsif Is_Package_Or_Generic_Package (Old_E) then |
4423 | ||
996ae0b0 RK |
4424 | -- Inherit categorization flags |
4425 | ||
4426 | New_E := Defining_Entity (N); | |
4427 | Set_Is_Pure (New_E, Is_Pure (Old_E)); | |
4428 | Set_Is_Preelaborated (New_E, Is_Preelaborated (Old_E)); | |
4429 | Set_Is_Remote_Call_Interface (New_E, | |
4430 | Is_Remote_Call_Interface (Old_E)); | |
4431 | Set_Is_Remote_Types (New_E, Is_Remote_Types (Old_E)); | |
4432 | Set_Is_Shared_Passive (New_E, Is_Shared_Passive (Old_E)); | |
4433 | end if; | |
4434 | end Check_Library_Unit_Renaming; | |
4435 | ||
ac7d724d ES |
4436 | ------------------------ |
4437 | -- Enclosing_Instance -- | |
4438 | ------------------------ | |
4439 | ||
4440 | function Enclosing_Instance return Entity_Id is | |
4441 | S : Entity_Id; | |
4442 | ||
4443 | begin | |
4444 | if not Is_Generic_Instance (Current_Scope) then | |
4445 | return Empty; | |
4446 | end if; | |
4447 | ||
4448 | S := Scope (Current_Scope); | |
4449 | while S /= Standard_Standard loop | |
4450 | if Is_Generic_Instance (S) then | |
4451 | return S; | |
4452 | end if; | |
4453 | ||
4454 | S := Scope (S); | |
4455 | end loop; | |
4456 | ||
4457 | return Empty; | |
4458 | end Enclosing_Instance; | |
4459 | ||
996ae0b0 RK |
4460 | --------------- |
4461 | -- End_Scope -- | |
4462 | --------------- | |
4463 | ||
4464 | procedure End_Scope is | |
4465 | Id : Entity_Id; | |
4466 | Prev : Entity_Id; | |
4467 | Outer : Entity_Id; | |
4468 | ||
4469 | begin | |
4470 | Id := First_Entity (Current_Scope); | |
996ae0b0 RK |
4471 | while Present (Id) loop |
4472 | -- An entity in the current scope is not necessarily the first one | |
4473 | -- on its homonym chain. Find its predecessor if any, | |
4474 | -- If it is an internal entity, it will not be in the visibility | |
4475 | -- chain altogether, and there is nothing to unchain. | |
4476 | ||
4477 | if Id /= Current_Entity (Id) then | |
4478 | Prev := Current_Entity (Id); | |
4479 | while Present (Prev) | |
4480 | and then Present (Homonym (Prev)) | |
4481 | and then Homonym (Prev) /= Id | |
4482 | loop | |
4483 | Prev := Homonym (Prev); | |
4484 | end loop; | |
4485 | ||
4486 | -- Skip to end of loop if Id is not in the visibility chain | |
4487 | ||
4488 | if No (Prev) or else Homonym (Prev) /= Id then | |
4489 | goto Next_Ent; | |
4490 | end if; | |
4491 | ||
4492 | else | |
4493 | Prev := Empty; | |
4494 | end if; | |
4495 | ||
996ae0b0 RK |
4496 | Set_Is_Immediately_Visible (Id, False); |
4497 | ||
16ca248a | 4498 | Outer := Homonym (Id); |
996ae0b0 RK |
4499 | while Present (Outer) and then Scope (Outer) = Current_Scope loop |
4500 | Outer := Homonym (Outer); | |
4501 | end loop; | |
4502 | ||
4503 | -- Reset homonym link of other entities, but do not modify link | |
4504 | -- between entities in current scope, so that the back-end can have | |
4505 | -- a proper count of local overloadings. | |
4506 | ||
4507 | if No (Prev) then | |
4508 | Set_Name_Entity_Id (Chars (Id), Outer); | |
4509 | ||
4510 | elsif Scope (Prev) /= Scope (Id) then | |
4511 | Set_Homonym (Prev, Outer); | |
4512 | end if; | |
4513 | ||
4514 | <<Next_Ent>> | |
4515 | Next_Entity (Id); | |
4516 | end loop; | |
4517 | ||
4518 | -- If the scope generated freeze actions, place them before the | |
4519 | -- current declaration and analyze them. Type declarations and | |
4520 | -- the bodies of initialization procedures can generate such nodes. | |
4521 | -- We follow the parent chain until we reach a list node, which is | |
4522 | -- the enclosing list of declarations. If the list appears within | |
4523 | -- a protected definition, move freeze nodes outside the protected | |
4524 | -- type altogether. | |
4525 | ||
4526 | if Present | |
4527 | (Scope_Stack.Table (Scope_Stack.Last).Pending_Freeze_Actions) | |
4528 | then | |
4529 | declare | |
4530 | Decl : Node_Id; | |
4531 | L : constant List_Id := Scope_Stack.Table | |
4532 | (Scope_Stack.Last).Pending_Freeze_Actions; | |
4533 | ||
4534 | begin | |
4535 | if Is_Itype (Current_Scope) then | |
4536 | Decl := Associated_Node_For_Itype (Current_Scope); | |
4537 | else | |
4538 | Decl := Parent (Current_Scope); | |
4539 | end if; | |
4540 | ||
4541 | Pop_Scope; | |
4542 | ||
4543 | while not (Is_List_Member (Decl)) | |
294ccb21 RD |
4544 | or else Nkind_In (Parent (Decl), N_Protected_Definition, |
4545 | N_Task_Definition) | |
996ae0b0 RK |
4546 | loop |
4547 | Decl := Parent (Decl); | |
4548 | end loop; | |
4549 | ||
4550 | Insert_List_Before_And_Analyze (Decl, L); | |
4551 | end; | |
4552 | ||
4553 | else | |
4554 | Pop_Scope; | |
4555 | end if; | |
996ae0b0 RK |
4556 | end End_Scope; |
4557 | ||
4558 | --------------------- | |
4559 | -- End_Use_Clauses -- | |
4560 | --------------------- | |
4561 | ||
4562 | procedure End_Use_Clauses (Clause : Node_Id) is | |
851e9f19 | 4563 | U : Node_Id; |
996ae0b0 RK |
4564 | |
4565 | begin | |
851e9f19 PMR |
4566 | -- Remove use_type_clauses first, because they affect the visibility of |
4567 | -- operators in subsequent used packages. | |
fbf5a39b AC |
4568 | |
4569 | U := Clause; | |
4570 | while Present (U) loop | |
4571 | if Nkind (U) = N_Use_Type_Clause then | |
4572 | End_Use_Type (U); | |
4573 | end if; | |
4574 | ||
4575 | Next_Use_Clause (U); | |
4576 | end loop; | |
4577 | ||
4578 | U := Clause; | |
996ae0b0 RK |
4579 | while Present (U) loop |
4580 | if Nkind (U) = N_Use_Package_Clause then | |
4581 | End_Use_Package (U); | |
996ae0b0 RK |
4582 | end if; |
4583 | ||
4584 | Next_Use_Clause (U); | |
4585 | end loop; | |
4586 | end End_Use_Clauses; | |
4587 | ||
4588 | --------------------- | |
4589 | -- End_Use_Package -- | |
4590 | --------------------- | |
4591 | ||
4592 | procedure End_Use_Package (N : Node_Id) is | |
996ae0b0 | 4593 | Pack : Entity_Id; |
851e9f19 | 4594 | Pack_Name : Node_Id; |
996ae0b0 RK |
4595 | Id : Entity_Id; |
4596 | Elmt : Elmt_Id; | |
4597 | ||
a780db15 | 4598 | function Is_Primitive_Operator_In_Use |
2e071734 AC |
4599 | (Op : Entity_Id; |
4600 | F : Entity_Id) return Boolean; | |
fbf5a39b AC |
4601 | -- Check whether Op is a primitive operator of a use-visible type |
4602 | ||
a780db15 AC |
4603 | ---------------------------------- |
4604 | -- Is_Primitive_Operator_In_Use -- | |
4605 | ---------------------------------- | |
fbf5a39b | 4606 | |
a780db15 | 4607 | function Is_Primitive_Operator_In_Use |
2e071734 AC |
4608 | (Op : Entity_Id; |
4609 | F : Entity_Id) return Boolean | |
fbf5a39b | 4610 | is |
95eb8b69 | 4611 | T : constant Entity_Id := Base_Type (Etype (F)); |
fbf5a39b | 4612 | begin |
95eb8b69 | 4613 | return In_Use (T) and then Scope (T) = Scope (Op); |
a780db15 | 4614 | end Is_Primitive_Operator_In_Use; |
fbf5a39b AC |
4615 | |
4616 | -- Start of processing for End_Use_Package | |
4617 | ||
996ae0b0 | 4618 | begin |
851e9f19 | 4619 | Pack_Name := Name (N); |
996ae0b0 | 4620 | |
851e9f19 | 4621 | -- Test that Pack_Name actually denotes a package before processing |
462c31ef | 4622 | |
851e9f19 PMR |
4623 | if Is_Entity_Name (Pack_Name) |
4624 | and then Ekind (Entity (Pack_Name)) = E_Package | |
4625 | then | |
4626 | Pack := Entity (Pack_Name); | |
462c31ef | 4627 | |
851e9f19 PMR |
4628 | if In_Open_Scopes (Pack) then |
4629 | null; | |
996ae0b0 | 4630 | |
851e9f19 PMR |
4631 | elsif not Redundant_Use (Pack_Name) then |
4632 | Set_In_Use (Pack, False); | |
4633 | Set_Current_Use_Clause (Pack, Empty); | |
996ae0b0 | 4634 | |
851e9f19 PMR |
4635 | Id := First_Entity (Pack); |
4636 | while Present (Id) loop | |
996ae0b0 | 4637 | |
851e9f19 PMR |
4638 | -- Preserve use-visibility of operators that are primitive |
4639 | -- operators of a type that is use-visible through an active | |
4640 | -- use_type_clause. | |
996ae0b0 | 4641 | |
851e9f19 PMR |
4642 | if Nkind (Id) = N_Defining_Operator_Symbol |
4643 | and then | |
4644 | (Is_Primitive_Operator_In_Use (Id, First_Formal (Id)) | |
4645 | or else | |
4646 | (Present (Next_Formal (First_Formal (Id))) | |
4647 | and then | |
4648 | Is_Primitive_Operator_In_Use | |
4649 | (Id, Next_Formal (First_Formal (Id))))) | |
4650 | then | |
4651 | null; | |
4652 | else | |
4653 | Set_Is_Potentially_Use_Visible (Id, False); | |
4654 | end if; | |
4655 | ||
4656 | if Is_Private_Type (Id) | |
4657 | and then Present (Full_View (Id)) | |
4658 | then | |
4659 | Set_Is_Potentially_Use_Visible (Full_View (Id), False); | |
4660 | end if; | |
4661 | ||
4662 | Next_Entity (Id); | |
4663 | end loop; | |
4664 | ||
4665 | if Present (Renamed_Object (Pack)) then | |
4666 | Set_In_Use (Renamed_Object (Pack), False); | |
4667 | Set_Current_Use_Clause (Renamed_Object (Pack), Empty); | |
4668 | end if; | |
4669 | ||
4670 | if Chars (Pack) = Name_System | |
4671 | and then Scope (Pack) = Standard_Standard | |
4672 | and then Present_System_Aux | |
4673 | then | |
4674 | Id := First_Entity (System_Aux_Id); | |
4675 | while Present (Id) loop | |
4676 | Set_Is_Potentially_Use_Visible (Id, False); | |
996ae0b0 RK |
4677 | |
4678 | if Is_Private_Type (Id) | |
4679 | and then Present (Full_View (Id)) | |
4680 | then | |
4681 | Set_Is_Potentially_Use_Visible (Full_View (Id), False); | |
4682 | end if; | |
4683 | ||
4684 | Next_Entity (Id); | |
4685 | end loop; | |
4686 | ||
851e9f19 | 4687 | Set_In_Use (System_Aux_Id, False); |
996ae0b0 | 4688 | end if; |
851e9f19 PMR |
4689 | else |
4690 | Set_Redundant_Use (Pack_Name, False); | |
996ae0b0 | 4691 | end if; |
851e9f19 | 4692 | end if; |
996ae0b0 RK |
4693 | |
4694 | if Present (Hidden_By_Use_Clause (N)) then | |
4695 | Elmt := First_Elmt (Hidden_By_Use_Clause (N)); | |
996ae0b0 | 4696 | while Present (Elmt) loop |
e69614ad AC |
4697 | declare |
4698 | E : constant Entity_Id := Node (Elmt); | |
4699 | ||
4700 | begin | |
4701 | -- Reset either Use_Visibility or Direct_Visibility, depending | |
4702 | -- on how the entity was hidden by the use clause. | |
4703 | ||
4704 | if In_Use (Scope (E)) | |
4705 | and then Used_As_Generic_Actual (Scope (E)) | |
4706 | then | |
4707 | Set_Is_Potentially_Use_Visible (Node (Elmt)); | |
4708 | else | |
4709 | Set_Is_Immediately_Visible (Node (Elmt)); | |
4710 | end if; | |
4711 | ||
4712 | Next_Elmt (Elmt); | |
4713 | end; | |
996ae0b0 RK |
4714 | end loop; |
4715 | ||
4716 | Set_Hidden_By_Use_Clause (N, No_Elist); | |
4717 | end if; | |
4718 | end End_Use_Package; | |
4719 | ||
4720 | ------------------ | |
4721 | -- End_Use_Type -- | |
4722 | ------------------ | |
4723 | ||
4724 | procedure End_Use_Type (N : Node_Id) is | |
851e9f19 PMR |
4725 | Elmt : Elmt_Id; |
4726 | Id : Entity_Id; | |
4727 | T : Entity_Id; | |
996ae0b0 | 4728 | |
4a214958 AC |
4729 | -- Start of processing for End_Use_Type |
4730 | ||
996ae0b0 | 4731 | begin |
851e9f19 | 4732 | Id := Subtype_Mark (N); |
fbf5a39b | 4733 | |
851e9f19 PMR |
4734 | -- A call to Rtsfind may occur while analyzing a use_type_clause, in |
4735 | -- which case the type marks are not resolved yet, so guard against that | |
4736 | -- here. | |
fbf5a39b | 4737 | |
851e9f19 | 4738 | if Is_Entity_Name (Id) and then Present (Entity (Id)) then |
996ae0b0 RK |
4739 | T := Entity (Id); |
4740 | ||
7b56a91b | 4741 | if T = Any_Type or else From_Limited_With (T) then |
996ae0b0 RK |
4742 | null; |
4743 | ||
851e9f19 | 4744 | -- Note that the use_type_clause may mention a subtype of the type |
16ca248a ES |
4745 | -- whose primitive operations have been made visible. Here as |
4746 | -- elsewhere, it is the base type that matters for visibility. | |
996ae0b0 RK |
4747 | |
4748 | elsif In_Open_Scopes (Scope (Base_Type (T))) then | |
4749 | null; | |
4750 | ||
4751 | elsif not Redundant_Use (Id) then | |
4752 | Set_In_Use (T, False); | |
4753 | Set_In_Use (Base_Type (T), False); | |
21d27997 RD |
4754 | Set_Current_Use_Clause (T, Empty); |
4755 | Set_Current_Use_Clause (Base_Type (T), Empty); | |
996ae0b0 | 4756 | end if; |
851e9f19 | 4757 | end if; |
29efbb8c ES |
4758 | |
4759 | if Is_Empty_Elmt_List (Used_Operations (N)) then | |
4760 | return; | |
4761 | ||
4762 | else | |
4763 | Elmt := First_Elmt (Used_Operations (N)); | |
4764 | while Present (Elmt) loop | |
4765 | Set_Is_Potentially_Use_Visible (Node (Elmt), False); | |
4766 | Next_Elmt (Elmt); | |
4767 | end loop; | |
4768 | end if; | |
996ae0b0 RK |
4769 | end End_Use_Type; |
4770 | ||
851e9f19 PMR |
4771 | -------------------- |
4772 | -- Entity_Of_Unit -- | |
4773 | -------------------- | |
4774 | ||
4775 | function Entity_Of_Unit (U : Node_Id) return Entity_Id is | |
4776 | begin | |
7f5e671b | 4777 | if Nkind (U) = N_Package_Instantiation and then Analyzed (U) then |
851e9f19 PMR |
4778 | return Defining_Entity (Instance_Spec (U)); |
4779 | else | |
4780 | return Defining_Entity (U); | |
4781 | end if; | |
4782 | end Entity_Of_Unit; | |
4783 | ||
996ae0b0 RK |
4784 | ---------------------- |
4785 | -- Find_Direct_Name -- | |
4786 | ---------------------- | |
4787 | ||
4788 | procedure Find_Direct_Name (N : Node_Id) is | |
522aa6ee AC |
4789 | E : Entity_Id; |
4790 | E2 : Entity_Id; | |
4791 | Msg : Boolean; | |
996ae0b0 RK |
4792 | |
4793 | Homonyms : Entity_Id; | |
4794 | -- Saves start of homonym chain | |
4795 | ||
522aa6ee AC |
4796 | Inst : Entity_Id := Empty; |
4797 | -- Enclosing instance, if any | |
4798 | ||
996ae0b0 | 4799 | Nvis_Entity : Boolean; |
3764bb00 BD |
4800 | -- Set True to indicate that there is at least one entity on the homonym |
4801 | -- chain which, while not visible, is visible enough from the user point | |
4802 | -- of view to warrant an error message of "not visible" rather than | |
4803 | -- undefined. | |
996ae0b0 | 4804 | |
9bc856dd | 4805 | Nvis_Is_Private_Subprg : Boolean := False; |
0ab80019 | 4806 | -- Ada 2005 (AI-262): Set True to indicate that a form of Beaujolais |
9bc856dd AC |
4807 | -- effect concerning library subprograms has been detected. Used to |
4808 | -- generate the precise error message. | |
4809 | ||
996ae0b0 | 4810 | function From_Actual_Package (E : Entity_Id) return Boolean; |
fba9ebfc | 4811 | -- Returns true if the entity is an actual for a package that is itself |
996ae0b0 | 4812 | -- an actual for a formal package of the current instance. Such an |
fba9ebfc AC |
4813 | -- entity requires special handling because it may be use-visible but |
4814 | -- hides directly visible entities defined outside the instance, because | |
4815 | -- the corresponding formal did so in the generic. | |
996ae0b0 | 4816 | |
67ce0d7e RD |
4817 | function Is_Actual_Parameter return Boolean; |
4818 | -- This function checks if the node N is an identifier that is an actual | |
4819 | -- parameter of a procedure call. If so it returns True, otherwise it | |
4820 | -- return False. The reason for this check is that at this stage we do | |
4821 | -- not know what procedure is being called if the procedure might be | |
4822 | -- overloaded, so it is premature to go setting referenced flags or | |
4823 | -- making calls to Generate_Reference. We will wait till Resolve_Actuals | |
4824 | -- for that processing | |
4825 | ||
996ae0b0 | 4826 | function Known_But_Invisible (E : Entity_Id) return Boolean; |
a43f6434 AC |
4827 | -- This function determines whether a reference to the entity E, which |
4828 | -- is not visible, can reasonably be considered to be known to the | |
4829 | -- writer of the reference. This is a heuristic test, used only for | |
4830 | -- the purposes of figuring out whether we prefer to complain that an | |
4831 | -- entity is undefined or invisible (and identify the declaration of | |
4832 | -- the invisible entity in the latter case). The point here is that we | |
4833 | -- don't want to complain that something is invisible and then point to | |
4834 | -- something entirely mysterious to the writer. | |
996ae0b0 RK |
4835 | |
4836 | procedure Nvis_Messages; | |
4837 | -- Called if there are no visible entries for N, but there is at least | |
4838 | -- one non-directly visible, or hidden declaration. This procedure | |
4839 | -- outputs an appropriate set of error messages. | |
4840 | ||
4841 | procedure Undefined (Nvis : Boolean); | |
4842 | -- This function is called if the current node has no corresponding | |
4843 | -- visible entity or entities. The value set in Msg indicates whether | |
4844 | -- an error message was generated (multiple error messages for the | |
4845 | -- same variable are generally suppressed, see body for details). | |
4846 | -- Msg is True if an error message was generated, False if not. This | |
4847 | -- value is used by the caller to determine whether or not to output | |
4848 | -- additional messages where appropriate. The parameter is set False | |
4849 | -- to get the message "X is undefined", and True to get the message | |
4850 | -- "X is not visible". | |
4851 | ||
4852 | ------------------------- | |
4853 | -- From_Actual_Package -- | |
4854 | ------------------------- | |
4855 | ||
4856 | function From_Actual_Package (E : Entity_Id) return Boolean is | |
4857 | Scop : constant Entity_Id := Scope (E); | |
fba9ebfc AC |
4858 | -- Declared scope of candidate entity |
4859 | ||
fba9ebfc AC |
4860 | function Declared_In_Actual (Pack : Entity_Id) return Boolean; |
4861 | -- Recursive function that does the work and examines actuals of | |
4862 | -- actual packages of current instance. | |
4863 | ||
4864 | ------------------------ | |
4865 | -- Declared_In_Actual -- | |
4866 | ------------------------ | |
4867 | ||
4868 | function Declared_In_Actual (Pack : Entity_Id) return Boolean is | |
4869 | Act : Entity_Id; | |
4870 | ||
4871 | begin | |
4872 | if No (Associated_Formal_Package (Pack)) then | |
4873 | return False; | |
4874 | ||
4875 | else | |
4876 | Act := First_Entity (Pack); | |
4877 | while Present (Act) loop | |
4878 | if Renamed_Object (Pack) = Scop then | |
4879 | return True; | |
4880 | ||
522aa6ee | 4881 | -- Check for end of list of actuals |
fba9ebfc AC |
4882 | |
4883 | elsif Ekind (Act) = E_Package | |
4884 | and then Renamed_Object (Act) = Pack | |
4885 | then | |
4886 | return False; | |
4887 | ||
4888 | elsif Ekind (Act) = E_Package | |
4889 | and then Declared_In_Actual (Act) | |
4890 | then | |
4891 | return True; | |
4892 | end if; | |
4893 | ||
4894 | Next_Entity (Act); | |
4895 | end loop; | |
4896 | ||
4897 | return False; | |
4898 | end if; | |
4899 | end Declared_In_Actual; | |
4900 | ||
522aa6ee AC |
4901 | -- Local variables |
4902 | ||
4903 | Act : Entity_Id; | |
4904 | ||
fba9ebfc | 4905 | -- Start of processing for From_Actual_Package |
996ae0b0 RK |
4906 | |
4907 | begin | |
4908 | if not In_Instance then | |
4909 | return False; | |
fba9ebfc | 4910 | |
996ae0b0 RK |
4911 | else |
4912 | Inst := Current_Scope; | |
996ae0b0 RK |
4913 | while Present (Inst) |
4914 | and then Ekind (Inst) /= E_Package | |
4915 | and then not Is_Generic_Instance (Inst) | |
4916 | loop | |
4917 | Inst := Scope (Inst); | |
4918 | end loop; | |
4919 | ||
4920 | if No (Inst) then | |
4921 | return False; | |
4922 | end if; | |
4923 | ||
4924 | Act := First_Entity (Inst); | |
996ae0b0 | 4925 | while Present (Act) loop |
fba9ebfc AC |
4926 | if Ekind (Act) = E_Package |
4927 | and then Declared_In_Actual (Act) | |
4928 | then | |
4929 | return True; | |
996ae0b0 | 4930 | end if; |
fba9ebfc AC |
4931 | |
4932 | Next_Entity (Act); | |
996ae0b0 RK |
4933 | end loop; |
4934 | ||
4935 | return False; | |
4936 | end if; | |
4937 | end From_Actual_Package; | |
4938 | ||
67ce0d7e RD |
4939 | ------------------------- |
4940 | -- Is_Actual_Parameter -- | |
4941 | ------------------------- | |
4942 | ||
4943 | function Is_Actual_Parameter return Boolean is | |
4944 | begin | |
4945 | return | |
4946 | Nkind (N) = N_Identifier | |
4947 | and then | |
4948 | (Nkind (Parent (N)) = N_Procedure_Call_Statement | |
ac7d724d ES |
4949 | or else |
4950 | (Nkind (Parent (N)) = N_Parameter_Association | |
4951 | and then N = Explicit_Actual_Parameter (Parent (N)) | |
4952 | and then Nkind (Parent (Parent (N))) = | |
67ce0d7e RD |
4953 | N_Procedure_Call_Statement)); |
4954 | end Is_Actual_Parameter; | |
4955 | ||
996ae0b0 RK |
4956 | ------------------------- |
4957 | -- Known_But_Invisible -- | |
4958 | ------------------------- | |
4959 | ||
4960 | function Known_But_Invisible (E : Entity_Id) return Boolean is | |
4961 | Fname : File_Name_Type; | |
4962 | ||
4963 | begin | |
4964 | -- Entities in Standard are always considered to be known | |
4965 | ||
4966 | if Sloc (E) <= Standard_Location then | |
4967 | return True; | |
4968 | ||
4969 | -- An entity that does not come from source is always considered | |
4970 | -- to be unknown, since it is an artifact of code expansion. | |
4971 | ||
4972 | elsif not Comes_From_Source (E) then | |
4973 | return False; | |
4974 | ||
a43f6434 AC |
4975 | -- In gnat internal mode, we consider all entities known. The |
4976 | -- historical reason behind this discrepancy is not known??? But the | |
4977 | -- only effect is to modify the error message given, so it is not | |
4978 | -- critical. Since it only affects the exact wording of error | |
4979 | -- messages in illegal programs, we do not mention this as an | |
4980 | -- effect of -gnatg, since it is not a language modification. | |
996ae0b0 RK |
4981 | |
4982 | elsif GNAT_Mode then | |
4983 | return True; | |
4984 | end if; | |
4985 | ||
4986 | -- Here we have an entity that is not from package Standard, and | |
4987 | -- which comes from Source. See if it comes from an internal file. | |
4988 | ||
4989 | Fname := Unit_File_Name (Get_Source_Unit (E)); | |
4990 | ||
4991 | -- Case of from internal file | |
4992 | ||
8ab31c0c | 4993 | if In_Internal_Unit (E) then |
996ae0b0 RK |
4994 | |
4995 | -- Private part entities in internal files are never considered | |
4996 | -- to be known to the writer of normal application code. | |
4997 | ||
4998 | if Is_Hidden (E) then | |
4999 | return False; | |
5000 | end if; | |
5001 | ||
5002 | -- Entities from System packages other than System and | |
5003 | -- System.Storage_Elements are not considered to be known. | |
5004 | -- System.Auxxxx files are also considered known to the user. | |
5005 | ||
5006 | -- Should refine this at some point to generally distinguish | |
5007 | -- between known and unknown internal files ??? | |
5008 | ||
5009 | Get_Name_String (Fname); | |
5010 | ||
5011 | return | |
5012 | Name_Len < 2 | |
5013 | or else | |
5014 | Name_Buffer (1 .. 2) /= "s-" | |
5015 | or else | |
5016 | Name_Buffer (3 .. 8) = "stoele" | |
5017 | or else | |
5018 | Name_Buffer (3 .. 5) = "aux"; | |
5019 | ||
497a660d AC |
5020 | -- If not an internal file, then entity is definitely known, even if |
5021 | -- it is in a private part (the message generated will note that it | |
5022 | -- is in a private part). | |
996ae0b0 RK |
5023 | |
5024 | else | |
5025 | return True; | |
5026 | end if; | |
5027 | end Known_But_Invisible; | |
5028 | ||
5029 | ------------------- | |
5030 | -- Nvis_Messages -- | |
5031 | ------------------- | |
5032 | ||
5033 | procedure Nvis_Messages is | |
9bc856dd AC |
5034 | Comp_Unit : Node_Id; |
5035 | Ent : Entity_Id; | |
1175f0b6 | 5036 | Found : Boolean := False; |
9bc856dd AC |
5037 | Hidden : Boolean := False; |
5038 | Item : Node_Id; | |
996ae0b0 RK |
5039 | |
5040 | begin | |
0ab80019 | 5041 | -- Ada 2005 (AI-262): Generate a precise error concerning the |
9bc856dd AC |
5042 | -- Beaujolais effect that was previously detected |
5043 | ||
5044 | if Nvis_Is_Private_Subprg then | |
5045 | ||
5046 | pragma Assert (Nkind (E2) = N_Defining_Identifier | |
16ca248a ES |
5047 | and then Ekind (E2) = E_Function |
5048 | and then Scope (E2) = Standard_Standard | |
5049 | and then Has_Private_With (E2)); | |
9bc856dd AC |
5050 | |
5051 | -- Find the sloc corresponding to the private with'ed unit | |
5052 | ||
16ca248a | 5053 | Comp_Unit := Cunit (Current_Sem_Unit); |
9bc856dd AC |
5054 | Error_Msg_Sloc := No_Location; |
5055 | ||
16ca248a | 5056 | Item := First (Context_Items (Comp_Unit)); |
9bc856dd AC |
5057 | while Present (Item) loop |
5058 | if Nkind (Item) = N_With_Clause | |
5059 | and then Private_Present (Item) | |
5060 | and then Entity (Name (Item)) = E2 | |
5061 | then | |
5062 | Error_Msg_Sloc := Sloc (Item); | |
5063 | exit; | |
5064 | end if; | |
5065 | ||
5066 | Next (Item); | |
5067 | end loop; | |
5068 | ||
5069 | pragma Assert (Error_Msg_Sloc /= No_Location); | |
5070 | ||
0ab80019 | 5071 | Error_Msg_N ("(Ada 2005): hidden by private with clause #", N); |
9bc856dd AC |
5072 | return; |
5073 | end if; | |
5074 | ||
996ae0b0 RK |
5075 | Undefined (Nvis => True); |
5076 | ||
5077 | if Msg then | |
5078 | ||
5079 | -- First loop does hidden declarations | |
5080 | ||
5081 | Ent := Homonyms; | |
5082 | while Present (Ent) loop | |
5083 | if Is_Potentially_Use_Visible (Ent) then | |
996ae0b0 | 5084 | if not Hidden then |
deef4289 AC |
5085 | Error_Msg_N -- CODEFIX |
5086 | ("multiple use clauses cause hiding!", N); | |
996ae0b0 RK |
5087 | Hidden := True; |
5088 | end if; | |
5089 | ||
5090 | Error_Msg_Sloc := Sloc (Ent); | |
4e7a4f6e AC |
5091 | Error_Msg_N -- CODEFIX |
5092 | ("hidden declaration#!", N); | |
996ae0b0 RK |
5093 | end if; |
5094 | ||
5095 | Ent := Homonym (Ent); | |
5096 | end loop; | |
5097 | ||
5098 | -- If we found hidden declarations, then that's enough, don't | |
5099 | -- bother looking for non-visible declarations as well. | |
5100 | ||
5101 | if Hidden then | |
5102 | return; | |
5103 | end if; | |
5104 | ||
5105 | -- Second loop does non-directly visible declarations | |
5106 | ||
5107 | Ent := Homonyms; | |
5108 | while Present (Ent) loop | |
5109 | if not Is_Potentially_Use_Visible (Ent) then | |
5110 | ||
5111 | -- Do not bother the user with unknown entities | |
5112 | ||
5113 | if not Known_But_Invisible (Ent) then | |
5114 | goto Continue; | |
5115 | end if; | |
5116 | ||
5117 | Error_Msg_Sloc := Sloc (Ent); | |
5118 | ||
5119 | -- Output message noting that there is a non-visible | |
5120 | -- declaration, distinguishing the private part case. | |
5121 | ||
5122 | if Is_Hidden (Ent) then | |
5123 | Error_Msg_N ("non-visible (private) declaration#!", N); | |
1175f0b6 AC |
5124 | |
5125 | -- If the entity is declared in a generic package, it | |
5126 | -- cannot be visible, so there is no point in adding it | |
5127 | -- to the list of candidates if another homograph from a | |
5128 | -- non-generic package has been seen. | |
5129 | ||
5130 | elsif Ekind (Scope (Ent)) = E_Generic_Package | |
5131 | and then Found | |
5132 | then | |
5133 | null; | |
5134 | ||
996ae0b0 | 5135 | else |
483c78cb RD |
5136 | Error_Msg_N -- CODEFIX |
5137 | ("non-visible declaration#!", N); | |
fbf5a39b | 5138 | |
1175f0b6 AC |
5139 | if Ekind (Scope (Ent)) /= E_Generic_Package then |
5140 | Found := True; | |
5141 | end if; | |
5142 | ||
fbf5a39b AC |
5143 | if Is_Compilation_Unit (Ent) |
5144 | and then | |
5145 | Nkind (Parent (Parent (N))) = N_Use_Package_Clause | |
5146 | then | |
16ca248a | 5147 | Error_Msg_Qual_Level := 99; |
ed2233dc AC |
5148 | Error_Msg_NE -- CODEFIX |
5149 | ("\\missing `WITH &;`", N, Ent); | |
16ca248a | 5150 | Error_Msg_Qual_Level := 0; |
fbf5a39b | 5151 | end if; |
e1b871e9 AC |
5152 | |
5153 | if Ekind (Ent) = E_Discriminant | |
5154 | and then Present (Corresponding_Discriminant (Ent)) | |
5155 | and then Scope (Corresponding_Discriminant (Ent)) = | |
5156 | Etype (Scope (Ent)) | |
5157 | then | |
5158 | Error_Msg_N | |
5159 | ("inherited discriminant not allowed here" & | |
5160 | " (RM 3.8 (12), 3.8.1 (6))!", N); | |
5161 | end if; | |
996ae0b0 | 5162 | end if; |
07fc65c4 GB |
5163 | |
5164 | -- Set entity and its containing package as referenced. We | |
5165 | -- can't be sure of this, but this seems a better choice | |
5166 | -- to avoid unused entity messages. | |
5167 | ||
5168 | if Comes_From_Source (Ent) then | |
5169 | Set_Referenced (Ent); | |
5170 | Set_Referenced (Cunit_Entity (Get_Source_Unit (Ent))); | |
5171 | end if; | |
996ae0b0 RK |
5172 | end if; |
5173 | ||
5174 | <<Continue>> | |
5175 | Ent := Homonym (Ent); | |
5176 | end loop; | |
996ae0b0 RK |
5177 | end if; |
5178 | end Nvis_Messages; | |
5179 | ||
5180 | --------------- | |
5181 | -- Undefined -- | |
5182 | --------------- | |
5183 | ||
5184 | procedure Undefined (Nvis : Boolean) is | |
5185 | Emsg : Error_Msg_Id; | |
5186 | ||
5187 | begin | |
fbf5a39b AC |
5188 | -- We should never find an undefined internal name. If we do, then |
5189 | -- see if we have previous errors. If so, ignore on the grounds that | |
5190 | -- it is probably a cascaded message (e.g. a block label from a badly | |
5191 | -- formed block). If no previous errors, then we have a real internal | |
5192 | -- error of some kind so raise an exception. | |
5193 | ||
5194 | if Is_Internal_Name (Chars (N)) then | |
5195 | if Total_Errors_Detected /= 0 then | |
5196 | return; | |
5197 | else | |
5198 | raise Program_Error; | |
5199 | end if; | |
5200 | end if; | |
5201 | ||
996ae0b0 RK |
5202 | -- A very specialized error check, if the undefined variable is |
5203 | -- a case tag, and the case type is an enumeration type, check | |
5204 | -- for a possible misspelling, and if so, modify the identifier | |
5205 | ||
5206 | -- Named aggregate should also be handled similarly ??? | |
5207 | ||
5208 | if Nkind (N) = N_Identifier | |
5209 | and then Nkind (Parent (N)) = N_Case_Statement_Alternative | |
5210 | then | |
996ae0b0 | 5211 | declare |
996ae0b0 RK |
5212 | Case_Stm : constant Node_Id := Parent (Parent (N)); |
5213 | Case_Typ : constant Entity_Id := Etype (Expression (Case_Stm)); | |
5214 | ||
5215 | Lit : Node_Id; | |
5216 | ||
5217 | begin | |
5218 | if Is_Enumeration_Type (Case_Typ) | |
21d27997 | 5219 | and then not Is_Standard_Character_Type (Case_Typ) |
996ae0b0 RK |
5220 | then |
5221 | Lit := First_Literal (Case_Typ); | |
5222 | Get_Name_String (Chars (Lit)); | |
5223 | ||
5224 | if Chars (Lit) /= Chars (N) | |
0b7f0f0e AC |
5225 | and then Is_Bad_Spelling_Of (Chars (N), Chars (Lit)) |
5226 | then | |
996ae0b0 | 5227 | Error_Msg_Node_2 := Lit; |
ed2233dc | 5228 | Error_Msg_N -- CODEFIX |
996ae0b0 RK |
5229 | ("& is undefined, assume misspelling of &", N); |
5230 | Rewrite (N, New_Occurrence_Of (Lit, Sloc (N))); | |
5231 | return; | |
5232 | end if; | |
5233 | ||
5234 | Lit := Next_Literal (Lit); | |
5235 | end if; | |
5236 | end; | |
5237 | end if; | |
5238 | ||
5239 | -- Normal processing | |
5240 | ||
5241 | Set_Entity (N, Any_Id); | |
5242 | Set_Etype (N, Any_Type); | |
5243 | ||
5244 | -- We use the table Urefs to keep track of entities for which we | |
5245 | -- have issued errors for undefined references. Multiple errors | |
5246 | -- for a single name are normally suppressed, however we modify | |
5247 | -- the error message to alert the programmer to this effect. | |
5248 | ||
5249 | for J in Urefs.First .. Urefs.Last loop | |
5250 | if Chars (N) = Chars (Urefs.Table (J).Node) then | |
5251 | if Urefs.Table (J).Err /= No_Error_Msg | |
5252 | and then Sloc (N) /= Urefs.Table (J).Loc | |
5253 | then | |
5254 | Error_Msg_Node_1 := Urefs.Table (J).Node; | |
5255 | ||
5256 | if Urefs.Table (J).Nvis then | |
5257 | Change_Error_Text (Urefs.Table (J).Err, | |
5258 | "& is not visible (more references follow)"); | |
5259 | else | |
5260 | Change_Error_Text (Urefs.Table (J).Err, | |
5261 | "& is undefined (more references follow)"); | |
5262 | end if; | |
5263 | ||
5264 | Urefs.Table (J).Err := No_Error_Msg; | |
5265 | end if; | |
5266 | ||
5267 | -- Although we will set Msg False, and thus suppress the | |
5268 | -- message, we also set Error_Posted True, to avoid any | |
5269 | -- cascaded messages resulting from the undefined reference. | |
5270 | ||
5271 | Msg := False; | |
5272 | Set_Error_Posted (N, True); | |
5273 | return; | |
5274 | end if; | |
5275 | end loop; | |
5276 | ||
5277 | -- If entry not found, this is first undefined occurrence | |
5278 | ||
5279 | if Nvis then | |
5280 | Error_Msg_N ("& is not visible!", N); | |
5281 | Emsg := Get_Msg_Id; | |
5282 | ||
5283 | else | |
5284 | Error_Msg_N ("& is undefined!", N); | |
5285 | Emsg := Get_Msg_Id; | |
5286 | ||
5287 | -- A very bizarre special check, if the undefined identifier | |
5288 | -- is put or put_line, then add a special error message (since | |
5289 | -- this is a very common error for beginners to make). | |
5290 | ||
b69cd36a | 5291 | if Nam_In (Chars (N), Name_Put, Name_Put_Line) then |
ed2233dc | 5292 | Error_Msg_N -- CODEFIX |
16ca248a ES |
5293 | ("\\possible missing `WITH Ada.Text_'I'O; " & |
5294 | "USE Ada.Text_'I'O`!", N); | |
5295 | ||
5296 | -- Another special check if N is the prefix of a selected | |
5297 | -- component which is a known unit, add message complaining | |
fbe627af | 5298 | -- about missing with for this unit. |
16ca248a ES |
5299 | |
5300 | elsif Nkind (Parent (N)) = N_Selected_Component | |
5301 | and then N = Prefix (Parent (N)) | |
5302 | and then Is_Known_Unit (Parent (N)) | |
5303 | then | |
5304 | Error_Msg_Node_2 := Selector_Name (Parent (N)); | |
ed2233dc AC |
5305 | Error_Msg_N -- CODEFIX |
5306 | ("\\missing `WITH &.&;`", Prefix (Parent (N))); | |
996ae0b0 RK |
5307 | end if; |
5308 | ||
5309 | -- Now check for possible misspellings | |
5310 | ||
996ae0b0 RK |
5311 | declare |
5312 | E : Entity_Id; | |
5313 | Ematch : Entity_Id := Empty; | |
5314 | ||
5315 | Last_Name_Id : constant Name_Id := | |
5316 | Name_Id (Nat (First_Name_Id) + | |
5317 | Name_Entries_Count - 1); | |
5318 | ||
996ae0b0 | 5319 | begin |
294ccb21 RD |
5320 | for Nam in First_Name_Id .. Last_Name_Id loop |
5321 | E := Get_Name_Entity_Id (Nam); | |
996ae0b0 RK |
5322 | |
5323 | if Present (E) | |
5324 | and then (Is_Immediately_Visible (E) | |
5325 | or else | |
5326 | Is_Potentially_Use_Visible (E)) | |
5327 | then | |
294ccb21 | 5328 | if Is_Bad_Spelling_Of (Chars (N), Nam) then |
996ae0b0 RK |
5329 | Ematch := E; |
5330 | exit; | |
5331 | end if; | |
5332 | end if; | |
5333 | end loop; | |
5334 | ||
5335 | if Present (Ematch) then | |
deef4289 AC |
5336 | Error_Msg_NE -- CODEFIX |
5337 | ("\possible misspelling of&", N, Ematch); | |
996ae0b0 RK |
5338 | end if; |
5339 | end; | |
5340 | end if; | |
5341 | ||
16ca248a ES |
5342 | -- Make entry in undefined references table unless the full errors |
5343 | -- switch is set, in which case by refraining from generating the | |
5344 | -- table entry, we guarantee that we get an error message for every | |
683af98c AC |
5345 | -- undefined reference. The entry is not added if we are ignoring |
5346 | -- errors. | |
996ae0b0 | 5347 | |
683af98c | 5348 | if not All_Errors_Mode and then Ignore_Errors_Enable = 0 then |
11560bcc TQ |
5349 | Urefs.Append ( |
5350 | (Node => N, | |
5351 | Err => Emsg, | |
5352 | Nvis => Nvis, | |
5353 | Loc => Sloc (N))); | |
996ae0b0 RK |
5354 | end if; |
5355 | ||
5356 | Msg := True; | |
5357 | end Undefined; | |
5358 | ||
522aa6ee AC |
5359 | -- Local variables |
5360 | ||
5361 | Nested_Inst : Entity_Id := Empty; | |
5362 | -- The entity of a nested instance which appears within Inst (if any) | |
5363 | ||
996ae0b0 RK |
5364 | -- Start of processing for Find_Direct_Name |
5365 | ||
5366 | begin | |
5367 | -- If the entity pointer is already set, this is an internal node, or | |
5368 | -- a node that is analyzed more than once, after a tree modification. | |
5369 | -- In such a case there is no resolution to perform, just set the type. | |
5370 | ||
5371 | if Present (Entity (N)) then | |
5372 | if Is_Type (Entity (N)) then | |
5373 | Set_Etype (N, Entity (N)); | |
5374 | ||
5375 | else | |
5376 | declare | |
5377 | Entyp : constant Entity_Id := Etype (Entity (N)); | |
5378 | ||
5379 | begin | |
5380 | -- One special case here. If the Etype field is already set, | |
5381 | -- and references the packed array type corresponding to the | |
5382 | -- etype of the referenced entity, then leave it alone. This | |
5383 | -- happens for trees generated from Exp_Pakd, where expressions | |
5384 | -- can be deliberately "mis-typed" to the packed array type. | |
5385 | ||
5386 | if Is_Array_Type (Entyp) | |
5387 | and then Is_Packed (Entyp) | |
5388 | and then Present (Etype (N)) | |
8ca597af | 5389 | and then Etype (N) = Packed_Array_Impl_Type (Entyp) |
996ae0b0 RK |
5390 | then |
5391 | null; | |
5392 | ||
5393 | -- If not that special case, then just reset the Etype | |
5394 | ||
5395 | else | |
5396 | Set_Etype (N, Etype (Entity (N))); | |
5397 | end if; | |
5398 | end; | |
5399 | end if; | |
5400 | ||
851e9f19 PMR |
5401 | -- Although the marking of use clauses happens at the end of |
5402 | -- Find_Direct_Name, a certain case where a generic actual satisfies | |
5403 | -- a use clause must be checked here due to how the generic machinery | |
5404 | -- handles the analysis of said actuals. | |
5405 | ||
5406 | if In_Instance | |
5407 | and then Nkind (Parent (N)) = N_Generic_Association | |
5408 | then | |
5409 | Mark_Use_Clauses (Entity (N)); | |
5410 | end if; | |
5411 | ||
996ae0b0 RK |
5412 | return; |
5413 | end if; | |
5414 | ||
90e491a7 PMR |
5415 | -- Preserve relevant elaboration-related attributes of the context which |
5416 | -- are no longer available or very expensive to recompute once analysis, | |
5417 | -- resolution, and expansion are over. | |
5418 | ||
5419 | if Nkind (N) = N_Identifier then | |
5420 | Mark_Elaboration_Attributes | |
5421 | (N_Id => N, | |
5422 | Modes => True); | |
5423 | end if; | |
5424 | ||
996ae0b0 RK |
5425 | -- Here if Entity pointer was not set, we need full visibility analysis |
5426 | -- First we generate debugging output if the debug E flag is set. | |
5427 | ||
5428 | if Debug_Flag_E then | |
5429 | Write_Str ("Looking for "); | |
5430 | Write_Name (Chars (N)); | |
5431 | Write_Eol; | |
5432 | end if; | |
5433 | ||
5434 | Homonyms := Current_Entity (N); | |
5435 | Nvis_Entity := False; | |
5436 | ||
5437 | E := Homonyms; | |
5438 | while Present (E) loop | |
5439 | ||
ff81221b ES |
5440 | -- If entity is immediately visible or potentially use visible, then |
5441 | -- process the entity and we are done. | |
996ae0b0 RK |
5442 | |
5443 | if Is_Immediately_Visible (E) then | |
5444 | goto Immediately_Visible_Entity; | |
5445 | ||
5446 | elsif Is_Potentially_Use_Visible (E) then | |
5447 | goto Potentially_Use_Visible_Entity; | |
5448 | ||
5449 | -- Note if a known but invisible entity encountered | |
5450 | ||
5451 | elsif Known_But_Invisible (E) then | |
5452 | Nvis_Entity := True; | |
5453 | end if; | |
5454 | ||
5455 | -- Move to next entity in chain and continue search | |
5456 | ||
5457 | E := Homonym (E); | |
5458 | end loop; | |
5459 | ||
5460 | -- If no entries on homonym chain that were potentially visible, | |
5461 | -- and no entities reasonably considered as non-visible, then | |
5462 | -- we have a plain undefined reference, with no additional | |
a90bd866 | 5463 | -- explanation required. |
996ae0b0 RK |
5464 | |
5465 | if not Nvis_Entity then | |
5466 | Undefined (Nvis => False); | |
996ae0b0 RK |
5467 | |
5468 | -- Otherwise there is at least one entry on the homonym chain that | |
5469 | -- is reasonably considered as being known and non-visible. | |
5470 | ||
5471 | else | |
5472 | Nvis_Messages; | |
996ae0b0 RK |
5473 | end if; |
5474 | ||
18dae814 | 5475 | goto Done; |
fbf5a39b | 5476 | |
996ae0b0 RK |
5477 | -- Processing for a potentially use visible entry found. We must search |
5478 | -- the rest of the homonym chain for two reasons. First, if there is a | |
5479 | -- directly visible entry, then none of the potentially use-visible | |
5480 | -- entities are directly visible (RM 8.4(10)). Second, we need to check | |
5481 | -- for the case of multiple potentially use-visible entries hiding one | |
5482 | -- another and as a result being non-directly visible (RM 8.4(11)). | |
5483 | ||
5484 | <<Potentially_Use_Visible_Entity>> declare | |
5485 | Only_One_Visible : Boolean := True; | |
5486 | All_Overloadable : Boolean := Is_Overloadable (E); | |
5487 | ||
5488 | begin | |
5489 | E2 := Homonym (E); | |
996ae0b0 RK |
5490 | while Present (E2) loop |
5491 | if Is_Immediately_Visible (E2) then | |
5492 | ||
5493 | -- If the use-visible entity comes from the actual for a | |
5494 | -- formal package, it hides a directly visible entity from | |
5495 | -- outside the instance. | |
5496 | ||
5497 | if From_Actual_Package (E) | |
5498 | and then Scope_Depth (E2) < Scope_Depth (Inst) | |
5499 | then | |
5500 | goto Found; | |
5501 | else | |
5502 | E := E2; | |
5503 | goto Immediately_Visible_Entity; | |
5504 | end if; | |
5505 | ||
5506 | elsif Is_Potentially_Use_Visible (E2) then | |
5507 | Only_One_Visible := False; | |
5508 | All_Overloadable := All_Overloadable and Is_Overloadable (E2); | |
9bc856dd | 5509 | |
30783513 | 5510 | -- Ada 2005 (AI-262): Protect against a form of Beaujolais effect |
f3d57416 | 5511 | -- that can occur in private_with clauses. Example: |
9bc856dd AC |
5512 | |
5513 | -- with A; | |
5514 | -- private with B; package A is | |
5515 | -- package C is function B return Integer; | |
5516 | -- use A; end A; | |
5517 | -- V1 : Integer := B; | |
5518 | -- private function B return Integer; | |
5519 | -- V2 : Integer := B; | |
5520 | -- end C; | |
5521 | ||
bc41faa2 | 5522 | -- V1 resolves to A.B, but V2 resolves to library unit B |
9bc856dd AC |
5523 | |
5524 | elsif Ekind (E2) = E_Function | |
5525 | and then Scope (E2) = Standard_Standard | |
5526 | and then Has_Private_With (E2) | |
5527 | then | |
5528 | Only_One_Visible := False; | |
5529 | All_Overloadable := False; | |
5530 | Nvis_Is_Private_Subprg := True; | |
5531 | exit; | |
996ae0b0 RK |
5532 | end if; |
5533 | ||
5534 | E2 := Homonym (E2); | |
5535 | end loop; | |
5536 | ||
5537 | -- On falling through this loop, we have checked that there are no | |
5538 | -- immediately visible entities. Only_One_Visible is set if exactly | |
5539 | -- one potentially use visible entity exists. All_Overloadable is | |
5540 | -- set if all the potentially use visible entities are overloadable. | |
5541 | -- The condition for legality is that either there is one potentially | |
5542 | -- use visible entity, or if there is more than one, then all of them | |
5543 | -- are overloadable. | |
5544 | ||
5545 | if Only_One_Visible or All_Overloadable then | |
5546 | goto Found; | |
5547 | ||
5548 | -- If there is more than one potentially use-visible entity and at | |
4ff4293f | 5549 | -- least one of them non-overloadable, we have an error (RM 8.4(11)). |
996ae0b0 | 5550 | -- Note that E points to the first such entity on the homonym list. |
996ae0b0 RK |
5551 | |
5552 | else | |
522aa6ee AC |
5553 | -- If one of the entities is declared in an actual package, it |
5554 | -- was visible in the generic, and takes precedence over other | |
5555 | -- entities that are potentially use-visible. The same applies | |
5556 | -- if the entity is declared in a local instantiation of the | |
5557 | -- current instance. | |
5558 | ||
996ae0b0 | 5559 | if In_Instance then |
fbf5a39b | 5560 | |
522aa6ee | 5561 | -- Find the current instance |
fbf5a39b | 5562 | |
16ca248a | 5563 | Inst := Current_Scope; |
ac7d724d | 5564 | while Present (Inst) and then Inst /= Standard_Standard loop |
fbf5a39b AC |
5565 | if Is_Generic_Instance (Inst) then |
5566 | exit; | |
5567 | end if; | |
5568 | ||
5569 | Inst := Scope (Inst); | |
5570 | end loop; | |
5571 | ||
522aa6ee AC |
5572 | -- Reexamine the candidate entities, giving priority to those |
5573 | -- that were visible within the generic. | |
5574 | ||
996ae0b0 | 5575 | E2 := E; |
996ae0b0 | 5576 | while Present (E2) loop |
522aa6ee AC |
5577 | Nested_Inst := Nearest_Enclosing_Instance (E2); |
5578 | ||
5579 | -- The entity is declared within an actual package, or in a | |
5580 | -- nested instance. The ">=" accounts for the case where the | |
5581 | -- current instance and the nested instance are the same. | |
5582 | ||
fbf5a39b | 5583 | if From_Actual_Package (E2) |
522aa6ee AC |
5584 | or else (Present (Nested_Inst) |
5585 | and then Scope_Depth (Nested_Inst) >= | |
5586 | Scope_Depth (Inst)) | |
fbf5a39b | 5587 | then |
996ae0b0 RK |
5588 | E := E2; |
5589 | goto Found; | |
5590 | end if; | |
5591 | ||
5592 | E2 := Homonym (E2); | |
5593 | end loop; | |
5594 | ||
5595 | Nvis_Messages; | |
18dae814 | 5596 | goto Done; |
996ae0b0 | 5597 | |
8ab31c0c | 5598 | elsif Is_Predefined_Unit (Current_Sem_Unit) then |
851e9f19 | 5599 | -- A use clause in the body of a system file creates conflict |
4de287c4 ES |
5600 | -- with some entity in a user scope, while rtsfind is active. |
5601 | -- Keep only the entity coming from another predefined unit. | |
5eb10f25 ES |
5602 | |
5603 | E2 := E; | |
5604 | while Present (E2) loop | |
8ab31c0c | 5605 | if In_Predefined_Unit (E2) then |
5eb10f25 ES |
5606 | E := E2; |
5607 | goto Found; | |
5608 | end if; | |
5609 | ||
5610 | E2 := Homonym (E2); | |
5611 | end loop; | |
5612 | ||
4de287c4 | 5613 | -- Entity must exist because predefined unit is correct |
5eb10f25 ES |
5614 | |
5615 | raise Program_Error; | |
5616 | ||
996ae0b0 RK |
5617 | else |
5618 | Nvis_Messages; | |
18dae814 | 5619 | goto Done; |
996ae0b0 RK |
5620 | end if; |
5621 | end if; | |
5622 | end; | |
5623 | ||
5624 | -- Come here with E set to the first immediately visible entity on | |
5625 | -- the homonym chain. This is the one we want unless there is another | |
ff81221b ES |
5626 | -- immediately visible entity further on in the chain for an inner |
5627 | -- scope (RM 8.3(8)). | |
996ae0b0 RK |
5628 | |
5629 | <<Immediately_Visible_Entity>> declare | |
5630 | Level : Int; | |
5631 | Scop : Entity_Id; | |
5632 | ||
5633 | begin | |
ff81221b | 5634 | -- Find scope level of initial entity. When compiling through |
996ae0b0 RK |
5635 | -- Rtsfind, the previous context is not completely invisible, and |
5636 | -- an outer entity may appear on the chain, whose scope is below | |
5637 | -- the entry for Standard that delimits the current scope stack. | |
5638 | -- Indicate that the level for this spurious entry is outside of | |
5639 | -- the current scope stack. | |
5640 | ||
5641 | Level := Scope_Stack.Last; | |
5642 | loop | |
5643 | Scop := Scope_Stack.Table (Level).Entity; | |
5644 | exit when Scop = Scope (E); | |
5645 | Level := Level - 1; | |
5646 | exit when Scop = Standard_Standard; | |
5647 | end loop; | |
5648 | ||
5649 | -- Now search remainder of homonym chain for more inner entry | |
5650 | -- If the entity is Standard itself, it has no scope, and we | |
5651 | -- compare it with the stack entry directly. | |
5652 | ||
5653 | E2 := Homonym (E); | |
5654 | while Present (E2) loop | |
5655 | if Is_Immediately_Visible (E2) then | |
4de287c4 ES |
5656 | |
5657 | -- If a generic package contains a local declaration that | |
5658 | -- has the same name as the generic, there may be a visibility | |
5659 | -- conflict in an instance, where the local declaration must | |
5660 | -- also hide the name of the corresponding package renaming. | |
5661 | -- We check explicitly for a package declared by a renaming, | |
5662 | -- whose renamed entity is an instance that is on the scope | |
5663 | -- stack, and that contains a homonym in the same scope. Once | |
5664 | -- we have found it, we know that the package renaming is not | |
5665 | -- immediately visible, and that the identifier denotes the | |
5666 | -- other entity (and its homonyms if overloaded). | |
5667 | ||
5668 | if Scope (E) = Scope (E2) | |
5669 | and then Ekind (E) = E_Package | |
5670 | and then Present (Renamed_Object (E)) | |
5671 | and then Is_Generic_Instance (Renamed_Object (E)) | |
5672 | and then In_Open_Scopes (Renamed_Object (E)) | |
5673 | and then Comes_From_Source (N) | |
5674 | then | |
5675 | Set_Is_Immediately_Visible (E, False); | |
5676 | E := E2; | |
5677 | ||
5678 | else | |
5679 | for J in Level + 1 .. Scope_Stack.Last loop | |
5680 | if Scope_Stack.Table (J).Entity = Scope (E2) | |
5681 | or else Scope_Stack.Table (J).Entity = E2 | |
5682 | then | |
5683 | Level := J; | |
5684 | E := E2; | |
5685 | exit; | |
5686 | end if; | |
5687 | end loop; | |
5688 | end if; | |
996ae0b0 RK |
5689 | end if; |
5690 | ||
5691 | E2 := Homonym (E2); | |
5692 | end loop; | |
5693 | ||
5694 | -- At the end of that loop, E is the innermost immediately | |
5695 | -- visible entity, so we are all set. | |
5696 | end; | |
5697 | ||
5698 | -- Come here with entity found, and stored in E | |
5699 | ||
5700 | <<Found>> begin | |
5701 | ||
30196a76 RD |
5702 | -- Check violation of No_Wide_Characters restriction |
5703 | ||
5704 | Check_Wide_Character_Restriction (E, N); | |
5705 | ||
294ccb21 RD |
5706 | -- When distribution features are available (Get_PCS_Name /= |
5707 | -- Name_No_DSA), a remote access-to-subprogram type is converted | |
5708 | -- into a record type holding whatever information is needed to | |
f3d57416 | 5709 | -- perform a remote call on an RCI subprogram. In that case we |
294ccb21 RD |
5710 | -- rewrite any occurrence of the RAS type into the equivalent record |
5711 | -- type here. 'Access attribute references and RAS dereferences are | |
5712 | -- then implemented using specific TSSs. However when distribution is | |
5713 | -- not available (case of Get_PCS_Name = Name_No_DSA), we bypass the | |
5714 | -- generation of these TSSs, and we must keep the RAS type in its | |
5715 | -- original access-to-subprogram form (since all calls through a | |
5716 | -- value of such type will be local anyway in the absence of a PCS). | |
5717 | ||
996ae0b0 RK |
5718 | if Comes_From_Source (N) |
5719 | and then Is_Remote_Access_To_Subprogram_Type (E) | |
d1d81616 | 5720 | and then Ekind (E) = E_Access_Subprogram_Type |
996ae0b0 | 5721 | and then Expander_Active |
a77842bd | 5722 | and then Get_PCS_Name /= Name_No_DSA |
996ae0b0 | 5723 | then |
18dae814 RD |
5724 | Rewrite (N, New_Occurrence_Of (Equivalent_Type (E), Sloc (N))); |
5725 | goto Done; | |
996ae0b0 RK |
5726 | end if; |
5727 | ||
6989bc1f | 5728 | -- Set the entity. Note that the reason we call Set_Entity for the |
e7ba564f | 5729 | -- overloadable case, as opposed to Set_Entity_With_Checks is |
6989bc1f AC |
5730 | -- that in the overloaded case, the initial call can set the wrong |
5731 | -- homonym. The call that sets the right homonym is in Sem_Res and | |
e7ba564f | 5732 | -- that call does use Set_Entity_With_Checks, so we don't miss |
6989bc1f AC |
5733 | -- a style check. |
5734 | ||
5735 | if Is_Overloadable (E) then | |
5736 | Set_Entity (N, E); | |
5737 | else | |
e7ba564f | 5738 | Set_Entity_With_Checks (N, E); |
6989bc1f | 5739 | end if; |
996ae0b0 RK |
5740 | |
5741 | if Is_Type (E) then | |
5742 | Set_Etype (N, E); | |
5743 | else | |
5744 | Set_Etype (N, Get_Full_View (Etype (E))); | |
5745 | end if; | |
5746 | ||
5747 | if Debug_Flag_E then | |
5748 | Write_Str (" found "); | |
5749 | Write_Entity_Info (E, " "); | |
5750 | end if; | |
5751 | ||
5752 | -- If the Ekind of the entity is Void, it means that all homonyms | |
5753 | -- are hidden from all visibility (RM 8.3(5,14-20)). However, this | |
5754 | -- test is skipped if the current scope is a record and the name is | |
5755 | -- a pragma argument expression (case of Atomic and Volatile pragmas | |
5756 | -- and possibly other similar pragmas added later, which are allowed | |
5757 | -- to reference components in the current record). | |
5758 | ||
5759 | if Ekind (E) = E_Void | |
5760 | and then | |
5761 | (not Is_Record_Type (Current_Scope) | |
5762 | or else Nkind (Parent (N)) /= N_Pragma_Argument_Association) | |
5763 | then | |
5764 | Premature_Usage (N); | |
5765 | ||
16ca248a ES |
5766 | -- If the entity is overloadable, collect all interpretations of the |
5767 | -- name for subsequent overload resolution. We optimize a bit here to | |
5768 | -- do this only if we have an overloadable entity that is not on its | |
5769 | -- own on the homonym chain. | |
996ae0b0 RK |
5770 | |
5771 | elsif Is_Overloadable (E) | |
5772 | and then (Present (Homonym (E)) or else Current_Entity (N) /= E) | |
5773 | then | |
5774 | Collect_Interps (N); | |
5775 | ||
bc41faa2 | 5776 | -- If no homonyms were visible, the entity is unambiguous |
996ae0b0 RK |
5777 | |
5778 | if not Is_Overloaded (N) then | |
67ce0d7e RD |
5779 | if not Is_Actual_Parameter then |
5780 | Generate_Reference (E, N); | |
5781 | end if; | |
996ae0b0 RK |
5782 | end if; |
5783 | ||
5784 | -- Case of non-overloadable entity, set the entity providing that | |
5785 | -- we do not have the case of a discriminant reference within a | |
5786 | -- default expression. Such references are replaced with the | |
5787 | -- corresponding discriminal, which is the formal corresponding to | |
5788 | -- to the discriminant in the initialization procedure. | |
5789 | ||
996ae0b0 | 5790 | else |
294ccb21 RD |
5791 | -- Entity is unambiguous, indicate that it is referenced here |
5792 | ||
5793 | -- For a renaming of an object, always generate simple reference, | |
5114f3ff AC |
5794 | -- we don't try to keep track of assignments in this case, except |
5795 | -- in SPARK mode where renamings are traversed for generating | |
5796 | -- local effects of subprograms. | |
294ccb21 | 5797 | |
5114f3ff AC |
5798 | if Is_Object (E) |
5799 | and then Present (Renamed_Object (E)) | |
f5da7a97 | 5800 | and then not GNATprove_Mode |
5114f3ff | 5801 | then |
294ccb21 | 5802 | Generate_Reference (E, N); |
996ae0b0 | 5803 | |
21d27997 RD |
5804 | -- If the renamed entity is a private protected component, |
5805 | -- reference the original component as well. This needs to be | |
5806 | -- done because the private renamings are installed before any | |
f3d0f304 | 5807 | -- analysis has occurred. Reference to a private component will |
21d27997 RD |
5808 | -- resolve to the renaming and the original component will be |
5809 | -- left unreferenced, hence the following. | |
5810 | ||
5811 | if Is_Prival (E) then | |
5812 | Generate_Reference (Prival_Link (E), N); | |
5813 | end if; | |
5814 | ||
294ccb21 RD |
5815 | -- One odd case is that we do not want to set the Referenced flag |
5816 | -- if the entity is a label, and the identifier is the label in | |
5817 | -- the source, since this is not a reference from the point of | |
5818 | -- view of the user. | |
5819 | ||
5820 | elsif Nkind (Parent (N)) = N_Label then | |
996ae0b0 RK |
5821 | declare |
5822 | R : constant Boolean := Referenced (E); | |
294ccb21 | 5823 | |
996ae0b0 | 5824 | begin |
294ccb21 RD |
5825 | -- Generate reference unless this is an actual parameter |
5826 | -- (see comment below) | |
5827 | ||
5828 | if Is_Actual_Parameter then | |
67ce0d7e RD |
5829 | Generate_Reference (E, N); |
5830 | Set_Referenced (E, R); | |
5831 | end if; | |
996ae0b0 RK |
5832 | end; |
5833 | ||
11560bcc TQ |
5834 | -- Normal case, not a label: generate reference |
5835 | ||
a54ffd6c AC |
5836 | else |
5837 | if not Is_Actual_Parameter then | |
61c161b2 | 5838 | |
a54ffd6c | 5839 | -- Package or generic package is always a simple reference |
61c161b2 | 5840 | |
a54ffd6c AC |
5841 | if Ekind_In (E, E_Package, E_Generic_Package) then |
5842 | Generate_Reference (E, N, 'r'); | |
5843 | ||
5844 | -- Else see if we have a left hand side | |
fbf5a39b | 5845 | |
84df40f7 | 5846 | else |
a54ffd6c AC |
5847 | case Is_LHS (N) is |
5848 | when Yes => | |
5849 | Generate_Reference (E, N, 'm'); | |
5850 | ||
5851 | when No => | |
5852 | Generate_Reference (E, N, 'r'); | |
5853 | ||
5854 | -- If we don't know now, generate reference later | |
5855 | ||
d8f43ee6 HK |
5856 | when Unknown => |
5857 | Deferred_References.Append ((E, N)); | |
a54ffd6c | 5858 | end case; |
84df40f7 | 5859 | end if; |
67ce0d7e | 5860 | end if; |
996ae0b0 RK |
5861 | end if; |
5862 | ||
4c484f40 | 5863 | Set_Entity_Or_Discriminal (N, E); |
d50f4827 | 5864 | |
27dd0dde | 5865 | -- The name may designate a generalized reference, in which case |
f6f40114 AC |
5866 | -- the dereference interpretation will be included. Context is |
5867 | -- one in which a name is legal. | |
27dd0dde | 5868 | |
d50f4827 | 5869 | if Ada_Version >= Ada_2012 |
444acbdd AC |
5870 | and then |
5871 | (Nkind (Parent (N)) in N_Subexpr | |
cdabbb52 HK |
5872 | or else Nkind_In (Parent (N), N_Assignment_Statement, |
5873 | N_Object_Declaration, | |
5874 | N_Parameter_Association)) | |
d50f4827 AC |
5875 | then |
5876 | Check_Implicit_Dereference (N, Etype (E)); | |
5877 | end if; | |
996ae0b0 RK |
5878 | end if; |
5879 | end; | |
18dae814 | 5880 | |
851e9f19 PMR |
5881 | -- Mark relevant use-type and use-package clauses as effective if the |
5882 | -- node in question is not overloaded and therefore does not require | |
5883 | -- resolution. | |
5884 | -- | |
5885 | -- Note: Generic actual subprograms do not follow the normal resolution | |
5886 | -- path, so ignore the fact that they are overloaded and mark them | |
5887 | -- anyway. | |
5888 | ||
7f5e671b | 5889 | if Nkind (N) not in N_Subexpr or else not Is_Overloaded (N) then |
851e9f19 PMR |
5890 | Mark_Use_Clauses (N); |
5891 | end if; | |
5892 | ||
18dae814 RD |
5893 | -- Come here with entity set |
5894 | ||
5895 | <<Done>> | |
5896 | Check_Restriction_No_Use_Of_Entity (N); | |
90e491a7 PMR |
5897 | |
5898 | -- Save the scenario for later examination by the ABE Processing phase | |
5899 | ||
5900 | Record_Elaboration_Scenario (N); | |
996ae0b0 RK |
5901 | end Find_Direct_Name; |
5902 | ||
5903 | ------------------------ | |
5904 | -- Find_Expanded_Name -- | |
5905 | ------------------------ | |
5906 | ||
5907 | -- This routine searches the homonym chain of the entity until it finds | |
5908 | -- an entity declared in the scope denoted by the prefix. If the entity | |
5909 | -- is private, it may nevertheless be immediately visible, if we are in | |
5910 | -- the scope of its declaration. | |
5911 | ||
5912 | procedure Find_Expanded_Name (N : Node_Id) is | |
95fef24f AC |
5913 | function In_Abstract_View_Pragma (Nod : Node_Id) return Boolean; |
5914 | -- Determine whether expanded name Nod appears within a pragma which is | |
5915 | -- a suitable context for an abstract view of a state or variable. The | |
5916 | -- following pragmas fall in this category: | |
5917 | -- Depends | |
5918 | -- Global | |
5919 | -- Initializes | |
5920 | -- Refined_Depends | |
5921 | -- Refined_Global | |
5922 | -- | |
5923 | -- In addition, pragma Abstract_State is also considered suitable even | |
5924 | -- though it is an illegal context for an abstract view as this allows | |
5925 | -- for proper resolution of abstract views of variables. This illegal | |
5926 | -- context is later flagged in the analysis of indicator Part_Of. | |
dc726757 | 5927 | |
95fef24f AC |
5928 | ----------------------------- |
5929 | -- In_Abstract_View_Pragma -- | |
5930 | ----------------------------- | |
dc726757 | 5931 | |
95fef24f | 5932 | function In_Abstract_View_Pragma (Nod : Node_Id) return Boolean is |
dc726757 HK |
5933 | Par : Node_Id; |
5934 | ||
5935 | begin | |
5936 | -- Climb the parent chain looking for a pragma | |
5937 | ||
95fef24f | 5938 | Par := Nod; |
dc726757 | 5939 | while Present (Par) loop |
95fef24f | 5940 | if Nkind (Par) = N_Pragma then |
6e759c2a BD |
5941 | if Nam_In (Pragma_Name_Unmapped (Par), |
5942 | Name_Abstract_State, | |
5943 | Name_Depends, | |
5944 | Name_Global, | |
5945 | Name_Initializes, | |
5946 | Name_Refined_Depends, | |
5947 | Name_Refined_Global) | |
95fef24f AC |
5948 | then |
5949 | return True; | |
5950 | ||
5951 | -- Otherwise the pragma is not a legal context for an abstract | |
5952 | -- view. | |
5953 | ||
5954 | else | |
5955 | exit; | |
5956 | end if; | |
dc726757 HK |
5957 | |
5958 | -- Prevent the search from going too far | |
5959 | ||
5960 | elsif Is_Body_Or_Package_Declaration (Par) then | |
95fef24f | 5961 | exit; |
dc726757 HK |
5962 | end if; |
5963 | ||
5964 | Par := Parent (Par); | |
5965 | end loop; | |
5966 | ||
5967 | return False; | |
95fef24f | 5968 | end In_Abstract_View_Pragma; |
dc726757 HK |
5969 | |
5970 | -- Local variables | |
5971 | ||
07fc65c4 GB |
5972 | Selector : constant Node_Id := Selector_Name (N); |
5973 | Candidate : Entity_Id := Empty; | |
996ae0b0 | 5974 | P_Name : Entity_Id; |
996ae0b0 RK |
5975 | Id : Entity_Id; |
5976 | ||
dc726757 HK |
5977 | -- Start of processing for Find_Expanded_Name |
5978 | ||
996ae0b0 RK |
5979 | begin |
5980 | P_Name := Entity (Prefix (N)); | |
996ae0b0 | 5981 | |
ff81221b ES |
5982 | -- If the prefix is a renamed package, look for the entity in the |
5983 | -- original package. | |
996ae0b0 RK |
5984 | |
5985 | if Ekind (P_Name) = E_Package | |
5986 | and then Present (Renamed_Object (P_Name)) | |
5987 | then | |
5988 | P_Name := Renamed_Object (P_Name); | |
5989 | ||
5990 | -- Rewrite node with entity field pointing to renamed object | |
5991 | ||
5992 | Rewrite (Prefix (N), New_Copy (Prefix (N))); | |
5993 | Set_Entity (Prefix (N), P_Name); | |
5994 | ||
5995 | -- If the prefix is an object of a concurrent type, look for | |
5996 | -- the entity in the associated task or protected type. | |
5997 | ||
5998 | elsif Is_Concurrent_Type (Etype (P_Name)) then | |
5999 | P_Name := Etype (P_Name); | |
6000 | end if; | |
6001 | ||
6002 | Id := Current_Entity (Selector); | |
6003 | ||
923fa078 RD |
6004 | declare |
6005 | Is_New_Candidate : Boolean; | |
996ae0b0 | 6006 | |
923fa078 RD |
6007 | begin |
6008 | while Present (Id) loop | |
6009 | if Scope (Id) = P_Name then | |
6010 | Candidate := Id; | |
6011 | Is_New_Candidate := True; | |
6012 | ||
dc726757 | 6013 | -- Handle abstract views of states and variables. These are |
95fef24f AC |
6014 | -- acceptable candidates only when the reference to the view |
6015 | -- appears in certain pragmas. | |
dc726757 HK |
6016 | |
6017 | if Ekind (Id) = E_Abstract_State | |
6018 | and then From_Limited_With (Id) | |
6019 | and then Present (Non_Limited_View (Id)) | |
6020 | then | |
95fef24f | 6021 | if In_Abstract_View_Pragma (N) then |
dc726757 HK |
6022 | Candidate := Non_Limited_View (Id); |
6023 | Is_New_Candidate := True; | |
6024 | ||
95fef24f AC |
6025 | -- Hide the candidate because it is not used in a proper |
6026 | -- context. | |
dc726757 HK |
6027 | |
6028 | else | |
6029 | Candidate := Empty; | |
6030 | Is_New_Candidate := False; | |
6031 | end if; | |
6032 | end if; | |
6033 | ||
47346923 AC |
6034 | -- Ada 2005 (AI-217): Handle shadow entities associated with |
6035 | -- types declared in limited-withed nested packages. We don't need | |
6036 | -- to handle E_Incomplete_Subtype entities because the entities | |
6037 | -- in the limited view are always E_Incomplete_Type and | |
6038 | -- E_Class_Wide_Type entities (see Build_Limited_Views). | |
6039 | ||
6040 | -- Regarding the expression used to evaluate the scope, it | |
6041 | -- is important to note that the limited view also has shadow | |
6042 | -- entities associated nested packages. For this reason the | |
6043 | -- correct scope of the entity is the scope of the real entity. | |
11560bcc TQ |
6044 | -- The non-limited view may itself be incomplete, in which case |
6045 | -- get the full view if available. | |
923fa078 | 6046 | |
47346923 | 6047 | elsif Ekind_In (Id, E_Incomplete_Type, E_Class_Wide_Type) |
dc726757 | 6048 | and then From_Limited_With (Id) |
923fa078 RD |
6049 | and then Present (Non_Limited_View (Id)) |
6050 | and then Scope (Non_Limited_View (Id)) = P_Name | |
6051 | then | |
11560bcc | 6052 | Candidate := Get_Full_View (Non_Limited_View (Id)); |
923fa078 | 6053 | Is_New_Candidate := True; |
996ae0b0 | 6054 | |
780d73d7 AC |
6055 | -- An unusual case arises with a fully qualified name for an |
6056 | -- entity local to a generic child unit package, within an | |
6057 | -- instantiation of that package. The name of the unit now | |
6058 | -- denotes the renaming created within the instance. This is | |
6059 | -- only relevant in an instance body, see below. | |
6060 | ||
6061 | elsif Is_Generic_Instance (Scope (Id)) | |
6062 | and then In_Open_Scopes (Scope (Id)) | |
6063 | and then In_Instance_Body | |
6064 | and then Ekind (Scope (Id)) = E_Package | |
6065 | and then Ekind (Id) = E_Package | |
6066 | and then Renamed_Entity (Id) = Scope (Id) | |
0cb81445 | 6067 | and then Is_Immediately_Visible (P_Name) |
780d73d7 AC |
6068 | then |
6069 | Is_New_Candidate := True; | |
6070 | ||
996ae0b0 | 6071 | else |
923fa078 | 6072 | Is_New_Candidate := False; |
996ae0b0 | 6073 | end if; |
996ae0b0 | 6074 | |
923fa078 | 6075 | if Is_New_Candidate then |
ddbc55d8 AC |
6076 | |
6077 | -- If entity is a child unit, either it is a visible child of | |
6078 | -- the prefix, or we are in the body of a generic prefix, as | |
6079 | -- will happen when a child unit is instantiated in the body | |
6080 | -- of a generic parent. This is because the instance body does | |
6081 | -- not restore the full compilation context, given that all | |
6082 | -- non-local references have been captured. | |
6083 | ||
8ca1ee5d | 6084 | if Is_Child_Unit (Id) or else P_Name = Standard_Standard then |
ddbc55d8 AC |
6085 | exit when Is_Visible_Lib_Unit (Id) |
6086 | or else (Is_Child_Unit (Id) | |
6087 | and then In_Open_Scopes (Scope (Id)) | |
6088 | and then In_Instance_Body); | |
923fa078 | 6089 | else |
8398e82e | 6090 | exit when not Is_Hidden (Id); |
923fa078 | 6091 | end if; |
8398e82e AC |
6092 | |
6093 | exit when Is_Immediately_Visible (Id); | |
923fa078 RD |
6094 | end if; |
6095 | ||
6096 | Id := Homonym (Id); | |
6097 | end loop; | |
6098 | end; | |
996ae0b0 RK |
6099 | |
6100 | if No (Id) | |
ac7d724d | 6101 | and then Ekind_In (P_Name, E_Procedure, E_Function) |
996ae0b0 RK |
6102 | and then Is_Generic_Instance (P_Name) |
6103 | then | |
6104 | -- Expanded name denotes entity in (instance of) generic subprogram. | |
6105 | -- The entity may be in the subprogram instance, or may denote one of | |
6106 | -- the formals, which is declared in the enclosing wrapper package. | |
6107 | ||
6108 | P_Name := Scope (P_Name); | |
996ae0b0 | 6109 | |
bc41faa2 | 6110 | Id := Current_Entity (Selector); |
996ae0b0 | 6111 | while Present (Id) loop |
bc41faa2 | 6112 | exit when Scope (Id) = P_Name; |
996ae0b0 RK |
6113 | Id := Homonym (Id); |
6114 | end loop; | |
6115 | end if; | |
6116 | ||
bc41faa2 | 6117 | if No (Id) or else Chars (Id) /= Chars (Selector) then |
996ae0b0 RK |
6118 | Set_Etype (N, Any_Type); |
6119 | ||
ff81221b ES |
6120 | -- If we are looking for an entity defined in System, try to find it |
6121 | -- in the child package that may have been provided as an extension | |
6122 | -- to System. The Extend_System pragma will have supplied the name of | |
6123 | -- the extension, which may have to be loaded. | |
996ae0b0 RK |
6124 | |
6125 | if Chars (P_Name) = Name_System | |
6126 | and then Scope (P_Name) = Standard_Standard | |
fbf5a39b | 6127 | and then Present (System_Extend_Unit) |
996ae0b0 RK |
6128 | and then Present_System_Aux (N) |
6129 | then | |
6130 | Set_Entity (Prefix (N), System_Aux_Id); | |
6131 | Find_Expanded_Name (N); | |
6132 | return; | |
6133 | ||
95fef24f AC |
6134 | -- There is an implicit instance of the predefined operator in |
6135 | -- the given scope. The operator entity is defined in Standard. | |
6136 | -- Has_Implicit_Operator makes the node into an Expanded_Name. | |
6137 | ||
fbf5a39b AC |
6138 | elsif Nkind (Selector) = N_Operator_Symbol |
6139 | and then Has_Implicit_Operator (N) | |
996ae0b0 | 6140 | then |
996ae0b0 RK |
6141 | return; |
6142 | ||
95fef24f AC |
6143 | -- If there is no literal defined in the scope denoted by the |
6144 | -- prefix, the literal may belong to (a type derived from) | |
6145 | -- Standard_Character, for which we have no explicit literals. | |
6146 | ||
996ae0b0 RK |
6147 | elsif Nkind (Selector) = N_Character_Literal |
6148 | and then Has_Implicit_Character_Literal (N) | |
6149 | then | |
996ae0b0 RK |
6150 | return; |
6151 | ||
6152 | else | |
ff81221b ES |
6153 | -- If the prefix is a single concurrent object, use its name in |
6154 | -- the error message, rather than that of the anonymous type. | |
996ae0b0 RK |
6155 | |
6156 | if Is_Concurrent_Type (P_Name) | |
6157 | and then Is_Internal_Name (Chars (P_Name)) | |
6158 | then | |
6159 | Error_Msg_Node_2 := Entity (Prefix (N)); | |
6160 | else | |
6161 | Error_Msg_Node_2 := P_Name; | |
6162 | end if; | |
6163 | ||
6164 | if P_Name = System_Aux_Id then | |
6165 | P_Name := Scope (P_Name); | |
6166 | Set_Entity (Prefix (N), P_Name); | |
6167 | end if; | |
6168 | ||
6169 | if Present (Candidate) then | |
6170 | ||
16ca248a ES |
6171 | -- If we know that the unit is a child unit we can give a more |
6172 | -- accurate error message. | |
6173 | ||
996ae0b0 | 6174 | if Is_Child_Unit (Candidate) then |
edd63e9b | 6175 | |
16ca248a ES |
6176 | -- If the candidate is a private child unit and we are in |
6177 | -- the visible part of a public unit, specialize the error | |
6178 | -- message. There might be a private with_clause for it, | |
6179 | -- but it is not currently active. | |
edd63e9b ES |
6180 | |
6181 | if Is_Private_Descendant (Candidate) | |
6182 | and then Ekind (Current_Scope) = E_Package | |
6183 | and then not In_Private_Part (Current_Scope) | |
6184 | and then not Is_Private_Descendant (Current_Scope) | |
6185 | then | |
95fef24f AC |
6186 | Error_Msg_N |
6187 | ("private child unit& is not visible here", Selector); | |
16ca248a ES |
6188 | |
6189 | -- Normal case where we have a missing with for a child unit | |
6190 | ||
edd63e9b | 6191 | else |
16ca248a | 6192 | Error_Msg_Qual_Level := 99; |
ed2233dc AC |
6193 | Error_Msg_NE -- CODEFIX |
6194 | ("missing `WITH &;`", Selector, Candidate); | |
16ca248a | 6195 | Error_Msg_Qual_Level := 0; |
edd63e9b | 6196 | end if; |
16ca248a ES |
6197 | |
6198 | -- Here we don't know that this is a child unit | |
6199 | ||
996ae0b0 RK |
6200 | else |
6201 | Error_Msg_NE ("& is not a visible entity of&", N, Selector); | |
6202 | end if; | |
6203 | ||
6204 | else | |
6205 | -- Within the instantiation of a child unit, the prefix may | |
16ca248a | 6206 | -- denote the parent instance, but the selector has the name |
58747e48 AC |
6207 | -- of the original child. That is to say, when A.B appears |
6208 | -- within an instantiation of generic child unit B, the scope | |
6209 | -- stack includes an instance of A (P_Name) and an instance | |
6210 | -- of B under some other name. We scan the scope to find this | |
6211 | -- child instance, which is the desired entity. | |
6212 | -- Note that the parent may itself be a child instance, if | |
6213 | -- the reference is of the form A.B.C, in which case A.B has | |
6214 | -- already been rewritten with the proper entity. | |
6215 | ||
6216 | if In_Open_Scopes (P_Name) | |
996ae0b0 RK |
6217 | and then Is_Generic_Instance (P_Name) |
6218 | then | |
6219 | declare | |
58747e48 AC |
6220 | Gen_Par : constant Entity_Id := |
6221 | Generic_Parent (Specification | |
6222 | (Unit_Declaration_Node (P_Name))); | |
996ae0b0 RK |
6223 | S : Entity_Id := Current_Scope; |
6224 | P : Entity_Id; | |
6225 | ||
6226 | begin | |
6227 | for J in reverse 0 .. Scope_Stack.Last loop | |
6228 | S := Scope_Stack.Table (J).Entity; | |
6229 | ||
6230 | exit when S = Standard_Standard; | |
6231 | ||
bce79204 AC |
6232 | if Ekind_In (S, E_Function, |
6233 | E_Package, | |
6234 | E_Procedure) | |
996ae0b0 | 6235 | then |
95fef24f AC |
6236 | P := |
6237 | Generic_Parent (Specification | |
6238 | (Unit_Declaration_Node (S))); | |
996ae0b0 | 6239 | |
58747e48 AC |
6240 | -- Check that P is a generic child of the generic |
6241 | -- parent of the prefix. | |
6242 | ||
996ae0b0 | 6243 | if Present (P) |
996ae0b0 | 6244 | and then Chars (P) = Chars (Selector) |
58747e48 | 6245 | and then Scope (P) = Gen_Par |
996ae0b0 RK |
6246 | then |
6247 | Id := S; | |
a77842bd | 6248 | goto Found; |
996ae0b0 RK |
6249 | end if; |
6250 | end if; | |
6251 | ||
6252 | end loop; | |
6253 | end; | |
6254 | end if; | |
6255 | ||
16ca248a ES |
6256 | -- If this is a selection from Ada, System or Interfaces, then |
6257 | -- we assume a missing with for the corresponding package. | |
6258 | ||
6259 | if Is_Known_Unit (N) then | |
fbe627af RD |
6260 | if not Error_Posted (N) then |
6261 | Error_Msg_Node_2 := Selector; | |
ed2233dc AC |
6262 | Error_Msg_N -- CODEFIX |
6263 | ("missing `WITH &.&;`", Prefix (N)); | |
fbe627af | 6264 | end if; |
996ae0b0 | 6265 | |
16ca248a ES |
6266 | -- If this is a selection from a dummy package, then suppress |
6267 | -- the error message, of course the entity is missing if the | |
a90bd866 | 6268 | -- package is missing. |
996ae0b0 RK |
6269 | |
6270 | elsif Sloc (Error_Msg_Node_2) = No_Location then | |
6271 | null; | |
6272 | ||
6273 | -- Here we have the case of an undefined component | |
6274 | ||
6275 | else | |
d6a24cdb AC |
6276 | -- The prefix may hide a homonym in the context that |
6277 | -- declares the desired entity. This error can use a | |
6278 | -- specialized message. | |
6279 | ||
8398e82e | 6280 | if In_Open_Scopes (P_Name) then |
d6a24cdb AC |
6281 | declare |
6282 | H : constant Entity_Id := Homonym (P_Name); | |
0d354370 | 6283 | |
d6a24cdb | 6284 | begin |
8398e82e AC |
6285 | if Present (H) |
6286 | and then Is_Compilation_Unit (H) | |
6287 | and then | |
6288 | (Is_Immediately_Visible (H) | |
6289 | or else Is_Visible_Lib_Unit (H)) | |
6290 | then | |
6291 | Id := First_Entity (H); | |
6292 | while Present (Id) loop | |
6293 | if Chars (Id) = Chars (Selector) then | |
6294 | Error_Msg_Qual_Level := 99; | |
6295 | Error_Msg_Name_1 := Chars (Selector); | |
6296 | Error_Msg_NE | |
6297 | ("% not declared in&", N, P_Name); | |
6298 | Error_Msg_NE | |
6299 | ("\use fully qualified name starting with " | |
6300 | & "Standard to make& visible", N, H); | |
6301 | Error_Msg_Qual_Level := 0; | |
6302 | goto Done; | |
6303 | end if; | |
d6a24cdb | 6304 | |
8398e82e AC |
6305 | Next_Entity (Id); |
6306 | end loop; | |
6307 | end if; | |
689cb4ac | 6308 | |
690943fc | 6309 | -- If not found, standard error message |
689cb4ac AC |
6310 | |
6311 | Error_Msg_NE ("& not declared in&", N, Selector); | |
6312 | ||
6313 | <<Done>> null; | |
d6a24cdb AC |
6314 | end; |
6315 | ||
6316 | else | |
780d73d7 AC |
6317 | -- Might be worth specializing the case when the prefix |
6318 | -- is a limited view. | |
6319 | -- ... not declared in limited view of... | |
6320 | ||
d6a24cdb AC |
6321 | Error_Msg_NE ("& not declared in&", N, Selector); |
6322 | end if; | |
996ae0b0 | 6323 | |
bc41faa2 | 6324 | -- Check for misspelling of some entity in prefix |
996ae0b0 RK |
6325 | |
6326 | Id := First_Entity (P_Name); | |
294ccb21 RD |
6327 | while Present (Id) loop |
6328 | if Is_Bad_Spelling_Of (Chars (Id), Chars (Selector)) | |
6329 | and then not Is_Internal_Name (Chars (Id)) | |
6330 | then | |
deef4289 | 6331 | Error_Msg_NE -- CODEFIX |
294ccb21 RD |
6332 | ("possible misspelling of&", Selector, Id); |
6333 | exit; | |
6334 | end if; | |
996ae0b0 | 6335 | |
294ccb21 RD |
6336 | Next_Entity (Id); |
6337 | end loop; | |
996ae0b0 RK |
6338 | |
6339 | -- Specialize the message if this may be an instantiation | |
6340 | -- of a child unit that was not mentioned in the context. | |
6341 | ||
6342 | if Nkind (Parent (N)) = N_Package_Instantiation | |
6343 | and then Is_Generic_Instance (Entity (Prefix (N))) | |
6344 | and then Is_Compilation_Unit | |
294ccb21 | 6345 | (Generic_Parent (Parent (Entity (Prefix (N))))) |
996ae0b0 | 6346 | then |
16ca248a | 6347 | Error_Msg_Node_2 := Selector; |
ed2233dc AC |
6348 | Error_Msg_N -- CODEFIX |
6349 | ("\missing `WITH &.&;`", Prefix (N)); | |
996ae0b0 RK |
6350 | end if; |
6351 | end if; | |
6352 | end if; | |
6353 | ||
6354 | Id := Any_Id; | |
6355 | end if; | |
6356 | end if; | |
6357 | ||
a77842bd | 6358 | <<Found>> |
996ae0b0 RK |
6359 | if Comes_From_Source (N) |
6360 | and then Is_Remote_Access_To_Subprogram_Type (Id) | |
d1d81616 | 6361 | and then Ekind (Id) = E_Access_Subprogram_Type |
a77842bd | 6362 | and then Present (Equivalent_Type (Id)) |
996ae0b0 | 6363 | then |
16ca248a ES |
6364 | -- If we are not actually generating distribution code (i.e. the |
6365 | -- current PCS is the dummy non-distributed version), then the | |
6366 | -- Equivalent_Type will be missing, and Id should be treated as | |
6367 | -- a regular access-to-subprogram type. | |
a77842bd | 6368 | |
996ae0b0 RK |
6369 | Id := Equivalent_Type (Id); |
6370 | Set_Chars (Selector, Chars (Id)); | |
6371 | end if; | |
6372 | ||
0ab80019 | 6373 | -- Ada 2005 (AI-50217): Check usage of entities in limited withed units |
19f0526a | 6374 | |
7b56a91b AC |
6375 | if Ekind (P_Name) = E_Package and then From_Limited_With (P_Name) then |
6376 | if From_Limited_With (Id) | |
0fb2ea01 AC |
6377 | or else Is_Type (Id) |
6378 | or else Ekind (Id) = E_Package | |
996ae0b0 RK |
6379 | then |
6380 | null; | |
6381 | else | |
6382 | Error_Msg_N | |
497a660d AC |
6383 | ("limited withed package can only be used to access incomplete " |
6384 | & "types", N); | |
996ae0b0 RK |
6385 | end if; |
6386 | end if; | |
6387 | ||
6388 | if Is_Task_Type (P_Name) | |
6389 | and then ((Ekind (Id) = E_Entry | |
ac7d724d | 6390 | and then Nkind (Parent (N)) /= N_Attribute_Reference) |
294ccb21 | 6391 | or else |
ac7d724d ES |
6392 | (Ekind (Id) = E_Entry_Family |
6393 | and then | |
6394 | Nkind (Parent (Parent (N))) /= N_Attribute_Reference)) | |
996ae0b0 | 6395 | then |
a53c5613 AC |
6396 | -- If both the task type and the entry are in scope, this may still |
6397 | -- be the expanded name of an entry formal. | |
996ae0b0 | 6398 | |
a53c5613 AC |
6399 | if In_Open_Scopes (Id) |
6400 | and then Nkind (Parent (N)) = N_Selected_Component | |
6401 | then | |
6402 | null; | |
6403 | ||
6404 | else | |
6405 | -- It is an entry call after all, either to the current task | |
6406 | -- (which will deadlock) or to an enclosing task. | |
6407 | ||
6408 | Analyze_Selected_Component (N); | |
6409 | return; | |
6410 | end if; | |
996ae0b0 RK |
6411 | end if; |
6412 | ||
6413 | Change_Selected_Component_To_Expanded_Name (N); | |
07fc65c4 | 6414 | |
90e491a7 PMR |
6415 | -- Preserve relevant elaboration-related attributes of the context which |
6416 | -- are no longer available or very expensive to recompute once analysis, | |
6417 | -- resolution, and expansion are over. | |
6418 | ||
6419 | Mark_Elaboration_Attributes | |
6420 | (N_Id => N, | |
6421 | Modes => True); | |
6422 | ||
a54ffd6c AC |
6423 | -- Set appropriate type |
6424 | ||
6425 | if Is_Type (Id) then | |
6426 | Set_Etype (N, Id); | |
6427 | else | |
6428 | Set_Etype (N, Get_Full_View (Etype (Id))); | |
6429 | end if; | |
6430 | ||
07fc65c4 | 6431 | -- Do style check and generate reference, but skip both steps if this |
16ca248a ES |
6432 | -- entity has homonyms, since we may not have the right homonym set yet. |
6433 | -- The proper homonym will be set during the resolve phase. | |
07fc65c4 GB |
6434 | |
6435 | if Has_Homonym (Id) then | |
6436 | Set_Entity (N, Id); | |
a54ffd6c | 6437 | |
07fc65c4 | 6438 | else |
4c484f40 | 6439 | Set_Entity_Or_Discriminal (N, Id); |
84df40f7 | 6440 | |
a54ffd6c AC |
6441 | case Is_LHS (N) is |
6442 | when Yes => | |
6443 | Generate_Reference (Id, N, 'm'); | |
d8f43ee6 | 6444 | |
a54ffd6c AC |
6445 | when No => |
6446 | Generate_Reference (Id, N, 'r'); | |
d8f43ee6 | 6447 | |
a54ffd6c AC |
6448 | when Unknown => |
6449 | Deferred_References.Append ((Id, N)); | |
6450 | end case; | |
996ae0b0 RK |
6451 | end if; |
6452 | ||
30196a76 RD |
6453 | -- Check for violation of No_Wide_Characters |
6454 | ||
6455 | Check_Wide_Character_Restriction (Id, N); | |
6456 | ||
16ca248a ES |
6457 | -- If the Ekind of the entity is Void, it means that all homonyms are |
6458 | -- hidden from all visibility (RM 8.3(5,14-20)). | |
996ae0b0 RK |
6459 | |
6460 | if Ekind (Id) = E_Void then | |
6461 | Premature_Usage (N); | |
6462 | ||
ac7d724d | 6463 | elsif Is_Overloadable (Id) and then Present (Homonym (Id)) then |
996ae0b0 RK |
6464 | declare |
6465 | H : Entity_Id := Homonym (Id); | |
6466 | ||
6467 | begin | |
6468 | while Present (H) loop | |
35ae2ed8 | 6469 | if Scope (H) = Scope (Id) |
ac7d724d ES |
6470 | and then (not Is_Hidden (H) |
6471 | or else Is_Immediately_Visible (H)) | |
35ae2ed8 | 6472 | then |
996ae0b0 RK |
6473 | Collect_Interps (N); |
6474 | exit; | |
6475 | end if; | |
6476 | ||
6477 | H := Homonym (H); | |
6478 | end loop; | |
fbf5a39b | 6479 | |
16ca248a ES |
6480 | -- If an extension of System is present, collect possible explicit |
6481 | -- overloadings declared in the extension. | |
fbf5a39b AC |
6482 | |
6483 | if Chars (P_Name) = Name_System | |
6484 | and then Scope (P_Name) = Standard_Standard | |
6485 | and then Present (System_Extend_Unit) | |
6486 | and then Present_System_Aux (N) | |
6487 | then | |
6488 | H := Current_Entity (Id); | |
6489 | ||
6490 | while Present (H) loop | |
6491 | if Scope (H) = System_Aux_Id then | |
6492 | Add_One_Interp (N, H, Etype (H)); | |
6493 | end if; | |
6494 | ||
6495 | H := Homonym (H); | |
6496 | end loop; | |
6497 | end if; | |
996ae0b0 RK |
6498 | end; |
6499 | end if; | |
6500 | ||
6501 | if Nkind (Selector_Name (N)) = N_Operator_Symbol | |
6502 | and then Scope (Id) /= Standard_Standard | |
6503 | then | |
16ca248a ES |
6504 | -- In addition to user-defined operators in the given scope, there |
6505 | -- may be an implicit instance of the predefined operator. The | |
6506 | -- operator (defined in Standard) is found in Has_Implicit_Operator, | |
6507 | -- and added to the interpretations. Procedure Add_One_Interp will | |
6508 | -- determine which hides which. | |
996ae0b0 RK |
6509 | |
6510 | if Has_Implicit_Operator (N) then | |
6511 | null; | |
6512 | end if; | |
6513 | end if; | |
be4c5193 AC |
6514 | |
6515 | -- If there is a single interpretation for N we can generate a | |
6516 | -- reference to the unique entity found. | |
6517 | ||
6518 | if Is_Overloadable (Id) and then not Is_Overloaded (N) then | |
6519 | Generate_Reference (Id, N); | |
6520 | end if; | |
fb757f7d | 6521 | |
851e9f19 PMR |
6522 | -- Mark relevant use-type and use-package clauses as effective if the |
6523 | -- node in question is not overloaded and therefore does not require | |
6524 | -- resolution. | |
6525 | ||
6526 | if Nkind (N) not in N_Subexpr or else not Is_Overloaded (N) then | |
6527 | Mark_Use_Clauses (N); | |
6528 | end if; | |
6529 | ||
fb757f7d | 6530 | Check_Restriction_No_Use_Of_Entity (N); |
90e491a7 PMR |
6531 | |
6532 | -- Save the scenario for later examination by the ABE Processing phase | |
6533 | ||
6534 | Record_Elaboration_Scenario (N); | |
996ae0b0 RK |
6535 | end Find_Expanded_Name; |
6536 | ||
851e9f19 PMR |
6537 | -------------------- |
6538 | -- Find_Most_Prev -- | |
6539 | -------------------- | |
6540 | ||
6541 | function Find_Most_Prev (Use_Clause : Node_Id) return Node_Id is | |
6542 | Curr : Node_Id; | |
7f5e671b | 6543 | |
851e9f19 PMR |
6544 | begin |
6545 | -- Loop through the Prev_Use_Clause chain | |
6546 | ||
6547 | Curr := Use_Clause; | |
6548 | while Present (Prev_Use_Clause (Curr)) loop | |
6549 | Curr := Prev_Use_Clause (Curr); | |
6550 | end loop; | |
6551 | ||
6552 | return Curr; | |
6553 | end Find_Most_Prev; | |
6554 | ||
996ae0b0 RK |
6555 | ------------------------- |
6556 | -- Find_Renamed_Entity -- | |
6557 | ------------------------- | |
6558 | ||
6559 | function Find_Renamed_Entity | |
6560 | (N : Node_Id; | |
6561 | Nam : Node_Id; | |
6562 | New_S : Entity_Id; | |
6563 | Is_Actual : Boolean := False) return Entity_Id | |
6564 | is | |
fbf5a39b | 6565 | Ind : Interp_Index; |
996ae0b0 RK |
6566 | I1 : Interp_Index := 0; -- Suppress junk warnings |
6567 | It : Interp; | |
6568 | It1 : Interp; | |
6569 | Old_S : Entity_Id; | |
6570 | Inst : Entity_Id; | |
6571 | ||
996ae0b0 RK |
6572 | function Is_Visible_Operation (Op : Entity_Id) return Boolean; |
6573 | -- If the renamed entity is an implicit operator, check whether it is | |
16ca248a ES |
6574 | -- visible because its operand type is properly visible. This check |
6575 | -- applies to explicit renamed entities that appear in the source in a | |
6576 | -- renaming declaration or a formal subprogram instance, but not to | |
6577 | -- default generic actuals with a name. | |
996ae0b0 | 6578 | |
923fa078 RD |
6579 | function Report_Overload return Entity_Id; |
6580 | -- List possible interpretations, and specialize message in the | |
6581 | -- case of a generic actual. | |
6582 | ||
6583 | function Within (Inner, Outer : Entity_Id) return Boolean; | |
16ca248a ES |
6584 | -- Determine whether a candidate subprogram is defined within the |
6585 | -- enclosing instance. If yes, it has precedence over outer candidates. | |
923fa078 | 6586 | |
996ae0b0 RK |
6587 | -------------------------- |
6588 | -- Is_Visible_Operation -- | |
6589 | -------------------------- | |
6590 | ||
6591 | function Is_Visible_Operation (Op : Entity_Id) return Boolean is | |
6592 | Scop : Entity_Id; | |
6593 | Typ : Entity_Id; | |
6594 | Btyp : Entity_Id; | |
6595 | ||
6596 | begin | |
6597 | if Ekind (Op) /= E_Operator | |
6598 | or else Scope (Op) /= Standard_Standard | |
6599 | or else (In_Instance | |
ac7d724d ES |
6600 | and then (not Is_Actual |
6601 | or else Present (Enclosing_Instance))) | |
996ae0b0 RK |
6602 | then |
6603 | return True; | |
6604 | ||
6605 | else | |
6606 | -- For a fixed point type operator, check the resulting type, | |
6607 | -- because it may be a mixed mode integer * fixed operation. | |
6608 | ||
6609 | if Present (Next_Formal (First_Formal (New_S))) | |
6610 | and then Is_Fixed_Point_Type (Etype (New_S)) | |
6611 | then | |
6612 | Typ := Etype (New_S); | |
6613 | else | |
6614 | Typ := Etype (First_Formal (New_S)); | |
6615 | end if; | |
6616 | ||
6617 | Btyp := Base_Type (Typ); | |
6618 | ||
6619 | if Nkind (Nam) /= N_Expanded_Name then | |
6620 | return (In_Open_Scopes (Scope (Btyp)) | |
6621 | or else Is_Potentially_Use_Visible (Btyp) | |
6622 | or else In_Use (Btyp) | |
6623 | or else In_Use (Scope (Btyp))); | |
6624 | ||
6625 | else | |
6626 | Scop := Entity (Prefix (Nam)); | |
6627 | ||
6628 | if Ekind (Scop) = E_Package | |
6629 | and then Present (Renamed_Object (Scop)) | |
6630 | then | |
6631 | Scop := Renamed_Object (Scop); | |
6632 | end if; | |
6633 | ||
6634 | -- Operator is visible if prefix of expanded name denotes | |
16b05213 | 6635 | -- scope of type, or else type is defined in System_Aux |
996ae0b0 RK |
6636 | -- and the prefix denotes System. |
6637 | ||
6638 | return Scope (Btyp) = Scop | |
6639 | or else (Scope (Btyp) = System_Aux_Id | |
6640 | and then Scope (Scope (Btyp)) = Scop); | |
6641 | end if; | |
6642 | end if; | |
6643 | end Is_Visible_Operation; | |
6644 | ||
6645 | ------------ | |
6646 | -- Within -- | |
6647 | ------------ | |
6648 | ||
6649 | function Within (Inner, Outer : Entity_Id) return Boolean is | |
16ca248a | 6650 | Sc : Entity_Id; |
996ae0b0 RK |
6651 | |
6652 | begin | |
16ca248a | 6653 | Sc := Scope (Inner); |
996ae0b0 | 6654 | while Sc /= Standard_Standard loop |
996ae0b0 RK |
6655 | if Sc = Outer then |
6656 | return True; | |
6657 | else | |
6658 | Sc := Scope (Sc); | |
6659 | end if; | |
6660 | end loop; | |
6661 | ||
6662 | return False; | |
6663 | end Within; | |
6664 | ||
923fa078 RD |
6665 | --------------------- |
6666 | -- Report_Overload -- | |
6667 | --------------------- | |
fbf5a39b AC |
6668 | |
6669 | function Report_Overload return Entity_Id is | |
6670 | begin | |
6671 | if Is_Actual then | |
ed2233dc | 6672 | Error_Msg_NE -- CODEFIX |
fbf5a39b | 6673 | ("ambiguous actual subprogram&, " & |
923fa078 | 6674 | "possible interpretations:", N, Nam); |
fbf5a39b | 6675 | else |
ed2233dc | 6676 | Error_Msg_N -- CODEFIX |
fbf5a39b | 6677 | ("ambiguous subprogram, " & |
923fa078 | 6678 | "possible interpretations:", N); |
fbf5a39b AC |
6679 | end if; |
6680 | ||
6681 | List_Interps (Nam, N); | |
6682 | return Old_S; | |
6683 | end Report_Overload; | |
6684 | ||
0187b60e | 6685 | -- Start of processing for Find_Renamed_Entity |
996ae0b0 RK |
6686 | |
6687 | begin | |
6688 | Old_S := Any_Id; | |
6689 | Candidate_Renaming := Empty; | |
6690 | ||
fc193526 | 6691 | if Is_Overloaded (Nam) then |
fbf5a39b | 6692 | Get_First_Interp (Nam, Ind, It); |
996ae0b0 | 6693 | while Present (It.Nam) loop |
996ae0b0 | 6694 | if Entity_Matches_Spec (It.Nam, New_S) |
fc193526 | 6695 | and then Is_Visible_Operation (It.Nam) |
996ae0b0 RK |
6696 | then |
6697 | if Old_S /= Any_Id then | |
6698 | ||
6699 | -- Note: The call to Disambiguate only happens if a | |
6700 | -- previous interpretation was found, in which case I1 | |
6701 | -- has received a value. | |
6702 | ||
fbf5a39b | 6703 | It1 := Disambiguate (Nam, I1, Ind, Etype (Old_S)); |
996ae0b0 RK |
6704 | |
6705 | if It1 = No_Interp then | |
996ae0b0 RK |
6706 | Inst := Enclosing_Instance; |
6707 | ||
6708 | if Present (Inst) then | |
996ae0b0 | 6709 | if Within (It.Nam, Inst) then |
444acbdd AC |
6710 | if Within (Old_S, Inst) then |
6711 | ||
6712 | -- Choose the innermost subprogram, which would | |
6713 | -- have hidden the outer one in the generic. | |
6714 | ||
6715 | if Scope_Depth (It.Nam) < | |
6716 | Scope_Depth (Old_S) | |
6717 | then | |
6718 | return Old_S; | |
444acbdd AC |
6719 | else |
6720 | return It.Nam; | |
6721 | end if; | |
6722 | end if; | |
6723 | ||
996ae0b0 RK |
6724 | elsif Within (Old_S, Inst) then |
6725 | return (Old_S); | |
444acbdd | 6726 | |
996ae0b0 | 6727 | else |
fbf5a39b | 6728 | return Report_Overload; |
996ae0b0 RK |
6729 | end if; |
6730 | ||
3ddd922e | 6731 | -- If not within an instance, ambiguity is real |
444acbdd | 6732 | |
996ae0b0 | 6733 | else |
fbf5a39b | 6734 | return Report_Overload; |
996ae0b0 RK |
6735 | end if; |
6736 | ||
6737 | else | |
6738 | Old_S := It1.Nam; | |
6739 | exit; | |
6740 | end if; | |
6741 | ||
6742 | else | |
fbf5a39b | 6743 | I1 := Ind; |
996ae0b0 RK |
6744 | Old_S := It.Nam; |
6745 | end if; | |
6746 | ||
6747 | elsif | |
6748 | Present (First_Formal (It.Nam)) | |
6749 | and then Present (First_Formal (New_S)) | |
ac7d724d ES |
6750 | and then (Base_Type (Etype (First_Formal (It.Nam))) = |
6751 | Base_Type (Etype (First_Formal (New_S)))) | |
996ae0b0 RK |
6752 | then |
6753 | Candidate_Renaming := It.Nam; | |
6754 | end if; | |
6755 | ||
fbf5a39b | 6756 | Get_Next_Interp (Ind, It); |
996ae0b0 RK |
6757 | end loop; |
6758 | ||
6759 | Set_Entity (Nam, Old_S); | |
1138cf59 AC |
6760 | |
6761 | if Old_S /= Any_Id then | |
6762 | Set_Is_Overloaded (Nam, False); | |
6763 | end if; | |
fc193526 HK |
6764 | |
6765 | -- Non-overloaded case | |
6766 | ||
6767 | else | |
60aa5228 AC |
6768 | if Is_Actual |
6769 | and then Present (Enclosing_Instance) | |
6770 | and then Entity_Matches_Spec (Entity (Nam), New_S) | |
6771 | then | |
fc193526 HK |
6772 | Old_S := Entity (Nam); |
6773 | ||
6774 | elsif Entity_Matches_Spec (Entity (Nam), New_S) then | |
6775 | Candidate_Renaming := New_S; | |
6776 | ||
6777 | if Is_Visible_Operation (Entity (Nam)) then | |
6778 | Old_S := Entity (Nam); | |
6779 | end if; | |
6780 | ||
6781 | elsif Present (First_Formal (Entity (Nam))) | |
6782 | and then Present (First_Formal (New_S)) | |
6783 | and then (Base_Type (Etype (First_Formal (Entity (Nam)))) = | |
6784 | Base_Type (Etype (First_Formal (New_S)))) | |
6785 | then | |
6786 | Candidate_Renaming := Entity (Nam); | |
6787 | end if; | |
996ae0b0 RK |
6788 | end if; |
6789 | ||
6790 | return Old_S; | |
6791 | end Find_Renamed_Entity; | |
6792 | ||
6793 | ----------------------------- | |
6794 | -- Find_Selected_Component -- | |
6795 | ----------------------------- | |
6796 | ||
6797 | procedure Find_Selected_Component (N : Node_Id) is | |
fbf5a39b | 6798 | P : constant Node_Id := Prefix (N); |
996ae0b0 RK |
6799 | |
6800 | P_Name : Entity_Id; | |
6801 | -- Entity denoted by prefix | |
6802 | ||
6803 | P_Type : Entity_Id; | |
6804 | -- and its type | |
6805 | ||
6806 | Nam : Node_Id; | |
6807 | ||
95e00a3a ES |
6808 | function Available_Subtype return Boolean; |
6809 | -- A small optimization: if the prefix is constrained and the component | |
6810 | -- is an array type we may already have a usable subtype for it, so we | |
6811 | -- can use it rather than generating a new one, because the bounds | |
6812 | -- will be the values of the discriminants and not discriminant refs. | |
c9d70ab1 AC |
6813 | -- This simplifies value tracing in GNATProve. For consistency, both |
6814 | -- the entity name and the subtype come from the constrained component. | |
95e00a3a | 6815 | |
c0dd5b38 AC |
6816 | -- This is only used in GNATProve mode: when generating code it may be |
6817 | -- necessary to create an itype in the scope of use of the selected | |
6818 | -- component, e.g. in the context of a expanded record equality. | |
6819 | ||
2e70d415 AC |
6820 | function Is_Reference_In_Subunit return Boolean; |
6821 | -- In a subunit, the scope depth is not a proper measure of hiding, | |
6822 | -- because the context of the proper body may itself hide entities in | |
6823 | -- parent units. This rare case requires inspecting the tree directly | |
6824 | -- because the proper body is inserted in the main unit and its context | |
6825 | -- is simply added to that of the parent. | |
6826 | ||
95e00a3a ES |
6827 | ----------------------- |
6828 | -- Available_Subtype -- | |
6829 | ----------------------- | |
6830 | ||
6831 | function Available_Subtype return Boolean is | |
6832 | Comp : Entity_Id; | |
c9d70ab1 | 6833 | |
95e00a3a | 6834 | begin |
c0dd5b38 AC |
6835 | if GNATprove_Mode then |
6836 | Comp := First_Entity (Etype (P)); | |
6837 | while Present (Comp) loop | |
6838 | if Chars (Comp) = Chars (Selector_Name (N)) then | |
6839 | Set_Etype (N, Etype (Comp)); | |
6840 | Set_Entity (Selector_Name (N), Comp); | |
6841 | Set_Etype (Selector_Name (N), Etype (Comp)); | |
6842 | return True; | |
6843 | end if; | |
95e00a3a | 6844 | |
c0dd5b38 AC |
6845 | Next_Component (Comp); |
6846 | end loop; | |
6847 | end if; | |
95e00a3a ES |
6848 | |
6849 | return False; | |
6850 | end Available_Subtype; | |
6851 | ||
2e70d415 AC |
6852 | ----------------------------- |
6853 | -- Is_Reference_In_Subunit -- | |
6854 | ----------------------------- | |
6855 | ||
6856 | function Is_Reference_In_Subunit return Boolean is | |
6857 | Clause : Node_Id; | |
6858 | Comp_Unit : Node_Id; | |
6859 | ||
6860 | begin | |
6861 | Comp_Unit := N; | |
6862 | while Present (Comp_Unit) | |
f5f6d8d7 | 6863 | and then Nkind (Comp_Unit) /= N_Compilation_Unit |
2e70d415 AC |
6864 | loop |
6865 | Comp_Unit := Parent (Comp_Unit); | |
6866 | end loop; | |
6867 | ||
f5f6d8d7 | 6868 | if No (Comp_Unit) or else Nkind (Unit (Comp_Unit)) /= N_Subunit then |
2e70d415 AC |
6869 | return False; |
6870 | end if; | |
6871 | ||
6872 | -- Now check whether the package is in the context of the subunit | |
6873 | ||
6874 | Clause := First (Context_Items (Comp_Unit)); | |
2e70d415 AC |
6875 | while Present (Clause) loop |
6876 | if Nkind (Clause) = N_With_Clause | |
6877 | and then Entity (Name (Clause)) = P_Name | |
6878 | then | |
6879 | return True; | |
6880 | end if; | |
6881 | ||
6882 | Clause := Next (Clause); | |
6883 | end loop; | |
6884 | ||
6885 | return False; | |
6886 | end Is_Reference_In_Subunit; | |
6887 | ||
f5f6d8d7 AC |
6888 | -- Start of processing for Find_Selected_Component |
6889 | ||
996ae0b0 RK |
6890 | begin |
6891 | Analyze (P); | |
6892 | ||
6893 | if Nkind (P) = N_Error then | |
6894 | return; | |
23685ae6 AC |
6895 | end if; |
6896 | ||
6897 | -- Selector name cannot be a character literal or an operator symbol in | |
db72f10a | 6898 | -- SPARK, except for the operator symbol in a renaming. |
23685ae6 | 6899 | |
6480338a | 6900 | if Restriction_Check_Required (SPARK_05) then |
23685ae6 | 6901 | if Nkind (Selector_Name (N)) = N_Character_Literal then |
ce5ba43a | 6902 | Check_SPARK_05_Restriction |
23685ae6 | 6903 | ("character literal cannot be prefixed", N); |
db72f10a AC |
6904 | elsif Nkind (Selector_Name (N)) = N_Operator_Symbol |
6905 | and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration | |
6906 | then | |
ce5ba43a AC |
6907 | Check_SPARK_05_Restriction |
6908 | ("operator symbol cannot be prefixed", N); | |
23685ae6 AC |
6909 | end if; |
6910 | end if; | |
996ae0b0 | 6911 | |
16ca248a ES |
6912 | -- If the selector already has an entity, the node has been constructed |
6913 | -- in the course of expansion, and is known to be valid. Do not verify | |
6914 | -- that it is defined for the type (it may be a private component used | |
6915 | -- in the expansion of record equality). | |
996ae0b0 | 6916 | |
23685ae6 | 6917 | if Present (Entity (Selector_Name (N))) then |
f5f6d8d7 | 6918 | if No (Etype (N)) or else Etype (N) = Any_Type then |
996ae0b0 | 6919 | declare |
fbf5a39b AC |
6920 | Sel_Name : constant Node_Id := Selector_Name (N); |
6921 | Selector : constant Entity_Id := Entity (Sel_Name); | |
996ae0b0 RK |
6922 | C_Etype : Node_Id; |
6923 | ||
6924 | begin | |
6925 | Set_Etype (Sel_Name, Etype (Selector)); | |
6926 | ||
6927 | if not Is_Entity_Name (P) then | |
fbf5a39b | 6928 | Resolve (P); |
996ae0b0 RK |
6929 | end if; |
6930 | ||
6931 | -- Build an actual subtype except for the first parameter | |
fbf5a39b | 6932 | -- of an init proc, where this actual subtype is by |
996ae0b0 RK |
6933 | -- definition incorrect, since the object is uninitialized |
6934 | -- (and does not even have defined discriminants etc.) | |
6935 | ||
6936 | if Is_Entity_Name (P) | |
6937 | and then Ekind (Entity (P)) = E_Function | |
6938 | then | |
6939 | Nam := New_Copy (P); | |
6940 | ||
6941 | if Is_Overloaded (P) then | |
6942 | Save_Interps (P, Nam); | |
6943 | end if; | |
6944 | ||
f5f6d8d7 | 6945 | Rewrite (P, Make_Function_Call (Sloc (P), Name => Nam)); |
996ae0b0 RK |
6946 | Analyze_Call (P); |
6947 | Analyze_Selected_Component (N); | |
6948 | return; | |
6949 | ||
6950 | elsif Ekind (Selector) = E_Component | |
6951 | and then (not Is_Entity_Name (P) | |
6952 | or else Chars (Entity (P)) /= Name_uInit) | |
6953 | then | |
5a271a7f RD |
6954 | -- Check if we already have an available subtype we can use |
6955 | ||
e0c23ac7 | 6956 | if Ekind (Etype (P)) = E_Record_Subtype |
95e00a3a ES |
6957 | and then Nkind (Parent (Etype (P))) = N_Subtype_Declaration |
6958 | and then Is_Array_Type (Etype (Selector)) | |
6959 | and then not Is_Packed (Etype (Selector)) | |
6960 | and then Available_Subtype | |
6961 | then | |
6962 | return; | |
6963 | ||
9fc2854d AC |
6964 | -- Do not build the subtype when referencing components of |
6965 | -- dispatch table wrappers. Required to avoid generating | |
535a8637 | 6966 | -- elaboration code with HI runtimes. |
9fc2854d | 6967 | |
535a8637 | 6968 | elsif RTU_Loaded (Ada_Tags) |
df3e68b1 HK |
6969 | and then |
6970 | ((RTE_Available (RE_Dispatch_Table_Wrapper) | |
2c1b72d7 | 6971 | and then Scope (Selector) = |
df3e68b1 | 6972 | RTE (RE_Dispatch_Table_Wrapper)) |
f5f6d8d7 AC |
6973 | or else |
6974 | (RTE_Available (RE_No_Dispatch_Table_Wrapper) | |
6975 | and then Scope (Selector) = | |
6976 | RTE (RE_No_Dispatch_Table_Wrapper))) | |
9fc2854d AC |
6977 | then |
6978 | C_Etype := Empty; | |
9fc2854d AC |
6979 | else |
6980 | C_Etype := | |
2c1b72d7 AC |
6981 | Build_Actual_Subtype_Of_Component |
6982 | (Etype (Selector), N); | |
9fc2854d AC |
6983 | end if; |
6984 | ||
996ae0b0 RK |
6985 | else |
6986 | C_Etype := Empty; | |
6987 | end if; | |
6988 | ||
6989 | if No (C_Etype) then | |
6990 | C_Etype := Etype (Selector); | |
6991 | else | |
6992 | Insert_Action (N, C_Etype); | |
6993 | C_Etype := Defining_Identifier (C_Etype); | |
6994 | end if; | |
6995 | ||
6996 | Set_Etype (N, C_Etype); | |
6997 | end; | |
6998 | ||
6999 | -- If this is the name of an entry or protected operation, and | |
7000 | -- the prefix is an access type, insert an explicit dereference, | |
7001 | -- so that entry calls are treated uniformly. | |
7002 | ||
7003 | if Is_Access_Type (Etype (P)) | |
7004 | and then Is_Concurrent_Type (Designated_Type (Etype (P))) | |
7005 | then | |
7006 | declare | |
fbf5a39b AC |
7007 | New_P : constant Node_Id := |
7008 | Make_Explicit_Dereference (Sloc (P), | |
7009 | Prefix => Relocate_Node (P)); | |
996ae0b0 RK |
7010 | begin |
7011 | Rewrite (P, New_P); | |
7012 | Set_Etype (P, Designated_Type (Etype (Prefix (P)))); | |
7013 | end; | |
7014 | end if; | |
7015 | ||
7016 | -- If the selected component appears within a default expression | |
7017 | -- and it has an actual subtype, the pre-analysis has not yet | |
7018 | -- completed its analysis, because Insert_Actions is disabled in | |
fbf5a39b | 7019 | -- that context. Within the init proc of the enclosing type we |
996ae0b0 RK |
7020 | -- must complete this analysis, if an actual subtype was created. |
7021 | ||
7022 | elsif Inside_Init_Proc then | |
7023 | declare | |
7024 | Typ : constant Entity_Id := Etype (N); | |
7025 | Decl : constant Node_Id := Declaration_Node (Typ); | |
996ae0b0 RK |
7026 | begin |
7027 | if Nkind (Decl) = N_Subtype_Declaration | |
7028 | and then not Analyzed (Decl) | |
7029 | and then Is_List_Member (Decl) | |
7030 | and then No (Parent (Decl)) | |
7031 | then | |
7032 | Remove (Decl); | |
7033 | Insert_Action (N, Decl); | |
7034 | end if; | |
7035 | end; | |
7036 | end if; | |
7037 | ||
7038 | return; | |
7039 | ||
7040 | elsif Is_Entity_Name (P) then | |
7041 | P_Name := Entity (P); | |
7042 | ||
7043 | -- The prefix may denote an enclosing type which is the completion | |
7044 | -- of an incomplete type declaration. | |
7045 | ||
7046 | if Is_Type (P_Name) then | |
7047 | Set_Entity (P, Get_Full_View (P_Name)); | |
7048 | Set_Etype (P, Entity (P)); | |
7049 | P_Name := Entity (P); | |
7050 | end if; | |
7051 | ||
7052 | P_Type := Base_Type (Etype (P)); | |
7053 | ||
7054 | if Debug_Flag_E then | |
7055 | Write_Str ("Found prefix type to be "); | |
7056 | Write_Entity_Info (P_Type, " "); Write_Eol; | |
7057 | end if; | |
7058 | ||
38cea80d ES |
7059 | -- The designated type may be a limited view with no components. |
7060 | -- Check whether the non-limited view is available, because in some | |
b943a971 AC |
7061 | -- cases this will not be set when installing the context. Rewrite |
7062 | -- the node by introducing an explicit dereference at once, and | |
7063 | -- setting the type of the rewritten prefix to the non-limited view | |
7064 | -- of the original designated type. | |
38cea80d ES |
7065 | |
7066 | if Is_Access_Type (P_Type) then | |
7067 | declare | |
b943a971 AC |
7068 | Desig_Typ : constant Entity_Id := |
7069 | Directly_Designated_Type (P_Type); | |
7070 | ||
38cea80d | 7071 | begin |
b943a971 AC |
7072 | if Is_Incomplete_Type (Desig_Typ) |
7073 | and then From_Limited_With (Desig_Typ) | |
7074 | and then Present (Non_Limited_View (Desig_Typ)) | |
38cea80d | 7075 | then |
b943a971 AC |
7076 | Rewrite (P, |
7077 | Make_Explicit_Dereference (Sloc (P), | |
7078 | Prefix => Relocate_Node (P))); | |
7079 | ||
7080 | Set_Etype (P, Get_Full_View (Non_Limited_View (Desig_Typ))); | |
7081 | P_Type := Etype (P); | |
38cea80d ES |
7082 | end if; |
7083 | end; | |
7084 | end if; | |
7085 | ||
996ae0b0 RK |
7086 | -- First check for components of a record object (not the |
7087 | -- result of a call, which is handled below). | |
7088 | ||
7089 | if Is_Appropriate_For_Record (P_Type) | |
7090 | and then not Is_Overloadable (P_Name) | |
7091 | and then not Is_Type (P_Name) | |
7092 | then | |
7093 | -- Selected component of record. Type checking will validate | |
7094 | -- name of selector. | |
dbfeb4fa RD |
7095 | |
7096 | -- ??? Could we rewrite an implicit dereference into an explicit | |
11560bcc | 7097 | -- one here? |
996ae0b0 RK |
7098 | |
7099 | Analyze_Selected_Component (N); | |
7100 | ||
f6b5dc8e AC |
7101 | -- Reference to type name in predicate/invariant expression |
7102 | ||
996ae0b0 RK |
7103 | elsif Is_Appropriate_For_Entry_Prefix (P_Type) |
7104 | and then not In_Open_Scopes (P_Name) | |
7105 | and then (not Is_Concurrent_Type (Etype (P_Name)) | |
ac7d724d | 7106 | or else not In_Open_Scopes (Etype (P_Name))) |
996ae0b0 RK |
7107 | then |
7108 | -- Call to protected operation or entry. Type checking is | |
7109 | -- needed on the prefix. | |
7110 | ||
7111 | Analyze_Selected_Component (N); | |
7112 | ||
7113 | elsif (In_Open_Scopes (P_Name) | |
f6b5dc8e AC |
7114 | and then Ekind (P_Name) /= E_Void |
7115 | and then not Is_Overloadable (P_Name)) | |
996ae0b0 | 7116 | or else (Is_Concurrent_Type (Etype (P_Name)) |
f6b5dc8e | 7117 | and then In_Open_Scopes (Etype (P_Name))) |
996ae0b0 RK |
7118 | then |
7119 | -- Prefix denotes an enclosing loop, block, or task, i.e. an | |
7120 | -- enclosing construct that is not a subprogram or accept. | |
7121 | ||
549cc9c2 AC |
7122 | -- A special case: a protected body may call an operation |
7123 | -- on an external object of the same type, in which case it | |
7124 | -- is not an expanded name. If the prefix is the type itself, | |
7125 | -- or the context is a single synchronized object it can only | |
7126 | -- be interpreted as an expanded name. | |
7127 | ||
7128 | if Is_Concurrent_Type (Etype (P_Name)) then | |
7129 | if Is_Type (P_Name) | |
7130 | or else Present (Anonymous_Object (Etype (P_Name))) | |
7131 | then | |
7132 | Find_Expanded_Name (N); | |
7133 | ||
7134 | else | |
7135 | Analyze_Selected_Component (N); | |
7136 | return; | |
7137 | end if; | |
7138 | ||
7139 | else | |
7140 | Find_Expanded_Name (N); | |
7141 | end if; | |
996ae0b0 RK |
7142 | |
7143 | elsif Ekind (P_Name) = E_Package then | |
7144 | Find_Expanded_Name (N); | |
7145 | ||
7146 | elsif Is_Overloadable (P_Name) then | |
7147 | ||
7148 | -- The subprogram may be a renaming (of an enclosing scope) as | |
7149 | -- in the case of the name of the generic within an instantiation. | |
7150 | ||
f6b5dc8e | 7151 | if Ekind_In (P_Name, E_Procedure, E_Function) |
996ae0b0 RK |
7152 | and then Present (Alias (P_Name)) |
7153 | and then Is_Generic_Instance (Alias (P_Name)) | |
7154 | then | |
7155 | P_Name := Alias (P_Name); | |
7156 | end if; | |
7157 | ||
7158 | if Is_Overloaded (P) then | |
7159 | ||
bc41faa2 | 7160 | -- The prefix must resolve to a unique enclosing construct |
996ae0b0 RK |
7161 | |
7162 | declare | |
7163 | Found : Boolean := False; | |
fbf5a39b | 7164 | Ind : Interp_Index; |
996ae0b0 RK |
7165 | It : Interp; |
7166 | ||
7167 | begin | |
fbf5a39b | 7168 | Get_First_Interp (P, Ind, It); |
996ae0b0 | 7169 | while Present (It.Nam) loop |
996ae0b0 RK |
7170 | if In_Open_Scopes (It.Nam) then |
7171 | if Found then | |
7172 | Error_Msg_N ( | |
7173 | "prefix must be unique enclosing scope", N); | |
7174 | Set_Entity (N, Any_Id); | |
7175 | Set_Etype (N, Any_Type); | |
7176 | return; | |
7177 | ||
7178 | else | |
7179 | Found := True; | |
7180 | P_Name := It.Nam; | |
7181 | end if; | |
7182 | end if; | |
7183 | ||
fbf5a39b | 7184 | Get_Next_Interp (Ind, It); |
996ae0b0 RK |
7185 | end loop; |
7186 | end; | |
7187 | end if; | |
7188 | ||
7189 | if In_Open_Scopes (P_Name) then | |
7190 | Set_Entity (P, P_Name); | |
7191 | Set_Is_Overloaded (P, False); | |
7192 | Find_Expanded_Name (N); | |
7193 | ||
7194 | else | |
7195 | -- If no interpretation as an expanded name is possible, it | |
7196 | -- must be a selected component of a record returned by a | |
16ca248a | 7197 | -- function call. Reformat prefix as a function call, the rest |
2757c5bf AC |
7198 | -- is done by type resolution. |
7199 | ||
7200 | -- Error if the prefix is procedure or entry, as is P.X | |
996ae0b0 RK |
7201 | |
7202 | if Ekind (P_Name) /= E_Function | |
ac7d724d ES |
7203 | and then |
7204 | (not Is_Overloaded (P) | |
7205 | or else Nkind (Parent (N)) = N_Procedure_Call_Statement) | |
996ae0b0 | 7206 | then |
996ae0b0 | 7207 | -- Prefix may mention a package that is hidden by a local |
290986ed GB |
7208 | -- declaration: let the user know. Scan the full homonym |
7209 | -- chain, the candidate package may be anywhere on it. | |
996ae0b0 | 7210 | |
290986ed | 7211 | if Present (Homonym (Current_Entity (P_Name))) then |
290986ed | 7212 | P_Name := Current_Entity (P_Name); |
996ae0b0 RK |
7213 | |
7214 | while Present (P_Name) loop | |
7215 | exit when Ekind (P_Name) = E_Package; | |
7216 | P_Name := Homonym (P_Name); | |
7217 | end loop; | |
7218 | ||
7219 | if Present (P_Name) then | |
2e70d415 AC |
7220 | if not Is_Reference_In_Subunit then |
7221 | Error_Msg_Sloc := Sloc (Entity (Prefix (N))); | |
2e70d415 | 7222 | Error_Msg_NE |
f5f6d8d7 | 7223 | ("package& is hidden by declaration#", N, P_Name); |
2e70d415 | 7224 | end if; |
996ae0b0 RK |
7225 | |
7226 | Set_Entity (Prefix (N), P_Name); | |
7227 | Find_Expanded_Name (N); | |
7228 | return; | |
2757c5bf | 7229 | |
996ae0b0 RK |
7230 | else |
7231 | P_Name := Entity (Prefix (N)); | |
7232 | end if; | |
7233 | end if; | |
7234 | ||
7235 | Error_Msg_NE | |
7236 | ("invalid prefix in selected component&", N, P_Name); | |
7237 | Change_Selected_Component_To_Expanded_Name (N); | |
7238 | Set_Entity (N, Any_Id); | |
7239 | Set_Etype (N, Any_Type); | |
7240 | ||
2757c5bf AC |
7241 | -- Here we have a function call, so do the reformatting |
7242 | ||
996ae0b0 RK |
7243 | else |
7244 | Nam := New_Copy (P); | |
7245 | Save_Interps (P, Nam); | |
2757c5bf AC |
7246 | |
7247 | -- We use Replace here because this is one of those cases | |
c63a2ad6 AC |
7248 | -- where the parser has missclassified the node, and we fix |
7249 | -- things up and then do the semantic analysis on the fixed | |
7250 | -- up node. Normally we do this using one of the Sinfo.CN | |
7251 | -- routines, but this is too tricky for that. | |
2757c5bf | 7252 | |
c63a2ad6 AC |
7253 | -- Note that using Rewrite would be wrong, because we would |
7254 | -- have a tree where the original node is unanalyzed, and | |
7255 | -- this violates the required interface for ASIS. | |
2757c5bf AC |
7256 | |
7257 | Replace (P, | |
996ae0b0 | 7258 | Make_Function_Call (Sloc (P), Name => Nam)); |
2757c5bf AC |
7259 | |
7260 | -- Now analyze the reformatted node | |
7261 | ||
996ae0b0 | 7262 | Analyze_Call (P); |
40bf00b1 | 7263 | |
c63a2ad6 AC |
7264 | -- If the prefix is illegal after this transformation, there |
7265 | -- may be visibility errors on the prefix. The safest is to | |
7266 | -- treat the selected component as an error. | |
40bf00b1 AC |
7267 | |
7268 | if Error_Posted (P) then | |
7269 | Set_Etype (N, Any_Type); | |
7270 | return; | |
7271 | ||
7272 | else | |
7273 | Analyze_Selected_Component (N); | |
7274 | end if; | |
996ae0b0 RK |
7275 | end if; |
7276 | end if; | |
7277 | ||
7278 | -- Remaining cases generate various error messages | |
7279 | ||
7280 | else | |
7281 | -- Format node as expanded name, to avoid cascaded errors | |
7282 | ||
c63a2ad6 AC |
7283 | -- If the limited_with transformation was applied earlier, restore |
7284 | -- source for proper error reporting. | |
b943a971 AC |
7285 | |
7286 | if not Comes_From_Source (P) | |
7287 | and then Nkind (P) = N_Explicit_Dereference | |
7288 | then | |
7289 | Rewrite (P, Prefix (P)); | |
7290 | P_Type := Etype (P); | |
7291 | end if; | |
7292 | ||
fbf5a39b | 7293 | Change_Selected_Component_To_Expanded_Name (N); |
b943a971 AC |
7294 | Set_Entity (N, Any_Id); |
7295 | Set_Etype (N, Any_Type); | |
996ae0b0 | 7296 | |
996ae0b0 RK |
7297 | -- Issue error message, but avoid this if error issued already. |
7298 | -- Use identifier of prefix if one is available. | |
7299 | ||
bcb0389e | 7300 | if P_Name = Any_Id then |
996ae0b0 RK |
7301 | null; |
7302 | ||
596b25f9 AC |
7303 | -- It is not an error if the prefix is the current instance of |
7304 | -- type name, e.g. the expression of a type aspect, when it is | |
7305 | -- analyzed for ASIS use. | |
7306 | ||
7307 | elsif Is_Entity_Name (P) and then Is_Current_Instance (P) then | |
7308 | null; | |
7309 | ||
996ae0b0 RK |
7310 | elsif Ekind (P_Name) = E_Void then |
7311 | Premature_Usage (P); | |
7312 | ||
7313 | elsif Nkind (P) /= N_Attribute_Reference then | |
67c0e662 RD |
7314 | |
7315 | -- This may have been meant as a prefixed call to a primitive | |
96df3ff4 AC |
7316 | -- of an untagged type. If it is a function call check type of |
7317 | -- its first formal and add explanation. | |
67c0e662 RD |
7318 | |
7319 | declare | |
7320 | F : constant Entity_Id := | |
7321 | Current_Entity (Selector_Name (N)); | |
7322 | begin | |
7323 | if Present (F) | |
7324 | and then Is_Overloadable (F) | |
7325 | and then Present (First_Entity (F)) | |
96df3ff4 | 7326 | and then not Is_Tagged_Type (Etype (First_Entity (F))) |
67c0e662 RD |
7327 | then |
7328 | Error_Msg_N | |
c308e762 HK |
7329 | ("prefixed call is only allowed for objects of a " |
7330 | & "tagged type", N); | |
67c0e662 RD |
7331 | end if; |
7332 | end; | |
7333 | ||
7334 | Error_Msg_N ("invalid prefix in selected component&", P); | |
996ae0b0 | 7335 | |
9596236a AC |
7336 | if Is_Access_Type (P_Type) |
7337 | and then Ekind (Designated_Type (P_Type)) = E_Incomplete_Type | |
7338 | then | |
65356e64 | 7339 | Error_Msg_N |
67c0e662 RD |
7340 | ("\dereference must not be of an incomplete type " |
7341 | & "(RM 3.10.1)", P); | |
9596236a AC |
7342 | end if; |
7343 | ||
996ae0b0 | 7344 | else |
67c0e662 | 7345 | Error_Msg_N ("invalid prefix in selected component", P); |
996ae0b0 RK |
7346 | end if; |
7347 | end if; | |
7348 | ||
db72f10a AC |
7349 | -- Selector name is restricted in SPARK |
7350 | ||
7351 | if Nkind (N) = N_Expanded_Name | |
6480338a | 7352 | and then Restriction_Check_Required (SPARK_05) |
db72f10a AC |
7353 | then |
7354 | if Is_Subprogram (P_Name) then | |
ce5ba43a | 7355 | Check_SPARK_05_Restriction |
db72f10a AC |
7356 | ("prefix of expanded name cannot be a subprogram", P); |
7357 | elsif Ekind (P_Name) = E_Loop then | |
ce5ba43a | 7358 | Check_SPARK_05_Restriction |
db72f10a AC |
7359 | ("prefix of expanded name cannot be a loop statement", P); |
7360 | end if; | |
7361 | end if; | |
7362 | ||
996ae0b0 RK |
7363 | else |
7364 | -- If prefix is not the name of an entity, it must be an expression, | |
7365 | -- whose type is appropriate for a record. This is determined by | |
7366 | -- type resolution. | |
7367 | ||
7368 | Analyze_Selected_Component (N); | |
7369 | end if; | |
0929eaeb AC |
7370 | |
7371 | Analyze_Dimension (N); | |
996ae0b0 RK |
7372 | end Find_Selected_Component; |
7373 | ||
7374 | --------------- | |
7375 | -- Find_Type -- | |
7376 | --------------- | |
7377 | ||
7378 | procedure Find_Type (N : Node_Id) is | |
7379 | C : Entity_Id; | |
7380 | Typ : Entity_Id; | |
7381 | T : Entity_Id; | |
7382 | T_Name : Entity_Id; | |
7383 | ||
7384 | begin | |
7385 | if N = Error then | |
7386 | return; | |
7387 | ||
7388 | elsif Nkind (N) = N_Attribute_Reference then | |
7389 | ||
11560bcc TQ |
7390 | -- Class attribute. This is not valid in Ada 83 mode, but we do not |
7391 | -- need to enforce that at this point, since the declaration of the | |
7392 | -- tagged type in the prefix would have been flagged already. | |
996ae0b0 RK |
7393 | |
7394 | if Attribute_Name (N) = Name_Class then | |
7395 | Check_Restriction (No_Dispatch, N); | |
7396 | Find_Type (Prefix (N)); | |
7397 | ||
7398 | -- Propagate error from bad prefix | |
7399 | ||
7400 | if Etype (Prefix (N)) = Any_Type then | |
7401 | Set_Entity (N, Any_Type); | |
7402 | Set_Etype (N, Any_Type); | |
7403 | return; | |
7404 | end if; | |
7405 | ||
7406 | T := Base_Type (Entity (Prefix (N))); | |
7407 | ||
11560bcc TQ |
7408 | -- Case where type is not known to be tagged. Its appearance in |
7409 | -- the prefix of the 'Class attribute indicates that the full view | |
16ca248a | 7410 | -- will be tagged. |
996ae0b0 RK |
7411 | |
7412 | if not Is_Tagged_Type (T) then | |
7413 | if Ekind (T) = E_Incomplete_Type then | |
7414 | ||
7415 | -- It is legal to denote the class type of an incomplete | |
7416 | -- type. The full type will have to be tagged, of course. | |
90067a15 | 7417 | -- In Ada 2005 this usage is declared obsolescent, so we |
ae247488 ES |
7418 | -- warn accordingly. This usage is only legal if the type |
7419 | -- is completed in the current scope, and not for a limited | |
7420 | -- view of a type. | |
7421 | ||
2f7b7467 AC |
7422 | if Ada_Version >= Ada_2005 then |
7423 | ||
7424 | -- Test whether the Available_View of a limited type view | |
7425 | -- is tagged, since the limited view may not be marked as | |
7426 | -- tagged if the type itself has an untagged incomplete | |
7427 | -- type view in its package. | |
7428 | ||
7b56a91b | 7429 | if From_Limited_With (T) |
2f7b7467 AC |
7430 | and then not Is_Tagged_Type (Available_View (T)) |
7431 | then | |
ae247488 ES |
7432 | Error_Msg_N |
7433 | ("prefix of Class attribute must be tagged", N); | |
7434 | Set_Etype (N, Any_Type); | |
7435 | Set_Entity (N, Any_Type); | |
7436 | return; | |
11560bcc | 7437 | |
dbfeb4fa RD |
7438 | -- ??? This test is temporarily disabled (always |
7439 | -- False) because it causes an unwanted warning on | |
7440 | -- GNAT sources (built with -gnatg, which includes | |
7441 | -- Warn_On_Obsolescent_ Feature). Once this issue | |
7442 | -- is cleared in the sources, it can be enabled. | |
11560bcc | 7443 | |
ac7d724d | 7444 | elsif Warn_On_Obsolescent_Feature and then False then |
ae247488 ES |
7445 | Error_Msg_N |
7446 | ("applying 'Class to an untagged incomplete type" | |
dbfeb4fa | 7447 | & " is an obsolescent feature (RM J.11)?r?", N); |
ae247488 | 7448 | end if; |
11560bcc | 7449 | end if; |
996ae0b0 RK |
7450 | |
7451 | Set_Is_Tagged_Type (T); | |
ef2a63ba | 7452 | Set_Direct_Primitive_Operations (T, New_Elmt_List); |
996ae0b0 RK |
7453 | Make_Class_Wide_Type (T); |
7454 | Set_Entity (N, Class_Wide_Type (T)); | |
7455 | Set_Etype (N, Class_Wide_Type (T)); | |
7456 | ||
7457 | elsif Ekind (T) = E_Private_Type | |
7458 | and then not Is_Generic_Type (T) | |
7459 | and then In_Private_Part (Scope (T)) | |
7460 | then | |
16ca248a ES |
7461 | -- The Class attribute can be applied to an untagged private |
7462 | -- type fulfilled by a tagged type prior to the full type | |
7463 | -- declaration (but only within the parent package's private | |
7464 | -- part). Create the class-wide type now and check that the | |
7465 | -- full type is tagged later during its analysis. Note that | |
7466 | -- we do not mark the private type as tagged, unlike the | |
7467 | -- case of incomplete types, because the type must still | |
996ae0b0 RK |
7468 | -- appear untagged to outside units. |
7469 | ||
cdc8c54c | 7470 | if No (Class_Wide_Type (T)) then |
996ae0b0 RK |
7471 | Make_Class_Wide_Type (T); |
7472 | end if; | |
7473 | ||
7474 | Set_Entity (N, Class_Wide_Type (T)); | |
7475 | Set_Etype (N, Class_Wide_Type (T)); | |
7476 | ||
7477 | else | |
16ca248a ES |
7478 | -- Should we introduce a type Any_Tagged and use Wrong_Type |
7479 | -- here, it would be a bit more consistent??? | |
996ae0b0 RK |
7480 | |
7481 | Error_Msg_NE | |
7482 | ("tagged type required, found}", | |
7483 | Prefix (N), First_Subtype (T)); | |
7484 | Set_Entity (N, Any_Type); | |
7485 | return; | |
7486 | end if; | |
7487 | ||
7488 | -- Case of tagged type | |
7489 | ||
7490 | else | |
39edfb45 | 7491 | if Is_Concurrent_Type (T) then |
cdc8c54c BD |
7492 | if No (Corresponding_Record_Type (Entity (Prefix (N)))) then |
7493 | ||
f2a54683 AC |
7494 | -- Previous error. Create a class-wide type for the |
7495 | -- synchronized type itself, with minimal semantic | |
7496 | -- attributes, to catch other errors in some ACATS tests. | |
cdc8c54c | 7497 | |
c48e0f27 | 7498 | pragma Assert (Serious_Errors_Detected /= 0); |
f2a54683 AC |
7499 | Make_Class_Wide_Type (T); |
7500 | C := Class_Wide_Type (T); | |
7501 | Set_First_Entity (C, First_Entity (T)); | |
cdc8c54c BD |
7502 | |
7503 | else | |
7504 | C := Class_Wide_Type | |
7505 | (Corresponding_Record_Type (Entity (Prefix (N)))); | |
7506 | end if; | |
7507 | ||
39edfb45 JM |
7508 | else |
7509 | C := Class_Wide_Type (Entity (Prefix (N))); | |
7510 | end if; | |
7511 | ||
e7ba564f | 7512 | Set_Entity_With_Checks (N, C); |
996ae0b0 RK |
7513 | Generate_Reference (C, N); |
7514 | Set_Etype (N, C); | |
996ae0b0 RK |
7515 | end if; |
7516 | ||
0ab80019 | 7517 | -- Base attribute, not allowed in Ada 83 |
996ae0b0 RK |
7518 | |
7519 | elsif Attribute_Name (N) = Name_Base then | |
7a489a2b | 7520 | Error_Msg_Name_1 := Name_Base; |
ce5ba43a | 7521 | Check_SPARK_05_Restriction |
7a489a2b AC |
7522 | ("attribute% is only allowed as prefix of another attribute", N); |
7523 | ||
0ab80019 | 7524 | if Ada_Version = Ada_83 and then Comes_From_Source (N) then |
996ae0b0 RK |
7525 | Error_Msg_N |
7526 | ("(Ada 83) Base attribute not allowed in subtype mark", N); | |
7527 | ||
7528 | else | |
7529 | Find_Type (Prefix (N)); | |
7530 | Typ := Entity (Prefix (N)); | |
7531 | ||
0ab80019 | 7532 | if Ada_Version >= Ada_95 |
fbf5a39b AC |
7533 | and then not Is_Scalar_Type (Typ) |
7534 | and then not Is_Generic_Type (Typ) | |
7535 | then | |
7536 | Error_Msg_N | |
bc41faa2 AC |
7537 | ("prefix of Base attribute must be scalar type", |
7538 | Prefix (N)); | |
fbf5a39b | 7539 | |
a8930b80 | 7540 | elsif Warn_On_Redundant_Constructs |
996ae0b0 | 7541 | and then Base_Type (Typ) = Typ |
996ae0b0 | 7542 | then |
ed2233dc | 7543 | Error_Msg_NE -- CODEFIX |
dbfeb4fa | 7544 | ("redundant attribute, & is its own base type?r?", N, Typ); |
996ae0b0 RK |
7545 | end if; |
7546 | ||
7547 | T := Base_Type (Typ); | |
996ae0b0 RK |
7548 | |
7549 | -- Rewrite attribute reference with type itself (see similar | |
a8930b80 AC |
7550 | -- processing in Analyze_Attribute, case Base). Preserve prefix |
7551 | -- if present, for other legality checks. | |
fbf5a39b AC |
7552 | |
7553 | if Nkind (Prefix (N)) = N_Expanded_Name then | |
7554 | Rewrite (N, | |
7555 | Make_Expanded_Name (Sloc (N), | |
11560bcc TQ |
7556 | Chars => Chars (T), |
7557 | Prefix => New_Copy (Prefix (Prefix (N))), | |
e4494292 | 7558 | Selector_Name => New_Occurrence_Of (T, Sloc (N)))); |
996ae0b0 | 7559 | |
fbf5a39b | 7560 | else |
e4494292 | 7561 | Rewrite (N, New_Occurrence_Of (T, Sloc (N))); |
fbf5a39b AC |
7562 | end if; |
7563 | ||
7564 | Set_Entity (N, T); | |
996ae0b0 RK |
7565 | Set_Etype (N, T); |
7566 | end if; | |
7567 | ||
923fa078 RD |
7568 | elsif Attribute_Name (N) = Name_Stub_Type then |
7569 | ||
7570 | -- This is handled in Analyze_Attribute | |
7571 | ||
7572 | Analyze (N); | |
7573 | ||
996ae0b0 RK |
7574 | -- All other attributes are invalid in a subtype mark |
7575 | ||
7576 | else | |
7577 | Error_Msg_N ("invalid attribute in subtype mark", N); | |
7578 | end if; | |
7579 | ||
7580 | else | |
7581 | Analyze (N); | |
7582 | ||
7583 | if Is_Entity_Name (N) then | |
7584 | T_Name := Entity (N); | |
7585 | else | |
7586 | Error_Msg_N ("subtype mark required in this context", N); | |
7587 | Set_Etype (N, Any_Type); | |
7588 | return; | |
7589 | end if; | |
7590 | ||
7591 | if T_Name = Any_Id or else Etype (N) = Any_Type then | |
7592 | ||
7593 | -- Undefined id. Make it into a valid type | |
7594 | ||
7595 | Set_Entity (N, Any_Type); | |
7596 | ||
7597 | elsif not Is_Type (T_Name) | |
7598 | and then T_Name /= Standard_Void_Type | |
7599 | then | |
7600 | Error_Msg_Sloc := Sloc (T_Name); | |
7601 | Error_Msg_N ("subtype mark required in this context", N); | |
923fa078 | 7602 | Error_Msg_NE ("\\found & declared#", N, T_Name); |
996ae0b0 RK |
7603 | Set_Entity (N, Any_Type); |
7604 | ||
7605 | else | |
11560bcc TQ |
7606 | -- If the type is an incomplete type created to handle |
7607 | -- anonymous access components of a record type, then the | |
7608 | -- incomplete type is the visible entity and subsequent | |
7609 | -- references will point to it. Mark the original full | |
7610 | -- type as referenced, to prevent spurious warnings. | |
7611 | ||
7612 | if Is_Incomplete_Type (T_Name) | |
7613 | and then Present (Full_View (T_Name)) | |
7614 | and then not Comes_From_Source (T_Name) | |
7615 | then | |
7616 | Set_Referenced (Full_View (T_Name)); | |
7617 | end if; | |
7618 | ||
996ae0b0 RK |
7619 | T_Name := Get_Full_View (T_Name); |
7620 | ||
11560bcc TQ |
7621 | -- Ada 2005 (AI-251, AI-50217): Handle interfaces visible through |
7622 | -- limited-with clauses | |
7623 | ||
7b56a91b | 7624 | if From_Limited_With (T_Name) |
11560bcc TQ |
7625 | and then Ekind (T_Name) in Incomplete_Kind |
7626 | and then Present (Non_Limited_View (T_Name)) | |
7627 | and then Is_Interface (Non_Limited_View (T_Name)) | |
7628 | then | |
7629 | T_Name := Non_Limited_View (T_Name); | |
7630 | end if; | |
7631 | ||
996ae0b0 RK |
7632 | if In_Open_Scopes (T_Name) then |
7633 | if Ekind (Base_Type (T_Name)) = E_Task_Type then | |
923fa078 RD |
7634 | |
7635 | -- In Ada 2005, a task name can be used in an access | |
e264efcc AC |
7636 | -- definition within its own body. It cannot be used |
7637 | -- in the discriminant part of the task declaration, | |
7638 | -- nor anywhere else in the declaration because entries | |
7639 | -- cannot have access parameters. | |
923fa078 | 7640 | |
0791fbe9 | 7641 | if Ada_Version >= Ada_2005 |
923fa078 RD |
7642 | and then Nkind (Parent (N)) = N_Access_Definition |
7643 | then | |
7644 | Set_Entity (N, T_Name); | |
7645 | Set_Etype (N, T_Name); | |
e264efcc AC |
7646 | |
7647 | if Has_Completion (T_Name) then | |
7648 | return; | |
7649 | ||
7650 | else | |
7651 | Error_Msg_N | |
7652 | ("task type cannot be used as type mark " & | |
7653 | "within its own declaration", N); | |
7654 | end if; | |
923fa078 RD |
7655 | |
7656 | else | |
7657 | Error_Msg_N | |
7658 | ("task type cannot be used as type mark " & | |
fbe627af | 7659 | "within its own spec or body", N); |
923fa078 | 7660 | end if; |
fbe627af RD |
7661 | |
7662 | elsif Ekind (Base_Type (T_Name)) = E_Protected_Type then | |
7663 | ||
7664 | -- In Ada 2005, a protected name can be used in an access | |
7665 | -- definition within its own body. | |
7666 | ||
0791fbe9 | 7667 | if Ada_Version >= Ada_2005 |
fbe627af RD |
7668 | and then Nkind (Parent (N)) = N_Access_Definition |
7669 | then | |
7670 | Set_Entity (N, T_Name); | |
7671 | Set_Etype (N, T_Name); | |
7672 | return; | |
7673 | ||
7674 | else | |
7675 | Error_Msg_N | |
7676 | ("protected type cannot be used as type mark " & | |
7677 | "within its own spec or body", N); | |
7678 | end if; | |
7679 | ||
996ae0b0 RK |
7680 | else |
7681 | Error_Msg_N ("type declaration cannot refer to itself", N); | |
7682 | end if; | |
7683 | ||
7684 | Set_Etype (N, Any_Type); | |
7685 | Set_Entity (N, Any_Type); | |
7686 | Set_Error_Posted (T_Name); | |
7687 | return; | |
7688 | end if; | |
7689 | ||
7690 | Set_Entity (N, T_Name); | |
7691 | Set_Etype (N, T_Name); | |
7692 | end if; | |
7693 | end if; | |
7694 | ||
07fc65c4 | 7695 | if Present (Etype (N)) and then Comes_From_Source (N) then |
996ae0b0 RK |
7696 | if Is_Fixed_Point_Type (Etype (N)) then |
7697 | Check_Restriction (No_Fixed_Point, N); | |
7698 | elsif Is_Floating_Point_Type (Etype (N)) then | |
7699 | Check_Restriction (No_Floating_Point, N); | |
7700 | end if; | |
8636f52f HK |
7701 | |
7702 | -- A Ghost type must appear in a specific context | |
7703 | ||
7704 | if Is_Ghost_Entity (Etype (N)) then | |
7705 | Check_Ghost_Context (Etype (N), N); | |
7706 | end if; | |
996ae0b0 RK |
7707 | end if; |
7708 | end Find_Type; | |
7709 | ||
996ae0b0 RK |
7710 | ------------------------------------ |
7711 | -- Has_Implicit_Character_Literal -- | |
7712 | ------------------------------------ | |
7713 | ||
7714 | function Has_Implicit_Character_Literal (N : Node_Id) return Boolean is | |
7715 | Id : Entity_Id; | |
7716 | Found : Boolean := False; | |
7717 | P : constant Entity_Id := Entity (Prefix (N)); | |
7718 | Priv_Id : Entity_Id := Empty; | |
7719 | ||
7720 | begin | |
ac7d724d | 7721 | if Ekind (P) = E_Package and then not In_Open_Scopes (P) then |
996ae0b0 RK |
7722 | Priv_Id := First_Private_Entity (P); |
7723 | end if; | |
7724 | ||
7725 | if P = Standard_Standard then | |
7726 | Change_Selected_Component_To_Expanded_Name (N); | |
7727 | Rewrite (N, Selector_Name (N)); | |
7728 | Analyze (N); | |
7729 | Set_Etype (Original_Node (N), Standard_Character); | |
7730 | return True; | |
7731 | end if; | |
7732 | ||
7733 | Id := First_Entity (P); | |
ac7d724d | 7734 | while Present (Id) and then Id /= Priv_Id loop |
d347f572 AC |
7735 | if Is_Standard_Character_Type (Id) and then Is_Base_Type (Id) then |
7736 | ||
996ae0b0 RK |
7737 | -- We replace the node with the literal itself, resolve as a |
7738 | -- character, and set the type correctly. | |
7739 | ||
7740 | if not Found then | |
7741 | Change_Selected_Component_To_Expanded_Name (N); | |
7742 | Rewrite (N, Selector_Name (N)); | |
7743 | Analyze (N); | |
7744 | Set_Etype (N, Id); | |
7745 | Set_Etype (Original_Node (N), Id); | |
7746 | Found := True; | |
7747 | ||
7748 | else | |
7749 | -- More than one type derived from Character in given scope. | |
7750 | -- Collect all possible interpretations. | |
7751 | ||
7752 | Add_One_Interp (N, Id, Id); | |
7753 | end if; | |
7754 | end if; | |
7755 | ||
7756 | Next_Entity (Id); | |
7757 | end loop; | |
7758 | ||
7759 | return Found; | |
7760 | end Has_Implicit_Character_Literal; | |
7761 | ||
9bc856dd AC |
7762 | ---------------------- |
7763 | -- Has_Private_With -- | |
7764 | ---------------------- | |
7765 | ||
7766 | function Has_Private_With (E : Entity_Id) return Boolean is | |
7767 | Comp_Unit : constant Node_Id := Cunit (Current_Sem_Unit); | |
7768 | Item : Node_Id; | |
7769 | ||
7770 | begin | |
7771 | Item := First (Context_Items (Comp_Unit)); | |
7772 | while Present (Item) loop | |
7773 | if Nkind (Item) = N_With_Clause | |
7774 | and then Private_Present (Item) | |
7775 | and then Entity (Name (Item)) = E | |
7776 | then | |
7777 | return True; | |
7778 | end if; | |
7779 | ||
7780 | Next (Item); | |
7781 | end loop; | |
7782 | ||
7783 | return False; | |
7784 | end Has_Private_With; | |
7785 | ||
996ae0b0 RK |
7786 | --------------------------- |
7787 | -- Has_Implicit_Operator -- | |
7788 | --------------------------- | |
7789 | ||
7790 | function Has_Implicit_Operator (N : Node_Id) return Boolean is | |
7791 | Op_Id : constant Name_Id := Chars (Selector_Name (N)); | |
7792 | P : constant Entity_Id := Entity (Prefix (N)); | |
7793 | Id : Entity_Id; | |
7794 | Priv_Id : Entity_Id := Empty; | |
7795 | ||
fbf5a39b AC |
7796 | procedure Add_Implicit_Operator |
7797 | (T : Entity_Id; | |
7798 | Op_Type : Entity_Id := Empty); | |
fbe627af RD |
7799 | -- Add implicit interpretation to node N, using the type for which a |
7800 | -- predefined operator exists. If the operator yields a boolean type, | |
7801 | -- the Operand_Type is implicitly referenced by the operator, and a | |
7802 | -- reference to it must be generated. | |
996ae0b0 RK |
7803 | |
7804 | --------------------------- | |
7805 | -- Add_Implicit_Operator -- | |
7806 | --------------------------- | |
7807 | ||
fbf5a39b AC |
7808 | procedure Add_Implicit_Operator |
7809 | (T : Entity_Id; | |
7810 | Op_Type : Entity_Id := Empty) | |
7811 | is | |
996ae0b0 RK |
7812 | Predef_Op : Entity_Id; |
7813 | ||
7814 | begin | |
7815 | Predef_Op := Current_Entity (Selector_Name (N)); | |
996ae0b0 RK |
7816 | while Present (Predef_Op) |
7817 | and then Scope (Predef_Op) /= Standard_Standard | |
7818 | loop | |
7819 | Predef_Op := Homonym (Predef_Op); | |
7820 | end loop; | |
7821 | ||
7822 | if Nkind (N) = N_Selected_Component then | |
7823 | Change_Selected_Component_To_Expanded_Name (N); | |
7824 | end if; | |
7825 | ||
719aaf4d AC |
7826 | -- If the context is an unanalyzed function call, determine whether |
7827 | -- a binary or unary interpretation is required. | |
996ae0b0 | 7828 | |
719aaf4d AC |
7829 | if Nkind (Parent (N)) = N_Indexed_Component then |
7830 | declare | |
964f13da RD |
7831 | Is_Binary_Call : constant Boolean := |
7832 | Present | |
7833 | (Next (First (Expressions (Parent (N))))); | |
7834 | Is_Binary_Op : constant Boolean := | |
7835 | First_Entity | |
7836 | (Predef_Op) /= Last_Entity (Predef_Op); | |
719aaf4d AC |
7837 | Predef_Op2 : constant Entity_Id := Homonym (Predef_Op); |
7838 | ||
7839 | begin | |
7840 | if Is_Binary_Call then | |
7841 | if Is_Binary_Op then | |
7842 | Add_One_Interp (N, Predef_Op, T); | |
7843 | else | |
7844 | Add_One_Interp (N, Predef_Op2, T); | |
7845 | end if; | |
996ae0b0 | 7846 | |
719aaf4d AC |
7847 | else |
7848 | if not Is_Binary_Op then | |
7849 | Add_One_Interp (N, Predef_Op, T); | |
7850 | else | |
7851 | Add_One_Interp (N, Predef_Op2, T); | |
7852 | end if; | |
7853 | end if; | |
7854 | end; | |
7855 | ||
7856 | else | |
7857 | Add_One_Interp (N, Predef_Op, T); | |
7858 | ||
7859 | -- For operators with unary and binary interpretations, if | |
7860 | -- context is not a call, add both | |
7861 | ||
7862 | if Present (Homonym (Predef_Op)) then | |
7863 | Add_One_Interp (N, Homonym (Predef_Op), T); | |
7864 | end if; | |
996ae0b0 | 7865 | end if; |
fbf5a39b AC |
7866 | |
7867 | -- The node is a reference to a predefined operator, and | |
7868 | -- an implicit reference to the type of its operands. | |
7869 | ||
7870 | if Present (Op_Type) then | |
7871 | Generate_Operator_Reference (N, Op_Type); | |
7872 | else | |
7873 | Generate_Operator_Reference (N, T); | |
7874 | end if; | |
996ae0b0 RK |
7875 | end Add_Implicit_Operator; |
7876 | ||
7877 | -- Start of processing for Has_Implicit_Operator | |
7878 | ||
7879 | begin | |
ac7d724d | 7880 | if Ekind (P) = E_Package and then not In_Open_Scopes (P) then |
996ae0b0 RK |
7881 | Priv_Id := First_Private_Entity (P); |
7882 | end if; | |
7883 | ||
7884 | Id := First_Entity (P); | |
7885 | ||
7886 | case Op_Id is | |
7887 | ||
7888 | -- Boolean operators: an implicit declaration exists if the scope | |
7889 | -- contains a declaration for a derived Boolean type, or for an | |
7890 | -- array of Boolean type. | |
7891 | ||
d8f43ee6 HK |
7892 | when Name_Op_And |
7893 | | Name_Op_Not | |
7894 | | Name_Op_Or | |
7895 | | Name_Op_Xor | |
7896 | => | |
fd22e260 | 7897 | while Id /= Priv_Id loop |
d347f572 | 7898 | if Valid_Boolean_Arg (Id) and then Is_Base_Type (Id) then |
996ae0b0 RK |
7899 | Add_Implicit_Operator (Id); |
7900 | return True; | |
7901 | end if; | |
7902 | ||
7903 | Next_Entity (Id); | |
7904 | end loop; | |
7905 | ||
bc41faa2 | 7906 | -- Equality: look for any non-limited type (result is Boolean) |
996ae0b0 | 7907 | |
d8f43ee6 HK |
7908 | when Name_Op_Eq |
7909 | | Name_Op_Ne | |
7910 | => | |
fd22e260 | 7911 | while Id /= Priv_Id loop |
996ae0b0 RK |
7912 | if Is_Type (Id) |
7913 | and then not Is_Limited_Type (Id) | |
d347f572 | 7914 | and then Is_Base_Type (Id) |
996ae0b0 | 7915 | then |
fbf5a39b | 7916 | Add_Implicit_Operator (Standard_Boolean, Id); |
996ae0b0 RK |
7917 | return True; |
7918 | end if; | |
7919 | ||
7920 | Next_Entity (Id); | |
7921 | end loop; | |
7922 | ||
bc41faa2 | 7923 | -- Comparison operators: scalar type, or array of scalar |
996ae0b0 | 7924 | |
d8f43ee6 HK |
7925 | when Name_Op_Ge |
7926 | | Name_Op_Gt | |
7927 | | Name_Op_Le | |
7928 | | Name_Op_Lt | |
7929 | => | |
fd22e260 | 7930 | while Id /= Priv_Id loop |
996ae0b0 | 7931 | if (Is_Scalar_Type (Id) |
d347f572 AC |
7932 | or else (Is_Array_Type (Id) |
7933 | and then Is_Scalar_Type (Component_Type (Id)))) | |
7934 | and then Is_Base_Type (Id) | |
996ae0b0 | 7935 | then |
fbf5a39b | 7936 | Add_Implicit_Operator (Standard_Boolean, Id); |
996ae0b0 RK |
7937 | return True; |
7938 | end if; | |
7939 | ||
7940 | Next_Entity (Id); | |
7941 | end loop; | |
7942 | ||
7943 | -- Arithmetic operators: any numeric type | |
7944 | ||
d8f43ee6 HK |
7945 | when Name_Op_Abs |
7946 | | Name_Op_Add | |
7947 | | Name_Op_Divide | |
7948 | | Name_Op_Expon | |
7949 | | Name_Op_Mod | |
7950 | | Name_Op_Multiply | |
7951 | | Name_Op_Rem | |
7952 | | Name_Op_Subtract | |
7953 | => | |
fd22e260 | 7954 | while Id /= Priv_Id loop |
d347f572 | 7955 | if Is_Numeric_Type (Id) and then Is_Base_Type (Id) then |
996ae0b0 RK |
7956 | Add_Implicit_Operator (Id); |
7957 | return True; | |
7958 | end if; | |
7959 | ||
7960 | Next_Entity (Id); | |
7961 | end loop; | |
7962 | ||
7963 | -- Concatenation: any one-dimensional array type | |
7964 | ||
7965 | when Name_Op_Concat => | |
fd22e260 | 7966 | while Id /= Priv_Id loop |
d347f572 AC |
7967 | if Is_Array_Type (Id) |
7968 | and then Number_Dimensions (Id) = 1 | |
7969 | and then Is_Base_Type (Id) | |
996ae0b0 RK |
7970 | then |
7971 | Add_Implicit_Operator (Id); | |
7972 | return True; | |
7973 | end if; | |
7974 | ||
7975 | Next_Entity (Id); | |
7976 | end loop; | |
7977 | ||
7978 | -- What is the others condition here? Should we be using a | |
7979 | -- subtype of Name_Id that would restrict to operators ??? | |
7980 | ||
d8f43ee6 HK |
7981 | when others => |
7982 | null; | |
996ae0b0 RK |
7983 | end case; |
7984 | ||
7985 | -- If we fall through, then we do not have an implicit operator | |
7986 | ||
7987 | return False; | |
996ae0b0 RK |
7988 | end Has_Implicit_Operator; |
7989 | ||
607d0635 AC |
7990 | ----------------------------------- |
7991 | -- Has_Loop_In_Inner_Open_Scopes -- | |
7992 | ----------------------------------- | |
7993 | ||
7994 | function Has_Loop_In_Inner_Open_Scopes (S : Entity_Id) return Boolean is | |
7995 | begin | |
7996 | -- Several scope stacks are maintained by Scope_Stack. The base of the | |
7997 | -- currently active scope stack is denoted by the Is_Active_Stack_Base | |
7998 | -- flag in the scope stack entry. Note that the scope stacks used to | |
7999 | -- simply be delimited implicitly by the presence of Standard_Standard | |
8000 | -- at their base, but there now are cases where this is not sufficient | |
8001 | -- because Standard_Standard actually may appear in the middle of the | |
8002 | -- active set of scopes. | |
8003 | ||
8004 | for J in reverse 0 .. Scope_Stack.Last loop | |
8d606a78 RD |
8005 | |
8006 | -- S was reached without seing a loop scope first | |
8007 | ||
607d0635 | 8008 | if Scope_Stack.Table (J).Entity = S then |
607d0635 | 8009 | return False; |
8d606a78 RD |
8010 | |
8011 | -- S was not yet reached, so it contains at least one inner loop | |
8012 | ||
607d0635 | 8013 | elsif Ekind (Scope_Stack.Table (J).Entity) = E_Loop then |
607d0635 AC |
8014 | return True; |
8015 | end if; | |
8016 | ||
8017 | -- Check Is_Active_Stack_Base to tell us when to stop, as there are | |
8018 | -- cases where Standard_Standard appears in the middle of the active | |
8019 | -- set of scopes. This affects the declaration and overriding of | |
8020 | -- private inherited operations in instantiations of generic child | |
8021 | -- units. | |
8022 | ||
8023 | pragma Assert (not Scope_Stack.Table (J).Is_Active_Stack_Base); | |
8024 | end loop; | |
8025 | ||
2010d078 | 8026 | raise Program_Error; -- unreachable |
607d0635 AC |
8027 | end Has_Loop_In_Inner_Open_Scopes; |
8028 | ||
996ae0b0 RK |
8029 | -------------------- |
8030 | -- In_Open_Scopes -- | |
8031 | -------------------- | |
8032 | ||
8033 | function In_Open_Scopes (S : Entity_Id) return Boolean is | |
8034 | begin | |
923fa078 RD |
8035 | -- Several scope stacks are maintained by Scope_Stack. The base of the |
8036 | -- currently active scope stack is denoted by the Is_Active_Stack_Base | |
8037 | -- flag in the scope stack entry. Note that the scope stacks used to | |
8038 | -- simply be delimited implicitly by the presence of Standard_Standard | |
8039 | -- at their base, but there now are cases where this is not sufficient | |
8040 | -- because Standard_Standard actually may appear in the middle of the | |
8041 | -- active set of scopes. | |
996ae0b0 RK |
8042 | |
8043 | for J in reverse 0 .. Scope_Stack.Last loop | |
8044 | if Scope_Stack.Table (J).Entity = S then | |
8045 | return True; | |
8046 | end if; | |
8047 | ||
923fa078 RD |
8048 | -- Check Is_Active_Stack_Base to tell us when to stop, as there are |
8049 | -- cases where Standard_Standard appears in the middle of the active | |
8050 | -- set of scopes. This affects the declaration and overriding of | |
8051 | -- private inherited operations in instantiations of generic child | |
8052 | -- units. | |
996ae0b0 RK |
8053 | |
8054 | exit when Scope_Stack.Table (J).Is_Active_Stack_Base; | |
8055 | end loop; | |
8056 | ||
8057 | return False; | |
8058 | end In_Open_Scopes; | |
8059 | ||
8060 | ----------------------------- | |
8061 | -- Inherit_Renamed_Profile -- | |
8062 | ----------------------------- | |
8063 | ||
8064 | procedure Inherit_Renamed_Profile (New_S : Entity_Id; Old_S : Entity_Id) is | |
8065 | New_F : Entity_Id; | |
8066 | Old_F : Entity_Id; | |
8067 | Old_T : Entity_Id; | |
8068 | New_T : Entity_Id; | |
8069 | ||
8070 | begin | |
8071 | if Ekind (Old_S) = E_Operator then | |
996ae0b0 RK |
8072 | New_F := First_Formal (New_S); |
8073 | ||
8074 | while Present (New_F) loop | |
8075 | Set_Etype (New_F, Base_Type (Etype (New_F))); | |
8076 | Next_Formal (New_F); | |
8077 | end loop; | |
8078 | ||
8079 | Set_Etype (New_S, Base_Type (Etype (New_S))); | |
8080 | ||
8081 | else | |
8082 | New_F := First_Formal (New_S); | |
8083 | Old_F := First_Formal (Old_S); | |
8084 | ||
8085 | while Present (New_F) loop | |
8086 | New_T := Etype (New_F); | |
8087 | Old_T := Etype (Old_F); | |
8088 | ||
ed3fe8cc AC |
8089 | -- If the new type is a renaming of the old one, as is the case |
8090 | -- for actuals in instances, retain its name, to simplify later | |
8091 | -- disambiguation. | |
996ae0b0 RK |
8092 | |
8093 | if Nkind (Parent (New_T)) = N_Subtype_Declaration | |
8094 | and then Is_Entity_Name (Subtype_Indication (Parent (New_T))) | |
8095 | and then Entity (Subtype_Indication (Parent (New_T))) = Old_T | |
8096 | then | |
8097 | null; | |
8098 | else | |
8099 | Set_Etype (New_F, Old_T); | |
8100 | end if; | |
8101 | ||
8102 | Next_Formal (New_F); | |
8103 | Next_Formal (Old_F); | |
8104 | end loop; | |
ed3fe8cc | 8105 | |
60aa5228 | 8106 | pragma Assert (No (Old_F)); |
996ae0b0 | 8107 | |
bce79204 | 8108 | if Ekind_In (Old_S, E_Function, E_Enumeration_Literal) then |
996ae0b0 RK |
8109 | Set_Etype (New_S, Etype (Old_S)); |
8110 | end if; | |
8111 | end if; | |
8112 | end Inherit_Renamed_Profile; | |
8113 | ||
8114 | ---------------- | |
8115 | -- Initialize -- | |
8116 | ---------------- | |
8117 | ||
8118 | procedure Initialize is | |
8119 | begin | |
8120 | Urefs.Init; | |
8121 | end Initialize; | |
8122 | ||
8123 | ------------------------- | |
8124 | -- Install_Use_Clauses -- | |
8125 | ------------------------- | |
8126 | ||
0da2c8ac AC |
8127 | procedure Install_Use_Clauses |
8128 | (Clause : Node_Id; | |
8129 | Force_Installation : Boolean := False) | |
8130 | is | |
851e9f19 | 8131 | U : Node_Id; |
996ae0b0 RK |
8132 | |
8133 | begin | |
16ca248a | 8134 | U := Clause; |
996ae0b0 RK |
8135 | while Present (U) loop |
8136 | ||
8137 | -- Case of USE package | |
8138 | ||
8139 | if Nkind (U) = N_Use_Package_Clause then | |
851e9f19 | 8140 | Use_One_Package (U, Name (U), True); |
996ae0b0 | 8141 | |
16ca248a | 8142 | -- Case of USE TYPE |
996ae0b0 RK |
8143 | |
8144 | else | |
851e9f19 | 8145 | Use_One_Type (Subtype_Mark (U), Force => Force_Installation); |
996ae0b0 | 8146 | |
996ae0b0 RK |
8147 | end if; |
8148 | ||
8149 | Next_Use_Clause (U); | |
8150 | end loop; | |
8151 | end Install_Use_Clauses; | |
8152 | ||
8153 | ------------------------------------- | |
8154 | -- Is_Appropriate_For_Entry_Prefix -- | |
8155 | ------------------------------------- | |
8156 | ||
8157 | function Is_Appropriate_For_Entry_Prefix (T : Entity_Id) return Boolean is | |
8158 | P_Type : Entity_Id := T; | |
8159 | ||
8160 | begin | |
8161 | if Is_Access_Type (P_Type) then | |
8162 | P_Type := Designated_Type (P_Type); | |
8163 | end if; | |
8164 | ||
8165 | return Is_Task_Type (P_Type) or else Is_Protected_Type (P_Type); | |
8166 | end Is_Appropriate_For_Entry_Prefix; | |
8167 | ||
8168 | ------------------------------- | |
8169 | -- Is_Appropriate_For_Record -- | |
8170 | ------------------------------- | |
8171 | ||
2e071734 AC |
8172 | function Is_Appropriate_For_Record (T : Entity_Id) return Boolean is |
8173 | ||
996ae0b0 RK |
8174 | function Has_Components (T1 : Entity_Id) return Boolean; |
8175 | -- Determine if given type has components (i.e. is either a record | |
8176 | -- type or a type that has discriminants). | |
8177 | ||
16ca248a ES |
8178 | -------------------- |
8179 | -- Has_Components -- | |
8180 | -------------------- | |
8181 | ||
996ae0b0 RK |
8182 | function Has_Components (T1 : Entity_Id) return Boolean is |
8183 | begin | |
8184 | return Is_Record_Type (T1) | |
8185 | or else (Is_Private_Type (T1) and then Has_Discriminants (T1)) | |
16ca248a ES |
8186 | or else (Is_Task_Type (T1) and then Has_Discriminants (T1)) |
8187 | or else (Is_Incomplete_Type (T1) | |
7b56a91b | 8188 | and then From_Limited_With (T1) |
16ca248a | 8189 | and then Present (Non_Limited_View (T1)) |
11560bcc TQ |
8190 | and then Is_Record_Type |
8191 | (Get_Full_View (Non_Limited_View (T1)))); | |
996ae0b0 RK |
8192 | end Has_Components; |
8193 | ||
8194 | -- Start of processing for Is_Appropriate_For_Record | |
8195 | ||
8196 | begin | |
8197 | return | |
8198 | Present (T) | |
8199 | and then (Has_Components (T) | |
16ca248a ES |
8200 | or else (Is_Access_Type (T) |
8201 | and then Has_Components (Designated_Type (T)))); | |
996ae0b0 RK |
8202 | end Is_Appropriate_For_Record; |
8203 | ||
851e9f19 PMR |
8204 | ---------------------- |
8205 | -- Mark_Use_Clauses -- | |
8206 | ---------------------- | |
d4810530 | 8207 | |
851e9f19 | 8208 | procedure Mark_Use_Clauses (Id : Node_Or_Entity_Id) is |
851e9f19 PMR |
8209 | procedure Mark_Parameters (Call : Entity_Id); |
8210 | -- Perform use_type_clause marking for all parameters in a subprogram | |
8211 | -- or operator call. | |
d4810530 | 8212 | |
851e9f19 PMR |
8213 | procedure Mark_Use_Package (Pak : Entity_Id); |
8214 | -- Move up the Prev_Use_Clause chain for packages denoted by Pak - | |
8215 | -- marking each clause in the chain as effective in the process. | |
d4810530 | 8216 | |
851e9f19 PMR |
8217 | procedure Mark_Use_Type (E : Entity_Id); |
8218 | -- Similar to Do_Use_Package_Marking except we move up the | |
8219 | -- Prev_Use_Clause chain for the type denoted by E. | |
d4810530 | 8220 | |
851e9f19 PMR |
8221 | --------------------- |
8222 | -- Mark_Parameters -- | |
8223 | --------------------- | |
d4810530 | 8224 | |
851e9f19 PMR |
8225 | procedure Mark_Parameters (Call : Entity_Id) is |
8226 | Curr : Node_Id; | |
cdc8c54c | 8227 | |
851e9f19 PMR |
8228 | begin |
8229 | -- Move through all of the formals | |
d4810530 | 8230 | |
851e9f19 PMR |
8231 | Curr := First_Formal (Call); |
8232 | while Present (Curr) loop | |
8233 | Mark_Use_Type (Curr); | |
d4810530 | 8234 | |
851e9f19 PMR |
8235 | Curr := Next_Formal (Curr); |
8236 | end loop; | |
d4810530 | 8237 | |
851e9f19 | 8238 | -- Handle the return type |
d4810530 | 8239 | |
851e9f19 PMR |
8240 | Mark_Use_Type (Call); |
8241 | end Mark_Parameters; | |
d4810530 | 8242 | |
851e9f19 PMR |
8243 | ---------------------- |
8244 | -- Mark_Use_Package -- | |
8245 | ---------------------- | |
d4810530 | 8246 | |
851e9f19 PMR |
8247 | procedure Mark_Use_Package (Pak : Entity_Id) is |
8248 | Curr : Node_Id; | |
d4810530 | 8249 | |
851e9f19 | 8250 | begin |
7f5e671b PMR |
8251 | -- Ignore cases where the scope of the type is not a package (e.g. |
8252 | -- Standard_Standard). | |
d4810530 | 8253 | |
851e9f19 PMR |
8254 | if Ekind (Pak) /= E_Package then |
8255 | return; | |
8256 | end if; | |
d4810530 | 8257 | |
851e9f19 PMR |
8258 | Curr := Current_Use_Clause (Pak); |
8259 | while Present (Curr) | |
7f5e671b | 8260 | and then not Is_Effective_Use_Clause (Curr) |
851e9f19 | 8261 | loop |
7f5e671b PMR |
8262 | -- We need to mark the previous use clauses as effective, but |
8263 | -- each use clause may in turn render other use_package_clauses | |
851e9f19 PMR |
8264 | -- effective. Additionally, it is possible to have a parent |
8265 | -- package renamed as a child of itself so we must check the | |
8266 | -- prefix entity is not the same as the package we are marking. | |
8267 | ||
8268 | if Nkind (Name (Curr)) /= N_Identifier | |
8269 | and then Present (Prefix (Name (Curr))) | |
8270 | and then Entity (Prefix (Name (Curr))) /= Pak | |
8271 | then | |
8272 | Mark_Use_Package (Entity (Prefix (Name (Curr)))); | |
d4810530 | 8273 | |
851e9f19 PMR |
8274 | -- It is also possible to have a child package without a prefix |
8275 | -- that relies on a previous use_package_clause. | |
d4810530 | 8276 | |
851e9f19 PMR |
8277 | elsif Nkind (Name (Curr)) = N_Identifier |
8278 | and then Is_Child_Unit (Entity (Name (Curr))) | |
8279 | then | |
8280 | Mark_Use_Package (Scope (Entity (Name (Curr)))); | |
8281 | end if; | |
d4810530 | 8282 | |
851e9f19 | 8283 | -- Mark the use_package_clause as effective and move up the chain |
d4810530 | 8284 | |
851e9f19 | 8285 | Set_Is_Effective_Use_Clause (Curr); |
d4810530 | 8286 | |
851e9f19 PMR |
8287 | Curr := Prev_Use_Clause (Curr); |
8288 | end loop; | |
8289 | end Mark_Use_Package; | |
d4810530 | 8290 | |
851e9f19 PMR |
8291 | ------------------- |
8292 | -- Mark_Use_Type -- | |
8293 | ------------------- | |
d4810530 | 8294 | |
851e9f19 PMR |
8295 | procedure Mark_Use_Type (E : Entity_Id) is |
8296 | Curr : Node_Id; | |
d4810530 | 8297 | |
851e9f19 PMR |
8298 | begin |
8299 | -- Ignore void types and unresolved string literals and primitives | |
8300 | ||
8301 | if Nkind (E) = N_String_Literal | |
8302 | or else Nkind (Etype (E)) not in N_Entity | |
8303 | or else not Is_Type (Etype (E)) | |
8304 | then | |
8305 | return; | |
8306 | end if; | |
8307 | ||
8308 | -- The package containing the type or operator function being used | |
8309 | -- may be in use as well, so mark any use_package_clauses for it as | |
8310 | -- effective. There are also additional sanity checks performed here | |
8311 | -- for ignoring previous errors. | |
8312 | ||
8313 | Mark_Use_Package (Scope (Base_Type (Etype (E)))); | |
7f5e671b | 8314 | |
851e9f19 PMR |
8315 | if Nkind (E) in N_Op |
8316 | and then Present (Entity (E)) | |
8317 | and then Present (Scope (Entity (E))) | |
8318 | then | |
8319 | Mark_Use_Package (Scope (Entity (E))); | |
8320 | end if; | |
8321 | ||
8322 | Curr := Current_Use_Clause (Base_Type (Etype (E))); | |
8323 | while Present (Curr) | |
8324 | and then not Is_Effective_Use_Clause (Curr) | |
8325 | loop | |
8326 | -- Current use_type_clause may render other use_package_clauses | |
8327 | -- effective. | |
8328 | ||
8329 | if Nkind (Subtype_Mark (Curr)) /= N_Identifier | |
8330 | and then Present (Prefix (Subtype_Mark (Curr))) | |
8331 | then | |
8332 | Mark_Use_Package (Entity (Prefix (Subtype_Mark (Curr)))); | |
d4810530 | 8333 | end if; |
d4810530 | 8334 | |
851e9f19 PMR |
8335 | -- Mark the use_type_clause as effective and move up the chain |
8336 | ||
8337 | Set_Is_Effective_Use_Clause (Curr); | |
8338 | ||
8339 | Curr := Prev_Use_Clause (Curr); | |
8340 | end loop; | |
8341 | end Mark_Use_Type; | |
8342 | ||
8343 | -- Start of processing for Mark_Use_Clauses | |
8344 | ||
8345 | begin | |
8346 | -- Use clauses in and of themselves do not count as a "use" of a | |
8347 | -- package. | |
8348 | ||
7f5e671b | 8349 | if Nkind_In (Parent (Id), N_Use_Package_Clause, N_Use_Type_Clause) then |
851e9f19 PMR |
8350 | return; |
8351 | end if; | |
8352 | ||
8353 | -- Handle entities | |
8354 | ||
8355 | if Nkind (Id) in N_Entity then | |
8356 | ||
8357 | -- Mark the entity's package | |
8358 | ||
8359 | if Is_Potentially_Use_Visible (Id) then | |
8360 | Mark_Use_Package (Scope (Id)); | |
d4810530 ES |
8361 | end if; |
8362 | ||
851e9f19 | 8363 | -- Mark enumeration literals |
d4810530 | 8364 | |
851e9f19 PMR |
8365 | if Ekind (Id) = E_Enumeration_Literal then |
8366 | Mark_Use_Type (Id); | |
8367 | ||
8368 | -- Mark primitives | |
8369 | ||
8370 | elsif (Ekind (Id) in Overloadable_Kind | |
7f5e671b PMR |
8371 | or else Ekind_In (Id, E_Generic_Function, |
8372 | E_Generic_Procedure)) | |
851e9f19 PMR |
8373 | and then (Is_Potentially_Use_Visible (Id) |
8374 | or else Is_Intrinsic_Subprogram (Id)) | |
d4810530 | 8375 | then |
851e9f19 PMR |
8376 | Mark_Parameters (Id); |
8377 | end if; | |
d4810530 | 8378 | |
851e9f19 PMR |
8379 | -- Handle nodes |
8380 | ||
8381 | else | |
8382 | -- Mark operators | |
8383 | ||
8384 | if Nkind (Id) in N_Op then | |
8385 | ||
8386 | -- At this point the left operand may not be resolved if we are | |
8387 | -- encountering multiple operators next to eachother in an | |
8388 | -- expression. | |
8389 | ||
8390 | if Nkind (Id) in N_Binary_Op | |
7f5e671b | 8391 | and then not (Nkind (Left_Opnd (Id)) in N_Op) |
851e9f19 PMR |
8392 | then |
8393 | Mark_Use_Type (Left_Opnd (Id)); | |
8394 | end if; | |
8395 | ||
8396 | Mark_Use_Type (Right_Opnd (Id)); | |
8397 | Mark_Use_Type (Id); | |
8398 | ||
8399 | -- Mark entity identifiers | |
8400 | ||
8401 | elsif Nkind (Id) in N_Has_Entity | |
8402 | and then (Is_Potentially_Use_Visible (Entity (Id)) | |
8403 | or else (Is_Generic_Instance (Entity (Id)) | |
8404 | and then Is_Immediately_Visible (Entity (Id)))) | |
8405 | then | |
8406 | -- Ignore fully qualified names as they do not count as a "use" of | |
8407 | -- a package. | |
8408 | ||
8409 | if Nkind_In (Id, N_Identifier, N_Operator_Symbol) | |
8410 | or else (Present (Prefix (Id)) | |
8411 | and then Scope (Entity (Id)) /= Entity (Prefix (Id))) | |
8412 | then | |
20ad0586 | 8413 | Mark_Use_Clauses (Entity (Id)); |
851e9f19 | 8414 | end if; |
d4810530 | 8415 | end if; |
851e9f19 PMR |
8416 | end if; |
8417 | end Mark_Use_Clauses; | |
d4810530 | 8418 | |
851e9f19 PMR |
8419 | -------------------------------- |
8420 | -- Most_Descendant_Use_Clause -- | |
8421 | -------------------------------- | |
ff81221b | 8422 | |
851e9f19 PMR |
8423 | function Most_Descendant_Use_Clause |
8424 | (Clause1 : Entity_Id; | |
8425 | Clause2 : Entity_Id) return Entity_Id | |
8426 | is | |
8427 | Scope1, Scope2 : Entity_Id; | |
ff81221b | 8428 | |
851e9f19 PMR |
8429 | begin |
8430 | if Clause1 = Clause2 then | |
8431 | return Clause1; | |
d4810530 ES |
8432 | end if; |
8433 | ||
851e9f19 PMR |
8434 | -- We determine which one is the most descendant by the scope distance |
8435 | -- to the ultimate parent unit. | |
8436 | ||
8437 | Scope1 := Entity_Of_Unit (Unit (Parent (Clause1))); | |
8438 | Scope2 := Entity_Of_Unit (Unit (Parent (Clause2))); | |
8439 | while Scope1 /= Standard_Standard | |
8440 | and then Scope2 /= Standard_Standard | |
8441 | loop | |
8442 | Scope1 := Scope (Scope1); | |
8443 | Scope2 := Scope (Scope2); | |
8444 | ||
8445 | if not Present (Scope1) then | |
8446 | return Clause1; | |
8447 | elsif not Present (Scope2) then | |
8448 | return Clause2; | |
8449 | end if; | |
8450 | end loop; | |
8451 | ||
8452 | if Scope1 = Standard_Standard then | |
8453 | return Clause1; | |
d4810530 | 8454 | end if; |
851e9f19 PMR |
8455 | |
8456 | return Clause2; | |
8457 | end Most_Descendant_Use_Clause; | |
d4810530 | 8458 | |
996ae0b0 RK |
8459 | --------------- |
8460 | -- Pop_Scope -- | |
8461 | --------------- | |
8462 | ||
8463 | procedure Pop_Scope is | |
fbf5a39b | 8464 | SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last); |
fab2daeb | 8465 | S : constant Entity_Id := SST.Entity; |
996ae0b0 RK |
8466 | |
8467 | begin | |
8468 | if Debug_Flag_E then | |
8469 | Write_Info; | |
8470 | end if; | |
8471 | ||
fab2daeb AC |
8472 | -- Set Default_Storage_Pool field of the library unit if necessary |
8473 | ||
8474 | if Ekind_In (S, E_Package, E_Generic_Package) | |
8475 | and then | |
8476 | Nkind (Parent (Unit_Declaration_Node (S))) = N_Compilation_Unit | |
8477 | then | |
8478 | declare | |
8479 | Aux : constant Node_Id := | |
4adf3c50 | 8480 | Aux_Decls_Node (Parent (Unit_Declaration_Node (S))); |
fab2daeb AC |
8481 | begin |
8482 | if No (Default_Storage_Pool (Aux)) then | |
8483 | Set_Default_Storage_Pool (Aux, Default_Pool); | |
8484 | end if; | |
8485 | end; | |
8486 | end if; | |
8487 | ||
21d27997 | 8488 | Scope_Suppress := SST.Save_Scope_Suppress; |
11560bcc | 8489 | Local_Suppress_Stack_Top := SST.Save_Local_Suppress_Stack_Top; |
21d27997 | 8490 | Check_Policy_List := SST.Save_Check_Policy_List; |
fab2daeb | 8491 | Default_Pool := SST.Save_Default_Storage_Pool; |
49d41397 | 8492 | No_Tagged_Streams := SST.Save_No_Tagged_Streams; |
43417b90 | 8493 | SPARK_Mode := SST.Save_SPARK_Mode; |
579847c2 | 8494 | SPARK_Mode_Pragma := SST.Save_SPARK_Mode_Pragma; |
220d1fd9 | 8495 | Default_SSO := SST.Save_Default_SSO; |
96e90ac1 | 8496 | Uneval_Old := SST.Save_Uneval_Old; |
996ae0b0 RK |
8497 | |
8498 | if Debug_Flag_W then | |
fab2daeb | 8499 | Write_Str ("<-- exiting scope: "); |
996ae0b0 RK |
8500 | Write_Name (Chars (Current_Scope)); |
8501 | Write_Str (", Depth="); | |
8502 | Write_Int (Int (Scope_Stack.Last)); | |
8503 | Write_Eol; | |
8504 | end if; | |
8505 | ||
fbf5a39b | 8506 | End_Use_Clauses (SST.First_Use_Clause); |
996ae0b0 RK |
8507 | |
8508 | -- If the actions to be wrapped are still there they will get lost | |
8509 | -- causing incomplete code to be generated. It is better to abort in | |
fbf5a39b | 8510 | -- this case (and we do the abort even with assertions off since the |
5eeeed5e | 8511 | -- penalty is incorrect code generation). |
996ae0b0 | 8512 | |
36295779 | 8513 | if SST.Actions_To_Be_Wrapped /= Scope_Actions'(others => No_List) then |
46202729 | 8514 | raise Program_Error; |
fbf5a39b | 8515 | end if; |
996ae0b0 RK |
8516 | |
8517 | -- Free last subprogram name if allocated, and pop scope | |
8518 | ||
fbf5a39b | 8519 | Free (SST.Last_Subprogram_Name); |
996ae0b0 RK |
8520 | Scope_Stack.Decrement_Last; |
8521 | end Pop_Scope; | |
8522 | ||
851e9f19 | 8523 | ---------------- |
fbe627af | 8524 | -- Push_Scope -- |
851e9f19 | 8525 | ---------------- |
fbe627af RD |
8526 | |
8527 | procedure Push_Scope (S : Entity_Id) is | |
fab2daeb | 8528 | E : constant Entity_Id := Scope (S); |
fbe627af RD |
8529 | |
8530 | begin | |
8531 | if Ekind (S) = E_Void then | |
8532 | null; | |
8533 | ||
f7ca1d04 AC |
8534 | -- Set scope depth if not a non-concurrent type, and we have not yet set |
8535 | -- the scope depth. This means that we have the first occurrence of the | |
8536 | -- scope, and this is where the depth is set. | |
fbe627af RD |
8537 | |
8538 | elsif (not Is_Type (S) or else Is_Concurrent_Type (S)) | |
8539 | and then not Scope_Depth_Set (S) | |
8540 | then | |
8541 | if S = Standard_Standard then | |
8542 | Set_Scope_Depth_Value (S, Uint_0); | |
8543 | ||
8544 | elsif Is_Child_Unit (S) then | |
8545 | Set_Scope_Depth_Value (S, Uint_1); | |
8546 | ||
8547 | elsif not Is_Record_Type (Current_Scope) then | |
8548 | if Ekind (S) = E_Loop then | |
8549 | Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope)); | |
8550 | else | |
8551 | Set_Scope_Depth_Value (S, Scope_Depth (Current_Scope) + 1); | |
8552 | end if; | |
8553 | end if; | |
8554 | end if; | |
8555 | ||
8556 | Scope_Stack.Increment_Last; | |
8557 | ||
8558 | declare | |
8559 | SST : Scope_Stack_Entry renames Scope_Stack.Table (Scope_Stack.Last); | |
8560 | ||
8561 | begin | |
11560bcc TQ |
8562 | SST.Entity := S; |
8563 | SST.Save_Scope_Suppress := Scope_Suppress; | |
8564 | SST.Save_Local_Suppress_Stack_Top := Local_Suppress_Stack_Top; | |
21d27997 | 8565 | SST.Save_Check_Policy_List := Check_Policy_List; |
fab2daeb | 8566 | SST.Save_Default_Storage_Pool := Default_Pool; |
49d41397 | 8567 | SST.Save_No_Tagged_Streams := No_Tagged_Streams; |
43417b90 | 8568 | SST.Save_SPARK_Mode := SPARK_Mode; |
579847c2 | 8569 | SST.Save_SPARK_Mode_Pragma := SPARK_Mode_Pragma; |
220d1fd9 | 8570 | SST.Save_Default_SSO := Default_SSO; |
96e90ac1 | 8571 | SST.Save_Uneval_Old := Uneval_Old; |
fbe627af | 8572 | |
194d6f3f JS |
8573 | -- Each new scope pushed onto the scope stack inherits the component |
8574 | -- alignment of the previous scope. This emulates the "visibility" | |
8575 | -- semantics of pragma Component_Alignment. | |
8576 | ||
fbe627af | 8577 | if Scope_Stack.Last > Scope_Stack.First then |
5dc203d2 AC |
8578 | SST.Component_Alignment_Default := |
8579 | Scope_Stack.Table | |
8580 | (Scope_Stack.Last - 1). Component_Alignment_Default; | |
194d6f3f JS |
8581 | |
8582 | -- Otherwise, this is the first scope being pushed on the scope | |
8583 | -- stack. Inherit the component alignment from the configuration | |
8584 | -- form of pragma Component_Alignment (if any). | |
8585 | ||
8586 | else | |
8587 | SST.Component_Alignment_Default := | |
8588 | Configuration_Component_Alignment; | |
fbe627af RD |
8589 | end if; |
8590 | ||
8591 | SST.Last_Subprogram_Name := null; | |
8592 | SST.Is_Transient := False; | |
8593 | SST.Node_To_Be_Wrapped := Empty; | |
8594 | SST.Pending_Freeze_Actions := No_List; | |
36295779 | 8595 | SST.Actions_To_Be_Wrapped := (others => No_List); |
fbe627af RD |
8596 | SST.First_Use_Clause := Empty; |
8597 | SST.Is_Active_Stack_Base := False; | |
8598 | SST.Previous_Visibility := False; | |
8071b771 | 8599 | SST.Locked_Shared_Objects := No_Elist; |
fbe627af RD |
8600 | end; |
8601 | ||
8602 | if Debug_Flag_W then | |
8603 | Write_Str ("--> new scope: "); | |
8604 | Write_Name (Chars (Current_Scope)); | |
8605 | Write_Str (", Id="); | |
8606 | Write_Int (Int (Current_Scope)); | |
8607 | Write_Str (", Depth="); | |
8608 | Write_Int (Int (Scope_Stack.Last)); | |
8609 | Write_Eol; | |
8610 | end if; | |
8611 | ||
f7ca1d04 AC |
8612 | -- Deal with copying flags from the previous scope to this one. This is |
8613 | -- not necessary if either scope is standard, or if the new scope is a | |
8614 | -- child unit. | |
fbe627af RD |
8615 | |
8616 | if S /= Standard_Standard | |
8617 | and then Scope (S) /= Standard_Standard | |
8618 | and then not Is_Child_Unit (S) | |
8619 | then | |
fbe627af RD |
8620 | if Nkind (E) not in N_Entity then |
8621 | return; | |
8622 | end if; | |
8623 | ||
8624 | -- Copy categorization flags from Scope (S) to S, this is not done | |
8625 | -- when Scope (S) is Standard_Standard since propagation is from | |
8626 | -- library unit entity inwards. Copy other relevant attributes as | |
8627 | -- well (Discard_Names in particular). | |
8628 | ||
8629 | -- We only propagate inwards for library level entities, | |
8630 | -- inner level subprograms do not inherit the categorization. | |
8631 | ||
8632 | if Is_Library_Level_Entity (S) then | |
8633 | Set_Is_Preelaborated (S, Is_Preelaborated (E)); | |
8634 | Set_Is_Shared_Passive (S, Is_Shared_Passive (E)); | |
8635 | Set_Discard_Names (S, Discard_Names (E)); | |
8636 | Set_Suppress_Value_Tracking_On_Call | |
8637 | (S, Suppress_Value_Tracking_On_Call (E)); | |
8638 | Set_Categorization_From_Scope (E => S, Scop => E); | |
8639 | end if; | |
8640 | end if; | |
fab2daeb AC |
8641 | |
8642 | if Is_Child_Unit (S) | |
8643 | and then Present (E) | |
8644 | and then Ekind_In (E, E_Package, E_Generic_Package) | |
8645 | and then | |
8646 | Nkind (Parent (Unit_Declaration_Node (E))) = N_Compilation_Unit | |
8647 | then | |
8648 | declare | |
8649 | Aux : constant Node_Id := | |
4adf3c50 | 8650 | Aux_Decls_Node (Parent (Unit_Declaration_Node (E))); |
fab2daeb AC |
8651 | begin |
8652 | if Present (Default_Storage_Pool (Aux)) then | |
8653 | Default_Pool := Default_Storage_Pool (Aux); | |
8654 | end if; | |
8655 | end; | |
8656 | end if; | |
fbe627af RD |
8657 | end Push_Scope; |
8658 | ||
996ae0b0 RK |
8659 | --------------------- |
8660 | -- Premature_Usage -- | |
8661 | --------------------- | |
8662 | ||
8663 | procedure Premature_Usage (N : Node_Id) is | |
fbf5a39b | 8664 | Kind : constant Node_Kind := Nkind (Parent (Entity (N))); |
996ae0b0 RK |
8665 | E : Entity_Id := Entity (N); |
8666 | ||
8667 | begin | |
8668 | -- Within an instance, the analysis of the actual for a formal object | |
16ca248a ES |
8669 | -- does not see the name of the object itself. This is significant only |
8670 | -- if the object is an aggregate, where its analysis does not do any | |
8671 | -- name resolution on component associations. (see 4717-008). In such a | |
8672 | -- case, look for the visible homonym on the chain. | |
996ae0b0 | 8673 | |
ac7d724d | 8674 | if In_Instance and then Present (Homonym (E)) then |
996ae0b0 | 8675 | E := Homonym (E); |
ac7d724d | 8676 | while Present (E) and then not In_Open_Scopes (Scope (E)) loop |
996ae0b0 RK |
8677 | E := Homonym (E); |
8678 | end loop; | |
8679 | ||
8680 | if Present (E) then | |
8681 | Set_Entity (N, E); | |
8682 | Set_Etype (N, Etype (E)); | |
8683 | return; | |
8684 | end if; | |
8685 | end if; | |
8686 | ||
8687 | if Kind = N_Component_Declaration then | |
8688 | Error_Msg_N | |
8689 | ("component&! cannot be used before end of record declaration", N); | |
8690 | ||
8691 | elsif Kind = N_Parameter_Specification then | |
8692 | Error_Msg_N | |
8693 | ("formal parameter&! cannot be used before end of specification", | |
8694 | N); | |
8695 | ||
8696 | elsif Kind = N_Discriminant_Specification then | |
8697 | Error_Msg_N | |
8698 | ("discriminant&! cannot be used before end of discriminant part", | |
8699 | N); | |
8700 | ||
8701 | elsif Kind = N_Procedure_Specification | |
8702 | or else Kind = N_Function_Specification | |
8703 | then | |
8704 | Error_Msg_N | |
8705 | ("subprogram&! cannot be used before end of its declaration", | |
8706 | N); | |
90067a15 ES |
8707 | |
8708 | elsif Kind = N_Full_Type_Declaration then | |
8709 | Error_Msg_N | |
8710 | ("type& cannot be used before end of its declaration!", N); | |
8711 | ||
996ae0b0 RK |
8712 | else |
8713 | Error_Msg_N | |
8714 | ("object& cannot be used before end of its declaration!", N); | |
42fe76e0 AC |
8715 | |
8716 | -- If the premature reference appears as the expression in its own | |
8717 | -- declaration, rewrite it to prevent compiler loops in subsequent | |
8718 | -- uses of this mangled declaration in address clauses. | |
8719 | ||
8720 | if Nkind (Parent (N)) = N_Object_Declaration then | |
8721 | Set_Entity (N, Any_Id); | |
8722 | end if; | |
996ae0b0 RK |
8723 | end if; |
8724 | end Premature_Usage; | |
8725 | ||
8726 | ------------------------ | |
8727 | -- Present_System_Aux -- | |
8728 | ------------------------ | |
8729 | ||
8730 | function Present_System_Aux (N : Node_Id := Empty) return Boolean is | |
8731 | Loc : Source_Ptr; | |
fbe627af | 8732 | Aux_Name : Unit_Name_Type; |
996ae0b0 RK |
8733 | Unum : Unit_Number_Type; |
8734 | Withn : Node_Id; | |
8735 | With_Sys : Node_Id; | |
8736 | The_Unit : Node_Id; | |
8737 | ||
8738 | function Find_System (C_Unit : Node_Id) return Entity_Id; | |
16ca248a | 8739 | -- Scan context clause of compilation unit to find with_clause |
996ae0b0 RK |
8740 | -- for System. |
8741 | ||
2e071734 AC |
8742 | ----------------- |
8743 | -- Find_System -- | |
8744 | ----------------- | |
8745 | ||
996ae0b0 RK |
8746 | function Find_System (C_Unit : Node_Id) return Entity_Id is |
8747 | With_Clause : Node_Id; | |
8748 | ||
8749 | begin | |
8750 | With_Clause := First (Context_Items (C_Unit)); | |
996ae0b0 RK |
8751 | while Present (With_Clause) loop |
8752 | if (Nkind (With_Clause) = N_With_Clause | |
8753 | and then Chars (Name (With_Clause)) = Name_System) | |
8754 | and then Comes_From_Source (With_Clause) | |
8755 | then | |
8756 | return With_Clause; | |
8757 | end if; | |
8758 | ||
8759 | Next (With_Clause); | |
8760 | end loop; | |
8761 | ||
8762 | return Empty; | |
8763 | end Find_System; | |
8764 | ||
8765 | -- Start of processing for Present_System_Aux | |
8766 | ||
8767 | begin | |
bc41faa2 | 8768 | -- The child unit may have been loaded and analyzed already |
996ae0b0 RK |
8769 | |
8770 | if Present (System_Aux_Id) then | |
8771 | return True; | |
8772 | ||
8773 | -- If no previous pragma for System.Aux, nothing to load | |
8774 | ||
fbf5a39b | 8775 | elsif No (System_Extend_Unit) then |
996ae0b0 RK |
8776 | return False; |
8777 | ||
8778 | -- Use the unit name given in the pragma to retrieve the unit. | |
8779 | -- Verify that System itself appears in the context clause of the | |
8780 | -- current compilation. If System is not present, an error will | |
8781 | -- have been reported already. | |
8782 | ||
8783 | else | |
8784 | With_Sys := Find_System (Cunit (Current_Sem_Unit)); | |
8785 | ||
8786 | The_Unit := Unit (Cunit (Current_Sem_Unit)); | |
8787 | ||
8788 | if No (With_Sys) | |
294ccb21 RD |
8789 | and then |
8790 | (Nkind (The_Unit) = N_Package_Body | |
ac7d724d ES |
8791 | or else (Nkind (The_Unit) = N_Subprogram_Body |
8792 | and then not Acts_As_Spec (Cunit (Current_Sem_Unit)))) | |
996ae0b0 RK |
8793 | then |
8794 | With_Sys := Find_System (Library_Unit (Cunit (Current_Sem_Unit))); | |
8795 | end if; | |
8796 | ||
ac7d724d ES |
8797 | if No (With_Sys) and then Present (N) then |
8798 | ||
996ae0b0 RK |
8799 | -- If we are compiling a subunit, we need to examine its |
8800 | -- context as well (Current_Sem_Unit is the parent unit); | |
8801 | ||
8802 | The_Unit := Parent (N); | |
996ae0b0 RK |
8803 | while Nkind (The_Unit) /= N_Compilation_Unit loop |
8804 | The_Unit := Parent (The_Unit); | |
8805 | end loop; | |
8806 | ||
8807 | if Nkind (Unit (The_Unit)) = N_Subunit then | |
8808 | With_Sys := Find_System (The_Unit); | |
8809 | end if; | |
8810 | end if; | |
8811 | ||
8812 | if No (With_Sys) then | |
8813 | return False; | |
8814 | end if; | |
8815 | ||
8816 | Loc := Sloc (With_Sys); | |
fbf5a39b | 8817 | Get_Name_String (Chars (Expression (System_Extend_Unit))); |
996ae0b0 RK |
8818 | Name_Buffer (8 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len); |
8819 | Name_Buffer (1 .. 7) := "system."; | |
8820 | Name_Buffer (Name_Len + 8) := '%'; | |
8821 | Name_Buffer (Name_Len + 9) := 's'; | |
8822 | Name_Len := Name_Len + 9; | |
8823 | Aux_Name := Name_Find; | |
8824 | ||
8825 | Unum := | |
8826 | Load_Unit | |
8827 | (Load_Name => Aux_Name, | |
8828 | Required => False, | |
8829 | Subunit => False, | |
8830 | Error_Node => With_Sys); | |
8831 | ||
8832 | if Unum /= No_Unit then | |
8833 | Semantics (Cunit (Unum)); | |
8834 | System_Aux_Id := | |
8835 | Defining_Entity (Specification (Unit (Cunit (Unum)))); | |
8836 | ||
16ca248a ES |
8837 | Withn := |
8838 | Make_With_Clause (Loc, | |
8839 | Name => | |
8840 | Make_Expanded_Name (Loc, | |
8841 | Chars => Chars (System_Aux_Id), | |
e4494292 RD |
8842 | Prefix => New_Occurrence_Of (Scope (System_Aux_Id), Loc), |
8843 | Selector_Name => New_Occurrence_Of (System_Aux_Id, Loc))); | |
996ae0b0 RK |
8844 | |
8845 | Set_Entity (Name (Withn), System_Aux_Id); | |
8846 | ||
16ca248a ES |
8847 | Set_Library_Unit (Withn, Cunit (Unum)); |
8848 | Set_Corresponding_Spec (Withn, System_Aux_Id); | |
8849 | Set_First_Name (Withn, True); | |
8850 | Set_Implicit_With (Withn, True); | |
996ae0b0 RK |
8851 | |
8852 | Insert_After (With_Sys, Withn); | |
8853 | Mark_Rewrite_Insertion (Withn); | |
8854 | Set_Context_Installed (Withn); | |
8855 | ||
8856 | return True; | |
8857 | ||
8858 | -- Here if unit load failed | |
8859 | ||
8860 | else | |
8861 | Error_Msg_Name_1 := Name_System; | |
fbf5a39b | 8862 | Error_Msg_Name_2 := Chars (Expression (System_Extend_Unit)); |
996ae0b0 RK |
8863 | Error_Msg_N |
8864 | ("extension package `%.%` does not exist", | |
fbf5a39b | 8865 | Opt.System_Extend_Unit); |
996ae0b0 RK |
8866 | return False; |
8867 | end if; | |
8868 | end if; | |
8869 | end Present_System_Aux; | |
8870 | ||
8871 | ------------------------- | |
8872 | -- Restore_Scope_Stack -- | |
8873 | ------------------------- | |
8874 | ||
e530a2d1 AC |
8875 | procedure Restore_Scope_Stack |
8876 | (List : Elist_Id; | |
8877 | Handle_Use : Boolean := True) | |
8878 | is | |
8879 | SS_Last : constant Int := Scope_Stack.Last; | |
8880 | Elmt : Elmt_Id; | |
996ae0b0 RK |
8881 | |
8882 | begin | |
9e40f163 AC |
8883 | -- Restore visibility of previous scope stack, if any, using the list |
8884 | -- we saved (we use Remove, since this list will not be used again). | |
996ae0b0 | 8885 | |
9e40f163 AC |
8886 | loop |
8887 | Elmt := Last_Elmt (List); | |
8888 | exit when Elmt = No_Elmt; | |
e530a2d1 | 8889 | Set_Is_Immediately_Visible (Node (Elmt)); |
9e40f163 | 8890 | Remove_Last_Elmt (List); |
996ae0b0 | 8891 | end loop; |
fbf5a39b | 8892 | |
9e40f163 AC |
8893 | -- Restore use clauses |
8894 | ||
fbf5a39b AC |
8895 | if SS_Last >= Scope_Stack.First |
8896 | and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard | |
ecad994d | 8897 | and then Handle_Use |
fbf5a39b | 8898 | then |
7f5e671b PMR |
8899 | Install_Use_Clauses |
8900 | (Scope_Stack.Table (SS_Last).First_Use_Clause, | |
8901 | Force_Installation => True); | |
fbf5a39b | 8902 | end if; |
996ae0b0 RK |
8903 | end Restore_Scope_Stack; |
8904 | ||
8905 | ---------------------- | |
8906 | -- Save_Scope_Stack -- | |
8907 | ---------------------- | |
8908 | ||
9e40f163 AC |
8909 | -- Save_Scope_Stack/Restore_Scope_Stack were originally designed to avoid |
8910 | -- consuming any memory. That is, Save_Scope_Stack took care of removing | |
8911 | -- from immediate visibility entities and Restore_Scope_Stack took care | |
8912 | -- of restoring their visibility analyzing the context of each entity. The | |
8913 | -- problem of such approach is that it was fragile and caused unexpected | |
8914 | -- visibility problems, and indeed one test was found where there was a | |
8915 | -- real problem. | |
8916 | ||
8917 | -- Furthermore, the following experiment was carried out: | |
8918 | ||
8919 | -- - Save_Scope_Stack was modified to store in an Elist1 all those | |
8920 | -- entities whose attribute Is_Immediately_Visible is modified | |
8921 | -- from True to False. | |
8922 | ||
8923 | -- - Restore_Scope_Stack was modified to store in another Elist2 | |
8924 | -- all the entities whose attribute Is_Immediately_Visible is | |
8925 | -- modified from False to True. | |
8926 | ||
8927 | -- - Extra code was added to verify that all the elements of Elist1 | |
8928 | -- are found in Elist2 | |
8929 | ||
a35017dc | 8930 | -- This test shows that there may be more occurrences of this problem which |
9e40f163 AC |
8931 | -- have not yet been detected. As a result, we replaced that approach by |
8932 | -- the current one in which Save_Scope_Stack returns the list of entities | |
a35017dc | 8933 | -- whose visibility is changed, and that list is passed to Restore_Scope_ |
9e40f163 AC |
8934 | -- Stack to undo that change. This approach is simpler and safer, although |
8935 | -- it consumes more memory. | |
8936 | ||
e530a2d1 AC |
8937 | function Save_Scope_Stack (Handle_Use : Boolean := True) return Elist_Id is |
8938 | Result : constant Elist_Id := New_Elmt_List; | |
996ae0b0 RK |
8939 | E : Entity_Id; |
8940 | S : Entity_Id; | |
8941 | SS_Last : constant Int := Scope_Stack.Last; | |
8942 | ||
e530a2d1 AC |
8943 | procedure Remove_From_Visibility (E : Entity_Id); |
8944 | -- If E is immediately visible then append it to the result and remove | |
85f6a831 RD |
8945 | -- it temporarily from visibility. |
8946 | ||
8947 | ---------------------------- | |
8948 | -- Remove_From_Visibility -- | |
8949 | ---------------------------- | |
8950 | ||
e530a2d1 AC |
8951 | procedure Remove_From_Visibility (E : Entity_Id) is |
8952 | begin | |
8953 | if Is_Immediately_Visible (E) then | |
8954 | Append_Elmt (E, Result); | |
8955 | Set_Is_Immediately_Visible (E, False); | |
8956 | end if; | |
8957 | end Remove_From_Visibility; | |
8958 | ||
85f6a831 RD |
8959 | -- Start of processing for Save_Scope_Stack |
8960 | ||
996ae0b0 RK |
8961 | begin |
8962 | if SS_Last >= Scope_Stack.First | |
8963 | and then Scope_Stack.Table (SS_Last).Entity /= Standard_Standard | |
8964 | then | |
ecad994d AC |
8965 | if Handle_Use then |
8966 | End_Use_Clauses (Scope_Stack.Table (SS_Last).First_Use_Clause); | |
8967 | end if; | |
fbf5a39b | 8968 | |
16ca248a ES |
8969 | -- If the call is from within a compilation unit, as when called from |
8970 | -- Rtsfind, make current entries in scope stack invisible while we | |
8971 | -- analyze the new unit. | |
996ae0b0 RK |
8972 | |
8973 | for J in reverse 0 .. SS_Last loop | |
8974 | exit when Scope_Stack.Table (J).Entity = Standard_Standard | |
8975 | or else No (Scope_Stack.Table (J).Entity); | |
8976 | ||
8977 | S := Scope_Stack.Table (J).Entity; | |
e530a2d1 AC |
8978 | |
8979 | Remove_From_Visibility (S); | |
996ae0b0 | 8980 | |
16ca248a | 8981 | E := First_Entity (S); |
996ae0b0 | 8982 | while Present (E) loop |
e530a2d1 | 8983 | Remove_From_Visibility (E); |
996ae0b0 RK |
8984 | Next_Entity (E); |
8985 | end loop; | |
8986 | end loop; | |
8987 | ||
8988 | end if; | |
e530a2d1 AC |
8989 | |
8990 | return Result; | |
996ae0b0 RK |
8991 | end Save_Scope_Stack; |
8992 | ||
8993 | ------------- | |
8994 | -- Set_Use -- | |
8995 | ------------- | |
8996 | ||
8997 | procedure Set_Use (L : List_Id) is | |
851e9f19 | 8998 | Decl : Node_Id; |
996ae0b0 RK |
8999 | |
9000 | begin | |
9001 | if Present (L) then | |
9002 | Decl := First (L); | |
996ae0b0 RK |
9003 | while Present (Decl) loop |
9004 | if Nkind (Decl) = N_Use_Package_Clause then | |
9005 | Chain_Use_Clause (Decl); | |
851e9f19 PMR |
9006 | Use_One_Package (Decl, Name (Decl)); |
9007 | ||
9008 | elsif Nkind (Decl) = N_Use_Type_Clause then | |
9009 | Chain_Use_Clause (Decl); | |
9010 | Use_One_Type (Subtype_Mark (Decl)); | |
9011 | ||
9012 | end if; | |
9013 | ||
9014 | Next (Decl); | |
9015 | end loop; | |
9016 | end if; | |
9017 | end Set_Use; | |
9018 | ||
9019 | ----------------------------- | |
9020 | -- Update_Use_Clause_Chain -- | |
9021 | ----------------------------- | |
9022 | ||
9023 | procedure Update_Use_Clause_Chain is | |
851e9f19 PMR |
9024 | procedure Update_Chain_In_Scope (Level : Int); |
9025 | -- Iterate through one level in the scope stack verifying each use-type | |
9026 | -- clause within said level is used then reset the Current_Use_Clause | |
9027 | -- to a redundant use clause outside of the current ending scope if such | |
9028 | -- a clause exists. | |
9029 | ||
9030 | --------------------------- | |
9031 | -- Update_Chain_In_Scope -- | |
9032 | --------------------------- | |
9033 | ||
9034 | procedure Update_Chain_In_Scope (Level : Int) is | |
9035 | Curr : Node_Id; | |
9036 | N : Node_Id; | |
9037 | ||
9038 | begin | |
9039 | -- Loop through all use clauses within the scope dictated by Level | |
9040 | ||
9041 | Curr := Scope_Stack.Table (Level).First_Use_Clause; | |
9042 | while Present (Curr) loop | |
9043 | ||
9044 | -- Retrieve the subtype mark or name within the current current | |
9045 | -- use clause. | |
9046 | ||
9047 | if Nkind (Curr) = N_Use_Type_Clause then | |
9048 | N := Subtype_Mark (Curr); | |
9049 | else | |
9050 | N := Name (Curr); | |
9051 | end if; | |
9052 | ||
9053 | -- If warnings for unreferenced entities are enabled and the | |
9054 | -- current use clause has not been marked effective. | |
996ae0b0 | 9055 | |
851e9f19 PMR |
9056 | if Check_Unreferenced |
9057 | and then Comes_From_Source (Curr) | |
9058 | and then not Is_Effective_Use_Clause (Curr) | |
9059 | and then not In_Instance | |
9060 | then | |
851e9f19 PMR |
9061 | -- We are dealing with a potentially unused use_package_clause |
9062 | ||
9063 | if Nkind (Curr) = N_Use_Package_Clause then | |
996ae0b0 | 9064 | |
851e9f19 PMR |
9065 | -- Renamings and formal subprograms may cause the associated |
9066 | -- to be marked as effective instead of the original. | |
9067 | ||
9068 | if not (Present (Associated_Node (N)) | |
9069 | and then Present | |
7f5e671b PMR |
9070 | (Current_Use_Clause |
9071 | (Associated_Node (N))) | |
851e9f19 | 9072 | and then Is_Effective_Use_Clause |
7f5e671b PMR |
9073 | (Current_Use_Clause |
9074 | (Associated_Node (N)))) | |
996ae0b0 | 9075 | then |
851e9f19 | 9076 | Error_Msg_Node_1 := Entity (N); |
7f5e671b | 9077 | Error_Msg_NE |
8f8f531f | 9078 | ("use clause for package & has no effect?u?", |
7f5e671b | 9079 | Curr, Entity (N)); |
996ae0b0 RK |
9080 | end if; |
9081 | ||
851e9f19 | 9082 | -- We are dealing with an unused use_type_clause |
996ae0b0 | 9083 | |
851e9f19 PMR |
9084 | else |
9085 | Error_Msg_Node_1 := Etype (N); | |
7f5e671b | 9086 | Error_Msg_NE |
8f8f531f | 9087 | ("use clause for } has no effect?u?", Curr, Etype (N)); |
851e9f19 PMR |
9088 | end if; |
9089 | end if; | |
996ae0b0 | 9090 | |
851e9f19 PMR |
9091 | -- Verify that we haven't already processed a redundant |
9092 | -- use_type_clause within the same scope before we move the | |
9093 | -- current use clause up to a previous one for type T. | |
996ae0b0 | 9094 | |
851e9f19 PMR |
9095 | if Present (Prev_Use_Clause (Curr)) then |
9096 | Set_Current_Use_Clause (Entity (N), Prev_Use_Clause (Curr)); | |
996ae0b0 RK |
9097 | end if; |
9098 | ||
851e9f19 | 9099 | Curr := Next_Use_Clause (Curr); |
996ae0b0 | 9100 | end loop; |
851e9f19 PMR |
9101 | end Update_Chain_In_Scope; |
9102 | ||
9103 | -- Start of processing for Update_Use_Clause_Chain | |
9104 | ||
9105 | begin | |
9106 | Update_Chain_In_Scope (Scope_Stack.Last); | |
9107 | ||
9108 | -- Deal with use clauses within the context area if the current | |
9109 | -- scope is a compilation unit. | |
9110 | ||
c840bf9b PMR |
9111 | if Is_Compilation_Unit (Current_Scope) |
9112 | and then Sloc (Scope_Stack.Table | |
9113 | (Scope_Stack.Last - 1).Entity) = Standard_Location | |
9114 | then | |
851e9f19 | 9115 | Update_Chain_In_Scope (Scope_Stack.Last - 1); |
996ae0b0 | 9116 | end if; |
851e9f19 | 9117 | end Update_Use_Clause_Chain; |
996ae0b0 RK |
9118 | |
9119 | --------------------- | |
9120 | -- Use_One_Package -- | |
9121 | --------------------- | |
9122 | ||
851e9f19 PMR |
9123 | procedure Use_One_Package |
9124 | (N : Node_Id; | |
9125 | Pack_Name : Entity_Id := Empty; | |
9126 | Force : Boolean := False) | |
9127 | is | |
851e9f19 PMR |
9128 | procedure Note_Redundant_Use (Clause : Node_Id); |
9129 | -- Mark the name in a use clause as redundant if the corresponding | |
9130 | -- entity is already use-visible. Emit a warning if the use clause comes | |
9131 | -- from source and the proper warnings are enabled. | |
9132 | ||
9133 | ------------------------ | |
9134 | -- Note_Redundant_Use -- | |
9135 | ------------------------ | |
9136 | ||
9137 | procedure Note_Redundant_Use (Clause : Node_Id) is | |
851e9f19 | 9138 | Decl : constant Node_Id := Parent (Clause); |
7f5e671b | 9139 | Pack_Name : constant Entity_Id := Entity (Clause); |
851e9f19 PMR |
9140 | |
9141 | Cur_Use : Node_Id := Current_Use_Clause (Pack_Name); | |
9142 | Prev_Use : Node_Id := Empty; | |
9143 | Redundant : Node_Id := Empty; | |
9144 | -- The Use_Clause which is actually redundant. In the simplest case | |
9145 | -- it is Pack itself, but when we compile a body we install its | |
9146 | -- context before that of its spec, in which case it is the | |
9147 | -- use_clause in the spec that will appear to be redundant, and we | |
9148 | -- want the warning to be placed on the body. Similar complications | |
9149 | -- appear when the redundancy is between a child unit and one of its | |
9150 | -- ancestors. | |
9151 | ||
9152 | begin | |
9153 | -- Could be renamed... | |
9154 | ||
9155 | if No (Cur_Use) then | |
9156 | Cur_Use := Current_Use_Clause (Renamed_Entity (Pack_Name)); | |
9157 | end if; | |
9158 | ||
9159 | Set_Redundant_Use (Clause, True); | |
9160 | ||
9161 | if not Comes_From_Source (Clause) | |
9162 | or else In_Instance | |
9163 | or else not Warn_On_Redundant_Constructs | |
9164 | then | |
9165 | return; | |
9166 | end if; | |
9167 | ||
9168 | if not Is_Compilation_Unit (Current_Scope) then | |
9169 | ||
9170 | -- If the use_clause is in an inner scope, it is made redundant by | |
9171 | -- some clause in the current context, with one exception: If we | |
9172 | -- are compiling a nested package body, and the use_clause comes | |
9173 | -- from then corresponding spec, the clause is not necessarily | |
9174 | -- fully redundant, so we should not warn. If a warning was | |
9175 | -- warranted, it would have been given when the spec was | |
9176 | -- processed. | |
9177 | ||
9178 | if Nkind (Parent (Decl)) = N_Package_Specification then | |
9179 | declare | |
9180 | Package_Spec_Entity : constant Entity_Id := | |
9181 | Defining_Unit_Name (Parent (Decl)); | |
9182 | begin | |
9183 | if In_Package_Body (Package_Spec_Entity) then | |
9184 | return; | |
9185 | end if; | |
9186 | end; | |
9187 | end if; | |
9188 | ||
9189 | Redundant := Clause; | |
9190 | Prev_Use := Cur_Use; | |
9191 | ||
9192 | elsif Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body then | |
9193 | declare | |
9194 | Cur_Unit : constant Unit_Number_Type := | |
7f5e671b | 9195 | Get_Source_Unit (Cur_Use); |
851e9f19 | 9196 | New_Unit : constant Unit_Number_Type := |
7f5e671b PMR |
9197 | Get_Source_Unit (Clause); |
9198 | ||
9199 | Scop : Entity_Id; | |
851e9f19 PMR |
9200 | |
9201 | begin | |
9202 | if Cur_Unit = New_Unit then | |
9203 | ||
9204 | -- Redundant clause in same body | |
9205 | ||
9206 | Redundant := Clause; | |
9207 | Prev_Use := Cur_Use; | |
9208 | ||
9209 | elsif Cur_Unit = Current_Sem_Unit then | |
9210 | ||
9211 | -- If the new clause is not in the current unit it has been | |
9212 | -- analyzed first, and it makes the other one redundant. | |
9213 | -- However, if the new clause appears in a subunit, Cur_Unit | |
9214 | -- is still the parent, and in that case the redundant one | |
9215 | -- is the one appearing in the subunit. | |
9216 | ||
9217 | if Nkind (Unit (Cunit (New_Unit))) = N_Subunit then | |
9218 | Redundant := Clause; | |
9219 | Prev_Use := Cur_Use; | |
9220 | ||
7f5e671b PMR |
9221 | -- Most common case: redundant clause in body, original |
9222 | -- clause in spec. Current scope is spec entity. | |
851e9f19 PMR |
9223 | |
9224 | elsif Current_Scope = Cunit_Entity (Current_Sem_Unit) then | |
9225 | Redundant := Cur_Use; | |
9226 | Prev_Use := Clause; | |
9227 | ||
9228 | else | |
9229 | -- The new clause may appear in an unrelated unit, when | |
9230 | -- the parents of a generic are being installed prior to | |
9231 | -- instantiation. In this case there must be no warning. | |
9232 | -- We detect this case by checking whether the current | |
9233 | -- top of the stack is related to the current | |
9234 | -- compilation. | |
9235 | ||
9236 | Scop := Current_Scope; | |
9237 | while Present (Scop) | |
9238 | and then Scop /= Standard_Standard | |
9239 | loop | |
9240 | if Is_Compilation_Unit (Scop) | |
9241 | and then not Is_Child_Unit (Scop) | |
9242 | then | |
9243 | return; | |
9244 | ||
9245 | elsif Scop = Cunit_Entity (Current_Sem_Unit) then | |
9246 | exit; | |
9247 | end if; | |
9248 | ||
9249 | Scop := Scope (Scop); | |
9250 | end loop; | |
9251 | ||
9252 | Redundant := Cur_Use; | |
9253 | Prev_Use := Clause; | |
9254 | end if; | |
9255 | ||
9256 | elsif New_Unit = Current_Sem_Unit then | |
9257 | Redundant := Clause; | |
9258 | Prev_Use := Cur_Use; | |
9259 | ||
9260 | else | |
9261 | -- Neither is the current unit, so they appear in parent or | |
9262 | -- sibling units. Warning will be emitted elsewhere. | |
9263 | ||
9264 | return; | |
9265 | end if; | |
9266 | end; | |
9267 | ||
9268 | elsif Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Declaration | |
9269 | and then Present (Parent_Spec (Unit (Cunit (Current_Sem_Unit)))) | |
9270 | then | |
9271 | -- Use_clause is in child unit of current unit, and the child unit | |
9272 | -- appears in the context of the body of the parent, so it has | |
9273 | -- been installed first, even though it is the redundant one. | |
9274 | -- Depending on their placement in the context, the visible or the | |
9275 | -- private parts of the two units, either might appear as | |
9276 | -- redundant, but the message has to be on the current unit. | |
9277 | ||
9278 | if Get_Source_Unit (Cur_Use) = Current_Sem_Unit then | |
9279 | Redundant := Cur_Use; | |
9280 | Prev_Use := Clause; | |
9281 | else | |
9282 | Redundant := Clause; | |
9283 | Prev_Use := Cur_Use; | |
9284 | end if; | |
9285 | ||
9286 | -- If the new use clause appears in the private part of a parent | |
9287 | -- unit it may appear to be redundant w.r.t. a use clause in a | |
9288 | -- child unit, but the previous use clause was needed in the | |
9289 | -- visible part of the child, and no warning should be emitted. | |
9290 | ||
9291 | if Nkind (Parent (Decl)) = N_Package_Specification | |
7f5e671b PMR |
9292 | and then List_Containing (Decl) = |
9293 | Private_Declarations (Parent (Decl)) | |
851e9f19 PMR |
9294 | then |
9295 | declare | |
9296 | Par : constant Entity_Id := Defining_Entity (Parent (Decl)); | |
9297 | Spec : constant Node_Id := | |
9298 | Specification (Unit (Cunit (Current_Sem_Unit))); | |
9299 | ||
9300 | begin | |
9301 | if Is_Compilation_Unit (Par) | |
9302 | and then Par /= Cunit_Entity (Current_Sem_Unit) | |
9303 | and then Parent (Cur_Use) = Spec | |
7f5e671b PMR |
9304 | and then List_Containing (Cur_Use) = |
9305 | Visible_Declarations (Spec) | |
851e9f19 PMR |
9306 | then |
9307 | return; | |
9308 | end if; | |
9309 | end; | |
9310 | end if; | |
9311 | ||
7f5e671b PMR |
9312 | -- Finally, if the current use clause is in the context then the |
9313 | -- clause is redundant when it is nested within the unit. | |
851e9f19 PMR |
9314 | |
9315 | elsif Nkind (Parent (Cur_Use)) = N_Compilation_Unit | |
9316 | and then Nkind (Parent (Parent (Clause))) /= N_Compilation_Unit | |
9317 | and then Get_Source_Unit (Cur_Use) = Get_Source_Unit (Clause) | |
9318 | then | |
9319 | Redundant := Clause; | |
9320 | Prev_Use := Cur_Use; | |
9321 | ||
9322 | end if; | |
9323 | ||
5b1265cc | 9324 | if Present (Redundant) and then Parent (Redundant) /= Prev_Use then |
7f5e671b | 9325 | |
851e9f19 PMR |
9326 | -- Make sure we are looking at most-descendant use_package_clause |
9327 | -- by traversing the chain with Find_Most_Prev and then verifying | |
9328 | -- there is no scope manipulation via Most_Descendant_Use_Clause. | |
9329 | ||
9330 | if Nkind (Prev_Use) = N_Use_Package_Clause | |
9331 | and then | |
9332 | (Nkind (Parent (Prev_Use)) /= N_Compilation_Unit | |
9333 | or else Most_Descendant_Use_Clause | |
7f5e671b | 9334 | (Prev_Use, Find_Most_Prev (Prev_Use)) /= Prev_Use) |
851e9f19 PMR |
9335 | then |
9336 | Prev_Use := Find_Most_Prev (Prev_Use); | |
9337 | end if; | |
9338 | ||
9339 | Error_Msg_Sloc := Sloc (Prev_Use); | |
9340 | Error_Msg_NE -- CODEFIX | |
f192ca5e | 9341 | ("& is already use-visible through previous use_clause #??", |
851e9f19 PMR |
9342 | Redundant, Pack_Name); |
9343 | end if; | |
9344 | end Note_Redundant_Use; | |
9345 | ||
9346 | -- Local variables | |
9347 | ||
7f5e671b | 9348 | Current_Instance : Entity_Id := Empty; |
996ae0b0 | 9349 | Id : Entity_Id; |
7f5e671b | 9350 | P : Entity_Id; |
996ae0b0 | 9351 | Prev : Entity_Id; |
9bc856dd | 9352 | Private_With_OK : Boolean := False; |
7f5e671b | 9353 | Real_P : Entity_Id; |
851e9f19 PMR |
9354 | |
9355 | -- Start of processing for Use_One_Package | |
996ae0b0 RK |
9356 | |
9357 | begin | |
851e9f19 PMR |
9358 | -- Use_One_Package may have been called recursively to handle an |
9359 | -- implicit use for a auxiliary system package, so set P accordingly | |
9360 | -- and skip redundancy checks. | |
9361 | ||
9362 | if No (Pack_Name) and then Present_System_Aux (N) then | |
9363 | P := System_Aux_Id; | |
9364 | ||
9365 | -- Check for redundant use_package_clauses | |
9366 | ||
9367 | else | |
9368 | -- Ignore cases where we are dealing with a non user defined package | |
9369 | -- like Standard_Standard or something other than a valid package. | |
9370 | ||
9371 | if not Is_Entity_Name (Pack_Name) | |
9372 | or else No (Entity (Pack_Name)) | |
9373 | or else Ekind (Entity (Pack_Name)) /= E_Package | |
9374 | then | |
9375 | return; | |
9376 | end if; | |
9377 | ||
9378 | -- When a renaming exists we must check it for redundancy. The | |
9379 | -- original package would have already been seen at this point. | |
9380 | ||
9381 | if Present (Renamed_Object (Entity (Pack_Name))) then | |
9382 | P := Renamed_Object (Entity (Pack_Name)); | |
9383 | else | |
9384 | P := Entity (Pack_Name); | |
9385 | end if; | |
9386 | ||
9387 | -- Check for redundant clauses then set the current use clause for | |
9388 | -- P if were are not "forcing" an installation from a scope | |
9389 | -- reinstallation that is done throughout analysis for various | |
9390 | -- reasons. | |
9391 | ||
9392 | if In_Use (P) then | |
9393 | Note_Redundant_Use (Pack_Name); | |
7f5e671b | 9394 | |
851e9f19 PMR |
9395 | if not Force then |
9396 | Set_Current_Use_Clause (P, N); | |
9397 | end if; | |
7f5e671b | 9398 | |
851e9f19 PMR |
9399 | return; |
9400 | ||
9401 | -- Warn about detected redundant clauses | |
9402 | ||
9403 | elsif In_Open_Scopes (P) and not Force then | |
9404 | if Warn_On_Redundant_Constructs and then P = Current_Scope then | |
9405 | Error_Msg_NE -- CODEFIX | |
9406 | ("& is already use-visible within itself?r?", | |
9407 | Pack_Name, P); | |
9408 | end if; | |
7f5e671b | 9409 | |
851e9f19 PMR |
9410 | return; |
9411 | end if; | |
9412 | ||
9413 | -- Set P back to the non-renamed package so that visiblilty of the | |
9414 | -- entities within the package can be properly set below. | |
9415 | ||
9416 | P := Entity (Pack_Name); | |
996ae0b0 RK |
9417 | end if; |
9418 | ||
9419 | Set_In_Use (P); | |
d4810530 | 9420 | Set_Current_Use_Clause (P, N); |
996ae0b0 | 9421 | |
0ab80019 | 9422 | -- Ada 2005 (AI-50217): Check restriction |
19f0526a | 9423 | |
7b56a91b | 9424 | if From_Limited_With (P) then |
657a9dd9 | 9425 | Error_Msg_N ("limited withed package cannot appear in use clause", N); |
996ae0b0 RK |
9426 | end if; |
9427 | ||
bc41faa2 | 9428 | -- Find enclosing instance, if any |
996ae0b0 RK |
9429 | |
9430 | if In_Instance then | |
9431 | Current_Instance := Current_Scope; | |
996ae0b0 RK |
9432 | while not Is_Generic_Instance (Current_Instance) loop |
9433 | Current_Instance := Scope (Current_Instance); | |
9434 | end loop; | |
9435 | ||
9436 | if No (Hidden_By_Use_Clause (N)) then | |
9437 | Set_Hidden_By_Use_Clause (N, New_Elmt_List); | |
9438 | end if; | |
9439 | end if; | |
9440 | ||
7f5e671b PMR |
9441 | -- If unit is a package renaming, indicate that the renamed package is |
9442 | -- also in use (the flags on both entities must remain consistent, and a | |
9443 | -- subsequent use of either of them should be recognized as redundant). | |
996ae0b0 RK |
9444 | |
9445 | if Present (Renamed_Object (P)) then | |
9446 | Set_In_Use (Renamed_Object (P)); | |
d4810530 | 9447 | Set_Current_Use_Clause (Renamed_Object (P), N); |
996ae0b0 RK |
9448 | Real_P := Renamed_Object (P); |
9449 | else | |
9450 | Real_P := P; | |
9451 | end if; | |
9452 | ||
0ab80019 | 9453 | -- Ada 2005 (AI-262): Check the use_clause of a private withed package |
9bc856dd AC |
9454 | -- found in the private part of a package specification |
9455 | ||
9456 | if In_Private_Part (Current_Scope) | |
9457 | and then Has_Private_With (P) | |
9458 | and then Is_Child_Unit (Current_Scope) | |
9459 | and then Is_Child_Unit (P) | |
9460 | and then Is_Ancestor_Package (Scope (Current_Scope), P) | |
9461 | then | |
9462 | Private_With_OK := True; | |
9463 | end if; | |
9464 | ||
996ae0b0 RK |
9465 | -- Loop through entities in one package making them potentially |
9466 | -- use-visible. | |
9467 | ||
9468 | Id := First_Entity (P); | |
9469 | while Present (Id) | |
9bc856dd | 9470 | and then (Id /= First_Private_Entity (P) |
ac7d724d | 9471 | or else Private_With_OK) -- Ada 2005 (AI-262) |
996ae0b0 RK |
9472 | loop |
9473 | Prev := Current_Entity (Id); | |
996ae0b0 RK |
9474 | while Present (Prev) loop |
9475 | if Is_Immediately_Visible (Prev) | |
9476 | and then (not Is_Overloadable (Prev) | |
9477 | or else not Is_Overloadable (Id) | |
9478 | or else (Type_Conformant (Id, Prev))) | |
9479 | then | |
9480 | if No (Current_Instance) then | |
9481 | ||
9482 | -- Potentially use-visible entity remains hidden | |
9483 | ||
9484 | goto Next_Usable_Entity; | |
9485 | ||
16ca248a ES |
9486 | -- A use clause within an instance hides outer global entities, |
9487 | -- which are not used to resolve local entities in the | |
9488 | -- instance. Note that the predefined entities in Standard | |
9489 | -- could not have been hidden in the generic by a use clause, | |
9490 | -- and therefore remain visible. Other compilation units whose | |
9491 | -- entities appear in Standard must be hidden in an instance. | |
996ae0b0 RK |
9492 | |
9493 | -- To determine whether an entity is external to the instance | |
9494 | -- we compare the scope depth of its scope with that of the | |
9495 | -- current instance. However, a generic actual of a subprogram | |
9496 | -- instance is declared in the wrapper package but will not be | |
e074d476 AC |
9497 | -- hidden by a use-visible entity. similarly, an entity that is |
9498 | -- declared in an enclosing instance will not be hidden by an | |
9499 | -- an entity declared in a generic actual, which can only have | |
9500 | -- been use-visible in the generic and will not have hidden the | |
9501 | -- entity in the generic parent. | |
996ae0b0 | 9502 | |
82c80734 RD |
9503 | -- If Id is called Standard, the predefined package with the |
9504 | -- same name is in the homonym chain. It has to be ignored | |
9505 | -- because it has no defined scope (being the only entity in | |
9506 | -- the system with this mandated behavior). | |
9507 | ||
996ae0b0 | 9508 | elsif not Is_Hidden (Id) |
82c80734 | 9509 | and then Present (Scope (Prev)) |
996ae0b0 RK |
9510 | and then not Is_Wrapper_Package (Scope (Prev)) |
9511 | and then Scope_Depth (Scope (Prev)) < | |
9512 | Scope_Depth (Current_Instance) | |
9513 | and then (Scope (Prev) /= Standard_Standard | |
9514 | or else Sloc (Prev) > Standard_Location) | |
9515 | then | |
e074d476 AC |
9516 | if In_Open_Scopes (Scope (Prev)) |
9517 | and then Is_Generic_Instance (Scope (Prev)) | |
c94a0b9d AC |
9518 | and then Present (Associated_Formal_Package (P)) |
9519 | then | |
9520 | null; | |
9521 | ||
9522 | else | |
9523 | Set_Is_Potentially_Use_Visible (Id); | |
9524 | Set_Is_Immediately_Visible (Prev, False); | |
9525 | Append_Elmt (Prev, Hidden_By_Use_Clause (N)); | |
9526 | end if; | |
996ae0b0 RK |
9527 | end if; |
9528 | ||
16ca248a ES |
9529 | -- A user-defined operator is not use-visible if the predefined |
9530 | -- operator for the type is immediately visible, which is the case | |
9531 | -- if the type of the operand is in an open scope. This does not | |
9532 | -- apply to user-defined operators that have operands of different | |
9533 | -- types, because the predefined mixed mode operations (multiply | |
9534 | -- and divide) apply to universal types and do not hide anything. | |
996ae0b0 RK |
9535 | |
9536 | elsif Ekind (Prev) = E_Operator | |
9537 | and then Operator_Matches_Spec (Prev, Id) | |
9538 | and then In_Open_Scopes | |
ac7d724d | 9539 | (Scope (Base_Type (Etype (First_Formal (Id))))) |
996ae0b0 | 9540 | and then (No (Next_Formal (First_Formal (Id))) |
ac7d724d ES |
9541 | or else Etype (First_Formal (Id)) = |
9542 | Etype (Next_Formal (First_Formal (Id))) | |
996ae0b0 RK |
9543 | or else Chars (Prev) = Name_Op_Expon) |
9544 | then | |
9545 | goto Next_Usable_Entity; | |
e69614ad AC |
9546 | |
9547 | -- In an instance, two homonyms may become use_visible through the | |
9548 | -- actuals of distinct formal packages. In the generic, only the | |
9549 | -- current one would have been visible, so make the other one | |
9550 | -- not use_visible. | |
9551 | ||
9552 | elsif Present (Current_Instance) | |
9553 | and then Is_Potentially_Use_Visible (Prev) | |
9554 | and then not Is_Overloadable (Prev) | |
9555 | and then Scope (Id) /= Scope (Prev) | |
9556 | and then Used_As_Generic_Actual (Scope (Prev)) | |
9557 | and then Used_As_Generic_Actual (Scope (Id)) | |
30196a76 RD |
9558 | and then not In_Same_List (Current_Use_Clause (Scope (Prev)), |
9559 | Current_Use_Clause (Scope (Id))) | |
e69614ad AC |
9560 | then |
9561 | Set_Is_Potentially_Use_Visible (Prev, False); | |
9562 | Append_Elmt (Prev, Hidden_By_Use_Clause (N)); | |
996ae0b0 RK |
9563 | end if; |
9564 | ||
9565 | Prev := Homonym (Prev); | |
9566 | end loop; | |
9567 | ||
bc41faa2 | 9568 | -- On exit, we know entity is not hidden, unless it is private |
996ae0b0 RK |
9569 | |
9570 | if not Is_Hidden (Id) | |
ac7d724d | 9571 | and then ((not Is_Child_Unit (Id)) or else Is_Visible_Lib_Unit (Id)) |
996ae0b0 RK |
9572 | then |
9573 | Set_Is_Potentially_Use_Visible (Id); | |
9574 | ||
ac7d724d | 9575 | if Is_Private_Type (Id) and then Present (Full_View (Id)) then |
996ae0b0 RK |
9576 | Set_Is_Potentially_Use_Visible (Full_View (Id)); |
9577 | end if; | |
9578 | end if; | |
9579 | ||
9580 | <<Next_Usable_Entity>> | |
9581 | Next_Entity (Id); | |
9582 | end loop; | |
9583 | ||
16ca248a ES |
9584 | -- Child units are also made use-visible by a use clause, but they may |
9585 | -- appear after all visible declarations in the parent entity list. | |
996ae0b0 RK |
9586 | |
9587 | while Present (Id) loop | |
8398e82e | 9588 | if Is_Child_Unit (Id) and then Is_Visible_Lib_Unit (Id) then |
996ae0b0 RK |
9589 | Set_Is_Potentially_Use_Visible (Id); |
9590 | end if; | |
9591 | ||
9592 | Next_Entity (Id); | |
9593 | end loop; | |
9594 | ||
9595 | if Chars (Real_P) = Name_System | |
9596 | and then Scope (Real_P) = Standard_Standard | |
9597 | and then Present_System_Aux (N) | |
9598 | then | |
851e9f19 | 9599 | Use_One_Package (N); |
996ae0b0 | 9600 | end if; |
996ae0b0 RK |
9601 | end Use_One_Package; |
9602 | ||
9603 | ------------------ | |
9604 | -- Use_One_Type -- | |
9605 | ------------------ | |
9606 | ||
851e9f19 | 9607 | procedure Use_One_Type |
7f5e671b PMR |
9608 | (Id : Node_Id; |
9609 | Installed : Boolean := False; | |
9610 | Force : Boolean := False) | |
851e9f19 | 9611 | is |
954c111a HK |
9612 | function Spec_Reloaded_For_Body return Boolean; |
9613 | -- Determine whether the compilation unit is a package body and the use | |
9614 | -- type clause is in the spec of the same package. Even though the spec | |
9615 | -- was analyzed first, its context is reloaded when analysing the body. | |
9616 | ||
29efbb8c ES |
9617 | procedure Use_Class_Wide_Operations (Typ : Entity_Id); |
9618 | -- AI05-150: if the use_type_clause carries the "all" qualifier, | |
9619 | -- class-wide operations of ancestor types are use-visible if the | |
9620 | -- ancestor type is visible. | |
9621 | ||
954c111a HK |
9622 | ---------------------------- |
9623 | -- Spec_Reloaded_For_Body -- | |
9624 | ---------------------------- | |
9625 | ||
9626 | function Spec_Reloaded_For_Body return Boolean is | |
9627 | begin | |
9628 | if Nkind (Unit (Cunit (Current_Sem_Unit))) = N_Package_Body then | |
9629 | declare | |
9630 | Spec : constant Node_Id := | |
9631 | Parent (List_Containing (Parent (Id))); | |
f146302c | 9632 | |
d99ff0f4 | 9633 | begin |
f146302c AC |
9634 | -- Check whether type is declared in a package specification, |
9635 | -- and current unit is the corresponding package body. The | |
9636 | -- use clauses themselves may be within a nested package. | |
9637 | ||
954c111a HK |
9638 | return |
9639 | Nkind (Spec) = N_Package_Specification | |
7f5e671b PMR |
9640 | and then In_Same_Source_Unit |
9641 | (Corresponding_Body (Parent (Spec)), | |
9642 | Cunit_Entity (Current_Sem_Unit)); | |
954c111a HK |
9643 | end; |
9644 | end if; | |
9645 | ||
9646 | return False; | |
9647 | end Spec_Reloaded_For_Body; | |
9648 | ||
29efbb8c ES |
9649 | ------------------------------- |
9650 | -- Use_Class_Wide_Operations -- | |
9651 | ------------------------------- | |
9652 | ||
9653 | procedure Use_Class_Wide_Operations (Typ : Entity_Id) is | |
29efbb8c | 9654 | function Is_Class_Wide_Operation_Of |
851e9f19 PMR |
9655 | (Op : Entity_Id; |
9656 | T : Entity_Id) return Boolean; | |
29efbb8c ES |
9657 | -- Determine whether a subprogram has a class-wide parameter or |
9658 | -- result that is T'Class. | |
9659 | ||
9660 | --------------------------------- | |
9661 | -- Is_Class_Wide_Operation_Of -- | |
9662 | --------------------------------- | |
9663 | ||
9664 | function Is_Class_Wide_Operation_Of | |
7f5e671b PMR |
9665 | (Op : Entity_Id; |
9666 | T : Entity_Id) return Boolean | |
29efbb8c ES |
9667 | is |
9668 | Formal : Entity_Id; | |
9669 | ||
9670 | begin | |
9671 | Formal := First_Formal (Op); | |
9672 | while Present (Formal) loop | |
9673 | if Etype (Formal) = Class_Wide_Type (T) then | |
9674 | return True; | |
9675 | end if; | |
7f5e671b | 9676 | |
29efbb8c ES |
9677 | Next_Formal (Formal); |
9678 | end loop; | |
9679 | ||
9680 | if Etype (Op) = Class_Wide_Type (T) then | |
9681 | return True; | |
9682 | end if; | |
9683 | ||
9684 | return False; | |
9685 | end Is_Class_Wide_Operation_Of; | |
9686 | ||
7f5e671b PMR |
9687 | -- Local variables |
9688 | ||
9689 | Ent : Entity_Id; | |
9690 | Scop : Entity_Id; | |
9691 | ||
29efbb8c ES |
9692 | -- Start of processing for Use_Class_Wide_Operations |
9693 | ||
9694 | begin | |
9695 | Scop := Scope (Typ); | |
9696 | if not Is_Hidden (Scop) then | |
9697 | Ent := First_Entity (Scop); | |
9698 | while Present (Ent) loop | |
9699 | if Is_Overloadable (Ent) | |
9700 | and then Is_Class_Wide_Operation_Of (Ent, Typ) | |
9701 | and then not Is_Potentially_Use_Visible (Ent) | |
9702 | then | |
9703 | Set_Is_Potentially_Use_Visible (Ent); | |
9704 | Append_Elmt (Ent, Used_Operations (Parent (Id))); | |
9705 | end if; | |
9706 | ||
9707 | Next_Entity (Ent); | |
9708 | end loop; | |
9709 | end if; | |
9710 | ||
9711 | if Is_Derived_Type (Typ) then | |
9712 | Use_Class_Wide_Operations (Etype (Base_Type (Typ))); | |
9713 | end if; | |
9714 | end Use_Class_Wide_Operations; | |
9715 | ||
7f5e671b PMR |
9716 | -- Local variables |
9717 | ||
9718 | Elmt : Elmt_Id; | |
9719 | Is_Known_Used : Boolean; | |
9720 | Op_List : Elist_Id; | |
9721 | T : Entity_Id; | |
9722 | ||
dea1d3dc | 9723 | -- Start of processing for Use_One_Type |
996ae0b0 RK |
9724 | |
9725 | begin | |
851e9f19 PMR |
9726 | if Entity (Id) = Any_Type then |
9727 | return; | |
9728 | end if; | |
9729 | ||
996ae0b0 RK |
9730 | -- It is the type determined by the subtype mark (8.4(8)) whose |
9731 | -- operations become potentially use-visible. | |
9732 | ||
9733 | T := Base_Type (Entity (Id)); | |
9734 | ||
851e9f19 PMR |
9735 | -- Either the type itself is used, the package where it is declared is |
9736 | -- in use or the entity is declared in the current package, thus | |
954c111a HK |
9737 | -- use-visible. |
9738 | ||
7f5e671b PMR |
9739 | Is_Known_Used := |
9740 | (In_Use (T) | |
9741 | and then ((Present (Current_Use_Clause (T)) | |
9742 | and then All_Present (Current_Use_Clause (T))) | |
9743 | or else not All_Present (Parent (Id)))) | |
9744 | or else In_Use (Scope (T)) | |
9745 | or else Scope (T) = Current_Scope; | |
954c111a HK |
9746 | |
9747 | Set_Redundant_Use (Id, | |
9748 | Is_Known_Used or else Is_Potentially_Use_Visible (T)); | |
996ae0b0 | 9749 | |
ecc4ddde AC |
9750 | if Ekind (T) = E_Incomplete_Type then |
9751 | Error_Msg_N ("premature usage of incomplete type", Id); | |
9752 | ||
9753 | elsif In_Open_Scopes (Scope (T)) then | |
996ae0b0 RK |
9754 | null; |
9755 | ||
851e9f19 | 9756 | -- A limited view cannot appear in a use_type_clause. However, an access |
f7ca1d04 AC |
9757 | -- type whose designated type is limited has the flag but is not itself |
9758 | -- a limited view unless we only have a limited view of its enclosing | |
9759 | -- package. | |
294ccb21 | 9760 | |
7b56a91b | 9761 | elsif From_Limited_With (T) and then From_Limited_With (Scope (T)) then |
923fa078 | 9762 | Error_Msg_N |
cc0b3bac AC |
9763 | ("incomplete type from limited view cannot appear in use clause", |
9764 | Id); | |
923fa078 | 9765 | |
c6840e83 AC |
9766 | -- If the use clause is redundant, Used_Operations will usually be |
9767 | -- empty, but we need to set it to empty here in one case: If we are | |
9768 | -- instantiating a generic library unit, then we install the ancestors | |
9769 | -- of that unit in the scope stack, which involves reprocessing use | |
9770 | -- clauses in those ancestors. Such a use clause will typically have a | |
9771 | -- nonempty Used_Operations unless it was redundant in the generic unit, | |
9772 | -- even if it is redundant at the place of the instantiation. | |
9773 | ||
9774 | elsif Redundant_Use (Id) then | |
851e9f19 PMR |
9775 | |
9776 | -- We must avoid incorrectly setting the Current_Use_Clause when we | |
9777 | -- are working with a redundant clause that has already been linked | |
9778 | -- in the Prev_Use_Clause chain, otherwise the chain will break. | |
9779 | ||
9780 | if Present (Current_Use_Clause (T)) | |
9781 | and then Present (Prev_Use_Clause (Current_Use_Clause (T))) | |
9782 | and then Parent (Id) = Prev_Use_Clause (Current_Use_Clause (T)) | |
9783 | then | |
9784 | null; | |
9785 | else | |
9786 | Set_Current_Use_Clause (T, Parent (Id)); | |
9787 | end if; | |
9788 | ||
c6840e83 AC |
9789 | Set_Used_Operations (Parent (Id), New_Elmt_List); |
9790 | ||
fbf5a39b AC |
9791 | -- If the subtype mark designates a subtype in a different package, |
9792 | -- we have to check that the parent type is visible, otherwise the | |
851e9f19 | 9793 | -- use_type_clause is a no-op. Not clear how to do that??? |
fbf5a39b | 9794 | |
c6840e83 | 9795 | else |
851e9f19 | 9796 | Set_Current_Use_Clause (T, Parent (Id)); |
996ae0b0 | 9797 | Set_In_Use (T); |
c3b36d48 | 9798 | |
7f5e671b PMR |
9799 | -- If T is tagged, primitive operators on class-wide operands are |
9800 | -- also available. | |
c3b36d48 AC |
9801 | |
9802 | if Is_Tagged_Type (T) then | |
9803 | Set_In_Use (Class_Wide_Type (T)); | |
9804 | end if; | |
9805 | ||
29efbb8c ES |
9806 | -- Iterate over primitive operations of the type. If an operation is |
9807 | -- already use_visible, it is the result of a previous use_clause, | |
7ff2d234 AC |
9808 | -- and already appears on the corresponding entity chain. If the |
9809 | -- clause is being reinstalled, operations are already use-visible. | |
29efbb8c | 9810 | |
7ff2d234 AC |
9811 | if Installed then |
9812 | null; | |
29efbb8c | 9813 | |
7ff2d234 AC |
9814 | else |
9815 | Op_List := Collect_Primitive_Operations (T); | |
9816 | Elmt := First_Elmt (Op_List); | |
9817 | while Present (Elmt) loop | |
9818 | if (Nkind (Node (Elmt)) = N_Defining_Operator_Symbol | |
9819 | or else Chars (Node (Elmt)) in Any_Operator_Name) | |
9820 | and then not Is_Hidden (Node (Elmt)) | |
9821 | and then not Is_Potentially_Use_Visible (Node (Elmt)) | |
9822 | then | |
9823 | Set_Is_Potentially_Use_Visible (Node (Elmt)); | |
9824 | Append_Elmt (Node (Elmt), Used_Operations (Parent (Id))); | |
996ae0b0 | 9825 | |
7ff2d234 AC |
9826 | elsif Ada_Version >= Ada_2012 |
9827 | and then All_Present (Parent (Id)) | |
9828 | and then not Is_Hidden (Node (Elmt)) | |
9829 | and then not Is_Potentially_Use_Visible (Node (Elmt)) | |
9830 | then | |
9831 | Set_Is_Potentially_Use_Visible (Node (Elmt)); | |
9832 | Append_Elmt (Node (Elmt), Used_Operations (Parent (Id))); | |
9833 | end if; | |
954c111a | 9834 | |
7ff2d234 AC |
9835 | Next_Elmt (Elmt); |
9836 | end loop; | |
9837 | end if; | |
9838 | ||
9839 | if Ada_Version >= Ada_2012 | |
9840 | and then All_Present (Parent (Id)) | |
9841 | and then Is_Tagged_Type (T) | |
9842 | then | |
9843 | Use_Class_Wide_Operations (T); | |
9844 | end if; | |
29efbb8c ES |
9845 | end if; |
9846 | ||
954c111a HK |
9847 | -- If warning on redundant constructs, check for unnecessary WITH |
9848 | ||
851e9f19 PMR |
9849 | if not Force |
9850 | and then Warn_On_Redundant_Constructs | |
954c111a HK |
9851 | and then Is_Known_Used |
9852 | ||
ac7d724d ES |
9853 | -- with P; with P; use P; |
9854 | -- package P is package X is package body X is | |
9855 | -- type T ... use P.T; | |
954c111a | 9856 | |
ac7d724d ES |
9857 | -- The compilation unit is the body of X. GNAT first compiles the |
9858 | -- spec of X, then proceeds to the body. At that point P is marked | |
9859 | -- as use visible. The analysis then reinstalls the spec along with | |
9860 | -- its context. The use clause P.T is now recognized as redundant, | |
9861 | -- but in the wrong context. Do not emit a warning in such cases. | |
9862 | -- Do not emit a warning either if we are in an instance, there is | |
9863 | -- no redundancy between an outer use_clause and one that appears | |
9864 | -- within the generic. | |
954c111a HK |
9865 | |
9866 | and then not Spec_Reloaded_For_Body | |
c56094bd | 9867 | and then not In_Instance |
954c111a HK |
9868 | then |
9869 | -- The type already has a use clause | |
9870 | ||
9871 | if In_Use (T) then | |
3ea52b2e ES |
9872 | |
9873 | -- Case where we know the current use clause for the type | |
9874 | ||
21d27997 | 9875 | if Present (Current_Use_Clause (T)) then |
44b90160 | 9876 | Use_Clause_Known : declare |
7f5e671b PMR |
9877 | Clause1 : constant Node_Id := |
9878 | Find_Most_Prev (Current_Use_Clause (T)); | |
851e9f19 | 9879 | Clause2 : constant Node_Id := Parent (Id); |
3ea52b2e ES |
9880 | Ent1 : Entity_Id; |
9881 | Ent2 : Entity_Id; | |
21d27997 RD |
9882 | Err_No : Node_Id; |
9883 | Unit1 : Node_Id; | |
9884 | Unit2 : Node_Id; | |
9885 | ||
44b90160 RD |
9886 | -- Start of processing for Use_Clause_Known |
9887 | ||
21d27997 | 9888 | begin |
851e9f19 | 9889 | -- If both current use_type_clause and the use_type_clause |
f7ca1d04 AC |
9890 | -- for the type are at the compilation unit level, one of |
9891 | -- the units must be an ancestor of the other, and the | |
9892 | -- warning belongs on the descendant. | |
3ea52b2e | 9893 | |
21d27997 | 9894 | if Nkind (Parent (Clause1)) = N_Compilation_Unit |
3ea52b2e ES |
9895 | and then |
9896 | Nkind (Parent (Clause2)) = N_Compilation_Unit | |
21d27997 | 9897 | then |
b0d3b11d AC |
9898 | -- If the unit is a subprogram body that acts as spec, |
9899 | -- the context clause is shared with the constructed | |
9900 | -- subprogram spec. Clearly there is no redundancy. | |
9901 | ||
9902 | if Clause1 = Clause2 then | |
9903 | return; | |
9904 | end if; | |
9905 | ||
3ea52b2e ES |
9906 | Unit1 := Unit (Parent (Clause1)); |
9907 | Unit2 := Unit (Parent (Clause2)); | |
9908 | ||
32beb1f3 AC |
9909 | -- If both clauses are on same unit, or one is the body |
9910 | -- of the other, or one of them is in a subunit, report | |
9911 | -- redundancy on the later one. | |
f7ca1d04 | 9912 | |
851e9f19 | 9913 | if Unit1 = Unit2 or else Nkind (Unit1) = N_Subunit then |
32beb1f3 | 9914 | Error_Msg_Sloc := Sloc (Current_Use_Clause (T)); |
ed2233dc | 9915 | Error_Msg_NE -- CODEFIX |
32beb1f3 | 9916 | ("& is already use-visible through previous " |
dbfeb4fa | 9917 | & "use_type_clause #??", Clause1, T); |
32beb1f3 AC |
9918 | return; |
9919 | ||
9920 | elsif Nkind_In (Unit2, N_Package_Body, N_Subprogram_Body) | |
9921 | and then Nkind (Unit1) /= Nkind (Unit2) | |
9922 | and then Nkind (Unit1) /= N_Subunit | |
9923 | then | |
9924 | Error_Msg_Sloc := Sloc (Clause1); | |
ed2233dc | 9925 | Error_Msg_NE -- CODEFIX |
32beb1f3 | 9926 | ("& is already use-visible through previous " |
dbfeb4fa | 9927 | & "use_type_clause #??", Current_Use_Clause (T), T); |
32beb1f3 | 9928 | return; |
f7ca1d04 AC |
9929 | end if; |
9930 | ||
851e9f19 | 9931 | -- There is a redundant use_type_clause in a child unit. |
21d27997 | 9932 | -- Determine which of the units is more deeply nested. |
3ea52b2e | 9933 | -- If a unit is a package instance, retrieve the entity |
7ca139d3 | 9934 | -- and its scope from the instance spec. |
21d27997 | 9935 | |
7ca139d3 TQ |
9936 | Ent1 := Entity_Of_Unit (Unit1); |
9937 | Ent2 := Entity_Of_Unit (Unit2); | |
3ea52b2e | 9938 | |
bcb0389e | 9939 | if Scope (Ent2) = Standard_Standard then |
21d27997 RD |
9940 | Error_Msg_Sloc := Sloc (Current_Use_Clause (T)); |
9941 | Err_No := Clause1; | |
9942 | ||
3ea52b2e | 9943 | elsif Scope (Ent1) = Standard_Standard then |
21d27997 RD |
9944 | Error_Msg_Sloc := Sloc (Id); |
9945 | Err_No := Clause2; | |
9946 | ||
7ca139d3 TQ |
9947 | -- If both units are child units, we determine which one |
9948 | -- is the descendant by the scope distance to the | |
3ea52b2e | 9949 | -- ultimate parent unit. |
21d27997 | 9950 | |
3ea52b2e | 9951 | else |
21d27997 | 9952 | declare |
7f5e671b PMR |
9953 | S1 : Entity_Id; |
9954 | S2 : Entity_Id; | |
21d27997 RD |
9955 | |
9956 | begin | |
3ea52b2e ES |
9957 | S1 := Scope (Ent1); |
9958 | S2 := Scope (Ent2); | |
c97c0163 AC |
9959 | while Present (S1) |
9960 | and then Present (S2) | |
9961 | and then S1 /= Standard_Standard | |
9962 | and then S2 /= Standard_Standard | |
21d27997 RD |
9963 | loop |
9964 | S1 := Scope (S1); | |
9965 | S2 := Scope (S2); | |
9966 | end loop; | |
9967 | ||
9968 | if S1 = Standard_Standard then | |
9969 | Error_Msg_Sloc := Sloc (Id); | |
9970 | Err_No := Clause2; | |
9971 | else | |
9972 | Error_Msg_Sloc := Sloc (Current_Use_Clause (T)); | |
9973 | Err_No := Clause1; | |
9974 | end if; | |
9975 | end; | |
9976 | end if; | |
9977 | ||
851e9f19 PMR |
9978 | if Parent (Id) /= Err_No then |
9979 | if Most_Descendant_Use_Clause | |
9980 | (Err_No, Parent (Id)) = Parent (Id) | |
9981 | then | |
9982 | Error_Msg_Sloc := Sloc (Err_No); | |
9983 | Err_No := Parent (Id); | |
9984 | end if; | |
9985 | ||
9986 | Error_Msg_NE -- CODEFIX | |
9987 | ("& is already use-visible through previous " | |
9988 | & "use_type_clause #??", Err_No, Id); | |
9989 | end if; | |
3ea52b2e | 9990 | |
851e9f19 PMR |
9991 | -- Case where current use_type_clause and use_type_clause |
9992 | -- for the type are not both at the compilation unit level. | |
9993 | -- In this case we don't have location information. | |
3ea52b2e | 9994 | |
21d27997 | 9995 | else |
ed2233dc | 9996 | Error_Msg_NE -- CODEFIX |
3ea52b2e | 9997 | ("& is already use-visible through previous " |
f192ca5e | 9998 | & "use_type_clause??", Id, T); |
21d27997 | 9999 | end if; |
44b90160 | 10000 | end Use_Clause_Known; |
3ea52b2e | 10001 | |
7f5e671b PMR |
10002 | -- Here if Current_Use_Clause is not set for T, another case where |
10003 | -- we do not have the location information available. | |
3ea52b2e | 10004 | |
21d27997 | 10005 | else |
ed2233dc | 10006 | Error_Msg_NE -- CODEFIX |
3ea52b2e | 10007 | ("& is already use-visible through previous " |
f192ca5e | 10008 | & "use_type_clause??", Id, T); |
21d27997 | 10009 | end if; |
954c111a HK |
10010 | |
10011 | -- The package where T is declared is already used | |
10012 | ||
10013 | elsif In_Use (Scope (T)) then | |
7f5e671b PMR |
10014 | Error_Msg_Sloc := |
10015 | Sloc (Find_Most_Prev (Current_Use_Clause (Scope (T)))); | |
ed2233dc | 10016 | Error_Msg_NE -- CODEFIX |
dbfeb4fa | 10017 | ("& is already use-visible through package use clause #??", |
37951d8e | 10018 | Id, T); |
954c111a HK |
10019 | |
10020 | -- The current scope is the package where T is declared | |
10021 | ||
10022 | else | |
10023 | Error_Msg_Node_2 := Scope (T); | |
ed2233dc | 10024 | Error_Msg_NE -- CODEFIX |
dbfeb4fa | 10025 | ("& is already use-visible inside package &??", Id, T); |
954c111a HK |
10026 | end if; |
10027 | end if; | |
996ae0b0 RK |
10028 | end Use_One_Type; |
10029 | ||
10030 | ---------------- | |
10031 | -- Write_Info -- | |
10032 | ---------------- | |
10033 | ||
10034 | procedure Write_Info is | |
10035 | Id : Entity_Id := First_Entity (Current_Scope); | |
10036 | ||
10037 | begin | |
10038 | -- No point in dumping standard entities | |
10039 | ||
10040 | if Current_Scope = Standard_Standard then | |
10041 | return; | |
10042 | end if; | |
10043 | ||
10044 | Write_Str ("========================================================"); | |
10045 | Write_Eol; | |
10046 | Write_Str (" Defined Entities in "); | |
10047 | Write_Name (Chars (Current_Scope)); | |
10048 | Write_Eol; | |
10049 | Write_Str ("========================================================"); | |
10050 | Write_Eol; | |
10051 | ||
10052 | if No (Id) then | |
10053 | Write_Str ("-- none --"); | |
10054 | Write_Eol; | |
10055 | ||
10056 | else | |
10057 | while Present (Id) loop | |
10058 | Write_Entity_Info (Id, " "); | |
10059 | Next_Entity (Id); | |
10060 | end loop; | |
10061 | end if; | |
10062 | ||
10063 | if Scope (Current_Scope) = Standard_Standard then | |
10064 | ||
10065 | -- Print information on the current unit itself | |
10066 | ||
10067 | Write_Entity_Info (Current_Scope, " "); | |
10068 | end if; | |
10069 | ||
10070 | Write_Eol; | |
10071 | end Write_Info; | |
10072 | ||
67536dcb RD |
10073 | -------- |
10074 | -- ws -- | |
10075 | -------- | |
996ae0b0 | 10076 | |
67536dcb | 10077 | procedure ws is |
996ae0b0 | 10078 | S : Entity_Id; |
996ae0b0 RK |
10079 | begin |
10080 | for J in reverse 1 .. Scope_Stack.Last loop | |
c8307596 | 10081 | S := Scope_Stack.Table (J).Entity; |
996ae0b0 RK |
10082 | Write_Int (Int (S)); |
10083 | Write_Str (" === "); | |
10084 | Write_Name (Chars (S)); | |
10085 | Write_Eol; | |
10086 | end loop; | |
67536dcb | 10087 | end ws; |
996ae0b0 | 10088 | |
c1ce0691 ES |
10089 | -------- |
10090 | -- we -- | |
10091 | -------- | |
10092 | ||
10093 | procedure we (S : Entity_Id) is | |
10094 | E : Entity_Id; | |
10095 | begin | |
10096 | E := First_Entity (S); | |
10097 | while Present (E) loop | |
10098 | Write_Int (Int (E)); | |
10099 | Write_Str (" === "); | |
10100 | Write_Name (Chars (E)); | |
10101 | Write_Eol; | |
c1ce0691 ES |
10102 | Next_Entity (E); |
10103 | end loop; | |
10104 | end we; | |
996ae0b0 | 10105 | end Sem_Ch8; |