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