]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ada/sem_aux.ads
c++: Handle multiple aggregate overloads [PR95319].
[thirdparty/gcc.git] / gcc / ada / sem_aux.ads
CommitLineData
21d27997
RD
1------------------------------------------------------------------------------
2-- --
3-- GNAT COMPILER COMPONENTS --
4-- --
5-- S E M _ A U X --
6-- --
7-- S p e c --
8-- --
1d005acc 9-- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
21d27997
RD
10-- --
11-- GNAT is free software; you can redistribute it and/or modify it under --
12-- terms of the GNU General Public License as published by the Free Soft- --
13-- ware Foundation; either version 3, or (at your option) any later ver- --
14-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17-- for more details. You should have received a copy of the GNU General --
18-- Public License distributed with GNAT; see file COPYING3. If not, go to --
19-- http://www.gnu.org/licenses for a complete copy of the license. --
20-- --
21-- As a special exception, if other files instantiate generics from this --
22-- unit, or you link this unit with other files to produce an executable, --
23-- this unit does not by itself cause the resulting executable to be --
24-- covered by the GNU General Public License. This exception does not --
25-- however invalidate any other reasons why the executable file might be --
26-- covered by the GNU Public License. --
27-- --
28-- GNAT was originally developed by the GNAT team at New York University. --
29-- Extensive contributions were provided by Ada Core Technologies Inc. --
30-- --
31------------------------------------------------------------------------------
32
33-- Package containing utility procedures used throughout the compiler,
34-- and also by ASIS so dependencies are limited to ASIS included packages.
35
a4100e55
RD
36-- Historical note. Many of the routines here were originally in Einfo, but
37-- Einfo is supposed to be a relatively low level package dealing with the
38-- content of entities in the tree, so this package is used for routines that
dbf04430 39-- require more than minimal semantic knowledge.
21d27997 40
851e9f19 41with Alloc;
34f3a701 42with Namet; use Namet;
21d27997 43with Table;
a4100e55 44with Types; use Types;
4b03d946 45with Sinfo; use Sinfo;
21d27997
RD
46
47package Sem_Aux is
48
49 --------------------------------
50 -- Obsolescent Warnings Table --
51 --------------------------------
52
53 -- This table records entities for which a pragma Obsolescent with a
54 -- message argument has been processed.
55
56 type OWT_Record is record
57 Ent : Entity_Id;
58 -- The entity to which the pragma applies
59
60 Msg : String_Id;
61 -- The string containing the message
62 end record;
63
64 package Obsolescent_Warnings is new Table.Table (
65 Table_Component_Type => OWT_Record,
66 Table_Index_Type => Int,
67 Table_Low_Bound => 0,
68 Table_Initial => Alloc.Obsolescent_Warnings_Initial,
69 Table_Increment => Alloc.Obsolescent_Warnings_Increment,
70 Table_Name => "Obsolescent_Warnings");
71
21d27997
RD
72 procedure Initialize;
73 -- Called at the start of compilation of each new main source file to
74 -- initialize the allocation of the Obsolescent_Warnings table. Note that
75 -- Initialize must not be called if Tree_Read is used.
76
77 procedure Tree_Read;
a4100e55
RD
78 -- Initializes Obsolescent_Warnings table from current tree file using the
79 -- relevant Table.Tree_Read routine.
21d27997
RD
80
81 procedure Tree_Write;
a4100e55
RD
82 -- Writes out Obsolescent_Warnings table to current tree file using the
83 -- relevant Table.Tree_Write routine.
84
85 -----------------
86 -- Subprograms --
87 -----------------
88
89 function Ancestor_Subtype (Typ : Entity_Id) return Entity_Id;
6d0289b1 90 -- The argument Typ is a type or subtype entity. If the argument is a
a4100e55
RD
91 -- subtype then it returns the subtype or type from which the subtype was
92 -- obtained, otherwise it returns Empty.
93
c7732bbe
EB
94 -- WARNING: There is a matching C declaration of this subprogram in fe.h
95
dc726757
HK
96 function Available_View (Ent : Entity_Id) return Entity_Id;
97 -- Ent denotes an abstract state or a type that may come from a limited
98 -- with clause. Return the non-limited view of Ent if there is one or Ent
99 -- if this is not the case.
a4100e55
RD
100
101 function Constant_Value (Ent : Entity_Id) return Node_Id;
4230bdb7 102 -- Ent is a variable, constant, named integer, or named real entity. This
a4100e55 103 -- call obtains the initialization expression for the entity. Will return
db664118 104 -- Empty for a deferred constant whose full view is not available or
a4100e55
RD
105 -- in some other cases of internal entities, which cannot be treated as
106 -- constants from the point of view of constant folding. Empty is also
107 -- returned for variables with no initialization expression.
108
c7732bbe
EB
109 -- WARNING: There is a matching C declaration of this subprogram in fe.h
110
2c9f8c0a
AC
111 function Corresponding_Unsigned_Type (Typ : Entity_Id) return Entity_Id;
112 -- Typ is a signed integer subtype. This routine returns the standard
113 -- unsigned type with the same Esize as the implementation base type of
114 -- Typ, e.g. Long_Integer => Long_Unsigned.
115
a4100e55
RD
116 function Enclosing_Dynamic_Scope (Ent : Entity_Id) return Entity_Id;
117 -- For any entity, Ent, returns the closest dynamic scope in which the
df3e68b1 118 -- entity is declared or Standard_Standard for library-level entities.
a4100e55
RD
119
120 function First_Discriminant (Typ : Entity_Id) return Entity_Id;
121 -- Typ is a type with discriminants. The discriminants are the first
122 -- entities declared in the type, so normally this is equivalent to
123 -- First_Entity. The exception arises for tagged types, where the tag
124 -- itself is prepended to the front of the entity chain, so the
125 -- First_Discriminant function steps past the tag if it is present.
66371f94
AC
126 -- The caller is responsible for checking that the type has discriminants.
127 -- When called on a private type with unknown discriminants, the function
128 -- always returns Empty.
a4100e55 129
c7732bbe
EB
130 -- WARNING: There is a matching C declaration of this subprogram in fe.h
131
a4100e55
RD
132 function First_Stored_Discriminant (Typ : Entity_Id) return Entity_Id;
133 -- Typ is a type with discriminants. Gives the first discriminant stored
134 -- in an object of this type. In many cases, these are the same as the
135 -- normal visible discriminants for the type, but in the case of renamed
136 -- discriminants, this is not always the case.
137 --
138 -- For tagged types, and untagged types which are root types or derived
139 -- types but which do not rename discriminants in their root type, the
140 -- stored discriminants are the same as the actual discriminants of the
141 -- type, and hence this function is the same as First_Discriminant.
142 --
7c0c194b 143 -- For derived untagged types that rename discriminants in the root type
a4100e55
RD
144 -- this is the first of the discriminants that occur in the root type. To
145 -- be precise, in this case stored discriminants are entities attached to
146 -- the entity chain of the derived type which are a copy of the
147 -- discriminants of the root type. Furthermore their Is_Completely_Hidden
148 -- flag is set since although they are actually stored in the object, they
308e6f3a 149 -- are not in the set of discriminants that is visible in the type.
a4100e55
RD
150 --
151 -- For derived untagged types, the set of stored discriminants are the real
152 -- discriminants from Gigi's standpoint, i.e. those that will be stored in
153 -- actual objects of the type.
154
c7732bbe
EB
155 -- WARNING: There is a matching C declaration of this subprogram in fe.h
156
a4100e55
RD
157 function First_Subtype (Typ : Entity_Id) return Entity_Id;
158 -- Applies to all types and subtypes. For types, yields the first subtype
159 -- of the type. For subtypes, yields the first subtype of the base type of
160 -- the subtype.
161
c7732bbe
EB
162 -- WARNING: There is a matching C declaration of this subprogram in fe.h
163
a4100e55
RD
164 function First_Tag_Component (Typ : Entity_Id) return Entity_Id;
165 -- Typ must be a tagged record type. This function returns the Entity for
166 -- the first _Tag field in the record type.
167
0382062b
AC
168 function Get_Binary_Nkind (Op : Entity_Id) return Node_Kind;
169 -- Op must be an entity with an Ekind of E_Operator. This function returns
170 -- the Nkind value that would be used to construct a binary operator node
171 -- referencing this entity. It is an error to call this function if Ekind
172 -- (Op) /= E_Operator.
173
8437edb4 174 function Get_Called_Entity (Call : Node_Id) return Entity_Id;
13126368
YM
175 -- Obtain the entity of the entry, operator, or subprogram being invoked
176 -- by call Call.
8437edb4 177
90a4b336 178 function Get_Low_Bound (E : Entity_Id) return Node_Id;
8437edb4 179 -- For an index subtype or string literal subtype, returns its low bound
90a4b336 180
0382062b
AC
181 function Get_Unary_Nkind (Op : Entity_Id) return Node_Kind;
182 -- Op must be an entity with an Ekind of E_Operator. This function returns
183 -- the Nkind value that would be used to construct a unary operator node
184 -- referencing this entity. It is an error to call this function if Ekind
185 -- (Op) /= E_Operator.
186
34f3a701
VP
187 function Get_Rep_Item
188 (E : Entity_Id;
189 Nam : Name_Id;
190 Check_Parents : Boolean := True) return Node_Id;
191 -- Searches the Rep_Item chain for a given entity E, for an instance of a
192 -- rep item (pragma, attribute definition clause, or aspect specification)
193 -- whose name matches the given name Nam. If Check_Parents is False then it
2a290fec 194 -- only returns rep item that has been directly specified for E (and not
34f3a701
VP
195 -- inherited from its parents, if any). If one is found, it is returned,
196 -- otherwise Empty is returned. A special case is that when Nam is
197 -- Name_Priority, the call will also find Interrupt_Priority.
198
dc3af7e2
AC
199 function Get_Rep_Item
200 (E : Entity_Id;
201 Nam1 : Name_Id;
202 Nam2 : Name_Id;
203 Check_Parents : Boolean := True) return Node_Id;
204 -- Searches the Rep_Item chain for a given entity E, for an instance of a
205 -- rep item (pragma, attribute definition clause, or aspect specification)
206 -- whose name matches one of the given names Nam1 or Nam2. If Check_Parents
207 -- is False then it only returns rep item that has been directly specified
208 -- for E (and not inherited from its parents, if any). If one is found, it
209 -- is returned, otherwise Empty is returned. A special case is that when
210 -- one of the given names is Name_Priority, the call will also find
211 -- Interrupt_Priority.
212
34f3a701
VP
213 function Get_Rep_Pragma
214 (E : Entity_Id;
215 Nam : Name_Id;
216 Check_Parents : Boolean := True) return Node_Id;
dc3af7e2
AC
217 -- Searches the Rep_Item chain for a given entity E, for an instance of a
218 -- representation pragma whose name matches the given name Nam. If
34f3a701 219 -- Check_Parents is False then it only returns representation pragma that
2a290fec 220 -- has been directly specified for E (and not inherited from its parents,
dc3af7e2
AC
221 -- if any). If one is found and if it is the first rep item in the list
222 -- that matches Nam, it is returned, otherwise Empty is returned. A special
223 -- case is that when Nam is Name_Priority, the call will also find
34f3a701
VP
224 -- Interrupt_Priority.
225
dc3af7e2
AC
226 function Get_Rep_Pragma
227 (E : Entity_Id;
228 Nam1 : Name_Id;
229 Nam2 : Name_Id;
230 Check_Parents : Boolean := True) return Node_Id;
231 -- Searches the Rep_Item chain for a given entity E, for an instance of a
232 -- representation pragma whose name matches one of the given names Nam1 or
233 -- Nam2. If Check_Parents is False then it only returns representation
234 -- pragma that has been directly specified for E (and not inherited from
235 -- its parents, if any). If one is found and if it is the first rep item in
236 -- the list that matches one of the given names, it is returned, otherwise
237 -- Empty is returned. A special case is that when one of the given names is
238 -- Name_Priority, the call will also find Interrupt_Priority.
239
34f3a701
VP
240 function Has_Rep_Item
241 (E : Entity_Id;
242 Nam : Name_Id;
243 Check_Parents : Boolean := True) return Boolean;
244 -- Searches the Rep_Item chain for the given entity E, for an instance of a
245 -- rep item (pragma, attribute definition clause, or aspect specification)
2a290fec
AC
246 -- with the given name Nam. If Check_Parents is False then it only checks
247 -- for a rep item that has been directly specified for E (and not inherited
248 -- from its parents, if any). If found then True is returned, otherwise
249 -- False indicates that no matching entry was found.
34f3a701 250
dc3af7e2
AC
251 function Has_Rep_Item
252 (E : Entity_Id;
253 Nam1 : Name_Id;
254 Nam2 : Name_Id;
255 Check_Parents : Boolean := True) return Boolean;
256 -- Searches the Rep_Item chain for the given entity E, for an instance of a
257 -- rep item (pragma, attribute definition clause, or aspect specification)
258 -- with the given names Nam1 or Nam2. If Check_Parents is False then it
259 -- only checks for a rep item that has been directly specified for E (and
260 -- not inherited from its parents, if any). If found then True is returned,
261 -- otherwise False indicates that no matching entry was found.
262
6dc87f5f
AC
263 function Has_Rep_Item (E : Entity_Id; N : Node_Id) return Boolean;
264 -- Determine whether the Rep_Item chain of arbitrary entity E contains item
265 -- N. N must denote a valid rep item.
266
34f3a701
VP
267 function Has_Rep_Pragma
268 (E : Entity_Id;
269 Nam : Name_Id;
270 Check_Parents : Boolean := True) return Boolean;
271 -- Searches the Rep_Item chain for the given entity E, for an instance of a
272 -- representation pragma with the given name Nam. If Check_Parents is False
2a290fec
AC
273 -- then it only checks for a representation pragma that has been directly
274 -- specified for E (and not inherited from its parents, if any). If found
dc3af7e2
AC
275 -- and if it is the first rep item in the list that matches Nam then True
276 -- is returned, otherwise False indicates that no matching entry was found.
277
278 function Has_Rep_Pragma
279 (E : Entity_Id;
280 Nam1 : Name_Id;
281 Nam2 : Name_Id;
282 Check_Parents : Boolean := True) return Boolean;
283 -- Searches the Rep_Item chain for the given entity E, for an instance of a
284 -- representation pragma with the given names Nam1 or Nam2. If
285 -- Check_Parents is False then it only checks for a rep item that has been
286 -- directly specified for E (and not inherited from its parents, if any).
287 -- If found and if it is the first rep item in the list that matches one of
288 -- the given names then True is returned, otherwise False indicates that no
289 -- matching entry was found.
34f3a701 290
36295779
AC
291 function Has_External_Tag_Rep_Clause (T : Entity_Id) return Boolean;
292 -- Defined in tagged types. Set if an External_Tag rep. clause has been
293 -- given for this type. Use to avoid the generation of the default
294 -- External_Tag.
c61ef416
AC
295 --
296 -- Note: we used to use an entity flag for this purpose, but that was wrong
297 -- because it was not propagated from the private view to the full view. We
298 -- could have added that propagation, but it would have been an annoying
299 -- irregularity compared to other representation aspects, and the cost of
300 -- looking up the aspect when needed is small.
36295779 301
b2834fbd
AC
302 function Has_Unconstrained_Elements (T : Entity_Id) return Boolean;
303 -- True if T has discriminants and is unconstrained, or is an array type
304 -- whose element type Has_Unconstrained_Elements.
305
dda38714
AC
306 function Has_Variant_Part (Typ : Entity_Id) return Boolean;
307 -- Return True if the first subtype of Typ is a discriminated record type
308 -- which has a variant part. False otherwise.
309
414b312e
AC
310 function In_Generic_Body (Id : Entity_Id) return Boolean;
311 -- Determine whether entity Id appears inside a generic body
312
0fbcb11c
ES
313 function Initialization_Suppressed (Typ : Entity_Id) return Boolean;
314 pragma Inline (Initialization_Suppressed);
315 -- Returns True if initialization should be suppressed for the given type
316 -- or subtype. This is true if Suppress_Initialization is set either for
317 -- the subtype itself, or for the corresponding base type.
318
fba9ebfc
AC
319 function Is_Body (N : Node_Id) return Boolean;
320 -- Determine whether an arbitrary node denotes a body
321
a4100e55
RD
322 function Is_By_Copy_Type (Ent : Entity_Id) return Boolean;
323 -- Ent is any entity. Returns True if Ent is a type entity where the type
324 -- is required to be passed by copy, as defined in (RM 6.2(3)).
325
326 function Is_By_Reference_Type (Ent : Entity_Id) return Boolean;
327 -- Ent is any entity. Returns True if Ent is a type entity where the type
328 -- is required to be passed by reference, as defined in (RM 6.2(4-9)).
329
c7732bbe
EB
330 -- WARNING: There is a matching C declaration of this subprogram in fe.h
331
b68cf874
AC
332 function Is_Definite_Subtype (T : Entity_Id) return Boolean;
333 -- T is a type entity. Returns True if T is a definite subtype.
334 -- Indefinite subtypes are unconstrained arrays, unconstrained
335 -- discriminated types without defaulted discriminants, class-wide types,
336 -- and types with unknown discriminants. Definite subtypes are all others
337 -- (elementary, constrained composites (including the case of records
338 -- without discriminants), and types with defaulted discriminants).
339
a4100e55
RD
340 function Is_Derived_Type (Ent : Entity_Id) return Boolean;
341 -- Determines if the given entity Ent is a derived type. Result is always
342 -- false if argument is not a type.
343
c7732bbe
EB
344 -- WARNING: There is a matching C declaration of this subprogram in fe.h
345
57d62f0c
AC
346 function Is_Generic_Formal (E : Entity_Id) return Boolean;
347 -- Determine whether E is a generic formal parameter. In particular this is
348 -- used to set the visibility of generic formals of a generic package
97027f64 349 -- declared with a box or with partial parameterization.
57d62f0c 350
40f07b4b 351 function Is_Immutably_Limited_Type (Ent : Entity_Id) return Boolean;
51245e2d
ES
352 -- Implements definition in Ada 2012 RM-7.5 (8.1/3). This differs from the
353 -- following predicate in that an untagged record with immutably limited
72d1b27a 354 -- components is NOT by itself immutably limited. This matters, e.g. when
51245e2d
ES
355 -- checking the legality of an access to the current instance.
356
357 function Is_Limited_View (Ent : Entity_Id) return Boolean;
a4100e55
RD
358 -- Ent is any entity. True for a type that is "inherently" limited (i.e.
359 -- cannot become nonlimited). From the Ada 2005 RM-7.5(8.1/2), "a type with
360 -- a part that is of a task, protected, or explicitly limited record type".
361 -- These are the types that are defined as return-by-reference types in Ada
362 -- 95 (see RM95-6.5(11-16)). In Ada 2005, these are the types that require
363 -- build-in-place for function calls. Note that build-in-place is allowed
308e6f3a 364 -- for other types, too. This is also used for identifying pure procedures
46f52a47 365 -- whose calls should not be eliminated (RM 10.2.1(18/2)).
a4100e55
RD
366
367 function Is_Limited_Type (Ent : Entity_Id) return Boolean;
368 -- Ent is any entity. Returns true if Ent is a limited type (limited
369 -- private type, limited interface type, task type, protected type,
370 -- composite containing a limited component, or a subtype of any of
51245e2d 371 -- these types). This older routine overlaps with the previous one, this
72d1b27a 372 -- should be cleaned up???
a4100e55 373
179682a5
YM
374 function Is_Protected_Operation (E : Entity_Id) return Boolean;
375 -- Given a subprogram or entry, determines whether E is a protected entry
376 -- or subprogram.
377
8110ee3b
RD
378 function Nearest_Ancestor (Typ : Entity_Id) return Entity_Id;
379 -- Given a subtype Typ, this function finds out the nearest ancestor from
380 -- which constraints and predicates are inherited. There is no simple link
381 -- for doing this, consider:
382 --
383 -- subtype R is Integer range 1 .. 10;
384 -- type T is new R;
385 --
386 -- In this case the nearest ancestor is R, but the Etype of T'Base will
387 -- point to R'Base, so we have to go rummaging in the declarations to get
388 -- this information. It is used for making sure we freeze this before we
389 -- freeze Typ, and also for retrieving inherited predicate information.
390 -- For the case of base types or first subtypes, there is no useful entity
391 -- to return, so Empty is returned.
392 --
393 -- Note: this is similar to Ancestor_Subtype except that it also deals
394 -- with the case of derived types.
395
24357840
RD
396 function Nearest_Dynamic_Scope (Ent : Entity_Id) return Entity_Id;
397 -- This is similar to Enclosing_Dynamic_Scope except that if Ent is itself
398 -- a dynamic scope, then it is returned. Otherwise the result is the same
399 -- as that returned by Enclosing_Dynamic_Scope.
400
a4100e55
RD
401 function Next_Tag_Component (Tag : Entity_Id) return Entity_Id;
402 -- Tag must be an entity representing a _Tag field of a tagged record.
403 -- The result returned is the next _Tag field in this record, or Empty
404 -- if this is the last such field.
405
877a5a12 406 function Number_Components (Typ : Entity_Id) return Nat;
90a4b336
YM
407 -- Typ is a record type, yields number of components (including
408 -- discriminants) in type.
409
a4100e55
RD
410 function Number_Discriminants (Typ : Entity_Id) return Pos;
411 -- Typ is a type with discriminants, yields number of discriminants in type
21d27997 412
0fbcb11c
ES
413 function Object_Type_Has_Constrained_Partial_View
414 (Typ : Entity_Id;
415 Scop : Entity_Id) return Boolean;
416 -- Return True if type of object has attribute Has_Constrained_Partial_View
417 -- set to True; in addition, within a generic body, return True if subtype
418 -- of the object is a descendant of an untagged generic formal private or
419 -- derived type, and the subtype is not an unconstrained array subtype
420 -- (RM 3.3(23.10/3)).
5b1e6aca 421
ff1bedac
YM
422 function Package_Body (E : Entity_Id) return Node_Id;
423 -- Given an entity for a package (spec or body), return the corresponding
424 -- package body if any, or else Empty.
425
426 function Package_Spec (E : Entity_Id) return Node_Id;
427 -- Given an entity for a package spec, return the corresponding package
428 -- spec if any, or else Empty.
429
430 function Package_Specification (E : Entity_Id) return Node_Id;
431 -- Given an entity for a package, return the corresponding package
432 -- specification.
90a4b336
YM
433
434 function Subprogram_Body (E : Entity_Id) return Node_Id;
435 -- Given an entity for a subprogram (spec or body), return the
436 -- corresponding subprogram body if any, or else Empty.
437
438 function Subprogram_Body_Entity (E : Entity_Id) return Entity_Id;
439 -- Given an entity for a subprogram (spec or body), return the entity
440 -- corresponding to the subprogram body, which may be the same as E or
441 -- Empty if no body is available.
442
443 function Subprogram_Spec (E : Entity_Id) return Node_Id;
444 -- Given an entity for a subprogram spec, return the corresponding
445 -- subprogram spec if any, or else Empty.
446
447 function Subprogram_Specification (E : Entity_Id) return Node_Id;
448 -- Given an entity for a subprogram, return the corresponding subprogram
449 -- specification. If the entity is an inherited subprogram without
450 -- specification itself, return the specification of the inherited
451 -- subprogram.
452
bb10b891
AC
453 function Ultimate_Alias (Prim : Entity_Id) return Entity_Id;
454 pragma Inline (Ultimate_Alias);
455 -- Return the last entity in the chain of aliased entities of Prim. If Prim
456 -- has no alias return Prim.
457
414b312e
AC
458 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id;
459 -- Unit_Id is the simple name of a program unit, this function returns the
460 -- corresponding xxx_Declaration node for the entity. Also applies to the
461 -- body entities for subprograms, tasks and protected units, in which case
462 -- it returns the subprogram, task or protected body node for it. The unit
463 -- may be a child unit with any number of ancestors.
464
21d27997 465end Sem_Aux;