2014-01-30 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / ada / sem_aux.ads
blob9f574ece1d3616cfe612d5ddf6851c18f5251d3f
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ A U X --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
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 ------------------------------------------------------------------------------
33 -- Package containing utility procedures used throughout the compiler,
34 -- and also by ASIS so dependencies are limited to ASIS included packages.
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
39 -- require more than minimal semantic knowledge.
41 with Alloc; use Alloc;
42 with Namet; use Namet;
43 with Table;
44 with Types; use Types;
46 package Sem_Aux is
48 --------------------------------
49 -- Obsolescent Warnings Table --
50 --------------------------------
52 -- This table records entities for which a pragma Obsolescent with a
53 -- message argument has been processed.
55 type OWT_Record is record
56 Ent : Entity_Id;
57 -- The entity to which the pragma applies
59 Msg : String_Id;
60 -- The string containing the message
61 end record;
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");
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.
76 procedure Tree_Read;
77 -- Initializes Obsolescent_Warnings table from current tree file using the
78 -- relevant Table.Tree_Read routine.
80 procedure Tree_Write;
81 -- Writes out Obsolescent_Warnings table to current tree file using the
82 -- relevant Table.Tree_Write routine.
84 -----------------
85 -- Subprograms --
86 -----------------
88 function Ancestor_Subtype (Typ : Entity_Id) return Entity_Id;
89 -- The argument Id is a type or subtype entity. If the argument is a
90 -- subtype then it returns the subtype or type from which the subtype was
91 -- obtained, otherwise it returns Empty.
93 function Available_View (Ent : Entity_Id) return Entity_Id;
94 -- Ent denotes an abstract state or a type that may come from a limited
95 -- with clause. Return the non-limited view of Ent if there is one or Ent
96 -- if this is not the case.
98 function Constant_Value (Ent : Entity_Id) return Node_Id;
99 -- Ent is a variable, constant, named integer, or named real entity. This
100 -- call obtains the initialization expression for the entity. Will return
101 -- Empty for a deferred constant whose full view is not available or
102 -- in some other cases of internal entities, which cannot be treated as
103 -- constants from the point of view of constant folding. Empty is also
104 -- returned for variables with no initialization expression.
106 function Enclosing_Dynamic_Scope (Ent : Entity_Id) return Entity_Id;
107 -- For any entity, Ent, returns the closest dynamic scope in which the
108 -- entity is declared or Standard_Standard for library-level entities.
110 function First_Discriminant (Typ : Entity_Id) return Entity_Id;
111 -- Typ is a type with discriminants. The discriminants are the first
112 -- entities declared in the type, so normally this is equivalent to
113 -- First_Entity. The exception arises for tagged types, where the tag
114 -- itself is prepended to the front of the entity chain, so the
115 -- First_Discriminant function steps past the tag if it is present.
117 function First_Stored_Discriminant (Typ : Entity_Id) return Entity_Id;
118 -- Typ is a type with discriminants. Gives the first discriminant stored
119 -- in an object of this type. In many cases, these are the same as the
120 -- normal visible discriminants for the type, but in the case of renamed
121 -- discriminants, this is not always the case.
123 -- For tagged types, and untagged types which are root types or derived
124 -- types but which do not rename discriminants in their root type, the
125 -- stored discriminants are the same as the actual discriminants of the
126 -- type, and hence this function is the same as First_Discriminant.
128 -- For derived non-tagged types that rename discriminants in the root type
129 -- this is the first of the discriminants that occur in the root type. To
130 -- be precise, in this case stored discriminants are entities attached to
131 -- the entity chain of the derived type which are a copy of the
132 -- discriminants of the root type. Furthermore their Is_Completely_Hidden
133 -- flag is set since although they are actually stored in the object, they
134 -- are not in the set of discriminants that is visible in the type.
136 -- For derived untagged types, the set of stored discriminants are the real
137 -- discriminants from Gigi's standpoint, i.e. those that will be stored in
138 -- actual objects of the type.
140 function First_Subtype (Typ : Entity_Id) return Entity_Id;
141 -- Applies to all types and subtypes. For types, yields the first subtype
142 -- of the type. For subtypes, yields the first subtype of the base type of
143 -- the subtype.
145 function First_Tag_Component (Typ : Entity_Id) return Entity_Id;
146 -- Typ must be a tagged record type. This function returns the Entity for
147 -- the first _Tag field in the record type.
149 function Get_Rep_Item
150 (E : Entity_Id;
151 Nam : Name_Id;
152 Check_Parents : Boolean := True) return Node_Id;
153 -- Searches the Rep_Item chain for a given entity E, for an instance of a
154 -- rep item (pragma, attribute definition clause, or aspect specification)
155 -- whose name matches the given name Nam. If Check_Parents is False then it
156 -- only returns rep item that has been directly specified for E (and not
157 -- inherited from its parents, if any). If one is found, it is returned,
158 -- otherwise Empty is returned. A special case is that when Nam is
159 -- Name_Priority, the call will also find Interrupt_Priority.
161 function Get_Rep_Item
162 (E : Entity_Id;
163 Nam1 : Name_Id;
164 Nam2 : Name_Id;
165 Check_Parents : Boolean := True) return Node_Id;
166 -- Searches the Rep_Item chain for a given entity E, for an instance of a
167 -- rep item (pragma, attribute definition clause, or aspect specification)
168 -- whose name matches one of the given names Nam1 or Nam2. If Check_Parents
169 -- is False then it only returns rep item that has been directly specified
170 -- for E (and not inherited from its parents, if any). If one is found, it
171 -- is returned, otherwise Empty is returned. A special case is that when
172 -- one of the given names is Name_Priority, the call will also find
173 -- Interrupt_Priority.
175 function Get_Rep_Pragma
176 (E : Entity_Id;
177 Nam : Name_Id;
178 Check_Parents : Boolean := True) return Node_Id;
179 -- Searches the Rep_Item chain for a given entity E, for an instance of a
180 -- representation pragma whose name matches the given name Nam. If
181 -- Check_Parents is False then it only returns representation pragma that
182 -- has been directly specified for E (and not inherited from its parents,
183 -- if any). If one is found and if it is the first rep item in the list
184 -- that matches Nam, it is returned, otherwise Empty is returned. A special
185 -- case is that when Nam is Name_Priority, the call will also find
186 -- Interrupt_Priority.
188 function Get_Rep_Pragma
189 (E : Entity_Id;
190 Nam1 : Name_Id;
191 Nam2 : Name_Id;
192 Check_Parents : Boolean := True) return Node_Id;
193 -- Searches the Rep_Item chain for a given entity E, for an instance of a
194 -- representation pragma whose name matches one of the given names Nam1 or
195 -- Nam2. If Check_Parents is False then it only returns representation
196 -- pragma that has been directly specified for E (and not inherited from
197 -- its parents, if any). If one is found and if it is the first rep item in
198 -- the list that matches one of the given names, it is returned, otherwise
199 -- Empty is returned. A special case is that when one of the given names is
200 -- Name_Priority, the call will also find Interrupt_Priority.
202 function Has_Rep_Item
203 (E : Entity_Id;
204 Nam : Name_Id;
205 Check_Parents : Boolean := True) return Boolean;
206 -- Searches the Rep_Item chain for the given entity E, for an instance of a
207 -- rep item (pragma, attribute definition clause, or aspect specification)
208 -- with the given name Nam. If Check_Parents is False then it only checks
209 -- for a rep item that has been directly specified for E (and not inherited
210 -- from its parents, if any). If found then True is returned, otherwise
211 -- False indicates that no matching entry was found.
213 function Has_Rep_Item
214 (E : Entity_Id;
215 Nam1 : Name_Id;
216 Nam2 : Name_Id;
217 Check_Parents : Boolean := True) return Boolean;
218 -- Searches the Rep_Item chain for the given entity E, for an instance of a
219 -- rep item (pragma, attribute definition clause, or aspect specification)
220 -- with the given names Nam1 or Nam2. If Check_Parents is False then it
221 -- only checks for a rep item that has been directly specified for E (and
222 -- not inherited from its parents, if any). If found then True is returned,
223 -- otherwise False indicates that no matching entry was found.
225 function Has_Rep_Pragma
226 (E : Entity_Id;
227 Nam : Name_Id;
228 Check_Parents : Boolean := True) return Boolean;
229 -- Searches the Rep_Item chain for the given entity E, for an instance of a
230 -- representation pragma with the given name Nam. If Check_Parents is False
231 -- then it only checks for a representation pragma that has been directly
232 -- specified for E (and not inherited from its parents, if any). If found
233 -- and if it is the first rep item in the list that matches Nam then True
234 -- is returned, otherwise False indicates that no matching entry was found.
236 function Has_Rep_Pragma
237 (E : Entity_Id;
238 Nam1 : Name_Id;
239 Nam2 : Name_Id;
240 Check_Parents : Boolean := True) return Boolean;
241 -- Searches the Rep_Item chain for the given entity E, for an instance of a
242 -- representation pragma with the given names Nam1 or Nam2. If
243 -- Check_Parents is False then it only checks for a rep item that has been
244 -- directly specified for E (and not inherited from its parents, if any).
245 -- If found and if it is the first rep item in the list that matches one of
246 -- the given names then True is returned, otherwise False indicates that no
247 -- matching entry was found.
249 function Has_Unconstrained_Elements (T : Entity_Id) return Boolean;
250 -- True if T has discriminants and is unconstrained, or is an array type
251 -- whose element type Has_Unconstrained_Elements.
253 function In_Generic_Body (Id : Entity_Id) return Boolean;
254 -- Determine whether entity Id appears inside a generic body
256 function Initialization_Suppressed (Typ : Entity_Id) return Boolean;
257 pragma Inline (Initialization_Suppressed);
258 -- Returns True if initialization should be suppressed for the given type
259 -- or subtype. This is true if Suppress_Initialization is set either for
260 -- the subtype itself, or for the corresponding base type.
262 function Is_Body (N : Node_Id) return Boolean;
263 -- Determine whether an arbitrary node denotes a body
265 function Is_By_Copy_Type (Ent : Entity_Id) return Boolean;
266 -- Ent is any entity. Returns True if Ent is a type entity where the type
267 -- is required to be passed by copy, as defined in (RM 6.2(3)).
269 function Is_By_Reference_Type (Ent : Entity_Id) return Boolean;
270 -- Ent is any entity. Returns True if Ent is a type entity where the type
271 -- is required to be passed by reference, as defined in (RM 6.2(4-9)).
273 function Is_Derived_Type (Ent : Entity_Id) return Boolean;
274 -- Determines if the given entity Ent is a derived type. Result is always
275 -- false if argument is not a type.
277 function Is_Generic_Formal (E : Entity_Id) return Boolean;
278 -- Determine whether E is a generic formal parameter. In particular this is
279 -- used to set the visibility of generic formals of a generic package
280 -- declared with a box or with partial parametrization.
282 function Is_Indefinite_Subtype (Ent : Entity_Id) return Boolean;
283 -- Ent is any entity. Determines if given entity is an unconstrained array
284 -- type or subtype, a discriminated record type or subtype with no initial
285 -- discriminant values or a class wide type or subtype and returns True if
286 -- so. False for other type entities, or any entities that are not types.
288 function Is_Immutably_Limited_Type (Ent : Entity_Id) return Boolean;
289 -- Implements definition in Ada 2012 RM-7.5 (8.1/3). This differs from the
290 -- following predicate in that an untagged record with immutably limited
291 -- components is NOT by itself immutably limited. This matters, e.g. when
292 -- checking the legality of an access to the current instance.
294 function Is_Limited_View (Ent : Entity_Id) return Boolean;
295 -- Ent is any entity. True for a type that is "inherently" limited (i.e.
296 -- cannot become nonlimited). From the Ada 2005 RM-7.5(8.1/2), "a type with
297 -- a part that is of a task, protected, or explicitly limited record type".
298 -- These are the types that are defined as return-by-reference types in Ada
299 -- 95 (see RM95-6.5(11-16)). In Ada 2005, these are the types that require
300 -- build-in-place for function calls. Note that build-in-place is allowed
301 -- for other types, too. This is also used for identifying pure procedures
302 -- whose calls should not be eliminated (RM 10.2.1(18/2)).
304 function Is_Limited_Type (Ent : Entity_Id) return Boolean;
305 -- Ent is any entity. Returns true if Ent is a limited type (limited
306 -- private type, limited interface type, task type, protected type,
307 -- composite containing a limited component, or a subtype of any of
308 -- these types). This older routine overlaps with the previous one, this
309 -- should be cleaned up???
311 function Nearest_Ancestor (Typ : Entity_Id) return Entity_Id;
312 -- Given a subtype Typ, this function finds out the nearest ancestor from
313 -- which constraints and predicates are inherited. There is no simple link
314 -- for doing this, consider:
316 -- subtype R is Integer range 1 .. 10;
317 -- type T is new R;
319 -- In this case the nearest ancestor is R, but the Etype of T'Base will
320 -- point to R'Base, so we have to go rummaging in the declarations to get
321 -- this information. It is used for making sure we freeze this before we
322 -- freeze Typ, and also for retrieving inherited predicate information.
323 -- For the case of base types or first subtypes, there is no useful entity
324 -- to return, so Empty is returned.
326 -- Note: this is similar to Ancestor_Subtype except that it also deals
327 -- with the case of derived types.
329 function Nearest_Dynamic_Scope (Ent : Entity_Id) return Entity_Id;
330 -- This is similar to Enclosing_Dynamic_Scope except that if Ent is itself
331 -- a dynamic scope, then it is returned. Otherwise the result is the same
332 -- as that returned by Enclosing_Dynamic_Scope.
334 function Next_Tag_Component (Tag : Entity_Id) return Entity_Id;
335 -- Tag must be an entity representing a _Tag field of a tagged record.
336 -- The result returned is the next _Tag field in this record, or Empty
337 -- if this is the last such field.
339 function Number_Discriminants (Typ : Entity_Id) return Pos;
340 -- Typ is a type with discriminants, yields number of discriminants in type
342 function Object_Type_Has_Constrained_Partial_View
343 (Typ : Entity_Id;
344 Scop : Entity_Id) return Boolean;
345 -- Return True if type of object has attribute Has_Constrained_Partial_View
346 -- set to True; in addition, within a generic body, return True if subtype
347 -- of the object is a descendant of an untagged generic formal private or
348 -- derived type, and the subtype is not an unconstrained array subtype
349 -- (RM 3.3(23.10/3)).
351 function Ultimate_Alias (Prim : Entity_Id) return Entity_Id;
352 pragma Inline (Ultimate_Alias);
353 -- Return the last entity in the chain of aliased entities of Prim. If Prim
354 -- has no alias return Prim.
356 function Unit_Declaration_Node (Unit_Id : Entity_Id) return Node_Id;
357 -- Unit_Id is the simple name of a program unit, this function returns the
358 -- corresponding xxx_Declaration node for the entity. Also applies to the
359 -- body entities for subprograms, tasks and protected units, in which case
360 -- it returns the subprogram, task or protected body node for it. The unit
361 -- may be a child unit with any number of ancestors.
363 function Package_Specification (Pack_Id : Entity_Id) return Node_Id;
364 -- Given an entity for a package or generic package, return corresponding
365 -- package specification. Simplifies handling of child units, and better
366 -- than the old idiom: Specification (Unit_Declaration_Node (Pack_Id)).
367 end Sem_Aux;