1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with Types
; use Types
;
28 with Uintp
; use Uintp
;
31 procedure Analyze_At_Clause
(N
: Node_Id
);
32 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
);
33 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
);
34 procedure Analyze_Free_Statement
(N
: Node_Id
);
35 procedure Analyze_Freeze_Entity
(N
: Node_Id
);
36 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
);
37 procedure Analyze_Code_Statement
(N
: Node_Id
);
39 procedure Analyze_Aspect_Specifications
43 -- This procedure is called to analyze aspect spefications for node N. E is
44 -- the corresponding entity declared by the declaration node N, and L is
45 -- the list of aspect specifications for this node. If L is No_List, the
46 -- call is ignored. Note that we can't use a simpler interface of just
47 -- passing the node N, since the analysis of the node may cause it to be
48 -- rewritten to a node not permitting aspect specifications.
50 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
);
51 -- Called from Freeze where R is a record entity for which reverse bit
52 -- order is specified and there is at least one component clause. Adjusts
53 -- component positions according to either Ada 95 or Ada 2005 (AI-133).
55 procedure Build_Invariant_Procedure
(Typ
: Entity_Id
; N
: Node_Id
);
56 -- Typ is a private type with invariants (indicated by Has_Invariants being
57 -- set for Typ, indicating the presence of pragma Invariant entries on the
58 -- rep chain, note that Invariant aspects have already been converted to
59 -- pragma Invariant), then this procedure builds the spec and body for the
60 -- corresponding Invariant procedure, inserting them at appropriate points
61 -- in the package specification N. Invariant_Procedure is set for Typ. Note
62 -- that this procedure is called at the end of processing the declarations
63 -- in the visible part (i.e. the right point for visibility analysis of
64 -- the invariant expression).
66 procedure Check_Record_Representation_Clause
(N
: Node_Id
);
67 -- This procedure completes the analysis of a record representation clause
68 -- N. It is called at freeze time after adjustment of component clause bit
69 -- positions for possible non-standard bit order. In the case of Ada 2005
70 -- (machine scalar) mode, this adjustment can make substantial changes, so
71 -- some checks, in particular for component overlaps cannot be done at the
72 -- time the record representation clause is first seen, but must be delayed
73 -- till freeze time, and in particular is called after calling the above
74 -- procedure for adjusting record bit positions for reverse bit order.
77 -- Initialize internal tables for new compilation
79 procedure Set_Enum_Esize
(T
: Entity_Id
);
80 -- This routine sets the Esize field for an enumeration type T, based
81 -- on the current representation information available for T. Note that
82 -- the setting of the RM_Size field is not affected. This routine also
83 -- initializes the alignment field to zero.
87 Biased
: Boolean := False) return Nat
;
88 -- Given an elementary type, determines the minimum number of bits required
89 -- to represent all values of the type. This function may not be called
90 -- with any other types. If the flag Biased is set True, then the minimum
91 -- size calculation that biased representation is used in the case of a
92 -- discrete type, e.g. the range 7..8 gives a minimum size of 4 with
93 -- Biased set to False, and 1 with Biased set to True. Note that the
94 -- biased parameter only has an effect if the type is not biased, it
95 -- causes Minimum_Size to indicate the minimum size of an object with
96 -- the given type, of the size the type would have if it were biased. If
97 -- the type is already biased, then Minimum_Size returns the biased size,
98 -- regardless of the setting of Biased. Also, fixed-point types are never
99 -- biased in the current implementation. If the size is not known at
100 -- compile time, this function returns 0.
102 procedure Check_Constant_Address_Clause
(Expr
: Node_Id
; U_Ent
: Entity_Id
);
103 -- Expr is an expression for an address clause. This procedure checks
104 -- that the expression is constant, in the limited sense that it is safe
105 -- to evaluate it at the point the object U_Ent is declared, rather than
106 -- at the point of the address clause. The condition for this to be true
107 -- is that the expression has no variables, no constants declared after
108 -- U_Ent, and no calls to non-pure functions. If this condition is not
109 -- met, then an appropriate error message is posted. This check is applied
110 -- at the point an object with an address clause is frozen, as well as for
111 -- address clauses for tasks and entries.
117 Biased
: out Boolean);
118 -- Called when size Siz is specified for subtype T. This subprogram checks
119 -- that the size is appropriate, posting errors on node N as required.
120 -- This check is effective for elementary types and bit-packed arrays.
121 -- For other non-elementary types, a check is only made if an explicit
122 -- size has been given for the type (and the specified size must match).
123 -- The parameter Biased is set False if the size specified did not require
124 -- the use of biased representation, and True if biased representation
125 -- was required to meet the size requirement. Note that Biased is only
126 -- set if the type is not currently biased, but biasing it is the only
127 -- way to meet the requirement. If the type is currently biased, then
128 -- this biased size is used in the initial check, and Biased is False.
129 -- If the size is too small, and an error message is given, then both
130 -- Esize and RM_Size are reset to the allowed minimum value in T.
132 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean;
133 -- Called at the start of processing a representation clause or a
134 -- representation pragma. Used to check that the representation item
135 -- is not being applied to an incomplete type or to a generic formal
136 -- type or a type derived from a generic formal type. Returns False if
137 -- no such error occurs. If this error does occur, appropriate error
138 -- messages are posted on node N, and True is returned.
140 function Rep_Item_Too_Late
143 FOnly
: Boolean := False) return Boolean;
144 -- Called at the start of processing a representation clause or a
145 -- representation pragma. Used to check that a representation item
146 -- for entity T does not appear too late (according to the rules in
147 -- RM 13.1(9) and RM 13.1(10)). N is the associated node, which in
148 -- the pragma case is the pragma or representation clause itself, used
149 -- for placing error messages if the item is too late.
151 -- Fonly is a flag that causes only the freezing rule (para 9) to be
152 -- applied, and the tests of para 10 are skipped. This is appropriate
153 -- for both subtype related attributes (Alignment and Size) and for
154 -- stream attributes, which, although certainly not subtype related
155 -- attributes, clearly should not be subject to the para 10 restrictions
156 -- (see AI95-00137). Similarly, we also skip the para 10 restrictions for
157 -- the Storage_Size case where they also clearly do not apply, and for
158 -- Stream_Convert which is in the same category as the stream attributes.
160 -- If the rep item is too late, an appropriate message is output and
161 -- True is returned, which is a signal that the caller should abandon
162 -- processing for the item. If the item is not too late, then False
163 -- is returned, and the caller can continue processing the item.
165 -- If no error is detected, this call also as a side effect links the
166 -- representation item onto the head of the representation item chain
167 -- (referenced by the First_Rep_Item field of the entity).
169 -- Note: Rep_Item_Too_Late must be called with the underlying type in
170 -- the case of a private or incomplete type. The protocol is to first
171 -- check for Rep_Item_Too_Early using the initial entity, then take the
172 -- underlying type, then call Rep_Item_Too_Late on the result.
174 -- Note: Calls to Rep_Item_Too_Late are ignored for the case of attribute
175 -- definition clauses which have From_Aspect_Specification set. This is
176 -- because such clauses are linked on to the Rep_Item chain in procedure
177 -- Sem_Ch13.Analyze_Aspect_Specifications. See that procedure for details.
179 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean;
180 -- Given two types, where the two types are related by possible derivation,
181 -- determines if the two types have the same representation, or different
182 -- representations, requiring the special processing for representation
183 -- change. A False result is possible only for array, enumeration or
186 procedure Validate_Unchecked_Conversion
188 Act_Unit
: Entity_Id
);
189 -- Validate a call to unchecked conversion. N is the node for the actual
190 -- instantiation, which is used only for error messages. Act_Unit is the
191 -- entity for the instantiation, from which the actual types etc. for this
192 -- instantiation can be determined. This procedure makes an entry in a
193 -- table and/or generates an N_Validate_Unchecked_Conversion node. The
194 -- actual checking is done in Validate_Unchecked_Conversions or in the
195 -- back end as required.
197 procedure Validate_Unchecked_Conversions
;
198 -- This routine is called after calling the backend to validate unchecked
199 -- conversions for size and alignment appropriateness. The reason it is
200 -- called that late is to take advantage of any back-annotation of size
201 -- and alignment performed by the backend.
203 procedure Validate_Address_Clauses
;
204 -- This is called after the back end has been called (and thus after the
205 -- alignments of objects have been back annotated). It goes through the
206 -- table of saved address clauses checking for suspicious alignments and
207 -- if necessary issuing warnings.
209 procedure Validate_Independence
;
210 -- This is called after the back end has been called (and thus after the
211 -- layout of components has been back annotated). It goes through the
212 -- table of saved pragma Independent[_Component] entries, checking that
213 -- independence can be achieved, and if necessary issuing error mssags.
215 -------------------------------------
216 -- Table for Validate_Independence --
217 -------------------------------------
219 -- If a legal pragma Independent or Independent_Components is given for
220 -- an entity, then an entry is made in this table, to be checked by a
221 -- call to Validate_Independence after back annotation of layout is done.
223 type Independence_Check_Record
is record
225 -- The pragma Independent or Independent_Components
228 -- The entity to which it applies
231 package Independence_Checks
is new Table
.Table
(
232 Table_Component_Type
=> Independence_Check_Record
,
233 Table_Index_Type
=> Int
,
234 Table_Low_Bound
=> 1,
236 Table_Increment
=> 200,
237 Table_Name
=> "Independence_Checks");