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