]>
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 | -- -- | |
60a4a5af | 9 | -- Copyright (C) 1992-2015, 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; |
d00681a7 | 33 | with Exp_Disp; use Exp_Disp; |
d6f39728 | 34 | with Exp_Tss; use Exp_Tss; |
35 | with Exp_Util; use Exp_Util; | |
37c6552c | 36 | with Freeze; use Freeze; |
f9e26ff7 | 37 | with Ghost; use Ghost; |
d6f39728 | 38 | with Lib; use Lib; |
83f8f0a6 | 39 | with Lib.Xref; use Lib.Xref; |
15ebb600 | 40 | with Namet; use Namet; |
d6f39728 | 41 | with Nlists; use Nlists; |
42 | with Nmake; use Nmake; | |
43 | with Opt; use Opt; | |
e0521a36 | 44 | with Restrict; use Restrict; |
45 | with Rident; use Rident; | |
d6f39728 | 46 | with Rtsfind; use Rtsfind; |
47 | with Sem; use Sem; | |
d60c9ff7 | 48 | with Sem_Aux; use Sem_Aux; |
be9124d0 | 49 | with Sem_Case; use Sem_Case; |
40ca69b9 | 50 | with Sem_Ch3; use Sem_Ch3; |
490beba6 | 51 | with Sem_Ch6; use Sem_Ch6; |
d6f39728 | 52 | with Sem_Ch8; use Sem_Ch8; |
85696508 | 53 | with Sem_Dim; use Sem_Dim; |
85377c9b | 54 | with Sem_Disp; use Sem_Disp; |
d6f39728 | 55 | with Sem_Eval; use Sem_Eval; |
51ea9c94 | 56 | with Sem_Prag; use Sem_Prag; |
d6f39728 | 57 | with Sem_Res; use Sem_Res; |
58 | with Sem_Type; use Sem_Type; | |
59 | with Sem_Util; use Sem_Util; | |
44e4341e | 60 | with Sem_Warn; use Sem_Warn; |
1e3c4ae6 | 61 | with Sinput; use Sinput; |
9dfe12ae | 62 | with Snames; use Snames; |
d6f39728 | 63 | with Stand; use Stand; |
64 | with Sinfo; use Sinfo; | |
5b5df4a9 | 65 | with Stringt; use Stringt; |
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 | |
eb66e842 | 104 | procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id); |
105 | -- If Typ has predicates (indicated by Has_Predicates being set for Typ), | |
106 | -- then either there are pragma Predicate entries on the rep chain for the | |
107 | -- type (note that Predicate aspects are converted to pragma Predicate), or | |
108 | -- there are inherited aspects from a parent type, or ancestor subtypes. | |
109 | -- This procedure builds the spec and body for the Predicate function that | |
110 | -- tests these predicates. N is the freeze node for the type. The spec of | |
111 | -- the function is inserted before the freeze node, and the body of the | |
112 | -- function is inserted after the freeze node. If the predicate expression | |
113 | -- has at least one Raise_Expression, then this procedure also builds the | |
114 | -- M version of the predicate function for use in membership tests. | |
115 | ||
6653b695 | 116 | procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id); |
117 | -- Called if both Storage_Pool and Storage_Size attribute definition | |
118 | -- clauses (SP and SS) are present for entity Ent. Issue error message. | |
119 | ||
d9f6a4ee | 120 | procedure Freeze_Entity_Checks (N : Node_Id); |
121 | -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity | |
122 | -- to generate appropriate semantic checks that are delayed until this | |
123 | -- point (they had to be delayed this long for cases of delayed aspects, | |
124 | -- e.g. analysis of statically predicated subtypes in choices, for which | |
5f067114 | 125 | -- we have to be sure the subtypes in question are frozen before checking). |
d9f6a4ee | 126 | |
d6f39728 | 127 | function Get_Alignment_Value (Expr : Node_Id) return Uint; |
128 | -- Given the expression for an alignment value, returns the corresponding | |
129 | -- Uint value. If the value is inappropriate, then error messages are | |
130 | -- posted as required, and a value of No_Uint is returned. | |
131 | ||
132 | function Is_Operational_Item (N : Node_Id) return Boolean; | |
1e3c4ae6 | 133 | -- A specification for a stream attribute is allowed before the full type |
134 | -- is declared, as explained in AI-00137 and the corrigendum. Attributes | |
135 | -- that do not specify a representation characteristic are operational | |
136 | -- attributes. | |
d6f39728 | 137 | |
3b23aaa0 | 138 | function Is_Predicate_Static |
139 | (Expr : Node_Id; | |
140 | Nam : Name_Id) return Boolean; | |
141 | -- Given predicate expression Expr, tests if Expr is predicate-static in | |
142 | -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type | |
143 | -- name in the predicate expression have been replaced by references to | |
144 | -- an identifier whose Chars field is Nam. This name is unique, so any | |
145 | -- identifier with Chars matching Nam must be a reference to the type. | |
146 | -- Returns True if the expression is predicate-static and False otherwise, | |
147 | -- but is not in the business of setting flags or issuing error messages. | |
148 | -- | |
149 | -- Only scalar types can have static predicates, so False is always | |
150 | -- returned for non-scalar types. | |
151 | -- | |
152 | -- Note: the RM seems to suggest that string types can also have static | |
153 | -- predicates. But that really makes lttle sense as very few useful | |
154 | -- predicates can be constructed for strings. Remember that: | |
155 | -- | |
156 | -- "ABC" < "DEF" | |
157 | -- | |
158 | -- is not a static expression. So even though the clearly faulty RM wording | |
159 | -- allows the following: | |
160 | -- | |
161 | -- subtype S is String with Static_Predicate => S < "DEF" | |
162 | -- | |
163 | -- We can't allow this, otherwise we have predicate-static applying to a | |
164 | -- larger class than static expressions, which was never intended. | |
165 | ||
44e4341e | 166 | procedure New_Stream_Subprogram |
d6f39728 | 167 | (N : Node_Id; |
168 | Ent : Entity_Id; | |
169 | Subp : Entity_Id; | |
9dfe12ae | 170 | Nam : TSS_Name_Type); |
44e4341e | 171 | -- Create a subprogram renaming of a given stream attribute to the |
172 | -- designated subprogram and then in the tagged case, provide this as a | |
d1a2e31b | 173 | -- primitive operation, or in the untagged case make an appropriate TSS |
44e4341e | 174 | -- entry. This is more properly an expansion activity than just semantics, |
d1a2e31b | 175 | -- but the presence of user-defined stream functions for limited types |
176 | -- is a legality check, which is why this takes place here rather than in | |
44e4341e | 177 | -- exp_ch13, where it was previously. Nam indicates the name of the TSS |
178 | -- function to be generated. | |
9dfe12ae | 179 | -- |
f15731c4 | 180 | -- To avoid elaboration anomalies with freeze nodes, for untagged types |
181 | -- we generate both a subprogram declaration and a subprogram renaming | |
182 | -- declaration, so that the attribute specification is handled as a | |
183 | -- renaming_as_body. For tagged types, the specification is one of the | |
184 | -- primitive specs. | |
185 | ||
3061ffde | 186 | procedure Resolve_Iterable_Operation |
187 | (N : Node_Id; | |
188 | Cursor : Entity_Id; | |
189 | Typ : Entity_Id; | |
190 | Nam : Name_Id); | |
191 | -- If the name of a primitive operation for an Iterable aspect is | |
192 | -- overloaded, resolve according to required signature. | |
193 | ||
b77e4501 | 194 | procedure Set_Biased |
195 | (E : Entity_Id; | |
196 | N : Node_Id; | |
197 | Msg : String; | |
198 | Biased : Boolean := True); | |
199 | -- If Biased is True, sets Has_Biased_Representation flag for E, and | |
200 | -- outputs a warning message at node N if Warn_On_Biased_Representation is | |
201 | -- is True. This warning inserts the string Msg to describe the construct | |
202 | -- causing biasing. | |
203 | ||
d6f39728 | 204 | ---------------------------------------------- |
205 | -- Table for Validate_Unchecked_Conversions -- | |
206 | ---------------------------------------------- | |
207 | ||
208 | -- The following table collects unchecked conversions for validation. | |
95deda50 | 209 | -- Entries are made by Validate_Unchecked_Conversion and then the call |
210 | -- to Validate_Unchecked_Conversions does the actual error checking and | |
211 | -- posting of warnings. The reason for this delayed processing is to take | |
212 | -- advantage of back-annotations of size and alignment values performed by | |
213 | -- the back end. | |
d6f39728 | 214 | |
95deda50 | 215 | -- Note: the reason we store a Source_Ptr value instead of a Node_Id is |
216 | -- that by the time Validate_Unchecked_Conversions is called, Sprint will | |
217 | -- already have modified all Sloc values if the -gnatD option is set. | |
299480f9 | 218 | |
d6f39728 | 219 | type UC_Entry is record |
86d32751 | 220 | Eloc : Source_Ptr; -- node used for posting warnings |
221 | Source : Entity_Id; -- source type for unchecked conversion | |
222 | Target : Entity_Id; -- target type for unchecked conversion | |
223 | Act_Unit : Entity_Id; -- actual function instantiated | |
d6f39728 | 224 | end record; |
225 | ||
226 | package Unchecked_Conversions is new Table.Table ( | |
227 | Table_Component_Type => UC_Entry, | |
228 | Table_Index_Type => Int, | |
229 | Table_Low_Bound => 1, | |
230 | Table_Initial => 50, | |
231 | Table_Increment => 200, | |
232 | Table_Name => "Unchecked_Conversions"); | |
233 | ||
83f8f0a6 | 234 | ---------------------------------------- |
235 | -- Table for Validate_Address_Clauses -- | |
236 | ---------------------------------------- | |
237 | ||
238 | -- If an address clause has the form | |
239 | ||
240 | -- for X'Address use Expr | |
241 | ||
95deda50 | 242 | -- where Expr is of the form Y'Address or recursively is a reference to a |
243 | -- constant of either of these forms, and X and Y are entities of objects, | |
244 | -- then if Y has a smaller alignment than X, that merits a warning about | |
245 | -- possible bad alignment. The following table collects address clauses of | |
246 | -- this kind. We put these in a table so that they can be checked after the | |
247 | -- back end has completed annotation of the alignments of objects, since we | |
248 | -- can catch more cases that way. | |
83f8f0a6 | 249 | |
250 | type Address_Clause_Check_Record is record | |
251 | N : Node_Id; | |
252 | -- The address clause | |
253 | ||
254 | X : Entity_Id; | |
255 | -- The entity of the object overlaying Y | |
256 | ||
257 | Y : Entity_Id; | |
258 | -- The entity of the object being overlaid | |
d6da7448 | 259 | |
260 | Off : Boolean; | |
6fb3c314 | 261 | -- Whether the address is offset within Y |
83f8f0a6 | 262 | end record; |
263 | ||
264 | package Address_Clause_Checks is new Table.Table ( | |
265 | Table_Component_Type => Address_Clause_Check_Record, | |
266 | Table_Index_Type => Int, | |
267 | Table_Low_Bound => 1, | |
268 | Table_Initial => 20, | |
269 | Table_Increment => 200, | |
270 | Table_Name => "Address_Clause_Checks"); | |
271 | ||
59ac57b5 | 272 | ----------------------------------------- |
273 | -- Adjust_Record_For_Reverse_Bit_Order -- | |
274 | ----------------------------------------- | |
275 | ||
276 | procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is | |
67278d60 | 277 | Comp : Node_Id; |
278 | CC : Node_Id; | |
59ac57b5 | 279 | |
280 | begin | |
67278d60 | 281 | -- Processing depends on version of Ada |
59ac57b5 | 282 | |
6797073f | 283 | -- For Ada 95, we just renumber bits within a storage unit. We do the |
568b0f6a | 284 | -- same for Ada 83 mode, since we recognize the Bit_Order attribute in |
ab19a652 | 285 | -- Ada 83, and are free to add this extension. |
6797073f | 286 | |
287 | if Ada_Version < Ada_2005 then | |
288 | Comp := First_Component_Or_Discriminant (R); | |
289 | while Present (Comp) loop | |
290 | CC := Component_Clause (Comp); | |
291 | ||
292 | -- If component clause is present, then deal with the non-default | |
293 | -- bit order case for Ada 95 mode. | |
294 | ||
295 | -- We only do this processing for the base type, and in fact that | |
296 | -- is important, since otherwise if there are record subtypes, we | |
297 | -- could reverse the bits once for each subtype, which is wrong. | |
298 | ||
b9e61b2a | 299 | if Present (CC) and then Ekind (R) = E_Record_Type then |
6797073f | 300 | declare |
301 | CFB : constant Uint := Component_Bit_Offset (Comp); | |
302 | CSZ : constant Uint := Esize (Comp); | |
303 | CLC : constant Node_Id := Component_Clause (Comp); | |
304 | Pos : constant Node_Id := Position (CLC); | |
305 | FB : constant Node_Id := First_Bit (CLC); | |
306 | ||
307 | Storage_Unit_Offset : constant Uint := | |
308 | CFB / System_Storage_Unit; | |
309 | ||
310 | Start_Bit : constant Uint := | |
311 | CFB mod System_Storage_Unit; | |
59ac57b5 | 312 | |
6797073f | 313 | begin |
314 | -- Cases where field goes over storage unit boundary | |
59ac57b5 | 315 | |
6797073f | 316 | if Start_Bit + CSZ > System_Storage_Unit then |
59ac57b5 | 317 | |
6797073f | 318 | -- Allow multi-byte field but generate warning |
59ac57b5 | 319 | |
6797073f | 320 | if Start_Bit mod System_Storage_Unit = 0 |
321 | and then CSZ mod System_Storage_Unit = 0 | |
322 | then | |
323 | Error_Msg_N | |
7a41db5b | 324 | ("info: multi-byte field specified with " |
325 | & "non-standard Bit_Order?V?", CLC); | |
31486bc0 | 326 | |
6797073f | 327 | if Bytes_Big_Endian then |
31486bc0 | 328 | Error_Msg_N |
7a41db5b | 329 | ("\bytes are not reversed " |
330 | & "(component is big-endian)?V?", CLC); | |
31486bc0 | 331 | else |
332 | Error_Msg_N | |
7a41db5b | 333 | ("\bytes are not reversed " |
334 | & "(component is little-endian)?V?", CLC); | |
31486bc0 | 335 | end if; |
59ac57b5 | 336 | |
6797073f | 337 | -- Do not allow non-contiguous field |
59ac57b5 | 338 | |
67278d60 | 339 | else |
6797073f | 340 | Error_Msg_N |
341 | ("attempt to specify non-contiguous field " | |
342 | & "not permitted", CLC); | |
343 | Error_Msg_N | |
344 | ("\caused by non-standard Bit_Order " | |
345 | & "specified", CLC); | |
346 | Error_Msg_N | |
347 | ("\consider possibility of using " | |
348 | & "Ada 2005 mode here", CLC); | |
349 | end if; | |
59ac57b5 | 350 | |
6797073f | 351 | -- Case where field fits in one storage unit |
59ac57b5 | 352 | |
6797073f | 353 | else |
354 | -- Give warning if suspicious component clause | |
59ac57b5 | 355 | |
6797073f | 356 | if Intval (FB) >= System_Storage_Unit |
357 | and then Warn_On_Reverse_Bit_Order | |
358 | then | |
359 | Error_Msg_N | |
7a41db5b | 360 | ("info: Bit_Order clause does not affect " & |
1e3532e7 | 361 | "byte ordering?V?", Pos); |
6797073f | 362 | Error_Msg_Uint_1 := |
363 | Intval (Pos) + Intval (FB) / | |
364 | System_Storage_Unit; | |
365 | Error_Msg_N | |
7a41db5b | 366 | ("info: position normalized to ^ before bit " & |
1e3532e7 | 367 | "order interpreted?V?", Pos); |
6797073f | 368 | end if; |
59ac57b5 | 369 | |
6797073f | 370 | -- Here is where we fix up the Component_Bit_Offset value |
371 | -- to account for the reverse bit order. Some examples of | |
372 | -- what needs to be done are: | |
bfa5a9d9 | 373 | |
6797073f | 374 | -- First_Bit .. Last_Bit Component_Bit_Offset |
375 | -- old new old new | |
59ac57b5 | 376 | |
6797073f | 377 | -- 0 .. 0 7 .. 7 0 7 |
378 | -- 0 .. 1 6 .. 7 0 6 | |
379 | -- 0 .. 2 5 .. 7 0 5 | |
380 | -- 0 .. 7 0 .. 7 0 4 | |
59ac57b5 | 381 | |
6797073f | 382 | -- 1 .. 1 6 .. 6 1 6 |
383 | -- 1 .. 4 3 .. 6 1 3 | |
384 | -- 4 .. 7 0 .. 3 4 0 | |
59ac57b5 | 385 | |
6797073f | 386 | -- The rule is that the first bit is is obtained by |
387 | -- subtracting the old ending bit from storage_unit - 1. | |
59ac57b5 | 388 | |
6797073f | 389 | Set_Component_Bit_Offset |
390 | (Comp, | |
391 | (Storage_Unit_Offset * System_Storage_Unit) + | |
392 | (System_Storage_Unit - 1) - | |
393 | (Start_Bit + CSZ - 1)); | |
59ac57b5 | 394 | |
6797073f | 395 | Set_Normalized_First_Bit |
396 | (Comp, | |
397 | Component_Bit_Offset (Comp) mod | |
398 | System_Storage_Unit); | |
399 | end if; | |
400 | end; | |
401 | end if; | |
402 | ||
403 | Next_Component_Or_Discriminant (Comp); | |
404 | end loop; | |
405 | ||
406 | -- For Ada 2005, we do machine scalar processing, as fully described In | |
407 | -- AI-133. This involves gathering all components which start at the | |
408 | -- same byte offset and processing them together. Same approach is still | |
409 | -- valid in later versions including Ada 2012. | |
410 | ||
411 | else | |
412 | declare | |
413 | Max_Machine_Scalar_Size : constant Uint := | |
414 | UI_From_Int | |
415 | (Standard_Long_Long_Integer_Size); | |
67278d60 | 416 | -- We use this as the maximum machine scalar size |
59ac57b5 | 417 | |
6797073f | 418 | Num_CC : Natural; |
419 | SSU : constant Uint := UI_From_Int (System_Storage_Unit); | |
59ac57b5 | 420 | |
6797073f | 421 | begin |
422 | -- This first loop through components does two things. First it | |
423 | -- deals with the case of components with component clauses whose | |
424 | -- length is greater than the maximum machine scalar size (either | |
425 | -- accepting them or rejecting as needed). Second, it counts the | |
426 | -- number of components with component clauses whose length does | |
427 | -- not exceed this maximum for later processing. | |
67278d60 | 428 | |
6797073f | 429 | Num_CC := 0; |
430 | Comp := First_Component_Or_Discriminant (R); | |
431 | while Present (Comp) loop | |
432 | CC := Component_Clause (Comp); | |
67278d60 | 433 | |
6797073f | 434 | if Present (CC) then |
435 | declare | |
1e3532e7 | 436 | Fbit : constant Uint := Static_Integer (First_Bit (CC)); |
437 | Lbit : constant Uint := Static_Integer (Last_Bit (CC)); | |
67278d60 | 438 | |
6797073f | 439 | begin |
b38e4131 | 440 | -- Case of component with last bit >= max machine scalar |
67278d60 | 441 | |
b38e4131 | 442 | if Lbit >= Max_Machine_Scalar_Size then |
67278d60 | 443 | |
b38e4131 | 444 | -- This is allowed only if first bit is zero, and |
445 | -- last bit + 1 is a multiple of storage unit size. | |
67278d60 | 446 | |
b38e4131 | 447 | if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then |
67278d60 | 448 | |
b38e4131 | 449 | -- This is the case to give a warning if enabled |
67278d60 | 450 | |
b38e4131 | 451 | if Warn_On_Reverse_Bit_Order then |
452 | Error_Msg_N | |
7a41db5b | 453 | ("info: multi-byte field specified with " |
1e3532e7 | 454 | & " non-standard Bit_Order?V?", CC); |
b38e4131 | 455 | |
456 | if Bytes_Big_Endian then | |
457 | Error_Msg_N | |
458 | ("\bytes are not reversed " | |
1e3532e7 | 459 | & "(component is big-endian)?V?", CC); |
b38e4131 | 460 | else |
461 | Error_Msg_N | |
462 | ("\bytes are not reversed " | |
1e3532e7 | 463 | & "(component is little-endian)?V?", CC); |
b38e4131 | 464 | end if; |
465 | end if; | |
67278d60 | 466 | |
7eb0e22f | 467 | -- Give error message for RM 13.5.1(10) violation |
67278d60 | 468 | |
b38e4131 | 469 | else |
470 | Error_Msg_FE | |
471 | ("machine scalar rules not followed for&", | |
472 | First_Bit (CC), Comp); | |
67278d60 | 473 | |
0c978552 | 474 | Error_Msg_Uint_1 := Lbit + 1; |
b38e4131 | 475 | Error_Msg_Uint_2 := Max_Machine_Scalar_Size; |
476 | Error_Msg_F | |
0c978552 | 477 | ("\last bit + 1 (^) exceeds maximum machine " |
b38e4131 | 478 | & "scalar size (^)", |
479 | First_Bit (CC)); | |
67278d60 | 480 | |
b38e4131 | 481 | if (Lbit + 1) mod SSU /= 0 then |
482 | Error_Msg_Uint_1 := SSU; | |
483 | Error_Msg_F | |
484 | ("\and is not a multiple of Storage_Unit (^) " | |
0c978552 | 485 | & "(RM 13.5.1(10))", |
b38e4131 | 486 | First_Bit (CC)); |
6797073f | 487 | |
6797073f | 488 | else |
b38e4131 | 489 | Error_Msg_Uint_1 := Fbit; |
490 | Error_Msg_F | |
491 | ("\and first bit (^) is non-zero " | |
0cafb066 | 492 | & "(RM 13.4.1(10))", |
b38e4131 | 493 | First_Bit (CC)); |
67278d60 | 494 | end if; |
6797073f | 495 | end if; |
59ac57b5 | 496 | |
b38e4131 | 497 | -- OK case of machine scalar related component clause, |
498 | -- For now, just count them. | |
59ac57b5 | 499 | |
6797073f | 500 | else |
501 | Num_CC := Num_CC + 1; | |
502 | end if; | |
503 | end; | |
504 | end if; | |
59ac57b5 | 505 | |
6797073f | 506 | Next_Component_Or_Discriminant (Comp); |
507 | end loop; | |
59ac57b5 | 508 | |
6797073f | 509 | -- We need to sort the component clauses on the basis of the |
510 | -- Position values in the clause, so we can group clauses with | |
4a87c513 | 511 | -- the same Position together to determine the relevant machine |
6797073f | 512 | -- scalar size. |
59ac57b5 | 513 | |
6797073f | 514 | Sort_CC : declare |
515 | Comps : array (0 .. Num_CC) of Entity_Id; | |
516 | -- Array to collect component and discriminant entities. The | |
517 | -- data starts at index 1, the 0'th entry is for the sort | |
518 | -- routine. | |
59ac57b5 | 519 | |
6797073f | 520 | function CP_Lt (Op1, Op2 : Natural) return Boolean; |
521 | -- Compare routine for Sort | |
59ac57b5 | 522 | |
6797073f | 523 | procedure CP_Move (From : Natural; To : Natural); |
524 | -- Move routine for Sort | |
59ac57b5 | 525 | |
6797073f | 526 | package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt); |
59ac57b5 | 527 | |
6797073f | 528 | Start : Natural; |
529 | Stop : Natural; | |
530 | -- Start and stop positions in the component list of the set of | |
531 | -- components with the same starting position (that constitute | |
532 | -- components in a single machine scalar). | |
59ac57b5 | 533 | |
6797073f | 534 | MaxL : Uint; |
535 | -- Maximum last bit value of any component in this set | |
59ac57b5 | 536 | |
6797073f | 537 | MSS : Uint; |
538 | -- Corresponding machine scalar size | |
67278d60 | 539 | |
6797073f | 540 | ----------- |
541 | -- CP_Lt -- | |
542 | ----------- | |
67278d60 | 543 | |
6797073f | 544 | function CP_Lt (Op1, Op2 : Natural) return Boolean is |
545 | begin | |
546 | return Position (Component_Clause (Comps (Op1))) < | |
547 | Position (Component_Clause (Comps (Op2))); | |
548 | end CP_Lt; | |
67278d60 | 549 | |
6797073f | 550 | ------------- |
551 | -- CP_Move -- | |
552 | ------------- | |
67278d60 | 553 | |
6797073f | 554 | procedure CP_Move (From : Natural; To : Natural) is |
555 | begin | |
556 | Comps (To) := Comps (From); | |
557 | end CP_Move; | |
67278d60 | 558 | |
4a87c513 | 559 | -- Start of processing for Sort_CC |
59ac57b5 | 560 | |
6797073f | 561 | begin |
b38e4131 | 562 | -- Collect the machine scalar relevant component clauses |
59ac57b5 | 563 | |
6797073f | 564 | Num_CC := 0; |
565 | Comp := First_Component_Or_Discriminant (R); | |
566 | while Present (Comp) loop | |
b38e4131 | 567 | declare |
568 | CC : constant Node_Id := Component_Clause (Comp); | |
569 | ||
570 | begin | |
571 | -- Collect only component clauses whose last bit is less | |
572 | -- than machine scalar size. Any component clause whose | |
573 | -- last bit exceeds this value does not take part in | |
574 | -- machine scalar layout considerations. The test for | |
575 | -- Error_Posted makes sure we exclude component clauses | |
576 | -- for which we already posted an error. | |
577 | ||
578 | if Present (CC) | |
579 | and then not Error_Posted (Last_Bit (CC)) | |
580 | and then Static_Integer (Last_Bit (CC)) < | |
d64221a7 | 581 | Max_Machine_Scalar_Size |
b38e4131 | 582 | then |
583 | Num_CC := Num_CC + 1; | |
584 | Comps (Num_CC) := Comp; | |
585 | end if; | |
586 | end; | |
59ac57b5 | 587 | |
6797073f | 588 | Next_Component_Or_Discriminant (Comp); |
589 | end loop; | |
67278d60 | 590 | |
6797073f | 591 | -- Sort by ascending position number |
67278d60 | 592 | |
6797073f | 593 | Sorting.Sort (Num_CC); |
67278d60 | 594 | |
6797073f | 595 | -- We now have all the components whose size does not exceed |
596 | -- the max machine scalar value, sorted by starting position. | |
597 | -- In this loop we gather groups of clauses starting at the | |
598 | -- same position, to process them in accordance with AI-133. | |
67278d60 | 599 | |
6797073f | 600 | Stop := 0; |
601 | while Stop < Num_CC loop | |
602 | Start := Stop + 1; | |
603 | Stop := Start; | |
604 | MaxL := | |
605 | Static_Integer | |
606 | (Last_Bit (Component_Clause (Comps (Start)))); | |
67278d60 | 607 | while Stop < Num_CC loop |
6797073f | 608 | if Static_Integer |
609 | (Position (Component_Clause (Comps (Stop + 1)))) = | |
610 | Static_Integer | |
611 | (Position (Component_Clause (Comps (Stop)))) | |
612 | then | |
613 | Stop := Stop + 1; | |
614 | MaxL := | |
615 | UI_Max | |
616 | (MaxL, | |
617 | Static_Integer | |
618 | (Last_Bit | |
619 | (Component_Clause (Comps (Stop))))); | |
620 | else | |
621 | exit; | |
622 | end if; | |
623 | end loop; | |
67278d60 | 624 | |
6797073f | 625 | -- Now we have a group of component clauses from Start to |
626 | -- Stop whose positions are identical, and MaxL is the | |
627 | -- maximum last bit value of any of these components. | |
628 | ||
629 | -- We need to determine the corresponding machine scalar | |
630 | -- size. This loop assumes that machine scalar sizes are | |
631 | -- even, and that each possible machine scalar has twice | |
632 | -- as many bits as the next smaller one. | |
633 | ||
634 | MSS := Max_Machine_Scalar_Size; | |
635 | while MSS mod 2 = 0 | |
636 | and then (MSS / 2) >= SSU | |
637 | and then (MSS / 2) > MaxL | |
638 | loop | |
639 | MSS := MSS / 2; | |
640 | end loop; | |
67278d60 | 641 | |
6797073f | 642 | -- Here is where we fix up the Component_Bit_Offset value |
643 | -- to account for the reverse bit order. Some examples of | |
644 | -- what needs to be done for the case of a machine scalar | |
645 | -- size of 8 are: | |
67278d60 | 646 | |
6797073f | 647 | -- First_Bit .. Last_Bit Component_Bit_Offset |
648 | -- old new old new | |
67278d60 | 649 | |
6797073f | 650 | -- 0 .. 0 7 .. 7 0 7 |
651 | -- 0 .. 1 6 .. 7 0 6 | |
652 | -- 0 .. 2 5 .. 7 0 5 | |
653 | -- 0 .. 7 0 .. 7 0 4 | |
67278d60 | 654 | |
6797073f | 655 | -- 1 .. 1 6 .. 6 1 6 |
656 | -- 1 .. 4 3 .. 6 1 3 | |
657 | -- 4 .. 7 0 .. 3 4 0 | |
67278d60 | 658 | |
6797073f | 659 | -- The rule is that the first bit is obtained by subtracting |
660 | -- the old ending bit from machine scalar size - 1. | |
67278d60 | 661 | |
6797073f | 662 | for C in Start .. Stop loop |
663 | declare | |
664 | Comp : constant Entity_Id := Comps (C); | |
b9e61b2a | 665 | CC : constant Node_Id := Component_Clause (Comp); |
666 | ||
667 | LB : constant Uint := Static_Integer (Last_Bit (CC)); | |
6797073f | 668 | NFB : constant Uint := MSS - Uint_1 - LB; |
669 | NLB : constant Uint := NFB + Esize (Comp) - 1; | |
b9e61b2a | 670 | Pos : constant Uint := Static_Integer (Position (CC)); |
67278d60 | 671 | |
6797073f | 672 | begin |
673 | if Warn_On_Reverse_Bit_Order then | |
674 | Error_Msg_Uint_1 := MSS; | |
675 | Error_Msg_N | |
676 | ("info: reverse bit order in machine " & | |
1e3532e7 | 677 | "scalar of length^?V?", First_Bit (CC)); |
6797073f | 678 | Error_Msg_Uint_1 := NFB; |
679 | Error_Msg_Uint_2 := NLB; | |
680 | ||
681 | if Bytes_Big_Endian then | |
682 | Error_Msg_NE | |
7a41db5b | 683 | ("\big-endian range for component " |
684 | & "& is ^ .. ^?V?", First_Bit (CC), Comp); | |
6797073f | 685 | else |
686 | Error_Msg_NE | |
7a41db5b | 687 | ("\little-endian range for component" |
688 | & "& is ^ .. ^?V?", First_Bit (CC), Comp); | |
67278d60 | 689 | end if; |
6797073f | 690 | end if; |
67278d60 | 691 | |
6797073f | 692 | Set_Component_Bit_Offset (Comp, Pos * SSU + NFB); |
693 | Set_Normalized_First_Bit (Comp, NFB mod SSU); | |
694 | end; | |
67278d60 | 695 | end loop; |
6797073f | 696 | end loop; |
697 | end Sort_CC; | |
698 | end; | |
699 | end if; | |
59ac57b5 | 700 | end Adjust_Record_For_Reverse_Bit_Order; |
701 | ||
1d366b32 | 702 | ------------------------------------- |
703 | -- Alignment_Check_For_Size_Change -- | |
704 | ------------------------------------- | |
d6f39728 | 705 | |
1d366b32 | 706 | procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is |
d6f39728 | 707 | begin |
708 | -- If the alignment is known, and not set by a rep clause, and is | |
709 | -- inconsistent with the size being set, then reset it to unknown, | |
710 | -- we assume in this case that the size overrides the inherited | |
711 | -- alignment, and that the alignment must be recomputed. | |
712 | ||
713 | if Known_Alignment (Typ) | |
714 | and then not Has_Alignment_Clause (Typ) | |
1d366b32 | 715 | and then Size mod (Alignment (Typ) * SSU) /= 0 |
d6f39728 | 716 | then |
717 | Init_Alignment (Typ); | |
718 | end if; | |
1d366b32 | 719 | end Alignment_Check_For_Size_Change; |
d6f39728 | 720 | |
06ef5f86 | 721 | ------------------------------------- |
722 | -- Analyze_Aspects_At_Freeze_Point -- | |
723 | ------------------------------------- | |
724 | ||
725 | procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is | |
726 | ASN : Node_Id; | |
727 | A_Id : Aspect_Id; | |
728 | Ritem : Node_Id; | |
729 | ||
730 | procedure Analyze_Aspect_Default_Value (ASN : Node_Id); | |
731 | -- This routine analyzes an Aspect_Default_[Component_]Value denoted by | |
732 | -- the aspect specification node ASN. | |
733 | ||
37c6e44c | 734 | procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id); |
735 | -- As discussed in the spec of Aspects (see Aspect_Delay declaration), | |
736 | -- a derived type can inherit aspects from its parent which have been | |
737 | -- specified at the time of the derivation using an aspect, as in: | |
738 | -- | |
739 | -- type A is range 1 .. 10 | |
740 | -- with Size => Not_Defined_Yet; | |
741 | -- .. | |
742 | -- type B is new A; | |
743 | -- .. | |
744 | -- Not_Defined_Yet : constant := 64; | |
745 | -- | |
746 | -- In this example, the Size of A is considered to be specified prior | |
747 | -- to the derivation, and thus inherited, even though the value is not | |
748 | -- known at the time of derivation. To deal with this, we use two entity | |
749 | -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A | |
750 | -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in | |
751 | -- the derived type (B here). If this flag is set when the derived type | |
752 | -- is frozen, then this procedure is called to ensure proper inheritance | |
b21edad9 | 753 | -- of all delayed aspects from the parent type. The derived type is E, |
37c6e44c | 754 | -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first |
755 | -- aspect specification node in the Rep_Item chain for the parent type. | |
756 | ||
06ef5f86 | 757 | procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id); |
758 | -- Given an aspect specification node ASN whose expression is an | |
759 | -- optional Boolean, this routines creates the corresponding pragma | |
760 | -- at the freezing point. | |
761 | ||
762 | ---------------------------------- | |
763 | -- Analyze_Aspect_Default_Value -- | |
764 | ---------------------------------- | |
765 | ||
766 | procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is | |
767 | Ent : constant Entity_Id := Entity (ASN); | |
768 | Expr : constant Node_Id := Expression (ASN); | |
769 | Id : constant Node_Id := Identifier (ASN); | |
770 | ||
771 | begin | |
772 | Error_Msg_Name_1 := Chars (Id); | |
773 | ||
774 | if not Is_Type (Ent) then | |
775 | Error_Msg_N ("aspect% can only apply to a type", Id); | |
776 | return; | |
777 | ||
778 | elsif not Is_First_Subtype (Ent) then | |
779 | Error_Msg_N ("aspect% cannot apply to subtype", Id); | |
780 | return; | |
781 | ||
782 | elsif A_Id = Aspect_Default_Value | |
783 | and then not Is_Scalar_Type (Ent) | |
784 | then | |
785 | Error_Msg_N ("aspect% can only be applied to scalar type", Id); | |
786 | return; | |
787 | ||
788 | elsif A_Id = Aspect_Default_Component_Value then | |
789 | if not Is_Array_Type (Ent) then | |
790 | Error_Msg_N ("aspect% can only be applied to array type", Id); | |
791 | return; | |
792 | ||
793 | elsif not Is_Scalar_Type (Component_Type (Ent)) then | |
794 | Error_Msg_N ("aspect% requires scalar components", Id); | |
795 | return; | |
796 | end if; | |
797 | end if; | |
798 | ||
799 | Set_Has_Default_Aspect (Base_Type (Ent)); | |
800 | ||
801 | if Is_Scalar_Type (Ent) then | |
9f36e3fb | 802 | Set_Default_Aspect_Value (Base_Type (Ent), Expr); |
06ef5f86 | 803 | else |
f3d70f08 | 804 | Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr); |
06ef5f86 | 805 | end if; |
806 | end Analyze_Aspect_Default_Value; | |
807 | ||
37c6e44c | 808 | --------------------------------- |
809 | -- Inherit_Delayed_Rep_Aspects -- | |
810 | --------------------------------- | |
811 | ||
812 | procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is | |
813 | P : constant Entity_Id := Entity (ASN); | |
814 | -- Entithy for parent type | |
815 | ||
816 | N : Node_Id; | |
817 | -- Item from Rep_Item chain | |
818 | ||
819 | A : Aspect_Id; | |
820 | ||
821 | begin | |
822 | -- Loop through delayed aspects for the parent type | |
823 | ||
824 | N := ASN; | |
825 | while Present (N) loop | |
826 | if Nkind (N) = N_Aspect_Specification then | |
827 | exit when Entity (N) /= P; | |
828 | ||
829 | if Is_Delayed_Aspect (N) then | |
830 | A := Get_Aspect_Id (Chars (Identifier (N))); | |
831 | ||
832 | -- Process delayed rep aspect. For Boolean attributes it is | |
833 | -- not possible to cancel an attribute once set (the attempt | |
834 | -- to use an aspect with xxx => False is an error) for a | |
835 | -- derived type. So for those cases, we do not have to check | |
836 | -- if a clause has been given for the derived type, since it | |
837 | -- is harmless to set it again if it is already set. | |
838 | ||
839 | case A is | |
840 | ||
841 | -- Alignment | |
842 | ||
843 | when Aspect_Alignment => | |
844 | if not Has_Alignment_Clause (E) then | |
845 | Set_Alignment (E, Alignment (P)); | |
846 | end if; | |
847 | ||
848 | -- Atomic | |
849 | ||
850 | when Aspect_Atomic => | |
851 | if Is_Atomic (P) then | |
852 | Set_Is_Atomic (E); | |
853 | end if; | |
854 | ||
855 | -- Atomic_Components | |
856 | ||
857 | when Aspect_Atomic_Components => | |
858 | if Has_Atomic_Components (P) then | |
859 | Set_Has_Atomic_Components (Base_Type (E)); | |
860 | end if; | |
861 | ||
862 | -- Bit_Order | |
863 | ||
864 | when Aspect_Bit_Order => | |
865 | if Is_Record_Type (E) | |
866 | and then No (Get_Attribute_Definition_Clause | |
867 | (E, Attribute_Bit_Order)) | |
868 | and then Reverse_Bit_Order (P) | |
869 | then | |
870 | Set_Reverse_Bit_Order (Base_Type (E)); | |
871 | end if; | |
872 | ||
873 | -- Component_Size | |
874 | ||
875 | when Aspect_Component_Size => | |
876 | if Is_Array_Type (E) | |
877 | and then not Has_Component_Size_Clause (E) | |
878 | then | |
879 | Set_Component_Size | |
880 | (Base_Type (E), Component_Size (P)); | |
881 | end if; | |
882 | ||
883 | -- Machine_Radix | |
884 | ||
885 | when Aspect_Machine_Radix => | |
886 | if Is_Decimal_Fixed_Point_Type (E) | |
887 | and then not Has_Machine_Radix_Clause (E) | |
888 | then | |
889 | Set_Machine_Radix_10 (E, Machine_Radix_10 (P)); | |
890 | end if; | |
891 | ||
892 | -- Object_Size (also Size which also sets Object_Size) | |
893 | ||
894 | when Aspect_Object_Size | Aspect_Size => | |
895 | if not Has_Size_Clause (E) | |
896 | and then | |
897 | No (Get_Attribute_Definition_Clause | |
898 | (E, Attribute_Object_Size)) | |
899 | then | |
900 | Set_Esize (E, Esize (P)); | |
901 | end if; | |
902 | ||
903 | -- Pack | |
904 | ||
905 | when Aspect_Pack => | |
906 | if not Is_Packed (E) then | |
907 | Set_Is_Packed (Base_Type (E)); | |
908 | ||
909 | if Is_Bit_Packed_Array (P) then | |
910 | Set_Is_Bit_Packed_Array (Base_Type (E)); | |
a88a5773 | 911 | Set_Packed_Array_Impl_Type |
912 | (E, Packed_Array_Impl_Type (P)); | |
37c6e44c | 913 | end if; |
914 | end if; | |
915 | ||
916 | -- Scalar_Storage_Order | |
917 | ||
918 | when Aspect_Scalar_Storage_Order => | |
919 | if (Is_Record_Type (E) or else Is_Array_Type (E)) | |
920 | and then No (Get_Attribute_Definition_Clause | |
e163cac8 | 921 | (E, Attribute_Scalar_Storage_Order)) |
37c6e44c | 922 | and then Reverse_Storage_Order (P) |
923 | then | |
924 | Set_Reverse_Storage_Order (Base_Type (E)); | |
b64082f2 | 925 | |
926 | -- Clear default SSO indications, since the aspect | |
927 | -- overrides the default. | |
928 | ||
929 | Set_SSO_Set_Low_By_Default (Base_Type (E), False); | |
930 | Set_SSO_Set_High_By_Default (Base_Type (E), False); | |
37c6e44c | 931 | end if; |
932 | ||
933 | -- Small | |
934 | ||
935 | when Aspect_Small => | |
936 | if Is_Fixed_Point_Type (E) | |
937 | and then not Has_Small_Clause (E) | |
938 | then | |
939 | Set_Small_Value (E, Small_Value (P)); | |
940 | end if; | |
941 | ||
942 | -- Storage_Size | |
943 | ||
944 | when Aspect_Storage_Size => | |
945 | if (Is_Access_Type (E) or else Is_Task_Type (E)) | |
946 | and then not Has_Storage_Size_Clause (E) | |
947 | then | |
948 | Set_Storage_Size_Variable | |
949 | (Base_Type (E), Storage_Size_Variable (P)); | |
950 | end if; | |
951 | ||
952 | -- Value_Size | |
953 | ||
954 | when Aspect_Value_Size => | |
955 | ||
956 | -- Value_Size is never inherited, it is either set by | |
957 | -- default, or it is explicitly set for the derived | |
958 | -- type. So nothing to do here. | |
959 | ||
960 | null; | |
961 | ||
962 | -- Volatile | |
963 | ||
964 | when Aspect_Volatile => | |
965 | if Is_Volatile (P) then | |
966 | Set_Is_Volatile (E); | |
967 | end if; | |
968 | ||
2fe893b9 | 969 | -- Volatile_Full_Access |
970 | ||
971 | when Aspect_Volatile_Full_Access => | |
4bf2acc9 | 972 | if Is_Volatile_Full_Access (P) then |
973 | Set_Is_Volatile_Full_Access (E); | |
2fe893b9 | 974 | end if; |
975 | ||
37c6e44c | 976 | -- Volatile_Components |
977 | ||
978 | when Aspect_Volatile_Components => | |
979 | if Has_Volatile_Components (P) then | |
980 | Set_Has_Volatile_Components (Base_Type (E)); | |
981 | end if; | |
982 | ||
983 | -- That should be all the Rep Aspects | |
984 | ||
985 | when others => | |
986 | pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect); | |
987 | null; | |
988 | ||
989 | end case; | |
990 | end if; | |
991 | end if; | |
992 | ||
993 | N := Next_Rep_Item (N); | |
994 | end loop; | |
995 | end Inherit_Delayed_Rep_Aspects; | |
996 | ||
06ef5f86 | 997 | ------------------------------------- |
998 | -- Make_Pragma_From_Boolean_Aspect -- | |
999 | ------------------------------------- | |
1000 | ||
1001 | procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is | |
1002 | Ident : constant Node_Id := Identifier (ASN); | |
1003 | A_Name : constant Name_Id := Chars (Ident); | |
1004 | A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name); | |
1005 | Ent : constant Entity_Id := Entity (ASN); | |
1006 | Expr : constant Node_Id := Expression (ASN); | |
1007 | Loc : constant Source_Ptr := Sloc (ASN); | |
1008 | ||
1009 | Prag : Node_Id; | |
1010 | ||
1011 | procedure Check_False_Aspect_For_Derived_Type; | |
1012 | -- This procedure checks for the case of a false aspect for a derived | |
1013 | -- type, which improperly tries to cancel an aspect inherited from | |
1014 | -- the parent. | |
1015 | ||
1016 | ----------------------------------------- | |
1017 | -- Check_False_Aspect_For_Derived_Type -- | |
1018 | ----------------------------------------- | |
1019 | ||
1020 | procedure Check_False_Aspect_For_Derived_Type is | |
1021 | Par : Node_Id; | |
1022 | ||
1023 | begin | |
1024 | -- We are only checking derived types | |
1025 | ||
1026 | if not Is_Derived_Type (E) then | |
1027 | return; | |
1028 | end if; | |
1029 | ||
1030 | Par := Nearest_Ancestor (E); | |
1031 | ||
1032 | case A_Id is | |
1033 | when Aspect_Atomic | Aspect_Shared => | |
1034 | if not Is_Atomic (Par) then | |
1035 | return; | |
1036 | end if; | |
1037 | ||
1038 | when Aspect_Atomic_Components => | |
1039 | if not Has_Atomic_Components (Par) then | |
1040 | return; | |
1041 | end if; | |
1042 | ||
1043 | when Aspect_Discard_Names => | |
1044 | if not Discard_Names (Par) then | |
1045 | return; | |
1046 | end if; | |
1047 | ||
1048 | when Aspect_Pack => | |
1049 | if not Is_Packed (Par) then | |
1050 | return; | |
1051 | end if; | |
1052 | ||
1053 | when Aspect_Unchecked_Union => | |
1054 | if not Is_Unchecked_Union (Par) then | |
1055 | return; | |
1056 | end if; | |
1057 | ||
1058 | when Aspect_Volatile => | |
1059 | if not Is_Volatile (Par) then | |
1060 | return; | |
1061 | end if; | |
1062 | ||
1063 | when Aspect_Volatile_Components => | |
1064 | if not Has_Volatile_Components (Par) then | |
1065 | return; | |
1066 | end if; | |
1067 | ||
2fe893b9 | 1068 | when Aspect_Volatile_Full_Access => |
4bf2acc9 | 1069 | if not Is_Volatile_Full_Access (Par) then |
2fe893b9 | 1070 | return; |
1071 | end if; | |
1072 | ||
06ef5f86 | 1073 | when others => |
1074 | return; | |
1075 | end case; | |
1076 | ||
1077 | -- Fall through means we are canceling an inherited aspect | |
1078 | ||
1079 | Error_Msg_Name_1 := A_Name; | |
37c6e44c | 1080 | Error_Msg_NE |
1081 | ("derived type& inherits aspect%, cannot cancel", Expr, E); | |
06ef5f86 | 1082 | end Check_False_Aspect_For_Derived_Type; |
1083 | ||
1084 | -- Start of processing for Make_Pragma_From_Boolean_Aspect | |
1085 | ||
1086 | begin | |
37c6e44c | 1087 | -- Note that we know Expr is present, because for a missing Expr |
1088 | -- argument, we knew it was True and did not need to delay the | |
1089 | -- evaluation to the freeze point. | |
1090 | ||
06ef5f86 | 1091 | if Is_False (Static_Boolean (Expr)) then |
1092 | Check_False_Aspect_For_Derived_Type; | |
1093 | ||
1094 | else | |
1095 | Prag := | |
1096 | Make_Pragma (Loc, | |
1097 | Pragma_Argument_Associations => New_List ( | |
57cd943b | 1098 | Make_Pragma_Argument_Association (Sloc (Ident), |
1099 | Expression => New_Occurrence_Of (Ent, Sloc (Ident)))), | |
1100 | ||
06ef5f86 | 1101 | Pragma_Identifier => |
1102 | Make_Identifier (Sloc (Ident), Chars (Ident))); | |
1103 | ||
1104 | Set_From_Aspect_Specification (Prag, True); | |
1105 | Set_Corresponding_Aspect (Prag, ASN); | |
1106 | Set_Aspect_Rep_Item (ASN, Prag); | |
1107 | Set_Is_Delayed_Aspect (Prag); | |
1108 | Set_Parent (Prag, ASN); | |
1109 | end if; | |
06ef5f86 | 1110 | end Make_Pragma_From_Boolean_Aspect; |
1111 | ||
1112 | -- Start of processing for Analyze_Aspects_At_Freeze_Point | |
1113 | ||
1114 | begin | |
29a9d4be | 1115 | -- Must be visible in current scope |
06ef5f86 | 1116 | |
ace3389d | 1117 | if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then |
06ef5f86 | 1118 | return; |
1119 | end if; | |
1120 | ||
1121 | -- Look for aspect specification entries for this entity | |
1122 | ||
1123 | ASN := First_Rep_Item (E); | |
06ef5f86 | 1124 | while Present (ASN) loop |
37c6e44c | 1125 | if Nkind (ASN) = N_Aspect_Specification then |
1126 | exit when Entity (ASN) /= E; | |
06ef5f86 | 1127 | |
37c6e44c | 1128 | if Is_Delayed_Aspect (ASN) then |
1129 | A_Id := Get_Aspect_Id (ASN); | |
1130 | ||
1131 | case A_Id is | |
e4c87fa5 | 1132 | |
37c6e44c | 1133 | -- For aspects whose expression is an optional Boolean, make |
7d6fb253 | 1134 | -- the corresponding pragma at the freeze point. |
06ef5f86 | 1135 | |
7d6fb253 | 1136 | when Boolean_Aspects | |
1137 | Library_Unit_Aspects => | |
1138 | Make_Pragma_From_Boolean_Aspect (ASN); | |
06ef5f86 | 1139 | |
37c6e44c | 1140 | -- Special handling for aspects that don't correspond to |
1141 | -- pragmas/attributes. | |
06ef5f86 | 1142 | |
7d6fb253 | 1143 | when Aspect_Default_Value | |
1144 | Aspect_Default_Component_Value => | |
81c2bc19 | 1145 | |
1146 | -- Do not inherit aspect for anonymous base type of a | |
1147 | -- scalar or array type, because they apply to the first | |
1148 | -- subtype of the type, and will be processed when that | |
1149 | -- first subtype is frozen. | |
1150 | ||
1151 | if Is_Derived_Type (E) | |
1152 | and then not Comes_From_Source (E) | |
1153 | and then E /= First_Subtype (E) | |
1154 | then | |
1155 | null; | |
1156 | else | |
1157 | Analyze_Aspect_Default_Value (ASN); | |
1158 | end if; | |
06ef5f86 | 1159 | |
37c6e44c | 1160 | -- Ditto for iterator aspects, because the corresponding |
1161 | -- attributes may not have been analyzed yet. | |
af9fed8f | 1162 | |
7d6fb253 | 1163 | when Aspect_Constant_Indexing | |
1164 | Aspect_Variable_Indexing | | |
1165 | Aspect_Default_Iterator | | |
1166 | Aspect_Iterator_Element => | |
1167 | Analyze (Expression (ASN)); | |
af9fed8f | 1168 | |
7d6fb253 | 1169 | if Etype (Expression (ASN)) = Any_Type then |
1170 | Error_Msg_NE | |
1171 | ("\aspect must be fully defined before & is frozen", | |
1172 | ASN, E); | |
1173 | end if; | |
b3f8228a | 1174 | |
7d6fb253 | 1175 | when Aspect_Iterable => |
1176 | Validate_Iterable_Aspect (E, ASN); | |
1177 | ||
1178 | when others => | |
1179 | null; | |
37c6e44c | 1180 | end case; |
06ef5f86 | 1181 | |
37c6e44c | 1182 | Ritem := Aspect_Rep_Item (ASN); |
06ef5f86 | 1183 | |
37c6e44c | 1184 | if Present (Ritem) then |
1185 | Analyze (Ritem); | |
1186 | end if; | |
06ef5f86 | 1187 | end if; |
1188 | end if; | |
1189 | ||
1190 | Next_Rep_Item (ASN); | |
1191 | end loop; | |
37c6e44c | 1192 | |
1193 | -- This is where we inherit delayed rep aspects from our parent. Note | |
1194 | -- that if we fell out of the above loop with ASN non-empty, it means | |
1195 | -- we hit an aspect for an entity other than E, and it must be the | |
1196 | -- type from which we were derived. | |
1197 | ||
1198 | if May_Inherit_Delayed_Rep_Aspects (E) then | |
1199 | Inherit_Delayed_Rep_Aspects (ASN); | |
1200 | end if; | |
06ef5f86 | 1201 | end Analyze_Aspects_At_Freeze_Point; |
1202 | ||
ae888dbd | 1203 | ----------------------------------- |
1204 | -- Analyze_Aspect_Specifications -- | |
1205 | ----------------------------------- | |
1206 | ||
21ea3a4f | 1207 | procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is |
e2bf777d | 1208 | procedure Decorate (Asp : Node_Id; Prag : Node_Id); |
6c5793cd | 1209 | -- Establish linkages between an aspect and its corresponding pragma |
5ddd846b | 1210 | |
50e44732 | 1211 | procedure Insert_After_SPARK_Mode |
1212 | (Prag : Node_Id; | |
1213 | Ins_Nod : Node_Id; | |
1214 | Decls : List_Id); | |
3dbe7a69 | 1215 | -- Subsidiary to the analysis of aspects Abstract_State, Ghost, |
1216 | -- Initializes, Initial_Condition and Refined_State. Insert node Prag | |
1217 | -- before node Ins_Nod. If Ins_Nod is for pragma SPARK_Mode, then skip | |
1218 | -- SPARK_Mode. Decls is the associated declarative list where Prag is to | |
1219 | -- reside. | |
e2bf777d | 1220 | |
1221 | procedure Insert_Pragma (Prag : Node_Id); | |
1222 | -- Subsidiary to the analysis of aspects Attach_Handler, Contract_Cases, | |
1223 | -- Depends, Global, Post, Pre, Refined_Depends and Refined_Global. | |
1224 | -- Insert pragma Prag such that it mimics the placement of a source | |
1225 | -- pragma of the same kind. | |
1226 | -- | |
1227 | -- procedure Proc (Formal : ...) with Global => ...; | |
1228 | -- | |
1229 | -- procedure Proc (Formal : ...); | |
1230 | -- pragma Global (...); | |
1231 | ||
1232 | -------------- | |
1233 | -- Decorate -- | |
1234 | -------------- | |
1235 | ||
1236 | procedure Decorate (Asp : Node_Id; Prag : Node_Id) is | |
5ddd846b | 1237 | begin |
6c5793cd | 1238 | Set_Aspect_Rep_Item (Asp, Prag); |
5ddd846b | 1239 | Set_Corresponding_Aspect (Prag, Asp); |
1240 | Set_From_Aspect_Specification (Prag); | |
5ddd846b | 1241 | Set_Parent (Prag, Asp); |
e2bf777d | 1242 | end Decorate; |
f0813d71 | 1243 | |
50e44732 | 1244 | ----------------------------- |
1245 | -- Insert_After_SPARK_Mode -- | |
1246 | ----------------------------- | |
1247 | ||
1248 | procedure Insert_After_SPARK_Mode | |
1249 | (Prag : Node_Id; | |
1250 | Ins_Nod : Node_Id; | |
1251 | Decls : List_Id) | |
1252 | is | |
1253 | Decl : Node_Id := Ins_Nod; | |
1254 | ||
1255 | begin | |
1256 | -- Skip SPARK_Mode | |
1257 | ||
1258 | if Present (Decl) | |
1259 | and then Nkind (Decl) = N_Pragma | |
1260 | and then Pragma_Name (Decl) = Name_SPARK_Mode | |
1261 | then | |
1262 | Decl := Next (Decl); | |
1263 | end if; | |
1264 | ||
1265 | if Present (Decl) then | |
1266 | Insert_Before (Decl, Prag); | |
1267 | ||
1268 | -- Aitem acts as the last declaration | |
1269 | ||
1270 | else | |
1271 | Append_To (Decls, Prag); | |
1272 | end if; | |
1273 | end Insert_After_SPARK_Mode; | |
1274 | ||
e2bf777d | 1275 | ------------------- |
1276 | -- Insert_Pragma -- | |
1277 | ------------------- | |
c1006d6d | 1278 | |
e2bf777d | 1279 | procedure Insert_Pragma (Prag : Node_Id) is |
1280 | Aux : Node_Id; | |
1281 | Decl : Node_Id; | |
c1006d6d | 1282 | |
1283 | begin | |
ed695684 | 1284 | if Nkind (N) = N_Subprogram_Body then |
e2bf777d | 1285 | if Present (Declarations (N)) then |
d324c418 | 1286 | |
e2bf777d | 1287 | -- Skip other internally generated pragmas from aspects to find |
1288 | -- the proper insertion point. As a result the order of pragmas | |
1289 | -- is the same as the order of aspects. | |
d324c418 | 1290 | |
607bc8f5 | 1291 | -- As precondition pragmas generated from conjuncts in the |
1292 | -- precondition aspect are presented in reverse order to | |
1293 | -- Insert_Pragma, insert them in the correct order here by not | |
1294 | -- skipping previously inserted precondition pragmas when the | |
1295 | -- current pragma is a precondition. | |
1296 | ||
e2bf777d | 1297 | Decl := First (Declarations (N)); |
1298 | while Present (Decl) loop | |
1299 | if Nkind (Decl) = N_Pragma | |
1300 | and then From_Aspect_Specification (Decl) | |
607bc8f5 | 1301 | and then not (Get_Pragma_Id (Decl) = Pragma_Precondition |
1302 | and then | |
1303 | Get_Pragma_Id (Prag) = Pragma_Precondition) | |
e2bf777d | 1304 | then |
1305 | Next (Decl); | |
d324c418 | 1306 | else |
e2bf777d | 1307 | exit; |
d324c418 | 1308 | end if; |
e2bf777d | 1309 | end loop; |
1310 | ||
1311 | if Present (Decl) then | |
1312 | Insert_Before (Decl, Prag); | |
1313 | else | |
1314 | Append (Prag, Declarations (N)); | |
1315 | end if; | |
1316 | else | |
1317 | Set_Declarations (N, New_List (Prag)); | |
d324c418 | 1318 | end if; |
c1006d6d | 1319 | |
ed695684 | 1320 | -- When the context is a library unit, the pragma is added to the |
1321 | -- Pragmas_After list. | |
1322 | ||
1323 | elsif Nkind (Parent (N)) = N_Compilation_Unit then | |
1324 | Aux := Aux_Decls_Node (Parent (N)); | |
1325 | ||
1326 | if No (Pragmas_After (Aux)) then | |
1327 | Set_Pragmas_After (Aux, New_List); | |
1328 | end if; | |
1329 | ||
1330 | Prepend (Prag, Pragmas_After (Aux)); | |
1331 | ||
c1006d6d | 1332 | -- Default |
1333 | ||
1334 | else | |
1335 | Insert_After (N, Prag); | |
c1006d6d | 1336 | end if; |
e2bf777d | 1337 | end Insert_Pragma; |
c1006d6d | 1338 | |
1339 | -- Local variables | |
1340 | ||
ae888dbd | 1341 | Aspect : Node_Id; |
d74fc39a | 1342 | Aitem : Node_Id; |
ae888dbd | 1343 | Ent : Node_Id; |
ae888dbd | 1344 | |
21ea3a4f | 1345 | L : constant List_Id := Aspect_Specifications (N); |
1346 | ||
ae888dbd | 1347 | Ins_Node : Node_Id := N; |
89f1e35c | 1348 | -- Insert pragmas/attribute definition clause after this node when no |
1349 | -- delayed analysis is required. | |
d74fc39a | 1350 | |
f0813d71 | 1351 | -- Start of processing for Analyze_Aspect_Specifications |
1352 | ||
d74fc39a | 1353 | -- The general processing involves building an attribute definition |
89f1e35c | 1354 | -- clause or a pragma node that corresponds to the aspect. Then in order |
1355 | -- to delay the evaluation of this aspect to the freeze point, we attach | |
1356 | -- the corresponding pragma/attribute definition clause to the aspect | |
1357 | -- specification node, which is then placed in the Rep Item chain. In | |
1358 | -- this case we mark the entity by setting the flag Has_Delayed_Aspects | |
1359 | -- and we evaluate the rep item at the freeze point. When the aspect | |
1360 | -- doesn't have a corresponding pragma/attribute definition clause, then | |
1361 | -- its analysis is simply delayed at the freeze point. | |
1362 | ||
1363 | -- Some special cases don't require delay analysis, thus the aspect is | |
1364 | -- analyzed right now. | |
1365 | ||
51ea9c94 | 1366 | -- Note that there is a special handling for Pre, Post, Test_Case, |
e66f4e2a | 1367 | -- Contract_Cases aspects. In these cases, we do not have to worry |
51ea9c94 | 1368 | -- about delay issues, since the pragmas themselves deal with delay |
1369 | -- of visibility for the expression analysis. Thus, we just insert | |
1370 | -- the pragma after the node N. | |
ae888dbd | 1371 | |
1372 | begin | |
21ea3a4f | 1373 | pragma Assert (Present (L)); |
1374 | ||
6fb3c314 | 1375 | -- Loop through aspects |
f93e7257 | 1376 | |
ae888dbd | 1377 | Aspect := First (L); |
21ea3a4f | 1378 | Aspect_Loop : while Present (Aspect) loop |
0fd13d32 | 1379 | Analyze_One_Aspect : declare |
94153a42 | 1380 | Expr : constant Node_Id := Expression (Aspect); |
89f1e35c | 1381 | Id : constant Node_Id := Identifier (Aspect); |
1382 | Loc : constant Source_Ptr := Sloc (Aspect); | |
94153a42 | 1383 | Nam : constant Name_Id := Chars (Id); |
1384 | A_Id : constant Aspect_Id := Get_Aspect_Id (Nam); | |
ae888dbd | 1385 | Anod : Node_Id; |
1386 | ||
37c6e44c | 1387 | Delay_Required : Boolean; |
89f1e35c | 1388 | -- Set False if delay is not required |
1389 | ||
c0793fff | 1390 | Eloc : Source_Ptr := No_Location; |
1391 | -- Source location of expression, modified when we split PPC's. It | |
1392 | -- is set below when Expr is present. | |
39e1f22f | 1393 | |
89f1e35c | 1394 | procedure Analyze_Aspect_External_Or_Link_Name; |
0fd13d32 | 1395 | -- Perform analysis of the External_Name or Link_Name aspects |
21ea3a4f | 1396 | |
89f1e35c | 1397 | procedure Analyze_Aspect_Implicit_Dereference; |
9ab32fe9 | 1398 | -- Perform analysis of the Implicit_Dereference aspects |
0fd13d32 | 1399 | |
1400 | procedure Make_Aitem_Pragma | |
1401 | (Pragma_Argument_Associations : List_Id; | |
1402 | Pragma_Name : Name_Id); | |
1403 | -- This is a wrapper for Make_Pragma used for converting aspects | |
1404 | -- to pragmas. It takes care of Sloc (set from Loc) and building | |
1405 | -- the pragma identifier from the given name. In addition the | |
1406 | -- flags Class_Present and Split_PPC are set from the aspect | |
1407 | -- node, as well as Is_Ignored. This routine also sets the | |
1408 | -- From_Aspect_Specification in the resulting pragma node to | |
1409 | -- True, and sets Corresponding_Aspect to point to the aspect. | |
1410 | -- The resulting pragma is assigned to Aitem. | |
21ea3a4f | 1411 | |
89f1e35c | 1412 | ------------------------------------------ |
1413 | -- Analyze_Aspect_External_Or_Link_Name -- | |
1414 | ------------------------------------------ | |
1415 | ||
1416 | procedure Analyze_Aspect_External_Or_Link_Name is | |
21ea3a4f | 1417 | begin |
89f1e35c | 1418 | -- Verify that there is an Import/Export aspect defined for the |
1419 | -- entity. The processing of that aspect in turn checks that | |
1420 | -- there is a Convention aspect declared. The pragma is | |
1421 | -- constructed when processing the Convention aspect. | |
21ea3a4f | 1422 | |
89f1e35c | 1423 | declare |
1424 | A : Node_Id; | |
21ea3a4f | 1425 | |
89f1e35c | 1426 | begin |
1427 | A := First (L); | |
89f1e35c | 1428 | while Present (A) loop |
18393965 | 1429 | exit when Nam_In (Chars (Identifier (A)), Name_Export, |
1430 | Name_Import); | |
89f1e35c | 1431 | Next (A); |
1432 | end loop; | |
21ea3a4f | 1433 | |
89f1e35c | 1434 | if No (A) then |
1435 | Error_Msg_N | |
51ea9c94 | 1436 | ("missing Import/Export for Link/External name", |
8a1e3cde | 1437 | Aspect); |
89f1e35c | 1438 | end if; |
1439 | end; | |
1440 | end Analyze_Aspect_External_Or_Link_Name; | |
21ea3a4f | 1441 | |
89f1e35c | 1442 | ----------------------------------------- |
1443 | -- Analyze_Aspect_Implicit_Dereference -- | |
1444 | ----------------------------------------- | |
21ea3a4f | 1445 | |
89f1e35c | 1446 | procedure Analyze_Aspect_Implicit_Dereference is |
1ff43c00 | 1447 | Disc : Entity_Id; |
1448 | Parent_Disc : Entity_Id; | |
1449 | ||
89f1e35c | 1450 | begin |
b9e61b2a | 1451 | if not Is_Type (E) or else not Has_Discriminants (E) then |
89f1e35c | 1452 | Error_Msg_N |
1ff43c00 | 1453 | ("aspect must apply to a type with discriminants", Expr); |
21ea3a4f | 1454 | |
1ff43c00 | 1455 | elsif not Is_Entity_Name (Expr) then |
1456 | Error_Msg_N | |
1457 | ("aspect must name a discriminant of current type", Expr); | |
21ea3a4f | 1458 | |
1ff43c00 | 1459 | else |
1460 | Disc := First_Discriminant (E); | |
1461 | while Present (Disc) loop | |
1462 | if Chars (Expr) = Chars (Disc) | |
1463 | and then Ekind (Etype (Disc)) = | |
1464 | E_Anonymous_Access_Type | |
1465 | then | |
1466 | Set_Has_Implicit_Dereference (E); | |
1467 | Set_Has_Implicit_Dereference (Disc); | |
1468 | exit; | |
1469 | end if; | |
21ea3a4f | 1470 | |
1ff43c00 | 1471 | Next_Discriminant (Disc); |
1472 | end loop; | |
21ea3a4f | 1473 | |
9b5b11fb | 1474 | -- Error if no proper access discriminant |
21ea3a4f | 1475 | |
1ff43c00 | 1476 | if No (Disc) then |
89f1e35c | 1477 | Error_Msg_NE |
1478 | ("not an access discriminant of&", Expr, E); | |
1ff43c00 | 1479 | return; |
1480 | end if; | |
1481 | end if; | |
1482 | ||
9b5b11fb | 1483 | -- For a type extension, check whether parent has a |
1484 | -- reference discriminant, to verify that use is proper. | |
1485 | ||
1ff43c00 | 1486 | if Is_Derived_Type (E) |
1487 | and then Has_Discriminants (Etype (E)) | |
1488 | then | |
1489 | Parent_Disc := Get_Reference_Discriminant (Etype (E)); | |
1490 | ||
1491 | if Present (Parent_Disc) | |
1492 | and then Corresponding_Discriminant (Disc) /= Parent_Disc | |
1493 | then | |
1494 | Error_Msg_N ("reference discriminant does not match " & | |
1495 | "discriminant of parent type", Expr); | |
1496 | end if; | |
89f1e35c | 1497 | end if; |
1498 | end Analyze_Aspect_Implicit_Dereference; | |
21ea3a4f | 1499 | |
0fd13d32 | 1500 | ----------------------- |
1501 | -- Make_Aitem_Pragma -- | |
1502 | ----------------------- | |
1503 | ||
1504 | procedure Make_Aitem_Pragma | |
1505 | (Pragma_Argument_Associations : List_Id; | |
1506 | Pragma_Name : Name_Id) | |
1507 | is | |
b855559d | 1508 | Args : List_Id := Pragma_Argument_Associations; |
1509 | ||
0fd13d32 | 1510 | begin |
1511 | -- We should never get here if aspect was disabled | |
1512 | ||
1513 | pragma Assert (not Is_Disabled (Aspect)); | |
1514 | ||
056dc987 | 1515 | -- Certain aspects allow for an optional name or expression. Do |
1516 | -- not generate a pragma with empty argument association list. | |
b855559d | 1517 | |
1518 | if No (Args) or else No (Expression (First (Args))) then | |
1519 | Args := No_List; | |
1520 | end if; | |
1521 | ||
0fd13d32 | 1522 | -- Build the pragma |
1523 | ||
1524 | Aitem := | |
1525 | Make_Pragma (Loc, | |
b855559d | 1526 | Pragma_Argument_Associations => Args, |
0fd13d32 | 1527 | Pragma_Identifier => |
1528 | Make_Identifier (Sloc (Id), Pragma_Name), | |
9ab32fe9 | 1529 | Class_Present => Class_Present (Aspect), |
1530 | Split_PPC => Split_PPC (Aspect)); | |
0fd13d32 | 1531 | |
1532 | -- Set additional semantic fields | |
1533 | ||
1534 | if Is_Ignored (Aspect) then | |
1535 | Set_Is_Ignored (Aitem); | |
57d8d1f3 | 1536 | elsif Is_Checked (Aspect) then |
a5109493 | 1537 | Set_Is_Checked (Aitem); |
0fd13d32 | 1538 | end if; |
1539 | ||
1540 | Set_Corresponding_Aspect (Aitem, Aspect); | |
1541 | Set_From_Aspect_Specification (Aitem, True); | |
1542 | end Make_Aitem_Pragma; | |
1543 | ||
1544 | -- Start of processing for Analyze_One_Aspect | |
1545 | ||
ae888dbd | 1546 | begin |
2d1acfa7 | 1547 | -- Skip aspect if already analyzed, to avoid looping in some cases |
fb7f2fc4 | 1548 | |
1549 | if Analyzed (Aspect) then | |
1550 | goto Continue; | |
1551 | end if; | |
1552 | ||
ef957022 | 1553 | -- Skip looking at aspect if it is totally disabled. Just mark it |
1554 | -- as such for later reference in the tree. This also sets the | |
1555 | -- Is_Ignored and Is_Checked flags appropriately. | |
51ea9c94 | 1556 | |
1557 | Check_Applicable_Policy (Aspect); | |
1558 | ||
1559 | if Is_Disabled (Aspect) then | |
1560 | goto Continue; | |
1561 | end if; | |
1562 | ||
c0793fff | 1563 | -- Set the source location of expression, used in the case of |
1564 | -- a failed precondition/postcondition or invariant. Note that | |
1565 | -- the source location of the expression is not usually the best | |
1566 | -- choice here. For example, it gets located on the last AND | |
1567 | -- keyword in a chain of boolean expressiond AND'ed together. | |
1568 | -- It is best to put the message on the first character of the | |
1569 | -- assertion, which is the effect of the First_Node call here. | |
1570 | ||
1571 | if Present (Expr) then | |
1572 | Eloc := Sloc (First_Node (Expr)); | |
1573 | end if; | |
1574 | ||
d7ed83a2 | 1575 | -- Check restriction No_Implementation_Aspect_Specifications |
1576 | ||
c171e1be | 1577 | if Implementation_Defined_Aspect (A_Id) then |
d7ed83a2 | 1578 | Check_Restriction |
1579 | (No_Implementation_Aspect_Specifications, Aspect); | |
1580 | end if; | |
1581 | ||
1582 | -- Check restriction No_Specification_Of_Aspect | |
1583 | ||
1584 | Check_Restriction_No_Specification_Of_Aspect (Aspect); | |
1585 | ||
f67ed4f5 | 1586 | -- Mark aspect analyzed (actual analysis is delayed till later) |
d7ed83a2 | 1587 | |
fb7f2fc4 | 1588 | Set_Analyzed (Aspect); |
d74fc39a | 1589 | Set_Entity (Aspect, E); |
1590 | Ent := New_Occurrence_Of (E, Sloc (Id)); | |
1591 | ||
1e3c4ae6 | 1592 | -- Check for duplicate aspect. Note that the Comes_From_Source |
1593 | -- test allows duplicate Pre/Post's that we generate internally | |
1594 | -- to escape being flagged here. | |
ae888dbd | 1595 | |
6c545057 | 1596 | if No_Duplicates_Allowed (A_Id) then |
1597 | Anod := First (L); | |
1598 | while Anod /= Aspect loop | |
c171e1be | 1599 | if Comes_From_Source (Aspect) |
1600 | and then Same_Aspect (A_Id, Get_Aspect_Id (Anod)) | |
6c545057 | 1601 | then |
1602 | Error_Msg_Name_1 := Nam; | |
1603 | Error_Msg_Sloc := Sloc (Anod); | |
39e1f22f | 1604 | |
6c545057 | 1605 | -- Case of same aspect specified twice |
39e1f22f | 1606 | |
6c545057 | 1607 | if Class_Present (Anod) = Class_Present (Aspect) then |
1608 | if not Class_Present (Anod) then | |
1609 | Error_Msg_NE | |
1610 | ("aspect% for & previously given#", | |
1611 | Id, E); | |
1612 | else | |
1613 | Error_Msg_NE | |
1614 | ("aspect `%''Class` for & previously given#", | |
1615 | Id, E); | |
1616 | end if; | |
39e1f22f | 1617 | end if; |
6c545057 | 1618 | end if; |
ae888dbd | 1619 | |
6c545057 | 1620 | Next (Anod); |
1621 | end loop; | |
1622 | end if; | |
ae888dbd | 1623 | |
4db325e6 | 1624 | -- Check some general restrictions on language defined aspects |
1625 | ||
c171e1be | 1626 | if not Implementation_Defined_Aspect (A_Id) then |
4db325e6 | 1627 | Error_Msg_Name_1 := Nam; |
1628 | ||
1629 | -- Not allowed for renaming declarations | |
1630 | ||
1631 | if Nkind (N) in N_Renaming_Declaration then | |
1632 | Error_Msg_N | |
1633 | ("aspect % not allowed for renaming declaration", | |
1634 | Aspect); | |
1635 | end if; | |
1636 | ||
1637 | -- Not allowed for formal type declarations | |
1638 | ||
1639 | if Nkind (N) = N_Formal_Type_Declaration then | |
1640 | Error_Msg_N | |
1641 | ("aspect % not allowed for formal type declaration", | |
1642 | Aspect); | |
1643 | end if; | |
1644 | end if; | |
1645 | ||
7d20685d | 1646 | -- Copy expression for later processing by the procedures |
1647 | -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations] | |
1648 | ||
1649 | Set_Entity (Id, New_Copy_Tree (Expr)); | |
1650 | ||
37c6e44c | 1651 | -- Set Delay_Required as appropriate to aspect |
1652 | ||
1653 | case Aspect_Delay (A_Id) is | |
1654 | when Always_Delay => | |
1655 | Delay_Required := True; | |
1656 | ||
1657 | when Never_Delay => | |
1658 | Delay_Required := False; | |
1659 | ||
1660 | when Rep_Aspect => | |
1661 | ||
1662 | -- If expression has the form of an integer literal, then | |
1663 | -- do not delay, since we know the value cannot change. | |
1664 | -- This optimization catches most rep clause cases. | |
1665 | ||
e43fc5c5 | 1666 | -- For Boolean aspects, don't delay if no expression |
1667 | ||
1668 | if A_Id in Boolean_Aspects and then No (Expr) then | |
1669 | Delay_Required := False; | |
1670 | ||
1671 | -- For non-Boolean aspects, don't delay if integer literal | |
1672 | ||
1673 | elsif A_Id not in Boolean_Aspects | |
1674 | and then Present (Expr) | |
1675 | and then Nkind (Expr) = N_Integer_Literal | |
1676 | then | |
1677 | Delay_Required := False; | |
1678 | ||
1679 | -- All other cases are delayed | |
1680 | ||
1681 | else | |
1682 | Delay_Required := True; | |
1683 | Set_Has_Delayed_Rep_Aspects (E); | |
1684 | end if; | |
37c6e44c | 1685 | end case; |
1686 | ||
ae888dbd | 1687 | -- Processing based on specific aspect |
1688 | ||
d74fc39a | 1689 | case A_Id is |
aa2f48d2 | 1690 | when Aspect_Unimplemented => |
1691 | null; -- ??? temp for now | |
ae888dbd | 1692 | |
1693 | -- No_Aspect should be impossible | |
1694 | ||
1695 | when No_Aspect => | |
1696 | raise Program_Error; | |
1697 | ||
89f1e35c | 1698 | -- Case 1: Aspects corresponding to attribute definition |
1699 | -- clauses. | |
ae888dbd | 1700 | |
b7b74740 | 1701 | when Aspect_Address | |
1702 | Aspect_Alignment | | |
1703 | Aspect_Bit_Order | | |
1704 | Aspect_Component_Size | | |
89f1e35c | 1705 | Aspect_Constant_Indexing | |
89f1e35c | 1706 | Aspect_Default_Iterator | |
1707 | Aspect_Dispatching_Domain | | |
b7b74740 | 1708 | Aspect_External_Tag | |
1709 | Aspect_Input | | |
b3f8228a | 1710 | Aspect_Iterable | |
89f1e35c | 1711 | Aspect_Iterator_Element | |
b7b74740 | 1712 | Aspect_Machine_Radix | |
1713 | Aspect_Object_Size | | |
1714 | Aspect_Output | | |
1715 | Aspect_Read | | |
1716 | Aspect_Scalar_Storage_Order | | |
1717 | Aspect_Size | | |
1718 | Aspect_Small | | |
1719 | Aspect_Simple_Storage_Pool | | |
1720 | Aspect_Storage_Pool | | |
b7b74740 | 1721 | Aspect_Stream_Size | |
1722 | Aspect_Value_Size | | |
89f1e35c | 1723 | Aspect_Variable_Indexing | |
b7b74740 | 1724 | Aspect_Write => |
d74fc39a | 1725 | |
89f1e35c | 1726 | -- Indexing aspects apply only to tagged type |
1727 | ||
1728 | if (A_Id = Aspect_Constant_Indexing | |
37c6e44c | 1729 | or else |
1730 | A_Id = Aspect_Variable_Indexing) | |
89f1e35c | 1731 | and then not (Is_Type (E) |
1732 | and then Is_Tagged_Type (E)) | |
1733 | then | |
05987af3 | 1734 | Error_Msg_N |
1735 | ("indexing aspect can only apply to a tagged type", | |
3f4c9ffc | 1736 | Aspect); |
89f1e35c | 1737 | goto Continue; |
1738 | end if; | |
1739 | ||
39616053 | 1740 | -- For the case of aspect Address, we don't consider that we |
588e7f97 | 1741 | -- know the entity is never set in the source, since it is |
1742 | -- is likely aliasing is occurring. | |
1743 | ||
1744 | -- Note: one might think that the analysis of the resulting | |
1745 | -- attribute definition clause would take care of that, but | |
1746 | -- that's not the case since it won't be from source. | |
1747 | ||
1748 | if A_Id = Aspect_Address then | |
1749 | Set_Never_Set_In_Source (E, False); | |
1750 | end if; | |
1751 | ||
5ac76cee | 1752 | -- Correctness of the profile of a stream operation is |
1753 | -- verified at the freeze point, but we must detect the | |
1754 | -- illegal specification of this aspect for a subtype now, | |
1755 | -- to prevent malformed rep_item chains. | |
1756 | ||
fbf4d6ef | 1757 | if A_Id = Aspect_Input or else |
1758 | A_Id = Aspect_Output or else | |
1759 | A_Id = Aspect_Read or else | |
1760 | A_Id = Aspect_Write | |
5ac76cee | 1761 | then |
fbf4d6ef | 1762 | if not Is_First_Subtype (E) then |
1763 | Error_Msg_N | |
1764 | ("local name must be a first subtype", Aspect); | |
1765 | goto Continue; | |
1766 | ||
1767 | -- If stream aspect applies to the class-wide type, | |
1768 | -- the generated attribute definition applies to the | |
1769 | -- class-wide type as well. | |
1770 | ||
1771 | elsif Class_Present (Aspect) then | |
1772 | Ent := | |
1773 | Make_Attribute_Reference (Loc, | |
1774 | Prefix => Ent, | |
1775 | Attribute_Name => Name_Class); | |
1776 | end if; | |
5ac76cee | 1777 | end if; |
1778 | ||
d74fc39a | 1779 | -- Construct the attribute definition clause |
1780 | ||
1781 | Aitem := | |
94153a42 | 1782 | Make_Attribute_Definition_Clause (Loc, |
d74fc39a | 1783 | Name => Ent, |
ae888dbd | 1784 | Chars => Chars (Id), |
1785 | Expression => Relocate_Node (Expr)); | |
1786 | ||
af9a0cc3 | 1787 | -- If the address is specified, then we treat the entity as |
41f06abf | 1788 | -- referenced, to avoid spurious warnings. This is analogous |
1789 | -- to what is done with an attribute definition clause, but | |
1790 | -- here we don't want to generate a reference because this | |
1791 | -- is the point of definition of the entity. | |
1792 | ||
1793 | if A_Id = Aspect_Address then | |
1794 | Set_Referenced (E); | |
1795 | end if; | |
1796 | ||
51ea9c94 | 1797 | -- Case 2: Aspects corresponding to pragmas |
d74fc39a | 1798 | |
89f1e35c | 1799 | -- Case 2a: Aspects corresponding to pragmas with two |
1800 | -- arguments, where the first argument is a local name | |
1801 | -- referring to the entity, and the second argument is the | |
1802 | -- aspect definition expression. | |
ae888dbd | 1803 | |
04ae062f | 1804 | -- Linker_Section/Suppress/Unsuppress |
0fd13d32 | 1805 | |
04ae062f | 1806 | when Aspect_Linker_Section | |
1807 | Aspect_Suppress | | |
1808 | Aspect_Unsuppress => | |
ae888dbd | 1809 | |
0fd13d32 | 1810 | Make_Aitem_Pragma |
1811 | (Pragma_Argument_Associations => New_List ( | |
1812 | Make_Pragma_Argument_Association (Loc, | |
1813 | Expression => New_Occurrence_Of (E, Loc)), | |
1814 | Make_Pragma_Argument_Association (Sloc (Expr), | |
1815 | Expression => Relocate_Node (Expr))), | |
1816 | Pragma_Name => Chars (Id)); | |
57cd943b | 1817 | |
0fd13d32 | 1818 | -- Synchronization |
d74fc39a | 1819 | |
0fd13d32 | 1820 | -- Corresponds to pragma Implemented, construct the pragma |
49213728 | 1821 | |
5bbfbad2 | 1822 | when Aspect_Synchronization => |
0fd13d32 | 1823 | Make_Aitem_Pragma |
1824 | (Pragma_Argument_Associations => New_List ( | |
1825 | Make_Pragma_Argument_Association (Loc, | |
1826 | Expression => New_Occurrence_Of (E, Loc)), | |
1827 | Make_Pragma_Argument_Association (Sloc (Expr), | |
1828 | Expression => Relocate_Node (Expr))), | |
1829 | Pragma_Name => Name_Implemented); | |
49213728 | 1830 | |
e2bf777d | 1831 | -- Attach_Handler |
0fd13d32 | 1832 | |
89f1e35c | 1833 | when Aspect_Attach_Handler => |
0fd13d32 | 1834 | Make_Aitem_Pragma |
1835 | (Pragma_Argument_Associations => New_List ( | |
1836 | Make_Pragma_Argument_Association (Sloc (Ent), | |
1837 | Expression => Ent), | |
1838 | Make_Pragma_Argument_Association (Sloc (Expr), | |
1839 | Expression => Relocate_Node (Expr))), | |
1840 | Pragma_Name => Name_Attach_Handler); | |
1841 | ||
f67ed4f5 | 1842 | -- We need to insert this pragma into the tree to get proper |
1843 | -- processing and to look valid from a placement viewpoint. | |
1844 | ||
e2bf777d | 1845 | Insert_Pragma (Aitem); |
f67ed4f5 | 1846 | goto Continue; |
1847 | ||
0fd13d32 | 1848 | -- Dynamic_Predicate, Predicate, Static_Predicate |
89f1e35c | 1849 | |
1850 | when Aspect_Dynamic_Predicate | | |
1851 | Aspect_Predicate | | |
1852 | Aspect_Static_Predicate => | |
1853 | ||
a47ce82d | 1854 | -- These aspects apply only to subtypes |
1855 | ||
1856 | if not Is_Type (E) then | |
1857 | Error_Msg_N | |
1858 | ("predicate can only be specified for a subtype", | |
1859 | Aspect); | |
1860 | goto Continue; | |
7c0c95b8 | 1861 | |
1862 | elsif Is_Incomplete_Type (E) then | |
1863 | Error_Msg_N | |
1864 | ("predicate cannot apply to incomplete view", Aspect); | |
1865 | goto Continue; | |
a47ce82d | 1866 | end if; |
1867 | ||
89f1e35c | 1868 | -- Construct the pragma (always a pragma Predicate, with |
51ea9c94 | 1869 | -- flags recording whether it is static/dynamic). We also |
1870 | -- set flags recording this in the type itself. | |
89f1e35c | 1871 | |
0fd13d32 | 1872 | Make_Aitem_Pragma |
1873 | (Pragma_Argument_Associations => New_List ( | |
1874 | Make_Pragma_Argument_Association (Sloc (Ent), | |
1875 | Expression => Ent), | |
1876 | Make_Pragma_Argument_Association (Sloc (Expr), | |
1877 | Expression => Relocate_Node (Expr))), | |
1878 | Pragma_Name => Name_Predicate); | |
89f1e35c | 1879 | |
51ea9c94 | 1880 | -- Mark type has predicates, and remember what kind of |
1881 | -- aspect lead to this predicate (we need this to access | |
1882 | -- the right set of check policies later on). | |
1883 | ||
1884 | Set_Has_Predicates (E); | |
1885 | ||
1886 | if A_Id = Aspect_Dynamic_Predicate then | |
1887 | Set_Has_Dynamic_Predicate_Aspect (E); | |
1888 | elsif A_Id = Aspect_Static_Predicate then | |
1889 | Set_Has_Static_Predicate_Aspect (E); | |
1890 | end if; | |
1891 | ||
89f1e35c | 1892 | -- If the type is private, indicate that its completion |
6653b695 | 1893 | -- has a freeze node, because that is the one that will |
1894 | -- be visible at freeze time. | |
89f1e35c | 1895 | |
0fd13d32 | 1896 | if Is_Private_Type (E) and then Present (Full_View (E)) then |
89f1e35c | 1897 | Set_Has_Predicates (Full_View (E)); |
51ea9c94 | 1898 | |
1899 | if A_Id = Aspect_Dynamic_Predicate then | |
1900 | Set_Has_Dynamic_Predicate_Aspect (Full_View (E)); | |
1901 | elsif A_Id = Aspect_Static_Predicate then | |
1902 | Set_Has_Static_Predicate_Aspect (Full_View (E)); | |
1903 | end if; | |
1904 | ||
89f1e35c | 1905 | Set_Has_Delayed_Aspects (Full_View (E)); |
1906 | Ensure_Freeze_Node (Full_View (E)); | |
1907 | end if; | |
1908 | ||
1909 | -- Case 2b: Aspects corresponding to pragmas with two | |
1910 | -- arguments, where the second argument is a local name | |
1911 | -- referring to the entity, and the first argument is the | |
1912 | -- aspect definition expression. | |
ae888dbd | 1913 | |
0fd13d32 | 1914 | -- Convention |
1915 | ||
a5a64273 | 1916 | when Aspect_Convention => |
1917 | ||
1918 | -- The aspect may be part of the specification of an import | |
1919 | -- or export pragma. Scan the aspect list to gather the | |
1920 | -- other components, if any. The name of the generated | |
1921 | -- pragma is one of Convention/Import/Export. | |
1922 | ||
1923 | declare | |
97bf66e6 | 1924 | Args : constant List_Id := New_List ( |
1925 | Make_Pragma_Argument_Association (Sloc (Expr), | |
1926 | Expression => Relocate_Node (Expr)), | |
1927 | Make_Pragma_Argument_Association (Sloc (Ent), | |
1928 | Expression => Ent)); | |
1929 | ||
1930 | Imp_Exp_Seen : Boolean := False; | |
1931 | -- Flag set when aspect Import or Export has been seen | |
1932 | ||
1933 | Imp_Seen : Boolean := False; | |
1934 | -- Flag set when aspect Import has been seen | |
1935 | ||
1936 | Asp : Node_Id; | |
1937 | Asp_Nam : Name_Id; | |
1938 | Extern_Arg : Node_Id; | |
1939 | Link_Arg : Node_Id; | |
1940 | Prag_Nam : Name_Id; | |
a5a64273 | 1941 | |
1942 | begin | |
97bf66e6 | 1943 | Extern_Arg := Empty; |
1944 | Link_Arg := Empty; | |
1945 | Prag_Nam := Chars (Id); | |
1946 | ||
1947 | Asp := First (L); | |
1948 | while Present (Asp) loop | |
1949 | Asp_Nam := Chars (Identifier (Asp)); | |
1950 | ||
1951 | -- Aspects Import and Export take precedence over | |
1952 | -- aspect Convention. As a result the generated pragma | |
1953 | -- must carry the proper interfacing aspect's name. | |
1954 | ||
1955 | if Nam_In (Asp_Nam, Name_Import, Name_Export) then | |
1956 | if Imp_Exp_Seen then | |
1957 | Error_Msg_N ("conflicting", Asp); | |
a5a64273 | 1958 | else |
97bf66e6 | 1959 | Imp_Exp_Seen := True; |
1960 | ||
1961 | if Asp_Nam = Name_Import then | |
1962 | Imp_Seen := True; | |
1963 | end if; | |
a5a64273 | 1964 | end if; |
1965 | ||
97bf66e6 | 1966 | Prag_Nam := Asp_Nam; |
a5a64273 | 1967 | |
97bf66e6 | 1968 | -- Aspect External_Name adds an extra argument to the |
1969 | -- generated pragma. | |
1970 | ||
1971 | elsif Asp_Nam = Name_External_Name then | |
1972 | Extern_Arg := | |
4bba0a8d | 1973 | Make_Pragma_Argument_Association (Loc, |
97bf66e6 | 1974 | Chars => Asp_Nam, |
1975 | Expression => Relocate_Node (Expression (Asp))); | |
1976 | ||
1977 | -- Aspect Link_Name adds an extra argument to the | |
1978 | -- generated pragma. | |
a5a64273 | 1979 | |
97bf66e6 | 1980 | elsif Asp_Nam = Name_Link_Name then |
1981 | Link_Arg := | |
4bba0a8d | 1982 | Make_Pragma_Argument_Association (Loc, |
97bf66e6 | 1983 | Chars => Asp_Nam, |
1984 | Expression => Relocate_Node (Expression (Asp))); | |
a5a64273 | 1985 | end if; |
1986 | ||
97bf66e6 | 1987 | Next (Asp); |
a5a64273 | 1988 | end loop; |
1989 | ||
97bf66e6 | 1990 | -- Assemble the full argument list |
b9e61b2a | 1991 | |
97bf66e6 | 1992 | if Present (Extern_Arg) then |
1993 | Append_To (Args, Extern_Arg); | |
a5a64273 | 1994 | end if; |
1995 | ||
8a1e3cde | 1996 | if Present (Link_Arg) then |
1997 | Append_To (Args, Link_Arg); | |
1998 | end if; | |
1999 | ||
0fd13d32 | 2000 | Make_Aitem_Pragma |
97bf66e6 | 2001 | (Pragma_Argument_Associations => Args, |
2002 | Pragma_Name => Prag_Nam); | |
2003 | ||
2004 | -- Store the generated pragma Import in the related | |
2005 | -- subprogram. | |
2006 | ||
2007 | if Imp_Seen and then Is_Subprogram (E) then | |
2008 | Set_Import_Pragma (E, Aitem); | |
2009 | end if; | |
a5a64273 | 2010 | end; |
e1cedbae | 2011 | |
0fd13d32 | 2012 | -- CPU, Interrupt_Priority, Priority |
2013 | ||
d6814978 | 2014 | -- These three aspects can be specified for a subprogram spec |
2015 | -- or body, in which case we analyze the expression and export | |
2016 | -- the value of the aspect. | |
2017 | ||
2018 | -- Previously, we generated an equivalent pragma for bodies | |
2019 | -- (note that the specs cannot contain these pragmas). The | |
2020 | -- pragma was inserted ahead of local declarations, rather than | |
2021 | -- after the body. This leads to a certain duplication between | |
2022 | -- the processing performed for the aspect and the pragma, but | |
2023 | -- given the straightforward handling required it is simpler | |
2024 | -- to duplicate than to translate the aspect in the spec into | |
2025 | -- a pragma in the declarative part of the body. | |
3a72f9c3 | 2026 | |
2027 | when Aspect_CPU | | |
2028 | Aspect_Interrupt_Priority | | |
2029 | Aspect_Priority => | |
51ea9c94 | 2030 | |
d6814978 | 2031 | if Nkind_In (N, N_Subprogram_Body, |
2032 | N_Subprogram_Declaration) | |
2033 | then | |
2034 | -- Analyze the aspect expression | |
2035 | ||
2036 | Analyze_And_Resolve (Expr, Standard_Integer); | |
2037 | ||
2038 | -- Interrupt_Priority aspect not allowed for main | |
078a74b8 | 2039 | -- subprograms. RM D.1 does not forbid this explicitly, |
2040 | -- but RM J.15.11(6/3) does not permit pragma | |
d6814978 | 2041 | -- Interrupt_Priority for subprograms. |
2042 | ||
2043 | if A_Id = Aspect_Interrupt_Priority then | |
2044 | Error_Msg_N | |
2045 | ("Interrupt_Priority aspect cannot apply to " | |
2046 | & "subprogram", Expr); | |
2047 | ||
2048 | -- The expression must be static | |
2049 | ||
cda40848 | 2050 | elsif not Is_OK_Static_Expression (Expr) then |
d6814978 | 2051 | Flag_Non_Static_Expr |
2052 | ("aspect requires static expression!", Expr); | |
2053 | ||
24d7b9d6 | 2054 | -- Check whether this is the main subprogram. Issue a |
2055 | -- warning only if it is obviously not a main program | |
2056 | -- (when it has parameters or when the subprogram is | |
2057 | -- within a package). | |
2058 | ||
2059 | elsif Present (Parameter_Specifications | |
2060 | (Specification (N))) | |
2061 | or else not Is_Compilation_Unit (Defining_Entity (N)) | |
d6814978 | 2062 | then |
078a74b8 | 2063 | -- See RM D.1(14/3) and D.16(12/3) |
d6814978 | 2064 | |
2065 | Error_Msg_N | |
2066 | ("aspect applied to subprogram other than the " | |
2067 | & "main subprogram has no effect??", Expr); | |
2068 | ||
2069 | -- Otherwise check in range and export the value | |
2070 | ||
2071 | -- For the CPU aspect | |
2072 | ||
2073 | elsif A_Id = Aspect_CPU then | |
2074 | if Is_In_Range (Expr, RTE (RE_CPU_Range)) then | |
2075 | ||
2076 | -- Value is correct so we export the value to make | |
2077 | -- it available at execution time. | |
2078 | ||
2079 | Set_Main_CPU | |
2080 | (Main_Unit, UI_To_Int (Expr_Value (Expr))); | |
2081 | ||
2082 | else | |
2083 | Error_Msg_N | |
2084 | ("main subprogram CPU is out of range", Expr); | |
2085 | end if; | |
2086 | ||
2087 | -- For the Priority aspect | |
2088 | ||
2089 | elsif A_Id = Aspect_Priority then | |
2090 | if Is_In_Range (Expr, RTE (RE_Priority)) then | |
2091 | ||
2092 | -- Value is correct so we export the value to make | |
2093 | -- it available at execution time. | |
2094 | ||
2095 | Set_Main_Priority | |
2096 | (Main_Unit, UI_To_Int (Expr_Value (Expr))); | |
2097 | ||
32572384 | 2098 | -- Ignore pragma if Relaxed_RM_Semantics to support |
2099 | -- other targets/non GNAT compilers. | |
2100 | ||
2101 | elsif not Relaxed_RM_Semantics then | |
d6814978 | 2102 | Error_Msg_N |
2103 | ("main subprogram priority is out of range", | |
2104 | Expr); | |
2105 | end if; | |
2106 | end if; | |
2107 | ||
2108 | -- Load an arbitrary entity from System.Tasking.Stages | |
2109 | -- or System.Tasking.Restricted.Stages (depending on | |
2110 | -- the supported profile) to make sure that one of these | |
2111 | -- packages is implicitly with'ed, since we need to have | |
2112 | -- the tasking run time active for the pragma Priority to | |
a0c3eeb9 | 2113 | -- have any effect. Previously we with'ed the package |
d6814978 | 2114 | -- System.Tasking, but this package does not trigger the |
2115 | -- required initialization of the run-time library. | |
2116 | ||
2117 | declare | |
2118 | Discard : Entity_Id; | |
d6814978 | 2119 | begin |
2120 | if Restricted_Profile then | |
2121 | Discard := RTE (RE_Activate_Restricted_Tasks); | |
2122 | else | |
2123 | Discard := RTE (RE_Activate_Tasks); | |
2124 | end if; | |
2125 | end; | |
2126 | ||
2127 | -- Handling for these Aspects in subprograms is complete | |
2128 | ||
2129 | goto Continue; | |
2130 | ||
2131 | -- For tasks | |
0fd13d32 | 2132 | |
3a72f9c3 | 2133 | else |
d6814978 | 2134 | -- Pass the aspect as an attribute |
2135 | ||
3a72f9c3 | 2136 | Aitem := |
2137 | Make_Attribute_Definition_Clause (Loc, | |
2138 | Name => Ent, | |
2139 | Chars => Chars (Id), | |
2140 | Expression => Relocate_Node (Expr)); | |
2141 | end if; | |
2142 | ||
0fd13d32 | 2143 | -- Warnings |
2144 | ||
ae888dbd | 2145 | when Aspect_Warnings => |
0fd13d32 | 2146 | Make_Aitem_Pragma |
2147 | (Pragma_Argument_Associations => New_List ( | |
2148 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2149 | Expression => Relocate_Node (Expr)), | |
2150 | Make_Pragma_Argument_Association (Loc, | |
2151 | Expression => New_Occurrence_Of (E, Loc))), | |
2152 | Pragma_Name => Chars (Id)); | |
ae888dbd | 2153 | |
89f1e35c | 2154 | -- Case 2c: Aspects corresponding to pragmas with three |
2155 | -- arguments. | |
d64221a7 | 2156 | |
89f1e35c | 2157 | -- Invariant aspects have a first argument that references the |
2158 | -- entity, a second argument that is the expression and a third | |
2159 | -- argument that is an appropriate message. | |
d64221a7 | 2160 | |
0fd13d32 | 2161 | -- Invariant, Type_Invariant |
2162 | ||
89f1e35c | 2163 | when Aspect_Invariant | |
2164 | Aspect_Type_Invariant => | |
d64221a7 | 2165 | |
89f1e35c | 2166 | -- Analysis of the pragma will verify placement legality: |
2167 | -- an invariant must apply to a private type, or appear in | |
2168 | -- the private part of a spec and apply to a completion. | |
d64221a7 | 2169 | |
0fd13d32 | 2170 | Make_Aitem_Pragma |
2171 | (Pragma_Argument_Associations => New_List ( | |
2172 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2173 | Expression => Ent), | |
2174 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2175 | Expression => Relocate_Node (Expr))), | |
2176 | Pragma_Name => Name_Invariant); | |
89f1e35c | 2177 | |
2178 | -- Add message unless exception messages are suppressed | |
2179 | ||
2180 | if not Opt.Exception_Locations_Suppressed then | |
2181 | Append_To (Pragma_Argument_Associations (Aitem), | |
2182 | Make_Pragma_Argument_Association (Eloc, | |
2183 | Chars => Name_Message, | |
2184 | Expression => | |
2185 | Make_String_Literal (Eloc, | |
2186 | Strval => "failed invariant from " | |
2187 | & Build_Location_String (Eloc)))); | |
d64221a7 | 2188 | end if; |
2189 | ||
89f1e35c | 2190 | -- For Invariant case, insert immediately after the entity |
2191 | -- declaration. We do not have to worry about delay issues | |
2192 | -- since the pragma processing takes care of this. | |
2193 | ||
89f1e35c | 2194 | Delay_Required := False; |
d64221a7 | 2195 | |
47a46747 | 2196 | -- Case 2d : Aspects that correspond to a pragma with one |
2197 | -- argument. | |
2198 | ||
0fd13d32 | 2199 | -- Abstract_State |
115f7b08 | 2200 | |
d4e369ad | 2201 | -- Aspect Abstract_State introduces implicit declarations for |
2202 | -- all state abstraction entities it defines. To emulate this | |
2203 | -- behavior, insert the pragma at the beginning of the visible | |
2204 | -- declarations of the related package so that it is analyzed | |
2205 | -- immediately. | |
2206 | ||
9129c28f | 2207 | when Aspect_Abstract_State => Abstract_State : declare |
eb4f7efa | 2208 | Context : Node_Id := N; |
630b6d55 | 2209 | Decl : Node_Id; |
eb4f7efa | 2210 | Decls : List_Id; |
9129c28f | 2211 | |
2212 | begin | |
eb4f7efa | 2213 | -- When aspect Abstract_State appears on a generic package, |
2214 | -- it is propageted to the package instance. The context in | |
2215 | -- this case is the instance spec. | |
2216 | ||
2217 | if Nkind (Context) = N_Package_Instantiation then | |
2218 | Context := Instance_Spec (Context); | |
2219 | end if; | |
2220 | ||
2221 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2222 | N_Package_Declaration) | |
9129c28f | 2223 | then |
9129c28f | 2224 | Make_Aitem_Pragma |
2225 | (Pragma_Argument_Associations => New_List ( | |
2226 | Make_Pragma_Argument_Association (Loc, | |
2227 | Expression => Relocate_Node (Expr))), | |
2228 | Pragma_Name => Name_Abstract_State); | |
e2bf777d | 2229 | Decorate (Aspect, Aitem); |
9129c28f | 2230 | |
630b6d55 | 2231 | Decls := Visible_Declarations (Specification (Context)); |
2232 | ||
2233 | -- In general pragma Abstract_State must be at the top | |
2234 | -- of the existing visible declarations to emulate its | |
2235 | -- source counterpart. The only exception to this is a | |
2236 | -- generic instance in which case the pragma must be | |
2237 | -- inserted after the association renamings. | |
2238 | ||
2239 | if Present (Decls) then | |
50e44732 | 2240 | Decl := First (Decls); |
630b6d55 | 2241 | |
2242 | -- The visible declarations of a generic instance have | |
2243 | -- the following structure: | |
2244 | ||
2245 | -- <renamings of generic formals> | |
2246 | -- <renamings of internally-generated spec and body> | |
2247 | -- <first source declaration> | |
2248 | ||
2249 | -- The pragma must be inserted before the first source | |
50e44732 | 2250 | -- declaration, skip the instance "header". |
630b6d55 | 2251 | |
2252 | if Is_Generic_Instance (Defining_Entity (Context)) then | |
630b6d55 | 2253 | while Present (Decl) |
2254 | and then not Comes_From_Source (Decl) | |
2255 | loop | |
2256 | Decl := Next (Decl); | |
2257 | end loop; | |
50e44732 | 2258 | end if; |
630b6d55 | 2259 | |
3dbe7a69 | 2260 | -- When aspects Abstract_State, Ghost, |
2261 | -- Initial_Condition and Initializes are out of order, | |
2262 | -- ensure that pragma SPARK_Mode is always at the top | |
2263 | -- of the declarations to properly enabled/suppress | |
2264 | -- errors. | |
630b6d55 | 2265 | |
50e44732 | 2266 | Insert_After_SPARK_Mode |
2267 | (Prag => Aitem, | |
2268 | Ins_Nod => Decl, | |
2269 | Decls => Decls); | |
630b6d55 | 2270 | |
2271 | -- Otherwise the pragma forms a new declarative list | |
2272 | ||
2273 | else | |
2274 | Set_Visible_Declarations | |
2275 | (Specification (Context), New_List (Aitem)); | |
2276 | end if; | |
9129c28f | 2277 | |
2278 | else | |
2279 | Error_Msg_NE | |
2280 | ("aspect & must apply to a package declaration", | |
2281 | Aspect, Id); | |
2282 | end if; | |
2283 | ||
2284 | goto Continue; | |
2285 | end Abstract_State; | |
115f7b08 | 2286 | |
85ee12c0 | 2287 | -- Aspect Async_Readers is never delayed because it is |
2288 | -- equivalent to a source pragma which appears after the | |
2289 | -- related object declaration. | |
2290 | ||
2291 | when Aspect_Async_Readers => | |
2292 | Make_Aitem_Pragma | |
2293 | (Pragma_Argument_Associations => New_List ( | |
2294 | Make_Pragma_Argument_Association (Loc, | |
2295 | Expression => Relocate_Node (Expr))), | |
2296 | Pragma_Name => Name_Async_Readers); | |
2297 | ||
2298 | Decorate (Aspect, Aitem); | |
2299 | Insert_Pragma (Aitem); | |
2300 | goto Continue; | |
2301 | ||
2302 | -- Aspect Async_Writers is never delayed because it is | |
2303 | -- equivalent to a source pragma which appears after the | |
2304 | -- related object declaration. | |
2305 | ||
2306 | when Aspect_Async_Writers => | |
2307 | Make_Aitem_Pragma | |
2308 | (Pragma_Argument_Associations => New_List ( | |
2309 | Make_Pragma_Argument_Association (Loc, | |
2310 | Expression => Relocate_Node (Expr))), | |
2311 | Pragma_Name => Name_Async_Writers); | |
2312 | ||
2313 | Decorate (Aspect, Aitem); | |
2314 | Insert_Pragma (Aitem); | |
2315 | goto Continue; | |
2316 | ||
d0849c23 | 2317 | -- Aspect Constant_After_Elaboration is never delayed because |
2318 | -- it is equivalent to a source pragma which appears after the | |
2319 | -- related object declaration. | |
2320 | ||
2321 | when Aspect_Constant_After_Elaboration => | |
2322 | Make_Aitem_Pragma | |
2323 | (Pragma_Argument_Associations => New_List ( | |
2324 | Make_Pragma_Argument_Association (Loc, | |
2325 | Expression => Relocate_Node (Expr))), | |
2326 | Pragma_Name => | |
2327 | Name_Constant_After_Elaboration); | |
2328 | ||
2329 | Decorate (Aspect, Aitem); | |
2330 | Insert_Pragma (Aitem); | |
2331 | goto Continue; | |
2332 | ||
ec6f6da5 | 2333 | -- Aspect Default_Internal_Condition is never delayed because |
2334 | -- it is equivalent to a source pragma which appears after the | |
2335 | -- related private type. To deal with forward references, the | |
2336 | -- generated pragma is stored in the rep chain of the related | |
2337 | -- private type as types do not carry contracts. The pragma is | |
2338 | -- wrapped inside of a procedure at the freeze point of the | |
2339 | -- private type's full view. | |
2340 | ||
2341 | when Aspect_Default_Initial_Condition => | |
2342 | Make_Aitem_Pragma | |
2343 | (Pragma_Argument_Associations => New_List ( | |
2344 | Make_Pragma_Argument_Association (Loc, | |
2345 | Expression => Relocate_Node (Expr))), | |
2346 | Pragma_Name => | |
2347 | Name_Default_Initial_Condition); | |
2348 | ||
2349 | Decorate (Aspect, Aitem); | |
2350 | Insert_Pragma (Aitem); | |
2351 | goto Continue; | |
2352 | ||
647fab54 | 2353 | -- Default_Storage_Pool |
2354 | ||
2355 | when Aspect_Default_Storage_Pool => | |
2356 | Make_Aitem_Pragma | |
2357 | (Pragma_Argument_Associations => New_List ( | |
2358 | Make_Pragma_Argument_Association (Loc, | |
2359 | Expression => Relocate_Node (Expr))), | |
2360 | Pragma_Name => | |
2361 | Name_Default_Storage_Pool); | |
2362 | ||
2363 | Decorate (Aspect, Aitem); | |
2364 | Insert_Pragma (Aitem); | |
2365 | goto Continue; | |
2366 | ||
0fd13d32 | 2367 | -- Depends |
2368 | ||
e2bf777d | 2369 | -- Aspect Depends is never delayed because it is equivalent to |
2370 | -- a source pragma which appears after the related subprogram. | |
2371 | -- To deal with forward references, the generated pragma is | |
2372 | -- stored in the contract of the related subprogram and later | |
2373 | -- analyzed at the end of the declarative region. See routine | |
2374 | -- Analyze_Depends_In_Decl_Part for details. | |
6144c105 | 2375 | |
12334c57 | 2376 | when Aspect_Depends => |
0fd13d32 | 2377 | Make_Aitem_Pragma |
2378 | (Pragma_Argument_Associations => New_List ( | |
2379 | Make_Pragma_Argument_Association (Loc, | |
2380 | Expression => Relocate_Node (Expr))), | |
2381 | Pragma_Name => Name_Depends); | |
2382 | ||
e2bf777d | 2383 | Decorate (Aspect, Aitem); |
2384 | Insert_Pragma (Aitem); | |
c1006d6d | 2385 | goto Continue; |
2386 | ||
85ee12c0 | 2387 | -- Aspect Effecitve_Reads is never delayed because it is |
2388 | -- equivalent to a source pragma which appears after the | |
2389 | -- related object declaration. | |
2390 | ||
2391 | when Aspect_Effective_Reads => | |
2392 | Make_Aitem_Pragma | |
2393 | (Pragma_Argument_Associations => New_List ( | |
2394 | Make_Pragma_Argument_Association (Loc, | |
2395 | Expression => Relocate_Node (Expr))), | |
2396 | Pragma_Name => Name_Effective_Reads); | |
2397 | ||
2398 | Decorate (Aspect, Aitem); | |
2399 | Insert_Pragma (Aitem); | |
2400 | goto Continue; | |
2401 | ||
2402 | -- Aspect Effective_Writes is never delayed because it is | |
2403 | -- equivalent to a source pragma which appears after the | |
2404 | -- related object declaration. | |
2405 | ||
2406 | when Aspect_Effective_Writes => | |
2407 | Make_Aitem_Pragma | |
2408 | (Pragma_Argument_Associations => New_List ( | |
2409 | Make_Pragma_Argument_Association (Loc, | |
2410 | Expression => Relocate_Node (Expr))), | |
2411 | Pragma_Name => Name_Effective_Writes); | |
2412 | ||
2413 | Decorate (Aspect, Aitem); | |
2414 | Insert_Pragma (Aitem); | |
2415 | goto Continue; | |
2416 | ||
cab27d2a | 2417 | -- Aspect Extensions_Visible is never delayed because it is |
2418 | -- equivalent to a source pragma which appears after the | |
2419 | -- related subprogram. | |
2420 | ||
2421 | when Aspect_Extensions_Visible => | |
2422 | Make_Aitem_Pragma | |
2423 | (Pragma_Argument_Associations => New_List ( | |
2424 | Make_Pragma_Argument_Association (Loc, | |
2425 | Expression => Relocate_Node (Expr))), | |
2426 | Pragma_Name => Name_Extensions_Visible); | |
2427 | ||
2428 | Decorate (Aspect, Aitem); | |
2429 | Insert_Pragma (Aitem); | |
2430 | goto Continue; | |
2431 | ||
3dbe7a69 | 2432 | -- Aspect Ghost is never delayed because it is equivalent to a |
2433 | -- source pragma which appears at the top of [generic] package | |
2434 | -- declarations or after an object, a [generic] subprogram, or | |
2435 | -- a type declaration. | |
2436 | ||
2437 | when Aspect_Ghost => Ghost : declare | |
2438 | Decls : List_Id; | |
2439 | ||
2440 | begin | |
2441 | Make_Aitem_Pragma | |
2442 | (Pragma_Argument_Associations => New_List ( | |
2443 | Make_Pragma_Argument_Association (Loc, | |
2444 | Expression => Relocate_Node (Expr))), | |
2445 | Pragma_Name => Name_Ghost); | |
2446 | ||
2447 | Decorate (Aspect, Aitem); | |
2448 | ||
2449 | -- When the aspect applies to a [generic] package, insert | |
2450 | -- the pragma at the top of the visible declarations. This | |
2451 | -- emulates the placement of a source pragma. | |
2452 | ||
2453 | if Nkind_In (N, N_Generic_Package_Declaration, | |
2454 | N_Package_Declaration) | |
2455 | then | |
2456 | Decls := Visible_Declarations (Specification (N)); | |
2457 | ||
2458 | if No (Decls) then | |
2459 | Decls := New_List; | |
2460 | Set_Visible_Declarations (N, Decls); | |
2461 | end if; | |
2462 | ||
2463 | -- When aspects Abstract_State, Ghost, Initial_Condition | |
2464 | -- and Initializes are out of order, ensure that pragma | |
2465 | -- SPARK_Mode is always at the top of the declarations to | |
2466 | -- properly enabled/suppress errors. | |
2467 | ||
2468 | Insert_After_SPARK_Mode | |
2469 | (Prag => Aitem, | |
2470 | Ins_Nod => First (Decls), | |
2471 | Decls => Decls); | |
2472 | ||
2473 | -- Otherwise the context is an object, [generic] subprogram | |
2474 | -- or type declaration. | |
2475 | ||
2476 | else | |
2477 | Insert_Pragma (Aitem); | |
2478 | end if; | |
2479 | ||
2480 | goto Continue; | |
2481 | end Ghost; | |
2482 | ||
0fd13d32 | 2483 | -- Global |
12334c57 | 2484 | |
e2bf777d | 2485 | -- Aspect Global is never delayed because it is equivalent to |
2486 | -- a source pragma which appears after the related subprogram. | |
2487 | -- To deal with forward references, the generated pragma is | |
2488 | -- stored in the contract of the related subprogram and later | |
2489 | -- analyzed at the end of the declarative region. See routine | |
2490 | -- Analyze_Global_In_Decl_Part for details. | |
3cdbaa5a | 2491 | |
2492 | when Aspect_Global => | |
0fd13d32 | 2493 | Make_Aitem_Pragma |
2494 | (Pragma_Argument_Associations => New_List ( | |
2495 | Make_Pragma_Argument_Association (Loc, | |
2496 | Expression => Relocate_Node (Expr))), | |
2497 | Pragma_Name => Name_Global); | |
2498 | ||
e2bf777d | 2499 | Decorate (Aspect, Aitem); |
2500 | Insert_Pragma (Aitem); | |
c1006d6d | 2501 | goto Continue; |
2502 | ||
9c138530 | 2503 | -- Initial_Condition |
2504 | ||
e2bf777d | 2505 | -- Aspect Initial_Condition is never delayed because it is |
2506 | -- equivalent to a source pragma which appears after the | |
2507 | -- related package. To deal with forward references, the | |
2508 | -- generated pragma is stored in the contract of the related | |
2509 | -- package and later analyzed at the end of the declarative | |
2510 | -- region. See routine Analyze_Initial_Condition_In_Decl_Part | |
2511 | -- for details. | |
9c138530 | 2512 | |
2513 | when Aspect_Initial_Condition => Initial_Condition : declare | |
eb4f7efa | 2514 | Context : Node_Id := N; |
2515 | Decls : List_Id; | |
9c138530 | 2516 | |
2517 | begin | |
e2bf777d | 2518 | -- When aspect Initial_Condition appears on a generic |
2519 | -- package, it is propageted to the package instance. The | |
2520 | -- context in this case is the instance spec. | |
eb4f7efa | 2521 | |
2522 | if Nkind (Context) = N_Package_Instantiation then | |
2523 | Context := Instance_Spec (Context); | |
2524 | end if; | |
2525 | ||
2526 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2527 | N_Package_Declaration) | |
9c138530 | 2528 | then |
eb4f7efa | 2529 | Decls := Visible_Declarations (Specification (Context)); |
9c138530 | 2530 | |
2531 | Make_Aitem_Pragma | |
2532 | (Pragma_Argument_Associations => New_List ( | |
2533 | Make_Pragma_Argument_Association (Loc, | |
2534 | Expression => Relocate_Node (Expr))), | |
2535 | Pragma_Name => | |
2536 | Name_Initial_Condition); | |
e2bf777d | 2537 | Decorate (Aspect, Aitem); |
9c138530 | 2538 | |
2539 | if No (Decls) then | |
2540 | Decls := New_List; | |
eb4f7efa | 2541 | Set_Visible_Declarations (Context, Decls); |
9c138530 | 2542 | end if; |
2543 | ||
3dbe7a69 | 2544 | -- When aspects Abstract_State, Ghost, Initial_Condition |
2545 | -- and Initializes are out of order, ensure that pragma | |
2546 | -- SPARK_Mode is always at the top of the declarations to | |
2547 | -- properly enabled/suppress errors. | |
50e44732 | 2548 | |
2549 | Insert_After_SPARK_Mode | |
2550 | (Prag => Aitem, | |
2551 | Ins_Nod => First (Decls), | |
2552 | Decls => Decls); | |
9c138530 | 2553 | |
2554 | else | |
2555 | Error_Msg_NE | |
2556 | ("aspect & must apply to a package declaration", | |
2557 | Aspect, Id); | |
2558 | end if; | |
2559 | ||
2560 | goto Continue; | |
2561 | end Initial_Condition; | |
2562 | ||
d4e369ad | 2563 | -- Initializes |
2564 | ||
e2bf777d | 2565 | -- Aspect Initializes is never delayed because it is equivalent |
2566 | -- to a source pragma appearing after the related package. To | |
2567 | -- deal with forward references, the generated pragma is stored | |
2568 | -- in the contract of the related package and later analyzed at | |
2569 | -- the end of the declarative region. For details, see routine | |
2570 | -- Analyze_Initializes_In_Decl_Part. | |
d4e369ad | 2571 | |
2572 | when Aspect_Initializes => Initializes : declare | |
eb4f7efa | 2573 | Context : Node_Id := N; |
2574 | Decls : List_Id; | |
d4e369ad | 2575 | |
2576 | begin | |
50e44732 | 2577 | -- When aspect Initializes appears on a generic package, |
2578 | -- it is propageted to the package instance. The context | |
2579 | -- in this case is the instance spec. | |
eb4f7efa | 2580 | |
2581 | if Nkind (Context) = N_Package_Instantiation then | |
2582 | Context := Instance_Spec (Context); | |
2583 | end if; | |
2584 | ||
2585 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2586 | N_Package_Declaration) | |
d4e369ad | 2587 | then |
eb4f7efa | 2588 | Decls := Visible_Declarations (Specification (Context)); |
d4e369ad | 2589 | |
2590 | Make_Aitem_Pragma | |
2591 | (Pragma_Argument_Associations => New_List ( | |
2592 | Make_Pragma_Argument_Association (Loc, | |
2593 | Expression => Relocate_Node (Expr))), | |
2594 | Pragma_Name => Name_Initializes); | |
e2bf777d | 2595 | Decorate (Aspect, Aitem); |
d4e369ad | 2596 | |
2597 | if No (Decls) then | |
2598 | Decls := New_List; | |
eb4f7efa | 2599 | Set_Visible_Declarations (Context, Decls); |
d4e369ad | 2600 | end if; |
2601 | ||
3dbe7a69 | 2602 | -- When aspects Abstract_State, Ghost, Initial_Condition |
2603 | -- and Initializes are out of order, ensure that pragma | |
2604 | -- SPARK_Mode is always at the top of the declarations to | |
2605 | -- properly enabled/suppress errors. | |
50e44732 | 2606 | |
2607 | Insert_After_SPARK_Mode | |
2608 | (Prag => Aitem, | |
2609 | Ins_Nod => First (Decls), | |
2610 | Decls => Decls); | |
d4e369ad | 2611 | |
2612 | else | |
2613 | Error_Msg_NE | |
2614 | ("aspect & must apply to a package declaration", | |
2615 | Aspect, Id); | |
2616 | end if; | |
2617 | ||
2618 | goto Continue; | |
2619 | end Initializes; | |
2620 | ||
1fd4313f | 2621 | -- Obsolescent |
2622 | ||
2623 | when Aspect_Obsolescent => declare | |
2624 | Args : List_Id; | |
2625 | ||
2626 | begin | |
2627 | if No (Expr) then | |
2628 | Args := No_List; | |
2629 | else | |
2630 | Args := New_List ( | |
2631 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2632 | Expression => Relocate_Node (Expr))); | |
2633 | end if; | |
2634 | ||
2635 | Make_Aitem_Pragma | |
2636 | (Pragma_Argument_Associations => Args, | |
2637 | Pragma_Name => Chars (Id)); | |
2638 | end; | |
2639 | ||
5cc6f0cf | 2640 | -- Part_Of |
2641 | ||
2642 | when Aspect_Part_Of => | |
2643 | if Nkind_In (N, N_Object_Declaration, | |
2644 | N_Package_Instantiation) | |
2645 | then | |
2646 | Make_Aitem_Pragma | |
2647 | (Pragma_Argument_Associations => New_List ( | |
2648 | Make_Pragma_Argument_Association (Loc, | |
2649 | Expression => Relocate_Node (Expr))), | |
2650 | Pragma_Name => Name_Part_Of); | |
2651 | ||
2652 | else | |
2653 | Error_Msg_NE | |
2654 | ("aspect & must apply to a variable or package " | |
2655 | & "instantiation", Aspect, Id); | |
2656 | end if; | |
2657 | ||
5dd93a61 | 2658 | -- SPARK_Mode |
2659 | ||
778ebf56 | 2660 | when Aspect_SPARK_Mode => SPARK_Mode : declare |
2661 | Decls : List_Id; | |
2662 | ||
2663 | begin | |
5dd93a61 | 2664 | Make_Aitem_Pragma |
2665 | (Pragma_Argument_Associations => New_List ( | |
2666 | Make_Pragma_Argument_Association (Loc, | |
2667 | Expression => Relocate_Node (Expr))), | |
2668 | Pragma_Name => Name_SPARK_Mode); | |
5dd93a61 | 2669 | |
b90d9656 | 2670 | -- When the aspect appears on a package or a subprogram |
2671 | -- body, insert the generated pragma at the top of the body | |
2672 | -- declarations to emulate the behavior of a source pragma. | |
778ebf56 | 2673 | |
b90d9656 | 2674 | if Nkind_In (N, N_Package_Body, N_Subprogram_Body) then |
e2bf777d | 2675 | Decorate (Aspect, Aitem); |
5cc6f0cf | 2676 | |
778ebf56 | 2677 | Decls := Declarations (N); |
2678 | ||
2679 | if No (Decls) then | |
2680 | Decls := New_List; | |
2681 | Set_Declarations (N, Decls); | |
2682 | end if; | |
2683 | ||
a04f9d2e | 2684 | Prepend_To (Decls, Aitem); |
2685 | goto Continue; | |
2686 | ||
b90d9656 | 2687 | -- When the aspect is associated with a [generic] package |
2688 | -- declaration, insert the generated pragma at the top of | |
2689 | -- the visible declarations to emulate the behavior of a | |
2690 | -- source pragma. | |
a04f9d2e | 2691 | |
b90d9656 | 2692 | elsif Nkind_In (N, N_Generic_Package_Declaration, |
2693 | N_Package_Declaration) | |
2694 | then | |
e2bf777d | 2695 | Decorate (Aspect, Aitem); |
5cc6f0cf | 2696 | |
a04f9d2e | 2697 | Decls := Visible_Declarations (Specification (N)); |
2698 | ||
2699 | if No (Decls) then | |
2700 | Decls := New_List; | |
2701 | Set_Visible_Declarations (Specification (N), Decls); | |
2702 | end if; | |
2703 | ||
778ebf56 | 2704 | Prepend_To (Decls, Aitem); |
2705 | goto Continue; | |
2706 | end if; | |
2707 | end SPARK_Mode; | |
2708 | ||
4befb1a0 | 2709 | -- Refined_Depends |
2710 | ||
e2bf777d | 2711 | -- Aspect Refined_Depends is never delayed because it is |
2712 | -- equivalent to a source pragma which appears in the | |
2713 | -- declarations of the related subprogram body. To deal with | |
2714 | -- forward references, the generated pragma is stored in the | |
2715 | -- contract of the related subprogram body and later analyzed | |
2716 | -- at the end of the declarative region. For details, see | |
2717 | -- routine Analyze_Refined_Depends_In_Decl_Part. | |
4befb1a0 | 2718 | |
2719 | when Aspect_Refined_Depends => | |
422073ed | 2720 | Make_Aitem_Pragma |
2721 | (Pragma_Argument_Associations => New_List ( | |
2722 | Make_Pragma_Argument_Association (Loc, | |
2723 | Expression => Relocate_Node (Expr))), | |
2724 | Pragma_Name => Name_Refined_Depends); | |
2725 | ||
e2bf777d | 2726 | Decorate (Aspect, Aitem); |
2727 | Insert_Pragma (Aitem); | |
422073ed | 2728 | goto Continue; |
4befb1a0 | 2729 | |
2730 | -- Refined_Global | |
2731 | ||
e2bf777d | 2732 | -- Aspect Refined_Global is never delayed because it is |
2733 | -- equivalent to a source pragma which appears in the | |
2734 | -- declarations of the related subprogram body. To deal with | |
2735 | -- forward references, the generated pragma is stored in the | |
2736 | -- contract of the related subprogram body and later analyzed | |
2737 | -- at the end of the declarative region. For details, see | |
2738 | -- routine Analyze_Refined_Global_In_Decl_Part. | |
4befb1a0 | 2739 | |
2740 | when Aspect_Refined_Global => | |
28ff117f | 2741 | Make_Aitem_Pragma |
2742 | (Pragma_Argument_Associations => New_List ( | |
2743 | Make_Pragma_Argument_Association (Loc, | |
2744 | Expression => Relocate_Node (Expr))), | |
2745 | Pragma_Name => Name_Refined_Global); | |
2746 | ||
e2bf777d | 2747 | Decorate (Aspect, Aitem); |
2748 | Insert_Pragma (Aitem); | |
28ff117f | 2749 | goto Continue; |
4befb1a0 | 2750 | |
63b65b2d | 2751 | -- Refined_Post |
2752 | ||
2753 | when Aspect_Refined_Post => | |
2754 | Make_Aitem_Pragma | |
2755 | (Pragma_Argument_Associations => New_List ( | |
2756 | Make_Pragma_Argument_Association (Loc, | |
2757 | Expression => Relocate_Node (Expr))), | |
2758 | Pragma_Name => Name_Refined_Post); | |
2759 | ||
9129c28f | 2760 | -- Refined_State |
2761 | ||
2762 | when Aspect_Refined_State => Refined_State : declare | |
2763 | Decls : List_Id; | |
2764 | ||
2765 | begin | |
2766 | -- The corresponding pragma for Refined_State is inserted in | |
2767 | -- the declarations of the related package body. This action | |
2768 | -- synchronizes both the source and from-aspect versions of | |
2769 | -- the pragma. | |
2770 | ||
2771 | if Nkind (N) = N_Package_Body then | |
e2bf777d | 2772 | Decls := Declarations (N); |
2773 | ||
9129c28f | 2774 | Make_Aitem_Pragma |
2775 | (Pragma_Argument_Associations => New_List ( | |
2776 | Make_Pragma_Argument_Association (Loc, | |
2777 | Expression => Relocate_Node (Expr))), | |
2778 | Pragma_Name => Name_Refined_State); | |
e2bf777d | 2779 | Decorate (Aspect, Aitem); |
b9b2d6e5 | 2780 | |
e2bf777d | 2781 | if No (Decls) then |
2782 | Decls := New_List; | |
2783 | Set_Declarations (N, Decls); | |
2784 | end if; | |
b9b2d6e5 | 2785 | |
e2bf777d | 2786 | -- Pragma Refined_State must be inserted after pragma |
2787 | -- SPARK_Mode in the tree. This ensures that any error | |
2788 | -- messages dependent on SPARK_Mode will be properly | |
2789 | -- enabled/suppressed. | |
b9b2d6e5 | 2790 | |
e2bf777d | 2791 | Insert_After_SPARK_Mode |
2792 | (Prag => Aitem, | |
2793 | Ins_Nod => First (Decls), | |
2794 | Decls => Decls); | |
9129c28f | 2795 | |
2796 | else | |
2797 | Error_Msg_NE | |
2798 | ("aspect & must apply to a package body", Aspect, Id); | |
2799 | end if; | |
2800 | ||
2801 | goto Continue; | |
2802 | end Refined_State; | |
2803 | ||
0fd13d32 | 2804 | -- Relative_Deadline |
3cdbaa5a | 2805 | |
2806 | when Aspect_Relative_Deadline => | |
0fd13d32 | 2807 | Make_Aitem_Pragma |
2808 | (Pragma_Argument_Associations => New_List ( | |
2809 | Make_Pragma_Argument_Association (Loc, | |
2810 | Expression => Relocate_Node (Expr))), | |
2811 | Pragma_Name => Name_Relative_Deadline); | |
47a46747 | 2812 | |
2813 | -- If the aspect applies to a task, the corresponding pragma | |
2814 | -- must appear within its declarations, not after. | |
2815 | ||
2816 | if Nkind (N) = N_Task_Type_Declaration then | |
2817 | declare | |
2818 | Def : Node_Id; | |
2819 | V : List_Id; | |
2820 | ||
2821 | begin | |
2822 | if No (Task_Definition (N)) then | |
2823 | Set_Task_Definition (N, | |
2824 | Make_Task_Definition (Loc, | |
2825 | Visible_Declarations => New_List, | |
2826 | End_Label => Empty)); | |
2827 | end if; | |
2828 | ||
2829 | Def := Task_Definition (N); | |
2830 | V := Visible_Declarations (Def); | |
2831 | if not Is_Empty_List (V) then | |
2832 | Insert_Before (First (V), Aitem); | |
2833 | ||
2834 | else | |
2835 | Set_Visible_Declarations (Def, New_List (Aitem)); | |
2836 | end if; | |
2837 | ||
2838 | goto Continue; | |
2839 | end; | |
2840 | end if; | |
2841 | ||
85ee12c0 | 2842 | -- Aspect Volatile_Function is never delayed because it is |
2843 | -- equivalent to a source pragma which appears after the | |
2844 | -- related subprogram. | |
2845 | ||
2846 | when Aspect_Volatile_Function => | |
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_Volatile_Function); | |
2852 | ||
2853 | Decorate (Aspect, Aitem); | |
2854 | Insert_Pragma (Aitem); | |
2855 | goto Continue; | |
2856 | ||
956ffaf4 | 2857 | -- Case 2e: Annotate aspect |
2858 | ||
2859 | when Aspect_Annotate => | |
2860 | declare | |
2861 | Args : List_Id; | |
2862 | Pargs : List_Id; | |
2863 | Arg : Node_Id; | |
2864 | ||
2865 | begin | |
2866 | -- The argument can be a single identifier | |
2867 | ||
2868 | if Nkind (Expr) = N_Identifier then | |
2869 | ||
2870 | -- One level of parens is allowed | |
2871 | ||
2872 | if Paren_Count (Expr) > 1 then | |
2873 | Error_Msg_F ("extra parentheses ignored", Expr); | |
2874 | end if; | |
2875 | ||
2876 | Set_Paren_Count (Expr, 0); | |
2877 | ||
2878 | -- Add the single item to the list | |
2879 | ||
2880 | Args := New_List (Expr); | |
2881 | ||
2882 | -- Otherwise we must have an aggregate | |
2883 | ||
2884 | elsif Nkind (Expr) = N_Aggregate then | |
2885 | ||
2886 | -- Must be positional | |
2887 | ||
2888 | if Present (Component_Associations (Expr)) then | |
2889 | Error_Msg_F | |
2890 | ("purely positional aggregate required", Expr); | |
2891 | goto Continue; | |
2892 | end if; | |
2893 | ||
2894 | -- Must not be parenthesized | |
2895 | ||
2896 | if Paren_Count (Expr) /= 0 then | |
2897 | Error_Msg_F ("extra parentheses ignored", Expr); | |
2898 | end if; | |
2899 | ||
2900 | -- List of arguments is list of aggregate expressions | |
2901 | ||
2902 | Args := Expressions (Expr); | |
2903 | ||
2904 | -- Anything else is illegal | |
2905 | ||
2906 | else | |
2907 | Error_Msg_F ("wrong form for Annotate aspect", Expr); | |
2908 | goto Continue; | |
2909 | end if; | |
2910 | ||
2911 | -- Prepare pragma arguments | |
2912 | ||
2913 | Pargs := New_List; | |
2914 | Arg := First (Args); | |
2915 | while Present (Arg) loop | |
2916 | Append_To (Pargs, | |
2917 | Make_Pragma_Argument_Association (Sloc (Arg), | |
2918 | Expression => Relocate_Node (Arg))); | |
2919 | Next (Arg); | |
2920 | end loop; | |
2921 | ||
2922 | Append_To (Pargs, | |
2923 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2924 | Chars => Name_Entity, | |
2925 | Expression => Ent)); | |
2926 | ||
2927 | Make_Aitem_Pragma | |
2928 | (Pragma_Argument_Associations => Pargs, | |
2929 | Pragma_Name => Name_Annotate); | |
2930 | end; | |
2931 | ||
89f1e35c | 2932 | -- Case 3 : Aspects that don't correspond to pragma/attribute |
2933 | -- definition clause. | |
7b9b2f05 | 2934 | |
89f1e35c | 2935 | -- Case 3a: The aspects listed below don't correspond to |
2936 | -- pragmas/attributes but do require delayed analysis. | |
7f694ca2 | 2937 | |
51fa2a45 | 2938 | -- Default_Value can only apply to a scalar type |
2939 | ||
2940 | when Aspect_Default_Value => | |
2941 | if not Is_Scalar_Type (E) then | |
2942 | Error_Msg_N | |
1089ff19 | 2943 | ("aspect Default_Value must apply to a scalar type", N); |
51fa2a45 | 2944 | end if; |
2945 | ||
2946 | Aitem := Empty; | |
2947 | ||
2948 | -- Default_Component_Value can only apply to an array type | |
2949 | -- with scalar components. | |
2950 | ||
2951 | when Aspect_Default_Component_Value => | |
2952 | if not (Is_Array_Type (E) | |
3f4c9ffc | 2953 | and then Is_Scalar_Type (Component_Type (E))) |
51fa2a45 | 2954 | then |
2955 | Error_Msg_N ("aspect Default_Component_Value can only " | |
2956 | & "apply to an array of scalar components", N); | |
2957 | end if; | |
0fd13d32 | 2958 | |
89f1e35c | 2959 | Aitem := Empty; |
7f694ca2 | 2960 | |
89f1e35c | 2961 | -- Case 3b: The aspects listed below don't correspond to |
2962 | -- pragmas/attributes and don't need delayed analysis. | |
95bc75fa | 2963 | |
0fd13d32 | 2964 | -- Implicit_Dereference |
2965 | ||
89f1e35c | 2966 | -- For Implicit_Dereference, External_Name and Link_Name, only |
2967 | -- the legality checks are done during the analysis, thus no | |
2968 | -- delay is required. | |
a8e38e1d | 2969 | |
89f1e35c | 2970 | when Aspect_Implicit_Dereference => |
2971 | Analyze_Aspect_Implicit_Dereference; | |
2972 | goto Continue; | |
7f694ca2 | 2973 | |
0fd13d32 | 2974 | -- External_Name, Link_Name |
2975 | ||
89f1e35c | 2976 | when Aspect_External_Name | |
2977 | Aspect_Link_Name => | |
2978 | Analyze_Aspect_External_Or_Link_Name; | |
2979 | goto Continue; | |
7f694ca2 | 2980 | |
0fd13d32 | 2981 | -- Dimension |
2982 | ||
89f1e35c | 2983 | when Aspect_Dimension => |
2984 | Analyze_Aspect_Dimension (N, Id, Expr); | |
2985 | goto Continue; | |
cb4c311d | 2986 | |
0fd13d32 | 2987 | -- Dimension_System |
2988 | ||
89f1e35c | 2989 | when Aspect_Dimension_System => |
2990 | Analyze_Aspect_Dimension_System (N, Id, Expr); | |
2991 | goto Continue; | |
7f694ca2 | 2992 | |
ceec4f7c | 2993 | -- Case 4: Aspects requiring special handling |
51ea9c94 | 2994 | |
e66f4e2a | 2995 | -- Pre/Post/Test_Case/Contract_Cases whose corresponding |
2996 | -- pragmas take care of the delay. | |
7f694ca2 | 2997 | |
0fd13d32 | 2998 | -- Pre/Post |
2999 | ||
1e3c4ae6 | 3000 | -- Aspects Pre/Post generate Precondition/Postcondition pragmas |
3001 | -- with a first argument that is the expression, and a second | |
3002 | -- argument that is an informative message if the test fails. | |
3003 | -- This is inserted right after the declaration, to get the | |
5b5df4a9 | 3004 | -- required pragma placement. The processing for the pragmas |
3005 | -- takes care of the required delay. | |
ae888dbd | 3006 | |
5ddd846b | 3007 | when Pre_Post_Aspects => Pre_Post : declare |
1e3c4ae6 | 3008 | Pname : Name_Id; |
ae888dbd | 3009 | |
1e3c4ae6 | 3010 | begin |
77ae6789 | 3011 | if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then |
1e3c4ae6 | 3012 | Pname := Name_Precondition; |
3013 | else | |
3014 | Pname := Name_Postcondition; | |
3015 | end if; | |
d74fc39a | 3016 | |
1e3c4ae6 | 3017 | -- If the expressions is of the form A and then B, then |
3018 | -- we generate separate Pre/Post aspects for the separate | |
3019 | -- clauses. Since we allow multiple pragmas, there is no | |
3020 | -- problem in allowing multiple Pre/Post aspects internally. | |
a273015d | 3021 | -- These should be treated in reverse order (B first and |
3022 | -- A second) since they are later inserted just after N in | |
3023 | -- the order they are treated. This way, the pragma for A | |
3024 | -- ends up preceding the pragma for B, which may have an | |
3025 | -- importance for the error raised (either constraint error | |
3026 | -- or precondition error). | |
1e3c4ae6 | 3027 | |
39e1f22f | 3028 | -- We do not do this for Pre'Class, since we have to put |
51fa2a45 | 3029 | -- these conditions together in a complex OR expression. |
ae888dbd | 3030 | |
4282d342 | 3031 | -- We do not do this in ASIS mode, as ASIS relies on the |
3032 | -- original node representing the complete expression, when | |
3033 | -- retrieving it through the source aspect table. | |
3034 | ||
3035 | if not ASIS_Mode | |
3036 | and then (Pname = Name_Postcondition | |
3037 | or else not Class_Present (Aspect)) | |
39e1f22f | 3038 | then |
3039 | while Nkind (Expr) = N_And_Then loop | |
3040 | Insert_After (Aspect, | |
a273015d | 3041 | Make_Aspect_Specification (Sloc (Left_Opnd (Expr)), |
39e1f22f | 3042 | Identifier => Identifier (Aspect), |
a273015d | 3043 | Expression => Relocate_Node (Left_Opnd (Expr)), |
39e1f22f | 3044 | Class_Present => Class_Present (Aspect), |
3045 | Split_PPC => True)); | |
a273015d | 3046 | Rewrite (Expr, Relocate_Node (Right_Opnd (Expr))); |
39e1f22f | 3047 | Eloc := Sloc (Expr); |
3048 | end loop; | |
3049 | end if; | |
ae888dbd | 3050 | |
48d6f069 | 3051 | -- Build the precondition/postcondition pragma |
3052 | ||
51fa2a45 | 3053 | -- Add note about why we do NOT need Copy_Tree here??? |
d74fc39a | 3054 | |
0fd13d32 | 3055 | Make_Aitem_Pragma |
3056 | (Pragma_Argument_Associations => New_List ( | |
3057 | Make_Pragma_Argument_Association (Eloc, | |
3058 | Chars => Name_Check, | |
a19e1763 | 3059 | Expression => Relocate_Node (Expr))), |
0fd13d32 | 3060 | Pragma_Name => Pname); |
39e1f22f | 3061 | |
3062 | -- Add message unless exception messages are suppressed | |
3063 | ||
3064 | if not Opt.Exception_Locations_Suppressed then | |
3065 | Append_To (Pragma_Argument_Associations (Aitem), | |
3066 | Make_Pragma_Argument_Association (Eloc, | |
ed695684 | 3067 | Chars => Name_Message, |
39e1f22f | 3068 | Expression => |
3069 | Make_String_Literal (Eloc, | |
3070 | Strval => "failed " | |
3071 | & Get_Name_String (Pname) | |
3072 | & " from " | |
3073 | & Build_Location_String (Eloc)))); | |
3074 | end if; | |
d74fc39a | 3075 | |
7d20685d | 3076 | Set_Is_Delayed_Aspect (Aspect); |
d74fc39a | 3077 | |
1e3c4ae6 | 3078 | -- For Pre/Post cases, insert immediately after the entity |
3079 | -- declaration, since that is the required pragma placement. | |
3080 | -- Note that for these aspects, we do not have to worry | |
3081 | -- about delay issues, since the pragmas themselves deal | |
3082 | -- with delay of visibility for the expression analysis. | |
3083 | ||
e2bf777d | 3084 | Insert_Pragma (Aitem); |
299b347e | 3085 | |
1e3c4ae6 | 3086 | goto Continue; |
5ddd846b | 3087 | end Pre_Post; |
ae888dbd | 3088 | |
0fd13d32 | 3089 | -- Test_Case |
3090 | ||
e66f4e2a | 3091 | when Aspect_Test_Case => Test_Case : declare |
3092 | Args : List_Id; | |
3093 | Comp_Expr : Node_Id; | |
3094 | Comp_Assn : Node_Id; | |
3095 | New_Expr : Node_Id; | |
57cd943b | 3096 | |
e66f4e2a | 3097 | begin |
3098 | Args := New_List; | |
b0bc40fd | 3099 | |
e66f4e2a | 3100 | if Nkind (Parent (N)) = N_Compilation_Unit then |
3101 | Error_Msg_Name_1 := Nam; | |
3102 | Error_Msg_N ("incorrect placement of aspect `%`", E); | |
3103 | goto Continue; | |
3104 | end if; | |
6c545057 | 3105 | |
e66f4e2a | 3106 | if Nkind (Expr) /= N_Aggregate then |
3107 | Error_Msg_Name_1 := Nam; | |
3108 | Error_Msg_NE | |
3109 | ("wrong syntax for aspect `%` for &", Id, E); | |
3110 | goto Continue; | |
3111 | end if; | |
6c545057 | 3112 | |
e66f4e2a | 3113 | -- Make pragma expressions refer to the original aspect |
51fa2a45 | 3114 | -- expressions through the Original_Node link. This is used |
3115 | -- in semantic analysis for ASIS mode, so that the original | |
3116 | -- expression also gets analyzed. | |
e66f4e2a | 3117 | |
3118 | Comp_Expr := First (Expressions (Expr)); | |
3119 | while Present (Comp_Expr) loop | |
3120 | New_Expr := Relocate_Node (Comp_Expr); | |
e66f4e2a | 3121 | Append_To (Args, |
3122 | Make_Pragma_Argument_Association (Sloc (Comp_Expr), | |
3123 | Expression => New_Expr)); | |
3124 | Next (Comp_Expr); | |
3125 | end loop; | |
3126 | ||
3127 | Comp_Assn := First (Component_Associations (Expr)); | |
3128 | while Present (Comp_Assn) loop | |
3129 | if List_Length (Choices (Comp_Assn)) /= 1 | |
3130 | or else | |
3131 | Nkind (First (Choices (Comp_Assn))) /= N_Identifier | |
3132 | then | |
fad014fe | 3133 | Error_Msg_Name_1 := Nam; |
6c545057 | 3134 | Error_Msg_NE |
fad014fe | 3135 | ("wrong syntax for aspect `%` for &", Id, E); |
6c545057 | 3136 | goto Continue; |
3137 | end if; | |
3138 | ||
e66f4e2a | 3139 | Append_To (Args, |
3140 | Make_Pragma_Argument_Association (Sloc (Comp_Assn), | |
ed695684 | 3141 | Chars => Chars (First (Choices (Comp_Assn))), |
3142 | Expression => | |
3143 | Relocate_Node (Expression (Comp_Assn)))); | |
e66f4e2a | 3144 | Next (Comp_Assn); |
3145 | end loop; | |
6c545057 | 3146 | |
e66f4e2a | 3147 | -- Build the test-case pragma |
6c545057 | 3148 | |
0fd13d32 | 3149 | Make_Aitem_Pragma |
3150 | (Pragma_Argument_Associations => Args, | |
3151 | Pragma_Name => Nam); | |
e66f4e2a | 3152 | end Test_Case; |
85696508 | 3153 | |
0fd13d32 | 3154 | -- Contract_Cases |
3155 | ||
5ddd846b | 3156 | when Aspect_Contract_Cases => |
0fd13d32 | 3157 | Make_Aitem_Pragma |
3158 | (Pragma_Argument_Associations => New_List ( | |
3159 | Make_Pragma_Argument_Association (Loc, | |
3160 | Expression => Relocate_Node (Expr))), | |
3161 | Pragma_Name => Nam); | |
3a128918 | 3162 | |
e2bf777d | 3163 | Decorate (Aspect, Aitem); |
3164 | Insert_Pragma (Aitem); | |
5ddd846b | 3165 | goto Continue; |
3a128918 | 3166 | |
89f1e35c | 3167 | -- Case 5: Special handling for aspects with an optional |
3168 | -- boolean argument. | |
85696508 | 3169 | |
6c5793cd | 3170 | -- In the delayed case, the corresponding pragma cannot be |
0fd13d32 | 3171 | -- generated yet because the evaluation of the boolean needs |
3172 | -- to be delayed till the freeze point. | |
3173 | ||
89f1e35c | 3174 | when Boolean_Aspects | |
3175 | Library_Unit_Aspects => | |
a5a64273 | 3176 | |
89f1e35c | 3177 | Set_Is_Boolean_Aspect (Aspect); |
a5a64273 | 3178 | |
89f1e35c | 3179 | -- Lock_Free aspect only apply to protected objects |
e1cedbae | 3180 | |
89f1e35c | 3181 | if A_Id = Aspect_Lock_Free then |
3182 | if Ekind (E) /= E_Protected_Type then | |
99a2d5bd | 3183 | Error_Msg_Name_1 := Nam; |
a5a64273 | 3184 | Error_Msg_N |
89f1e35c | 3185 | ("aspect % only applies to a protected object", |
3186 | Aspect); | |
3187 | ||
3188 | else | |
3189 | -- Set the Uses_Lock_Free flag to True if there is no | |
37c6e44c | 3190 | -- expression or if the expression is True. The |
89f1e35c | 3191 | -- evaluation of this aspect should be delayed to the |
37c6e44c | 3192 | -- freeze point (why???) |
89f1e35c | 3193 | |
e81df51c | 3194 | if No (Expr) |
3195 | or else Is_True (Static_Boolean (Expr)) | |
89f1e35c | 3196 | then |
3197 | Set_Uses_Lock_Free (E); | |
3198 | end if; | |
caf125ce | 3199 | |
3200 | Record_Rep_Item (E, Aspect); | |
a5a64273 | 3201 | end if; |
e1cedbae | 3202 | |
89f1e35c | 3203 | goto Continue; |
ae888dbd | 3204 | |
17631aa0 | 3205 | elsif A_Id = Aspect_Import or else A_Id = Aspect_Export then |
d74fc39a | 3206 | |
39616053 | 3207 | -- For the case of aspects Import and Export, we don't |
3208 | -- consider that we know the entity is never set in the | |
3209 | -- source, since it is is likely modified outside the | |
3210 | -- program. | |
3211 | ||
3212 | -- Note: one might think that the analysis of the | |
3213 | -- resulting pragma would take care of that, but | |
3214 | -- that's not the case since it won't be from source. | |
3215 | ||
3216 | if Ekind (E) = E_Variable then | |
3217 | Set_Never_Set_In_Source (E, False); | |
3218 | end if; | |
3219 | ||
2e1821c9 | 3220 | -- In older versions of Ada the corresponding pragmas |
51fa2a45 | 3221 | -- specified a Convention. In Ada 2012 the convention is |
3222 | -- specified as a separate aspect, and it is optional, | |
2e1821c9 | 3223 | -- given that it defaults to Convention_Ada. The code |
3224 | -- that verifed that there was a matching convention | |
3225 | -- is now obsolete. | |
d74fc39a | 3226 | |
718d0d92 | 3227 | -- Resolve the expression of an Import or Export here, |
3228 | -- and require it to be of type Boolean and static. This | |
3229 | -- is not quite right, because in general this should be | |
3230 | -- delayed, but that seems tricky for these, because | |
3231 | -- normally Boolean aspects are replaced with pragmas at | |
3232 | -- the freeze point (in Make_Pragma_From_Boolean_Aspect), | |
3233 | -- but in the case of these aspects we can't generate | |
3234 | -- a simple pragma with just the entity name. ??? | |
3235 | ||
3236 | if not Present (Expr) | |
3237 | or else Is_True (Static_Boolean (Expr)) | |
3238 | then | |
3239 | if A_Id = Aspect_Import then | |
3240 | Set_Is_Imported (E); | |
19a2e7b4 | 3241 | Set_Has_Completion (E); |
dd4c44af | 3242 | |
718d0d92 | 3243 | -- An imported entity cannot have an explicit |
3244 | -- initialization. | |
dd4c44af | 3245 | |
718d0d92 | 3246 | if Nkind (N) = N_Object_Declaration |
3247 | and then Present (Expression (N)) | |
3248 | then | |
3249 | Error_Msg_N | |
3250 | ("imported entities cannot be initialized " | |
3251 | & "(RM B.1(24))", Expression (N)); | |
3252 | end if; | |
3253 | ||
3254 | elsif A_Id = Aspect_Export then | |
3255 | Set_Is_Exported (E); | |
dd4c44af | 3256 | end if; |
3257 | end if; | |
3258 | ||
6c5793cd | 3259 | goto Continue; |
3260 | ||
3261 | -- Disable_Controlled | |
3262 | ||
3263 | elsif A_Id = Aspect_Disable_Controlled then | |
3264 | if Ekind (E) /= E_Record_Type | |
3265 | or else not Is_Controlled (E) | |
3266 | then | |
3267 | Error_Msg_N | |
3268 | ("aspect % requires controlled record type", Aspect); | |
3269 | goto Continue; | |
3270 | end if; | |
3271 | ||
3f716509 | 3272 | -- If we're in a generic template, we don't want to try |
3273 | -- to disable controlled types, because typical usage is | |
3274 | -- "Disable_Controlled => not <some_check>'Enabled", and | |
3275 | -- the value of Enabled is not known until we see a | |
7e2d3667 | 3276 | -- particular instance. In such a context, we just need |
3277 | -- to preanalyze the expression for legality. | |
3f716509 | 3278 | |
3279 | if Expander_Active then | |
aae9bc79 | 3280 | Analyze_And_Resolve (Expr, Standard_Boolean); |
3281 | ||
3f716509 | 3282 | if not Present (Expr) |
3283 | or else Is_True (Static_Boolean (Expr)) | |
3284 | then | |
3285 | Set_Disable_Controlled (E); | |
3286 | end if; | |
7e2d3667 | 3287 | |
3288 | elsif Serious_Errors_Detected = 0 then | |
3289 | Preanalyze_And_Resolve (Expr, Standard_Boolean); | |
6c5793cd | 3290 | end if; |
3291 | ||
89f1e35c | 3292 | goto Continue; |
3293 | end if; | |
d74fc39a | 3294 | |
37c6e44c | 3295 | -- Library unit aspects require special handling in the case |
3296 | -- of a package declaration, the pragma needs to be inserted | |
3297 | -- in the list of declarations for the associated package. | |
3298 | -- There is no issue of visibility delay for these aspects. | |
d64221a7 | 3299 | |
89f1e35c | 3300 | if A_Id in Library_Unit_Aspects |
178fec9b | 3301 | and then |
3302 | Nkind_In (N, N_Package_Declaration, | |
3303 | N_Generic_Package_Declaration) | |
89f1e35c | 3304 | and then Nkind (Parent (N)) /= N_Compilation_Unit |
3ad60f63 | 3305 | |
3306 | -- Aspect is legal on a local instantiation of a library- | |
3307 | -- level generic unit. | |
3308 | ||
b94a633e | 3309 | and then not Is_Generic_Instance (Defining_Entity (N)) |
89f1e35c | 3310 | then |
3311 | Error_Msg_N | |
dd4c44af | 3312 | ("incorrect context for library unit aspect&", Id); |
89f1e35c | 3313 | goto Continue; |
3314 | end if; | |
cce84b09 | 3315 | |
51fa2a45 | 3316 | -- Cases where we do not delay, includes all cases where the |
3317 | -- expression is missing other than the above cases. | |
d74fc39a | 3318 | |
85ee12c0 | 3319 | if not Delay_Required or else No (Expr) then |
0fd13d32 | 3320 | Make_Aitem_Pragma |
3321 | (Pragma_Argument_Associations => New_List ( | |
3322 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3323 | Expression => Ent)), | |
3324 | Pragma_Name => Chars (Id)); | |
89f1e35c | 3325 | Delay_Required := False; |
ddf1337b | 3326 | |
89f1e35c | 3327 | -- In general cases, the corresponding pragma/attribute |
3328 | -- definition clause will be inserted later at the freezing | |
294709fa | 3329 | -- point, and we do not need to build it now. |
ddf1337b | 3330 | |
89f1e35c | 3331 | else |
3332 | Aitem := Empty; | |
3333 | end if; | |
ceec4f7c | 3334 | |
3335 | -- Storage_Size | |
3336 | ||
3337 | -- This is special because for access types we need to generate | |
3338 | -- an attribute definition clause. This also works for single | |
3339 | -- task declarations, but it does not work for task type | |
3340 | -- declarations, because we have the case where the expression | |
3341 | -- references a discriminant of the task type. That can't use | |
3342 | -- an attribute definition clause because we would not have | |
3343 | -- visibility on the discriminant. For that case we must | |
3344 | -- generate a pragma in the task definition. | |
3345 | ||
3346 | when Aspect_Storage_Size => | |
3347 | ||
3348 | -- Task type case | |
3349 | ||
3350 | if Ekind (E) = E_Task_Type then | |
3351 | declare | |
3352 | Decl : constant Node_Id := Declaration_Node (E); | |
3353 | ||
3354 | begin | |
3355 | pragma Assert (Nkind (Decl) = N_Task_Type_Declaration); | |
3356 | ||
3357 | -- If no task definition, create one | |
3358 | ||
3359 | if No (Task_Definition (Decl)) then | |
3360 | Set_Task_Definition (Decl, | |
3361 | Make_Task_Definition (Loc, | |
3362 | Visible_Declarations => Empty_List, | |
3363 | End_Label => Empty)); | |
3364 | end if; | |
3365 | ||
51fa2a45 | 3366 | -- Create a pragma and put it at the start of the task |
3367 | -- definition for the task type declaration. | |
ceec4f7c | 3368 | |
3369 | Make_Aitem_Pragma | |
3370 | (Pragma_Argument_Associations => New_List ( | |
3371 | Make_Pragma_Argument_Association (Loc, | |
3372 | Expression => Relocate_Node (Expr))), | |
3373 | Pragma_Name => Name_Storage_Size); | |
3374 | ||
3375 | Prepend | |
3376 | (Aitem, | |
3377 | Visible_Declarations (Task_Definition (Decl))); | |
3378 | goto Continue; | |
3379 | end; | |
3380 | ||
3381 | -- All other cases, generate attribute definition | |
3382 | ||
3383 | else | |
3384 | Aitem := | |
3385 | Make_Attribute_Definition_Clause (Loc, | |
3386 | Name => Ent, | |
3387 | Chars => Chars (Id), | |
3388 | Expression => Relocate_Node (Expr)); | |
3389 | end if; | |
89f1e35c | 3390 | end case; |
ddf1337b | 3391 | |
89f1e35c | 3392 | -- Attach the corresponding pragma/attribute definition clause to |
3393 | -- the aspect specification node. | |
d74fc39a | 3394 | |
89f1e35c | 3395 | if Present (Aitem) then |
e2bf777d | 3396 | Set_From_Aspect_Specification (Aitem); |
89f1e35c | 3397 | end if; |
53c179ea | 3398 | |
89f1e35c | 3399 | -- In the context of a compilation unit, we directly put the |
0fd13d32 | 3400 | -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux |
3401 | -- node (no delay is required here) except for aspects on a | |
51fa2a45 | 3402 | -- subprogram body (see below) and a generic package, for which we |
3403 | -- need to introduce the pragma before building the generic copy | |
3404 | -- (see sem_ch12), and for package instantiations, where the | |
3405 | -- library unit pragmas are better handled early. | |
ddf1337b | 3406 | |
9129c28f | 3407 | if Nkind (Parent (N)) = N_Compilation_Unit |
89f1e35c | 3408 | and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect)) |
3409 | then | |
3410 | declare | |
3411 | Aux : constant Node_Id := Aux_Decls_Node (Parent (N)); | |
7f694ca2 | 3412 | |
89f1e35c | 3413 | begin |
3414 | pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux); | |
7f694ca2 | 3415 | |
89f1e35c | 3416 | -- For a Boolean aspect, create the corresponding pragma if |
3417 | -- no expression or if the value is True. | |
7f694ca2 | 3418 | |
b9e61b2a | 3419 | if Is_Boolean_Aspect (Aspect) and then No (Aitem) then |
89f1e35c | 3420 | if Is_True (Static_Boolean (Expr)) then |
0fd13d32 | 3421 | Make_Aitem_Pragma |
3422 | (Pragma_Argument_Associations => New_List ( | |
3423 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3424 | Expression => Ent)), | |
3425 | Pragma_Name => Chars (Id)); | |
7f694ca2 | 3426 | |
89f1e35c | 3427 | Set_From_Aspect_Specification (Aitem, True); |
3428 | Set_Corresponding_Aspect (Aitem, Aspect); | |
3429 | ||
3430 | else | |
3431 | goto Continue; | |
3432 | end if; | |
3433 | end if; | |
7f694ca2 | 3434 | |
d6814978 | 3435 | -- If the aspect is on a subprogram body (relevant aspect |
3436 | -- is Inline), add the pragma in front of the declarations. | |
3a72f9c3 | 3437 | |
3438 | if Nkind (N) = N_Subprogram_Body then | |
3439 | if No (Declarations (N)) then | |
3440 | Set_Declarations (N, New_List); | |
3441 | end if; | |
3442 | ||
3443 | Prepend (Aitem, Declarations (N)); | |
3444 | ||
178fec9b | 3445 | elsif Nkind (N) = N_Generic_Package_Declaration then |
3446 | if No (Visible_Declarations (Specification (N))) then | |
3447 | Set_Visible_Declarations (Specification (N), New_List); | |
3448 | end if; | |
3449 | ||
3450 | Prepend (Aitem, | |
3451 | Visible_Declarations (Specification (N))); | |
3452 | ||
c39cce40 | 3453 | elsif Nkind (N) = N_Package_Instantiation then |
df8b0dae | 3454 | declare |
3455 | Spec : constant Node_Id := | |
3456 | Specification (Instance_Spec (N)); | |
3457 | begin | |
3458 | if No (Visible_Declarations (Spec)) then | |
3459 | Set_Visible_Declarations (Spec, New_List); | |
3460 | end if; | |
3461 | ||
3462 | Prepend (Aitem, Visible_Declarations (Spec)); | |
3463 | end; | |
3464 | ||
3a72f9c3 | 3465 | else |
3466 | if No (Pragmas_After (Aux)) then | |
d4596fbe | 3467 | Set_Pragmas_After (Aux, New_List); |
3a72f9c3 | 3468 | end if; |
3469 | ||
3470 | Append (Aitem, Pragmas_After (Aux)); | |
89f1e35c | 3471 | end if; |
7f694ca2 | 3472 | |
89f1e35c | 3473 | goto Continue; |
3474 | end; | |
3475 | end if; | |
7f694ca2 | 3476 | |
89f1e35c | 3477 | -- The evaluation of the aspect is delayed to the freezing point. |
3478 | -- The pragma or attribute clause if there is one is then attached | |
37c6e44c | 3479 | -- to the aspect specification which is put in the rep item list. |
1a814552 | 3480 | |
89f1e35c | 3481 | if Delay_Required then |
3482 | if Present (Aitem) then | |
3483 | Set_Is_Delayed_Aspect (Aitem); | |
3484 | Set_Aspect_Rep_Item (Aspect, Aitem); | |
3485 | Set_Parent (Aitem, Aspect); | |
3486 | end if; | |
1a814552 | 3487 | |
89f1e35c | 3488 | Set_Is_Delayed_Aspect (Aspect); |
9f36e3fb | 3489 | |
cba2ae82 | 3490 | -- In the case of Default_Value, link the aspect to base type |
3491 | -- as well, even though it appears on a first subtype. This is | |
3492 | -- mandated by the semantics of the aspect. Do not establish | |
3493 | -- the link when processing the base type itself as this leads | |
3494 | -- to a rep item circularity. Verify that we are dealing with | |
3495 | -- a scalar type to prevent cascaded errors. | |
3496 | ||
3497 | if A_Id = Aspect_Default_Value | |
3498 | and then Is_Scalar_Type (E) | |
3499 | and then Base_Type (E) /= E | |
3500 | then | |
9f36e3fb | 3501 | Set_Has_Delayed_Aspects (Base_Type (E)); |
3502 | Record_Rep_Item (Base_Type (E), Aspect); | |
3503 | end if; | |
3504 | ||
89f1e35c | 3505 | Set_Has_Delayed_Aspects (E); |
3506 | Record_Rep_Item (E, Aspect); | |
ddf1337b | 3507 | |
b855559d | 3508 | -- When delay is not required and the context is a package or a |
3509 | -- subprogram body, insert the pragma in the body declarations. | |
f55ce169 | 3510 | |
b855559d | 3511 | elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then |
f55ce169 | 3512 | if No (Declarations (N)) then |
3513 | Set_Declarations (N, New_List); | |
3514 | end if; | |
3515 | ||
3516 | -- The pragma is added before source declarations | |
3517 | ||
3518 | Prepend_To (Declarations (N), Aitem); | |
3519 | ||
89f1e35c | 3520 | -- When delay is not required and the context is not a compilation |
3521 | -- unit, we simply insert the pragma/attribute definition clause | |
3522 | -- in sequence. | |
ddf1337b | 3523 | |
89f1e35c | 3524 | else |
3525 | Insert_After (Ins_Node, Aitem); | |
3526 | Ins_Node := Aitem; | |
d74fc39a | 3527 | end if; |
0fd13d32 | 3528 | end Analyze_One_Aspect; |
ae888dbd | 3529 | |
d64221a7 | 3530 | <<Continue>> |
3531 | Next (Aspect); | |
21ea3a4f | 3532 | end loop Aspect_Loop; |
89f1e35c | 3533 | |
3534 | if Has_Delayed_Aspects (E) then | |
3535 | Ensure_Freeze_Node (E); | |
3536 | end if; | |
21ea3a4f | 3537 | end Analyze_Aspect_Specifications; |
ae888dbd | 3538 | |
eb8aeefc | 3539 | --------------------------------------------------- |
3540 | -- Analyze_Aspect_Specifications_On_Body_Or_Stub -- | |
3541 | --------------------------------------------------- | |
3542 | ||
3543 | procedure Analyze_Aspect_Specifications_On_Body_Or_Stub (N : Node_Id) is | |
3544 | Body_Id : constant Entity_Id := Defining_Entity (N); | |
3545 | ||
3546 | procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id); | |
3547 | -- Subprogram body [stub] N has aspects, but they are not properly | |
3548 | -- placed. Emit an error message depending on the aspects involved. | |
3549 | -- Spec_Id is the entity of the corresponding spec. | |
3550 | ||
3551 | -------------------------------- | |
3552 | -- Diagnose_Misplaced_Aspects -- | |
3553 | -------------------------------- | |
3554 | ||
3555 | procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is | |
3556 | procedure Misplaced_Aspect_Error | |
3557 | (Asp : Node_Id; | |
3558 | Ref_Nam : Name_Id); | |
3559 | -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is | |
3560 | -- the name of the refined version of the aspect. | |
3561 | ||
3562 | ---------------------------- | |
3563 | -- Misplaced_Aspect_Error -- | |
3564 | ---------------------------- | |
3565 | ||
3566 | procedure Misplaced_Aspect_Error | |
3567 | (Asp : Node_Id; | |
3568 | Ref_Nam : Name_Id) | |
3569 | is | |
3570 | Asp_Nam : constant Name_Id := Chars (Identifier (Asp)); | |
3571 | Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam); | |
3572 | ||
3573 | begin | |
3574 | -- The corresponding spec already contains the aspect in question | |
3575 | -- and the one appearing on the body must be the refined form: | |
3576 | ||
3577 | -- procedure P with Global ...; | |
3578 | -- procedure P with Global ... is ... end P; | |
3579 | -- ^ | |
3580 | -- Refined_Global | |
3581 | ||
3582 | if Has_Aspect (Spec_Id, Asp_Id) then | |
3583 | Error_Msg_Name_1 := Asp_Nam; | |
3584 | ||
3585 | -- Subunits cannot carry aspects that apply to a subprogram | |
3586 | -- declaration. | |
3587 | ||
3588 | if Nkind (Parent (N)) = N_Subunit then | |
3589 | Error_Msg_N ("aspect % cannot apply to a subunit", Asp); | |
3590 | ||
3591 | -- Otherwise suggest the refined form | |
3592 | ||
3593 | else | |
3594 | Error_Msg_Name_2 := Ref_Nam; | |
3595 | Error_Msg_N ("aspect % should be %", Asp); | |
3596 | end if; | |
3597 | ||
3598 | -- Otherwise the aspect must appear on the spec, not on the body | |
3599 | ||
3600 | -- procedure P; | |
3601 | -- procedure P with Global ... is ... end P; | |
3602 | ||
3603 | else | |
3604 | Error_Msg_N | |
3605 | ("aspect specification must appear in subprogram declaration", | |
3606 | Asp); | |
3607 | end if; | |
3608 | end Misplaced_Aspect_Error; | |
3609 | ||
3610 | -- Local variables | |
3611 | ||
3612 | Asp : Node_Id; | |
3613 | Asp_Nam : Name_Id; | |
3614 | ||
3615 | -- Start of processing for Diagnose_Misplaced_Aspects | |
3616 | ||
3617 | begin | |
3618 | -- Iterate over the aspect specifications and emit specific errors | |
3619 | -- where applicable. | |
3620 | ||
3621 | Asp := First (Aspect_Specifications (N)); | |
3622 | while Present (Asp) loop | |
3623 | Asp_Nam := Chars (Identifier (Asp)); | |
3624 | ||
3625 | -- Do not emit errors on aspects that can appear on a subprogram | |
3626 | -- body. This scenario occurs when the aspect specification list | |
3627 | -- contains both misplaced and properly placed aspects. | |
3628 | ||
3629 | if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then | |
3630 | null; | |
3631 | ||
3632 | -- Special diagnostics for SPARK aspects | |
3633 | ||
3634 | elsif Asp_Nam = Name_Depends then | |
3635 | Misplaced_Aspect_Error (Asp, Name_Refined_Depends); | |
3636 | ||
3637 | elsif Asp_Nam = Name_Global then | |
3638 | Misplaced_Aspect_Error (Asp, Name_Refined_Global); | |
3639 | ||
3640 | elsif Asp_Nam = Name_Post then | |
3641 | Misplaced_Aspect_Error (Asp, Name_Refined_Post); | |
3642 | ||
3643 | -- Otherwise a language-defined aspect is misplaced | |
3644 | ||
3645 | else | |
3646 | Error_Msg_N | |
3647 | ("aspect specification must appear in subprogram declaration", | |
3648 | Asp); | |
3649 | end if; | |
3650 | ||
3651 | Next (Asp); | |
3652 | end loop; | |
3653 | end Diagnose_Misplaced_Aspects; | |
3654 | ||
3655 | -- Local variables | |
3656 | ||
3657 | Spec_Id : Entity_Id; | |
3658 | ||
3659 | -- Start of processing for Analyze_Aspects_On_Body_Or_Stub | |
3660 | ||
3661 | begin | |
3662 | if Nkind (N) = N_Subprogram_Body_Stub then | |
3663 | Spec_Id := Corresponding_Spec_Of_Stub (N); | |
3664 | else | |
3665 | Spec_Id := Corresponding_Spec (N); | |
3666 | end if; | |
3667 | ||
3668 | -- Language-defined aspects cannot be associated with a subprogram body | |
3669 | -- [stub] if the subprogram has a spec. Certain implementation defined | |
3670 | -- aspects are allowed to break this rule (for all applicable cases, see | |
3671 | -- table Aspects.Aspect_On_Body_Or_Stub_OK). | |
3672 | ||
3673 | if Present (Spec_Id) and then not Aspects_On_Body_Or_Stub_OK (N) then | |
3674 | Diagnose_Misplaced_Aspects (Spec_Id); | |
3675 | else | |
3676 | Analyze_Aspect_Specifications (N, Body_Id); | |
3677 | end if; | |
3678 | end Analyze_Aspect_Specifications_On_Body_Or_Stub; | |
3679 | ||
d6f39728 | 3680 | ----------------------- |
3681 | -- Analyze_At_Clause -- | |
3682 | ----------------------- | |
3683 | ||
3684 | -- An at clause is replaced by the corresponding Address attribute | |
3685 | -- definition clause that is the preferred approach in Ada 95. | |
3686 | ||
3687 | procedure Analyze_At_Clause (N : Node_Id) is | |
177675a7 | 3688 | CS : constant Boolean := Comes_From_Source (N); |
3689 | ||
d6f39728 | 3690 | begin |
177675a7 | 3691 | -- This is an obsolescent feature |
3692 | ||
e0521a36 | 3693 | Check_Restriction (No_Obsolescent_Features, N); |
3694 | ||
9dfe12ae | 3695 | if Warn_On_Obsolescent_Feature then |
3696 | Error_Msg_N | |
b174444e | 3697 | ("?j?at clause is an obsolescent feature (RM J.7(2))", N); |
9dfe12ae | 3698 | Error_Msg_N |
b174444e | 3699 | ("\?j?use address attribute definition clause instead", N); |
9dfe12ae | 3700 | end if; |
3701 | ||
177675a7 | 3702 | -- Rewrite as address clause |
3703 | ||
d6f39728 | 3704 | Rewrite (N, |
3705 | Make_Attribute_Definition_Clause (Sloc (N), | |
935e86e0 | 3706 | Name => Identifier (N), |
3707 | Chars => Name_Address, | |
d6f39728 | 3708 | Expression => Expression (N))); |
177675a7 | 3709 | |
2beb22b1 | 3710 | -- We preserve Comes_From_Source, since logically the clause still comes |
3711 | -- from the source program even though it is changed in form. | |
177675a7 | 3712 | |
3713 | Set_Comes_From_Source (N, CS); | |
3714 | ||
3715 | -- Analyze rewritten clause | |
3716 | ||
d6f39728 | 3717 | Analyze_Attribute_Definition_Clause (N); |
3718 | end Analyze_At_Clause; | |
3719 | ||
3720 | ----------------------------------------- | |
3721 | -- Analyze_Attribute_Definition_Clause -- | |
3722 | ----------------------------------------- | |
3723 | ||
3724 | procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is | |
3725 | Loc : constant Source_Ptr := Sloc (N); | |
3726 | Nam : constant Node_Id := Name (N); | |
3727 | Attr : constant Name_Id := Chars (N); | |
3728 | Expr : constant Node_Id := Expression (N); | |
3729 | Id : constant Attribute_Id := Get_Attribute_Id (Attr); | |
d64221a7 | 3730 | |
3731 | Ent : Entity_Id; | |
3732 | -- The entity of Nam after it is analyzed. In the case of an incomplete | |
3733 | -- type, this is the underlying type. | |
3734 | ||
d6f39728 | 3735 | U_Ent : Entity_Id; |
d64221a7 | 3736 | -- The underlying entity to which the attribute applies. Generally this |
3737 | -- is the Underlying_Type of Ent, except in the case where the clause | |
3738 | -- applies to full view of incomplete type or private type in which case | |
3739 | -- U_Ent is just a copy of Ent. | |
d6f39728 | 3740 | |
3741 | FOnly : Boolean := False; | |
3742 | -- Reset to True for subtype specific attribute (Alignment, Size) | |
51fa2a45 | 3743 | -- and for stream attributes, i.e. those cases where in the call to |
3744 | -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules | |
3745 | -- are checked. Note that the case of stream attributes is not clear | |
3746 | -- from the RM, but see AI95-00137. Also, the RM seems to disallow | |
3747 | -- Storage_Size for derived task types, but that is also clearly | |
3748 | -- unintentional. | |
d6f39728 | 3749 | |
9f373bb8 | 3750 | procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type); |
3751 | -- Common processing for 'Read, 'Write, 'Input and 'Output attribute | |
3752 | -- definition clauses. | |
3753 | ||
ae888dbd | 3754 | function Duplicate_Clause return Boolean; |
3755 | -- This routine checks if the aspect for U_Ent being given by attribute | |
3756 | -- definition clause N is for an aspect that has already been specified, | |
3757 | -- and if so gives an error message. If there is a duplicate, True is | |
3758 | -- returned, otherwise if there is no error, False is returned. | |
3759 | ||
81b424ac | 3760 | procedure Check_Indexing_Functions; |
3761 | -- Check that the function in Constant_Indexing or Variable_Indexing | |
3762 | -- attribute has the proper type structure. If the name is overloaded, | |
cac18f71 | 3763 | -- check that some interpretation is legal. |
81b424ac | 3764 | |
89cc7147 | 3765 | procedure Check_Iterator_Functions; |
3766 | -- Check that there is a single function in Default_Iterator attribute | |
8df4f2a5 | 3767 | -- has the proper type structure. |
89cc7147 | 3768 | |
3769 | function Check_Primitive_Function (Subp : Entity_Id) return Boolean; | |
d03bfaa1 | 3770 | -- Common legality check for the previous two |
89cc7147 | 3771 | |
177675a7 | 3772 | ----------------------------------- |
3773 | -- Analyze_Stream_TSS_Definition -- | |
3774 | ----------------------------------- | |
3775 | ||
9f373bb8 | 3776 | procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is |
3777 | Subp : Entity_Id := Empty; | |
3778 | I : Interp_Index; | |
3779 | It : Interp; | |
3780 | Pnam : Entity_Id; | |
3781 | ||
3782 | Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read); | |
d64221a7 | 3783 | -- True for Read attribute, false for other attributes |
9f373bb8 | 3784 | |
3785 | function Has_Good_Profile (Subp : Entity_Id) return Boolean; | |
3786 | -- Return true if the entity is a subprogram with an appropriate | |
3787 | -- profile for the attribute being defined. | |
3788 | ||
3789 | ---------------------- | |
3790 | -- Has_Good_Profile -- | |
3791 | ---------------------- | |
3792 | ||
3793 | function Has_Good_Profile (Subp : Entity_Id) return Boolean is | |
3794 | F : Entity_Id; | |
3795 | Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input); | |
3796 | Expected_Ekind : constant array (Boolean) of Entity_Kind := | |
3797 | (False => E_Procedure, True => E_Function); | |
3798 | Typ : Entity_Id; | |
3799 | ||
3800 | begin | |
3801 | if Ekind (Subp) /= Expected_Ekind (Is_Function) then | |
3802 | return False; | |
3803 | end if; | |
3804 | ||
3805 | F := First_Formal (Subp); | |
3806 | ||
3807 | if No (F) | |
3808 | or else Ekind (Etype (F)) /= E_Anonymous_Access_Type | |
3809 | or else Designated_Type (Etype (F)) /= | |
3810 | Class_Wide_Type (RTE (RE_Root_Stream_Type)) | |
3811 | then | |
3812 | return False; | |
3813 | end if; | |
3814 | ||
3815 | if not Is_Function then | |
3816 | Next_Formal (F); | |
3817 | ||
3818 | declare | |
3819 | Expected_Mode : constant array (Boolean) of Entity_Kind := | |
3820 | (False => E_In_Parameter, | |
3821 | True => E_Out_Parameter); | |
3822 | begin | |
3823 | if Parameter_Mode (F) /= Expected_Mode (Is_Read) then | |
3824 | return False; | |
3825 | end if; | |
3826 | end; | |
3827 | ||
3828 | Typ := Etype (F); | |
3829 | ||
b64082f2 | 3830 | -- If the attribute specification comes from an aspect |
51fa2a45 | 3831 | -- specification for a class-wide stream, the parameter must be |
3832 | -- a class-wide type of the entity to which the aspect applies. | |
b64082f2 | 3833 | |
3834 | if From_Aspect_Specification (N) | |
3835 | and then Class_Present (Parent (N)) | |
3836 | and then Is_Class_Wide_Type (Typ) | |
3837 | then | |
3838 | Typ := Etype (Typ); | |
3839 | end if; | |
3840 | ||
9f373bb8 | 3841 | else |
3842 | Typ := Etype (Subp); | |
3843 | end if; | |
3844 | ||
51fa2a45 | 3845 | -- Verify that the prefix of the attribute and the local name for |
5a8fe506 | 3846 | -- the type of the formal match, or one is the class-wide of the |
3847 | -- other, in the case of a class-wide stream operation. | |
48680a09 | 3848 | |
b8eacb12 | 3849 | if Base_Type (Typ) = Base_Type (Ent) |
5a8fe506 | 3850 | or else (Is_Class_Wide_Type (Typ) |
2be1f7d7 | 3851 | and then Typ = Class_Wide_Type (Base_Type (Ent))) |
fbf4d6ef | 3852 | or else (Is_Class_Wide_Type (Ent) |
3853 | and then Ent = Class_Wide_Type (Base_Type (Typ))) | |
5a8fe506 | 3854 | then |
3855 | null; | |
3856 | else | |
3857 | return False; | |
3858 | end if; | |
3859 | ||
3860 | if Present ((Next_Formal (F))) | |
48680a09 | 3861 | then |
3862 | return False; | |
3863 | ||
3864 | elsif not Is_Scalar_Type (Typ) | |
3865 | and then not Is_First_Subtype (Typ) | |
3866 | and then not Is_Class_Wide_Type (Typ) | |
3867 | then | |
3868 | return False; | |
3869 | ||
3870 | else | |
3871 | return True; | |
3872 | end if; | |
9f373bb8 | 3873 | end Has_Good_Profile; |
3874 | ||
3875 | -- Start of processing for Analyze_Stream_TSS_Definition | |
3876 | ||
3877 | begin | |
3878 | FOnly := True; | |
3879 | ||
3880 | if not Is_Type (U_Ent) then | |
3881 | Error_Msg_N ("local name must be a subtype", Nam); | |
3882 | return; | |
48680a09 | 3883 | |
3884 | elsif not Is_First_Subtype (U_Ent) then | |
3885 | Error_Msg_N ("local name must be a first subtype", Nam); | |
3886 | return; | |
9f373bb8 | 3887 | end if; |
3888 | ||
3889 | Pnam := TSS (Base_Type (U_Ent), TSS_Nam); | |
3890 | ||
44e4341e | 3891 | -- If Pnam is present, it can be either inherited from an ancestor |
3892 | -- type (in which case it is legal to redefine it for this type), or | |
3893 | -- be a previous definition of the attribute for the same type (in | |
3894 | -- which case it is illegal). | |
3895 | ||
3896 | -- In the first case, it will have been analyzed already, and we | |
3897 | -- can check that its profile does not match the expected profile | |
3898 | -- for a stream attribute of U_Ent. In the second case, either Pnam | |
3899 | -- has been analyzed (and has the expected profile), or it has not | |
3900 | -- been analyzed yet (case of a type that has not been frozen yet | |
3901 | -- and for which the stream attribute has been set using Set_TSS). | |
3902 | ||
3903 | if Present (Pnam) | |
3904 | and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam)) | |
3905 | then | |
9f373bb8 | 3906 | Error_Msg_Sloc := Sloc (Pnam); |
3907 | Error_Msg_Name_1 := Attr; | |
3908 | Error_Msg_N ("% attribute already defined #", Nam); | |
3909 | return; | |
3910 | end if; | |
3911 | ||
3912 | Analyze (Expr); | |
3913 | ||
3914 | if Is_Entity_Name (Expr) then | |
3915 | if not Is_Overloaded (Expr) then | |
3916 | if Has_Good_Profile (Entity (Expr)) then | |
3917 | Subp := Entity (Expr); | |
3918 | end if; | |
3919 | ||
3920 | else | |
3921 | Get_First_Interp (Expr, I, It); | |
9f373bb8 | 3922 | while Present (It.Nam) loop |
3923 | if Has_Good_Profile (It.Nam) then | |
3924 | Subp := It.Nam; | |
3925 | exit; | |
3926 | end if; | |
3927 | ||
3928 | Get_Next_Interp (I, It); | |
3929 | end loop; | |
3930 | end if; | |
3931 | end if; | |
3932 | ||
3933 | if Present (Subp) then | |
59ac57b5 | 3934 | if Is_Abstract_Subprogram (Subp) then |
9f373bb8 | 3935 | Error_Msg_N ("stream subprogram must not be abstract", Expr); |
3936 | return; | |
e12b2502 | 3937 | |
299b347e | 3938 | -- A stream subprogram for an interface type must be a null |
3939 | -- procedure (RM 13.13.2 (38/3)). | |
e12b2502 | 3940 | |
3941 | elsif Is_Interface (U_Ent) | |
5a8fe506 | 3942 | and then not Is_Class_Wide_Type (U_Ent) |
e12b2502 | 3943 | and then not Inside_A_Generic |
e12b2502 | 3944 | and then |
5a8fe506 | 3945 | (Ekind (Subp) = E_Function |
3946 | or else | |
3947 | not Null_Present | |
2be1f7d7 | 3948 | (Specification |
3949 | (Unit_Declaration_Node (Ultimate_Alias (Subp))))) | |
e12b2502 | 3950 | then |
3951 | Error_Msg_N | |
3952 | ("stream subprogram for interface type " | |
3953 | & "must be null procedure", Expr); | |
9f373bb8 | 3954 | end if; |
3955 | ||
3956 | Set_Entity (Expr, Subp); | |
3957 | Set_Etype (Expr, Etype (Subp)); | |
3958 | ||
44e4341e | 3959 | New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam); |
9f373bb8 | 3960 | |
3961 | else | |
3962 | Error_Msg_Name_1 := Attr; | |
3963 | Error_Msg_N ("incorrect expression for% attribute", Expr); | |
3964 | end if; | |
3965 | end Analyze_Stream_TSS_Definition; | |
3966 | ||
81b424ac | 3967 | ------------------------------ |
3968 | -- Check_Indexing_Functions -- | |
3969 | ------------------------------ | |
3970 | ||
3971 | procedure Check_Indexing_Functions is | |
c8a2d809 | 3972 | Indexing_Found : Boolean := False; |
8df4f2a5 | 3973 | |
44d567c8 | 3974 | procedure Check_Inherited_Indexing; |
3975 | -- For a derived type, check that no indexing aspect is specified | |
3976 | -- for the type if it is also inherited | |
3977 | ||
81b424ac | 3978 | procedure Check_One_Function (Subp : Entity_Id); |
7796365f | 3979 | -- Check one possible interpretation. Sets Indexing_Found True if a |
3980 | -- legal indexing function is found. | |
81b424ac | 3981 | |
05987af3 | 3982 | procedure Illegal_Indexing (Msg : String); |
3983 | -- Diagnose illegal indexing function if not overloaded. In the | |
3984 | -- overloaded case indicate that no legal interpretation exists. | |
3985 | ||
44d567c8 | 3986 | ------------------------------ |
3987 | -- Check_Inherited_Indexing -- | |
3988 | ------------------------------ | |
3989 | ||
3990 | procedure Check_Inherited_Indexing is | |
3991 | Inherited : Node_Id; | |
3992 | ||
3993 | begin | |
3994 | if Attr = Name_Constant_Indexing then | |
3995 | Inherited := | |
3996 | Find_Aspect (Etype (Ent), Aspect_Constant_Indexing); | |
3997 | else pragma Assert (Attr = Name_Variable_Indexing); | |
3998 | Inherited := | |
3999 | Find_Aspect (Etype (Ent), Aspect_Variable_Indexing); | |
4000 | end if; | |
4001 | ||
4002 | if Present (Inherited) then | |
4003 | if Debug_Flag_Dot_XX then | |
4004 | null; | |
4005 | ||
4006 | -- OK if current attribute_definition_clause is expansion | |
4007 | -- of inherited aspect. | |
4008 | ||
4009 | elsif Aspect_Rep_Item (Inherited) = N then | |
4010 | null; | |
4011 | ||
4012 | -- Indicate the operation that must be overridden, rather | |
4013 | -- than redefining the indexing aspect | |
4014 | ||
4015 | else | |
4016 | Illegal_Indexing | |
4017 | ("indexing function already inherited " | |
4018 | & "from parent type"); | |
4019 | Error_Msg_NE | |
4020 | ("!override & instead", | |
4021 | N, Entity (Expression (Inherited))); | |
4022 | end if; | |
4023 | end if; | |
4024 | end Check_Inherited_Indexing; | |
4025 | ||
81b424ac | 4026 | ------------------------ |
4027 | -- Check_One_Function -- | |
4028 | ------------------------ | |
4029 | ||
4030 | procedure Check_One_Function (Subp : Entity_Id) is | |
05987af3 | 4031 | Default_Element : Node_Id; |
4032 | Ret_Type : constant Entity_Id := Etype (Subp); | |
1b7510f9 | 4033 | |
81b424ac | 4034 | begin |
05987af3 | 4035 | if not Is_Overloadable (Subp) then |
4036 | Illegal_Indexing ("illegal indexing function for type&"); | |
4037 | return; | |
4038 | ||
7796365f | 4039 | elsif Scope (Subp) /= Scope (Ent) then |
4040 | if Nkind (Expr) = N_Expanded_Name then | |
4041 | ||
4042 | -- Indexing function can't be declared elsewhere | |
4043 | ||
4044 | Illegal_Indexing | |
4045 | ("indexing function must be declared in scope of type&"); | |
4046 | end if; | |
4047 | ||
05987af3 | 4048 | return; |
4049 | ||
4050 | elsif No (First_Formal (Subp)) then | |
4051 | Illegal_Indexing | |
4052 | ("Indexing requires a function that applies to type&"); | |
4053 | return; | |
4054 | ||
4055 | elsif No (Next_Formal (First_Formal (Subp))) then | |
4056 | Illegal_Indexing | |
2eb0ff42 | 4057 | ("indexing function must have at least two parameters"); |
05987af3 | 4058 | return; |
4059 | ||
4060 | elsif Is_Derived_Type (Ent) then | |
44d567c8 | 4061 | Check_Inherited_Indexing; |
05987af3 | 4062 | end if; |
4063 | ||
e81df51c | 4064 | if not Check_Primitive_Function (Subp) then |
05987af3 | 4065 | Illegal_Indexing |
4066 | ("Indexing aspect requires a function that applies to type&"); | |
4067 | return; | |
81b424ac | 4068 | end if; |
4069 | ||
7796365f | 4070 | -- If partial declaration exists, verify that it is not tagged. |
4071 | ||
4072 | if Ekind (Current_Scope) = E_Package | |
4073 | and then Has_Private_Declaration (Ent) | |
4074 | and then From_Aspect_Specification (N) | |
7c0c95b8 | 4075 | and then |
4076 | List_Containing (Parent (Ent)) = | |
4077 | Private_Declarations | |
7796365f | 4078 | (Specification (Unit_Declaration_Node (Current_Scope))) |
4079 | and then Nkind (N) = N_Attribute_Definition_Clause | |
4080 | then | |
4081 | declare | |
4082 | Decl : Node_Id; | |
4083 | ||
4084 | begin | |
4085 | Decl := | |
4086 | First (Visible_Declarations | |
7c0c95b8 | 4087 | (Specification |
4088 | (Unit_Declaration_Node (Current_Scope)))); | |
7796365f | 4089 | |
4090 | while Present (Decl) loop | |
4091 | if Nkind (Decl) = N_Private_Type_Declaration | |
4092 | and then Ent = Full_View (Defining_Identifier (Decl)) | |
4093 | and then Tagged_Present (Decl) | |
4094 | and then No (Aspect_Specifications (Decl)) | |
4095 | then | |
4096 | Illegal_Indexing | |
4097 | ("Indexing aspect cannot be specified on full view " | |
7c0c95b8 | 4098 | & "if partial view is tagged"); |
7796365f | 4099 | return; |
4100 | end if; | |
4101 | ||
4102 | Next (Decl); | |
4103 | end loop; | |
4104 | end; | |
4105 | end if; | |
4106 | ||
1b7510f9 | 4107 | -- An indexing function must return either the default element of |
cac18f71 | 4108 | -- the container, or a reference type. For variable indexing it |
a45d946f | 4109 | -- must be the latter. |
1b7510f9 | 4110 | |
05987af3 | 4111 | Default_Element := |
4112 | Find_Value_Of_Aspect | |
4113 | (Etype (First_Formal (Subp)), Aspect_Iterator_Element); | |
4114 | ||
1b7510f9 | 4115 | if Present (Default_Element) then |
4116 | Analyze (Default_Element); | |
a45d946f | 4117 | |
1b7510f9 | 4118 | if Is_Entity_Name (Default_Element) |
05987af3 | 4119 | and then not Covers (Entity (Default_Element), Ret_Type) |
4120 | and then False | |
1b7510f9 | 4121 | then |
05987af3 | 4122 | Illegal_Indexing |
4123 | ("wrong return type for indexing function"); | |
1b7510f9 | 4124 | return; |
4125 | end if; | |
4126 | end if; | |
4127 | ||
a45d946f | 4128 | -- For variable_indexing the return type must be a reference type |
1b7510f9 | 4129 | |
05987af3 | 4130 | if Attr = Name_Variable_Indexing then |
4131 | if not Has_Implicit_Dereference (Ret_Type) then | |
4132 | Illegal_Indexing | |
4133 | ("variable indexing must return a reference type"); | |
4134 | return; | |
4135 | ||
423b89fd | 4136 | elsif Is_Access_Constant |
4137 | (Etype (First_Discriminant (Ret_Type))) | |
05987af3 | 4138 | then |
4139 | Illegal_Indexing | |
4140 | ("variable indexing must return an access to variable"); | |
4141 | return; | |
4142 | end if; | |
cac18f71 | 4143 | |
4144 | else | |
05987af3 | 4145 | if Has_Implicit_Dereference (Ret_Type) |
4146 | and then not | |
4147 | Is_Access_Constant (Etype (First_Discriminant (Ret_Type))) | |
4148 | then | |
4149 | Illegal_Indexing | |
4150 | ("constant indexing must return an access to constant"); | |
4151 | return; | |
4152 | ||
4153 | elsif Is_Access_Type (Etype (First_Formal (Subp))) | |
4154 | and then not Is_Access_Constant (Etype (First_Formal (Subp))) | |
4155 | then | |
4156 | Illegal_Indexing | |
4157 | ("constant indexing must apply to an access to constant"); | |
4158 | return; | |
4159 | end if; | |
81b424ac | 4160 | end if; |
05987af3 | 4161 | |
4162 | -- All checks succeeded. | |
4163 | ||
4164 | Indexing_Found := True; | |
81b424ac | 4165 | end Check_One_Function; |
4166 | ||
05987af3 | 4167 | ----------------------- |
4168 | -- Illegal_Indexing -- | |
4169 | ----------------------- | |
4170 | ||
4171 | procedure Illegal_Indexing (Msg : String) is | |
4172 | begin | |
7796365f | 4173 | Error_Msg_NE (Msg, N, Ent); |
05987af3 | 4174 | end Illegal_Indexing; |
4175 | ||
81b424ac | 4176 | -- Start of processing for Check_Indexing_Functions |
4177 | ||
4178 | begin | |
89cc7147 | 4179 | if In_Instance then |
44d567c8 | 4180 | Check_Inherited_Indexing; |
89cc7147 | 4181 | end if; |
4182 | ||
81b424ac | 4183 | Analyze (Expr); |
4184 | ||
4185 | if not Is_Overloaded (Expr) then | |
4186 | Check_One_Function (Entity (Expr)); | |
4187 | ||
4188 | else | |
4189 | declare | |
2c5754de | 4190 | I : Interp_Index; |
81b424ac | 4191 | It : Interp; |
4192 | ||
4193 | begin | |
cac18f71 | 4194 | Indexing_Found := False; |
81b424ac | 4195 | Get_First_Interp (Expr, I, It); |
4196 | while Present (It.Nam) loop | |
4197 | ||
4198 | -- Note that analysis will have added the interpretation | |
4199 | -- that corresponds to the dereference. We only check the | |
4200 | -- subprogram itself. | |
4201 | ||
4202 | if Is_Overloadable (It.Nam) then | |
4203 | Check_One_Function (It.Nam); | |
4204 | end if; | |
4205 | ||
4206 | Get_Next_Interp (I, It); | |
4207 | end loop; | |
4208 | end; | |
4209 | end if; | |
7796365f | 4210 | |
7c0c95b8 | 4211 | if not Indexing_Found and then not Error_Posted (N) then |
7796365f | 4212 | Error_Msg_NE |
4213 | ("aspect Indexing requires a local function that " | |
4214 | & "applies to type&", Expr, Ent); | |
4215 | end if; | |
81b424ac | 4216 | end Check_Indexing_Functions; |
4217 | ||
89cc7147 | 4218 | ------------------------------ |
4219 | -- Check_Iterator_Functions -- | |
4220 | ------------------------------ | |
4221 | ||
4222 | procedure Check_Iterator_Functions is | |
4223 | Default : Entity_Id; | |
4224 | ||
4225 | function Valid_Default_Iterator (Subp : Entity_Id) return Boolean; | |
8df4f2a5 | 4226 | -- Check one possible interpretation for validity |
89cc7147 | 4227 | |
4228 | ---------------------------- | |
4229 | -- Valid_Default_Iterator -- | |
4230 | ---------------------------- | |
4231 | ||
4232 | function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is | |
4233 | Formal : Entity_Id; | |
4234 | ||
4235 | begin | |
4236 | if not Check_Primitive_Function (Subp) then | |
4237 | return False; | |
4238 | else | |
4239 | Formal := First_Formal (Subp); | |
4240 | end if; | |
4241 | ||
8df4f2a5 | 4242 | -- False if any subsequent formal has no default expression |
89cc7147 | 4243 | |
8df4f2a5 | 4244 | Formal := Next_Formal (Formal); |
4245 | while Present (Formal) loop | |
4246 | if No (Expression (Parent (Formal))) then | |
4247 | return False; | |
4248 | end if; | |
89cc7147 | 4249 | |
8df4f2a5 | 4250 | Next_Formal (Formal); |
4251 | end loop; | |
89cc7147 | 4252 | |
8df4f2a5 | 4253 | -- True if all subsequent formals have default expressions |
89cc7147 | 4254 | |
4255 | return True; | |
4256 | end Valid_Default_Iterator; | |
4257 | ||
4258 | -- Start of processing for Check_Iterator_Functions | |
4259 | ||
4260 | begin | |
4261 | Analyze (Expr); | |
4262 | ||
4263 | if not Is_Entity_Name (Expr) then | |
4264 | Error_Msg_N ("aspect Iterator must be a function name", Expr); | |
4265 | end if; | |
4266 | ||
4267 | if not Is_Overloaded (Expr) then | |
4268 | if not Check_Primitive_Function (Entity (Expr)) then | |
4269 | Error_Msg_NE | |
4270 | ("aspect Indexing requires a function that applies to type&", | |
4271 | Entity (Expr), Ent); | |
4272 | end if; | |
4273 | ||
05f6f999 | 4274 | -- Flag the default_iterator as well as the denoted function. |
4275 | ||
89cc7147 | 4276 | if not Valid_Default_Iterator (Entity (Expr)) then |
05f6f999 | 4277 | Error_Msg_N ("improper function for default iterator!", Expr); |
89cc7147 | 4278 | end if; |
4279 | ||
4280 | else | |
4281 | Default := Empty; | |
4282 | declare | |
4283 | I : Interp_Index; | |
4284 | It : Interp; | |
4285 | ||
4286 | begin | |
4287 | Get_First_Interp (Expr, I, It); | |
4288 | while Present (It.Nam) loop | |
4289 | if not Check_Primitive_Function (It.Nam) | |
59f3e675 | 4290 | or else not Valid_Default_Iterator (It.Nam) |
89cc7147 | 4291 | then |
4292 | Remove_Interp (I); | |
4293 | ||
4294 | elsif Present (Default) then | |
4295 | Error_Msg_N ("default iterator must be unique", Expr); | |
4296 | ||
4297 | else | |
4298 | Default := It.Nam; | |
4299 | end if; | |
4300 | ||
4301 | Get_Next_Interp (I, It); | |
4302 | end loop; | |
4303 | end; | |
4304 | ||
4305 | if Present (Default) then | |
4306 | Set_Entity (Expr, Default); | |
4307 | Set_Is_Overloaded (Expr, False); | |
4308 | end if; | |
4309 | end if; | |
4310 | end Check_Iterator_Functions; | |
4311 | ||
4312 | ------------------------------- | |
4313 | -- Check_Primitive_Function -- | |
4314 | ------------------------------- | |
4315 | ||
4316 | function Check_Primitive_Function (Subp : Entity_Id) return Boolean is | |
4317 | Ctrl : Entity_Id; | |
4318 | ||
4319 | begin | |
4320 | if Ekind (Subp) /= E_Function then | |
4321 | return False; | |
4322 | end if; | |
4323 | ||
4324 | if No (First_Formal (Subp)) then | |
4325 | return False; | |
4326 | else | |
4327 | Ctrl := Etype (First_Formal (Subp)); | |
4328 | end if; | |
4329 | ||
05f6f999 | 4330 | -- To be a primitive operation subprogram has to be in same scope. |
4331 | ||
4332 | if Scope (Ctrl) /= Scope (Subp) then | |
4333 | return False; | |
4334 | end if; | |
4335 | ||
7d6fb253 | 4336 | -- Type of formal may be the class-wide type, an access to such, |
4337 | -- or an incomplete view. | |
4338 | ||
89cc7147 | 4339 | if Ctrl = Ent |
4340 | or else Ctrl = Class_Wide_Type (Ent) | |
4341 | or else | |
4342 | (Ekind (Ctrl) = E_Anonymous_Access_Type | |
b85d62ec | 4343 | and then (Designated_Type (Ctrl) = Ent |
4344 | or else | |
4345 | Designated_Type (Ctrl) = Class_Wide_Type (Ent))) | |
7d6fb253 | 4346 | or else |
4347 | (Ekind (Ctrl) = E_Incomplete_Type | |
4348 | and then Full_View (Ctrl) = Ent) | |
89cc7147 | 4349 | then |
4350 | null; | |
89cc7147 | 4351 | else |
4352 | return False; | |
4353 | end if; | |
4354 | ||
4355 | return True; | |
4356 | end Check_Primitive_Function; | |
4357 | ||
ae888dbd | 4358 | ---------------------- |
4359 | -- Duplicate_Clause -- | |
4360 | ---------------------- | |
4361 | ||
4362 | function Duplicate_Clause return Boolean is | |
d74fc39a | 4363 | A : Node_Id; |
ae888dbd | 4364 | |
4365 | begin | |
c8969ba6 | 4366 | -- Nothing to do if this attribute definition clause comes from |
4367 | -- an aspect specification, since we could not be duplicating an | |
ae888dbd | 4368 | -- explicit clause, and we dealt with the case of duplicated aspects |
4369 | -- in Analyze_Aspect_Specifications. | |
4370 | ||
4371 | if From_Aspect_Specification (N) then | |
4372 | return False; | |
4373 | end if; | |
4374 | ||
89f1e35c | 4375 | -- Otherwise current clause may duplicate previous clause, or a |
4376 | -- previously given pragma or aspect specification for the same | |
4377 | -- aspect. | |
d74fc39a | 4378 | |
89b3b365 | 4379 | A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False); |
ae888dbd | 4380 | |
4381 | if Present (A) then | |
89f1e35c | 4382 | Error_Msg_Name_1 := Chars (N); |
4383 | Error_Msg_Sloc := Sloc (A); | |
4384 | ||
89b3b365 | 4385 | Error_Msg_NE ("aspect% for & previously given#", N, U_Ent); |
89f1e35c | 4386 | return True; |
ae888dbd | 4387 | end if; |
4388 | ||
4389 | return False; | |
4390 | end Duplicate_Clause; | |
4391 | ||
9f373bb8 | 4392 | -- Start of processing for Analyze_Attribute_Definition_Clause |
4393 | ||
d6f39728 | 4394 | begin |
d64221a7 | 4395 | -- The following code is a defense against recursion. Not clear that |
51fa2a45 | 4396 | -- this can happen legitimately, but perhaps some error situations can |
4397 | -- cause it, and we did see this recursion during testing. | |
d64221a7 | 4398 | |
4399 | if Analyzed (N) then | |
4400 | return; | |
4401 | else | |
4402 | Set_Analyzed (N, True); | |
4403 | end if; | |
4404 | ||
a29bc1d9 | 4405 | -- Ignore some selected attributes in CodePeer mode since they are not |
4406 | -- relevant in this context. | |
4407 | ||
4408 | if CodePeer_Mode then | |
4409 | case Id is | |
4410 | ||
4411 | -- Ignore Component_Size in CodePeer mode, to avoid changing the | |
4412 | -- internal representation of types by implicitly packing them. | |
4413 | ||
4414 | when Attribute_Component_Size => | |
4415 | Rewrite (N, Make_Null_Statement (Sloc (N))); | |
4416 | return; | |
4417 | ||
4418 | when others => | |
4419 | null; | |
4420 | end case; | |
4421 | end if; | |
4422 | ||
d8ba53a8 | 4423 | -- Process Ignore_Rep_Clauses option |
eef1ca1e | 4424 | |
d8ba53a8 | 4425 | if Ignore_Rep_Clauses then |
9d627c41 | 4426 | case Id is |
4427 | ||
eef1ca1e | 4428 | -- The following should be ignored. They do not affect legality |
4429 | -- and may be target dependent. The basic idea of -gnatI is to | |
4430 | -- ignore any rep clauses that may be target dependent but do not | |
4431 | -- affect legality (except possibly to be rejected because they | |
4432 | -- are incompatible with the compilation target). | |
9d627c41 | 4433 | |
2f1aac99 | 4434 | when Attribute_Alignment | |
9d627c41 | 4435 | Attribute_Bit_Order | |
4436 | Attribute_Component_Size | | |
4437 | Attribute_Machine_Radix | | |
4438 | Attribute_Object_Size | | |
4439 | Attribute_Size | | |
2ff55065 | 4440 | Attribute_Small | |
9d627c41 | 4441 | Attribute_Stream_Size | |
4442 | Attribute_Value_Size => | |
2ff55065 | 4443 | Kill_Rep_Clause (N); |
9d627c41 | 4444 | return; |
4445 | ||
eef1ca1e | 4446 | -- The following should not be ignored, because in the first place |
51fa2a45 | 4447 | -- they are reasonably portable, and should not cause problems |
4448 | -- in compiling code from another target, and also they do affect | |
4449 | -- legality, e.g. failing to provide a stream attribute for a type | |
4450 | -- may make a program illegal. | |
9d627c41 | 4451 | |
b55f7641 | 4452 | when Attribute_External_Tag | |
4453 | Attribute_Input | | |
4454 | Attribute_Output | | |
4455 | Attribute_Read | | |
4456 | Attribute_Simple_Storage_Pool | | |
4457 | Attribute_Storage_Pool | | |
4458 | Attribute_Storage_Size | | |
4459 | Attribute_Write => | |
9d627c41 | 4460 | null; |
4461 | ||
2ff55065 | 4462 | -- We do not do anything here with address clauses, they will be |
4463 | -- removed by Freeze later on, but for now, it works better to | |
4464 | -- keep then in the tree. | |
4465 | ||
4466 | when Attribute_Address => | |
4467 | null; | |
4468 | ||
b593a52c | 4469 | -- Other cases are errors ("attribute& cannot be set with |
4470 | -- definition clause"), which will be caught below. | |
9d627c41 | 4471 | |
4472 | when others => | |
4473 | null; | |
4474 | end case; | |
fbc67f84 | 4475 | end if; |
4476 | ||
d6f39728 | 4477 | Analyze (Nam); |
4478 | Ent := Entity (Nam); | |
4479 | ||
4480 | if Rep_Item_Too_Early (Ent, N) then | |
4481 | return; | |
4482 | end if; | |
4483 | ||
9f373bb8 | 4484 | -- Rep clause applies to full view of incomplete type or private type if |
4485 | -- we have one (if not, this is a premature use of the type). However, | |
4486 | -- certain semantic checks need to be done on the specified entity (i.e. | |
4487 | -- the private view), so we save it in Ent. | |
d6f39728 | 4488 | |
4489 | if Is_Private_Type (Ent) | |
4490 | and then Is_Derived_Type (Ent) | |
4491 | and then not Is_Tagged_Type (Ent) | |
4492 | and then No (Full_View (Ent)) | |
4493 | then | |
9f373bb8 | 4494 | -- If this is a private type whose completion is a derivation from |
4495 | -- another private type, there is no full view, and the attribute | |
4496 | -- belongs to the type itself, not its underlying parent. | |
d6f39728 | 4497 | |
4498 | U_Ent := Ent; | |
4499 | ||
4500 | elsif Ekind (Ent) = E_Incomplete_Type then | |
d5b349fa | 4501 | |
9f373bb8 | 4502 | -- The attribute applies to the full view, set the entity of the |
4503 | -- attribute definition accordingly. | |
d5b349fa | 4504 | |
d6f39728 | 4505 | Ent := Underlying_Type (Ent); |
4506 | U_Ent := Ent; | |
d5b349fa | 4507 | Set_Entity (Nam, Ent); |
4508 | ||
d6f39728 | 4509 | else |
4510 | U_Ent := Underlying_Type (Ent); | |
4511 | end if; | |
4512 | ||
44705307 | 4513 | -- Avoid cascaded error |
d6f39728 | 4514 | |
4515 | if Etype (Nam) = Any_Type then | |
4516 | return; | |
4517 | ||
89f1e35c | 4518 | -- Must be declared in current scope or in case of an aspect |
ace3389d | 4519 | -- specification, must be visible in current scope. |
44705307 | 4520 | |
89f1e35c | 4521 | elsif Scope (Ent) /= Current_Scope |
ace3389d | 4522 | and then |
4523 | not (From_Aspect_Specification (N) | |
4524 | and then Scope_Within_Or_Same (Current_Scope, Scope (Ent))) | |
89f1e35c | 4525 | then |
d6f39728 | 4526 | Error_Msg_N ("entity must be declared in this scope", Nam); |
4527 | return; | |
4528 | ||
44705307 | 4529 | -- Must not be a source renaming (we do have some cases where the |
4530 | -- expander generates a renaming, and those cases are OK, in such | |
a3248fc4 | 4531 | -- cases any attribute applies to the renamed object as well). |
44705307 | 4532 | |
4533 | elsif Is_Object (Ent) | |
4534 | and then Present (Renamed_Object (Ent)) | |
44705307 | 4535 | then |
a3248fc4 | 4536 | -- Case of renamed object from source, this is an error |
4537 | ||
4538 | if Comes_From_Source (Renamed_Object (Ent)) then | |
4539 | Get_Name_String (Chars (N)); | |
4540 | Error_Msg_Strlen := Name_Len; | |
4541 | Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); | |
4542 | Error_Msg_N | |
4543 | ("~ clause not allowed for a renaming declaration " | |
4544 | & "(RM 13.1(6))", Nam); | |
4545 | return; | |
4546 | ||
4547 | -- For the case of a compiler generated renaming, the attribute | |
4548 | -- definition clause applies to the renamed object created by the | |
4549 | -- expander. The easiest general way to handle this is to create a | |
4550 | -- copy of the attribute definition clause for this object. | |
4551 | ||
9a48fc56 | 4552 | elsif Is_Entity_Name (Renamed_Object (Ent)) then |
a3248fc4 | 4553 | Insert_Action (N, |
4554 | Make_Attribute_Definition_Clause (Loc, | |
4555 | Name => | |
4556 | New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc), | |
4557 | Chars => Chars (N), | |
4558 | Expression => Duplicate_Subexpr (Expression (N)))); | |
9a48fc56 | 4559 | |
4560 | -- If the renamed object is not an entity, it must be a dereference | |
4561 | -- of an unconstrained function call, and we must introduce a new | |
4562 | -- declaration to capture the expression. This is needed in the case | |
4563 | -- of 'Alignment, where the original declaration must be rewritten. | |
4564 | ||
4565 | else | |
4566 | pragma Assert | |
4567 | (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference); | |
4568 | null; | |
a3248fc4 | 4569 | end if; |
44705307 | 4570 | |
4571 | -- If no underlying entity, use entity itself, applies to some | |
4572 | -- previously detected error cases ??? | |
4573 | ||
f15731c4 | 4574 | elsif No (U_Ent) then |
4575 | U_Ent := Ent; | |
4576 | ||
44705307 | 4577 | -- Cannot specify for a subtype (exception Object/Value_Size) |
4578 | ||
d6f39728 | 4579 | elsif Is_Type (U_Ent) |
4580 | and then not Is_First_Subtype (U_Ent) | |
4581 | and then Id /= Attribute_Object_Size | |
4582 | and then Id /= Attribute_Value_Size | |
4583 | and then not From_At_Mod (N) | |
4584 | then | |
4585 | Error_Msg_N ("cannot specify attribute for subtype", Nam); | |
4586 | return; | |
d6f39728 | 4587 | end if; |
4588 | ||
ae888dbd | 4589 | Set_Entity (N, U_Ent); |
25e23a77 | 4590 | Check_Restriction_No_Use_Of_Attribute (N); |
ae888dbd | 4591 | |
d6f39728 | 4592 | -- Switch on particular attribute |
4593 | ||
4594 | case Id is | |
4595 | ||
4596 | ------------- | |
4597 | -- Address -- | |
4598 | ------------- | |
4599 | ||
4600 | -- Address attribute definition clause | |
4601 | ||
4602 | when Attribute_Address => Address : begin | |
177675a7 | 4603 | |
4604 | -- A little error check, catch for X'Address use X'Address; | |
4605 | ||
4606 | if Nkind (Nam) = N_Identifier | |
4607 | and then Nkind (Expr) = N_Attribute_Reference | |
4608 | and then Attribute_Name (Expr) = Name_Address | |
4609 | and then Nkind (Prefix (Expr)) = N_Identifier | |
4610 | and then Chars (Nam) = Chars (Prefix (Expr)) | |
4611 | then | |
4612 | Error_Msg_NE | |
4613 | ("address for & is self-referencing", Prefix (Expr), Ent); | |
4614 | return; | |
4615 | end if; | |
4616 | ||
4617 | -- Not that special case, carry on with analysis of expression | |
4618 | ||
d6f39728 | 4619 | Analyze_And_Resolve (Expr, RTE (RE_Address)); |
4620 | ||
2f1aac99 | 4621 | -- Even when ignoring rep clauses we need to indicate that the |
4622 | -- entity has an address clause and thus it is legal to declare | |
2ff55065 | 4623 | -- it imported. Freeze will get rid of the address clause later. |
2f1aac99 | 4624 | |
4625 | if Ignore_Rep_Clauses then | |
d3ef794c | 4626 | if Ekind_In (U_Ent, E_Variable, E_Constant) then |
2f1aac99 | 4627 | Record_Rep_Item (U_Ent, N); |
4628 | end if; | |
4629 | ||
4630 | return; | |
4631 | end if; | |
4632 | ||
ae888dbd | 4633 | if Duplicate_Clause then |
4634 | null; | |
d6f39728 | 4635 | |
4636 | -- Case of address clause for subprogram | |
4637 | ||
4638 | elsif Is_Subprogram (U_Ent) then | |
d6f39728 | 4639 | if Has_Homonym (U_Ent) then |
4640 | Error_Msg_N | |
4641 | ("address clause cannot be given " & | |
4642 | "for overloaded subprogram", | |
4643 | Nam); | |
83f8f0a6 | 4644 | return; |
d6f39728 | 4645 | end if; |
4646 | ||
83f8f0a6 | 4647 | -- For subprograms, all address clauses are permitted, and we |
4648 | -- mark the subprogram as having a deferred freeze so that Gigi | |
4649 | -- will not elaborate it too soon. | |
d6f39728 | 4650 | |
4651 | -- Above needs more comments, what is too soon about??? | |
4652 | ||
4653 | Set_Has_Delayed_Freeze (U_Ent); | |
4654 | ||
4655 | -- Case of address clause for entry | |
4656 | ||
4657 | elsif Ekind (U_Ent) = E_Entry then | |
d6f39728 | 4658 | if Nkind (Parent (N)) = N_Task_Body then |
4659 | Error_Msg_N | |
4660 | ("entry address must be specified in task spec", Nam); | |
83f8f0a6 | 4661 | return; |
d6f39728 | 4662 | end if; |
4663 | ||
4664 | -- For entries, we require a constant address | |
4665 | ||
4666 | Check_Constant_Address_Clause (Expr, U_Ent); | |
4667 | ||
83f8f0a6 | 4668 | -- Special checks for task types |
4669 | ||
f15731c4 | 4670 | if Is_Task_Type (Scope (U_Ent)) |
4671 | and then Comes_From_Source (Scope (U_Ent)) | |
4672 | then | |
4673 | Error_Msg_N | |
1e3532e7 | 4674 | ("??entry address declared for entry in task type", N); |
f15731c4 | 4675 | Error_Msg_N |
1e3532e7 | 4676 | ("\??only one task can be declared of this type", N); |
f15731c4 | 4677 | end if; |
4678 | ||
83f8f0a6 | 4679 | -- Entry address clauses are obsolescent |
4680 | ||
e0521a36 | 4681 | Check_Restriction (No_Obsolescent_Features, N); |
4682 | ||
9dfe12ae | 4683 | if Warn_On_Obsolescent_Feature then |
4684 | Error_Msg_N | |
1e3532e7 | 4685 | ("?j?attaching interrupt to task entry is an " & |
4686 | "obsolescent feature (RM J.7.1)", N); | |
9dfe12ae | 4687 | Error_Msg_N |
1e3532e7 | 4688 | ("\?j?use interrupt procedure instead", N); |
9dfe12ae | 4689 | end if; |
4690 | ||
83f8f0a6 | 4691 | -- Case of an address clause for a controlled object which we |
4692 | -- consider to be erroneous. | |
9dfe12ae | 4693 | |
83f8f0a6 | 4694 | elsif Is_Controlled (Etype (U_Ent)) |
4695 | or else Has_Controlled_Component (Etype (U_Ent)) | |
4696 | then | |
9dfe12ae | 4697 | Error_Msg_NE |
1e3532e7 | 4698 | ("??controlled object& must not be overlaid", Nam, U_Ent); |
9dfe12ae | 4699 | Error_Msg_N |
1e3532e7 | 4700 | ("\??Program_Error will be raised at run time", Nam); |
9dfe12ae | 4701 | Insert_Action (Declaration_Node (U_Ent), |
4702 | Make_Raise_Program_Error (Loc, | |
4703 | Reason => PE_Overlaid_Controlled_Object)); | |
83f8f0a6 | 4704 | return; |
9dfe12ae | 4705 | |
4706 | -- Case of address clause for a (non-controlled) object | |
d6f39728 | 4707 | |
f02a9a9a | 4708 | elsif Ekind_In (U_Ent, E_Variable, E_Constant) then |
d6f39728 | 4709 | declare |
d6da7448 | 4710 | Expr : constant Node_Id := Expression (N); |
4711 | O_Ent : Entity_Id; | |
4712 | Off : Boolean; | |
d6f39728 | 4713 | |
4714 | begin | |
7ee315cc | 4715 | -- Exported variables cannot have an address clause, because |
4716 | -- this cancels the effect of the pragma Export. | |
d6f39728 | 4717 | |
4718 | if Is_Exported (U_Ent) then | |
4719 | Error_Msg_N | |
4720 | ("cannot export object with address clause", Nam); | |
83f8f0a6 | 4721 | return; |
d6da7448 | 4722 | end if; |
4723 | ||
4724 | Find_Overlaid_Entity (N, O_Ent, Off); | |
d6f39728 | 4725 | |
0c30cda1 | 4726 | -- Overlaying controlled objects is erroneous. |
4727 | -- Emit warning but continue analysis because program is | |
4728 | -- itself legal, and back-end must see address clause. | |
9dfe12ae | 4729 | |
d6da7448 | 4730 | if Present (O_Ent) |
4731 | and then (Has_Controlled_Component (Etype (O_Ent)) | |
f02a9a9a | 4732 | or else Is_Controlled (Etype (O_Ent))) |
0c30cda1 | 4733 | and then not Inside_A_Generic |
9dfe12ae | 4734 | then |
4735 | Error_Msg_N | |
0c30cda1 | 4736 | ("??cannot use overlays with controlled objects", Expr); |
9dfe12ae | 4737 | Error_Msg_N |
1e3532e7 | 4738 | ("\??Program_Error will be raised at run time", Expr); |
9dfe12ae | 4739 | Insert_Action (Declaration_Node (U_Ent), |
4740 | Make_Raise_Program_Error (Loc, | |
4741 | Reason => PE_Overlaid_Controlled_Object)); | |
4742 | ||
95009d64 | 4743 | -- Issue an unconditional warning for a constant overlaying |
4744 | -- a variable. For the reverse case, we will issue it only | |
4745 | -- if the variable is modified, see below. | |
4746 | ||
4747 | elsif Address_Clause_Overlay_Warnings | |
4748 | and then Present (O_Ent) | |
9dfe12ae | 4749 | and then Ekind (U_Ent) = E_Constant |
d6da7448 | 4750 | and then not Is_Constant_Object (O_Ent) |
9dfe12ae | 4751 | then |
1e3532e7 | 4752 | Error_Msg_N ("??constant overlays a variable", Expr); |
9dfe12ae | 4753 | |
d6f39728 | 4754 | -- Imported variables can have an address clause, but then |
4755 | -- the import is pretty meaningless except to suppress | |
4756 | -- initializations, so we do not need such variables to | |
4757 | -- be statically allocated (and in fact it causes trouble | |
4758 | -- if the address clause is a local value). | |
4759 | ||
4760 | elsif Is_Imported (U_Ent) then | |
4761 | Set_Is_Statically_Allocated (U_Ent, False); | |
4762 | end if; | |
4763 | ||
4764 | -- We mark a possible modification of a variable with an | |
4765 | -- address clause, since it is likely aliasing is occurring. | |
4766 | ||
177675a7 | 4767 | Note_Possible_Modification (Nam, Sure => False); |
d6f39728 | 4768 | |
83f8f0a6 | 4769 | -- Here we are checking for explicit overlap of one variable |
4770 | -- by another, and if we find this then mark the overlapped | |
4771 | -- variable as also being volatile to prevent unwanted | |
d6da7448 | 4772 | -- optimizations. This is a significant pessimization so |
4773 | -- avoid it when there is an offset, i.e. when the object | |
4774 | -- is composite; they cannot be optimized easily anyway. | |
d6f39728 | 4775 | |
d6da7448 | 4776 | if Present (O_Ent) |
4777 | and then Is_Object (O_Ent) | |
4778 | and then not Off | |
ba5efa21 | 4779 | |
4780 | -- The following test is an expedient solution to what | |
4781 | -- is really a problem in CodePeer. Suppressing the | |
4782 | -- Set_Treat_As_Volatile call here prevents later | |
4783 | -- generation (in some cases) of trees that CodePeer | |
4784 | -- should, but currently does not, handle correctly. | |
4785 | -- This test should probably be removed when CodePeer | |
4786 | -- is improved, just because we want the tree CodePeer | |
4787 | -- analyzes to match the tree for which we generate code | |
4788 | -- as closely as is practical. ??? | |
4789 | ||
4790 | and then not CodePeer_Mode | |
d6da7448 | 4791 | then |
ba5efa21 | 4792 | -- ??? O_Ent might not be in current unit |
4793 | ||
d6da7448 | 4794 | Set_Treat_As_Volatile (O_Ent); |
d6f39728 | 4795 | end if; |
4796 | ||
9dfe12ae | 4797 | -- Legality checks on the address clause for initialized |
4798 | -- objects is deferred until the freeze point, because | |
2beb22b1 | 4799 | -- a subsequent pragma might indicate that the object |
42e09e36 | 4800 | -- is imported and thus not initialized. Also, the address |
4801 | -- clause might involve entities that have yet to be | |
4802 | -- elaborated. | |
9dfe12ae | 4803 | |
4804 | Set_Has_Delayed_Freeze (U_Ent); | |
4805 | ||
51ad5ad2 | 4806 | -- If an initialization call has been generated for this |
4807 | -- object, it needs to be deferred to after the freeze node | |
4808 | -- we have just now added, otherwise GIGI will see a | |
4809 | -- reference to the variable (as actual to the IP call) | |
4810 | -- before its definition. | |
4811 | ||
4812 | declare | |
df9fba45 | 4813 | Init_Call : constant Node_Id := |
4814 | Remove_Init_Call (U_Ent, N); | |
4bba0a8d | 4815 | |
51ad5ad2 | 4816 | begin |
4817 | if Present (Init_Call) then | |
28a4283c | 4818 | Append_Freeze_Action (U_Ent, Init_Call); |
df9fba45 | 4819 | |
28a4283c | 4820 | -- Reset Initialization_Statements pointer so that |
4821 | -- if there is a pragma Import further down, it can | |
4822 | -- clear any default initialization. | |
df9fba45 | 4823 | |
28a4283c | 4824 | Set_Initialization_Statements (U_Ent, Init_Call); |
51ad5ad2 | 4825 | end if; |
4826 | end; | |
4827 | ||
44e4341e | 4828 | -- Entity has delayed freeze, so we will generate an |
4829 | -- alignment check at the freeze point unless suppressed. | |
d6f39728 | 4830 | |
44e4341e | 4831 | if not Range_Checks_Suppressed (U_Ent) |
4832 | and then not Alignment_Checks_Suppressed (U_Ent) | |
4833 | then | |
4834 | Set_Check_Address_Alignment (N); | |
4835 | end if; | |
d6f39728 | 4836 | |
4837 | -- Kill the size check code, since we are not allocating | |
4838 | -- the variable, it is somewhere else. | |
4839 | ||
4840 | Kill_Size_Check_Code (U_Ent); | |
83f8f0a6 | 4841 | |
d6da7448 | 4842 | -- If the address clause is of the form: |
83f8f0a6 | 4843 | |
d6da7448 | 4844 | -- for Y'Address use X'Address |
83f8f0a6 | 4845 | |
d6da7448 | 4846 | -- or |
83f8f0a6 | 4847 | |
d6da7448 | 4848 | -- Const : constant Address := X'Address; |
4849 | -- ... | |
4850 | -- for Y'Address use Const; | |
83f8f0a6 | 4851 | |
d6da7448 | 4852 | -- then we make an entry in the table for checking the size |
4853 | -- and alignment of the overlaying variable. We defer this | |
4854 | -- check till after code generation to take full advantage | |
f4623c89 | 4855 | -- of the annotation done by the back end. |
d64221a7 | 4856 | |
9474aa9c | 4857 | -- If the entity has a generic type, the check will be |
43dd6937 | 4858 | -- performed in the instance if the actual type justifies |
4859 | -- it, and we do not insert the clause in the table to | |
4860 | -- prevent spurious warnings. | |
83f8f0a6 | 4861 | |
f4623c89 | 4862 | -- Note: we used to test Comes_From_Source and only give |
4863 | -- this warning for source entities, but we have removed | |
4864 | -- this test. It really seems bogus to generate overlays | |
4865 | -- that would trigger this warning in generated code. | |
4866 | -- Furthermore, by removing the test, we handle the | |
4867 | -- aspect case properly. | |
4868 | ||
d6da7448 | 4869 | if Address_Clause_Overlay_Warnings |
d6da7448 | 4870 | and then Present (O_Ent) |
4871 | and then Is_Object (O_Ent) | |
4872 | then | |
9474aa9c | 4873 | if not Is_Generic_Type (Etype (U_Ent)) then |
4874 | Address_Clause_Checks.Append ((N, U_Ent, O_Ent, Off)); | |
4875 | end if; | |
177675a7 | 4876 | |
d6da7448 | 4877 | -- If variable overlays a constant view, and we are |
4878 | -- warning on overlays, then mark the variable as | |
95009d64 | 4879 | -- overlaying a constant and warn immediately if it |
4880 | -- is initialized. We will give other warnings later | |
4881 | -- if the variable is assigned. | |
177675a7 | 4882 | |
d6da7448 | 4883 | if Is_Constant_Object (O_Ent) |
4884 | and then Ekind (U_Ent) = E_Variable | |
4885 | then | |
95009d64 | 4886 | declare |
4887 | Init : constant Node_Id := | |
6a7c16f5 | 4888 | Expression (Declaration_Node (U_Ent)); |
95009d64 | 4889 | begin |
4890 | Set_Overlays_Constant (U_Ent); | |
6a7c16f5 | 4891 | |
95009d64 | 4892 | if Present (Init) |
4893 | and then Comes_From_Source (Init) | |
4894 | then | |
4895 | Error_Msg_Sloc := Sloc (N); | |
4896 | Error_Msg_NE | |
4897 | ("??constant& may be modified via address " | |
4898 | & "clause#", Declaration_Node (U_Ent), O_Ent); | |
4899 | end if; | |
4900 | end; | |
83f8f0a6 | 4901 | end if; |
d6da7448 | 4902 | end if; |
4903 | end; | |
83f8f0a6 | 4904 | |
d6f39728 | 4905 | -- Not a valid entity for an address clause |
4906 | ||
4907 | else | |
4908 | Error_Msg_N ("address cannot be given for &", Nam); | |
4909 | end if; | |
4910 | end Address; | |
4911 | ||
4912 | --------------- | |
4913 | -- Alignment -- | |
4914 | --------------- | |
4915 | ||
4916 | -- Alignment attribute definition clause | |
4917 | ||
b47769f0 | 4918 | when Attribute_Alignment => Alignment : declare |
208fd589 | 4919 | Align : constant Uint := Get_Alignment_Value (Expr); |
4920 | Max_Align : constant Uint := UI_From_Int (Maximum_Alignment); | |
41331dcf | 4921 | |
d6f39728 | 4922 | begin |
4923 | FOnly := True; | |
4924 | ||
4925 | if not Is_Type (U_Ent) | |
4926 | and then Ekind (U_Ent) /= E_Variable | |
4927 | and then Ekind (U_Ent) /= E_Constant | |
4928 | then | |
4929 | Error_Msg_N ("alignment cannot be given for &", Nam); | |
4930 | ||
ae888dbd | 4931 | elsif Duplicate_Clause then |
4932 | null; | |
d6f39728 | 4933 | |
4934 | elsif Align /= No_Uint then | |
4935 | Set_Has_Alignment_Clause (U_Ent); | |
208fd589 | 4936 | |
44705307 | 4937 | -- Tagged type case, check for attempt to set alignment to a |
4938 | -- value greater than Max_Align, and reset if so. | |
4939 | ||
41331dcf | 4940 | if Is_Tagged_Type (U_Ent) and then Align > Max_Align then |
208fd589 | 4941 | Error_Msg_N |
1e3532e7 | 4942 | ("alignment for & set to Maximum_Aligment??", Nam); |
44705307 | 4943 | Set_Alignment (U_Ent, Max_Align); |
4944 | ||
4945 | -- All other cases | |
4946 | ||
208fd589 | 4947 | else |
4948 | Set_Alignment (U_Ent, Align); | |
4949 | end if; | |
b47769f0 | 4950 | |
4951 | -- For an array type, U_Ent is the first subtype. In that case, | |
4952 | -- also set the alignment of the anonymous base type so that | |
4953 | -- other subtypes (such as the itypes for aggregates of the | |
4954 | -- type) also receive the expected alignment. | |
4955 | ||
4956 | if Is_Array_Type (U_Ent) then | |
4957 | Set_Alignment (Base_Type (U_Ent), Align); | |
4958 | end if; | |
d6f39728 | 4959 | end if; |
b47769f0 | 4960 | end Alignment; |
d6f39728 | 4961 | |
4962 | --------------- | |
4963 | -- Bit_Order -- | |
4964 | --------------- | |
4965 | ||
4966 | -- Bit_Order attribute definition clause | |
4967 | ||
4968 | when Attribute_Bit_Order => Bit_Order : declare | |
4969 | begin | |
4970 | if not Is_Record_Type (U_Ent) then | |
4971 | Error_Msg_N | |
4972 | ("Bit_Order can only be defined for record type", Nam); | |
4973 | ||
ae888dbd | 4974 | elsif Duplicate_Clause then |
4975 | null; | |
4976 | ||
d6f39728 | 4977 | else |
4978 | Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); | |
4979 | ||
4980 | if Etype (Expr) = Any_Type then | |
4981 | return; | |
4982 | ||
cda40848 | 4983 | elsif not Is_OK_Static_Expression (Expr) then |
9dfe12ae | 4984 | Flag_Non_Static_Expr |
4985 | ("Bit_Order requires static expression!", Expr); | |
d6f39728 | 4986 | |
4987 | else | |
4988 | if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then | |
fae4ea1f | 4989 | Set_Reverse_Bit_Order (Base_Type (U_Ent), True); |
d6f39728 | 4990 | end if; |
4991 | end if; | |
4992 | end if; | |
4993 | end Bit_Order; | |
4994 | ||
4995 | -------------------- | |
4996 | -- Component_Size -- | |
4997 | -------------------- | |
4998 | ||
4999 | -- Component_Size attribute definition clause | |
5000 | ||
5001 | when Attribute_Component_Size => Component_Size_Case : declare | |
5002 | Csize : constant Uint := Static_Integer (Expr); | |
a0fc8c5b | 5003 | Ctyp : Entity_Id; |
d6f39728 | 5004 | Btype : Entity_Id; |
5005 | Biased : Boolean; | |
5006 | New_Ctyp : Entity_Id; | |
5007 | Decl : Node_Id; | |
5008 | ||
5009 | begin | |
5010 | if not Is_Array_Type (U_Ent) then | |
5011 | Error_Msg_N ("component size requires array type", Nam); | |
5012 | return; | |
5013 | end if; | |
5014 | ||
5015 | Btype := Base_Type (U_Ent); | |
a0fc8c5b | 5016 | Ctyp := Component_Type (Btype); |
d6f39728 | 5017 | |
ae888dbd | 5018 | if Duplicate_Clause then |
5019 | null; | |
d6f39728 | 5020 | |
f3e4db96 | 5021 | elsif Rep_Item_Too_Early (Btype, N) then |
5022 | null; | |
5023 | ||
d6f39728 | 5024 | elsif Csize /= No_Uint then |
a0fc8c5b | 5025 | Check_Size (Expr, Ctyp, Csize, Biased); |
d6f39728 | 5026 | |
d74fc39a | 5027 | -- For the biased case, build a declaration for a subtype that |
5028 | -- will be used to represent the biased subtype that reflects | |
5029 | -- the biased representation of components. We need the subtype | |
5030 | -- to get proper conversions on referencing elements of the | |
36ac5fbb | 5031 | -- array. |
3062c401 | 5032 | |
36ac5fbb | 5033 | if Biased then |
5034 | New_Ctyp := | |
5035 | Make_Defining_Identifier (Loc, | |
5036 | Chars => | |
5037 | New_External_Name (Chars (U_Ent), 'C', 0, 'T')); | |
3062c401 | 5038 | |
36ac5fbb | 5039 | Decl := |
5040 | Make_Subtype_Declaration (Loc, | |
5041 | Defining_Identifier => New_Ctyp, | |
5042 | Subtype_Indication => | |
5043 | New_Occurrence_Of (Component_Type (Btype), Loc)); | |
5044 | ||
5045 | Set_Parent (Decl, N); | |
5046 | Analyze (Decl, Suppress => All_Checks); | |
5047 | ||
5048 | Set_Has_Delayed_Freeze (New_Ctyp, False); | |
5049 | Set_Esize (New_Ctyp, Csize); | |
5050 | Set_RM_Size (New_Ctyp, Csize); | |
5051 | Init_Alignment (New_Ctyp); | |
5052 | Set_Is_Itype (New_Ctyp, True); | |
5053 | Set_Associated_Node_For_Itype (New_Ctyp, U_Ent); | |
5054 | ||
5055 | Set_Component_Type (Btype, New_Ctyp); | |
5056 | Set_Biased (New_Ctyp, N, "component size clause"); | |
d6f39728 | 5057 | end if; |
5058 | ||
36ac5fbb | 5059 | Set_Component_Size (Btype, Csize); |
5060 | ||
a0fc8c5b | 5061 | -- Deal with warning on overridden size |
5062 | ||
5063 | if Warn_On_Overridden_Size | |
5064 | and then Has_Size_Clause (Ctyp) | |
5065 | and then RM_Size (Ctyp) /= Csize | |
5066 | then | |
5067 | Error_Msg_NE | |
1e3532e7 | 5068 | ("component size overrides size clause for&?S?", N, Ctyp); |
a0fc8c5b | 5069 | end if; |
5070 | ||
d6f39728 | 5071 | Set_Has_Component_Size_Clause (Btype, True); |
f3e4db96 | 5072 | Set_Has_Non_Standard_Rep (Btype, True); |
d6f39728 | 5073 | end if; |
5074 | end Component_Size_Case; | |
5075 | ||
81b424ac | 5076 | ----------------------- |
5077 | -- Constant_Indexing -- | |
5078 | ----------------------- | |
5079 | ||
5080 | when Attribute_Constant_Indexing => | |
5081 | Check_Indexing_Functions; | |
5082 | ||
89f1e35c | 5083 | --------- |
5084 | -- CPU -- | |
5085 | --------- | |
5086 | ||
5087 | when Attribute_CPU => CPU : | |
5088 | begin | |
5089 | -- CPU attribute definition clause not allowed except from aspect | |
5090 | -- specification. | |
5091 | ||
5092 | if From_Aspect_Specification (N) then | |
5093 | if not Is_Task_Type (U_Ent) then | |
5094 | Error_Msg_N ("CPU can only be defined for task", Nam); | |
5095 | ||
5096 | elsif Duplicate_Clause then | |
5097 | null; | |
5098 | ||
5099 | else | |
5100 | -- The expression must be analyzed in the special manner | |
5101 | -- described in "Handling of Default and Per-Object | |
5102 | -- Expressions" in sem.ads. | |
5103 | ||
5104 | -- The visibility to the discriminants must be restored | |
5105 | ||
5106 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5107 | Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range)); | |
5108 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
5109 | ||
cda40848 | 5110 | if not Is_OK_Static_Expression (Expr) then |
89f1e35c | 5111 | Check_Restriction (Static_Priorities, Expr); |
5112 | end if; | |
5113 | end if; | |
5114 | ||
5115 | else | |
5116 | Error_Msg_N | |
5117 | ("attribute& cannot be set with definition clause", N); | |
5118 | end if; | |
5119 | end CPU; | |
5120 | ||
89cc7147 | 5121 | ---------------------- |
5122 | -- Default_Iterator -- | |
5123 | ---------------------- | |
5124 | ||
5125 | when Attribute_Default_Iterator => Default_Iterator : declare | |
5126 | Func : Entity_Id; | |
fbf4d6ef | 5127 | Typ : Entity_Id; |
89cc7147 | 5128 | |
5129 | begin | |
05f6f999 | 5130 | -- If target type is untagged, further checks are irrelevant |
5131 | ||
89cc7147 | 5132 | if not Is_Tagged_Type (U_Ent) then |
5133 | Error_Msg_N | |
05f6f999 | 5134 | ("aspect Default_Iterator applies to tagged type", Nam); |
5135 | return; | |
89cc7147 | 5136 | end if; |
5137 | ||
5138 | Check_Iterator_Functions; | |
5139 | ||
5140 | Analyze (Expr); | |
5141 | ||
5142 | if not Is_Entity_Name (Expr) | |
5143 | or else Ekind (Entity (Expr)) /= E_Function | |
5144 | then | |
5145 | Error_Msg_N ("aspect Iterator must be a function", Expr); | |
05f6f999 | 5146 | return; |
89cc7147 | 5147 | else |
5148 | Func := Entity (Expr); | |
5149 | end if; | |
5150 | ||
fbf4d6ef | 5151 | -- The type of the first parameter must be T, T'class, or a |
05f6f999 | 5152 | -- corresponding access type (5.5.1 (8/3). If function is |
5153 | -- parameterless label type accordingly. | |
fbf4d6ef | 5154 | |
5155 | if No (First_Formal (Func)) then | |
05f6f999 | 5156 | Typ := Any_Type; |
fbf4d6ef | 5157 | else |
5158 | Typ := Etype (First_Formal (Func)); | |
5159 | end if; | |
5160 | ||
5161 | if Typ = U_Ent | |
5162 | or else Typ = Class_Wide_Type (U_Ent) | |
5163 | or else (Is_Access_Type (Typ) | |
5164 | and then Designated_Type (Typ) = U_Ent) | |
5165 | or else (Is_Access_Type (Typ) | |
5166 | and then Designated_Type (Typ) = | |
5167 | Class_Wide_Type (U_Ent)) | |
89cc7147 | 5168 | then |
fbf4d6ef | 5169 | null; |
5170 | ||
5171 | else | |
89cc7147 | 5172 | Error_Msg_NE |
5173 | ("Default Iterator must be a primitive of&", Func, U_Ent); | |
5174 | end if; | |
5175 | end Default_Iterator; | |
5176 | ||
89f1e35c | 5177 | ------------------------ |
5178 | -- Dispatching_Domain -- | |
5179 | ------------------------ | |
5180 | ||
5181 | when Attribute_Dispatching_Domain => Dispatching_Domain : | |
5182 | begin | |
5183 | -- Dispatching_Domain attribute definition clause not allowed | |
5184 | -- except from aspect specification. | |
5185 | ||
5186 | if From_Aspect_Specification (N) then | |
5187 | if not Is_Task_Type (U_Ent) then | |
fbf4d6ef | 5188 | Error_Msg_N |
5189 | ("Dispatching_Domain can only be defined for task", Nam); | |
89f1e35c | 5190 | |
5191 | elsif Duplicate_Clause then | |
5192 | null; | |
5193 | ||
5194 | else | |
5195 | -- The expression must be analyzed in the special manner | |
5196 | -- described in "Handling of Default and Per-Object | |
5197 | -- Expressions" in sem.ads. | |
5198 | ||
5199 | -- The visibility to the discriminants must be restored | |
5200 | ||
5201 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5202 | ||
5203 | Preanalyze_Spec_Expression | |
5204 | (Expr, RTE (RE_Dispatching_Domain)); | |
5205 | ||
5206 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
5207 | end if; | |
5208 | ||
5209 | else | |
5210 | Error_Msg_N | |
5211 | ("attribute& cannot be set with definition clause", N); | |
5212 | end if; | |
5213 | end Dispatching_Domain; | |
5214 | ||
d6f39728 | 5215 | ------------------ |
5216 | -- External_Tag -- | |
5217 | ------------------ | |
5218 | ||
5219 | when Attribute_External_Tag => External_Tag : | |
5220 | begin | |
5221 | if not Is_Tagged_Type (U_Ent) then | |
5222 | Error_Msg_N ("should be a tagged type", Nam); | |
5223 | end if; | |
5224 | ||
ae888dbd | 5225 | if Duplicate_Clause then |
5226 | null; | |
d6f39728 | 5227 | |
9af0ddc7 | 5228 | else |
ae888dbd | 5229 | Analyze_And_Resolve (Expr, Standard_String); |
fbc67f84 | 5230 | |
cda40848 | 5231 | if not Is_OK_Static_Expression (Expr) then |
ae888dbd | 5232 | Flag_Non_Static_Expr |
5233 | ("static string required for tag name!", Nam); | |
5234 | end if; | |
5235 | ||
ae888dbd | 5236 | if not Is_Library_Level_Entity (U_Ent) then |
5237 | Error_Msg_NE | |
1e3532e7 | 5238 | ("??non-unique external tag supplied for &", N, U_Ent); |
ae888dbd | 5239 | Error_Msg_N |
1e3532e7 | 5240 | ("\??same external tag applies to all " |
5241 | & "subprogram calls", N); | |
ae888dbd | 5242 | Error_Msg_N |
1e3532e7 | 5243 | ("\??corresponding internal tag cannot be obtained", N); |
ae888dbd | 5244 | end if; |
fbc67f84 | 5245 | end if; |
d6f39728 | 5246 | end External_Tag; |
5247 | ||
b57530b8 | 5248 | -------------------------- |
5249 | -- Implicit_Dereference -- | |
5250 | -------------------------- | |
7947a439 | 5251 | |
b57530b8 | 5252 | when Attribute_Implicit_Dereference => |
7947a439 | 5253 | |
2beb22b1 | 5254 | -- Legality checks already performed at the point of the type |
5255 | -- declaration, aspect is not delayed. | |
7947a439 | 5256 | |
89cc7147 | 5257 | null; |
b57530b8 | 5258 | |
d6f39728 | 5259 | ----------- |
5260 | -- Input -- | |
5261 | ----------- | |
5262 | ||
9f373bb8 | 5263 | when Attribute_Input => |
5264 | Analyze_Stream_TSS_Definition (TSS_Stream_Input); | |
5265 | Set_Has_Specified_Stream_Input (Ent); | |
d6f39728 | 5266 | |
89f1e35c | 5267 | ------------------------ |
5268 | -- Interrupt_Priority -- | |
5269 | ------------------------ | |
5270 | ||
5271 | when Attribute_Interrupt_Priority => Interrupt_Priority : | |
5272 | begin | |
5273 | -- Interrupt_Priority attribute definition clause not allowed | |
5274 | -- except from aspect specification. | |
5275 | ||
5276 | if From_Aspect_Specification (N) then | |
f02a9a9a | 5277 | if not Is_Concurrent_Type (U_Ent) then |
89f1e35c | 5278 | Error_Msg_N |
f02a9a9a | 5279 | ("Interrupt_Priority can only be defined for task " |
5280 | & "and protected object", Nam); | |
89f1e35c | 5281 | |
5282 | elsif Duplicate_Clause then | |
5283 | null; | |
5284 | ||
5285 | else | |
5286 | -- The expression must be analyzed in the special manner | |
5287 | -- described in "Handling of Default and Per-Object | |
5288 | -- Expressions" in sem.ads. | |
5289 | ||
5290 | -- The visibility to the discriminants must be restored | |
5291 | ||
5292 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5293 | ||
5294 | Preanalyze_Spec_Expression | |
5295 | (Expr, RTE (RE_Interrupt_Priority)); | |
5296 | ||
5297 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
d4e1acfa | 5298 | |
5299 | -- Check the No_Task_At_Interrupt_Priority restriction | |
5300 | ||
5301 | if Is_Task_Type (U_Ent) then | |
5302 | Check_Restriction (No_Task_At_Interrupt_Priority, N); | |
5303 | end if; | |
89f1e35c | 5304 | end if; |
5305 | ||
5306 | else | |
5307 | Error_Msg_N | |
5308 | ("attribute& cannot be set with definition clause", N); | |
5309 | end if; | |
5310 | end Interrupt_Priority; | |
5311 | ||
b3f8228a | 5312 | -------------- |
5313 | -- Iterable -- | |
5314 | -------------- | |
5315 | ||
5316 | when Attribute_Iterable => | |
5317 | Analyze (Expr); | |
bde03454 | 5318 | |
b3f8228a | 5319 | if Nkind (Expr) /= N_Aggregate then |
5320 | Error_Msg_N ("aspect Iterable must be an aggregate", Expr); | |
5321 | end if; | |
5322 | ||
5323 | declare | |
5324 | Assoc : Node_Id; | |
5325 | ||
5326 | begin | |
5327 | Assoc := First (Component_Associations (Expr)); | |
5328 | while Present (Assoc) loop | |
5329 | if not Is_Entity_Name (Expression (Assoc)) then | |
5330 | Error_Msg_N ("value must be a function", Assoc); | |
5331 | end if; | |
bde03454 | 5332 | |
b3f8228a | 5333 | Next (Assoc); |
5334 | end loop; | |
5335 | end; | |
5336 | ||
89cc7147 | 5337 | ---------------------- |
5338 | -- Iterator_Element -- | |
5339 | ---------------------- | |
5340 | ||
5341 | when Attribute_Iterator_Element => | |
5342 | Analyze (Expr); | |
5343 | ||
5344 | if not Is_Entity_Name (Expr) | |
5345 | or else not Is_Type (Entity (Expr)) | |
5346 | then | |
5347 | Error_Msg_N ("aspect Iterator_Element must be a type", Expr); | |
5348 | end if; | |
5349 | ||
d6f39728 | 5350 | ------------------- |
5351 | -- Machine_Radix -- | |
5352 | ------------------- | |
5353 | ||
5354 | -- Machine radix attribute definition clause | |
5355 | ||
5356 | when Attribute_Machine_Radix => Machine_Radix : declare | |
5357 | Radix : constant Uint := Static_Integer (Expr); | |
5358 | ||
5359 | begin | |
5360 | if not Is_Decimal_Fixed_Point_Type (U_Ent) then | |
5361 | Error_Msg_N ("decimal fixed-point type expected for &", Nam); | |
5362 | ||
ae888dbd | 5363 | elsif Duplicate_Clause then |
5364 | null; | |
d6f39728 | 5365 | |
5366 | elsif Radix /= No_Uint then | |
5367 | Set_Has_Machine_Radix_Clause (U_Ent); | |
5368 | Set_Has_Non_Standard_Rep (Base_Type (U_Ent)); | |
5369 | ||
5370 | if Radix = 2 then | |
5371 | null; | |
5372 | elsif Radix = 10 then | |
5373 | Set_Machine_Radix_10 (U_Ent); | |
5374 | else | |
5375 | Error_Msg_N ("machine radix value must be 2 or 10", Expr); | |
5376 | end if; | |
5377 | end if; | |
5378 | end Machine_Radix; | |
5379 | ||
5380 | ----------------- | |
5381 | -- Object_Size -- | |
5382 | ----------------- | |
5383 | ||
5384 | -- Object_Size attribute definition clause | |
5385 | ||
5386 | when Attribute_Object_Size => Object_Size : declare | |
bfa5a9d9 | 5387 | Size : constant Uint := Static_Integer (Expr); |
5388 | ||
d6f39728 | 5389 | Biased : Boolean; |
bfa5a9d9 | 5390 | pragma Warnings (Off, Biased); |
d6f39728 | 5391 | |
5392 | begin | |
5393 | if not Is_Type (U_Ent) then | |
5394 | Error_Msg_N ("Object_Size cannot be given for &", Nam); | |
5395 | ||
ae888dbd | 5396 | elsif Duplicate_Clause then |
5397 | null; | |
d6f39728 | 5398 | |
5399 | else | |
5400 | Check_Size (Expr, U_Ent, Size, Biased); | |
5401 | ||
829cd457 | 5402 | if Is_Scalar_Type (U_Ent) then |
5403 | if Size /= 8 and then Size /= 16 and then Size /= 32 | |
5404 | and then UI_Mod (Size, 64) /= 0 | |
5405 | then | |
5406 | Error_Msg_N | |
5407 | ("Object_Size must be 8, 16, 32, or multiple of 64", | |
5408 | Expr); | |
5409 | end if; | |
5410 | ||
5411 | elsif Size mod 8 /= 0 then | |
5412 | Error_Msg_N ("Object_Size must be a multiple of 8", Expr); | |
d6f39728 | 5413 | end if; |
5414 | ||
5415 | Set_Esize (U_Ent, Size); | |
5416 | Set_Has_Object_Size_Clause (U_Ent); | |
1d366b32 | 5417 | Alignment_Check_For_Size_Change (U_Ent, Size); |
d6f39728 | 5418 | end if; |
5419 | end Object_Size; | |
5420 | ||
5421 | ------------ | |
5422 | -- Output -- | |
5423 | ------------ | |
5424 | ||
9f373bb8 | 5425 | when Attribute_Output => |
5426 | Analyze_Stream_TSS_Definition (TSS_Stream_Output); | |
5427 | Set_Has_Specified_Stream_Output (Ent); | |
d6f39728 | 5428 | |
89f1e35c | 5429 | -------------- |
5430 | -- Priority -- | |
5431 | -------------- | |
5432 | ||
5433 | when Attribute_Priority => Priority : | |
5434 | begin | |
5435 | -- Priority attribute definition clause not allowed except from | |
5436 | -- aspect specification. | |
5437 | ||
5438 | if From_Aspect_Specification (N) then | |
f02a9a9a | 5439 | if not (Is_Concurrent_Type (U_Ent) |
3a72f9c3 | 5440 | or else Ekind (U_Ent) = E_Procedure) |
89f1e35c | 5441 | then |
5442 | Error_Msg_N | |
f02a9a9a | 5443 | ("Priority can only be defined for task and protected " |
5444 | & "object", Nam); | |
89f1e35c | 5445 | |
5446 | elsif Duplicate_Clause then | |
5447 | null; | |
5448 | ||
5449 | else | |
5450 | -- The expression must be analyzed in the special manner | |
5451 | -- described in "Handling of Default and Per-Object | |
5452 | -- Expressions" in sem.ads. | |
5453 | ||
5454 | -- The visibility to the discriminants must be restored | |
5455 | ||
5456 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5457 | Preanalyze_Spec_Expression (Expr, Standard_Integer); | |
5458 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
5459 | ||
cda40848 | 5460 | if not Is_OK_Static_Expression (Expr) then |
89f1e35c | 5461 | Check_Restriction (Static_Priorities, Expr); |
5462 | end if; | |
5463 | end if; | |
5464 | ||
5465 | else | |
5466 | Error_Msg_N | |
5467 | ("attribute& cannot be set with definition clause", N); | |
5468 | end if; | |
5469 | end Priority; | |
5470 | ||
d6f39728 | 5471 | ---------- |
5472 | -- Read -- | |
5473 | ---------- | |
5474 | ||
9f373bb8 | 5475 | when Attribute_Read => |
5476 | Analyze_Stream_TSS_Definition (TSS_Stream_Read); | |
5477 | Set_Has_Specified_Stream_Read (Ent); | |
d6f39728 | 5478 | |
b7b74740 | 5479 | -------------------------- |
5480 | -- Scalar_Storage_Order -- | |
5481 | -------------------------- | |
5482 | ||
5483 | -- Scalar_Storage_Order attribute definition clause | |
5484 | ||
5485 | when Attribute_Scalar_Storage_Order => Scalar_Storage_Order : declare | |
5486 | begin | |
b43a5770 | 5487 | if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then |
b7b74740 | 5488 | Error_Msg_N |
b43a5770 | 5489 | ("Scalar_Storage_Order can only be defined for " |
5490 | & "record or array type", Nam); | |
b7b74740 | 5491 | |
5492 | elsif Duplicate_Clause then | |
5493 | null; | |
5494 | ||
5495 | else | |
5496 | Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); | |
5497 | ||
5498 | if Etype (Expr) = Any_Type then | |
5499 | return; | |
5500 | ||
cda40848 | 5501 | elsif not Is_OK_Static_Expression (Expr) then |
b7b74740 | 5502 | Flag_Non_Static_Expr |
5503 | ("Scalar_Storage_Order requires static expression!", Expr); | |
5504 | ||
c0912570 | 5505 | elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then |
5506 | ||
5507 | -- Here for the case of a non-default (i.e. non-confirming) | |
5508 | -- Scalar_Storage_Order attribute definition. | |
5509 | ||
5510 | if Support_Nondefault_SSO_On_Target then | |
d0a9ea3b | 5511 | Set_Reverse_Storage_Order (Base_Type (U_Ent), True); |
c0912570 | 5512 | else |
5513 | Error_Msg_N | |
5514 | ("non-default Scalar_Storage_Order " | |
5515 | & "not supported on target", Expr); | |
b7b74740 | 5516 | end if; |
5517 | end if; | |
b64082f2 | 5518 | |
5519 | -- Clear SSO default indications since explicit setting of the | |
5520 | -- order overrides the defaults. | |
5521 | ||
5522 | Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False); | |
5523 | Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False); | |
b7b74740 | 5524 | end if; |
5525 | end Scalar_Storage_Order; | |
5526 | ||
d6f39728 | 5527 | ---------- |
5528 | -- Size -- | |
5529 | ---------- | |
5530 | ||
5531 | -- Size attribute definition clause | |
5532 | ||
5533 | when Attribute_Size => Size : declare | |
5534 | Size : constant Uint := Static_Integer (Expr); | |
5535 | Etyp : Entity_Id; | |
5536 | Biased : Boolean; | |
5537 | ||
5538 | begin | |
5539 | FOnly := True; | |
5540 | ||
ae888dbd | 5541 | if Duplicate_Clause then |
5542 | null; | |
d6f39728 | 5543 | |
5544 | elsif not Is_Type (U_Ent) | |
5545 | and then Ekind (U_Ent) /= E_Variable | |
5546 | and then Ekind (U_Ent) /= E_Constant | |
5547 | then | |
5548 | Error_Msg_N ("size cannot be given for &", Nam); | |
5549 | ||
5550 | elsif Is_Array_Type (U_Ent) | |
5551 | and then not Is_Constrained (U_Ent) | |
5552 | then | |
5553 | Error_Msg_N | |
5554 | ("size cannot be given for unconstrained array", Nam); | |
5555 | ||
c2b89d6e | 5556 | elsif Size /= No_Uint then |
d6f39728 | 5557 | if Is_Type (U_Ent) then |
5558 | Etyp := U_Ent; | |
5559 | else | |
5560 | Etyp := Etype (U_Ent); | |
5561 | end if; | |
5562 | ||
59ac57b5 | 5563 | -- Check size, note that Gigi is in charge of checking that the |
5564 | -- size of an array or record type is OK. Also we do not check | |
5565 | -- the size in the ordinary fixed-point case, since it is too | |
5566 | -- early to do so (there may be subsequent small clause that | |
5567 | -- affects the size). We can check the size if a small clause | |
5568 | -- has already been given. | |
d6f39728 | 5569 | |
5570 | if not Is_Ordinary_Fixed_Point_Type (U_Ent) | |
5571 | or else Has_Small_Clause (U_Ent) | |
5572 | then | |
5573 | Check_Size (Expr, Etyp, Size, Biased); | |
b77e4501 | 5574 | Set_Biased (U_Ent, N, "size clause", Biased); |
d6f39728 | 5575 | end if; |
5576 | ||
5577 | -- For types set RM_Size and Esize if possible | |
5578 | ||
5579 | if Is_Type (U_Ent) then | |
5580 | Set_RM_Size (U_Ent, Size); | |
5581 | ||
ada34def | 5582 | -- For elementary types, increase Object_Size to power of 2, |
5583 | -- but not less than a storage unit in any case (normally | |
59ac57b5 | 5584 | -- this means it will be byte addressable). |
d6f39728 | 5585 | |
ada34def | 5586 | -- For all other types, nothing else to do, we leave Esize |
5587 | -- (object size) unset, the back end will set it from the | |
5588 | -- size and alignment in an appropriate manner. | |
5589 | ||
1d366b32 | 5590 | -- In both cases, we check whether the alignment must be |
5591 | -- reset in the wake of the size change. | |
5592 | ||
ada34def | 5593 | if Is_Elementary_Type (U_Ent) then |
f15731c4 | 5594 | if Size <= System_Storage_Unit then |
5595 | Init_Esize (U_Ent, System_Storage_Unit); | |
d6f39728 | 5596 | elsif Size <= 16 then |
5597 | Init_Esize (U_Ent, 16); | |
5598 | elsif Size <= 32 then | |
5599 | Init_Esize (U_Ent, 32); | |
5600 | else | |
5601 | Set_Esize (U_Ent, (Size + 63) / 64 * 64); | |
5602 | end if; | |
5603 | ||
1d366b32 | 5604 | Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent)); |
5605 | else | |
5606 | Alignment_Check_For_Size_Change (U_Ent, Size); | |
d6f39728 | 5607 | end if; |
5608 | ||
d6f39728 | 5609 | -- For objects, set Esize only |
5610 | ||
5611 | else | |
9dfe12ae | 5612 | if Is_Elementary_Type (Etyp) then |
5613 | if Size /= System_Storage_Unit | |
5614 | and then | |
5615 | Size /= System_Storage_Unit * 2 | |
5616 | and then | |
5617 | Size /= System_Storage_Unit * 4 | |
5618 | and then | |
5619 | Size /= System_Storage_Unit * 8 | |
5620 | then | |
5c99c290 | 5621 | Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); |
87d5c1d0 | 5622 | Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8; |
9dfe12ae | 5623 | Error_Msg_N |
5c99c290 | 5624 | ("size for primitive object must be a power of 2" |
87d5c1d0 | 5625 | & " in the range ^-^", N); |
9dfe12ae | 5626 | end if; |
5627 | end if; | |
5628 | ||
d6f39728 | 5629 | Set_Esize (U_Ent, Size); |
5630 | end if; | |
5631 | ||
5632 | Set_Has_Size_Clause (U_Ent); | |
5633 | end if; | |
5634 | end Size; | |
5635 | ||
5636 | ----------- | |
5637 | -- Small -- | |
5638 | ----------- | |
5639 | ||
5640 | -- Small attribute definition clause | |
5641 | ||
5642 | when Attribute_Small => Small : declare | |
5643 | Implicit_Base : constant Entity_Id := Base_Type (U_Ent); | |
5644 | Small : Ureal; | |
5645 | ||
5646 | begin | |
5647 | Analyze_And_Resolve (Expr, Any_Real); | |
5648 | ||
5649 | if Etype (Expr) = Any_Type then | |
5650 | return; | |
5651 | ||
cda40848 | 5652 | elsif not Is_OK_Static_Expression (Expr) then |
9dfe12ae | 5653 | Flag_Non_Static_Expr |
5654 | ("small requires static expression!", Expr); | |
d6f39728 | 5655 | return; |
5656 | ||
5657 | else | |
5658 | Small := Expr_Value_R (Expr); | |
5659 | ||
5660 | if Small <= Ureal_0 then | |
5661 | Error_Msg_N ("small value must be greater than zero", Expr); | |
5662 | return; | |
5663 | end if; | |
5664 | ||
5665 | end if; | |
5666 | ||
5667 | if not Is_Ordinary_Fixed_Point_Type (U_Ent) then | |
5668 | Error_Msg_N | |
5669 | ("small requires an ordinary fixed point type", Nam); | |
5670 | ||
5671 | elsif Has_Small_Clause (U_Ent) then | |
5672 | Error_Msg_N ("small already given for &", Nam); | |
5673 | ||
5674 | elsif Small > Delta_Value (U_Ent) then | |
5675 | Error_Msg_N | |
ce3e25d6 | 5676 | ("small value must not be greater than delta value", Nam); |
d6f39728 | 5677 | |
5678 | else | |
5679 | Set_Small_Value (U_Ent, Small); | |
5680 | Set_Small_Value (Implicit_Base, Small); | |
5681 | Set_Has_Small_Clause (U_Ent); | |
5682 | Set_Has_Small_Clause (Implicit_Base); | |
5683 | Set_Has_Non_Standard_Rep (Implicit_Base); | |
5684 | end if; | |
5685 | end Small; | |
5686 | ||
d6f39728 | 5687 | ------------------ |
5688 | -- Storage_Pool -- | |
5689 | ------------------ | |
5690 | ||
5691 | -- Storage_Pool attribute definition clause | |
5692 | ||
b55f7641 | 5693 | when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool => declare |
d6f39728 | 5694 | Pool : Entity_Id; |
6b567c71 | 5695 | T : Entity_Id; |
d6f39728 | 5696 | |
5697 | begin | |
44e4341e | 5698 | if Ekind (U_Ent) = E_Access_Subprogram_Type then |
5699 | Error_Msg_N | |
5700 | ("storage pool cannot be given for access-to-subprogram type", | |
5701 | Nam); | |
5702 | return; | |
5703 | ||
d3ef794c | 5704 | elsif not |
5705 | Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type) | |
d6f39728 | 5706 | then |
44e4341e | 5707 | Error_Msg_N |
5708 | ("storage pool can only be given for access types", Nam); | |
d6f39728 | 5709 | return; |
5710 | ||
5711 | elsif Is_Derived_Type (U_Ent) then | |
5712 | Error_Msg_N | |
5713 | ("storage pool cannot be given for a derived access type", | |
5714 | Nam); | |
5715 | ||
ae888dbd | 5716 | elsif Duplicate_Clause then |
d6f39728 | 5717 | return; |
5718 | ||
5719 | elsif Present (Associated_Storage_Pool (U_Ent)) then | |
5720 | Error_Msg_N ("storage pool already given for &", Nam); | |
5721 | return; | |
5722 | end if; | |
5723 | ||
6653b695 | 5724 | -- Check for Storage_Size previously given |
5725 | ||
5726 | declare | |
5727 | SS : constant Node_Id := | |
5728 | Get_Attribute_Definition_Clause | |
5729 | (U_Ent, Attribute_Storage_Size); | |
5730 | begin | |
5731 | if Present (SS) then | |
5732 | Check_Pool_Size_Clash (U_Ent, N, SS); | |
5733 | end if; | |
5734 | end; | |
5735 | ||
5736 | -- Storage_Pool case | |
5737 | ||
b55f7641 | 5738 | if Id = Attribute_Storage_Pool then |
5739 | Analyze_And_Resolve | |
5740 | (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool))); | |
5741 | ||
5742 | -- In the Simple_Storage_Pool case, we allow a variable of any | |
b15003c3 | 5743 | -- simple storage pool type, so we Resolve without imposing an |
b55f7641 | 5744 | -- expected type. |
5745 | ||
5746 | else | |
5747 | Analyze_And_Resolve (Expr); | |
5748 | ||
5749 | if not Present (Get_Rep_Pragma | |
b15003c3 | 5750 | (Etype (Expr), Name_Simple_Storage_Pool_Type)) |
b55f7641 | 5751 | then |
5752 | Error_Msg_N | |
5753 | ("expression must be of a simple storage pool type", Expr); | |
5754 | end if; | |
5755 | end if; | |
d6f39728 | 5756 | |
8c5c7277 | 5757 | if not Denotes_Variable (Expr) then |
5758 | Error_Msg_N ("storage pool must be a variable", Expr); | |
5759 | return; | |
5760 | end if; | |
5761 | ||
6b567c71 | 5762 | if Nkind (Expr) = N_Type_Conversion then |
5763 | T := Etype (Expression (Expr)); | |
5764 | else | |
5765 | T := Etype (Expr); | |
5766 | end if; | |
5767 | ||
5768 | -- The Stack_Bounded_Pool is used internally for implementing | |
d64221a7 | 5769 | -- access types with a Storage_Size. Since it only work properly |
5770 | -- when used on one specific type, we need to check that it is not | |
5771 | -- hijacked improperly: | |
5772 | ||
6b567c71 | 5773 | -- type T is access Integer; |
5774 | -- for T'Storage_Size use n; | |
5775 | -- type Q is access Float; | |
5776 | -- for Q'Storage_Size use T'Storage_Size; -- incorrect | |
5777 | ||
15ebb600 | 5778 | if RTE_Available (RE_Stack_Bounded_Pool) |
5779 | and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool) | |
5780 | then | |
5781 | Error_Msg_N ("non-shareable internal Pool", Expr); | |
6b567c71 | 5782 | return; |
5783 | end if; | |
5784 | ||
d6f39728 | 5785 | -- If the argument is a name that is not an entity name, then |
5786 | -- we construct a renaming operation to define an entity of | |
5787 | -- type storage pool. | |
5788 | ||
5789 | if not Is_Entity_Name (Expr) | |
5790 | and then Is_Object_Reference (Expr) | |
5791 | then | |
11deeeb6 | 5792 | Pool := Make_Temporary (Loc, 'P', Expr); |
d6f39728 | 5793 | |
5794 | declare | |
5795 | Rnode : constant Node_Id := | |
5796 | Make_Object_Renaming_Declaration (Loc, | |
5797 | Defining_Identifier => Pool, | |
5798 | Subtype_Mark => | |
5799 | New_Occurrence_Of (Etype (Expr), Loc), | |
11deeeb6 | 5800 | Name => Expr); |
d6f39728 | 5801 | |
5802 | begin | |
f65f7fdf | 5803 | -- If the attribute definition clause comes from an aspect |
5804 | -- clause, then insert the renaming before the associated | |
5805 | -- entity's declaration, since the attribute clause has | |
5806 | -- not yet been appended to the declaration list. | |
5807 | ||
5808 | if From_Aspect_Specification (N) then | |
5809 | Insert_Before (Parent (Entity (N)), Rnode); | |
5810 | else | |
5811 | Insert_Before (N, Rnode); | |
5812 | end if; | |
5813 | ||
d6f39728 | 5814 | Analyze (Rnode); |
5815 | Set_Associated_Storage_Pool (U_Ent, Pool); | |
5816 | end; | |
5817 | ||
5818 | elsif Is_Entity_Name (Expr) then | |
5819 | Pool := Entity (Expr); | |
5820 | ||
5821 | -- If pool is a renamed object, get original one. This can | |
5822 | -- happen with an explicit renaming, and within instances. | |
5823 | ||
5824 | while Present (Renamed_Object (Pool)) | |
5825 | and then Is_Entity_Name (Renamed_Object (Pool)) | |
5826 | loop | |
5827 | Pool := Entity (Renamed_Object (Pool)); | |
5828 | end loop; | |
5829 | ||
5830 | if Present (Renamed_Object (Pool)) | |
5831 | and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion | |
5832 | and then Is_Entity_Name (Expression (Renamed_Object (Pool))) | |
5833 | then | |
5834 | Pool := Entity (Expression (Renamed_Object (Pool))); | |
5835 | end if; | |
5836 | ||
6b567c71 | 5837 | Set_Associated_Storage_Pool (U_Ent, Pool); |
d6f39728 | 5838 | |
5839 | elsif Nkind (Expr) = N_Type_Conversion | |
5840 | and then Is_Entity_Name (Expression (Expr)) | |
5841 | and then Nkind (Original_Node (Expr)) = N_Attribute_Reference | |
5842 | then | |
5843 | Pool := Entity (Expression (Expr)); | |
6b567c71 | 5844 | Set_Associated_Storage_Pool (U_Ent, Pool); |
d6f39728 | 5845 | |
5846 | else | |
5847 | Error_Msg_N ("incorrect reference to a Storage Pool", Expr); | |
5848 | return; | |
5849 | end if; | |
b55f7641 | 5850 | end; |
d6f39728 | 5851 | |
44e4341e | 5852 | ------------------ |
5853 | -- Storage_Size -- | |
5854 | ------------------ | |
5855 | ||
5856 | -- Storage_Size attribute definition clause | |
5857 | ||
5858 | when Attribute_Storage_Size => Storage_Size : declare | |
5859 | Btype : constant Entity_Id := Base_Type (U_Ent); | |
44e4341e | 5860 | |
5861 | begin | |
5862 | if Is_Task_Type (U_Ent) then | |
44e4341e | 5863 | |
39a0c1d3 | 5864 | -- Check obsolescent (but never obsolescent if from aspect) |
ceec4f7c | 5865 | |
5866 | if not From_Aspect_Specification (N) then | |
5867 | Check_Restriction (No_Obsolescent_Features, N); | |
5868 | ||
5869 | if Warn_On_Obsolescent_Feature then | |
5870 | Error_Msg_N | |
5871 | ("?j?storage size clause for task is an " & | |
5872 | "obsolescent feature (RM J.9)", N); | |
5873 | Error_Msg_N ("\?j?use Storage_Size pragma instead", N); | |
5874 | end if; | |
44e4341e | 5875 | end if; |
5876 | ||
5877 | FOnly := True; | |
5878 | end if; | |
5879 | ||
5880 | if not Is_Access_Type (U_Ent) | |
5881 | and then Ekind (U_Ent) /= E_Task_Type | |
5882 | then | |
5883 | Error_Msg_N ("storage size cannot be given for &", Nam); | |
5884 | ||
5885 | elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then | |
5886 | Error_Msg_N | |
5887 | ("storage size cannot be given for a derived access type", | |
5888 | Nam); | |
5889 | ||
ae888dbd | 5890 | elsif Duplicate_Clause then |
5891 | null; | |
44e4341e | 5892 | |
5893 | else | |
5894 | Analyze_And_Resolve (Expr, Any_Integer); | |
5895 | ||
5896 | if Is_Access_Type (U_Ent) then | |
6653b695 | 5897 | |
5898 | -- Check for Storage_Pool previously given | |
5899 | ||
5900 | declare | |
5901 | SP : constant Node_Id := | |
5902 | Get_Attribute_Definition_Clause | |
5903 | (U_Ent, Attribute_Storage_Pool); | |
5904 | ||
5905 | begin | |
5906 | if Present (SP) then | |
5907 | Check_Pool_Size_Clash (U_Ent, SP, N); | |
5908 | end if; | |
5909 | end; | |
5910 | ||
5911 | -- Special case of for x'Storage_Size use 0 | |
44e4341e | 5912 | |
5941a4e9 | 5913 | if Is_OK_Static_Expression (Expr) |
44e4341e | 5914 | and then Expr_Value (Expr) = 0 |
5915 | then | |
5916 | Set_No_Pool_Assigned (Btype); | |
5917 | end if; | |
44e4341e | 5918 | end if; |
5919 | ||
5920 | Set_Has_Storage_Size_Clause (Btype); | |
5921 | end if; | |
5922 | end Storage_Size; | |
5923 | ||
7189d17f | 5924 | ----------------- |
5925 | -- Stream_Size -- | |
5926 | ----------------- | |
5927 | ||
5928 | when Attribute_Stream_Size => Stream_Size : declare | |
5929 | Size : constant Uint := Static_Integer (Expr); | |
5930 | ||
5931 | begin | |
15ebb600 | 5932 | if Ada_Version <= Ada_95 then |
5933 | Check_Restriction (No_Implementation_Attributes, N); | |
5934 | end if; | |
5935 | ||
ae888dbd | 5936 | if Duplicate_Clause then |
5937 | null; | |
7189d17f | 5938 | |
5939 | elsif Is_Elementary_Type (U_Ent) then | |
5940 | if Size /= System_Storage_Unit | |
5941 | and then | |
5942 | Size /= System_Storage_Unit * 2 | |
5943 | and then | |
5944 | Size /= System_Storage_Unit * 4 | |
5945 | and then | |
5946 | Size /= System_Storage_Unit * 8 | |
5947 | then | |
5948 | Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); | |
5949 | Error_Msg_N | |
5950 | ("stream size for elementary type must be a" | |
5951 | & " power of 2 and at least ^", N); | |
5952 | ||
5953 | elsif RM_Size (U_Ent) > Size then | |
5954 | Error_Msg_Uint_1 := RM_Size (U_Ent); | |
5955 | Error_Msg_N | |
5956 | ("stream size for elementary type must be a" | |
5957 | & " power of 2 and at least ^", N); | |
5958 | end if; | |
5959 | ||
5960 | Set_Has_Stream_Size_Clause (U_Ent); | |
5961 | ||
5962 | else | |
5963 | Error_Msg_N ("Stream_Size cannot be given for &", Nam); | |
5964 | end if; | |
5965 | end Stream_Size; | |
5966 | ||
d6f39728 | 5967 | ---------------- |
5968 | -- Value_Size -- | |
5969 | ---------------- | |
5970 | ||
5971 | -- Value_Size attribute definition clause | |
5972 | ||
5973 | when Attribute_Value_Size => Value_Size : declare | |
5974 | Size : constant Uint := Static_Integer (Expr); | |
5975 | Biased : Boolean; | |
5976 | ||
5977 | begin | |
5978 | if not Is_Type (U_Ent) then | |
5979 | Error_Msg_N ("Value_Size cannot be given for &", Nam); | |
5980 | ||
ae888dbd | 5981 | elsif Duplicate_Clause then |
5982 | null; | |
d6f39728 | 5983 | |
59ac57b5 | 5984 | elsif Is_Array_Type (U_Ent) |
5985 | and then not Is_Constrained (U_Ent) | |
5986 | then | |
5987 | Error_Msg_N | |
5988 | ("Value_Size cannot be given for unconstrained array", Nam); | |
5989 | ||
d6f39728 | 5990 | else |
5991 | if Is_Elementary_Type (U_Ent) then | |
5992 | Check_Size (Expr, U_Ent, Size, Biased); | |
b77e4501 | 5993 | Set_Biased (U_Ent, N, "value size clause", Biased); |
d6f39728 | 5994 | end if; |
5995 | ||
5996 | Set_RM_Size (U_Ent, Size); | |
5997 | end if; | |
5998 | end Value_Size; | |
5999 | ||
81b424ac | 6000 | ----------------------- |
6001 | -- Variable_Indexing -- | |
6002 | ----------------------- | |
6003 | ||
6004 | when Attribute_Variable_Indexing => | |
6005 | Check_Indexing_Functions; | |
6006 | ||
d6f39728 | 6007 | ----------- |
6008 | -- Write -- | |
6009 | ----------- | |
6010 | ||
9f373bb8 | 6011 | when Attribute_Write => |
6012 | Analyze_Stream_TSS_Definition (TSS_Stream_Write); | |
6013 | Set_Has_Specified_Stream_Write (Ent); | |
d6f39728 | 6014 | |
6015 | -- All other attributes cannot be set | |
6016 | ||
6017 | when others => | |
6018 | Error_Msg_N | |
6019 | ("attribute& cannot be set with definition clause", N); | |
d6f39728 | 6020 | end case; |
6021 | ||
d64221a7 | 6022 | -- The test for the type being frozen must be performed after any |
6023 | -- expression the clause has been analyzed since the expression itself | |
6024 | -- might cause freezing that makes the clause illegal. | |
d6f39728 | 6025 | |
6026 | if Rep_Item_Too_Late (U_Ent, N, FOnly) then | |
6027 | return; | |
6028 | end if; | |
6029 | end Analyze_Attribute_Definition_Clause; | |
6030 | ||
6031 | ---------------------------- | |
6032 | -- Analyze_Code_Statement -- | |
6033 | ---------------------------- | |
6034 | ||
6035 | procedure Analyze_Code_Statement (N : Node_Id) is | |
6036 | HSS : constant Node_Id := Parent (N); | |
6037 | SBody : constant Node_Id := Parent (HSS); | |
6038 | Subp : constant Entity_Id := Current_Scope; | |
6039 | Stmt : Node_Id; | |
6040 | Decl : Node_Id; | |
6041 | StmtO : Node_Id; | |
6042 | DeclO : Node_Id; | |
6043 | ||
6044 | begin | |
6045 | -- Analyze and check we get right type, note that this implements the | |
6046 | -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that | |
6047 | -- is the only way that Asm_Insn could possibly be visible. | |
6048 | ||
6049 | Analyze_And_Resolve (Expression (N)); | |
6050 | ||
6051 | if Etype (Expression (N)) = Any_Type then | |
6052 | return; | |
6053 | elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then | |
6054 | Error_Msg_N ("incorrect type for code statement", N); | |
6055 | return; | |
6056 | end if; | |
6057 | ||
44e4341e | 6058 | Check_Code_Statement (N); |
6059 | ||
d6f39728 | 6060 | -- Make sure we appear in the handled statement sequence of a |
6061 | -- subprogram (RM 13.8(3)). | |
6062 | ||
6063 | if Nkind (HSS) /= N_Handled_Sequence_Of_Statements | |
6064 | or else Nkind (SBody) /= N_Subprogram_Body | |
6065 | then | |
6066 | Error_Msg_N | |
6067 | ("code statement can only appear in body of subprogram", N); | |
6068 | return; | |
6069 | end if; | |
6070 | ||
6071 | -- Do remaining checks (RM 13.8(3)) if not already done | |
6072 | ||
6073 | if not Is_Machine_Code_Subprogram (Subp) then | |
6074 | Set_Is_Machine_Code_Subprogram (Subp); | |
6075 | ||
6076 | -- No exception handlers allowed | |
6077 | ||
6078 | if Present (Exception_Handlers (HSS)) then | |
6079 | Error_Msg_N | |
6080 | ("exception handlers not permitted in machine code subprogram", | |
6081 | First (Exception_Handlers (HSS))); | |
6082 | end if; | |
6083 | ||
6084 | -- No declarations other than use clauses and pragmas (we allow | |
6085 | -- certain internally generated declarations as well). | |
6086 | ||
6087 | Decl := First (Declarations (SBody)); | |
6088 | while Present (Decl) loop | |
6089 | DeclO := Original_Node (Decl); | |
6090 | if Comes_From_Source (DeclO) | |
fdd294d1 | 6091 | and not Nkind_In (DeclO, N_Pragma, |
6092 | N_Use_Package_Clause, | |
6093 | N_Use_Type_Clause, | |
6094 | N_Implicit_Label_Declaration) | |
d6f39728 | 6095 | then |
6096 | Error_Msg_N | |
6097 | ("this declaration not allowed in machine code subprogram", | |
6098 | DeclO); | |
6099 | end if; | |
6100 | ||
6101 | Next (Decl); | |
6102 | end loop; | |
6103 | ||
6104 | -- No statements other than code statements, pragmas, and labels. | |
6105 | -- Again we allow certain internally generated statements. | |
3ab42ff7 | 6106 | |
c3107527 | 6107 | -- In Ada 2012, qualified expressions are names, and the code |
6108 | -- statement is initially parsed as a procedure call. | |
d6f39728 | 6109 | |
6110 | Stmt := First (Statements (HSS)); | |
6111 | while Present (Stmt) loop | |
6112 | StmtO := Original_Node (Stmt); | |
c3107527 | 6113 | |
59f2fcab | 6114 | -- A procedure call transformed into a code statement is OK. |
6115 | ||
c3107527 | 6116 | if Ada_Version >= Ada_2012 |
6117 | and then Nkind (StmtO) = N_Procedure_Call_Statement | |
59f2fcab | 6118 | and then Nkind (Name (StmtO)) = N_Qualified_Expression |
c3107527 | 6119 | then |
6120 | null; | |
6121 | ||
6122 | elsif Comes_From_Source (StmtO) | |
fdd294d1 | 6123 | and then not Nkind_In (StmtO, N_Pragma, |
6124 | N_Label, | |
6125 | N_Code_Statement) | |
d6f39728 | 6126 | then |
6127 | Error_Msg_N | |
6128 | ("this statement is not allowed in machine code subprogram", | |
6129 | StmtO); | |
6130 | end if; | |
6131 | ||
6132 | Next (Stmt); | |
6133 | end loop; | |
6134 | end if; | |
d6f39728 | 6135 | end Analyze_Code_Statement; |
6136 | ||
6137 | ----------------------------------------------- | |
6138 | -- Analyze_Enumeration_Representation_Clause -- | |
6139 | ----------------------------------------------- | |
6140 | ||
6141 | procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is | |
6142 | Ident : constant Node_Id := Identifier (N); | |
6143 | Aggr : constant Node_Id := Array_Aggregate (N); | |
6144 | Enumtype : Entity_Id; | |
6145 | Elit : Entity_Id; | |
6146 | Expr : Node_Id; | |
6147 | Assoc : Node_Id; | |
6148 | Choice : Node_Id; | |
6149 | Val : Uint; | |
b3190af0 | 6150 | |
6151 | Err : Boolean := False; | |
098d3082 | 6152 | -- Set True to avoid cascade errors and crashes on incorrect source code |
d6f39728 | 6153 | |
e30c7d84 | 6154 | Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer)); |
6155 | Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer)); | |
6156 | -- Allowed range of universal integer (= allowed range of enum lit vals) | |
6157 | ||
d6f39728 | 6158 | Min : Uint; |
6159 | Max : Uint; | |
e30c7d84 | 6160 | -- Minimum and maximum values of entries |
6161 | ||
6162 | Max_Node : Node_Id; | |
6163 | -- Pointer to node for literal providing max value | |
d6f39728 | 6164 | |
6165 | begin | |
ca301e17 | 6166 | if Ignore_Rep_Clauses then |
2ff55065 | 6167 | Kill_Rep_Clause (N); |
fbc67f84 | 6168 | return; |
6169 | end if; | |
6170 | ||
175a6969 | 6171 | -- Ignore enumeration rep clauses by default in CodePeer mode, |
6172 | -- unless -gnatd.I is specified, as a work around for potential false | |
6173 | -- positive messages. | |
6174 | ||
6175 | if CodePeer_Mode and not Debug_Flag_Dot_II then | |
6176 | return; | |
6177 | end if; | |
6178 | ||
d6f39728 | 6179 | -- First some basic error checks |
6180 | ||
6181 | Find_Type (Ident); | |
6182 | Enumtype := Entity (Ident); | |
6183 | ||
6184 | if Enumtype = Any_Type | |
6185 | or else Rep_Item_Too_Early (Enumtype, N) | |
6186 | then | |
6187 | return; | |
6188 | else | |
6189 | Enumtype := Underlying_Type (Enumtype); | |
6190 | end if; | |
6191 | ||
6192 | if not Is_Enumeration_Type (Enumtype) then | |
6193 | Error_Msg_NE | |
6194 | ("enumeration type required, found}", | |
6195 | Ident, First_Subtype (Enumtype)); | |
6196 | return; | |
6197 | end if; | |
6198 | ||
9dfe12ae | 6199 | -- Ignore rep clause on generic actual type. This will already have |
6200 | -- been flagged on the template as an error, and this is the safest | |
6201 | -- way to ensure we don't get a junk cascaded message in the instance. | |
6202 | ||
6203 | if Is_Generic_Actual_Type (Enumtype) then | |
6204 | return; | |
6205 | ||
6206 | -- Type must be in current scope | |
6207 | ||
6208 | elsif Scope (Enumtype) /= Current_Scope then | |
d6f39728 | 6209 | Error_Msg_N ("type must be declared in this scope", Ident); |
6210 | return; | |
6211 | ||
9dfe12ae | 6212 | -- Type must be a first subtype |
6213 | ||
d6f39728 | 6214 | elsif not Is_First_Subtype (Enumtype) then |
6215 | Error_Msg_N ("cannot give enumeration rep clause for subtype", N); | |
6216 | return; | |
6217 | ||
9dfe12ae | 6218 | -- Ignore duplicate rep clause |
6219 | ||
d6f39728 | 6220 | elsif Has_Enumeration_Rep_Clause (Enumtype) then |
6221 | Error_Msg_N ("duplicate enumeration rep clause ignored", N); | |
6222 | return; | |
6223 | ||
7189d17f | 6224 | -- Don't allow rep clause for standard [wide_[wide_]]character |
9dfe12ae | 6225 | |
177675a7 | 6226 | elsif Is_Standard_Character_Type (Enumtype) then |
d6f39728 | 6227 | Error_Msg_N ("enumeration rep clause not allowed for this type", N); |
9dfe12ae | 6228 | return; |
6229 | ||
d9125581 | 6230 | -- Check that the expression is a proper aggregate (no parentheses) |
6231 | ||
6232 | elsif Paren_Count (Aggr) /= 0 then | |
6233 | Error_Msg | |
6234 | ("extra parentheses surrounding aggregate not allowed", | |
6235 | First_Sloc (Aggr)); | |
6236 | return; | |
6237 | ||
9dfe12ae | 6238 | -- All tests passed, so set rep clause in place |
d6f39728 | 6239 | |
6240 | else | |
6241 | Set_Has_Enumeration_Rep_Clause (Enumtype); | |
6242 | Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype)); | |
6243 | end if; | |
6244 | ||
6245 | -- Now we process the aggregate. Note that we don't use the normal | |
6246 | -- aggregate code for this purpose, because we don't want any of the | |
6247 | -- normal expansion activities, and a number of special semantic | |
6248 | -- rules apply (including the component type being any integer type) | |
6249 | ||
d6f39728 | 6250 | Elit := First_Literal (Enumtype); |
6251 | ||
6252 | -- First the positional entries if any | |
6253 | ||
6254 | if Present (Expressions (Aggr)) then | |
6255 | Expr := First (Expressions (Aggr)); | |
6256 | while Present (Expr) loop | |
6257 | if No (Elit) then | |
6258 | Error_Msg_N ("too many entries in aggregate", Expr); | |
6259 | return; | |
6260 | end if; | |
6261 | ||
6262 | Val := Static_Integer (Expr); | |
6263 | ||
d9125581 | 6264 | -- Err signals that we found some incorrect entries processing |
6265 | -- the list. The final checks for completeness and ordering are | |
6266 | -- skipped in this case. | |
6267 | ||
d6f39728 | 6268 | if Val = No_Uint then |
6269 | Err := True; | |
f02a9a9a | 6270 | |
d6f39728 | 6271 | elsif Val < Lo or else Hi < Val then |
6272 | Error_Msg_N ("value outside permitted range", Expr); | |
6273 | Err := True; | |
6274 | end if; | |
6275 | ||
6276 | Set_Enumeration_Rep (Elit, Val); | |
6277 | Set_Enumeration_Rep_Expr (Elit, Expr); | |
6278 | Next (Expr); | |
6279 | Next (Elit); | |
6280 | end loop; | |
6281 | end if; | |
6282 | ||
6283 | -- Now process the named entries if present | |
6284 | ||
6285 | if Present (Component_Associations (Aggr)) then | |
6286 | Assoc := First (Component_Associations (Aggr)); | |
6287 | while Present (Assoc) loop | |
6288 | Choice := First (Choices (Assoc)); | |
6289 | ||
6290 | if Present (Next (Choice)) then | |
6291 | Error_Msg_N | |
6292 | ("multiple choice not allowed here", Next (Choice)); | |
6293 | Err := True; | |
6294 | end if; | |
6295 | ||
6296 | if Nkind (Choice) = N_Others_Choice then | |
6297 | Error_Msg_N ("others choice not allowed here", Choice); | |
6298 | Err := True; | |
6299 | ||
6300 | elsif Nkind (Choice) = N_Range then | |
b3190af0 | 6301 | |
d6f39728 | 6302 | -- ??? should allow zero/one element range here |
b3190af0 | 6303 | |
d6f39728 | 6304 | Error_Msg_N ("range not allowed here", Choice); |
6305 | Err := True; | |
6306 | ||
6307 | else | |
6308 | Analyze_And_Resolve (Choice, Enumtype); | |
b3190af0 | 6309 | |
098d3082 | 6310 | if Error_Posted (Choice) then |
d6f39728 | 6311 | Err := True; |
098d3082 | 6312 | end if; |
d6f39728 | 6313 | |
098d3082 | 6314 | if not Err then |
6315 | if Is_Entity_Name (Choice) | |
6316 | and then Is_Type (Entity (Choice)) | |
6317 | then | |
6318 | Error_Msg_N ("subtype name not allowed here", Choice); | |
d6f39728 | 6319 | Err := True; |
b3190af0 | 6320 | |
098d3082 | 6321 | -- ??? should allow static subtype with zero/one entry |
d6f39728 | 6322 | |
098d3082 | 6323 | elsif Etype (Choice) = Base_Type (Enumtype) then |
cda40848 | 6324 | if not Is_OK_Static_Expression (Choice) then |
098d3082 | 6325 | Flag_Non_Static_Expr |
6326 | ("non-static expression used for choice!", Choice); | |
d6f39728 | 6327 | Err := True; |
d6f39728 | 6328 | |
098d3082 | 6329 | else |
6330 | Elit := Expr_Value_E (Choice); | |
6331 | ||
6332 | if Present (Enumeration_Rep_Expr (Elit)) then | |
6333 | Error_Msg_Sloc := | |
6334 | Sloc (Enumeration_Rep_Expr (Elit)); | |
6335 | Error_Msg_NE | |
6336 | ("representation for& previously given#", | |
6337 | Choice, Elit); | |
6338 | Err := True; | |
6339 | end if; | |
d6f39728 | 6340 | |
098d3082 | 6341 | Set_Enumeration_Rep_Expr (Elit, Expression (Assoc)); |
d6f39728 | 6342 | |
098d3082 | 6343 | Expr := Expression (Assoc); |
6344 | Val := Static_Integer (Expr); | |
d6f39728 | 6345 | |
098d3082 | 6346 | if Val = No_Uint then |
6347 | Err := True; | |
6348 | ||
6349 | elsif Val < Lo or else Hi < Val then | |
6350 | Error_Msg_N ("value outside permitted range", Expr); | |
6351 | Err := True; | |
6352 | end if; | |
d6f39728 | 6353 | |
098d3082 | 6354 | Set_Enumeration_Rep (Elit, Val); |
6355 | end if; | |
d6f39728 | 6356 | end if; |
6357 | end if; | |
6358 | end if; | |
6359 | ||
6360 | Next (Assoc); | |
6361 | end loop; | |
6362 | end if; | |
6363 | ||
6364 | -- Aggregate is fully processed. Now we check that a full set of | |
6365 | -- representations was given, and that they are in range and in order. | |
6366 | -- These checks are only done if no other errors occurred. | |
6367 | ||
6368 | if not Err then | |
6369 | Min := No_Uint; | |
6370 | Max := No_Uint; | |
6371 | ||
6372 | Elit := First_Literal (Enumtype); | |
6373 | while Present (Elit) loop | |
6374 | if No (Enumeration_Rep_Expr (Elit)) then | |
6375 | Error_Msg_NE ("missing representation for&!", N, Elit); | |
6376 | ||
6377 | else | |
6378 | Val := Enumeration_Rep (Elit); | |
6379 | ||
6380 | if Min = No_Uint then | |
6381 | Min := Val; | |
6382 | end if; | |
6383 | ||
6384 | if Val /= No_Uint then | |
6385 | if Max /= No_Uint and then Val <= Max then | |
6386 | Error_Msg_NE | |
6387 | ("enumeration value for& not ordered!", | |
e30c7d84 | 6388 | Enumeration_Rep_Expr (Elit), Elit); |
d6f39728 | 6389 | end if; |
6390 | ||
e30c7d84 | 6391 | Max_Node := Enumeration_Rep_Expr (Elit); |
d6f39728 | 6392 | Max := Val; |
6393 | end if; | |
6394 | ||
e30c7d84 | 6395 | -- If there is at least one literal whose representation is not |
6396 | -- equal to the Pos value, then note that this enumeration type | |
6397 | -- has a non-standard representation. | |
d6f39728 | 6398 | |
6399 | if Val /= Enumeration_Pos (Elit) then | |
6400 | Set_Has_Non_Standard_Rep (Base_Type (Enumtype)); | |
6401 | end if; | |
6402 | end if; | |
6403 | ||
6404 | Next (Elit); | |
6405 | end loop; | |
6406 | ||
6407 | -- Now set proper size information | |
6408 | ||
6409 | declare | |
6410 | Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype)); | |
6411 | ||
6412 | begin | |
6413 | if Has_Size_Clause (Enumtype) then | |
e30c7d84 | 6414 | |
6415 | -- All OK, if size is OK now | |
6416 | ||
6417 | if RM_Size (Enumtype) >= Minsize then | |
d6f39728 | 6418 | null; |
6419 | ||
6420 | else | |
e30c7d84 | 6421 | -- Try if we can get by with biasing |
6422 | ||
d6f39728 | 6423 | Minsize := |
6424 | UI_From_Int (Minimum_Size (Enumtype, Biased => True)); | |
6425 | ||
e30c7d84 | 6426 | -- Error message if even biasing does not work |
6427 | ||
6428 | if RM_Size (Enumtype) < Minsize then | |
6429 | Error_Msg_Uint_1 := RM_Size (Enumtype); | |
6430 | Error_Msg_Uint_2 := Max; | |
6431 | Error_Msg_N | |
6432 | ("previously given size (^) is too small " | |
6433 | & "for this value (^)", Max_Node); | |
6434 | ||
6435 | -- If biasing worked, indicate that we now have biased rep | |
d6f39728 | 6436 | |
6437 | else | |
b77e4501 | 6438 | Set_Biased |
6439 | (Enumtype, Size_Clause (Enumtype), "size clause"); | |
d6f39728 | 6440 | end if; |
6441 | end if; | |
6442 | ||
6443 | else | |
6444 | Set_RM_Size (Enumtype, Minsize); | |
6445 | Set_Enum_Esize (Enumtype); | |
6446 | end if; | |
6447 | ||
6448 | Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype)); | |
6449 | Set_Esize (Base_Type (Enumtype), Esize (Enumtype)); | |
6450 | Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype)); | |
6451 | end; | |
6452 | end if; | |
6453 | ||
39a0c1d3 | 6454 | -- We repeat the too late test in case it froze itself |
d6f39728 | 6455 | |
6456 | if Rep_Item_Too_Late (Enumtype, N) then | |
6457 | null; | |
6458 | end if; | |
d6f39728 | 6459 | end Analyze_Enumeration_Representation_Clause; |
6460 | ||
6461 | ---------------------------- | |
6462 | -- Analyze_Free_Statement -- | |
6463 | ---------------------------- | |
6464 | ||
6465 | procedure Analyze_Free_Statement (N : Node_Id) is | |
6466 | begin | |
6467 | Analyze (Expression (N)); | |
6468 | end Analyze_Free_Statement; | |
6469 | ||
40ca69b9 | 6470 | --------------------------- |
6471 | -- Analyze_Freeze_Entity -- | |
6472 | --------------------------- | |
6473 | ||
6474 | procedure Analyze_Freeze_Entity (N : Node_Id) is | |
40ca69b9 | 6475 | begin |
d9f6a4ee | 6476 | Freeze_Entity_Checks (N); |
6477 | end Analyze_Freeze_Entity; | |
98f7db28 | 6478 | |
d9f6a4ee | 6479 | ----------------------------------- |
6480 | -- Analyze_Freeze_Generic_Entity -- | |
6481 | ----------------------------------- | |
98f7db28 | 6482 | |
d9f6a4ee | 6483 | procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is |
6484 | begin | |
6485 | Freeze_Entity_Checks (N); | |
6486 | end Analyze_Freeze_Generic_Entity; | |
40ca69b9 | 6487 | |
d9f6a4ee | 6488 | ------------------------------------------ |
6489 | -- Analyze_Record_Representation_Clause -- | |
6490 | ------------------------------------------ | |
c8da6114 | 6491 | |
d9f6a4ee | 6492 | -- Note: we check as much as we can here, but we can't do any checks |
6493 | -- based on the position values (e.g. overlap checks) until freeze time | |
6494 | -- because especially in Ada 2005 (machine scalar mode), the processing | |
6495 | -- for non-standard bit order can substantially change the positions. | |
6496 | -- See procedure Check_Record_Representation_Clause (called from Freeze) | |
6497 | -- for the remainder of this processing. | |
d00681a7 | 6498 | |
d9f6a4ee | 6499 | procedure Analyze_Record_Representation_Clause (N : Node_Id) is |
6500 | Ident : constant Node_Id := Identifier (N); | |
6501 | Biased : Boolean; | |
6502 | CC : Node_Id; | |
6503 | Comp : Entity_Id; | |
6504 | Fbit : Uint; | |
6505 | Hbit : Uint := Uint_0; | |
6506 | Lbit : Uint; | |
6507 | Ocomp : Entity_Id; | |
6508 | Posit : Uint; | |
6509 | Rectype : Entity_Id; | |
6510 | Recdef : Node_Id; | |
d00681a7 | 6511 | |
d9f6a4ee | 6512 | function Is_Inherited (Comp : Entity_Id) return Boolean; |
6513 | -- True if Comp is an inherited component in a record extension | |
d00681a7 | 6514 | |
d9f6a4ee | 6515 | ------------------ |
6516 | -- Is_Inherited -- | |
6517 | ------------------ | |
d00681a7 | 6518 | |
d9f6a4ee | 6519 | function Is_Inherited (Comp : Entity_Id) return Boolean is |
6520 | Comp_Base : Entity_Id; | |
d00681a7 | 6521 | |
d9f6a4ee | 6522 | begin |
6523 | if Ekind (Rectype) = E_Record_Subtype then | |
6524 | Comp_Base := Original_Record_Component (Comp); | |
6525 | else | |
6526 | Comp_Base := Comp; | |
d00681a7 | 6527 | end if; |
6528 | ||
d9f6a4ee | 6529 | return Comp_Base /= Original_Record_Component (Comp_Base); |
6530 | end Is_Inherited; | |
d00681a7 | 6531 | |
d9f6a4ee | 6532 | -- Local variables |
d00681a7 | 6533 | |
d9f6a4ee | 6534 | Is_Record_Extension : Boolean; |
6535 | -- True if Rectype is a record extension | |
d00681a7 | 6536 | |
d9f6a4ee | 6537 | CR_Pragma : Node_Id := Empty; |
6538 | -- Points to N_Pragma node if Complete_Representation pragma present | |
d00681a7 | 6539 | |
d9f6a4ee | 6540 | -- Start of processing for Analyze_Record_Representation_Clause |
d00681a7 | 6541 | |
d9f6a4ee | 6542 | begin |
6543 | if Ignore_Rep_Clauses then | |
2ff55065 | 6544 | Kill_Rep_Clause (N); |
d9f6a4ee | 6545 | return; |
d00681a7 | 6546 | end if; |
98f7db28 | 6547 | |
d9f6a4ee | 6548 | Find_Type (Ident); |
6549 | Rectype := Entity (Ident); | |
85377c9b | 6550 | |
d9f6a4ee | 6551 | if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then |
6552 | return; | |
6553 | else | |
6554 | Rectype := Underlying_Type (Rectype); | |
6555 | end if; | |
85377c9b | 6556 | |
d9f6a4ee | 6557 | -- First some basic error checks |
85377c9b | 6558 | |
d9f6a4ee | 6559 | if not Is_Record_Type (Rectype) then |
6560 | Error_Msg_NE | |
6561 | ("record type required, found}", Ident, First_Subtype (Rectype)); | |
6562 | return; | |
85377c9b | 6563 | |
d9f6a4ee | 6564 | elsif Scope (Rectype) /= Current_Scope then |
6565 | Error_Msg_N ("type must be declared in this scope", N); | |
6566 | return; | |
85377c9b | 6567 | |
d9f6a4ee | 6568 | elsif not Is_First_Subtype (Rectype) then |
6569 | Error_Msg_N ("cannot give record rep clause for subtype", N); | |
6570 | return; | |
9dc88aea | 6571 | |
d9f6a4ee | 6572 | elsif Has_Record_Rep_Clause (Rectype) then |
6573 | Error_Msg_N ("duplicate record rep clause ignored", N); | |
6574 | return; | |
9dc88aea | 6575 | |
d9f6a4ee | 6576 | elsif Rep_Item_Too_Late (Rectype, N) then |
6577 | return; | |
9dc88aea | 6578 | end if; |
fb7f2fc4 | 6579 | |
2ced3742 | 6580 | -- We know we have a first subtype, now possibly go to the anonymous |
d9f6a4ee | 6581 | -- base type to determine whether Rectype is a record extension. |
89f1e35c | 6582 | |
d9f6a4ee | 6583 | Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype))); |
6584 | Is_Record_Extension := | |
6585 | Nkind (Recdef) = N_Derived_Type_Definition | |
6586 | and then Present (Record_Extension_Part (Recdef)); | |
89f1e35c | 6587 | |
d9f6a4ee | 6588 | if Present (Mod_Clause (N)) then |
fb7f2fc4 | 6589 | declare |
d9f6a4ee | 6590 | Loc : constant Source_Ptr := Sloc (N); |
6591 | M : constant Node_Id := Mod_Clause (N); | |
6592 | P : constant List_Id := Pragmas_Before (M); | |
6593 | AtM_Nod : Node_Id; | |
6594 | ||
6595 | Mod_Val : Uint; | |
6596 | pragma Warnings (Off, Mod_Val); | |
fb7f2fc4 | 6597 | |
6598 | begin | |
d9f6a4ee | 6599 | Check_Restriction (No_Obsolescent_Features, Mod_Clause (N)); |
fb7f2fc4 | 6600 | |
d9f6a4ee | 6601 | if Warn_On_Obsolescent_Feature then |
6602 | Error_Msg_N | |
6603 | ("?j?mod clause is an obsolescent feature (RM J.8)", N); | |
6604 | Error_Msg_N | |
6605 | ("\?j?use alignment attribute definition clause instead", N); | |
6606 | end if; | |
fb7f2fc4 | 6607 | |
d9f6a4ee | 6608 | if Present (P) then |
6609 | Analyze_List (P); | |
6610 | end if; | |
89f1e35c | 6611 | |
d9f6a4ee | 6612 | -- In ASIS_Mode mode, expansion is disabled, but we must convert |
6613 | -- the Mod clause into an alignment clause anyway, so that the | |
6614 | -- back-end can compute and back-annotate properly the size and | |
6615 | -- alignment of types that may include this record. | |
be9124d0 | 6616 | |
d9f6a4ee | 6617 | -- This seems dubious, this destroys the source tree in a manner |
6618 | -- not detectable by ASIS ??? | |
be9124d0 | 6619 | |
d9f6a4ee | 6620 | if Operating_Mode = Check_Semantics and then ASIS_Mode then |
6621 | AtM_Nod := | |
6622 | Make_Attribute_Definition_Clause (Loc, | |
83c6c069 | 6623 | Name => New_Occurrence_Of (Base_Type (Rectype), Loc), |
d9f6a4ee | 6624 | Chars => Name_Alignment, |
6625 | Expression => Relocate_Node (Expression (M))); | |
be9124d0 | 6626 | |
d9f6a4ee | 6627 | Set_From_At_Mod (AtM_Nod); |
6628 | Insert_After (N, AtM_Nod); | |
6629 | Mod_Val := Get_Alignment_Value (Expression (AtM_Nod)); | |
6630 | Set_Mod_Clause (N, Empty); | |
be9124d0 | 6631 | |
d9f6a4ee | 6632 | else |
6633 | -- Get the alignment value to perform error checking | |
be9124d0 | 6634 | |
d9f6a4ee | 6635 | Mod_Val := Get_Alignment_Value (Expression (M)); |
6636 | end if; | |
6637 | end; | |
6638 | end if; | |
be9124d0 | 6639 | |
d9f6a4ee | 6640 | -- For untagged types, clear any existing component clauses for the |
6641 | -- type. If the type is derived, this is what allows us to override | |
6642 | -- a rep clause for the parent. For type extensions, the representation | |
6643 | -- of the inherited components is inherited, so we want to keep previous | |
6644 | -- component clauses for completeness. | |
be9124d0 | 6645 | |
d9f6a4ee | 6646 | if not Is_Tagged_Type (Rectype) then |
6647 | Comp := First_Component_Or_Discriminant (Rectype); | |
6648 | while Present (Comp) loop | |
6649 | Set_Component_Clause (Comp, Empty); | |
6650 | Next_Component_Or_Discriminant (Comp); | |
6651 | end loop; | |
6652 | end if; | |
be9124d0 | 6653 | |
d9f6a4ee | 6654 | -- All done if no component clauses |
be9124d0 | 6655 | |
d9f6a4ee | 6656 | CC := First (Component_Clauses (N)); |
be9124d0 | 6657 | |
d9f6a4ee | 6658 | if No (CC) then |
6659 | return; | |
6660 | end if; | |
be9124d0 | 6661 | |
d9f6a4ee | 6662 | -- A representation like this applies to the base type |
be9124d0 | 6663 | |
d9f6a4ee | 6664 | Set_Has_Record_Rep_Clause (Base_Type (Rectype)); |
6665 | Set_Has_Non_Standard_Rep (Base_Type (Rectype)); | |
6666 | Set_Has_Specified_Layout (Base_Type (Rectype)); | |
be9124d0 | 6667 | |
d9f6a4ee | 6668 | -- Process the component clauses |
be9124d0 | 6669 | |
d9f6a4ee | 6670 | while Present (CC) loop |
be9124d0 | 6671 | |
d9f6a4ee | 6672 | -- Pragma |
be9124d0 | 6673 | |
d9f6a4ee | 6674 | if Nkind (CC) = N_Pragma then |
6675 | Analyze (CC); | |
be9124d0 | 6676 | |
d9f6a4ee | 6677 | -- The only pragma of interest is Complete_Representation |
be9124d0 | 6678 | |
d9f6a4ee | 6679 | if Pragma_Name (CC) = Name_Complete_Representation then |
6680 | CR_Pragma := CC; | |
6681 | end if; | |
be9124d0 | 6682 | |
d9f6a4ee | 6683 | -- Processing for real component clause |
be9124d0 | 6684 | |
d9f6a4ee | 6685 | else |
6686 | Posit := Static_Integer (Position (CC)); | |
6687 | Fbit := Static_Integer (First_Bit (CC)); | |
6688 | Lbit := Static_Integer (Last_Bit (CC)); | |
be9124d0 | 6689 | |
d9f6a4ee | 6690 | if Posit /= No_Uint |
6691 | and then Fbit /= No_Uint | |
6692 | and then Lbit /= No_Uint | |
6693 | then | |
6694 | if Posit < 0 then | |
6695 | Error_Msg_N | |
6696 | ("position cannot be negative", Position (CC)); | |
be9124d0 | 6697 | |
d9f6a4ee | 6698 | elsif Fbit < 0 then |
6699 | Error_Msg_N | |
6700 | ("first bit cannot be negative", First_Bit (CC)); | |
be9124d0 | 6701 | |
d9f6a4ee | 6702 | -- The Last_Bit specified in a component clause must not be |
6703 | -- less than the First_Bit minus one (RM-13.5.1(10)). | |
be9124d0 | 6704 | |
d9f6a4ee | 6705 | elsif Lbit < Fbit - 1 then |
6706 | Error_Msg_N | |
6707 | ("last bit cannot be less than first bit minus one", | |
6708 | Last_Bit (CC)); | |
be9124d0 | 6709 | |
d9f6a4ee | 6710 | -- Values look OK, so find the corresponding record component |
6711 | -- Even though the syntax allows an attribute reference for | |
6712 | -- implementation-defined components, GNAT does not allow the | |
6713 | -- tag to get an explicit position. | |
be9124d0 | 6714 | |
d9f6a4ee | 6715 | elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then |
6716 | if Attribute_Name (Component_Name (CC)) = Name_Tag then | |
6717 | Error_Msg_N ("position of tag cannot be specified", CC); | |
6718 | else | |
6719 | Error_Msg_N ("illegal component name", CC); | |
6720 | end if; | |
be9124d0 | 6721 | |
d9f6a4ee | 6722 | else |
6723 | Comp := First_Entity (Rectype); | |
6724 | while Present (Comp) loop | |
6725 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
6726 | Next_Entity (Comp); | |
6727 | end loop; | |
be9124d0 | 6728 | |
d9f6a4ee | 6729 | if No (Comp) then |
be9124d0 | 6730 | |
d9f6a4ee | 6731 | -- Maybe component of base type that is absent from |
6732 | -- statically constrained first subtype. | |
be9124d0 | 6733 | |
d9f6a4ee | 6734 | Comp := First_Entity (Base_Type (Rectype)); |
6735 | while Present (Comp) loop | |
6736 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
6737 | Next_Entity (Comp); | |
6738 | end loop; | |
6739 | end if; | |
be9124d0 | 6740 | |
d9f6a4ee | 6741 | if No (Comp) then |
6742 | Error_Msg_N | |
6743 | ("component clause is for non-existent field", CC); | |
be9124d0 | 6744 | |
d9f6a4ee | 6745 | -- Ada 2012 (AI05-0026): Any name that denotes a |
6746 | -- discriminant of an object of an unchecked union type | |
6747 | -- shall not occur within a record_representation_clause. | |
be9124d0 | 6748 | |
d9f6a4ee | 6749 | -- The general restriction of using record rep clauses on |
6750 | -- Unchecked_Union types has now been lifted. Since it is | |
6751 | -- possible to introduce a record rep clause which mentions | |
6752 | -- the discriminant of an Unchecked_Union in non-Ada 2012 | |
6753 | -- code, this check is applied to all versions of the | |
6754 | -- language. | |
be9124d0 | 6755 | |
d9f6a4ee | 6756 | elsif Ekind (Comp) = E_Discriminant |
6757 | and then Is_Unchecked_Union (Rectype) | |
6758 | then | |
6759 | Error_Msg_N | |
6760 | ("cannot reference discriminant of unchecked union", | |
6761 | Component_Name (CC)); | |
be9124d0 | 6762 | |
d9f6a4ee | 6763 | elsif Is_Record_Extension and then Is_Inherited (Comp) then |
6764 | Error_Msg_NE | |
6765 | ("component clause not allowed for inherited " | |
6766 | & "component&", CC, Comp); | |
40ca69b9 | 6767 | |
d9f6a4ee | 6768 | elsif Present (Component_Clause (Comp)) then |
462a079f | 6769 | |
d9f6a4ee | 6770 | -- Diagnose duplicate rep clause, or check consistency |
6771 | -- if this is an inherited component. In a double fault, | |
6772 | -- there may be a duplicate inconsistent clause for an | |
6773 | -- inherited component. | |
462a079f | 6774 | |
d9f6a4ee | 6775 | if Scope (Original_Record_Component (Comp)) = Rectype |
6776 | or else Parent (Component_Clause (Comp)) = N | |
6777 | then | |
6778 | Error_Msg_Sloc := Sloc (Component_Clause (Comp)); | |
6779 | Error_Msg_N ("component clause previously given#", CC); | |
3062c401 | 6780 | |
6781 | else | |
6782 | declare | |
6783 | Rep1 : constant Node_Id := Component_Clause (Comp); | |
3062c401 | 6784 | begin |
6785 | if Intval (Position (Rep1)) /= | |
6786 | Intval (Position (CC)) | |
6787 | or else Intval (First_Bit (Rep1)) /= | |
6788 | Intval (First_Bit (CC)) | |
6789 | or else Intval (Last_Bit (Rep1)) /= | |
6790 | Intval (Last_Bit (CC)) | |
6791 | then | |
b9e61b2a | 6792 | Error_Msg_N |
6793 | ("component clause inconsistent " | |
6794 | & "with representation of ancestor", CC); | |
6a06584c | 6795 | |
3062c401 | 6796 | elsif Warn_On_Redundant_Constructs then |
b9e61b2a | 6797 | Error_Msg_N |
6a06584c | 6798 | ("?r?redundant confirming component clause " |
6799 | & "for component!", CC); | |
3062c401 | 6800 | end if; |
6801 | end; | |
6802 | end if; | |
d6f39728 | 6803 | |
d2b860b4 | 6804 | -- Normal case where this is the first component clause we |
6805 | -- have seen for this entity, so set it up properly. | |
6806 | ||
d6f39728 | 6807 | else |
83f8f0a6 | 6808 | -- Make reference for field in record rep clause and set |
6809 | -- appropriate entity field in the field identifier. | |
6810 | ||
6811 | Generate_Reference | |
6812 | (Comp, Component_Name (CC), Set_Ref => False); | |
6813 | Set_Entity (Component_Name (CC), Comp); | |
6814 | ||
2866d595 | 6815 | -- Update Fbit and Lbit to the actual bit number |
d6f39728 | 6816 | |
6817 | Fbit := Fbit + UI_From_Int (SSU) * Posit; | |
6818 | Lbit := Lbit + UI_From_Int (SSU) * Posit; | |
6819 | ||
d6f39728 | 6820 | if Has_Size_Clause (Rectype) |
ada34def | 6821 | and then RM_Size (Rectype) <= Lbit |
d6f39728 | 6822 | then |
6823 | Error_Msg_N | |
6824 | ("bit number out of range of specified size", | |
6825 | Last_Bit (CC)); | |
6826 | else | |
6827 | Set_Component_Clause (Comp, CC); | |
6828 | Set_Component_Bit_Offset (Comp, Fbit); | |
6829 | Set_Esize (Comp, 1 + (Lbit - Fbit)); | |
6830 | Set_Normalized_First_Bit (Comp, Fbit mod SSU); | |
6831 | Set_Normalized_Position (Comp, Fbit / SSU); | |
6832 | ||
a0fc8c5b | 6833 | if Warn_On_Overridden_Size |
6834 | and then Has_Size_Clause (Etype (Comp)) | |
6835 | and then RM_Size (Etype (Comp)) /= Esize (Comp) | |
6836 | then | |
6837 | Error_Msg_NE | |
1e3532e7 | 6838 | ("?S?component size overrides size clause for&", |
a0fc8c5b | 6839 | Component_Name (CC), Etype (Comp)); |
6840 | end if; | |
6841 | ||
ea61a7ea | 6842 | -- This information is also set in the corresponding |
6843 | -- component of the base type, found by accessing the | |
6844 | -- Original_Record_Component link if it is present. | |
d6f39728 | 6845 | |
6846 | Ocomp := Original_Record_Component (Comp); | |
6847 | ||
6848 | if Hbit < Lbit then | |
6849 | Hbit := Lbit; | |
6850 | end if; | |
6851 | ||
6852 | Check_Size | |
6853 | (Component_Name (CC), | |
6854 | Etype (Comp), | |
6855 | Esize (Comp), | |
6856 | Biased); | |
6857 | ||
b77e4501 | 6858 | Set_Biased |
6859 | (Comp, First_Node (CC), "component clause", Biased); | |
cc46ff4b | 6860 | |
d6f39728 | 6861 | if Present (Ocomp) then |
6862 | Set_Component_Clause (Ocomp, CC); | |
6863 | Set_Component_Bit_Offset (Ocomp, Fbit); | |
6864 | Set_Normalized_First_Bit (Ocomp, Fbit mod SSU); | |
6865 | Set_Normalized_Position (Ocomp, Fbit / SSU); | |
6866 | Set_Esize (Ocomp, 1 + (Lbit - Fbit)); | |
6867 | ||
6868 | Set_Normalized_Position_Max | |
6869 | (Ocomp, Normalized_Position (Ocomp)); | |
6870 | ||
b77e4501 | 6871 | -- Note: we don't use Set_Biased here, because we |
6872 | -- already gave a warning above if needed, and we | |
6873 | -- would get a duplicate for the same name here. | |
6874 | ||
d6f39728 | 6875 | Set_Has_Biased_Representation |
6876 | (Ocomp, Has_Biased_Representation (Comp)); | |
6877 | end if; | |
6878 | ||
6879 | if Esize (Comp) < 0 then | |
6880 | Error_Msg_N ("component size is negative", CC); | |
6881 | end if; | |
6882 | end if; | |
6883 | end if; | |
6884 | end if; | |
6885 | end if; | |
6886 | end if; | |
6887 | ||
6888 | Next (CC); | |
6889 | end loop; | |
6890 | ||
67278d60 | 6891 | -- Check missing components if Complete_Representation pragma appeared |
d6f39728 | 6892 | |
67278d60 | 6893 | if Present (CR_Pragma) then |
6894 | Comp := First_Component_Or_Discriminant (Rectype); | |
6895 | while Present (Comp) loop | |
6896 | if No (Component_Clause (Comp)) then | |
6897 | Error_Msg_NE | |
6898 | ("missing component clause for &", CR_Pragma, Comp); | |
6899 | end if; | |
d6f39728 | 6900 | |
67278d60 | 6901 | Next_Component_Or_Discriminant (Comp); |
6902 | end loop; | |
d6f39728 | 6903 | |
1e3532e7 | 6904 | -- Give missing components warning if required |
15ebb600 | 6905 | |
fdd294d1 | 6906 | elsif Warn_On_Unrepped_Components then |
15ebb600 | 6907 | declare |
6908 | Num_Repped_Components : Nat := 0; | |
6909 | Num_Unrepped_Components : Nat := 0; | |
6910 | ||
6911 | begin | |
6912 | -- First count number of repped and unrepped components | |
6913 | ||
6914 | Comp := First_Component_Or_Discriminant (Rectype); | |
6915 | while Present (Comp) loop | |
6916 | if Present (Component_Clause (Comp)) then | |
6917 | Num_Repped_Components := Num_Repped_Components + 1; | |
6918 | else | |
6919 | Num_Unrepped_Components := Num_Unrepped_Components + 1; | |
6920 | end if; | |
6921 | ||
6922 | Next_Component_Or_Discriminant (Comp); | |
6923 | end loop; | |
6924 | ||
6925 | -- We are only interested in the case where there is at least one | |
6926 | -- unrepped component, and at least half the components have rep | |
6927 | -- clauses. We figure that if less than half have them, then the | |
87f9eef5 | 6928 | -- partial rep clause is really intentional. If the component |
6929 | -- type has no underlying type set at this point (as for a generic | |
6930 | -- formal type), we don't know enough to give a warning on the | |
6931 | -- component. | |
15ebb600 | 6932 | |
6933 | if Num_Unrepped_Components > 0 | |
6934 | and then Num_Unrepped_Components < Num_Repped_Components | |
6935 | then | |
6936 | Comp := First_Component_Or_Discriminant (Rectype); | |
6937 | while Present (Comp) loop | |
83f8f0a6 | 6938 | if No (Component_Clause (Comp)) |
3062c401 | 6939 | and then Comes_From_Source (Comp) |
87f9eef5 | 6940 | and then Present (Underlying_Type (Etype (Comp))) |
83f8f0a6 | 6941 | and then (Is_Scalar_Type (Underlying_Type (Etype (Comp))) |
67278d60 | 6942 | or else Size_Known_At_Compile_Time |
6943 | (Underlying_Type (Etype (Comp)))) | |
fdd294d1 | 6944 | and then not Has_Warnings_Off (Rectype) |
2be1f7d7 | 6945 | |
6946 | -- Ignore discriminant in unchecked union, since it is | |
6947 | -- not there, and cannot have a component clause. | |
6948 | ||
6949 | and then (not Is_Unchecked_Union (Rectype) | |
6950 | or else Ekind (Comp) /= E_Discriminant) | |
83f8f0a6 | 6951 | then |
15ebb600 | 6952 | Error_Msg_Sloc := Sloc (Comp); |
6953 | Error_Msg_NE | |
1e3532e7 | 6954 | ("?C?no component clause given for & declared #", |
15ebb600 | 6955 | N, Comp); |
6956 | end if; | |
6957 | ||
6958 | Next_Component_Or_Discriminant (Comp); | |
6959 | end loop; | |
6960 | end if; | |
6961 | end; | |
d6f39728 | 6962 | end if; |
d6f39728 | 6963 | end Analyze_Record_Representation_Clause; |
6964 | ||
eb66e842 | 6965 | ------------------------------------- |
6966 | -- Build_Discrete_Static_Predicate -- | |
6967 | ------------------------------------- | |
9ea61fdd | 6968 | |
eb66e842 | 6969 | procedure Build_Discrete_Static_Predicate |
6970 | (Typ : Entity_Id; | |
6971 | Expr : Node_Id; | |
6972 | Nam : Name_Id) | |
9ea61fdd | 6973 | is |
eb66e842 | 6974 | Loc : constant Source_Ptr := Sloc (Expr); |
9ea61fdd | 6975 | |
eb66e842 | 6976 | Non_Static : exception; |
6977 | -- Raised if something non-static is found | |
9ea61fdd | 6978 | |
eb66e842 | 6979 | Btyp : constant Entity_Id := Base_Type (Typ); |
9ea61fdd | 6980 | |
eb66e842 | 6981 | BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp)); |
6982 | BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp)); | |
6983 | -- Low bound and high bound value of base type of Typ | |
9ea61fdd | 6984 | |
afc229da | 6985 | TLo : Uint; |
6986 | THi : Uint; | |
6987 | -- Bounds for constructing the static predicate. We use the bound of the | |
6988 | -- subtype if it is static, otherwise the corresponding base type bound. | |
6989 | -- Note: a non-static subtype can have a static predicate. | |
9ea61fdd | 6990 | |
eb66e842 | 6991 | type REnt is record |
6992 | Lo, Hi : Uint; | |
6993 | end record; | |
6994 | -- One entry in a Rlist value, a single REnt (range entry) value denotes | |
6995 | -- one range from Lo to Hi. To represent a single value range Lo = Hi = | |
6996 | -- value. | |
9ea61fdd | 6997 | |
eb66e842 | 6998 | type RList is array (Nat range <>) of REnt; |
6999 | -- A list of ranges. The ranges are sorted in increasing order, and are | |
7000 | -- disjoint (there is a gap of at least one value between each range in | |
7001 | -- the table). A value is in the set of ranges in Rlist if it lies | |
7002 | -- within one of these ranges. | |
9ea61fdd | 7003 | |
eb66e842 | 7004 | False_Range : constant RList := |
7005 | RList'(1 .. 0 => REnt'(No_Uint, No_Uint)); | |
7006 | -- An empty set of ranges represents a range list that can never be | |
7007 | -- satisfied, since there are no ranges in which the value could lie, | |
7008 | -- so it does not lie in any of them. False_Range is a canonical value | |
7009 | -- for this empty set, but general processing should test for an Rlist | |
7010 | -- with length zero (see Is_False predicate), since other null ranges | |
7011 | -- may appear which must be treated as False. | |
5b5df4a9 | 7012 | |
eb66e842 | 7013 | True_Range : constant RList := RList'(1 => REnt'(BLo, BHi)); |
7014 | -- Range representing True, value must be in the base range | |
5b5df4a9 | 7015 | |
eb66e842 | 7016 | function "and" (Left : RList; Right : RList) return RList; |
7017 | -- And's together two range lists, returning a range list. This is a set | |
7018 | -- intersection operation. | |
5b5df4a9 | 7019 | |
eb66e842 | 7020 | function "or" (Left : RList; Right : RList) return RList; |
7021 | -- Or's together two range lists, returning a range list. This is a set | |
7022 | -- union operation. | |
87f3d5d3 | 7023 | |
eb66e842 | 7024 | function "not" (Right : RList) return RList; |
7025 | -- Returns complement of a given range list, i.e. a range list | |
7026 | -- representing all the values in TLo .. THi that are not in the input | |
7027 | -- operand Right. | |
ed4adc99 | 7028 | |
eb66e842 | 7029 | function Build_Val (V : Uint) return Node_Id; |
7030 | -- Return an analyzed N_Identifier node referencing this value, suitable | |
5c6a5792 | 7031 | -- for use as an entry in the Static_Discrte_Predicate list. This node |
7032 | -- is typed with the base type. | |
5b5df4a9 | 7033 | |
eb66e842 | 7034 | function Build_Range (Lo : Uint; Hi : Uint) return Node_Id; |
7035 | -- Return an analyzed N_Range node referencing this range, suitable for | |
5c6a5792 | 7036 | -- use as an entry in the Static_Discrete_Predicate list. This node is |
7037 | -- typed with the base type. | |
5b5df4a9 | 7038 | |
eb66e842 | 7039 | function Get_RList (Exp : Node_Id) return RList; |
7040 | -- This is a recursive routine that converts the given expression into a | |
7041 | -- list of ranges, suitable for use in building the static predicate. | |
5b5df4a9 | 7042 | |
eb66e842 | 7043 | function Is_False (R : RList) return Boolean; |
7044 | pragma Inline (Is_False); | |
7045 | -- Returns True if the given range list is empty, and thus represents a | |
7046 | -- False list of ranges that can never be satisfied. | |
87f3d5d3 | 7047 | |
eb66e842 | 7048 | function Is_True (R : RList) return Boolean; |
7049 | -- Returns True if R trivially represents the True predicate by having a | |
7050 | -- single range from BLo to BHi. | |
5b5df4a9 | 7051 | |
eb66e842 | 7052 | function Is_Type_Ref (N : Node_Id) return Boolean; |
7053 | pragma Inline (Is_Type_Ref); | |
7054 | -- Returns if True if N is a reference to the type for the predicate in | |
7055 | -- the expression (i.e. if it is an identifier whose Chars field matches | |
7de4cba3 | 7056 | -- the Nam given in the call). N must not be parenthesized, if the type |
7057 | -- name appears in parens, this routine will return False. | |
5b5df4a9 | 7058 | |
eb66e842 | 7059 | function Lo_Val (N : Node_Id) return Uint; |
5c6a5792 | 7060 | -- Given an entry from a Static_Discrete_Predicate list that is either |
7061 | -- a static expression or static range, gets either the expression value | |
7062 | -- or the low bound of the range. | |
5b5df4a9 | 7063 | |
eb66e842 | 7064 | function Hi_Val (N : Node_Id) return Uint; |
5c6a5792 | 7065 | -- Given an entry from a Static_Discrete_Predicate list that is either |
7066 | -- a static expression or static range, gets either the expression value | |
7067 | -- or the high bound of the range. | |
5b5df4a9 | 7068 | |
eb66e842 | 7069 | function Membership_Entry (N : Node_Id) return RList; |
7070 | -- Given a single membership entry (range, value, or subtype), returns | |
7071 | -- the corresponding range list. Raises Static_Error if not static. | |
5b5df4a9 | 7072 | |
eb66e842 | 7073 | function Membership_Entries (N : Node_Id) return RList; |
7074 | -- Given an element on an alternatives list of a membership operation, | |
7075 | -- returns the range list corresponding to this entry and all following | |
7076 | -- entries (i.e. returns the "or" of this list of values). | |
b9e61b2a | 7077 | |
eb66e842 | 7078 | function Stat_Pred (Typ : Entity_Id) return RList; |
7079 | -- Given a type, if it has a static predicate, then return the predicate | |
7080 | -- as a range list, otherwise raise Non_Static. | |
c4968aa2 | 7081 | |
eb66e842 | 7082 | ----------- |
7083 | -- "and" -- | |
7084 | ----------- | |
c4968aa2 | 7085 | |
eb66e842 | 7086 | function "and" (Left : RList; Right : RList) return RList is |
7087 | FEnt : REnt; | |
7088 | -- First range of result | |
c4968aa2 | 7089 | |
eb66e842 | 7090 | SLeft : Nat := Left'First; |
7091 | -- Start of rest of left entries | |
c4968aa2 | 7092 | |
eb66e842 | 7093 | SRight : Nat := Right'First; |
7094 | -- Start of rest of right entries | |
2072eaa9 | 7095 | |
eb66e842 | 7096 | begin |
7097 | -- If either range is True, return the other | |
5b5df4a9 | 7098 | |
eb66e842 | 7099 | if Is_True (Left) then |
7100 | return Right; | |
7101 | elsif Is_True (Right) then | |
7102 | return Left; | |
7103 | end if; | |
87f3d5d3 | 7104 | |
eb66e842 | 7105 | -- If either range is False, return False |
5b5df4a9 | 7106 | |
eb66e842 | 7107 | if Is_False (Left) or else Is_False (Right) then |
7108 | return False_Range; | |
7109 | end if; | |
4c1fd062 | 7110 | |
eb66e842 | 7111 | -- Loop to remove entries at start that are disjoint, and thus just |
7112 | -- get discarded from the result entirely. | |
5b5df4a9 | 7113 | |
eb66e842 | 7114 | loop |
7115 | -- If no operands left in either operand, result is false | |
5b5df4a9 | 7116 | |
eb66e842 | 7117 | if SLeft > Left'Last or else SRight > Right'Last then |
7118 | return False_Range; | |
5b5df4a9 | 7119 | |
eb66e842 | 7120 | -- Discard first left operand entry if disjoint with right |
5b5df4a9 | 7121 | |
eb66e842 | 7122 | elsif Left (SLeft).Hi < Right (SRight).Lo then |
7123 | SLeft := SLeft + 1; | |
5b5df4a9 | 7124 | |
eb66e842 | 7125 | -- Discard first right operand entry if disjoint with left |
5b5df4a9 | 7126 | |
eb66e842 | 7127 | elsif Right (SRight).Hi < Left (SLeft).Lo then |
7128 | SRight := SRight + 1; | |
5b5df4a9 | 7129 | |
eb66e842 | 7130 | -- Otherwise we have an overlapping entry |
5b5df4a9 | 7131 | |
eb66e842 | 7132 | else |
7133 | exit; | |
7134 | end if; | |
7135 | end loop; | |
5b5df4a9 | 7136 | |
eb66e842 | 7137 | -- Now we have two non-null operands, and first entries overlap. The |
7138 | -- first entry in the result will be the overlapping part of these | |
7139 | -- two entries. | |
47a46747 | 7140 | |
eb66e842 | 7141 | FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo), |
7142 | Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi)); | |
47a46747 | 7143 | |
eb66e842 | 7144 | -- Now we can remove the entry that ended at a lower value, since its |
7145 | -- contribution is entirely contained in Fent. | |
5b5df4a9 | 7146 | |
eb66e842 | 7147 | if Left (SLeft).Hi <= Right (SRight).Hi then |
7148 | SLeft := SLeft + 1; | |
7149 | else | |
7150 | SRight := SRight + 1; | |
7151 | end if; | |
5b5df4a9 | 7152 | |
eb66e842 | 7153 | -- Compute result by concatenating this first entry with the "and" of |
7154 | -- the remaining parts of the left and right operands. Note that if | |
7155 | -- either of these is empty, "and" will yield empty, so that we will | |
7156 | -- end up with just Fent, which is what we want in that case. | |
5b5df4a9 | 7157 | |
eb66e842 | 7158 | return |
7159 | FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last)); | |
7160 | end "and"; | |
fb7f2fc4 | 7161 | |
eb66e842 | 7162 | ----------- |
7163 | -- "not" -- | |
7164 | ----------- | |
fb7f2fc4 | 7165 | |
eb66e842 | 7166 | function "not" (Right : RList) return RList is |
7167 | begin | |
7168 | -- Return True if False range | |
fb7f2fc4 | 7169 | |
eb66e842 | 7170 | if Is_False (Right) then |
7171 | return True_Range; | |
7172 | end if; | |
ed4adc99 | 7173 | |
eb66e842 | 7174 | -- Return False if True range |
fb7f2fc4 | 7175 | |
eb66e842 | 7176 | if Is_True (Right) then |
7177 | return False_Range; | |
7178 | end if; | |
fb7f2fc4 | 7179 | |
eb66e842 | 7180 | -- Here if not trivial case |
87f3d5d3 | 7181 | |
eb66e842 | 7182 | declare |
7183 | Result : RList (1 .. Right'Length + 1); | |
7184 | -- May need one more entry for gap at beginning and end | |
87f3d5d3 | 7185 | |
eb66e842 | 7186 | Count : Nat := 0; |
7187 | -- Number of entries stored in Result | |
4098232e | 7188 | |
eb66e842 | 7189 | begin |
7190 | -- Gap at start | |
4098232e | 7191 | |
eb66e842 | 7192 | if Right (Right'First).Lo > TLo then |
7193 | Count := Count + 1; | |
7194 | Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1); | |
7195 | end if; | |
ed4adc99 | 7196 | |
eb66e842 | 7197 | -- Gaps between ranges |
ed4adc99 | 7198 | |
eb66e842 | 7199 | for J in Right'First .. Right'Last - 1 loop |
7200 | Count := Count + 1; | |
7201 | Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1); | |
7202 | end loop; | |
5b5df4a9 | 7203 | |
eb66e842 | 7204 | -- Gap at end |
5b5df4a9 | 7205 | |
eb66e842 | 7206 | if Right (Right'Last).Hi < THi then |
7207 | Count := Count + 1; | |
7208 | Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi); | |
7209 | end if; | |
5b5df4a9 | 7210 | |
eb66e842 | 7211 | return Result (1 .. Count); |
7212 | end; | |
7213 | end "not"; | |
5b5df4a9 | 7214 | |
eb66e842 | 7215 | ---------- |
7216 | -- "or" -- | |
7217 | ---------- | |
5b5df4a9 | 7218 | |
eb66e842 | 7219 | function "or" (Left : RList; Right : RList) return RList is |
7220 | FEnt : REnt; | |
7221 | -- First range of result | |
5b5df4a9 | 7222 | |
eb66e842 | 7223 | SLeft : Nat := Left'First; |
7224 | -- Start of rest of left entries | |
5b5df4a9 | 7225 | |
eb66e842 | 7226 | SRight : Nat := Right'First; |
7227 | -- Start of rest of right entries | |
5b5df4a9 | 7228 | |
eb66e842 | 7229 | begin |
7230 | -- If either range is True, return True | |
5b5df4a9 | 7231 | |
eb66e842 | 7232 | if Is_True (Left) or else Is_True (Right) then |
7233 | return True_Range; | |
7234 | end if; | |
5b5df4a9 | 7235 | |
eb66e842 | 7236 | -- If either range is False (empty), return the other |
5b5df4a9 | 7237 | |
eb66e842 | 7238 | if Is_False (Left) then |
7239 | return Right; | |
7240 | elsif Is_False (Right) then | |
7241 | return Left; | |
7242 | end if; | |
5b5df4a9 | 7243 | |
eb66e842 | 7244 | -- Initialize result first entry from left or right operand depending |
7245 | -- on which starts with the lower range. | |
5b5df4a9 | 7246 | |
eb66e842 | 7247 | if Left (SLeft).Lo < Right (SRight).Lo then |
7248 | FEnt := Left (SLeft); | |
7249 | SLeft := SLeft + 1; | |
7250 | else | |
7251 | FEnt := Right (SRight); | |
7252 | SRight := SRight + 1; | |
7253 | end if; | |
5b5df4a9 | 7254 | |
eb66e842 | 7255 | -- This loop eats ranges from left and right operands that are |
7256 | -- contiguous with the first range we are gathering. | |
9ea61fdd | 7257 | |
eb66e842 | 7258 | loop |
7259 | -- Eat first entry in left operand if contiguous or overlapped by | |
7260 | -- gathered first operand of result. | |
9ea61fdd | 7261 | |
eb66e842 | 7262 | if SLeft <= Left'Last |
7263 | and then Left (SLeft).Lo <= FEnt.Hi + 1 | |
7264 | then | |
7265 | FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi); | |
7266 | SLeft := SLeft + 1; | |
9ea61fdd | 7267 | |
eb66e842 | 7268 | -- Eat first entry in right operand if contiguous or overlapped by |
7269 | -- gathered right operand of result. | |
9ea61fdd | 7270 | |
eb66e842 | 7271 | elsif SRight <= Right'Last |
7272 | and then Right (SRight).Lo <= FEnt.Hi + 1 | |
7273 | then | |
7274 | FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi); | |
7275 | SRight := SRight + 1; | |
9ea61fdd | 7276 | |
eb66e842 | 7277 | -- All done if no more entries to eat |
5b5df4a9 | 7278 | |
eb66e842 | 7279 | else |
7280 | exit; | |
7281 | end if; | |
7282 | end loop; | |
5b5df4a9 | 7283 | |
eb66e842 | 7284 | -- Obtain result as the first entry we just computed, concatenated |
7285 | -- to the "or" of the remaining results (if one operand is empty, | |
7286 | -- this will just concatenate with the other | |
5b5df4a9 | 7287 | |
eb66e842 | 7288 | return |
7289 | FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last)); | |
7290 | end "or"; | |
5b5df4a9 | 7291 | |
eb66e842 | 7292 | ----------------- |
7293 | -- Build_Range -- | |
7294 | ----------------- | |
5b5df4a9 | 7295 | |
eb66e842 | 7296 | function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is |
7297 | Result : Node_Id; | |
5b5df4a9 | 7298 | begin |
eb66e842 | 7299 | Result := |
7300 | Make_Range (Loc, | |
7301 | Low_Bound => Build_Val (Lo), | |
7302 | High_Bound => Build_Val (Hi)); | |
7303 | Set_Etype (Result, Btyp); | |
7304 | Set_Analyzed (Result); | |
7305 | return Result; | |
7306 | end Build_Range; | |
5b5df4a9 | 7307 | |
eb66e842 | 7308 | --------------- |
7309 | -- Build_Val -- | |
7310 | --------------- | |
5b5df4a9 | 7311 | |
eb66e842 | 7312 | function Build_Val (V : Uint) return Node_Id is |
7313 | Result : Node_Id; | |
5b5df4a9 | 7314 | |
eb66e842 | 7315 | begin |
7316 | if Is_Enumeration_Type (Typ) then | |
7317 | Result := Get_Enum_Lit_From_Pos (Typ, V, Loc); | |
7318 | else | |
7319 | Result := Make_Integer_Literal (Loc, V); | |
7320 | end if; | |
5b5df4a9 | 7321 | |
eb66e842 | 7322 | Set_Etype (Result, Btyp); |
7323 | Set_Is_Static_Expression (Result); | |
7324 | Set_Analyzed (Result); | |
7325 | return Result; | |
7326 | end Build_Val; | |
87f3d5d3 | 7327 | |
eb66e842 | 7328 | --------------- |
7329 | -- Get_RList -- | |
7330 | --------------- | |
87f3d5d3 | 7331 | |
eb66e842 | 7332 | function Get_RList (Exp : Node_Id) return RList is |
7333 | Op : Node_Kind; | |
7334 | Val : Uint; | |
87f3d5d3 | 7335 | |
eb66e842 | 7336 | begin |
7337 | -- Static expression can only be true or false | |
87f3d5d3 | 7338 | |
eb66e842 | 7339 | if Is_OK_Static_Expression (Exp) then |
7340 | if Expr_Value (Exp) = 0 then | |
7341 | return False_Range; | |
7342 | else | |
7343 | return True_Range; | |
9ea61fdd | 7344 | end if; |
eb66e842 | 7345 | end if; |
87f3d5d3 | 7346 | |
eb66e842 | 7347 | -- Otherwise test node type |
192b8dab | 7348 | |
eb66e842 | 7349 | Op := Nkind (Exp); |
192b8dab | 7350 | |
eb66e842 | 7351 | case Op is |
5d3fb947 | 7352 | |
eb66e842 | 7353 | -- And |
5d3fb947 | 7354 | |
eb66e842 | 7355 | when N_Op_And | N_And_Then => |
7356 | return Get_RList (Left_Opnd (Exp)) | |
7357 | and | |
7358 | Get_RList (Right_Opnd (Exp)); | |
5b5df4a9 | 7359 | |
eb66e842 | 7360 | -- Or |
9dc88aea | 7361 | |
eb66e842 | 7362 | when N_Op_Or | N_Or_Else => |
7363 | return Get_RList (Left_Opnd (Exp)) | |
7364 | or | |
7365 | Get_RList (Right_Opnd (Exp)); | |
7c443ae8 | 7366 | |
eb66e842 | 7367 | -- Not |
9dc88aea | 7368 | |
eb66e842 | 7369 | when N_Op_Not => |
7370 | return not Get_RList (Right_Opnd (Exp)); | |
9dc88aea | 7371 | |
eb66e842 | 7372 | -- Comparisons of type with static value |
84c8f0b8 | 7373 | |
eb66e842 | 7374 | when N_Op_Compare => |
490beba6 | 7375 | |
eb66e842 | 7376 | -- Type is left operand |
9dc88aea | 7377 | |
eb66e842 | 7378 | if Is_Type_Ref (Left_Opnd (Exp)) |
7379 | and then Is_OK_Static_Expression (Right_Opnd (Exp)) | |
7380 | then | |
7381 | Val := Expr_Value (Right_Opnd (Exp)); | |
84c8f0b8 | 7382 | |
eb66e842 | 7383 | -- Typ is right operand |
84c8f0b8 | 7384 | |
eb66e842 | 7385 | elsif Is_Type_Ref (Right_Opnd (Exp)) |
7386 | and then Is_OK_Static_Expression (Left_Opnd (Exp)) | |
7387 | then | |
7388 | Val := Expr_Value (Left_Opnd (Exp)); | |
84c8f0b8 | 7389 | |
eb66e842 | 7390 | -- Invert sense of comparison |
84c8f0b8 | 7391 | |
eb66e842 | 7392 | case Op is |
7393 | when N_Op_Gt => Op := N_Op_Lt; | |
7394 | when N_Op_Lt => Op := N_Op_Gt; | |
7395 | when N_Op_Ge => Op := N_Op_Le; | |
7396 | when N_Op_Le => Op := N_Op_Ge; | |
7397 | when others => null; | |
7398 | end case; | |
84c8f0b8 | 7399 | |
eb66e842 | 7400 | -- Other cases are non-static |
34d045d3 | 7401 | |
eb66e842 | 7402 | else |
7403 | raise Non_Static; | |
7404 | end if; | |
9dc88aea | 7405 | |
eb66e842 | 7406 | -- Construct range according to comparison operation |
9dc88aea | 7407 | |
eb66e842 | 7408 | case Op is |
7409 | when N_Op_Eq => | |
7410 | return RList'(1 => REnt'(Val, Val)); | |
9dc88aea | 7411 | |
eb66e842 | 7412 | when N_Op_Ge => |
7413 | return RList'(1 => REnt'(Val, BHi)); | |
84c8f0b8 | 7414 | |
eb66e842 | 7415 | when N_Op_Gt => |
7416 | return RList'(1 => REnt'(Val + 1, BHi)); | |
84c8f0b8 | 7417 | |
eb66e842 | 7418 | when N_Op_Le => |
7419 | return RList'(1 => REnt'(BLo, Val)); | |
fb7f2fc4 | 7420 | |
eb66e842 | 7421 | when N_Op_Lt => |
7422 | return RList'(1 => REnt'(BLo, Val - 1)); | |
9dc88aea | 7423 | |
eb66e842 | 7424 | when N_Op_Ne => |
7425 | return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi)); | |
9dc88aea | 7426 | |
eb66e842 | 7427 | when others => |
7428 | raise Program_Error; | |
7429 | end case; | |
9dc88aea | 7430 | |
eb66e842 | 7431 | -- Membership (IN) |
9dc88aea | 7432 | |
eb66e842 | 7433 | when N_In => |
7434 | if not Is_Type_Ref (Left_Opnd (Exp)) then | |
7435 | raise Non_Static; | |
7436 | end if; | |
9dc88aea | 7437 | |
eb66e842 | 7438 | if Present (Right_Opnd (Exp)) then |
7439 | return Membership_Entry (Right_Opnd (Exp)); | |
7440 | else | |
7441 | return Membership_Entries (First (Alternatives (Exp))); | |
7442 | end if; | |
9dc88aea | 7443 | |
eb66e842 | 7444 | -- Negative membership (NOT IN) |
9dc88aea | 7445 | |
eb66e842 | 7446 | when N_Not_In => |
7447 | if not Is_Type_Ref (Left_Opnd (Exp)) then | |
7448 | raise Non_Static; | |
7449 | end if; | |
9dc88aea | 7450 | |
eb66e842 | 7451 | if Present (Right_Opnd (Exp)) then |
7452 | return not Membership_Entry (Right_Opnd (Exp)); | |
7453 | else | |
7454 | return not Membership_Entries (First (Alternatives (Exp))); | |
7455 | end if; | |
9dc88aea | 7456 | |
eb66e842 | 7457 | -- Function call, may be call to static predicate |
9dc88aea | 7458 | |
eb66e842 | 7459 | when N_Function_Call => |
7460 | if Is_Entity_Name (Name (Exp)) then | |
7461 | declare | |
7462 | Ent : constant Entity_Id := Entity (Name (Exp)); | |
7463 | begin | |
7464 | if Is_Predicate_Function (Ent) | |
7465 | or else | |
7466 | Is_Predicate_Function_M (Ent) | |
7467 | then | |
7468 | return Stat_Pred (Etype (First_Formal (Ent))); | |
7469 | end if; | |
7470 | end; | |
7471 | end if; | |
9dc88aea | 7472 | |
eb66e842 | 7473 | -- Other function call cases are non-static |
9dc88aea | 7474 | |
eb66e842 | 7475 | raise Non_Static; |
490beba6 | 7476 | |
eb66e842 | 7477 | -- Qualified expression, dig out the expression |
c92e878b | 7478 | |
eb66e842 | 7479 | when N_Qualified_Expression => |
7480 | return Get_RList (Expression (Exp)); | |
4c1fd062 | 7481 | |
eb66e842 | 7482 | when N_Case_Expression => |
7483 | declare | |
7484 | Alt : Node_Id; | |
7485 | Choices : List_Id; | |
7486 | Dep : Node_Id; | |
4c1fd062 | 7487 | |
eb66e842 | 7488 | begin |
7489 | if not Is_Entity_Name (Expression (Expr)) | |
7490 | or else Etype (Expression (Expr)) /= Typ | |
7491 | then | |
7492 | Error_Msg_N | |
7493 | ("expression must denaote subtype", Expression (Expr)); | |
7494 | return False_Range; | |
7495 | end if; | |
9dc88aea | 7496 | |
eb66e842 | 7497 | -- Collect discrete choices in all True alternatives |
9dc88aea | 7498 | |
eb66e842 | 7499 | Choices := New_List; |
7500 | Alt := First (Alternatives (Exp)); | |
7501 | while Present (Alt) loop | |
7502 | Dep := Expression (Alt); | |
34d045d3 | 7503 | |
cda40848 | 7504 | if not Is_OK_Static_Expression (Dep) then |
eb66e842 | 7505 | raise Non_Static; |
ebbab42d | 7506 | |
eb66e842 | 7507 | elsif Is_True (Expr_Value (Dep)) then |
7508 | Append_List_To (Choices, | |
7509 | New_Copy_List (Discrete_Choices (Alt))); | |
7510 | end if; | |
fb7f2fc4 | 7511 | |
eb66e842 | 7512 | Next (Alt); |
7513 | end loop; | |
9dc88aea | 7514 | |
eb66e842 | 7515 | return Membership_Entries (First (Choices)); |
7516 | end; | |
9dc88aea | 7517 | |
eb66e842 | 7518 | -- Expression with actions: if no actions, dig out expression |
9dc88aea | 7519 | |
eb66e842 | 7520 | when N_Expression_With_Actions => |
7521 | if Is_Empty_List (Actions (Exp)) then | |
7522 | return Get_RList (Expression (Exp)); | |
7523 | else | |
7524 | raise Non_Static; | |
7525 | end if; | |
9dc88aea | 7526 | |
eb66e842 | 7527 | -- Xor operator |
490beba6 | 7528 | |
eb66e842 | 7529 | when N_Op_Xor => |
7530 | return (Get_RList (Left_Opnd (Exp)) | |
7531 | and not Get_RList (Right_Opnd (Exp))) | |
7532 | or (Get_RList (Right_Opnd (Exp)) | |
7533 | and not Get_RList (Left_Opnd (Exp))); | |
9dc88aea | 7534 | |
eb66e842 | 7535 | -- Any other node type is non-static |
fb7f2fc4 | 7536 | |
eb66e842 | 7537 | when others => |
7538 | raise Non_Static; | |
7539 | end case; | |
7540 | end Get_RList; | |
fb7f2fc4 | 7541 | |
eb66e842 | 7542 | ------------ |
7543 | -- Hi_Val -- | |
7544 | ------------ | |
fb7f2fc4 | 7545 | |
eb66e842 | 7546 | function Hi_Val (N : Node_Id) return Uint is |
7547 | begin | |
cda40848 | 7548 | if Is_OK_Static_Expression (N) then |
eb66e842 | 7549 | return Expr_Value (N); |
7550 | else | |
7551 | pragma Assert (Nkind (N) = N_Range); | |
7552 | return Expr_Value (High_Bound (N)); | |
7553 | end if; | |
7554 | end Hi_Val; | |
fb7f2fc4 | 7555 | |
eb66e842 | 7556 | -------------- |
7557 | -- Is_False -- | |
7558 | -------------- | |
fb7f2fc4 | 7559 | |
eb66e842 | 7560 | function Is_False (R : RList) return Boolean is |
7561 | begin | |
7562 | return R'Length = 0; | |
7563 | end Is_False; | |
9dc88aea | 7564 | |
eb66e842 | 7565 | ------------- |
7566 | -- Is_True -- | |
7567 | ------------- | |
9dc88aea | 7568 | |
eb66e842 | 7569 | function Is_True (R : RList) return Boolean is |
7570 | begin | |
7571 | return R'Length = 1 | |
7572 | and then R (R'First).Lo = BLo | |
7573 | and then R (R'First).Hi = BHi; | |
7574 | end Is_True; | |
9dc88aea | 7575 | |
eb66e842 | 7576 | ----------------- |
7577 | -- Is_Type_Ref -- | |
7578 | ----------------- | |
9dc88aea | 7579 | |
eb66e842 | 7580 | function Is_Type_Ref (N : Node_Id) return Boolean is |
7581 | begin | |
7de4cba3 | 7582 | return Nkind (N) = N_Identifier |
7583 | and then Chars (N) = Nam | |
7584 | and then Paren_Count (N) = 0; | |
eb66e842 | 7585 | end Is_Type_Ref; |
9dc88aea | 7586 | |
eb66e842 | 7587 | ------------ |
7588 | -- Lo_Val -- | |
7589 | ------------ | |
9dc88aea | 7590 | |
eb66e842 | 7591 | function Lo_Val (N : Node_Id) return Uint is |
84c8f0b8 | 7592 | begin |
cda40848 | 7593 | if Is_OK_Static_Expression (N) then |
eb66e842 | 7594 | return Expr_Value (N); |
84c8f0b8 | 7595 | else |
eb66e842 | 7596 | pragma Assert (Nkind (N) = N_Range); |
7597 | return Expr_Value (Low_Bound (N)); | |
84c8f0b8 | 7598 | end if; |
eb66e842 | 7599 | end Lo_Val; |
d97beb2f | 7600 | |
eb66e842 | 7601 | ------------------------ |
7602 | -- Membership_Entries -- | |
7603 | ------------------------ | |
d97beb2f | 7604 | |
eb66e842 | 7605 | function Membership_Entries (N : Node_Id) return RList is |
84c8f0b8 | 7606 | begin |
eb66e842 | 7607 | if No (Next (N)) then |
7608 | return Membership_Entry (N); | |
84c8f0b8 | 7609 | else |
eb66e842 | 7610 | return Membership_Entry (N) or Membership_Entries (Next (N)); |
84c8f0b8 | 7611 | end if; |
eb66e842 | 7612 | end Membership_Entries; |
84c8f0b8 | 7613 | |
eb66e842 | 7614 | ---------------------- |
7615 | -- Membership_Entry -- | |
7616 | ---------------------- | |
84c8f0b8 | 7617 | |
eb66e842 | 7618 | function Membership_Entry (N : Node_Id) return RList is |
7619 | Val : Uint; | |
7620 | SLo : Uint; | |
7621 | SHi : Uint; | |
d97beb2f | 7622 | |
eb66e842 | 7623 | begin |
7624 | -- Range case | |
d97beb2f | 7625 | |
eb66e842 | 7626 | if Nkind (N) = N_Range then |
cda40848 | 7627 | if not Is_OK_Static_Expression (Low_Bound (N)) |
eb66e842 | 7628 | or else |
cda40848 | 7629 | not Is_OK_Static_Expression (High_Bound (N)) |
eb66e842 | 7630 | then |
7631 | raise Non_Static; | |
7632 | else | |
7633 | SLo := Expr_Value (Low_Bound (N)); | |
7634 | SHi := Expr_Value (High_Bound (N)); | |
7635 | return RList'(1 => REnt'(SLo, SHi)); | |
7636 | end if; | |
84c8f0b8 | 7637 | |
eb66e842 | 7638 | -- Static expression case |
84c8f0b8 | 7639 | |
cda40848 | 7640 | elsif Is_OK_Static_Expression (N) then |
eb66e842 | 7641 | Val := Expr_Value (N); |
7642 | return RList'(1 => REnt'(Val, Val)); | |
d97beb2f | 7643 | |
eb66e842 | 7644 | -- Identifier (other than static expression) case |
d97beb2f | 7645 | |
eb66e842 | 7646 | else pragma Assert (Nkind (N) = N_Identifier); |
d97beb2f | 7647 | |
eb66e842 | 7648 | -- Type case |
d97beb2f | 7649 | |
eb66e842 | 7650 | if Is_Type (Entity (N)) then |
d97beb2f | 7651 | |
eb66e842 | 7652 | -- If type has predicates, process them |
d97beb2f | 7653 | |
eb66e842 | 7654 | if Has_Predicates (Entity (N)) then |
7655 | return Stat_Pred (Entity (N)); | |
d97beb2f | 7656 | |
eb66e842 | 7657 | -- For static subtype without predicates, get range |
9dc88aea | 7658 | |
cda40848 | 7659 | elsif Is_OK_Static_Subtype (Entity (N)) then |
eb66e842 | 7660 | SLo := Expr_Value (Type_Low_Bound (Entity (N))); |
7661 | SHi := Expr_Value (Type_High_Bound (Entity (N))); | |
7662 | return RList'(1 => REnt'(SLo, SHi)); | |
9f269bd8 | 7663 | |
eb66e842 | 7664 | -- Any other type makes us non-static |
9f269bd8 | 7665 | |
eb66e842 | 7666 | else |
7667 | raise Non_Static; | |
7668 | end if; | |
84c8f0b8 | 7669 | |
eb66e842 | 7670 | -- Any other kind of identifier in predicate (e.g. a non-static |
7671 | -- expression value) means this is not a static predicate. | |
84c8f0b8 | 7672 | |
eb66e842 | 7673 | else |
7674 | raise Non_Static; | |
7675 | end if; | |
7676 | end if; | |
7677 | end Membership_Entry; | |
84c8f0b8 | 7678 | |
eb66e842 | 7679 | --------------- |
7680 | -- Stat_Pred -- | |
7681 | --------------- | |
84c8f0b8 | 7682 | |
eb66e842 | 7683 | function Stat_Pred (Typ : Entity_Id) return RList is |
7684 | begin | |
7685 | -- Not static if type does not have static predicates | |
84c8f0b8 | 7686 | |
5c6a5792 | 7687 | if not Has_Static_Predicate (Typ) then |
eb66e842 | 7688 | raise Non_Static; |
7689 | end if; | |
84c8f0b8 | 7690 | |
eb66e842 | 7691 | -- Otherwise we convert the predicate list to a range list |
84c8f0b8 | 7692 | |
eb66e842 | 7693 | declare |
5c6a5792 | 7694 | Spred : constant List_Id := Static_Discrete_Predicate (Typ); |
7695 | Result : RList (1 .. List_Length (Spred)); | |
eb66e842 | 7696 | P : Node_Id; |
84c8f0b8 | 7697 | |
eb66e842 | 7698 | begin |
5c6a5792 | 7699 | P := First (Static_Discrete_Predicate (Typ)); |
eb66e842 | 7700 | for J in Result'Range loop |
7701 | Result (J) := REnt'(Lo_Val (P), Hi_Val (P)); | |
7702 | Next (P); | |
7703 | end loop; | |
84c8f0b8 | 7704 | |
eb66e842 | 7705 | return Result; |
7706 | end; | |
7707 | end Stat_Pred; | |
84c8f0b8 | 7708 | |
eb66e842 | 7709 | -- Start of processing for Build_Discrete_Static_Predicate |
84c8f0b8 | 7710 | |
eb66e842 | 7711 | begin |
afc229da | 7712 | -- Establish bounds for the predicate |
7713 | ||
7714 | if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then | |
7715 | TLo := Expr_Value (Type_Low_Bound (Typ)); | |
7716 | else | |
7717 | TLo := BLo; | |
7718 | end if; | |
7719 | ||
7720 | if Compile_Time_Known_Value (Type_High_Bound (Typ)) then | |
7721 | THi := Expr_Value (Type_High_Bound (Typ)); | |
7722 | else | |
7723 | THi := BHi; | |
7724 | end if; | |
7725 | ||
eb66e842 | 7726 | -- Analyze the expression to see if it is a static predicate |
84c8f0b8 | 7727 | |
eb66e842 | 7728 | declare |
7729 | Ranges : constant RList := Get_RList (Expr); | |
7730 | -- Range list from expression if it is static | |
84c8f0b8 | 7731 | |
eb66e842 | 7732 | Plist : List_Id; |
84c8f0b8 | 7733 | |
eb66e842 | 7734 | begin |
7735 | -- Convert range list into a form for the static predicate. In the | |
7736 | -- Ranges array, we just have raw ranges, these must be converted | |
7737 | -- to properly typed and analyzed static expressions or range nodes. | |
84c8f0b8 | 7738 | |
eb66e842 | 7739 | -- Note: here we limit ranges to the ranges of the subtype, so that |
7740 | -- a predicate is always false for values outside the subtype. That | |
7741 | -- seems fine, such values are invalid anyway, and considering them | |
7742 | -- to fail the predicate seems allowed and friendly, and furthermore | |
7743 | -- simplifies processing for case statements and loops. | |
84c8f0b8 | 7744 | |
eb66e842 | 7745 | Plist := New_List; |
7746 | ||
7747 | for J in Ranges'Range loop | |
84c8f0b8 | 7748 | declare |
eb66e842 | 7749 | Lo : Uint := Ranges (J).Lo; |
7750 | Hi : Uint := Ranges (J).Hi; | |
84c8f0b8 | 7751 | |
eb66e842 | 7752 | begin |
7753 | -- Ignore completely out of range entry | |
84c8f0b8 | 7754 | |
eb66e842 | 7755 | if Hi < TLo or else Lo > THi then |
7756 | null; | |
84c8f0b8 | 7757 | |
eb66e842 | 7758 | -- Otherwise process entry |
84c8f0b8 | 7759 | |
eb66e842 | 7760 | else |
7761 | -- Adjust out of range value to subtype range | |
490beba6 | 7762 | |
eb66e842 | 7763 | if Lo < TLo then |
7764 | Lo := TLo; | |
7765 | end if; | |
490beba6 | 7766 | |
eb66e842 | 7767 | if Hi > THi then |
7768 | Hi := THi; | |
7769 | end if; | |
84c8f0b8 | 7770 | |
eb66e842 | 7771 | -- Convert range into required form |
84c8f0b8 | 7772 | |
eb66e842 | 7773 | Append_To (Plist, Build_Range (Lo, Hi)); |
84c8f0b8 | 7774 | end if; |
eb66e842 | 7775 | end; |
7776 | end loop; | |
84c8f0b8 | 7777 | |
eb66e842 | 7778 | -- Processing was successful and all entries were static, so now we |
7779 | -- can store the result as the predicate list. | |
84c8f0b8 | 7780 | |
5c6a5792 | 7781 | Set_Static_Discrete_Predicate (Typ, Plist); |
84c8f0b8 | 7782 | |
eb66e842 | 7783 | -- The processing for static predicates put the expression into |
7784 | -- canonical form as a series of ranges. It also eliminated | |
7785 | -- duplicates and collapsed and combined ranges. We might as well | |
7786 | -- replace the alternatives list of the right operand of the | |
7787 | -- membership test with the static predicate list, which will | |
7788 | -- usually be more efficient. | |
84c8f0b8 | 7789 | |
eb66e842 | 7790 | declare |
7791 | New_Alts : constant List_Id := New_List; | |
7792 | Old_Node : Node_Id; | |
7793 | New_Node : Node_Id; | |
84c8f0b8 | 7794 | |
eb66e842 | 7795 | begin |
7796 | Old_Node := First (Plist); | |
7797 | while Present (Old_Node) loop | |
7798 | New_Node := New_Copy (Old_Node); | |
84c8f0b8 | 7799 | |
eb66e842 | 7800 | if Nkind (New_Node) = N_Range then |
7801 | Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node))); | |
7802 | Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node))); | |
7803 | end if; | |
84c8f0b8 | 7804 | |
eb66e842 | 7805 | Append_To (New_Alts, New_Node); |
7806 | Next (Old_Node); | |
7807 | end loop; | |
84c8f0b8 | 7808 | |
eb66e842 | 7809 | -- If empty list, replace by False |
84c8f0b8 | 7810 | |
eb66e842 | 7811 | if Is_Empty_List (New_Alts) then |
7812 | Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc)); | |
84c8f0b8 | 7813 | |
eb66e842 | 7814 | -- Else replace by set membership test |
84c8f0b8 | 7815 | |
eb66e842 | 7816 | else |
7817 | Rewrite (Expr, | |
7818 | Make_In (Loc, | |
7819 | Left_Opnd => Make_Identifier (Loc, Nam), | |
7820 | Right_Opnd => Empty, | |
7821 | Alternatives => New_Alts)); | |
490beba6 | 7822 | |
eb66e842 | 7823 | -- Resolve new expression in function context |
490beba6 | 7824 | |
eb66e842 | 7825 | Install_Formals (Predicate_Function (Typ)); |
7826 | Push_Scope (Predicate_Function (Typ)); | |
7827 | Analyze_And_Resolve (Expr, Standard_Boolean); | |
7828 | Pop_Scope; | |
7829 | end if; | |
7830 | end; | |
7831 | end; | |
9ab32fe9 | 7832 | |
eb66e842 | 7833 | -- If non-static, return doing nothing |
9ab32fe9 | 7834 | |
eb66e842 | 7835 | exception |
7836 | when Non_Static => | |
7837 | return; | |
7838 | end Build_Discrete_Static_Predicate; | |
64cc9e5d | 7839 | |
eb66e842 | 7840 | ------------------------------------------- |
7841 | -- Build_Invariant_Procedure_Declaration -- | |
7842 | ------------------------------------------- | |
9ab32fe9 | 7843 | |
eb66e842 | 7844 | function Build_Invariant_Procedure_Declaration |
7845 | (Typ : Entity_Id) return Node_Id | |
7846 | is | |
30f8d103 | 7847 | Loc : constant Source_Ptr := Sloc (Typ); |
f9e26ff7 | 7848 | Decl : Node_Id; |
7849 | Obj_Id : Entity_Id; | |
7850 | SId : Entity_Id; | |
9ab32fe9 | 7851 | |
30f8d103 | 7852 | Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode; |
7853 | ||
eb66e842 | 7854 | begin |
8d8194a6 | 7855 | -- Check for duplicate definitions |
eb66e842 | 7856 | |
7857 | if Has_Invariants (Typ) and then Present (Invariant_Procedure (Typ)) then | |
7858 | return Empty; | |
d97beb2f | 7859 | end if; |
d97beb2f | 7860 | |
30f8d103 | 7861 | -- The related type may be subject to pragma Ghost. Set the mode now to |
39629e6a | 7862 | -- ensure that the invariant procedure is properly marked as Ghost. |
f9e26ff7 | 7863 | |
7864 | Set_Ghost_Mode_From_Entity (Typ); | |
7865 | ||
eb66e842 | 7866 | SId := |
7867 | Make_Defining_Identifier (Loc, | |
7868 | Chars => New_External_Name (Chars (Typ), "Invariant")); | |
7869 | Set_Has_Invariants (Typ); | |
7870 | Set_Ekind (SId, E_Procedure); | |
856a9917 | 7871 | Set_Etype (SId, Standard_Void_Type); |
eb66e842 | 7872 | Set_Is_Invariant_Procedure (SId); |
7873 | Set_Invariant_Procedure (Typ, SId); | |
d97beb2f | 7874 | |
f9e26ff7 | 7875 | -- Mark the invariant procedure explicitly as Ghost because it does not |
7876 | -- come from source. | |
7877 | ||
7878 | if Ghost_Mode > None then | |
7879 | Set_Is_Ghost_Entity (SId); | |
7880 | end if; | |
7881 | ||
7882 | Obj_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('I')); | |
7883 | Set_Etype (Obj_Id, Typ); | |
7884 | ||
7885 | Decl := | |
7886 | Make_Subprogram_Declaration (Loc, | |
7887 | Make_Procedure_Specification (Loc, | |
7888 | Defining_Unit_Name => SId, | |
7889 | Parameter_Specifications => New_List ( | |
7890 | Make_Parameter_Specification (Loc, | |
7891 | Defining_Identifier => Obj_Id, | |
7892 | Parameter_Type => New_Occurrence_Of (Typ, Loc))))); | |
7893 | ||
30f8d103 | 7894 | Ghost_Mode := Save_Ghost_Mode; |
f9e26ff7 | 7895 | |
7896 | return Decl; | |
eb66e842 | 7897 | end Build_Invariant_Procedure_Declaration; |
7898 | ||
7899 | ------------------------------- | |
7900 | -- Build_Invariant_Procedure -- | |
7901 | ------------------------------- | |
7902 | ||
7903 | -- The procedure that is constructed here has the form | |
7904 | ||
7905 | -- procedure typInvariant (Ixxx : typ) is | |
7906 | -- begin | |
7907 | -- pragma Check (Invariant, exp, "failed invariant from xxx"); | |
7908 | -- pragma Check (Invariant, exp, "failed invariant from xxx"); | |
7909 | -- ... | |
7910 | -- pragma Check (Invariant, exp, "failed inherited invariant from xxx"); | |
7911 | -- ... | |
7912 | -- end typInvariant; | |
7913 | ||
7914 | procedure Build_Invariant_Procedure (Typ : Entity_Id; N : Node_Id) is | |
39629e6a | 7915 | procedure Add_Invariants |
7916 | (T : Entity_Id; | |
7917 | Obj_Id : Entity_Id; | |
7918 | Stmts : in out List_Id; | |
7919 | Inherit : Boolean); | |
eb66e842 | 7920 | -- Appends statements to Stmts for any invariants in the rep item chain |
7921 | -- of the given type. If Inherit is False, then we only process entries | |
7922 | -- on the chain for the type Typ. If Inherit is True, then we ignore any | |
7923 | -- Invariant aspects, but we process all Invariant'Class aspects, adding | |
7924 | -- "inherited" to the exception message and generating an informational | |
7925 | -- message about the inheritance of an invariant. | |
d97beb2f | 7926 | |
eb66e842 | 7927 | -------------------- |
7928 | -- Add_Invariants -- | |
7929 | -------------------- | |
d97beb2f | 7930 | |
39629e6a | 7931 | procedure Add_Invariants |
7932 | (T : Entity_Id; | |
7933 | Obj_Id : Entity_Id; | |
7934 | Stmts : in out List_Id; | |
7935 | Inherit : Boolean) | |
7936 | is | |
f9e26ff7 | 7937 | procedure Add_Invariant (Prag : Node_Id); |
7938 | -- Create a runtime check to verify the exression of invariant pragma | |
7939 | -- Prag. All generated code is added to list Stmts. | |
d97beb2f | 7940 | |
f9e26ff7 | 7941 | ------------------- |
7942 | -- Add_Invariant -- | |
7943 | ------------------- | |
d97beb2f | 7944 | |
f9e26ff7 | 7945 | procedure Add_Invariant (Prag : Node_Id) is |
7946 | procedure Replace_Type_Reference (N : Node_Id); | |
7947 | -- Replace a single occurrence N of the subtype name with a | |
7948 | -- reference to the formal of the predicate function. N can be an | |
7949 | -- identifier referencing the subtype, or a selected component, | |
7950 | -- representing an appropriately qualified occurrence of the | |
7951 | -- subtype name. | |
7952 | ||
7953 | procedure Replace_Type_References is | |
7954 | new Replace_Type_References_Generic (Replace_Type_Reference); | |
7955 | -- Traverse an expression replacing all occurrences of the subtype | |
7956 | -- name with appropriate references to the formal of the predicate | |
7957 | -- function. Note that we must ensure that the type and entity | |
7958 | -- information is properly set in the replacement node, since we | |
7959 | -- will do a Preanalyze call of this expression without proper | |
7960 | -- visibility of the procedure argument. | |
7961 | ||
7962 | ---------------------------- | |
7963 | -- Replace_Type_Reference -- | |
7964 | ---------------------------- | |
7965 | ||
7966 | -- Note: See comments in Add_Predicates.Replace_Type_Reference | |
7967 | -- regarding handling of Sloc and Comes_From_Source. | |
7968 | ||
7969 | procedure Replace_Type_Reference (N : Node_Id) is | |
7970 | Nloc : constant Source_Ptr := Sloc (N); | |
d97beb2f | 7971 | |
f9e26ff7 | 7972 | begin |
7973 | -- Add semantic information to node to be rewritten, for ASIS | |
7974 | -- navigation needs. | |
d97beb2f | 7975 | |
f9e26ff7 | 7976 | if Nkind (N) = N_Identifier then |
7977 | Set_Entity (N, T); | |
7978 | Set_Etype (N, T); | |
d7c2851f | 7979 | |
f9e26ff7 | 7980 | elsif Nkind (N) = N_Selected_Component then |
7981 | Analyze (Prefix (N)); | |
7982 | Set_Entity (Selector_Name (N), T); | |
7983 | Set_Etype (Selector_Name (N), T); | |
7984 | end if; | |
d7c2851f | 7985 | |
f9e26ff7 | 7986 | -- Invariant'Class, replace with T'Class (obj) |
d97beb2f | 7987 | |
f9e26ff7 | 7988 | if Class_Present (Prag) then |
69004fe6 | 7989 | |
f9e26ff7 | 7990 | -- In ASIS mode, an inherited item is already analyzed, |
7991 | -- and the replacement has been done, so do not repeat | |
7992 | -- the transformation to prevent a malformed tree. | |
d9f6a4ee | 7993 | |
f9e26ff7 | 7994 | if ASIS_Mode |
7995 | and then Nkind (Parent (N)) = N_Attribute_Reference | |
7996 | and then Attribute_Name (Parent (N)) = Name_Class | |
7997 | then | |
7998 | null; | |
d9f6a4ee | 7999 | |
f9e26ff7 | 8000 | else |
8001 | Rewrite (N, | |
8002 | Make_Type_Conversion (Nloc, | |
8003 | Subtype_Mark => | |
8004 | Make_Attribute_Reference (Nloc, | |
8005 | Prefix => New_Occurrence_Of (T, Nloc), | |
8006 | Attribute_Name => Name_Class), | |
39629e6a | 8007 | Expression => |
8008 | Make_Identifier (Nloc, Chars (Obj_Id)))); | |
f9e26ff7 | 8009 | |
39629e6a | 8010 | Set_Entity (Expression (N), Obj_Id); |
f9e26ff7 | 8011 | Set_Etype (Expression (N), Typ); |
8012 | end if; | |
d9f6a4ee | 8013 | |
f9e26ff7 | 8014 | -- Invariant, replace with obj |
d9f6a4ee | 8015 | |
f9e26ff7 | 8016 | else |
39629e6a | 8017 | Rewrite (N, Make_Identifier (Nloc, Chars (Obj_Id))); |
8018 | Set_Entity (N, Obj_Id); | |
f9e26ff7 | 8019 | Set_Etype (N, Typ); |
8020 | end if; | |
d9f6a4ee | 8021 | |
f9e26ff7 | 8022 | Set_Comes_From_Source (N, True); |
8023 | end Replace_Type_Reference; | |
d9f6a4ee | 8024 | |
f9e26ff7 | 8025 | -- Local variables |
d9f6a4ee | 8026 | |
f9e26ff7 | 8027 | Asp : constant Node_Id := Corresponding_Aspect (Prag); |
8028 | Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag); | |
8029 | Ploc : constant Source_Ptr := Sloc (Prag); | |
8030 | Arg1 : Node_Id; | |
8031 | Arg2 : Node_Id; | |
8032 | Arg3 : Node_Id; | |
8033 | Assoc : List_Id; | |
8034 | Expr : Node_Id; | |
8035 | Str : String_Id; | |
d9f6a4ee | 8036 | |
f9e26ff7 | 8037 | -- Start of processing for Add_Invariant |
d9f6a4ee | 8038 | |
f9e26ff7 | 8039 | begin |
8040 | -- Extract the arguments of the invariant pragma | |
d9f6a4ee | 8041 | |
f9e26ff7 | 8042 | Arg1 := First (Pragma_Argument_Associations (Prag)); |
8043 | Arg2 := Next (Arg1); | |
8044 | Arg3 := Next (Arg2); | |
d9f6a4ee | 8045 | |
f9e26ff7 | 8046 | Arg1 := Get_Pragma_Arg (Arg1); |
8047 | Arg2 := Get_Pragma_Arg (Arg2); | |
d9f6a4ee | 8048 | |
f9e26ff7 | 8049 | -- The caller requests processing of all Invariant'Class pragmas, |
8050 | -- but the current pragma does not fall in this category. Return | |
8051 | -- as there is nothing left to do. | |
d9f6a4ee | 8052 | |
f9e26ff7 | 8053 | if Inherit then |
8054 | if not Class_Present (Prag) then | |
8055 | return; | |
8056 | end if; | |
d9f6a4ee | 8057 | |
f9e26ff7 | 8058 | -- Otherwise the pragma must apply to the current type |
d9f6a4ee | 8059 | |
f9e26ff7 | 8060 | elsif Entity (Arg1) /= T then |
8061 | return; | |
8062 | end if; | |
d9f6a4ee | 8063 | |
f9e26ff7 | 8064 | Expr := New_Copy_Tree (Arg2); |
d9f6a4ee | 8065 | |
f9e26ff7 | 8066 | -- Replace all occurrences of the type's name with references to |
8067 | -- the formal parameter of the invariant procedure. | |
d9f6a4ee | 8068 | |
f9e26ff7 | 8069 | Replace_Type_References (Expr, T); |
d9f6a4ee | 8070 | |
f9e26ff7 | 8071 | -- If the invariant pragma comes from an aspect, replace the saved |
8072 | -- expression because we need the subtype references replaced for | |
8073 | -- the calls to Preanalyze_Spec_Expression in Check_Aspect_At_xxx | |
8074 | -- routines. | |
d9f6a4ee | 8075 | |
f9e26ff7 | 8076 | if Present (Asp) then |
8077 | Set_Entity (Identifier (Asp), New_Copy_Tree (Expr)); | |
8078 | end if; | |
d9f6a4ee | 8079 | |
f9e26ff7 | 8080 | -- Preanalyze the invariant expression to capture the visibility |
8081 | -- of the proper package part. In general the expression is not | |
8082 | -- fully analyzed until the body of the invariant procedure is | |
8083 | -- analyzed at the end of the private part, but that yields the | |
8084 | -- wrong visibility. | |
d9f6a4ee | 8085 | |
8d8194a6 | 8086 | -- Historical note: we used to set N as the parent, but a package |
f9e26ff7 | 8087 | -- specification as the parent of an expression is bizarre. |
d9f6a4ee | 8088 | |
f9e26ff7 | 8089 | Set_Parent (Expr, Parent (Arg2)); |
8090 | Preanalyze_Assert_Expression (Expr, Any_Boolean); | |
d9f6a4ee | 8091 | |
f9e26ff7 | 8092 | -- A class-wide invariant may be inherited in a separate unit, |
8093 | -- where the corresponding expression cannot be resolved by | |
8094 | -- visibility, because it refers to a local function. Propagate | |
8095 | -- semantic information to the original representation item, to | |
8096 | -- be used when an invariant procedure for a derived type is | |
8097 | -- constructed. | |
d9f6a4ee | 8098 | |
f9e26ff7 | 8099 | -- ??? Unclear how to handle class-wide invariants that are not |
8100 | -- function calls. | |
f02a9a9a | 8101 | |
f9e26ff7 | 8102 | if not Inherit |
8103 | and then Class_Present (Prag) | |
8104 | and then Nkind (Expr) = N_Function_Call | |
8105 | and then Nkind (Arg2) = N_Indexed_Component | |
8106 | then | |
8107 | Rewrite (Arg2, | |
8108 | Make_Function_Call (Ploc, | |
8109 | Name => | |
8110 | New_Occurrence_Of (Entity (Name (Expr)), Ploc), | |
8111 | Parameter_Associations => | |
8112 | New_Copy_List (Expressions (Arg2)))); | |
8113 | end if; | |
f02a9a9a | 8114 | |
f9e26ff7 | 8115 | -- In ASIS mode, even if assertions are not enabled, we must |
8116 | -- analyze the original expression in the aspect specification | |
8117 | -- because it is part of the original tree. | |
f02a9a9a | 8118 | |
f9e26ff7 | 8119 | if ASIS_Mode and then Present (Asp) then |
8120 | declare | |
8121 | Orig_Expr : constant Node_Id := Expression (Asp); | |
8122 | begin | |
8123 | Replace_Type_References (Orig_Expr, T); | |
8124 | Preanalyze_Assert_Expression (Orig_Expr, Any_Boolean); | |
8125 | end; | |
8126 | end if; | |
d9f6a4ee | 8127 | |
f9e26ff7 | 8128 | -- An ignored invariant must not generate a runtime check. Add a |
8129 | -- null statement to ensure that the invariant procedure does get | |
8130 | -- a completing body. | |
d9f6a4ee | 8131 | |
f9e26ff7 | 8132 | if No (Stmts) then |
8133 | Stmts := Empty_List; | |
8134 | end if; | |
d9f6a4ee | 8135 | |
f9e26ff7 | 8136 | if Is_Ignored (Prag) then |
8137 | Append_To (Stmts, Make_Null_Statement (Ploc)); | |
d9f6a4ee | 8138 | |
f9e26ff7 | 8139 | -- Otherwise the invariant is checked. Build a Check pragma to |
8140 | -- verify the expression at runtime. | |
d9f6a4ee | 8141 | |
f9e26ff7 | 8142 | else |
8143 | Assoc := New_List ( | |
8144 | Make_Pragma_Argument_Association (Ploc, | |
8145 | Expression => Make_Identifier (Ploc, Nam)), | |
8146 | Make_Pragma_Argument_Association (Ploc, | |
8147 | Expression => Expr)); | |
d9f6a4ee | 8148 | |
f9e26ff7 | 8149 | -- Handle the String argument (if any) |
d9f6a4ee | 8150 | |
eb66e842 | 8151 | if Present (Arg3) then |
8152 | Str := Strval (Get_Pragma_Arg (Arg3)); | |
d9f6a4ee | 8153 | |
f9e26ff7 | 8154 | -- When inheriting an invariant, modify the message from |
8155 | -- "failed invariant" to "failed inherited invariant". | |
d9f6a4ee | 8156 | |
eb66e842 | 8157 | if Inherit then |
8158 | String_To_Name_Buffer (Str); | |
d9f6a4ee | 8159 | |
eb66e842 | 8160 | if Name_Buffer (1 .. 16) = "failed invariant" then |
8161 | Insert_Str_In_Name_Buffer ("inherited ", 8); | |
8162 | Str := String_From_Name_Buffer; | |
8163 | end if; | |
8164 | end if; | |
d9f6a4ee | 8165 | |
eb66e842 | 8166 | Append_To (Assoc, |
f9e26ff7 | 8167 | Make_Pragma_Argument_Association (Ploc, |
8168 | Expression => Make_String_Literal (Ploc, Str))); | |
eb66e842 | 8169 | end if; |
d9f6a4ee | 8170 | |
f9e26ff7 | 8171 | -- Generate: |
8172 | -- pragma Check (Nam, Expr, Str); | |
d97beb2f | 8173 | |
eb66e842 | 8174 | Append_To (Stmts, |
f9e26ff7 | 8175 | Make_Pragma (Ploc, |
eb66e842 | 8176 | Pragma_Identifier => |
f9e26ff7 | 8177 | Make_Identifier (Ploc, Name_Check), |
eb66e842 | 8178 | Pragma_Argument_Associations => Assoc)); |
f9e26ff7 | 8179 | end if; |
d97beb2f | 8180 | |
f9e26ff7 | 8181 | -- Output an info message when inheriting an invariant and the |
8182 | -- listing option is enabled. | |
d97beb2f | 8183 | |
f9e26ff7 | 8184 | if Inherit and Opt.List_Inherited_Aspects then |
8185 | Error_Msg_Sloc := Sloc (Prag); | |
8186 | Error_Msg_N | |
8187 | ("info: & inherits `Invariant''Class` aspect from #?L?", Typ); | |
8188 | end if; | |
8189 | end Add_Invariant; | |
8190 | ||
8191 | -- Local variables | |
8192 | ||
8193 | Ritem : Node_Id; | |
8194 | ||
8195 | -- Start of processing for Add_Invariants | |
8196 | ||
8197 | begin | |
8198 | Ritem := First_Rep_Item (T); | |
8199 | while Present (Ritem) loop | |
8200 | if Nkind (Ritem) = N_Pragma | |
8201 | and then Pragma_Name (Ritem) = Name_Invariant | |
8202 | then | |
8203 | Add_Invariant (Ritem); | |
d9f6a4ee | 8204 | end if; |
d97beb2f | 8205 | |
eb66e842 | 8206 | Next_Rep_Item (Ritem); |
8207 | end loop; | |
8208 | end Add_Invariants; | |
d97beb2f | 8209 | |
39629e6a | 8210 | -- Local variables |
8211 | ||
8212 | Loc : constant Source_Ptr := Sloc (Typ); | |
8213 | Priv_Decls : constant List_Id := Private_Declarations (N); | |
8214 | Vis_Decls : constant List_Id := Visible_Declarations (N); | |
8215 | ||
8216 | Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode; | |
8217 | ||
8218 | PBody : Node_Id; | |
8219 | PDecl : Node_Id; | |
8220 | SId : Entity_Id; | |
8221 | Spec : Node_Id; | |
8222 | Stmts : List_Id; | |
8223 | ||
8224 | Obj_Id : Node_Id; | |
8225 | -- The entity of the formal for the procedure | |
8226 | ||
eb66e842 | 8227 | -- Start of processing for Build_Invariant_Procedure |
d97beb2f | 8228 | |
eb66e842 | 8229 | begin |
39629e6a | 8230 | -- The related type may be subject to pragma Ghost. Set the mode now to |
8231 | -- ensure that the invariant procedure is properly marked as Ghost. | |
8232 | ||
8233 | Set_Ghost_Mode_From_Entity (Typ); | |
8234 | ||
eb66e842 | 8235 | Stmts := No_List; |
8236 | PDecl := Empty; | |
8237 | PBody := Empty; | |
8238 | SId := Empty; | |
d97beb2f | 8239 | |
eb66e842 | 8240 | -- If the aspect specification exists for some view of the type, the |
8241 | -- declaration for the procedure has been created. | |
d97beb2f | 8242 | |
eb66e842 | 8243 | if Has_Invariants (Typ) then |
8244 | SId := Invariant_Procedure (Typ); | |
8245 | end if; | |
9dc88aea | 8246 | |
0c2bde47 | 8247 | -- If the body is already present, nothing to do. This will occur when |
8248 | -- the type is already frozen, which is the case when the invariant | |
8249 | -- appears in a private part, and the freezing takes place before the | |
8250 | -- final pass over full declarations. | |
aba11c12 | 8251 | |
8252 | -- See Exp_Ch3.Insert_Component_Invariant_Checks for details. | |
0c2bde47 | 8253 | |
eb66e842 | 8254 | if Present (SId) then |
8255 | PDecl := Unit_Declaration_Node (SId); | |
0c2bde47 | 8256 | |
8257 | if Present (PDecl) | |
8258 | and then Nkind (PDecl) = N_Subprogram_Declaration | |
8259 | and then Present (Corresponding_Body (PDecl)) | |
8260 | then | |
39629e6a | 8261 | Ghost_Mode := Save_Ghost_Mode; |
0c2bde47 | 8262 | return; |
8263 | end if; | |
8264 | ||
eb66e842 | 8265 | else |
8266 | PDecl := Build_Invariant_Procedure_Declaration (Typ); | |
8267 | end if; | |
9dc88aea | 8268 | |
eb66e842 | 8269 | -- Recover formal of procedure, for use in the calls to invariant |
8270 | -- functions (including inherited ones). | |
d9f6a4ee | 8271 | |
39629e6a | 8272 | Obj_Id := |
eb66e842 | 8273 | Defining_Identifier |
8274 | (First (Parameter_Specifications (Specification (PDecl)))); | |
d9f6a4ee | 8275 | |
eb66e842 | 8276 | -- Add invariants for the current type |
9dc88aea | 8277 | |
39629e6a | 8278 | Add_Invariants |
8279 | (T => Typ, | |
8280 | Obj_Id => Obj_Id, | |
8281 | Stmts => Stmts, | |
8282 | Inherit => False); | |
9dc88aea | 8283 | |
eb66e842 | 8284 | -- Add invariants for parent types |
9dc88aea | 8285 | |
eb66e842 | 8286 | declare |
8287 | Current_Typ : Entity_Id; | |
8288 | Parent_Typ : Entity_Id; | |
9dc88aea | 8289 | |
eb66e842 | 8290 | begin |
8291 | Current_Typ := Typ; | |
d97beb2f | 8292 | loop |
eb66e842 | 8293 | Parent_Typ := Etype (Current_Typ); |
9dc88aea | 8294 | |
eb66e842 | 8295 | if Is_Private_Type (Parent_Typ) |
8296 | and then Present (Full_View (Base_Type (Parent_Typ))) | |
d9f6a4ee | 8297 | then |
eb66e842 | 8298 | Parent_Typ := Full_View (Base_Type (Parent_Typ)); |
8299 | end if; | |
9dc88aea | 8300 | |
eb66e842 | 8301 | exit when Parent_Typ = Current_Typ; |
9dc88aea | 8302 | |
eb66e842 | 8303 | Current_Typ := Parent_Typ; |
39629e6a | 8304 | Add_Invariants |
8305 | (T => Current_Typ, | |
8306 | Obj_Id => Obj_Id, | |
8307 | Stmts => Stmts, | |
8308 | Inherit => True); | |
eb66e842 | 8309 | end loop; |
8310 | end; | |
ad274a73 | 8311 | |
8312 | -- Add invariants of progenitors | |
8313 | ||
8314 | if Is_Tagged_Type (Typ) and then not Is_Interface (Typ) then | |
8315 | declare | |
8316 | Ifaces_List : Elist_Id; | |
8317 | AI : Elmt_Id; | |
8318 | Iface : Entity_Id; | |
8319 | ||
8320 | begin | |
8321 | Collect_Interfaces (Typ, Ifaces_List); | |
8322 | ||
8323 | AI := First_Elmt (Ifaces_List); | |
8324 | while Present (AI) loop | |
8325 | Iface := Node (AI); | |
8326 | ||
8327 | if not Is_Ancestor (Iface, Typ, Use_Full_View => True) then | |
39629e6a | 8328 | Add_Invariants |
8329 | (T => Iface, | |
8330 | Obj_Id => Obj_Id, | |
8331 | Stmts => Stmts, | |
8332 | Inherit => True); | |
ad274a73 | 8333 | end if; |
8334 | ||
8335 | Next_Elmt (AI); | |
8336 | end loop; | |
8337 | end; | |
8338 | end if; | |
9dc88aea | 8339 | |
eb66e842 | 8340 | -- Build the procedure if we generated at least one Check pragma |
9dc88aea | 8341 | |
eb66e842 | 8342 | if Stmts /= No_List then |
39629e6a | 8343 | Spec := Copy_Separate_Tree (Specification (PDecl)); |
9dc88aea | 8344 | |
eb66e842 | 8345 | PBody := |
8346 | Make_Subprogram_Body (Loc, | |
8347 | Specification => Spec, | |
8348 | Declarations => Empty_List, | |
8349 | Handled_Statement_Sequence => | |
8350 | Make_Handled_Sequence_Of_Statements (Loc, | |
8351 | Statements => Stmts)); | |
9dc88aea | 8352 | |
eb66e842 | 8353 | -- Insert procedure declaration and spec at the appropriate points. |
8354 | -- If declaration is already analyzed, it was processed by the | |
8355 | -- generated pragma. | |
9dc88aea | 8356 | |
f9e26ff7 | 8357 | if Present (Priv_Decls) then |
d97beb2f | 8358 | |
eb66e842 | 8359 | -- The spec goes at the end of visible declarations, but they have |
8360 | -- already been analyzed, so we need to explicitly do the analyze. | |
d9f6a4ee | 8361 | |
eb66e842 | 8362 | if not Analyzed (PDecl) then |
f9e26ff7 | 8363 | Append_To (Vis_Decls, PDecl); |
eb66e842 | 8364 | Analyze (PDecl); |
8365 | end if; | |
d9f6a4ee | 8366 | |
eb66e842 | 8367 | -- The body goes at the end of the private declarations, which we |
8368 | -- have not analyzed yet, so we do not need to perform an explicit | |
8369 | -- analyze call. We skip this if there are no private declarations | |
8370 | -- (this is an error that will be caught elsewhere); | |
d9f6a4ee | 8371 | |
f9e26ff7 | 8372 | Append_To (Priv_Decls, PBody); |
d9f6a4ee | 8373 | |
eb66e842 | 8374 | -- If the invariant appears on the full view of a type, the |
8375 | -- analysis of the private part is complete, and we must | |
8376 | -- analyze the new body explicitly. | |
d9f6a4ee | 8377 | |
eb66e842 | 8378 | if In_Private_Part (Current_Scope) then |
8379 | Analyze (PBody); | |
8380 | end if; | |
d97beb2f | 8381 | |
eb66e842 | 8382 | -- If there are no private declarations this may be an error that |
8383 | -- will be diagnosed elsewhere. However, if this is a non-private | |
8384 | -- type that inherits invariants, it needs no completion and there | |
8385 | -- may be no private part. In this case insert invariant procedure | |
8386 | -- at end of current declarative list, and analyze at once, given | |
8387 | -- that the type is about to be frozen. | |
d97beb2f | 8388 | |
eb66e842 | 8389 | elsif not Is_Private_Type (Typ) then |
f9e26ff7 | 8390 | Append_To (Vis_Decls, PDecl); |
8391 | Append_To (Vis_Decls, PBody); | |
eb66e842 | 8392 | Analyze (PDecl); |
8393 | Analyze (PBody); | |
8394 | end if; | |
8395 | end if; | |
39629e6a | 8396 | |
8397 | Ghost_Mode := Save_Ghost_Mode; | |
eb66e842 | 8398 | end Build_Invariant_Procedure; |
d9f6a4ee | 8399 | |
eb66e842 | 8400 | ------------------------------- |
8401 | -- Build_Predicate_Functions -- | |
8402 | ------------------------------- | |
d9f6a4ee | 8403 | |
eb66e842 | 8404 | -- The procedures that are constructed here have the form: |
d9f6a4ee | 8405 | |
eb66e842 | 8406 | -- function typPredicate (Ixxx : typ) return Boolean is |
8407 | -- begin | |
8408 | -- return | |
8409 | -- exp1 and then exp2 and then ... | |
8410 | -- and then typ1Predicate (typ1 (Ixxx)) | |
8411 | -- and then typ2Predicate (typ2 (Ixxx)) | |
8412 | -- and then ...; | |
8413 | -- end typPredicate; | |
d9f6a4ee | 8414 | |
eb66e842 | 8415 | -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that |
8416 | -- this is the point at which these expressions get analyzed, providing the | |
8417 | -- required delay, and typ1, typ2, are entities from which predicates are | |
8418 | -- inherited. Note that we do NOT generate Check pragmas, that's because we | |
8419 | -- use this function even if checks are off, e.g. for membership tests. | |
d9f6a4ee | 8420 | |
eb66e842 | 8421 | -- If the expression has at least one Raise_Expression, then we also build |
8422 | -- the typPredicateM version of the function, in which any occurrence of a | |
8423 | -- Raise_Expression is converted to "return False". | |
d9f6a4ee | 8424 | |
eb66e842 | 8425 | procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is |
8426 | Loc : constant Source_Ptr := Sloc (Typ); | |
d9f6a4ee | 8427 | |
eb66e842 | 8428 | Expr : Node_Id; |
8429 | -- This is the expression for the result of the function. It is | |
8430 | -- is build by connecting the component predicates with AND THEN. | |
d9f6a4ee | 8431 | |
eb66e842 | 8432 | Expr_M : Node_Id; |
8433 | -- This is the corresponding return expression for the Predicate_M | |
8434 | -- function. It differs in that raise expressions are marked for | |
8435 | -- special expansion (see Process_REs). | |
d9f6a4ee | 8436 | |
eb66e842 | 8437 | Object_Name : constant Name_Id := New_Internal_Name ('I'); |
8438 | -- Name for argument of Predicate procedure. Note that we use the same | |
499918a7 | 8439 | -- name for both predicate functions. That way the reference within the |
eb66e842 | 8440 | -- predicate expression is the same in both functions. |
d9f6a4ee | 8441 | |
eb66e842 | 8442 | Object_Entity : constant Entity_Id := |
8443 | Make_Defining_Identifier (Loc, Chars => Object_Name); | |
8444 | -- Entity for argument of Predicate procedure | |
d9f6a4ee | 8445 | |
eb66e842 | 8446 | Object_Entity_M : constant Entity_Id := |
8447 | Make_Defining_Identifier (Loc, Chars => Object_Name); | |
8448 | -- Entity for argument of Predicate_M procedure | |
d9f6a4ee | 8449 | |
eb66e842 | 8450 | Raise_Expression_Present : Boolean := False; |
8451 | -- Set True if Expr has at least one Raise_Expression | |
d9f6a4ee | 8452 | |
eb66e842 | 8453 | procedure Add_Call (T : Entity_Id); |
8454 | -- Includes a call to the predicate function for type T in Expr if T | |
8455 | -- has predicates and Predicate_Function (T) is non-empty. | |
d9f6a4ee | 8456 | |
eb66e842 | 8457 | procedure Add_Predicates; |
8458 | -- Appends expressions for any Predicate pragmas in the rep item chain | |
8459 | -- Typ to Expr. Note that we look only at items for this exact entity. | |
8460 | -- Inheritance of predicates for the parent type is done by calling the | |
8461 | -- Predicate_Function of the parent type, using Add_Call above. | |
d9f6a4ee | 8462 | |
eb66e842 | 8463 | function Process_RE (N : Node_Id) return Traverse_Result; |
8464 | -- Used in Process REs, tests if node N is a raise expression, and if | |
8465 | -- so, marks it to be converted to return False. | |
d9f6a4ee | 8466 | |
eb66e842 | 8467 | procedure Process_REs is new Traverse_Proc (Process_RE); |
8468 | -- Marks any raise expressions in Expr_M to return False | |
d9f6a4ee | 8469 | |
f9e26ff7 | 8470 | function Test_RE (N : Node_Id) return Traverse_Result; |
8471 | -- Used in Test_REs, tests one node for being a raise expression, and if | |
8472 | -- so sets Raise_Expression_Present True. | |
8473 | ||
8474 | procedure Test_REs is new Traverse_Proc (Test_RE); | |
8475 | -- Tests to see if Expr contains any raise expressions | |
8476 | ||
eb66e842 | 8477 | -------------- |
8478 | -- Add_Call -- | |
8479 | -------------- | |
d9f6a4ee | 8480 | |
eb66e842 | 8481 | procedure Add_Call (T : Entity_Id) is |
8482 | Exp : Node_Id; | |
d9f6a4ee | 8483 | |
eb66e842 | 8484 | begin |
8485 | if Present (T) and then Present (Predicate_Function (T)) then | |
8486 | Set_Has_Predicates (Typ); | |
d9f6a4ee | 8487 | |
eb66e842 | 8488 | -- Build the call to the predicate function of T |
d9f6a4ee | 8489 | |
eb66e842 | 8490 | Exp := |
8491 | Make_Predicate_Call | |
8492 | (T, Convert_To (T, Make_Identifier (Loc, Object_Name))); | |
d9f6a4ee | 8493 | |
eb66e842 | 8494 | -- Add call to evolving expression, using AND THEN if needed |
d9f6a4ee | 8495 | |
eb66e842 | 8496 | if No (Expr) then |
8497 | Expr := Exp; | |
3b23aaa0 | 8498 | |
eb66e842 | 8499 | else |
8500 | Expr := | |
3b23aaa0 | 8501 | Make_And_Then (Sloc (Expr), |
eb66e842 | 8502 | Left_Opnd => Relocate_Node (Expr), |
8503 | Right_Opnd => Exp); | |
8504 | end if; | |
d9f6a4ee | 8505 | |
eb66e842 | 8506 | -- Output info message on inheritance if required. Note we do not |
8507 | -- give this information for generic actual types, since it is | |
8508 | -- unwelcome noise in that case in instantiations. We also | |
8509 | -- generally suppress the message in instantiations, and also | |
8510 | -- if it involves internal names. | |
d9f6a4ee | 8511 | |
eb66e842 | 8512 | if Opt.List_Inherited_Aspects |
8513 | and then not Is_Generic_Actual_Type (Typ) | |
8514 | and then Instantiation_Depth (Sloc (Typ)) = 0 | |
8515 | and then not Is_Internal_Name (Chars (T)) | |
8516 | and then not Is_Internal_Name (Chars (Typ)) | |
8517 | then | |
8518 | Error_Msg_Sloc := Sloc (Predicate_Function (T)); | |
8519 | Error_Msg_Node_2 := T; | |
8520 | Error_Msg_N ("info: & inherits predicate from & #?L?", Typ); | |
8521 | end if; | |
8522 | end if; | |
8523 | end Add_Call; | |
d9f6a4ee | 8524 | |
eb66e842 | 8525 | -------------------- |
8526 | -- Add_Predicates -- | |
8527 | -------------------- | |
d9f6a4ee | 8528 | |
eb66e842 | 8529 | procedure Add_Predicates is |
f9e26ff7 | 8530 | procedure Add_Predicate (Prag : Node_Id); |
8531 | -- Concatenate the expression of predicate pragma Prag to Expr by | |
8532 | -- using a short circuit "and then" operator. | |
d9f6a4ee | 8533 | |
f9e26ff7 | 8534 | ------------------- |
8535 | -- Add_Predicate -- | |
8536 | ------------------- | |
d9f6a4ee | 8537 | |
f9e26ff7 | 8538 | procedure Add_Predicate (Prag : Node_Id) is |
8539 | procedure Replace_Type_Reference (N : Node_Id); | |
8540 | -- Replace a single occurrence N of the subtype name with a | |
8541 | -- reference to the formal of the predicate function. N can be an | |
8542 | -- identifier referencing the subtype, or a selected component, | |
8543 | -- representing an appropriately qualified occurrence of the | |
8544 | -- subtype name. | |
8545 | ||
8546 | procedure Replace_Type_References is | |
8547 | new Replace_Type_References_Generic (Replace_Type_Reference); | |
8548 | -- Traverse an expression changing every occurrence of an | |
8549 | -- identifier whose name matches the name of the subtype with a | |
8550 | -- reference to the formal parameter of the predicate function. | |
8551 | ||
8552 | ---------------------------- | |
8553 | -- Replace_Type_Reference -- | |
8554 | ---------------------------- | |
8555 | ||
8556 | procedure Replace_Type_Reference (N : Node_Id) is | |
8557 | begin | |
8558 | Rewrite (N, Make_Identifier (Sloc (N), Object_Name)); | |
8559 | -- Use the Sloc of the usage name, not the defining name | |
d9f6a4ee | 8560 | |
f9e26ff7 | 8561 | Set_Etype (N, Typ); |
8562 | Set_Entity (N, Object_Entity); | |
d97beb2f | 8563 | |
f9e26ff7 | 8564 | -- We want to treat the node as if it comes from source, so |
8565 | -- that ASIS will not ignore it. | |
d97beb2f | 8566 | |
f9e26ff7 | 8567 | Set_Comes_From_Source (N, True); |
8568 | end Replace_Type_Reference; | |
d97beb2f | 8569 | |
f9e26ff7 | 8570 | -- Local variables |
d97beb2f | 8571 | |
f9e26ff7 | 8572 | Asp : constant Node_Id := Corresponding_Aspect (Prag); |
8573 | Arg1 : Node_Id; | |
8574 | Arg2 : Node_Id; | |
d97beb2f | 8575 | |
f9e26ff7 | 8576 | -- Start of processing for Add_Predicate |
24c8d764 | 8577 | |
f9e26ff7 | 8578 | begin |
8579 | -- Extract the arguments of the pragma. The expression itself | |
8580 | -- is copied for use in the predicate function, to preserve the | |
8581 | -- original version for ASIS use. | |
d97beb2f | 8582 | |
f9e26ff7 | 8583 | Arg1 := First (Pragma_Argument_Associations (Prag)); |
8584 | Arg2 := Next (Arg1); | |
d97beb2f | 8585 | |
f9e26ff7 | 8586 | Arg1 := Get_Pragma_Arg (Arg1); |
8587 | Arg2 := New_Copy_Tree (Get_Pragma_Arg (Arg2)); | |
d97beb2f | 8588 | |
f9e26ff7 | 8589 | -- When the predicate pragma applies to the current type or its |
8590 | -- full view, replace all occurrences of the subtype name with | |
8591 | -- references to the formal parameter of the predicate function. | |
639c3741 | 8592 | |
f9e26ff7 | 8593 | if Entity (Arg1) = Typ |
8594 | or else Full_View (Entity (Arg1)) = Typ | |
8595 | then | |
8596 | Replace_Type_References (Arg2, Typ); | |
639c3741 | 8597 | |
f9e26ff7 | 8598 | -- If the predicate pragma comes from an aspect, replace the |
8599 | -- saved expression because we need the subtype references | |
8600 | -- replaced for the calls to Preanalyze_Spec_Expression in | |
8601 | -- Check_Aspect_At_xxx routines. | |
639c3741 | 8602 | |
f9e26ff7 | 8603 | if Present (Asp) then |
639c3741 | 8604 | |
f9e26ff7 | 8605 | Set_Entity (Identifier (Asp), New_Copy_Tree (Arg2)); |
8606 | end if; | |
24c8d764 | 8607 | |
f9e26ff7 | 8608 | -- Concatenate to the existing predicate expressions by using |
8609 | -- "and then". | |
24c8d764 | 8610 | |
f9e26ff7 | 8611 | if Present (Expr) then |
8612 | Expr := | |
8613 | Make_And_Then (Loc, | |
8614 | Left_Opnd => Relocate_Node (Expr), | |
8615 | Right_Opnd => Relocate_Node (Arg2)); | |
639c3741 | 8616 | |
f9e26ff7 | 8617 | -- Otherwise this is the first predicate expression |
639c3741 | 8618 | |
f9e26ff7 | 8619 | else |
8620 | Expr := Relocate_Node (Arg2); | |
8621 | end if; | |
8622 | end if; | |
8623 | end Add_Predicate; | |
737e8460 | 8624 | |
f9e26ff7 | 8625 | -- Local variables |
737e8460 | 8626 | |
f9e26ff7 | 8627 | Ritem : Node_Id; |
d97beb2f | 8628 | |
f9e26ff7 | 8629 | -- Start of processing for Add_Predicates |
d97beb2f | 8630 | |
f9e26ff7 | 8631 | begin |
8632 | Ritem := First_Rep_Item (Typ); | |
8633 | while Present (Ritem) loop | |
8634 | if Nkind (Ritem) = N_Pragma | |
8635 | and then Pragma_Name (Ritem) = Name_Predicate | |
8636 | then | |
8637 | Add_Predicate (Ritem); | |
eb66e842 | 8638 | end if; |
d97beb2f | 8639 | |
eb66e842 | 8640 | Next_Rep_Item (Ritem); |
8641 | end loop; | |
8642 | end Add_Predicates; | |
d97beb2f | 8643 | |
eb66e842 | 8644 | ---------------- |
8645 | -- Process_RE -- | |
8646 | ---------------- | |
d97beb2f | 8647 | |
eb66e842 | 8648 | function Process_RE (N : Node_Id) return Traverse_Result is |
d9f6a4ee | 8649 | begin |
eb66e842 | 8650 | if Nkind (N) = N_Raise_Expression then |
8651 | Set_Convert_To_Return_False (N); | |
8652 | return Skip; | |
d9f6a4ee | 8653 | else |
eb66e842 | 8654 | return OK; |
d9f6a4ee | 8655 | end if; |
eb66e842 | 8656 | end Process_RE; |
d7c2851f | 8657 | |
d9f6a4ee | 8658 | ------------- |
eb66e842 | 8659 | -- Test_RE -- |
d9f6a4ee | 8660 | ------------- |
d7c2851f | 8661 | |
eb66e842 | 8662 | function Test_RE (N : Node_Id) return Traverse_Result is |
d97beb2f | 8663 | begin |
eb66e842 | 8664 | if Nkind (N) = N_Raise_Expression then |
8665 | Raise_Expression_Present := True; | |
8666 | return Abandon; | |
8667 | else | |
8668 | return OK; | |
8669 | end if; | |
8670 | end Test_RE; | |
d97beb2f | 8671 | |
f9e26ff7 | 8672 | -- Local variables |
8673 | ||
30f8d103 | 8674 | Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode; |
f9e26ff7 | 8675 | |
eb66e842 | 8676 | -- Start of processing for Build_Predicate_Functions |
d97beb2f | 8677 | |
eb66e842 | 8678 | begin |
8679 | -- Return if already built or if type does not have predicates | |
9dc88aea | 8680 | |
eb66e842 | 8681 | if not Has_Predicates (Typ) |
8682 | or else Present (Predicate_Function (Typ)) | |
8683 | then | |
8684 | return; | |
8685 | end if; | |
d9f6a4ee | 8686 | |
30f8d103 | 8687 | -- The related type may be subject to pragma Ghost. Set the mode now to |
8688 | -- ensure that the predicate functions are properly marked as Ghost. | |
f9e26ff7 | 8689 | |
8690 | Set_Ghost_Mode_From_Entity (Typ); | |
8691 | ||
eb66e842 | 8692 | -- Prepare to construct predicate expression |
d97beb2f | 8693 | |
eb66e842 | 8694 | Expr := Empty; |
d97beb2f | 8695 | |
eb66e842 | 8696 | -- Add Predicates for the current type |
d97beb2f | 8697 | |
eb66e842 | 8698 | Add_Predicates; |
d97beb2f | 8699 | |
eb66e842 | 8700 | -- Add predicates for ancestor if present |
d97beb2f | 8701 | |
eb66e842 | 8702 | declare |
8703 | Atyp : constant Entity_Id := Nearest_Ancestor (Typ); | |
d9f6a4ee | 8704 | begin |
eb66e842 | 8705 | if Present (Atyp) then |
8706 | Add_Call (Atyp); | |
8707 | end if; | |
8708 | end; | |
9dc88aea | 8709 | |
eb66e842 | 8710 | -- Case where predicates are present |
9dc88aea | 8711 | |
eb66e842 | 8712 | if Present (Expr) then |
726fd56a | 8713 | |
eb66e842 | 8714 | -- Test for raise expression present |
726fd56a | 8715 | |
eb66e842 | 8716 | Test_REs (Expr); |
9dc88aea | 8717 | |
eb66e842 | 8718 | -- If raise expression is present, capture a copy of Expr for use |
8719 | -- in building the predicateM function version later on. For this | |
8720 | -- copy we replace references to Object_Entity by Object_Entity_M. | |
9dc88aea | 8721 | |
eb66e842 | 8722 | if Raise_Expression_Present then |
8723 | declare | |
299b347e | 8724 | Map : constant Elist_Id := New_Elmt_List; |
8725 | New_V : Entity_Id := Empty; | |
8726 | ||
8727 | -- The unanalyzed expression will be copied and appear in | |
8728 | -- both functions. Normally expressions do not declare new | |
8729 | -- entities, but quantified expressions do, so we need to | |
8730 | -- create new entities for their bound variables, to prevent | |
8731 | -- multiple definitions in gigi. | |
8732 | ||
8733 | function Reset_Loop_Variable (N : Node_Id) | |
8734 | return Traverse_Result; | |
8735 | ||
8736 | procedure Collect_Loop_Variables is | |
8737 | new Traverse_Proc (Reset_Loop_Variable); | |
8738 | ||
8739 | ------------------------ | |
8740 | -- Reset_Loop_Variable -- | |
8741 | ------------------------ | |
8742 | ||
8743 | function Reset_Loop_Variable (N : Node_Id) | |
8744 | return Traverse_Result | |
8745 | is | |
8746 | begin | |
8747 | if Nkind (N) = N_Iterator_Specification then | |
8748 | New_V := Make_Defining_Identifier | |
8749 | (Sloc (N), Chars (Defining_Identifier (N))); | |
8750 | ||
8751 | Set_Defining_Identifier (N, New_V); | |
8752 | end if; | |
8753 | ||
8754 | return OK; | |
8755 | end Reset_Loop_Variable; | |
8756 | ||
eb66e842 | 8757 | begin |
8758 | Append_Elmt (Object_Entity, Map); | |
8759 | Append_Elmt (Object_Entity_M, Map); | |
8760 | Expr_M := New_Copy_Tree (Expr, Map => Map); | |
299b347e | 8761 | Collect_Loop_Variables (Expr_M); |
eb66e842 | 8762 | end; |
8763 | end if; | |
d97beb2f | 8764 | |
eb66e842 | 8765 | -- Build the main predicate function |
9dc88aea | 8766 | |
eb66e842 | 8767 | declare |
8768 | SId : constant Entity_Id := | |
8769 | Make_Defining_Identifier (Loc, | |
8770 | Chars => New_External_Name (Chars (Typ), "Predicate")); | |
c96806b2 | 8771 | -- The entity for the function spec |
9dc88aea | 8772 | |
eb66e842 | 8773 | SIdB : constant Entity_Id := |
8774 | Make_Defining_Identifier (Loc, | |
8775 | Chars => New_External_Name (Chars (Typ), "Predicate")); | |
8776 | -- The entity for the function body | |
9dc88aea | 8777 | |
eb66e842 | 8778 | Spec : Node_Id; |
8779 | FDecl : Node_Id; | |
8780 | FBody : Node_Id; | |
9dc88aea | 8781 | |
eb66e842 | 8782 | begin |
8783 | -- Build function declaration | |
d97beb2f | 8784 | |
eb66e842 | 8785 | Set_Ekind (SId, E_Function); |
8786 | Set_Is_Internal (SId); | |
8787 | Set_Is_Predicate_Function (SId); | |
8788 | Set_Predicate_Function (Typ, SId); | |
d97beb2f | 8789 | |
eb66e842 | 8790 | -- The predicate function is shared between views of a type |
d97beb2f | 8791 | |
eb66e842 | 8792 | if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
8793 | Set_Predicate_Function (Full_View (Typ), SId); | |
d97beb2f | 8794 | end if; |
d97beb2f | 8795 | |
f9e26ff7 | 8796 | -- Mark the predicate function explicitly as Ghost because it does |
8797 | -- not come from source. | |
8798 | ||
8799 | if Ghost_Mode > None then | |
8800 | Set_Is_Ghost_Entity (SId); | |
8801 | end if; | |
8802 | ||
eb66e842 | 8803 | Spec := |
8804 | Make_Function_Specification (Loc, | |
8805 | Defining_Unit_Name => SId, | |
8806 | Parameter_Specifications => New_List ( | |
8807 | Make_Parameter_Specification (Loc, | |
8808 | Defining_Identifier => Object_Entity, | |
8809 | Parameter_Type => New_Occurrence_Of (Typ, Loc))), | |
8810 | Result_Definition => | |
8811 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
d97beb2f | 8812 | |
eb66e842 | 8813 | FDecl := |
8814 | Make_Subprogram_Declaration (Loc, | |
8815 | Specification => Spec); | |
d97beb2f | 8816 | |
eb66e842 | 8817 | -- Build function body |
d97beb2f | 8818 | |
eb66e842 | 8819 | Spec := |
8820 | Make_Function_Specification (Loc, | |
8821 | Defining_Unit_Name => SIdB, | |
8822 | Parameter_Specifications => New_List ( | |
8823 | Make_Parameter_Specification (Loc, | |
8824 | Defining_Identifier => | |
8825 | Make_Defining_Identifier (Loc, Object_Name), | |
8826 | Parameter_Type => | |
8827 | New_Occurrence_Of (Typ, Loc))), | |
8828 | Result_Definition => | |
8829 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
d97beb2f | 8830 | |
eb66e842 | 8831 | FBody := |
8832 | Make_Subprogram_Body (Loc, | |
8833 | Specification => Spec, | |
8834 | Declarations => Empty_List, | |
8835 | Handled_Statement_Sequence => | |
8836 | Make_Handled_Sequence_Of_Statements (Loc, | |
8837 | Statements => New_List ( | |
8838 | Make_Simple_Return_Statement (Loc, | |
8839 | Expression => Expr)))); | |
9dc88aea | 8840 | |
eb66e842 | 8841 | -- Insert declaration before freeze node and body after |
d97beb2f | 8842 | |
eb66e842 | 8843 | Insert_Before_And_Analyze (N, FDecl); |
8844 | Insert_After_And_Analyze (N, FBody); | |
6958c62c | 8845 | |
8846 | -- Static predicate functions are always side-effect free, and | |
8847 | -- in most cases dynamic predicate functions are as well. Mark | |
8848 | -- them as such whenever possible, so redundant predicate checks | |
7dd0b9b3 | 8849 | -- can be optimized. If there is a variable reference within the |
8850 | -- expression, the function is not pure. | |
b2e821de | 8851 | |
6958c62c | 8852 | if Expander_Active then |
7dd0b9b3 | 8853 | Set_Is_Pure (SId, |
8854 | Side_Effect_Free (Expr, Variable_Ref => True)); | |
6958c62c | 8855 | Set_Is_Inlined (SId); |
8856 | end if; | |
d9f6a4ee | 8857 | end; |
d97beb2f | 8858 | |
eb66e842 | 8859 | -- Test for raise expressions present and if so build M version |
d97beb2f | 8860 | |
eb66e842 | 8861 | if Raise_Expression_Present then |
8862 | declare | |
8863 | SId : constant Entity_Id := | |
8864 | Make_Defining_Identifier (Loc, | |
8865 | Chars => New_External_Name (Chars (Typ), "PredicateM")); | |
c96806b2 | 8866 | -- The entity for the function spec |
d97beb2f | 8867 | |
eb66e842 | 8868 | SIdB : constant Entity_Id := |
8869 | Make_Defining_Identifier (Loc, | |
8870 | Chars => New_External_Name (Chars (Typ), "PredicateM")); | |
8871 | -- The entity for the function body | |
b9e61b2a | 8872 | |
eb66e842 | 8873 | Spec : Node_Id; |
8874 | FDecl : Node_Id; | |
8875 | FBody : Node_Id; | |
8876 | BTemp : Entity_Id; | |
d97beb2f | 8877 | |
eb66e842 | 8878 | begin |
8879 | -- Mark any raise expressions for special expansion | |
d97beb2f | 8880 | |
eb66e842 | 8881 | Process_REs (Expr_M); |
d97beb2f | 8882 | |
eb66e842 | 8883 | -- Build function declaration |
d97beb2f | 8884 | |
eb66e842 | 8885 | Set_Ekind (SId, E_Function); |
8886 | Set_Is_Predicate_Function_M (SId); | |
8887 | Set_Predicate_Function_M (Typ, SId); | |
d97beb2f | 8888 | |
eb66e842 | 8889 | -- The predicate function is shared between views of a type |
d97beb2f | 8890 | |
eb66e842 | 8891 | if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
8892 | Set_Predicate_Function_M (Full_View (Typ), SId); | |
8893 | end if; | |
9dc88aea | 8894 | |
f9e26ff7 | 8895 | -- Mark the predicate function explicitly as Ghost because it |
8896 | -- does not come from source. | |
8897 | ||
8898 | if Ghost_Mode > None then | |
8899 | Set_Is_Ghost_Entity (SId); | |
8900 | end if; | |
8901 | ||
eb66e842 | 8902 | Spec := |
8903 | Make_Function_Specification (Loc, | |
8904 | Defining_Unit_Name => SId, | |
8905 | Parameter_Specifications => New_List ( | |
8906 | Make_Parameter_Specification (Loc, | |
8907 | Defining_Identifier => Object_Entity_M, | |
8908 | Parameter_Type => New_Occurrence_Of (Typ, Loc))), | |
8909 | Result_Definition => | |
8910 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
9dc88aea | 8911 | |
eb66e842 | 8912 | FDecl := |
8913 | Make_Subprogram_Declaration (Loc, | |
8914 | Specification => Spec); | |
9dc88aea | 8915 | |
eb66e842 | 8916 | -- Build function body |
9dc88aea | 8917 | |
eb66e842 | 8918 | Spec := |
8919 | Make_Function_Specification (Loc, | |
8920 | Defining_Unit_Name => SIdB, | |
8921 | Parameter_Specifications => New_List ( | |
8922 | Make_Parameter_Specification (Loc, | |
8923 | Defining_Identifier => | |
8924 | Make_Defining_Identifier (Loc, Object_Name), | |
8925 | Parameter_Type => | |
8926 | New_Occurrence_Of (Typ, Loc))), | |
8927 | Result_Definition => | |
8928 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
9dc88aea | 8929 | |
eb66e842 | 8930 | -- Build the body, we declare the boolean expression before |
8931 | -- doing the return, because we are not really confident of | |
8932 | -- what happens if a return appears within a return. | |
9dc88aea | 8933 | |
eb66e842 | 8934 | BTemp := |
8935 | Make_Defining_Identifier (Loc, | |
8936 | Chars => New_Internal_Name ('B')); | |
9dc88aea | 8937 | |
eb66e842 | 8938 | FBody := |
8939 | Make_Subprogram_Body (Loc, | |
8940 | Specification => Spec, | |
9dc88aea | 8941 | |
eb66e842 | 8942 | Declarations => New_List ( |
8943 | Make_Object_Declaration (Loc, | |
8944 | Defining_Identifier => BTemp, | |
8945 | Constant_Present => True, | |
8946 | Object_Definition => | |
8947 | New_Occurrence_Of (Standard_Boolean, Loc), | |
8948 | Expression => Expr_M)), | |
d97beb2f | 8949 | |
eb66e842 | 8950 | Handled_Statement_Sequence => |
8951 | Make_Handled_Sequence_Of_Statements (Loc, | |
8952 | Statements => New_List ( | |
8953 | Make_Simple_Return_Statement (Loc, | |
8954 | Expression => New_Occurrence_Of (BTemp, Loc))))); | |
d97beb2f | 8955 | |
eb66e842 | 8956 | -- Insert declaration before freeze node and body after |
d97beb2f | 8957 | |
eb66e842 | 8958 | Insert_Before_And_Analyze (N, FDecl); |
8959 | Insert_After_And_Analyze (N, FBody); | |
8960 | end; | |
8961 | end if; | |
9dc88aea | 8962 | |
3b23aaa0 | 8963 | -- See if we have a static predicate. Note that the answer may be |
8964 | -- yes even if we have an explicit Dynamic_Predicate present. | |
9dc88aea | 8965 | |
3b23aaa0 | 8966 | declare |
94d896aa | 8967 | PS : Boolean; |
3b23aaa0 | 8968 | EN : Node_Id; |
9dc88aea | 8969 | |
3b23aaa0 | 8970 | begin |
94d896aa | 8971 | if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then |
8972 | PS := False; | |
8973 | else | |
8974 | PS := Is_Predicate_Static (Expr, Object_Name); | |
8975 | end if; | |
8976 | ||
a360a0f7 | 8977 | -- Case where we have a predicate-static aspect |
9dc88aea | 8978 | |
3b23aaa0 | 8979 | if PS then |
9dc88aea | 8980 | |
3b23aaa0 | 8981 | -- We don't set Has_Static_Predicate_Aspect, since we can have |
8982 | -- any of the three cases (Predicate, Dynamic_Predicate, or | |
8983 | -- Static_Predicate) generating a predicate with an expression | |
a360a0f7 | 8984 | -- that is predicate-static. We just indicate that we have a |
3b23aaa0 | 8985 | -- predicate that can be treated as static. |
d7c2851f | 8986 | |
3b23aaa0 | 8987 | Set_Has_Static_Predicate (Typ); |
d7c2851f | 8988 | |
3b23aaa0 | 8989 | -- For discrete subtype, build the static predicate list |
9dc88aea | 8990 | |
3b23aaa0 | 8991 | if Is_Discrete_Type (Typ) then |
8992 | Build_Discrete_Static_Predicate (Typ, Expr, Object_Name); | |
8993 | ||
8994 | -- If we don't get a static predicate list, it means that we | |
8995 | -- have a case where this is not possible, most typically in | |
8996 | -- the case where we inherit a dynamic predicate. We do not | |
8997 | -- consider this an error, we just leave the predicate as | |
8998 | -- dynamic. But if we do succeed in building the list, then | |
8999 | -- we mark the predicate as static. | |
9000 | ||
5c6a5792 | 9001 | if No (Static_Discrete_Predicate (Typ)) then |
3b23aaa0 | 9002 | Set_Has_Static_Predicate (Typ, False); |
9003 | end if; | |
94d896aa | 9004 | |
9005 | -- For real or string subtype, save predicate expression | |
9006 | ||
9007 | elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then | |
9008 | Set_Static_Real_Or_String_Predicate (Typ, Expr); | |
3b23aaa0 | 9009 | end if; |
9010 | ||
9011 | -- Case of dynamic predicate (expression is not predicate-static) | |
9dc88aea | 9012 | |
eb66e842 | 9013 | else |
3b23aaa0 | 9014 | -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that |
9015 | -- is only set if we have an explicit Dynamic_Predicate aspect | |
9016 | -- given. Here we may simply have a Predicate aspect where the | |
9017 | -- expression happens not to be predicate-static. | |
9018 | ||
9019 | -- Emit an error when the predicate is categorized as static | |
9020 | -- but its expression is not predicate-static. | |
9021 | ||
9022 | -- First a little fiddling to get a nice location for the | |
9023 | -- message. If the expression is of the form (A and then B), | |
9024 | -- then use the left operand for the Sloc. This avoids getting | |
a360a0f7 | 9025 | -- confused by a call to a higher-level predicate with a less |
3b23aaa0 | 9026 | -- convenient source location. |
9027 | ||
9028 | EN := Expr; | |
9029 | while Nkind (EN) = N_And_Then loop | |
9030 | EN := Left_Opnd (EN); | |
9031 | end loop; | |
9032 | ||
9033 | -- Now post appropriate message | |
9034 | ||
9035 | if Has_Static_Predicate_Aspect (Typ) then | |
94d896aa | 9036 | if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then |
3b23aaa0 | 9037 | Error_Msg_F |
26279d91 | 9038 | ("expression is not predicate-static (RM 3.2.4(16-22))", |
3b23aaa0 | 9039 | EN); |
9040 | else | |
94d896aa | 9041 | Error_Msg_F |
9042 | ("static predicate requires scalar or string type", EN); | |
3b23aaa0 | 9043 | end if; |
9044 | end if; | |
eb66e842 | 9045 | end if; |
3b23aaa0 | 9046 | end; |
eb66e842 | 9047 | end if; |
f9e26ff7 | 9048 | |
30f8d103 | 9049 | Ghost_Mode := Save_Ghost_Mode; |
eb66e842 | 9050 | end Build_Predicate_Functions; |
9dc88aea | 9051 | |
d9f6a4ee | 9052 | ----------------------------------------- |
9053 | -- Check_Aspect_At_End_Of_Declarations -- | |
9054 | ----------------------------------------- | |
9dc88aea | 9055 | |
d9f6a4ee | 9056 | procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is |
9057 | Ent : constant Entity_Id := Entity (ASN); | |
9058 | Ident : constant Node_Id := Identifier (ASN); | |
9059 | A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); | |
d7c2851f | 9060 | |
d9f6a4ee | 9061 | End_Decl_Expr : constant Node_Id := Entity (Ident); |
9062 | -- Expression to be analyzed at end of declarations | |
d7c2851f | 9063 | |
d9f6a4ee | 9064 | Freeze_Expr : constant Node_Id := Expression (ASN); |
9065 | -- Expression from call to Check_Aspect_At_Freeze_Point | |
d7c2851f | 9066 | |
d9f6a4ee | 9067 | T : constant Entity_Id := Etype (Freeze_Expr); |
9068 | -- Type required for preanalyze call | |
d7c2851f | 9069 | |
d9f6a4ee | 9070 | Err : Boolean; |
9071 | -- Set False if error | |
9dc88aea | 9072 | |
d9f6a4ee | 9073 | -- On entry to this procedure, Entity (Ident) contains a copy of the |
9074 | -- original expression from the aspect, saved for this purpose, and | |
9075 | -- but Expression (Ident) is a preanalyzed copy of the expression, | |
9076 | -- preanalyzed just after the freeze point. | |
9dc88aea | 9077 | |
d9f6a4ee | 9078 | procedure Check_Overloaded_Name; |
9079 | -- For aspects whose expression is simply a name, this routine checks if | |
9080 | -- the name is overloaded or not. If so, it verifies there is an | |
9081 | -- interpretation that matches the entity obtained at the freeze point, | |
9082 | -- otherwise the compiler complains. | |
9dc88aea | 9083 | |
d9f6a4ee | 9084 | --------------------------- |
9085 | -- Check_Overloaded_Name -- | |
9086 | --------------------------- | |
9087 | ||
9088 | procedure Check_Overloaded_Name is | |
d97beb2f | 9089 | begin |
d9f6a4ee | 9090 | if not Is_Overloaded (End_Decl_Expr) then |
5ac76cee | 9091 | Err := not Is_Entity_Name (End_Decl_Expr) |
9092 | or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr); | |
d9f6a4ee | 9093 | |
d97beb2f | 9094 | else |
d9f6a4ee | 9095 | Err := True; |
9dc88aea | 9096 | |
d9f6a4ee | 9097 | declare |
9098 | Index : Interp_Index; | |
9099 | It : Interp; | |
9dc88aea | 9100 | |
d9f6a4ee | 9101 | begin |
9102 | Get_First_Interp (End_Decl_Expr, Index, It); | |
9103 | while Present (It.Typ) loop | |
9104 | if It.Nam = Entity (Freeze_Expr) then | |
9105 | Err := False; | |
9106 | exit; | |
9107 | end if; | |
9108 | ||
9109 | Get_Next_Interp (Index, It); | |
9110 | end loop; | |
9111 | end; | |
9dc88aea | 9112 | end if; |
d9f6a4ee | 9113 | end Check_Overloaded_Name; |
9dc88aea | 9114 | |
d9f6a4ee | 9115 | -- Start of processing for Check_Aspect_At_End_Of_Declarations |
9dc88aea | 9116 | |
d9f6a4ee | 9117 | begin |
da3cad01 | 9118 | -- In an instance we do not perform the consistency check between freeze |
9119 | -- point and end of declarations, because it was done already in the | |
9120 | -- analysis of the generic. Furthermore, the delayed analysis of an | |
9121 | -- aspect of the instance may produce spurious errors when the generic | |
9122 | -- is a child unit that references entities in the parent (which might | |
9123 | -- not be in scope at the freeze point of the instance). | |
9124 | ||
9125 | if In_Instance then | |
9126 | return; | |
9127 | ||
d9f6a4ee | 9128 | -- Case of aspects Dimension, Dimension_System and Synchronization |
9dc88aea | 9129 | |
da3cad01 | 9130 | elsif A_Id = Aspect_Synchronization then |
d9f6a4ee | 9131 | return; |
d97beb2f | 9132 | |
d9f6a4ee | 9133 | -- Case of stream attributes, just have to compare entities. However, |
9134 | -- the expression is just a name (possibly overloaded), and there may | |
9135 | -- be stream operations declared for unrelated types, so we just need | |
9136 | -- to verify that one of these interpretations is the one available at | |
9137 | -- at the freeze point. | |
9dc88aea | 9138 | |
d9f6a4ee | 9139 | elsif A_Id = Aspect_Input or else |
f02a9a9a | 9140 | A_Id = Aspect_Output or else |
9141 | A_Id = Aspect_Read or else | |
9142 | A_Id = Aspect_Write | |
d9f6a4ee | 9143 | then |
9144 | Analyze (End_Decl_Expr); | |
9145 | Check_Overloaded_Name; | |
9dc88aea | 9146 | |
d9f6a4ee | 9147 | elsif A_Id = Aspect_Variable_Indexing or else |
9148 | A_Id = Aspect_Constant_Indexing or else | |
9149 | A_Id = Aspect_Default_Iterator or else | |
9150 | A_Id = Aspect_Iterator_Element | |
9151 | then | |
9152 | -- Make type unfrozen before analysis, to prevent spurious errors | |
9153 | -- about late attributes. | |
9dc88aea | 9154 | |
d9f6a4ee | 9155 | Set_Is_Frozen (Ent, False); |
9156 | Analyze (End_Decl_Expr); | |
9157 | Set_Is_Frozen (Ent, True); | |
9dc88aea | 9158 | |
d9f6a4ee | 9159 | -- If the end of declarations comes before any other freeze |
9160 | -- point, the Freeze_Expr is not analyzed: no check needed. | |
9dc88aea | 9161 | |
d9f6a4ee | 9162 | if Analyzed (Freeze_Expr) and then not In_Instance then |
9163 | Check_Overloaded_Name; | |
9164 | else | |
9165 | Err := False; | |
9166 | end if; | |
55e8372b | 9167 | |
d9f6a4ee | 9168 | -- All other cases |
55e8372b | 9169 | |
d9f6a4ee | 9170 | else |
c1efebf9 | 9171 | -- Indicate that the expression comes from an aspect specification, |
9172 | -- which is used in subsequent analysis even if expansion is off. | |
9173 | ||
9174 | Set_Parent (End_Decl_Expr, ASN); | |
9175 | ||
d9f6a4ee | 9176 | -- In a generic context the aspect expressions have not been |
9177 | -- preanalyzed, so do it now. There are no conformance checks | |
9178 | -- to perform in this case. | |
55e8372b | 9179 | |
d9f6a4ee | 9180 | if No (T) then |
9181 | Check_Aspect_At_Freeze_Point (ASN); | |
9182 | return; | |
55e8372b | 9183 | |
d9f6a4ee | 9184 | -- The default values attributes may be defined in the private part, |
9185 | -- and the analysis of the expression may take place when only the | |
9186 | -- partial view is visible. The expression must be scalar, so use | |
9187 | -- the full view to resolve. | |
55e8372b | 9188 | |
d9f6a4ee | 9189 | elsif (A_Id = Aspect_Default_Value |
9190 | or else | |
9191 | A_Id = Aspect_Default_Component_Value) | |
9192 | and then Is_Private_Type (T) | |
9193 | then | |
9194 | Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T)); | |
c1efebf9 | 9195 | |
d9f6a4ee | 9196 | else |
9197 | Preanalyze_Spec_Expression (End_Decl_Expr, T); | |
9198 | end if; | |
d97beb2f | 9199 | |
d9f6a4ee | 9200 | Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr); |
9201 | end if; | |
55e8372b | 9202 | |
c1efebf9 | 9203 | -- Output error message if error. Force error on aspect specification |
9204 | -- even if there is an error on the expression itself. | |
55e8372b | 9205 | |
d9f6a4ee | 9206 | if Err then |
9207 | Error_Msg_NE | |
c1efebf9 | 9208 | ("!visibility of aspect for& changes after freeze point", |
d9f6a4ee | 9209 | ASN, Ent); |
9210 | Error_Msg_NE | |
9211 | ("info: & is frozen here, aspects evaluated at this point??", | |
9212 | Freeze_Node (Ent), Ent); | |
9213 | end if; | |
9214 | end Check_Aspect_At_End_Of_Declarations; | |
55e8372b | 9215 | |
d9f6a4ee | 9216 | ---------------------------------- |
9217 | -- Check_Aspect_At_Freeze_Point -- | |
9218 | ---------------------------------- | |
9dc88aea | 9219 | |
d9f6a4ee | 9220 | procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is |
9221 | Ident : constant Node_Id := Identifier (ASN); | |
9222 | -- Identifier (use Entity field to save expression) | |
9dc88aea | 9223 | |
d9f6a4ee | 9224 | A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); |
9dc88aea | 9225 | |
d9f6a4ee | 9226 | T : Entity_Id := Empty; |
9227 | -- Type required for preanalyze call | |
9dc88aea | 9228 | |
d9f6a4ee | 9229 | begin |
9230 | -- On entry to this procedure, Entity (Ident) contains a copy of the | |
9231 | -- original expression from the aspect, saved for this purpose. | |
9dc88aea | 9232 | |
d9f6a4ee | 9233 | -- On exit from this procedure Entity (Ident) is unchanged, still |
9234 | -- containing that copy, but Expression (Ident) is a preanalyzed copy | |
9235 | -- of the expression, preanalyzed just after the freeze point. | |
d97beb2f | 9236 | |
d9f6a4ee | 9237 | -- Make a copy of the expression to be preanalyzed |
d97beb2f | 9238 | |
d9f6a4ee | 9239 | Set_Expression (ASN, New_Copy_Tree (Entity (Ident))); |
d97beb2f | 9240 | |
d9f6a4ee | 9241 | -- Find type for preanalyze call |
d97beb2f | 9242 | |
d9f6a4ee | 9243 | case A_Id is |
9dc88aea | 9244 | |
d9f6a4ee | 9245 | -- No_Aspect should be impossible |
d97beb2f | 9246 | |
d9f6a4ee | 9247 | when No_Aspect => |
9248 | raise Program_Error; | |
9249 | ||
9250 | -- Aspects taking an optional boolean argument | |
d97beb2f | 9251 | |
d9f6a4ee | 9252 | when Boolean_Aspects | |
9253 | Library_Unit_Aspects => | |
9dc88aea | 9254 | |
d9f6a4ee | 9255 | T := Standard_Boolean; |
d7c2851f | 9256 | |
d9f6a4ee | 9257 | -- Aspects corresponding to attribute definition clauses |
9dc88aea | 9258 | |
d9f6a4ee | 9259 | when Aspect_Address => |
9260 | T := RTE (RE_Address); | |
9dc88aea | 9261 | |
d9f6a4ee | 9262 | when Aspect_Attach_Handler => |
9263 | T := RTE (RE_Interrupt_ID); | |
d7c2851f | 9264 | |
d9f6a4ee | 9265 | when Aspect_Bit_Order | Aspect_Scalar_Storage_Order => |
9266 | T := RTE (RE_Bit_Order); | |
d7c2851f | 9267 | |
d9f6a4ee | 9268 | when Aspect_Convention => |
9269 | return; | |
d7c2851f | 9270 | |
d9f6a4ee | 9271 | when Aspect_CPU => |
9272 | T := RTE (RE_CPU_Range); | |
d7c2851f | 9273 | |
d9f6a4ee | 9274 | -- Default_Component_Value is resolved with the component type |
d7c2851f | 9275 | |
d9f6a4ee | 9276 | when Aspect_Default_Component_Value => |
9277 | T := Component_Type (Entity (ASN)); | |
d7c2851f | 9278 | |
647fab54 | 9279 | when Aspect_Default_Storage_Pool => |
9280 | T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); | |
9281 | ||
d9f6a4ee | 9282 | -- Default_Value is resolved with the type entity in question |
d7c2851f | 9283 | |
d9f6a4ee | 9284 | when Aspect_Default_Value => |
9285 | T := Entity (ASN); | |
9dc88aea | 9286 | |
d9f6a4ee | 9287 | when Aspect_Dispatching_Domain => |
9288 | T := RTE (RE_Dispatching_Domain); | |
9dc88aea | 9289 | |
d9f6a4ee | 9290 | when Aspect_External_Tag => |
9291 | T := Standard_String; | |
9dc88aea | 9292 | |
d9f6a4ee | 9293 | when Aspect_External_Name => |
9294 | T := Standard_String; | |
9dc88aea | 9295 | |
d9f6a4ee | 9296 | when Aspect_Link_Name => |
9297 | T := Standard_String; | |
9dc88aea | 9298 | |
d9f6a4ee | 9299 | when Aspect_Priority | Aspect_Interrupt_Priority => |
9300 | T := Standard_Integer; | |
d97beb2f | 9301 | |
d9f6a4ee | 9302 | when Aspect_Relative_Deadline => |
9303 | T := RTE (RE_Time_Span); | |
d97beb2f | 9304 | |
d9f6a4ee | 9305 | when Aspect_Small => |
9306 | T := Universal_Real; | |
490beba6 | 9307 | |
d9f6a4ee | 9308 | -- For a simple storage pool, we have to retrieve the type of the |
9309 | -- pool object associated with the aspect's corresponding attribute | |
9310 | -- definition clause. | |
490beba6 | 9311 | |
d9f6a4ee | 9312 | when Aspect_Simple_Storage_Pool => |
9313 | T := Etype (Expression (Aspect_Rep_Item (ASN))); | |
d97beb2f | 9314 | |
d9f6a4ee | 9315 | when Aspect_Storage_Pool => |
9316 | T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); | |
d97beb2f | 9317 | |
d9f6a4ee | 9318 | when Aspect_Alignment | |
9319 | Aspect_Component_Size | | |
9320 | Aspect_Machine_Radix | | |
9321 | Aspect_Object_Size | | |
9322 | Aspect_Size | | |
9323 | Aspect_Storage_Size | | |
9324 | Aspect_Stream_Size | | |
9325 | Aspect_Value_Size => | |
9326 | T := Any_Integer; | |
9dc88aea | 9327 | |
04ae062f | 9328 | when Aspect_Linker_Section => |
9329 | T := Standard_String; | |
9330 | ||
d9f6a4ee | 9331 | when Aspect_Synchronization => |
9332 | return; | |
7d20685d | 9333 | |
d9f6a4ee | 9334 | -- Special case, the expression of these aspects is just an entity |
9335 | -- that does not need any resolution, so just analyze. | |
7d20685d | 9336 | |
d9f6a4ee | 9337 | when Aspect_Input | |
9338 | Aspect_Output | | |
9339 | Aspect_Read | | |
9340 | Aspect_Suppress | | |
9341 | Aspect_Unsuppress | | |
9342 | Aspect_Warnings | | |
9343 | Aspect_Write => | |
9344 | Analyze (Expression (ASN)); | |
9345 | return; | |
7d20685d | 9346 | |
d9f6a4ee | 9347 | -- Same for Iterator aspects, where the expression is a function |
9348 | -- name. Legality rules are checked separately. | |
89f1e35c | 9349 | |
d9f6a4ee | 9350 | when Aspect_Constant_Indexing | |
9351 | Aspect_Default_Iterator | | |
9352 | Aspect_Iterator_Element | | |
9353 | Aspect_Variable_Indexing => | |
9354 | Analyze (Expression (ASN)); | |
9355 | return; | |
7d20685d | 9356 | |
b3f8228a | 9357 | -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect. |
9358 | ||
9359 | when Aspect_Iterable => | |
3061ffde | 9360 | T := Entity (ASN); |
9361 | ||
b3f8228a | 9362 | declare |
a9f5fea7 | 9363 | Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T); |
3061ffde | 9364 | Assoc : Node_Id; |
9365 | Expr : Node_Id; | |
a9f5fea7 | 9366 | |
b3f8228a | 9367 | begin |
a9f5fea7 | 9368 | if Cursor = Any_Type then |
9369 | return; | |
9370 | end if; | |
9371 | ||
b3f8228a | 9372 | Assoc := First (Component_Associations (Expression (ASN))); |
9373 | while Present (Assoc) loop | |
3061ffde | 9374 | Expr := Expression (Assoc); |
9375 | Analyze (Expr); | |
a9f5fea7 | 9376 | |
9377 | if not Error_Posted (Expr) then | |
9378 | Resolve_Iterable_Operation | |
9379 | (Expr, Cursor, T, Chars (First (Choices (Assoc)))); | |
9380 | end if; | |
9381 | ||
b3f8228a | 9382 | Next (Assoc); |
9383 | end loop; | |
9384 | end; | |
3061ffde | 9385 | |
b3f8228a | 9386 | return; |
9387 | ||
d9f6a4ee | 9388 | -- Invariant/Predicate take boolean expressions |
7d20685d | 9389 | |
d9f6a4ee | 9390 | when Aspect_Dynamic_Predicate | |
9391 | Aspect_Invariant | | |
9392 | Aspect_Predicate | | |
9393 | Aspect_Static_Predicate | | |
9394 | Aspect_Type_Invariant => | |
9395 | T := Standard_Boolean; | |
7d20685d | 9396 | |
d9f6a4ee | 9397 | -- Here is the list of aspects that don't require delay analysis |
89f1e35c | 9398 | |
d0849c23 | 9399 | when Aspect_Abstract_State | |
9400 | Aspect_Annotate | | |
85ee12c0 | 9401 | Aspect_Async_Readers | |
9402 | Aspect_Async_Writers | | |
d0849c23 | 9403 | Aspect_Constant_After_Elaboration | |
9404 | Aspect_Contract_Cases | | |
9405 | Aspect_Default_Initial_Condition | | |
9406 | Aspect_Depends | | |
9407 | Aspect_Dimension | | |
9408 | Aspect_Dimension_System | | |
85ee12c0 | 9409 | Aspect_Effective_Reads | |
9410 | Aspect_Effective_Writes | | |
d0849c23 | 9411 | Aspect_Extensions_Visible | |
9412 | Aspect_Ghost | | |
9413 | Aspect_Global | | |
9414 | Aspect_Implicit_Dereference | | |
9415 | Aspect_Initial_Condition | | |
9416 | Aspect_Initializes | | |
9417 | Aspect_Obsolescent | | |
9418 | Aspect_Part_Of | | |
9419 | Aspect_Post | | |
9420 | Aspect_Postcondition | | |
9421 | Aspect_Pre | | |
9422 | Aspect_Precondition | | |
9423 | Aspect_Refined_Depends | | |
9424 | Aspect_Refined_Global | | |
9425 | Aspect_Refined_Post | | |
9426 | Aspect_Refined_State | | |
9427 | Aspect_SPARK_Mode | | |
9428 | Aspect_Test_Case | | |
85ee12c0 | 9429 | Aspect_Unimplemented | |
9430 | Aspect_Volatile_Function => | |
d9f6a4ee | 9431 | raise Program_Error; |
2b184b2f | 9432 | |
d9f6a4ee | 9433 | end case; |
2b184b2f | 9434 | |
d9f6a4ee | 9435 | -- Do the preanalyze call |
2b184b2f | 9436 | |
d9f6a4ee | 9437 | Preanalyze_Spec_Expression (Expression (ASN), T); |
9438 | end Check_Aspect_At_Freeze_Point; | |
2b184b2f | 9439 | |
d9f6a4ee | 9440 | ----------------------------------- |
9441 | -- Check_Constant_Address_Clause -- | |
9442 | ----------------------------------- | |
2b184b2f | 9443 | |
d9f6a4ee | 9444 | procedure Check_Constant_Address_Clause |
9445 | (Expr : Node_Id; | |
9446 | U_Ent : Entity_Id) | |
9447 | is | |
9448 | procedure Check_At_Constant_Address (Nod : Node_Id); | |
9449 | -- Checks that the given node N represents a name whose 'Address is | |
9450 | -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the | |
9451 | -- address value is the same at the point of declaration of U_Ent and at | |
9452 | -- the time of elaboration of the address clause. | |
84ed7523 | 9453 | |
d9f6a4ee | 9454 | procedure Check_Expr_Constants (Nod : Node_Id); |
9455 | -- Checks that Nod meets the requirements for a constant address clause | |
9456 | -- in the sense of the enclosing procedure. | |
84ed7523 | 9457 | |
d9f6a4ee | 9458 | procedure Check_List_Constants (Lst : List_Id); |
9459 | -- Check that all elements of list Lst meet the requirements for a | |
9460 | -- constant address clause in the sense of the enclosing procedure. | |
84ed7523 | 9461 | |
d9f6a4ee | 9462 | ------------------------------- |
9463 | -- Check_At_Constant_Address -- | |
9464 | ------------------------------- | |
84ed7523 | 9465 | |
d9f6a4ee | 9466 | procedure Check_At_Constant_Address (Nod : Node_Id) is |
9467 | begin | |
9468 | if Is_Entity_Name (Nod) then | |
9469 | if Present (Address_Clause (Entity ((Nod)))) then | |
9470 | Error_Msg_NE | |
9471 | ("invalid address clause for initialized object &!", | |
9472 | Nod, U_Ent); | |
9473 | Error_Msg_NE | |
9474 | ("address for& cannot" & | |
9475 | " depend on another address clause! (RM 13.1(22))!", | |
9476 | Nod, U_Ent); | |
84ed7523 | 9477 | |
d9f6a4ee | 9478 | elsif In_Same_Source_Unit (Entity (Nod), U_Ent) |
9479 | and then Sloc (U_Ent) < Sloc (Entity (Nod)) | |
9480 | then | |
9481 | Error_Msg_NE | |
9482 | ("invalid address clause for initialized object &!", | |
9483 | Nod, U_Ent); | |
9484 | Error_Msg_Node_2 := U_Ent; | |
9485 | Error_Msg_NE | |
9486 | ("\& must be defined before & (RM 13.1(22))!", | |
9487 | Nod, Entity (Nod)); | |
9488 | end if; | |
7d20685d | 9489 | |
d9f6a4ee | 9490 | elsif Nkind (Nod) = N_Selected_Component then |
9491 | declare | |
9492 | T : constant Entity_Id := Etype (Prefix (Nod)); | |
59f3e675 | 9493 | |
d9f6a4ee | 9494 | begin |
9495 | if (Is_Record_Type (T) | |
9496 | and then Has_Discriminants (T)) | |
9497 | or else | |
9498 | (Is_Access_Type (T) | |
f02a9a9a | 9499 | and then Is_Record_Type (Designated_Type (T)) |
9500 | and then Has_Discriminants (Designated_Type (T))) | |
d9f6a4ee | 9501 | then |
9502 | Error_Msg_NE | |
9503 | ("invalid address clause for initialized object &!", | |
9504 | Nod, U_Ent); | |
9505 | Error_Msg_N | |
9506 | ("\address cannot depend on component" & | |
9507 | " of discriminated record (RM 13.1(22))!", | |
9508 | Nod); | |
9509 | else | |
9510 | Check_At_Constant_Address (Prefix (Nod)); | |
9511 | end if; | |
9512 | end; | |
89cc7147 | 9513 | |
d9f6a4ee | 9514 | elsif Nkind (Nod) = N_Indexed_Component then |
9515 | Check_At_Constant_Address (Prefix (Nod)); | |
9516 | Check_List_Constants (Expressions (Nod)); | |
89cc7147 | 9517 | |
84ed7523 | 9518 | else |
d9f6a4ee | 9519 | Check_Expr_Constants (Nod); |
84ed7523 | 9520 | end if; |
d9f6a4ee | 9521 | end Check_At_Constant_Address; |
81b424ac | 9522 | |
d9f6a4ee | 9523 | -------------------------- |
9524 | -- Check_Expr_Constants -- | |
9525 | -------------------------- | |
7b9b2f05 | 9526 | |
d9f6a4ee | 9527 | procedure Check_Expr_Constants (Nod : Node_Id) is |
9528 | Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent); | |
9529 | Ent : Entity_Id := Empty; | |
7b9b2f05 | 9530 | |
d9f6a4ee | 9531 | begin |
9532 | if Nkind (Nod) in N_Has_Etype | |
9533 | and then Etype (Nod) = Any_Type | |
7b9b2f05 | 9534 | then |
d9f6a4ee | 9535 | return; |
309c3053 | 9536 | end if; |
9537 | ||
d9f6a4ee | 9538 | case Nkind (Nod) is |
9539 | when N_Empty | N_Error => | |
9540 | return; | |
7d20685d | 9541 | |
d9f6a4ee | 9542 | when N_Identifier | N_Expanded_Name => |
9543 | Ent := Entity (Nod); | |
7d20685d | 9544 | |
d9f6a4ee | 9545 | -- We need to look at the original node if it is different |
9546 | -- from the node, since we may have rewritten things and | |
9547 | -- substituted an identifier representing the rewrite. | |
7d20685d | 9548 | |
d9f6a4ee | 9549 | if Original_Node (Nod) /= Nod then |
9550 | Check_Expr_Constants (Original_Node (Nod)); | |
7d20685d | 9551 | |
d9f6a4ee | 9552 | -- If the node is an object declaration without initial |
9553 | -- value, some code has been expanded, and the expression | |
9554 | -- is not constant, even if the constituents might be | |
9555 | -- acceptable, as in A'Address + offset. | |
7d20685d | 9556 | |
d9f6a4ee | 9557 | if Ekind (Ent) = E_Variable |
9558 | and then | |
9559 | Nkind (Declaration_Node (Ent)) = N_Object_Declaration | |
9560 | and then | |
9561 | No (Expression (Declaration_Node (Ent))) | |
9562 | then | |
9563 | Error_Msg_NE | |
9564 | ("invalid address clause for initialized object &!", | |
9565 | Nod, U_Ent); | |
89f1e35c | 9566 | |
d9f6a4ee | 9567 | -- If entity is constant, it may be the result of expanding |
9568 | -- a check. We must verify that its declaration appears | |
9569 | -- before the object in question, else we also reject the | |
9570 | -- address clause. | |
7d20685d | 9571 | |
d9f6a4ee | 9572 | elsif Ekind (Ent) = E_Constant |
9573 | and then In_Same_Source_Unit (Ent, U_Ent) | |
9574 | and then Sloc (Ent) > Loc_U_Ent | |
9575 | then | |
9576 | Error_Msg_NE | |
9577 | ("invalid address clause for initialized object &!", | |
9578 | Nod, U_Ent); | |
9579 | end if; | |
7d20685d | 9580 | |
d9f6a4ee | 9581 | return; |
9582 | end if; | |
7d20685d | 9583 | |
d9f6a4ee | 9584 | -- Otherwise look at the identifier and see if it is OK |
7d20685d | 9585 | |
d9f6a4ee | 9586 | if Ekind_In (Ent, E_Named_Integer, E_Named_Real) |
9587 | or else Is_Type (Ent) | |
9588 | then | |
9589 | return; | |
7d20685d | 9590 | |
f02a9a9a | 9591 | elsif Ekind_In (Ent, E_Constant, E_In_Parameter) then |
9592 | ||
d9f6a4ee | 9593 | -- This is the case where we must have Ent defined before |
9594 | -- U_Ent. Clearly if they are in different units this | |
9595 | -- requirement is met since the unit containing Ent is | |
9596 | -- already processed. | |
7d20685d | 9597 | |
d9f6a4ee | 9598 | if not In_Same_Source_Unit (Ent, U_Ent) then |
9599 | return; | |
7d20685d | 9600 | |
d9f6a4ee | 9601 | -- Otherwise location of Ent must be before the location |
9602 | -- of U_Ent, that's what prior defined means. | |
7d20685d | 9603 | |
d9f6a4ee | 9604 | elsif Sloc (Ent) < Loc_U_Ent then |
9605 | return; | |
6c545057 | 9606 | |
d9f6a4ee | 9607 | else |
9608 | Error_Msg_NE | |
9609 | ("invalid address clause for initialized object &!", | |
9610 | Nod, U_Ent); | |
9611 | Error_Msg_Node_2 := U_Ent; | |
9612 | Error_Msg_NE | |
9613 | ("\& must be defined before & (RM 13.1(22))!", | |
9614 | Nod, Ent); | |
9615 | end if; | |
37c6e44c | 9616 | |
d9f6a4ee | 9617 | elsif Nkind (Original_Node (Nod)) = N_Function_Call then |
9618 | Check_Expr_Constants (Original_Node (Nod)); | |
6c545057 | 9619 | |
d9f6a4ee | 9620 | else |
9621 | Error_Msg_NE | |
9622 | ("invalid address clause for initialized object &!", | |
9623 | Nod, U_Ent); | |
3cdbaa5a | 9624 | |
d9f6a4ee | 9625 | if Comes_From_Source (Ent) then |
9626 | Error_Msg_NE | |
9627 | ("\reference to variable& not allowed" | |
9628 | & " (RM 13.1(22))!", Nod, Ent); | |
9629 | else | |
9630 | Error_Msg_N | |
9631 | ("non-static expression not allowed" | |
9632 | & " (RM 13.1(22))!", Nod); | |
9633 | end if; | |
9634 | end if; | |
3cdbaa5a | 9635 | |
d9f6a4ee | 9636 | when N_Integer_Literal => |
7f694ca2 | 9637 | |
d9f6a4ee | 9638 | -- If this is a rewritten unchecked conversion, in a system |
9639 | -- where Address is an integer type, always use the base type | |
9640 | -- for a literal value. This is user-friendly and prevents | |
9641 | -- order-of-elaboration issues with instances of unchecked | |
9642 | -- conversion. | |
3cdbaa5a | 9643 | |
d9f6a4ee | 9644 | if Nkind (Original_Node (Nod)) = N_Function_Call then |
9645 | Set_Etype (Nod, Base_Type (Etype (Nod))); | |
9646 | end if; | |
e1cedbae | 9647 | |
d9f6a4ee | 9648 | when N_Real_Literal | |
9649 | N_String_Literal | | |
9650 | N_Character_Literal => | |
9651 | return; | |
7d20685d | 9652 | |
d9f6a4ee | 9653 | when N_Range => |
9654 | Check_Expr_Constants (Low_Bound (Nod)); | |
9655 | Check_Expr_Constants (High_Bound (Nod)); | |
231eb581 | 9656 | |
d9f6a4ee | 9657 | when N_Explicit_Dereference => |
9658 | Check_Expr_Constants (Prefix (Nod)); | |
231eb581 | 9659 | |
d9f6a4ee | 9660 | when N_Indexed_Component => |
9661 | Check_Expr_Constants (Prefix (Nod)); | |
9662 | Check_List_Constants (Expressions (Nod)); | |
7d20685d | 9663 | |
d9f6a4ee | 9664 | when N_Slice => |
9665 | Check_Expr_Constants (Prefix (Nod)); | |
9666 | Check_Expr_Constants (Discrete_Range (Nod)); | |
cb4c311d | 9667 | |
d9f6a4ee | 9668 | when N_Selected_Component => |
9669 | Check_Expr_Constants (Prefix (Nod)); | |
6144c105 | 9670 | |
d9f6a4ee | 9671 | when N_Attribute_Reference => |
9672 | if Nam_In (Attribute_Name (Nod), Name_Address, | |
9673 | Name_Access, | |
9674 | Name_Unchecked_Access, | |
9675 | Name_Unrestricted_Access) | |
9676 | then | |
9677 | Check_At_Constant_Address (Prefix (Nod)); | |
6144c105 | 9678 | |
d9f6a4ee | 9679 | else |
9680 | Check_Expr_Constants (Prefix (Nod)); | |
9681 | Check_List_Constants (Expressions (Nod)); | |
9682 | end if; | |
a7a4a7c2 | 9683 | |
d9f6a4ee | 9684 | when N_Aggregate => |
9685 | Check_List_Constants (Component_Associations (Nod)); | |
9686 | Check_List_Constants (Expressions (Nod)); | |
7d20685d | 9687 | |
d9f6a4ee | 9688 | when N_Component_Association => |
9689 | Check_Expr_Constants (Expression (Nod)); | |
e1cedbae | 9690 | |
d9f6a4ee | 9691 | when N_Extension_Aggregate => |
9692 | Check_Expr_Constants (Ancestor_Part (Nod)); | |
9693 | Check_List_Constants (Component_Associations (Nod)); | |
9694 | Check_List_Constants (Expressions (Nod)); | |
3cdbaa5a | 9695 | |
d9f6a4ee | 9696 | when N_Null => |
9697 | return; | |
3cdbaa5a | 9698 | |
d9f6a4ee | 9699 | when N_Binary_Op | N_Short_Circuit | N_Membership_Test => |
9700 | Check_Expr_Constants (Left_Opnd (Nod)); | |
9701 | Check_Expr_Constants (Right_Opnd (Nod)); | |
e1cedbae | 9702 | |
d9f6a4ee | 9703 | when N_Unary_Op => |
9704 | Check_Expr_Constants (Right_Opnd (Nod)); | |
7f694ca2 | 9705 | |
d9f6a4ee | 9706 | when N_Type_Conversion | |
9707 | N_Qualified_Expression | | |
9708 | N_Allocator | | |
9709 | N_Unchecked_Type_Conversion => | |
9710 | Check_Expr_Constants (Expression (Nod)); | |
47a46747 | 9711 | |
d9f6a4ee | 9712 | when N_Function_Call => |
9713 | if not Is_Pure (Entity (Name (Nod))) then | |
9714 | Error_Msg_NE | |
9715 | ("invalid address clause for initialized object &!", | |
9716 | Nod, U_Ent); | |
7f694ca2 | 9717 | |
d9f6a4ee | 9718 | Error_Msg_NE |
9719 | ("\function & is not pure (RM 13.1(22))!", | |
9720 | Nod, Entity (Name (Nod))); | |
b55f7641 | 9721 | |
d9f6a4ee | 9722 | else |
9723 | Check_List_Constants (Parameter_Associations (Nod)); | |
9724 | end if; | |
b55f7641 | 9725 | |
d9f6a4ee | 9726 | when N_Parameter_Association => |
9727 | Check_Expr_Constants (Explicit_Actual_Parameter (Nod)); | |
7d20685d | 9728 | |
d9f6a4ee | 9729 | when others => |
9730 | Error_Msg_NE | |
9731 | ("invalid address clause for initialized object &!", | |
9732 | Nod, U_Ent); | |
9733 | Error_Msg_NE | |
9734 | ("\must be constant defined before& (RM 13.1(22))!", | |
9735 | Nod, U_Ent); | |
9736 | end case; | |
9737 | end Check_Expr_Constants; | |
7d20685d | 9738 | |
d9f6a4ee | 9739 | -------------------------- |
9740 | -- Check_List_Constants -- | |
9741 | -------------------------- | |
89f1e35c | 9742 | |
d9f6a4ee | 9743 | procedure Check_List_Constants (Lst : List_Id) is |
9744 | Nod1 : Node_Id; | |
7d20685d | 9745 | |
d9f6a4ee | 9746 | begin |
9747 | if Present (Lst) then | |
9748 | Nod1 := First (Lst); | |
9749 | while Present (Nod1) loop | |
9750 | Check_Expr_Constants (Nod1); | |
9751 | Next (Nod1); | |
9752 | end loop; | |
9753 | end if; | |
9754 | end Check_List_Constants; | |
81b424ac | 9755 | |
d9f6a4ee | 9756 | -- Start of processing for Check_Constant_Address_Clause |
81b424ac | 9757 | |
d9f6a4ee | 9758 | begin |
9759 | -- If rep_clauses are to be ignored, no need for legality checks. In | |
9c7948d7 | 9760 | -- particular, no need to pester user about rep clauses that violate the |
9761 | -- rule on constant addresses, given that these clauses will be removed | |
9762 | -- by Freeze before they reach the back end. Similarly in CodePeer mode, | |
9763 | -- we want to relax these checks. | |
7d20685d | 9764 | |
f1a9be43 | 9765 | if not Ignore_Rep_Clauses and not CodePeer_Mode then |
d9f6a4ee | 9766 | Check_Expr_Constants (Expr); |
9767 | end if; | |
9768 | end Check_Constant_Address_Clause; | |
7d20685d | 9769 | |
6653b695 | 9770 | --------------------------- |
9771 | -- Check_Pool_Size_Clash -- | |
9772 | --------------------------- | |
9773 | ||
9774 | procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is | |
9775 | Post : Node_Id; | |
9776 | ||
9777 | begin | |
9778 | -- We need to find out which one came first. Note that in the case of | |
9779 | -- aspects mixed with pragmas there are cases where the processing order | |
9780 | -- is reversed, which is why we do the check here. | |
9781 | ||
9782 | if Sloc (SP) < Sloc (SS) then | |
9783 | Error_Msg_Sloc := Sloc (SP); | |
9784 | Post := SS; | |
9785 | Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent); | |
9786 | ||
9787 | else | |
9788 | Error_Msg_Sloc := Sloc (SS); | |
9789 | Post := SP; | |
9790 | Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent); | |
9791 | end if; | |
9792 | ||
9793 | Error_Msg_N | |
9794 | ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post); | |
9795 | end Check_Pool_Size_Clash; | |
9796 | ||
d9f6a4ee | 9797 | ---------------------------------------- |
9798 | -- Check_Record_Representation_Clause -- | |
9799 | ---------------------------------------- | |
85696508 | 9800 | |
d9f6a4ee | 9801 | procedure Check_Record_Representation_Clause (N : Node_Id) is |
9802 | Loc : constant Source_Ptr := Sloc (N); | |
9803 | Ident : constant Node_Id := Identifier (N); | |
9804 | Rectype : Entity_Id; | |
9805 | Fent : Entity_Id; | |
9806 | CC : Node_Id; | |
9807 | Fbit : Uint; | |
9808 | Lbit : Uint; | |
9809 | Hbit : Uint := Uint_0; | |
9810 | Comp : Entity_Id; | |
9811 | Pcomp : Entity_Id; | |
89f1e35c | 9812 | |
d9f6a4ee | 9813 | Max_Bit_So_Far : Uint; |
9814 | -- Records the maximum bit position so far. If all field positions | |
9815 | -- are monotonically increasing, then we can skip the circuit for | |
9816 | -- checking for overlap, since no overlap is possible. | |
85696508 | 9817 | |
d9f6a4ee | 9818 | Tagged_Parent : Entity_Id := Empty; |
9819 | -- This is set in the case of a derived tagged type for which we have | |
9820 | -- Is_Fully_Repped_Tagged_Type True (indicating that all components are | |
9821 | -- positioned by record representation clauses). In this case we must | |
9822 | -- check for overlap between components of this tagged type, and the | |
9823 | -- components of its parent. Tagged_Parent will point to this parent | |
9824 | -- type. For all other cases Tagged_Parent is left set to Empty. | |
7d20685d | 9825 | |
d9f6a4ee | 9826 | Parent_Last_Bit : Uint; |
9827 | -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the | |
9828 | -- last bit position for any field in the parent type. We only need to | |
9829 | -- check overlap for fields starting below this point. | |
7d20685d | 9830 | |
d9f6a4ee | 9831 | Overlap_Check_Required : Boolean; |
9832 | -- Used to keep track of whether or not an overlap check is required | |
7d20685d | 9833 | |
d9f6a4ee | 9834 | Overlap_Detected : Boolean := False; |
9835 | -- Set True if an overlap is detected | |
d6f39728 | 9836 | |
d9f6a4ee | 9837 | Ccount : Natural := 0; |
9838 | -- Number of component clauses in record rep clause | |
d6f39728 | 9839 | |
d9f6a4ee | 9840 | procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id); |
9841 | -- Given two entities for record components or discriminants, checks | |
9842 | -- if they have overlapping component clauses and issues errors if so. | |
d6f39728 | 9843 | |
d9f6a4ee | 9844 | procedure Find_Component; |
9845 | -- Finds component entity corresponding to current component clause (in | |
9846 | -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin | |
9847 | -- start/stop bits for the field. If there is no matching component or | |
9848 | -- if the matching component does not have a component clause, then | |
9849 | -- that's an error and Comp is set to Empty, but no error message is | |
9850 | -- issued, since the message was already given. Comp is also set to | |
9851 | -- Empty if the current "component clause" is in fact a pragma. | |
d6f39728 | 9852 | |
d9f6a4ee | 9853 | ----------------------------- |
9854 | -- Check_Component_Overlap -- | |
9855 | ----------------------------- | |
9856 | ||
9857 | procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is | |
9858 | CC1 : constant Node_Id := Component_Clause (C1_Ent); | |
9859 | CC2 : constant Node_Id := Component_Clause (C2_Ent); | |
d6f39728 | 9860 | |
d6f39728 | 9861 | begin |
d9f6a4ee | 9862 | if Present (CC1) and then Present (CC2) then |
d6f39728 | 9863 | |
d9f6a4ee | 9864 | -- Exclude odd case where we have two tag components in the same |
9865 | -- record, both at location zero. This seems a bit strange, but | |
9866 | -- it seems to happen in some circumstances, perhaps on an error. | |
9867 | ||
9868 | if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then | |
9869 | return; | |
d6f39728 | 9870 | end if; |
9871 | ||
d9f6a4ee | 9872 | -- Here we check if the two fields overlap |
9873 | ||
d6f39728 | 9874 | declare |
d9f6a4ee | 9875 | S1 : constant Uint := Component_Bit_Offset (C1_Ent); |
9876 | S2 : constant Uint := Component_Bit_Offset (C2_Ent); | |
9877 | E1 : constant Uint := S1 + Esize (C1_Ent); | |
9878 | E2 : constant Uint := S2 + Esize (C2_Ent); | |
d6f39728 | 9879 | |
9880 | begin | |
d9f6a4ee | 9881 | if E2 <= S1 or else E1 <= S2 then |
9882 | null; | |
d6f39728 | 9883 | else |
d9f6a4ee | 9884 | Error_Msg_Node_2 := Component_Name (CC2); |
9885 | Error_Msg_Sloc := Sloc (Error_Msg_Node_2); | |
9886 | Error_Msg_Node_1 := Component_Name (CC1); | |
9887 | Error_Msg_N | |
9888 | ("component& overlaps & #", Component_Name (CC1)); | |
9889 | Overlap_Detected := True; | |
d6f39728 | 9890 | end if; |
9891 | end; | |
d6f39728 | 9892 | end if; |
d9f6a4ee | 9893 | end Check_Component_Overlap; |
d6f39728 | 9894 | |
d9f6a4ee | 9895 | -------------------- |
9896 | -- Find_Component -- | |
9897 | -------------------- | |
9dfe12ae | 9898 | |
d9f6a4ee | 9899 | procedure Find_Component is |
9dfe12ae | 9900 | |
d9f6a4ee | 9901 | procedure Search_Component (R : Entity_Id); |
9902 | -- Search components of R for a match. If found, Comp is set | |
9dfe12ae | 9903 | |
d9f6a4ee | 9904 | ---------------------- |
9905 | -- Search_Component -- | |
9906 | ---------------------- | |
e7b2d6bc | 9907 | |
d9f6a4ee | 9908 | procedure Search_Component (R : Entity_Id) is |
9909 | begin | |
9910 | Comp := First_Component_Or_Discriminant (R); | |
9911 | while Present (Comp) loop | |
e7b2d6bc | 9912 | |
d9f6a4ee | 9913 | -- Ignore error of attribute name for component name (we |
9914 | -- already gave an error message for this, so no need to | |
9915 | -- complain here) | |
e7b2d6bc | 9916 | |
d9f6a4ee | 9917 | if Nkind (Component_Name (CC)) = N_Attribute_Reference then |
9918 | null; | |
9919 | else | |
9920 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
9dfe12ae | 9921 | end if; |
9922 | ||
d9f6a4ee | 9923 | Next_Component_Or_Discriminant (Comp); |
9924 | end loop; | |
9925 | end Search_Component; | |
d6f39728 | 9926 | |
d9f6a4ee | 9927 | -- Start of processing for Find_Component |
d6f39728 | 9928 | |
d9f6a4ee | 9929 | begin |
9930 | -- Return with Comp set to Empty if we have a pragma | |
d6f39728 | 9931 | |
d9f6a4ee | 9932 | if Nkind (CC) = N_Pragma then |
9933 | Comp := Empty; | |
9934 | return; | |
9935 | end if; | |
d6f39728 | 9936 | |
d9f6a4ee | 9937 | -- Search current record for matching component |
d6f39728 | 9938 | |
d9f6a4ee | 9939 | Search_Component (Rectype); |
9dfe12ae | 9940 | |
d9f6a4ee | 9941 | -- If not found, maybe component of base type discriminant that is |
9942 | -- absent from statically constrained first subtype. | |
e7b2d6bc | 9943 | |
d9f6a4ee | 9944 | if No (Comp) then |
9945 | Search_Component (Base_Type (Rectype)); | |
9946 | end if; | |
e7b2d6bc | 9947 | |
d9f6a4ee | 9948 | -- If no component, or the component does not reference the component |
9949 | -- clause in question, then there was some previous error for which | |
9950 | -- we already gave a message, so just return with Comp Empty. | |
d6f39728 | 9951 | |
d9f6a4ee | 9952 | if No (Comp) or else Component_Clause (Comp) /= CC then |
9953 | Check_Error_Detected; | |
9954 | Comp := Empty; | |
93735cb8 | 9955 | |
d9f6a4ee | 9956 | -- Normal case where we have a component clause |
93735cb8 | 9957 | |
d9f6a4ee | 9958 | else |
9959 | Fbit := Component_Bit_Offset (Comp); | |
9960 | Lbit := Fbit + Esize (Comp) - 1; | |
9961 | end if; | |
9962 | end Find_Component; | |
93735cb8 | 9963 | |
d9f6a4ee | 9964 | -- Start of processing for Check_Record_Representation_Clause |
d6f39728 | 9965 | |
d9f6a4ee | 9966 | begin |
9967 | Find_Type (Ident); | |
9968 | Rectype := Entity (Ident); | |
d6f39728 | 9969 | |
d9f6a4ee | 9970 | if Rectype = Any_Type then |
9971 | return; | |
9972 | else | |
9973 | Rectype := Underlying_Type (Rectype); | |
9974 | end if; | |
d6f39728 | 9975 | |
d9f6a4ee | 9976 | -- See if we have a fully repped derived tagged type |
d6f39728 | 9977 | |
d9f6a4ee | 9978 | declare |
9979 | PS : constant Entity_Id := Parent_Subtype (Rectype); | |
d6f39728 | 9980 | |
d9f6a4ee | 9981 | begin |
9982 | if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then | |
9983 | Tagged_Parent := PS; | |
d6f39728 | 9984 | |
d9f6a4ee | 9985 | -- Find maximum bit of any component of the parent type |
d6f39728 | 9986 | |
d9f6a4ee | 9987 | Parent_Last_Bit := UI_From_Int (System_Address_Size - 1); |
9988 | Pcomp := First_Entity (Tagged_Parent); | |
9989 | while Present (Pcomp) loop | |
9990 | if Ekind_In (Pcomp, E_Discriminant, E_Component) then | |
9991 | if Component_Bit_Offset (Pcomp) /= No_Uint | |
9992 | and then Known_Static_Esize (Pcomp) | |
9993 | then | |
9994 | Parent_Last_Bit := | |
9995 | UI_Max | |
9996 | (Parent_Last_Bit, | |
9997 | Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1); | |
9998 | end if; | |
b7df4cda | 9999 | else |
10000 | ||
10001 | -- Skip anonymous types generated for constrained array | |
10002 | -- or record components. | |
d9f6a4ee | 10003 | |
b7df4cda | 10004 | null; |
d6f39728 | 10005 | end if; |
b7df4cda | 10006 | |
10007 | Next_Entity (Pcomp); | |
d9f6a4ee | 10008 | end loop; |
10009 | end if; | |
10010 | end; | |
d6f39728 | 10011 | |
d9f6a4ee | 10012 | -- All done if no component clauses |
d6f39728 | 10013 | |
d9f6a4ee | 10014 | CC := First (Component_Clauses (N)); |
d6f39728 | 10015 | |
d9f6a4ee | 10016 | if No (CC) then |
10017 | return; | |
10018 | end if; | |
d6f39728 | 10019 | |
d9f6a4ee | 10020 | -- If a tag is present, then create a component clause that places it |
10021 | -- at the start of the record (otherwise gigi may place it after other | |
10022 | -- fields that have rep clauses). | |
d6f39728 | 10023 | |
d9f6a4ee | 10024 | Fent := First_Entity (Rectype); |
d6f39728 | 10025 | |
d9f6a4ee | 10026 | if Nkind (Fent) = N_Defining_Identifier |
10027 | and then Chars (Fent) = Name_uTag | |
10028 | then | |
10029 | Set_Component_Bit_Offset (Fent, Uint_0); | |
10030 | Set_Normalized_Position (Fent, Uint_0); | |
10031 | Set_Normalized_First_Bit (Fent, Uint_0); | |
10032 | Set_Normalized_Position_Max (Fent, Uint_0); | |
10033 | Init_Esize (Fent, System_Address_Size); | |
d6f39728 | 10034 | |
d9f6a4ee | 10035 | Set_Component_Clause (Fent, |
10036 | Make_Component_Clause (Loc, | |
10037 | Component_Name => Make_Identifier (Loc, Name_uTag), | |
d6f39728 | 10038 | |
d9f6a4ee | 10039 | Position => Make_Integer_Literal (Loc, Uint_0), |
10040 | First_Bit => Make_Integer_Literal (Loc, Uint_0), | |
10041 | Last_Bit => | |
10042 | Make_Integer_Literal (Loc, | |
10043 | UI_From_Int (System_Address_Size)))); | |
d6f39728 | 10044 | |
d9f6a4ee | 10045 | Ccount := Ccount + 1; |
10046 | end if; | |
d6f39728 | 10047 | |
d9f6a4ee | 10048 | Max_Bit_So_Far := Uint_Minus_1; |
10049 | Overlap_Check_Required := False; | |
d6f39728 | 10050 | |
d9f6a4ee | 10051 | -- Process the component clauses |
d6f39728 | 10052 | |
d9f6a4ee | 10053 | while Present (CC) loop |
10054 | Find_Component; | |
d6f39728 | 10055 | |
d9f6a4ee | 10056 | if Present (Comp) then |
10057 | Ccount := Ccount + 1; | |
d6f39728 | 10058 | |
d9f6a4ee | 10059 | -- We need a full overlap check if record positions non-monotonic |
d6f39728 | 10060 | |
d9f6a4ee | 10061 | if Fbit <= Max_Bit_So_Far then |
10062 | Overlap_Check_Required := True; | |
10063 | end if; | |
d6f39728 | 10064 | |
d9f6a4ee | 10065 | Max_Bit_So_Far := Lbit; |
d6f39728 | 10066 | |
d9f6a4ee | 10067 | -- Check bit position out of range of specified size |
01cb2726 | 10068 | |
d9f6a4ee | 10069 | if Has_Size_Clause (Rectype) |
10070 | and then RM_Size (Rectype) <= Lbit | |
10071 | then | |
10072 | Error_Msg_N | |
10073 | ("bit number out of range of specified size", | |
10074 | Last_Bit (CC)); | |
d6f39728 | 10075 | |
d9f6a4ee | 10076 | -- Check for overlap with tag component |
67278d60 | 10077 | |
d9f6a4ee | 10078 | else |
10079 | if Is_Tagged_Type (Rectype) | |
10080 | and then Fbit < System_Address_Size | |
10081 | then | |
10082 | Error_Msg_NE | |
10083 | ("component overlaps tag field of&", | |
10084 | Component_Name (CC), Rectype); | |
10085 | Overlap_Detected := True; | |
10086 | end if; | |
67278d60 | 10087 | |
d9f6a4ee | 10088 | if Hbit < Lbit then |
10089 | Hbit := Lbit; | |
10090 | end if; | |
10091 | end if; | |
67278d60 | 10092 | |
d9f6a4ee | 10093 | -- Check parent overlap if component might overlap parent field |
67278d60 | 10094 | |
d9f6a4ee | 10095 | if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then |
10096 | Pcomp := First_Component_Or_Discriminant (Tagged_Parent); | |
10097 | while Present (Pcomp) loop | |
10098 | if not Is_Tag (Pcomp) | |
10099 | and then Chars (Pcomp) /= Name_uParent | |
10100 | then | |
10101 | Check_Component_Overlap (Comp, Pcomp); | |
10102 | end if; | |
67278d60 | 10103 | |
d9f6a4ee | 10104 | Next_Component_Or_Discriminant (Pcomp); |
10105 | end loop; | |
10106 | end if; | |
10107 | end if; | |
67278d60 | 10108 | |
d9f6a4ee | 10109 | Next (CC); |
10110 | end loop; | |
47495553 | 10111 | |
d9f6a4ee | 10112 | -- Now that we have processed all the component clauses, check for |
10113 | -- overlap. We have to leave this till last, since the components can | |
10114 | -- appear in any arbitrary order in the representation clause. | |
67278d60 | 10115 | |
d9f6a4ee | 10116 | -- We do not need this check if all specified ranges were monotonic, |
10117 | -- as recorded by Overlap_Check_Required being False at this stage. | |
67278d60 | 10118 | |
d9f6a4ee | 10119 | -- This first section checks if there are any overlapping entries at |
10120 | -- all. It does this by sorting all entries and then seeing if there are | |
10121 | -- any overlaps. If there are none, then that is decisive, but if there | |
10122 | -- are overlaps, they may still be OK (they may result from fields in | |
10123 | -- different variants). | |
67278d60 | 10124 | |
d9f6a4ee | 10125 | if Overlap_Check_Required then |
10126 | Overlap_Check1 : declare | |
67278d60 | 10127 | |
d9f6a4ee | 10128 | OC_Fbit : array (0 .. Ccount) of Uint; |
10129 | -- First-bit values for component clauses, the value is the offset | |
10130 | -- of the first bit of the field from start of record. The zero | |
10131 | -- entry is for use in sorting. | |
47495553 | 10132 | |
d9f6a4ee | 10133 | OC_Lbit : array (0 .. Ccount) of Uint; |
10134 | -- Last-bit values for component clauses, the value is the offset | |
10135 | -- of the last bit of the field from start of record. The zero | |
10136 | -- entry is for use in sorting. | |
10137 | ||
10138 | OC_Count : Natural := 0; | |
10139 | -- Count of entries in OC_Fbit and OC_Lbit | |
67278d60 | 10140 | |
d9f6a4ee | 10141 | function OC_Lt (Op1, Op2 : Natural) return Boolean; |
10142 | -- Compare routine for Sort | |
67278d60 | 10143 | |
d9f6a4ee | 10144 | procedure OC_Move (From : Natural; To : Natural); |
10145 | -- Move routine for Sort | |
67278d60 | 10146 | |
d9f6a4ee | 10147 | package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt); |
67278d60 | 10148 | |
d9f6a4ee | 10149 | ----------- |
10150 | -- OC_Lt -- | |
10151 | ----------- | |
67278d60 | 10152 | |
d9f6a4ee | 10153 | function OC_Lt (Op1, Op2 : Natural) return Boolean is |
67278d60 | 10154 | begin |
d9f6a4ee | 10155 | return OC_Fbit (Op1) < OC_Fbit (Op2); |
10156 | end OC_Lt; | |
67278d60 | 10157 | |
d9f6a4ee | 10158 | ------------- |
10159 | -- OC_Move -- | |
10160 | ------------- | |
67278d60 | 10161 | |
d9f6a4ee | 10162 | procedure OC_Move (From : Natural; To : Natural) is |
10163 | begin | |
10164 | OC_Fbit (To) := OC_Fbit (From); | |
10165 | OC_Lbit (To) := OC_Lbit (From); | |
10166 | end OC_Move; | |
67278d60 | 10167 | |
d9f6a4ee | 10168 | -- Start of processing for Overlap_Check |
67278d60 | 10169 | |
67278d60 | 10170 | begin |
d9f6a4ee | 10171 | CC := First (Component_Clauses (N)); |
10172 | while Present (CC) loop | |
67278d60 | 10173 | |
d9f6a4ee | 10174 | -- Exclude component clause already marked in error |
67278d60 | 10175 | |
d9f6a4ee | 10176 | if not Error_Posted (CC) then |
10177 | Find_Component; | |
10178 | ||
10179 | if Present (Comp) then | |
10180 | OC_Count := OC_Count + 1; | |
10181 | OC_Fbit (OC_Count) := Fbit; | |
10182 | OC_Lbit (OC_Count) := Lbit; | |
10183 | end if; | |
67278d60 | 10184 | end if; |
10185 | ||
d9f6a4ee | 10186 | Next (CC); |
67278d60 | 10187 | end loop; |
67278d60 | 10188 | |
d9f6a4ee | 10189 | Sorting.Sort (OC_Count); |
67278d60 | 10190 | |
d9f6a4ee | 10191 | Overlap_Check_Required := False; |
10192 | for J in 1 .. OC_Count - 1 loop | |
10193 | if OC_Lbit (J) >= OC_Fbit (J + 1) then | |
10194 | Overlap_Check_Required := True; | |
10195 | exit; | |
10196 | end if; | |
10197 | end loop; | |
10198 | end Overlap_Check1; | |
10199 | end if; | |
67278d60 | 10200 | |
d9f6a4ee | 10201 | -- If Overlap_Check_Required is still True, then we have to do the full |
10202 | -- scale overlap check, since we have at least two fields that do | |
10203 | -- overlap, and we need to know if that is OK since they are in | |
10204 | -- different variant, or whether we have a definite problem. | |
67278d60 | 10205 | |
d9f6a4ee | 10206 | if Overlap_Check_Required then |
10207 | Overlap_Check2 : declare | |
10208 | C1_Ent, C2_Ent : Entity_Id; | |
10209 | -- Entities of components being checked for overlap | |
67278d60 | 10210 | |
d9f6a4ee | 10211 | Clist : Node_Id; |
10212 | -- Component_List node whose Component_Items are being checked | |
67278d60 | 10213 | |
d9f6a4ee | 10214 | Citem : Node_Id; |
10215 | -- Component declaration for component being checked | |
67278d60 | 10216 | |
d9f6a4ee | 10217 | begin |
10218 | C1_Ent := First_Entity (Base_Type (Rectype)); | |
67278d60 | 10219 | |
d9f6a4ee | 10220 | -- Loop through all components in record. For each component check |
10221 | -- for overlap with any of the preceding elements on the component | |
10222 | -- list containing the component and also, if the component is in | |
10223 | -- a variant, check against components outside the case structure. | |
10224 | -- This latter test is repeated recursively up the variant tree. | |
67278d60 | 10225 | |
d9f6a4ee | 10226 | Main_Component_Loop : while Present (C1_Ent) loop |
10227 | if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then | |
10228 | goto Continue_Main_Component_Loop; | |
10229 | end if; | |
67278d60 | 10230 | |
d9f6a4ee | 10231 | -- Skip overlap check if entity has no declaration node. This |
10232 | -- happens with discriminants in constrained derived types. | |
10233 | -- Possibly we are missing some checks as a result, but that | |
10234 | -- does not seem terribly serious. | |
67278d60 | 10235 | |
d9f6a4ee | 10236 | if No (Declaration_Node (C1_Ent)) then |
10237 | goto Continue_Main_Component_Loop; | |
10238 | end if; | |
67278d60 | 10239 | |
d9f6a4ee | 10240 | Clist := Parent (List_Containing (Declaration_Node (C1_Ent))); |
67278d60 | 10241 | |
d9f6a4ee | 10242 | -- Loop through component lists that need checking. Check the |
10243 | -- current component list and all lists in variants above us. | |
67278d60 | 10244 | |
d9f6a4ee | 10245 | Component_List_Loop : loop |
67278d60 | 10246 | |
d9f6a4ee | 10247 | -- If derived type definition, go to full declaration |
10248 | -- If at outer level, check discriminants if there are any. | |
67278d60 | 10249 | |
d9f6a4ee | 10250 | if Nkind (Clist) = N_Derived_Type_Definition then |
10251 | Clist := Parent (Clist); | |
10252 | end if; | |
67278d60 | 10253 | |
d9f6a4ee | 10254 | -- Outer level of record definition, check discriminants |
67278d60 | 10255 | |
d9f6a4ee | 10256 | if Nkind_In (Clist, N_Full_Type_Declaration, |
10257 | N_Private_Type_Declaration) | |
67278d60 | 10258 | then |
d9f6a4ee | 10259 | if Has_Discriminants (Defining_Identifier (Clist)) then |
10260 | C2_Ent := | |
10261 | First_Discriminant (Defining_Identifier (Clist)); | |
10262 | while Present (C2_Ent) loop | |
10263 | exit when C1_Ent = C2_Ent; | |
10264 | Check_Component_Overlap (C1_Ent, C2_Ent); | |
10265 | Next_Discriminant (C2_Ent); | |
10266 | end loop; | |
10267 | end if; | |
67278d60 | 10268 | |
d9f6a4ee | 10269 | -- Record extension case |
67278d60 | 10270 | |
d9f6a4ee | 10271 | elsif Nkind (Clist) = N_Derived_Type_Definition then |
10272 | Clist := Empty; | |
67278d60 | 10273 | |
d9f6a4ee | 10274 | -- Otherwise check one component list |
67278d60 | 10275 | |
d9f6a4ee | 10276 | else |
10277 | Citem := First (Component_Items (Clist)); | |
10278 | while Present (Citem) loop | |
10279 | if Nkind (Citem) = N_Component_Declaration then | |
10280 | C2_Ent := Defining_Identifier (Citem); | |
10281 | exit when C1_Ent = C2_Ent; | |
10282 | Check_Component_Overlap (C1_Ent, C2_Ent); | |
10283 | end if; | |
67278d60 | 10284 | |
d9f6a4ee | 10285 | Next (Citem); |
10286 | end loop; | |
10287 | end if; | |
67278d60 | 10288 | |
d9f6a4ee | 10289 | -- Check for variants above us (the parent of the Clist can |
10290 | -- be a variant, in which case its parent is a variant part, | |
10291 | -- and the parent of the variant part is a component list | |
10292 | -- whose components must all be checked against the current | |
10293 | -- component for overlap). | |
67278d60 | 10294 | |
d9f6a4ee | 10295 | if Nkind (Parent (Clist)) = N_Variant then |
10296 | Clist := Parent (Parent (Parent (Clist))); | |
67278d60 | 10297 | |
d9f6a4ee | 10298 | -- Check for possible discriminant part in record, this |
10299 | -- is treated essentially as another level in the | |
10300 | -- recursion. For this case the parent of the component | |
10301 | -- list is the record definition, and its parent is the | |
10302 | -- full type declaration containing the discriminant | |
10303 | -- specifications. | |
10304 | ||
10305 | elsif Nkind (Parent (Clist)) = N_Record_Definition then | |
10306 | Clist := Parent (Parent ((Clist))); | |
10307 | ||
10308 | -- If neither of these two cases, we are at the top of | |
10309 | -- the tree. | |
10310 | ||
10311 | else | |
10312 | exit Component_List_Loop; | |
10313 | end if; | |
10314 | end loop Component_List_Loop; | |
67278d60 | 10315 | |
d9f6a4ee | 10316 | <<Continue_Main_Component_Loop>> |
10317 | Next_Entity (C1_Ent); | |
67278d60 | 10318 | |
d9f6a4ee | 10319 | end loop Main_Component_Loop; |
10320 | end Overlap_Check2; | |
67278d60 | 10321 | end if; |
10322 | ||
d9f6a4ee | 10323 | -- The following circuit deals with warning on record holes (gaps). We |
10324 | -- skip this check if overlap was detected, since it makes sense for the | |
10325 | -- programmer to fix this illegality before worrying about warnings. | |
67278d60 | 10326 | |
d9f6a4ee | 10327 | if not Overlap_Detected and Warn_On_Record_Holes then |
10328 | Record_Hole_Check : declare | |
10329 | Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype)); | |
10330 | -- Full declaration of record type | |
67278d60 | 10331 | |
d9f6a4ee | 10332 | procedure Check_Component_List |
10333 | (CL : Node_Id; | |
10334 | Sbit : Uint; | |
10335 | DS : List_Id); | |
10336 | -- Check component list CL for holes. The starting bit should be | |
10337 | -- Sbit. which is zero for the main record component list and set | |
10338 | -- appropriately for recursive calls for variants. DS is set to | |
10339 | -- a list of discriminant specifications to be included in the | |
10340 | -- consideration of components. It is No_List if none to consider. | |
67278d60 | 10341 | |
d9f6a4ee | 10342 | -------------------------- |
10343 | -- Check_Component_List -- | |
10344 | -------------------------- | |
47495553 | 10345 | |
d9f6a4ee | 10346 | procedure Check_Component_List |
10347 | (CL : Node_Id; | |
10348 | Sbit : Uint; | |
10349 | DS : List_Id) | |
10350 | is | |
10351 | Compl : Integer; | |
67278d60 | 10352 | |
d9f6a4ee | 10353 | begin |
10354 | Compl := Integer (List_Length (Component_Items (CL))); | |
47495553 | 10355 | |
d9f6a4ee | 10356 | if DS /= No_List then |
10357 | Compl := Compl + Integer (List_Length (DS)); | |
10358 | end if; | |
67278d60 | 10359 | |
d9f6a4ee | 10360 | declare |
10361 | Comps : array (Natural range 0 .. Compl) of Entity_Id; | |
10362 | -- Gather components (zero entry is for sort routine) | |
67278d60 | 10363 | |
d9f6a4ee | 10364 | Ncomps : Natural := 0; |
10365 | -- Number of entries stored in Comps (starting at Comps (1)) | |
67278d60 | 10366 | |
d9f6a4ee | 10367 | Citem : Node_Id; |
10368 | -- One component item or discriminant specification | |
67278d60 | 10369 | |
d9f6a4ee | 10370 | Nbit : Uint; |
10371 | -- Starting bit for next component | |
67278d60 | 10372 | |
d9f6a4ee | 10373 | CEnt : Entity_Id; |
10374 | -- Component entity | |
67278d60 | 10375 | |
d9f6a4ee | 10376 | Variant : Node_Id; |
10377 | -- One variant | |
67278d60 | 10378 | |
d9f6a4ee | 10379 | function Lt (Op1, Op2 : Natural) return Boolean; |
10380 | -- Compare routine for Sort | |
67278d60 | 10381 | |
d9f6a4ee | 10382 | procedure Move (From : Natural; To : Natural); |
10383 | -- Move routine for Sort | |
67278d60 | 10384 | |
d9f6a4ee | 10385 | package Sorting is new GNAT.Heap_Sort_G (Move, Lt); |
67278d60 | 10386 | |
d9f6a4ee | 10387 | -------- |
10388 | -- Lt -- | |
10389 | -------- | |
67278d60 | 10390 | |
d9f6a4ee | 10391 | function Lt (Op1, Op2 : Natural) return Boolean is |
10392 | begin | |
10393 | return Component_Bit_Offset (Comps (Op1)) | |
10394 | < | |
10395 | Component_Bit_Offset (Comps (Op2)); | |
10396 | end Lt; | |
67278d60 | 10397 | |
d9f6a4ee | 10398 | ---------- |
10399 | -- Move -- | |
10400 | ---------- | |
67278d60 | 10401 | |
d9f6a4ee | 10402 | procedure Move (From : Natural; To : Natural) is |
10403 | begin | |
10404 | Comps (To) := Comps (From); | |
10405 | end Move; | |
67278d60 | 10406 | |
d9f6a4ee | 10407 | begin |
10408 | -- Gather discriminants into Comp | |
67278d60 | 10409 | |
d9f6a4ee | 10410 | if DS /= No_List then |
10411 | Citem := First (DS); | |
10412 | while Present (Citem) loop | |
10413 | if Nkind (Citem) = N_Discriminant_Specification then | |
10414 | declare | |
10415 | Ent : constant Entity_Id := | |
10416 | Defining_Identifier (Citem); | |
10417 | begin | |
10418 | if Ekind (Ent) = E_Discriminant then | |
10419 | Ncomps := Ncomps + 1; | |
10420 | Comps (Ncomps) := Ent; | |
10421 | end if; | |
10422 | end; | |
10423 | end if; | |
67278d60 | 10424 | |
d9f6a4ee | 10425 | Next (Citem); |
10426 | end loop; | |
10427 | end if; | |
67278d60 | 10428 | |
d9f6a4ee | 10429 | -- Gather component entities into Comp |
67278d60 | 10430 | |
d9f6a4ee | 10431 | Citem := First (Component_Items (CL)); |
10432 | while Present (Citem) loop | |
10433 | if Nkind (Citem) = N_Component_Declaration then | |
10434 | Ncomps := Ncomps + 1; | |
10435 | Comps (Ncomps) := Defining_Identifier (Citem); | |
10436 | end if; | |
67278d60 | 10437 | |
d9f6a4ee | 10438 | Next (Citem); |
10439 | end loop; | |
67278d60 | 10440 | |
d9f6a4ee | 10441 | -- Now sort the component entities based on the first bit. |
10442 | -- Note we already know there are no overlapping components. | |
67278d60 | 10443 | |
d9f6a4ee | 10444 | Sorting.Sort (Ncomps); |
67278d60 | 10445 | |
d9f6a4ee | 10446 | -- Loop through entries checking for holes |
67278d60 | 10447 | |
d9f6a4ee | 10448 | Nbit := Sbit; |
10449 | for J in 1 .. Ncomps loop | |
10450 | CEnt := Comps (J); | |
10451 | Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit; | |
67278d60 | 10452 | |
d9f6a4ee | 10453 | if Error_Msg_Uint_1 > 0 then |
10454 | Error_Msg_NE | |
10455 | ("?H?^-bit gap before component&", | |
10456 | Component_Name (Component_Clause (CEnt)), CEnt); | |
10457 | end if; | |
67278d60 | 10458 | |
d9f6a4ee | 10459 | Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt); |
10460 | end loop; | |
67278d60 | 10461 | |
d9f6a4ee | 10462 | -- Process variant parts recursively if present |
67278d60 | 10463 | |
d9f6a4ee | 10464 | if Present (Variant_Part (CL)) then |
10465 | Variant := First (Variants (Variant_Part (CL))); | |
10466 | while Present (Variant) loop | |
10467 | Check_Component_List | |
10468 | (Component_List (Variant), Nbit, No_List); | |
10469 | Next (Variant); | |
10470 | end loop; | |
67278d60 | 10471 | end if; |
d9f6a4ee | 10472 | end; |
10473 | end Check_Component_List; | |
67278d60 | 10474 | |
d9f6a4ee | 10475 | -- Start of processing for Record_Hole_Check |
67278d60 | 10476 | |
d9f6a4ee | 10477 | begin |
10478 | declare | |
10479 | Sbit : Uint; | |
67278d60 | 10480 | |
d9f6a4ee | 10481 | begin |
10482 | if Is_Tagged_Type (Rectype) then | |
10483 | Sbit := UI_From_Int (System_Address_Size); | |
10484 | else | |
10485 | Sbit := Uint_0; | |
10486 | end if; | |
10487 | ||
10488 | if Nkind (Decl) = N_Full_Type_Declaration | |
10489 | and then Nkind (Type_Definition (Decl)) = N_Record_Definition | |
10490 | then | |
10491 | Check_Component_List | |
10492 | (Component_List (Type_Definition (Decl)), | |
10493 | Sbit, | |
10494 | Discriminant_Specifications (Decl)); | |
67278d60 | 10495 | end if; |
d9f6a4ee | 10496 | end; |
10497 | end Record_Hole_Check; | |
67278d60 | 10498 | end if; |
10499 | ||
d9f6a4ee | 10500 | -- For records that have component clauses for all components, and whose |
10501 | -- size is less than or equal to 32, we need to know the size in the | |
10502 | -- front end to activate possible packed array processing where the | |
10503 | -- component type is a record. | |
67278d60 | 10504 | |
d9f6a4ee | 10505 | -- At this stage Hbit + 1 represents the first unused bit from all the |
10506 | -- component clauses processed, so if the component clauses are | |
10507 | -- complete, then this is the length of the record. | |
67278d60 | 10508 | |
d9f6a4ee | 10509 | -- For records longer than System.Storage_Unit, and for those where not |
10510 | -- all components have component clauses, the back end determines the | |
10511 | -- length (it may for example be appropriate to round up the size | |
10512 | -- to some convenient boundary, based on alignment considerations, etc). | |
67278d60 | 10513 | |
d9f6a4ee | 10514 | if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then |
67278d60 | 10515 | |
d9f6a4ee | 10516 | -- Nothing to do if at least one component has no component clause |
67278d60 | 10517 | |
d9f6a4ee | 10518 | Comp := First_Component_Or_Discriminant (Rectype); |
10519 | while Present (Comp) loop | |
10520 | exit when No (Component_Clause (Comp)); | |
10521 | Next_Component_Or_Discriminant (Comp); | |
10522 | end loop; | |
67278d60 | 10523 | |
d9f6a4ee | 10524 | -- If we fall out of loop, all components have component clauses |
10525 | -- and so we can set the size to the maximum value. | |
67278d60 | 10526 | |
d9f6a4ee | 10527 | if No (Comp) then |
10528 | Set_RM_Size (Rectype, Hbit + 1); | |
10529 | end if; | |
10530 | end if; | |
10531 | end Check_Record_Representation_Clause; | |
67278d60 | 10532 | |
d9f6a4ee | 10533 | ---------------- |
10534 | -- Check_Size -- | |
10535 | ---------------- | |
67278d60 | 10536 | |
d9f6a4ee | 10537 | procedure Check_Size |
10538 | (N : Node_Id; | |
10539 | T : Entity_Id; | |
10540 | Siz : Uint; | |
10541 | Biased : out Boolean) | |
10542 | is | |
10543 | UT : constant Entity_Id := Underlying_Type (T); | |
10544 | M : Uint; | |
67278d60 | 10545 | |
d9f6a4ee | 10546 | begin |
10547 | Biased := False; | |
67278d60 | 10548 | |
d9f6a4ee | 10549 | -- Reject patently improper size values. |
67278d60 | 10550 | |
d9f6a4ee | 10551 | if Is_Elementary_Type (T) |
10552 | and then Siz > UI_From_Int (Int'Last) | |
10553 | then | |
10554 | Error_Msg_N ("Size value too large for elementary type", N); | |
67278d60 | 10555 | |
d9f6a4ee | 10556 | if Nkind (Original_Node (N)) = N_Op_Expon then |
10557 | Error_Msg_N | |
10558 | ("\maybe '* was meant, rather than '*'*", Original_Node (N)); | |
10559 | end if; | |
10560 | end if; | |
67278d60 | 10561 | |
d9f6a4ee | 10562 | -- Dismiss generic types |
67278d60 | 10563 | |
d9f6a4ee | 10564 | if Is_Generic_Type (T) |
10565 | or else | |
10566 | Is_Generic_Type (UT) | |
10567 | or else | |
10568 | Is_Generic_Type (Root_Type (UT)) | |
10569 | then | |
10570 | return; | |
67278d60 | 10571 | |
d9f6a4ee | 10572 | -- Guard against previous errors |
67278d60 | 10573 | |
d9f6a4ee | 10574 | elsif No (UT) or else UT = Any_Type then |
10575 | Check_Error_Detected; | |
10576 | return; | |
67278d60 | 10577 | |
d9f6a4ee | 10578 | -- Check case of bit packed array |
67278d60 | 10579 | |
d9f6a4ee | 10580 | elsif Is_Array_Type (UT) |
10581 | and then Known_Static_Component_Size (UT) | |
10582 | and then Is_Bit_Packed_Array (UT) | |
10583 | then | |
10584 | declare | |
10585 | Asiz : Uint; | |
10586 | Indx : Node_Id; | |
10587 | Ityp : Entity_Id; | |
67278d60 | 10588 | |
d9f6a4ee | 10589 | begin |
10590 | Asiz := Component_Size (UT); | |
10591 | Indx := First_Index (UT); | |
10592 | loop | |
10593 | Ityp := Etype (Indx); | |
67278d60 | 10594 | |
d9f6a4ee | 10595 | -- If non-static bound, then we are not in the business of |
10596 | -- trying to check the length, and indeed an error will be | |
10597 | -- issued elsewhere, since sizes of non-static array types | |
10598 | -- cannot be set implicitly or explicitly. | |
67278d60 | 10599 | |
cda40848 | 10600 | if not Is_OK_Static_Subtype (Ityp) then |
d9f6a4ee | 10601 | return; |
10602 | end if; | |
67278d60 | 10603 | |
d9f6a4ee | 10604 | -- Otherwise accumulate next dimension |
67278d60 | 10605 | |
d9f6a4ee | 10606 | Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) - |
10607 | Expr_Value (Type_Low_Bound (Ityp)) + | |
10608 | Uint_1); | |
67278d60 | 10609 | |
d9f6a4ee | 10610 | Next_Index (Indx); |
10611 | exit when No (Indx); | |
10612 | end loop; | |
67278d60 | 10613 | |
d9f6a4ee | 10614 | if Asiz <= Siz then |
10615 | return; | |
67278d60 | 10616 | |
d9f6a4ee | 10617 | else |
10618 | Error_Msg_Uint_1 := Asiz; | |
10619 | Error_Msg_NE | |
10620 | ("size for& too small, minimum allowed is ^", N, T); | |
10621 | Set_Esize (T, Asiz); | |
10622 | Set_RM_Size (T, Asiz); | |
10623 | end if; | |
10624 | end; | |
67278d60 | 10625 | |
d9f6a4ee | 10626 | -- All other composite types are ignored |
67278d60 | 10627 | |
d9f6a4ee | 10628 | elsif Is_Composite_Type (UT) then |
10629 | return; | |
47495553 | 10630 | |
d9f6a4ee | 10631 | -- For fixed-point types, don't check minimum if type is not frozen, |
10632 | -- since we don't know all the characteristics of the type that can | |
10633 | -- affect the size (e.g. a specified small) till freeze time. | |
47495553 | 10634 | |
d9f6a4ee | 10635 | elsif Is_Fixed_Point_Type (UT) |
10636 | and then not Is_Frozen (UT) | |
10637 | then | |
10638 | null; | |
47495553 | 10639 | |
d9f6a4ee | 10640 | -- Cases for which a minimum check is required |
47495553 | 10641 | |
d9f6a4ee | 10642 | else |
10643 | -- Ignore if specified size is correct for the type | |
47495553 | 10644 | |
d9f6a4ee | 10645 | if Known_Esize (UT) and then Siz = Esize (UT) then |
10646 | return; | |
10647 | end if; | |
47495553 | 10648 | |
d9f6a4ee | 10649 | -- Otherwise get minimum size |
47495553 | 10650 | |
d9f6a4ee | 10651 | M := UI_From_Int (Minimum_Size (UT)); |
47495553 | 10652 | |
d9f6a4ee | 10653 | if Siz < M then |
47495553 | 10654 | |
d9f6a4ee | 10655 | -- Size is less than minimum size, but one possibility remains |
10656 | -- that we can manage with the new size if we bias the type. | |
47495553 | 10657 | |
d9f6a4ee | 10658 | M := UI_From_Int (Minimum_Size (UT, Biased => True)); |
47495553 | 10659 | |
d9f6a4ee | 10660 | if Siz < M then |
10661 | Error_Msg_Uint_1 := M; | |
10662 | Error_Msg_NE | |
10663 | ("size for& too small, minimum allowed is ^", N, T); | |
10664 | Set_Esize (T, M); | |
10665 | Set_RM_Size (T, M); | |
10666 | else | |
10667 | Biased := True; | |
10668 | end if; | |
10669 | end if; | |
10670 | end if; | |
10671 | end Check_Size; | |
47495553 | 10672 | |
d9f6a4ee | 10673 | -------------------------- |
10674 | -- Freeze_Entity_Checks -- | |
10675 | -------------------------- | |
47495553 | 10676 | |
d9f6a4ee | 10677 | procedure Freeze_Entity_Checks (N : Node_Id) is |
8cf481c9 | 10678 | procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id); |
10679 | -- Inspect the primitive operations of type Typ and hide all pairs of | |
3118058b | 10680 | -- implicitly declared non-overridden non-fully conformant homographs |
10681 | -- (Ada RM 8.3 12.3/2). | |
8cf481c9 | 10682 | |
10683 | ------------------------------------- | |
10684 | -- Hide_Non_Overridden_Subprograms -- | |
10685 | ------------------------------------- | |
10686 | ||
10687 | procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is | |
10688 | procedure Hide_Matching_Homographs | |
10689 | (Subp_Id : Entity_Id; | |
10690 | Start_Elmt : Elmt_Id); | |
10691 | -- Inspect a list of primitive operations starting with Start_Elmt | |
3118058b | 10692 | -- and find matching implicitly declared non-overridden non-fully |
10693 | -- conformant homographs of Subp_Id. If found, all matches along | |
10694 | -- with Subp_Id are hidden from all visibility. | |
8cf481c9 | 10695 | |
10696 | function Is_Non_Overridden_Or_Null_Procedure | |
10697 | (Subp_Id : Entity_Id) return Boolean; | |
10698 | -- Determine whether subprogram Subp_Id is implicitly declared non- | |
10699 | -- overridden subprogram or an implicitly declared null procedure. | |
10700 | ||
10701 | ------------------------------ | |
10702 | -- Hide_Matching_Homographs -- | |
10703 | ------------------------------ | |
10704 | ||
10705 | procedure Hide_Matching_Homographs | |
10706 | (Subp_Id : Entity_Id; | |
10707 | Start_Elmt : Elmt_Id) | |
10708 | is | |
10709 | Prim : Entity_Id; | |
10710 | Prim_Elmt : Elmt_Id; | |
10711 | ||
10712 | begin | |
10713 | Prim_Elmt := Start_Elmt; | |
10714 | while Present (Prim_Elmt) loop | |
10715 | Prim := Node (Prim_Elmt); | |
10716 | ||
10717 | -- The current primitive is implicitly declared non-overridden | |
3118058b | 10718 | -- non-fully conformant homograph of Subp_Id. Both subprograms |
10719 | -- must be hidden from visibility. | |
8cf481c9 | 10720 | |
10721 | if Chars (Prim) = Chars (Subp_Id) | |
8cf481c9 | 10722 | and then Is_Non_Overridden_Or_Null_Procedure (Prim) |
3118058b | 10723 | and then not Fully_Conformant (Prim, Subp_Id) |
8cf481c9 | 10724 | then |
8c7ee4ac | 10725 | Set_Is_Hidden_Non_Overridden_Subpgm (Prim); |
10726 | Set_Is_Immediately_Visible (Prim, False); | |
10727 | Set_Is_Potentially_Use_Visible (Prim, False); | |
8cf481c9 | 10728 | |
8c7ee4ac | 10729 | Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id); |
10730 | Set_Is_Immediately_Visible (Subp_Id, False); | |
10731 | Set_Is_Potentially_Use_Visible (Subp_Id, False); | |
8cf481c9 | 10732 | end if; |
10733 | ||
10734 | Next_Elmt (Prim_Elmt); | |
10735 | end loop; | |
10736 | end Hide_Matching_Homographs; | |
10737 | ||
10738 | ----------------------------------------- | |
10739 | -- Is_Non_Overridden_Or_Null_Procedure -- | |
10740 | ----------------------------------------- | |
10741 | ||
10742 | function Is_Non_Overridden_Or_Null_Procedure | |
10743 | (Subp_Id : Entity_Id) return Boolean | |
10744 | is | |
10745 | Alias_Id : Entity_Id; | |
10746 | ||
10747 | begin | |
10748 | -- The subprogram is inherited (implicitly declared), it does not | |
10749 | -- override and does not cover a primitive of an interface. | |
10750 | ||
10751 | if Ekind_In (Subp_Id, E_Function, E_Procedure) | |
10752 | and then Present (Alias (Subp_Id)) | |
10753 | and then No (Interface_Alias (Subp_Id)) | |
10754 | and then No (Overridden_Operation (Subp_Id)) | |
10755 | then | |
10756 | Alias_Id := Alias (Subp_Id); | |
10757 | ||
10758 | if Requires_Overriding (Alias_Id) then | |
10759 | return True; | |
10760 | ||
10761 | elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification | |
10762 | and then Null_Present (Parent (Alias_Id)) | |
10763 | then | |
10764 | return True; | |
10765 | end if; | |
10766 | end if; | |
10767 | ||
10768 | return False; | |
10769 | end Is_Non_Overridden_Or_Null_Procedure; | |
10770 | ||
10771 | -- Local variables | |
10772 | ||
10773 | Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ); | |
10774 | Prim : Entity_Id; | |
10775 | Prim_Elmt : Elmt_Id; | |
10776 | ||
10777 | -- Start of processing for Hide_Non_Overridden_Subprograms | |
10778 | ||
10779 | begin | |
3118058b | 10780 | -- Inspect the list of primitives looking for non-overridden |
10781 | -- subprograms. | |
8cf481c9 | 10782 | |
10783 | if Present (Prim_Ops) then | |
10784 | Prim_Elmt := First_Elmt (Prim_Ops); | |
10785 | while Present (Prim_Elmt) loop | |
10786 | Prim := Node (Prim_Elmt); | |
10787 | Next_Elmt (Prim_Elmt); | |
10788 | ||
10789 | if Is_Non_Overridden_Or_Null_Procedure (Prim) then | |
10790 | Hide_Matching_Homographs | |
10791 | (Subp_Id => Prim, | |
10792 | Start_Elmt => Prim_Elmt); | |
10793 | end if; | |
10794 | end loop; | |
10795 | end if; | |
10796 | end Hide_Non_Overridden_Subprograms; | |
10797 | ||
10798 | --------------------- | |
10799 | -- Local variables -- | |
10800 | --------------------- | |
10801 | ||
d9f6a4ee | 10802 | E : constant Entity_Id := Entity (N); |
47495553 | 10803 | |
d9f6a4ee | 10804 | Non_Generic_Case : constant Boolean := Nkind (N) = N_Freeze_Entity; |
10805 | -- True in non-generic case. Some of the processing here is skipped | |
10806 | -- for the generic case since it is not needed. Basically in the | |
10807 | -- generic case, we only need to do stuff that might generate error | |
10808 | -- messages or warnings. | |
8cf481c9 | 10809 | |
10810 | -- Start of processing for Freeze_Entity_Checks | |
10811 | ||
d9f6a4ee | 10812 | begin |
10813 | -- Remember that we are processing a freezing entity. Required to | |
10814 | -- ensure correct decoration of internal entities associated with | |
10815 | -- interfaces (see New_Overloaded_Entity). | |
47495553 | 10816 | |
d9f6a4ee | 10817 | Inside_Freezing_Actions := Inside_Freezing_Actions + 1; |
47495553 | 10818 | |
d9f6a4ee | 10819 | -- For tagged types covering interfaces add internal entities that link |
10820 | -- the primitives of the interfaces with the primitives that cover them. | |
10821 | -- Note: These entities were originally generated only when generating | |
10822 | -- code because their main purpose was to provide support to initialize | |
10823 | -- the secondary dispatch tables. They are now generated also when | |
10824 | -- compiling with no code generation to provide ASIS the relationship | |
10825 | -- between interface primitives and tagged type primitives. They are | |
10826 | -- also used to locate primitives covering interfaces when processing | |
10827 | -- generics (see Derive_Subprograms). | |
47495553 | 10828 | |
d9f6a4ee | 10829 | -- This is not needed in the generic case |
47495553 | 10830 | |
d9f6a4ee | 10831 | if Ada_Version >= Ada_2005 |
10832 | and then Non_Generic_Case | |
10833 | and then Ekind (E) = E_Record_Type | |
10834 | and then Is_Tagged_Type (E) | |
10835 | and then not Is_Interface (E) | |
10836 | and then Has_Interfaces (E) | |
10837 | then | |
10838 | -- This would be a good common place to call the routine that checks | |
10839 | -- overriding of interface primitives (and thus factorize calls to | |
10840 | -- Check_Abstract_Overriding located at different contexts in the | |
10841 | -- compiler). However, this is not possible because it causes | |
10842 | -- spurious errors in case of late overriding. | |
47495553 | 10843 | |
d9f6a4ee | 10844 | Add_Internal_Interface_Entities (E); |
10845 | end if; | |
47495553 | 10846 | |
8cf481c9 | 10847 | -- After all forms of overriding have been resolved, a tagged type may |
10848 | -- be left with a set of implicitly declared and possibly erroneous | |
10849 | -- abstract subprograms, null procedures and subprograms that require | |
10850 | -- overriding. If this set contains fully conformat homographs, then one | |
10851 | -- is chosen arbitrarily (already done during resolution), otherwise all | |
3118058b | 10852 | -- remaining non-fully conformant homographs are hidden from visibility |
8cf481c9 | 10853 | -- (Ada RM 8.3 12.3/2). |
10854 | ||
10855 | if Is_Tagged_Type (E) then | |
10856 | Hide_Non_Overridden_Subprograms (E); | |
10857 | end if; | |
10858 | ||
d9f6a4ee | 10859 | -- Check CPP types |
47495553 | 10860 | |
d9f6a4ee | 10861 | if Ekind (E) = E_Record_Type |
10862 | and then Is_CPP_Class (E) | |
10863 | and then Is_Tagged_Type (E) | |
10864 | and then Tagged_Type_Expansion | |
d9f6a4ee | 10865 | then |
10866 | if CPP_Num_Prims (E) = 0 then | |
47495553 | 10867 | |
d9f6a4ee | 10868 | -- If the CPP type has user defined components then it must import |
10869 | -- primitives from C++. This is required because if the C++ class | |
10870 | -- has no primitives then the C++ compiler does not added the _tag | |
10871 | -- component to the type. | |
47495553 | 10872 | |
d9f6a4ee | 10873 | if First_Entity (E) /= Last_Entity (E) then |
10874 | Error_Msg_N | |
10875 | ("'C'P'P type must import at least one primitive from C++??", | |
10876 | E); | |
10877 | end if; | |
10878 | end if; | |
47495553 | 10879 | |
d9f6a4ee | 10880 | -- Check that all its primitives are abstract or imported from C++. |
10881 | -- Check also availability of the C++ constructor. | |
47495553 | 10882 | |
d9f6a4ee | 10883 | declare |
10884 | Has_Constructors : constant Boolean := Has_CPP_Constructors (E); | |
10885 | Elmt : Elmt_Id; | |
10886 | Error_Reported : Boolean := False; | |
10887 | Prim : Node_Id; | |
47495553 | 10888 | |
d9f6a4ee | 10889 | begin |
10890 | Elmt := First_Elmt (Primitive_Operations (E)); | |
10891 | while Present (Elmt) loop | |
10892 | Prim := Node (Elmt); | |
47495553 | 10893 | |
d9f6a4ee | 10894 | if Comes_From_Source (Prim) then |
10895 | if Is_Abstract_Subprogram (Prim) then | |
10896 | null; | |
47495553 | 10897 | |
d9f6a4ee | 10898 | elsif not Is_Imported (Prim) |
10899 | or else Convention (Prim) /= Convention_CPP | |
10900 | then | |
10901 | Error_Msg_N | |
10902 | ("primitives of 'C'P'P types must be imported from C++ " | |
10903 | & "or abstract??", Prim); | |
47495553 | 10904 | |
d9f6a4ee | 10905 | elsif not Has_Constructors |
10906 | and then not Error_Reported | |
10907 | then | |
10908 | Error_Msg_Name_1 := Chars (E); | |
10909 | Error_Msg_N | |
10910 | ("??'C'P'P constructor required for type %", Prim); | |
10911 | Error_Reported := True; | |
10912 | end if; | |
10913 | end if; | |
47495553 | 10914 | |
d9f6a4ee | 10915 | Next_Elmt (Elmt); |
10916 | end loop; | |
10917 | end; | |
10918 | end if; | |
47495553 | 10919 | |
d9f6a4ee | 10920 | -- Check Ada derivation of CPP type |
47495553 | 10921 | |
30ab103b | 10922 | if Expander_Active -- why? losing errors in -gnatc mode??? |
10923 | and then Present (Etype (E)) -- defend against errors | |
d9f6a4ee | 10924 | and then Tagged_Type_Expansion |
10925 | and then Ekind (E) = E_Record_Type | |
10926 | and then Etype (E) /= E | |
10927 | and then Is_CPP_Class (Etype (E)) | |
10928 | and then CPP_Num_Prims (Etype (E)) > 0 | |
10929 | and then not Is_CPP_Class (E) | |
10930 | and then not Has_CPP_Constructors (Etype (E)) | |
10931 | then | |
10932 | -- If the parent has C++ primitives but it has no constructor then | |
10933 | -- check that all the primitives are overridden in this derivation; | |
10934 | -- otherwise the constructor of the parent is needed to build the | |
10935 | -- dispatch table. | |
47495553 | 10936 | |
d9f6a4ee | 10937 | declare |
10938 | Elmt : Elmt_Id; | |
10939 | Prim : Node_Id; | |
47495553 | 10940 | |
10941 | begin | |
d9f6a4ee | 10942 | Elmt := First_Elmt (Primitive_Operations (E)); |
10943 | while Present (Elmt) loop | |
10944 | Prim := Node (Elmt); | |
47495553 | 10945 | |
d9f6a4ee | 10946 | if not Is_Abstract_Subprogram (Prim) |
10947 | and then No (Interface_Alias (Prim)) | |
10948 | and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E | |
47495553 | 10949 | then |
d9f6a4ee | 10950 | Error_Msg_Name_1 := Chars (Etype (E)); |
10951 | Error_Msg_N | |
10952 | ("'C'P'P constructor required for parent type %", E); | |
10953 | exit; | |
47495553 | 10954 | end if; |
d9f6a4ee | 10955 | |
10956 | Next_Elmt (Elmt); | |
10957 | end loop; | |
10958 | end; | |
47495553 | 10959 | end if; |
10960 | ||
d9f6a4ee | 10961 | Inside_Freezing_Actions := Inside_Freezing_Actions - 1; |
67278d60 | 10962 | |
d9f6a4ee | 10963 | -- If we have a type with predicates, build predicate function. This |
0e9014a7 | 10964 | -- is not needed in the generic case, and is not needed within TSS |
ea822fd4 | 10965 | -- subprograms and other predefined primitives. |
67278d60 | 10966 | |
ea822fd4 | 10967 | if Non_Generic_Case |
10968 | and then Is_Type (E) | |
10969 | and then Has_Predicates (E) | |
10970 | and then not Within_Internal_Subprogram | |
10971 | then | |
d9f6a4ee | 10972 | Build_Predicate_Functions (E, N); |
10973 | end if; | |
67278d60 | 10974 | |
d9f6a4ee | 10975 | -- If type has delayed aspects, this is where we do the preanalysis at |
10976 | -- the freeze point, as part of the consistent visibility check. Note | |
10977 | -- that this must be done after calling Build_Predicate_Functions or | |
10978 | -- Build_Invariant_Procedure since these subprograms fix occurrences of | |
10979 | -- the subtype name in the saved expression so that they will not cause | |
10980 | -- trouble in the preanalysis. | |
67278d60 | 10981 | |
d9f6a4ee | 10982 | -- This is also not needed in the generic case |
10983 | ||
10984 | if Non_Generic_Case | |
10985 | and then Has_Delayed_Aspects (E) | |
10986 | and then Scope (E) = Current_Scope | |
10987 | then | |
10988 | -- Retrieve the visibility to the discriminants in order to properly | |
10989 | -- analyze the aspects. | |
10990 | ||
10991 | Push_Scope_And_Install_Discriminants (E); | |
10992 | ||
10993 | declare | |
10994 | Ritem : Node_Id; | |
10995 | ||
10996 | begin | |
10997 | -- Look for aspect specification entries for this entity | |
67278d60 | 10998 | |
d9f6a4ee | 10999 | Ritem := First_Rep_Item (E); |
11000 | while Present (Ritem) loop | |
11001 | if Nkind (Ritem) = N_Aspect_Specification | |
11002 | and then Entity (Ritem) = E | |
11003 | and then Is_Delayed_Aspect (Ritem) | |
11004 | then | |
11005 | Check_Aspect_At_Freeze_Point (Ritem); | |
11006 | end if; | |
67278d60 | 11007 | |
d9f6a4ee | 11008 | Next_Rep_Item (Ritem); |
11009 | end loop; | |
11010 | end; | |
67278d60 | 11011 | |
d9f6a4ee | 11012 | Uninstall_Discriminants_And_Pop_Scope (E); |
67278d60 | 11013 | end if; |
67278d60 | 11014 | |
d9f6a4ee | 11015 | -- For a record type, deal with variant parts. This has to be delayed |
d0988351 | 11016 | -- to this point, because of the issue of statically predicated |
d9f6a4ee | 11017 | -- subtypes, which we have to ensure are frozen before checking |
11018 | -- choices, since we need to have the static choice list set. | |
d6f39728 | 11019 | |
d9f6a4ee | 11020 | if Is_Record_Type (E) then |
11021 | Check_Variant_Part : declare | |
11022 | D : constant Node_Id := Declaration_Node (E); | |
11023 | T : Node_Id; | |
11024 | C : Node_Id; | |
11025 | VP : Node_Id; | |
d6f39728 | 11026 | |
d9f6a4ee | 11027 | Others_Present : Boolean; |
11028 | pragma Warnings (Off, Others_Present); | |
11029 | -- Indicates others present, not used in this case | |
d6f39728 | 11030 | |
d9f6a4ee | 11031 | procedure Non_Static_Choice_Error (Choice : Node_Id); |
11032 | -- Error routine invoked by the generic instantiation below when | |
11033 | -- the variant part has a non static choice. | |
f117057b | 11034 | |
d9f6a4ee | 11035 | procedure Process_Declarations (Variant : Node_Id); |
11036 | -- Processes declarations associated with a variant. We analyzed | |
11037 | -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part), | |
11038 | -- but we still need the recursive call to Check_Choices for any | |
11039 | -- nested variant to get its choices properly processed. This is | |
11040 | -- also where we expand out the choices if expansion is active. | |
1f526845 | 11041 | |
d9f6a4ee | 11042 | package Variant_Choices_Processing is new |
11043 | Generic_Check_Choices | |
11044 | (Process_Empty_Choice => No_OP, | |
11045 | Process_Non_Static_Choice => Non_Static_Choice_Error, | |
11046 | Process_Associated_Node => Process_Declarations); | |
11047 | use Variant_Choices_Processing; | |
f117057b | 11048 | |
d9f6a4ee | 11049 | ----------------------------- |
11050 | -- Non_Static_Choice_Error -- | |
11051 | ----------------------------- | |
d6f39728 | 11052 | |
d9f6a4ee | 11053 | procedure Non_Static_Choice_Error (Choice : Node_Id) is |
11054 | begin | |
11055 | Flag_Non_Static_Expr | |
11056 | ("choice given in variant part is not static!", Choice); | |
11057 | end Non_Static_Choice_Error; | |
d6f39728 | 11058 | |
d9f6a4ee | 11059 | -------------------------- |
11060 | -- Process_Declarations -- | |
11061 | -------------------------- | |
dba36b60 | 11062 | |
d9f6a4ee | 11063 | procedure Process_Declarations (Variant : Node_Id) is |
11064 | CL : constant Node_Id := Component_List (Variant); | |
11065 | VP : Node_Id; | |
dba36b60 | 11066 | |
d9f6a4ee | 11067 | begin |
11068 | -- Check for static predicate present in this variant | |
ea61a7ea | 11069 | |
d9f6a4ee | 11070 | if Has_SP_Choice (Variant) then |
ea61a7ea | 11071 | |
d9f6a4ee | 11072 | -- Here we expand. You might expect to find this call in |
11073 | -- Expand_N_Variant_Part, but that is called when we first | |
11074 | -- see the variant part, and we cannot do this expansion | |
11075 | -- earlier than the freeze point, since for statically | |
11076 | -- predicated subtypes, the predicate is not known till | |
11077 | -- the freeze point. | |
ea61a7ea | 11078 | |
d9f6a4ee | 11079 | -- Furthermore, we do this expansion even if the expander |
11080 | -- is not active, because other semantic processing, e.g. | |
11081 | -- for aggregates, requires the expanded list of choices. | |
ea61a7ea | 11082 | |
d9f6a4ee | 11083 | -- If the expander is not active, then we can't just clobber |
11084 | -- the list since it would invalidate the ASIS -gnatct tree. | |
11085 | -- So we have to rewrite the variant part with a Rewrite | |
11086 | -- call that replaces it with a copy and clobber the copy. | |
11087 | ||
11088 | if not Expander_Active then | |
11089 | declare | |
11090 | NewV : constant Node_Id := New_Copy (Variant); | |
11091 | begin | |
11092 | Set_Discrete_Choices | |
11093 | (NewV, New_Copy_List (Discrete_Choices (Variant))); | |
11094 | Rewrite (Variant, NewV); | |
11095 | end; | |
11096 | end if; | |
11097 | ||
11098 | Expand_Static_Predicates_In_Choices (Variant); | |
ea61a7ea | 11099 | end if; |
11100 | ||
d9f6a4ee | 11101 | -- We don't need to worry about the declarations in the variant |
11102 | -- (since they were analyzed by Analyze_Choices when we first | |
11103 | -- encountered the variant), but we do need to take care of | |
11104 | -- expansion of any nested variants. | |
ea61a7ea | 11105 | |
d9f6a4ee | 11106 | if not Null_Present (CL) then |
11107 | VP := Variant_Part (CL); | |
ea61a7ea | 11108 | |
d9f6a4ee | 11109 | if Present (VP) then |
11110 | Check_Choices | |
11111 | (VP, Variants (VP), Etype (Name (VP)), Others_Present); | |
11112 | end if; | |
11113 | end if; | |
11114 | end Process_Declarations; | |
ea61a7ea | 11115 | |
d9f6a4ee | 11116 | -- Start of processing for Check_Variant_Part |
b9e61b2a | 11117 | |
d9f6a4ee | 11118 | begin |
11119 | -- Find component list | |
ea61a7ea | 11120 | |
d9f6a4ee | 11121 | C := Empty; |
ea61a7ea | 11122 | |
d9f6a4ee | 11123 | if Nkind (D) = N_Full_Type_Declaration then |
11124 | T := Type_Definition (D); | |
ea61a7ea | 11125 | |
d9f6a4ee | 11126 | if Nkind (T) = N_Record_Definition then |
11127 | C := Component_List (T); | |
d6f39728 | 11128 | |
d9f6a4ee | 11129 | elsif Nkind (T) = N_Derived_Type_Definition |
11130 | and then Present (Record_Extension_Part (T)) | |
11131 | then | |
11132 | C := Component_List (Record_Extension_Part (T)); | |
11133 | end if; | |
11134 | end if; | |
d6f39728 | 11135 | |
d9f6a4ee | 11136 | -- Case of variant part present |
d6f39728 | 11137 | |
d9f6a4ee | 11138 | if Present (C) and then Present (Variant_Part (C)) then |
11139 | VP := Variant_Part (C); | |
ea61a7ea | 11140 | |
d9f6a4ee | 11141 | -- Check choices |
ea61a7ea | 11142 | |
d9f6a4ee | 11143 | Check_Choices |
11144 | (VP, Variants (VP), Etype (Name (VP)), Others_Present); | |
ea61a7ea | 11145 | |
d9f6a4ee | 11146 | -- If the last variant does not contain the Others choice, |
11147 | -- replace it with an N_Others_Choice node since Gigi always | |
11148 | -- wants an Others. Note that we do not bother to call Analyze | |
11149 | -- on the modified variant part, since its only effect would be | |
11150 | -- to compute the Others_Discrete_Choices node laboriously, and | |
11151 | -- of course we already know the list of choices corresponding | |
39a0c1d3 | 11152 | -- to the others choice (it's the list we're replacing). |
d6f39728 | 11153 | |
d9f6a4ee | 11154 | -- We only want to do this if the expander is active, since |
39a0c1d3 | 11155 | -- we do not want to clobber the ASIS tree. |
d6f39728 | 11156 | |
d9f6a4ee | 11157 | if Expander_Active then |
11158 | declare | |
11159 | Last_Var : constant Node_Id := | |
11160 | Last_Non_Pragma (Variants (VP)); | |
d6f39728 | 11161 | |
d9f6a4ee | 11162 | Others_Node : Node_Id; |
d6f39728 | 11163 | |
d9f6a4ee | 11164 | begin |
11165 | if Nkind (First (Discrete_Choices (Last_Var))) /= | |
11166 | N_Others_Choice | |
11167 | then | |
11168 | Others_Node := Make_Others_Choice (Sloc (Last_Var)); | |
11169 | Set_Others_Discrete_Choices | |
11170 | (Others_Node, Discrete_Choices (Last_Var)); | |
11171 | Set_Discrete_Choices | |
11172 | (Last_Var, New_List (Others_Node)); | |
11173 | end if; | |
11174 | end; | |
11175 | end if; | |
d6f39728 | 11176 | end if; |
d9f6a4ee | 11177 | end Check_Variant_Part; |
d6f39728 | 11178 | end if; |
d9f6a4ee | 11179 | end Freeze_Entity_Checks; |
d6f39728 | 11180 | |
11181 | ------------------------- | |
11182 | -- Get_Alignment_Value -- | |
11183 | ------------------------- | |
11184 | ||
11185 | function Get_Alignment_Value (Expr : Node_Id) return Uint is | |
11186 | Align : constant Uint := Static_Integer (Expr); | |
11187 | ||
11188 | begin | |
11189 | if Align = No_Uint then | |
11190 | return No_Uint; | |
11191 | ||
11192 | elsif Align <= 0 then | |
11193 | Error_Msg_N ("alignment value must be positive", Expr); | |
11194 | return No_Uint; | |
11195 | ||
11196 | else | |
11197 | for J in Int range 0 .. 64 loop | |
11198 | declare | |
11199 | M : constant Uint := Uint_2 ** J; | |
11200 | ||
11201 | begin | |
11202 | exit when M = Align; | |
11203 | ||
11204 | if M > Align then | |
11205 | Error_Msg_N | |
11206 | ("alignment value must be power of 2", Expr); | |
11207 | return No_Uint; | |
11208 | end if; | |
11209 | end; | |
11210 | end loop; | |
11211 | ||
11212 | return Align; | |
11213 | end if; | |
11214 | end Get_Alignment_Value; | |
11215 | ||
99a2d5bd | 11216 | ------------------------------------- |
11217 | -- Inherit_Aspects_At_Freeze_Point -- | |
11218 | ------------------------------------- | |
11219 | ||
11220 | procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is | |
11221 | function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11222 | (Rep_Item : Node_Id) return Boolean; | |
11223 | -- This routine checks if Rep_Item is either a pragma or an aspect | |
11224 | -- specification node whose correponding pragma (if any) is present in | |
11225 | -- the Rep Item chain of the entity it has been specified to. | |
11226 | ||
11227 | -------------------------------------------------- | |
11228 | -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item -- | |
11229 | -------------------------------------------------- | |
11230 | ||
11231 | function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11232 | (Rep_Item : Node_Id) return Boolean | |
11233 | is | |
11234 | begin | |
ec6f6da5 | 11235 | return |
11236 | Nkind (Rep_Item) = N_Pragma | |
11237 | or else Present_In_Rep_Item | |
11238 | (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item)); | |
99a2d5bd | 11239 | end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item; |
11240 | ||
29a9d4be | 11241 | -- Start of processing for Inherit_Aspects_At_Freeze_Point |
11242 | ||
99a2d5bd | 11243 | begin |
11244 | -- A representation item is either subtype-specific (Size and Alignment | |
11245 | -- clauses) or type-related (all others). Subtype-specific aspects may | |
29a9d4be | 11246 | -- differ for different subtypes of the same type (RM 13.1.8). |
99a2d5bd | 11247 | |
11248 | -- A derived type inherits each type-related representation aspect of | |
11249 | -- its parent type that was directly specified before the declaration of | |
29a9d4be | 11250 | -- the derived type (RM 13.1.15). |
99a2d5bd | 11251 | |
11252 | -- A derived subtype inherits each subtype-specific representation | |
11253 | -- aspect of its parent subtype that was directly specified before the | |
29a9d4be | 11254 | -- declaration of the derived type (RM 13.1.15). |
99a2d5bd | 11255 | |
11256 | -- The general processing involves inheriting a representation aspect | |
11257 | -- from a parent type whenever the first rep item (aspect specification, | |
11258 | -- attribute definition clause, pragma) corresponding to the given | |
11259 | -- representation aspect in the rep item chain of Typ, if any, isn't | |
11260 | -- directly specified to Typ but to one of its parents. | |
11261 | ||
11262 | -- ??? Note that, for now, just a limited number of representation | |
29a9d4be | 11263 | -- aspects have been inherited here so far. Many of them are |
11264 | -- still inherited in Sem_Ch3. This will be fixed soon. Here is | |
11265 | -- a non- exhaustive list of aspects that likely also need to | |
11266 | -- be moved to this routine: Alignment, Component_Alignment, | |
11267 | -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates, | |
99a2d5bd | 11268 | -- Preelaborable_Initialization, RM_Size and Small. |
11269 | ||
8b6e9bf2 | 11270 | -- In addition, Convention must be propagated from base type to subtype, |
11271 | -- because the subtype may have been declared on an incomplete view. | |
11272 | ||
99a2d5bd | 11273 | if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then |
11274 | return; | |
11275 | end if; | |
11276 | ||
11277 | -- Ada_05/Ada_2005 | |
11278 | ||
11279 | if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False) | |
11280 | and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005) | |
11281 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11282 | (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)) | |
11283 | then | |
11284 | Set_Is_Ada_2005_Only (Typ); | |
11285 | end if; | |
11286 | ||
11287 | -- Ada_12/Ada_2012 | |
11288 | ||
11289 | if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False) | |
11290 | and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012) | |
11291 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11292 | (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)) | |
11293 | then | |
11294 | Set_Is_Ada_2012_Only (Typ); | |
11295 | end if; | |
11296 | ||
11297 | -- Atomic/Shared | |
11298 | ||
11299 | if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False) | |
11300 | and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared) | |
11301 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11302 | (Get_Rep_Item (Typ, Name_Atomic, Name_Shared)) | |
11303 | then | |
11304 | Set_Is_Atomic (Typ); | |
99a2d5bd | 11305 | Set_Is_Volatile (Typ); |
4bf2acc9 | 11306 | Set_Treat_As_Volatile (Typ); |
99a2d5bd | 11307 | end if; |
11308 | ||
8b6e9bf2 | 11309 | -- Convention |
11310 | ||
7ac4254e | 11311 | if Is_Record_Type (Typ) |
11312 | and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ)) | |
11313 | then | |
8b6e9bf2 | 11314 | Set_Convention (Typ, Convention (Base_Type (Typ))); |
11315 | end if; | |
11316 | ||
29a9d4be | 11317 | -- Default_Component_Value |
99a2d5bd | 11318 | |
81c2bc19 | 11319 | -- Verify that there is no rep_item declared for the type, and there |
11320 | -- is one coming from an ancestor. | |
11321 | ||
99a2d5bd | 11322 | if Is_Array_Type (Typ) |
f3d70f08 | 11323 | and then Is_Base_Type (Typ) |
81c2bc19 | 11324 | and then not Has_Rep_Item (Typ, Name_Default_Component_Value, False) |
99a2d5bd | 11325 | and then Has_Rep_Item (Typ, Name_Default_Component_Value) |
11326 | then | |
11327 | Set_Default_Aspect_Component_Value (Typ, | |
11328 | Default_Aspect_Component_Value | |
11329 | (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value)))); | |
11330 | end if; | |
11331 | ||
29a9d4be | 11332 | -- Default_Value |
99a2d5bd | 11333 | |
11334 | if Is_Scalar_Type (Typ) | |
f3d70f08 | 11335 | and then Is_Base_Type (Typ) |
81c2bc19 | 11336 | and then not Has_Rep_Item (Typ, Name_Default_Value, False) |
99a2d5bd | 11337 | and then Has_Rep_Item (Typ, Name_Default_Value) |
11338 | then | |
81c2bc19 | 11339 | Set_Has_Default_Aspect (Typ); |
99a2d5bd | 11340 | Set_Default_Aspect_Value (Typ, |
11341 | Default_Aspect_Value | |
11342 | (Entity (Get_Rep_Item (Typ, Name_Default_Value)))); | |
11343 | end if; | |
11344 | ||
11345 | -- Discard_Names | |
11346 | ||
11347 | if not Has_Rep_Item (Typ, Name_Discard_Names, False) | |
11348 | and then Has_Rep_Item (Typ, Name_Discard_Names) | |
11349 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11350 | (Get_Rep_Item (Typ, Name_Discard_Names)) | |
11351 | then | |
11352 | Set_Discard_Names (Typ); | |
11353 | end if; | |
11354 | ||
11355 | -- Invariants | |
11356 | ||
11357 | if not Has_Rep_Item (Typ, Name_Invariant, False) | |
11358 | and then Has_Rep_Item (Typ, Name_Invariant) | |
11359 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11360 | (Get_Rep_Item (Typ, Name_Invariant)) | |
11361 | then | |
11362 | Set_Has_Invariants (Typ); | |
11363 | ||
11364 | if Class_Present (Get_Rep_Item (Typ, Name_Invariant)) then | |
11365 | Set_Has_Inheritable_Invariants (Typ); | |
11366 | end if; | |
d7487d7d | 11367 | |
953378ae | 11368 | -- If we have a subtype with invariants, whose base type does not have |
11369 | -- invariants, copy these invariants to the base type. This happens for | |
11370 | -- the case of implicit base types created for scalar and array types. | |
d7487d7d | 11371 | |
953378ae | 11372 | elsif Has_Invariants (Typ) |
d7487d7d | 11373 | and then not Has_Invariants (Base_Type (Typ)) |
11374 | then | |
11375 | Set_Has_Invariants (Base_Type (Typ)); | |
11376 | Set_Invariant_Procedure (Base_Type (Typ), Invariant_Procedure (Typ)); | |
99a2d5bd | 11377 | end if; |
11378 | ||
11379 | -- Volatile | |
11380 | ||
11381 | if not Has_Rep_Item (Typ, Name_Volatile, False) | |
11382 | and then Has_Rep_Item (Typ, Name_Volatile) | |
11383 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11384 | (Get_Rep_Item (Typ, Name_Volatile)) | |
11385 | then | |
99a2d5bd | 11386 | Set_Is_Volatile (Typ); |
4bf2acc9 | 11387 | Set_Treat_As_Volatile (Typ); |
99a2d5bd | 11388 | end if; |
11389 | ||
2fe893b9 | 11390 | -- Volatile_Full_Access |
11391 | ||
11392 | if not Has_Rep_Item (Typ, Name_Volatile_Full_Access, False) | |
11393 | and then Has_Rep_Pragma (Typ, Name_Volatile_Full_Access) | |
11394 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11395 | (Get_Rep_Item (Typ, Name_Volatile_Full_Access)) | |
11396 | then | |
4bf2acc9 | 11397 | Set_Is_Volatile_Full_Access (Typ); |
2fe893b9 | 11398 | Set_Is_Volatile (Typ); |
4bf2acc9 | 11399 | Set_Treat_As_Volatile (Typ); |
2fe893b9 | 11400 | end if; |
11401 | ||
99a2d5bd | 11402 | -- Inheritance for derived types only |
11403 | ||
11404 | if Is_Derived_Type (Typ) then | |
11405 | declare | |
11406 | Bas_Typ : constant Entity_Id := Base_Type (Typ); | |
11407 | Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ); | |
11408 | ||
11409 | begin | |
11410 | -- Atomic_Components | |
11411 | ||
11412 | if not Has_Rep_Item (Typ, Name_Atomic_Components, False) | |
11413 | and then Has_Rep_Item (Typ, Name_Atomic_Components) | |
11414 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11415 | (Get_Rep_Item (Typ, Name_Atomic_Components)) | |
11416 | then | |
11417 | Set_Has_Atomic_Components (Imp_Bas_Typ); | |
11418 | end if; | |
11419 | ||
11420 | -- Volatile_Components | |
11421 | ||
11422 | if not Has_Rep_Item (Typ, Name_Volatile_Components, False) | |
11423 | and then Has_Rep_Item (Typ, Name_Volatile_Components) | |
11424 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11425 | (Get_Rep_Item (Typ, Name_Volatile_Components)) | |
11426 | then | |
11427 | Set_Has_Volatile_Components (Imp_Bas_Typ); | |
11428 | end if; | |
11429 | ||
e81df51c | 11430 | -- Finalize_Storage_Only |
99a2d5bd | 11431 | |
11432 | if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False) | |
11433 | and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only) | |
11434 | then | |
11435 | Set_Finalize_Storage_Only (Bas_Typ); | |
11436 | end if; | |
11437 | ||
11438 | -- Universal_Aliasing | |
11439 | ||
11440 | if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False) | |
11441 | and then Has_Rep_Item (Typ, Name_Universal_Aliasing) | |
11442 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11443 | (Get_Rep_Item (Typ, Name_Universal_Aliasing)) | |
11444 | then | |
11445 | Set_Universal_Aliasing (Imp_Bas_Typ); | |
11446 | end if; | |
11447 | ||
e81df51c | 11448 | -- Bit_Order |
99a2d5bd | 11449 | |
11450 | if Is_Record_Type (Typ) then | |
99a2d5bd | 11451 | if not Has_Rep_Item (Typ, Name_Bit_Order, False) |
11452 | and then Has_Rep_Item (Typ, Name_Bit_Order) | |
11453 | then | |
11454 | Set_Reverse_Bit_Order (Bas_Typ, | |
11455 | Reverse_Bit_Order (Entity (Name | |
11456 | (Get_Rep_Item (Typ, Name_Bit_Order))))); | |
11457 | end if; | |
e81df51c | 11458 | end if; |
11459 | ||
e9218716 | 11460 | -- Scalar_Storage_Order |
11461 | ||
11462 | -- Note: the aspect is specified on a first subtype, but recorded | |
11463 | -- in a flag of the base type! | |
e81df51c | 11464 | |
11465 | if (Is_Record_Type (Typ) or else Is_Array_Type (Typ)) | |
29b91bc7 | 11466 | and then Typ = Bas_Typ |
e81df51c | 11467 | then |
e81df51c | 11468 | -- For a type extension, always inherit from parent; otherwise |
11469 | -- inherit if no default applies. Note: we do not check for | |
11470 | -- an explicit rep item on the parent type when inheriting, | |
11471 | -- because the parent SSO may itself have been set by default. | |
99a2d5bd | 11472 | |
e9218716 | 11473 | if not Has_Rep_Item (First_Subtype (Typ), |
11474 | Name_Scalar_Storage_Order, False) | |
e81df51c | 11475 | and then (Is_Tagged_Type (Bas_Typ) |
29b91bc7 | 11476 | or else not (SSO_Set_Low_By_Default (Bas_Typ) |
11477 | or else | |
11478 | SSO_Set_High_By_Default (Bas_Typ))) | |
99a2d5bd | 11479 | then |
11480 | Set_Reverse_Storage_Order (Bas_Typ, | |
423b89fd | 11481 | Reverse_Storage_Order |
11482 | (Implementation_Base_Type (Etype (Bas_Typ)))); | |
b64082f2 | 11483 | |
11484 | -- Clear default SSO indications, since the inherited aspect | |
11485 | -- which was set explicitly overrides the default. | |
11486 | ||
11487 | Set_SSO_Set_Low_By_Default (Bas_Typ, False); | |
11488 | Set_SSO_Set_High_By_Default (Bas_Typ, False); | |
99a2d5bd | 11489 | end if; |
11490 | end if; | |
11491 | end; | |
11492 | end if; | |
11493 | end Inherit_Aspects_At_Freeze_Point; | |
11494 | ||
d6f39728 | 11495 | ---------------- |
11496 | -- Initialize -- | |
11497 | ---------------- | |
11498 | ||
11499 | procedure Initialize is | |
11500 | begin | |
7717ea00 | 11501 | Address_Clause_Checks.Init; |
d6f39728 | 11502 | Unchecked_Conversions.Init; |
dba38d2f | 11503 | |
36ac5fbb | 11504 | if AAMP_On_Target then |
dba38d2f | 11505 | Independence_Checks.Init; |
11506 | end if; | |
d6f39728 | 11507 | end Initialize; |
11508 | ||
2625eb01 | 11509 | --------------------------- |
11510 | -- Install_Discriminants -- | |
11511 | --------------------------- | |
11512 | ||
11513 | procedure Install_Discriminants (E : Entity_Id) is | |
11514 | Disc : Entity_Id; | |
11515 | Prev : Entity_Id; | |
11516 | begin | |
11517 | Disc := First_Discriminant (E); | |
11518 | while Present (Disc) loop | |
11519 | Prev := Current_Entity (Disc); | |
11520 | Set_Current_Entity (Disc); | |
11521 | Set_Is_Immediately_Visible (Disc); | |
11522 | Set_Homonym (Disc, Prev); | |
11523 | Next_Discriminant (Disc); | |
11524 | end loop; | |
11525 | end Install_Discriminants; | |
11526 | ||
d6f39728 | 11527 | ------------------------- |
11528 | -- Is_Operational_Item -- | |
11529 | ------------------------- | |
11530 | ||
11531 | function Is_Operational_Item (N : Node_Id) return Boolean is | |
11532 | begin | |
11533 | if Nkind (N) /= N_Attribute_Definition_Clause then | |
11534 | return False; | |
b9e61b2a | 11535 | |
d6f39728 | 11536 | else |
11537 | declare | |
b9e61b2a | 11538 | Id : constant Attribute_Id := Get_Attribute_Id (Chars (N)); |
d6f39728 | 11539 | begin |
078a74b8 | 11540 | |
55ab5265 | 11541 | -- List of operational items is given in AARM 13.1(8.mm/1). |
078a74b8 | 11542 | -- It is clearly incomplete, as it does not include iterator |
11543 | -- aspects, among others. | |
11544 | ||
11545 | return Id = Attribute_Constant_Indexing | |
11546 | or else Id = Attribute_Default_Iterator | |
11547 | or else Id = Attribute_Implicit_Dereference | |
11548 | or else Id = Attribute_Input | |
11549 | or else Id = Attribute_Iterator_Element | |
11550 | or else Id = Attribute_Iterable | |
d6f39728 | 11551 | or else Id = Attribute_Output |
11552 | or else Id = Attribute_Read | |
078a74b8 | 11553 | or else Id = Attribute_Variable_Indexing |
f15731c4 | 11554 | or else Id = Attribute_Write |
11555 | or else Id = Attribute_External_Tag; | |
d6f39728 | 11556 | end; |
11557 | end if; | |
11558 | end Is_Operational_Item; | |
11559 | ||
3b23aaa0 | 11560 | ------------------------- |
11561 | -- Is_Predicate_Static -- | |
11562 | ------------------------- | |
11563 | ||
94d896aa | 11564 | -- Note: the basic legality of the expression has already been checked, so |
11565 | -- we don't need to worry about cases or ranges on strings for example. | |
11566 | ||
3b23aaa0 | 11567 | function Is_Predicate_Static |
11568 | (Expr : Node_Id; | |
11569 | Nam : Name_Id) return Boolean | |
11570 | is | |
11571 | function All_Static_Case_Alternatives (L : List_Id) return Boolean; | |
973c2fba | 11572 | -- Given a list of case expression alternatives, returns True if all |
11573 | -- the alternatives are static (have all static choices, and a static | |
11574 | -- expression). | |
3b23aaa0 | 11575 | |
11576 | function All_Static_Choices (L : List_Id) return Boolean; | |
a360a0f7 | 11577 | -- Returns true if all elements of the list are OK static choices |
3b23aaa0 | 11578 | -- as defined below for Is_Static_Choice. Used for case expression |
973c2fba | 11579 | -- alternatives and for the right operand of a membership test. An |
11580 | -- others_choice is static if the corresponding expression is static. | |
7c0c95b8 | 11581 | -- The staticness of the bounds is checked separately. |
3b23aaa0 | 11582 | |
11583 | function Is_Static_Choice (N : Node_Id) return Boolean; | |
11584 | -- Returns True if N represents a static choice (static subtype, or | |
a360a0f7 | 11585 | -- static subtype indication, or static expression, or static range). |
3b23aaa0 | 11586 | -- |
11587 | -- Note that this is a bit more inclusive than we actually need | |
11588 | -- (in particular membership tests do not allow the use of subtype | |
a360a0f7 | 11589 | -- indications). But that doesn't matter, we have already checked |
3b23aaa0 | 11590 | -- that the construct is legal to get this far. |
11591 | ||
11592 | function Is_Type_Ref (N : Node_Id) return Boolean; | |
11593 | pragma Inline (Is_Type_Ref); | |
973c2fba | 11594 | -- Returns True if N is a reference to the type for the predicate in the |
11595 | -- expression (i.e. if it is an identifier whose Chars field matches the | |
11596 | -- Nam given in the call). N must not be parenthesized, if the type name | |
11597 | -- appears in parens, this routine will return False. | |
3b23aaa0 | 11598 | |
11599 | ---------------------------------- | |
11600 | -- All_Static_Case_Alternatives -- | |
11601 | ---------------------------------- | |
11602 | ||
11603 | function All_Static_Case_Alternatives (L : List_Id) return Boolean is | |
11604 | N : Node_Id; | |
11605 | ||
11606 | begin | |
11607 | N := First (L); | |
11608 | while Present (N) loop | |
11609 | if not (All_Static_Choices (Discrete_Choices (N)) | |
11610 | and then Is_OK_Static_Expression (Expression (N))) | |
11611 | then | |
11612 | return False; | |
11613 | end if; | |
11614 | ||
11615 | Next (N); | |
11616 | end loop; | |
11617 | ||
11618 | return True; | |
11619 | end All_Static_Case_Alternatives; | |
11620 | ||
11621 | ------------------------ | |
11622 | -- All_Static_Choices -- | |
11623 | ------------------------ | |
11624 | ||
11625 | function All_Static_Choices (L : List_Id) return Boolean is | |
11626 | N : Node_Id; | |
11627 | ||
11628 | begin | |
11629 | N := First (L); | |
11630 | while Present (N) loop | |
11631 | if not Is_Static_Choice (N) then | |
11632 | return False; | |
11633 | end if; | |
11634 | ||
11635 | Next (N); | |
11636 | end loop; | |
11637 | ||
11638 | return True; | |
11639 | end All_Static_Choices; | |
11640 | ||
11641 | ---------------------- | |
11642 | -- Is_Static_Choice -- | |
11643 | ---------------------- | |
11644 | ||
11645 | function Is_Static_Choice (N : Node_Id) return Boolean is | |
11646 | begin | |
7c0c95b8 | 11647 | return Nkind (N) = N_Others_Choice |
11648 | or else Is_OK_Static_Expression (N) | |
3b23aaa0 | 11649 | or else (Is_Entity_Name (N) and then Is_Type (Entity (N)) |
11650 | and then Is_OK_Static_Subtype (Entity (N))) | |
11651 | or else (Nkind (N) = N_Subtype_Indication | |
11652 | and then Is_OK_Static_Subtype (Entity (N))) | |
11653 | or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N)); | |
11654 | end Is_Static_Choice; | |
11655 | ||
11656 | ----------------- | |
11657 | -- Is_Type_Ref -- | |
11658 | ----------------- | |
11659 | ||
11660 | function Is_Type_Ref (N : Node_Id) return Boolean is | |
11661 | begin | |
11662 | return Nkind (N) = N_Identifier | |
11663 | and then Chars (N) = Nam | |
11664 | and then Paren_Count (N) = 0; | |
11665 | end Is_Type_Ref; | |
11666 | ||
11667 | -- Start of processing for Is_Predicate_Static | |
11668 | ||
11669 | begin | |
3b23aaa0 | 11670 | -- Predicate_Static means one of the following holds. Numbers are the |
11671 | -- corresponding paragraph numbers in (RM 3.2.4(16-22)). | |
11672 | ||
11673 | -- 16: A static expression | |
11674 | ||
11675 | if Is_OK_Static_Expression (Expr) then | |
11676 | return True; | |
11677 | ||
11678 | -- 17: A membership test whose simple_expression is the current | |
11679 | -- instance, and whose membership_choice_list meets the requirements | |
11680 | -- for a static membership test. | |
11681 | ||
11682 | elsif Nkind (Expr) in N_Membership_Test | |
11683 | and then ((Present (Right_Opnd (Expr)) | |
11684 | and then Is_Static_Choice (Right_Opnd (Expr))) | |
11685 | or else | |
11686 | (Present (Alternatives (Expr)) | |
11687 | and then All_Static_Choices (Alternatives (Expr)))) | |
11688 | then | |
11689 | return True; | |
11690 | ||
11691 | -- 18. A case_expression whose selecting_expression is the current | |
11692 | -- instance, and whose dependent expressions are static expressions. | |
11693 | ||
11694 | elsif Nkind (Expr) = N_Case_Expression | |
11695 | and then Is_Type_Ref (Expression (Expr)) | |
11696 | and then All_Static_Case_Alternatives (Alternatives (Expr)) | |
11697 | then | |
11698 | return True; | |
11699 | ||
11700 | -- 19. A call to a predefined equality or ordering operator, where one | |
11701 | -- operand is the current instance, and the other is a static | |
11702 | -- expression. | |
11703 | ||
94d896aa | 11704 | -- Note: the RM is clearly wrong here in not excluding string types. |
11705 | -- Without this exclusion, we would allow expressions like X > "ABC" | |
11706 | -- to be considered as predicate-static, which is clearly not intended, | |
11707 | -- since the idea is for predicate-static to be a subset of normal | |
11708 | -- static expressions (and "DEF" > "ABC" is not a static expression). | |
11709 | ||
11710 | -- However, we do allow internally generated (not from source) equality | |
11711 | -- and inequality operations to be valid on strings (this helps deal | |
11712 | -- with cases where we transform A in "ABC" to A = "ABC). | |
11713 | ||
3b23aaa0 | 11714 | elsif Nkind (Expr) in N_Op_Compare |
94d896aa | 11715 | and then ((not Is_String_Type (Etype (Left_Opnd (Expr)))) |
11716 | or else (Nkind_In (Expr, N_Op_Eq, N_Op_Ne) | |
11717 | and then not Comes_From_Source (Expr))) | |
3b23aaa0 | 11718 | and then ((Is_Type_Ref (Left_Opnd (Expr)) |
11719 | and then Is_OK_Static_Expression (Right_Opnd (Expr))) | |
11720 | or else | |
11721 | (Is_Type_Ref (Right_Opnd (Expr)) | |
11722 | and then Is_OK_Static_Expression (Left_Opnd (Expr)))) | |
11723 | then | |
11724 | return True; | |
11725 | ||
11726 | -- 20. A call to a predefined boolean logical operator, where each | |
11727 | -- operand is predicate-static. | |
11728 | ||
11729 | elsif (Nkind_In (Expr, N_Op_And, N_Op_Or, N_Op_Xor) | |
11730 | and then Is_Predicate_Static (Left_Opnd (Expr), Nam) | |
11731 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam)) | |
11732 | or else | |
11733 | (Nkind (Expr) = N_Op_Not | |
11734 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam)) | |
11735 | then | |
11736 | return True; | |
11737 | ||
11738 | -- 21. A short-circuit control form where both operands are | |
11739 | -- predicate-static. | |
11740 | ||
11741 | elsif Nkind (Expr) in N_Short_Circuit | |
11742 | and then Is_Predicate_Static (Left_Opnd (Expr), Nam) | |
11743 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam) | |
11744 | then | |
11745 | return True; | |
11746 | ||
11747 | -- 22. A parenthesized predicate-static expression. This does not | |
11748 | -- require any special test, since we just ignore paren levels in | |
11749 | -- all the cases above. | |
11750 | ||
11751 | -- One more test that is an implementation artifact caused by the fact | |
499918a7 | 11752 | -- that we are analyzing not the original expression, but the generated |
3b23aaa0 | 11753 | -- expression in the body of the predicate function. This can include |
a360a0f7 | 11754 | -- references to inherited predicates, so that the expression we are |
3b23aaa0 | 11755 | -- processing looks like: |
11756 | ||
11757 | -- expression and then xxPredicate (typ (Inns)) | |
11758 | ||
11759 | -- Where the call is to a Predicate function for an inherited predicate. | |
60a4a5af | 11760 | -- We simply ignore such a call, which could be to either a dynamic or |
11761 | -- a static predicate. Note that if the parent predicate is dynamic then | |
11762 | -- eventually this type will be marked as dynamic, but you are allowed | |
11763 | -- to specify a static predicate for a subtype which is inheriting a | |
11764 | -- dynamic predicate, so the static predicate validation here ignores | |
11765 | -- the inherited predicate even if it is dynamic. | |
3b23aaa0 | 11766 | |
11767 | elsif Nkind (Expr) = N_Function_Call | |
11768 | and then Is_Predicate_Function (Entity (Name (Expr))) | |
11769 | then | |
11770 | return True; | |
11771 | ||
11772 | -- That's an exhaustive list of tests, all other cases are not | |
a360a0f7 | 11773 | -- predicate-static, so we return False. |
3b23aaa0 | 11774 | |
11775 | else | |
11776 | return False; | |
11777 | end if; | |
11778 | end Is_Predicate_Static; | |
11779 | ||
2ff55065 | 11780 | --------------------- |
11781 | -- Kill_Rep_Clause -- | |
11782 | --------------------- | |
11783 | ||
11784 | procedure Kill_Rep_Clause (N : Node_Id) is | |
11785 | begin | |
11786 | pragma Assert (Ignore_Rep_Clauses); | |
360f426f | 11787 | |
11788 | -- Note: we use Replace rather than Rewrite, because we don't want | |
11789 | -- ASIS to be able to use Original_Node to dig out the (undecorated) | |
11790 | -- rep clause that is being replaced. | |
11791 | ||
4949ddd5 | 11792 | Replace (N, Make_Null_Statement (Sloc (N))); |
360f426f | 11793 | |
11794 | -- The null statement must be marked as not coming from source. This is | |
37c6552c | 11795 | -- so that ASIS ignores it, and also the back end does not expect bogus |
360f426f | 11796 | -- "from source" null statements in weird places (e.g. in declarative |
11797 | -- regions where such null statements are not allowed). | |
11798 | ||
11799 | Set_Comes_From_Source (N, False); | |
2ff55065 | 11800 | end Kill_Rep_Clause; |
11801 | ||
d6f39728 | 11802 | ------------------ |
11803 | -- Minimum_Size -- | |
11804 | ------------------ | |
11805 | ||
11806 | function Minimum_Size | |
11807 | (T : Entity_Id; | |
d5b349fa | 11808 | Biased : Boolean := False) return Nat |
d6f39728 | 11809 | is |
11810 | Lo : Uint := No_Uint; | |
11811 | Hi : Uint := No_Uint; | |
11812 | LoR : Ureal := No_Ureal; | |
11813 | HiR : Ureal := No_Ureal; | |
11814 | LoSet : Boolean := False; | |
11815 | HiSet : Boolean := False; | |
11816 | B : Uint; | |
11817 | S : Nat; | |
11818 | Ancest : Entity_Id; | |
f15731c4 | 11819 | R_Typ : constant Entity_Id := Root_Type (T); |
d6f39728 | 11820 | |
11821 | begin | |
11822 | -- If bad type, return 0 | |
11823 | ||
11824 | if T = Any_Type then | |
11825 | return 0; | |
11826 | ||
11827 | -- For generic types, just return zero. There cannot be any legitimate | |
11828 | -- need to know such a size, but this routine may be called with a | |
11829 | -- generic type as part of normal processing. | |
11830 | ||
f02a9a9a | 11831 | elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then |
d6f39728 | 11832 | return 0; |
11833 | ||
74c7ae52 | 11834 | -- Access types (cannot have size smaller than System.Address) |
d6f39728 | 11835 | |
11836 | elsif Is_Access_Type (T) then | |
74c7ae52 | 11837 | return System_Address_Size; |
d6f39728 | 11838 | |
11839 | -- Floating-point types | |
11840 | ||
11841 | elsif Is_Floating_Point_Type (T) then | |
f15731c4 | 11842 | return UI_To_Int (Esize (R_Typ)); |
d6f39728 | 11843 | |
11844 | -- Discrete types | |
11845 | ||
11846 | elsif Is_Discrete_Type (T) then | |
11847 | ||
fdd294d1 | 11848 | -- The following loop is looking for the nearest compile time known |
11849 | -- bounds following the ancestor subtype chain. The idea is to find | |
11850 | -- the most restrictive known bounds information. | |
d6f39728 | 11851 | |
11852 | Ancest := T; | |
11853 | loop | |
11854 | if Ancest = Any_Type or else Etype (Ancest) = Any_Type then | |
11855 | return 0; | |
11856 | end if; | |
11857 | ||
11858 | if not LoSet then | |
11859 | if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then | |
11860 | Lo := Expr_Rep_Value (Type_Low_Bound (Ancest)); | |
11861 | LoSet := True; | |
11862 | exit when HiSet; | |
11863 | end if; | |
11864 | end if; | |
11865 | ||
11866 | if not HiSet then | |
11867 | if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then | |
11868 | Hi := Expr_Rep_Value (Type_High_Bound (Ancest)); | |
11869 | HiSet := True; | |
11870 | exit when LoSet; | |
11871 | end if; | |
11872 | end if; | |
11873 | ||
11874 | Ancest := Ancestor_Subtype (Ancest); | |
11875 | ||
11876 | if No (Ancest) then | |
11877 | Ancest := Base_Type (T); | |
11878 | ||
11879 | if Is_Generic_Type (Ancest) then | |
11880 | return 0; | |
11881 | end if; | |
11882 | end if; | |
11883 | end loop; | |
11884 | ||
11885 | -- Fixed-point types. We can't simply use Expr_Value to get the | |
fdd294d1 | 11886 | -- Corresponding_Integer_Value values of the bounds, since these do not |
11887 | -- get set till the type is frozen, and this routine can be called | |
11888 | -- before the type is frozen. Similarly the test for bounds being static | |
11889 | -- needs to include the case where we have unanalyzed real literals for | |
11890 | -- the same reason. | |
d6f39728 | 11891 | |
11892 | elsif Is_Fixed_Point_Type (T) then | |
11893 | ||
fdd294d1 | 11894 | -- The following loop is looking for the nearest compile time known |
11895 | -- bounds following the ancestor subtype chain. The idea is to find | |
11896 | -- the most restrictive known bounds information. | |
d6f39728 | 11897 | |
11898 | Ancest := T; | |
11899 | loop | |
11900 | if Ancest = Any_Type or else Etype (Ancest) = Any_Type then | |
11901 | return 0; | |
11902 | end if; | |
11903 | ||
3062c401 | 11904 | -- Note: In the following two tests for LoSet and HiSet, it may |
11905 | -- seem redundant to test for N_Real_Literal here since normally | |
11906 | -- one would assume that the test for the value being known at | |
11907 | -- compile time includes this case. However, there is a glitch. | |
11908 | -- If the real literal comes from folding a non-static expression, | |
11909 | -- then we don't consider any non- static expression to be known | |
11910 | -- at compile time if we are in configurable run time mode (needed | |
11911 | -- in some cases to give a clearer definition of what is and what | |
11912 | -- is not accepted). So the test is indeed needed. Without it, we | |
11913 | -- would set neither Lo_Set nor Hi_Set and get an infinite loop. | |
11914 | ||
d6f39728 | 11915 | if not LoSet then |
11916 | if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal | |
11917 | or else Compile_Time_Known_Value (Type_Low_Bound (Ancest)) | |
11918 | then | |
11919 | LoR := Expr_Value_R (Type_Low_Bound (Ancest)); | |
11920 | LoSet := True; | |
11921 | exit when HiSet; | |
11922 | end if; | |
11923 | end if; | |
11924 | ||
11925 | if not HiSet then | |
11926 | if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal | |
11927 | or else Compile_Time_Known_Value (Type_High_Bound (Ancest)) | |
11928 | then | |
11929 | HiR := Expr_Value_R (Type_High_Bound (Ancest)); | |
11930 | HiSet := True; | |
11931 | exit when LoSet; | |
11932 | end if; | |
11933 | end if; | |
11934 | ||
11935 | Ancest := Ancestor_Subtype (Ancest); | |
11936 | ||
11937 | if No (Ancest) then | |
11938 | Ancest := Base_Type (T); | |
11939 | ||
11940 | if Is_Generic_Type (Ancest) then | |
11941 | return 0; | |
11942 | end if; | |
11943 | end if; | |
11944 | end loop; | |
11945 | ||
11946 | Lo := UR_To_Uint (LoR / Small_Value (T)); | |
11947 | Hi := UR_To_Uint (HiR / Small_Value (T)); | |
11948 | ||
11949 | -- No other types allowed | |
11950 | ||
11951 | else | |
11952 | raise Program_Error; | |
11953 | end if; | |
11954 | ||
2866d595 | 11955 | -- Fall through with Hi and Lo set. Deal with biased case |
d6f39728 | 11956 | |
cc46ff4b | 11957 | if (Biased |
11958 | and then not Is_Fixed_Point_Type (T) | |
11959 | and then not (Is_Enumeration_Type (T) | |
11960 | and then Has_Non_Standard_Rep (T))) | |
d6f39728 | 11961 | or else Has_Biased_Representation (T) |
11962 | then | |
11963 | Hi := Hi - Lo; | |
11964 | Lo := Uint_0; | |
11965 | end if; | |
11966 | ||
005366f7 | 11967 | -- Null range case, size is always zero. We only do this in the discrete |
11968 | -- type case, since that's the odd case that came up. Probably we should | |
11969 | -- also do this in the fixed-point case, but doing so causes peculiar | |
11970 | -- gigi failures, and it is not worth worrying about this incredibly | |
11971 | -- marginal case (explicit null-range fixed-point type declarations)??? | |
11972 | ||
11973 | if Lo > Hi and then Is_Discrete_Type (T) then | |
11974 | S := 0; | |
11975 | ||
d6f39728 | 11976 | -- Signed case. Note that we consider types like range 1 .. -1 to be |
fdd294d1 | 11977 | -- signed for the purpose of computing the size, since the bounds have |
1a34e48c | 11978 | -- to be accommodated in the base type. |
d6f39728 | 11979 | |
005366f7 | 11980 | elsif Lo < 0 or else Hi < 0 then |
d6f39728 | 11981 | S := 1; |
11982 | B := Uint_1; | |
11983 | ||
da253936 | 11984 | -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1)) |
11985 | -- Note that we accommodate the case where the bounds cross. This | |
d6f39728 | 11986 | -- can happen either because of the way the bounds are declared |
11987 | -- or because of the algorithm in Freeze_Fixed_Point_Type. | |
11988 | ||
11989 | while Lo < -B | |
11990 | or else Hi < -B | |
11991 | or else Lo >= B | |
11992 | or else Hi >= B | |
11993 | loop | |
11994 | B := Uint_2 ** S; | |
11995 | S := S + 1; | |
11996 | end loop; | |
11997 | ||
11998 | -- Unsigned case | |
11999 | ||
12000 | else | |
12001 | -- If both bounds are positive, make sure that both are represen- | |
12002 | -- table in the case where the bounds are crossed. This can happen | |
12003 | -- either because of the way the bounds are declared, or because of | |
12004 | -- the algorithm in Freeze_Fixed_Point_Type. | |
12005 | ||
12006 | if Lo > Hi then | |
12007 | Hi := Lo; | |
12008 | end if; | |
12009 | ||
da253936 | 12010 | -- S = size, (can accommodate 0 .. (2**size - 1)) |
d6f39728 | 12011 | |
12012 | S := 0; | |
12013 | while Hi >= Uint_2 ** S loop | |
12014 | S := S + 1; | |
12015 | end loop; | |
12016 | end if; | |
12017 | ||
12018 | return S; | |
12019 | end Minimum_Size; | |
12020 | ||
44e4341e | 12021 | --------------------------- |
12022 | -- New_Stream_Subprogram -- | |
12023 | --------------------------- | |
d6f39728 | 12024 | |
44e4341e | 12025 | procedure New_Stream_Subprogram |
12026 | (N : Node_Id; | |
12027 | Ent : Entity_Id; | |
12028 | Subp : Entity_Id; | |
12029 | Nam : TSS_Name_Type) | |
d6f39728 | 12030 | is |
12031 | Loc : constant Source_Ptr := Sloc (N); | |
9dfe12ae | 12032 | Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam); |
f15731c4 | 12033 | Subp_Id : Entity_Id; |
d6f39728 | 12034 | Subp_Decl : Node_Id; |
12035 | F : Entity_Id; | |
12036 | Etyp : Entity_Id; | |
12037 | ||
44e4341e | 12038 | Defer_Declaration : constant Boolean := |
12039 | Is_Tagged_Type (Ent) or else Is_Private_Type (Ent); | |
12040 | -- For a tagged type, there is a declaration for each stream attribute | |
12041 | -- at the freeze point, and we must generate only a completion of this | |
12042 | -- declaration. We do the same for private types, because the full view | |
12043 | -- might be tagged. Otherwise we generate a declaration at the point of | |
12044 | -- the attribute definition clause. | |
12045 | ||
f15731c4 | 12046 | function Build_Spec return Node_Id; |
12047 | -- Used for declaration and renaming declaration, so that this is | |
12048 | -- treated as a renaming_as_body. | |
12049 | ||
12050 | ---------------- | |
12051 | -- Build_Spec -- | |
12052 | ---------------- | |
12053 | ||
d5b349fa | 12054 | function Build_Spec return Node_Id is |
44e4341e | 12055 | Out_P : constant Boolean := (Nam = TSS_Stream_Read); |
12056 | Formals : List_Id; | |
12057 | Spec : Node_Id; | |
83c6c069 | 12058 | T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc); |
44e4341e | 12059 | |
f15731c4 | 12060 | begin |
9dfe12ae | 12061 | Subp_Id := Make_Defining_Identifier (Loc, Sname); |
f15731c4 | 12062 | |
44e4341e | 12063 | -- S : access Root_Stream_Type'Class |
12064 | ||
12065 | Formals := New_List ( | |
12066 | Make_Parameter_Specification (Loc, | |
12067 | Defining_Identifier => | |
12068 | Make_Defining_Identifier (Loc, Name_S), | |
12069 | Parameter_Type => | |
12070 | Make_Access_Definition (Loc, | |
12071 | Subtype_Mark => | |
83c6c069 | 12072 | New_Occurrence_Of ( |
44e4341e | 12073 | Designated_Type (Etype (F)), Loc)))); |
12074 | ||
12075 | if Nam = TSS_Stream_Input then | |
4bba0a8d | 12076 | Spec := |
12077 | Make_Function_Specification (Loc, | |
12078 | Defining_Unit_Name => Subp_Id, | |
12079 | Parameter_Specifications => Formals, | |
12080 | Result_Definition => T_Ref); | |
44e4341e | 12081 | else |
12082 | -- V : [out] T | |
f15731c4 | 12083 | |
44e4341e | 12084 | Append_To (Formals, |
12085 | Make_Parameter_Specification (Loc, | |
12086 | Defining_Identifier => Make_Defining_Identifier (Loc, Name_V), | |
12087 | Out_Present => Out_P, | |
12088 | Parameter_Type => T_Ref)); | |
f15731c4 | 12089 | |
d3ef794c | 12090 | Spec := |
12091 | Make_Procedure_Specification (Loc, | |
12092 | Defining_Unit_Name => Subp_Id, | |
12093 | Parameter_Specifications => Formals); | |
44e4341e | 12094 | end if; |
f15731c4 | 12095 | |
44e4341e | 12096 | return Spec; |
12097 | end Build_Spec; | |
d6f39728 | 12098 | |
44e4341e | 12099 | -- Start of processing for New_Stream_Subprogram |
d6f39728 | 12100 | |
44e4341e | 12101 | begin |
12102 | F := First_Formal (Subp); | |
12103 | ||
12104 | if Ekind (Subp) = E_Procedure then | |
12105 | Etyp := Etype (Next_Formal (F)); | |
d6f39728 | 12106 | else |
44e4341e | 12107 | Etyp := Etype (Subp); |
d6f39728 | 12108 | end if; |
f15731c4 | 12109 | |
44e4341e | 12110 | -- Prepare subprogram declaration and insert it as an action on the |
12111 | -- clause node. The visibility for this entity is used to test for | |
12112 | -- visibility of the attribute definition clause (in the sense of | |
12113 | -- 8.3(23) as amended by AI-195). | |
9dfe12ae | 12114 | |
44e4341e | 12115 | if not Defer_Declaration then |
f15731c4 | 12116 | Subp_Decl := |
12117 | Make_Subprogram_Declaration (Loc, | |
12118 | Specification => Build_Spec); | |
44e4341e | 12119 | |
12120 | -- For a tagged type, there is always a visible declaration for each | |
15ebb600 | 12121 | -- stream TSS (it is a predefined primitive operation), and the |
44e4341e | 12122 | -- completion of this declaration occurs at the freeze point, which is |
12123 | -- not always visible at places where the attribute definition clause is | |
12124 | -- visible. So, we create a dummy entity here for the purpose of | |
12125 | -- tracking the visibility of the attribute definition clause itself. | |
12126 | ||
12127 | else | |
12128 | Subp_Id := | |
55868293 | 12129 | Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V')); |
44e4341e | 12130 | Subp_Decl := |
12131 | Make_Object_Declaration (Loc, | |
12132 | Defining_Identifier => Subp_Id, | |
12133 | Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc)); | |
f15731c4 | 12134 | end if; |
12135 | ||
44e4341e | 12136 | Insert_Action (N, Subp_Decl); |
12137 | Set_Entity (N, Subp_Id); | |
12138 | ||
d6f39728 | 12139 | Subp_Decl := |
12140 | Make_Subprogram_Renaming_Declaration (Loc, | |
f15731c4 | 12141 | Specification => Build_Spec, |
83c6c069 | 12142 | Name => New_Occurrence_Of (Subp, Loc)); |
d6f39728 | 12143 | |
44e4341e | 12144 | if Defer_Declaration then |
d6f39728 | 12145 | Set_TSS (Base_Type (Ent), Subp_Id); |
12146 | else | |
12147 | Insert_Action (N, Subp_Decl); | |
12148 | Copy_TSS (Subp_Id, Base_Type (Ent)); | |
12149 | end if; | |
44e4341e | 12150 | end New_Stream_Subprogram; |
d6f39728 | 12151 | |
2625eb01 | 12152 | ------------------------------------------ |
12153 | -- Push_Scope_And_Install_Discriminants -- | |
12154 | ------------------------------------------ | |
12155 | ||
12156 | procedure Push_Scope_And_Install_Discriminants (E : Entity_Id) is | |
12157 | begin | |
12158 | if Has_Discriminants (E) then | |
12159 | Push_Scope (E); | |
12160 | ||
12161 | -- Make discriminants visible for type declarations and protected | |
12162 | -- type declarations, not for subtype declarations (RM 13.1.1 (12/3)) | |
12163 | ||
12164 | if Nkind (Parent (E)) /= N_Subtype_Declaration then | |
12165 | Install_Discriminants (E); | |
12166 | end if; | |
12167 | end if; | |
12168 | end Push_Scope_And_Install_Discriminants; | |
12169 | ||
d6f39728 | 12170 | ------------------------ |
12171 | -- Rep_Item_Too_Early -- | |
12172 | ------------------------ | |
12173 | ||
80d4fec4 | 12174 | function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is |
d6f39728 | 12175 | begin |
44e4341e | 12176 | -- Cannot apply non-operational rep items to generic types |
d6f39728 | 12177 | |
f15731c4 | 12178 | if Is_Operational_Item (N) then |
12179 | return False; | |
12180 | ||
12181 | elsif Is_Type (T) | |
d6f39728 | 12182 | and then Is_Generic_Type (Root_Type (T)) |
e17c5076 | 12183 | and then (Nkind (N) /= N_Pragma |
12184 | or else Get_Pragma_Id (N) /= Pragma_Convention) | |
d6f39728 | 12185 | then |
503f7fd3 | 12186 | Error_Msg_N ("representation item not allowed for generic type", N); |
d6f39728 | 12187 | return True; |
12188 | end if; | |
12189 | ||
fdd294d1 | 12190 | -- Otherwise check for incomplete type |
d6f39728 | 12191 | |
12192 | if Is_Incomplete_Or_Private_Type (T) | |
12193 | and then No (Underlying_Type (T)) | |
d64221a7 | 12194 | and then |
12195 | (Nkind (N) /= N_Pragma | |
60014bc9 | 12196 | or else Get_Pragma_Id (N) /= Pragma_Import) |
d6f39728 | 12197 | then |
12198 | Error_Msg_N | |
12199 | ("representation item must be after full type declaration", N); | |
12200 | return True; | |
12201 | ||
1a34e48c | 12202 | -- If the type has incomplete components, a representation clause is |
d6f39728 | 12203 | -- illegal but stream attributes and Convention pragmas are correct. |
12204 | ||
12205 | elsif Has_Private_Component (T) then | |
f15731c4 | 12206 | if Nkind (N) = N_Pragma then |
d6f39728 | 12207 | return False; |
b9e61b2a | 12208 | |
d6f39728 | 12209 | else |
12210 | Error_Msg_N | |
12211 | ("representation item must appear after type is fully defined", | |
12212 | N); | |
12213 | return True; | |
12214 | end if; | |
12215 | else | |
12216 | return False; | |
12217 | end if; | |
12218 | end Rep_Item_Too_Early; | |
12219 | ||
12220 | ----------------------- | |
12221 | -- Rep_Item_Too_Late -- | |
12222 | ----------------------- | |
12223 | ||
12224 | function Rep_Item_Too_Late | |
12225 | (T : Entity_Id; | |
12226 | N : Node_Id; | |
d5b349fa | 12227 | FOnly : Boolean := False) return Boolean |
d6f39728 | 12228 | is |
12229 | S : Entity_Id; | |
12230 | Parent_Type : Entity_Id; | |
12231 | ||
4d0944e9 | 12232 | procedure No_Type_Rep_Item; |
12233 | -- Output message indicating that no type-related aspects can be | |
12234 | -- specified due to some property of the parent type. | |
12235 | ||
d6f39728 | 12236 | procedure Too_Late; |
4d0944e9 | 12237 | -- Output message for an aspect being specified too late |
12238 | ||
12239 | -- Note that neither of the above errors is considered a serious one, | |
12240 | -- since the effect is simply that we ignore the representation clause | |
12241 | -- in these cases. | |
04d38ee4 | 12242 | -- Is this really true? In any case if we make this change we must |
12243 | -- document the requirement in the spec of Rep_Item_Too_Late that | |
12244 | -- if True is returned, then the rep item must be completely ignored??? | |
4d0944e9 | 12245 | |
12246 | ---------------------- | |
12247 | -- No_Type_Rep_Item -- | |
12248 | ---------------------- | |
12249 | ||
12250 | procedure No_Type_Rep_Item is | |
12251 | begin | |
12252 | Error_Msg_N ("|type-related representation item not permitted!", N); | |
12253 | end No_Type_Rep_Item; | |
d53a018a | 12254 | |
12255 | -------------- | |
12256 | -- Too_Late -- | |
12257 | -------------- | |
d6f39728 | 12258 | |
12259 | procedure Too_Late is | |
12260 | begin | |
ce4da1ed | 12261 | -- Other compilers seem more relaxed about rep items appearing too |
12262 | -- late. Since analysis tools typically don't care about rep items | |
12263 | -- anyway, no reason to be too strict about this. | |
12264 | ||
a9cd517c | 12265 | if not Relaxed_RM_Semantics then |
12266 | Error_Msg_N ("|representation item appears too late!", N); | |
12267 | end if; | |
d6f39728 | 12268 | end Too_Late; |
12269 | ||
12270 | -- Start of processing for Rep_Item_Too_Late | |
12271 | ||
12272 | begin | |
a3248fc4 | 12273 | -- First make sure entity is not frozen (RM 13.1(9)) |
d6f39728 | 12274 | |
12275 | if Is_Frozen (T) | |
a3248fc4 | 12276 | |
12277 | -- Exclude imported types, which may be frozen if they appear in a | |
12278 | -- representation clause for a local type. | |
12279 | ||
4aa270d8 | 12280 | and then not From_Limited_With (T) |
a3248fc4 | 12281 | |
a9cd517c | 12282 | -- Exclude generated entities (not coming from source). The common |
a3248fc4 | 12283 | -- case is when we generate a renaming which prematurely freezes the |
12284 | -- renamed internal entity, but we still want to be able to set copies | |
12285 | -- of attribute values such as Size/Alignment. | |
12286 | ||
12287 | and then Comes_From_Source (T) | |
d6f39728 | 12288 | then |
12289 | Too_Late; | |
12290 | S := First_Subtype (T); | |
12291 | ||
12292 | if Present (Freeze_Node (S)) then | |
04d38ee4 | 12293 | if not Relaxed_RM_Semantics then |
12294 | Error_Msg_NE | |
12295 | ("??no more representation items for }", Freeze_Node (S), S); | |
12296 | end if; | |
d6f39728 | 12297 | end if; |
12298 | ||
12299 | return True; | |
12300 | ||
d1a2e31b | 12301 | -- Check for case of untagged derived type whose parent either has |
4d0944e9 | 12302 | -- primitive operations, or is a by reference type (RM 13.1(10)). In |
12303 | -- this case we do not output a Too_Late message, since there is no | |
12304 | -- earlier point where the rep item could be placed to make it legal. | |
d6f39728 | 12305 | |
12306 | elsif Is_Type (T) | |
12307 | and then not FOnly | |
12308 | and then Is_Derived_Type (T) | |
12309 | and then not Is_Tagged_Type (T) | |
12310 | then | |
12311 | Parent_Type := Etype (Base_Type (T)); | |
12312 | ||
12313 | if Has_Primitive_Operations (Parent_Type) then | |
4d0944e9 | 12314 | No_Type_Rep_Item; |
04d38ee4 | 12315 | |
12316 | if not Relaxed_RM_Semantics then | |
12317 | Error_Msg_NE | |
12318 | ("\parent type & has primitive operations!", N, Parent_Type); | |
12319 | end if; | |
12320 | ||
d6f39728 | 12321 | return True; |
12322 | ||
12323 | elsif Is_By_Reference_Type (Parent_Type) then | |
4d0944e9 | 12324 | No_Type_Rep_Item; |
04d38ee4 | 12325 | |
12326 | if not Relaxed_RM_Semantics then | |
12327 | Error_Msg_NE | |
12328 | ("\parent type & is a by reference type!", N, Parent_Type); | |
12329 | end if; | |
12330 | ||
d6f39728 | 12331 | return True; |
12332 | end if; | |
12333 | end if; | |
12334 | ||
04d38ee4 | 12335 | -- No error, but one more warning to consider. The RM (surprisingly) |
12336 | -- allows this pattern: | |
12337 | ||
12338 | -- type S is ... | |
12339 | -- primitive operations for S | |
12340 | -- type R is new S; | |
12341 | -- rep clause for S | |
12342 | ||
12343 | -- Meaning that calls on the primitive operations of S for values of | |
12344 | -- type R may require possibly expensive implicit conversion operations. | |
12345 | -- This is not an error, but is worth a warning. | |
12346 | ||
12347 | if not Relaxed_RM_Semantics and then Is_Type (T) then | |
12348 | declare | |
12349 | DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T)); | |
12350 | ||
12351 | begin | |
12352 | if Present (DTL) | |
12353 | and then Has_Primitive_Operations (Base_Type (T)) | |
12354 | ||
12355 | -- For now, do not generate this warning for the case of aspect | |
12356 | -- specification using Ada 2012 syntax, since we get wrong | |
12357 | -- messages we do not understand. The whole business of derived | |
12358 | -- types and rep items seems a bit confused when aspects are | |
12359 | -- used, since the aspects are not evaluated till freeze time. | |
12360 | ||
12361 | and then not From_Aspect_Specification (N) | |
12362 | then | |
12363 | Error_Msg_Sloc := Sloc (DTL); | |
12364 | Error_Msg_N | |
12365 | ("representation item for& appears after derived type " | |
12366 | & "declaration#??", N); | |
12367 | Error_Msg_NE | |
12368 | ("\may result in implicit conversions for primitive " | |
12369 | & "operations of&??", N, T); | |
12370 | Error_Msg_NE | |
12371 | ("\to change representations when called with arguments " | |
12372 | & "of type&??", N, DTL); | |
12373 | end if; | |
12374 | end; | |
12375 | end if; | |
12376 | ||
3062c401 | 12377 | -- No error, link item into head of chain of rep items for the entity, |
12378 | -- but avoid chaining if we have an overloadable entity, and the pragma | |
12379 | -- is one that can apply to multiple overloaded entities. | |
12380 | ||
b9e61b2a | 12381 | if Is_Overloadable (T) and then Nkind (N) = N_Pragma then |
fdd294d1 | 12382 | declare |
12383 | Pname : constant Name_Id := Pragma_Name (N); | |
12384 | begin | |
18393965 | 12385 | if Nam_In (Pname, Name_Convention, Name_Import, Name_Export, |
12386 | Name_External, Name_Interface) | |
fdd294d1 | 12387 | then |
12388 | return False; | |
12389 | end if; | |
12390 | end; | |
3062c401 | 12391 | end if; |
12392 | ||
fdd294d1 | 12393 | Record_Rep_Item (T, N); |
d6f39728 | 12394 | return False; |
12395 | end Rep_Item_Too_Late; | |
12396 | ||
2072eaa9 | 12397 | ------------------------------------- |
12398 | -- Replace_Type_References_Generic -- | |
12399 | ------------------------------------- | |
12400 | ||
37c6552c | 12401 | procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is |
12402 | TName : constant Name_Id := Chars (T); | |
2072eaa9 | 12403 | |
12404 | function Replace_Node (N : Node_Id) return Traverse_Result; | |
12405 | -- Processes a single node in the traversal procedure below, checking | |
12406 | -- if node N should be replaced, and if so, doing the replacement. | |
12407 | ||
12408 | procedure Replace_Type_Refs is new Traverse_Proc (Replace_Node); | |
12409 | -- This instantiation provides the body of Replace_Type_References | |
12410 | ||
12411 | ------------------ | |
12412 | -- Replace_Node -- | |
12413 | ------------------ | |
12414 | ||
12415 | function Replace_Node (N : Node_Id) return Traverse_Result is | |
12416 | S : Entity_Id; | |
12417 | P : Node_Id; | |
12418 | ||
12419 | begin | |
12420 | -- Case of identifier | |
12421 | ||
12422 | if Nkind (N) = N_Identifier then | |
12423 | ||
37c6552c | 12424 | -- If not the type name, check whether it is a reference to |
12425 | -- some other type, which must be frozen before the predicate | |
12426 | -- function is analyzed, i.e. before the freeze node of the | |
12427 | -- type to which the predicate applies. | |
2072eaa9 | 12428 | |
12429 | if Chars (N) /= TName then | |
37c6552c | 12430 | if Present (Current_Entity (N)) |
12431 | and then Is_Type (Current_Entity (N)) | |
12432 | then | |
12433 | Freeze_Before (Freeze_Node (T), Current_Entity (N)); | |
12434 | end if; | |
12435 | ||
2072eaa9 | 12436 | return Skip; |
12437 | ||
12438 | -- Otherwise do the replacement and we are done with this node | |
12439 | ||
12440 | else | |
12441 | Replace_Type_Reference (N); | |
12442 | return Skip; | |
12443 | end if; | |
12444 | ||
12445 | -- Case of selected component (which is what a qualification | |
12446 | -- looks like in the unanalyzed tree, which is what we have. | |
12447 | ||
12448 | elsif Nkind (N) = N_Selected_Component then | |
12449 | ||
12450 | -- If selector name is not our type, keeping going (we might | |
12451 | -- still have an occurrence of the type in the prefix). | |
12452 | ||
12453 | if Nkind (Selector_Name (N)) /= N_Identifier | |
12454 | or else Chars (Selector_Name (N)) /= TName | |
12455 | then | |
12456 | return OK; | |
12457 | ||
12458 | -- Selector name is our type, check qualification | |
12459 | ||
12460 | else | |
12461 | -- Loop through scopes and prefixes, doing comparison | |
12462 | ||
12463 | S := Current_Scope; | |
12464 | P := Prefix (N); | |
12465 | loop | |
12466 | -- Continue if no more scopes or scope with no name | |
12467 | ||
12468 | if No (S) or else Nkind (S) not in N_Has_Chars then | |
12469 | return OK; | |
12470 | end if; | |
12471 | ||
12472 | -- Do replace if prefix is an identifier matching the | |
12473 | -- scope that we are currently looking at. | |
12474 | ||
12475 | if Nkind (P) = N_Identifier | |
12476 | and then Chars (P) = Chars (S) | |
12477 | then | |
12478 | Replace_Type_Reference (N); | |
12479 | return Skip; | |
12480 | end if; | |
12481 | ||
12482 | -- Go check scope above us if prefix is itself of the | |
12483 | -- form of a selected component, whose selector matches | |
12484 | -- the scope we are currently looking at. | |
12485 | ||
12486 | if Nkind (P) = N_Selected_Component | |
12487 | and then Nkind (Selector_Name (P)) = N_Identifier | |
12488 | and then Chars (Selector_Name (P)) = Chars (S) | |
12489 | then | |
12490 | S := Scope (S); | |
12491 | P := Prefix (P); | |
12492 | ||
12493 | -- For anything else, we don't have a match, so keep on | |
12494 | -- going, there are still some weird cases where we may | |
12495 | -- still have a replacement within the prefix. | |
12496 | ||
12497 | else | |
12498 | return OK; | |
12499 | end if; | |
12500 | end loop; | |
12501 | end if; | |
12502 | ||
ec6f6da5 | 12503 | -- Continue for any other node kind |
2072eaa9 | 12504 | |
12505 | else | |
12506 | return OK; | |
12507 | end if; | |
12508 | end Replace_Node; | |
12509 | ||
12510 | begin | |
12511 | Replace_Type_Refs (N); | |
12512 | end Replace_Type_References_Generic; | |
12513 | ||
81bd1c0d | 12514 | -------------------------------- |
12515 | -- Resolve_Aspect_Expressions -- | |
12516 | -------------------------------- | |
12517 | ||
12518 | procedure Resolve_Aspect_Expressions (E : Entity_Id) is | |
12519 | ASN : Node_Id; | |
12520 | A_Id : Aspect_Id; | |
12521 | Expr : Node_Id; | |
12522 | ||
12523 | begin | |
12524 | ASN := First_Rep_Item (E); | |
12525 | while Present (ASN) loop | |
12526 | if Nkind (ASN) = N_Aspect_Specification and then Entity (ASN) = E then | |
12527 | A_Id := Get_Aspect_Id (ASN); | |
12528 | Expr := Expression (ASN); | |
12529 | ||
12530 | case A_Id is | |
12531 | -- For now we only deal with aspects that do not generate | |
12532 | -- subprograms, or that may mention current instances of | |
12533 | -- types. These will require special handling (TBD). | |
12534 | ||
12535 | when Aspect_Predicate | | |
12536 | Aspect_Invariant | | |
12537 | Aspect_Static_Predicate | | |
12538 | Aspect_Dynamic_Predicate => | |
12539 | null; | |
12540 | ||
12541 | when Pre_Post_Aspects => | |
12542 | null; | |
12543 | ||
12544 | when Aspect_Iterable => | |
12545 | if Nkind (Expr) = N_Aggregate then | |
12546 | declare | |
12547 | Assoc : Node_Id; | |
12548 | ||
12549 | begin | |
12550 | Assoc := First (Component_Associations (Expr)); | |
12551 | while Present (Assoc) loop | |
12552 | Find_Direct_Name (Expression (Assoc)); | |
12553 | Next (Assoc); | |
12554 | end loop; | |
12555 | end; | |
12556 | end if; | |
12557 | ||
12558 | when others => | |
12559 | if Present (Expr) then | |
12560 | case Aspect_Argument (A_Id) is | |
12561 | when Expression | Optional_Expression => | |
12562 | Analyze_And_Resolve (Expression (ASN)); | |
12563 | ||
12564 | when Name | Optional_Name => | |
12565 | if Nkind (Expr) = N_Identifier then | |
12566 | Find_Direct_Name (Expr); | |
12567 | ||
12568 | elsif Nkind (Expr) = N_Selected_Component then | |
12569 | Find_Selected_Component (Expr); | |
12570 | ||
12571 | else | |
12572 | null; | |
12573 | end if; | |
12574 | end case; | |
12575 | end if; | |
12576 | end case; | |
12577 | end if; | |
12578 | ||
a738763e | 12579 | ASN := Next_Rep_Item (ASN); |
81bd1c0d | 12580 | end loop; |
12581 | end Resolve_Aspect_Expressions; | |
12582 | ||
d6f39728 | 12583 | ------------------------- |
12584 | -- Same_Representation -- | |
12585 | ------------------------- | |
12586 | ||
12587 | function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is | |
12588 | T1 : constant Entity_Id := Underlying_Type (Typ1); | |
12589 | T2 : constant Entity_Id := Underlying_Type (Typ2); | |
12590 | ||
12591 | begin | |
12592 | -- A quick check, if base types are the same, then we definitely have | |
12593 | -- the same representation, because the subtype specific representation | |
12594 | -- attributes (Size and Alignment) do not affect representation from | |
12595 | -- the point of view of this test. | |
12596 | ||
12597 | if Base_Type (T1) = Base_Type (T2) then | |
12598 | return True; | |
12599 | ||
12600 | elsif Is_Private_Type (Base_Type (T2)) | |
12601 | and then Base_Type (T1) = Full_View (Base_Type (T2)) | |
12602 | then | |
12603 | return True; | |
12604 | end if; | |
12605 | ||
12606 | -- Tagged types never have differing representations | |
12607 | ||
12608 | if Is_Tagged_Type (T1) then | |
12609 | return True; | |
12610 | end if; | |
12611 | ||
12612 | -- Representations are definitely different if conventions differ | |
12613 | ||
12614 | if Convention (T1) /= Convention (T2) then | |
12615 | return False; | |
12616 | end if; | |
12617 | ||
ef0772bc | 12618 | -- Representations are different if component alignments or scalar |
12619 | -- storage orders differ. | |
d6f39728 | 12620 | |
12621 | if (Is_Record_Type (T1) or else Is_Array_Type (T1)) | |
726fd56a | 12622 | and then |
d6f39728 | 12623 | (Is_Record_Type (T2) or else Is_Array_Type (T2)) |
ef0772bc | 12624 | and then |
12625 | (Component_Alignment (T1) /= Component_Alignment (T2) | |
f02a9a9a | 12626 | or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2)) |
d6f39728 | 12627 | then |
12628 | return False; | |
12629 | end if; | |
12630 | ||
12631 | -- For arrays, the only real issue is component size. If we know the | |
12632 | -- component size for both arrays, and it is the same, then that's | |
12633 | -- good enough to know we don't have a change of representation. | |
12634 | ||
12635 | if Is_Array_Type (T1) then | |
12636 | if Known_Component_Size (T1) | |
12637 | and then Known_Component_Size (T2) | |
12638 | and then Component_Size (T1) = Component_Size (T2) | |
12639 | then | |
36ac5fbb | 12640 | return True; |
d6f39728 | 12641 | end if; |
12642 | end if; | |
12643 | ||
12644 | -- Types definitely have same representation if neither has non-standard | |
12645 | -- representation since default representations are always consistent. | |
12646 | -- If only one has non-standard representation, and the other does not, | |
12647 | -- then we consider that they do not have the same representation. They | |
12648 | -- might, but there is no way of telling early enough. | |
12649 | ||
12650 | if Has_Non_Standard_Rep (T1) then | |
12651 | if not Has_Non_Standard_Rep (T2) then | |
12652 | return False; | |
12653 | end if; | |
12654 | else | |
12655 | return not Has_Non_Standard_Rep (T2); | |
12656 | end if; | |
12657 | ||
fdd294d1 | 12658 | -- Here the two types both have non-standard representation, and we need |
12659 | -- to determine if they have the same non-standard representation. | |
d6f39728 | 12660 | |
12661 | -- For arrays, we simply need to test if the component sizes are the | |
12662 | -- same. Pragma Pack is reflected in modified component sizes, so this | |
12663 | -- check also deals with pragma Pack. | |
12664 | ||
12665 | if Is_Array_Type (T1) then | |
12666 | return Component_Size (T1) = Component_Size (T2); | |
12667 | ||
12668 | -- Tagged types always have the same representation, because it is not | |
12669 | -- possible to specify different representations for common fields. | |
12670 | ||
12671 | elsif Is_Tagged_Type (T1) then | |
12672 | return True; | |
12673 | ||
12674 | -- Case of record types | |
12675 | ||
12676 | elsif Is_Record_Type (T1) then | |
12677 | ||
12678 | -- Packed status must conform | |
12679 | ||
12680 | if Is_Packed (T1) /= Is_Packed (T2) then | |
12681 | return False; | |
12682 | ||
12683 | -- Otherwise we must check components. Typ2 maybe a constrained | |
12684 | -- subtype with fewer components, so we compare the components | |
12685 | -- of the base types. | |
12686 | ||
12687 | else | |
12688 | Record_Case : declare | |
12689 | CD1, CD2 : Entity_Id; | |
12690 | ||
12691 | function Same_Rep return Boolean; | |
12692 | -- CD1 and CD2 are either components or discriminants. This | |
ef0772bc | 12693 | -- function tests whether they have the same representation. |
d6f39728 | 12694 | |
80d4fec4 | 12695 | -------------- |
12696 | -- Same_Rep -- | |
12697 | -------------- | |
12698 | ||
d6f39728 | 12699 | function Same_Rep return Boolean is |
12700 | begin | |
12701 | if No (Component_Clause (CD1)) then | |
12702 | return No (Component_Clause (CD2)); | |
d6f39728 | 12703 | else |
ef0772bc | 12704 | -- Note: at this point, component clauses have been |
12705 | -- normalized to the default bit order, so that the | |
12706 | -- comparison of Component_Bit_Offsets is meaningful. | |
12707 | ||
d6f39728 | 12708 | return |
12709 | Present (Component_Clause (CD2)) | |
12710 | and then | |
12711 | Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2) | |
12712 | and then | |
12713 | Esize (CD1) = Esize (CD2); | |
12714 | end if; | |
12715 | end Same_Rep; | |
12716 | ||
1e35409d | 12717 | -- Start of processing for Record_Case |
d6f39728 | 12718 | |
12719 | begin | |
12720 | if Has_Discriminants (T1) then | |
d6f39728 | 12721 | |
9dfe12ae | 12722 | -- The number of discriminants may be different if the |
12723 | -- derived type has fewer (constrained by values). The | |
12724 | -- invisible discriminants retain the representation of | |
12725 | -- the original, so the discrepancy does not per se | |
12726 | -- indicate a different representation. | |
12727 | ||
b9e61b2a | 12728 | CD1 := First_Discriminant (T1); |
12729 | CD2 := First_Discriminant (T2); | |
12730 | while Present (CD1) and then Present (CD2) loop | |
d6f39728 | 12731 | if not Same_Rep then |
12732 | return False; | |
12733 | else | |
12734 | Next_Discriminant (CD1); | |
12735 | Next_Discriminant (CD2); | |
12736 | end if; | |
12737 | end loop; | |
12738 | end if; | |
12739 | ||
12740 | CD1 := First_Component (Underlying_Type (Base_Type (T1))); | |
12741 | CD2 := First_Component (Underlying_Type (Base_Type (T2))); | |
d6f39728 | 12742 | while Present (CD1) loop |
12743 | if not Same_Rep then | |
12744 | return False; | |
12745 | else | |
12746 | Next_Component (CD1); | |
12747 | Next_Component (CD2); | |
12748 | end if; | |
12749 | end loop; | |
12750 | ||
12751 | return True; | |
12752 | end Record_Case; | |
12753 | end if; | |
12754 | ||
12755 | -- For enumeration types, we must check each literal to see if the | |
12756 | -- representation is the same. Note that we do not permit enumeration | |
1a34e48c | 12757 | -- representation clauses for Character and Wide_Character, so these |
d6f39728 | 12758 | -- cases were already dealt with. |
12759 | ||
12760 | elsif Is_Enumeration_Type (T1) then | |
d6f39728 | 12761 | Enumeration_Case : declare |
12762 | L1, L2 : Entity_Id; | |
12763 | ||
12764 | begin | |
12765 | L1 := First_Literal (T1); | |
12766 | L2 := First_Literal (T2); | |
d6f39728 | 12767 | while Present (L1) loop |
12768 | if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then | |
12769 | return False; | |
12770 | else | |
12771 | Next_Literal (L1); | |
12772 | Next_Literal (L2); | |
12773 | end if; | |
12774 | end loop; | |
12775 | ||
12776 | return True; | |
d6f39728 | 12777 | end Enumeration_Case; |
12778 | ||
12779 | -- Any other types have the same representation for these purposes | |
12780 | ||
12781 | else | |
12782 | return True; | |
12783 | end if; | |
d6f39728 | 12784 | end Same_Representation; |
12785 | ||
3061ffde | 12786 | -------------------------------- |
12787 | -- Resolve_Iterable_Operation -- | |
12788 | -------------------------------- | |
12789 | ||
12790 | procedure Resolve_Iterable_Operation | |
12791 | (N : Node_Id; | |
12792 | Cursor : Entity_Id; | |
12793 | Typ : Entity_Id; | |
12794 | Nam : Name_Id) | |
12795 | is | |
12796 | Ent : Entity_Id; | |
12797 | F1 : Entity_Id; | |
12798 | F2 : Entity_Id; | |
12799 | ||
12800 | begin | |
12801 | if not Is_Overloaded (N) then | |
12802 | if not Is_Entity_Name (N) | |
12803 | or else Ekind (Entity (N)) /= E_Function | |
12804 | or else Scope (Entity (N)) /= Scope (Typ) | |
12805 | or else No (First_Formal (Entity (N))) | |
12806 | or else Etype (First_Formal (Entity (N))) /= Typ | |
12807 | then | |
12808 | Error_Msg_N ("iterable primitive must be local function name " | |
12809 | & "whose first formal is an iterable type", N); | |
a9f5fea7 | 12810 | return; |
3061ffde | 12811 | end if; |
12812 | ||
12813 | Ent := Entity (N); | |
12814 | F1 := First_Formal (Ent); | |
12815 | if Nam = Name_First then | |
12816 | ||
12817 | -- First (Container) => Cursor | |
12818 | ||
12819 | if Etype (Ent) /= Cursor then | |
12820 | Error_Msg_N ("primitive for First must yield a curosr", N); | |
12821 | end if; | |
12822 | ||
12823 | elsif Nam = Name_Next then | |
12824 | ||
12825 | -- Next (Container, Cursor) => Cursor | |
12826 | ||
12827 | F2 := Next_Formal (F1); | |
12828 | ||
12829 | if Etype (F2) /= Cursor | |
12830 | or else Etype (Ent) /= Cursor | |
12831 | or else Present (Next_Formal (F2)) | |
12832 | then | |
12833 | Error_Msg_N ("no match for Next iterable primitive", N); | |
12834 | end if; | |
12835 | ||
12836 | elsif Nam = Name_Has_Element then | |
12837 | ||
12838 | -- Has_Element (Container, Cursor) => Boolean | |
12839 | ||
12840 | F2 := Next_Formal (F1); | |
12841 | if Etype (F2) /= Cursor | |
12842 | or else Etype (Ent) /= Standard_Boolean | |
12843 | or else Present (Next_Formal (F2)) | |
12844 | then | |
12845 | Error_Msg_N ("no match for Has_Element iterable primitive", N); | |
12846 | end if; | |
12847 | ||
12848 | elsif Nam = Name_Element then | |
b9b03799 | 12849 | F2 := Next_Formal (F1); |
12850 | ||
12851 | if No (F2) | |
12852 | or else Etype (F2) /= Cursor | |
12853 | or else Present (Next_Formal (F2)) | |
12854 | then | |
12855 | Error_Msg_N ("no match for Element iterable primitive", N); | |
12856 | end if; | |
3061ffde | 12857 | null; |
12858 | ||
12859 | else | |
12860 | raise Program_Error; | |
12861 | end if; | |
12862 | ||
12863 | else | |
12864 | -- Overloaded case: find subprogram with proper signature. | |
12865 | -- Caller will report error if no match is found. | |
12866 | ||
12867 | declare | |
12868 | I : Interp_Index; | |
12869 | It : Interp; | |
12870 | ||
12871 | begin | |
12872 | Get_First_Interp (N, I, It); | |
12873 | while Present (It.Typ) loop | |
12874 | if Ekind (It.Nam) = E_Function | |
b9b03799 | 12875 | and then Scope (It.Nam) = Scope (Typ) |
3061ffde | 12876 | and then Etype (First_Formal (It.Nam)) = Typ |
12877 | then | |
12878 | F1 := First_Formal (It.Nam); | |
12879 | ||
12880 | if Nam = Name_First then | |
12881 | if Etype (It.Nam) = Cursor | |
12882 | and then No (Next_Formal (F1)) | |
12883 | then | |
12884 | Set_Entity (N, It.Nam); | |
12885 | exit; | |
12886 | end if; | |
12887 | ||
12888 | elsif Nam = Name_Next then | |
12889 | F2 := Next_Formal (F1); | |
12890 | ||
12891 | if Present (F2) | |
12892 | and then No (Next_Formal (F2)) | |
12893 | and then Etype (F2) = Cursor | |
12894 | and then Etype (It.Nam) = Cursor | |
12895 | then | |
12896 | Set_Entity (N, It.Nam); | |
12897 | exit; | |
12898 | end if; | |
12899 | ||
12900 | elsif Nam = Name_Has_Element then | |
12901 | F2 := Next_Formal (F1); | |
12902 | ||
12903 | if Present (F2) | |
12904 | and then No (Next_Formal (F2)) | |
12905 | and then Etype (F2) = Cursor | |
12906 | and then Etype (It.Nam) = Standard_Boolean | |
12907 | then | |
12908 | Set_Entity (N, It.Nam); | |
12909 | F2 := Next_Formal (F1); | |
12910 | exit; | |
12911 | end if; | |
12912 | ||
12913 | elsif Nam = Name_Element then | |
b9b03799 | 12914 | F2 := Next_Formal (F1); |
12915 | ||
3061ffde | 12916 | if Present (F2) |
12917 | and then No (Next_Formal (F2)) | |
12918 | and then Etype (F2) = Cursor | |
12919 | then | |
12920 | Set_Entity (N, It.Nam); | |
12921 | exit; | |
12922 | end if; | |
12923 | end if; | |
12924 | end if; | |
12925 | ||
12926 | Get_Next_Interp (I, It); | |
12927 | end loop; | |
12928 | end; | |
12929 | end if; | |
12930 | end Resolve_Iterable_Operation; | |
12931 | ||
b77e4501 | 12932 | ---------------- |
12933 | -- Set_Biased -- | |
12934 | ---------------- | |
12935 | ||
12936 | procedure Set_Biased | |
12937 | (E : Entity_Id; | |
12938 | N : Node_Id; | |
12939 | Msg : String; | |
12940 | Biased : Boolean := True) | |
12941 | is | |
12942 | begin | |
12943 | if Biased then | |
12944 | Set_Has_Biased_Representation (E); | |
12945 | ||
12946 | if Warn_On_Biased_Representation then | |
12947 | Error_Msg_NE | |
1e3532e7 | 12948 | ("?B?" & Msg & " forces biased representation for&", N, E); |
b77e4501 | 12949 | end if; |
12950 | end if; | |
12951 | end Set_Biased; | |
12952 | ||
d6f39728 | 12953 | -------------------- |
12954 | -- Set_Enum_Esize -- | |
12955 | -------------------- | |
12956 | ||
12957 | procedure Set_Enum_Esize (T : Entity_Id) is | |
12958 | Lo : Uint; | |
12959 | Hi : Uint; | |
12960 | Sz : Nat; | |
12961 | ||
12962 | begin | |
12963 | Init_Alignment (T); | |
12964 | ||
12965 | -- Find the minimum standard size (8,16,32,64) that fits | |
12966 | ||
12967 | Lo := Enumeration_Rep (Entity (Type_Low_Bound (T))); | |
12968 | Hi := Enumeration_Rep (Entity (Type_High_Bound (T))); | |
12969 | ||
12970 | if Lo < 0 then | |
12971 | if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then | |
f15731c4 | 12972 | Sz := Standard_Character_Size; -- May be > 8 on some targets |
d6f39728 | 12973 | |
12974 | elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then | |
12975 | Sz := 16; | |
12976 | ||
12977 | elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then | |
12978 | Sz := 32; | |
12979 | ||
12980 | else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63); | |
12981 | Sz := 64; | |
12982 | end if; | |
12983 | ||
12984 | else | |
12985 | if Hi < Uint_2**08 then | |
f15731c4 | 12986 | Sz := Standard_Character_Size; -- May be > 8 on some targets |
d6f39728 | 12987 | |
12988 | elsif Hi < Uint_2**16 then | |
12989 | Sz := 16; | |
12990 | ||
12991 | elsif Hi < Uint_2**32 then | |
12992 | Sz := 32; | |
12993 | ||
12994 | else pragma Assert (Hi < Uint_2**63); | |
12995 | Sz := 64; | |
12996 | end if; | |
12997 | end if; | |
12998 | ||
12999 | -- That minimum is the proper size unless we have a foreign convention | |
13000 | -- and the size required is 32 or less, in which case we bump the size | |
13001 | -- up to 32. This is required for C and C++ and seems reasonable for | |
13002 | -- all other foreign conventions. | |
13003 | ||
13004 | if Has_Foreign_Convention (T) | |
13005 | and then Esize (T) < Standard_Integer_Size | |
db1eed69 | 13006 | |
13007 | -- Don't do this if Short_Enums on target | |
13008 | ||
e9185b9d | 13009 | and then not Target_Short_Enums |
d6f39728 | 13010 | then |
13011 | Init_Esize (T, Standard_Integer_Size); | |
d6f39728 | 13012 | else |
13013 | Init_Esize (T, Sz); | |
13014 | end if; | |
d6f39728 | 13015 | end Set_Enum_Esize; |
13016 | ||
2625eb01 | 13017 | ----------------------------- |
13018 | -- Uninstall_Discriminants -- | |
13019 | ----------------------------- | |
13020 | ||
13021 | procedure Uninstall_Discriminants (E : Entity_Id) is | |
13022 | Disc : Entity_Id; | |
13023 | Prev : Entity_Id; | |
13024 | Outer : Entity_Id; | |
13025 | ||
13026 | begin | |
13027 | -- Discriminants have been made visible for type declarations and | |
13028 | -- protected type declarations, not for subtype declarations. | |
13029 | ||
13030 | if Nkind (Parent (E)) /= N_Subtype_Declaration then | |
13031 | Disc := First_Discriminant (E); | |
13032 | while Present (Disc) loop | |
13033 | if Disc /= Current_Entity (Disc) then | |
13034 | Prev := Current_Entity (Disc); | |
13035 | while Present (Prev) | |
13036 | and then Present (Homonym (Prev)) | |
13037 | and then Homonym (Prev) /= Disc | |
13038 | loop | |
13039 | Prev := Homonym (Prev); | |
13040 | end loop; | |
13041 | else | |
13042 | Prev := Empty; | |
13043 | end if; | |
13044 | ||
13045 | Set_Is_Immediately_Visible (Disc, False); | |
13046 | ||
13047 | Outer := Homonym (Disc); | |
13048 | while Present (Outer) and then Scope (Outer) = E loop | |
13049 | Outer := Homonym (Outer); | |
13050 | end loop; | |
13051 | ||
13052 | -- Reset homonym link of other entities, but do not modify link | |
13053 | -- between entities in current scope, so that the back-end can | |
13054 | -- have a proper count of local overloadings. | |
13055 | ||
13056 | if No (Prev) then | |
13057 | Set_Name_Entity_Id (Chars (Disc), Outer); | |
13058 | ||
13059 | elsif Scope (Prev) /= Scope (Disc) then | |
13060 | Set_Homonym (Prev, Outer); | |
13061 | end if; | |
13062 | ||
13063 | Next_Discriminant (Disc); | |
13064 | end loop; | |
13065 | end if; | |
13066 | end Uninstall_Discriminants; | |
13067 | ||
13068 | ------------------------------------------- | |
13069 | -- Uninstall_Discriminants_And_Pop_Scope -- | |
13070 | ------------------------------------------- | |
13071 | ||
13072 | procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id) is | |
13073 | begin | |
13074 | if Has_Discriminants (E) then | |
13075 | Uninstall_Discriminants (E); | |
13076 | Pop_Scope; | |
13077 | end if; | |
13078 | end Uninstall_Discriminants_And_Pop_Scope; | |
13079 | ||
83f8f0a6 | 13080 | ------------------------------ |
13081 | -- Validate_Address_Clauses -- | |
13082 | ------------------------------ | |
13083 | ||
13084 | procedure Validate_Address_Clauses is | |
13085 | begin | |
13086 | for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop | |
13087 | declare | |
13088 | ACCR : Address_Clause_Check_Record | |
13089 | renames Address_Clause_Checks.Table (J); | |
13090 | ||
d6da7448 | 13091 | Expr : Node_Id; |
13092 | ||
83f8f0a6 | 13093 | X_Alignment : Uint; |
13094 | Y_Alignment : Uint; | |
13095 | ||
13096 | X_Size : Uint; | |
13097 | Y_Size : Uint; | |
13098 | ||
13099 | begin | |
13100 | -- Skip processing of this entry if warning already posted | |
13101 | ||
13102 | if not Address_Warning_Posted (ACCR.N) then | |
d6da7448 | 13103 | Expr := Original_Node (Expression (ACCR.N)); |
83f8f0a6 | 13104 | |
d6da7448 | 13105 | -- Get alignments |
83f8f0a6 | 13106 | |
d6da7448 | 13107 | X_Alignment := Alignment (ACCR.X); |
13108 | Y_Alignment := Alignment (ACCR.Y); | |
83f8f0a6 | 13109 | |
13110 | -- Similarly obtain sizes | |
13111 | ||
d6da7448 | 13112 | X_Size := Esize (ACCR.X); |
13113 | Y_Size := Esize (ACCR.Y); | |
83f8f0a6 | 13114 | |
13115 | -- Check for large object overlaying smaller one | |
13116 | ||
13117 | if Y_Size > Uint_0 | |
13118 | and then X_Size > Uint_0 | |
13119 | and then X_Size > Y_Size | |
13120 | then | |
d6da7448 | 13121 | Error_Msg_NE |
1581f2d7 | 13122 | ("??& overlays smaller object", ACCR.N, ACCR.X); |
83f8f0a6 | 13123 | Error_Msg_N |
1e3532e7 | 13124 | ("\??program execution may be erroneous", ACCR.N); |
83f8f0a6 | 13125 | Error_Msg_Uint_1 := X_Size; |
13126 | Error_Msg_NE | |
1e3532e7 | 13127 | ("\??size of & is ^", ACCR.N, ACCR.X); |
83f8f0a6 | 13128 | Error_Msg_Uint_1 := Y_Size; |
13129 | Error_Msg_NE | |
1e3532e7 | 13130 | ("\??size of & is ^", ACCR.N, ACCR.Y); |
83f8f0a6 | 13131 | |
d6da7448 | 13132 | -- Check for inadequate alignment, both of the base object |
e556831e | 13133 | -- and of the offset, if any. We only do this check if the |
13134 | -- run-time Alignment_Check is active. No point in warning | |
13135 | -- if this check has been suppressed (or is suppressed by | |
13136 | -- default in the non-strict alignment machine case). | |
83f8f0a6 | 13137 | |
d6da7448 | 13138 | -- Note: we do not check the alignment if we gave a size |
13139 | -- warning, since it would likely be redundant. | |
83f8f0a6 | 13140 | |
e556831e | 13141 | elsif not Alignment_Checks_Suppressed (ACCR.Y) |
13142 | and then Y_Alignment /= Uint_0 | |
d6da7448 | 13143 | and then (Y_Alignment < X_Alignment |
13144 | or else (ACCR.Off | |
13145 | and then | |
13146 | Nkind (Expr) = N_Attribute_Reference | |
13147 | and then | |
13148 | Attribute_Name (Expr) = Name_Address | |
13149 | and then | |
13150 | Has_Compatible_Alignment | |
13151 | (ACCR.X, Prefix (Expr)) | |
13152 | /= Known_Compatible)) | |
83f8f0a6 | 13153 | then |
13154 | Error_Msg_NE | |
1e3532e7 | 13155 | ("??specified address for& may be inconsistent " |
13156 | & "with alignment", ACCR.N, ACCR.X); | |
83f8f0a6 | 13157 | Error_Msg_N |
1e3532e7 | 13158 | ("\??program execution may be erroneous (RM 13.3(27))", |
83f8f0a6 | 13159 | ACCR.N); |
13160 | Error_Msg_Uint_1 := X_Alignment; | |
13161 | Error_Msg_NE | |
1e3532e7 | 13162 | ("\??alignment of & is ^", ACCR.N, ACCR.X); |
83f8f0a6 | 13163 | Error_Msg_Uint_1 := Y_Alignment; |
13164 | Error_Msg_NE | |
1e3532e7 | 13165 | ("\??alignment of & is ^", ACCR.N, ACCR.Y); |
d6da7448 | 13166 | if Y_Alignment >= X_Alignment then |
13167 | Error_Msg_N | |
1e3532e7 | 13168 | ("\??but offset is not multiple of alignment", ACCR.N); |
d6da7448 | 13169 | end if; |
83f8f0a6 | 13170 | end if; |
13171 | end if; | |
13172 | end; | |
13173 | end loop; | |
13174 | end Validate_Address_Clauses; | |
13175 | ||
7717ea00 | 13176 | --------------------------- |
13177 | -- Validate_Independence -- | |
13178 | --------------------------- | |
13179 | ||
13180 | procedure Validate_Independence is | |
13181 | SU : constant Uint := UI_From_Int (System_Storage_Unit); | |
13182 | N : Node_Id; | |
13183 | E : Entity_Id; | |
13184 | IC : Boolean; | |
13185 | Comp : Entity_Id; | |
13186 | Addr : Node_Id; | |
13187 | P : Node_Id; | |
13188 | ||
13189 | procedure Check_Array_Type (Atyp : Entity_Id); | |
13190 | -- Checks if the array type Atyp has independent components, and | |
13191 | -- if not, outputs an appropriate set of error messages. | |
13192 | ||
13193 | procedure No_Independence; | |
13194 | -- Output message that independence cannot be guaranteed | |
13195 | ||
13196 | function OK_Component (C : Entity_Id) return Boolean; | |
13197 | -- Checks one component to see if it is independently accessible, and | |
13198 | -- if so yields True, otherwise yields False if independent access | |
13199 | -- cannot be guaranteed. This is a conservative routine, it only | |
13200 | -- returns True if it knows for sure, it returns False if it knows | |
13201 | -- there is a problem, or it cannot be sure there is no problem. | |
13202 | ||
13203 | procedure Reason_Bad_Component (C : Entity_Id); | |
13204 | -- Outputs continuation message if a reason can be determined for | |
13205 | -- the component C being bad. | |
13206 | ||
13207 | ---------------------- | |
13208 | -- Check_Array_Type -- | |
13209 | ---------------------- | |
13210 | ||
13211 | procedure Check_Array_Type (Atyp : Entity_Id) is | |
13212 | Ctyp : constant Entity_Id := Component_Type (Atyp); | |
13213 | ||
13214 | begin | |
13215 | -- OK if no alignment clause, no pack, and no component size | |
13216 | ||
13217 | if not Has_Component_Size_Clause (Atyp) | |
13218 | and then not Has_Alignment_Clause (Atyp) | |
13219 | and then not Is_Packed (Atyp) | |
13220 | then | |
13221 | return; | |
13222 | end if; | |
13223 | ||
aa0a69ab | 13224 | -- Case of component size is greater than or equal to 64 and the |
13225 | -- alignment of the array is at least as large as the alignment | |
13226 | -- of the component. We are definitely OK in this situation. | |
13227 | ||
13228 | if Known_Component_Size (Atyp) | |
13229 | and then Component_Size (Atyp) >= 64 | |
13230 | and then Known_Alignment (Atyp) | |
13231 | and then Known_Alignment (Ctyp) | |
13232 | and then Alignment (Atyp) >= Alignment (Ctyp) | |
13233 | then | |
13234 | return; | |
13235 | end if; | |
13236 | ||
7717ea00 | 13237 | -- Check actual component size |
13238 | ||
13239 | if not Known_Component_Size (Atyp) | |
13240 | or else not (Addressable (Component_Size (Atyp)) | |
aa0a69ab | 13241 | and then Component_Size (Atyp) < 64) |
7717ea00 | 13242 | or else Component_Size (Atyp) mod Esize (Ctyp) /= 0 |
13243 | then | |
13244 | No_Independence; | |
13245 | ||
13246 | -- Bad component size, check reason | |
13247 | ||
13248 | if Has_Component_Size_Clause (Atyp) then | |
b9e61b2a | 13249 | P := Get_Attribute_Definition_Clause |
13250 | (Atyp, Attribute_Component_Size); | |
7717ea00 | 13251 | |
13252 | if Present (P) then | |
13253 | Error_Msg_Sloc := Sloc (P); | |
13254 | Error_Msg_N ("\because of Component_Size clause#", N); | |
13255 | return; | |
13256 | end if; | |
13257 | end if; | |
13258 | ||
13259 | if Is_Packed (Atyp) then | |
13260 | P := Get_Rep_Pragma (Atyp, Name_Pack); | |
13261 | ||
13262 | if Present (P) then | |
13263 | Error_Msg_Sloc := Sloc (P); | |
13264 | Error_Msg_N ("\because of pragma Pack#", N); | |
13265 | return; | |
13266 | end if; | |
13267 | end if; | |
13268 | ||
13269 | -- No reason found, just return | |
13270 | ||
13271 | return; | |
13272 | end if; | |
13273 | ||
13274 | -- Array type is OK independence-wise | |
13275 | ||
13276 | return; | |
13277 | end Check_Array_Type; | |
13278 | ||
13279 | --------------------- | |
13280 | -- No_Independence -- | |
13281 | --------------------- | |
13282 | ||
13283 | procedure No_Independence is | |
13284 | begin | |
13285 | if Pragma_Name (N) = Name_Independent then | |
18393965 | 13286 | Error_Msg_NE ("independence cannot be guaranteed for&", N, E); |
7717ea00 | 13287 | else |
13288 | Error_Msg_NE | |
13289 | ("independent components cannot be guaranteed for&", N, E); | |
13290 | end if; | |
13291 | end No_Independence; | |
13292 | ||
13293 | ------------------ | |
13294 | -- OK_Component -- | |
13295 | ------------------ | |
13296 | ||
13297 | function OK_Component (C : Entity_Id) return Boolean is | |
13298 | Rec : constant Entity_Id := Scope (C); | |
13299 | Ctyp : constant Entity_Id := Etype (C); | |
13300 | ||
13301 | begin | |
13302 | -- OK if no component clause, no Pack, and no alignment clause | |
13303 | ||
13304 | if No (Component_Clause (C)) | |
13305 | and then not Is_Packed (Rec) | |
13306 | and then not Has_Alignment_Clause (Rec) | |
13307 | then | |
13308 | return True; | |
13309 | end if; | |
13310 | ||
13311 | -- Here we look at the actual component layout. A component is | |
13312 | -- addressable if its size is a multiple of the Esize of the | |
13313 | -- component type, and its starting position in the record has | |
13314 | -- appropriate alignment, and the record itself has appropriate | |
13315 | -- alignment to guarantee the component alignment. | |
13316 | ||
13317 | -- Make sure sizes are static, always assume the worst for any | |
13318 | -- cases where we cannot check static values. | |
13319 | ||
13320 | if not (Known_Static_Esize (C) | |
b9e61b2a | 13321 | and then |
13322 | Known_Static_Esize (Ctyp)) | |
7717ea00 | 13323 | then |
13324 | return False; | |
13325 | end if; | |
13326 | ||
13327 | -- Size of component must be addressable or greater than 64 bits | |
13328 | -- and a multiple of bytes. | |
13329 | ||
b9e61b2a | 13330 | if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then |
7717ea00 | 13331 | return False; |
13332 | end if; | |
13333 | ||
13334 | -- Check size is proper multiple | |
13335 | ||
13336 | if Esize (C) mod Esize (Ctyp) /= 0 then | |
13337 | return False; | |
13338 | end if; | |
13339 | ||
13340 | -- Check alignment of component is OK | |
13341 | ||
13342 | if not Known_Component_Bit_Offset (C) | |
13343 | or else Component_Bit_Offset (C) < Uint_0 | |
13344 | or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0 | |
13345 | then | |
13346 | return False; | |
13347 | end if; | |
13348 | ||
13349 | -- Check alignment of record type is OK | |
13350 | ||
13351 | if not Known_Alignment (Rec) | |
13352 | or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0 | |
13353 | then | |
13354 | return False; | |
13355 | end if; | |
13356 | ||
13357 | -- All tests passed, component is addressable | |
13358 | ||
13359 | return True; | |
13360 | end OK_Component; | |
13361 | ||
13362 | -------------------------- | |
13363 | -- Reason_Bad_Component -- | |
13364 | -------------------------- | |
13365 | ||
13366 | procedure Reason_Bad_Component (C : Entity_Id) is | |
13367 | Rec : constant Entity_Id := Scope (C); | |
13368 | Ctyp : constant Entity_Id := Etype (C); | |
13369 | ||
13370 | begin | |
13371 | -- If component clause present assume that's the problem | |
13372 | ||
13373 | if Present (Component_Clause (C)) then | |
13374 | Error_Msg_Sloc := Sloc (Component_Clause (C)); | |
13375 | Error_Msg_N ("\because of Component_Clause#", N); | |
13376 | return; | |
13377 | end if; | |
13378 | ||
13379 | -- If pragma Pack clause present, assume that's the problem | |
13380 | ||
13381 | if Is_Packed (Rec) then | |
13382 | P := Get_Rep_Pragma (Rec, Name_Pack); | |
13383 | ||
13384 | if Present (P) then | |
13385 | Error_Msg_Sloc := Sloc (P); | |
13386 | Error_Msg_N ("\because of pragma Pack#", N); | |
13387 | return; | |
13388 | end if; | |
13389 | end if; | |
13390 | ||
13391 | -- See if record has bad alignment clause | |
13392 | ||
13393 | if Has_Alignment_Clause (Rec) | |
13394 | and then Known_Alignment (Rec) | |
13395 | and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0 | |
13396 | then | |
13397 | P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment); | |
13398 | ||
13399 | if Present (P) then | |
13400 | Error_Msg_Sloc := Sloc (P); | |
13401 | Error_Msg_N ("\because of Alignment clause#", N); | |
13402 | end if; | |
13403 | end if; | |
13404 | ||
13405 | -- Couldn't find a reason, so return without a message | |
13406 | ||
13407 | return; | |
13408 | end Reason_Bad_Component; | |
13409 | ||
13410 | -- Start of processing for Validate_Independence | |
13411 | ||
13412 | begin | |
13413 | for J in Independence_Checks.First .. Independence_Checks.Last loop | |
13414 | N := Independence_Checks.Table (J).N; | |
13415 | E := Independence_Checks.Table (J).E; | |
13416 | IC := Pragma_Name (N) = Name_Independent_Components; | |
13417 | ||
13418 | -- Deal with component case | |
13419 | ||
13420 | if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then | |
13421 | if not OK_Component (E) then | |
13422 | No_Independence; | |
13423 | Reason_Bad_Component (E); | |
13424 | goto Continue; | |
13425 | end if; | |
13426 | end if; | |
13427 | ||
13428 | -- Deal with record with Independent_Components | |
13429 | ||
13430 | if IC and then Is_Record_Type (E) then | |
13431 | Comp := First_Component_Or_Discriminant (E); | |
13432 | while Present (Comp) loop | |
13433 | if not OK_Component (Comp) then | |
13434 | No_Independence; | |
13435 | Reason_Bad_Component (Comp); | |
13436 | goto Continue; | |
13437 | end if; | |
13438 | ||
13439 | Next_Component_Or_Discriminant (Comp); | |
13440 | end loop; | |
13441 | end if; | |
13442 | ||
13443 | -- Deal with address clause case | |
13444 | ||
13445 | if Is_Object (E) then | |
13446 | Addr := Address_Clause (E); | |
13447 | ||
13448 | if Present (Addr) then | |
13449 | No_Independence; | |
13450 | Error_Msg_Sloc := Sloc (Addr); | |
13451 | Error_Msg_N ("\because of Address clause#", N); | |
13452 | goto Continue; | |
13453 | end if; | |
13454 | end if; | |
13455 | ||
13456 | -- Deal with independent components for array type | |
13457 | ||
13458 | if IC and then Is_Array_Type (E) then | |
13459 | Check_Array_Type (E); | |
13460 | end if; | |
13461 | ||
13462 | -- Deal with independent components for array object | |
13463 | ||
13464 | if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then | |
13465 | Check_Array_Type (Etype (E)); | |
13466 | end if; | |
13467 | ||
13468 | <<Continue>> null; | |
13469 | end loop; | |
13470 | end Validate_Independence; | |
13471 | ||
b3f8228a | 13472 | ------------------------------ |
13473 | -- Validate_Iterable_Aspect -- | |
13474 | ------------------------------ | |
13475 | ||
13476 | procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is | |
3061ffde | 13477 | Assoc : Node_Id; |
13478 | Expr : Node_Id; | |
b3f8228a | 13479 | |
bde03454 | 13480 | Prim : Node_Id; |
a9f5fea7 | 13481 | Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ); |
b3f8228a | 13482 | |
13483 | First_Id : Entity_Id; | |
13484 | Next_Id : Entity_Id; | |
13485 | Has_Element_Id : Entity_Id; | |
13486 | Element_Id : Entity_Id; | |
13487 | ||
b3f8228a | 13488 | begin |
9698629c | 13489 | -- If previous error aspect is unusable |
a9f5fea7 | 13490 | |
13491 | if Cursor = Any_Type then | |
3061ffde | 13492 | return; |
13493 | end if; | |
b3f8228a | 13494 | |
13495 | First_Id := Empty; | |
13496 | Next_Id := Empty; | |
13497 | Has_Element_Id := Empty; | |
32de816b | 13498 | Element_Id := Empty; |
b3f8228a | 13499 | |
13500 | -- Each expression must resolve to a function with the proper signature | |
13501 | ||
13502 | Assoc := First (Component_Associations (Expression (ASN))); | |
13503 | while Present (Assoc) loop | |
13504 | Expr := Expression (Assoc); | |
13505 | Analyze (Expr); | |
13506 | ||
b3f8228a | 13507 | Prim := First (Choices (Assoc)); |
bde03454 | 13508 | |
f02a9a9a | 13509 | if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then |
b3f8228a | 13510 | Error_Msg_N ("illegal name in association", Prim); |
13511 | ||
13512 | elsif Chars (Prim) = Name_First then | |
3061ffde | 13513 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First); |
b3f8228a | 13514 | First_Id := Entity (Expr); |
b3f8228a | 13515 | |
13516 | elsif Chars (Prim) = Name_Next then | |
3061ffde | 13517 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next); |
b3f8228a | 13518 | Next_Id := Entity (Expr); |
b3f8228a | 13519 | |
13520 | elsif Chars (Prim) = Name_Has_Element then | |
3061ffde | 13521 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element); |
b3f8228a | 13522 | Has_Element_Id := Entity (Expr); |
bde03454 | 13523 | |
b3f8228a | 13524 | elsif Chars (Prim) = Name_Element then |
3061ffde | 13525 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element); |
b3f8228a | 13526 | Element_Id := Entity (Expr); |
b3f8228a | 13527 | |
13528 | else | |
13529 | Error_Msg_N ("invalid name for iterable function", Prim); | |
13530 | end if; | |
13531 | ||
13532 | Next (Assoc); | |
13533 | end loop; | |
13534 | ||
13535 | if No (First_Id) then | |
3061ffde | 13536 | Error_Msg_N ("match for First primitive not found", ASN); |
b3f8228a | 13537 | |
13538 | elsif No (Next_Id) then | |
3061ffde | 13539 | Error_Msg_N ("match for Next primitive not found", ASN); |
b3f8228a | 13540 | |
13541 | elsif No (Has_Element_Id) then | |
3061ffde | 13542 | Error_Msg_N ("match for Has_Element primitive not found", ASN); |
13543 | ||
13544 | elsif No (Element_Id) then | |
13545 | null; -- Optional. | |
b3f8228a | 13546 | end if; |
13547 | end Validate_Iterable_Aspect; | |
13548 | ||
d6f39728 | 13549 | ----------------------------------- |
13550 | -- Validate_Unchecked_Conversion -- | |
13551 | ----------------------------------- | |
13552 | ||
13553 | procedure Validate_Unchecked_Conversion | |
13554 | (N : Node_Id; | |
13555 | Act_Unit : Entity_Id) | |
13556 | is | |
13557 | Source : Entity_Id; | |
13558 | Target : Entity_Id; | |
13559 | Vnode : Node_Id; | |
13560 | ||
13561 | begin | |
13562 | -- Obtain source and target types. Note that we call Ancestor_Subtype | |
13563 | -- here because the processing for generic instantiation always makes | |
13564 | -- subtypes, and we want the original frozen actual types. | |
13565 | ||
13566 | -- If we are dealing with private types, then do the check on their | |
13567 | -- fully declared counterparts if the full declarations have been | |
39a0c1d3 | 13568 | -- encountered (they don't have to be visible, but they must exist). |
d6f39728 | 13569 | |
13570 | Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit))); | |
13571 | ||
13572 | if Is_Private_Type (Source) | |
13573 | and then Present (Underlying_Type (Source)) | |
13574 | then | |
13575 | Source := Underlying_Type (Source); | |
13576 | end if; | |
13577 | ||
13578 | Target := Ancestor_Subtype (Etype (Act_Unit)); | |
13579 | ||
fdd294d1 | 13580 | -- If either type is generic, the instantiation happens within a generic |
95deda50 | 13581 | -- unit, and there is nothing to check. The proper check will happen |
13582 | -- when the enclosing generic is instantiated. | |
d6f39728 | 13583 | |
13584 | if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then | |
13585 | return; | |
13586 | end if; | |
13587 | ||
13588 | if Is_Private_Type (Target) | |
13589 | and then Present (Underlying_Type (Target)) | |
13590 | then | |
13591 | Target := Underlying_Type (Target); | |
13592 | end if; | |
13593 | ||
13594 | -- Source may be unconstrained array, but not target | |
13595 | ||
b9e61b2a | 13596 | if Is_Array_Type (Target) and then not Is_Constrained (Target) then |
d6f39728 | 13597 | Error_Msg_N |
13598 | ("unchecked conversion to unconstrained array not allowed", N); | |
13599 | return; | |
13600 | end if; | |
13601 | ||
fbc67f84 | 13602 | -- Warn if conversion between two different convention pointers |
13603 | ||
13604 | if Is_Access_Type (Target) | |
13605 | and then Is_Access_Type (Source) | |
13606 | and then Convention (Target) /= Convention (Source) | |
13607 | and then Warn_On_Unchecked_Conversion | |
13608 | then | |
74c7ae52 | 13609 | -- Give warnings for subprogram pointers only on most targets |
fdd294d1 | 13610 | |
13611 | if Is_Access_Subprogram_Type (Target) | |
13612 | or else Is_Access_Subprogram_Type (Source) | |
fdd294d1 | 13613 | then |
13614 | Error_Msg_N | |
cb97ae5c | 13615 | ("?z?conversion between pointers with different conventions!", |
1e3532e7 | 13616 | N); |
fdd294d1 | 13617 | end if; |
fbc67f84 | 13618 | end if; |
13619 | ||
3062c401 | 13620 | -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a |
13621 | -- warning when compiling GNAT-related sources. | |
13622 | ||
13623 | if Warn_On_Unchecked_Conversion | |
13624 | and then not In_Predefined_Unit (N) | |
13625 | and then RTU_Loaded (Ada_Calendar) | |
f02a9a9a | 13626 | and then (Chars (Source) = Name_Time |
13627 | or else | |
13628 | Chars (Target) = Name_Time) | |
3062c401 | 13629 | then |
13630 | -- If Ada.Calendar is loaded and the name of one of the operands is | |
13631 | -- Time, there is a good chance that this is Ada.Calendar.Time. | |
13632 | ||
13633 | declare | |
f02a9a9a | 13634 | Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time)); |
3062c401 | 13635 | begin |
13636 | pragma Assert (Present (Calendar_Time)); | |
13637 | ||
b9e61b2a | 13638 | if Source = Calendar_Time or else Target = Calendar_Time then |
3062c401 | 13639 | Error_Msg_N |
f02a9a9a | 13640 | ("?z?representation of 'Time values may change between " |
13641 | & "'G'N'A'T versions", N); | |
3062c401 | 13642 | end if; |
13643 | end; | |
13644 | end if; | |
13645 | ||
fdd294d1 | 13646 | -- Make entry in unchecked conversion table for later processing by |
13647 | -- Validate_Unchecked_Conversions, which will check sizes and alignments | |
13648 | -- (using values set by the back-end where possible). This is only done | |
13649 | -- if the appropriate warning is active. | |
d6f39728 | 13650 | |
9dfe12ae | 13651 | if Warn_On_Unchecked_Conversion then |
13652 | Unchecked_Conversions.Append | |
86d32751 | 13653 | (New_Val => UC_Entry'(Eloc => Sloc (N), |
13654 | Source => Source, | |
13655 | Target => Target, | |
13656 | Act_Unit => Act_Unit)); | |
9dfe12ae | 13657 | |
13658 | -- If both sizes are known statically now, then back end annotation | |
13659 | -- is not required to do a proper check but if either size is not | |
13660 | -- known statically, then we need the annotation. | |
13661 | ||
13662 | if Known_Static_RM_Size (Source) | |
1e3532e7 | 13663 | and then |
13664 | Known_Static_RM_Size (Target) | |
9dfe12ae | 13665 | then |
13666 | null; | |
13667 | else | |
13668 | Back_Annotate_Rep_Info := True; | |
13669 | end if; | |
13670 | end if; | |
d6f39728 | 13671 | |
fdd294d1 | 13672 | -- If unchecked conversion to access type, and access type is declared |
95deda50 | 13673 | -- in the same unit as the unchecked conversion, then set the flag |
13674 | -- No_Strict_Aliasing (no strict aliasing is implicit here) | |
28ed91d4 | 13675 | |
13676 | if Is_Access_Type (Target) and then | |
13677 | In_Same_Source_Unit (Target, N) | |
13678 | then | |
13679 | Set_No_Strict_Aliasing (Implementation_Base_Type (Target)); | |
13680 | end if; | |
3d875462 | 13681 | |
95deda50 | 13682 | -- Generate N_Validate_Unchecked_Conversion node for back end in case |
13683 | -- the back end needs to perform special validation checks. | |
3d875462 | 13684 | |
95deda50 | 13685 | -- Shouldn't this be in Exp_Ch13, since the check only gets done if we |
13686 | -- have full expansion and the back end is called ??? | |
3d875462 | 13687 | |
13688 | Vnode := | |
13689 | Make_Validate_Unchecked_Conversion (Sloc (N)); | |
13690 | Set_Source_Type (Vnode, Source); | |
13691 | Set_Target_Type (Vnode, Target); | |
13692 | ||
fdd294d1 | 13693 | -- If the unchecked conversion node is in a list, just insert before it. |
13694 | -- If not we have some strange case, not worth bothering about. | |
3d875462 | 13695 | |
13696 | if Is_List_Member (N) then | |
d6f39728 | 13697 | Insert_After (N, Vnode); |
13698 | end if; | |
13699 | end Validate_Unchecked_Conversion; | |
13700 | ||
13701 | ------------------------------------ | |
13702 | -- Validate_Unchecked_Conversions -- | |
13703 | ------------------------------------ | |
13704 | ||
13705 | procedure Validate_Unchecked_Conversions is | |
13706 | begin | |
13707 | for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop | |
13708 | declare | |
13709 | T : UC_Entry renames Unchecked_Conversions.Table (N); | |
13710 | ||
86d32751 | 13711 | Eloc : constant Source_Ptr := T.Eloc; |
13712 | Source : constant Entity_Id := T.Source; | |
13713 | Target : constant Entity_Id := T.Target; | |
13714 | Act_Unit : constant Entity_Id := T.Act_Unit; | |
d6f39728 | 13715 | |
44705307 | 13716 | Source_Siz : Uint; |
13717 | Target_Siz : Uint; | |
d6f39728 | 13718 | |
13719 | begin | |
86d32751 | 13720 | -- Skip if function marked as warnings off |
13721 | ||
13722 | if Warnings_Off (Act_Unit) then | |
13723 | goto Continue; | |
13724 | end if; | |
13725 | ||
fdd294d1 | 13726 | -- This validation check, which warns if we have unequal sizes for |
13727 | -- unchecked conversion, and thus potentially implementation | |
d6f39728 | 13728 | -- dependent semantics, is one of the few occasions on which we |
fdd294d1 | 13729 | -- use the official RM size instead of Esize. See description in |
13730 | -- Einfo "Handling of Type'Size Values" for details. | |
d6f39728 | 13731 | |
f15731c4 | 13732 | if Serious_Errors_Detected = 0 |
d6f39728 | 13733 | and then Known_Static_RM_Size (Source) |
13734 | and then Known_Static_RM_Size (Target) | |
f25f4252 | 13735 | |
13736 | -- Don't do the check if warnings off for either type, note the | |
13737 | -- deliberate use of OR here instead of OR ELSE to get the flag | |
13738 | -- Warnings_Off_Used set for both types if appropriate. | |
13739 | ||
13740 | and then not (Has_Warnings_Off (Source) | |
13741 | or | |
13742 | Has_Warnings_Off (Target)) | |
d6f39728 | 13743 | then |
13744 | Source_Siz := RM_Size (Source); | |
13745 | Target_Siz := RM_Size (Target); | |
13746 | ||
13747 | if Source_Siz /= Target_Siz then | |
299480f9 | 13748 | Error_Msg |
cb97ae5c | 13749 | ("?z?types for unchecked conversion have different sizes!", |
299480f9 | 13750 | Eloc); |
d6f39728 | 13751 | |
13752 | if All_Errors_Mode then | |
13753 | Error_Msg_Name_1 := Chars (Source); | |
13754 | Error_Msg_Uint_1 := Source_Siz; | |
13755 | Error_Msg_Name_2 := Chars (Target); | |
13756 | Error_Msg_Uint_2 := Target_Siz; | |
cb97ae5c | 13757 | Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc); |
d6f39728 | 13758 | |
13759 | Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz); | |
13760 | ||
13761 | if Is_Discrete_Type (Source) | |
b9e61b2a | 13762 | and then |
13763 | Is_Discrete_Type (Target) | |
d6f39728 | 13764 | then |
13765 | if Source_Siz > Target_Siz then | |
299480f9 | 13766 | Error_Msg |
cb97ae5c | 13767 | ("\?z?^ high order bits of source will " |
1e3532e7 | 13768 | & "be ignored!", Eloc); |
d6f39728 | 13769 | |
9dfe12ae | 13770 | elsif Is_Unsigned_Type (Source) then |
299480f9 | 13771 | Error_Msg |
cb97ae5c | 13772 | ("\?z?source will be extended with ^ high order " |
1581f2d7 | 13773 | & "zero bits!", Eloc); |
d6f39728 | 13774 | |
13775 | else | |
299480f9 | 13776 | Error_Msg |
cb97ae5c | 13777 | ("\?z?source will be extended with ^ high order " |
1e3532e7 | 13778 | & "sign bits!", Eloc); |
d6f39728 | 13779 | end if; |
13780 | ||
13781 | elsif Source_Siz < Target_Siz then | |
13782 | if Is_Discrete_Type (Target) then | |
13783 | if Bytes_Big_Endian then | |
299480f9 | 13784 | Error_Msg |
cb97ae5c | 13785 | ("\?z?target value will include ^ undefined " |
1e3532e7 | 13786 | & "low order bits!", Eloc); |
d6f39728 | 13787 | else |
299480f9 | 13788 | Error_Msg |
cb97ae5c | 13789 | ("\?z?target value will include ^ undefined " |
1e3532e7 | 13790 | & "high order bits!", Eloc); |
d6f39728 | 13791 | end if; |
13792 | ||
13793 | else | |
299480f9 | 13794 | Error_Msg |
cb97ae5c | 13795 | ("\?z?^ trailing bits of target value will be " |
1e3532e7 | 13796 | & "undefined!", Eloc); |
d6f39728 | 13797 | end if; |
13798 | ||
13799 | else pragma Assert (Source_Siz > Target_Siz); | |
0388e54e | 13800 | if Is_Discrete_Type (Source) then |
13801 | if Bytes_Big_Endian then | |
13802 | Error_Msg | |
13803 | ("\?z?^ low order bits of source will be " | |
13804 | & "ignored!", Eloc); | |
13805 | else | |
13806 | Error_Msg | |
13807 | ("\?z?^ high order bits of source will be " | |
13808 | & "ignored!", Eloc); | |
13809 | end if; | |
13810 | ||
13811 | else | |
13812 | Error_Msg | |
13813 | ("\?z?^ trailing bits of source will be " | |
13814 | & "ignored!", Eloc); | |
13815 | end if; | |
d6f39728 | 13816 | end if; |
13817 | end if; | |
d6f39728 | 13818 | end if; |
13819 | end if; | |
13820 | ||
13821 | -- If both types are access types, we need to check the alignment. | |
13822 | -- If the alignment of both is specified, we can do it here. | |
13823 | ||
f15731c4 | 13824 | if Serious_Errors_Detected = 0 |
2a10e737 | 13825 | and then Is_Access_Type (Source) |
13826 | and then Is_Access_Type (Target) | |
d6f39728 | 13827 | and then Target_Strict_Alignment |
13828 | and then Present (Designated_Type (Source)) | |
13829 | and then Present (Designated_Type (Target)) | |
13830 | then | |
13831 | declare | |
13832 | D_Source : constant Entity_Id := Designated_Type (Source); | |
13833 | D_Target : constant Entity_Id := Designated_Type (Target); | |
13834 | ||
13835 | begin | |
13836 | if Known_Alignment (D_Source) | |
b9e61b2a | 13837 | and then |
13838 | Known_Alignment (D_Target) | |
d6f39728 | 13839 | then |
13840 | declare | |
13841 | Source_Align : constant Uint := Alignment (D_Source); | |
13842 | Target_Align : constant Uint := Alignment (D_Target); | |
13843 | ||
13844 | begin | |
13845 | if Source_Align < Target_Align | |
13846 | and then not Is_Tagged_Type (D_Source) | |
f25f4252 | 13847 | |
13848 | -- Suppress warning if warnings suppressed on either | |
13849 | -- type or either designated type. Note the use of | |
13850 | -- OR here instead of OR ELSE. That is intentional, | |
13851 | -- we would like to set flag Warnings_Off_Used in | |
13852 | -- all types for which warnings are suppressed. | |
13853 | ||
13854 | and then not (Has_Warnings_Off (D_Source) | |
13855 | or | |
13856 | Has_Warnings_Off (D_Target) | |
13857 | or | |
13858 | Has_Warnings_Off (Source) | |
13859 | or | |
13860 | Has_Warnings_Off (Target)) | |
d6f39728 | 13861 | then |
d6f39728 | 13862 | Error_Msg_Uint_1 := Target_Align; |
13863 | Error_Msg_Uint_2 := Source_Align; | |
299480f9 | 13864 | Error_Msg_Node_1 := D_Target; |
d6f39728 | 13865 | Error_Msg_Node_2 := D_Source; |
299480f9 | 13866 | Error_Msg |
cb97ae5c | 13867 | ("?z?alignment of & (^) is stricter than " |
1e3532e7 | 13868 | & "alignment of & (^)!", Eloc); |
f25f4252 | 13869 | Error_Msg |
cb97ae5c | 13870 | ("\?z?resulting access value may have invalid " |
1e3532e7 | 13871 | & "alignment!", Eloc); |
d6f39728 | 13872 | end if; |
13873 | end; | |
13874 | end if; | |
13875 | end; | |
13876 | end if; | |
13877 | end; | |
86d32751 | 13878 | |
13879 | <<Continue>> | |
13880 | null; | |
d6f39728 | 13881 | end loop; |
13882 | end Validate_Unchecked_Conversions; | |
13883 | ||
d6f39728 | 13884 | end Sem_Ch13; |