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