annotate gcc/ada/freeze.ads @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- F R E E Z E --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 with Types; use Types;
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 package Freeze is
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 --------------------------
kono
parents:
diff changeset
31 -- Handling of Freezing --
kono
parents:
diff changeset
32 --------------------------
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 -- In the formal Ada semantics, freezing of entities occurs at a well
kono
parents:
diff changeset
35 -- defined point, described in (RM 13.14). The model in GNAT of freezing
kono
parents:
diff changeset
36 -- is that a Freeze_Entity node is generated at the point where an entity
kono
parents:
diff changeset
37 -- is frozen, and the entity contains a pointer (Freeze_Node) to this
kono
parents:
diff changeset
38 -- generated freeze node.
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 -- The freeze node is processed in the expander to generate associated
kono
parents:
diff changeset
41 -- data and subprograms (e.g. an initialization procedure) which must
kono
parents:
diff changeset
42 -- be delayed until the type is frozen and its representation can be
kono
parents:
diff changeset
43 -- fully determined. Subsequently the freeze node is used by Gigi to
kono
parents:
diff changeset
44 -- determine the point at which it should elaborate the corresponding
kono
parents:
diff changeset
45 -- entity (this elaboration also requires the representation of the
kono
parents:
diff changeset
46 -- entity to be fully determinable). The freeze node is also used to
kono
parents:
diff changeset
47 -- provide additional diagnostic information (pinpointing the freeze
kono
parents:
diff changeset
48 -- point), when order of freezing errors are detected.
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 -- If we were fully faithful to the Ada model, we would generate freeze
kono
parents:
diff changeset
51 -- nodes for all entities, but that is a bit heavy so we optimize (that
kono
parents:
diff changeset
52 -- is the nice word) or cut corners (which is a bit more honest). For
kono
parents:
diff changeset
53 -- many entities, we do not need to delay the freeze and instead can
kono
parents:
diff changeset
54 -- freeze them at the point of declaration. The conditions for this
kono
parents:
diff changeset
55 -- early freezing being permissible are as follows:
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 -- There is no associated expander activity that needs to be delayed
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 -- Gigi can fully elaborate the entity at the point of occurrence (or,
kono
parents:
diff changeset
60 -- equivalently, no real elaboration is required for the entity).
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 -- In order for these conditions to be met (especially the second), it
kono
parents:
diff changeset
63 -- must be the case that all representation characteristics of the entity
kono
parents:
diff changeset
64 -- can be determined at declaration time.
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 -- The following indicates how freezing is handled for all entity kinds:
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 -- Types
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 -- All declared types have freeze nodes, as well as anonymous base
kono
parents:
diff changeset
71 -- types created for type declarations where the defining identifier
kono
parents:
diff changeset
72 -- is a first subtype of the anonymous type.
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 -- Subtypes
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 -- All first subtypes have freeze nodes. Other subtypes need freeze
kono
parents:
diff changeset
77 -- nodes if the corresponding base type has not yet been frozen. If
kono
parents:
diff changeset
78 -- the base type has been frozen, then there is no need for a freeze
kono
parents:
diff changeset
79 -- node, since no rep clauses can appear for the subtype in any case.
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 -- Implicit types and subtypes
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 -- As noted above, implicit base types always have freeze nodes. Other
kono
parents:
diff changeset
84 -- implicit types and subtypes typically do not require freeze nodes,
kono
parents:
diff changeset
85 -- because there is no possibility of delaying any information about
kono
parents:
diff changeset
86 -- their representation.
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 -- Subprograms
kono
parents:
diff changeset
89 --
kono
parents:
diff changeset
90 -- Are frozen at the point of declaration unless one or more of the
kono
parents:
diff changeset
91 -- formal types or return type themselves have delayed freezing and
kono
parents:
diff changeset
92 -- are not yet frozen. This includes the case of a formal access type
kono
parents:
diff changeset
93 -- where the designated type is not frozen. Note that we are talking
kono
parents:
diff changeset
94 -- about subprogram specs here (subprogram body entities have no
kono
parents:
diff changeset
95 -- relevance), and in any case, subprogram bodies freeze everything.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 -- Objects with dynamic address clauses
kono
parents:
diff changeset
98 --
kono
parents:
diff changeset
99 -- These have a delayed freeze. Gigi will generate code to evaluate
kono
parents:
diff changeset
100 -- the initialization expression if present and store it in a temp.
kono
parents:
diff changeset
101 -- The actual object is created at the point of the freeze, and if
kono
parents:
diff changeset
102 -- necessary initialized by copying the value of this temporary.
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 -- Formal Parameters
kono
parents:
diff changeset
105 --
kono
parents:
diff changeset
106 -- Are frozen when the associated subprogram is frozen, so there is
kono
parents:
diff changeset
107 -- never any need for them to have delayed freezing.
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 -- Other Objects
kono
parents:
diff changeset
110 --
kono
parents:
diff changeset
111 -- Are always frozen at the point of declaration
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 -- All Other Entities
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 -- Are always frozen at the point of declaration
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 -- The flag Has_Delayed_Freeze is used to indicate that delayed freezing
kono
parents:
diff changeset
118 -- is required. Usually the associated freeze node is allocated at the
kono
parents:
diff changeset
119 -- freezing point. One special exception occurs with anonymous base types,
kono
parents:
diff changeset
120 -- where the freeze node is preallocated at the point of declaration, so
kono
parents:
diff changeset
121 -- that the First_Subtype_Link field can be set.
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 Freezing_Library_Level_Tagged_Type : Boolean := False;
kono
parents:
diff changeset
124 -- Flag used to indicate that we are freezing the primitives of a library
kono
parents:
diff changeset
125 -- level tagged type. Used to disable checks on premature freezing.
kono
parents:
diff changeset
126 -- More documentation needed??? why is this flag needed? what are these
kono
parents:
diff changeset
127 -- checks? why do they need disabling in some cases?
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 -----------------
kono
parents:
diff changeset
130 -- Subprograms --
kono
parents:
diff changeset
131 -----------------
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 function Build_Renamed_Body
kono
parents:
diff changeset
134 (Decl : Node_Id;
kono
parents:
diff changeset
135 New_S : Entity_Id) return Node_Id;
kono
parents:
diff changeset
136 -- Rewrite renaming declaration as a subprogram body, whose single
kono
parents:
diff changeset
137 -- statement is a call to the renamed entity. New_S is the entity that
kono
parents:
diff changeset
138 -- appears in the renaming declaration. If this is a Renaming_As_Body,
kono
parents:
diff changeset
139 -- then Decl is the original subprogram declaration that is completed
kono
parents:
diff changeset
140 -- by the renaming, otherwise it is the renaming declaration itself.
kono
parents:
diff changeset
141 -- The caller inserts the body where required. If this call comes
kono
parents:
diff changeset
142 -- from a freezing action, the resulting body is analyzed at once.
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 procedure Check_Compile_Time_Size (T : Entity_Id);
kono
parents:
diff changeset
145 -- Check to see whether the size of the type T is known at compile time.
kono
parents:
diff changeset
146 -- There are three possible cases:
kono
parents:
diff changeset
147 --
kono
parents:
diff changeset
148 -- Size is not known at compile time. In this case, the call has no
kono
parents:
diff changeset
149 -- effect. Note that the processing is conservative here, in the sense
kono
parents:
diff changeset
150 -- that this routine may decide that the size is not known even if in
kono
parents:
diff changeset
151 -- fact Gigi decides it is known, but the opposite situation can never
kono
parents:
diff changeset
152 -- occur.
kono
parents:
diff changeset
153 --
kono
parents:
diff changeset
154 -- Size is known at compile time, but the actual value of the size is not
kono
parents:
diff changeset
155 -- known to the front end or is definitely greater than 64. In this case,
kono
parents:
diff changeset
156 -- Size_Known_At_Compile_Time is set, but the RM_Size field is left set
kono
parents:
diff changeset
157 -- to zero (to be set by Gigi).
kono
parents:
diff changeset
158 --
kono
parents:
diff changeset
159 -- Size is known at compile time, and the actual value of the size is
kono
parents:
diff changeset
160 -- known to the front end and is not greater than 64. In this case, the
kono
parents:
diff changeset
161 -- flag Size_Known_At_Compile_Time is set, and in addition RM_Size is set
kono
parents:
diff changeset
162 -- to the required size, allowing for possible front end packing of an
kono
parents:
diff changeset
163 -- array using this type as a component type.
kono
parents:
diff changeset
164 --
kono
parents:
diff changeset
165 -- Note: the flag Size_Known_At_Compile_Time is used to determine if the
kono
parents:
diff changeset
166 -- secondary stack must be used to return a value of the type, and also
kono
parents:
diff changeset
167 -- to determine whether a component clause is allowed for a component
kono
parents:
diff changeset
168 -- of the given type.
kono
parents:
diff changeset
169 --
kono
parents:
diff changeset
170 -- Note: this is public because of one dubious use in Sem_Res???
kono
parents:
diff changeset
171 --
kono
parents:
diff changeset
172 -- Note: Check_Compile_Time_Size does not test the case of the size being
kono
parents:
diff changeset
173 -- known because a size clause is specifically given. That is because we
kono
parents:
diff changeset
174 -- do not allow a size clause if the size would not otherwise be known at
kono
parents:
diff changeset
175 -- compile time in any case.
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 function Is_Atomic_VFA_Aggregate (N : Node_Id) return Boolean;
kono
parents:
diff changeset
178 -- If an atomic/VFA object is initialized with an aggregate or is assigned
kono
parents:
diff changeset
179 -- an aggregate, we have to prevent a piecemeal access or assignment to the
kono
parents:
diff changeset
180 -- object, even if the aggregate is to be expanded. We create a temporary
kono
parents:
diff changeset
181 -- for the aggregate, and assign the temporary instead, so that the back
kono
parents:
diff changeset
182 -- end can generate an atomic move for it. This is only done in the context
kono
parents:
diff changeset
183 -- of an object declaration or an assignment. Function is a noop and
kono
parents:
diff changeset
184 -- returns false in other contexts.
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 procedure Explode_Initialization_Compound_Statement (E : Entity_Id);
kono
parents:
diff changeset
187 -- If Initialization_Statements (E) is an N_Compound_Statement, insert its
kono
parents:
diff changeset
188 -- actions in the enclosing list and reset the attribute.
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 function Freeze_Entity
kono
parents:
diff changeset
191 (E : Entity_Id;
kono
parents:
diff changeset
192 N : Node_Id;
kono
parents:
diff changeset
193 Do_Freeze_Profile : Boolean := True) return List_Id;
kono
parents:
diff changeset
194 -- Freeze an entity, and return Freeze nodes, to be inserted at the point
kono
parents:
diff changeset
195 -- of call. N is a node whose source location corresponds to the freeze
kono
parents:
diff changeset
196 -- point. This is used in placing warning messages in the situation where
kono
parents:
diff changeset
197 -- it appears that a type has been frozen too early, e.g. when a primitive
kono
parents:
diff changeset
198 -- operation is declared after the freezing point of its tagged type.
kono
parents:
diff changeset
199 -- Returns No_List if no freeze nodes needed. Parameter Do_Freeze_Profile
kono
parents:
diff changeset
200 -- is used when E is a subprogram, and determines whether the profile of
kono
parents:
diff changeset
201 -- the subprogram should be frozen as well.
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 procedure Freeze_All (From : Entity_Id; After : in out Node_Id);
kono
parents:
diff changeset
204 -- Before a non-instance body, or at the end of a declarative part,
kono
parents:
diff changeset
205 -- freeze all entities therein that are not yet frozen. Calls itself
kono
parents:
diff changeset
206 -- recursively to catch types in inner packages that were not frozen
kono
parents:
diff changeset
207 -- at the inner level because they were not yet completely defined.
kono
parents:
diff changeset
208 -- This routine also analyzes and freezes default parameter expressions
kono
parents:
diff changeset
209 -- in subprogram specifications (this has to be delayed until all the
kono
parents:
diff changeset
210 -- types are frozen). The resulting freeze nodes are inserted just
kono
parents:
diff changeset
211 -- after node After (which is a list node) and analyzed. On return,
kono
parents:
diff changeset
212 -- 'After' is updated to point to the last node inserted (or is returned
kono
parents:
diff changeset
213 -- unchanged if no nodes were inserted). 'From' is the last entity frozen
kono
parents:
diff changeset
214 -- in the scope. It is used to prevent a quadratic traversal over already
kono
parents:
diff changeset
215 -- frozen entities.
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 procedure Freeze_Before
kono
parents:
diff changeset
218 (N : Node_Id;
kono
parents:
diff changeset
219 T : Entity_Id;
kono
parents:
diff changeset
220 Do_Freeze_Profile : Boolean := True);
kono
parents:
diff changeset
221 -- Freeze T then Insert the generated Freeze nodes before the node N. Flag
kono
parents:
diff changeset
222 -- Do_Freeze_Profile is used when T is an overloadable entity and indicates
kono
parents:
diff changeset
223 -- whether its profile should be frozen at the same time.
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 procedure Freeze_Expression (N : Node_Id);
kono
parents:
diff changeset
226 -- Freezes the required entities when the Expression N causes freezing.
kono
parents:
diff changeset
227 -- The node N here is either a subexpression node (a "real" expression)
kono
parents:
diff changeset
228 -- or a subtype mark, or a subtype indication. The latter two cases are
kono
parents:
diff changeset
229 -- not really expressions, but they can appear within expressions and
kono
parents:
diff changeset
230 -- so need to be similarly treated. Freeze_Expression takes care of
kono
parents:
diff changeset
231 -- determining the proper insertion point for generated freeze actions.
kono
parents:
diff changeset
232
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
233 procedure Freeze_Expr_Types
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
234 (Def_Id : Entity_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
235 Typ : Entity_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
236 Expr : Node_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
237 N : Node_Id);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
238 -- N is the body constructed for an expression function that is a
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
239 -- completion, and Def_Id is the function being completed.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
240 -- This procedure freezes before N all the types referenced in Expr,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
241 -- which is either the expression of the expression function, or
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
242 -- the expression in a pre/post aspect that applies to Def_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
243
111
kono
parents:
diff changeset
244 procedure Freeze_Fixed_Point_Type (Typ : Entity_Id);
kono
parents:
diff changeset
245 -- Freeze fixed point type. For fixed-point types, we have to defer
kono
parents:
diff changeset
246 -- setting the size and bounds till the freeze point, since they are
kono
parents:
diff changeset
247 -- potentially affected by the presence of size and small clauses.
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 procedure Freeze_Itype (T : Entity_Id; N : Node_Id);
kono
parents:
diff changeset
250 -- This routine is called when an Itype is created and must be frozen
kono
parents:
diff changeset
251 -- immediately at the point of creation (for the sake of the expansion
kono
parents:
diff changeset
252 -- activities in Exp_Ch3 (for example, the creation of packed array
kono
parents:
diff changeset
253 -- types). We can't just let Freeze_Expression do this job since it
kono
parents:
diff changeset
254 -- goes out of its way to make sure that the freeze node occurs at a
kono
parents:
diff changeset
255 -- point outside the current construct, e.g. outside the expression or
kono
parents:
diff changeset
256 -- outside the initialization procedure. That's normally right, but
kono
parents:
diff changeset
257 -- not in this case, since if we create an Itype in an expression it
kono
parents:
diff changeset
258 -- may be the case that it is not always elaborated (for example it
kono
parents:
diff changeset
259 -- may result from the right operand of a short circuit). In this case
kono
parents:
diff changeset
260 -- we want the freeze node to be inserted at the same point as the Itype.
kono
parents:
diff changeset
261 -- The node N provides both the location for the freezing and also the
kono
parents:
diff changeset
262 -- insertion point for the resulting freeze nodes.
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 end Freeze;