]>
Commit | Line | Data |
---|---|---|
d6f39728 | 1 | ------------------------------------------------------------------------------ |
7189d17f | 2 | -- -- |
d6f39728 | 3 | -- GNAT COMPILER COMPONENTS -- |
4 | -- -- | |
5 | -- S E M _ C H 1 3 -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
9c20237a | 9 | -- Copyright (C) 1992-2016, Free Software Foundation, Inc. -- |
d6f39728 | 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- -- | |
80df182a | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
d6f39728 | 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 -- | |
80df182a | 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. -- | |
d6f39728 | 20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
e78e8c8e | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
d6f39728 | 23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
ae888dbd | 26 | with Aspects; use Aspects; |
d6f39728 | 27 | with Atree; use Atree; |
713c00d6 | 28 | with Checks; use Checks; |
175a6969 | 29 | with Debug; use Debug; |
d6f39728 | 30 | with Einfo; use Einfo; |
d00681a7 | 31 | with Elists; use Elists; |
d6f39728 | 32 | with Errout; use Errout; |
76a6b7c7 | 33 | with Expander; use Expander; |
d00681a7 | 34 | with Exp_Disp; use Exp_Disp; |
d6f39728 | 35 | with Exp_Tss; use Exp_Tss; |
36 | with Exp_Util; use Exp_Util; | |
37c6552c | 37 | with Freeze; use Freeze; |
f9e26ff7 | 38 | with Ghost; use Ghost; |
d6f39728 | 39 | with Lib; use Lib; |
83f8f0a6 | 40 | with Lib.Xref; use Lib.Xref; |
15ebb600 | 41 | with Namet; use Namet; |
d6f39728 | 42 | with Nlists; use Nlists; |
43 | with Nmake; use Nmake; | |
44 | with Opt; use Opt; | |
e0521a36 | 45 | with Restrict; use Restrict; |
46 | with Rident; use Rident; | |
d6f39728 | 47 | with Rtsfind; use Rtsfind; |
48 | with Sem; use Sem; | |
d60c9ff7 | 49 | with Sem_Aux; use Sem_Aux; |
be9124d0 | 50 | with Sem_Case; use Sem_Case; |
40ca69b9 | 51 | with Sem_Ch3; use Sem_Ch3; |
490beba6 | 52 | with Sem_Ch6; use Sem_Ch6; |
d6f39728 | 53 | with Sem_Ch8; use Sem_Ch8; |
85696508 | 54 | with Sem_Dim; use Sem_Dim; |
85377c9b | 55 | with Sem_Disp; use Sem_Disp; |
d6f39728 | 56 | with Sem_Eval; use Sem_Eval; |
51ea9c94 | 57 | with Sem_Prag; use Sem_Prag; |
d6f39728 | 58 | with Sem_Res; use Sem_Res; |
59 | with Sem_Type; use Sem_Type; | |
60 | with Sem_Util; use Sem_Util; | |
44e4341e | 61 | with Sem_Warn; use Sem_Warn; |
738ec25b | 62 | with Sinfo; use Sinfo; |
1e3c4ae6 | 63 | with Sinput; use Sinput; |
9dfe12ae | 64 | with Snames; use Snames; |
d6f39728 | 65 | with Stand; use Stand; |
93735cb8 | 66 | with Targparm; use Targparm; |
d6f39728 | 67 | with Ttypes; use Ttypes; |
68 | with Tbuild; use Tbuild; | |
69 | with Urealp; use Urealp; | |
f42f24d7 | 70 | with Warnsw; use Warnsw; |
d6f39728 | 71 | |
bfa5a9d9 | 72 | with GNAT.Heap_Sort_G; |
d6f39728 | 73 | |
74 | package body Sem_Ch13 is | |
75 | ||
76 | SSU : constant Pos := System_Storage_Unit; | |
77 | -- Convenient short hand for commonly used constant | |
78 | ||
79 | ----------------------- | |
80 | -- Local Subprograms -- | |
81 | ----------------------- | |
82 | ||
1d366b32 | 83 | procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint); |
84 | -- This routine is called after setting one of the sizes of type entity | |
85 | -- Typ to Size. The purpose is to deal with the situation of a derived | |
86 | -- type whose inherited alignment is no longer appropriate for the new | |
87 | -- size value. In this case, we reset the Alignment to unknown. | |
d6f39728 | 88 | |
eb66e842 | 89 | procedure Build_Discrete_Static_Predicate |
d97beb2f | 90 | (Typ : Entity_Id; |
91 | Expr : Node_Id; | |
92 | Nam : Name_Id); | |
d7c2851f | 93 | -- Given a predicated type Typ, where Typ is a discrete static subtype, |
94 | -- whose predicate expression is Expr, tests if Expr is a static predicate, | |
95 | -- and if so, builds the predicate range list. Nam is the name of the one | |
96 | -- argument to the predicate function. Occurrences of the type name in the | |
6fb3c314 | 97 | -- predicate expression have been replaced by identifier references to this |
d7c2851f | 98 | -- name, which is unique, so any identifier with Chars matching Nam must be |
99 | -- a reference to the type. If the predicate is non-static, this procedure | |
100 | -- returns doing nothing. If the predicate is static, then the predicate | |
5c6a5792 | 101 | -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is |
102 | -- rewritten as a canonicalized membership operation. | |
d97beb2f | 103 | |
ee2b7923 | 104 | function Build_Export_Import_Pragma |
105 | (Asp : Node_Id; | |
106 | Id : Entity_Id) return Node_Id; | |
107 | -- Create the corresponding pragma for aspect Export or Import denoted by | |
108 | -- Asp. Id is the related entity subject to the aspect. Return Empty when | |
109 | -- the expression of aspect Asp evaluates to False or is erroneous. | |
110 | ||
9c20237a | 111 | function Build_Predicate_Function_Declaration |
112 | (Typ : Entity_Id) return Node_Id; | |
113 | -- Build the declaration for a predicate function. The declaration is built | |
114 | -- at the end of the declarative part containing the type definition, which | |
115 | -- may be before the freeze point of the type. The predicate expression is | |
116 | -- pre-analyzed at this point, to catch visibility errors. | |
117 | ||
eb66e842 | 118 | procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id); |
119 | -- If Typ has predicates (indicated by Has_Predicates being set for Typ), | |
120 | -- then either there are pragma Predicate entries on the rep chain for the | |
121 | -- type (note that Predicate aspects are converted to pragma Predicate), or | |
122 | -- there are inherited aspects from a parent type, or ancestor subtypes. | |
9c20237a | 123 | -- This procedure builds body for the Predicate function that tests these |
124 | -- predicates. N is the freeze node for the type. The spec of the function | |
125 | -- is inserted before the freeze node, and the body of the function is | |
126 | -- inserted after the freeze node. If the predicate expression has a least | |
127 | -- one Raise_Expression, then this procedure also builds the M version of | |
128 | -- the predicate function for use in membership tests. | |
eb66e842 | 129 | |
6653b695 | 130 | procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id); |
131 | -- Called if both Storage_Pool and Storage_Size attribute definition | |
132 | -- clauses (SP and SS) are present for entity Ent. Issue error message. | |
133 | ||
d9f6a4ee | 134 | procedure Freeze_Entity_Checks (N : Node_Id); |
135 | -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity | |
136 | -- to generate appropriate semantic checks that are delayed until this | |
137 | -- point (they had to be delayed this long for cases of delayed aspects, | |
138 | -- e.g. analysis of statically predicated subtypes in choices, for which | |
5f067114 | 139 | -- we have to be sure the subtypes in question are frozen before checking). |
d9f6a4ee | 140 | |
d6f39728 | 141 | function Get_Alignment_Value (Expr : Node_Id) return Uint; |
142 | -- Given the expression for an alignment value, returns the corresponding | |
143 | -- Uint value. If the value is inappropriate, then error messages are | |
144 | -- posted as required, and a value of No_Uint is returned. | |
145 | ||
ee2b7923 | 146 | procedure Get_Interfacing_Aspects |
147 | (Iface_Asp : Node_Id; | |
148 | Conv_Asp : out Node_Id; | |
149 | EN_Asp : out Node_Id; | |
150 | Expo_Asp : out Node_Id; | |
151 | Imp_Asp : out Node_Id; | |
152 | LN_Asp : out Node_Id; | |
153 | Do_Checks : Boolean := False); | |
154 | -- Given a single interfacing aspect Iface_Asp, retrieve other interfacing | |
155 | -- aspects that apply to the same related entity. The aspects considered by | |
156 | -- this routine are as follows: | |
157 | -- | |
158 | -- Conv_Asp - aspect Convention | |
159 | -- EN_Asp - aspect External_Name | |
160 | -- Expo_Asp - aspect Export | |
161 | -- Imp_Asp - aspect Import | |
162 | -- LN_Asp - aspect Link_Name | |
163 | -- | |
164 | -- When flag Do_Checks is set, this routine will flag duplicate uses of | |
165 | -- aspects. | |
166 | ||
d6f39728 | 167 | function Is_Operational_Item (N : Node_Id) return Boolean; |
1e3c4ae6 | 168 | -- A specification for a stream attribute is allowed before the full type |
169 | -- is declared, as explained in AI-00137 and the corrigendum. Attributes | |
170 | -- that do not specify a representation characteristic are operational | |
171 | -- attributes. | |
d6f39728 | 172 | |
3b23aaa0 | 173 | function Is_Predicate_Static |
174 | (Expr : Node_Id; | |
175 | Nam : Name_Id) return Boolean; | |
176 | -- Given predicate expression Expr, tests if Expr is predicate-static in | |
177 | -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type | |
178 | -- name in the predicate expression have been replaced by references to | |
179 | -- an identifier whose Chars field is Nam. This name is unique, so any | |
180 | -- identifier with Chars matching Nam must be a reference to the type. | |
181 | -- Returns True if the expression is predicate-static and False otherwise, | |
182 | -- but is not in the business of setting flags or issuing error messages. | |
183 | -- | |
184 | -- Only scalar types can have static predicates, so False is always | |
185 | -- returned for non-scalar types. | |
186 | -- | |
187 | -- Note: the RM seems to suggest that string types can also have static | |
188 | -- predicates. But that really makes lttle sense as very few useful | |
189 | -- predicates can be constructed for strings. Remember that: | |
190 | -- | |
191 | -- "ABC" < "DEF" | |
192 | -- | |
193 | -- is not a static expression. So even though the clearly faulty RM wording | |
194 | -- allows the following: | |
195 | -- | |
196 | -- subtype S is String with Static_Predicate => S < "DEF" | |
197 | -- | |
198 | -- We can't allow this, otherwise we have predicate-static applying to a | |
199 | -- larger class than static expressions, which was never intended. | |
200 | ||
44e4341e | 201 | procedure New_Stream_Subprogram |
d6f39728 | 202 | (N : Node_Id; |
203 | Ent : Entity_Id; | |
204 | Subp : Entity_Id; | |
9dfe12ae | 205 | Nam : TSS_Name_Type); |
44e4341e | 206 | -- Create a subprogram renaming of a given stream attribute to the |
207 | -- designated subprogram and then in the tagged case, provide this as a | |
d1a2e31b | 208 | -- primitive operation, or in the untagged case make an appropriate TSS |
44e4341e | 209 | -- entry. This is more properly an expansion activity than just semantics, |
d1a2e31b | 210 | -- but the presence of user-defined stream functions for limited types |
211 | -- is a legality check, which is why this takes place here rather than in | |
44e4341e | 212 | -- exp_ch13, where it was previously. Nam indicates the name of the TSS |
213 | -- function to be generated. | |
9dfe12ae | 214 | -- |
f15731c4 | 215 | -- To avoid elaboration anomalies with freeze nodes, for untagged types |
216 | -- we generate both a subprogram declaration and a subprogram renaming | |
217 | -- declaration, so that the attribute specification is handled as a | |
218 | -- renaming_as_body. For tagged types, the specification is one of the | |
219 | -- primitive specs. | |
220 | ||
3061ffde | 221 | procedure Resolve_Iterable_Operation |
222 | (N : Node_Id; | |
223 | Cursor : Entity_Id; | |
224 | Typ : Entity_Id; | |
225 | Nam : Name_Id); | |
226 | -- If the name of a primitive operation for an Iterable aspect is | |
227 | -- overloaded, resolve according to required signature. | |
228 | ||
b77e4501 | 229 | procedure Set_Biased |
230 | (E : Entity_Id; | |
231 | N : Node_Id; | |
232 | Msg : String; | |
233 | Biased : Boolean := True); | |
234 | -- If Biased is True, sets Has_Biased_Representation flag for E, and | |
235 | -- outputs a warning message at node N if Warn_On_Biased_Representation is | |
236 | -- is True. This warning inserts the string Msg to describe the construct | |
237 | -- causing biasing. | |
238 | ||
76a6b7c7 | 239 | --------------------------------------------------- |
240 | -- Table for Validate_Compile_Time_Warning_Error -- | |
241 | --------------------------------------------------- | |
242 | ||
243 | -- The following table collects pragmas Compile_Time_Error and Compile_ | |
244 | -- Time_Warning for validation. Entries are made by calls to subprogram | |
245 | -- Validate_Compile_Time_Warning_Error, and the call to the procedure | |
246 | -- Validate_Compile_Time_Warning_Errors does the actual error checking | |
247 | -- and posting of warning and error messages. The reason for this delayed | |
248 | -- processing is to take advantage of back-annotations of attributes size | |
249 | -- and alignment values performed by the back end. | |
250 | ||
251 | -- Note: the reason we store a Source_Ptr value instead of a Node_Id is | |
252 | -- that by the time Validate_Unchecked_Conversions is called, Sprint will | |
253 | -- already have modified all Sloc values if the -gnatD option is set. | |
254 | ||
255 | type CTWE_Entry is record | |
256 | Eloc : Source_Ptr; | |
257 | -- Source location used in warnings and error messages | |
258 | ||
259 | Prag : Node_Id; | |
260 | -- Pragma Compile_Time_Error or Compile_Time_Warning | |
261 | ||
262 | Scope : Node_Id; | |
263 | -- The scope which encloses the pragma | |
264 | end record; | |
265 | ||
266 | package Compile_Time_Warnings_Errors is new Table.Table ( | |
267 | Table_Component_Type => CTWE_Entry, | |
268 | Table_Index_Type => Int, | |
269 | Table_Low_Bound => 1, | |
270 | Table_Initial => 50, | |
271 | Table_Increment => 200, | |
272 | Table_Name => "Compile_Time_Warnings_Errors"); | |
273 | ||
d6f39728 | 274 | ---------------------------------------------- |
275 | -- Table for Validate_Unchecked_Conversions -- | |
276 | ---------------------------------------------- | |
277 | ||
278 | -- The following table collects unchecked conversions for validation. | |
95deda50 | 279 | -- Entries are made by Validate_Unchecked_Conversion and then the call |
280 | -- to Validate_Unchecked_Conversions does the actual error checking and | |
281 | -- posting of warnings. The reason for this delayed processing is to take | |
282 | -- advantage of back-annotations of size and alignment values performed by | |
283 | -- the back end. | |
d6f39728 | 284 | |
95deda50 | 285 | -- Note: the reason we store a Source_Ptr value instead of a Node_Id is |
286 | -- that by the time Validate_Unchecked_Conversions is called, Sprint will | |
287 | -- already have modified all Sloc values if the -gnatD option is set. | |
299480f9 | 288 | |
d6f39728 | 289 | type UC_Entry is record |
86d32751 | 290 | Eloc : Source_Ptr; -- node used for posting warnings |
291 | Source : Entity_Id; -- source type for unchecked conversion | |
292 | Target : Entity_Id; -- target type for unchecked conversion | |
293 | Act_Unit : Entity_Id; -- actual function instantiated | |
d6f39728 | 294 | end record; |
295 | ||
296 | package Unchecked_Conversions is new Table.Table ( | |
297 | Table_Component_Type => UC_Entry, | |
298 | Table_Index_Type => Int, | |
299 | Table_Low_Bound => 1, | |
300 | Table_Initial => 50, | |
301 | Table_Increment => 200, | |
302 | Table_Name => "Unchecked_Conversions"); | |
303 | ||
83f8f0a6 | 304 | ---------------------------------------- |
305 | -- Table for Validate_Address_Clauses -- | |
306 | ---------------------------------------- | |
307 | ||
308 | -- If an address clause has the form | |
309 | ||
310 | -- for X'Address use Expr | |
311 | ||
514a5555 | 312 | -- where Expr has a value known at compile time or is of the form Y'Address |
313 | -- or recursively is a reference to a constant initialized with either of | |
314 | -- these forms, and the value of Expr is not a multiple of X's alignment, | |
315 | -- or if Y has a smaller alignment than X, then that merits a warning about | |
95deda50 | 316 | -- possible bad alignment. The following table collects address clauses of |
317 | -- this kind. We put these in a table so that they can be checked after the | |
318 | -- back end has completed annotation of the alignments of objects, since we | |
319 | -- can catch more cases that way. | |
83f8f0a6 | 320 | |
321 | type Address_Clause_Check_Record is record | |
322 | N : Node_Id; | |
323 | -- The address clause | |
324 | ||
325 | X : Entity_Id; | |
514a5555 | 326 | -- The entity of the object subject to the address clause |
327 | ||
328 | A : Uint; | |
329 | -- The value of the address in the first case | |
83f8f0a6 | 330 | |
331 | Y : Entity_Id; | |
514a5555 | 332 | -- The entity of the object being overlaid in the second case |
d6da7448 | 333 | |
334 | Off : Boolean; | |
514a5555 | 335 | -- Whether the address is offset within Y in the second case |
83f8f0a6 | 336 | end record; |
337 | ||
338 | package Address_Clause_Checks is new Table.Table ( | |
339 | Table_Component_Type => Address_Clause_Check_Record, | |
340 | Table_Index_Type => Int, | |
341 | Table_Low_Bound => 1, | |
342 | Table_Initial => 20, | |
343 | Table_Increment => 200, | |
344 | Table_Name => "Address_Clause_Checks"); | |
345 | ||
59ac57b5 | 346 | ----------------------------------------- |
347 | -- Adjust_Record_For_Reverse_Bit_Order -- | |
348 | ----------------------------------------- | |
349 | ||
350 | procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is | |
67278d60 | 351 | Comp : Node_Id; |
352 | CC : Node_Id; | |
59ac57b5 | 353 | |
354 | begin | |
67278d60 | 355 | -- Processing depends on version of Ada |
59ac57b5 | 356 | |
6797073f | 357 | -- For Ada 95, we just renumber bits within a storage unit. We do the |
568b0f6a | 358 | -- same for Ada 83 mode, since we recognize the Bit_Order attribute in |
ab19a652 | 359 | -- Ada 83, and are free to add this extension. |
6797073f | 360 | |
361 | if Ada_Version < Ada_2005 then | |
362 | Comp := First_Component_Or_Discriminant (R); | |
363 | while Present (Comp) loop | |
364 | CC := Component_Clause (Comp); | |
365 | ||
366 | -- If component clause is present, then deal with the non-default | |
367 | -- bit order case for Ada 95 mode. | |
368 | ||
369 | -- We only do this processing for the base type, and in fact that | |
370 | -- is important, since otherwise if there are record subtypes, we | |
371 | -- could reverse the bits once for each subtype, which is wrong. | |
372 | ||
b9e61b2a | 373 | if Present (CC) and then Ekind (R) = E_Record_Type then |
6797073f | 374 | declare |
375 | CFB : constant Uint := Component_Bit_Offset (Comp); | |
376 | CSZ : constant Uint := Esize (Comp); | |
377 | CLC : constant Node_Id := Component_Clause (Comp); | |
378 | Pos : constant Node_Id := Position (CLC); | |
379 | FB : constant Node_Id := First_Bit (CLC); | |
380 | ||
381 | Storage_Unit_Offset : constant Uint := | |
382 | CFB / System_Storage_Unit; | |
383 | ||
384 | Start_Bit : constant Uint := | |
385 | CFB mod System_Storage_Unit; | |
59ac57b5 | 386 | |
6797073f | 387 | begin |
388 | -- Cases where field goes over storage unit boundary | |
59ac57b5 | 389 | |
6797073f | 390 | if Start_Bit + CSZ > System_Storage_Unit then |
59ac57b5 | 391 | |
6797073f | 392 | -- Allow multi-byte field but generate warning |
59ac57b5 | 393 | |
6797073f | 394 | if Start_Bit mod System_Storage_Unit = 0 |
395 | and then CSZ mod System_Storage_Unit = 0 | |
396 | then | |
397 | Error_Msg_N | |
7a41db5b | 398 | ("info: multi-byte field specified with " |
399 | & "non-standard Bit_Order?V?", CLC); | |
31486bc0 | 400 | |
6797073f | 401 | if Bytes_Big_Endian then |
31486bc0 | 402 | Error_Msg_N |
7a41db5b | 403 | ("\bytes are not reversed " |
404 | & "(component is big-endian)?V?", CLC); | |
31486bc0 | 405 | else |
406 | Error_Msg_N | |
7a41db5b | 407 | ("\bytes are not reversed " |
408 | & "(component is little-endian)?V?", CLC); | |
31486bc0 | 409 | end if; |
59ac57b5 | 410 | |
cfc922ed | 411 | -- Do not allow non-contiguous field |
59ac57b5 | 412 | |
67278d60 | 413 | else |
6797073f | 414 | Error_Msg_N |
415 | ("attempt to specify non-contiguous field " | |
416 | & "not permitted", CLC); | |
417 | Error_Msg_N | |
418 | ("\caused by non-standard Bit_Order " | |
419 | & "specified", CLC); | |
420 | Error_Msg_N | |
421 | ("\consider possibility of using " | |
422 | & "Ada 2005 mode here", CLC); | |
423 | end if; | |
59ac57b5 | 424 | |
6797073f | 425 | -- Case where field fits in one storage unit |
59ac57b5 | 426 | |
6797073f | 427 | else |
428 | -- Give warning if suspicious component clause | |
59ac57b5 | 429 | |
6797073f | 430 | if Intval (FB) >= System_Storage_Unit |
431 | and then Warn_On_Reverse_Bit_Order | |
432 | then | |
433 | Error_Msg_N | |
7a41db5b | 434 | ("info: Bit_Order clause does not affect " & |
1e3532e7 | 435 | "byte ordering?V?", Pos); |
6797073f | 436 | Error_Msg_Uint_1 := |
437 | Intval (Pos) + Intval (FB) / | |
438 | System_Storage_Unit; | |
439 | Error_Msg_N | |
7a41db5b | 440 | ("info: position normalized to ^ before bit " & |
1e3532e7 | 441 | "order interpreted?V?", Pos); |
6797073f | 442 | end if; |
59ac57b5 | 443 | |
6797073f | 444 | -- Here is where we fix up the Component_Bit_Offset value |
445 | -- to account for the reverse bit order. Some examples of | |
446 | -- what needs to be done are: | |
bfa5a9d9 | 447 | |
6797073f | 448 | -- First_Bit .. Last_Bit Component_Bit_Offset |
449 | -- old new old new | |
59ac57b5 | 450 | |
6797073f | 451 | -- 0 .. 0 7 .. 7 0 7 |
452 | -- 0 .. 1 6 .. 7 0 6 | |
453 | -- 0 .. 2 5 .. 7 0 5 | |
454 | -- 0 .. 7 0 .. 7 0 4 | |
59ac57b5 | 455 | |
6797073f | 456 | -- 1 .. 1 6 .. 6 1 6 |
457 | -- 1 .. 4 3 .. 6 1 3 | |
458 | -- 4 .. 7 0 .. 3 4 0 | |
59ac57b5 | 459 | |
6797073f | 460 | -- The rule is that the first bit is is obtained by |
461 | -- subtracting the old ending bit from storage_unit - 1. | |
59ac57b5 | 462 | |
6797073f | 463 | Set_Component_Bit_Offset |
464 | (Comp, | |
465 | (Storage_Unit_Offset * System_Storage_Unit) + | |
466 | (System_Storage_Unit - 1) - | |
467 | (Start_Bit + CSZ - 1)); | |
59ac57b5 | 468 | |
6797073f | 469 | Set_Normalized_First_Bit |
470 | (Comp, | |
471 | Component_Bit_Offset (Comp) mod | |
472 | System_Storage_Unit); | |
473 | end if; | |
474 | end; | |
475 | end if; | |
476 | ||
477 | Next_Component_Or_Discriminant (Comp); | |
478 | end loop; | |
479 | ||
480 | -- For Ada 2005, we do machine scalar processing, as fully described In | |
481 | -- AI-133. This involves gathering all components which start at the | |
482 | -- same byte offset and processing them together. Same approach is still | |
483 | -- valid in later versions including Ada 2012. | |
484 | ||
485 | else | |
486 | declare | |
487 | Max_Machine_Scalar_Size : constant Uint := | |
488 | UI_From_Int | |
489 | (Standard_Long_Long_Integer_Size); | |
67278d60 | 490 | -- We use this as the maximum machine scalar size |
59ac57b5 | 491 | |
6797073f | 492 | Num_CC : Natural; |
493 | SSU : constant Uint := UI_From_Int (System_Storage_Unit); | |
59ac57b5 | 494 | |
6797073f | 495 | begin |
496 | -- This first loop through components does two things. First it | |
497 | -- deals with the case of components with component clauses whose | |
498 | -- length is greater than the maximum machine scalar size (either | |
499 | -- accepting them or rejecting as needed). Second, it counts the | |
500 | -- number of components with component clauses whose length does | |
501 | -- not exceed this maximum for later processing. | |
67278d60 | 502 | |
6797073f | 503 | Num_CC := 0; |
504 | Comp := First_Component_Or_Discriminant (R); | |
505 | while Present (Comp) loop | |
506 | CC := Component_Clause (Comp); | |
67278d60 | 507 | |
6797073f | 508 | if Present (CC) then |
509 | declare | |
1e3532e7 | 510 | Fbit : constant Uint := Static_Integer (First_Bit (CC)); |
511 | Lbit : constant Uint := Static_Integer (Last_Bit (CC)); | |
67278d60 | 512 | |
6797073f | 513 | begin |
b38e4131 | 514 | -- Case of component with last bit >= max machine scalar |
67278d60 | 515 | |
b38e4131 | 516 | if Lbit >= Max_Machine_Scalar_Size then |
67278d60 | 517 | |
b38e4131 | 518 | -- This is allowed only if first bit is zero, and |
519 | -- last bit + 1 is a multiple of storage unit size. | |
67278d60 | 520 | |
b38e4131 | 521 | if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then |
67278d60 | 522 | |
b38e4131 | 523 | -- This is the case to give a warning if enabled |
67278d60 | 524 | |
b38e4131 | 525 | if Warn_On_Reverse_Bit_Order then |
526 | Error_Msg_N | |
7a41db5b | 527 | ("info: multi-byte field specified with " |
cfc922ed | 528 | & "non-standard Bit_Order?V?", CC); |
b38e4131 | 529 | |
530 | if Bytes_Big_Endian then | |
531 | Error_Msg_N | |
532 | ("\bytes are not reversed " | |
1e3532e7 | 533 | & "(component is big-endian)?V?", CC); |
b38e4131 | 534 | else |
535 | Error_Msg_N | |
536 | ("\bytes are not reversed " | |
1e3532e7 | 537 | & "(component is little-endian)?V?", CC); |
b38e4131 | 538 | end if; |
539 | end if; | |
67278d60 | 540 | |
7eb0e22f | 541 | -- Give error message for RM 13.5.1(10) violation |
67278d60 | 542 | |
b38e4131 | 543 | else |
544 | Error_Msg_FE | |
545 | ("machine scalar rules not followed for&", | |
546 | First_Bit (CC), Comp); | |
67278d60 | 547 | |
0c978552 | 548 | Error_Msg_Uint_1 := Lbit + 1; |
b38e4131 | 549 | Error_Msg_Uint_2 := Max_Machine_Scalar_Size; |
550 | Error_Msg_F | |
0c978552 | 551 | ("\last bit + 1 (^) exceeds maximum machine " |
b38e4131 | 552 | & "scalar size (^)", |
553 | First_Bit (CC)); | |
67278d60 | 554 | |
b38e4131 | 555 | if (Lbit + 1) mod SSU /= 0 then |
556 | Error_Msg_Uint_1 := SSU; | |
557 | Error_Msg_F | |
558 | ("\and is not a multiple of Storage_Unit (^) " | |
0c978552 | 559 | & "(RM 13.5.1(10))", |
b38e4131 | 560 | First_Bit (CC)); |
6797073f | 561 | |
6797073f | 562 | else |
b38e4131 | 563 | Error_Msg_Uint_1 := Fbit; |
564 | Error_Msg_F | |
565 | ("\and first bit (^) is non-zero " | |
0cafb066 | 566 | & "(RM 13.4.1(10))", |
b38e4131 | 567 | First_Bit (CC)); |
67278d60 | 568 | end if; |
6797073f | 569 | end if; |
59ac57b5 | 570 | |
b38e4131 | 571 | -- OK case of machine scalar related component clause, |
572 | -- For now, just count them. | |
59ac57b5 | 573 | |
6797073f | 574 | else |
575 | Num_CC := Num_CC + 1; | |
576 | end if; | |
577 | end; | |
578 | end if; | |
59ac57b5 | 579 | |
6797073f | 580 | Next_Component_Or_Discriminant (Comp); |
581 | end loop; | |
59ac57b5 | 582 | |
6797073f | 583 | -- We need to sort the component clauses on the basis of the |
584 | -- Position values in the clause, so we can group clauses with | |
4a87c513 | 585 | -- the same Position together to determine the relevant machine |
6797073f | 586 | -- scalar size. |
59ac57b5 | 587 | |
6797073f | 588 | Sort_CC : declare |
589 | Comps : array (0 .. Num_CC) of Entity_Id; | |
590 | -- Array to collect component and discriminant entities. The | |
591 | -- data starts at index 1, the 0'th entry is for the sort | |
592 | -- routine. | |
59ac57b5 | 593 | |
6797073f | 594 | function CP_Lt (Op1, Op2 : Natural) return Boolean; |
595 | -- Compare routine for Sort | |
59ac57b5 | 596 | |
6797073f | 597 | procedure CP_Move (From : Natural; To : Natural); |
598 | -- Move routine for Sort | |
59ac57b5 | 599 | |
6797073f | 600 | package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt); |
59ac57b5 | 601 | |
6797073f | 602 | Start : Natural; |
603 | Stop : Natural; | |
604 | -- Start and stop positions in the component list of the set of | |
605 | -- components with the same starting position (that constitute | |
606 | -- components in a single machine scalar). | |
59ac57b5 | 607 | |
6797073f | 608 | MaxL : Uint; |
609 | -- Maximum last bit value of any component in this set | |
59ac57b5 | 610 | |
6797073f | 611 | MSS : Uint; |
612 | -- Corresponding machine scalar size | |
67278d60 | 613 | |
6797073f | 614 | ----------- |
615 | -- CP_Lt -- | |
616 | ----------- | |
67278d60 | 617 | |
6797073f | 618 | function CP_Lt (Op1, Op2 : Natural) return Boolean is |
619 | begin | |
620 | return Position (Component_Clause (Comps (Op1))) < | |
621 | Position (Component_Clause (Comps (Op2))); | |
622 | end CP_Lt; | |
67278d60 | 623 | |
6797073f | 624 | ------------- |
625 | -- CP_Move -- | |
626 | ------------- | |
67278d60 | 627 | |
6797073f | 628 | procedure CP_Move (From : Natural; To : Natural) is |
629 | begin | |
630 | Comps (To) := Comps (From); | |
631 | end CP_Move; | |
67278d60 | 632 | |
4a87c513 | 633 | -- Start of processing for Sort_CC |
59ac57b5 | 634 | |
6797073f | 635 | begin |
b38e4131 | 636 | -- Collect the machine scalar relevant component clauses |
59ac57b5 | 637 | |
6797073f | 638 | Num_CC := 0; |
639 | Comp := First_Component_Or_Discriminant (R); | |
640 | while Present (Comp) loop | |
b38e4131 | 641 | declare |
642 | CC : constant Node_Id := Component_Clause (Comp); | |
643 | ||
644 | begin | |
645 | -- Collect only component clauses whose last bit is less | |
646 | -- than machine scalar size. Any component clause whose | |
647 | -- last bit exceeds this value does not take part in | |
648 | -- machine scalar layout considerations. The test for | |
649 | -- Error_Posted makes sure we exclude component clauses | |
650 | -- for which we already posted an error. | |
651 | ||
652 | if Present (CC) | |
653 | and then not Error_Posted (Last_Bit (CC)) | |
654 | and then Static_Integer (Last_Bit (CC)) < | |
d64221a7 | 655 | Max_Machine_Scalar_Size |
b38e4131 | 656 | then |
657 | Num_CC := Num_CC + 1; | |
658 | Comps (Num_CC) := Comp; | |
659 | end if; | |
660 | end; | |
59ac57b5 | 661 | |
6797073f | 662 | Next_Component_Or_Discriminant (Comp); |
663 | end loop; | |
67278d60 | 664 | |
6797073f | 665 | -- Sort by ascending position number |
67278d60 | 666 | |
6797073f | 667 | Sorting.Sort (Num_CC); |
67278d60 | 668 | |
6797073f | 669 | -- We now have all the components whose size does not exceed |
670 | -- the max machine scalar value, sorted by starting position. | |
671 | -- In this loop we gather groups of clauses starting at the | |
672 | -- same position, to process them in accordance with AI-133. | |
67278d60 | 673 | |
6797073f | 674 | Stop := 0; |
675 | while Stop < Num_CC loop | |
676 | Start := Stop + 1; | |
677 | Stop := Start; | |
678 | MaxL := | |
679 | Static_Integer | |
680 | (Last_Bit (Component_Clause (Comps (Start)))); | |
67278d60 | 681 | while Stop < Num_CC loop |
6797073f | 682 | if Static_Integer |
683 | (Position (Component_Clause (Comps (Stop + 1)))) = | |
684 | Static_Integer | |
685 | (Position (Component_Clause (Comps (Stop)))) | |
686 | then | |
687 | Stop := Stop + 1; | |
688 | MaxL := | |
689 | UI_Max | |
690 | (MaxL, | |
691 | Static_Integer | |
692 | (Last_Bit | |
693 | (Component_Clause (Comps (Stop))))); | |
694 | else | |
695 | exit; | |
696 | end if; | |
697 | end loop; | |
67278d60 | 698 | |
6797073f | 699 | -- Now we have a group of component clauses from Start to |
700 | -- Stop whose positions are identical, and MaxL is the | |
701 | -- maximum last bit value of any of these components. | |
702 | ||
703 | -- We need to determine the corresponding machine scalar | |
704 | -- size. This loop assumes that machine scalar sizes are | |
705 | -- even, and that each possible machine scalar has twice | |
706 | -- as many bits as the next smaller one. | |
707 | ||
708 | MSS := Max_Machine_Scalar_Size; | |
709 | while MSS mod 2 = 0 | |
710 | and then (MSS / 2) >= SSU | |
711 | and then (MSS / 2) > MaxL | |
712 | loop | |
713 | MSS := MSS / 2; | |
714 | end loop; | |
67278d60 | 715 | |
6797073f | 716 | -- Here is where we fix up the Component_Bit_Offset value |
717 | -- to account for the reverse bit order. Some examples of | |
718 | -- what needs to be done for the case of a machine scalar | |
719 | -- size of 8 are: | |
67278d60 | 720 | |
6797073f | 721 | -- First_Bit .. Last_Bit Component_Bit_Offset |
722 | -- old new old new | |
67278d60 | 723 | |
6797073f | 724 | -- 0 .. 0 7 .. 7 0 7 |
725 | -- 0 .. 1 6 .. 7 0 6 | |
726 | -- 0 .. 2 5 .. 7 0 5 | |
727 | -- 0 .. 7 0 .. 7 0 4 | |
67278d60 | 728 | |
6797073f | 729 | -- 1 .. 1 6 .. 6 1 6 |
730 | -- 1 .. 4 3 .. 6 1 3 | |
731 | -- 4 .. 7 0 .. 3 4 0 | |
67278d60 | 732 | |
6797073f | 733 | -- The rule is that the first bit is obtained by subtracting |
734 | -- the old ending bit from machine scalar size - 1. | |
67278d60 | 735 | |
6797073f | 736 | for C in Start .. Stop loop |
737 | declare | |
738 | Comp : constant Entity_Id := Comps (C); | |
b9e61b2a | 739 | CC : constant Node_Id := Component_Clause (Comp); |
740 | ||
741 | LB : constant Uint := Static_Integer (Last_Bit (CC)); | |
6797073f | 742 | NFB : constant Uint := MSS - Uint_1 - LB; |
743 | NLB : constant Uint := NFB + Esize (Comp) - 1; | |
b9e61b2a | 744 | Pos : constant Uint := Static_Integer (Position (CC)); |
67278d60 | 745 | |
6797073f | 746 | begin |
747 | if Warn_On_Reverse_Bit_Order then | |
748 | Error_Msg_Uint_1 := MSS; | |
749 | Error_Msg_N | |
750 | ("info: reverse bit order in machine " & | |
1e3532e7 | 751 | "scalar of length^?V?", First_Bit (CC)); |
6797073f | 752 | Error_Msg_Uint_1 := NFB; |
753 | Error_Msg_Uint_2 := NLB; | |
754 | ||
755 | if Bytes_Big_Endian then | |
756 | Error_Msg_NE | |
7a41db5b | 757 | ("\big-endian range for component " |
758 | & "& is ^ .. ^?V?", First_Bit (CC), Comp); | |
6797073f | 759 | else |
760 | Error_Msg_NE | |
7a41db5b | 761 | ("\little-endian range for component" |
762 | & "& is ^ .. ^?V?", First_Bit (CC), Comp); | |
67278d60 | 763 | end if; |
6797073f | 764 | end if; |
67278d60 | 765 | |
6797073f | 766 | Set_Component_Bit_Offset (Comp, Pos * SSU + NFB); |
767 | Set_Normalized_First_Bit (Comp, NFB mod SSU); | |
768 | end; | |
67278d60 | 769 | end loop; |
6797073f | 770 | end loop; |
771 | end Sort_CC; | |
772 | end; | |
773 | end if; | |
59ac57b5 | 774 | end Adjust_Record_For_Reverse_Bit_Order; |
775 | ||
1d366b32 | 776 | ------------------------------------- |
777 | -- Alignment_Check_For_Size_Change -- | |
778 | ------------------------------------- | |
d6f39728 | 779 | |
1d366b32 | 780 | procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is |
d6f39728 | 781 | begin |
782 | -- If the alignment is known, and not set by a rep clause, and is | |
783 | -- inconsistent with the size being set, then reset it to unknown, | |
784 | -- we assume in this case that the size overrides the inherited | |
785 | -- alignment, and that the alignment must be recomputed. | |
786 | ||
787 | if Known_Alignment (Typ) | |
788 | and then not Has_Alignment_Clause (Typ) | |
1d366b32 | 789 | and then Size mod (Alignment (Typ) * SSU) /= 0 |
d6f39728 | 790 | then |
791 | Init_Alignment (Typ); | |
792 | end if; | |
1d366b32 | 793 | end Alignment_Check_For_Size_Change; |
d6f39728 | 794 | |
06ef5f86 | 795 | ------------------------------------- |
796 | -- Analyze_Aspects_At_Freeze_Point -- | |
797 | ------------------------------------- | |
798 | ||
799 | procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is | |
06ef5f86 | 800 | procedure Analyze_Aspect_Default_Value (ASN : Node_Id); |
801 | -- This routine analyzes an Aspect_Default_[Component_]Value denoted by | |
802 | -- the aspect specification node ASN. | |
803 | ||
37c6e44c | 804 | procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id); |
805 | -- As discussed in the spec of Aspects (see Aspect_Delay declaration), | |
806 | -- a derived type can inherit aspects from its parent which have been | |
807 | -- specified at the time of the derivation using an aspect, as in: | |
808 | -- | |
809 | -- type A is range 1 .. 10 | |
810 | -- with Size => Not_Defined_Yet; | |
811 | -- .. | |
812 | -- type B is new A; | |
813 | -- .. | |
814 | -- Not_Defined_Yet : constant := 64; | |
815 | -- | |
816 | -- In this example, the Size of A is considered to be specified prior | |
817 | -- to the derivation, and thus inherited, even though the value is not | |
818 | -- known at the time of derivation. To deal with this, we use two entity | |
819 | -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A | |
820 | -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in | |
821 | -- the derived type (B here). If this flag is set when the derived type | |
822 | -- is frozen, then this procedure is called to ensure proper inheritance | |
b21edad9 | 823 | -- of all delayed aspects from the parent type. The derived type is E, |
37c6e44c | 824 | -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first |
825 | -- aspect specification node in the Rep_Item chain for the parent type. | |
826 | ||
06ef5f86 | 827 | procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id); |
828 | -- Given an aspect specification node ASN whose expression is an | |
829 | -- optional Boolean, this routines creates the corresponding pragma | |
830 | -- at the freezing point. | |
831 | ||
832 | ---------------------------------- | |
833 | -- Analyze_Aspect_Default_Value -- | |
834 | ---------------------------------- | |
835 | ||
836 | procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is | |
ee2b7923 | 837 | A_Id : constant Aspect_Id := Get_Aspect_Id (ASN); |
06ef5f86 | 838 | Ent : constant Entity_Id := Entity (ASN); |
839 | Expr : constant Node_Id := Expression (ASN); | |
840 | Id : constant Node_Id := Identifier (ASN); | |
841 | ||
842 | begin | |
843 | Error_Msg_Name_1 := Chars (Id); | |
844 | ||
845 | if not Is_Type (Ent) then | |
846 | Error_Msg_N ("aspect% can only apply to a type", Id); | |
847 | return; | |
848 | ||
849 | elsif not Is_First_Subtype (Ent) then | |
850 | Error_Msg_N ("aspect% cannot apply to subtype", Id); | |
851 | return; | |
852 | ||
853 | elsif A_Id = Aspect_Default_Value | |
854 | and then not Is_Scalar_Type (Ent) | |
855 | then | |
856 | Error_Msg_N ("aspect% can only be applied to scalar type", Id); | |
857 | return; | |
858 | ||
859 | elsif A_Id = Aspect_Default_Component_Value then | |
860 | if not Is_Array_Type (Ent) then | |
861 | Error_Msg_N ("aspect% can only be applied to array type", Id); | |
862 | return; | |
863 | ||
864 | elsif not Is_Scalar_Type (Component_Type (Ent)) then | |
865 | Error_Msg_N ("aspect% requires scalar components", Id); | |
866 | return; | |
867 | end if; | |
868 | end if; | |
869 | ||
870 | Set_Has_Default_Aspect (Base_Type (Ent)); | |
871 | ||
872 | if Is_Scalar_Type (Ent) then | |
9f36e3fb | 873 | Set_Default_Aspect_Value (Base_Type (Ent), Expr); |
06ef5f86 | 874 | else |
f3d70f08 | 875 | Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr); |
06ef5f86 | 876 | end if; |
877 | end Analyze_Aspect_Default_Value; | |
878 | ||
37c6e44c | 879 | --------------------------------- |
880 | -- Inherit_Delayed_Rep_Aspects -- | |
881 | --------------------------------- | |
882 | ||
883 | procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is | |
ee2b7923 | 884 | A_Id : constant Aspect_Id := Get_Aspect_Id (ASN); |
885 | P : constant Entity_Id := Entity (ASN); | |
37c6e44c | 886 | -- Entithy for parent type |
887 | ||
888 | N : Node_Id; | |
889 | -- Item from Rep_Item chain | |
890 | ||
891 | A : Aspect_Id; | |
892 | ||
893 | begin | |
894 | -- Loop through delayed aspects for the parent type | |
895 | ||
896 | N := ASN; | |
897 | while Present (N) loop | |
898 | if Nkind (N) = N_Aspect_Specification then | |
899 | exit when Entity (N) /= P; | |
900 | ||
901 | if Is_Delayed_Aspect (N) then | |
902 | A := Get_Aspect_Id (Chars (Identifier (N))); | |
903 | ||
904 | -- Process delayed rep aspect. For Boolean attributes it is | |
905 | -- not possible to cancel an attribute once set (the attempt | |
906 | -- to use an aspect with xxx => False is an error) for a | |
907 | -- derived type. So for those cases, we do not have to check | |
908 | -- if a clause has been given for the derived type, since it | |
909 | -- is harmless to set it again if it is already set. | |
910 | ||
911 | case A is | |
912 | ||
913 | -- Alignment | |
914 | ||
915 | when Aspect_Alignment => | |
916 | if not Has_Alignment_Clause (E) then | |
917 | Set_Alignment (E, Alignment (P)); | |
918 | end if; | |
919 | ||
920 | -- Atomic | |
921 | ||
922 | when Aspect_Atomic => | |
923 | if Is_Atomic (P) then | |
924 | Set_Is_Atomic (E); | |
925 | end if; | |
926 | ||
927 | -- Atomic_Components | |
928 | ||
929 | when Aspect_Atomic_Components => | |
930 | if Has_Atomic_Components (P) then | |
931 | Set_Has_Atomic_Components (Base_Type (E)); | |
932 | end if; | |
933 | ||
934 | -- Bit_Order | |
935 | ||
936 | when Aspect_Bit_Order => | |
937 | if Is_Record_Type (E) | |
938 | and then No (Get_Attribute_Definition_Clause | |
939 | (E, Attribute_Bit_Order)) | |
940 | and then Reverse_Bit_Order (P) | |
941 | then | |
942 | Set_Reverse_Bit_Order (Base_Type (E)); | |
943 | end if; | |
944 | ||
945 | -- Component_Size | |
946 | ||
947 | when Aspect_Component_Size => | |
948 | if Is_Array_Type (E) | |
949 | and then not Has_Component_Size_Clause (E) | |
950 | then | |
951 | Set_Component_Size | |
952 | (Base_Type (E), Component_Size (P)); | |
953 | end if; | |
954 | ||
955 | -- Machine_Radix | |
956 | ||
957 | when Aspect_Machine_Radix => | |
958 | if Is_Decimal_Fixed_Point_Type (E) | |
959 | and then not Has_Machine_Radix_Clause (E) | |
960 | then | |
961 | Set_Machine_Radix_10 (E, Machine_Radix_10 (P)); | |
962 | end if; | |
963 | ||
964 | -- Object_Size (also Size which also sets Object_Size) | |
965 | ||
966 | when Aspect_Object_Size | Aspect_Size => | |
967 | if not Has_Size_Clause (E) | |
968 | and then | |
969 | No (Get_Attribute_Definition_Clause | |
970 | (E, Attribute_Object_Size)) | |
971 | then | |
972 | Set_Esize (E, Esize (P)); | |
973 | end if; | |
974 | ||
975 | -- Pack | |
976 | ||
977 | when Aspect_Pack => | |
978 | if not Is_Packed (E) then | |
979 | Set_Is_Packed (Base_Type (E)); | |
980 | ||
981 | if Is_Bit_Packed_Array (P) then | |
982 | Set_Is_Bit_Packed_Array (Base_Type (E)); | |
a88a5773 | 983 | Set_Packed_Array_Impl_Type |
984 | (E, Packed_Array_Impl_Type (P)); | |
37c6e44c | 985 | end if; |
986 | end if; | |
987 | ||
988 | -- Scalar_Storage_Order | |
989 | ||
990 | when Aspect_Scalar_Storage_Order => | |
991 | if (Is_Record_Type (E) or else Is_Array_Type (E)) | |
992 | and then No (Get_Attribute_Definition_Clause | |
e163cac8 | 993 | (E, Attribute_Scalar_Storage_Order)) |
37c6e44c | 994 | and then Reverse_Storage_Order (P) |
995 | then | |
996 | Set_Reverse_Storage_Order (Base_Type (E)); | |
b64082f2 | 997 | |
998 | -- Clear default SSO indications, since the aspect | |
999 | -- overrides the default. | |
1000 | ||
1001 | Set_SSO_Set_Low_By_Default (Base_Type (E), False); | |
1002 | Set_SSO_Set_High_By_Default (Base_Type (E), False); | |
37c6e44c | 1003 | end if; |
1004 | ||
1005 | -- Small | |
1006 | ||
1007 | when Aspect_Small => | |
1008 | if Is_Fixed_Point_Type (E) | |
1009 | and then not Has_Small_Clause (E) | |
1010 | then | |
1011 | Set_Small_Value (E, Small_Value (P)); | |
1012 | end if; | |
1013 | ||
1014 | -- Storage_Size | |
1015 | ||
1016 | when Aspect_Storage_Size => | |
1017 | if (Is_Access_Type (E) or else Is_Task_Type (E)) | |
1018 | and then not Has_Storage_Size_Clause (E) | |
1019 | then | |
1020 | Set_Storage_Size_Variable | |
1021 | (Base_Type (E), Storage_Size_Variable (P)); | |
1022 | end if; | |
1023 | ||
1024 | -- Value_Size | |
1025 | ||
1026 | when Aspect_Value_Size => | |
1027 | ||
1028 | -- Value_Size is never inherited, it is either set by | |
1029 | -- default, or it is explicitly set for the derived | |
1030 | -- type. So nothing to do here. | |
1031 | ||
1032 | null; | |
1033 | ||
1034 | -- Volatile | |
1035 | ||
1036 | when Aspect_Volatile => | |
1037 | if Is_Volatile (P) then | |
1038 | Set_Is_Volatile (E); | |
1039 | end if; | |
1040 | ||
2fe893b9 | 1041 | -- Volatile_Full_Access |
1042 | ||
1043 | when Aspect_Volatile_Full_Access => | |
4bf2acc9 | 1044 | if Is_Volatile_Full_Access (P) then |
1045 | Set_Is_Volatile_Full_Access (E); | |
2fe893b9 | 1046 | end if; |
1047 | ||
37c6e44c | 1048 | -- Volatile_Components |
1049 | ||
1050 | when Aspect_Volatile_Components => | |
1051 | if Has_Volatile_Components (P) then | |
1052 | Set_Has_Volatile_Components (Base_Type (E)); | |
1053 | end if; | |
1054 | ||
1055 | -- That should be all the Rep Aspects | |
1056 | ||
1057 | when others => | |
1058 | pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect); | |
1059 | null; | |
1060 | ||
1061 | end case; | |
1062 | end if; | |
1063 | end if; | |
1064 | ||
1065 | N := Next_Rep_Item (N); | |
1066 | end loop; | |
1067 | end Inherit_Delayed_Rep_Aspects; | |
1068 | ||
06ef5f86 | 1069 | ------------------------------------- |
1070 | -- Make_Pragma_From_Boolean_Aspect -- | |
1071 | ------------------------------------- | |
1072 | ||
1073 | procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is | |
1074 | Ident : constant Node_Id := Identifier (ASN); | |
1075 | A_Name : constant Name_Id := Chars (Ident); | |
1076 | A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name); | |
1077 | Ent : constant Entity_Id := Entity (ASN); | |
1078 | Expr : constant Node_Id := Expression (ASN); | |
1079 | Loc : constant Source_Ptr := Sloc (ASN); | |
1080 | ||
06ef5f86 | 1081 | procedure Check_False_Aspect_For_Derived_Type; |
1082 | -- This procedure checks for the case of a false aspect for a derived | |
1083 | -- type, which improperly tries to cancel an aspect inherited from | |
1084 | -- the parent. | |
1085 | ||
1086 | ----------------------------------------- | |
1087 | -- Check_False_Aspect_For_Derived_Type -- | |
1088 | ----------------------------------------- | |
1089 | ||
1090 | procedure Check_False_Aspect_For_Derived_Type is | |
1091 | Par : Node_Id; | |
1092 | ||
1093 | begin | |
1094 | -- We are only checking derived types | |
1095 | ||
1096 | if not Is_Derived_Type (E) then | |
1097 | return; | |
1098 | end if; | |
1099 | ||
1100 | Par := Nearest_Ancestor (E); | |
1101 | ||
1102 | case A_Id is | |
1103 | when Aspect_Atomic | Aspect_Shared => | |
1104 | if not Is_Atomic (Par) then | |
1105 | return; | |
1106 | end if; | |
1107 | ||
1108 | when Aspect_Atomic_Components => | |
1109 | if not Has_Atomic_Components (Par) then | |
1110 | return; | |
1111 | end if; | |
1112 | ||
1113 | when Aspect_Discard_Names => | |
1114 | if not Discard_Names (Par) then | |
1115 | return; | |
1116 | end if; | |
1117 | ||
1118 | when Aspect_Pack => | |
1119 | if not Is_Packed (Par) then | |
1120 | return; | |
1121 | end if; | |
1122 | ||
1123 | when Aspect_Unchecked_Union => | |
1124 | if not Is_Unchecked_Union (Par) then | |
1125 | return; | |
1126 | end if; | |
1127 | ||
1128 | when Aspect_Volatile => | |
1129 | if not Is_Volatile (Par) then | |
1130 | return; | |
1131 | end if; | |
1132 | ||
1133 | when Aspect_Volatile_Components => | |
1134 | if not Has_Volatile_Components (Par) then | |
1135 | return; | |
1136 | end if; | |
1137 | ||
2fe893b9 | 1138 | when Aspect_Volatile_Full_Access => |
4bf2acc9 | 1139 | if not Is_Volatile_Full_Access (Par) then |
2fe893b9 | 1140 | return; |
1141 | end if; | |
1142 | ||
06ef5f86 | 1143 | when others => |
1144 | return; | |
1145 | end case; | |
1146 | ||
1147 | -- Fall through means we are canceling an inherited aspect | |
1148 | ||
1149 | Error_Msg_Name_1 := A_Name; | |
37c6e44c | 1150 | Error_Msg_NE |
1151 | ("derived type& inherits aspect%, cannot cancel", Expr, E); | |
06ef5f86 | 1152 | end Check_False_Aspect_For_Derived_Type; |
1153 | ||
ee2b7923 | 1154 | -- Local variables |
1155 | ||
1156 | Prag : Node_Id; | |
1157 | ||
06ef5f86 | 1158 | -- Start of processing for Make_Pragma_From_Boolean_Aspect |
1159 | ||
1160 | begin | |
37c6e44c | 1161 | -- Note that we know Expr is present, because for a missing Expr |
1162 | -- argument, we knew it was True and did not need to delay the | |
1163 | -- evaluation to the freeze point. | |
1164 | ||
06ef5f86 | 1165 | if Is_False (Static_Boolean (Expr)) then |
1166 | Check_False_Aspect_For_Derived_Type; | |
1167 | ||
1168 | else | |
1169 | Prag := | |
1170 | Make_Pragma (Loc, | |
ee2b7923 | 1171 | Pragma_Identifier => |
1172 | Make_Identifier (Sloc (Ident), Chars (Ident)), | |
06ef5f86 | 1173 | Pragma_Argument_Associations => New_List ( |
57cd943b | 1174 | Make_Pragma_Argument_Association (Sloc (Ident), |
ee2b7923 | 1175 | Expression => New_Occurrence_Of (Ent, Sloc (Ident))))); |
06ef5f86 | 1176 | |
1177 | Set_From_Aspect_Specification (Prag, True); | |
1178 | Set_Corresponding_Aspect (Prag, ASN); | |
1179 | Set_Aspect_Rep_Item (ASN, Prag); | |
1180 | Set_Is_Delayed_Aspect (Prag); | |
1181 | Set_Parent (Prag, ASN); | |
1182 | end if; | |
06ef5f86 | 1183 | end Make_Pragma_From_Boolean_Aspect; |
1184 | ||
ee2b7923 | 1185 | -- Local variables |
1186 | ||
1187 | A_Id : Aspect_Id; | |
1188 | ASN : Node_Id; | |
1189 | Ritem : Node_Id; | |
1190 | ||
06ef5f86 | 1191 | -- Start of processing for Analyze_Aspects_At_Freeze_Point |
1192 | ||
1193 | begin | |
29a9d4be | 1194 | -- Must be visible in current scope |
06ef5f86 | 1195 | |
ace3389d | 1196 | if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then |
06ef5f86 | 1197 | return; |
1198 | end if; | |
1199 | ||
1200 | -- Look for aspect specification entries for this entity | |
1201 | ||
1202 | ASN := First_Rep_Item (E); | |
06ef5f86 | 1203 | while Present (ASN) loop |
37c6e44c | 1204 | if Nkind (ASN) = N_Aspect_Specification then |
1205 | exit when Entity (ASN) /= E; | |
06ef5f86 | 1206 | |
37c6e44c | 1207 | if Is_Delayed_Aspect (ASN) then |
1208 | A_Id := Get_Aspect_Id (ASN); | |
1209 | ||
1210 | case A_Id is | |
e4c87fa5 | 1211 | |
37c6e44c | 1212 | -- For aspects whose expression is an optional Boolean, make |
7d6fb253 | 1213 | -- the corresponding pragma at the freeze point. |
06ef5f86 | 1214 | |
7d6fb253 | 1215 | when Boolean_Aspects | |
1216 | Library_Unit_Aspects => | |
ee2b7923 | 1217 | |
1218 | -- Aspects Export and Import require special handling. | |
1219 | -- Both are by definition Boolean and may benefit from | |
1220 | -- forward references, however their expressions are | |
1221 | -- treated as static. In addition, the syntax of their | |
1222 | -- corresponding pragmas requires extra "pieces" which | |
1223 | -- may also contain forward references. To account for | |
1224 | -- all of this, the corresponding pragma is created by | |
1225 | -- Analyze_Aspect_Export_Import, but is not analyzed as | |
1226 | -- the complete analysis must happen now. | |
1227 | ||
1228 | if A_Id = Aspect_Export or else A_Id = Aspect_Import then | |
1229 | null; | |
1230 | ||
1231 | -- Otherwise create a corresponding pragma | |
1232 | ||
1233 | else | |
1234 | Make_Pragma_From_Boolean_Aspect (ASN); | |
1235 | end if; | |
06ef5f86 | 1236 | |
37c6e44c | 1237 | -- Special handling for aspects that don't correspond to |
1238 | -- pragmas/attributes. | |
06ef5f86 | 1239 | |
7d6fb253 | 1240 | when Aspect_Default_Value | |
1241 | Aspect_Default_Component_Value => | |
81c2bc19 | 1242 | |
1243 | -- Do not inherit aspect for anonymous base type of a | |
1244 | -- scalar or array type, because they apply to the first | |
1245 | -- subtype of the type, and will be processed when that | |
1246 | -- first subtype is frozen. | |
1247 | ||
1248 | if Is_Derived_Type (E) | |
1249 | and then not Comes_From_Source (E) | |
1250 | and then E /= First_Subtype (E) | |
1251 | then | |
1252 | null; | |
1253 | else | |
1254 | Analyze_Aspect_Default_Value (ASN); | |
1255 | end if; | |
06ef5f86 | 1256 | |
37c6e44c | 1257 | -- Ditto for iterator aspects, because the corresponding |
1258 | -- attributes may not have been analyzed yet. | |
af9fed8f | 1259 | |
7d6fb253 | 1260 | when Aspect_Constant_Indexing | |
1261 | Aspect_Variable_Indexing | | |
1262 | Aspect_Default_Iterator | | |
1263 | Aspect_Iterator_Element => | |
1264 | Analyze (Expression (ASN)); | |
af9fed8f | 1265 | |
7d6fb253 | 1266 | if Etype (Expression (ASN)) = Any_Type then |
1267 | Error_Msg_NE | |
1268 | ("\aspect must be fully defined before & is frozen", | |
1269 | ASN, E); | |
1270 | end if; | |
b3f8228a | 1271 | |
7d6fb253 | 1272 | when Aspect_Iterable => |
1273 | Validate_Iterable_Aspect (E, ASN); | |
1274 | ||
1275 | when others => | |
1276 | null; | |
37c6e44c | 1277 | end case; |
06ef5f86 | 1278 | |
37c6e44c | 1279 | Ritem := Aspect_Rep_Item (ASN); |
06ef5f86 | 1280 | |
37c6e44c | 1281 | if Present (Ritem) then |
1282 | Analyze (Ritem); | |
1283 | end if; | |
06ef5f86 | 1284 | end if; |
1285 | end if; | |
1286 | ||
1287 | Next_Rep_Item (ASN); | |
1288 | end loop; | |
37c6e44c | 1289 | |
1290 | -- This is where we inherit delayed rep aspects from our parent. Note | |
1291 | -- that if we fell out of the above loop with ASN non-empty, it means | |
1292 | -- we hit an aspect for an entity other than E, and it must be the | |
1293 | -- type from which we were derived. | |
1294 | ||
1295 | if May_Inherit_Delayed_Rep_Aspects (E) then | |
1296 | Inherit_Delayed_Rep_Aspects (ASN); | |
1297 | end if; | |
06ef5f86 | 1298 | end Analyze_Aspects_At_Freeze_Point; |
1299 | ||
ae888dbd | 1300 | ----------------------------------- |
1301 | -- Analyze_Aspect_Specifications -- | |
1302 | ----------------------------------- | |
1303 | ||
21ea3a4f | 1304 | procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is |
e2bf777d | 1305 | procedure Decorate (Asp : Node_Id; Prag : Node_Id); |
6c5793cd | 1306 | -- Establish linkages between an aspect and its corresponding pragma |
5ddd846b | 1307 | |
5655be8a | 1308 | procedure Insert_Pragma |
1309 | (Prag : Node_Id; | |
1310 | Is_Instance : Boolean := False); | |
2f06c88a | 1311 | -- Subsidiary to the analysis of aspects |
1312 | -- Abstract_State | |
2f06c88a | 1313 | -- Attach_Handler |
1314 | -- Contract_Cases | |
1315 | -- Depends | |
5655be8a | 1316 | -- Ghost |
2f06c88a | 1317 | -- Global |
5655be8a | 1318 | -- Initial_Condition |
1319 | -- Initializes | |
2f06c88a | 1320 | -- Post |
1321 | -- Pre | |
1322 | -- Refined_Depends | |
1323 | -- Refined_Global | |
5655be8a | 1324 | -- Refined_State |
2f06c88a | 1325 | -- SPARK_Mode |
1326 | -- Warnings | |
e2bf777d | 1327 | -- Insert pragma Prag such that it mimics the placement of a source |
5655be8a | 1328 | -- pragma of the same kind. Flag Is_Generic should be set when the |
1329 | -- context denotes a generic instance. | |
e2bf777d | 1330 | |
1331 | -------------- | |
1332 | -- Decorate -- | |
1333 | -------------- | |
1334 | ||
1335 | procedure Decorate (Asp : Node_Id; Prag : Node_Id) is | |
5ddd846b | 1336 | begin |
6c5793cd | 1337 | Set_Aspect_Rep_Item (Asp, Prag); |
5ddd846b | 1338 | Set_Corresponding_Aspect (Prag, Asp); |
1339 | Set_From_Aspect_Specification (Prag); | |
5ddd846b | 1340 | Set_Parent (Prag, Asp); |
e2bf777d | 1341 | end Decorate; |
f0813d71 | 1342 | |
e2bf777d | 1343 | ------------------- |
1344 | -- Insert_Pragma -- | |
1345 | ------------------- | |
c1006d6d | 1346 | |
5655be8a | 1347 | procedure Insert_Pragma |
1348 | (Prag : Node_Id; | |
1349 | Is_Instance : Boolean := False) | |
1350 | is | |
3ff5e35d | 1351 | Aux : Node_Id; |
1352 | Decl : Node_Id; | |
1353 | Decls : List_Id; | |
1354 | Def : Node_Id; | |
1355 | Inserted : Boolean := False; | |
c1006d6d | 1356 | |
1357 | begin | |
3ff5e35d | 1358 | -- When the aspect appears on an entry, package, protected unit, |
1359 | -- subprogram, or task unit body, insert the generated pragma at the | |
1360 | -- top of the body declarations to emulate the behavior of a source | |
1361 | -- pragma. | |
2f06c88a | 1362 | |
1363 | -- package body Pack with Aspect is | |
1364 | ||
1365 | -- package body Pack is | |
1366 | -- pragma Prag; | |
1367 | ||
3ff5e35d | 1368 | if Nkind_In (N, N_Entry_Body, |
1369 | N_Package_Body, | |
2f06c88a | 1370 | N_Protected_Body, |
1371 | N_Subprogram_Body, | |
1372 | N_Task_Body) | |
1373 | then | |
1374 | Decls := Declarations (N); | |
1375 | ||
1376 | if No (Decls) then | |
1377 | Decls := New_List; | |
1378 | Set_Declarations (N, Decls); | |
1379 | end if; | |
e2bf777d | 1380 | |
3ff5e35d | 1381 | Prepend_To (Decls, Prag); |
2f06c88a | 1382 | |
1383 | -- When the aspect is associated with a [generic] package declaration | |
1384 | -- insert the generated pragma at the top of the visible declarations | |
1385 | -- to emulate the behavior of a source pragma. | |
1386 | ||
1387 | -- package Pack with Aspect is | |
1388 | ||
1389 | -- package Pack is | |
1390 | -- pragma Prag; | |
1391 | ||
1392 | elsif Nkind_In (N, N_Generic_Package_Declaration, | |
1393 | N_Package_Declaration) | |
1394 | then | |
1395 | Decls := Visible_Declarations (Specification (N)); | |
1396 | ||
1397 | if No (Decls) then | |
1398 | Decls := New_List; | |
1399 | Set_Visible_Declarations (Specification (N), Decls); | |
1400 | end if; | |
1401 | ||
5655be8a | 1402 | -- The visible declarations of a generic instance have the |
1403 | -- following structure: | |
1404 | ||
1405 | -- <renamings of generic formals> | |
1406 | -- <renamings of internally-generated spec and body> | |
1407 | -- <first source declaration> | |
1408 | ||
1409 | -- Insert the pragma before the first source declaration by | |
3ff5e35d | 1410 | -- skipping the instance "header" to ensure proper visibility of |
1411 | -- all formals. | |
5655be8a | 1412 | |
1413 | if Is_Instance then | |
1414 | Decl := First (Decls); | |
3ff5e35d | 1415 | while Present (Decl) loop |
1416 | if Comes_From_Source (Decl) then | |
1417 | Insert_Before (Decl, Prag); | |
1418 | Inserted := True; | |
1419 | exit; | |
1420 | else | |
1421 | Next (Decl); | |
1422 | end if; | |
5655be8a | 1423 | end loop; |
1424 | ||
3ff5e35d | 1425 | -- The pragma is placed after the instance "header" |
5655be8a | 1426 | |
3ff5e35d | 1427 | if not Inserted then |
5655be8a | 1428 | Append_To (Decls, Prag); |
1429 | end if; | |
1430 | ||
1431 | -- Otherwise this is not a generic instance | |
1432 | ||
1433 | else | |
1434 | Prepend_To (Decls, Prag); | |
1435 | end if; | |
2f06c88a | 1436 | |
1437 | -- When the aspect is associated with a protected unit declaration, | |
1438 | -- insert the generated pragma at the top of the visible declarations | |
1439 | -- the emulate the behavior of a source pragma. | |
1440 | ||
1441 | -- protected [type] Prot with Aspect is | |
1442 | ||
1443 | -- protected [type] Prot is | |
1444 | -- pragma Prag; | |
1445 | ||
1446 | elsif Nkind (N) = N_Protected_Type_Declaration then | |
736b80cc | 1447 | Def := Protected_Definition (N); |
1448 | ||
1449 | if No (Def) then | |
1450 | Def := | |
1451 | Make_Protected_Definition (Sloc (N), | |
1452 | Visible_Declarations => New_List, | |
1453 | End_Label => Empty); | |
1454 | ||
1455 | Set_Protected_Definition (N, Def); | |
1456 | end if; | |
1457 | ||
1458 | Decls := Visible_Declarations (Def); | |
2f06c88a | 1459 | |
1460 | if No (Decls) then | |
1461 | Decls := New_List; | |
736b80cc | 1462 | Set_Visible_Declarations (Def, Decls); |
2f06c88a | 1463 | end if; |
1464 | ||
1465 | Prepend_To (Decls, Prag); | |
1466 | ||
736b80cc | 1467 | -- When the aspect is associated with a task unit declaration, insert |
1468 | -- insert the generated pragma at the top of the visible declarations | |
1469 | -- the emulate the behavior of a source pragma. | |
2f06c88a | 1470 | |
1471 | -- task [type] Prot with Aspect is | |
1472 | ||
1473 | -- task [type] Prot is | |
1474 | -- pragma Prag; | |
1475 | ||
736b80cc | 1476 | elsif Nkind (N) = N_Task_Type_Declaration then |
1477 | Def := Task_Definition (N); | |
1478 | ||
1479 | if No (Def) then | |
1480 | Def := | |
1481 | Make_Task_Definition (Sloc (N), | |
1482 | Visible_Declarations => New_List, | |
1483 | End_Label => Empty); | |
1484 | ||
1485 | Set_Task_Definition (N, Def); | |
1486 | end if; | |
1487 | ||
1488 | Decls := Visible_Declarations (Def); | |
2f06c88a | 1489 | |
1490 | if No (Decls) then | |
1491 | Decls := New_List; | |
736b80cc | 1492 | Set_Visible_Declarations (Def, Decls); |
d324c418 | 1493 | end if; |
c1006d6d | 1494 | |
2f06c88a | 1495 | Prepend_To (Decls, Prag); |
1496 | ||
ed695684 | 1497 | -- When the context is a library unit, the pragma is added to the |
1498 | -- Pragmas_After list. | |
1499 | ||
1500 | elsif Nkind (Parent (N)) = N_Compilation_Unit then | |
1501 | Aux := Aux_Decls_Node (Parent (N)); | |
1502 | ||
1503 | if No (Pragmas_After (Aux)) then | |
1504 | Set_Pragmas_After (Aux, New_List); | |
1505 | end if; | |
1506 | ||
1507 | Prepend (Prag, Pragmas_After (Aux)); | |
1508 | ||
2f06c88a | 1509 | -- Default, the pragma is inserted after the context |
c1006d6d | 1510 | |
1511 | else | |
1512 | Insert_After (N, Prag); | |
c1006d6d | 1513 | end if; |
e2bf777d | 1514 | end Insert_Pragma; |
c1006d6d | 1515 | |
1516 | -- Local variables | |
1517 | ||
ae888dbd | 1518 | Aspect : Node_Id; |
d74fc39a | 1519 | Aitem : Node_Id; |
ae888dbd | 1520 | Ent : Node_Id; |
ae888dbd | 1521 | |
21ea3a4f | 1522 | L : constant List_Id := Aspect_Specifications (N); |
1523 | ||
ae888dbd | 1524 | Ins_Node : Node_Id := N; |
89f1e35c | 1525 | -- Insert pragmas/attribute definition clause after this node when no |
1526 | -- delayed analysis is required. | |
d74fc39a | 1527 | |
ee2b7923 | 1528 | -- Start of processing for Analyze_Aspect_Specifications |
f0813d71 | 1529 | |
ee2b7923 | 1530 | begin |
d74fc39a | 1531 | -- The general processing involves building an attribute definition |
89f1e35c | 1532 | -- clause or a pragma node that corresponds to the aspect. Then in order |
1533 | -- to delay the evaluation of this aspect to the freeze point, we attach | |
1534 | -- the corresponding pragma/attribute definition clause to the aspect | |
1535 | -- specification node, which is then placed in the Rep Item chain. In | |
1536 | -- this case we mark the entity by setting the flag Has_Delayed_Aspects | |
1537 | -- and we evaluate the rep item at the freeze point. When the aspect | |
1538 | -- doesn't have a corresponding pragma/attribute definition clause, then | |
1539 | -- its analysis is simply delayed at the freeze point. | |
1540 | ||
1541 | -- Some special cases don't require delay analysis, thus the aspect is | |
1542 | -- analyzed right now. | |
1543 | ||
51ea9c94 | 1544 | -- Note that there is a special handling for Pre, Post, Test_Case, |
e66f4e2a | 1545 | -- Contract_Cases aspects. In these cases, we do not have to worry |
51ea9c94 | 1546 | -- about delay issues, since the pragmas themselves deal with delay |
1547 | -- of visibility for the expression analysis. Thus, we just insert | |
1548 | -- the pragma after the node N. | |
ae888dbd | 1549 | |
21ea3a4f | 1550 | pragma Assert (Present (L)); |
1551 | ||
6fb3c314 | 1552 | -- Loop through aspects |
f93e7257 | 1553 | |
ae888dbd | 1554 | Aspect := First (L); |
21ea3a4f | 1555 | Aspect_Loop : while Present (Aspect) loop |
0fd13d32 | 1556 | Analyze_One_Aspect : declare |
94153a42 | 1557 | Expr : constant Node_Id := Expression (Aspect); |
89f1e35c | 1558 | Id : constant Node_Id := Identifier (Aspect); |
1559 | Loc : constant Source_Ptr := Sloc (Aspect); | |
94153a42 | 1560 | Nam : constant Name_Id := Chars (Id); |
1561 | A_Id : constant Aspect_Id := Get_Aspect_Id (Nam); | |
ae888dbd | 1562 | Anod : Node_Id; |
1563 | ||
37c6e44c | 1564 | Delay_Required : Boolean; |
89f1e35c | 1565 | -- Set False if delay is not required |
1566 | ||
c0793fff | 1567 | Eloc : Source_Ptr := No_Location; |
1568 | -- Source location of expression, modified when we split PPC's. It | |
1569 | -- is set below when Expr is present. | |
39e1f22f | 1570 | |
ee2b7923 | 1571 | procedure Analyze_Aspect_Convention; |
1572 | -- Perform analysis of aspect Convention | |
1573 | ||
1574 | procedure Analyze_Aspect_Export_Import; | |
1575 | -- Perform analysis of aspects Export or Import | |
1576 | ||
1577 | procedure Analyze_Aspect_External_Link_Name; | |
1578 | -- Perform analysis of aspects External_Name or Link_Name | |
21ea3a4f | 1579 | |
89f1e35c | 1580 | procedure Analyze_Aspect_Implicit_Dereference; |
9ab32fe9 | 1581 | -- Perform analysis of the Implicit_Dereference aspects |
0fd13d32 | 1582 | |
1583 | procedure Make_Aitem_Pragma | |
1584 | (Pragma_Argument_Associations : List_Id; | |
1585 | Pragma_Name : Name_Id); | |
1586 | -- This is a wrapper for Make_Pragma used for converting aspects | |
1587 | -- to pragmas. It takes care of Sloc (set from Loc) and building | |
1588 | -- the pragma identifier from the given name. In addition the | |
1589 | -- flags Class_Present and Split_PPC are set from the aspect | |
1590 | -- node, as well as Is_Ignored. This routine also sets the | |
1591 | -- From_Aspect_Specification in the resulting pragma node to | |
1592 | -- True, and sets Corresponding_Aspect to point to the aspect. | |
1593 | -- The resulting pragma is assigned to Aitem. | |
21ea3a4f | 1594 | |
ee2b7923 | 1595 | ------------------------------- |
1596 | -- Analyze_Aspect_Convention -- | |
1597 | ------------------------------- | |
1598 | ||
1599 | procedure Analyze_Aspect_Convention is | |
1600 | Conv : Node_Id; | |
1601 | Dummy_1 : Node_Id; | |
1602 | Dummy_2 : Node_Id; | |
1603 | Dummy_3 : Node_Id; | |
1604 | Expo : Node_Id; | |
1605 | Imp : Node_Id; | |
89f1e35c | 1606 | |
21ea3a4f | 1607 | begin |
ee2b7923 | 1608 | -- Obtain all interfacing aspects that apply to the related |
1609 | -- entity. | |
1610 | ||
1611 | Get_Interfacing_Aspects | |
1612 | (Iface_Asp => Aspect, | |
1613 | Conv_Asp => Dummy_1, | |
1614 | EN_Asp => Dummy_2, | |
1615 | Expo_Asp => Expo, | |
1616 | Imp_Asp => Imp, | |
1617 | LN_Asp => Dummy_3, | |
1618 | Do_Checks => True); | |
1619 | ||
1620 | -- The related entity is subject to aspect Export or Import. | |
1621 | -- Do not process Convention now because it must be analysed | |
1622 | -- as part of Export or Import. | |
1623 | ||
1624 | if Present (Expo) or else Present (Imp) then | |
1625 | return; | |
21ea3a4f | 1626 | |
ee2b7923 | 1627 | -- Otherwise Convention appears by itself |
21ea3a4f | 1628 | |
ee2b7923 | 1629 | else |
1630 | -- The aspect specifies a particular convention | |
1631 | ||
1632 | if Present (Expr) then | |
1633 | Conv := New_Copy_Tree (Expr); | |
1634 | ||
1635 | -- Otherwise assume convention Ada | |
1636 | ||
1637 | else | |
1638 | Conv := Make_Identifier (Loc, Name_Ada); | |
1639 | end if; | |
1640 | ||
1641 | -- Generate: | |
1642 | -- pragma Convention (<Conv>, <E>); | |
1643 | ||
1644 | Make_Aitem_Pragma | |
1645 | (Pragma_Name => Name_Convention, | |
1646 | Pragma_Argument_Associations => New_List ( | |
1647 | Make_Pragma_Argument_Association (Loc, | |
1648 | Expression => Conv), | |
1649 | Make_Pragma_Argument_Association (Loc, | |
1650 | Expression => New_Occurrence_Of (E, Loc)))); | |
1651 | ||
1652 | Decorate (Aspect, Aitem); | |
1653 | Insert_Pragma (Aitem); | |
1654 | end if; | |
1655 | end Analyze_Aspect_Convention; | |
1656 | ||
1657 | ---------------------------------- | |
1658 | -- Analyze_Aspect_Export_Import -- | |
1659 | ---------------------------------- | |
21ea3a4f | 1660 | |
ee2b7923 | 1661 | procedure Analyze_Aspect_Export_Import is |
1662 | Dummy_1 : Node_Id; | |
1663 | Dummy_2 : Node_Id; | |
1664 | Dummy_3 : Node_Id; | |
1665 | Expo : Node_Id; | |
1666 | Imp : Node_Id; | |
1667 | ||
1668 | begin | |
1669 | -- Obtain all interfacing aspects that apply to the related | |
1670 | -- entity. | |
1671 | ||
1672 | Get_Interfacing_Aspects | |
1673 | (Iface_Asp => Aspect, | |
1674 | Conv_Asp => Dummy_1, | |
1675 | EN_Asp => Dummy_2, | |
1676 | Expo_Asp => Expo, | |
1677 | Imp_Asp => Imp, | |
1678 | LN_Asp => Dummy_3, | |
1679 | Do_Checks => True); | |
1680 | ||
1681 | -- The related entity cannot be subject to both aspects Export | |
1682 | -- and Import. | |
1683 | ||
1684 | if Present (Expo) and then Present (Imp) then | |
1685 | Error_Msg_N | |
1686 | ("incompatible interfacing aspects given for &", E); | |
1687 | Error_Msg_Sloc := Sloc (Expo); | |
1688 | Error_Msg_N ("\aspect `Export` #", E); | |
1689 | Error_Msg_Sloc := Sloc (Imp); | |
1690 | Error_Msg_N ("\aspect `Import` #", E); | |
1691 | end if; | |
1692 | ||
1693 | -- A variable is most likely modified from the outside. Take | |
1694 | -- Take the optimistic approach to avoid spurious errors. | |
1695 | ||
1696 | if Ekind (E) = E_Variable then | |
1697 | Set_Never_Set_In_Source (E, False); | |
1698 | end if; | |
1699 | ||
1700 | -- Resolve the expression of an Import or Export here, and | |
1701 | -- require it to be of type Boolean and static. This is not | |
1702 | -- quite right, because in general this should be delayed, | |
1703 | -- but that seems tricky for these, because normally Boolean | |
1704 | -- aspects are replaced with pragmas at the freeze point in | |
1705 | -- Make_Pragma_From_Boolean_Aspect. | |
1706 | ||
1707 | if not Present (Expr) | |
1708 | or else Is_True (Static_Boolean (Expr)) | |
1709 | then | |
1710 | if A_Id = Aspect_Import then | |
1711 | Set_Has_Completion (E); | |
1712 | Set_Is_Imported (E); | |
1713 | ||
1714 | -- An imported object cannot be explicitly initialized | |
1715 | ||
1716 | if Nkind (N) = N_Object_Declaration | |
1717 | and then Present (Expression (N)) | |
1718 | then | |
1719 | Error_Msg_N | |
1720 | ("imported entities cannot be initialized " | |
1721 | & "(RM B.1(24))", Expression (N)); | |
1722 | end if; | |
1723 | ||
1724 | else | |
1725 | pragma Assert (A_Id = Aspect_Export); | |
1726 | Set_Is_Exported (E); | |
1727 | end if; | |
1728 | ||
1729 | -- Create the proper form of pragma Export or Import taking | |
1730 | -- into account Conversion, External_Name, and Link_Name. | |
1731 | ||
1732 | Aitem := Build_Export_Import_Pragma (Aspect, E); | |
d8e539ae | 1733 | |
1734 | -- Otherwise the expression is either False or erroneous. There | |
1735 | -- is no corresponding pragma. | |
1736 | ||
1737 | else | |
1738 | Aitem := Empty; | |
ee2b7923 | 1739 | end if; |
1740 | end Analyze_Aspect_Export_Import; | |
1741 | ||
1742 | --------------------------------------- | |
1743 | -- Analyze_Aspect_External_Link_Name -- | |
1744 | --------------------------------------- | |
1745 | ||
1746 | procedure Analyze_Aspect_External_Link_Name is | |
1747 | Dummy_1 : Node_Id; | |
1748 | Dummy_2 : Node_Id; | |
1749 | Dummy_3 : Node_Id; | |
1750 | Expo : Node_Id; | |
1751 | Imp : Node_Id; | |
1752 | ||
1753 | begin | |
1754 | -- Obtain all interfacing aspects that apply to the related | |
1755 | -- entity. | |
1756 | ||
1757 | Get_Interfacing_Aspects | |
1758 | (Iface_Asp => Aspect, | |
1759 | Conv_Asp => Dummy_1, | |
1760 | EN_Asp => Dummy_2, | |
1761 | Expo_Asp => Expo, | |
1762 | Imp_Asp => Imp, | |
1763 | LN_Asp => Dummy_3, | |
1764 | Do_Checks => True); | |
1765 | ||
1766 | -- Ensure that aspect External_Name applies to aspect Export or | |
1767 | -- Import. | |
1768 | ||
1769 | if A_Id = Aspect_External_Name then | |
1770 | if No (Expo) and then No (Imp) then | |
89f1e35c | 1771 | Error_Msg_N |
ee2b7923 | 1772 | ("aspect `External_Name` requires aspect `Import` or " |
1773 | & "`Export`", Aspect); | |
89f1e35c | 1774 | end if; |
ee2b7923 | 1775 | |
1776 | -- Otherwise ensure that aspect Link_Name applies to aspect | |
1777 | -- Export or Import. | |
1778 | ||
1779 | else | |
1780 | pragma Assert (A_Id = Aspect_Link_Name); | |
1781 | if No (Expo) and then No (Imp) then | |
1782 | Error_Msg_N | |
1783 | ("aspect `Link_Name` requires aspect `Import` or " | |
1784 | & "`Export`", Aspect); | |
1785 | end if; | |
1786 | end if; | |
1787 | end Analyze_Aspect_External_Link_Name; | |
21ea3a4f | 1788 | |
89f1e35c | 1789 | ----------------------------------------- |
1790 | -- Analyze_Aspect_Implicit_Dereference -- | |
1791 | ----------------------------------------- | |
21ea3a4f | 1792 | |
89f1e35c | 1793 | procedure Analyze_Aspect_Implicit_Dereference is |
1ff43c00 | 1794 | Disc : Entity_Id; |
1795 | Parent_Disc : Entity_Id; | |
1796 | ||
89f1e35c | 1797 | begin |
b9e61b2a | 1798 | if not Is_Type (E) or else not Has_Discriminants (E) then |
89f1e35c | 1799 | Error_Msg_N |
1ff43c00 | 1800 | ("aspect must apply to a type with discriminants", Expr); |
21ea3a4f | 1801 | |
1ff43c00 | 1802 | elsif not Is_Entity_Name (Expr) then |
1803 | Error_Msg_N | |
1804 | ("aspect must name a discriminant of current type", Expr); | |
21ea3a4f | 1805 | |
1ff43c00 | 1806 | else |
1807 | Disc := First_Discriminant (E); | |
1808 | while Present (Disc) loop | |
1809 | if Chars (Expr) = Chars (Disc) | |
1810 | and then Ekind (Etype (Disc)) = | |
1811 | E_Anonymous_Access_Type | |
1812 | then | |
1813 | Set_Has_Implicit_Dereference (E); | |
1814 | Set_Has_Implicit_Dereference (Disc); | |
1815 | exit; | |
1816 | end if; | |
21ea3a4f | 1817 | |
1ff43c00 | 1818 | Next_Discriminant (Disc); |
1819 | end loop; | |
21ea3a4f | 1820 | |
9b5b11fb | 1821 | -- Error if no proper access discriminant |
21ea3a4f | 1822 | |
1ff43c00 | 1823 | if No (Disc) then |
ee2b7923 | 1824 | Error_Msg_NE ("not an access discriminant of&", Expr, E); |
1ff43c00 | 1825 | return; |
1826 | end if; | |
1827 | end if; | |
1828 | ||
9b5b11fb | 1829 | -- For a type extension, check whether parent has a |
1830 | -- reference discriminant, to verify that use is proper. | |
1831 | ||
1ff43c00 | 1832 | if Is_Derived_Type (E) |
1833 | and then Has_Discriminants (Etype (E)) | |
1834 | then | |
1835 | Parent_Disc := Get_Reference_Discriminant (Etype (E)); | |
1836 | ||
1837 | if Present (Parent_Disc) | |
1838 | and then Corresponding_Discriminant (Disc) /= Parent_Disc | |
1839 | then | |
ee2b7923 | 1840 | Error_Msg_N |
1841 | ("reference discriminant does not match discriminant " | |
1842 | & "of parent type", Expr); | |
1ff43c00 | 1843 | end if; |
89f1e35c | 1844 | end if; |
1845 | end Analyze_Aspect_Implicit_Dereference; | |
21ea3a4f | 1846 | |
0fd13d32 | 1847 | ----------------------- |
1848 | -- Make_Aitem_Pragma -- | |
1849 | ----------------------- | |
1850 | ||
1851 | procedure Make_Aitem_Pragma | |
1852 | (Pragma_Argument_Associations : List_Id; | |
1853 | Pragma_Name : Name_Id) | |
1854 | is | |
b855559d | 1855 | Args : List_Id := Pragma_Argument_Associations; |
1856 | ||
0fd13d32 | 1857 | begin |
1858 | -- We should never get here if aspect was disabled | |
1859 | ||
1860 | pragma Assert (not Is_Disabled (Aspect)); | |
1861 | ||
056dc987 | 1862 | -- Certain aspects allow for an optional name or expression. Do |
1863 | -- not generate a pragma with empty argument association list. | |
b855559d | 1864 | |
1865 | if No (Args) or else No (Expression (First (Args))) then | |
1866 | Args := No_List; | |
1867 | end if; | |
1868 | ||
0fd13d32 | 1869 | -- Build the pragma |
1870 | ||
1871 | Aitem := | |
1872 | Make_Pragma (Loc, | |
b855559d | 1873 | Pragma_Argument_Associations => Args, |
0fd13d32 | 1874 | Pragma_Identifier => |
1875 | Make_Identifier (Sloc (Id), Pragma_Name), | |
9ab32fe9 | 1876 | Class_Present => Class_Present (Aspect), |
1877 | Split_PPC => Split_PPC (Aspect)); | |
0fd13d32 | 1878 | |
1879 | -- Set additional semantic fields | |
1880 | ||
1881 | if Is_Ignored (Aspect) then | |
1882 | Set_Is_Ignored (Aitem); | |
57d8d1f3 | 1883 | elsif Is_Checked (Aspect) then |
a5109493 | 1884 | Set_Is_Checked (Aitem); |
0fd13d32 | 1885 | end if; |
1886 | ||
1887 | Set_Corresponding_Aspect (Aitem, Aspect); | |
fdec445e | 1888 | Set_From_Aspect_Specification (Aitem); |
0fd13d32 | 1889 | end Make_Aitem_Pragma; |
1890 | ||
738ec25b | 1891 | -- Start of processing for Analyze_One_Aspect |
0fd13d32 | 1892 | |
ae888dbd | 1893 | begin |
2d1acfa7 | 1894 | -- Skip aspect if already analyzed, to avoid looping in some cases |
fb7f2fc4 | 1895 | |
1896 | if Analyzed (Aspect) then | |
1897 | goto Continue; | |
1898 | end if; | |
1899 | ||
ef957022 | 1900 | -- Skip looking at aspect if it is totally disabled. Just mark it |
1901 | -- as such for later reference in the tree. This also sets the | |
1902 | -- Is_Ignored and Is_Checked flags appropriately. | |
51ea9c94 | 1903 | |
1904 | Check_Applicable_Policy (Aspect); | |
1905 | ||
1906 | if Is_Disabled (Aspect) then | |
1907 | goto Continue; | |
1908 | end if; | |
1909 | ||
c0793fff | 1910 | -- Set the source location of expression, used in the case of |
1911 | -- a failed precondition/postcondition or invariant. Note that | |
1912 | -- the source location of the expression is not usually the best | |
1913 | -- choice here. For example, it gets located on the last AND | |
1914 | -- keyword in a chain of boolean expressiond AND'ed together. | |
1915 | -- It is best to put the message on the first character of the | |
1916 | -- assertion, which is the effect of the First_Node call here. | |
1917 | ||
1918 | if Present (Expr) then | |
1919 | Eloc := Sloc (First_Node (Expr)); | |
1920 | end if; | |
1921 | ||
d7ed83a2 | 1922 | -- Check restriction No_Implementation_Aspect_Specifications |
1923 | ||
c171e1be | 1924 | if Implementation_Defined_Aspect (A_Id) then |
d7ed83a2 | 1925 | Check_Restriction |
1926 | (No_Implementation_Aspect_Specifications, Aspect); | |
1927 | end if; | |
1928 | ||
1929 | -- Check restriction No_Specification_Of_Aspect | |
1930 | ||
1931 | Check_Restriction_No_Specification_Of_Aspect (Aspect); | |
1932 | ||
f67ed4f5 | 1933 | -- Mark aspect analyzed (actual analysis is delayed till later) |
d7ed83a2 | 1934 | |
fb7f2fc4 | 1935 | Set_Analyzed (Aspect); |
d74fc39a | 1936 | Set_Entity (Aspect, E); |
738ec25b | 1937 | |
1938 | -- Build the reference to E that will be used in the built pragmas | |
1939 | ||
d74fc39a | 1940 | Ent := New_Occurrence_Of (E, Sloc (Id)); |
1941 | ||
738ec25b | 1942 | if A_Id = Aspect_Attach_Handler |
1943 | or else A_Id = Aspect_Interrupt_Handler | |
1944 | then | |
1945 | -- Decorate the reference as comming from the sources and force | |
1946 | -- its reanalysis to generate the reference to E; required to | |
1947 | -- avoid reporting spurious warning on E as unreferenced entity | |
1948 | -- (because aspects are not fully analyzed). | |
1949 | ||
1950 | Set_Comes_From_Source (Ent, Comes_From_Source (Id)); | |
1951 | Set_Entity (Ent, Empty); | |
1952 | ||
1953 | Analyze (Ent); | |
1954 | end if; | |
1955 | ||
1e3c4ae6 | 1956 | -- Check for duplicate aspect. Note that the Comes_From_Source |
1957 | -- test allows duplicate Pre/Post's that we generate internally | |
1958 | -- to escape being flagged here. | |
ae888dbd | 1959 | |
6c545057 | 1960 | if No_Duplicates_Allowed (A_Id) then |
1961 | Anod := First (L); | |
1962 | while Anod /= Aspect loop | |
c171e1be | 1963 | if Comes_From_Source (Aspect) |
1964 | and then Same_Aspect (A_Id, Get_Aspect_Id (Anod)) | |
6c545057 | 1965 | then |
1966 | Error_Msg_Name_1 := Nam; | |
1967 | Error_Msg_Sloc := Sloc (Anod); | |
39e1f22f | 1968 | |
6c545057 | 1969 | -- Case of same aspect specified twice |
39e1f22f | 1970 | |
6c545057 | 1971 | if Class_Present (Anod) = Class_Present (Aspect) then |
1972 | if not Class_Present (Anod) then | |
1973 | Error_Msg_NE | |
1974 | ("aspect% for & previously given#", | |
1975 | Id, E); | |
1976 | else | |
1977 | Error_Msg_NE | |
1978 | ("aspect `%''Class` for & previously given#", | |
1979 | Id, E); | |
1980 | end if; | |
39e1f22f | 1981 | end if; |
6c545057 | 1982 | end if; |
ae888dbd | 1983 | |
6c545057 | 1984 | Next (Anod); |
1985 | end loop; | |
1986 | end if; | |
ae888dbd | 1987 | |
4db325e6 | 1988 | -- Check some general restrictions on language defined aspects |
1989 | ||
c171e1be | 1990 | if not Implementation_Defined_Aspect (A_Id) then |
4db325e6 | 1991 | Error_Msg_Name_1 := Nam; |
1992 | ||
d1edd78e | 1993 | -- Not allowed for renaming declarations. Examine the original |
da1b7592 | 1994 | -- node because a subprogram renaming may have been rewritten |
1995 | -- as a body. | |
4db325e6 | 1996 | |
da1b7592 | 1997 | if Nkind (Original_Node (N)) in N_Renaming_Declaration then |
4db325e6 | 1998 | Error_Msg_N |
1999 | ("aspect % not allowed for renaming declaration", | |
2000 | Aspect); | |
2001 | end if; | |
2002 | ||
2003 | -- Not allowed for formal type declarations | |
2004 | ||
2005 | if Nkind (N) = N_Formal_Type_Declaration then | |
2006 | Error_Msg_N | |
2007 | ("aspect % not allowed for formal type declaration", | |
2008 | Aspect); | |
2009 | end if; | |
2010 | end if; | |
2011 | ||
7d20685d | 2012 | -- Copy expression for later processing by the procedures |
2013 | -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations] | |
2014 | ||
2015 | Set_Entity (Id, New_Copy_Tree (Expr)); | |
2016 | ||
37c6e44c | 2017 | -- Set Delay_Required as appropriate to aspect |
2018 | ||
2019 | case Aspect_Delay (A_Id) is | |
2020 | when Always_Delay => | |
2021 | Delay_Required := True; | |
2022 | ||
2023 | when Never_Delay => | |
2024 | Delay_Required := False; | |
2025 | ||
2026 | when Rep_Aspect => | |
2027 | ||
2028 | -- If expression has the form of an integer literal, then | |
2029 | -- do not delay, since we know the value cannot change. | |
2030 | -- This optimization catches most rep clause cases. | |
2031 | ||
e43fc5c5 | 2032 | -- For Boolean aspects, don't delay if no expression |
2033 | ||
2034 | if A_Id in Boolean_Aspects and then No (Expr) then | |
2035 | Delay_Required := False; | |
2036 | ||
2037 | -- For non-Boolean aspects, don't delay if integer literal | |
2038 | ||
2039 | elsif A_Id not in Boolean_Aspects | |
2040 | and then Present (Expr) | |
2041 | and then Nkind (Expr) = N_Integer_Literal | |
2042 | then | |
2043 | Delay_Required := False; | |
2044 | ||
2045 | -- All other cases are delayed | |
2046 | ||
2047 | else | |
2048 | Delay_Required := True; | |
2049 | Set_Has_Delayed_Rep_Aspects (E); | |
2050 | end if; | |
37c6e44c | 2051 | end case; |
2052 | ||
ae888dbd | 2053 | -- Processing based on specific aspect |
2054 | ||
d74fc39a | 2055 | case A_Id is |
aa2f48d2 | 2056 | when Aspect_Unimplemented => |
2057 | null; -- ??? temp for now | |
ae888dbd | 2058 | |
2059 | -- No_Aspect should be impossible | |
2060 | ||
2061 | when No_Aspect => | |
2062 | raise Program_Error; | |
2063 | ||
89f1e35c | 2064 | -- Case 1: Aspects corresponding to attribute definition |
2065 | -- clauses. | |
ae888dbd | 2066 | |
b7b74740 | 2067 | when Aspect_Address | |
2068 | Aspect_Alignment | | |
2069 | Aspect_Bit_Order | | |
2070 | Aspect_Component_Size | | |
89f1e35c | 2071 | Aspect_Constant_Indexing | |
89f1e35c | 2072 | Aspect_Default_Iterator | |
2073 | Aspect_Dispatching_Domain | | |
b7b74740 | 2074 | Aspect_External_Tag | |
2075 | Aspect_Input | | |
b3f8228a | 2076 | Aspect_Iterable | |
89f1e35c | 2077 | Aspect_Iterator_Element | |
b7b74740 | 2078 | Aspect_Machine_Radix | |
2079 | Aspect_Object_Size | | |
2080 | Aspect_Output | | |
2081 | Aspect_Read | | |
2082 | Aspect_Scalar_Storage_Order | | |
e6ce0468 | 2083 | Aspect_Secondary_Stack_Size | |
b7b74740 | 2084 | Aspect_Simple_Storage_Pool | |
fe696bd7 | 2085 | Aspect_Size | |
2086 | Aspect_Small | | |
b7b74740 | 2087 | Aspect_Storage_Pool | |
b7b74740 | 2088 | Aspect_Stream_Size | |
2089 | Aspect_Value_Size | | |
89f1e35c | 2090 | Aspect_Variable_Indexing | |
b7b74740 | 2091 | Aspect_Write => |
d74fc39a | 2092 | |
89f1e35c | 2093 | -- Indexing aspects apply only to tagged type |
2094 | ||
2095 | if (A_Id = Aspect_Constant_Indexing | |
37c6e44c | 2096 | or else |
2097 | A_Id = Aspect_Variable_Indexing) | |
89f1e35c | 2098 | and then not (Is_Type (E) |
2099 | and then Is_Tagged_Type (E)) | |
2100 | then | |
05987af3 | 2101 | Error_Msg_N |
2102 | ("indexing aspect can only apply to a tagged type", | |
3f4c9ffc | 2103 | Aspect); |
89f1e35c | 2104 | goto Continue; |
2105 | end if; | |
2106 | ||
39616053 | 2107 | -- For the case of aspect Address, we don't consider that we |
588e7f97 | 2108 | -- know the entity is never set in the source, since it is |
2109 | -- is likely aliasing is occurring. | |
2110 | ||
2111 | -- Note: one might think that the analysis of the resulting | |
2112 | -- attribute definition clause would take care of that, but | |
2113 | -- that's not the case since it won't be from source. | |
2114 | ||
2115 | if A_Id = Aspect_Address then | |
2116 | Set_Never_Set_In_Source (E, False); | |
2117 | end if; | |
2118 | ||
5ac76cee | 2119 | -- Correctness of the profile of a stream operation is |
2120 | -- verified at the freeze point, but we must detect the | |
2121 | -- illegal specification of this aspect for a subtype now, | |
2122 | -- to prevent malformed rep_item chains. | |
2123 | ||
fbf4d6ef | 2124 | if A_Id = Aspect_Input or else |
2125 | A_Id = Aspect_Output or else | |
2126 | A_Id = Aspect_Read or else | |
2127 | A_Id = Aspect_Write | |
5ac76cee | 2128 | then |
fbf4d6ef | 2129 | if not Is_First_Subtype (E) then |
2130 | Error_Msg_N | |
2131 | ("local name must be a first subtype", Aspect); | |
2132 | goto Continue; | |
2133 | ||
2134 | -- If stream aspect applies to the class-wide type, | |
2135 | -- the generated attribute definition applies to the | |
2136 | -- class-wide type as well. | |
2137 | ||
2138 | elsif Class_Present (Aspect) then | |
2139 | Ent := | |
2140 | Make_Attribute_Reference (Loc, | |
2141 | Prefix => Ent, | |
2142 | Attribute_Name => Name_Class); | |
2143 | end if; | |
5ac76cee | 2144 | end if; |
2145 | ||
d74fc39a | 2146 | -- Construct the attribute definition clause |
2147 | ||
2148 | Aitem := | |
94153a42 | 2149 | Make_Attribute_Definition_Clause (Loc, |
d74fc39a | 2150 | Name => Ent, |
ae888dbd | 2151 | Chars => Chars (Id), |
2152 | Expression => Relocate_Node (Expr)); | |
2153 | ||
af9a0cc3 | 2154 | -- If the address is specified, then we treat the entity as |
41f06abf | 2155 | -- referenced, to avoid spurious warnings. This is analogous |
2156 | -- to what is done with an attribute definition clause, but | |
2157 | -- here we don't want to generate a reference because this | |
2158 | -- is the point of definition of the entity. | |
2159 | ||
2160 | if A_Id = Aspect_Address then | |
2161 | Set_Referenced (E); | |
2162 | end if; | |
2163 | ||
51ea9c94 | 2164 | -- Case 2: Aspects corresponding to pragmas |
d74fc39a | 2165 | |
89f1e35c | 2166 | -- Case 2a: Aspects corresponding to pragmas with two |
2167 | -- arguments, where the first argument is a local name | |
2168 | -- referring to the entity, and the second argument is the | |
2169 | -- aspect definition expression. | |
ae888dbd | 2170 | |
04ae062f | 2171 | -- Linker_Section/Suppress/Unsuppress |
0fd13d32 | 2172 | |
04ae062f | 2173 | when Aspect_Linker_Section | |
2174 | Aspect_Suppress | | |
2175 | Aspect_Unsuppress => | |
ae888dbd | 2176 | |
0fd13d32 | 2177 | Make_Aitem_Pragma |
2178 | (Pragma_Argument_Associations => New_List ( | |
2179 | Make_Pragma_Argument_Association (Loc, | |
2180 | Expression => New_Occurrence_Of (E, Loc)), | |
2181 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2182 | Expression => Relocate_Node (Expr))), | |
2183 | Pragma_Name => Chars (Id)); | |
57cd943b | 2184 | |
0fd13d32 | 2185 | -- Synchronization |
d74fc39a | 2186 | |
0fd13d32 | 2187 | -- Corresponds to pragma Implemented, construct the pragma |
49213728 | 2188 | |
5bbfbad2 | 2189 | when Aspect_Synchronization => |
0fd13d32 | 2190 | Make_Aitem_Pragma |
2191 | (Pragma_Argument_Associations => New_List ( | |
2192 | Make_Pragma_Argument_Association (Loc, | |
2193 | Expression => New_Occurrence_Of (E, Loc)), | |
2194 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2195 | Expression => Relocate_Node (Expr))), | |
2196 | Pragma_Name => Name_Implemented); | |
49213728 | 2197 | |
e2bf777d | 2198 | -- Attach_Handler |
0fd13d32 | 2199 | |
89f1e35c | 2200 | when Aspect_Attach_Handler => |
0fd13d32 | 2201 | Make_Aitem_Pragma |
2202 | (Pragma_Argument_Associations => New_List ( | |
2203 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2204 | Expression => Ent), | |
2205 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2206 | Expression => Relocate_Node (Expr))), | |
2207 | Pragma_Name => Name_Attach_Handler); | |
2208 | ||
f67ed4f5 | 2209 | -- We need to insert this pragma into the tree to get proper |
2210 | -- processing and to look valid from a placement viewpoint. | |
2211 | ||
e2bf777d | 2212 | Insert_Pragma (Aitem); |
f67ed4f5 | 2213 | goto Continue; |
2214 | ||
0fd13d32 | 2215 | -- Dynamic_Predicate, Predicate, Static_Predicate |
89f1e35c | 2216 | |
2217 | when Aspect_Dynamic_Predicate | | |
2218 | Aspect_Predicate | | |
2219 | Aspect_Static_Predicate => | |
2220 | ||
a47ce82d | 2221 | -- These aspects apply only to subtypes |
2222 | ||
2223 | if not Is_Type (E) then | |
2224 | Error_Msg_N | |
2225 | ("predicate can only be specified for a subtype", | |
2226 | Aspect); | |
2227 | goto Continue; | |
7c0c95b8 | 2228 | |
2229 | elsif Is_Incomplete_Type (E) then | |
2230 | Error_Msg_N | |
2231 | ("predicate cannot apply to incomplete view", Aspect); | |
2232 | goto Continue; | |
a47ce82d | 2233 | end if; |
2234 | ||
89f1e35c | 2235 | -- Construct the pragma (always a pragma Predicate, with |
51ea9c94 | 2236 | -- flags recording whether it is static/dynamic). We also |
2237 | -- set flags recording this in the type itself. | |
89f1e35c | 2238 | |
0fd13d32 | 2239 | Make_Aitem_Pragma |
2240 | (Pragma_Argument_Associations => New_List ( | |
2241 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2242 | Expression => Ent), | |
2243 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2244 | Expression => Relocate_Node (Expr))), | |
fdec445e | 2245 | Pragma_Name => Name_Predicate); |
89f1e35c | 2246 | |
51ea9c94 | 2247 | -- Mark type has predicates, and remember what kind of |
2248 | -- aspect lead to this predicate (we need this to access | |
2249 | -- the right set of check policies later on). | |
2250 | ||
2251 | Set_Has_Predicates (E); | |
2252 | ||
2253 | if A_Id = Aspect_Dynamic_Predicate then | |
2254 | Set_Has_Dynamic_Predicate_Aspect (E); | |
2255 | elsif A_Id = Aspect_Static_Predicate then | |
2256 | Set_Has_Static_Predicate_Aspect (E); | |
2257 | end if; | |
2258 | ||
89f1e35c | 2259 | -- If the type is private, indicate that its completion |
6653b695 | 2260 | -- has a freeze node, because that is the one that will |
2261 | -- be visible at freeze time. | |
89f1e35c | 2262 | |
0fd13d32 | 2263 | if Is_Private_Type (E) and then Present (Full_View (E)) then |
89f1e35c | 2264 | Set_Has_Predicates (Full_View (E)); |
51ea9c94 | 2265 | |
2266 | if A_Id = Aspect_Dynamic_Predicate then | |
2267 | Set_Has_Dynamic_Predicate_Aspect (Full_View (E)); | |
2268 | elsif A_Id = Aspect_Static_Predicate then | |
2269 | Set_Has_Static_Predicate_Aspect (Full_View (E)); | |
2270 | end if; | |
2271 | ||
89f1e35c | 2272 | Set_Has_Delayed_Aspects (Full_View (E)); |
2273 | Ensure_Freeze_Node (Full_View (E)); | |
2274 | end if; | |
2275 | ||
fdec445e | 2276 | -- Predicate_Failure |
2277 | ||
2278 | when Aspect_Predicate_Failure => | |
2279 | ||
2280 | -- This aspect applies only to subtypes | |
2281 | ||
2282 | if not Is_Type (E) then | |
2283 | Error_Msg_N | |
2284 | ("predicate can only be specified for a subtype", | |
2285 | Aspect); | |
2286 | goto Continue; | |
2287 | ||
2288 | elsif Is_Incomplete_Type (E) then | |
2289 | Error_Msg_N | |
2290 | ("predicate cannot apply to incomplete view", Aspect); | |
2291 | goto Continue; | |
2292 | end if; | |
2293 | ||
2294 | -- Construct the pragma | |
2295 | ||
2296 | Make_Aitem_Pragma | |
2297 | (Pragma_Argument_Associations => New_List ( | |
2298 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2299 | Expression => Ent), | |
2300 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2301 | Expression => Relocate_Node (Expr))), | |
2302 | Pragma_Name => Name_Predicate_Failure); | |
2303 | ||
2304 | Set_Has_Predicates (E); | |
2305 | ||
2306 | -- If the type is private, indicate that its completion | |
2307 | -- has a freeze node, because that is the one that will | |
2308 | -- be visible at freeze time. | |
2309 | ||
2310 | if Is_Private_Type (E) and then Present (Full_View (E)) then | |
2311 | Set_Has_Predicates (Full_View (E)); | |
2312 | Set_Has_Delayed_Aspects (Full_View (E)); | |
2313 | Ensure_Freeze_Node (Full_View (E)); | |
2314 | end if; | |
2315 | ||
89f1e35c | 2316 | -- Case 2b: Aspects corresponding to pragmas with two |
2317 | -- arguments, where the second argument is a local name | |
2318 | -- referring to the entity, and the first argument is the | |
2319 | -- aspect definition expression. | |
ae888dbd | 2320 | |
0fd13d32 | 2321 | -- Convention |
2322 | ||
ee2b7923 | 2323 | when Aspect_Convention => |
2324 | Analyze_Aspect_Convention; | |
2325 | goto Continue; | |
97bf66e6 | 2326 | |
ee2b7923 | 2327 | -- External_Name, Link_Name |
97bf66e6 | 2328 | |
ee2b7923 | 2329 | when Aspect_External_Name | |
2330 | Aspect_Link_Name => | |
2331 | Analyze_Aspect_External_Link_Name; | |
2332 | goto Continue; | |
e1cedbae | 2333 | |
0fd13d32 | 2334 | -- CPU, Interrupt_Priority, Priority |
2335 | ||
d6814978 | 2336 | -- These three aspects can be specified for a subprogram spec |
2337 | -- or body, in which case we analyze the expression and export | |
2338 | -- the value of the aspect. | |
2339 | ||
2340 | -- Previously, we generated an equivalent pragma for bodies | |
2341 | -- (note that the specs cannot contain these pragmas). The | |
2342 | -- pragma was inserted ahead of local declarations, rather than | |
2343 | -- after the body. This leads to a certain duplication between | |
2344 | -- the processing performed for the aspect and the pragma, but | |
2345 | -- given the straightforward handling required it is simpler | |
2346 | -- to duplicate than to translate the aspect in the spec into | |
2347 | -- a pragma in the declarative part of the body. | |
3a72f9c3 | 2348 | |
2349 | when Aspect_CPU | | |
2350 | Aspect_Interrupt_Priority | | |
2351 | Aspect_Priority => | |
51ea9c94 | 2352 | |
d6814978 | 2353 | if Nkind_In (N, N_Subprogram_Body, |
2354 | N_Subprogram_Declaration) | |
2355 | then | |
2356 | -- Analyze the aspect expression | |
2357 | ||
2358 | Analyze_And_Resolve (Expr, Standard_Integer); | |
2359 | ||
2360 | -- Interrupt_Priority aspect not allowed for main | |
078a74b8 | 2361 | -- subprograms. RM D.1 does not forbid this explicitly, |
2362 | -- but RM J.15.11(6/3) does not permit pragma | |
d6814978 | 2363 | -- Interrupt_Priority for subprograms. |
2364 | ||
2365 | if A_Id = Aspect_Interrupt_Priority then | |
2366 | Error_Msg_N | |
2367 | ("Interrupt_Priority aspect cannot apply to " | |
2368 | & "subprogram", Expr); | |
2369 | ||
2370 | -- The expression must be static | |
2371 | ||
cda40848 | 2372 | elsif not Is_OK_Static_Expression (Expr) then |
d6814978 | 2373 | Flag_Non_Static_Expr |
2374 | ("aspect requires static expression!", Expr); | |
2375 | ||
24d7b9d6 | 2376 | -- Check whether this is the main subprogram. Issue a |
2377 | -- warning only if it is obviously not a main program | |
2378 | -- (when it has parameters or when the subprogram is | |
2379 | -- within a package). | |
2380 | ||
2381 | elsif Present (Parameter_Specifications | |
2382 | (Specification (N))) | |
2383 | or else not Is_Compilation_Unit (Defining_Entity (N)) | |
d6814978 | 2384 | then |
078a74b8 | 2385 | -- See RM D.1(14/3) and D.16(12/3) |
d6814978 | 2386 | |
2387 | Error_Msg_N | |
2388 | ("aspect applied to subprogram other than the " | |
2389 | & "main subprogram has no effect??", Expr); | |
2390 | ||
2391 | -- Otherwise check in range and export the value | |
2392 | ||
2393 | -- For the CPU aspect | |
2394 | ||
2395 | elsif A_Id = Aspect_CPU then | |
2396 | if Is_In_Range (Expr, RTE (RE_CPU_Range)) then | |
2397 | ||
2398 | -- Value is correct so we export the value to make | |
2399 | -- it available at execution time. | |
2400 | ||
2401 | Set_Main_CPU | |
2402 | (Main_Unit, UI_To_Int (Expr_Value (Expr))); | |
2403 | ||
2404 | else | |
2405 | Error_Msg_N | |
2406 | ("main subprogram CPU is out of range", Expr); | |
2407 | end if; | |
2408 | ||
2409 | -- For the Priority aspect | |
2410 | ||
2411 | elsif A_Id = Aspect_Priority then | |
2412 | if Is_In_Range (Expr, RTE (RE_Priority)) then | |
2413 | ||
2414 | -- Value is correct so we export the value to make | |
2415 | -- it available at execution time. | |
2416 | ||
2417 | Set_Main_Priority | |
2418 | (Main_Unit, UI_To_Int (Expr_Value (Expr))); | |
2419 | ||
32572384 | 2420 | -- Ignore pragma if Relaxed_RM_Semantics to support |
2421 | -- other targets/non GNAT compilers. | |
2422 | ||
2423 | elsif not Relaxed_RM_Semantics then | |
d6814978 | 2424 | Error_Msg_N |
2425 | ("main subprogram priority is out of range", | |
2426 | Expr); | |
2427 | end if; | |
2428 | end if; | |
2429 | ||
2430 | -- Load an arbitrary entity from System.Tasking.Stages | |
2431 | -- or System.Tasking.Restricted.Stages (depending on | |
2432 | -- the supported profile) to make sure that one of these | |
2433 | -- packages is implicitly with'ed, since we need to have | |
2434 | -- the tasking run time active for the pragma Priority to | |
a0c3eeb9 | 2435 | -- have any effect. Previously we with'ed the package |
d6814978 | 2436 | -- System.Tasking, but this package does not trigger the |
2437 | -- required initialization of the run-time library. | |
2438 | ||
2439 | declare | |
2440 | Discard : Entity_Id; | |
d6814978 | 2441 | begin |
2442 | if Restricted_Profile then | |
2443 | Discard := RTE (RE_Activate_Restricted_Tasks); | |
2444 | else | |
2445 | Discard := RTE (RE_Activate_Tasks); | |
2446 | end if; | |
2447 | end; | |
2448 | ||
e6ce0468 | 2449 | -- Handling for these aspects in subprograms is complete |
d6814978 | 2450 | |
2451 | goto Continue; | |
2452 | ||
2f06c88a | 2453 | -- For tasks pass the aspect as an attribute |
0fd13d32 | 2454 | |
3a72f9c3 | 2455 | else |
2456 | Aitem := | |
2457 | Make_Attribute_Definition_Clause (Loc, | |
2458 | Name => Ent, | |
2459 | Chars => Chars (Id), | |
2460 | Expression => Relocate_Node (Expr)); | |
2461 | end if; | |
2462 | ||
0fd13d32 | 2463 | -- Warnings |
2464 | ||
ae888dbd | 2465 | when Aspect_Warnings => |
0fd13d32 | 2466 | Make_Aitem_Pragma |
2467 | (Pragma_Argument_Associations => New_List ( | |
2468 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2469 | Expression => Relocate_Node (Expr)), | |
2470 | Make_Pragma_Argument_Association (Loc, | |
2471 | Expression => New_Occurrence_Of (E, Loc))), | |
2472 | Pragma_Name => Chars (Id)); | |
ae888dbd | 2473 | |
2f06c88a | 2474 | Decorate (Aspect, Aitem); |
2475 | Insert_Pragma (Aitem); | |
2476 | goto Continue; | |
2477 | ||
89f1e35c | 2478 | -- Case 2c: Aspects corresponding to pragmas with three |
2479 | -- arguments. | |
d64221a7 | 2480 | |
89f1e35c | 2481 | -- Invariant aspects have a first argument that references the |
2482 | -- entity, a second argument that is the expression and a third | |
2483 | -- argument that is an appropriate message. | |
d64221a7 | 2484 | |
0fd13d32 | 2485 | -- Invariant, Type_Invariant |
2486 | ||
89f1e35c | 2487 | when Aspect_Invariant | |
2488 | Aspect_Type_Invariant => | |
d64221a7 | 2489 | |
89f1e35c | 2490 | -- Analysis of the pragma will verify placement legality: |
2491 | -- an invariant must apply to a private type, or appear in | |
2492 | -- the private part of a spec and apply to a completion. | |
d64221a7 | 2493 | |
0fd13d32 | 2494 | Make_Aitem_Pragma |
2495 | (Pragma_Argument_Associations => New_List ( | |
2496 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2497 | Expression => Ent), | |
2498 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2499 | Expression => Relocate_Node (Expr))), | |
2500 | Pragma_Name => Name_Invariant); | |
89f1e35c | 2501 | |
2502 | -- Add message unless exception messages are suppressed | |
2503 | ||
2504 | if not Opt.Exception_Locations_Suppressed then | |
2505 | Append_To (Pragma_Argument_Associations (Aitem), | |
2506 | Make_Pragma_Argument_Association (Eloc, | |
2507 | Chars => Name_Message, | |
2508 | Expression => | |
2509 | Make_String_Literal (Eloc, | |
2510 | Strval => "failed invariant from " | |
2511 | & Build_Location_String (Eloc)))); | |
d64221a7 | 2512 | end if; |
2513 | ||
89f1e35c | 2514 | -- For Invariant case, insert immediately after the entity |
2515 | -- declaration. We do not have to worry about delay issues | |
2516 | -- since the pragma processing takes care of this. | |
2517 | ||
89f1e35c | 2518 | Delay_Required := False; |
d64221a7 | 2519 | |
47a46747 | 2520 | -- Case 2d : Aspects that correspond to a pragma with one |
2521 | -- argument. | |
2522 | ||
0fd13d32 | 2523 | -- Abstract_State |
115f7b08 | 2524 | |
d4e369ad | 2525 | -- Aspect Abstract_State introduces implicit declarations for |
2526 | -- all state abstraction entities it defines. To emulate this | |
2527 | -- behavior, insert the pragma at the beginning of the visible | |
2528 | -- declarations of the related package so that it is analyzed | |
2529 | -- immediately. | |
2530 | ||
9129c28f | 2531 | when Aspect_Abstract_State => Abstract_State : declare |
eb4f7efa | 2532 | Context : Node_Id := N; |
9129c28f | 2533 | |
2534 | begin | |
eb4f7efa | 2535 | -- When aspect Abstract_State appears on a generic package, |
2536 | -- it is propageted to the package instance. The context in | |
2537 | -- this case is the instance spec. | |
2538 | ||
2539 | if Nkind (Context) = N_Package_Instantiation then | |
2540 | Context := Instance_Spec (Context); | |
2541 | end if; | |
2542 | ||
2543 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2544 | N_Package_Declaration) | |
9129c28f | 2545 | then |
9129c28f | 2546 | Make_Aitem_Pragma |
2547 | (Pragma_Argument_Associations => New_List ( | |
2548 | Make_Pragma_Argument_Association (Loc, | |
2549 | Expression => Relocate_Node (Expr))), | |
2550 | Pragma_Name => Name_Abstract_State); | |
630b6d55 | 2551 | |
5655be8a | 2552 | Decorate (Aspect, Aitem); |
2553 | Insert_Pragma | |
2554 | (Prag => Aitem, | |
2555 | Is_Instance => | |
2556 | Is_Generic_Instance (Defining_Entity (Context))); | |
9129c28f | 2557 | |
2558 | else | |
2559 | Error_Msg_NE | |
2560 | ("aspect & must apply to a package declaration", | |
2561 | Aspect, Id); | |
2562 | end if; | |
2563 | ||
2564 | goto Continue; | |
2565 | end Abstract_State; | |
115f7b08 | 2566 | |
85ee12c0 | 2567 | -- Aspect Async_Readers is never delayed because it is |
2568 | -- equivalent to a source pragma which appears after the | |
2569 | -- related object declaration. | |
2570 | ||
2571 | when Aspect_Async_Readers => | |
2572 | Make_Aitem_Pragma | |
2573 | (Pragma_Argument_Associations => New_List ( | |
2574 | Make_Pragma_Argument_Association (Loc, | |
2575 | Expression => Relocate_Node (Expr))), | |
2576 | Pragma_Name => Name_Async_Readers); | |
2577 | ||
2578 | Decorate (Aspect, Aitem); | |
2579 | Insert_Pragma (Aitem); | |
2580 | goto Continue; | |
2581 | ||
2582 | -- Aspect Async_Writers is never delayed because it is | |
2583 | -- equivalent to a source pragma which appears after the | |
2584 | -- related object declaration. | |
2585 | ||
2586 | when Aspect_Async_Writers => | |
2587 | Make_Aitem_Pragma | |
2588 | (Pragma_Argument_Associations => New_List ( | |
2589 | Make_Pragma_Argument_Association (Loc, | |
2590 | Expression => Relocate_Node (Expr))), | |
2591 | Pragma_Name => Name_Async_Writers); | |
2592 | ||
2593 | Decorate (Aspect, Aitem); | |
2594 | Insert_Pragma (Aitem); | |
2595 | goto Continue; | |
2596 | ||
d0849c23 | 2597 | -- Aspect Constant_After_Elaboration is never delayed because |
2598 | -- it is equivalent to a source pragma which appears after the | |
2599 | -- related object declaration. | |
2600 | ||
2601 | when Aspect_Constant_After_Elaboration => | |
2602 | Make_Aitem_Pragma | |
2603 | (Pragma_Argument_Associations => New_List ( | |
2604 | Make_Pragma_Argument_Association (Loc, | |
2605 | Expression => Relocate_Node (Expr))), | |
2606 | Pragma_Name => | |
2607 | Name_Constant_After_Elaboration); | |
2608 | ||
2609 | Decorate (Aspect, Aitem); | |
2610 | Insert_Pragma (Aitem); | |
2611 | goto Continue; | |
2612 | ||
ec6f6da5 | 2613 | -- Aspect Default_Internal_Condition is never delayed because |
2614 | -- it is equivalent to a source pragma which appears after the | |
2615 | -- related private type. To deal with forward references, the | |
2616 | -- generated pragma is stored in the rep chain of the related | |
2617 | -- private type as types do not carry contracts. The pragma is | |
2618 | -- wrapped inside of a procedure at the freeze point of the | |
2619 | -- private type's full view. | |
2620 | ||
2621 | when Aspect_Default_Initial_Condition => | |
2622 | Make_Aitem_Pragma | |
2623 | (Pragma_Argument_Associations => New_List ( | |
2624 | Make_Pragma_Argument_Association (Loc, | |
2625 | Expression => Relocate_Node (Expr))), | |
2626 | Pragma_Name => | |
2627 | Name_Default_Initial_Condition); | |
2628 | ||
2629 | Decorate (Aspect, Aitem); | |
2630 | Insert_Pragma (Aitem); | |
2631 | goto Continue; | |
2632 | ||
647fab54 | 2633 | -- Default_Storage_Pool |
2634 | ||
2635 | when Aspect_Default_Storage_Pool => | |
2636 | Make_Aitem_Pragma | |
2637 | (Pragma_Argument_Associations => New_List ( | |
2638 | Make_Pragma_Argument_Association (Loc, | |
2639 | Expression => Relocate_Node (Expr))), | |
2640 | Pragma_Name => | |
2641 | Name_Default_Storage_Pool); | |
2642 | ||
2643 | Decorate (Aspect, Aitem); | |
2644 | Insert_Pragma (Aitem); | |
2645 | goto Continue; | |
2646 | ||
0fd13d32 | 2647 | -- Depends |
2648 | ||
e2bf777d | 2649 | -- Aspect Depends is never delayed because it is equivalent to |
2650 | -- a source pragma which appears after the related subprogram. | |
2651 | -- To deal with forward references, the generated pragma is | |
2652 | -- stored in the contract of the related subprogram and later | |
2653 | -- analyzed at the end of the declarative region. See routine | |
2654 | -- Analyze_Depends_In_Decl_Part for details. | |
6144c105 | 2655 | |
12334c57 | 2656 | when Aspect_Depends => |
0fd13d32 | 2657 | Make_Aitem_Pragma |
2658 | (Pragma_Argument_Associations => New_List ( | |
2659 | Make_Pragma_Argument_Association (Loc, | |
2660 | Expression => Relocate_Node (Expr))), | |
2661 | Pragma_Name => Name_Depends); | |
2662 | ||
e2bf777d | 2663 | Decorate (Aspect, Aitem); |
2664 | Insert_Pragma (Aitem); | |
c1006d6d | 2665 | goto Continue; |
2666 | ||
85ee12c0 | 2667 | -- Aspect Effecitve_Reads is never delayed because it is |
2668 | -- equivalent to a source pragma which appears after the | |
2669 | -- related object declaration. | |
2670 | ||
2671 | when Aspect_Effective_Reads => | |
2672 | Make_Aitem_Pragma | |
2673 | (Pragma_Argument_Associations => New_List ( | |
2674 | Make_Pragma_Argument_Association (Loc, | |
2675 | Expression => Relocate_Node (Expr))), | |
2676 | Pragma_Name => Name_Effective_Reads); | |
2677 | ||
2678 | Decorate (Aspect, Aitem); | |
2679 | Insert_Pragma (Aitem); | |
2680 | goto Continue; | |
2681 | ||
2682 | -- Aspect Effective_Writes is never delayed because it is | |
2683 | -- equivalent to a source pragma which appears after the | |
2684 | -- related object declaration. | |
2685 | ||
2686 | when Aspect_Effective_Writes => | |
2687 | Make_Aitem_Pragma | |
2688 | (Pragma_Argument_Associations => New_List ( | |
2689 | Make_Pragma_Argument_Association (Loc, | |
2690 | Expression => Relocate_Node (Expr))), | |
2691 | Pragma_Name => Name_Effective_Writes); | |
2692 | ||
2693 | Decorate (Aspect, Aitem); | |
2694 | Insert_Pragma (Aitem); | |
2695 | goto Continue; | |
2696 | ||
cab27d2a | 2697 | -- Aspect Extensions_Visible is never delayed because it is |
2698 | -- equivalent to a source pragma which appears after the | |
2699 | -- related subprogram. | |
2700 | ||
2701 | when Aspect_Extensions_Visible => | |
2702 | Make_Aitem_Pragma | |
2703 | (Pragma_Argument_Associations => New_List ( | |
2704 | Make_Pragma_Argument_Association (Loc, | |
2705 | Expression => Relocate_Node (Expr))), | |
2706 | Pragma_Name => Name_Extensions_Visible); | |
2707 | ||
2708 | Decorate (Aspect, Aitem); | |
2709 | Insert_Pragma (Aitem); | |
2710 | goto Continue; | |
2711 | ||
3dbe7a69 | 2712 | -- Aspect Ghost is never delayed because it is equivalent to a |
2713 | -- source pragma which appears at the top of [generic] package | |
2714 | -- declarations or after an object, a [generic] subprogram, or | |
2715 | -- a type declaration. | |
2716 | ||
5655be8a | 2717 | when Aspect_Ghost => |
3dbe7a69 | 2718 | Make_Aitem_Pragma |
2719 | (Pragma_Argument_Associations => New_List ( | |
2720 | Make_Pragma_Argument_Association (Loc, | |
2721 | Expression => Relocate_Node (Expr))), | |
2722 | Pragma_Name => Name_Ghost); | |
2723 | ||
2724 | Decorate (Aspect, Aitem); | |
5655be8a | 2725 | Insert_Pragma (Aitem); |
3dbe7a69 | 2726 | goto Continue; |
3dbe7a69 | 2727 | |
0fd13d32 | 2728 | -- Global |
12334c57 | 2729 | |
e2bf777d | 2730 | -- Aspect Global is never delayed because it is equivalent to |
2731 | -- a source pragma which appears after the related subprogram. | |
2732 | -- To deal with forward references, the generated pragma is | |
2733 | -- stored in the contract of the related subprogram and later | |
2734 | -- analyzed at the end of the declarative region. See routine | |
2735 | -- Analyze_Global_In_Decl_Part for details. | |
3cdbaa5a | 2736 | |
2737 | when Aspect_Global => | |
0fd13d32 | 2738 | Make_Aitem_Pragma |
2739 | (Pragma_Argument_Associations => New_List ( | |
2740 | Make_Pragma_Argument_Association (Loc, | |
2741 | Expression => Relocate_Node (Expr))), | |
2742 | Pragma_Name => Name_Global); | |
2743 | ||
e2bf777d | 2744 | Decorate (Aspect, Aitem); |
2745 | Insert_Pragma (Aitem); | |
c1006d6d | 2746 | goto Continue; |
2747 | ||
9c138530 | 2748 | -- Initial_Condition |
2749 | ||
e2bf777d | 2750 | -- Aspect Initial_Condition is never delayed because it is |
2751 | -- equivalent to a source pragma which appears after the | |
2752 | -- related package. To deal with forward references, the | |
2753 | -- generated pragma is stored in the contract of the related | |
2754 | -- package and later analyzed at the end of the declarative | |
2755 | -- region. See routine Analyze_Initial_Condition_In_Decl_Part | |
2756 | -- for details. | |
9c138530 | 2757 | |
2758 | when Aspect_Initial_Condition => Initial_Condition : declare | |
eb4f7efa | 2759 | Context : Node_Id := N; |
9c138530 | 2760 | |
2761 | begin | |
e2bf777d | 2762 | -- When aspect Initial_Condition appears on a generic |
2763 | -- package, it is propageted to the package instance. The | |
2764 | -- context in this case is the instance spec. | |
eb4f7efa | 2765 | |
2766 | if Nkind (Context) = N_Package_Instantiation then | |
2767 | Context := Instance_Spec (Context); | |
2768 | end if; | |
2769 | ||
2770 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2771 | N_Package_Declaration) | |
9c138530 | 2772 | then |
9c138530 | 2773 | Make_Aitem_Pragma |
2774 | (Pragma_Argument_Associations => New_List ( | |
2775 | Make_Pragma_Argument_Association (Loc, | |
2776 | Expression => Relocate_Node (Expr))), | |
2777 | Pragma_Name => | |
2778 | Name_Initial_Condition); | |
9c138530 | 2779 | |
5655be8a | 2780 | Decorate (Aspect, Aitem); |
2781 | Insert_Pragma | |
2782 | (Prag => Aitem, | |
2783 | Is_Instance => | |
2784 | Is_Generic_Instance (Defining_Entity (Context))); | |
50e44732 | 2785 | |
5655be8a | 2786 | -- Otherwise the context is illegal |
9c138530 | 2787 | |
2788 | else | |
2789 | Error_Msg_NE | |
2790 | ("aspect & must apply to a package declaration", | |
2791 | Aspect, Id); | |
2792 | end if; | |
2793 | ||
2794 | goto Continue; | |
2795 | end Initial_Condition; | |
2796 | ||
d4e369ad | 2797 | -- Initializes |
2798 | ||
e2bf777d | 2799 | -- Aspect Initializes is never delayed because it is equivalent |
2800 | -- to a source pragma appearing after the related package. To | |
2801 | -- deal with forward references, the generated pragma is stored | |
2802 | -- in the contract of the related package and later analyzed at | |
2803 | -- the end of the declarative region. For details, see routine | |
2804 | -- Analyze_Initializes_In_Decl_Part. | |
d4e369ad | 2805 | |
2806 | when Aspect_Initializes => Initializes : declare | |
eb4f7efa | 2807 | Context : Node_Id := N; |
d4e369ad | 2808 | |
2809 | begin | |
50e44732 | 2810 | -- When aspect Initializes appears on a generic package, |
2811 | -- it is propageted to the package instance. The context | |
2812 | -- in this case is the instance spec. | |
eb4f7efa | 2813 | |
2814 | if Nkind (Context) = N_Package_Instantiation then | |
2815 | Context := Instance_Spec (Context); | |
2816 | end if; | |
2817 | ||
2818 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2819 | N_Package_Declaration) | |
d4e369ad | 2820 | then |
d4e369ad | 2821 | Make_Aitem_Pragma |
2822 | (Pragma_Argument_Associations => New_List ( | |
2823 | Make_Pragma_Argument_Association (Loc, | |
2824 | Expression => Relocate_Node (Expr))), | |
2825 | Pragma_Name => Name_Initializes); | |
d4e369ad | 2826 | |
5655be8a | 2827 | Decorate (Aspect, Aitem); |
2828 | Insert_Pragma | |
2829 | (Prag => Aitem, | |
2830 | Is_Instance => | |
2831 | Is_Generic_Instance (Defining_Entity (Context))); | |
50e44732 | 2832 | |
5655be8a | 2833 | -- Otherwise the context is illegal |
d4e369ad | 2834 | |
2835 | else | |
2836 | Error_Msg_NE | |
2837 | ("aspect & must apply to a package declaration", | |
2838 | Aspect, Id); | |
2839 | end if; | |
2840 | ||
2841 | goto Continue; | |
2842 | end Initializes; | |
2843 | ||
cbd45084 | 2844 | -- Max_Queue_Length |
2845 | ||
2846 | when Aspect_Max_Queue_Length => | |
2847 | Make_Aitem_Pragma | |
2848 | (Pragma_Argument_Associations => New_List ( | |
2849 | Make_Pragma_Argument_Association (Loc, | |
2850 | Expression => Relocate_Node (Expr))), | |
2851 | Pragma_Name => Name_Max_Queue_Length); | |
2852 | ||
2853 | Decorate (Aspect, Aitem); | |
2854 | Insert_Pragma (Aitem); | |
2855 | goto Continue; | |
2856 | ||
1fd4313f | 2857 | -- Obsolescent |
2858 | ||
2859 | when Aspect_Obsolescent => declare | |
2860 | Args : List_Id; | |
2861 | ||
2862 | begin | |
2863 | if No (Expr) then | |
2864 | Args := No_List; | |
2865 | else | |
2866 | Args := New_List ( | |
2867 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2868 | Expression => Relocate_Node (Expr))); | |
2869 | end if; | |
2870 | ||
2871 | Make_Aitem_Pragma | |
2872 | (Pragma_Argument_Associations => Args, | |
2873 | Pragma_Name => Chars (Id)); | |
2874 | end; | |
2875 | ||
5cc6f0cf | 2876 | -- Part_Of |
2877 | ||
2878 | when Aspect_Part_Of => | |
2879 | if Nkind_In (N, N_Object_Declaration, | |
2880 | N_Package_Instantiation) | |
736b80cc | 2881 | or else Is_Single_Concurrent_Type_Declaration (N) |
5cc6f0cf | 2882 | then |
2883 | Make_Aitem_Pragma | |
2884 | (Pragma_Argument_Associations => New_List ( | |
2885 | Make_Pragma_Argument_Association (Loc, | |
2886 | Expression => Relocate_Node (Expr))), | |
2887 | Pragma_Name => Name_Part_Of); | |
2888 | ||
736b80cc | 2889 | Decorate (Aspect, Aitem); |
2890 | Insert_Pragma (Aitem); | |
736b80cc | 2891 | |
5cc6f0cf | 2892 | else |
2893 | Error_Msg_NE | |
736b80cc | 2894 | ("aspect & must apply to package instantiation, " |
2895 | & "object, single protected type or single task type", | |
2896 | Aspect, Id); | |
5cc6f0cf | 2897 | end if; |
2898 | ||
d5c65b80 | 2899 | goto Continue; |
2900 | ||
5dd93a61 | 2901 | -- SPARK_Mode |
2902 | ||
2f06c88a | 2903 | when Aspect_SPARK_Mode => |
5dd93a61 | 2904 | Make_Aitem_Pragma |
2905 | (Pragma_Argument_Associations => New_List ( | |
2906 | Make_Pragma_Argument_Association (Loc, | |
2907 | Expression => Relocate_Node (Expr))), | |
2908 | Pragma_Name => Name_SPARK_Mode); | |
5dd93a61 | 2909 | |
2f06c88a | 2910 | Decorate (Aspect, Aitem); |
2911 | Insert_Pragma (Aitem); | |
2912 | goto Continue; | |
778ebf56 | 2913 | |
4befb1a0 | 2914 | -- Refined_Depends |
2915 | ||
e2bf777d | 2916 | -- Aspect Refined_Depends is never delayed because it is |
2917 | -- equivalent to a source pragma which appears in the | |
2918 | -- declarations of the related subprogram body. To deal with | |
2919 | -- forward references, the generated pragma is stored in the | |
2920 | -- contract of the related subprogram body and later analyzed | |
2921 | -- at the end of the declarative region. For details, see | |
2922 | -- routine Analyze_Refined_Depends_In_Decl_Part. | |
4befb1a0 | 2923 | |
2924 | when Aspect_Refined_Depends => | |
422073ed | 2925 | Make_Aitem_Pragma |
2926 | (Pragma_Argument_Associations => New_List ( | |
2927 | Make_Pragma_Argument_Association (Loc, | |
2928 | Expression => Relocate_Node (Expr))), | |
2929 | Pragma_Name => Name_Refined_Depends); | |
2930 | ||
e2bf777d | 2931 | Decorate (Aspect, Aitem); |
2932 | Insert_Pragma (Aitem); | |
422073ed | 2933 | goto Continue; |
4befb1a0 | 2934 | |
2935 | -- Refined_Global | |
2936 | ||
e2bf777d | 2937 | -- Aspect Refined_Global is never delayed because it is |
2938 | -- equivalent to a source pragma which appears in the | |
2939 | -- declarations of the related subprogram body. To deal with | |
2940 | -- forward references, the generated pragma is stored in the | |
2941 | -- contract of the related subprogram body and later analyzed | |
2942 | -- at the end of the declarative region. For details, see | |
2943 | -- routine Analyze_Refined_Global_In_Decl_Part. | |
4befb1a0 | 2944 | |
2945 | when Aspect_Refined_Global => | |
28ff117f | 2946 | Make_Aitem_Pragma |
2947 | (Pragma_Argument_Associations => New_List ( | |
2948 | Make_Pragma_Argument_Association (Loc, | |
2949 | Expression => Relocate_Node (Expr))), | |
2950 | Pragma_Name => Name_Refined_Global); | |
2951 | ||
e2bf777d | 2952 | Decorate (Aspect, Aitem); |
2953 | Insert_Pragma (Aitem); | |
28ff117f | 2954 | goto Continue; |
4befb1a0 | 2955 | |
63b65b2d | 2956 | -- Refined_Post |
2957 | ||
2958 | when Aspect_Refined_Post => | |
2959 | Make_Aitem_Pragma | |
2960 | (Pragma_Argument_Associations => New_List ( | |
2961 | Make_Pragma_Argument_Association (Loc, | |
2962 | Expression => Relocate_Node (Expr))), | |
2963 | Pragma_Name => Name_Refined_Post); | |
2964 | ||
3ff5e35d | 2965 | Decorate (Aspect, Aitem); |
2966 | Insert_Pragma (Aitem); | |
2967 | goto Continue; | |
2968 | ||
9129c28f | 2969 | -- Refined_State |
2970 | ||
5655be8a | 2971 | when Aspect_Refined_State => |
9129c28f | 2972 | |
9129c28f | 2973 | -- The corresponding pragma for Refined_State is inserted in |
2974 | -- the declarations of the related package body. This action | |
2975 | -- synchronizes both the source and from-aspect versions of | |
2976 | -- the pragma. | |
2977 | ||
2978 | if Nkind (N) = N_Package_Body then | |
9129c28f | 2979 | Make_Aitem_Pragma |
2980 | (Pragma_Argument_Associations => New_List ( | |
2981 | Make_Pragma_Argument_Association (Loc, | |
2982 | Expression => Relocate_Node (Expr))), | |
2983 | Pragma_Name => Name_Refined_State); | |
b9b2d6e5 | 2984 | |
5655be8a | 2985 | Decorate (Aspect, Aitem); |
2986 | Insert_Pragma (Aitem); | |
b9b2d6e5 | 2987 | |
5655be8a | 2988 | -- Otherwise the context is illegal |
9129c28f | 2989 | |
2990 | else | |
2991 | Error_Msg_NE | |
2992 | ("aspect & must apply to a package body", Aspect, Id); | |
2993 | end if; | |
2994 | ||
2995 | goto Continue; | |
9129c28f | 2996 | |
0fd13d32 | 2997 | -- Relative_Deadline |
3cdbaa5a | 2998 | |
2999 | when Aspect_Relative_Deadline => | |
0fd13d32 | 3000 | Make_Aitem_Pragma |
3001 | (Pragma_Argument_Associations => New_List ( | |
3002 | Make_Pragma_Argument_Association (Loc, | |
3003 | Expression => Relocate_Node (Expr))), | |
3004 | Pragma_Name => Name_Relative_Deadline); | |
47a46747 | 3005 | |
3006 | -- If the aspect applies to a task, the corresponding pragma | |
3007 | -- must appear within its declarations, not after. | |
3008 | ||
3009 | if Nkind (N) = N_Task_Type_Declaration then | |
3010 | declare | |
3011 | Def : Node_Id; | |
3012 | V : List_Id; | |
3013 | ||
3014 | begin | |
3015 | if No (Task_Definition (N)) then | |
3016 | Set_Task_Definition (N, | |
3017 | Make_Task_Definition (Loc, | |
3018 | Visible_Declarations => New_List, | |
3019 | End_Label => Empty)); | |
3020 | end if; | |
3021 | ||
3022 | Def := Task_Definition (N); | |
3023 | V := Visible_Declarations (Def); | |
3024 | if not Is_Empty_List (V) then | |
3025 | Insert_Before (First (V), Aitem); | |
3026 | ||
3027 | else | |
3028 | Set_Visible_Declarations (Def, New_List (Aitem)); | |
3029 | end if; | |
3030 | ||
3031 | goto Continue; | |
3032 | end; | |
3033 | end if; | |
3034 | ||
85ee12c0 | 3035 | -- Aspect Volatile_Function is never delayed because it is |
3036 | -- equivalent to a source pragma which appears after the | |
3037 | -- related subprogram. | |
3038 | ||
3039 | when Aspect_Volatile_Function => | |
3040 | Make_Aitem_Pragma | |
3041 | (Pragma_Argument_Associations => New_List ( | |
3042 | Make_Pragma_Argument_Association (Loc, | |
3043 | Expression => Relocate_Node (Expr))), | |
3044 | Pragma_Name => Name_Volatile_Function); | |
3045 | ||
3046 | Decorate (Aspect, Aitem); | |
3047 | Insert_Pragma (Aitem); | |
3048 | goto Continue; | |
3049 | ||
956ffaf4 | 3050 | -- Case 2e: Annotate aspect |
3051 | ||
3052 | when Aspect_Annotate => | |
3053 | declare | |
3054 | Args : List_Id; | |
3055 | Pargs : List_Id; | |
3056 | Arg : Node_Id; | |
3057 | ||
3058 | begin | |
3059 | -- The argument can be a single identifier | |
3060 | ||
3061 | if Nkind (Expr) = N_Identifier then | |
3062 | ||
3063 | -- One level of parens is allowed | |
3064 | ||
3065 | if Paren_Count (Expr) > 1 then | |
3066 | Error_Msg_F ("extra parentheses ignored", Expr); | |
3067 | end if; | |
3068 | ||
3069 | Set_Paren_Count (Expr, 0); | |
3070 | ||
3071 | -- Add the single item to the list | |
3072 | ||
3073 | Args := New_List (Expr); | |
3074 | ||
3075 | -- Otherwise we must have an aggregate | |
3076 | ||
3077 | elsif Nkind (Expr) = N_Aggregate then | |
3078 | ||
3079 | -- Must be positional | |
3080 | ||
3081 | if Present (Component_Associations (Expr)) then | |
3082 | Error_Msg_F | |
3083 | ("purely positional aggregate required", Expr); | |
3084 | goto Continue; | |
3085 | end if; | |
3086 | ||
3087 | -- Must not be parenthesized | |
3088 | ||
3089 | if Paren_Count (Expr) /= 0 then | |
3090 | Error_Msg_F ("extra parentheses ignored", Expr); | |
3091 | end if; | |
3092 | ||
3093 | -- List of arguments is list of aggregate expressions | |
3094 | ||
3095 | Args := Expressions (Expr); | |
3096 | ||
3097 | -- Anything else is illegal | |
3098 | ||
3099 | else | |
3100 | Error_Msg_F ("wrong form for Annotate aspect", Expr); | |
3101 | goto Continue; | |
3102 | end if; | |
3103 | ||
3104 | -- Prepare pragma arguments | |
3105 | ||
3106 | Pargs := New_List; | |
3107 | Arg := First (Args); | |
3108 | while Present (Arg) loop | |
3109 | Append_To (Pargs, | |
3110 | Make_Pragma_Argument_Association (Sloc (Arg), | |
3111 | Expression => Relocate_Node (Arg))); | |
3112 | Next (Arg); | |
3113 | end loop; | |
3114 | ||
3115 | Append_To (Pargs, | |
3116 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3117 | Chars => Name_Entity, | |
3118 | Expression => Ent)); | |
3119 | ||
3120 | Make_Aitem_Pragma | |
3121 | (Pragma_Argument_Associations => Pargs, | |
3122 | Pragma_Name => Name_Annotate); | |
3123 | end; | |
3124 | ||
89f1e35c | 3125 | -- Case 3 : Aspects that don't correspond to pragma/attribute |
3126 | -- definition clause. | |
7b9b2f05 | 3127 | |
89f1e35c | 3128 | -- Case 3a: The aspects listed below don't correspond to |
3129 | -- pragmas/attributes but do require delayed analysis. | |
7f694ca2 | 3130 | |
51fa2a45 | 3131 | -- Default_Value can only apply to a scalar type |
3132 | ||
3133 | when Aspect_Default_Value => | |
3134 | if not Is_Scalar_Type (E) then | |
3135 | Error_Msg_N | |
1089ff19 | 3136 | ("aspect Default_Value must apply to a scalar type", N); |
51fa2a45 | 3137 | end if; |
3138 | ||
3139 | Aitem := Empty; | |
3140 | ||
3141 | -- Default_Component_Value can only apply to an array type | |
3142 | -- with scalar components. | |
3143 | ||
3144 | when Aspect_Default_Component_Value => | |
3145 | if not (Is_Array_Type (E) | |
3f4c9ffc | 3146 | and then Is_Scalar_Type (Component_Type (E))) |
51fa2a45 | 3147 | then |
ee2b7923 | 3148 | Error_Msg_N |
3149 | ("aspect Default_Component_Value can only apply to an " | |
3150 | & "array of scalar components", N); | |
51fa2a45 | 3151 | end if; |
0fd13d32 | 3152 | |
89f1e35c | 3153 | Aitem := Empty; |
7f694ca2 | 3154 | |
89f1e35c | 3155 | -- Case 3b: The aspects listed below don't correspond to |
3156 | -- pragmas/attributes and don't need delayed analysis. | |
95bc75fa | 3157 | |
0fd13d32 | 3158 | -- Implicit_Dereference |
3159 | ||
89f1e35c | 3160 | -- For Implicit_Dereference, External_Name and Link_Name, only |
3161 | -- the legality checks are done during the analysis, thus no | |
3162 | -- delay is required. | |
a8e38e1d | 3163 | |
89f1e35c | 3164 | when Aspect_Implicit_Dereference => |
3165 | Analyze_Aspect_Implicit_Dereference; | |
3166 | goto Continue; | |
7f694ca2 | 3167 | |
0fd13d32 | 3168 | -- Dimension |
3169 | ||
89f1e35c | 3170 | when Aspect_Dimension => |
3171 | Analyze_Aspect_Dimension (N, Id, Expr); | |
3172 | goto Continue; | |
cb4c311d | 3173 | |
0fd13d32 | 3174 | -- Dimension_System |
3175 | ||
89f1e35c | 3176 | when Aspect_Dimension_System => |
3177 | Analyze_Aspect_Dimension_System (N, Id, Expr); | |
3178 | goto Continue; | |
7f694ca2 | 3179 | |
ceec4f7c | 3180 | -- Case 4: Aspects requiring special handling |
51ea9c94 | 3181 | |
e66f4e2a | 3182 | -- Pre/Post/Test_Case/Contract_Cases whose corresponding |
3183 | -- pragmas take care of the delay. | |
7f694ca2 | 3184 | |
0fd13d32 | 3185 | -- Pre/Post |
3186 | ||
1e3c4ae6 | 3187 | -- Aspects Pre/Post generate Precondition/Postcondition pragmas |
3188 | -- with a first argument that is the expression, and a second | |
3189 | -- argument that is an informative message if the test fails. | |
3190 | -- This is inserted right after the declaration, to get the | |
5b5df4a9 | 3191 | -- required pragma placement. The processing for the pragmas |
3192 | -- takes care of the required delay. | |
ae888dbd | 3193 | |
5ddd846b | 3194 | when Pre_Post_Aspects => Pre_Post : declare |
1e3c4ae6 | 3195 | Pname : Name_Id; |
ae888dbd | 3196 | |
1e3c4ae6 | 3197 | begin |
77ae6789 | 3198 | if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then |
1e3c4ae6 | 3199 | Pname := Name_Precondition; |
3200 | else | |
3201 | Pname := Name_Postcondition; | |
3202 | end if; | |
d74fc39a | 3203 | |
26062729 | 3204 | -- Check that the class-wide predicate cannot be applied to |
3205 | -- an operation of a synchronized type that is not a tagged | |
3206 | -- type. Other legality checks are performed when analyzing | |
3207 | -- the contract of the operation. | |
3208 | ||
3209 | if Class_Present (Aspect) | |
3210 | and then Is_Concurrent_Type (Current_Scope) | |
3211 | and then not Is_Tagged_Type (Current_Scope) | |
3212 | and then Ekind_In (E, E_Entry, E_Function, E_Procedure) | |
3213 | then | |
3214 | Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Aspect); | |
3215 | Error_Msg_N | |
3216 | ("aspect % can only be specified for a primitive " | |
3217 | & "operation of a tagged type", Aspect); | |
3218 | ||
3219 | goto Continue; | |
3220 | end if; | |
3221 | ||
1e3c4ae6 | 3222 | -- If the expressions is of the form A and then B, then |
3223 | -- we generate separate Pre/Post aspects for the separate | |
3224 | -- clauses. Since we allow multiple pragmas, there is no | |
3225 | -- problem in allowing multiple Pre/Post aspects internally. | |
a273015d | 3226 | -- These should be treated in reverse order (B first and |
3227 | -- A second) since they are later inserted just after N in | |
3228 | -- the order they are treated. This way, the pragma for A | |
3229 | -- ends up preceding the pragma for B, which may have an | |
3230 | -- importance for the error raised (either constraint error | |
3231 | -- or precondition error). | |
1e3c4ae6 | 3232 | |
39e1f22f | 3233 | -- We do not do this for Pre'Class, since we have to put |
51fa2a45 | 3234 | -- these conditions together in a complex OR expression. |
ae888dbd | 3235 | |
4282d342 | 3236 | -- We do not do this in ASIS mode, as ASIS relies on the |
3237 | -- original node representing the complete expression, when | |
3238 | -- retrieving it through the source aspect table. | |
3239 | ||
3240 | if not ASIS_Mode | |
3241 | and then (Pname = Name_Postcondition | |
3242 | or else not Class_Present (Aspect)) | |
39e1f22f | 3243 | then |
3244 | while Nkind (Expr) = N_And_Then loop | |
3245 | Insert_After (Aspect, | |
a273015d | 3246 | Make_Aspect_Specification (Sloc (Left_Opnd (Expr)), |
39e1f22f | 3247 | Identifier => Identifier (Aspect), |
a273015d | 3248 | Expression => Relocate_Node (Left_Opnd (Expr)), |
39e1f22f | 3249 | Class_Present => Class_Present (Aspect), |
3250 | Split_PPC => True)); | |
a273015d | 3251 | Rewrite (Expr, Relocate_Node (Right_Opnd (Expr))); |
39e1f22f | 3252 | Eloc := Sloc (Expr); |
3253 | end loop; | |
3254 | end if; | |
ae888dbd | 3255 | |
48d6f069 | 3256 | -- Build the precondition/postcondition pragma |
3257 | ||
51fa2a45 | 3258 | -- Add note about why we do NOT need Copy_Tree here??? |
d74fc39a | 3259 | |
0fd13d32 | 3260 | Make_Aitem_Pragma |
3261 | (Pragma_Argument_Associations => New_List ( | |
3262 | Make_Pragma_Argument_Association (Eloc, | |
3263 | Chars => Name_Check, | |
a19e1763 | 3264 | Expression => Relocate_Node (Expr))), |
0fd13d32 | 3265 | Pragma_Name => Pname); |
39e1f22f | 3266 | |
3267 | -- Add message unless exception messages are suppressed | |
3268 | ||
3269 | if not Opt.Exception_Locations_Suppressed then | |
3270 | Append_To (Pragma_Argument_Associations (Aitem), | |
3271 | Make_Pragma_Argument_Association (Eloc, | |
ed695684 | 3272 | Chars => Name_Message, |
39e1f22f | 3273 | Expression => |
3274 | Make_String_Literal (Eloc, | |
3275 | Strval => "failed " | |
3276 | & Get_Name_String (Pname) | |
3277 | & " from " | |
3278 | & Build_Location_String (Eloc)))); | |
3279 | end if; | |
d74fc39a | 3280 | |
7d20685d | 3281 | Set_Is_Delayed_Aspect (Aspect); |
d74fc39a | 3282 | |
1e3c4ae6 | 3283 | -- For Pre/Post cases, insert immediately after the entity |
3284 | -- declaration, since that is the required pragma placement. | |
3285 | -- Note that for these aspects, we do not have to worry | |
3286 | -- about delay issues, since the pragmas themselves deal | |
3287 | -- with delay of visibility for the expression analysis. | |
3288 | ||
e2bf777d | 3289 | Insert_Pragma (Aitem); |
299b347e | 3290 | |
1e3c4ae6 | 3291 | goto Continue; |
5ddd846b | 3292 | end Pre_Post; |
ae888dbd | 3293 | |
0fd13d32 | 3294 | -- Test_Case |
3295 | ||
e66f4e2a | 3296 | when Aspect_Test_Case => Test_Case : declare |
3297 | Args : List_Id; | |
3298 | Comp_Expr : Node_Id; | |
3299 | Comp_Assn : Node_Id; | |
3300 | New_Expr : Node_Id; | |
57cd943b | 3301 | |
e66f4e2a | 3302 | begin |
3303 | Args := New_List; | |
b0bc40fd | 3304 | |
e66f4e2a | 3305 | if Nkind (Parent (N)) = N_Compilation_Unit then |
3306 | Error_Msg_Name_1 := Nam; | |
3307 | Error_Msg_N ("incorrect placement of aspect `%`", E); | |
3308 | goto Continue; | |
3309 | end if; | |
6c545057 | 3310 | |
e66f4e2a | 3311 | if Nkind (Expr) /= N_Aggregate then |
3312 | Error_Msg_Name_1 := Nam; | |
3313 | Error_Msg_NE | |
3314 | ("wrong syntax for aspect `%` for &", Id, E); | |
3315 | goto Continue; | |
3316 | end if; | |
6c545057 | 3317 | |
e66f4e2a | 3318 | -- Make pragma expressions refer to the original aspect |
51fa2a45 | 3319 | -- expressions through the Original_Node link. This is used |
3320 | -- in semantic analysis for ASIS mode, so that the original | |
3321 | -- expression also gets analyzed. | |
e66f4e2a | 3322 | |
3323 | Comp_Expr := First (Expressions (Expr)); | |
3324 | while Present (Comp_Expr) loop | |
3325 | New_Expr := Relocate_Node (Comp_Expr); | |
e66f4e2a | 3326 | Append_To (Args, |
3327 | Make_Pragma_Argument_Association (Sloc (Comp_Expr), | |
3328 | Expression => New_Expr)); | |
3329 | Next (Comp_Expr); | |
3330 | end loop; | |
3331 | ||
3332 | Comp_Assn := First (Component_Associations (Expr)); | |
3333 | while Present (Comp_Assn) loop | |
3334 | if List_Length (Choices (Comp_Assn)) /= 1 | |
3335 | or else | |
3336 | Nkind (First (Choices (Comp_Assn))) /= N_Identifier | |
3337 | then | |
fad014fe | 3338 | Error_Msg_Name_1 := Nam; |
6c545057 | 3339 | Error_Msg_NE |
fad014fe | 3340 | ("wrong syntax for aspect `%` for &", Id, E); |
6c545057 | 3341 | goto Continue; |
3342 | end if; | |
3343 | ||
e66f4e2a | 3344 | Append_To (Args, |
3345 | Make_Pragma_Argument_Association (Sloc (Comp_Assn), | |
ed695684 | 3346 | Chars => Chars (First (Choices (Comp_Assn))), |
3347 | Expression => | |
3348 | Relocate_Node (Expression (Comp_Assn)))); | |
e66f4e2a | 3349 | Next (Comp_Assn); |
3350 | end loop; | |
6c545057 | 3351 | |
e66f4e2a | 3352 | -- Build the test-case pragma |
6c545057 | 3353 | |
0fd13d32 | 3354 | Make_Aitem_Pragma |
3355 | (Pragma_Argument_Associations => Args, | |
3356 | Pragma_Name => Nam); | |
e66f4e2a | 3357 | end Test_Case; |
85696508 | 3358 | |
0fd13d32 | 3359 | -- Contract_Cases |
3360 | ||
5ddd846b | 3361 | when Aspect_Contract_Cases => |
0fd13d32 | 3362 | Make_Aitem_Pragma |
3363 | (Pragma_Argument_Associations => New_List ( | |
3364 | Make_Pragma_Argument_Association (Loc, | |
3365 | Expression => Relocate_Node (Expr))), | |
3366 | Pragma_Name => Nam); | |
3a128918 | 3367 | |
e2bf777d | 3368 | Decorate (Aspect, Aitem); |
3369 | Insert_Pragma (Aitem); | |
5ddd846b | 3370 | goto Continue; |
3a128918 | 3371 | |
89f1e35c | 3372 | -- Case 5: Special handling for aspects with an optional |
3373 | -- boolean argument. | |
85696508 | 3374 | |
6c5793cd | 3375 | -- In the delayed case, the corresponding pragma cannot be |
0fd13d32 | 3376 | -- generated yet because the evaluation of the boolean needs |
3377 | -- to be delayed till the freeze point. | |
3378 | ||
89f1e35c | 3379 | when Boolean_Aspects | |
3380 | Library_Unit_Aspects => | |
a5a64273 | 3381 | |
89f1e35c | 3382 | Set_Is_Boolean_Aspect (Aspect); |
a5a64273 | 3383 | |
89f1e35c | 3384 | -- Lock_Free aspect only apply to protected objects |
e1cedbae | 3385 | |
89f1e35c | 3386 | if A_Id = Aspect_Lock_Free then |
3387 | if Ekind (E) /= E_Protected_Type then | |
99a2d5bd | 3388 | Error_Msg_Name_1 := Nam; |
a5a64273 | 3389 | Error_Msg_N |
89f1e35c | 3390 | ("aspect % only applies to a protected object", |
3391 | Aspect); | |
3392 | ||
3393 | else | |
3394 | -- Set the Uses_Lock_Free flag to True if there is no | |
37c6e44c | 3395 | -- expression or if the expression is True. The |
89f1e35c | 3396 | -- evaluation of this aspect should be delayed to the |
37c6e44c | 3397 | -- freeze point (why???) |
89f1e35c | 3398 | |
e81df51c | 3399 | if No (Expr) |
3400 | or else Is_True (Static_Boolean (Expr)) | |
89f1e35c | 3401 | then |
3402 | Set_Uses_Lock_Free (E); | |
3403 | end if; | |
caf125ce | 3404 | |
3405 | Record_Rep_Item (E, Aspect); | |
a5a64273 | 3406 | end if; |
e1cedbae | 3407 | |
89f1e35c | 3408 | goto Continue; |
ae888dbd | 3409 | |
ee2b7923 | 3410 | elsif A_Id = Aspect_Export or else A_Id = Aspect_Import then |
3411 | Analyze_Aspect_Export_Import; | |
6c5793cd | 3412 | |
3413 | -- Disable_Controlled | |
3414 | ||
3415 | elsif A_Id = Aspect_Disable_Controlled then | |
3416 | if Ekind (E) /= E_Record_Type | |
3417 | or else not Is_Controlled (E) | |
3418 | then | |
3419 | Error_Msg_N | |
3420 | ("aspect % requires controlled record type", Aspect); | |
3421 | goto Continue; | |
3422 | end if; | |
3423 | ||
3f716509 | 3424 | -- If we're in a generic template, we don't want to try |
3425 | -- to disable controlled types, because typical usage is | |
3426 | -- "Disable_Controlled => not <some_check>'Enabled", and | |
3427 | -- the value of Enabled is not known until we see a | |
7e2d3667 | 3428 | -- particular instance. In such a context, we just need |
3429 | -- to preanalyze the expression for legality. | |
3f716509 | 3430 | |
3431 | if Expander_Active then | |
aae9bc79 | 3432 | Analyze_And_Resolve (Expr, Standard_Boolean); |
3433 | ||
3f716509 | 3434 | if not Present (Expr) |
3435 | or else Is_True (Static_Boolean (Expr)) | |
3436 | then | |
3437 | Set_Disable_Controlled (E); | |
3438 | end if; | |
7e2d3667 | 3439 | |
3440 | elsif Serious_Errors_Detected = 0 then | |
3441 | Preanalyze_And_Resolve (Expr, Standard_Boolean); | |
6c5793cd | 3442 | end if; |
3443 | ||
89f1e35c | 3444 | goto Continue; |
3445 | end if; | |
d74fc39a | 3446 | |
37c6e44c | 3447 | -- Library unit aspects require special handling in the case |
3448 | -- of a package declaration, the pragma needs to be inserted | |
3449 | -- in the list of declarations for the associated package. | |
3450 | -- There is no issue of visibility delay for these aspects. | |
d64221a7 | 3451 | |
89f1e35c | 3452 | if A_Id in Library_Unit_Aspects |
178fec9b | 3453 | and then |
3454 | Nkind_In (N, N_Package_Declaration, | |
3455 | N_Generic_Package_Declaration) | |
89f1e35c | 3456 | and then Nkind (Parent (N)) /= N_Compilation_Unit |
3ad60f63 | 3457 | |
3458 | -- Aspect is legal on a local instantiation of a library- | |
3459 | -- level generic unit. | |
3460 | ||
b94a633e | 3461 | and then not Is_Generic_Instance (Defining_Entity (N)) |
89f1e35c | 3462 | then |
3463 | Error_Msg_N | |
dd4c44af | 3464 | ("incorrect context for library unit aspect&", Id); |
89f1e35c | 3465 | goto Continue; |
3466 | end if; | |
cce84b09 | 3467 | |
51fa2a45 | 3468 | -- Cases where we do not delay, includes all cases where the |
3469 | -- expression is missing other than the above cases. | |
d74fc39a | 3470 | |
85ee12c0 | 3471 | if not Delay_Required or else No (Expr) then |
ee2b7923 | 3472 | |
3473 | -- Exclude aspects Export and Import because their pragma | |
3474 | -- syntax does not map directly to a Boolean aspect. | |
3475 | ||
3476 | if A_Id /= Aspect_Export | |
3477 | and then A_Id /= Aspect_Import | |
3478 | then | |
3479 | Make_Aitem_Pragma | |
3480 | (Pragma_Argument_Associations => New_List ( | |
3481 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3482 | Expression => Ent)), | |
3483 | Pragma_Name => Chars (Id)); | |
3484 | end if; | |
3485 | ||
89f1e35c | 3486 | Delay_Required := False; |
ddf1337b | 3487 | |
89f1e35c | 3488 | -- In general cases, the corresponding pragma/attribute |
3489 | -- definition clause will be inserted later at the freezing | |
294709fa | 3490 | -- point, and we do not need to build it now. |
ddf1337b | 3491 | |
89f1e35c | 3492 | else |
3493 | Aitem := Empty; | |
3494 | end if; | |
ceec4f7c | 3495 | |
3496 | -- Storage_Size | |
3497 | ||
3498 | -- This is special because for access types we need to generate | |
3499 | -- an attribute definition clause. This also works for single | |
3500 | -- task declarations, but it does not work for task type | |
3501 | -- declarations, because we have the case where the expression | |
3502 | -- references a discriminant of the task type. That can't use | |
3503 | -- an attribute definition clause because we would not have | |
3504 | -- visibility on the discriminant. For that case we must | |
3505 | -- generate a pragma in the task definition. | |
3506 | ||
3507 | when Aspect_Storage_Size => | |
3508 | ||
3509 | -- Task type case | |
3510 | ||
3511 | if Ekind (E) = E_Task_Type then | |
3512 | declare | |
3513 | Decl : constant Node_Id := Declaration_Node (E); | |
3514 | ||
3515 | begin | |
3516 | pragma Assert (Nkind (Decl) = N_Task_Type_Declaration); | |
3517 | ||
3518 | -- If no task definition, create one | |
3519 | ||
3520 | if No (Task_Definition (Decl)) then | |
3521 | Set_Task_Definition (Decl, | |
3522 | Make_Task_Definition (Loc, | |
3523 | Visible_Declarations => Empty_List, | |
3524 | End_Label => Empty)); | |
3525 | end if; | |
3526 | ||
51fa2a45 | 3527 | -- Create a pragma and put it at the start of the task |
3528 | -- definition for the task type declaration. | |
ceec4f7c | 3529 | |
3530 | Make_Aitem_Pragma | |
3531 | (Pragma_Argument_Associations => New_List ( | |
3532 | Make_Pragma_Argument_Association (Loc, | |
3533 | Expression => Relocate_Node (Expr))), | |
3534 | Pragma_Name => Name_Storage_Size); | |
3535 | ||
3536 | Prepend | |
3537 | (Aitem, | |
3538 | Visible_Declarations (Task_Definition (Decl))); | |
3539 | goto Continue; | |
3540 | end; | |
3541 | ||
3542 | -- All other cases, generate attribute definition | |
3543 | ||
3544 | else | |
3545 | Aitem := | |
3546 | Make_Attribute_Definition_Clause (Loc, | |
3547 | Name => Ent, | |
3548 | Chars => Chars (Id), | |
3549 | Expression => Relocate_Node (Expr)); | |
3550 | end if; | |
89f1e35c | 3551 | end case; |
ddf1337b | 3552 | |
89f1e35c | 3553 | -- Attach the corresponding pragma/attribute definition clause to |
3554 | -- the aspect specification node. | |
d74fc39a | 3555 | |
89f1e35c | 3556 | if Present (Aitem) then |
e2bf777d | 3557 | Set_From_Aspect_Specification (Aitem); |
89f1e35c | 3558 | end if; |
53c179ea | 3559 | |
89f1e35c | 3560 | -- In the context of a compilation unit, we directly put the |
0fd13d32 | 3561 | -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux |
3562 | -- node (no delay is required here) except for aspects on a | |
51fa2a45 | 3563 | -- subprogram body (see below) and a generic package, for which we |
3564 | -- need to introduce the pragma before building the generic copy | |
3565 | -- (see sem_ch12), and for package instantiations, where the | |
3566 | -- library unit pragmas are better handled early. | |
ddf1337b | 3567 | |
9129c28f | 3568 | if Nkind (Parent (N)) = N_Compilation_Unit |
89f1e35c | 3569 | and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect)) |
3570 | then | |
3571 | declare | |
3572 | Aux : constant Node_Id := Aux_Decls_Node (Parent (N)); | |
7f694ca2 | 3573 | |
89f1e35c | 3574 | begin |
3575 | pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux); | |
7f694ca2 | 3576 | |
89f1e35c | 3577 | -- For a Boolean aspect, create the corresponding pragma if |
3578 | -- no expression or if the value is True. | |
7f694ca2 | 3579 | |
b9e61b2a | 3580 | if Is_Boolean_Aspect (Aspect) and then No (Aitem) then |
89f1e35c | 3581 | if Is_True (Static_Boolean (Expr)) then |
0fd13d32 | 3582 | Make_Aitem_Pragma |
3583 | (Pragma_Argument_Associations => New_List ( | |
3584 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3585 | Expression => Ent)), | |
3586 | Pragma_Name => Chars (Id)); | |
7f694ca2 | 3587 | |
89f1e35c | 3588 | Set_From_Aspect_Specification (Aitem, True); |
3589 | Set_Corresponding_Aspect (Aitem, Aspect); | |
3590 | ||
3591 | else | |
3592 | goto Continue; | |
3593 | end if; | |
3594 | end if; | |
7f694ca2 | 3595 | |
d6814978 | 3596 | -- If the aspect is on a subprogram body (relevant aspect |
3597 | -- is Inline), add the pragma in front of the declarations. | |
3a72f9c3 | 3598 | |
3599 | if Nkind (N) = N_Subprogram_Body then | |
3600 | if No (Declarations (N)) then | |
3601 | Set_Declarations (N, New_List); | |
3602 | end if; | |
3603 | ||
3604 | Prepend (Aitem, Declarations (N)); | |
3605 | ||
178fec9b | 3606 | elsif Nkind (N) = N_Generic_Package_Declaration then |
3607 | if No (Visible_Declarations (Specification (N))) then | |
3608 | Set_Visible_Declarations (Specification (N), New_List); | |
3609 | end if; | |
3610 | ||
3611 | Prepend (Aitem, | |
3612 | Visible_Declarations (Specification (N))); | |
3613 | ||
c39cce40 | 3614 | elsif Nkind (N) = N_Package_Instantiation then |
df8b0dae | 3615 | declare |
3616 | Spec : constant Node_Id := | |
3617 | Specification (Instance_Spec (N)); | |
3618 | begin | |
3619 | if No (Visible_Declarations (Spec)) then | |
3620 | Set_Visible_Declarations (Spec, New_List); | |
3621 | end if; | |
3622 | ||
3623 | Prepend (Aitem, Visible_Declarations (Spec)); | |
3624 | end; | |
3625 | ||
3a72f9c3 | 3626 | else |
3627 | if No (Pragmas_After (Aux)) then | |
d4596fbe | 3628 | Set_Pragmas_After (Aux, New_List); |
3a72f9c3 | 3629 | end if; |
3630 | ||
3631 | Append (Aitem, Pragmas_After (Aux)); | |
89f1e35c | 3632 | end if; |
7f694ca2 | 3633 | |
89f1e35c | 3634 | goto Continue; |
3635 | end; | |
3636 | end if; | |
7f694ca2 | 3637 | |
89f1e35c | 3638 | -- The evaluation of the aspect is delayed to the freezing point. |
3639 | -- The pragma or attribute clause if there is one is then attached | |
37c6e44c | 3640 | -- to the aspect specification which is put in the rep item list. |
1a814552 | 3641 | |
89f1e35c | 3642 | if Delay_Required then |
3643 | if Present (Aitem) then | |
3644 | Set_Is_Delayed_Aspect (Aitem); | |
3645 | Set_Aspect_Rep_Item (Aspect, Aitem); | |
3646 | Set_Parent (Aitem, Aspect); | |
3647 | end if; | |
1a814552 | 3648 | |
89f1e35c | 3649 | Set_Is_Delayed_Aspect (Aspect); |
9f36e3fb | 3650 | |
cba2ae82 | 3651 | -- In the case of Default_Value, link the aspect to base type |
3652 | -- as well, even though it appears on a first subtype. This is | |
3653 | -- mandated by the semantics of the aspect. Do not establish | |
3654 | -- the link when processing the base type itself as this leads | |
3655 | -- to a rep item circularity. Verify that we are dealing with | |
3656 | -- a scalar type to prevent cascaded errors. | |
3657 | ||
3658 | if A_Id = Aspect_Default_Value | |
3659 | and then Is_Scalar_Type (E) | |
3660 | and then Base_Type (E) /= E | |
3661 | then | |
9f36e3fb | 3662 | Set_Has_Delayed_Aspects (Base_Type (E)); |
3663 | Record_Rep_Item (Base_Type (E), Aspect); | |
3664 | end if; | |
3665 | ||
89f1e35c | 3666 | Set_Has_Delayed_Aspects (E); |
3667 | Record_Rep_Item (E, Aspect); | |
ddf1337b | 3668 | |
b855559d | 3669 | -- When delay is not required and the context is a package or a |
3670 | -- subprogram body, insert the pragma in the body declarations. | |
f55ce169 | 3671 | |
b855559d | 3672 | elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then |
f55ce169 | 3673 | if No (Declarations (N)) then |
3674 | Set_Declarations (N, New_List); | |
3675 | end if; | |
3676 | ||
3677 | -- The pragma is added before source declarations | |
3678 | ||
3679 | Prepend_To (Declarations (N), Aitem); | |
3680 | ||
89f1e35c | 3681 | -- When delay is not required and the context is not a compilation |
3682 | -- unit, we simply insert the pragma/attribute definition clause | |
3683 | -- in sequence. | |
ddf1337b | 3684 | |
ee2b7923 | 3685 | elsif Present (Aitem) then |
89f1e35c | 3686 | Insert_After (Ins_Node, Aitem); |
3687 | Ins_Node := Aitem; | |
d74fc39a | 3688 | end if; |
0fd13d32 | 3689 | end Analyze_One_Aspect; |
ae888dbd | 3690 | |
d64221a7 | 3691 | <<Continue>> |
3692 | Next (Aspect); | |
21ea3a4f | 3693 | end loop Aspect_Loop; |
89f1e35c | 3694 | |
3695 | if Has_Delayed_Aspects (E) then | |
3696 | Ensure_Freeze_Node (E); | |
3697 | end if; | |
21ea3a4f | 3698 | end Analyze_Aspect_Specifications; |
ae888dbd | 3699 | |
eb8aeefc | 3700 | --------------------------------------------------- |
3701 | -- Analyze_Aspect_Specifications_On_Body_Or_Stub -- | |
3702 | --------------------------------------------------- | |
3703 | ||
3704 | procedure Analyze_Aspect_Specifications_On_Body_Or_Stub (N : Node_Id) is | |
3705 | Body_Id : constant Entity_Id := Defining_Entity (N); | |
3706 | ||
3707 | procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id); | |
c02dccca | 3708 | -- Body [stub] N has aspects, but they are not properly placed. Emit an |
3709 | -- error message depending on the aspects involved. Spec_Id denotes the | |
3710 | -- entity of the corresponding spec. | |
eb8aeefc | 3711 | |
3712 | -------------------------------- | |
3713 | -- Diagnose_Misplaced_Aspects -- | |
3714 | -------------------------------- | |
3715 | ||
3716 | procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is | |
3717 | procedure Misplaced_Aspect_Error | |
3718 | (Asp : Node_Id; | |
3719 | Ref_Nam : Name_Id); | |
3720 | -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is | |
3721 | -- the name of the refined version of the aspect. | |
3722 | ||
3723 | ---------------------------- | |
3724 | -- Misplaced_Aspect_Error -- | |
3725 | ---------------------------- | |
3726 | ||
3727 | procedure Misplaced_Aspect_Error | |
3728 | (Asp : Node_Id; | |
3729 | Ref_Nam : Name_Id) | |
3730 | is | |
3731 | Asp_Nam : constant Name_Id := Chars (Identifier (Asp)); | |
3732 | Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam); | |
3733 | ||
3734 | begin | |
3735 | -- The corresponding spec already contains the aspect in question | |
3736 | -- and the one appearing on the body must be the refined form: | |
3737 | ||
3738 | -- procedure P with Global ...; | |
3739 | -- procedure P with Global ... is ... end P; | |
3740 | -- ^ | |
3741 | -- Refined_Global | |
3742 | ||
3743 | if Has_Aspect (Spec_Id, Asp_Id) then | |
3744 | Error_Msg_Name_1 := Asp_Nam; | |
3745 | ||
3746 | -- Subunits cannot carry aspects that apply to a subprogram | |
3747 | -- declaration. | |
3748 | ||
3749 | if Nkind (Parent (N)) = N_Subunit then | |
3750 | Error_Msg_N ("aspect % cannot apply to a subunit", Asp); | |
3751 | ||
3752 | -- Otherwise suggest the refined form | |
3753 | ||
3754 | else | |
3755 | Error_Msg_Name_2 := Ref_Nam; | |
3756 | Error_Msg_N ("aspect % should be %", Asp); | |
3757 | end if; | |
3758 | ||
3759 | -- Otherwise the aspect must appear on the spec, not on the body | |
3760 | ||
3761 | -- procedure P; | |
3762 | -- procedure P with Global ... is ... end P; | |
3763 | ||
3764 | else | |
3765 | Error_Msg_N | |
c02dccca | 3766 | ("aspect specification must appear on initial declaration", |
eb8aeefc | 3767 | Asp); |
3768 | end if; | |
3769 | end Misplaced_Aspect_Error; | |
3770 | ||
3771 | -- Local variables | |
3772 | ||
3773 | Asp : Node_Id; | |
3774 | Asp_Nam : Name_Id; | |
3775 | ||
3776 | -- Start of processing for Diagnose_Misplaced_Aspects | |
3777 | ||
3778 | begin | |
3779 | -- Iterate over the aspect specifications and emit specific errors | |
3780 | -- where applicable. | |
3781 | ||
3782 | Asp := First (Aspect_Specifications (N)); | |
3783 | while Present (Asp) loop | |
3784 | Asp_Nam := Chars (Identifier (Asp)); | |
3785 | ||
3786 | -- Do not emit errors on aspects that can appear on a subprogram | |
3787 | -- body. This scenario occurs when the aspect specification list | |
3788 | -- contains both misplaced and properly placed aspects. | |
3789 | ||
3790 | if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then | |
3791 | null; | |
3792 | ||
3793 | -- Special diagnostics for SPARK aspects | |
3794 | ||
3795 | elsif Asp_Nam = Name_Depends then | |
3796 | Misplaced_Aspect_Error (Asp, Name_Refined_Depends); | |
3797 | ||
3798 | elsif Asp_Nam = Name_Global then | |
3799 | Misplaced_Aspect_Error (Asp, Name_Refined_Global); | |
3800 | ||
3801 | elsif Asp_Nam = Name_Post then | |
3802 | Misplaced_Aspect_Error (Asp, Name_Refined_Post); | |
3803 | ||
3804 | -- Otherwise a language-defined aspect is misplaced | |
3805 | ||
3806 | else | |
3807 | Error_Msg_N | |
c02dccca | 3808 | ("aspect specification must appear on initial declaration", |
eb8aeefc | 3809 | Asp); |
3810 | end if; | |
3811 | ||
3812 | Next (Asp); | |
3813 | end loop; | |
3814 | end Diagnose_Misplaced_Aspects; | |
3815 | ||
3816 | -- Local variables | |
3817 | ||
c02dccca | 3818 | Spec_Id : constant Entity_Id := Unique_Defining_Entity (N); |
eb8aeefc | 3819 | |
3820 | -- Start of processing for Analyze_Aspects_On_Body_Or_Stub | |
3821 | ||
3822 | begin | |
eb8aeefc | 3823 | -- Language-defined aspects cannot be associated with a subprogram body |
3824 | -- [stub] if the subprogram has a spec. Certain implementation defined | |
3825 | -- aspects are allowed to break this rule (for all applicable cases, see | |
3826 | -- table Aspects.Aspect_On_Body_Or_Stub_OK). | |
3827 | ||
c02dccca | 3828 | if Spec_Id /= Body_Id and then not Aspects_On_Body_Or_Stub_OK (N) then |
eb8aeefc | 3829 | Diagnose_Misplaced_Aspects (Spec_Id); |
3830 | else | |
3831 | Analyze_Aspect_Specifications (N, Body_Id); | |
3832 | end if; | |
3833 | end Analyze_Aspect_Specifications_On_Body_Or_Stub; | |
3834 | ||
d6f39728 | 3835 | ----------------------- |
3836 | -- Analyze_At_Clause -- | |
3837 | ----------------------- | |
3838 | ||
3839 | -- An at clause is replaced by the corresponding Address attribute | |
3840 | -- definition clause that is the preferred approach in Ada 95. | |
3841 | ||
3842 | procedure Analyze_At_Clause (N : Node_Id) is | |
177675a7 | 3843 | CS : constant Boolean := Comes_From_Source (N); |
3844 | ||
d6f39728 | 3845 | begin |
177675a7 | 3846 | -- This is an obsolescent feature |
3847 | ||
e0521a36 | 3848 | Check_Restriction (No_Obsolescent_Features, N); |
3849 | ||
9dfe12ae | 3850 | if Warn_On_Obsolescent_Feature then |
3851 | Error_Msg_N | |
b174444e | 3852 | ("?j?at clause is an obsolescent feature (RM J.7(2))", N); |
9dfe12ae | 3853 | Error_Msg_N |
b174444e | 3854 | ("\?j?use address attribute definition clause instead", N); |
9dfe12ae | 3855 | end if; |
3856 | ||
177675a7 | 3857 | -- Rewrite as address clause |
3858 | ||
d6f39728 | 3859 | Rewrite (N, |
3860 | Make_Attribute_Definition_Clause (Sloc (N), | |
935e86e0 | 3861 | Name => Identifier (N), |
3862 | Chars => Name_Address, | |
d6f39728 | 3863 | Expression => Expression (N))); |
177675a7 | 3864 | |
2beb22b1 | 3865 | -- We preserve Comes_From_Source, since logically the clause still comes |
3866 | -- from the source program even though it is changed in form. | |
177675a7 | 3867 | |
3868 | Set_Comes_From_Source (N, CS); | |
3869 | ||
3870 | -- Analyze rewritten clause | |
3871 | ||
d6f39728 | 3872 | Analyze_Attribute_Definition_Clause (N); |
3873 | end Analyze_At_Clause; | |
3874 | ||
3875 | ----------------------------------------- | |
3876 | -- Analyze_Attribute_Definition_Clause -- | |
3877 | ----------------------------------------- | |
3878 | ||
3879 | procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is | |
3880 | Loc : constant Source_Ptr := Sloc (N); | |
3881 | Nam : constant Node_Id := Name (N); | |
3882 | Attr : constant Name_Id := Chars (N); | |
3883 | Expr : constant Node_Id := Expression (N); | |
3884 | Id : constant Attribute_Id := Get_Attribute_Id (Attr); | |
d64221a7 | 3885 | |
3886 | Ent : Entity_Id; | |
3887 | -- The entity of Nam after it is analyzed. In the case of an incomplete | |
3888 | -- type, this is the underlying type. | |
3889 | ||
d6f39728 | 3890 | U_Ent : Entity_Id; |
d64221a7 | 3891 | -- The underlying entity to which the attribute applies. Generally this |
3892 | -- is the Underlying_Type of Ent, except in the case where the clause | |
69069c76 | 3893 | -- applies to the full view of an incomplete or private type, in which |
3894 | -- case U_Ent is just a copy of Ent. | |
d6f39728 | 3895 | |
3896 | FOnly : Boolean := False; | |
3897 | -- Reset to True for subtype specific attribute (Alignment, Size) | |
51fa2a45 | 3898 | -- and for stream attributes, i.e. those cases where in the call to |
3899 | -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules | |
3900 | -- are checked. Note that the case of stream attributes is not clear | |
3901 | -- from the RM, but see AI95-00137. Also, the RM seems to disallow | |
3902 | -- Storage_Size for derived task types, but that is also clearly | |
3903 | -- unintentional. | |
d6f39728 | 3904 | |
9f373bb8 | 3905 | procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type); |
3906 | -- Common processing for 'Read, 'Write, 'Input and 'Output attribute | |
3907 | -- definition clauses. | |
3908 | ||
ae888dbd | 3909 | function Duplicate_Clause return Boolean; |
3910 | -- This routine checks if the aspect for U_Ent being given by attribute | |
3911 | -- definition clause N is for an aspect that has already been specified, | |
3912 | -- and if so gives an error message. If there is a duplicate, True is | |
3913 | -- returned, otherwise if there is no error, False is returned. | |
3914 | ||
81b424ac | 3915 | procedure Check_Indexing_Functions; |
3916 | -- Check that the function in Constant_Indexing or Variable_Indexing | |
3917 | -- attribute has the proper type structure. If the name is overloaded, | |
cac18f71 | 3918 | -- check that some interpretation is legal. |
81b424ac | 3919 | |
89cc7147 | 3920 | procedure Check_Iterator_Functions; |
3921 | -- Check that there is a single function in Default_Iterator attribute | |
8df4f2a5 | 3922 | -- has the proper type structure. |
89cc7147 | 3923 | |
3924 | function Check_Primitive_Function (Subp : Entity_Id) return Boolean; | |
d03bfaa1 | 3925 | -- Common legality check for the previous two |
89cc7147 | 3926 | |
177675a7 | 3927 | ----------------------------------- |
3928 | -- Analyze_Stream_TSS_Definition -- | |
3929 | ----------------------------------- | |
3930 | ||
9f373bb8 | 3931 | procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is |
3932 | Subp : Entity_Id := Empty; | |
3933 | I : Interp_Index; | |
3934 | It : Interp; | |
3935 | Pnam : Entity_Id; | |
3936 | ||
3937 | Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read); | |
ba662f09 | 3938 | -- True for Read attribute, False for other attributes |
9f373bb8 | 3939 | |
c41e404d | 3940 | function Has_Good_Profile |
3941 | (Subp : Entity_Id; | |
3942 | Report : Boolean := False) return Boolean; | |
9f373bb8 | 3943 | -- Return true if the entity is a subprogram with an appropriate |
ba662f09 | 3944 | -- profile for the attribute being defined. If result is False and |
3945 | -- Report is True, function emits appropriate error. | |
9f373bb8 | 3946 | |
3947 | ---------------------- | |
3948 | -- Has_Good_Profile -- | |
3949 | ---------------------- | |
3950 | ||
c41e404d | 3951 | function Has_Good_Profile |
3952 | (Subp : Entity_Id; | |
3953 | Report : Boolean := False) return Boolean | |
3954 | is | |
9f373bb8 | 3955 | Expected_Ekind : constant array (Boolean) of Entity_Kind := |
3956 | (False => E_Procedure, True => E_Function); | |
4a83cc35 | 3957 | Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input); |
3958 | F : Entity_Id; | |
9f373bb8 | 3959 | Typ : Entity_Id; |
3960 | ||
3961 | begin | |
3962 | if Ekind (Subp) /= Expected_Ekind (Is_Function) then | |
3963 | return False; | |
3964 | end if; | |
3965 | ||
3966 | F := First_Formal (Subp); | |
3967 | ||
3968 | if No (F) | |
3969 | or else Ekind (Etype (F)) /= E_Anonymous_Access_Type | |
3970 | or else Designated_Type (Etype (F)) /= | |
4a83cc35 | 3971 | Class_Wide_Type (RTE (RE_Root_Stream_Type)) |
9f373bb8 | 3972 | then |
3973 | return False; | |
3974 | end if; | |
3975 | ||
3976 | if not Is_Function then | |
3977 | Next_Formal (F); | |
3978 | ||
3979 | declare | |
3980 | Expected_Mode : constant array (Boolean) of Entity_Kind := | |
3981 | (False => E_In_Parameter, | |
3982 | True => E_Out_Parameter); | |
3983 | begin | |
3984 | if Parameter_Mode (F) /= Expected_Mode (Is_Read) then | |
3985 | return False; | |
3986 | end if; | |
3987 | end; | |
3988 | ||
3989 | Typ := Etype (F); | |
3990 | ||
b64082f2 | 3991 | -- If the attribute specification comes from an aspect |
51fa2a45 | 3992 | -- specification for a class-wide stream, the parameter must be |
3993 | -- a class-wide type of the entity to which the aspect applies. | |
b64082f2 | 3994 | |
3995 | if From_Aspect_Specification (N) | |
3996 | and then Class_Present (Parent (N)) | |
3997 | and then Is_Class_Wide_Type (Typ) | |
3998 | then | |
3999 | Typ := Etype (Typ); | |
4000 | end if; | |
4001 | ||
9f373bb8 | 4002 | else |
4003 | Typ := Etype (Subp); | |
4004 | end if; | |
4005 | ||
51fa2a45 | 4006 | -- Verify that the prefix of the attribute and the local name for |
5a8fe506 | 4007 | -- the type of the formal match, or one is the class-wide of the |
4008 | -- other, in the case of a class-wide stream operation. | |
48680a09 | 4009 | |
b8eacb12 | 4010 | if Base_Type (Typ) = Base_Type (Ent) |
5a8fe506 | 4011 | or else (Is_Class_Wide_Type (Typ) |
2be1f7d7 | 4012 | and then Typ = Class_Wide_Type (Base_Type (Ent))) |
fbf4d6ef | 4013 | or else (Is_Class_Wide_Type (Ent) |
4014 | and then Ent = Class_Wide_Type (Base_Type (Typ))) | |
5a8fe506 | 4015 | then |
4016 | null; | |
4017 | else | |
4018 | return False; | |
4019 | end if; | |
4020 | ||
4a83cc35 | 4021 | if Present (Next_Formal (F)) then |
48680a09 | 4022 | return False; |
4023 | ||
4024 | elsif not Is_Scalar_Type (Typ) | |
4025 | and then not Is_First_Subtype (Typ) | |
4026 | and then not Is_Class_Wide_Type (Typ) | |
4027 | then | |
c41e404d | 4028 | if Report and not Is_First_Subtype (Typ) then |
4029 | Error_Msg_N | |
ba662f09 | 4030 | ("subtype of formal in stream operation must be a first " |
4031 | & "subtype", Parameter_Type (Parent (F))); | |
c41e404d | 4032 | end if; |
4033 | ||
48680a09 | 4034 | return False; |
4035 | ||
4036 | else | |
4037 | return True; | |
4038 | end if; | |
9f373bb8 | 4039 | end Has_Good_Profile; |
4040 | ||
4041 | -- Start of processing for Analyze_Stream_TSS_Definition | |
4042 | ||
4043 | begin | |
4044 | FOnly := True; | |
4045 | ||
4046 | if not Is_Type (U_Ent) then | |
4047 | Error_Msg_N ("local name must be a subtype", Nam); | |
4048 | return; | |
48680a09 | 4049 | |
4050 | elsif not Is_First_Subtype (U_Ent) then | |
4051 | Error_Msg_N ("local name must be a first subtype", Nam); | |
4052 | return; | |
9f373bb8 | 4053 | end if; |
4054 | ||
4055 | Pnam := TSS (Base_Type (U_Ent), TSS_Nam); | |
4056 | ||
44e4341e | 4057 | -- If Pnam is present, it can be either inherited from an ancestor |
4058 | -- type (in which case it is legal to redefine it for this type), or | |
4059 | -- be a previous definition of the attribute for the same type (in | |
4060 | -- which case it is illegal). | |
4061 | ||
4062 | -- In the first case, it will have been analyzed already, and we | |
4063 | -- can check that its profile does not match the expected profile | |
4064 | -- for a stream attribute of U_Ent. In the second case, either Pnam | |
4065 | -- has been analyzed (and has the expected profile), or it has not | |
4066 | -- been analyzed yet (case of a type that has not been frozen yet | |
4067 | -- and for which the stream attribute has been set using Set_TSS). | |
4068 | ||
4069 | if Present (Pnam) | |
4070 | and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam)) | |
4071 | then | |
9f373bb8 | 4072 | Error_Msg_Sloc := Sloc (Pnam); |
4073 | Error_Msg_Name_1 := Attr; | |
4074 | Error_Msg_N ("% attribute already defined #", Nam); | |
4075 | return; | |
4076 | end if; | |
4077 | ||
4078 | Analyze (Expr); | |
4079 | ||
4080 | if Is_Entity_Name (Expr) then | |
4081 | if not Is_Overloaded (Expr) then | |
c41e404d | 4082 | if Has_Good_Profile (Entity (Expr), Report => True) then |
9f373bb8 | 4083 | Subp := Entity (Expr); |
4084 | end if; | |
4085 | ||
4086 | else | |
4087 | Get_First_Interp (Expr, I, It); | |
9f373bb8 | 4088 | while Present (It.Nam) loop |
4089 | if Has_Good_Profile (It.Nam) then | |
4090 | Subp := It.Nam; | |
4091 | exit; | |
4092 | end if; | |
4093 | ||
4094 | Get_Next_Interp (I, It); | |
4095 | end loop; | |
4096 | end if; | |
4097 | end if; | |
4098 | ||
4099 | if Present (Subp) then | |
59ac57b5 | 4100 | if Is_Abstract_Subprogram (Subp) then |
9f373bb8 | 4101 | Error_Msg_N ("stream subprogram must not be abstract", Expr); |
4102 | return; | |
e12b2502 | 4103 | |
299b347e | 4104 | -- A stream subprogram for an interface type must be a null |
bfbd9cf4 | 4105 | -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type |
4106 | -- of an interface is not an interface type (3.9.4 (6.b/2)). | |
e12b2502 | 4107 | |
4108 | elsif Is_Interface (U_Ent) | |
5a8fe506 | 4109 | and then not Is_Class_Wide_Type (U_Ent) |
e12b2502 | 4110 | and then not Inside_A_Generic |
e12b2502 | 4111 | and then |
5a8fe506 | 4112 | (Ekind (Subp) = E_Function |
4113 | or else | |
4114 | not Null_Present | |
2be1f7d7 | 4115 | (Specification |
4116 | (Unit_Declaration_Node (Ultimate_Alias (Subp))))) | |
e12b2502 | 4117 | then |
4118 | Error_Msg_N | |
4a83cc35 | 4119 | ("stream subprogram for interface type must be null " |
4120 | & "procedure", Expr); | |
9f373bb8 | 4121 | end if; |
4122 | ||
4123 | Set_Entity (Expr, Subp); | |
4124 | Set_Etype (Expr, Etype (Subp)); | |
4125 | ||
44e4341e | 4126 | New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam); |
9f373bb8 | 4127 | |
4128 | else | |
4129 | Error_Msg_Name_1 := Attr; | |
4130 | Error_Msg_N ("incorrect expression for% attribute", Expr); | |
4131 | end if; | |
4132 | end Analyze_Stream_TSS_Definition; | |
4133 | ||
81b424ac | 4134 | ------------------------------ |
4135 | -- Check_Indexing_Functions -- | |
4136 | ------------------------------ | |
4137 | ||
4138 | procedure Check_Indexing_Functions is | |
c8a2d809 | 4139 | Indexing_Found : Boolean := False; |
8df4f2a5 | 4140 | |
44d567c8 | 4141 | procedure Check_Inherited_Indexing; |
4142 | -- For a derived type, check that no indexing aspect is specified | |
4143 | -- for the type if it is also inherited | |
4144 | ||
81b424ac | 4145 | procedure Check_One_Function (Subp : Entity_Id); |
7796365f | 4146 | -- Check one possible interpretation. Sets Indexing_Found True if a |
4147 | -- legal indexing function is found. | |
81b424ac | 4148 | |
05987af3 | 4149 | procedure Illegal_Indexing (Msg : String); |
4150 | -- Diagnose illegal indexing function if not overloaded. In the | |
4151 | -- overloaded case indicate that no legal interpretation exists. | |
4152 | ||
44d567c8 | 4153 | ------------------------------ |
4154 | -- Check_Inherited_Indexing -- | |
4155 | ------------------------------ | |
4156 | ||
4157 | procedure Check_Inherited_Indexing is | |
4158 | Inherited : Node_Id; | |
4159 | ||
4160 | begin | |
4161 | if Attr = Name_Constant_Indexing then | |
4162 | Inherited := | |
4163 | Find_Aspect (Etype (Ent), Aspect_Constant_Indexing); | |
4164 | else pragma Assert (Attr = Name_Variable_Indexing); | |
4165 | Inherited := | |
4166 | Find_Aspect (Etype (Ent), Aspect_Variable_Indexing); | |
4167 | end if; | |
4168 | ||
4169 | if Present (Inherited) then | |
4170 | if Debug_Flag_Dot_XX then | |
4171 | null; | |
4172 | ||
83d39cd3 | 4173 | -- OK if current attribute_definition_clause is expansion of |
4174 | -- inherited aspect. | |
44d567c8 | 4175 | |
4176 | elsif Aspect_Rep_Item (Inherited) = N then | |
4177 | null; | |
4178 | ||
83d39cd3 | 4179 | -- Indicate the operation that must be overridden, rather than |
4180 | -- redefining the indexing aspect. | |
44d567c8 | 4181 | |
4182 | else | |
4183 | Illegal_Indexing | |
f2837ceb | 4184 | ("indexing function already inherited from parent type"); |
44d567c8 | 4185 | Error_Msg_NE |
4186 | ("!override & instead", | |
4187 | N, Entity (Expression (Inherited))); | |
4188 | end if; | |
4189 | end if; | |
4190 | end Check_Inherited_Indexing; | |
4191 | ||
81b424ac | 4192 | ------------------------ |
4193 | -- Check_One_Function -- | |
4194 | ------------------------ | |
4195 | ||
4196 | procedure Check_One_Function (Subp : Entity_Id) is | |
05987af3 | 4197 | Default_Element : Node_Id; |
4198 | Ret_Type : constant Entity_Id := Etype (Subp); | |
1b7510f9 | 4199 | |
81b424ac | 4200 | begin |
05987af3 | 4201 | if not Is_Overloadable (Subp) then |
4202 | Illegal_Indexing ("illegal indexing function for type&"); | |
4203 | return; | |
4204 | ||
7796365f | 4205 | elsif Scope (Subp) /= Scope (Ent) then |
4206 | if Nkind (Expr) = N_Expanded_Name then | |
4207 | ||
4208 | -- Indexing function can't be declared elsewhere | |
4209 | ||
4210 | Illegal_Indexing | |
4211 | ("indexing function must be declared in scope of type&"); | |
4212 | end if; | |
4213 | ||
05987af3 | 4214 | return; |
4215 | ||
4216 | elsif No (First_Formal (Subp)) then | |
4217 | Illegal_Indexing | |
4218 | ("Indexing requires a function that applies to type&"); | |
4219 | return; | |
4220 | ||
4221 | elsif No (Next_Formal (First_Formal (Subp))) then | |
4222 | Illegal_Indexing | |
2eb0ff42 | 4223 | ("indexing function must have at least two parameters"); |
05987af3 | 4224 | return; |
4225 | ||
4226 | elsif Is_Derived_Type (Ent) then | |
44d567c8 | 4227 | Check_Inherited_Indexing; |
05987af3 | 4228 | end if; |
4229 | ||
e81df51c | 4230 | if not Check_Primitive_Function (Subp) then |
05987af3 | 4231 | Illegal_Indexing |
4232 | ("Indexing aspect requires a function that applies to type&"); | |
4233 | return; | |
81b424ac | 4234 | end if; |
4235 | ||
7796365f | 4236 | -- If partial declaration exists, verify that it is not tagged. |
4237 | ||
4238 | if Ekind (Current_Scope) = E_Package | |
4239 | and then Has_Private_Declaration (Ent) | |
4240 | and then From_Aspect_Specification (N) | |
7c0c95b8 | 4241 | and then |
4242 | List_Containing (Parent (Ent)) = | |
4243 | Private_Declarations | |
7796365f | 4244 | (Specification (Unit_Declaration_Node (Current_Scope))) |
4245 | and then Nkind (N) = N_Attribute_Definition_Clause | |
4246 | then | |
4247 | declare | |
4248 | Decl : Node_Id; | |
4249 | ||
4250 | begin | |
4251 | Decl := | |
4252 | First (Visible_Declarations | |
7c0c95b8 | 4253 | (Specification |
4254 | (Unit_Declaration_Node (Current_Scope)))); | |
7796365f | 4255 | |
4256 | while Present (Decl) loop | |
4257 | if Nkind (Decl) = N_Private_Type_Declaration | |
4258 | and then Ent = Full_View (Defining_Identifier (Decl)) | |
4259 | and then Tagged_Present (Decl) | |
4260 | and then No (Aspect_Specifications (Decl)) | |
4261 | then | |
4262 | Illegal_Indexing | |
4263 | ("Indexing aspect cannot be specified on full view " | |
7c0c95b8 | 4264 | & "if partial view is tagged"); |
7796365f | 4265 | return; |
4266 | end if; | |
4267 | ||
4268 | Next (Decl); | |
4269 | end loop; | |
4270 | end; | |
4271 | end if; | |
4272 | ||
1b7510f9 | 4273 | -- An indexing function must return either the default element of |
cac18f71 | 4274 | -- the container, or a reference type. For variable indexing it |
a45d946f | 4275 | -- must be the latter. |
1b7510f9 | 4276 | |
05987af3 | 4277 | Default_Element := |
4278 | Find_Value_Of_Aspect | |
4279 | (Etype (First_Formal (Subp)), Aspect_Iterator_Element); | |
4280 | ||
1b7510f9 | 4281 | if Present (Default_Element) then |
4282 | Analyze (Default_Element); | |
a45d946f | 4283 | |
1b7510f9 | 4284 | if Is_Entity_Name (Default_Element) |
05987af3 | 4285 | and then not Covers (Entity (Default_Element), Ret_Type) |
4286 | and then False | |
1b7510f9 | 4287 | then |
05987af3 | 4288 | Illegal_Indexing |
4289 | ("wrong return type for indexing function"); | |
1b7510f9 | 4290 | return; |
4291 | end if; | |
4292 | end if; | |
4293 | ||
a45d946f | 4294 | -- For variable_indexing the return type must be a reference type |
1b7510f9 | 4295 | |
05987af3 | 4296 | if Attr = Name_Variable_Indexing then |
4297 | if not Has_Implicit_Dereference (Ret_Type) then | |
4298 | Illegal_Indexing | |
4299 | ("variable indexing must return a reference type"); | |
4300 | return; | |
4301 | ||
423b89fd | 4302 | elsif Is_Access_Constant |
4303 | (Etype (First_Discriminant (Ret_Type))) | |
05987af3 | 4304 | then |
4305 | Illegal_Indexing | |
4306 | ("variable indexing must return an access to variable"); | |
4307 | return; | |
4308 | end if; | |
cac18f71 | 4309 | |
4310 | else | |
05987af3 | 4311 | if Has_Implicit_Dereference (Ret_Type) |
4312 | and then not | |
4313 | Is_Access_Constant (Etype (First_Discriminant (Ret_Type))) | |
4314 | then | |
4315 | Illegal_Indexing | |
4316 | ("constant indexing must return an access to constant"); | |
4317 | return; | |
4318 | ||
4319 | elsif Is_Access_Type (Etype (First_Formal (Subp))) | |
4320 | and then not Is_Access_Constant (Etype (First_Formal (Subp))) | |
4321 | then | |
4322 | Illegal_Indexing | |
4323 | ("constant indexing must apply to an access to constant"); | |
4324 | return; | |
4325 | end if; | |
81b424ac | 4326 | end if; |
05987af3 | 4327 | |
4328 | -- All checks succeeded. | |
4329 | ||
4330 | Indexing_Found := True; | |
81b424ac | 4331 | end Check_One_Function; |
4332 | ||
05987af3 | 4333 | ----------------------- |
4334 | -- Illegal_Indexing -- | |
4335 | ----------------------- | |
4336 | ||
4337 | procedure Illegal_Indexing (Msg : String) is | |
4338 | begin | |
7796365f | 4339 | Error_Msg_NE (Msg, N, Ent); |
05987af3 | 4340 | end Illegal_Indexing; |
4341 | ||
81b424ac | 4342 | -- Start of processing for Check_Indexing_Functions |
4343 | ||
4344 | begin | |
89cc7147 | 4345 | if In_Instance then |
44d567c8 | 4346 | Check_Inherited_Indexing; |
89cc7147 | 4347 | end if; |
4348 | ||
81b424ac | 4349 | Analyze (Expr); |
4350 | ||
4351 | if not Is_Overloaded (Expr) then | |
4352 | Check_One_Function (Entity (Expr)); | |
4353 | ||
4354 | else | |
4355 | declare | |
2c5754de | 4356 | I : Interp_Index; |
81b424ac | 4357 | It : Interp; |
4358 | ||
4359 | begin | |
cac18f71 | 4360 | Indexing_Found := False; |
81b424ac | 4361 | Get_First_Interp (Expr, I, It); |
4362 | while Present (It.Nam) loop | |
4363 | ||
4364 | -- Note that analysis will have added the interpretation | |
4365 | -- that corresponds to the dereference. We only check the | |
4366 | -- subprogram itself. | |
4367 | ||
4368 | if Is_Overloadable (It.Nam) then | |
4369 | Check_One_Function (It.Nam); | |
4370 | end if; | |
4371 | ||
4372 | Get_Next_Interp (I, It); | |
4373 | end loop; | |
4374 | end; | |
4375 | end if; | |
7796365f | 4376 | |
7c0c95b8 | 4377 | if not Indexing_Found and then not Error_Posted (N) then |
7796365f | 4378 | Error_Msg_NE |
4379 | ("aspect Indexing requires a local function that " | |
4380 | & "applies to type&", Expr, Ent); | |
4381 | end if; | |
81b424ac | 4382 | end Check_Indexing_Functions; |
4383 | ||
89cc7147 | 4384 | ------------------------------ |
4385 | -- Check_Iterator_Functions -- | |
4386 | ------------------------------ | |
4387 | ||
4388 | procedure Check_Iterator_Functions is | |
89cc7147 | 4389 | function Valid_Default_Iterator (Subp : Entity_Id) return Boolean; |
8df4f2a5 | 4390 | -- Check one possible interpretation for validity |
89cc7147 | 4391 | |
4392 | ---------------------------- | |
4393 | -- Valid_Default_Iterator -- | |
4394 | ---------------------------- | |
4395 | ||
4396 | function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is | |
8b8be176 | 4397 | Root_T : constant Entity_Id := Root_Type (Etype (Etype (Subp))); |
7f5dd8d8 | 4398 | Formal : Entity_Id; |
89cc7147 | 4399 | |
4400 | begin | |
4401 | if not Check_Primitive_Function (Subp) then | |
4402 | return False; | |
8b8be176 | 4403 | |
4404 | -- The return type must be derived from a type in an instance | |
4405 | -- of Iterator.Interfaces, and thus its root type must have a | |
4406 | -- predefined name. | |
4407 | ||
4408 | elsif Chars (Root_T) /= Name_Forward_Iterator | |
4409 | and then Chars (Root_T) /= Name_Reversible_Iterator | |
4410 | then | |
4411 | return False; | |
4412 | ||
89cc7147 | 4413 | else |
4414 | Formal := First_Formal (Subp); | |
4415 | end if; | |
4416 | ||
8df4f2a5 | 4417 | -- False if any subsequent formal has no default expression |
89cc7147 | 4418 | |
8df4f2a5 | 4419 | Formal := Next_Formal (Formal); |
4420 | while Present (Formal) loop | |
4421 | if No (Expression (Parent (Formal))) then | |
4422 | return False; | |
4423 | end if; | |
89cc7147 | 4424 | |
8df4f2a5 | 4425 | Next_Formal (Formal); |
4426 | end loop; | |
89cc7147 | 4427 | |
8df4f2a5 | 4428 | -- True if all subsequent formals have default expressions |
89cc7147 | 4429 | |
4430 | return True; | |
4431 | end Valid_Default_Iterator; | |
4432 | ||
4433 | -- Start of processing for Check_Iterator_Functions | |
4434 | ||
4435 | begin | |
4436 | Analyze (Expr); | |
4437 | ||
4438 | if not Is_Entity_Name (Expr) then | |
4439 | Error_Msg_N ("aspect Iterator must be a function name", Expr); | |
4440 | end if; | |
4441 | ||
4442 | if not Is_Overloaded (Expr) then | |
4443 | if not Check_Primitive_Function (Entity (Expr)) then | |
4444 | Error_Msg_NE | |
4445 | ("aspect Indexing requires a function that applies to type&", | |
4446 | Entity (Expr), Ent); | |
4447 | end if; | |
4448 | ||
05f6f999 | 4449 | -- Flag the default_iterator as well as the denoted function. |
4450 | ||
89cc7147 | 4451 | if not Valid_Default_Iterator (Entity (Expr)) then |
05f6f999 | 4452 | Error_Msg_N ("improper function for default iterator!", Expr); |
89cc7147 | 4453 | end if; |
4454 | ||
4455 | else | |
89cc7147 | 4456 | declare |
270ee9c5 | 4457 | Default : Entity_Id := Empty; |
8be33fbe | 4458 | I : Interp_Index; |
4459 | It : Interp; | |
89cc7147 | 4460 | |
4461 | begin | |
4462 | Get_First_Interp (Expr, I, It); | |
4463 | while Present (It.Nam) loop | |
4464 | if not Check_Primitive_Function (It.Nam) | |
59f3e675 | 4465 | or else not Valid_Default_Iterator (It.Nam) |
89cc7147 | 4466 | then |
4467 | Remove_Interp (I); | |
4468 | ||
4469 | elsif Present (Default) then | |
89cc7147 | 4470 | |
8be33fbe | 4471 | -- An explicit one should override an implicit one |
4472 | ||
4473 | if Comes_From_Source (Default) = | |
4474 | Comes_From_Source (It.Nam) | |
4475 | then | |
4476 | Error_Msg_N ("default iterator must be unique", Expr); | |
4477 | Error_Msg_Sloc := Sloc (Default); | |
4478 | Error_Msg_N ("\\possible interpretation#", Expr); | |
4479 | Error_Msg_Sloc := Sloc (It.Nam); | |
4480 | Error_Msg_N ("\\possible interpretation#", Expr); | |
4481 | ||
4482 | elsif Comes_From_Source (It.Nam) then | |
4483 | Default := It.Nam; | |
4484 | end if; | |
89cc7147 | 4485 | else |
4486 | Default := It.Nam; | |
4487 | end if; | |
4488 | ||
4489 | Get_Next_Interp (I, It); | |
4490 | end loop; | |
89cc7147 | 4491 | |
270ee9c5 | 4492 | if Present (Default) then |
4493 | Set_Entity (Expr, Default); | |
4494 | Set_Is_Overloaded (Expr, False); | |
8b8be176 | 4495 | else |
4496 | Error_Msg_N | |
7f5dd8d8 | 4497 | ("no interpretation is a valid default iterator!", Expr); |
270ee9c5 | 4498 | end if; |
4499 | end; | |
89cc7147 | 4500 | end if; |
4501 | end Check_Iterator_Functions; | |
4502 | ||
4503 | ------------------------------- | |
4504 | -- Check_Primitive_Function -- | |
4505 | ------------------------------- | |
4506 | ||
4507 | function Check_Primitive_Function (Subp : Entity_Id) return Boolean is | |
4508 | Ctrl : Entity_Id; | |
4509 | ||
4510 | begin | |
4511 | if Ekind (Subp) /= E_Function then | |
4512 | return False; | |
4513 | end if; | |
4514 | ||
4515 | if No (First_Formal (Subp)) then | |
4516 | return False; | |
4517 | else | |
4518 | Ctrl := Etype (First_Formal (Subp)); | |
4519 | end if; | |
4520 | ||
05f6f999 | 4521 | -- To be a primitive operation subprogram has to be in same scope. |
4522 | ||
4523 | if Scope (Ctrl) /= Scope (Subp) then | |
4524 | return False; | |
4525 | end if; | |
4526 | ||
7d6fb253 | 4527 | -- Type of formal may be the class-wide type, an access to such, |
4528 | -- or an incomplete view. | |
4529 | ||
89cc7147 | 4530 | if Ctrl = Ent |
4531 | or else Ctrl = Class_Wide_Type (Ent) | |
4532 | or else | |
4533 | (Ekind (Ctrl) = E_Anonymous_Access_Type | |
b85d62ec | 4534 | and then (Designated_Type (Ctrl) = Ent |
4535 | or else | |
4536 | Designated_Type (Ctrl) = Class_Wide_Type (Ent))) | |
7d6fb253 | 4537 | or else |
4538 | (Ekind (Ctrl) = E_Incomplete_Type | |
4539 | and then Full_View (Ctrl) = Ent) | |
89cc7147 | 4540 | then |
4541 | null; | |
89cc7147 | 4542 | else |
4543 | return False; | |
4544 | end if; | |
4545 | ||
4546 | return True; | |
4547 | end Check_Primitive_Function; | |
4548 | ||
ae888dbd | 4549 | ---------------------- |
4550 | -- Duplicate_Clause -- | |
4551 | ---------------------- | |
4552 | ||
4553 | function Duplicate_Clause return Boolean is | |
d74fc39a | 4554 | A : Node_Id; |
ae888dbd | 4555 | |
4556 | begin | |
c8969ba6 | 4557 | -- Nothing to do if this attribute definition clause comes from |
4558 | -- an aspect specification, since we could not be duplicating an | |
ae888dbd | 4559 | -- explicit clause, and we dealt with the case of duplicated aspects |
4560 | -- in Analyze_Aspect_Specifications. | |
4561 | ||
4562 | if From_Aspect_Specification (N) then | |
4563 | return False; | |
4564 | end if; | |
4565 | ||
89f1e35c | 4566 | -- Otherwise current clause may duplicate previous clause, or a |
4567 | -- previously given pragma or aspect specification for the same | |
4568 | -- aspect. | |
d74fc39a | 4569 | |
89b3b365 | 4570 | A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False); |
ae888dbd | 4571 | |
4572 | if Present (A) then | |
89f1e35c | 4573 | Error_Msg_Name_1 := Chars (N); |
4574 | Error_Msg_Sloc := Sloc (A); | |
4575 | ||
89b3b365 | 4576 | Error_Msg_NE ("aspect% for & previously given#", N, U_Ent); |
89f1e35c | 4577 | return True; |
ae888dbd | 4578 | end if; |
4579 | ||
4580 | return False; | |
4581 | end Duplicate_Clause; | |
4582 | ||
9f373bb8 | 4583 | -- Start of processing for Analyze_Attribute_Definition_Clause |
4584 | ||
d6f39728 | 4585 | begin |
d64221a7 | 4586 | -- The following code is a defense against recursion. Not clear that |
51fa2a45 | 4587 | -- this can happen legitimately, but perhaps some error situations can |
4588 | -- cause it, and we did see this recursion during testing. | |
d64221a7 | 4589 | |
4590 | if Analyzed (N) then | |
4591 | return; | |
4592 | else | |
4593 | Set_Analyzed (N, True); | |
4594 | end if; | |
4595 | ||
2609e4d0 | 4596 | Check_Restriction_No_Use_Of_Attribute (N); |
4597 | ||
a29bc1d9 | 4598 | -- Ignore some selected attributes in CodePeer mode since they are not |
4599 | -- relevant in this context. | |
4600 | ||
4601 | if CodePeer_Mode then | |
4602 | case Id is | |
4603 | ||
4604 | -- Ignore Component_Size in CodePeer mode, to avoid changing the | |
4605 | -- internal representation of types by implicitly packing them. | |
4606 | ||
4607 | when Attribute_Component_Size => | |
4608 | Rewrite (N, Make_Null_Statement (Sloc (N))); | |
4609 | return; | |
4610 | ||
4611 | when others => | |
4612 | null; | |
4613 | end case; | |
4614 | end if; | |
4615 | ||
d8ba53a8 | 4616 | -- Process Ignore_Rep_Clauses option |
eef1ca1e | 4617 | |
d8ba53a8 | 4618 | if Ignore_Rep_Clauses then |
9d627c41 | 4619 | case Id is |
4620 | ||
eef1ca1e | 4621 | -- The following should be ignored. They do not affect legality |
4622 | -- and may be target dependent. The basic idea of -gnatI is to | |
4623 | -- ignore any rep clauses that may be target dependent but do not | |
4624 | -- affect legality (except possibly to be rejected because they | |
4625 | -- are incompatible with the compilation target). | |
9d627c41 | 4626 | |
2f1aac99 | 4627 | when Attribute_Alignment | |
9d627c41 | 4628 | Attribute_Bit_Order | |
4629 | Attribute_Component_Size | | |
4630 | Attribute_Machine_Radix | | |
4631 | Attribute_Object_Size | | |
4632 | Attribute_Size | | |
2ff55065 | 4633 | Attribute_Small | |
9d627c41 | 4634 | Attribute_Stream_Size | |
4635 | Attribute_Value_Size => | |
2ff55065 | 4636 | Kill_Rep_Clause (N); |
9d627c41 | 4637 | return; |
4638 | ||
eef1ca1e | 4639 | -- The following should not be ignored, because in the first place |
51fa2a45 | 4640 | -- they are reasonably portable, and should not cause problems |
4641 | -- in compiling code from another target, and also they do affect | |
4642 | -- legality, e.g. failing to provide a stream attribute for a type | |
4643 | -- may make a program illegal. | |
9d627c41 | 4644 | |
b55f7641 | 4645 | when Attribute_External_Tag | |
4646 | Attribute_Input | | |
4647 | Attribute_Output | | |
4648 | Attribute_Read | | |
4649 | Attribute_Simple_Storage_Pool | | |
4650 | Attribute_Storage_Pool | | |
4651 | Attribute_Storage_Size | | |
4652 | Attribute_Write => | |
9d627c41 | 4653 | null; |
4654 | ||
2ff55065 | 4655 | -- We do not do anything here with address clauses, they will be |
4656 | -- removed by Freeze later on, but for now, it works better to | |
4657 | -- keep then in the tree. | |
4658 | ||
4659 | when Attribute_Address => | |
4660 | null; | |
4661 | ||
b593a52c | 4662 | -- Other cases are errors ("attribute& cannot be set with |
4663 | -- definition clause"), which will be caught below. | |
9d627c41 | 4664 | |
4665 | when others => | |
4666 | null; | |
4667 | end case; | |
fbc67f84 | 4668 | end if; |
4669 | ||
d6f39728 | 4670 | Analyze (Nam); |
4671 | Ent := Entity (Nam); | |
4672 | ||
4673 | if Rep_Item_Too_Early (Ent, N) then | |
4674 | return; | |
4675 | end if; | |
4676 | ||
9f373bb8 | 4677 | -- Rep clause applies to full view of incomplete type or private type if |
4678 | -- we have one (if not, this is a premature use of the type). However, | |
4679 | -- certain semantic checks need to be done on the specified entity (i.e. | |
4680 | -- the private view), so we save it in Ent. | |
d6f39728 | 4681 | |
4682 | if Is_Private_Type (Ent) | |
4683 | and then Is_Derived_Type (Ent) | |
4684 | and then not Is_Tagged_Type (Ent) | |
4685 | and then No (Full_View (Ent)) | |
4686 | then | |
9f373bb8 | 4687 | -- If this is a private type whose completion is a derivation from |
4688 | -- another private type, there is no full view, and the attribute | |
4689 | -- belongs to the type itself, not its underlying parent. | |
d6f39728 | 4690 | |
4691 | U_Ent := Ent; | |
4692 | ||
4693 | elsif Ekind (Ent) = E_Incomplete_Type then | |
d5b349fa | 4694 | |
9f373bb8 | 4695 | -- The attribute applies to the full view, set the entity of the |
4696 | -- attribute definition accordingly. | |
d5b349fa | 4697 | |
d6f39728 | 4698 | Ent := Underlying_Type (Ent); |
4699 | U_Ent := Ent; | |
d5b349fa | 4700 | Set_Entity (Nam, Ent); |
4701 | ||
d6f39728 | 4702 | else |
4703 | U_Ent := Underlying_Type (Ent); | |
4704 | end if; | |
4705 | ||
44705307 | 4706 | -- Avoid cascaded error |
d6f39728 | 4707 | |
4708 | if Etype (Nam) = Any_Type then | |
4709 | return; | |
4710 | ||
89f1e35c | 4711 | -- Must be declared in current scope or in case of an aspect |
ace3389d | 4712 | -- specification, must be visible in current scope. |
44705307 | 4713 | |
89f1e35c | 4714 | elsif Scope (Ent) /= Current_Scope |
ace3389d | 4715 | and then |
4716 | not (From_Aspect_Specification (N) | |
4717 | and then Scope_Within_Or_Same (Current_Scope, Scope (Ent))) | |
89f1e35c | 4718 | then |
d6f39728 | 4719 | Error_Msg_N ("entity must be declared in this scope", Nam); |
4720 | return; | |
4721 | ||
44705307 | 4722 | -- Must not be a source renaming (we do have some cases where the |
4723 | -- expander generates a renaming, and those cases are OK, in such | |
a3248fc4 | 4724 | -- cases any attribute applies to the renamed object as well). |
44705307 | 4725 | |
4726 | elsif Is_Object (Ent) | |
4727 | and then Present (Renamed_Object (Ent)) | |
44705307 | 4728 | then |
a3248fc4 | 4729 | -- Case of renamed object from source, this is an error |
4730 | ||
4731 | if Comes_From_Source (Renamed_Object (Ent)) then | |
4732 | Get_Name_String (Chars (N)); | |
4733 | Error_Msg_Strlen := Name_Len; | |
4734 | Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); | |
4735 | Error_Msg_N | |
4736 | ("~ clause not allowed for a renaming declaration " | |
4737 | & "(RM 13.1(6))", Nam); | |
4738 | return; | |
4739 | ||
4740 | -- For the case of a compiler generated renaming, the attribute | |
4741 | -- definition clause applies to the renamed object created by the | |
4742 | -- expander. The easiest general way to handle this is to create a | |
4743 | -- copy of the attribute definition clause for this object. | |
4744 | ||
9a48fc56 | 4745 | elsif Is_Entity_Name (Renamed_Object (Ent)) then |
a3248fc4 | 4746 | Insert_Action (N, |
4747 | Make_Attribute_Definition_Clause (Loc, | |
4748 | Name => | |
4749 | New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc), | |
4750 | Chars => Chars (N), | |
4751 | Expression => Duplicate_Subexpr (Expression (N)))); | |
9a48fc56 | 4752 | |
4753 | -- If the renamed object is not an entity, it must be a dereference | |
4754 | -- of an unconstrained function call, and we must introduce a new | |
4755 | -- declaration to capture the expression. This is needed in the case | |
4756 | -- of 'Alignment, where the original declaration must be rewritten. | |
4757 | ||
4758 | else | |
4759 | pragma Assert | |
4760 | (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference); | |
4761 | null; | |
a3248fc4 | 4762 | end if; |
44705307 | 4763 | |
4764 | -- If no underlying entity, use entity itself, applies to some | |
4765 | -- previously detected error cases ??? | |
4766 | ||
f15731c4 | 4767 | elsif No (U_Ent) then |
4768 | U_Ent := Ent; | |
4769 | ||
44705307 | 4770 | -- Cannot specify for a subtype (exception Object/Value_Size) |
4771 | ||
d6f39728 | 4772 | elsif Is_Type (U_Ent) |
4773 | and then not Is_First_Subtype (U_Ent) | |
4774 | and then Id /= Attribute_Object_Size | |
4775 | and then Id /= Attribute_Value_Size | |
4776 | and then not From_At_Mod (N) | |
4777 | then | |
4778 | Error_Msg_N ("cannot specify attribute for subtype", Nam); | |
4779 | return; | |
d6f39728 | 4780 | end if; |
4781 | ||
ae888dbd | 4782 | Set_Entity (N, U_Ent); |
4783 | ||
d6f39728 | 4784 | -- Switch on particular attribute |
4785 | ||
4786 | case Id is | |
4787 | ||
4788 | ------------- | |
4789 | -- Address -- | |
4790 | ------------- | |
4791 | ||
4792 | -- Address attribute definition clause | |
4793 | ||
4794 | when Attribute_Address => Address : begin | |
177675a7 | 4795 | |
4796 | -- A little error check, catch for X'Address use X'Address; | |
4797 | ||
4798 | if Nkind (Nam) = N_Identifier | |
4799 | and then Nkind (Expr) = N_Attribute_Reference | |
4800 | and then Attribute_Name (Expr) = Name_Address | |
4801 | and then Nkind (Prefix (Expr)) = N_Identifier | |
4802 | and then Chars (Nam) = Chars (Prefix (Expr)) | |
4803 | then | |
4804 | Error_Msg_NE | |
4805 | ("address for & is self-referencing", Prefix (Expr), Ent); | |
4806 | return; | |
4807 | end if; | |
4808 | ||
4809 | -- Not that special case, carry on with analysis of expression | |
4810 | ||
d6f39728 | 4811 | Analyze_And_Resolve (Expr, RTE (RE_Address)); |
4812 | ||
2f1aac99 | 4813 | -- Even when ignoring rep clauses we need to indicate that the |
4814 | -- entity has an address clause and thus it is legal to declare | |
2ff55065 | 4815 | -- it imported. Freeze will get rid of the address clause later. |
2f1aac99 | 4816 | |
4817 | if Ignore_Rep_Clauses then | |
d3ef794c | 4818 | if Ekind_In (U_Ent, E_Variable, E_Constant) then |
2f1aac99 | 4819 | Record_Rep_Item (U_Ent, N); |
4820 | end if; | |
4821 | ||
4822 | return; | |
4823 | end if; | |
4824 | ||
ae888dbd | 4825 | if Duplicate_Clause then |
4826 | null; | |
d6f39728 | 4827 | |
4828 | -- Case of address clause for subprogram | |
4829 | ||
4830 | elsif Is_Subprogram (U_Ent) then | |
d6f39728 | 4831 | if Has_Homonym (U_Ent) then |
4832 | Error_Msg_N | |
f74a102b | 4833 | ("address clause cannot be given for overloaded " |
4834 | & "subprogram", Nam); | |
83f8f0a6 | 4835 | return; |
d6f39728 | 4836 | end if; |
4837 | ||
83f8f0a6 | 4838 | -- For subprograms, all address clauses are permitted, and we |
4839 | -- mark the subprogram as having a deferred freeze so that Gigi | |
4840 | -- will not elaborate it too soon. | |
d6f39728 | 4841 | |
4842 | -- Above needs more comments, what is too soon about??? | |
4843 | ||
4844 | Set_Has_Delayed_Freeze (U_Ent); | |
4845 | ||
4846 | -- Case of address clause for entry | |
4847 | ||
4848 | elsif Ekind (U_Ent) = E_Entry then | |
d6f39728 | 4849 | if Nkind (Parent (N)) = N_Task_Body then |
4850 | Error_Msg_N | |
4851 | ("entry address must be specified in task spec", Nam); | |
83f8f0a6 | 4852 | return; |
d6f39728 | 4853 | end if; |
4854 | ||
4855 | -- For entries, we require a constant address | |
4856 | ||
4857 | Check_Constant_Address_Clause (Expr, U_Ent); | |
4858 | ||
83f8f0a6 | 4859 | -- Special checks for task types |
4860 | ||
f15731c4 | 4861 | if Is_Task_Type (Scope (U_Ent)) |
4862 | and then Comes_From_Source (Scope (U_Ent)) | |
4863 | then | |
4864 | Error_Msg_N | |
1e3532e7 | 4865 | ("??entry address declared for entry in task type", N); |
f15731c4 | 4866 | Error_Msg_N |
1e3532e7 | 4867 | ("\??only one task can be declared of this type", N); |
f15731c4 | 4868 | end if; |
4869 | ||
83f8f0a6 | 4870 | -- Entry address clauses are obsolescent |
4871 | ||
e0521a36 | 4872 | Check_Restriction (No_Obsolescent_Features, N); |
4873 | ||
9dfe12ae | 4874 | if Warn_On_Obsolescent_Feature then |
4875 | Error_Msg_N | |
f74a102b | 4876 | ("?j?attaching interrupt to task entry is an obsolescent " |
4877 | & "feature (RM J.7.1)", N); | |
9dfe12ae | 4878 | Error_Msg_N |
1e3532e7 | 4879 | ("\?j?use interrupt procedure instead", N); |
9dfe12ae | 4880 | end if; |
4881 | ||
83f8f0a6 | 4882 | -- Case of an address clause for a controlled object which we |
4883 | -- consider to be erroneous. | |
9dfe12ae | 4884 | |
83f8f0a6 | 4885 | elsif Is_Controlled (Etype (U_Ent)) |
4886 | or else Has_Controlled_Component (Etype (U_Ent)) | |
4887 | then | |
9dfe12ae | 4888 | Error_Msg_NE |
1e3532e7 | 4889 | ("??controlled object& must not be overlaid", Nam, U_Ent); |
9dfe12ae | 4890 | Error_Msg_N |
1e3532e7 | 4891 | ("\??Program_Error will be raised at run time", Nam); |
9dfe12ae | 4892 | Insert_Action (Declaration_Node (U_Ent), |
4893 | Make_Raise_Program_Error (Loc, | |
4894 | Reason => PE_Overlaid_Controlled_Object)); | |
83f8f0a6 | 4895 | return; |
9dfe12ae | 4896 | |
4897 | -- Case of address clause for a (non-controlled) object | |
d6f39728 | 4898 | |
f02a9a9a | 4899 | elsif Ekind_In (U_Ent, E_Variable, E_Constant) then |
d6f39728 | 4900 | declare |
d6da7448 | 4901 | Expr : constant Node_Id := Expression (N); |
4902 | O_Ent : Entity_Id; | |
4903 | Off : Boolean; | |
d6f39728 | 4904 | |
4905 | begin | |
7ee315cc | 4906 | -- Exported variables cannot have an address clause, because |
4907 | -- this cancels the effect of the pragma Export. | |
d6f39728 | 4908 | |
4909 | if Is_Exported (U_Ent) then | |
4910 | Error_Msg_N | |
4911 | ("cannot export object with address clause", Nam); | |
83f8f0a6 | 4912 | return; |
d6da7448 | 4913 | end if; |
4914 | ||
4915 | Find_Overlaid_Entity (N, O_Ent, Off); | |
d6f39728 | 4916 | |
a9dd889b | 4917 | if Present (O_Ent) then |
798dec73 | 4918 | |
a9dd889b | 4919 | -- If the object overlays a constant object, mark it so |
b2d32174 | 4920 | |
a9dd889b | 4921 | if Is_Constant_Object (O_Ent) then |
4922 | Set_Overlays_Constant (U_Ent); | |
4923 | end if; | |
798dec73 | 4924 | |
514a5555 | 4925 | -- If the address clause is of the form: |
4926 | ||
4927 | -- for X'Address use Y'Address; | |
4928 | ||
4929 | -- or | |
4930 | ||
4931 | -- C : constant Address := Y'Address; | |
4932 | -- ... | |
4933 | -- for X'Address use C; | |
4934 | ||
4935 | -- then we make an entry in the table to check the size | |
4936 | -- and alignment of the overlaying variable. But we defer | |
4937 | -- this check till after code generation to take full | |
4938 | -- advantage of the annotation done by the back end. | |
4939 | ||
4940 | -- If the entity has a generic type, the check will be | |
4941 | -- performed in the instance if the actual type justifies | |
4942 | -- it, and we do not insert the clause in the table to | |
4943 | -- prevent spurious warnings. | |
4944 | ||
4945 | -- Note: we used to test Comes_From_Source and only give | |
4946 | -- this warning for source entities, but we have removed | |
4947 | -- this test. It really seems bogus to generate overlays | |
4948 | -- that would trigger this warning in generated code. | |
4949 | -- Furthermore, by removing the test, we handle the | |
4950 | -- aspect case properly. | |
4951 | ||
4952 | if Is_Object (O_Ent) | |
4953 | and then not Is_Generic_Type (Etype (U_Ent)) | |
4954 | and then Address_Clause_Overlay_Warnings | |
4955 | then | |
4956 | Address_Clause_Checks.Append | |
4957 | ((N, U_Ent, No_Uint, O_Ent, Off)); | |
4958 | end if; | |
a9dd889b | 4959 | else |
4960 | -- If this is not an overlay, mark a variable as being | |
4961 | -- volatile to prevent unwanted optimizations. It's a | |
4962 | -- conservative interpretation of RM 13.3(19) for the | |
4963 | -- cases where the compiler cannot detect potential | |
4964 | -- aliasing issues easily and it also covers the case | |
4965 | -- of an absolute address where the volatile aspect is | |
4966 | -- kind of implicit. | |
4967 | ||
4968 | if Ekind (U_Ent) = E_Variable then | |
4969 | Set_Treat_As_Volatile (U_Ent); | |
4970 | end if; | |
514a5555 | 4971 | |
4972 | -- Make an entry in the table for an absolute address as | |
4973 | -- above to check that the value is compatible with the | |
4974 | -- alignment of the object. | |
4975 | ||
4976 | declare | |
4977 | Addr : constant Node_Id := Address_Value (Expr); | |
4978 | begin | |
4979 | if Compile_Time_Known_Value (Addr) | |
4980 | and then Address_Clause_Overlay_Warnings | |
4981 | then | |
4982 | Address_Clause_Checks.Append | |
4983 | ((N, U_Ent, Expr_Value (Addr), Empty, False)); | |
4984 | end if; | |
4985 | end; | |
b2d32174 | 4986 | end if; |
4987 | ||
798dec73 | 4988 | -- Overlaying controlled objects is erroneous. Emit warning |
4989 | -- but continue analysis because program is itself legal, | |
3ff5e35d | 4990 | -- and back end must see address clause. |
9dfe12ae | 4991 | |
d6da7448 | 4992 | if Present (O_Ent) |
4993 | and then (Has_Controlled_Component (Etype (O_Ent)) | |
f02a9a9a | 4994 | or else Is_Controlled (Etype (O_Ent))) |
0c30cda1 | 4995 | and then not Inside_A_Generic |
9dfe12ae | 4996 | then |
4997 | Error_Msg_N | |
0c30cda1 | 4998 | ("??cannot use overlays with controlled objects", Expr); |
9dfe12ae | 4999 | Error_Msg_N |
1e3532e7 | 5000 | ("\??Program_Error will be raised at run time", Expr); |
9dfe12ae | 5001 | Insert_Action (Declaration_Node (U_Ent), |
5002 | Make_Raise_Program_Error (Loc, | |
5003 | Reason => PE_Overlaid_Controlled_Object)); | |
5004 | ||
95009d64 | 5005 | -- Issue an unconditional warning for a constant overlaying |
5006 | -- a variable. For the reverse case, we will issue it only | |
b2d32174 | 5007 | -- if the variable is modified. |
95009d64 | 5008 | |
b2d32174 | 5009 | elsif Ekind (U_Ent) = E_Constant |
95009d64 | 5010 | and then Present (O_Ent) |
b2d32174 | 5011 | and then not Overlays_Constant (U_Ent) |
5012 | and then Address_Clause_Overlay_Warnings | |
9dfe12ae | 5013 | then |
1e3532e7 | 5014 | Error_Msg_N ("??constant overlays a variable", Expr); |
9dfe12ae | 5015 | |
d6f39728 | 5016 | -- Imported variables can have an address clause, but then |
5017 | -- the import is pretty meaningless except to suppress | |
5018 | -- initializations, so we do not need such variables to | |
5019 | -- be statically allocated (and in fact it causes trouble | |
5020 | -- if the address clause is a local value). | |
5021 | ||
5022 | elsif Is_Imported (U_Ent) then | |
5023 | Set_Is_Statically_Allocated (U_Ent, False); | |
5024 | end if; | |
5025 | ||
5026 | -- We mark a possible modification of a variable with an | |
5027 | -- address clause, since it is likely aliasing is occurring. | |
5028 | ||
177675a7 | 5029 | Note_Possible_Modification (Nam, Sure => False); |
d6f39728 | 5030 | |
9dfe12ae | 5031 | -- Legality checks on the address clause for initialized |
5032 | -- objects is deferred until the freeze point, because | |
2beb22b1 | 5033 | -- a subsequent pragma might indicate that the object |
42e09e36 | 5034 | -- is imported and thus not initialized. Also, the address |
5035 | -- clause might involve entities that have yet to be | |
5036 | -- elaborated. | |
9dfe12ae | 5037 | |
5038 | Set_Has_Delayed_Freeze (U_Ent); | |
5039 | ||
51ad5ad2 | 5040 | -- If an initialization call has been generated for this |
5041 | -- object, it needs to be deferred to after the freeze node | |
5042 | -- we have just now added, otherwise GIGI will see a | |
5043 | -- reference to the variable (as actual to the IP call) | |
5044 | -- before its definition. | |
5045 | ||
5046 | declare | |
df9fba45 | 5047 | Init_Call : constant Node_Id := |
5048 | Remove_Init_Call (U_Ent, N); | |
4bba0a8d | 5049 | |
51ad5ad2 | 5050 | begin |
5051 | if Present (Init_Call) then | |
28a4283c | 5052 | Append_Freeze_Action (U_Ent, Init_Call); |
df9fba45 | 5053 | |
28a4283c | 5054 | -- Reset Initialization_Statements pointer so that |
5055 | -- if there is a pragma Import further down, it can | |
5056 | -- clear any default initialization. | |
df9fba45 | 5057 | |
28a4283c | 5058 | Set_Initialization_Statements (U_Ent, Init_Call); |
51ad5ad2 | 5059 | end if; |
5060 | end; | |
5061 | ||
44e4341e | 5062 | -- Entity has delayed freeze, so we will generate an |
5063 | -- alignment check at the freeze point unless suppressed. | |
d6f39728 | 5064 | |
44e4341e | 5065 | if not Range_Checks_Suppressed (U_Ent) |
5066 | and then not Alignment_Checks_Suppressed (U_Ent) | |
5067 | then | |
5068 | Set_Check_Address_Alignment (N); | |
5069 | end if; | |
d6f39728 | 5070 | |
5071 | -- Kill the size check code, since we are not allocating | |
5072 | -- the variable, it is somewhere else. | |
5073 | ||
5074 | Kill_Size_Check_Code (U_Ent); | |
d6da7448 | 5075 | end; |
83f8f0a6 | 5076 | |
d6f39728 | 5077 | -- Not a valid entity for an address clause |
5078 | ||
5079 | else | |
5080 | Error_Msg_N ("address cannot be given for &", Nam); | |
5081 | end if; | |
5082 | end Address; | |
5083 | ||
5084 | --------------- | |
5085 | -- Alignment -- | |
5086 | --------------- | |
5087 | ||
5088 | -- Alignment attribute definition clause | |
5089 | ||
b47769f0 | 5090 | when Attribute_Alignment => Alignment : declare |
208fd589 | 5091 | Align : constant Uint := Get_Alignment_Value (Expr); |
5092 | Max_Align : constant Uint := UI_From_Int (Maximum_Alignment); | |
41331dcf | 5093 | |
d6f39728 | 5094 | begin |
5095 | FOnly := True; | |
5096 | ||
5097 | if not Is_Type (U_Ent) | |
5098 | and then Ekind (U_Ent) /= E_Variable | |
5099 | and then Ekind (U_Ent) /= E_Constant | |
5100 | then | |
5101 | Error_Msg_N ("alignment cannot be given for &", Nam); | |
5102 | ||
ae888dbd | 5103 | elsif Duplicate_Clause then |
5104 | null; | |
d6f39728 | 5105 | |
5106 | elsif Align /= No_Uint then | |
5107 | Set_Has_Alignment_Clause (U_Ent); | |
208fd589 | 5108 | |
44705307 | 5109 | -- Tagged type case, check for attempt to set alignment to a |
f74a102b | 5110 | -- value greater than Max_Align, and reset if so. This error |
5111 | -- is suppressed in ASIS mode to allow for different ASIS | |
f9906591 | 5112 | -- back ends or ASIS-based tools to query the illegal clause. |
44705307 | 5113 | |
f74a102b | 5114 | if Is_Tagged_Type (U_Ent) |
5115 | and then Align > Max_Align | |
5116 | and then not ASIS_Mode | |
5117 | then | |
208fd589 | 5118 | Error_Msg_N |
1e3532e7 | 5119 | ("alignment for & set to Maximum_Aligment??", Nam); |
f74a102b | 5120 | Set_Alignment (U_Ent, Max_Align); |
44705307 | 5121 | |
5122 | -- All other cases | |
5123 | ||
208fd589 | 5124 | else |
5125 | Set_Alignment (U_Ent, Align); | |
5126 | end if; | |
b47769f0 | 5127 | |
5128 | -- For an array type, U_Ent is the first subtype. In that case, | |
5129 | -- also set the alignment of the anonymous base type so that | |
5130 | -- other subtypes (such as the itypes for aggregates of the | |
5131 | -- type) also receive the expected alignment. | |
5132 | ||
5133 | if Is_Array_Type (U_Ent) then | |
5134 | Set_Alignment (Base_Type (U_Ent), Align); | |
5135 | end if; | |
d6f39728 | 5136 | end if; |
b47769f0 | 5137 | end Alignment; |
d6f39728 | 5138 | |
5139 | --------------- | |
5140 | -- Bit_Order -- | |
5141 | --------------- | |
5142 | ||
5143 | -- Bit_Order attribute definition clause | |
5144 | ||
5145 | when Attribute_Bit_Order => Bit_Order : declare | |
5146 | begin | |
5147 | if not Is_Record_Type (U_Ent) then | |
5148 | Error_Msg_N | |
5149 | ("Bit_Order can only be defined for record type", Nam); | |
5150 | ||
ae888dbd | 5151 | elsif Duplicate_Clause then |
5152 | null; | |
5153 | ||
d6f39728 | 5154 | else |
5155 | Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); | |
5156 | ||
5157 | if Etype (Expr) = Any_Type then | |
5158 | return; | |
5159 | ||
cda40848 | 5160 | elsif not Is_OK_Static_Expression (Expr) then |
9dfe12ae | 5161 | Flag_Non_Static_Expr |
5162 | ("Bit_Order requires static expression!", Expr); | |
d6f39728 | 5163 | |
5164 | else | |
5165 | if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then | |
fae4ea1f | 5166 | Set_Reverse_Bit_Order (Base_Type (U_Ent), True); |
d6f39728 | 5167 | end if; |
5168 | end if; | |
5169 | end if; | |
5170 | end Bit_Order; | |
5171 | ||
5172 | -------------------- | |
5173 | -- Component_Size -- | |
5174 | -------------------- | |
5175 | ||
5176 | -- Component_Size attribute definition clause | |
5177 | ||
5178 | when Attribute_Component_Size => Component_Size_Case : declare | |
5179 | Csize : constant Uint := Static_Integer (Expr); | |
a0fc8c5b | 5180 | Ctyp : Entity_Id; |
d6f39728 | 5181 | Btype : Entity_Id; |
5182 | Biased : Boolean; | |
5183 | New_Ctyp : Entity_Id; | |
5184 | Decl : Node_Id; | |
5185 | ||
5186 | begin | |
5187 | if not Is_Array_Type (U_Ent) then | |
5188 | Error_Msg_N ("component size requires array type", Nam); | |
5189 | return; | |
5190 | end if; | |
5191 | ||
5192 | Btype := Base_Type (U_Ent); | |
f74a102b | 5193 | Ctyp := Component_Type (Btype); |
d6f39728 | 5194 | |
ae888dbd | 5195 | if Duplicate_Clause then |
5196 | null; | |
d6f39728 | 5197 | |
f3e4db96 | 5198 | elsif Rep_Item_Too_Early (Btype, N) then |
5199 | null; | |
5200 | ||
d6f39728 | 5201 | elsif Csize /= No_Uint then |
a0fc8c5b | 5202 | Check_Size (Expr, Ctyp, Csize, Biased); |
d6f39728 | 5203 | |
d74fc39a | 5204 | -- For the biased case, build a declaration for a subtype that |
5205 | -- will be used to represent the biased subtype that reflects | |
5206 | -- the biased representation of components. We need the subtype | |
5207 | -- to get proper conversions on referencing elements of the | |
36ac5fbb | 5208 | -- array. |
3062c401 | 5209 | |
36ac5fbb | 5210 | if Biased then |
5211 | New_Ctyp := | |
5212 | Make_Defining_Identifier (Loc, | |
5213 | Chars => | |
5214 | New_External_Name (Chars (U_Ent), 'C', 0, 'T')); | |
3062c401 | 5215 | |
36ac5fbb | 5216 | Decl := |
5217 | Make_Subtype_Declaration (Loc, | |
5218 | Defining_Identifier => New_Ctyp, | |
5219 | Subtype_Indication => | |
5220 | New_Occurrence_Of (Component_Type (Btype), Loc)); | |
5221 | ||
5222 | Set_Parent (Decl, N); | |
5223 | Analyze (Decl, Suppress => All_Checks); | |
5224 | ||
5225 | Set_Has_Delayed_Freeze (New_Ctyp, False); | |
5226 | Set_Esize (New_Ctyp, Csize); | |
5227 | Set_RM_Size (New_Ctyp, Csize); | |
5228 | Init_Alignment (New_Ctyp); | |
5229 | Set_Is_Itype (New_Ctyp, True); | |
5230 | Set_Associated_Node_For_Itype (New_Ctyp, U_Ent); | |
5231 | ||
5232 | Set_Component_Type (Btype, New_Ctyp); | |
5233 | Set_Biased (New_Ctyp, N, "component size clause"); | |
d6f39728 | 5234 | end if; |
5235 | ||
36ac5fbb | 5236 | Set_Component_Size (Btype, Csize); |
5237 | ||
a0fc8c5b | 5238 | -- Deal with warning on overridden size |
5239 | ||
5240 | if Warn_On_Overridden_Size | |
5241 | and then Has_Size_Clause (Ctyp) | |
5242 | and then RM_Size (Ctyp) /= Csize | |
5243 | then | |
5244 | Error_Msg_NE | |
1e3532e7 | 5245 | ("component size overrides size clause for&?S?", N, Ctyp); |
a0fc8c5b | 5246 | end if; |
5247 | ||
d6f39728 | 5248 | Set_Has_Component_Size_Clause (Btype, True); |
f3e4db96 | 5249 | Set_Has_Non_Standard_Rep (Btype, True); |
d6f39728 | 5250 | end if; |
5251 | end Component_Size_Case; | |
5252 | ||
81b424ac | 5253 | ----------------------- |
5254 | -- Constant_Indexing -- | |
5255 | ----------------------- | |
5256 | ||
5257 | when Attribute_Constant_Indexing => | |
5258 | Check_Indexing_Functions; | |
5259 | ||
89f1e35c | 5260 | --------- |
5261 | -- CPU -- | |
5262 | --------- | |
5263 | ||
5264 | when Attribute_CPU => CPU : | |
5265 | begin | |
5266 | -- CPU attribute definition clause not allowed except from aspect | |
5267 | -- specification. | |
5268 | ||
5269 | if From_Aspect_Specification (N) then | |
5270 | if not Is_Task_Type (U_Ent) then | |
5271 | Error_Msg_N ("CPU can only be defined for task", Nam); | |
5272 | ||
5273 | elsif Duplicate_Clause then | |
5274 | null; | |
5275 | ||
5276 | else | |
5277 | -- The expression must be analyzed in the special manner | |
5278 | -- described in "Handling of Default and Per-Object | |
5279 | -- Expressions" in sem.ads. | |
5280 | ||
5281 | -- The visibility to the discriminants must be restored | |
5282 | ||
5283 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5284 | Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range)); | |
5285 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
5286 | ||
cda40848 | 5287 | if not Is_OK_Static_Expression (Expr) then |
89f1e35c | 5288 | Check_Restriction (Static_Priorities, Expr); |
5289 | end if; | |
5290 | end if; | |
5291 | ||
5292 | else | |
5293 | Error_Msg_N | |
5294 | ("attribute& cannot be set with definition clause", N); | |
5295 | end if; | |
5296 | end CPU; | |
5297 | ||
89cc7147 | 5298 | ---------------------- |
5299 | -- Default_Iterator -- | |
5300 | ---------------------- | |
5301 | ||
5302 | when Attribute_Default_Iterator => Default_Iterator : declare | |
5303 | Func : Entity_Id; | |
fbf4d6ef | 5304 | Typ : Entity_Id; |
89cc7147 | 5305 | |
5306 | begin | |
05f6f999 | 5307 | -- If target type is untagged, further checks are irrelevant |
5308 | ||
89cc7147 | 5309 | if not Is_Tagged_Type (U_Ent) then |
5310 | Error_Msg_N | |
05f6f999 | 5311 | ("aspect Default_Iterator applies to tagged type", Nam); |
5312 | return; | |
89cc7147 | 5313 | end if; |
5314 | ||
5315 | Check_Iterator_Functions; | |
5316 | ||
5317 | Analyze (Expr); | |
5318 | ||
5319 | if not Is_Entity_Name (Expr) | |
5320 | or else Ekind (Entity (Expr)) /= E_Function | |
5321 | then | |
5322 | Error_Msg_N ("aspect Iterator must be a function", Expr); | |
05f6f999 | 5323 | return; |
89cc7147 | 5324 | else |
5325 | Func := Entity (Expr); | |
5326 | end if; | |
5327 | ||
fbf4d6ef | 5328 | -- The type of the first parameter must be T, T'class, or a |
05f6f999 | 5329 | -- corresponding access type (5.5.1 (8/3). If function is |
5330 | -- parameterless label type accordingly. | |
fbf4d6ef | 5331 | |
5332 | if No (First_Formal (Func)) then | |
05f6f999 | 5333 | Typ := Any_Type; |
fbf4d6ef | 5334 | else |
5335 | Typ := Etype (First_Formal (Func)); | |
5336 | end if; | |
5337 | ||
5338 | if Typ = U_Ent | |
5339 | or else Typ = Class_Wide_Type (U_Ent) | |
5340 | or else (Is_Access_Type (Typ) | |
5341 | and then Designated_Type (Typ) = U_Ent) | |
5342 | or else (Is_Access_Type (Typ) | |
5343 | and then Designated_Type (Typ) = | |
5344 | Class_Wide_Type (U_Ent)) | |
89cc7147 | 5345 | then |
fbf4d6ef | 5346 | null; |
5347 | ||
5348 | else | |
89cc7147 | 5349 | Error_Msg_NE |
5350 | ("Default Iterator must be a primitive of&", Func, U_Ent); | |
5351 | end if; | |
5352 | end Default_Iterator; | |
5353 | ||
89f1e35c | 5354 | ------------------------ |
5355 | -- Dispatching_Domain -- | |
5356 | ------------------------ | |
5357 | ||
5358 | when Attribute_Dispatching_Domain => Dispatching_Domain : | |
5359 | begin | |
5360 | -- Dispatching_Domain attribute definition clause not allowed | |
5361 | -- except from aspect specification. | |
5362 | ||
5363 | if From_Aspect_Specification (N) then | |
5364 | if not Is_Task_Type (U_Ent) then | |
fbf4d6ef | 5365 | Error_Msg_N |
5366 | ("Dispatching_Domain can only be defined for task", Nam); | |
89f1e35c | 5367 | |
5368 | elsif Duplicate_Clause then | |
5369 | null; | |
5370 | ||
5371 | else | |
5372 | -- The expression must be analyzed in the special manner | |
5373 | -- described in "Handling of Default and Per-Object | |
5374 | -- Expressions" in sem.ads. | |
5375 | ||
5376 | -- The visibility to the discriminants must be restored | |
5377 | ||
5378 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5379 | ||
5380 | Preanalyze_Spec_Expression | |
5381 | (Expr, RTE (RE_Dispatching_Domain)); | |
5382 | ||
5383 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
5384 | end if; | |
5385 | ||
5386 | else | |
5387 | Error_Msg_N | |
5388 | ("attribute& cannot be set with definition clause", N); | |
5389 | end if; | |
5390 | end Dispatching_Domain; | |
5391 | ||
d6f39728 | 5392 | ------------------ |
5393 | -- External_Tag -- | |
5394 | ------------------ | |
5395 | ||
5396 | when Attribute_External_Tag => External_Tag : | |
5397 | begin | |
5398 | if not Is_Tagged_Type (U_Ent) then | |
5399 | Error_Msg_N ("should be a tagged type", Nam); | |
5400 | end if; | |
5401 | ||
ae888dbd | 5402 | if Duplicate_Clause then |
5403 | null; | |
d6f39728 | 5404 | |
9af0ddc7 | 5405 | else |
ae888dbd | 5406 | Analyze_And_Resolve (Expr, Standard_String); |
fbc67f84 | 5407 | |
cda40848 | 5408 | if not Is_OK_Static_Expression (Expr) then |
ae888dbd | 5409 | Flag_Non_Static_Expr |
5410 | ("static string required for tag name!", Nam); | |
5411 | end if; | |
5412 | ||
ae888dbd | 5413 | if not Is_Library_Level_Entity (U_Ent) then |
5414 | Error_Msg_NE | |
1e3532e7 | 5415 | ("??non-unique external tag supplied for &", N, U_Ent); |
ae888dbd | 5416 | Error_Msg_N |
f74a102b | 5417 | ("\??same external tag applies to all subprogram calls", |
5418 | N); | |
ae888dbd | 5419 | Error_Msg_N |
1e3532e7 | 5420 | ("\??corresponding internal tag cannot be obtained", N); |
ae888dbd | 5421 | end if; |
fbc67f84 | 5422 | end if; |
d6f39728 | 5423 | end External_Tag; |
5424 | ||
b57530b8 | 5425 | -------------------------- |
5426 | -- Implicit_Dereference -- | |
5427 | -------------------------- | |
7947a439 | 5428 | |
b57530b8 | 5429 | when Attribute_Implicit_Dereference => |
7947a439 | 5430 | |
2beb22b1 | 5431 | -- Legality checks already performed at the point of the type |
5432 | -- declaration, aspect is not delayed. | |
7947a439 | 5433 | |
89cc7147 | 5434 | null; |
b57530b8 | 5435 | |
d6f39728 | 5436 | ----------- |
5437 | -- Input -- | |
5438 | ----------- | |
5439 | ||
9f373bb8 | 5440 | when Attribute_Input => |
5441 | Analyze_Stream_TSS_Definition (TSS_Stream_Input); | |
5442 | Set_Has_Specified_Stream_Input (Ent); | |
d6f39728 | 5443 | |
89f1e35c | 5444 | ------------------------ |
5445 | -- Interrupt_Priority -- | |
5446 | ------------------------ | |
5447 | ||
5448 | when Attribute_Interrupt_Priority => Interrupt_Priority : | |
5449 | begin | |
5450 | -- Interrupt_Priority attribute definition clause not allowed | |
5451 | -- except from aspect specification. | |
5452 | ||
5453 | if From_Aspect_Specification (N) then | |
f02a9a9a | 5454 | if not Is_Concurrent_Type (U_Ent) then |
89f1e35c | 5455 | Error_Msg_N |
f74a102b | 5456 | ("Interrupt_Priority can only be defined for task and " |
5457 | & "protected object", Nam); | |
89f1e35c | 5458 | |
5459 | elsif Duplicate_Clause then | |
5460 | null; | |
5461 | ||
5462 | else | |
5463 | -- The expression must be analyzed in the special manner | |
5464 | -- described in "Handling of Default and Per-Object | |
5465 | -- Expressions" in sem.ads. | |
5466 | ||
5467 | -- The visibility to the discriminants must be restored | |
5468 | ||
5469 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5470 | ||
5471 | Preanalyze_Spec_Expression | |
5472 | (Expr, RTE (RE_Interrupt_Priority)); | |
5473 | ||
5474 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
d4e1acfa | 5475 | |
5476 | -- Check the No_Task_At_Interrupt_Priority restriction | |
5477 | ||
5478 | if Is_Task_Type (U_Ent) then | |
5479 | Check_Restriction (No_Task_At_Interrupt_Priority, N); | |
5480 | end if; | |
89f1e35c | 5481 | end if; |
5482 | ||
5483 | else | |
5484 | Error_Msg_N | |
5485 | ("attribute& cannot be set with definition clause", N); | |
5486 | end if; | |
5487 | end Interrupt_Priority; | |
5488 | ||
b3f8228a | 5489 | -------------- |
5490 | -- Iterable -- | |
5491 | -------------- | |
5492 | ||
5493 | when Attribute_Iterable => | |
5494 | Analyze (Expr); | |
bde03454 | 5495 | |
b3f8228a | 5496 | if Nkind (Expr) /= N_Aggregate then |
5497 | Error_Msg_N ("aspect Iterable must be an aggregate", Expr); | |
5498 | end if; | |
5499 | ||
5500 | declare | |
5501 | Assoc : Node_Id; | |
5502 | ||
5503 | begin | |
5504 | Assoc := First (Component_Associations (Expr)); | |
5505 | while Present (Assoc) loop | |
5506 | if not Is_Entity_Name (Expression (Assoc)) then | |
5507 | Error_Msg_N ("value must be a function", Assoc); | |
5508 | end if; | |
bde03454 | 5509 | |
b3f8228a | 5510 | Next (Assoc); |
5511 | end loop; | |
5512 | end; | |
5513 | ||
89cc7147 | 5514 | ---------------------- |
5515 | -- Iterator_Element -- | |
5516 | ---------------------- | |
5517 | ||
5518 | when Attribute_Iterator_Element => | |
5519 | Analyze (Expr); | |
5520 | ||
5521 | if not Is_Entity_Name (Expr) | |
5522 | or else not Is_Type (Entity (Expr)) | |
5523 | then | |
5524 | Error_Msg_N ("aspect Iterator_Element must be a type", Expr); | |
5525 | end if; | |
5526 | ||
d6f39728 | 5527 | ------------------- |
5528 | -- Machine_Radix -- | |
5529 | ------------------- | |
5530 | ||
5531 | -- Machine radix attribute definition clause | |
5532 | ||
5533 | when Attribute_Machine_Radix => Machine_Radix : declare | |
5534 | Radix : constant Uint := Static_Integer (Expr); | |
5535 | ||
5536 | begin | |
5537 | if not Is_Decimal_Fixed_Point_Type (U_Ent) then | |
5538 | Error_Msg_N ("decimal fixed-point type expected for &", Nam); | |
5539 | ||
ae888dbd | 5540 | elsif Duplicate_Clause then |
5541 | null; | |
d6f39728 | 5542 | |
5543 | elsif Radix /= No_Uint then | |
5544 | Set_Has_Machine_Radix_Clause (U_Ent); | |
5545 | Set_Has_Non_Standard_Rep (Base_Type (U_Ent)); | |
5546 | ||
5547 | if Radix = 2 then | |
5548 | null; | |
f74a102b | 5549 | |
d6f39728 | 5550 | elsif Radix = 10 then |
5551 | Set_Machine_Radix_10 (U_Ent); | |
f74a102b | 5552 | |
5553 | -- The following error is suppressed in ASIS mode to allow for | |
f9906591 | 5554 | -- different ASIS back ends or ASIS-based tools to query the |
f74a102b | 5555 | -- illegal clause. |
5556 | ||
5557 | elsif not ASIS_Mode then | |
d6f39728 | 5558 | Error_Msg_N ("machine radix value must be 2 or 10", Expr); |
5559 | end if; | |
5560 | end if; | |
5561 | end Machine_Radix; | |
5562 | ||
5563 | ----------------- | |
5564 | -- Object_Size -- | |
5565 | ----------------- | |
5566 | ||
5567 | -- Object_Size attribute definition clause | |
5568 | ||
5569 | when Attribute_Object_Size => Object_Size : declare | |
bfa5a9d9 | 5570 | Size : constant Uint := Static_Integer (Expr); |
5571 | ||
d6f39728 | 5572 | Biased : Boolean; |
bfa5a9d9 | 5573 | pragma Warnings (Off, Biased); |
d6f39728 | 5574 | |
5575 | begin | |
5576 | if not Is_Type (U_Ent) then | |
5577 | Error_Msg_N ("Object_Size cannot be given for &", Nam); | |
5578 | ||
ae888dbd | 5579 | elsif Duplicate_Clause then |
5580 | null; | |
d6f39728 | 5581 | |
5582 | else | |
5583 | Check_Size (Expr, U_Ent, Size, Biased); | |
5584 | ||
f74a102b | 5585 | -- The following errors are suppressed in ASIS mode to allow |
f9906591 | 5586 | -- for different ASIS back ends or ASIS-based tools to query |
f74a102b | 5587 | -- the illegal clause. |
5588 | ||
5589 | if ASIS_Mode then | |
5590 | null; | |
5591 | ||
5592 | elsif Is_Scalar_Type (U_Ent) then | |
829cd457 | 5593 | if Size /= 8 and then Size /= 16 and then Size /= 32 |
5594 | and then UI_Mod (Size, 64) /= 0 | |
5595 | then | |
5596 | Error_Msg_N | |
5597 | ("Object_Size must be 8, 16, 32, or multiple of 64", | |
5598 | Expr); | |
5599 | end if; | |
5600 | ||
5601 | elsif Size mod 8 /= 0 then | |
5602 | Error_Msg_N ("Object_Size must be a multiple of 8", Expr); | |
d6f39728 | 5603 | end if; |
5604 | ||
5605 | Set_Esize (U_Ent, Size); | |
5606 | Set_Has_Object_Size_Clause (U_Ent); | |
1d366b32 | 5607 | Alignment_Check_For_Size_Change (U_Ent, Size); |
d6f39728 | 5608 | end if; |
5609 | end Object_Size; | |
5610 | ||
5611 | ------------ | |
5612 | -- Output -- | |
5613 | ------------ | |
5614 | ||
9f373bb8 | 5615 | when Attribute_Output => |
5616 | Analyze_Stream_TSS_Definition (TSS_Stream_Output); | |
5617 | Set_Has_Specified_Stream_Output (Ent); | |
d6f39728 | 5618 | |
89f1e35c | 5619 | -------------- |
5620 | -- Priority -- | |
5621 | -------------- | |
5622 | ||
5623 | when Attribute_Priority => Priority : | |
5624 | begin | |
5625 | -- Priority attribute definition clause not allowed except from | |
5626 | -- aspect specification. | |
5627 | ||
5628 | if From_Aspect_Specification (N) then | |
f02a9a9a | 5629 | if not (Is_Concurrent_Type (U_Ent) |
3a72f9c3 | 5630 | or else Ekind (U_Ent) = E_Procedure) |
89f1e35c | 5631 | then |
5632 | Error_Msg_N | |
f02a9a9a | 5633 | ("Priority can only be defined for task and protected " |
5634 | & "object", Nam); | |
89f1e35c | 5635 | |
5636 | elsif Duplicate_Clause then | |
5637 | null; | |
5638 | ||
5639 | else | |
5640 | -- The expression must be analyzed in the special manner | |
5641 | -- described in "Handling of Default and Per-Object | |
5642 | -- Expressions" in sem.ads. | |
5643 | ||
5644 | -- The visibility to the discriminants must be restored | |
5645 | ||
5646 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5647 | Preanalyze_Spec_Expression (Expr, Standard_Integer); | |
5648 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
5649 | ||
cda40848 | 5650 | if not Is_OK_Static_Expression (Expr) then |
89f1e35c | 5651 | Check_Restriction (Static_Priorities, Expr); |
5652 | end if; | |
5653 | end if; | |
5654 | ||
5655 | else | |
5656 | Error_Msg_N | |
5657 | ("attribute& cannot be set with definition clause", N); | |
5658 | end if; | |
5659 | end Priority; | |
5660 | ||
d6f39728 | 5661 | ---------- |
5662 | -- Read -- | |
5663 | ---------- | |
5664 | ||
9f373bb8 | 5665 | when Attribute_Read => |
5666 | Analyze_Stream_TSS_Definition (TSS_Stream_Read); | |
5667 | Set_Has_Specified_Stream_Read (Ent); | |
d6f39728 | 5668 | |
b7b74740 | 5669 | -------------------------- |
5670 | -- Scalar_Storage_Order -- | |
5671 | -------------------------- | |
5672 | ||
5673 | -- Scalar_Storage_Order attribute definition clause | |
5674 | ||
5675 | when Attribute_Scalar_Storage_Order => Scalar_Storage_Order : declare | |
5676 | begin | |
b43a5770 | 5677 | if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then |
b7b74740 | 5678 | Error_Msg_N |
f74a102b | 5679 | ("Scalar_Storage_Order can only be defined for record or " |
5680 | & "array type", Nam); | |
b7b74740 | 5681 | |
5682 | elsif Duplicate_Clause then | |
5683 | null; | |
5684 | ||
5685 | else | |
5686 | Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); | |
5687 | ||
5688 | if Etype (Expr) = Any_Type then | |
5689 | return; | |
5690 | ||
cda40848 | 5691 | elsif not Is_OK_Static_Expression (Expr) then |
b7b74740 | 5692 | Flag_Non_Static_Expr |
5693 | ("Scalar_Storage_Order requires static expression!", Expr); | |
5694 | ||
c0912570 | 5695 | elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then |
5696 | ||
5697 | -- Here for the case of a non-default (i.e. non-confirming) | |
5698 | -- Scalar_Storage_Order attribute definition. | |
5699 | ||
5700 | if Support_Nondefault_SSO_On_Target then | |
d0a9ea3b | 5701 | Set_Reverse_Storage_Order (Base_Type (U_Ent), True); |
c0912570 | 5702 | else |
5703 | Error_Msg_N | |
f74a102b | 5704 | ("non-default Scalar_Storage_Order not supported on " |
5705 | & "target", Expr); | |
b7b74740 | 5706 | end if; |
5707 | end if; | |
b64082f2 | 5708 | |
5709 | -- Clear SSO default indications since explicit setting of the | |
5710 | -- order overrides the defaults. | |
5711 | ||
5712 | Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False); | |
5713 | Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False); | |
b7b74740 | 5714 | end if; |
5715 | end Scalar_Storage_Order; | |
5716 | ||
e6ce0468 | 5717 | -------------------------- |
5718 | -- Secondary_Stack_Size -- | |
5719 | -------------------------- | |
5720 | ||
5721 | when Attribute_Secondary_Stack_Size => Secondary_Stack_Size : | |
5722 | begin | |
5723 | -- Secondary_Stack_Size attribute definition clause not allowed | |
5724 | -- except from aspect specification. | |
5725 | ||
5726 | if From_Aspect_Specification (N) then | |
5727 | if not Is_Task_Type (U_Ent) then | |
fe696bd7 | 5728 | Error_Msg_N |
5729 | ("Secondary Stack Size can only be defined for task", Nam); | |
e6ce0468 | 5730 | |
5731 | elsif Duplicate_Clause then | |
5732 | null; | |
5733 | ||
5734 | else | |
5735 | Check_Restriction (No_Secondary_Stack, Expr); | |
5736 | ||
5737 | -- The expression must be analyzed in the special manner | |
5738 | -- described in "Handling of Default and Per-Object | |
5739 | -- Expressions" in sem.ads. | |
5740 | ||
5741 | -- The visibility to the discriminants must be restored | |
5742 | ||
5743 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5744 | Preanalyze_Spec_Expression (Expr, Any_Integer); | |
5745 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
5746 | ||
5747 | if not Is_OK_Static_Expression (Expr) then | |
5748 | Check_Restriction (Static_Storage_Size, Expr); | |
5749 | end if; | |
5750 | end if; | |
5751 | ||
5752 | else | |
5753 | Error_Msg_N | |
5754 | ("attribute& cannot be set with definition clause", N); | |
5755 | end if; | |
5756 | end Secondary_Stack_Size; | |
5757 | ||
d6f39728 | 5758 | ---------- |
5759 | -- Size -- | |
5760 | ---------- | |
5761 | ||
5762 | -- Size attribute definition clause | |
5763 | ||
5764 | when Attribute_Size => Size : declare | |
5765 | Size : constant Uint := Static_Integer (Expr); | |
5766 | Etyp : Entity_Id; | |
5767 | Biased : Boolean; | |
5768 | ||
5769 | begin | |
5770 | FOnly := True; | |
5771 | ||
ae888dbd | 5772 | if Duplicate_Clause then |
5773 | null; | |
d6f39728 | 5774 | |
5775 | elsif not Is_Type (U_Ent) | |
5776 | and then Ekind (U_Ent) /= E_Variable | |
5777 | and then Ekind (U_Ent) /= E_Constant | |
5778 | then | |
5779 | Error_Msg_N ("size cannot be given for &", Nam); | |
5780 | ||
5781 | elsif Is_Array_Type (U_Ent) | |
5782 | and then not Is_Constrained (U_Ent) | |
5783 | then | |
5784 | Error_Msg_N | |
5785 | ("size cannot be given for unconstrained array", Nam); | |
5786 | ||
c2b89d6e | 5787 | elsif Size /= No_Uint then |
d6f39728 | 5788 | if Is_Type (U_Ent) then |
5789 | Etyp := U_Ent; | |
5790 | else | |
5791 | Etyp := Etype (U_Ent); | |
5792 | end if; | |
5793 | ||
59ac57b5 | 5794 | -- Check size, note that Gigi is in charge of checking that the |
5795 | -- size of an array or record type is OK. Also we do not check | |
5796 | -- the size in the ordinary fixed-point case, since it is too | |
5797 | -- early to do so (there may be subsequent small clause that | |
5798 | -- affects the size). We can check the size if a small clause | |
5799 | -- has already been given. | |
d6f39728 | 5800 | |
5801 | if not Is_Ordinary_Fixed_Point_Type (U_Ent) | |
5802 | or else Has_Small_Clause (U_Ent) | |
5803 | then | |
5804 | Check_Size (Expr, Etyp, Size, Biased); | |
b77e4501 | 5805 | Set_Biased (U_Ent, N, "size clause", Biased); |
d6f39728 | 5806 | end if; |
5807 | ||
5808 | -- For types set RM_Size and Esize if possible | |
5809 | ||
5810 | if Is_Type (U_Ent) then | |
5811 | Set_RM_Size (U_Ent, Size); | |
5812 | ||
ada34def | 5813 | -- For elementary types, increase Object_Size to power of 2, |
5814 | -- but not less than a storage unit in any case (normally | |
59ac57b5 | 5815 | -- this means it will be byte addressable). |
d6f39728 | 5816 | |
ada34def | 5817 | -- For all other types, nothing else to do, we leave Esize |
5818 | -- (object size) unset, the back end will set it from the | |
5819 | -- size and alignment in an appropriate manner. | |
5820 | ||
1d366b32 | 5821 | -- In both cases, we check whether the alignment must be |
5822 | -- reset in the wake of the size change. | |
5823 | ||
ada34def | 5824 | if Is_Elementary_Type (U_Ent) then |
f15731c4 | 5825 | if Size <= System_Storage_Unit then |
5826 | Init_Esize (U_Ent, System_Storage_Unit); | |
d6f39728 | 5827 | elsif Size <= 16 then |
5828 | Init_Esize (U_Ent, 16); | |
5829 | elsif Size <= 32 then | |
5830 | Init_Esize (U_Ent, 32); | |
5831 | else | |
5832 | Set_Esize (U_Ent, (Size + 63) / 64 * 64); | |
5833 | end if; | |
5834 | ||
1d366b32 | 5835 | Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent)); |
5836 | else | |
5837 | Alignment_Check_For_Size_Change (U_Ent, Size); | |
d6f39728 | 5838 | end if; |
5839 | ||
d6f39728 | 5840 | -- For objects, set Esize only |
5841 | ||
5842 | else | |
f74a102b | 5843 | -- The following error is suppressed in ASIS mode to allow |
f9906591 | 5844 | -- for different ASIS back ends or ASIS-based tools to query |
f74a102b | 5845 | -- the illegal clause. |
5846 | ||
5847 | if Is_Elementary_Type (Etyp) | |
5848 | and then Size /= System_Storage_Unit | |
5849 | and then Size /= System_Storage_Unit * 2 | |
5850 | and then Size /= System_Storage_Unit * 4 | |
5851 | and then Size /= System_Storage_Unit * 8 | |
5852 | and then not ASIS_Mode | |
5853 | then | |
5854 | Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); | |
5855 | Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8; | |
5856 | Error_Msg_N | |
5857 | ("size for primitive object must be a power of 2 in " | |
5858 | & "the range ^-^", N); | |
9dfe12ae | 5859 | end if; |
5860 | ||
d6f39728 | 5861 | Set_Esize (U_Ent, Size); |
5862 | end if; | |
5863 | ||
5864 | Set_Has_Size_Clause (U_Ent); | |
5865 | end if; | |
5866 | end Size; | |
5867 | ||
5868 | ----------- | |
5869 | -- Small -- | |
5870 | ----------- | |
5871 | ||
5872 | -- Small attribute definition clause | |
5873 | ||
5874 | when Attribute_Small => Small : declare | |
5875 | Implicit_Base : constant Entity_Id := Base_Type (U_Ent); | |
5876 | Small : Ureal; | |
5877 | ||
5878 | begin | |
5879 | Analyze_And_Resolve (Expr, Any_Real); | |
5880 | ||
5881 | if Etype (Expr) = Any_Type then | |
5882 | return; | |
5883 | ||
cda40848 | 5884 | elsif not Is_OK_Static_Expression (Expr) then |
9dfe12ae | 5885 | Flag_Non_Static_Expr |
5886 | ("small requires static expression!", Expr); | |
d6f39728 | 5887 | return; |
5888 | ||
5889 | else | |
5890 | Small := Expr_Value_R (Expr); | |
5891 | ||
5892 | if Small <= Ureal_0 then | |
5893 | Error_Msg_N ("small value must be greater than zero", Expr); | |
5894 | return; | |
5895 | end if; | |
5896 | ||
5897 | end if; | |
5898 | ||
5899 | if not Is_Ordinary_Fixed_Point_Type (U_Ent) then | |
5900 | Error_Msg_N | |
5901 | ("small requires an ordinary fixed point type", Nam); | |
5902 | ||
5903 | elsif Has_Small_Clause (U_Ent) then | |
5904 | Error_Msg_N ("small already given for &", Nam); | |
5905 | ||
5906 | elsif Small > Delta_Value (U_Ent) then | |
5907 | Error_Msg_N | |
ce3e25d6 | 5908 | ("small value must not be greater than delta value", Nam); |
d6f39728 | 5909 | |
5910 | else | |
5911 | Set_Small_Value (U_Ent, Small); | |
5912 | Set_Small_Value (Implicit_Base, Small); | |
5913 | Set_Has_Small_Clause (U_Ent); | |
5914 | Set_Has_Small_Clause (Implicit_Base); | |
5915 | Set_Has_Non_Standard_Rep (Implicit_Base); | |
5916 | end if; | |
5917 | end Small; | |
5918 | ||
d6f39728 | 5919 | ------------------ |
5920 | -- Storage_Pool -- | |
5921 | ------------------ | |
5922 | ||
5923 | -- Storage_Pool attribute definition clause | |
5924 | ||
b55f7641 | 5925 | when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool => declare |
d6f39728 | 5926 | Pool : Entity_Id; |
6b567c71 | 5927 | T : Entity_Id; |
d6f39728 | 5928 | |
5929 | begin | |
44e4341e | 5930 | if Ekind (U_Ent) = E_Access_Subprogram_Type then |
5931 | Error_Msg_N | |
5932 | ("storage pool cannot be given for access-to-subprogram type", | |
5933 | Nam); | |
5934 | return; | |
5935 | ||
d3ef794c | 5936 | elsif not |
5937 | Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type) | |
d6f39728 | 5938 | then |
44e4341e | 5939 | Error_Msg_N |
5940 | ("storage pool can only be given for access types", Nam); | |
d6f39728 | 5941 | return; |
5942 | ||
5943 | elsif Is_Derived_Type (U_Ent) then | |
5944 | Error_Msg_N | |
5945 | ("storage pool cannot be given for a derived access type", | |
5946 | Nam); | |
5947 | ||
ae888dbd | 5948 | elsif Duplicate_Clause then |
d6f39728 | 5949 | return; |
5950 | ||
5951 | elsif Present (Associated_Storage_Pool (U_Ent)) then | |
5952 | Error_Msg_N ("storage pool already given for &", Nam); | |
5953 | return; | |
5954 | end if; | |
5955 | ||
6653b695 | 5956 | -- Check for Storage_Size previously given |
5957 | ||
5958 | declare | |
5959 | SS : constant Node_Id := | |
5960 | Get_Attribute_Definition_Clause | |
5961 | (U_Ent, Attribute_Storage_Size); | |
5962 | begin | |
5963 | if Present (SS) then | |
5964 | Check_Pool_Size_Clash (U_Ent, N, SS); | |
5965 | end if; | |
5966 | end; | |
5967 | ||
5968 | -- Storage_Pool case | |
5969 | ||
b55f7641 | 5970 | if Id = Attribute_Storage_Pool then |
5971 | Analyze_And_Resolve | |
5972 | (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool))); | |
5973 | ||
5974 | -- In the Simple_Storage_Pool case, we allow a variable of any | |
b15003c3 | 5975 | -- simple storage pool type, so we Resolve without imposing an |
b55f7641 | 5976 | -- expected type. |
5977 | ||
5978 | else | |
5979 | Analyze_And_Resolve (Expr); | |
5980 | ||
5981 | if not Present (Get_Rep_Pragma | |
b15003c3 | 5982 | (Etype (Expr), Name_Simple_Storage_Pool_Type)) |
b55f7641 | 5983 | then |
5984 | Error_Msg_N | |
5985 | ("expression must be of a simple storage pool type", Expr); | |
5986 | end if; | |
5987 | end if; | |
d6f39728 | 5988 | |
8c5c7277 | 5989 | if not Denotes_Variable (Expr) then |
5990 | Error_Msg_N ("storage pool must be a variable", Expr); | |
5991 | return; | |
5992 | end if; | |
5993 | ||
6b567c71 | 5994 | if Nkind (Expr) = N_Type_Conversion then |
5995 | T := Etype (Expression (Expr)); | |
5996 | else | |
5997 | T := Etype (Expr); | |
5998 | end if; | |
5999 | ||
6000 | -- The Stack_Bounded_Pool is used internally for implementing | |
d64221a7 | 6001 | -- access types with a Storage_Size. Since it only work properly |
6002 | -- when used on one specific type, we need to check that it is not | |
6003 | -- hijacked improperly: | |
6004 | ||
6b567c71 | 6005 | -- type T is access Integer; |
6006 | -- for T'Storage_Size use n; | |
6007 | -- type Q is access Float; | |
6008 | -- for Q'Storage_Size use T'Storage_Size; -- incorrect | |
6009 | ||
15ebb600 | 6010 | if RTE_Available (RE_Stack_Bounded_Pool) |
6011 | and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool) | |
6012 | then | |
6013 | Error_Msg_N ("non-shareable internal Pool", Expr); | |
6b567c71 | 6014 | return; |
6015 | end if; | |
6016 | ||
d6f39728 | 6017 | -- If the argument is a name that is not an entity name, then |
6018 | -- we construct a renaming operation to define an entity of | |
6019 | -- type storage pool. | |
6020 | ||
6021 | if not Is_Entity_Name (Expr) | |
6022 | and then Is_Object_Reference (Expr) | |
6023 | then | |
11deeeb6 | 6024 | Pool := Make_Temporary (Loc, 'P', Expr); |
d6f39728 | 6025 | |
6026 | declare | |
6027 | Rnode : constant Node_Id := | |
6028 | Make_Object_Renaming_Declaration (Loc, | |
6029 | Defining_Identifier => Pool, | |
6030 | Subtype_Mark => | |
6031 | New_Occurrence_Of (Etype (Expr), Loc), | |
11deeeb6 | 6032 | Name => Expr); |
d6f39728 | 6033 | |
6034 | begin | |
f65f7fdf | 6035 | -- If the attribute definition clause comes from an aspect |
6036 | -- clause, then insert the renaming before the associated | |
6037 | -- entity's declaration, since the attribute clause has | |
6038 | -- not yet been appended to the declaration list. | |
6039 | ||
6040 | if From_Aspect_Specification (N) then | |
6041 | Insert_Before (Parent (Entity (N)), Rnode); | |
6042 | else | |
6043 | Insert_Before (N, Rnode); | |
6044 | end if; | |
6045 | ||
d6f39728 | 6046 | Analyze (Rnode); |
6047 | Set_Associated_Storage_Pool (U_Ent, Pool); | |
6048 | end; | |
6049 | ||
6050 | elsif Is_Entity_Name (Expr) then | |
6051 | Pool := Entity (Expr); | |
6052 | ||
6053 | -- If pool is a renamed object, get original one. This can | |
6054 | -- happen with an explicit renaming, and within instances. | |
6055 | ||
6056 | while Present (Renamed_Object (Pool)) | |
6057 | and then Is_Entity_Name (Renamed_Object (Pool)) | |
6058 | loop | |
6059 | Pool := Entity (Renamed_Object (Pool)); | |
6060 | end loop; | |
6061 | ||
6062 | if Present (Renamed_Object (Pool)) | |
6063 | and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion | |
6064 | and then Is_Entity_Name (Expression (Renamed_Object (Pool))) | |
6065 | then | |
6066 | Pool := Entity (Expression (Renamed_Object (Pool))); | |
6067 | end if; | |
6068 | ||
6b567c71 | 6069 | Set_Associated_Storage_Pool (U_Ent, Pool); |
d6f39728 | 6070 | |
6071 | elsif Nkind (Expr) = N_Type_Conversion | |
6072 | and then Is_Entity_Name (Expression (Expr)) | |
6073 | and then Nkind (Original_Node (Expr)) = N_Attribute_Reference | |
6074 | then | |
6075 | Pool := Entity (Expression (Expr)); | |
6b567c71 | 6076 | Set_Associated_Storage_Pool (U_Ent, Pool); |
d6f39728 | 6077 | |
6078 | else | |
6079 | Error_Msg_N ("incorrect reference to a Storage Pool", Expr); | |
6080 | return; | |
6081 | end if; | |
b55f7641 | 6082 | end; |
d6f39728 | 6083 | |
44e4341e | 6084 | ------------------ |
6085 | -- Storage_Size -- | |
6086 | ------------------ | |
6087 | ||
6088 | -- Storage_Size attribute definition clause | |
6089 | ||
6090 | when Attribute_Storage_Size => Storage_Size : declare | |
6091 | Btype : constant Entity_Id := Base_Type (U_Ent); | |
44e4341e | 6092 | |
6093 | begin | |
6094 | if Is_Task_Type (U_Ent) then | |
44e4341e | 6095 | |
39a0c1d3 | 6096 | -- Check obsolescent (but never obsolescent if from aspect) |
ceec4f7c | 6097 | |
6098 | if not From_Aspect_Specification (N) then | |
6099 | Check_Restriction (No_Obsolescent_Features, N); | |
6100 | ||
6101 | if Warn_On_Obsolescent_Feature then | |
6102 | Error_Msg_N | |
f74a102b | 6103 | ("?j?storage size clause for task is an obsolescent " |
6104 | & "feature (RM J.9)", N); | |
ceec4f7c | 6105 | Error_Msg_N ("\?j?use Storage_Size pragma instead", N); |
6106 | end if; | |
44e4341e | 6107 | end if; |
6108 | ||
6109 | FOnly := True; | |
6110 | end if; | |
6111 | ||
6112 | if not Is_Access_Type (U_Ent) | |
6113 | and then Ekind (U_Ent) /= E_Task_Type | |
6114 | then | |
6115 | Error_Msg_N ("storage size cannot be given for &", Nam); | |
6116 | ||
6117 | elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then | |
6118 | Error_Msg_N | |
6119 | ("storage size cannot be given for a derived access type", | |
6120 | Nam); | |
6121 | ||
ae888dbd | 6122 | elsif Duplicate_Clause then |
6123 | null; | |
44e4341e | 6124 | |
6125 | else | |
6126 | Analyze_And_Resolve (Expr, Any_Integer); | |
6127 | ||
6128 | if Is_Access_Type (U_Ent) then | |
6653b695 | 6129 | |
6130 | -- Check for Storage_Pool previously given | |
6131 | ||
6132 | declare | |
6133 | SP : constant Node_Id := | |
6134 | Get_Attribute_Definition_Clause | |
6135 | (U_Ent, Attribute_Storage_Pool); | |
6136 | ||
6137 | begin | |
6138 | if Present (SP) then | |
6139 | Check_Pool_Size_Clash (U_Ent, SP, N); | |
6140 | end if; | |
6141 | end; | |
6142 | ||
6143 | -- Special case of for x'Storage_Size use 0 | |
44e4341e | 6144 | |
5941a4e9 | 6145 | if Is_OK_Static_Expression (Expr) |
44e4341e | 6146 | and then Expr_Value (Expr) = 0 |
6147 | then | |
6148 | Set_No_Pool_Assigned (Btype); | |
6149 | end if; | |
44e4341e | 6150 | end if; |
6151 | ||
6152 | Set_Has_Storage_Size_Clause (Btype); | |
6153 | end if; | |
6154 | end Storage_Size; | |
6155 | ||
7189d17f | 6156 | ----------------- |
6157 | -- Stream_Size -- | |
6158 | ----------------- | |
6159 | ||
6160 | when Attribute_Stream_Size => Stream_Size : declare | |
6161 | Size : constant Uint := Static_Integer (Expr); | |
6162 | ||
6163 | begin | |
15ebb600 | 6164 | if Ada_Version <= Ada_95 then |
6165 | Check_Restriction (No_Implementation_Attributes, N); | |
6166 | end if; | |
6167 | ||
ae888dbd | 6168 | if Duplicate_Clause then |
6169 | null; | |
7189d17f | 6170 | |
6171 | elsif Is_Elementary_Type (U_Ent) then | |
f74a102b | 6172 | |
6173 | -- The following errors are suppressed in ASIS mode to allow | |
f9906591 | 6174 | -- for different ASIS back ends or ASIS-based tools to query |
f74a102b | 6175 | -- the illegal clause. |
6176 | ||
6177 | if ASIS_Mode then | |
6178 | null; | |
6179 | ||
6180 | elsif Size /= System_Storage_Unit | |
6181 | and then Size /= System_Storage_Unit * 2 | |
6182 | and then Size /= System_Storage_Unit * 4 | |
6183 | and then Size /= System_Storage_Unit * 8 | |
7189d17f | 6184 | then |
6185 | Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); | |
6186 | Error_Msg_N | |
f74a102b | 6187 | ("stream size for elementary type must be a power of 2 " |
6188 | & "and at least ^", N); | |
7189d17f | 6189 | |
6190 | elsif RM_Size (U_Ent) > Size then | |
6191 | Error_Msg_Uint_1 := RM_Size (U_Ent); | |
6192 | Error_Msg_N | |
f74a102b | 6193 | ("stream size for elementary type must be a power of 2 " |
6194 | & "and at least ^", N); | |
7189d17f | 6195 | end if; |
6196 | ||
6197 | Set_Has_Stream_Size_Clause (U_Ent); | |
6198 | ||
6199 | else | |
6200 | Error_Msg_N ("Stream_Size cannot be given for &", Nam); | |
6201 | end if; | |
6202 | end Stream_Size; | |
6203 | ||
d6f39728 | 6204 | ---------------- |
6205 | -- Value_Size -- | |
6206 | ---------------- | |
6207 | ||
6208 | -- Value_Size attribute definition clause | |
6209 | ||
6210 | when Attribute_Value_Size => Value_Size : declare | |
6211 | Size : constant Uint := Static_Integer (Expr); | |
6212 | Biased : Boolean; | |
6213 | ||
6214 | begin | |
6215 | if not Is_Type (U_Ent) then | |
6216 | Error_Msg_N ("Value_Size cannot be given for &", Nam); | |
6217 | ||
ae888dbd | 6218 | elsif Duplicate_Clause then |
6219 | null; | |
d6f39728 | 6220 | |
59ac57b5 | 6221 | elsif Is_Array_Type (U_Ent) |
6222 | and then not Is_Constrained (U_Ent) | |
6223 | then | |
6224 | Error_Msg_N | |
6225 | ("Value_Size cannot be given for unconstrained array", Nam); | |
6226 | ||
d6f39728 | 6227 | else |
6228 | if Is_Elementary_Type (U_Ent) then | |
6229 | Check_Size (Expr, U_Ent, Size, Biased); | |
b77e4501 | 6230 | Set_Biased (U_Ent, N, "value size clause", Biased); |
d6f39728 | 6231 | end if; |
6232 | ||
6233 | Set_RM_Size (U_Ent, Size); | |
6234 | end if; | |
6235 | end Value_Size; | |
6236 | ||
81b424ac | 6237 | ----------------------- |
6238 | -- Variable_Indexing -- | |
6239 | ----------------------- | |
6240 | ||
6241 | when Attribute_Variable_Indexing => | |
6242 | Check_Indexing_Functions; | |
6243 | ||
d6f39728 | 6244 | ----------- |
6245 | -- Write -- | |
6246 | ----------- | |
6247 | ||
9f373bb8 | 6248 | when Attribute_Write => |
6249 | Analyze_Stream_TSS_Definition (TSS_Stream_Write); | |
6250 | Set_Has_Specified_Stream_Write (Ent); | |
d6f39728 | 6251 | |
6252 | -- All other attributes cannot be set | |
6253 | ||
6254 | when others => | |
6255 | Error_Msg_N | |
6256 | ("attribute& cannot be set with definition clause", N); | |
d6f39728 | 6257 | end case; |
6258 | ||
d64221a7 | 6259 | -- The test for the type being frozen must be performed after any |
6260 | -- expression the clause has been analyzed since the expression itself | |
6261 | -- might cause freezing that makes the clause illegal. | |
d6f39728 | 6262 | |
6263 | if Rep_Item_Too_Late (U_Ent, N, FOnly) then | |
6264 | return; | |
6265 | end if; | |
6266 | end Analyze_Attribute_Definition_Clause; | |
6267 | ||
6268 | ---------------------------- | |
6269 | -- Analyze_Code_Statement -- | |
6270 | ---------------------------- | |
6271 | ||
6272 | procedure Analyze_Code_Statement (N : Node_Id) is | |
6273 | HSS : constant Node_Id := Parent (N); | |
6274 | SBody : constant Node_Id := Parent (HSS); | |
6275 | Subp : constant Entity_Id := Current_Scope; | |
6276 | Stmt : Node_Id; | |
6277 | Decl : Node_Id; | |
6278 | StmtO : Node_Id; | |
6279 | DeclO : Node_Id; | |
6280 | ||
6281 | begin | |
1d3f0c6b | 6282 | -- Accept foreign code statements for CodePeer. The analysis is skipped |
6283 | -- to avoid rejecting unrecognized constructs. | |
6284 | ||
6285 | if CodePeer_Mode then | |
6286 | Set_Analyzed (N); | |
6287 | return; | |
6288 | end if; | |
6289 | ||
d6f39728 | 6290 | -- Analyze and check we get right type, note that this implements the |
1d3f0c6b | 6291 | -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is |
6292 | -- the only way that Asm_Insn could possibly be visible. | |
d6f39728 | 6293 | |
6294 | Analyze_And_Resolve (Expression (N)); | |
6295 | ||
6296 | if Etype (Expression (N)) = Any_Type then | |
6297 | return; | |
6298 | elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then | |
6299 | Error_Msg_N ("incorrect type for code statement", N); | |
6300 | return; | |
6301 | end if; | |
6302 | ||
44e4341e | 6303 | Check_Code_Statement (N); |
6304 | ||
1d3f0c6b | 6305 | -- Make sure we appear in the handled statement sequence of a subprogram |
6306 | -- (RM 13.8(3)). | |
d6f39728 | 6307 | |
6308 | if Nkind (HSS) /= N_Handled_Sequence_Of_Statements | |
6309 | or else Nkind (SBody) /= N_Subprogram_Body | |
6310 | then | |
6311 | Error_Msg_N | |
6312 | ("code statement can only appear in body of subprogram", N); | |
6313 | return; | |
6314 | end if; | |
6315 | ||
6316 | -- Do remaining checks (RM 13.8(3)) if not already done | |
6317 | ||
6318 | if not Is_Machine_Code_Subprogram (Subp) then | |
6319 | Set_Is_Machine_Code_Subprogram (Subp); | |
6320 | ||
6321 | -- No exception handlers allowed | |
6322 | ||
6323 | if Present (Exception_Handlers (HSS)) then | |
6324 | Error_Msg_N | |
6325 | ("exception handlers not permitted in machine code subprogram", | |
6326 | First (Exception_Handlers (HSS))); | |
6327 | end if; | |
6328 | ||
6329 | -- No declarations other than use clauses and pragmas (we allow | |
6330 | -- certain internally generated declarations as well). | |
6331 | ||
6332 | Decl := First (Declarations (SBody)); | |
6333 | while Present (Decl) loop | |
6334 | DeclO := Original_Node (Decl); | |
6335 | if Comes_From_Source (DeclO) | |
fdd294d1 | 6336 | and not Nkind_In (DeclO, N_Pragma, |
6337 | N_Use_Package_Clause, | |
6338 | N_Use_Type_Clause, | |
6339 | N_Implicit_Label_Declaration) | |
d6f39728 | 6340 | then |
6341 | Error_Msg_N | |
6342 | ("this declaration not allowed in machine code subprogram", | |
6343 | DeclO); | |
6344 | end if; | |
6345 | ||
6346 | Next (Decl); | |
6347 | end loop; | |
6348 | ||
6349 | -- No statements other than code statements, pragmas, and labels. | |
6350 | -- Again we allow certain internally generated statements. | |
3ab42ff7 | 6351 | |
c3107527 | 6352 | -- In Ada 2012, qualified expressions are names, and the code |
6353 | -- statement is initially parsed as a procedure call. | |
d6f39728 | 6354 | |
6355 | Stmt := First (Statements (HSS)); | |
6356 | while Present (Stmt) loop | |
6357 | StmtO := Original_Node (Stmt); | |
c3107527 | 6358 | |
1d3f0c6b | 6359 | -- A procedure call transformed into a code statement is OK |
59f2fcab | 6360 | |
c3107527 | 6361 | if Ada_Version >= Ada_2012 |
6362 | and then Nkind (StmtO) = N_Procedure_Call_Statement | |
59f2fcab | 6363 | and then Nkind (Name (StmtO)) = N_Qualified_Expression |
c3107527 | 6364 | then |
6365 | null; | |
6366 | ||
6367 | elsif Comes_From_Source (StmtO) | |
fdd294d1 | 6368 | and then not Nkind_In (StmtO, N_Pragma, |
6369 | N_Label, | |
6370 | N_Code_Statement) | |
d6f39728 | 6371 | then |
6372 | Error_Msg_N | |
6373 | ("this statement is not allowed in machine code subprogram", | |
6374 | StmtO); | |
6375 | end if; | |
6376 | ||
6377 | Next (Stmt); | |
6378 | end loop; | |
6379 | end if; | |
d6f39728 | 6380 | end Analyze_Code_Statement; |
6381 | ||
6382 | ----------------------------------------------- | |
6383 | -- Analyze_Enumeration_Representation_Clause -- | |
6384 | ----------------------------------------------- | |
6385 | ||
6386 | procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is | |
21647c2d | 6387 | Ident : constant Node_Id := Identifier (N); |
6388 | Aggr : constant Node_Id := Array_Aggregate (N); | |
d6f39728 | 6389 | Enumtype : Entity_Id; |
6390 | Elit : Entity_Id; | |
6391 | Expr : Node_Id; | |
6392 | Assoc : Node_Id; | |
6393 | Choice : Node_Id; | |
6394 | Val : Uint; | |
b3190af0 | 6395 | |
6396 | Err : Boolean := False; | |
098d3082 | 6397 | -- Set True to avoid cascade errors and crashes on incorrect source code |
d6f39728 | 6398 | |
e30c7d84 | 6399 | Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer)); |
6400 | Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer)); | |
6401 | -- Allowed range of universal integer (= allowed range of enum lit vals) | |
6402 | ||
d6f39728 | 6403 | Min : Uint; |
6404 | Max : Uint; | |
e30c7d84 | 6405 | -- Minimum and maximum values of entries |
6406 | ||
6407 | Max_Node : Node_Id; | |
6408 | -- Pointer to node for literal providing max value | |
d6f39728 | 6409 | |
6410 | begin | |
ca301e17 | 6411 | if Ignore_Rep_Clauses then |
2ff55065 | 6412 | Kill_Rep_Clause (N); |
fbc67f84 | 6413 | return; |
6414 | end if; | |
6415 | ||
175a6969 | 6416 | -- Ignore enumeration rep clauses by default in CodePeer mode, |
6417 | -- unless -gnatd.I is specified, as a work around for potential false | |
6418 | -- positive messages. | |
6419 | ||
6420 | if CodePeer_Mode and not Debug_Flag_Dot_II then | |
6421 | return; | |
6422 | end if; | |
6423 | ||
d6f39728 | 6424 | -- First some basic error checks |
6425 | ||
6426 | Find_Type (Ident); | |
6427 | Enumtype := Entity (Ident); | |
6428 | ||
6429 | if Enumtype = Any_Type | |
6430 | or else Rep_Item_Too_Early (Enumtype, N) | |
6431 | then | |
6432 | return; | |
6433 | else | |
6434 | Enumtype := Underlying_Type (Enumtype); | |
6435 | end if; | |
6436 | ||
6437 | if not Is_Enumeration_Type (Enumtype) then | |
6438 | Error_Msg_NE | |
6439 | ("enumeration type required, found}", | |
6440 | Ident, First_Subtype (Enumtype)); | |
6441 | return; | |
6442 | end if; | |
6443 | ||
9dfe12ae | 6444 | -- Ignore rep clause on generic actual type. This will already have |
6445 | -- been flagged on the template as an error, and this is the safest | |
6446 | -- way to ensure we don't get a junk cascaded message in the instance. | |
6447 | ||
6448 | if Is_Generic_Actual_Type (Enumtype) then | |
6449 | return; | |
6450 | ||
6451 | -- Type must be in current scope | |
6452 | ||
6453 | elsif Scope (Enumtype) /= Current_Scope then | |
d6f39728 | 6454 | Error_Msg_N ("type must be declared in this scope", Ident); |
6455 | return; | |
6456 | ||
9dfe12ae | 6457 | -- Type must be a first subtype |
6458 | ||
d6f39728 | 6459 | elsif not Is_First_Subtype (Enumtype) then |
6460 | Error_Msg_N ("cannot give enumeration rep clause for subtype", N); | |
6461 | return; | |
6462 | ||
9dfe12ae | 6463 | -- Ignore duplicate rep clause |
6464 | ||
d6f39728 | 6465 | elsif Has_Enumeration_Rep_Clause (Enumtype) then |
6466 | Error_Msg_N ("duplicate enumeration rep clause ignored", N); | |
6467 | return; | |
6468 | ||
7189d17f | 6469 | -- Don't allow rep clause for standard [wide_[wide_]]character |
9dfe12ae | 6470 | |
177675a7 | 6471 | elsif Is_Standard_Character_Type (Enumtype) then |
d6f39728 | 6472 | Error_Msg_N ("enumeration rep clause not allowed for this type", N); |
9dfe12ae | 6473 | return; |
6474 | ||
d9125581 | 6475 | -- Check that the expression is a proper aggregate (no parentheses) |
6476 | ||
6477 | elsif Paren_Count (Aggr) /= 0 then | |
6478 | Error_Msg | |
6479 | ("extra parentheses surrounding aggregate not allowed", | |
6480 | First_Sloc (Aggr)); | |
6481 | return; | |
6482 | ||
9dfe12ae | 6483 | -- All tests passed, so set rep clause in place |
d6f39728 | 6484 | |
6485 | else | |
6486 | Set_Has_Enumeration_Rep_Clause (Enumtype); | |
6487 | Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype)); | |
6488 | end if; | |
6489 | ||
6490 | -- Now we process the aggregate. Note that we don't use the normal | |
6491 | -- aggregate code for this purpose, because we don't want any of the | |
6492 | -- normal expansion activities, and a number of special semantic | |
6493 | -- rules apply (including the component type being any integer type) | |
6494 | ||
d6f39728 | 6495 | Elit := First_Literal (Enumtype); |
6496 | ||
6497 | -- First the positional entries if any | |
6498 | ||
6499 | if Present (Expressions (Aggr)) then | |
6500 | Expr := First (Expressions (Aggr)); | |
6501 | while Present (Expr) loop | |
6502 | if No (Elit) then | |
6503 | Error_Msg_N ("too many entries in aggregate", Expr); | |
6504 | return; | |
6505 | end if; | |
6506 | ||
6507 | Val := Static_Integer (Expr); | |
6508 | ||
d9125581 | 6509 | -- Err signals that we found some incorrect entries processing |
6510 | -- the list. The final checks for completeness and ordering are | |
6511 | -- skipped in this case. | |
6512 | ||
d6f39728 | 6513 | if Val = No_Uint then |
6514 | Err := True; | |
f02a9a9a | 6515 | |
d6f39728 | 6516 | elsif Val < Lo or else Hi < Val then |
6517 | Error_Msg_N ("value outside permitted range", Expr); | |
6518 | Err := True; | |
6519 | end if; | |
6520 | ||
6521 | Set_Enumeration_Rep (Elit, Val); | |
6522 | Set_Enumeration_Rep_Expr (Elit, Expr); | |
6523 | Next (Expr); | |
6524 | Next (Elit); | |
6525 | end loop; | |
6526 | end if; | |
6527 | ||
6528 | -- Now process the named entries if present | |
6529 | ||
6530 | if Present (Component_Associations (Aggr)) then | |
6531 | Assoc := First (Component_Associations (Aggr)); | |
6532 | while Present (Assoc) loop | |
6533 | Choice := First (Choices (Assoc)); | |
6534 | ||
6535 | if Present (Next (Choice)) then | |
6536 | Error_Msg_N | |
6537 | ("multiple choice not allowed here", Next (Choice)); | |
6538 | Err := True; | |
6539 | end if; | |
6540 | ||
6541 | if Nkind (Choice) = N_Others_Choice then | |
6542 | Error_Msg_N ("others choice not allowed here", Choice); | |
6543 | Err := True; | |
6544 | ||
6545 | elsif Nkind (Choice) = N_Range then | |
b3190af0 | 6546 | |
d6f39728 | 6547 | -- ??? should allow zero/one element range here |
b3190af0 | 6548 | |
d6f39728 | 6549 | Error_Msg_N ("range not allowed here", Choice); |
6550 | Err := True; | |
6551 | ||
6552 | else | |
6553 | Analyze_And_Resolve (Choice, Enumtype); | |
b3190af0 | 6554 | |
098d3082 | 6555 | if Error_Posted (Choice) then |
d6f39728 | 6556 | Err := True; |
098d3082 | 6557 | end if; |
d6f39728 | 6558 | |
098d3082 | 6559 | if not Err then |
6560 | if Is_Entity_Name (Choice) | |
6561 | and then Is_Type (Entity (Choice)) | |
6562 | then | |
6563 | Error_Msg_N ("subtype name not allowed here", Choice); | |
d6f39728 | 6564 | Err := True; |
b3190af0 | 6565 | |
098d3082 | 6566 | -- ??? should allow static subtype with zero/one entry |
d6f39728 | 6567 | |
098d3082 | 6568 | elsif Etype (Choice) = Base_Type (Enumtype) then |
cda40848 | 6569 | if not Is_OK_Static_Expression (Choice) then |
098d3082 | 6570 | Flag_Non_Static_Expr |
6571 | ("non-static expression used for choice!", Choice); | |
d6f39728 | 6572 | Err := True; |
d6f39728 | 6573 | |
098d3082 | 6574 | else |
6575 | Elit := Expr_Value_E (Choice); | |
6576 | ||
6577 | if Present (Enumeration_Rep_Expr (Elit)) then | |
6578 | Error_Msg_Sloc := | |
6579 | Sloc (Enumeration_Rep_Expr (Elit)); | |
6580 | Error_Msg_NE | |
6581 | ("representation for& previously given#", | |
6582 | Choice, Elit); | |
6583 | Err := True; | |
6584 | end if; | |
d6f39728 | 6585 | |
098d3082 | 6586 | Set_Enumeration_Rep_Expr (Elit, Expression (Assoc)); |
d6f39728 | 6587 | |
098d3082 | 6588 | Expr := Expression (Assoc); |
6589 | Val := Static_Integer (Expr); | |
d6f39728 | 6590 | |
098d3082 | 6591 | if Val = No_Uint then |
6592 | Err := True; | |
6593 | ||
6594 | elsif Val < Lo or else Hi < Val then | |
6595 | Error_Msg_N ("value outside permitted range", Expr); | |
6596 | Err := True; | |
6597 | end if; | |
d6f39728 | 6598 | |
098d3082 | 6599 | Set_Enumeration_Rep (Elit, Val); |
6600 | end if; | |
d6f39728 | 6601 | end if; |
6602 | end if; | |
6603 | end if; | |
6604 | ||
6605 | Next (Assoc); | |
6606 | end loop; | |
6607 | end if; | |
6608 | ||
6609 | -- Aggregate is fully processed. Now we check that a full set of | |
6610 | -- representations was given, and that they are in range and in order. | |
6611 | -- These checks are only done if no other errors occurred. | |
6612 | ||
6613 | if not Err then | |
6614 | Min := No_Uint; | |
6615 | Max := No_Uint; | |
6616 | ||
6617 | Elit := First_Literal (Enumtype); | |
6618 | while Present (Elit) loop | |
6619 | if No (Enumeration_Rep_Expr (Elit)) then | |
6620 | Error_Msg_NE ("missing representation for&!", N, Elit); | |
6621 | ||
6622 | else | |
6623 | Val := Enumeration_Rep (Elit); | |
6624 | ||
6625 | if Min = No_Uint then | |
6626 | Min := Val; | |
6627 | end if; | |
6628 | ||
6629 | if Val /= No_Uint then | |
6630 | if Max /= No_Uint and then Val <= Max then | |
6631 | Error_Msg_NE | |
6632 | ("enumeration value for& not ordered!", | |
e30c7d84 | 6633 | Enumeration_Rep_Expr (Elit), Elit); |
d6f39728 | 6634 | end if; |
6635 | ||
e30c7d84 | 6636 | Max_Node := Enumeration_Rep_Expr (Elit); |
d6f39728 | 6637 | Max := Val; |
6638 | end if; | |
6639 | ||
e30c7d84 | 6640 | -- If there is at least one literal whose representation is not |
6641 | -- equal to the Pos value, then note that this enumeration type | |
6642 | -- has a non-standard representation. | |
d6f39728 | 6643 | |
6644 | if Val /= Enumeration_Pos (Elit) then | |
6645 | Set_Has_Non_Standard_Rep (Base_Type (Enumtype)); | |
6646 | end if; | |
6647 | end if; | |
6648 | ||
6649 | Next (Elit); | |
6650 | end loop; | |
6651 | ||
6652 | -- Now set proper size information | |
6653 | ||
6654 | declare | |
6655 | Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype)); | |
6656 | ||
6657 | begin | |
6658 | if Has_Size_Clause (Enumtype) then | |
e30c7d84 | 6659 | |
6660 | -- All OK, if size is OK now | |
6661 | ||
6662 | if RM_Size (Enumtype) >= Minsize then | |
d6f39728 | 6663 | null; |
6664 | ||
6665 | else | |
e30c7d84 | 6666 | -- Try if we can get by with biasing |
6667 | ||
d6f39728 | 6668 | Minsize := |
6669 | UI_From_Int (Minimum_Size (Enumtype, Biased => True)); | |
6670 | ||
e30c7d84 | 6671 | -- Error message if even biasing does not work |
6672 | ||
6673 | if RM_Size (Enumtype) < Minsize then | |
6674 | Error_Msg_Uint_1 := RM_Size (Enumtype); | |
6675 | Error_Msg_Uint_2 := Max; | |
6676 | Error_Msg_N | |
6677 | ("previously given size (^) is too small " | |
6678 | & "for this value (^)", Max_Node); | |
6679 | ||
6680 | -- If biasing worked, indicate that we now have biased rep | |
d6f39728 | 6681 | |
6682 | else | |
b77e4501 | 6683 | Set_Biased |
6684 | (Enumtype, Size_Clause (Enumtype), "size clause"); | |
d6f39728 | 6685 | end if; |
6686 | end if; | |
6687 | ||
6688 | else | |
6689 | Set_RM_Size (Enumtype, Minsize); | |
6690 | Set_Enum_Esize (Enumtype); | |
6691 | end if; | |
6692 | ||
6693 | Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype)); | |
6694 | Set_Esize (Base_Type (Enumtype), Esize (Enumtype)); | |
6695 | Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype)); | |
6696 | end; | |
6697 | end if; | |
6698 | ||
39a0c1d3 | 6699 | -- We repeat the too late test in case it froze itself |
d6f39728 | 6700 | |
6701 | if Rep_Item_Too_Late (Enumtype, N) then | |
6702 | null; | |
6703 | end if; | |
d6f39728 | 6704 | end Analyze_Enumeration_Representation_Clause; |
6705 | ||
6706 | ---------------------------- | |
6707 | -- Analyze_Free_Statement -- | |
6708 | ---------------------------- | |
6709 | ||
6710 | procedure Analyze_Free_Statement (N : Node_Id) is | |
6711 | begin | |
6712 | Analyze (Expression (N)); | |
6713 | end Analyze_Free_Statement; | |
6714 | ||
40ca69b9 | 6715 | --------------------------- |
6716 | -- Analyze_Freeze_Entity -- | |
6717 | --------------------------- | |
6718 | ||
6719 | procedure Analyze_Freeze_Entity (N : Node_Id) is | |
40ca69b9 | 6720 | begin |
d9f6a4ee | 6721 | Freeze_Entity_Checks (N); |
6722 | end Analyze_Freeze_Entity; | |
98f7db28 | 6723 | |
d9f6a4ee | 6724 | ----------------------------------- |
6725 | -- Analyze_Freeze_Generic_Entity -- | |
6726 | ----------------------------------- | |
98f7db28 | 6727 | |
d9f6a4ee | 6728 | procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is |
61989dbb | 6729 | E : constant Entity_Id := Entity (N); |
6730 | ||
d9f6a4ee | 6731 | begin |
61989dbb | 6732 | if not Is_Frozen (E) and then Has_Delayed_Aspects (E) then |
6733 | Analyze_Aspects_At_Freeze_Point (E); | |
6734 | end if; | |
6735 | ||
d9f6a4ee | 6736 | Freeze_Entity_Checks (N); |
6737 | end Analyze_Freeze_Generic_Entity; | |
40ca69b9 | 6738 | |
d9f6a4ee | 6739 | ------------------------------------------ |
6740 | -- Analyze_Record_Representation_Clause -- | |
6741 | ------------------------------------------ | |
c8da6114 | 6742 | |
d9f6a4ee | 6743 | -- Note: we check as much as we can here, but we can't do any checks |
6744 | -- based on the position values (e.g. overlap checks) until freeze time | |
6745 | -- because especially in Ada 2005 (machine scalar mode), the processing | |
6746 | -- for non-standard bit order can substantially change the positions. | |
6747 | -- See procedure Check_Record_Representation_Clause (called from Freeze) | |
6748 | -- for the remainder of this processing. | |
d00681a7 | 6749 | |
d9f6a4ee | 6750 | procedure Analyze_Record_Representation_Clause (N : Node_Id) is |
6751 | Ident : constant Node_Id := Identifier (N); | |
6752 | Biased : Boolean; | |
6753 | CC : Node_Id; | |
6754 | Comp : Entity_Id; | |
6755 | Fbit : Uint; | |
6756 | Hbit : Uint := Uint_0; | |
6757 | Lbit : Uint; | |
6758 | Ocomp : Entity_Id; | |
6759 | Posit : Uint; | |
6760 | Rectype : Entity_Id; | |
6761 | Recdef : Node_Id; | |
d00681a7 | 6762 | |
d9f6a4ee | 6763 | function Is_Inherited (Comp : Entity_Id) return Boolean; |
6764 | -- True if Comp is an inherited component in a record extension | |
d00681a7 | 6765 | |
d9f6a4ee | 6766 | ------------------ |
6767 | -- Is_Inherited -- | |
6768 | ------------------ | |
d00681a7 | 6769 | |
d9f6a4ee | 6770 | function Is_Inherited (Comp : Entity_Id) return Boolean is |
6771 | Comp_Base : Entity_Id; | |
d00681a7 | 6772 | |
d9f6a4ee | 6773 | begin |
6774 | if Ekind (Rectype) = E_Record_Subtype then | |
6775 | Comp_Base := Original_Record_Component (Comp); | |
6776 | else | |
6777 | Comp_Base := Comp; | |
d00681a7 | 6778 | end if; |
6779 | ||
d9f6a4ee | 6780 | return Comp_Base /= Original_Record_Component (Comp_Base); |
6781 | end Is_Inherited; | |
d00681a7 | 6782 | |
d9f6a4ee | 6783 | -- Local variables |
d00681a7 | 6784 | |
d9f6a4ee | 6785 | Is_Record_Extension : Boolean; |
6786 | -- True if Rectype is a record extension | |
d00681a7 | 6787 | |
d9f6a4ee | 6788 | CR_Pragma : Node_Id := Empty; |
6789 | -- Points to N_Pragma node if Complete_Representation pragma present | |
d00681a7 | 6790 | |
d9f6a4ee | 6791 | -- Start of processing for Analyze_Record_Representation_Clause |
d00681a7 | 6792 | |
d9f6a4ee | 6793 | begin |
6794 | if Ignore_Rep_Clauses then | |
2ff55065 | 6795 | Kill_Rep_Clause (N); |
d9f6a4ee | 6796 | return; |
d00681a7 | 6797 | end if; |
98f7db28 | 6798 | |
d9f6a4ee | 6799 | Find_Type (Ident); |
6800 | Rectype := Entity (Ident); | |
85377c9b | 6801 | |
d9f6a4ee | 6802 | if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then |
6803 | return; | |
6804 | else | |
6805 | Rectype := Underlying_Type (Rectype); | |
6806 | end if; | |
85377c9b | 6807 | |
d9f6a4ee | 6808 | -- First some basic error checks |
85377c9b | 6809 | |
d9f6a4ee | 6810 | if not Is_Record_Type (Rectype) then |
6811 | Error_Msg_NE | |
6812 | ("record type required, found}", Ident, First_Subtype (Rectype)); | |
6813 | return; | |
85377c9b | 6814 | |
d9f6a4ee | 6815 | elsif Scope (Rectype) /= Current_Scope then |
6816 | Error_Msg_N ("type must be declared in this scope", N); | |
6817 | return; | |
85377c9b | 6818 | |
d9f6a4ee | 6819 | elsif not Is_First_Subtype (Rectype) then |
6820 | Error_Msg_N ("cannot give record rep clause for subtype", N); | |
6821 | return; | |
9dc88aea | 6822 | |
d9f6a4ee | 6823 | elsif Has_Record_Rep_Clause (Rectype) then |
6824 | Error_Msg_N ("duplicate record rep clause ignored", N); | |
6825 | return; | |
9dc88aea | 6826 | |
d9f6a4ee | 6827 | elsif Rep_Item_Too_Late (Rectype, N) then |
6828 | return; | |
9dc88aea | 6829 | end if; |
fb7f2fc4 | 6830 | |
2ced3742 | 6831 | -- We know we have a first subtype, now possibly go to the anonymous |
d9f6a4ee | 6832 | -- base type to determine whether Rectype is a record extension. |
89f1e35c | 6833 | |
d9f6a4ee | 6834 | Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype))); |
6835 | Is_Record_Extension := | |
6836 | Nkind (Recdef) = N_Derived_Type_Definition | |
6837 | and then Present (Record_Extension_Part (Recdef)); | |
89f1e35c | 6838 | |
d9f6a4ee | 6839 | if Present (Mod_Clause (N)) then |
fb7f2fc4 | 6840 | declare |
d9f6a4ee | 6841 | Loc : constant Source_Ptr := Sloc (N); |
6842 | M : constant Node_Id := Mod_Clause (N); | |
6843 | P : constant List_Id := Pragmas_Before (M); | |
6844 | AtM_Nod : Node_Id; | |
6845 | ||
6846 | Mod_Val : Uint; | |
6847 | pragma Warnings (Off, Mod_Val); | |
fb7f2fc4 | 6848 | |
6849 | begin | |
d9f6a4ee | 6850 | Check_Restriction (No_Obsolescent_Features, Mod_Clause (N)); |
fb7f2fc4 | 6851 | |
d9f6a4ee | 6852 | if Warn_On_Obsolescent_Feature then |
6853 | Error_Msg_N | |
6854 | ("?j?mod clause is an obsolescent feature (RM J.8)", N); | |
6855 | Error_Msg_N | |
6856 | ("\?j?use alignment attribute definition clause instead", N); | |
6857 | end if; | |
fb7f2fc4 | 6858 | |
d9f6a4ee | 6859 | if Present (P) then |
6860 | Analyze_List (P); | |
6861 | end if; | |
89f1e35c | 6862 | |
d9f6a4ee | 6863 | -- In ASIS_Mode mode, expansion is disabled, but we must convert |
6864 | -- the Mod clause into an alignment clause anyway, so that the | |
3ff5e35d | 6865 | -- back end can compute and back-annotate properly the size and |
d9f6a4ee | 6866 | -- alignment of types that may include this record. |
be9124d0 | 6867 | |
d9f6a4ee | 6868 | -- This seems dubious, this destroys the source tree in a manner |
6869 | -- not detectable by ASIS ??? | |
be9124d0 | 6870 | |
d9f6a4ee | 6871 | if Operating_Mode = Check_Semantics and then ASIS_Mode then |
6872 | AtM_Nod := | |
6873 | Make_Attribute_Definition_Clause (Loc, | |
83c6c069 | 6874 | Name => New_Occurrence_Of (Base_Type (Rectype), Loc), |
d9f6a4ee | 6875 | Chars => Name_Alignment, |
6876 | Expression => Relocate_Node (Expression (M))); | |
be9124d0 | 6877 | |
d9f6a4ee | 6878 | Set_From_At_Mod (AtM_Nod); |
6879 | Insert_After (N, AtM_Nod); | |
6880 | Mod_Val := Get_Alignment_Value (Expression (AtM_Nod)); | |
6881 | Set_Mod_Clause (N, Empty); | |
be9124d0 | 6882 | |
d9f6a4ee | 6883 | else |
6884 | -- Get the alignment value to perform error checking | |
be9124d0 | 6885 | |
d9f6a4ee | 6886 | Mod_Val := Get_Alignment_Value (Expression (M)); |
6887 | end if; | |
6888 | end; | |
6889 | end if; | |
be9124d0 | 6890 | |
d9f6a4ee | 6891 | -- For untagged types, clear any existing component clauses for the |
6892 | -- type. If the type is derived, this is what allows us to override | |
6893 | -- a rep clause for the parent. For type extensions, the representation | |
6894 | -- of the inherited components is inherited, so we want to keep previous | |
6895 | -- component clauses for completeness. | |
be9124d0 | 6896 | |
d9f6a4ee | 6897 | if not Is_Tagged_Type (Rectype) then |
6898 | Comp := First_Component_Or_Discriminant (Rectype); | |
6899 | while Present (Comp) loop | |
6900 | Set_Component_Clause (Comp, Empty); | |
6901 | Next_Component_Or_Discriminant (Comp); | |
6902 | end loop; | |
6903 | end if; | |
be9124d0 | 6904 | |
d9f6a4ee | 6905 | -- All done if no component clauses |
be9124d0 | 6906 | |
d9f6a4ee | 6907 | CC := First (Component_Clauses (N)); |
be9124d0 | 6908 | |
d9f6a4ee | 6909 | if No (CC) then |
6910 | return; | |
6911 | end if; | |
be9124d0 | 6912 | |
d9f6a4ee | 6913 | -- A representation like this applies to the base type |
be9124d0 | 6914 | |
d9f6a4ee | 6915 | Set_Has_Record_Rep_Clause (Base_Type (Rectype)); |
6916 | Set_Has_Non_Standard_Rep (Base_Type (Rectype)); | |
6917 | Set_Has_Specified_Layout (Base_Type (Rectype)); | |
be9124d0 | 6918 | |
d9f6a4ee | 6919 | -- Process the component clauses |
be9124d0 | 6920 | |
d9f6a4ee | 6921 | while Present (CC) loop |
be9124d0 | 6922 | |
d9f6a4ee | 6923 | -- Pragma |
be9124d0 | 6924 | |
d9f6a4ee | 6925 | if Nkind (CC) = N_Pragma then |
6926 | Analyze (CC); | |
be9124d0 | 6927 | |
d9f6a4ee | 6928 | -- The only pragma of interest is Complete_Representation |
be9124d0 | 6929 | |
ddccc924 | 6930 | if Pragma_Name (CC) = Name_Complete_Representation then |
d9f6a4ee | 6931 | CR_Pragma := CC; |
6932 | end if; | |
be9124d0 | 6933 | |
d9f6a4ee | 6934 | -- Processing for real component clause |
be9124d0 | 6935 | |
d9f6a4ee | 6936 | else |
6937 | Posit := Static_Integer (Position (CC)); | |
6938 | Fbit := Static_Integer (First_Bit (CC)); | |
6939 | Lbit := Static_Integer (Last_Bit (CC)); | |
be9124d0 | 6940 | |
d9f6a4ee | 6941 | if Posit /= No_Uint |
6942 | and then Fbit /= No_Uint | |
6943 | and then Lbit /= No_Uint | |
6944 | then | |
6945 | if Posit < 0 then | |
f74a102b | 6946 | Error_Msg_N ("position cannot be negative", Position (CC)); |
be9124d0 | 6947 | |
d9f6a4ee | 6948 | elsif Fbit < 0 then |
f74a102b | 6949 | Error_Msg_N ("first bit cannot be negative", First_Bit (CC)); |
be9124d0 | 6950 | |
d9f6a4ee | 6951 | -- The Last_Bit specified in a component clause must not be |
6952 | -- less than the First_Bit minus one (RM-13.5.1(10)). | |
be9124d0 | 6953 | |
d9f6a4ee | 6954 | elsif Lbit < Fbit - 1 then |
6955 | Error_Msg_N | |
6956 | ("last bit cannot be less than first bit minus one", | |
6957 | Last_Bit (CC)); | |
be9124d0 | 6958 | |
d9f6a4ee | 6959 | -- Values look OK, so find the corresponding record component |
6960 | -- Even though the syntax allows an attribute reference for | |
6961 | -- implementation-defined components, GNAT does not allow the | |
6962 | -- tag to get an explicit position. | |
be9124d0 | 6963 | |
d9f6a4ee | 6964 | elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then |
6965 | if Attribute_Name (Component_Name (CC)) = Name_Tag then | |
6966 | Error_Msg_N ("position of tag cannot be specified", CC); | |
6967 | else | |
6968 | Error_Msg_N ("illegal component name", CC); | |
6969 | end if; | |
be9124d0 | 6970 | |
d9f6a4ee | 6971 | else |
6972 | Comp := First_Entity (Rectype); | |
6973 | while Present (Comp) loop | |
6974 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
6975 | Next_Entity (Comp); | |
6976 | end loop; | |
be9124d0 | 6977 | |
d9f6a4ee | 6978 | if No (Comp) then |
be9124d0 | 6979 | |
d9f6a4ee | 6980 | -- Maybe component of base type that is absent from |
6981 | -- statically constrained first subtype. | |
be9124d0 | 6982 | |
d9f6a4ee | 6983 | Comp := First_Entity (Base_Type (Rectype)); |
6984 | while Present (Comp) loop | |
6985 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
6986 | Next_Entity (Comp); | |
6987 | end loop; | |
6988 | end if; | |
be9124d0 | 6989 | |
d9f6a4ee | 6990 | if No (Comp) then |
6991 | Error_Msg_N | |
6992 | ("component clause is for non-existent field", CC); | |
be9124d0 | 6993 | |
d9f6a4ee | 6994 | -- Ada 2012 (AI05-0026): Any name that denotes a |
6995 | -- discriminant of an object of an unchecked union type | |
6996 | -- shall not occur within a record_representation_clause. | |
be9124d0 | 6997 | |
d9f6a4ee | 6998 | -- The general restriction of using record rep clauses on |
6999 | -- Unchecked_Union types has now been lifted. Since it is | |
7000 | -- possible to introduce a record rep clause which mentions | |
7001 | -- the discriminant of an Unchecked_Union in non-Ada 2012 | |
7002 | -- code, this check is applied to all versions of the | |
7003 | -- language. | |
be9124d0 | 7004 | |
d9f6a4ee | 7005 | elsif Ekind (Comp) = E_Discriminant |
7006 | and then Is_Unchecked_Union (Rectype) | |
7007 | then | |
7008 | Error_Msg_N | |
7009 | ("cannot reference discriminant of unchecked union", | |
7010 | Component_Name (CC)); | |
be9124d0 | 7011 | |
d9f6a4ee | 7012 | elsif Is_Record_Extension and then Is_Inherited (Comp) then |
7013 | Error_Msg_NE | |
7014 | ("component clause not allowed for inherited " | |
7015 | & "component&", CC, Comp); | |
40ca69b9 | 7016 | |
d9f6a4ee | 7017 | elsif Present (Component_Clause (Comp)) then |
462a079f | 7018 | |
d9f6a4ee | 7019 | -- Diagnose duplicate rep clause, or check consistency |
7020 | -- if this is an inherited component. In a double fault, | |
7021 | -- there may be a duplicate inconsistent clause for an | |
7022 | -- inherited component. | |
462a079f | 7023 | |
d9f6a4ee | 7024 | if Scope (Original_Record_Component (Comp)) = Rectype |
7025 | or else Parent (Component_Clause (Comp)) = N | |
7026 | then | |
7027 | Error_Msg_Sloc := Sloc (Component_Clause (Comp)); | |
7028 | Error_Msg_N ("component clause previously given#", CC); | |
3062c401 | 7029 | |
7030 | else | |
7031 | declare | |
7032 | Rep1 : constant Node_Id := Component_Clause (Comp); | |
3062c401 | 7033 | begin |
7034 | if Intval (Position (Rep1)) /= | |
7035 | Intval (Position (CC)) | |
7036 | or else Intval (First_Bit (Rep1)) /= | |
7037 | Intval (First_Bit (CC)) | |
7038 | or else Intval (Last_Bit (Rep1)) /= | |
7039 | Intval (Last_Bit (CC)) | |
7040 | then | |
b9e61b2a | 7041 | Error_Msg_N |
f74a102b | 7042 | ("component clause inconsistent with " |
7043 | & "representation of ancestor", CC); | |
6a06584c | 7044 | |
3062c401 | 7045 | elsif Warn_On_Redundant_Constructs then |
b9e61b2a | 7046 | Error_Msg_N |
6a06584c | 7047 | ("?r?redundant confirming component clause " |
7048 | & "for component!", CC); | |
3062c401 | 7049 | end if; |
7050 | end; | |
7051 | end if; | |
d6f39728 | 7052 | |
d2b860b4 | 7053 | -- Normal case where this is the first component clause we |
7054 | -- have seen for this entity, so set it up properly. | |
7055 | ||
d6f39728 | 7056 | else |
83f8f0a6 | 7057 | -- Make reference for field in record rep clause and set |
7058 | -- appropriate entity field in the field identifier. | |
7059 | ||
7060 | Generate_Reference | |
7061 | (Comp, Component_Name (CC), Set_Ref => False); | |
7062 | Set_Entity (Component_Name (CC), Comp); | |
7063 | ||
2866d595 | 7064 | -- Update Fbit and Lbit to the actual bit number |
d6f39728 | 7065 | |
7066 | Fbit := Fbit + UI_From_Int (SSU) * Posit; | |
7067 | Lbit := Lbit + UI_From_Int (SSU) * Posit; | |
7068 | ||
d6f39728 | 7069 | if Has_Size_Clause (Rectype) |
ada34def | 7070 | and then RM_Size (Rectype) <= Lbit |
d6f39728 | 7071 | then |
7072 | Error_Msg_N | |
7073 | ("bit number out of range of specified size", | |
7074 | Last_Bit (CC)); | |
7075 | else | |
7076 | Set_Component_Clause (Comp, CC); | |
7077 | Set_Component_Bit_Offset (Comp, Fbit); | |
7078 | Set_Esize (Comp, 1 + (Lbit - Fbit)); | |
7079 | Set_Normalized_First_Bit (Comp, Fbit mod SSU); | |
7080 | Set_Normalized_Position (Comp, Fbit / SSU); | |
7081 | ||
a0fc8c5b | 7082 | if Warn_On_Overridden_Size |
7083 | and then Has_Size_Clause (Etype (Comp)) | |
7084 | and then RM_Size (Etype (Comp)) /= Esize (Comp) | |
7085 | then | |
7086 | Error_Msg_NE | |
1e3532e7 | 7087 | ("?S?component size overrides size clause for&", |
a0fc8c5b | 7088 | Component_Name (CC), Etype (Comp)); |
7089 | end if; | |
7090 | ||
ea61a7ea | 7091 | -- This information is also set in the corresponding |
7092 | -- component of the base type, found by accessing the | |
7093 | -- Original_Record_Component link if it is present. | |
d6f39728 | 7094 | |
7095 | Ocomp := Original_Record_Component (Comp); | |
7096 | ||
7097 | if Hbit < Lbit then | |
7098 | Hbit := Lbit; | |
7099 | end if; | |
7100 | ||
7101 | Check_Size | |
7102 | (Component_Name (CC), | |
7103 | Etype (Comp), | |
7104 | Esize (Comp), | |
7105 | Biased); | |
7106 | ||
b77e4501 | 7107 | Set_Biased |
7108 | (Comp, First_Node (CC), "component clause", Biased); | |
cc46ff4b | 7109 | |
d6f39728 | 7110 | if Present (Ocomp) then |
7111 | Set_Component_Clause (Ocomp, CC); | |
7112 | Set_Component_Bit_Offset (Ocomp, Fbit); | |
7113 | Set_Normalized_First_Bit (Ocomp, Fbit mod SSU); | |
7114 | Set_Normalized_Position (Ocomp, Fbit / SSU); | |
7115 | Set_Esize (Ocomp, 1 + (Lbit - Fbit)); | |
7116 | ||
7117 | Set_Normalized_Position_Max | |
7118 | (Ocomp, Normalized_Position (Ocomp)); | |
7119 | ||
b77e4501 | 7120 | -- Note: we don't use Set_Biased here, because we |
7121 | -- already gave a warning above if needed, and we | |
7122 | -- would get a duplicate for the same name here. | |
7123 | ||
d6f39728 | 7124 | Set_Has_Biased_Representation |
7125 | (Ocomp, Has_Biased_Representation (Comp)); | |
7126 | end if; | |
7127 | ||
7128 | if Esize (Comp) < 0 then | |
7129 | Error_Msg_N ("component size is negative", CC); | |
7130 | end if; | |
7131 | end if; | |
7132 | end if; | |
7133 | end if; | |
7134 | end if; | |
7135 | end if; | |
7136 | ||
7137 | Next (CC); | |
7138 | end loop; | |
7139 | ||
67278d60 | 7140 | -- Check missing components if Complete_Representation pragma appeared |
d6f39728 | 7141 | |
67278d60 | 7142 | if Present (CR_Pragma) then |
7143 | Comp := First_Component_Or_Discriminant (Rectype); | |
7144 | while Present (Comp) loop | |
7145 | if No (Component_Clause (Comp)) then | |
7146 | Error_Msg_NE | |
7147 | ("missing component clause for &", CR_Pragma, Comp); | |
7148 | end if; | |
d6f39728 | 7149 | |
67278d60 | 7150 | Next_Component_Or_Discriminant (Comp); |
7151 | end loop; | |
d6f39728 | 7152 | |
1e3532e7 | 7153 | -- Give missing components warning if required |
15ebb600 | 7154 | |
fdd294d1 | 7155 | elsif Warn_On_Unrepped_Components then |
15ebb600 | 7156 | declare |
7157 | Num_Repped_Components : Nat := 0; | |
7158 | Num_Unrepped_Components : Nat := 0; | |
7159 | ||
7160 | begin | |
7161 | -- First count number of repped and unrepped components | |
7162 | ||
7163 | Comp := First_Component_Or_Discriminant (Rectype); | |
7164 | while Present (Comp) loop | |
7165 | if Present (Component_Clause (Comp)) then | |
7166 | Num_Repped_Components := Num_Repped_Components + 1; | |
7167 | else | |
7168 | Num_Unrepped_Components := Num_Unrepped_Components + 1; | |
7169 | end if; | |
7170 | ||
7171 | Next_Component_Or_Discriminant (Comp); | |
7172 | end loop; | |
7173 | ||
7174 | -- We are only interested in the case where there is at least one | |
7175 | -- unrepped component, and at least half the components have rep | |
7176 | -- clauses. We figure that if less than half have them, then the | |
87f9eef5 | 7177 | -- partial rep clause is really intentional. If the component |
7178 | -- type has no underlying type set at this point (as for a generic | |
7179 | -- formal type), we don't know enough to give a warning on the | |
7180 | -- component. | |
15ebb600 | 7181 | |
7182 | if Num_Unrepped_Components > 0 | |
7183 | and then Num_Unrepped_Components < Num_Repped_Components | |
7184 | then | |
7185 | Comp := First_Component_Or_Discriminant (Rectype); | |
7186 | while Present (Comp) loop | |
83f8f0a6 | 7187 | if No (Component_Clause (Comp)) |
3062c401 | 7188 | and then Comes_From_Source (Comp) |
87f9eef5 | 7189 | and then Present (Underlying_Type (Etype (Comp))) |
83f8f0a6 | 7190 | and then (Is_Scalar_Type (Underlying_Type (Etype (Comp))) |
67278d60 | 7191 | or else Size_Known_At_Compile_Time |
7192 | (Underlying_Type (Etype (Comp)))) | |
fdd294d1 | 7193 | and then not Has_Warnings_Off (Rectype) |
2be1f7d7 | 7194 | |
7195 | -- Ignore discriminant in unchecked union, since it is | |
7196 | -- not there, and cannot have a component clause. | |
7197 | ||
7198 | and then (not Is_Unchecked_Union (Rectype) | |
7199 | or else Ekind (Comp) /= E_Discriminant) | |
83f8f0a6 | 7200 | then |
15ebb600 | 7201 | Error_Msg_Sloc := Sloc (Comp); |
7202 | Error_Msg_NE | |
1e3532e7 | 7203 | ("?C?no component clause given for & declared #", |
15ebb600 | 7204 | N, Comp); |
7205 | end if; | |
7206 | ||
7207 | Next_Component_Or_Discriminant (Comp); | |
7208 | end loop; | |
7209 | end if; | |
7210 | end; | |
d6f39728 | 7211 | end if; |
d6f39728 | 7212 | end Analyze_Record_Representation_Clause; |
7213 | ||
eb66e842 | 7214 | ------------------------------------- |
7215 | -- Build_Discrete_Static_Predicate -- | |
7216 | ------------------------------------- | |
9ea61fdd | 7217 | |
eb66e842 | 7218 | procedure Build_Discrete_Static_Predicate |
7219 | (Typ : Entity_Id; | |
7220 | Expr : Node_Id; | |
7221 | Nam : Name_Id) | |
9ea61fdd | 7222 | is |
eb66e842 | 7223 | Loc : constant Source_Ptr := Sloc (Expr); |
9ea61fdd | 7224 | |
eb66e842 | 7225 | Non_Static : exception; |
7226 | -- Raised if something non-static is found | |
9ea61fdd | 7227 | |
eb66e842 | 7228 | Btyp : constant Entity_Id := Base_Type (Typ); |
9ea61fdd | 7229 | |
eb66e842 | 7230 | BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp)); |
7231 | BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp)); | |
7232 | -- Low bound and high bound value of base type of Typ | |
9ea61fdd | 7233 | |
afc229da | 7234 | TLo : Uint; |
7235 | THi : Uint; | |
7236 | -- Bounds for constructing the static predicate. We use the bound of the | |
7237 | -- subtype if it is static, otherwise the corresponding base type bound. | |
7238 | -- Note: a non-static subtype can have a static predicate. | |
9ea61fdd | 7239 | |
eb66e842 | 7240 | type REnt is record |
7241 | Lo, Hi : Uint; | |
7242 | end record; | |
7243 | -- One entry in a Rlist value, a single REnt (range entry) value denotes | |
7244 | -- one range from Lo to Hi. To represent a single value range Lo = Hi = | |
7245 | -- value. | |
9ea61fdd | 7246 | |
eb66e842 | 7247 | type RList is array (Nat range <>) of REnt; |
7248 | -- A list of ranges. The ranges are sorted in increasing order, and are | |
7249 | -- disjoint (there is a gap of at least one value between each range in | |
7250 | -- the table). A value is in the set of ranges in Rlist if it lies | |
7251 | -- within one of these ranges. | |
9ea61fdd | 7252 | |
eb66e842 | 7253 | False_Range : constant RList := |
7254 | RList'(1 .. 0 => REnt'(No_Uint, No_Uint)); | |
7255 | -- An empty set of ranges represents a range list that can never be | |
7256 | -- satisfied, since there are no ranges in which the value could lie, | |
7257 | -- so it does not lie in any of them. False_Range is a canonical value | |
7258 | -- for this empty set, but general processing should test for an Rlist | |
7259 | -- with length zero (see Is_False predicate), since other null ranges | |
7260 | -- may appear which must be treated as False. | |
5b5df4a9 | 7261 | |
eb66e842 | 7262 | True_Range : constant RList := RList'(1 => REnt'(BLo, BHi)); |
7263 | -- Range representing True, value must be in the base range | |
5b5df4a9 | 7264 | |
eb66e842 | 7265 | function "and" (Left : RList; Right : RList) return RList; |
7266 | -- And's together two range lists, returning a range list. This is a set | |
7267 | -- intersection operation. | |
5b5df4a9 | 7268 | |
eb66e842 | 7269 | function "or" (Left : RList; Right : RList) return RList; |
7270 | -- Or's together two range lists, returning a range list. This is a set | |
7271 | -- union operation. | |
87f3d5d3 | 7272 | |
eb66e842 | 7273 | function "not" (Right : RList) return RList; |
7274 | -- Returns complement of a given range list, i.e. a range list | |
7275 | -- representing all the values in TLo .. THi that are not in the input | |
7276 | -- operand Right. | |
ed4adc99 | 7277 | |
eb66e842 | 7278 | function Build_Val (V : Uint) return Node_Id; |
7279 | -- Return an analyzed N_Identifier node referencing this value, suitable | |
5c6a5792 | 7280 | -- for use as an entry in the Static_Discrte_Predicate list. This node |
7281 | -- is typed with the base type. | |
5b5df4a9 | 7282 | |
eb66e842 | 7283 | function Build_Range (Lo : Uint; Hi : Uint) return Node_Id; |
7284 | -- Return an analyzed N_Range node referencing this range, suitable for | |
5c6a5792 | 7285 | -- use as an entry in the Static_Discrete_Predicate list. This node is |
7286 | -- typed with the base type. | |
5b5df4a9 | 7287 | |
eb66e842 | 7288 | function Get_RList (Exp : Node_Id) return RList; |
7289 | -- This is a recursive routine that converts the given expression into a | |
7290 | -- list of ranges, suitable for use in building the static predicate. | |
5b5df4a9 | 7291 | |
eb66e842 | 7292 | function Is_False (R : RList) return Boolean; |
7293 | pragma Inline (Is_False); | |
7294 | -- Returns True if the given range list is empty, and thus represents a | |
7295 | -- False list of ranges that can never be satisfied. | |
87f3d5d3 | 7296 | |
eb66e842 | 7297 | function Is_True (R : RList) return Boolean; |
7298 | -- Returns True if R trivially represents the True predicate by having a | |
7299 | -- single range from BLo to BHi. | |
5b5df4a9 | 7300 | |
eb66e842 | 7301 | function Is_Type_Ref (N : Node_Id) return Boolean; |
7302 | pragma Inline (Is_Type_Ref); | |
7303 | -- Returns if True if N is a reference to the type for the predicate in | |
7304 | -- the expression (i.e. if it is an identifier whose Chars field matches | |
7de4cba3 | 7305 | -- the Nam given in the call). N must not be parenthesized, if the type |
7306 | -- name appears in parens, this routine will return False. | |
5b5df4a9 | 7307 | |
eb66e842 | 7308 | function Lo_Val (N : Node_Id) return Uint; |
5c6a5792 | 7309 | -- Given an entry from a Static_Discrete_Predicate list that is either |
7310 | -- a static expression or static range, gets either the expression value | |
7311 | -- or the low bound of the range. | |
5b5df4a9 | 7312 | |
eb66e842 | 7313 | function Hi_Val (N : Node_Id) return Uint; |
5c6a5792 | 7314 | -- Given an entry from a Static_Discrete_Predicate list that is either |
7315 | -- a static expression or static range, gets either the expression value | |
7316 | -- or the high bound of the range. | |
5b5df4a9 | 7317 | |
eb66e842 | 7318 | function Membership_Entry (N : Node_Id) return RList; |
7319 | -- Given a single membership entry (range, value, or subtype), returns | |
7320 | -- the corresponding range list. Raises Static_Error if not static. | |
5b5df4a9 | 7321 | |
eb66e842 | 7322 | function Membership_Entries (N : Node_Id) return RList; |
7323 | -- Given an element on an alternatives list of a membership operation, | |
7324 | -- returns the range list corresponding to this entry and all following | |
7325 | -- entries (i.e. returns the "or" of this list of values). | |
b9e61b2a | 7326 | |
eb66e842 | 7327 | function Stat_Pred (Typ : Entity_Id) return RList; |
7328 | -- Given a type, if it has a static predicate, then return the predicate | |
7329 | -- as a range list, otherwise raise Non_Static. | |
c4968aa2 | 7330 | |
eb66e842 | 7331 | ----------- |
7332 | -- "and" -- | |
7333 | ----------- | |
c4968aa2 | 7334 | |
eb66e842 | 7335 | function "and" (Left : RList; Right : RList) return RList is |
7336 | FEnt : REnt; | |
7337 | -- First range of result | |
c4968aa2 | 7338 | |
eb66e842 | 7339 | SLeft : Nat := Left'First; |
7340 | -- Start of rest of left entries | |
c4968aa2 | 7341 | |
eb66e842 | 7342 | SRight : Nat := Right'First; |
7343 | -- Start of rest of right entries | |
2072eaa9 | 7344 | |
eb66e842 | 7345 | begin |
7346 | -- If either range is True, return the other | |
5b5df4a9 | 7347 | |
eb66e842 | 7348 | if Is_True (Left) then |
7349 | return Right; | |
7350 | elsif Is_True (Right) then | |
7351 | return Left; | |
7352 | end if; | |
87f3d5d3 | 7353 | |
eb66e842 | 7354 | -- If either range is False, return False |
5b5df4a9 | 7355 | |
eb66e842 | 7356 | if Is_False (Left) or else Is_False (Right) then |
7357 | return False_Range; | |
7358 | end if; | |
4c1fd062 | 7359 | |
eb66e842 | 7360 | -- Loop to remove entries at start that are disjoint, and thus just |
7361 | -- get discarded from the result entirely. | |
5b5df4a9 | 7362 | |
eb66e842 | 7363 | loop |
7364 | -- If no operands left in either operand, result is false | |
5b5df4a9 | 7365 | |
eb66e842 | 7366 | if SLeft > Left'Last or else SRight > Right'Last then |
7367 | return False_Range; | |
5b5df4a9 | 7368 | |
eb66e842 | 7369 | -- Discard first left operand entry if disjoint with right |
5b5df4a9 | 7370 | |
eb66e842 | 7371 | elsif Left (SLeft).Hi < Right (SRight).Lo then |
7372 | SLeft := SLeft + 1; | |
5b5df4a9 | 7373 | |
eb66e842 | 7374 | -- Discard first right operand entry if disjoint with left |
5b5df4a9 | 7375 | |
eb66e842 | 7376 | elsif Right (SRight).Hi < Left (SLeft).Lo then |
7377 | SRight := SRight + 1; | |
5b5df4a9 | 7378 | |
eb66e842 | 7379 | -- Otherwise we have an overlapping entry |
5b5df4a9 | 7380 | |
eb66e842 | 7381 | else |
7382 | exit; | |
7383 | end if; | |
7384 | end loop; | |
5b5df4a9 | 7385 | |
eb66e842 | 7386 | -- Now we have two non-null operands, and first entries overlap. The |
7387 | -- first entry in the result will be the overlapping part of these | |
7388 | -- two entries. | |
47a46747 | 7389 | |
eb66e842 | 7390 | FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo), |
7391 | Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi)); | |
47a46747 | 7392 | |
eb66e842 | 7393 | -- Now we can remove the entry that ended at a lower value, since its |
7394 | -- contribution is entirely contained in Fent. | |
5b5df4a9 | 7395 | |
eb66e842 | 7396 | if Left (SLeft).Hi <= Right (SRight).Hi then |
7397 | SLeft := SLeft + 1; | |
7398 | else | |
7399 | SRight := SRight + 1; | |
7400 | end if; | |
5b5df4a9 | 7401 | |
eb66e842 | 7402 | -- Compute result by concatenating this first entry with the "and" of |
7403 | -- the remaining parts of the left and right operands. Note that if | |
7404 | -- either of these is empty, "and" will yield empty, so that we will | |
7405 | -- end up with just Fent, which is what we want in that case. | |
5b5df4a9 | 7406 | |
eb66e842 | 7407 | return |
7408 | FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last)); | |
7409 | end "and"; | |
fb7f2fc4 | 7410 | |
eb66e842 | 7411 | ----------- |
7412 | -- "not" -- | |
7413 | ----------- | |
fb7f2fc4 | 7414 | |
eb66e842 | 7415 | function "not" (Right : RList) return RList is |
7416 | begin | |
7417 | -- Return True if False range | |
fb7f2fc4 | 7418 | |
eb66e842 | 7419 | if Is_False (Right) then |
7420 | return True_Range; | |
7421 | end if; | |
ed4adc99 | 7422 | |
eb66e842 | 7423 | -- Return False if True range |
fb7f2fc4 | 7424 | |
eb66e842 | 7425 | if Is_True (Right) then |
7426 | return False_Range; | |
7427 | end if; | |
fb7f2fc4 | 7428 | |
eb66e842 | 7429 | -- Here if not trivial case |
87f3d5d3 | 7430 | |
eb66e842 | 7431 | declare |
7432 | Result : RList (1 .. Right'Length + 1); | |
7433 | -- May need one more entry for gap at beginning and end | |
87f3d5d3 | 7434 | |
eb66e842 | 7435 | Count : Nat := 0; |
7436 | -- Number of entries stored in Result | |
4098232e | 7437 | |
eb66e842 | 7438 | begin |
7439 | -- Gap at start | |
4098232e | 7440 | |
eb66e842 | 7441 | if Right (Right'First).Lo > TLo then |
7442 | Count := Count + 1; | |
7443 | Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1); | |
7444 | end if; | |
ed4adc99 | 7445 | |
eb66e842 | 7446 | -- Gaps between ranges |
ed4adc99 | 7447 | |
eb66e842 | 7448 | for J in Right'First .. Right'Last - 1 loop |
7449 | Count := Count + 1; | |
7450 | Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1); | |
7451 | end loop; | |
5b5df4a9 | 7452 | |
eb66e842 | 7453 | -- Gap at end |
5b5df4a9 | 7454 | |
eb66e842 | 7455 | if Right (Right'Last).Hi < THi then |
7456 | Count := Count + 1; | |
7457 | Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi); | |
7458 | end if; | |
5b5df4a9 | 7459 | |
eb66e842 | 7460 | return Result (1 .. Count); |
7461 | end; | |
7462 | end "not"; | |
5b5df4a9 | 7463 | |
eb66e842 | 7464 | ---------- |
7465 | -- "or" -- | |
7466 | ---------- | |
5b5df4a9 | 7467 | |
eb66e842 | 7468 | function "or" (Left : RList; Right : RList) return RList is |
7469 | FEnt : REnt; | |
7470 | -- First range of result | |
5b5df4a9 | 7471 | |
eb66e842 | 7472 | SLeft : Nat := Left'First; |
7473 | -- Start of rest of left entries | |
5b5df4a9 | 7474 | |
eb66e842 | 7475 | SRight : Nat := Right'First; |
7476 | -- Start of rest of right entries | |
5b5df4a9 | 7477 | |
eb66e842 | 7478 | begin |
7479 | -- If either range is True, return True | |
5b5df4a9 | 7480 | |
eb66e842 | 7481 | if Is_True (Left) or else Is_True (Right) then |
7482 | return True_Range; | |
7483 | end if; | |
5b5df4a9 | 7484 | |
eb66e842 | 7485 | -- If either range is False (empty), return the other |
5b5df4a9 | 7486 | |
eb66e842 | 7487 | if Is_False (Left) then |
7488 | return Right; | |
7489 | elsif Is_False (Right) then | |
7490 | return Left; | |
7491 | end if; | |
5b5df4a9 | 7492 | |
eb66e842 | 7493 | -- Initialize result first entry from left or right operand depending |
7494 | -- on which starts with the lower range. | |
5b5df4a9 | 7495 | |
eb66e842 | 7496 | if Left (SLeft).Lo < Right (SRight).Lo then |
7497 | FEnt := Left (SLeft); | |
7498 | SLeft := SLeft + 1; | |
7499 | else | |
7500 | FEnt := Right (SRight); | |
7501 | SRight := SRight + 1; | |
7502 | end if; | |
5b5df4a9 | 7503 | |
eb66e842 | 7504 | -- This loop eats ranges from left and right operands that are |
7505 | -- contiguous with the first range we are gathering. | |
9ea61fdd | 7506 | |
eb66e842 | 7507 | loop |
7508 | -- Eat first entry in left operand if contiguous or overlapped by | |
7509 | -- gathered first operand of result. | |
9ea61fdd | 7510 | |
eb66e842 | 7511 | if SLeft <= Left'Last |
7512 | and then Left (SLeft).Lo <= FEnt.Hi + 1 | |
7513 | then | |
7514 | FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi); | |
7515 | SLeft := SLeft + 1; | |
9ea61fdd | 7516 | |
eb66e842 | 7517 | -- Eat first entry in right operand if contiguous or overlapped by |
7518 | -- gathered right operand of result. | |
9ea61fdd | 7519 | |
eb66e842 | 7520 | elsif SRight <= Right'Last |
7521 | and then Right (SRight).Lo <= FEnt.Hi + 1 | |
7522 | then | |
7523 | FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi); | |
7524 | SRight := SRight + 1; | |
9ea61fdd | 7525 | |
eb66e842 | 7526 | -- All done if no more entries to eat |
5b5df4a9 | 7527 | |
eb66e842 | 7528 | else |
7529 | exit; | |
7530 | end if; | |
7531 | end loop; | |
5b5df4a9 | 7532 | |
eb66e842 | 7533 | -- Obtain result as the first entry we just computed, concatenated |
7534 | -- to the "or" of the remaining results (if one operand is empty, | |
7535 | -- this will just concatenate with the other | |
5b5df4a9 | 7536 | |
eb66e842 | 7537 | return |
7538 | FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last)); | |
7539 | end "or"; | |
5b5df4a9 | 7540 | |
eb66e842 | 7541 | ----------------- |
7542 | -- Build_Range -- | |
7543 | ----------------- | |
5b5df4a9 | 7544 | |
eb66e842 | 7545 | function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is |
7546 | Result : Node_Id; | |
5b5df4a9 | 7547 | begin |
eb66e842 | 7548 | Result := |
7549 | Make_Range (Loc, | |
7550 | Low_Bound => Build_Val (Lo), | |
7551 | High_Bound => Build_Val (Hi)); | |
7552 | Set_Etype (Result, Btyp); | |
7553 | Set_Analyzed (Result); | |
7554 | return Result; | |
7555 | end Build_Range; | |
5b5df4a9 | 7556 | |
eb66e842 | 7557 | --------------- |
7558 | -- Build_Val -- | |
7559 | --------------- | |
5b5df4a9 | 7560 | |
eb66e842 | 7561 | function Build_Val (V : Uint) return Node_Id is |
7562 | Result : Node_Id; | |
5b5df4a9 | 7563 | |
eb66e842 | 7564 | begin |
7565 | if Is_Enumeration_Type (Typ) then | |
7566 | Result := Get_Enum_Lit_From_Pos (Typ, V, Loc); | |
7567 | else | |
7568 | Result := Make_Integer_Literal (Loc, V); | |
7569 | end if; | |
5b5df4a9 | 7570 | |
eb66e842 | 7571 | Set_Etype (Result, Btyp); |
7572 | Set_Is_Static_Expression (Result); | |
7573 | Set_Analyzed (Result); | |
7574 | return Result; | |
7575 | end Build_Val; | |
87f3d5d3 | 7576 | |
eb66e842 | 7577 | --------------- |
7578 | -- Get_RList -- | |
7579 | --------------- | |
87f3d5d3 | 7580 | |
eb66e842 | 7581 | function Get_RList (Exp : Node_Id) return RList is |
7582 | Op : Node_Kind; | |
7583 | Val : Uint; | |
87f3d5d3 | 7584 | |
eb66e842 | 7585 | begin |
7586 | -- Static expression can only be true or false | |
87f3d5d3 | 7587 | |
eb66e842 | 7588 | if Is_OK_Static_Expression (Exp) then |
7589 | if Expr_Value (Exp) = 0 then | |
7590 | return False_Range; | |
7591 | else | |
7592 | return True_Range; | |
9ea61fdd | 7593 | end if; |
eb66e842 | 7594 | end if; |
87f3d5d3 | 7595 | |
eb66e842 | 7596 | -- Otherwise test node type |
192b8dab | 7597 | |
eb66e842 | 7598 | Op := Nkind (Exp); |
192b8dab | 7599 | |
eb66e842 | 7600 | case Op is |
5d3fb947 | 7601 | |
eb66e842 | 7602 | -- And |
5d3fb947 | 7603 | |
eb66e842 | 7604 | when N_Op_And | N_And_Then => |
7605 | return Get_RList (Left_Opnd (Exp)) | |
7606 | and | |
7607 | Get_RList (Right_Opnd (Exp)); | |
5b5df4a9 | 7608 | |
eb66e842 | 7609 | -- Or |
9dc88aea | 7610 | |
eb66e842 | 7611 | when N_Op_Or | N_Or_Else => |
7612 | return Get_RList (Left_Opnd (Exp)) | |
7613 | or | |
7614 | Get_RList (Right_Opnd (Exp)); | |
7c443ae8 | 7615 | |
eb66e842 | 7616 | -- Not |
9dc88aea | 7617 | |
eb66e842 | 7618 | when N_Op_Not => |
7619 | return not Get_RList (Right_Opnd (Exp)); | |
9dc88aea | 7620 | |
eb66e842 | 7621 | -- Comparisons of type with static value |
84c8f0b8 | 7622 | |
eb66e842 | 7623 | when N_Op_Compare => |
490beba6 | 7624 | |
eb66e842 | 7625 | -- Type is left operand |
9dc88aea | 7626 | |
eb66e842 | 7627 | if Is_Type_Ref (Left_Opnd (Exp)) |
7628 | and then Is_OK_Static_Expression (Right_Opnd (Exp)) | |
7629 | then | |
7630 | Val := Expr_Value (Right_Opnd (Exp)); | |
84c8f0b8 | 7631 | |
eb66e842 | 7632 | -- Typ is right operand |
84c8f0b8 | 7633 | |
eb66e842 | 7634 | elsif Is_Type_Ref (Right_Opnd (Exp)) |
7635 | and then Is_OK_Static_Expression (Left_Opnd (Exp)) | |
7636 | then | |
7637 | Val := Expr_Value (Left_Opnd (Exp)); | |
84c8f0b8 | 7638 | |
eb66e842 | 7639 | -- Invert sense of comparison |
84c8f0b8 | 7640 | |
eb66e842 | 7641 | case Op is |
7642 | when N_Op_Gt => Op := N_Op_Lt; | |
7643 | when N_Op_Lt => Op := N_Op_Gt; | |
7644 | when N_Op_Ge => Op := N_Op_Le; | |
7645 | when N_Op_Le => Op := N_Op_Ge; | |
7646 | when others => null; | |
7647 | end case; | |
84c8f0b8 | 7648 | |
eb66e842 | 7649 | -- Other cases are non-static |
34d045d3 | 7650 | |
eb66e842 | 7651 | else |
7652 | raise Non_Static; | |
7653 | end if; | |
9dc88aea | 7654 | |
eb66e842 | 7655 | -- Construct range according to comparison operation |
9dc88aea | 7656 | |
eb66e842 | 7657 | case Op is |
7658 | when N_Op_Eq => | |
7659 | return RList'(1 => REnt'(Val, Val)); | |
9dc88aea | 7660 | |
eb66e842 | 7661 | when N_Op_Ge => |
7662 | return RList'(1 => REnt'(Val, BHi)); | |
84c8f0b8 | 7663 | |
eb66e842 | 7664 | when N_Op_Gt => |
7665 | return RList'(1 => REnt'(Val + 1, BHi)); | |
84c8f0b8 | 7666 | |
eb66e842 | 7667 | when N_Op_Le => |
7668 | return RList'(1 => REnt'(BLo, Val)); | |
fb7f2fc4 | 7669 | |
eb66e842 | 7670 | when N_Op_Lt => |
7671 | return RList'(1 => REnt'(BLo, Val - 1)); | |
9dc88aea | 7672 | |
eb66e842 | 7673 | when N_Op_Ne => |
7674 | return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi)); | |
9dc88aea | 7675 | |
eb66e842 | 7676 | when others => |
7677 | raise Program_Error; | |
7678 | end case; | |
9dc88aea | 7679 | |
eb66e842 | 7680 | -- Membership (IN) |
9dc88aea | 7681 | |
eb66e842 | 7682 | when N_In => |
7683 | if not Is_Type_Ref (Left_Opnd (Exp)) then | |
7684 | raise Non_Static; | |
7685 | end if; | |
9dc88aea | 7686 | |
eb66e842 | 7687 | if Present (Right_Opnd (Exp)) then |
7688 | return Membership_Entry (Right_Opnd (Exp)); | |
7689 | else | |
7690 | return Membership_Entries (First (Alternatives (Exp))); | |
7691 | end if; | |
9dc88aea | 7692 | |
eb66e842 | 7693 | -- Negative membership (NOT IN) |
9dc88aea | 7694 | |
eb66e842 | 7695 | when N_Not_In => |
7696 | if not Is_Type_Ref (Left_Opnd (Exp)) then | |
7697 | raise Non_Static; | |
7698 | end if; | |
9dc88aea | 7699 | |
eb66e842 | 7700 | if Present (Right_Opnd (Exp)) then |
7701 | return not Membership_Entry (Right_Opnd (Exp)); | |
7702 | else | |
7703 | return not Membership_Entries (First (Alternatives (Exp))); | |
7704 | end if; | |
9dc88aea | 7705 | |
eb66e842 | 7706 | -- Function call, may be call to static predicate |
9dc88aea | 7707 | |
eb66e842 | 7708 | when N_Function_Call => |
7709 | if Is_Entity_Name (Name (Exp)) then | |
7710 | declare | |
7711 | Ent : constant Entity_Id := Entity (Name (Exp)); | |
7712 | begin | |
7713 | if Is_Predicate_Function (Ent) | |
7714 | or else | |
7715 | Is_Predicate_Function_M (Ent) | |
7716 | then | |
7717 | return Stat_Pred (Etype (First_Formal (Ent))); | |
7718 | end if; | |
7719 | end; | |
7720 | end if; | |
9dc88aea | 7721 | |
eb66e842 | 7722 | -- Other function call cases are non-static |
9dc88aea | 7723 | |
eb66e842 | 7724 | raise Non_Static; |
490beba6 | 7725 | |
eb66e842 | 7726 | -- Qualified expression, dig out the expression |
c92e878b | 7727 | |
eb66e842 | 7728 | when N_Qualified_Expression => |
7729 | return Get_RList (Expression (Exp)); | |
4c1fd062 | 7730 | |
eb66e842 | 7731 | when N_Case_Expression => |
7732 | declare | |
7733 | Alt : Node_Id; | |
7734 | Choices : List_Id; | |
7735 | Dep : Node_Id; | |
4c1fd062 | 7736 | |
eb66e842 | 7737 | begin |
7738 | if not Is_Entity_Name (Expression (Expr)) | |
7739 | or else Etype (Expression (Expr)) /= Typ | |
7740 | then | |
7741 | Error_Msg_N | |
7742 | ("expression must denaote subtype", Expression (Expr)); | |
7743 | return False_Range; | |
7744 | end if; | |
9dc88aea | 7745 | |
eb66e842 | 7746 | -- Collect discrete choices in all True alternatives |
9dc88aea | 7747 | |
eb66e842 | 7748 | Choices := New_List; |
7749 | Alt := First (Alternatives (Exp)); | |
7750 | while Present (Alt) loop | |
7751 | Dep := Expression (Alt); | |
34d045d3 | 7752 | |
cda40848 | 7753 | if not Is_OK_Static_Expression (Dep) then |
eb66e842 | 7754 | raise Non_Static; |
ebbab42d | 7755 | |
eb66e842 | 7756 | elsif Is_True (Expr_Value (Dep)) then |
7757 | Append_List_To (Choices, | |
7758 | New_Copy_List (Discrete_Choices (Alt))); | |
7759 | end if; | |
fb7f2fc4 | 7760 | |
eb66e842 | 7761 | Next (Alt); |
7762 | end loop; | |
9dc88aea | 7763 | |
eb66e842 | 7764 | return Membership_Entries (First (Choices)); |
7765 | end; | |
9dc88aea | 7766 | |
eb66e842 | 7767 | -- Expression with actions: if no actions, dig out expression |
9dc88aea | 7768 | |
eb66e842 | 7769 | when N_Expression_With_Actions => |
7770 | if Is_Empty_List (Actions (Exp)) then | |
7771 | return Get_RList (Expression (Exp)); | |
7772 | else | |
7773 | raise Non_Static; | |
7774 | end if; | |
9dc88aea | 7775 | |
eb66e842 | 7776 | -- Xor operator |
490beba6 | 7777 | |
eb66e842 | 7778 | when N_Op_Xor => |
7779 | return (Get_RList (Left_Opnd (Exp)) | |
7780 | and not Get_RList (Right_Opnd (Exp))) | |
7781 | or (Get_RList (Right_Opnd (Exp)) | |
7782 | and not Get_RList (Left_Opnd (Exp))); | |
9dc88aea | 7783 | |
eb66e842 | 7784 | -- Any other node type is non-static |
fb7f2fc4 | 7785 | |
eb66e842 | 7786 | when others => |
7787 | raise Non_Static; | |
7788 | end case; | |
7789 | end Get_RList; | |
fb7f2fc4 | 7790 | |
eb66e842 | 7791 | ------------ |
7792 | -- Hi_Val -- | |
7793 | ------------ | |
fb7f2fc4 | 7794 | |
eb66e842 | 7795 | function Hi_Val (N : Node_Id) return Uint is |
7796 | begin | |
cda40848 | 7797 | if Is_OK_Static_Expression (N) then |
eb66e842 | 7798 | return Expr_Value (N); |
7799 | else | |
7800 | pragma Assert (Nkind (N) = N_Range); | |
7801 | return Expr_Value (High_Bound (N)); | |
7802 | end if; | |
7803 | end Hi_Val; | |
fb7f2fc4 | 7804 | |
eb66e842 | 7805 | -------------- |
7806 | -- Is_False -- | |
7807 | -------------- | |
fb7f2fc4 | 7808 | |
eb66e842 | 7809 | function Is_False (R : RList) return Boolean is |
7810 | begin | |
7811 | return R'Length = 0; | |
7812 | end Is_False; | |
9dc88aea | 7813 | |
eb66e842 | 7814 | ------------- |
7815 | -- Is_True -- | |
7816 | ------------- | |
9dc88aea | 7817 | |
eb66e842 | 7818 | function Is_True (R : RList) return Boolean is |
7819 | begin | |
7820 | return R'Length = 1 | |
7821 | and then R (R'First).Lo = BLo | |
7822 | and then R (R'First).Hi = BHi; | |
7823 | end Is_True; | |
9dc88aea | 7824 | |
eb66e842 | 7825 | ----------------- |
7826 | -- Is_Type_Ref -- | |
7827 | ----------------- | |
9dc88aea | 7828 | |
eb66e842 | 7829 | function Is_Type_Ref (N : Node_Id) return Boolean is |
7830 | begin | |
7de4cba3 | 7831 | return Nkind (N) = N_Identifier |
7832 | and then Chars (N) = Nam | |
7833 | and then Paren_Count (N) = 0; | |
eb66e842 | 7834 | end Is_Type_Ref; |
9dc88aea | 7835 | |
eb66e842 | 7836 | ------------ |
7837 | -- Lo_Val -- | |
7838 | ------------ | |
9dc88aea | 7839 | |
eb66e842 | 7840 | function Lo_Val (N : Node_Id) return Uint is |
84c8f0b8 | 7841 | begin |
cda40848 | 7842 | if Is_OK_Static_Expression (N) then |
eb66e842 | 7843 | return Expr_Value (N); |
84c8f0b8 | 7844 | else |
eb66e842 | 7845 | pragma Assert (Nkind (N) = N_Range); |
7846 | return Expr_Value (Low_Bound (N)); | |
84c8f0b8 | 7847 | end if; |
eb66e842 | 7848 | end Lo_Val; |
d97beb2f | 7849 | |
eb66e842 | 7850 | ------------------------ |
7851 | -- Membership_Entries -- | |
7852 | ------------------------ | |
d97beb2f | 7853 | |
eb66e842 | 7854 | function Membership_Entries (N : Node_Id) return RList is |
84c8f0b8 | 7855 | begin |
eb66e842 | 7856 | if No (Next (N)) then |
7857 | return Membership_Entry (N); | |
84c8f0b8 | 7858 | else |
eb66e842 | 7859 | return Membership_Entry (N) or Membership_Entries (Next (N)); |
84c8f0b8 | 7860 | end if; |
eb66e842 | 7861 | end Membership_Entries; |
84c8f0b8 | 7862 | |
eb66e842 | 7863 | ---------------------- |
7864 | -- Membership_Entry -- | |
7865 | ---------------------- | |
84c8f0b8 | 7866 | |
eb66e842 | 7867 | function Membership_Entry (N : Node_Id) return RList is |
7868 | Val : Uint; | |
7869 | SLo : Uint; | |
7870 | SHi : Uint; | |
d97beb2f | 7871 | |
eb66e842 | 7872 | begin |
7873 | -- Range case | |
d97beb2f | 7874 | |
eb66e842 | 7875 | if Nkind (N) = N_Range then |
cda40848 | 7876 | if not Is_OK_Static_Expression (Low_Bound (N)) |
eb66e842 | 7877 | or else |
cda40848 | 7878 | not Is_OK_Static_Expression (High_Bound (N)) |
eb66e842 | 7879 | then |
7880 | raise Non_Static; | |
7881 | else | |
7882 | SLo := Expr_Value (Low_Bound (N)); | |
7883 | SHi := Expr_Value (High_Bound (N)); | |
7884 | return RList'(1 => REnt'(SLo, SHi)); | |
7885 | end if; | |
84c8f0b8 | 7886 | |
eb66e842 | 7887 | -- Static expression case |
84c8f0b8 | 7888 | |
cda40848 | 7889 | elsif Is_OK_Static_Expression (N) then |
eb66e842 | 7890 | Val := Expr_Value (N); |
7891 | return RList'(1 => REnt'(Val, Val)); | |
d97beb2f | 7892 | |
eb66e842 | 7893 | -- Identifier (other than static expression) case |
d97beb2f | 7894 | |
eb66e842 | 7895 | else pragma Assert (Nkind (N) = N_Identifier); |
d97beb2f | 7896 | |
eb66e842 | 7897 | -- Type case |
d97beb2f | 7898 | |
eb66e842 | 7899 | if Is_Type (Entity (N)) then |
d97beb2f | 7900 | |
eb66e842 | 7901 | -- If type has predicates, process them |
d97beb2f | 7902 | |
eb66e842 | 7903 | if Has_Predicates (Entity (N)) then |
7904 | return Stat_Pred (Entity (N)); | |
d97beb2f | 7905 | |
eb66e842 | 7906 | -- For static subtype without predicates, get range |
9dc88aea | 7907 | |
cda40848 | 7908 | elsif Is_OK_Static_Subtype (Entity (N)) then |
eb66e842 | 7909 | SLo := Expr_Value (Type_Low_Bound (Entity (N))); |
7910 | SHi := Expr_Value (Type_High_Bound (Entity (N))); | |
7911 | return RList'(1 => REnt'(SLo, SHi)); | |
9f269bd8 | 7912 | |
eb66e842 | 7913 | -- Any other type makes us non-static |
9f269bd8 | 7914 | |
eb66e842 | 7915 | else |
7916 | raise Non_Static; | |
7917 | end if; | |
84c8f0b8 | 7918 | |
eb66e842 | 7919 | -- Any other kind of identifier in predicate (e.g. a non-static |
7920 | -- expression value) means this is not a static predicate. | |
84c8f0b8 | 7921 | |
eb66e842 | 7922 | else |
7923 | raise Non_Static; | |
7924 | end if; | |
7925 | end if; | |
7926 | end Membership_Entry; | |
84c8f0b8 | 7927 | |
eb66e842 | 7928 | --------------- |
7929 | -- Stat_Pred -- | |
7930 | --------------- | |
84c8f0b8 | 7931 | |
eb66e842 | 7932 | function Stat_Pred (Typ : Entity_Id) return RList is |
7933 | begin | |
7934 | -- Not static if type does not have static predicates | |
84c8f0b8 | 7935 | |
5c6a5792 | 7936 | if not Has_Static_Predicate (Typ) then |
eb66e842 | 7937 | raise Non_Static; |
7938 | end if; | |
84c8f0b8 | 7939 | |
eb66e842 | 7940 | -- Otherwise we convert the predicate list to a range list |
84c8f0b8 | 7941 | |
eb66e842 | 7942 | declare |
5c6a5792 | 7943 | Spred : constant List_Id := Static_Discrete_Predicate (Typ); |
7944 | Result : RList (1 .. List_Length (Spred)); | |
eb66e842 | 7945 | P : Node_Id; |
84c8f0b8 | 7946 | |
eb66e842 | 7947 | begin |
5c6a5792 | 7948 | P := First (Static_Discrete_Predicate (Typ)); |
eb66e842 | 7949 | for J in Result'Range loop |
7950 | Result (J) := REnt'(Lo_Val (P), Hi_Val (P)); | |
7951 | Next (P); | |
7952 | end loop; | |
84c8f0b8 | 7953 | |
eb66e842 | 7954 | return Result; |
7955 | end; | |
7956 | end Stat_Pred; | |
84c8f0b8 | 7957 | |
eb66e842 | 7958 | -- Start of processing for Build_Discrete_Static_Predicate |
84c8f0b8 | 7959 | |
eb66e842 | 7960 | begin |
fdec445e | 7961 | -- Establish bounds for the predicate |
afc229da | 7962 | |
7963 | if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then | |
7964 | TLo := Expr_Value (Type_Low_Bound (Typ)); | |
7965 | else | |
7966 | TLo := BLo; | |
7967 | end if; | |
7968 | ||
7969 | if Compile_Time_Known_Value (Type_High_Bound (Typ)) then | |
7970 | THi := Expr_Value (Type_High_Bound (Typ)); | |
7971 | else | |
7972 | THi := BHi; | |
7973 | end if; | |
7974 | ||
eb66e842 | 7975 | -- Analyze the expression to see if it is a static predicate |
84c8f0b8 | 7976 | |
eb66e842 | 7977 | declare |
7978 | Ranges : constant RList := Get_RList (Expr); | |
7979 | -- Range list from expression if it is static | |
84c8f0b8 | 7980 | |
eb66e842 | 7981 | Plist : List_Id; |
84c8f0b8 | 7982 | |
eb66e842 | 7983 | begin |
7984 | -- Convert range list into a form for the static predicate. In the | |
7985 | -- Ranges array, we just have raw ranges, these must be converted | |
7986 | -- to properly typed and analyzed static expressions or range nodes. | |
84c8f0b8 | 7987 | |
eb66e842 | 7988 | -- Note: here we limit ranges to the ranges of the subtype, so that |
7989 | -- a predicate is always false for values outside the subtype. That | |
7990 | -- seems fine, such values are invalid anyway, and considering them | |
7991 | -- to fail the predicate seems allowed and friendly, and furthermore | |
7992 | -- simplifies processing for case statements and loops. | |
84c8f0b8 | 7993 | |
eb66e842 | 7994 | Plist := New_List; |
7995 | ||
7996 | for J in Ranges'Range loop | |
84c8f0b8 | 7997 | declare |
eb66e842 | 7998 | Lo : Uint := Ranges (J).Lo; |
7999 | Hi : Uint := Ranges (J).Hi; | |
84c8f0b8 | 8000 | |
eb66e842 | 8001 | begin |
8002 | -- Ignore completely out of range entry | |
84c8f0b8 | 8003 | |
eb66e842 | 8004 | if Hi < TLo or else Lo > THi then |
8005 | null; | |
84c8f0b8 | 8006 | |
eb66e842 | 8007 | -- Otherwise process entry |
84c8f0b8 | 8008 | |
eb66e842 | 8009 | else |
8010 | -- Adjust out of range value to subtype range | |
490beba6 | 8011 | |
eb66e842 | 8012 | if Lo < TLo then |
8013 | Lo := TLo; | |
8014 | end if; | |
490beba6 | 8015 | |
eb66e842 | 8016 | if Hi > THi then |
8017 | Hi := THi; | |
8018 | end if; | |
84c8f0b8 | 8019 | |
eb66e842 | 8020 | -- Convert range into required form |
84c8f0b8 | 8021 | |
eb66e842 | 8022 | Append_To (Plist, Build_Range (Lo, Hi)); |
84c8f0b8 | 8023 | end if; |
eb66e842 | 8024 | end; |
8025 | end loop; | |
84c8f0b8 | 8026 | |
eb66e842 | 8027 | -- Processing was successful and all entries were static, so now we |
8028 | -- can store the result as the predicate list. | |
84c8f0b8 | 8029 | |
5c6a5792 | 8030 | Set_Static_Discrete_Predicate (Typ, Plist); |
84c8f0b8 | 8031 | |
eb66e842 | 8032 | -- The processing for static predicates put the expression into |
8033 | -- canonical form as a series of ranges. It also eliminated | |
8034 | -- duplicates and collapsed and combined ranges. We might as well | |
8035 | -- replace the alternatives list of the right operand of the | |
8036 | -- membership test with the static predicate list, which will | |
8037 | -- usually be more efficient. | |
84c8f0b8 | 8038 | |
eb66e842 | 8039 | declare |
8040 | New_Alts : constant List_Id := New_List; | |
8041 | Old_Node : Node_Id; | |
8042 | New_Node : Node_Id; | |
84c8f0b8 | 8043 | |
eb66e842 | 8044 | begin |
8045 | Old_Node := First (Plist); | |
8046 | while Present (Old_Node) loop | |
8047 | New_Node := New_Copy (Old_Node); | |
84c8f0b8 | 8048 | |
eb66e842 | 8049 | if Nkind (New_Node) = N_Range then |
8050 | Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node))); | |
8051 | Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node))); | |
8052 | end if; | |
84c8f0b8 | 8053 | |
eb66e842 | 8054 | Append_To (New_Alts, New_Node); |
8055 | Next (Old_Node); | |
8056 | end loop; | |
84c8f0b8 | 8057 | |
eb66e842 | 8058 | -- If empty list, replace by False |
84c8f0b8 | 8059 | |
eb66e842 | 8060 | if Is_Empty_List (New_Alts) then |
8061 | Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc)); | |
84c8f0b8 | 8062 | |
eb66e842 | 8063 | -- Else replace by set membership test |
84c8f0b8 | 8064 | |
eb66e842 | 8065 | else |
8066 | Rewrite (Expr, | |
8067 | Make_In (Loc, | |
8068 | Left_Opnd => Make_Identifier (Loc, Nam), | |
8069 | Right_Opnd => Empty, | |
8070 | Alternatives => New_Alts)); | |
490beba6 | 8071 | |
eb66e842 | 8072 | -- Resolve new expression in function context |
490beba6 | 8073 | |
eb66e842 | 8074 | Install_Formals (Predicate_Function (Typ)); |
8075 | Push_Scope (Predicate_Function (Typ)); | |
8076 | Analyze_And_Resolve (Expr, Standard_Boolean); | |
8077 | Pop_Scope; | |
8078 | end if; | |
8079 | end; | |
8080 | end; | |
9ab32fe9 | 8081 | |
eb66e842 | 8082 | -- If non-static, return doing nothing |
9ab32fe9 | 8083 | |
eb66e842 | 8084 | exception |
8085 | when Non_Static => | |
8086 | return; | |
8087 | end Build_Discrete_Static_Predicate; | |
64cc9e5d | 8088 | |
ee2b7923 | 8089 | -------------------------------- |
8090 | -- Build_Export_Import_Pragma -- | |
8091 | -------------------------------- | |
8092 | ||
8093 | function Build_Export_Import_Pragma | |
8094 | (Asp : Node_Id; | |
8095 | Id : Entity_Id) return Node_Id | |
8096 | is | |
8097 | Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp); | |
8098 | Expr : constant Node_Id := Expression (Asp); | |
8099 | Loc : constant Source_Ptr := Sloc (Asp); | |
8100 | ||
8101 | Args : List_Id; | |
8102 | Conv : Node_Id; | |
8103 | Conv_Arg : Node_Id; | |
8104 | Dummy_1 : Node_Id; | |
8105 | Dummy_2 : Node_Id; | |
8106 | EN : Node_Id; | |
8107 | LN : Node_Id; | |
8108 | Prag : Node_Id; | |
8109 | ||
8110 | Create_Pragma : Boolean := False; | |
8111 | -- This flag is set when the aspect form is such that it warrants the | |
8112 | -- creation of a corresponding pragma. | |
8113 | ||
8114 | begin | |
8115 | if Present (Expr) then | |
8116 | if Error_Posted (Expr) then | |
8117 | null; | |
8118 | ||
8119 | elsif Is_True (Expr_Value (Expr)) then | |
8120 | Create_Pragma := True; | |
8121 | end if; | |
8122 | ||
8123 | -- Otherwise the aspect defaults to True | |
8124 | ||
8125 | else | |
8126 | Create_Pragma := True; | |
8127 | end if; | |
8128 | ||
8129 | -- Nothing to do when the expression is False or is erroneous | |
8130 | ||
8131 | if not Create_Pragma then | |
8132 | return Empty; | |
8133 | end if; | |
8134 | ||
8135 | -- Obtain all interfacing aspects that apply to the related entity | |
8136 | ||
8137 | Get_Interfacing_Aspects | |
8138 | (Iface_Asp => Asp, | |
8139 | Conv_Asp => Conv, | |
8140 | EN_Asp => EN, | |
8141 | Expo_Asp => Dummy_1, | |
8142 | Imp_Asp => Dummy_2, | |
8143 | LN_Asp => LN); | |
8144 | ||
8145 | Args := New_List; | |
8146 | ||
8147 | -- Handle the convention argument | |
8148 | ||
8149 | if Present (Conv) then | |
8150 | Conv_Arg := New_Copy_Tree (Expression (Conv)); | |
8151 | ||
8152 | -- Assume convention "Ada' when aspect Convention is missing | |
8153 | ||
8154 | else | |
8155 | Conv_Arg := Make_Identifier (Loc, Name_Ada); | |
8156 | end if; | |
8157 | ||
8158 | Append_To (Args, | |
8159 | Make_Pragma_Argument_Association (Loc, | |
8160 | Chars => Name_Convention, | |
8161 | Expression => Conv_Arg)); | |
8162 | ||
8163 | -- Handle the entity argument | |
8164 | ||
8165 | Append_To (Args, | |
8166 | Make_Pragma_Argument_Association (Loc, | |
8167 | Chars => Name_Entity, | |
8168 | Expression => New_Occurrence_Of (Id, Loc))); | |
8169 | ||
8170 | -- Handle the External_Name argument | |
8171 | ||
8172 | if Present (EN) then | |
8173 | Append_To (Args, | |
8174 | Make_Pragma_Argument_Association (Loc, | |
8175 | Chars => Name_External_Name, | |
8176 | Expression => New_Copy_Tree (Expression (EN)))); | |
8177 | end if; | |
8178 | ||
8179 | -- Handle the Link_Name argument | |
8180 | ||
8181 | if Present (LN) then | |
8182 | Append_To (Args, | |
8183 | Make_Pragma_Argument_Association (Loc, | |
8184 | Chars => Name_Link_Name, | |
8185 | Expression => New_Copy_Tree (Expression (LN)))); | |
8186 | end if; | |
8187 | ||
8188 | -- Generate: | |
8189 | -- pragma Export/Import | |
8190 | -- (Convention => <Conv>/Ada, | |
8191 | -- Entity => <Id>, | |
8192 | -- [External_Name => <EN>,] | |
8193 | -- [Link_Name => <LN>]); | |
8194 | ||
8195 | Prag := | |
8196 | Make_Pragma (Loc, | |
8197 | Pragma_Identifier => | |
8198 | Make_Identifier (Loc, Chars (Identifier (Asp))), | |
8199 | Pragma_Argument_Associations => Args); | |
8200 | ||
8201 | -- Decorate the relevant aspect and the pragma | |
8202 | ||
8203 | Set_Aspect_Rep_Item (Asp, Prag); | |
8204 | ||
8205 | Set_Corresponding_Aspect (Prag, Asp); | |
8206 | Set_From_Aspect_Specification (Prag); | |
8207 | Set_Parent (Prag, Asp); | |
8208 | ||
8209 | if Asp_Id = Aspect_Import and then Is_Subprogram (Id) then | |
8210 | Set_Import_Pragma (Id, Prag); | |
8211 | end if; | |
8212 | ||
8213 | return Prag; | |
8214 | end Build_Export_Import_Pragma; | |
8215 | ||
eb66e842 | 8216 | ------------------------------- |
8217 | -- Build_Predicate_Functions -- | |
8218 | ------------------------------- | |
d9f6a4ee | 8219 | |
eb66e842 | 8220 | -- The procedures that are constructed here have the form: |
d9f6a4ee | 8221 | |
eb66e842 | 8222 | -- function typPredicate (Ixxx : typ) return Boolean is |
8223 | -- begin | |
8224 | -- return | |
75491446 | 8225 | -- typ1Predicate (typ1 (Ixxx)) |
eb66e842 | 8226 | -- and then typ2Predicate (typ2 (Ixxx)) |
8227 | -- and then ...; | |
75491446 | 8228 | -- exp1 and then exp2 and then ... |
eb66e842 | 8229 | -- end typPredicate; |
d9f6a4ee | 8230 | |
eb66e842 | 8231 | -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that |
8232 | -- this is the point at which these expressions get analyzed, providing the | |
8233 | -- required delay, and typ1, typ2, are entities from which predicates are | |
8234 | -- inherited. Note that we do NOT generate Check pragmas, that's because we | |
8235 | -- use this function even if checks are off, e.g. for membership tests. | |
d9f6a4ee | 8236 | |
75491446 | 8237 | -- Note that the inherited predicates are evaluated first, as required by |
8238 | -- AI12-0071-1. | |
8239 | ||
8240 | -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on | |
8241 | -- the form of this return expression. | |
8242 | ||
eb66e842 | 8243 | -- If the expression has at least one Raise_Expression, then we also build |
8244 | -- the typPredicateM version of the function, in which any occurrence of a | |
8245 | -- Raise_Expression is converted to "return False". | |
d9f6a4ee | 8246 | |
eb66e842 | 8247 | procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is |
8248 | Loc : constant Source_Ptr := Sloc (Typ); | |
d9f6a4ee | 8249 | |
eb66e842 | 8250 | Expr : Node_Id; |
8251 | -- This is the expression for the result of the function. It is | |
8252 | -- is build by connecting the component predicates with AND THEN. | |
d9f6a4ee | 8253 | |
eb66e842 | 8254 | Expr_M : Node_Id; |
8255 | -- This is the corresponding return expression for the Predicate_M | |
8256 | -- function. It differs in that raise expressions are marked for | |
8257 | -- special expansion (see Process_REs). | |
d9f6a4ee | 8258 | |
9c20237a | 8259 | Object_Name : Name_Id; |
eb66e842 | 8260 | -- Name for argument of Predicate procedure. Note that we use the same |
499918a7 | 8261 | -- name for both predicate functions. That way the reference within the |
eb66e842 | 8262 | -- predicate expression is the same in both functions. |
d9f6a4ee | 8263 | |
9c20237a | 8264 | Object_Entity : Entity_Id; |
eb66e842 | 8265 | -- Entity for argument of Predicate procedure |
d9f6a4ee | 8266 | |
9c20237a | 8267 | Object_Entity_M : Entity_Id; |
8268 | -- Entity for argument of separate Predicate procedure when exceptions | |
8269 | -- are present in expression. | |
8270 | ||
02e5d0d0 | 8271 | FDecl : Node_Id; |
8272 | -- The function declaration | |
9c20237a | 8273 | |
02e5d0d0 | 8274 | SId : Entity_Id; |
8275 | -- Its entity | |
d9f6a4ee | 8276 | |
eb66e842 | 8277 | Raise_Expression_Present : Boolean := False; |
8278 | -- Set True if Expr has at least one Raise_Expression | |
d9f6a4ee | 8279 | |
75491446 | 8280 | procedure Add_Condition (Cond : Node_Id); |
8281 | -- Append Cond to Expr using "and then" (or just copy Cond to Expr if | |
8282 | -- Expr is empty). | |
d9f6a4ee | 8283 | |
eb66e842 | 8284 | procedure Add_Predicates; |
8285 | -- Appends expressions for any Predicate pragmas in the rep item chain | |
8286 | -- Typ to Expr. Note that we look only at items for this exact entity. | |
8287 | -- Inheritance of predicates for the parent type is done by calling the | |
8288 | -- Predicate_Function of the parent type, using Add_Call above. | |
d9f6a4ee | 8289 | |
75491446 | 8290 | procedure Add_Call (T : Entity_Id); |
8291 | -- Includes a call to the predicate function for type T in Expr if T | |
8292 | -- has predicates and Predicate_Function (T) is non-empty. | |
8293 | ||
eb66e842 | 8294 | function Process_RE (N : Node_Id) return Traverse_Result; |
8295 | -- Used in Process REs, tests if node N is a raise expression, and if | |
8296 | -- so, marks it to be converted to return False. | |
d9f6a4ee | 8297 | |
eb66e842 | 8298 | procedure Process_REs is new Traverse_Proc (Process_RE); |
8299 | -- Marks any raise expressions in Expr_M to return False | |
d9f6a4ee | 8300 | |
f9e26ff7 | 8301 | function Test_RE (N : Node_Id) return Traverse_Result; |
8302 | -- Used in Test_REs, tests one node for being a raise expression, and if | |
8303 | -- so sets Raise_Expression_Present True. | |
8304 | ||
8305 | procedure Test_REs is new Traverse_Proc (Test_RE); | |
8306 | -- Tests to see if Expr contains any raise expressions | |
8307 | ||
eb66e842 | 8308 | -------------- |
8309 | -- Add_Call -- | |
8310 | -------------- | |
d9f6a4ee | 8311 | |
eb66e842 | 8312 | procedure Add_Call (T : Entity_Id) is |
8313 | Exp : Node_Id; | |
d9f6a4ee | 8314 | |
eb66e842 | 8315 | begin |
8316 | if Present (T) and then Present (Predicate_Function (T)) then | |
8317 | Set_Has_Predicates (Typ); | |
d9f6a4ee | 8318 | |
eb66e842 | 8319 | -- Build the call to the predicate function of T |
d9f6a4ee | 8320 | |
eb66e842 | 8321 | Exp := |
8322 | Make_Predicate_Call | |
8323 | (T, Convert_To (T, Make_Identifier (Loc, Object_Name))); | |
d9f6a4ee | 8324 | |
75491446 | 8325 | -- "and"-in the call to evolving expression |
d9f6a4ee | 8326 | |
75491446 | 8327 | Add_Condition (Exp); |
d9f6a4ee | 8328 | |
eb66e842 | 8329 | -- Output info message on inheritance if required. Note we do not |
8330 | -- give this information for generic actual types, since it is | |
8331 | -- unwelcome noise in that case in instantiations. We also | |
8332 | -- generally suppress the message in instantiations, and also | |
8333 | -- if it involves internal names. | |
d9f6a4ee | 8334 | |
eb66e842 | 8335 | if Opt.List_Inherited_Aspects |
8336 | and then not Is_Generic_Actual_Type (Typ) | |
8337 | and then Instantiation_Depth (Sloc (Typ)) = 0 | |
8338 | and then not Is_Internal_Name (Chars (T)) | |
8339 | and then not Is_Internal_Name (Chars (Typ)) | |
8340 | then | |
8341 | Error_Msg_Sloc := Sloc (Predicate_Function (T)); | |
8342 | Error_Msg_Node_2 := T; | |
8343 | Error_Msg_N ("info: & inherits predicate from & #?L?", Typ); | |
8344 | end if; | |
8345 | end if; | |
8346 | end Add_Call; | |
d9f6a4ee | 8347 | |
75491446 | 8348 | ------------------- |
8349 | -- Add_Condition -- | |
8350 | ------------------- | |
8351 | ||
8352 | procedure Add_Condition (Cond : Node_Id) is | |
8353 | begin | |
8354 | -- This is the first predicate expression | |
8355 | ||
8356 | if No (Expr) then | |
8357 | Expr := Cond; | |
8358 | ||
8359 | -- Otherwise concatenate to the existing predicate expressions by | |
8360 | -- using "and then". | |
8361 | ||
8362 | else | |
8363 | Expr := | |
8364 | Make_And_Then (Loc, | |
8365 | Left_Opnd => Relocate_Node (Expr), | |
8366 | Right_Opnd => Cond); | |
8367 | end if; | |
8368 | end Add_Condition; | |
8369 | ||
eb66e842 | 8370 | -------------------- |
8371 | -- Add_Predicates -- | |
8372 | -------------------- | |
d9f6a4ee | 8373 | |
eb66e842 | 8374 | procedure Add_Predicates is |
f9e26ff7 | 8375 | procedure Add_Predicate (Prag : Node_Id); |
8376 | -- Concatenate the expression of predicate pragma Prag to Expr by | |
8377 | -- using a short circuit "and then" operator. | |
d9f6a4ee | 8378 | |
f9e26ff7 | 8379 | ------------------- |
8380 | -- Add_Predicate -- | |
8381 | ------------------- | |
d9f6a4ee | 8382 | |
f9e26ff7 | 8383 | procedure Add_Predicate (Prag : Node_Id) is |
8384 | procedure Replace_Type_Reference (N : Node_Id); | |
8385 | -- Replace a single occurrence N of the subtype name with a | |
8386 | -- reference to the formal of the predicate function. N can be an | |
8387 | -- identifier referencing the subtype, or a selected component, | |
8388 | -- representing an appropriately qualified occurrence of the | |
8389 | -- subtype name. | |
8390 | ||
8391 | procedure Replace_Type_References is | |
8392 | new Replace_Type_References_Generic (Replace_Type_Reference); | |
8393 | -- Traverse an expression changing every occurrence of an | |
8394 | -- identifier whose name matches the name of the subtype with a | |
8395 | -- reference to the formal parameter of the predicate function. | |
8396 | ||
8397 | ---------------------------- | |
8398 | -- Replace_Type_Reference -- | |
8399 | ---------------------------- | |
8400 | ||
8401 | procedure Replace_Type_Reference (N : Node_Id) is | |
8402 | begin | |
8403 | Rewrite (N, Make_Identifier (Sloc (N), Object_Name)); | |
8404 | -- Use the Sloc of the usage name, not the defining name | |
d9f6a4ee | 8405 | |
f9e26ff7 | 8406 | Set_Etype (N, Typ); |
8407 | Set_Entity (N, Object_Entity); | |
d97beb2f | 8408 | |
f9e26ff7 | 8409 | -- We want to treat the node as if it comes from source, so |
8410 | -- that ASIS will not ignore it. | |
d97beb2f | 8411 | |
f9e26ff7 | 8412 | Set_Comes_From_Source (N, True); |
8413 | end Replace_Type_Reference; | |
d97beb2f | 8414 | |
f9e26ff7 | 8415 | -- Local variables |
d97beb2f | 8416 | |
f9e26ff7 | 8417 | Asp : constant Node_Id := Corresponding_Aspect (Prag); |
8418 | Arg1 : Node_Id; | |
8419 | Arg2 : Node_Id; | |
d97beb2f | 8420 | |
f9e26ff7 | 8421 | -- Start of processing for Add_Predicate |
24c8d764 | 8422 | |
f9e26ff7 | 8423 | begin |
8424 | -- Extract the arguments of the pragma. The expression itself | |
8425 | -- is copied for use in the predicate function, to preserve the | |
8426 | -- original version for ASIS use. | |
d97beb2f | 8427 | |
f9e26ff7 | 8428 | Arg1 := First (Pragma_Argument_Associations (Prag)); |
8429 | Arg2 := Next (Arg1); | |
d97beb2f | 8430 | |
f9e26ff7 | 8431 | Arg1 := Get_Pragma_Arg (Arg1); |
8432 | Arg2 := New_Copy_Tree (Get_Pragma_Arg (Arg2)); | |
d97beb2f | 8433 | |
f9e26ff7 | 8434 | -- When the predicate pragma applies to the current type or its |
8435 | -- full view, replace all occurrences of the subtype name with | |
8436 | -- references to the formal parameter of the predicate function. | |
639c3741 | 8437 | |
f9e26ff7 | 8438 | if Entity (Arg1) = Typ |
8439 | or else Full_View (Entity (Arg1)) = Typ | |
8440 | then | |
8441 | Replace_Type_References (Arg2, Typ); | |
639c3741 | 8442 | |
f9e26ff7 | 8443 | -- If the predicate pragma comes from an aspect, replace the |
8444 | -- saved expression because we need the subtype references | |
8445 | -- replaced for the calls to Preanalyze_Spec_Expression in | |
8446 | -- Check_Aspect_At_xxx routines. | |
639c3741 | 8447 | |
f9e26ff7 | 8448 | if Present (Asp) then |
f9e26ff7 | 8449 | Set_Entity (Identifier (Asp), New_Copy_Tree (Arg2)); |
8450 | end if; | |
24c8d764 | 8451 | |
75491446 | 8452 | -- "and"-in the Arg2 condition to evolving expression |
639c3741 | 8453 | |
75491446 | 8454 | Add_Condition (Relocate_Node (Arg2)); |
f9e26ff7 | 8455 | end if; |
8456 | end Add_Predicate; | |
737e8460 | 8457 | |
f9e26ff7 | 8458 | -- Local variables |
737e8460 | 8459 | |
f9e26ff7 | 8460 | Ritem : Node_Id; |
d97beb2f | 8461 | |
f9e26ff7 | 8462 | -- Start of processing for Add_Predicates |
d97beb2f | 8463 | |
f9e26ff7 | 8464 | begin |
8465 | Ritem := First_Rep_Item (Typ); | |
8466 | while Present (Ritem) loop | |
8467 | if Nkind (Ritem) = N_Pragma | |
ddccc924 | 8468 | and then Pragma_Name (Ritem) = Name_Predicate |
f9e26ff7 | 8469 | then |
8470 | Add_Predicate (Ritem); | |
0ea02224 | 8471 | |
8472 | -- If the type is declared in an inner package it may be frozen | |
8473 | -- outside of the package, and the generated pragma has not been | |
8474 | -- analyzed yet, so capture the expression for the predicate | |
8475 | -- function at this point. | |
8476 | ||
8477 | elsif Nkind (Ritem) = N_Aspect_Specification | |
238921ae | 8478 | and then Present (Aspect_Rep_Item (Ritem)) |
8479 | and then Scope (Typ) /= Current_Scope | |
0ea02224 | 8480 | then |
8481 | declare | |
8482 | Prag : constant Node_Id := Aspect_Rep_Item (Ritem); | |
8483 | ||
8484 | begin | |
8485 | if Nkind (Prag) = N_Pragma | |
ddccc924 | 8486 | and then Pragma_Name (Prag) = Name_Predicate |
0ea02224 | 8487 | then |
8488 | Add_Predicate (Prag); | |
8489 | end if; | |
8490 | end; | |
eb66e842 | 8491 | end if; |
d97beb2f | 8492 | |
eb66e842 | 8493 | Next_Rep_Item (Ritem); |
8494 | end loop; | |
8495 | end Add_Predicates; | |
d97beb2f | 8496 | |
eb66e842 | 8497 | ---------------- |
8498 | -- Process_RE -- | |
8499 | ---------------- | |
d97beb2f | 8500 | |
eb66e842 | 8501 | function Process_RE (N : Node_Id) return Traverse_Result is |
d9f6a4ee | 8502 | begin |
eb66e842 | 8503 | if Nkind (N) = N_Raise_Expression then |
8504 | Set_Convert_To_Return_False (N); | |
8505 | return Skip; | |
d9f6a4ee | 8506 | else |
eb66e842 | 8507 | return OK; |
d9f6a4ee | 8508 | end if; |
eb66e842 | 8509 | end Process_RE; |
d7c2851f | 8510 | |
d9f6a4ee | 8511 | ------------- |
eb66e842 | 8512 | -- Test_RE -- |
d9f6a4ee | 8513 | ------------- |
d7c2851f | 8514 | |
eb66e842 | 8515 | function Test_RE (N : Node_Id) return Traverse_Result is |
d97beb2f | 8516 | begin |
eb66e842 | 8517 | if Nkind (N) = N_Raise_Expression then |
8518 | Raise_Expression_Present := True; | |
8519 | return Abandon; | |
8520 | else | |
8521 | return OK; | |
8522 | end if; | |
8523 | end Test_RE; | |
d97beb2f | 8524 | |
f9e26ff7 | 8525 | -- Local variables |
8526 | ||
72a98436 | 8527 | Mode : Ghost_Mode_Type; |
f9e26ff7 | 8528 | |
eb66e842 | 8529 | -- Start of processing for Build_Predicate_Functions |
d97beb2f | 8530 | |
eb66e842 | 8531 | begin |
8532 | -- Return if already built or if type does not have predicates | |
9dc88aea | 8533 | |
9c20237a | 8534 | SId := Predicate_Function (Typ); |
eb66e842 | 8535 | if not Has_Predicates (Typ) |
9c20237a | 8536 | or else (Present (SId) and then Has_Completion (SId)) |
eb66e842 | 8537 | then |
8538 | return; | |
8539 | end if; | |
d9f6a4ee | 8540 | |
30f8d103 | 8541 | -- The related type may be subject to pragma Ghost. Set the mode now to |
8542 | -- ensure that the predicate functions are properly marked as Ghost. | |
f9e26ff7 | 8543 | |
72a98436 | 8544 | Set_Ghost_Mode (Typ, Mode); |
f9e26ff7 | 8545 | |
eb66e842 | 8546 | -- Prepare to construct predicate expression |
d97beb2f | 8547 | |
eb66e842 | 8548 | Expr := Empty; |
d97beb2f | 8549 | |
9c20237a | 8550 | if Present (SId) then |
8551 | FDecl := Unit_Declaration_Node (SId); | |
8552 | ||
8553 | else | |
8554 | FDecl := Build_Predicate_Function_Declaration (Typ); | |
8555 | SId := Defining_Entity (FDecl); | |
8556 | end if; | |
8557 | ||
8558 | -- Recover name of formal parameter of function that replaces references | |
8559 | -- to the type in predicate expressions. | |
8560 | ||
8561 | Object_Entity := | |
8562 | Defining_Identifier | |
8563 | (First (Parameter_Specifications (Specification (FDecl)))); | |
8564 | ||
8565 | Object_Name := Chars (Object_Entity); | |
8566 | Object_Entity_M := Make_Defining_Identifier (Loc, Chars => Object_Name); | |
8567 | ||
75491446 | 8568 | -- Add predicates for ancestor if present. These must come before the |
8569 | -- ones for the current type, as required by AI12-0071-1. | |
d97beb2f | 8570 | |
eb66e842 | 8571 | declare |
8572 | Atyp : constant Entity_Id := Nearest_Ancestor (Typ); | |
d9f6a4ee | 8573 | begin |
eb66e842 | 8574 | if Present (Atyp) then |
8575 | Add_Call (Atyp); | |
8576 | end if; | |
8577 | end; | |
02e5d0d0 | 8578 | |
75491446 | 8579 | -- Add Predicates for the current type |
8580 | ||
8581 | Add_Predicates; | |
8582 | ||
eb66e842 | 8583 | -- Case where predicates are present |
9dc88aea | 8584 | |
eb66e842 | 8585 | if Present (Expr) then |
726fd56a | 8586 | |
eb66e842 | 8587 | -- Test for raise expression present |
726fd56a | 8588 | |
eb66e842 | 8589 | Test_REs (Expr); |
9dc88aea | 8590 | |
eb66e842 | 8591 | -- If raise expression is present, capture a copy of Expr for use |
8592 | -- in building the predicateM function version later on. For this | |
8593 | -- copy we replace references to Object_Entity by Object_Entity_M. | |
9dc88aea | 8594 | |
eb66e842 | 8595 | if Raise_Expression_Present then |
8596 | declare | |
299b347e | 8597 | Map : constant Elist_Id := New_Elmt_List; |
8598 | New_V : Entity_Id := Empty; | |
8599 | ||
8600 | -- The unanalyzed expression will be copied and appear in | |
8601 | -- both functions. Normally expressions do not declare new | |
8602 | -- entities, but quantified expressions do, so we need to | |
8603 | -- create new entities for their bound variables, to prevent | |
8604 | -- multiple definitions in gigi. | |
8605 | ||
8606 | function Reset_Loop_Variable (N : Node_Id) | |
8607 | return Traverse_Result; | |
8608 | ||
8609 | procedure Collect_Loop_Variables is | |
8610 | new Traverse_Proc (Reset_Loop_Variable); | |
8611 | ||
8612 | ------------------------ | |
8613 | -- Reset_Loop_Variable -- | |
8614 | ------------------------ | |
8615 | ||
8616 | function Reset_Loop_Variable (N : Node_Id) | |
8617 | return Traverse_Result | |
8618 | is | |
8619 | begin | |
8620 | if Nkind (N) = N_Iterator_Specification then | |
8621 | New_V := Make_Defining_Identifier | |
8622 | (Sloc (N), Chars (Defining_Identifier (N))); | |
8623 | ||
8624 | Set_Defining_Identifier (N, New_V); | |
8625 | end if; | |
8626 | ||
8627 | return OK; | |
8628 | end Reset_Loop_Variable; | |
8629 | ||
eb66e842 | 8630 | begin |
8631 | Append_Elmt (Object_Entity, Map); | |
8632 | Append_Elmt (Object_Entity_M, Map); | |
8633 | Expr_M := New_Copy_Tree (Expr, Map => Map); | |
299b347e | 8634 | Collect_Loop_Variables (Expr_M); |
eb66e842 | 8635 | end; |
8636 | end if; | |
d97beb2f | 8637 | |
eb66e842 | 8638 | -- Build the main predicate function |
9dc88aea | 8639 | |
eb66e842 | 8640 | declare |
eb66e842 | 8641 | SIdB : constant Entity_Id := |
8642 | Make_Defining_Identifier (Loc, | |
8643 | Chars => New_External_Name (Chars (Typ), "Predicate")); | |
8644 | -- The entity for the function body | |
9dc88aea | 8645 | |
eb66e842 | 8646 | Spec : Node_Id; |
eb66e842 | 8647 | FBody : Node_Id; |
9dc88aea | 8648 | |
eb66e842 | 8649 | begin |
eb66e842 | 8650 | -- The predicate function is shared between views of a type |
d97beb2f | 8651 | |
eb66e842 | 8652 | if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
8653 | Set_Predicate_Function (Full_View (Typ), SId); | |
d97beb2f | 8654 | end if; |
d97beb2f | 8655 | |
eb66e842 | 8656 | -- Build function body |
d97beb2f | 8657 | |
eb66e842 | 8658 | Spec := |
8659 | Make_Function_Specification (Loc, | |
8660 | Defining_Unit_Name => SIdB, | |
8661 | Parameter_Specifications => New_List ( | |
8662 | Make_Parameter_Specification (Loc, | |
8663 | Defining_Identifier => | |
8664 | Make_Defining_Identifier (Loc, Object_Name), | |
8665 | Parameter_Type => | |
8666 | New_Occurrence_Of (Typ, Loc))), | |
8667 | Result_Definition => | |
8668 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
d97beb2f | 8669 | |
eb66e842 | 8670 | FBody := |
8671 | Make_Subprogram_Body (Loc, | |
8672 | Specification => Spec, | |
8673 | Declarations => Empty_List, | |
8674 | Handled_Statement_Sequence => | |
8675 | Make_Handled_Sequence_Of_Statements (Loc, | |
8676 | Statements => New_List ( | |
8677 | Make_Simple_Return_Statement (Loc, | |
8678 | Expression => Expr)))); | |
9dc88aea | 8679 | |
9c20237a | 8680 | -- If declaration has not been analyzed yet, Insert declaration |
7db33803 | 8681 | -- before freeze node. Insert body itself after freeze node. |
9c20237a | 8682 | |
8683 | if not Analyzed (FDecl) then | |
8684 | Insert_Before_And_Analyze (N, FDecl); | |
8685 | end if; | |
d97beb2f | 8686 | |
02e5d0d0 | 8687 | Insert_After_And_Analyze (N, FBody); |
6958c62c | 8688 | |
8689 | -- Static predicate functions are always side-effect free, and | |
8690 | -- in most cases dynamic predicate functions are as well. Mark | |
8691 | -- them as such whenever possible, so redundant predicate checks | |
7dd0b9b3 | 8692 | -- can be optimized. If there is a variable reference within the |
8693 | -- expression, the function is not pure. | |
b2e821de | 8694 | |
6958c62c | 8695 | if Expander_Active then |
7dd0b9b3 | 8696 | Set_Is_Pure (SId, |
8697 | Side_Effect_Free (Expr, Variable_Ref => True)); | |
6958c62c | 8698 | Set_Is_Inlined (SId); |
8699 | end if; | |
d9f6a4ee | 8700 | end; |
d97beb2f | 8701 | |
eb66e842 | 8702 | -- Test for raise expressions present and if so build M version |
d97beb2f | 8703 | |
eb66e842 | 8704 | if Raise_Expression_Present then |
8705 | declare | |
8706 | SId : constant Entity_Id := | |
8707 | Make_Defining_Identifier (Loc, | |
8708 | Chars => New_External_Name (Chars (Typ), "PredicateM")); | |
c96806b2 | 8709 | -- The entity for the function spec |
d97beb2f | 8710 | |
eb66e842 | 8711 | SIdB : constant Entity_Id := |
8712 | Make_Defining_Identifier (Loc, | |
8713 | Chars => New_External_Name (Chars (Typ), "PredicateM")); | |
8714 | -- The entity for the function body | |
b9e61b2a | 8715 | |
eb66e842 | 8716 | Spec : Node_Id; |
eb66e842 | 8717 | FBody : Node_Id; |
9c20237a | 8718 | FDecl : Node_Id; |
eb66e842 | 8719 | BTemp : Entity_Id; |
d97beb2f | 8720 | |
eb66e842 | 8721 | begin |
8722 | -- Mark any raise expressions for special expansion | |
d97beb2f | 8723 | |
eb66e842 | 8724 | Process_REs (Expr_M); |
d97beb2f | 8725 | |
eb66e842 | 8726 | -- Build function declaration |
d97beb2f | 8727 | |
eb66e842 | 8728 | Set_Ekind (SId, E_Function); |
8729 | Set_Is_Predicate_Function_M (SId); | |
8730 | Set_Predicate_Function_M (Typ, SId); | |
d97beb2f | 8731 | |
eb66e842 | 8732 | -- The predicate function is shared between views of a type |
d97beb2f | 8733 | |
eb66e842 | 8734 | if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
8735 | Set_Predicate_Function_M (Full_View (Typ), SId); | |
8736 | end if; | |
9dc88aea | 8737 | |
eb66e842 | 8738 | Spec := |
8739 | Make_Function_Specification (Loc, | |
8740 | Defining_Unit_Name => SId, | |
8741 | Parameter_Specifications => New_List ( | |
8742 | Make_Parameter_Specification (Loc, | |
8743 | Defining_Identifier => Object_Entity_M, | |
8744 | Parameter_Type => New_Occurrence_Of (Typ, Loc))), | |
8745 | Result_Definition => | |
8746 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
9dc88aea | 8747 | |
eb66e842 | 8748 | FDecl := |
8749 | Make_Subprogram_Declaration (Loc, | |
8750 | Specification => Spec); | |
9dc88aea | 8751 | |
eb66e842 | 8752 | -- Build function body |
9dc88aea | 8753 | |
eb66e842 | 8754 | Spec := |
8755 | Make_Function_Specification (Loc, | |
8756 | Defining_Unit_Name => SIdB, | |
8757 | Parameter_Specifications => New_List ( | |
8758 | Make_Parameter_Specification (Loc, | |
8759 | Defining_Identifier => | |
8760 | Make_Defining_Identifier (Loc, Object_Name), | |
8761 | Parameter_Type => | |
8762 | New_Occurrence_Of (Typ, Loc))), | |
8763 | Result_Definition => | |
8764 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
9dc88aea | 8765 | |
eb66e842 | 8766 | -- Build the body, we declare the boolean expression before |
8767 | -- doing the return, because we are not really confident of | |
8768 | -- what happens if a return appears within a return. | |
9dc88aea | 8769 | |
eb66e842 | 8770 | BTemp := |
8771 | Make_Defining_Identifier (Loc, | |
8772 | Chars => New_Internal_Name ('B')); | |
9dc88aea | 8773 | |
eb66e842 | 8774 | FBody := |
8775 | Make_Subprogram_Body (Loc, | |
8776 | Specification => Spec, | |
9dc88aea | 8777 | |
eb66e842 | 8778 | Declarations => New_List ( |
8779 | Make_Object_Declaration (Loc, | |
8780 | Defining_Identifier => BTemp, | |
8781 | Constant_Present => True, | |
8782 | Object_Definition => | |
8783 | New_Occurrence_Of (Standard_Boolean, Loc), | |
8784 | Expression => Expr_M)), | |
d97beb2f | 8785 | |
eb66e842 | 8786 | Handled_Statement_Sequence => |
8787 | Make_Handled_Sequence_Of_Statements (Loc, | |
8788 | Statements => New_List ( | |
8789 | Make_Simple_Return_Statement (Loc, | |
8790 | Expression => New_Occurrence_Of (BTemp, Loc))))); | |
d97beb2f | 8791 | |
eb66e842 | 8792 | -- Insert declaration before freeze node and body after |
d97beb2f | 8793 | |
eb66e842 | 8794 | Insert_Before_And_Analyze (N, FDecl); |
8795 | Insert_After_And_Analyze (N, FBody); | |
8796 | end; | |
8797 | end if; | |
9dc88aea | 8798 | |
3b23aaa0 | 8799 | -- See if we have a static predicate. Note that the answer may be |
8800 | -- yes even if we have an explicit Dynamic_Predicate present. | |
9dc88aea | 8801 | |
3b23aaa0 | 8802 | declare |
94d896aa | 8803 | PS : Boolean; |
3b23aaa0 | 8804 | EN : Node_Id; |
9dc88aea | 8805 | |
3b23aaa0 | 8806 | begin |
94d896aa | 8807 | if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then |
8808 | PS := False; | |
8809 | else | |
8810 | PS := Is_Predicate_Static (Expr, Object_Name); | |
8811 | end if; | |
8812 | ||
a360a0f7 | 8813 | -- Case where we have a predicate-static aspect |
9dc88aea | 8814 | |
3b23aaa0 | 8815 | if PS then |
9dc88aea | 8816 | |
3b23aaa0 | 8817 | -- We don't set Has_Static_Predicate_Aspect, since we can have |
8818 | -- any of the three cases (Predicate, Dynamic_Predicate, or | |
8819 | -- Static_Predicate) generating a predicate with an expression | |
a360a0f7 | 8820 | -- that is predicate-static. We just indicate that we have a |
3b23aaa0 | 8821 | -- predicate that can be treated as static. |
d7c2851f | 8822 | |
3b23aaa0 | 8823 | Set_Has_Static_Predicate (Typ); |
d7c2851f | 8824 | |
3b23aaa0 | 8825 | -- For discrete subtype, build the static predicate list |
9dc88aea | 8826 | |
3b23aaa0 | 8827 | if Is_Discrete_Type (Typ) then |
8828 | Build_Discrete_Static_Predicate (Typ, Expr, Object_Name); | |
8829 | ||
8830 | -- If we don't get a static predicate list, it means that we | |
8831 | -- have a case where this is not possible, most typically in | |
8832 | -- the case where we inherit a dynamic predicate. We do not | |
8833 | -- consider this an error, we just leave the predicate as | |
8834 | -- dynamic. But if we do succeed in building the list, then | |
8835 | -- we mark the predicate as static. | |
8836 | ||
5c6a5792 | 8837 | if No (Static_Discrete_Predicate (Typ)) then |
3b23aaa0 | 8838 | Set_Has_Static_Predicate (Typ, False); |
8839 | end if; | |
94d896aa | 8840 | |
8841 | -- For real or string subtype, save predicate expression | |
8842 | ||
8843 | elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then | |
8844 | Set_Static_Real_Or_String_Predicate (Typ, Expr); | |
3b23aaa0 | 8845 | end if; |
8846 | ||
8847 | -- Case of dynamic predicate (expression is not predicate-static) | |
9dc88aea | 8848 | |
eb66e842 | 8849 | else |
3b23aaa0 | 8850 | -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that |
8851 | -- is only set if we have an explicit Dynamic_Predicate aspect | |
8852 | -- given. Here we may simply have a Predicate aspect where the | |
8853 | -- expression happens not to be predicate-static. | |
8854 | ||
8855 | -- Emit an error when the predicate is categorized as static | |
8856 | -- but its expression is not predicate-static. | |
8857 | ||
8858 | -- First a little fiddling to get a nice location for the | |
8859 | -- message. If the expression is of the form (A and then B), | |
75491446 | 8860 | -- where A is an inherited predicate, then use the right |
8861 | -- operand for the Sloc. This avoids getting confused by a call | |
8862 | -- to an inherited predicate with a less convenient source | |
8863 | -- location. | |
3b23aaa0 | 8864 | |
8865 | EN := Expr; | |
75491446 | 8866 | while Nkind (EN) = N_And_Then |
8867 | and then Nkind (Left_Opnd (EN)) = N_Function_Call | |
8868 | and then Is_Predicate_Function | |
8869 | (Entity (Name (Left_Opnd (EN)))) | |
8870 | loop | |
8871 | EN := Right_Opnd (EN); | |
3b23aaa0 | 8872 | end loop; |
8873 | ||
8874 | -- Now post appropriate message | |
8875 | ||
8876 | if Has_Static_Predicate_Aspect (Typ) then | |
94d896aa | 8877 | if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then |
3b23aaa0 | 8878 | Error_Msg_F |
26279d91 | 8879 | ("expression is not predicate-static (RM 3.2.4(16-22))", |
3b23aaa0 | 8880 | EN); |
8881 | else | |
94d896aa | 8882 | Error_Msg_F |
8883 | ("static predicate requires scalar or string type", EN); | |
3b23aaa0 | 8884 | end if; |
8885 | end if; | |
eb66e842 | 8886 | end if; |
3b23aaa0 | 8887 | end; |
eb66e842 | 8888 | end if; |
f9e26ff7 | 8889 | |
72a98436 | 8890 | Restore_Ghost_Mode (Mode); |
eb66e842 | 8891 | end Build_Predicate_Functions; |
9dc88aea | 8892 | |
9c20237a | 8893 | ------------------------------------------ |
8894 | -- Build_Predicate_Function_Declaration -- | |
8895 | ------------------------------------------ | |
8896 | ||
8897 | function Build_Predicate_Function_Declaration | |
8898 | (Typ : Entity_Id) return Node_Id | |
8899 | is | |
8900 | Loc : constant Source_Ptr := Sloc (Typ); | |
8901 | ||
72a98436 | 8902 | Func_Decl : Node_Id; |
8903 | Func_Id : Entity_Id; | |
8904 | Mode : Ghost_Mode_Type; | |
8905 | Spec : Node_Id; | |
9c20237a | 8906 | |
72a98436 | 8907 | begin |
8908 | -- The related type may be subject to pragma Ghost. Set the mode now to | |
8909 | -- ensure that the predicate functions are properly marked as Ghost. | |
9c20237a | 8910 | |
72a98436 | 8911 | Set_Ghost_Mode (Typ, Mode); |
9c20237a | 8912 | |
72a98436 | 8913 | Func_Id := |
8914 | Make_Defining_Identifier (Loc, | |
8915 | Chars => New_External_Name (Chars (Typ), "Predicate")); | |
9c20237a | 8916 | |
9c20237a | 8917 | Spec := |
8918 | Make_Function_Specification (Loc, | |
72a98436 | 8919 | Defining_Unit_Name => Func_Id, |
9c20237a | 8920 | Parameter_Specifications => New_List ( |
8921 | Make_Parameter_Specification (Loc, | |
72a98436 | 8922 | Defining_Identifier => Make_Temporary (Loc, 'I'), |
9c20237a | 8923 | Parameter_Type => New_Occurrence_Of (Typ, Loc))), |
8924 | Result_Definition => | |
8925 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
8926 | ||
72a98436 | 8927 | Func_Decl := Make_Subprogram_Declaration (Loc, Specification => Spec); |
9c20237a | 8928 | |
72a98436 | 8929 | Set_Ekind (Func_Id, E_Function); |
8930 | Set_Etype (Func_Id, Standard_Boolean); | |
8931 | Set_Is_Internal (Func_Id); | |
8932 | Set_Is_Predicate_Function (Func_Id); | |
8933 | Set_Predicate_Function (Typ, Func_Id); | |
9c20237a | 8934 | |
72a98436 | 8935 | Insert_After (Parent (Typ), Func_Decl); |
8936 | Analyze (Func_Decl); | |
9c20237a | 8937 | |
72a98436 | 8938 | Restore_Ghost_Mode (Mode); |
9c20237a | 8939 | |
72a98436 | 8940 | return Func_Decl; |
9c20237a | 8941 | end Build_Predicate_Function_Declaration; |
8942 | ||
d9f6a4ee | 8943 | ----------------------------------------- |
8944 | -- Check_Aspect_At_End_Of_Declarations -- | |
8945 | ----------------------------------------- | |
9dc88aea | 8946 | |
d9f6a4ee | 8947 | procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is |
8948 | Ent : constant Entity_Id := Entity (ASN); | |
8949 | Ident : constant Node_Id := Identifier (ASN); | |
8950 | A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); | |
d7c2851f | 8951 | |
d9f6a4ee | 8952 | End_Decl_Expr : constant Node_Id := Entity (Ident); |
8953 | -- Expression to be analyzed at end of declarations | |
d7c2851f | 8954 | |
d9f6a4ee | 8955 | Freeze_Expr : constant Node_Id := Expression (ASN); |
8956 | -- Expression from call to Check_Aspect_At_Freeze_Point | |
d7c2851f | 8957 | |
d9f6a4ee | 8958 | T : constant Entity_Id := Etype (Freeze_Expr); |
8959 | -- Type required for preanalyze call | |
d7c2851f | 8960 | |
d9f6a4ee | 8961 | Err : Boolean; |
8962 | -- Set False if error | |
9dc88aea | 8963 | |
d9f6a4ee | 8964 | -- On entry to this procedure, Entity (Ident) contains a copy of the |
8965 | -- original expression from the aspect, saved for this purpose, and | |
8966 | -- but Expression (Ident) is a preanalyzed copy of the expression, | |
8967 | -- preanalyzed just after the freeze point. | |
9dc88aea | 8968 | |
d9f6a4ee | 8969 | procedure Check_Overloaded_Name; |
8970 | -- For aspects whose expression is simply a name, this routine checks if | |
8971 | -- the name is overloaded or not. If so, it verifies there is an | |
8972 | -- interpretation that matches the entity obtained at the freeze point, | |
8973 | -- otherwise the compiler complains. | |
9dc88aea | 8974 | |
d9f6a4ee | 8975 | --------------------------- |
8976 | -- Check_Overloaded_Name -- | |
8977 | --------------------------- | |
8978 | ||
8979 | procedure Check_Overloaded_Name is | |
d97beb2f | 8980 | begin |
d9f6a4ee | 8981 | if not Is_Overloaded (End_Decl_Expr) then |
5ac76cee | 8982 | Err := not Is_Entity_Name (End_Decl_Expr) |
8983 | or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr); | |
d9f6a4ee | 8984 | |
d97beb2f | 8985 | else |
d9f6a4ee | 8986 | Err := True; |
9dc88aea | 8987 | |
d9f6a4ee | 8988 | declare |
8989 | Index : Interp_Index; | |
8990 | It : Interp; | |
9dc88aea | 8991 | |
d9f6a4ee | 8992 | begin |
8993 | Get_First_Interp (End_Decl_Expr, Index, It); | |
8994 | while Present (It.Typ) loop | |
8995 | if It.Nam = Entity (Freeze_Expr) then | |
8996 | Err := False; | |
8997 | exit; | |
8998 | end if; | |
8999 | ||
9000 | Get_Next_Interp (Index, It); | |
9001 | end loop; | |
9002 | end; | |
9dc88aea | 9003 | end if; |
d9f6a4ee | 9004 | end Check_Overloaded_Name; |
9dc88aea | 9005 | |
d9f6a4ee | 9006 | -- Start of processing for Check_Aspect_At_End_Of_Declarations |
9dc88aea | 9007 | |
d9f6a4ee | 9008 | begin |
da3cad01 | 9009 | -- In an instance we do not perform the consistency check between freeze |
9010 | -- point and end of declarations, because it was done already in the | |
9011 | -- analysis of the generic. Furthermore, the delayed analysis of an | |
9012 | -- aspect of the instance may produce spurious errors when the generic | |
9013 | -- is a child unit that references entities in the parent (which might | |
9014 | -- not be in scope at the freeze point of the instance). | |
9015 | ||
9016 | if In_Instance then | |
9017 | return; | |
9018 | ||
d9f6a4ee | 9019 | -- Case of aspects Dimension, Dimension_System and Synchronization |
9dc88aea | 9020 | |
da3cad01 | 9021 | elsif A_Id = Aspect_Synchronization then |
d9f6a4ee | 9022 | return; |
d97beb2f | 9023 | |
d9f6a4ee | 9024 | -- Case of stream attributes, just have to compare entities. However, |
9025 | -- the expression is just a name (possibly overloaded), and there may | |
9026 | -- be stream operations declared for unrelated types, so we just need | |
9027 | -- to verify that one of these interpretations is the one available at | |
9028 | -- at the freeze point. | |
9dc88aea | 9029 | |
d9f6a4ee | 9030 | elsif A_Id = Aspect_Input or else |
f02a9a9a | 9031 | A_Id = Aspect_Output or else |
9032 | A_Id = Aspect_Read or else | |
9033 | A_Id = Aspect_Write | |
d9f6a4ee | 9034 | then |
9035 | Analyze (End_Decl_Expr); | |
9036 | Check_Overloaded_Name; | |
9dc88aea | 9037 | |
d9f6a4ee | 9038 | elsif A_Id = Aspect_Variable_Indexing or else |
9039 | A_Id = Aspect_Constant_Indexing or else | |
9040 | A_Id = Aspect_Default_Iterator or else | |
9041 | A_Id = Aspect_Iterator_Element | |
9042 | then | |
9043 | -- Make type unfrozen before analysis, to prevent spurious errors | |
9044 | -- about late attributes. | |
9dc88aea | 9045 | |
d9f6a4ee | 9046 | Set_Is_Frozen (Ent, False); |
9047 | Analyze (End_Decl_Expr); | |
9048 | Set_Is_Frozen (Ent, True); | |
9dc88aea | 9049 | |
d9f6a4ee | 9050 | -- If the end of declarations comes before any other freeze |
9051 | -- point, the Freeze_Expr is not analyzed: no check needed. | |
9dc88aea | 9052 | |
d9f6a4ee | 9053 | if Analyzed (Freeze_Expr) and then not In_Instance then |
9054 | Check_Overloaded_Name; | |
9055 | else | |
9056 | Err := False; | |
9057 | end if; | |
55e8372b | 9058 | |
d9f6a4ee | 9059 | -- All other cases |
55e8372b | 9060 | |
d9f6a4ee | 9061 | else |
c1efebf9 | 9062 | -- Indicate that the expression comes from an aspect specification, |
9063 | -- which is used in subsequent analysis even if expansion is off. | |
9064 | ||
9065 | Set_Parent (End_Decl_Expr, ASN); | |
9066 | ||
d9f6a4ee | 9067 | -- In a generic context the aspect expressions have not been |
9068 | -- preanalyzed, so do it now. There are no conformance checks | |
9069 | -- to perform in this case. | |
55e8372b | 9070 | |
d9f6a4ee | 9071 | if No (T) then |
9072 | Check_Aspect_At_Freeze_Point (ASN); | |
9073 | return; | |
55e8372b | 9074 | |
d9f6a4ee | 9075 | -- The default values attributes may be defined in the private part, |
9076 | -- and the analysis of the expression may take place when only the | |
9077 | -- partial view is visible. The expression must be scalar, so use | |
9078 | -- the full view to resolve. | |
55e8372b | 9079 | |
d9f6a4ee | 9080 | elsif (A_Id = Aspect_Default_Value |
9081 | or else | |
9082 | A_Id = Aspect_Default_Component_Value) | |
9083 | and then Is_Private_Type (T) | |
9084 | then | |
9085 | Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T)); | |
c1efebf9 | 9086 | |
d9f6a4ee | 9087 | else |
9088 | Preanalyze_Spec_Expression (End_Decl_Expr, T); | |
9089 | end if; | |
d97beb2f | 9090 | |
d9f6a4ee | 9091 | Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr); |
9092 | end if; | |
55e8372b | 9093 | |
c1efebf9 | 9094 | -- Output error message if error. Force error on aspect specification |
9095 | -- even if there is an error on the expression itself. | |
55e8372b | 9096 | |
d9f6a4ee | 9097 | if Err then |
9098 | Error_Msg_NE | |
c1efebf9 | 9099 | ("!visibility of aspect for& changes after freeze point", |
d9f6a4ee | 9100 | ASN, Ent); |
9101 | Error_Msg_NE | |
9102 | ("info: & is frozen here, aspects evaluated at this point??", | |
9103 | Freeze_Node (Ent), Ent); | |
9104 | end if; | |
9105 | end Check_Aspect_At_End_Of_Declarations; | |
55e8372b | 9106 | |
d9f6a4ee | 9107 | ---------------------------------- |
9108 | -- Check_Aspect_At_Freeze_Point -- | |
9109 | ---------------------------------- | |
9dc88aea | 9110 | |
d9f6a4ee | 9111 | procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is |
9112 | Ident : constant Node_Id := Identifier (ASN); | |
9113 | -- Identifier (use Entity field to save expression) | |
9dc88aea | 9114 | |
d9f6a4ee | 9115 | A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); |
9dc88aea | 9116 | |
d9f6a4ee | 9117 | T : Entity_Id := Empty; |
9118 | -- Type required for preanalyze call | |
9dc88aea | 9119 | |
d9f6a4ee | 9120 | begin |
9121 | -- On entry to this procedure, Entity (Ident) contains a copy of the | |
9122 | -- original expression from the aspect, saved for this purpose. | |
9dc88aea | 9123 | |
d9f6a4ee | 9124 | -- On exit from this procedure Entity (Ident) is unchanged, still |
9125 | -- containing that copy, but Expression (Ident) is a preanalyzed copy | |
9126 | -- of the expression, preanalyzed just after the freeze point. | |
d97beb2f | 9127 | |
d9f6a4ee | 9128 | -- Make a copy of the expression to be preanalyzed |
d97beb2f | 9129 | |
d9f6a4ee | 9130 | Set_Expression (ASN, New_Copy_Tree (Entity (Ident))); |
d97beb2f | 9131 | |
d9f6a4ee | 9132 | -- Find type for preanalyze call |
d97beb2f | 9133 | |
d9f6a4ee | 9134 | case A_Id is |
9dc88aea | 9135 | |
d9f6a4ee | 9136 | -- No_Aspect should be impossible |
d97beb2f | 9137 | |
d9f6a4ee | 9138 | when No_Aspect => |
9139 | raise Program_Error; | |
9140 | ||
9141 | -- Aspects taking an optional boolean argument | |
d97beb2f | 9142 | |
d9f6a4ee | 9143 | when Boolean_Aspects | |
9144 | Library_Unit_Aspects => | |
9dc88aea | 9145 | |
d9f6a4ee | 9146 | T := Standard_Boolean; |
d7c2851f | 9147 | |
d9f6a4ee | 9148 | -- Aspects corresponding to attribute definition clauses |
9dc88aea | 9149 | |
d9f6a4ee | 9150 | when Aspect_Address => |
9151 | T := RTE (RE_Address); | |
9dc88aea | 9152 | |
d9f6a4ee | 9153 | when Aspect_Attach_Handler => |
9154 | T := RTE (RE_Interrupt_ID); | |
d7c2851f | 9155 | |
d9f6a4ee | 9156 | when Aspect_Bit_Order | Aspect_Scalar_Storage_Order => |
9157 | T := RTE (RE_Bit_Order); | |
d7c2851f | 9158 | |
d9f6a4ee | 9159 | when Aspect_Convention => |
9160 | return; | |
d7c2851f | 9161 | |
d9f6a4ee | 9162 | when Aspect_CPU => |
9163 | T := RTE (RE_CPU_Range); | |
d7c2851f | 9164 | |
d9f6a4ee | 9165 | -- Default_Component_Value is resolved with the component type |
d7c2851f | 9166 | |
d9f6a4ee | 9167 | when Aspect_Default_Component_Value => |
9168 | T := Component_Type (Entity (ASN)); | |
d7c2851f | 9169 | |
647fab54 | 9170 | when Aspect_Default_Storage_Pool => |
9171 | T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); | |
9172 | ||
d9f6a4ee | 9173 | -- Default_Value is resolved with the type entity in question |
d7c2851f | 9174 | |
d9f6a4ee | 9175 | when Aspect_Default_Value => |
9176 | T := Entity (ASN); | |
9dc88aea | 9177 | |
d9f6a4ee | 9178 | when Aspect_Dispatching_Domain => |
9179 | T := RTE (RE_Dispatching_Domain); | |
9dc88aea | 9180 | |
d9f6a4ee | 9181 | when Aspect_External_Tag => |
9182 | T := Standard_String; | |
9dc88aea | 9183 | |
d9f6a4ee | 9184 | when Aspect_External_Name => |
9185 | T := Standard_String; | |
9dc88aea | 9186 | |
d9f6a4ee | 9187 | when Aspect_Link_Name => |
9188 | T := Standard_String; | |
9dc88aea | 9189 | |
d9f6a4ee | 9190 | when Aspect_Priority | Aspect_Interrupt_Priority => |
9191 | T := Standard_Integer; | |
d97beb2f | 9192 | |
d9f6a4ee | 9193 | when Aspect_Relative_Deadline => |
9194 | T := RTE (RE_Time_Span); | |
d97beb2f | 9195 | |
e6ce0468 | 9196 | when Aspect_Secondary_Stack_Size => |
9197 | T := Standard_Integer; | |
9198 | ||
d9f6a4ee | 9199 | when Aspect_Small => |
9200 | T := Universal_Real; | |
490beba6 | 9201 | |
d9f6a4ee | 9202 | -- For a simple storage pool, we have to retrieve the type of the |
9203 | -- pool object associated with the aspect's corresponding attribute | |
9204 | -- definition clause. | |
490beba6 | 9205 | |
d9f6a4ee | 9206 | when Aspect_Simple_Storage_Pool => |
9207 | T := Etype (Expression (Aspect_Rep_Item (ASN))); | |
d97beb2f | 9208 | |
d9f6a4ee | 9209 | when Aspect_Storage_Pool => |
9210 | T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); | |
d97beb2f | 9211 | |
d9f6a4ee | 9212 | when Aspect_Alignment | |
9213 | Aspect_Component_Size | | |
9214 | Aspect_Machine_Radix | | |
9215 | Aspect_Object_Size | | |
9216 | Aspect_Size | | |
9217 | Aspect_Storage_Size | | |
9218 | Aspect_Stream_Size | | |
9219 | Aspect_Value_Size => | |
9220 | T := Any_Integer; | |
9dc88aea | 9221 | |
04ae062f | 9222 | when Aspect_Linker_Section => |
9223 | T := Standard_String; | |
9224 | ||
d9f6a4ee | 9225 | when Aspect_Synchronization => |
9226 | return; | |
7d20685d | 9227 | |
d9f6a4ee | 9228 | -- Special case, the expression of these aspects is just an entity |
9229 | -- that does not need any resolution, so just analyze. | |
7d20685d | 9230 | |
d9f6a4ee | 9231 | when Aspect_Input | |
9232 | Aspect_Output | | |
9233 | Aspect_Read | | |
9234 | Aspect_Suppress | | |
9235 | Aspect_Unsuppress | | |
9236 | Aspect_Warnings | | |
9237 | Aspect_Write => | |
9238 | Analyze (Expression (ASN)); | |
9239 | return; | |
7d20685d | 9240 | |
d9f6a4ee | 9241 | -- Same for Iterator aspects, where the expression is a function |
9242 | -- name. Legality rules are checked separately. | |
89f1e35c | 9243 | |
d9f6a4ee | 9244 | when Aspect_Constant_Indexing | |
9245 | Aspect_Default_Iterator | | |
9246 | Aspect_Iterator_Element | | |
9247 | Aspect_Variable_Indexing => | |
9248 | Analyze (Expression (ASN)); | |
9249 | return; | |
7d20685d | 9250 | |
b3f8228a | 9251 | -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect. |
9252 | ||
9253 | when Aspect_Iterable => | |
3061ffde | 9254 | T := Entity (ASN); |
9255 | ||
b3f8228a | 9256 | declare |
a9f5fea7 | 9257 | Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T); |
3061ffde | 9258 | Assoc : Node_Id; |
9259 | Expr : Node_Id; | |
a9f5fea7 | 9260 | |
b3f8228a | 9261 | begin |
a9f5fea7 | 9262 | if Cursor = Any_Type then |
9263 | return; | |
9264 | end if; | |
9265 | ||
b3f8228a | 9266 | Assoc := First (Component_Associations (Expression (ASN))); |
9267 | while Present (Assoc) loop | |
3061ffde | 9268 | Expr := Expression (Assoc); |
9269 | Analyze (Expr); | |
a9f5fea7 | 9270 | |
9271 | if not Error_Posted (Expr) then | |
9272 | Resolve_Iterable_Operation | |
9273 | (Expr, Cursor, T, Chars (First (Choices (Assoc)))); | |
9274 | end if; | |
9275 | ||
b3f8228a | 9276 | Next (Assoc); |
9277 | end loop; | |
9278 | end; | |
3061ffde | 9279 | |
b3f8228a | 9280 | return; |
9281 | ||
d9f6a4ee | 9282 | -- Invariant/Predicate take boolean expressions |
7d20685d | 9283 | |
d9f6a4ee | 9284 | when Aspect_Dynamic_Predicate | |
9285 | Aspect_Invariant | | |
9286 | Aspect_Predicate | | |
9287 | Aspect_Static_Predicate | | |
9288 | Aspect_Type_Invariant => | |
9289 | T := Standard_Boolean; | |
7d20685d | 9290 | |
fdec445e | 9291 | when Aspect_Predicate_Failure => |
9292 | T := Standard_String; | |
9293 | ||
d9f6a4ee | 9294 | -- Here is the list of aspects that don't require delay analysis |
89f1e35c | 9295 | |
d0849c23 | 9296 | when Aspect_Abstract_State | |
9297 | Aspect_Annotate | | |
85ee12c0 | 9298 | Aspect_Async_Readers | |
9299 | Aspect_Async_Writers | | |
d0849c23 | 9300 | Aspect_Constant_After_Elaboration | |
9301 | Aspect_Contract_Cases | | |
9302 | Aspect_Default_Initial_Condition | | |
9303 | Aspect_Depends | | |
9304 | Aspect_Dimension | | |
9305 | Aspect_Dimension_System | | |
85ee12c0 | 9306 | Aspect_Effective_Reads | |
9307 | Aspect_Effective_Writes | | |
d0849c23 | 9308 | Aspect_Extensions_Visible | |
9309 | Aspect_Ghost | | |
9310 | Aspect_Global | | |
9311 | Aspect_Implicit_Dereference | | |
9312 | Aspect_Initial_Condition | | |
9313 | Aspect_Initializes | | |
cbd45084 | 9314 | Aspect_Max_Queue_Length | |
d0849c23 | 9315 | Aspect_Obsolescent | |
9316 | Aspect_Part_Of | | |
9317 | Aspect_Post | | |
9318 | Aspect_Postcondition | | |
9319 | Aspect_Pre | | |
9320 | Aspect_Precondition | | |
9321 | Aspect_Refined_Depends | | |
9322 | Aspect_Refined_Global | | |
9323 | Aspect_Refined_Post | | |
9324 | Aspect_Refined_State | | |
9325 | Aspect_SPARK_Mode | | |
9326 | Aspect_Test_Case | | |
85ee12c0 | 9327 | Aspect_Unimplemented | |
9328 | Aspect_Volatile_Function => | |
d9f6a4ee | 9329 | raise Program_Error; |
2b184b2f | 9330 | |
d9f6a4ee | 9331 | end case; |
2b184b2f | 9332 | |
d9f6a4ee | 9333 | -- Do the preanalyze call |
2b184b2f | 9334 | |
d9f6a4ee | 9335 | Preanalyze_Spec_Expression (Expression (ASN), T); |
9336 | end Check_Aspect_At_Freeze_Point; | |
2b184b2f | 9337 | |
d9f6a4ee | 9338 | ----------------------------------- |
9339 | -- Check_Constant_Address_Clause -- | |
9340 | ----------------------------------- | |
2b184b2f | 9341 | |
d9f6a4ee | 9342 | procedure Check_Constant_Address_Clause |
9343 | (Expr : Node_Id; | |
9344 | U_Ent : Entity_Id) | |
9345 | is | |
9346 | procedure Check_At_Constant_Address (Nod : Node_Id); | |
9347 | -- Checks that the given node N represents a name whose 'Address is | |
9348 | -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the | |
9349 | -- address value is the same at the point of declaration of U_Ent and at | |
9350 | -- the time of elaboration of the address clause. | |
84ed7523 | 9351 | |
d9f6a4ee | 9352 | procedure Check_Expr_Constants (Nod : Node_Id); |
9353 | -- Checks that Nod meets the requirements for a constant address clause | |
9354 | -- in the sense of the enclosing procedure. | |
84ed7523 | 9355 | |
d9f6a4ee | 9356 | procedure Check_List_Constants (Lst : List_Id); |
9357 | -- Check that all elements of list Lst meet the requirements for a | |
9358 | -- constant address clause in the sense of the enclosing procedure. | |
84ed7523 | 9359 | |
d9f6a4ee | 9360 | ------------------------------- |
9361 | -- Check_At_Constant_Address -- | |
9362 | ------------------------------- | |
84ed7523 | 9363 | |
d9f6a4ee | 9364 | procedure Check_At_Constant_Address (Nod : Node_Id) is |
9365 | begin | |
9366 | if Is_Entity_Name (Nod) then | |
9367 | if Present (Address_Clause (Entity ((Nod)))) then | |
9368 | Error_Msg_NE | |
9369 | ("invalid address clause for initialized object &!", | |
9370 | Nod, U_Ent); | |
9371 | Error_Msg_NE | |
9372 | ("address for& cannot" & | |
9373 | " depend on another address clause! (RM 13.1(22))!", | |
9374 | Nod, U_Ent); | |
84ed7523 | 9375 | |
d9f6a4ee | 9376 | elsif In_Same_Source_Unit (Entity (Nod), U_Ent) |
9377 | and then Sloc (U_Ent) < Sloc (Entity (Nod)) | |
9378 | then | |
9379 | Error_Msg_NE | |
9380 | ("invalid address clause for initialized object &!", | |
9381 | Nod, U_Ent); | |
9382 | Error_Msg_Node_2 := U_Ent; | |
9383 | Error_Msg_NE | |
9384 | ("\& must be defined before & (RM 13.1(22))!", | |
9385 | Nod, Entity (Nod)); | |
9386 | end if; | |
7d20685d | 9387 | |
d9f6a4ee | 9388 | elsif Nkind (Nod) = N_Selected_Component then |
9389 | declare | |
9390 | T : constant Entity_Id := Etype (Prefix (Nod)); | |
59f3e675 | 9391 | |
d9f6a4ee | 9392 | begin |
9393 | if (Is_Record_Type (T) | |
9394 | and then Has_Discriminants (T)) | |
9395 | or else | |
9396 | (Is_Access_Type (T) | |
f02a9a9a | 9397 | and then Is_Record_Type (Designated_Type (T)) |
9398 | and then Has_Discriminants (Designated_Type (T))) | |
d9f6a4ee | 9399 | then |
9400 | Error_Msg_NE | |
9401 | ("invalid address clause for initialized object &!", | |
9402 | Nod, U_Ent); | |
9403 | Error_Msg_N | |
9404 | ("\address cannot depend on component" & | |
9405 | " of discriminated record (RM 13.1(22))!", | |
9406 | Nod); | |
9407 | else | |
9408 | Check_At_Constant_Address (Prefix (Nod)); | |
9409 | end if; | |
9410 | end; | |
89cc7147 | 9411 | |
d9f6a4ee | 9412 | elsif Nkind (Nod) = N_Indexed_Component then |
9413 | Check_At_Constant_Address (Prefix (Nod)); | |
9414 | Check_List_Constants (Expressions (Nod)); | |
89cc7147 | 9415 | |
84ed7523 | 9416 | else |
d9f6a4ee | 9417 | Check_Expr_Constants (Nod); |
84ed7523 | 9418 | end if; |
d9f6a4ee | 9419 | end Check_At_Constant_Address; |
81b424ac | 9420 | |
d9f6a4ee | 9421 | -------------------------- |
9422 | -- Check_Expr_Constants -- | |
9423 | -------------------------- | |
7b9b2f05 | 9424 | |
d9f6a4ee | 9425 | procedure Check_Expr_Constants (Nod : Node_Id) is |
9426 | Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent); | |
9427 | Ent : Entity_Id := Empty; | |
7b9b2f05 | 9428 | |
d9f6a4ee | 9429 | begin |
9430 | if Nkind (Nod) in N_Has_Etype | |
9431 | and then Etype (Nod) = Any_Type | |
7b9b2f05 | 9432 | then |
d9f6a4ee | 9433 | return; |
309c3053 | 9434 | end if; |
9435 | ||
d9f6a4ee | 9436 | case Nkind (Nod) is |
9437 | when N_Empty | N_Error => | |
9438 | return; | |
7d20685d | 9439 | |
d9f6a4ee | 9440 | when N_Identifier | N_Expanded_Name => |
9441 | Ent := Entity (Nod); | |
7d20685d | 9442 | |
d9f6a4ee | 9443 | -- We need to look at the original node if it is different |
9444 | -- from the node, since we may have rewritten things and | |
9445 | -- substituted an identifier representing the rewrite. | |
7d20685d | 9446 | |
d9f6a4ee | 9447 | if Original_Node (Nod) /= Nod then |
9448 | Check_Expr_Constants (Original_Node (Nod)); | |
7d20685d | 9449 | |
d9f6a4ee | 9450 | -- If the node is an object declaration without initial |
9451 | -- value, some code has been expanded, and the expression | |
9452 | -- is not constant, even if the constituents might be | |
9453 | -- acceptable, as in A'Address + offset. | |
7d20685d | 9454 | |
d9f6a4ee | 9455 | if Ekind (Ent) = E_Variable |
9456 | and then | |
9457 | Nkind (Declaration_Node (Ent)) = N_Object_Declaration | |
9458 | and then | |
9459 | No (Expression (Declaration_Node (Ent))) | |
9460 | then | |
9461 | Error_Msg_NE | |
9462 | ("invalid address clause for initialized object &!", | |
9463 | Nod, U_Ent); | |
89f1e35c | 9464 | |
d9f6a4ee | 9465 | -- If entity is constant, it may be the result of expanding |
9466 | -- a check. We must verify that its declaration appears | |
9467 | -- before the object in question, else we also reject the | |
9468 | -- address clause. | |
7d20685d | 9469 | |
d9f6a4ee | 9470 | elsif Ekind (Ent) = E_Constant |
9471 | and then In_Same_Source_Unit (Ent, U_Ent) | |
9472 | and then Sloc (Ent) > Loc_U_Ent | |
9473 | then | |
9474 | Error_Msg_NE | |
9475 | ("invalid address clause for initialized object &!", | |
9476 | Nod, U_Ent); | |
9477 | end if; | |
7d20685d | 9478 | |
d9f6a4ee | 9479 | return; |
9480 | end if; | |
7d20685d | 9481 | |
d9f6a4ee | 9482 | -- Otherwise look at the identifier and see if it is OK |
7d20685d | 9483 | |
d9f6a4ee | 9484 | if Ekind_In (Ent, E_Named_Integer, E_Named_Real) |
9485 | or else Is_Type (Ent) | |
9486 | then | |
9487 | return; | |
7d20685d | 9488 | |
f02a9a9a | 9489 | elsif Ekind_In (Ent, E_Constant, E_In_Parameter) then |
9490 | ||
d9f6a4ee | 9491 | -- This is the case where we must have Ent defined before |
9492 | -- U_Ent. Clearly if they are in different units this | |
9493 | -- requirement is met since the unit containing Ent is | |
9494 | -- already processed. | |
7d20685d | 9495 | |
d9f6a4ee | 9496 | if not In_Same_Source_Unit (Ent, U_Ent) then |
9497 | return; | |
7d20685d | 9498 | |
d9f6a4ee | 9499 | -- Otherwise location of Ent must be before the location |
9500 | -- of U_Ent, that's what prior defined means. | |
7d20685d | 9501 | |
d9f6a4ee | 9502 | elsif Sloc (Ent) < Loc_U_Ent then |
9503 | return; | |
6c545057 | 9504 | |
d9f6a4ee | 9505 | else |
9506 | Error_Msg_NE | |
9507 | ("invalid address clause for initialized object &!", | |
9508 | Nod, U_Ent); | |
9509 | Error_Msg_Node_2 := U_Ent; | |
9510 | Error_Msg_NE | |
9511 | ("\& must be defined before & (RM 13.1(22))!", | |
9512 | Nod, Ent); | |
9513 | end if; | |
37c6e44c | 9514 | |
d9f6a4ee | 9515 | elsif Nkind (Original_Node (Nod)) = N_Function_Call then |
9516 | Check_Expr_Constants (Original_Node (Nod)); | |
6c545057 | 9517 | |
d9f6a4ee | 9518 | else |
9519 | Error_Msg_NE | |
9520 | ("invalid address clause for initialized object &!", | |
9521 | Nod, U_Ent); | |
3cdbaa5a | 9522 | |
d9f6a4ee | 9523 | if Comes_From_Source (Ent) then |
9524 | Error_Msg_NE | |
9525 | ("\reference to variable& not allowed" | |
9526 | & " (RM 13.1(22))!", Nod, Ent); | |
9527 | else | |
9528 | Error_Msg_N | |
9529 | ("non-static expression not allowed" | |
9530 | & " (RM 13.1(22))!", Nod); | |
9531 | end if; | |
9532 | end if; | |
3cdbaa5a | 9533 | |
d9f6a4ee | 9534 | when N_Integer_Literal => |
7f694ca2 | 9535 | |
d9f6a4ee | 9536 | -- If this is a rewritten unchecked conversion, in a system |
9537 | -- where Address is an integer type, always use the base type | |
9538 | -- for a literal value. This is user-friendly and prevents | |
9539 | -- order-of-elaboration issues with instances of unchecked | |
9540 | -- conversion. | |
3cdbaa5a | 9541 | |
d9f6a4ee | 9542 | if Nkind (Original_Node (Nod)) = N_Function_Call then |
9543 | Set_Etype (Nod, Base_Type (Etype (Nod))); | |
9544 | end if; | |
e1cedbae | 9545 | |
d9f6a4ee | 9546 | when N_Real_Literal | |
9547 | N_String_Literal | | |
9548 | N_Character_Literal => | |
9549 | return; | |
7d20685d | 9550 | |
d9f6a4ee | 9551 | when N_Range => |
9552 | Check_Expr_Constants (Low_Bound (Nod)); | |
9553 | Check_Expr_Constants (High_Bound (Nod)); | |
231eb581 | 9554 | |
d9f6a4ee | 9555 | when N_Explicit_Dereference => |
9556 | Check_Expr_Constants (Prefix (Nod)); | |
231eb581 | 9557 | |
d9f6a4ee | 9558 | when N_Indexed_Component => |
9559 | Check_Expr_Constants (Prefix (Nod)); | |
9560 | Check_List_Constants (Expressions (Nod)); | |
7d20685d | 9561 | |
d9f6a4ee | 9562 | when N_Slice => |
9563 | Check_Expr_Constants (Prefix (Nod)); | |
9564 | Check_Expr_Constants (Discrete_Range (Nod)); | |
cb4c311d | 9565 | |
d9f6a4ee | 9566 | when N_Selected_Component => |
9567 | Check_Expr_Constants (Prefix (Nod)); | |
6144c105 | 9568 | |
d9f6a4ee | 9569 | when N_Attribute_Reference => |
9570 | if Nam_In (Attribute_Name (Nod), Name_Address, | |
9571 | Name_Access, | |
9572 | Name_Unchecked_Access, | |
9573 | Name_Unrestricted_Access) | |
9574 | then | |
9575 | Check_At_Constant_Address (Prefix (Nod)); | |
6144c105 | 9576 | |
d9f6a4ee | 9577 | else |
9578 | Check_Expr_Constants (Prefix (Nod)); | |
9579 | Check_List_Constants (Expressions (Nod)); | |
9580 | end if; | |
a7a4a7c2 | 9581 | |
d9f6a4ee | 9582 | when N_Aggregate => |
9583 | Check_List_Constants (Component_Associations (Nod)); | |
9584 | Check_List_Constants (Expressions (Nod)); | |
7d20685d | 9585 | |
d9f6a4ee | 9586 | when N_Component_Association => |
9587 | Check_Expr_Constants (Expression (Nod)); | |
e1cedbae | 9588 | |
d9f6a4ee | 9589 | when N_Extension_Aggregate => |
9590 | Check_Expr_Constants (Ancestor_Part (Nod)); | |
9591 | Check_List_Constants (Component_Associations (Nod)); | |
9592 | Check_List_Constants (Expressions (Nod)); | |
3cdbaa5a | 9593 | |
d9f6a4ee | 9594 | when N_Null => |
9595 | return; | |
3cdbaa5a | 9596 | |
d9f6a4ee | 9597 | when N_Binary_Op | N_Short_Circuit | N_Membership_Test => |
9598 | Check_Expr_Constants (Left_Opnd (Nod)); | |
9599 | Check_Expr_Constants (Right_Opnd (Nod)); | |
e1cedbae | 9600 | |
d9f6a4ee | 9601 | when N_Unary_Op => |
9602 | Check_Expr_Constants (Right_Opnd (Nod)); | |
7f694ca2 | 9603 | |
d9f6a4ee | 9604 | when N_Type_Conversion | |
9605 | N_Qualified_Expression | | |
9606 | N_Allocator | | |
9607 | N_Unchecked_Type_Conversion => | |
9608 | Check_Expr_Constants (Expression (Nod)); | |
47a46747 | 9609 | |
d9f6a4ee | 9610 | when N_Function_Call => |
9611 | if not Is_Pure (Entity (Name (Nod))) then | |
9612 | Error_Msg_NE | |
9613 | ("invalid address clause for initialized object &!", | |
9614 | Nod, U_Ent); | |
7f694ca2 | 9615 | |
d9f6a4ee | 9616 | Error_Msg_NE |
9617 | ("\function & is not pure (RM 13.1(22))!", | |
9618 | Nod, Entity (Name (Nod))); | |
b55f7641 | 9619 | |
d9f6a4ee | 9620 | else |
9621 | Check_List_Constants (Parameter_Associations (Nod)); | |
9622 | end if; | |
b55f7641 | 9623 | |
d9f6a4ee | 9624 | when N_Parameter_Association => |
9625 | Check_Expr_Constants (Explicit_Actual_Parameter (Nod)); | |
7d20685d | 9626 | |
d9f6a4ee | 9627 | when others => |
9628 | Error_Msg_NE | |
9629 | ("invalid address clause for initialized object &!", | |
9630 | Nod, U_Ent); | |
9631 | Error_Msg_NE | |
9632 | ("\must be constant defined before& (RM 13.1(22))!", | |
9633 | Nod, U_Ent); | |
9634 | end case; | |
9635 | end Check_Expr_Constants; | |
7d20685d | 9636 | |
d9f6a4ee | 9637 | -------------------------- |
9638 | -- Check_List_Constants -- | |
9639 | -------------------------- | |
89f1e35c | 9640 | |
d9f6a4ee | 9641 | procedure Check_List_Constants (Lst : List_Id) is |
9642 | Nod1 : Node_Id; | |
7d20685d | 9643 | |
d9f6a4ee | 9644 | begin |
9645 | if Present (Lst) then | |
9646 | Nod1 := First (Lst); | |
9647 | while Present (Nod1) loop | |
9648 | Check_Expr_Constants (Nod1); | |
9649 | Next (Nod1); | |
9650 | end loop; | |
9651 | end if; | |
9652 | end Check_List_Constants; | |
81b424ac | 9653 | |
d9f6a4ee | 9654 | -- Start of processing for Check_Constant_Address_Clause |
81b424ac | 9655 | |
d9f6a4ee | 9656 | begin |
9657 | -- If rep_clauses are to be ignored, no need for legality checks. In | |
9c7948d7 | 9658 | -- particular, no need to pester user about rep clauses that violate the |
9659 | -- rule on constant addresses, given that these clauses will be removed | |
9660 | -- by Freeze before they reach the back end. Similarly in CodePeer mode, | |
9661 | -- we want to relax these checks. | |
7d20685d | 9662 | |
f1a9be43 | 9663 | if not Ignore_Rep_Clauses and not CodePeer_Mode then |
d9f6a4ee | 9664 | Check_Expr_Constants (Expr); |
9665 | end if; | |
9666 | end Check_Constant_Address_Clause; | |
7d20685d | 9667 | |
6653b695 | 9668 | --------------------------- |
9669 | -- Check_Pool_Size_Clash -- | |
9670 | --------------------------- | |
9671 | ||
9672 | procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is | |
9673 | Post : Node_Id; | |
9674 | ||
9675 | begin | |
9676 | -- We need to find out which one came first. Note that in the case of | |
9677 | -- aspects mixed with pragmas there are cases where the processing order | |
9678 | -- is reversed, which is why we do the check here. | |
9679 | ||
9680 | if Sloc (SP) < Sloc (SS) then | |
9681 | Error_Msg_Sloc := Sloc (SP); | |
9682 | Post := SS; | |
9683 | Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent); | |
9684 | ||
9685 | else | |
9686 | Error_Msg_Sloc := Sloc (SS); | |
9687 | Post := SP; | |
9688 | Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent); | |
9689 | end if; | |
9690 | ||
9691 | Error_Msg_N | |
9692 | ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post); | |
9693 | end Check_Pool_Size_Clash; | |
9694 | ||
d9f6a4ee | 9695 | ---------------------------------------- |
9696 | -- Check_Record_Representation_Clause -- | |
9697 | ---------------------------------------- | |
85696508 | 9698 | |
d9f6a4ee | 9699 | procedure Check_Record_Representation_Clause (N : Node_Id) is |
9700 | Loc : constant Source_Ptr := Sloc (N); | |
9701 | Ident : constant Node_Id := Identifier (N); | |
9702 | Rectype : Entity_Id; | |
9703 | Fent : Entity_Id; | |
9704 | CC : Node_Id; | |
9705 | Fbit : Uint; | |
9706 | Lbit : Uint; | |
9707 | Hbit : Uint := Uint_0; | |
9708 | Comp : Entity_Id; | |
9709 | Pcomp : Entity_Id; | |
89f1e35c | 9710 | |
d9f6a4ee | 9711 | Max_Bit_So_Far : Uint; |
9712 | -- Records the maximum bit position so far. If all field positions | |
9713 | -- are monotonically increasing, then we can skip the circuit for | |
9714 | -- checking for overlap, since no overlap is possible. | |
85696508 | 9715 | |
d9f6a4ee | 9716 | Tagged_Parent : Entity_Id := Empty; |
9717 | -- This is set in the case of a derived tagged type for which we have | |
9718 | -- Is_Fully_Repped_Tagged_Type True (indicating that all components are | |
9719 | -- positioned by record representation clauses). In this case we must | |
9720 | -- check for overlap between components of this tagged type, and the | |
9721 | -- components of its parent. Tagged_Parent will point to this parent | |
9722 | -- type. For all other cases Tagged_Parent is left set to Empty. | |
7d20685d | 9723 | |
d9f6a4ee | 9724 | Parent_Last_Bit : Uint; |
9725 | -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the | |
9726 | -- last bit position for any field in the parent type. We only need to | |
9727 | -- check overlap for fields starting below this point. | |
7d20685d | 9728 | |
d9f6a4ee | 9729 | Overlap_Check_Required : Boolean; |
9730 | -- Used to keep track of whether or not an overlap check is required | |
7d20685d | 9731 | |
d9f6a4ee | 9732 | Overlap_Detected : Boolean := False; |
9733 | -- Set True if an overlap is detected | |
d6f39728 | 9734 | |
d9f6a4ee | 9735 | Ccount : Natural := 0; |
9736 | -- Number of component clauses in record rep clause | |
d6f39728 | 9737 | |
d9f6a4ee | 9738 | procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id); |
9739 | -- Given two entities for record components or discriminants, checks | |
9740 | -- if they have overlapping component clauses and issues errors if so. | |
d6f39728 | 9741 | |
d9f6a4ee | 9742 | procedure Find_Component; |
9743 | -- Finds component entity corresponding to current component clause (in | |
9744 | -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin | |
9745 | -- start/stop bits for the field. If there is no matching component or | |
9746 | -- if the matching component does not have a component clause, then | |
9747 | -- that's an error and Comp is set to Empty, but no error message is | |
9748 | -- issued, since the message was already given. Comp is also set to | |
9749 | -- Empty if the current "component clause" is in fact a pragma. | |
d6f39728 | 9750 | |
d9f6a4ee | 9751 | ----------------------------- |
9752 | -- Check_Component_Overlap -- | |
9753 | ----------------------------- | |
9754 | ||
9755 | procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is | |
9756 | CC1 : constant Node_Id := Component_Clause (C1_Ent); | |
9757 | CC2 : constant Node_Id := Component_Clause (C2_Ent); | |
d6f39728 | 9758 | |
d6f39728 | 9759 | begin |
d9f6a4ee | 9760 | if Present (CC1) and then Present (CC2) then |
d6f39728 | 9761 | |
d9f6a4ee | 9762 | -- Exclude odd case where we have two tag components in the same |
9763 | -- record, both at location zero. This seems a bit strange, but | |
9764 | -- it seems to happen in some circumstances, perhaps on an error. | |
9765 | ||
9766 | if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then | |
9767 | return; | |
d6f39728 | 9768 | end if; |
9769 | ||
d9f6a4ee | 9770 | -- Here we check if the two fields overlap |
9771 | ||
d6f39728 | 9772 | declare |
d9f6a4ee | 9773 | S1 : constant Uint := Component_Bit_Offset (C1_Ent); |
9774 | S2 : constant Uint := Component_Bit_Offset (C2_Ent); | |
9775 | E1 : constant Uint := S1 + Esize (C1_Ent); | |
9776 | E2 : constant Uint := S2 + Esize (C2_Ent); | |
d6f39728 | 9777 | |
9778 | begin | |
d9f6a4ee | 9779 | if E2 <= S1 or else E1 <= S2 then |
9780 | null; | |
d6f39728 | 9781 | else |
d9f6a4ee | 9782 | Error_Msg_Node_2 := Component_Name (CC2); |
9783 | Error_Msg_Sloc := Sloc (Error_Msg_Node_2); | |
9784 | Error_Msg_Node_1 := Component_Name (CC1); | |
9785 | Error_Msg_N | |
9786 | ("component& overlaps & #", Component_Name (CC1)); | |
9787 | Overlap_Detected := True; | |
d6f39728 | 9788 | end if; |
9789 | end; | |
d6f39728 | 9790 | end if; |
d9f6a4ee | 9791 | end Check_Component_Overlap; |
d6f39728 | 9792 | |
d9f6a4ee | 9793 | -------------------- |
9794 | -- Find_Component -- | |
9795 | -------------------- | |
9dfe12ae | 9796 | |
d9f6a4ee | 9797 | procedure Find_Component is |
9dfe12ae | 9798 | |
d9f6a4ee | 9799 | procedure Search_Component (R : Entity_Id); |
9800 | -- Search components of R for a match. If found, Comp is set | |
9dfe12ae | 9801 | |
d9f6a4ee | 9802 | ---------------------- |
9803 | -- Search_Component -- | |
9804 | ---------------------- | |
e7b2d6bc | 9805 | |
d9f6a4ee | 9806 | procedure Search_Component (R : Entity_Id) is |
9807 | begin | |
9808 | Comp := First_Component_Or_Discriminant (R); | |
9809 | while Present (Comp) loop | |
e7b2d6bc | 9810 | |
d9f6a4ee | 9811 | -- Ignore error of attribute name for component name (we |
9812 | -- already gave an error message for this, so no need to | |
9813 | -- complain here) | |
e7b2d6bc | 9814 | |
d9f6a4ee | 9815 | if Nkind (Component_Name (CC)) = N_Attribute_Reference then |
9816 | null; | |
9817 | else | |
9818 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
9dfe12ae | 9819 | end if; |
9820 | ||
d9f6a4ee | 9821 | Next_Component_Or_Discriminant (Comp); |
9822 | end loop; | |
9823 | end Search_Component; | |
d6f39728 | 9824 | |
d9f6a4ee | 9825 | -- Start of processing for Find_Component |
d6f39728 | 9826 | |
d9f6a4ee | 9827 | begin |
9828 | -- Return with Comp set to Empty if we have a pragma | |
d6f39728 | 9829 | |
d9f6a4ee | 9830 | if Nkind (CC) = N_Pragma then |
9831 | Comp := Empty; | |
9832 | return; | |
9833 | end if; | |
d6f39728 | 9834 | |
d9f6a4ee | 9835 | -- Search current record for matching component |
d6f39728 | 9836 | |
d9f6a4ee | 9837 | Search_Component (Rectype); |
9dfe12ae | 9838 | |
d9f6a4ee | 9839 | -- If not found, maybe component of base type discriminant that is |
9840 | -- absent from statically constrained first subtype. | |
e7b2d6bc | 9841 | |
d9f6a4ee | 9842 | if No (Comp) then |
9843 | Search_Component (Base_Type (Rectype)); | |
9844 | end if; | |
e7b2d6bc | 9845 | |
d9f6a4ee | 9846 | -- If no component, or the component does not reference the component |
9847 | -- clause in question, then there was some previous error for which | |
9848 | -- we already gave a message, so just return with Comp Empty. | |
d6f39728 | 9849 | |
d9f6a4ee | 9850 | if No (Comp) or else Component_Clause (Comp) /= CC then |
9851 | Check_Error_Detected; | |
9852 | Comp := Empty; | |
93735cb8 | 9853 | |
d9f6a4ee | 9854 | -- Normal case where we have a component clause |
93735cb8 | 9855 | |
d9f6a4ee | 9856 | else |
9857 | Fbit := Component_Bit_Offset (Comp); | |
9858 | Lbit := Fbit + Esize (Comp) - 1; | |
9859 | end if; | |
9860 | end Find_Component; | |
93735cb8 | 9861 | |
d9f6a4ee | 9862 | -- Start of processing for Check_Record_Representation_Clause |
d6f39728 | 9863 | |
d9f6a4ee | 9864 | begin |
9865 | Find_Type (Ident); | |
9866 | Rectype := Entity (Ident); | |
d6f39728 | 9867 | |
d9f6a4ee | 9868 | if Rectype = Any_Type then |
9869 | return; | |
9870 | else | |
9871 | Rectype := Underlying_Type (Rectype); | |
9872 | end if; | |
d6f39728 | 9873 | |
d9f6a4ee | 9874 | -- See if we have a fully repped derived tagged type |
d6f39728 | 9875 | |
d9f6a4ee | 9876 | declare |
9877 | PS : constant Entity_Id := Parent_Subtype (Rectype); | |
d6f39728 | 9878 | |
d9f6a4ee | 9879 | begin |
9880 | if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then | |
9881 | Tagged_Parent := PS; | |
d6f39728 | 9882 | |
d9f6a4ee | 9883 | -- Find maximum bit of any component of the parent type |
d6f39728 | 9884 | |
d9f6a4ee | 9885 | Parent_Last_Bit := UI_From_Int (System_Address_Size - 1); |
9886 | Pcomp := First_Entity (Tagged_Parent); | |
9887 | while Present (Pcomp) loop | |
9888 | if Ekind_In (Pcomp, E_Discriminant, E_Component) then | |
9889 | if Component_Bit_Offset (Pcomp) /= No_Uint | |
9890 | and then Known_Static_Esize (Pcomp) | |
9891 | then | |
9892 | Parent_Last_Bit := | |
9893 | UI_Max | |
9894 | (Parent_Last_Bit, | |
9895 | Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1); | |
9896 | end if; | |
b7df4cda | 9897 | else |
9898 | ||
9899 | -- Skip anonymous types generated for constrained array | |
9900 | -- or record components. | |
d9f6a4ee | 9901 | |
b7df4cda | 9902 | null; |
d6f39728 | 9903 | end if; |
b7df4cda | 9904 | |
9905 | Next_Entity (Pcomp); | |
d9f6a4ee | 9906 | end loop; |
9907 | end if; | |
9908 | end; | |
d6f39728 | 9909 | |
d9f6a4ee | 9910 | -- All done if no component clauses |
d6f39728 | 9911 | |
d9f6a4ee | 9912 | CC := First (Component_Clauses (N)); |
d6f39728 | 9913 | |
d9f6a4ee | 9914 | if No (CC) then |
9915 | return; | |
9916 | end if; | |
d6f39728 | 9917 | |
d9f6a4ee | 9918 | -- If a tag is present, then create a component clause that places it |
9919 | -- at the start of the record (otherwise gigi may place it after other | |
9920 | -- fields that have rep clauses). | |
d6f39728 | 9921 | |
d9f6a4ee | 9922 | Fent := First_Entity (Rectype); |
d6f39728 | 9923 | |
d9f6a4ee | 9924 | if Nkind (Fent) = N_Defining_Identifier |
9925 | and then Chars (Fent) = Name_uTag | |
9926 | then | |
9927 | Set_Component_Bit_Offset (Fent, Uint_0); | |
9928 | Set_Normalized_Position (Fent, Uint_0); | |
9929 | Set_Normalized_First_Bit (Fent, Uint_0); | |
9930 | Set_Normalized_Position_Max (Fent, Uint_0); | |
9931 | Init_Esize (Fent, System_Address_Size); | |
d6f39728 | 9932 | |
d9f6a4ee | 9933 | Set_Component_Clause (Fent, |
9934 | Make_Component_Clause (Loc, | |
9935 | Component_Name => Make_Identifier (Loc, Name_uTag), | |
d6f39728 | 9936 | |
d9f6a4ee | 9937 | Position => Make_Integer_Literal (Loc, Uint_0), |
9938 | First_Bit => Make_Integer_Literal (Loc, Uint_0), | |
9939 | Last_Bit => | |
9940 | Make_Integer_Literal (Loc, | |
9941 | UI_From_Int (System_Address_Size)))); | |
d6f39728 | 9942 | |
d9f6a4ee | 9943 | Ccount := Ccount + 1; |
9944 | end if; | |
d6f39728 | 9945 | |
d9f6a4ee | 9946 | Max_Bit_So_Far := Uint_Minus_1; |
9947 | Overlap_Check_Required := False; | |
d6f39728 | 9948 | |
d9f6a4ee | 9949 | -- Process the component clauses |
d6f39728 | 9950 | |
d9f6a4ee | 9951 | while Present (CC) loop |
9952 | Find_Component; | |
d6f39728 | 9953 | |
d9f6a4ee | 9954 | if Present (Comp) then |
9955 | Ccount := Ccount + 1; | |
d6f39728 | 9956 | |
d9f6a4ee | 9957 | -- We need a full overlap check if record positions non-monotonic |
d6f39728 | 9958 | |
d9f6a4ee | 9959 | if Fbit <= Max_Bit_So_Far then |
9960 | Overlap_Check_Required := True; | |
9961 | end if; | |
d6f39728 | 9962 | |
d9f6a4ee | 9963 | Max_Bit_So_Far := Lbit; |
d6f39728 | 9964 | |
d9f6a4ee | 9965 | -- Check bit position out of range of specified size |
01cb2726 | 9966 | |
d9f6a4ee | 9967 | if Has_Size_Clause (Rectype) |
9968 | and then RM_Size (Rectype) <= Lbit | |
9969 | then | |
9970 | Error_Msg_N | |
9971 | ("bit number out of range of specified size", | |
9972 | Last_Bit (CC)); | |
d6f39728 | 9973 | |
d9f6a4ee | 9974 | -- Check for overlap with tag component |
67278d60 | 9975 | |
d9f6a4ee | 9976 | else |
9977 | if Is_Tagged_Type (Rectype) | |
9978 | and then Fbit < System_Address_Size | |
9979 | then | |
9980 | Error_Msg_NE | |
9981 | ("component overlaps tag field of&", | |
9982 | Component_Name (CC), Rectype); | |
9983 | Overlap_Detected := True; | |
9984 | end if; | |
67278d60 | 9985 | |
d9f6a4ee | 9986 | if Hbit < Lbit then |
9987 | Hbit := Lbit; | |
9988 | end if; | |
9989 | end if; | |
67278d60 | 9990 | |
d9f6a4ee | 9991 | -- Check parent overlap if component might overlap parent field |
67278d60 | 9992 | |
d9f6a4ee | 9993 | if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then |
9994 | Pcomp := First_Component_Or_Discriminant (Tagged_Parent); | |
9995 | while Present (Pcomp) loop | |
9996 | if not Is_Tag (Pcomp) | |
9997 | and then Chars (Pcomp) /= Name_uParent | |
9998 | then | |
9999 | Check_Component_Overlap (Comp, Pcomp); | |
10000 | end if; | |
67278d60 | 10001 | |
d9f6a4ee | 10002 | Next_Component_Or_Discriminant (Pcomp); |
10003 | end loop; | |
10004 | end if; | |
10005 | end if; | |
67278d60 | 10006 | |
d9f6a4ee | 10007 | Next (CC); |
10008 | end loop; | |
47495553 | 10009 | |
d9f6a4ee | 10010 | -- Now that we have processed all the component clauses, check for |
10011 | -- overlap. We have to leave this till last, since the components can | |
10012 | -- appear in any arbitrary order in the representation clause. | |
67278d60 | 10013 | |
d9f6a4ee | 10014 | -- We do not need this check if all specified ranges were monotonic, |
10015 | -- as recorded by Overlap_Check_Required being False at this stage. | |
67278d60 | 10016 | |
d9f6a4ee | 10017 | -- This first section checks if there are any overlapping entries at |
10018 | -- all. It does this by sorting all entries and then seeing if there are | |
10019 | -- any overlaps. If there are none, then that is decisive, but if there | |
10020 | -- are overlaps, they may still be OK (they may result from fields in | |
10021 | -- different variants). | |
67278d60 | 10022 | |
d9f6a4ee | 10023 | if Overlap_Check_Required then |
10024 | Overlap_Check1 : declare | |
67278d60 | 10025 | |
d9f6a4ee | 10026 | OC_Fbit : array (0 .. Ccount) of Uint; |
10027 | -- First-bit values for component clauses, the value is the offset | |
10028 | -- of the first bit of the field from start of record. The zero | |
10029 | -- entry is for use in sorting. | |
47495553 | 10030 | |
d9f6a4ee | 10031 | OC_Lbit : array (0 .. Ccount) of Uint; |
10032 | -- Last-bit values for component clauses, the value is the offset | |
10033 | -- of the last bit of the field from start of record. The zero | |
10034 | -- entry is for use in sorting. | |
10035 | ||
10036 | OC_Count : Natural := 0; | |
10037 | -- Count of entries in OC_Fbit and OC_Lbit | |
67278d60 | 10038 | |
d9f6a4ee | 10039 | function OC_Lt (Op1, Op2 : Natural) return Boolean; |
10040 | -- Compare routine for Sort | |
67278d60 | 10041 | |
d9f6a4ee | 10042 | procedure OC_Move (From : Natural; To : Natural); |
10043 | -- Move routine for Sort | |
67278d60 | 10044 | |
d9f6a4ee | 10045 | package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt); |
67278d60 | 10046 | |
d9f6a4ee | 10047 | ----------- |
10048 | -- OC_Lt -- | |
10049 | ----------- | |
67278d60 | 10050 | |
d9f6a4ee | 10051 | function OC_Lt (Op1, Op2 : Natural) return Boolean is |
67278d60 | 10052 | begin |
d9f6a4ee | 10053 | return OC_Fbit (Op1) < OC_Fbit (Op2); |
10054 | end OC_Lt; | |
67278d60 | 10055 | |
d9f6a4ee | 10056 | ------------- |
10057 | -- OC_Move -- | |
10058 | ------------- | |
67278d60 | 10059 | |
d9f6a4ee | 10060 | procedure OC_Move (From : Natural; To : Natural) is |
10061 | begin | |
10062 | OC_Fbit (To) := OC_Fbit (From); | |
10063 | OC_Lbit (To) := OC_Lbit (From); | |
10064 | end OC_Move; | |
67278d60 | 10065 | |
d9f6a4ee | 10066 | -- Start of processing for Overlap_Check |
67278d60 | 10067 | |
67278d60 | 10068 | begin |
d9f6a4ee | 10069 | CC := First (Component_Clauses (N)); |
10070 | while Present (CC) loop | |
67278d60 | 10071 | |
d9f6a4ee | 10072 | -- Exclude component clause already marked in error |
67278d60 | 10073 | |
d9f6a4ee | 10074 | if not Error_Posted (CC) then |
10075 | Find_Component; | |
10076 | ||
10077 | if Present (Comp) then | |
10078 | OC_Count := OC_Count + 1; | |
10079 | OC_Fbit (OC_Count) := Fbit; | |
10080 | OC_Lbit (OC_Count) := Lbit; | |
10081 | end if; | |
67278d60 | 10082 | end if; |
10083 | ||
d9f6a4ee | 10084 | Next (CC); |
67278d60 | 10085 | end loop; |
67278d60 | 10086 | |
d9f6a4ee | 10087 | Sorting.Sort (OC_Count); |
67278d60 | 10088 | |
d9f6a4ee | 10089 | Overlap_Check_Required := False; |
10090 | for J in 1 .. OC_Count - 1 loop | |
10091 | if OC_Lbit (J) >= OC_Fbit (J + 1) then | |
10092 | Overlap_Check_Required := True; | |
10093 | exit; | |
10094 | end if; | |
10095 | end loop; | |
10096 | end Overlap_Check1; | |
10097 | end if; | |
67278d60 | 10098 | |
d9f6a4ee | 10099 | -- If Overlap_Check_Required is still True, then we have to do the full |
10100 | -- scale overlap check, since we have at least two fields that do | |
10101 | -- overlap, and we need to know if that is OK since they are in | |
10102 | -- different variant, or whether we have a definite problem. | |
67278d60 | 10103 | |
d9f6a4ee | 10104 | if Overlap_Check_Required then |
10105 | Overlap_Check2 : declare | |
10106 | C1_Ent, C2_Ent : Entity_Id; | |
10107 | -- Entities of components being checked for overlap | |
67278d60 | 10108 | |
d9f6a4ee | 10109 | Clist : Node_Id; |
10110 | -- Component_List node whose Component_Items are being checked | |
67278d60 | 10111 | |
d9f6a4ee | 10112 | Citem : Node_Id; |
10113 | -- Component declaration for component being checked | |
67278d60 | 10114 | |
d9f6a4ee | 10115 | begin |
10116 | C1_Ent := First_Entity (Base_Type (Rectype)); | |
67278d60 | 10117 | |
d9f6a4ee | 10118 | -- Loop through all components in record. For each component check |
10119 | -- for overlap with any of the preceding elements on the component | |
10120 | -- list containing the component and also, if the component is in | |
10121 | -- a variant, check against components outside the case structure. | |
10122 | -- This latter test is repeated recursively up the variant tree. | |
67278d60 | 10123 | |
d9f6a4ee | 10124 | Main_Component_Loop : while Present (C1_Ent) loop |
10125 | if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then | |
10126 | goto Continue_Main_Component_Loop; | |
10127 | end if; | |
67278d60 | 10128 | |
d9f6a4ee | 10129 | -- Skip overlap check if entity has no declaration node. This |
10130 | -- happens with discriminants in constrained derived types. | |
10131 | -- Possibly we are missing some checks as a result, but that | |
10132 | -- does not seem terribly serious. | |
67278d60 | 10133 | |
d9f6a4ee | 10134 | if No (Declaration_Node (C1_Ent)) then |
10135 | goto Continue_Main_Component_Loop; | |
10136 | end if; | |
67278d60 | 10137 | |
d9f6a4ee | 10138 | Clist := Parent (List_Containing (Declaration_Node (C1_Ent))); |
67278d60 | 10139 | |
d9f6a4ee | 10140 | -- Loop through component lists that need checking. Check the |
10141 | -- current component list and all lists in variants above us. | |
67278d60 | 10142 | |
d9f6a4ee | 10143 | Component_List_Loop : loop |
67278d60 | 10144 | |
d9f6a4ee | 10145 | -- If derived type definition, go to full declaration |
10146 | -- If at outer level, check discriminants if there are any. | |
67278d60 | 10147 | |
d9f6a4ee | 10148 | if Nkind (Clist) = N_Derived_Type_Definition then |
10149 | Clist := Parent (Clist); | |
10150 | end if; | |
67278d60 | 10151 | |
d9f6a4ee | 10152 | -- Outer level of record definition, check discriminants |
67278d60 | 10153 | |
d9f6a4ee | 10154 | if Nkind_In (Clist, N_Full_Type_Declaration, |
10155 | N_Private_Type_Declaration) | |
67278d60 | 10156 | then |
d9f6a4ee | 10157 | if Has_Discriminants (Defining_Identifier (Clist)) then |
10158 | C2_Ent := | |
10159 | First_Discriminant (Defining_Identifier (Clist)); | |
10160 | while Present (C2_Ent) loop | |
10161 | exit when C1_Ent = C2_Ent; | |
10162 | Check_Component_Overlap (C1_Ent, C2_Ent); | |
10163 | Next_Discriminant (C2_Ent); | |
10164 | end loop; | |
10165 | end if; | |
67278d60 | 10166 | |
d9f6a4ee | 10167 | -- Record extension case |
67278d60 | 10168 | |
d9f6a4ee | 10169 | elsif Nkind (Clist) = N_Derived_Type_Definition then |
10170 | Clist := Empty; | |
67278d60 | 10171 | |
d9f6a4ee | 10172 | -- Otherwise check one component list |
67278d60 | 10173 | |
d9f6a4ee | 10174 | else |
10175 | Citem := First (Component_Items (Clist)); | |
10176 | while Present (Citem) loop | |
10177 | if Nkind (Citem) = N_Component_Declaration then | |
10178 | C2_Ent := Defining_Identifier (Citem); | |
10179 | exit when C1_Ent = C2_Ent; | |
10180 | Check_Component_Overlap (C1_Ent, C2_Ent); | |
10181 | end if; | |
67278d60 | 10182 | |
d9f6a4ee | 10183 | Next (Citem); |
10184 | end loop; | |
10185 | end if; | |
67278d60 | 10186 | |
d9f6a4ee | 10187 | -- Check for variants above us (the parent of the Clist can |
10188 | -- be a variant, in which case its parent is a variant part, | |
10189 | -- and the parent of the variant part is a component list | |
10190 | -- whose components must all be checked against the current | |
10191 | -- component for overlap). | |
67278d60 | 10192 | |
d9f6a4ee | 10193 | if Nkind (Parent (Clist)) = N_Variant then |
10194 | Clist := Parent (Parent (Parent (Clist))); | |
67278d60 | 10195 | |
d9f6a4ee | 10196 | -- Check for possible discriminant part in record, this |
10197 | -- is treated essentially as another level in the | |
10198 | -- recursion. For this case the parent of the component | |
10199 | -- list is the record definition, and its parent is the | |
10200 | -- full type declaration containing the discriminant | |
10201 | -- specifications. | |
10202 | ||
10203 | elsif Nkind (Parent (Clist)) = N_Record_Definition then | |
10204 | Clist := Parent (Parent ((Clist))); | |
10205 | ||
10206 | -- If neither of these two cases, we are at the top of | |
10207 | -- the tree. | |
10208 | ||
10209 | else | |
10210 | exit Component_List_Loop; | |
10211 | end if; | |
10212 | end loop Component_List_Loop; | |
67278d60 | 10213 | |
d9f6a4ee | 10214 | <<Continue_Main_Component_Loop>> |
10215 | Next_Entity (C1_Ent); | |
67278d60 | 10216 | |
d9f6a4ee | 10217 | end loop Main_Component_Loop; |
10218 | end Overlap_Check2; | |
67278d60 | 10219 | end if; |
10220 | ||
d9f6a4ee | 10221 | -- The following circuit deals with warning on record holes (gaps). We |
10222 | -- skip this check if overlap was detected, since it makes sense for the | |
10223 | -- programmer to fix this illegality before worrying about warnings. | |
67278d60 | 10224 | |
d9f6a4ee | 10225 | if not Overlap_Detected and Warn_On_Record_Holes then |
10226 | Record_Hole_Check : declare | |
10227 | Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype)); | |
10228 | -- Full declaration of record type | |
67278d60 | 10229 | |
d9f6a4ee | 10230 | procedure Check_Component_List |
10231 | (CL : Node_Id; | |
10232 | Sbit : Uint; | |
10233 | DS : List_Id); | |
10234 | -- Check component list CL for holes. The starting bit should be | |
10235 | -- Sbit. which is zero for the main record component list and set | |
10236 | -- appropriately for recursive calls for variants. DS is set to | |
10237 | -- a list of discriminant specifications to be included in the | |
10238 | -- consideration of components. It is No_List if none to consider. | |
67278d60 | 10239 | |
d9f6a4ee | 10240 | -------------------------- |
10241 | -- Check_Component_List -- | |
10242 | -------------------------- | |
47495553 | 10243 | |
d9f6a4ee | 10244 | procedure Check_Component_List |
10245 | (CL : Node_Id; | |
10246 | Sbit : Uint; | |
10247 | DS : List_Id) | |
10248 | is | |
10249 | Compl : Integer; | |
67278d60 | 10250 | |
d9f6a4ee | 10251 | begin |
10252 | Compl := Integer (List_Length (Component_Items (CL))); | |
47495553 | 10253 | |
d9f6a4ee | 10254 | if DS /= No_List then |
10255 | Compl := Compl + Integer (List_Length (DS)); | |
10256 | end if; | |
67278d60 | 10257 | |
d9f6a4ee | 10258 | declare |
10259 | Comps : array (Natural range 0 .. Compl) of Entity_Id; | |
10260 | -- Gather components (zero entry is for sort routine) | |
67278d60 | 10261 | |
d9f6a4ee | 10262 | Ncomps : Natural := 0; |
10263 | -- Number of entries stored in Comps (starting at Comps (1)) | |
67278d60 | 10264 | |
d9f6a4ee | 10265 | Citem : Node_Id; |
10266 | -- One component item or discriminant specification | |
67278d60 | 10267 | |
d9f6a4ee | 10268 | Nbit : Uint; |
10269 | -- Starting bit for next component | |
67278d60 | 10270 | |
d9f6a4ee | 10271 | CEnt : Entity_Id; |
10272 | -- Component entity | |
67278d60 | 10273 | |
d9f6a4ee | 10274 | Variant : Node_Id; |
10275 | -- One variant | |
67278d60 | 10276 | |
d9f6a4ee | 10277 | function Lt (Op1, Op2 : Natural) return Boolean; |
10278 | -- Compare routine for Sort | |
67278d60 | 10279 | |
d9f6a4ee | 10280 | procedure Move (From : Natural; To : Natural); |
10281 | -- Move routine for Sort | |
67278d60 | 10282 | |
d9f6a4ee | 10283 | package Sorting is new GNAT.Heap_Sort_G (Move, Lt); |
67278d60 | 10284 | |
d9f6a4ee | 10285 | -------- |
10286 | -- Lt -- | |
10287 | -------- | |
67278d60 | 10288 | |
d9f6a4ee | 10289 | function Lt (Op1, Op2 : Natural) return Boolean is |
10290 | begin | |
10291 | return Component_Bit_Offset (Comps (Op1)) | |
10292 | < | |
10293 | Component_Bit_Offset (Comps (Op2)); | |
10294 | end Lt; | |
67278d60 | 10295 | |
d9f6a4ee | 10296 | ---------- |
10297 | -- Move -- | |
10298 | ---------- | |
67278d60 | 10299 | |
d9f6a4ee | 10300 | procedure Move (From : Natural; To : Natural) is |
10301 | begin | |
10302 | Comps (To) := Comps (From); | |
10303 | end Move; | |
67278d60 | 10304 | |
d9f6a4ee | 10305 | begin |
10306 | -- Gather discriminants into Comp | |
67278d60 | 10307 | |
d9f6a4ee | 10308 | if DS /= No_List then |
10309 | Citem := First (DS); | |
10310 | while Present (Citem) loop | |
10311 | if Nkind (Citem) = N_Discriminant_Specification then | |
10312 | declare | |
10313 | Ent : constant Entity_Id := | |
10314 | Defining_Identifier (Citem); | |
10315 | begin | |
10316 | if Ekind (Ent) = E_Discriminant then | |
10317 | Ncomps := Ncomps + 1; | |
10318 | Comps (Ncomps) := Ent; | |
10319 | end if; | |
10320 | end; | |
10321 | end if; | |
67278d60 | 10322 | |
d9f6a4ee | 10323 | Next (Citem); |
10324 | end loop; | |
10325 | end if; | |
67278d60 | 10326 | |
d9f6a4ee | 10327 | -- Gather component entities into Comp |
67278d60 | 10328 | |
d9f6a4ee | 10329 | Citem := First (Component_Items (CL)); |
10330 | while Present (Citem) loop | |
10331 | if Nkind (Citem) = N_Component_Declaration then | |
10332 | Ncomps := Ncomps + 1; | |
10333 | Comps (Ncomps) := Defining_Identifier (Citem); | |
10334 | end if; | |
67278d60 | 10335 | |
d9f6a4ee | 10336 | Next (Citem); |
10337 | end loop; | |
67278d60 | 10338 | |
d9f6a4ee | 10339 | -- Now sort the component entities based on the first bit. |
10340 | -- Note we already know there are no overlapping components. | |
67278d60 | 10341 | |
d9f6a4ee | 10342 | Sorting.Sort (Ncomps); |
67278d60 | 10343 | |
d9f6a4ee | 10344 | -- Loop through entries checking for holes |
67278d60 | 10345 | |
d9f6a4ee | 10346 | Nbit := Sbit; |
10347 | for J in 1 .. Ncomps loop | |
10348 | CEnt := Comps (J); | |
10349 | Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit; | |
67278d60 | 10350 | |
d9f6a4ee | 10351 | if Error_Msg_Uint_1 > 0 then |
10352 | Error_Msg_NE | |
10353 | ("?H?^-bit gap before component&", | |
10354 | Component_Name (Component_Clause (CEnt)), CEnt); | |
10355 | end if; | |
67278d60 | 10356 | |
d9f6a4ee | 10357 | Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt); |
10358 | end loop; | |
67278d60 | 10359 | |
d9f6a4ee | 10360 | -- Process variant parts recursively if present |
67278d60 | 10361 | |
d9f6a4ee | 10362 | if Present (Variant_Part (CL)) then |
10363 | Variant := First (Variants (Variant_Part (CL))); | |
10364 | while Present (Variant) loop | |
10365 | Check_Component_List | |
10366 | (Component_List (Variant), Nbit, No_List); | |
10367 | Next (Variant); | |
10368 | end loop; | |
67278d60 | 10369 | end if; |
d9f6a4ee | 10370 | end; |
10371 | end Check_Component_List; | |
67278d60 | 10372 | |
d9f6a4ee | 10373 | -- Start of processing for Record_Hole_Check |
67278d60 | 10374 | |
d9f6a4ee | 10375 | begin |
10376 | declare | |
10377 | Sbit : Uint; | |
67278d60 | 10378 | |
d9f6a4ee | 10379 | begin |
10380 | if Is_Tagged_Type (Rectype) then | |
10381 | Sbit := UI_From_Int (System_Address_Size); | |
10382 | else | |
10383 | Sbit := Uint_0; | |
10384 | end if; | |
10385 | ||
10386 | if Nkind (Decl) = N_Full_Type_Declaration | |
10387 | and then Nkind (Type_Definition (Decl)) = N_Record_Definition | |
10388 | then | |
10389 | Check_Component_List | |
10390 | (Component_List (Type_Definition (Decl)), | |
10391 | Sbit, | |
10392 | Discriminant_Specifications (Decl)); | |
67278d60 | 10393 | end if; |
d9f6a4ee | 10394 | end; |
10395 | end Record_Hole_Check; | |
67278d60 | 10396 | end if; |
10397 | ||
d9f6a4ee | 10398 | -- For records that have component clauses for all components, and whose |
10399 | -- size is less than or equal to 32, we need to know the size in the | |
10400 | -- front end to activate possible packed array processing where the | |
10401 | -- component type is a record. | |
67278d60 | 10402 | |
d9f6a4ee | 10403 | -- At this stage Hbit + 1 represents the first unused bit from all the |
10404 | -- component clauses processed, so if the component clauses are | |
10405 | -- complete, then this is the length of the record. | |
67278d60 | 10406 | |
d9f6a4ee | 10407 | -- For records longer than System.Storage_Unit, and for those where not |
10408 | -- all components have component clauses, the back end determines the | |
10409 | -- length (it may for example be appropriate to round up the size | |
10410 | -- to some convenient boundary, based on alignment considerations, etc). | |
67278d60 | 10411 | |
d9f6a4ee | 10412 | if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then |
67278d60 | 10413 | |
d9f6a4ee | 10414 | -- Nothing to do if at least one component has no component clause |
67278d60 | 10415 | |
d9f6a4ee | 10416 | Comp := First_Component_Or_Discriminant (Rectype); |
10417 | while Present (Comp) loop | |
10418 | exit when No (Component_Clause (Comp)); | |
10419 | Next_Component_Or_Discriminant (Comp); | |
10420 | end loop; | |
67278d60 | 10421 | |
d9f6a4ee | 10422 | -- If we fall out of loop, all components have component clauses |
10423 | -- and so we can set the size to the maximum value. | |
67278d60 | 10424 | |
d9f6a4ee | 10425 | if No (Comp) then |
10426 | Set_RM_Size (Rectype, Hbit + 1); | |
10427 | end if; | |
10428 | end if; | |
10429 | end Check_Record_Representation_Clause; | |
67278d60 | 10430 | |
d9f6a4ee | 10431 | ---------------- |
10432 | -- Check_Size -- | |
10433 | ---------------- | |
67278d60 | 10434 | |
d9f6a4ee | 10435 | procedure Check_Size |
10436 | (N : Node_Id; | |
10437 | T : Entity_Id; | |
10438 | Siz : Uint; | |
10439 | Biased : out Boolean) | |
10440 | is | |
f74a102b | 10441 | procedure Size_Too_Small_Error (Min_Siz : Uint); |
10442 | -- Emit an error concerning illegal size Siz. Min_Siz denotes the | |
10443 | -- minimum size. | |
10444 | ||
10445 | -------------------------- | |
10446 | -- Size_Too_Small_Error -- | |
10447 | -------------------------- | |
10448 | ||
10449 | procedure Size_Too_Small_Error (Min_Siz : Uint) is | |
10450 | begin | |
10451 | -- This error is suppressed in ASIS mode to allow for different ASIS | |
f9906591 | 10452 | -- back ends or ASIS-based tools to query the illegal clause. |
f74a102b | 10453 | |
10454 | if not ASIS_Mode then | |
10455 | Error_Msg_Uint_1 := Min_Siz; | |
6d22398d | 10456 | Error_Msg_NE ("size for& too small, minimum allowed is ^", N, T); |
f74a102b | 10457 | end if; |
10458 | end Size_Too_Small_Error; | |
10459 | ||
10460 | -- Local variables | |
10461 | ||
d9f6a4ee | 10462 | UT : constant Entity_Id := Underlying_Type (T); |
10463 | M : Uint; | |
67278d60 | 10464 | |
f74a102b | 10465 | -- Start of processing for Check_Size |
10466 | ||
d9f6a4ee | 10467 | begin |
10468 | Biased := False; | |
67278d60 | 10469 | |
f74a102b | 10470 | -- Reject patently improper size values |
67278d60 | 10471 | |
d9f6a4ee | 10472 | if Is_Elementary_Type (T) |
10473 | and then Siz > UI_From_Int (Int'Last) | |
10474 | then | |
10475 | Error_Msg_N ("Size value too large for elementary type", N); | |
67278d60 | 10476 | |
d9f6a4ee | 10477 | if Nkind (Original_Node (N)) = N_Op_Expon then |
10478 | Error_Msg_N | |
10479 | ("\maybe '* was meant, rather than '*'*", Original_Node (N)); | |
10480 | end if; | |
10481 | end if; | |
67278d60 | 10482 | |
d9f6a4ee | 10483 | -- Dismiss generic types |
67278d60 | 10484 | |
d9f6a4ee | 10485 | if Is_Generic_Type (T) |
10486 | or else | |
10487 | Is_Generic_Type (UT) | |
10488 | or else | |
10489 | Is_Generic_Type (Root_Type (UT)) | |
10490 | then | |
10491 | return; | |
67278d60 | 10492 | |
d9f6a4ee | 10493 | -- Guard against previous errors |
67278d60 | 10494 | |
d9f6a4ee | 10495 | elsif No (UT) or else UT = Any_Type then |
10496 | Check_Error_Detected; | |
10497 | return; | |
67278d60 | 10498 | |
d9f6a4ee | 10499 | -- Check case of bit packed array |
67278d60 | 10500 | |
d9f6a4ee | 10501 | elsif Is_Array_Type (UT) |
10502 | and then Known_Static_Component_Size (UT) | |
10503 | and then Is_Bit_Packed_Array (UT) | |
10504 | then | |
10505 | declare | |
10506 | Asiz : Uint; | |
10507 | Indx : Node_Id; | |
10508 | Ityp : Entity_Id; | |
67278d60 | 10509 | |
d9f6a4ee | 10510 | begin |
10511 | Asiz := Component_Size (UT); | |
10512 | Indx := First_Index (UT); | |
10513 | loop | |
10514 | Ityp := Etype (Indx); | |
67278d60 | 10515 | |
d9f6a4ee | 10516 | -- If non-static bound, then we are not in the business of |
10517 | -- trying to check the length, and indeed an error will be | |
10518 | -- issued elsewhere, since sizes of non-static array types | |
10519 | -- cannot be set implicitly or explicitly. | |
67278d60 | 10520 | |
cda40848 | 10521 | if not Is_OK_Static_Subtype (Ityp) then |
d9f6a4ee | 10522 | return; |
10523 | end if; | |
67278d60 | 10524 | |
d9f6a4ee | 10525 | -- Otherwise accumulate next dimension |
67278d60 | 10526 | |
d9f6a4ee | 10527 | Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) - |
10528 | Expr_Value (Type_Low_Bound (Ityp)) + | |
10529 | Uint_1); | |
67278d60 | 10530 | |
d9f6a4ee | 10531 | Next_Index (Indx); |
10532 | exit when No (Indx); | |
10533 | end loop; | |
67278d60 | 10534 | |
d9f6a4ee | 10535 | if Asiz <= Siz then |
10536 | return; | |
67278d60 | 10537 | |
d9f6a4ee | 10538 | else |
f74a102b | 10539 | Size_Too_Small_Error (Asiz); |
d9f6a4ee | 10540 | Set_Esize (T, Asiz); |
10541 | Set_RM_Size (T, Asiz); | |
10542 | end if; | |
10543 | end; | |
67278d60 | 10544 | |
d9f6a4ee | 10545 | -- All other composite types are ignored |
67278d60 | 10546 | |
d9f6a4ee | 10547 | elsif Is_Composite_Type (UT) then |
10548 | return; | |
47495553 | 10549 | |
d9f6a4ee | 10550 | -- For fixed-point types, don't check minimum if type is not frozen, |
10551 | -- since we don't know all the characteristics of the type that can | |
10552 | -- affect the size (e.g. a specified small) till freeze time. | |
47495553 | 10553 | |
f74a102b | 10554 | elsif Is_Fixed_Point_Type (UT) and then not Is_Frozen (UT) then |
d9f6a4ee | 10555 | null; |
47495553 | 10556 | |
d9f6a4ee | 10557 | -- Cases for which a minimum check is required |
47495553 | 10558 | |
d9f6a4ee | 10559 | else |
10560 | -- Ignore if specified size is correct for the type | |
47495553 | 10561 | |
d9f6a4ee | 10562 | if Known_Esize (UT) and then Siz = Esize (UT) then |
10563 | return; | |
10564 | end if; | |
47495553 | 10565 | |
d9f6a4ee | 10566 | -- Otherwise get minimum size |
47495553 | 10567 | |
d9f6a4ee | 10568 | M := UI_From_Int (Minimum_Size (UT)); |
47495553 | 10569 | |
d9f6a4ee | 10570 | if Siz < M then |
47495553 | 10571 | |
d9f6a4ee | 10572 | -- Size is less than minimum size, but one possibility remains |
10573 | -- that we can manage with the new size if we bias the type. | |
47495553 | 10574 | |
d9f6a4ee | 10575 | M := UI_From_Int (Minimum_Size (UT, Biased => True)); |
47495553 | 10576 | |
d9f6a4ee | 10577 | if Siz < M then |
f74a102b | 10578 | Size_Too_Small_Error (M); |
10579 | Set_Esize (T, M); | |
d9f6a4ee | 10580 | Set_RM_Size (T, M); |
10581 | else | |
10582 | Biased := True; | |
10583 | end if; | |
10584 | end if; | |
10585 | end if; | |
10586 | end Check_Size; | |
47495553 | 10587 | |
d9f6a4ee | 10588 | -------------------------- |
10589 | -- Freeze_Entity_Checks -- | |
10590 | -------------------------- | |
47495553 | 10591 | |
d9f6a4ee | 10592 | procedure Freeze_Entity_Checks (N : Node_Id) is |
8cf481c9 | 10593 | procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id); |
10594 | -- Inspect the primitive operations of type Typ and hide all pairs of | |
3118058b | 10595 | -- implicitly declared non-overridden non-fully conformant homographs |
10596 | -- (Ada RM 8.3 12.3/2). | |
8cf481c9 | 10597 | |
10598 | ------------------------------------- | |
10599 | -- Hide_Non_Overridden_Subprograms -- | |
10600 | ------------------------------------- | |
10601 | ||
10602 | procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is | |
10603 | procedure Hide_Matching_Homographs | |
10604 | (Subp_Id : Entity_Id; | |
10605 | Start_Elmt : Elmt_Id); | |
10606 | -- Inspect a list of primitive operations starting with Start_Elmt | |
3118058b | 10607 | -- and find matching implicitly declared non-overridden non-fully |
10608 | -- conformant homographs of Subp_Id. If found, all matches along | |
10609 | -- with Subp_Id are hidden from all visibility. | |
8cf481c9 | 10610 | |
10611 | function Is_Non_Overridden_Or_Null_Procedure | |
10612 | (Subp_Id : Entity_Id) return Boolean; | |
10613 | -- Determine whether subprogram Subp_Id is implicitly declared non- | |
10614 | -- overridden subprogram or an implicitly declared null procedure. | |
10615 | ||
10616 | ------------------------------ | |
10617 | -- Hide_Matching_Homographs -- | |
10618 | ------------------------------ | |
10619 | ||
10620 | procedure Hide_Matching_Homographs | |
10621 | (Subp_Id : Entity_Id; | |
10622 | Start_Elmt : Elmt_Id) | |
10623 | is | |
10624 | Prim : Entity_Id; | |
10625 | Prim_Elmt : Elmt_Id; | |
10626 | ||
10627 | begin | |
10628 | Prim_Elmt := Start_Elmt; | |
10629 | while Present (Prim_Elmt) loop | |
10630 | Prim := Node (Prim_Elmt); | |
10631 | ||
10632 | -- The current primitive is implicitly declared non-overridden | |
3118058b | 10633 | -- non-fully conformant homograph of Subp_Id. Both subprograms |
10634 | -- must be hidden from visibility. | |
8cf481c9 | 10635 | |
10636 | if Chars (Prim) = Chars (Subp_Id) | |
8cf481c9 | 10637 | and then Is_Non_Overridden_Or_Null_Procedure (Prim) |
3118058b | 10638 | and then not Fully_Conformant (Prim, Subp_Id) |
8cf481c9 | 10639 | then |
8c7ee4ac | 10640 | Set_Is_Hidden_Non_Overridden_Subpgm (Prim); |
10641 | Set_Is_Immediately_Visible (Prim, False); | |
10642 | Set_Is_Potentially_Use_Visible (Prim, False); | |
8cf481c9 | 10643 | |
8c7ee4ac | 10644 | Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id); |
10645 | Set_Is_Immediately_Visible (Subp_Id, False); | |
10646 | Set_Is_Potentially_Use_Visible (Subp_Id, False); | |
8cf481c9 | 10647 | end if; |
10648 | ||
10649 | Next_Elmt (Prim_Elmt); | |
10650 | end loop; | |
10651 | end Hide_Matching_Homographs; | |
10652 | ||
10653 | ----------------------------------------- | |
10654 | -- Is_Non_Overridden_Or_Null_Procedure -- | |
10655 | ----------------------------------------- | |
10656 | ||
10657 | function Is_Non_Overridden_Or_Null_Procedure | |
10658 | (Subp_Id : Entity_Id) return Boolean | |
10659 | is | |
10660 | Alias_Id : Entity_Id; | |
10661 | ||
10662 | begin | |
10663 | -- The subprogram is inherited (implicitly declared), it does not | |
10664 | -- override and does not cover a primitive of an interface. | |
10665 | ||
10666 | if Ekind_In (Subp_Id, E_Function, E_Procedure) | |
10667 | and then Present (Alias (Subp_Id)) | |
10668 | and then No (Interface_Alias (Subp_Id)) | |
10669 | and then No (Overridden_Operation (Subp_Id)) | |
10670 | then | |
10671 | Alias_Id := Alias (Subp_Id); | |
10672 | ||
10673 | if Requires_Overriding (Alias_Id) then | |
10674 | return True; | |
10675 | ||
10676 | elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification | |
10677 | and then Null_Present (Parent (Alias_Id)) | |
10678 | then | |
10679 | return True; | |
10680 | end if; | |
10681 | end if; | |
10682 | ||
10683 | return False; | |
10684 | end Is_Non_Overridden_Or_Null_Procedure; | |
10685 | ||
10686 | -- Local variables | |
10687 | ||
10688 | Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ); | |
10689 | Prim : Entity_Id; | |
10690 | Prim_Elmt : Elmt_Id; | |
10691 | ||
10692 | -- Start of processing for Hide_Non_Overridden_Subprograms | |
10693 | ||
10694 | begin | |
3118058b | 10695 | -- Inspect the list of primitives looking for non-overridden |
10696 | -- subprograms. | |
8cf481c9 | 10697 | |
10698 | if Present (Prim_Ops) then | |
10699 | Prim_Elmt := First_Elmt (Prim_Ops); | |
10700 | while Present (Prim_Elmt) loop | |
10701 | Prim := Node (Prim_Elmt); | |
10702 | Next_Elmt (Prim_Elmt); | |
10703 | ||
10704 | if Is_Non_Overridden_Or_Null_Procedure (Prim) then | |
10705 | Hide_Matching_Homographs | |
10706 | (Subp_Id => Prim, | |
10707 | Start_Elmt => Prim_Elmt); | |
10708 | end if; | |
10709 | end loop; | |
10710 | end if; | |
10711 | end Hide_Non_Overridden_Subprograms; | |
10712 | ||
97c23bbe | 10713 | -- Local variables |
8cf481c9 | 10714 | |
d9f6a4ee | 10715 | E : constant Entity_Id := Entity (N); |
47495553 | 10716 | |
d9f6a4ee | 10717 | Non_Generic_Case : constant Boolean := Nkind (N) = N_Freeze_Entity; |
10718 | -- True in non-generic case. Some of the processing here is skipped | |
10719 | -- for the generic case since it is not needed. Basically in the | |
10720 | -- generic case, we only need to do stuff that might generate error | |
10721 | -- messages or warnings. | |
8cf481c9 | 10722 | |
10723 | -- Start of processing for Freeze_Entity_Checks | |
10724 | ||
d9f6a4ee | 10725 | begin |
10726 | -- Remember that we are processing a freezing entity. Required to | |
10727 | -- ensure correct decoration of internal entities associated with | |
10728 | -- interfaces (see New_Overloaded_Entity). | |
47495553 | 10729 | |
d9f6a4ee | 10730 | Inside_Freezing_Actions := Inside_Freezing_Actions + 1; |
47495553 | 10731 | |
d9f6a4ee | 10732 | -- For tagged types covering interfaces add internal entities that link |
10733 | -- the primitives of the interfaces with the primitives that cover them. | |
10734 | -- Note: These entities were originally generated only when generating | |
10735 | -- code because their main purpose was to provide support to initialize | |
10736 | -- the secondary dispatch tables. They are now generated also when | |
10737 | -- compiling with no code generation to provide ASIS the relationship | |
10738 | -- between interface primitives and tagged type primitives. They are | |
10739 | -- also used to locate primitives covering interfaces when processing | |
10740 | -- generics (see Derive_Subprograms). | |
47495553 | 10741 | |
d9f6a4ee | 10742 | -- This is not needed in the generic case |
47495553 | 10743 | |
d9f6a4ee | 10744 | if Ada_Version >= Ada_2005 |
10745 | and then Non_Generic_Case | |
10746 | and then Ekind (E) = E_Record_Type | |
10747 | and then Is_Tagged_Type (E) | |
10748 | and then not Is_Interface (E) | |
10749 | and then Has_Interfaces (E) | |
10750 | then | |
10751 | -- This would be a good common place to call the routine that checks | |
10752 | -- overriding of interface primitives (and thus factorize calls to | |
10753 | -- Check_Abstract_Overriding located at different contexts in the | |
10754 | -- compiler). However, this is not possible because it causes | |
10755 | -- spurious errors in case of late overriding. | |
47495553 | 10756 | |
d9f6a4ee | 10757 | Add_Internal_Interface_Entities (E); |
10758 | end if; | |
47495553 | 10759 | |
8cf481c9 | 10760 | -- After all forms of overriding have been resolved, a tagged type may |
10761 | -- be left with a set of implicitly declared and possibly erroneous | |
10762 | -- abstract subprograms, null procedures and subprograms that require | |
0c4e0575 | 10763 | -- overriding. If this set contains fully conformant homographs, then |
10764 | -- one is chosen arbitrarily (already done during resolution), otherwise | |
10765 | -- all remaining non-fully conformant homographs are hidden from | |
10766 | -- visibility (Ada RM 8.3 12.3/2). | |
8cf481c9 | 10767 | |
10768 | if Is_Tagged_Type (E) then | |
10769 | Hide_Non_Overridden_Subprograms (E); | |
10770 | end if; | |
10771 | ||
d9f6a4ee | 10772 | -- Check CPP types |
47495553 | 10773 | |
d9f6a4ee | 10774 | if Ekind (E) = E_Record_Type |
10775 | and then Is_CPP_Class (E) | |
10776 | and then Is_Tagged_Type (E) | |
10777 | and then Tagged_Type_Expansion | |
d9f6a4ee | 10778 | then |
10779 | if CPP_Num_Prims (E) = 0 then | |
47495553 | 10780 | |
d9f6a4ee | 10781 | -- If the CPP type has user defined components then it must import |
10782 | -- primitives from C++. This is required because if the C++ class | |
10783 | -- has no primitives then the C++ compiler does not added the _tag | |
10784 | -- component to the type. | |
47495553 | 10785 | |
d9f6a4ee | 10786 | if First_Entity (E) /= Last_Entity (E) then |
10787 | Error_Msg_N | |
10788 | ("'C'P'P type must import at least one primitive from C++??", | |
10789 | E); | |
10790 | end if; | |
10791 | end if; | |
47495553 | 10792 | |
d9f6a4ee | 10793 | -- Check that all its primitives are abstract or imported from C++. |
10794 | -- Check also availability of the C++ constructor. | |
47495553 | 10795 | |
d9f6a4ee | 10796 | declare |
10797 | Has_Constructors : constant Boolean := Has_CPP_Constructors (E); | |
10798 | Elmt : Elmt_Id; | |
10799 | Error_Reported : Boolean := False; | |
10800 | Prim : Node_Id; | |
47495553 | 10801 | |
d9f6a4ee | 10802 | begin |
10803 | Elmt := First_Elmt (Primitive_Operations (E)); | |
10804 | while Present (Elmt) loop | |
10805 | Prim := Node (Elmt); | |
47495553 | 10806 | |
d9f6a4ee | 10807 | if Comes_From_Source (Prim) then |
10808 | if Is_Abstract_Subprogram (Prim) then | |
10809 | null; | |
47495553 | 10810 | |
d9f6a4ee | 10811 | elsif not Is_Imported (Prim) |
10812 | or else Convention (Prim) /= Convention_CPP | |
10813 | then | |
10814 | Error_Msg_N | |
10815 | ("primitives of 'C'P'P types must be imported from C++ " | |
10816 | & "or abstract??", Prim); | |
47495553 | 10817 | |
d9f6a4ee | 10818 | elsif not Has_Constructors |
10819 | and then not Error_Reported | |
10820 | then | |
10821 | Error_Msg_Name_1 := Chars (E); | |
10822 | Error_Msg_N | |
10823 | ("??'C'P'P constructor required for type %", Prim); | |
10824 | Error_Reported := True; | |
10825 | end if; | |
10826 | end if; | |
47495553 | 10827 | |
d9f6a4ee | 10828 | Next_Elmt (Elmt); |
10829 | end loop; | |
10830 | end; | |
10831 | end if; | |
47495553 | 10832 | |
d9f6a4ee | 10833 | -- Check Ada derivation of CPP type |
47495553 | 10834 | |
30ab103b | 10835 | if Expander_Active -- why? losing errors in -gnatc mode??? |
10836 | and then Present (Etype (E)) -- defend against errors | |
d9f6a4ee | 10837 | and then Tagged_Type_Expansion |
10838 | and then Ekind (E) = E_Record_Type | |
10839 | and then Etype (E) /= E | |
10840 | and then Is_CPP_Class (Etype (E)) | |
10841 | and then CPP_Num_Prims (Etype (E)) > 0 | |
10842 | and then not Is_CPP_Class (E) | |
10843 | and then not Has_CPP_Constructors (Etype (E)) | |
10844 | then | |
10845 | -- If the parent has C++ primitives but it has no constructor then | |
10846 | -- check that all the primitives are overridden in this derivation; | |
10847 | -- otherwise the constructor of the parent is needed to build the | |
10848 | -- dispatch table. | |
47495553 | 10849 | |
d9f6a4ee | 10850 | declare |
10851 | Elmt : Elmt_Id; | |
10852 | Prim : Node_Id; | |
47495553 | 10853 | |
10854 | begin | |
d9f6a4ee | 10855 | Elmt := First_Elmt (Primitive_Operations (E)); |
10856 | while Present (Elmt) loop | |
10857 | Prim := Node (Elmt); | |
47495553 | 10858 | |
d9f6a4ee | 10859 | if not Is_Abstract_Subprogram (Prim) |
10860 | and then No (Interface_Alias (Prim)) | |
10861 | and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E | |
47495553 | 10862 | then |
d9f6a4ee | 10863 | Error_Msg_Name_1 := Chars (Etype (E)); |
10864 | Error_Msg_N | |
10865 | ("'C'P'P constructor required for parent type %", E); | |
10866 | exit; | |
47495553 | 10867 | end if; |
d9f6a4ee | 10868 | |
10869 | Next_Elmt (Elmt); | |
10870 | end loop; | |
10871 | end; | |
47495553 | 10872 | end if; |
10873 | ||
d9f6a4ee | 10874 | Inside_Freezing_Actions := Inside_Freezing_Actions - 1; |
67278d60 | 10875 | |
97c23bbe | 10876 | -- If we have a type with predicates, build predicate function. This is |
10877 | -- not needed in the generic case, nor within TSS subprograms and other | |
10878 | -- predefined primitives. | |
67278d60 | 10879 | |
97c23bbe | 10880 | if Is_Type (E) |
10881 | and then Non_Generic_Case | |
ea822fd4 | 10882 | and then not Within_Internal_Subprogram |
97c23bbe | 10883 | and then Has_Predicates (E) |
ea822fd4 | 10884 | then |
d9f6a4ee | 10885 | Build_Predicate_Functions (E, N); |
10886 | end if; | |
67278d60 | 10887 | |
d9f6a4ee | 10888 | -- If type has delayed aspects, this is where we do the preanalysis at |
10889 | -- the freeze point, as part of the consistent visibility check. Note | |
10890 | -- that this must be done after calling Build_Predicate_Functions or | |
10891 | -- Build_Invariant_Procedure since these subprograms fix occurrences of | |
10892 | -- the subtype name in the saved expression so that they will not cause | |
10893 | -- trouble in the preanalysis. | |
67278d60 | 10894 | |
61989dbb | 10895 | -- This is also not needed in the generic case |
d9f6a4ee | 10896 | |
61989dbb | 10897 | if Non_Generic_Case |
10898 | and then Has_Delayed_Aspects (E) | |
d9f6a4ee | 10899 | and then Scope (E) = Current_Scope |
10900 | then | |
10901 | -- Retrieve the visibility to the discriminants in order to properly | |
10902 | -- analyze the aspects. | |
10903 | ||
10904 | Push_Scope_And_Install_Discriminants (E); | |
10905 | ||
10906 | declare | |
10907 | Ritem : Node_Id; | |
10908 | ||
10909 | begin | |
10910 | -- Look for aspect specification entries for this entity | |
67278d60 | 10911 | |
d9f6a4ee | 10912 | Ritem := First_Rep_Item (E); |
10913 | while Present (Ritem) loop | |
10914 | if Nkind (Ritem) = N_Aspect_Specification | |
10915 | and then Entity (Ritem) = E | |
10916 | and then Is_Delayed_Aspect (Ritem) | |
10917 | then | |
10918 | Check_Aspect_At_Freeze_Point (Ritem); | |
10919 | end if; | |
67278d60 | 10920 | |
d9f6a4ee | 10921 | Next_Rep_Item (Ritem); |
10922 | end loop; | |
10923 | end; | |
67278d60 | 10924 | |
d9f6a4ee | 10925 | Uninstall_Discriminants_And_Pop_Scope (E); |
67278d60 | 10926 | end if; |
67278d60 | 10927 | |
d9f6a4ee | 10928 | -- For a record type, deal with variant parts. This has to be delayed |
d0988351 | 10929 | -- to this point, because of the issue of statically predicated |
d9f6a4ee | 10930 | -- subtypes, which we have to ensure are frozen before checking |
10931 | -- choices, since we need to have the static choice list set. | |
d6f39728 | 10932 | |
d9f6a4ee | 10933 | if Is_Record_Type (E) then |
10934 | Check_Variant_Part : declare | |
10935 | D : constant Node_Id := Declaration_Node (E); | |
10936 | T : Node_Id; | |
10937 | C : Node_Id; | |
10938 | VP : Node_Id; | |
d6f39728 | 10939 | |
d9f6a4ee | 10940 | Others_Present : Boolean; |
10941 | pragma Warnings (Off, Others_Present); | |
10942 | -- Indicates others present, not used in this case | |
d6f39728 | 10943 | |
d9f6a4ee | 10944 | procedure Non_Static_Choice_Error (Choice : Node_Id); |
10945 | -- Error routine invoked by the generic instantiation below when | |
10946 | -- the variant part has a non static choice. | |
f117057b | 10947 | |
d9f6a4ee | 10948 | procedure Process_Declarations (Variant : Node_Id); |
10949 | -- Processes declarations associated with a variant. We analyzed | |
10950 | -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part), | |
10951 | -- but we still need the recursive call to Check_Choices for any | |
10952 | -- nested variant to get its choices properly processed. This is | |
10953 | -- also where we expand out the choices if expansion is active. | |
1f526845 | 10954 | |
d9f6a4ee | 10955 | package Variant_Choices_Processing is new |
10956 | Generic_Check_Choices | |
10957 | (Process_Empty_Choice => No_OP, | |
10958 | Process_Non_Static_Choice => Non_Static_Choice_Error, | |
10959 | Process_Associated_Node => Process_Declarations); | |
10960 | use Variant_Choices_Processing; | |
f117057b | 10961 | |
d9f6a4ee | 10962 | ----------------------------- |
10963 | -- Non_Static_Choice_Error -- | |
10964 | ----------------------------- | |
d6f39728 | 10965 | |
d9f6a4ee | 10966 | procedure Non_Static_Choice_Error (Choice : Node_Id) is |
10967 | begin | |
10968 | Flag_Non_Static_Expr | |
10969 | ("choice given in variant part is not static!", Choice); | |
10970 | end Non_Static_Choice_Error; | |
d6f39728 | 10971 | |
d9f6a4ee | 10972 | -------------------------- |
10973 | -- Process_Declarations -- | |
10974 | -------------------------- | |
dba36b60 | 10975 | |
d9f6a4ee | 10976 | procedure Process_Declarations (Variant : Node_Id) is |
10977 | CL : constant Node_Id := Component_List (Variant); | |
10978 | VP : Node_Id; | |
dba36b60 | 10979 | |
d9f6a4ee | 10980 | begin |
10981 | -- Check for static predicate present in this variant | |
ea61a7ea | 10982 | |
d9f6a4ee | 10983 | if Has_SP_Choice (Variant) then |
ea61a7ea | 10984 | |
d9f6a4ee | 10985 | -- Here we expand. You might expect to find this call in |
10986 | -- Expand_N_Variant_Part, but that is called when we first | |
10987 | -- see the variant part, and we cannot do this expansion | |
10988 | -- earlier than the freeze point, since for statically | |
10989 | -- predicated subtypes, the predicate is not known till | |
10990 | -- the freeze point. | |
ea61a7ea | 10991 | |
d9f6a4ee | 10992 | -- Furthermore, we do this expansion even if the expander |
10993 | -- is not active, because other semantic processing, e.g. | |
10994 | -- for aggregates, requires the expanded list of choices. | |
ea61a7ea | 10995 | |
d9f6a4ee | 10996 | -- If the expander is not active, then we can't just clobber |
10997 | -- the list since it would invalidate the ASIS -gnatct tree. | |
10998 | -- So we have to rewrite the variant part with a Rewrite | |
10999 | -- call that replaces it with a copy and clobber the copy. | |
11000 | ||
11001 | if not Expander_Active then | |
11002 | declare | |
11003 | NewV : constant Node_Id := New_Copy (Variant); | |
11004 | begin | |
11005 | Set_Discrete_Choices | |
11006 | (NewV, New_Copy_List (Discrete_Choices (Variant))); | |
11007 | Rewrite (Variant, NewV); | |
11008 | end; | |
11009 | end if; | |
11010 | ||
11011 | Expand_Static_Predicates_In_Choices (Variant); | |
ea61a7ea | 11012 | end if; |
11013 | ||
d9f6a4ee | 11014 | -- We don't need to worry about the declarations in the variant |
11015 | -- (since they were analyzed by Analyze_Choices when we first | |
11016 | -- encountered the variant), but we do need to take care of | |
11017 | -- expansion of any nested variants. | |
ea61a7ea | 11018 | |
d9f6a4ee | 11019 | if not Null_Present (CL) then |
11020 | VP := Variant_Part (CL); | |
ea61a7ea | 11021 | |
d9f6a4ee | 11022 | if Present (VP) then |
11023 | Check_Choices | |
11024 | (VP, Variants (VP), Etype (Name (VP)), Others_Present); | |
11025 | end if; | |
11026 | end if; | |
11027 | end Process_Declarations; | |
ea61a7ea | 11028 | |
d9f6a4ee | 11029 | -- Start of processing for Check_Variant_Part |
b9e61b2a | 11030 | |
d9f6a4ee | 11031 | begin |
11032 | -- Find component list | |
ea61a7ea | 11033 | |
d9f6a4ee | 11034 | C := Empty; |
ea61a7ea | 11035 | |
d9f6a4ee | 11036 | if Nkind (D) = N_Full_Type_Declaration then |
11037 | T := Type_Definition (D); | |
ea61a7ea | 11038 | |
d9f6a4ee | 11039 | if Nkind (T) = N_Record_Definition then |
11040 | C := Component_List (T); | |
d6f39728 | 11041 | |
d9f6a4ee | 11042 | elsif Nkind (T) = N_Derived_Type_Definition |
11043 | and then Present (Record_Extension_Part (T)) | |
11044 | then | |
11045 | C := Component_List (Record_Extension_Part (T)); | |
11046 | end if; | |
11047 | end if; | |
d6f39728 | 11048 | |
d9f6a4ee | 11049 | -- Case of variant part present |
d6f39728 | 11050 | |
d9f6a4ee | 11051 | if Present (C) and then Present (Variant_Part (C)) then |
11052 | VP := Variant_Part (C); | |
ea61a7ea | 11053 | |
d9f6a4ee | 11054 | -- Check choices |
ea61a7ea | 11055 | |
d9f6a4ee | 11056 | Check_Choices |
11057 | (VP, Variants (VP), Etype (Name (VP)), Others_Present); | |
ea61a7ea | 11058 | |
d9f6a4ee | 11059 | -- If the last variant does not contain the Others choice, |
11060 | -- replace it with an N_Others_Choice node since Gigi always | |
11061 | -- wants an Others. Note that we do not bother to call Analyze | |
11062 | -- on the modified variant part, since its only effect would be | |
11063 | -- to compute the Others_Discrete_Choices node laboriously, and | |
11064 | -- of course we already know the list of choices corresponding | |
39a0c1d3 | 11065 | -- to the others choice (it's the list we're replacing). |
d6f39728 | 11066 | |
d9f6a4ee | 11067 | -- We only want to do this if the expander is active, since |
39a0c1d3 | 11068 | -- we do not want to clobber the ASIS tree. |
d6f39728 | 11069 | |
d9f6a4ee | 11070 | if Expander_Active then |
11071 | declare | |
11072 | Last_Var : constant Node_Id := | |
11073 | Last_Non_Pragma (Variants (VP)); | |
d6f39728 | 11074 | |
d9f6a4ee | 11075 | Others_Node : Node_Id; |
d6f39728 | 11076 | |
d9f6a4ee | 11077 | begin |
11078 | if Nkind (First (Discrete_Choices (Last_Var))) /= | |
11079 | N_Others_Choice | |
11080 | then | |
11081 | Others_Node := Make_Others_Choice (Sloc (Last_Var)); | |
11082 | Set_Others_Discrete_Choices | |
11083 | (Others_Node, Discrete_Choices (Last_Var)); | |
11084 | Set_Discrete_Choices | |
11085 | (Last_Var, New_List (Others_Node)); | |
11086 | end if; | |
11087 | end; | |
11088 | end if; | |
d6f39728 | 11089 | end if; |
d9f6a4ee | 11090 | end Check_Variant_Part; |
d6f39728 | 11091 | end if; |
d9f6a4ee | 11092 | end Freeze_Entity_Checks; |
d6f39728 | 11093 | |
11094 | ------------------------- | |
11095 | -- Get_Alignment_Value -- | |
11096 | ------------------------- | |
11097 | ||
11098 | function Get_Alignment_Value (Expr : Node_Id) return Uint is | |
f5d97bf5 | 11099 | Align : constant Uint := Static_Integer (Expr); |
f74a102b | 11100 | |
f5d97bf5 | 11101 | begin |
11102 | if Align = No_Uint then | |
11103 | return No_Uint; | |
11104 | ||
11105 | elsif Align <= 0 then | |
f74a102b | 11106 | |
f74a102b | 11107 | -- This error is suppressed in ASIS mode to allow for different ASIS |
f9906591 | 11108 | -- back ends or ASIS-based tools to query the illegal clause. |
f74a102b | 11109 | |
11110 | if not ASIS_Mode then | |
11111 | Error_Msg_N ("alignment value must be positive", Expr); | |
11112 | end if; | |
f74a102b | 11113 | |
d6f39728 | 11114 | return No_Uint; |
11115 | ||
11116 | else | |
11117 | for J in Int range 0 .. 64 loop | |
11118 | declare | |
11119 | M : constant Uint := Uint_2 ** J; | |
11120 | ||
11121 | begin | |
11122 | exit when M = Align; | |
11123 | ||
11124 | if M > Align then | |
f5d97bf5 | 11125 | |
11126 | -- This error is suppressed in ASIS mode to allow for | |
f9906591 | 11127 | -- different ASIS back ends or ASIS-based tools to query the |
f5d97bf5 | 11128 | -- illegal clause. |
11129 | ||
11130 | if not ASIS_Mode then | |
11131 | Error_Msg_N ("alignment value must be power of 2", Expr); | |
11132 | end if; | |
11133 | ||
d6f39728 | 11134 | return No_Uint; |
11135 | end if; | |
11136 | end; | |
11137 | end loop; | |
11138 | ||
11139 | return Align; | |
11140 | end if; | |
11141 | end Get_Alignment_Value; | |
11142 | ||
ee2b7923 | 11143 | ----------------------------- |
11144 | -- Get_Interfacing_Aspects -- | |
11145 | ----------------------------- | |
11146 | ||
11147 | procedure Get_Interfacing_Aspects | |
11148 | (Iface_Asp : Node_Id; | |
11149 | Conv_Asp : out Node_Id; | |
11150 | EN_Asp : out Node_Id; | |
11151 | Expo_Asp : out Node_Id; | |
11152 | Imp_Asp : out Node_Id; | |
11153 | LN_Asp : out Node_Id; | |
11154 | Do_Checks : Boolean := False) | |
11155 | is | |
11156 | procedure Save_Or_Duplication_Error | |
11157 | (Asp : Node_Id; | |
11158 | To : in out Node_Id); | |
11159 | -- Save the value of aspect Asp in node To. If To already has a value, | |
11160 | -- then this is considered a duplicate use of aspect. Emit an error if | |
11161 | -- flag Do_Checks is set. | |
11162 | ||
11163 | ------------------------------- | |
11164 | -- Save_Or_Duplication_Error -- | |
11165 | ------------------------------- | |
11166 | ||
11167 | procedure Save_Or_Duplication_Error | |
11168 | (Asp : Node_Id; | |
11169 | To : in out Node_Id) | |
11170 | is | |
11171 | begin | |
11172 | -- Detect an extra aspect and issue an error | |
11173 | ||
11174 | if Present (To) then | |
11175 | if Do_Checks then | |
11176 | Error_Msg_Name_1 := Chars (Identifier (Asp)); | |
11177 | Error_Msg_Sloc := Sloc (To); | |
11178 | Error_Msg_N ("aspect % previously given #", Asp); | |
11179 | end if; | |
11180 | ||
11181 | -- Otherwise capture the aspect | |
11182 | ||
11183 | else | |
11184 | To := Asp; | |
11185 | end if; | |
11186 | end Save_Or_Duplication_Error; | |
11187 | ||
11188 | -- Local variables | |
11189 | ||
11190 | Asp : Node_Id; | |
11191 | Asp_Id : Aspect_Id; | |
11192 | ||
11193 | -- The following variables capture each individual aspect | |
11194 | ||
11195 | Conv : Node_Id := Empty; | |
11196 | EN : Node_Id := Empty; | |
11197 | Expo : Node_Id := Empty; | |
11198 | Imp : Node_Id := Empty; | |
11199 | LN : Node_Id := Empty; | |
11200 | ||
11201 | -- Start of processing for Get_Interfacing_Aspects | |
11202 | ||
11203 | begin | |
11204 | -- The input interfacing aspect should reside in an aspect specification | |
11205 | -- list. | |
11206 | ||
11207 | pragma Assert (Is_List_Member (Iface_Asp)); | |
11208 | ||
11209 | -- Examine the aspect specifications of the related entity. Find and | |
11210 | -- capture all interfacing aspects. Detect duplicates and emit errors | |
11211 | -- if applicable. | |
11212 | ||
11213 | Asp := First (List_Containing (Iface_Asp)); | |
11214 | while Present (Asp) loop | |
11215 | Asp_Id := Get_Aspect_Id (Asp); | |
11216 | ||
11217 | if Asp_Id = Aspect_Convention then | |
11218 | Save_Or_Duplication_Error (Asp, Conv); | |
11219 | ||
11220 | elsif Asp_Id = Aspect_External_Name then | |
11221 | Save_Or_Duplication_Error (Asp, EN); | |
11222 | ||
11223 | elsif Asp_Id = Aspect_Export then | |
11224 | Save_Or_Duplication_Error (Asp, Expo); | |
11225 | ||
11226 | elsif Asp_Id = Aspect_Import then | |
11227 | Save_Or_Duplication_Error (Asp, Imp); | |
11228 | ||
11229 | elsif Asp_Id = Aspect_Link_Name then | |
11230 | Save_Or_Duplication_Error (Asp, LN); | |
11231 | end if; | |
11232 | ||
11233 | Next (Asp); | |
11234 | end loop; | |
11235 | ||
11236 | Conv_Asp := Conv; | |
11237 | EN_Asp := EN; | |
11238 | Expo_Asp := Expo; | |
11239 | Imp_Asp := Imp; | |
11240 | LN_Asp := LN; | |
11241 | end Get_Interfacing_Aspects; | |
11242 | ||
99a2d5bd | 11243 | ------------------------------------- |
11244 | -- Inherit_Aspects_At_Freeze_Point -- | |
11245 | ------------------------------------- | |
11246 | ||
11247 | procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is | |
11248 | function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11249 | (Rep_Item : Node_Id) return Boolean; | |
11250 | -- This routine checks if Rep_Item is either a pragma or an aspect | |
11251 | -- specification node whose correponding pragma (if any) is present in | |
11252 | -- the Rep Item chain of the entity it has been specified to. | |
11253 | ||
11254 | -------------------------------------------------- | |
11255 | -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item -- | |
11256 | -------------------------------------------------- | |
11257 | ||
11258 | function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11259 | (Rep_Item : Node_Id) return Boolean | |
11260 | is | |
11261 | begin | |
ec6f6da5 | 11262 | return |
11263 | Nkind (Rep_Item) = N_Pragma | |
11264 | or else Present_In_Rep_Item | |
11265 | (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item)); | |
99a2d5bd | 11266 | end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item; |
11267 | ||
29a9d4be | 11268 | -- Start of processing for Inherit_Aspects_At_Freeze_Point |
11269 | ||
99a2d5bd | 11270 | begin |
11271 | -- A representation item is either subtype-specific (Size and Alignment | |
11272 | -- clauses) or type-related (all others). Subtype-specific aspects may | |
29a9d4be | 11273 | -- differ for different subtypes of the same type (RM 13.1.8). |
99a2d5bd | 11274 | |
11275 | -- A derived type inherits each type-related representation aspect of | |
11276 | -- its parent type that was directly specified before the declaration of | |
29a9d4be | 11277 | -- the derived type (RM 13.1.15). |
99a2d5bd | 11278 | |
11279 | -- A derived subtype inherits each subtype-specific representation | |
11280 | -- aspect of its parent subtype that was directly specified before the | |
29a9d4be | 11281 | -- declaration of the derived type (RM 13.1.15). |
99a2d5bd | 11282 | |
11283 | -- The general processing involves inheriting a representation aspect | |
11284 | -- from a parent type whenever the first rep item (aspect specification, | |
11285 | -- attribute definition clause, pragma) corresponding to the given | |
11286 | -- representation aspect in the rep item chain of Typ, if any, isn't | |
11287 | -- directly specified to Typ but to one of its parents. | |
11288 | ||
11289 | -- ??? Note that, for now, just a limited number of representation | |
29a9d4be | 11290 | -- aspects have been inherited here so far. Many of them are |
11291 | -- still inherited in Sem_Ch3. This will be fixed soon. Here is | |
11292 | -- a non- exhaustive list of aspects that likely also need to | |
11293 | -- be moved to this routine: Alignment, Component_Alignment, | |
11294 | -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates, | |
99a2d5bd | 11295 | -- Preelaborable_Initialization, RM_Size and Small. |
11296 | ||
8b6e9bf2 | 11297 | -- In addition, Convention must be propagated from base type to subtype, |
11298 | -- because the subtype may have been declared on an incomplete view. | |
11299 | ||
99a2d5bd | 11300 | if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then |
11301 | return; | |
11302 | end if; | |
11303 | ||
11304 | -- Ada_05/Ada_2005 | |
11305 | ||
11306 | if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False) | |
11307 | and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005) | |
11308 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11309 | (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)) | |
11310 | then | |
11311 | Set_Is_Ada_2005_Only (Typ); | |
11312 | end if; | |
11313 | ||
11314 | -- Ada_12/Ada_2012 | |
11315 | ||
11316 | if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False) | |
11317 | and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012) | |
11318 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11319 | (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)) | |
11320 | then | |
11321 | Set_Is_Ada_2012_Only (Typ); | |
11322 | end if; | |
11323 | ||
11324 | -- Atomic/Shared | |
11325 | ||
11326 | if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False) | |
11327 | and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared) | |
11328 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11329 | (Get_Rep_Item (Typ, Name_Atomic, Name_Shared)) | |
11330 | then | |
11331 | Set_Is_Atomic (Typ); | |
99a2d5bd | 11332 | Set_Is_Volatile (Typ); |
4bf2acc9 | 11333 | Set_Treat_As_Volatile (Typ); |
99a2d5bd | 11334 | end if; |
11335 | ||
8b6e9bf2 | 11336 | -- Convention |
11337 | ||
7ac4254e | 11338 | if Is_Record_Type (Typ) |
11339 | and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ)) | |
11340 | then | |
8b6e9bf2 | 11341 | Set_Convention (Typ, Convention (Base_Type (Typ))); |
11342 | end if; | |
11343 | ||
29a9d4be | 11344 | -- Default_Component_Value |
99a2d5bd | 11345 | |
81c2bc19 | 11346 | -- Verify that there is no rep_item declared for the type, and there |
11347 | -- is one coming from an ancestor. | |
11348 | ||
99a2d5bd | 11349 | if Is_Array_Type (Typ) |
f3d70f08 | 11350 | and then Is_Base_Type (Typ) |
81c2bc19 | 11351 | and then not Has_Rep_Item (Typ, Name_Default_Component_Value, False) |
99a2d5bd | 11352 | and then Has_Rep_Item (Typ, Name_Default_Component_Value) |
11353 | then | |
11354 | Set_Default_Aspect_Component_Value (Typ, | |
11355 | Default_Aspect_Component_Value | |
11356 | (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value)))); | |
11357 | end if; | |
11358 | ||
29a9d4be | 11359 | -- Default_Value |
99a2d5bd | 11360 | |
11361 | if Is_Scalar_Type (Typ) | |
f3d70f08 | 11362 | and then Is_Base_Type (Typ) |
81c2bc19 | 11363 | and then not Has_Rep_Item (Typ, Name_Default_Value, False) |
99a2d5bd | 11364 | and then Has_Rep_Item (Typ, Name_Default_Value) |
11365 | then | |
81c2bc19 | 11366 | Set_Has_Default_Aspect (Typ); |
99a2d5bd | 11367 | Set_Default_Aspect_Value (Typ, |
11368 | Default_Aspect_Value | |
11369 | (Entity (Get_Rep_Item (Typ, Name_Default_Value)))); | |
11370 | end if; | |
11371 | ||
11372 | -- Discard_Names | |
11373 | ||
11374 | if not Has_Rep_Item (Typ, Name_Discard_Names, False) | |
11375 | and then Has_Rep_Item (Typ, Name_Discard_Names) | |
11376 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11377 | (Get_Rep_Item (Typ, Name_Discard_Names)) | |
11378 | then | |
11379 | Set_Discard_Names (Typ); | |
11380 | end if; | |
11381 | ||
99a2d5bd | 11382 | -- Volatile |
11383 | ||
11384 | if not Has_Rep_Item (Typ, Name_Volatile, False) | |
11385 | and then Has_Rep_Item (Typ, Name_Volatile) | |
11386 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11387 | (Get_Rep_Item (Typ, Name_Volatile)) | |
11388 | then | |
99a2d5bd | 11389 | Set_Is_Volatile (Typ); |
4bf2acc9 | 11390 | Set_Treat_As_Volatile (Typ); |
99a2d5bd | 11391 | end if; |
11392 | ||
2fe893b9 | 11393 | -- Volatile_Full_Access |
11394 | ||
11395 | if not Has_Rep_Item (Typ, Name_Volatile_Full_Access, False) | |
11396 | and then Has_Rep_Pragma (Typ, Name_Volatile_Full_Access) | |
11397 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11398 | (Get_Rep_Item (Typ, Name_Volatile_Full_Access)) | |
11399 | then | |
4bf2acc9 | 11400 | Set_Is_Volatile_Full_Access (Typ); |
2fe893b9 | 11401 | Set_Is_Volatile (Typ); |
4bf2acc9 | 11402 | Set_Treat_As_Volatile (Typ); |
2fe893b9 | 11403 | end if; |
11404 | ||
99a2d5bd | 11405 | -- Inheritance for derived types only |
11406 | ||
11407 | if Is_Derived_Type (Typ) then | |
11408 | declare | |
11409 | Bas_Typ : constant Entity_Id := Base_Type (Typ); | |
11410 | Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ); | |
11411 | ||
11412 | begin | |
11413 | -- Atomic_Components | |
11414 | ||
11415 | if not Has_Rep_Item (Typ, Name_Atomic_Components, False) | |
11416 | and then Has_Rep_Item (Typ, Name_Atomic_Components) | |
11417 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11418 | (Get_Rep_Item (Typ, Name_Atomic_Components)) | |
11419 | then | |
11420 | Set_Has_Atomic_Components (Imp_Bas_Typ); | |
11421 | end if; | |
11422 | ||
11423 | -- Volatile_Components | |
11424 | ||
11425 | if not Has_Rep_Item (Typ, Name_Volatile_Components, False) | |
11426 | and then Has_Rep_Item (Typ, Name_Volatile_Components) | |
11427 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11428 | (Get_Rep_Item (Typ, Name_Volatile_Components)) | |
11429 | then | |
11430 | Set_Has_Volatile_Components (Imp_Bas_Typ); | |
11431 | end if; | |
11432 | ||
e81df51c | 11433 | -- Finalize_Storage_Only |
99a2d5bd | 11434 | |
11435 | if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False) | |
11436 | and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only) | |
11437 | then | |
11438 | Set_Finalize_Storage_Only (Bas_Typ); | |
11439 | end if; | |
11440 | ||
11441 | -- Universal_Aliasing | |
11442 | ||
11443 | if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False) | |
11444 | and then Has_Rep_Item (Typ, Name_Universal_Aliasing) | |
11445 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11446 | (Get_Rep_Item (Typ, Name_Universal_Aliasing)) | |
11447 | then | |
11448 | Set_Universal_Aliasing (Imp_Bas_Typ); | |
11449 | end if; | |
11450 | ||
e81df51c | 11451 | -- Bit_Order |
99a2d5bd | 11452 | |
11453 | if Is_Record_Type (Typ) then | |
99a2d5bd | 11454 | if not Has_Rep_Item (Typ, Name_Bit_Order, False) |
11455 | and then Has_Rep_Item (Typ, Name_Bit_Order) | |
11456 | then | |
11457 | Set_Reverse_Bit_Order (Bas_Typ, | |
11458 | Reverse_Bit_Order (Entity (Name | |
11459 | (Get_Rep_Item (Typ, Name_Bit_Order))))); | |
11460 | end if; | |
e81df51c | 11461 | end if; |
11462 | ||
e9218716 | 11463 | -- Scalar_Storage_Order |
11464 | ||
11465 | -- Note: the aspect is specified on a first subtype, but recorded | |
11466 | -- in a flag of the base type! | |
e81df51c | 11467 | |
11468 | if (Is_Record_Type (Typ) or else Is_Array_Type (Typ)) | |
29b91bc7 | 11469 | and then Typ = Bas_Typ |
e81df51c | 11470 | then |
e81df51c | 11471 | -- For a type extension, always inherit from parent; otherwise |
11472 | -- inherit if no default applies. Note: we do not check for | |
11473 | -- an explicit rep item on the parent type when inheriting, | |
11474 | -- because the parent SSO may itself have been set by default. | |
99a2d5bd | 11475 | |
e9218716 | 11476 | if not Has_Rep_Item (First_Subtype (Typ), |
11477 | Name_Scalar_Storage_Order, False) | |
e81df51c | 11478 | and then (Is_Tagged_Type (Bas_Typ) |
29b91bc7 | 11479 | or else not (SSO_Set_Low_By_Default (Bas_Typ) |
11480 | or else | |
11481 | SSO_Set_High_By_Default (Bas_Typ))) | |
99a2d5bd | 11482 | then |
11483 | Set_Reverse_Storage_Order (Bas_Typ, | |
423b89fd | 11484 | Reverse_Storage_Order |
11485 | (Implementation_Base_Type (Etype (Bas_Typ)))); | |
b64082f2 | 11486 | |
11487 | -- Clear default SSO indications, since the inherited aspect | |
11488 | -- which was set explicitly overrides the default. | |
11489 | ||
11490 | Set_SSO_Set_Low_By_Default (Bas_Typ, False); | |
11491 | Set_SSO_Set_High_By_Default (Bas_Typ, False); | |
99a2d5bd | 11492 | end if; |
11493 | end if; | |
11494 | end; | |
11495 | end if; | |
11496 | end Inherit_Aspects_At_Freeze_Point; | |
11497 | ||
d6f39728 | 11498 | ---------------- |
11499 | -- Initialize -- | |
11500 | ---------------- | |
11501 | ||
11502 | procedure Initialize is | |
11503 | begin | |
7717ea00 | 11504 | Address_Clause_Checks.Init; |
76a6b7c7 | 11505 | Compile_Time_Warnings_Errors.Init; |
d6f39728 | 11506 | Unchecked_Conversions.Init; |
dba38d2f | 11507 | |
36ac5fbb | 11508 | if AAMP_On_Target then |
dba38d2f | 11509 | Independence_Checks.Init; |
11510 | end if; | |
d6f39728 | 11511 | end Initialize; |
11512 | ||
2625eb01 | 11513 | --------------------------- |
11514 | -- Install_Discriminants -- | |
11515 | --------------------------- | |
11516 | ||
11517 | procedure Install_Discriminants (E : Entity_Id) is | |
11518 | Disc : Entity_Id; | |
11519 | Prev : Entity_Id; | |
11520 | begin | |
11521 | Disc := First_Discriminant (E); | |
11522 | while Present (Disc) loop | |
11523 | Prev := Current_Entity (Disc); | |
11524 | Set_Current_Entity (Disc); | |
11525 | Set_Is_Immediately_Visible (Disc); | |
11526 | Set_Homonym (Disc, Prev); | |
11527 | Next_Discriminant (Disc); | |
11528 | end loop; | |
11529 | end Install_Discriminants; | |
11530 | ||
d6f39728 | 11531 | ------------------------- |
11532 | -- Is_Operational_Item -- | |
11533 | ------------------------- | |
11534 | ||
11535 | function Is_Operational_Item (N : Node_Id) return Boolean is | |
11536 | begin | |
11537 | if Nkind (N) /= N_Attribute_Definition_Clause then | |
11538 | return False; | |
b9e61b2a | 11539 | |
d6f39728 | 11540 | else |
11541 | declare | |
b9e61b2a | 11542 | Id : constant Attribute_Id := Get_Attribute_Id (Chars (N)); |
d6f39728 | 11543 | begin |
078a74b8 | 11544 | |
55ab5265 | 11545 | -- List of operational items is given in AARM 13.1(8.mm/1). |
078a74b8 | 11546 | -- It is clearly incomplete, as it does not include iterator |
11547 | -- aspects, among others. | |
11548 | ||
11549 | return Id = Attribute_Constant_Indexing | |
11550 | or else Id = Attribute_Default_Iterator | |
11551 | or else Id = Attribute_Implicit_Dereference | |
11552 | or else Id = Attribute_Input | |
11553 | or else Id = Attribute_Iterator_Element | |
11554 | or else Id = Attribute_Iterable | |
d6f39728 | 11555 | or else Id = Attribute_Output |
11556 | or else Id = Attribute_Read | |
078a74b8 | 11557 | or else Id = Attribute_Variable_Indexing |
f15731c4 | 11558 | or else Id = Attribute_Write |
11559 | or else Id = Attribute_External_Tag; | |
d6f39728 | 11560 | end; |
11561 | end if; | |
11562 | end Is_Operational_Item; | |
11563 | ||
3b23aaa0 | 11564 | ------------------------- |
11565 | -- Is_Predicate_Static -- | |
11566 | ------------------------- | |
11567 | ||
94d896aa | 11568 | -- Note: the basic legality of the expression has already been checked, so |
11569 | -- we don't need to worry about cases or ranges on strings for example. | |
11570 | ||
3b23aaa0 | 11571 | function Is_Predicate_Static |
11572 | (Expr : Node_Id; | |
11573 | Nam : Name_Id) return Boolean | |
11574 | is | |
11575 | function All_Static_Case_Alternatives (L : List_Id) return Boolean; | |
973c2fba | 11576 | -- Given a list of case expression alternatives, returns True if all |
11577 | -- the alternatives are static (have all static choices, and a static | |
11578 | -- expression). | |
3b23aaa0 | 11579 | |
11580 | function All_Static_Choices (L : List_Id) return Boolean; | |
a360a0f7 | 11581 | -- Returns true if all elements of the list are OK static choices |
3b23aaa0 | 11582 | -- as defined below for Is_Static_Choice. Used for case expression |
973c2fba | 11583 | -- alternatives and for the right operand of a membership test. An |
11584 | -- others_choice is static if the corresponding expression is static. | |
7c0c95b8 | 11585 | -- The staticness of the bounds is checked separately. |
3b23aaa0 | 11586 | |
11587 | function Is_Static_Choice (N : Node_Id) return Boolean; | |
11588 | -- Returns True if N represents a static choice (static subtype, or | |
a360a0f7 | 11589 | -- static subtype indication, or static expression, or static range). |
3b23aaa0 | 11590 | -- |
11591 | -- Note that this is a bit more inclusive than we actually need | |
11592 | -- (in particular membership tests do not allow the use of subtype | |
a360a0f7 | 11593 | -- indications). But that doesn't matter, we have already checked |
3b23aaa0 | 11594 | -- that the construct is legal to get this far. |
11595 | ||
11596 | function Is_Type_Ref (N : Node_Id) return Boolean; | |
11597 | pragma Inline (Is_Type_Ref); | |
973c2fba | 11598 | -- Returns True if N is a reference to the type for the predicate in the |
11599 | -- expression (i.e. if it is an identifier whose Chars field matches the | |
11600 | -- Nam given in the call). N must not be parenthesized, if the type name | |
11601 | -- appears in parens, this routine will return False. | |
3b23aaa0 | 11602 | |
11603 | ---------------------------------- | |
11604 | -- All_Static_Case_Alternatives -- | |
11605 | ---------------------------------- | |
11606 | ||
11607 | function All_Static_Case_Alternatives (L : List_Id) return Boolean is | |
11608 | N : Node_Id; | |
11609 | ||
11610 | begin | |
11611 | N := First (L); | |
11612 | while Present (N) loop | |
11613 | if not (All_Static_Choices (Discrete_Choices (N)) | |
11614 | and then Is_OK_Static_Expression (Expression (N))) | |
11615 | then | |
11616 | return False; | |
11617 | end if; | |
11618 | ||
11619 | Next (N); | |
11620 | end loop; | |
11621 | ||
11622 | return True; | |
11623 | end All_Static_Case_Alternatives; | |
11624 | ||
11625 | ------------------------ | |
11626 | -- All_Static_Choices -- | |
11627 | ------------------------ | |
11628 | ||
11629 | function All_Static_Choices (L : List_Id) return Boolean is | |
11630 | N : Node_Id; | |
11631 | ||
11632 | begin | |
11633 | N := First (L); | |
11634 | while Present (N) loop | |
11635 | if not Is_Static_Choice (N) then | |
11636 | return False; | |
11637 | end if; | |
11638 | ||
11639 | Next (N); | |
11640 | end loop; | |
11641 | ||
11642 | return True; | |
11643 | end All_Static_Choices; | |
11644 | ||
11645 | ---------------------- | |
11646 | -- Is_Static_Choice -- | |
11647 | ---------------------- | |
11648 | ||
11649 | function Is_Static_Choice (N : Node_Id) return Boolean is | |
11650 | begin | |
7c0c95b8 | 11651 | return Nkind (N) = N_Others_Choice |
11652 | or else Is_OK_Static_Expression (N) | |
3b23aaa0 | 11653 | or else (Is_Entity_Name (N) and then Is_Type (Entity (N)) |
11654 | and then Is_OK_Static_Subtype (Entity (N))) | |
11655 | or else (Nkind (N) = N_Subtype_Indication | |
11656 | and then Is_OK_Static_Subtype (Entity (N))) | |
11657 | or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N)); | |
11658 | end Is_Static_Choice; | |
11659 | ||
11660 | ----------------- | |
11661 | -- Is_Type_Ref -- | |
11662 | ----------------- | |
11663 | ||
11664 | function Is_Type_Ref (N : Node_Id) return Boolean is | |
11665 | begin | |
11666 | return Nkind (N) = N_Identifier | |
11667 | and then Chars (N) = Nam | |
11668 | and then Paren_Count (N) = 0; | |
11669 | end Is_Type_Ref; | |
11670 | ||
11671 | -- Start of processing for Is_Predicate_Static | |
11672 | ||
11673 | begin | |
3b23aaa0 | 11674 | -- Predicate_Static means one of the following holds. Numbers are the |
11675 | -- corresponding paragraph numbers in (RM 3.2.4(16-22)). | |
11676 | ||
11677 | -- 16: A static expression | |
11678 | ||
11679 | if Is_OK_Static_Expression (Expr) then | |
11680 | return True; | |
11681 | ||
11682 | -- 17: A membership test whose simple_expression is the current | |
11683 | -- instance, and whose membership_choice_list meets the requirements | |
11684 | -- for a static membership test. | |
11685 | ||
11686 | elsif Nkind (Expr) in N_Membership_Test | |
11687 | and then ((Present (Right_Opnd (Expr)) | |
11688 | and then Is_Static_Choice (Right_Opnd (Expr))) | |
11689 | or else | |
11690 | (Present (Alternatives (Expr)) | |
11691 | and then All_Static_Choices (Alternatives (Expr)))) | |
11692 | then | |
11693 | return True; | |
11694 | ||
11695 | -- 18. A case_expression whose selecting_expression is the current | |
11696 | -- instance, and whose dependent expressions are static expressions. | |
11697 | ||
11698 | elsif Nkind (Expr) = N_Case_Expression | |
11699 | and then Is_Type_Ref (Expression (Expr)) | |
11700 | and then All_Static_Case_Alternatives (Alternatives (Expr)) | |
11701 | then | |
11702 | return True; | |
11703 | ||
11704 | -- 19. A call to a predefined equality or ordering operator, where one | |
11705 | -- operand is the current instance, and the other is a static | |
11706 | -- expression. | |
11707 | ||
94d896aa | 11708 | -- Note: the RM is clearly wrong here in not excluding string types. |
11709 | -- Without this exclusion, we would allow expressions like X > "ABC" | |
11710 | -- to be considered as predicate-static, which is clearly not intended, | |
11711 | -- since the idea is for predicate-static to be a subset of normal | |
11712 | -- static expressions (and "DEF" > "ABC" is not a static expression). | |
11713 | ||
11714 | -- However, we do allow internally generated (not from source) equality | |
11715 | -- and inequality operations to be valid on strings (this helps deal | |
11716 | -- with cases where we transform A in "ABC" to A = "ABC). | |
11717 | ||
3b23aaa0 | 11718 | elsif Nkind (Expr) in N_Op_Compare |
94d896aa | 11719 | and then ((not Is_String_Type (Etype (Left_Opnd (Expr)))) |
11720 | or else (Nkind_In (Expr, N_Op_Eq, N_Op_Ne) | |
11721 | and then not Comes_From_Source (Expr))) | |
3b23aaa0 | 11722 | and then ((Is_Type_Ref (Left_Opnd (Expr)) |
11723 | and then Is_OK_Static_Expression (Right_Opnd (Expr))) | |
11724 | or else | |
11725 | (Is_Type_Ref (Right_Opnd (Expr)) | |
11726 | and then Is_OK_Static_Expression (Left_Opnd (Expr)))) | |
11727 | then | |
11728 | return True; | |
11729 | ||
11730 | -- 20. A call to a predefined boolean logical operator, where each | |
11731 | -- operand is predicate-static. | |
11732 | ||
11733 | elsif (Nkind_In (Expr, N_Op_And, N_Op_Or, N_Op_Xor) | |
11734 | and then Is_Predicate_Static (Left_Opnd (Expr), Nam) | |
11735 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam)) | |
11736 | or else | |
11737 | (Nkind (Expr) = N_Op_Not | |
11738 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam)) | |
11739 | then | |
11740 | return True; | |
11741 | ||
11742 | -- 21. A short-circuit control form where both operands are | |
11743 | -- predicate-static. | |
11744 | ||
11745 | elsif Nkind (Expr) in N_Short_Circuit | |
11746 | and then Is_Predicate_Static (Left_Opnd (Expr), Nam) | |
11747 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam) | |
11748 | then | |
11749 | return True; | |
11750 | ||
11751 | -- 22. A parenthesized predicate-static expression. This does not | |
11752 | -- require any special test, since we just ignore paren levels in | |
11753 | -- all the cases above. | |
11754 | ||
11755 | -- One more test that is an implementation artifact caused by the fact | |
499918a7 | 11756 | -- that we are analyzing not the original expression, but the generated |
3b23aaa0 | 11757 | -- expression in the body of the predicate function. This can include |
a360a0f7 | 11758 | -- references to inherited predicates, so that the expression we are |
3b23aaa0 | 11759 | -- processing looks like: |
11760 | ||
75491446 | 11761 | -- xxPredicate (typ (Inns)) and then expression |
3b23aaa0 | 11762 | |
11763 | -- Where the call is to a Predicate function for an inherited predicate. | |
60a4a5af | 11764 | -- We simply ignore such a call, which could be to either a dynamic or |
11765 | -- a static predicate. Note that if the parent predicate is dynamic then | |
11766 | -- eventually this type will be marked as dynamic, but you are allowed | |
11767 | -- to specify a static predicate for a subtype which is inheriting a | |
11768 | -- dynamic predicate, so the static predicate validation here ignores | |
11769 | -- the inherited predicate even if it is dynamic. | |
7db33803 | 11770 | -- In all cases, a static predicate can only apply to a scalar type. |
3b23aaa0 | 11771 | |
11772 | elsif Nkind (Expr) = N_Function_Call | |
11773 | and then Is_Predicate_Function (Entity (Name (Expr))) | |
7db33803 | 11774 | and then Is_Scalar_Type (Etype (First_Entity (Entity (Name (Expr))))) |
3b23aaa0 | 11775 | then |
11776 | return True; | |
11777 | ||
11778 | -- That's an exhaustive list of tests, all other cases are not | |
a360a0f7 | 11779 | -- predicate-static, so we return False. |
3b23aaa0 | 11780 | |
11781 | else | |
11782 | return False; | |
11783 | end if; | |
11784 | end Is_Predicate_Static; | |
11785 | ||
2ff55065 | 11786 | --------------------- |
11787 | -- Kill_Rep_Clause -- | |
11788 | --------------------- | |
11789 | ||
11790 | procedure Kill_Rep_Clause (N : Node_Id) is | |
11791 | begin | |
11792 | pragma Assert (Ignore_Rep_Clauses); | |
360f426f | 11793 | |
11794 | -- Note: we use Replace rather than Rewrite, because we don't want | |
11795 | -- ASIS to be able to use Original_Node to dig out the (undecorated) | |
11796 | -- rep clause that is being replaced. | |
11797 | ||
4949ddd5 | 11798 | Replace (N, Make_Null_Statement (Sloc (N))); |
360f426f | 11799 | |
11800 | -- The null statement must be marked as not coming from source. This is | |
37c6552c | 11801 | -- so that ASIS ignores it, and also the back end does not expect bogus |
360f426f | 11802 | -- "from source" null statements in weird places (e.g. in declarative |
11803 | -- regions where such null statements are not allowed). | |
11804 | ||
11805 | Set_Comes_From_Source (N, False); | |
2ff55065 | 11806 | end Kill_Rep_Clause; |
11807 | ||
d6f39728 | 11808 | ------------------ |
11809 | -- Minimum_Size -- | |
11810 | ------------------ | |
11811 | ||
11812 | function Minimum_Size | |
11813 | (T : Entity_Id; | |
d5b349fa | 11814 | Biased : Boolean := False) return Nat |
d6f39728 | 11815 | is |
11816 | Lo : Uint := No_Uint; | |
11817 | Hi : Uint := No_Uint; | |
11818 | LoR : Ureal := No_Ureal; | |
11819 | HiR : Ureal := No_Ureal; | |
11820 | LoSet : Boolean := False; | |
11821 | HiSet : Boolean := False; | |
11822 | B : Uint; | |
11823 | S : Nat; | |
11824 | Ancest : Entity_Id; | |
f15731c4 | 11825 | R_Typ : constant Entity_Id := Root_Type (T); |
d6f39728 | 11826 | |
11827 | begin | |
11828 | -- If bad type, return 0 | |
11829 | ||
11830 | if T = Any_Type then | |
11831 | return 0; | |
11832 | ||
11833 | -- For generic types, just return zero. There cannot be any legitimate | |
11834 | -- need to know such a size, but this routine may be called with a | |
11835 | -- generic type as part of normal processing. | |
11836 | ||
f02a9a9a | 11837 | elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then |
d6f39728 | 11838 | return 0; |
11839 | ||
74c7ae52 | 11840 | -- Access types (cannot have size smaller than System.Address) |
d6f39728 | 11841 | |
11842 | elsif Is_Access_Type (T) then | |
74c7ae52 | 11843 | return System_Address_Size; |
d6f39728 | 11844 | |
11845 | -- Floating-point types | |
11846 | ||
11847 | elsif Is_Floating_Point_Type (T) then | |
f15731c4 | 11848 | return UI_To_Int (Esize (R_Typ)); |
d6f39728 | 11849 | |
11850 | -- Discrete types | |
11851 | ||
11852 | elsif Is_Discrete_Type (T) then | |
11853 | ||
fdd294d1 | 11854 | -- The following loop is looking for the nearest compile time known |
11855 | -- bounds following the ancestor subtype chain. The idea is to find | |
11856 | -- the most restrictive known bounds information. | |
d6f39728 | 11857 | |
11858 | Ancest := T; | |
11859 | loop | |
11860 | if Ancest = Any_Type or else Etype (Ancest) = Any_Type then | |
11861 | return 0; | |
11862 | end if; | |
11863 | ||
11864 | if not LoSet then | |
11865 | if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then | |
11866 | Lo := Expr_Rep_Value (Type_Low_Bound (Ancest)); | |
11867 | LoSet := True; | |
11868 | exit when HiSet; | |
11869 | end if; | |
11870 | end if; | |
11871 | ||
11872 | if not HiSet then | |
11873 | if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then | |
11874 | Hi := Expr_Rep_Value (Type_High_Bound (Ancest)); | |
11875 | HiSet := True; | |
11876 | exit when LoSet; | |
11877 | end if; | |
11878 | end if; | |
11879 | ||
11880 | Ancest := Ancestor_Subtype (Ancest); | |
11881 | ||
11882 | if No (Ancest) then | |
11883 | Ancest := Base_Type (T); | |
11884 | ||
11885 | if Is_Generic_Type (Ancest) then | |
11886 | return 0; | |
11887 | end if; | |
11888 | end if; | |
11889 | end loop; | |
11890 | ||
11891 | -- Fixed-point types. We can't simply use Expr_Value to get the | |
fdd294d1 | 11892 | -- Corresponding_Integer_Value values of the bounds, since these do not |
11893 | -- get set till the type is frozen, and this routine can be called | |
11894 | -- before the type is frozen. Similarly the test for bounds being static | |
11895 | -- needs to include the case where we have unanalyzed real literals for | |
11896 | -- the same reason. | |
d6f39728 | 11897 | |
11898 | elsif Is_Fixed_Point_Type (T) then | |
11899 | ||
fdd294d1 | 11900 | -- The following loop is looking for the nearest compile time known |
11901 | -- bounds following the ancestor subtype chain. The idea is to find | |
11902 | -- the most restrictive known bounds information. | |
d6f39728 | 11903 | |
11904 | Ancest := T; | |
11905 | loop | |
11906 | if Ancest = Any_Type or else Etype (Ancest) = Any_Type then | |
11907 | return 0; | |
11908 | end if; | |
11909 | ||
3062c401 | 11910 | -- Note: In the following two tests for LoSet and HiSet, it may |
11911 | -- seem redundant to test for N_Real_Literal here since normally | |
11912 | -- one would assume that the test for the value being known at | |
11913 | -- compile time includes this case. However, there is a glitch. | |
11914 | -- If the real literal comes from folding a non-static expression, | |
11915 | -- then we don't consider any non- static expression to be known | |
11916 | -- at compile time if we are in configurable run time mode (needed | |
11917 | -- in some cases to give a clearer definition of what is and what | |
11918 | -- is not accepted). So the test is indeed needed. Without it, we | |
11919 | -- would set neither Lo_Set nor Hi_Set and get an infinite loop. | |
11920 | ||
d6f39728 | 11921 | if not LoSet then |
11922 | if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal | |
11923 | or else Compile_Time_Known_Value (Type_Low_Bound (Ancest)) | |
11924 | then | |
11925 | LoR := Expr_Value_R (Type_Low_Bound (Ancest)); | |
11926 | LoSet := True; | |
11927 | exit when HiSet; | |
11928 | end if; | |
11929 | end if; | |
11930 | ||
11931 | if not HiSet then | |
11932 | if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal | |
11933 | or else Compile_Time_Known_Value (Type_High_Bound (Ancest)) | |
11934 | then | |
11935 | HiR := Expr_Value_R (Type_High_Bound (Ancest)); | |
11936 | HiSet := True; | |
11937 | exit when LoSet; | |
11938 | end if; | |
11939 | end if; | |
11940 | ||
11941 | Ancest := Ancestor_Subtype (Ancest); | |
11942 | ||
11943 | if No (Ancest) then | |
11944 | Ancest := Base_Type (T); | |
11945 | ||
11946 | if Is_Generic_Type (Ancest) then | |
11947 | return 0; | |
11948 | end if; | |
11949 | end if; | |
11950 | end loop; | |
11951 | ||
11952 | Lo := UR_To_Uint (LoR / Small_Value (T)); | |
11953 | Hi := UR_To_Uint (HiR / Small_Value (T)); | |
11954 | ||
11955 | -- No other types allowed | |
11956 | ||
11957 | else | |
11958 | raise Program_Error; | |
11959 | end if; | |
11960 | ||
2866d595 | 11961 | -- Fall through with Hi and Lo set. Deal with biased case |
d6f39728 | 11962 | |
cc46ff4b | 11963 | if (Biased |
11964 | and then not Is_Fixed_Point_Type (T) | |
11965 | and then not (Is_Enumeration_Type (T) | |
11966 | and then Has_Non_Standard_Rep (T))) | |
d6f39728 | 11967 | or else Has_Biased_Representation (T) |
11968 | then | |
11969 | Hi := Hi - Lo; | |
11970 | Lo := Uint_0; | |
11971 | end if; | |
11972 | ||
005366f7 | 11973 | -- Null range case, size is always zero. We only do this in the discrete |
11974 | -- type case, since that's the odd case that came up. Probably we should | |
11975 | -- also do this in the fixed-point case, but doing so causes peculiar | |
11976 | -- gigi failures, and it is not worth worrying about this incredibly | |
11977 | -- marginal case (explicit null-range fixed-point type declarations)??? | |
11978 | ||
11979 | if Lo > Hi and then Is_Discrete_Type (T) then | |
11980 | S := 0; | |
11981 | ||
d6f39728 | 11982 | -- Signed case. Note that we consider types like range 1 .. -1 to be |
fdd294d1 | 11983 | -- signed for the purpose of computing the size, since the bounds have |
1a34e48c | 11984 | -- to be accommodated in the base type. |
d6f39728 | 11985 | |
005366f7 | 11986 | elsif Lo < 0 or else Hi < 0 then |
d6f39728 | 11987 | S := 1; |
11988 | B := Uint_1; | |
11989 | ||
da253936 | 11990 | -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1)) |
11991 | -- Note that we accommodate the case where the bounds cross. This | |
d6f39728 | 11992 | -- can happen either because of the way the bounds are declared |
11993 | -- or because of the algorithm in Freeze_Fixed_Point_Type. | |
11994 | ||
11995 | while Lo < -B | |
11996 | or else Hi < -B | |
11997 | or else Lo >= B | |
11998 | or else Hi >= B | |
11999 | loop | |
12000 | B := Uint_2 ** S; | |
12001 | S := S + 1; | |
12002 | end loop; | |
12003 | ||
12004 | -- Unsigned case | |
12005 | ||
12006 | else | |
12007 | -- If both bounds are positive, make sure that both are represen- | |
12008 | -- table in the case where the bounds are crossed. This can happen | |
12009 | -- either because of the way the bounds are declared, or because of | |
12010 | -- the algorithm in Freeze_Fixed_Point_Type. | |
12011 | ||
12012 | if Lo > Hi then | |
12013 | Hi := Lo; | |
12014 | end if; | |
12015 | ||
da253936 | 12016 | -- S = size, (can accommodate 0 .. (2**size - 1)) |
d6f39728 | 12017 | |
12018 | S := 0; | |
12019 | while Hi >= Uint_2 ** S loop | |
12020 | S := S + 1; | |
12021 | end loop; | |
12022 | end if; | |
12023 | ||
12024 | return S; | |
12025 | end Minimum_Size; | |
12026 | ||
44e4341e | 12027 | --------------------------- |
12028 | -- New_Stream_Subprogram -- | |
12029 | --------------------------- | |
d6f39728 | 12030 | |
44e4341e | 12031 | procedure New_Stream_Subprogram |
12032 | (N : Node_Id; | |
12033 | Ent : Entity_Id; | |
12034 | Subp : Entity_Id; | |
12035 | Nam : TSS_Name_Type) | |
d6f39728 | 12036 | is |
12037 | Loc : constant Source_Ptr := Sloc (N); | |
9dfe12ae | 12038 | Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam); |
f15731c4 | 12039 | Subp_Id : Entity_Id; |
d6f39728 | 12040 | Subp_Decl : Node_Id; |
12041 | F : Entity_Id; | |
12042 | Etyp : Entity_Id; | |
12043 | ||
44e4341e | 12044 | Defer_Declaration : constant Boolean := |
12045 | Is_Tagged_Type (Ent) or else Is_Private_Type (Ent); | |
12046 | -- For a tagged type, there is a declaration for each stream attribute | |
12047 | -- at the freeze point, and we must generate only a completion of this | |
12048 | -- declaration. We do the same for private types, because the full view | |
12049 | -- might be tagged. Otherwise we generate a declaration at the point of | |
449c4f58 | 12050 | -- the attribute definition clause. If the attribute definition comes |
12051 | -- from an aspect specification the declaration is part of the freeze | |
12052 | -- actions of the type. | |
44e4341e | 12053 | |
f15731c4 | 12054 | function Build_Spec return Node_Id; |
12055 | -- Used for declaration and renaming declaration, so that this is | |
12056 | -- treated as a renaming_as_body. | |
12057 | ||
12058 | ---------------- | |
12059 | -- Build_Spec -- | |
12060 | ---------------- | |
12061 | ||
d5b349fa | 12062 | function Build_Spec return Node_Id is |
44e4341e | 12063 | Out_P : constant Boolean := (Nam = TSS_Stream_Read); |
12064 | Formals : List_Id; | |
12065 | Spec : Node_Id; | |
83c6c069 | 12066 | T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc); |
44e4341e | 12067 | |
f15731c4 | 12068 | begin |
9dfe12ae | 12069 | Subp_Id := Make_Defining_Identifier (Loc, Sname); |
f15731c4 | 12070 | |
44e4341e | 12071 | -- S : access Root_Stream_Type'Class |
12072 | ||
12073 | Formals := New_List ( | |
12074 | Make_Parameter_Specification (Loc, | |
12075 | Defining_Identifier => | |
12076 | Make_Defining_Identifier (Loc, Name_S), | |
12077 | Parameter_Type => | |
12078 | Make_Access_Definition (Loc, | |
12079 | Subtype_Mark => | |
83c6c069 | 12080 | New_Occurrence_Of ( |
44e4341e | 12081 | Designated_Type (Etype (F)), Loc)))); |
12082 | ||
12083 | if Nam = TSS_Stream_Input then | |
4bba0a8d | 12084 | Spec := |
12085 | Make_Function_Specification (Loc, | |
12086 | Defining_Unit_Name => Subp_Id, | |
12087 | Parameter_Specifications => Formals, | |
12088 | Result_Definition => T_Ref); | |
44e4341e | 12089 | else |
12090 | -- V : [out] T | |
f15731c4 | 12091 | |
44e4341e | 12092 | Append_To (Formals, |
12093 | Make_Parameter_Specification (Loc, | |
12094 | Defining_Identifier => Make_Defining_Identifier (Loc, Name_V), | |
12095 | Out_Present => Out_P, | |
12096 | Parameter_Type => T_Ref)); | |
f15731c4 | 12097 | |
d3ef794c | 12098 | Spec := |
12099 | Make_Procedure_Specification (Loc, | |
12100 | Defining_Unit_Name => Subp_Id, | |
12101 | Parameter_Specifications => Formals); | |
44e4341e | 12102 | end if; |
f15731c4 | 12103 | |
44e4341e | 12104 | return Spec; |
12105 | end Build_Spec; | |
d6f39728 | 12106 | |
44e4341e | 12107 | -- Start of processing for New_Stream_Subprogram |
d6f39728 | 12108 | |
44e4341e | 12109 | begin |
12110 | F := First_Formal (Subp); | |
12111 | ||
12112 | if Ekind (Subp) = E_Procedure then | |
12113 | Etyp := Etype (Next_Formal (F)); | |
d6f39728 | 12114 | else |
44e4341e | 12115 | Etyp := Etype (Subp); |
d6f39728 | 12116 | end if; |
f15731c4 | 12117 | |
44e4341e | 12118 | -- Prepare subprogram declaration and insert it as an action on the |
12119 | -- clause node. The visibility for this entity is used to test for | |
12120 | -- visibility of the attribute definition clause (in the sense of | |
12121 | -- 8.3(23) as amended by AI-195). | |
9dfe12ae | 12122 | |
44e4341e | 12123 | if not Defer_Declaration then |
f15731c4 | 12124 | Subp_Decl := |
12125 | Make_Subprogram_Declaration (Loc, | |
12126 | Specification => Build_Spec); | |
44e4341e | 12127 | |
12128 | -- For a tagged type, there is always a visible declaration for each | |
15ebb600 | 12129 | -- stream TSS (it is a predefined primitive operation), and the |
44e4341e | 12130 | -- completion of this declaration occurs at the freeze point, which is |
12131 | -- not always visible at places where the attribute definition clause is | |
12132 | -- visible. So, we create a dummy entity here for the purpose of | |
12133 | -- tracking the visibility of the attribute definition clause itself. | |
12134 | ||
12135 | else | |
12136 | Subp_Id := | |
55868293 | 12137 | Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V')); |
44e4341e | 12138 | Subp_Decl := |
12139 | Make_Object_Declaration (Loc, | |
12140 | Defining_Identifier => Subp_Id, | |
12141 | Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc)); | |
f15731c4 | 12142 | end if; |
12143 | ||
449c4f58 | 12144 | if not Defer_Declaration |
12145 | and then From_Aspect_Specification (N) | |
12146 | and then Has_Delayed_Freeze (Ent) | |
12147 | then | |
12148 | Append_Freeze_Action (Ent, Subp_Decl); | |
12149 | ||
12150 | else | |
12151 | Insert_Action (N, Subp_Decl); | |
12152 | Set_Entity (N, Subp_Id); | |
12153 | end if; | |
44e4341e | 12154 | |
d6f39728 | 12155 | Subp_Decl := |
12156 | Make_Subprogram_Renaming_Declaration (Loc, | |
f15731c4 | 12157 | Specification => Build_Spec, |
8acb75b4 | 12158 | Name => New_Occurrence_Of (Subp, Loc)); |
d6f39728 | 12159 | |
44e4341e | 12160 | if Defer_Declaration then |
d6f39728 | 12161 | Set_TSS (Base_Type (Ent), Subp_Id); |
449c4f58 | 12162 | |
d6f39728 | 12163 | else |
449c4f58 | 12164 | if From_Aspect_Specification (N) then |
12165 | Append_Freeze_Action (Ent, Subp_Decl); | |
449c4f58 | 12166 | else |
12167 | Insert_Action (N, Subp_Decl); | |
12168 | end if; | |
12169 | ||
d6f39728 | 12170 | Copy_TSS (Subp_Id, Base_Type (Ent)); |
12171 | end if; | |
44e4341e | 12172 | end New_Stream_Subprogram; |
d6f39728 | 12173 | |
2625eb01 | 12174 | ------------------------------------------ |
12175 | -- Push_Scope_And_Install_Discriminants -- | |
12176 | ------------------------------------------ | |
12177 | ||
12178 | procedure Push_Scope_And_Install_Discriminants (E : Entity_Id) is | |
12179 | begin | |
12180 | if Has_Discriminants (E) then | |
12181 | Push_Scope (E); | |
12182 | ||
97c23bbe | 12183 | -- Make the discriminants visible for type declarations and protected |
2625eb01 | 12184 | -- type declarations, not for subtype declarations (RM 13.1.1 (12/3)) |
12185 | ||
12186 | if Nkind (Parent (E)) /= N_Subtype_Declaration then | |
12187 | Install_Discriminants (E); | |
12188 | end if; | |
12189 | end if; | |
12190 | end Push_Scope_And_Install_Discriminants; | |
12191 | ||
d6f39728 | 12192 | ------------------------ |
12193 | -- Rep_Item_Too_Early -- | |
12194 | ------------------------ | |
12195 | ||
80d4fec4 | 12196 | function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is |
d6f39728 | 12197 | begin |
44e4341e | 12198 | -- Cannot apply non-operational rep items to generic types |
d6f39728 | 12199 | |
f15731c4 | 12200 | if Is_Operational_Item (N) then |
12201 | return False; | |
12202 | ||
12203 | elsif Is_Type (T) | |
d6f39728 | 12204 | and then Is_Generic_Type (Root_Type (T)) |
e17c5076 | 12205 | and then (Nkind (N) /= N_Pragma |
12206 | or else Get_Pragma_Id (N) /= Pragma_Convention) | |
d6f39728 | 12207 | then |
503f7fd3 | 12208 | Error_Msg_N ("representation item not allowed for generic type", N); |
d6f39728 | 12209 | return True; |
12210 | end if; | |
12211 | ||
fdd294d1 | 12212 | -- Otherwise check for incomplete type |
d6f39728 | 12213 | |
12214 | if Is_Incomplete_Or_Private_Type (T) | |
12215 | and then No (Underlying_Type (T)) | |
d64221a7 | 12216 | and then |
12217 | (Nkind (N) /= N_Pragma | |
60014bc9 | 12218 | or else Get_Pragma_Id (N) /= Pragma_Import) |
d6f39728 | 12219 | then |
12220 | Error_Msg_N | |
12221 | ("representation item must be after full type declaration", N); | |
12222 | return True; | |
12223 | ||
1a34e48c | 12224 | -- If the type has incomplete components, a representation clause is |
d6f39728 | 12225 | -- illegal but stream attributes and Convention pragmas are correct. |
12226 | ||
12227 | elsif Has_Private_Component (T) then | |
f15731c4 | 12228 | if Nkind (N) = N_Pragma then |
d6f39728 | 12229 | return False; |
b9e61b2a | 12230 | |
d6f39728 | 12231 | else |
12232 | Error_Msg_N | |
12233 | ("representation item must appear after type is fully defined", | |
12234 | N); | |
12235 | return True; | |
12236 | end if; | |
12237 | else | |
12238 | return False; | |
12239 | end if; | |
12240 | end Rep_Item_Too_Early; | |
12241 | ||
12242 | ----------------------- | |
12243 | -- Rep_Item_Too_Late -- | |
12244 | ----------------------- | |
12245 | ||
12246 | function Rep_Item_Too_Late | |
12247 | (T : Entity_Id; | |
12248 | N : Node_Id; | |
d5b349fa | 12249 | FOnly : Boolean := False) return Boolean |
d6f39728 | 12250 | is |
12251 | S : Entity_Id; | |
12252 | Parent_Type : Entity_Id; | |
12253 | ||
4d0944e9 | 12254 | procedure No_Type_Rep_Item; |
12255 | -- Output message indicating that no type-related aspects can be | |
12256 | -- specified due to some property of the parent type. | |
12257 | ||
d6f39728 | 12258 | procedure Too_Late; |
4d0944e9 | 12259 | -- Output message for an aspect being specified too late |
12260 | ||
12261 | -- Note that neither of the above errors is considered a serious one, | |
12262 | -- since the effect is simply that we ignore the representation clause | |
12263 | -- in these cases. | |
04d38ee4 | 12264 | -- Is this really true? In any case if we make this change we must |
12265 | -- document the requirement in the spec of Rep_Item_Too_Late that | |
12266 | -- if True is returned, then the rep item must be completely ignored??? | |
4d0944e9 | 12267 | |
12268 | ---------------------- | |
12269 | -- No_Type_Rep_Item -- | |
12270 | ---------------------- | |
12271 | ||
12272 | procedure No_Type_Rep_Item is | |
12273 | begin | |
12274 | Error_Msg_N ("|type-related representation item not permitted!", N); | |
12275 | end No_Type_Rep_Item; | |
d53a018a | 12276 | |
12277 | -------------- | |
12278 | -- Too_Late -- | |
12279 | -------------- | |
d6f39728 | 12280 | |
12281 | procedure Too_Late is | |
12282 | begin | |
ce4da1ed | 12283 | -- Other compilers seem more relaxed about rep items appearing too |
12284 | -- late. Since analysis tools typically don't care about rep items | |
12285 | -- anyway, no reason to be too strict about this. | |
12286 | ||
a9cd517c | 12287 | if not Relaxed_RM_Semantics then |
12288 | Error_Msg_N ("|representation item appears too late!", N); | |
12289 | end if; | |
d6f39728 | 12290 | end Too_Late; |
12291 | ||
12292 | -- Start of processing for Rep_Item_Too_Late | |
12293 | ||
12294 | begin | |
a3248fc4 | 12295 | -- First make sure entity is not frozen (RM 13.1(9)) |
d6f39728 | 12296 | |
12297 | if Is_Frozen (T) | |
a3248fc4 | 12298 | |
12299 | -- Exclude imported types, which may be frozen if they appear in a | |
12300 | -- representation clause for a local type. | |
12301 | ||
4aa270d8 | 12302 | and then not From_Limited_With (T) |
a3248fc4 | 12303 | |
a9cd517c | 12304 | -- Exclude generated entities (not coming from source). The common |
a3248fc4 | 12305 | -- case is when we generate a renaming which prematurely freezes the |
12306 | -- renamed internal entity, but we still want to be able to set copies | |
12307 | -- of attribute values such as Size/Alignment. | |
12308 | ||
12309 | and then Comes_From_Source (T) | |
d6f39728 | 12310 | then |
58e133a6 | 12311 | -- A self-referential aspect is illegal if it forces freezing the |
12312 | -- entity before the corresponding pragma has been analyzed. | |
12313 | ||
12314 | if Nkind_In (N, N_Attribute_Definition_Clause, N_Pragma) | |
12315 | and then From_Aspect_Specification (N) | |
12316 | then | |
12317 | Error_Msg_NE | |
12318 | ("aspect specification causes premature freezing of&", T, N); | |
12319 | Set_Has_Delayed_Freeze (T, False); | |
12320 | return True; | |
12321 | end if; | |
12322 | ||
d6f39728 | 12323 | Too_Late; |
12324 | S := First_Subtype (T); | |
12325 | ||
12326 | if Present (Freeze_Node (S)) then | |
04d38ee4 | 12327 | if not Relaxed_RM_Semantics then |
12328 | Error_Msg_NE | |
12329 | ("??no more representation items for }", Freeze_Node (S), S); | |
12330 | end if; | |
d6f39728 | 12331 | end if; |
12332 | ||
12333 | return True; | |
12334 | ||
d1a2e31b | 12335 | -- Check for case of untagged derived type whose parent either has |
4d0944e9 | 12336 | -- primitive operations, or is a by reference type (RM 13.1(10)). In |
12337 | -- this case we do not output a Too_Late message, since there is no | |
12338 | -- earlier point where the rep item could be placed to make it legal. | |
d6f39728 | 12339 | |
12340 | elsif Is_Type (T) | |
12341 | and then not FOnly | |
12342 | and then Is_Derived_Type (T) | |
12343 | and then not Is_Tagged_Type (T) | |
12344 | then | |
12345 | Parent_Type := Etype (Base_Type (T)); | |
12346 | ||
12347 | if Has_Primitive_Operations (Parent_Type) then | |
4d0944e9 | 12348 | No_Type_Rep_Item; |
04d38ee4 | 12349 | |
12350 | if not Relaxed_RM_Semantics then | |
12351 | Error_Msg_NE | |
12352 | ("\parent type & has primitive operations!", N, Parent_Type); | |
12353 | end if; | |
12354 | ||
d6f39728 | 12355 | return True; |
12356 | ||
12357 | elsif Is_By_Reference_Type (Parent_Type) then | |
4d0944e9 | 12358 | No_Type_Rep_Item; |
04d38ee4 | 12359 | |
12360 | if not Relaxed_RM_Semantics then | |
12361 | Error_Msg_NE | |
12362 | ("\parent type & is a by reference type!", N, Parent_Type); | |
12363 | end if; | |
12364 | ||
d6f39728 | 12365 | return True; |
12366 | end if; | |
12367 | end if; | |
12368 | ||
04d38ee4 | 12369 | -- No error, but one more warning to consider. The RM (surprisingly) |
12370 | -- allows this pattern: | |
12371 | ||
12372 | -- type S is ... | |
12373 | -- primitive operations for S | |
12374 | -- type R is new S; | |
12375 | -- rep clause for S | |
12376 | ||
12377 | -- Meaning that calls on the primitive operations of S for values of | |
12378 | -- type R may require possibly expensive implicit conversion operations. | |
12379 | -- This is not an error, but is worth a warning. | |
12380 | ||
12381 | if not Relaxed_RM_Semantics and then Is_Type (T) then | |
12382 | declare | |
12383 | DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T)); | |
12384 | ||
12385 | begin | |
12386 | if Present (DTL) | |
12387 | and then Has_Primitive_Operations (Base_Type (T)) | |
12388 | ||
12389 | -- For now, do not generate this warning for the case of aspect | |
12390 | -- specification using Ada 2012 syntax, since we get wrong | |
12391 | -- messages we do not understand. The whole business of derived | |
12392 | -- types and rep items seems a bit confused when aspects are | |
12393 | -- used, since the aspects are not evaluated till freeze time. | |
12394 | ||
12395 | and then not From_Aspect_Specification (N) | |
12396 | then | |
12397 | Error_Msg_Sloc := Sloc (DTL); | |
12398 | Error_Msg_N | |
12399 | ("representation item for& appears after derived type " | |
12400 | & "declaration#??", N); | |
12401 | Error_Msg_NE | |
12402 | ("\may result in implicit conversions for primitive " | |
12403 | & "operations of&??", N, T); | |
12404 | Error_Msg_NE | |
12405 | ("\to change representations when called with arguments " | |
12406 | & "of type&??", N, DTL); | |
12407 | end if; | |
12408 | end; | |
12409 | end if; | |
12410 | ||
3062c401 | 12411 | -- No error, link item into head of chain of rep items for the entity, |
12412 | -- but avoid chaining if we have an overloadable entity, and the pragma | |
12413 | -- is one that can apply to multiple overloaded entities. | |
12414 | ||
b9e61b2a | 12415 | if Is_Overloadable (T) and then Nkind (N) = N_Pragma then |
fdd294d1 | 12416 | declare |
ddccc924 | 12417 | Pname : constant Name_Id := Pragma_Name (N); |
fdd294d1 | 12418 | begin |
18393965 | 12419 | if Nam_In (Pname, Name_Convention, Name_Import, Name_Export, |
12420 | Name_External, Name_Interface) | |
fdd294d1 | 12421 | then |
12422 | return False; | |
12423 | end if; | |
12424 | end; | |
3062c401 | 12425 | end if; |
12426 | ||
fdd294d1 | 12427 | Record_Rep_Item (T, N); |
d6f39728 | 12428 | return False; |
12429 | end Rep_Item_Too_Late; | |
12430 | ||
2072eaa9 | 12431 | ------------------------------------- |
12432 | -- Replace_Type_References_Generic -- | |
12433 | ------------------------------------- | |
12434 | ||
37c6552c | 12435 | procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is |
12436 | TName : constant Name_Id := Chars (T); | |
2072eaa9 | 12437 | |
97c23bbe | 12438 | function Replace_Type_Ref (N : Node_Id) return Traverse_Result; |
2072eaa9 | 12439 | -- Processes a single node in the traversal procedure below, checking |
12440 | -- if node N should be replaced, and if so, doing the replacement. | |
12441 | ||
d0931270 | 12442 | function Visible_Component (Comp : Name_Id) return Entity_Id; |
12443 | -- Given an identifier in the expression, check whether there is a | |
12444 | -- discriminant or component of the type that is directy visible, and | |
12445 | -- rewrite it as the corresponding selected component of the formal of | |
12446 | -- the subprogram. The entity is located by a sequential search, which | |
12447 | -- seems acceptable given the typical size of component lists and check | |
12448 | -- expressions. Possible optimization ??? | |
12449 | ||
97c23bbe | 12450 | ---------------------- |
12451 | -- Replace_Type_Ref -- | |
12452 | ---------------------- | |
2072eaa9 | 12453 | |
97c23bbe | 12454 | function Replace_Type_Ref (N : Node_Id) return Traverse_Result is |
d0931270 | 12455 | Loc : constant Source_Ptr := Sloc (N); |
2072eaa9 | 12456 | |
d0931270 | 12457 | procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id); |
77fd9c7a | 12458 | -- Add the proper prefix to a reference to a component of the type |
12459 | -- when it is not already a selected component. | |
d0931270 | 12460 | |
12461 | ---------------- | |
12462 | -- Add_Prefix -- | |
12463 | ---------------- | |
2072eaa9 | 12464 | |
d0931270 | 12465 | procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id) is |
12466 | begin | |
12467 | Rewrite (Ref, | |
12468 | Make_Selected_Component (Loc, | |
77fd9c7a | 12469 | Prefix => New_Occurrence_Of (T, Loc), |
d0931270 | 12470 | Selector_Name => New_Occurrence_Of (Comp, Loc))); |
12471 | Replace_Type_Reference (Prefix (Ref)); | |
12472 | end Add_Prefix; | |
12473 | ||
77fd9c7a | 12474 | -- Local variables |
12475 | ||
12476 | Comp : Entity_Id; | |
12477 | Pref : Node_Id; | |
12478 | Scop : Entity_Id; | |
12479 | ||
d0931270 | 12480 | -- Start of processing for Replace_Type_Ref |
12481 | ||
12482 | begin | |
2072eaa9 | 12483 | if Nkind (N) = N_Identifier then |
12484 | ||
97c23bbe | 12485 | -- If not the type name, check whether it is a reference to some |
12486 | -- other type, which must be frozen before the predicate function | |
12487 | -- is analyzed, i.e. before the freeze node of the type to which | |
12488 | -- the predicate applies. | |
2072eaa9 | 12489 | |
12490 | if Chars (N) /= TName then | |
37c6552c | 12491 | if Present (Current_Entity (N)) |
46532462 | 12492 | and then Is_Type (Current_Entity (N)) |
37c6552c | 12493 | then |
12494 | Freeze_Before (Freeze_Node (T), Current_Entity (N)); | |
12495 | end if; | |
12496 | ||
d0931270 | 12497 | -- The components of the type are directly visible and can |
12498 | -- be referenced without a prefix. | |
12499 | ||
12500 | if Nkind (Parent (N)) = N_Selected_Component then | |
12501 | null; | |
12502 | ||
12503 | -- In expression C (I), C may be a directly visible function | |
12504 | -- or a visible component that has an array type. Disambiguate | |
12505 | -- by examining the component type. | |
12506 | ||
12507 | elsif Nkind (Parent (N)) = N_Indexed_Component | |
12508 | and then N = Prefix (Parent (N)) | |
12509 | then | |
77fd9c7a | 12510 | Comp := Visible_Component (Chars (N)); |
d0931270 | 12511 | |
77fd9c7a | 12512 | if Present (Comp) and then Is_Array_Type (Etype (Comp)) then |
12513 | Add_Prefix (N, Comp); | |
d0931270 | 12514 | end if; |
12515 | ||
12516 | else | |
77fd9c7a | 12517 | Comp := Visible_Component (Chars (N)); |
d0931270 | 12518 | |
77fd9c7a | 12519 | if Present (Comp) then |
12520 | Add_Prefix (N, Comp); | |
d0931270 | 12521 | end if; |
12522 | end if; | |
12523 | ||
2072eaa9 | 12524 | return Skip; |
12525 | ||
12526 | -- Otherwise do the replacement and we are done with this node | |
12527 | ||
12528 | else | |
12529 | Replace_Type_Reference (N); | |
12530 | return Skip; | |
12531 | end if; | |
12532 | ||
97c23bbe | 12533 | -- Case of selected component (which is what a qualification looks |
12534 | -- like in the unanalyzed tree, which is what we have. | |
2072eaa9 | 12535 | |
12536 | elsif Nkind (N) = N_Selected_Component then | |
12537 | ||
97c23bbe | 12538 | -- If selector name is not our type, keeping going (we might still |
12539 | -- have an occurrence of the type in the prefix). | |
2072eaa9 | 12540 | |
12541 | if Nkind (Selector_Name (N)) /= N_Identifier | |
12542 | or else Chars (Selector_Name (N)) /= TName | |
12543 | then | |
12544 | return OK; | |
12545 | ||
12546 | -- Selector name is our type, check qualification | |
12547 | ||
12548 | else | |
12549 | -- Loop through scopes and prefixes, doing comparison | |
12550 | ||
77fd9c7a | 12551 | Scop := Current_Scope; |
12552 | Pref := Prefix (N); | |
2072eaa9 | 12553 | loop |
12554 | -- Continue if no more scopes or scope with no name | |
12555 | ||
77fd9c7a | 12556 | if No (Scop) or else Nkind (Scop) not in N_Has_Chars then |
2072eaa9 | 12557 | return OK; |
12558 | end if; | |
12559 | ||
97c23bbe | 12560 | -- Do replace if prefix is an identifier matching the scope |
12561 | -- that we are currently looking at. | |
2072eaa9 | 12562 | |
77fd9c7a | 12563 | if Nkind (Pref) = N_Identifier |
12564 | and then Chars (Pref) = Chars (Scop) | |
2072eaa9 | 12565 | then |
12566 | Replace_Type_Reference (N); | |
12567 | return Skip; | |
12568 | end if; | |
12569 | ||
97c23bbe | 12570 | -- Go check scope above us if prefix is itself of the form |
12571 | -- of a selected component, whose selector matches the scope | |
12572 | -- we are currently looking at. | |
2072eaa9 | 12573 | |
77fd9c7a | 12574 | if Nkind (Pref) = N_Selected_Component |
12575 | and then Nkind (Selector_Name (Pref)) = N_Identifier | |
12576 | and then Chars (Selector_Name (Pref)) = Chars (Scop) | |
2072eaa9 | 12577 | then |
77fd9c7a | 12578 | Scop := Scope (Scop); |
12579 | Pref := Prefix (Pref); | |
2072eaa9 | 12580 | |
12581 | -- For anything else, we don't have a match, so keep on | |
12582 | -- going, there are still some weird cases where we may | |
12583 | -- still have a replacement within the prefix. | |
12584 | ||
12585 | else | |
12586 | return OK; | |
12587 | end if; | |
12588 | end loop; | |
12589 | end if; | |
12590 | ||
ec6f6da5 | 12591 | -- Continue for any other node kind |
2072eaa9 | 12592 | |
12593 | else | |
12594 | return OK; | |
12595 | end if; | |
97c23bbe | 12596 | end Replace_Type_Ref; |
12597 | ||
77fd9c7a | 12598 | procedure Replace_Type_Refs is new Traverse_Proc (Replace_Type_Ref); |
12599 | ||
d0931270 | 12600 | ----------------------- |
12601 | -- Visible_Component -- | |
12602 | ----------------------- | |
12603 | ||
12604 | function Visible_Component (Comp : Name_Id) return Entity_Id is | |
12605 | E : Entity_Id; | |
77fd9c7a | 12606 | |
d0931270 | 12607 | begin |
12608 | if Ekind (T) /= E_Record_Type then | |
12609 | return Empty; | |
12610 | ||
12611 | else | |
12612 | E := First_Entity (T); | |
12613 | while Present (E) loop | |
77fd9c7a | 12614 | if Comes_From_Source (E) and then Chars (E) = Comp then |
d0931270 | 12615 | return E; |
12616 | end if; | |
12617 | ||
12618 | Next_Entity (E); | |
12619 | end loop; | |
12620 | ||
12621 | return Empty; | |
12622 | end if; | |
12623 | end Visible_Component; | |
12624 | ||
77fd9c7a | 12625 | -- Start of processing for Replace_Type_References_Generic |
2072eaa9 | 12626 | |
12627 | begin | |
12628 | Replace_Type_Refs (N); | |
12629 | end Replace_Type_References_Generic; | |
12630 | ||
81bd1c0d | 12631 | -------------------------------- |
12632 | -- Resolve_Aspect_Expressions -- | |
12633 | -------------------------------- | |
12634 | ||
12635 | procedure Resolve_Aspect_Expressions (E : Entity_Id) is | |
12636 | ASN : Node_Id; | |
12637 | A_Id : Aspect_Id; | |
12638 | Expr : Node_Id; | |
12639 | ||
9c20237a | 12640 | function Resolve_Name (N : Node_Id) return Traverse_Result; |
12641 | -- Verify that all identifiers in the expression, with the exception | |
12642 | -- of references to the current entity, denote visible entities. This | |
12643 | -- is done only to detect visibility errors, as the expression will be | |
12644 | -- properly analyzed/expanded during analysis of the predicate function | |
c098acfb | 12645 | -- body. We omit quantified expressions from this test, given that they |
12646 | -- introduce a local identifier that would require proper expansion to | |
12647 | -- handle properly. | |
9c20237a | 12648 | |
12649 | ------------------ | |
12650 | -- Resolve_Name -- | |
12651 | ------------------ | |
12652 | ||
12653 | function Resolve_Name (N : Node_Id) return Traverse_Result is | |
12654 | begin | |
12655 | if Nkind (N) = N_Selected_Component then | |
12656 | if Nkind (Prefix (N)) = N_Identifier | |
12657 | and then Chars (Prefix (N)) /= Chars (E) | |
12658 | then | |
f4e18891 | 12659 | Find_Selected_Component (N); |
9c20237a | 12660 | end if; |
02e5d0d0 | 12661 | |
9c20237a | 12662 | return Skip; |
12663 | ||
02e5d0d0 | 12664 | elsif Nkind (N) = N_Identifier and then Chars (N) /= Chars (E) then |
9c20237a | 12665 | Find_Direct_Name (N); |
12666 | Set_Entity (N, Empty); | |
c098acfb | 12667 | |
12668 | elsif Nkind (N) = N_Quantified_Expression then | |
12669 | return Skip; | |
9c20237a | 12670 | end if; |
12671 | ||
12672 | return OK; | |
12673 | end Resolve_Name; | |
12674 | ||
12675 | procedure Resolve_Aspect_Expression is new Traverse_Proc (Resolve_Name); | |
12676 | ||
02e5d0d0 | 12677 | -- Start of processing for Resolve_Aspect_Expressions |
12678 | ||
81bd1c0d | 12679 | begin |
12680 | ASN := First_Rep_Item (E); | |
12681 | while Present (ASN) loop | |
12682 | if Nkind (ASN) = N_Aspect_Specification and then Entity (ASN) = E then | |
12683 | A_Id := Get_Aspect_Id (ASN); | |
12684 | Expr := Expression (ASN); | |
12685 | ||
12686 | case A_Id is | |
97c23bbe | 12687 | |
81bd1c0d | 12688 | -- For now we only deal with aspects that do not generate |
12689 | -- subprograms, or that may mention current instances of | |
fdec445e | 12690 | -- types. These will require special handling (???TBD). |
81bd1c0d | 12691 | |
02e5d0d0 | 12692 | when Aspect_Predicate | |
fdec445e | 12693 | Aspect_Predicate_Failure | |
97c23bbe | 12694 | Aspect_Invariant => |
81bd1c0d | 12695 | null; |
12696 | ||
97c23bbe | 12697 | when Aspect_Dynamic_Predicate | |
12698 | Aspect_Static_Predicate => | |
9c20237a | 12699 | |
02e5d0d0 | 12700 | -- Build predicate function specification and preanalyze |
9c20237a | 12701 | -- expression after type replacement. |
12702 | ||
12703 | if No (Predicate_Function (E)) then | |
12704 | declare | |
12705 | FDecl : constant Node_Id := | |
02e5d0d0 | 12706 | Build_Predicate_Function_Declaration (E); |
9c20237a | 12707 | pragma Unreferenced (FDecl); |
12708 | begin | |
12709 | Resolve_Aspect_Expression (Expr); | |
12710 | end; | |
12711 | end if; | |
12712 | ||
81bd1c0d | 12713 | when Pre_Post_Aspects => |
12714 | null; | |
12715 | ||
12716 | when Aspect_Iterable => | |
12717 | if Nkind (Expr) = N_Aggregate then | |
12718 | declare | |
12719 | Assoc : Node_Id; | |
12720 | ||
12721 | begin | |
12722 | Assoc := First (Component_Associations (Expr)); | |
12723 | while Present (Assoc) loop | |
12724 | Find_Direct_Name (Expression (Assoc)); | |
12725 | Next (Assoc); | |
12726 | end loop; | |
12727 | end; | |
12728 | end if; | |
12729 | ||
12730 | when others => | |
12731 | if Present (Expr) then | |
12732 | case Aspect_Argument (A_Id) is | |
12733 | when Expression | Optional_Expression => | |
12734 | Analyze_And_Resolve (Expression (ASN)); | |
12735 | ||
12736 | when Name | Optional_Name => | |
12737 | if Nkind (Expr) = N_Identifier then | |
12738 | Find_Direct_Name (Expr); | |
12739 | ||
12740 | elsif Nkind (Expr) = N_Selected_Component then | |
12741 | Find_Selected_Component (Expr); | |
12742 | ||
12743 | else | |
12744 | null; | |
12745 | end if; | |
12746 | end case; | |
12747 | end if; | |
12748 | end case; | |
12749 | end if; | |
12750 | ||
a738763e | 12751 | ASN := Next_Rep_Item (ASN); |
81bd1c0d | 12752 | end loop; |
12753 | end Resolve_Aspect_Expressions; | |
12754 | ||
d6f39728 | 12755 | ------------------------- |
12756 | -- Same_Representation -- | |
12757 | ------------------------- | |
12758 | ||
12759 | function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is | |
12760 | T1 : constant Entity_Id := Underlying_Type (Typ1); | |
12761 | T2 : constant Entity_Id := Underlying_Type (Typ2); | |
12762 | ||
12763 | begin | |
12764 | -- A quick check, if base types are the same, then we definitely have | |
12765 | -- the same representation, because the subtype specific representation | |
12766 | -- attributes (Size and Alignment) do not affect representation from | |
12767 | -- the point of view of this test. | |
12768 | ||
12769 | if Base_Type (T1) = Base_Type (T2) then | |
12770 | return True; | |
12771 | ||
12772 | elsif Is_Private_Type (Base_Type (T2)) | |
12773 | and then Base_Type (T1) = Full_View (Base_Type (T2)) | |
12774 | then | |
12775 | return True; | |
12776 | end if; | |
12777 | ||
12778 | -- Tagged types never have differing representations | |
12779 | ||
12780 | if Is_Tagged_Type (T1) then | |
12781 | return True; | |
12782 | end if; | |
12783 | ||
12784 | -- Representations are definitely different if conventions differ | |
12785 | ||
12786 | if Convention (T1) /= Convention (T2) then | |
12787 | return False; | |
12788 | end if; | |
12789 | ||
ef0772bc | 12790 | -- Representations are different if component alignments or scalar |
12791 | -- storage orders differ. | |
d6f39728 | 12792 | |
12793 | if (Is_Record_Type (T1) or else Is_Array_Type (T1)) | |
726fd56a | 12794 | and then |
d6f39728 | 12795 | (Is_Record_Type (T2) or else Is_Array_Type (T2)) |
ef0772bc | 12796 | and then |
12797 | (Component_Alignment (T1) /= Component_Alignment (T2) | |
f02a9a9a | 12798 | or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2)) |
d6f39728 | 12799 | then |
12800 | return False; | |
12801 | end if; | |
12802 | ||
12803 | -- For arrays, the only real issue is component size. If we know the | |
12804 | -- component size for both arrays, and it is the same, then that's | |
12805 | -- good enough to know we don't have a change of representation. | |
12806 | ||
12807 | if Is_Array_Type (T1) then | |
12808 | if Known_Component_Size (T1) | |
12809 | and then Known_Component_Size (T2) | |
12810 | and then Component_Size (T1) = Component_Size (T2) | |
12811 | then | |
36ac5fbb | 12812 | return True; |
d6f39728 | 12813 | end if; |
12814 | end if; | |
12815 | ||
12816 | -- Types definitely have same representation if neither has non-standard | |
12817 | -- representation since default representations are always consistent. | |
12818 | -- If only one has non-standard representation, and the other does not, | |
12819 | -- then we consider that they do not have the same representation. They | |
12820 | -- might, but there is no way of telling early enough. | |
12821 | ||
12822 | if Has_Non_Standard_Rep (T1) then | |
12823 | if not Has_Non_Standard_Rep (T2) then | |
12824 | return False; | |
12825 | end if; | |
12826 | else | |
12827 | return not Has_Non_Standard_Rep (T2); | |
12828 | end if; | |
12829 | ||
fdd294d1 | 12830 | -- Here the two types both have non-standard representation, and we need |
12831 | -- to determine if they have the same non-standard representation. | |
d6f39728 | 12832 | |
12833 | -- For arrays, we simply need to test if the component sizes are the | |
12834 | -- same. Pragma Pack is reflected in modified component sizes, so this | |
12835 | -- check also deals with pragma Pack. | |
12836 | ||
12837 | if Is_Array_Type (T1) then | |
12838 | return Component_Size (T1) = Component_Size (T2); | |
12839 | ||
12840 | -- Tagged types always have the same representation, because it is not | |
12841 | -- possible to specify different representations for common fields. | |
12842 | ||
12843 | elsif Is_Tagged_Type (T1) then | |
12844 | return True; | |
12845 | ||
12846 | -- Case of record types | |
12847 | ||
12848 | elsif Is_Record_Type (T1) then | |
12849 | ||
12850 | -- Packed status must conform | |
12851 | ||
12852 | if Is_Packed (T1) /= Is_Packed (T2) then | |
12853 | return False; | |
12854 | ||
12855 | -- Otherwise we must check components. Typ2 maybe a constrained | |
12856 | -- subtype with fewer components, so we compare the components | |
12857 | -- of the base types. | |
12858 | ||
12859 | else | |
12860 | Record_Case : declare | |
12861 | CD1, CD2 : Entity_Id; | |
12862 | ||
12863 | function Same_Rep return Boolean; | |
12864 | -- CD1 and CD2 are either components or discriminants. This | |
ef0772bc | 12865 | -- function tests whether they have the same representation. |
d6f39728 | 12866 | |
80d4fec4 | 12867 | -------------- |
12868 | -- Same_Rep -- | |
12869 | -------------- | |
12870 | ||
d6f39728 | 12871 | function Same_Rep return Boolean is |
12872 | begin | |
12873 | if No (Component_Clause (CD1)) then | |
12874 | return No (Component_Clause (CD2)); | |
d6f39728 | 12875 | else |
ef0772bc | 12876 | -- Note: at this point, component clauses have been |
12877 | -- normalized to the default bit order, so that the | |
12878 | -- comparison of Component_Bit_Offsets is meaningful. | |
12879 | ||
d6f39728 | 12880 | return |
12881 | Present (Component_Clause (CD2)) | |
12882 | and then | |
12883 | Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2) | |
12884 | and then | |
12885 | Esize (CD1) = Esize (CD2); | |
12886 | end if; | |
12887 | end Same_Rep; | |
12888 | ||
1e35409d | 12889 | -- Start of processing for Record_Case |
d6f39728 | 12890 | |
12891 | begin | |
12892 | if Has_Discriminants (T1) then | |
d6f39728 | 12893 | |
9dfe12ae | 12894 | -- The number of discriminants may be different if the |
12895 | -- derived type has fewer (constrained by values). The | |
12896 | -- invisible discriminants retain the representation of | |
12897 | -- the original, so the discrepancy does not per se | |
12898 | -- indicate a different representation. | |
12899 | ||
b9e61b2a | 12900 | CD1 := First_Discriminant (T1); |
12901 | CD2 := First_Discriminant (T2); | |
12902 | while Present (CD1) and then Present (CD2) loop | |
d6f39728 | 12903 | if not Same_Rep then |
12904 | return False; | |
12905 | else | |
12906 | Next_Discriminant (CD1); | |
12907 | Next_Discriminant (CD2); | |
12908 | end if; | |
12909 | end loop; | |
12910 | end if; | |
12911 | ||
12912 | CD1 := First_Component (Underlying_Type (Base_Type (T1))); | |
12913 | CD2 := First_Component (Underlying_Type (Base_Type (T2))); | |
d6f39728 | 12914 | while Present (CD1) loop |
12915 | if not Same_Rep then | |
12916 | return False; | |
12917 | else | |
12918 | Next_Component (CD1); | |
12919 | Next_Component (CD2); | |
12920 | end if; | |
12921 | end loop; | |
12922 | ||
12923 | return True; | |
12924 | end Record_Case; | |
12925 | end if; | |
12926 | ||
12927 | -- For enumeration types, we must check each literal to see if the | |
12928 | -- representation is the same. Note that we do not permit enumeration | |
1a34e48c | 12929 | -- representation clauses for Character and Wide_Character, so these |
d6f39728 | 12930 | -- cases were already dealt with. |
12931 | ||
12932 | elsif Is_Enumeration_Type (T1) then | |
d6f39728 | 12933 | Enumeration_Case : declare |
12934 | L1, L2 : Entity_Id; | |
12935 | ||
12936 | begin | |
12937 | L1 := First_Literal (T1); | |
12938 | L2 := First_Literal (T2); | |
d6f39728 | 12939 | while Present (L1) loop |
12940 | if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then | |
12941 | return False; | |
12942 | else | |
12943 | Next_Literal (L1); | |
12944 | Next_Literal (L2); | |
12945 | end if; | |
12946 | end loop; | |
12947 | ||
12948 | return True; | |
d6f39728 | 12949 | end Enumeration_Case; |
12950 | ||
12951 | -- Any other types have the same representation for these purposes | |
12952 | ||
12953 | else | |
12954 | return True; | |
12955 | end if; | |
d6f39728 | 12956 | end Same_Representation; |
12957 | ||
3061ffde | 12958 | -------------------------------- |
12959 | -- Resolve_Iterable_Operation -- | |
12960 | -------------------------------- | |
12961 | ||
12962 | procedure Resolve_Iterable_Operation | |
12963 | (N : Node_Id; | |
12964 | Cursor : Entity_Id; | |
12965 | Typ : Entity_Id; | |
12966 | Nam : Name_Id) | |
12967 | is | |
12968 | Ent : Entity_Id; | |
12969 | F1 : Entity_Id; | |
12970 | F2 : Entity_Id; | |
12971 | ||
12972 | begin | |
12973 | if not Is_Overloaded (N) then | |
12974 | if not Is_Entity_Name (N) | |
12975 | or else Ekind (Entity (N)) /= E_Function | |
12976 | or else Scope (Entity (N)) /= Scope (Typ) | |
12977 | or else No (First_Formal (Entity (N))) | |
12978 | or else Etype (First_Formal (Entity (N))) /= Typ | |
12979 | then | |
12980 | Error_Msg_N ("iterable primitive must be local function name " | |
12981 | & "whose first formal is an iterable type", N); | |
a9f5fea7 | 12982 | return; |
3061ffde | 12983 | end if; |
12984 | ||
12985 | Ent := Entity (N); | |
12986 | F1 := First_Formal (Ent); | |
12987 | if Nam = Name_First then | |
12988 | ||
12989 | -- First (Container) => Cursor | |
12990 | ||
12991 | if Etype (Ent) /= Cursor then | |
12992 | Error_Msg_N ("primitive for First must yield a curosr", N); | |
12993 | end if; | |
12994 | ||
12995 | elsif Nam = Name_Next then | |
12996 | ||
12997 | -- Next (Container, Cursor) => Cursor | |
12998 | ||
12999 | F2 := Next_Formal (F1); | |
13000 | ||
13001 | if Etype (F2) /= Cursor | |
13002 | or else Etype (Ent) /= Cursor | |
13003 | or else Present (Next_Formal (F2)) | |
13004 | then | |
13005 | Error_Msg_N ("no match for Next iterable primitive", N); | |
13006 | end if; | |
13007 | ||
13008 | elsif Nam = Name_Has_Element then | |
13009 | ||
13010 | -- Has_Element (Container, Cursor) => Boolean | |
13011 | ||
13012 | F2 := Next_Formal (F1); | |
13013 | if Etype (F2) /= Cursor | |
13014 | or else Etype (Ent) /= Standard_Boolean | |
13015 | or else Present (Next_Formal (F2)) | |
13016 | then | |
13017 | Error_Msg_N ("no match for Has_Element iterable primitive", N); | |
13018 | end if; | |
13019 | ||
13020 | elsif Nam = Name_Element then | |
b9b03799 | 13021 | F2 := Next_Formal (F1); |
13022 | ||
13023 | if No (F2) | |
13024 | or else Etype (F2) /= Cursor | |
13025 | or else Present (Next_Formal (F2)) | |
13026 | then | |
13027 | Error_Msg_N ("no match for Element iterable primitive", N); | |
13028 | end if; | |
3061ffde | 13029 | null; |
13030 | ||
13031 | else | |
13032 | raise Program_Error; | |
13033 | end if; | |
13034 | ||
13035 | else | |
13036 | -- Overloaded case: find subprogram with proper signature. | |
13037 | -- Caller will report error if no match is found. | |
13038 | ||
13039 | declare | |
13040 | I : Interp_Index; | |
13041 | It : Interp; | |
13042 | ||
13043 | begin | |
13044 | Get_First_Interp (N, I, It); | |
13045 | while Present (It.Typ) loop | |
13046 | if Ekind (It.Nam) = E_Function | |
b9b03799 | 13047 | and then Scope (It.Nam) = Scope (Typ) |
3061ffde | 13048 | and then Etype (First_Formal (It.Nam)) = Typ |
13049 | then | |
13050 | F1 := First_Formal (It.Nam); | |
13051 | ||
13052 | if Nam = Name_First then | |
13053 | if Etype (It.Nam) = Cursor | |
13054 | and then No (Next_Formal (F1)) | |
13055 | then | |
13056 | Set_Entity (N, It.Nam); | |
13057 | exit; | |
13058 | end if; | |
13059 | ||
13060 | elsif Nam = Name_Next then | |
13061 | F2 := Next_Formal (F1); | |
13062 | ||
13063 | if Present (F2) | |
13064 | and then No (Next_Formal (F2)) | |
13065 | and then Etype (F2) = Cursor | |
13066 | and then Etype (It.Nam) = Cursor | |
13067 | then | |
13068 | Set_Entity (N, It.Nam); | |
13069 | exit; | |
13070 | end if; | |
13071 | ||
13072 | elsif Nam = Name_Has_Element then | |
13073 | F2 := Next_Formal (F1); | |
13074 | ||
13075 | if Present (F2) | |
13076 | and then No (Next_Formal (F2)) | |
13077 | and then Etype (F2) = Cursor | |
13078 | and then Etype (It.Nam) = Standard_Boolean | |
13079 | then | |
13080 | Set_Entity (N, It.Nam); | |
13081 | F2 := Next_Formal (F1); | |
13082 | exit; | |
13083 | end if; | |
13084 | ||
13085 | elsif Nam = Name_Element then | |
b9b03799 | 13086 | F2 := Next_Formal (F1); |
13087 | ||
3061ffde | 13088 | if Present (F2) |
13089 | and then No (Next_Formal (F2)) | |
13090 | and then Etype (F2) = Cursor | |
13091 | then | |
13092 | Set_Entity (N, It.Nam); | |
13093 | exit; | |
13094 | end if; | |
13095 | end if; | |
13096 | end if; | |
13097 | ||
13098 | Get_Next_Interp (I, It); | |
13099 | end loop; | |
13100 | end; | |
13101 | end if; | |
13102 | end Resolve_Iterable_Operation; | |
13103 | ||
b77e4501 | 13104 | ---------------- |
13105 | -- Set_Biased -- | |
13106 | ---------------- | |
13107 | ||
13108 | procedure Set_Biased | |
13109 | (E : Entity_Id; | |
13110 | N : Node_Id; | |
13111 | Msg : String; | |
13112 | Biased : Boolean := True) | |
13113 | is | |
13114 | begin | |
13115 | if Biased then | |
13116 | Set_Has_Biased_Representation (E); | |
13117 | ||
13118 | if Warn_On_Biased_Representation then | |
13119 | Error_Msg_NE | |
1e3532e7 | 13120 | ("?B?" & Msg & " forces biased representation for&", N, E); |
b77e4501 | 13121 | end if; |
13122 | end if; | |
13123 | end Set_Biased; | |
13124 | ||
d6f39728 | 13125 | -------------------- |
13126 | -- Set_Enum_Esize -- | |
13127 | -------------------- | |
13128 | ||
13129 | procedure Set_Enum_Esize (T : Entity_Id) is | |
13130 | Lo : Uint; | |
13131 | Hi : Uint; | |
13132 | Sz : Nat; | |
13133 | ||
13134 | begin | |
13135 | Init_Alignment (T); | |
13136 | ||
13137 | -- Find the minimum standard size (8,16,32,64) that fits | |
13138 | ||
13139 | Lo := Enumeration_Rep (Entity (Type_Low_Bound (T))); | |
13140 | Hi := Enumeration_Rep (Entity (Type_High_Bound (T))); | |
13141 | ||
13142 | if Lo < 0 then | |
13143 | if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then | |
f15731c4 | 13144 | Sz := Standard_Character_Size; -- May be > 8 on some targets |
d6f39728 | 13145 | |
13146 | elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then | |
13147 | Sz := 16; | |
13148 | ||
13149 | elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then | |
13150 | Sz := 32; | |
13151 | ||
13152 | else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63); | |
13153 | Sz := 64; | |
13154 | end if; | |
13155 | ||
13156 | else | |
13157 | if Hi < Uint_2**08 then | |
f15731c4 | 13158 | Sz := Standard_Character_Size; -- May be > 8 on some targets |
d6f39728 | 13159 | |
13160 | elsif Hi < Uint_2**16 then | |
13161 | Sz := 16; | |
13162 | ||
13163 | elsif Hi < Uint_2**32 then | |
13164 | Sz := 32; | |
13165 | ||
13166 | else pragma Assert (Hi < Uint_2**63); | |
13167 | Sz := 64; | |
13168 | end if; | |
13169 | end if; | |
13170 | ||
13171 | -- That minimum is the proper size unless we have a foreign convention | |
13172 | -- and the size required is 32 or less, in which case we bump the size | |
13173 | -- up to 32. This is required for C and C++ and seems reasonable for | |
13174 | -- all other foreign conventions. | |
13175 | ||
13176 | if Has_Foreign_Convention (T) | |
13177 | and then Esize (T) < Standard_Integer_Size | |
db1eed69 | 13178 | |
13179 | -- Don't do this if Short_Enums on target | |
13180 | ||
e9185b9d | 13181 | and then not Target_Short_Enums |
d6f39728 | 13182 | then |
13183 | Init_Esize (T, Standard_Integer_Size); | |
d6f39728 | 13184 | else |
13185 | Init_Esize (T, Sz); | |
13186 | end if; | |
d6f39728 | 13187 | end Set_Enum_Esize; |
13188 | ||
2625eb01 | 13189 | ----------------------------- |
13190 | -- Uninstall_Discriminants -- | |
13191 | ----------------------------- | |
13192 | ||
13193 | procedure Uninstall_Discriminants (E : Entity_Id) is | |
13194 | Disc : Entity_Id; | |
13195 | Prev : Entity_Id; | |
13196 | Outer : Entity_Id; | |
13197 | ||
13198 | begin | |
13199 | -- Discriminants have been made visible for type declarations and | |
13200 | -- protected type declarations, not for subtype declarations. | |
13201 | ||
13202 | if Nkind (Parent (E)) /= N_Subtype_Declaration then | |
13203 | Disc := First_Discriminant (E); | |
13204 | while Present (Disc) loop | |
13205 | if Disc /= Current_Entity (Disc) then | |
13206 | Prev := Current_Entity (Disc); | |
13207 | while Present (Prev) | |
13208 | and then Present (Homonym (Prev)) | |
13209 | and then Homonym (Prev) /= Disc | |
13210 | loop | |
13211 | Prev := Homonym (Prev); | |
13212 | end loop; | |
13213 | else | |
13214 | Prev := Empty; | |
13215 | end if; | |
13216 | ||
13217 | Set_Is_Immediately_Visible (Disc, False); | |
13218 | ||
13219 | Outer := Homonym (Disc); | |
13220 | while Present (Outer) and then Scope (Outer) = E loop | |
13221 | Outer := Homonym (Outer); | |
13222 | end loop; | |
13223 | ||
13224 | -- Reset homonym link of other entities, but do not modify link | |
3ff5e35d | 13225 | -- between entities in current scope, so that the back end can |
2625eb01 | 13226 | -- have a proper count of local overloadings. |
13227 | ||
13228 | if No (Prev) then | |
13229 | Set_Name_Entity_Id (Chars (Disc), Outer); | |
13230 | ||
13231 | elsif Scope (Prev) /= Scope (Disc) then | |
13232 | Set_Homonym (Prev, Outer); | |
13233 | end if; | |
13234 | ||
13235 | Next_Discriminant (Disc); | |
13236 | end loop; | |
13237 | end if; | |
13238 | end Uninstall_Discriminants; | |
13239 | ||
13240 | ------------------------------------------- | |
13241 | -- Uninstall_Discriminants_And_Pop_Scope -- | |
13242 | ------------------------------------------- | |
13243 | ||
13244 | procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id) is | |
13245 | begin | |
13246 | if Has_Discriminants (E) then | |
13247 | Uninstall_Discriminants (E); | |
13248 | Pop_Scope; | |
13249 | end if; | |
13250 | end Uninstall_Discriminants_And_Pop_Scope; | |
13251 | ||
83f8f0a6 | 13252 | ------------------------------ |
13253 | -- Validate_Address_Clauses -- | |
13254 | ------------------------------ | |
13255 | ||
13256 | procedure Validate_Address_Clauses is | |
c7a1569a | 13257 | function Offset_Value (Expr : Node_Id) return Uint; |
13258 | -- Given an Address attribute reference, return the value in bits of its | |
13259 | -- offset from the first bit of the underlying entity, or 0 if it is not | |
13260 | -- known at compile time. | |
13261 | ||
13262 | ------------------ | |
13263 | -- Offset_Value -- | |
13264 | ------------------ | |
13265 | ||
13266 | function Offset_Value (Expr : Node_Id) return Uint is | |
13267 | N : Node_Id := Prefix (Expr); | |
13268 | Off : Uint; | |
13269 | Val : Uint := Uint_0; | |
13270 | ||
13271 | begin | |
13272 | -- Climb the prefix chain and compute the cumulative offset | |
13273 | ||
13274 | loop | |
13275 | if Is_Entity_Name (N) then | |
13276 | return Val; | |
13277 | ||
13278 | elsif Nkind (N) = N_Selected_Component then | |
13279 | Off := Component_Bit_Offset (Entity (Selector_Name (N))); | |
13280 | if Off /= No_Uint and then Off >= Uint_0 then | |
13281 | Val := Val + Off; | |
13282 | N := Prefix (N); | |
13283 | else | |
13284 | return Uint_0; | |
13285 | end if; | |
13286 | ||
13287 | elsif Nkind (N) = N_Indexed_Component then | |
13288 | Off := Indexed_Component_Bit_Offset (N); | |
13289 | if Off /= No_Uint then | |
13290 | Val := Val + Off; | |
13291 | N := Prefix (N); | |
13292 | else | |
13293 | return Uint_0; | |
13294 | end if; | |
13295 | ||
13296 | else | |
13297 | return Uint_0; | |
13298 | end if; | |
13299 | end loop; | |
13300 | end Offset_Value; | |
13301 | ||
13302 | -- Start of processing for Validate_Address_Clauses | |
13303 | ||
83f8f0a6 | 13304 | begin |
13305 | for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop | |
13306 | declare | |
13307 | ACCR : Address_Clause_Check_Record | |
13308 | renames Address_Clause_Checks.Table (J); | |
13309 | ||
d6da7448 | 13310 | Expr : Node_Id; |
13311 | ||
83f8f0a6 | 13312 | X_Alignment : Uint; |
13313 | Y_Alignment : Uint; | |
13314 | ||
13315 | X_Size : Uint; | |
13316 | Y_Size : Uint; | |
13317 | ||
c7a1569a | 13318 | X_Offs : Uint; |
13319 | ||
83f8f0a6 | 13320 | begin |
13321 | -- Skip processing of this entry if warning already posted | |
13322 | ||
13323 | if not Address_Warning_Posted (ACCR.N) then | |
d6da7448 | 13324 | Expr := Original_Node (Expression (ACCR.N)); |
83f8f0a6 | 13325 | |
514a5555 | 13326 | -- Get alignments, sizes and offset, if any |
83f8f0a6 | 13327 | |
d6da7448 | 13328 | X_Alignment := Alignment (ACCR.X); |
8650387e | 13329 | X_Size := Esize (ACCR.X); |
514a5555 | 13330 | |
13331 | if Present (ACCR.Y) then | |
13332 | Y_Alignment := Alignment (ACCR.Y); | |
8650387e | 13333 | Y_Size := Esize (ACCR.Y); |
514a5555 | 13334 | end if; |
83f8f0a6 | 13335 | |
c7a1569a | 13336 | if ACCR.Off |
13337 | and then Nkind (Expr) = N_Attribute_Reference | |
13338 | and then Attribute_Name (Expr) = Name_Address | |
13339 | then | |
13340 | X_Offs := Offset_Value (Expr); | |
13341 | else | |
13342 | X_Offs := Uint_0; | |
13343 | end if; | |
13344 | ||
514a5555 | 13345 | -- Check for known value not multiple of alignment |
13346 | ||
13347 | if No (ACCR.Y) then | |
13348 | if not Alignment_Checks_Suppressed (ACCR.X) | |
13349 | and then X_Alignment /= 0 | |
13350 | and then ACCR.A mod X_Alignment /= 0 | |
13351 | then | |
13352 | Error_Msg_NE | |
13353 | ("??specified address for& is inconsistent with " | |
13354 | & "alignment", ACCR.N, ACCR.X); | |
13355 | Error_Msg_N | |
13356 | ("\??program execution may be erroneous (RM 13.3(27))", | |
13357 | ACCR.N); | |
13358 | ||
13359 | Error_Msg_Uint_1 := X_Alignment; | |
13360 | Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X); | |
13361 | end if; | |
13362 | ||
83f8f0a6 | 13363 | -- Check for large object overlaying smaller one |
13364 | ||
514a5555 | 13365 | elsif Y_Size > Uint_0 |
83f8f0a6 | 13366 | and then X_Size > Uint_0 |
c7a1569a | 13367 | and then X_Offs + X_Size > Y_Size |
83f8f0a6 | 13368 | then |
7161e166 | 13369 | Error_Msg_NE ("??& overlays smaller object", ACCR.N, ACCR.X); |
83f8f0a6 | 13370 | Error_Msg_N |
1e3532e7 | 13371 | ("\??program execution may be erroneous", ACCR.N); |
7161e166 | 13372 | |
83f8f0a6 | 13373 | Error_Msg_Uint_1 := X_Size; |
7161e166 | 13374 | Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.X); |
13375 | ||
83f8f0a6 | 13376 | Error_Msg_Uint_1 := Y_Size; |
7161e166 | 13377 | Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.Y); |
83f8f0a6 | 13378 | |
f5cc2579 | 13379 | if Y_Size >= X_Size then |
c7a1569a | 13380 | Error_Msg_Uint_1 := X_Offs; |
f5cc2579 | 13381 | Error_Msg_NE ("\??but offset of & is ^", ACCR.N, ACCR.X); |
c7a1569a | 13382 | end if; |
13383 | ||
d6da7448 | 13384 | -- Check for inadequate alignment, both of the base object |
e556831e | 13385 | -- and of the offset, if any. We only do this check if the |
13386 | -- run-time Alignment_Check is active. No point in warning | |
13387 | -- if this check has been suppressed (or is suppressed by | |
13388 | -- default in the non-strict alignment machine case). | |
83f8f0a6 | 13389 | |
d6da7448 | 13390 | -- Note: we do not check the alignment if we gave a size |
13391 | -- warning, since it would likely be redundant. | |
83f8f0a6 | 13392 | |
514a5555 | 13393 | elsif not Alignment_Checks_Suppressed (ACCR.X) |
e556831e | 13394 | and then Y_Alignment /= Uint_0 |
7161e166 | 13395 | and then |
13396 | (Y_Alignment < X_Alignment | |
13397 | or else | |
13398 | (ACCR.Off | |
13399 | and then Nkind (Expr) = N_Attribute_Reference | |
13400 | and then Attribute_Name (Expr) = Name_Address | |
13401 | and then Has_Compatible_Alignment | |
13402 | (ACCR.X, Prefix (Expr), True) /= | |
13403 | Known_Compatible)) | |
83f8f0a6 | 13404 | then |
13405 | Error_Msg_NE | |
7161e166 | 13406 | ("??specified address for& may be inconsistent with " |
13407 | & "alignment", ACCR.N, ACCR.X); | |
83f8f0a6 | 13408 | Error_Msg_N |
1e3532e7 | 13409 | ("\??program execution may be erroneous (RM 13.3(27))", |
83f8f0a6 | 13410 | ACCR.N); |
7161e166 | 13411 | |
83f8f0a6 | 13412 | Error_Msg_Uint_1 := X_Alignment; |
7161e166 | 13413 | Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X); |
13414 | ||
83f8f0a6 | 13415 | Error_Msg_Uint_1 := Y_Alignment; |
7161e166 | 13416 | Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.Y); |
13417 | ||
d6da7448 | 13418 | if Y_Alignment >= X_Alignment then |
13419 | Error_Msg_N | |
7161e166 | 13420 | ("\??but offset is not multiple of alignment", ACCR.N); |
d6da7448 | 13421 | end if; |
83f8f0a6 | 13422 | end if; |
13423 | end if; | |
13424 | end; | |
13425 | end loop; | |
13426 | end Validate_Address_Clauses; | |
13427 | ||
76a6b7c7 | 13428 | ----------------------------------------- |
13429 | -- Validate_Compile_Time_Warning_Error -- | |
13430 | ----------------------------------------- | |
13431 | ||
13432 | procedure Validate_Compile_Time_Warning_Error (N : Node_Id) is | |
13433 | begin | |
13434 | Compile_Time_Warnings_Errors.Append | |
13435 | (New_Val => CTWE_Entry'(Eloc => Sloc (N), | |
13436 | Scope => Current_Scope, | |
13437 | Prag => N)); | |
13438 | end Validate_Compile_Time_Warning_Error; | |
13439 | ||
13440 | ------------------------------------------ | |
13441 | -- Validate_Compile_Time_Warning_Errors -- | |
13442 | ------------------------------------------ | |
13443 | ||
13444 | procedure Validate_Compile_Time_Warning_Errors is | |
13445 | procedure Set_Scope (S : Entity_Id); | |
13446 | -- Install all enclosing scopes of S along with S itself | |
13447 | ||
13448 | procedure Unset_Scope (S : Entity_Id); | |
13449 | -- Uninstall all enclosing scopes of S along with S itself | |
13450 | ||
13451 | --------------- | |
13452 | -- Set_Scope -- | |
13453 | --------------- | |
13454 | ||
13455 | procedure Set_Scope (S : Entity_Id) is | |
13456 | begin | |
13457 | if S /= Standard_Standard then | |
13458 | Set_Scope (Scope (S)); | |
13459 | end if; | |
13460 | ||
13461 | Push_Scope (S); | |
13462 | end Set_Scope; | |
13463 | ||
13464 | ----------------- | |
13465 | -- Unset_Scope -- | |
13466 | ----------------- | |
13467 | ||
13468 | procedure Unset_Scope (S : Entity_Id) is | |
13469 | begin | |
13470 | if S /= Standard_Standard then | |
13471 | Unset_Scope (Scope (S)); | |
13472 | end if; | |
13473 | ||
13474 | Pop_Scope; | |
13475 | end Unset_Scope; | |
13476 | ||
13477 | -- Start of processing for Validate_Compile_Time_Warning_Errors | |
13478 | ||
13479 | begin | |
13480 | Expander_Mode_Save_And_Set (False); | |
13481 | In_Compile_Time_Warning_Or_Error := True; | |
13482 | ||
13483 | for N in Compile_Time_Warnings_Errors.First .. | |
13484 | Compile_Time_Warnings_Errors.Last | |
13485 | loop | |
13486 | declare | |
13487 | T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N); | |
13488 | ||
13489 | begin | |
13490 | Set_Scope (T.Scope); | |
13491 | Reset_Analyzed_Flags (T.Prag); | |
13492 | Process_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc); | |
13493 | Unset_Scope (T.Scope); | |
13494 | end; | |
13495 | end loop; | |
13496 | ||
13497 | In_Compile_Time_Warning_Or_Error := False; | |
13498 | Expander_Mode_Restore; | |
13499 | end Validate_Compile_Time_Warning_Errors; | |
13500 | ||
7717ea00 | 13501 | --------------------------- |
13502 | -- Validate_Independence -- | |
13503 | --------------------------- | |
13504 | ||
13505 | procedure Validate_Independence is | |
13506 | SU : constant Uint := UI_From_Int (System_Storage_Unit); | |
13507 | N : Node_Id; | |
13508 | E : Entity_Id; | |
13509 | IC : Boolean; | |
13510 | Comp : Entity_Id; | |
13511 | Addr : Node_Id; | |
13512 | P : Node_Id; | |
13513 | ||
13514 | procedure Check_Array_Type (Atyp : Entity_Id); | |
13515 | -- Checks if the array type Atyp has independent components, and | |
13516 | -- if not, outputs an appropriate set of error messages. | |
13517 | ||
13518 | procedure No_Independence; | |
13519 | -- Output message that independence cannot be guaranteed | |
13520 | ||
13521 | function OK_Component (C : Entity_Id) return Boolean; | |
13522 | -- Checks one component to see if it is independently accessible, and | |
13523 | -- if so yields True, otherwise yields False if independent access | |
13524 | -- cannot be guaranteed. This is a conservative routine, it only | |
13525 | -- returns True if it knows for sure, it returns False if it knows | |
13526 | -- there is a problem, or it cannot be sure there is no problem. | |
13527 | ||
13528 | procedure Reason_Bad_Component (C : Entity_Id); | |
13529 | -- Outputs continuation message if a reason can be determined for | |
13530 | -- the component C being bad. | |
13531 | ||
13532 | ---------------------- | |
13533 | -- Check_Array_Type -- | |
13534 | ---------------------- | |
13535 | ||
13536 | procedure Check_Array_Type (Atyp : Entity_Id) is | |
13537 | Ctyp : constant Entity_Id := Component_Type (Atyp); | |
13538 | ||
13539 | begin | |
13540 | -- OK if no alignment clause, no pack, and no component size | |
13541 | ||
13542 | if not Has_Component_Size_Clause (Atyp) | |
13543 | and then not Has_Alignment_Clause (Atyp) | |
13544 | and then not Is_Packed (Atyp) | |
13545 | then | |
13546 | return; | |
13547 | end if; | |
13548 | ||
aa0a69ab | 13549 | -- Case of component size is greater than or equal to 64 and the |
13550 | -- alignment of the array is at least as large as the alignment | |
13551 | -- of the component. We are definitely OK in this situation. | |
13552 | ||
13553 | if Known_Component_Size (Atyp) | |
13554 | and then Component_Size (Atyp) >= 64 | |
13555 | and then Known_Alignment (Atyp) | |
13556 | and then Known_Alignment (Ctyp) | |
13557 | and then Alignment (Atyp) >= Alignment (Ctyp) | |
13558 | then | |
13559 | return; | |
13560 | end if; | |
13561 | ||
7717ea00 | 13562 | -- Check actual component size |
13563 | ||
13564 | if not Known_Component_Size (Atyp) | |
13565 | or else not (Addressable (Component_Size (Atyp)) | |
aa0a69ab | 13566 | and then Component_Size (Atyp) < 64) |
7717ea00 | 13567 | or else Component_Size (Atyp) mod Esize (Ctyp) /= 0 |
13568 | then | |
13569 | No_Independence; | |
13570 | ||
13571 | -- Bad component size, check reason | |
13572 | ||
13573 | if Has_Component_Size_Clause (Atyp) then | |
b9e61b2a | 13574 | P := Get_Attribute_Definition_Clause |
13575 | (Atyp, Attribute_Component_Size); | |
7717ea00 | 13576 | |
13577 | if Present (P) then | |
13578 | Error_Msg_Sloc := Sloc (P); | |
13579 | Error_Msg_N ("\because of Component_Size clause#", N); | |
13580 | return; | |
13581 | end if; | |
13582 | end if; | |
13583 | ||
13584 | if Is_Packed (Atyp) then | |
13585 | P := Get_Rep_Pragma (Atyp, Name_Pack); | |
13586 | ||
13587 | if Present (P) then | |
13588 | Error_Msg_Sloc := Sloc (P); | |
13589 | Error_Msg_N ("\because of pragma Pack#", N); | |
13590 | return; | |
13591 | end if; | |
13592 | end if; | |
13593 | ||
13594 | -- No reason found, just return | |
13595 | ||
13596 | return; | |
13597 | end if; | |
13598 | ||
13599 | -- Array type is OK independence-wise | |
13600 | ||
13601 | return; | |
13602 | end Check_Array_Type; | |
13603 | ||
13604 | --------------------- | |
13605 | -- No_Independence -- | |
13606 | --------------------- | |
13607 | ||
13608 | procedure No_Independence is | |
13609 | begin | |
ddccc924 | 13610 | if Pragma_Name (N) = Name_Independent then |
18393965 | 13611 | Error_Msg_NE ("independence cannot be guaranteed for&", N, E); |
7717ea00 | 13612 | else |
13613 | Error_Msg_NE | |
13614 | ("independent components cannot be guaranteed for&", N, E); | |
13615 | end if; | |
13616 | end No_Independence; | |
13617 | ||
13618 | ------------------ | |
13619 | -- OK_Component -- | |
13620 | ------------------ | |
13621 | ||
13622 | function OK_Component (C : Entity_Id) return Boolean is | |
13623 | Rec : constant Entity_Id := Scope (C); | |
13624 | Ctyp : constant Entity_Id := Etype (C); | |
13625 | ||
13626 | begin | |
13627 | -- OK if no component clause, no Pack, and no alignment clause | |
13628 | ||
13629 | if No (Component_Clause (C)) | |
13630 | and then not Is_Packed (Rec) | |
13631 | and then not Has_Alignment_Clause (Rec) | |
13632 | then | |
13633 | return True; | |
13634 | end if; | |
13635 | ||
13636 | -- Here we look at the actual component layout. A component is | |
13637 | -- addressable if its size is a multiple of the Esize of the | |
13638 | -- component type, and its starting position in the record has | |
13639 | -- appropriate alignment, and the record itself has appropriate | |
13640 | -- alignment to guarantee the component alignment. | |
13641 | ||
13642 | -- Make sure sizes are static, always assume the worst for any | |
13643 | -- cases where we cannot check static values. | |
13644 | ||
13645 | if not (Known_Static_Esize (C) | |
b9e61b2a | 13646 | and then |
13647 | Known_Static_Esize (Ctyp)) | |
7717ea00 | 13648 | then |
13649 | return False; | |
13650 | end if; | |
13651 | ||
13652 | -- Size of component must be addressable or greater than 64 bits | |
13653 | -- and a multiple of bytes. | |
13654 | ||
b9e61b2a | 13655 | if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then |
7717ea00 | 13656 | return False; |
13657 | end if; | |
13658 | ||
13659 | -- Check size is proper multiple | |
13660 | ||
13661 | if Esize (C) mod Esize (Ctyp) /= 0 then | |
13662 | return False; | |
13663 | end if; | |
13664 | ||
13665 | -- Check alignment of component is OK | |
13666 | ||
13667 | if not Known_Component_Bit_Offset (C) | |
13668 | or else Component_Bit_Offset (C) < Uint_0 | |
13669 | or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0 | |
13670 | then | |
13671 | return False; | |
13672 | end if; | |
13673 | ||
13674 | -- Check alignment of record type is OK | |
13675 | ||
13676 | if not Known_Alignment (Rec) | |
13677 | or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0 | |
13678 | then | |
13679 | return False; | |
13680 | end if; | |
13681 | ||
13682 | -- All tests passed, component is addressable | |
13683 | ||
13684 | return True; | |
13685 | end OK_Component; | |
13686 | ||
13687 | -------------------------- | |
13688 | -- Reason_Bad_Component -- | |
13689 | -------------------------- | |
13690 | ||
13691 | procedure Reason_Bad_Component (C : Entity_Id) is | |
13692 | Rec : constant Entity_Id := Scope (C); | |
13693 | Ctyp : constant Entity_Id := Etype (C); | |
13694 | ||
13695 | begin | |
13696 | -- If component clause present assume that's the problem | |
13697 | ||
13698 | if Present (Component_Clause (C)) then | |
13699 | Error_Msg_Sloc := Sloc (Component_Clause (C)); | |
13700 | Error_Msg_N ("\because of Component_Clause#", N); | |
13701 | return; | |
13702 | end if; | |
13703 | ||
13704 | -- If pragma Pack clause present, assume that's the problem | |
13705 | ||
13706 | if Is_Packed (Rec) then | |
13707 | P := Get_Rep_Pragma (Rec, Name_Pack); | |
13708 | ||
13709 | if Present (P) then | |
13710 | Error_Msg_Sloc := Sloc (P); | |
13711 | Error_Msg_N ("\because of pragma Pack#", N); | |
13712 | return; | |
13713 | end if; | |
13714 | end if; | |
13715 | ||
13716 | -- See if record has bad alignment clause | |
13717 | ||
13718 | if Has_Alignment_Clause (Rec) | |
13719 | and then Known_Alignment (Rec) | |
13720 | and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0 | |
13721 | then | |
13722 | P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment); | |
13723 | ||
13724 | if Present (P) then | |
13725 | Error_Msg_Sloc := Sloc (P); | |
13726 | Error_Msg_N ("\because of Alignment clause#", N); | |
13727 | end if; | |
13728 | end if; | |
13729 | ||
13730 | -- Couldn't find a reason, so return without a message | |
13731 | ||
13732 | return; | |
13733 | end Reason_Bad_Component; | |
13734 | ||
13735 | -- Start of processing for Validate_Independence | |
13736 | ||
13737 | begin | |
13738 | for J in Independence_Checks.First .. Independence_Checks.Last loop | |
13739 | N := Independence_Checks.Table (J).N; | |
13740 | E := Independence_Checks.Table (J).E; | |
ddccc924 | 13741 | IC := Pragma_Name (N) = Name_Independent_Components; |
7717ea00 | 13742 | |
13743 | -- Deal with component case | |
13744 | ||
13745 | if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then | |
13746 | if not OK_Component (E) then | |
13747 | No_Independence; | |
13748 | Reason_Bad_Component (E); | |
13749 | goto Continue; | |
13750 | end if; | |
13751 | end if; | |
13752 | ||
13753 | -- Deal with record with Independent_Components | |
13754 | ||
13755 | if IC and then Is_Record_Type (E) then | |
13756 | Comp := First_Component_Or_Discriminant (E); | |
13757 | while Present (Comp) loop | |
13758 | if not OK_Component (Comp) then | |
13759 | No_Independence; | |
13760 | Reason_Bad_Component (Comp); | |
13761 | goto Continue; | |
13762 | end if; | |
13763 | ||
13764 | Next_Component_Or_Discriminant (Comp); | |
13765 | end loop; | |
13766 | end if; | |
13767 | ||
13768 | -- Deal with address clause case | |
13769 | ||
13770 | if Is_Object (E) then | |
13771 | Addr := Address_Clause (E); | |
13772 | ||
13773 | if Present (Addr) then | |
13774 | No_Independence; | |
13775 | Error_Msg_Sloc := Sloc (Addr); | |
13776 | Error_Msg_N ("\because of Address clause#", N); | |
13777 | goto Continue; | |
13778 | end if; | |
13779 | end if; | |
13780 | ||
13781 | -- Deal with independent components for array type | |
13782 | ||
13783 | if IC and then Is_Array_Type (E) then | |
13784 | Check_Array_Type (E); | |
13785 | end if; | |
13786 | ||
13787 | -- Deal with independent components for array object | |
13788 | ||
13789 | if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then | |
13790 | Check_Array_Type (Etype (E)); | |
13791 | end if; | |
13792 | ||
13793 | <<Continue>> null; | |
13794 | end loop; | |
13795 | end Validate_Independence; | |
13796 | ||
b3f8228a | 13797 | ------------------------------ |
13798 | -- Validate_Iterable_Aspect -- | |
13799 | ------------------------------ | |
13800 | ||
13801 | procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is | |
3061ffde | 13802 | Assoc : Node_Id; |
13803 | Expr : Node_Id; | |
b3f8228a | 13804 | |
bde03454 | 13805 | Prim : Node_Id; |
a9f5fea7 | 13806 | Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ); |
b3f8228a | 13807 | |
13808 | First_Id : Entity_Id; | |
13809 | Next_Id : Entity_Id; | |
13810 | Has_Element_Id : Entity_Id; | |
13811 | Element_Id : Entity_Id; | |
13812 | ||
b3f8228a | 13813 | begin |
9698629c | 13814 | -- If previous error aspect is unusable |
a9f5fea7 | 13815 | |
13816 | if Cursor = Any_Type then | |
3061ffde | 13817 | return; |
13818 | end if; | |
b3f8228a | 13819 | |
13820 | First_Id := Empty; | |
13821 | Next_Id := Empty; | |
13822 | Has_Element_Id := Empty; | |
32de816b | 13823 | Element_Id := Empty; |
b3f8228a | 13824 | |
13825 | -- Each expression must resolve to a function with the proper signature | |
13826 | ||
13827 | Assoc := First (Component_Associations (Expression (ASN))); | |
13828 | while Present (Assoc) loop | |
13829 | Expr := Expression (Assoc); | |
13830 | Analyze (Expr); | |
13831 | ||
b3f8228a | 13832 | Prim := First (Choices (Assoc)); |
bde03454 | 13833 | |
f02a9a9a | 13834 | if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then |
b3f8228a | 13835 | Error_Msg_N ("illegal name in association", Prim); |
13836 | ||
13837 | elsif Chars (Prim) = Name_First then | |
3061ffde | 13838 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First); |
b3f8228a | 13839 | First_Id := Entity (Expr); |
b3f8228a | 13840 | |
13841 | elsif Chars (Prim) = Name_Next then | |
3061ffde | 13842 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next); |
b3f8228a | 13843 | Next_Id := Entity (Expr); |
b3f8228a | 13844 | |
13845 | elsif Chars (Prim) = Name_Has_Element then | |
3061ffde | 13846 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element); |
b3f8228a | 13847 | Has_Element_Id := Entity (Expr); |
bde03454 | 13848 | |
b3f8228a | 13849 | elsif Chars (Prim) = Name_Element then |
3061ffde | 13850 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element); |
b3f8228a | 13851 | Element_Id := Entity (Expr); |
b3f8228a | 13852 | |
13853 | else | |
13854 | Error_Msg_N ("invalid name for iterable function", Prim); | |
13855 | end if; | |
13856 | ||
13857 | Next (Assoc); | |
13858 | end loop; | |
13859 | ||
13860 | if No (First_Id) then | |
3061ffde | 13861 | Error_Msg_N ("match for First primitive not found", ASN); |
b3f8228a | 13862 | |
13863 | elsif No (Next_Id) then | |
3061ffde | 13864 | Error_Msg_N ("match for Next primitive not found", ASN); |
b3f8228a | 13865 | |
13866 | elsif No (Has_Element_Id) then | |
3061ffde | 13867 | Error_Msg_N ("match for Has_Element primitive not found", ASN); |
13868 | ||
13869 | elsif No (Element_Id) then | |
13870 | null; -- Optional. | |
b3f8228a | 13871 | end if; |
13872 | end Validate_Iterable_Aspect; | |
13873 | ||
d6f39728 | 13874 | ----------------------------------- |
13875 | -- Validate_Unchecked_Conversion -- | |
13876 | ----------------------------------- | |
13877 | ||
13878 | procedure Validate_Unchecked_Conversion | |
13879 | (N : Node_Id; | |
13880 | Act_Unit : Entity_Id) | |
13881 | is | |
13882 | Source : Entity_Id; | |
13883 | Target : Entity_Id; | |
13884 | Vnode : Node_Id; | |
13885 | ||
13886 | begin | |
13887 | -- Obtain source and target types. Note that we call Ancestor_Subtype | |
13888 | -- here because the processing for generic instantiation always makes | |
13889 | -- subtypes, and we want the original frozen actual types. | |
13890 | ||
13891 | -- If we are dealing with private types, then do the check on their | |
13892 | -- fully declared counterparts if the full declarations have been | |
39a0c1d3 | 13893 | -- encountered (they don't have to be visible, but they must exist). |
d6f39728 | 13894 | |
13895 | Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit))); | |
13896 | ||
13897 | if Is_Private_Type (Source) | |
13898 | and then Present (Underlying_Type (Source)) | |
13899 | then | |
13900 | Source := Underlying_Type (Source); | |
13901 | end if; | |
13902 | ||
13903 | Target := Ancestor_Subtype (Etype (Act_Unit)); | |
13904 | ||
fdd294d1 | 13905 | -- If either type is generic, the instantiation happens within a generic |
95deda50 | 13906 | -- unit, and there is nothing to check. The proper check will happen |
13907 | -- when the enclosing generic is instantiated. | |
d6f39728 | 13908 | |
13909 | if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then | |
13910 | return; | |
13911 | end if; | |
13912 | ||
13913 | if Is_Private_Type (Target) | |
13914 | and then Present (Underlying_Type (Target)) | |
13915 | then | |
13916 | Target := Underlying_Type (Target); | |
13917 | end if; | |
13918 | ||
0924014e | 13919 | -- Source may be unconstrained array, but not target, except in relaxed |
13920 | -- semantics mode. | |
d6f39728 | 13921 | |
0924014e | 13922 | if Is_Array_Type (Target) |
13923 | and then not Is_Constrained (Target) | |
13924 | and then not Relaxed_RM_Semantics | |
13925 | then | |
d6f39728 | 13926 | Error_Msg_N |
13927 | ("unchecked conversion to unconstrained array not allowed", N); | |
13928 | return; | |
13929 | end if; | |
13930 | ||
fbc67f84 | 13931 | -- Warn if conversion between two different convention pointers |
13932 | ||
13933 | if Is_Access_Type (Target) | |
13934 | and then Is_Access_Type (Source) | |
13935 | and then Convention (Target) /= Convention (Source) | |
13936 | and then Warn_On_Unchecked_Conversion | |
13937 | then | |
74c7ae52 | 13938 | -- Give warnings for subprogram pointers only on most targets |
fdd294d1 | 13939 | |
13940 | if Is_Access_Subprogram_Type (Target) | |
13941 | or else Is_Access_Subprogram_Type (Source) | |
fdd294d1 | 13942 | then |
13943 | Error_Msg_N | |
cb97ae5c | 13944 | ("?z?conversion between pointers with different conventions!", |
1e3532e7 | 13945 | N); |
fdd294d1 | 13946 | end if; |
fbc67f84 | 13947 | end if; |
13948 | ||
3062c401 | 13949 | -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a |
13950 | -- warning when compiling GNAT-related sources. | |
13951 | ||
13952 | if Warn_On_Unchecked_Conversion | |
13953 | and then not In_Predefined_Unit (N) | |
13954 | and then RTU_Loaded (Ada_Calendar) | |
f02a9a9a | 13955 | and then (Chars (Source) = Name_Time |
13956 | or else | |
13957 | Chars (Target) = Name_Time) | |
3062c401 | 13958 | then |
13959 | -- If Ada.Calendar is loaded and the name of one of the operands is | |
13960 | -- Time, there is a good chance that this is Ada.Calendar.Time. | |
13961 | ||
13962 | declare | |
f02a9a9a | 13963 | Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time)); |
3062c401 | 13964 | begin |
13965 | pragma Assert (Present (Calendar_Time)); | |
13966 | ||
b9e61b2a | 13967 | if Source = Calendar_Time or else Target = Calendar_Time then |
3062c401 | 13968 | Error_Msg_N |
f02a9a9a | 13969 | ("?z?representation of 'Time values may change between " |
13970 | & "'G'N'A'T versions", N); | |
3062c401 | 13971 | end if; |
13972 | end; | |
13973 | end if; | |
13974 | ||
fdd294d1 | 13975 | -- Make entry in unchecked conversion table for later processing by |
13976 | -- Validate_Unchecked_Conversions, which will check sizes and alignments | |
3ff5e35d | 13977 | -- (using values set by the back end where possible). This is only done |
fdd294d1 | 13978 | -- if the appropriate warning is active. |
d6f39728 | 13979 | |
9dfe12ae | 13980 | if Warn_On_Unchecked_Conversion then |
13981 | Unchecked_Conversions.Append | |
86d32751 | 13982 | (New_Val => UC_Entry'(Eloc => Sloc (N), |
13983 | Source => Source, | |
13984 | Target => Target, | |
13985 | Act_Unit => Act_Unit)); | |
9dfe12ae | 13986 | |
f9906591 | 13987 | -- If both sizes are known statically now, then back-end annotation |
9dfe12ae | 13988 | -- is not required to do a proper check but if either size is not |
13989 | -- known statically, then we need the annotation. | |
13990 | ||
13991 | if Known_Static_RM_Size (Source) | |
1e3532e7 | 13992 | and then |
13993 | Known_Static_RM_Size (Target) | |
9dfe12ae | 13994 | then |
13995 | null; | |
13996 | else | |
13997 | Back_Annotate_Rep_Info := True; | |
13998 | end if; | |
13999 | end if; | |
d6f39728 | 14000 | |
fdd294d1 | 14001 | -- If unchecked conversion to access type, and access type is declared |
95deda50 | 14002 | -- in the same unit as the unchecked conversion, then set the flag |
14003 | -- No_Strict_Aliasing (no strict aliasing is implicit here) | |
28ed91d4 | 14004 | |
14005 | if Is_Access_Type (Target) and then | |
14006 | In_Same_Source_Unit (Target, N) | |
14007 | then | |
14008 | Set_No_Strict_Aliasing (Implementation_Base_Type (Target)); | |
14009 | end if; | |
3d875462 | 14010 | |
95deda50 | 14011 | -- Generate N_Validate_Unchecked_Conversion node for back end in case |
14012 | -- the back end needs to perform special validation checks. | |
3d875462 | 14013 | |
95deda50 | 14014 | -- Shouldn't this be in Exp_Ch13, since the check only gets done if we |
14015 | -- have full expansion and the back end is called ??? | |
3d875462 | 14016 | |
14017 | Vnode := | |
14018 | Make_Validate_Unchecked_Conversion (Sloc (N)); | |
14019 | Set_Source_Type (Vnode, Source); | |
14020 | Set_Target_Type (Vnode, Target); | |
14021 | ||
fdd294d1 | 14022 | -- If the unchecked conversion node is in a list, just insert before it. |
14023 | -- If not we have some strange case, not worth bothering about. | |
3d875462 | 14024 | |
14025 | if Is_List_Member (N) then | |
d6f39728 | 14026 | Insert_After (N, Vnode); |
14027 | end if; | |
14028 | end Validate_Unchecked_Conversion; | |
14029 | ||
14030 | ------------------------------------ | |
14031 | -- Validate_Unchecked_Conversions -- | |
14032 | ------------------------------------ | |
14033 | ||
14034 | procedure Validate_Unchecked_Conversions is | |
14035 | begin | |
14036 | for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop | |
14037 | declare | |
14038 | T : UC_Entry renames Unchecked_Conversions.Table (N); | |
14039 | ||
e13b1635 | 14040 | Act_Unit : constant Entity_Id := T.Act_Unit; |
86d32751 | 14041 | Eloc : constant Source_Ptr := T.Eloc; |
14042 | Source : constant Entity_Id := T.Source; | |
14043 | Target : constant Entity_Id := T.Target; | |
d6f39728 | 14044 | |
44705307 | 14045 | Source_Siz : Uint; |
14046 | Target_Siz : Uint; | |
d6f39728 | 14047 | |
14048 | begin | |
86d32751 | 14049 | -- Skip if function marked as warnings off |
14050 | ||
14051 | if Warnings_Off (Act_Unit) then | |
14052 | goto Continue; | |
14053 | end if; | |
14054 | ||
fdd294d1 | 14055 | -- This validation check, which warns if we have unequal sizes for |
14056 | -- unchecked conversion, and thus potentially implementation | |
d6f39728 | 14057 | -- dependent semantics, is one of the few occasions on which we |
fdd294d1 | 14058 | -- use the official RM size instead of Esize. See description in |
14059 | -- Einfo "Handling of Type'Size Values" for details. | |
d6f39728 | 14060 | |
f15731c4 | 14061 | if Serious_Errors_Detected = 0 |
d6f39728 | 14062 | and then Known_Static_RM_Size (Source) |
14063 | and then Known_Static_RM_Size (Target) | |
f25f4252 | 14064 | |
14065 | -- Don't do the check if warnings off for either type, note the | |
14066 | -- deliberate use of OR here instead of OR ELSE to get the flag | |
14067 | -- Warnings_Off_Used set for both types if appropriate. | |
14068 | ||
14069 | and then not (Has_Warnings_Off (Source) | |
14070 | or | |
14071 | Has_Warnings_Off (Target)) | |
d6f39728 | 14072 | then |
14073 | Source_Siz := RM_Size (Source); | |
14074 | Target_Siz := RM_Size (Target); | |
14075 | ||
14076 | if Source_Siz /= Target_Siz then | |
299480f9 | 14077 | Error_Msg |
cb97ae5c | 14078 | ("?z?types for unchecked conversion have different sizes!", |
299480f9 | 14079 | Eloc); |
d6f39728 | 14080 | |
14081 | if All_Errors_Mode then | |
14082 | Error_Msg_Name_1 := Chars (Source); | |
14083 | Error_Msg_Uint_1 := Source_Siz; | |
14084 | Error_Msg_Name_2 := Chars (Target); | |
14085 | Error_Msg_Uint_2 := Target_Siz; | |
cb97ae5c | 14086 | Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc); |
d6f39728 | 14087 | |
14088 | Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz); | |
14089 | ||
14090 | if Is_Discrete_Type (Source) | |
b9e61b2a | 14091 | and then |
14092 | Is_Discrete_Type (Target) | |
d6f39728 | 14093 | then |
14094 | if Source_Siz > Target_Siz then | |
299480f9 | 14095 | Error_Msg |
cb97ae5c | 14096 | ("\?z?^ high order bits of source will " |
1e3532e7 | 14097 | & "be ignored!", Eloc); |
d6f39728 | 14098 | |
9dfe12ae | 14099 | elsif Is_Unsigned_Type (Source) then |
299480f9 | 14100 | Error_Msg |
cb97ae5c | 14101 | ("\?z?source will be extended with ^ high order " |
1581f2d7 | 14102 | & "zero bits!", Eloc); |
d6f39728 | 14103 | |
14104 | else | |
299480f9 | 14105 | Error_Msg |
cb97ae5c | 14106 | ("\?z?source will be extended with ^ high order " |
1e3532e7 | 14107 | & "sign bits!", Eloc); |
d6f39728 | 14108 | end if; |
14109 | ||
14110 | elsif Source_Siz < Target_Siz then | |
14111 | if Is_Discrete_Type (Target) then | |
14112 | if Bytes_Big_Endian then | |
299480f9 | 14113 | Error_Msg |
cb97ae5c | 14114 | ("\?z?target value will include ^ undefined " |
1e3532e7 | 14115 | & "low order bits!", Eloc); |
d6f39728 | 14116 | else |
299480f9 | 14117 | Error_Msg |
cb97ae5c | 14118 | ("\?z?target value will include ^ undefined " |
1e3532e7 | 14119 | & "high order bits!", Eloc); |
d6f39728 | 14120 | end if; |
14121 | ||
14122 | else | |
299480f9 | 14123 | Error_Msg |
cb97ae5c | 14124 | ("\?z?^ trailing bits of target value will be " |
1e3532e7 | 14125 | & "undefined!", Eloc); |
d6f39728 | 14126 | end if; |
14127 | ||
14128 | else pragma Assert (Source_Siz > Target_Siz); | |
0388e54e | 14129 | if Is_Discrete_Type (Source) then |
14130 | if Bytes_Big_Endian then | |
14131 | Error_Msg | |
14132 | ("\?z?^ low order bits of source will be " | |
14133 | & "ignored!", Eloc); | |
14134 | else | |
14135 | Error_Msg | |
14136 | ("\?z?^ high order bits of source will be " | |
14137 | & "ignored!", Eloc); | |
14138 | end if; | |
14139 | ||
14140 | else | |
14141 | Error_Msg | |
14142 | ("\?z?^ trailing bits of source will be " | |
14143 | & "ignored!", Eloc); | |
14144 | end if; | |
d6f39728 | 14145 | end if; |
14146 | end if; | |
d6f39728 | 14147 | end if; |
14148 | end if; | |
14149 | ||
14150 | -- If both types are access types, we need to check the alignment. | |
14151 | -- If the alignment of both is specified, we can do it here. | |
14152 | ||
f15731c4 | 14153 | if Serious_Errors_Detected = 0 |
2a10e737 | 14154 | and then Is_Access_Type (Source) |
14155 | and then Is_Access_Type (Target) | |
d6f39728 | 14156 | and then Target_Strict_Alignment |
14157 | and then Present (Designated_Type (Source)) | |
14158 | and then Present (Designated_Type (Target)) | |
14159 | then | |
14160 | declare | |
14161 | D_Source : constant Entity_Id := Designated_Type (Source); | |
14162 | D_Target : constant Entity_Id := Designated_Type (Target); | |
14163 | ||
14164 | begin | |
14165 | if Known_Alignment (D_Source) | |
b9e61b2a | 14166 | and then |
14167 | Known_Alignment (D_Target) | |
d6f39728 | 14168 | then |
14169 | declare | |
14170 | Source_Align : constant Uint := Alignment (D_Source); | |
14171 | Target_Align : constant Uint := Alignment (D_Target); | |
14172 | ||
14173 | begin | |
14174 | if Source_Align < Target_Align | |
14175 | and then not Is_Tagged_Type (D_Source) | |
f25f4252 | 14176 | |
14177 | -- Suppress warning if warnings suppressed on either | |
14178 | -- type or either designated type. Note the use of | |
14179 | -- OR here instead of OR ELSE. That is intentional, | |
14180 | -- we would like to set flag Warnings_Off_Used in | |
14181 | -- all types for which warnings are suppressed. | |
14182 | ||
14183 | and then not (Has_Warnings_Off (D_Source) | |
14184 | or | |
14185 | Has_Warnings_Off (D_Target) | |
14186 | or | |
14187 | Has_Warnings_Off (Source) | |
14188 | or | |
14189 | Has_Warnings_Off (Target)) | |
d6f39728 | 14190 | then |
d6f39728 | 14191 | Error_Msg_Uint_1 := Target_Align; |
14192 | Error_Msg_Uint_2 := Source_Align; | |
299480f9 | 14193 | Error_Msg_Node_1 := D_Target; |
d6f39728 | 14194 | Error_Msg_Node_2 := D_Source; |
299480f9 | 14195 | Error_Msg |
cb97ae5c | 14196 | ("?z?alignment of & (^) is stricter than " |
1e3532e7 | 14197 | & "alignment of & (^)!", Eloc); |
f25f4252 | 14198 | Error_Msg |
cb97ae5c | 14199 | ("\?z?resulting access value may have invalid " |
1e3532e7 | 14200 | & "alignment!", Eloc); |
d6f39728 | 14201 | end if; |
14202 | end; | |
14203 | end if; | |
14204 | end; | |
14205 | end if; | |
14206 | end; | |
86d32751 | 14207 | |
14208 | <<Continue>> | |
14209 | null; | |
d6f39728 | 14210 | end loop; |
14211 | end Validate_Unchecked_Conversions; | |
14212 | ||
d6f39728 | 14213 | end Sem_Ch13; |