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