annotate gcc/ada/sem_type.adb @ 117:f81c5aa9f14f

fix
author mir3636
date Tue, 28 Nov 2017 21:17:15 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S E M _ T Y P E --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 with Atree; use Atree;
kono
parents:
diff changeset
27 with Alloc;
kono
parents:
diff changeset
28 with Debug; use Debug;
kono
parents:
diff changeset
29 with Einfo; use Einfo;
kono
parents:
diff changeset
30 with Elists; use Elists;
kono
parents:
diff changeset
31 with Nlists; use Nlists;
kono
parents:
diff changeset
32 with Errout; use Errout;
kono
parents:
diff changeset
33 with Lib; use Lib;
kono
parents:
diff changeset
34 with Namet; use Namet;
kono
parents:
diff changeset
35 with Opt; use Opt;
kono
parents:
diff changeset
36 with Output; use Output;
kono
parents:
diff changeset
37 with Sem; use Sem;
kono
parents:
diff changeset
38 with Sem_Aux; use Sem_Aux;
kono
parents:
diff changeset
39 with Sem_Ch6; use Sem_Ch6;
kono
parents:
diff changeset
40 with Sem_Ch8; use Sem_Ch8;
kono
parents:
diff changeset
41 with Sem_Ch12; use Sem_Ch12;
kono
parents:
diff changeset
42 with Sem_Disp; use Sem_Disp;
kono
parents:
diff changeset
43 with Sem_Dist; use Sem_Dist;
kono
parents:
diff changeset
44 with Sem_Util; use Sem_Util;
kono
parents:
diff changeset
45 with Stand; use Stand;
kono
parents:
diff changeset
46 with Sinfo; use Sinfo;
kono
parents:
diff changeset
47 with Snames; use Snames;
kono
parents:
diff changeset
48 with Table;
kono
parents:
diff changeset
49 with Treepr; use Treepr;
kono
parents:
diff changeset
50 with Uintp; use Uintp;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 package body Sem_Type is
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 ---------------------
kono
parents:
diff changeset
55 -- Data Structures --
kono
parents:
diff changeset
56 ---------------------
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 -- The following data structures establish a mapping between nodes and
kono
parents:
diff changeset
59 -- their interpretations. An overloaded node has an entry in Interp_Map,
kono
parents:
diff changeset
60 -- which in turn contains a pointer into the All_Interp array. The
kono
parents:
diff changeset
61 -- interpretations of a given node are contiguous in All_Interp. Each set
kono
parents:
diff changeset
62 -- of interpretations is terminated with the marker No_Interp. In order to
kono
parents:
diff changeset
63 -- speed up the retrieval of the interpretations of an overloaded node, the
kono
parents:
diff changeset
64 -- Interp_Map table is accessed by means of a simple hashing scheme, and
kono
parents:
diff changeset
65 -- the entries in Interp_Map are chained. The heads of clash lists are
kono
parents:
diff changeset
66 -- stored in array Headers.
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 -- Headers Interp_Map All_Interp
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 -- _ +-----+ +--------+
kono
parents:
diff changeset
71 -- |_| |_____| --->|interp1 |
kono
parents:
diff changeset
72 -- |_|---------->|node | | |interp2 |
kono
parents:
diff changeset
73 -- |_| |index|---------| |nointerp|
kono
parents:
diff changeset
74 -- |_| |next | | |
kono
parents:
diff changeset
75 -- |-----| | |
kono
parents:
diff changeset
76 -- +-----+ +--------+
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 -- This scheme does not currently reclaim interpretations. In principle,
kono
parents:
diff changeset
79 -- after a unit is compiled, all overloadings have been resolved, and the
kono
parents:
diff changeset
80 -- candidate interpretations should be deleted. This should be easier
kono
parents:
diff changeset
81 -- now than with the previous scheme???
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 package All_Interp is new Table.Table (
kono
parents:
diff changeset
84 Table_Component_Type => Interp,
kono
parents:
diff changeset
85 Table_Index_Type => Interp_Index,
kono
parents:
diff changeset
86 Table_Low_Bound => 0,
kono
parents:
diff changeset
87 Table_Initial => Alloc.All_Interp_Initial,
kono
parents:
diff changeset
88 Table_Increment => Alloc.All_Interp_Increment,
kono
parents:
diff changeset
89 Table_Name => "All_Interp");
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 type Interp_Ref is record
kono
parents:
diff changeset
92 Node : Node_Id;
kono
parents:
diff changeset
93 Index : Interp_Index;
kono
parents:
diff changeset
94 Next : Int;
kono
parents:
diff changeset
95 end record;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 Header_Size : constant Int := 2 ** 12;
kono
parents:
diff changeset
98 No_Entry : constant Int := -1;
kono
parents:
diff changeset
99 Headers : array (0 .. Header_Size) of Int := (others => No_Entry);
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 package Interp_Map is new Table.Table (
kono
parents:
diff changeset
102 Table_Component_Type => Interp_Ref,
kono
parents:
diff changeset
103 Table_Index_Type => Int,
kono
parents:
diff changeset
104 Table_Low_Bound => 0,
kono
parents:
diff changeset
105 Table_Initial => Alloc.Interp_Map_Initial,
kono
parents:
diff changeset
106 Table_Increment => Alloc.Interp_Map_Increment,
kono
parents:
diff changeset
107 Table_Name => "Interp_Map");
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 function Hash (N : Node_Id) return Int;
kono
parents:
diff changeset
110 -- A trivial hashing function for nodes, used to insert an overloaded
kono
parents:
diff changeset
111 -- node into the Interp_Map table.
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 -------------------------------------
kono
parents:
diff changeset
114 -- Handling of Overload Resolution --
kono
parents:
diff changeset
115 -------------------------------------
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 -- Overload resolution uses two passes over the syntax tree of a complete
kono
parents:
diff changeset
118 -- context. In the first, bottom-up pass, the types of actuals in calls
kono
parents:
diff changeset
119 -- are used to resolve possibly overloaded subprogram and operator names.
kono
parents:
diff changeset
120 -- In the second top-down pass, the type of the context (for example the
kono
parents:
diff changeset
121 -- condition in a while statement) is used to resolve a possibly ambiguous
kono
parents:
diff changeset
122 -- call, and the unique subprogram name in turn imposes a specific context
kono
parents:
diff changeset
123 -- on each of its actuals.
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 -- Most expressions are in fact unambiguous, and the bottom-up pass is
kono
parents:
diff changeset
126 -- sufficient to resolve most everything. To simplify the common case,
kono
parents:
diff changeset
127 -- names and expressions carry a flag Is_Overloaded to indicate whether
kono
parents:
diff changeset
128 -- they have more than one interpretation. If the flag is off, then each
kono
parents:
diff changeset
129 -- name has already a unique meaning and type, and the bottom-up pass is
kono
parents:
diff changeset
130 -- sufficient (and much simpler).
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 --------------------------
kono
parents:
diff changeset
133 -- Operator Overloading --
kono
parents:
diff changeset
134 --------------------------
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 -- The visibility of operators is handled differently from that of other
kono
parents:
diff changeset
137 -- entities. We do not introduce explicit versions of primitive operators
kono
parents:
diff changeset
138 -- for each type definition. As a result, there is only one entity
kono
parents:
diff changeset
139 -- corresponding to predefined addition on all numeric types, etc. The
kono
parents:
diff changeset
140 -- back end resolves predefined operators according to their type. The
kono
parents:
diff changeset
141 -- visibility of primitive operations then reduces to the visibility of the
kono
parents:
diff changeset
142 -- resulting type: (a + b) is a legal interpretation of some primitive
kono
parents:
diff changeset
143 -- operator + if the type of the result (which must also be the type of a
kono
parents:
diff changeset
144 -- and b) is directly visible (either immediately visible or use-visible).
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 -- User-defined operators are treated like other functions, but the
kono
parents:
diff changeset
147 -- visibility of these user-defined operations must be special-cased
kono
parents:
diff changeset
148 -- to determine whether they hide or are hidden by predefined operators.
kono
parents:
diff changeset
149 -- The form P."+" (x, y) requires additional handling.
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 -- Concatenation is treated more conventionally: for every one-dimensional
kono
parents:
diff changeset
152 -- array type we introduce a explicit concatenation operator. This is
kono
parents:
diff changeset
153 -- necessary to handle the case of (element & element => array) which
kono
parents:
diff changeset
154 -- cannot be handled conveniently if there is no explicit instance of
kono
parents:
diff changeset
155 -- resulting type of the operation.
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 -----------------------
kono
parents:
diff changeset
158 -- Local Subprograms --
kono
parents:
diff changeset
159 -----------------------
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 procedure All_Overloads;
kono
parents:
diff changeset
162 pragma Warnings (Off, All_Overloads);
kono
parents:
diff changeset
163 -- Debugging procedure: list full contents of Overloads table
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 function Binary_Op_Interp_Has_Abstract_Op
kono
parents:
diff changeset
166 (N : Node_Id;
kono
parents:
diff changeset
167 E : Entity_Id) return Entity_Id;
kono
parents:
diff changeset
168 -- Given the node and entity of a binary operator, determine whether the
kono
parents:
diff changeset
169 -- actuals of E contain an abstract interpretation with regards to the
kono
parents:
diff changeset
170 -- types of their corresponding formals. Return the abstract operation or
kono
parents:
diff changeset
171 -- Empty.
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 function Function_Interp_Has_Abstract_Op
kono
parents:
diff changeset
174 (N : Node_Id;
kono
parents:
diff changeset
175 E : Entity_Id) return Entity_Id;
kono
parents:
diff changeset
176 -- Given the node and entity of a function call, determine whether the
kono
parents:
diff changeset
177 -- actuals of E contain an abstract interpretation with regards to the
kono
parents:
diff changeset
178 -- types of their corresponding formals. Return the abstract operation or
kono
parents:
diff changeset
179 -- Empty.
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 function Has_Abstract_Op
kono
parents:
diff changeset
182 (N : Node_Id;
kono
parents:
diff changeset
183 Typ : Entity_Id) return Entity_Id;
kono
parents:
diff changeset
184 -- Subsidiary routine to Binary_Op_Interp_Has_Abstract_Op and Function_
kono
parents:
diff changeset
185 -- Interp_Has_Abstract_Op. Determine whether an overloaded node has an
kono
parents:
diff changeset
186 -- abstract interpretation which yields type Typ.
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 procedure New_Interps (N : Node_Id);
kono
parents:
diff changeset
189 -- Initialize collection of interpretations for the given node, which is
kono
parents:
diff changeset
190 -- either an overloaded entity, or an operation whose arguments have
kono
parents:
diff changeset
191 -- multiple interpretations. Interpretations can be added to only one
kono
parents:
diff changeset
192 -- node at a time.
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 function Specific_Type (Typ_1, Typ_2 : Entity_Id) return Entity_Id;
kono
parents:
diff changeset
195 -- If Typ_1 and Typ_2 are compatible, return the one that is not universal
kono
parents:
diff changeset
196 -- or is not a "class" type (any_character, etc).
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 --------------------
kono
parents:
diff changeset
199 -- Add_One_Interp --
kono
parents:
diff changeset
200 --------------------
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 procedure Add_One_Interp
kono
parents:
diff changeset
203 (N : Node_Id;
kono
parents:
diff changeset
204 E : Entity_Id;
kono
parents:
diff changeset
205 T : Entity_Id;
kono
parents:
diff changeset
206 Opnd_Type : Entity_Id := Empty)
kono
parents:
diff changeset
207 is
kono
parents:
diff changeset
208 Vis_Type : Entity_Id;
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 procedure Add_Entry (Name : Entity_Id; Typ : Entity_Id);
kono
parents:
diff changeset
211 -- Add one interpretation to an overloaded node. Add a new entry if
kono
parents:
diff changeset
212 -- not hidden by previous one, and remove previous one if hidden by
kono
parents:
diff changeset
213 -- new one.
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 function Is_Universal_Operation (Op : Entity_Id) return Boolean;
kono
parents:
diff changeset
216 -- True if the entity is a predefined operator and the operands have
kono
parents:
diff changeset
217 -- a universal Interpretation.
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 ---------------
kono
parents:
diff changeset
220 -- Add_Entry --
kono
parents:
diff changeset
221 ---------------
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 procedure Add_Entry (Name : Entity_Id; Typ : Entity_Id) is
kono
parents:
diff changeset
224 Abstr_Op : Entity_Id := Empty;
kono
parents:
diff changeset
225 I : Interp_Index;
kono
parents:
diff changeset
226 It : Interp;
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 -- Start of processing for Add_Entry
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 begin
kono
parents:
diff changeset
231 -- Find out whether the new entry references interpretations that
kono
parents:
diff changeset
232 -- are abstract or disabled by abstract operators.
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 if Ada_Version >= Ada_2005 then
kono
parents:
diff changeset
235 if Nkind (N) in N_Binary_Op then
kono
parents:
diff changeset
236 Abstr_Op := Binary_Op_Interp_Has_Abstract_Op (N, Name);
kono
parents:
diff changeset
237 elsif Nkind (N) = N_Function_Call then
kono
parents:
diff changeset
238 Abstr_Op := Function_Interp_Has_Abstract_Op (N, Name);
kono
parents:
diff changeset
239 end if;
kono
parents:
diff changeset
240 end if;
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 Get_First_Interp (N, I, It);
kono
parents:
diff changeset
243 while Present (It.Nam) loop
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 -- A user-defined subprogram hides another declared at an outer
kono
parents:
diff changeset
246 -- level, or one that is use-visible. So return if previous
kono
parents:
diff changeset
247 -- definition hides new one (which is either in an outer
kono
parents:
diff changeset
248 -- scope, or use-visible). Note that for functions use-visible
kono
parents:
diff changeset
249 -- is the same as potentially use-visible. If new one hides
kono
parents:
diff changeset
250 -- previous one, replace entry in table of interpretations.
kono
parents:
diff changeset
251 -- If this is a universal operation, retain the operator in case
kono
parents:
diff changeset
252 -- preference rule applies.
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 if (((Ekind (Name) = E_Function or else Ekind (Name) = E_Procedure)
kono
parents:
diff changeset
255 and then Ekind (Name) = Ekind (It.Nam))
kono
parents:
diff changeset
256 or else (Ekind (Name) = E_Operator
kono
parents:
diff changeset
257 and then Ekind (It.Nam) = E_Function))
kono
parents:
diff changeset
258 and then Is_Immediately_Visible (It.Nam)
kono
parents:
diff changeset
259 and then Type_Conformant (Name, It.Nam)
kono
parents:
diff changeset
260 and then Base_Type (It.Typ) = Base_Type (T)
kono
parents:
diff changeset
261 then
kono
parents:
diff changeset
262 if Is_Universal_Operation (Name) then
kono
parents:
diff changeset
263 exit;
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 -- If node is an operator symbol, we have no actuals with
kono
parents:
diff changeset
266 -- which to check hiding, and this is done in full in the
kono
parents:
diff changeset
267 -- caller (Analyze_Subprogram_Renaming) so we include the
kono
parents:
diff changeset
268 -- predefined operator in any case.
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 elsif Nkind (N) = N_Operator_Symbol
kono
parents:
diff changeset
271 or else
kono
parents:
diff changeset
272 (Nkind (N) = N_Expanded_Name
kono
parents:
diff changeset
273 and then Nkind (Selector_Name (N)) = N_Operator_Symbol)
kono
parents:
diff changeset
274 then
kono
parents:
diff changeset
275 exit;
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 elsif not In_Open_Scopes (Scope (Name))
kono
parents:
diff changeset
278 or else Scope_Depth (Scope (Name)) <=
kono
parents:
diff changeset
279 Scope_Depth (Scope (It.Nam))
kono
parents:
diff changeset
280 then
kono
parents:
diff changeset
281 -- If ambiguity within instance, and entity is not an
kono
parents:
diff changeset
282 -- implicit operation, save for later disambiguation.
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 if Scope (Name) = Scope (It.Nam)
kono
parents:
diff changeset
285 and then not Is_Inherited_Operation (Name)
kono
parents:
diff changeset
286 and then In_Instance
kono
parents:
diff changeset
287 then
kono
parents:
diff changeset
288 exit;
kono
parents:
diff changeset
289 else
kono
parents:
diff changeset
290 return;
kono
parents:
diff changeset
291 end if;
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 else
kono
parents:
diff changeset
294 All_Interp.Table (I).Nam := Name;
kono
parents:
diff changeset
295 return;
kono
parents:
diff changeset
296 end if;
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 -- Avoid making duplicate entries in overloads
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 elsif Name = It.Nam
kono
parents:
diff changeset
301 and then Base_Type (It.Typ) = Base_Type (T)
kono
parents:
diff changeset
302 then
kono
parents:
diff changeset
303 return;
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 -- Otherwise keep going
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 else
kono
parents:
diff changeset
308 Get_Next_Interp (I, It);
kono
parents:
diff changeset
309 end if;
kono
parents:
diff changeset
310 end loop;
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 All_Interp.Table (All_Interp.Last) := (Name, Typ, Abstr_Op);
kono
parents:
diff changeset
313 All_Interp.Append (No_Interp);
kono
parents:
diff changeset
314 end Add_Entry;
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 ----------------------------
kono
parents:
diff changeset
317 -- Is_Universal_Operation --
kono
parents:
diff changeset
318 ----------------------------
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 function Is_Universal_Operation (Op : Entity_Id) return Boolean is
kono
parents:
diff changeset
321 Arg : Node_Id;
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 begin
kono
parents:
diff changeset
324 if Ekind (Op) /= E_Operator then
kono
parents:
diff changeset
325 return False;
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 elsif Nkind (N) in N_Binary_Op then
kono
parents:
diff changeset
328 return Present (Universal_Interpretation (Left_Opnd (N)))
kono
parents:
diff changeset
329 and then Present (Universal_Interpretation (Right_Opnd (N)));
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 elsif Nkind (N) in N_Unary_Op then
kono
parents:
diff changeset
332 return Present (Universal_Interpretation (Right_Opnd (N)));
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 elsif Nkind (N) = N_Function_Call then
kono
parents:
diff changeset
335 Arg := First_Actual (N);
kono
parents:
diff changeset
336 while Present (Arg) loop
kono
parents:
diff changeset
337 if No (Universal_Interpretation (Arg)) then
kono
parents:
diff changeset
338 return False;
kono
parents:
diff changeset
339 end if;
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 Next_Actual (Arg);
kono
parents:
diff changeset
342 end loop;
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 return True;
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 else
kono
parents:
diff changeset
347 return False;
kono
parents:
diff changeset
348 end if;
kono
parents:
diff changeset
349 end Is_Universal_Operation;
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 -- Start of processing for Add_One_Interp
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 begin
kono
parents:
diff changeset
354 -- If the interpretation is a predefined operator, verify that the
kono
parents:
diff changeset
355 -- result type is visible, or that the entity has already been
kono
parents:
diff changeset
356 -- resolved (case of an instantiation node that refers to a predefined
kono
parents:
diff changeset
357 -- operation, or an internally generated operator node, or an operator
kono
parents:
diff changeset
358 -- given as an expanded name). If the operator is a comparison or
kono
parents:
diff changeset
359 -- equality, it is the type of the operand that matters to determine
kono
parents:
diff changeset
360 -- whether the operator is visible. In an instance, the check is not
kono
parents:
diff changeset
361 -- performed, given that the operator was visible in the generic.
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 if Ekind (E) = E_Operator then
kono
parents:
diff changeset
364 if Present (Opnd_Type) then
kono
parents:
diff changeset
365 Vis_Type := Opnd_Type;
kono
parents:
diff changeset
366 else
kono
parents:
diff changeset
367 Vis_Type := Base_Type (T);
kono
parents:
diff changeset
368 end if;
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 if In_Open_Scopes (Scope (Vis_Type))
kono
parents:
diff changeset
371 or else Is_Potentially_Use_Visible (Vis_Type)
kono
parents:
diff changeset
372 or else In_Use (Vis_Type)
kono
parents:
diff changeset
373 or else (In_Use (Scope (Vis_Type))
kono
parents:
diff changeset
374 and then not Is_Hidden (Vis_Type))
kono
parents:
diff changeset
375 or else Nkind (N) = N_Expanded_Name
kono
parents:
diff changeset
376 or else (Nkind (N) in N_Op and then E = Entity (N))
kono
parents:
diff changeset
377 or else (In_Instance or else In_Inlined_Body)
kono
parents:
diff changeset
378 or else Ekind (Vis_Type) = E_Anonymous_Access_Type
kono
parents:
diff changeset
379 then
kono
parents:
diff changeset
380 null;
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 -- If the node is given in functional notation and the prefix
kono
parents:
diff changeset
383 -- is an expanded name, then the operator is visible if the
kono
parents:
diff changeset
384 -- prefix is the scope of the result type as well. If the
kono
parents:
diff changeset
385 -- operator is (implicitly) defined in an extension of system,
kono
parents:
diff changeset
386 -- it is know to be valid (see Defined_In_Scope, sem_ch4.adb).
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388 elsif Nkind (N) = N_Function_Call
kono
parents:
diff changeset
389 and then Nkind (Name (N)) = N_Expanded_Name
kono
parents:
diff changeset
390 and then (Entity (Prefix (Name (N))) = Scope (Base_Type (T))
kono
parents:
diff changeset
391 or else Entity (Prefix (Name (N))) = Scope (Vis_Type)
kono
parents:
diff changeset
392 or else Scope (Vis_Type) = System_Aux_Id)
kono
parents:
diff changeset
393 then
kono
parents:
diff changeset
394 null;
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 -- Save type for subsequent error message, in case no other
kono
parents:
diff changeset
397 -- interpretation is found.
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 else
kono
parents:
diff changeset
400 Candidate_Type := Vis_Type;
kono
parents:
diff changeset
401 return;
kono
parents:
diff changeset
402 end if;
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 -- In an instance, an abstract non-dispatching operation cannot be a
kono
parents:
diff changeset
405 -- candidate interpretation, because it could not have been one in the
kono
parents:
diff changeset
406 -- generic (it may be a spurious overloading in the instance).
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 elsif In_Instance
kono
parents:
diff changeset
409 and then Is_Overloadable (E)
kono
parents:
diff changeset
410 and then Is_Abstract_Subprogram (E)
kono
parents:
diff changeset
411 and then not Is_Dispatching_Operation (E)
kono
parents:
diff changeset
412 then
kono
parents:
diff changeset
413 return;
kono
parents:
diff changeset
414
kono
parents:
diff changeset
415 -- An inherited interface operation that is implemented by some derived
kono
parents:
diff changeset
416 -- type does not participate in overload resolution, only the
kono
parents:
diff changeset
417 -- implementation operation does.
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 elsif Is_Hidden (E)
kono
parents:
diff changeset
420 and then Is_Subprogram (E)
kono
parents:
diff changeset
421 and then Present (Interface_Alias (E))
kono
parents:
diff changeset
422 then
kono
parents:
diff changeset
423 -- Ada 2005 (AI-251): If this primitive operation corresponds with
kono
parents:
diff changeset
424 -- an immediate ancestor interface there is no need to add it to the
kono
parents:
diff changeset
425 -- list of interpretations. The corresponding aliased primitive is
kono
parents:
diff changeset
426 -- also in this list of primitive operations and will be used instead
kono
parents:
diff changeset
427 -- because otherwise we have a dummy ambiguity between the two
kono
parents:
diff changeset
428 -- subprograms which are in fact the same.
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 if not Is_Ancestor
kono
parents:
diff changeset
431 (Find_Dispatching_Type (Interface_Alias (E)),
kono
parents:
diff changeset
432 Find_Dispatching_Type (E))
kono
parents:
diff changeset
433 then
kono
parents:
diff changeset
434 Add_One_Interp (N, Interface_Alias (E), T);
kono
parents:
diff changeset
435 end if;
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 return;
kono
parents:
diff changeset
438
kono
parents:
diff changeset
439 -- Calling stubs for an RACW operation never participate in resolution,
kono
parents:
diff changeset
440 -- they are executed only through dispatching calls.
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 elsif Is_RACW_Stub_Type_Operation (E) then
kono
parents:
diff changeset
443 return;
kono
parents:
diff changeset
444 end if;
kono
parents:
diff changeset
445
kono
parents:
diff changeset
446 -- If this is the first interpretation of N, N has type Any_Type.
kono
parents:
diff changeset
447 -- In that case place the new type on the node. If one interpretation
kono
parents:
diff changeset
448 -- already exists, indicate that the node is overloaded, and store
kono
parents:
diff changeset
449 -- both the previous and the new interpretation in All_Interp. If
kono
parents:
diff changeset
450 -- this is a later interpretation, just add it to the set.
kono
parents:
diff changeset
451
kono
parents:
diff changeset
452 if Etype (N) = Any_Type then
kono
parents:
diff changeset
453 if Is_Type (E) then
kono
parents:
diff changeset
454 Set_Etype (N, T);
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 else
kono
parents:
diff changeset
457 -- Record both the operator or subprogram name, and its type
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 if Nkind (N) in N_Op or else Is_Entity_Name (N) then
kono
parents:
diff changeset
460 Set_Entity (N, E);
kono
parents:
diff changeset
461 end if;
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 Set_Etype (N, T);
kono
parents:
diff changeset
464 end if;
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 -- Either there is no current interpretation in the table for any
kono
parents:
diff changeset
467 -- node or the interpretation that is present is for a different
kono
parents:
diff changeset
468 -- node. In both cases add a new interpretation to the table.
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 elsif Interp_Map.Last < 0
kono
parents:
diff changeset
471 or else
kono
parents:
diff changeset
472 (Interp_Map.Table (Interp_Map.Last).Node /= N
kono
parents:
diff changeset
473 and then not Is_Overloaded (N))
kono
parents:
diff changeset
474 then
kono
parents:
diff changeset
475 New_Interps (N);
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 if (Nkind (N) in N_Op or else Is_Entity_Name (N))
kono
parents:
diff changeset
478 and then Present (Entity (N))
kono
parents:
diff changeset
479 then
kono
parents:
diff changeset
480 Add_Entry (Entity (N), Etype (N));
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 elsif Nkind (N) in N_Subprogram_Call
kono
parents:
diff changeset
483 and then Is_Entity_Name (Name (N))
kono
parents:
diff changeset
484 then
kono
parents:
diff changeset
485 Add_Entry (Entity (Name (N)), Etype (N));
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 -- If this is an indirect call there will be no name associated
kono
parents:
diff changeset
488 -- with the previous entry. To make diagnostics clearer, save
kono
parents:
diff changeset
489 -- Subprogram_Type of first interpretation, so that the error will
kono
parents:
diff changeset
490 -- point to the anonymous access to subprogram, not to the result
kono
parents:
diff changeset
491 -- type of the call itself.
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 elsif (Nkind (N)) = N_Function_Call
kono
parents:
diff changeset
494 and then Nkind (Name (N)) = N_Explicit_Dereference
kono
parents:
diff changeset
495 and then Is_Overloaded (Name (N))
kono
parents:
diff changeset
496 then
kono
parents:
diff changeset
497 declare
kono
parents:
diff changeset
498 It : Interp;
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 Itn : Interp_Index;
kono
parents:
diff changeset
501 pragma Warnings (Off, Itn);
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503 begin
kono
parents:
diff changeset
504 Get_First_Interp (Name (N), Itn, It);
kono
parents:
diff changeset
505 Add_Entry (It.Nam, Etype (N));
kono
parents:
diff changeset
506 end;
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 else
kono
parents:
diff changeset
509 -- Overloaded prefix in indexed or selected component, or call
kono
parents:
diff changeset
510 -- whose name is an expression or another call.
kono
parents:
diff changeset
511
kono
parents:
diff changeset
512 Add_Entry (Etype (N), Etype (N));
kono
parents:
diff changeset
513 end if;
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 Add_Entry (E, T);
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 else
kono
parents:
diff changeset
518 Add_Entry (E, T);
kono
parents:
diff changeset
519 end if;
kono
parents:
diff changeset
520 end Add_One_Interp;
kono
parents:
diff changeset
521
kono
parents:
diff changeset
522 -------------------
kono
parents:
diff changeset
523 -- All_Overloads --
kono
parents:
diff changeset
524 -------------------
kono
parents:
diff changeset
525
kono
parents:
diff changeset
526 procedure All_Overloads is
kono
parents:
diff changeset
527 begin
kono
parents:
diff changeset
528 for J in All_Interp.First .. All_Interp.Last loop
kono
parents:
diff changeset
529
kono
parents:
diff changeset
530 if Present (All_Interp.Table (J).Nam) then
kono
parents:
diff changeset
531 Write_Entity_Info (All_Interp.Table (J). Nam, " ");
kono
parents:
diff changeset
532 else
kono
parents:
diff changeset
533 Write_Str ("No Interp");
kono
parents:
diff changeset
534 Write_Eol;
kono
parents:
diff changeset
535 end if;
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537 Write_Str ("=================");
kono
parents:
diff changeset
538 Write_Eol;
kono
parents:
diff changeset
539 end loop;
kono
parents:
diff changeset
540 end All_Overloads;
kono
parents:
diff changeset
541
kono
parents:
diff changeset
542 --------------------------------------
kono
parents:
diff changeset
543 -- Binary_Op_Interp_Has_Abstract_Op --
kono
parents:
diff changeset
544 --------------------------------------
kono
parents:
diff changeset
545
kono
parents:
diff changeset
546 function Binary_Op_Interp_Has_Abstract_Op
kono
parents:
diff changeset
547 (N : Node_Id;
kono
parents:
diff changeset
548 E : Entity_Id) return Entity_Id
kono
parents:
diff changeset
549 is
kono
parents:
diff changeset
550 Abstr_Op : Entity_Id;
kono
parents:
diff changeset
551 E_Left : constant Node_Id := First_Formal (E);
kono
parents:
diff changeset
552 E_Right : constant Node_Id := Next_Formal (E_Left);
kono
parents:
diff changeset
553
kono
parents:
diff changeset
554 begin
kono
parents:
diff changeset
555 Abstr_Op := Has_Abstract_Op (Left_Opnd (N), Etype (E_Left));
kono
parents:
diff changeset
556 if Present (Abstr_Op) then
kono
parents:
diff changeset
557 return Abstr_Op;
kono
parents:
diff changeset
558 end if;
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 return Has_Abstract_Op (Right_Opnd (N), Etype (E_Right));
kono
parents:
diff changeset
561 end Binary_Op_Interp_Has_Abstract_Op;
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 ---------------------
kono
parents:
diff changeset
564 -- Collect_Interps --
kono
parents:
diff changeset
565 ---------------------
kono
parents:
diff changeset
566
kono
parents:
diff changeset
567 procedure Collect_Interps (N : Node_Id) is
kono
parents:
diff changeset
568 Ent : constant Entity_Id := Entity (N);
kono
parents:
diff changeset
569 H : Entity_Id;
kono
parents:
diff changeset
570 First_Interp : Interp_Index;
kono
parents:
diff changeset
571
kono
parents:
diff changeset
572 function Within_Instance (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
573 -- Within an instance there can be spurious ambiguities between a local
kono
parents:
diff changeset
574 -- entity and one declared outside of the instance. This can only happen
kono
parents:
diff changeset
575 -- for subprograms, because otherwise the local entity hides the outer
kono
parents:
diff changeset
576 -- one. For an overloadable entity, this predicate determines whether it
kono
parents:
diff changeset
577 -- is a candidate within the instance, or must be ignored.
kono
parents:
diff changeset
578
kono
parents:
diff changeset
579 ---------------------
kono
parents:
diff changeset
580 -- Within_Instance --
kono
parents:
diff changeset
581 ---------------------
kono
parents:
diff changeset
582
kono
parents:
diff changeset
583 function Within_Instance (E : Entity_Id) return Boolean is
kono
parents:
diff changeset
584 Inst : Entity_Id;
kono
parents:
diff changeset
585 Scop : Entity_Id;
kono
parents:
diff changeset
586
kono
parents:
diff changeset
587 begin
kono
parents:
diff changeset
588 if not In_Instance then
kono
parents:
diff changeset
589 return False;
kono
parents:
diff changeset
590 end if;
kono
parents:
diff changeset
591
kono
parents:
diff changeset
592 Inst := Current_Scope;
kono
parents:
diff changeset
593 while Present (Inst) and then not Is_Generic_Instance (Inst) loop
kono
parents:
diff changeset
594 Inst := Scope (Inst);
kono
parents:
diff changeset
595 end loop;
kono
parents:
diff changeset
596
kono
parents:
diff changeset
597 Scop := Scope (E);
kono
parents:
diff changeset
598 while Present (Scop) and then Scop /= Standard_Standard loop
kono
parents:
diff changeset
599 if Scop = Inst then
kono
parents:
diff changeset
600 return True;
kono
parents:
diff changeset
601 end if;
kono
parents:
diff changeset
602
kono
parents:
diff changeset
603 Scop := Scope (Scop);
kono
parents:
diff changeset
604 end loop;
kono
parents:
diff changeset
605
kono
parents:
diff changeset
606 return False;
kono
parents:
diff changeset
607 end Within_Instance;
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 -- Start of processing for Collect_Interps
kono
parents:
diff changeset
610
kono
parents:
diff changeset
611 begin
kono
parents:
diff changeset
612 New_Interps (N);
kono
parents:
diff changeset
613
kono
parents:
diff changeset
614 -- Unconditionally add the entity that was initially matched
kono
parents:
diff changeset
615
kono
parents:
diff changeset
616 First_Interp := All_Interp.Last;
kono
parents:
diff changeset
617 Add_One_Interp (N, Ent, Etype (N));
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 -- For expanded name, pick up all additional entities from the
kono
parents:
diff changeset
620 -- same scope, since these are obviously also visible. Note that
kono
parents:
diff changeset
621 -- these are not necessarily contiguous on the homonym chain.
kono
parents:
diff changeset
622
kono
parents:
diff changeset
623 if Nkind (N) = N_Expanded_Name then
kono
parents:
diff changeset
624 H := Homonym (Ent);
kono
parents:
diff changeset
625 while Present (H) loop
kono
parents:
diff changeset
626 if Scope (H) = Scope (Entity (N)) then
kono
parents:
diff changeset
627 Add_One_Interp (N, H, Etype (H));
kono
parents:
diff changeset
628 end if;
kono
parents:
diff changeset
629
kono
parents:
diff changeset
630 H := Homonym (H);
kono
parents:
diff changeset
631 end loop;
kono
parents:
diff changeset
632
kono
parents:
diff changeset
633 -- Case of direct name
kono
parents:
diff changeset
634
kono
parents:
diff changeset
635 else
kono
parents:
diff changeset
636 -- First, search the homonym chain for directly visible entities
kono
parents:
diff changeset
637
kono
parents:
diff changeset
638 H := Current_Entity (Ent);
kono
parents:
diff changeset
639 while Present (H) loop
kono
parents:
diff changeset
640 exit when
kono
parents:
diff changeset
641 not Is_Overloadable (H)
kono
parents:
diff changeset
642 and then Is_Immediately_Visible (H);
kono
parents:
diff changeset
643
kono
parents:
diff changeset
644 if Is_Immediately_Visible (H) and then H /= Ent then
kono
parents:
diff changeset
645
kono
parents:
diff changeset
646 -- Only add interpretation if not hidden by an inner
kono
parents:
diff changeset
647 -- immediately visible one.
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 for J in First_Interp .. All_Interp.Last - 1 loop
kono
parents:
diff changeset
650
kono
parents:
diff changeset
651 -- Current homograph is not hidden. Add to overloads
kono
parents:
diff changeset
652
kono
parents:
diff changeset
653 if not Is_Immediately_Visible (All_Interp.Table (J).Nam) then
kono
parents:
diff changeset
654 exit;
kono
parents:
diff changeset
655
kono
parents:
diff changeset
656 -- Homograph is hidden, unless it is a predefined operator
kono
parents:
diff changeset
657
kono
parents:
diff changeset
658 elsif Type_Conformant (H, All_Interp.Table (J).Nam) then
kono
parents:
diff changeset
659
kono
parents:
diff changeset
660 -- A homograph in the same scope can occur within an
kono
parents:
diff changeset
661 -- instantiation, the resulting ambiguity has to be
kono
parents:
diff changeset
662 -- resolved later. The homographs may both be local
kono
parents:
diff changeset
663 -- functions or actuals, or may be declared at different
kono
parents:
diff changeset
664 -- levels within the instance. The renaming of an actual
kono
parents:
diff changeset
665 -- within the instance must not be included.
kono
parents:
diff changeset
666
kono
parents:
diff changeset
667 if Within_Instance (H)
kono
parents:
diff changeset
668 and then H /= Renamed_Entity (Ent)
kono
parents:
diff changeset
669 and then not Is_Inherited_Operation (H)
kono
parents:
diff changeset
670 then
kono
parents:
diff changeset
671 All_Interp.Table (All_Interp.Last) :=
kono
parents:
diff changeset
672 (H, Etype (H), Empty);
kono
parents:
diff changeset
673 All_Interp.Append (No_Interp);
kono
parents:
diff changeset
674 goto Next_Homograph;
kono
parents:
diff changeset
675
kono
parents:
diff changeset
676 elsif Scope (H) /= Standard_Standard then
kono
parents:
diff changeset
677 goto Next_Homograph;
kono
parents:
diff changeset
678 end if;
kono
parents:
diff changeset
679 end if;
kono
parents:
diff changeset
680 end loop;
kono
parents:
diff changeset
681
kono
parents:
diff changeset
682 -- On exit, we know that current homograph is not hidden
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 Add_One_Interp (N, H, Etype (H));
kono
parents:
diff changeset
685
kono
parents:
diff changeset
686 if Debug_Flag_E then
kono
parents:
diff changeset
687 Write_Str ("Add overloaded interpretation ");
kono
parents:
diff changeset
688 Write_Int (Int (H));
kono
parents:
diff changeset
689 Write_Eol;
kono
parents:
diff changeset
690 end if;
kono
parents:
diff changeset
691 end if;
kono
parents:
diff changeset
692
kono
parents:
diff changeset
693 <<Next_Homograph>>
kono
parents:
diff changeset
694 H := Homonym (H);
kono
parents:
diff changeset
695 end loop;
kono
parents:
diff changeset
696
kono
parents:
diff changeset
697 -- Scan list of homographs for use-visible entities only
kono
parents:
diff changeset
698
kono
parents:
diff changeset
699 H := Current_Entity (Ent);
kono
parents:
diff changeset
700
kono
parents:
diff changeset
701 while Present (H) loop
kono
parents:
diff changeset
702 if Is_Potentially_Use_Visible (H)
kono
parents:
diff changeset
703 and then H /= Ent
kono
parents:
diff changeset
704 and then Is_Overloadable (H)
kono
parents:
diff changeset
705 then
kono
parents:
diff changeset
706 for J in First_Interp .. All_Interp.Last - 1 loop
kono
parents:
diff changeset
707
kono
parents:
diff changeset
708 if not Is_Immediately_Visible (All_Interp.Table (J).Nam) then
kono
parents:
diff changeset
709 exit;
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 elsif Type_Conformant (H, All_Interp.Table (J).Nam) then
kono
parents:
diff changeset
712 goto Next_Use_Homograph;
kono
parents:
diff changeset
713 end if;
kono
parents:
diff changeset
714 end loop;
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 Add_One_Interp (N, H, Etype (H));
kono
parents:
diff changeset
717 end if;
kono
parents:
diff changeset
718
kono
parents:
diff changeset
719 <<Next_Use_Homograph>>
kono
parents:
diff changeset
720 H := Homonym (H);
kono
parents:
diff changeset
721 end loop;
kono
parents:
diff changeset
722 end if;
kono
parents:
diff changeset
723
kono
parents:
diff changeset
724 if All_Interp.Last = First_Interp + 1 then
kono
parents:
diff changeset
725
kono
parents:
diff changeset
726 -- The final interpretation is in fact not overloaded. Note that the
kono
parents:
diff changeset
727 -- unique legal interpretation may or may not be the original one,
kono
parents:
diff changeset
728 -- so we need to update N's entity and etype now, because once N
kono
parents:
diff changeset
729 -- is marked as not overloaded it is also expected to carry the
kono
parents:
diff changeset
730 -- proper interpretation.
kono
parents:
diff changeset
731
kono
parents:
diff changeset
732 Set_Is_Overloaded (N, False);
kono
parents:
diff changeset
733 Set_Entity (N, All_Interp.Table (First_Interp).Nam);
kono
parents:
diff changeset
734 Set_Etype (N, All_Interp.Table (First_Interp).Typ);
kono
parents:
diff changeset
735 end if;
kono
parents:
diff changeset
736 end Collect_Interps;
kono
parents:
diff changeset
737
kono
parents:
diff changeset
738 ------------
kono
parents:
diff changeset
739 -- Covers --
kono
parents:
diff changeset
740 ------------
kono
parents:
diff changeset
741
kono
parents:
diff changeset
742 function Covers (T1, T2 : Entity_Id) return Boolean is
kono
parents:
diff changeset
743 BT1 : Entity_Id;
kono
parents:
diff changeset
744 BT2 : Entity_Id;
kono
parents:
diff changeset
745
kono
parents:
diff changeset
746 function Full_View_Covers (Typ1, Typ2 : Entity_Id) return Boolean;
kono
parents:
diff changeset
747 -- In an instance the proper view may not always be correct for
kono
parents:
diff changeset
748 -- private types, but private and full view are compatible. This
kono
parents:
diff changeset
749 -- removes spurious errors from nested instantiations that involve,
kono
parents:
diff changeset
750 -- among other things, types derived from private types.
kono
parents:
diff changeset
751
kono
parents:
diff changeset
752 function Real_Actual (T : Entity_Id) return Entity_Id;
kono
parents:
diff changeset
753 -- If an actual in an inner instance is the formal of an enclosing
kono
parents:
diff changeset
754 -- generic, the actual in the enclosing instance is the one that can
kono
parents:
diff changeset
755 -- create an accidental ambiguity, and the check on compatibily of
kono
parents:
diff changeset
756 -- generic actual types must use this enclosing actual.
kono
parents:
diff changeset
757
kono
parents:
diff changeset
758 ----------------------
kono
parents:
diff changeset
759 -- Full_View_Covers --
kono
parents:
diff changeset
760 ----------------------
kono
parents:
diff changeset
761
kono
parents:
diff changeset
762 function Full_View_Covers (Typ1, Typ2 : Entity_Id) return Boolean is
kono
parents:
diff changeset
763 begin
kono
parents:
diff changeset
764 if Present (Full_View (Typ1))
kono
parents:
diff changeset
765 and then Covers (Full_View (Typ1), Typ2)
kono
parents:
diff changeset
766 then
kono
parents:
diff changeset
767 return True;
kono
parents:
diff changeset
768
kono
parents:
diff changeset
769 elsif Present (Underlying_Full_View (Typ1))
kono
parents:
diff changeset
770 and then Covers (Underlying_Full_View (Typ1), Typ2)
kono
parents:
diff changeset
771 then
kono
parents:
diff changeset
772 return True;
kono
parents:
diff changeset
773
kono
parents:
diff changeset
774 else
kono
parents:
diff changeset
775 return False;
kono
parents:
diff changeset
776 end if;
kono
parents:
diff changeset
777 end Full_View_Covers;
kono
parents:
diff changeset
778
kono
parents:
diff changeset
779 -----------------
kono
parents:
diff changeset
780 -- Real_Actual --
kono
parents:
diff changeset
781 -----------------
kono
parents:
diff changeset
782
kono
parents:
diff changeset
783 function Real_Actual (T : Entity_Id) return Entity_Id is
kono
parents:
diff changeset
784 Par : constant Node_Id := Parent (T);
kono
parents:
diff changeset
785 RA : Entity_Id;
kono
parents:
diff changeset
786
kono
parents:
diff changeset
787 begin
kono
parents:
diff changeset
788 -- Retrieve parent subtype from subtype declaration for actual
kono
parents:
diff changeset
789
kono
parents:
diff changeset
790 if Nkind (Par) = N_Subtype_Declaration
kono
parents:
diff changeset
791 and then not Comes_From_Source (Par)
kono
parents:
diff changeset
792 and then Is_Entity_Name (Subtype_Indication (Par))
kono
parents:
diff changeset
793 then
kono
parents:
diff changeset
794 RA := Entity (Subtype_Indication (Par));
kono
parents:
diff changeset
795
kono
parents:
diff changeset
796 if Is_Generic_Actual_Type (RA) then
kono
parents:
diff changeset
797 return RA;
kono
parents:
diff changeset
798 end if;
kono
parents:
diff changeset
799 end if;
kono
parents:
diff changeset
800
kono
parents:
diff changeset
801 -- Otherwise actual is not the actual of an enclosing instance
kono
parents:
diff changeset
802
kono
parents:
diff changeset
803 return T;
kono
parents:
diff changeset
804 end Real_Actual;
kono
parents:
diff changeset
805
kono
parents:
diff changeset
806 -- Start of processing for Covers
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808 begin
kono
parents:
diff changeset
809 -- If either operand is missing, then this is an error, but ignore it
kono
parents:
diff changeset
810 -- and pretend we have a cover if errors already detected since this may
kono
parents:
diff changeset
811 -- simply mean we have malformed trees or a semantic error upstream.
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 if No (T1) or else No (T2) then
kono
parents:
diff changeset
814 if Total_Errors_Detected /= 0 then
kono
parents:
diff changeset
815 return True;
kono
parents:
diff changeset
816 else
kono
parents:
diff changeset
817 raise Program_Error;
kono
parents:
diff changeset
818 end if;
kono
parents:
diff changeset
819 end if;
kono
parents:
diff changeset
820
kono
parents:
diff changeset
821 -- Trivial case: same types are always compatible
kono
parents:
diff changeset
822
kono
parents:
diff changeset
823 if T1 = T2 then
kono
parents:
diff changeset
824 return True;
kono
parents:
diff changeset
825 end if;
kono
parents:
diff changeset
826
kono
parents:
diff changeset
827 -- First check for Standard_Void_Type, which is special. Subsequent
kono
parents:
diff changeset
828 -- processing in this routine assumes T1 and T2 are bona fide types;
kono
parents:
diff changeset
829 -- Standard_Void_Type is a special entity that has some, but not all,
kono
parents:
diff changeset
830 -- properties of types.
kono
parents:
diff changeset
831
kono
parents:
diff changeset
832 if T1 = Standard_Void_Type or else T2 = Standard_Void_Type then
kono
parents:
diff changeset
833 return False;
kono
parents:
diff changeset
834 end if;
kono
parents:
diff changeset
835
kono
parents:
diff changeset
836 BT1 := Base_Type (T1);
kono
parents:
diff changeset
837 BT2 := Base_Type (T2);
kono
parents:
diff changeset
838
kono
parents:
diff changeset
839 -- Handle underlying view of records with unknown discriminants
kono
parents:
diff changeset
840 -- using the original entity that motivated the construction of
kono
parents:
diff changeset
841 -- this underlying record view (see Build_Derived_Private_Type).
kono
parents:
diff changeset
842
kono
parents:
diff changeset
843 if Is_Underlying_Record_View (BT1) then
kono
parents:
diff changeset
844 BT1 := Underlying_Record_View (BT1);
kono
parents:
diff changeset
845 end if;
kono
parents:
diff changeset
846
kono
parents:
diff changeset
847 if Is_Underlying_Record_View (BT2) then
kono
parents:
diff changeset
848 BT2 := Underlying_Record_View (BT2);
kono
parents:
diff changeset
849 end if;
kono
parents:
diff changeset
850
kono
parents:
diff changeset
851 -- Simplest case: types that have the same base type and are not generic
kono
parents:
diff changeset
852 -- actuals are compatible. Generic actuals belong to their class but are
kono
parents:
diff changeset
853 -- not compatible with other types of their class, and in particular
kono
parents:
diff changeset
854 -- with other generic actuals. They are however compatible with their
kono
parents:
diff changeset
855 -- own subtypes, and itypes with the same base are compatible as well.
kono
parents:
diff changeset
856 -- Similarly, constrained subtypes obtained from expressions of an
kono
parents:
diff changeset
857 -- unconstrained nominal type are compatible with the base type (may
kono
parents:
diff changeset
858 -- lead to spurious ambiguities in obscure cases ???)
kono
parents:
diff changeset
859
kono
parents:
diff changeset
860 -- Generic actuals require special treatment to avoid spurious ambi-
kono
parents:
diff changeset
861 -- guities in an instance, when two formal types are instantiated with
kono
parents:
diff changeset
862 -- the same actual, so that different subprograms end up with the same
kono
parents:
diff changeset
863 -- signature in the instance. If a generic actual is the actual of an
kono
parents:
diff changeset
864 -- enclosing instance, it is that actual that we must compare: generic
kono
parents:
diff changeset
865 -- actuals are only incompatible if they appear in the same instance.
kono
parents:
diff changeset
866
kono
parents:
diff changeset
867 if BT1 = BT2
kono
parents:
diff changeset
868 or else BT1 = T2
kono
parents:
diff changeset
869 or else BT2 = T1
kono
parents:
diff changeset
870 then
kono
parents:
diff changeset
871 if not Is_Generic_Actual_Type (T1)
kono
parents:
diff changeset
872 or else
kono
parents:
diff changeset
873 not Is_Generic_Actual_Type (T2)
kono
parents:
diff changeset
874 then
kono
parents:
diff changeset
875 return True;
kono
parents:
diff changeset
876
kono
parents:
diff changeset
877 -- Both T1 and T2 are generic actual types
kono
parents:
diff changeset
878
kono
parents:
diff changeset
879 else
kono
parents:
diff changeset
880 declare
kono
parents:
diff changeset
881 RT1 : constant Entity_Id := Real_Actual (T1);
kono
parents:
diff changeset
882 RT2 : constant Entity_Id := Real_Actual (T2);
kono
parents:
diff changeset
883 begin
kono
parents:
diff changeset
884 return RT1 = RT2
kono
parents:
diff changeset
885 or else Is_Itype (T1)
kono
parents:
diff changeset
886 or else Is_Itype (T2)
kono
parents:
diff changeset
887 or else Is_Constr_Subt_For_U_Nominal (T1)
kono
parents:
diff changeset
888 or else Is_Constr_Subt_For_U_Nominal (T2)
kono
parents:
diff changeset
889 or else Scope (RT1) /= Scope (RT2);
kono
parents:
diff changeset
890 end;
kono
parents:
diff changeset
891 end if;
kono
parents:
diff changeset
892
kono
parents:
diff changeset
893 -- Literals are compatible with types in a given "class"
kono
parents:
diff changeset
894
kono
parents:
diff changeset
895 elsif (T2 = Universal_Integer and then Is_Integer_Type (T1))
kono
parents:
diff changeset
896 or else (T2 = Universal_Real and then Is_Real_Type (T1))
kono
parents:
diff changeset
897 or else (T2 = Universal_Fixed and then Is_Fixed_Point_Type (T1))
kono
parents:
diff changeset
898 or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
kono
parents:
diff changeset
899 or else (T2 = Any_Character and then Is_Character_Type (T1))
kono
parents:
diff changeset
900 or else (T2 = Any_String and then Is_String_Type (T1))
kono
parents:
diff changeset
901 or else (T2 = Any_Access and then Is_Access_Type (T1))
kono
parents:
diff changeset
902 then
kono
parents:
diff changeset
903 return True;
kono
parents:
diff changeset
904
kono
parents:
diff changeset
905 -- The context may be class wide, and a class-wide type is compatible
kono
parents:
diff changeset
906 -- with any member of the class.
kono
parents:
diff changeset
907
kono
parents:
diff changeset
908 elsif Is_Class_Wide_Type (T1)
kono
parents:
diff changeset
909 and then Is_Ancestor (Root_Type (T1), T2)
kono
parents:
diff changeset
910 then
kono
parents:
diff changeset
911 return True;
kono
parents:
diff changeset
912
kono
parents:
diff changeset
913 elsif Is_Class_Wide_Type (T1)
kono
parents:
diff changeset
914 and then Is_Class_Wide_Type (T2)
kono
parents:
diff changeset
915 and then Base_Type (Etype (T1)) = Base_Type (Etype (T2))
kono
parents:
diff changeset
916 then
kono
parents:
diff changeset
917 return True;
kono
parents:
diff changeset
918
kono
parents:
diff changeset
919 -- Ada 2005 (AI-345): A class-wide abstract interface type covers a
kono
parents:
diff changeset
920 -- task_type or protected_type that implements the interface.
kono
parents:
diff changeset
921
kono
parents:
diff changeset
922 elsif Ada_Version >= Ada_2005
kono
parents:
diff changeset
923 and then Is_Concurrent_Type (T2)
kono
parents:
diff changeset
924 and then Is_Class_Wide_Type (T1)
kono
parents:
diff changeset
925 and then Is_Interface (Etype (T1))
kono
parents:
diff changeset
926 and then Interface_Present_In_Ancestor
kono
parents:
diff changeset
927 (Typ => BT2, Iface => Etype (T1))
kono
parents:
diff changeset
928 then
kono
parents:
diff changeset
929 return True;
kono
parents:
diff changeset
930
kono
parents:
diff changeset
931 -- Ada 2005 (AI-251): A class-wide abstract interface type T1 covers an
kono
parents:
diff changeset
932 -- object T2 implementing T1.
kono
parents:
diff changeset
933
kono
parents:
diff changeset
934 elsif Ada_Version >= Ada_2005
kono
parents:
diff changeset
935 and then Is_Tagged_Type (T2)
kono
parents:
diff changeset
936 and then Is_Class_Wide_Type (T1)
kono
parents:
diff changeset
937 and then Is_Interface (Etype (T1))
kono
parents:
diff changeset
938 then
kono
parents:
diff changeset
939 if Interface_Present_In_Ancestor (Typ => T2,
kono
parents:
diff changeset
940 Iface => Etype (T1))
kono
parents:
diff changeset
941 then
kono
parents:
diff changeset
942 return True;
kono
parents:
diff changeset
943 end if;
kono
parents:
diff changeset
944
kono
parents:
diff changeset
945 declare
kono
parents:
diff changeset
946 E : Entity_Id;
kono
parents:
diff changeset
947 Elmt : Elmt_Id;
kono
parents:
diff changeset
948
kono
parents:
diff changeset
949 begin
kono
parents:
diff changeset
950 if Is_Concurrent_Type (BT2) then
kono
parents:
diff changeset
951 E := Corresponding_Record_Type (BT2);
kono
parents:
diff changeset
952 else
kono
parents:
diff changeset
953 E := BT2;
kono
parents:
diff changeset
954 end if;
kono
parents:
diff changeset
955
kono
parents:
diff changeset
956 -- Ada 2005 (AI-251): A class-wide abstract interface type T1
kono
parents:
diff changeset
957 -- covers an object T2 that implements a direct derivation of T1.
kono
parents:
diff changeset
958 -- Note: test for presence of E is defense against previous error.
kono
parents:
diff changeset
959
kono
parents:
diff changeset
960 if No (E) then
kono
parents:
diff changeset
961
kono
parents:
diff changeset
962 -- If expansion is disabled the Corresponding_Record_Type may
kono
parents:
diff changeset
963 -- not be available yet, so use the interface list in the
kono
parents:
diff changeset
964 -- declaration directly.
kono
parents:
diff changeset
965
kono
parents:
diff changeset
966 if ASIS_Mode
kono
parents:
diff changeset
967 and then Nkind (Parent (BT2)) = N_Protected_Type_Declaration
kono
parents:
diff changeset
968 and then Present (Interface_List (Parent (BT2)))
kono
parents:
diff changeset
969 then
kono
parents:
diff changeset
970 declare
kono
parents:
diff changeset
971 Intf : Node_Id := First (Interface_List (Parent (BT2)));
kono
parents:
diff changeset
972 begin
kono
parents:
diff changeset
973 while Present (Intf) loop
kono
parents:
diff changeset
974 if Is_Ancestor (Etype (T1), Entity (Intf)) then
kono
parents:
diff changeset
975 return True;
kono
parents:
diff changeset
976 else
kono
parents:
diff changeset
977 Next (Intf);
kono
parents:
diff changeset
978 end if;
kono
parents:
diff changeset
979 end loop;
kono
parents:
diff changeset
980 end;
kono
parents:
diff changeset
981
kono
parents:
diff changeset
982 return False;
kono
parents:
diff changeset
983
kono
parents:
diff changeset
984 else
kono
parents:
diff changeset
985 Check_Error_Detected;
kono
parents:
diff changeset
986 end if;
kono
parents:
diff changeset
987
kono
parents:
diff changeset
988 -- Here we have a corresponding record type
kono
parents:
diff changeset
989
kono
parents:
diff changeset
990 elsif Present (Interfaces (E)) then
kono
parents:
diff changeset
991 Elmt := First_Elmt (Interfaces (E));
kono
parents:
diff changeset
992 while Present (Elmt) loop
kono
parents:
diff changeset
993 if Is_Ancestor (Etype (T1), Node (Elmt)) then
kono
parents:
diff changeset
994 return True;
kono
parents:
diff changeset
995 else
kono
parents:
diff changeset
996 Next_Elmt (Elmt);
kono
parents:
diff changeset
997 end if;
kono
parents:
diff changeset
998 end loop;
kono
parents:
diff changeset
999 end if;
kono
parents:
diff changeset
1000
kono
parents:
diff changeset
1001 -- We should also check the case in which T1 is an ancestor of
kono
parents:
diff changeset
1002 -- some implemented interface???
kono
parents:
diff changeset
1003
kono
parents:
diff changeset
1004 return False;
kono
parents:
diff changeset
1005 end;
kono
parents:
diff changeset
1006
kono
parents:
diff changeset
1007 -- In a dispatching call, the formal is of some specific type, and the
kono
parents:
diff changeset
1008 -- actual is of the corresponding class-wide type, including a subtype
kono
parents:
diff changeset
1009 -- of the class-wide type.
kono
parents:
diff changeset
1010
kono
parents:
diff changeset
1011 elsif Is_Class_Wide_Type (T2)
kono
parents:
diff changeset
1012 and then
kono
parents:
diff changeset
1013 (Class_Wide_Type (T1) = Class_Wide_Type (T2)
kono
parents:
diff changeset
1014 or else Base_Type (Root_Type (T2)) = BT1)
kono
parents:
diff changeset
1015 then
kono
parents:
diff changeset
1016 return True;
kono
parents:
diff changeset
1017
kono
parents:
diff changeset
1018 -- Some contexts require a class of types rather than a specific type.
kono
parents:
diff changeset
1019 -- For example, conditions require any boolean type, fixed point
kono
parents:
diff changeset
1020 -- attributes require some real type, etc. The built-in types Any_XXX
kono
parents:
diff changeset
1021 -- represent these classes.
kono
parents:
diff changeset
1022
kono
parents:
diff changeset
1023 elsif (T1 = Any_Integer and then Is_Integer_Type (T2))
kono
parents:
diff changeset
1024 or else (T1 = Any_Boolean and then Is_Boolean_Type (T2))
kono
parents:
diff changeset
1025 or else (T1 = Any_Real and then Is_Real_Type (T2))
kono
parents:
diff changeset
1026 or else (T1 = Any_Fixed and then Is_Fixed_Point_Type (T2))
kono
parents:
diff changeset
1027 or else (T1 = Any_Discrete and then Is_Discrete_Type (T2))
kono
parents:
diff changeset
1028 then
kono
parents:
diff changeset
1029 return True;
kono
parents:
diff changeset
1030
kono
parents:
diff changeset
1031 -- An aggregate is compatible with an array or record type
kono
parents:
diff changeset
1032
kono
parents:
diff changeset
1033 elsif T2 = Any_Composite and then Is_Aggregate_Type (T1) then
kono
parents:
diff changeset
1034 return True;
kono
parents:
diff changeset
1035
kono
parents:
diff changeset
1036 -- If the expected type is an anonymous access, the designated type must
kono
parents:
diff changeset
1037 -- cover that of the expression. Use the base type for this check: even
kono
parents:
diff changeset
1038 -- though access subtypes are rare in sources, they are generated for
kono
parents:
diff changeset
1039 -- actuals in instantiations.
kono
parents:
diff changeset
1040
kono
parents:
diff changeset
1041 elsif Ekind (BT1) = E_Anonymous_Access_Type
kono
parents:
diff changeset
1042 and then Is_Access_Type (T2)
kono
parents:
diff changeset
1043 and then Covers (Designated_Type (T1), Designated_Type (T2))
kono
parents:
diff changeset
1044 then
kono
parents:
diff changeset
1045 return True;
kono
parents:
diff changeset
1046
kono
parents:
diff changeset
1047 -- Ada 2012 (AI05-0149): Allow an anonymous access type in the context
kono
parents:
diff changeset
1048 -- of a named general access type. An implicit conversion will be
kono
parents:
diff changeset
1049 -- applied. For the resolution, one designated type must cover the
kono
parents:
diff changeset
1050 -- other.
kono
parents:
diff changeset
1051
kono
parents:
diff changeset
1052 elsif Ada_Version >= Ada_2012
kono
parents:
diff changeset
1053 and then Ekind (BT1) = E_General_Access_Type
kono
parents:
diff changeset
1054 and then Ekind (BT2) = E_Anonymous_Access_Type
kono
parents:
diff changeset
1055 and then (Covers (Designated_Type (T1), Designated_Type (T2))
kono
parents:
diff changeset
1056 or else
kono
parents:
diff changeset
1057 Covers (Designated_Type (T2), Designated_Type (T1)))
kono
parents:
diff changeset
1058 then
kono
parents:
diff changeset
1059 return True;
kono
parents:
diff changeset
1060
kono
parents:
diff changeset
1061 -- An Access_To_Subprogram is compatible with itself, or with an
kono
parents:
diff changeset
1062 -- anonymous type created for an attribute reference Access.
kono
parents:
diff changeset
1063
kono
parents:
diff changeset
1064 elsif Ekind_In (BT1, E_Access_Subprogram_Type,
kono
parents:
diff changeset
1065 E_Access_Protected_Subprogram_Type)
kono
parents:
diff changeset
1066 and then Is_Access_Type (T2)
kono
parents:
diff changeset
1067 and then (not Comes_From_Source (T1)
kono
parents:
diff changeset
1068 or else not Comes_From_Source (T2))
kono
parents:
diff changeset
1069 and then (Is_Overloadable (Designated_Type (T2))
kono
parents:
diff changeset
1070 or else Ekind (Designated_Type (T2)) = E_Subprogram_Type)
kono
parents:
diff changeset
1071 and then Type_Conformant (Designated_Type (T1), Designated_Type (T2))
kono
parents:
diff changeset
1072 and then Mode_Conformant (Designated_Type (T1), Designated_Type (T2))
kono
parents:
diff changeset
1073 then
kono
parents:
diff changeset
1074 return True;
kono
parents:
diff changeset
1075
kono
parents:
diff changeset
1076 -- Ada 2005 (AI-254): An Anonymous_Access_To_Subprogram is compatible
kono
parents:
diff changeset
1077 -- with itself, or with an anonymous type created for an attribute
kono
parents:
diff changeset
1078 -- reference Access.
kono
parents:
diff changeset
1079
kono
parents:
diff changeset
1080 elsif Ekind_In (BT1, E_Anonymous_Access_Subprogram_Type,
kono
parents:
diff changeset
1081 E_Anonymous_Access_Protected_Subprogram_Type)
kono
parents:
diff changeset
1082 and then Is_Access_Type (T2)
kono
parents:
diff changeset
1083 and then (not Comes_From_Source (T1)
kono
parents:
diff changeset
1084 or else not Comes_From_Source (T2))
kono
parents:
diff changeset
1085 and then (Is_Overloadable (Designated_Type (T2))
kono
parents:
diff changeset
1086 or else Ekind (Designated_Type (T2)) = E_Subprogram_Type)
kono
parents:
diff changeset
1087 and then Type_Conformant (Designated_Type (T1), Designated_Type (T2))
kono
parents:
diff changeset
1088 and then Mode_Conformant (Designated_Type (T1), Designated_Type (T2))
kono
parents:
diff changeset
1089 then
kono
parents:
diff changeset
1090 return True;
kono
parents:
diff changeset
1091
kono
parents:
diff changeset
1092 -- The context can be a remote access type, and the expression the
kono
parents:
diff changeset
1093 -- corresponding source type declared in a categorized package, or
kono
parents:
diff changeset
1094 -- vice versa.
kono
parents:
diff changeset
1095
kono
parents:
diff changeset
1096 elsif Is_Record_Type (T1)
kono
parents:
diff changeset
1097 and then (Is_Remote_Call_Interface (T1) or else Is_Remote_Types (T1))
kono
parents:
diff changeset
1098 and then Present (Corresponding_Remote_Type (T1))
kono
parents:
diff changeset
1099 then
kono
parents:
diff changeset
1100 return Covers (Corresponding_Remote_Type (T1), T2);
kono
parents:
diff changeset
1101
kono
parents:
diff changeset
1102 -- and conversely.
kono
parents:
diff changeset
1103
kono
parents:
diff changeset
1104 elsif Is_Record_Type (T2)
kono
parents:
diff changeset
1105 and then (Is_Remote_Call_Interface (T2) or else Is_Remote_Types (T2))
kono
parents:
diff changeset
1106 and then Present (Corresponding_Remote_Type (T2))
kono
parents:
diff changeset
1107 then
kono
parents:
diff changeset
1108 return Covers (Corresponding_Remote_Type (T2), T1);
kono
parents:
diff changeset
1109
kono
parents:
diff changeset
1110 -- Synchronized types are represented at run time by their corresponding
kono
parents:
diff changeset
1111 -- record type. During expansion one is replaced with the other, but
kono
parents:
diff changeset
1112 -- they are compatible views of the same type.
kono
parents:
diff changeset
1113
kono
parents:
diff changeset
1114 elsif Is_Record_Type (T1)
kono
parents:
diff changeset
1115 and then Is_Concurrent_Type (T2)
kono
parents:
diff changeset
1116 and then Present (Corresponding_Record_Type (T2))
kono
parents:
diff changeset
1117 then
kono
parents:
diff changeset
1118 return Covers (T1, Corresponding_Record_Type (T2));
kono
parents:
diff changeset
1119
kono
parents:
diff changeset
1120 elsif Is_Concurrent_Type (T1)
kono
parents:
diff changeset
1121 and then Present (Corresponding_Record_Type (T1))
kono
parents:
diff changeset
1122 and then Is_Record_Type (T2)
kono
parents:
diff changeset
1123 then
kono
parents:
diff changeset
1124 return Covers (Corresponding_Record_Type (T1), T2);
kono
parents:
diff changeset
1125
kono
parents:
diff changeset
1126 -- During analysis, an attribute reference 'Access has a special type
kono
parents:
diff changeset
1127 -- kind: Access_Attribute_Type, to be replaced eventually with the type
kono
parents:
diff changeset
1128 -- imposed by context.
kono
parents:
diff changeset
1129
kono
parents:
diff changeset
1130 elsif Ekind (T2) = E_Access_Attribute_Type
kono
parents:
diff changeset
1131 and then Ekind_In (BT1, E_General_Access_Type, E_Access_Type)
kono
parents:
diff changeset
1132 and then Covers (Designated_Type (T1), Designated_Type (T2))
kono
parents:
diff changeset
1133 then
kono
parents:
diff changeset
1134 -- If the target type is a RACW type while the source is an access
kono
parents:
diff changeset
1135 -- attribute type, we are building a RACW that may be exported.
kono
parents:
diff changeset
1136
kono
parents:
diff changeset
1137 if Is_Remote_Access_To_Class_Wide_Type (BT1) then
kono
parents:
diff changeset
1138 Set_Has_RACW (Current_Sem_Unit);
kono
parents:
diff changeset
1139 end if;
kono
parents:
diff changeset
1140
kono
parents:
diff changeset
1141 return True;
kono
parents:
diff changeset
1142
kono
parents:
diff changeset
1143 -- Ditto for allocators, which eventually resolve to the context type
kono
parents:
diff changeset
1144
kono
parents:
diff changeset
1145 elsif Ekind (T2) = E_Allocator_Type and then Is_Access_Type (T1) then
kono
parents:
diff changeset
1146 return Covers (Designated_Type (T1), Designated_Type (T2))
kono
parents:
diff changeset
1147 or else
kono
parents:
diff changeset
1148 (From_Limited_With (Designated_Type (T1))
kono
parents:
diff changeset
1149 and then Covers (Designated_Type (T2), Designated_Type (T1)));
kono
parents:
diff changeset
1150
kono
parents:
diff changeset
1151 -- A boolean operation on integer literals is compatible with modular
kono
parents:
diff changeset
1152 -- context.
kono
parents:
diff changeset
1153
kono
parents:
diff changeset
1154 elsif T2 = Any_Modular and then Is_Modular_Integer_Type (T1) then
kono
parents:
diff changeset
1155 return True;
kono
parents:
diff changeset
1156
kono
parents:
diff changeset
1157 -- The actual type may be the result of a previous error
kono
parents:
diff changeset
1158
kono
parents:
diff changeset
1159 elsif BT2 = Any_Type then
kono
parents:
diff changeset
1160 return True;
kono
parents:
diff changeset
1161
kono
parents:
diff changeset
1162 -- A Raise_Expressions is legal in any expression context
kono
parents:
diff changeset
1163
kono
parents:
diff changeset
1164 elsif BT2 = Raise_Type then
kono
parents:
diff changeset
1165 return True;
kono
parents:
diff changeset
1166
kono
parents:
diff changeset
1167 -- A packed array type covers its corresponding non-packed type. This is
kono
parents:
diff changeset
1168 -- not legitimate Ada, but allows the omission of a number of otherwise
kono
parents:
diff changeset
1169 -- useless unchecked conversions, and since this can only arise in
kono
parents:
diff changeset
1170 -- (known correct) expanded code, no harm is done.
kono
parents:
diff changeset
1171
kono
parents:
diff changeset
1172 elsif Is_Array_Type (T2)
kono
parents:
diff changeset
1173 and then Is_Packed (T2)
kono
parents:
diff changeset
1174 and then T1 = Packed_Array_Impl_Type (T2)
kono
parents:
diff changeset
1175 then
kono
parents:
diff changeset
1176 return True;
kono
parents:
diff changeset
1177
kono
parents:
diff changeset
1178 -- Similarly an array type covers its corresponding packed array type
kono
parents:
diff changeset
1179
kono
parents:
diff changeset
1180 elsif Is_Array_Type (T1)
kono
parents:
diff changeset
1181 and then Is_Packed (T1)
kono
parents:
diff changeset
1182 and then T2 = Packed_Array_Impl_Type (T1)
kono
parents:
diff changeset
1183 then
kono
parents:
diff changeset
1184 return True;
kono
parents:
diff changeset
1185
kono
parents:
diff changeset
1186 -- In instances, or with types exported from instantiations, check
kono
parents:
diff changeset
1187 -- whether a partial and a full view match. Verify that types are
kono
parents:
diff changeset
1188 -- legal, to prevent cascaded errors.
kono
parents:
diff changeset
1189
kono
parents:
diff changeset
1190 elsif Is_Private_Type (T1)
kono
parents:
diff changeset
1191 and then (In_Instance
kono
parents:
diff changeset
1192 or else (Is_Type (T2) and then Is_Generic_Actual_Type (T2)))
kono
parents:
diff changeset
1193 and then Full_View_Covers (T1, T2)
kono
parents:
diff changeset
1194 then
kono
parents:
diff changeset
1195 return True;
kono
parents:
diff changeset
1196
kono
parents:
diff changeset
1197 elsif Is_Private_Type (T2)
kono
parents:
diff changeset
1198 and then (In_Instance
kono
parents:
diff changeset
1199 or else (Is_Type (T1) and then Is_Generic_Actual_Type (T1)))
kono
parents:
diff changeset
1200 and then Full_View_Covers (T2, T1)
kono
parents:
diff changeset
1201 then
kono
parents:
diff changeset
1202 return True;
kono
parents:
diff changeset
1203
kono
parents:
diff changeset
1204 -- In the expansion of inlined bodies, types are compatible if they
kono
parents:
diff changeset
1205 -- are structurally equivalent.
kono
parents:
diff changeset
1206
kono
parents:
diff changeset
1207 elsif In_Inlined_Body
kono
parents:
diff changeset
1208 and then (Underlying_Type (T1) = Underlying_Type (T2)
kono
parents:
diff changeset
1209 or else
kono
parents:
diff changeset
1210 (Is_Access_Type (T1)
kono
parents:
diff changeset
1211 and then Is_Access_Type (T2)
kono
parents:
diff changeset
1212 and then Designated_Type (T1) = Designated_Type (T2))
kono
parents:
diff changeset
1213 or else
kono
parents:
diff changeset
1214 (T1 = Any_Access
kono
parents:
diff changeset
1215 and then Is_Access_Type (Underlying_Type (T2)))
kono
parents:
diff changeset
1216 or else
kono
parents:
diff changeset
1217 (T2 = Any_Composite
kono
parents:
diff changeset
1218 and then Is_Composite_Type (Underlying_Type (T1))))
kono
parents:
diff changeset
1219 then
kono
parents:
diff changeset
1220 return True;
kono
parents:
diff changeset
1221
kono
parents:
diff changeset
1222 -- Ada 2005 (AI-50217): Additional branches to make the shadow entity
kono
parents:
diff changeset
1223 -- obtained through a limited_with compatible with its real entity.
kono
parents:
diff changeset
1224
kono
parents:
diff changeset
1225 elsif From_Limited_With (T1) then
kono
parents:
diff changeset
1226
kono
parents:
diff changeset
1227 -- If the expected type is the nonlimited view of a type, the
kono
parents:
diff changeset
1228 -- expression may have the limited view. If that one in turn is
kono
parents:
diff changeset
1229 -- incomplete, get full view if available.
kono
parents:
diff changeset
1230
kono
parents:
diff changeset
1231 return Has_Non_Limited_View (T1)
kono
parents:
diff changeset
1232 and then Covers (Get_Full_View (Non_Limited_View (T1)), T2);
kono
parents:
diff changeset
1233
kono
parents:
diff changeset
1234 elsif From_Limited_With (T2) then
kono
parents:
diff changeset
1235
kono
parents:
diff changeset
1236 -- If units in the context have Limited_With clauses on each other,
kono
parents:
diff changeset
1237 -- either type might have a limited view. Checks performed elsewhere
kono
parents:
diff changeset
1238 -- verify that the context type is the nonlimited view.
kono
parents:
diff changeset
1239
kono
parents:
diff changeset
1240 return Has_Non_Limited_View (T2)
kono
parents:
diff changeset
1241 and then Covers (T1, Get_Full_View (Non_Limited_View (T2)));
kono
parents:
diff changeset
1242
kono
parents:
diff changeset
1243 -- Ada 2005 (AI-412): Coverage for regular incomplete subtypes
kono
parents:
diff changeset
1244
kono
parents:
diff changeset
1245 elsif Ekind (T1) = E_Incomplete_Subtype then
kono
parents:
diff changeset
1246 return Covers (Full_View (Etype (T1)), T2);
kono
parents:
diff changeset
1247
kono
parents:
diff changeset
1248 elsif Ekind (T2) = E_Incomplete_Subtype then
kono
parents:
diff changeset
1249 return Covers (T1, Full_View (Etype (T2)));
kono
parents:
diff changeset
1250
kono
parents:
diff changeset
1251 -- Ada 2005 (AI-423): Coverage of formal anonymous access types
kono
parents:
diff changeset
1252 -- and actual anonymous access types in the context of generic
kono
parents:
diff changeset
1253 -- instantiations. We have the following situation:
kono
parents:
diff changeset
1254
kono
parents:
diff changeset
1255 -- generic
kono
parents:
diff changeset
1256 -- type Formal is private;
kono
parents:
diff changeset
1257 -- Formal_Obj : access Formal; -- T1
kono
parents:
diff changeset
1258 -- package G is ...
kono
parents:
diff changeset
1259
kono
parents:
diff changeset
1260 -- package P is
kono
parents:
diff changeset
1261 -- type Actual is ...
kono
parents:
diff changeset
1262 -- Actual_Obj : access Actual; -- T2
kono
parents:
diff changeset
1263 -- package Instance is new G (Formal => Actual,
kono
parents:
diff changeset
1264 -- Formal_Obj => Actual_Obj);
kono
parents:
diff changeset
1265
kono
parents:
diff changeset
1266 elsif Ada_Version >= Ada_2005
kono
parents:
diff changeset
1267 and then Ekind (T1) = E_Anonymous_Access_Type
kono
parents:
diff changeset
1268 and then Ekind (T2) = E_Anonymous_Access_Type
kono
parents:
diff changeset
1269 and then Is_Generic_Type (Directly_Designated_Type (T1))
kono
parents:
diff changeset
1270 and then Get_Instance_Of (Directly_Designated_Type (T1)) =
kono
parents:
diff changeset
1271 Directly_Designated_Type (T2)
kono
parents:
diff changeset
1272 then
kono
parents:
diff changeset
1273 return True;
kono
parents:
diff changeset
1274
kono
parents:
diff changeset
1275 -- Otherwise, types are not compatible
kono
parents:
diff changeset
1276
kono
parents:
diff changeset
1277 else
kono
parents:
diff changeset
1278 return False;
kono
parents:
diff changeset
1279 end if;
kono
parents:
diff changeset
1280 end Covers;
kono
parents:
diff changeset
1281
kono
parents:
diff changeset
1282 ------------------
kono
parents:
diff changeset
1283 -- Disambiguate --
kono
parents:
diff changeset
1284 ------------------
kono
parents:
diff changeset
1285
kono
parents:
diff changeset
1286 function Disambiguate
kono
parents:
diff changeset
1287 (N : Node_Id;
kono
parents:
diff changeset
1288 I1, I2 : Interp_Index;
kono
parents:
diff changeset
1289 Typ : Entity_Id) return Interp
kono
parents:
diff changeset
1290 is
kono
parents:
diff changeset
1291 I : Interp_Index;
kono
parents:
diff changeset
1292 It : Interp;
kono
parents:
diff changeset
1293 It1, It2 : Interp;
kono
parents:
diff changeset
1294 Nam1, Nam2 : Entity_Id;
kono
parents:
diff changeset
1295 Predef_Subp : Entity_Id;
kono
parents:
diff changeset
1296 User_Subp : Entity_Id;
kono
parents:
diff changeset
1297
kono
parents:
diff changeset
1298 function Inherited_From_Actual (S : Entity_Id) return Boolean;
kono
parents:
diff changeset
1299 -- Determine whether one of the candidates is an operation inherited by
kono
parents:
diff changeset
1300 -- a type that is derived from an actual in an instantiation.
kono
parents:
diff changeset
1301
kono
parents:
diff changeset
1302 function In_Same_Declaration_List
kono
parents:
diff changeset
1303 (Typ : Entity_Id;
kono
parents:
diff changeset
1304 Op_Decl : Entity_Id) return Boolean;
kono
parents:
diff changeset
1305 -- AI05-0020: a spurious ambiguity may arise when equality on anonymous
kono
parents:
diff changeset
1306 -- access types is declared on the partial view of a designated type, so
kono
parents:
diff changeset
1307 -- that the type declaration and equality are not in the same list of
kono
parents:
diff changeset
1308 -- declarations. This AI gives a preference rule for the user-defined
kono
parents:
diff changeset
1309 -- operation. Same rule applies for arithmetic operations on private
kono
parents:
diff changeset
1310 -- types completed with fixed-point types: the predefined operation is
kono
parents:
diff changeset
1311 -- hidden; this is already handled properly in GNAT.
kono
parents:
diff changeset
1312
kono
parents:
diff changeset
1313 function Is_Actual_Subprogram (S : Entity_Id) return Boolean;
kono
parents:
diff changeset
1314 -- Determine whether a subprogram is an actual in an enclosing instance.
kono
parents:
diff changeset
1315 -- An overloading between such a subprogram and one declared outside the
kono
parents:
diff changeset
1316 -- instance is resolved in favor of the first, because it resolved in
kono
parents:
diff changeset
1317 -- the generic. Within the instance the actual is represented by a
kono
parents:
diff changeset
1318 -- constructed subprogram renaming.
kono
parents:
diff changeset
1319
kono
parents:
diff changeset
1320 function Matches (Op : Node_Id; Func_Id : Entity_Id) return Boolean;
kono
parents:
diff changeset
1321 -- Determine whether function Func_Id is an exact match for binary or
kono
parents:
diff changeset
1322 -- unary operator Op.
kono
parents:
diff changeset
1323
kono
parents:
diff changeset
1324 function Operand_Type return Entity_Id;
kono
parents:
diff changeset
1325 -- Determine type of operand for an equality operation, to apply Ada
kono
parents:
diff changeset
1326 -- 2005 rules to equality on anonymous access types.
kono
parents:
diff changeset
1327
kono
parents:
diff changeset
1328 function Standard_Operator return Boolean;
kono
parents:
diff changeset
1329 -- Check whether subprogram is predefined operator declared in Standard.
kono
parents:
diff changeset
1330 -- It may given by an operator name, or by an expanded name whose prefix
kono
parents:
diff changeset
1331 -- is Standard.
kono
parents:
diff changeset
1332
kono
parents:
diff changeset
1333 function Remove_Conversions return Interp;
kono
parents:
diff changeset
1334 -- Last chance for pathological cases involving comparisons on literals,
kono
parents:
diff changeset
1335 -- and user overloadings of the same operator. Such pathologies have
kono
parents:
diff changeset
1336 -- been removed from the ACVC, but still appear in two DEC tests, with
kono
parents:
diff changeset
1337 -- the following notable quote from Ben Brosgol:
kono
parents:
diff changeset
1338 --
kono
parents:
diff changeset
1339 -- [Note: I disclaim all credit/responsibility/blame for coming up with
kono
parents:
diff changeset
1340 -- this example; Robert Dewar brought it to our attention, since it is
kono
parents:
diff changeset
1341 -- apparently found in the ACVC 1.5. I did not attempt to find the
kono
parents:
diff changeset
1342 -- reason in the Reference Manual that makes the example legal, since I
kono
parents:
diff changeset
1343 -- was too nauseated by it to want to pursue it further.]
kono
parents:
diff changeset
1344 --
kono
parents:
diff changeset
1345 -- Accordingly, this is not a fully recursive solution, but it handles
kono
parents:
diff changeset
1346 -- DEC tests c460vsa, c460vsb. It also handles ai00136a, which pushes
kono
parents:
diff changeset
1347 -- pathology in the other direction with calls whose multiple overloaded
kono
parents:
diff changeset
1348 -- actuals make them truly unresolvable.
kono
parents:
diff changeset
1349
kono
parents:
diff changeset
1350 -- The new rules concerning abstract operations create additional need
kono
parents:
diff changeset
1351 -- for special handling of expressions with universal operands, see
kono
parents:
diff changeset
1352 -- comments to Has_Abstract_Interpretation below.
kono
parents:
diff changeset
1353
kono
parents:
diff changeset
1354 ---------------------------
kono
parents:
diff changeset
1355 -- Inherited_From_Actual --
kono
parents:
diff changeset
1356 ---------------------------
kono
parents:
diff changeset
1357
kono
parents:
diff changeset
1358 function Inherited_From_Actual (S : Entity_Id) return Boolean is
kono
parents:
diff changeset
1359 Par : constant Node_Id := Parent (S);
kono
parents:
diff changeset
1360 begin
kono
parents:
diff changeset
1361 if Nkind (Par) /= N_Full_Type_Declaration
kono
parents:
diff changeset
1362 or else Nkind (Type_Definition (Par)) /= N_Derived_Type_Definition
kono
parents:
diff changeset
1363 then
kono
parents:
diff changeset
1364 return False;
kono
parents:
diff changeset
1365 else
kono
parents:
diff changeset
1366 return Is_Entity_Name (Subtype_Indication (Type_Definition (Par)))
kono
parents:
diff changeset
1367 and then
kono
parents:
diff changeset
1368 Is_Generic_Actual_Type (
kono
parents:
diff changeset
1369 Entity (Subtype_Indication (Type_Definition (Par))));
kono
parents:
diff changeset
1370 end if;
kono
parents:
diff changeset
1371 end Inherited_From_Actual;
kono
parents:
diff changeset
1372
kono
parents:
diff changeset
1373 ------------------------------
kono
parents:
diff changeset
1374 -- In_Same_Declaration_List --
kono
parents:
diff changeset
1375 ------------------------------
kono
parents:
diff changeset
1376
kono
parents:
diff changeset
1377 function In_Same_Declaration_List
kono
parents:
diff changeset
1378 (Typ : Entity_Id;
kono
parents:
diff changeset
1379 Op_Decl : Entity_Id) return Boolean
kono
parents:
diff changeset
1380 is
kono
parents:
diff changeset
1381 Scop : constant Entity_Id := Scope (Typ);
kono
parents:
diff changeset
1382
kono
parents:
diff changeset
1383 begin
kono
parents:
diff changeset
1384 return In_Same_List (Parent (Typ), Op_Decl)
kono
parents:
diff changeset
1385 or else
kono
parents:
diff changeset
1386 (Ekind_In (Scop, E_Package, E_Generic_Package)
kono
parents:
diff changeset
1387 and then List_Containing (Op_Decl) =
kono
parents:
diff changeset
1388 Visible_Declarations (Parent (Scop))
kono
parents:
diff changeset
1389 and then List_Containing (Parent (Typ)) =
kono
parents:
diff changeset
1390 Private_Declarations (Parent (Scop)));
kono
parents:
diff changeset
1391 end In_Same_Declaration_List;
kono
parents:
diff changeset
1392
kono
parents:
diff changeset
1393 --------------------------
kono
parents:
diff changeset
1394 -- Is_Actual_Subprogram --
kono
parents:
diff changeset
1395 --------------------------
kono
parents:
diff changeset
1396
kono
parents:
diff changeset
1397 function Is_Actual_Subprogram (S : Entity_Id) return Boolean is
kono
parents:
diff changeset
1398 begin
kono
parents:
diff changeset
1399 return In_Open_Scopes (Scope (S))
kono
parents:
diff changeset
1400 and then Nkind (Unit_Declaration_Node (S)) =
kono
parents:
diff changeset
1401 N_Subprogram_Renaming_Declaration
kono
parents:
diff changeset
1402
kono
parents:
diff changeset
1403 -- Why the Comes_From_Source test here???
kono
parents:
diff changeset
1404
kono
parents:
diff changeset
1405 and then not Comes_From_Source (Unit_Declaration_Node (S))
kono
parents:
diff changeset
1406
kono
parents:
diff changeset
1407 and then
kono
parents:
diff changeset
1408 (Is_Generic_Instance (Scope (S))
kono
parents:
diff changeset
1409 or else Is_Wrapper_Package (Scope (S)));
kono
parents:
diff changeset
1410 end Is_Actual_Subprogram;
kono
parents:
diff changeset
1411
kono
parents:
diff changeset
1412 -------------
kono
parents:
diff changeset
1413 -- Matches --
kono
parents:
diff changeset
1414 -------------
kono
parents:
diff changeset
1415
kono
parents:
diff changeset
1416 function Matches (Op : Node_Id; Func_Id : Entity_Id) return Boolean is
kono
parents:
diff changeset
1417 function Matching_Types
kono
parents:
diff changeset
1418 (Opnd_Typ : Entity_Id;
kono
parents:
diff changeset
1419 Formal_Typ : Entity_Id) return Boolean;
kono
parents:
diff changeset
1420 -- Determine whether operand type Opnd_Typ and formal parameter type
kono
parents:
diff changeset
1421 -- Formal_Typ are either the same or compatible.
kono
parents:
diff changeset
1422
kono
parents:
diff changeset
1423 --------------------
kono
parents:
diff changeset
1424 -- Matching_Types --
kono
parents:
diff changeset
1425 --------------------
kono
parents:
diff changeset
1426
kono
parents:
diff changeset
1427 function Matching_Types
kono
parents:
diff changeset
1428 (Opnd_Typ : Entity_Id;
kono
parents:
diff changeset
1429 Formal_Typ : Entity_Id) return Boolean
kono
parents:
diff changeset
1430 is
kono
parents:
diff changeset
1431 begin
kono
parents:
diff changeset
1432 -- A direct match
kono
parents:
diff changeset
1433
kono
parents:
diff changeset
1434 if Opnd_Typ = Formal_Typ then
kono
parents:
diff changeset
1435 return True;
kono
parents:
diff changeset
1436
kono
parents:
diff changeset
1437 -- Any integer type matches universal integer
kono
parents:
diff changeset
1438
kono
parents:
diff changeset
1439 elsif Opnd_Typ = Universal_Integer
kono
parents:
diff changeset
1440 and then Is_Integer_Type (Formal_Typ)
kono
parents:
diff changeset
1441 then
kono
parents:
diff changeset
1442 return True;
kono
parents:
diff changeset
1443
kono
parents:
diff changeset
1444 -- Any floating point type matches universal real
kono
parents:
diff changeset
1445
kono
parents:
diff changeset
1446 elsif Opnd_Typ = Universal_Real
kono
parents:
diff changeset
1447 and then Is_Floating_Point_Type (Formal_Typ)
kono
parents:
diff changeset
1448 then
kono
parents:
diff changeset
1449 return True;
kono
parents:
diff changeset
1450
kono
parents:
diff changeset
1451 -- The type of the formal parameter maps a generic actual type to
kono
parents:
diff changeset
1452 -- a generic formal type. If the operand type is the type being
kono
parents:
diff changeset
1453 -- mapped in an instance, then this is a match.
kono
parents:
diff changeset
1454
kono
parents:
diff changeset
1455 elsif Is_Generic_Actual_Type (Formal_Typ)
kono
parents:
diff changeset
1456 and then Etype (Formal_Typ) = Opnd_Typ
kono
parents:
diff changeset
1457 then
kono
parents:
diff changeset
1458 return True;
kono
parents:
diff changeset
1459
kono
parents:
diff changeset
1460 -- ??? There are possibly other cases to consider
kono
parents:
diff changeset
1461
kono
parents:
diff changeset
1462 else
kono
parents:
diff changeset
1463 return False;
kono
parents:
diff changeset
1464 end if;
kono
parents:
diff changeset
1465 end Matching_Types;
kono
parents:
diff changeset
1466
kono
parents:
diff changeset
1467 -- Local variables
kono
parents:
diff changeset
1468
kono
parents:
diff changeset
1469 F1 : constant Entity_Id := First_Formal (Func_Id);
kono
parents:
diff changeset
1470 F1_Typ : constant Entity_Id := Etype (F1);
kono
parents:
diff changeset
1471 F2 : constant Entity_Id := Next_Formal (F1);
kono
parents:
diff changeset
1472 F2_Typ : constant Entity_Id := Etype (F2);
kono
parents:
diff changeset
1473 Lop_Typ : constant Entity_Id := Etype (Left_Opnd (Op));
kono
parents:
diff changeset
1474 Rop_Typ : constant Entity_Id := Etype (Right_Opnd (Op));
kono
parents:
diff changeset
1475
kono
parents:
diff changeset
1476 -- Start of processing for Matches
kono
parents:
diff changeset
1477
kono
parents:
diff changeset
1478 begin
kono
parents:
diff changeset
1479 if Lop_Typ = F1_Typ then
kono
parents:
diff changeset
1480 return Matching_Types (Rop_Typ, F2_Typ);
kono
parents:
diff changeset
1481
kono
parents:
diff changeset
1482 elsif Rop_Typ = F2_Typ then
kono
parents:
diff changeset
1483 return Matching_Types (Lop_Typ, F1_Typ);
kono
parents:
diff changeset
1484
kono
parents:
diff changeset
1485 -- Otherwise this is not a good match because each operand-formal
kono
parents:
diff changeset
1486 -- pair is compatible only on base-type basis, which is not specific
kono
parents:
diff changeset
1487 -- enough.
kono
parents:
diff changeset
1488
kono
parents:
diff changeset
1489 else
kono
parents:
diff changeset
1490 return False;
kono
parents:
diff changeset
1491 end if;
kono
parents:
diff changeset
1492 end Matches;
kono
parents:
diff changeset
1493
kono
parents:
diff changeset
1494 ------------------
kono
parents:
diff changeset
1495 -- Operand_Type --
kono
parents:
diff changeset
1496 ------------------
kono
parents:
diff changeset
1497
kono
parents:
diff changeset
1498 function Operand_Type return Entity_Id is
kono
parents:
diff changeset
1499 Opnd : Node_Id;
kono
parents:
diff changeset
1500
kono
parents:
diff changeset
1501 begin
kono
parents:
diff changeset
1502 if Nkind (N) = N_Function_Call then
kono
parents:
diff changeset
1503 Opnd := First_Actual (N);
kono
parents:
diff changeset
1504 else
kono
parents:
diff changeset
1505 Opnd := Left_Opnd (N);
kono
parents:
diff changeset
1506 end if;
kono
parents:
diff changeset
1507
kono
parents:
diff changeset
1508 return Etype (Opnd);
kono
parents:
diff changeset
1509 end Operand_Type;
kono
parents:
diff changeset
1510
kono
parents:
diff changeset
1511 ------------------------
kono
parents:
diff changeset
1512 -- Remove_Conversions --
kono
parents:
diff changeset
1513 ------------------------
kono
parents:
diff changeset
1514
kono
parents:
diff changeset
1515 function Remove_Conversions return Interp is
kono
parents:
diff changeset
1516 I : Interp_Index;
kono
parents:
diff changeset
1517 It : Interp;
kono
parents:
diff changeset
1518 It1 : Interp;
kono
parents:
diff changeset
1519 F1 : Entity_Id;
kono
parents:
diff changeset
1520 Act1 : Node_Id;
kono
parents:
diff changeset
1521 Act2 : Node_Id;
kono
parents:
diff changeset
1522
kono
parents:
diff changeset
1523 function Has_Abstract_Interpretation (N : Node_Id) return Boolean;
kono
parents:
diff changeset
1524 -- If an operation has universal operands the universal operation
kono
parents:
diff changeset
1525 -- is present among its interpretations. If there is an abstract
kono
parents:
diff changeset
1526 -- interpretation for the operator, with a numeric result, this
kono
parents:
diff changeset
1527 -- interpretation was already removed in sem_ch4, but the universal
kono
parents:
diff changeset
1528 -- one is still visible. We must rescan the list of operators and
kono
parents:
diff changeset
1529 -- remove the universal interpretation to resolve the ambiguity.
kono
parents:
diff changeset
1530
kono
parents:
diff changeset
1531 ---------------------------------
kono
parents:
diff changeset
1532 -- Has_Abstract_Interpretation --
kono
parents:
diff changeset
1533 ---------------------------------
kono
parents:
diff changeset
1534
kono
parents:
diff changeset
1535 function Has_Abstract_Interpretation (N : Node_Id) return Boolean is
kono
parents:
diff changeset
1536 E : Entity_Id;
kono
parents:
diff changeset
1537
kono
parents:
diff changeset
1538 begin
kono
parents:
diff changeset
1539 if Nkind (N) not in N_Op
kono
parents:
diff changeset
1540 or else Ada_Version < Ada_2005
kono
parents:
diff changeset
1541 or else not Is_Overloaded (N)
kono
parents:
diff changeset
1542 or else No (Universal_Interpretation (N))
kono
parents:
diff changeset
1543 then
kono
parents:
diff changeset
1544 return False;
kono
parents:
diff changeset
1545
kono
parents:
diff changeset
1546 else
kono
parents:
diff changeset
1547 E := Get_Name_Entity_Id (Chars (N));
kono
parents:
diff changeset
1548 while Present (E) loop
kono
parents:
diff changeset
1549 if Is_Overloadable (E)
kono
parents:
diff changeset
1550 and then Is_Abstract_Subprogram (E)
kono
parents:
diff changeset
1551 and then Is_Numeric_Type (Etype (E))
kono
parents:
diff changeset
1552 then
kono
parents:
diff changeset
1553 return True;
kono
parents:
diff changeset
1554 else
kono
parents:
diff changeset
1555 E := Homonym (E);
kono
parents:
diff changeset
1556 end if;
kono
parents:
diff changeset
1557 end loop;
kono
parents:
diff changeset
1558
kono
parents:
diff changeset
1559 -- Finally, if an operand of the binary operator is itself
kono
parents:
diff changeset
1560 -- an operator, recurse to see whether its own abstract
kono
parents:
diff changeset
1561 -- interpretation is responsible for the spurious ambiguity.
kono
parents:
diff changeset
1562
kono
parents:
diff changeset
1563 if Nkind (N) in N_Binary_Op then
kono
parents:
diff changeset
1564 return Has_Abstract_Interpretation (Left_Opnd (N))
kono
parents:
diff changeset
1565 or else Has_Abstract_Interpretation (Right_Opnd (N));
kono
parents:
diff changeset
1566
kono
parents:
diff changeset
1567 elsif Nkind (N) in N_Unary_Op then
kono
parents:
diff changeset
1568 return Has_Abstract_Interpretation (Right_Opnd (N));
kono
parents:
diff changeset
1569
kono
parents:
diff changeset
1570 else
kono
parents:
diff changeset
1571 return False;
kono
parents:
diff changeset
1572 end if;
kono
parents:
diff changeset
1573 end if;
kono
parents:
diff changeset
1574 end Has_Abstract_Interpretation;
kono
parents:
diff changeset
1575
kono
parents:
diff changeset
1576 -- Start of processing for Remove_Conversions
kono
parents:
diff changeset
1577
kono
parents:
diff changeset
1578 begin
kono
parents:
diff changeset
1579 It1 := No_Interp;
kono
parents:
diff changeset
1580
kono
parents:
diff changeset
1581 Get_First_Interp (N, I, It);
kono
parents:
diff changeset
1582 while Present (It.Typ) loop
kono
parents:
diff changeset
1583 if not Is_Overloadable (It.Nam) then
kono
parents:
diff changeset
1584 return No_Interp;
kono
parents:
diff changeset
1585 end if;
kono
parents:
diff changeset
1586
kono
parents:
diff changeset
1587 F1 := First_Formal (It.Nam);
kono
parents:
diff changeset
1588
kono
parents:
diff changeset
1589 if No (F1) then
kono
parents:
diff changeset
1590 return It1;
kono
parents:
diff changeset
1591
kono
parents:
diff changeset
1592 else
kono
parents:
diff changeset
1593 if Nkind (N) in N_Subprogram_Call then
kono
parents:
diff changeset
1594 Act1 := First_Actual (N);
kono
parents:
diff changeset
1595
kono
parents:
diff changeset
1596 if Present (Act1) then
kono
parents:
diff changeset
1597 Act2 := Next_Actual (Act1);
kono
parents:
diff changeset
1598 else
kono
parents:
diff changeset
1599 Act2 := Empty;
kono
parents:
diff changeset
1600 end if;
kono
parents:
diff changeset
1601
kono
parents:
diff changeset
1602 elsif Nkind (N) in N_Unary_Op then
kono
parents:
diff changeset
1603 Act1 := Right_Opnd (N);
kono
parents:
diff changeset
1604 Act2 := Empty;
kono
parents:
diff changeset
1605
kono
parents:
diff changeset
1606 elsif Nkind (N) in N_Binary_Op then
kono
parents:
diff changeset
1607 Act1 := Left_Opnd (N);
kono
parents:
diff changeset
1608 Act2 := Right_Opnd (N);
kono
parents:
diff changeset
1609
kono
parents:
diff changeset
1610 -- Use the type of the second formal, so as to include
kono
parents:
diff changeset
1611 -- exponentiation, where the exponent may be ambiguous and
kono
parents:
diff changeset
1612 -- the result non-universal.
kono
parents:
diff changeset
1613
kono
parents:
diff changeset
1614 Next_Formal (F1);
kono
parents:
diff changeset
1615
kono
parents:
diff changeset
1616 else
kono
parents:
diff changeset
1617 return It1;
kono
parents:
diff changeset
1618 end if;
kono
parents:
diff changeset
1619
kono
parents:
diff changeset
1620 if Nkind (Act1) in N_Op
kono
parents:
diff changeset
1621 and then Is_Overloaded (Act1)
kono
parents:
diff changeset
1622 and then
kono
parents:
diff changeset
1623 (Nkind (Act1) in N_Unary_Op
kono
parents:
diff changeset
1624 or else Nkind_In (Left_Opnd (Act1), N_Integer_Literal,
kono
parents:
diff changeset
1625 N_Real_Literal))
kono
parents:
diff changeset
1626 and then Nkind_In (Right_Opnd (Act1), N_Integer_Literal,
kono
parents:
diff changeset
1627 N_Real_Literal)
kono
parents:
diff changeset
1628 and then Has_Compatible_Type (Act1, Standard_Boolean)
kono
parents:
diff changeset
1629 and then Etype (F1) = Standard_Boolean
kono
parents:
diff changeset
1630 then
kono
parents:
diff changeset
1631 -- If the two candidates are the original ones, the
kono
parents:
diff changeset
1632 -- ambiguity is real. Otherwise keep the original, further
kono
parents:
diff changeset
1633 -- calls to Disambiguate will take care of others in the
kono
parents:
diff changeset
1634 -- list of candidates.
kono
parents:
diff changeset
1635
kono
parents:
diff changeset
1636 if It1 /= No_Interp then
kono
parents:
diff changeset
1637 if It = Disambiguate.It1
kono
parents:
diff changeset
1638 or else It = Disambiguate.It2
kono
parents:
diff changeset
1639 then
kono
parents:
diff changeset
1640 if It1 = Disambiguate.It1
kono
parents:
diff changeset
1641 or else It1 = Disambiguate.It2
kono
parents:
diff changeset
1642 then
kono
parents:
diff changeset
1643 return No_Interp;
kono
parents:
diff changeset
1644 else
kono
parents:
diff changeset
1645 It1 := It;
kono
parents:
diff changeset
1646 end if;
kono
parents:
diff changeset
1647 end if;
kono
parents:
diff changeset
1648
kono
parents:
diff changeset
1649 elsif Present (Act2)
kono
parents:
diff changeset
1650 and then Nkind (Act2) in N_Op
kono
parents:
diff changeset
1651 and then Is_Overloaded (Act2)
kono
parents:
diff changeset
1652 and then Nkind_In (Right_Opnd (Act2), N_Integer_Literal,
kono
parents:
diff changeset
1653 N_Real_Literal)
kono
parents:
diff changeset
1654 and then Has_Compatible_Type (Act2, Standard_Boolean)
kono
parents:
diff changeset
1655 then
kono
parents:
diff changeset
1656 -- The preference rule on the first actual is not
kono
parents:
diff changeset
1657 -- sufficient to disambiguate.
kono
parents:
diff changeset
1658
kono
parents:
diff changeset
1659 goto Next_Interp;
kono
parents:
diff changeset
1660
kono
parents:
diff changeset
1661 else
kono
parents:
diff changeset
1662 It1 := It;
kono
parents:
diff changeset
1663 end if;
kono
parents:
diff changeset
1664
kono
parents:
diff changeset
1665 elsif Is_Numeric_Type (Etype (F1))
kono
parents:
diff changeset
1666 and then Has_Abstract_Interpretation (Act1)
kono
parents:
diff changeset
1667 then
kono
parents:
diff changeset
1668 -- Current interpretation is not the right one because it
kono
parents:
diff changeset
1669 -- expects a numeric operand. Examine all the other ones.
kono
parents:
diff changeset
1670
kono
parents:
diff changeset
1671 declare
kono
parents:
diff changeset
1672 I : Interp_Index;
kono
parents:
diff changeset
1673 It : Interp;
kono
parents:
diff changeset
1674
kono
parents:
diff changeset
1675 begin
kono
parents:
diff changeset
1676 Get_First_Interp (N, I, It);
kono
parents:
diff changeset
1677 while Present (It.Typ) loop
kono
parents:
diff changeset
1678 if
kono
parents:
diff changeset
1679 not Is_Numeric_Type (Etype (First_Formal (It.Nam)))
kono
parents:
diff changeset
1680 then
kono
parents:
diff changeset
1681 if No (Act2)
kono
parents:
diff changeset
1682 or else not Has_Abstract_Interpretation (Act2)
kono
parents:
diff changeset
1683 or else not
kono
parents:
diff changeset
1684 Is_Numeric_Type
kono
parents:
diff changeset
1685 (Etype (Next_Formal (First_Formal (It.Nam))))
kono
parents:
diff changeset
1686 then
kono
parents:
diff changeset
1687 return It;
kono
parents:
diff changeset
1688 end if;
kono
parents:
diff changeset
1689 end if;
kono
parents:
diff changeset
1690
kono
parents:
diff changeset
1691 Get_Next_Interp (I, It);
kono
parents:
diff changeset
1692 end loop;
kono
parents:
diff changeset
1693
kono
parents:
diff changeset
1694 return No_Interp;
kono
parents:
diff changeset
1695 end;
kono
parents:
diff changeset
1696 end if;
kono
parents:
diff changeset
1697 end if;
kono
parents:
diff changeset
1698
kono
parents:
diff changeset
1699 <<Next_Interp>>
kono
parents:
diff changeset
1700 Get_Next_Interp (I, It);
kono
parents:
diff changeset
1701 end loop;
kono
parents:
diff changeset
1702
kono
parents:
diff changeset
1703 -- After some error, a formal may have Any_Type and yield a spurious
kono
parents:
diff changeset
1704 -- match. To avoid cascaded errors if possible, check for such a
kono
parents:
diff changeset
1705 -- formal in either candidate.
kono
parents:
diff changeset
1706
kono
parents:
diff changeset
1707 if Serious_Errors_Detected > 0 then
kono
parents:
diff changeset
1708 declare
kono
parents:
diff changeset
1709 Formal : Entity_Id;
kono
parents:
diff changeset
1710
kono
parents:
diff changeset
1711 begin
kono
parents:
diff changeset
1712 Formal := First_Formal (Nam1);
kono
parents:
diff changeset
1713 while Present (Formal) loop
kono
parents:
diff changeset
1714 if Etype (Formal) = Any_Type then
kono
parents:
diff changeset
1715 return Disambiguate.It2;
kono
parents:
diff changeset
1716 end if;
kono
parents:
diff changeset
1717
kono
parents:
diff changeset
1718 Next_Formal (Formal);
kono
parents:
diff changeset
1719 end loop;
kono
parents:
diff changeset
1720
kono
parents:
diff changeset
1721 Formal := First_Formal (Nam2);
kono
parents:
diff changeset
1722 while Present (Formal) loop
kono
parents:
diff changeset
1723 if Etype (Formal) = Any_Type then
kono
parents:
diff changeset
1724 return Disambiguate.It1;
kono
parents:
diff changeset
1725 end if;
kono
parents:
diff changeset
1726
kono
parents:
diff changeset
1727 Next_Formal (Formal);
kono
parents:
diff changeset
1728 end loop;
kono
parents:
diff changeset
1729 end;
kono
parents:
diff changeset
1730 end if;
kono
parents:
diff changeset
1731
kono
parents:
diff changeset
1732 return It1;
kono
parents:
diff changeset
1733 end Remove_Conversions;
kono
parents:
diff changeset
1734
kono
parents:
diff changeset
1735 -----------------------
kono
parents:
diff changeset
1736 -- Standard_Operator --
kono
parents:
diff changeset
1737 -----------------------
kono
parents:
diff changeset
1738
kono
parents:
diff changeset
1739 function Standard_Operator return Boolean is
kono
parents:
diff changeset
1740 Nam : Node_Id;
kono
parents:
diff changeset
1741
kono
parents:
diff changeset
1742 begin
kono
parents:
diff changeset
1743 if Nkind (N) in N_Op then
kono
parents:
diff changeset
1744 return True;
kono
parents:
diff changeset
1745
kono
parents:
diff changeset
1746 elsif Nkind (N) = N_Function_Call then
kono
parents:
diff changeset
1747 Nam := Name (N);
kono
parents:
diff changeset
1748
kono
parents:
diff changeset
1749 if Nkind (Nam) /= N_Expanded_Name then
kono
parents:
diff changeset
1750 return True;
kono
parents:
diff changeset
1751 else
kono
parents:
diff changeset
1752 return Entity (Prefix (Nam)) = Standard_Standard;
kono
parents:
diff changeset
1753 end if;
kono
parents:
diff changeset
1754 else
kono
parents:
diff changeset
1755 return False;
kono
parents:
diff changeset
1756 end if;
kono
parents:
diff changeset
1757 end Standard_Operator;
kono
parents:
diff changeset
1758
kono
parents:
diff changeset
1759 -- Start of processing for Disambiguate
kono
parents:
diff changeset
1760
kono
parents:
diff changeset
1761 begin
kono
parents:
diff changeset
1762 -- Recover the two legal interpretations
kono
parents:
diff changeset
1763
kono
parents:
diff changeset
1764 Get_First_Interp (N, I, It);
kono
parents:
diff changeset
1765 while I /= I1 loop
kono
parents:
diff changeset
1766 Get_Next_Interp (I, It);
kono
parents:
diff changeset
1767 end loop;
kono
parents:
diff changeset
1768
kono
parents:
diff changeset
1769 It1 := It;
kono
parents:
diff changeset
1770 Nam1 := It.Nam;
kono
parents:
diff changeset
1771
kono
parents:
diff changeset
1772 while I /= I2 loop
kono
parents:
diff changeset
1773 Get_Next_Interp (I, It);
kono
parents:
diff changeset
1774 end loop;
kono
parents:
diff changeset
1775
kono
parents:
diff changeset
1776 It2 := It;
kono
parents:
diff changeset
1777 Nam2 := It.Nam;
kono
parents:
diff changeset
1778
kono
parents:
diff changeset
1779 -- Check whether one of the entities is an Ada 2005/2012 and we are
kono
parents:
diff changeset
1780 -- operating in an earlier mode, in which case we discard the Ada
kono
parents:
diff changeset
1781 -- 2005/2012 entity, so that we get proper Ada 95 overload resolution.
kono
parents:
diff changeset
1782
kono
parents:
diff changeset
1783 if Ada_Version < Ada_2005 then
kono
parents:
diff changeset
1784 if Is_Ada_2005_Only (Nam1) or else Is_Ada_2012_Only (Nam1) then
kono
parents:
diff changeset
1785 return It2;
kono
parents:
diff changeset
1786 elsif Is_Ada_2005_Only (Nam2) or else Is_Ada_2012_Only (Nam1) then
kono
parents:
diff changeset
1787 return It1;
kono
parents:
diff changeset
1788 end if;
kono
parents:
diff changeset
1789 end if;
kono
parents:
diff changeset
1790
kono
parents:
diff changeset
1791 -- Check whether one of the entities is an Ada 2012 entity and we are
kono
parents:
diff changeset
1792 -- operating in Ada 2005 mode, in which case we discard the Ada 2012
kono
parents:
diff changeset
1793 -- entity, so that we get proper Ada 2005 overload resolution.
kono
parents:
diff changeset
1794
kono
parents:
diff changeset
1795 if Ada_Version = Ada_2005 then
kono
parents:
diff changeset
1796 if Is_Ada_2012_Only (Nam1) then
kono
parents:
diff changeset
1797 return It2;
kono
parents:
diff changeset
1798 elsif Is_Ada_2012_Only (Nam2) then
kono
parents:
diff changeset
1799 return It1;
kono
parents:
diff changeset
1800 end if;
kono
parents:
diff changeset
1801 end if;
kono
parents:
diff changeset
1802
kono
parents:
diff changeset
1803 -- If the context is universal, the predefined operator is preferred.
kono
parents:
diff changeset
1804 -- This includes bounds in numeric type declarations, and expressions
kono
parents:
diff changeset
1805 -- in type conversions. If no interpretation yields a universal type,
kono
parents:
diff changeset
1806 -- then we must check whether the user-defined entity hides the prede-
kono
parents:
diff changeset
1807 -- fined one.
kono
parents:
diff changeset
1808
kono
parents:
diff changeset
1809 if Chars (Nam1) in Any_Operator_Name and then Standard_Operator then
kono
parents:
diff changeset
1810 if Typ = Universal_Integer
kono
parents:
diff changeset
1811 or else Typ = Universal_Real
kono
parents:
diff changeset
1812 or else Typ = Any_Integer
kono
parents:
diff changeset
1813 or else Typ = Any_Discrete
kono
parents:
diff changeset
1814 or else Typ = Any_Real
kono
parents:
diff changeset
1815 or else Typ = Any_Type
kono
parents:
diff changeset
1816 then
kono
parents:
diff changeset
1817 -- Find an interpretation that yields the universal type, or else
kono
parents:
diff changeset
1818 -- a predefined operator that yields a predefined numeric type.
kono
parents:
diff changeset
1819
kono
parents:
diff changeset
1820 declare
kono
parents:
diff changeset
1821 Candidate : Interp := No_Interp;
kono
parents:
diff changeset
1822
kono
parents:
diff changeset
1823 begin
kono
parents:
diff changeset
1824 Get_First_Interp (N, I, It);
kono
parents:
diff changeset
1825 while Present (It.Typ) loop
kono
parents:
diff changeset
1826 if (It.Typ = Universal_Integer
kono
parents:
diff changeset
1827 or else It.Typ = Universal_Real)
kono
parents:
diff changeset
1828 and then (Typ = Any_Type or else Covers (Typ, It.Typ))
kono
parents:
diff changeset
1829 then
kono
parents:
diff changeset
1830 return It;
kono
parents:
diff changeset
1831
kono
parents:
diff changeset
1832 elsif Is_Numeric_Type (It.Typ)
kono
parents:
diff changeset
1833 and then Scope (It.Typ) = Standard_Standard
kono
parents:
diff changeset
1834 and then Scope (It.Nam) = Standard_Standard
kono
parents:
diff changeset
1835 and then Covers (Typ, It.Typ)
kono
parents:
diff changeset
1836 then
kono
parents:
diff changeset
1837 Candidate := It;
kono
parents:
diff changeset
1838 end if;
kono
parents:
diff changeset
1839
kono
parents:
diff changeset
1840 Get_Next_Interp (I, It);
kono
parents:
diff changeset
1841 end loop;
kono
parents:
diff changeset
1842
kono
parents:
diff changeset
1843 if Candidate /= No_Interp then
kono
parents:
diff changeset
1844 return Candidate;
kono
parents:
diff changeset
1845 end if;
kono
parents:
diff changeset
1846 end;
kono
parents:
diff changeset
1847
kono
parents:
diff changeset
1848 elsif Chars (Nam1) /= Name_Op_Not
kono
parents:
diff changeset
1849 and then (Typ = Standard_Boolean or else Typ = Any_Boolean)
kono
parents:
diff changeset
1850 then
kono
parents:
diff changeset
1851 -- Equality or comparison operation. Choose predefined operator if
kono
parents:
diff changeset
1852 -- arguments are universal. The node may be an operator, name, or
kono
parents:
diff changeset
1853 -- a function call, so unpack arguments accordingly.
kono
parents:
diff changeset
1854
kono
parents:
diff changeset
1855 declare
kono
parents:
diff changeset
1856 Arg1, Arg2 : Node_Id;
kono
parents:
diff changeset
1857
kono
parents:
diff changeset
1858 begin
kono
parents:
diff changeset
1859 if Nkind (N) in N_Op then
kono
parents:
diff changeset
1860 Arg1 := Left_Opnd (N);
kono
parents:
diff changeset
1861 Arg2 := Right_Opnd (N);
kono
parents:
diff changeset
1862
kono
parents:
diff changeset
1863 elsif Is_Entity_Name (N) then
kono
parents:
diff changeset
1864 Arg1 := First_Entity (Entity (N));
kono
parents:
diff changeset
1865 Arg2 := Next_Entity (Arg1);
kono
parents:
diff changeset
1866
kono
parents:
diff changeset
1867 else
kono
parents:
diff changeset
1868 Arg1 := First_Actual (N);
kono
parents:
diff changeset
1869 Arg2 := Next_Actual (Arg1);
kono
parents:
diff changeset
1870 end if;
kono
parents:
diff changeset
1871
kono
parents:
diff changeset
1872 if Present (Arg2)
kono
parents:
diff changeset
1873 and then Present (Universal_Interpretation (Arg1))
kono
parents:
diff changeset
1874 and then Universal_Interpretation (Arg2) =
kono
parents:
diff changeset
1875 Universal_Interpretation (Arg1)
kono
parents:
diff changeset
1876 then
kono
parents:
diff changeset
1877 Get_First_Interp (N, I, It);
kono
parents:
diff changeset
1878 while Scope (It.Nam) /= Standard_Standard loop
kono
parents:
diff changeset
1879 Get_Next_Interp (I, It);
kono
parents:
diff changeset
1880 end loop;
kono
parents:
diff changeset
1881
kono
parents:
diff changeset
1882 return It;
kono
parents:
diff changeset
1883 end if;
kono
parents:
diff changeset
1884 end;
kono
parents:
diff changeset
1885 end if;
kono
parents:
diff changeset
1886 end if;
kono
parents:
diff changeset
1887
kono
parents:
diff changeset
1888 -- If no universal interpretation, check whether user-defined operator
kono
parents:
diff changeset
1889 -- hides predefined one, as well as other special cases. If the node
kono
parents:
diff changeset
1890 -- is a range, then one or both bounds are ambiguous. Each will have
kono
parents:
diff changeset
1891 -- to be disambiguated w.r.t. the context type. The type of the range
kono
parents:
diff changeset
1892 -- itself is imposed by the context, so we can return either legal
kono
parents:
diff changeset
1893 -- interpretation.
kono
parents:
diff changeset
1894
kono
parents:
diff changeset
1895 if Ekind (Nam1) = E_Operator then
kono
parents:
diff changeset
1896 Predef_Subp := Nam1;
kono
parents:
diff changeset
1897 User_Subp := Nam2;
kono
parents:
diff changeset
1898
kono
parents:
diff changeset
1899 elsif Ekind (Nam2) = E_Operator then
kono
parents:
diff changeset
1900 Predef_Subp := Nam2;
kono
parents:
diff changeset
1901 User_Subp := Nam1;
kono
parents:
diff changeset
1902
kono
parents:
diff changeset
1903 elsif Nkind (N) = N_Range then
kono
parents:
diff changeset
1904 return It1;
kono
parents:
diff changeset
1905
kono
parents:
diff changeset
1906 -- Implement AI05-105: A renaming declaration with an access
kono
parents:
diff changeset
1907 -- definition must resolve to an anonymous access type. This
kono
parents:
diff changeset
1908 -- is a resolution rule and can be used to disambiguate.
kono
parents:
diff changeset
1909
kono
parents:
diff changeset
1910 elsif Nkind (Parent (N)) = N_Object_Renaming_Declaration
kono
parents:
diff changeset
1911 and then Present (Access_Definition (Parent (N)))
kono
parents:
diff changeset
1912 then
kono
parents:
diff changeset
1913 if Ekind_In (It1.Typ, E_Anonymous_Access_Type,
kono
parents:
diff changeset
1914 E_Anonymous_Access_Subprogram_Type)
kono
parents:
diff changeset
1915 then
kono
parents:
diff changeset
1916 if Ekind (It2.Typ) = Ekind (It1.Typ) then
kono
parents:
diff changeset
1917
kono
parents:
diff changeset
1918 -- True ambiguity
kono
parents:
diff changeset
1919
kono
parents:
diff changeset
1920 return No_Interp;
kono
parents:
diff changeset
1921
kono
parents:
diff changeset
1922 else
kono
parents:
diff changeset
1923 return It1;
kono
parents:
diff changeset
1924 end if;
kono
parents:
diff changeset
1925
kono
parents:
diff changeset
1926 elsif Ekind_In (It2.Typ, E_Anonymous_Access_Type,
kono
parents:
diff changeset
1927 E_Anonymous_Access_Subprogram_Type)
kono
parents:
diff changeset
1928 then
kono
parents:
diff changeset
1929 return It2;
kono
parents:
diff changeset
1930
kono
parents:
diff changeset
1931 -- No legal interpretation
kono
parents:
diff changeset
1932
kono
parents:
diff changeset
1933 else
kono
parents:
diff changeset
1934 return No_Interp;
kono
parents:
diff changeset
1935 end if;
kono
parents:
diff changeset
1936
kono
parents:
diff changeset
1937 -- Two access attribute types may have been created for an expression
kono
parents:
diff changeset
1938 -- with an implicit dereference, which is automatically overloaded.
kono
parents:
diff changeset
1939 -- If both access attribute types designate the same object type,
kono
parents:
diff changeset
1940 -- disambiguation if any will take place elsewhere, so keep any one of
kono
parents:
diff changeset
1941 -- the interpretations.
kono
parents:
diff changeset
1942
kono
parents:
diff changeset
1943 elsif Ekind (It1.Typ) = E_Access_Attribute_Type
kono
parents:
diff changeset
1944 and then Ekind (It2.Typ) = E_Access_Attribute_Type
kono
parents:
diff changeset
1945 and then Designated_Type (It1.Typ) = Designated_Type (It2.Typ)
kono
parents:
diff changeset
1946 then
kono
parents:
diff changeset
1947 return It1;
kono
parents:
diff changeset
1948
kono
parents:
diff changeset
1949 -- If two user defined-subprograms are visible, it is a true ambiguity,
kono
parents:
diff changeset
1950 -- unless one of them is an entry and the context is a conditional or
kono
parents:
diff changeset
1951 -- timed entry call, or unless we are within an instance and this is
kono
parents:
diff changeset
1952 -- results from two formals types with the same actual.
kono
parents:
diff changeset
1953
kono
parents:
diff changeset
1954 else
kono
parents:
diff changeset
1955 if Nkind (N) = N_Procedure_Call_Statement
kono
parents:
diff changeset
1956 and then Nkind (Parent (N)) = N_Entry_Call_Alternative
kono
parents:
diff changeset
1957 and then N = Entry_Call_Statement (Parent (N))
kono
parents:
diff changeset
1958 then
kono
parents:
diff changeset
1959 if Ekind (Nam2) = E_Entry then
kono
parents:
diff changeset
1960 return It2;
kono
parents:
diff changeset
1961 elsif Ekind (Nam1) = E_Entry then
kono
parents:
diff changeset
1962 return It1;
kono
parents:
diff changeset
1963 else
kono
parents:
diff changeset
1964 return No_Interp;
kono
parents:
diff changeset
1965 end if;
kono
parents:
diff changeset
1966
kono
parents:
diff changeset
1967 -- If the ambiguity occurs within an instance, it is due to several
kono
parents:
diff changeset
1968 -- formal types with the same actual. Look for an exact match between
kono
parents:
diff changeset
1969 -- the types of the formals of the overloadable entities, and the
kono
parents:
diff changeset
1970 -- actuals in the call, to recover the unambiguous match in the
kono
parents:
diff changeset
1971 -- original generic.
kono
parents:
diff changeset
1972
kono
parents:
diff changeset
1973 -- The ambiguity can also be due to an overloading between a formal
kono
parents:
diff changeset
1974 -- subprogram and a subprogram declared outside the generic. If the
kono
parents:
diff changeset
1975 -- node is overloaded, it did not resolve to the global entity in
kono
parents:
diff changeset
1976 -- the generic, and we choose the formal subprogram.
kono
parents:
diff changeset
1977
kono
parents:
diff changeset
1978 -- Finally, the ambiguity can be between an explicit subprogram and
kono
parents:
diff changeset
1979 -- one inherited (with different defaults) from an actual. In this
kono
parents:
diff changeset
1980 -- case the resolution was to the explicit declaration in the
kono
parents:
diff changeset
1981 -- generic, and remains so in the instance.
kono
parents:
diff changeset
1982
kono
parents:
diff changeset
1983 -- The same sort of disambiguation needed for calls is also required
kono
parents:
diff changeset
1984 -- for the name given in a subprogram renaming, and that case is
kono
parents:
diff changeset
1985 -- handled here as well. We test Comes_From_Source to exclude this
kono
parents:
diff changeset
1986 -- treatment for implicit renamings created for formal subprograms.
kono
parents:
diff changeset
1987
kono
parents:
diff changeset
1988 elsif In_Instance and then not In_Generic_Actual (N) then
kono
parents:
diff changeset
1989 if Nkind (N) in N_Subprogram_Call
kono
parents:
diff changeset
1990 or else
kono
parents:
diff changeset
1991 (Nkind (N) in N_Has_Entity
kono
parents:
diff changeset
1992 and then
kono
parents:
diff changeset
1993 Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
kono
parents:
diff changeset
1994 and then Comes_From_Source (Parent (N)))
kono
parents:
diff changeset
1995 then
kono
parents:
diff changeset
1996 declare
kono
parents:
diff changeset
1997 Actual : Node_Id;
kono
parents:
diff changeset
1998 Formal : Entity_Id;
kono
parents:
diff changeset
1999 Renam : Entity_Id := Empty;
kono
parents:
diff changeset
2000 Is_Act1 : constant Boolean := Is_Actual_Subprogram (Nam1);
kono
parents:
diff changeset
2001 Is_Act2 : constant Boolean := Is_Actual_Subprogram (Nam2);
kono
parents:
diff changeset
2002
kono
parents:
diff changeset
2003 begin
kono
parents:
diff changeset
2004 if Is_Act1 and then not Is_Act2 then
kono
parents:
diff changeset
2005 return It1;
kono
parents:
diff changeset
2006
kono
parents:
diff changeset
2007 elsif Is_Act2 and then not Is_Act1 then
kono
parents:
diff changeset
2008 return It2;
kono
parents:
diff changeset
2009
kono
parents:
diff changeset
2010 elsif Inherited_From_Actual (Nam1)
kono
parents:
diff changeset
2011 and then Comes_From_Source (Nam2)
kono
parents:
diff changeset
2012 then
kono
parents:
diff changeset
2013 return It2;
kono
parents:
diff changeset
2014
kono
parents:
diff changeset
2015 elsif Inherited_From_Actual (Nam2)
kono
parents:
diff changeset
2016 and then Comes_From_Source (Nam1)
kono
parents:
diff changeset
2017 then
kono
parents:
diff changeset
2018 return It1;
kono
parents:
diff changeset
2019 end if;
kono
parents:
diff changeset
2020
kono
parents:
diff changeset
2021 -- In the case of a renamed subprogram, pick up the entity
kono
parents:
diff changeset
2022 -- of the renaming declaration so we can traverse its
kono
parents:
diff changeset
2023 -- formal parameters.
kono
parents:
diff changeset
2024
kono
parents:
diff changeset
2025 if Nkind (N) in N_Has_Entity then
kono
parents:
diff changeset
2026 Renam := Defining_Unit_Name (Specification (Parent (N)));
kono
parents:
diff changeset
2027 end if;
kono
parents:
diff changeset
2028
kono
parents:
diff changeset
2029 if Present (Renam) then
kono
parents:
diff changeset
2030 Actual := First_Formal (Renam);
kono
parents:
diff changeset
2031 else
kono
parents:
diff changeset
2032 Actual := First_Actual (N);
kono
parents:
diff changeset
2033 end if;
kono
parents:
diff changeset
2034
kono
parents:
diff changeset
2035 Formal := First_Formal (Nam1);
kono
parents:
diff changeset
2036 while Present (Actual) loop
kono
parents:
diff changeset
2037 if Etype (Actual) /= Etype (Formal) then
kono
parents:
diff changeset
2038 return It2;
kono
parents:
diff changeset
2039 end if;
kono
parents:
diff changeset
2040
kono
parents:
diff changeset
2041 if Present (Renam) then
kono
parents:
diff changeset
2042 Next_Formal (Actual);
kono
parents:
diff changeset
2043 else
kono
parents:
diff changeset
2044 Next_Actual (Actual);
kono
parents:
diff changeset
2045 end if;
kono
parents:
diff changeset
2046
kono
parents:
diff changeset
2047 Next_Formal (Formal);
kono
parents:
diff changeset
2048 end loop;
kono
parents:
diff changeset
2049
kono
parents:
diff changeset
2050 return It1;
kono
parents:
diff changeset
2051 end;
kono
parents:
diff changeset
2052
kono
parents:
diff changeset
2053 elsif Nkind (N) in N_Binary_Op then
kono
parents:
diff changeset
2054 if Matches (N, Nam1) then
kono
parents:
diff changeset
2055 return It1;
kono
parents:
diff changeset
2056 else
kono
parents:
diff changeset
2057 return It2;
kono
parents:
diff changeset
2058 end if;
kono
parents:
diff changeset
2059
kono
parents:
diff changeset
2060 elsif Nkind (N) in N_Unary_Op then
kono
parents:
diff changeset
2061 if Etype (Right_Opnd (N)) = Etype (First_Formal (Nam1)) then
kono
parents:
diff changeset
2062 return It1;
kono
parents:
diff changeset
2063 else
kono
parents:
diff changeset
2064 return It2;
kono
parents:
diff changeset
2065 end if;
kono
parents:
diff changeset
2066
kono
parents:
diff changeset
2067 else
kono
parents:
diff changeset
2068 return Remove_Conversions;
kono
parents:
diff changeset
2069 end if;
kono
parents:
diff changeset
2070 else
kono
parents:
diff changeset
2071 return Remove_Conversions;
kono
parents:
diff changeset
2072 end if;
kono
parents:
diff changeset
2073 end if;
kono
parents:
diff changeset
2074
kono
parents:
diff changeset
2075 -- An implicit concatenation operator on a string type cannot be
kono
parents:
diff changeset
2076 -- disambiguated from the predefined concatenation. This can only
kono
parents:
diff changeset
2077 -- happen with concatenation of string literals.
kono
parents:
diff changeset
2078
kono
parents:
diff changeset
2079 if Chars (User_Subp) = Name_Op_Concat
kono
parents:
diff changeset
2080 and then Ekind (User_Subp) = E_Operator
kono
parents:
diff changeset
2081 and then Is_String_Type (Etype (First_Formal (User_Subp)))
kono
parents:
diff changeset
2082 then
kono
parents:
diff changeset
2083 return No_Interp;
kono
parents:
diff changeset
2084
kono
parents:
diff changeset
2085 -- If the user-defined operator is in an open scope, or in the scope
kono
parents:
diff changeset
2086 -- of the resulting type, or given by an expanded name that names its
kono
parents:
diff changeset
2087 -- scope, it hides the predefined operator for the type. Exponentiation
kono
parents:
diff changeset
2088 -- has to be special-cased because the implicit operator does not have
kono
parents:
diff changeset
2089 -- a symmetric signature, and may not be hidden by the explicit one.
kono
parents:
diff changeset
2090
kono
parents:
diff changeset
2091 elsif (Nkind (N) = N_Function_Call
kono
parents:
diff changeset
2092 and then Nkind (Name (N)) = N_Expanded_Name
kono
parents:
diff changeset
2093 and then (Chars (Predef_Subp) /= Name_Op_Expon
kono
parents:
diff changeset
2094 or else Hides_Op (User_Subp, Predef_Subp))
kono
parents:
diff changeset
2095 and then Scope (User_Subp) = Entity (Prefix (Name (N))))
kono
parents:
diff changeset
2096 or else Hides_Op (User_Subp, Predef_Subp)
kono
parents:
diff changeset
2097 then
kono
parents:
diff changeset
2098 if It1.Nam = User_Subp then
kono
parents:
diff changeset
2099 return It1;
kono
parents:
diff changeset
2100 else
kono
parents:
diff changeset
2101 return It2;
kono
parents:
diff changeset
2102 end if;
kono
parents:
diff changeset
2103
kono
parents:
diff changeset
2104 -- Otherwise, the predefined operator has precedence, or if the user-
kono
parents:
diff changeset
2105 -- defined operation is directly visible we have a true ambiguity.
kono
parents:
diff changeset
2106
kono
parents:
diff changeset
2107 -- If this is a fixed-point multiplication and division in Ada 83 mode,
kono
parents:
diff changeset
2108 -- exclude the universal_fixed operator, which often causes ambiguities
kono
parents:
diff changeset
2109 -- in legacy code.
kono
parents:
diff changeset
2110
kono
parents:
diff changeset
2111 -- Ditto in Ada 2012, where an ambiguity may arise for an operation
kono
parents:
diff changeset
2112 -- on a partial view that is completed with a fixed point type. See
kono
parents:
diff changeset
2113 -- AI05-0020 and AI05-0209. The ambiguity is resolved in favor of the
kono
parents:
diff changeset
2114 -- user-defined type and subprogram, so that a client of the package
kono
parents:
diff changeset
2115 -- has the same resolution as the body of the package.
kono
parents:
diff changeset
2116
kono
parents:
diff changeset
2117 else
kono
parents:
diff changeset
2118 if (In_Open_Scopes (Scope (User_Subp))
kono
parents:
diff changeset
2119 or else Is_Potentially_Use_Visible (User_Subp))
kono
parents:
diff changeset
2120 and then not In_Instance
kono
parents:
diff changeset
2121 then
kono
parents:
diff changeset
2122 if Is_Fixed_Point_Type (Typ)
kono
parents:
diff changeset
2123 and then Nam_In (Chars (Nam1), Name_Op_Multiply, Name_Op_Divide)
kono
parents:
diff changeset
2124 and then
kono
parents:
diff changeset
2125 (Ada_Version = Ada_83
kono
parents:
diff changeset
2126 or else (Ada_Version >= Ada_2012
kono
parents:
diff changeset
2127 and then In_Same_Declaration_List
kono
parents:
diff changeset
2128 (First_Subtype (Typ),
kono
parents:
diff changeset
2129 Unit_Declaration_Node (User_Subp))))
kono
parents:
diff changeset
2130 then
kono
parents:
diff changeset
2131 if It2.Nam = Predef_Subp then
kono
parents:
diff changeset
2132 return It1;
kono
parents:
diff changeset
2133 else
kono
parents:
diff changeset
2134 return It2;
kono
parents:
diff changeset
2135 end if;
kono
parents:
diff changeset
2136
kono
parents:
diff changeset
2137 -- Ada 2005, AI-420: preference rule for "=" on Universal_Access
kono
parents:
diff changeset
2138 -- states that the operator defined in Standard is not available
kono
parents:
diff changeset
2139 -- if there is a user-defined equality with the proper signature,
kono
parents:
diff changeset
2140 -- declared in the same declarative list as the type. The node
kono
parents:
diff changeset
2141 -- may be an operator or a function call.
kono
parents:
diff changeset
2142
kono
parents:
diff changeset
2143 elsif Nam_In (Chars (Nam1), Name_Op_Eq, Name_Op_Ne)
kono
parents:
diff changeset
2144 and then Ada_Version >= Ada_2005
kono
parents:
diff changeset
2145 and then Etype (User_Subp) = Standard_Boolean
kono
parents:
diff changeset
2146 and then Ekind (Operand_Type) = E_Anonymous_Access_Type
kono
parents:
diff changeset
2147 and then
kono
parents:
diff changeset
2148 In_Same_Declaration_List
kono
parents:
diff changeset
2149 (Designated_Type (Operand_Type),
kono
parents:
diff changeset
2150 Unit_Declaration_Node (User_Subp))
kono
parents:
diff changeset
2151 then
kono
parents:
diff changeset
2152 if It2.Nam = Predef_Subp then
kono
parents:
diff changeset
2153 return It1;
kono
parents:
diff changeset
2154 else
kono
parents:
diff changeset
2155 return It2;
kono
parents:
diff changeset
2156 end if;
kono
parents:
diff changeset
2157
kono
parents:
diff changeset
2158 -- An immediately visible operator hides a use-visible user-
kono
parents:
diff changeset
2159 -- defined operation. This disambiguation cannot take place
kono
parents:
diff changeset
2160 -- earlier because the visibility of the predefined operator
kono
parents:
diff changeset
2161 -- can only be established when operand types are known.
kono
parents:
diff changeset
2162
kono
parents:
diff changeset
2163 elsif Ekind (User_Subp) = E_Function
kono
parents:
diff changeset
2164 and then Ekind (Predef_Subp) = E_Operator
kono
parents:
diff changeset
2165 and then Nkind (N) in N_Op
kono
parents:
diff changeset
2166 and then not Is_Overloaded (Right_Opnd (N))
kono
parents:
diff changeset
2167 and then
kono
parents:
diff changeset
2168 Is_Immediately_Visible (Base_Type (Etype (Right_Opnd (N))))
kono
parents:
diff changeset
2169 and then Is_Potentially_Use_Visible (User_Subp)
kono
parents:
diff changeset
2170 then
kono
parents:
diff changeset
2171 if It2.Nam = Predef_Subp then
kono
parents:
diff changeset
2172 return It1;
kono
parents:
diff changeset
2173 else
kono
parents:
diff changeset
2174 return It2;
kono
parents:
diff changeset
2175 end if;
kono
parents:
diff changeset
2176
kono
parents:
diff changeset
2177 else
kono
parents:
diff changeset
2178 return No_Interp;
kono
parents:
diff changeset
2179 end if;
kono
parents:
diff changeset
2180
kono
parents:
diff changeset
2181 elsif It1.Nam = Predef_Subp then
kono
parents:
diff changeset
2182 return It1;
kono
parents:
diff changeset
2183
kono
parents:
diff changeset
2184 else
kono
parents:
diff changeset
2185 return It2;
kono
parents:
diff changeset
2186 end if;
kono
parents:
diff changeset
2187 end if;
kono
parents:
diff changeset
2188 end Disambiguate;
kono
parents:
diff changeset
2189
kono
parents:
diff changeset
2190 ---------------------
kono
parents:
diff changeset
2191 -- End_Interp_List --
kono
parents:
diff changeset
2192 ---------------------
kono
parents:
diff changeset
2193
kono
parents:
diff changeset
2194 procedure End_Interp_List is
kono
parents:
diff changeset
2195 begin
kono
parents:
diff changeset
2196 All_Interp.Table (All_Interp.Last) := No_Interp;
kono
parents:
diff changeset
2197 All_Interp.Increment_Last;
kono
parents:
diff changeset
2198 end End_Interp_List;
kono
parents:
diff changeset
2199
kono
parents:
diff changeset
2200 -------------------------
kono
parents:
diff changeset
2201 -- Entity_Matches_Spec --
kono
parents:
diff changeset
2202 -------------------------
kono
parents:
diff changeset
2203
kono
parents:
diff changeset
2204 function Entity_Matches_Spec (Old_S, New_S : Entity_Id) return Boolean is
kono
parents:
diff changeset
2205 begin
kono
parents:
diff changeset
2206 -- Simple case: same entity kinds, type conformance is required. A
kono
parents:
diff changeset
2207 -- parameterless function can also rename a literal.
kono
parents:
diff changeset
2208
kono
parents:
diff changeset
2209 if Ekind (Old_S) = Ekind (New_S)
kono
parents:
diff changeset
2210 or else (Ekind (New_S) = E_Function
kono
parents:
diff changeset
2211 and then Ekind (Old_S) = E_Enumeration_Literal)
kono
parents:
diff changeset
2212 then
kono
parents:
diff changeset
2213 return Type_Conformant (New_S, Old_S);
kono
parents:
diff changeset
2214
kono
parents:
diff changeset
2215 elsif Ekind (New_S) = E_Function and then Ekind (Old_S) = E_Operator then
kono
parents:
diff changeset
2216 return Operator_Matches_Spec (Old_S, New_S);
kono
parents:
diff changeset
2217
kono
parents:
diff changeset
2218 elsif Ekind (New_S) = E_Procedure and then Is_Entry (Old_S) then
kono
parents:
diff changeset
2219 return Type_Conformant (New_S, Old_S);
kono
parents:
diff changeset
2220
kono
parents:
diff changeset
2221 else
kono
parents:
diff changeset
2222 return False;
kono
parents:
diff changeset
2223 end if;
kono
parents:
diff changeset
2224 end Entity_Matches_Spec;
kono
parents:
diff changeset
2225
kono
parents:
diff changeset
2226 ----------------------
kono
parents:
diff changeset
2227 -- Find_Unique_Type --
kono
parents:
diff changeset
2228 ----------------------
kono
parents:
diff changeset
2229
kono
parents:
diff changeset
2230 function Find_Unique_Type (L : Node_Id; R : Node_Id) return Entity_Id is
kono
parents:
diff changeset
2231 T : constant Entity_Id := Etype (L);
kono
parents:
diff changeset
2232 I : Interp_Index;
kono
parents:
diff changeset
2233 It : Interp;
kono
parents:
diff changeset
2234 TR : Entity_Id := Any_Type;
kono
parents:
diff changeset
2235
kono
parents:
diff changeset
2236 begin
kono
parents:
diff changeset
2237 if Is_Overloaded (R) then
kono
parents:
diff changeset
2238 Get_First_Interp (R, I, It);
kono
parents:
diff changeset
2239 while Present (It.Typ) loop
kono
parents:
diff changeset
2240 if Covers (T, It.Typ) or else Covers (It.Typ, T) then
kono
parents:
diff changeset
2241
kono
parents:
diff changeset
2242 -- If several interpretations are possible and L is universal,
kono
parents:
diff changeset
2243 -- apply preference rule.
kono
parents:
diff changeset
2244
kono
parents:
diff changeset
2245 if TR /= Any_Type then
kono
parents:
diff changeset
2246 if (T = Universal_Integer or else T = Universal_Real)
kono
parents:
diff changeset
2247 and then It.Typ = T
kono
parents:
diff changeset
2248 then
kono
parents:
diff changeset
2249 TR := It.Typ;
kono
parents:
diff changeset
2250 end if;
kono
parents:
diff changeset
2251
kono
parents:
diff changeset
2252 else
kono
parents:
diff changeset
2253 TR := It.Typ;
kono
parents:
diff changeset
2254 end if;
kono
parents:
diff changeset
2255 end if;
kono
parents:
diff changeset
2256
kono
parents:
diff changeset
2257 Get_Next_Interp (I, It);
kono
parents:
diff changeset
2258 end loop;
kono
parents:
diff changeset
2259
kono
parents:
diff changeset
2260 Set_Etype (R, TR);
kono
parents:
diff changeset
2261
kono
parents:
diff changeset
2262 -- In the non-overloaded case, the Etype of R is already set correctly
kono
parents:
diff changeset
2263
kono
parents:
diff changeset
2264 else
kono
parents:
diff changeset
2265 null;
kono
parents:
diff changeset
2266 end if;
kono
parents:
diff changeset
2267
kono
parents:
diff changeset
2268 -- If one of the operands is Universal_Fixed, the type of the other
kono
parents:
diff changeset
2269 -- operand provides the context.
kono
parents:
diff changeset
2270
kono
parents:
diff changeset
2271 if Etype (R) = Universal_Fixed then
kono
parents:
diff changeset
2272 return T;
kono
parents:
diff changeset
2273
kono
parents:
diff changeset
2274 elsif T = Universal_Fixed then
kono
parents:
diff changeset
2275 return Etype (R);
kono
parents:
diff changeset
2276
kono
parents:
diff changeset
2277 -- Ada 2005 (AI-230): Support the following operators:
kono
parents:
diff changeset
2278
kono
parents:
diff changeset
2279 -- function "=" (L, R : universal_access) return Boolean;
kono
parents:
diff changeset
2280 -- function "/=" (L, R : universal_access) return Boolean;
kono
parents:
diff changeset
2281
kono
parents:
diff changeset
2282 -- Pool specific access types (E_Access_Type) are not covered by these
kono
parents:
diff changeset
2283 -- operators because of the legality rule of 4.5.2(9.2): "The operands
kono
parents:
diff changeset
2284 -- of the equality operators for universal_access shall be convertible
kono
parents:
diff changeset
2285 -- to one another (see 4.6)". For example, considering the type decla-
kono
parents:
diff changeset
2286 -- ration "type P is access Integer" and an anonymous access to Integer,
kono
parents:
diff changeset
2287 -- P is convertible to "access Integer" by 4.6 (24.11-24.15), but there
kono
parents:
diff changeset
2288 -- is no rule in 4.6 that allows "access Integer" to be converted to P.
kono
parents:
diff changeset
2289
kono
parents:
diff changeset
2290 elsif Ada_Version >= Ada_2005
kono
parents:
diff changeset
2291 and then Ekind_In (Etype (L), E_Anonymous_Access_Type,
kono
parents:
diff changeset
2292 E_Anonymous_Access_Subprogram_Type)
kono
parents:
diff changeset
2293 and then Is_Access_Type (Etype (R))
kono
parents:
diff changeset
2294 and then Ekind (Etype (R)) /= E_Access_Type
kono
parents:
diff changeset
2295 then
kono
parents:
diff changeset
2296 return Etype (L);
kono
parents:
diff changeset
2297
kono
parents:
diff changeset
2298 elsif Ada_Version >= Ada_2005
kono
parents:
diff changeset
2299 and then Ekind_In (Etype (R), E_Anonymous_Access_Type,
kono
parents:
diff changeset
2300 E_Anonymous_Access_Subprogram_Type)
kono
parents:
diff changeset
2301 and then Is_Access_Type (Etype (L))
kono
parents:
diff changeset
2302 and then Ekind (Etype (L)) /= E_Access_Type
kono
parents:
diff changeset
2303 then
kono
parents:
diff changeset
2304 return Etype (R);
kono
parents:
diff changeset
2305
kono
parents:
diff changeset
2306 -- If one operand is a raise_expression, use type of other operand
kono
parents:
diff changeset
2307
kono
parents:
diff changeset
2308 elsif Nkind (L) = N_Raise_Expression then
kono
parents:
diff changeset
2309 return Etype (R);
kono
parents:
diff changeset
2310
kono
parents:
diff changeset
2311 else
kono
parents:
diff changeset
2312 return Specific_Type (T, Etype (R));
kono
parents:
diff changeset
2313 end if;
kono
parents:
diff changeset
2314 end Find_Unique_Type;
kono
parents:
diff changeset
2315
kono
parents:
diff changeset
2316 -------------------------------------
kono
parents:
diff changeset
2317 -- Function_Interp_Has_Abstract_Op --
kono
parents:
diff changeset
2318 -------------------------------------
kono
parents:
diff changeset
2319
kono
parents:
diff changeset
2320 function Function_Interp_Has_Abstract_Op
kono
parents:
diff changeset
2321 (N : Node_Id;
kono
parents:
diff changeset
2322 E : Entity_Id) return Entity_Id
kono
parents:
diff changeset
2323 is
kono
parents:
diff changeset
2324 Abstr_Op : Entity_Id;
kono
parents:
diff changeset
2325 Act : Node_Id;
kono
parents:
diff changeset
2326 Act_Parm : Node_Id;
kono
parents:
diff changeset
2327 Form_Parm : Node_Id;
kono
parents:
diff changeset
2328
kono
parents:
diff changeset
2329 begin
kono
parents:
diff changeset
2330 -- Why is check on E needed below ???
kono
parents:
diff changeset
2331 -- In any case this para needs comments ???
kono
parents:
diff changeset
2332
kono
parents:
diff changeset
2333 if Is_Overloaded (N) and then Is_Overloadable (E) then
kono
parents:
diff changeset
2334 Act_Parm := First_Actual (N);
kono
parents:
diff changeset
2335 Form_Parm := First_Formal (E);
kono
parents:
diff changeset
2336 while Present (Act_Parm) and then Present (Form_Parm) loop
kono
parents:
diff changeset
2337 Act := Act_Parm;
kono
parents:
diff changeset
2338
kono
parents:
diff changeset
2339 if Nkind (Act) = N_Parameter_Association then
kono
parents:
diff changeset
2340 Act := Explicit_Actual_Parameter (Act);
kono
parents:
diff changeset
2341 end if;
kono
parents:
diff changeset
2342
kono
parents:
diff changeset
2343 Abstr_Op := Has_Abstract_Op (Act, Etype (Form_Parm));
kono
parents:
diff changeset
2344
kono
parents:
diff changeset
2345 if Present (Abstr_Op) then
kono
parents:
diff changeset
2346 return Abstr_Op;
kono
parents:
diff changeset
2347 end if;
kono
parents:
diff changeset
2348
kono
parents:
diff changeset
2349 Next_Actual (Act_Parm);
kono
parents:
diff changeset
2350 Next_Formal (Form_Parm);
kono
parents:
diff changeset
2351 end loop;
kono
parents:
diff changeset
2352 end if;
kono
parents:
diff changeset
2353
kono
parents:
diff changeset
2354 return Empty;
kono
parents:
diff changeset
2355 end Function_Interp_Has_Abstract_Op;
kono
parents:
diff changeset
2356
kono
parents:
diff changeset
2357 ----------------------
kono
parents:
diff changeset
2358 -- Get_First_Interp --
kono
parents:
diff changeset
2359 ----------------------
kono
parents:
diff changeset
2360
kono
parents:
diff changeset
2361 procedure Get_First_Interp
kono
parents:
diff changeset
2362 (N : Node_Id;
kono
parents:
diff changeset
2363 I : out Interp_Index;
kono
parents:
diff changeset
2364 It : out Interp)
kono
parents:
diff changeset
2365 is
kono
parents:
diff changeset
2366 Int_Ind : Interp_Index;
kono
parents:
diff changeset
2367 Map_Ptr : Int;
kono
parents:
diff changeset
2368 O_N : Node_Id;
kono
parents:
diff changeset
2369
kono
parents:
diff changeset
2370 begin
kono
parents:
diff changeset
2371 -- If a selected component is overloaded because the selector has
kono
parents:
diff changeset
2372 -- multiple interpretations, the node is a call to a protected
kono
parents:
diff changeset
2373 -- operation or an indirect call. Retrieve the interpretation from
kono
parents:
diff changeset
2374 -- the selector name. The selected component may be overloaded as well
kono
parents:
diff changeset
2375 -- if the prefix is overloaded. That case is unchanged.
kono
parents:
diff changeset
2376
kono
parents:
diff changeset
2377 if Nkind (N) = N_Selected_Component
kono
parents:
diff changeset
2378 and then Is_Overloaded (Selector_Name (N))
kono
parents:
diff changeset
2379 then
kono
parents:
diff changeset
2380 O_N := Selector_Name (N);
kono
parents:
diff changeset
2381 else
kono
parents:
diff changeset
2382 O_N := N;
kono
parents:
diff changeset
2383 end if;
kono
parents:
diff changeset
2384
kono
parents:
diff changeset
2385 Map_Ptr := Headers (Hash (O_N));
kono
parents:
diff changeset
2386 while Map_Ptr /= No_Entry loop
kono
parents:
diff changeset
2387 if Interp_Map.Table (Map_Ptr).Node = O_N then
kono
parents:
diff changeset
2388 Int_Ind := Interp_Map.Table (Map_Ptr).Index;
kono
parents:
diff changeset
2389 It := All_Interp.Table (Int_Ind);
kono
parents:
diff changeset
2390 I := Int_Ind;
kono
parents:
diff changeset
2391 return;
kono
parents:
diff changeset
2392 else
kono
parents:
diff changeset
2393 Map_Ptr := Interp_Map.Table (Map_Ptr).Next;
kono
parents:
diff changeset
2394 end if;
kono
parents:
diff changeset
2395 end loop;
kono
parents:
diff changeset
2396
kono
parents:
diff changeset
2397 -- Procedure should never be called if the node has no interpretations
kono
parents:
diff changeset
2398
kono
parents:
diff changeset
2399 raise Program_Error;
kono
parents:
diff changeset
2400 end Get_First_Interp;
kono
parents:
diff changeset
2401
kono
parents:
diff changeset
2402 ---------------------
kono
parents:
diff changeset
2403 -- Get_Next_Interp --
kono
parents:
diff changeset
2404 ---------------------
kono
parents:
diff changeset
2405
kono
parents:
diff changeset
2406 procedure Get_Next_Interp (I : in out Interp_Index; It : out Interp) is
kono
parents:
diff changeset
2407 begin
kono
parents:
diff changeset
2408 I := I + 1;
kono
parents:
diff changeset
2409 It := All_Interp.Table (I);
kono
parents:
diff changeset
2410 end Get_Next_Interp;
kono
parents:
diff changeset
2411
kono
parents:
diff changeset
2412 -------------------------
kono
parents:
diff changeset
2413 -- Has_Compatible_Type --
kono
parents:
diff changeset
2414 -------------------------
kono
parents:
diff changeset
2415
kono
parents:
diff changeset
2416 function Has_Compatible_Type
kono
parents:
diff changeset
2417 (N : Node_Id;
kono
parents:
diff changeset
2418 Typ : Entity_Id) return Boolean
kono
parents:
diff changeset
2419 is
kono
parents:
diff changeset
2420 I : Interp_Index;
kono
parents:
diff changeset
2421 It : Interp;
kono
parents:
diff changeset
2422
kono
parents:
diff changeset
2423 begin
kono
parents:
diff changeset
2424 if N = Error then
kono
parents:
diff changeset
2425 return False;
kono
parents:
diff changeset
2426 end if;
kono
parents:
diff changeset
2427
kono
parents:
diff changeset
2428 if Nkind (N) = N_Subtype_Indication
kono
parents:
diff changeset
2429 or else not Is_Overloaded (N)
kono
parents:
diff changeset
2430 then
kono
parents:
diff changeset
2431 return
kono
parents:
diff changeset
2432 Covers (Typ, Etype (N))
kono
parents:
diff changeset
2433
kono
parents:
diff changeset
2434 -- Ada 2005 (AI-345): The context may be a synchronized interface.
kono
parents:
diff changeset
2435 -- If the type is already frozen use the corresponding_record
kono
parents:
diff changeset
2436 -- to check whether it is a proper descendant.
kono
parents:
diff changeset
2437
kono
parents:
diff changeset
2438 or else
kono
parents:
diff changeset
2439 (Is_Record_Type (Typ)
kono
parents:
diff changeset
2440 and then Is_Concurrent_Type (Etype (N))
kono
parents:
diff changeset
2441 and then Present (Corresponding_Record_Type (Etype (N)))
kono
parents:
diff changeset
2442 and then Covers (Typ, Corresponding_Record_Type (Etype (N))))
kono
parents:
diff changeset
2443
kono
parents:
diff changeset
2444 or else
kono
parents:
diff changeset
2445 (Is_Concurrent_Type (Typ)
kono
parents:
diff changeset
2446 and then Is_Record_Type (Etype (N))
kono
parents:
diff changeset
2447 and then Present (Corresponding_Record_Type (Typ))
kono
parents:
diff changeset
2448 and then Covers (Corresponding_Record_Type (Typ), Etype (N)))
kono
parents:
diff changeset
2449
kono
parents:
diff changeset
2450 or else
kono
parents:
diff changeset
2451 (not Is_Tagged_Type (Typ)
kono
parents:
diff changeset
2452 and then Ekind (Typ) /= E_Anonymous_Access_Type
kono
parents:
diff changeset
2453 and then Covers (Etype (N), Typ));
kono
parents:
diff changeset
2454
kono
parents:
diff changeset
2455 -- Overloaded case
kono
parents:
diff changeset
2456
kono
parents:
diff changeset
2457 else
kono
parents:
diff changeset
2458 Get_First_Interp (N, I, It);
kono
parents:
diff changeset
2459 while Present (It.Typ) loop
kono
parents:
diff changeset
2460 if (Covers (Typ, It.Typ)
kono
parents:
diff changeset
2461 and then
kono
parents:
diff changeset
2462 (Scope (It.Nam) /= Standard_Standard
kono
parents:
diff changeset
2463 or else not Is_Invisible_Operator (N, Base_Type (Typ))))
kono
parents:
diff changeset
2464
kono
parents:
diff changeset
2465 -- Ada 2005 (AI-345)
kono
parents:
diff changeset
2466
kono
parents:
diff changeset
2467 or else
kono
parents:
diff changeset
2468 (Is_Concurrent_Type (It.Typ)
kono
parents:
diff changeset
2469 and then Present (Corresponding_Record_Type
kono
parents:
diff changeset
2470 (Etype (It.Typ)))
kono
parents:
diff changeset
2471 and then Covers (Typ, Corresponding_Record_Type
kono
parents:
diff changeset
2472 (Etype (It.Typ))))
kono
parents:
diff changeset
2473
kono
parents:
diff changeset
2474 or else (not Is_Tagged_Type (Typ)
kono
parents:
diff changeset
2475 and then Ekind (Typ) /= E_Anonymous_Access_Type
kono
parents:
diff changeset
2476 and then Covers (It.Typ, Typ))
kono
parents:
diff changeset
2477 then
kono
parents:
diff changeset
2478 return True;
kono
parents:
diff changeset
2479 end if;
kono
parents:
diff changeset
2480
kono
parents:
diff changeset
2481 Get_Next_Interp (I, It);
kono
parents:
diff changeset
2482 end loop;
kono
parents:
diff changeset
2483
kono
parents:
diff changeset
2484 return False;
kono
parents:
diff changeset
2485 end if;
kono
parents:
diff changeset
2486 end Has_Compatible_Type;
kono
parents:
diff changeset
2487
kono
parents:
diff changeset
2488 ---------------------
kono
parents:
diff changeset
2489 -- Has_Abstract_Op --
kono
parents:
diff changeset
2490 ---------------------
kono
parents:
diff changeset
2491
kono
parents:
diff changeset
2492 function Has_Abstract_Op
kono
parents:
diff changeset
2493 (N : Node_Id;
kono
parents:
diff changeset
2494 Typ : Entity_Id) return Entity_Id
kono
parents:
diff changeset
2495 is
kono
parents:
diff changeset
2496 I : Interp_Index;
kono
parents:
diff changeset
2497 It : Interp;
kono
parents:
diff changeset
2498
kono
parents:
diff changeset
2499 begin
kono
parents:
diff changeset
2500 if Is_Overloaded (N) then
kono
parents:
diff changeset
2501 Get_First_Interp (N, I, It);
kono
parents:
diff changeset
2502 while Present (It.Nam) loop
kono
parents:
diff changeset
2503 if Present (It.Abstract_Op)
kono
parents:
diff changeset
2504 and then Etype (It.Abstract_Op) = Typ
kono
parents:
diff changeset
2505 then
kono
parents:
diff changeset
2506 return It.Abstract_Op;
kono
parents:
diff changeset
2507 end if;
kono
parents:
diff changeset
2508
kono
parents:
diff changeset
2509 Get_Next_Interp (I, It);
kono
parents:
diff changeset
2510 end loop;
kono
parents:
diff changeset
2511 end if;
kono
parents:
diff changeset
2512
kono
parents:
diff changeset
2513 return Empty;
kono
parents:
diff changeset
2514 end Has_Abstract_Op;
kono
parents:
diff changeset
2515
kono
parents:
diff changeset
2516 ----------
kono
parents:
diff changeset
2517 -- Hash --
kono
parents:
diff changeset
2518 ----------
kono
parents:
diff changeset
2519
kono
parents:
diff changeset
2520 function Hash (N : Node_Id) return Int is
kono
parents:
diff changeset
2521 begin
kono
parents:
diff changeset
2522 -- Nodes have a size that is power of two, so to select significant
kono
parents:
diff changeset
2523 -- bits only we remove the low-order bits.
kono
parents:
diff changeset
2524
kono
parents:
diff changeset
2525 return ((Int (N) / 2 ** 5) mod Header_Size);
kono
parents:
diff changeset
2526 end Hash;
kono
parents:
diff changeset
2527
kono
parents:
diff changeset
2528 --------------
kono
parents:
diff changeset
2529 -- Hides_Op --
kono
parents:
diff changeset
2530 --------------
kono
parents:
diff changeset
2531
kono
parents:
diff changeset
2532 function Hides_Op (F : Entity_Id; Op : Entity_Id) return Boolean is
kono
parents:
diff changeset
2533 Btyp : constant Entity_Id := Base_Type (Etype (First_Formal (F)));
kono
parents:
diff changeset
2534 begin
kono
parents:
diff changeset
2535 return Operator_Matches_Spec (Op, F)
kono
parents:
diff changeset
2536 and then (In_Open_Scopes (Scope (F))
kono
parents:
diff changeset
2537 or else Scope (F) = Scope (Btyp)
kono
parents:
diff changeset
2538 or else (not In_Open_Scopes (Scope (Btyp))
kono
parents:
diff changeset
2539 and then not In_Use (Btyp)
kono
parents:
diff changeset
2540 and then not In_Use (Scope (Btyp))));
kono
parents:
diff changeset
2541 end Hides_Op;
kono
parents:
diff changeset
2542
kono
parents:
diff changeset
2543 ------------------------
kono
parents:
diff changeset
2544 -- Init_Interp_Tables --
kono
parents:
diff changeset
2545 ------------------------
kono
parents:
diff changeset
2546
kono
parents:
diff changeset
2547 procedure Init_Interp_Tables is
kono
parents:
diff changeset
2548 begin
kono
parents:
diff changeset
2549 All_Interp.Init;
kono
parents:
diff changeset
2550 Interp_Map.Init;
kono
parents:
diff changeset
2551 Headers := (others => No_Entry);
kono
parents:
diff changeset
2552 end Init_Interp_Tables;
kono
parents:
diff changeset
2553
kono
parents:
diff changeset
2554 -----------------------------------
kono
parents:
diff changeset
2555 -- Interface_Present_In_Ancestor --
kono
parents:
diff changeset
2556 -----------------------------------
kono
parents:
diff changeset
2557
kono
parents:
diff changeset
2558 function Interface_Present_In_Ancestor
kono
parents:
diff changeset
2559 (Typ : Entity_Id;
kono
parents:
diff changeset
2560 Iface : Entity_Id) return Boolean
kono
parents:
diff changeset
2561 is
kono
parents:
diff changeset
2562 Target_Typ : Entity_Id;
kono
parents:
diff changeset
2563 Iface_Typ : Entity_Id;
kono
parents:
diff changeset
2564
kono
parents:
diff changeset
2565 function Iface_Present_In_Ancestor (Typ : Entity_Id) return Boolean;
kono
parents:
diff changeset
2566 -- Returns True if Typ or some ancestor of Typ implements Iface
kono
parents:
diff changeset
2567
kono
parents:
diff changeset
2568 -------------------------------
kono
parents:
diff changeset
2569 -- Iface_Present_In_Ancestor --
kono
parents:
diff changeset
2570 -------------------------------
kono
parents:
diff changeset
2571
kono
parents:
diff changeset
2572 function Iface_Present_In_Ancestor (Typ : Entity_Id) return Boolean is
kono
parents:
diff changeset
2573 E : Entity_Id;
kono
parents:
diff changeset
2574 AI : Entity_Id;
kono
parents:
diff changeset
2575 Elmt : Elmt_Id;
kono
parents:
diff changeset
2576
kono
parents:
diff changeset
2577 begin
kono
parents:
diff changeset
2578 if Typ = Iface_Typ then
kono
parents:
diff changeset
2579 return True;
kono
parents:
diff changeset
2580 end if;
kono
parents:
diff changeset
2581
kono
parents:
diff changeset
2582 -- Handle private types
kono
parents:
diff changeset
2583
kono
parents:
diff changeset
2584 if Present (Full_View (Typ))
kono
parents:
diff changeset
2585 and then not Is_Concurrent_Type (Full_View (Typ))
kono
parents:
diff changeset
2586 then
kono
parents:
diff changeset
2587 E := Full_View (Typ);
kono
parents:
diff changeset
2588 else
kono
parents:
diff changeset
2589 E := Typ;
kono
parents:
diff changeset
2590 end if;
kono
parents:
diff changeset
2591
kono
parents:
diff changeset
2592 loop
kono
parents:
diff changeset
2593 if Present (Interfaces (E))
kono
parents:
diff changeset
2594 and then not Is_Empty_Elmt_List (Interfaces (E))
kono
parents:
diff changeset
2595 then
kono
parents:
diff changeset
2596 Elmt := First_Elmt (Interfaces (E));
kono
parents:
diff changeset
2597 while Present (Elmt) loop
kono
parents:
diff changeset
2598 AI := Node (Elmt);
kono
parents:
diff changeset
2599
kono
parents:
diff changeset
2600 if AI = Iface_Typ or else Is_Ancestor (Iface_Typ, AI) then
kono
parents:
diff changeset
2601 return True;
kono
parents:
diff changeset
2602 end if;
kono
parents:
diff changeset
2603
kono
parents:
diff changeset
2604 Next_Elmt (Elmt);
kono
parents:
diff changeset
2605 end loop;
kono
parents:
diff changeset
2606 end if;
kono
parents:
diff changeset
2607
kono
parents:
diff changeset
2608 exit when Etype (E) = E
kono
parents:
diff changeset
2609
kono
parents:
diff changeset
2610 -- Handle private types
kono
parents:
diff changeset
2611
kono
parents:
diff changeset
2612 or else (Present (Full_View (Etype (E)))
kono
parents:
diff changeset
2613 and then Full_View (Etype (E)) = E);
kono
parents:
diff changeset
2614
kono
parents:
diff changeset
2615 -- Check if the current type is a direct derivation of the
kono
parents:
diff changeset
2616 -- interface
kono
parents:
diff changeset
2617
kono
parents:
diff changeset
2618 if Etype (E) = Iface_Typ then
kono
parents:
diff changeset
2619 return True;
kono
parents:
diff changeset
2620 end if;
kono
parents:
diff changeset
2621
kono
parents:
diff changeset
2622 -- Climb to the immediate ancestor handling private types
kono
parents:
diff changeset
2623
kono
parents:
diff changeset
2624 if Present (Full_View (Etype (E))) then
kono
parents:
diff changeset
2625 E := Full_View (Etype (E));
kono
parents:
diff changeset
2626 else
kono
parents:
diff changeset
2627 E := Etype (E);
kono
parents:
diff changeset
2628 end if;
kono
parents:
diff changeset
2629 end loop;
kono
parents:
diff changeset
2630
kono
parents:
diff changeset
2631 return False;
kono
parents:
diff changeset
2632 end Iface_Present_In_Ancestor;
kono
parents:
diff changeset
2633
kono
parents:
diff changeset
2634 -- Start of processing for Interface_Present_In_Ancestor
kono
parents:
diff changeset
2635
kono
parents:
diff changeset
2636 begin
kono
parents:
diff changeset
2637 -- Iface might be a class-wide subtype, so we have to apply Base_Type
kono
parents:
diff changeset
2638
kono
parents:
diff changeset
2639 if Is_Class_Wide_Type (Iface) then
kono
parents:
diff changeset
2640 Iface_Typ := Etype (Base_Type (Iface));
kono
parents:
diff changeset
2641 else
kono
parents:
diff changeset
2642 Iface_Typ := Iface;
kono
parents:
diff changeset
2643 end if;
kono
parents:
diff changeset
2644
kono
parents:
diff changeset
2645 -- Handle subtypes
kono
parents:
diff changeset
2646
kono
parents:
diff changeset
2647 Iface_Typ := Base_Type (Iface_Typ);
kono
parents:
diff changeset
2648
kono
parents:
diff changeset
2649 if Is_Access_Type (Typ) then
kono
parents:
diff changeset
2650 Target_Typ := Etype (Directly_Designated_Type (Typ));
kono
parents:
diff changeset
2651 else
kono
parents:
diff changeset
2652 Target_Typ := Typ;
kono
parents:
diff changeset
2653 end if;
kono
parents:
diff changeset
2654
kono
parents:
diff changeset
2655 if Is_Concurrent_Record_Type (Target_Typ) then
kono
parents:
diff changeset
2656 Target_Typ := Corresponding_Concurrent_Type (Target_Typ);
kono
parents:
diff changeset
2657 end if;
kono
parents:
diff changeset
2658
kono
parents:
diff changeset
2659 Target_Typ := Base_Type (Target_Typ);
kono
parents:
diff changeset
2660
kono
parents:
diff changeset
2661 -- In case of concurrent types we can't use the Corresponding Record_Typ
kono
parents:
diff changeset
2662 -- to look for the interface because it is built by the expander (and
kono
parents:
diff changeset
2663 -- hence it is not always available). For this reason we traverse the
kono
parents:
diff changeset
2664 -- list of interfaces (available in the parent of the concurrent type)
kono
parents:
diff changeset
2665
kono
parents:
diff changeset
2666 if Is_Concurrent_Type (Target_Typ) then
kono
parents:
diff changeset
2667 if Present (Interface_List (Parent (Target_Typ))) then
kono
parents:
diff changeset
2668 declare
kono
parents:
diff changeset
2669 AI : Node_Id;
kono
parents:
diff changeset
2670
kono
parents:
diff changeset
2671 begin
kono
parents:
diff changeset
2672 AI := First (Interface_List (Parent (Target_Typ)));
kono
parents:
diff changeset
2673
kono
parents:
diff changeset
2674 -- The progenitor itself may be a subtype of an interface type.
kono
parents:
diff changeset
2675
kono
parents:
diff changeset
2676 while Present (AI) loop
kono
parents:
diff changeset
2677 if Etype (AI) = Iface_Typ
kono
parents:
diff changeset
2678 or else Base_Type (Etype (AI)) = Iface_Typ
kono
parents:
diff changeset
2679 then
kono
parents:
diff changeset
2680 return True;
kono
parents:
diff changeset
2681
kono
parents:
diff changeset
2682 elsif Present (Interfaces (Etype (AI)))
kono
parents:
diff changeset
2683 and then Iface_Present_In_Ancestor (Etype (AI))
kono
parents:
diff changeset
2684 then
kono
parents:
diff changeset
2685 return True;
kono
parents:
diff changeset
2686 end if;
kono
parents:
diff changeset
2687
kono
parents:
diff changeset
2688 Next (AI);
kono
parents:
diff changeset
2689 end loop;
kono
parents:
diff changeset
2690 end;
kono
parents:
diff changeset
2691 end if;
kono
parents:
diff changeset
2692
kono
parents:
diff changeset
2693 return False;
kono
parents:
diff changeset
2694 end if;
kono
parents:
diff changeset
2695
kono
parents:
diff changeset
2696 if Is_Class_Wide_Type (Target_Typ) then
kono
parents:
diff changeset
2697 Target_Typ := Etype (Target_Typ);
kono
parents:
diff changeset
2698 end if;
kono
parents:
diff changeset
2699
kono
parents:
diff changeset
2700 if Ekind (Target_Typ) = E_Incomplete_Type then
kono
parents:
diff changeset
2701
kono
parents:
diff changeset
2702 -- We must have either a full view or a nonlimited view of the type
kono
parents:
diff changeset
2703 -- to locate the list of ancestors.
kono
parents:
diff changeset
2704
kono
parents:
diff changeset
2705 if Present (Full_View (Target_Typ)) then
kono
parents:
diff changeset
2706 Target_Typ := Full_View (Target_Typ);
kono
parents:
diff changeset
2707 else
kono
parents:
diff changeset
2708 -- In a spec expression or in an expression function, the use of
kono
parents:
diff changeset
2709 -- an incomplete type is legal; legality of the conversion will be
kono
parents:
diff changeset
2710 -- checked at freeze point of related entity.
kono
parents:
diff changeset
2711
kono
parents:
diff changeset
2712 if In_Spec_Expression then
kono
parents:
diff changeset
2713 return True;
kono
parents:
diff changeset
2714
kono
parents:
diff changeset
2715 else
kono
parents:
diff changeset
2716 pragma Assert (Present (Non_Limited_View (Target_Typ)));
kono
parents:
diff changeset
2717 Target_Typ := Non_Limited_View (Target_Typ);
kono
parents:
diff changeset
2718 end if;
kono
parents:
diff changeset
2719 end if;
kono
parents:
diff changeset
2720
kono
parents:
diff changeset
2721 -- Protect the front end against previously detected errors
kono
parents:
diff changeset
2722
kono
parents:
diff changeset
2723 if Ekind (Target_Typ) = E_Incomplete_Type then
kono
parents:
diff changeset
2724 return False;
kono
parents:
diff changeset
2725 end if;
kono
parents:
diff changeset
2726 end if;
kono
parents:
diff changeset
2727
kono
parents:
diff changeset
2728 return Iface_Present_In_Ancestor (Target_Typ);
kono
parents:
diff changeset
2729 end Interface_Present_In_Ancestor;
kono
parents:
diff changeset
2730
kono
parents:
diff changeset
2731 ---------------------
kono
parents:
diff changeset
2732 -- Intersect_Types --
kono
parents:
diff changeset
2733 ---------------------
kono
parents:
diff changeset
2734
kono
parents:
diff changeset
2735 function Intersect_Types (L, R : Node_Id) return Entity_Id is
kono
parents:
diff changeset
2736 Index : Interp_Index;
kono
parents:
diff changeset
2737 It : Interp;
kono
parents:
diff changeset
2738 Typ : Entity_Id;
kono
parents:
diff changeset
2739
kono
parents:
diff changeset
2740 function Check_Right_Argument (T : Entity_Id) return Entity_Id;
kono
parents:
diff changeset
2741 -- Find interpretation of right arg that has type compatible with T
kono
parents:
diff changeset
2742
kono
parents:
diff changeset
2743 --------------------------
kono
parents:
diff changeset
2744 -- Check_Right_Argument --
kono
parents:
diff changeset
2745 --------------------------
kono
parents:
diff changeset
2746
kono
parents:
diff changeset
2747 function Check_Right_Argument (T : Entity_Id) return Entity_Id is
kono
parents:
diff changeset
2748 Index : Interp_Index;
kono
parents:
diff changeset
2749 It : Interp;
kono
parents:
diff changeset
2750 T2 : Entity_Id;
kono
parents:
diff changeset
2751
kono
parents:
diff changeset
2752 begin
kono
parents:
diff changeset
2753 if not Is_Overloaded (R) then
kono
parents:
diff changeset
2754 return Specific_Type (T, Etype (R));
kono
parents:
diff changeset
2755
kono
parents:
diff changeset
2756 else
kono
parents:
diff changeset
2757 Get_First_Interp (R, Index, It);
kono
parents:
diff changeset
2758 loop
kono
parents:
diff changeset
2759 T2 := Specific_Type (T, It.Typ);
kono
parents:
diff changeset
2760
kono
parents:
diff changeset
2761 if T2 /= Any_Type then
kono
parents:
diff changeset
2762 return T2;
kono
parents:
diff changeset
2763 end if;
kono
parents:
diff changeset
2764
kono
parents:
diff changeset
2765 Get_Next_Interp (Index, It);
kono
parents:
diff changeset
2766 exit when No (It.Typ);
kono
parents:
diff changeset
2767 end loop;
kono
parents:
diff changeset
2768
kono
parents:
diff changeset
2769 return Any_Type;
kono
parents:
diff changeset
2770 end if;
kono
parents:
diff changeset
2771 end Check_Right_Argument;
kono
parents:
diff changeset
2772
kono
parents:
diff changeset
2773 -- Start of processing for Intersect_Types
kono
parents:
diff changeset
2774
kono
parents:
diff changeset
2775 begin
kono
parents:
diff changeset
2776 if Etype (L) = Any_Type or else Etype (R) = Any_Type then
kono
parents:
diff changeset
2777 return Any_Type;
kono
parents:
diff changeset
2778 end if;
kono
parents:
diff changeset
2779
kono
parents:
diff changeset
2780 if not Is_Overloaded (L) then
kono
parents:
diff changeset
2781 Typ := Check_Right_Argument (Etype (L));
kono
parents:
diff changeset
2782
kono
parents:
diff changeset
2783 else
kono
parents:
diff changeset
2784 Typ := Any_Type;
kono
parents:
diff changeset
2785 Get_First_Interp (L, Index, It);
kono
parents:
diff changeset
2786 while Present (It.Typ) loop
kono
parents:
diff changeset
2787 Typ := Check_Right_Argument (It.Typ);
kono
parents:
diff changeset
2788 exit when Typ /= Any_Type;
kono
parents:
diff changeset
2789 Get_Next_Interp (Index, It);
kono
parents:
diff changeset
2790 end loop;
kono
parents:
diff changeset
2791
kono
parents:
diff changeset
2792 end if;
kono
parents:
diff changeset
2793
kono
parents:
diff changeset
2794 -- If Typ is Any_Type, it means no compatible pair of types was found
kono
parents:
diff changeset
2795
kono
parents:
diff changeset
2796 if Typ = Any_Type then
kono
parents:
diff changeset
2797 if Nkind (Parent (L)) in N_Op then
kono
parents:
diff changeset
2798 Error_Msg_N ("incompatible types for operator", Parent (L));
kono
parents:
diff changeset
2799
kono
parents:
diff changeset
2800 elsif Nkind (Parent (L)) = N_Range then
kono
parents:
diff changeset
2801 Error_Msg_N ("incompatible types given in constraint", Parent (L));
kono
parents:
diff changeset
2802
kono
parents:
diff changeset
2803 -- Ada 2005 (AI-251): Complete the error notification
kono
parents:
diff changeset
2804
kono
parents:
diff changeset
2805 elsif Is_Class_Wide_Type (Etype (R))
kono
parents:
diff changeset
2806 and then Is_Interface (Etype (Class_Wide_Type (Etype (R))))
kono
parents:
diff changeset
2807 then
kono
parents:
diff changeset
2808 Error_Msg_NE ("(Ada 2005) does not implement interface }",
kono
parents:
diff changeset
2809 L, Etype (Class_Wide_Type (Etype (R))));
kono
parents:
diff changeset
2810
kono
parents:
diff changeset
2811 -- Specialize message if one operand is a limited view, a priori
kono
parents:
diff changeset
2812 -- unrelated to all other types.
kono
parents:
diff changeset
2813
kono
parents:
diff changeset
2814 elsif From_Limited_With (Etype (R)) then
kono
parents:
diff changeset
2815 Error_Msg_NE ("limited view of& not compatible with context",
kono
parents:
diff changeset
2816 R, Etype (R));
kono
parents:
diff changeset
2817
kono
parents:
diff changeset
2818 elsif From_Limited_With (Etype (L)) then
kono
parents:
diff changeset
2819 Error_Msg_NE ("limited view of& not compatible with context",
kono
parents:
diff changeset
2820 L, Etype (L));
kono
parents:
diff changeset
2821 else
kono
parents:
diff changeset
2822 Error_Msg_N ("incompatible types", Parent (L));
kono
parents:
diff changeset
2823 end if;
kono
parents:
diff changeset
2824 end if;
kono
parents:
diff changeset
2825
kono
parents:
diff changeset
2826 return Typ;
kono
parents:
diff changeset
2827 end Intersect_Types;
kono
parents:
diff changeset
2828
kono
parents:
diff changeset
2829 -----------------------
kono
parents:
diff changeset
2830 -- In_Generic_Actual --
kono
parents:
diff changeset
2831 -----------------------
kono
parents:
diff changeset
2832
kono
parents:
diff changeset
2833 function In_Generic_Actual (Exp : Node_Id) return Boolean is
kono
parents:
diff changeset
2834 Par : constant Node_Id := Parent (Exp);
kono
parents:
diff changeset
2835
kono
parents:
diff changeset
2836 begin
kono
parents:
diff changeset
2837 if No (Par) then
kono
parents:
diff changeset
2838 return False;
kono
parents:
diff changeset
2839
kono
parents:
diff changeset
2840 elsif Nkind (Par) in N_Declaration then
kono
parents:
diff changeset
2841 return
kono
parents:
diff changeset
2842 Nkind (Par) = N_Object_Declaration
kono
parents:
diff changeset
2843 and then Present (Corresponding_Generic_Association (Par));
kono
parents:
diff changeset
2844
kono
parents:
diff changeset
2845 elsif Nkind (Par) = N_Object_Renaming_Declaration then
kono
parents:
diff changeset
2846 return Present (Corresponding_Generic_Association (Par));
kono
parents:
diff changeset
2847
kono
parents:
diff changeset
2848 elsif Nkind (Par) in N_Statement_Other_Than_Procedure_Call then
kono
parents:
diff changeset
2849 return False;
kono
parents:
diff changeset
2850
kono
parents:
diff changeset
2851 else
kono
parents:
diff changeset
2852 return In_Generic_Actual (Parent (Par));
kono
parents:
diff changeset
2853 end if;
kono
parents:
diff changeset
2854 end In_Generic_Actual;
kono
parents:
diff changeset
2855
kono
parents:
diff changeset
2856 -----------------
kono
parents:
diff changeset
2857 -- Is_Ancestor --
kono
parents:
diff changeset
2858 -----------------
kono
parents:
diff changeset
2859
kono
parents:
diff changeset
2860 function Is_Ancestor
kono
parents:
diff changeset
2861 (T1 : Entity_Id;
kono
parents:
diff changeset
2862 T2 : Entity_Id;
kono
parents:
diff changeset
2863 Use_Full_View : Boolean := False) return Boolean
kono
parents:
diff changeset
2864 is
kono
parents:
diff changeset
2865 BT1 : Entity_Id;
kono
parents:
diff changeset
2866 BT2 : Entity_Id;
kono
parents:
diff changeset
2867 Par : Entity_Id;
kono
parents:
diff changeset
2868
kono
parents:
diff changeset
2869 begin
kono
parents:
diff changeset
2870 BT1 := Base_Type (T1);
kono
parents:
diff changeset
2871 BT2 := Base_Type (T2);
kono
parents:
diff changeset
2872
kono
parents:
diff changeset
2873 -- Handle underlying view of records with unknown discriminants using
kono
parents:
diff changeset
2874 -- the original entity that motivated the construction of this
kono
parents:
diff changeset
2875 -- underlying record view (see Build_Derived_Private_Type).
kono
parents:
diff changeset
2876
kono
parents:
diff changeset
2877 if Is_Underlying_Record_View (BT1) then
kono
parents:
diff changeset
2878 BT1 := Underlying_Record_View (BT1);
kono
parents:
diff changeset
2879 end if;
kono
parents:
diff changeset
2880
kono
parents:
diff changeset
2881 if Is_Underlying_Record_View (BT2) then
kono
parents:
diff changeset
2882 BT2 := Underlying_Record_View (BT2);
kono
parents:
diff changeset
2883 end if;
kono
parents:
diff changeset
2884
kono
parents:
diff changeset
2885 if BT1 = BT2 then
kono
parents:
diff changeset
2886 return True;
kono
parents:
diff changeset
2887
kono
parents:
diff changeset
2888 -- The predicate must look past privacy
kono
parents:
diff changeset
2889
kono
parents:
diff changeset
2890 elsif Is_Private_Type (T1)
kono
parents:
diff changeset
2891 and then Present (Full_View (T1))
kono
parents:
diff changeset
2892 and then BT2 = Base_Type (Full_View (T1))
kono
parents:
diff changeset
2893 then
kono
parents:
diff changeset
2894 return True;
kono
parents:
diff changeset
2895
kono
parents:
diff changeset
2896 elsif Is_Private_Type (T2)
kono
parents:
diff changeset
2897 and then Present (Full_View (T2))
kono
parents:
diff changeset
2898 and then BT1 = Base_Type (Full_View (T2))
kono
parents:
diff changeset
2899 then
kono
parents:
diff changeset
2900 return True;
kono
parents:
diff changeset
2901
kono
parents:
diff changeset
2902 else
kono
parents:
diff changeset
2903 -- Obtain the parent of the base type of T2 (use the full view if
kono
parents:
diff changeset
2904 -- allowed).
kono
parents:
diff changeset
2905
kono
parents:
diff changeset
2906 if Use_Full_View
kono
parents:
diff changeset
2907 and then Is_Private_Type (BT2)
kono
parents:
diff changeset
2908 and then Present (Full_View (BT2))
kono
parents:
diff changeset
2909 then
kono
parents:
diff changeset
2910 -- No climbing needed if its full view is the root type
kono
parents:
diff changeset
2911
kono
parents:
diff changeset
2912 if Full_View (BT2) = Root_Type (Full_View (BT2)) then
kono
parents:
diff changeset
2913 return False;
kono
parents:
diff changeset
2914 end if;
kono
parents:
diff changeset
2915
kono
parents:
diff changeset
2916 Par := Etype (Full_View (BT2));
kono
parents:
diff changeset
2917
kono
parents:
diff changeset
2918 else
kono
parents:
diff changeset
2919 Par := Etype (BT2);
kono
parents:
diff changeset
2920 end if;
kono
parents:
diff changeset
2921
kono
parents:
diff changeset
2922 loop
kono
parents:
diff changeset
2923 -- If there was a error on the type declaration, do not recurse
kono
parents:
diff changeset
2924
kono
parents:
diff changeset
2925 if Error_Posted (Par) then
kono
parents:
diff changeset
2926 return False;
kono
parents:
diff changeset
2927
kono
parents:
diff changeset
2928 elsif BT1 = Base_Type (Par)
kono
parents:
diff changeset
2929 or else (Is_Private_Type (T1)
kono
parents:
diff changeset
2930 and then Present (Full_View (T1))
kono
parents:
diff changeset
2931 and then Base_Type (Par) = Base_Type (Full_View (T1)))
kono
parents:
diff changeset
2932 then
kono
parents:
diff changeset
2933 return True;
kono
parents:
diff changeset
2934
kono
parents:
diff changeset
2935 elsif Is_Private_Type (Par)
kono
parents:
diff changeset
2936 and then Present (Full_View (Par))
kono
parents:
diff changeset
2937 and then Full_View (Par) = BT1
kono
parents:
diff changeset
2938 then
kono
parents:
diff changeset
2939 return True;
kono
parents:
diff changeset
2940
kono
parents:
diff changeset
2941 -- Root type found
kono
parents:
diff changeset
2942
kono
parents:
diff changeset
2943 elsif Par = Root_Type (Par) then
kono
parents:
diff changeset
2944 return False;
kono
parents:
diff changeset
2945
kono
parents:
diff changeset
2946 -- Continue climbing
kono
parents:
diff changeset
2947
kono
parents:
diff changeset
2948 else
kono
parents:
diff changeset
2949 -- Use the full-view of private types (if allowed). Guard
kono
parents:
diff changeset
2950 -- against infinite loops when full view has same type as
kono
parents:
diff changeset
2951 -- parent, as can happen with interface extensions.
kono
parents:
diff changeset
2952
kono
parents:
diff changeset
2953 if Use_Full_View
kono
parents:
diff changeset
2954 and then Is_Private_Type (Par)
kono
parents:
diff changeset
2955 and then Present (Full_View (Par))
kono
parents:
diff changeset
2956 and then Par /= Etype (Full_View (Par))
kono
parents:
diff changeset
2957 then
kono
parents:
diff changeset
2958 Par := Etype (Full_View (Par));
kono
parents:
diff changeset
2959 else
kono
parents:
diff changeset
2960 Par := Etype (Par);
kono
parents:
diff changeset
2961 end if;
kono
parents:
diff changeset
2962 end if;
kono
parents:
diff changeset
2963 end loop;
kono
parents:
diff changeset
2964 end if;
kono
parents:
diff changeset
2965 end Is_Ancestor;
kono
parents:
diff changeset
2966
kono
parents:
diff changeset
2967 ---------------------------
kono
parents:
diff changeset
2968 -- Is_Invisible_Operator --
kono
parents:
diff changeset
2969 ---------------------------
kono
parents:
diff changeset
2970
kono
parents:
diff changeset
2971 function Is_Invisible_Operator
kono
parents:
diff changeset
2972 (N : Node_Id;
kono
parents:
diff changeset
2973 T : Entity_Id) return Boolean
kono
parents:
diff changeset
2974 is
kono
parents:
diff changeset
2975 Orig_Node : constant Node_Id := Original_Node (N);
kono
parents:
diff changeset
2976
kono
parents:
diff changeset
2977 begin
kono
parents:
diff changeset
2978 if Nkind (N) not in N_Op then
kono
parents:
diff changeset
2979 return False;
kono
parents:
diff changeset
2980
kono
parents:
diff changeset
2981 elsif not Comes_From_Source (N) then
kono
parents:
diff changeset
2982 return False;
kono
parents:
diff changeset
2983
kono
parents:
diff changeset
2984 elsif No (Universal_Interpretation (Right_Opnd (N))) then
kono
parents:
diff changeset
2985 return False;
kono
parents:
diff changeset
2986
kono
parents:
diff changeset
2987 elsif Nkind (N) in N_Binary_Op
kono
parents:
diff changeset
2988 and then No (Universal_Interpretation (Left_Opnd (N)))
kono
parents:
diff changeset
2989 then
kono
parents:
diff changeset
2990 return False;
kono
parents:
diff changeset
2991
kono
parents:
diff changeset
2992 else
kono
parents:
diff changeset
2993 return Is_Numeric_Type (T)
kono
parents:
diff changeset
2994 and then not In_Open_Scopes (Scope (T))
kono
parents:
diff changeset
2995 and then not Is_Potentially_Use_Visible (T)
kono
parents:
diff changeset
2996 and then not In_Use (T)
kono
parents:
diff changeset
2997 and then not In_Use (Scope (T))
kono
parents:
diff changeset
2998 and then
kono
parents:
diff changeset
2999 (Nkind (Orig_Node) /= N_Function_Call
kono
parents:
diff changeset
3000 or else Nkind (Name (Orig_Node)) /= N_Expanded_Name
kono
parents:
diff changeset
3001 or else Entity (Prefix (Name (Orig_Node))) /= Scope (T))
kono
parents:
diff changeset
3002 and then not In_Instance;
kono
parents:
diff changeset
3003 end if;
kono
parents:
diff changeset
3004 end Is_Invisible_Operator;
kono
parents:
diff changeset
3005
kono
parents:
diff changeset
3006 --------------------
kono
parents:
diff changeset
3007 -- Is_Progenitor --
kono
parents:
diff changeset
3008 --------------------
kono
parents:
diff changeset
3009
kono
parents:
diff changeset
3010 function Is_Progenitor
kono
parents:
diff changeset
3011 (Iface : Entity_Id;
kono
parents:
diff changeset
3012 Typ : Entity_Id) return Boolean
kono
parents:
diff changeset
3013 is
kono
parents:
diff changeset
3014 begin
kono
parents:
diff changeset
3015 return Implements_Interface (Typ, Iface, Exclude_Parents => True);
kono
parents:
diff changeset
3016 end Is_Progenitor;
kono
parents:
diff changeset
3017
kono
parents:
diff changeset
3018 -------------------
kono
parents:
diff changeset
3019 -- Is_Subtype_Of --
kono
parents:
diff changeset
3020 -------------------
kono
parents:
diff changeset
3021
kono
parents:
diff changeset
3022 function Is_Subtype_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
kono
parents:
diff changeset
3023 S : Entity_Id;
kono
parents:
diff changeset
3024
kono
parents:
diff changeset
3025 begin
kono
parents:
diff changeset
3026 S := Ancestor_Subtype (T1);
kono
parents:
diff changeset
3027 while Present (S) loop
kono
parents:
diff changeset
3028 if S = T2 then
kono
parents:
diff changeset
3029 return True;
kono
parents:
diff changeset
3030 else
kono
parents:
diff changeset
3031 S := Ancestor_Subtype (S);
kono
parents:
diff changeset
3032 end if;
kono
parents:
diff changeset
3033 end loop;
kono
parents:
diff changeset
3034
kono
parents:
diff changeset
3035 return False;
kono
parents:
diff changeset
3036 end Is_Subtype_Of;
kono
parents:
diff changeset
3037
kono
parents:
diff changeset
3038 ------------------
kono
parents:
diff changeset
3039 -- List_Interps --
kono
parents:
diff changeset
3040 ------------------
kono
parents:
diff changeset
3041
kono
parents:
diff changeset
3042 procedure List_Interps (Nam : Node_Id; Err : Node_Id) is
kono
parents:
diff changeset
3043 Index : Interp_Index;
kono
parents:
diff changeset
3044 It : Interp;
kono
parents:
diff changeset
3045
kono
parents:
diff changeset
3046 begin
kono
parents:
diff changeset
3047 Get_First_Interp (Nam, Index, It);
kono
parents:
diff changeset
3048 while Present (It.Nam) loop
kono
parents:
diff changeset
3049 if Scope (It.Nam) = Standard_Standard
kono
parents:
diff changeset
3050 and then Scope (It.Typ) /= Standard_Standard
kono
parents:
diff changeset
3051 then
kono
parents:
diff changeset
3052 Error_Msg_Sloc := Sloc (Parent (It.Typ));
kono
parents:
diff changeset
3053 Error_Msg_NE ("\\& (inherited) declared#!", Err, It.Nam);
kono
parents:
diff changeset
3054
kono
parents:
diff changeset
3055 else
kono
parents:
diff changeset
3056 Error_Msg_Sloc := Sloc (It.Nam);
kono
parents:
diff changeset
3057 Error_Msg_NE ("\\& declared#!", Err, It.Nam);
kono
parents:
diff changeset
3058 end if;
kono
parents:
diff changeset
3059
kono
parents:
diff changeset
3060 Get_Next_Interp (Index, It);
kono
parents:
diff changeset
3061 end loop;
kono
parents:
diff changeset
3062 end List_Interps;
kono
parents:
diff changeset
3063
kono
parents:
diff changeset
3064 -----------------
kono
parents:
diff changeset
3065 -- New_Interps --
kono
parents:
diff changeset
3066 -----------------
kono
parents:
diff changeset
3067
kono
parents:
diff changeset
3068 procedure New_Interps (N : Node_Id) is
kono
parents:
diff changeset
3069 Map_Ptr : Int;
kono
parents:
diff changeset
3070
kono
parents:
diff changeset
3071 begin
kono
parents:
diff changeset
3072 All_Interp.Append (No_Interp);
kono
parents:
diff changeset
3073
kono
parents:
diff changeset
3074 Map_Ptr := Headers (Hash (N));
kono
parents:
diff changeset
3075
kono
parents:
diff changeset
3076 if Map_Ptr = No_Entry then
kono
parents:
diff changeset
3077
kono
parents:
diff changeset
3078 -- Place new node at end of table
kono
parents:
diff changeset
3079
kono
parents:
diff changeset
3080 Interp_Map.Increment_Last;
kono
parents:
diff changeset
3081 Headers (Hash (N)) := Interp_Map.Last;
kono
parents:
diff changeset
3082
kono
parents:
diff changeset
3083 else
kono
parents:
diff changeset
3084 -- Place node at end of chain, or locate its previous entry
kono
parents:
diff changeset
3085
kono
parents:
diff changeset
3086 loop
kono
parents:
diff changeset
3087 if Interp_Map.Table (Map_Ptr).Node = N then
kono
parents:
diff changeset
3088
kono
parents:
diff changeset
3089 -- Node is already in the table, and is being rewritten.
kono
parents:
diff changeset
3090 -- Start a new interp section, retain hash link.
kono
parents:
diff changeset
3091
kono
parents:
diff changeset
3092 Interp_Map.Table (Map_Ptr).Node := N;
kono
parents:
diff changeset
3093 Interp_Map.Table (Map_Ptr).Index := All_Interp.Last;
kono
parents:
diff changeset
3094 Set_Is_Overloaded (N, True);
kono
parents:
diff changeset
3095 return;
kono
parents:
diff changeset
3096
kono
parents:
diff changeset
3097 else
kono
parents:
diff changeset
3098 exit when Interp_Map.Table (Map_Ptr).Next = No_Entry;
kono
parents:
diff changeset
3099 Map_Ptr := Interp_Map.Table (Map_Ptr).Next;
kono
parents:
diff changeset
3100 end if;
kono
parents:
diff changeset
3101 end loop;
kono
parents:
diff changeset
3102
kono
parents:
diff changeset
3103 -- Chain the new node
kono
parents:
diff changeset
3104
kono
parents:
diff changeset
3105 Interp_Map.Increment_Last;
kono
parents:
diff changeset
3106 Interp_Map.Table (Map_Ptr).Next := Interp_Map.Last;
kono
parents:
diff changeset
3107 end if;
kono
parents:
diff changeset
3108
kono
parents:
diff changeset
3109 Interp_Map.Table (Interp_Map.Last) := (N, All_Interp.Last, No_Entry);
kono
parents:
diff changeset
3110 Set_Is_Overloaded (N, True);
kono
parents:
diff changeset
3111 end New_Interps;
kono
parents:
diff changeset
3112
kono
parents:
diff changeset
3113 ---------------------------
kono
parents:
diff changeset
3114 -- Operator_Matches_Spec --
kono
parents:
diff changeset
3115 ---------------------------
kono
parents:
diff changeset
3116
kono
parents:
diff changeset
3117 function Operator_Matches_Spec (Op, New_S : Entity_Id) return Boolean is
kono
parents:
diff changeset
3118 New_First_F : constant Entity_Id := First_Formal (New_S);
kono
parents:
diff changeset
3119 Op_Name : constant Name_Id := Chars (Op);
kono
parents:
diff changeset
3120 T : constant Entity_Id := Etype (New_S);
kono
parents:
diff changeset
3121 New_F : Entity_Id;
kono
parents:
diff changeset
3122 Num : Nat;
kono
parents:
diff changeset
3123 Old_F : Entity_Id;
kono
parents:
diff changeset
3124 T1 : Entity_Id;
kono
parents:
diff changeset
3125 T2 : Entity_Id;
kono
parents:
diff changeset
3126
kono
parents:
diff changeset
3127 begin
kono
parents:
diff changeset
3128 -- To verify that a predefined operator matches a given signature, do a
kono
parents:
diff changeset
3129 -- case analysis of the operator classes. Function can have one or two
kono
parents:
diff changeset
3130 -- formals and must have the proper result type.
kono
parents:
diff changeset
3131
kono
parents:
diff changeset
3132 New_F := New_First_F;
kono
parents:
diff changeset
3133 Old_F := First_Formal (Op);
kono
parents:
diff changeset
3134 Num := 0;
kono
parents:
diff changeset
3135 while Present (New_F) and then Present (Old_F) loop
kono
parents:
diff changeset
3136 Num := Num + 1;
kono
parents:
diff changeset
3137 Next_Formal (New_F);
kono
parents:
diff changeset
3138 Next_Formal (Old_F);
kono
parents:
diff changeset
3139 end loop;
kono
parents:
diff changeset
3140
kono
parents:
diff changeset
3141 -- Definite mismatch if different number of parameters
kono
parents:
diff changeset
3142
kono
parents:
diff changeset
3143 if Present (Old_F) or else Present (New_F) then
kono
parents:
diff changeset
3144 return False;
kono
parents:
diff changeset
3145
kono
parents:
diff changeset
3146 -- Unary operators
kono
parents:
diff changeset
3147
kono
parents:
diff changeset
3148 elsif Num = 1 then
kono
parents:
diff changeset
3149 T1 := Etype (New_First_F);
kono
parents:
diff changeset
3150
kono
parents:
diff changeset
3151 if Nam_In (Op_Name, Name_Op_Subtract, Name_Op_Add, Name_Op_Abs) then
kono
parents:
diff changeset
3152 return Base_Type (T1) = Base_Type (T)
kono
parents:
diff changeset
3153 and then Is_Numeric_Type (T);
kono
parents:
diff changeset
3154
kono
parents:
diff changeset
3155 elsif Op_Name = Name_Op_Not then
kono
parents:
diff changeset
3156 return Base_Type (T1) = Base_Type (T)
kono
parents:
diff changeset
3157 and then Valid_Boolean_Arg (Base_Type (T));
kono
parents:
diff changeset
3158
kono
parents:
diff changeset
3159 else
kono
parents:
diff changeset
3160 return False;
kono
parents:
diff changeset
3161 end if;
kono
parents:
diff changeset
3162
kono
parents:
diff changeset
3163 -- Binary operators
kono
parents:
diff changeset
3164
kono
parents:
diff changeset
3165 else
kono
parents:
diff changeset
3166 T1 := Etype (New_First_F);
kono
parents:
diff changeset
3167 T2 := Etype (Next_Formal (New_First_F));
kono
parents:
diff changeset
3168
kono
parents:
diff changeset
3169 if Nam_In (Op_Name, Name_Op_And, Name_Op_Or, Name_Op_Xor) then
kono
parents:
diff changeset
3170 return Base_Type (T1) = Base_Type (T2)
kono
parents:
diff changeset
3171 and then Base_Type (T1) = Base_Type (T)
kono
parents:
diff changeset
3172 and then Valid_Boolean_Arg (Base_Type (T));
kono
parents:
diff changeset
3173
kono
parents:
diff changeset
3174 elsif Nam_In (Op_Name, Name_Op_Eq, Name_Op_Ne) then
kono
parents:
diff changeset
3175 return Base_Type (T1) = Base_Type (T2)
kono
parents:
diff changeset
3176 and then not Is_Limited_Type (T1)
kono
parents:
diff changeset
3177 and then Is_Boolean_Type (T);
kono
parents:
diff changeset
3178
kono
parents:
diff changeset
3179 elsif Nam_In (Op_Name, Name_Op_Lt, Name_Op_Le,
kono
parents:
diff changeset
3180 Name_Op_Gt, Name_Op_Ge)
kono
parents:
diff changeset
3181 then
kono
parents:
diff changeset
3182 return Base_Type (T1) = Base_Type (T2)
kono
parents:
diff changeset
3183 and then Valid_Comparison_Arg (T1)
kono
parents:
diff changeset
3184 and then Is_Boolean_Type (T);
kono
parents:
diff changeset
3185
kono
parents:
diff changeset
3186 elsif Nam_In (Op_Name, Name_Op_Add, Name_Op_Subtract) then
kono
parents:
diff changeset
3187 return Base_Type (T1) = Base_Type (T2)
kono
parents:
diff changeset
3188 and then Base_Type (T1) = Base_Type (T)
kono
parents:
diff changeset
3189 and then Is_Numeric_Type (T);
kono
parents:
diff changeset
3190
kono
parents:
diff changeset
3191 -- For division and multiplication, a user-defined function does not
kono
parents:
diff changeset
3192 -- match the predefined universal_fixed operation, except in Ada 83.
kono
parents:
diff changeset
3193
kono
parents:
diff changeset
3194 elsif Op_Name = Name_Op_Divide then
kono
parents:
diff changeset
3195 return (Base_Type (T1) = Base_Type (T2)
kono
parents:
diff changeset
3196 and then Base_Type (T1) = Base_Type (T)
kono
parents:
diff changeset
3197 and then Is_Numeric_Type (T)
kono
parents:
diff changeset
3198 and then (not Is_Fixed_Point_Type (T)
kono
parents:
diff changeset
3199 or else Ada_Version = Ada_83))
kono
parents:
diff changeset
3200
kono
parents:
diff changeset
3201 -- Mixed_Mode operations on fixed-point types
kono
parents:
diff changeset
3202
kono
parents:
diff changeset
3203 or else (Base_Type (T1) = Base_Type (T)
kono
parents:
diff changeset
3204 and then Base_Type (T2) = Base_Type (Standard_Integer)
kono
parents:
diff changeset
3205 and then Is_Fixed_Point_Type (T))
kono
parents:
diff changeset
3206
kono
parents:
diff changeset
3207 -- A user defined operator can also match (and hide) a mixed
kono
parents:
diff changeset
3208 -- operation on universal literals.
kono
parents:
diff changeset
3209
kono
parents:
diff changeset
3210 or else (Is_Integer_Type (T2)
kono
parents:
diff changeset
3211 and then Is_Floating_Point_Type (T1)
kono
parents:
diff changeset
3212 and then Base_Type (T1) = Base_Type (T));
kono
parents:
diff changeset
3213
kono
parents:
diff changeset
3214 elsif Op_Name = Name_Op_Multiply then
kono
parents:
diff changeset
3215 return (Base_Type (T1) = Base_Type (T2)
kono
parents:
diff changeset
3216 and then Base_Type (T1) = Base_Type (T)
kono
parents:
diff changeset
3217 and then Is_Numeric_Type (T)
kono
parents:
diff changeset
3218 and then (not Is_Fixed_Point_Type (T)
kono
parents:
diff changeset
3219 or else Ada_Version = Ada_83))
kono
parents:
diff changeset
3220
kono
parents:
diff changeset
3221 -- Mixed_Mode operations on fixed-point types
kono
parents:
diff changeset
3222
kono
parents:
diff changeset
3223 or else (Base_Type (T1) = Base_Type (T)
kono
parents:
diff changeset
3224 and then Base_Type (T2) = Base_Type (Standard_Integer)
kono
parents:
diff changeset
3225 and then Is_Fixed_Point_Type (T))
kono
parents:
diff changeset
3226
kono
parents:
diff changeset
3227 or else (Base_Type (T2) = Base_Type (T)
kono
parents:
diff changeset
3228 and then Base_Type (T1) = Base_Type (Standard_Integer)
kono
parents:
diff changeset
3229 and then Is_Fixed_Point_Type (T))
kono
parents:
diff changeset
3230
kono
parents:
diff changeset
3231 or else (Is_Integer_Type (T2)
kono
parents:
diff changeset
3232 and then Is_Floating_Point_Type (T1)
kono
parents:
diff changeset
3233 and then Base_Type (T1) = Base_Type (T))
kono
parents:
diff changeset
3234
kono
parents:
diff changeset
3235 or else (Is_Integer_Type (T1)
kono
parents:
diff changeset
3236 and then Is_Floating_Point_Type (T2)
kono
parents:
diff changeset
3237 and then Base_Type (T2) = Base_Type (T));
kono
parents:
diff changeset
3238
kono
parents:
diff changeset
3239 elsif Nam_In (Op_Name, Name_Op_Mod, Name_Op_Rem) then
kono
parents:
diff changeset
3240 return Base_Type (T1) = Base_Type (T2)
kono
parents:
diff changeset
3241 and then Base_Type (T1) = Base_Type (T)
kono
parents:
diff changeset
3242 and then Is_Integer_Type (T);
kono
parents:
diff changeset
3243
kono
parents:
diff changeset
3244 elsif Op_Name = Name_Op_Expon then
kono
parents:
diff changeset
3245 return Base_Type (T1) = Base_Type (T)
kono
parents:
diff changeset
3246 and then Is_Numeric_Type (T)
kono
parents:
diff changeset
3247 and then Base_Type (T2) = Base_Type (Standard_Integer);
kono
parents:
diff changeset
3248
kono
parents:
diff changeset
3249 elsif Op_Name = Name_Op_Concat then
kono
parents:
diff changeset
3250 return Is_Array_Type (T)
kono
parents:
diff changeset
3251 and then (Base_Type (T) = Base_Type (Etype (Op)))
kono
parents:
diff changeset
3252 and then (Base_Type (T1) = Base_Type (T)
kono
parents:
diff changeset
3253 or else
kono
parents:
diff changeset
3254 Base_Type (T1) = Base_Type (Component_Type (T)))
kono
parents:
diff changeset
3255 and then (Base_Type (T2) = Base_Type (T)
kono
parents:
diff changeset
3256 or else
kono
parents:
diff changeset
3257 Base_Type (T2) = Base_Type (Component_Type (T)));
kono
parents:
diff changeset
3258
kono
parents:
diff changeset
3259 else
kono
parents:
diff changeset
3260 return False;
kono
parents:
diff changeset
3261 end if;
kono
parents:
diff changeset
3262 end if;
kono
parents:
diff changeset
3263 end Operator_Matches_Spec;
kono
parents:
diff changeset
3264
kono
parents:
diff changeset
3265 -------------------
kono
parents:
diff changeset
3266 -- Remove_Interp --
kono
parents:
diff changeset
3267 -------------------
kono
parents:
diff changeset
3268
kono
parents:
diff changeset
3269 procedure Remove_Interp (I : in out Interp_Index) is
kono
parents:
diff changeset
3270 II : Interp_Index;
kono
parents:
diff changeset
3271
kono
parents:
diff changeset
3272 begin
kono
parents:
diff changeset
3273 -- Find end of interp list and copy downward to erase the discarded one
kono
parents:
diff changeset
3274
kono
parents:
diff changeset
3275 II := I + 1;
kono
parents:
diff changeset
3276 while Present (All_Interp.Table (II).Typ) loop
kono
parents:
diff changeset
3277 II := II + 1;
kono
parents:
diff changeset
3278 end loop;
kono
parents:
diff changeset
3279
kono
parents:
diff changeset
3280 for J in I + 1 .. II loop
kono
parents:
diff changeset
3281 All_Interp.Table (J - 1) := All_Interp.Table (J);
kono
parents:
diff changeset
3282 end loop;
kono
parents:
diff changeset
3283
kono
parents:
diff changeset
3284 -- Back up interp index to insure that iterator will pick up next
kono
parents:
diff changeset
3285 -- available interpretation.
kono
parents:
diff changeset
3286
kono
parents:
diff changeset
3287 I := I - 1;
kono
parents:
diff changeset
3288 end Remove_Interp;
kono
parents:
diff changeset
3289
kono
parents:
diff changeset
3290 ------------------
kono
parents:
diff changeset
3291 -- Save_Interps --
kono
parents:
diff changeset
3292 ------------------
kono
parents:
diff changeset
3293
kono
parents:
diff changeset
3294 procedure Save_Interps (Old_N : Node_Id; New_N : Node_Id) is
kono
parents:
diff changeset
3295 Map_Ptr : Int;
kono
parents:
diff changeset
3296 O_N : Node_Id := Old_N;
kono
parents:
diff changeset
3297
kono
parents:
diff changeset
3298 begin
kono
parents:
diff changeset
3299 if Is_Overloaded (Old_N) then
kono
parents:
diff changeset
3300 Set_Is_Overloaded (New_N);
kono
parents:
diff changeset
3301
kono
parents:
diff changeset
3302 if Nkind (Old_N) = N_Selected_Component
kono
parents:
diff changeset
3303 and then Is_Overloaded (Selector_Name (Old_N))
kono
parents:
diff changeset
3304 then
kono
parents:
diff changeset
3305 O_N := Selector_Name (Old_N);
kono
parents:
diff changeset
3306 end if;
kono
parents:
diff changeset
3307
kono
parents:
diff changeset
3308 Map_Ptr := Headers (Hash (O_N));
kono
parents:
diff changeset
3309
kono
parents:
diff changeset
3310 while Interp_Map.Table (Map_Ptr).Node /= O_N loop
kono
parents:
diff changeset
3311 Map_Ptr := Interp_Map.Table (Map_Ptr).Next;
kono
parents:
diff changeset
3312 pragma Assert (Map_Ptr /= No_Entry);
kono
parents:
diff changeset
3313 end loop;
kono
parents:
diff changeset
3314
kono
parents:
diff changeset
3315 New_Interps (New_N);
kono
parents:
diff changeset
3316 Interp_Map.Table (Interp_Map.Last).Index :=
kono
parents:
diff changeset
3317 Interp_Map.Table (Map_Ptr).Index;
kono
parents:
diff changeset
3318 end if;
kono
parents:
diff changeset
3319 end Save_Interps;
kono
parents:
diff changeset
3320
kono
parents:
diff changeset
3321 -------------------
kono
parents:
diff changeset
3322 -- Specific_Type --
kono
parents:
diff changeset
3323 -------------------
kono
parents:
diff changeset
3324
kono
parents:
diff changeset
3325 function Specific_Type (Typ_1, Typ_2 : Entity_Id) return Entity_Id is
kono
parents:
diff changeset
3326 T1 : constant Entity_Id := Available_View (Typ_1);
kono
parents:
diff changeset
3327 T2 : constant Entity_Id := Available_View (Typ_2);
kono
parents:
diff changeset
3328 B1 : constant Entity_Id := Base_Type (T1);
kono
parents:
diff changeset
3329 B2 : constant Entity_Id := Base_Type (T2);
kono
parents:
diff changeset
3330
kono
parents:
diff changeset
3331 function Is_Remote_Access (T : Entity_Id) return Boolean;
kono
parents:
diff changeset
3332 -- Check whether T is the equivalent type of a remote access type.
kono
parents:
diff changeset
3333 -- If distribution is enabled, T is a legal context for Null.
kono
parents:
diff changeset
3334
kono
parents:
diff changeset
3335 ----------------------
kono
parents:
diff changeset
3336 -- Is_Remote_Access --
kono
parents:
diff changeset
3337 ----------------------
kono
parents:
diff changeset
3338
kono
parents:
diff changeset
3339 function Is_Remote_Access (T : Entity_Id) return Boolean is
kono
parents:
diff changeset
3340 begin
kono
parents:
diff changeset
3341 return Is_Record_Type (T)
kono
parents:
diff changeset
3342 and then (Is_Remote_Call_Interface (T)
kono
parents:
diff changeset
3343 or else Is_Remote_Types (T))
kono
parents:
diff changeset
3344 and then Present (Corresponding_Remote_Type (T))
kono
parents:
diff changeset
3345 and then Is_Access_Type (Corresponding_Remote_Type (T));
kono
parents:
diff changeset
3346 end Is_Remote_Access;
kono
parents:
diff changeset
3347
kono
parents:
diff changeset
3348 -- Start of processing for Specific_Type
kono
parents:
diff changeset
3349
kono
parents:
diff changeset
3350 begin
kono
parents:
diff changeset
3351 if T1 = Any_Type or else T2 = Any_Type then
kono
parents:
diff changeset
3352 return Any_Type;
kono
parents:
diff changeset
3353 end if;
kono
parents:
diff changeset
3354
kono
parents:
diff changeset
3355 if B1 = B2 then
kono
parents:
diff changeset
3356 return B1;
kono
parents:
diff changeset
3357
kono
parents:
diff changeset
3358 elsif (T1 = Universal_Integer and then Is_Integer_Type (T2))
kono
parents:
diff changeset
3359 or else (T1 = Universal_Real and then Is_Real_Type (T2))
kono
parents:
diff changeset
3360 or else (T1 = Universal_Fixed and then Is_Fixed_Point_Type (T2))
kono
parents:
diff changeset
3361 or else (T1 = Any_Fixed and then Is_Fixed_Point_Type (T2))
kono
parents:
diff changeset
3362 then
kono
parents:
diff changeset
3363 return B2;
kono
parents:
diff changeset
3364
kono
parents:
diff changeset
3365 elsif (T2 = Universal_Integer and then Is_Integer_Type (T1))
kono
parents:
diff changeset
3366 or else (T2 = Universal_Real and then Is_Real_Type (T1))
kono
parents:
diff changeset
3367 or else (T2 = Universal_Fixed and then Is_Fixed_Point_Type (T1))
kono
parents:
diff changeset
3368 or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
kono
parents:
diff changeset
3369 then
kono
parents:
diff changeset
3370 return B1;
kono
parents:
diff changeset
3371
kono
parents:
diff changeset
3372 elsif T2 = Any_String and then Is_String_Type (T1) then
kono
parents:
diff changeset
3373 return B1;
kono
parents:
diff changeset
3374
kono
parents:
diff changeset
3375 elsif T1 = Any_String and then Is_String_Type (T2) then
kono
parents:
diff changeset
3376 return B2;
kono
parents:
diff changeset
3377
kono
parents:
diff changeset
3378 elsif T2 = Any_Character and then Is_Character_Type (T1) then
kono
parents:
diff changeset
3379 return B1;
kono
parents:
diff changeset
3380
kono
parents:
diff changeset
3381 elsif T1 = Any_Character and then Is_Character_Type (T2) then
kono
parents:
diff changeset
3382 return B2;
kono
parents:
diff changeset
3383
kono
parents:
diff changeset
3384 elsif T1 = Any_Access
kono
parents:
diff changeset
3385 and then (Is_Access_Type (T2) or else Is_Remote_Access (T2))
kono
parents:
diff changeset
3386 then
kono
parents:
diff changeset
3387 return T2;
kono
parents:
diff changeset
3388
kono
parents:
diff changeset
3389 elsif T2 = Any_Access
kono
parents:
diff changeset
3390 and then (Is_Access_Type (T1) or else Is_Remote_Access (T1))
kono
parents:
diff changeset
3391 then
kono
parents:
diff changeset
3392 return T1;
kono
parents:
diff changeset
3393
kono
parents:
diff changeset
3394 -- In an instance, the specific type may have a private view. Use full
kono
parents:
diff changeset
3395 -- view to check legality.
kono
parents:
diff changeset
3396
kono
parents:
diff changeset
3397 elsif T2 = Any_Access
kono
parents:
diff changeset
3398 and then Is_Private_Type (T1)
kono
parents:
diff changeset
3399 and then Present (Full_View (T1))
kono
parents:
diff changeset
3400 and then Is_Access_Type (Full_View (T1))
kono
parents:
diff changeset
3401 and then In_Instance
kono
parents:
diff changeset
3402 then
kono
parents:
diff changeset
3403 return T1;
kono
parents:
diff changeset
3404
kono
parents:
diff changeset
3405 elsif T2 = Any_Composite and then Is_Aggregate_Type (T1) then
kono
parents:
diff changeset
3406 return T1;
kono
parents:
diff changeset
3407
kono
parents:
diff changeset
3408 elsif T1 = Any_Composite and then Is_Aggregate_Type (T2) then
kono
parents:
diff changeset
3409 return T2;
kono
parents:
diff changeset
3410
kono
parents:
diff changeset
3411 elsif T1 = Any_Modular and then Is_Modular_Integer_Type (T2) then
kono
parents:
diff changeset
3412 return T2;
kono
parents:
diff changeset
3413
kono
parents:
diff changeset
3414 elsif T2 = Any_Modular and then Is_Modular_Integer_Type (T1) then
kono
parents:
diff changeset
3415 return T1;
kono
parents:
diff changeset
3416
kono
parents:
diff changeset
3417 -- ----------------------------------------------------------
kono
parents:
diff changeset
3418 -- Special cases for equality operators (all other predefined
kono
parents:
diff changeset
3419 -- operators can never apply to tagged types)
kono
parents:
diff changeset
3420 -- ----------------------------------------------------------
kono
parents:
diff changeset
3421
kono
parents:
diff changeset
3422 -- Ada 2005 (AI-251): T1 and T2 are class-wide types, and T2 is an
kono
parents:
diff changeset
3423 -- interface
kono
parents:
diff changeset
3424
kono
parents:
diff changeset
3425 elsif Is_Class_Wide_Type (T1)
kono
parents:
diff changeset
3426 and then Is_Class_Wide_Type (T2)
kono
parents:
diff changeset
3427 and then Is_Interface (Etype (T2))
kono
parents:
diff changeset
3428 then
kono
parents:
diff changeset
3429 return T1;
kono
parents:
diff changeset
3430
kono
parents:
diff changeset
3431 -- Ada 2005 (AI-251): T1 is a concrete type that implements the
kono
parents:
diff changeset
3432 -- class-wide interface T2
kono
parents:
diff changeset
3433
kono
parents:
diff changeset
3434 elsif Is_Class_Wide_Type (T2)
kono
parents:
diff changeset
3435 and then Is_Interface (Etype (T2))
kono
parents:
diff changeset
3436 and then Interface_Present_In_Ancestor (Typ => T1,
kono
parents:
diff changeset
3437 Iface => Etype (T2))
kono
parents:
diff changeset
3438 then
kono
parents:
diff changeset
3439 return T1;
kono
parents:
diff changeset
3440
kono
parents:
diff changeset
3441 elsif Is_Class_Wide_Type (T1)
kono
parents:
diff changeset
3442 and then Is_Ancestor (Root_Type (T1), T2)
kono
parents:
diff changeset
3443 then
kono
parents:
diff changeset
3444 return T1;
kono
parents:
diff changeset
3445
kono
parents:
diff changeset
3446 elsif Is_Class_Wide_Type (T2)
kono
parents:
diff changeset
3447 and then Is_Ancestor (Root_Type (T2), T1)
kono
parents:
diff changeset
3448 then
kono
parents:
diff changeset
3449 return T2;
kono
parents:
diff changeset
3450
kono
parents:
diff changeset
3451 elsif Ekind_In (B1, E_Access_Subprogram_Type,
kono
parents:
diff changeset
3452 E_Access_Protected_Subprogram_Type)
kono
parents:
diff changeset
3453 and then Ekind (Designated_Type (B1)) /= E_Subprogram_Type
kono
parents:
diff changeset
3454 and then Is_Access_Type (T2)
kono
parents:
diff changeset
3455 then
kono
parents:
diff changeset
3456 return T2;
kono
parents:
diff changeset
3457
kono
parents:
diff changeset
3458 elsif Ekind_In (B2, E_Access_Subprogram_Type,
kono
parents:
diff changeset
3459 E_Access_Protected_Subprogram_Type)
kono
parents:
diff changeset
3460 and then Ekind (Designated_Type (B2)) /= E_Subprogram_Type
kono
parents:
diff changeset
3461 and then Is_Access_Type (T1)
kono
parents:
diff changeset
3462 then
kono
parents:
diff changeset
3463 return T1;
kono
parents:
diff changeset
3464
kono
parents:
diff changeset
3465 elsif Ekind_In (T1, E_Allocator_Type,
kono
parents:
diff changeset
3466 E_Access_Attribute_Type,
kono
parents:
diff changeset
3467 E_Anonymous_Access_Type)
kono
parents:
diff changeset
3468 and then Is_Access_Type (T2)
kono
parents:
diff changeset
3469 then
kono
parents:
diff changeset
3470 return T2;
kono
parents:
diff changeset
3471
kono
parents:
diff changeset
3472 elsif Ekind_In (T2, E_Allocator_Type,
kono
parents:
diff changeset
3473 E_Access_Attribute_Type,
kono
parents:
diff changeset
3474 E_Anonymous_Access_Type)
kono
parents:
diff changeset
3475 and then Is_Access_Type (T1)
kono
parents:
diff changeset
3476 then
kono
parents:
diff changeset
3477 return T1;
kono
parents:
diff changeset
3478
kono
parents:
diff changeset
3479 -- If none of the above cases applies, types are not compatible
kono
parents:
diff changeset
3480
kono
parents:
diff changeset
3481 else
kono
parents:
diff changeset
3482 return Any_Type;
kono
parents:
diff changeset
3483 end if;
kono
parents:
diff changeset
3484 end Specific_Type;
kono
parents:
diff changeset
3485
kono
parents:
diff changeset
3486 ---------------------
kono
parents:
diff changeset
3487 -- Set_Abstract_Op --
kono
parents:
diff changeset
3488 ---------------------
kono
parents:
diff changeset
3489
kono
parents:
diff changeset
3490 procedure Set_Abstract_Op (I : Interp_Index; V : Entity_Id) is
kono
parents:
diff changeset
3491 begin
kono
parents:
diff changeset
3492 All_Interp.Table (I).Abstract_Op := V;
kono
parents:
diff changeset
3493 end Set_Abstract_Op;
kono
parents:
diff changeset
3494
kono
parents:
diff changeset
3495 -----------------------
kono
parents:
diff changeset
3496 -- Valid_Boolean_Arg --
kono
parents:
diff changeset
3497 -----------------------
kono
parents:
diff changeset
3498
kono
parents:
diff changeset
3499 -- In addition to booleans and arrays of booleans, we must include
kono
parents:
diff changeset
3500 -- aggregates as valid boolean arguments, because in the first pass of
kono
parents:
diff changeset
3501 -- resolution their components are not examined. If it turns out not to be
kono
parents:
diff changeset
3502 -- an aggregate of booleans, this will be diagnosed in Resolve.
kono
parents:
diff changeset
3503 -- Any_Composite must be checked for prior to the array type checks because
kono
parents:
diff changeset
3504 -- Any_Composite does not have any associated indexes.
kono
parents:
diff changeset
3505
kono
parents:
diff changeset
3506 function Valid_Boolean_Arg (T : Entity_Id) return Boolean is
kono
parents:
diff changeset
3507 begin
kono
parents:
diff changeset
3508 if Is_Boolean_Type (T)
kono
parents:
diff changeset
3509 or else Is_Modular_Integer_Type (T)
kono
parents:
diff changeset
3510 or else T = Universal_Integer
kono
parents:
diff changeset
3511 or else T = Any_Composite
kono
parents:
diff changeset
3512 then
kono
parents:
diff changeset
3513 return True;
kono
parents:
diff changeset
3514
kono
parents:
diff changeset
3515 elsif Is_Array_Type (T)
kono
parents:
diff changeset
3516 and then T /= Any_String
kono
parents:
diff changeset
3517 and then Number_Dimensions (T) = 1
kono
parents:
diff changeset
3518 and then Is_Boolean_Type (Component_Type (T))
kono
parents:
diff changeset
3519 and then
kono
parents:
diff changeset
3520 ((not Is_Private_Composite (T) and then not Is_Limited_Composite (T))
kono
parents:
diff changeset
3521 or else In_Instance
kono
parents:
diff changeset
3522 or else Available_Full_View_Of_Component (T))
kono
parents:
diff changeset
3523 then
kono
parents:
diff changeset
3524 return True;
kono
parents:
diff changeset
3525
kono
parents:
diff changeset
3526 else
kono
parents:
diff changeset
3527 return False;
kono
parents:
diff changeset
3528 end if;
kono
parents:
diff changeset
3529 end Valid_Boolean_Arg;
kono
parents:
diff changeset
3530
kono
parents:
diff changeset
3531 --------------------------
kono
parents:
diff changeset
3532 -- Valid_Comparison_Arg --
kono
parents:
diff changeset
3533 --------------------------
kono
parents:
diff changeset
3534
kono
parents:
diff changeset
3535 function Valid_Comparison_Arg (T : Entity_Id) return Boolean is
kono
parents:
diff changeset
3536 begin
kono
parents:
diff changeset
3537
kono
parents:
diff changeset
3538 if T = Any_Composite then
kono
parents:
diff changeset
3539 return False;
kono
parents:
diff changeset
3540
kono
parents:
diff changeset
3541 elsif Is_Discrete_Type (T)
kono
parents:
diff changeset
3542 or else Is_Real_Type (T)
kono
parents:
diff changeset
3543 then
kono
parents:
diff changeset
3544 return True;
kono
parents:
diff changeset
3545
kono
parents:
diff changeset
3546 elsif Is_Array_Type (T)
kono
parents:
diff changeset
3547 and then Number_Dimensions (T) = 1
kono
parents:
diff changeset
3548 and then Is_Discrete_Type (Component_Type (T))
kono
parents:
diff changeset
3549 and then (not Is_Private_Composite (T) or else In_Instance)
kono
parents:
diff changeset
3550 and then (not Is_Limited_Composite (T) or else In_Instance)
kono
parents:
diff changeset
3551 then
kono
parents:
diff changeset
3552 return True;
kono
parents:
diff changeset
3553
kono
parents:
diff changeset
3554 elsif Is_Array_Type (T)
kono
parents:
diff changeset
3555 and then Number_Dimensions (T) = 1
kono
parents:
diff changeset
3556 and then Is_Discrete_Type (Component_Type (T))
kono
parents:
diff changeset
3557 and then Available_Full_View_Of_Component (T)
kono
parents:
diff changeset
3558 then
kono
parents:
diff changeset
3559 return True;
kono
parents:
diff changeset
3560
kono
parents:
diff changeset
3561 elsif Is_String_Type (T) then
kono
parents:
diff changeset
3562 return True;
kono
parents:
diff changeset
3563 else
kono
parents:
diff changeset
3564 return False;
kono
parents:
diff changeset
3565 end if;
kono
parents:
diff changeset
3566 end Valid_Comparison_Arg;
kono
parents:
diff changeset
3567
kono
parents:
diff changeset
3568 ------------------
kono
parents:
diff changeset
3569 -- Write_Interp --
kono
parents:
diff changeset
3570 ------------------
kono
parents:
diff changeset
3571
kono
parents:
diff changeset
3572 procedure Write_Interp (It : Interp) is
kono
parents:
diff changeset
3573 begin
kono
parents:
diff changeset
3574 Write_Str ("Nam: ");
kono
parents:
diff changeset
3575 Print_Tree_Node (It.Nam);
kono
parents:
diff changeset
3576 Write_Str ("Typ: ");
kono
parents:
diff changeset
3577 Print_Tree_Node (It.Typ);
kono
parents:
diff changeset
3578 Write_Str ("Abstract_Op: ");
kono
parents:
diff changeset
3579 Print_Tree_Node (It.Abstract_Op);
kono
parents:
diff changeset
3580 end Write_Interp;
kono
parents:
diff changeset
3581
kono
parents:
diff changeset
3582 ----------------------
kono
parents:
diff changeset
3583 -- Write_Interp_Ref --
kono
parents:
diff changeset
3584 ----------------------
kono
parents:
diff changeset
3585
kono
parents:
diff changeset
3586 procedure Write_Interp_Ref (Map_Ptr : Int) is
kono
parents:
diff changeset
3587 begin
kono
parents:
diff changeset
3588 Write_Str (" Node: ");
kono
parents:
diff changeset
3589 Write_Int (Int (Interp_Map.Table (Map_Ptr).Node));
kono
parents:
diff changeset
3590 Write_Str (" Index: ");
kono
parents:
diff changeset
3591 Write_Int (Int (Interp_Map.Table (Map_Ptr).Index));
kono
parents:
diff changeset
3592 Write_Str (" Next: ");
kono
parents:
diff changeset
3593 Write_Int (Interp_Map.Table (Map_Ptr).Next);
kono
parents:
diff changeset
3594 Write_Eol;
kono
parents:
diff changeset
3595 end Write_Interp_Ref;
kono
parents:
diff changeset
3596
kono
parents:
diff changeset
3597 ---------------------
kono
parents:
diff changeset
3598 -- Write_Overloads --
kono
parents:
diff changeset
3599 ---------------------
kono
parents:
diff changeset
3600
kono
parents:
diff changeset
3601 procedure Write_Overloads (N : Node_Id) is
kono
parents:
diff changeset
3602 I : Interp_Index;
kono
parents:
diff changeset
3603 It : Interp;
kono
parents:
diff changeset
3604 Nam : Entity_Id;
kono
parents:
diff changeset
3605
kono
parents:
diff changeset
3606 begin
kono
parents:
diff changeset
3607 Write_Str ("Overloads: ");
kono
parents:
diff changeset
3608 Print_Node_Briefly (N);
kono
parents:
diff changeset
3609
kono
parents:
diff changeset
3610 if not Is_Overloaded (N) then
kono
parents:
diff changeset
3611 Write_Line ("Non-overloaded entity ");
kono
parents:
diff changeset
3612 Write_Entity_Info (Entity (N), " ");
kono
parents:
diff changeset
3613
kono
parents:
diff changeset
3614 elsif Nkind (N) not in N_Has_Entity then
kono
parents:
diff changeset
3615 Get_First_Interp (N, I, It);
kono
parents:
diff changeset
3616 while Present (It.Nam) loop
kono
parents:
diff changeset
3617 Write_Int (Int (It.Typ));
kono
parents:
diff changeset
3618 Write_Str (" ");
kono
parents:
diff changeset
3619 Write_Name (Chars (It.Typ));
kono
parents:
diff changeset
3620 Write_Eol;
kono
parents:
diff changeset
3621 Get_Next_Interp (I, It);
kono
parents:
diff changeset
3622 end loop;
kono
parents:
diff changeset
3623
kono
parents:
diff changeset
3624 else
kono
parents:
diff changeset
3625 Get_First_Interp (N, I, It);
kono
parents:
diff changeset
3626 Write_Line ("Overloaded entity ");
kono
parents:
diff changeset
3627 Write_Line (" Name Type Abstract Op");
kono
parents:
diff changeset
3628 Write_Line ("===============================================");
kono
parents:
diff changeset
3629 Nam := It.Nam;
kono
parents:
diff changeset
3630
kono
parents:
diff changeset
3631 while Present (Nam) loop
kono
parents:
diff changeset
3632 Write_Int (Int (Nam));
kono
parents:
diff changeset
3633 Write_Str (" ");
kono
parents:
diff changeset
3634 Write_Name (Chars (Nam));
kono
parents:
diff changeset
3635 Write_Str (" ");
kono
parents:
diff changeset
3636 Write_Int (Int (It.Typ));
kono
parents:
diff changeset
3637 Write_Str (" ");
kono
parents:
diff changeset
3638 Write_Name (Chars (It.Typ));
kono
parents:
diff changeset
3639
kono
parents:
diff changeset
3640 if Present (It.Abstract_Op) then
kono
parents:
diff changeset
3641 Write_Str (" ");
kono
parents:
diff changeset
3642 Write_Int (Int (It.Abstract_Op));
kono
parents:
diff changeset
3643 Write_Str (" ");
kono
parents:
diff changeset
3644 Write_Name (Chars (It.Abstract_Op));
kono
parents:
diff changeset
3645 end if;
kono
parents:
diff changeset
3646
kono
parents:
diff changeset
3647 Write_Eol;
kono
parents:
diff changeset
3648 Get_Next_Interp (I, It);
kono
parents:
diff changeset
3649 Nam := It.Nam;
kono
parents:
diff changeset
3650 end loop;
kono
parents:
diff changeset
3651 end if;
kono
parents:
diff changeset
3652 end Write_Overloads;
kono
parents:
diff changeset
3653
kono
parents:
diff changeset
3654 end Sem_Type;