OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [ada/] [freeze.ads] - Blame information for rev 843

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.