]>
Commit | Line | Data |
---|---|---|
996ae0b0 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- S E M _ C H 6 -- | |
6 | -- -- | |
7 | -- B o d y -- | |
996ae0b0 | 8 | -- -- |
76a69663 | 9 | -- Copyright (C) 1992-2008, 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 Checks; use Checks; | |
28 | with Debug; use Debug; | |
29 | with Einfo; use Einfo; | |
30 | with Elists; use Elists; | |
31 | with Errout; use Errout; | |
32 | with Expander; use Expander; | |
ec4867fa | 33 | with Exp_Ch6; use Exp_Ch6; |
996ae0b0 | 34 | with Exp_Ch7; use Exp_Ch7; |
e660dbf7 | 35 | with Exp_Tss; use Exp_Tss; |
ec4867fa | 36 | with Exp_Util; use Exp_Util; |
fbf5a39b | 37 | with Fname; use Fname; |
996ae0b0 | 38 | with Freeze; use Freeze; |
41251c60 | 39 | with Itypes; use Itypes; |
996ae0b0 | 40 | with Lib.Xref; use Lib.Xref; |
ec4867fa | 41 | with Layout; use Layout; |
996ae0b0 RK |
42 | with Namet; use Namet; |
43 | with Lib; use Lib; | |
44 | with Nlists; use Nlists; | |
45 | with Nmake; use Nmake; | |
46 | with Opt; use Opt; | |
47 | with Output; use Output; | |
48 | with Rtsfind; use Rtsfind; | |
49 | with Sem; use Sem; | |
50 | with Sem_Cat; use Sem_Cat; | |
51 | with Sem_Ch3; use Sem_Ch3; | |
52 | with Sem_Ch4; use Sem_Ch4; | |
53 | with Sem_Ch5; use Sem_Ch5; | |
54 | with Sem_Ch8; use Sem_Ch8; | |
9bc856dd | 55 | with Sem_Ch10; use Sem_Ch10; |
996ae0b0 RK |
56 | with Sem_Ch12; use Sem_Ch12; |
57 | with Sem_Disp; use Sem_Disp; | |
58 | with Sem_Dist; use Sem_Dist; | |
59 | with Sem_Elim; use Sem_Elim; | |
60 | with Sem_Eval; use Sem_Eval; | |
61 | with Sem_Mech; use Sem_Mech; | |
62 | with Sem_Prag; use Sem_Prag; | |
63 | with Sem_Res; use Sem_Res; | |
64 | with Sem_Util; use Sem_Util; | |
65 | with Sem_Type; use Sem_Type; | |
66 | with Sem_Warn; use Sem_Warn; | |
67 | with Sinput; use Sinput; | |
68 | with Stand; use Stand; | |
69 | with Sinfo; use Sinfo; | |
70 | with Sinfo.CN; use Sinfo.CN; | |
71 | with Snames; use Snames; | |
72 | with Stringt; use Stringt; | |
73 | with Style; | |
74 | with Stylesw; use Stylesw; | |
75 | with Tbuild; use Tbuild; | |
76 | with Uintp; use Uintp; | |
77 | with Urealp; use Urealp; | |
78 | with Validsw; use Validsw; | |
79 | ||
80 | package body Sem_Ch6 is | |
81 | ||
c8ef728f | 82 | May_Hide_Profile : Boolean := False; |
ec4867fa ES |
83 | -- This flag is used to indicate that two formals in two subprograms being |
84 | -- checked for conformance differ only in that one is an access parameter | |
85 | -- while the other is of a general access type with the same designated | |
86 | -- type. In this case, if the rest of the signatures match, a call to | |
87 | -- either subprogram may be ambiguous, which is worth a warning. The flag | |
88 | -- is set in Compatible_Types, and the warning emitted in | |
89 | -- New_Overloaded_Entity. | |
c8ef728f | 90 | |
996ae0b0 RK |
91 | ----------------------- |
92 | -- Local Subprograms -- | |
93 | ----------------------- | |
94 | ||
5d37ba92 | 95 | procedure Analyze_Return_Statement (N : Node_Id); |
ec4867fa ES |
96 | -- Common processing for simple_ and extended_return_statements |
97 | ||
98 | procedure Analyze_Function_Return (N : Node_Id); | |
81db9d77 ES |
99 | -- Subsidiary to Analyze_Return_Statement. Called when the return statement |
100 | -- applies to a [generic] function. | |
ec4867fa | 101 | |
82c80734 RD |
102 | procedure Analyze_Return_Type (N : Node_Id); |
103 | -- Subsidiary to Process_Formals: analyze subtype mark in function | |
104 | -- specification, in a context where the formals are visible and hide | |
105 | -- outer homographs. | |
106 | ||
996ae0b0 | 107 | procedure Analyze_Generic_Subprogram_Body (N : Node_Id; Gen_Id : Entity_Id); |
82c80734 RD |
108 | -- Analyze a generic subprogram body. N is the body to be analyzed, and |
109 | -- Gen_Id is the defining entity Id for the corresponding spec. | |
996ae0b0 | 110 | |
d05ef0ab | 111 | procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id); |
996ae0b0 RK |
112 | -- If a subprogram has pragma Inline and inlining is active, use generic |
113 | -- machinery to build an unexpanded body for the subprogram. This body is | |
114 | -- subsequenty used for inline expansions at call sites. If subprogram can | |
115 | -- be inlined (depending on size and nature of local declarations) this | |
116 | -- function returns true. Otherwise subprogram body is treated normally. | |
aa720a54 AC |
117 | -- If proper warnings are enabled and the subprogram contains a construct |
118 | -- that cannot be inlined, the offending construct is flagged accordingly. | |
996ae0b0 | 119 | |
996ae0b0 | 120 | procedure Check_Conformance |
41251c60 JM |
121 | (New_Id : Entity_Id; |
122 | Old_Id : Entity_Id; | |
123 | Ctype : Conformance_Type; | |
124 | Errmsg : Boolean; | |
125 | Conforms : out Boolean; | |
126 | Err_Loc : Node_Id := Empty; | |
127 | Get_Inst : Boolean := False; | |
128 | Skip_Controlling_Formals : Boolean := False); | |
996ae0b0 RK |
129 | -- Given two entities, this procedure checks that the profiles associated |
130 | -- with these entities meet the conformance criterion given by the third | |
131 | -- parameter. If they conform, Conforms is set True and control returns | |
132 | -- to the caller. If they do not conform, Conforms is set to False, and | |
133 | -- in addition, if Errmsg is True on the call, proper messages are output | |
134 | -- to complain about the conformance failure. If Err_Loc is non_Empty | |
135 | -- the error messages are placed on Err_Loc, if Err_Loc is empty, then | |
136 | -- error messages are placed on the appropriate part of the construct | |
137 | -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance | |
138 | -- against a formal access-to-subprogram type so Get_Instance_Of must | |
139 | -- be called. | |
140 | ||
758c442c | 141 | procedure Check_Overriding_Indicator |
ec4867fa | 142 | (Subp : Entity_Id; |
5d37ba92 ES |
143 | Overridden_Subp : Entity_Id; |
144 | Is_Primitive : Boolean); | |
758c442c | 145 | -- Verify the consistency of an overriding_indicator given for subprogram |
5d37ba92 ES |
146 | -- declaration, body, renaming, or instantiation. Overridden_Subp is set |
147 | -- if the scope where we are introducing the subprogram contains a | |
ec4867fa | 148 | -- type-conformant subprogram that becomes hidden by the new subprogram. |
5d37ba92 | 149 | -- Is_Primitive indicates whether the subprogram is primitive. |
fbf5a39b | 150 | |
996ae0b0 RK |
151 | procedure Check_Subprogram_Order (N : Node_Id); |
152 | -- N is the N_Subprogram_Body node for a subprogram. This routine applies | |
153 | -- the alpha ordering rule for N if this ordering requirement applicable. | |
154 | ||
996ae0b0 RK |
155 | procedure Check_Returns |
156 | (HSS : Node_Id; | |
157 | Mode : Character; | |
c8ef728f ES |
158 | Err : out Boolean; |
159 | Proc : Entity_Id := Empty); | |
160 | -- Called to check for missing return statements in a function body, or for | |
0a36105d | 161 | -- returns present in a procedure body which has No_Return set. HSS is the |
c8ef728f ES |
162 | -- handled statement sequence for the subprogram body. This procedure |
163 | -- checks all flow paths to make sure they either have return (Mode = 'F', | |
164 | -- used for functions) or do not have a return (Mode = 'P', used for | |
165 | -- No_Return procedures). The flag Err is set if there are any control | |
166 | -- paths not explicitly terminated by a return in the function case, and is | |
167 | -- True otherwise. Proc is the entity for the procedure case and is used | |
168 | -- in posting the warning message. | |
996ae0b0 | 169 | |
996ae0b0 | 170 | procedure Enter_Overloaded_Entity (S : Entity_Id); |
82c80734 RD |
171 | -- This procedure makes S, a new overloaded entity, into the first visible |
172 | -- entity with that name. | |
996ae0b0 RK |
173 | |
174 | procedure Install_Entity (E : Entity_Id); | |
e895b435 | 175 | -- Make single entity visible. Used for generic formals as well |
996ae0b0 RK |
176 | |
177 | procedure Install_Formals (Id : Entity_Id); | |
82c80734 RD |
178 | -- On entry to a subprogram body, make the formals visible. Note that |
179 | -- simply placing the subprogram on the scope stack is not sufficient: | |
180 | -- the formals must become the current entities for their names. | |
996ae0b0 | 181 | |
a5b62485 AC |
182 | function Is_Non_Overriding_Operation |
183 | (Prev_E : Entity_Id; | |
184 | New_E : Entity_Id) return Boolean; | |
185 | -- Enforce the rule given in 12.3(18): a private operation in an instance | |
186 | -- overrides an inherited operation only if the corresponding operation | |
187 | -- was overriding in the generic. This can happen for primitive operations | |
188 | -- of types derived (in the generic unit) from formal private or formal | |
189 | -- derived types. | |
190 | ||
996ae0b0 RK |
191 | procedure Make_Inequality_Operator (S : Entity_Id); |
192 | -- Create the declaration for an inequality operator that is implicitly | |
193 | -- created by a user-defined equality operator that yields a boolean. | |
194 | ||
195 | procedure May_Need_Actuals (Fun : Entity_Id); | |
196 | -- Flag functions that can be called without parameters, i.e. those that | |
197 | -- have no parameters, or those for which defaults exist for all parameters | |
198 | ||
199 | procedure Set_Formal_Validity (Formal_Id : Entity_Id); | |
200 | -- Formal_Id is an formal parameter entity. This procedure deals with | |
201 | -- setting the proper validity status for this entity, which depends | |
202 | -- on the kind of parameter and the validity checking mode. | |
203 | ||
5d37ba92 ES |
204 | ------------------------------ |
205 | -- Analyze_Return_Statement -- | |
206 | ------------------------------ | |
ec4867fa | 207 | |
5d37ba92 | 208 | procedure Analyze_Return_Statement (N : Node_Id) is |
ec4867fa | 209 | |
800621e0 RD |
210 | pragma Assert (Nkind_In (N, N_Simple_Return_Statement, |
211 | N_Extended_Return_Statement)); | |
ec4867fa ES |
212 | |
213 | Returns_Object : constant Boolean := | |
5d37ba92 ES |
214 | Nkind (N) = N_Extended_Return_Statement |
215 | or else | |
216 | (Nkind (N) = N_Simple_Return_Statement | |
217 | and then Present (Expression (N))); | |
ec4867fa | 218 | -- True if we're returning something; that is, "return <expression>;" |
5d37ba92 ES |
219 | -- or "return Result : T [:= ...]". False for "return;". Used for error |
220 | -- checking: If Returns_Object is True, N should apply to a function | |
221 | -- body; otherwise N should apply to a procedure body, entry body, | |
222 | -- accept statement, or extended return statement. | |
ec4867fa ES |
223 | |
224 | function Find_What_It_Applies_To return Entity_Id; | |
225 | -- Find the entity representing the innermost enclosing body, accept | |
5d37ba92 ES |
226 | -- statement, or extended return statement. If the result is a callable |
227 | -- construct or extended return statement, then this will be the value | |
228 | -- of the Return_Applies_To attribute. Otherwise, the program is | |
229 | -- illegal. See RM-6.5(4/2). | |
ec4867fa ES |
230 | |
231 | ----------------------------- | |
232 | -- Find_What_It_Applies_To -- | |
233 | ----------------------------- | |
234 | ||
235 | function Find_What_It_Applies_To return Entity_Id is | |
236 | Result : Entity_Id := Empty; | |
237 | ||
238 | begin | |
239 | -- Loop outward through the Scope_Stack, skipping blocks and loops | |
240 | ||
241 | for J in reverse 0 .. Scope_Stack.Last loop | |
242 | Result := Scope_Stack.Table (J).Entity; | |
243 | exit when Ekind (Result) /= E_Block and then | |
244 | Ekind (Result) /= E_Loop; | |
245 | end loop; | |
246 | ||
247 | pragma Assert (Present (Result)); | |
248 | return Result; | |
ec4867fa ES |
249 | end Find_What_It_Applies_To; |
250 | ||
5d37ba92 ES |
251 | -- Local declarations |
252 | ||
ec4867fa ES |
253 | Scope_Id : constant Entity_Id := Find_What_It_Applies_To; |
254 | Kind : constant Entity_Kind := Ekind (Scope_Id); | |
ec4867fa ES |
255 | Loc : constant Source_Ptr := Sloc (N); |
256 | Stm_Entity : constant Entity_Id := | |
257 | New_Internal_Entity | |
258 | (E_Return_Statement, Current_Scope, Loc, 'R'); | |
259 | ||
5d37ba92 | 260 | -- Start of processing for Analyze_Return_Statement |
ec4867fa ES |
261 | |
262 | begin | |
ec4867fa ES |
263 | Set_Return_Statement_Entity (N, Stm_Entity); |
264 | ||
265 | Set_Etype (Stm_Entity, Standard_Void_Type); | |
266 | Set_Return_Applies_To (Stm_Entity, Scope_Id); | |
267 | ||
5d37ba92 ES |
268 | -- Place Return entity on scope stack, to simplify enforcement of 6.5 |
269 | -- (4/2): an inner return statement will apply to this extended return. | |
ec4867fa ES |
270 | |
271 | if Nkind (N) = N_Extended_Return_Statement then | |
0a36105d | 272 | Push_Scope (Stm_Entity); |
ec4867fa ES |
273 | end if; |
274 | ||
5d37ba92 | 275 | -- Check that pragma No_Return is obeyed |
ec4867fa ES |
276 | |
277 | if No_Return (Scope_Id) then | |
278 | Error_Msg_N ("RETURN statement not allowed (No_Return)", N); | |
279 | end if; | |
280 | ||
5d37ba92 ES |
281 | -- Warn on any unassigned OUT parameters if in procedure |
282 | ||
283 | if Ekind (Scope_Id) = E_Procedure then | |
284 | Warn_On_Unassigned_Out_Parameter (N, Scope_Id); | |
285 | end if; | |
286 | ||
287 | -- Check that functions return objects, and other things do not | |
ec4867fa ES |
288 | |
289 | if Kind = E_Function or else Kind = E_Generic_Function then | |
290 | if not Returns_Object then | |
291 | Error_Msg_N ("missing expression in return from function", N); | |
292 | end if; | |
293 | ||
294 | elsif Kind = E_Procedure or else Kind = E_Generic_Procedure then | |
295 | if Returns_Object then | |
296 | Error_Msg_N ("procedure cannot return value (use function)", N); | |
297 | end if; | |
298 | ||
299 | elsif Kind = E_Entry or else Kind = E_Entry_Family then | |
300 | if Returns_Object then | |
301 | if Is_Protected_Type (Scope (Scope_Id)) then | |
302 | Error_Msg_N ("entry body cannot return value", N); | |
303 | else | |
304 | Error_Msg_N ("accept statement cannot return value", N); | |
305 | end if; | |
306 | end if; | |
307 | ||
308 | elsif Kind = E_Return_Statement then | |
309 | ||
310 | -- We are nested within another return statement, which must be an | |
311 | -- extended_return_statement. | |
312 | ||
313 | if Returns_Object then | |
314 | Error_Msg_N | |
315 | ("extended_return_statement cannot return value; " & | |
316 | "use `""RETURN;""`", N); | |
317 | end if; | |
318 | ||
319 | else | |
320 | Error_Msg_N ("illegal context for return statement", N); | |
321 | end if; | |
322 | ||
323 | if Kind = E_Function or else Kind = E_Generic_Function then | |
324 | Analyze_Function_Return (N); | |
325 | end if; | |
326 | ||
327 | if Nkind (N) = N_Extended_Return_Statement then | |
328 | End_Scope; | |
329 | end if; | |
330 | ||
81db9d77 | 331 | Kill_Current_Values (Last_Assignment_Only => True); |
ec4867fa | 332 | Check_Unreachable_Code (N); |
5d37ba92 | 333 | end Analyze_Return_Statement; |
ec4867fa | 334 | |
996ae0b0 RK |
335 | --------------------------------------------- |
336 | -- Analyze_Abstract_Subprogram_Declaration -- | |
337 | --------------------------------------------- | |
338 | ||
339 | procedure Analyze_Abstract_Subprogram_Declaration (N : Node_Id) is | |
fbf5a39b AC |
340 | Designator : constant Entity_Id := |
341 | Analyze_Subprogram_Specification (Specification (N)); | |
996ae0b0 RK |
342 | Scop : constant Entity_Id := Current_Scope; |
343 | ||
344 | begin | |
345 | Generate_Definition (Designator); | |
f937473f | 346 | Set_Is_Abstract_Subprogram (Designator); |
996ae0b0 RK |
347 | New_Overloaded_Entity (Designator); |
348 | Check_Delayed_Subprogram (Designator); | |
349 | ||
fbf5a39b | 350 | Set_Categorization_From_Scope (Designator, Scop); |
996ae0b0 RK |
351 | |
352 | if Ekind (Scope (Designator)) = E_Protected_Type then | |
353 | Error_Msg_N | |
354 | ("abstract subprogram not allowed in protected type", N); | |
5d37ba92 ES |
355 | |
356 | -- Issue a warning if the abstract subprogram is neither a dispatching | |
357 | -- operation nor an operation that overrides an inherited subprogram or | |
358 | -- predefined operator, since this most likely indicates a mistake. | |
359 | ||
360 | elsif Warn_On_Redundant_Constructs | |
361 | and then not Is_Dispatching_Operation (Designator) | |
362 | and then not Is_Overriding_Operation (Designator) | |
363 | and then (not Is_Operator_Symbol_Name (Chars (Designator)) | |
364 | or else Scop /= Scope (Etype (First_Formal (Designator)))) | |
365 | then | |
366 | Error_Msg_N | |
367 | ("?abstract subprogram is not dispatching or overriding", N); | |
996ae0b0 | 368 | end if; |
fbf5a39b AC |
369 | |
370 | Generate_Reference_To_Formals (Designator); | |
996ae0b0 RK |
371 | end Analyze_Abstract_Subprogram_Declaration; |
372 | ||
ec4867fa ES |
373 | ---------------------------------------- |
374 | -- Analyze_Extended_Return_Statement -- | |
375 | ---------------------------------------- | |
376 | ||
377 | procedure Analyze_Extended_Return_Statement (N : Node_Id) is | |
378 | begin | |
5d37ba92 | 379 | Analyze_Return_Statement (N); |
ec4867fa ES |
380 | end Analyze_Extended_Return_Statement; |
381 | ||
996ae0b0 RK |
382 | ---------------------------- |
383 | -- Analyze_Function_Call -- | |
384 | ---------------------------- | |
385 | ||
386 | procedure Analyze_Function_Call (N : Node_Id) is | |
387 | P : constant Node_Id := Name (N); | |
388 | L : constant List_Id := Parameter_Associations (N); | |
389 | Actual : Node_Id; | |
390 | ||
391 | begin | |
392 | Analyze (P); | |
393 | ||
82c80734 | 394 | -- A call of the form A.B (X) may be an Ada05 call, which is rewritten |
e660dbf7 | 395 | -- as B (A, X). If the rewriting is successful, the call has been |
82c80734 RD |
396 | -- analyzed and we just return. |
397 | ||
398 | if Nkind (P) = N_Selected_Component | |
399 | and then Name (N) /= P | |
400 | and then Is_Rewrite_Substitution (N) | |
401 | and then Present (Etype (N)) | |
402 | then | |
403 | return; | |
404 | end if; | |
405 | ||
996ae0b0 RK |
406 | -- If error analyzing name, then set Any_Type as result type and return |
407 | ||
408 | if Etype (P) = Any_Type then | |
409 | Set_Etype (N, Any_Type); | |
410 | return; | |
411 | end if; | |
412 | ||
413 | -- Otherwise analyze the parameters | |
414 | ||
415 | if Present (L) then | |
416 | Actual := First (L); | |
996ae0b0 RK |
417 | while Present (Actual) loop |
418 | Analyze (Actual); | |
419 | Check_Parameterless_Call (Actual); | |
420 | Next (Actual); | |
421 | end loop; | |
422 | end if; | |
423 | ||
424 | Analyze_Call (N); | |
996ae0b0 RK |
425 | end Analyze_Function_Call; |
426 | ||
ec4867fa ES |
427 | ----------------------------- |
428 | -- Analyze_Function_Return -- | |
429 | ----------------------------- | |
430 | ||
431 | procedure Analyze_Function_Return (N : Node_Id) is | |
432 | Loc : constant Source_Ptr := Sloc (N); | |
433 | Stm_Entity : constant Entity_Id := Return_Statement_Entity (N); | |
434 | Scope_Id : constant Entity_Id := Return_Applies_To (Stm_Entity); | |
435 | ||
5d37ba92 | 436 | R_Type : constant Entity_Id := Etype (Scope_Id); |
ec4867fa ES |
437 | -- Function result subtype |
438 | ||
439 | procedure Check_Limited_Return (Expr : Node_Id); | |
440 | -- Check the appropriate (Ada 95 or Ada 2005) rules for returning | |
441 | -- limited types. Used only for simple return statements. | |
442 | -- Expr is the expression returned. | |
443 | ||
444 | procedure Check_Return_Subtype_Indication (Obj_Decl : Node_Id); | |
445 | -- Check that the return_subtype_indication properly matches the result | |
446 | -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2). | |
447 | ||
448 | -------------------------- | |
449 | -- Check_Limited_Return -- | |
450 | -------------------------- | |
451 | ||
452 | procedure Check_Limited_Return (Expr : Node_Id) is | |
453 | begin | |
454 | -- Ada 2005 (AI-318-02): Return-by-reference types have been | |
455 | -- removed and replaced by anonymous access results. This is an | |
456 | -- incompatibility with Ada 95. Not clear whether this should be | |
457 | -- enforced yet or perhaps controllable with special switch. ??? | |
458 | ||
459 | if Is_Limited_Type (R_Type) | |
460 | and then Comes_From_Source (N) | |
461 | and then not In_Instance_Body | |
462 | and then not OK_For_Limited_Init_In_05 (Expr) | |
463 | then | |
464 | -- Error in Ada 2005 | |
465 | ||
466 | if Ada_Version >= Ada_05 | |
467 | and then not Debug_Flag_Dot_L | |
468 | and then not GNAT_Mode | |
469 | then | |
470 | Error_Msg_N | |
471 | ("(Ada 2005) cannot copy object of a limited type " & | |
5d37ba92 | 472 | "(RM-2005 6.5(5.5/2))", Expr); |
ec4867fa ES |
473 | if Is_Inherently_Limited_Type (R_Type) then |
474 | Error_Msg_N | |
475 | ("\return by reference not permitted in Ada 2005", Expr); | |
476 | end if; | |
477 | ||
478 | -- Warn in Ada 95 mode, to give folks a heads up about this | |
479 | -- incompatibility. | |
480 | ||
481 | -- In GNAT mode, this is just a warning, to allow it to be | |
482 | -- evilly turned off. Otherwise it is a real error. | |
483 | ||
484 | elsif Warn_On_Ada_2005_Compatibility or GNAT_Mode then | |
485 | if Is_Inherently_Limited_Type (R_Type) then | |
486 | Error_Msg_N | |
487 | ("return by reference not permitted in Ada 2005 " & | |
5d37ba92 | 488 | "(RM-2005 6.5(5.5/2))?", Expr); |
ec4867fa ES |
489 | else |
490 | Error_Msg_N | |
491 | ("cannot copy object of a limited type in Ada 2005 " & | |
5d37ba92 | 492 | "(RM-2005 6.5(5.5/2))?", Expr); |
ec4867fa ES |
493 | end if; |
494 | ||
495 | -- Ada 95 mode, compatibility warnings disabled | |
496 | ||
497 | else | |
498 | return; -- skip continuation messages below | |
499 | end if; | |
500 | ||
501 | Error_Msg_N | |
502 | ("\consider switching to return of access type", Expr); | |
503 | Explain_Limited_Type (R_Type, Expr); | |
504 | end if; | |
505 | end Check_Limited_Return; | |
506 | ||
507 | ------------------------------------- | |
508 | -- Check_Return_Subtype_Indication -- | |
509 | ------------------------------------- | |
510 | ||
511 | procedure Check_Return_Subtype_Indication (Obj_Decl : Node_Id) is | |
512 | Return_Obj : constant Node_Id := Defining_Identifier (Obj_Decl); | |
513 | R_Stm_Type : constant Entity_Id := Etype (Return_Obj); | |
514 | -- Subtype given in the extended return statement; | |
515 | -- this must match R_Type. | |
516 | ||
517 | Subtype_Ind : constant Node_Id := | |
518 | Object_Definition (Original_Node (Obj_Decl)); | |
519 | ||
520 | R_Type_Is_Anon_Access : | |
521 | constant Boolean := | |
522 | Ekind (R_Type) = E_Anonymous_Access_Subprogram_Type | |
523 | or else | |
524 | Ekind (R_Type) = E_Anonymous_Access_Protected_Subprogram_Type | |
525 | or else | |
526 | Ekind (R_Type) = E_Anonymous_Access_Type; | |
527 | -- True if return type of the function is an anonymous access type | |
528 | -- Can't we make Is_Anonymous_Access_Type in einfo ??? | |
529 | ||
530 | R_Stm_Type_Is_Anon_Access : | |
531 | constant Boolean := | |
0a36105d | 532 | Ekind (R_Stm_Type) = E_Anonymous_Access_Subprogram_Type |
ec4867fa | 533 | or else |
0a36105d | 534 | Ekind (R_Stm_Type) = E_Anonymous_Access_Protected_Subprogram_Type |
ec4867fa | 535 | or else |
0a36105d | 536 | Ekind (R_Stm_Type) = E_Anonymous_Access_Type; |
ec4867fa ES |
537 | -- True if type of the return object is an anonymous access type |
538 | ||
539 | begin | |
540 | -- First, avoid cascade errors: | |
541 | ||
542 | if Error_Posted (Obj_Decl) or else Error_Posted (Subtype_Ind) then | |
543 | return; | |
544 | end if; | |
545 | ||
546 | -- "return access T" case; check that the return statement also has | |
547 | -- "access T", and that the subtypes statically match: | |
548 | ||
549 | if R_Type_Is_Anon_Access then | |
550 | if R_Stm_Type_Is_Anon_Access then | |
0a36105d JM |
551 | if Base_Type (Designated_Type (R_Stm_Type)) /= |
552 | Base_Type (Designated_Type (R_Type)) | |
553 | or else not Subtypes_Statically_Match (R_Stm_Type, R_Type) | |
554 | then | |
ec4867fa | 555 | Error_Msg_N |
0a36105d JM |
556 | ("subtype must statically match function result subtype", |
557 | Subtype_Mark (Subtype_Ind)); | |
ec4867fa | 558 | end if; |
0a36105d | 559 | |
ec4867fa ES |
560 | else |
561 | Error_Msg_N ("must use anonymous access type", Subtype_Ind); | |
562 | end if; | |
563 | ||
564 | -- Subtype_indication case; check that the types are the same, and | |
565 | -- statically match if appropriate: | |
566 | ||
567 | elsif Base_Type (R_Stm_Type) = Base_Type (R_Type) then | |
568 | if Is_Constrained (R_Type) then | |
569 | if not Subtypes_Statically_Match (R_Stm_Type, R_Type) then | |
570 | Error_Msg_N | |
0a36105d JM |
571 | ("subtype must statically match function result subtype", |
572 | Subtype_Ind); | |
ec4867fa ES |
573 | end if; |
574 | end if; | |
575 | ||
0a36105d JM |
576 | -- If the function's result type doesn't match the return object |
577 | -- entity's type, then we check for the case where the result type | |
578 | -- is class-wide, and allow the declaration if the type of the object | |
579 | -- definition matches the class-wide type. This prevents rejection | |
580 | -- in the case where the object declaration is initialized by a call | |
581 | -- to a build-in-place function with a specific result type and the | |
582 | -- object entity had its type changed to that specific type. (Note | |
583 | -- that the ARG believes that return objects should be allowed to | |
584 | -- have a type covered by a class-wide result type in any case, so | |
585 | -- once that relaxation is made (see AI05-32), the above check for | |
586 | -- type compatibility should be changed to test Covers rather than | |
587 | -- equality, and then the following special test will no longer be | |
588 | -- needed. ???) | |
589 | ||
590 | elsif Is_Class_Wide_Type (R_Type) | |
5d37ba92 ES |
591 | and then |
592 | R_Type = Etype (Object_Definition (Original_Node (Obj_Decl))) | |
0a36105d JM |
593 | then |
594 | null; | |
595 | ||
ec4867fa ES |
596 | else |
597 | Error_Msg_N | |
598 | ("wrong type for return_subtype_indication", Subtype_Ind); | |
599 | end if; | |
600 | end Check_Return_Subtype_Indication; | |
601 | ||
602 | --------------------- | |
603 | -- Local Variables -- | |
604 | --------------------- | |
605 | ||
606 | Expr : Node_Id; | |
607 | ||
608 | -- Start of processing for Analyze_Function_Return | |
609 | ||
610 | begin | |
611 | Set_Return_Present (Scope_Id); | |
612 | ||
5d37ba92 | 613 | if Nkind (N) = N_Simple_Return_Statement then |
ec4867fa ES |
614 | Expr := Expression (N); |
615 | Analyze_And_Resolve (Expr, R_Type); | |
616 | Check_Limited_Return (Expr); | |
617 | ||
618 | else | |
619 | -- Analyze parts specific to extended_return_statement: | |
620 | ||
621 | declare | |
622 | Obj_Decl : constant Node_Id := | |
623 | Last (Return_Object_Declarations (N)); | |
624 | ||
625 | HSS : constant Node_Id := Handled_Statement_Sequence (N); | |
626 | ||
627 | begin | |
628 | Expr := Expression (Obj_Decl); | |
629 | ||
630 | -- Note: The check for OK_For_Limited_Init will happen in | |
631 | -- Analyze_Object_Declaration; we treat it as a normal | |
632 | -- object declaration. | |
633 | ||
634 | Analyze (Obj_Decl); | |
635 | ||
636 | Set_Is_Return_Object (Defining_Identifier (Obj_Decl)); | |
637 | Check_Return_Subtype_Indication (Obj_Decl); | |
638 | ||
639 | if Present (HSS) then | |
640 | Analyze (HSS); | |
641 | ||
642 | if Present (Exception_Handlers (HSS)) then | |
643 | ||
644 | -- ???Has_Nested_Block_With_Handler needs to be set. | |
645 | -- Probably by creating an actual N_Block_Statement. | |
646 | -- Probably in Expand. | |
647 | ||
648 | null; | |
649 | end if; | |
650 | end if; | |
651 | ||
652 | Check_References (Stm_Entity); | |
653 | end; | |
654 | end if; | |
655 | ||
5d37ba92 ES |
656 | -- Case of Expr present (Etype check defends against previous errors) |
657 | ||
ec4867fa | 658 | if Present (Expr) |
5d37ba92 | 659 | and then Present (Etype (Expr)) |
ec4867fa | 660 | then |
5d37ba92 ES |
661 | -- Apply constraint check. Note that this is done before the implicit |
662 | -- conversion of the expression done for anonymous access types to | |
663 | -- ensure correct generation of the null-excluding check asssociated | |
664 | -- with null-excluding expressions found in return statements. | |
665 | ||
666 | Apply_Constraint_Check (Expr, R_Type); | |
667 | ||
668 | -- Ada 2005 (AI-318-02): When the result type is an anonymous access | |
669 | -- type, apply an implicit conversion of the expression to that type | |
670 | -- to force appropriate static and run-time accessibility checks. | |
ec4867fa ES |
671 | |
672 | if Ada_Version >= Ada_05 | |
673 | and then Ekind (R_Type) = E_Anonymous_Access_Type | |
674 | then | |
675 | Rewrite (Expr, Convert_To (R_Type, Relocate_Node (Expr))); | |
676 | Analyze_And_Resolve (Expr, R_Type); | |
677 | end if; | |
678 | ||
679 | if (Is_Class_Wide_Type (Etype (Expr)) | |
680 | or else Is_Dynamically_Tagged (Expr)) | |
681 | and then not Is_Class_Wide_Type (R_Type) | |
682 | then | |
683 | Error_Msg_N | |
684 | ("dynamically tagged expression not allowed!", Expr); | |
685 | end if; | |
686 | ||
ec4867fa ES |
687 | -- ??? A real run-time accessibility check is needed in cases |
688 | -- involving dereferences of access parameters. For now we just | |
689 | -- check the static cases. | |
690 | ||
691 | if (Ada_Version < Ada_05 or else Debug_Flag_Dot_L) | |
692 | and then Is_Inherently_Limited_Type (Etype (Scope_Id)) | |
693 | and then Object_Access_Level (Expr) > | |
694 | Subprogram_Access_Level (Scope_Id) | |
695 | then | |
696 | Rewrite (N, | |
697 | Make_Raise_Program_Error (Loc, | |
698 | Reason => PE_Accessibility_Check_Failed)); | |
699 | Analyze (N); | |
700 | ||
701 | Error_Msg_N | |
702 | ("cannot return a local value by reference?", N); | |
703 | Error_Msg_NE | |
704 | ("\& will be raised at run time?", | |
705 | N, Standard_Program_Error); | |
706 | end if; | |
5d37ba92 ES |
707 | |
708 | if Known_Null (Expr) | |
709 | and then Nkind (Parent (Scope_Id)) = N_Function_Specification | |
710 | and then Null_Exclusion_Present (Parent (Scope_Id)) | |
711 | then | |
712 | Apply_Compile_Time_Constraint_Error | |
713 | (N => Expr, | |
714 | Msg => "(Ada 2005) null not allowed for " | |
715 | & "null-excluding return?", | |
716 | Reason => CE_Null_Not_Allowed); | |
717 | end if; | |
ec4867fa ES |
718 | end if; |
719 | end Analyze_Function_Return; | |
720 | ||
996ae0b0 RK |
721 | ------------------------------------- |
722 | -- Analyze_Generic_Subprogram_Body -- | |
723 | ------------------------------------- | |
724 | ||
725 | procedure Analyze_Generic_Subprogram_Body | |
726 | (N : Node_Id; | |
727 | Gen_Id : Entity_Id) | |
728 | is | |
fbf5a39b | 729 | Gen_Decl : constant Node_Id := Unit_Declaration_Node (Gen_Id); |
996ae0b0 | 730 | Kind : constant Entity_Kind := Ekind (Gen_Id); |
fbf5a39b | 731 | Body_Id : Entity_Id; |
996ae0b0 | 732 | New_N : Node_Id; |
fbf5a39b | 733 | Spec : Node_Id; |
996ae0b0 RK |
734 | |
735 | begin | |
82c80734 RD |
736 | -- Copy body and disable expansion while analyzing the generic For a |
737 | -- stub, do not copy the stub (which would load the proper body), this | |
738 | -- will be done when the proper body is analyzed. | |
996ae0b0 RK |
739 | |
740 | if Nkind (N) /= N_Subprogram_Body_Stub then | |
741 | New_N := Copy_Generic_Node (N, Empty, Instantiating => False); | |
742 | Rewrite (N, New_N); | |
743 | Start_Generic; | |
744 | end if; | |
745 | ||
746 | Spec := Specification (N); | |
747 | ||
748 | -- Within the body of the generic, the subprogram is callable, and | |
749 | -- behaves like the corresponding non-generic unit. | |
750 | ||
fbf5a39b | 751 | Body_Id := Defining_Entity (Spec); |
996ae0b0 RK |
752 | |
753 | if Kind = E_Generic_Procedure | |
754 | and then Nkind (Spec) /= N_Procedure_Specification | |
755 | then | |
fbf5a39b | 756 | Error_Msg_N ("invalid body for generic procedure ", Body_Id); |
996ae0b0 RK |
757 | return; |
758 | ||
759 | elsif Kind = E_Generic_Function | |
760 | and then Nkind (Spec) /= N_Function_Specification | |
761 | then | |
fbf5a39b | 762 | Error_Msg_N ("invalid body for generic function ", Body_Id); |
996ae0b0 RK |
763 | return; |
764 | end if; | |
765 | ||
fbf5a39b | 766 | Set_Corresponding_Body (Gen_Decl, Body_Id); |
996ae0b0 RK |
767 | |
768 | if Has_Completion (Gen_Id) | |
769 | and then Nkind (Parent (N)) /= N_Subunit | |
770 | then | |
771 | Error_Msg_N ("duplicate generic body", N); | |
772 | return; | |
773 | else | |
774 | Set_Has_Completion (Gen_Id); | |
775 | end if; | |
776 | ||
777 | if Nkind (N) = N_Subprogram_Body_Stub then | |
778 | Set_Ekind (Defining_Entity (Specification (N)), Kind); | |
779 | else | |
780 | Set_Corresponding_Spec (N, Gen_Id); | |
781 | end if; | |
782 | ||
783 | if Nkind (Parent (N)) = N_Compilation_Unit then | |
784 | Set_Cunit_Entity (Current_Sem_Unit, Defining_Entity (N)); | |
785 | end if; | |
786 | ||
787 | -- Make generic parameters immediately visible in the body. They are | |
788 | -- needed to process the formals declarations. Then make the formals | |
789 | -- visible in a separate step. | |
790 | ||
0a36105d | 791 | Push_Scope (Gen_Id); |
996ae0b0 RK |
792 | |
793 | declare | |
794 | E : Entity_Id; | |
795 | First_Ent : Entity_Id; | |
796 | ||
797 | begin | |
798 | First_Ent := First_Entity (Gen_Id); | |
799 | ||
800 | E := First_Ent; | |
801 | while Present (E) and then not Is_Formal (E) loop | |
802 | Install_Entity (E); | |
803 | Next_Entity (E); | |
804 | end loop; | |
805 | ||
806 | Set_Use (Generic_Formal_Declarations (Gen_Decl)); | |
807 | ||
808 | -- Now generic formals are visible, and the specification can be | |
809 | -- analyzed, for subsequent conformance check. | |
810 | ||
fbf5a39b | 811 | Body_Id := Analyze_Subprogram_Specification (Spec); |
996ae0b0 | 812 | |
fbf5a39b | 813 | -- Make formal parameters visible |
996ae0b0 RK |
814 | |
815 | if Present (E) then | |
816 | ||
fbf5a39b AC |
817 | -- E is the first formal parameter, we loop through the formals |
818 | -- installing them so that they will be visible. | |
996ae0b0 RK |
819 | |
820 | Set_First_Entity (Gen_Id, E); | |
996ae0b0 RK |
821 | while Present (E) loop |
822 | Install_Entity (E); | |
823 | Next_Formal (E); | |
824 | end loop; | |
825 | end if; | |
826 | ||
e895b435 | 827 | -- Visible generic entity is callable within its own body |
996ae0b0 | 828 | |
ec4867fa ES |
829 | Set_Ekind (Gen_Id, Ekind (Body_Id)); |
830 | Set_Ekind (Body_Id, E_Subprogram_Body); | |
831 | Set_Convention (Body_Id, Convention (Gen_Id)); | |
832 | Set_Is_Obsolescent (Body_Id, Is_Obsolescent (Gen_Id)); | |
833 | Set_Scope (Body_Id, Scope (Gen_Id)); | |
fbf5a39b AC |
834 | Check_Fully_Conformant (Body_Id, Gen_Id, Body_Id); |
835 | ||
836 | if Nkind (N) = N_Subprogram_Body_Stub then | |
837 | ||
e895b435 | 838 | -- No body to analyze, so restore state of generic unit |
fbf5a39b AC |
839 | |
840 | Set_Ekind (Gen_Id, Kind); | |
841 | Set_Ekind (Body_Id, Kind); | |
842 | ||
843 | if Present (First_Ent) then | |
844 | Set_First_Entity (Gen_Id, First_Ent); | |
845 | end if; | |
846 | ||
847 | End_Scope; | |
848 | return; | |
849 | end if; | |
996ae0b0 | 850 | |
82c80734 RD |
851 | -- If this is a compilation unit, it must be made visible explicitly, |
852 | -- because the compilation of the declaration, unlike other library | |
853 | -- unit declarations, does not. If it is not a unit, the following | |
854 | -- is redundant but harmless. | |
996ae0b0 RK |
855 | |
856 | Set_Is_Immediately_Visible (Gen_Id); | |
fbf5a39b | 857 | Reference_Body_Formals (Gen_Id, Body_Id); |
996ae0b0 | 858 | |
ec4867fa ES |
859 | if Is_Child_Unit (Gen_Id) then |
860 | Generate_Reference (Gen_Id, Scope (Gen_Id), 'k', False); | |
861 | end if; | |
862 | ||
996ae0b0 RK |
863 | Set_Actual_Subtypes (N, Current_Scope); |
864 | Analyze_Declarations (Declarations (N)); | |
865 | Check_Completion; | |
866 | Analyze (Handled_Statement_Sequence (N)); | |
867 | ||
868 | Save_Global_References (Original_Node (N)); | |
869 | ||
82c80734 RD |
870 | -- Prior to exiting the scope, include generic formals again (if any |
871 | -- are present) in the set of local entities. | |
996ae0b0 RK |
872 | |
873 | if Present (First_Ent) then | |
874 | Set_First_Entity (Gen_Id, First_Ent); | |
875 | end if; | |
876 | ||
fbf5a39b | 877 | Check_References (Gen_Id); |
996ae0b0 RK |
878 | end; |
879 | ||
e6f69614 | 880 | Process_End_Label (Handled_Statement_Sequence (N), 't', Current_Scope); |
996ae0b0 RK |
881 | End_Scope; |
882 | Check_Subprogram_Order (N); | |
883 | ||
e895b435 | 884 | -- Outside of its body, unit is generic again |
996ae0b0 RK |
885 | |
886 | Set_Ekind (Gen_Id, Kind); | |
fbf5a39b | 887 | Generate_Reference (Gen_Id, Body_Id, 'b', Set_Ref => False); |
5d37ba92 ES |
888 | |
889 | if Style_Check then | |
890 | Style.Check_Identifier (Body_Id, Gen_Id); | |
891 | end if; | |
996ae0b0 | 892 | End_Generic; |
996ae0b0 RK |
893 | end Analyze_Generic_Subprogram_Body; |
894 | ||
895 | ----------------------------- | |
896 | -- Analyze_Operator_Symbol -- | |
897 | ----------------------------- | |
898 | ||
82c80734 RD |
899 | -- An operator symbol such as "+" or "and" may appear in context where the |
900 | -- literal denotes an entity name, such as "+"(x, y) or in context when it | |
901 | -- is just a string, as in (conjunction = "or"). In these cases the parser | |
902 | -- generates this node, and the semantics does the disambiguation. Other | |
903 | -- such case are actuals in an instantiation, the generic unit in an | |
904 | -- instantiation, and pragma arguments. | |
996ae0b0 RK |
905 | |
906 | procedure Analyze_Operator_Symbol (N : Node_Id) is | |
907 | Par : constant Node_Id := Parent (N); | |
908 | ||
909 | begin | |
800621e0 RD |
910 | if (Nkind (Par) = N_Function_Call |
911 | and then N = Name (Par)) | |
996ae0b0 | 912 | or else Nkind (Par) = N_Function_Instantiation |
800621e0 RD |
913 | or else (Nkind (Par) = N_Indexed_Component |
914 | and then N = Prefix (Par)) | |
996ae0b0 RK |
915 | or else (Nkind (Par) = N_Pragma_Argument_Association |
916 | and then not Is_Pragma_String_Literal (Par)) | |
917 | or else Nkind (Par) = N_Subprogram_Renaming_Declaration | |
800621e0 RD |
918 | or else (Nkind (Par) = N_Attribute_Reference |
919 | and then Attribute_Name (Par) /= Name_Value) | |
996ae0b0 RK |
920 | then |
921 | Find_Direct_Name (N); | |
922 | ||
923 | else | |
924 | Change_Operator_Symbol_To_String_Literal (N); | |
925 | Analyze (N); | |
926 | end if; | |
927 | end Analyze_Operator_Symbol; | |
928 | ||
929 | ----------------------------------- | |
930 | -- Analyze_Parameter_Association -- | |
931 | ----------------------------------- | |
932 | ||
933 | procedure Analyze_Parameter_Association (N : Node_Id) is | |
934 | begin | |
935 | Analyze (Explicit_Actual_Parameter (N)); | |
936 | end Analyze_Parameter_Association; | |
937 | ||
938 | ---------------------------- | |
939 | -- Analyze_Procedure_Call -- | |
940 | ---------------------------- | |
941 | ||
942 | procedure Analyze_Procedure_Call (N : Node_Id) is | |
943 | Loc : constant Source_Ptr := Sloc (N); | |
944 | P : constant Node_Id := Name (N); | |
945 | Actuals : constant List_Id := Parameter_Associations (N); | |
946 | Actual : Node_Id; | |
947 | New_N : Node_Id; | |
948 | ||
949 | procedure Analyze_Call_And_Resolve; | |
950 | -- Do Analyze and Resolve calls for procedure call | |
951 | ||
fbf5a39b AC |
952 | ------------------------------ |
953 | -- Analyze_Call_And_Resolve -- | |
954 | ------------------------------ | |
955 | ||
996ae0b0 RK |
956 | procedure Analyze_Call_And_Resolve is |
957 | begin | |
958 | if Nkind (N) = N_Procedure_Call_Statement then | |
959 | Analyze_Call (N); | |
960 | Resolve (N, Standard_Void_Type); | |
961 | else | |
962 | Analyze (N); | |
963 | end if; | |
964 | end Analyze_Call_And_Resolve; | |
965 | ||
966 | -- Start of processing for Analyze_Procedure_Call | |
967 | ||
968 | begin | |
969 | -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote | |
970 | -- a procedure call or an entry call. The prefix may denote an access | |
971 | -- to subprogram type, in which case an implicit dereference applies. | |
972 | -- If the prefix is an indexed component (without implicit defererence) | |
973 | -- then the construct denotes a call to a member of an entire family. | |
974 | -- If the prefix is a simple name, it may still denote a call to a | |
975 | -- parameterless member of an entry family. Resolution of these various | |
976 | -- interpretations is delicate. | |
977 | ||
978 | Analyze (P); | |
979 | ||
758c442c GD |
980 | -- If this is a call of the form Obj.Op, the call may have been |
981 | -- analyzed and possibly rewritten into a block, in which case | |
982 | -- we are done. | |
983 | ||
984 | if Analyzed (N) then | |
985 | return; | |
986 | end if; | |
987 | ||
996ae0b0 RK |
988 | -- If error analyzing prefix, then set Any_Type as result and return |
989 | ||
990 | if Etype (P) = Any_Type then | |
991 | Set_Etype (N, Any_Type); | |
992 | return; | |
993 | end if; | |
994 | ||
995 | -- Otherwise analyze the parameters | |
996 | ||
997 | if Present (Actuals) then | |
998 | Actual := First (Actuals); | |
999 | ||
1000 | while Present (Actual) loop | |
1001 | Analyze (Actual); | |
1002 | Check_Parameterless_Call (Actual); | |
1003 | Next (Actual); | |
1004 | end loop; | |
1005 | end if; | |
1006 | ||
1007 | -- Special processing for Elab_Spec and Elab_Body calls | |
1008 | ||
1009 | if Nkind (P) = N_Attribute_Reference | |
1010 | and then (Attribute_Name (P) = Name_Elab_Spec | |
1011 | or else Attribute_Name (P) = Name_Elab_Body) | |
1012 | then | |
1013 | if Present (Actuals) then | |
1014 | Error_Msg_N | |
1015 | ("no parameters allowed for this call", First (Actuals)); | |
1016 | return; | |
1017 | end if; | |
1018 | ||
1019 | Set_Etype (N, Standard_Void_Type); | |
1020 | Set_Analyzed (N); | |
1021 | ||
1022 | elsif Is_Entity_Name (P) | |
1023 | and then Is_Record_Type (Etype (Entity (P))) | |
1024 | and then Remote_AST_I_Dereference (P) | |
1025 | then | |
1026 | return; | |
1027 | ||
1028 | elsif Is_Entity_Name (P) | |
1029 | and then Ekind (Entity (P)) /= E_Entry_Family | |
1030 | then | |
1031 | if Is_Access_Type (Etype (P)) | |
1032 | and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type | |
1033 | and then No (Actuals) | |
1034 | and then Comes_From_Source (N) | |
1035 | then | |
1036 | Error_Msg_N ("missing explicit dereference in call", N); | |
1037 | end if; | |
1038 | ||
1039 | Analyze_Call_And_Resolve; | |
1040 | ||
1041 | -- If the prefix is the simple name of an entry family, this is | |
1042 | -- a parameterless call from within the task body itself. | |
1043 | ||
1044 | elsif Is_Entity_Name (P) | |
1045 | and then Nkind (P) = N_Identifier | |
1046 | and then Ekind (Entity (P)) = E_Entry_Family | |
1047 | and then Present (Actuals) | |
1048 | and then No (Next (First (Actuals))) | |
1049 | then | |
82c80734 RD |
1050 | -- Can be call to parameterless entry family. What appears to be the |
1051 | -- sole argument is in fact the entry index. Rewrite prefix of node | |
1052 | -- accordingly. Source representation is unchanged by this | |
996ae0b0 RK |
1053 | -- transformation. |
1054 | ||
1055 | New_N := | |
1056 | Make_Indexed_Component (Loc, | |
1057 | Prefix => | |
1058 | Make_Selected_Component (Loc, | |
1059 | Prefix => New_Occurrence_Of (Scope (Entity (P)), Loc), | |
1060 | Selector_Name => New_Occurrence_Of (Entity (P), Loc)), | |
1061 | Expressions => Actuals); | |
1062 | Set_Name (N, New_N); | |
1063 | Set_Etype (New_N, Standard_Void_Type); | |
1064 | Set_Parameter_Associations (N, No_List); | |
1065 | Analyze_Call_And_Resolve; | |
1066 | ||
1067 | elsif Nkind (P) = N_Explicit_Dereference then | |
1068 | if Ekind (Etype (P)) = E_Subprogram_Type then | |
1069 | Analyze_Call_And_Resolve; | |
1070 | else | |
1071 | Error_Msg_N ("expect access to procedure in call", P); | |
1072 | end if; | |
1073 | ||
82c80734 RD |
1074 | -- The name can be a selected component or an indexed component that |
1075 | -- yields an access to subprogram. Such a prefix is legal if the call | |
1076 | -- has parameter associations. | |
996ae0b0 RK |
1077 | |
1078 | elsif Is_Access_Type (Etype (P)) | |
1079 | and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type | |
1080 | then | |
1081 | if Present (Actuals) then | |
1082 | Analyze_Call_And_Resolve; | |
1083 | else | |
1084 | Error_Msg_N ("missing explicit dereference in call ", N); | |
1085 | end if; | |
1086 | ||
82c80734 RD |
1087 | -- If not an access to subprogram, then the prefix must resolve to the |
1088 | -- name of an entry, entry family, or protected operation. | |
996ae0b0 | 1089 | |
82c80734 RD |
1090 | -- For the case of a simple entry call, P is a selected component where |
1091 | -- the prefix is the task and the selector name is the entry. A call to | |
1092 | -- a protected procedure will have the same syntax. If the protected | |
1093 | -- object contains overloaded operations, the entity may appear as a | |
1094 | -- function, the context will select the operation whose type is Void. | |
996ae0b0 RK |
1095 | |
1096 | elsif Nkind (P) = N_Selected_Component | |
1097 | and then (Ekind (Entity (Selector_Name (P))) = E_Entry | |
1098 | or else | |
1099 | Ekind (Entity (Selector_Name (P))) = E_Procedure | |
1100 | or else | |
1101 | Ekind (Entity (Selector_Name (P))) = E_Function) | |
1102 | then | |
1103 | Analyze_Call_And_Resolve; | |
1104 | ||
1105 | elsif Nkind (P) = N_Selected_Component | |
1106 | and then Ekind (Entity (Selector_Name (P))) = E_Entry_Family | |
1107 | and then Present (Actuals) | |
1108 | and then No (Next (First (Actuals))) | |
1109 | then | |
82c80734 RD |
1110 | -- Can be call to parameterless entry family. What appears to be the |
1111 | -- sole argument is in fact the entry index. Rewrite prefix of node | |
1112 | -- accordingly. Source representation is unchanged by this | |
996ae0b0 RK |
1113 | -- transformation. |
1114 | ||
1115 | New_N := | |
1116 | Make_Indexed_Component (Loc, | |
1117 | Prefix => New_Copy (P), | |
1118 | Expressions => Actuals); | |
1119 | Set_Name (N, New_N); | |
1120 | Set_Etype (New_N, Standard_Void_Type); | |
1121 | Set_Parameter_Associations (N, No_List); | |
1122 | Analyze_Call_And_Resolve; | |
1123 | ||
1124 | -- For the case of a reference to an element of an entry family, P is | |
1125 | -- an indexed component whose prefix is a selected component (task and | |
1126 | -- entry family), and whose index is the entry family index. | |
1127 | ||
1128 | elsif Nkind (P) = N_Indexed_Component | |
1129 | and then Nkind (Prefix (P)) = N_Selected_Component | |
1130 | and then Ekind (Entity (Selector_Name (Prefix (P)))) = E_Entry_Family | |
1131 | then | |
1132 | Analyze_Call_And_Resolve; | |
1133 | ||
1134 | -- If the prefix is the name of an entry family, it is a call from | |
1135 | -- within the task body itself. | |
1136 | ||
1137 | elsif Nkind (P) = N_Indexed_Component | |
1138 | and then Nkind (Prefix (P)) = N_Identifier | |
1139 | and then Ekind (Entity (Prefix (P))) = E_Entry_Family | |
1140 | then | |
1141 | New_N := | |
1142 | Make_Selected_Component (Loc, | |
1143 | Prefix => New_Occurrence_Of (Scope (Entity (Prefix (P))), Loc), | |
1144 | Selector_Name => New_Occurrence_Of (Entity (Prefix (P)), Loc)); | |
1145 | Rewrite (Prefix (P), New_N); | |
1146 | Analyze (P); | |
1147 | Analyze_Call_And_Resolve; | |
1148 | ||
e895b435 | 1149 | -- Anything else is an error |
996ae0b0 RK |
1150 | |
1151 | else | |
758c442c | 1152 | Error_Msg_N ("invalid procedure or entry call", N); |
996ae0b0 RK |
1153 | end if; |
1154 | end Analyze_Procedure_Call; | |
1155 | ||
5d37ba92 ES |
1156 | ------------------------------------- |
1157 | -- Analyze_Simple_Return_Statement -- | |
1158 | ------------------------------------- | |
ec4867fa | 1159 | |
5d37ba92 | 1160 | procedure Analyze_Simple_Return_Statement (N : Node_Id) is |
996ae0b0 | 1161 | begin |
5d37ba92 ES |
1162 | if Present (Expression (N)) then |
1163 | Mark_Coextensions (N, Expression (N)); | |
996ae0b0 RK |
1164 | end if; |
1165 | ||
5d37ba92 ES |
1166 | Analyze_Return_Statement (N); |
1167 | end Analyze_Simple_Return_Statement; | |
996ae0b0 | 1168 | |
82c80734 RD |
1169 | ------------------------- |
1170 | -- Analyze_Return_Type -- | |
1171 | ------------------------- | |
1172 | ||
1173 | procedure Analyze_Return_Type (N : Node_Id) is | |
1174 | Designator : constant Entity_Id := Defining_Entity (N); | |
1175 | Typ : Entity_Id := Empty; | |
1176 | ||
1177 | begin | |
ec4867fa ES |
1178 | -- Normal case where result definition does not indicate an error |
1179 | ||
41251c60 JM |
1180 | if Result_Definition (N) /= Error then |
1181 | if Nkind (Result_Definition (N)) = N_Access_Definition then | |
1182 | Typ := Access_Definition (N, Result_Definition (N)); | |
1183 | Set_Parent (Typ, Result_Definition (N)); | |
1184 | Set_Is_Local_Anonymous_Access (Typ); | |
1185 | Set_Etype (Designator, Typ); | |
1186 | ||
41251c60 JM |
1187 | -- Subtype_Mark case |
1188 | ||
1189 | else | |
1190 | Find_Type (Result_Definition (N)); | |
1191 | Typ := Entity (Result_Definition (N)); | |
1192 | Set_Etype (Designator, Typ); | |
1193 | ||
1194 | if Ekind (Typ) = E_Incomplete_Type | |
0a36105d JM |
1195 | and then Is_Value_Type (Typ) |
1196 | then | |
1197 | null; | |
1198 | ||
1199 | elsif Ekind (Typ) = E_Incomplete_Type | |
41251c60 JM |
1200 | or else (Is_Class_Wide_Type (Typ) |
1201 | and then | |
1202 | Ekind (Root_Type (Typ)) = E_Incomplete_Type) | |
1203 | then | |
1204 | Error_Msg_N | |
1205 | ("invalid use of incomplete type", Result_Definition (N)); | |
1206 | end if; | |
82c80734 RD |
1207 | end if; |
1208 | ||
ec4867fa ES |
1209 | -- Ada 2005 (AI-231): Ensure proper usage of null exclusion |
1210 | ||
1211 | Null_Exclusion_Static_Checks (N); | |
1212 | ||
1213 | -- Case where result definition does indicate an error | |
1214 | ||
82c80734 RD |
1215 | else |
1216 | Set_Etype (Designator, Any_Type); | |
1217 | end if; | |
1218 | end Analyze_Return_Type; | |
1219 | ||
996ae0b0 RK |
1220 | ----------------------------- |
1221 | -- Analyze_Subprogram_Body -- | |
1222 | ----------------------------- | |
1223 | ||
1224 | -- This procedure is called for regular subprogram bodies, generic bodies, | |
1225 | -- and for subprogram stubs of both kinds. In the case of stubs, only the | |
1226 | -- specification matters, and is used to create a proper declaration for | |
1227 | -- the subprogram, or to perform conformance checks. | |
1228 | ||
1229 | procedure Analyze_Subprogram_Body (N : Node_Id) is | |
fbf5a39b AC |
1230 | Loc : constant Source_Ptr := Sloc (N); |
1231 | Body_Spec : constant Node_Id := Specification (N); | |
1232 | Body_Id : Entity_Id := Defining_Entity (Body_Spec); | |
1233 | Prev_Id : constant Entity_Id := Current_Entity_In_Scope (Body_Id); | |
1234 | Body_Deleted : constant Boolean := False; | |
996ae0b0 | 1235 | |
0868e09c RD |
1236 | HSS : Node_Id; |
1237 | Spec_Id : Entity_Id; | |
1238 | Spec_Decl : Node_Id := Empty; | |
1239 | Last_Formal : Entity_Id := Empty; | |
1240 | Conformant : Boolean; | |
1241 | Missing_Ret : Boolean; | |
07fc65c4 | 1242 | P_Ent : Entity_Id; |
996ae0b0 | 1243 | |
ec4867fa ES |
1244 | procedure Check_Anonymous_Return; |
1245 | -- (Ada 2005): if a function returns an access type that denotes a task, | |
1246 | -- or a type that contains tasks, we must create a master entity for | |
1247 | -- the anonymous type, which typically will be used in an allocator | |
1248 | -- in the body of the function. | |
1249 | ||
e660dbf7 JM |
1250 | procedure Check_Inline_Pragma (Spec : in out Node_Id); |
1251 | -- Look ahead to recognize a pragma that may appear after the body. | |
1252 | -- If there is a previous spec, check that it appears in the same | |
1253 | -- declarative part. If the pragma is Inline_Always, perform inlining | |
1254 | -- unconditionally, otherwise only if Front_End_Inlining is requested. | |
1255 | -- If the body acts as a spec, and inlining is required, we create a | |
1256 | -- subprogram declaration for it, in order to attach the body to inline. | |
1257 | ||
1258 | procedure Copy_Parameter_List (Plist : List_Id); | |
f937473f RD |
1259 | -- Utility to create a parameter profile for a new subprogram spec, |
1260 | -- when the subprogram has a body that acts as spec. This is done for | |
1261 | -- some cases of inlining, and for private protected ops. | |
c37bb106 | 1262 | |
76a69663 ES |
1263 | procedure Set_Trivial_Subprogram (N : Node_Id); |
1264 | -- Sets the Is_Trivial_Subprogram flag in both spec and body of the | |
1265 | -- subprogram whose body is being analyzed. N is the statement node | |
1266 | -- causing the flag to be set, if the following statement is a return | |
1267 | -- of an entity, we mark the entity as set in source to suppress any | |
1268 | -- warning on the stylized use of function stubs with a dummy return. | |
1269 | ||
758c442c GD |
1270 | procedure Verify_Overriding_Indicator; |
1271 | -- If there was a previous spec, the entity has been entered in the | |
1272 | -- current scope previously. If the body itself carries an overriding | |
1273 | -- indicator, check that it is consistent with the known status of the | |
1274 | -- entity. | |
1275 | ||
ec4867fa ES |
1276 | ---------------------------- |
1277 | -- Check_Anonymous_Return -- | |
1278 | ---------------------------- | |
1279 | ||
1280 | procedure Check_Anonymous_Return is | |
1281 | Decl : Node_Id; | |
1282 | Scop : Entity_Id; | |
1283 | ||
1284 | begin | |
1285 | if Present (Spec_Id) then | |
1286 | Scop := Spec_Id; | |
1287 | else | |
1288 | Scop := Body_Id; | |
1289 | end if; | |
1290 | ||
1291 | if Ekind (Scop) = E_Function | |
1292 | and then Ekind (Etype (Scop)) = E_Anonymous_Access_Type | |
1293 | and then Has_Task (Designated_Type (Etype (Scop))) | |
1294 | and then Expander_Active | |
1295 | then | |
1296 | Decl := | |
1297 | Make_Object_Declaration (Loc, | |
1298 | Defining_Identifier => | |
1299 | Make_Defining_Identifier (Loc, Name_uMaster), | |
1300 | Constant_Present => True, | |
1301 | Object_Definition => | |
1302 | New_Reference_To (RTE (RE_Master_Id), Loc), | |
1303 | Expression => | |
1304 | Make_Explicit_Dereference (Loc, | |
1305 | New_Reference_To (RTE (RE_Current_Master), Loc))); | |
1306 | ||
1307 | if Present (Declarations (N)) then | |
1308 | Prepend (Decl, Declarations (N)); | |
1309 | else | |
1310 | Set_Declarations (N, New_List (Decl)); | |
1311 | end if; | |
1312 | ||
1313 | Set_Master_Id (Etype (Scop), Defining_Identifier (Decl)); | |
1314 | Set_Has_Master_Entity (Scop); | |
1315 | end if; | |
1316 | end Check_Anonymous_Return; | |
1317 | ||
e660dbf7 JM |
1318 | ------------------------- |
1319 | -- Check_Inline_Pragma -- | |
1320 | ------------------------- | |
758c442c | 1321 | |
e660dbf7 JM |
1322 | procedure Check_Inline_Pragma (Spec : in out Node_Id) is |
1323 | Prag : Node_Id; | |
1324 | Plist : List_Id; | |
0fb2ea01 | 1325 | |
c37bb106 | 1326 | begin |
e660dbf7 JM |
1327 | if not Expander_Active then |
1328 | return; | |
1329 | end if; | |
1330 | ||
1331 | if Is_List_Member (N) | |
1332 | and then Present (Next (N)) | |
1333 | and then Nkind (Next (N)) = N_Pragma | |
c37bb106 AC |
1334 | then |
1335 | Prag := Next (N); | |
1336 | ||
e660dbf7 JM |
1337 | if Nkind (Prag) = N_Pragma |
1338 | and then | |
76a69663 ES |
1339 | (Pragma_Name (Prag) = Name_Inline_Always |
1340 | or else | |
e660dbf7 | 1341 | (Front_End_Inlining |
76a69663 | 1342 | and then Pragma_Name (Prag) = Name_Inline)) |
c37bb106 | 1343 | and then |
e660dbf7 JM |
1344 | Chars |
1345 | (Expression (First (Pragma_Argument_Associations (Prag)))) | |
1346 | = Chars (Body_Id) | |
c37bb106 | 1347 | then |
e660dbf7 JM |
1348 | Prag := Next (N); |
1349 | else | |
1350 | Prag := Empty; | |
c37bb106 | 1351 | end if; |
e660dbf7 JM |
1352 | else |
1353 | Prag := Empty; | |
c37bb106 | 1354 | end if; |
e660dbf7 JM |
1355 | |
1356 | if Present (Prag) then | |
1357 | if Present (Spec_Id) then | |
1358 | if List_Containing (N) = | |
1359 | List_Containing (Unit_Declaration_Node (Spec_Id)) | |
1360 | then | |
1361 | Analyze (Prag); | |
1362 | end if; | |
1363 | ||
1364 | else | |
d39d6bb8 | 1365 | -- Create a subprogram declaration, to make treatment uniform |
e660dbf7 JM |
1366 | |
1367 | declare | |
1368 | Subp : constant Entity_Id := | |
1369 | Make_Defining_Identifier (Loc, Chars (Body_Id)); | |
1370 | Decl : constant Node_Id := | |
1371 | Make_Subprogram_Declaration (Loc, | |
1372 | Specification => New_Copy_Tree (Specification (N))); | |
1373 | begin | |
1374 | Set_Defining_Unit_Name (Specification (Decl), Subp); | |
1375 | ||
1376 | if Present (First_Formal (Body_Id)) then | |
1377 | Plist := New_List; | |
1378 | Copy_Parameter_List (Plist); | |
1379 | Set_Parameter_Specifications | |
1380 | (Specification (Decl), Plist); | |
1381 | end if; | |
1382 | ||
1383 | Insert_Before (N, Decl); | |
1384 | Analyze (Decl); | |
1385 | Analyze (Prag); | |
1386 | Set_Has_Pragma_Inline (Subp); | |
1387 | ||
76a69663 | 1388 | if Pragma_Name (Prag) = Name_Inline_Always then |
e660dbf7 JM |
1389 | Set_Is_Inlined (Subp); |
1390 | Set_Next_Rep_Item (Prag, First_Rep_Item (Subp)); | |
1391 | Set_First_Rep_Item (Subp, Prag); | |
1392 | end if; | |
1393 | ||
1394 | Spec := Subp; | |
1395 | end; | |
1396 | end if; | |
1397 | end if; | |
1398 | end Check_Inline_Pragma; | |
1399 | ||
1400 | ------------------------- | |
1401 | -- Copy_Parameter_List -- | |
1402 | ------------------------- | |
1403 | ||
1404 | procedure Copy_Parameter_List (Plist : List_Id) is | |
1405 | Formal : Entity_Id; | |
1406 | ||
1407 | begin | |
1408 | Formal := First_Formal (Body_Id); | |
1409 | ||
1410 | while Present (Formal) loop | |
1411 | Append | |
1412 | (Make_Parameter_Specification (Loc, | |
1413 | Defining_Identifier => | |
1414 | Make_Defining_Identifier (Sloc (Formal), | |
1415 | Chars => Chars (Formal)), | |
1416 | In_Present => In_Present (Parent (Formal)), | |
1417 | Out_Present => Out_Present (Parent (Formal)), | |
1418 | Parameter_Type => | |
1419 | New_Reference_To (Etype (Formal), Loc), | |
1420 | Expression => | |
1421 | New_Copy_Tree (Expression (Parent (Formal)))), | |
1422 | Plist); | |
1423 | ||
1424 | Next_Formal (Formal); | |
1425 | end loop; | |
1426 | end Copy_Parameter_List; | |
c37bb106 | 1427 | |
76a69663 ES |
1428 | ---------------------------- |
1429 | -- Set_Trivial_Subprogram -- | |
1430 | ---------------------------- | |
1431 | ||
1432 | procedure Set_Trivial_Subprogram (N : Node_Id) is | |
1433 | Nxt : constant Node_Id := Next (N); | |
1434 | ||
1435 | begin | |
1436 | Set_Is_Trivial_Subprogram (Body_Id); | |
1437 | ||
1438 | if Present (Spec_Id) then | |
1439 | Set_Is_Trivial_Subprogram (Spec_Id); | |
1440 | end if; | |
1441 | ||
1442 | if Present (Nxt) | |
1443 | and then Nkind (Nxt) = N_Simple_Return_Statement | |
1444 | and then No (Next (Nxt)) | |
1445 | and then Present (Expression (Nxt)) | |
1446 | and then Is_Entity_Name (Expression (Nxt)) | |
1447 | then | |
1448 | Set_Never_Set_In_Source (Entity (Expression (Nxt)), False); | |
1449 | end if; | |
1450 | end Set_Trivial_Subprogram; | |
1451 | ||
758c442c GD |
1452 | --------------------------------- |
1453 | -- Verify_Overriding_Indicator -- | |
1454 | --------------------------------- | |
1455 | ||
1456 | procedure Verify_Overriding_Indicator is | |
1457 | begin | |
1458 | if Must_Override (Body_Spec) | |
1459 | and then not Is_Overriding_Operation (Spec_Id) | |
1460 | then | |
1461 | Error_Msg_NE | |
1462 | ("subprogram& is not overriding", Body_Spec, Spec_Id); | |
1463 | ||
5d37ba92 ES |
1464 | elsif Must_Not_Override (Body_Spec) then |
1465 | if Is_Overriding_Operation (Spec_Id) then | |
1466 | Error_Msg_NE | |
1467 | ("subprogram& overrides inherited operation", | |
76a69663 | 1468 | Body_Spec, Spec_Id); |
5d37ba92 ES |
1469 | |
1470 | -- If this is not a primitive operation the overriding indicator | |
1471 | -- is altogether illegal. | |
1472 | ||
1473 | elsif not Is_Primitive (Spec_Id) then | |
1474 | Error_Msg_N ("overriding indicator only allowed " & | |
1475 | "if subprogram is primitive", | |
1476 | Body_Spec); | |
1477 | end if; | |
758c442c GD |
1478 | end if; |
1479 | end Verify_Overriding_Indicator; | |
1480 | ||
0fb2ea01 AC |
1481 | -- Start of processing for Analyze_Subprogram_Body |
1482 | ||
996ae0b0 RK |
1483 | begin |
1484 | if Debug_Flag_C then | |
1485 | Write_Str ("==== Compiling subprogram body "); | |
1486 | Write_Name (Chars (Body_Id)); | |
1487 | Write_Str (" from "); | |
0868e09c | 1488 | Write_Location (Loc); |
996ae0b0 RK |
1489 | Write_Eol; |
1490 | end if; | |
1491 | ||
800621e0 | 1492 | Trace_Scope (N, Body_Id, " Analyze subprogram: "); |
996ae0b0 | 1493 | |
82c80734 RD |
1494 | -- Generic subprograms are handled separately. They always have a |
1495 | -- generic specification. Determine whether current scope has a | |
1496 | -- previous declaration. | |
996ae0b0 | 1497 | |
82c80734 RD |
1498 | -- If the subprogram body is defined within an instance of the same |
1499 | -- name, the instance appears as a package renaming, and will be hidden | |
1500 | -- within the subprogram. | |
996ae0b0 RK |
1501 | |
1502 | if Present (Prev_Id) | |
1503 | and then not Is_Overloadable (Prev_Id) | |
1504 | and then (Nkind (Parent (Prev_Id)) /= N_Package_Renaming_Declaration | |
1505 | or else Comes_From_Source (Prev_Id)) | |
1506 | then | |
fbf5a39b | 1507 | if Is_Generic_Subprogram (Prev_Id) then |
996ae0b0 RK |
1508 | Spec_Id := Prev_Id; |
1509 | Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id)); | |
1510 | Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id)); | |
1511 | ||
1512 | Analyze_Generic_Subprogram_Body (N, Spec_Id); | |
1513 | return; | |
1514 | ||
1515 | else | |
82c80734 RD |
1516 | -- Previous entity conflicts with subprogram name. Attempting to |
1517 | -- enter name will post error. | |
996ae0b0 RK |
1518 | |
1519 | Enter_Name (Body_Id); | |
1520 | return; | |
1521 | end if; | |
1522 | ||
82c80734 RD |
1523 | -- Non-generic case, find the subprogram declaration, if one was seen, |
1524 | -- or enter new overloaded entity in the current scope. If the | |
1525 | -- Current_Entity is the Body_Id itself, the unit is being analyzed as | |
1526 | -- part of the context of one of its subunits. No need to redo the | |
1527 | -- analysis. | |
996ae0b0 RK |
1528 | |
1529 | elsif Prev_Id = Body_Id | |
1530 | and then Has_Completion (Body_Id) | |
1531 | then | |
1532 | return; | |
1533 | ||
1534 | else | |
fbf5a39b | 1535 | Body_Id := Analyze_Subprogram_Specification (Body_Spec); |
996ae0b0 RK |
1536 | |
1537 | if Nkind (N) = N_Subprogram_Body_Stub | |
1538 | or else No (Corresponding_Spec (N)) | |
1539 | then | |
1540 | Spec_Id := Find_Corresponding_Spec (N); | |
1541 | ||
1542 | -- If this is a duplicate body, no point in analyzing it | |
1543 | ||
1544 | if Error_Posted (N) then | |
1545 | return; | |
1546 | end if; | |
1547 | ||
82c80734 RD |
1548 | -- A subprogram body should cause freezing of its own declaration, |
1549 | -- but if there was no previous explicit declaration, then the | |
1550 | -- subprogram will get frozen too late (there may be code within | |
1551 | -- the body that depends on the subprogram having been frozen, | |
1552 | -- such as uses of extra formals), so we force it to be frozen | |
76a69663 | 1553 | -- here. Same holds if the body and spec are compilation units. |
996ae0b0 RK |
1554 | |
1555 | if No (Spec_Id) then | |
1556 | Freeze_Before (N, Body_Id); | |
1557 | ||
1558 | elsif Nkind (Parent (N)) = N_Compilation_Unit then | |
1559 | Freeze_Before (N, Spec_Id); | |
1560 | end if; | |
1561 | else | |
1562 | Spec_Id := Corresponding_Spec (N); | |
1563 | end if; | |
1564 | end if; | |
1565 | ||
82c80734 RD |
1566 | -- Do not inline any subprogram that contains nested subprograms, since |
1567 | -- the backend inlining circuit seems to generate uninitialized | |
07fc65c4 | 1568 | -- references in this case. We know this happens in the case of front |
82c80734 RD |
1569 | -- end ZCX support, but it also appears it can happen in other cases as |
1570 | -- well. The backend often rejects attempts to inline in the case of | |
1571 | -- nested procedures anyway, so little if anything is lost by this. | |
1572 | -- Note that this is test is for the benefit of the back-end. There is | |
1573 | -- a separate test for front-end inlining that also rejects nested | |
1574 | -- subprograms. | |
07fc65c4 GB |
1575 | |
1576 | -- Do not do this test if errors have been detected, because in some | |
1577 | -- error cases, this code blows up, and we don't need it anyway if | |
1578 | -- there have been errors, since we won't get to the linker anyway. | |
1579 | ||
82c80734 RD |
1580 | if Comes_From_Source (Body_Id) |
1581 | and then Serious_Errors_Detected = 0 | |
1582 | then | |
07fc65c4 GB |
1583 | P_Ent := Body_Id; |
1584 | loop | |
1585 | P_Ent := Scope (P_Ent); | |
1586 | exit when No (P_Ent) or else P_Ent = Standard_Standard; | |
1587 | ||
fbf5a39b | 1588 | if Is_Subprogram (P_Ent) then |
07fc65c4 GB |
1589 | Set_Is_Inlined (P_Ent, False); |
1590 | ||
1591 | if Comes_From_Source (P_Ent) | |
07fc65c4 GB |
1592 | and then Has_Pragma_Inline (P_Ent) |
1593 | then | |
fbf5a39b AC |
1594 | Cannot_Inline |
1595 | ("cannot inline& (nested subprogram)?", | |
1596 | N, P_Ent); | |
07fc65c4 GB |
1597 | end if; |
1598 | end if; | |
1599 | end loop; | |
1600 | end if; | |
1601 | ||
e660dbf7 JM |
1602 | Check_Inline_Pragma (Spec_Id); |
1603 | ||
07fc65c4 GB |
1604 | -- Case of fully private operation in the body of the protected type. |
1605 | -- We must create a declaration for the subprogram, in order to attach | |
1606 | -- the protected subprogram that will be used in internal calls. | |
1607 | ||
996ae0b0 RK |
1608 | if No (Spec_Id) |
1609 | and then Comes_From_Source (N) | |
1610 | and then Is_Protected_Type (Current_Scope) | |
1611 | then | |
996ae0b0 | 1612 | declare |
996ae0b0 RK |
1613 | Decl : Node_Id; |
1614 | Plist : List_Id; | |
1615 | Formal : Entity_Id; | |
1616 | New_Spec : Node_Id; | |
1617 | ||
1618 | begin | |
1619 | Formal := First_Formal (Body_Id); | |
1620 | ||
82c80734 RD |
1621 | -- The protected operation always has at least one formal, namely |
1622 | -- the object itself, but it is only placed in the parameter list | |
1623 | -- if expansion is enabled. | |
996ae0b0 RK |
1624 | |
1625 | if Present (Formal) | |
1626 | or else Expander_Active | |
1627 | then | |
1628 | Plist := New_List; | |
1629 | ||
1630 | else | |
1631 | Plist := No_List; | |
1632 | end if; | |
1633 | ||
e660dbf7 | 1634 | Copy_Parameter_List (Plist); |
996ae0b0 RK |
1635 | |
1636 | if Nkind (Body_Spec) = N_Procedure_Specification then | |
1637 | New_Spec := | |
1638 | Make_Procedure_Specification (Loc, | |
1639 | Defining_Unit_Name => | |
1640 | Make_Defining_Identifier (Sloc (Body_Id), | |
1641 | Chars => Chars (Body_Id)), | |
1642 | Parameter_Specifications => Plist); | |
1643 | else | |
1644 | New_Spec := | |
1645 | Make_Function_Specification (Loc, | |
1646 | Defining_Unit_Name => | |
1647 | Make_Defining_Identifier (Sloc (Body_Id), | |
1648 | Chars => Chars (Body_Id)), | |
1649 | Parameter_Specifications => Plist, | |
41251c60 JM |
1650 | Result_Definition => |
1651 | New_Occurrence_Of (Etype (Body_Id), Loc)); | |
996ae0b0 RK |
1652 | end if; |
1653 | ||
1654 | Decl := | |
1655 | Make_Subprogram_Declaration (Loc, | |
1656 | Specification => New_Spec); | |
1657 | Insert_Before (N, Decl); | |
996ae0b0 | 1658 | Spec_Id := Defining_Unit_Name (New_Spec); |
2820d220 AC |
1659 | |
1660 | -- Indicate that the entity comes from source, to ensure that | |
82c80734 RD |
1661 | -- cross-reference information is properly generated. The body |
1662 | -- itself is rewritten during expansion, and the body entity will | |
1663 | -- not appear in calls to the operation. | |
2820d220 AC |
1664 | |
1665 | Set_Comes_From_Source (Spec_Id, True); | |
1666 | Analyze (Decl); | |
996ae0b0 RK |
1667 | Set_Has_Completion (Spec_Id); |
1668 | Set_Convention (Spec_Id, Convention_Protected); | |
1669 | end; | |
1670 | ||
1671 | elsif Present (Spec_Id) then | |
1672 | Spec_Decl := Unit_Declaration_Node (Spec_Id); | |
758c442c | 1673 | Verify_Overriding_Indicator; |
5d37ba92 ES |
1674 | |
1675 | -- In general, the spec will be frozen when we start analyzing the | |
1676 | -- body. However, for internally generated operations, such as | |
1677 | -- wrapper functions for inherited operations with controlling | |
1678 | -- results, the spec may not have been frozen by the time we | |
1679 | -- expand the freeze actions that include the bodies. In particular, | |
1680 | -- extra formals for accessibility or for return-in-place may need | |
1681 | -- to be generated. Freeze nodes, if any, are inserted before the | |
1682 | -- current body. | |
1683 | ||
1684 | if not Is_Frozen (Spec_Id) | |
1685 | and then Expander_Active | |
1686 | then | |
1687 | -- Force the generation of its freezing node to ensure proper | |
1688 | -- management of access types in the backend. | |
1689 | ||
1690 | -- This is definitely needed for some cases, but it is not clear | |
1691 | -- why, to be investigated further??? | |
1692 | ||
1693 | Set_Has_Delayed_Freeze (Spec_Id); | |
1694 | Insert_Actions (N, Freeze_Entity (Spec_Id, Loc)); | |
1695 | end if; | |
996ae0b0 RK |
1696 | end if; |
1697 | ||
1698 | -- Place subprogram on scope stack, and make formals visible. If there | |
1699 | -- is a spec, the visible entity remains that of the spec. | |
1700 | ||
1701 | if Present (Spec_Id) then | |
07fc65c4 | 1702 | Generate_Reference (Spec_Id, Body_Id, 'b', Set_Ref => False); |
758c442c GD |
1703 | |
1704 | if Is_Child_Unit (Spec_Id) then | |
1705 | Generate_Reference (Spec_Id, Scope (Spec_Id), 'k', False); | |
1706 | end if; | |
1707 | ||
fbf5a39b AC |
1708 | if Style_Check then |
1709 | Style.Check_Identifier (Body_Id, Spec_Id); | |
1710 | end if; | |
996ae0b0 RK |
1711 | |
1712 | Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id)); | |
1713 | Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id)); | |
1714 | ||
f937473f | 1715 | if Is_Abstract_Subprogram (Spec_Id) then |
996ae0b0 RK |
1716 | Error_Msg_N ("an abstract subprogram cannot have a body", N); |
1717 | return; | |
1718 | else | |
1719 | Set_Convention (Body_Id, Convention (Spec_Id)); | |
1720 | Set_Has_Completion (Spec_Id); | |
1721 | ||
1722 | if Is_Protected_Type (Scope (Spec_Id)) then | |
1723 | Set_Privals_Chain (Spec_Id, New_Elmt_List); | |
1724 | end if; | |
1725 | ||
1726 | -- If this is a body generated for a renaming, do not check for | |
1727 | -- full conformance. The check is redundant, because the spec of | |
1728 | -- the body is a copy of the spec in the renaming declaration, | |
1729 | -- and the test can lead to spurious errors on nested defaults. | |
1730 | ||
1731 | if Present (Spec_Decl) | |
996ae0b0 | 1732 | and then not Comes_From_Source (N) |
93a81b02 GB |
1733 | and then |
1734 | (Nkind (Original_Node (Spec_Decl)) = | |
d2f97d3e GB |
1735 | N_Subprogram_Renaming_Declaration |
1736 | or else (Present (Corresponding_Body (Spec_Decl)) | |
1737 | and then | |
1738 | Nkind (Unit_Declaration_Node | |
1739 | (Corresponding_Body (Spec_Decl))) = | |
1740 | N_Subprogram_Renaming_Declaration)) | |
996ae0b0 RK |
1741 | then |
1742 | Conformant := True; | |
76a69663 | 1743 | |
996ae0b0 RK |
1744 | else |
1745 | Check_Conformance | |
1746 | (Body_Id, Spec_Id, | |
76a69663 | 1747 | Fully_Conformant, True, Conformant, Body_Id); |
996ae0b0 RK |
1748 | end if; |
1749 | ||
1750 | -- If the body is not fully conformant, we have to decide if we | |
1751 | -- should analyze it or not. If it has a really messed up profile | |
1752 | -- then we probably should not analyze it, since we will get too | |
1753 | -- many bogus messages. | |
1754 | ||
1755 | -- Our decision is to go ahead in the non-fully conformant case | |
1756 | -- only if it is at least mode conformant with the spec. Note | |
1757 | -- that the call to Check_Fully_Conformant has issued the proper | |
1758 | -- error messages to complain about the lack of conformance. | |
1759 | ||
1760 | if not Conformant | |
1761 | and then not Mode_Conformant (Body_Id, Spec_Id) | |
1762 | then | |
1763 | return; | |
1764 | end if; | |
1765 | end if; | |
1766 | ||
996ae0b0 | 1767 | if Spec_Id /= Body_Id then |
fbf5a39b | 1768 | Reference_Body_Formals (Spec_Id, Body_Id); |
996ae0b0 RK |
1769 | end if; |
1770 | ||
1771 | if Nkind (N) /= N_Subprogram_Body_Stub then | |
1772 | Set_Corresponding_Spec (N, Spec_Id); | |
758c442c | 1773 | |
5d37ba92 ES |
1774 | -- Ada 2005 (AI-345): If the operation is a primitive operation |
1775 | -- of a concurrent type, the type of the first parameter has been | |
1776 | -- replaced with the corresponding record, which is the proper | |
1777 | -- run-time structure to use. However, within the body there may | |
1778 | -- be uses of the formals that depend on primitive operations | |
1779 | -- of the type (in particular calls in prefixed form) for which | |
1780 | -- we need the original concurrent type. The operation may have | |
1781 | -- several controlling formals, so the replacement must be done | |
1782 | -- for all of them. | |
758c442c GD |
1783 | |
1784 | if Comes_From_Source (Spec_Id) | |
1785 | and then Present (First_Entity (Spec_Id)) | |
1786 | and then Ekind (Etype (First_Entity (Spec_Id))) = E_Record_Type | |
1787 | and then Is_Tagged_Type (Etype (First_Entity (Spec_Id))) | |
5d37ba92 ES |
1788 | and then |
1789 | Present (Abstract_Interfaces (Etype (First_Entity (Spec_Id)))) | |
1790 | and then | |
1791 | Present | |
1792 | (Corresponding_Concurrent_Type | |
1793 | (Etype (First_Entity (Spec_Id)))) | |
758c442c | 1794 | then |
5d37ba92 ES |
1795 | declare |
1796 | Typ : constant Entity_Id := Etype (First_Entity (Spec_Id)); | |
1797 | Form : Entity_Id; | |
1798 | ||
1799 | begin | |
1800 | Form := First_Formal (Spec_Id); | |
1801 | while Present (Form) loop | |
1802 | if Etype (Form) = Typ then | |
1803 | Set_Etype (Form, Corresponding_Concurrent_Type (Typ)); | |
1804 | end if; | |
1805 | ||
1806 | Next_Formal (Form); | |
1807 | end loop; | |
1808 | end; | |
758c442c GD |
1809 | end if; |
1810 | ||
76a69663 | 1811 | -- Make the formals visible, and place subprogram on scope stack |
758c442c | 1812 | |
996ae0b0 RK |
1813 | Install_Formals (Spec_Id); |
1814 | Last_Formal := Last_Entity (Spec_Id); | |
0a36105d | 1815 | Push_Scope (Spec_Id); |
996ae0b0 RK |
1816 | |
1817 | -- Make sure that the subprogram is immediately visible. For | |
1818 | -- child units that have no separate spec this is indispensable. | |
1819 | -- Otherwise it is safe albeit redundant. | |
1820 | ||
1821 | Set_Is_Immediately_Visible (Spec_Id); | |
1822 | end if; | |
1823 | ||
1824 | Set_Corresponding_Body (Unit_Declaration_Node (Spec_Id), Body_Id); | |
1825 | Set_Ekind (Body_Id, E_Subprogram_Body); | |
1826 | Set_Scope (Body_Id, Scope (Spec_Id)); | |
ec4867fa | 1827 | Set_Is_Obsolescent (Body_Id, Is_Obsolescent (Spec_Id)); |
996ae0b0 RK |
1828 | |
1829 | -- Case of subprogram body with no previous spec | |
1830 | ||
1831 | else | |
1832 | if Style_Check | |
1833 | and then Comes_From_Source (Body_Id) | |
1834 | and then not Suppress_Style_Checks (Body_Id) | |
1835 | and then not In_Instance | |
1836 | then | |
1837 | Style.Body_With_No_Spec (N); | |
1838 | end if; | |
1839 | ||
1840 | New_Overloaded_Entity (Body_Id); | |
1841 | ||
1842 | if Nkind (N) /= N_Subprogram_Body_Stub then | |
1843 | Set_Acts_As_Spec (N); | |
1844 | Generate_Definition (Body_Id); | |
fbf5a39b AC |
1845 | Generate_Reference |
1846 | (Body_Id, Body_Id, 'b', Set_Ref => False, Force => True); | |
1847 | Generate_Reference_To_Formals (Body_Id); | |
996ae0b0 | 1848 | Install_Formals (Body_Id); |
0a36105d | 1849 | Push_Scope (Body_Id); |
996ae0b0 RK |
1850 | end if; |
1851 | end if; | |
1852 | ||
76a69663 ES |
1853 | -- If the return type is an anonymous access type whose designated type |
1854 | -- is the limited view of a class-wide type and the non-limited view is | |
1855 | -- available, update the return type accordingly. | |
ec4867fa ES |
1856 | |
1857 | if Ada_Version >= Ada_05 | |
1858 | and then Comes_From_Source (N) | |
1859 | then | |
1860 | declare | |
ec4867fa | 1861 | Etyp : Entity_Id; |
0a36105d | 1862 | Rtyp : Entity_Id; |
ec4867fa ES |
1863 | |
1864 | begin | |
0a36105d JM |
1865 | Rtyp := Etype (Current_Scope); |
1866 | ||
1867 | if Ekind (Rtyp) = E_Anonymous_Access_Type then | |
1868 | Etyp := Directly_Designated_Type (Rtyp); | |
1869 | ||
1870 | if Is_Class_Wide_Type (Etyp) | |
1871 | and then From_With_Type (Etyp) | |
1872 | then | |
1873 | Set_Directly_Designated_Type | |
1874 | (Etype (Current_Scope), Available_View (Etyp)); | |
1875 | end if; | |
1876 | end if; | |
ec4867fa ES |
1877 | end; |
1878 | end if; | |
1879 | ||
996ae0b0 RK |
1880 | -- If this is the proper body of a stub, we must verify that the stub |
1881 | -- conforms to the body, and to the previous spec if one was present. | |
1882 | -- we know already that the body conforms to that spec. This test is | |
1883 | -- only required for subprograms that come from source. | |
1884 | ||
1885 | if Nkind (Parent (N)) = N_Subunit | |
1886 | and then Comes_From_Source (N) | |
1887 | and then not Error_Posted (Body_Id) | |
e895b435 ES |
1888 | and then Nkind (Corresponding_Stub (Parent (N))) = |
1889 | N_Subprogram_Body_Stub | |
996ae0b0 RK |
1890 | then |
1891 | declare | |
fbf5a39b AC |
1892 | Old_Id : constant Entity_Id := |
1893 | Defining_Entity | |
1894 | (Specification (Corresponding_Stub (Parent (N)))); | |
1895 | ||
996ae0b0 | 1896 | Conformant : Boolean := False; |
996ae0b0 RK |
1897 | |
1898 | begin | |
1899 | if No (Spec_Id) then | |
1900 | Check_Fully_Conformant (Body_Id, Old_Id); | |
1901 | ||
1902 | else | |
1903 | Check_Conformance | |
1904 | (Body_Id, Old_Id, Fully_Conformant, False, Conformant); | |
1905 | ||
1906 | if not Conformant then | |
1907 | ||
1908 | -- The stub was taken to be a new declaration. Indicate | |
1909 | -- that it lacks a body. | |
1910 | ||
1911 | Set_Has_Completion (Old_Id, False); | |
1912 | end if; | |
1913 | end if; | |
1914 | end; | |
1915 | end if; | |
1916 | ||
1917 | Set_Has_Completion (Body_Id); | |
1918 | Check_Eliminated (Body_Id); | |
1919 | ||
1920 | if Nkind (N) = N_Subprogram_Body_Stub then | |
1921 | return; | |
1922 | ||
ec4867fa | 1923 | elsif Present (Spec_Id) |
996ae0b0 | 1924 | and then Expander_Active |
e660dbf7 | 1925 | and then |
800621e0 | 1926 | (Has_Pragma_Inline_Always (Spec_Id) |
e660dbf7 | 1927 | or else (Has_Pragma_Inline (Spec_Id) and Front_End_Inlining)) |
996ae0b0 | 1928 | then |
e660dbf7 | 1929 | Build_Body_To_Inline (N, Spec_Id); |
996ae0b0 RK |
1930 | end if; |
1931 | ||
0ab80019 | 1932 | -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis |
9bc856dd AC |
1933 | -- if its specification we have to install the private withed units. |
1934 | ||
1935 | if Is_Compilation_Unit (Body_Id) | |
1936 | and then Scope (Body_Id) = Standard_Standard | |
1937 | then | |
1938 | Install_Private_With_Clauses (Body_Id); | |
1939 | end if; | |
1940 | ||
ec4867fa ES |
1941 | Check_Anonymous_Return; |
1942 | ||
fdce4bb7 JM |
1943 | -- Set the Protected_Formal field of each extra formal of the protected |
1944 | -- subprogram to reference the corresponding extra formal of the | |
1945 | -- subprogram that implements it. For regular formals this occurs when | |
1946 | -- the protected subprogram's declaration is expanded, but the extra | |
1947 | -- formals don't get created until the subprogram is frozen. We need to | |
1948 | -- do this before analyzing the protected subprogram's body so that any | |
1949 | -- references to the original subprogram's extra formals will be changed | |
1950 | -- refer to the implementing subprogram's formals (see Expand_Formal). | |
1951 | ||
1952 | if Present (Spec_Id) | |
1953 | and then Is_Protected_Type (Scope (Spec_Id)) | |
1954 | and then Present (Protected_Body_Subprogram (Spec_Id)) | |
1955 | then | |
1956 | declare | |
1957 | Impl_Subp : constant Entity_Id := | |
1958 | Protected_Body_Subprogram (Spec_Id); | |
1959 | Prot_Ext_Formal : Entity_Id := Extra_Formals (Spec_Id); | |
1960 | Impl_Ext_Formal : Entity_Id := Extra_Formals (Impl_Subp); | |
fdce4bb7 JM |
1961 | begin |
1962 | while Present (Prot_Ext_Formal) loop | |
1963 | pragma Assert (Present (Impl_Ext_Formal)); | |
1964 | ||
1965 | Set_Protected_Formal (Prot_Ext_Formal, Impl_Ext_Formal); | |
1966 | ||
1967 | Next_Formal_With_Extras (Prot_Ext_Formal); | |
1968 | Next_Formal_With_Extras (Impl_Ext_Formal); | |
1969 | end loop; | |
1970 | end; | |
1971 | end if; | |
1972 | ||
0868e09c | 1973 | -- Now we can go on to analyze the body |
996ae0b0 RK |
1974 | |
1975 | HSS := Handled_Statement_Sequence (N); | |
1976 | Set_Actual_Subtypes (N, Current_Scope); | |
1977 | Analyze_Declarations (Declarations (N)); | |
1978 | Check_Completion; | |
1979 | Analyze (HSS); | |
07fc65c4 | 1980 | Process_End_Label (HSS, 't', Current_Scope); |
996ae0b0 RK |
1981 | End_Scope; |
1982 | Check_Subprogram_Order (N); | |
c37bb106 | 1983 | Set_Analyzed (Body_Id); |
996ae0b0 RK |
1984 | |
1985 | -- If we have a separate spec, then the analysis of the declarations | |
1986 | -- caused the entities in the body to be chained to the spec id, but | |
1987 | -- we want them chained to the body id. Only the formal parameters | |
1988 | -- end up chained to the spec id in this case. | |
1989 | ||
1990 | if Present (Spec_Id) then | |
1991 | ||
d39d6bb8 | 1992 | -- We must conform to the categorization of our spec |
996ae0b0 | 1993 | |
d39d6bb8 | 1994 | Validate_Categorization_Dependency (N, Spec_Id); |
996ae0b0 | 1995 | |
d39d6bb8 RD |
1996 | -- And if this is a child unit, the parent units must conform |
1997 | ||
1998 | if Is_Child_Unit (Spec_Id) then | |
996ae0b0 RK |
1999 | Validate_Categorization_Dependency |
2000 | (Unit_Declaration_Node (Spec_Id), Spec_Id); | |
2001 | end if; | |
2002 | ||
2003 | if Present (Last_Formal) then | |
2004 | Set_Next_Entity | |
2005 | (Last_Entity (Body_Id), Next_Entity (Last_Formal)); | |
2006 | Set_Next_Entity (Last_Formal, Empty); | |
2007 | Set_Last_Entity (Body_Id, Last_Entity (Spec_Id)); | |
2008 | Set_Last_Entity (Spec_Id, Last_Formal); | |
2009 | ||
2010 | else | |
2011 | Set_First_Entity (Body_Id, First_Entity (Spec_Id)); | |
2012 | Set_Last_Entity (Body_Id, Last_Entity (Spec_Id)); | |
2013 | Set_First_Entity (Spec_Id, Empty); | |
2014 | Set_Last_Entity (Spec_Id, Empty); | |
2015 | end if; | |
2016 | end if; | |
2017 | ||
2018 | -- If function, check return statements | |
2019 | ||
2020 | if Nkind (Body_Spec) = N_Function_Specification then | |
2021 | declare | |
2022 | Id : Entity_Id; | |
2023 | ||
2024 | begin | |
2025 | if Present (Spec_Id) then | |
2026 | Id := Spec_Id; | |
2027 | else | |
2028 | Id := Body_Id; | |
2029 | end if; | |
2030 | ||
2031 | if Return_Present (Id) then | |
2032 | Check_Returns (HSS, 'F', Missing_Ret); | |
2033 | ||
2034 | if Missing_Ret then | |
2035 | Set_Has_Missing_Return (Id); | |
2036 | end if; | |
2037 | ||
0868e09c RD |
2038 | elsif not Is_Machine_Code_Subprogram (Id) |
2039 | and then not Body_Deleted | |
2040 | then | |
996ae0b0 RK |
2041 | Error_Msg_N ("missing RETURN statement in function body", N); |
2042 | end if; | |
2043 | end; | |
2044 | ||
2045 | -- If procedure with No_Return, check returns | |
2046 | ||
2047 | elsif Nkind (Body_Spec) = N_Procedure_Specification | |
2048 | and then Present (Spec_Id) | |
2049 | and then No_Return (Spec_Id) | |
2050 | then | |
c8ef728f | 2051 | Check_Returns (HSS, 'P', Missing_Ret, Spec_Id); |
996ae0b0 RK |
2052 | end if; |
2053 | ||
82c80734 | 2054 | -- Now we are going to check for variables that are never modified in |
76a69663 ES |
2055 | -- the body of the procedure. But first we deal with a special case |
2056 | -- where we want to modify this check. If the body of the subprogram | |
2057 | -- starts with a raise statement or its equivalent, or if the body | |
2058 | -- consists entirely of a null statement, then it is pretty obvious | |
2059 | -- that it is OK to not reference the parameters. For example, this | |
2060 | -- might be the following common idiom for a stubbed function: | |
82c80734 RD |
2061 | -- statement of the procedure raises an exception. In particular this |
2062 | -- deals with the common idiom of a stubbed function, which might | |
2063 | -- appear as something like | |
fbf5a39b AC |
2064 | |
2065 | -- function F (A : Integer) return Some_Type; | |
2066 | -- X : Some_Type; | |
2067 | -- begin | |
2068 | -- raise Program_Error; | |
2069 | -- return X; | |
2070 | -- end F; | |
2071 | ||
76a69663 ES |
2072 | -- Here the purpose of X is simply to satisfy the annoying requirement |
2073 | -- in Ada that there be at least one return, and we certainly do not | |
2074 | -- want to go posting warnings on X that it is not initialized! On | |
2075 | -- the other hand, if X is entirely unreferenced that should still | |
2076 | -- get a warning. | |
2077 | ||
2078 | -- What we do is to detect these cases, and if we find them, flag the | |
2079 | -- subprogram as being Is_Trivial_Subprogram and then use that flag to | |
2080 | -- suppress unwanted warnings. For the case of the function stub above | |
2081 | -- we have a special test to set X as apparently assigned to suppress | |
2082 | -- the warning. | |
996ae0b0 RK |
2083 | |
2084 | declare | |
800621e0 | 2085 | Stm : Node_Id; |
996ae0b0 RK |
2086 | |
2087 | begin | |
0a36105d JM |
2088 | -- Skip initial labels (for one thing this occurs when we are in |
2089 | -- front end ZCX mode, but in any case it is irrelevant), and also | |
2090 | -- initial Push_xxx_Error_Label nodes, which are also irrelevant. | |
fbf5a39b | 2091 | |
800621e0 | 2092 | Stm := First (Statements (HSS)); |
0a36105d JM |
2093 | while Nkind (Stm) = N_Label |
2094 | or else Nkind (Stm) in N_Push_xxx_Label | |
2095 | loop | |
996ae0b0 | 2096 | Next (Stm); |
0a36105d | 2097 | end loop; |
996ae0b0 | 2098 | |
fbf5a39b AC |
2099 | -- Do the test on the original statement before expansion |
2100 | ||
2101 | declare | |
2102 | Ostm : constant Node_Id := Original_Node (Stm); | |
2103 | ||
2104 | begin | |
76a69663 | 2105 | -- If explicit raise statement, turn on flag |
fbf5a39b AC |
2106 | |
2107 | if Nkind (Ostm) = N_Raise_Statement then | |
76a69663 ES |
2108 | Set_Trivial_Subprogram (Stm); |
2109 | ||
2110 | -- If null statement, and no following statemennts, turn on flag | |
2111 | ||
2112 | elsif Nkind (Stm) = N_Null_Statement | |
2113 | and then Comes_From_Source (Stm) | |
2114 | and then No (Next (Stm)) | |
2115 | then | |
2116 | Set_Trivial_Subprogram (Stm); | |
fbf5a39b AC |
2117 | |
2118 | -- Check for explicit call cases which likely raise an exception | |
2119 | ||
2120 | elsif Nkind (Ostm) = N_Procedure_Call_Statement then | |
2121 | if Is_Entity_Name (Name (Ostm)) then | |
2122 | declare | |
2123 | Ent : constant Entity_Id := Entity (Name (Ostm)); | |
2124 | ||
2125 | begin | |
2126 | -- If the procedure is marked No_Return, then likely it | |
2127 | -- raises an exception, but in any case it is not coming | |
76a69663 | 2128 | -- back here, so turn on the flag. |
fbf5a39b AC |
2129 | |
2130 | if Ekind (Ent) = E_Procedure | |
2131 | and then No_Return (Ent) | |
2132 | then | |
76a69663 | 2133 | Set_Trivial_Subprogram (Stm); |
fbf5a39b AC |
2134 | |
2135 | -- If the procedure name is Raise_Exception, then also | |
2136 | -- assume that it raises an exception. The main target | |
2137 | -- here is Ada.Exceptions.Raise_Exception, but this name | |
2138 | -- is pretty evocative in any context! Note that the | |
2139 | -- procedure in Ada.Exceptions is not marked No_Return | |
76a69663 ES |
2140 | -- because of the annoying case of the null exception Id |
2141 | -- when operating in Ada 95 mode. | |
fbf5a39b AC |
2142 | |
2143 | elsif Chars (Ent) = Name_Raise_Exception then | |
76a69663 | 2144 | Set_Trivial_Subprogram (Stm); |
fbf5a39b AC |
2145 | end if; |
2146 | end; | |
2147 | end if; | |
2148 | end if; | |
2149 | end; | |
996ae0b0 RK |
2150 | end; |
2151 | ||
2152 | -- Check for variables that are never modified | |
2153 | ||
2154 | declare | |
2155 | E1, E2 : Entity_Id; | |
2156 | ||
2157 | begin | |
fbf5a39b | 2158 | -- If there is a separate spec, then transfer Never_Set_In_Source |
996ae0b0 RK |
2159 | -- flags from out parameters to the corresponding entities in the |
2160 | -- body. The reason we do that is we want to post error flags on | |
2161 | -- the body entities, not the spec entities. | |
2162 | ||
2163 | if Present (Spec_Id) then | |
2164 | E1 := First_Entity (Spec_Id); | |
996ae0b0 RK |
2165 | while Present (E1) loop |
2166 | if Ekind (E1) = E_Out_Parameter then | |
2167 | E2 := First_Entity (Body_Id); | |
fbf5a39b | 2168 | while Present (E2) loop |
996ae0b0 RK |
2169 | exit when Chars (E1) = Chars (E2); |
2170 | Next_Entity (E2); | |
2171 | end loop; | |
2172 | ||
fbf5a39b AC |
2173 | if Present (E2) then |
2174 | Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1)); | |
2175 | end if; | |
996ae0b0 RK |
2176 | end if; |
2177 | ||
2178 | Next_Entity (E1); | |
2179 | end loop; | |
2180 | end if; | |
2181 | ||
0868e09c RD |
2182 | -- Check references in body unless it was deleted. Note that the |
2183 | -- check of Body_Deleted here is not just for efficiency, it is | |
2184 | -- necessary to avoid junk warnings on formal parameters. | |
2185 | ||
2186 | if not Body_Deleted then | |
2187 | Check_References (Body_Id); | |
2188 | end if; | |
996ae0b0 RK |
2189 | end; |
2190 | end Analyze_Subprogram_Body; | |
2191 | ||
2192 | ------------------------------------ | |
2193 | -- Analyze_Subprogram_Declaration -- | |
2194 | ------------------------------------ | |
2195 | ||
2196 | procedure Analyze_Subprogram_Declaration (N : Node_Id) is | |
fbf5a39b AC |
2197 | Designator : constant Entity_Id := |
2198 | Analyze_Subprogram_Specification (Specification (N)); | |
2199 | Scop : constant Entity_Id := Current_Scope; | |
996ae0b0 RK |
2200 | |
2201 | -- Start of processing for Analyze_Subprogram_Declaration | |
2202 | ||
2203 | begin | |
2204 | Generate_Definition (Designator); | |
2205 | ||
0a36105d | 2206 | -- Check for RCI unit subprogram declarations for illegal inlined |
996ae0b0 | 2207 | -- subprograms and subprograms having access parameter or limited |
0a36105d | 2208 | -- parameter without Read and Write attributes (RM E.2.3(12-13)). |
996ae0b0 RK |
2209 | |
2210 | Validate_RCI_Subprogram_Declaration (N); | |
2211 | ||
2212 | Trace_Scope | |
2213 | (N, | |
2214 | Defining_Entity (N), | |
800621e0 | 2215 | " Analyze subprogram spec: "); |
996ae0b0 RK |
2216 | |
2217 | if Debug_Flag_C then | |
2218 | Write_Str ("==== Compiling subprogram spec "); | |
2219 | Write_Name (Chars (Designator)); | |
2220 | Write_Str (" from "); | |
2221 | Write_Location (Sloc (N)); | |
2222 | Write_Eol; | |
2223 | end if; | |
2224 | ||
2225 | New_Overloaded_Entity (Designator); | |
2226 | Check_Delayed_Subprogram (Designator); | |
fbf5a39b | 2227 | |
ec4867fa ES |
2228 | -- Ada 2005 (AI-251): Abstract interface primitives must be abstract |
2229 | -- or null. | |
2230 | ||
2231 | if Ada_Version >= Ada_05 | |
2232 | and then Comes_From_Source (N) | |
2233 | and then Is_Dispatching_Operation (Designator) | |
2234 | then | |
2235 | declare | |
2236 | E : Entity_Id; | |
2237 | Etyp : Entity_Id; | |
2238 | ||
2239 | begin | |
2240 | if Has_Controlling_Result (Designator) then | |
2241 | Etyp := Etype (Designator); | |
2242 | ||
2243 | else | |
2244 | E := First_Entity (Designator); | |
2245 | while Present (E) | |
2246 | and then Is_Formal (E) | |
2247 | and then not Is_Controlling_Formal (E) | |
2248 | loop | |
2249 | Next_Entity (E); | |
2250 | end loop; | |
2251 | ||
2252 | Etyp := Etype (E); | |
2253 | end if; | |
2254 | ||
2255 | if Is_Access_Type (Etyp) then | |
2256 | Etyp := Directly_Designated_Type (Etyp); | |
2257 | end if; | |
2258 | ||
2259 | if Is_Interface (Etyp) | |
f937473f | 2260 | and then not Is_Abstract_Subprogram (Designator) |
ec4867fa ES |
2261 | and then not (Ekind (Designator) = E_Procedure |
2262 | and then Null_Present (Specification (N))) | |
2263 | then | |
2264 | Error_Msg_Name_1 := Chars (Defining_Entity (N)); | |
2265 | Error_Msg_N | |
2266 | ("(Ada 2005) interface subprogram % must be abstract or null", | |
2267 | N); | |
2268 | end if; | |
2269 | end; | |
2270 | end if; | |
2271 | ||
fbf5a39b AC |
2272 | -- What is the following code for, it used to be |
2273 | ||
2274 | -- ??? Set_Suppress_Elaboration_Checks | |
2275 | -- ??? (Designator, Elaboration_Checks_Suppressed (Designator)); | |
2276 | ||
2277 | -- The following seems equivalent, but a bit dubious | |
2278 | ||
2279 | if Elaboration_Checks_Suppressed (Designator) then | |
2280 | Set_Kill_Elaboration_Checks (Designator); | |
2281 | end if; | |
996ae0b0 RK |
2282 | |
2283 | if Scop /= Standard_Standard | |
2284 | and then not Is_Child_Unit (Designator) | |
2285 | then | |
fbf5a39b | 2286 | Set_Categorization_From_Scope (Designator, Scop); |
996ae0b0 | 2287 | else |
e895b435 | 2288 | -- For a compilation unit, check for library-unit pragmas |
996ae0b0 | 2289 | |
0a36105d | 2290 | Push_Scope (Designator); |
996ae0b0 RK |
2291 | Set_Categorization_From_Pragmas (N); |
2292 | Validate_Categorization_Dependency (N, Designator); | |
2293 | Pop_Scope; | |
2294 | end if; | |
2295 | ||
2296 | -- For a compilation unit, set body required. This flag will only be | |
2297 | -- reset if a valid Import or Interface pragma is processed later on. | |
2298 | ||
2299 | if Nkind (Parent (N)) = N_Compilation_Unit then | |
2300 | Set_Body_Required (Parent (N), True); | |
758c442c GD |
2301 | |
2302 | if Ada_Version >= Ada_05 | |
2303 | and then Nkind (Specification (N)) = N_Procedure_Specification | |
2304 | and then Null_Present (Specification (N)) | |
2305 | then | |
2306 | Error_Msg_N | |
2307 | ("null procedure cannot be declared at library level", N); | |
2308 | end if; | |
996ae0b0 RK |
2309 | end if; |
2310 | ||
fbf5a39b | 2311 | Generate_Reference_To_Formals (Designator); |
996ae0b0 | 2312 | Check_Eliminated (Designator); |
fbf5a39b | 2313 | |
758c442c GD |
2314 | -- Ada 2005: if procedure is declared with "is null" qualifier, |
2315 | -- it requires no body. | |
2316 | ||
2317 | if Nkind (Specification (N)) = N_Procedure_Specification | |
2318 | and then Null_Present (Specification (N)) | |
fbf5a39b | 2319 | then |
758c442c GD |
2320 | Set_Has_Completion (Designator); |
2321 | Set_Is_Inlined (Designator); | |
ec4867fa ES |
2322 | |
2323 | if Is_Protected_Type (Current_Scope) then | |
2324 | Error_Msg_N | |
2325 | ("protected operation cannot be a null procedure", N); | |
2326 | end if; | |
fbf5a39b | 2327 | end if; |
996ae0b0 RK |
2328 | end Analyze_Subprogram_Declaration; |
2329 | ||
fbf5a39b AC |
2330 | -------------------------------------- |
2331 | -- Analyze_Subprogram_Specification -- | |
2332 | -------------------------------------- | |
2333 | ||
2334 | -- Reminder: N here really is a subprogram specification (not a subprogram | |
2335 | -- declaration). This procedure is called to analyze the specification in | |
2336 | -- both subprogram bodies and subprogram declarations (specs). | |
2337 | ||
2338 | function Analyze_Subprogram_Specification (N : Node_Id) return Entity_Id is | |
2339 | Designator : constant Entity_Id := Defining_Entity (N); | |
0a36105d JM |
2340 | Formal : Entity_Id; |
2341 | Formal_Typ : Entity_Id; | |
fbf5a39b | 2342 | Formals : constant List_Id := Parameter_Specifications (N); |
fbf5a39b | 2343 | |
758c442c GD |
2344 | -- Start of processing for Analyze_Subprogram_Specification |
2345 | ||
fbf5a39b AC |
2346 | begin |
2347 | Generate_Definition (Designator); | |
2348 | ||
2349 | if Nkind (N) = N_Function_Specification then | |
2350 | Set_Ekind (Designator, E_Function); | |
2351 | Set_Mechanism (Designator, Default_Mechanism); | |
2352 | ||
fbf5a39b AC |
2353 | else |
2354 | Set_Ekind (Designator, E_Procedure); | |
2355 | Set_Etype (Designator, Standard_Void_Type); | |
2356 | end if; | |
2357 | ||
800621e0 | 2358 | -- Introduce new scope for analysis of the formals and the return type |
82c80734 RD |
2359 | |
2360 | Set_Scope (Designator, Current_Scope); | |
2361 | ||
fbf5a39b | 2362 | if Present (Formals) then |
0a36105d | 2363 | Push_Scope (Designator); |
fbf5a39b | 2364 | Process_Formals (Formals, N); |
758c442c | 2365 | |
0a36105d JM |
2366 | -- Ada 2005 (AI-345): Allow the overriding of interface primitives |
2367 | -- by subprograms which belong to a concurrent type implementing an | |
2368 | -- interface. Set the parameter type of each controlling formal to | |
2369 | -- the corresponding record type. | |
758c442c | 2370 | |
0a36105d JM |
2371 | if Ada_Version >= Ada_05 then |
2372 | Formal := First_Formal (Designator); | |
2373 | while Present (Formal) loop | |
2374 | Formal_Typ := Etype (Formal); | |
2375 | ||
2376 | if (Ekind (Formal_Typ) = E_Protected_Type | |
2377 | or else Ekind (Formal_Typ) = E_Task_Type) | |
2378 | and then Present (Corresponding_Record_Type (Formal_Typ)) | |
2379 | and then Present (Abstract_Interfaces | |
2380 | (Corresponding_Record_Type (Formal_Typ))) | |
2381 | then | |
2382 | Set_Etype (Formal, | |
2383 | Corresponding_Record_Type (Formal_Typ)); | |
2384 | end if; | |
2385 | ||
2386 | Formal := Next_Formal (Formal); | |
2387 | end loop; | |
758c442c GD |
2388 | end if; |
2389 | ||
fbf5a39b | 2390 | End_Scope; |
82c80734 RD |
2391 | |
2392 | elsif Nkind (N) = N_Function_Specification then | |
2393 | Analyze_Return_Type (N); | |
fbf5a39b AC |
2394 | end if; |
2395 | ||
2396 | if Nkind (N) = N_Function_Specification then | |
2397 | if Nkind (Designator) = N_Defining_Operator_Symbol then | |
2398 | Valid_Operator_Definition (Designator); | |
2399 | end if; | |
2400 | ||
2401 | May_Need_Actuals (Designator); | |
2402 | ||
ec4867fa ES |
2403 | -- Ada 2005 (AI-251): In case of primitives associated with abstract |
2404 | -- interface types the following error message will be reported later | |
2405 | -- (see Analyze_Subprogram_Declaration). | |
2406 | ||
f937473f | 2407 | if Is_Abstract_Type (Etype (Designator)) |
ec4867fa | 2408 | and then not Is_Interface (Etype (Designator)) |
82c80734 RD |
2409 | and then Nkind (Parent (N)) |
2410 | /= N_Abstract_Subprogram_Declaration | |
2411 | and then (Nkind (Parent (N))) | |
2412 | /= N_Formal_Abstract_Subprogram_Declaration | |
2413 | and then (Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration | |
2414 | or else not Is_Entity_Name (Name (Parent (N))) | |
f937473f RD |
2415 | or else not Is_Abstract_Subprogram |
2416 | (Entity (Name (Parent (N))))) | |
fbf5a39b AC |
2417 | then |
2418 | Error_Msg_N | |
2419 | ("function that returns abstract type must be abstract", N); | |
2420 | end if; | |
2421 | end if; | |
2422 | ||
2423 | return Designator; | |
2424 | end Analyze_Subprogram_Specification; | |
2425 | ||
996ae0b0 RK |
2426 | -------------------------- |
2427 | -- Build_Body_To_Inline -- | |
2428 | -------------------------- | |
2429 | ||
d05ef0ab | 2430 | procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id) is |
f937473f | 2431 | Decl : constant Node_Id := Unit_Declaration_Node (Subp); |
996ae0b0 RK |
2432 | Original_Body : Node_Id; |
2433 | Body_To_Analyze : Node_Id; | |
2434 | Max_Size : constant := 10; | |
2435 | Stat_Count : Integer := 0; | |
2436 | ||
2437 | function Has_Excluded_Declaration (Decls : List_Id) return Boolean; | |
e895b435 | 2438 | -- Check for declarations that make inlining not worthwhile |
996ae0b0 RK |
2439 | |
2440 | function Has_Excluded_Statement (Stats : List_Id) return Boolean; | |
82c80734 RD |
2441 | -- Check for statements that make inlining not worthwhile: any tasking |
2442 | -- statement, nested at any level. Keep track of total number of | |
2443 | -- elementary statements, as a measure of acceptable size. | |
996ae0b0 RK |
2444 | |
2445 | function Has_Pending_Instantiation return Boolean; | |
f937473f RD |
2446 | -- If some enclosing body contains instantiations that appear before the |
2447 | -- corresponding generic body, the enclosing body has a freeze node so | |
2448 | -- that it can be elaborated after the generic itself. This might | |
996ae0b0 RK |
2449 | -- conflict with subsequent inlinings, so that it is unsafe to try to |
2450 | -- inline in such a case. | |
2451 | ||
c8ef728f | 2452 | function Has_Single_Return return Boolean; |
f937473f RD |
2453 | -- In general we cannot inline functions that return unconstrained type. |
2454 | -- However, we can handle such functions if all return statements return | |
2455 | -- a local variable that is the only declaration in the body of the | |
2456 | -- function. In that case the call can be replaced by that local | |
2457 | -- variable as is done for other inlined calls. | |
c8ef728f | 2458 | |
fbf5a39b | 2459 | procedure Remove_Pragmas; |
76a69663 ES |
2460 | -- A pragma Unreferenced or pragma Unmodified that mentions a formal |
2461 | -- parameter has no meaning when the body is inlined and the formals | |
2462 | -- are rewritten. Remove it from body to inline. The analysis of the | |
2463 | -- non-inlined body will handle the pragma properly. | |
996ae0b0 | 2464 | |
e895b435 ES |
2465 | function Uses_Secondary_Stack (Bod : Node_Id) return Boolean; |
2466 | -- If the body of the subprogram includes a call that returns an | |
2467 | -- unconstrained type, the secondary stack is involved, and it | |
2468 | -- is not worth inlining. | |
2469 | ||
996ae0b0 RK |
2470 | ------------------------------ |
2471 | -- Has_Excluded_Declaration -- | |
2472 | ------------------------------ | |
2473 | ||
2474 | function Has_Excluded_Declaration (Decls : List_Id) return Boolean is | |
2475 | D : Node_Id; | |
2476 | ||
fbf5a39b | 2477 | function Is_Unchecked_Conversion (D : Node_Id) return Boolean; |
82c80734 RD |
2478 | -- Nested subprograms make a given body ineligible for inlining, but |
2479 | -- we make an exception for instantiations of unchecked conversion. | |
2480 | -- The body has not been analyzed yet, so check the name, and verify | |
2481 | -- that the visible entity with that name is the predefined unit. | |
2482 | ||
2483 | ----------------------------- | |
2484 | -- Is_Unchecked_Conversion -- | |
2485 | ----------------------------- | |
fbf5a39b AC |
2486 | |
2487 | function Is_Unchecked_Conversion (D : Node_Id) return Boolean is | |
82c80734 | 2488 | Id : constant Node_Id := Name (D); |
fbf5a39b AC |
2489 | Conv : Entity_Id; |
2490 | ||
2491 | begin | |
2492 | if Nkind (Id) = N_Identifier | |
2493 | and then Chars (Id) = Name_Unchecked_Conversion | |
2494 | then | |
2495 | Conv := Current_Entity (Id); | |
2496 | ||
800621e0 | 2497 | elsif Nkind_In (Id, N_Selected_Component, N_Expanded_Name) |
fbf5a39b AC |
2498 | and then Chars (Selector_Name (Id)) = Name_Unchecked_Conversion |
2499 | then | |
2500 | Conv := Current_Entity (Selector_Name (Id)); | |
fbf5a39b AC |
2501 | else |
2502 | return False; | |
2503 | end if; | |
2504 | ||
758c442c GD |
2505 | return Present (Conv) |
2506 | and then Is_Predefined_File_Name | |
2507 | (Unit_File_Name (Get_Source_Unit (Conv))) | |
fbf5a39b AC |
2508 | and then Is_Intrinsic_Subprogram (Conv); |
2509 | end Is_Unchecked_Conversion; | |
2510 | ||
2511 | -- Start of processing for Has_Excluded_Declaration | |
2512 | ||
996ae0b0 RK |
2513 | begin |
2514 | D := First (Decls); | |
996ae0b0 | 2515 | while Present (D) loop |
800621e0 RD |
2516 | if (Nkind (D) = N_Function_Instantiation |
2517 | and then not Is_Unchecked_Conversion (D)) | |
2518 | or else Nkind_In (D, N_Protected_Type_Declaration, | |
2519 | N_Package_Declaration, | |
2520 | N_Package_Instantiation, | |
2521 | N_Subprogram_Body, | |
2522 | N_Procedure_Instantiation, | |
2523 | N_Task_Type_Declaration) | |
996ae0b0 RK |
2524 | then |
2525 | Cannot_Inline | |
fbf5a39b | 2526 | ("cannot inline & (non-allowed declaration)?", D, Subp); |
996ae0b0 RK |
2527 | return True; |
2528 | end if; | |
2529 | ||
2530 | Next (D); | |
2531 | end loop; | |
2532 | ||
2533 | return False; | |
996ae0b0 RK |
2534 | end Has_Excluded_Declaration; |
2535 | ||
2536 | ---------------------------- | |
2537 | -- Has_Excluded_Statement -- | |
2538 | ---------------------------- | |
2539 | ||
2540 | function Has_Excluded_Statement (Stats : List_Id) return Boolean is | |
2541 | S : Node_Id; | |
2542 | E : Node_Id; | |
2543 | ||
2544 | begin | |
2545 | S := First (Stats); | |
996ae0b0 RK |
2546 | while Present (S) loop |
2547 | Stat_Count := Stat_Count + 1; | |
2548 | ||
800621e0 RD |
2549 | if Nkind_In (S, N_Abort_Statement, |
2550 | N_Asynchronous_Select, | |
2551 | N_Conditional_Entry_Call, | |
2552 | N_Delay_Relative_Statement, | |
2553 | N_Delay_Until_Statement, | |
2554 | N_Selective_Accept, | |
2555 | N_Timed_Entry_Call) | |
996ae0b0 RK |
2556 | then |
2557 | Cannot_Inline | |
fbf5a39b | 2558 | ("cannot inline & (non-allowed statement)?", S, Subp); |
996ae0b0 RK |
2559 | return True; |
2560 | ||
2561 | elsif Nkind (S) = N_Block_Statement then | |
2562 | if Present (Declarations (S)) | |
2563 | and then Has_Excluded_Declaration (Declarations (S)) | |
2564 | then | |
2565 | return True; | |
2566 | ||
2567 | elsif Present (Handled_Statement_Sequence (S)) | |
2568 | and then | |
2569 | (Present | |
2570 | (Exception_Handlers (Handled_Statement_Sequence (S))) | |
2571 | or else | |
2572 | Has_Excluded_Statement | |
2573 | (Statements (Handled_Statement_Sequence (S)))) | |
2574 | then | |
2575 | return True; | |
2576 | end if; | |
2577 | ||
2578 | elsif Nkind (S) = N_Case_Statement then | |
2579 | E := First (Alternatives (S)); | |
996ae0b0 RK |
2580 | while Present (E) loop |
2581 | if Has_Excluded_Statement (Statements (E)) then | |
2582 | return True; | |
2583 | end if; | |
2584 | ||
2585 | Next (E); | |
2586 | end loop; | |
2587 | ||
2588 | elsif Nkind (S) = N_If_Statement then | |
2589 | if Has_Excluded_Statement (Then_Statements (S)) then | |
2590 | return True; | |
2591 | end if; | |
2592 | ||
2593 | if Present (Elsif_Parts (S)) then | |
2594 | E := First (Elsif_Parts (S)); | |
996ae0b0 RK |
2595 | while Present (E) loop |
2596 | if Has_Excluded_Statement (Then_Statements (E)) then | |
2597 | return True; | |
2598 | end if; | |
2599 | Next (E); | |
2600 | end loop; | |
2601 | end if; | |
2602 | ||
2603 | if Present (Else_Statements (S)) | |
2604 | and then Has_Excluded_Statement (Else_Statements (S)) | |
2605 | then | |
2606 | return True; | |
2607 | end if; | |
2608 | ||
2609 | elsif Nkind (S) = N_Loop_Statement | |
2610 | and then Has_Excluded_Statement (Statements (S)) | |
2611 | then | |
2612 | return True; | |
2613 | end if; | |
2614 | ||
2615 | Next (S); | |
2616 | end loop; | |
2617 | ||
2618 | return False; | |
2619 | end Has_Excluded_Statement; | |
2620 | ||
2621 | ------------------------------- | |
2622 | -- Has_Pending_Instantiation -- | |
2623 | ------------------------------- | |
2624 | ||
2625 | function Has_Pending_Instantiation return Boolean is | |
ec4867fa | 2626 | S : Entity_Id; |
996ae0b0 RK |
2627 | |
2628 | begin | |
ec4867fa | 2629 | S := Current_Scope; |
996ae0b0 RK |
2630 | while Present (S) loop |
2631 | if Is_Compilation_Unit (S) | |
2632 | or else Is_Child_Unit (S) | |
2633 | then | |
2634 | return False; | |
2635 | elsif Ekind (S) = E_Package | |
2636 | and then Has_Forward_Instantiation (S) | |
2637 | then | |
2638 | return True; | |
2639 | end if; | |
2640 | ||
2641 | S := Scope (S); | |
2642 | end loop; | |
2643 | ||
2644 | return False; | |
2645 | end Has_Pending_Instantiation; | |
2646 | ||
c8ef728f ES |
2647 | ------------------------ |
2648 | -- Has_Single_Return -- | |
2649 | ------------------------ | |
2650 | ||
2651 | function Has_Single_Return return Boolean is | |
2652 | Return_Statement : Node_Id := Empty; | |
2653 | ||
2654 | function Check_Return (N : Node_Id) return Traverse_Result; | |
2655 | ||
2656 | ------------------ | |
2657 | -- Check_Return -- | |
2658 | ------------------ | |
2659 | ||
2660 | function Check_Return (N : Node_Id) return Traverse_Result is | |
2661 | begin | |
5d37ba92 | 2662 | if Nkind (N) = N_Simple_Return_Statement then |
c8ef728f ES |
2663 | if Present (Expression (N)) |
2664 | and then Is_Entity_Name (Expression (N)) | |
2665 | then | |
2666 | if No (Return_Statement) then | |
2667 | Return_Statement := N; | |
2668 | return OK; | |
2669 | ||
2670 | elsif Chars (Expression (N)) = | |
2671 | Chars (Expression (Return_Statement)) | |
2672 | then | |
2673 | return OK; | |
2674 | ||
2675 | else | |
2676 | return Abandon; | |
2677 | end if; | |
2678 | ||
2679 | else | |
2680 | -- Expression has wrong form | |
2681 | ||
2682 | return Abandon; | |
2683 | end if; | |
2684 | ||
2685 | else | |
2686 | return OK; | |
2687 | end if; | |
2688 | end Check_Return; | |
2689 | ||
2690 | function Check_All_Returns is new Traverse_Func (Check_Return); | |
2691 | ||
2692 | -- Start of processing for Has_Single_Return | |
2693 | ||
2694 | begin | |
08402a6d ES |
2695 | return Check_All_Returns (N) = OK |
2696 | and then Present (Declarations (N)) | |
0a36105d | 2697 | and then Present (First (Declarations (N))) |
08402a6d ES |
2698 | and then Chars (Expression (Return_Statement)) = |
2699 | Chars (Defining_Identifier (First (Declarations (N)))); | |
c8ef728f ES |
2700 | end Has_Single_Return; |
2701 | ||
fbf5a39b AC |
2702 | -------------------- |
2703 | -- Remove_Pragmas -- | |
2704 | -------------------- | |
2705 | ||
2706 | procedure Remove_Pragmas is | |
2707 | Decl : Node_Id; | |
2708 | Nxt : Node_Id; | |
2709 | ||
2710 | begin | |
2711 | Decl := First (Declarations (Body_To_Analyze)); | |
2712 | while Present (Decl) loop | |
2713 | Nxt := Next (Decl); | |
2714 | ||
2715 | if Nkind (Decl) = N_Pragma | |
76a69663 ES |
2716 | and then (Pragma_Name (Decl) = Name_Unreferenced |
2717 | or else | |
2718 | Pragma_Name (Decl) = Name_Unmodified) | |
fbf5a39b AC |
2719 | then |
2720 | Remove (Decl); | |
2721 | end if; | |
2722 | ||
2723 | Decl := Nxt; | |
2724 | end loop; | |
2725 | end Remove_Pragmas; | |
2726 | ||
e895b435 ES |
2727 | -------------------------- |
2728 | -- Uses_Secondary_Stack -- | |
2729 | -------------------------- | |
2730 | ||
2731 | function Uses_Secondary_Stack (Bod : Node_Id) return Boolean is | |
2732 | function Check_Call (N : Node_Id) return Traverse_Result; | |
2733 | -- Look for function calls that return an unconstrained type | |
2734 | ||
2735 | ---------------- | |
2736 | -- Check_Call -- | |
2737 | ---------------- | |
2738 | ||
2739 | function Check_Call (N : Node_Id) return Traverse_Result is | |
2740 | begin | |
2741 | if Nkind (N) = N_Function_Call | |
2742 | and then Is_Entity_Name (Name (N)) | |
2743 | and then Is_Composite_Type (Etype (Entity (Name (N)))) | |
2744 | and then not Is_Constrained (Etype (Entity (Name (N)))) | |
2745 | then | |
2746 | Cannot_Inline | |
2747 | ("cannot inline & (call returns unconstrained type)?", | |
2748 | N, Subp); | |
2749 | return Abandon; | |
2750 | else | |
2751 | return OK; | |
2752 | end if; | |
2753 | end Check_Call; | |
2754 | ||
2755 | function Check_Calls is new Traverse_Func (Check_Call); | |
2756 | ||
2757 | begin | |
2758 | return Check_Calls (Bod) = Abandon; | |
2759 | end Uses_Secondary_Stack; | |
2760 | ||
996ae0b0 RK |
2761 | -- Start of processing for Build_Body_To_Inline |
2762 | ||
2763 | begin | |
2764 | if Nkind (Decl) = N_Subprogram_Declaration | |
2765 | and then Present (Body_To_Inline (Decl)) | |
2766 | then | |
d05ef0ab | 2767 | return; -- Done already. |
996ae0b0 | 2768 | |
08402a6d ES |
2769 | -- Functions that return unconstrained composite types require |
2770 | -- secondary stack handling, and cannot currently be inlined, unless | |
2771 | -- all return statements return a local variable that is the first | |
2772 | -- local declaration in the body. | |
996ae0b0 RK |
2773 | |
2774 | elsif Ekind (Subp) = E_Function | |
2775 | and then not Is_Scalar_Type (Etype (Subp)) | |
2776 | and then not Is_Access_Type (Etype (Subp)) | |
2777 | and then not Is_Constrained (Etype (Subp)) | |
2778 | then | |
08402a6d ES |
2779 | if not Has_Single_Return then |
2780 | Cannot_Inline | |
2781 | ("cannot inline & (unconstrained return type)?", N, Subp); | |
2782 | return; | |
2783 | end if; | |
2784 | ||
2785 | -- Ditto for functions that return controlled types, where controlled | |
2786 | -- actions interfere in complex ways with inlining. | |
2820d220 AC |
2787 | |
2788 | elsif Ekind (Subp) = E_Function | |
2789 | and then Controlled_Type (Etype (Subp)) | |
2790 | then | |
2791 | Cannot_Inline | |
2792 | ("cannot inline & (controlled return type)?", N, Subp); | |
2793 | return; | |
996ae0b0 RK |
2794 | end if; |
2795 | ||
d05ef0ab AC |
2796 | if Present (Declarations (N)) |
2797 | and then Has_Excluded_Declaration (Declarations (N)) | |
996ae0b0 | 2798 | then |
d05ef0ab | 2799 | return; |
996ae0b0 RK |
2800 | end if; |
2801 | ||
2802 | if Present (Handled_Statement_Sequence (N)) then | |
fbf5a39b AC |
2803 | if Present (Exception_Handlers (Handled_Statement_Sequence (N))) then |
2804 | Cannot_Inline | |
2805 | ("cannot inline& (exception handler)?", | |
2806 | First (Exception_Handlers (Handled_Statement_Sequence (N))), | |
2807 | Subp); | |
d05ef0ab | 2808 | return; |
996ae0b0 RK |
2809 | elsif |
2810 | Has_Excluded_Statement | |
2811 | (Statements (Handled_Statement_Sequence (N))) | |
2812 | then | |
d05ef0ab | 2813 | return; |
996ae0b0 RK |
2814 | end if; |
2815 | end if; | |
2816 | ||
2817 | -- We do not inline a subprogram that is too large, unless it is | |
2818 | -- marked Inline_Always. This pragma does not suppress the other | |
2819 | -- checks on inlining (forbidden declarations, handlers, etc). | |
2820 | ||
2821 | if Stat_Count > Max_Size | |
800621e0 | 2822 | and then not Has_Pragma_Inline_Always (Subp) |
996ae0b0 | 2823 | then |
fbf5a39b | 2824 | Cannot_Inline ("cannot inline& (body too large)?", N, Subp); |
d05ef0ab | 2825 | return; |
996ae0b0 RK |
2826 | end if; |
2827 | ||
2828 | if Has_Pending_Instantiation then | |
2829 | Cannot_Inline | |
fbf5a39b AC |
2830 | ("cannot inline& (forward instance within enclosing body)?", |
2831 | N, Subp); | |
d05ef0ab AC |
2832 | return; |
2833 | end if; | |
2834 | ||
2835 | -- Within an instance, the body to inline must be treated as a nested | |
2836 | -- generic, so that the proper global references are preserved. | |
2837 | ||
2838 | if In_Instance then | |
2839 | Save_Env (Scope (Current_Scope), Scope (Current_Scope)); | |
2840 | Original_Body := Copy_Generic_Node (N, Empty, True); | |
2841 | else | |
2842 | Original_Body := Copy_Separate_Tree (N); | |
996ae0b0 RK |
2843 | end if; |
2844 | ||
d05ef0ab AC |
2845 | -- We need to capture references to the formals in order to substitute |
2846 | -- the actuals at the point of inlining, i.e. instantiation. To treat | |
2847 | -- the formals as globals to the body to inline, we nest it within | |
2848 | -- a dummy parameterless subprogram, declared within the real one. | |
24105bab AC |
2849 | -- To avoid generating an internal name (which is never public, and |
2850 | -- which affects serial numbers of other generated names), we use | |
2851 | -- an internal symbol that cannot conflict with user declarations. | |
d05ef0ab AC |
2852 | |
2853 | Set_Parameter_Specifications (Specification (Original_Body), No_List); | |
24105bab AC |
2854 | Set_Defining_Unit_Name |
2855 | (Specification (Original_Body), | |
2856 | Make_Defining_Identifier (Sloc (N), Name_uParent)); | |
d05ef0ab AC |
2857 | Set_Corresponding_Spec (Original_Body, Empty); |
2858 | ||
996ae0b0 RK |
2859 | Body_To_Analyze := Copy_Generic_Node (Original_Body, Empty, False); |
2860 | ||
2861 | -- Set return type of function, which is also global and does not need | |
2862 | -- to be resolved. | |
2863 | ||
2864 | if Ekind (Subp) = E_Function then | |
41251c60 | 2865 | Set_Result_Definition (Specification (Body_To_Analyze), |
996ae0b0 RK |
2866 | New_Occurrence_Of (Etype (Subp), Sloc (N))); |
2867 | end if; | |
2868 | ||
2869 | if No (Declarations (N)) then | |
2870 | Set_Declarations (N, New_List (Body_To_Analyze)); | |
2871 | else | |
2872 | Append (Body_To_Analyze, Declarations (N)); | |
2873 | end if; | |
2874 | ||
2875 | Expander_Mode_Save_And_Set (False); | |
fbf5a39b | 2876 | Remove_Pragmas; |
996ae0b0 RK |
2877 | |
2878 | Analyze (Body_To_Analyze); | |
0a36105d | 2879 | Push_Scope (Defining_Entity (Body_To_Analyze)); |
996ae0b0 RK |
2880 | Save_Global_References (Original_Body); |
2881 | End_Scope; | |
2882 | Remove (Body_To_Analyze); | |
2883 | ||
2884 | Expander_Mode_Restore; | |
d05ef0ab AC |
2885 | |
2886 | if In_Instance then | |
2887 | Restore_Env; | |
2888 | end if; | |
e895b435 ES |
2889 | |
2890 | -- If secondary stk used there is no point in inlining. We have | |
2891 | -- already issued the warning in this case, so nothing to do. | |
2892 | ||
2893 | if Uses_Secondary_Stack (Body_To_Analyze) then | |
2894 | return; | |
2895 | end if; | |
2896 | ||
2897 | Set_Body_To_Inline (Decl, Original_Body); | |
2898 | Set_Ekind (Defining_Entity (Original_Body), Ekind (Subp)); | |
2899 | Set_Is_Inlined (Subp); | |
996ae0b0 RK |
2900 | end Build_Body_To_Inline; |
2901 | ||
fbf5a39b AC |
2902 | ------------------- |
2903 | -- Cannot_Inline -- | |
2904 | ------------------- | |
2905 | ||
2906 | procedure Cannot_Inline (Msg : String; N : Node_Id; Subp : Entity_Id) is | |
2907 | begin | |
2908 | -- Do not emit warning if this is a predefined unit which is not | |
2909 | -- the main unit. With validity checks enabled, some predefined | |
2910 | -- subprograms may contain nested subprograms and become ineligible | |
2911 | -- for inlining. | |
2912 | ||
2913 | if Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Subp))) | |
2914 | and then not In_Extended_Main_Source_Unit (Subp) | |
2915 | then | |
2916 | null; | |
2917 | ||
800621e0 | 2918 | elsif Has_Pragma_Inline_Always (Subp) then |
e895b435 ES |
2919 | |
2920 | -- Remove last character (question mark) to make this into an error, | |
2921 | -- because the Inline_Always pragma cannot be obeyed. | |
2922 | ||
ec4867fa | 2923 | Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp); |
fbf5a39b AC |
2924 | |
2925 | elsif Ineffective_Inline_Warnings then | |
2926 | Error_Msg_NE (Msg, N, Subp); | |
2927 | end if; | |
2928 | end Cannot_Inline; | |
2929 | ||
996ae0b0 RK |
2930 | ----------------------- |
2931 | -- Check_Conformance -- | |
2932 | ----------------------- | |
2933 | ||
2934 | procedure Check_Conformance | |
41251c60 JM |
2935 | (New_Id : Entity_Id; |
2936 | Old_Id : Entity_Id; | |
2937 | Ctype : Conformance_Type; | |
2938 | Errmsg : Boolean; | |
2939 | Conforms : out Boolean; | |
2940 | Err_Loc : Node_Id := Empty; | |
2941 | Get_Inst : Boolean := False; | |
2942 | Skip_Controlling_Formals : Boolean := False) | |
996ae0b0 | 2943 | is |
996ae0b0 | 2944 | procedure Conformance_Error (Msg : String; N : Node_Id := New_Id); |
82c80734 RD |
2945 | -- Post error message for conformance error on given node. Two messages |
2946 | -- are output. The first points to the previous declaration with a | |
2947 | -- general "no conformance" message. The second is the detailed reason, | |
2948 | -- supplied as Msg. The parameter N provide information for a possible | |
2949 | -- & insertion in the message, and also provides the location for | |
2950 | -- posting the message in the absence of a specified Err_Loc location. | |
996ae0b0 RK |
2951 | |
2952 | ----------------------- | |
2953 | -- Conformance_Error -- | |
2954 | ----------------------- | |
2955 | ||
2956 | procedure Conformance_Error (Msg : String; N : Node_Id := New_Id) is | |
2957 | Enode : Node_Id; | |
2958 | ||
2959 | begin | |
2960 | Conforms := False; | |
2961 | ||
2962 | if Errmsg then | |
2963 | if No (Err_Loc) then | |
2964 | Enode := N; | |
2965 | else | |
2966 | Enode := Err_Loc; | |
2967 | end if; | |
2968 | ||
2969 | Error_Msg_Sloc := Sloc (Old_Id); | |
2970 | ||
2971 | case Ctype is | |
2972 | when Type_Conformant => | |
2973 | Error_Msg_N | |
2974 | ("not type conformant with declaration#!", Enode); | |
2975 | ||
2976 | when Mode_Conformant => | |
19590d70 GD |
2977 | if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then |
2978 | Error_Msg_N | |
2979 | ("not mode conformant with operation inherited#!", | |
2980 | Enode); | |
2981 | else | |
2982 | Error_Msg_N | |
2983 | ("not mode conformant with declaration#!", Enode); | |
2984 | end if; | |
996ae0b0 RK |
2985 | |
2986 | when Subtype_Conformant => | |
19590d70 GD |
2987 | if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then |
2988 | Error_Msg_N | |
2989 | ("not subtype conformant with operation inherited#!", | |
2990 | Enode); | |
2991 | else | |
2992 | Error_Msg_N | |
2993 | ("not subtype conformant with declaration#!", Enode); | |
2994 | end if; | |
996ae0b0 RK |
2995 | |
2996 | when Fully_Conformant => | |
19590d70 GD |
2997 | if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then |
2998 | Error_Msg_N | |
2999 | ("not fully conformant with operation inherited#!", | |
3000 | Enode); | |
3001 | else | |
3002 | Error_Msg_N | |
3003 | ("not fully conformant with declaration#!", Enode); | |
3004 | end if; | |
996ae0b0 RK |
3005 | end case; |
3006 | ||
3007 | Error_Msg_NE (Msg, Enode, N); | |
3008 | end if; | |
3009 | end Conformance_Error; | |
3010 | ||
ec4867fa ES |
3011 | -- Local Variables |
3012 | ||
3013 | Old_Type : constant Entity_Id := Etype (Old_Id); | |
3014 | New_Type : constant Entity_Id := Etype (New_Id); | |
3015 | Old_Formal : Entity_Id; | |
3016 | New_Formal : Entity_Id; | |
3017 | Access_Types_Match : Boolean; | |
3018 | Old_Formal_Base : Entity_Id; | |
3019 | New_Formal_Base : Entity_Id; | |
3020 | ||
996ae0b0 RK |
3021 | -- Start of processing for Check_Conformance |
3022 | ||
3023 | begin | |
3024 | Conforms := True; | |
3025 | ||
82c80734 RD |
3026 | -- We need a special case for operators, since they don't appear |
3027 | -- explicitly. | |
996ae0b0 RK |
3028 | |
3029 | if Ctype = Type_Conformant then | |
3030 | if Ekind (New_Id) = E_Operator | |
3031 | and then Operator_Matches_Spec (New_Id, Old_Id) | |
3032 | then | |
3033 | return; | |
3034 | end if; | |
3035 | end if; | |
3036 | ||
3037 | -- If both are functions/operators, check return types conform | |
3038 | ||
3039 | if Old_Type /= Standard_Void_Type | |
3040 | and then New_Type /= Standard_Void_Type | |
3041 | then | |
3042 | if not Conforming_Types (Old_Type, New_Type, Ctype, Get_Inst) then | |
5d37ba92 | 3043 | Conformance_Error ("\return type does not match!", New_Id); |
996ae0b0 RK |
3044 | return; |
3045 | end if; | |
3046 | ||
41251c60 | 3047 | -- Ada 2005 (AI-231): In case of anonymous access types check the |
0a36105d | 3048 | -- null-exclusion and access-to-constant attributes match. |
41251c60 JM |
3049 | |
3050 | if Ada_Version >= Ada_05 | |
3051 | and then Ekind (Etype (Old_Type)) = E_Anonymous_Access_Type | |
3052 | and then | |
3053 | (Can_Never_Be_Null (Old_Type) | |
3054 | /= Can_Never_Be_Null (New_Type) | |
3055 | or else Is_Access_Constant (Etype (Old_Type)) | |
3056 | /= Is_Access_Constant (Etype (New_Type))) | |
3057 | then | |
5d37ba92 | 3058 | Conformance_Error ("\return type does not match!", New_Id); |
41251c60 JM |
3059 | return; |
3060 | end if; | |
3061 | ||
996ae0b0 RK |
3062 | -- If either is a function/operator and the other isn't, error |
3063 | ||
3064 | elsif Old_Type /= Standard_Void_Type | |
3065 | or else New_Type /= Standard_Void_Type | |
3066 | then | |
5d37ba92 | 3067 | Conformance_Error ("\functions can only match functions!", New_Id); |
996ae0b0 RK |
3068 | return; |
3069 | end if; | |
3070 | ||
0a36105d | 3071 | -- In subtype conformant case, conventions must match (RM 6.3.1(16)). |
996ae0b0 RK |
3072 | -- If this is a renaming as body, refine error message to indicate that |
3073 | -- the conflict is with the original declaration. If the entity is not | |
3074 | -- frozen, the conventions don't have to match, the one of the renamed | |
3075 | -- entity is inherited. | |
3076 | ||
3077 | if Ctype >= Subtype_Conformant then | |
996ae0b0 RK |
3078 | if Convention (Old_Id) /= Convention (New_Id) then |
3079 | ||
3080 | if not Is_Frozen (New_Id) then | |
3081 | null; | |
3082 | ||
3083 | elsif Present (Err_Loc) | |
3084 | and then Nkind (Err_Loc) = N_Subprogram_Renaming_Declaration | |
3085 | and then Present (Corresponding_Spec (Err_Loc)) | |
3086 | then | |
3087 | Error_Msg_Name_1 := Chars (New_Id); | |
3088 | Error_Msg_Name_2 := | |
3089 | Name_Ada + Convention_Id'Pos (Convention (New_Id)); | |
3090 | ||
5d37ba92 | 3091 | Conformance_Error ("\prior declaration for% has convention %!"); |
996ae0b0 RK |
3092 | |
3093 | else | |
5d37ba92 | 3094 | Conformance_Error ("\calling conventions do not match!"); |
996ae0b0 RK |
3095 | end if; |
3096 | ||
3097 | return; | |
3098 | ||
3099 | elsif Is_Formal_Subprogram (Old_Id) | |
3100 | or else Is_Formal_Subprogram (New_Id) | |
3101 | then | |
5d37ba92 | 3102 | Conformance_Error ("\formal subprograms not allowed!"); |
996ae0b0 RK |
3103 | return; |
3104 | end if; | |
3105 | end if; | |
3106 | ||
3107 | -- Deal with parameters | |
3108 | ||
3109 | -- Note: we use the entity information, rather than going directly | |
3110 | -- to the specification in the tree. This is not only simpler, but | |
3111 | -- absolutely necessary for some cases of conformance tests between | |
3112 | -- operators, where the declaration tree simply does not exist! | |
3113 | ||
3114 | Old_Formal := First_Formal (Old_Id); | |
3115 | New_Formal := First_Formal (New_Id); | |
3116 | ||
3117 | while Present (Old_Formal) and then Present (New_Formal) loop | |
41251c60 JM |
3118 | if Is_Controlling_Formal (Old_Formal) |
3119 | and then Is_Controlling_Formal (New_Formal) | |
3120 | and then Skip_Controlling_Formals | |
3121 | then | |
3122 | goto Skip_Controlling_Formal; | |
3123 | end if; | |
3124 | ||
fbf5a39b AC |
3125 | if Ctype = Fully_Conformant then |
3126 | ||
3127 | -- Names must match. Error message is more accurate if we do | |
3128 | -- this before checking that the types of the formals match. | |
3129 | ||
3130 | if Chars (Old_Formal) /= Chars (New_Formal) then | |
5d37ba92 | 3131 | Conformance_Error ("\name & does not match!", New_Formal); |
fbf5a39b AC |
3132 | |
3133 | -- Set error posted flag on new formal as well to stop | |
3134 | -- junk cascaded messages in some cases. | |
3135 | ||
3136 | Set_Error_Posted (New_Formal); | |
3137 | return; | |
3138 | end if; | |
3139 | end if; | |
996ae0b0 | 3140 | |
ec4867fa ES |
3141 | -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This |
3142 | -- case occurs whenever a subprogram is being renamed and one of its | |
3143 | -- parameters imposes a null exclusion. For example: | |
3144 | ||
3145 | -- type T is null record; | |
3146 | -- type Acc_T is access T; | |
3147 | -- subtype Acc_T_Sub is Acc_T; | |
3148 | ||
3149 | -- procedure P (Obj : not null Acc_T_Sub); -- itype | |
3150 | -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype | |
3151 | -- renames P; | |
3152 | ||
3153 | Old_Formal_Base := Etype (Old_Formal); | |
3154 | New_Formal_Base := Etype (New_Formal); | |
3155 | ||
3156 | if Get_Inst then | |
3157 | Old_Formal_Base := Get_Instance_Of (Old_Formal_Base); | |
3158 | New_Formal_Base := Get_Instance_Of (New_Formal_Base); | |
3159 | end if; | |
3160 | ||
3161 | Access_Types_Match := Ada_Version >= Ada_05 | |
3162 | ||
3163 | -- Ensure that this rule is only applied when New_Id is a | |
5d37ba92 | 3164 | -- renaming of Old_Id. |
ec4867fa | 3165 | |
5d37ba92 ES |
3166 | and then Nkind (Parent (Parent (New_Id))) = |
3167 | N_Subprogram_Renaming_Declaration | |
ec4867fa ES |
3168 | and then Nkind (Name (Parent (Parent (New_Id)))) in N_Has_Entity |
3169 | and then Present (Entity (Name (Parent (Parent (New_Id))))) | |
3170 | and then Entity (Name (Parent (Parent (New_Id)))) = Old_Id | |
3171 | ||
3172 | -- Now handle the allowed access-type case | |
3173 | ||
3174 | and then Is_Access_Type (Old_Formal_Base) | |
3175 | and then Is_Access_Type (New_Formal_Base) | |
5d37ba92 ES |
3176 | |
3177 | -- The type kinds must match. The only exception occurs with | |
3178 | -- multiple generics of the form: | |
3179 | ||
3180 | -- generic generic | |
3181 | -- type F is private; type A is private; | |
3182 | -- type F_Ptr is access F; type A_Ptr is access A; | |
3183 | -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr); | |
3184 | -- package F_Pack is ... package A_Pack is | |
3185 | -- package F_Inst is | |
3186 | -- new F_Pack (A, A_Ptr, A_P); | |
3187 | ||
3188 | -- When checking for conformance between the parameters of A_P | |
3189 | -- and F_P, the type kinds of F_Ptr and A_Ptr will not match | |
3190 | -- because the compiler has transformed A_Ptr into a subtype of | |
3191 | -- F_Ptr. We catch this case in the code below. | |
3192 | ||
3193 | and then (Ekind (Old_Formal_Base) = Ekind (New_Formal_Base) | |
3194 | or else | |
3195 | (Is_Generic_Type (Old_Formal_Base) | |
3196 | and then Is_Generic_Type (New_Formal_Base) | |
3197 | and then Is_Internal (New_Formal_Base) | |
3198 | and then Etype (Etype (New_Formal_Base)) = | |
3199 | Old_Formal_Base)) | |
ec4867fa ES |
3200 | and then Directly_Designated_Type (Old_Formal_Base) = |
3201 | Directly_Designated_Type (New_Formal_Base) | |
3202 | and then ((Is_Itype (Old_Formal_Base) | |
3203 | and then Can_Never_Be_Null (Old_Formal_Base)) | |
3204 | or else | |
3205 | (Is_Itype (New_Formal_Base) | |
3206 | and then Can_Never_Be_Null (New_Formal_Base))); | |
3207 | ||
996ae0b0 RK |
3208 | -- Types must always match. In the visible part of an instance, |
3209 | -- usual overloading rules for dispatching operations apply, and | |
3210 | -- we check base types (not the actual subtypes). | |
3211 | ||
3212 | if In_Instance_Visible_Part | |
3213 | and then Is_Dispatching_Operation (New_Id) | |
3214 | then | |
3215 | if not Conforming_Types | |
ec4867fa ES |
3216 | (T1 => Base_Type (Etype (Old_Formal)), |
3217 | T2 => Base_Type (Etype (New_Formal)), | |
3218 | Ctype => Ctype, | |
3219 | Get_Inst => Get_Inst) | |
3220 | and then not Access_Types_Match | |
996ae0b0 | 3221 | then |
5d37ba92 | 3222 | Conformance_Error ("\type of & does not match!", New_Formal); |
996ae0b0 RK |
3223 | return; |
3224 | end if; | |
3225 | ||
3226 | elsif not Conforming_Types | |
5d37ba92 ES |
3227 | (T1 => Old_Formal_Base, |
3228 | T2 => New_Formal_Base, | |
ec4867fa ES |
3229 | Ctype => Ctype, |
3230 | Get_Inst => Get_Inst) | |
3231 | and then not Access_Types_Match | |
996ae0b0 | 3232 | then |
5d37ba92 | 3233 | Conformance_Error ("\type of & does not match!", New_Formal); |
996ae0b0 RK |
3234 | return; |
3235 | end if; | |
3236 | ||
3237 | -- For mode conformance, mode must match | |
3238 | ||
5d37ba92 ES |
3239 | if Ctype >= Mode_Conformant then |
3240 | if Parameter_Mode (Old_Formal) /= Parameter_Mode (New_Formal) then | |
3241 | Conformance_Error ("\mode of & does not match!", New_Formal); | |
3242 | return; | |
3243 | ||
3244 | -- Part of mode conformance for access types is having the same | |
3245 | -- constant modifier. | |
3246 | ||
3247 | elsif Access_Types_Match | |
3248 | and then Is_Access_Constant (Old_Formal_Base) /= | |
3249 | Is_Access_Constant (New_Formal_Base) | |
3250 | then | |
3251 | Conformance_Error | |
3252 | ("\constant modifier does not match!", New_Formal); | |
3253 | return; | |
3254 | end if; | |
996ae0b0 RK |
3255 | end if; |
3256 | ||
0a36105d | 3257 | if Ctype >= Subtype_Conformant then |
996ae0b0 | 3258 | |
0a36105d JM |
3259 | -- Ada 2005 (AI-231): In case of anonymous access types check |
3260 | -- the null-exclusion and access-to-constant attributes must | |
3261 | -- match. | |
996ae0b0 | 3262 | |
0a36105d JM |
3263 | if Ada_Version >= Ada_05 |
3264 | and then Ekind (Etype (Old_Formal)) = E_Anonymous_Access_Type | |
3265 | and then Ekind (Etype (New_Formal)) = E_Anonymous_Access_Type | |
3266 | and then | |
3267 | (Can_Never_Be_Null (Old_Formal) /= | |
3268 | Can_Never_Be_Null (New_Formal) | |
3269 | or else | |
3270 | Is_Access_Constant (Etype (Old_Formal)) /= | |
3271 | Is_Access_Constant (Etype (New_Formal))) | |
3272 | then | |
3273 | -- It is allowed to omit the null-exclusion in case of stream | |
3274 | -- attribute subprograms. We recognize stream subprograms | |
3275 | -- through their TSS-generated suffix. | |
996ae0b0 | 3276 | |
0a36105d JM |
3277 | declare |
3278 | TSS_Name : constant TSS_Name_Type := Get_TSS_Name (New_Id); | |
3279 | begin | |
3280 | if TSS_Name /= TSS_Stream_Read | |
3281 | and then TSS_Name /= TSS_Stream_Write | |
3282 | and then TSS_Name /= TSS_Stream_Input | |
3283 | and then TSS_Name /= TSS_Stream_Output | |
3284 | then | |
3285 | Conformance_Error | |
5d37ba92 | 3286 | ("\type of & does not match!", New_Formal); |
0a36105d JM |
3287 | return; |
3288 | end if; | |
3289 | end; | |
3290 | end if; | |
3291 | end if; | |
41251c60 | 3292 | |
0a36105d | 3293 | -- Full conformance checks |
41251c60 | 3294 | |
0a36105d | 3295 | if Ctype = Fully_Conformant then |
e660dbf7 | 3296 | |
0a36105d | 3297 | -- We have checked already that names match |
e660dbf7 | 3298 | |
0a36105d | 3299 | if Parameter_Mode (Old_Formal) = E_In_Parameter then |
41251c60 JM |
3300 | |
3301 | -- Check default expressions for in parameters | |
3302 | ||
996ae0b0 RK |
3303 | declare |
3304 | NewD : constant Boolean := | |
3305 | Present (Default_Value (New_Formal)); | |
3306 | OldD : constant Boolean := | |
3307 | Present (Default_Value (Old_Formal)); | |
3308 | begin | |
3309 | if NewD or OldD then | |
3310 | ||
82c80734 RD |
3311 | -- The old default value has been analyzed because the |
3312 | -- current full declaration will have frozen everything | |
0a36105d JM |
3313 | -- before. The new default value has not been analyzed, |
3314 | -- so analyze it now before we check for conformance. | |
996ae0b0 RK |
3315 | |
3316 | if NewD then | |
0a36105d | 3317 | Push_Scope (New_Id); |
fbf5a39b AC |
3318 | Analyze_Per_Use_Expression |
3319 | (Default_Value (New_Formal), Etype (New_Formal)); | |
996ae0b0 RK |
3320 | End_Scope; |
3321 | end if; | |
3322 | ||
3323 | if not (NewD and OldD) | |
3324 | or else not Fully_Conformant_Expressions | |
3325 | (Default_Value (Old_Formal), | |
3326 | Default_Value (New_Formal)) | |
3327 | then | |
3328 | Conformance_Error | |
5d37ba92 | 3329 | ("\default expression for & does not match!", |
996ae0b0 RK |
3330 | New_Formal); |
3331 | return; | |
3332 | end if; | |
3333 | end if; | |
3334 | end; | |
3335 | end if; | |
3336 | end if; | |
3337 | ||
3338 | -- A couple of special checks for Ada 83 mode. These checks are | |
0a36105d | 3339 | -- skipped if either entity is an operator in package Standard, |
996ae0b0 RK |
3340 | -- or if either old or new instance is not from the source program. |
3341 | ||
0ab80019 | 3342 | if Ada_Version = Ada_83 |
996ae0b0 RK |
3343 | and then Sloc (Old_Id) > Standard_Location |
3344 | and then Sloc (New_Id) > Standard_Location | |
3345 | and then Comes_From_Source (Old_Id) | |
3346 | and then Comes_From_Source (New_Id) | |
3347 | then | |
3348 | declare | |
3349 | Old_Param : constant Node_Id := Declaration_Node (Old_Formal); | |
3350 | New_Param : constant Node_Id := Declaration_Node (New_Formal); | |
3351 | ||
3352 | begin | |
3353 | -- Explicit IN must be present or absent in both cases. This | |
3354 | -- test is required only in the full conformance case. | |
3355 | ||
3356 | if In_Present (Old_Param) /= In_Present (New_Param) | |
3357 | and then Ctype = Fully_Conformant | |
3358 | then | |
3359 | Conformance_Error | |
5d37ba92 | 3360 | ("\(Ada 83) IN must appear in both declarations", |
996ae0b0 RK |
3361 | New_Formal); |
3362 | return; | |
3363 | end if; | |
3364 | ||
3365 | -- Grouping (use of comma in param lists) must be the same | |
3366 | -- This is where we catch a misconformance like: | |
3367 | ||
0a36105d | 3368 | -- A, B : Integer |
996ae0b0 RK |
3369 | -- A : Integer; B : Integer |
3370 | ||
3371 | -- which are represented identically in the tree except | |
3372 | -- for the setting of the flags More_Ids and Prev_Ids. | |
3373 | ||
3374 | if More_Ids (Old_Param) /= More_Ids (New_Param) | |
3375 | or else Prev_Ids (Old_Param) /= Prev_Ids (New_Param) | |
3376 | then | |
3377 | Conformance_Error | |
5d37ba92 | 3378 | ("\grouping of & does not match!", New_Formal); |
996ae0b0 RK |
3379 | return; |
3380 | end if; | |
3381 | end; | |
3382 | end if; | |
3383 | ||
41251c60 JM |
3384 | -- This label is required when skipping controlling formals |
3385 | ||
3386 | <<Skip_Controlling_Formal>> | |
3387 | ||
996ae0b0 RK |
3388 | Next_Formal (Old_Formal); |
3389 | Next_Formal (New_Formal); | |
3390 | end loop; | |
3391 | ||
3392 | if Present (Old_Formal) then | |
5d37ba92 | 3393 | Conformance_Error ("\too few parameters!"); |
996ae0b0 RK |
3394 | return; |
3395 | ||
3396 | elsif Present (New_Formal) then | |
5d37ba92 | 3397 | Conformance_Error ("\too many parameters!", New_Formal); |
996ae0b0 RK |
3398 | return; |
3399 | end if; | |
996ae0b0 RK |
3400 | end Check_Conformance; |
3401 | ||
ec4867fa ES |
3402 | ----------------------- |
3403 | -- Check_Conventions -- | |
3404 | ----------------------- | |
3405 | ||
3406 | procedure Check_Conventions (Typ : Entity_Id) is | |
0a36105d JM |
3407 | |
3408 | function Skip_Check (Op : Entity_Id) return Boolean; | |
3409 | pragma Inline (Skip_Check); | |
3410 | -- A small optimization: skip the predefined dispatching operations, | |
3411 | -- since they always have the same convention. Also do not consider | |
3412 | -- abstract primitives since those are left by an erroneous overriding. | |
3413 | -- This function returns True for any operation that is thus exempted | |
3414 | -- exempted from checking. | |
3415 | ||
ec4867fa ES |
3416 | procedure Check_Convention |
3417 | (Op : Entity_Id; | |
3418 | Search_From : Elmt_Id); | |
0a36105d JM |
3419 | -- Verify that the convention of inherited dispatching operation Op is |
3420 | -- consistent among all subprograms it overrides. In order to minimize | |
3421 | -- the search, Search_From is utilized to designate a specific point in | |
3422 | -- the list rather than iterating over the whole list once more. | |
ec4867fa ES |
3423 | |
3424 | ---------------------- | |
3425 | -- Check_Convention -- | |
3426 | ---------------------- | |
3427 | ||
3428 | procedure Check_Convention | |
3429 | (Op : Entity_Id; | |
3430 | Search_From : Elmt_Id) | |
3431 | is | |
3432 | procedure Error_Msg_Operation (Op : Entity_Id); | |
0a36105d JM |
3433 | -- Emit a continuation to an error message depicting the kind, name, |
3434 | -- convention and source location of subprogram Op. | |
ec4867fa ES |
3435 | |
3436 | ------------------------- | |
3437 | -- Error_Msg_Operation -- | |
3438 | ------------------------- | |
3439 | ||
3440 | procedure Error_Msg_Operation (Op : Entity_Id) is | |
3441 | begin | |
3442 | Error_Msg_Name_1 := Chars (Op); | |
3443 | ||
3444 | -- Error messages of primitive subprograms do not contain a | |
0a36105d JM |
3445 | -- convention attribute since the convention may have been first |
3446 | -- inherited from a parent subprogram, then changed by a pragma. | |
ec4867fa ES |
3447 | |
3448 | if Comes_From_Source (Op) then | |
3449 | Error_Msg_Sloc := Sloc (Op); | |
3450 | Error_Msg_N | |
3451 | ("\ primitive % defined #", Typ); | |
3452 | ||
3453 | else | |
3454 | Error_Msg_Name_2 := Get_Convention_Name (Convention (Op)); | |
3455 | ||
3456 | if Present (Abstract_Interface_Alias (Op)) then | |
3457 | Error_Msg_Sloc := Sloc (Abstract_Interface_Alias (Op)); | |
3458 | Error_Msg_N ("\\overridden operation % with " & | |
3459 | "convention % defined #", Typ); | |
3460 | ||
3461 | else pragma Assert (Present (Alias (Op))); | |
3462 | Error_Msg_Sloc := Sloc (Alias (Op)); | |
3463 | Error_Msg_N ("\\inherited operation % with " & | |
3464 | "convention % defined #", Typ); | |
3465 | end if; | |
3466 | end if; | |
3467 | end Error_Msg_Operation; | |
3468 | ||
3469 | -- Local variables | |
3470 | ||
0a36105d JM |
3471 | Second_Prim_Op : Entity_Id; |
3472 | Second_Prim_Op_Elmt : Elmt_Id; | |
ec4867fa ES |
3473 | |
3474 | -- Start of processing for Check_Convention | |
3475 | ||
3476 | begin | |
0a36105d JM |
3477 | Second_Prim_Op_Elmt := Next_Elmt (Search_From); |
3478 | while Present (Second_Prim_Op_Elmt) loop | |
3479 | Second_Prim_Op := Node (Second_Prim_Op_Elmt); | |
3480 | ||
3481 | if not Skip_Check (Second_Prim_Op) | |
3482 | and then Chars (Second_Prim_Op) = Chars (Op) | |
3483 | and then Type_Conformant (Second_Prim_Op, Op) | |
3484 | and then Convention (Second_Prim_Op) /= Convention (Op) | |
ec4867fa ES |
3485 | then |
3486 | Error_Msg_N | |
3487 | ("inconsistent conventions in primitive operations", Typ); | |
3488 | ||
3489 | Error_Msg_Operation (Op); | |
0a36105d | 3490 | Error_Msg_Operation (Second_Prim_Op); |
ec4867fa ES |
3491 | |
3492 | -- Avoid cascading errors | |
3493 | ||
3494 | return; | |
3495 | end if; | |
3496 | ||
0a36105d | 3497 | Next_Elmt (Second_Prim_Op_Elmt); |
ec4867fa ES |
3498 | end loop; |
3499 | end Check_Convention; | |
3500 | ||
0a36105d JM |
3501 | ---------------- |
3502 | -- Skip_Check -- | |
3503 | ---------------- | |
3504 | ||
3505 | function Skip_Check (Op : Entity_Id) return Boolean is | |
3506 | begin | |
3507 | return Is_Predefined_Dispatching_Operation (Op) | |
3508 | or else Is_Abstract_Subprogram (Op); | |
3509 | end Skip_Check; | |
3510 | ||
ec4867fa ES |
3511 | -- Local variables |
3512 | ||
3513 | Prim_Op : Entity_Id; | |
3514 | Prim_Op_Elmt : Elmt_Id; | |
3515 | ||
3516 | -- Start of processing for Check_Conventions | |
3517 | ||
3518 | begin | |
0a36105d JM |
3519 | -- The algorithm checks every overriding dispatching operation against |
3520 | -- all the corresponding overridden dispatching operations, detecting | |
3521 | -- differences in coventions. | |
ec4867fa ES |
3522 | |
3523 | Prim_Op_Elmt := First_Elmt (Primitive_Operations (Typ)); | |
3524 | while Present (Prim_Op_Elmt) loop | |
3525 | Prim_Op := Node (Prim_Op_Elmt); | |
3526 | ||
0a36105d | 3527 | -- A small optimization: skip the predefined dispatching operations |
ec4867fa ES |
3528 | -- since they always have the same convention. Also avoid processing |
3529 | -- of abstract primitives left from an erroneous overriding. | |
3530 | ||
0a36105d | 3531 | if not Skip_Check (Prim_Op) then |
ec4867fa ES |
3532 | Check_Convention |
3533 | (Op => Prim_Op, | |
3534 | Search_From => Prim_Op_Elmt); | |
3535 | end if; | |
3536 | ||
3537 | Next_Elmt (Prim_Op_Elmt); | |
3538 | end loop; | |
3539 | end Check_Conventions; | |
3540 | ||
996ae0b0 RK |
3541 | ------------------------------ |
3542 | -- Check_Delayed_Subprogram -- | |
3543 | ------------------------------ | |
3544 | ||
3545 | procedure Check_Delayed_Subprogram (Designator : Entity_Id) is | |
3546 | F : Entity_Id; | |
3547 | ||
3548 | procedure Possible_Freeze (T : Entity_Id); | |
3549 | -- T is the type of either a formal parameter or of the return type. | |
3550 | -- If T is not yet frozen and needs a delayed freeze, then the | |
3551 | -- subprogram itself must be delayed. | |
3552 | ||
82c80734 RD |
3553 | --------------------- |
3554 | -- Possible_Freeze -- | |
3555 | --------------------- | |
3556 | ||
996ae0b0 RK |
3557 | procedure Possible_Freeze (T : Entity_Id) is |
3558 | begin | |
3559 | if Has_Delayed_Freeze (T) | |
3560 | and then not Is_Frozen (T) | |
3561 | then | |
3562 | Set_Has_Delayed_Freeze (Designator); | |
3563 | ||
3564 | elsif Is_Access_Type (T) | |
3565 | and then Has_Delayed_Freeze (Designated_Type (T)) | |
3566 | and then not Is_Frozen (Designated_Type (T)) | |
3567 | then | |
3568 | Set_Has_Delayed_Freeze (Designator); | |
3569 | end if; | |
3570 | end Possible_Freeze; | |
3571 | ||
3572 | -- Start of processing for Check_Delayed_Subprogram | |
3573 | ||
3574 | begin | |
3575 | -- Never need to freeze abstract subprogram | |
3576 | ||
f937473f RD |
3577 | if Ekind (Designator) /= E_Subprogram_Type |
3578 | and then Is_Abstract_Subprogram (Designator) | |
3579 | then | |
996ae0b0 RK |
3580 | null; |
3581 | else | |
3582 | -- Need delayed freeze if return type itself needs a delayed | |
3583 | -- freeze and is not yet frozen. | |
3584 | ||
3585 | Possible_Freeze (Etype (Designator)); | |
3586 | Possible_Freeze (Base_Type (Etype (Designator))); -- needed ??? | |
3587 | ||
3588 | -- Need delayed freeze if any of the formal types themselves need | |
3589 | -- a delayed freeze and are not yet frozen. | |
3590 | ||
3591 | F := First_Formal (Designator); | |
3592 | while Present (F) loop | |
3593 | Possible_Freeze (Etype (F)); | |
3594 | Possible_Freeze (Base_Type (Etype (F))); -- needed ??? | |
3595 | Next_Formal (F); | |
3596 | end loop; | |
3597 | end if; | |
3598 | ||
3599 | -- Mark functions that return by reference. Note that it cannot be | |
3600 | -- done for delayed_freeze subprograms because the underlying | |
3601 | -- returned type may not be known yet (for private types) | |
3602 | ||
3603 | if not Has_Delayed_Freeze (Designator) | |
3604 | and then Expander_Active | |
3605 | then | |
3606 | declare | |
3607 | Typ : constant Entity_Id := Etype (Designator); | |
3608 | Utyp : constant Entity_Id := Underlying_Type (Typ); | |
3609 | ||
3610 | begin | |
ec4867fa | 3611 | if Is_Inherently_Limited_Type (Typ) then |
996ae0b0 RK |
3612 | Set_Returns_By_Ref (Designator); |
3613 | ||
f937473f | 3614 | elsif Present (Utyp) and then CW_Or_Controlled_Type (Utyp) then |
996ae0b0 RK |
3615 | Set_Returns_By_Ref (Designator); |
3616 | end if; | |
3617 | end; | |
3618 | end if; | |
3619 | end Check_Delayed_Subprogram; | |
3620 | ||
3621 | ------------------------------------ | |
3622 | -- Check_Discriminant_Conformance -- | |
3623 | ------------------------------------ | |
3624 | ||
3625 | procedure Check_Discriminant_Conformance | |
3626 | (N : Node_Id; | |
3627 | Prev : Entity_Id; | |
3628 | Prev_Loc : Node_Id) | |
3629 | is | |
3630 | Old_Discr : Entity_Id := First_Discriminant (Prev); | |
3631 | New_Discr : Node_Id := First (Discriminant_Specifications (N)); | |
3632 | New_Discr_Id : Entity_Id; | |
3633 | New_Discr_Type : Entity_Id; | |
3634 | ||
3635 | procedure Conformance_Error (Msg : String; N : Node_Id); | |
82c80734 RD |
3636 | -- Post error message for conformance error on given node. Two messages |
3637 | -- are output. The first points to the previous declaration with a | |
3638 | -- general "no conformance" message. The second is the detailed reason, | |
3639 | -- supplied as Msg. The parameter N provide information for a possible | |
3640 | -- & insertion in the message. | |
996ae0b0 RK |
3641 | |
3642 | ----------------------- | |
3643 | -- Conformance_Error -- | |
3644 | ----------------------- | |
3645 | ||
3646 | procedure Conformance_Error (Msg : String; N : Node_Id) is | |
3647 | begin | |
3648 | Error_Msg_Sloc := Sloc (Prev_Loc); | |
3649 | Error_Msg_N ("not fully conformant with declaration#!", N); | |
3650 | Error_Msg_NE (Msg, N, N); | |
3651 | end Conformance_Error; | |
3652 | ||
3653 | -- Start of processing for Check_Discriminant_Conformance | |
3654 | ||
3655 | begin | |
3656 | while Present (Old_Discr) and then Present (New_Discr) loop | |
3657 | ||
3658 | New_Discr_Id := Defining_Identifier (New_Discr); | |
3659 | ||
82c80734 RD |
3660 | -- The subtype mark of the discriminant on the full type has not |
3661 | -- been analyzed so we do it here. For an access discriminant a new | |
3662 | -- type is created. | |
996ae0b0 RK |
3663 | |
3664 | if Nkind (Discriminant_Type (New_Discr)) = N_Access_Definition then | |
3665 | New_Discr_Type := | |
3666 | Access_Definition (N, Discriminant_Type (New_Discr)); | |
3667 | ||
3668 | else | |
3669 | Analyze (Discriminant_Type (New_Discr)); | |
3670 | New_Discr_Type := Etype (Discriminant_Type (New_Discr)); | |
3671 | end if; | |
3672 | ||
3673 | if not Conforming_Types | |
3674 | (Etype (Old_Discr), New_Discr_Type, Fully_Conformant) | |
3675 | then | |
3676 | Conformance_Error ("type of & does not match!", New_Discr_Id); | |
3677 | return; | |
fbf5a39b | 3678 | else |
82c80734 RD |
3679 | -- Treat the new discriminant as an occurrence of the old one, |
3680 | -- for navigation purposes, and fill in some semantic | |
fbf5a39b AC |
3681 | -- information, for completeness. |
3682 | ||
3683 | Generate_Reference (Old_Discr, New_Discr_Id, 'r'); | |
3684 | Set_Etype (New_Discr_Id, Etype (Old_Discr)); | |
3685 | Set_Scope (New_Discr_Id, Scope (Old_Discr)); | |
996ae0b0 RK |
3686 | end if; |
3687 | ||
3688 | -- Names must match | |
3689 | ||
3690 | if Chars (Old_Discr) /= Chars (Defining_Identifier (New_Discr)) then | |
3691 | Conformance_Error ("name & does not match!", New_Discr_Id); | |
3692 | return; | |
3693 | end if; | |
3694 | ||
3695 | -- Default expressions must match | |
3696 | ||
3697 | declare | |
3698 | NewD : constant Boolean := | |
3699 | Present (Expression (New_Discr)); | |
3700 | OldD : constant Boolean := | |
3701 | Present (Expression (Parent (Old_Discr))); | |
3702 | ||
3703 | begin | |
3704 | if NewD or OldD then | |
3705 | ||
3706 | -- The old default value has been analyzed and expanded, | |
3707 | -- because the current full declaration will have frozen | |
82c80734 RD |
3708 | -- everything before. The new default values have not been |
3709 | -- expanded, so expand now to check conformance. | |
996ae0b0 RK |
3710 | |
3711 | if NewD then | |
fbf5a39b | 3712 | Analyze_Per_Use_Expression |
996ae0b0 RK |
3713 | (Expression (New_Discr), New_Discr_Type); |
3714 | end if; | |
3715 | ||
3716 | if not (NewD and OldD) | |
3717 | or else not Fully_Conformant_Expressions | |
3718 | (Expression (Parent (Old_Discr)), | |
3719 | Expression (New_Discr)) | |
3720 | ||
3721 | then | |
3722 | Conformance_Error | |
3723 | ("default expression for & does not match!", | |
3724 | New_Discr_Id); | |
3725 | return; | |
3726 | end if; | |
3727 | end if; | |
3728 | end; | |
3729 | ||
3730 | -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X) | |
3731 | ||
0ab80019 | 3732 | if Ada_Version = Ada_83 then |
996ae0b0 RK |
3733 | declare |
3734 | Old_Disc : constant Node_Id := Declaration_Node (Old_Discr); | |
3735 | ||
3736 | begin | |
3737 | -- Grouping (use of comma in param lists) must be the same | |
3738 | -- This is where we catch a misconformance like: | |
3739 | ||
3740 | -- A,B : Integer | |
3741 | -- A : Integer; B : Integer | |
3742 | ||
3743 | -- which are represented identically in the tree except | |
3744 | -- for the setting of the flags More_Ids and Prev_Ids. | |
3745 | ||
3746 | if More_Ids (Old_Disc) /= More_Ids (New_Discr) | |
3747 | or else Prev_Ids (Old_Disc) /= Prev_Ids (New_Discr) | |
3748 | then | |
3749 | Conformance_Error | |
3750 | ("grouping of & does not match!", New_Discr_Id); | |
3751 | return; | |
3752 | end if; | |
3753 | end; | |
3754 | end if; | |
3755 | ||
3756 | Next_Discriminant (Old_Discr); | |
3757 | Next (New_Discr); | |
3758 | end loop; | |
3759 | ||
3760 | if Present (Old_Discr) then | |
3761 | Conformance_Error ("too few discriminants!", Defining_Identifier (N)); | |
3762 | return; | |
3763 | ||
3764 | elsif Present (New_Discr) then | |
3765 | Conformance_Error | |
3766 | ("too many discriminants!", Defining_Identifier (New_Discr)); | |
3767 | return; | |
3768 | end if; | |
3769 | end Check_Discriminant_Conformance; | |
3770 | ||
3771 | ---------------------------- | |
3772 | -- Check_Fully_Conformant -- | |
3773 | ---------------------------- | |
3774 | ||
3775 | procedure Check_Fully_Conformant | |
3776 | (New_Id : Entity_Id; | |
3777 | Old_Id : Entity_Id; | |
3778 | Err_Loc : Node_Id := Empty) | |
3779 | is | |
3780 | Result : Boolean; | |
81db9d77 | 3781 | pragma Warnings (Off, Result); |
996ae0b0 RK |
3782 | begin |
3783 | Check_Conformance | |
3784 | (New_Id, Old_Id, Fully_Conformant, True, Result, Err_Loc); | |
3785 | end Check_Fully_Conformant; | |
3786 | ||
3787 | --------------------------- | |
3788 | -- Check_Mode_Conformant -- | |
3789 | --------------------------- | |
3790 | ||
3791 | procedure Check_Mode_Conformant | |
3792 | (New_Id : Entity_Id; | |
3793 | Old_Id : Entity_Id; | |
3794 | Err_Loc : Node_Id := Empty; | |
3795 | Get_Inst : Boolean := False) | |
3796 | is | |
3797 | Result : Boolean; | |
81db9d77 | 3798 | pragma Warnings (Off, Result); |
996ae0b0 RK |
3799 | begin |
3800 | Check_Conformance | |
3801 | (New_Id, Old_Id, Mode_Conformant, True, Result, Err_Loc, Get_Inst); | |
3802 | end Check_Mode_Conformant; | |
3803 | ||
fbf5a39b | 3804 | -------------------------------- |
758c442c | 3805 | -- Check_Overriding_Indicator -- |
fbf5a39b AC |
3806 | -------------------------------- |
3807 | ||
758c442c | 3808 | procedure Check_Overriding_Indicator |
ec4867fa | 3809 | (Subp : Entity_Id; |
5d37ba92 ES |
3810 | Overridden_Subp : Entity_Id; |
3811 | Is_Primitive : Boolean) | |
fbf5a39b | 3812 | is |
758c442c GD |
3813 | Decl : Node_Id; |
3814 | Spec : Node_Id; | |
fbf5a39b AC |
3815 | |
3816 | begin | |
ec4867fa | 3817 | -- No overriding indicator for literals |
fbf5a39b | 3818 | |
ec4867fa | 3819 | if Ekind (Subp) = E_Enumeration_Literal then |
758c442c | 3820 | return; |
fbf5a39b | 3821 | |
ec4867fa ES |
3822 | elsif Ekind (Subp) = E_Entry then |
3823 | Decl := Parent (Subp); | |
3824 | ||
758c442c GD |
3825 | else |
3826 | Decl := Unit_Declaration_Node (Subp); | |
3827 | end if; | |
fbf5a39b | 3828 | |
800621e0 RD |
3829 | if Nkind_In (Decl, N_Subprogram_Body, |
3830 | N_Subprogram_Body_Stub, | |
3831 | N_Subprogram_Declaration, | |
3832 | N_Abstract_Subprogram_Declaration, | |
3833 | N_Subprogram_Renaming_Declaration) | |
758c442c GD |
3834 | then |
3835 | Spec := Specification (Decl); | |
ec4867fa ES |
3836 | |
3837 | elsif Nkind (Decl) = N_Entry_Declaration then | |
3838 | Spec := Decl; | |
3839 | ||
758c442c GD |
3840 | else |
3841 | return; | |
3842 | end if; | |
fbf5a39b | 3843 | |
ec4867fa ES |
3844 | if Present (Overridden_Subp) then |
3845 | if Must_Not_Override (Spec) then | |
3846 | Error_Msg_Sloc := Sloc (Overridden_Subp); | |
fbf5a39b | 3847 | |
ec4867fa | 3848 | if Ekind (Subp) = E_Entry then |
5d37ba92 ES |
3849 | Error_Msg_NE |
3850 | ("entry & overrides inherited operation #", Spec, Subp); | |
ec4867fa | 3851 | else |
5d37ba92 ES |
3852 | Error_Msg_NE |
3853 | ("subprogram & overrides inherited operation #", Spec, Subp); | |
ec4867fa ES |
3854 | end if; |
3855 | end if; | |
f937473f RD |
3856 | |
3857 | -- If Subp is an operator, it may override a predefined operation. | |
3858 | -- In that case overridden_subp is empty because of our implicit | |
5d37ba92 ES |
3859 | -- representation for predefined operators. We have to check whether the |
3860 | -- signature of Subp matches that of a predefined operator. Note that | |
3861 | -- first argument provides the name of the operator, and the second | |
3862 | -- argument the signature that may match that of a standard operation. | |
f937473f RD |
3863 | |
3864 | elsif Nkind (Subp) = N_Defining_Operator_Symbol | |
800621e0 | 3865 | and then Must_Not_Override (Spec) |
f937473f RD |
3866 | then |
3867 | if Operator_Matches_Spec (Subp, Subp) then | |
3868 | Error_Msg_NE | |
5d37ba92 | 3869 | ("subprogram & overrides predefined operator ", |
f937473f RD |
3870 | Spec, Subp); |
3871 | end if; | |
3872 | ||
5d37ba92 ES |
3873 | elsif Must_Override (Spec) then |
3874 | if Ekind (Subp) = E_Entry then | |
3875 | Error_Msg_NE ("entry & is not overriding", Spec, Subp); | |
f937473f | 3876 | |
5d37ba92 ES |
3877 | elsif Nkind (Subp) = N_Defining_Operator_Symbol then |
3878 | if not Operator_Matches_Spec (Subp, Subp) then | |
3879 | Error_Msg_NE | |
3880 | ("subprogram & is not overriding", Spec, Subp); | |
ec4867fa | 3881 | end if; |
5d37ba92 ES |
3882 | |
3883 | else | |
3884 | Error_Msg_NE ("subprogram & is not overriding", Spec, Subp); | |
758c442c | 3885 | end if; |
5d37ba92 ES |
3886 | |
3887 | -- If the operation is marked "not overriding" and it's not primitive | |
3888 | -- then an error is issued, unless this is an operation of a task or | |
3889 | -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding" | |
3890 | -- has been specified have already been checked above. | |
3891 | ||
3892 | elsif Must_Not_Override (Spec) | |
3893 | and then not Is_Primitive | |
3894 | and then Ekind (Subp) /= E_Entry | |
3895 | and then Ekind (Scope (Subp)) /= E_Protected_Type | |
3896 | then | |
3897 | Error_Msg_N | |
3898 | ("overriding indicator only allowed if subprogram is primitive", | |
3899 | Subp); | |
3900 | ||
3901 | return; | |
fbf5a39b | 3902 | end if; |
758c442c | 3903 | end Check_Overriding_Indicator; |
fbf5a39b | 3904 | |
996ae0b0 RK |
3905 | ------------------- |
3906 | -- Check_Returns -- | |
3907 | ------------------- | |
3908 | ||
0a36105d JM |
3909 | -- Note: this procedure needs to know far too much about how the expander |
3910 | -- messes with exceptions. The use of the flag Exception_Junk and the | |
3911 | -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers | |
3912 | -- works, but is not very clean. It would be better if the expansion | |
3913 | -- routines would leave Original_Node working nicely, and we could use | |
3914 | -- Original_Node here to ignore all the peculiar expander messing ??? | |
3915 | ||
996ae0b0 RK |
3916 | procedure Check_Returns |
3917 | (HSS : Node_Id; | |
3918 | Mode : Character; | |
c8ef728f ES |
3919 | Err : out Boolean; |
3920 | Proc : Entity_Id := Empty) | |
996ae0b0 RK |
3921 | is |
3922 | Handler : Node_Id; | |
3923 | ||
3924 | procedure Check_Statement_Sequence (L : List_Id); | |
3925 | -- Internal recursive procedure to check a list of statements for proper | |
3926 | -- termination by a return statement (or a transfer of control or a | |
3927 | -- compound statement that is itself internally properly terminated). | |
3928 | ||
3929 | ------------------------------ | |
3930 | -- Check_Statement_Sequence -- | |
3931 | ------------------------------ | |
3932 | ||
3933 | procedure Check_Statement_Sequence (L : List_Id) is | |
3934 | Last_Stm : Node_Id; | |
0a36105d | 3935 | Stm : Node_Id; |
996ae0b0 RK |
3936 | Kind : Node_Kind; |
3937 | ||
3938 | Raise_Exception_Call : Boolean; | |
3939 | -- Set True if statement sequence terminated by Raise_Exception call | |
3940 | -- or a Reraise_Occurrence call. | |
3941 | ||
3942 | begin | |
3943 | Raise_Exception_Call := False; | |
3944 | ||
3945 | -- Get last real statement | |
3946 | ||
3947 | Last_Stm := Last (L); | |
3948 | ||
0a36105d JM |
3949 | -- Deal with digging out exception handler statement sequences that |
3950 | -- have been transformed by the local raise to goto optimization. | |
3951 | -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this | |
3952 | -- optimization has occurred, we are looking at something like: | |
3953 | ||
3954 | -- begin | |
3955 | -- original stmts in block | |
3956 | ||
3957 | -- exception \ | |
3958 | -- when excep1 => | | |
3959 | -- goto L1; | omitted if No_Exception_Propagation | |
3960 | -- when excep2 => | | |
3961 | -- goto L2; / | |
3962 | -- end; | |
3963 | ||
3964 | -- goto L3; -- skip handler when exception not raised | |
3965 | ||
3966 | -- <<L1>> -- target label for local exception | |
3967 | -- begin | |
3968 | -- estmts1 | |
3969 | -- end; | |
3970 | ||
3971 | -- goto L3; | |
3972 | ||
3973 | -- <<L2>> | |
3974 | -- begin | |
3975 | -- estmts2 | |
3976 | -- end; | |
3977 | ||
3978 | -- <<L3>> | |
3979 | ||
3980 | -- and what we have to do is to dig out the estmts1 and estmts2 | |
3981 | -- sequences (which were the original sequences of statements in | |
3982 | -- the exception handlers) and check them. | |
3983 | ||
3984 | if Nkind (Last_Stm) = N_Label | |
3985 | and then Exception_Junk (Last_Stm) | |
3986 | then | |
3987 | Stm := Last_Stm; | |
3988 | loop | |
3989 | Prev (Stm); | |
3990 | exit when No (Stm); | |
3991 | exit when Nkind (Stm) /= N_Block_Statement; | |
3992 | exit when not Exception_Junk (Stm); | |
3993 | Prev (Stm); | |
3994 | exit when No (Stm); | |
3995 | exit when Nkind (Stm) /= N_Label; | |
3996 | exit when not Exception_Junk (Stm); | |
3997 | Check_Statement_Sequence | |
3998 | (Statements (Handled_Statement_Sequence (Next (Stm)))); | |
3999 | ||
4000 | Prev (Stm); | |
4001 | Last_Stm := Stm; | |
4002 | exit when No (Stm); | |
4003 | exit when Nkind (Stm) /= N_Goto_Statement; | |
4004 | exit when not Exception_Junk (Stm); | |
4005 | end loop; | |
4006 | end if; | |
4007 | ||
996ae0b0 RK |
4008 | -- Don't count pragmas |
4009 | ||
4010 | while Nkind (Last_Stm) = N_Pragma | |
4011 | ||
4012 | -- Don't count call to SS_Release (can happen after Raise_Exception) | |
4013 | ||
4014 | or else | |
4015 | (Nkind (Last_Stm) = N_Procedure_Call_Statement | |
4016 | and then | |
4017 | Nkind (Name (Last_Stm)) = N_Identifier | |
4018 | and then | |
4019 | Is_RTE (Entity (Name (Last_Stm)), RE_SS_Release)) | |
4020 | ||
4021 | -- Don't count exception junk | |
4022 | ||
4023 | or else | |
800621e0 RD |
4024 | (Nkind_In (Last_Stm, N_Goto_Statement, |
4025 | N_Label, | |
4026 | N_Object_Declaration) | |
0a36105d JM |
4027 | and then Exception_Junk (Last_Stm)) |
4028 | or else Nkind (Last_Stm) in N_Push_xxx_Label | |
4029 | or else Nkind (Last_Stm) in N_Pop_xxx_Label | |
996ae0b0 RK |
4030 | loop |
4031 | Prev (Last_Stm); | |
4032 | end loop; | |
4033 | ||
4034 | -- Here we have the "real" last statement | |
4035 | ||
4036 | Kind := Nkind (Last_Stm); | |
4037 | ||
4038 | -- Transfer of control, OK. Note that in the No_Return procedure | |
4039 | -- case, we already diagnosed any explicit return statements, so | |
4040 | -- we can treat them as OK in this context. | |
4041 | ||
4042 | if Is_Transfer (Last_Stm) then | |
4043 | return; | |
4044 | ||
4045 | -- Check cases of explicit non-indirect procedure calls | |
4046 | ||
4047 | elsif Kind = N_Procedure_Call_Statement | |
4048 | and then Is_Entity_Name (Name (Last_Stm)) | |
4049 | then | |
4050 | -- Check call to Raise_Exception procedure which is treated | |
4051 | -- specially, as is a call to Reraise_Occurrence. | |
4052 | ||
4053 | -- We suppress the warning in these cases since it is likely that | |
4054 | -- the programmer really does not expect to deal with the case | |
4055 | -- of Null_Occurrence, and thus would find a warning about a | |
4056 | -- missing return curious, and raising Program_Error does not | |
4057 | -- seem such a bad behavior if this does occur. | |
4058 | ||
c8ef728f ES |
4059 | -- Note that in the Ada 2005 case for Raise_Exception, the actual |
4060 | -- behavior will be to raise Constraint_Error (see AI-329). | |
4061 | ||
996ae0b0 RK |
4062 | if Is_RTE (Entity (Name (Last_Stm)), RE_Raise_Exception) |
4063 | or else | |
4064 | Is_RTE (Entity (Name (Last_Stm)), RE_Reraise_Occurrence) | |
4065 | then | |
4066 | Raise_Exception_Call := True; | |
4067 | ||
4068 | -- For Raise_Exception call, test first argument, if it is | |
4069 | -- an attribute reference for a 'Identity call, then we know | |
4070 | -- that the call cannot possibly return. | |
4071 | ||
4072 | declare | |
4073 | Arg : constant Node_Id := | |
4074 | Original_Node (First_Actual (Last_Stm)); | |
996ae0b0 RK |
4075 | begin |
4076 | if Nkind (Arg) = N_Attribute_Reference | |
4077 | and then Attribute_Name (Arg) = Name_Identity | |
4078 | then | |
4079 | return; | |
4080 | end if; | |
4081 | end; | |
4082 | end if; | |
4083 | ||
4084 | -- If statement, need to look inside if there is an else and check | |
4085 | -- each constituent statement sequence for proper termination. | |
4086 | ||
4087 | elsif Kind = N_If_Statement | |
4088 | and then Present (Else_Statements (Last_Stm)) | |
4089 | then | |
4090 | Check_Statement_Sequence (Then_Statements (Last_Stm)); | |
4091 | Check_Statement_Sequence (Else_Statements (Last_Stm)); | |
4092 | ||
4093 | if Present (Elsif_Parts (Last_Stm)) then | |
4094 | declare | |
4095 | Elsif_Part : Node_Id := First (Elsif_Parts (Last_Stm)); | |
4096 | ||
4097 | begin | |
4098 | while Present (Elsif_Part) loop | |
4099 | Check_Statement_Sequence (Then_Statements (Elsif_Part)); | |
4100 | Next (Elsif_Part); | |
4101 | end loop; | |
4102 | end; | |
4103 | end if; | |
4104 | ||
4105 | return; | |
4106 | ||
4107 | -- Case statement, check each case for proper termination | |
4108 | ||
4109 | elsif Kind = N_Case_Statement then | |
4110 | declare | |
4111 | Case_Alt : Node_Id; | |
996ae0b0 RK |
4112 | begin |
4113 | Case_Alt := First_Non_Pragma (Alternatives (Last_Stm)); | |
4114 | while Present (Case_Alt) loop | |
4115 | Check_Statement_Sequence (Statements (Case_Alt)); | |
4116 | Next_Non_Pragma (Case_Alt); | |
4117 | end loop; | |
4118 | end; | |
4119 | ||
4120 | return; | |
4121 | ||
4122 | -- Block statement, check its handled sequence of statements | |
4123 | ||
4124 | elsif Kind = N_Block_Statement then | |
4125 | declare | |
4126 | Err1 : Boolean; | |
4127 | ||
4128 | begin | |
4129 | Check_Returns | |
4130 | (Handled_Statement_Sequence (Last_Stm), Mode, Err1); | |
4131 | ||
4132 | if Err1 then | |
4133 | Err := True; | |
4134 | end if; | |
4135 | ||
4136 | return; | |
4137 | end; | |
4138 | ||
4139 | -- Loop statement. If there is an iteration scheme, we can definitely | |
4140 | -- fall out of the loop. Similarly if there is an exit statement, we | |
4141 | -- can fall out. In either case we need a following return. | |
4142 | ||
4143 | elsif Kind = N_Loop_Statement then | |
4144 | if Present (Iteration_Scheme (Last_Stm)) | |
4145 | or else Has_Exit (Entity (Identifier (Last_Stm))) | |
4146 | then | |
4147 | null; | |
4148 | ||
4149 | -- A loop with no exit statement or iteration scheme if either | |
4150 | -- an inifite loop, or it has some other exit (raise/return). | |
4151 | -- In either case, no warning is required. | |
4152 | ||
4153 | else | |
4154 | return; | |
4155 | end if; | |
4156 | ||
4157 | -- Timed entry call, check entry call and delay alternatives | |
4158 | ||
4159 | -- Note: in expanded code, the timed entry call has been converted | |
4160 | -- to a set of expanded statements on which the check will work | |
4161 | -- correctly in any case. | |
4162 | ||
4163 | elsif Kind = N_Timed_Entry_Call then | |
4164 | declare | |
4165 | ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm); | |
4166 | DCA : constant Node_Id := Delay_Alternative (Last_Stm); | |
4167 | ||
4168 | begin | |
4169 | -- If statement sequence of entry call alternative is missing, | |
4170 | -- then we can definitely fall through, and we post the error | |
4171 | -- message on the entry call alternative itself. | |
4172 | ||
4173 | if No (Statements (ECA)) then | |
4174 | Last_Stm := ECA; | |
4175 | ||
4176 | -- If statement sequence of delay alternative is missing, then | |
4177 | -- we can definitely fall through, and we post the error | |
4178 | -- message on the delay alternative itself. | |
4179 | ||
4180 | -- Note: if both ECA and DCA are missing the return, then we | |
4181 | -- post only one message, should be enough to fix the bugs. | |
4182 | -- If not we will get a message next time on the DCA when the | |
4183 | -- ECA is fixed! | |
4184 | ||
4185 | elsif No (Statements (DCA)) then | |
4186 | Last_Stm := DCA; | |
4187 | ||
4188 | -- Else check both statement sequences | |
4189 | ||
4190 | else | |
4191 | Check_Statement_Sequence (Statements (ECA)); | |
4192 | Check_Statement_Sequence (Statements (DCA)); | |
4193 | return; | |
4194 | end if; | |
4195 | end; | |
4196 | ||
4197 | -- Conditional entry call, check entry call and else part | |
4198 | ||
4199 | -- Note: in expanded code, the conditional entry call has been | |
4200 | -- converted to a set of expanded statements on which the check | |
4201 | -- will work correctly in any case. | |
4202 | ||
4203 | elsif Kind = N_Conditional_Entry_Call then | |
4204 | declare | |
4205 | ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm); | |
4206 | ||
4207 | begin | |
4208 | -- If statement sequence of entry call alternative is missing, | |
4209 | -- then we can definitely fall through, and we post the error | |
4210 | -- message on the entry call alternative itself. | |
4211 | ||
4212 | if No (Statements (ECA)) then | |
4213 | Last_Stm := ECA; | |
4214 | ||
4215 | -- Else check statement sequence and else part | |
4216 | ||
4217 | else | |
4218 | Check_Statement_Sequence (Statements (ECA)); | |
4219 | Check_Statement_Sequence (Else_Statements (Last_Stm)); | |
4220 | return; | |
4221 | end if; | |
4222 | end; | |
4223 | end if; | |
4224 | ||
4225 | -- If we fall through, issue appropriate message | |
4226 | ||
4227 | if Mode = 'F' then | |
996ae0b0 RK |
4228 | if not Raise_Exception_Call then |
4229 | Error_Msg_N | |
5d37ba92 | 4230 | ("?RETURN statement missing following this statement!", |
996ae0b0 RK |
4231 | Last_Stm); |
4232 | Error_Msg_N | |
5d37ba92 | 4233 | ("\?Program_Error may be raised at run time!", |
996ae0b0 RK |
4234 | Last_Stm); |
4235 | end if; | |
4236 | ||
4237 | -- Note: we set Err even though we have not issued a warning | |
4238 | -- because we still have a case of a missing return. This is | |
4239 | -- an extremely marginal case, probably will never be noticed | |
4240 | -- but we might as well get it right. | |
4241 | ||
4242 | Err := True; | |
4243 | ||
c8ef728f ES |
4244 | -- Otherwise we have the case of a procedure marked No_Return |
4245 | ||
996ae0b0 | 4246 | else |
800621e0 RD |
4247 | if not Raise_Exception_Call then |
4248 | Error_Msg_N | |
4249 | ("?implied return after this statement " & | |
4250 | "will raise Program_Error", | |
4251 | Last_Stm); | |
4252 | Error_Msg_NE | |
4253 | ("\?procedure & is marked as No_Return!", | |
4254 | Last_Stm, Proc); | |
4255 | end if; | |
c8ef728f ES |
4256 | |
4257 | declare | |
4258 | RE : constant Node_Id := | |
4259 | Make_Raise_Program_Error (Sloc (Last_Stm), | |
4260 | Reason => PE_Implicit_Return); | |
4261 | begin | |
4262 | Insert_After (Last_Stm, RE); | |
4263 | Analyze (RE); | |
4264 | end; | |
996ae0b0 RK |
4265 | end if; |
4266 | end Check_Statement_Sequence; | |
4267 | ||
4268 | -- Start of processing for Check_Returns | |
4269 | ||
4270 | begin | |
4271 | Err := False; | |
4272 | Check_Statement_Sequence (Statements (HSS)); | |
4273 | ||
4274 | if Present (Exception_Handlers (HSS)) then | |
4275 | Handler := First_Non_Pragma (Exception_Handlers (HSS)); | |
4276 | while Present (Handler) loop | |
4277 | Check_Statement_Sequence (Statements (Handler)); | |
4278 | Next_Non_Pragma (Handler); | |
4279 | end loop; | |
4280 | end if; | |
4281 | end Check_Returns; | |
4282 | ||
4283 | ---------------------------- | |
4284 | -- Check_Subprogram_Order -- | |
4285 | ---------------------------- | |
4286 | ||
4287 | procedure Check_Subprogram_Order (N : Node_Id) is | |
4288 | ||
4289 | function Subprogram_Name_Greater (S1, S2 : String) return Boolean; | |
4290 | -- This is used to check if S1 > S2 in the sense required by this | |
4291 | -- test, for example nameab < namec, but name2 < name10. | |
4292 | ||
82c80734 RD |
4293 | ----------------------------- |
4294 | -- Subprogram_Name_Greater -- | |
4295 | ----------------------------- | |
4296 | ||
996ae0b0 RK |
4297 | function Subprogram_Name_Greater (S1, S2 : String) return Boolean is |
4298 | L1, L2 : Positive; | |
4299 | N1, N2 : Natural; | |
4300 | ||
4301 | begin | |
4302 | -- Remove trailing numeric parts | |
4303 | ||
4304 | L1 := S1'Last; | |
4305 | while S1 (L1) in '0' .. '9' loop | |
4306 | L1 := L1 - 1; | |
4307 | end loop; | |
4308 | ||
4309 | L2 := S2'Last; | |
4310 | while S2 (L2) in '0' .. '9' loop | |
4311 | L2 := L2 - 1; | |
4312 | end loop; | |
4313 | ||
4314 | -- If non-numeric parts non-equal, that's decisive | |
4315 | ||
4316 | if S1 (S1'First .. L1) < S2 (S2'First .. L2) then | |
4317 | return False; | |
4318 | ||
4319 | elsif S1 (S1'First .. L1) > S2 (S2'First .. L2) then | |
4320 | return True; | |
4321 | ||
4322 | -- If non-numeric parts equal, compare suffixed numeric parts. Note | |
4323 | -- that a missing suffix is treated as numeric zero in this test. | |
4324 | ||
4325 | else | |
4326 | N1 := 0; | |
4327 | while L1 < S1'Last loop | |
4328 | L1 := L1 + 1; | |
4329 | N1 := N1 * 10 + Character'Pos (S1 (L1)) - Character'Pos ('0'); | |
4330 | end loop; | |
4331 | ||
4332 | N2 := 0; | |
4333 | while L2 < S2'Last loop | |
4334 | L2 := L2 + 1; | |
4335 | N2 := N2 * 10 + Character'Pos (S2 (L2)) - Character'Pos ('0'); | |
4336 | end loop; | |
4337 | ||
4338 | return N1 > N2; | |
4339 | end if; | |
4340 | end Subprogram_Name_Greater; | |
4341 | ||
4342 | -- Start of processing for Check_Subprogram_Order | |
4343 | ||
4344 | begin | |
4345 | -- Check body in alpha order if this is option | |
4346 | ||
fbf5a39b | 4347 | if Style_Check |
bc202b70 | 4348 | and then Style_Check_Order_Subprograms |
996ae0b0 RK |
4349 | and then Nkind (N) = N_Subprogram_Body |
4350 | and then Comes_From_Source (N) | |
4351 | and then In_Extended_Main_Source_Unit (N) | |
4352 | then | |
4353 | declare | |
4354 | LSN : String_Ptr | |
4355 | renames Scope_Stack.Table | |
4356 | (Scope_Stack.Last).Last_Subprogram_Name; | |
4357 | ||
4358 | Body_Id : constant Entity_Id := | |
4359 | Defining_Entity (Specification (N)); | |
4360 | ||
4361 | begin | |
4362 | Get_Decoded_Name_String (Chars (Body_Id)); | |
4363 | ||
4364 | if LSN /= null then | |
4365 | if Subprogram_Name_Greater | |
4366 | (LSN.all, Name_Buffer (1 .. Name_Len)) | |
4367 | then | |
4368 | Style.Subprogram_Not_In_Alpha_Order (Body_Id); | |
4369 | end if; | |
4370 | ||
4371 | Free (LSN); | |
4372 | end if; | |
4373 | ||
4374 | LSN := new String'(Name_Buffer (1 .. Name_Len)); | |
4375 | end; | |
4376 | end if; | |
4377 | end Check_Subprogram_Order; | |
4378 | ||
4379 | ------------------------------ | |
4380 | -- Check_Subtype_Conformant -- | |
4381 | ------------------------------ | |
4382 | ||
4383 | procedure Check_Subtype_Conformant | |
4384 | (New_Id : Entity_Id; | |
4385 | Old_Id : Entity_Id; | |
4386 | Err_Loc : Node_Id := Empty) | |
4387 | is | |
4388 | Result : Boolean; | |
81db9d77 | 4389 | pragma Warnings (Off, Result); |
996ae0b0 RK |
4390 | begin |
4391 | Check_Conformance | |
4392 | (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc); | |
4393 | end Check_Subtype_Conformant; | |
4394 | ||
4395 | --------------------------- | |
4396 | -- Check_Type_Conformant -- | |
4397 | --------------------------- | |
4398 | ||
4399 | procedure Check_Type_Conformant | |
4400 | (New_Id : Entity_Id; | |
4401 | Old_Id : Entity_Id; | |
4402 | Err_Loc : Node_Id := Empty) | |
4403 | is | |
4404 | Result : Boolean; | |
81db9d77 | 4405 | pragma Warnings (Off, Result); |
996ae0b0 RK |
4406 | begin |
4407 | Check_Conformance | |
4408 | (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc); | |
4409 | end Check_Type_Conformant; | |
4410 | ||
4411 | ---------------------- | |
4412 | -- Conforming_Types -- | |
4413 | ---------------------- | |
4414 | ||
4415 | function Conforming_Types | |
4416 | (T1 : Entity_Id; | |
4417 | T2 : Entity_Id; | |
4418 | Ctype : Conformance_Type; | |
d05ef0ab | 4419 | Get_Inst : Boolean := False) return Boolean |
996ae0b0 RK |
4420 | is |
4421 | Type_1 : Entity_Id := T1; | |
4422 | Type_2 : Entity_Id := T2; | |
af4b9434 | 4423 | Are_Anonymous_Access_To_Subprogram_Types : Boolean := False; |
996ae0b0 RK |
4424 | |
4425 | function Base_Types_Match (T1, T2 : Entity_Id) return Boolean; | |
0a36105d JM |
4426 | -- If neither T1 nor T2 are generic actual types, or if they are in |
4427 | -- different scopes (e.g. parent and child instances), then verify that | |
4428 | -- the base types are equal. Otherwise T1 and T2 must be on the same | |
4429 | -- subtype chain. The whole purpose of this procedure is to prevent | |
4430 | -- spurious ambiguities in an instantiation that may arise if two | |
4431 | -- distinct generic types are instantiated with the same actual. | |
4432 | ||
5d37ba92 ES |
4433 | function Find_Designated_Type (T : Entity_Id) return Entity_Id; |
4434 | -- An access parameter can designate an incomplete type. If the | |
4435 | -- incomplete type is the limited view of a type from a limited_ | |
4436 | -- with_clause, check whether the non-limited view is available. If | |
4437 | -- it is a (non-limited) incomplete type, get the full view. | |
4438 | ||
0a36105d JM |
4439 | function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean; |
4440 | -- Returns True if and only if either T1 denotes a limited view of T2 | |
4441 | -- or T2 denotes a limited view of T1. This can arise when the limited | |
4442 | -- with view of a type is used in a subprogram declaration and the | |
4443 | -- subprogram body is in the scope of a regular with clause for the | |
4444 | -- same unit. In such a case, the two type entities can be considered | |
4445 | -- identical for purposes of conformance checking. | |
996ae0b0 RK |
4446 | |
4447 | ---------------------- | |
4448 | -- Base_Types_Match -- | |
4449 | ---------------------- | |
4450 | ||
4451 | function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is | |
4452 | begin | |
4453 | if T1 = T2 then | |
4454 | return True; | |
4455 | ||
4456 | elsif Base_Type (T1) = Base_Type (T2) then | |
4457 | ||
0a36105d | 4458 | -- The following is too permissive. A more precise test should |
996ae0b0 RK |
4459 | -- check that the generic actual is an ancestor subtype of the |
4460 | -- other ???. | |
4461 | ||
4462 | return not Is_Generic_Actual_Type (T1) | |
07fc65c4 GB |
4463 | or else not Is_Generic_Actual_Type (T2) |
4464 | or else Scope (T1) /= Scope (T2); | |
996ae0b0 | 4465 | |
0a36105d JM |
4466 | else |
4467 | return False; | |
4468 | end if; | |
4469 | end Base_Types_Match; | |
aa720a54 | 4470 | |
5d37ba92 ES |
4471 | -------------------------- |
4472 | -- Find_Designated_Type -- | |
4473 | -------------------------- | |
4474 | ||
4475 | function Find_Designated_Type (T : Entity_Id) return Entity_Id is | |
4476 | Desig : Entity_Id; | |
4477 | ||
4478 | begin | |
4479 | Desig := Directly_Designated_Type (T); | |
4480 | ||
4481 | if Ekind (Desig) = E_Incomplete_Type then | |
4482 | ||
4483 | -- If regular incomplete type, get full view if available | |
4484 | ||
4485 | if Present (Full_View (Desig)) then | |
4486 | Desig := Full_View (Desig); | |
4487 | ||
4488 | -- If limited view of a type, get non-limited view if available, | |
4489 | -- and check again for a regular incomplete type. | |
4490 | ||
4491 | elsif Present (Non_Limited_View (Desig)) then | |
4492 | Desig := Get_Full_View (Non_Limited_View (Desig)); | |
4493 | end if; | |
4494 | end if; | |
4495 | ||
4496 | return Desig; | |
4497 | end Find_Designated_Type; | |
4498 | ||
0a36105d JM |
4499 | ------------------------------- |
4500 | -- Matches_Limited_With_View -- | |
4501 | ------------------------------- | |
4502 | ||
4503 | function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean is | |
4504 | begin | |
4505 | -- In some cases a type imported through a limited_with clause, and | |
4506 | -- its nonlimited view are both visible, for example in an anonymous | |
4507 | -- access-to-class-wide type in a formal. Both entities designate the | |
4508 | -- same type. | |
4509 | ||
4510 | if From_With_Type (T1) | |
4511 | and then T2 = Available_View (T1) | |
aa720a54 AC |
4512 | then |
4513 | return True; | |
4514 | ||
41251c60 | 4515 | elsif From_With_Type (T2) |
0a36105d | 4516 | and then T1 = Available_View (T2) |
41251c60 JM |
4517 | then |
4518 | return True; | |
4519 | ||
996ae0b0 RK |
4520 | else |
4521 | return False; | |
4522 | end if; | |
0a36105d | 4523 | end Matches_Limited_With_View; |
996ae0b0 | 4524 | |
ec4867fa | 4525 | -- Start of processing for Conforming_Types |
758c442c | 4526 | |
996ae0b0 RK |
4527 | begin |
4528 | -- The context is an instance association for a formal | |
82c80734 RD |
4529 | -- access-to-subprogram type; the formal parameter types require |
4530 | -- mapping because they may denote other formal parameters of the | |
4531 | -- generic unit. | |
996ae0b0 RK |
4532 | |
4533 | if Get_Inst then | |
4534 | Type_1 := Get_Instance_Of (T1); | |
4535 | Type_2 := Get_Instance_Of (T2); | |
4536 | end if; | |
4537 | ||
0a36105d JM |
4538 | -- If one of the types is a view of the other introduced by a limited |
4539 | -- with clause, treat these as conforming for all purposes. | |
996ae0b0 | 4540 | |
0a36105d JM |
4541 | if Matches_Limited_With_View (T1, T2) then |
4542 | return True; | |
4543 | ||
4544 | elsif Base_Types_Match (Type_1, Type_2) then | |
996ae0b0 RK |
4545 | return Ctype <= Mode_Conformant |
4546 | or else Subtypes_Statically_Match (Type_1, Type_2); | |
4547 | ||
4548 | elsif Is_Incomplete_Or_Private_Type (Type_1) | |
4549 | and then Present (Full_View (Type_1)) | |
4550 | and then Base_Types_Match (Full_View (Type_1), Type_2) | |
4551 | then | |
4552 | return Ctype <= Mode_Conformant | |
4553 | or else Subtypes_Statically_Match (Full_View (Type_1), Type_2); | |
4554 | ||
4555 | elsif Ekind (Type_2) = E_Incomplete_Type | |
4556 | and then Present (Full_View (Type_2)) | |
4557 | and then Base_Types_Match (Type_1, Full_View (Type_2)) | |
4558 | then | |
4559 | return Ctype <= Mode_Conformant | |
4560 | or else Subtypes_Statically_Match (Type_1, Full_View (Type_2)); | |
fbf5a39b AC |
4561 | |
4562 | elsif Is_Private_Type (Type_2) | |
4563 | and then In_Instance | |
4564 | and then Present (Full_View (Type_2)) | |
4565 | and then Base_Types_Match (Type_1, Full_View (Type_2)) | |
4566 | then | |
4567 | return Ctype <= Mode_Conformant | |
4568 | or else Subtypes_Statically_Match (Type_1, Full_View (Type_2)); | |
996ae0b0 RK |
4569 | end if; |
4570 | ||
0a36105d | 4571 | -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be |
758c442c | 4572 | -- treated recursively because they carry a signature. |
af4b9434 AC |
4573 | |
4574 | Are_Anonymous_Access_To_Subprogram_Types := | |
f937473f RD |
4575 | Ekind (Type_1) = Ekind (Type_2) |
4576 | and then | |
800621e0 | 4577 | (Ekind (Type_1) = E_Anonymous_Access_Subprogram_Type |
f937473f RD |
4578 | or else |
4579 | Ekind (Type_1) = E_Anonymous_Access_Protected_Subprogram_Type); | |
af4b9434 | 4580 | |
996ae0b0 | 4581 | -- Test anonymous access type case. For this case, static subtype |
5d37ba92 ES |
4582 | -- matching is required for mode conformance (RM 6.3.1(15)). We check |
4583 | -- the base types because we may have built internal subtype entities | |
4584 | -- to handle null-excluding types (see Process_Formals). | |
996ae0b0 | 4585 | |
5d37ba92 ES |
4586 | if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type |
4587 | and then | |
4588 | Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type) | |
0ab80019 | 4589 | or else Are_Anonymous_Access_To_Subprogram_Types -- Ada 2005 (AI-254) |
996ae0b0 RK |
4590 | then |
4591 | declare | |
4592 | Desig_1 : Entity_Id; | |
4593 | Desig_2 : Entity_Id; | |
4594 | ||
4595 | begin | |
5d37ba92 ES |
4596 | -- In Ada2005, access constant indicators must match for |
4597 | -- subtype conformance. | |
9dcb52e1 | 4598 | |
5d37ba92 ES |
4599 | if Ada_Version >= Ada_05 |
4600 | and then Ctype >= Subtype_Conformant | |
4601 | and then | |
4602 | Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2) | |
4603 | then | |
4604 | return False; | |
996ae0b0 RK |
4605 | end if; |
4606 | ||
5d37ba92 | 4607 | Desig_1 := Find_Designated_Type (Type_1); |
996ae0b0 | 4608 | |
5d37ba92 | 4609 | Desig_2 := Find_Designated_Type (Type_2); |
996ae0b0 | 4610 | |
5d37ba92 | 4611 | -- If the context is an instance association for a formal |
82c80734 RD |
4612 | -- access-to-subprogram type; formal access parameter designated |
4613 | -- types require mapping because they may denote other formal | |
4614 | -- parameters of the generic unit. | |
996ae0b0 RK |
4615 | |
4616 | if Get_Inst then | |
4617 | Desig_1 := Get_Instance_Of (Desig_1); | |
4618 | Desig_2 := Get_Instance_Of (Desig_2); | |
4619 | end if; | |
4620 | ||
82c80734 RD |
4621 | -- It is possible for a Class_Wide_Type to be introduced for an |
4622 | -- incomplete type, in which case there is a separate class_ wide | |
4623 | -- type for the full view. The types conform if their Etypes | |
4624 | -- conform, i.e. one may be the full view of the other. This can | |
4625 | -- only happen in the context of an access parameter, other uses | |
4626 | -- of an incomplete Class_Wide_Type are illegal. | |
996ae0b0 | 4627 | |
fbf5a39b AC |
4628 | if Is_Class_Wide_Type (Desig_1) |
4629 | and then Is_Class_Wide_Type (Desig_2) | |
996ae0b0 RK |
4630 | then |
4631 | return | |
fbf5a39b AC |
4632 | Conforming_Types |
4633 | (Etype (Base_Type (Desig_1)), | |
4634 | Etype (Base_Type (Desig_2)), Ctype); | |
af4b9434 AC |
4635 | |
4636 | elsif Are_Anonymous_Access_To_Subprogram_Types then | |
758c442c GD |
4637 | if Ada_Version < Ada_05 then |
4638 | return Ctype = Type_Conformant | |
4639 | or else | |
af4b9434 AC |
4640 | Subtypes_Statically_Match (Desig_1, Desig_2); |
4641 | ||
758c442c GD |
4642 | -- We must check the conformance of the signatures themselves |
4643 | ||
4644 | else | |
4645 | declare | |
4646 | Conformant : Boolean; | |
4647 | begin | |
4648 | Check_Conformance | |
4649 | (Desig_1, Desig_2, Ctype, False, Conformant); | |
4650 | return Conformant; | |
4651 | end; | |
4652 | end if; | |
4653 | ||
996ae0b0 RK |
4654 | else |
4655 | return Base_Type (Desig_1) = Base_Type (Desig_2) | |
4656 | and then (Ctype = Type_Conformant | |
af4b9434 AC |
4657 | or else |
4658 | Subtypes_Statically_Match (Desig_1, Desig_2)); | |
996ae0b0 RK |
4659 | end if; |
4660 | end; | |
4661 | ||
4662 | -- Otherwise definitely no match | |
4663 | ||
4664 | else | |
c8ef728f ES |
4665 | if ((Ekind (Type_1) = E_Anonymous_Access_Type |
4666 | and then Is_Access_Type (Type_2)) | |
4667 | or else (Ekind (Type_2) = E_Anonymous_Access_Type | |
4668 | and then Is_Access_Type (Type_1))) | |
4669 | and then | |
4670 | Conforming_Types | |
4671 | (Designated_Type (Type_1), Designated_Type (Type_2), Ctype) | |
4672 | then | |
4673 | May_Hide_Profile := True; | |
4674 | end if; | |
4675 | ||
996ae0b0 RK |
4676 | return False; |
4677 | end if; | |
996ae0b0 RK |
4678 | end Conforming_Types; |
4679 | ||
4680 | -------------------------- | |
4681 | -- Create_Extra_Formals -- | |
4682 | -------------------------- | |
4683 | ||
4684 | procedure Create_Extra_Formals (E : Entity_Id) is | |
4685 | Formal : Entity_Id; | |
ec4867fa | 4686 | First_Extra : Entity_Id := Empty; |
996ae0b0 RK |
4687 | Last_Extra : Entity_Id; |
4688 | Formal_Type : Entity_Id; | |
4689 | P_Formal : Entity_Id := Empty; | |
4690 | ||
ec4867fa ES |
4691 | function Add_Extra_Formal |
4692 | (Assoc_Entity : Entity_Id; | |
4693 | Typ : Entity_Id; | |
4694 | Scope : Entity_Id; | |
4695 | Suffix : String) return Entity_Id; | |
4696 | -- Add an extra formal to the current list of formals and extra formals. | |
4697 | -- The extra formal is added to the end of the list of extra formals, | |
4698 | -- and also returned as the result. These formals are always of mode IN. | |
4699 | -- The new formal has the type Typ, is declared in Scope, and its name | |
4700 | -- is given by a concatenation of the name of Assoc_Entity and Suffix. | |
996ae0b0 | 4701 | |
fbf5a39b AC |
4702 | ---------------------- |
4703 | -- Add_Extra_Formal -- | |
4704 | ---------------------- | |
4705 | ||
ec4867fa ES |
4706 | function Add_Extra_Formal |
4707 | (Assoc_Entity : Entity_Id; | |
4708 | Typ : Entity_Id; | |
4709 | Scope : Entity_Id; | |
4710 | Suffix : String) return Entity_Id | |
4711 | is | |
996ae0b0 | 4712 | EF : constant Entity_Id := |
ec4867fa ES |
4713 | Make_Defining_Identifier (Sloc (Assoc_Entity), |
4714 | Chars => New_External_Name (Chars (Assoc_Entity), | |
f937473f | 4715 | Suffix => Suffix)); |
996ae0b0 RK |
4716 | |
4717 | begin | |
82c80734 RD |
4718 | -- A little optimization. Never generate an extra formal for the |
4719 | -- _init operand of an initialization procedure, since it could | |
4720 | -- never be used. | |
996ae0b0 RK |
4721 | |
4722 | if Chars (Formal) = Name_uInit then | |
4723 | return Empty; | |
4724 | end if; | |
4725 | ||
4726 | Set_Ekind (EF, E_In_Parameter); | |
4727 | Set_Actual_Subtype (EF, Typ); | |
4728 | Set_Etype (EF, Typ); | |
ec4867fa | 4729 | Set_Scope (EF, Scope); |
996ae0b0 RK |
4730 | Set_Mechanism (EF, Default_Mechanism); |
4731 | Set_Formal_Validity (EF); | |
4732 | ||
ec4867fa ES |
4733 | if No (First_Extra) then |
4734 | First_Extra := EF; | |
4735 | Set_Extra_Formals (Scope, First_Extra); | |
4736 | end if; | |
4737 | ||
4738 | if Present (Last_Extra) then | |
4739 | Set_Extra_Formal (Last_Extra, EF); | |
4740 | end if; | |
4741 | ||
996ae0b0 | 4742 | Last_Extra := EF; |
ec4867fa | 4743 | |
996ae0b0 RK |
4744 | return EF; |
4745 | end Add_Extra_Formal; | |
4746 | ||
4747 | -- Start of processing for Create_Extra_Formals | |
4748 | ||
4749 | begin | |
f937473f RD |
4750 | -- We never generate extra formals if expansion is not active |
4751 | -- because we don't need them unless we are generating code. | |
4752 | ||
4753 | if not Expander_Active then | |
4754 | return; | |
4755 | end if; | |
4756 | ||
82c80734 RD |
4757 | -- If this is a derived subprogram then the subtypes of the parent |
4758 | -- subprogram's formal parameters will be used to to determine the need | |
4759 | -- for extra formals. | |
996ae0b0 RK |
4760 | |
4761 | if Is_Overloadable (E) and then Present (Alias (E)) then | |
4762 | P_Formal := First_Formal (Alias (E)); | |
4763 | end if; | |
4764 | ||
4765 | Last_Extra := Empty; | |
4766 | Formal := First_Formal (E); | |
4767 | while Present (Formal) loop | |
4768 | Last_Extra := Formal; | |
4769 | Next_Formal (Formal); | |
4770 | end loop; | |
4771 | ||
f937473f | 4772 | -- If Extra_formals were already created, don't do it again. This |
82c80734 RD |
4773 | -- situation may arise for subprogram types created as part of |
4774 | -- dispatching calls (see Expand_Dispatching_Call) | |
996ae0b0 RK |
4775 | |
4776 | if Present (Last_Extra) and then | |
4777 | Present (Extra_Formal (Last_Extra)) | |
4778 | then | |
4779 | return; | |
4780 | end if; | |
4781 | ||
19590d70 GD |
4782 | -- If the subprogram is a predefined dispatching subprogram then don't |
4783 | -- generate any extra constrained or accessibility level formals. In | |
4784 | -- general we suppress these for internal subprograms (by not calling | |
4785 | -- Freeze_Subprogram and Create_Extra_Formals at all), but internally | |
4786 | -- generated stream attributes do get passed through because extra | |
4787 | -- build-in-place formals are needed in some cases (limited 'Input). | |
4788 | ||
4789 | if Is_Predefined_Dispatching_Operation (E) then | |
4790 | goto Test_For_BIP_Extras; | |
4791 | end if; | |
4792 | ||
996ae0b0 | 4793 | Formal := First_Formal (E); |
996ae0b0 RK |
4794 | while Present (Formal) loop |
4795 | ||
4796 | -- Create extra formal for supporting the attribute 'Constrained. | |
4797 | -- The case of a private type view without discriminants also | |
4798 | -- requires the extra formal if the underlying type has defaulted | |
4799 | -- discriminants. | |
4800 | ||
4801 | if Ekind (Formal) /= E_In_Parameter then | |
4802 | if Present (P_Formal) then | |
4803 | Formal_Type := Etype (P_Formal); | |
4804 | else | |
4805 | Formal_Type := Etype (Formal); | |
4806 | end if; | |
4807 | ||
5d09245e AC |
4808 | -- Do not produce extra formals for Unchecked_Union parameters. |
4809 | -- Jump directly to the end of the loop. | |
4810 | ||
4811 | if Is_Unchecked_Union (Base_Type (Formal_Type)) then | |
4812 | goto Skip_Extra_Formal_Generation; | |
4813 | end if; | |
4814 | ||
996ae0b0 RK |
4815 | if not Has_Discriminants (Formal_Type) |
4816 | and then Ekind (Formal_Type) in Private_Kind | |
4817 | and then Present (Underlying_Type (Formal_Type)) | |
4818 | then | |
4819 | Formal_Type := Underlying_Type (Formal_Type); | |
4820 | end if; | |
4821 | ||
4822 | if Has_Discriminants (Formal_Type) | |
f937473f RD |
4823 | and then not Is_Constrained (Formal_Type) |
4824 | and then not Is_Indefinite_Subtype (Formal_Type) | |
996ae0b0 RK |
4825 | then |
4826 | Set_Extra_Constrained | |
5d37ba92 | 4827 | (Formal, Add_Extra_Formal (Formal, Standard_Boolean, E, "F")); |
996ae0b0 RK |
4828 | end if; |
4829 | end if; | |
4830 | ||
0a36105d JM |
4831 | -- Create extra formal for supporting accessibility checking. This |
4832 | -- is done for both anonymous access formals and formals of named | |
4833 | -- access types that are marked as controlling formals. The latter | |
4834 | -- case can occur when Expand_Dispatching_Call creates a subprogram | |
4835 | -- type and substitutes the types of access-to-class-wide actuals | |
4836 | -- for the anonymous access-to-specific-type of controlling formals. | |
5d37ba92 ES |
4837 | -- Base_Type is applied because in cases where there is a null |
4838 | -- exclusion the formal may have an access subtype. | |
996ae0b0 RK |
4839 | |
4840 | -- This is suppressed if we specifically suppress accessibility | |
f937473f | 4841 | -- checks at the package level for either the subprogram, or the |
fbf5a39b AC |
4842 | -- package in which it resides. However, we do not suppress it |
4843 | -- simply if the scope has accessibility checks suppressed, since | |
4844 | -- this could cause trouble when clients are compiled with a | |
4845 | -- different suppression setting. The explicit checks at the | |
4846 | -- package level are safe from this point of view. | |
996ae0b0 | 4847 | |
5d37ba92 | 4848 | if (Ekind (Base_Type (Etype (Formal))) = E_Anonymous_Access_Type |
0a36105d | 4849 | or else (Is_Controlling_Formal (Formal) |
5d37ba92 | 4850 | and then Is_Access_Type (Base_Type (Etype (Formal))))) |
996ae0b0 | 4851 | and then not |
fbf5a39b | 4852 | (Explicit_Suppress (E, Accessibility_Check) |
996ae0b0 | 4853 | or else |
fbf5a39b | 4854 | Explicit_Suppress (Scope (E), Accessibility_Check)) |
996ae0b0 | 4855 | and then |
c8ef728f | 4856 | (No (P_Formal) |
996ae0b0 RK |
4857 | or else Present (Extra_Accessibility (P_Formal))) |
4858 | then | |
82c80734 RD |
4859 | -- Temporary kludge: for now we avoid creating the extra formal |
4860 | -- for access parameters of protected operations because of | |
4861 | -- problem with the case of internal protected calls. ??? | |
996ae0b0 RK |
4862 | |
4863 | if Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Definition | |
4864 | and then Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Body | |
4865 | then | |
4866 | Set_Extra_Accessibility | |
5d37ba92 | 4867 | (Formal, Add_Extra_Formal (Formal, Standard_Natural, E, "F")); |
996ae0b0 RK |
4868 | end if; |
4869 | end if; | |
4870 | ||
5d09245e AC |
4871 | -- This label is required when skipping extra formal generation for |
4872 | -- Unchecked_Union parameters. | |
4873 | ||
4874 | <<Skip_Extra_Formal_Generation>> | |
4875 | ||
f937473f RD |
4876 | if Present (P_Formal) then |
4877 | Next_Formal (P_Formal); | |
4878 | end if; | |
4879 | ||
996ae0b0 RK |
4880 | Next_Formal (Formal); |
4881 | end loop; | |
ec4867fa | 4882 | |
19590d70 GD |
4883 | <<Test_For_BIP_Extras>> |
4884 | ||
ec4867fa | 4885 | -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add |
f937473f RD |
4886 | -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind. |
4887 | ||
4888 | if Ada_Version >= Ada_05 and then Is_Build_In_Place_Function (E) then | |
ec4867fa | 4889 | declare |
f937473f RD |
4890 | Result_Subt : constant Entity_Id := Etype (E); |
4891 | ||
4892 | Discard : Entity_Id; | |
4893 | pragma Warnings (Off, Discard); | |
ec4867fa ES |
4894 | |
4895 | begin | |
f937473f RD |
4896 | -- In the case of functions with unconstrained result subtypes, |
4897 | -- add a 3-state formal indicating whether the return object is | |
4898 | -- allocated by the caller (0), or should be allocated by the | |
4899 | -- callee on the secondary stack (1) or in the global heap (2). | |
4900 | -- For the moment we just use Natural for the type of this formal. | |
0a36105d JM |
4901 | -- Note that this formal isn't usually needed in the case where |
4902 | -- the result subtype is constrained, but it is needed when the | |
4903 | -- function has a tagged result, because generally such functions | |
4904 | -- can be called in a dispatching context and such calls must be | |
4905 | -- handled like calls to a class-wide function. | |
4906 | ||
4907 | if not Is_Constrained (Result_Subt) | |
4908 | or else Is_Tagged_Type (Underlying_Type (Result_Subt)) | |
4909 | then | |
f937473f RD |
4910 | Discard := |
4911 | Add_Extra_Formal | |
4912 | (E, Standard_Natural, | |
4913 | E, BIP_Formal_Suffix (BIP_Alloc_Form)); | |
4914 | end if; | |
ec4867fa | 4915 | |
f937473f RD |
4916 | -- In the case of functions whose result type has controlled |
4917 | -- parts, we have an extra formal of type | |
4918 | -- System.Finalization_Implementation.Finalizable_Ptr_Ptr. That | |
4919 | -- is, we are passing a pointer to a finalization list (which is | |
4920 | -- itself a pointer). This extra formal is then passed along to | |
4921 | -- Move_Final_List in case of successful completion of a return | |
4922 | -- statement. We cannot pass an 'in out' parameter, because we | |
4923 | -- need to update the finalization list during an abort-deferred | |
4924 | -- region, rather than using copy-back after the function | |
4925 | -- returns. This is true even if we are able to get away with | |
4926 | -- having 'in out' parameters, which are normally illegal for | |
0a36105d JM |
4927 | -- functions. This formal is also needed when the function has |
4928 | -- a tagged result, because generally such functions can be called | |
4929 | -- in a dispatching context and such calls must be handled like | |
4930 | -- calls to class-wide functions. | |
f937473f | 4931 | |
0a36105d JM |
4932 | if Controlled_Type (Result_Subt) |
4933 | or else Is_Tagged_Type (Underlying_Type (Result_Subt)) | |
f937473f RD |
4934 | then |
4935 | Discard := | |
4936 | Add_Extra_Formal | |
4937 | (E, RTE (RE_Finalizable_Ptr_Ptr), | |
4938 | E, BIP_Formal_Suffix (BIP_Final_List)); | |
4939 | end if; | |
4940 | ||
4941 | -- If the result type contains tasks, we have two extra formals: | |
4942 | -- the master of the tasks to be created, and the caller's | |
4943 | -- activation chain. | |
4944 | ||
4945 | if Has_Task (Result_Subt) then | |
4946 | Discard := | |
4947 | Add_Extra_Formal | |
4948 | (E, RTE (RE_Master_Id), | |
4949 | E, BIP_Formal_Suffix (BIP_Master)); | |
4950 | Discard := | |
4951 | Add_Extra_Formal | |
4952 | (E, RTE (RE_Activation_Chain_Access), | |
4953 | E, BIP_Formal_Suffix (BIP_Activation_Chain)); | |
4954 | end if; | |
ec4867fa | 4955 | |
f937473f RD |
4956 | -- All build-in-place functions get an extra formal that will be |
4957 | -- passed the address of the return object within the caller. | |
ec4867fa | 4958 | |
f937473f RD |
4959 | declare |
4960 | Formal_Type : constant Entity_Id := | |
4961 | Create_Itype | |
4962 | (E_Anonymous_Access_Type, E, | |
4963 | Scope_Id => Scope (E)); | |
4964 | begin | |
4965 | Set_Directly_Designated_Type (Formal_Type, Result_Subt); | |
4966 | Set_Etype (Formal_Type, Formal_Type); | |
4967 | Init_Size_Align (Formal_Type); | |
4968 | Set_Depends_On_Private | |
4969 | (Formal_Type, Has_Private_Component (Formal_Type)); | |
4970 | Set_Is_Public (Formal_Type, Is_Public (Scope (Formal_Type))); | |
4971 | Set_Is_Access_Constant (Formal_Type, False); | |
ec4867fa | 4972 | |
f937473f RD |
4973 | -- Ada 2005 (AI-50217): Propagate the attribute that indicates |
4974 | -- the designated type comes from the limited view (for | |
4975 | -- back-end purposes). | |
ec4867fa | 4976 | |
f937473f | 4977 | Set_From_With_Type (Formal_Type, From_With_Type (Result_Subt)); |
ec4867fa | 4978 | |
f937473f RD |
4979 | Layout_Type (Formal_Type); |
4980 | ||
4981 | Discard := | |
4982 | Add_Extra_Formal | |
4983 | (E, Formal_Type, E, BIP_Formal_Suffix (BIP_Object_Access)); | |
4984 | end; | |
ec4867fa ES |
4985 | end; |
4986 | end if; | |
996ae0b0 RK |
4987 | end Create_Extra_Formals; |
4988 | ||
4989 | ----------------------------- | |
4990 | -- Enter_Overloaded_Entity -- | |
4991 | ----------------------------- | |
4992 | ||
4993 | procedure Enter_Overloaded_Entity (S : Entity_Id) is | |
4994 | E : Entity_Id := Current_Entity_In_Scope (S); | |
4995 | C_E : Entity_Id := Current_Entity (S); | |
4996 | ||
4997 | begin | |
4998 | if Present (E) then | |
4999 | Set_Has_Homonym (E); | |
5000 | Set_Has_Homonym (S); | |
5001 | end if; | |
5002 | ||
5003 | Set_Is_Immediately_Visible (S); | |
5004 | Set_Scope (S, Current_Scope); | |
5005 | ||
5006 | -- Chain new entity if front of homonym in current scope, so that | |
5007 | -- homonyms are contiguous. | |
5008 | ||
5009 | if Present (E) | |
5010 | and then E /= C_E | |
5011 | then | |
5012 | while Homonym (C_E) /= E loop | |
5013 | C_E := Homonym (C_E); | |
5014 | end loop; | |
5015 | ||
5016 | Set_Homonym (C_E, S); | |
5017 | ||
5018 | else | |
5019 | E := C_E; | |
5020 | Set_Current_Entity (S); | |
5021 | end if; | |
5022 | ||
5023 | Set_Homonym (S, E); | |
5024 | ||
5025 | Append_Entity (S, Current_Scope); | |
5026 | Set_Public_Status (S); | |
5027 | ||
5028 | if Debug_Flag_E then | |
5029 | Write_Str ("New overloaded entity chain: "); | |
5030 | Write_Name (Chars (S)); | |
996ae0b0 | 5031 | |
82c80734 | 5032 | E := S; |
996ae0b0 RK |
5033 | while Present (E) loop |
5034 | Write_Str (" "); Write_Int (Int (E)); | |
5035 | E := Homonym (E); | |
5036 | end loop; | |
5037 | ||
5038 | Write_Eol; | |
5039 | end if; | |
5040 | ||
5041 | -- Generate warning for hiding | |
5042 | ||
5043 | if Warn_On_Hiding | |
5044 | and then Comes_From_Source (S) | |
5045 | and then In_Extended_Main_Source_Unit (S) | |
5046 | then | |
5047 | E := S; | |
5048 | loop | |
5049 | E := Homonym (E); | |
5050 | exit when No (E); | |
5051 | ||
5052 | -- Warn unless genuine overloading | |
5053 | ||
f937473f RD |
5054 | if (not Is_Overloadable (E) or else Subtype_Conformant (E, S)) |
5055 | and then (Is_Immediately_Visible (E) | |
5056 | or else | |
5057 | Is_Potentially_Use_Visible (S)) | |
996ae0b0 RK |
5058 | then |
5059 | Error_Msg_Sloc := Sloc (E); | |
5060 | Error_Msg_N ("declaration of & hides one#?", S); | |
5061 | end if; | |
5062 | end loop; | |
5063 | end if; | |
5064 | end Enter_Overloaded_Entity; | |
5065 | ||
5066 | ----------------------------- | |
5067 | -- Find_Corresponding_Spec -- | |
5068 | ----------------------------- | |
5069 | ||
5070 | function Find_Corresponding_Spec (N : Node_Id) return Entity_Id is | |
5071 | Spec : constant Node_Id := Specification (N); | |
5072 | Designator : constant Entity_Id := Defining_Entity (Spec); | |
5073 | ||
5074 | E : Entity_Id; | |
5075 | ||
5076 | begin | |
5077 | E := Current_Entity (Designator); | |
996ae0b0 RK |
5078 | while Present (E) loop |
5079 | ||
5080 | -- We are looking for a matching spec. It must have the same scope, | |
5081 | -- and the same name, and either be type conformant, or be the case | |
5082 | -- of a library procedure spec and its body (which belong to one | |
5083 | -- another regardless of whether they are type conformant or not). | |
5084 | ||
5085 | if Scope (E) = Current_Scope then | |
fbf5a39b AC |
5086 | if Current_Scope = Standard_Standard |
5087 | or else (Ekind (E) = Ekind (Designator) | |
5088 | and then Type_Conformant (E, Designator)) | |
996ae0b0 RK |
5089 | then |
5090 | -- Within an instantiation, we know that spec and body are | |
5091 | -- subtype conformant, because they were subtype conformant | |
5092 | -- in the generic. We choose the subtype-conformant entity | |
5093 | -- here as well, to resolve spurious ambiguities in the | |
5094 | -- instance that were not present in the generic (i.e. when | |
5095 | -- two different types are given the same actual). If we are | |
5096 | -- looking for a spec to match a body, full conformance is | |
5097 | -- expected. | |
5098 | ||
5099 | if In_Instance then | |
5100 | Set_Convention (Designator, Convention (E)); | |
5101 | ||
5102 | if Nkind (N) = N_Subprogram_Body | |
5103 | and then Present (Homonym (E)) | |
5104 | and then not Fully_Conformant (E, Designator) | |
5105 | then | |
5106 | goto Next_Entity; | |
5107 | ||
5108 | elsif not Subtype_Conformant (E, Designator) then | |
5109 | goto Next_Entity; | |
5110 | end if; | |
5111 | end if; | |
5112 | ||
5113 | if not Has_Completion (E) then | |
5114 | ||
5115 | if Nkind (N) /= N_Subprogram_Body_Stub then | |
5116 | Set_Corresponding_Spec (N, E); | |
5117 | end if; | |
5118 | ||
5119 | Set_Has_Completion (E); | |
5120 | return E; | |
5121 | ||
5122 | elsif Nkind (Parent (N)) = N_Subunit then | |
5123 | ||
5124 | -- If this is the proper body of a subunit, the completion | |
5125 | -- flag is set when analyzing the stub. | |
5126 | ||
5127 | return E; | |
5128 | ||
81db9d77 ES |
5129 | -- If E is an internal function with a controlling result |
5130 | -- that was created for an operation inherited by a null | |
5131 | -- extension, it may be overridden by a body without a previous | |
5132 | -- spec (one more reason why these should be shunned). In that | |
5133 | -- case remove the generated body, because the current one is | |
5134 | -- the explicit overriding. | |
5135 | ||
5136 | elsif Ekind (E) = E_Function | |
5137 | and then Ada_Version >= Ada_05 | |
5138 | and then not Comes_From_Source (E) | |
5139 | and then Has_Controlling_Result (E) | |
5140 | and then Is_Null_Extension (Etype (E)) | |
5141 | and then Comes_From_Source (Spec) | |
5142 | then | |
5143 | Set_Has_Completion (E, False); | |
5144 | ||
5145 | if Expander_Active then | |
5146 | Remove | |
5147 | (Unit_Declaration_Node | |
5148 | (Corresponding_Body (Unit_Declaration_Node (E)))); | |
5149 | return E; | |
5150 | ||
5151 | -- If expansion is disabled, the wrapper function has not | |
5152 | -- been generated, and this is the standard case of a late | |
5153 | -- body overriding an inherited operation. | |
5154 | ||
5155 | else | |
5156 | return Empty; | |
5157 | end if; | |
5158 | ||
996ae0b0 RK |
5159 | -- If body already exists, this is an error unless the |
5160 | -- previous declaration is the implicit declaration of | |
5161 | -- a derived subprogram, or this is a spurious overloading | |
5162 | -- in an instance. | |
5163 | ||
5164 | elsif No (Alias (E)) | |
5165 | and then not Is_Intrinsic_Subprogram (E) | |
5166 | and then not In_Instance | |
5167 | then | |
5168 | Error_Msg_Sloc := Sloc (E); | |
07fc65c4 GB |
5169 | if Is_Imported (E) then |
5170 | Error_Msg_NE | |
5171 | ("body not allowed for imported subprogram & declared#", | |
5172 | N, E); | |
5173 | else | |
5174 | Error_Msg_NE ("duplicate body for & declared#", N, E); | |
5175 | end if; | |
996ae0b0 RK |
5176 | end if; |
5177 | ||
5178 | elsif Is_Child_Unit (E) | |
5179 | and then | |
5180 | Nkind (Unit_Declaration_Node (Designator)) = N_Subprogram_Body | |
5181 | and then | |
5d37ba92 ES |
5182 | Nkind (Parent (Unit_Declaration_Node (Designator))) = |
5183 | N_Compilation_Unit | |
996ae0b0 | 5184 | then |
996ae0b0 RK |
5185 | -- Child units cannot be overloaded, so a conformance mismatch |
5186 | -- between body and a previous spec is an error. | |
5187 | ||
5188 | Error_Msg_N | |
5189 | ("body of child unit does not match previous declaration", N); | |
5190 | end if; | |
5191 | end if; | |
5192 | ||
5193 | <<Next_Entity>> | |
5194 | E := Homonym (E); | |
5195 | end loop; | |
5196 | ||
5197 | -- On exit, we know that no previous declaration of subprogram exists | |
5198 | ||
5199 | return Empty; | |
5200 | end Find_Corresponding_Spec; | |
5201 | ||
5202 | ---------------------- | |
5203 | -- Fully_Conformant -- | |
5204 | ---------------------- | |
5205 | ||
5206 | function Fully_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is | |
5207 | Result : Boolean; | |
996ae0b0 RK |
5208 | begin |
5209 | Check_Conformance (New_Id, Old_Id, Fully_Conformant, False, Result); | |
5210 | return Result; | |
5211 | end Fully_Conformant; | |
5212 | ||
5213 | ---------------------------------- | |
5214 | -- Fully_Conformant_Expressions -- | |
5215 | ---------------------------------- | |
5216 | ||
5217 | function Fully_Conformant_Expressions | |
5218 | (Given_E1 : Node_Id; | |
d05ef0ab | 5219 | Given_E2 : Node_Id) return Boolean |
996ae0b0 RK |
5220 | is |
5221 | E1 : constant Node_Id := Original_Node (Given_E1); | |
5222 | E2 : constant Node_Id := Original_Node (Given_E2); | |
5223 | -- We always test conformance on original nodes, since it is possible | |
5224 | -- for analysis and/or expansion to make things look as though they | |
5225 | -- conform when they do not, e.g. by converting 1+2 into 3. | |
5226 | ||
5227 | function FCE (Given_E1, Given_E2 : Node_Id) return Boolean | |
5228 | renames Fully_Conformant_Expressions; | |
5229 | ||
5230 | function FCL (L1, L2 : List_Id) return Boolean; | |
5231 | -- Compare elements of two lists for conformance. Elements have to | |
5232 | -- be conformant, and actuals inserted as default parameters do not | |
5233 | -- match explicit actuals with the same value. | |
5234 | ||
5235 | function FCO (Op_Node, Call_Node : Node_Id) return Boolean; | |
e895b435 | 5236 | -- Compare an operator node with a function call |
996ae0b0 RK |
5237 | |
5238 | --------- | |
5239 | -- FCL -- | |
5240 | --------- | |
5241 | ||
5242 | function FCL (L1, L2 : List_Id) return Boolean is | |
5243 | N1, N2 : Node_Id; | |
5244 | ||
5245 | begin | |
5246 | if L1 = No_List then | |
5247 | N1 := Empty; | |
5248 | else | |
5249 | N1 := First (L1); | |
5250 | end if; | |
5251 | ||
5252 | if L2 = No_List then | |
5253 | N2 := Empty; | |
5254 | else | |
5255 | N2 := First (L2); | |
5256 | end if; | |
5257 | ||
5258 | -- Compare two lists, skipping rewrite insertions (we want to | |
5259 | -- compare the original trees, not the expanded versions!) | |
5260 | ||
5261 | loop | |
5262 | if Is_Rewrite_Insertion (N1) then | |
5263 | Next (N1); | |
5264 | elsif Is_Rewrite_Insertion (N2) then | |
5265 | Next (N2); | |
5266 | elsif No (N1) then | |
5267 | return No (N2); | |
5268 | elsif No (N2) then | |
5269 | return False; | |
5270 | elsif not FCE (N1, N2) then | |
5271 | return False; | |
5272 | else | |
5273 | Next (N1); | |
5274 | Next (N2); | |
5275 | end if; | |
5276 | end loop; | |
5277 | end FCL; | |
5278 | ||
5279 | --------- | |
5280 | -- FCO -- | |
5281 | --------- | |
5282 | ||
5283 | function FCO (Op_Node, Call_Node : Node_Id) return Boolean is | |
5284 | Actuals : constant List_Id := Parameter_Associations (Call_Node); | |
5285 | Act : Node_Id; | |
5286 | ||
5287 | begin | |
5288 | if No (Actuals) | |
5289 | or else Entity (Op_Node) /= Entity (Name (Call_Node)) | |
5290 | then | |
5291 | return False; | |
5292 | ||
5293 | else | |
5294 | Act := First (Actuals); | |
5295 | ||
5296 | if Nkind (Op_Node) in N_Binary_Op then | |
5297 | ||
5298 | if not FCE (Left_Opnd (Op_Node), Act) then | |
5299 | return False; | |
5300 | end if; | |
5301 | ||
5302 | Next (Act); | |
5303 | end if; | |
5304 | ||
5305 | return Present (Act) | |
5306 | and then FCE (Right_Opnd (Op_Node), Act) | |
5307 | and then No (Next (Act)); | |
5308 | end if; | |
5309 | end FCO; | |
5310 | ||
5311 | -- Start of processing for Fully_Conformant_Expressions | |
5312 | ||
5313 | begin | |
5314 | -- Non-conformant if paren count does not match. Note: if some idiot | |
5315 | -- complains that we don't do this right for more than 3 levels of | |
0a36105d | 5316 | -- parentheses, they will be treated with the respect they deserve! |
996ae0b0 RK |
5317 | |
5318 | if Paren_Count (E1) /= Paren_Count (E2) then | |
5319 | return False; | |
5320 | ||
82c80734 RD |
5321 | -- If same entities are referenced, then they are conformant even if |
5322 | -- they have different forms (RM 8.3.1(19-20)). | |
996ae0b0 RK |
5323 | |
5324 | elsif Is_Entity_Name (E1) and then Is_Entity_Name (E2) then | |
5325 | if Present (Entity (E1)) then | |
5326 | return Entity (E1) = Entity (E2) | |
5327 | or else (Chars (Entity (E1)) = Chars (Entity (E2)) | |
5328 | and then Ekind (Entity (E1)) = E_Discriminant | |
5329 | and then Ekind (Entity (E2)) = E_In_Parameter); | |
5330 | ||
5331 | elsif Nkind (E1) = N_Expanded_Name | |
5332 | and then Nkind (E2) = N_Expanded_Name | |
5333 | and then Nkind (Selector_Name (E1)) = N_Character_Literal | |
5334 | and then Nkind (Selector_Name (E2)) = N_Character_Literal | |
5335 | then | |
5336 | return Chars (Selector_Name (E1)) = Chars (Selector_Name (E2)); | |
5337 | ||
5338 | else | |
5339 | -- Identifiers in component associations don't always have | |
5340 | -- entities, but their names must conform. | |
5341 | ||
5342 | return Nkind (E1) = N_Identifier | |
5343 | and then Nkind (E2) = N_Identifier | |
5344 | and then Chars (E1) = Chars (E2); | |
5345 | end if; | |
5346 | ||
5347 | elsif Nkind (E1) = N_Character_Literal | |
5348 | and then Nkind (E2) = N_Expanded_Name | |
5349 | then | |
5350 | return Nkind (Selector_Name (E2)) = N_Character_Literal | |
5351 | and then Chars (E1) = Chars (Selector_Name (E2)); | |
5352 | ||
5353 | elsif Nkind (E2) = N_Character_Literal | |
5354 | and then Nkind (E1) = N_Expanded_Name | |
5355 | then | |
5356 | return Nkind (Selector_Name (E1)) = N_Character_Literal | |
5357 | and then Chars (E2) = Chars (Selector_Name (E1)); | |
5358 | ||
5359 | elsif Nkind (E1) in N_Op | |
5360 | and then Nkind (E2) = N_Function_Call | |
5361 | then | |
5362 | return FCO (E1, E2); | |
5363 | ||
5364 | elsif Nkind (E2) in N_Op | |
5365 | and then Nkind (E1) = N_Function_Call | |
5366 | then | |
5367 | return FCO (E2, E1); | |
5368 | ||
5369 | -- Otherwise we must have the same syntactic entity | |
5370 | ||
5371 | elsif Nkind (E1) /= Nkind (E2) then | |
5372 | return False; | |
5373 | ||
5374 | -- At this point, we specialize by node type | |
5375 | ||
5376 | else | |
5377 | case Nkind (E1) is | |
5378 | ||
5379 | when N_Aggregate => | |
5380 | return | |
5381 | FCL (Expressions (E1), Expressions (E2)) | |
5382 | and then FCL (Component_Associations (E1), | |
5383 | Component_Associations (E2)); | |
5384 | ||
5385 | when N_Allocator => | |
5386 | if Nkind (Expression (E1)) = N_Qualified_Expression | |
5387 | or else | |
5388 | Nkind (Expression (E2)) = N_Qualified_Expression | |
5389 | then | |
5390 | return FCE (Expression (E1), Expression (E2)); | |
5391 | ||
5392 | -- Check that the subtype marks and any constraints | |
5393 | -- are conformant | |
5394 | ||
5395 | else | |
5396 | declare | |
5397 | Indic1 : constant Node_Id := Expression (E1); | |
5398 | Indic2 : constant Node_Id := Expression (E2); | |
5399 | Elt1 : Node_Id; | |
5400 | Elt2 : Node_Id; | |
5401 | ||
5402 | begin | |
5403 | if Nkind (Indic1) /= N_Subtype_Indication then | |
5404 | return | |
5405 | Nkind (Indic2) /= N_Subtype_Indication | |
5406 | and then Entity (Indic1) = Entity (Indic2); | |
5407 | ||
5408 | elsif Nkind (Indic2) /= N_Subtype_Indication then | |
5409 | return | |
5410 | Nkind (Indic1) /= N_Subtype_Indication | |
5411 | and then Entity (Indic1) = Entity (Indic2); | |
5412 | ||
5413 | else | |
5414 | if Entity (Subtype_Mark (Indic1)) /= | |
5415 | Entity (Subtype_Mark (Indic2)) | |
5416 | then | |
5417 | return False; | |
5418 | end if; | |
5419 | ||
5420 | Elt1 := First (Constraints (Constraint (Indic1))); | |
5421 | Elt2 := First (Constraints (Constraint (Indic2))); | |
5422 | ||
5423 | while Present (Elt1) and then Present (Elt2) loop | |
5424 | if not FCE (Elt1, Elt2) then | |
5425 | return False; | |
5426 | end if; | |
5427 | ||
5428 | Next (Elt1); | |
5429 | Next (Elt2); | |
5430 | end loop; | |
5431 | ||
5432 | return True; | |
5433 | end if; | |
5434 | end; | |
5435 | end if; | |
5436 | ||
5437 | when N_Attribute_Reference => | |
5438 | return | |
5439 | Attribute_Name (E1) = Attribute_Name (E2) | |
5440 | and then FCL (Expressions (E1), Expressions (E2)); | |
5441 | ||
5442 | when N_Binary_Op => | |
5443 | return | |
5444 | Entity (E1) = Entity (E2) | |
5445 | and then FCE (Left_Opnd (E1), Left_Opnd (E2)) | |
5446 | and then FCE (Right_Opnd (E1), Right_Opnd (E2)); | |
5447 | ||
ec4867fa | 5448 | when N_And_Then | N_Or_Else | N_Membership_Test => |
996ae0b0 RK |
5449 | return |
5450 | FCE (Left_Opnd (E1), Left_Opnd (E2)) | |
5451 | and then | |
5452 | FCE (Right_Opnd (E1), Right_Opnd (E2)); | |
5453 | ||
5454 | when N_Character_Literal => | |
5455 | return | |
5456 | Char_Literal_Value (E1) = Char_Literal_Value (E2); | |
5457 | ||
5458 | when N_Component_Association => | |
5459 | return | |
5460 | FCL (Choices (E1), Choices (E2)) | |
5461 | and then FCE (Expression (E1), Expression (E2)); | |
5462 | ||
5463 | when N_Conditional_Expression => | |
5464 | return | |
5465 | FCL (Expressions (E1), Expressions (E2)); | |
5466 | ||
5467 | when N_Explicit_Dereference => | |
5468 | return | |
5469 | FCE (Prefix (E1), Prefix (E2)); | |
5470 | ||
5471 | when N_Extension_Aggregate => | |
5472 | return | |
5473 | FCL (Expressions (E1), Expressions (E2)) | |
5474 | and then Null_Record_Present (E1) = | |
5475 | Null_Record_Present (E2) | |
5476 | and then FCL (Component_Associations (E1), | |
5477 | Component_Associations (E2)); | |
5478 | ||
5479 | when N_Function_Call => | |
5480 | return | |
5481 | FCE (Name (E1), Name (E2)) | |
5482 | and then FCL (Parameter_Associations (E1), | |
5483 | Parameter_Associations (E2)); | |
5484 | ||
5485 | when N_Indexed_Component => | |
5486 | return | |
5487 | FCE (Prefix (E1), Prefix (E2)) | |
5488 | and then FCL (Expressions (E1), Expressions (E2)); | |
5489 | ||
5490 | when N_Integer_Literal => | |
5491 | return (Intval (E1) = Intval (E2)); | |
5492 | ||
5493 | when N_Null => | |
5494 | return True; | |
5495 | ||
5496 | when N_Operator_Symbol => | |
5497 | return | |
5498 | Chars (E1) = Chars (E2); | |
5499 | ||
5500 | when N_Others_Choice => | |
5501 | return True; | |
5502 | ||
5503 | when N_Parameter_Association => | |
5504 | return | |
996ae0b0 RK |
5505 | Chars (Selector_Name (E1)) = Chars (Selector_Name (E2)) |
5506 | and then FCE (Explicit_Actual_Parameter (E1), | |
5507 | Explicit_Actual_Parameter (E2)); | |
5508 | ||
5509 | when N_Qualified_Expression => | |
5510 | return | |
5511 | FCE (Subtype_Mark (E1), Subtype_Mark (E2)) | |
5512 | and then FCE (Expression (E1), Expression (E2)); | |
5513 | ||
5514 | when N_Range => | |
5515 | return | |
5516 | FCE (Low_Bound (E1), Low_Bound (E2)) | |
5517 | and then FCE (High_Bound (E1), High_Bound (E2)); | |
5518 | ||
5519 | when N_Real_Literal => | |
5520 | return (Realval (E1) = Realval (E2)); | |
5521 | ||
5522 | when N_Selected_Component => | |
5523 | return | |
5524 | FCE (Prefix (E1), Prefix (E2)) | |
5525 | and then FCE (Selector_Name (E1), Selector_Name (E2)); | |
5526 | ||
5527 | when N_Slice => | |
5528 | return | |
5529 | FCE (Prefix (E1), Prefix (E2)) | |
5530 | and then FCE (Discrete_Range (E1), Discrete_Range (E2)); | |
5531 | ||
5532 | when N_String_Literal => | |
5533 | declare | |
5534 | S1 : constant String_Id := Strval (E1); | |
5535 | S2 : constant String_Id := Strval (E2); | |
5536 | L1 : constant Nat := String_Length (S1); | |
5537 | L2 : constant Nat := String_Length (S2); | |
5538 | ||
5539 | begin | |
5540 | if L1 /= L2 then | |
5541 | return False; | |
5542 | ||
5543 | else | |
5544 | for J in 1 .. L1 loop | |
5545 | if Get_String_Char (S1, J) /= | |
5546 | Get_String_Char (S2, J) | |
5547 | then | |
5548 | return False; | |
5549 | end if; | |
5550 | end loop; | |
5551 | ||
5552 | return True; | |
5553 | end if; | |
5554 | end; | |
5555 | ||
5556 | when N_Type_Conversion => | |
5557 | return | |
5558 | FCE (Subtype_Mark (E1), Subtype_Mark (E2)) | |
5559 | and then FCE (Expression (E1), Expression (E2)); | |
5560 | ||
5561 | when N_Unary_Op => | |
5562 | return | |
5563 | Entity (E1) = Entity (E2) | |
5564 | and then FCE (Right_Opnd (E1), Right_Opnd (E2)); | |
5565 | ||
5566 | when N_Unchecked_Type_Conversion => | |
5567 | return | |
5568 | FCE (Subtype_Mark (E1), Subtype_Mark (E2)) | |
5569 | and then FCE (Expression (E1), Expression (E2)); | |
5570 | ||
5571 | -- All other node types cannot appear in this context. Strictly | |
5572 | -- we should raise a fatal internal error. Instead we just ignore | |
5573 | -- the nodes. This means that if anyone makes a mistake in the | |
5574 | -- expander and mucks an expression tree irretrievably, the | |
5575 | -- result will be a failure to detect a (probably very obscure) | |
5576 | -- case of non-conformance, which is better than bombing on some | |
5577 | -- case where two expressions do in fact conform. | |
5578 | ||
5579 | when others => | |
5580 | return True; | |
5581 | ||
5582 | end case; | |
5583 | end if; | |
5584 | end Fully_Conformant_Expressions; | |
5585 | ||
fbf5a39b AC |
5586 | ---------------------------------------- |
5587 | -- Fully_Conformant_Discrete_Subtypes -- | |
5588 | ---------------------------------------- | |
5589 | ||
5590 | function Fully_Conformant_Discrete_Subtypes | |
5591 | (Given_S1 : Node_Id; | |
d05ef0ab | 5592 | Given_S2 : Node_Id) return Boolean |
fbf5a39b AC |
5593 | is |
5594 | S1 : constant Node_Id := Original_Node (Given_S1); | |
5595 | S2 : constant Node_Id := Original_Node (Given_S2); | |
5596 | ||
5597 | function Conforming_Bounds (B1, B2 : Node_Id) return Boolean; | |
82c80734 RD |
5598 | -- Special-case for a bound given by a discriminant, which in the body |
5599 | -- is replaced with the discriminal of the enclosing type. | |
fbf5a39b AC |
5600 | |
5601 | function Conforming_Ranges (R1, R2 : Node_Id) return Boolean; | |
e895b435 | 5602 | -- Check both bounds |
fbf5a39b | 5603 | |
5d37ba92 ES |
5604 | ----------------------- |
5605 | -- Conforming_Bounds -- | |
5606 | ----------------------- | |
5607 | ||
fbf5a39b AC |
5608 | function Conforming_Bounds (B1, B2 : Node_Id) return Boolean is |
5609 | begin | |
5610 | if Is_Entity_Name (B1) | |
5611 | and then Is_Entity_Name (B2) | |
5612 | and then Ekind (Entity (B1)) = E_Discriminant | |
5613 | then | |
5614 | return Chars (B1) = Chars (B2); | |
5615 | ||
5616 | else | |
5617 | return Fully_Conformant_Expressions (B1, B2); | |
5618 | end if; | |
5619 | end Conforming_Bounds; | |
5620 | ||
5d37ba92 ES |
5621 | ----------------------- |
5622 | -- Conforming_Ranges -- | |
5623 | ----------------------- | |
5624 | ||
fbf5a39b AC |
5625 | function Conforming_Ranges (R1, R2 : Node_Id) return Boolean is |
5626 | begin | |
5627 | return | |
5628 | Conforming_Bounds (Low_Bound (R1), Low_Bound (R2)) | |
5629 | and then | |
5630 | Conforming_Bounds (High_Bound (R1), High_Bound (R2)); | |
5631 | end Conforming_Ranges; | |
5632 | ||
5633 | -- Start of processing for Fully_Conformant_Discrete_Subtypes | |
5634 | ||
5635 | begin | |
5636 | if Nkind (S1) /= Nkind (S2) then | |
5637 | return False; | |
5638 | ||
5639 | elsif Is_Entity_Name (S1) then | |
5640 | return Entity (S1) = Entity (S2); | |
5641 | ||
5642 | elsif Nkind (S1) = N_Range then | |
5643 | return Conforming_Ranges (S1, S2); | |
5644 | ||
5645 | elsif Nkind (S1) = N_Subtype_Indication then | |
5646 | return | |
5647 | Entity (Subtype_Mark (S1)) = Entity (Subtype_Mark (S2)) | |
5648 | and then | |
5649 | Conforming_Ranges | |
5650 | (Range_Expression (Constraint (S1)), | |
5651 | Range_Expression (Constraint (S2))); | |
5652 | else | |
5653 | return True; | |
5654 | end if; | |
5655 | end Fully_Conformant_Discrete_Subtypes; | |
5656 | ||
996ae0b0 RK |
5657 | -------------------- |
5658 | -- Install_Entity -- | |
5659 | -------------------- | |
5660 | ||
5661 | procedure Install_Entity (E : Entity_Id) is | |
5662 | Prev : constant Entity_Id := Current_Entity (E); | |
996ae0b0 RK |
5663 | begin |
5664 | Set_Is_Immediately_Visible (E); | |
5665 | Set_Current_Entity (E); | |
5666 | Set_Homonym (E, Prev); | |
5667 | end Install_Entity; | |
5668 | ||
5669 | --------------------- | |
5670 | -- Install_Formals -- | |
5671 | --------------------- | |
5672 | ||
5673 | procedure Install_Formals (Id : Entity_Id) is | |
5674 | F : Entity_Id; | |
996ae0b0 RK |
5675 | begin |
5676 | F := First_Formal (Id); | |
996ae0b0 RK |
5677 | while Present (F) loop |
5678 | Install_Entity (F); | |
5679 | Next_Formal (F); | |
5680 | end loop; | |
5681 | end Install_Formals; | |
5682 | ||
5683 | --------------------------------- | |
5684 | -- Is_Non_Overriding_Operation -- | |
5685 | --------------------------------- | |
5686 | ||
5687 | function Is_Non_Overriding_Operation | |
5688 | (Prev_E : Entity_Id; | |
d05ef0ab | 5689 | New_E : Entity_Id) return Boolean |
996ae0b0 RK |
5690 | is |
5691 | Formal : Entity_Id; | |
5692 | F_Typ : Entity_Id; | |
5693 | G_Typ : Entity_Id := Empty; | |
5694 | ||
5695 | function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id; | |
5d37ba92 ES |
5696 | -- If F_Type is a derived type associated with a generic actual subtype, |
5697 | -- then return its Generic_Parent_Type attribute, else return Empty. | |
996ae0b0 RK |
5698 | |
5699 | function Types_Correspond | |
5700 | (P_Type : Entity_Id; | |
d05ef0ab | 5701 | N_Type : Entity_Id) return Boolean; |
82c80734 RD |
5702 | -- Returns true if and only if the types (or designated types in the |
5703 | -- case of anonymous access types) are the same or N_Type is derived | |
5704 | -- directly or indirectly from P_Type. | |
996ae0b0 RK |
5705 | |
5706 | ----------------------------- | |
5707 | -- Get_Generic_Parent_Type -- | |
5708 | ----------------------------- | |
5709 | ||
5710 | function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id is | |
5711 | G_Typ : Entity_Id; | |
5712 | Indic : Node_Id; | |
5713 | ||
5714 | begin | |
5715 | if Is_Derived_Type (F_Typ) | |
5716 | and then Nkind (Parent (F_Typ)) = N_Full_Type_Declaration | |
5717 | then | |
82c80734 RD |
5718 | -- The tree must be traversed to determine the parent subtype in |
5719 | -- the generic unit, which unfortunately isn't always available | |
5720 | -- via semantic attributes. ??? (Note: The use of Original_Node | |
5721 | -- is needed for cases where a full derived type has been | |
5722 | -- rewritten.) | |
996ae0b0 RK |
5723 | |
5724 | Indic := Subtype_Indication | |
5725 | (Type_Definition (Original_Node (Parent (F_Typ)))); | |
5726 | ||
5727 | if Nkind (Indic) = N_Subtype_Indication then | |
5728 | G_Typ := Entity (Subtype_Mark (Indic)); | |
5729 | else | |
5730 | G_Typ := Entity (Indic); | |
5731 | end if; | |
5732 | ||
5733 | if Nkind (Parent (G_Typ)) = N_Subtype_Declaration | |
5734 | and then Present (Generic_Parent_Type (Parent (G_Typ))) | |
5735 | then | |
5736 | return Generic_Parent_Type (Parent (G_Typ)); | |
5737 | end if; | |
5738 | end if; | |
5739 | ||
5740 | return Empty; | |
5741 | end Get_Generic_Parent_Type; | |
5742 | ||
5743 | ---------------------- | |
5744 | -- Types_Correspond -- | |
5745 | ---------------------- | |
5746 | ||
5747 | function Types_Correspond | |
5748 | (P_Type : Entity_Id; | |
d05ef0ab | 5749 | N_Type : Entity_Id) return Boolean |
996ae0b0 RK |
5750 | is |
5751 | Prev_Type : Entity_Id := Base_Type (P_Type); | |
5752 | New_Type : Entity_Id := Base_Type (N_Type); | |
5753 | ||
5754 | begin | |
5755 | if Ekind (Prev_Type) = E_Anonymous_Access_Type then | |
5756 | Prev_Type := Designated_Type (Prev_Type); | |
5757 | end if; | |
5758 | ||
5759 | if Ekind (New_Type) = E_Anonymous_Access_Type then | |
5760 | New_Type := Designated_Type (New_Type); | |
5761 | end if; | |
5762 | ||
5763 | if Prev_Type = New_Type then | |
5764 | return True; | |
5765 | ||
5766 | elsif not Is_Class_Wide_Type (New_Type) then | |
5767 | while Etype (New_Type) /= New_Type loop | |
5768 | New_Type := Etype (New_Type); | |
5769 | if New_Type = Prev_Type then | |
5770 | return True; | |
5771 | end if; | |
5772 | end loop; | |
5773 | end if; | |
5774 | return False; | |
5775 | end Types_Correspond; | |
5776 | ||
5777 | -- Start of processing for Is_Non_Overriding_Operation | |
5778 | ||
5779 | begin | |
82c80734 RD |
5780 | -- In the case where both operations are implicit derived subprograms |
5781 | -- then neither overrides the other. This can only occur in certain | |
5782 | -- obscure cases (e.g., derivation from homographs created in a generic | |
5783 | -- instantiation). | |
996ae0b0 RK |
5784 | |
5785 | if Present (Alias (Prev_E)) and then Present (Alias (New_E)) then | |
5786 | return True; | |
5787 | ||
5788 | elsif Ekind (Current_Scope) = E_Package | |
5789 | and then Is_Generic_Instance (Current_Scope) | |
5790 | and then In_Private_Part (Current_Scope) | |
5791 | and then Comes_From_Source (New_E) | |
5792 | then | |
5793 | -- We examine the formals and result subtype of the inherited | |
82c80734 RD |
5794 | -- operation, to determine whether their type is derived from (the |
5795 | -- instance of) a generic type. | |
996ae0b0 RK |
5796 | |
5797 | Formal := First_Formal (Prev_E); | |
5798 | ||
5799 | while Present (Formal) loop | |
5800 | F_Typ := Base_Type (Etype (Formal)); | |
5801 | ||
5802 | if Ekind (F_Typ) = E_Anonymous_Access_Type then | |
5803 | F_Typ := Designated_Type (F_Typ); | |
5804 | end if; | |
5805 | ||
5806 | G_Typ := Get_Generic_Parent_Type (F_Typ); | |
5807 | ||
5808 | Next_Formal (Formal); | |
5809 | end loop; | |
5810 | ||
c8ef728f | 5811 | if No (G_Typ) and then Ekind (Prev_E) = E_Function then |
996ae0b0 RK |
5812 | G_Typ := Get_Generic_Parent_Type (Base_Type (Etype (Prev_E))); |
5813 | end if; | |
5814 | ||
5815 | if No (G_Typ) then | |
5816 | return False; | |
5817 | end if; | |
5818 | ||
5819 | -- If the generic type is a private type, then the original | |
5820 | -- operation was not overriding in the generic, because there was | |
5821 | -- no primitive operation to override. | |
5822 | ||
5823 | if Nkind (Parent (G_Typ)) = N_Formal_Type_Declaration | |
5824 | and then Nkind (Formal_Type_Definition (Parent (G_Typ))) = | |
5825 | N_Formal_Private_Type_Definition | |
5826 | then | |
5827 | return True; | |
5828 | ||
5829 | -- The generic parent type is the ancestor of a formal derived | |
5830 | -- type declaration. We need to check whether it has a primitive | |
5831 | -- operation that should be overridden by New_E in the generic. | |
5832 | ||
5833 | else | |
5834 | declare | |
5835 | P_Formal : Entity_Id; | |
5836 | N_Formal : Entity_Id; | |
5837 | P_Typ : Entity_Id; | |
5838 | N_Typ : Entity_Id; | |
5839 | P_Prim : Entity_Id; | |
5840 | Prim_Elt : Elmt_Id := First_Elmt (Primitive_Operations (G_Typ)); | |
5841 | ||
5842 | begin | |
5843 | while Present (Prim_Elt) loop | |
5844 | P_Prim := Node (Prim_Elt); | |
fbf5a39b | 5845 | |
996ae0b0 RK |
5846 | if Chars (P_Prim) = Chars (New_E) |
5847 | and then Ekind (P_Prim) = Ekind (New_E) | |
5848 | then | |
5849 | P_Formal := First_Formal (P_Prim); | |
5850 | N_Formal := First_Formal (New_E); | |
5851 | while Present (P_Formal) and then Present (N_Formal) loop | |
5852 | P_Typ := Etype (P_Formal); | |
5853 | N_Typ := Etype (N_Formal); | |
5854 | ||
5855 | if not Types_Correspond (P_Typ, N_Typ) then | |
5856 | exit; | |
5857 | end if; | |
5858 | ||
5859 | Next_Entity (P_Formal); | |
5860 | Next_Entity (N_Formal); | |
5861 | end loop; | |
5862 | ||
82c80734 RD |
5863 | -- Found a matching primitive operation belonging to the |
5864 | -- formal ancestor type, so the new subprogram is | |
5865 | -- overriding. | |
996ae0b0 | 5866 | |
c8ef728f ES |
5867 | if No (P_Formal) |
5868 | and then No (N_Formal) | |
996ae0b0 RK |
5869 | and then (Ekind (New_E) /= E_Function |
5870 | or else | |
5871 | Types_Correspond | |
5872 | (Etype (P_Prim), Etype (New_E))) | |
5873 | then | |
5874 | return False; | |
5875 | end if; | |
5876 | end if; | |
5877 | ||
5878 | Next_Elmt (Prim_Elt); | |
5879 | end loop; | |
5880 | ||
82c80734 RD |
5881 | -- If no match found, then the new subprogram does not |
5882 | -- override in the generic (nor in the instance). | |
996ae0b0 RK |
5883 | |
5884 | return True; | |
5885 | end; | |
5886 | end if; | |
5887 | else | |
5888 | return False; | |
5889 | end if; | |
5890 | end Is_Non_Overriding_Operation; | |
5891 | ||
5892 | ------------------------------ | |
5893 | -- Make_Inequality_Operator -- | |
5894 | ------------------------------ | |
5895 | ||
5896 | -- S is the defining identifier of an equality operator. We build a | |
5897 | -- subprogram declaration with the right signature. This operation is | |
5898 | -- intrinsic, because it is always expanded as the negation of the | |
5899 | -- call to the equality function. | |
5900 | ||
5901 | procedure Make_Inequality_Operator (S : Entity_Id) is | |
5902 | Loc : constant Source_Ptr := Sloc (S); | |
5903 | Decl : Node_Id; | |
5904 | Formals : List_Id; | |
5905 | Op_Name : Entity_Id; | |
5906 | ||
c8ef728f ES |
5907 | FF : constant Entity_Id := First_Formal (S); |
5908 | NF : constant Entity_Id := Next_Formal (FF); | |
996ae0b0 RK |
5909 | |
5910 | begin | |
c8ef728f | 5911 | -- Check that equality was properly defined, ignore call if not |
996ae0b0 | 5912 | |
c8ef728f | 5913 | if No (NF) then |
996ae0b0 RK |
5914 | return; |
5915 | end if; | |
5916 | ||
c8ef728f ES |
5917 | declare |
5918 | A : constant Entity_Id := | |
5919 | Make_Defining_Identifier (Sloc (FF), | |
5920 | Chars => Chars (FF)); | |
5921 | ||
5d37ba92 ES |
5922 | B : constant Entity_Id := |
5923 | Make_Defining_Identifier (Sloc (NF), | |
5924 | Chars => Chars (NF)); | |
c8ef728f ES |
5925 | |
5926 | begin | |
5927 | Op_Name := Make_Defining_Operator_Symbol (Loc, Name_Op_Ne); | |
5928 | ||
5929 | Formals := New_List ( | |
5930 | Make_Parameter_Specification (Loc, | |
5931 | Defining_Identifier => A, | |
5932 | Parameter_Type => | |
5933 | New_Reference_To (Etype (First_Formal (S)), | |
5934 | Sloc (Etype (First_Formal (S))))), | |
5935 | ||
5936 | Make_Parameter_Specification (Loc, | |
5937 | Defining_Identifier => B, | |
5938 | Parameter_Type => | |
5939 | New_Reference_To (Etype (Next_Formal (First_Formal (S))), | |
5940 | Sloc (Etype (Next_Formal (First_Formal (S))))))); | |
5941 | ||
5942 | Decl := | |
5943 | Make_Subprogram_Declaration (Loc, | |
5944 | Specification => | |
5945 | Make_Function_Specification (Loc, | |
5946 | Defining_Unit_Name => Op_Name, | |
5947 | Parameter_Specifications => Formals, | |
5948 | Result_Definition => | |
5949 | New_Reference_To (Standard_Boolean, Loc))); | |
5950 | ||
5951 | -- Insert inequality right after equality if it is explicit or after | |
5952 | -- the derived type when implicit. These entities are created only | |
5953 | -- for visibility purposes, and eventually replaced in the course of | |
5954 | -- expansion, so they do not need to be attached to the tree and seen | |
5955 | -- by the back-end. Keeping them internal also avoids spurious | |
5956 | -- freezing problems. The declaration is inserted in the tree for | |
5957 | -- analysis, and removed afterwards. If the equality operator comes | |
5958 | -- from an explicit declaration, attach the inequality immediately | |
5959 | -- after. Else the equality is inherited from a derived type | |
5960 | -- declaration, so insert inequality after that declaration. | |
5961 | ||
5962 | if No (Alias (S)) then | |
5963 | Insert_After (Unit_Declaration_Node (S), Decl); | |
5964 | elsif Is_List_Member (Parent (S)) then | |
5965 | Insert_After (Parent (S), Decl); | |
5966 | else | |
5967 | Insert_After (Parent (Etype (First_Formal (S))), Decl); | |
5968 | end if; | |
996ae0b0 | 5969 | |
c8ef728f ES |
5970 | Mark_Rewrite_Insertion (Decl); |
5971 | Set_Is_Intrinsic_Subprogram (Op_Name); | |
5972 | Analyze (Decl); | |
5973 | Remove (Decl); | |
5974 | Set_Has_Completion (Op_Name); | |
5975 | Set_Corresponding_Equality (Op_Name, S); | |
f937473f | 5976 | Set_Is_Abstract_Subprogram (Op_Name, Is_Abstract_Subprogram (S)); |
c8ef728f | 5977 | end; |
996ae0b0 RK |
5978 | end Make_Inequality_Operator; |
5979 | ||
5980 | ---------------------- | |
5981 | -- May_Need_Actuals -- | |
5982 | ---------------------- | |
5983 | ||
5984 | procedure May_Need_Actuals (Fun : Entity_Id) is | |
5985 | F : Entity_Id; | |
5986 | B : Boolean; | |
5987 | ||
5988 | begin | |
5989 | F := First_Formal (Fun); | |
5990 | B := True; | |
996ae0b0 RK |
5991 | while Present (F) loop |
5992 | if No (Default_Value (F)) then | |
5993 | B := False; | |
5994 | exit; | |
5995 | end if; | |
5996 | ||
5997 | Next_Formal (F); | |
5998 | end loop; | |
5999 | ||
6000 | Set_Needs_No_Actuals (Fun, B); | |
6001 | end May_Need_Actuals; | |
6002 | ||
6003 | --------------------- | |
6004 | -- Mode_Conformant -- | |
6005 | --------------------- | |
6006 | ||
6007 | function Mode_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is | |
6008 | Result : Boolean; | |
996ae0b0 RK |
6009 | begin |
6010 | Check_Conformance (New_Id, Old_Id, Mode_Conformant, False, Result); | |
6011 | return Result; | |
6012 | end Mode_Conformant; | |
6013 | ||
6014 | --------------------------- | |
6015 | -- New_Overloaded_Entity -- | |
6016 | --------------------------- | |
6017 | ||
6018 | procedure New_Overloaded_Entity | |
6019 | (S : Entity_Id; | |
6020 | Derived_Type : Entity_Id := Empty) | |
6021 | is | |
ec4867fa | 6022 | Overridden_Subp : Entity_Id := Empty; |
758c442c GD |
6023 | -- Set if the current scope has an operation that is type-conformant |
6024 | -- with S, and becomes hidden by S. | |
6025 | ||
5d37ba92 ES |
6026 | Is_Primitive_Subp : Boolean; |
6027 | -- Set to True if the new subprogram is primitive | |
6028 | ||
fbf5a39b AC |
6029 | E : Entity_Id; |
6030 | -- Entity that S overrides | |
6031 | ||
996ae0b0 | 6032 | Prev_Vis : Entity_Id := Empty; |
ec4867fa ES |
6033 | -- Predecessor of E in Homonym chain |
6034 | ||
5d37ba92 ES |
6035 | procedure Check_For_Primitive_Subprogram |
6036 | (Is_Primitive : out Boolean; | |
6037 | Is_Overriding : Boolean := False); | |
6038 | -- If the subprogram being analyzed is a primitive operation of the type | |
6039 | -- of a formal or result, set the Has_Primitive_Operations flag on the | |
6040 | -- type, and set Is_Primitive to True (otherwise set to False). Set the | |
6041 | -- corresponding flag on the entity itself for later use. | |
6042 | ||
ec4867fa ES |
6043 | procedure Check_Synchronized_Overriding |
6044 | (Def_Id : Entity_Id; | |
6045 | First_Hom : Entity_Id; | |
6046 | Overridden_Subp : out Entity_Id); | |
6047 | -- First determine if Def_Id is an entry or a subprogram either defined | |
6048 | -- in the scope of a task or protected type, or is a primitive of such | |
6049 | -- a type. Check whether Def_Id overrides a subprogram of an interface | |
6050 | -- implemented by the synchronized type, return the overridden entity | |
6051 | -- or Empty. | |
758c442c | 6052 | |
996ae0b0 RK |
6053 | function Is_Private_Declaration (E : Entity_Id) return Boolean; |
6054 | -- Check that E is declared in the private part of the current package, | |
6055 | -- or in the package body, where it may hide a previous declaration. | |
fbf5a39b | 6056 | -- We can't use In_Private_Part by itself because this flag is also |
996ae0b0 RK |
6057 | -- set when freezing entities, so we must examine the place of the |
6058 | -- declaration in the tree, and recognize wrapper packages as well. | |
6059 | ||
5d37ba92 ES |
6060 | ------------------------------------ |
6061 | -- Check_For_Primitive_Subprogram -- | |
6062 | ------------------------------------ | |
996ae0b0 | 6063 | |
5d37ba92 ES |
6064 | procedure Check_For_Primitive_Subprogram |
6065 | (Is_Primitive : out Boolean; | |
6066 | Is_Overriding : Boolean := False) | |
ec4867fa | 6067 | is |
996ae0b0 RK |
6068 | Formal : Entity_Id; |
6069 | F_Typ : Entity_Id; | |
07fc65c4 | 6070 | B_Typ : Entity_Id; |
996ae0b0 RK |
6071 | |
6072 | function Visible_Part_Type (T : Entity_Id) return Boolean; | |
6073 | -- Returns true if T is declared in the visible part of | |
6074 | -- the current package scope; otherwise returns false. | |
6075 | -- Assumes that T is declared in a package. | |
6076 | ||
6077 | procedure Check_Private_Overriding (T : Entity_Id); | |
6078 | -- Checks that if a primitive abstract subprogram of a visible | |
6079 | -- abstract type is declared in a private part, then it must | |
6080 | -- override an abstract subprogram declared in the visible part. | |
6081 | -- Also checks that if a primitive function with a controlling | |
6082 | -- result is declared in a private part, then it must override | |
6083 | -- a function declared in the visible part. | |
6084 | ||
6085 | ------------------------------ | |
6086 | -- Check_Private_Overriding -- | |
6087 | ------------------------------ | |
6088 | ||
6089 | procedure Check_Private_Overriding (T : Entity_Id) is | |
6090 | begin | |
6091 | if Ekind (Current_Scope) = E_Package | |
6092 | and then In_Private_Part (Current_Scope) | |
6093 | and then Visible_Part_Type (T) | |
6094 | and then not In_Instance | |
6095 | then | |
f937473f RD |
6096 | if Is_Abstract_Type (T) |
6097 | and then Is_Abstract_Subprogram (S) | |
6098 | and then (not Is_Overriding | |
6099 | or else not Is_Abstract_Subprogram (E)) | |
996ae0b0 | 6100 | then |
f937473f | 6101 | Error_Msg_N ("abstract subprograms must be visible " |
5d37ba92 | 6102 | & "(RM 3.9.3(10))!", S); |
758c442c | 6103 | |
996ae0b0 RK |
6104 | elsif Ekind (S) = E_Function |
6105 | and then Is_Tagged_Type (T) | |
6106 | and then T = Base_Type (Etype (S)) | |
82c80734 | 6107 | and then not Is_Overriding |
996ae0b0 RK |
6108 | then |
6109 | Error_Msg_N | |
6110 | ("private function with tagged result must" | |
6111 | & " override visible-part function", S); | |
6112 | Error_Msg_N | |
6113 | ("\move subprogram to the visible part" | |
5d37ba92 | 6114 | & " (RM 3.9.3(10))", S); |
996ae0b0 RK |
6115 | end if; |
6116 | end if; | |
6117 | end Check_Private_Overriding; | |
6118 | ||
6119 | ----------------------- | |
6120 | -- Visible_Part_Type -- | |
6121 | ----------------------- | |
6122 | ||
6123 | function Visible_Part_Type (T : Entity_Id) return Boolean is | |
07fc65c4 GB |
6124 | P : constant Node_Id := Unit_Declaration_Node (Scope (T)); |
6125 | N : Node_Id; | |
996ae0b0 RK |
6126 | |
6127 | begin | |
6128 | -- If the entity is a private type, then it must be | |
6129 | -- declared in a visible part. | |
6130 | ||
6131 | if Ekind (T) in Private_Kind then | |
6132 | return True; | |
6133 | end if; | |
6134 | ||
6135 | -- Otherwise, we traverse the visible part looking for its | |
6136 | -- corresponding declaration. We cannot use the declaration | |
6137 | -- node directly because in the private part the entity of a | |
6138 | -- private type is the one in the full view, which does not | |
6139 | -- indicate that it is the completion of something visible. | |
6140 | ||
07fc65c4 | 6141 | N := First (Visible_Declarations (Specification (P))); |
996ae0b0 RK |
6142 | while Present (N) loop |
6143 | if Nkind (N) = N_Full_Type_Declaration | |
6144 | and then Present (Defining_Identifier (N)) | |
6145 | and then T = Defining_Identifier (N) | |
6146 | then | |
6147 | return True; | |
6148 | ||
800621e0 RD |
6149 | elsif Nkind_In (N, N_Private_Type_Declaration, |
6150 | N_Private_Extension_Declaration) | |
996ae0b0 RK |
6151 | and then Present (Defining_Identifier (N)) |
6152 | and then T = Full_View (Defining_Identifier (N)) | |
6153 | then | |
6154 | return True; | |
6155 | end if; | |
6156 | ||
6157 | Next (N); | |
6158 | end loop; | |
6159 | ||
6160 | return False; | |
6161 | end Visible_Part_Type; | |
6162 | ||
5d37ba92 | 6163 | -- Start of processing for Check_For_Primitive_Subprogram |
996ae0b0 RK |
6164 | |
6165 | begin | |
5d37ba92 ES |
6166 | Is_Primitive := False; |
6167 | ||
996ae0b0 RK |
6168 | if not Comes_From_Source (S) then |
6169 | null; | |
6170 | ||
5d37ba92 | 6171 | -- If subprogram is at library level, it is not primitive operation |
15ce9ca2 AC |
6172 | |
6173 | elsif Current_Scope = Standard_Standard then | |
6174 | null; | |
6175 | ||
5d37ba92 ES |
6176 | elsif ((Ekind (Current_Scope) = E_Package |
6177 | or else Ekind (Current_Scope) = E_Generic_Package) | |
996ae0b0 | 6178 | and then not In_Package_Body (Current_Scope)) |
82c80734 | 6179 | or else Is_Overriding |
996ae0b0 | 6180 | then |
07fc65c4 | 6181 | -- For function, check return type |
996ae0b0 | 6182 | |
07fc65c4 | 6183 | if Ekind (S) = E_Function then |
5d37ba92 ES |
6184 | if Ekind (Etype (S)) = E_Anonymous_Access_Type then |
6185 | F_Typ := Designated_Type (Etype (S)); | |
6186 | else | |
6187 | F_Typ := Etype (S); | |
6188 | end if; | |
6189 | ||
6190 | B_Typ := Base_Type (F_Typ); | |
07fc65c4 | 6191 | |
5d37ba92 ES |
6192 | if Scope (B_Typ) = Current_Scope |
6193 | and then not Is_Class_Wide_Type (B_Typ) | |
6194 | and then not Is_Generic_Type (B_Typ) | |
6195 | then | |
6196 | Is_Primitive := True; | |
07fc65c4 | 6197 | Set_Has_Primitive_Operations (B_Typ); |
5d37ba92 | 6198 | Set_Is_Primitive (S); |
07fc65c4 GB |
6199 | Check_Private_Overriding (B_Typ); |
6200 | end if; | |
996ae0b0 RK |
6201 | end if; |
6202 | ||
07fc65c4 | 6203 | -- For all subprograms, check formals |
996ae0b0 | 6204 | |
07fc65c4 | 6205 | Formal := First_Formal (S); |
996ae0b0 RK |
6206 | while Present (Formal) loop |
6207 | if Ekind (Etype (Formal)) = E_Anonymous_Access_Type then | |
6208 | F_Typ := Designated_Type (Etype (Formal)); | |
6209 | else | |
6210 | F_Typ := Etype (Formal); | |
6211 | end if; | |
6212 | ||
07fc65c4 GB |
6213 | B_Typ := Base_Type (F_Typ); |
6214 | ||
ec4867fa ES |
6215 | if Ekind (B_Typ) = E_Access_Subtype then |
6216 | B_Typ := Base_Type (B_Typ); | |
6217 | end if; | |
6218 | ||
5d37ba92 ES |
6219 | if Scope (B_Typ) = Current_Scope |
6220 | and then not Is_Class_Wide_Type (B_Typ) | |
6221 | and then not Is_Generic_Type (B_Typ) | |
6222 | then | |
6223 | Is_Primitive := True; | |
6224 | Set_Is_Primitive (S); | |
07fc65c4 GB |
6225 | Set_Has_Primitive_Operations (B_Typ); |
6226 | Check_Private_Overriding (B_Typ); | |
996ae0b0 RK |
6227 | end if; |
6228 | ||
6229 | Next_Formal (Formal); | |
6230 | end loop; | |
996ae0b0 | 6231 | end if; |
5d37ba92 ES |
6232 | end Check_For_Primitive_Subprogram; |
6233 | ||
6234 | ----------------------------------- | |
6235 | -- Check_Synchronized_Overriding -- | |
6236 | ----------------------------------- | |
6237 | ||
6238 | procedure Check_Synchronized_Overriding | |
6239 | (Def_Id : Entity_Id; | |
6240 | First_Hom : Entity_Id; | |
6241 | Overridden_Subp : out Entity_Id) | |
6242 | is | |
6243 | Formal_Typ : Entity_Id; | |
6244 | Ifaces_List : Elist_Id; | |
6245 | In_Scope : Boolean; | |
6246 | Typ : Entity_Id; | |
6247 | ||
6248 | begin | |
6249 | Overridden_Subp := Empty; | |
6250 | ||
6251 | -- Def_Id must be an entry or a subprogram | |
6252 | ||
6253 | if Ekind (Def_Id) /= E_Entry | |
6254 | and then Ekind (Def_Id) /= E_Function | |
6255 | and then Ekind (Def_Id) /= E_Procedure | |
6256 | then | |
6257 | return; | |
6258 | end if; | |
6259 | ||
6260 | -- Search for the concurrent declaration since it contains the list | |
6261 | -- of all implemented interfaces. In this case, the subprogram is | |
6262 | -- declared within the scope of a protected or a task type. | |
6263 | ||
6264 | if Present (Scope (Def_Id)) | |
6265 | and then Is_Concurrent_Type (Scope (Def_Id)) | |
6266 | and then not Is_Generic_Actual_Type (Scope (Def_Id)) | |
6267 | then | |
6268 | Typ := Scope (Def_Id); | |
6269 | In_Scope := True; | |
6270 | ||
6271 | -- The subprogram may be a primitive of a concurrent type | |
6272 | ||
6273 | elsif Present (First_Formal (Def_Id)) then | |
6274 | Formal_Typ := Etype (First_Formal (Def_Id)); | |
6275 | ||
6276 | if Is_Concurrent_Type (Formal_Typ) | |
6277 | and then not Is_Generic_Actual_Type (Formal_Typ) | |
6278 | then | |
6279 | Typ := Formal_Typ; | |
6280 | In_Scope := False; | |
6281 | ||
6282 | -- This case occurs when the concurrent type is declared within | |
6283 | -- a generic unit. As a result the corresponding record has been | |
6284 | -- built and used as the type of the first formal, we just have | |
6285 | -- to retrieve the corresponding concurrent type. | |
6286 | ||
6287 | elsif Is_Concurrent_Record_Type (Formal_Typ) | |
6288 | and then Present (Corresponding_Concurrent_Type (Formal_Typ)) | |
6289 | then | |
6290 | Typ := Corresponding_Concurrent_Type (Formal_Typ); | |
6291 | In_Scope := False; | |
6292 | ||
6293 | else | |
6294 | return; | |
6295 | end if; | |
6296 | else | |
6297 | return; | |
6298 | end if; | |
6299 | ||
6300 | -- Gather all limited, protected and task interfaces that Typ | |
6301 | -- implements. There is no overriding to check if is an inherited | |
6302 | -- operation in a type derivation on for a generic actual. | |
6303 | ||
6304 | if Nkind (Parent (Typ)) /= N_Full_Type_Declaration | |
800621e0 RD |
6305 | and then |
6306 | not Nkind_In (Parent (Def_Id), N_Subtype_Declaration, | |
6307 | N_Task_Type_Declaration, | |
6308 | N_Protected_Type_Declaration) | |
5d37ba92 ES |
6309 | then |
6310 | Collect_Abstract_Interfaces (Typ, Ifaces_List); | |
6311 | ||
6312 | if not Is_Empty_Elmt_List (Ifaces_List) then | |
6313 | Overridden_Subp := | |
6314 | Find_Overridden_Synchronized_Primitive | |
6315 | (Def_Id, First_Hom, Ifaces_List, In_Scope); | |
6316 | end if; | |
6317 | end if; | |
6318 | end Check_Synchronized_Overriding; | |
6319 | ||
6320 | ---------------------------- | |
6321 | -- Is_Private_Declaration -- | |
6322 | ---------------------------- | |
6323 | ||
6324 | function Is_Private_Declaration (E : Entity_Id) return Boolean is | |
6325 | Priv_Decls : List_Id; | |
6326 | Decl : constant Node_Id := Unit_Declaration_Node (E); | |
6327 | ||
6328 | begin | |
6329 | if Is_Package_Or_Generic_Package (Current_Scope) | |
6330 | and then In_Private_Part (Current_Scope) | |
6331 | then | |
6332 | Priv_Decls := | |
6333 | Private_Declarations ( | |
6334 | Specification (Unit_Declaration_Node (Current_Scope))); | |
6335 | ||
6336 | return In_Package_Body (Current_Scope) | |
6337 | or else | |
6338 | (Is_List_Member (Decl) | |
6339 | and then List_Containing (Decl) = Priv_Decls) | |
6340 | or else (Nkind (Parent (Decl)) = N_Package_Specification | |
6341 | and then not Is_Compilation_Unit ( | |
6342 | Defining_Entity (Parent (Decl))) | |
6343 | and then List_Containing (Parent (Parent (Decl))) | |
6344 | = Priv_Decls); | |
6345 | else | |
6346 | return False; | |
6347 | end if; | |
6348 | end Is_Private_Declaration; | |
996ae0b0 RK |
6349 | |
6350 | -- Start of processing for New_Overloaded_Entity | |
6351 | ||
6352 | begin | |
fbf5a39b AC |
6353 | -- We need to look for an entity that S may override. This must be a |
6354 | -- homonym in the current scope, so we look for the first homonym of | |
6355 | -- S in the current scope as the starting point for the search. | |
6356 | ||
6357 | E := Current_Entity_In_Scope (S); | |
6358 | ||
6359 | -- If there is no homonym then this is definitely not overriding | |
6360 | ||
996ae0b0 RK |
6361 | if No (E) then |
6362 | Enter_Overloaded_Entity (S); | |
6363 | Check_Dispatching_Operation (S, Empty); | |
5d37ba92 | 6364 | Check_For_Primitive_Subprogram (Is_Primitive_Subp); |
996ae0b0 | 6365 | |
ec4867fa ES |
6366 | -- If subprogram has an explicit declaration, check whether it |
6367 | -- has an overriding indicator. | |
758c442c | 6368 | |
ec4867fa ES |
6369 | if Comes_From_Source (S) then |
6370 | Check_Synchronized_Overriding (S, Homonym (S), Overridden_Subp); | |
5d37ba92 ES |
6371 | Check_Overriding_Indicator |
6372 | (S, Overridden_Subp, Is_Primitive => Is_Primitive_Subp); | |
758c442c GD |
6373 | end if; |
6374 | ||
fbf5a39b AC |
6375 | -- If there is a homonym that is not overloadable, then we have an |
6376 | -- error, except for the special cases checked explicitly below. | |
6377 | ||
996ae0b0 RK |
6378 | elsif not Is_Overloadable (E) then |
6379 | ||
6380 | -- Check for spurious conflict produced by a subprogram that has the | |
6381 | -- same name as that of the enclosing generic package. The conflict | |
6382 | -- occurs within an instance, between the subprogram and the renaming | |
6383 | -- declaration for the package. After the subprogram, the package | |
6384 | -- renaming declaration becomes hidden. | |
6385 | ||
6386 | if Ekind (E) = E_Package | |
6387 | and then Present (Renamed_Object (E)) | |
6388 | and then Renamed_Object (E) = Current_Scope | |
6389 | and then Nkind (Parent (Renamed_Object (E))) = | |
6390 | N_Package_Specification | |
6391 | and then Present (Generic_Parent (Parent (Renamed_Object (E)))) | |
6392 | then | |
6393 | Set_Is_Hidden (E); | |
6394 | Set_Is_Immediately_Visible (E, False); | |
6395 | Enter_Overloaded_Entity (S); | |
6396 | Set_Homonym (S, Homonym (E)); | |
6397 | Check_Dispatching_Operation (S, Empty); | |
5d37ba92 | 6398 | Check_Overriding_Indicator (S, Empty, Is_Primitive => False); |
996ae0b0 RK |
6399 | |
6400 | -- If the subprogram is implicit it is hidden by the previous | |
82c80734 RD |
6401 | -- declaration. However if it is dispatching, it must appear in the |
6402 | -- dispatch table anyway, because it can be dispatched to even if it | |
6403 | -- cannot be called directly. | |
996ae0b0 RK |
6404 | |
6405 | elsif Present (Alias (S)) | |
6406 | and then not Comes_From_Source (S) | |
6407 | then | |
6408 | Set_Scope (S, Current_Scope); | |
6409 | ||
6410 | if Is_Dispatching_Operation (Alias (S)) then | |
6411 | Check_Dispatching_Operation (S, Empty); | |
6412 | end if; | |
6413 | ||
6414 | return; | |
6415 | ||
6416 | else | |
6417 | Error_Msg_Sloc := Sloc (E); | |
996ae0b0 | 6418 | |
5d37ba92 | 6419 | -- Generate message,with useful additionalwarning if in generic |
996ae0b0 RK |
6420 | |
6421 | if Is_Generic_Unit (E) then | |
5d37ba92 ES |
6422 | Error_Msg_N ("previous generic unit cannot be overloaded", S); |
6423 | Error_Msg_N ("\& conflicts with declaration#", S); | |
6424 | else | |
6425 | Error_Msg_N ("& conflicts with declaration#", S); | |
996ae0b0 RK |
6426 | end if; |
6427 | ||
6428 | return; | |
6429 | end if; | |
6430 | ||
fbf5a39b AC |
6431 | -- E exists and is overloadable |
6432 | ||
996ae0b0 | 6433 | else |
ec4867fa ES |
6434 | -- Ada 2005 (AI-251): Derivation of abstract interface primitives |
6435 | -- need no check against the homonym chain. They are directly added | |
6436 | -- to the list of primitive operations of Derived_Type. | |
6437 | ||
6438 | if Ada_Version >= Ada_05 | |
6439 | and then Present (Derived_Type) | |
6440 | and then Is_Dispatching_Operation (Alias (S)) | |
6441 | and then Present (Find_Dispatching_Type (Alias (S))) | |
6442 | and then Is_Interface (Find_Dispatching_Type (Alias (S))) | |
6443 | and then not Is_Predefined_Dispatching_Operation (Alias (S)) | |
6444 | then | |
6445 | goto Add_New_Entity; | |
6446 | end if; | |
6447 | ||
6448 | Check_Synchronized_Overriding (S, E, Overridden_Subp); | |
758c442c | 6449 | |
82c80734 RD |
6450 | -- Loop through E and its homonyms to determine if any of them is |
6451 | -- the candidate for overriding by S. | |
996ae0b0 RK |
6452 | |
6453 | while Present (E) loop | |
fbf5a39b AC |
6454 | |
6455 | -- Definitely not interesting if not in the current scope | |
6456 | ||
996ae0b0 RK |
6457 | if Scope (E) /= Current_Scope then |
6458 | null; | |
6459 | ||
fbf5a39b AC |
6460 | -- Check if we have type conformance |
6461 | ||
ec4867fa | 6462 | elsif Type_Conformant (E, S) then |
c8ef728f | 6463 | |
82c80734 RD |
6464 | -- If the old and new entities have the same profile and one |
6465 | -- is not the body of the other, then this is an error, unless | |
6466 | -- one of them is implicitly declared. | |
996ae0b0 RK |
6467 | |
6468 | -- There are some cases when both can be implicit, for example | |
6469 | -- when both a literal and a function that overrides it are | |
6470 | -- inherited in a derivation, or when an inhertited operation | |
ec4867fa | 6471 | -- of a tagged full type overrides the inherited operation of |
82c80734 RD |
6472 | -- a private extension. Ada 83 had a special rule for the the |
6473 | -- literal case. In Ada95, the later implicit operation hides | |
6474 | -- the former, and the literal is always the former. In the | |
6475 | -- odd case where both are derived operations declared at the | |
6476 | -- same point, both operations should be declared, and in that | |
6477 | -- case we bypass the following test and proceed to the next | |
6478 | -- part (this can only occur for certain obscure cases | |
6479 | -- involving homographs in instances and can't occur for | |
996ae0b0 | 6480 | -- dispatching operations ???). Note that the following |
82c80734 RD |
6481 | -- condition is less than clear. For example, it's not at all |
6482 | -- clear why there's a test for E_Entry here. ??? | |
996ae0b0 RK |
6483 | |
6484 | if Present (Alias (S)) | |
6485 | and then (No (Alias (E)) | |
6486 | or else Comes_From_Source (E) | |
6487 | or else Is_Dispatching_Operation (E)) | |
6488 | and then | |
6489 | (Ekind (E) = E_Entry | |
6490 | or else Ekind (E) /= E_Enumeration_Literal) | |
6491 | then | |
82c80734 RD |
6492 | -- When an derived operation is overloaded it may be due to |
6493 | -- the fact that the full view of a private extension | |
996ae0b0 RK |
6494 | -- re-inherits. It has to be dealt with. |
6495 | ||
e660dbf7 | 6496 | if Is_Package_Or_Generic_Package (Current_Scope) |
996ae0b0 RK |
6497 | and then In_Private_Part (Current_Scope) |
6498 | then | |
6499 | Check_Operation_From_Private_View (S, E); | |
6500 | end if; | |
6501 | ||
6502 | -- In any case the implicit operation remains hidden by | |
5950a3ac | 6503 | -- the existing declaration, which is overriding. |
996ae0b0 | 6504 | |
5950a3ac | 6505 | Set_Is_Overriding_Operation (E); |
758c442c GD |
6506 | |
6507 | if Comes_From_Source (E) then | |
5d37ba92 | 6508 | Check_Overriding_Indicator (E, S, Is_Primitive => False); |
41251c60 JM |
6509 | |
6510 | -- Indicate that E overrides the operation from which | |
6511 | -- S is inherited. | |
6512 | ||
0a36105d | 6513 | if Present (Alias (S)) then |
41251c60 JM |
6514 | Set_Overridden_Operation (E, Alias (S)); |
6515 | else | |
6516 | Set_Overridden_Operation (E, S); | |
6517 | end if; | |
758c442c GD |
6518 | end if; |
6519 | ||
996ae0b0 RK |
6520 | return; |
6521 | ||
6522 | -- Within an instance, the renaming declarations for | |
6523 | -- actual subprograms may become ambiguous, but they do | |
6524 | -- not hide each other. | |
6525 | ||
6526 | elsif Ekind (E) /= E_Entry | |
6527 | and then not Comes_From_Source (E) | |
6528 | and then not Is_Generic_Instance (E) | |
6529 | and then (Present (Alias (E)) | |
6530 | or else Is_Intrinsic_Subprogram (E)) | |
6531 | and then (not In_Instance | |
6532 | or else No (Parent (E)) | |
6533 | or else Nkind (Unit_Declaration_Node (E)) /= | |
6534 | N_Subprogram_Renaming_Declaration) | |
6535 | then | |
6536 | -- A subprogram child unit is not allowed to override | |
6537 | -- an inherited subprogram (10.1.1(20)). | |
6538 | ||
6539 | if Is_Child_Unit (S) then | |
6540 | Error_Msg_N | |
6541 | ("child unit overrides inherited subprogram in parent", | |
6542 | S); | |
6543 | return; | |
6544 | end if; | |
6545 | ||
6546 | if Is_Non_Overriding_Operation (E, S) then | |
6547 | Enter_Overloaded_Entity (S); | |
c8ef728f | 6548 | if No (Derived_Type) |
996ae0b0 RK |
6549 | or else Is_Tagged_Type (Derived_Type) |
6550 | then | |
6551 | Check_Dispatching_Operation (S, Empty); | |
6552 | end if; | |
6553 | ||
6554 | return; | |
6555 | end if; | |
6556 | ||
6557 | -- E is a derived operation or an internal operator which | |
6558 | -- is being overridden. Remove E from further visibility. | |
6559 | -- Furthermore, if E is a dispatching operation, it must be | |
6560 | -- replaced in the list of primitive operations of its type | |
6561 | -- (see Override_Dispatching_Operation). | |
6562 | ||
ec4867fa | 6563 | Overridden_Subp := E; |
758c442c | 6564 | |
996ae0b0 RK |
6565 | declare |
6566 | Prev : Entity_Id; | |
6567 | ||
6568 | begin | |
6569 | Prev := First_Entity (Current_Scope); | |
6570 | ||
6571 | while Present (Prev) | |
6572 | and then Next_Entity (Prev) /= E | |
6573 | loop | |
6574 | Next_Entity (Prev); | |
6575 | end loop; | |
6576 | ||
6577 | -- It is possible for E to be in the current scope and | |
6578 | -- yet not in the entity chain. This can only occur in a | |
6579 | -- generic context where E is an implicit concatenation | |
6580 | -- in the formal part, because in a generic body the | |
6581 | -- entity chain starts with the formals. | |
6582 | ||
6583 | pragma Assert | |
6584 | (Present (Prev) or else Chars (E) = Name_Op_Concat); | |
6585 | ||
6586 | -- E must be removed both from the entity_list of the | |
6587 | -- current scope, and from the visibility chain | |
6588 | ||
6589 | if Debug_Flag_E then | |
6590 | Write_Str ("Override implicit operation "); | |
6591 | Write_Int (Int (E)); | |
6592 | Write_Eol; | |
6593 | end if; | |
6594 | ||
6595 | -- If E is a predefined concatenation, it stands for four | |
6596 | -- different operations. As a result, a single explicit | |
6597 | -- declaration does not hide it. In a possible ambiguous | |
6598 | -- situation, Disambiguate chooses the user-defined op, | |
6599 | -- so it is correct to retain the previous internal one. | |
6600 | ||
6601 | if Chars (E) /= Name_Op_Concat | |
6602 | or else Ekind (E) /= E_Operator | |
6603 | then | |
6604 | -- For nondispatching derived operations that are | |
6605 | -- overridden by a subprogram declared in the private | |
82c80734 RD |
6606 | -- part of a package, we retain the derived |
6607 | -- subprogram but mark it as not immediately visible. | |
6608 | -- If the derived operation was declared in the | |
6609 | -- visible part then this ensures that it will still | |
6610 | -- be visible outside the package with the proper | |
6611 | -- signature (calls from outside must also be | |
6612 | -- directed to this version rather than the | |
6613 | -- overriding one, unlike the dispatching case). | |
6614 | -- Calls from inside the package will still resolve | |
6615 | -- to the overriding subprogram since the derived one | |
6616 | -- is marked as not visible within the package. | |
996ae0b0 RK |
6617 | |
6618 | -- If the private operation is dispatching, we achieve | |
6619 | -- the overriding by keeping the implicit operation | |
9865d858 | 6620 | -- but setting its alias to be the overriding one. In |
996ae0b0 RK |
6621 | -- this fashion the proper body is executed in all |
6622 | -- cases, but the original signature is used outside | |
6623 | -- of the package. | |
6624 | ||
6625 | -- If the overriding is not in the private part, we | |
6626 | -- remove the implicit operation altogether. | |
6627 | ||
6628 | if Is_Private_Declaration (S) then | |
6629 | ||
6630 | if not Is_Dispatching_Operation (E) then | |
6631 | Set_Is_Immediately_Visible (E, False); | |
6632 | else | |
e895b435 ES |
6633 | -- Work done in Override_Dispatching_Operation, |
6634 | -- so nothing else need to be done here. | |
996ae0b0 RK |
6635 | |
6636 | null; | |
6637 | end if; | |
996ae0b0 | 6638 | |
fbf5a39b AC |
6639 | else |
6640 | -- Find predecessor of E in Homonym chain | |
996ae0b0 RK |
6641 | |
6642 | if E = Current_Entity (E) then | |
6643 | Prev_Vis := Empty; | |
6644 | else | |
6645 | Prev_Vis := Current_Entity (E); | |
6646 | while Homonym (Prev_Vis) /= E loop | |
6647 | Prev_Vis := Homonym (Prev_Vis); | |
6648 | end loop; | |
6649 | end if; | |
6650 | ||
6651 | if Prev_Vis /= Empty then | |
6652 | ||
6653 | -- Skip E in the visibility chain | |
6654 | ||
6655 | Set_Homonym (Prev_Vis, Homonym (E)); | |
6656 | ||
6657 | else | |
6658 | Set_Name_Entity_Id (Chars (E), Homonym (E)); | |
6659 | end if; | |
6660 | ||
6661 | Set_Next_Entity (Prev, Next_Entity (E)); | |
6662 | ||
6663 | if No (Next_Entity (Prev)) then | |
6664 | Set_Last_Entity (Current_Scope, Prev); | |
6665 | end if; | |
6666 | ||
6667 | end if; | |
6668 | end if; | |
6669 | ||
6670 | Enter_Overloaded_Entity (S); | |
fbf5a39b | 6671 | Set_Is_Overriding_Operation (S); |
5d37ba92 | 6672 | Check_Overriding_Indicator (S, E, Is_Primitive => True); |
996ae0b0 | 6673 | |
41251c60 JM |
6674 | -- Indicate that S overrides the operation from which |
6675 | -- E is inherited. | |
6676 | ||
6677 | if Comes_From_Source (S) then | |
c8ef728f | 6678 | if Present (Alias (E)) then |
41251c60 JM |
6679 | Set_Overridden_Operation (S, Alias (E)); |
6680 | else | |
6681 | Set_Overridden_Operation (S, E); | |
6682 | end if; | |
6683 | end if; | |
6684 | ||
996ae0b0 | 6685 | if Is_Dispatching_Operation (E) then |
fbf5a39b | 6686 | |
82c80734 RD |
6687 | -- An overriding dispatching subprogram inherits the |
6688 | -- convention of the overridden subprogram (by | |
6689 | -- AI-117). | |
996ae0b0 RK |
6690 | |
6691 | Set_Convention (S, Convention (E)); | |
41251c60 JM |
6692 | Check_Dispatching_Operation (S, E); |
6693 | ||
996ae0b0 RK |
6694 | else |
6695 | Check_Dispatching_Operation (S, Empty); | |
6696 | end if; | |
6697 | ||
5d37ba92 ES |
6698 | Check_For_Primitive_Subprogram |
6699 | (Is_Primitive_Subp, Is_Overriding => True); | |
996ae0b0 RK |
6700 | goto Check_Inequality; |
6701 | end; | |
6702 | ||
6703 | -- Apparent redeclarations in instances can occur when two | |
6704 | -- formal types get the same actual type. The subprograms in | |
6705 | -- in the instance are legal, even if not callable from the | |
6706 | -- outside. Calls from within are disambiguated elsewhere. | |
6707 | -- For dispatching operations in the visible part, the usual | |
6708 | -- rules apply, and operations with the same profile are not | |
6709 | -- legal (B830001). | |
6710 | ||
6711 | elsif (In_Instance_Visible_Part | |
6712 | and then not Is_Dispatching_Operation (E)) | |
6713 | or else In_Instance_Not_Visible | |
6714 | then | |
6715 | null; | |
6716 | ||
6717 | -- Here we have a real error (identical profile) | |
6718 | ||
6719 | else | |
6720 | Error_Msg_Sloc := Sloc (E); | |
6721 | ||
6722 | -- Avoid cascaded errors if the entity appears in | |
6723 | -- subsequent calls. | |
6724 | ||
6725 | Set_Scope (S, Current_Scope); | |
6726 | ||
5d37ba92 ES |
6727 | -- Generate error, with extra useful warning for the case |
6728 | -- of a generic instance with no completion. | |
996ae0b0 RK |
6729 | |
6730 | if Is_Generic_Instance (S) | |
6731 | and then not Has_Completion (E) | |
6732 | then | |
6733 | Error_Msg_N | |
5d37ba92 ES |
6734 | ("instantiation cannot provide body for&", S); |
6735 | Error_Msg_N ("\& conflicts with declaration#", S); | |
6736 | else | |
6737 | Error_Msg_N ("& conflicts with declaration#", S); | |
996ae0b0 RK |
6738 | end if; |
6739 | ||
6740 | return; | |
6741 | end if; | |
6742 | ||
6743 | else | |
c8ef728f ES |
6744 | -- If one subprogram has an access parameter and the other |
6745 | -- a parameter of an access type, calls to either might be | |
6746 | -- ambiguous. Verify that parameters match except for the | |
6747 | -- access parameter. | |
6748 | ||
6749 | if May_Hide_Profile then | |
6750 | declare | |
ec4867fa ES |
6751 | F1 : Entity_Id; |
6752 | F2 : Entity_Id; | |
c8ef728f ES |
6753 | begin |
6754 | F1 := First_Formal (S); | |
6755 | F2 := First_Formal (E); | |
6756 | while Present (F1) and then Present (F2) loop | |
6757 | if Is_Access_Type (Etype (F1)) then | |
6758 | if not Is_Access_Type (Etype (F2)) | |
6759 | or else not Conforming_Types | |
6760 | (Designated_Type (Etype (F1)), | |
6761 | Designated_Type (Etype (F2)), | |
6762 | Type_Conformant) | |
6763 | then | |
6764 | May_Hide_Profile := False; | |
6765 | end if; | |
6766 | ||
6767 | elsif | |
6768 | not Conforming_Types | |
6769 | (Etype (F1), Etype (F2), Type_Conformant) | |
6770 | then | |
6771 | May_Hide_Profile := False; | |
6772 | end if; | |
6773 | ||
6774 | Next_Formal (F1); | |
6775 | Next_Formal (F2); | |
6776 | end loop; | |
6777 | ||
6778 | if May_Hide_Profile | |
6779 | and then No (F1) | |
6780 | and then No (F2) | |
6781 | then | |
6782 | Error_Msg_NE ("calls to& may be ambiguous?", S, S); | |
6783 | end if; | |
6784 | end; | |
6785 | end if; | |
996ae0b0 RK |
6786 | end if; |
6787 | ||
996ae0b0 RK |
6788 | E := Homonym (E); |
6789 | end loop; | |
6790 | ||
ec4867fa ES |
6791 | <<Add_New_Entity>> |
6792 | ||
996ae0b0 RK |
6793 | -- On exit, we know that S is a new entity |
6794 | ||
6795 | Enter_Overloaded_Entity (S); | |
5d37ba92 ES |
6796 | Check_For_Primitive_Subprogram (Is_Primitive_Subp); |
6797 | Check_Overriding_Indicator | |
6798 | (S, Overridden_Subp, Is_Primitive => Is_Primitive_Subp); | |
996ae0b0 | 6799 | |
82c80734 RD |
6800 | -- If S is a derived operation for an untagged type then by |
6801 | -- definition it's not a dispatching operation (even if the parent | |
6802 | -- operation was dispatching), so we don't call | |
6803 | -- Check_Dispatching_Operation in that case. | |
996ae0b0 | 6804 | |
c8ef728f | 6805 | if No (Derived_Type) |
996ae0b0 RK |
6806 | or else Is_Tagged_Type (Derived_Type) |
6807 | then | |
6808 | Check_Dispatching_Operation (S, Empty); | |
6809 | end if; | |
6810 | end if; | |
6811 | ||
82c80734 RD |
6812 | -- If this is a user-defined equality operator that is not a derived |
6813 | -- subprogram, create the corresponding inequality. If the operation is | |
6814 | -- dispatching, the expansion is done elsewhere, and we do not create | |
6815 | -- an explicit inequality operation. | |
996ae0b0 RK |
6816 | |
6817 | <<Check_Inequality>> | |
6818 | if Chars (S) = Name_Op_Eq | |
6819 | and then Etype (S) = Standard_Boolean | |
6820 | and then Present (Parent (S)) | |
6821 | and then not Is_Dispatching_Operation (S) | |
6822 | then | |
6823 | Make_Inequality_Operator (S); | |
6824 | end if; | |
996ae0b0 RK |
6825 | end New_Overloaded_Entity; |
6826 | ||
6827 | --------------------- | |
6828 | -- Process_Formals -- | |
6829 | --------------------- | |
6830 | ||
6831 | procedure Process_Formals | |
07fc65c4 | 6832 | (T : List_Id; |
996ae0b0 RK |
6833 | Related_Nod : Node_Id) |
6834 | is | |
6835 | Param_Spec : Node_Id; | |
6836 | Formal : Entity_Id; | |
6837 | Formal_Type : Entity_Id; | |
6838 | Default : Node_Id; | |
6839 | Ptype : Entity_Id; | |
6840 | ||
800621e0 RD |
6841 | -- The following are used for setting Is_Only_Out_ |
6842 | Num_Out_Params : Nat := 0; | |
6843 | First_Out_Param : Entity_Id := Empty; | |
6844 | ||
07fc65c4 | 6845 | function Is_Class_Wide_Default (D : Node_Id) return Boolean; |
82c80734 RD |
6846 | -- Check whether the default has a class-wide type. After analysis the |
6847 | -- default has the type of the formal, so we must also check explicitly | |
6848 | -- for an access attribute. | |
07fc65c4 GB |
6849 | |
6850 | --------------------------- | |
6851 | -- Is_Class_Wide_Default -- | |
6852 | --------------------------- | |
6853 | ||
6854 | function Is_Class_Wide_Default (D : Node_Id) return Boolean is | |
6855 | begin | |
6856 | return Is_Class_Wide_Type (Designated_Type (Etype (D))) | |
6857 | or else (Nkind (D) = N_Attribute_Reference | |
6858 | and then Attribute_Name (D) = Name_Access | |
6859 | and then Is_Class_Wide_Type (Etype (Prefix (D)))); | |
6860 | end Is_Class_Wide_Default; | |
6861 | ||
6862 | -- Start of processing for Process_Formals | |
6863 | ||
996ae0b0 RK |
6864 | begin |
6865 | -- In order to prevent premature use of the formals in the same formal | |
6866 | -- part, the Ekind is left undefined until all default expressions are | |
6867 | -- analyzed. The Ekind is established in a separate loop at the end. | |
6868 | ||
6869 | Param_Spec := First (T); | |
996ae0b0 | 6870 | while Present (Param_Spec) loop |
996ae0b0 | 6871 | Formal := Defining_Identifier (Param_Spec); |
5d37ba92 | 6872 | Set_Never_Set_In_Source (Formal, True); |
996ae0b0 RK |
6873 | Enter_Name (Formal); |
6874 | ||
6875 | -- Case of ordinary parameters | |
6876 | ||
6877 | if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then | |
6878 | Find_Type (Parameter_Type (Param_Spec)); | |
6879 | Ptype := Parameter_Type (Param_Spec); | |
6880 | ||
6881 | if Ptype = Error then | |
6882 | goto Continue; | |
6883 | end if; | |
6884 | ||
6885 | Formal_Type := Entity (Ptype); | |
6886 | ||
ec4867fa ES |
6887 | if Is_Incomplete_Type (Formal_Type) |
6888 | or else | |
6889 | (Is_Class_Wide_Type (Formal_Type) | |
6890 | and then Is_Incomplete_Type (Root_Type (Formal_Type))) | |
996ae0b0 | 6891 | then |
d8db0bca | 6892 | -- Ada 2005 (AI-326): Tagged incomplete types allowed |
fbf5a39b | 6893 | |
d8db0bca | 6894 | if Is_Tagged_Type (Formal_Type) then |
fbf5a39b AC |
6895 | null; |
6896 | ||
0a36105d JM |
6897 | -- Special handling of Value_Type for CIL case |
6898 | ||
6899 | elsif Is_Value_Type (Formal_Type) then | |
6900 | null; | |
6901 | ||
800621e0 RD |
6902 | elsif not Nkind_In (Parent (T), N_Access_Function_Definition, |
6903 | N_Access_Procedure_Definition) | |
996ae0b0 RK |
6904 | then |
6905 | Error_Msg_N ("invalid use of incomplete type", Param_Spec); | |
0a36105d JM |
6906 | |
6907 | -- An incomplete type that is not tagged is allowed in an | |
6908 | -- access-to-subprogram type only if it is a local declaration | |
6909 | -- with a forthcoming completion (3.10.1 (9.2/2)). | |
6910 | ||
6911 | elsif Scope (Formal_Type) /= Scope (Current_Scope) then | |
6912 | Error_Msg_N | |
6913 | ("invalid use of limited view of type", Param_Spec); | |
996ae0b0 RK |
6914 | end if; |
6915 | ||
6916 | elsif Ekind (Formal_Type) = E_Void then | |
6917 | Error_Msg_NE ("premature use of&", | |
6918 | Parameter_Type (Param_Spec), Formal_Type); | |
6919 | end if; | |
6920 | ||
0ab80019 | 6921 | -- Ada 2005 (AI-231): Create and decorate an internal subtype |
7324bf49 | 6922 | -- declaration corresponding to the null-excluding type of the |
d8db0bca JM |
6923 | -- formal in the enclosing scope. Finally, replace the parameter |
6924 | -- type of the formal with the internal subtype. | |
7324bf49 | 6925 | |
41251c60 | 6926 | if Ada_Version >= Ada_05 |
41251c60 | 6927 | and then Null_Exclusion_Present (Param_Spec) |
7324bf49 | 6928 | then |
ec4867fa | 6929 | if not Is_Access_Type (Formal_Type) then |
0a36105d JM |
6930 | Error_Msg_N |
6931 | ("`NOT NULL` allowed only for an access type", Param_Spec); | |
6932 | ||
ec4867fa ES |
6933 | else |
6934 | if Can_Never_Be_Null (Formal_Type) | |
6935 | and then Comes_From_Source (Related_Nod) | |
6936 | then | |
0a36105d JM |
6937 | Error_Msg_NE |
6938 | ("`NOT NULL` not allowed (& already excludes null)", | |
6939 | Param_Spec, | |
6940 | Formal_Type); | |
ec4867fa | 6941 | end if; |
41251c60 | 6942 | |
ec4867fa ES |
6943 | Formal_Type := |
6944 | Create_Null_Excluding_Itype | |
6945 | (T => Formal_Type, | |
6946 | Related_Nod => Related_Nod, | |
6947 | Scope_Id => Scope (Current_Scope)); | |
0a36105d JM |
6948 | |
6949 | -- If the designated type of the itype is an itype we | |
6950 | -- decorate it with the Has_Delayed_Freeze attribute to | |
6951 | -- avoid problems with the backend. | |
6952 | ||
6953 | -- Example: | |
6954 | -- type T is access procedure; | |
6955 | -- procedure Op (O : not null T); | |
6956 | ||
6957 | if Is_Itype (Directly_Designated_Type (Formal_Type)) then | |
6958 | Set_Has_Delayed_Freeze (Formal_Type); | |
6959 | end if; | |
ec4867fa | 6960 | end if; |
7324bf49 AC |
6961 | end if; |
6962 | ||
996ae0b0 RK |
6963 | -- An access formal type |
6964 | ||
6965 | else | |
6966 | Formal_Type := | |
6967 | Access_Definition (Related_Nod, Parameter_Type (Param_Spec)); | |
7324bf49 | 6968 | |
f937473f RD |
6969 | -- No need to continue if we already notified errors |
6970 | ||
6971 | if not Present (Formal_Type) then | |
6972 | return; | |
6973 | end if; | |
6974 | ||
0ab80019 | 6975 | -- Ada 2005 (AI-254) |
7324bf49 | 6976 | |
af4b9434 AC |
6977 | declare |
6978 | AD : constant Node_Id := | |
6979 | Access_To_Subprogram_Definition | |
6980 | (Parameter_Type (Param_Spec)); | |
6981 | begin | |
6982 | if Present (AD) and then Protected_Present (AD) then | |
6983 | Formal_Type := | |
6984 | Replace_Anonymous_Access_To_Protected_Subprogram | |
f937473f | 6985 | (Param_Spec); |
af4b9434 AC |
6986 | end if; |
6987 | end; | |
996ae0b0 RK |
6988 | end if; |
6989 | ||
6990 | Set_Etype (Formal, Formal_Type); | |
fbf5a39b | 6991 | Default := Expression (Param_Spec); |
996ae0b0 RK |
6992 | |
6993 | if Present (Default) then | |
6994 | if Out_Present (Param_Spec) then | |
6995 | Error_Msg_N | |
6996 | ("default initialization only allowed for IN parameters", | |
6997 | Param_Spec); | |
6998 | end if; | |
6999 | ||
7000 | -- Do the special preanalysis of the expression (see section on | |
7001 | -- "Handling of Default Expressions" in the spec of package Sem). | |
7002 | ||
fbf5a39b | 7003 | Analyze_Per_Use_Expression (Default, Formal_Type); |
996ae0b0 | 7004 | |
f29b857f ES |
7005 | -- An access to constant cannot be the default for |
7006 | -- an access parameter that is an access to variable. | |
2eb160f2 ST |
7007 | |
7008 | if Ekind (Formal_Type) = E_Anonymous_Access_Type | |
7009 | and then not Is_Access_Constant (Formal_Type) | |
7010 | and then Is_Access_Type (Etype (Default)) | |
7011 | and then Is_Access_Constant (Etype (Default)) | |
7012 | then | |
f29b857f ES |
7013 | Error_Msg_N |
7014 | ("formal that is access to variable cannot be initialized " & | |
7015 | "with an access-to-constant expression", Default); | |
2eb160f2 ST |
7016 | end if; |
7017 | ||
d8db0bca JM |
7018 | -- Check that the designated type of an access parameter's default |
7019 | -- is not a class-wide type unless the parameter's designated type | |
7020 | -- is also class-wide. | |
996ae0b0 RK |
7021 | |
7022 | if Ekind (Formal_Type) = E_Anonymous_Access_Type | |
d8db0bca | 7023 | and then not From_With_Type (Formal_Type) |
07fc65c4 | 7024 | and then Is_Class_Wide_Default (Default) |
996ae0b0 RK |
7025 | and then not Is_Class_Wide_Type (Designated_Type (Formal_Type)) |
7026 | then | |
07fc65c4 GB |
7027 | Error_Msg_N |
7028 | ("access to class-wide expression not allowed here", Default); | |
996ae0b0 RK |
7029 | end if; |
7030 | end if; | |
7031 | ||
41251c60 JM |
7032 | -- Ada 2005 (AI-231): Static checks |
7033 | ||
7034 | if Ada_Version >= Ada_05 | |
7035 | and then Is_Access_Type (Etype (Formal)) | |
7036 | and then Can_Never_Be_Null (Etype (Formal)) | |
7037 | then | |
7038 | Null_Exclusion_Static_Checks (Param_Spec); | |
7039 | end if; | |
7040 | ||
996ae0b0 RK |
7041 | <<Continue>> |
7042 | Next (Param_Spec); | |
7043 | end loop; | |
7044 | ||
82c80734 RD |
7045 | -- If this is the formal part of a function specification, analyze the |
7046 | -- subtype mark in the context where the formals are visible but not | |
7047 | -- yet usable, and may hide outer homographs. | |
7048 | ||
7049 | if Nkind (Related_Nod) = N_Function_Specification then | |
7050 | Analyze_Return_Type (Related_Nod); | |
7051 | end if; | |
7052 | ||
996ae0b0 RK |
7053 | -- Now set the kind (mode) of each formal |
7054 | ||
7055 | Param_Spec := First (T); | |
7056 | ||
7057 | while Present (Param_Spec) loop | |
7058 | Formal := Defining_Identifier (Param_Spec); | |
7059 | Set_Formal_Mode (Formal); | |
7060 | ||
7061 | if Ekind (Formal) = E_In_Parameter then | |
7062 | Set_Default_Value (Formal, Expression (Param_Spec)); | |
7063 | ||
7064 | if Present (Expression (Param_Spec)) then | |
7065 | Default := Expression (Param_Spec); | |
7066 | ||
7067 | if Is_Scalar_Type (Etype (Default)) then | |
7068 | if Nkind | |
7069 | (Parameter_Type (Param_Spec)) /= N_Access_Definition | |
7070 | then | |
7071 | Formal_Type := Entity (Parameter_Type (Param_Spec)); | |
7072 | ||
7073 | else | |
7074 | Formal_Type := Access_Definition | |
7075 | (Related_Nod, Parameter_Type (Param_Spec)); | |
7076 | end if; | |
7077 | ||
7078 | Apply_Scalar_Range_Check (Default, Formal_Type); | |
7079 | end if; | |
2820d220 | 7080 | end if; |
800621e0 RD |
7081 | |
7082 | elsif Ekind (Formal) = E_Out_Parameter then | |
7083 | Num_Out_Params := Num_Out_Params + 1; | |
7084 | ||
7085 | if Num_Out_Params = 1 then | |
7086 | First_Out_Param := Formal; | |
7087 | end if; | |
7088 | ||
7089 | elsif Ekind (Formal) = E_In_Out_Parameter then | |
7090 | Num_Out_Params := Num_Out_Params + 1; | |
996ae0b0 RK |
7091 | end if; |
7092 | ||
7093 | Next (Param_Spec); | |
7094 | end loop; | |
800621e0 RD |
7095 | |
7096 | if Present (First_Out_Param) and then Num_Out_Params = 1 then | |
7097 | Set_Is_Only_Out_Parameter (First_Out_Param); | |
7098 | end if; | |
996ae0b0 RK |
7099 | end Process_Formals; |
7100 | ||
fbf5a39b AC |
7101 | ---------------------------- |
7102 | -- Reference_Body_Formals -- | |
7103 | ---------------------------- | |
7104 | ||
7105 | procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id) is | |
7106 | Fs : Entity_Id; | |
7107 | Fb : Entity_Id; | |
7108 | ||
7109 | begin | |
7110 | if Error_Posted (Spec) then | |
7111 | return; | |
7112 | end if; | |
7113 | ||
0a36105d JM |
7114 | -- Iterate over both lists. They may be of different lengths if the two |
7115 | -- specs are not conformant. | |
7116 | ||
fbf5a39b AC |
7117 | Fs := First_Formal (Spec); |
7118 | Fb := First_Formal (Bod); | |
0a36105d | 7119 | while Present (Fs) and then Present (Fb) loop |
fbf5a39b AC |
7120 | Generate_Reference (Fs, Fb, 'b'); |
7121 | ||
7122 | if Style_Check then | |
7123 | Style.Check_Identifier (Fb, Fs); | |
7124 | end if; | |
7125 | ||
7126 | Set_Spec_Entity (Fb, Fs); | |
7127 | Set_Referenced (Fs, False); | |
7128 | Next_Formal (Fs); | |
7129 | Next_Formal (Fb); | |
7130 | end loop; | |
7131 | end Reference_Body_Formals; | |
7132 | ||
996ae0b0 RK |
7133 | ------------------------- |
7134 | -- Set_Actual_Subtypes -- | |
7135 | ------------------------- | |
7136 | ||
7137 | procedure Set_Actual_Subtypes (N : Node_Id; Subp : Entity_Id) is | |
2820d220 AC |
7138 | Loc : constant Source_Ptr := Sloc (N); |
7139 | Decl : Node_Id; | |
7140 | Formal : Entity_Id; | |
7141 | T : Entity_Id; | |
7142 | First_Stmt : Node_Id := Empty; | |
7143 | AS_Needed : Boolean; | |
996ae0b0 RK |
7144 | |
7145 | begin | |
fbf5a39b AC |
7146 | -- If this is an emtpy initialization procedure, no need to create |
7147 | -- actual subtypes (small optimization). | |
7148 | ||
7149 | if Ekind (Subp) = E_Procedure | |
7150 | and then Is_Null_Init_Proc (Subp) | |
7151 | then | |
7152 | return; | |
7153 | end if; | |
7154 | ||
996ae0b0 RK |
7155 | Formal := First_Formal (Subp); |
7156 | while Present (Formal) loop | |
7157 | T := Etype (Formal); | |
7158 | ||
e895b435 | 7159 | -- We never need an actual subtype for a constrained formal |
996ae0b0 RK |
7160 | |
7161 | if Is_Constrained (T) then | |
7162 | AS_Needed := False; | |
7163 | ||
82c80734 RD |
7164 | -- If we have unknown discriminants, then we do not need an actual |
7165 | -- subtype, or more accurately we cannot figure it out! Note that | |
7166 | -- all class-wide types have unknown discriminants. | |
996ae0b0 RK |
7167 | |
7168 | elsif Has_Unknown_Discriminants (T) then | |
7169 | AS_Needed := False; | |
7170 | ||
82c80734 RD |
7171 | -- At this stage we have an unconstrained type that may need an |
7172 | -- actual subtype. For sure the actual subtype is needed if we have | |
7173 | -- an unconstrained array type. | |
996ae0b0 RK |
7174 | |
7175 | elsif Is_Array_Type (T) then | |
7176 | AS_Needed := True; | |
7177 | ||
d8db0bca JM |
7178 | -- The only other case needing an actual subtype is an unconstrained |
7179 | -- record type which is an IN parameter (we cannot generate actual | |
7180 | -- subtypes for the OUT or IN OUT case, since an assignment can | |
7181 | -- change the discriminant values. However we exclude the case of | |
7182 | -- initialization procedures, since discriminants are handled very | |
7183 | -- specially in this context, see the section entitled "Handling of | |
7184 | -- Discriminants" in Einfo. | |
7185 | ||
7186 | -- We also exclude the case of Discrim_SO_Functions (functions used | |
7187 | -- in front end layout mode for size/offset values), since in such | |
7188 | -- functions only discriminants are referenced, and not only are such | |
7189 | -- subtypes not needed, but they cannot always be generated, because | |
7190 | -- of order of elaboration issues. | |
996ae0b0 RK |
7191 | |
7192 | elsif Is_Record_Type (T) | |
7193 | and then Ekind (Formal) = E_In_Parameter | |
7194 | and then Chars (Formal) /= Name_uInit | |
5d09245e | 7195 | and then not Is_Unchecked_Union (T) |
996ae0b0 RK |
7196 | and then not Is_Discrim_SO_Function (Subp) |
7197 | then | |
7198 | AS_Needed := True; | |
7199 | ||
7200 | -- All other cases do not need an actual subtype | |
7201 | ||
7202 | else | |
7203 | AS_Needed := False; | |
7204 | end if; | |
7205 | ||
7206 | -- Generate actual subtypes for unconstrained arrays and | |
7207 | -- unconstrained discriminated records. | |
7208 | ||
7209 | if AS_Needed then | |
7324bf49 | 7210 | if Nkind (N) = N_Accept_Statement then |
fbf5a39b AC |
7211 | |
7212 | -- If expansion is active, The formal is replaced by a local | |
7213 | -- variable that renames the corresponding entry of the | |
7214 | -- parameter block, and it is this local variable that may | |
7215 | -- require an actual subtype. | |
7216 | ||
7217 | if Expander_Active then | |
7218 | Decl := Build_Actual_Subtype (T, Renamed_Object (Formal)); | |
7219 | else | |
7220 | Decl := Build_Actual_Subtype (T, Formal); | |
7221 | end if; | |
7222 | ||
996ae0b0 RK |
7223 | if Present (Handled_Statement_Sequence (N)) then |
7224 | First_Stmt := | |
7225 | First (Statements (Handled_Statement_Sequence (N))); | |
7226 | Prepend (Decl, Statements (Handled_Statement_Sequence (N))); | |
7227 | Mark_Rewrite_Insertion (Decl); | |
7228 | else | |
82c80734 RD |
7229 | -- If the accept statement has no body, there will be no |
7230 | -- reference to the actuals, so no need to compute actual | |
7231 | -- subtypes. | |
996ae0b0 RK |
7232 | |
7233 | return; | |
7234 | end if; | |
7235 | ||
7236 | else | |
fbf5a39b | 7237 | Decl := Build_Actual_Subtype (T, Formal); |
996ae0b0 RK |
7238 | Prepend (Decl, Declarations (N)); |
7239 | Mark_Rewrite_Insertion (Decl); | |
7240 | end if; | |
7241 | ||
82c80734 RD |
7242 | -- The declaration uses the bounds of an existing object, and |
7243 | -- therefore needs no constraint checks. | |
2820d220 | 7244 | |
7324bf49 | 7245 | Analyze (Decl, Suppress => All_Checks); |
2820d220 | 7246 | |
996ae0b0 RK |
7247 | -- We need to freeze manually the generated type when it is |
7248 | -- inserted anywhere else than in a declarative part. | |
7249 | ||
7250 | if Present (First_Stmt) then | |
7251 | Insert_List_Before_And_Analyze (First_Stmt, | |
7252 | Freeze_Entity (Defining_Identifier (Decl), Loc)); | |
7253 | end if; | |
7254 | ||
fbf5a39b AC |
7255 | if Nkind (N) = N_Accept_Statement |
7256 | and then Expander_Active | |
7257 | then | |
7258 | Set_Actual_Subtype (Renamed_Object (Formal), | |
7259 | Defining_Identifier (Decl)); | |
7260 | else | |
7261 | Set_Actual_Subtype (Formal, Defining_Identifier (Decl)); | |
7262 | end if; | |
996ae0b0 RK |
7263 | end if; |
7264 | ||
7265 | Next_Formal (Formal); | |
7266 | end loop; | |
7267 | end Set_Actual_Subtypes; | |
7268 | ||
7269 | --------------------- | |
7270 | -- Set_Formal_Mode -- | |
7271 | --------------------- | |
7272 | ||
7273 | procedure Set_Formal_Mode (Formal_Id : Entity_Id) is | |
7274 | Spec : constant Node_Id := Parent (Formal_Id); | |
7275 | ||
7276 | begin | |
7277 | -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters | |
7278 | -- since we ensure that corresponding actuals are always valid at the | |
7279 | -- point of the call. | |
7280 | ||
7281 | if Out_Present (Spec) then | |
996ae0b0 RK |
7282 | if Ekind (Scope (Formal_Id)) = E_Function |
7283 | or else Ekind (Scope (Formal_Id)) = E_Generic_Function | |
7284 | then | |
7285 | Error_Msg_N ("functions can only have IN parameters", Spec); | |
7286 | Set_Ekind (Formal_Id, E_In_Parameter); | |
7287 | ||
7288 | elsif In_Present (Spec) then | |
7289 | Set_Ekind (Formal_Id, E_In_Out_Parameter); | |
7290 | ||
7291 | else | |
fbf5a39b AC |
7292 | Set_Ekind (Formal_Id, E_Out_Parameter); |
7293 | Set_Never_Set_In_Source (Formal_Id, True); | |
7294 | Set_Is_True_Constant (Formal_Id, False); | |
7295 | Set_Current_Value (Formal_Id, Empty); | |
996ae0b0 RK |
7296 | end if; |
7297 | ||
7298 | else | |
7299 | Set_Ekind (Formal_Id, E_In_Parameter); | |
7300 | end if; | |
7301 | ||
fbf5a39b | 7302 | -- Set Is_Known_Non_Null for access parameters since the language |
82c80734 RD |
7303 | -- guarantees that access parameters are always non-null. We also set |
7304 | -- Can_Never_Be_Null, since there is no way to change the value. | |
fbf5a39b AC |
7305 | |
7306 | if Nkind (Parameter_Type (Spec)) = N_Access_Definition then | |
2820d220 | 7307 | |
2813bb6b ES |
7308 | -- Ada 2005 (AI-231): In Ada95, access parameters are always non- |
7309 | -- null; In Ada 2005, only if then null_exclusion is explicit. | |
2820d220 | 7310 | |
0ab80019 | 7311 | if Ada_Version < Ada_05 |
2813bb6b | 7312 | or else Can_Never_Be_Null (Etype (Formal_Id)) |
2820d220 AC |
7313 | then |
7314 | Set_Is_Known_Non_Null (Formal_Id); | |
7315 | Set_Can_Never_Be_Null (Formal_Id); | |
7316 | end if; | |
2813bb6b | 7317 | |
41251c60 JM |
7318 | -- Ada 2005 (AI-231): Null-exclusion access subtype |
7319 | ||
2813bb6b ES |
7320 | elsif Is_Access_Type (Etype (Formal_Id)) |
7321 | and then Can_Never_Be_Null (Etype (Formal_Id)) | |
7322 | then | |
2813bb6b | 7323 | Set_Is_Known_Non_Null (Formal_Id); |
fbf5a39b AC |
7324 | end if; |
7325 | ||
996ae0b0 RK |
7326 | Set_Mechanism (Formal_Id, Default_Mechanism); |
7327 | Set_Formal_Validity (Formal_Id); | |
7328 | end Set_Formal_Mode; | |
7329 | ||
7330 | ------------------------- | |
7331 | -- Set_Formal_Validity -- | |
7332 | ------------------------- | |
7333 | ||
7334 | procedure Set_Formal_Validity (Formal_Id : Entity_Id) is | |
7335 | begin | |
82c80734 RD |
7336 | -- If no validity checking, then we cannot assume anything about the |
7337 | -- validity of parameters, since we do not know there is any checking | |
7338 | -- of the validity on the call side. | |
996ae0b0 RK |
7339 | |
7340 | if not Validity_Checks_On then | |
7341 | return; | |
7342 | ||
fbf5a39b AC |
7343 | -- If validity checking for parameters is enabled, this means we are |
7344 | -- not supposed to make any assumptions about argument values. | |
7345 | ||
7346 | elsif Validity_Check_Parameters then | |
7347 | return; | |
7348 | ||
7349 | -- If we are checking in parameters, we will assume that the caller is | |
7350 | -- also checking parameters, so we can assume the parameter is valid. | |
7351 | ||
996ae0b0 RK |
7352 | elsif Ekind (Formal_Id) = E_In_Parameter |
7353 | and then Validity_Check_In_Params | |
7354 | then | |
7355 | Set_Is_Known_Valid (Formal_Id, True); | |
7356 | ||
fbf5a39b AC |
7357 | -- Similar treatment for IN OUT parameters |
7358 | ||
996ae0b0 RK |
7359 | elsif Ekind (Formal_Id) = E_In_Out_Parameter |
7360 | and then Validity_Check_In_Out_Params | |
7361 | then | |
7362 | Set_Is_Known_Valid (Formal_Id, True); | |
7363 | end if; | |
7364 | end Set_Formal_Validity; | |
7365 | ||
7366 | ------------------------ | |
7367 | -- Subtype_Conformant -- | |
7368 | ------------------------ | |
7369 | ||
7370 | function Subtype_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is | |
7371 | Result : Boolean; | |
996ae0b0 RK |
7372 | begin |
7373 | Check_Conformance (New_Id, Old_Id, Subtype_Conformant, False, Result); | |
7374 | return Result; | |
7375 | end Subtype_Conformant; | |
7376 | ||
7377 | --------------------- | |
7378 | -- Type_Conformant -- | |
7379 | --------------------- | |
7380 | ||
41251c60 JM |
7381 | function Type_Conformant |
7382 | (New_Id : Entity_Id; | |
7383 | Old_Id : Entity_Id; | |
7384 | Skip_Controlling_Formals : Boolean := False) return Boolean | |
7385 | is | |
996ae0b0 | 7386 | Result : Boolean; |
996ae0b0 | 7387 | begin |
c8ef728f ES |
7388 | May_Hide_Profile := False; |
7389 | ||
41251c60 JM |
7390 | Check_Conformance |
7391 | (New_Id, Old_Id, Type_Conformant, False, Result, | |
7392 | Skip_Controlling_Formals => Skip_Controlling_Formals); | |
996ae0b0 RK |
7393 | return Result; |
7394 | end Type_Conformant; | |
7395 | ||
7396 | ------------------------------- | |
7397 | -- Valid_Operator_Definition -- | |
7398 | ------------------------------- | |
7399 | ||
7400 | procedure Valid_Operator_Definition (Designator : Entity_Id) is | |
7401 | N : Integer := 0; | |
7402 | F : Entity_Id; | |
7403 | Id : constant Name_Id := Chars (Designator); | |
7404 | N_OK : Boolean; | |
7405 | ||
7406 | begin | |
7407 | F := First_Formal (Designator); | |
996ae0b0 RK |
7408 | while Present (F) loop |
7409 | N := N + 1; | |
7410 | ||
7411 | if Present (Default_Value (F)) then | |
7412 | Error_Msg_N | |
7413 | ("default values not allowed for operator parameters", | |
7414 | Parent (F)); | |
7415 | end if; | |
7416 | ||
7417 | Next_Formal (F); | |
7418 | end loop; | |
7419 | ||
7420 | -- Verify that user-defined operators have proper number of arguments | |
7421 | -- First case of operators which can only be unary | |
7422 | ||
7423 | if Id = Name_Op_Not | |
7424 | or else Id = Name_Op_Abs | |
7425 | then | |
7426 | N_OK := (N = 1); | |
7427 | ||
7428 | -- Case of operators which can be unary or binary | |
7429 | ||
7430 | elsif Id = Name_Op_Add | |
7431 | or Id = Name_Op_Subtract | |
7432 | then | |
7433 | N_OK := (N in 1 .. 2); | |
7434 | ||
7435 | -- All other operators can only be binary | |
7436 | ||
7437 | else | |
7438 | N_OK := (N = 2); | |
7439 | end if; | |
7440 | ||
7441 | if not N_OK then | |
7442 | Error_Msg_N | |
7443 | ("incorrect number of arguments for operator", Designator); | |
7444 | end if; | |
7445 | ||
7446 | if Id = Name_Op_Ne | |
7447 | and then Base_Type (Etype (Designator)) = Standard_Boolean | |
7448 | and then not Is_Intrinsic_Subprogram (Designator) | |
7449 | then | |
7450 | Error_Msg_N | |
7451 | ("explicit definition of inequality not allowed", Designator); | |
7452 | end if; | |
7453 | end Valid_Operator_Definition; | |
7454 | ||
7455 | end Sem_Ch6; |