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