]>
Commit | Line | Data |
---|---|---|
996ae0b0 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- S E M _ C H 4 -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
19d846a0 | 9 | -- Copyright (C) 1992-2010, 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- -- | |
157a9bf5 | 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 -- | |
157a9bf5 ES |
18 | -- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
19 | -- http://www.gnu.org/licenses for a complete copy of the license. -- | |
996ae0b0 RK |
20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
996ae0b0 RK |
23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
26 | with Atree; use Atree; | |
27 | with Debug; use Debug; | |
28 | with Einfo; use Einfo; | |
35ae2ed8 | 29 | with Elists; use Elists; |
996ae0b0 RK |
30 | with Errout; use Errout; |
31 | with Exp_Util; use Exp_Util; | |
d935a36e | 32 | with Fname; use Fname; |
996ae0b0 | 33 | with Itypes; use Itypes; |
d935a36e | 34 | with Lib; use Lib; |
996ae0b0 RK |
35 | with Lib.Xref; use Lib.Xref; |
36 | with Namet; use Namet; | |
d469eabe | 37 | with Namet.Sp; use Namet.Sp; |
996ae0b0 RK |
38 | with Nlists; use Nlists; |
39 | with Nmake; use Nmake; | |
40 | with Opt; use Opt; | |
41 | with Output; use Output; | |
42 | with Restrict; use Restrict; | |
6e937c1c | 43 | with Rident; use Rident; |
996ae0b0 | 44 | with Sem; use Sem; |
a4100e55 | 45 | with Sem_Aux; use Sem_Aux; |
19d846a0 | 46 | with Sem_Case; use Sem_Case; |
996ae0b0 RK |
47 | with Sem_Cat; use Sem_Cat; |
48 | with Sem_Ch3; use Sem_Ch3; | |
d469eabe | 49 | with Sem_Ch6; use Sem_Ch6; |
996ae0b0 | 50 | with Sem_Ch8; use Sem_Ch8; |
b67a385c | 51 | with Sem_Disp; use Sem_Disp; |
996ae0b0 RK |
52 | with Sem_Dist; use Sem_Dist; |
53 | with Sem_Eval; use Sem_Eval; | |
54 | with Sem_Res; use Sem_Res; | |
996ae0b0 | 55 | with Sem_Type; use Sem_Type; |
19d846a0 RD |
56 | with Sem_Util; use Sem_Util; |
57 | with Sem_Warn; use Sem_Warn; | |
996ae0b0 RK |
58 | with Stand; use Stand; |
59 | with Sinfo; use Sinfo; | |
60 | with Snames; use Snames; | |
61 | with Tbuild; use Tbuild; | |
62 | ||
996ae0b0 RK |
63 | package body Sem_Ch4 is |
64 | ||
65 | ----------------------- | |
66 | -- Local Subprograms -- | |
67 | ----------------------- | |
68 | ||
fe39cf20 BD |
69 | procedure Analyze_Concatenation_Rest (N : Node_Id); |
70 | -- Does the "rest" of the work of Analyze_Concatenation, after the left | |
71 | -- operand has been analyzed. See Analyze_Concatenation for details. | |
72 | ||
996ae0b0 RK |
73 | procedure Analyze_Expression (N : Node_Id); |
74 | -- For expressions that are not names, this is just a call to analyze. | |
75 | -- If the expression is a name, it may be a call to a parameterless | |
76 | -- function, and if so must be converted into an explicit call node | |
77 | -- and analyzed as such. This deproceduring must be done during the first | |
78 | -- pass of overload resolution, because otherwise a procedure call with | |
b4592168 | 79 | -- overloaded actuals may fail to resolve. |
996ae0b0 RK |
80 | |
81 | procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id); | |
82 | -- Analyze a call of the form "+"(x, y), etc. The prefix of the call | |
83 | -- is an operator name or an expanded name whose selector is an operator | |
84 | -- name, and one possible interpretation is as a predefined operator. | |
85 | ||
86 | procedure Analyze_Overloaded_Selected_Component (N : Node_Id); | |
87 | -- If the prefix of a selected_component is overloaded, the proper | |
88 | -- interpretation that yields a record type with the proper selector | |
89 | -- name must be selected. | |
90 | ||
91 | procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id); | |
92 | -- Procedure to analyze a user defined binary operator, which is resolved | |
93 | -- like a function, but instead of a list of actuals it is presented | |
94 | -- with the left and right operands of an operator node. | |
95 | ||
96 | procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id); | |
97 | -- Procedure to analyze a user defined unary operator, which is resolved | |
98 | -- like a function, but instead of a list of actuals, it is presented with | |
99 | -- the operand of the operator node. | |
100 | ||
101 | procedure Ambiguous_Operands (N : Node_Id); | |
102 | -- for equality, membership, and comparison operators with overloaded | |
103 | -- arguments, list possible interpretations. | |
104 | ||
996ae0b0 | 105 | procedure Analyze_One_Call |
ec6078e3 ES |
106 | (N : Node_Id; |
107 | Nam : Entity_Id; | |
108 | Report : Boolean; | |
109 | Success : out Boolean; | |
110 | Skip_First : Boolean := False); | |
996ae0b0 RK |
111 | -- Check one interpretation of an overloaded subprogram name for |
112 | -- compatibility with the types of the actuals in a call. If there is a | |
113 | -- single interpretation which does not match, post error if Report is | |
114 | -- set to True. | |
115 | -- | |
116 | -- Nam is the entity that provides the formals against which the actuals | |
117 | -- are checked. Nam is either the name of a subprogram, or the internal | |
118 | -- subprogram type constructed for an access_to_subprogram. If the actuals | |
119 | -- are compatible with Nam, then Nam is added to the list of candidate | |
120 | -- interpretations for N, and Success is set to True. | |
ec6078e3 ES |
121 | -- |
122 | -- The flag Skip_First is used when analyzing a call that was rewritten | |
123 | -- from object notation. In this case the first actual may have to receive | |
124 | -- an explicit dereference, depending on the first formal of the operation | |
125 | -- being called. The caller will have verified that the object is legal | |
126 | -- for the call. If the remaining parameters match, the first parameter | |
127 | -- will rewritten as a dereference if needed, prior to completing analysis. | |
996ae0b0 RK |
128 | |
129 | procedure Check_Misspelled_Selector | |
130 | (Prefix : Entity_Id; | |
131 | Sel : Node_Id); | |
8dbf3473 AC |
132 | -- Give possible misspelling diagnostic if Sel is likely to be a mis- |
133 | -- spelling of one of the selectors of the Prefix. This is called by | |
134 | -- Analyze_Selected_Component after producing an invalid selector error | |
135 | -- message. | |
996ae0b0 RK |
136 | |
137 | function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean; | |
f3d57416 | 138 | -- Verify that type T is declared in scope S. Used to find interpretations |
996ae0b0 RK |
139 | -- for operators given by expanded names. This is abstracted as a separate |
140 | -- function to handle extensions to System, where S is System, but T is | |
141 | -- declared in the extension. | |
142 | ||
143 | procedure Find_Arithmetic_Types | |
144 | (L, R : Node_Id; | |
145 | Op_Id : Entity_Id; | |
146 | N : Node_Id); | |
147 | -- L and R are the operands of an arithmetic operator. Find | |
148 | -- consistent pairs of interpretations for L and R that have a | |
149 | -- numeric type consistent with the semantics of the operator. | |
150 | ||
151 | procedure Find_Comparison_Types | |
152 | (L, R : Node_Id; | |
153 | Op_Id : Entity_Id; | |
154 | N : Node_Id); | |
155 | -- L and R are operands of a comparison operator. Find consistent | |
156 | -- pairs of interpretations for L and R. | |
157 | ||
158 | procedure Find_Concatenation_Types | |
159 | (L, R : Node_Id; | |
160 | Op_Id : Entity_Id; | |
161 | N : Node_Id); | |
6e73e3ab | 162 | -- For the four varieties of concatenation |
996ae0b0 RK |
163 | |
164 | procedure Find_Equality_Types | |
165 | (L, R : Node_Id; | |
166 | Op_Id : Entity_Id; | |
167 | N : Node_Id); | |
6e73e3ab | 168 | -- Ditto for equality operators |
996ae0b0 RK |
169 | |
170 | procedure Find_Boolean_Types | |
171 | (L, R : Node_Id; | |
172 | Op_Id : Entity_Id; | |
173 | N : Node_Id); | |
6e73e3ab | 174 | -- Ditto for binary logical operations |
996ae0b0 RK |
175 | |
176 | procedure Find_Negation_Types | |
177 | (R : Node_Id; | |
178 | Op_Id : Entity_Id; | |
179 | N : Node_Id); | |
6e73e3ab | 180 | -- Find consistent interpretation for operand of negation operator |
996ae0b0 RK |
181 | |
182 | procedure Find_Non_Universal_Interpretations | |
183 | (N : Node_Id; | |
184 | R : Node_Id; | |
185 | Op_Id : Entity_Id; | |
186 | T1 : Entity_Id); | |
187 | -- For equality and comparison operators, the result is always boolean, | |
188 | -- and the legality of the operation is determined from the visibility | |
189 | -- of the operand types. If one of the operands has a universal interpre- | |
190 | -- tation, the legality check uses some compatible non-universal | |
191 | -- interpretation of the other operand. N can be an operator node, or | |
192 | -- a function call whose name is an operator designator. | |
193 | ||
d469eabe HK |
194 | function Find_Primitive_Operation (N : Node_Id) return Boolean; |
195 | -- Find candidate interpretations for the name Obj.Proc when it appears | |
196 | -- in a subprogram renaming declaration. | |
197 | ||
996ae0b0 RK |
198 | procedure Find_Unary_Types |
199 | (R : Node_Id; | |
200 | Op_Id : Entity_Id; | |
201 | N : Node_Id); | |
6e73e3ab | 202 | -- Unary arithmetic types: plus, minus, abs |
996ae0b0 RK |
203 | |
204 | procedure Check_Arithmetic_Pair | |
205 | (T1, T2 : Entity_Id; | |
206 | Op_Id : Entity_Id; | |
207 | N : Node_Id); | |
208 | -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid | |
209 | -- types for left and right operand. Determine whether they constitute | |
210 | -- a valid pair for the given operator, and record the corresponding | |
211 | -- interpretation of the operator node. The node N may be an operator | |
212 | -- node (the usual case) or a function call whose prefix is an operator | |
401093c1 | 213 | -- designator. In both cases Op_Id is the operator name itself. |
996ae0b0 RK |
214 | |
215 | procedure Diagnose_Call (N : Node_Id; Nam : Node_Id); | |
216 | -- Give detailed information on overloaded call where none of the | |
217 | -- interpretations match. N is the call node, Nam the designator for | |
218 | -- the overloaded entity being called. | |
219 | ||
220 | function Junk_Operand (N : Node_Id) return Boolean; | |
221 | -- Test for an operand that is an inappropriate entity (e.g. a package | |
222 | -- name or a label). If so, issue an error message and return True. If | |
223 | -- the operand is not an inappropriate entity kind, return False. | |
224 | ||
225 | procedure Operator_Check (N : Node_Id); | |
da709d08 AC |
226 | -- Verify that an operator has received some valid interpretation. If none |
227 | -- was found, determine whether a use clause would make the operation | |
228 | -- legal. The variable Candidate_Type (defined in Sem_Type) is set for | |
229 | -- every type compatible with the operator, even if the operator for the | |
230 | -- type is not directly visible. The routine uses this type to emit a more | |
231 | -- informative message. | |
996ae0b0 | 232 | |
d469eabe | 233 | function Process_Implicit_Dereference_Prefix |
da709d08 | 234 | (E : Entity_Id; |
d469eabe | 235 | P : Node_Id) return Entity_Id; |
da709d08 | 236 | -- Called when P is the prefix of an implicit dereference, denoting an |
d469eabe HK |
237 | -- object E. The function returns the designated type of the prefix, taking |
238 | -- into account that the designated type of an anonymous access type may be | |
239 | -- a limited view, when the non-limited view is visible. | |
240 | -- If in semantics only mode (-gnatc or generic), the function also records | |
241 | -- that the prefix is a reference to E, if any. Normally, such a reference | |
242 | -- is generated only when the implicit dereference is expanded into an | |
243 | -- explicit one, but for consistency we must generate the reference when | |
244 | -- expansion is disabled as well. | |
6e73e3ab | 245 | |
30c20106 AC |
246 | procedure Remove_Abstract_Operations (N : Node_Id); |
247 | -- Ada 2005: implementation of AI-310. An abstract non-dispatching | |
248 | -- operation is not a candidate interpretation. | |
249 | ||
996ae0b0 | 250 | function Try_Indexed_Call |
aab883ec ES |
251 | (N : Node_Id; |
252 | Nam : Entity_Id; | |
253 | Typ : Entity_Id; | |
254 | Skip_First : Boolean) return Boolean; | |
255 | -- If a function has defaults for all its actuals, a call to it may in fact | |
256 | -- be an indexing on the result of the call. Try_Indexed_Call attempts the | |
257 | -- interpretation as an indexing, prior to analysis as a call. If both are | |
258 | -- possible, the node is overloaded with both interpretations (same symbol | |
259 | -- but two different types). If the call is written in prefix form, the | |
260 | -- prefix becomes the first parameter in the call, and only the remaining | |
261 | -- actuals must be checked for the presence of defaults. | |
996ae0b0 RK |
262 | |
263 | function Try_Indirect_Call | |
91b1417d AC |
264 | (N : Node_Id; |
265 | Nam : Entity_Id; | |
266 | Typ : Entity_Id) return Boolean; | |
aab883ec ES |
267 | -- Similarly, a function F that needs no actuals can return an access to a |
268 | -- subprogram, and the call F (X) interpreted as F.all (X). In this case | |
269 | -- the call may be overloaded with both interpretations. | |
996ae0b0 | 270 | |
35ae2ed8 | 271 | function Try_Object_Operation (N : Node_Id) return Boolean; |
aab883ec | 272 | -- Ada 2005 (AI-252): Support the object.operation notation |
35ae2ed8 | 273 | |
b4592168 GD |
274 | procedure wpo (T : Entity_Id); |
275 | pragma Warnings (Off, wpo); | |
276 | -- Used for debugging: obtain list of primitive operations even if | |
277 | -- type is not frozen and dispatch table is not built yet. | |
278 | ||
996ae0b0 RK |
279 | ------------------------ |
280 | -- Ambiguous_Operands -- | |
281 | ------------------------ | |
282 | ||
283 | procedure Ambiguous_Operands (N : Node_Id) is | |
fbf5a39b | 284 | procedure List_Operand_Interps (Opnd : Node_Id); |
996ae0b0 | 285 | |
4c46b835 AC |
286 | -------------------------- |
287 | -- List_Operand_Interps -- | |
288 | -------------------------- | |
289 | ||
fbf5a39b | 290 | procedure List_Operand_Interps (Opnd : Node_Id) is |
996ae0b0 RK |
291 | Nam : Node_Id; |
292 | Err : Node_Id := N; | |
293 | ||
294 | begin | |
295 | if Is_Overloaded (Opnd) then | |
296 | if Nkind (Opnd) in N_Op then | |
297 | Nam := Opnd; | |
996ae0b0 RK |
298 | elsif Nkind (Opnd) = N_Function_Call then |
299 | Nam := Name (Opnd); | |
996ae0b0 RK |
300 | else |
301 | return; | |
302 | end if; | |
303 | ||
304 | else | |
305 | return; | |
306 | end if; | |
307 | ||
308 | if Opnd = Left_Opnd (N) then | |
ed2233dc | 309 | Error_Msg_N ("\left operand has the following interpretations", N); |
996ae0b0 | 310 | else |
ed2233dc | 311 | Error_Msg_N |
996ae0b0 RK |
312 | ("\right operand has the following interpretations", N); |
313 | Err := Opnd; | |
314 | end if; | |
315 | ||
fbf5a39b AC |
316 | List_Interps (Nam, Err); |
317 | end List_Operand_Interps; | |
996ae0b0 | 318 | |
4c46b835 AC |
319 | -- Start of processing for Ambiguous_Operands |
320 | ||
996ae0b0 | 321 | begin |
b67a385c | 322 | if Nkind (N) in N_Membership_Test then |
ed2233dc | 323 | Error_Msg_N ("ambiguous operands for membership", N); |
996ae0b0 | 324 | |
d469eabe | 325 | elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then |
ed2233dc | 326 | Error_Msg_N ("ambiguous operands for equality", N); |
996ae0b0 RK |
327 | |
328 | else | |
ed2233dc | 329 | Error_Msg_N ("ambiguous operands for comparison", N); |
996ae0b0 RK |
330 | end if; |
331 | ||
332 | if All_Errors_Mode then | |
fbf5a39b AC |
333 | List_Operand_Interps (Left_Opnd (N)); |
334 | List_Operand_Interps (Right_Opnd (N)); | |
996ae0b0 | 335 | else |
555360a5 | 336 | Error_Msg_N ("\use -gnatf switch for details", N); |
996ae0b0 RK |
337 | end if; |
338 | end Ambiguous_Operands; | |
339 | ||
340 | ----------------------- | |
341 | -- Analyze_Aggregate -- | |
342 | ----------------------- | |
343 | ||
344 | -- Most of the analysis of Aggregates requires that the type be known, | |
345 | -- and is therefore put off until resolution. | |
346 | ||
347 | procedure Analyze_Aggregate (N : Node_Id) is | |
348 | begin | |
349 | if No (Etype (N)) then | |
350 | Set_Etype (N, Any_Composite); | |
351 | end if; | |
352 | end Analyze_Aggregate; | |
353 | ||
354 | ----------------------- | |
355 | -- Analyze_Allocator -- | |
356 | ----------------------- | |
357 | ||
358 | procedure Analyze_Allocator (N : Node_Id) is | |
359 | Loc : constant Source_Ptr := Sloc (N); | |
07fc65c4 | 360 | Sav_Errs : constant Nat := Serious_Errors_Detected; |
b67a385c | 361 | E : Node_Id := Expression (N); |
996ae0b0 RK |
362 | Acc_Type : Entity_Id; |
363 | Type_Id : Entity_Id; | |
364 | ||
365 | begin | |
50cff367 GD |
366 | -- In accordance with H.4(7), the No_Allocators restriction only applies |
367 | -- to user-written allocators. | |
368 | ||
369 | if Comes_From_Source (N) then | |
370 | Check_Restriction (No_Allocators, N); | |
371 | end if; | |
996ae0b0 RK |
372 | |
373 | if Nkind (E) = N_Qualified_Expression then | |
374 | Acc_Type := Create_Itype (E_Allocator_Type, N); | |
375 | Set_Etype (Acc_Type, Acc_Type); | |
996ae0b0 | 376 | Find_Type (Subtype_Mark (E)); |
45c8b94b ES |
377 | |
378 | -- Analyze the qualified expression, and apply the name resolution | |
379 | -- rule given in 4.7 (3). | |
380 | ||
381 | Analyze (E); | |
382 | Type_Id := Etype (E); | |
996ae0b0 RK |
383 | Set_Directly_Designated_Type (Acc_Type, Type_Id); |
384 | ||
45c8b94b | 385 | Resolve (Expression (E), Type_Id); |
b67a385c | 386 | |
d05ef0ab | 387 | if Is_Limited_Type (Type_Id) |
996ae0b0 RK |
388 | and then Comes_From_Source (N) |
389 | and then not In_Instance_Body | |
390 | then | |
2a31c32b | 391 | if not OK_For_Limited_Init (Type_Id, Expression (E)) then |
d05ef0ab AC |
392 | Error_Msg_N ("initialization not allowed for limited types", N); |
393 | Explain_Limited_Type (Type_Id, N); | |
394 | end if; | |
996ae0b0 RK |
395 | end if; |
396 | ||
996ae0b0 RK |
397 | -- A qualified expression requires an exact match of the type, |
398 | -- class-wide matching is not allowed. | |
399 | ||
45c8b94b ES |
400 | -- if Is_Class_Wide_Type (Type_Id) |
401 | -- and then Base_Type | |
402 | -- (Etype (Expression (E))) /= Base_Type (Type_Id) | |
403 | -- then | |
404 | -- Wrong_Type (Expression (E), Type_Id); | |
405 | -- end if; | |
996ae0b0 RK |
406 | |
407 | Check_Non_Static_Context (Expression (E)); | |
408 | ||
409 | -- We don't analyze the qualified expression itself because it's | |
410 | -- part of the allocator | |
411 | ||
412 | Set_Etype (E, Type_Id); | |
413 | ||
aab883ec | 414 | -- Case where allocator has a subtype indication |
4c46b835 | 415 | |
996ae0b0 RK |
416 | else |
417 | declare | |
758c442c GD |
418 | Def_Id : Entity_Id; |
419 | Base_Typ : Entity_Id; | |
996ae0b0 RK |
420 | |
421 | begin | |
422 | -- If the allocator includes a N_Subtype_Indication then a | |
423 | -- constraint is present, otherwise the node is a subtype mark. | |
424 | -- Introduce an explicit subtype declaration into the tree | |
425 | -- defining some anonymous subtype and rewrite the allocator to | |
426 | -- use this subtype rather than the subtype indication. | |
427 | ||
428 | -- It is important to introduce the explicit subtype declaration | |
429 | -- so that the bounds of the subtype indication are attached to | |
430 | -- the tree in case the allocator is inside a generic unit. | |
431 | ||
432 | if Nkind (E) = N_Subtype_Indication then | |
433 | ||
434 | -- A constraint is only allowed for a composite type in Ada | |
435 | -- 95. In Ada 83, a constraint is also allowed for an | |
436 | -- access-to-composite type, but the constraint is ignored. | |
437 | ||
438 | Find_Type (Subtype_Mark (E)); | |
758c442c | 439 | Base_Typ := Entity (Subtype_Mark (E)); |
996ae0b0 | 440 | |
758c442c | 441 | if Is_Elementary_Type (Base_Typ) then |
0ab80019 | 442 | if not (Ada_Version = Ada_83 |
758c442c | 443 | and then Is_Access_Type (Base_Typ)) |
996ae0b0 RK |
444 | then |
445 | Error_Msg_N ("constraint not allowed here", E); | |
446 | ||
24657705 HK |
447 | if Nkind (Constraint (E)) = |
448 | N_Index_Or_Discriminant_Constraint | |
996ae0b0 | 449 | then |
4e7a4f6e | 450 | Error_Msg_N -- CODEFIX |
996ae0b0 RK |
451 | ("\if qualified expression was meant, " & |
452 | "use apostrophe", Constraint (E)); | |
453 | end if; | |
454 | end if; | |
455 | ||
456 | -- Get rid of the bogus constraint: | |
457 | ||
458 | Rewrite (E, New_Copy_Tree (Subtype_Mark (E))); | |
459 | Analyze_Allocator (N); | |
460 | return; | |
758c442c GD |
461 | |
462 | -- Ada 2005, AI-363: if the designated type has a constrained | |
463 | -- partial view, it cannot receive a discriminant constraint, | |
464 | -- and the allocated object is unconstrained. | |
465 | ||
466 | elsif Ada_Version >= Ada_05 | |
467 | and then Has_Constrained_Partial_View (Base_Typ) | |
468 | then | |
469 | Error_Msg_N | |
470 | ("constraint no allowed when type " & | |
471 | "has a constrained partial view", Constraint (E)); | |
996ae0b0 RK |
472 | end if; |
473 | ||
474 | if Expander_Active then | |
092ef350 | 475 | Def_Id := Make_Temporary (Loc, 'S'); |
996ae0b0 RK |
476 | |
477 | Insert_Action (E, | |
478 | Make_Subtype_Declaration (Loc, | |
479 | Defining_Identifier => Def_Id, | |
480 | Subtype_Indication => Relocate_Node (E))); | |
481 | ||
07fc65c4 | 482 | if Sav_Errs /= Serious_Errors_Detected |
d469eabe HK |
483 | and then Nkind (Constraint (E)) = |
484 | N_Index_Or_Discriminant_Constraint | |
996ae0b0 | 485 | then |
4e7a4f6e | 486 | Error_Msg_N -- CODEFIX |
996ae0b0 RK |
487 | ("if qualified expression was meant, " & |
488 | "use apostrophe!", Constraint (E)); | |
489 | end if; | |
490 | ||
491 | E := New_Occurrence_Of (Def_Id, Loc); | |
492 | Rewrite (Expression (N), E); | |
493 | end if; | |
494 | end if; | |
495 | ||
496 | Type_Id := Process_Subtype (E, N); | |
497 | Acc_Type := Create_Itype (E_Allocator_Type, N); | |
498 | Set_Etype (Acc_Type, Acc_Type); | |
996ae0b0 RK |
499 | Set_Directly_Designated_Type (Acc_Type, Type_Id); |
500 | Check_Fully_Declared (Type_Id, N); | |
501 | ||
1baa4d2d | 502 | -- Ada 2005 (AI-231): If the designated type is itself an access |
16b05213 | 503 | -- type that excludes null, its default initialization will |
75ad5042 ES |
504 | -- be a null object, and we can insert an unconditional raise |
505 | -- before the allocator. | |
2820d220 AC |
506 | |
507 | if Can_Never_Be_Null (Type_Id) then | |
75ad5042 ES |
508 | declare |
509 | Not_Null_Check : constant Node_Id := | |
510 | Make_Raise_Constraint_Error (Sloc (E), | |
511 | Reason => CE_Null_Not_Allowed); | |
512 | begin | |
513 | if Expander_Active then | |
514 | Insert_Action (N, Not_Null_Check); | |
515 | Analyze (Not_Null_Check); | |
516 | else | |
517 | Error_Msg_N ("null value not allowed here?", E); | |
518 | end if; | |
519 | end; | |
2820d220 AC |
520 | end if; |
521 | ||
91b1417d AC |
522 | -- Check restriction against dynamically allocated protected |
523 | -- objects. Note that when limited aggregates are supported, | |
524 | -- a similar test should be applied to an allocator with a | |
525 | -- qualified expression ??? | |
526 | ||
527 | if Is_Protected_Type (Type_Id) then | |
528 | Check_Restriction (No_Protected_Type_Allocators, N); | |
529 | end if; | |
530 | ||
996ae0b0 RK |
531 | -- Check for missing initialization. Skip this check if we already |
532 | -- had errors on analyzing the allocator, since in that case these | |
24657705 | 533 | -- are probably cascaded errors. |
996ae0b0 RK |
534 | |
535 | if Is_Indefinite_Subtype (Type_Id) | |
07fc65c4 | 536 | and then Serious_Errors_Detected = Sav_Errs |
996ae0b0 RK |
537 | then |
538 | if Is_Class_Wide_Type (Type_Id) then | |
539 | Error_Msg_N | |
540 | ("initialization required in class-wide allocation", N); | |
541 | else | |
24657705 HK |
542 | if Ada_Version < Ada_05 |
543 | and then Is_Limited_Type (Type_Id) | |
544 | then | |
545 | Error_Msg_N ("unconstrained allocation not allowed", N); | |
546 | ||
547 | if Is_Array_Type (Type_Id) then | |
548 | Error_Msg_N | |
549 | ("\constraint with array bounds required", N); | |
550 | ||
551 | elsif Has_Unknown_Discriminants (Type_Id) then | |
552 | null; | |
553 | ||
554 | else pragma Assert (Has_Discriminants (Type_Id)); | |
555 | Error_Msg_N | |
556 | ("\constraint with discriminant values required", N); | |
557 | end if; | |
558 | ||
559 | -- Limited Ada 2005 and general non-limited case | |
560 | ||
561 | else | |
562 | Error_Msg_N | |
563 | ("uninitialized unconstrained allocation not allowed", | |
564 | N); | |
565 | ||
566 | if Is_Array_Type (Type_Id) then | |
567 | Error_Msg_N | |
568 | ("\qualified expression or constraint with " & | |
569 | "array bounds required", N); | |
570 | ||
571 | elsif Has_Unknown_Discriminants (Type_Id) then | |
572 | Error_Msg_N ("\qualified expression required", N); | |
573 | ||
574 | else pragma Assert (Has_Discriminants (Type_Id)); | |
575 | Error_Msg_N | |
576 | ("\qualified expression or constraint with " & | |
577 | "discriminant values required", N); | |
578 | end if; | |
579 | end if; | |
996ae0b0 RK |
580 | end if; |
581 | end if; | |
582 | end; | |
583 | end if; | |
584 | ||
aab883ec | 585 | if Is_Abstract_Type (Type_Id) then |
996ae0b0 RK |
586 | Error_Msg_N ("cannot allocate abstract object", E); |
587 | end if; | |
588 | ||
589 | if Has_Task (Designated_Type (Acc_Type)) then | |
6e937c1c | 590 | Check_Restriction (No_Tasking, N); |
fbf5a39b | 591 | Check_Restriction (Max_Tasks, N); |
996ae0b0 RK |
592 | Check_Restriction (No_Task_Allocators, N); |
593 | end if; | |
594 | ||
ffe9aba8 AC |
595 | -- If the No_Streams restriction is set, check that the type of the |
596 | -- object is not, and does not contain, any subtype derived from | |
597 | -- Ada.Streams.Root_Stream_Type. Note that we guard the call to | |
598 | -- Has_Stream just for efficiency reasons. There is no point in | |
599 | -- spending time on a Has_Stream check if the restriction is not set. | |
600 | ||
601 | if Restrictions.Set (No_Streams) then | |
602 | if Has_Stream (Designated_Type (Acc_Type)) then | |
603 | Check_Restriction (No_Streams, N); | |
604 | end if; | |
605 | end if; | |
606 | ||
996ae0b0 RK |
607 | Set_Etype (N, Acc_Type); |
608 | ||
609 | if not Is_Library_Level_Entity (Acc_Type) then | |
610 | Check_Restriction (No_Local_Allocators, N); | |
611 | end if; | |
2820d220 | 612 | |
07fc65c4 | 613 | if Serious_Errors_Detected > Sav_Errs then |
996ae0b0 RK |
614 | Set_Error_Posted (N); |
615 | Set_Etype (N, Any_Type); | |
616 | end if; | |
996ae0b0 RK |
617 | end Analyze_Allocator; |
618 | ||
619 | --------------------------- | |
620 | -- Analyze_Arithmetic_Op -- | |
621 | --------------------------- | |
622 | ||
623 | procedure Analyze_Arithmetic_Op (N : Node_Id) is | |
624 | L : constant Node_Id := Left_Opnd (N); | |
625 | R : constant Node_Id := Right_Opnd (N); | |
626 | Op_Id : Entity_Id; | |
627 | ||
628 | begin | |
629 | Candidate_Type := Empty; | |
630 | Analyze_Expression (L); | |
631 | Analyze_Expression (R); | |
632 | ||
d469eabe HK |
633 | -- If the entity is already set, the node is the instantiation of a |
634 | -- generic node with a non-local reference, or was manufactured by a | |
635 | -- call to Make_Op_xxx. In either case the entity is known to be valid, | |
636 | -- and we do not need to collect interpretations, instead we just get | |
637 | -- the single possible interpretation. | |
996ae0b0 RK |
638 | |
639 | Op_Id := Entity (N); | |
640 | ||
641 | if Present (Op_Id) then | |
642 | if Ekind (Op_Id) = E_Operator then | |
643 | ||
d469eabe | 644 | if Nkind_In (N, N_Op_Divide, N_Op_Mod, N_Op_Multiply, N_Op_Rem) |
996ae0b0 RK |
645 | and then Treat_Fixed_As_Integer (N) |
646 | then | |
647 | null; | |
648 | else | |
649 | Set_Etype (N, Any_Type); | |
650 | Find_Arithmetic_Types (L, R, Op_Id, N); | |
651 | end if; | |
652 | ||
653 | else | |
654 | Set_Etype (N, Any_Type); | |
655 | Add_One_Interp (N, Op_Id, Etype (Op_Id)); | |
656 | end if; | |
657 | ||
658 | -- Entity is not already set, so we do need to collect interpretations | |
659 | ||
660 | else | |
661 | Op_Id := Get_Name_Entity_Id (Chars (N)); | |
662 | Set_Etype (N, Any_Type); | |
663 | ||
664 | while Present (Op_Id) loop | |
665 | if Ekind (Op_Id) = E_Operator | |
666 | and then Present (Next_Entity (First_Entity (Op_Id))) | |
667 | then | |
668 | Find_Arithmetic_Types (L, R, Op_Id, N); | |
669 | ||
670 | -- The following may seem superfluous, because an operator cannot | |
671 | -- be generic, but this ignores the cleverness of the author of | |
672 | -- ACVC bc1013a. | |
673 | ||
674 | elsif Is_Overloadable (Op_Id) then | |
675 | Analyze_User_Defined_Binary_Op (N, Op_Id); | |
676 | end if; | |
677 | ||
678 | Op_Id := Homonym (Op_Id); | |
679 | end loop; | |
680 | end if; | |
681 | ||
682 | Operator_Check (N); | |
683 | end Analyze_Arithmetic_Op; | |
684 | ||
685 | ------------------ | |
686 | -- Analyze_Call -- | |
687 | ------------------ | |
688 | ||
4c46b835 AC |
689 | -- Function, procedure, and entry calls are checked here. The Name in |
690 | -- the call may be overloaded. The actuals have been analyzed and may | |
691 | -- themselves be overloaded. On exit from this procedure, the node N | |
692 | -- may have zero, one or more interpretations. In the first case an | |
693 | -- error message is produced. In the last case, the node is flagged | |
694 | -- as overloaded and the interpretations are collected in All_Interp. | |
996ae0b0 RK |
695 | |
696 | -- If the name is an Access_To_Subprogram, it cannot be overloaded, but | |
697 | -- the type-checking is similar to that of other calls. | |
698 | ||
699 | procedure Analyze_Call (N : Node_Id) is | |
700 | Actuals : constant List_Id := Parameter_Associations (N); | |
63319f58 | 701 | Nam : Node_Id; |
996ae0b0 RK |
702 | X : Interp_Index; |
703 | It : Interp; | |
704 | Nam_Ent : Entity_Id; | |
63319f58 RD |
705 | Success : Boolean := False; |
706 | ||
707 | Deref : Boolean := False; | |
1cb17b78 AC |
708 | -- Flag indicates whether an interpretation of the prefix is a |
709 | -- parameterless call that returns an access_to_subprogram. | |
996ae0b0 RK |
710 | |
711 | function Name_Denotes_Function return Boolean; | |
5ff22245 ES |
712 | -- If the type of the name is an access to subprogram, this may be the |
713 | -- type of a name, or the return type of the function being called. If | |
714 | -- the name is not an entity then it can denote a protected function. | |
715 | -- Until we distinguish Etype from Return_Type, we must use this routine | |
716 | -- to resolve the meaning of the name in the call. | |
717 | ||
718 | procedure No_Interpretation; | |
719 | -- Output error message when no valid interpretation exists | |
996ae0b0 RK |
720 | |
721 | --------------------------- | |
722 | -- Name_Denotes_Function -- | |
723 | --------------------------- | |
724 | ||
725 | function Name_Denotes_Function return Boolean is | |
726 | begin | |
727 | if Is_Entity_Name (Nam) then | |
728 | return Ekind (Entity (Nam)) = E_Function; | |
729 | ||
730 | elsif Nkind (Nam) = N_Selected_Component then | |
731 | return Ekind (Entity (Selector_Name (Nam))) = E_Function; | |
732 | ||
733 | else | |
734 | return False; | |
735 | end if; | |
736 | end Name_Denotes_Function; | |
737 | ||
5ff22245 ES |
738 | ----------------------- |
739 | -- No_Interpretation -- | |
740 | ----------------------- | |
741 | ||
742 | procedure No_Interpretation is | |
743 | L : constant Boolean := Is_List_Member (N); | |
744 | K : constant Node_Kind := Nkind (Parent (N)); | |
745 | ||
746 | begin | |
747 | -- If the node is in a list whose parent is not an expression then it | |
748 | -- must be an attempted procedure call. | |
749 | ||
750 | if L and then K not in N_Subexpr then | |
751 | if Ekind (Entity (Nam)) = E_Generic_Procedure then | |
752 | Error_Msg_NE | |
753 | ("must instantiate generic procedure& before call", | |
754 | Nam, Entity (Nam)); | |
755 | else | |
756 | Error_Msg_N | |
757 | ("procedure or entry name expected", Nam); | |
758 | end if; | |
759 | ||
760 | -- Check for tasking cases where only an entry call will do | |
761 | ||
762 | elsif not L | |
763 | and then Nkind_In (K, N_Entry_Call_Alternative, | |
764 | N_Triggering_Alternative) | |
765 | then | |
766 | Error_Msg_N ("entry name expected", Nam); | |
767 | ||
768 | -- Otherwise give general error message | |
769 | ||
770 | else | |
771 | Error_Msg_N ("invalid prefix in call", Nam); | |
772 | end if; | |
773 | end No_Interpretation; | |
774 | ||
996ae0b0 RK |
775 | -- Start of processing for Analyze_Call |
776 | ||
777 | begin | |
778 | -- Initialize the type of the result of the call to the error type, | |
779 | -- which will be reset if the type is successfully resolved. | |
780 | ||
781 | Set_Etype (N, Any_Type); | |
782 | ||
63319f58 RD |
783 | Nam := Name (N); |
784 | ||
996ae0b0 RK |
785 | if not Is_Overloaded (Nam) then |
786 | ||
787 | -- Only one interpretation to check | |
788 | ||
789 | if Ekind (Etype (Nam)) = E_Subprogram_Type then | |
790 | Nam_Ent := Etype (Nam); | |
791 | ||
758c442c GD |
792 | -- If the prefix is an access_to_subprogram, this may be an indirect |
793 | -- call. This is the case if the name in the call is not an entity | |
794 | -- name, or if it is a function name in the context of a procedure | |
795 | -- call. In this latter case, we have a call to a parameterless | |
796 | -- function that returns a pointer_to_procedure which is the entity | |
5ff22245 ES |
797 | -- being called. Finally, F (X) may be a call to a parameterless |
798 | -- function that returns a pointer to a function with parameters. | |
758c442c | 799 | |
996ae0b0 RK |
800 | elsif Is_Access_Type (Etype (Nam)) |
801 | and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type | |
758c442c GD |
802 | and then |
803 | (not Name_Denotes_Function | |
5ff22245 ES |
804 | or else Nkind (N) = N_Procedure_Call_Statement |
805 | or else | |
806 | (Nkind (Parent (N)) /= N_Explicit_Dereference | |
807 | and then Is_Entity_Name (Nam) | |
808 | and then No (First_Formal (Entity (Nam))) | |
809 | and then Present (Actuals))) | |
996ae0b0 RK |
810 | then |
811 | Nam_Ent := Designated_Type (Etype (Nam)); | |
812 | Insert_Explicit_Dereference (Nam); | |
813 | ||
814 | -- Selected component case. Simple entry or protected operation, | |
815 | -- where the entry name is given by the selector name. | |
816 | ||
817 | elsif Nkind (Nam) = N_Selected_Component then | |
818 | Nam_Ent := Entity (Selector_Name (Nam)); | |
819 | ||
bce79204 AC |
820 | if not Ekind_In (Nam_Ent, E_Entry, |
821 | E_Entry_Family, | |
822 | E_Function, | |
823 | E_Procedure) | |
996ae0b0 RK |
824 | then |
825 | Error_Msg_N ("name in call is not a callable entity", Nam); | |
826 | Set_Etype (N, Any_Type); | |
827 | return; | |
828 | end if; | |
829 | ||
830 | -- If the name is an Indexed component, it can be a call to a member | |
831 | -- of an entry family. The prefix must be a selected component whose | |
832 | -- selector is the entry. Analyze_Procedure_Call normalizes several | |
833 | -- kinds of call into this form. | |
834 | ||
835 | elsif Nkind (Nam) = N_Indexed_Component then | |
996ae0b0 RK |
836 | if Nkind (Prefix (Nam)) = N_Selected_Component then |
837 | Nam_Ent := Entity (Selector_Name (Prefix (Nam))); | |
996ae0b0 RK |
838 | else |
839 | Error_Msg_N ("name in call is not a callable entity", Nam); | |
840 | Set_Etype (N, Any_Type); | |
841 | return; | |
996ae0b0 RK |
842 | end if; |
843 | ||
844 | elsif not Is_Entity_Name (Nam) then | |
845 | Error_Msg_N ("name in call is not a callable entity", Nam); | |
846 | Set_Etype (N, Any_Type); | |
847 | return; | |
848 | ||
849 | else | |
850 | Nam_Ent := Entity (Nam); | |
851 | ||
852 | -- If no interpretations, give error message | |
853 | ||
854 | if not Is_Overloadable (Nam_Ent) then | |
5ff22245 ES |
855 | No_Interpretation; |
856 | return; | |
857 | end if; | |
858 | end if; | |
996ae0b0 | 859 | |
5ff22245 ES |
860 | -- Operations generated for RACW stub types are called only through |
861 | -- dispatching, and can never be the static interpretation of a call. | |
996ae0b0 | 862 | |
5ff22245 ES |
863 | if Is_RACW_Stub_Type_Operation (Nam_Ent) then |
864 | No_Interpretation; | |
865 | return; | |
996ae0b0 RK |
866 | end if; |
867 | ||
868 | Analyze_One_Call (N, Nam_Ent, True, Success); | |
869 | ||
ec6078e3 ES |
870 | -- If this is an indirect call, the return type of the access_to |
871 | -- subprogram may be an incomplete type. At the point of the call, | |
872 | -- use the full type if available, and at the same time update | |
873 | -- the return type of the access_to_subprogram. | |
874 | ||
875 | if Success | |
d469eabe | 876 | and then Nkind (Nam) = N_Explicit_Dereference |
ec6078e3 ES |
877 | and then Ekind (Etype (N)) = E_Incomplete_Type |
878 | and then Present (Full_View (Etype (N))) | |
879 | then | |
880 | Set_Etype (N, Full_View (Etype (N))); | |
881 | Set_Etype (Nam_Ent, Etype (N)); | |
882 | end if; | |
883 | ||
996ae0b0 | 884 | else |
5ff22245 ES |
885 | -- An overloaded selected component must denote overloaded operations |
886 | -- of a concurrent type. The interpretations are attached to the | |
887 | -- simple name of those operations. | |
996ae0b0 RK |
888 | |
889 | if Nkind (Nam) = N_Selected_Component then | |
890 | Nam := Selector_Name (Nam); | |
891 | end if; | |
892 | ||
893 | Get_First_Interp (Nam, X, It); | |
894 | ||
895 | while Present (It.Nam) loop | |
896 | Nam_Ent := It.Nam; | |
1cb17b78 | 897 | Deref := False; |
996ae0b0 RK |
898 | |
899 | -- Name may be call that returns an access to subprogram, or more | |
900 | -- generally an overloaded expression one of whose interpretations | |
901 | -- yields an access to subprogram. If the name is an entity, we | |
902 | -- do not dereference, because the node is a call that returns | |
903 | -- the access type: note difference between f(x), where the call | |
904 | -- may return an access subprogram type, and f(x)(y), where the | |
905 | -- type returned by the call to f is implicitly dereferenced to | |
906 | -- analyze the outer call. | |
907 | ||
908 | if Is_Access_Type (Nam_Ent) then | |
909 | Nam_Ent := Designated_Type (Nam_Ent); | |
910 | ||
911 | elsif Is_Access_Type (Etype (Nam_Ent)) | |
1cb17b78 AC |
912 | and then |
913 | (not Is_Entity_Name (Nam) | |
914 | or else Nkind (N) = N_Procedure_Call_Statement) | |
996ae0b0 RK |
915 | and then Ekind (Designated_Type (Etype (Nam_Ent))) |
916 | = E_Subprogram_Type | |
917 | then | |
918 | Nam_Ent := Designated_Type (Etype (Nam_Ent)); | |
1cb17b78 AC |
919 | |
920 | if Is_Entity_Name (Nam) then | |
921 | Deref := True; | |
922 | end if; | |
996ae0b0 RK |
923 | end if; |
924 | ||
7415029d AC |
925 | -- If the call has been rewritten from a prefixed call, the first |
926 | -- parameter has been analyzed, but may need a subsequent | |
927 | -- dereference, so skip its analysis now. | |
928 | ||
929 | if N /= Original_Node (N) | |
930 | and then Nkind (Original_Node (N)) = Nkind (N) | |
931 | and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N))) | |
932 | and then Present (Parameter_Associations (N)) | |
933 | and then Present (Etype (First (Parameter_Associations (N)))) | |
934 | then | |
935 | Analyze_One_Call | |
936 | (N, Nam_Ent, False, Success, Skip_First => True); | |
937 | else | |
938 | Analyze_One_Call (N, Nam_Ent, False, Success); | |
939 | end if; | |
996ae0b0 RK |
940 | |
941 | -- If the interpretation succeeds, mark the proper type of the | |
942 | -- prefix (any valid candidate will do). If not, remove the | |
943 | -- candidate interpretation. This only needs to be done for | |
944 | -- overloaded protected operations, for other entities disambi- | |
945 | -- guation is done directly in Resolve. | |
946 | ||
947 | if Success then | |
1cb17b78 AC |
948 | if Deref |
949 | and then Nkind (Parent (N)) /= N_Explicit_Dereference | |
950 | then | |
951 | Set_Entity (Nam, It.Nam); | |
952 | Insert_Explicit_Dereference (Nam); | |
953 | Set_Etype (Nam, Nam_Ent); | |
954 | ||
955 | else | |
956 | Set_Etype (Nam, It.Typ); | |
957 | end if; | |
996ae0b0 | 958 | |
d469eabe HK |
959 | elsif Nkind_In (Name (N), N_Selected_Component, |
960 | N_Function_Call) | |
fbf5a39b | 961 | then |
996ae0b0 RK |
962 | Remove_Interp (X); |
963 | end if; | |
964 | ||
965 | Get_Next_Interp (X, It); | |
966 | end loop; | |
967 | ||
968 | -- If the name is the result of a function call, it can only | |
969 | -- be a call to a function returning an access to subprogram. | |
970 | -- Insert explicit dereference. | |
971 | ||
972 | if Nkind (Nam) = N_Function_Call then | |
973 | Insert_Explicit_Dereference (Nam); | |
974 | end if; | |
975 | ||
976 | if Etype (N) = Any_Type then | |
977 | ||
978 | -- None of the interpretations is compatible with the actuals | |
979 | ||
980 | Diagnose_Call (N, Nam); | |
981 | ||
982 | -- Special checks for uninstantiated put routines | |
983 | ||
984 | if Nkind (N) = N_Procedure_Call_Statement | |
985 | and then Is_Entity_Name (Nam) | |
986 | and then Chars (Nam) = Name_Put | |
987 | and then List_Length (Actuals) = 1 | |
988 | then | |
989 | declare | |
990 | Arg : constant Node_Id := First (Actuals); | |
991 | Typ : Entity_Id; | |
992 | ||
993 | begin | |
994 | if Nkind (Arg) = N_Parameter_Association then | |
995 | Typ := Etype (Explicit_Actual_Parameter (Arg)); | |
996 | else | |
997 | Typ := Etype (Arg); | |
998 | end if; | |
999 | ||
1000 | if Is_Signed_Integer_Type (Typ) then | |
1001 | Error_Msg_N | |
1002 | ("possible missing instantiation of " & | |
1003 | "'Text_'I'O.'Integer_'I'O!", Nam); | |
1004 | ||
1005 | elsif Is_Modular_Integer_Type (Typ) then | |
1006 | Error_Msg_N | |
1007 | ("possible missing instantiation of " & | |
1008 | "'Text_'I'O.'Modular_'I'O!", Nam); | |
1009 | ||
1010 | elsif Is_Floating_Point_Type (Typ) then | |
1011 | Error_Msg_N | |
1012 | ("possible missing instantiation of " & | |
1013 | "'Text_'I'O.'Float_'I'O!", Nam); | |
1014 | ||
1015 | elsif Is_Ordinary_Fixed_Point_Type (Typ) then | |
1016 | Error_Msg_N | |
1017 | ("possible missing instantiation of " & | |
1018 | "'Text_'I'O.'Fixed_'I'O!", Nam); | |
1019 | ||
1020 | elsif Is_Decimal_Fixed_Point_Type (Typ) then | |
1021 | Error_Msg_N | |
1022 | ("possible missing instantiation of " & | |
1023 | "'Text_'I'O.'Decimal_'I'O!", Nam); | |
1024 | ||
1025 | elsif Is_Enumeration_Type (Typ) then | |
1026 | Error_Msg_N | |
1027 | ("possible missing instantiation of " & | |
1028 | "'Text_'I'O.'Enumeration_'I'O!", Nam); | |
1029 | end if; | |
1030 | end; | |
1031 | end if; | |
1032 | ||
1033 | elsif not Is_Overloaded (N) | |
1034 | and then Is_Entity_Name (Nam) | |
1035 | then | |
aab883ec ES |
1036 | -- Resolution yields a single interpretation. Verify that the |
1037 | -- reference has capitalization consistent with the declaration. | |
996ae0b0 RK |
1038 | |
1039 | Set_Entity_With_Style_Check (Nam, Entity (Nam)); | |
1040 | Generate_Reference (Entity (Nam), Nam); | |
1041 | ||
1042 | Set_Etype (Nam, Etype (Entity (Nam))); | |
30c20106 AC |
1043 | else |
1044 | Remove_Abstract_Operations (N); | |
996ae0b0 RK |
1045 | end if; |
1046 | ||
1047 | End_Interp_List; | |
1048 | end if; | |
1049 | end Analyze_Call; | |
1050 | ||
19d846a0 RD |
1051 | ----------------------------- |
1052 | -- Analyze_Case_Expression -- | |
1053 | ----------------------------- | |
1054 | ||
1055 | procedure Analyze_Case_Expression (N : Node_Id) is | |
1056 | Expr : constant Node_Id := Expression (N); | |
1057 | FirstX : constant Node_Id := Expression (First (Alternatives (N))); | |
1058 | Alt : Node_Id; | |
1059 | Exp_Type : Entity_Id; | |
1060 | Exp_Btype : Entity_Id; | |
1061 | ||
1062 | Last_Choice : Nat; | |
1063 | Dont_Care : Boolean; | |
1064 | Others_Present : Boolean; | |
1065 | ||
1066 | procedure Non_Static_Choice_Error (Choice : Node_Id); | |
1067 | -- Error routine invoked by the generic instantiation below when | |
1068 | -- the case expression has a non static choice. | |
1069 | ||
1070 | package Case_Choices_Processing is new | |
1071 | Generic_Choices_Processing | |
1072 | (Get_Alternatives => Alternatives, | |
1073 | Get_Choices => Discrete_Choices, | |
1074 | Process_Empty_Choice => No_OP, | |
1075 | Process_Non_Static_Choice => Non_Static_Choice_Error, | |
1076 | Process_Associated_Node => No_OP); | |
1077 | use Case_Choices_Processing; | |
1078 | ||
1079 | Case_Table : Choice_Table_Type (1 .. Number_Of_Choices (N)); | |
1080 | ||
1081 | ----------------------------- | |
1082 | -- Non_Static_Choice_Error -- | |
1083 | ----------------------------- | |
1084 | ||
1085 | procedure Non_Static_Choice_Error (Choice : Node_Id) is | |
1086 | begin | |
1087 | Flag_Non_Static_Expr | |
1088 | ("choice given in case expression is not static!", Choice); | |
1089 | end Non_Static_Choice_Error; | |
1090 | ||
1091 | -- Start of processing for Analyze_Case_Expression | |
1092 | ||
1093 | begin | |
1094 | if Comes_From_Source (N) then | |
1095 | Check_Compiler_Unit (N); | |
1096 | end if; | |
1097 | ||
1098 | Analyze_And_Resolve (Expr, Any_Discrete); | |
1099 | Check_Unset_Reference (Expr); | |
1100 | Exp_Type := Etype (Expr); | |
1101 | Exp_Btype := Base_Type (Exp_Type); | |
1102 | ||
1103 | Alt := First (Alternatives (N)); | |
1104 | while Present (Alt) loop | |
1105 | Analyze (Expression (Alt)); | |
1106 | Next (Alt); | |
1107 | end loop; | |
1108 | ||
1109 | if not Is_Overloaded (FirstX) then | |
1110 | Set_Etype (N, Etype (FirstX)); | |
1111 | ||
1112 | else | |
1113 | declare | |
1114 | I : Interp_Index; | |
1115 | It : Interp; | |
1116 | ||
1117 | begin | |
1118 | Set_Etype (N, Any_Type); | |
1119 | ||
1120 | Get_First_Interp (FirstX, I, It); | |
1121 | while Present (It.Nam) loop | |
1122 | ||
1123 | -- For each intepretation of the first expression, we only | |
1124 | -- add the intepretation if every other expression in the | |
1125 | -- case expression alternatives has a compatible type. | |
1126 | ||
1127 | Alt := Next (First (Alternatives (N))); | |
1128 | while Present (Alt) loop | |
1129 | exit when not Has_Compatible_Type (Expression (Alt), It.Typ); | |
1130 | Next (Alt); | |
1131 | end loop; | |
1132 | ||
1133 | if No (Alt) then | |
1134 | Add_One_Interp (N, It.Typ, It.Typ); | |
1135 | end if; | |
1136 | ||
1137 | Get_Next_Interp (I, It); | |
1138 | end loop; | |
1139 | end; | |
1140 | end if; | |
1141 | ||
1142 | Exp_Btype := Base_Type (Exp_Type); | |
1143 | ||
1144 | -- The expression must be of a discrete type which must be determinable | |
1145 | -- independently of the context in which the expression occurs, but | |
1146 | -- using the fact that the expression must be of a discrete type. | |
1147 | -- Moreover, the type this expression must not be a character literal | |
1148 | -- (which is always ambiguous). | |
1149 | ||
1150 | -- If error already reported by Resolve, nothing more to do | |
1151 | ||
1152 | if Exp_Btype = Any_Discrete | |
1153 | or else Exp_Btype = Any_Type | |
1154 | then | |
1155 | return; | |
1156 | ||
1157 | elsif Exp_Btype = Any_Character then | |
1158 | Error_Msg_N | |
1159 | ("character literal as case expression is ambiguous", Expr); | |
1160 | return; | |
1161 | end if; | |
1162 | ||
1163 | -- If the case expression is a formal object of mode in out, then | |
1164 | -- treat it as having a nonstatic subtype by forcing use of the base | |
1165 | -- type (which has to get passed to Check_Case_Choices below). Also | |
1166 | -- use base type when the case expression is parenthesized. | |
1167 | ||
1168 | if Paren_Count (Expr) > 0 | |
1169 | or else (Is_Entity_Name (Expr) | |
1170 | and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter) | |
1171 | then | |
1172 | Exp_Type := Exp_Btype; | |
1173 | end if; | |
1174 | ||
1175 | -- Call instantiated Analyze_Choices which does the rest of the work | |
1176 | ||
1177 | Analyze_Choices | |
1178 | (N, Exp_Type, Case_Table, Last_Choice, Dont_Care, Others_Present); | |
1179 | ||
1180 | if Exp_Type = Universal_Integer and then not Others_Present then | |
1181 | Error_Msg_N | |
1182 | ("case on universal integer requires OTHERS choice", Expr); | |
1183 | end if; | |
1184 | end Analyze_Case_Expression; | |
1185 | ||
996ae0b0 RK |
1186 | --------------------------- |
1187 | -- Analyze_Comparison_Op -- | |
1188 | --------------------------- | |
1189 | ||
1190 | procedure Analyze_Comparison_Op (N : Node_Id) is | |
1191 | L : constant Node_Id := Left_Opnd (N); | |
1192 | R : constant Node_Id := Right_Opnd (N); | |
1193 | Op_Id : Entity_Id := Entity (N); | |
1194 | ||
1195 | begin | |
1196 | Set_Etype (N, Any_Type); | |
1197 | Candidate_Type := Empty; | |
1198 | ||
1199 | Analyze_Expression (L); | |
1200 | Analyze_Expression (R); | |
1201 | ||
1202 | if Present (Op_Id) then | |
996ae0b0 RK |
1203 | if Ekind (Op_Id) = E_Operator then |
1204 | Find_Comparison_Types (L, R, Op_Id, N); | |
1205 | else | |
1206 | Add_One_Interp (N, Op_Id, Etype (Op_Id)); | |
1207 | end if; | |
1208 | ||
1209 | if Is_Overloaded (L) then | |
1210 | Set_Etype (L, Intersect_Types (L, R)); | |
1211 | end if; | |
1212 | ||
1213 | else | |
1214 | Op_Id := Get_Name_Entity_Id (Chars (N)); | |
996ae0b0 | 1215 | while Present (Op_Id) loop |
996ae0b0 RK |
1216 | if Ekind (Op_Id) = E_Operator then |
1217 | Find_Comparison_Types (L, R, Op_Id, N); | |
1218 | else | |
1219 | Analyze_User_Defined_Binary_Op (N, Op_Id); | |
1220 | end if; | |
1221 | ||
1222 | Op_Id := Homonym (Op_Id); | |
1223 | end loop; | |
1224 | end if; | |
1225 | ||
1226 | Operator_Check (N); | |
1227 | end Analyze_Comparison_Op; | |
1228 | ||
1229 | --------------------------- | |
1230 | -- Analyze_Concatenation -- | |
1231 | --------------------------- | |
1232 | ||
fe39cf20 BD |
1233 | procedure Analyze_Concatenation (N : Node_Id) is |
1234 | ||
1235 | -- We wish to avoid deep recursion, because concatenations are often | |
1236 | -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left | |
1237 | -- operands nonrecursively until we find something that is not a | |
1238 | -- concatenation (A in this case), or has already been analyzed. We | |
1239 | -- analyze that, and then walk back up the tree following Parent | |
1240 | -- pointers, calling Analyze_Concatenation_Rest to do the rest of the | |
1241 | -- work at each level. The Parent pointers allow us to avoid recursion, | |
1242 | -- and thus avoid running out of memory. | |
1243 | ||
1244 | NN : Node_Id := N; | |
1245 | L : Node_Id; | |
1246 | ||
1247 | begin | |
1248 | Candidate_Type := Empty; | |
1249 | ||
1250 | -- The following code is equivalent to: | |
1251 | ||
1252 | -- Set_Etype (N, Any_Type); | |
1253 | -- Analyze_Expression (Left_Opnd (N)); | |
1254 | -- Analyze_Concatenation_Rest (N); | |
1255 | ||
1256 | -- where the Analyze_Expression call recurses back here if the left | |
1257 | -- operand is a concatenation. | |
1258 | ||
1259 | -- Walk down left operands | |
1260 | ||
1261 | loop | |
1262 | Set_Etype (NN, Any_Type); | |
1263 | L := Left_Opnd (NN); | |
1264 | exit when Nkind (L) /= N_Op_Concat or else Analyzed (L); | |
1265 | NN := L; | |
1266 | end loop; | |
1267 | ||
1268 | -- Now (given the above example) NN is A&B and L is A | |
1269 | ||
1270 | -- First analyze L ... | |
1271 | ||
1272 | Analyze_Expression (L); | |
1273 | ||
1274 | -- ... then walk NN back up until we reach N (where we started), calling | |
1275 | -- Analyze_Concatenation_Rest along the way. | |
1276 | ||
1277 | loop | |
1278 | Analyze_Concatenation_Rest (NN); | |
1279 | exit when NN = N; | |
1280 | NN := Parent (NN); | |
1281 | end loop; | |
1282 | end Analyze_Concatenation; | |
1283 | ||
1284 | -------------------------------- | |
1285 | -- Analyze_Concatenation_Rest -- | |
1286 | -------------------------------- | |
1287 | ||
996ae0b0 RK |
1288 | -- If the only one-dimensional array type in scope is String, |
1289 | -- this is the resulting type of the operation. Otherwise there | |
1290 | -- will be a concatenation operation defined for each user-defined | |
1291 | -- one-dimensional array. | |
1292 | ||
fe39cf20 | 1293 | procedure Analyze_Concatenation_Rest (N : Node_Id) is |
996ae0b0 RK |
1294 | L : constant Node_Id := Left_Opnd (N); |
1295 | R : constant Node_Id := Right_Opnd (N); | |
1296 | Op_Id : Entity_Id := Entity (N); | |
1297 | LT : Entity_Id; | |
1298 | RT : Entity_Id; | |
1299 | ||
1300 | begin | |
996ae0b0 RK |
1301 | Analyze_Expression (R); |
1302 | ||
cd3cd5b1 AC |
1303 | -- If the entity is present, the node appears in an instance, and |
1304 | -- denotes a predefined concatenation operation. The resulting type is | |
1305 | -- obtained from the arguments when possible. If the arguments are | |
1306 | -- aggregates, the array type and the concatenation type must be | |
fbf5a39b | 1307 | -- visible. |
996ae0b0 RK |
1308 | |
1309 | if Present (Op_Id) then | |
1310 | if Ekind (Op_Id) = E_Operator then | |
996ae0b0 RK |
1311 | LT := Base_Type (Etype (L)); |
1312 | RT := Base_Type (Etype (R)); | |
1313 | ||
1314 | if Is_Array_Type (LT) | |
1315 | and then (RT = LT or else RT = Base_Type (Component_Type (LT))) | |
1316 | then | |
1317 | Add_One_Interp (N, Op_Id, LT); | |
1318 | ||
1319 | elsif Is_Array_Type (RT) | |
1320 | and then LT = Base_Type (Component_Type (RT)) | |
1321 | then | |
1322 | Add_One_Interp (N, Op_Id, RT); | |
1323 | ||
fbf5a39b AC |
1324 | -- If one operand is a string type or a user-defined array type, |
1325 | -- and the other is a literal, result is of the specific type. | |
1326 | ||
1327 | elsif | |
1328 | (Root_Type (LT) = Standard_String | |
1329 | or else Scope (LT) /= Standard_Standard) | |
1330 | and then Etype (R) = Any_String | |
1331 | then | |
1332 | Add_One_Interp (N, Op_Id, LT); | |
1333 | ||
1334 | elsif | |
1335 | (Root_Type (RT) = Standard_String | |
1336 | or else Scope (RT) /= Standard_Standard) | |
1337 | and then Etype (L) = Any_String | |
1338 | then | |
1339 | Add_One_Interp (N, Op_Id, RT); | |
1340 | ||
1341 | elsif not Is_Generic_Type (Etype (Op_Id)) then | |
996ae0b0 | 1342 | Add_One_Interp (N, Op_Id, Etype (Op_Id)); |
fbf5a39b AC |
1343 | |
1344 | else | |
4c46b835 | 1345 | -- Type and its operations must be visible |
fbf5a39b AC |
1346 | |
1347 | Set_Entity (N, Empty); | |
1348 | Analyze_Concatenation (N); | |
996ae0b0 RK |
1349 | end if; |
1350 | ||
1351 | else | |
1352 | Add_One_Interp (N, Op_Id, Etype (Op_Id)); | |
1353 | end if; | |
1354 | ||
1355 | else | |
1a8fae99 | 1356 | Op_Id := Get_Name_Entity_Id (Name_Op_Concat); |
996ae0b0 RK |
1357 | while Present (Op_Id) loop |
1358 | if Ekind (Op_Id) = E_Operator then | |
1a8fae99 ES |
1359 | |
1360 | -- Do not consider operators declared in dead code, they can | |
1361 | -- not be part of the resolution. | |
1362 | ||
1363 | if Is_Eliminated (Op_Id) then | |
1364 | null; | |
1365 | else | |
1366 | Find_Concatenation_Types (L, R, Op_Id, N); | |
1367 | end if; | |
1368 | ||
996ae0b0 RK |
1369 | else |
1370 | Analyze_User_Defined_Binary_Op (N, Op_Id); | |
1371 | end if; | |
1372 | ||
1373 | Op_Id := Homonym (Op_Id); | |
1374 | end loop; | |
1375 | end if; | |
1376 | ||
1377 | Operator_Check (N); | |
fe39cf20 | 1378 | end Analyze_Concatenation_Rest; |
996ae0b0 RK |
1379 | |
1380 | ------------------------------------ | |
1381 | -- Analyze_Conditional_Expression -- | |
1382 | ------------------------------------ | |
1383 | ||
1384 | procedure Analyze_Conditional_Expression (N : Node_Id) is | |
1385 | Condition : constant Node_Id := First (Expressions (N)); | |
1386 | Then_Expr : constant Node_Id := Next (Condition); | |
6c994759 | 1387 | Else_Expr : Node_Id; |
b46be8a2 | 1388 | |
996ae0b0 | 1389 | begin |
6c994759 AC |
1390 | -- Defend against error of missing expressions from previous error |
1391 | ||
1392 | if No (Then_Expr) then | |
1393 | return; | |
1394 | end if; | |
1395 | ||
1396 | Else_Expr := Next (Then_Expr); | |
1397 | ||
b46be8a2 RD |
1398 | if Comes_From_Source (N) then |
1399 | Check_Compiler_Unit (N); | |
1400 | end if; | |
1401 | ||
996ae0b0 RK |
1402 | Analyze_Expression (Condition); |
1403 | Analyze_Expression (Then_Expr); | |
b46be8a2 RD |
1404 | |
1405 | if Present (Else_Expr) then | |
1406 | Analyze_Expression (Else_Expr); | |
1407 | end if; | |
1408 | ||
19d846a0 RD |
1409 | -- If then expression not overloaded, then that decides the type |
1410 | ||
bee2a781 | 1411 | if not Is_Overloaded (Then_Expr) then |
e0ba1bfd | 1412 | Set_Etype (N, Etype (Then_Expr)); |
19d846a0 RD |
1413 | |
1414 | -- Case where then expression is overloaded | |
1415 | ||
e0ba1bfd ES |
1416 | else |
1417 | declare | |
1418 | I : Interp_Index; | |
1419 | It : Interp; | |
1420 | ||
1421 | begin | |
1422 | Set_Etype (N, Any_Type); | |
1423 | Get_First_Interp (Then_Expr, I, It); | |
1424 | while Present (It.Nam) loop | |
19d846a0 RD |
1425 | |
1426 | -- For each possible intepretation of the Then Expression, | |
1427 | -- add it only if the else expression has a compatible type. | |
1428 | ||
1429 | -- Is this right if Else_Expr is empty? | |
1430 | ||
e0ba1bfd ES |
1431 | if Has_Compatible_Type (Else_Expr, It.Typ) then |
1432 | Add_One_Interp (N, It.Typ, It.Typ); | |
1433 | end if; | |
1434 | ||
1435 | Get_Next_Interp (I, It); | |
1436 | end loop; | |
1437 | end; | |
1438 | end if; | |
996ae0b0 RK |
1439 | end Analyze_Conditional_Expression; |
1440 | ||
1441 | ------------------------- | |
1442 | -- Analyze_Equality_Op -- | |
1443 | ------------------------- | |
1444 | ||
1445 | procedure Analyze_Equality_Op (N : Node_Id) is | |
4c46b835 AC |
1446 | Loc : constant Source_Ptr := Sloc (N); |
1447 | L : constant Node_Id := Left_Opnd (N); | |
1448 | R : constant Node_Id := Right_Opnd (N); | |
1449 | Op_Id : Entity_Id; | |
996ae0b0 RK |
1450 | |
1451 | begin | |
1452 | Set_Etype (N, Any_Type); | |
1453 | Candidate_Type := Empty; | |
1454 | ||
1455 | Analyze_Expression (L); | |
1456 | Analyze_Expression (R); | |
1457 | ||
1458 | -- If the entity is set, the node is a generic instance with a non-local | |
1459 | -- reference to the predefined operator or to a user-defined function. | |
1460 | -- It can also be an inequality that is expanded into the negation of a | |
1461 | -- call to a user-defined equality operator. | |
1462 | ||
1463 | -- For the predefined case, the result is Boolean, regardless of the | |
1464 | -- type of the operands. The operands may even be limited, if they are | |
1465 | -- generic actuals. If they are overloaded, label the left argument with | |
1466 | -- the common type that must be present, or with the type of the formal | |
1467 | -- of the user-defined function. | |
1468 | ||
1469 | if Present (Entity (N)) then | |
996ae0b0 RK |
1470 | Op_Id := Entity (N); |
1471 | ||
1472 | if Ekind (Op_Id) = E_Operator then | |
1473 | Add_One_Interp (N, Op_Id, Standard_Boolean); | |
1474 | else | |
1475 | Add_One_Interp (N, Op_Id, Etype (Op_Id)); | |
1476 | end if; | |
1477 | ||
1478 | if Is_Overloaded (L) then | |
996ae0b0 RK |
1479 | if Ekind (Op_Id) = E_Operator then |
1480 | Set_Etype (L, Intersect_Types (L, R)); | |
1481 | else | |
1482 | Set_Etype (L, Etype (First_Formal (Op_Id))); | |
1483 | end if; | |
1484 | end if; | |
1485 | ||
1486 | else | |
1487 | Op_Id := Get_Name_Entity_Id (Chars (N)); | |
996ae0b0 | 1488 | while Present (Op_Id) loop |
996ae0b0 RK |
1489 | if Ekind (Op_Id) = E_Operator then |
1490 | Find_Equality_Types (L, R, Op_Id, N); | |
1491 | else | |
1492 | Analyze_User_Defined_Binary_Op (N, Op_Id); | |
1493 | end if; | |
1494 | ||
1495 | Op_Id := Homonym (Op_Id); | |
1496 | end loop; | |
1497 | end if; | |
1498 | ||
1499 | -- If there was no match, and the operator is inequality, this may | |
1500 | -- be a case where inequality has not been made explicit, as for | |
1501 | -- tagged types. Analyze the node as the negation of an equality | |
1502 | -- operation. This cannot be done earlier, because before analysis | |
1503 | -- we cannot rule out the presence of an explicit inequality. | |
1504 | ||
1505 | if Etype (N) = Any_Type | |
1506 | and then Nkind (N) = N_Op_Ne | |
1507 | then | |
1508 | Op_Id := Get_Name_Entity_Id (Name_Op_Eq); | |
996ae0b0 | 1509 | while Present (Op_Id) loop |
996ae0b0 RK |
1510 | if Ekind (Op_Id) = E_Operator then |
1511 | Find_Equality_Types (L, R, Op_Id, N); | |
1512 | else | |
1513 | Analyze_User_Defined_Binary_Op (N, Op_Id); | |
1514 | end if; | |
1515 | ||
1516 | Op_Id := Homonym (Op_Id); | |
1517 | end loop; | |
1518 | ||
1519 | if Etype (N) /= Any_Type then | |
1520 | Op_Id := Entity (N); | |
1521 | ||
1522 | Rewrite (N, | |
1523 | Make_Op_Not (Loc, | |
1524 | Right_Opnd => | |
1525 | Make_Op_Eq (Loc, | |
aab883ec ES |
1526 | Left_Opnd => Left_Opnd (N), |
1527 | Right_Opnd => Right_Opnd (N)))); | |
996ae0b0 RK |
1528 | |
1529 | Set_Entity (Right_Opnd (N), Op_Id); | |
1530 | Analyze (N); | |
1531 | end if; | |
1532 | end if; | |
1533 | ||
1534 | Operator_Check (N); | |
1535 | end Analyze_Equality_Op; | |
1536 | ||
1537 | ---------------------------------- | |
1538 | -- Analyze_Explicit_Dereference -- | |
1539 | ---------------------------------- | |
1540 | ||
1541 | procedure Analyze_Explicit_Dereference (N : Node_Id) is | |
1542 | Loc : constant Source_Ptr := Sloc (N); | |
1543 | P : constant Node_Id := Prefix (N); | |
1544 | T : Entity_Id; | |
1545 | I : Interp_Index; | |
1546 | It : Interp; | |
1547 | New_N : Node_Id; | |
1548 | ||
1549 | function Is_Function_Type return Boolean; | |
4c46b835 AC |
1550 | -- Check whether node may be interpreted as an implicit function call |
1551 | ||
1552 | ---------------------- | |
1553 | -- Is_Function_Type -- | |
1554 | ---------------------- | |
996ae0b0 RK |
1555 | |
1556 | function Is_Function_Type return Boolean is | |
4c46b835 AC |
1557 | I : Interp_Index; |
1558 | It : Interp; | |
996ae0b0 RK |
1559 | |
1560 | begin | |
1561 | if not Is_Overloaded (N) then | |
1562 | return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type | |
1563 | and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type; | |
1564 | ||
1565 | else | |
1566 | Get_First_Interp (N, I, It); | |
996ae0b0 RK |
1567 | while Present (It.Nam) loop |
1568 | if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type | |
1569 | or else Etype (Base_Type (It.Typ)) = Standard_Void_Type | |
1570 | then | |
1571 | return False; | |
1572 | end if; | |
1573 | ||
1574 | Get_Next_Interp (I, It); | |
1575 | end loop; | |
1576 | ||
1577 | return True; | |
1578 | end if; | |
1579 | end Is_Function_Type; | |
1580 | ||
98123480 | 1581 | -- Start of processing for Analyze_Explicit_Dereference |
4c46b835 | 1582 | |
996ae0b0 RK |
1583 | begin |
1584 | Analyze (P); | |
1585 | Set_Etype (N, Any_Type); | |
1586 | ||
1587 | -- Test for remote access to subprogram type, and if so return | |
1588 | -- after rewriting the original tree. | |
1589 | ||
1590 | if Remote_AST_E_Dereference (P) then | |
1591 | return; | |
1592 | end if; | |
1593 | ||
1594 | -- Normal processing for other than remote access to subprogram type | |
1595 | ||
1596 | if not Is_Overloaded (P) then | |
1597 | if Is_Access_Type (Etype (P)) then | |
1598 | ||
f3d57416 | 1599 | -- Set the Etype. We need to go through Is_For_Access_Subtypes to |
0a36105d JM |
1600 | -- avoid other problems caused by the Private_Subtype and it is |
1601 | -- safe to go to the Base_Type because this is the same as | |
1602 | -- converting the access value to its Base_Type. | |
996ae0b0 RK |
1603 | |
1604 | declare | |
1605 | DT : Entity_Id := Designated_Type (Etype (P)); | |
1606 | ||
1607 | begin | |
1608 | if Ekind (DT) = E_Private_Subtype | |
1609 | and then Is_For_Access_Subtype (DT) | |
1610 | then | |
1611 | DT := Base_Type (DT); | |
1612 | end if; | |
1613 | ||
0a36105d JM |
1614 | -- An explicit dereference is a legal occurrence of an |
1615 | -- incomplete type imported through a limited_with clause, | |
1616 | -- if the full view is visible. | |
1617 | ||
1618 | if From_With_Type (DT) | |
1619 | and then not From_With_Type (Scope (DT)) | |
1620 | and then | |
1621 | (Is_Immediately_Visible (Scope (DT)) | |
1622 | or else | |
1623 | (Is_Child_Unit (Scope (DT)) | |
1624 | and then Is_Visible_Child_Unit (Scope (DT)))) | |
1625 | then | |
1626 | Set_Etype (N, Available_View (DT)); | |
1627 | ||
1628 | else | |
1629 | Set_Etype (N, DT); | |
1630 | end if; | |
996ae0b0 RK |
1631 | end; |
1632 | ||
1633 | elsif Etype (P) /= Any_Type then | |
1634 | Error_Msg_N ("prefix of dereference must be an access type", N); | |
1635 | return; | |
1636 | end if; | |
1637 | ||
1638 | else | |
1639 | Get_First_Interp (P, I, It); | |
996ae0b0 RK |
1640 | while Present (It.Nam) loop |
1641 | T := It.Typ; | |
1642 | ||
1643 | if Is_Access_Type (T) then | |
1644 | Add_One_Interp (N, Designated_Type (T), Designated_Type (T)); | |
1645 | end if; | |
1646 | ||
1647 | Get_Next_Interp (I, It); | |
1648 | end loop; | |
1649 | ||
6e73e3ab | 1650 | -- Error if no interpretation of the prefix has an access type |
996ae0b0 RK |
1651 | |
1652 | if Etype (N) = Any_Type then | |
1653 | Error_Msg_N | |
1654 | ("access type required in prefix of explicit dereference", P); | |
1655 | Set_Etype (N, Any_Type); | |
1656 | return; | |
1657 | end if; | |
1658 | end if; | |
1659 | ||
1660 | if Is_Function_Type | |
1661 | and then Nkind (Parent (N)) /= N_Indexed_Component | |
1662 | ||
1663 | and then (Nkind (Parent (N)) /= N_Function_Call | |
1664 | or else N /= Name (Parent (N))) | |
1665 | ||
1666 | and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement | |
1667 | or else N /= Name (Parent (N))) | |
1668 | ||
1669 | and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration | |
1670 | and then (Nkind (Parent (N)) /= N_Attribute_Reference | |
1671 | or else | |
1672 | (Attribute_Name (Parent (N)) /= Name_Address | |
1673 | and then | |
1674 | Attribute_Name (Parent (N)) /= Name_Access)) | |
1675 | then | |
1676 | -- Name is a function call with no actuals, in a context that | |
1677 | -- requires deproceduring (including as an actual in an enclosing | |
98123480 | 1678 | -- function or procedure call). There are some pathological cases |
996ae0b0 RK |
1679 | -- where the prefix might include functions that return access to |
1680 | -- subprograms and others that return a regular type. Disambiguation | |
98123480 | 1681 | -- of those has to take place in Resolve. |
996ae0b0 RK |
1682 | |
1683 | New_N := | |
1684 | Make_Function_Call (Loc, | |
1685 | Name => Make_Explicit_Dereference (Loc, P), | |
1686 | Parameter_Associations => New_List); | |
1687 | ||
1688 | -- If the prefix is overloaded, remove operations that have formals, | |
1689 | -- we know that this is a parameterless call. | |
1690 | ||
1691 | if Is_Overloaded (P) then | |
1692 | Get_First_Interp (P, I, It); | |
996ae0b0 RK |
1693 | while Present (It.Nam) loop |
1694 | T := It.Typ; | |
1695 | ||
1696 | if No (First_Formal (Base_Type (Designated_Type (T)))) then | |
1697 | Set_Etype (P, T); | |
1698 | else | |
1699 | Remove_Interp (I); | |
1700 | end if; | |
1701 | ||
1702 | Get_Next_Interp (I, It); | |
1703 | end loop; | |
1704 | end if; | |
1705 | ||
1706 | Rewrite (N, New_N); | |
1707 | Analyze (N); | |
98123480 ES |
1708 | |
1709 | elsif not Is_Function_Type | |
1710 | and then Is_Overloaded (N) | |
1711 | then | |
1712 | -- The prefix may include access to subprograms and other access | |
1cb17b78 | 1713 | -- types. If the context selects the interpretation that is a |
56a7a3ab TQ |
1714 | -- function call (not a procedure call) we cannot rewrite the node |
1715 | -- yet, but we include the result of the call interpretation. | |
98123480 ES |
1716 | |
1717 | Get_First_Interp (N, I, It); | |
1718 | while Present (It.Nam) loop | |
1719 | if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type | |
1720 | and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type | |
1cb17b78 | 1721 | and then Nkind (Parent (N)) /= N_Procedure_Call_Statement |
98123480 ES |
1722 | then |
1723 | Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ)); | |
1724 | end if; | |
1725 | ||
1726 | Get_Next_Interp (I, It); | |
1727 | end loop; | |
996ae0b0 RK |
1728 | end if; |
1729 | ||
1730 | -- A value of remote access-to-class-wide must not be dereferenced | |
1731 | -- (RM E.2.2(16)). | |
1732 | ||
1733 | Validate_Remote_Access_To_Class_Wide_Type (N); | |
996ae0b0 RK |
1734 | end Analyze_Explicit_Dereference; |
1735 | ||
1736 | ------------------------ | |
1737 | -- Analyze_Expression -- | |
1738 | ------------------------ | |
1739 | ||
1740 | procedure Analyze_Expression (N : Node_Id) is | |
1741 | begin | |
1742 | Analyze (N); | |
1743 | Check_Parameterless_Call (N); | |
1744 | end Analyze_Expression; | |
1745 | ||
955871d3 AC |
1746 | ------------------------------------- |
1747 | -- Analyze_Expression_With_Actions -- | |
1748 | ------------------------------------- | |
1749 | ||
1750 | procedure Analyze_Expression_With_Actions (N : Node_Id) is | |
1751 | A : Node_Id; | |
1752 | ||
1753 | begin | |
1754 | A := First (Actions (N)); | |
1755 | loop | |
1756 | Analyze (A); | |
1757 | Next (A); | |
1758 | exit when No (A); | |
1759 | end loop; | |
1760 | ||
1761 | Analyze_Expression (Expression (N)); | |
1762 | Set_Etype (N, Etype (Expression (N))); | |
1763 | end Analyze_Expression_With_Actions; | |
1764 | ||
996ae0b0 RK |
1765 | ------------------------------------ |
1766 | -- Analyze_Indexed_Component_Form -- | |
1767 | ------------------------------------ | |
1768 | ||
1769 | procedure Analyze_Indexed_Component_Form (N : Node_Id) is | |
fbf5a39b AC |
1770 | P : constant Node_Id := Prefix (N); |
1771 | Exprs : constant List_Id := Expressions (N); | |
1772 | Exp : Node_Id; | |
1773 | P_T : Entity_Id; | |
1774 | E : Node_Id; | |
1775 | U_N : Entity_Id; | |
996ae0b0 RK |
1776 | |
1777 | procedure Process_Function_Call; | |
1778 | -- Prefix in indexed component form is an overloadable entity, | |
1779 | -- so the node is a function call. Reformat it as such. | |
1780 | ||
1781 | procedure Process_Indexed_Component; | |
1782 | -- Prefix in indexed component form is actually an indexed component. | |
1783 | -- This routine processes it, knowing that the prefix is already | |
1784 | -- resolved. | |
1785 | ||
1786 | procedure Process_Indexed_Component_Or_Slice; | |
1787 | -- An indexed component with a single index may designate a slice if | |
1788 | -- the index is a subtype mark. This routine disambiguates these two | |
1789 | -- cases by resolving the prefix to see if it is a subtype mark. | |
1790 | ||
1791 | procedure Process_Overloaded_Indexed_Component; | |
1792 | -- If the prefix of an indexed component is overloaded, the proper | |
1793 | -- interpretation is selected by the index types and the context. | |
1794 | ||
1795 | --------------------------- | |
1796 | -- Process_Function_Call -- | |
1797 | --------------------------- | |
1798 | ||
1799 | procedure Process_Function_Call is | |
1800 | Actual : Node_Id; | |
1801 | ||
1802 | begin | |
1803 | Change_Node (N, N_Function_Call); | |
1804 | Set_Name (N, P); | |
1805 | Set_Parameter_Associations (N, Exprs); | |
996ae0b0 | 1806 | |
401093c1 | 1807 | -- Analyze actuals prior to analyzing the call itself |
0a36105d | 1808 | |
4c46b835 | 1809 | Actual := First (Parameter_Associations (N)); |
996ae0b0 RK |
1810 | while Present (Actual) loop |
1811 | Analyze (Actual); | |
1812 | Check_Parameterless_Call (Actual); | |
0a36105d JM |
1813 | |
1814 | -- Move to next actual. Note that we use Next, not Next_Actual | |
1815 | -- here. The reason for this is a bit subtle. If a function call | |
1816 | -- includes named associations, the parser recognizes the node as | |
1817 | -- a call, and it is analyzed as such. If all associations are | |
1818 | -- positional, the parser builds an indexed_component node, and | |
1819 | -- it is only after analysis of the prefix that the construct | |
1820 | -- is recognized as a call, in which case Process_Function_Call | |
1821 | -- rewrites the node and analyzes the actuals. If the list of | |
1822 | -- actuals is malformed, the parser may leave the node as an | |
1823 | -- indexed component (despite the presence of named associations). | |
1824 | -- The iterator Next_Actual is equivalent to Next if the list is | |
1825 | -- positional, but follows the normalized chain of actuals when | |
1826 | -- named associations are present. In this case normalization has | |
1827 | -- not taken place, and actuals remain unanalyzed, which leads to | |
1828 | -- subsequent crashes or loops if there is an attempt to continue | |
1829 | -- analysis of the program. | |
1830 | ||
1831 | Next (Actual); | |
996ae0b0 RK |
1832 | end loop; |
1833 | ||
1834 | Analyze_Call (N); | |
1835 | end Process_Function_Call; | |
1836 | ||
1837 | ------------------------------- | |
1838 | -- Process_Indexed_Component -- | |
1839 | ------------------------------- | |
1840 | ||
1841 | procedure Process_Indexed_Component is | |
fe39cf20 BD |
1842 | Exp : Node_Id; |
1843 | Array_Type : Entity_Id; | |
1844 | Index : Node_Id; | |
1845 | Pent : Entity_Id := Empty; | |
996ae0b0 RK |
1846 | |
1847 | begin | |
1848 | Exp := First (Exprs); | |
1849 | ||
1850 | if Is_Overloaded (P) then | |
1851 | Process_Overloaded_Indexed_Component; | |
1852 | ||
1853 | else | |
1854 | Array_Type := Etype (P); | |
1855 | ||
6e73e3ab AC |
1856 | if Is_Entity_Name (P) then |
1857 | Pent := Entity (P); | |
1858 | elsif Nkind (P) = N_Selected_Component | |
1859 | and then Is_Entity_Name (Selector_Name (P)) | |
1860 | then | |
1861 | Pent := Entity (Selector_Name (P)); | |
1862 | end if; | |
1863 | ||
1864 | -- Prefix must be appropriate for an array type, taking into | |
1865 | -- account a possible implicit dereference. | |
996ae0b0 RK |
1866 | |
1867 | if Is_Access_Type (Array_Type) then | |
fbf5a39b | 1868 | Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N); |
d469eabe | 1869 | Array_Type := Process_Implicit_Dereference_Prefix (Pent, P); |
996ae0b0 RK |
1870 | end if; |
1871 | ||
1872 | if Is_Array_Type (Array_Type) then | |
1873 | null; | |
1874 | ||
6e73e3ab | 1875 | elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then |
996ae0b0 RK |
1876 | Analyze (Exp); |
1877 | Set_Etype (N, Any_Type); | |
1878 | ||
1879 | if not Has_Compatible_Type | |
6e73e3ab | 1880 | (Exp, Entry_Index_Type (Pent)) |
996ae0b0 RK |
1881 | then |
1882 | Error_Msg_N ("invalid index type in entry name", N); | |
1883 | ||
1884 | elsif Present (Next (Exp)) then | |
1885 | Error_Msg_N ("too many subscripts in entry reference", N); | |
1886 | ||
1887 | else | |
1888 | Set_Etype (N, Etype (P)); | |
1889 | end if; | |
1890 | ||
1891 | return; | |
1892 | ||
1893 | elsif Is_Record_Type (Array_Type) | |
1894 | and then Remote_AST_I_Dereference (P) | |
1895 | then | |
1896 | return; | |
1897 | ||
1898 | elsif Array_Type = Any_Type then | |
1899 | Set_Etype (N, Any_Type); | |
6465b6a7 AC |
1900 | |
1901 | -- In most cases the analysis of the prefix will have emitted | |
1902 | -- an error already, but if the prefix may be interpreted as a | |
1903 | -- call in prefixed notation, the report is left to the caller. | |
1904 | -- To prevent cascaded errors, report only if no previous ones. | |
1905 | ||
1906 | if Serious_Errors_Detected = 0 then | |
1907 | Error_Msg_N ("invalid prefix in indexed component", P); | |
1908 | ||
1909 | if Nkind (P) = N_Expanded_Name then | |
1910 | Error_Msg_NE ("\& is not visible", P, Selector_Name (P)); | |
1911 | end if; | |
1912 | end if; | |
1913 | ||
996ae0b0 RK |
1914 | return; |
1915 | ||
1916 | -- Here we definitely have a bad indexing | |
1917 | ||
1918 | else | |
1919 | if Nkind (Parent (N)) = N_Requeue_Statement | |
6e73e3ab | 1920 | and then Present (Pent) and then Ekind (Pent) = E_Entry |
996ae0b0 RK |
1921 | then |
1922 | Error_Msg_N | |
1923 | ("REQUEUE does not permit parameters", First (Exprs)); | |
1924 | ||
1925 | elsif Is_Entity_Name (P) | |
1926 | and then Etype (P) = Standard_Void_Type | |
1927 | then | |
1928 | Error_Msg_NE ("incorrect use of&", P, Entity (P)); | |
1929 | ||
1930 | else | |
1931 | Error_Msg_N ("array type required in indexed component", P); | |
1932 | end if; | |
1933 | ||
1934 | Set_Etype (N, Any_Type); | |
1935 | return; | |
1936 | end if; | |
1937 | ||
1938 | Index := First_Index (Array_Type); | |
996ae0b0 RK |
1939 | while Present (Index) and then Present (Exp) loop |
1940 | if not Has_Compatible_Type (Exp, Etype (Index)) then | |
1941 | Wrong_Type (Exp, Etype (Index)); | |
1942 | Set_Etype (N, Any_Type); | |
1943 | return; | |
1944 | end if; | |
1945 | ||
1946 | Next_Index (Index); | |
1947 | Next (Exp); | |
1948 | end loop; | |
1949 | ||
1950 | Set_Etype (N, Component_Type (Array_Type)); | |
1951 | ||
1952 | if Present (Index) then | |
1953 | Error_Msg_N | |
1954 | ("too few subscripts in array reference", First (Exprs)); | |
1955 | ||
1956 | elsif Present (Exp) then | |
1957 | Error_Msg_N ("too many subscripts in array reference", Exp); | |
1958 | end if; | |
1959 | end if; | |
996ae0b0 RK |
1960 | end Process_Indexed_Component; |
1961 | ||
1962 | ---------------------------------------- | |
1963 | -- Process_Indexed_Component_Or_Slice -- | |
1964 | ---------------------------------------- | |
1965 | ||
1966 | procedure Process_Indexed_Component_Or_Slice is | |
1967 | begin | |
1968 | Exp := First (Exprs); | |
996ae0b0 RK |
1969 | while Present (Exp) loop |
1970 | Analyze_Expression (Exp); | |
1971 | Next (Exp); | |
1972 | end loop; | |
1973 | ||
1974 | Exp := First (Exprs); | |
1975 | ||
1976 | -- If one index is present, and it is a subtype name, then the | |
1977 | -- node denotes a slice (note that the case of an explicit range | |
1978 | -- for a slice was already built as an N_Slice node in the first | |
1979 | -- place, so that case is not handled here). | |
1980 | ||
1981 | -- We use a replace rather than a rewrite here because this is one | |
1982 | -- of the cases in which the tree built by the parser is plain wrong. | |
1983 | ||
1984 | if No (Next (Exp)) | |
1985 | and then Is_Entity_Name (Exp) | |
1986 | and then Is_Type (Entity (Exp)) | |
1987 | then | |
1988 | Replace (N, | |
1989 | Make_Slice (Sloc (N), | |
1990 | Prefix => P, | |
1991 | Discrete_Range => New_Copy (Exp))); | |
1992 | Analyze (N); | |
1993 | ||
1994 | -- Otherwise (more than one index present, or single index is not | |
1995 | -- a subtype name), then we have the indexed component case. | |
1996 | ||
1997 | else | |
1998 | Process_Indexed_Component; | |
1999 | end if; | |
2000 | end Process_Indexed_Component_Or_Slice; | |
2001 | ||
2002 | ------------------------------------------ | |
2003 | -- Process_Overloaded_Indexed_Component -- | |
2004 | ------------------------------------------ | |
2005 | ||
2006 | procedure Process_Overloaded_Indexed_Component is | |
2007 | Exp : Node_Id; | |
2008 | I : Interp_Index; | |
2009 | It : Interp; | |
2010 | Typ : Entity_Id; | |
2011 | Index : Node_Id; | |
2012 | Found : Boolean; | |
2013 | ||
2014 | begin | |
2015 | Set_Etype (N, Any_Type); | |
996ae0b0 | 2016 | |
4c46b835 | 2017 | Get_First_Interp (P, I, It); |
996ae0b0 RK |
2018 | while Present (It.Nam) loop |
2019 | Typ := It.Typ; | |
2020 | ||
2021 | if Is_Access_Type (Typ) then | |
2022 | Typ := Designated_Type (Typ); | |
fbf5a39b | 2023 | Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N); |
996ae0b0 RK |
2024 | end if; |
2025 | ||
2026 | if Is_Array_Type (Typ) then | |
2027 | ||
2028 | -- Got a candidate: verify that index types are compatible | |
2029 | ||
2030 | Index := First_Index (Typ); | |
2031 | Found := True; | |
996ae0b0 | 2032 | Exp := First (Exprs); |
996ae0b0 RK |
2033 | while Present (Index) and then Present (Exp) loop |
2034 | if Has_Compatible_Type (Exp, Etype (Index)) then | |
2035 | null; | |
2036 | else | |
2037 | Found := False; | |
2038 | Remove_Interp (I); | |
2039 | exit; | |
2040 | end if; | |
2041 | ||
2042 | Next_Index (Index); | |
2043 | Next (Exp); | |
2044 | end loop; | |
2045 | ||
2046 | if Found and then No (Index) and then No (Exp) then | |
2047 | Add_One_Interp (N, | |
2048 | Etype (Component_Type (Typ)), | |
2049 | Etype (Component_Type (Typ))); | |
2050 | end if; | |
2051 | end if; | |
2052 | ||
2053 | Get_Next_Interp (I, It); | |
2054 | end loop; | |
2055 | ||
2056 | if Etype (N) = Any_Type then | |
ad6b5b00 | 2057 | Error_Msg_N ("no legal interpretation for indexed component", N); |
996ae0b0 RK |
2058 | Set_Is_Overloaded (N, False); |
2059 | end if; | |
2060 | ||
2061 | End_Interp_List; | |
2062 | end Process_Overloaded_Indexed_Component; | |
2063 | ||
4c46b835 | 2064 | -- Start of processing for Analyze_Indexed_Component_Form |
996ae0b0 RK |
2065 | |
2066 | begin | |
2067 | -- Get name of array, function or type | |
2068 | ||
2069 | Analyze (P); | |
d469eabe HK |
2070 | |
2071 | if Nkind_In (N, N_Function_Call, N_Procedure_Call_Statement) then | |
2072 | ||
fbf5a39b AC |
2073 | -- If P is an explicit dereference whose prefix is of a |
2074 | -- remote access-to-subprogram type, then N has already | |
2075 | -- been rewritten as a subprogram call and analyzed. | |
2076 | ||
2077 | return; | |
2078 | end if; | |
2079 | ||
2080 | pragma Assert (Nkind (N) = N_Indexed_Component); | |
2081 | ||
996ae0b0 RK |
2082 | P_T := Base_Type (Etype (P)); |
2083 | ||
2084 | if Is_Entity_Name (P) | |
2085 | or else Nkind (P) = N_Operator_Symbol | |
2086 | then | |
2087 | U_N := Entity (P); | |
2088 | ||
aab883ec | 2089 | if Is_Type (U_N) then |
996ae0b0 | 2090 | |
4c46b835 | 2091 | -- Reformat node as a type conversion |
996ae0b0 RK |
2092 | |
2093 | E := Remove_Head (Exprs); | |
2094 | ||
2095 | if Present (First (Exprs)) then | |
2096 | Error_Msg_N | |
2097 | ("argument of type conversion must be single expression", N); | |
2098 | end if; | |
2099 | ||
2100 | Change_Node (N, N_Type_Conversion); | |
2101 | Set_Subtype_Mark (N, P); | |
2102 | Set_Etype (N, U_N); | |
2103 | Set_Expression (N, E); | |
2104 | ||
2105 | -- After changing the node, call for the specific Analysis | |
2106 | -- routine directly, to avoid a double call to the expander. | |
2107 | ||
2108 | Analyze_Type_Conversion (N); | |
2109 | return; | |
2110 | end if; | |
2111 | ||
2112 | if Is_Overloadable (U_N) then | |
2113 | Process_Function_Call; | |
2114 | ||
2115 | elsif Ekind (Etype (P)) = E_Subprogram_Type | |
2116 | or else (Is_Access_Type (Etype (P)) | |
2117 | and then | |
bce79204 AC |
2118 | Ekind (Designated_Type (Etype (P))) = |
2119 | E_Subprogram_Type) | |
996ae0b0 RK |
2120 | then |
2121 | -- Call to access_to-subprogram with possible implicit dereference | |
2122 | ||
2123 | Process_Function_Call; | |
2124 | ||
fbf5a39b AC |
2125 | elsif Is_Generic_Subprogram (U_N) then |
2126 | ||
4c46b835 | 2127 | -- A common beginner's (or C++ templates fan) error |
996ae0b0 RK |
2128 | |
2129 | Error_Msg_N ("generic subprogram cannot be called", N); | |
2130 | Set_Etype (N, Any_Type); | |
2131 | return; | |
2132 | ||
2133 | else | |
2134 | Process_Indexed_Component_Or_Slice; | |
2135 | end if; | |
2136 | ||
2137 | -- If not an entity name, prefix is an expression that may denote | |
2138 | -- an array or an access-to-subprogram. | |
2139 | ||
2140 | else | |
fbf5a39b | 2141 | if Ekind (P_T) = E_Subprogram_Type |
996ae0b0 RK |
2142 | or else (Is_Access_Type (P_T) |
2143 | and then | |
bce79204 | 2144 | Ekind (Designated_Type (P_T)) = E_Subprogram_Type) |
996ae0b0 RK |
2145 | then |
2146 | Process_Function_Call; | |
2147 | ||
2148 | elsif Nkind (P) = N_Selected_Component | |
ffe9aba8 | 2149 | and then Is_Overloadable (Entity (Selector_Name (P))) |
996ae0b0 RK |
2150 | then |
2151 | Process_Function_Call; | |
2152 | ||
2153 | else | |
2154 | -- Indexed component, slice, or a call to a member of a family | |
2155 | -- entry, which will be converted to an entry call later. | |
fbf5a39b | 2156 | |
996ae0b0 RK |
2157 | Process_Indexed_Component_Or_Slice; |
2158 | end if; | |
2159 | end if; | |
2160 | end Analyze_Indexed_Component_Form; | |
2161 | ||
2162 | ------------------------ | |
2163 | -- Analyze_Logical_Op -- | |
2164 | ------------------------ | |
2165 | ||
2166 | procedure Analyze_Logical_Op (N : Node_Id) is | |
2167 | L : constant Node_Id := Left_Opnd (N); | |
2168 | R : constant Node_Id := Right_Opnd (N); | |
2169 | Op_Id : Entity_Id := Entity (N); | |
2170 | ||
2171 | begin | |
2172 | Set_Etype (N, Any_Type); | |
2173 | Candidate_Type := Empty; | |
2174 | ||
2175 | Analyze_Expression (L); | |
2176 | Analyze_Expression (R); | |
2177 | ||
2178 | if Present (Op_Id) then | |
2179 | ||
2180 | if Ekind (Op_Id) = E_Operator then | |
2181 | Find_Boolean_Types (L, R, Op_Id, N); | |
2182 | else | |
2183 | Add_One_Interp (N, Op_Id, Etype (Op_Id)); | |
2184 | end if; | |
2185 | ||
2186 | else | |
2187 | Op_Id := Get_Name_Entity_Id (Chars (N)); | |
996ae0b0 RK |
2188 | while Present (Op_Id) loop |
2189 | if Ekind (Op_Id) = E_Operator then | |
2190 | Find_Boolean_Types (L, R, Op_Id, N); | |
2191 | else | |
2192 | Analyze_User_Defined_Binary_Op (N, Op_Id); | |
2193 | end if; | |
2194 | ||
2195 | Op_Id := Homonym (Op_Id); | |
2196 | end loop; | |
2197 | end if; | |
2198 | ||
2199 | Operator_Check (N); | |
2200 | end Analyze_Logical_Op; | |
2201 | ||
2202 | --------------------------- | |
2203 | -- Analyze_Membership_Op -- | |
2204 | --------------------------- | |
2205 | ||
2206 | procedure Analyze_Membership_Op (N : Node_Id) is | |
2207 | L : constant Node_Id := Left_Opnd (N); | |
2208 | R : constant Node_Id := Right_Opnd (N); | |
2209 | ||
2210 | Index : Interp_Index; | |
2211 | It : Interp; | |
2212 | Found : Boolean := False; | |
2213 | I_F : Interp_Index; | |
2214 | T_F : Entity_Id; | |
2215 | ||
2216 | procedure Try_One_Interp (T1 : Entity_Id); | |
2217 | -- Routine to try one proposed interpretation. Note that the context | |
2218 | -- of the operation plays no role in resolving the arguments, so that | |
2219 | -- if there is more than one interpretation of the operands that is | |
2220 | -- compatible with a membership test, the operation is ambiguous. | |
2221 | ||
4c46b835 AC |
2222 | -------------------- |
2223 | -- Try_One_Interp -- | |
2224 | -------------------- | |
2225 | ||
996ae0b0 RK |
2226 | procedure Try_One_Interp (T1 : Entity_Id) is |
2227 | begin | |
2228 | if Has_Compatible_Type (R, T1) then | |
2229 | if Found | |
2230 | and then Base_Type (T1) /= Base_Type (T_F) | |
2231 | then | |
2232 | It := Disambiguate (L, I_F, Index, Any_Type); | |
2233 | ||
2234 | if It = No_Interp then | |
2235 | Ambiguous_Operands (N); | |
2236 | Set_Etype (L, Any_Type); | |
2237 | return; | |
2238 | ||
2239 | else | |
2240 | T_F := It.Typ; | |
2241 | end if; | |
2242 | ||
2243 | else | |
2244 | Found := True; | |
2245 | T_F := T1; | |
2246 | I_F := Index; | |
2247 | end if; | |
2248 | ||
2249 | Set_Etype (L, T_F); | |
2250 | end if; | |
996ae0b0 RK |
2251 | end Try_One_Interp; |
2252 | ||
197e4514 AC |
2253 | procedure Analyze_Set_Membership; |
2254 | -- If a set of alternatives is present, analyze each and find the | |
2255 | -- common type to which they must all resolve. | |
2256 | ||
2257 | ---------------------------- | |
2258 | -- Analyze_Set_Membership -- | |
2259 | ---------------------------- | |
2260 | ||
2261 | procedure Analyze_Set_Membership is | |
2262 | Alt : Node_Id; | |
2263 | Index : Interp_Index; | |
2264 | It : Interp; | |
197e4514 AC |
2265 | Candidate_Interps : Node_Id; |
2266 | Common_Type : Entity_Id := Empty; | |
2267 | ||
2268 | begin | |
2269 | Analyze (L); | |
2270 | Candidate_Interps := L; | |
2271 | ||
2272 | if not Is_Overloaded (L) then | |
2273 | Common_Type := Etype (L); | |
2274 | ||
2275 | Alt := First (Alternatives (N)); | |
2276 | while Present (Alt) loop | |
2277 | Analyze (Alt); | |
2278 | ||
2279 | if not Has_Compatible_Type (Alt, Common_Type) then | |
2280 | Wrong_Type (Alt, Common_Type); | |
2281 | end if; | |
2282 | ||
2283 | Next (Alt); | |
2284 | end loop; | |
2285 | ||
2286 | else | |
2287 | Alt := First (Alternatives (N)); | |
2288 | while Present (Alt) loop | |
2289 | Analyze (Alt); | |
2290 | if not Is_Overloaded (Alt) then | |
2291 | Common_Type := Etype (Alt); | |
2292 | ||
2293 | else | |
2294 | Get_First_Interp (Alt, Index, It); | |
2295 | while Present (It.Typ) loop | |
442c0581 RD |
2296 | if not |
2297 | Has_Compatible_Type (Candidate_Interps, It.Typ) | |
197e4514 AC |
2298 | then |
2299 | Remove_Interp (Index); | |
2300 | end if; | |
442c0581 | 2301 | |
197e4514 AC |
2302 | Get_Next_Interp (Index, It); |
2303 | end loop; | |
2304 | ||
2305 | Get_First_Interp (Alt, Index, It); | |
442c0581 | 2306 | |
197e4514 AC |
2307 | if No (It.Typ) then |
2308 | Error_Msg_N ("alternative has no legal type", Alt); | |
2309 | return; | |
2310 | end if; | |
2311 | ||
442c0581 RD |
2312 | -- If alternative is not overloaded, we have a unique type |
2313 | -- for all of them. | |
197e4514 AC |
2314 | |
2315 | Set_Etype (Alt, It.Typ); | |
2316 | Get_Next_Interp (Index, It); | |
2317 | ||
2318 | if No (It.Typ) then | |
2319 | Set_Is_Overloaded (Alt, False); | |
2320 | Common_Type := Etype (Alt); | |
2321 | end if; | |
2322 | ||
2323 | Candidate_Interps := Alt; | |
2324 | end if; | |
2325 | ||
2326 | Next (Alt); | |
2327 | end loop; | |
2328 | end if; | |
2329 | ||
2330 | Set_Etype (N, Standard_Boolean); | |
2331 | ||
2332 | if Present (Common_Type) then | |
2333 | Set_Etype (L, Common_Type); | |
2334 | Set_Is_Overloaded (L, False); | |
2335 | ||
2336 | else | |
2337 | Error_Msg_N ("cannot resolve membership operation", N); | |
2338 | end if; | |
2339 | end Analyze_Set_Membership; | |
2340 | ||
996ae0b0 RK |
2341 | -- Start of processing for Analyze_Membership_Op |
2342 | ||
2343 | begin | |
2344 | Analyze_Expression (L); | |
2345 | ||
197e4514 | 2346 | if No (R) |
0eed45bb | 2347 | and then Ada_Version >= Ada_12 |
197e4514 AC |
2348 | then |
2349 | Analyze_Set_Membership; | |
2350 | return; | |
2351 | end if; | |
2352 | ||
996ae0b0 RK |
2353 | if Nkind (R) = N_Range |
2354 | or else (Nkind (R) = N_Attribute_Reference | |
2355 | and then Attribute_Name (R) = Name_Range) | |
2356 | then | |
2357 | Analyze (R); | |
2358 | ||
2359 | if not Is_Overloaded (L) then | |
2360 | Try_One_Interp (Etype (L)); | |
2361 | ||
2362 | else | |
2363 | Get_First_Interp (L, Index, It); | |
996ae0b0 RK |
2364 | while Present (It.Typ) loop |
2365 | Try_One_Interp (It.Typ); | |
2366 | Get_Next_Interp (Index, It); | |
2367 | end loop; | |
2368 | end if; | |
2369 | ||
2370 | -- If not a range, it can only be a subtype mark, or else there | |
2371 | -- is a more basic error, to be diagnosed in Find_Type. | |
2372 | ||
2373 | else | |
2374 | Find_Type (R); | |
2375 | ||
2376 | if Is_Entity_Name (R) then | |
2377 | Check_Fully_Declared (Entity (R), R); | |
2378 | end if; | |
2379 | end if; | |
2380 | ||
2381 | -- Compatibility between expression and subtype mark or range is | |
2382 | -- checked during resolution. The result of the operation is Boolean | |
2383 | -- in any case. | |
2384 | ||
2385 | Set_Etype (N, Standard_Boolean); | |
fe45e59e ES |
2386 | |
2387 | if Comes_From_Source (N) | |
197e4514 | 2388 | and then Present (Right_Opnd (N)) |
fe45e59e ES |
2389 | and then Is_CPP_Class (Etype (Etype (Right_Opnd (N)))) |
2390 | then | |
2391 | Error_Msg_N ("membership test not applicable to cpp-class types", N); | |
2392 | end if; | |
996ae0b0 RK |
2393 | end Analyze_Membership_Op; |
2394 | ||
2395 | ---------------------- | |
2396 | -- Analyze_Negation -- | |
2397 | ---------------------- | |
2398 | ||
2399 | procedure Analyze_Negation (N : Node_Id) is | |
2400 | R : constant Node_Id := Right_Opnd (N); | |
2401 | Op_Id : Entity_Id := Entity (N); | |
2402 | ||
2403 | begin | |
2404 | Set_Etype (N, Any_Type); | |
2405 | Candidate_Type := Empty; | |
2406 | ||
2407 | Analyze_Expression (R); | |
2408 | ||
2409 | if Present (Op_Id) then | |
2410 | if Ekind (Op_Id) = E_Operator then | |
2411 | Find_Negation_Types (R, Op_Id, N); | |
2412 | else | |
2413 | Add_One_Interp (N, Op_Id, Etype (Op_Id)); | |
2414 | end if; | |
2415 | ||
2416 | else | |
2417 | Op_Id := Get_Name_Entity_Id (Chars (N)); | |
996ae0b0 RK |
2418 | while Present (Op_Id) loop |
2419 | if Ekind (Op_Id) = E_Operator then | |
2420 | Find_Negation_Types (R, Op_Id, N); | |
2421 | else | |
2422 | Analyze_User_Defined_Unary_Op (N, Op_Id); | |
2423 | end if; | |
2424 | ||
2425 | Op_Id := Homonym (Op_Id); | |
2426 | end loop; | |
2427 | end if; | |
2428 | ||
2429 | Operator_Check (N); | |
2430 | end Analyze_Negation; | |
2431 | ||
15ce9ca2 AC |
2432 | ------------------ |
2433 | -- Analyze_Null -- | |
2434 | ------------------ | |
996ae0b0 RK |
2435 | |
2436 | procedure Analyze_Null (N : Node_Id) is | |
2437 | begin | |
2438 | Set_Etype (N, Any_Access); | |
2439 | end Analyze_Null; | |
2440 | ||
2441 | ---------------------- | |
2442 | -- Analyze_One_Call -- | |
2443 | ---------------------- | |
2444 | ||
2445 | procedure Analyze_One_Call | |
ec6078e3 ES |
2446 | (N : Node_Id; |
2447 | Nam : Entity_Id; | |
2448 | Report : Boolean; | |
2449 | Success : out Boolean; | |
2450 | Skip_First : Boolean := False) | |
996ae0b0 | 2451 | is |
d469eabe HK |
2452 | Actuals : constant List_Id := Parameter_Associations (N); |
2453 | Prev_T : constant Entity_Id := Etype (N); | |
2454 | ||
aab883ec ES |
2455 | Must_Skip : constant Boolean := Skip_First |
2456 | or else Nkind (Original_Node (N)) = N_Selected_Component | |
2457 | or else | |
2458 | (Nkind (Original_Node (N)) = N_Indexed_Component | |
2459 | and then Nkind (Prefix (Original_Node (N))) | |
2460 | = N_Selected_Component); | |
2461 | -- The first formal must be omitted from the match when trying to find | |
2462 | -- a primitive operation that is a possible interpretation, and also | |
2463 | -- after the call has been rewritten, because the corresponding actual | |
2464 | -- is already known to be compatible, and because this may be an | |
2465 | -- indexing of a call with default parameters. | |
2466 | ||
53cf4600 ES |
2467 | Formal : Entity_Id; |
2468 | Actual : Node_Id; | |
2469 | Is_Indexed : Boolean := False; | |
2470 | Is_Indirect : Boolean := False; | |
2471 | Subp_Type : constant Entity_Id := Etype (Nam); | |
2472 | Norm_OK : Boolean; | |
996ae0b0 | 2473 | |
157a9bf5 ES |
2474 | function Operator_Hidden_By (Fun : Entity_Id) return Boolean; |
2475 | -- There may be a user-defined operator that hides the current | |
2476 | -- interpretation. We must check for this independently of the | |
2477 | -- analysis of the call with the user-defined operation, because | |
2478 | -- the parameter names may be wrong and yet the hiding takes place. | |
2479 | -- This fixes a problem with ACATS test B34014O. | |
2480 | -- | |
2481 | -- When the type Address is a visible integer type, and the DEC | |
2482 | -- system extension is visible, the predefined operator may be | |
2483 | -- hidden as well, by one of the address operations in auxdec. | |
2484 | -- Finally, The abstract operations on address do not hide the | |
2485 | -- predefined operator (this is the purpose of making them abstract). | |
2486 | ||
fbf5a39b | 2487 | procedure Indicate_Name_And_Type; |
996ae0b0 RK |
2488 | -- If candidate interpretation matches, indicate name and type of |
2489 | -- result on call node. | |
2490 | ||
fbf5a39b AC |
2491 | ---------------------------- |
2492 | -- Indicate_Name_And_Type -- | |
2493 | ---------------------------- | |
996ae0b0 | 2494 | |
fbf5a39b | 2495 | procedure Indicate_Name_And_Type is |
996ae0b0 RK |
2496 | begin |
2497 | Add_One_Interp (N, Nam, Etype (Nam)); | |
2498 | Success := True; | |
2499 | ||
2500 | -- If the prefix of the call is a name, indicate the entity | |
2501 | -- being called. If it is not a name, it is an expression that | |
2502 | -- denotes an access to subprogram or else an entry or family. In | |
2503 | -- the latter case, the name is a selected component, and the entity | |
2504 | -- being called is noted on the selector. | |
2505 | ||
2506 | if not Is_Type (Nam) then | |
2507 | if Is_Entity_Name (Name (N)) | |
2508 | or else Nkind (Name (N)) = N_Operator_Symbol | |
2509 | then | |
2510 | Set_Entity (Name (N), Nam); | |
2511 | ||
2512 | elsif Nkind (Name (N)) = N_Selected_Component then | |
2513 | Set_Entity (Selector_Name (Name (N)), Nam); | |
2514 | end if; | |
2515 | end if; | |
2516 | ||
2517 | if Debug_Flag_E and not Report then | |
2518 | Write_Str (" Overloaded call "); | |
2519 | Write_Int (Int (N)); | |
2520 | Write_Str (" compatible with "); | |
2521 | Write_Int (Int (Nam)); | |
2522 | Write_Eol; | |
2523 | end if; | |
fbf5a39b | 2524 | end Indicate_Name_And_Type; |
996ae0b0 | 2525 | |
157a9bf5 ES |
2526 | ------------------------ |
2527 | -- Operator_Hidden_By -- | |
2528 | ------------------------ | |
2529 | ||
2530 | function Operator_Hidden_By (Fun : Entity_Id) return Boolean is | |
2531 | Act1 : constant Node_Id := First_Actual (N); | |
2532 | Act2 : constant Node_Id := Next_Actual (Act1); | |
2533 | Form1 : constant Entity_Id := First_Formal (Fun); | |
2534 | Form2 : constant Entity_Id := Next_Formal (Form1); | |
2535 | ||
2536 | begin | |
2537 | if Ekind (Fun) /= E_Function | |
2538 | or else Is_Abstract_Subprogram (Fun) | |
2539 | then | |
2540 | return False; | |
2541 | ||
2542 | elsif not Has_Compatible_Type (Act1, Etype (Form1)) then | |
2543 | return False; | |
2544 | ||
2545 | elsif Present (Form2) then | |
2546 | if | |
2547 | No (Act2) or else not Has_Compatible_Type (Act2, Etype (Form2)) | |
2548 | then | |
2549 | return False; | |
2550 | end if; | |
2551 | ||
2552 | elsif Present (Act2) then | |
2553 | return False; | |
2554 | end if; | |
2555 | ||
2556 | -- Now we know that the arity of the operator matches the function, | |
2557 | -- and the function call is a valid interpretation. The function | |
2558 | -- hides the operator if it has the right signature, or if one of | |
2559 | -- its operands is a non-abstract operation on Address when this is | |
2560 | -- a visible integer type. | |
2561 | ||
2562 | return Hides_Op (Fun, Nam) | |
2563 | or else Is_Descendent_Of_Address (Etype (Form1)) | |
2564 | or else | |
2565 | (Present (Form2) | |
2566 | and then Is_Descendent_Of_Address (Etype (Form2))); | |
2567 | end Operator_Hidden_By; | |
2568 | ||
996ae0b0 RK |
2569 | -- Start of processing for Analyze_One_Call |
2570 | ||
2571 | begin | |
2572 | Success := False; | |
2573 | ||
157a9bf5 ES |
2574 | -- If the subprogram has no formals or if all the formals have defaults, |
2575 | -- and the return type is an array type, the node may denote an indexing | |
2576 | -- of the result of a parameterless call. In Ada 2005, the subprogram | |
2577 | -- may have one non-defaulted formal, and the call may have been written | |
2578 | -- in prefix notation, so that the rebuilt parameter list has more than | |
2579 | -- one actual. | |
996ae0b0 | 2580 | |
53cf4600 ES |
2581 | if not Is_Overloadable (Nam) |
2582 | and then Ekind (Nam) /= E_Subprogram_Type | |
2583 | and then Ekind (Nam) /= E_Entry_Family | |
2584 | then | |
2585 | return; | |
2586 | end if; | |
2587 | ||
8f2eeab7 | 2588 | -- An indexing requires at least one actual |
e1f3cb58 AC |
2589 | |
2590 | if not Is_Empty_List (Actuals) | |
aab883ec ES |
2591 | and then |
2592 | (Needs_No_Actuals (Nam) | |
2593 | or else | |
2594 | (Needs_One_Actual (Nam) | |
2595 | and then Present (Next_Actual (First (Actuals))))) | |
996ae0b0 RK |
2596 | then |
2597 | if Is_Array_Type (Subp_Type) then | |
aab883ec | 2598 | Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip); |
996ae0b0 RK |
2599 | |
2600 | elsif Is_Access_Type (Subp_Type) | |
2601 | and then Is_Array_Type (Designated_Type (Subp_Type)) | |
2602 | then | |
2603 | Is_Indexed := | |
aab883ec ES |
2604 | Try_Indexed_Call |
2605 | (N, Nam, Designated_Type (Subp_Type), Must_Skip); | |
996ae0b0 | 2606 | |
758c442c | 2607 | -- The prefix can also be a parameterless function that returns an |
f3d57416 | 2608 | -- access to subprogram, in which case this is an indirect call. |
53cf4600 ES |
2609 | -- If this succeeds, an explicit dereference is added later on, |
2610 | -- in Analyze_Call or Resolve_Call. | |
758c442c | 2611 | |
996ae0b0 | 2612 | elsif Is_Access_Type (Subp_Type) |
401093c1 | 2613 | and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type |
996ae0b0 | 2614 | then |
53cf4600 | 2615 | Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type); |
996ae0b0 RK |
2616 | end if; |
2617 | ||
2618 | end if; | |
2619 | ||
5ff22245 | 2620 | -- If the call has been transformed into a slice, it is of the form |
30783513 | 2621 | -- F (Subtype) where F is parameterless. The node has been rewritten in |
5ff22245 ES |
2622 | -- Try_Indexed_Call and there is nothing else to do. |
2623 | ||
2624 | if Is_Indexed | |
2625 | and then Nkind (N) = N_Slice | |
2626 | then | |
2627 | return; | |
2628 | end if; | |
2629 | ||
53cf4600 ES |
2630 | Normalize_Actuals |
2631 | (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK); | |
996ae0b0 RK |
2632 | |
2633 | if not Norm_OK then | |
2634 | ||
53cf4600 ES |
2635 | -- If an indirect call is a possible interpretation, indicate |
2636 | -- success to the caller. | |
2637 | ||
2638 | if Is_Indirect then | |
2639 | Success := True; | |
2640 | return; | |
2641 | ||
996ae0b0 RK |
2642 | -- Mismatch in number or names of parameters |
2643 | ||
53cf4600 | 2644 | elsif Debug_Flag_E then |
996ae0b0 RK |
2645 | Write_Str (" normalization fails in call "); |
2646 | Write_Int (Int (N)); | |
2647 | Write_Str (" with subprogram "); | |
2648 | Write_Int (Int (Nam)); | |
2649 | Write_Eol; | |
2650 | end if; | |
2651 | ||
2652 | -- If the context expects a function call, discard any interpretation | |
2653 | -- that is a procedure. If the node is not overloaded, leave as is for | |
2654 | -- better error reporting when type mismatch is found. | |
2655 | ||
2656 | elsif Nkind (N) = N_Function_Call | |
2657 | and then Is_Overloaded (Name (N)) | |
2658 | and then Ekind (Nam) = E_Procedure | |
2659 | then | |
2660 | return; | |
2661 | ||
4c46b835 | 2662 | -- Ditto for function calls in a procedure context |
996ae0b0 RK |
2663 | |
2664 | elsif Nkind (N) = N_Procedure_Call_Statement | |
2665 | and then Is_Overloaded (Name (N)) | |
2666 | and then Etype (Nam) /= Standard_Void_Type | |
2667 | then | |
2668 | return; | |
2669 | ||
fe45e59e | 2670 | elsif No (Actuals) then |
996ae0b0 RK |
2671 | |
2672 | -- If Normalize succeeds, then there are default parameters for | |
2673 | -- all formals. | |
2674 | ||
fbf5a39b | 2675 | Indicate_Name_And_Type; |
996ae0b0 RK |
2676 | |
2677 | elsif Ekind (Nam) = E_Operator then | |
996ae0b0 RK |
2678 | if Nkind (N) = N_Procedure_Call_Statement then |
2679 | return; | |
2680 | end if; | |
2681 | ||
2682 | -- This can occur when the prefix of the call is an operator | |
2683 | -- name or an expanded name whose selector is an operator name. | |
2684 | ||
2685 | Analyze_Operator_Call (N, Nam); | |
2686 | ||
2687 | if Etype (N) /= Prev_T then | |
2688 | ||
157a9bf5 | 2689 | -- Check that operator is not hidden by a function interpretation |
996ae0b0 RK |
2690 | |
2691 | if Is_Overloaded (Name (N)) then | |
2692 | declare | |
2693 | I : Interp_Index; | |
2694 | It : Interp; | |
2695 | ||
2696 | begin | |
2697 | Get_First_Interp (Name (N), I, It); | |
996ae0b0 | 2698 | while Present (It.Nam) loop |
157a9bf5 | 2699 | if Operator_Hidden_By (It.Nam) then |
996ae0b0 RK |
2700 | Set_Etype (N, Prev_T); |
2701 | return; | |
2702 | end if; | |
2703 | ||
2704 | Get_Next_Interp (I, It); | |
2705 | end loop; | |
2706 | end; | |
2707 | end if; | |
2708 | ||
2709 | -- If operator matches formals, record its name on the call. | |
2710 | -- If the operator is overloaded, Resolve will select the | |
2711 | -- correct one from the list of interpretations. The call | |
2712 | -- node itself carries the first candidate. | |
2713 | ||
2714 | Set_Entity (Name (N), Nam); | |
2715 | Success := True; | |
2716 | ||
2717 | elsif Report and then Etype (N) = Any_Type then | |
2718 | Error_Msg_N ("incompatible arguments for operator", N); | |
2719 | end if; | |
2720 | ||
2721 | else | |
2722 | -- Normalize_Actuals has chained the named associations in the | |
2723 | -- correct order of the formals. | |
2724 | ||
2725 | Actual := First_Actual (N); | |
2726 | Formal := First_Formal (Nam); | |
ec6078e3 ES |
2727 | |
2728 | -- If we are analyzing a call rewritten from object notation, | |
2729 | -- skip first actual, which may be rewritten later as an | |
2730 | -- explicit dereference. | |
2731 | ||
aab883ec | 2732 | if Must_Skip then |
ec6078e3 ES |
2733 | Next_Actual (Actual); |
2734 | Next_Formal (Formal); | |
2735 | end if; | |
2736 | ||
996ae0b0 | 2737 | while Present (Actual) and then Present (Formal) loop |
fbf5a39b AC |
2738 | if Nkind (Parent (Actual)) /= N_Parameter_Association |
2739 | or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal) | |
996ae0b0 | 2740 | then |
9c510803 ES |
2741 | -- The actual can be compatible with the formal, but we must |
2742 | -- also check that the context is not an address type that is | |
2743 | -- visibly an integer type, as is the case in VMS_64. In this | |
2744 | -- case the use of literals is illegal, except in the body of | |
2745 | -- descendents of system, where arithmetic operations on | |
2746 | -- address are of course used. | |
2747 | ||
2748 | if Has_Compatible_Type (Actual, Etype (Formal)) | |
2749 | and then | |
2750 | (Etype (Actual) /= Universal_Integer | |
2751 | or else not Is_Descendent_Of_Address (Etype (Formal)) | |
2752 | or else | |
2753 | Is_Predefined_File_Name | |
2754 | (Unit_File_Name (Get_Source_Unit (N)))) | |
2755 | then | |
996ae0b0 RK |
2756 | Next_Actual (Actual); |
2757 | Next_Formal (Formal); | |
2758 | ||
2759 | else | |
2760 | if Debug_Flag_E then | |
2761 | Write_Str (" type checking fails in call "); | |
2762 | Write_Int (Int (N)); | |
2763 | Write_Str (" with formal "); | |
2764 | Write_Int (Int (Formal)); | |
2765 | Write_Str (" in subprogram "); | |
2766 | Write_Int (Int (Nam)); | |
2767 | Write_Eol; | |
2768 | end if; | |
2769 | ||
53cf4600 | 2770 | if Report and not Is_Indexed and not Is_Indirect then |
758c442c GD |
2771 | |
2772 | -- Ada 2005 (AI-251): Complete the error notification | |
8f2eeab7 | 2773 | -- to help new Ada 2005 users. |
758c442c GD |
2774 | |
2775 | if Is_Class_Wide_Type (Etype (Formal)) | |
2776 | and then Is_Interface (Etype (Etype (Formal))) | |
2777 | and then not Interface_Present_In_Ancestor | |
2778 | (Typ => Etype (Actual), | |
2779 | Iface => Etype (Etype (Formal))) | |
2780 | then | |
758c442c | 2781 | Error_Msg_NE |
ec6078e3 | 2782 | ("(Ada 2005) does not implement interface }", |
758c442c GD |
2783 | Actual, Etype (Etype (Formal))); |
2784 | end if; | |
2785 | ||
996ae0b0 RK |
2786 | Wrong_Type (Actual, Etype (Formal)); |
2787 | ||
2788 | if Nkind (Actual) = N_Op_Eq | |
2789 | and then Nkind (Left_Opnd (Actual)) = N_Identifier | |
2790 | then | |
2791 | Formal := First_Formal (Nam); | |
996ae0b0 | 2792 | while Present (Formal) loop |
996ae0b0 | 2793 | if Chars (Left_Opnd (Actual)) = Chars (Formal) then |
4e7a4f6e | 2794 | Error_Msg_N -- CODEFIX |
fbf5a39b | 2795 | ("possible misspelling of `='>`!", Actual); |
996ae0b0 RK |
2796 | exit; |
2797 | end if; | |
2798 | ||
2799 | Next_Formal (Formal); | |
2800 | end loop; | |
2801 | end if; | |
2802 | ||
2803 | if All_Errors_Mode then | |
2804 | Error_Msg_Sloc := Sloc (Nam); | |
2805 | ||
2806 | if Is_Overloadable (Nam) | |
2807 | and then Present (Alias (Nam)) | |
2808 | and then not Comes_From_Source (Nam) | |
2809 | then | |
2810 | Error_Msg_NE | |
401093c1 ES |
2811 | ("\\ =='> in call to inherited operation & #!", |
2812 | Actual, Nam); | |
7324bf49 AC |
2813 | |
2814 | elsif Ekind (Nam) = E_Subprogram_Type then | |
2815 | declare | |
2816 | Access_To_Subprogram_Typ : | |
2817 | constant Entity_Id := | |
2818 | Defining_Identifier | |
2819 | (Associated_Node_For_Itype (Nam)); | |
2820 | begin | |
2821 | Error_Msg_NE ( | |
401093c1 | 2822 | "\\ =='> in call to dereference of &#!", |
7324bf49 AC |
2823 | Actual, Access_To_Subprogram_Typ); |
2824 | end; | |
2825 | ||
996ae0b0 | 2826 | else |
401093c1 ES |
2827 | Error_Msg_NE |
2828 | ("\\ =='> in call to &#!", Actual, Nam); | |
7324bf49 | 2829 | |
996ae0b0 RK |
2830 | end if; |
2831 | end if; | |
2832 | end if; | |
2833 | ||
2834 | return; | |
2835 | end if; | |
2836 | ||
2837 | else | |
2838 | -- Normalize_Actuals has verified that a default value exists | |
2839 | -- for this formal. Current actual names a subsequent formal. | |
2840 | ||
2841 | Next_Formal (Formal); | |
2842 | end if; | |
2843 | end loop; | |
2844 | ||
4c46b835 | 2845 | -- On exit, all actuals match |
996ae0b0 | 2846 | |
fbf5a39b | 2847 | Indicate_Name_And_Type; |
996ae0b0 RK |
2848 | end if; |
2849 | end Analyze_One_Call; | |
2850 | ||
15ce9ca2 AC |
2851 | --------------------------- |
2852 | -- Analyze_Operator_Call -- | |
2853 | --------------------------- | |
996ae0b0 RK |
2854 | |
2855 | procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is | |
2856 | Op_Name : constant Name_Id := Chars (Op_Id); | |
2857 | Act1 : constant Node_Id := First_Actual (N); | |
2858 | Act2 : constant Node_Id := Next_Actual (Act1); | |
2859 | ||
2860 | begin | |
4c46b835 AC |
2861 | -- Binary operator case |
2862 | ||
996ae0b0 RK |
2863 | if Present (Act2) then |
2864 | ||
4c46b835 | 2865 | -- If more than two operands, then not binary operator after all |
996ae0b0 RK |
2866 | |
2867 | if Present (Next_Actual (Act2)) then | |
996ae0b0 RK |
2868 | return; |
2869 | ||
2870 | elsif Op_Name = Name_Op_Add | |
2871 | or else Op_Name = Name_Op_Subtract | |
2872 | or else Op_Name = Name_Op_Multiply | |
2873 | or else Op_Name = Name_Op_Divide | |
2874 | or else Op_Name = Name_Op_Mod | |
2875 | or else Op_Name = Name_Op_Rem | |
2876 | or else Op_Name = Name_Op_Expon | |
2877 | then | |
2878 | Find_Arithmetic_Types (Act1, Act2, Op_Id, N); | |
2879 | ||
2880 | elsif Op_Name = Name_Op_And | |
2881 | or else Op_Name = Name_Op_Or | |
2882 | or else Op_Name = Name_Op_Xor | |
2883 | then | |
2884 | Find_Boolean_Types (Act1, Act2, Op_Id, N); | |
2885 | ||
2886 | elsif Op_Name = Name_Op_Lt | |
2887 | or else Op_Name = Name_Op_Le | |
2888 | or else Op_Name = Name_Op_Gt | |
2889 | or else Op_Name = Name_Op_Ge | |
2890 | then | |
2891 | Find_Comparison_Types (Act1, Act2, Op_Id, N); | |
2892 | ||
2893 | elsif Op_Name = Name_Op_Eq | |
2894 | or else Op_Name = Name_Op_Ne | |
2895 | then | |
2896 | Find_Equality_Types (Act1, Act2, Op_Id, N); | |
2897 | ||
2898 | elsif Op_Name = Name_Op_Concat then | |
2899 | Find_Concatenation_Types (Act1, Act2, Op_Id, N); | |
2900 | ||
2901 | -- Is this else null correct, or should it be an abort??? | |
2902 | ||
2903 | else | |
2904 | null; | |
2905 | end if; | |
2906 | ||
4c46b835 | 2907 | -- Unary operator case |
996ae0b0 | 2908 | |
4c46b835 | 2909 | else |
996ae0b0 RK |
2910 | if Op_Name = Name_Op_Subtract or else |
2911 | Op_Name = Name_Op_Add or else | |
2912 | Op_Name = Name_Op_Abs | |
2913 | then | |
2914 | Find_Unary_Types (Act1, Op_Id, N); | |
2915 | ||
2916 | elsif | |
2917 | Op_Name = Name_Op_Not | |
2918 | then | |
2919 | Find_Negation_Types (Act1, Op_Id, N); | |
2920 | ||
2921 | -- Is this else null correct, or should it be an abort??? | |
2922 | ||
2923 | else | |
2924 | null; | |
2925 | end if; | |
2926 | end if; | |
2927 | end Analyze_Operator_Call; | |
2928 | ||
2929 | ------------------------------------------- | |
2930 | -- Analyze_Overloaded_Selected_Component -- | |
2931 | ------------------------------------------- | |
2932 | ||
2933 | procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is | |
fbf5a39b AC |
2934 | Nam : constant Node_Id := Prefix (N); |
2935 | Sel : constant Node_Id := Selector_Name (N); | |
996ae0b0 | 2936 | Comp : Entity_Id; |
996ae0b0 RK |
2937 | I : Interp_Index; |
2938 | It : Interp; | |
2939 | T : Entity_Id; | |
2940 | ||
2941 | begin | |
4c46b835 | 2942 | Set_Etype (Sel, Any_Type); |
996ae0b0 | 2943 | |
4c46b835 | 2944 | Get_First_Interp (Nam, I, It); |
996ae0b0 RK |
2945 | while Present (It.Typ) loop |
2946 | if Is_Access_Type (It.Typ) then | |
2947 | T := Designated_Type (It.Typ); | |
fbf5a39b | 2948 | Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N); |
996ae0b0 RK |
2949 | else |
2950 | T := It.Typ; | |
2951 | end if; | |
2952 | ||
2953 | if Is_Record_Type (T) then | |
d469eabe HK |
2954 | |
2955 | -- If the prefix is a class-wide type, the visible components are | |
2956 | -- those of the base type. | |
2957 | ||
2958 | if Is_Class_Wide_Type (T) then | |
2959 | T := Etype (T); | |
2960 | end if; | |
2961 | ||
996ae0b0 | 2962 | Comp := First_Entity (T); |
996ae0b0 | 2963 | while Present (Comp) loop |
996ae0b0 RK |
2964 | if Chars (Comp) = Chars (Sel) |
2965 | and then Is_Visible_Component (Comp) | |
2966 | then | |
996ae0b0 | 2967 | |
f16d05d9 AC |
2968 | -- AI05-105: if the context is an object renaming with |
2969 | -- an anonymous access type, the expected type of the | |
2970 | -- object must be anonymous. This is a name resolution rule. | |
996ae0b0 | 2971 | |
f16d05d9 AC |
2972 | if Nkind (Parent (N)) /= N_Object_Renaming_Declaration |
2973 | or else No (Access_Definition (Parent (N))) | |
2974 | or else Ekind (Etype (Comp)) = E_Anonymous_Access_Type | |
2975 | or else | |
2976 | Ekind (Etype (Comp)) = E_Anonymous_Access_Subprogram_Type | |
2977 | then | |
2978 | Set_Entity (Sel, Comp); | |
2979 | Set_Etype (Sel, Etype (Comp)); | |
2980 | Add_One_Interp (N, Etype (Comp), Etype (Comp)); | |
2981 | ||
2982 | -- This also specifies a candidate to resolve the name. | |
2983 | -- Further overloading will be resolved from context. | |
2984 | -- The selector name itself does not carry overloading | |
2985 | -- information. | |
2986 | ||
2987 | Set_Etype (Nam, It.Typ); | |
2988 | ||
2989 | else | |
b61ee1aa | 2990 | -- Named access type in the context of a renaming |
f16d05d9 AC |
2991 | -- declaration with an access definition. Remove |
2992 | -- inapplicable candidate. | |
2993 | ||
2994 | Remove_Interp (I); | |
2995 | end if; | |
996ae0b0 RK |
2996 | end if; |
2997 | ||
2998 | Next_Entity (Comp); | |
2999 | end loop; | |
3000 | ||
3001 | elsif Is_Concurrent_Type (T) then | |
3002 | Comp := First_Entity (T); | |
996ae0b0 RK |
3003 | while Present (Comp) |
3004 | and then Comp /= First_Private_Entity (T) | |
3005 | loop | |
3006 | if Chars (Comp) = Chars (Sel) then | |
3007 | if Is_Overloadable (Comp) then | |
3008 | Add_One_Interp (Sel, Comp, Etype (Comp)); | |
3009 | else | |
3010 | Set_Entity_With_Style_Check (Sel, Comp); | |
3011 | Generate_Reference (Comp, Sel); | |
3012 | end if; | |
3013 | ||
3014 | Set_Etype (Sel, Etype (Comp)); | |
3015 | Set_Etype (N, Etype (Comp)); | |
3016 | Set_Etype (Nam, It.Typ); | |
3017 | ||
09494c32 AC |
3018 | -- For access type case, introduce explicit dereference for |
3019 | -- more uniform treatment of entry calls. Do this only once | |
3020 | -- if several interpretations yield an access type. | |
996ae0b0 | 3021 | |
d469eabe HK |
3022 | if Is_Access_Type (Etype (Nam)) |
3023 | and then Nkind (Nam) /= N_Explicit_Dereference | |
3024 | then | |
996ae0b0 | 3025 | Insert_Explicit_Dereference (Nam); |
fbf5a39b AC |
3026 | Error_Msg_NW |
3027 | (Warn_On_Dereference, "?implicit dereference", N); | |
996ae0b0 RK |
3028 | end if; |
3029 | end if; | |
3030 | ||
3031 | Next_Entity (Comp); | |
3032 | end loop; | |
3033 | ||
3034 | Set_Is_Overloaded (N, Is_Overloaded (Sel)); | |
996ae0b0 RK |
3035 | end if; |
3036 | ||
3037 | Get_Next_Interp (I, It); | |
3038 | end loop; | |
3039 | ||
0a36105d JM |
3040 | if Etype (N) = Any_Type |
3041 | and then not Try_Object_Operation (N) | |
3042 | then | |
996ae0b0 RK |
3043 | Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel); |
3044 | Set_Entity (Sel, Any_Id); | |
3045 | Set_Etype (Sel, Any_Type); | |
3046 | end if; | |
996ae0b0 RK |
3047 | end Analyze_Overloaded_Selected_Component; |
3048 | ||
3049 | ---------------------------------- | |
3050 | -- Analyze_Qualified_Expression -- | |
3051 | ---------------------------------- | |
3052 | ||
3053 | procedure Analyze_Qualified_Expression (N : Node_Id) is | |
3054 | Mark : constant Entity_Id := Subtype_Mark (N); | |
45c8b94b ES |
3055 | Expr : constant Node_Id := Expression (N); |
3056 | I : Interp_Index; | |
3057 | It : Interp; | |
996ae0b0 RK |
3058 | T : Entity_Id; |
3059 | ||
3060 | begin | |
45c8b94b ES |
3061 | Analyze_Expression (Expr); |
3062 | ||
996ae0b0 RK |
3063 | Set_Etype (N, Any_Type); |
3064 | Find_Type (Mark); | |
3065 | T := Entity (Mark); | |
45c8b94b | 3066 | Set_Etype (N, T); |
996ae0b0 RK |
3067 | |
3068 | if T = Any_Type then | |
3069 | return; | |
3070 | end if; | |
996ae0b0 | 3071 | |
4c46b835 | 3072 | Check_Fully_Declared (T, N); |
45c8b94b ES |
3073 | |
3074 | -- If expected type is class-wide, check for exact match before | |
3075 | -- expansion, because if the expression is a dispatching call it | |
3076 | -- may be rewritten as explicit dereference with class-wide result. | |
3077 | -- If expression is overloaded, retain only interpretations that | |
3078 | -- will yield exact matches. | |
3079 | ||
3080 | if Is_Class_Wide_Type (T) then | |
3081 | if not Is_Overloaded (Expr) then | |
3082 | if Base_Type (Etype (Expr)) /= Base_Type (T) then | |
3083 | if Nkind (Expr) = N_Aggregate then | |
3084 | Error_Msg_N ("type of aggregate cannot be class-wide", Expr); | |
3085 | else | |
3086 | Wrong_Type (Expr, T); | |
3087 | end if; | |
3088 | end if; | |
3089 | ||
3090 | else | |
3091 | Get_First_Interp (Expr, I, It); | |
3092 | ||
3093 | while Present (It.Nam) loop | |
3094 | if Base_Type (It.Typ) /= Base_Type (T) then | |
3095 | Remove_Interp (I); | |
3096 | end if; | |
3097 | ||
3098 | Get_Next_Interp (I, It); | |
3099 | end loop; | |
3100 | end if; | |
3101 | end if; | |
3102 | ||
996ae0b0 RK |
3103 | Set_Etype (N, T); |
3104 | end Analyze_Qualified_Expression; | |
3105 | ||
3106 | ------------------- | |
3107 | -- Analyze_Range -- | |
3108 | ------------------- | |
3109 | ||
3110 | procedure Analyze_Range (N : Node_Id) is | |
3111 | L : constant Node_Id := Low_Bound (N); | |
3112 | H : constant Node_Id := High_Bound (N); | |
3113 | I1, I2 : Interp_Index; | |
3114 | It1, It2 : Interp; | |
3115 | ||
3116 | procedure Check_Common_Type (T1, T2 : Entity_Id); | |
3117 | -- Verify the compatibility of two types, and choose the | |
3118 | -- non universal one if the other is universal. | |
3119 | ||
3120 | procedure Check_High_Bound (T : Entity_Id); | |
3121 | -- Test one interpretation of the low bound against all those | |
3122 | -- of the high bound. | |
3123 | ||
fbf5a39b AC |
3124 | procedure Check_Universal_Expression (N : Node_Id); |
3125 | -- In Ada83, reject bounds of a universal range that are not | |
3126 | -- literals or entity names. | |
3127 | ||
996ae0b0 RK |
3128 | ----------------------- |
3129 | -- Check_Common_Type -- | |
3130 | ----------------------- | |
3131 | ||
3132 | procedure Check_Common_Type (T1, T2 : Entity_Id) is | |
3133 | begin | |
b4592168 GD |
3134 | if Covers (T1 => T1, T2 => T2) |
3135 | or else | |
3136 | Covers (T1 => T2, T2 => T1) | |
3137 | then | |
996ae0b0 RK |
3138 | if T1 = Universal_Integer |
3139 | or else T1 = Universal_Real | |
3140 | or else T1 = Any_Character | |
3141 | then | |
3142 | Add_One_Interp (N, Base_Type (T2), Base_Type (T2)); | |
3143 | ||
fbf5a39b | 3144 | elsif T1 = T2 then |
996ae0b0 RK |
3145 | Add_One_Interp (N, T1, T1); |
3146 | ||
3147 | else | |
3148 | Add_One_Interp (N, Base_Type (T1), Base_Type (T1)); | |
3149 | end if; | |
3150 | end if; | |
3151 | end Check_Common_Type; | |
3152 | ||
3153 | ---------------------- | |
3154 | -- Check_High_Bound -- | |
3155 | ---------------------- | |
3156 | ||
3157 | procedure Check_High_Bound (T : Entity_Id) is | |
3158 | begin | |
3159 | if not Is_Overloaded (H) then | |
3160 | Check_Common_Type (T, Etype (H)); | |
3161 | else | |
3162 | Get_First_Interp (H, I2, It2); | |
996ae0b0 RK |
3163 | while Present (It2.Typ) loop |
3164 | Check_Common_Type (T, It2.Typ); | |
3165 | Get_Next_Interp (I2, It2); | |
3166 | end loop; | |
3167 | end if; | |
3168 | end Check_High_Bound; | |
3169 | ||
fbf5a39b AC |
3170 | ----------------------------- |
3171 | -- Is_Universal_Expression -- | |
3172 | ----------------------------- | |
3173 | ||
3174 | procedure Check_Universal_Expression (N : Node_Id) is | |
3175 | begin | |
3176 | if Etype (N) = Universal_Integer | |
3177 | and then Nkind (N) /= N_Integer_Literal | |
3178 | and then not Is_Entity_Name (N) | |
3179 | and then Nkind (N) /= N_Attribute_Reference | |
3180 | then | |
3181 | Error_Msg_N ("illegal bound in discrete range", N); | |
3182 | end if; | |
3183 | end Check_Universal_Expression; | |
3184 | ||
996ae0b0 RK |
3185 | -- Start of processing for Analyze_Range |
3186 | ||
3187 | begin | |
3188 | Set_Etype (N, Any_Type); | |
3189 | Analyze_Expression (L); | |
3190 | Analyze_Expression (H); | |
3191 | ||
3192 | if Etype (L) = Any_Type or else Etype (H) = Any_Type then | |
3193 | return; | |
3194 | ||
3195 | else | |
3196 | if not Is_Overloaded (L) then | |
3197 | Check_High_Bound (Etype (L)); | |
3198 | else | |
3199 | Get_First_Interp (L, I1, It1); | |
996ae0b0 RK |
3200 | while Present (It1.Typ) loop |
3201 | Check_High_Bound (It1.Typ); | |
3202 | Get_Next_Interp (I1, It1); | |
3203 | end loop; | |
3204 | end if; | |
3205 | ||
3206 | -- If result is Any_Type, then we did not find a compatible pair | |
3207 | ||
3208 | if Etype (N) = Any_Type then | |
3209 | Error_Msg_N ("incompatible types in range ", N); | |
3210 | end if; | |
3211 | end if; | |
fbf5a39b | 3212 | |
0ab80019 | 3213 | if Ada_Version = Ada_83 |
fbf5a39b AC |
3214 | and then |
3215 | (Nkind (Parent (N)) = N_Loop_Parameter_Specification | |
4c46b835 | 3216 | or else Nkind (Parent (N)) = N_Constrained_Array_Definition) |
fbf5a39b AC |
3217 | then |
3218 | Check_Universal_Expression (L); | |
3219 | Check_Universal_Expression (H); | |
3220 | end if; | |
996ae0b0 RK |
3221 | end Analyze_Range; |
3222 | ||
3223 | ----------------------- | |
3224 | -- Analyze_Reference -- | |
3225 | ----------------------- | |
3226 | ||
3227 | procedure Analyze_Reference (N : Node_Id) is | |
3228 | P : constant Node_Id := Prefix (N); | |
b4592168 GD |
3229 | E : Entity_Id; |
3230 | T : Entity_Id; | |
996ae0b0 | 3231 | Acc_Type : Entity_Id; |
b4592168 | 3232 | |
996ae0b0 RK |
3233 | begin |
3234 | Analyze (P); | |
b4592168 GD |
3235 | |
3236 | -- An interesting error check, if we take the 'Reference of an object | |
3237 | -- for which a pragma Atomic or Volatile has been given, and the type | |
3238 | -- of the object is not Atomic or Volatile, then we are in trouble. The | |
3239 | -- problem is that no trace of the atomic/volatile status will remain | |
3240 | -- for the backend to respect when it deals with the resulting pointer, | |
3241 | -- since the pointer type will not be marked atomic (it is a pointer to | |
3242 | -- the base type of the object). | |
3243 | ||
3244 | -- It is not clear if that can ever occur, but in case it does, we will | |
3245 | -- generate an error message. Not clear if this message can ever be | |
3246 | -- generated, and pretty clear that it represents a bug if it is, still | |
d2f25cd1 AC |
3247 | -- seems worth checking, except in CodePeer mode where we do not really |
3248 | -- care and don't want to bother the user. | |
b4592168 GD |
3249 | |
3250 | T := Etype (P); | |
3251 | ||
3252 | if Is_Entity_Name (P) | |
3253 | and then Is_Object_Reference (P) | |
d2f25cd1 | 3254 | and then not CodePeer_Mode |
b4592168 GD |
3255 | then |
3256 | E := Entity (P); | |
3257 | T := Etype (P); | |
3258 | ||
3259 | if (Has_Atomic_Components (E) | |
3260 | and then not Has_Atomic_Components (T)) | |
3261 | or else | |
3262 | (Has_Volatile_Components (E) | |
3263 | and then not Has_Volatile_Components (T)) | |
3264 | or else (Is_Atomic (E) and then not Is_Atomic (T)) | |
3265 | or else (Is_Volatile (E) and then not Is_Volatile (T)) | |
3266 | then | |
3267 | Error_Msg_N ("cannot take reference to Atomic/Volatile object", N); | |
3268 | end if; | |
3269 | end if; | |
3270 | ||
3271 | -- Carry on with normal processing | |
3272 | ||
996ae0b0 | 3273 | Acc_Type := Create_Itype (E_Allocator_Type, N); |
b4592168 | 3274 | Set_Etype (Acc_Type, Acc_Type); |
996ae0b0 RK |
3275 | Set_Directly_Designated_Type (Acc_Type, Etype (P)); |
3276 | Set_Etype (N, Acc_Type); | |
3277 | end Analyze_Reference; | |
3278 | ||
3279 | -------------------------------- | |
3280 | -- Analyze_Selected_Component -- | |
3281 | -------------------------------- | |
3282 | ||
2383acbd AC |
3283 | -- Prefix is a record type or a task or protected type. In the latter case, |
3284 | -- the selector must denote a visible entry. | |
996ae0b0 RK |
3285 | |
3286 | procedure Analyze_Selected_Component (N : Node_Id) is | |
d469eabe HK |
3287 | Name : constant Node_Id := Prefix (N); |
3288 | Sel : constant Node_Id := Selector_Name (N); | |
3289 | Act_Decl : Node_Id; | |
3290 | Comp : Entity_Id; | |
3291 | Has_Candidate : Boolean := False; | |
3292 | In_Scope : Boolean; | |
3293 | Parent_N : Node_Id; | |
3294 | Pent : Entity_Id := Empty; | |
3295 | Prefix_Type : Entity_Id; | |
401093c1 ES |
3296 | |
3297 | Type_To_Use : Entity_Id; | |
3298 | -- In most cases this is the Prefix_Type, but if the Prefix_Type is | |
3299 | -- a class-wide type, we use its root type, whose components are | |
3300 | -- present in the class-wide type. | |
3301 | ||
2383acbd AC |
3302 | Is_Single_Concurrent_Object : Boolean; |
3303 | -- Set True if the prefix is a single task or a single protected object | |
3304 | ||
d469eabe HK |
3305 | function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean; |
3306 | -- It is known that the parent of N denotes a subprogram call. Comp | |
3307 | -- is an overloadable component of the concurrent type of the prefix. | |
3308 | -- Determine whether all formals of the parent of N and Comp are mode | |
b4592168 GD |
3309 | -- conformant. If the parent node is not analyzed yet it may be an |
3310 | -- indexed component rather than a function call. | |
d469eabe HK |
3311 | |
3312 | ------------------------------ | |
3313 | -- Has_Mode_Conformant_Spec -- | |
3314 | ------------------------------ | |
3315 | ||
3316 | function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is | |
3317 | Comp_Param : Entity_Id; | |
3318 | Param : Node_Id; | |
3319 | Param_Typ : Entity_Id; | |
3320 | ||
3321 | begin | |
3322 | Comp_Param := First_Formal (Comp); | |
b4592168 GD |
3323 | |
3324 | if Nkind (Parent (N)) = N_Indexed_Component then | |
3325 | Param := First (Expressions (Parent (N))); | |
3326 | else | |
3327 | Param := First (Parameter_Associations (Parent (N))); | |
3328 | end if; | |
3329 | ||
d469eabe HK |
3330 | while Present (Comp_Param) |
3331 | and then Present (Param) | |
3332 | loop | |
3333 | Param_Typ := Find_Parameter_Type (Param); | |
3334 | ||
3335 | if Present (Param_Typ) | |
3336 | and then | |
3337 | not Conforming_Types | |
3338 | (Etype (Comp_Param), Param_Typ, Mode_Conformant) | |
3339 | then | |
3340 | return False; | |
3341 | end if; | |
3342 | ||
3343 | Next_Formal (Comp_Param); | |
3344 | Next (Param); | |
3345 | end loop; | |
3346 | ||
3347 | -- One of the specs has additional formals | |
3348 | ||
3349 | if Present (Comp_Param) or else Present (Param) then | |
3350 | return False; | |
3351 | end if; | |
3352 | ||
3353 | return True; | |
3354 | end Has_Mode_Conformant_Spec; | |
996ae0b0 RK |
3355 | |
3356 | -- Start of processing for Analyze_Selected_Component | |
3357 | ||
3358 | begin | |
3359 | Set_Etype (N, Any_Type); | |
3360 | ||
3361 | if Is_Overloaded (Name) then | |
3362 | Analyze_Overloaded_Selected_Component (N); | |
3363 | return; | |
3364 | ||
3365 | elsif Etype (Name) = Any_Type then | |
3366 | Set_Entity (Sel, Any_Id); | |
3367 | Set_Etype (Sel, Any_Type); | |
3368 | return; | |
3369 | ||
3370 | else | |
996ae0b0 RK |
3371 | Prefix_Type := Etype (Name); |
3372 | end if; | |
3373 | ||
3374 | if Is_Access_Type (Prefix_Type) then | |
07fc65c4 GB |
3375 | |
3376 | -- A RACW object can never be used as prefix of a selected | |
3377 | -- component since that means it is dereferenced without | |
3378 | -- being a controlling operand of a dispatching operation | |
b4592168 GD |
3379 | -- (RM E.2.2(16/1)). Before reporting an error, we must check |
3380 | -- whether this is actually a dispatching call in prefix form. | |
07fc65c4 | 3381 | |
996ae0b0 RK |
3382 | if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type) |
3383 | and then Comes_From_Source (N) | |
3384 | then | |
b4592168 GD |
3385 | if Try_Object_Operation (N) then |
3386 | return; | |
3387 | else | |
3388 | Error_Msg_N | |
3389 | ("invalid dereference of a remote access-to-class-wide value", | |
3390 | N); | |
3391 | end if; | |
07fc65c4 GB |
3392 | |
3393 | -- Normal case of selected component applied to access type | |
3394 | ||
3395 | else | |
fbf5a39b | 3396 | Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N); |
da709d08 | 3397 | |
6e73e3ab AC |
3398 | if Is_Entity_Name (Name) then |
3399 | Pent := Entity (Name); | |
3400 | elsif Nkind (Name) = N_Selected_Component | |
3401 | and then Is_Entity_Name (Selector_Name (Name)) | |
3402 | then | |
3403 | Pent := Entity (Selector_Name (Name)); | |
3404 | end if; | |
da709d08 | 3405 | |
d469eabe | 3406 | Prefix_Type := Process_Implicit_Dereference_Prefix (Pent, Name); |
996ae0b0 | 3407 | end if; |
b4592168 GD |
3408 | |
3409 | -- If we have an explicit dereference of a remote access-to-class-wide | |
3410 | -- value, then issue an error (see RM-E.2.2(16/1)). However we first | |
3411 | -- have to check for the case of a prefix that is a controlling operand | |
3412 | -- of a prefixed dispatching call, as the dereference is legal in that | |
3413 | -- case. Normally this condition is checked in Validate_Remote_Access_ | |
3414 | -- To_Class_Wide_Type, but we have to defer the checking for selected | |
3415 | -- component prefixes because of the prefixed dispatching call case. | |
3416 | -- Note that implicit dereferences are checked for this just above. | |
3417 | ||
3418 | elsif Nkind (Name) = N_Explicit_Dereference | |
3419 | and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name))) | |
3420 | and then Comes_From_Source (N) | |
3421 | then | |
3422 | if Try_Object_Operation (N) then | |
3423 | return; | |
3424 | else | |
3425 | Error_Msg_N | |
3426 | ("invalid dereference of a remote access-to-class-wide value", | |
3427 | N); | |
3428 | end if; | |
aab883ec | 3429 | end if; |
b67a385c | 3430 | |
aab883ec ES |
3431 | -- (Ada 2005): if the prefix is the limited view of a type, and |
3432 | -- the context already includes the full view, use the full view | |
3433 | -- in what follows, either to retrieve a component of to find | |
3434 | -- a primitive operation. If the prefix is an explicit dereference, | |
3435 | -- set the type of the prefix to reflect this transformation. | |
401093c1 ES |
3436 | -- If the non-limited view is itself an incomplete type, get the |
3437 | -- full view if available. | |
aab883ec ES |
3438 | |
3439 | if Is_Incomplete_Type (Prefix_Type) | |
3440 | and then From_With_Type (Prefix_Type) | |
3441 | and then Present (Non_Limited_View (Prefix_Type)) | |
3442 | then | |
401093c1 | 3443 | Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type)); |
aab883ec ES |
3444 | |
3445 | if Nkind (N) = N_Explicit_Dereference then | |
3446 | Set_Etype (Prefix (N), Prefix_Type); | |
3447 | end if; | |
3448 | ||
3449 | elsif Ekind (Prefix_Type) = E_Class_Wide_Type | |
3450 | and then From_With_Type (Prefix_Type) | |
3451 | and then Present (Non_Limited_View (Etype (Prefix_Type))) | |
3452 | then | |
3453 | Prefix_Type := | |
3454 | Class_Wide_Type (Non_Limited_View (Etype (Prefix_Type))); | |
3455 | ||
3456 | if Nkind (N) = N_Explicit_Dereference then | |
3457 | Set_Etype (Prefix (N), Prefix_Type); | |
b67a385c | 3458 | end if; |
996ae0b0 RK |
3459 | end if; |
3460 | ||
3461 | if Ekind (Prefix_Type) = E_Private_Subtype then | |
3462 | Prefix_Type := Base_Type (Prefix_Type); | |
3463 | end if; | |
3464 | ||
401093c1 | 3465 | Type_To_Use := Prefix_Type; |
996ae0b0 RK |
3466 | |
3467 | -- For class-wide types, use the entity list of the root type. This | |
3468 | -- indirection is specially important for private extensions because | |
3469 | -- only the root type get switched (not the class-wide type). | |
3470 | ||
3471 | if Is_Class_Wide_Type (Prefix_Type) then | |
401093c1 | 3472 | Type_To_Use := Root_Type (Prefix_Type); |
996ae0b0 RK |
3473 | end if; |
3474 | ||
2383acbd AC |
3475 | -- If the prefix is a single concurrent object, use its name in error |
3476 | -- messages, rather than that of its anonymous type. | |
3477 | ||
3478 | Is_Single_Concurrent_Object := | |
3479 | Is_Concurrent_Type (Prefix_Type) | |
3480 | and then Is_Internal_Name (Chars (Prefix_Type)) | |
3481 | and then not Is_Derived_Type (Prefix_Type) | |
3482 | and then Is_Entity_Name (Name); | |
3483 | ||
401093c1 | 3484 | Comp := First_Entity (Type_To_Use); |
996ae0b0 RK |
3485 | |
3486 | -- If the selector has an original discriminant, the node appears in | |
3487 | -- an instance. Replace the discriminant with the corresponding one | |
3488 | -- in the current discriminated type. For nested generics, this must | |
3489 | -- be done transitively, so note the new original discriminant. | |
3490 | ||
3491 | if Nkind (Sel) = N_Identifier | |
3492 | and then Present (Original_Discriminant (Sel)) | |
3493 | then | |
3494 | Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type); | |
3495 | ||
3496 | -- Mark entity before rewriting, for completeness and because | |
3497 | -- subsequent semantic checks might examine the original node. | |
3498 | ||
3499 | Set_Entity (Sel, Comp); | |
3500 | Rewrite (Selector_Name (N), | |
3501 | New_Occurrence_Of (Comp, Sloc (N))); | |
3502 | Set_Original_Discriminant (Selector_Name (N), Comp); | |
3503 | Set_Etype (N, Etype (Comp)); | |
3504 | ||
3505 | if Is_Access_Type (Etype (Name)) then | |
3506 | Insert_Explicit_Dereference (Name); | |
fbf5a39b | 3507 | Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N); |
996ae0b0 RK |
3508 | end if; |
3509 | ||
3510 | elsif Is_Record_Type (Prefix_Type) then | |
3511 | ||
3512 | -- Find component with given name | |
3513 | ||
3514 | while Present (Comp) loop | |
996ae0b0 RK |
3515 | if Chars (Comp) = Chars (Sel) |
3516 | and then Is_Visible_Component (Comp) | |
3517 | then | |
3518 | Set_Entity_With_Style_Check (Sel, Comp); | |
996ae0b0 RK |
3519 | Set_Etype (Sel, Etype (Comp)); |
3520 | ||
3521 | if Ekind (Comp) = E_Discriminant then | |
5d09245e | 3522 | if Is_Unchecked_Union (Base_Type (Prefix_Type)) then |
996ae0b0 RK |
3523 | Error_Msg_N |
3524 | ("cannot reference discriminant of Unchecked_Union", | |
3525 | Sel); | |
3526 | end if; | |
3527 | ||
3528 | if Is_Generic_Type (Prefix_Type) | |
3529 | or else | |
3530 | Is_Generic_Type (Root_Type (Prefix_Type)) | |
3531 | then | |
3532 | Set_Original_Discriminant (Sel, Comp); | |
3533 | end if; | |
3534 | end if; | |
3535 | ||
3536 | -- Resolve the prefix early otherwise it is not possible to | |
3537 | -- build the actual subtype of the component: it may need | |
3538 | -- to duplicate this prefix and duplication is only allowed | |
3539 | -- on fully resolved expressions. | |
3540 | ||
fbf5a39b | 3541 | Resolve (Name); |
996ae0b0 | 3542 | |
b67a385c ES |
3543 | -- Ada 2005 (AI-50217): Check wrong use of incomplete types or |
3544 | -- subtypes in a package specification. | |
28be29ce ES |
3545 | -- Example: |
3546 | ||
3547 | -- limited with Pkg; | |
3548 | -- package Pkg is | |
3549 | -- type Acc_Inc is access Pkg.T; | |
3550 | -- X : Acc_Inc; | |
b67a385c ES |
3551 | -- N : Natural := X.all.Comp; -- ERROR, limited view |
3552 | -- end Pkg; -- Comp is not visible | |
28be29ce ES |
3553 | |
3554 | if Nkind (Name) = N_Explicit_Dereference | |
3555 | and then From_With_Type (Etype (Prefix (Name))) | |
3556 | and then not Is_Potentially_Use_Visible (Etype (Name)) | |
b67a385c ES |
3557 | and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) = |
3558 | N_Package_Specification | |
28be29ce ES |
3559 | then |
3560 | Error_Msg_NE | |
3561 | ("premature usage of incomplete}", Prefix (Name), | |
3562 | Etype (Prefix (Name))); | |
3563 | end if; | |
3564 | ||
996ae0b0 RK |
3565 | -- We never need an actual subtype for the case of a selection |
3566 | -- for a indexed component of a non-packed array, since in | |
3567 | -- this case gigi generates all the checks and can find the | |
3568 | -- necessary bounds information. | |
3569 | ||
3570 | -- We also do not need an actual subtype for the case of | |
3571 | -- a first, last, length, or range attribute applied to a | |
3572 | -- non-packed array, since gigi can again get the bounds in | |
3573 | -- these cases (gigi cannot handle the packed case, since it | |
3574 | -- has the bounds of the packed array type, not the original | |
3575 | -- bounds of the type). However, if the prefix is itself a | |
3576 | -- selected component, as in a.b.c (i), gigi may regard a.b.c | |
3577 | -- as a dynamic-sized temporary, so we do generate an actual | |
3578 | -- subtype for this case. | |
3579 | ||
3580 | Parent_N := Parent (N); | |
3581 | ||
3582 | if not Is_Packed (Etype (Comp)) | |
3583 | and then | |
3584 | ((Nkind (Parent_N) = N_Indexed_Component | |
d469eabe | 3585 | and then Nkind (Name) /= N_Selected_Component) |
996ae0b0 RK |
3586 | or else |
3587 | (Nkind (Parent_N) = N_Attribute_Reference | |
3588 | and then (Attribute_Name (Parent_N) = Name_First | |
ffe9aba8 | 3589 | or else |
996ae0b0 | 3590 | Attribute_Name (Parent_N) = Name_Last |
ffe9aba8 | 3591 | or else |
996ae0b0 | 3592 | Attribute_Name (Parent_N) = Name_Length |
ffe9aba8 | 3593 | or else |
996ae0b0 RK |
3594 | Attribute_Name (Parent_N) = Name_Range))) |
3595 | then | |
3596 | Set_Etype (N, Etype (Comp)); | |
3597 | ||
98123480 ES |
3598 | -- If full analysis is not enabled, we do not generate an |
3599 | -- actual subtype, because in the absence of expansion | |
3600 | -- reference to a formal of a protected type, for example, | |
3601 | -- will not be properly transformed, and will lead to | |
3602 | -- out-of-scope references in gigi. | |
3603 | ||
3604 | -- In all other cases, we currently build an actual subtype. | |
3605 | -- It seems likely that many of these cases can be avoided, | |
3606 | -- but right now, the front end makes direct references to the | |
fbf5a39b | 3607 | -- bounds (e.g. in generating a length check), and if we do |
996ae0b0 | 3608 | -- not make an actual subtype, we end up getting a direct |
98123480 | 3609 | -- reference to a discriminant, which will not do. |
996ae0b0 | 3610 | |
98123480 | 3611 | elsif Full_Analysis then |
996ae0b0 RK |
3612 | Act_Decl := |
3613 | Build_Actual_Subtype_Of_Component (Etype (Comp), N); | |
3614 | Insert_Action (N, Act_Decl); | |
3615 | ||
3616 | if No (Act_Decl) then | |
3617 | Set_Etype (N, Etype (Comp)); | |
3618 | ||
3619 | else | |
3620 | -- Component type depends on discriminants. Enter the | |
3621 | -- main attributes of the subtype. | |
3622 | ||
3623 | declare | |
fbf5a39b AC |
3624 | Subt : constant Entity_Id := |
3625 | Defining_Identifier (Act_Decl); | |
996ae0b0 RK |
3626 | |
3627 | begin | |
3628 | Set_Etype (Subt, Base_Type (Etype (Comp))); | |
3629 | Set_Ekind (Subt, Ekind (Etype (Comp))); | |
3630 | Set_Etype (N, Subt); | |
3631 | end; | |
3632 | end if; | |
98123480 ES |
3633 | |
3634 | -- If Full_Analysis not enabled, just set the Etype | |
3635 | ||
3636 | else | |
3637 | Set_Etype (N, Etype (Comp)); | |
996ae0b0 RK |
3638 | end if; |
3639 | ||
3640 | return; | |
3641 | end if; | |
3642 | ||
aab883ec | 3643 | -- If the prefix is a private extension, check only the visible |
9c510803 | 3644 | -- components of the partial view. This must include the tag, |
f3d57416 | 3645 | -- which can appear in expanded code in a tag check. |
aab883ec | 3646 | |
9c510803 ES |
3647 | if Ekind (Type_To_Use) = E_Record_Type_With_Private |
3648 | and then Chars (Selector_Name (N)) /= Name_uTag | |
3649 | then | |
401093c1 | 3650 | exit when Comp = Last_Entity (Type_To_Use); |
aab883ec ES |
3651 | end if; |
3652 | ||
996ae0b0 RK |
3653 | Next_Entity (Comp); |
3654 | end loop; | |
3655 | ||
d469eabe HK |
3656 | -- Ada 2005 (AI-252): The selected component can be interpreted as |
3657 | -- a prefixed view of a subprogram. Depending on the context, this is | |
3658 | -- either a name that can appear in a renaming declaration, or part | |
3659 | -- of an enclosing call given in prefix form. | |
3660 | ||
3661 | -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the | |
3662 | -- selected component should resolve to a name. | |
35ae2ed8 AC |
3663 | |
3664 | if Ada_Version >= Ada_05 | |
3665 | and then Is_Tagged_Type (Prefix_Type) | |
d469eabe | 3666 | and then not Is_Concurrent_Type (Prefix_Type) |
35ae2ed8 | 3667 | then |
d469eabe HK |
3668 | if Nkind (Parent (N)) = N_Generic_Association |
3669 | or else Nkind (Parent (N)) = N_Requeue_Statement | |
3670 | or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration | |
3671 | then | |
3672 | if Find_Primitive_Operation (N) then | |
3673 | return; | |
3674 | end if; | |
3675 | ||
3676 | elsif Try_Object_Operation (N) then | |
3677 | return; | |
3678 | end if; | |
4c46b835 | 3679 | |
98123480 ES |
3680 | -- If the transformation fails, it will be necessary to redo the |
3681 | -- analysis with all errors enabled, to indicate candidate | |
3682 | -- interpretations and reasons for each failure ??? | |
4c46b835 | 3683 | |
35ae2ed8 AC |
3684 | end if; |
3685 | ||
996ae0b0 | 3686 | elsif Is_Private_Type (Prefix_Type) then |
d469eabe | 3687 | |
98123480 ES |
3688 | -- Allow access only to discriminants of the type. If the type has |
3689 | -- no full view, gigi uses the parent type for the components, so we | |
3690 | -- do the same here. | |
996ae0b0 RK |
3691 | |
3692 | if No (Full_View (Prefix_Type)) then | |
401093c1 ES |
3693 | Type_To_Use := Root_Type (Base_Type (Prefix_Type)); |
3694 | Comp := First_Entity (Type_To_Use); | |
996ae0b0 RK |
3695 | end if; |
3696 | ||
3697 | while Present (Comp) loop | |
996ae0b0 RK |
3698 | if Chars (Comp) = Chars (Sel) then |
3699 | if Ekind (Comp) = E_Discriminant then | |
3700 | Set_Entity_With_Style_Check (Sel, Comp); | |
3701 | Generate_Reference (Comp, Sel); | |
3702 | ||
3703 | Set_Etype (Sel, Etype (Comp)); | |
3704 | Set_Etype (N, Etype (Comp)); | |
3705 | ||
3706 | if Is_Generic_Type (Prefix_Type) | |
d469eabe | 3707 | or else Is_Generic_Type (Root_Type (Prefix_Type)) |
996ae0b0 RK |
3708 | then |
3709 | Set_Original_Discriminant (Sel, Comp); | |
3710 | end if; | |
3711 | ||
f3d57416 | 3712 | -- Before declaring an error, check whether this is tagged |
aab883ec ES |
3713 | -- private type and a call to a primitive operation. |
3714 | ||
3715 | elsif Ada_Version >= Ada_05 | |
3716 | and then Is_Tagged_Type (Prefix_Type) | |
3717 | and then Try_Object_Operation (N) | |
3718 | then | |
3719 | return; | |
3720 | ||
996ae0b0 | 3721 | else |
2383acbd AC |
3722 | Error_Msg_Node_2 := First_Subtype (Prefix_Type); |
3723 | Error_Msg_NE ("invisible selector& for }", N, Sel); | |
996ae0b0 RK |
3724 | Set_Entity (Sel, Any_Id); |
3725 | Set_Etype (N, Any_Type); | |
3726 | end if; | |
3727 | ||
3728 | return; | |
3729 | end if; | |
3730 | ||
3731 | Next_Entity (Comp); | |
3732 | end loop; | |
3733 | ||
3734 | elsif Is_Concurrent_Type (Prefix_Type) then | |
3735 | ||
d469eabe HK |
3736 | -- Find visible operation with given name. For a protected type, |
3737 | -- the possible candidates are discriminants, entries or protected | |
3738 | -- procedures. For a task type, the set can only include entries or | |
3739 | -- discriminants if the task type is not an enclosing scope. If it | |
3740 | -- is an enclosing scope (e.g. in an inner task) then all entities | |
3741 | -- are visible, but the prefix must denote the enclosing scope, i.e. | |
3742 | -- can only be a direct name or an expanded name. | |
996ae0b0 | 3743 | |
d469eabe | 3744 | Set_Etype (Sel, Any_Type); |
996ae0b0 RK |
3745 | In_Scope := In_Open_Scopes (Prefix_Type); |
3746 | ||
3747 | while Present (Comp) loop | |
3748 | if Chars (Comp) = Chars (Sel) then | |
3749 | if Is_Overloadable (Comp) then | |
3750 | Add_One_Interp (Sel, Comp, Etype (Comp)); | |
3751 | ||
d469eabe HK |
3752 | -- If the prefix is tagged, the correct interpretation may |
3753 | -- lie in the primitive or class-wide operations of the | |
3754 | -- type. Perform a simple conformance check to determine | |
3755 | -- whether Try_Object_Operation should be invoked even if | |
3756 | -- a visible entity is found. | |
3757 | ||
3758 | if Is_Tagged_Type (Prefix_Type) | |
3759 | and then | |
3760 | Nkind_In (Parent (N), N_Procedure_Call_Statement, | |
b4592168 GD |
3761 | N_Function_Call, |
3762 | N_Indexed_Component) | |
d469eabe HK |
3763 | and then Has_Mode_Conformant_Spec (Comp) |
3764 | then | |
3765 | Has_Candidate := True; | |
3766 | end if; | |
3767 | ||
2383acbd AC |
3768 | -- Note: a selected component may not denote a component of a |
3769 | -- protected type (4.1.3(7)). | |
3770 | ||
bce79204 | 3771 | elsif Ekind_In (Comp, E_Discriminant, E_Entry_Family) |
2383acbd AC |
3772 | or else (In_Scope |
3773 | and then not Is_Protected_Type (Prefix_Type) | |
3774 | and then Is_Entity_Name (Name)) | |
996ae0b0 RK |
3775 | then |
3776 | Set_Entity_With_Style_Check (Sel, Comp); | |
3777 | Generate_Reference (Comp, Sel); | |
3778 | ||
3779 | else | |
3780 | goto Next_Comp; | |
3781 | end if; | |
3782 | ||
3783 | Set_Etype (Sel, Etype (Comp)); | |
3784 | Set_Etype (N, Etype (Comp)); | |
3785 | ||
3786 | if Ekind (Comp) = E_Discriminant then | |
3787 | Set_Original_Discriminant (Sel, Comp); | |
3788 | end if; | |
3789 | ||
09494c32 AC |
3790 | -- For access type case, introduce explicit dereference for |
3791 | -- more uniform treatment of entry calls. | |
996ae0b0 RK |
3792 | |
3793 | if Is_Access_Type (Etype (Name)) then | |
3794 | Insert_Explicit_Dereference (Name); | |
fbf5a39b AC |
3795 | Error_Msg_NW |
3796 | (Warn_On_Dereference, "?implicit dereference", N); | |
996ae0b0 RK |
3797 | end if; |
3798 | end if; | |
3799 | ||
3800 | <<Next_Comp>> | |
3801 | Next_Entity (Comp); | |
3802 | exit when not In_Scope | |
9bc856dd AC |
3803 | and then |
3804 | Comp = First_Private_Entity (Base_Type (Prefix_Type)); | |
996ae0b0 RK |
3805 | end loop; |
3806 | ||
d469eabe HK |
3807 | -- If there is no visible entity with the given name or none of the |
3808 | -- visible entities are plausible interpretations, check whether | |
3809 | -- there is some other primitive operation with that name. | |
aab883ec | 3810 | |
0a36105d | 3811 | if Ada_Version >= Ada_05 |
aab883ec | 3812 | and then Is_Tagged_Type (Prefix_Type) |
aab883ec | 3813 | then |
d469eabe HK |
3814 | if (Etype (N) = Any_Type |
3815 | or else not Has_Candidate) | |
0a36105d JM |
3816 | and then Try_Object_Operation (N) |
3817 | then | |
3818 | return; | |
3819 | ||
3820 | -- If the context is not syntactically a procedure call, it | |
3821 | -- may be a call to a primitive function declared outside of | |
3822 | -- the synchronized type. | |
3823 | ||
3824 | -- If the context is a procedure call, there might still be | |
3825 | -- an overloading between an entry and a primitive procedure | |
3826 | -- declared outside of the synchronized type, called in prefix | |
3827 | -- notation. This is harder to disambiguate because in one case | |
3828 | -- the controlling formal is implicit ??? | |
3829 | ||
3830 | elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement | |
b4592168 | 3831 | and then Nkind (Parent (N)) /= N_Indexed_Component |
0a36105d JM |
3832 | and then Try_Object_Operation (N) |
3833 | then | |
3834 | return; | |
3835 | end if; | |
aab883ec ES |
3836 | end if; |
3837 | ||
2383acbd AC |
3838 | if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then |
3839 | -- Case of a prefix of a protected type: selector might denote | |
3840 | -- an invisible private component. | |
3841 | ||
3842 | Comp := First_Private_Entity (Base_Type (Prefix_Type)); | |
3843 | while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop | |
3844 | Next_Entity (Comp); | |
3845 | end loop; | |
3846 | ||
3847 | if Present (Comp) then | |
3848 | if Is_Single_Concurrent_Object then | |
3849 | Error_Msg_Node_2 := Entity (Name); | |
3850 | Error_Msg_NE ("invisible selector& for &", N, Sel); | |
3851 | ||
3852 | else | |
3853 | Error_Msg_Node_2 := First_Subtype (Prefix_Type); | |
3854 | Error_Msg_NE ("invisible selector& for }", N, Sel); | |
3855 | end if; | |
3856 | return; | |
3857 | end if; | |
3858 | end if; | |
3859 | ||
996ae0b0 RK |
3860 | Set_Is_Overloaded (N, Is_Overloaded (Sel)); |
3861 | ||
3862 | else | |
3863 | -- Invalid prefix | |
3864 | ||
3865 | Error_Msg_NE ("invalid prefix in selected component&", N, Sel); | |
3866 | end if; | |
3867 | ||
4c46b835 | 3868 | -- If N still has no type, the component is not defined in the prefix |
996ae0b0 RK |
3869 | |
3870 | if Etype (N) = Any_Type then | |
3871 | ||
2383acbd | 3872 | if Is_Single_Concurrent_Object then |
996ae0b0 RK |
3873 | Error_Msg_Node_2 := Entity (Name); |
3874 | Error_Msg_NE ("no selector& for&", N, Sel); | |
3875 | ||
401093c1 | 3876 | Check_Misspelled_Selector (Type_To_Use, Sel); |
996ae0b0 | 3877 | |
de76a39c GB |
3878 | elsif Is_Generic_Type (Prefix_Type) |
3879 | and then Ekind (Prefix_Type) = E_Record_Type_With_Private | |
07fc65c4 | 3880 | and then Prefix_Type /= Etype (Prefix_Type) |
de76a39c GB |
3881 | and then Is_Record_Type (Etype (Prefix_Type)) |
3882 | then | |
98123480 | 3883 | -- If this is a derived formal type, the parent may have |
de76a39c GB |
3884 | -- different visibility at this point. Try for an inherited |
3885 | -- component before reporting an error. | |
3886 | ||
3887 | Set_Etype (Prefix (N), Etype (Prefix_Type)); | |
3888 | Analyze_Selected_Component (N); | |
3889 | return; | |
3890 | ||
fbf5a39b AC |
3891 | elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private |
3892 | and then Is_Generic_Actual_Type (Prefix_Type) | |
3893 | and then Present (Full_View (Prefix_Type)) | |
3894 | then | |
4c46b835 AC |
3895 | -- Similarly, if this the actual for a formal derived type, the |
3896 | -- component inherited from the generic parent may not be visible | |
3897 | -- in the actual, but the selected component is legal. | |
fbf5a39b AC |
3898 | |
3899 | declare | |
3900 | Comp : Entity_Id; | |
4c46b835 | 3901 | |
fbf5a39b AC |
3902 | begin |
3903 | Comp := | |
3904 | First_Component (Generic_Parent_Type (Parent (Prefix_Type))); | |
fbf5a39b AC |
3905 | while Present (Comp) loop |
3906 | if Chars (Comp) = Chars (Sel) then | |
3907 | Set_Entity_With_Style_Check (Sel, Comp); | |
3908 | Set_Etype (Sel, Etype (Comp)); | |
3909 | Set_Etype (N, Etype (Comp)); | |
69e6a03e | 3910 | return; |
fbf5a39b AC |
3911 | end if; |
3912 | ||
3913 | Next_Component (Comp); | |
3914 | end loop; | |
3915 | ||
3916 | pragma Assert (Etype (N) /= Any_Type); | |
3917 | end; | |
3918 | ||
996ae0b0 RK |
3919 | else |
3920 | if Ekind (Prefix_Type) = E_Record_Subtype then | |
3921 | ||
3922 | -- Check whether this is a component of the base type | |
3923 | -- which is absent from a statically constrained subtype. | |
3924 | -- This will raise constraint error at run-time, but is | |
3925 | -- not a compile-time error. When the selector is illegal | |
3926 | -- for base type as well fall through and generate a | |
3927 | -- compilation error anyway. | |
3928 | ||
3929 | Comp := First_Component (Base_Type (Prefix_Type)); | |
996ae0b0 | 3930 | while Present (Comp) loop |
996ae0b0 RK |
3931 | if Chars (Comp) = Chars (Sel) |
3932 | and then Is_Visible_Component (Comp) | |
3933 | then | |
3934 | Set_Entity_With_Style_Check (Sel, Comp); | |
3935 | Generate_Reference (Comp, Sel); | |
3936 | Set_Etype (Sel, Etype (Comp)); | |
3937 | Set_Etype (N, Etype (Comp)); | |
3938 | ||
3939 | -- Emit appropriate message. Gigi will replace the | |
3940 | -- node subsequently with the appropriate Raise. | |
3941 | ||
3942 | Apply_Compile_Time_Constraint_Error | |
3943 | (N, "component not present in }?", | |
07fc65c4 | 3944 | CE_Discriminant_Check_Failed, |
996ae0b0 RK |
3945 | Ent => Prefix_Type, Rep => False); |
3946 | Set_Raises_Constraint_Error (N); | |
3947 | return; | |
3948 | end if; | |
3949 | ||
3950 | Next_Component (Comp); | |
3951 | end loop; | |
3952 | ||
3953 | end if; | |
3954 | ||
3955 | Error_Msg_Node_2 := First_Subtype (Prefix_Type); | |
3956 | Error_Msg_NE ("no selector& for}", N, Sel); | |
3957 | ||
401093c1 | 3958 | Check_Misspelled_Selector (Type_To_Use, Sel); |
996ae0b0 RK |
3959 | end if; |
3960 | ||
3961 | Set_Entity (Sel, Any_Id); | |
3962 | Set_Etype (Sel, Any_Type); | |
3963 | end if; | |
3964 | end Analyze_Selected_Component; | |
3965 | ||
3966 | --------------------------- | |
3967 | -- Analyze_Short_Circuit -- | |
3968 | --------------------------- | |
3969 | ||
3970 | procedure Analyze_Short_Circuit (N : Node_Id) is | |
3971 | L : constant Node_Id := Left_Opnd (N); | |
3972 | R : constant Node_Id := Right_Opnd (N); | |
3973 | Ind : Interp_Index; | |
3974 | It : Interp; | |
3975 | ||
3976 | begin | |
3977 | Analyze_Expression (L); | |
3978 | Analyze_Expression (R); | |
3979 | Set_Etype (N, Any_Type); | |
3980 | ||
3981 | if not Is_Overloaded (L) then | |
996ae0b0 RK |
3982 | if Root_Type (Etype (L)) = Standard_Boolean |
3983 | and then Has_Compatible_Type (R, Etype (L)) | |
3984 | then | |
3985 | Add_One_Interp (N, Etype (L), Etype (L)); | |
3986 | end if; | |
3987 | ||
3988 | else | |
3989 | Get_First_Interp (L, Ind, It); | |
996ae0b0 RK |
3990 | while Present (It.Typ) loop |
3991 | if Root_Type (It.Typ) = Standard_Boolean | |
3992 | and then Has_Compatible_Type (R, It.Typ) | |
3993 | then | |
3994 | Add_One_Interp (N, It.Typ, It.Typ); | |
3995 | end if; | |
3996 | ||
3997 | Get_Next_Interp (Ind, It); | |
3998 | end loop; | |
3999 | end if; | |
4000 | ||
d469eabe HK |
4001 | -- Here we have failed to find an interpretation. Clearly we know that |
4002 | -- it is not the case that both operands can have an interpretation of | |
4003 | -- Boolean, but this is by far the most likely intended interpretation. | |
4004 | -- So we simply resolve both operands as Booleans, and at least one of | |
4005 | -- these resolutions will generate an error message, and we do not need | |
4006 | -- to give another error message on the short circuit operation itself. | |
996ae0b0 RK |
4007 | |
4008 | if Etype (N) = Any_Type then | |
4009 | Resolve (L, Standard_Boolean); | |
4010 | Resolve (R, Standard_Boolean); | |
4011 | Set_Etype (N, Standard_Boolean); | |
4012 | end if; | |
4013 | end Analyze_Short_Circuit; | |
4014 | ||
4015 | ------------------- | |
4016 | -- Analyze_Slice -- | |
4017 | ------------------- | |
4018 | ||
4019 | procedure Analyze_Slice (N : Node_Id) is | |
4020 | P : constant Node_Id := Prefix (N); | |
4021 | D : constant Node_Id := Discrete_Range (N); | |
4022 | Array_Type : Entity_Id; | |
4023 | ||
4024 | procedure Analyze_Overloaded_Slice; | |
4025 | -- If the prefix is overloaded, select those interpretations that | |
4026 | -- yield a one-dimensional array type. | |
4027 | ||
4c46b835 AC |
4028 | ------------------------------ |
4029 | -- Analyze_Overloaded_Slice -- | |
4030 | ------------------------------ | |
4031 | ||
996ae0b0 RK |
4032 | procedure Analyze_Overloaded_Slice is |
4033 | I : Interp_Index; | |
4034 | It : Interp; | |
4035 | Typ : Entity_Id; | |
4036 | ||
4037 | begin | |
4038 | Set_Etype (N, Any_Type); | |
996ae0b0 | 4039 | |
4c46b835 | 4040 | Get_First_Interp (P, I, It); |
996ae0b0 RK |
4041 | while Present (It.Nam) loop |
4042 | Typ := It.Typ; | |
4043 | ||
4044 | if Is_Access_Type (Typ) then | |
4045 | Typ := Designated_Type (Typ); | |
fbf5a39b | 4046 | Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N); |
996ae0b0 RK |
4047 | end if; |
4048 | ||
4049 | if Is_Array_Type (Typ) | |
4050 | and then Number_Dimensions (Typ) = 1 | |
4051 | and then Has_Compatible_Type (D, Etype (First_Index (Typ))) | |
4052 | then | |
4053 | Add_One_Interp (N, Typ, Typ); | |
4054 | end if; | |
4055 | ||
4056 | Get_Next_Interp (I, It); | |
4057 | end loop; | |
4058 | ||
4059 | if Etype (N) = Any_Type then | |
4060 | Error_Msg_N ("expect array type in prefix of slice", N); | |
4061 | end if; | |
4062 | end Analyze_Overloaded_Slice; | |
4063 | ||
4064 | -- Start of processing for Analyze_Slice | |
4065 | ||
4066 | begin | |
523456db | 4067 | Analyze (P); |
996ae0b0 RK |
4068 | Analyze (D); |
4069 | ||
4070 | if Is_Overloaded (P) then | |
4071 | Analyze_Overloaded_Slice; | |
4072 | ||
4073 | else | |
4074 | Array_Type := Etype (P); | |
4075 | Set_Etype (N, Any_Type); | |
4076 | ||
4077 | if Is_Access_Type (Array_Type) then | |
4078 | Array_Type := Designated_Type (Array_Type); | |
fbf5a39b | 4079 | Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N); |
996ae0b0 RK |
4080 | end if; |
4081 | ||
4082 | if not Is_Array_Type (Array_Type) then | |
4083 | Wrong_Type (P, Any_Array); | |
4084 | ||
4085 | elsif Number_Dimensions (Array_Type) > 1 then | |
4086 | Error_Msg_N | |
4087 | ("type is not one-dimensional array in slice prefix", N); | |
4088 | ||
4089 | elsif not | |
4090 | Has_Compatible_Type (D, Etype (First_Index (Array_Type))) | |
4091 | then | |
4092 | Wrong_Type (D, Etype (First_Index (Array_Type))); | |
4093 | ||
4094 | else | |
4095 | Set_Etype (N, Array_Type); | |
4096 | end if; | |
4097 | end if; | |
4098 | end Analyze_Slice; | |
4099 | ||
4100 | ----------------------------- | |
4101 | -- Analyze_Type_Conversion -- | |
4102 | ----------------------------- | |
4103 | ||
4104 | procedure Analyze_Type_Conversion (N : Node_Id) is | |
4105 | Expr : constant Node_Id := Expression (N); | |
4106 | T : Entity_Id; | |
4107 | ||
4108 | begin | |
4109 | -- If Conversion_OK is set, then the Etype is already set, and the | |
4110 | -- only processing required is to analyze the expression. This is | |
4111 | -- used to construct certain "illegal" conversions which are not | |
4112 | -- allowed by Ada semantics, but can be handled OK by Gigi, see | |
4113 | -- Sinfo for further details. | |
4114 | ||
4115 | if Conversion_OK (N) then | |
4116 | Analyze (Expr); | |
4117 | return; | |
4118 | end if; | |
4119 | ||
4120 | -- Otherwise full type analysis is required, as well as some semantic | |
4121 | -- checks to make sure the argument of the conversion is appropriate. | |
4122 | ||
4123 | Find_Type (Subtype_Mark (N)); | |
4124 | T := Entity (Subtype_Mark (N)); | |
4125 | Set_Etype (N, T); | |
4126 | Check_Fully_Declared (T, N); | |
4127 | Analyze_Expression (Expr); | |
4128 | Validate_Remote_Type_Type_Conversion (N); | |
4129 | ||
4130 | -- Only remaining step is validity checks on the argument. These | |
4131 | -- are skipped if the conversion does not come from the source. | |
4132 | ||
4133 | if not Comes_From_Source (N) then | |
4134 | return; | |
4135 | ||
b67a385c ES |
4136 | -- If there was an error in a generic unit, no need to replicate the |
4137 | -- error message. Conversely, constant-folding in the generic may | |
4138 | -- transform the argument of a conversion into a string literal, which | |
4139 | -- is legal. Therefore the following tests are not performed in an | |
4140 | -- instance. | |
4141 | ||
4142 | elsif In_Instance then | |
4143 | return; | |
4144 | ||
996ae0b0 RK |
4145 | elsif Nkind (Expr) = N_Null then |
4146 | Error_Msg_N ("argument of conversion cannot be null", N); | |
ed2233dc | 4147 | Error_Msg_N ("\use qualified expression instead", N); |
996ae0b0 RK |
4148 | Set_Etype (N, Any_Type); |
4149 | ||
4150 | elsif Nkind (Expr) = N_Aggregate then | |
4151 | Error_Msg_N ("argument of conversion cannot be aggregate", N); | |
ed2233dc | 4152 | Error_Msg_N ("\use qualified expression instead", N); |
996ae0b0 RK |
4153 | |
4154 | elsif Nkind (Expr) = N_Allocator then | |
4155 | Error_Msg_N ("argument of conversion cannot be an allocator", N); | |
ed2233dc | 4156 | Error_Msg_N ("\use qualified expression instead", N); |
996ae0b0 RK |
4157 | |
4158 | elsif Nkind (Expr) = N_String_Literal then | |
4159 | Error_Msg_N ("argument of conversion cannot be string literal", N); | |
ed2233dc | 4160 | Error_Msg_N ("\use qualified expression instead", N); |
996ae0b0 RK |
4161 | |
4162 | elsif Nkind (Expr) = N_Character_Literal then | |
0ab80019 | 4163 | if Ada_Version = Ada_83 then |
996ae0b0 RK |
4164 | Resolve (Expr, T); |
4165 | else | |
4166 | Error_Msg_N ("argument of conversion cannot be character literal", | |
4167 | N); | |
ed2233dc | 4168 | Error_Msg_N ("\use qualified expression instead", N); |
996ae0b0 RK |
4169 | end if; |
4170 | ||
4171 | elsif Nkind (Expr) = N_Attribute_Reference | |
4172 | and then | |
4173 | (Attribute_Name (Expr) = Name_Access or else | |
4174 | Attribute_Name (Expr) = Name_Unchecked_Access or else | |
4175 | Attribute_Name (Expr) = Name_Unrestricted_Access) | |
4176 | then | |
4177 | Error_Msg_N ("argument of conversion cannot be access", N); | |
ed2233dc | 4178 | Error_Msg_N ("\use qualified expression instead", N); |
996ae0b0 | 4179 | end if; |
996ae0b0 RK |
4180 | end Analyze_Type_Conversion; |
4181 | ||
4182 | ---------------------- | |
4183 | -- Analyze_Unary_Op -- | |
4184 | ---------------------- | |
4185 | ||
4186 | procedure Analyze_Unary_Op (N : Node_Id) is | |
4187 | R : constant Node_Id := Right_Opnd (N); | |
4188 | Op_Id : Entity_Id := Entity (N); | |
4189 | ||
4190 | begin | |
4191 | Set_Etype (N, Any_Type); | |
4192 | Candidate_Type := Empty; | |
4193 | ||
4194 | Analyze_Expression (R); | |
4195 | ||
4196 | if Present (Op_Id) then | |
4197 | if Ekind (Op_Id) = E_Operator then | |
4198 | Find_Unary_Types (R, Op_Id, N); | |
4199 | else | |
4200 | Add_One_Interp (N, Op_Id, Etype (Op_Id)); | |
4201 | end if; | |
4202 | ||
4203 | else | |
4204 | Op_Id := Get_Name_Entity_Id (Chars (N)); | |
996ae0b0 | 4205 | while Present (Op_Id) loop |
996ae0b0 RK |
4206 | if Ekind (Op_Id) = E_Operator then |
4207 | if No (Next_Entity (First_Entity (Op_Id))) then | |
4208 | Find_Unary_Types (R, Op_Id, N); | |
4209 | end if; | |
4210 | ||
4211 | elsif Is_Overloadable (Op_Id) then | |
4212 | Analyze_User_Defined_Unary_Op (N, Op_Id); | |
4213 | end if; | |
4214 | ||
4215 | Op_Id := Homonym (Op_Id); | |
4216 | end loop; | |
4217 | end if; | |
4218 | ||
4219 | Operator_Check (N); | |
4220 | end Analyze_Unary_Op; | |
4221 | ||
4222 | ---------------------------------- | |
4223 | -- Analyze_Unchecked_Expression -- | |
4224 | ---------------------------------- | |
4225 | ||
4226 | procedure Analyze_Unchecked_Expression (N : Node_Id) is | |
4227 | begin | |
4228 | Analyze (Expression (N), Suppress => All_Checks); | |
4229 | Set_Etype (N, Etype (Expression (N))); | |
4230 | Save_Interps (Expression (N), N); | |
4231 | end Analyze_Unchecked_Expression; | |
4232 | ||
4233 | --------------------------------------- | |
4234 | -- Analyze_Unchecked_Type_Conversion -- | |
4235 | --------------------------------------- | |
4236 | ||
4237 | procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is | |
4238 | begin | |
4239 | Find_Type (Subtype_Mark (N)); | |
4240 | Analyze_Expression (Expression (N)); | |
4241 | Set_Etype (N, Entity (Subtype_Mark (N))); | |
4242 | end Analyze_Unchecked_Type_Conversion; | |
4243 | ||
4244 | ------------------------------------ | |
4245 | -- Analyze_User_Defined_Binary_Op -- | |
4246 | ------------------------------------ | |
4247 | ||
4248 | procedure Analyze_User_Defined_Binary_Op | |
4249 | (N : Node_Id; | |
4250 | Op_Id : Entity_Id) | |
4251 | is | |
4252 | begin | |
4253 | -- Only do analysis if the operator Comes_From_Source, since otherwise | |
4254 | -- the operator was generated by the expander, and all such operators | |
4255 | -- always refer to the operators in package Standard. | |
4256 | ||
4257 | if Comes_From_Source (N) then | |
4258 | declare | |
4259 | F1 : constant Entity_Id := First_Formal (Op_Id); | |
4260 | F2 : constant Entity_Id := Next_Formal (F1); | |
4261 | ||
4262 | begin | |
4263 | -- Verify that Op_Id is a visible binary function. Note that since | |
4264 | -- we know Op_Id is overloaded, potentially use visible means use | |
4265 | -- visible for sure (RM 9.4(11)). | |
4266 | ||
4267 | if Ekind (Op_Id) = E_Function | |
4268 | and then Present (F2) | |
4269 | and then (Is_Immediately_Visible (Op_Id) | |
4270 | or else Is_Potentially_Use_Visible (Op_Id)) | |
4271 | and then Has_Compatible_Type (Left_Opnd (N), Etype (F1)) | |
4272 | and then Has_Compatible_Type (Right_Opnd (N), Etype (F2)) | |
4273 | then | |
4274 | Add_One_Interp (N, Op_Id, Etype (Op_Id)); | |
4275 | ||
7340e432 AC |
4276 | -- If the left operand is overloaded, indicate that the |
4277 | -- current type is a viable candidate. This is redundant | |
4278 | -- in most cases, but for equality and comparison operators | |
4279 | -- where the context does not impose a type on the operands, | |
4280 | -- setting the proper type is necessary to avoid subsequent | |
4281 | -- ambiguities during resolution, when both user-defined and | |
4282 | -- predefined operators may be candidates. | |
4283 | ||
4284 | if Is_Overloaded (Left_Opnd (N)) then | |
4285 | Set_Etype (Left_Opnd (N), Etype (F1)); | |
4286 | end if; | |
4287 | ||
996ae0b0 RK |
4288 | if Debug_Flag_E then |
4289 | Write_Str ("user defined operator "); | |
4290 | Write_Name (Chars (Op_Id)); | |
4291 | Write_Str (" on node "); | |
4292 | Write_Int (Int (N)); | |
4293 | Write_Eol; | |
4294 | end if; | |
4295 | end if; | |
4296 | end; | |
4297 | end if; | |
4298 | end Analyze_User_Defined_Binary_Op; | |
4299 | ||
4300 | ----------------------------------- | |
4301 | -- Analyze_User_Defined_Unary_Op -- | |
4302 | ----------------------------------- | |
4303 | ||
4304 | procedure Analyze_User_Defined_Unary_Op | |
4305 | (N : Node_Id; | |
4306 | Op_Id : Entity_Id) | |
4307 | is | |
4308 | begin | |
4309 | -- Only do analysis if the operator Comes_From_Source, since otherwise | |
4310 | -- the operator was generated by the expander, and all such operators | |
4311 | -- always refer to the operators in package Standard. | |
4312 | ||
4313 | if Comes_From_Source (N) then | |
4314 | declare | |
4315 | F : constant Entity_Id := First_Formal (Op_Id); | |
4316 | ||
4317 | begin | |
4318 | -- Verify that Op_Id is a visible unary function. Note that since | |
4319 | -- we know Op_Id is overloaded, potentially use visible means use | |
4320 | -- visible for sure (RM 9.4(11)). | |
4321 | ||
4322 | if Ekind (Op_Id) = E_Function | |
4323 | and then No (Next_Formal (F)) | |
4324 | and then (Is_Immediately_Visible (Op_Id) | |
4325 | or else Is_Potentially_Use_Visible (Op_Id)) | |
4326 | and then Has_Compatible_Type (Right_Opnd (N), Etype (F)) | |
4327 | then | |
4328 | Add_One_Interp (N, Op_Id, Etype (Op_Id)); | |
4329 | end if; | |
4330 | end; | |
4331 | end if; | |
4332 | end Analyze_User_Defined_Unary_Op; | |
4333 | ||
4334 | --------------------------- | |
4335 | -- Check_Arithmetic_Pair -- | |
4336 | --------------------------- | |
4337 | ||
4338 | procedure Check_Arithmetic_Pair | |
4339 | (T1, T2 : Entity_Id; | |
4340 | Op_Id : Entity_Id; | |
4341 | N : Node_Id) | |
4342 | is | |
401093c1 | 4343 | Op_Name : constant Name_Id := Chars (Op_Id); |
996ae0b0 | 4344 | |
da709d08 AC |
4345 | function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean; |
4346 | -- Check whether the fixed-point type Typ has a user-defined operator | |
4347 | -- (multiplication or division) that should hide the corresponding | |
4348 | -- predefined operator. Used to implement Ada 2005 AI-264, to make | |
4349 | -- such operators more visible and therefore useful. | |
4350 | ||
50cff367 GD |
4351 | -- If the name of the operation is an expanded name with prefix |
4352 | -- Standard, the predefined universal fixed operator is available, | |
4353 | -- as specified by AI-420 (RM 4.5.5 (19.1/2)). | |
4354 | ||
996ae0b0 RK |
4355 | function Specific_Type (T1, T2 : Entity_Id) return Entity_Id; |
4356 | -- Get specific type (i.e. non-universal type if there is one) | |
4357 | ||
da709d08 AC |
4358 | ------------------ |
4359 | -- Has_Fixed_Op -- | |
4360 | ------------------ | |
4361 | ||
4362 | function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is | |
401093c1 | 4363 | Bas : constant Entity_Id := Base_Type (Typ); |
da709d08 AC |
4364 | Ent : Entity_Id; |
4365 | F1 : Entity_Id; | |
4366 | F2 : Entity_Id; | |
4367 | ||
4368 | begin | |
50cff367 GD |
4369 | -- If the universal_fixed operation is given explicitly the rule |
4370 | -- concerning primitive operations of the type do not apply. | |
4371 | ||
4372 | if Nkind (N) = N_Function_Call | |
4373 | and then Nkind (Name (N)) = N_Expanded_Name | |
4374 | and then Entity (Prefix (Name (N))) = Standard_Standard | |
4375 | then | |
4376 | return False; | |
4377 | end if; | |
4378 | ||
da709d08 AC |
4379 | -- The operation is treated as primitive if it is declared in the |
4380 | -- same scope as the type, and therefore on the same entity chain. | |
4381 | ||
4382 | Ent := Next_Entity (Typ); | |
4383 | while Present (Ent) loop | |
4384 | if Chars (Ent) = Chars (Op) then | |
4385 | F1 := First_Formal (Ent); | |
4386 | F2 := Next_Formal (F1); | |
4387 | ||
4388 | -- The operation counts as primitive if either operand or | |
401093c1 ES |
4389 | -- result are of the given base type, and both operands are |
4390 | -- fixed point types. | |
da709d08 | 4391 | |
401093c1 | 4392 | if (Base_Type (Etype (F1)) = Bas |
da709d08 AC |
4393 | and then Is_Fixed_Point_Type (Etype (F2))) |
4394 | ||
4395 | or else | |
401093c1 | 4396 | (Base_Type (Etype (F2)) = Bas |
da709d08 AC |
4397 | and then Is_Fixed_Point_Type (Etype (F1))) |
4398 | ||
4399 | or else | |
401093c1 | 4400 | (Base_Type (Etype (Ent)) = Bas |
da709d08 AC |
4401 | and then Is_Fixed_Point_Type (Etype (F1)) |
4402 | and then Is_Fixed_Point_Type (Etype (F2))) | |
4403 | then | |
4404 | return True; | |
4405 | end if; | |
4406 | end if; | |
4407 | ||
4408 | Next_Entity (Ent); | |
4409 | end loop; | |
4410 | ||
4411 | return False; | |
4412 | end Has_Fixed_Op; | |
4413 | ||
4c46b835 AC |
4414 | ------------------- |
4415 | -- Specific_Type -- | |
4416 | ------------------- | |
4417 | ||
996ae0b0 RK |
4418 | function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is |
4419 | begin | |
4420 | if T1 = Universal_Integer or else T1 = Universal_Real then | |
4421 | return Base_Type (T2); | |
4422 | else | |
4423 | return Base_Type (T1); | |
4424 | end if; | |
4425 | end Specific_Type; | |
4426 | ||
4427 | -- Start of processing for Check_Arithmetic_Pair | |
4428 | ||
4429 | begin | |
4430 | if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then | |
4431 | ||
4432 | if Is_Numeric_Type (T1) | |
4433 | and then Is_Numeric_Type (T2) | |
b4592168 GD |
4434 | and then (Covers (T1 => T1, T2 => T2) |
4435 | or else | |
4436 | Covers (T1 => T2, T2 => T1)) | |
996ae0b0 RK |
4437 | then |
4438 | Add_One_Interp (N, Op_Id, Specific_Type (T1, T2)); | |
4439 | end if; | |
4440 | ||
4441 | elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then | |
4442 | ||
4443 | if Is_Fixed_Point_Type (T1) | |
4444 | and then (Is_Fixed_Point_Type (T2) | |
4445 | or else T2 = Universal_Real) | |
4446 | then | |
4447 | -- If Treat_Fixed_As_Integer is set then the Etype is already set | |
4448 | -- and no further processing is required (this is the case of an | |
4449 | -- operator constructed by Exp_Fixd for a fixed point operation) | |
4450 | -- Otherwise add one interpretation with universal fixed result | |
4451 | -- If the operator is given in functional notation, it comes | |
4452 | -- from source and Fixed_As_Integer cannot apply. | |
4453 | ||
da709d08 AC |
4454 | if (Nkind (N) not in N_Op |
4455 | or else not Treat_Fixed_As_Integer (N)) | |
4456 | and then | |
401093c1 | 4457 | (not Has_Fixed_Op (T1, Op_Id) |
da709d08 | 4458 | or else Nkind (Parent (N)) = N_Type_Conversion) |
fbf5a39b | 4459 | then |
996ae0b0 RK |
4460 | Add_One_Interp (N, Op_Id, Universal_Fixed); |
4461 | end if; | |
4462 | ||
4463 | elsif Is_Fixed_Point_Type (T2) | |
4464 | and then (Nkind (N) not in N_Op | |
4465 | or else not Treat_Fixed_As_Integer (N)) | |
4466 | and then T1 = Universal_Real | |
da709d08 | 4467 | and then |
401093c1 | 4468 | (not Has_Fixed_Op (T1, Op_Id) |
da709d08 | 4469 | or else Nkind (Parent (N)) = N_Type_Conversion) |
996ae0b0 RK |
4470 | then |
4471 | Add_One_Interp (N, Op_Id, Universal_Fixed); | |
4472 | ||
4473 | elsif Is_Numeric_Type (T1) | |
4474 | and then Is_Numeric_Type (T2) | |
b4592168 GD |
4475 | and then (Covers (T1 => T1, T2 => T2) |
4476 | or else | |
4477 | Covers (T1 => T2, T2 => T1)) | |
996ae0b0 RK |
4478 | then |
4479 | Add_One_Interp (N, Op_Id, Specific_Type (T1, T2)); | |
4480 | ||
4481 | elsif Is_Fixed_Point_Type (T1) | |
4482 | and then (Base_Type (T2) = Base_Type (Standard_Integer) | |
4483 | or else T2 = Universal_Integer) | |
4484 | then | |
4485 | Add_One_Interp (N, Op_Id, T1); | |
4486 | ||
4487 | elsif T2 = Universal_Real | |
4488 | and then Base_Type (T1) = Base_Type (Standard_Integer) | |
4489 | and then Op_Name = Name_Op_Multiply | |
4490 | then | |
4491 | Add_One_Interp (N, Op_Id, Any_Fixed); | |
4492 | ||
4493 | elsif T1 = Universal_Real | |
4494 | and then Base_Type (T2) = Base_Type (Standard_Integer) | |
4495 | then | |
4496 | Add_One_Interp (N, Op_Id, Any_Fixed); | |
4497 | ||
4498 | elsif Is_Fixed_Point_Type (T2) | |
4499 | and then (Base_Type (T1) = Base_Type (Standard_Integer) | |
4500 | or else T1 = Universal_Integer) | |
4501 | and then Op_Name = Name_Op_Multiply | |
4502 | then | |
4503 | Add_One_Interp (N, Op_Id, T2); | |
4504 | ||
4505 | elsif T1 = Universal_Real and then T2 = Universal_Integer then | |
4506 | Add_One_Interp (N, Op_Id, T1); | |
4507 | ||
4508 | elsif T2 = Universal_Real | |
4509 | and then T1 = Universal_Integer | |
4510 | and then Op_Name = Name_Op_Multiply | |
4511 | then | |
4512 | Add_One_Interp (N, Op_Id, T2); | |
4513 | end if; | |
4514 | ||
4515 | elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then | |
4516 | ||
4517 | -- Note: The fixed-point operands case with Treat_Fixed_As_Integer | |
4518 | -- set does not require any special processing, since the Etype is | |
4519 | -- already set (case of operation constructed by Exp_Fixed). | |
4520 | ||
4521 | if Is_Integer_Type (T1) | |
b4592168 GD |
4522 | and then (Covers (T1 => T1, T2 => T2) |
4523 | or else | |
4524 | Covers (T1 => T2, T2 => T1)) | |
996ae0b0 RK |
4525 | then |
4526 | Add_One_Interp (N, Op_Id, Specific_Type (T1, T2)); | |
4527 | end if; | |
4528 | ||
4529 | elsif Op_Name = Name_Op_Expon then | |
996ae0b0 RK |
4530 | if Is_Numeric_Type (T1) |
4531 | and then not Is_Fixed_Point_Type (T1) | |
4532 | and then (Base_Type (T2) = Base_Type (Standard_Integer) | |
4533 | or else T2 = Universal_Integer) | |
4534 | then | |
4535 | Add_One_Interp (N, Op_Id, Base_Type (T1)); | |
4536 | end if; | |
4537 | ||
4538 | else pragma Assert (Nkind (N) in N_Op_Shift); | |
4539 | ||
4540 | -- If not one of the predefined operators, the node may be one | |
4541 | -- of the intrinsic functions. Its kind is always specific, and | |
4542 | -- we can use it directly, rather than the name of the operation. | |
4543 | ||
4544 | if Is_Integer_Type (T1) | |
4545 | and then (Base_Type (T2) = Base_Type (Standard_Integer) | |
4546 | or else T2 = Universal_Integer) | |
4547 | then | |
4548 | Add_One_Interp (N, Op_Id, Base_Type (T1)); | |
4549 | end if; | |
4550 | end if; | |
4551 | end Check_Arithmetic_Pair; | |
4552 | ||
4553 | ------------------------------- | |
4554 | -- Check_Misspelled_Selector -- | |
4555 | ------------------------------- | |
4556 | ||
4557 | procedure Check_Misspelled_Selector | |
4558 | (Prefix : Entity_Id; | |
4559 | Sel : Node_Id) | |
4560 | is | |
4561 | Max_Suggestions : constant := 2; | |
4562 | Nr_Of_Suggestions : Natural := 0; | |
4563 | ||
4564 | Suggestion_1 : Entity_Id := Empty; | |
4565 | Suggestion_2 : Entity_Id := Empty; | |
4566 | ||
4567 | Comp : Entity_Id; | |
4568 | ||
4569 | begin | |
4570 | -- All the components of the prefix of selector Sel are matched | |
4571 | -- against Sel and a count is maintained of possible misspellings. | |
4572 | -- When at the end of the analysis there are one or two (not more!) | |
4573 | -- possible misspellings, these misspellings will be suggested as | |
4574 | -- possible correction. | |
4575 | ||
4c46b835 AC |
4576 | if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then |
4577 | ||
996ae0b0 | 4578 | -- Concurrent types should be handled as well ??? |
4c46b835 | 4579 | |
996ae0b0 RK |
4580 | return; |
4581 | end if; | |
4582 | ||
d469eabe HK |
4583 | Comp := First_Entity (Prefix); |
4584 | while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop | |
4585 | if Is_Visible_Component (Comp) then | |
4586 | if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then | |
4587 | Nr_Of_Suggestions := Nr_Of_Suggestions + 1; | |
4588 | ||
4589 | case Nr_Of_Suggestions is | |
4590 | when 1 => Suggestion_1 := Comp; | |
4591 | when 2 => Suggestion_2 := Comp; | |
4592 | when others => exit; | |
4593 | end case; | |
996ae0b0 | 4594 | end if; |
d469eabe | 4595 | end if; |
996ae0b0 | 4596 | |
d469eabe HK |
4597 | Comp := Next_Entity (Comp); |
4598 | end loop; | |
996ae0b0 | 4599 | |
d469eabe | 4600 | -- Report at most two suggestions |
996ae0b0 | 4601 | |
d469eabe | 4602 | if Nr_Of_Suggestions = 1 then |
4e7a4f6e | 4603 | Error_Msg_NE -- CODEFIX |
d469eabe | 4604 | ("\possible misspelling of&", Sel, Suggestion_1); |
996ae0b0 | 4605 | |
d469eabe HK |
4606 | elsif Nr_Of_Suggestions = 2 then |
4607 | Error_Msg_Node_2 := Suggestion_2; | |
4e7a4f6e | 4608 | Error_Msg_NE -- CODEFIX |
d469eabe HK |
4609 | ("\possible misspelling of& or&", Sel, Suggestion_1); |
4610 | end if; | |
996ae0b0 RK |
4611 | end Check_Misspelled_Selector; |
4612 | ||
4613 | ---------------------- | |
4614 | -- Defined_In_Scope -- | |
4615 | ---------------------- | |
4616 | ||
4617 | function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean | |
4618 | is | |
4619 | S1 : constant Entity_Id := Scope (Base_Type (T)); | |
996ae0b0 RK |
4620 | begin |
4621 | return S1 = S | |
4622 | or else (S1 = System_Aux_Id and then S = Scope (S1)); | |
4623 | end Defined_In_Scope; | |
4624 | ||
4625 | ------------------- | |
4626 | -- Diagnose_Call -- | |
4627 | ------------------- | |
4628 | ||
4629 | procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is | |
fbf5a39b AC |
4630 | Actual : Node_Id; |
4631 | X : Interp_Index; | |
4632 | It : Interp; | |
fbf5a39b AC |
4633 | Err_Mode : Boolean; |
4634 | New_Nam : Node_Id; | |
4635 | Void_Interp_Seen : Boolean := False; | |
996ae0b0 | 4636 | |
24657705 HK |
4637 | Success : Boolean; |
4638 | pragma Warnings (Off, Boolean); | |
4639 | ||
996ae0b0 | 4640 | begin |
0ab80019 | 4641 | if Ada_Version >= Ada_05 then |
996ae0b0 | 4642 | Actual := First_Actual (N); |
996ae0b0 | 4643 | while Present (Actual) loop |
0ab80019 AC |
4644 | |
4645 | -- Ada 2005 (AI-50217): Post an error in case of premature | |
4646 | -- usage of an entity from the limited view. | |
19f0526a | 4647 | |
996ae0b0 RK |
4648 | if not Analyzed (Etype (Actual)) |
4649 | and then From_With_Type (Etype (Actual)) | |
4650 | then | |
4651 | Error_Msg_Qual_Level := 1; | |
ed2233dc | 4652 | Error_Msg_NE |
996ae0b0 RK |
4653 | ("missing with_clause for scope of imported type&", |
4654 | Actual, Etype (Actual)); | |
4655 | Error_Msg_Qual_Level := 0; | |
4656 | end if; | |
4657 | ||
4658 | Next_Actual (Actual); | |
4659 | end loop; | |
4660 | end if; | |
4661 | ||
fbf5a39b AC |
4662 | -- Analyze each candidate call again, with full error reporting |
4663 | -- for each. | |
4664 | ||
4665 | Error_Msg_N | |
4666 | ("no candidate interpretations match the actuals:!", Nam); | |
4667 | Err_Mode := All_Errors_Mode; | |
4668 | All_Errors_Mode := True; | |
4669 | ||
4670 | -- If this is a call to an operation of a concurrent type, | |
4671 | -- the failed interpretations have been removed from the | |
4672 | -- name. Recover them to provide full diagnostics. | |
4673 | ||
4674 | if Nkind (Parent (Nam)) = N_Selected_Component then | |
4675 | Set_Entity (Nam, Empty); | |
4676 | New_Nam := New_Copy_Tree (Parent (Nam)); | |
4677 | Set_Is_Overloaded (New_Nam, False); | |
4678 | Set_Is_Overloaded (Selector_Name (New_Nam), False); | |
4679 | Set_Parent (New_Nam, Parent (Parent (Nam))); | |
4680 | Analyze_Selected_Component (New_Nam); | |
4681 | Get_First_Interp (Selector_Name (New_Nam), X, It); | |
4682 | else | |
996ae0b0 | 4683 | Get_First_Interp (Nam, X, It); |
fbf5a39b | 4684 | end if; |
996ae0b0 | 4685 | |
fbf5a39b AC |
4686 | while Present (It.Nam) loop |
4687 | if Etype (It.Nam) = Standard_Void_Type then | |
4688 | Void_Interp_Seen := True; | |
996ae0b0 | 4689 | end if; |
fbf5a39b AC |
4690 | |
4691 | Analyze_One_Call (N, It.Nam, True, Success); | |
4692 | Get_Next_Interp (X, It); | |
4693 | end loop; | |
996ae0b0 RK |
4694 | |
4695 | if Nkind (N) = N_Function_Call then | |
4696 | Get_First_Interp (Nam, X, It); | |
996ae0b0 | 4697 | while Present (It.Nam) loop |
bce79204 | 4698 | if Ekind_In (It.Nam, E_Function, E_Operator) then |
996ae0b0 RK |
4699 | return; |
4700 | else | |
4701 | Get_Next_Interp (X, It); | |
4702 | end if; | |
4703 | end loop; | |
4704 | ||
4705 | -- If all interpretations are procedures, this deserves a | |
4706 | -- more precise message. Ditto if this appears as the prefix | |
4707 | -- of a selected component, which may be a lexical error. | |
4708 | ||
4c46b835 AC |
4709 | Error_Msg_N |
4710 | ("\context requires function call, found procedure name", Nam); | |
996ae0b0 RK |
4711 | |
4712 | if Nkind (Parent (N)) = N_Selected_Component | |
4713 | and then N = Prefix (Parent (N)) | |
4714 | then | |
4e7a4f6e AC |
4715 | Error_Msg_N -- CODEFIX |
4716 | ("\period should probably be semicolon", Parent (N)); | |
996ae0b0 | 4717 | end if; |
fbf5a39b AC |
4718 | |
4719 | elsif Nkind (N) = N_Procedure_Call_Statement | |
4720 | and then not Void_Interp_Seen | |
4721 | then | |
4722 | Error_Msg_N ( | |
4723 | "\function name found in procedure call", Nam); | |
996ae0b0 | 4724 | end if; |
fbf5a39b AC |
4725 | |
4726 | All_Errors_Mode := Err_Mode; | |
996ae0b0 RK |
4727 | end Diagnose_Call; |
4728 | ||
4729 | --------------------------- | |
4730 | -- Find_Arithmetic_Types -- | |
4731 | --------------------------- | |
4732 | ||
4733 | procedure Find_Arithmetic_Types | |
4734 | (L, R : Node_Id; | |
4735 | Op_Id : Entity_Id; | |
4736 | N : Node_Id) | |
4737 | is | |
4c46b835 AC |
4738 | Index1 : Interp_Index; |
4739 | Index2 : Interp_Index; | |
4740 | It1 : Interp; | |
4741 | It2 : Interp; | |
996ae0b0 RK |
4742 | |
4743 | procedure Check_Right_Argument (T : Entity_Id); | |
4744 | -- Check right operand of operator | |
4745 | ||
4c46b835 AC |
4746 | -------------------------- |
4747 | -- Check_Right_Argument -- | |
4748 | -------------------------- | |
4749 | ||
996ae0b0 RK |
4750 | procedure Check_Right_Argument (T : Entity_Id) is |
4751 | begin | |
4752 | if not Is_Overloaded (R) then | |
4753 | Check_Arithmetic_Pair (T, Etype (R), Op_Id, N); | |
4754 | else | |
4755 | Get_First_Interp (R, Index2, It2); | |
996ae0b0 RK |
4756 | while Present (It2.Typ) loop |
4757 | Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N); | |
4758 | Get_Next_Interp (Index2, It2); | |
4759 | end loop; | |
4760 | end if; | |
4761 | end Check_Right_Argument; | |
4762 | ||
d8221f45 | 4763 | -- Start of processing for Find_Arithmetic_Types |
996ae0b0 RK |
4764 | |
4765 | begin | |
4766 | if not Is_Overloaded (L) then | |
4767 | Check_Right_Argument (Etype (L)); | |
4768 | ||
4769 | else | |
4770 | Get_First_Interp (L, Index1, It1); | |
996ae0b0 RK |
4771 | while Present (It1.Typ) loop |
4772 | Check_Right_Argument (It1.Typ); | |
4773 | Get_Next_Interp (Index1, It1); | |
4774 | end loop; | |
4775 | end if; | |
4776 | ||
4777 | end Find_Arithmetic_Types; | |
4778 | ||
4779 | ------------------------ | |
4780 | -- Find_Boolean_Types -- | |
4781 | ------------------------ | |
4782 | ||
4783 | procedure Find_Boolean_Types | |
4784 | (L, R : Node_Id; | |
4785 | Op_Id : Entity_Id; | |
4786 | N : Node_Id) | |
4787 | is | |
4788 | Index : Interp_Index; | |
4789 | It : Interp; | |
4790 | ||
4791 | procedure Check_Numeric_Argument (T : Entity_Id); | |
4792 | -- Special case for logical operations one of whose operands is an | |
4793 | -- integer literal. If both are literal the result is any modular type. | |
4794 | ||
4c46b835 AC |
4795 | ---------------------------- |
4796 | -- Check_Numeric_Argument -- | |
4797 | ---------------------------- | |
4798 | ||
996ae0b0 RK |
4799 | procedure Check_Numeric_Argument (T : Entity_Id) is |
4800 | begin | |
4801 | if T = Universal_Integer then | |
4802 | Add_One_Interp (N, Op_Id, Any_Modular); | |
4803 | ||
4804 | elsif Is_Modular_Integer_Type (T) then | |
4805 | Add_One_Interp (N, Op_Id, T); | |
4806 | end if; | |
4807 | end Check_Numeric_Argument; | |
4808 | ||
4809 | -- Start of processing for Find_Boolean_Types | |
4810 | ||
4811 | begin | |
4812 | if not Is_Overloaded (L) then | |
996ae0b0 RK |
4813 | if Etype (L) = Universal_Integer |
4814 | or else Etype (L) = Any_Modular | |
4815 | then | |
4816 | if not Is_Overloaded (R) then | |
4817 | Check_Numeric_Argument (Etype (R)); | |
4818 | ||
4819 | else | |
4820 | Get_First_Interp (R, Index, It); | |
996ae0b0 RK |
4821 | while Present (It.Typ) loop |
4822 | Check_Numeric_Argument (It.Typ); | |
996ae0b0 RK |
4823 | Get_Next_Interp (Index, It); |
4824 | end loop; | |
4825 | end if; | |
4826 | ||
69e6a03e ES |
4827 | -- If operands are aggregates, we must assume that they may be |
4828 | -- boolean arrays, and leave disambiguation for the second pass. | |
4829 | -- If only one is an aggregate, verify that the other one has an | |
4830 | -- interpretation as a boolean array | |
4831 | ||
4832 | elsif Nkind (L) = N_Aggregate then | |
4833 | if Nkind (R) = N_Aggregate then | |
4834 | Add_One_Interp (N, Op_Id, Etype (L)); | |
4835 | ||
4836 | elsif not Is_Overloaded (R) then | |
4837 | if Valid_Boolean_Arg (Etype (R)) then | |
4838 | Add_One_Interp (N, Op_Id, Etype (R)); | |
4839 | end if; | |
4840 | ||
4841 | else | |
4842 | Get_First_Interp (R, Index, It); | |
4843 | while Present (It.Typ) loop | |
4844 | if Valid_Boolean_Arg (It.Typ) then | |
4845 | Add_One_Interp (N, Op_Id, It.Typ); | |
4846 | end if; | |
4847 | ||
4848 | Get_Next_Interp (Index, It); | |
4849 | end loop; | |
4850 | end if; | |
4851 | ||
996ae0b0 RK |
4852 | elsif Valid_Boolean_Arg (Etype (L)) |
4853 | and then Has_Compatible_Type (R, Etype (L)) | |
4854 | then | |
4855 | Add_One_Interp (N, Op_Id, Etype (L)); | |
4856 | end if; | |
4857 | ||
4858 | else | |
4859 | Get_First_Interp (L, Index, It); | |
996ae0b0 RK |
4860 | while Present (It.Typ) loop |
4861 | if Valid_Boolean_Arg (It.Typ) | |
4862 | and then Has_Compatible_Type (R, It.Typ) | |
4863 | then | |
4864 | Add_One_Interp (N, Op_Id, It.Typ); | |
4865 | end if; | |
4866 | ||
4867 | Get_Next_Interp (Index, It); | |
4868 | end loop; | |
4869 | end if; | |
4870 | end Find_Boolean_Types; | |
4871 | ||
4872 | --------------------------- | |
4873 | -- Find_Comparison_Types -- | |
4874 | --------------------------- | |
4875 | ||
4876 | procedure Find_Comparison_Types | |
4877 | (L, R : Node_Id; | |
4878 | Op_Id : Entity_Id; | |
4879 | N : Node_Id) | |
4880 | is | |
4881 | Index : Interp_Index; | |
4882 | It : Interp; | |
4883 | Found : Boolean := False; | |
4884 | I_F : Interp_Index; | |
4885 | T_F : Entity_Id; | |
4886 | Scop : Entity_Id := Empty; | |
4887 | ||
4888 | procedure Try_One_Interp (T1 : Entity_Id); | |
4889 | -- Routine to try one proposed interpretation. Note that the context | |
4890 | -- of the operator plays no role in resolving the arguments, so that | |
4891 | -- if there is more than one interpretation of the operands that is | |
4892 | -- compatible with comparison, the operation is ambiguous. | |
4893 | ||
4c46b835 AC |
4894 | -------------------- |
4895 | -- Try_One_Interp -- | |
4896 | -------------------- | |
4897 | ||
996ae0b0 RK |
4898 | procedure Try_One_Interp (T1 : Entity_Id) is |
4899 | begin | |
4900 | ||
4901 | -- If the operator is an expanded name, then the type of the operand | |
4902 | -- must be defined in the corresponding scope. If the type is | |
4903 | -- universal, the context will impose the correct type. | |
4904 | ||
4905 | if Present (Scop) | |
4906 | and then not Defined_In_Scope (T1, Scop) | |
4907 | and then T1 /= Universal_Integer | |
4908 | and then T1 /= Universal_Real | |
4909 | and then T1 /= Any_String | |
4910 | and then T1 /= Any_Composite | |
4911 | then | |
4912 | return; | |
4913 | end if; | |
4914 | ||
4915 | if Valid_Comparison_Arg (T1) | |
4916 | and then Has_Compatible_Type (R, T1) | |
4917 | then | |
4918 | if Found | |
4919 | and then Base_Type (T1) /= Base_Type (T_F) | |
4920 | then | |
4921 | It := Disambiguate (L, I_F, Index, Any_Type); | |
4922 | ||
4923 | if It = No_Interp then | |
4924 | Ambiguous_Operands (N); | |
4925 | Set_Etype (L, Any_Type); | |
4926 | return; | |
4927 | ||
4928 | else | |
4929 | T_F := It.Typ; | |
4930 | end if; | |
4931 | ||
4932 | else | |
4933 | Found := True; | |
4934 | T_F := T1; | |
4935 | I_F := Index; | |
4936 | end if; | |
4937 | ||
4938 | Set_Etype (L, T_F); | |
4939 | Find_Non_Universal_Interpretations (N, R, Op_Id, T1); | |
4940 | ||
4941 | end if; | |
4942 | end Try_One_Interp; | |
4943 | ||
d8221f45 | 4944 | -- Start of processing for Find_Comparison_Types |
996ae0b0 RK |
4945 | |
4946 | begin | |
fbf5a39b AC |
4947 | -- If left operand is aggregate, the right operand has to |
4948 | -- provide a usable type for it. | |
4949 | ||
4950 | if Nkind (L) = N_Aggregate | |
4951 | and then Nkind (R) /= N_Aggregate | |
4952 | then | |
b4592168 | 4953 | Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N); |
fbf5a39b AC |
4954 | return; |
4955 | end if; | |
996ae0b0 RK |
4956 | |
4957 | if Nkind (N) = N_Function_Call | |
4958 | and then Nkind (Name (N)) = N_Expanded_Name | |
4959 | then | |
4960 | Scop := Entity (Prefix (Name (N))); | |
4961 | ||
4962 | -- The prefix may be a package renaming, and the subsequent test | |
4963 | -- requires the original package. | |
4964 | ||
4965 | if Ekind (Scop) = E_Package | |
4966 | and then Present (Renamed_Entity (Scop)) | |
4967 | then | |
4968 | Scop := Renamed_Entity (Scop); | |
4969 | Set_Entity (Prefix (Name (N)), Scop); | |
4970 | end if; | |
4971 | end if; | |
4972 | ||
4973 | if not Is_Overloaded (L) then | |
4974 | Try_One_Interp (Etype (L)); | |
4975 | ||
4976 | else | |
4977 | Get_First_Interp (L, Index, It); | |
996ae0b0 RK |
4978 | while Present (It.Typ) loop |
4979 | Try_One_Interp (It.Typ); | |
4980 | Get_Next_Interp (Index, It); | |
4981 | end loop; | |
4982 | end if; | |
4983 | end Find_Comparison_Types; | |
4984 | ||
4985 | ---------------------------------------- | |
4986 | -- Find_Non_Universal_Interpretations -- | |
4987 | ---------------------------------------- | |
4988 | ||
4989 | procedure Find_Non_Universal_Interpretations | |
4990 | (N : Node_Id; | |
4991 | R : Node_Id; | |
4992 | Op_Id : Entity_Id; | |
4993 | T1 : Entity_Id) | |
4994 | is | |
4995 | Index : Interp_Index; | |
4c46b835 | 4996 | It : Interp; |
996ae0b0 RK |
4997 | |
4998 | begin | |
4999 | if T1 = Universal_Integer | |
5000 | or else T1 = Universal_Real | |
5001 | then | |
5002 | if not Is_Overloaded (R) then | |
5003 | Add_One_Interp | |
5004 | (N, Op_Id, Standard_Boolean, Base_Type (Etype (R))); | |
5005 | else | |
5006 | Get_First_Interp (R, Index, It); | |
996ae0b0 RK |
5007 | while Present (It.Typ) loop |
5008 | if Covers (It.Typ, T1) then | |
5009 | Add_One_Interp | |
5010 | (N, Op_Id, Standard_Boolean, Base_Type (It.Typ)); | |
5011 | end if; | |
5012 | ||
5013 | Get_Next_Interp (Index, It); | |
5014 | end loop; | |
5015 | end if; | |
5016 | else | |
5017 | Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1)); | |
5018 | end if; | |
5019 | end Find_Non_Universal_Interpretations; | |
5020 | ||
5021 | ------------------------------ | |
5022 | -- Find_Concatenation_Types -- | |
5023 | ------------------------------ | |
5024 | ||
5025 | procedure Find_Concatenation_Types | |
5026 | (L, R : Node_Id; | |
5027 | Op_Id : Entity_Id; | |
5028 | N : Node_Id) | |
5029 | is | |
5030 | Op_Type : constant Entity_Id := Etype (Op_Id); | |
5031 | ||
5032 | begin | |
5033 | if Is_Array_Type (Op_Type) | |
5034 | and then not Is_Limited_Type (Op_Type) | |
5035 | ||
5036 | and then (Has_Compatible_Type (L, Op_Type) | |
5037 | or else | |
5038 | Has_Compatible_Type (L, Component_Type (Op_Type))) | |
5039 | ||
5040 | and then (Has_Compatible_Type (R, Op_Type) | |
5041 | or else | |
5042 | Has_Compatible_Type (R, Component_Type (Op_Type))) | |
5043 | then | |
5044 | Add_One_Interp (N, Op_Id, Op_Type); | |
5045 | end if; | |
5046 | end Find_Concatenation_Types; | |
5047 | ||
5048 | ------------------------- | |
5049 | -- Find_Equality_Types -- | |
5050 | ------------------------- | |
5051 | ||
5052 | procedure Find_Equality_Types | |
5053 | (L, R : Node_Id; | |
5054 | Op_Id : Entity_Id; | |
5055 | N : Node_Id) | |
5056 | is | |
5057 | Index : Interp_Index; | |
5058 | It : Interp; | |
5059 | Found : Boolean := False; | |
5060 | I_F : Interp_Index; | |
5061 | T_F : Entity_Id; | |
5062 | Scop : Entity_Id := Empty; | |
5063 | ||
5064 | procedure Try_One_Interp (T1 : Entity_Id); | |
a8e65aa5 AC |
5065 | -- The context of the equality operator plays no role in resolving the |
5066 | -- arguments, so that if there is more than one interpretation of the | |
5067 | -- operands that is compatible with equality, the construct is ambiguous | |
5068 | -- and an error can be emitted now, after trying to disambiguate, i.e. | |
5069 | -- applying preference rules. | |
996ae0b0 | 5070 | |
4c46b835 AC |
5071 | -------------------- |
5072 | -- Try_One_Interp -- | |
5073 | -------------------- | |
5074 | ||
996ae0b0 | 5075 | procedure Try_One_Interp (T1 : Entity_Id) is |
a8e65aa5 AC |
5076 | Bas : constant Entity_Id := Base_Type (T1); |
5077 | ||
996ae0b0 | 5078 | begin |
996ae0b0 RK |
5079 | -- If the operator is an expanded name, then the type of the operand |
5080 | -- must be defined in the corresponding scope. If the type is | |
5081 | -- universal, the context will impose the correct type. An anonymous | |
5082 | -- type for a 'Access reference is also universal in this sense, as | |
5083 | -- the actual type is obtained from context. | |
fe45e59e ES |
5084 | -- In Ada 2005, the equality operator for anonymous access types |
5085 | -- is declared in Standard, and preference rules apply to it. | |
996ae0b0 | 5086 | |
fe45e59e ES |
5087 | if Present (Scop) then |
5088 | if Defined_In_Scope (T1, Scop) | |
5089 | or else T1 = Universal_Integer | |
5090 | or else T1 = Universal_Real | |
5091 | or else T1 = Any_Access | |
5092 | or else T1 = Any_String | |
5093 | or else T1 = Any_Composite | |
5094 | or else (Ekind (T1) = E_Access_Subprogram_Type | |
a8e65aa5 | 5095 | and then not Comes_From_Source (T1)) |
fe45e59e ES |
5096 | then |
5097 | null; | |
5098 | ||
5099 | elsif Ekind (T1) = E_Anonymous_Access_Type | |
5100 | and then Scop = Standard_Standard | |
5101 | then | |
5102 | null; | |
5103 | ||
5104 | else | |
5105 | -- The scope does not contain an operator for the type | |
5106 | ||
5107 | return; | |
5108 | end if; | |
a8e65aa5 AC |
5109 | |
5110 | -- If we have infix notation, the operator must be usable. | |
5111 | -- Within an instance, if the type is already established we | |
5112 | -- know it is correct. | |
5113 | -- In Ada 2005, the equality on anonymous access types is declared | |
5114 | -- in Standard, and is always visible. | |
5115 | ||
5116 | elsif In_Open_Scopes (Scope (Bas)) | |
5117 | or else Is_Potentially_Use_Visible (Bas) | |
5118 | or else In_Use (Bas) | |
5119 | or else (In_Use (Scope (Bas)) | |
5120 | and then not Is_Hidden (Bas)) | |
5121 | or else (In_Instance | |
5122 | and then First_Subtype (T1) = First_Subtype (Etype (R))) | |
5123 | or else Ekind (T1) = E_Anonymous_Access_Type | |
5124 | then | |
5125 | null; | |
5126 | ||
5127 | else | |
2794f022 | 5128 | -- Save candidate type for subsquent error message, if any |
a8e65aa5 AC |
5129 | |
5130 | if not Is_Limited_Type (T1) then | |
5131 | Candidate_Type := T1; | |
5132 | end if; | |
5133 | ||
5134 | return; | |
996ae0b0 RK |
5135 | end if; |
5136 | ||
0ab80019 AC |
5137 | -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95: |
5138 | -- Do not allow anonymous access types in equality operators. | |
6e937c1c | 5139 | |
0ab80019 | 5140 | if Ada_Version < Ada_05 |
6e937c1c AC |
5141 | and then Ekind (T1) = E_Anonymous_Access_Type |
5142 | then | |
5143 | return; | |
5144 | end if; | |
5145 | ||
996ae0b0 RK |
5146 | if T1 /= Standard_Void_Type |
5147 | and then not Is_Limited_Type (T1) | |
5148 | and then not Is_Limited_Composite (T1) | |
996ae0b0 RK |
5149 | and then Has_Compatible_Type (R, T1) |
5150 | then | |
5151 | if Found | |
5152 | and then Base_Type (T1) /= Base_Type (T_F) | |
5153 | then | |
5154 | It := Disambiguate (L, I_F, Index, Any_Type); | |
5155 | ||
5156 | if It = No_Interp then | |
5157 | Ambiguous_Operands (N); | |
5158 | Set_Etype (L, Any_Type); | |
5159 | return; | |
5160 | ||
5161 | else | |
5162 | T_F := It.Typ; | |
5163 | end if; | |
5164 | ||
5165 | else | |
5166 | Found := True; | |
5167 | T_F := T1; | |
5168 | I_F := Index; | |
5169 | end if; | |
5170 | ||
5171 | if not Analyzed (L) then | |
5172 | Set_Etype (L, T_F); | |
5173 | end if; | |
5174 | ||
5175 | Find_Non_Universal_Interpretations (N, R, Op_Id, T1); | |
5176 | ||
6e73e3ab | 5177 | -- Case of operator was not visible, Etype still set to Any_Type |
996ae0b0 | 5178 | |
6e73e3ab | 5179 | if Etype (N) = Any_Type then |
996ae0b0 RK |
5180 | Found := False; |
5181 | end if; | |
fe45e59e ES |
5182 | |
5183 | elsif Scop = Standard_Standard | |
5184 | and then Ekind (T1) = E_Anonymous_Access_Type | |
5185 | then | |
5186 | Found := True; | |
996ae0b0 RK |
5187 | end if; |
5188 | end Try_One_Interp; | |
5189 | ||
5190 | -- Start of processing for Find_Equality_Types | |
5191 | ||
5192 | begin | |
fbf5a39b AC |
5193 | -- If left operand is aggregate, the right operand has to |
5194 | -- provide a usable type for it. | |
5195 | ||
5196 | if Nkind (L) = N_Aggregate | |
5197 | and then Nkind (R) /= N_Aggregate | |
5198 | then | |
b4592168 | 5199 | Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N); |
fbf5a39b AC |
5200 | return; |
5201 | end if; | |
996ae0b0 RK |
5202 | |
5203 | if Nkind (N) = N_Function_Call | |
5204 | and then Nkind (Name (N)) = N_Expanded_Name | |
5205 | then | |
5206 | Scop := Entity (Prefix (Name (N))); | |
5207 | ||
5208 | -- The prefix may be a package renaming, and the subsequent test | |
5209 | -- requires the original package. | |
5210 | ||
5211 | if Ekind (Scop) = E_Package | |
5212 | and then Present (Renamed_Entity (Scop)) | |
5213 | then | |
5214 | Scop := Renamed_Entity (Scop); | |
5215 | Set_Entity (Prefix (Name (N)), Scop); | |
5216 | end if; | |
5217 | end if; | |
5218 | ||
5219 | if not Is_Overloaded (L) then | |
5220 | Try_One_Interp (Etype (L)); | |
996ae0b0 | 5221 | |
4c46b835 | 5222 | else |
996ae0b0 | 5223 | Get_First_Interp (L, Index, It); |
996ae0b0 RK |
5224 | while Present (It.Typ) loop |
5225 | Try_One_Interp (It.Typ); | |
5226 | Get_Next_Interp (Index, It); | |
5227 | end loop; | |
5228 | end if; | |
5229 | end Find_Equality_Types; | |
5230 | ||
5231 | ------------------------- | |
5232 | -- Find_Negation_Types -- | |
5233 | ------------------------- | |
5234 | ||
5235 | procedure Find_Negation_Types | |
5236 | (R : Node_Id; | |
5237 | Op_Id : Entity_Id; | |
5238 | N : Node_Id) | |
5239 | is | |
5240 | Index : Interp_Index; | |
5241 | It : Interp; | |
5242 | ||
5243 | begin | |
5244 | if not Is_Overloaded (R) then | |
996ae0b0 RK |
5245 | if Etype (R) = Universal_Integer then |
5246 | Add_One_Interp (N, Op_Id, Any_Modular); | |
996ae0b0 RK |
5247 | elsif Valid_Boolean_Arg (Etype (R)) then |
5248 | Add_One_Interp (N, Op_Id, Etype (R)); | |
5249 | end if; | |
5250 | ||
5251 | else | |
5252 | Get_First_Interp (R, Index, It); | |
996ae0b0 RK |
5253 | while Present (It.Typ) loop |
5254 | if Valid_Boolean_Arg (It.Typ) then | |
5255 | Add_One_Interp (N, Op_Id, It.Typ); | |
5256 | end if; | |
5257 | ||
5258 | Get_Next_Interp (Index, It); | |
5259 | end loop; | |
5260 | end if; | |
5261 | end Find_Negation_Types; | |
5262 | ||
d469eabe HK |
5263 | ------------------------------ |
5264 | -- Find_Primitive_Operation -- | |
5265 | ------------------------------ | |
5266 | ||
5267 | function Find_Primitive_Operation (N : Node_Id) return Boolean is | |
5268 | Obj : constant Node_Id := Prefix (N); | |
5269 | Op : constant Node_Id := Selector_Name (N); | |
5270 | ||
5271 | Prim : Elmt_Id; | |
5272 | Prims : Elist_Id; | |
5273 | Typ : Entity_Id; | |
5274 | ||
5275 | begin | |
5276 | Set_Etype (Op, Any_Type); | |
5277 | ||
5278 | if Is_Access_Type (Etype (Obj)) then | |
5279 | Typ := Designated_Type (Etype (Obj)); | |
5280 | else | |
5281 | Typ := Etype (Obj); | |
5282 | end if; | |
5283 | ||
5284 | if Is_Class_Wide_Type (Typ) then | |
5285 | Typ := Root_Type (Typ); | |
5286 | end if; | |
5287 | ||
5288 | Prims := Primitive_Operations (Typ); | |
5289 | ||
5290 | Prim := First_Elmt (Prims); | |
5291 | while Present (Prim) loop | |
5292 | if Chars (Node (Prim)) = Chars (Op) then | |
5293 | Add_One_Interp (Op, Node (Prim), Etype (Node (Prim))); | |
5294 | Set_Etype (N, Etype (Node (Prim))); | |
5295 | end if; | |
5296 | ||
5297 | Next_Elmt (Prim); | |
5298 | end loop; | |
5299 | ||
5300 | -- Now look for class-wide operations of the type or any of its | |
5301 | -- ancestors by iterating over the homonyms of the selector. | |
5302 | ||
5303 | declare | |
5304 | Cls_Type : constant Entity_Id := Class_Wide_Type (Typ); | |
5305 | Hom : Entity_Id; | |
5306 | ||
5307 | begin | |
5308 | Hom := Current_Entity (Op); | |
5309 | while Present (Hom) loop | |
5310 | if (Ekind (Hom) = E_Procedure | |
5311 | or else | |
5312 | Ekind (Hom) = E_Function) | |
5313 | and then Scope (Hom) = Scope (Typ) | |
5314 | and then Present (First_Formal (Hom)) | |
5315 | and then | |
5316 | (Base_Type (Etype (First_Formal (Hom))) = Cls_Type | |
5317 | or else | |
5318 | (Is_Access_Type (Etype (First_Formal (Hom))) | |
5319 | and then | |
5320 | Ekind (Etype (First_Formal (Hom))) = | |
5321 | E_Anonymous_Access_Type | |
5322 | and then | |
5323 | Base_Type | |
5324 | (Designated_Type (Etype (First_Formal (Hom)))) = | |
5325 | Cls_Type)) | |
5326 | then | |
5327 | Add_One_Interp (Op, Hom, Etype (Hom)); | |
5328 | Set_Etype (N, Etype (Hom)); | |
5329 | end if; | |
5330 | ||
5331 | Hom := Homonym (Hom); | |
5332 | end loop; | |
5333 | end; | |
5334 | ||
5335 | return Etype (Op) /= Any_Type; | |
5336 | end Find_Primitive_Operation; | |
5337 | ||
996ae0b0 RK |
5338 | ---------------------- |
5339 | -- Find_Unary_Types -- | |
5340 | ---------------------- | |
5341 | ||
5342 | procedure Find_Unary_Types | |
5343 | (R : Node_Id; | |
5344 | Op_Id : Entity_Id; | |
5345 | N : Node_Id) | |
5346 | is | |
5347 | Index : Interp_Index; | |
5348 | It : Interp; | |
5349 | ||
5350 | begin | |
5351 | if not Is_Overloaded (R) then | |
5352 | if Is_Numeric_Type (Etype (R)) then | |
5353 | Add_One_Interp (N, Op_Id, Base_Type (Etype (R))); | |
5354 | end if; | |
5355 | ||
5356 | else | |
5357 | Get_First_Interp (R, Index, It); | |
996ae0b0 RK |
5358 | while Present (It.Typ) loop |
5359 | if Is_Numeric_Type (It.Typ) then | |
5360 | Add_One_Interp (N, Op_Id, Base_Type (It.Typ)); | |
5361 | end if; | |
5362 | ||
5363 | Get_Next_Interp (Index, It); | |
5364 | end loop; | |
5365 | end if; | |
5366 | end Find_Unary_Types; | |
5367 | ||
996ae0b0 RK |
5368 | ------------------ |
5369 | -- Junk_Operand -- | |
5370 | ------------------ | |
5371 | ||
5372 | function Junk_Operand (N : Node_Id) return Boolean is | |
5373 | Enode : Node_Id; | |
5374 | ||
5375 | begin | |
5376 | if Error_Posted (N) then | |
5377 | return False; | |
5378 | end if; | |
5379 | ||
5380 | -- Get entity to be tested | |
5381 | ||
5382 | if Is_Entity_Name (N) | |
5383 | and then Present (Entity (N)) | |
5384 | then | |
5385 | Enode := N; | |
5386 | ||
5387 | -- An odd case, a procedure name gets converted to a very peculiar | |
5388 | -- function call, and here is where we detect this happening. | |
5389 | ||
5390 | elsif Nkind (N) = N_Function_Call | |
5391 | and then Is_Entity_Name (Name (N)) | |
5392 | and then Present (Entity (Name (N))) | |
5393 | then | |
5394 | Enode := Name (N); | |
5395 | ||
5396 | -- Another odd case, there are at least some cases of selected | |
5397 | -- components where the selected component is not marked as having | |
5398 | -- an entity, even though the selector does have an entity | |
5399 | ||
5400 | elsif Nkind (N) = N_Selected_Component | |
5401 | and then Present (Entity (Selector_Name (N))) | |
5402 | then | |
5403 | Enode := Selector_Name (N); | |
5404 | ||
5405 | else | |
5406 | return False; | |
5407 | end if; | |
5408 | ||
9de61fcb | 5409 | -- Now test the entity we got to see if it is a bad case |
996ae0b0 RK |
5410 | |
5411 | case Ekind (Entity (Enode)) is | |
5412 | ||
5413 | when E_Package => | |
5414 | Error_Msg_N | |
5415 | ("package name cannot be used as operand", Enode); | |
5416 | ||
5417 | when Generic_Unit_Kind => | |
5418 | Error_Msg_N | |
5419 | ("generic unit name cannot be used as operand", Enode); | |
5420 | ||
5421 | when Type_Kind => | |
5422 | Error_Msg_N | |
5423 | ("subtype name cannot be used as operand", Enode); | |
5424 | ||
5425 | when Entry_Kind => | |
5426 | Error_Msg_N | |
5427 | ("entry name cannot be used as operand", Enode); | |
5428 | ||
5429 | when E_Procedure => | |
5430 | Error_Msg_N | |
5431 | ("procedure name cannot be used as operand", Enode); | |
5432 | ||
5433 | when E_Exception => | |
5434 | Error_Msg_N | |
5435 | ("exception name cannot be used as operand", Enode); | |
5436 | ||
5437 | when E_Block | E_Label | E_Loop => | |
5438 | Error_Msg_N | |
5439 | ("label name cannot be used as operand", Enode); | |
5440 | ||
5441 | when others => | |
5442 | return False; | |
5443 | ||
5444 | end case; | |
5445 | ||
5446 | return True; | |
5447 | end Junk_Operand; | |
5448 | ||
5449 | -------------------- | |
5450 | -- Operator_Check -- | |
5451 | -------------------- | |
5452 | ||
5453 | procedure Operator_Check (N : Node_Id) is | |
5454 | begin | |
30c20106 AC |
5455 | Remove_Abstract_Operations (N); |
5456 | ||
996ae0b0 RK |
5457 | -- Test for case of no interpretation found for operator |
5458 | ||
5459 | if Etype (N) = Any_Type then | |
5460 | declare | |
b67a385c ES |
5461 | L : Node_Id; |
5462 | R : Node_Id; | |
5463 | Op_Id : Entity_Id := Empty; | |
996ae0b0 RK |
5464 | |
5465 | begin | |
5466 | R := Right_Opnd (N); | |
5467 | ||
5468 | if Nkind (N) in N_Binary_Op then | |
5469 | L := Left_Opnd (N); | |
5470 | else | |
5471 | L := Empty; | |
5472 | end if; | |
5473 | ||
5474 | -- If either operand has no type, then don't complain further, | |
9de61fcb | 5475 | -- since this simply means that we have a propagated error. |
996ae0b0 RK |
5476 | |
5477 | if R = Error | |
5478 | or else Etype (R) = Any_Type | |
5479 | or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type) | |
5480 | then | |
5481 | return; | |
5482 | ||
4c46b835 AC |
5483 | -- We explicitly check for the case of concatenation of component |
5484 | -- with component to avoid reporting spurious matching array types | |
5485 | -- that might happen to be lurking in distant packages (such as | |
5486 | -- run-time packages). This also prevents inconsistencies in the | |
5487 | -- messages for certain ACVC B tests, which can vary depending on | |
5488 | -- types declared in run-time interfaces. Another improvement when | |
5489 | -- aggregates are present is to look for a well-typed operand. | |
996ae0b0 RK |
5490 | |
5491 | elsif Present (Candidate_Type) | |
5492 | and then (Nkind (N) /= N_Op_Concat | |
5493 | or else Is_Array_Type (Etype (L)) | |
5494 | or else Is_Array_Type (Etype (R))) | |
5495 | then | |
5496 | ||
5497 | if Nkind (N) = N_Op_Concat then | |
5498 | if Etype (L) /= Any_Composite | |
5499 | and then Is_Array_Type (Etype (L)) | |
5500 | then | |
5501 | Candidate_Type := Etype (L); | |
5502 | ||
5503 | elsif Etype (R) /= Any_Composite | |
5504 | and then Is_Array_Type (Etype (R)) | |
5505 | then | |
5506 | Candidate_Type := Etype (R); | |
5507 | end if; | |
5508 | end if; | |
5509 | ||
19d846a0 | 5510 | Error_Msg_NE -- CODEFIX |
996ae0b0 RK |
5511 | ("operator for} is not directly visible!", |
5512 | N, First_Subtype (Candidate_Type)); | |
19d846a0 RD |
5513 | Error_Msg_N -- CODEFIX |
5514 | ("use clause would make operation legal!", N); | |
996ae0b0 RK |
5515 | return; |
5516 | ||
5517 | -- If either operand is a junk operand (e.g. package name), then | |
5518 | -- post appropriate error messages, but do not complain further. | |
5519 | ||
0e0eecec ES |
5520 | -- Note that the use of OR in this test instead of OR ELSE is |
5521 | -- quite deliberate, we may as well check both operands in the | |
5522 | -- binary operator case. | |
996ae0b0 RK |
5523 | |
5524 | elsif Junk_Operand (R) | |
5525 | or (Nkind (N) in N_Binary_Op and then Junk_Operand (L)) | |
5526 | then | |
5527 | return; | |
5528 | ||
5529 | -- If we have a logical operator, one of whose operands is | |
0e0eecec ES |
5530 | -- Boolean, then we know that the other operand cannot resolve to |
5531 | -- Boolean (since we got no interpretations), but in that case we | |
5532 | -- pretty much know that the other operand should be Boolean, so | |
5533 | -- resolve it that way (generating an error) | |
996ae0b0 | 5534 | |
d469eabe | 5535 | elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then |
996ae0b0 RK |
5536 | if Etype (L) = Standard_Boolean then |
5537 | Resolve (R, Standard_Boolean); | |
5538 | return; | |
5539 | elsif Etype (R) = Standard_Boolean then | |
5540 | Resolve (L, Standard_Boolean); | |
5541 | return; | |
5542 | end if; | |
5543 | ||
5544 | -- For an arithmetic operator or comparison operator, if one | |
5545 | -- of the operands is numeric, then we know the other operand | |
5546 | -- is not the same numeric type. If it is a non-numeric type, | |
5547 | -- then probably it is intended to match the other operand. | |
5548 | ||
d469eabe HK |
5549 | elsif Nkind_In (N, N_Op_Add, |
5550 | N_Op_Divide, | |
5551 | N_Op_Ge, | |
5552 | N_Op_Gt, | |
5553 | N_Op_Le) | |
5554 | or else | |
5555 | Nkind_In (N, N_Op_Lt, | |
5556 | N_Op_Mod, | |
5557 | N_Op_Multiply, | |
5558 | N_Op_Rem, | |
5559 | N_Op_Subtract) | |
996ae0b0 RK |
5560 | then |
5561 | if Is_Numeric_Type (Etype (L)) | |
5562 | and then not Is_Numeric_Type (Etype (R)) | |
5563 | then | |
5564 | Resolve (R, Etype (L)); | |
5565 | return; | |
5566 | ||
5567 | elsif Is_Numeric_Type (Etype (R)) | |
5568 | and then not Is_Numeric_Type (Etype (L)) | |
5569 | then | |
5570 | Resolve (L, Etype (R)); | |
5571 | return; | |
5572 | end if; | |
5573 | ||
5574 | -- Comparisons on A'Access are common enough to deserve a | |
5575 | -- special message. | |
5576 | ||
d469eabe | 5577 | elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) |
996ae0b0 RK |
5578 | and then Ekind (Etype (L)) = E_Access_Attribute_Type |
5579 | and then Ekind (Etype (R)) = E_Access_Attribute_Type | |
5580 | then | |
5581 | Error_Msg_N | |
5582 | ("two access attributes cannot be compared directly", N); | |
5583 | Error_Msg_N | |
aab883ec | 5584 | ("\use qualified expression for one of the operands", |
996ae0b0 RK |
5585 | N); |
5586 | return; | |
5587 | ||
5588 | -- Another one for C programmers | |
5589 | ||
5590 | elsif Nkind (N) = N_Op_Concat | |
5591 | and then Valid_Boolean_Arg (Etype (L)) | |
5592 | and then Valid_Boolean_Arg (Etype (R)) | |
5593 | then | |
5594 | Error_Msg_N ("invalid operands for concatenation", N); | |
4e7a4f6e AC |
5595 | Error_Msg_N -- CODEFIX |
5596 | ("\maybe AND was meant", N); | |
996ae0b0 RK |
5597 | return; |
5598 | ||
5599 | -- A special case for comparison of access parameter with null | |
5600 | ||
5601 | elsif Nkind (N) = N_Op_Eq | |
5602 | and then Is_Entity_Name (L) | |
5603 | and then Nkind (Parent (Entity (L))) = N_Parameter_Specification | |
5604 | and then Nkind (Parameter_Type (Parent (Entity (L)))) = | |
5605 | N_Access_Definition | |
5606 | and then Nkind (R) = N_Null | |
5607 | then | |
5608 | Error_Msg_N ("access parameter is not allowed to be null", L); | |
5609 | Error_Msg_N ("\(call would raise Constraint_Error)", L); | |
5610 | return; | |
61bee0e3 AC |
5611 | |
5612 | -- Another special case for exponentiation, where the right | |
5613 | -- operand must be Natural, independently of the base. | |
5614 | ||
5615 | elsif Nkind (N) = N_Op_Expon | |
5616 | and then Is_Numeric_Type (Etype (L)) | |
5617 | and then not Is_Overloaded (R) | |
5618 | and then | |
5619 | First_Subtype (Base_Type (Etype (R))) /= Standard_Integer | |
5620 | and then Base_Type (Etype (R)) /= Universal_Integer | |
5621 | then | |
5622 | Error_Msg_NE | |
5623 | ("exponent must be of type Natural, found}", R, Etype (R)); | |
5624 | return; | |
996ae0b0 RK |
5625 | end if; |
5626 | ||
0e0eecec ES |
5627 | -- If we fall through then just give general message. Note that in |
5628 | -- the following messages, if the operand is overloaded we choose | |
5629 | -- an arbitrary type to complain about, but that is probably more | |
5630 | -- useful than not giving a type at all. | |
996ae0b0 RK |
5631 | |
5632 | if Nkind (N) in N_Unary_Op then | |
5633 | Error_Msg_Node_2 := Etype (R); | |
5634 | Error_Msg_N ("operator& not defined for}", N); | |
5635 | return; | |
5636 | ||
5637 | else | |
fbf5a39b AC |
5638 | if Nkind (N) in N_Binary_Op then |
5639 | if not Is_Overloaded (L) | |
5640 | and then not Is_Overloaded (R) | |
5641 | and then Base_Type (Etype (L)) = Base_Type (Etype (R)) | |
5642 | then | |
7ffd9312 | 5643 | Error_Msg_Node_2 := First_Subtype (Etype (R)); |
fbf5a39b | 5644 | Error_Msg_N ("there is no applicable operator& for}", N); |
996ae0b0 | 5645 | |
fbf5a39b | 5646 | else |
b67a385c ES |
5647 | -- Another attempt to find a fix: one of the candidate |
5648 | -- interpretations may not be use-visible. This has | |
5649 | -- already been checked for predefined operators, so | |
5650 | -- we examine only user-defined functions. | |
5651 | ||
5652 | Op_Id := Get_Name_Entity_Id (Chars (N)); | |
5653 | ||
5654 | while Present (Op_Id) loop | |
5655 | if Ekind (Op_Id) /= E_Operator | |
5656 | and then Is_Overloadable (Op_Id) | |
5657 | then | |
5658 | if not Is_Immediately_Visible (Op_Id) | |
5659 | and then not In_Use (Scope (Op_Id)) | |
aab883ec | 5660 | and then not Is_Abstract_Subprogram (Op_Id) |
b67a385c ES |
5661 | and then not Is_Hidden (Op_Id) |
5662 | and then Ekind (Scope (Op_Id)) = E_Package | |
5663 | and then | |
5664 | Has_Compatible_Type | |
5665 | (L, Etype (First_Formal (Op_Id))) | |
5666 | and then Present | |
5667 | (Next_Formal (First_Formal (Op_Id))) | |
5668 | and then | |
5669 | Has_Compatible_Type | |
5670 | (R, | |
5671 | Etype (Next_Formal (First_Formal (Op_Id)))) | |
5672 | then | |
ed2233dc | 5673 | Error_Msg_N |
b67a385c | 5674 | ("No legal interpretation for operator&", N); |
ed2233dc | 5675 | Error_Msg_NE |
b67a385c ES |
5676 | ("\use clause on& would make operation legal", |
5677 | N, Scope (Op_Id)); | |
5678 | exit; | |
5679 | end if; | |
5680 | end if; | |
fbf5a39b | 5681 | |
b67a385c ES |
5682 | Op_Id := Homonym (Op_Id); |
5683 | end loop; | |
5684 | ||
5685 | if No (Op_Id) then | |
5686 | Error_Msg_N ("invalid operand types for operator&", N); | |
5687 | ||
5688 | if Nkind (N) /= N_Op_Concat then | |
5689 | Error_Msg_NE ("\left operand has}!", N, Etype (L)); | |
5690 | Error_Msg_NE ("\right operand has}!", N, Etype (R)); | |
5691 | end if; | |
fbf5a39b AC |
5692 | end if; |
5693 | end if; | |
996ae0b0 RK |
5694 | end if; |
5695 | end if; | |
5696 | end; | |
5697 | end if; | |
5698 | end Operator_Check; | |
5699 | ||
6e73e3ab AC |
5700 | ----------------------------------------- |
5701 | -- Process_Implicit_Dereference_Prefix -- | |
5702 | ----------------------------------------- | |
5703 | ||
d469eabe | 5704 | function Process_Implicit_Dereference_Prefix |
da709d08 | 5705 | (E : Entity_Id; |
d469eabe | 5706 | P : Entity_Id) return Entity_Id |
6e73e3ab AC |
5707 | is |
5708 | Ref : Node_Id; | |
d469eabe | 5709 | Typ : constant Entity_Id := Designated_Type (Etype (P)); |
da709d08 | 5710 | |
6e73e3ab | 5711 | begin |
1a8fae99 ES |
5712 | if Present (E) |
5713 | and then (Operating_Mode = Check_Semantics or else not Expander_Active) | |
5714 | then | |
6e73e3ab AC |
5715 | -- We create a dummy reference to E to ensure that the reference |
5716 | -- is not considered as part of an assignment (an implicit | |
5717 | -- dereference can never assign to its prefix). The Comes_From_Source | |
5718 | -- attribute needs to be propagated for accurate warnings. | |
5719 | ||
5720 | Ref := New_Reference_To (E, Sloc (P)); | |
5721 | Set_Comes_From_Source (Ref, Comes_From_Source (P)); | |
5722 | Generate_Reference (E, Ref); | |
5723 | end if; | |
d469eabe HK |
5724 | |
5725 | -- An implicit dereference is a legal occurrence of an | |
5726 | -- incomplete type imported through a limited_with clause, | |
5727 | -- if the full view is visible. | |
5728 | ||
5729 | if From_With_Type (Typ) | |
5730 | and then not From_With_Type (Scope (Typ)) | |
5731 | and then | |
5732 | (Is_Immediately_Visible (Scope (Typ)) | |
5733 | or else | |
5734 | (Is_Child_Unit (Scope (Typ)) | |
5735 | and then Is_Visible_Child_Unit (Scope (Typ)))) | |
5736 | then | |
5737 | return Available_View (Typ); | |
5738 | else | |
5739 | return Typ; | |
5740 | end if; | |
5741 | ||
6e73e3ab AC |
5742 | end Process_Implicit_Dereference_Prefix; |
5743 | ||
30c20106 AC |
5744 | -------------------------------- |
5745 | -- Remove_Abstract_Operations -- | |
5746 | -------------------------------- | |
5747 | ||
5748 | procedure Remove_Abstract_Operations (N : Node_Id) is | |
401093c1 ES |
5749 | Abstract_Op : Entity_Id := Empty; |
5750 | Address_Kludge : Boolean := False; | |
5751 | I : Interp_Index; | |
5752 | It : Interp; | |
30c20106 | 5753 | |
0e0eecec ES |
5754 | -- AI-310: If overloaded, remove abstract non-dispatching operations. We |
5755 | -- activate this if either extensions are enabled, or if the abstract | |
5756 | -- operation in question comes from a predefined file. This latter test | |
5757 | -- allows us to use abstract to make operations invisible to users. In | |
5758 | -- particular, if type Address is non-private and abstract subprograms | |
5759 | -- are used to hide its operators, they will be truly hidden. | |
30c20106 | 5760 | |
5950a3ac | 5761 | type Operand_Position is (First_Op, Second_Op); |
8a36a0cc | 5762 | Univ_Type : constant Entity_Id := Universal_Interpretation (N); |
5950a3ac AC |
5763 | |
5764 | procedure Remove_Address_Interpretations (Op : Operand_Position); | |
0e0eecec ES |
5765 | -- Ambiguities may arise when the operands are literal and the address |
5766 | -- operations in s-auxdec are visible. In that case, remove the | |
5767 | -- interpretation of a literal as Address, to retain the semantics of | |
5768 | -- Address as a private type. | |
9f4fd324 AC |
5769 | |
5770 | ------------------------------------ | |
5950a3ac | 5771 | -- Remove_Address_Interpretations -- |
9f4fd324 AC |
5772 | ------------------------------------ |
5773 | ||
5950a3ac | 5774 | procedure Remove_Address_Interpretations (Op : Operand_Position) is |
9f4fd324 AC |
5775 | Formal : Entity_Id; |
5776 | ||
5777 | begin | |
5778 | if Is_Overloaded (N) then | |
5779 | Get_First_Interp (N, I, It); | |
5780 | while Present (It.Nam) loop | |
5781 | Formal := First_Entity (It.Nam); | |
5782 | ||
5950a3ac AC |
5783 | if Op = Second_Op then |
5784 | Formal := Next_Entity (Formal); | |
5785 | end if; | |
5786 | ||
5787 | if Is_Descendent_Of_Address (Etype (Formal)) then | |
401093c1 | 5788 | Address_Kludge := True; |
9f4fd324 AC |
5789 | Remove_Interp (I); |
5790 | end if; | |
5791 | ||
5792 | Get_Next_Interp (I, It); | |
5793 | end loop; | |
5794 | end if; | |
5795 | end Remove_Address_Interpretations; | |
5796 | ||
5797 | -- Start of processing for Remove_Abstract_Operations | |
5798 | ||
30c20106 | 5799 | begin |
d935a36e | 5800 | if Is_Overloaded (N) then |
30c20106 | 5801 | Get_First_Interp (N, I, It); |
d935a36e | 5802 | |
30c20106 | 5803 | while Present (It.Nam) loop |
aab883ec ES |
5804 | if Is_Overloadable (It.Nam) |
5805 | and then Is_Abstract_Subprogram (It.Nam) | |
30c20106 AC |
5806 | and then not Is_Dispatching_Operation (It.Nam) |
5807 | then | |
af152989 | 5808 | Abstract_Op := It.Nam; |
fe45e59e | 5809 | |
401093c1 ES |
5810 | if Is_Descendent_Of_Address (It.Typ) then |
5811 | Address_Kludge := True; | |
5812 | Remove_Interp (I); | |
5813 | exit; | |
5814 | ||
fe45e59e | 5815 | -- In Ada 2005, this operation does not participate in Overload |
9c510803 | 5816 | -- resolution. If the operation is defined in a predefined |
fe45e59e ES |
5817 | -- unit, it is one of the operations declared abstract in some |
5818 | -- variants of System, and it must be removed as well. | |
5819 | ||
401093c1 ES |
5820 | elsif Ada_Version >= Ada_05 |
5821 | or else Is_Predefined_File_Name | |
5822 | (Unit_File_Name (Get_Source_Unit (It.Nam))) | |
fe45e59e ES |
5823 | then |
5824 | Remove_Interp (I); | |
5825 | exit; | |
5826 | end if; | |
30c20106 AC |
5827 | end if; |
5828 | ||
5829 | Get_Next_Interp (I, It); | |
5830 | end loop; | |
5831 | ||
af152989 | 5832 | if No (Abstract_Op) then |
fe45e59e ES |
5833 | |
5834 | -- If some interpretation yields an integer type, it is still | |
5835 | -- possible that there are address interpretations. Remove them | |
5836 | -- if one operand is a literal, to avoid spurious ambiguities | |
5837 | -- on systems where Address is a visible integer type. | |
5838 | ||
5839 | if Is_Overloaded (N) | |
401093c1 | 5840 | and then Nkind (N) in N_Op |
fe45e59e ES |
5841 | and then Is_Integer_Type (Etype (N)) |
5842 | then | |
5843 | if Nkind (N) in N_Binary_Op then | |
5844 | if Nkind (Right_Opnd (N)) = N_Integer_Literal then | |
5845 | Remove_Address_Interpretations (Second_Op); | |
5846 | ||
5847 | elsif Nkind (Right_Opnd (N)) = N_Integer_Literal then | |
5848 | Remove_Address_Interpretations (First_Op); | |
5849 | end if; | |
5850 | end if; | |
5851 | end if; | |
3984e89a AC |
5852 | |
5853 | elsif Nkind (N) in N_Op then | |
4c46b835 | 5854 | |
fe45e59e ES |
5855 | -- Remove interpretations that treat literals as addresses. This |
5856 | -- is never appropriate, even when Address is defined as a visible | |
5857 | -- Integer type. The reason is that we would really prefer Address | |
5858 | -- to behave as a private type, even in this case, which is there | |
f3d57416 RW |
5859 | -- only to accommodate oddities of VMS address sizes. If Address |
5860 | -- is a visible integer type, we get lots of overload ambiguities. | |
30c20106 | 5861 | |
5950a3ac AC |
5862 | if Nkind (N) in N_Binary_Op then |
5863 | declare | |
5864 | U1 : constant Boolean := | |
5865 | Present (Universal_Interpretation (Right_Opnd (N))); | |
5866 | U2 : constant Boolean := | |
5867 | Present (Universal_Interpretation (Left_Opnd (N))); | |
30c20106 | 5868 | |
5950a3ac | 5869 | begin |
0e0eecec | 5870 | if U1 then |
5950a3ac | 5871 | Remove_Address_Interpretations (Second_Op); |
0e0eecec | 5872 | end if; |
5950a3ac | 5873 | |
0e0eecec | 5874 | if U2 then |
5950a3ac | 5875 | Remove_Address_Interpretations (First_Op); |
30c20106 AC |
5876 | end if; |
5877 | ||
5950a3ac AC |
5878 | if not (U1 and U2) then |
5879 | ||
5880 | -- Remove corresponding predefined operator, which is | |
5881 | -- always added to the overload set. | |
5882 | ||
5883 | Get_First_Interp (N, I, It); | |
5884 | while Present (It.Nam) loop | |
0ab80019 AC |
5885 | if Scope (It.Nam) = Standard_Standard |
5886 | and then Base_Type (It.Typ) = | |
5887 | Base_Type (Etype (Abstract_Op)) | |
5888 | then | |
5950a3ac AC |
5889 | Remove_Interp (I); |
5890 | end if; | |
5891 | ||
8a36a0cc AC |
5892 | Get_Next_Interp (I, It); |
5893 | end loop; | |
5894 | ||
5895 | elsif Is_Overloaded (N) | |
5896 | and then Present (Univ_Type) | |
5897 | then | |
5898 | -- If both operands have a universal interpretation, | |
0e0eecec ES |
5899 | -- it is still necessary to remove interpretations that |
5900 | -- yield Address. Any remaining ambiguities will be | |
5901 | -- removed in Disambiguate. | |
8a36a0cc AC |
5902 | |
5903 | Get_First_Interp (N, I, It); | |
8a36a0cc | 5904 | while Present (It.Nam) loop |
0e0eecec ES |
5905 | if Is_Descendent_Of_Address (It.Typ) then |
5906 | Remove_Interp (I); | |
5907 | ||
5908 | elsif not Is_Type (It.Nam) then | |
8a36a0cc | 5909 | Set_Entity (N, It.Nam); |
8a36a0cc AC |
5910 | end if; |
5911 | ||
5950a3ac AC |
5912 | Get_Next_Interp (I, It); |
5913 | end loop; | |
5914 | end if; | |
5915 | end; | |
30c20106 | 5916 | end if; |
3984e89a AC |
5917 | |
5918 | elsif Nkind (N) = N_Function_Call | |
5919 | and then | |
5920 | (Nkind (Name (N)) = N_Operator_Symbol | |
5921 | or else | |
5922 | (Nkind (Name (N)) = N_Expanded_Name | |
5923 | and then | |
5924 | Nkind (Selector_Name (Name (N))) = N_Operator_Symbol)) | |
5925 | then | |
5950a3ac | 5926 | |
3984e89a AC |
5927 | declare |
5928 | Arg1 : constant Node_Id := First (Parameter_Associations (N)); | |
5950a3ac AC |
5929 | U1 : constant Boolean := |
5930 | Present (Universal_Interpretation (Arg1)); | |
5931 | U2 : constant Boolean := | |
5932 | Present (Next (Arg1)) and then | |
5933 | Present (Universal_Interpretation (Next (Arg1))); | |
3984e89a AC |
5934 | |
5935 | begin | |
0e0eecec | 5936 | if U1 then |
5950a3ac | 5937 | Remove_Address_Interpretations (First_Op); |
0e0eecec | 5938 | end if; |
3984e89a | 5939 | |
0e0eecec | 5940 | if U2 then |
5950a3ac AC |
5941 | Remove_Address_Interpretations (Second_Op); |
5942 | end if; | |
5943 | ||
5944 | if not (U1 and U2) then | |
3984e89a AC |
5945 | Get_First_Interp (N, I, It); |
5946 | while Present (It.Nam) loop | |
9f4fd324 AC |
5947 | if Scope (It.Nam) = Standard_Standard |
5948 | and then It.Typ = Base_Type (Etype (Abstract_Op)) | |
5949 | then | |
3984e89a AC |
5950 | Remove_Interp (I); |
5951 | end if; | |
5952 | ||
5953 | Get_Next_Interp (I, It); | |
5954 | end loop; | |
5955 | end if; | |
5956 | end; | |
30c20106 | 5957 | end if; |
af152989 | 5958 | |
401093c1 ES |
5959 | -- If the removal has left no valid interpretations, emit an error |
5960 | -- message now and label node as illegal. | |
af152989 AC |
5961 | |
5962 | if Present (Abstract_Op) then | |
5963 | Get_First_Interp (N, I, It); | |
5964 | ||
5965 | if No (It.Nam) then | |
5966 | ||
6e73e3ab | 5967 | -- Removal of abstract operation left no viable candidate |
af152989 AC |
5968 | |
5969 | Set_Etype (N, Any_Type); | |
5970 | Error_Msg_Sloc := Sloc (Abstract_Op); | |
5971 | Error_Msg_NE | |
5972 | ("cannot call abstract operation& declared#", N, Abstract_Op); | |
401093c1 ES |
5973 | |
5974 | -- In Ada 2005, an abstract operation may disable predefined | |
5975 | -- operators. Since the context is not yet known, we mark the | |
5976 | -- predefined operators as potentially hidden. Do not include | |
5977 | -- predefined operators when addresses are involved since this | |
5978 | -- case is handled separately. | |
5979 | ||
5980 | elsif Ada_Version >= Ada_05 | |
5981 | and then not Address_Kludge | |
5982 | then | |
5983 | while Present (It.Nam) loop | |
5984 | if Is_Numeric_Type (It.Typ) | |
5985 | and then Scope (It.Typ) = Standard_Standard | |
5986 | then | |
5987 | Set_Abstract_Op (I, Abstract_Op); | |
5988 | end if; | |
5989 | ||
5990 | Get_Next_Interp (I, It); | |
5991 | end loop; | |
af152989 AC |
5992 | end if; |
5993 | end if; | |
30c20106 AC |
5994 | end if; |
5995 | end Remove_Abstract_Operations; | |
5996 | ||
996ae0b0 RK |
5997 | ----------------------- |
5998 | -- Try_Indirect_Call -- | |
5999 | ----------------------- | |
6000 | ||
6001 | function Try_Indirect_Call | |
91b1417d AC |
6002 | (N : Node_Id; |
6003 | Nam : Entity_Id; | |
6004 | Typ : Entity_Id) return Boolean | |
996ae0b0 | 6005 | is |
24657705 HK |
6006 | Actual : Node_Id; |
6007 | Formal : Entity_Id; | |
6008 | ||
8a7988f5 | 6009 | Call_OK : Boolean; |
24657705 | 6010 | pragma Warnings (Off, Call_OK); |
996ae0b0 RK |
6011 | |
6012 | begin | |
8a7988f5 | 6013 | Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK); |
9de61fcb | 6014 | |
8a7988f5 | 6015 | Actual := First_Actual (N); |
fbf5a39b | 6016 | Formal := First_Formal (Designated_Type (Typ)); |
9de61fcb | 6017 | while Present (Actual) and then Present (Formal) loop |
996ae0b0 RK |
6018 | if not Has_Compatible_Type (Actual, Etype (Formal)) then |
6019 | return False; | |
6020 | end if; | |
6021 | ||
6022 | Next (Actual); | |
6023 | Next_Formal (Formal); | |
6024 | end loop; | |
6025 | ||
6026 | if No (Actual) and then No (Formal) then | |
6027 | Add_One_Interp (N, Nam, Etype (Designated_Type (Typ))); | |
6028 | ||
6029 | -- Nam is a candidate interpretation for the name in the call, | |
6030 | -- if it is not an indirect call. | |
6031 | ||
6032 | if not Is_Type (Nam) | |
6033 | and then Is_Entity_Name (Name (N)) | |
6034 | then | |
6035 | Set_Entity (Name (N), Nam); | |
6036 | end if; | |
6037 | ||
6038 | return True; | |
6039 | else | |
6040 | return False; | |
6041 | end if; | |
6042 | end Try_Indirect_Call; | |
6043 | ||
6044 | ---------------------- | |
6045 | -- Try_Indexed_Call -- | |
6046 | ---------------------- | |
6047 | ||
6048 | function Try_Indexed_Call | |
aab883ec ES |
6049 | (N : Node_Id; |
6050 | Nam : Entity_Id; | |
6051 | Typ : Entity_Id; | |
6052 | Skip_First : Boolean) return Boolean | |
996ae0b0 | 6053 | is |
5ff22245 ES |
6054 | Loc : constant Source_Ptr := Sloc (N); |
6055 | Actuals : constant List_Id := Parameter_Associations (N); | |
6056 | Actual : Node_Id; | |
6057 | Index : Entity_Id; | |
996ae0b0 RK |
6058 | |
6059 | begin | |
fbf5a39b | 6060 | Actual := First (Actuals); |
aab883ec ES |
6061 | |
6062 | -- If the call was originally written in prefix form, skip the first | |
6063 | -- actual, which is obviously not defaulted. | |
6064 | ||
6065 | if Skip_First then | |
6066 | Next (Actual); | |
6067 | end if; | |
6068 | ||
fbf5a39b | 6069 | Index := First_Index (Typ); |
9de61fcb RD |
6070 | while Present (Actual) and then Present (Index) loop |
6071 | ||
996ae0b0 RK |
6072 | -- If the parameter list has a named association, the expression |
6073 | -- is definitely a call and not an indexed component. | |
6074 | ||
6075 | if Nkind (Actual) = N_Parameter_Association then | |
6076 | return False; | |
6077 | end if; | |
6078 | ||
5ff22245 ES |
6079 | if Is_Entity_Name (Actual) |
6080 | and then Is_Type (Entity (Actual)) | |
6081 | and then No (Next (Actual)) | |
6082 | then | |
6083 | Rewrite (N, | |
6084 | Make_Slice (Loc, | |
6085 | Prefix => Make_Function_Call (Loc, | |
6086 | Name => Relocate_Node (Name (N))), | |
6087 | Discrete_Range => | |
6088 | New_Occurrence_Of (Entity (Actual), Sloc (Actual)))); | |
6089 | ||
6090 | Analyze (N); | |
6091 | return True; | |
6092 | ||
6093 | elsif not Has_Compatible_Type (Actual, Etype (Index)) then | |
996ae0b0 RK |
6094 | return False; |
6095 | end if; | |
6096 | ||
6097 | Next (Actual); | |
6098 | Next_Index (Index); | |
6099 | end loop; | |
6100 | ||
6101 | if No (Actual) and then No (Index) then | |
6102 | Add_One_Interp (N, Nam, Component_Type (Typ)); | |
6103 | ||
6104 | -- Nam is a candidate interpretation for the name in the call, | |
6105 | -- if it is not an indirect call. | |
6106 | ||
6107 | if not Is_Type (Nam) | |
6108 | and then Is_Entity_Name (Name (N)) | |
6109 | then | |
6110 | Set_Entity (Name (N), Nam); | |
6111 | end if; | |
6112 | ||
6113 | return True; | |
6114 | else | |
6115 | return False; | |
6116 | end if; | |
996ae0b0 RK |
6117 | end Try_Indexed_Call; |
6118 | ||
35ae2ed8 AC |
6119 | -------------------------- |
6120 | -- Try_Object_Operation -- | |
6121 | -------------------------- | |
6122 | ||
6123 | function Try_Object_Operation (N : Node_Id) return Boolean is | |
b67a385c | 6124 | K : constant Node_Kind := Nkind (Parent (N)); |
d469eabe HK |
6125 | Is_Subprg_Call : constant Boolean := Nkind_In |
6126 | (K, N_Procedure_Call_Statement, | |
6127 | N_Function_Call); | |
b67a385c | 6128 | Loc : constant Source_Ptr := Sloc (N); |
b67a385c | 6129 | Obj : constant Node_Id := Prefix (N); |
0a36105d JM |
6130 | Subprog : constant Node_Id := |
6131 | Make_Identifier (Sloc (Selector_Name (N)), | |
6132 | Chars => Chars (Selector_Name (N))); | |
401093c1 | 6133 | -- Identifier on which possible interpretations will be collected |
0a36105d | 6134 | |
b67a385c ES |
6135 | Report_Error : Boolean := False; |
6136 | -- If no candidate interpretation matches the context, redo the | |
6137 | -- analysis with error enabled to provide additional information. | |
28d6470f JM |
6138 | |
6139 | Actual : Node_Id; | |
d469eabe | 6140 | Candidate : Entity_Id := Empty; |
b67a385c | 6141 | New_Call_Node : Node_Id := Empty; |
4c46b835 | 6142 | Node_To_Replace : Node_Id; |
28d6470f | 6143 | Obj_Type : Entity_Id := Etype (Obj); |
d469eabe | 6144 | Success : Boolean := False; |
4c46b835 | 6145 | |
0a36105d JM |
6146 | function Valid_Candidate |
6147 | (Success : Boolean; | |
6148 | Call : Node_Id; | |
6149 | Subp : Entity_Id) return Entity_Id; | |
6150 | -- If the subprogram is a valid interpretation, record it, and add | |
6151 | -- to the list of interpretations of Subprog. | |
6152 | ||
4c46b835 AC |
6153 | procedure Complete_Object_Operation |
6154 | (Call_Node : Node_Id; | |
0a36105d | 6155 | Node_To_Replace : Node_Id); |
ec6078e3 ES |
6156 | -- Make Subprog the name of Call_Node, replace Node_To_Replace with |
6157 | -- Call_Node, insert the object (or its dereference) as the first actual | |
6158 | -- in the call, and complete the analysis of the call. | |
4c46b835 | 6159 | |
0a36105d JM |
6160 | procedure Report_Ambiguity (Op : Entity_Id); |
6161 | -- If a prefixed procedure call is ambiguous, indicate whether the | |
6162 | -- call includes an implicit dereference or an implicit 'Access. | |
6163 | ||
4c46b835 AC |
6164 | procedure Transform_Object_Operation |
6165 | (Call_Node : out Node_Id; | |
0a36105d | 6166 | Node_To_Replace : out Node_Id); |
ec6078e3 | 6167 | -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..) |
d469eabe HK |
6168 | -- Call_Node is the resulting subprogram call, Node_To_Replace is |
6169 | -- either N or the parent of N, and Subprog is a reference to the | |
6170 | -- subprogram we are trying to match. | |
35ae2ed8 AC |
6171 | |
6172 | function Try_Class_Wide_Operation | |
4c46b835 AC |
6173 | (Call_Node : Node_Id; |
6174 | Node_To_Replace : Node_Id) return Boolean; | |
ec6078e3 ES |
6175 | -- Traverse all ancestor types looking for a class-wide subprogram |
6176 | -- for which the current operation is a valid non-dispatching call. | |
35ae2ed8 | 6177 | |
0a36105d JM |
6178 | procedure Try_One_Prefix_Interpretation (T : Entity_Id); |
6179 | -- If prefix is overloaded, its interpretation may include different | |
6180 | -- tagged types, and we must examine the primitive operations and | |
6181 | -- the class-wide operations of each in order to find candidate | |
6182 | -- interpretations for the call as a whole. | |
6183 | ||
4c46b835 AC |
6184 | function Try_Primitive_Operation |
6185 | (Call_Node : Node_Id; | |
6186 | Node_To_Replace : Node_Id) return Boolean; | |
ec6078e3 ES |
6187 | -- Traverse the list of primitive subprograms looking for a dispatching |
6188 | -- operation for which the current node is a valid call . | |
4c46b835 | 6189 | |
0a36105d JM |
6190 | --------------------- |
6191 | -- Valid_Candidate -- | |
6192 | --------------------- | |
6193 | ||
6194 | function Valid_Candidate | |
6195 | (Success : Boolean; | |
6196 | Call : Node_Id; | |
6197 | Subp : Entity_Id) return Entity_Id | |
6198 | is | |
ee9aa7b6 | 6199 | Arr_Type : Entity_Id; |
0a36105d JM |
6200 | Comp_Type : Entity_Id; |
6201 | ||
6202 | begin | |
6203 | -- If the subprogram is a valid interpretation, record it in global | |
6204 | -- variable Subprog, to collect all possible overloadings. | |
6205 | ||
6206 | if Success then | |
6207 | if Subp /= Entity (Subprog) then | |
6208 | Add_One_Interp (Subprog, Subp, Etype (Subp)); | |
6209 | end if; | |
6210 | end if; | |
6211 | ||
d469eabe HK |
6212 | -- If the call may be an indexed call, retrieve component type of |
6213 | -- resulting expression, and add possible interpretation. | |
0a36105d | 6214 | |
ee9aa7b6 | 6215 | Arr_Type := Empty; |
0a36105d JM |
6216 | Comp_Type := Empty; |
6217 | ||
6218 | if Nkind (Call) = N_Function_Call | |
d469eabe HK |
6219 | and then Nkind (Parent (N)) = N_Indexed_Component |
6220 | and then Needs_One_Actual (Subp) | |
0a36105d JM |
6221 | then |
6222 | if Is_Array_Type (Etype (Subp)) then | |
ee9aa7b6 | 6223 | Arr_Type := Etype (Subp); |
0a36105d JM |
6224 | |
6225 | elsif Is_Access_Type (Etype (Subp)) | |
6226 | and then Is_Array_Type (Designated_Type (Etype (Subp))) | |
6227 | then | |
ee9aa7b6 | 6228 | Arr_Type := Designated_Type (Etype (Subp)); |
0a36105d JM |
6229 | end if; |
6230 | end if; | |
6231 | ||
ee9aa7b6 AC |
6232 | if Present (Arr_Type) then |
6233 | ||
6234 | -- Verify that the actuals (excluding the object) | |
6235 | -- match the types of the indices. | |
6236 | ||
6237 | declare | |
6238 | Actual : Node_Id; | |
6239 | Index : Node_Id; | |
6240 | ||
6241 | begin | |
6242 | Actual := Next (First_Actual (Call)); | |
6243 | Index := First_Index (Arr_Type); | |
ee9aa7b6 AC |
6244 | while Present (Actual) and then Present (Index) loop |
6245 | if not Has_Compatible_Type (Actual, Etype (Index)) then | |
6246 | Arr_Type := Empty; | |
6247 | exit; | |
6248 | end if; | |
6249 | ||
6250 | Next_Actual (Actual); | |
6251 | Next_Index (Index); | |
6252 | end loop; | |
6253 | ||
6254 | if No (Actual) | |
6255 | and then No (Index) | |
6256 | and then Present (Arr_Type) | |
6257 | then | |
6258 | Comp_Type := Component_Type (Arr_Type); | |
6259 | end if; | |
6260 | end; | |
6261 | ||
6262 | if Present (Comp_Type) | |
6263 | and then Etype (Subprog) /= Comp_Type | |
6264 | then | |
6265 | Add_One_Interp (Subprog, Subp, Comp_Type); | |
6266 | end if; | |
0a36105d JM |
6267 | end if; |
6268 | ||
6269 | if Etype (Call) /= Any_Type then | |
6270 | return Subp; | |
6271 | else | |
6272 | return Empty; | |
6273 | end if; | |
6274 | end Valid_Candidate; | |
6275 | ||
4c46b835 AC |
6276 | ------------------------------- |
6277 | -- Complete_Object_Operation -- | |
6278 | ------------------------------- | |
6279 | ||
6280 | procedure Complete_Object_Operation | |
6281 | (Call_Node : Node_Id; | |
0a36105d | 6282 | Node_To_Replace : Node_Id) |
4c46b835 | 6283 | is |
b4592168 GD |
6284 | Control : constant Entity_Id := First_Formal (Entity (Subprog)); |
6285 | Formal_Type : constant Entity_Id := Etype (Control); | |
ec6078e3 ES |
6286 | First_Actual : Node_Id; |
6287 | ||
4c46b835 | 6288 | begin |
955871d3 AC |
6289 | -- Place the name of the operation, with its interpretations, |
6290 | -- on the rewritten call. | |
0a36105d | 6291 | |
ec6078e3 ES |
6292 | Set_Name (Call_Node, Subprog); |
6293 | ||
0a36105d JM |
6294 | First_Actual := First (Parameter_Associations (Call_Node)); |
6295 | ||
b67a385c ES |
6296 | -- For cross-reference purposes, treat the new node as being in |
6297 | -- the source if the original one is. | |
6298 | ||
6299 | Set_Comes_From_Source (Subprog, Comes_From_Source (N)); | |
6300 | Set_Comes_From_Source (Call_Node, Comes_From_Source (N)); | |
6301 | ||
ec6078e3 ES |
6302 | if Nkind (N) = N_Selected_Component |
6303 | and then not Inside_A_Generic | |
6304 | then | |
6305 | Set_Entity (Selector_Name (N), Entity (Subprog)); | |
6306 | end if; | |
6307 | ||
6308 | -- If need be, rewrite first actual as an explicit dereference | |
0a36105d JM |
6309 | -- If the call is overloaded, the rewriting can only be done |
6310 | -- once the primitive operation is identified. | |
6311 | ||
6312 | if Is_Overloaded (Subprog) then | |
ec6078e3 | 6313 | |
0a36105d JM |
6314 | -- The prefix itself may be overloaded, and its interpretations |
6315 | -- must be propagated to the new actual in the call. | |
6316 | ||
6317 | if Is_Overloaded (Obj) then | |
6318 | Save_Interps (Obj, First_Actual); | |
6319 | end if; | |
6320 | ||
6321 | Rewrite (First_Actual, Obj); | |
6322 | ||
6323 | elsif not Is_Access_Type (Formal_Type) | |
ec6078e3 ES |
6324 | and then Is_Access_Type (Etype (Obj)) |
6325 | then | |
6326 | Rewrite (First_Actual, | |
6327 | Make_Explicit_Dereference (Sloc (Obj), Obj)); | |
6328 | Analyze (First_Actual); | |
fe45e59e | 6329 | |
401093c1 ES |
6330 | -- If we need to introduce an explicit dereference, verify that |
6331 | -- the resulting actual is compatible with the mode of the formal. | |
6332 | ||
6333 | if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter | |
6334 | and then Is_Access_Constant (Etype (Obj)) | |
6335 | then | |
6336 | Error_Msg_NE | |
6337 | ("expect variable in call to&", Prefix (N), Entity (Subprog)); | |
6338 | end if; | |
6339 | ||
d469eabe HK |
6340 | -- Conversely, if the formal is an access parameter and the object |
6341 | -- is not, replace the actual with a 'Access reference. Its analysis | |
6342 | -- will check that the object is aliased. | |
fe45e59e ES |
6343 | |
6344 | elsif Is_Access_Type (Formal_Type) | |
6345 | and then not Is_Access_Type (Etype (Obj)) | |
6346 | then | |
b4592168 GD |
6347 | -- A special case: A.all'access is illegal if A is an access to a |
6348 | -- constant and the context requires an access to a variable. | |
6349 | ||
6350 | if not Is_Access_Constant (Formal_Type) then | |
6351 | if (Nkind (Obj) = N_Explicit_Dereference | |
6352 | and then Is_Access_Constant (Etype (Prefix (Obj)))) | |
6353 | or else not Is_Variable (Obj) | |
6354 | then | |
6355 | Error_Msg_NE | |
6356 | ("actual for& must be a variable", Obj, Control); | |
6357 | end if; | |
6358 | end if; | |
6359 | ||
fe45e59e ES |
6360 | Rewrite (First_Actual, |
6361 | Make_Attribute_Reference (Loc, | |
6362 | Attribute_Name => Name_Access, | |
6363 | Prefix => Relocate_Node (Obj))); | |
0a36105d JM |
6364 | |
6365 | if not Is_Aliased_View (Obj) then | |
ed2233dc | 6366 | Error_Msg_NE |
0a36105d | 6367 | ("object in prefixed call to& must be aliased" |
401093c1 | 6368 | & " (RM-2005 4.3.1 (13))", |
0a36105d JM |
6369 | Prefix (First_Actual), Subprog); |
6370 | end if; | |
6371 | ||
fe45e59e ES |
6372 | Analyze (First_Actual); |
6373 | ||
ec6078e3 | 6374 | else |
0a36105d JM |
6375 | if Is_Overloaded (Obj) then |
6376 | Save_Interps (Obj, First_Actual); | |
6377 | end if; | |
ec6078e3 | 6378 | |
0a36105d | 6379 | Rewrite (First_Actual, Obj); |
aab883ec ES |
6380 | end if; |
6381 | ||
7ffd9312 | 6382 | Rewrite (Node_To_Replace, Call_Node); |
0a36105d JM |
6383 | |
6384 | -- Propagate the interpretations collected in subprog to the new | |
6385 | -- function call node, to be resolved from context. | |
6386 | ||
6387 | if Is_Overloaded (Subprog) then | |
6388 | Save_Interps (Subprog, Node_To_Replace); | |
7415029d | 6389 | |
0a36105d JM |
6390 | else |
6391 | Analyze (Node_To_Replace); | |
438ff97c ES |
6392 | |
6393 | -- If the operation has been rewritten into a call, which may | |
6394 | -- get subsequently an explicit dereference, preserve the | |
6395 | -- type on the original node (selected component or indexed | |
6396 | -- component) for subsequent legality tests, e.g. Is_Variable. | |
6397 | -- which examines the original node. | |
6398 | ||
6399 | if Nkind (Node_To_Replace) = N_Function_Call then | |
6400 | Set_Etype | |
6401 | (Original_Node (Node_To_Replace), Etype (Node_To_Replace)); | |
6402 | end if; | |
0a36105d | 6403 | end if; |
4c46b835 AC |
6404 | end Complete_Object_Operation; |
6405 | ||
0a36105d JM |
6406 | ---------------------- |
6407 | -- Report_Ambiguity -- | |
6408 | ---------------------- | |
6409 | ||
6410 | procedure Report_Ambiguity (Op : Entity_Id) is | |
6411 | Access_Formal : constant Boolean := | |
6412 | Is_Access_Type (Etype (First_Formal (Op))); | |
6413 | Access_Actual : constant Boolean := | |
6414 | Is_Access_Type (Etype (Prefix (N))); | |
6415 | ||
6416 | begin | |
6417 | Error_Msg_Sloc := Sloc (Op); | |
6418 | ||
6419 | if Access_Formal and then not Access_Actual then | |
6420 | if Nkind (Parent (Op)) = N_Full_Type_Declaration then | |
ed2233dc | 6421 | Error_Msg_N |
0a36105d JM |
6422 | ("\possible interpretation" |
6423 | & " (inherited, with implicit 'Access) #", N); | |
6424 | else | |
ed2233dc | 6425 | Error_Msg_N |
0a36105d JM |
6426 | ("\possible interpretation (with implicit 'Access) #", N); |
6427 | end if; | |
6428 | ||
6429 | elsif not Access_Formal and then Access_Actual then | |
6430 | if Nkind (Parent (Op)) = N_Full_Type_Declaration then | |
ed2233dc | 6431 | Error_Msg_N |
0a36105d JM |
6432 | ("\possible interpretation" |
6433 | & " ( inherited, with implicit dereference) #", N); | |
6434 | else | |
ed2233dc | 6435 | Error_Msg_N |
0a36105d JM |
6436 | ("\possible interpretation (with implicit dereference) #", N); |
6437 | end if; | |
6438 | ||
6439 | else | |
6440 | if Nkind (Parent (Op)) = N_Full_Type_Declaration then | |
ed2233dc | 6441 | Error_Msg_N ("\possible interpretation (inherited)#", N); |
0a36105d | 6442 | else |
4e7a4f6e AC |
6443 | Error_Msg_N -- CODEFIX |
6444 | ("\possible interpretation#", N); | |
0a36105d JM |
6445 | end if; |
6446 | end if; | |
6447 | end Report_Ambiguity; | |
6448 | ||
4c46b835 AC |
6449 | -------------------------------- |
6450 | -- Transform_Object_Operation -- | |
6451 | -------------------------------- | |
6452 | ||
6453 | procedure Transform_Object_Operation | |
6454 | (Call_Node : out Node_Id; | |
0a36105d | 6455 | Node_To_Replace : out Node_Id) |
35ae2ed8 | 6456 | is |
ec6078e3 ES |
6457 | Dummy : constant Node_Id := New_Copy (Obj); |
6458 | -- Placeholder used as a first parameter in the call, replaced | |
6459 | -- eventually by the proper object. | |
6460 | ||
d469eabe HK |
6461 | Parent_Node : constant Node_Id := Parent (N); |
6462 | ||
ec6078e3 | 6463 | Actual : Node_Id; |
d469eabe | 6464 | Actuals : List_Id; |
ec6078e3 | 6465 | |
35ae2ed8 | 6466 | begin |
ec6078e3 ES |
6467 | -- Common case covering 1) Call to a procedure and 2) Call to a |
6468 | -- function that has some additional actuals. | |
35ae2ed8 | 6469 | |
d469eabe HK |
6470 | if Nkind_In (Parent_Node, N_Function_Call, |
6471 | N_Procedure_Call_Statement) | |
35ae2ed8 | 6472 | |
ec6078e3 ES |
6473 | -- N is a selected component node containing the name of the |
6474 | -- subprogram. If N is not the name of the parent node we must | |
6475 | -- not replace the parent node by the new construct. This case | |
6476 | -- occurs when N is a parameterless call to a subprogram that | |
6477 | -- is an actual parameter of a call to another subprogram. For | |
6478 | -- example: | |
6479 | -- Some_Subprogram (..., Obj.Operation, ...) | |
35ae2ed8 | 6480 | |
ec6078e3 | 6481 | and then Name (Parent_Node) = N |
4c46b835 AC |
6482 | then |
6483 | Node_To_Replace := Parent_Node; | |
35ae2ed8 | 6484 | |
ec6078e3 | 6485 | Actuals := Parameter_Associations (Parent_Node); |
d3e65aad | 6486 | |
ec6078e3 ES |
6487 | if Present (Actuals) then |
6488 | Prepend (Dummy, Actuals); | |
6489 | else | |
6490 | Actuals := New_List (Dummy); | |
6491 | end if; | |
4c46b835 AC |
6492 | |
6493 | if Nkind (Parent_Node) = N_Procedure_Call_Statement then | |
6494 | Call_Node := | |
6495 | Make_Procedure_Call_Statement (Loc, | |
0a36105d | 6496 | Name => New_Copy (Subprog), |
4c46b835 AC |
6497 | Parameter_Associations => Actuals); |
6498 | ||
6499 | else | |
4c46b835 AC |
6500 | Call_Node := |
6501 | Make_Function_Call (Loc, | |
0a36105d | 6502 | Name => New_Copy (Subprog), |
4c46b835 | 6503 | Parameter_Associations => Actuals); |
35ae2ed8 | 6504 | |
35ae2ed8 AC |
6505 | end if; |
6506 | ||
d469eabe | 6507 | -- Before analysis, a function call appears as an indexed component |
ec6078e3 | 6508 | -- if there are no named associations. |
758c442c | 6509 | |
ec6078e3 ES |
6510 | elsif Nkind (Parent_Node) = N_Indexed_Component |
6511 | and then N = Prefix (Parent_Node) | |
6512 | then | |
758c442c GD |
6513 | Node_To_Replace := Parent_Node; |
6514 | ||
ec6078e3 ES |
6515 | Actuals := Expressions (Parent_Node); |
6516 | ||
6517 | Actual := First (Actuals); | |
6518 | while Present (Actual) loop | |
6519 | Analyze (Actual); | |
6520 | Next (Actual); | |
6521 | end loop; | |
6522 | ||
6523 | Prepend (Dummy, Actuals); | |
758c442c GD |
6524 | |
6525 | Call_Node := | |
6526 | Make_Function_Call (Loc, | |
0a36105d | 6527 | Name => New_Copy (Subprog), |
758c442c GD |
6528 | Parameter_Associations => Actuals); |
6529 | ||
d469eabe | 6530 | -- Parameterless call: Obj.F is rewritten as F (Obj) |
35ae2ed8 | 6531 | |
4c46b835 AC |
6532 | else |
6533 | Node_To_Replace := N; | |
6534 | ||
6535 | Call_Node := | |
6536 | Make_Function_Call (Loc, | |
0a36105d | 6537 | Name => New_Copy (Subprog), |
ec6078e3 | 6538 | Parameter_Associations => New_List (Dummy)); |
4c46b835 AC |
6539 | end if; |
6540 | end Transform_Object_Operation; | |
35ae2ed8 AC |
6541 | |
6542 | ------------------------------ | |
6543 | -- Try_Class_Wide_Operation -- | |
6544 | ------------------------------ | |
6545 | ||
6546 | function Try_Class_Wide_Operation | |
4c46b835 AC |
6547 | (Call_Node : Node_Id; |
6548 | Node_To_Replace : Node_Id) return Boolean | |
35ae2ed8 | 6549 | is |
0a36105d JM |
6550 | Anc_Type : Entity_Id; |
6551 | Matching_Op : Entity_Id := Empty; | |
6552 | Error : Boolean; | |
6553 | ||
6554 | procedure Traverse_Homonyms | |
6555 | (Anc_Type : Entity_Id; | |
6556 | Error : out Boolean); | |
6557 | -- Traverse the homonym chain of the subprogram searching for those | |
6558 | -- homonyms whose first formal has the Anc_Type's class-wide type, | |
d469eabe HK |
6559 | -- or an anonymous access type designating the class-wide type. If |
6560 | -- an ambiguity is detected, then Error is set to True. | |
0a36105d JM |
6561 | |
6562 | procedure Traverse_Interfaces | |
6563 | (Anc_Type : Entity_Id; | |
6564 | Error : out Boolean); | |
6565 | -- Traverse the list of interfaces, if any, associated with Anc_Type | |
6566 | -- and search for acceptable class-wide homonyms associated with each | |
6567 | -- interface. If an ambiguity is detected, then Error is set to True. | |
6568 | ||
6569 | ----------------------- | |
6570 | -- Traverse_Homonyms -- | |
6571 | ----------------------- | |
6572 | ||
6573 | procedure Traverse_Homonyms | |
6574 | (Anc_Type : Entity_Id; | |
6575 | Error : out Boolean) | |
6576 | is | |
6577 | Cls_Type : Entity_Id; | |
6578 | Hom : Entity_Id; | |
6579 | Hom_Ref : Node_Id; | |
6580 | Success : Boolean; | |
35ae2ed8 | 6581 | |
0a36105d JM |
6582 | begin |
6583 | Error := False; | |
ec6078e3 | 6584 | |
b67a385c ES |
6585 | Cls_Type := Class_Wide_Type (Anc_Type); |
6586 | ||
4c46b835 | 6587 | Hom := Current_Entity (Subprog); |
401093c1 ES |
6588 | |
6589 | -- Find operation whose first parameter is of the class-wide | |
6590 | -- type, a subtype thereof, or an anonymous access to same. | |
6591 | ||
35ae2ed8 AC |
6592 | while Present (Hom) loop |
6593 | if (Ekind (Hom) = E_Procedure | |
4c46b835 AC |
6594 | or else |
6595 | Ekind (Hom) = E_Function) | |
b67a385c | 6596 | and then Scope (Hom) = Scope (Anc_Type) |
4c46b835 | 6597 | and then Present (First_Formal (Hom)) |
b67a385c | 6598 | and then |
401093c1 | 6599 | (Base_Type (Etype (First_Formal (Hom))) = Cls_Type |
b67a385c ES |
6600 | or else |
6601 | (Is_Access_Type (Etype (First_Formal (Hom))) | |
0a36105d JM |
6602 | and then |
6603 | Ekind (Etype (First_Formal (Hom))) = | |
6604 | E_Anonymous_Access_Type | |
b67a385c | 6605 | and then |
401093c1 ES |
6606 | Base_Type |
6607 | (Designated_Type (Etype (First_Formal (Hom)))) = | |
0a36105d | 6608 | Cls_Type)) |
35ae2ed8 | 6609 | then |
ec6078e3 | 6610 | Set_Etype (Call_Node, Any_Type); |
0a36105d JM |
6611 | Set_Is_Overloaded (Call_Node, False); |
6612 | Success := False; | |
4c46b835 | 6613 | |
0a36105d JM |
6614 | if No (Matching_Op) then |
6615 | Hom_Ref := New_Reference_To (Hom, Sloc (Subprog)); | |
6616 | Set_Etype (Call_Node, Any_Type); | |
6617 | Set_Parent (Call_Node, Parent (Node_To_Replace)); | |
4c46b835 | 6618 | |
0a36105d | 6619 | Set_Name (Call_Node, Hom_Ref); |
4c46b835 | 6620 | |
0a36105d JM |
6621 | Analyze_One_Call |
6622 | (N => Call_Node, | |
6623 | Nam => Hom, | |
6624 | Report => Report_Error, | |
6625 | Success => Success, | |
6626 | Skip_First => True); | |
4c46b835 | 6627 | |
0a36105d JM |
6628 | Matching_Op := |
6629 | Valid_Candidate (Success, Call_Node, Hom); | |
4c46b835 | 6630 | |
0a36105d JM |
6631 | else |
6632 | Analyze_One_Call | |
6633 | (N => Call_Node, | |
6634 | Nam => Hom, | |
6635 | Report => Report_Error, | |
6636 | Success => Success, | |
6637 | Skip_First => True); | |
6638 | ||
6639 | if Present (Valid_Candidate (Success, Call_Node, Hom)) | |
6640 | and then Nkind (Call_Node) /= N_Function_Call | |
6641 | then | |
ed2233dc | 6642 | Error_Msg_NE ("ambiguous call to&", N, Hom); |
0a36105d JM |
6643 | Report_Ambiguity (Matching_Op); |
6644 | Report_Ambiguity (Hom); | |
6645 | Error := True; | |
6646 | return; | |
6647 | end if; | |
35ae2ed8 AC |
6648 | end if; |
6649 | end if; | |
6650 | ||
6651 | Hom := Homonym (Hom); | |
6652 | end loop; | |
0a36105d JM |
6653 | end Traverse_Homonyms; |
6654 | ||
6655 | ------------------------- | |
6656 | -- Traverse_Interfaces -- | |
6657 | ------------------------- | |
35ae2ed8 | 6658 | |
0a36105d JM |
6659 | procedure Traverse_Interfaces |
6660 | (Anc_Type : Entity_Id; | |
6661 | Error : out Boolean) | |
6662 | is | |
0a36105d JM |
6663 | Intface_List : constant List_Id := |
6664 | Abstract_Interface_List (Anc_Type); | |
d469eabe | 6665 | Intface : Node_Id; |
0a36105d JM |
6666 | |
6667 | begin | |
6668 | Error := False; | |
6669 | ||
6670 | if Is_Non_Empty_List (Intface_List) then | |
6671 | Intface := First (Intface_List); | |
6672 | while Present (Intface) loop | |
6673 | ||
6674 | -- Look for acceptable class-wide homonyms associated with | |
6675 | -- the interface. | |
6676 | ||
6677 | Traverse_Homonyms (Etype (Intface), Error); | |
6678 | ||
6679 | if Error then | |
6680 | return; | |
6681 | end if; | |
6682 | ||
6683 | -- Continue the search by looking at each of the interface's | |
6684 | -- associated interface ancestors. | |
6685 | ||
6686 | Traverse_Interfaces (Etype (Intface), Error); | |
6687 | ||
6688 | if Error then | |
6689 | return; | |
6690 | end if; | |
6691 | ||
6692 | Next (Intface); | |
6693 | end loop; | |
6694 | end if; | |
6695 | end Traverse_Interfaces; | |
6696 | ||
6697 | -- Start of processing for Try_Class_Wide_Operation | |
6698 | ||
6699 | begin | |
d469eabe HK |
6700 | -- Loop through ancestor types (including interfaces), traversing |
6701 | -- the homonym chain of the subprogram, trying out those homonyms | |
6702 | -- whose first formal has the class-wide type of the ancestor, or | |
6703 | -- an anonymous access type designating the class-wide type. | |
0a36105d JM |
6704 | |
6705 | Anc_Type := Obj_Type; | |
6706 | loop | |
6707 | -- Look for a match among homonyms associated with the ancestor | |
6708 | ||
6709 | Traverse_Homonyms (Anc_Type, Error); | |
6710 | ||
6711 | if Error then | |
6712 | return True; | |
6713 | end if; | |
6714 | ||
6715 | -- Continue the search for matches among homonyms associated with | |
6716 | -- any interfaces implemented by the ancestor. | |
6717 | ||
6718 | Traverse_Interfaces (Anc_Type, Error); | |
6719 | ||
6720 | if Error then | |
6721 | return True; | |
6722 | end if; | |
35ae2ed8 | 6723 | |
4c46b835 AC |
6724 | exit when Etype (Anc_Type) = Anc_Type; |
6725 | Anc_Type := Etype (Anc_Type); | |
35ae2ed8 AC |
6726 | end loop; |
6727 | ||
0a36105d JM |
6728 | if Present (Matching_Op) then |
6729 | Set_Etype (Call_Node, Etype (Matching_Op)); | |
6730 | end if; | |
ec6078e3 | 6731 | |
0a36105d | 6732 | return Present (Matching_Op); |
35ae2ed8 AC |
6733 | end Try_Class_Wide_Operation; |
6734 | ||
0a36105d JM |
6735 | ----------------------------------- |
6736 | -- Try_One_Prefix_Interpretation -- | |
6737 | ----------------------------------- | |
6738 | ||
6739 | procedure Try_One_Prefix_Interpretation (T : Entity_Id) is | |
6740 | begin | |
6741 | Obj_Type := T; | |
6742 | ||
6743 | if Is_Access_Type (Obj_Type) then | |
6744 | Obj_Type := Designated_Type (Obj_Type); | |
6745 | end if; | |
6746 | ||
6747 | if Ekind (Obj_Type) = E_Private_Subtype then | |
6748 | Obj_Type := Base_Type (Obj_Type); | |
6749 | end if; | |
6750 | ||
6751 | if Is_Class_Wide_Type (Obj_Type) then | |
6752 | Obj_Type := Etype (Class_Wide_Type (Obj_Type)); | |
6753 | end if; | |
6754 | ||
6755 | -- The type may have be obtained through a limited_with clause, | |
6756 | -- in which case the primitive operations are available on its | |
401093c1 | 6757 | -- non-limited view. If still incomplete, retrieve full view. |
0a36105d JM |
6758 | |
6759 | if Ekind (Obj_Type) = E_Incomplete_Type | |
6760 | and then From_With_Type (Obj_Type) | |
6761 | then | |
401093c1 | 6762 | Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type)); |
0a36105d JM |
6763 | end if; |
6764 | ||
6765 | -- If the object is not tagged, or the type is still an incomplete | |
6766 | -- type, this is not a prefixed call. | |
6767 | ||
6768 | if not Is_Tagged_Type (Obj_Type) | |
6769 | or else Is_Incomplete_Type (Obj_Type) | |
6770 | then | |
6771 | return; | |
6772 | end if; | |
6773 | ||
6774 | if Try_Primitive_Operation | |
6775 | (Call_Node => New_Call_Node, | |
6776 | Node_To_Replace => Node_To_Replace) | |
6777 | or else | |
6778 | Try_Class_Wide_Operation | |
6779 | (Call_Node => New_Call_Node, | |
6780 | Node_To_Replace => Node_To_Replace) | |
6781 | then | |
6782 | null; | |
6783 | end if; | |
6784 | end Try_One_Prefix_Interpretation; | |
6785 | ||
4c46b835 AC |
6786 | ----------------------------- |
6787 | -- Try_Primitive_Operation -- | |
6788 | ----------------------------- | |
35ae2ed8 | 6789 | |
4c46b835 AC |
6790 | function Try_Primitive_Operation |
6791 | (Call_Node : Node_Id; | |
6792 | Node_To_Replace : Node_Id) return Boolean | |
35ae2ed8 | 6793 | is |
6e73e3ab AC |
6794 | Elmt : Elmt_Id; |
6795 | Prim_Op : Entity_Id; | |
0a36105d JM |
6796 | Matching_Op : Entity_Id := Empty; |
6797 | Prim_Op_Ref : Node_Id := Empty; | |
6798 | ||
6799 | Corr_Type : Entity_Id := Empty; | |
6800 | -- If the prefix is a synchronized type, the controlling type of | |
6801 | -- the primitive operation is the corresponding record type, else | |
6802 | -- this is the object type itself. | |
6803 | ||
6804 | Success : Boolean := False; | |
35ae2ed8 | 6805 | |
401093c1 ES |
6806 | function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id; |
6807 | -- For tagged types the candidate interpretations are found in | |
6808 | -- the list of primitive operations of the type and its ancestors. | |
6809 | -- For formal tagged types we have to find the operations declared | |
6810 | -- in the same scope as the type (including in the generic formal | |
6811 | -- part) because the type itself carries no primitive operations, | |
6812 | -- except for formal derived types that inherit the operations of | |
6813 | -- the parent and progenitors. | |
d469eabe HK |
6814 | -- If the context is a generic subprogram body, the generic formals |
6815 | -- are visible by name, but are not in the entity list of the | |
6816 | -- subprogram because that list starts with the subprogram formals. | |
6817 | -- We retrieve the candidate operations from the generic declaration. | |
401093c1 | 6818 | |
dfcfdc0a AC |
6819 | function Is_Private_Overriding (Op : Entity_Id) return Boolean; |
6820 | -- An operation that overrides an inherited operation in the private | |
6821 | -- part of its package may be hidden, but if the inherited operation | |
6822 | -- is visible a direct call to it will dispatch to the private one, | |
6823 | -- which is therefore a valid candidate. | |
6824 | ||
ec6078e3 ES |
6825 | function Valid_First_Argument_Of (Op : Entity_Id) return Boolean; |
6826 | -- Verify that the prefix, dereferenced if need be, is a valid | |
6827 | -- controlling argument in a call to Op. The remaining actuals | |
6828 | -- are checked in the subsequent call to Analyze_One_Call. | |
35ae2ed8 | 6829 | |
401093c1 ES |
6830 | ------------------------------ |
6831 | -- Collect_Generic_Type_Ops -- | |
6832 | ------------------------------ | |
6833 | ||
6834 | function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is | |
6835 | Bas : constant Entity_Id := Base_Type (T); | |
6836 | Candidates : constant Elist_Id := New_Elmt_List; | |
6837 | Subp : Entity_Id; | |
6838 | Formal : Entity_Id; | |
6839 | ||
d469eabe HK |
6840 | procedure Check_Candidate; |
6841 | -- The operation is a candidate if its first parameter is a | |
6842 | -- controlling operand of the desired type. | |
6843 | ||
6844 | ----------------------- | |
6845 | -- Check_Candidate; -- | |
6846 | ----------------------- | |
6847 | ||
6848 | procedure Check_Candidate is | |
6849 | begin | |
6850 | Formal := First_Formal (Subp); | |
6851 | ||
6852 | if Present (Formal) | |
6853 | and then Is_Controlling_Formal (Formal) | |
6854 | and then | |
6855 | (Base_Type (Etype (Formal)) = Bas | |
6856 | or else | |
6857 | (Is_Access_Type (Etype (Formal)) | |
6858 | and then Designated_Type (Etype (Formal)) = Bas)) | |
6859 | then | |
6860 | Append_Elmt (Subp, Candidates); | |
6861 | end if; | |
6862 | end Check_Candidate; | |
6863 | ||
6864 | -- Start of processing for Collect_Generic_Type_Ops | |
6865 | ||
401093c1 ES |
6866 | begin |
6867 | if Is_Derived_Type (T) then | |
6868 | return Primitive_Operations (T); | |
6869 | ||
bce79204 AC |
6870 | elsif Ekind_In (Scope (T), E_Procedure, E_Function) then |
6871 | ||
d469eabe HK |
6872 | -- Scan the list of generic formals to find subprograms |
6873 | -- that may have a first controlling formal of the type. | |
6874 | ||
bb10b891 AC |
6875 | if Nkind (Unit_Declaration_Node (Scope (T))) |
6876 | = N_Generic_Subprogram_Declaration | |
6877 | then | |
6878 | declare | |
6879 | Decl : Node_Id; | |
6880 | ||
6881 | begin | |
6882 | Decl := | |
6883 | First (Generic_Formal_Declarations | |
6884 | (Unit_Declaration_Node (Scope (T)))); | |
6885 | while Present (Decl) loop | |
6886 | if Nkind (Decl) in N_Formal_Subprogram_Declaration then | |
6887 | Subp := Defining_Entity (Decl); | |
6888 | Check_Candidate; | |
6889 | end if; | |
d469eabe | 6890 | |
bb10b891 AC |
6891 | Next (Decl); |
6892 | end loop; | |
6893 | end; | |
6894 | end if; | |
d469eabe HK |
6895 | return Candidates; |
6896 | ||
401093c1 ES |
6897 | else |
6898 | -- Scan the list of entities declared in the same scope as | |
6899 | -- the type. In general this will be an open scope, given that | |
6900 | -- the call we are analyzing can only appear within a generic | |
6901 | -- declaration or body (either the one that declares T, or a | |
6902 | -- child unit). | |
6903 | ||
bb10b891 AC |
6904 | -- For a subtype representing a generic actual type, go to the |
6905 | -- base type. | |
6906 | ||
6907 | if Is_Generic_Actual_Type (T) then | |
6908 | Subp := First_Entity (Scope (Base_Type (T))); | |
6909 | else | |
6910 | Subp := First_Entity (Scope (T)); | |
6911 | end if; | |
6912 | ||
401093c1 ES |
6913 | while Present (Subp) loop |
6914 | if Is_Overloadable (Subp) then | |
d469eabe | 6915 | Check_Candidate; |
401093c1 ES |
6916 | end if; |
6917 | ||
6918 | Next_Entity (Subp); | |
6919 | end loop; | |
6920 | ||
6921 | return Candidates; | |
6922 | end if; | |
6923 | end Collect_Generic_Type_Ops; | |
6924 | ||
dfcfdc0a AC |
6925 | --------------------------- |
6926 | -- Is_Private_Overriding -- | |
6927 | --------------------------- | |
6928 | ||
6929 | function Is_Private_Overriding (Op : Entity_Id) return Boolean is | |
6930 | Visible_Op : constant Entity_Id := Homonym (Op); | |
6931 | ||
6932 | begin | |
6933 | return Present (Visible_Op) | |
6465b6a7 | 6934 | and then Scope (Op) = Scope (Visible_Op) |
dfcfdc0a AC |
6935 | and then not Comes_From_Source (Visible_Op) |
6936 | and then Alias (Visible_Op) = Op | |
6937 | and then not Is_Hidden (Visible_Op); | |
6938 | end Is_Private_Overriding; | |
6939 | ||
ec6078e3 ES |
6940 | ----------------------------- |
6941 | -- Valid_First_Argument_Of -- | |
6942 | ----------------------------- | |
35ae2ed8 | 6943 | |
ec6078e3 | 6944 | function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is |
9febb58f | 6945 | Typ : Entity_Id := Etype (First_Formal (Op)); |
35ae2ed8 | 6946 | |
ec6078e3 | 6947 | begin |
9febb58f JM |
6948 | if Is_Concurrent_Type (Typ) |
6949 | and then Present (Corresponding_Record_Type (Typ)) | |
6950 | then | |
6951 | Typ := Corresponding_Record_Type (Typ); | |
6952 | end if; | |
6953 | ||
d469eabe HK |
6954 | -- Simple case. Object may be a subtype of the tagged type or |
6955 | -- may be the corresponding record of a synchronized type. | |
5d09245e | 6956 | |
aab883ec | 6957 | return Obj_Type = Typ |
d469eabe | 6958 | or else Base_Type (Obj_Type) = Typ |
0a36105d JM |
6959 | or else Corr_Type = Typ |
6960 | ||
6961 | -- Prefix can be dereferenced | |
725e2a15 | 6962 | |
ec6078e3 | 6963 | or else |
0a36105d JM |
6964 | (Is_Access_Type (Corr_Type) |
6965 | and then Designated_Type (Corr_Type) = Typ) | |
5d09245e | 6966 | |
0a36105d JM |
6967 | -- Formal is an access parameter, for which the object |
6968 | -- can provide an access. | |
35ae2ed8 | 6969 | |
ec6078e3 ES |
6970 | or else |
6971 | (Ekind (Typ) = E_Anonymous_Access_Type | |
0a36105d | 6972 | and then Designated_Type (Typ) = Base_Type (Corr_Type)); |
ec6078e3 | 6973 | end Valid_First_Argument_Of; |
35ae2ed8 | 6974 | |
ec6078e3 | 6975 | -- Start of processing for Try_Primitive_Operation |
35ae2ed8 | 6976 | |
ec6078e3 | 6977 | begin |
d469eabe | 6978 | -- Look for subprograms in the list of primitive operations. The name |
0a36105d JM |
6979 | -- must be identical, and the kind of call indicates the expected |
6980 | -- kind of operation (function or procedure). If the type is a | |
d469eabe | 6981 | -- (tagged) synchronized type, the primitive ops are attached to the |
b4592168 | 6982 | -- corresponding record (base) type. |
aab883ec ES |
6983 | |
6984 | if Is_Concurrent_Type (Obj_Type) then | |
bb10b891 AC |
6985 | if Present (Corresponding_Record_Type (Obj_Type)) then |
6986 | Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type)); | |
6987 | Elmt := First_Elmt (Primitive_Operations (Corr_Type)); | |
6988 | else | |
6989 | Corr_Type := Obj_Type; | |
6990 | Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type)); | |
15e4986c JM |
6991 | end if; |
6992 | ||
401093c1 | 6993 | elsif not Is_Generic_Type (Obj_Type) then |
0a36105d | 6994 | Corr_Type := Obj_Type; |
aab883ec | 6995 | Elmt := First_Elmt (Primitive_Operations (Obj_Type)); |
401093c1 ES |
6996 | |
6997 | else | |
6998 | Corr_Type := Obj_Type; | |
6999 | Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type)); | |
aab883ec | 7000 | end if; |
35ae2ed8 | 7001 | |
ec6078e3 ES |
7002 | while Present (Elmt) loop |
7003 | Prim_Op := Node (Elmt); | |
7004 | ||
7005 | if Chars (Prim_Op) = Chars (Subprog) | |
7006 | and then Present (First_Formal (Prim_Op)) | |
7007 | and then Valid_First_Argument_Of (Prim_Op) | |
fe45e59e | 7008 | and then |
7415029d | 7009 | (Nkind (Call_Node) = N_Function_Call) |
fe45e59e | 7010 | = (Ekind (Prim_Op) = E_Function) |
ec6078e3 | 7011 | then |
b67a385c ES |
7012 | -- Ada 2005 (AI-251): If this primitive operation corresponds |
7013 | -- with an immediate ancestor interface there is no need to add | |
7014 | -- it to the list of interpretations; the corresponding aliased | |
7015 | -- primitive is also in this list of primitive operations and | |
7016 | -- will be used instead. | |
fe45e59e | 7017 | |
ce2b6ba5 JM |
7018 | if (Present (Interface_Alias (Prim_Op)) |
7019 | and then Is_Ancestor (Find_Dispatching_Type | |
7020 | (Alias (Prim_Op)), Corr_Type)) | |
0a36105d | 7021 | |
dfcfdc0a AC |
7022 | -- Do not consider hidden primitives unless the type is in an |
7023 | -- open scope or we are within an instance, where visibility | |
7024 | -- is known to be correct, or else if this is an overriding | |
7025 | -- operation in the private part for an inherited operation. | |
0a36105d | 7026 | |
dfcfdc0a AC |
7027 | or else (Is_Hidden (Prim_Op) |
7028 | and then not Is_Immediately_Visible (Obj_Type) | |
7029 | and then not In_Instance | |
7030 | and then not Is_Private_Overriding (Prim_Op)) | |
fe45e59e ES |
7031 | then |
7032 | goto Continue; | |
7033 | end if; | |
7034 | ||
0a36105d JM |
7035 | Set_Etype (Call_Node, Any_Type); |
7036 | Set_Is_Overloaded (Call_Node, False); | |
7037 | ||
7038 | if No (Matching_Op) then | |
fe45e59e | 7039 | Prim_Op_Ref := New_Reference_To (Prim_Op, Sloc (Subprog)); |
b67a385c | 7040 | Candidate := Prim_Op; |
35ae2ed8 | 7041 | |
fe45e59e | 7042 | Set_Parent (Call_Node, Parent (Node_To_Replace)); |
35ae2ed8 | 7043 | |
fe45e59e | 7044 | Set_Name (Call_Node, Prim_Op_Ref); |
0a36105d | 7045 | Success := False; |
35ae2ed8 | 7046 | |
fe45e59e ES |
7047 | Analyze_One_Call |
7048 | (N => Call_Node, | |
7049 | Nam => Prim_Op, | |
b67a385c | 7050 | Report => Report_Error, |
fe45e59e ES |
7051 | Success => Success, |
7052 | Skip_First => True); | |
35ae2ed8 | 7053 | |
0a36105d | 7054 | Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op); |
fe45e59e | 7055 | |
d469eabe HK |
7056 | -- More than one interpretation, collect for subsequent |
7057 | -- disambiguation. If this is a procedure call and there | |
7058 | -- is another match, report ambiguity now. | |
0a36105d | 7059 | |
d469eabe | 7060 | else |
0a36105d JM |
7061 | Analyze_One_Call |
7062 | (N => Call_Node, | |
7063 | Nam => Prim_Op, | |
7064 | Report => Report_Error, | |
7065 | Success => Success, | |
7066 | Skip_First => True); | |
fe45e59e | 7067 | |
0a36105d JM |
7068 | if Present (Valid_Candidate (Success, Call_Node, Prim_Op)) |
7069 | and then Nkind (Call_Node) /= N_Function_Call | |
7070 | then | |
ed2233dc | 7071 | Error_Msg_NE ("ambiguous call to&", N, Prim_Op); |
0a36105d JM |
7072 | Report_Ambiguity (Matching_Op); |
7073 | Report_Ambiguity (Prim_Op); | |
7074 | return True; | |
7075 | end if; | |
4c46b835 AC |
7076 | end if; |
7077 | end if; | |
35ae2ed8 | 7078 | |
fe45e59e | 7079 | <<Continue>> |
4c46b835 AC |
7080 | Next_Elmt (Elmt); |
7081 | end loop; | |
35ae2ed8 | 7082 | |
0a36105d JM |
7083 | if Present (Matching_Op) then |
7084 | Set_Etype (Call_Node, Etype (Matching_Op)); | |
fe45e59e ES |
7085 | end if; |
7086 | ||
0a36105d | 7087 | return Present (Matching_Op); |
4c46b835 | 7088 | end Try_Primitive_Operation; |
35ae2ed8 | 7089 | |
4c46b835 | 7090 | -- Start of processing for Try_Object_Operation |
35ae2ed8 | 7091 | |
4c46b835 | 7092 | begin |
0a36105d | 7093 | Analyze_Expression (Obj); |
ec6078e3 | 7094 | |
0a36105d | 7095 | -- Analyze the actuals if node is known to be a subprogram call |
28d6470f JM |
7096 | |
7097 | if Is_Subprg_Call and then N = Name (Parent (N)) then | |
7098 | Actual := First (Parameter_Associations (Parent (N))); | |
7099 | while Present (Actual) loop | |
725e2a15 | 7100 | Analyze_Expression (Actual); |
28d6470f JM |
7101 | Next (Actual); |
7102 | end loop; | |
7103 | end if; | |
5d09245e | 7104 | |
ec6078e3 ES |
7105 | -- Build a subprogram call node, using a copy of Obj as its first |
7106 | -- actual. This is a placeholder, to be replaced by an explicit | |
7107 | -- dereference when needed. | |
4c46b835 | 7108 | |
ec6078e3 ES |
7109 | Transform_Object_Operation |
7110 | (Call_Node => New_Call_Node, | |
0a36105d | 7111 | Node_To_Replace => Node_To_Replace); |
4c46b835 | 7112 | |
ec6078e3 | 7113 | Set_Etype (New_Call_Node, Any_Type); |
0a36105d | 7114 | Set_Etype (Subprog, Any_Type); |
ec6078e3 | 7115 | Set_Parent (New_Call_Node, Parent (Node_To_Replace)); |
4c46b835 | 7116 | |
0a36105d JM |
7117 | if not Is_Overloaded (Obj) then |
7118 | Try_One_Prefix_Interpretation (Obj_Type); | |
ec6078e3 | 7119 | |
0a36105d JM |
7120 | else |
7121 | declare | |
7122 | I : Interp_Index; | |
7123 | It : Interp; | |
7124 | begin | |
7125 | Get_First_Interp (Obj, I, It); | |
7126 | while Present (It.Nam) loop | |
7127 | Try_One_Prefix_Interpretation (It.Typ); | |
7128 | Get_Next_Interp (I, It); | |
7129 | end loop; | |
7130 | end; | |
7131 | end if; | |
7132 | ||
7133 | if Etype (New_Call_Node) /= Any_Type then | |
7134 | Complete_Object_Operation | |
7135 | (Call_Node => New_Call_Node, | |
7136 | Node_To_Replace => Node_To_Replace); | |
b67a385c ES |
7137 | return True; |
7138 | ||
7139 | elsif Present (Candidate) then | |
7140 | ||
7141 | -- The argument list is not type correct. Re-analyze with error | |
7142 | -- reporting enabled, and use one of the possible candidates. | |
d469eabe | 7143 | -- In All_Errors_Mode, re-analyze all failed interpretations. |
b67a385c ES |
7144 | |
7145 | if All_Errors_Mode then | |
7146 | Report_Error := True; | |
7147 | if Try_Primitive_Operation | |
7148 | (Call_Node => New_Call_Node, | |
7149 | Node_To_Replace => Node_To_Replace) | |
7150 | ||
7151 | or else | |
7152 | Try_Class_Wide_Operation | |
7153 | (Call_Node => New_Call_Node, | |
7154 | Node_To_Replace => Node_To_Replace) | |
7155 | then | |
7156 | null; | |
7157 | end if; | |
7158 | ||
7159 | else | |
7160 | Analyze_One_Call | |
7161 | (N => New_Call_Node, | |
7162 | Nam => Candidate, | |
7163 | Report => True, | |
7164 | Success => Success, | |
7165 | Skip_First => True); | |
7166 | end if; | |
7167 | ||
d469eabe HK |
7168 | -- No need for further errors |
7169 | ||
7170 | return True; | |
b67a385c ES |
7171 | |
7172 | else | |
7173 | -- There was no candidate operation, so report it as an error | |
7174 | -- in the caller: Analyze_Selected_Component. | |
7175 | ||
7176 | return False; | |
7177 | end if; | |
35ae2ed8 AC |
7178 | end Try_Object_Operation; |
7179 | ||
b4592168 GD |
7180 | --------- |
7181 | -- wpo -- | |
7182 | --------- | |
7183 | ||
7184 | procedure wpo (T : Entity_Id) is | |
7185 | Op : Entity_Id; | |
7186 | E : Elmt_Id; | |
7187 | ||
7188 | begin | |
7189 | if not Is_Tagged_Type (T) then | |
7190 | return; | |
7191 | end if; | |
7192 | ||
7193 | E := First_Elmt (Primitive_Operations (Base_Type (T))); | |
7194 | while Present (E) loop | |
7195 | Op := Node (E); | |
7196 | Write_Int (Int (Op)); | |
7197 | Write_Str (" === "); | |
7198 | Write_Name (Chars (Op)); | |
7199 | Write_Str (" in "); | |
7200 | Write_Name (Chars (Scope (Op))); | |
7201 | Next_Elmt (E); | |
7202 | Write_Eol; | |
7203 | end loop; | |
7204 | end wpo; | |
7205 | ||
996ae0b0 | 7206 | end Sem_Ch4; |