FSF GCC merge 02/23/03
[official-gcc.git] / gcc / ada / freeze.ads
blobc628d7c8b218fd7ad92cddc369ad70cfb3b0bd31
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- F R E E Z E --
6 -- --
7 -- S p e c --
8 -- --
9 -- --
10 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 -- --
26 ------------------------------------------------------------------------------
28 with Types; use Types;
30 package Freeze is
32 --------------------------
33 -- Handling of Freezing --
34 --------------------------
36 -- In the formal Ada semantics, freezing of entities occurs at a well
37 -- defined point, described in (RM 13.14). The model in GNAT of freezing
38 -- is that a Freeze_Entity node is generated at the point where an entity
39 -- is frozen, and the entity contains a pointer (Freeze_Node) to this
40 -- generated freeze node.
42 -- The freeze node is processed in the expander to generate associated
43 -- data and subprograms (e.g. an initialization procedure) which must
44 -- be delayed until the type is frozen and its representation can be
45 -- fully determined. Subsequently the freeze node is used by Gigi to
46 -- determine the point at which it should elaborate the corresponding
47 -- entity (this elaboration also requires the representation of the
48 -- entity to be fully determinable). The freeze node is also used to
49 -- provide additional diagnostic information (pinpointing the freeze
50 -- point), when order of freezing errors are detected.
52 -- If we were fully faithful to the Ada model, we would generate freeze
53 -- nodes for all entities, but that is a bit heavy so we optimize (that
54 -- is the nice word) or cut corners (which is a bit more honest). For
55 -- many entities, we do not need to delay the freeze and instead can
56 -- freeze them at the point of declaration. The conditions for this
57 -- early freezing being permissible are as follows:
59 -- There is no associated expander activity that needs to be delayed
61 -- Gigi can fully elaborate the entity at the point of occurrence (or,
62 -- equivalently, no real elaboration is required for the entity).
64 -- In order for these conditions to be met (especially the second), it
65 -- must be the case that all representation characteristics of the entity
66 -- can be determined at declaration time.
68 -- The following indicates how freezing is handled for all entity kinds:
70 -- Types
72 -- All declared types have freeze nodes, as well as anonymous base
73 -- types created for type declarations where the defining identifier
74 -- is a first subtype of the anonymous type.
76 -- Subtypes
78 -- All first subtypes have freeze nodes. Other subtypes need freeze
79 -- nodes if the corresponding base type has not yet been frozen. If
80 -- the base type has been frozen, then there is no need for a freeze
81 -- node, since no rep clauses can appear for the subtype in any case.
83 -- Implicit types and subtypes
85 -- As noted above, implicit base types always have freeze nodes. Other
86 -- implicit types and subtypes typically do not require freeze nodes,
87 -- because there is no possibility of delaying any information about
88 -- their representation.
90 -- Subprograms
92 -- Are frozen at the point of declaration unless one or more of the
93 -- formal types or return type themselves have delayed freezing and
94 -- are not yet frozen. This includes the case of a formal access type
95 -- where the designated type is not frozen. Note that we are talking
96 -- about subprogram specs here (subprogram body entities have no
97 -- relevance), and in any case, subprogram bodies freeze everything.
99 -- Objects with dynamic address clauses
101 -- These have a delayed freeze. Gigi will generate code to evaluate
102 -- the initialization expression if present and store it in a temp.
103 -- The actual object is created at the point of the freeze, and if
104 -- necessary initialized by copying the value of this temporary.
106 -- Formal Parameters
108 -- Are frozen when the associated subprogram is frozen, so there is
109 -- never any need for them to have delayed freezing.
111 -- Other Objects
113 -- Are always frozen at the point of declaration
115 -- All Other Entities
117 -- Are always frozen at the point of declaration
119 -- The flag Has_Delayed_Freeze is used for to indicate that delayed
120 -- freezing is required. Usually the associated freeze node is allocated
121 -- at the freezing point. One special exception occurs with anonymous
122 -- base types, where the freeze node is preallocated at the point of
123 -- declaration, so that the First_Subtype_Link field can be set.
125 -----------------
126 -- Subprograms --
127 -----------------
129 function Build_Renamed_Body
130 (Decl : Node_Id;
131 New_S : Entity_Id)
132 return Node_Id;
133 -- Rewrite renaming declaration as a subprogram body, whose single
134 -- statement is a call to the renamed entity. New_S is the entity that
135 -- appears in the renaming declaration. If this is a Renaming_As_Body,
136 -- then Decl is the original subprogram declaration that is completed
137 -- by the renaming, otherwise it is the renaming declaration itself.
138 -- The caller inserts the body where required. If this call comes
139 -- from a freezing action, the resulting body is analyzed at once.
141 procedure Check_Compile_Time_Size (T : Entity_Id);
142 -- Check to see whether the size of the type T is known at compile time.
143 -- There are three possible cases:
145 -- Size is not known at compile time. In this case, the call has no
146 -- effect. Note that the processing is conservative here, in the sense
147 -- that this routine may decide that the size is not known even if in
148 -- fact Gigi decides it is known, but the opposite situation can never
149 -- occur.
151 -- Size is known at compile time, but the actual value of the size is
152 -- not known to the front end or is definitely 32 or more. In this case
153 -- Size_Known_At_Compile_Time is set, but the Esize field is left set
154 -- to zero (to be set by Gigi).
156 -- Size is known at compile time, and the actual value of the size is
157 -- known to the front end and is less than 32. In this case, the flag
158 -- Size_Known_At_Compile_Time is set, and in addition Esize is set to
159 -- the required size, allowing for possible front end packing of an
160 -- array using this type as a component type.
162 -- Note: the flag Size_Known_At_Compile_Time is used to determine if the
163 -- secondary stack must be used to return a value of the type, and also
164 -- to determine whether a component clause is allowed for a component
165 -- of the given type.
167 -- Note: this is public because of one dubious use in Sem_Res???
169 -- Note: Check_Compile_Time_Size does not test the case of the size being
170 -- known because a size clause is specifically given. That is because we
171 -- do not allow a size clause if the size would not otherwise be known at
172 -- compile time in any case.
174 function Freeze_Entity (E : Entity_Id; Loc : Source_Ptr) return List_Id;
175 -- Freeze an entity, and return Freeze nodes, to be inserted at the
176 -- point of call. Loc is a source location which corresponds to the
177 -- freeze point. This is used in placing warning messages in the
178 -- situation where it appears that a type has been frozen too early,
179 -- e.g. when a primitive operation is declared after the freezing
180 -- point of its tagged type. Returns No_List if no freeze nodes needed.
182 procedure Freeze_All (From : Entity_Id; After : in out Node_Id);
183 -- Before a non-instance body, or at the end of a declarative part
184 -- freeze all entities therein that are not yet frozen. Calls itself
185 -- recursively to catch types in inner packages that were not frozen
186 -- at the inner level because they were not yet completely defined.
187 -- This routine also analyzes and freezes default parameter expressions
188 -- in subprogram specifications (this has to be delayed until all the
189 -- types are frozen). The resulting freeze nodes are inserted just
190 -- after node After (which is a list node) and analyzed. On return,
191 -- 'After' is updated to point to the last node inserted (or is returned
192 -- unchanged if no nodes were inserted). 'From' is the last entity frozen
193 -- in the scope. It is used to prevent a quadratic traversal over already
194 -- frozen entities.
196 procedure Freeze_Before (N : Node_Id; T : Entity_Id);
197 -- Freeze T then Insert the generated Freeze nodes before the node N.
199 procedure Freeze_Expression (N : Node_Id);
200 -- Freezes the required entities when the Expression N causes freezing.
201 -- The node N here is either a subexpression node (a "real" expression)
202 -- or a subtype mark, or a subtype indication. The latter two cases are
203 -- not really expressions, but they can appear within expressions and
204 -- so need to be similarly treated. Freeze_Expression takes care of
205 -- determining the proper insertion point for generated freeze actions.
207 procedure Freeze_Fixed_Point_Type (Typ : Entity_Id);
208 -- Freeze fixed point type. For fixed-point types, we have to defer
209 -- setting the size and bounds till the freeze point, since they are
210 -- potentially affected by the presence of size and small clauses.
212 procedure Freeze_Itype (T : Entity_Id; N : Node_Id);
213 -- This routine is called when an Itype is created and must be frozen
214 -- immediately at the point of creation (for the sake of the expansion
215 -- activities in Exp_Ch3 (for example, the creation of packed array
216 -- types). We can't just let Freeze_Expression do this job since it
217 -- goes out of its way to make sure that the freeze node occurs at a
218 -- point outside the current construct, e.g. outside the expression or
219 -- outside the initialization procedure. That's normally right, but
220 -- not in this case, since if we create an Itype in an expression it
221 -- may be the case that it is not always elaborated (for example it
222 -- may result from the right operand of a short circuit). In this case
223 -- we want the freeze node to be inserted at the same point as the Itype.
224 -- The node N provides both the location for the freezing and also the
225 -- insertion point for the resulting freeze nodes.
227 end Freeze;