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