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