]>
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 | -- -- | |
2625eb01 | 9 | -- Copyright (C) 1992-2014, 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; |
d6f39728 | 37 | with Lib; use Lib; |
83f8f0a6 | 38 | with Lib.Xref; use Lib.Xref; |
15ebb600 | 39 | with Namet; use Namet; |
d6f39728 | 40 | with Nlists; use Nlists; |
41 | with Nmake; use Nmake; | |
42 | with Opt; use Opt; | |
e0521a36 | 43 | with Restrict; use Restrict; |
44 | with Rident; use Rident; | |
d6f39728 | 45 | with Rtsfind; use Rtsfind; |
46 | with Sem; use Sem; | |
d60c9ff7 | 47 | with Sem_Aux; use Sem_Aux; |
be9124d0 | 48 | with Sem_Case; use Sem_Case; |
40ca69b9 | 49 | with Sem_Ch3; use Sem_Ch3; |
490beba6 | 50 | with Sem_Ch6; use Sem_Ch6; |
d6f39728 | 51 | with Sem_Ch8; use Sem_Ch8; |
85696508 | 52 | with Sem_Dim; use Sem_Dim; |
85377c9b | 53 | with Sem_Disp; use Sem_Disp; |
d6f39728 | 54 | with Sem_Eval; use Sem_Eval; |
51ea9c94 | 55 | with Sem_Prag; use Sem_Prag; |
d6f39728 | 56 | with Sem_Res; use Sem_Res; |
57 | with Sem_Type; use Sem_Type; | |
58 | with Sem_Util; use Sem_Util; | |
44e4341e | 59 | with Sem_Warn; use Sem_Warn; |
1e3c4ae6 | 60 | with Sinput; use Sinput; |
9dfe12ae | 61 | with Snames; use Snames; |
d6f39728 | 62 | with Stand; use Stand; |
63 | with Sinfo; use Sinfo; | |
5b5df4a9 | 64 | with Stringt; use Stringt; |
93735cb8 | 65 | with Targparm; use Targparm; |
d6f39728 | 66 | with Ttypes; use Ttypes; |
67 | with Tbuild; use Tbuild; | |
68 | with Urealp; use Urealp; | |
f42f24d7 | 69 | with Warnsw; use Warnsw; |
d6f39728 | 70 | |
bfa5a9d9 | 71 | with GNAT.Heap_Sort_G; |
d6f39728 | 72 | |
73 | package body Sem_Ch13 is | |
74 | ||
75 | SSU : constant Pos := System_Storage_Unit; | |
76 | -- Convenient short hand for commonly used constant | |
77 | ||
78 | ----------------------- | |
79 | -- Local Subprograms -- | |
80 | ----------------------- | |
81 | ||
1d366b32 | 82 | procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint); |
83 | -- This routine is called after setting one of the sizes of type entity | |
84 | -- Typ to Size. The purpose is to deal with the situation of a derived | |
85 | -- type whose inherited alignment is no longer appropriate for the new | |
86 | -- size value. In this case, we reset the Alignment to unknown. | |
d6f39728 | 87 | |
eb66e842 | 88 | procedure Build_Discrete_Static_Predicate |
d97beb2f | 89 | (Typ : Entity_Id; |
90 | Expr : Node_Id; | |
91 | Nam : Name_Id); | |
d7c2851f | 92 | -- Given a predicated type Typ, where Typ is a discrete static subtype, |
93 | -- whose predicate expression is Expr, tests if Expr is a static predicate, | |
94 | -- and if so, builds the predicate range list. Nam is the name of the one | |
95 | -- argument to the predicate function. Occurrences of the type name in the | |
6fb3c314 | 96 | -- predicate expression have been replaced by identifier references to this |
d7c2851f | 97 | -- name, which is unique, so any identifier with Chars matching Nam must be |
98 | -- a reference to the type. If the predicate is non-static, this procedure | |
99 | -- returns doing nothing. If the predicate is static, then the predicate | |
5c6a5792 | 100 | -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is |
101 | -- rewritten as a canonicalized membership operation. | |
d97beb2f | 102 | |
eb66e842 | 103 | procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id); |
104 | -- If Typ has predicates (indicated by Has_Predicates being set for Typ), | |
105 | -- then either there are pragma Predicate entries on the rep chain for the | |
106 | -- type (note that Predicate aspects are converted to pragma Predicate), or | |
107 | -- there are inherited aspects from a parent type, or ancestor subtypes. | |
108 | -- This procedure builds the spec and body for the Predicate function that | |
109 | -- tests these predicates. N is the freeze node for the type. The spec of | |
110 | -- the function is inserted before the freeze node, and the body of the | |
111 | -- function is inserted after the freeze node. If the predicate expression | |
112 | -- has at least one Raise_Expression, then this procedure also builds the | |
113 | -- M version of the predicate function for use in membership tests. | |
114 | ||
6653b695 | 115 | procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id); |
116 | -- Called if both Storage_Pool and Storage_Size attribute definition | |
117 | -- clauses (SP and SS) are present for entity Ent. Issue error message. | |
118 | ||
d9f6a4ee | 119 | procedure Freeze_Entity_Checks (N : Node_Id); |
120 | -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity | |
121 | -- to generate appropriate semantic checks that are delayed until this | |
122 | -- point (they had to be delayed this long for cases of delayed aspects, | |
123 | -- e.g. analysis of statically predicated subtypes in choices, for which | |
124 | -- we have to be sure the subtypes in question are frozen before checking. | |
125 | ||
d6f39728 | 126 | function Get_Alignment_Value (Expr : Node_Id) return Uint; |
127 | -- Given the expression for an alignment value, returns the corresponding | |
128 | -- Uint value. If the value is inappropriate, then error messages are | |
129 | -- posted as required, and a value of No_Uint is returned. | |
130 | ||
131 | function Is_Operational_Item (N : Node_Id) return Boolean; | |
1e3c4ae6 | 132 | -- A specification for a stream attribute is allowed before the full type |
133 | -- is declared, as explained in AI-00137 and the corrigendum. Attributes | |
134 | -- that do not specify a representation characteristic are operational | |
135 | -- attributes. | |
d6f39728 | 136 | |
3b23aaa0 | 137 | function Is_Predicate_Static |
138 | (Expr : Node_Id; | |
139 | Nam : Name_Id) return Boolean; | |
140 | -- Given predicate expression Expr, tests if Expr is predicate-static in | |
141 | -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type | |
142 | -- name in the predicate expression have been replaced by references to | |
143 | -- an identifier whose Chars field is Nam. This name is unique, so any | |
144 | -- identifier with Chars matching Nam must be a reference to the type. | |
145 | -- Returns True if the expression is predicate-static and False otherwise, | |
146 | -- but is not in the business of setting flags or issuing error messages. | |
147 | -- | |
148 | -- Only scalar types can have static predicates, so False is always | |
149 | -- returned for non-scalar types. | |
150 | -- | |
151 | -- Note: the RM seems to suggest that string types can also have static | |
152 | -- predicates. But that really makes lttle sense as very few useful | |
153 | -- predicates can be constructed for strings. Remember that: | |
154 | -- | |
155 | -- "ABC" < "DEF" | |
156 | -- | |
157 | -- is not a static expression. So even though the clearly faulty RM wording | |
158 | -- allows the following: | |
159 | -- | |
160 | -- subtype S is String with Static_Predicate => S < "DEF" | |
161 | -- | |
162 | -- We can't allow this, otherwise we have predicate-static applying to a | |
163 | -- larger class than static expressions, which was never intended. | |
164 | ||
44e4341e | 165 | procedure New_Stream_Subprogram |
d6f39728 | 166 | (N : Node_Id; |
167 | Ent : Entity_Id; | |
168 | Subp : Entity_Id; | |
9dfe12ae | 169 | Nam : TSS_Name_Type); |
44e4341e | 170 | -- Create a subprogram renaming of a given stream attribute to the |
171 | -- designated subprogram and then in the tagged case, provide this as a | |
d1a2e31b | 172 | -- primitive operation, or in the untagged case make an appropriate TSS |
44e4341e | 173 | -- entry. This is more properly an expansion activity than just semantics, |
d1a2e31b | 174 | -- but the presence of user-defined stream functions for limited types |
175 | -- is a legality check, which is why this takes place here rather than in | |
44e4341e | 176 | -- exp_ch13, where it was previously. Nam indicates the name of the TSS |
177 | -- function to be generated. | |
9dfe12ae | 178 | -- |
f15731c4 | 179 | -- To avoid elaboration anomalies with freeze nodes, for untagged types |
180 | -- we generate both a subprogram declaration and a subprogram renaming | |
181 | -- declaration, so that the attribute specification is handled as a | |
182 | -- renaming_as_body. For tagged types, the specification is one of the | |
183 | -- primitive specs. | |
184 | ||
3061ffde | 185 | procedure Resolve_Iterable_Operation |
186 | (N : Node_Id; | |
187 | Cursor : Entity_Id; | |
188 | Typ : Entity_Id; | |
189 | Nam : Name_Id); | |
190 | -- If the name of a primitive operation for an Iterable aspect is | |
191 | -- overloaded, resolve according to required signature. | |
192 | ||
b77e4501 | 193 | procedure Set_Biased |
194 | (E : Entity_Id; | |
195 | N : Node_Id; | |
196 | Msg : String; | |
197 | Biased : Boolean := True); | |
198 | -- If Biased is True, sets Has_Biased_Representation flag for E, and | |
199 | -- outputs a warning message at node N if Warn_On_Biased_Representation is | |
200 | -- is True. This warning inserts the string Msg to describe the construct | |
201 | -- causing biasing. | |
202 | ||
d6f39728 | 203 | ---------------------------------------------- |
204 | -- Table for Validate_Unchecked_Conversions -- | |
205 | ---------------------------------------------- | |
206 | ||
207 | -- The following table collects unchecked conversions for validation. | |
95deda50 | 208 | -- Entries are made by Validate_Unchecked_Conversion and then the call |
209 | -- to Validate_Unchecked_Conversions does the actual error checking and | |
210 | -- posting of warnings. The reason for this delayed processing is to take | |
211 | -- advantage of back-annotations of size and alignment values performed by | |
212 | -- the back end. | |
d6f39728 | 213 | |
95deda50 | 214 | -- Note: the reason we store a Source_Ptr value instead of a Node_Id is |
215 | -- that by the time Validate_Unchecked_Conversions is called, Sprint will | |
216 | -- already have modified all Sloc values if the -gnatD option is set. | |
299480f9 | 217 | |
d6f39728 | 218 | type UC_Entry is record |
86d32751 | 219 | Eloc : Source_Ptr; -- node used for posting warnings |
220 | Source : Entity_Id; -- source type for unchecked conversion | |
221 | Target : Entity_Id; -- target type for unchecked conversion | |
222 | Act_Unit : Entity_Id; -- actual function instantiated | |
d6f39728 | 223 | end record; |
224 | ||
225 | package Unchecked_Conversions is new Table.Table ( | |
226 | Table_Component_Type => UC_Entry, | |
227 | Table_Index_Type => Int, | |
228 | Table_Low_Bound => 1, | |
229 | Table_Initial => 50, | |
230 | Table_Increment => 200, | |
231 | Table_Name => "Unchecked_Conversions"); | |
232 | ||
83f8f0a6 | 233 | ---------------------------------------- |
234 | -- Table for Validate_Address_Clauses -- | |
235 | ---------------------------------------- | |
236 | ||
237 | -- If an address clause has the form | |
238 | ||
239 | -- for X'Address use Expr | |
240 | ||
95deda50 | 241 | -- where Expr is of the form Y'Address or recursively is a reference to a |
242 | -- constant of either of these forms, and X and Y are entities of objects, | |
243 | -- then if Y has a smaller alignment than X, that merits a warning about | |
244 | -- possible bad alignment. The following table collects address clauses of | |
245 | -- this kind. We put these in a table so that they can be checked after the | |
246 | -- back end has completed annotation of the alignments of objects, since we | |
247 | -- can catch more cases that way. | |
83f8f0a6 | 248 | |
249 | type Address_Clause_Check_Record is record | |
250 | N : Node_Id; | |
251 | -- The address clause | |
252 | ||
253 | X : Entity_Id; | |
254 | -- The entity of the object overlaying Y | |
255 | ||
256 | Y : Entity_Id; | |
257 | -- The entity of the object being overlaid | |
d6da7448 | 258 | |
259 | Off : Boolean; | |
6fb3c314 | 260 | -- Whether the address is offset within Y |
83f8f0a6 | 261 | end record; |
262 | ||
263 | package Address_Clause_Checks is new Table.Table ( | |
264 | Table_Component_Type => Address_Clause_Check_Record, | |
265 | Table_Index_Type => Int, | |
266 | Table_Low_Bound => 1, | |
267 | Table_Initial => 20, | |
268 | Table_Increment => 200, | |
269 | Table_Name => "Address_Clause_Checks"); | |
270 | ||
59ac57b5 | 271 | ----------------------------------------- |
272 | -- Adjust_Record_For_Reverse_Bit_Order -- | |
273 | ----------------------------------------- | |
274 | ||
275 | procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is | |
67278d60 | 276 | Comp : Node_Id; |
277 | CC : Node_Id; | |
59ac57b5 | 278 | |
279 | begin | |
67278d60 | 280 | -- Processing depends on version of Ada |
59ac57b5 | 281 | |
6797073f | 282 | -- For Ada 95, we just renumber bits within a storage unit. We do the |
568b0f6a | 283 | -- same for Ada 83 mode, since we recognize the Bit_Order attribute in |
ab19a652 | 284 | -- Ada 83, and are free to add this extension. |
6797073f | 285 | |
286 | if Ada_Version < Ada_2005 then | |
287 | Comp := First_Component_Or_Discriminant (R); | |
288 | while Present (Comp) loop | |
289 | CC := Component_Clause (Comp); | |
290 | ||
291 | -- If component clause is present, then deal with the non-default | |
292 | -- bit order case for Ada 95 mode. | |
293 | ||
294 | -- We only do this processing for the base type, and in fact that | |
295 | -- is important, since otherwise if there are record subtypes, we | |
296 | -- could reverse the bits once for each subtype, which is wrong. | |
297 | ||
b9e61b2a | 298 | if Present (CC) and then Ekind (R) = E_Record_Type then |
6797073f | 299 | declare |
300 | CFB : constant Uint := Component_Bit_Offset (Comp); | |
301 | CSZ : constant Uint := Esize (Comp); | |
302 | CLC : constant Node_Id := Component_Clause (Comp); | |
303 | Pos : constant Node_Id := Position (CLC); | |
304 | FB : constant Node_Id := First_Bit (CLC); | |
305 | ||
306 | Storage_Unit_Offset : constant Uint := | |
307 | CFB / System_Storage_Unit; | |
308 | ||
309 | Start_Bit : constant Uint := | |
310 | CFB mod System_Storage_Unit; | |
59ac57b5 | 311 | |
6797073f | 312 | begin |
313 | -- Cases where field goes over storage unit boundary | |
59ac57b5 | 314 | |
6797073f | 315 | if Start_Bit + CSZ > System_Storage_Unit then |
59ac57b5 | 316 | |
6797073f | 317 | -- Allow multi-byte field but generate warning |
59ac57b5 | 318 | |
6797073f | 319 | if Start_Bit mod System_Storage_Unit = 0 |
320 | and then CSZ mod System_Storage_Unit = 0 | |
321 | then | |
322 | Error_Msg_N | |
7a41db5b | 323 | ("info: multi-byte field specified with " |
324 | & "non-standard Bit_Order?V?", CLC); | |
31486bc0 | 325 | |
6797073f | 326 | if Bytes_Big_Endian then |
31486bc0 | 327 | Error_Msg_N |
7a41db5b | 328 | ("\bytes are not reversed " |
329 | & "(component is big-endian)?V?", CLC); | |
31486bc0 | 330 | else |
331 | Error_Msg_N | |
7a41db5b | 332 | ("\bytes are not reversed " |
333 | & "(component is little-endian)?V?", CLC); | |
31486bc0 | 334 | end if; |
59ac57b5 | 335 | |
6797073f | 336 | -- Do not allow non-contiguous field |
59ac57b5 | 337 | |
67278d60 | 338 | else |
6797073f | 339 | Error_Msg_N |
340 | ("attempt to specify non-contiguous field " | |
341 | & "not permitted", CLC); | |
342 | Error_Msg_N | |
343 | ("\caused by non-standard Bit_Order " | |
344 | & "specified", CLC); | |
345 | Error_Msg_N | |
346 | ("\consider possibility of using " | |
347 | & "Ada 2005 mode here", CLC); | |
348 | end if; | |
59ac57b5 | 349 | |
6797073f | 350 | -- Case where field fits in one storage unit |
59ac57b5 | 351 | |
6797073f | 352 | else |
353 | -- Give warning if suspicious component clause | |
59ac57b5 | 354 | |
6797073f | 355 | if Intval (FB) >= System_Storage_Unit |
356 | and then Warn_On_Reverse_Bit_Order | |
357 | then | |
358 | Error_Msg_N | |
7a41db5b | 359 | ("info: Bit_Order clause does not affect " & |
1e3532e7 | 360 | "byte ordering?V?", Pos); |
6797073f | 361 | Error_Msg_Uint_1 := |
362 | Intval (Pos) + Intval (FB) / | |
363 | System_Storage_Unit; | |
364 | Error_Msg_N | |
7a41db5b | 365 | ("info: position normalized to ^ before bit " & |
1e3532e7 | 366 | "order interpreted?V?", Pos); |
6797073f | 367 | end if; |
59ac57b5 | 368 | |
6797073f | 369 | -- Here is where we fix up the Component_Bit_Offset value |
370 | -- to account for the reverse bit order. Some examples of | |
371 | -- what needs to be done are: | |
bfa5a9d9 | 372 | |
6797073f | 373 | -- First_Bit .. Last_Bit Component_Bit_Offset |
374 | -- old new old new | |
59ac57b5 | 375 | |
6797073f | 376 | -- 0 .. 0 7 .. 7 0 7 |
377 | -- 0 .. 1 6 .. 7 0 6 | |
378 | -- 0 .. 2 5 .. 7 0 5 | |
379 | -- 0 .. 7 0 .. 7 0 4 | |
59ac57b5 | 380 | |
6797073f | 381 | -- 1 .. 1 6 .. 6 1 6 |
382 | -- 1 .. 4 3 .. 6 1 3 | |
383 | -- 4 .. 7 0 .. 3 4 0 | |
59ac57b5 | 384 | |
6797073f | 385 | -- The rule is that the first bit is is obtained by |
386 | -- subtracting the old ending bit from storage_unit - 1. | |
59ac57b5 | 387 | |
6797073f | 388 | Set_Component_Bit_Offset |
389 | (Comp, | |
390 | (Storage_Unit_Offset * System_Storage_Unit) + | |
391 | (System_Storage_Unit - 1) - | |
392 | (Start_Bit + CSZ - 1)); | |
59ac57b5 | 393 | |
6797073f | 394 | Set_Normalized_First_Bit |
395 | (Comp, | |
396 | Component_Bit_Offset (Comp) mod | |
397 | System_Storage_Unit); | |
398 | end if; | |
399 | end; | |
400 | end if; | |
401 | ||
402 | Next_Component_Or_Discriminant (Comp); | |
403 | end loop; | |
404 | ||
405 | -- For Ada 2005, we do machine scalar processing, as fully described In | |
406 | -- AI-133. This involves gathering all components which start at the | |
407 | -- same byte offset and processing them together. Same approach is still | |
408 | -- valid in later versions including Ada 2012. | |
409 | ||
410 | else | |
411 | declare | |
412 | Max_Machine_Scalar_Size : constant Uint := | |
413 | UI_From_Int | |
414 | (Standard_Long_Long_Integer_Size); | |
67278d60 | 415 | -- We use this as the maximum machine scalar size |
59ac57b5 | 416 | |
6797073f | 417 | Num_CC : Natural; |
418 | SSU : constant Uint := UI_From_Int (System_Storage_Unit); | |
59ac57b5 | 419 | |
6797073f | 420 | begin |
421 | -- This first loop through components does two things. First it | |
422 | -- deals with the case of components with component clauses whose | |
423 | -- length is greater than the maximum machine scalar size (either | |
424 | -- accepting them or rejecting as needed). Second, it counts the | |
425 | -- number of components with component clauses whose length does | |
426 | -- not exceed this maximum for later processing. | |
67278d60 | 427 | |
6797073f | 428 | Num_CC := 0; |
429 | Comp := First_Component_Or_Discriminant (R); | |
430 | while Present (Comp) loop | |
431 | CC := Component_Clause (Comp); | |
67278d60 | 432 | |
6797073f | 433 | if Present (CC) then |
434 | declare | |
1e3532e7 | 435 | Fbit : constant Uint := Static_Integer (First_Bit (CC)); |
436 | Lbit : constant Uint := Static_Integer (Last_Bit (CC)); | |
67278d60 | 437 | |
6797073f | 438 | begin |
b38e4131 | 439 | -- Case of component with last bit >= max machine scalar |
67278d60 | 440 | |
b38e4131 | 441 | if Lbit >= Max_Machine_Scalar_Size then |
67278d60 | 442 | |
b38e4131 | 443 | -- This is allowed only if first bit is zero, and |
444 | -- last bit + 1 is a multiple of storage unit size. | |
67278d60 | 445 | |
b38e4131 | 446 | if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then |
67278d60 | 447 | |
b38e4131 | 448 | -- This is the case to give a warning if enabled |
67278d60 | 449 | |
b38e4131 | 450 | if Warn_On_Reverse_Bit_Order then |
451 | Error_Msg_N | |
7a41db5b | 452 | ("info: multi-byte field specified with " |
1e3532e7 | 453 | & " non-standard Bit_Order?V?", CC); |
b38e4131 | 454 | |
455 | if Bytes_Big_Endian then | |
456 | Error_Msg_N | |
457 | ("\bytes are not reversed " | |
1e3532e7 | 458 | & "(component is big-endian)?V?", CC); |
b38e4131 | 459 | else |
460 | Error_Msg_N | |
461 | ("\bytes are not reversed " | |
1e3532e7 | 462 | & "(component is little-endian)?V?", CC); |
b38e4131 | 463 | end if; |
464 | end if; | |
67278d60 | 465 | |
7eb0e22f | 466 | -- Give error message for RM 13.5.1(10) violation |
67278d60 | 467 | |
b38e4131 | 468 | else |
469 | Error_Msg_FE | |
470 | ("machine scalar rules not followed for&", | |
471 | First_Bit (CC), Comp); | |
67278d60 | 472 | |
b38e4131 | 473 | Error_Msg_Uint_1 := Lbit; |
474 | Error_Msg_Uint_2 := Max_Machine_Scalar_Size; | |
475 | Error_Msg_F | |
476 | ("\last bit (^) exceeds maximum machine " | |
477 | & "scalar size (^)", | |
478 | First_Bit (CC)); | |
67278d60 | 479 | |
b38e4131 | 480 | if (Lbit + 1) mod SSU /= 0 then |
481 | Error_Msg_Uint_1 := SSU; | |
482 | Error_Msg_F | |
483 | ("\and is not a multiple of Storage_Unit (^) " | |
0cafb066 | 484 | & "(RM 13.4.1(10))", |
b38e4131 | 485 | First_Bit (CC)); |
6797073f | 486 | |
6797073f | 487 | else |
b38e4131 | 488 | Error_Msg_Uint_1 := Fbit; |
489 | Error_Msg_F | |
490 | ("\and first bit (^) is non-zero " | |
0cafb066 | 491 | & "(RM 13.4.1(10))", |
b38e4131 | 492 | First_Bit (CC)); |
67278d60 | 493 | end if; |
6797073f | 494 | end if; |
59ac57b5 | 495 | |
b38e4131 | 496 | -- OK case of machine scalar related component clause, |
497 | -- For now, just count them. | |
59ac57b5 | 498 | |
6797073f | 499 | else |
500 | Num_CC := Num_CC + 1; | |
501 | end if; | |
502 | end; | |
503 | end if; | |
59ac57b5 | 504 | |
6797073f | 505 | Next_Component_Or_Discriminant (Comp); |
506 | end loop; | |
59ac57b5 | 507 | |
6797073f | 508 | -- We need to sort the component clauses on the basis of the |
509 | -- Position values in the clause, so we can group clauses with | |
4a87c513 | 510 | -- the same Position together to determine the relevant machine |
6797073f | 511 | -- scalar size. |
59ac57b5 | 512 | |
6797073f | 513 | Sort_CC : declare |
514 | Comps : array (0 .. Num_CC) of Entity_Id; | |
515 | -- Array to collect component and discriminant entities. The | |
516 | -- data starts at index 1, the 0'th entry is for the sort | |
517 | -- routine. | |
59ac57b5 | 518 | |
6797073f | 519 | function CP_Lt (Op1, Op2 : Natural) return Boolean; |
520 | -- Compare routine for Sort | |
59ac57b5 | 521 | |
6797073f | 522 | procedure CP_Move (From : Natural; To : Natural); |
523 | -- Move routine for Sort | |
59ac57b5 | 524 | |
6797073f | 525 | package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt); |
59ac57b5 | 526 | |
6797073f | 527 | Start : Natural; |
528 | Stop : Natural; | |
529 | -- Start and stop positions in the component list of the set of | |
530 | -- components with the same starting position (that constitute | |
531 | -- components in a single machine scalar). | |
59ac57b5 | 532 | |
6797073f | 533 | MaxL : Uint; |
534 | -- Maximum last bit value of any component in this set | |
59ac57b5 | 535 | |
6797073f | 536 | MSS : Uint; |
537 | -- Corresponding machine scalar size | |
67278d60 | 538 | |
6797073f | 539 | ----------- |
540 | -- CP_Lt -- | |
541 | ----------- | |
67278d60 | 542 | |
6797073f | 543 | function CP_Lt (Op1, Op2 : Natural) return Boolean is |
544 | begin | |
545 | return Position (Component_Clause (Comps (Op1))) < | |
546 | Position (Component_Clause (Comps (Op2))); | |
547 | end CP_Lt; | |
67278d60 | 548 | |
6797073f | 549 | ------------- |
550 | -- CP_Move -- | |
551 | ------------- | |
67278d60 | 552 | |
6797073f | 553 | procedure CP_Move (From : Natural; To : Natural) is |
554 | begin | |
555 | Comps (To) := Comps (From); | |
556 | end CP_Move; | |
67278d60 | 557 | |
4a87c513 | 558 | -- Start of processing for Sort_CC |
59ac57b5 | 559 | |
6797073f | 560 | begin |
b38e4131 | 561 | -- Collect the machine scalar relevant component clauses |
59ac57b5 | 562 | |
6797073f | 563 | Num_CC := 0; |
564 | Comp := First_Component_Or_Discriminant (R); | |
565 | while Present (Comp) loop | |
b38e4131 | 566 | declare |
567 | CC : constant Node_Id := Component_Clause (Comp); | |
568 | ||
569 | begin | |
570 | -- Collect only component clauses whose last bit is less | |
571 | -- than machine scalar size. Any component clause whose | |
572 | -- last bit exceeds this value does not take part in | |
573 | -- machine scalar layout considerations. The test for | |
574 | -- Error_Posted makes sure we exclude component clauses | |
575 | -- for which we already posted an error. | |
576 | ||
577 | if Present (CC) | |
578 | and then not Error_Posted (Last_Bit (CC)) | |
579 | and then Static_Integer (Last_Bit (CC)) < | |
d64221a7 | 580 | Max_Machine_Scalar_Size |
b38e4131 | 581 | then |
582 | Num_CC := Num_CC + 1; | |
583 | Comps (Num_CC) := Comp; | |
584 | end if; | |
585 | end; | |
59ac57b5 | 586 | |
6797073f | 587 | Next_Component_Or_Discriminant (Comp); |
588 | end loop; | |
67278d60 | 589 | |
6797073f | 590 | -- Sort by ascending position number |
67278d60 | 591 | |
6797073f | 592 | Sorting.Sort (Num_CC); |
67278d60 | 593 | |
6797073f | 594 | -- We now have all the components whose size does not exceed |
595 | -- the max machine scalar value, sorted by starting position. | |
596 | -- In this loop we gather groups of clauses starting at the | |
597 | -- same position, to process them in accordance with AI-133. | |
67278d60 | 598 | |
6797073f | 599 | Stop := 0; |
600 | while Stop < Num_CC loop | |
601 | Start := Stop + 1; | |
602 | Stop := Start; | |
603 | MaxL := | |
604 | Static_Integer | |
605 | (Last_Bit (Component_Clause (Comps (Start)))); | |
67278d60 | 606 | while Stop < Num_CC loop |
6797073f | 607 | if Static_Integer |
608 | (Position (Component_Clause (Comps (Stop + 1)))) = | |
609 | Static_Integer | |
610 | (Position (Component_Clause (Comps (Stop)))) | |
611 | then | |
612 | Stop := Stop + 1; | |
613 | MaxL := | |
614 | UI_Max | |
615 | (MaxL, | |
616 | Static_Integer | |
617 | (Last_Bit | |
618 | (Component_Clause (Comps (Stop))))); | |
619 | else | |
620 | exit; | |
621 | end if; | |
622 | end loop; | |
67278d60 | 623 | |
6797073f | 624 | -- Now we have a group of component clauses from Start to |
625 | -- Stop whose positions are identical, and MaxL is the | |
626 | -- maximum last bit value of any of these components. | |
627 | ||
628 | -- We need to determine the corresponding machine scalar | |
629 | -- size. This loop assumes that machine scalar sizes are | |
630 | -- even, and that each possible machine scalar has twice | |
631 | -- as many bits as the next smaller one. | |
632 | ||
633 | MSS := Max_Machine_Scalar_Size; | |
634 | while MSS mod 2 = 0 | |
635 | and then (MSS / 2) >= SSU | |
636 | and then (MSS / 2) > MaxL | |
637 | loop | |
638 | MSS := MSS / 2; | |
639 | end loop; | |
67278d60 | 640 | |
6797073f | 641 | -- Here is where we fix up the Component_Bit_Offset value |
642 | -- to account for the reverse bit order. Some examples of | |
643 | -- what needs to be done for the case of a machine scalar | |
644 | -- size of 8 are: | |
67278d60 | 645 | |
6797073f | 646 | -- First_Bit .. Last_Bit Component_Bit_Offset |
647 | -- old new old new | |
67278d60 | 648 | |
6797073f | 649 | -- 0 .. 0 7 .. 7 0 7 |
650 | -- 0 .. 1 6 .. 7 0 6 | |
651 | -- 0 .. 2 5 .. 7 0 5 | |
652 | -- 0 .. 7 0 .. 7 0 4 | |
67278d60 | 653 | |
6797073f | 654 | -- 1 .. 1 6 .. 6 1 6 |
655 | -- 1 .. 4 3 .. 6 1 3 | |
656 | -- 4 .. 7 0 .. 3 4 0 | |
67278d60 | 657 | |
6797073f | 658 | -- The rule is that the first bit is obtained by subtracting |
659 | -- the old ending bit from machine scalar size - 1. | |
67278d60 | 660 | |
6797073f | 661 | for C in Start .. Stop loop |
662 | declare | |
663 | Comp : constant Entity_Id := Comps (C); | |
b9e61b2a | 664 | CC : constant Node_Id := Component_Clause (Comp); |
665 | ||
666 | LB : constant Uint := Static_Integer (Last_Bit (CC)); | |
6797073f | 667 | NFB : constant Uint := MSS - Uint_1 - LB; |
668 | NLB : constant Uint := NFB + Esize (Comp) - 1; | |
b9e61b2a | 669 | Pos : constant Uint := Static_Integer (Position (CC)); |
67278d60 | 670 | |
6797073f | 671 | begin |
672 | if Warn_On_Reverse_Bit_Order then | |
673 | Error_Msg_Uint_1 := MSS; | |
674 | Error_Msg_N | |
675 | ("info: reverse bit order in machine " & | |
1e3532e7 | 676 | "scalar of length^?V?", First_Bit (CC)); |
6797073f | 677 | Error_Msg_Uint_1 := NFB; |
678 | Error_Msg_Uint_2 := NLB; | |
679 | ||
680 | if Bytes_Big_Endian then | |
681 | Error_Msg_NE | |
7a41db5b | 682 | ("\big-endian range for component " |
683 | & "& is ^ .. ^?V?", First_Bit (CC), Comp); | |
6797073f | 684 | else |
685 | Error_Msg_NE | |
7a41db5b | 686 | ("\little-endian range for component" |
687 | & "& is ^ .. ^?V?", First_Bit (CC), Comp); | |
67278d60 | 688 | end if; |
6797073f | 689 | end if; |
67278d60 | 690 | |
6797073f | 691 | Set_Component_Bit_Offset (Comp, Pos * SSU + NFB); |
692 | Set_Normalized_First_Bit (Comp, NFB mod SSU); | |
693 | end; | |
67278d60 | 694 | end loop; |
6797073f | 695 | end loop; |
696 | end Sort_CC; | |
697 | end; | |
698 | end if; | |
59ac57b5 | 699 | end Adjust_Record_For_Reverse_Bit_Order; |
700 | ||
1d366b32 | 701 | ------------------------------------- |
702 | -- Alignment_Check_For_Size_Change -- | |
703 | ------------------------------------- | |
d6f39728 | 704 | |
1d366b32 | 705 | procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is |
d6f39728 | 706 | begin |
707 | -- If the alignment is known, and not set by a rep clause, and is | |
708 | -- inconsistent with the size being set, then reset it to unknown, | |
709 | -- we assume in this case that the size overrides the inherited | |
710 | -- alignment, and that the alignment must be recomputed. | |
711 | ||
712 | if Known_Alignment (Typ) | |
713 | and then not Has_Alignment_Clause (Typ) | |
1d366b32 | 714 | and then Size mod (Alignment (Typ) * SSU) /= 0 |
d6f39728 | 715 | then |
716 | Init_Alignment (Typ); | |
717 | end if; | |
1d366b32 | 718 | end Alignment_Check_For_Size_Change; |
d6f39728 | 719 | |
06ef5f86 | 720 | ------------------------------------- |
721 | -- Analyze_Aspects_At_Freeze_Point -- | |
722 | ------------------------------------- | |
723 | ||
724 | procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is | |
725 | ASN : Node_Id; | |
726 | A_Id : Aspect_Id; | |
727 | Ritem : Node_Id; | |
728 | ||
729 | procedure Analyze_Aspect_Default_Value (ASN : Node_Id); | |
730 | -- This routine analyzes an Aspect_Default_[Component_]Value denoted by | |
731 | -- the aspect specification node ASN. | |
732 | ||
37c6e44c | 733 | procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id); |
734 | -- As discussed in the spec of Aspects (see Aspect_Delay declaration), | |
735 | -- a derived type can inherit aspects from its parent which have been | |
736 | -- specified at the time of the derivation using an aspect, as in: | |
737 | -- | |
738 | -- type A is range 1 .. 10 | |
739 | -- with Size => Not_Defined_Yet; | |
740 | -- .. | |
741 | -- type B is new A; | |
742 | -- .. | |
743 | -- Not_Defined_Yet : constant := 64; | |
744 | -- | |
745 | -- In this example, the Size of A is considered to be specified prior | |
746 | -- to the derivation, and thus inherited, even though the value is not | |
747 | -- known at the time of derivation. To deal with this, we use two entity | |
748 | -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A | |
749 | -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in | |
750 | -- the derived type (B here). If this flag is set when the derived type | |
751 | -- is frozen, then this procedure is called to ensure proper inheritance | |
b21edad9 | 752 | -- of all delayed aspects from the parent type. The derived type is E, |
37c6e44c | 753 | -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first |
754 | -- aspect specification node in the Rep_Item chain for the parent type. | |
755 | ||
06ef5f86 | 756 | procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id); |
757 | -- Given an aspect specification node ASN whose expression is an | |
758 | -- optional Boolean, this routines creates the corresponding pragma | |
759 | -- at the freezing point. | |
760 | ||
761 | ---------------------------------- | |
762 | -- Analyze_Aspect_Default_Value -- | |
763 | ---------------------------------- | |
764 | ||
765 | procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is | |
766 | Ent : constant Entity_Id := Entity (ASN); | |
767 | Expr : constant Node_Id := Expression (ASN); | |
768 | Id : constant Node_Id := Identifier (ASN); | |
769 | ||
770 | begin | |
771 | Error_Msg_Name_1 := Chars (Id); | |
772 | ||
773 | if not Is_Type (Ent) then | |
774 | Error_Msg_N ("aspect% can only apply to a type", Id); | |
775 | return; | |
776 | ||
777 | elsif not Is_First_Subtype (Ent) then | |
778 | Error_Msg_N ("aspect% cannot apply to subtype", Id); | |
779 | return; | |
780 | ||
781 | elsif A_Id = Aspect_Default_Value | |
782 | and then not Is_Scalar_Type (Ent) | |
783 | then | |
784 | Error_Msg_N ("aspect% can only be applied to scalar type", Id); | |
785 | return; | |
786 | ||
787 | elsif A_Id = Aspect_Default_Component_Value then | |
788 | if not Is_Array_Type (Ent) then | |
789 | Error_Msg_N ("aspect% can only be applied to array type", Id); | |
790 | return; | |
791 | ||
792 | elsif not Is_Scalar_Type (Component_Type (Ent)) then | |
793 | Error_Msg_N ("aspect% requires scalar components", Id); | |
794 | return; | |
795 | end if; | |
796 | end if; | |
797 | ||
798 | Set_Has_Default_Aspect (Base_Type (Ent)); | |
799 | ||
800 | if Is_Scalar_Type (Ent) then | |
9f36e3fb | 801 | Set_Default_Aspect_Value (Base_Type (Ent), Expr); |
06ef5f86 | 802 | else |
f3d70f08 | 803 | Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr); |
06ef5f86 | 804 | end if; |
805 | end Analyze_Aspect_Default_Value; | |
806 | ||
37c6e44c | 807 | --------------------------------- |
808 | -- Inherit_Delayed_Rep_Aspects -- | |
809 | --------------------------------- | |
810 | ||
811 | procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is | |
812 | P : constant Entity_Id := Entity (ASN); | |
813 | -- Entithy for parent type | |
814 | ||
815 | N : Node_Id; | |
816 | -- Item from Rep_Item chain | |
817 | ||
818 | A : Aspect_Id; | |
819 | ||
820 | begin | |
821 | -- Loop through delayed aspects for the parent type | |
822 | ||
823 | N := ASN; | |
824 | while Present (N) loop | |
825 | if Nkind (N) = N_Aspect_Specification then | |
826 | exit when Entity (N) /= P; | |
827 | ||
828 | if Is_Delayed_Aspect (N) then | |
829 | A := Get_Aspect_Id (Chars (Identifier (N))); | |
830 | ||
831 | -- Process delayed rep aspect. For Boolean attributes it is | |
832 | -- not possible to cancel an attribute once set (the attempt | |
833 | -- to use an aspect with xxx => False is an error) for a | |
834 | -- derived type. So for those cases, we do not have to check | |
835 | -- if a clause has been given for the derived type, since it | |
836 | -- is harmless to set it again if it is already set. | |
837 | ||
838 | case A is | |
839 | ||
840 | -- Alignment | |
841 | ||
842 | when Aspect_Alignment => | |
843 | if not Has_Alignment_Clause (E) then | |
844 | Set_Alignment (E, Alignment (P)); | |
845 | end if; | |
846 | ||
847 | -- Atomic | |
848 | ||
849 | when Aspect_Atomic => | |
850 | if Is_Atomic (P) then | |
851 | Set_Is_Atomic (E); | |
852 | end if; | |
853 | ||
854 | -- Atomic_Components | |
855 | ||
856 | when Aspect_Atomic_Components => | |
857 | if Has_Atomic_Components (P) then | |
858 | Set_Has_Atomic_Components (Base_Type (E)); | |
859 | end if; | |
860 | ||
861 | -- Bit_Order | |
862 | ||
863 | when Aspect_Bit_Order => | |
864 | if Is_Record_Type (E) | |
865 | and then No (Get_Attribute_Definition_Clause | |
866 | (E, Attribute_Bit_Order)) | |
867 | and then Reverse_Bit_Order (P) | |
868 | then | |
869 | Set_Reverse_Bit_Order (Base_Type (E)); | |
870 | end if; | |
871 | ||
872 | -- Component_Size | |
873 | ||
874 | when Aspect_Component_Size => | |
875 | if Is_Array_Type (E) | |
876 | and then not Has_Component_Size_Clause (E) | |
877 | then | |
878 | Set_Component_Size | |
879 | (Base_Type (E), Component_Size (P)); | |
880 | end if; | |
881 | ||
882 | -- Machine_Radix | |
883 | ||
884 | when Aspect_Machine_Radix => | |
885 | if Is_Decimal_Fixed_Point_Type (E) | |
886 | and then not Has_Machine_Radix_Clause (E) | |
887 | then | |
888 | Set_Machine_Radix_10 (E, Machine_Radix_10 (P)); | |
889 | end if; | |
890 | ||
891 | -- Object_Size (also Size which also sets Object_Size) | |
892 | ||
893 | when Aspect_Object_Size | Aspect_Size => | |
894 | if not Has_Size_Clause (E) | |
895 | and then | |
896 | No (Get_Attribute_Definition_Clause | |
897 | (E, Attribute_Object_Size)) | |
898 | then | |
899 | Set_Esize (E, Esize (P)); | |
900 | end if; | |
901 | ||
902 | -- Pack | |
903 | ||
904 | when Aspect_Pack => | |
905 | if not Is_Packed (E) then | |
906 | Set_Is_Packed (Base_Type (E)); | |
907 | ||
908 | if Is_Bit_Packed_Array (P) then | |
909 | Set_Is_Bit_Packed_Array (Base_Type (E)); | |
a88a5773 | 910 | Set_Packed_Array_Impl_Type |
911 | (E, Packed_Array_Impl_Type (P)); | |
37c6e44c | 912 | end if; |
913 | end if; | |
914 | ||
915 | -- Scalar_Storage_Order | |
916 | ||
917 | when Aspect_Scalar_Storage_Order => | |
918 | if (Is_Record_Type (E) or else Is_Array_Type (E)) | |
919 | and then No (Get_Attribute_Definition_Clause | |
e163cac8 | 920 | (E, Attribute_Scalar_Storage_Order)) |
37c6e44c | 921 | and then Reverse_Storage_Order (P) |
922 | then | |
923 | Set_Reverse_Storage_Order (Base_Type (E)); | |
b64082f2 | 924 | |
925 | -- Clear default SSO indications, since the aspect | |
926 | -- overrides the default. | |
927 | ||
928 | Set_SSO_Set_Low_By_Default (Base_Type (E), False); | |
929 | Set_SSO_Set_High_By_Default (Base_Type (E), False); | |
37c6e44c | 930 | end if; |
931 | ||
932 | -- Small | |
933 | ||
934 | when Aspect_Small => | |
935 | if Is_Fixed_Point_Type (E) | |
936 | and then not Has_Small_Clause (E) | |
937 | then | |
938 | Set_Small_Value (E, Small_Value (P)); | |
939 | end if; | |
940 | ||
941 | -- Storage_Size | |
942 | ||
943 | when Aspect_Storage_Size => | |
944 | if (Is_Access_Type (E) or else Is_Task_Type (E)) | |
945 | and then not Has_Storage_Size_Clause (E) | |
946 | then | |
947 | Set_Storage_Size_Variable | |
948 | (Base_Type (E), Storage_Size_Variable (P)); | |
949 | end if; | |
950 | ||
951 | -- Value_Size | |
952 | ||
953 | when Aspect_Value_Size => | |
954 | ||
955 | -- Value_Size is never inherited, it is either set by | |
956 | -- default, or it is explicitly set for the derived | |
957 | -- type. So nothing to do here. | |
958 | ||
959 | null; | |
960 | ||
961 | -- Volatile | |
962 | ||
963 | when Aspect_Volatile => | |
964 | if Is_Volatile (P) then | |
965 | Set_Is_Volatile (E); | |
966 | end if; | |
967 | ||
968 | -- Volatile_Components | |
969 | ||
970 | when Aspect_Volatile_Components => | |
971 | if Has_Volatile_Components (P) then | |
972 | Set_Has_Volatile_Components (Base_Type (E)); | |
973 | end if; | |
974 | ||
975 | -- That should be all the Rep Aspects | |
976 | ||
977 | when others => | |
978 | pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect); | |
979 | null; | |
980 | ||
981 | end case; | |
982 | end if; | |
983 | end if; | |
984 | ||
985 | N := Next_Rep_Item (N); | |
986 | end loop; | |
987 | end Inherit_Delayed_Rep_Aspects; | |
988 | ||
06ef5f86 | 989 | ------------------------------------- |
990 | -- Make_Pragma_From_Boolean_Aspect -- | |
991 | ------------------------------------- | |
992 | ||
993 | procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is | |
994 | Ident : constant Node_Id := Identifier (ASN); | |
995 | A_Name : constant Name_Id := Chars (Ident); | |
996 | A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name); | |
997 | Ent : constant Entity_Id := Entity (ASN); | |
998 | Expr : constant Node_Id := Expression (ASN); | |
999 | Loc : constant Source_Ptr := Sloc (ASN); | |
1000 | ||
1001 | Prag : Node_Id; | |
1002 | ||
1003 | procedure Check_False_Aspect_For_Derived_Type; | |
1004 | -- This procedure checks for the case of a false aspect for a derived | |
1005 | -- type, which improperly tries to cancel an aspect inherited from | |
1006 | -- the parent. | |
1007 | ||
1008 | ----------------------------------------- | |
1009 | -- Check_False_Aspect_For_Derived_Type -- | |
1010 | ----------------------------------------- | |
1011 | ||
1012 | procedure Check_False_Aspect_For_Derived_Type is | |
1013 | Par : Node_Id; | |
1014 | ||
1015 | begin | |
1016 | -- We are only checking derived types | |
1017 | ||
1018 | if not Is_Derived_Type (E) then | |
1019 | return; | |
1020 | end if; | |
1021 | ||
1022 | Par := Nearest_Ancestor (E); | |
1023 | ||
1024 | case A_Id is | |
1025 | when Aspect_Atomic | Aspect_Shared => | |
1026 | if not Is_Atomic (Par) then | |
1027 | return; | |
1028 | end if; | |
1029 | ||
1030 | when Aspect_Atomic_Components => | |
1031 | if not Has_Atomic_Components (Par) then | |
1032 | return; | |
1033 | end if; | |
1034 | ||
1035 | when Aspect_Discard_Names => | |
1036 | if not Discard_Names (Par) then | |
1037 | return; | |
1038 | end if; | |
1039 | ||
1040 | when Aspect_Pack => | |
1041 | if not Is_Packed (Par) then | |
1042 | return; | |
1043 | end if; | |
1044 | ||
1045 | when Aspect_Unchecked_Union => | |
1046 | if not Is_Unchecked_Union (Par) then | |
1047 | return; | |
1048 | end if; | |
1049 | ||
1050 | when Aspect_Volatile => | |
1051 | if not Is_Volatile (Par) then | |
1052 | return; | |
1053 | end if; | |
1054 | ||
1055 | when Aspect_Volatile_Components => | |
1056 | if not Has_Volatile_Components (Par) then | |
1057 | return; | |
1058 | end if; | |
1059 | ||
1060 | when others => | |
1061 | return; | |
1062 | end case; | |
1063 | ||
1064 | -- Fall through means we are canceling an inherited aspect | |
1065 | ||
1066 | Error_Msg_Name_1 := A_Name; | |
37c6e44c | 1067 | Error_Msg_NE |
1068 | ("derived type& inherits aspect%, cannot cancel", Expr, E); | |
06ef5f86 | 1069 | |
1070 | end Check_False_Aspect_For_Derived_Type; | |
1071 | ||
1072 | -- Start of processing for Make_Pragma_From_Boolean_Aspect | |
1073 | ||
1074 | begin | |
37c6e44c | 1075 | -- Note that we know Expr is present, because for a missing Expr |
1076 | -- argument, we knew it was True and did not need to delay the | |
1077 | -- evaluation to the freeze point. | |
1078 | ||
06ef5f86 | 1079 | if Is_False (Static_Boolean (Expr)) then |
1080 | Check_False_Aspect_For_Derived_Type; | |
1081 | ||
1082 | else | |
1083 | Prag := | |
1084 | Make_Pragma (Loc, | |
1085 | Pragma_Argument_Associations => New_List ( | |
57cd943b | 1086 | Make_Pragma_Argument_Association (Sloc (Ident), |
1087 | Expression => New_Occurrence_Of (Ent, Sloc (Ident)))), | |
1088 | ||
06ef5f86 | 1089 | Pragma_Identifier => |
1090 | Make_Identifier (Sloc (Ident), Chars (Ident))); | |
1091 | ||
1092 | Set_From_Aspect_Specification (Prag, True); | |
1093 | Set_Corresponding_Aspect (Prag, ASN); | |
1094 | Set_Aspect_Rep_Item (ASN, Prag); | |
1095 | Set_Is_Delayed_Aspect (Prag); | |
1096 | Set_Parent (Prag, ASN); | |
1097 | end if; | |
06ef5f86 | 1098 | end Make_Pragma_From_Boolean_Aspect; |
1099 | ||
1100 | -- Start of processing for Analyze_Aspects_At_Freeze_Point | |
1101 | ||
1102 | begin | |
29a9d4be | 1103 | -- Must be visible in current scope |
06ef5f86 | 1104 | |
ace3389d | 1105 | if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then |
06ef5f86 | 1106 | return; |
1107 | end if; | |
1108 | ||
1109 | -- Look for aspect specification entries for this entity | |
1110 | ||
1111 | ASN := First_Rep_Item (E); | |
06ef5f86 | 1112 | while Present (ASN) loop |
37c6e44c | 1113 | if Nkind (ASN) = N_Aspect_Specification then |
1114 | exit when Entity (ASN) /= E; | |
06ef5f86 | 1115 | |
37c6e44c | 1116 | if Is_Delayed_Aspect (ASN) then |
1117 | A_Id := Get_Aspect_Id (ASN); | |
1118 | ||
1119 | case A_Id is | |
e4c87fa5 | 1120 | |
37c6e44c | 1121 | -- For aspects whose expression is an optional Boolean, make |
7d6fb253 | 1122 | -- the corresponding pragma at the freeze point. |
06ef5f86 | 1123 | |
7d6fb253 | 1124 | when Boolean_Aspects | |
1125 | Library_Unit_Aspects => | |
1126 | Make_Pragma_From_Boolean_Aspect (ASN); | |
06ef5f86 | 1127 | |
37c6e44c | 1128 | -- Special handling for aspects that don't correspond to |
1129 | -- pragmas/attributes. | |
06ef5f86 | 1130 | |
7d6fb253 | 1131 | when Aspect_Default_Value | |
1132 | Aspect_Default_Component_Value => | |
1133 | Analyze_Aspect_Default_Value (ASN); | |
06ef5f86 | 1134 | |
37c6e44c | 1135 | -- Ditto for iterator aspects, because the corresponding |
1136 | -- attributes may not have been analyzed yet. | |
af9fed8f | 1137 | |
7d6fb253 | 1138 | when Aspect_Constant_Indexing | |
1139 | Aspect_Variable_Indexing | | |
1140 | Aspect_Default_Iterator | | |
1141 | Aspect_Iterator_Element => | |
1142 | Analyze (Expression (ASN)); | |
af9fed8f | 1143 | |
7d6fb253 | 1144 | if Etype (Expression (ASN)) = Any_Type then |
1145 | Error_Msg_NE | |
1146 | ("\aspect must be fully defined before & is frozen", | |
1147 | ASN, E); | |
1148 | end if; | |
b3f8228a | 1149 | |
7d6fb253 | 1150 | when Aspect_Iterable => |
1151 | Validate_Iterable_Aspect (E, ASN); | |
1152 | ||
1153 | when others => | |
1154 | null; | |
37c6e44c | 1155 | end case; |
06ef5f86 | 1156 | |
37c6e44c | 1157 | Ritem := Aspect_Rep_Item (ASN); |
06ef5f86 | 1158 | |
37c6e44c | 1159 | if Present (Ritem) then |
1160 | Analyze (Ritem); | |
1161 | end if; | |
06ef5f86 | 1162 | end if; |
1163 | end if; | |
1164 | ||
1165 | Next_Rep_Item (ASN); | |
1166 | end loop; | |
37c6e44c | 1167 | |
1168 | -- This is where we inherit delayed rep aspects from our parent. Note | |
1169 | -- that if we fell out of the above loop with ASN non-empty, it means | |
1170 | -- we hit an aspect for an entity other than E, and it must be the | |
1171 | -- type from which we were derived. | |
1172 | ||
1173 | if May_Inherit_Delayed_Rep_Aspects (E) then | |
1174 | Inherit_Delayed_Rep_Aspects (ASN); | |
1175 | end if; | |
06ef5f86 | 1176 | end Analyze_Aspects_At_Freeze_Point; |
1177 | ||
ae888dbd | 1178 | ----------------------------------- |
1179 | -- Analyze_Aspect_Specifications -- | |
1180 | ----------------------------------- | |
1181 | ||
21ea3a4f | 1182 | procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is |
e2bf777d | 1183 | procedure Decorate (Asp : Node_Id; Prag : Node_Id); |
c4369687 | 1184 | -- Establish linkages between an aspect and its corresponding |
e2bf777d | 1185 | -- pragma. |
5ddd846b | 1186 | |
50e44732 | 1187 | procedure Insert_After_SPARK_Mode |
1188 | (Prag : Node_Id; | |
1189 | Ins_Nod : Node_Id; | |
1190 | Decls : List_Id); | |
e2bf777d | 1191 | -- Subsidiary to the analysis of aspects Abstract_State, Initializes, |
1192 | -- Initial_Condition and Refined_State. Insert node Prag before node | |
c4369687 | 1193 | -- Ins_Nod. If Ins_Nod is for pragma SPARK_Mode, then skip SPARK_Mode. |
1194 | -- Decls is the associated declarative list where Prag is to reside. | |
e2bf777d | 1195 | |
1196 | procedure Insert_Pragma (Prag : Node_Id); | |
1197 | -- Subsidiary to the analysis of aspects Attach_Handler, Contract_Cases, | |
1198 | -- Depends, Global, Post, Pre, Refined_Depends and Refined_Global. | |
1199 | -- Insert pragma Prag such that it mimics the placement of a source | |
1200 | -- pragma of the same kind. | |
1201 | -- | |
1202 | -- procedure Proc (Formal : ...) with Global => ...; | |
1203 | -- | |
1204 | -- procedure Proc (Formal : ...); | |
1205 | -- pragma Global (...); | |
1206 | ||
1207 | -------------- | |
1208 | -- Decorate -- | |
1209 | -------------- | |
1210 | ||
1211 | procedure Decorate (Asp : Node_Id; Prag : Node_Id) is | |
5ddd846b | 1212 | begin |
5cc6f0cf | 1213 | Set_Aspect_Rep_Item (Asp, Prag); |
5ddd846b | 1214 | Set_Corresponding_Aspect (Prag, Asp); |
1215 | Set_From_Aspect_Specification (Prag); | |
5ddd846b | 1216 | Set_Parent (Prag, Asp); |
e2bf777d | 1217 | end Decorate; |
f0813d71 | 1218 | |
50e44732 | 1219 | ----------------------------- |
1220 | -- Insert_After_SPARK_Mode -- | |
1221 | ----------------------------- | |
1222 | ||
1223 | procedure Insert_After_SPARK_Mode | |
1224 | (Prag : Node_Id; | |
1225 | Ins_Nod : Node_Id; | |
1226 | Decls : List_Id) | |
1227 | is | |
1228 | Decl : Node_Id := Ins_Nod; | |
1229 | ||
1230 | begin | |
1231 | -- Skip SPARK_Mode | |
1232 | ||
1233 | if Present (Decl) | |
1234 | and then Nkind (Decl) = N_Pragma | |
1235 | and then Pragma_Name (Decl) = Name_SPARK_Mode | |
1236 | then | |
1237 | Decl := Next (Decl); | |
1238 | end if; | |
1239 | ||
1240 | if Present (Decl) then | |
1241 | Insert_Before (Decl, Prag); | |
1242 | ||
1243 | -- Aitem acts as the last declaration | |
1244 | ||
1245 | else | |
1246 | Append_To (Decls, Prag); | |
1247 | end if; | |
1248 | end Insert_After_SPARK_Mode; | |
1249 | ||
e2bf777d | 1250 | ------------------- |
1251 | -- Insert_Pragma -- | |
1252 | ------------------- | |
c1006d6d | 1253 | |
e2bf777d | 1254 | procedure Insert_Pragma (Prag : Node_Id) is |
1255 | Aux : Node_Id; | |
1256 | Decl : Node_Id; | |
c1006d6d | 1257 | |
1258 | begin | |
1259 | -- When the context is a library unit, the pragma is added to the | |
1260 | -- Pragmas_After list. | |
1261 | ||
1262 | if Nkind (Parent (N)) = N_Compilation_Unit then | |
1263 | Aux := Aux_Decls_Node (Parent (N)); | |
1264 | ||
1265 | if No (Pragmas_After (Aux)) then | |
1266 | Set_Pragmas_After (Aux, New_List); | |
1267 | end if; | |
1268 | ||
1269 | Prepend (Prag, Pragmas_After (Aux)); | |
1270 | ||
1271 | -- Pragmas associated with subprogram bodies are inserted in the | |
1272 | -- declarative part. | |
1273 | ||
1274 | elsif Nkind (N) = N_Subprogram_Body then | |
e2bf777d | 1275 | if Present (Declarations (N)) then |
d324c418 | 1276 | |
e2bf777d | 1277 | -- Skip other internally generated pragmas from aspects to find |
1278 | -- the proper insertion point. As a result the order of pragmas | |
1279 | -- is the same as the order of aspects. | |
d324c418 | 1280 | |
607bc8f5 | 1281 | -- As precondition pragmas generated from conjuncts in the |
1282 | -- precondition aspect are presented in reverse order to | |
1283 | -- Insert_Pragma, insert them in the correct order here by not | |
1284 | -- skipping previously inserted precondition pragmas when the | |
1285 | -- current pragma is a precondition. | |
1286 | ||
e2bf777d | 1287 | Decl := First (Declarations (N)); |
1288 | while Present (Decl) loop | |
1289 | if Nkind (Decl) = N_Pragma | |
1290 | and then From_Aspect_Specification (Decl) | |
607bc8f5 | 1291 | and then not (Get_Pragma_Id (Decl) = Pragma_Precondition |
1292 | and then | |
1293 | Get_Pragma_Id (Prag) = Pragma_Precondition) | |
e2bf777d | 1294 | then |
1295 | Next (Decl); | |
d324c418 | 1296 | else |
e2bf777d | 1297 | exit; |
d324c418 | 1298 | end if; |
e2bf777d | 1299 | end loop; |
1300 | ||
1301 | if Present (Decl) then | |
1302 | Insert_Before (Decl, Prag); | |
1303 | else | |
1304 | Append (Prag, Declarations (N)); | |
1305 | end if; | |
1306 | else | |
1307 | Set_Declarations (N, New_List (Prag)); | |
d324c418 | 1308 | end if; |
c1006d6d | 1309 | |
1310 | -- Default | |
1311 | ||
1312 | else | |
1313 | Insert_After (N, Prag); | |
c1006d6d | 1314 | end if; |
e2bf777d | 1315 | end Insert_Pragma; |
c1006d6d | 1316 | |
1317 | -- Local variables | |
1318 | ||
ae888dbd | 1319 | Aspect : Node_Id; |
d74fc39a | 1320 | Aitem : Node_Id; |
ae888dbd | 1321 | Ent : Node_Id; |
ae888dbd | 1322 | |
21ea3a4f | 1323 | L : constant List_Id := Aspect_Specifications (N); |
1324 | ||
ae888dbd | 1325 | Ins_Node : Node_Id := N; |
89f1e35c | 1326 | -- Insert pragmas/attribute definition clause after this node when no |
1327 | -- delayed analysis is required. | |
d74fc39a | 1328 | |
f0813d71 | 1329 | -- Start of processing for Analyze_Aspect_Specifications |
1330 | ||
d74fc39a | 1331 | -- The general processing involves building an attribute definition |
89f1e35c | 1332 | -- clause or a pragma node that corresponds to the aspect. Then in order |
1333 | -- to delay the evaluation of this aspect to the freeze point, we attach | |
1334 | -- the corresponding pragma/attribute definition clause to the aspect | |
1335 | -- specification node, which is then placed in the Rep Item chain. In | |
1336 | -- this case we mark the entity by setting the flag Has_Delayed_Aspects | |
1337 | -- and we evaluate the rep item at the freeze point. When the aspect | |
1338 | -- doesn't have a corresponding pragma/attribute definition clause, then | |
1339 | -- its analysis is simply delayed at the freeze point. | |
1340 | ||
1341 | -- Some special cases don't require delay analysis, thus the aspect is | |
1342 | -- analyzed right now. | |
1343 | ||
51ea9c94 | 1344 | -- Note that there is a special handling for Pre, Post, Test_Case, |
e66f4e2a | 1345 | -- Contract_Cases aspects. In these cases, we do not have to worry |
51ea9c94 | 1346 | -- about delay issues, since the pragmas themselves deal with delay |
1347 | -- of visibility for the expression analysis. Thus, we just insert | |
1348 | -- the pragma after the node N. | |
ae888dbd | 1349 | |
1350 | begin | |
21ea3a4f | 1351 | pragma Assert (Present (L)); |
1352 | ||
6fb3c314 | 1353 | -- Loop through aspects |
f93e7257 | 1354 | |
ae888dbd | 1355 | Aspect := First (L); |
21ea3a4f | 1356 | Aspect_Loop : while Present (Aspect) loop |
0fd13d32 | 1357 | Analyze_One_Aspect : declare |
94153a42 | 1358 | Expr : constant Node_Id := Expression (Aspect); |
89f1e35c | 1359 | Id : constant Node_Id := Identifier (Aspect); |
1360 | Loc : constant Source_Ptr := Sloc (Aspect); | |
94153a42 | 1361 | Nam : constant Name_Id := Chars (Id); |
1362 | A_Id : constant Aspect_Id := Get_Aspect_Id (Nam); | |
ae888dbd | 1363 | Anod : Node_Id; |
1364 | ||
37c6e44c | 1365 | Delay_Required : Boolean; |
89f1e35c | 1366 | -- Set False if delay is not required |
1367 | ||
c0793fff | 1368 | Eloc : Source_Ptr := No_Location; |
1369 | -- Source location of expression, modified when we split PPC's. It | |
1370 | -- is set below when Expr is present. | |
39e1f22f | 1371 | |
89f1e35c | 1372 | procedure Analyze_Aspect_External_Or_Link_Name; |
0fd13d32 | 1373 | -- Perform analysis of the External_Name or Link_Name aspects |
21ea3a4f | 1374 | |
89f1e35c | 1375 | procedure Analyze_Aspect_Implicit_Dereference; |
9ab32fe9 | 1376 | -- Perform analysis of the Implicit_Dereference aspects |
0fd13d32 | 1377 | |
1378 | procedure Make_Aitem_Pragma | |
1379 | (Pragma_Argument_Associations : List_Id; | |
1380 | Pragma_Name : Name_Id); | |
1381 | -- This is a wrapper for Make_Pragma used for converting aspects | |
1382 | -- to pragmas. It takes care of Sloc (set from Loc) and building | |
1383 | -- the pragma identifier from the given name. In addition the | |
1384 | -- flags Class_Present and Split_PPC are set from the aspect | |
1385 | -- node, as well as Is_Ignored. This routine also sets the | |
1386 | -- From_Aspect_Specification in the resulting pragma node to | |
1387 | -- True, and sets Corresponding_Aspect to point to the aspect. | |
1388 | -- The resulting pragma is assigned to Aitem. | |
21ea3a4f | 1389 | |
89f1e35c | 1390 | ------------------------------------------ |
1391 | -- Analyze_Aspect_External_Or_Link_Name -- | |
1392 | ------------------------------------------ | |
1393 | ||
1394 | procedure Analyze_Aspect_External_Or_Link_Name is | |
21ea3a4f | 1395 | begin |
89f1e35c | 1396 | -- Verify that there is an Import/Export aspect defined for the |
1397 | -- entity. The processing of that aspect in turn checks that | |
1398 | -- there is a Convention aspect declared. The pragma is | |
1399 | -- constructed when processing the Convention aspect. | |
21ea3a4f | 1400 | |
89f1e35c | 1401 | declare |
1402 | A : Node_Id; | |
21ea3a4f | 1403 | |
89f1e35c | 1404 | begin |
1405 | A := First (L); | |
89f1e35c | 1406 | while Present (A) loop |
18393965 | 1407 | exit when Nam_In (Chars (Identifier (A)), Name_Export, |
1408 | Name_Import); | |
89f1e35c | 1409 | Next (A); |
1410 | end loop; | |
21ea3a4f | 1411 | |
89f1e35c | 1412 | if No (A) then |
1413 | Error_Msg_N | |
51ea9c94 | 1414 | ("missing Import/Export for Link/External name", |
8a1e3cde | 1415 | Aspect); |
89f1e35c | 1416 | end if; |
1417 | end; | |
1418 | end Analyze_Aspect_External_Or_Link_Name; | |
21ea3a4f | 1419 | |
89f1e35c | 1420 | ----------------------------------------- |
1421 | -- Analyze_Aspect_Implicit_Dereference -- | |
1422 | ----------------------------------------- | |
21ea3a4f | 1423 | |
89f1e35c | 1424 | procedure Analyze_Aspect_Implicit_Dereference is |
1425 | begin | |
b9e61b2a | 1426 | if not Is_Type (E) or else not Has_Discriminants (E) then |
89f1e35c | 1427 | Error_Msg_N |
51ea9c94 | 1428 | ("aspect must apply to a type with discriminants", N); |
21ea3a4f | 1429 | |
89f1e35c | 1430 | else |
1431 | declare | |
1432 | Disc : Entity_Id; | |
21ea3a4f | 1433 | |
89f1e35c | 1434 | begin |
1435 | Disc := First_Discriminant (E); | |
89f1e35c | 1436 | while Present (Disc) loop |
1437 | if Chars (Expr) = Chars (Disc) | |
1438 | and then Ekind (Etype (Disc)) = | |
1439 | E_Anonymous_Access_Type | |
1440 | then | |
1441 | Set_Has_Implicit_Dereference (E); | |
1442 | Set_Has_Implicit_Dereference (Disc); | |
1443 | return; | |
1444 | end if; | |
21ea3a4f | 1445 | |
89f1e35c | 1446 | Next_Discriminant (Disc); |
1447 | end loop; | |
21ea3a4f | 1448 | |
89f1e35c | 1449 | -- Error if no proper access discriminant. |
21ea3a4f | 1450 | |
89f1e35c | 1451 | Error_Msg_NE |
1452 | ("not an access discriminant of&", Expr, E); | |
1453 | end; | |
1454 | end if; | |
1455 | end Analyze_Aspect_Implicit_Dereference; | |
21ea3a4f | 1456 | |
0fd13d32 | 1457 | ----------------------- |
1458 | -- Make_Aitem_Pragma -- | |
1459 | ----------------------- | |
1460 | ||
1461 | procedure Make_Aitem_Pragma | |
1462 | (Pragma_Argument_Associations : List_Id; | |
1463 | Pragma_Name : Name_Id) | |
1464 | is | |
b855559d | 1465 | Args : List_Id := Pragma_Argument_Associations; |
1466 | ||
0fd13d32 | 1467 | begin |
1468 | -- We should never get here if aspect was disabled | |
1469 | ||
1470 | pragma Assert (not Is_Disabled (Aspect)); | |
1471 | ||
056dc987 | 1472 | -- Certain aspects allow for an optional name or expression. Do |
1473 | -- not generate a pragma with empty argument association list. | |
b855559d | 1474 | |
1475 | if No (Args) or else No (Expression (First (Args))) then | |
1476 | Args := No_List; | |
1477 | end if; | |
1478 | ||
0fd13d32 | 1479 | -- Build the pragma |
1480 | ||
1481 | Aitem := | |
1482 | Make_Pragma (Loc, | |
b855559d | 1483 | Pragma_Argument_Associations => Args, |
0fd13d32 | 1484 | Pragma_Identifier => |
1485 | Make_Identifier (Sloc (Id), Pragma_Name), | |
9ab32fe9 | 1486 | Class_Present => Class_Present (Aspect), |
1487 | Split_PPC => Split_PPC (Aspect)); | |
0fd13d32 | 1488 | |
1489 | -- Set additional semantic fields | |
1490 | ||
1491 | if Is_Ignored (Aspect) then | |
1492 | Set_Is_Ignored (Aitem); | |
57d8d1f3 | 1493 | elsif Is_Checked (Aspect) then |
a5109493 | 1494 | Set_Is_Checked (Aitem); |
0fd13d32 | 1495 | end if; |
1496 | ||
1497 | Set_Corresponding_Aspect (Aitem, Aspect); | |
1498 | Set_From_Aspect_Specification (Aitem, True); | |
1499 | end Make_Aitem_Pragma; | |
1500 | ||
1501 | -- Start of processing for Analyze_One_Aspect | |
1502 | ||
ae888dbd | 1503 | begin |
2d1acfa7 | 1504 | -- Skip aspect if already analyzed, to avoid looping in some cases |
fb7f2fc4 | 1505 | |
1506 | if Analyzed (Aspect) then | |
1507 | goto Continue; | |
1508 | end if; | |
1509 | ||
ef957022 | 1510 | -- Skip looking at aspect if it is totally disabled. Just mark it |
1511 | -- as such for later reference in the tree. This also sets the | |
1512 | -- Is_Ignored and Is_Checked flags appropriately. | |
51ea9c94 | 1513 | |
1514 | Check_Applicable_Policy (Aspect); | |
1515 | ||
1516 | if Is_Disabled (Aspect) then | |
1517 | goto Continue; | |
1518 | end if; | |
1519 | ||
c0793fff | 1520 | -- Set the source location of expression, used in the case of |
1521 | -- a failed precondition/postcondition or invariant. Note that | |
1522 | -- the source location of the expression is not usually the best | |
1523 | -- choice here. For example, it gets located on the last AND | |
1524 | -- keyword in a chain of boolean expressiond AND'ed together. | |
1525 | -- It is best to put the message on the first character of the | |
1526 | -- assertion, which is the effect of the First_Node call here. | |
1527 | ||
1528 | if Present (Expr) then | |
1529 | Eloc := Sloc (First_Node (Expr)); | |
1530 | end if; | |
1531 | ||
d7ed83a2 | 1532 | -- Check restriction No_Implementation_Aspect_Specifications |
1533 | ||
c171e1be | 1534 | if Implementation_Defined_Aspect (A_Id) then |
d7ed83a2 | 1535 | Check_Restriction |
1536 | (No_Implementation_Aspect_Specifications, Aspect); | |
1537 | end if; | |
1538 | ||
1539 | -- Check restriction No_Specification_Of_Aspect | |
1540 | ||
1541 | Check_Restriction_No_Specification_Of_Aspect (Aspect); | |
1542 | ||
f67ed4f5 | 1543 | -- Mark aspect analyzed (actual analysis is delayed till later) |
d7ed83a2 | 1544 | |
fb7f2fc4 | 1545 | Set_Analyzed (Aspect); |
d74fc39a | 1546 | Set_Entity (Aspect, E); |
1547 | Ent := New_Occurrence_Of (E, Sloc (Id)); | |
1548 | ||
1e3c4ae6 | 1549 | -- Check for duplicate aspect. Note that the Comes_From_Source |
1550 | -- test allows duplicate Pre/Post's that we generate internally | |
1551 | -- to escape being flagged here. | |
ae888dbd | 1552 | |
6c545057 | 1553 | if No_Duplicates_Allowed (A_Id) then |
1554 | Anod := First (L); | |
1555 | while Anod /= Aspect loop | |
c171e1be | 1556 | if Comes_From_Source (Aspect) |
1557 | and then Same_Aspect (A_Id, Get_Aspect_Id (Anod)) | |
6c545057 | 1558 | then |
1559 | Error_Msg_Name_1 := Nam; | |
1560 | Error_Msg_Sloc := Sloc (Anod); | |
39e1f22f | 1561 | |
6c545057 | 1562 | -- Case of same aspect specified twice |
39e1f22f | 1563 | |
6c545057 | 1564 | if Class_Present (Anod) = Class_Present (Aspect) then |
1565 | if not Class_Present (Anod) then | |
1566 | Error_Msg_NE | |
1567 | ("aspect% for & previously given#", | |
1568 | Id, E); | |
1569 | else | |
1570 | Error_Msg_NE | |
1571 | ("aspect `%''Class` for & previously given#", | |
1572 | Id, E); | |
1573 | end if; | |
39e1f22f | 1574 | end if; |
6c545057 | 1575 | end if; |
ae888dbd | 1576 | |
6c545057 | 1577 | Next (Anod); |
1578 | end loop; | |
1579 | end if; | |
ae888dbd | 1580 | |
4db325e6 | 1581 | -- Check some general restrictions on language defined aspects |
1582 | ||
c171e1be | 1583 | if not Implementation_Defined_Aspect (A_Id) then |
4db325e6 | 1584 | Error_Msg_Name_1 := Nam; |
1585 | ||
1586 | -- Not allowed for renaming declarations | |
1587 | ||
1588 | if Nkind (N) in N_Renaming_Declaration then | |
1589 | Error_Msg_N | |
1590 | ("aspect % not allowed for renaming declaration", | |
1591 | Aspect); | |
1592 | end if; | |
1593 | ||
1594 | -- Not allowed for formal type declarations | |
1595 | ||
1596 | if Nkind (N) = N_Formal_Type_Declaration then | |
1597 | Error_Msg_N | |
1598 | ("aspect % not allowed for formal type declaration", | |
1599 | Aspect); | |
1600 | end if; | |
1601 | end if; | |
1602 | ||
7d20685d | 1603 | -- Copy expression for later processing by the procedures |
1604 | -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations] | |
1605 | ||
1606 | Set_Entity (Id, New_Copy_Tree (Expr)); | |
1607 | ||
37c6e44c | 1608 | -- Set Delay_Required as appropriate to aspect |
1609 | ||
1610 | case Aspect_Delay (A_Id) is | |
1611 | when Always_Delay => | |
1612 | Delay_Required := True; | |
1613 | ||
1614 | when Never_Delay => | |
1615 | Delay_Required := False; | |
1616 | ||
1617 | when Rep_Aspect => | |
1618 | ||
1619 | -- If expression has the form of an integer literal, then | |
1620 | -- do not delay, since we know the value cannot change. | |
1621 | -- This optimization catches most rep clause cases. | |
1622 | ||
1623 | if (Present (Expr) and then Nkind (Expr) = N_Integer_Literal) | |
1624 | or else (A_Id in Boolean_Aspects and then No (Expr)) | |
1625 | then | |
1626 | Delay_Required := False; | |
1627 | else | |
1628 | Delay_Required := True; | |
1629 | Set_Has_Delayed_Rep_Aspects (E); | |
1630 | end if; | |
1631 | end case; | |
1632 | ||
ae888dbd | 1633 | -- Processing based on specific aspect |
1634 | ||
d74fc39a | 1635 | case A_Id is |
ae888dbd | 1636 | |
1637 | -- No_Aspect should be impossible | |
1638 | ||
1639 | when No_Aspect => | |
1640 | raise Program_Error; | |
1641 | ||
89f1e35c | 1642 | -- Case 1: Aspects corresponding to attribute definition |
1643 | -- clauses. | |
ae888dbd | 1644 | |
b7b74740 | 1645 | when Aspect_Address | |
1646 | Aspect_Alignment | | |
1647 | Aspect_Bit_Order | | |
1648 | Aspect_Component_Size | | |
89f1e35c | 1649 | Aspect_Constant_Indexing | |
89f1e35c | 1650 | Aspect_Default_Iterator | |
1651 | Aspect_Dispatching_Domain | | |
b7b74740 | 1652 | Aspect_External_Tag | |
1653 | Aspect_Input | | |
b3f8228a | 1654 | Aspect_Iterable | |
89f1e35c | 1655 | Aspect_Iterator_Element | |
b7b74740 | 1656 | Aspect_Machine_Radix | |
1657 | Aspect_Object_Size | | |
1658 | Aspect_Output | | |
1659 | Aspect_Read | | |
1660 | Aspect_Scalar_Storage_Order | | |
1661 | Aspect_Size | | |
1662 | Aspect_Small | | |
1663 | Aspect_Simple_Storage_Pool | | |
1664 | Aspect_Storage_Pool | | |
b7b74740 | 1665 | Aspect_Stream_Size | |
1666 | Aspect_Value_Size | | |
89f1e35c | 1667 | Aspect_Variable_Indexing | |
b7b74740 | 1668 | Aspect_Write => |
d74fc39a | 1669 | |
89f1e35c | 1670 | -- Indexing aspects apply only to tagged type |
1671 | ||
1672 | if (A_Id = Aspect_Constant_Indexing | |
37c6e44c | 1673 | or else |
1674 | A_Id = Aspect_Variable_Indexing) | |
89f1e35c | 1675 | and then not (Is_Type (E) |
1676 | and then Is_Tagged_Type (E)) | |
1677 | then | |
05987af3 | 1678 | Error_Msg_N |
1679 | ("indexing aspect can only apply to a tagged type", | |
3f4c9ffc | 1680 | Aspect); |
89f1e35c | 1681 | goto Continue; |
1682 | end if; | |
1683 | ||
39616053 | 1684 | -- For the case of aspect Address, we don't consider that we |
588e7f97 | 1685 | -- know the entity is never set in the source, since it is |
1686 | -- is likely aliasing is occurring. | |
1687 | ||
1688 | -- Note: one might think that the analysis of the resulting | |
1689 | -- attribute definition clause would take care of that, but | |
1690 | -- that's not the case since it won't be from source. | |
1691 | ||
1692 | if A_Id = Aspect_Address then | |
1693 | Set_Never_Set_In_Source (E, False); | |
1694 | end if; | |
1695 | ||
5ac76cee | 1696 | -- Correctness of the profile of a stream operation is |
1697 | -- verified at the freeze point, but we must detect the | |
1698 | -- illegal specification of this aspect for a subtype now, | |
1699 | -- to prevent malformed rep_item chains. | |
1700 | ||
cda40848 | 1701 | if (A_Id = Aspect_Input or else |
1702 | A_Id = Aspect_Output or else | |
1703 | A_Id = Aspect_Read or else | |
1704 | A_Id = Aspect_Write) | |
5ac76cee | 1705 | and not Is_First_Subtype (E) |
1706 | then | |
1707 | Error_Msg_N | |
1708 | ("local name must be a first subtype", Aspect); | |
1709 | goto Continue; | |
1710 | end if; | |
1711 | ||
d74fc39a | 1712 | -- Construct the attribute definition clause |
1713 | ||
1714 | Aitem := | |
94153a42 | 1715 | Make_Attribute_Definition_Clause (Loc, |
d74fc39a | 1716 | Name => Ent, |
ae888dbd | 1717 | Chars => Chars (Id), |
1718 | Expression => Relocate_Node (Expr)); | |
1719 | ||
af9a0cc3 | 1720 | -- If the address is specified, then we treat the entity as |
41f06abf | 1721 | -- referenced, to avoid spurious warnings. This is analogous |
1722 | -- to what is done with an attribute definition clause, but | |
1723 | -- here we don't want to generate a reference because this | |
1724 | -- is the point of definition of the entity. | |
1725 | ||
1726 | if A_Id = Aspect_Address then | |
1727 | Set_Referenced (E); | |
1728 | end if; | |
1729 | ||
51ea9c94 | 1730 | -- Case 2: Aspects corresponding to pragmas |
d74fc39a | 1731 | |
89f1e35c | 1732 | -- Case 2a: Aspects corresponding to pragmas with two |
1733 | -- arguments, where the first argument is a local name | |
1734 | -- referring to the entity, and the second argument is the | |
1735 | -- aspect definition expression. | |
ae888dbd | 1736 | |
04ae062f | 1737 | -- Linker_Section/Suppress/Unsuppress |
0fd13d32 | 1738 | |
04ae062f | 1739 | when Aspect_Linker_Section | |
1740 | Aspect_Suppress | | |
1741 | Aspect_Unsuppress => | |
ae888dbd | 1742 | |
0fd13d32 | 1743 | Make_Aitem_Pragma |
1744 | (Pragma_Argument_Associations => New_List ( | |
1745 | Make_Pragma_Argument_Association (Loc, | |
1746 | Expression => New_Occurrence_Of (E, Loc)), | |
1747 | Make_Pragma_Argument_Association (Sloc (Expr), | |
1748 | Expression => Relocate_Node (Expr))), | |
1749 | Pragma_Name => Chars (Id)); | |
57cd943b | 1750 | |
0fd13d32 | 1751 | -- Synchronization |
d74fc39a | 1752 | |
0fd13d32 | 1753 | -- Corresponds to pragma Implemented, construct the pragma |
49213728 | 1754 | |
5bbfbad2 | 1755 | when Aspect_Synchronization => |
0fd13d32 | 1756 | Make_Aitem_Pragma |
1757 | (Pragma_Argument_Associations => New_List ( | |
1758 | Make_Pragma_Argument_Association (Loc, | |
1759 | Expression => New_Occurrence_Of (E, Loc)), | |
1760 | Make_Pragma_Argument_Association (Sloc (Expr), | |
1761 | Expression => Relocate_Node (Expr))), | |
1762 | Pragma_Name => Name_Implemented); | |
49213728 | 1763 | |
e2bf777d | 1764 | -- Attach_Handler |
0fd13d32 | 1765 | |
89f1e35c | 1766 | when Aspect_Attach_Handler => |
0fd13d32 | 1767 | Make_Aitem_Pragma |
1768 | (Pragma_Argument_Associations => New_List ( | |
1769 | Make_Pragma_Argument_Association (Sloc (Ent), | |
1770 | Expression => Ent), | |
1771 | Make_Pragma_Argument_Association (Sloc (Expr), | |
1772 | Expression => Relocate_Node (Expr))), | |
1773 | Pragma_Name => Name_Attach_Handler); | |
1774 | ||
f67ed4f5 | 1775 | -- We need to insert this pragma into the tree to get proper |
1776 | -- processing and to look valid from a placement viewpoint. | |
1777 | ||
e2bf777d | 1778 | Insert_Pragma (Aitem); |
f67ed4f5 | 1779 | goto Continue; |
1780 | ||
0fd13d32 | 1781 | -- Dynamic_Predicate, Predicate, Static_Predicate |
89f1e35c | 1782 | |
1783 | when Aspect_Dynamic_Predicate | | |
1784 | Aspect_Predicate | | |
1785 | Aspect_Static_Predicate => | |
1786 | ||
a47ce82d | 1787 | -- These aspects apply only to subtypes |
1788 | ||
1789 | if not Is_Type (E) then | |
1790 | Error_Msg_N | |
1791 | ("predicate can only be specified for a subtype", | |
1792 | Aspect); | |
1793 | goto Continue; | |
7c0c95b8 | 1794 | |
1795 | elsif Is_Incomplete_Type (E) then | |
1796 | Error_Msg_N | |
1797 | ("predicate cannot apply to incomplete view", Aspect); | |
1798 | goto Continue; | |
a47ce82d | 1799 | end if; |
1800 | ||
89f1e35c | 1801 | -- Construct the pragma (always a pragma Predicate, with |
51ea9c94 | 1802 | -- flags recording whether it is static/dynamic). We also |
1803 | -- set flags recording this in the type itself. | |
89f1e35c | 1804 | |
0fd13d32 | 1805 | Make_Aitem_Pragma |
1806 | (Pragma_Argument_Associations => New_List ( | |
1807 | Make_Pragma_Argument_Association (Sloc (Ent), | |
1808 | Expression => Ent), | |
1809 | Make_Pragma_Argument_Association (Sloc (Expr), | |
1810 | Expression => Relocate_Node (Expr))), | |
1811 | Pragma_Name => Name_Predicate); | |
89f1e35c | 1812 | |
51ea9c94 | 1813 | -- Mark type has predicates, and remember what kind of |
1814 | -- aspect lead to this predicate (we need this to access | |
1815 | -- the right set of check policies later on). | |
1816 | ||
1817 | Set_Has_Predicates (E); | |
1818 | ||
1819 | if A_Id = Aspect_Dynamic_Predicate then | |
1820 | Set_Has_Dynamic_Predicate_Aspect (E); | |
1821 | elsif A_Id = Aspect_Static_Predicate then | |
1822 | Set_Has_Static_Predicate_Aspect (E); | |
1823 | end if; | |
1824 | ||
89f1e35c | 1825 | -- If the type is private, indicate that its completion |
6653b695 | 1826 | -- has a freeze node, because that is the one that will |
1827 | -- be visible at freeze time. | |
89f1e35c | 1828 | |
0fd13d32 | 1829 | if Is_Private_Type (E) and then Present (Full_View (E)) then |
89f1e35c | 1830 | Set_Has_Predicates (Full_View (E)); |
51ea9c94 | 1831 | |
1832 | if A_Id = Aspect_Dynamic_Predicate then | |
1833 | Set_Has_Dynamic_Predicate_Aspect (Full_View (E)); | |
1834 | elsif A_Id = Aspect_Static_Predicate then | |
1835 | Set_Has_Static_Predicate_Aspect (Full_View (E)); | |
1836 | end if; | |
1837 | ||
89f1e35c | 1838 | Set_Has_Delayed_Aspects (Full_View (E)); |
1839 | Ensure_Freeze_Node (Full_View (E)); | |
1840 | end if; | |
1841 | ||
1842 | -- Case 2b: Aspects corresponding to pragmas with two | |
1843 | -- arguments, where the second argument is a local name | |
1844 | -- referring to the entity, and the first argument is the | |
1845 | -- aspect definition expression. | |
ae888dbd | 1846 | |
0fd13d32 | 1847 | -- Convention |
1848 | ||
a5a64273 | 1849 | when Aspect_Convention => |
1850 | ||
1851 | -- The aspect may be part of the specification of an import | |
1852 | -- or export pragma. Scan the aspect list to gather the | |
1853 | -- other components, if any. The name of the generated | |
1854 | -- pragma is one of Convention/Import/Export. | |
1855 | ||
1856 | declare | |
97bf66e6 | 1857 | Args : constant List_Id := New_List ( |
1858 | Make_Pragma_Argument_Association (Sloc (Expr), | |
1859 | Expression => Relocate_Node (Expr)), | |
1860 | Make_Pragma_Argument_Association (Sloc (Ent), | |
1861 | Expression => Ent)); | |
1862 | ||
1863 | Imp_Exp_Seen : Boolean := False; | |
1864 | -- Flag set when aspect Import or Export has been seen | |
1865 | ||
1866 | Imp_Seen : Boolean := False; | |
1867 | -- Flag set when aspect Import has been seen | |
1868 | ||
1869 | Asp : Node_Id; | |
1870 | Asp_Nam : Name_Id; | |
1871 | Extern_Arg : Node_Id; | |
1872 | Link_Arg : Node_Id; | |
1873 | Prag_Nam : Name_Id; | |
a5a64273 | 1874 | |
1875 | begin | |
97bf66e6 | 1876 | Extern_Arg := Empty; |
1877 | Link_Arg := Empty; | |
1878 | Prag_Nam := Chars (Id); | |
1879 | ||
1880 | Asp := First (L); | |
1881 | while Present (Asp) loop | |
1882 | Asp_Nam := Chars (Identifier (Asp)); | |
1883 | ||
1884 | -- Aspects Import and Export take precedence over | |
1885 | -- aspect Convention. As a result the generated pragma | |
1886 | -- must carry the proper interfacing aspect's name. | |
1887 | ||
1888 | if Nam_In (Asp_Nam, Name_Import, Name_Export) then | |
1889 | if Imp_Exp_Seen then | |
1890 | Error_Msg_N ("conflicting", Asp); | |
a5a64273 | 1891 | else |
97bf66e6 | 1892 | Imp_Exp_Seen := True; |
1893 | ||
1894 | if Asp_Nam = Name_Import then | |
1895 | Imp_Seen := True; | |
1896 | end if; | |
a5a64273 | 1897 | end if; |
1898 | ||
97bf66e6 | 1899 | Prag_Nam := Asp_Nam; |
a5a64273 | 1900 | |
97bf66e6 | 1901 | -- Aspect External_Name adds an extra argument to the |
1902 | -- generated pragma. | |
1903 | ||
1904 | elsif Asp_Nam = Name_External_Name then | |
1905 | Extern_Arg := | |
4bba0a8d | 1906 | Make_Pragma_Argument_Association (Loc, |
97bf66e6 | 1907 | Chars => Asp_Nam, |
1908 | Expression => Relocate_Node (Expression (Asp))); | |
1909 | ||
1910 | -- Aspect Link_Name adds an extra argument to the | |
1911 | -- generated pragma. | |
a5a64273 | 1912 | |
97bf66e6 | 1913 | elsif Asp_Nam = Name_Link_Name then |
1914 | Link_Arg := | |
4bba0a8d | 1915 | Make_Pragma_Argument_Association (Loc, |
97bf66e6 | 1916 | Chars => Asp_Nam, |
1917 | Expression => Relocate_Node (Expression (Asp))); | |
a5a64273 | 1918 | end if; |
1919 | ||
97bf66e6 | 1920 | Next (Asp); |
a5a64273 | 1921 | end loop; |
1922 | ||
97bf66e6 | 1923 | -- Assemble the full argument list |
b9e61b2a | 1924 | |
97bf66e6 | 1925 | if Present (Extern_Arg) then |
1926 | Append_To (Args, Extern_Arg); | |
a5a64273 | 1927 | end if; |
1928 | ||
8a1e3cde | 1929 | if Present (Link_Arg) then |
1930 | Append_To (Args, Link_Arg); | |
1931 | end if; | |
1932 | ||
0fd13d32 | 1933 | Make_Aitem_Pragma |
97bf66e6 | 1934 | (Pragma_Argument_Associations => Args, |
1935 | Pragma_Name => Prag_Nam); | |
1936 | ||
1937 | -- Store the generated pragma Import in the related | |
1938 | -- subprogram. | |
1939 | ||
1940 | if Imp_Seen and then Is_Subprogram (E) then | |
1941 | Set_Import_Pragma (E, Aitem); | |
1942 | end if; | |
a5a64273 | 1943 | end; |
e1cedbae | 1944 | |
0fd13d32 | 1945 | -- CPU, Interrupt_Priority, Priority |
1946 | ||
d6814978 | 1947 | -- These three aspects can be specified for a subprogram spec |
1948 | -- or body, in which case we analyze the expression and export | |
1949 | -- the value of the aspect. | |
1950 | ||
1951 | -- Previously, we generated an equivalent pragma for bodies | |
1952 | -- (note that the specs cannot contain these pragmas). The | |
1953 | -- pragma was inserted ahead of local declarations, rather than | |
1954 | -- after the body. This leads to a certain duplication between | |
1955 | -- the processing performed for the aspect and the pragma, but | |
1956 | -- given the straightforward handling required it is simpler | |
1957 | -- to duplicate than to translate the aspect in the spec into | |
1958 | -- a pragma in the declarative part of the body. | |
3a72f9c3 | 1959 | |
1960 | when Aspect_CPU | | |
1961 | Aspect_Interrupt_Priority | | |
1962 | Aspect_Priority => | |
51ea9c94 | 1963 | |
d6814978 | 1964 | if Nkind_In (N, N_Subprogram_Body, |
1965 | N_Subprogram_Declaration) | |
1966 | then | |
1967 | -- Analyze the aspect expression | |
1968 | ||
1969 | Analyze_And_Resolve (Expr, Standard_Integer); | |
1970 | ||
1971 | -- Interrupt_Priority aspect not allowed for main | |
1972 | -- subprograms. ARM D.1 does not forbid this explicitly, | |
1973 | -- but ARM J.15.11 (6/3) does not permit pragma | |
1974 | -- Interrupt_Priority for subprograms. | |
1975 | ||
1976 | if A_Id = Aspect_Interrupt_Priority then | |
1977 | Error_Msg_N | |
1978 | ("Interrupt_Priority aspect cannot apply to " | |
1979 | & "subprogram", Expr); | |
1980 | ||
1981 | -- The expression must be static | |
1982 | ||
cda40848 | 1983 | elsif not Is_OK_Static_Expression (Expr) then |
d6814978 | 1984 | Flag_Non_Static_Expr |
1985 | ("aspect requires static expression!", Expr); | |
1986 | ||
24d7b9d6 | 1987 | -- Check whether this is the main subprogram. Issue a |
1988 | -- warning only if it is obviously not a main program | |
1989 | -- (when it has parameters or when the subprogram is | |
1990 | -- within a package). | |
1991 | ||
1992 | elsif Present (Parameter_Specifications | |
1993 | (Specification (N))) | |
1994 | or else not Is_Compilation_Unit (Defining_Entity (N)) | |
d6814978 | 1995 | then |
1996 | -- See ARM D.1 (14/3) and D.16 (12/3) | |
1997 | ||
1998 | Error_Msg_N | |
1999 | ("aspect applied to subprogram other than the " | |
2000 | & "main subprogram has no effect??", Expr); | |
2001 | ||
2002 | -- Otherwise check in range and export the value | |
2003 | ||
2004 | -- For the CPU aspect | |
2005 | ||
2006 | elsif A_Id = Aspect_CPU then | |
2007 | if Is_In_Range (Expr, RTE (RE_CPU_Range)) then | |
2008 | ||
2009 | -- Value is correct so we export the value to make | |
2010 | -- it available at execution time. | |
2011 | ||
2012 | Set_Main_CPU | |
2013 | (Main_Unit, UI_To_Int (Expr_Value (Expr))); | |
2014 | ||
2015 | else | |
2016 | Error_Msg_N | |
2017 | ("main subprogram CPU is out of range", Expr); | |
2018 | end if; | |
2019 | ||
2020 | -- For the Priority aspect | |
2021 | ||
2022 | elsif A_Id = Aspect_Priority then | |
2023 | if Is_In_Range (Expr, RTE (RE_Priority)) then | |
2024 | ||
2025 | -- Value is correct so we export the value to make | |
2026 | -- it available at execution time. | |
2027 | ||
2028 | Set_Main_Priority | |
2029 | (Main_Unit, UI_To_Int (Expr_Value (Expr))); | |
2030 | ||
32572384 | 2031 | -- Ignore pragma if Relaxed_RM_Semantics to support |
2032 | -- other targets/non GNAT compilers. | |
2033 | ||
2034 | elsif not Relaxed_RM_Semantics then | |
d6814978 | 2035 | Error_Msg_N |
2036 | ("main subprogram priority is out of range", | |
2037 | Expr); | |
2038 | end if; | |
2039 | end if; | |
2040 | ||
2041 | -- Load an arbitrary entity from System.Tasking.Stages | |
2042 | -- or System.Tasking.Restricted.Stages (depending on | |
2043 | -- the supported profile) to make sure that one of these | |
2044 | -- packages is implicitly with'ed, since we need to have | |
2045 | -- the tasking run time active for the pragma Priority to | |
a0c3eeb9 | 2046 | -- have any effect. Previously we with'ed the package |
d6814978 | 2047 | -- System.Tasking, but this package does not trigger the |
2048 | -- required initialization of the run-time library. | |
2049 | ||
2050 | declare | |
2051 | Discard : Entity_Id; | |
d6814978 | 2052 | begin |
2053 | if Restricted_Profile then | |
2054 | Discard := RTE (RE_Activate_Restricted_Tasks); | |
2055 | else | |
2056 | Discard := RTE (RE_Activate_Tasks); | |
2057 | end if; | |
2058 | end; | |
2059 | ||
2060 | -- Handling for these Aspects in subprograms is complete | |
2061 | ||
2062 | goto Continue; | |
2063 | ||
2064 | -- For tasks | |
0fd13d32 | 2065 | |
3a72f9c3 | 2066 | else |
d6814978 | 2067 | -- Pass the aspect as an attribute |
2068 | ||
3a72f9c3 | 2069 | Aitem := |
2070 | Make_Attribute_Definition_Clause (Loc, | |
2071 | Name => Ent, | |
2072 | Chars => Chars (Id), | |
2073 | Expression => Relocate_Node (Expr)); | |
2074 | end if; | |
2075 | ||
0fd13d32 | 2076 | -- Warnings |
2077 | ||
ae888dbd | 2078 | when Aspect_Warnings => |
0fd13d32 | 2079 | Make_Aitem_Pragma |
2080 | (Pragma_Argument_Associations => New_List ( | |
2081 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2082 | Expression => Relocate_Node (Expr)), | |
2083 | Make_Pragma_Argument_Association (Loc, | |
2084 | Expression => New_Occurrence_Of (E, Loc))), | |
2085 | Pragma_Name => Chars (Id)); | |
ae888dbd | 2086 | |
89f1e35c | 2087 | -- Case 2c: Aspects corresponding to pragmas with three |
2088 | -- arguments. | |
d64221a7 | 2089 | |
89f1e35c | 2090 | -- Invariant aspects have a first argument that references the |
2091 | -- entity, a second argument that is the expression and a third | |
2092 | -- argument that is an appropriate message. | |
d64221a7 | 2093 | |
0fd13d32 | 2094 | -- Invariant, Type_Invariant |
2095 | ||
89f1e35c | 2096 | when Aspect_Invariant | |
2097 | Aspect_Type_Invariant => | |
d64221a7 | 2098 | |
89f1e35c | 2099 | -- Analysis of the pragma will verify placement legality: |
2100 | -- an invariant must apply to a private type, or appear in | |
2101 | -- the private part of a spec and apply to a completion. | |
d64221a7 | 2102 | |
0fd13d32 | 2103 | Make_Aitem_Pragma |
2104 | (Pragma_Argument_Associations => New_List ( | |
2105 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2106 | Expression => Ent), | |
2107 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2108 | Expression => Relocate_Node (Expr))), | |
2109 | Pragma_Name => Name_Invariant); | |
89f1e35c | 2110 | |
2111 | -- Add message unless exception messages are suppressed | |
2112 | ||
2113 | if not Opt.Exception_Locations_Suppressed then | |
2114 | Append_To (Pragma_Argument_Associations (Aitem), | |
2115 | Make_Pragma_Argument_Association (Eloc, | |
2116 | Chars => Name_Message, | |
2117 | Expression => | |
2118 | Make_String_Literal (Eloc, | |
2119 | Strval => "failed invariant from " | |
2120 | & Build_Location_String (Eloc)))); | |
d64221a7 | 2121 | end if; |
2122 | ||
89f1e35c | 2123 | -- For Invariant case, insert immediately after the entity |
2124 | -- declaration. We do not have to worry about delay issues | |
2125 | -- since the pragma processing takes care of this. | |
2126 | ||
89f1e35c | 2127 | Delay_Required := False; |
d64221a7 | 2128 | |
47a46747 | 2129 | -- Case 2d : Aspects that correspond to a pragma with one |
2130 | -- argument. | |
2131 | ||
0fd13d32 | 2132 | -- Abstract_State |
115f7b08 | 2133 | |
d4e369ad | 2134 | -- Aspect Abstract_State introduces implicit declarations for |
2135 | -- all state abstraction entities it defines. To emulate this | |
2136 | -- behavior, insert the pragma at the beginning of the visible | |
2137 | -- declarations of the related package so that it is analyzed | |
2138 | -- immediately. | |
2139 | ||
9129c28f | 2140 | when Aspect_Abstract_State => Abstract_State : declare |
eb4f7efa | 2141 | Context : Node_Id := N; |
630b6d55 | 2142 | Decl : Node_Id; |
eb4f7efa | 2143 | Decls : List_Id; |
9129c28f | 2144 | |
2145 | begin | |
eb4f7efa | 2146 | -- When aspect Abstract_State appears on a generic package, |
2147 | -- it is propageted to the package instance. The context in | |
2148 | -- this case is the instance spec. | |
2149 | ||
2150 | if Nkind (Context) = N_Package_Instantiation then | |
2151 | Context := Instance_Spec (Context); | |
2152 | end if; | |
2153 | ||
2154 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2155 | N_Package_Declaration) | |
9129c28f | 2156 | then |
9129c28f | 2157 | Make_Aitem_Pragma |
2158 | (Pragma_Argument_Associations => New_List ( | |
2159 | Make_Pragma_Argument_Association (Loc, | |
2160 | Expression => Relocate_Node (Expr))), | |
2161 | Pragma_Name => Name_Abstract_State); | |
e2bf777d | 2162 | Decorate (Aspect, Aitem); |
9129c28f | 2163 | |
630b6d55 | 2164 | Decls := Visible_Declarations (Specification (Context)); |
2165 | ||
2166 | -- In general pragma Abstract_State must be at the top | |
2167 | -- of the existing visible declarations to emulate its | |
2168 | -- source counterpart. The only exception to this is a | |
2169 | -- generic instance in which case the pragma must be | |
2170 | -- inserted after the association renamings. | |
2171 | ||
2172 | if Present (Decls) then | |
50e44732 | 2173 | Decl := First (Decls); |
630b6d55 | 2174 | |
2175 | -- The visible declarations of a generic instance have | |
2176 | -- the following structure: | |
2177 | ||
2178 | -- <renamings of generic formals> | |
2179 | -- <renamings of internally-generated spec and body> | |
2180 | -- <first source declaration> | |
2181 | ||
2182 | -- The pragma must be inserted before the first source | |
50e44732 | 2183 | -- declaration, skip the instance "header". |
630b6d55 | 2184 | |
2185 | if Is_Generic_Instance (Defining_Entity (Context)) then | |
630b6d55 | 2186 | while Present (Decl) |
2187 | and then not Comes_From_Source (Decl) | |
2188 | loop | |
2189 | Decl := Next (Decl); | |
2190 | end loop; | |
50e44732 | 2191 | end if; |
630b6d55 | 2192 | |
50e44732 | 2193 | -- Pragma Abstract_State must be inserted after pragma |
2194 | -- SPARK_Mode in the tree. This ensures that any error | |
2195 | -- messages dependent on SPARK_Mode will be properly | |
2196 | -- enabled/suppressed. | |
630b6d55 | 2197 | |
50e44732 | 2198 | Insert_After_SPARK_Mode |
2199 | (Prag => Aitem, | |
2200 | Ins_Nod => Decl, | |
2201 | Decls => Decls); | |
630b6d55 | 2202 | |
2203 | -- Otherwise the pragma forms a new declarative list | |
2204 | ||
2205 | else | |
2206 | Set_Visible_Declarations | |
2207 | (Specification (Context), New_List (Aitem)); | |
2208 | end if; | |
9129c28f | 2209 | |
2210 | else | |
2211 | Error_Msg_NE | |
2212 | ("aspect & must apply to a package declaration", | |
2213 | Aspect, Id); | |
2214 | end if; | |
2215 | ||
2216 | goto Continue; | |
2217 | end Abstract_State; | |
115f7b08 | 2218 | |
ec6f6da5 | 2219 | -- Aspect Default_Internal_Condition is never delayed because |
2220 | -- it is equivalent to a source pragma which appears after the | |
2221 | -- related private type. To deal with forward references, the | |
2222 | -- generated pragma is stored in the rep chain of the related | |
2223 | -- private type as types do not carry contracts. The pragma is | |
2224 | -- wrapped inside of a procedure at the freeze point of the | |
2225 | -- private type's full view. | |
2226 | ||
2227 | when Aspect_Default_Initial_Condition => | |
2228 | Make_Aitem_Pragma | |
2229 | (Pragma_Argument_Associations => New_List ( | |
2230 | Make_Pragma_Argument_Association (Loc, | |
2231 | Expression => Relocate_Node (Expr))), | |
2232 | Pragma_Name => | |
2233 | Name_Default_Initial_Condition); | |
2234 | ||
2235 | Decorate (Aspect, Aitem); | |
2236 | Insert_Pragma (Aitem); | |
2237 | goto Continue; | |
2238 | ||
0fd13d32 | 2239 | -- Depends |
2240 | ||
e2bf777d | 2241 | -- Aspect Depends is never delayed because it is equivalent to |
2242 | -- a source pragma which appears after the related subprogram. | |
2243 | -- To deal with forward references, the generated pragma is | |
2244 | -- stored in the contract of the related subprogram and later | |
2245 | -- analyzed at the end of the declarative region. See routine | |
2246 | -- Analyze_Depends_In_Decl_Part for details. | |
6144c105 | 2247 | |
12334c57 | 2248 | when Aspect_Depends => |
0fd13d32 | 2249 | Make_Aitem_Pragma |
2250 | (Pragma_Argument_Associations => New_List ( | |
2251 | Make_Pragma_Argument_Association (Loc, | |
2252 | Expression => Relocate_Node (Expr))), | |
2253 | Pragma_Name => Name_Depends); | |
2254 | ||
e2bf777d | 2255 | Decorate (Aspect, Aitem); |
2256 | Insert_Pragma (Aitem); | |
c1006d6d | 2257 | goto Continue; |
2258 | ||
0fd13d32 | 2259 | -- Global |
12334c57 | 2260 | |
e2bf777d | 2261 | -- Aspect Global is never delayed because it is equivalent to |
2262 | -- a source pragma which appears after the related subprogram. | |
2263 | -- To deal with forward references, the generated pragma is | |
2264 | -- stored in the contract of the related subprogram and later | |
2265 | -- analyzed at the end of the declarative region. See routine | |
2266 | -- Analyze_Global_In_Decl_Part for details. | |
3cdbaa5a | 2267 | |
2268 | when Aspect_Global => | |
0fd13d32 | 2269 | Make_Aitem_Pragma |
2270 | (Pragma_Argument_Associations => New_List ( | |
2271 | Make_Pragma_Argument_Association (Loc, | |
2272 | Expression => Relocate_Node (Expr))), | |
2273 | Pragma_Name => Name_Global); | |
2274 | ||
e2bf777d | 2275 | Decorate (Aspect, Aitem); |
2276 | Insert_Pragma (Aitem); | |
c1006d6d | 2277 | goto Continue; |
2278 | ||
9c138530 | 2279 | -- Initial_Condition |
2280 | ||
e2bf777d | 2281 | -- Aspect Initial_Condition is never delayed because it is |
2282 | -- equivalent to a source pragma which appears after the | |
2283 | -- related package. To deal with forward references, the | |
2284 | -- generated pragma is stored in the contract of the related | |
2285 | -- package and later analyzed at the end of the declarative | |
2286 | -- region. See routine Analyze_Initial_Condition_In_Decl_Part | |
2287 | -- for details. | |
9c138530 | 2288 | |
2289 | when Aspect_Initial_Condition => Initial_Condition : declare | |
eb4f7efa | 2290 | Context : Node_Id := N; |
2291 | Decls : List_Id; | |
9c138530 | 2292 | |
2293 | begin | |
e2bf777d | 2294 | -- When aspect Initial_Condition appears on a generic |
2295 | -- package, it is propageted to the package instance. The | |
2296 | -- context in this case is the instance spec. | |
eb4f7efa | 2297 | |
2298 | if Nkind (Context) = N_Package_Instantiation then | |
2299 | Context := Instance_Spec (Context); | |
2300 | end if; | |
2301 | ||
2302 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2303 | N_Package_Declaration) | |
9c138530 | 2304 | then |
eb4f7efa | 2305 | Decls := Visible_Declarations (Specification (Context)); |
9c138530 | 2306 | |
2307 | Make_Aitem_Pragma | |
2308 | (Pragma_Argument_Associations => New_List ( | |
2309 | Make_Pragma_Argument_Association (Loc, | |
2310 | Expression => Relocate_Node (Expr))), | |
2311 | Pragma_Name => | |
2312 | Name_Initial_Condition); | |
e2bf777d | 2313 | Decorate (Aspect, Aitem); |
9c138530 | 2314 | |
2315 | if No (Decls) then | |
2316 | Decls := New_List; | |
eb4f7efa | 2317 | Set_Visible_Declarations (Context, Decls); |
9c138530 | 2318 | end if; |
2319 | ||
50e44732 | 2320 | -- When aspects Abstract_State, Initial_Condition and |
2321 | -- Initializes are out of order, ensure that pragma | |
2322 | -- SPARK_Mode is always at the top of the declarative | |
2323 | -- list to properly enable/suppress errors. | |
2324 | ||
2325 | Insert_After_SPARK_Mode | |
2326 | (Prag => Aitem, | |
2327 | Ins_Nod => First (Decls), | |
2328 | Decls => Decls); | |
9c138530 | 2329 | |
2330 | else | |
2331 | Error_Msg_NE | |
2332 | ("aspect & must apply to a package declaration", | |
2333 | Aspect, Id); | |
2334 | end if; | |
2335 | ||
2336 | goto Continue; | |
2337 | end Initial_Condition; | |
2338 | ||
d4e369ad | 2339 | -- Initializes |
2340 | ||
e2bf777d | 2341 | -- Aspect Initializes is never delayed because it is equivalent |
2342 | -- to a source pragma appearing after the related package. To | |
2343 | -- deal with forward references, the generated pragma is stored | |
2344 | -- in the contract of the related package and later analyzed at | |
2345 | -- the end of the declarative region. For details, see routine | |
2346 | -- Analyze_Initializes_In_Decl_Part. | |
d4e369ad | 2347 | |
2348 | when Aspect_Initializes => Initializes : declare | |
eb4f7efa | 2349 | Context : Node_Id := N; |
2350 | Decls : List_Id; | |
d4e369ad | 2351 | |
2352 | begin | |
50e44732 | 2353 | -- When aspect Initializes appears on a generic package, |
2354 | -- it is propageted to the package instance. The context | |
2355 | -- in this case is the instance spec. | |
eb4f7efa | 2356 | |
2357 | if Nkind (Context) = N_Package_Instantiation then | |
2358 | Context := Instance_Spec (Context); | |
2359 | end if; | |
2360 | ||
2361 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2362 | N_Package_Declaration) | |
d4e369ad | 2363 | then |
eb4f7efa | 2364 | Decls := Visible_Declarations (Specification (Context)); |
d4e369ad | 2365 | |
2366 | Make_Aitem_Pragma | |
2367 | (Pragma_Argument_Associations => New_List ( | |
2368 | Make_Pragma_Argument_Association (Loc, | |
2369 | Expression => Relocate_Node (Expr))), | |
2370 | Pragma_Name => Name_Initializes); | |
e2bf777d | 2371 | Decorate (Aspect, Aitem); |
d4e369ad | 2372 | |
2373 | if No (Decls) then | |
2374 | Decls := New_List; | |
eb4f7efa | 2375 | Set_Visible_Declarations (Context, Decls); |
d4e369ad | 2376 | end if; |
2377 | ||
50e44732 | 2378 | -- When aspects Abstract_State, Initial_Condition and |
2379 | -- Initializes are out of order, ensure that pragma | |
2380 | -- SPARK_Mode is always at the top of the declarative | |
2381 | -- list to properly enable/suppress errors. | |
2382 | ||
2383 | Insert_After_SPARK_Mode | |
2384 | (Prag => Aitem, | |
2385 | Ins_Nod => First (Decls), | |
2386 | Decls => Decls); | |
d4e369ad | 2387 | |
2388 | else | |
2389 | Error_Msg_NE | |
2390 | ("aspect & must apply to a package declaration", | |
2391 | Aspect, Id); | |
2392 | end if; | |
2393 | ||
2394 | goto Continue; | |
2395 | end Initializes; | |
2396 | ||
1fd4313f | 2397 | -- Obsolescent |
2398 | ||
2399 | when Aspect_Obsolescent => declare | |
2400 | Args : List_Id; | |
2401 | ||
2402 | begin | |
2403 | if No (Expr) then | |
2404 | Args := No_List; | |
2405 | else | |
2406 | Args := New_List ( | |
2407 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2408 | Expression => Relocate_Node (Expr))); | |
2409 | end if; | |
2410 | ||
2411 | Make_Aitem_Pragma | |
2412 | (Pragma_Argument_Associations => Args, | |
2413 | Pragma_Name => Chars (Id)); | |
2414 | end; | |
2415 | ||
5cc6f0cf | 2416 | -- Part_Of |
2417 | ||
2418 | when Aspect_Part_Of => | |
2419 | if Nkind_In (N, N_Object_Declaration, | |
2420 | N_Package_Instantiation) | |
2421 | then | |
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_Part_Of); | |
2427 | ||
2428 | else | |
2429 | Error_Msg_NE | |
2430 | ("aspect & must apply to a variable or package " | |
2431 | & "instantiation", Aspect, Id); | |
2432 | end if; | |
2433 | ||
5dd93a61 | 2434 | -- SPARK_Mode |
2435 | ||
778ebf56 | 2436 | when Aspect_SPARK_Mode => SPARK_Mode : declare |
2437 | Decls : List_Id; | |
2438 | ||
2439 | begin | |
5dd93a61 | 2440 | Make_Aitem_Pragma |
2441 | (Pragma_Argument_Associations => New_List ( | |
2442 | Make_Pragma_Argument_Association (Loc, | |
2443 | Expression => Relocate_Node (Expr))), | |
2444 | Pragma_Name => Name_SPARK_Mode); | |
5dd93a61 | 2445 | |
b90d9656 | 2446 | -- When the aspect appears on a package or a subprogram |
2447 | -- body, insert the generated pragma at the top of the body | |
2448 | -- declarations to emulate the behavior of a source pragma. | |
778ebf56 | 2449 | |
b90d9656 | 2450 | if Nkind_In (N, N_Package_Body, N_Subprogram_Body) then |
e2bf777d | 2451 | Decorate (Aspect, Aitem); |
5cc6f0cf | 2452 | |
778ebf56 | 2453 | Decls := Declarations (N); |
2454 | ||
2455 | if No (Decls) then | |
2456 | Decls := New_List; | |
2457 | Set_Declarations (N, Decls); | |
2458 | end if; | |
2459 | ||
a04f9d2e | 2460 | Prepend_To (Decls, Aitem); |
2461 | goto Continue; | |
2462 | ||
b90d9656 | 2463 | -- When the aspect is associated with a [generic] package |
2464 | -- declaration, insert the generated pragma at the top of | |
2465 | -- the visible declarations to emulate the behavior of a | |
2466 | -- source pragma. | |
a04f9d2e | 2467 | |
b90d9656 | 2468 | elsif Nkind_In (N, N_Generic_Package_Declaration, |
2469 | N_Package_Declaration) | |
2470 | then | |
e2bf777d | 2471 | Decorate (Aspect, Aitem); |
5cc6f0cf | 2472 | |
a04f9d2e | 2473 | Decls := Visible_Declarations (Specification (N)); |
2474 | ||
2475 | if No (Decls) then | |
2476 | Decls := New_List; | |
2477 | Set_Visible_Declarations (Specification (N), Decls); | |
2478 | end if; | |
2479 | ||
778ebf56 | 2480 | Prepend_To (Decls, Aitem); |
2481 | goto Continue; | |
2482 | end if; | |
2483 | end SPARK_Mode; | |
2484 | ||
4befb1a0 | 2485 | -- Refined_Depends |
2486 | ||
e2bf777d | 2487 | -- Aspect Refined_Depends is never delayed because it is |
2488 | -- equivalent to a source pragma which appears in the | |
2489 | -- declarations of the related subprogram body. To deal with | |
2490 | -- forward references, the generated pragma is stored in the | |
2491 | -- contract of the related subprogram body and later analyzed | |
2492 | -- at the end of the declarative region. For details, see | |
2493 | -- routine Analyze_Refined_Depends_In_Decl_Part. | |
4befb1a0 | 2494 | |
2495 | when Aspect_Refined_Depends => | |
422073ed | 2496 | Make_Aitem_Pragma |
2497 | (Pragma_Argument_Associations => New_List ( | |
2498 | Make_Pragma_Argument_Association (Loc, | |
2499 | Expression => Relocate_Node (Expr))), | |
2500 | Pragma_Name => Name_Refined_Depends); | |
2501 | ||
e2bf777d | 2502 | Decorate (Aspect, Aitem); |
2503 | Insert_Pragma (Aitem); | |
422073ed | 2504 | goto Continue; |
4befb1a0 | 2505 | |
2506 | -- Refined_Global | |
2507 | ||
e2bf777d | 2508 | -- Aspect Refined_Global is never delayed because it is |
2509 | -- equivalent to a source pragma which appears in the | |
2510 | -- declarations of the related subprogram body. To deal with | |
2511 | -- forward references, the generated pragma is stored in the | |
2512 | -- contract of the related subprogram body and later analyzed | |
2513 | -- at the end of the declarative region. For details, see | |
2514 | -- routine Analyze_Refined_Global_In_Decl_Part. | |
4befb1a0 | 2515 | |
2516 | when Aspect_Refined_Global => | |
28ff117f | 2517 | Make_Aitem_Pragma |
2518 | (Pragma_Argument_Associations => New_List ( | |
2519 | Make_Pragma_Argument_Association (Loc, | |
2520 | Expression => Relocate_Node (Expr))), | |
2521 | Pragma_Name => Name_Refined_Global); | |
2522 | ||
e2bf777d | 2523 | Decorate (Aspect, Aitem); |
2524 | Insert_Pragma (Aitem); | |
28ff117f | 2525 | goto Continue; |
4befb1a0 | 2526 | |
63b65b2d | 2527 | -- Refined_Post |
2528 | ||
2529 | when Aspect_Refined_Post => | |
2530 | Make_Aitem_Pragma | |
2531 | (Pragma_Argument_Associations => New_List ( | |
2532 | Make_Pragma_Argument_Association (Loc, | |
2533 | Expression => Relocate_Node (Expr))), | |
2534 | Pragma_Name => Name_Refined_Post); | |
2535 | ||
9129c28f | 2536 | -- Refined_State |
2537 | ||
2538 | when Aspect_Refined_State => Refined_State : declare | |
2539 | Decls : List_Id; | |
2540 | ||
2541 | begin | |
2542 | -- The corresponding pragma for Refined_State is inserted in | |
2543 | -- the declarations of the related package body. This action | |
2544 | -- synchronizes both the source and from-aspect versions of | |
2545 | -- the pragma. | |
2546 | ||
2547 | if Nkind (N) = N_Package_Body then | |
e2bf777d | 2548 | Decls := Declarations (N); |
2549 | ||
9129c28f | 2550 | Make_Aitem_Pragma |
2551 | (Pragma_Argument_Associations => New_List ( | |
2552 | Make_Pragma_Argument_Association (Loc, | |
2553 | Expression => Relocate_Node (Expr))), | |
2554 | Pragma_Name => Name_Refined_State); | |
e2bf777d | 2555 | Decorate (Aspect, Aitem); |
b9b2d6e5 | 2556 | |
e2bf777d | 2557 | if No (Decls) then |
2558 | Decls := New_List; | |
2559 | Set_Declarations (N, Decls); | |
2560 | end if; | |
b9b2d6e5 | 2561 | |
e2bf777d | 2562 | -- Pragma Refined_State must be inserted after pragma |
2563 | -- SPARK_Mode in the tree. This ensures that any error | |
2564 | -- messages dependent on SPARK_Mode will be properly | |
2565 | -- enabled/suppressed. | |
b9b2d6e5 | 2566 | |
e2bf777d | 2567 | Insert_After_SPARK_Mode |
2568 | (Prag => Aitem, | |
2569 | Ins_Nod => First (Decls), | |
2570 | Decls => Decls); | |
9129c28f | 2571 | |
2572 | else | |
2573 | Error_Msg_NE | |
2574 | ("aspect & must apply to a package body", Aspect, Id); | |
2575 | end if; | |
2576 | ||
2577 | goto Continue; | |
2578 | end Refined_State; | |
2579 | ||
0fd13d32 | 2580 | -- Relative_Deadline |
3cdbaa5a | 2581 | |
2582 | when Aspect_Relative_Deadline => | |
0fd13d32 | 2583 | Make_Aitem_Pragma |
2584 | (Pragma_Argument_Associations => New_List ( | |
2585 | Make_Pragma_Argument_Association (Loc, | |
2586 | Expression => Relocate_Node (Expr))), | |
2587 | Pragma_Name => Name_Relative_Deadline); | |
47a46747 | 2588 | |
2589 | -- If the aspect applies to a task, the corresponding pragma | |
2590 | -- must appear within its declarations, not after. | |
2591 | ||
2592 | if Nkind (N) = N_Task_Type_Declaration then | |
2593 | declare | |
2594 | Def : Node_Id; | |
2595 | V : List_Id; | |
2596 | ||
2597 | begin | |
2598 | if No (Task_Definition (N)) then | |
2599 | Set_Task_Definition (N, | |
2600 | Make_Task_Definition (Loc, | |
2601 | Visible_Declarations => New_List, | |
2602 | End_Label => Empty)); | |
2603 | end if; | |
2604 | ||
2605 | Def := Task_Definition (N); | |
2606 | V := Visible_Declarations (Def); | |
2607 | if not Is_Empty_List (V) then | |
2608 | Insert_Before (First (V), Aitem); | |
2609 | ||
2610 | else | |
2611 | Set_Visible_Declarations (Def, New_List (Aitem)); | |
2612 | end if; | |
2613 | ||
2614 | goto Continue; | |
2615 | end; | |
2616 | end if; | |
2617 | ||
956ffaf4 | 2618 | -- Case 2e: Annotate aspect |
2619 | ||
2620 | when Aspect_Annotate => | |
2621 | declare | |
2622 | Args : List_Id; | |
2623 | Pargs : List_Id; | |
2624 | Arg : Node_Id; | |
2625 | ||
2626 | begin | |
2627 | -- The argument can be a single identifier | |
2628 | ||
2629 | if Nkind (Expr) = N_Identifier then | |
2630 | ||
2631 | -- One level of parens is allowed | |
2632 | ||
2633 | if Paren_Count (Expr) > 1 then | |
2634 | Error_Msg_F ("extra parentheses ignored", Expr); | |
2635 | end if; | |
2636 | ||
2637 | Set_Paren_Count (Expr, 0); | |
2638 | ||
2639 | -- Add the single item to the list | |
2640 | ||
2641 | Args := New_List (Expr); | |
2642 | ||
2643 | -- Otherwise we must have an aggregate | |
2644 | ||
2645 | elsif Nkind (Expr) = N_Aggregate then | |
2646 | ||
2647 | -- Must be positional | |
2648 | ||
2649 | if Present (Component_Associations (Expr)) then | |
2650 | Error_Msg_F | |
2651 | ("purely positional aggregate required", Expr); | |
2652 | goto Continue; | |
2653 | end if; | |
2654 | ||
2655 | -- Must not be parenthesized | |
2656 | ||
2657 | if Paren_Count (Expr) /= 0 then | |
2658 | Error_Msg_F ("extra parentheses ignored", Expr); | |
2659 | end if; | |
2660 | ||
2661 | -- List of arguments is list of aggregate expressions | |
2662 | ||
2663 | Args := Expressions (Expr); | |
2664 | ||
2665 | -- Anything else is illegal | |
2666 | ||
2667 | else | |
2668 | Error_Msg_F ("wrong form for Annotate aspect", Expr); | |
2669 | goto Continue; | |
2670 | end if; | |
2671 | ||
2672 | -- Prepare pragma arguments | |
2673 | ||
2674 | Pargs := New_List; | |
2675 | Arg := First (Args); | |
2676 | while Present (Arg) loop | |
2677 | Append_To (Pargs, | |
2678 | Make_Pragma_Argument_Association (Sloc (Arg), | |
2679 | Expression => Relocate_Node (Arg))); | |
2680 | Next (Arg); | |
2681 | end loop; | |
2682 | ||
2683 | Append_To (Pargs, | |
2684 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2685 | Chars => Name_Entity, | |
2686 | Expression => Ent)); | |
2687 | ||
2688 | Make_Aitem_Pragma | |
2689 | (Pragma_Argument_Associations => Pargs, | |
2690 | Pragma_Name => Name_Annotate); | |
2691 | end; | |
2692 | ||
89f1e35c | 2693 | -- Case 3 : Aspects that don't correspond to pragma/attribute |
2694 | -- definition clause. | |
7b9b2f05 | 2695 | |
89f1e35c | 2696 | -- Case 3a: The aspects listed below don't correspond to |
2697 | -- pragmas/attributes but do require delayed analysis. | |
7f694ca2 | 2698 | |
51fa2a45 | 2699 | -- Default_Value can only apply to a scalar type |
2700 | ||
2701 | when Aspect_Default_Value => | |
2702 | if not Is_Scalar_Type (E) then | |
2703 | Error_Msg_N | |
2704 | ("aspect Default_Value must apply to a scalar_Type", N); | |
2705 | end if; | |
2706 | ||
2707 | Aitem := Empty; | |
2708 | ||
2709 | -- Default_Component_Value can only apply to an array type | |
2710 | -- with scalar components. | |
2711 | ||
2712 | when Aspect_Default_Component_Value => | |
2713 | if not (Is_Array_Type (E) | |
3f4c9ffc | 2714 | and then Is_Scalar_Type (Component_Type (E))) |
51fa2a45 | 2715 | then |
2716 | Error_Msg_N ("aspect Default_Component_Value can only " | |
2717 | & "apply to an array of scalar components", N); | |
2718 | end if; | |
0fd13d32 | 2719 | |
89f1e35c | 2720 | Aitem := Empty; |
7f694ca2 | 2721 | |
89f1e35c | 2722 | -- Case 3b: The aspects listed below don't correspond to |
2723 | -- pragmas/attributes and don't need delayed analysis. | |
95bc75fa | 2724 | |
0fd13d32 | 2725 | -- Implicit_Dereference |
2726 | ||
89f1e35c | 2727 | -- For Implicit_Dereference, External_Name and Link_Name, only |
2728 | -- the legality checks are done during the analysis, thus no | |
2729 | -- delay is required. | |
a8e38e1d | 2730 | |
89f1e35c | 2731 | when Aspect_Implicit_Dereference => |
2732 | Analyze_Aspect_Implicit_Dereference; | |
2733 | goto Continue; | |
7f694ca2 | 2734 | |
0fd13d32 | 2735 | -- External_Name, Link_Name |
2736 | ||
89f1e35c | 2737 | when Aspect_External_Name | |
2738 | Aspect_Link_Name => | |
2739 | Analyze_Aspect_External_Or_Link_Name; | |
2740 | goto Continue; | |
7f694ca2 | 2741 | |
0fd13d32 | 2742 | -- Dimension |
2743 | ||
89f1e35c | 2744 | when Aspect_Dimension => |
2745 | Analyze_Aspect_Dimension (N, Id, Expr); | |
2746 | goto Continue; | |
cb4c311d | 2747 | |
0fd13d32 | 2748 | -- Dimension_System |
2749 | ||
89f1e35c | 2750 | when Aspect_Dimension_System => |
2751 | Analyze_Aspect_Dimension_System (N, Id, Expr); | |
2752 | goto Continue; | |
7f694ca2 | 2753 | |
ceec4f7c | 2754 | -- Case 4: Aspects requiring special handling |
51ea9c94 | 2755 | |
e66f4e2a | 2756 | -- Pre/Post/Test_Case/Contract_Cases whose corresponding |
2757 | -- pragmas take care of the delay. | |
7f694ca2 | 2758 | |
0fd13d32 | 2759 | -- Pre/Post |
2760 | ||
1e3c4ae6 | 2761 | -- Aspects Pre/Post generate Precondition/Postcondition pragmas |
2762 | -- with a first argument that is the expression, and a second | |
2763 | -- argument that is an informative message if the test fails. | |
2764 | -- This is inserted right after the declaration, to get the | |
5b5df4a9 | 2765 | -- required pragma placement. The processing for the pragmas |
2766 | -- takes care of the required delay. | |
ae888dbd | 2767 | |
5ddd846b | 2768 | when Pre_Post_Aspects => Pre_Post : declare |
1e3c4ae6 | 2769 | Pname : Name_Id; |
ae888dbd | 2770 | |
1e3c4ae6 | 2771 | begin |
77ae6789 | 2772 | if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then |
1e3c4ae6 | 2773 | Pname := Name_Precondition; |
2774 | else | |
2775 | Pname := Name_Postcondition; | |
2776 | end if; | |
d74fc39a | 2777 | |
1e3c4ae6 | 2778 | -- If the expressions is of the form A and then B, then |
2779 | -- we generate separate Pre/Post aspects for the separate | |
2780 | -- clauses. Since we allow multiple pragmas, there is no | |
2781 | -- problem in allowing multiple Pre/Post aspects internally. | |
a273015d | 2782 | -- These should be treated in reverse order (B first and |
2783 | -- A second) since they are later inserted just after N in | |
2784 | -- the order they are treated. This way, the pragma for A | |
2785 | -- ends up preceding the pragma for B, which may have an | |
2786 | -- importance for the error raised (either constraint error | |
2787 | -- or precondition error). | |
1e3c4ae6 | 2788 | |
39e1f22f | 2789 | -- We do not do this for Pre'Class, since we have to put |
51fa2a45 | 2790 | -- these conditions together in a complex OR expression. |
ae888dbd | 2791 | |
4282d342 | 2792 | -- We do not do this in ASIS mode, as ASIS relies on the |
2793 | -- original node representing the complete expression, when | |
2794 | -- retrieving it through the source aspect table. | |
2795 | ||
2796 | if not ASIS_Mode | |
2797 | and then (Pname = Name_Postcondition | |
2798 | or else not Class_Present (Aspect)) | |
39e1f22f | 2799 | then |
2800 | while Nkind (Expr) = N_And_Then loop | |
2801 | Insert_After (Aspect, | |
a273015d | 2802 | Make_Aspect_Specification (Sloc (Left_Opnd (Expr)), |
39e1f22f | 2803 | Identifier => Identifier (Aspect), |
a273015d | 2804 | Expression => Relocate_Node (Left_Opnd (Expr)), |
39e1f22f | 2805 | Class_Present => Class_Present (Aspect), |
2806 | Split_PPC => True)); | |
a273015d | 2807 | Rewrite (Expr, Relocate_Node (Right_Opnd (Expr))); |
39e1f22f | 2808 | Eloc := Sloc (Expr); |
2809 | end loop; | |
2810 | end if; | |
ae888dbd | 2811 | |
48d6f069 | 2812 | -- Build the precondition/postcondition pragma |
2813 | ||
51fa2a45 | 2814 | -- Add note about why we do NOT need Copy_Tree here??? |
d74fc39a | 2815 | |
0fd13d32 | 2816 | Make_Aitem_Pragma |
2817 | (Pragma_Argument_Associations => New_List ( | |
2818 | Make_Pragma_Argument_Association (Eloc, | |
2819 | Chars => Name_Check, | |
a19e1763 | 2820 | Expression => Relocate_Node (Expr))), |
0fd13d32 | 2821 | Pragma_Name => Pname); |
39e1f22f | 2822 | |
2823 | -- Add message unless exception messages are suppressed | |
2824 | ||
2825 | if not Opt.Exception_Locations_Suppressed then | |
2826 | Append_To (Pragma_Argument_Associations (Aitem), | |
2827 | Make_Pragma_Argument_Association (Eloc, | |
2828 | Chars => Name_Message, | |
2829 | Expression => | |
2830 | Make_String_Literal (Eloc, | |
2831 | Strval => "failed " | |
2832 | & Get_Name_String (Pname) | |
2833 | & " from " | |
2834 | & Build_Location_String (Eloc)))); | |
2835 | end if; | |
d74fc39a | 2836 | |
7d20685d | 2837 | Set_Is_Delayed_Aspect (Aspect); |
d74fc39a | 2838 | |
1e3c4ae6 | 2839 | -- For Pre/Post cases, insert immediately after the entity |
2840 | -- declaration, since that is the required pragma placement. | |
2841 | -- Note that for these aspects, we do not have to worry | |
2842 | -- about delay issues, since the pragmas themselves deal | |
2843 | -- with delay of visibility for the expression analysis. | |
2844 | ||
e2bf777d | 2845 | Insert_Pragma (Aitem); |
1e3c4ae6 | 2846 | goto Continue; |
5ddd846b | 2847 | end Pre_Post; |
ae888dbd | 2848 | |
0fd13d32 | 2849 | -- Test_Case |
2850 | ||
e66f4e2a | 2851 | when Aspect_Test_Case => Test_Case : declare |
2852 | Args : List_Id; | |
2853 | Comp_Expr : Node_Id; | |
2854 | Comp_Assn : Node_Id; | |
2855 | New_Expr : Node_Id; | |
57cd943b | 2856 | |
e66f4e2a | 2857 | begin |
2858 | Args := New_List; | |
b0bc40fd | 2859 | |
e66f4e2a | 2860 | if Nkind (Parent (N)) = N_Compilation_Unit then |
2861 | Error_Msg_Name_1 := Nam; | |
2862 | Error_Msg_N ("incorrect placement of aspect `%`", E); | |
2863 | goto Continue; | |
2864 | end if; | |
6c545057 | 2865 | |
e66f4e2a | 2866 | if Nkind (Expr) /= N_Aggregate then |
2867 | Error_Msg_Name_1 := Nam; | |
2868 | Error_Msg_NE | |
2869 | ("wrong syntax for aspect `%` for &", Id, E); | |
2870 | goto Continue; | |
2871 | end if; | |
6c545057 | 2872 | |
e66f4e2a | 2873 | -- Make pragma expressions refer to the original aspect |
51fa2a45 | 2874 | -- expressions through the Original_Node link. This is used |
2875 | -- in semantic analysis for ASIS mode, so that the original | |
2876 | -- expression also gets analyzed. | |
e66f4e2a | 2877 | |
2878 | Comp_Expr := First (Expressions (Expr)); | |
2879 | while Present (Comp_Expr) loop | |
2880 | New_Expr := Relocate_Node (Comp_Expr); | |
2881 | Set_Original_Node (New_Expr, Comp_Expr); | |
2882 | Append_To (Args, | |
2883 | Make_Pragma_Argument_Association (Sloc (Comp_Expr), | |
2884 | Expression => New_Expr)); | |
2885 | Next (Comp_Expr); | |
2886 | end loop; | |
2887 | ||
2888 | Comp_Assn := First (Component_Associations (Expr)); | |
2889 | while Present (Comp_Assn) loop | |
2890 | if List_Length (Choices (Comp_Assn)) /= 1 | |
2891 | or else | |
2892 | Nkind (First (Choices (Comp_Assn))) /= N_Identifier | |
2893 | then | |
fad014fe | 2894 | Error_Msg_Name_1 := Nam; |
6c545057 | 2895 | Error_Msg_NE |
fad014fe | 2896 | ("wrong syntax for aspect `%` for &", Id, E); |
6c545057 | 2897 | goto Continue; |
2898 | end if; | |
2899 | ||
e66f4e2a | 2900 | New_Expr := Relocate_Node (Expression (Comp_Assn)); |
2901 | Set_Original_Node (New_Expr, Expression (Comp_Assn)); | |
2902 | Append_To (Args, | |
2903 | Make_Pragma_Argument_Association (Sloc (Comp_Assn), | |
2904 | Chars => Chars (First (Choices (Comp_Assn))), | |
2905 | Expression => New_Expr)); | |
2906 | Next (Comp_Assn); | |
2907 | end loop; | |
6c545057 | 2908 | |
e66f4e2a | 2909 | -- Build the test-case pragma |
6c545057 | 2910 | |
0fd13d32 | 2911 | Make_Aitem_Pragma |
2912 | (Pragma_Argument_Associations => Args, | |
2913 | Pragma_Name => Nam); | |
e66f4e2a | 2914 | end Test_Case; |
85696508 | 2915 | |
0fd13d32 | 2916 | -- Contract_Cases |
2917 | ||
5ddd846b | 2918 | when Aspect_Contract_Cases => |
0fd13d32 | 2919 | Make_Aitem_Pragma |
2920 | (Pragma_Argument_Associations => New_List ( | |
2921 | Make_Pragma_Argument_Association (Loc, | |
2922 | Expression => Relocate_Node (Expr))), | |
2923 | Pragma_Name => Nam); | |
3a128918 | 2924 | |
e2bf777d | 2925 | Decorate (Aspect, Aitem); |
2926 | Insert_Pragma (Aitem); | |
5ddd846b | 2927 | goto Continue; |
3a128918 | 2928 | |
89f1e35c | 2929 | -- Case 5: Special handling for aspects with an optional |
2930 | -- boolean argument. | |
85696508 | 2931 | |
89f1e35c | 2932 | -- In the general case, the corresponding pragma cannot be |
0fd13d32 | 2933 | -- generated yet because the evaluation of the boolean needs |
2934 | -- to be delayed till the freeze point. | |
2935 | ||
89f1e35c | 2936 | when Boolean_Aspects | |
2937 | Library_Unit_Aspects => | |
a5a64273 | 2938 | |
89f1e35c | 2939 | Set_Is_Boolean_Aspect (Aspect); |
a5a64273 | 2940 | |
89f1e35c | 2941 | -- Lock_Free aspect only apply to protected objects |
e1cedbae | 2942 | |
89f1e35c | 2943 | if A_Id = Aspect_Lock_Free then |
2944 | if Ekind (E) /= E_Protected_Type then | |
99a2d5bd | 2945 | Error_Msg_Name_1 := Nam; |
a5a64273 | 2946 | Error_Msg_N |
89f1e35c | 2947 | ("aspect % only applies to a protected object", |
2948 | Aspect); | |
2949 | ||
2950 | else | |
2951 | -- Set the Uses_Lock_Free flag to True if there is no | |
37c6e44c | 2952 | -- expression or if the expression is True. The |
89f1e35c | 2953 | -- evaluation of this aspect should be delayed to the |
37c6e44c | 2954 | -- freeze point (why???) |
89f1e35c | 2955 | |
f02a9a9a | 2956 | if No (Expr) or else Is_True (Static_Boolean (Expr)) |
89f1e35c | 2957 | then |
2958 | Set_Uses_Lock_Free (E); | |
2959 | end if; | |
caf125ce | 2960 | |
2961 | Record_Rep_Item (E, Aspect); | |
a5a64273 | 2962 | end if; |
e1cedbae | 2963 | |
89f1e35c | 2964 | goto Continue; |
ae888dbd | 2965 | |
17631aa0 | 2966 | elsif A_Id = Aspect_Import or else A_Id = Aspect_Export then |
d74fc39a | 2967 | |
39616053 | 2968 | -- For the case of aspects Import and Export, we don't |
2969 | -- consider that we know the entity is never set in the | |
2970 | -- source, since it is is likely modified outside the | |
2971 | -- program. | |
2972 | ||
2973 | -- Note: one might think that the analysis of the | |
2974 | -- resulting pragma would take care of that, but | |
2975 | -- that's not the case since it won't be from source. | |
2976 | ||
2977 | if Ekind (E) = E_Variable then | |
2978 | Set_Never_Set_In_Source (E, False); | |
2979 | end if; | |
2980 | ||
2e1821c9 | 2981 | -- In older versions of Ada the corresponding pragmas |
51fa2a45 | 2982 | -- specified a Convention. In Ada 2012 the convention is |
2983 | -- specified as a separate aspect, and it is optional, | |
2e1821c9 | 2984 | -- given that it defaults to Convention_Ada. The code |
2985 | -- that verifed that there was a matching convention | |
2986 | -- is now obsolete. | |
d74fc39a | 2987 | |
718d0d92 | 2988 | -- Resolve the expression of an Import or Export here, |
2989 | -- and require it to be of type Boolean and static. This | |
2990 | -- is not quite right, because in general this should be | |
2991 | -- delayed, but that seems tricky for these, because | |
2992 | -- normally Boolean aspects are replaced with pragmas at | |
2993 | -- the freeze point (in Make_Pragma_From_Boolean_Aspect), | |
2994 | -- but in the case of these aspects we can't generate | |
2995 | -- a simple pragma with just the entity name. ??? | |
2996 | ||
2997 | if not Present (Expr) | |
2998 | or else Is_True (Static_Boolean (Expr)) | |
2999 | then | |
3000 | if A_Id = Aspect_Import then | |
3001 | Set_Is_Imported (E); | |
dd4c44af | 3002 | |
718d0d92 | 3003 | -- An imported entity cannot have an explicit |
3004 | -- initialization. | |
dd4c44af | 3005 | |
718d0d92 | 3006 | if Nkind (N) = N_Object_Declaration |
3007 | and then Present (Expression (N)) | |
3008 | then | |
3009 | Error_Msg_N | |
3010 | ("imported entities cannot be initialized " | |
3011 | & "(RM B.1(24))", Expression (N)); | |
3012 | end if; | |
3013 | ||
3014 | elsif A_Id = Aspect_Export then | |
3015 | Set_Is_Exported (E); | |
dd4c44af | 3016 | end if; |
3017 | end if; | |
3018 | ||
89f1e35c | 3019 | goto Continue; |
3020 | end if; | |
d74fc39a | 3021 | |
37c6e44c | 3022 | -- Library unit aspects require special handling in the case |
3023 | -- of a package declaration, the pragma needs to be inserted | |
3024 | -- in the list of declarations for the associated package. | |
3025 | -- There is no issue of visibility delay for these aspects. | |
d64221a7 | 3026 | |
89f1e35c | 3027 | if A_Id in Library_Unit_Aspects |
178fec9b | 3028 | and then |
3029 | Nkind_In (N, N_Package_Declaration, | |
3030 | N_Generic_Package_Declaration) | |
89f1e35c | 3031 | and then Nkind (Parent (N)) /= N_Compilation_Unit |
3ad60f63 | 3032 | |
3033 | -- Aspect is legal on a local instantiation of a library- | |
3034 | -- level generic unit. | |
3035 | ||
b94a633e | 3036 | and then not Is_Generic_Instance (Defining_Entity (N)) |
89f1e35c | 3037 | then |
3038 | Error_Msg_N | |
dd4c44af | 3039 | ("incorrect context for library unit aspect&", Id); |
89f1e35c | 3040 | goto Continue; |
3041 | end if; | |
cce84b09 | 3042 | |
294709fa | 3043 | -- External property aspects are Boolean by nature, but |
3044 | -- their pragmas must contain two arguments, the second | |
3045 | -- being the optional Boolean expression. | |
3046 | ||
a7ed0410 | 3047 | if A_Id = Aspect_Async_Readers or else |
3048 | A_Id = Aspect_Async_Writers or else | |
3049 | A_Id = Aspect_Effective_Reads or else | |
3050 | A_Id = Aspect_Effective_Writes | |
294709fa | 3051 | then |
3052 | declare | |
3053 | Args : List_Id; | |
3054 | ||
3055 | begin | |
3056 | -- The first argument of the external property pragma | |
3057 | -- is the related object. | |
3058 | ||
a7ed0410 | 3059 | Args := |
3060 | New_List ( | |
3061 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3062 | Expression => Ent)); | |
294709fa | 3063 | |
3064 | -- The second argument is the optional Boolean | |
3065 | -- expression which must be propagated even if it | |
3066 | -- evaluates to False as this has special semantic | |
3067 | -- meaning. | |
3068 | ||
3069 | if Present (Expr) then | |
3070 | Append_To (Args, | |
3071 | Make_Pragma_Argument_Association (Loc, | |
3072 | Expression => Relocate_Node (Expr))); | |
3073 | end if; | |
3074 | ||
3075 | Make_Aitem_Pragma | |
3076 | (Pragma_Argument_Associations => Args, | |
3077 | Pragma_Name => Nam); | |
3078 | end; | |
3079 | ||
51fa2a45 | 3080 | -- Cases where we do not delay, includes all cases where the |
3081 | -- expression is missing other than the above cases. | |
d74fc39a | 3082 | |
294709fa | 3083 | elsif not Delay_Required or else No (Expr) then |
0fd13d32 | 3084 | Make_Aitem_Pragma |
3085 | (Pragma_Argument_Associations => New_List ( | |
3086 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3087 | Expression => Ent)), | |
3088 | Pragma_Name => Chars (Id)); | |
89f1e35c | 3089 | Delay_Required := False; |
ddf1337b | 3090 | |
89f1e35c | 3091 | -- In general cases, the corresponding pragma/attribute |
3092 | -- definition clause will be inserted later at the freezing | |
294709fa | 3093 | -- point, and we do not need to build it now. |
ddf1337b | 3094 | |
89f1e35c | 3095 | else |
3096 | Aitem := Empty; | |
3097 | end if; | |
ceec4f7c | 3098 | |
3099 | -- Storage_Size | |
3100 | ||
3101 | -- This is special because for access types we need to generate | |
3102 | -- an attribute definition clause. This also works for single | |
3103 | -- task declarations, but it does not work for task type | |
3104 | -- declarations, because we have the case where the expression | |
3105 | -- references a discriminant of the task type. That can't use | |
3106 | -- an attribute definition clause because we would not have | |
3107 | -- visibility on the discriminant. For that case we must | |
3108 | -- generate a pragma in the task definition. | |
3109 | ||
3110 | when Aspect_Storage_Size => | |
3111 | ||
3112 | -- Task type case | |
3113 | ||
3114 | if Ekind (E) = E_Task_Type then | |
3115 | declare | |
3116 | Decl : constant Node_Id := Declaration_Node (E); | |
3117 | ||
3118 | begin | |
3119 | pragma Assert (Nkind (Decl) = N_Task_Type_Declaration); | |
3120 | ||
3121 | -- If no task definition, create one | |
3122 | ||
3123 | if No (Task_Definition (Decl)) then | |
3124 | Set_Task_Definition (Decl, | |
3125 | Make_Task_Definition (Loc, | |
3126 | Visible_Declarations => Empty_List, | |
3127 | End_Label => Empty)); | |
3128 | end if; | |
3129 | ||
51fa2a45 | 3130 | -- Create a pragma and put it at the start of the task |
3131 | -- definition for the task type declaration. | |
ceec4f7c | 3132 | |
3133 | Make_Aitem_Pragma | |
3134 | (Pragma_Argument_Associations => New_List ( | |
3135 | Make_Pragma_Argument_Association (Loc, | |
3136 | Expression => Relocate_Node (Expr))), | |
3137 | Pragma_Name => Name_Storage_Size); | |
3138 | ||
3139 | Prepend | |
3140 | (Aitem, | |
3141 | Visible_Declarations (Task_Definition (Decl))); | |
3142 | goto Continue; | |
3143 | end; | |
3144 | ||
3145 | -- All other cases, generate attribute definition | |
3146 | ||
3147 | else | |
3148 | Aitem := | |
3149 | Make_Attribute_Definition_Clause (Loc, | |
3150 | Name => Ent, | |
3151 | Chars => Chars (Id), | |
3152 | Expression => Relocate_Node (Expr)); | |
3153 | end if; | |
89f1e35c | 3154 | end case; |
ddf1337b | 3155 | |
89f1e35c | 3156 | -- Attach the corresponding pragma/attribute definition clause to |
3157 | -- the aspect specification node. | |
d74fc39a | 3158 | |
89f1e35c | 3159 | if Present (Aitem) then |
e2bf777d | 3160 | Set_From_Aspect_Specification (Aitem); |
89f1e35c | 3161 | end if; |
53c179ea | 3162 | |
89f1e35c | 3163 | -- In the context of a compilation unit, we directly put the |
0fd13d32 | 3164 | -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux |
3165 | -- node (no delay is required here) except for aspects on a | |
51fa2a45 | 3166 | -- subprogram body (see below) and a generic package, for which we |
3167 | -- need to introduce the pragma before building the generic copy | |
3168 | -- (see sem_ch12), and for package instantiations, where the | |
3169 | -- library unit pragmas are better handled early. | |
ddf1337b | 3170 | |
9129c28f | 3171 | if Nkind (Parent (N)) = N_Compilation_Unit |
89f1e35c | 3172 | and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect)) |
3173 | then | |
3174 | declare | |
3175 | Aux : constant Node_Id := Aux_Decls_Node (Parent (N)); | |
7f694ca2 | 3176 | |
89f1e35c | 3177 | begin |
3178 | pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux); | |
7f694ca2 | 3179 | |
89f1e35c | 3180 | -- For a Boolean aspect, create the corresponding pragma if |
3181 | -- no expression or if the value is True. | |
7f694ca2 | 3182 | |
b9e61b2a | 3183 | if Is_Boolean_Aspect (Aspect) and then No (Aitem) then |
89f1e35c | 3184 | if Is_True (Static_Boolean (Expr)) then |
0fd13d32 | 3185 | Make_Aitem_Pragma |
3186 | (Pragma_Argument_Associations => New_List ( | |
3187 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3188 | Expression => Ent)), | |
3189 | Pragma_Name => Chars (Id)); | |
7f694ca2 | 3190 | |
89f1e35c | 3191 | Set_From_Aspect_Specification (Aitem, True); |
3192 | Set_Corresponding_Aspect (Aitem, Aspect); | |
3193 | ||
3194 | else | |
3195 | goto Continue; | |
3196 | end if; | |
3197 | end if; | |
7f694ca2 | 3198 | |
d6814978 | 3199 | -- If the aspect is on a subprogram body (relevant aspect |
3200 | -- is Inline), add the pragma in front of the declarations. | |
3a72f9c3 | 3201 | |
3202 | if Nkind (N) = N_Subprogram_Body then | |
3203 | if No (Declarations (N)) then | |
3204 | Set_Declarations (N, New_List); | |
3205 | end if; | |
3206 | ||
3207 | Prepend (Aitem, Declarations (N)); | |
3208 | ||
178fec9b | 3209 | elsif Nkind (N) = N_Generic_Package_Declaration then |
3210 | if No (Visible_Declarations (Specification (N))) then | |
3211 | Set_Visible_Declarations (Specification (N), New_List); | |
3212 | end if; | |
3213 | ||
3214 | Prepend (Aitem, | |
3215 | Visible_Declarations (Specification (N))); | |
3216 | ||
c39cce40 | 3217 | elsif Nkind (N) = N_Package_Instantiation then |
df8b0dae | 3218 | declare |
3219 | Spec : constant Node_Id := | |
3220 | Specification (Instance_Spec (N)); | |
3221 | begin | |
3222 | if No (Visible_Declarations (Spec)) then | |
3223 | Set_Visible_Declarations (Spec, New_List); | |
3224 | end if; | |
3225 | ||
3226 | Prepend (Aitem, Visible_Declarations (Spec)); | |
3227 | end; | |
3228 | ||
3a72f9c3 | 3229 | else |
3230 | if No (Pragmas_After (Aux)) then | |
d4596fbe | 3231 | Set_Pragmas_After (Aux, New_List); |
3a72f9c3 | 3232 | end if; |
3233 | ||
3234 | Append (Aitem, Pragmas_After (Aux)); | |
89f1e35c | 3235 | end if; |
7f694ca2 | 3236 | |
89f1e35c | 3237 | goto Continue; |
3238 | end; | |
3239 | end if; | |
7f694ca2 | 3240 | |
89f1e35c | 3241 | -- The evaluation of the aspect is delayed to the freezing point. |
3242 | -- The pragma or attribute clause if there is one is then attached | |
37c6e44c | 3243 | -- to the aspect specification which is put in the rep item list. |
1a814552 | 3244 | |
89f1e35c | 3245 | if Delay_Required then |
3246 | if Present (Aitem) then | |
3247 | Set_Is_Delayed_Aspect (Aitem); | |
3248 | Set_Aspect_Rep_Item (Aspect, Aitem); | |
3249 | Set_Parent (Aitem, Aspect); | |
3250 | end if; | |
1a814552 | 3251 | |
89f1e35c | 3252 | Set_Is_Delayed_Aspect (Aspect); |
9f36e3fb | 3253 | |
cba2ae82 | 3254 | -- In the case of Default_Value, link the aspect to base type |
3255 | -- as well, even though it appears on a first subtype. This is | |
3256 | -- mandated by the semantics of the aspect. Do not establish | |
3257 | -- the link when processing the base type itself as this leads | |
3258 | -- to a rep item circularity. Verify that we are dealing with | |
3259 | -- a scalar type to prevent cascaded errors. | |
3260 | ||
3261 | if A_Id = Aspect_Default_Value | |
3262 | and then Is_Scalar_Type (E) | |
3263 | and then Base_Type (E) /= E | |
3264 | then | |
9f36e3fb | 3265 | Set_Has_Delayed_Aspects (Base_Type (E)); |
3266 | Record_Rep_Item (Base_Type (E), Aspect); | |
3267 | end if; | |
3268 | ||
89f1e35c | 3269 | Set_Has_Delayed_Aspects (E); |
3270 | Record_Rep_Item (E, Aspect); | |
ddf1337b | 3271 | |
b855559d | 3272 | -- When delay is not required and the context is a package or a |
3273 | -- subprogram body, insert the pragma in the body declarations. | |
f55ce169 | 3274 | |
b855559d | 3275 | elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then |
f55ce169 | 3276 | if No (Declarations (N)) then |
3277 | Set_Declarations (N, New_List); | |
3278 | end if; | |
3279 | ||
3280 | -- The pragma is added before source declarations | |
3281 | ||
3282 | Prepend_To (Declarations (N), Aitem); | |
3283 | ||
89f1e35c | 3284 | -- When delay is not required and the context is not a compilation |
3285 | -- unit, we simply insert the pragma/attribute definition clause | |
3286 | -- in sequence. | |
ddf1337b | 3287 | |
89f1e35c | 3288 | else |
3289 | Insert_After (Ins_Node, Aitem); | |
3290 | Ins_Node := Aitem; | |
d74fc39a | 3291 | end if; |
0fd13d32 | 3292 | end Analyze_One_Aspect; |
ae888dbd | 3293 | |
d64221a7 | 3294 | <<Continue>> |
3295 | Next (Aspect); | |
21ea3a4f | 3296 | end loop Aspect_Loop; |
89f1e35c | 3297 | |
3298 | if Has_Delayed_Aspects (E) then | |
3299 | Ensure_Freeze_Node (E); | |
3300 | end if; | |
21ea3a4f | 3301 | end Analyze_Aspect_Specifications; |
ae888dbd | 3302 | |
d6f39728 | 3303 | ----------------------- |
3304 | -- Analyze_At_Clause -- | |
3305 | ----------------------- | |
3306 | ||
3307 | -- An at clause is replaced by the corresponding Address attribute | |
3308 | -- definition clause that is the preferred approach in Ada 95. | |
3309 | ||
3310 | procedure Analyze_At_Clause (N : Node_Id) is | |
177675a7 | 3311 | CS : constant Boolean := Comes_From_Source (N); |
3312 | ||
d6f39728 | 3313 | begin |
177675a7 | 3314 | -- This is an obsolescent feature |
3315 | ||
e0521a36 | 3316 | Check_Restriction (No_Obsolescent_Features, N); |
3317 | ||
9dfe12ae | 3318 | if Warn_On_Obsolescent_Feature then |
3319 | Error_Msg_N | |
b174444e | 3320 | ("?j?at clause is an obsolescent feature (RM J.7(2))", N); |
9dfe12ae | 3321 | Error_Msg_N |
b174444e | 3322 | ("\?j?use address attribute definition clause instead", N); |
9dfe12ae | 3323 | end if; |
3324 | ||
177675a7 | 3325 | -- Rewrite as address clause |
3326 | ||
d6f39728 | 3327 | Rewrite (N, |
3328 | Make_Attribute_Definition_Clause (Sloc (N), | |
935e86e0 | 3329 | Name => Identifier (N), |
3330 | Chars => Name_Address, | |
d6f39728 | 3331 | Expression => Expression (N))); |
177675a7 | 3332 | |
2beb22b1 | 3333 | -- We preserve Comes_From_Source, since logically the clause still comes |
3334 | -- from the source program even though it is changed in form. | |
177675a7 | 3335 | |
3336 | Set_Comes_From_Source (N, CS); | |
3337 | ||
3338 | -- Analyze rewritten clause | |
3339 | ||
d6f39728 | 3340 | Analyze_Attribute_Definition_Clause (N); |
3341 | end Analyze_At_Clause; | |
3342 | ||
3343 | ----------------------------------------- | |
3344 | -- Analyze_Attribute_Definition_Clause -- | |
3345 | ----------------------------------------- | |
3346 | ||
3347 | procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is | |
3348 | Loc : constant Source_Ptr := Sloc (N); | |
3349 | Nam : constant Node_Id := Name (N); | |
3350 | Attr : constant Name_Id := Chars (N); | |
3351 | Expr : constant Node_Id := Expression (N); | |
3352 | Id : constant Attribute_Id := Get_Attribute_Id (Attr); | |
d64221a7 | 3353 | |
3354 | Ent : Entity_Id; | |
3355 | -- The entity of Nam after it is analyzed. In the case of an incomplete | |
3356 | -- type, this is the underlying type. | |
3357 | ||
d6f39728 | 3358 | U_Ent : Entity_Id; |
d64221a7 | 3359 | -- The underlying entity to which the attribute applies. Generally this |
3360 | -- is the Underlying_Type of Ent, except in the case where the clause | |
3361 | -- applies to full view of incomplete type or private type in which case | |
3362 | -- U_Ent is just a copy of Ent. | |
d6f39728 | 3363 | |
3364 | FOnly : Boolean := False; | |
3365 | -- Reset to True for subtype specific attribute (Alignment, Size) | |
51fa2a45 | 3366 | -- and for stream attributes, i.e. those cases where in the call to |
3367 | -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules | |
3368 | -- are checked. Note that the case of stream attributes is not clear | |
3369 | -- from the RM, but see AI95-00137. Also, the RM seems to disallow | |
3370 | -- Storage_Size for derived task types, but that is also clearly | |
3371 | -- unintentional. | |
d6f39728 | 3372 | |
9f373bb8 | 3373 | procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type); |
3374 | -- Common processing for 'Read, 'Write, 'Input and 'Output attribute | |
3375 | -- definition clauses. | |
3376 | ||
ae888dbd | 3377 | function Duplicate_Clause return Boolean; |
3378 | -- This routine checks if the aspect for U_Ent being given by attribute | |
3379 | -- definition clause N is for an aspect that has already been specified, | |
3380 | -- and if so gives an error message. If there is a duplicate, True is | |
3381 | -- returned, otherwise if there is no error, False is returned. | |
3382 | ||
81b424ac | 3383 | procedure Check_Indexing_Functions; |
3384 | -- Check that the function in Constant_Indexing or Variable_Indexing | |
3385 | -- attribute has the proper type structure. If the name is overloaded, | |
cac18f71 | 3386 | -- check that some interpretation is legal. |
81b424ac | 3387 | |
89cc7147 | 3388 | procedure Check_Iterator_Functions; |
3389 | -- Check that there is a single function in Default_Iterator attribute | |
8df4f2a5 | 3390 | -- has the proper type structure. |
89cc7147 | 3391 | |
3392 | function Check_Primitive_Function (Subp : Entity_Id) return Boolean; | |
d03bfaa1 | 3393 | -- Common legality check for the previous two |
89cc7147 | 3394 | |
177675a7 | 3395 | ----------------------------------- |
3396 | -- Analyze_Stream_TSS_Definition -- | |
3397 | ----------------------------------- | |
3398 | ||
9f373bb8 | 3399 | procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is |
3400 | Subp : Entity_Id := Empty; | |
3401 | I : Interp_Index; | |
3402 | It : Interp; | |
3403 | Pnam : Entity_Id; | |
3404 | ||
3405 | Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read); | |
d64221a7 | 3406 | -- True for Read attribute, false for other attributes |
9f373bb8 | 3407 | |
3408 | function Has_Good_Profile (Subp : Entity_Id) return Boolean; | |
3409 | -- Return true if the entity is a subprogram with an appropriate | |
3410 | -- profile for the attribute being defined. | |
3411 | ||
3412 | ---------------------- | |
3413 | -- Has_Good_Profile -- | |
3414 | ---------------------- | |
3415 | ||
3416 | function Has_Good_Profile (Subp : Entity_Id) return Boolean is | |
3417 | F : Entity_Id; | |
3418 | Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input); | |
3419 | Expected_Ekind : constant array (Boolean) of Entity_Kind := | |
3420 | (False => E_Procedure, True => E_Function); | |
3421 | Typ : Entity_Id; | |
3422 | ||
3423 | begin | |
3424 | if Ekind (Subp) /= Expected_Ekind (Is_Function) then | |
3425 | return False; | |
3426 | end if; | |
3427 | ||
3428 | F := First_Formal (Subp); | |
3429 | ||
3430 | if No (F) | |
3431 | or else Ekind (Etype (F)) /= E_Anonymous_Access_Type | |
3432 | or else Designated_Type (Etype (F)) /= | |
3433 | Class_Wide_Type (RTE (RE_Root_Stream_Type)) | |
3434 | then | |
3435 | return False; | |
3436 | end if; | |
3437 | ||
3438 | if not Is_Function then | |
3439 | Next_Formal (F); | |
3440 | ||
3441 | declare | |
3442 | Expected_Mode : constant array (Boolean) of Entity_Kind := | |
3443 | (False => E_In_Parameter, | |
3444 | True => E_Out_Parameter); | |
3445 | begin | |
3446 | if Parameter_Mode (F) /= Expected_Mode (Is_Read) then | |
3447 | return False; | |
3448 | end if; | |
3449 | end; | |
3450 | ||
3451 | Typ := Etype (F); | |
3452 | ||
b64082f2 | 3453 | -- If the attribute specification comes from an aspect |
51fa2a45 | 3454 | -- specification for a class-wide stream, the parameter must be |
3455 | -- a class-wide type of the entity to which the aspect applies. | |
b64082f2 | 3456 | |
3457 | if From_Aspect_Specification (N) | |
3458 | and then Class_Present (Parent (N)) | |
3459 | and then Is_Class_Wide_Type (Typ) | |
3460 | then | |
3461 | Typ := Etype (Typ); | |
3462 | end if; | |
3463 | ||
9f373bb8 | 3464 | else |
3465 | Typ := Etype (Subp); | |
3466 | end if; | |
3467 | ||
51fa2a45 | 3468 | -- Verify that the prefix of the attribute and the local name for |
3469 | -- the type of the formal match. | |
48680a09 | 3470 | |
3471 | if Base_Type (Typ) /= Base_Type (Ent) | |
3472 | or else Present ((Next_Formal (F))) | |
3473 | then | |
3474 | return False; | |
3475 | ||
3476 | elsif not Is_Scalar_Type (Typ) | |
3477 | and then not Is_First_Subtype (Typ) | |
3478 | and then not Is_Class_Wide_Type (Typ) | |
3479 | then | |
3480 | return False; | |
3481 | ||
3482 | else | |
3483 | return True; | |
3484 | end if; | |
9f373bb8 | 3485 | end Has_Good_Profile; |
3486 | ||
3487 | -- Start of processing for Analyze_Stream_TSS_Definition | |
3488 | ||
3489 | begin | |
3490 | FOnly := True; | |
3491 | ||
3492 | if not Is_Type (U_Ent) then | |
3493 | Error_Msg_N ("local name must be a subtype", Nam); | |
3494 | return; | |
48680a09 | 3495 | |
3496 | elsif not Is_First_Subtype (U_Ent) then | |
3497 | Error_Msg_N ("local name must be a first subtype", Nam); | |
3498 | return; | |
9f373bb8 | 3499 | end if; |
3500 | ||
3501 | Pnam := TSS (Base_Type (U_Ent), TSS_Nam); | |
3502 | ||
44e4341e | 3503 | -- If Pnam is present, it can be either inherited from an ancestor |
3504 | -- type (in which case it is legal to redefine it for this type), or | |
3505 | -- be a previous definition of the attribute for the same type (in | |
3506 | -- which case it is illegal). | |
3507 | ||
3508 | -- In the first case, it will have been analyzed already, and we | |
3509 | -- can check that its profile does not match the expected profile | |
3510 | -- for a stream attribute of U_Ent. In the second case, either Pnam | |
3511 | -- has been analyzed (and has the expected profile), or it has not | |
3512 | -- been analyzed yet (case of a type that has not been frozen yet | |
3513 | -- and for which the stream attribute has been set using Set_TSS). | |
3514 | ||
3515 | if Present (Pnam) | |
3516 | and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam)) | |
3517 | then | |
9f373bb8 | 3518 | Error_Msg_Sloc := Sloc (Pnam); |
3519 | Error_Msg_Name_1 := Attr; | |
3520 | Error_Msg_N ("% attribute already defined #", Nam); | |
3521 | return; | |
3522 | end if; | |
3523 | ||
3524 | Analyze (Expr); | |
3525 | ||
3526 | if Is_Entity_Name (Expr) then | |
3527 | if not Is_Overloaded (Expr) then | |
3528 | if Has_Good_Profile (Entity (Expr)) then | |
3529 | Subp := Entity (Expr); | |
3530 | end if; | |
3531 | ||
3532 | else | |
3533 | Get_First_Interp (Expr, I, It); | |
9f373bb8 | 3534 | while Present (It.Nam) loop |
3535 | if Has_Good_Profile (It.Nam) then | |
3536 | Subp := It.Nam; | |
3537 | exit; | |
3538 | end if; | |
3539 | ||
3540 | Get_Next_Interp (I, It); | |
3541 | end loop; | |
3542 | end if; | |
3543 | end if; | |
3544 | ||
3545 | if Present (Subp) then | |
59ac57b5 | 3546 | if Is_Abstract_Subprogram (Subp) then |
9f373bb8 | 3547 | Error_Msg_N ("stream subprogram must not be abstract", Expr); |
3548 | return; | |
e12b2502 | 3549 | |
dd270bcf | 3550 | -- Test for stream subprogram for interface type being non-null |
e12b2502 | 3551 | |
3552 | elsif Is_Interface (U_Ent) | |
3553 | and then not Inside_A_Generic | |
3554 | and then Ekind (Subp) = E_Procedure | |
3555 | and then | |
3556 | not Null_Present | |
3557 | (Specification | |
3558 | (Unit_Declaration_Node (Ultimate_Alias (Subp)))) | |
e12b2502 | 3559 | then |
3560 | Error_Msg_N | |
3561 | ("stream subprogram for interface type " | |
3562 | & "must be null procedure", Expr); | |
9f373bb8 | 3563 | end if; |
3564 | ||
3565 | Set_Entity (Expr, Subp); | |
3566 | Set_Etype (Expr, Etype (Subp)); | |
3567 | ||
44e4341e | 3568 | New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam); |
9f373bb8 | 3569 | |
3570 | else | |
3571 | Error_Msg_Name_1 := Attr; | |
3572 | Error_Msg_N ("incorrect expression for% attribute", Expr); | |
3573 | end if; | |
3574 | end Analyze_Stream_TSS_Definition; | |
3575 | ||
81b424ac | 3576 | ------------------------------ |
3577 | -- Check_Indexing_Functions -- | |
3578 | ------------------------------ | |
3579 | ||
3580 | procedure Check_Indexing_Functions is | |
c8a2d809 | 3581 | Indexing_Found : Boolean := False; |
8df4f2a5 | 3582 | |
81b424ac | 3583 | procedure Check_One_Function (Subp : Entity_Id); |
7796365f | 3584 | -- Check one possible interpretation. Sets Indexing_Found True if a |
3585 | -- legal indexing function is found. | |
81b424ac | 3586 | |
05987af3 | 3587 | procedure Illegal_Indexing (Msg : String); |
3588 | -- Diagnose illegal indexing function if not overloaded. In the | |
3589 | -- overloaded case indicate that no legal interpretation exists. | |
3590 | ||
81b424ac | 3591 | ------------------------ |
3592 | -- Check_One_Function -- | |
3593 | ------------------------ | |
3594 | ||
3595 | procedure Check_One_Function (Subp : Entity_Id) is | |
05987af3 | 3596 | Default_Element : Node_Id; |
3597 | Ret_Type : constant Entity_Id := Etype (Subp); | |
1b7510f9 | 3598 | |
81b424ac | 3599 | begin |
05987af3 | 3600 | if not Is_Overloadable (Subp) then |
3601 | Illegal_Indexing ("illegal indexing function for type&"); | |
3602 | return; | |
3603 | ||
7796365f | 3604 | elsif Scope (Subp) /= Scope (Ent) then |
3605 | if Nkind (Expr) = N_Expanded_Name then | |
3606 | ||
3607 | -- Indexing function can't be declared elsewhere | |
3608 | ||
3609 | Illegal_Indexing | |
3610 | ("indexing function must be declared in scope of type&"); | |
3611 | end if; | |
3612 | ||
05987af3 | 3613 | return; |
3614 | ||
3615 | elsif No (First_Formal (Subp)) then | |
3616 | Illegal_Indexing | |
3617 | ("Indexing requires a function that applies to type&"); | |
3618 | return; | |
3619 | ||
3620 | elsif No (Next_Formal (First_Formal (Subp))) then | |
3621 | Illegal_Indexing | |
3622 | ("indexing function must have at least two parameters"); | |
3623 | return; | |
3624 | ||
3625 | elsif Is_Derived_Type (Ent) then | |
3626 | if (Attr = Name_Constant_Indexing | |
3627 | and then Present | |
3628 | (Find_Aspect (Etype (Ent), Aspect_Constant_Indexing))) | |
f02a9a9a | 3629 | or else |
3630 | (Attr = Name_Variable_Indexing | |
3631 | and then Present | |
3632 | (Find_Aspect (Etype (Ent), Aspect_Variable_Indexing))) | |
05987af3 | 3633 | then |
3634 | if Debug_Flag_Dot_XX then | |
3635 | null; | |
3636 | ||
3637 | else | |
3638 | Illegal_Indexing | |
3639 | ("indexing function already inherited " | |
3640 | & "from parent type"); | |
7796365f | 3641 | return; |
05987af3 | 3642 | end if; |
05987af3 | 3643 | end if; |
3644 | end if; | |
3645 | ||
cac18f71 | 3646 | if not Check_Primitive_Function (Subp) |
cac18f71 | 3647 | then |
05987af3 | 3648 | Illegal_Indexing |
3649 | ("Indexing aspect requires a function that applies to type&"); | |
3650 | return; | |
81b424ac | 3651 | end if; |
3652 | ||
7796365f | 3653 | -- If partial declaration exists, verify that it is not tagged. |
3654 | ||
3655 | if Ekind (Current_Scope) = E_Package | |
3656 | and then Has_Private_Declaration (Ent) | |
3657 | and then From_Aspect_Specification (N) | |
7c0c95b8 | 3658 | and then |
3659 | List_Containing (Parent (Ent)) = | |
3660 | Private_Declarations | |
7796365f | 3661 | (Specification (Unit_Declaration_Node (Current_Scope))) |
3662 | and then Nkind (N) = N_Attribute_Definition_Clause | |
3663 | then | |
3664 | declare | |
3665 | Decl : Node_Id; | |
3666 | ||
3667 | begin | |
3668 | Decl := | |
3669 | First (Visible_Declarations | |
7c0c95b8 | 3670 | (Specification |
3671 | (Unit_Declaration_Node (Current_Scope)))); | |
7796365f | 3672 | |
3673 | while Present (Decl) loop | |
3674 | if Nkind (Decl) = N_Private_Type_Declaration | |
3675 | and then Ent = Full_View (Defining_Identifier (Decl)) | |
3676 | and then Tagged_Present (Decl) | |
3677 | and then No (Aspect_Specifications (Decl)) | |
3678 | then | |
3679 | Illegal_Indexing | |
3680 | ("Indexing aspect cannot be specified on full view " | |
7c0c95b8 | 3681 | & "if partial view is tagged"); |
7796365f | 3682 | return; |
3683 | end if; | |
3684 | ||
3685 | Next (Decl); | |
3686 | end loop; | |
3687 | end; | |
3688 | end if; | |
3689 | ||
1b7510f9 | 3690 | -- An indexing function must return either the default element of |
cac18f71 | 3691 | -- the container, or a reference type. For variable indexing it |
a45d946f | 3692 | -- must be the latter. |
1b7510f9 | 3693 | |
05987af3 | 3694 | Default_Element := |
3695 | Find_Value_Of_Aspect | |
3696 | (Etype (First_Formal (Subp)), Aspect_Iterator_Element); | |
3697 | ||
1b7510f9 | 3698 | if Present (Default_Element) then |
3699 | Analyze (Default_Element); | |
a45d946f | 3700 | |
1b7510f9 | 3701 | if Is_Entity_Name (Default_Element) |
05987af3 | 3702 | and then not Covers (Entity (Default_Element), Ret_Type) |
3703 | and then False | |
1b7510f9 | 3704 | then |
05987af3 | 3705 | Illegal_Indexing |
3706 | ("wrong return type for indexing function"); | |
1b7510f9 | 3707 | return; |
3708 | end if; | |
3709 | end if; | |
3710 | ||
a45d946f | 3711 | -- For variable_indexing the return type must be a reference type |
1b7510f9 | 3712 | |
05987af3 | 3713 | if Attr = Name_Variable_Indexing then |
3714 | if not Has_Implicit_Dereference (Ret_Type) then | |
3715 | Illegal_Indexing | |
3716 | ("variable indexing must return a reference type"); | |
3717 | return; | |
3718 | ||
3719 | elsif Is_Access_Constant (Etype (First_Discriminant (Ret_Type))) | |
3720 | then | |
3721 | Illegal_Indexing | |
3722 | ("variable indexing must return an access to variable"); | |
3723 | return; | |
3724 | end if; | |
cac18f71 | 3725 | |
3726 | else | |
05987af3 | 3727 | if Has_Implicit_Dereference (Ret_Type) |
3728 | and then not | |
3729 | Is_Access_Constant (Etype (First_Discriminant (Ret_Type))) | |
3730 | then | |
3731 | Illegal_Indexing | |
3732 | ("constant indexing must return an access to constant"); | |
3733 | return; | |
3734 | ||
3735 | elsif Is_Access_Type (Etype (First_Formal (Subp))) | |
3736 | and then not Is_Access_Constant (Etype (First_Formal (Subp))) | |
3737 | then | |
3738 | Illegal_Indexing | |
3739 | ("constant indexing must apply to an access to constant"); | |
3740 | return; | |
3741 | end if; | |
81b424ac | 3742 | end if; |
05987af3 | 3743 | |
3744 | -- All checks succeeded. | |
3745 | ||
3746 | Indexing_Found := True; | |
81b424ac | 3747 | end Check_One_Function; |
3748 | ||
05987af3 | 3749 | ----------------------- |
3750 | -- Illegal_Indexing -- | |
3751 | ----------------------- | |
3752 | ||
3753 | procedure Illegal_Indexing (Msg : String) is | |
3754 | begin | |
7796365f | 3755 | Error_Msg_NE (Msg, N, Ent); |
05987af3 | 3756 | end Illegal_Indexing; |
3757 | ||
81b424ac | 3758 | -- Start of processing for Check_Indexing_Functions |
3759 | ||
3760 | begin | |
89cc7147 | 3761 | if In_Instance then |
3762 | return; | |
3763 | end if; | |
3764 | ||
81b424ac | 3765 | Analyze (Expr); |
3766 | ||
3767 | if not Is_Overloaded (Expr) then | |
3768 | Check_One_Function (Entity (Expr)); | |
3769 | ||
3770 | else | |
3771 | declare | |
2c5754de | 3772 | I : Interp_Index; |
81b424ac | 3773 | It : Interp; |
3774 | ||
3775 | begin | |
cac18f71 | 3776 | Indexing_Found := False; |
81b424ac | 3777 | Get_First_Interp (Expr, I, It); |
3778 | while Present (It.Nam) loop | |
3779 | ||
3780 | -- Note that analysis will have added the interpretation | |
3781 | -- that corresponds to the dereference. We only check the | |
3782 | -- subprogram itself. | |
3783 | ||
3784 | if Is_Overloadable (It.Nam) then | |
3785 | Check_One_Function (It.Nam); | |
3786 | end if; | |
3787 | ||
3788 | Get_Next_Interp (I, It); | |
3789 | end loop; | |
3790 | end; | |
3791 | end if; | |
7796365f | 3792 | |
7c0c95b8 | 3793 | if not Indexing_Found and then not Error_Posted (N) then |
7796365f | 3794 | Error_Msg_NE |
3795 | ("aspect Indexing requires a local function that " | |
3796 | & "applies to type&", Expr, Ent); | |
3797 | end if; | |
81b424ac | 3798 | end Check_Indexing_Functions; |
3799 | ||
89cc7147 | 3800 | ------------------------------ |
3801 | -- Check_Iterator_Functions -- | |
3802 | ------------------------------ | |
3803 | ||
3804 | procedure Check_Iterator_Functions is | |
3805 | Default : Entity_Id; | |
3806 | ||
3807 | function Valid_Default_Iterator (Subp : Entity_Id) return Boolean; | |
8df4f2a5 | 3808 | -- Check one possible interpretation for validity |
89cc7147 | 3809 | |
3810 | ---------------------------- | |
3811 | -- Valid_Default_Iterator -- | |
3812 | ---------------------------- | |
3813 | ||
3814 | function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is | |
3815 | Formal : Entity_Id; | |
3816 | ||
3817 | begin | |
3818 | if not Check_Primitive_Function (Subp) then | |
3819 | return False; | |
3820 | else | |
3821 | Formal := First_Formal (Subp); | |
3822 | end if; | |
3823 | ||
8df4f2a5 | 3824 | -- False if any subsequent formal has no default expression |
89cc7147 | 3825 | |
8df4f2a5 | 3826 | Formal := Next_Formal (Formal); |
3827 | while Present (Formal) loop | |
3828 | if No (Expression (Parent (Formal))) then | |
3829 | return False; | |
3830 | end if; | |
89cc7147 | 3831 | |
8df4f2a5 | 3832 | Next_Formal (Formal); |
3833 | end loop; | |
89cc7147 | 3834 | |
8df4f2a5 | 3835 | -- True if all subsequent formals have default expressions |
89cc7147 | 3836 | |
3837 | return True; | |
3838 | end Valid_Default_Iterator; | |
3839 | ||
3840 | -- Start of processing for Check_Iterator_Functions | |
3841 | ||
3842 | begin | |
3843 | Analyze (Expr); | |
3844 | ||
3845 | if not Is_Entity_Name (Expr) then | |
3846 | Error_Msg_N ("aspect Iterator must be a function name", Expr); | |
3847 | end if; | |
3848 | ||
3849 | if not Is_Overloaded (Expr) then | |
3850 | if not Check_Primitive_Function (Entity (Expr)) then | |
3851 | Error_Msg_NE | |
3852 | ("aspect Indexing requires a function that applies to type&", | |
3853 | Entity (Expr), Ent); | |
3854 | end if; | |
3855 | ||
3856 | if not Valid_Default_Iterator (Entity (Expr)) then | |
3857 | Error_Msg_N ("improper function for default iterator", Expr); | |
3858 | end if; | |
3859 | ||
3860 | else | |
3861 | Default := Empty; | |
3862 | declare | |
3863 | I : Interp_Index; | |
3864 | It : Interp; | |
3865 | ||
3866 | begin | |
3867 | Get_First_Interp (Expr, I, It); | |
3868 | while Present (It.Nam) loop | |
3869 | if not Check_Primitive_Function (It.Nam) | |
59f3e675 | 3870 | or else not Valid_Default_Iterator (It.Nam) |
89cc7147 | 3871 | then |
3872 | Remove_Interp (I); | |
3873 | ||
3874 | elsif Present (Default) then | |
3875 | Error_Msg_N ("default iterator must be unique", Expr); | |
3876 | ||
3877 | else | |
3878 | Default := It.Nam; | |
3879 | end if; | |
3880 | ||
3881 | Get_Next_Interp (I, It); | |
3882 | end loop; | |
3883 | end; | |
3884 | ||
3885 | if Present (Default) then | |
3886 | Set_Entity (Expr, Default); | |
3887 | Set_Is_Overloaded (Expr, False); | |
3888 | end if; | |
3889 | end if; | |
3890 | end Check_Iterator_Functions; | |
3891 | ||
3892 | ------------------------------- | |
3893 | -- Check_Primitive_Function -- | |
3894 | ------------------------------- | |
3895 | ||
3896 | function Check_Primitive_Function (Subp : Entity_Id) return Boolean is | |
3897 | Ctrl : Entity_Id; | |
3898 | ||
3899 | begin | |
3900 | if Ekind (Subp) /= E_Function then | |
3901 | return False; | |
3902 | end if; | |
3903 | ||
3904 | if No (First_Formal (Subp)) then | |
3905 | return False; | |
3906 | else | |
3907 | Ctrl := Etype (First_Formal (Subp)); | |
3908 | end if; | |
3909 | ||
7d6fb253 | 3910 | -- Type of formal may be the class-wide type, an access to such, |
3911 | -- or an incomplete view. | |
3912 | ||
89cc7147 | 3913 | if Ctrl = Ent |
3914 | or else Ctrl = Class_Wide_Type (Ent) | |
3915 | or else | |
3916 | (Ekind (Ctrl) = E_Anonymous_Access_Type | |
b85d62ec | 3917 | and then (Designated_Type (Ctrl) = Ent |
3918 | or else | |
3919 | Designated_Type (Ctrl) = Class_Wide_Type (Ent))) | |
7d6fb253 | 3920 | or else |
3921 | (Ekind (Ctrl) = E_Incomplete_Type | |
3922 | and then Full_View (Ctrl) = Ent) | |
89cc7147 | 3923 | then |
3924 | null; | |
89cc7147 | 3925 | else |
3926 | return False; | |
3927 | end if; | |
3928 | ||
3929 | return True; | |
3930 | end Check_Primitive_Function; | |
3931 | ||
ae888dbd | 3932 | ---------------------- |
3933 | -- Duplicate_Clause -- | |
3934 | ---------------------- | |
3935 | ||
3936 | function Duplicate_Clause return Boolean is | |
d74fc39a | 3937 | A : Node_Id; |
ae888dbd | 3938 | |
3939 | begin | |
c8969ba6 | 3940 | -- Nothing to do if this attribute definition clause comes from |
3941 | -- an aspect specification, since we could not be duplicating an | |
ae888dbd | 3942 | -- explicit clause, and we dealt with the case of duplicated aspects |
3943 | -- in Analyze_Aspect_Specifications. | |
3944 | ||
3945 | if From_Aspect_Specification (N) then | |
3946 | return False; | |
3947 | end if; | |
3948 | ||
89f1e35c | 3949 | -- Otherwise current clause may duplicate previous clause, or a |
3950 | -- previously given pragma or aspect specification for the same | |
3951 | -- aspect. | |
d74fc39a | 3952 | |
89b3b365 | 3953 | A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False); |
ae888dbd | 3954 | |
3955 | if Present (A) then | |
89f1e35c | 3956 | Error_Msg_Name_1 := Chars (N); |
3957 | Error_Msg_Sloc := Sloc (A); | |
3958 | ||
89b3b365 | 3959 | Error_Msg_NE ("aspect% for & previously given#", N, U_Ent); |
89f1e35c | 3960 | return True; |
ae888dbd | 3961 | end if; |
3962 | ||
3963 | return False; | |
3964 | end Duplicate_Clause; | |
3965 | ||
9f373bb8 | 3966 | -- Start of processing for Analyze_Attribute_Definition_Clause |
3967 | ||
d6f39728 | 3968 | begin |
d64221a7 | 3969 | -- The following code is a defense against recursion. Not clear that |
51fa2a45 | 3970 | -- this can happen legitimately, but perhaps some error situations can |
3971 | -- cause it, and we did see this recursion during testing. | |
d64221a7 | 3972 | |
3973 | if Analyzed (N) then | |
3974 | return; | |
3975 | else | |
3976 | Set_Analyzed (N, True); | |
3977 | end if; | |
3978 | ||
a29bc1d9 | 3979 | -- Ignore some selected attributes in CodePeer mode since they are not |
3980 | -- relevant in this context. | |
3981 | ||
3982 | if CodePeer_Mode then | |
3983 | case Id is | |
3984 | ||
3985 | -- Ignore Component_Size in CodePeer mode, to avoid changing the | |
3986 | -- internal representation of types by implicitly packing them. | |
3987 | ||
3988 | when Attribute_Component_Size => | |
3989 | Rewrite (N, Make_Null_Statement (Sloc (N))); | |
3990 | return; | |
3991 | ||
3992 | when others => | |
3993 | null; | |
3994 | end case; | |
3995 | end if; | |
3996 | ||
d8ba53a8 | 3997 | -- Process Ignore_Rep_Clauses option |
eef1ca1e | 3998 | |
d8ba53a8 | 3999 | if Ignore_Rep_Clauses then |
9d627c41 | 4000 | case Id is |
4001 | ||
eef1ca1e | 4002 | -- The following should be ignored. They do not affect legality |
4003 | -- and may be target dependent. The basic idea of -gnatI is to | |
4004 | -- ignore any rep clauses that may be target dependent but do not | |
4005 | -- affect legality (except possibly to be rejected because they | |
4006 | -- are incompatible with the compilation target). | |
9d627c41 | 4007 | |
2f1aac99 | 4008 | when Attribute_Alignment | |
9d627c41 | 4009 | Attribute_Bit_Order | |
4010 | Attribute_Component_Size | | |
4011 | Attribute_Machine_Radix | | |
4012 | Attribute_Object_Size | | |
4013 | Attribute_Size | | |
2ff55065 | 4014 | Attribute_Small | |
9d627c41 | 4015 | Attribute_Stream_Size | |
4016 | Attribute_Value_Size => | |
2ff55065 | 4017 | Kill_Rep_Clause (N); |
9d627c41 | 4018 | return; |
4019 | ||
eef1ca1e | 4020 | -- The following should not be ignored, because in the first place |
51fa2a45 | 4021 | -- they are reasonably portable, and should not cause problems |
4022 | -- in compiling code from another target, and also they do affect | |
4023 | -- legality, e.g. failing to provide a stream attribute for a type | |
4024 | -- may make a program illegal. | |
9d627c41 | 4025 | |
b55f7641 | 4026 | when Attribute_External_Tag | |
4027 | Attribute_Input | | |
4028 | Attribute_Output | | |
4029 | Attribute_Read | | |
4030 | Attribute_Simple_Storage_Pool | | |
4031 | Attribute_Storage_Pool | | |
4032 | Attribute_Storage_Size | | |
4033 | Attribute_Write => | |
9d627c41 | 4034 | null; |
4035 | ||
2ff55065 | 4036 | -- We do not do anything here with address clauses, they will be |
4037 | -- removed by Freeze later on, but for now, it works better to | |
4038 | -- keep then in the tree. | |
4039 | ||
4040 | when Attribute_Address => | |
4041 | null; | |
4042 | ||
b593a52c | 4043 | -- Other cases are errors ("attribute& cannot be set with |
4044 | -- definition clause"), which will be caught below. | |
9d627c41 | 4045 | |
4046 | when others => | |
4047 | null; | |
4048 | end case; | |
fbc67f84 | 4049 | end if; |
4050 | ||
d6f39728 | 4051 | Analyze (Nam); |
4052 | Ent := Entity (Nam); | |
4053 | ||
4054 | if Rep_Item_Too_Early (Ent, N) then | |
4055 | return; | |
4056 | end if; | |
4057 | ||
9f373bb8 | 4058 | -- Rep clause applies to full view of incomplete type or private type if |
4059 | -- we have one (if not, this is a premature use of the type). However, | |
4060 | -- certain semantic checks need to be done on the specified entity (i.e. | |
4061 | -- the private view), so we save it in Ent. | |
d6f39728 | 4062 | |
4063 | if Is_Private_Type (Ent) | |
4064 | and then Is_Derived_Type (Ent) | |
4065 | and then not Is_Tagged_Type (Ent) | |
4066 | and then No (Full_View (Ent)) | |
4067 | then | |
9f373bb8 | 4068 | -- If this is a private type whose completion is a derivation from |
4069 | -- another private type, there is no full view, and the attribute | |
4070 | -- belongs to the type itself, not its underlying parent. | |
d6f39728 | 4071 | |
4072 | U_Ent := Ent; | |
4073 | ||
4074 | elsif Ekind (Ent) = E_Incomplete_Type then | |
d5b349fa | 4075 | |
9f373bb8 | 4076 | -- The attribute applies to the full view, set the entity of the |
4077 | -- attribute definition accordingly. | |
d5b349fa | 4078 | |
d6f39728 | 4079 | Ent := Underlying_Type (Ent); |
4080 | U_Ent := Ent; | |
d5b349fa | 4081 | Set_Entity (Nam, Ent); |
4082 | ||
d6f39728 | 4083 | else |
4084 | U_Ent := Underlying_Type (Ent); | |
4085 | end if; | |
4086 | ||
44705307 | 4087 | -- Avoid cascaded error |
d6f39728 | 4088 | |
4089 | if Etype (Nam) = Any_Type then | |
4090 | return; | |
4091 | ||
89f1e35c | 4092 | -- Must be declared in current scope or in case of an aspect |
ace3389d | 4093 | -- specification, must be visible in current scope. |
44705307 | 4094 | |
89f1e35c | 4095 | elsif Scope (Ent) /= Current_Scope |
ace3389d | 4096 | and then |
4097 | not (From_Aspect_Specification (N) | |
4098 | and then Scope_Within_Or_Same (Current_Scope, Scope (Ent))) | |
89f1e35c | 4099 | then |
d6f39728 | 4100 | Error_Msg_N ("entity must be declared in this scope", Nam); |
4101 | return; | |
4102 | ||
44705307 | 4103 | -- Must not be a source renaming (we do have some cases where the |
4104 | -- expander generates a renaming, and those cases are OK, in such | |
a3248fc4 | 4105 | -- cases any attribute applies to the renamed object as well). |
44705307 | 4106 | |
4107 | elsif Is_Object (Ent) | |
4108 | and then Present (Renamed_Object (Ent)) | |
44705307 | 4109 | then |
a3248fc4 | 4110 | -- Case of renamed object from source, this is an error |
4111 | ||
4112 | if Comes_From_Source (Renamed_Object (Ent)) then | |
4113 | Get_Name_String (Chars (N)); | |
4114 | Error_Msg_Strlen := Name_Len; | |
4115 | Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); | |
4116 | Error_Msg_N | |
4117 | ("~ clause not allowed for a renaming declaration " | |
4118 | & "(RM 13.1(6))", Nam); | |
4119 | return; | |
4120 | ||
4121 | -- For the case of a compiler generated renaming, the attribute | |
4122 | -- definition clause applies to the renamed object created by the | |
4123 | -- expander. The easiest general way to handle this is to create a | |
4124 | -- copy of the attribute definition clause for this object. | |
4125 | ||
9a48fc56 | 4126 | elsif Is_Entity_Name (Renamed_Object (Ent)) then |
a3248fc4 | 4127 | Insert_Action (N, |
4128 | Make_Attribute_Definition_Clause (Loc, | |
4129 | Name => | |
4130 | New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc), | |
4131 | Chars => Chars (N), | |
4132 | Expression => Duplicate_Subexpr (Expression (N)))); | |
9a48fc56 | 4133 | |
4134 | -- If the renamed object is not an entity, it must be a dereference | |
4135 | -- of an unconstrained function call, and we must introduce a new | |
4136 | -- declaration to capture the expression. This is needed in the case | |
4137 | -- of 'Alignment, where the original declaration must be rewritten. | |
4138 | ||
4139 | else | |
4140 | pragma Assert | |
4141 | (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference); | |
4142 | null; | |
a3248fc4 | 4143 | end if; |
44705307 | 4144 | |
4145 | -- If no underlying entity, use entity itself, applies to some | |
4146 | -- previously detected error cases ??? | |
4147 | ||
f15731c4 | 4148 | elsif No (U_Ent) then |
4149 | U_Ent := Ent; | |
4150 | ||
44705307 | 4151 | -- Cannot specify for a subtype (exception Object/Value_Size) |
4152 | ||
d6f39728 | 4153 | elsif Is_Type (U_Ent) |
4154 | and then not Is_First_Subtype (U_Ent) | |
4155 | and then Id /= Attribute_Object_Size | |
4156 | and then Id /= Attribute_Value_Size | |
4157 | and then not From_At_Mod (N) | |
4158 | then | |
4159 | Error_Msg_N ("cannot specify attribute for subtype", Nam); | |
4160 | return; | |
d6f39728 | 4161 | end if; |
4162 | ||
ae888dbd | 4163 | Set_Entity (N, U_Ent); |
25e23a77 | 4164 | Check_Restriction_No_Use_Of_Attribute (N); |
ae888dbd | 4165 | |
d6f39728 | 4166 | -- Switch on particular attribute |
4167 | ||
4168 | case Id is | |
4169 | ||
4170 | ------------- | |
4171 | -- Address -- | |
4172 | ------------- | |
4173 | ||
4174 | -- Address attribute definition clause | |
4175 | ||
4176 | when Attribute_Address => Address : begin | |
177675a7 | 4177 | |
4178 | -- A little error check, catch for X'Address use X'Address; | |
4179 | ||
4180 | if Nkind (Nam) = N_Identifier | |
4181 | and then Nkind (Expr) = N_Attribute_Reference | |
4182 | and then Attribute_Name (Expr) = Name_Address | |
4183 | and then Nkind (Prefix (Expr)) = N_Identifier | |
4184 | and then Chars (Nam) = Chars (Prefix (Expr)) | |
4185 | then | |
4186 | Error_Msg_NE | |
4187 | ("address for & is self-referencing", Prefix (Expr), Ent); | |
4188 | return; | |
4189 | end if; | |
4190 | ||
4191 | -- Not that special case, carry on with analysis of expression | |
4192 | ||
d6f39728 | 4193 | Analyze_And_Resolve (Expr, RTE (RE_Address)); |
4194 | ||
2f1aac99 | 4195 | -- Even when ignoring rep clauses we need to indicate that the |
4196 | -- entity has an address clause and thus it is legal to declare | |
2ff55065 | 4197 | -- it imported. Freeze will get rid of the address clause later. |
2f1aac99 | 4198 | |
4199 | if Ignore_Rep_Clauses then | |
d3ef794c | 4200 | if Ekind_In (U_Ent, E_Variable, E_Constant) then |
2f1aac99 | 4201 | Record_Rep_Item (U_Ent, N); |
4202 | end if; | |
4203 | ||
4204 | return; | |
4205 | end if; | |
4206 | ||
ae888dbd | 4207 | if Duplicate_Clause then |
4208 | null; | |
d6f39728 | 4209 | |
4210 | -- Case of address clause for subprogram | |
4211 | ||
4212 | elsif Is_Subprogram (U_Ent) then | |
d6f39728 | 4213 | if Has_Homonym (U_Ent) then |
4214 | Error_Msg_N | |
4215 | ("address clause cannot be given " & | |
4216 | "for overloaded subprogram", | |
4217 | Nam); | |
83f8f0a6 | 4218 | return; |
d6f39728 | 4219 | end if; |
4220 | ||
83f8f0a6 | 4221 | -- For subprograms, all address clauses are permitted, and we |
4222 | -- mark the subprogram as having a deferred freeze so that Gigi | |
4223 | -- will not elaborate it too soon. | |
d6f39728 | 4224 | |
4225 | -- Above needs more comments, what is too soon about??? | |
4226 | ||
4227 | Set_Has_Delayed_Freeze (U_Ent); | |
4228 | ||
4229 | -- Case of address clause for entry | |
4230 | ||
4231 | elsif Ekind (U_Ent) = E_Entry then | |
d6f39728 | 4232 | if Nkind (Parent (N)) = N_Task_Body then |
4233 | Error_Msg_N | |
4234 | ("entry address must be specified in task spec", Nam); | |
83f8f0a6 | 4235 | return; |
d6f39728 | 4236 | end if; |
4237 | ||
4238 | -- For entries, we require a constant address | |
4239 | ||
4240 | Check_Constant_Address_Clause (Expr, U_Ent); | |
4241 | ||
83f8f0a6 | 4242 | -- Special checks for task types |
4243 | ||
f15731c4 | 4244 | if Is_Task_Type (Scope (U_Ent)) |
4245 | and then Comes_From_Source (Scope (U_Ent)) | |
4246 | then | |
4247 | Error_Msg_N | |
1e3532e7 | 4248 | ("??entry address declared for entry in task type", N); |
f15731c4 | 4249 | Error_Msg_N |
1e3532e7 | 4250 | ("\??only one task can be declared of this type", N); |
f15731c4 | 4251 | end if; |
4252 | ||
83f8f0a6 | 4253 | -- Entry address clauses are obsolescent |
4254 | ||
e0521a36 | 4255 | Check_Restriction (No_Obsolescent_Features, N); |
4256 | ||
9dfe12ae | 4257 | if Warn_On_Obsolescent_Feature then |
4258 | Error_Msg_N | |
1e3532e7 | 4259 | ("?j?attaching interrupt to task entry is an " & |
4260 | "obsolescent feature (RM J.7.1)", N); | |
9dfe12ae | 4261 | Error_Msg_N |
1e3532e7 | 4262 | ("\?j?use interrupt procedure instead", N); |
9dfe12ae | 4263 | end if; |
4264 | ||
83f8f0a6 | 4265 | -- Case of an address clause for a controlled object which we |
4266 | -- consider to be erroneous. | |
9dfe12ae | 4267 | |
83f8f0a6 | 4268 | elsif Is_Controlled (Etype (U_Ent)) |
4269 | or else Has_Controlled_Component (Etype (U_Ent)) | |
4270 | then | |
9dfe12ae | 4271 | Error_Msg_NE |
1e3532e7 | 4272 | ("??controlled object& must not be overlaid", Nam, U_Ent); |
9dfe12ae | 4273 | Error_Msg_N |
1e3532e7 | 4274 | ("\??Program_Error will be raised at run time", Nam); |
9dfe12ae | 4275 | Insert_Action (Declaration_Node (U_Ent), |
4276 | Make_Raise_Program_Error (Loc, | |
4277 | Reason => PE_Overlaid_Controlled_Object)); | |
83f8f0a6 | 4278 | return; |
9dfe12ae | 4279 | |
4280 | -- Case of address clause for a (non-controlled) object | |
d6f39728 | 4281 | |
f02a9a9a | 4282 | elsif Ekind_In (U_Ent, E_Variable, E_Constant) then |
d6f39728 | 4283 | declare |
d6da7448 | 4284 | Expr : constant Node_Id := Expression (N); |
4285 | O_Ent : Entity_Id; | |
4286 | Off : Boolean; | |
d6f39728 | 4287 | |
4288 | begin | |
7ee315cc | 4289 | -- Exported variables cannot have an address clause, because |
4290 | -- this cancels the effect of the pragma Export. | |
d6f39728 | 4291 | |
4292 | if Is_Exported (U_Ent) then | |
4293 | Error_Msg_N | |
4294 | ("cannot export object with address clause", Nam); | |
83f8f0a6 | 4295 | return; |
d6da7448 | 4296 | end if; |
4297 | ||
4298 | Find_Overlaid_Entity (N, O_Ent, Off); | |
d6f39728 | 4299 | |
9dfe12ae | 4300 | -- Overlaying controlled objects is erroneous |
4301 | ||
d6da7448 | 4302 | if Present (O_Ent) |
4303 | and then (Has_Controlled_Component (Etype (O_Ent)) | |
f02a9a9a | 4304 | or else Is_Controlled (Etype (O_Ent))) |
9dfe12ae | 4305 | then |
4306 | Error_Msg_N | |
1e3532e7 | 4307 | ("??cannot overlay with controlled object", Expr); |
9dfe12ae | 4308 | Error_Msg_N |
1e3532e7 | 4309 | ("\??Program_Error will be raised at run time", Expr); |
9dfe12ae | 4310 | Insert_Action (Declaration_Node (U_Ent), |
4311 | Make_Raise_Program_Error (Loc, | |
4312 | Reason => PE_Overlaid_Controlled_Object)); | |
83f8f0a6 | 4313 | return; |
9dfe12ae | 4314 | |
d6da7448 | 4315 | elsif Present (O_Ent) |
9dfe12ae | 4316 | and then Ekind (U_Ent) = E_Constant |
d6da7448 | 4317 | and then not Is_Constant_Object (O_Ent) |
9dfe12ae | 4318 | then |
1e3532e7 | 4319 | Error_Msg_N ("??constant overlays a variable", Expr); |
9dfe12ae | 4320 | |
d6f39728 | 4321 | -- Imported variables can have an address clause, but then |
4322 | -- the import is pretty meaningless except to suppress | |
4323 | -- initializations, so we do not need such variables to | |
4324 | -- be statically allocated (and in fact it causes trouble | |
4325 | -- if the address clause is a local value). | |
4326 | ||
4327 | elsif Is_Imported (U_Ent) then | |
4328 | Set_Is_Statically_Allocated (U_Ent, False); | |
4329 | end if; | |
4330 | ||
4331 | -- We mark a possible modification of a variable with an | |
4332 | -- address clause, since it is likely aliasing is occurring. | |
4333 | ||
177675a7 | 4334 | Note_Possible_Modification (Nam, Sure => False); |
d6f39728 | 4335 | |
83f8f0a6 | 4336 | -- Here we are checking for explicit overlap of one variable |
4337 | -- by another, and if we find this then mark the overlapped | |
4338 | -- variable as also being volatile to prevent unwanted | |
d6da7448 | 4339 | -- optimizations. This is a significant pessimization so |
4340 | -- avoid it when there is an offset, i.e. when the object | |
4341 | -- is composite; they cannot be optimized easily anyway. | |
d6f39728 | 4342 | |
d6da7448 | 4343 | if Present (O_Ent) |
4344 | and then Is_Object (O_Ent) | |
4345 | and then not Off | |
ba5efa21 | 4346 | |
4347 | -- The following test is an expedient solution to what | |
4348 | -- is really a problem in CodePeer. Suppressing the | |
4349 | -- Set_Treat_As_Volatile call here prevents later | |
4350 | -- generation (in some cases) of trees that CodePeer | |
4351 | -- should, but currently does not, handle correctly. | |
4352 | -- This test should probably be removed when CodePeer | |
4353 | -- is improved, just because we want the tree CodePeer | |
4354 | -- analyzes to match the tree for which we generate code | |
4355 | -- as closely as is practical. ??? | |
4356 | ||
4357 | and then not CodePeer_Mode | |
d6da7448 | 4358 | then |
ba5efa21 | 4359 | -- ??? O_Ent might not be in current unit |
4360 | ||
d6da7448 | 4361 | Set_Treat_As_Volatile (O_Ent); |
d6f39728 | 4362 | end if; |
4363 | ||
9dfe12ae | 4364 | -- Legality checks on the address clause for initialized |
4365 | -- objects is deferred until the freeze point, because | |
2beb22b1 | 4366 | -- a subsequent pragma might indicate that the object |
42e09e36 | 4367 | -- is imported and thus not initialized. Also, the address |
4368 | -- clause might involve entities that have yet to be | |
4369 | -- elaborated. | |
9dfe12ae | 4370 | |
4371 | Set_Has_Delayed_Freeze (U_Ent); | |
4372 | ||
51ad5ad2 | 4373 | -- If an initialization call has been generated for this |
4374 | -- object, it needs to be deferred to after the freeze node | |
4375 | -- we have just now added, otherwise GIGI will see a | |
4376 | -- reference to the variable (as actual to the IP call) | |
4377 | -- before its definition. | |
4378 | ||
4379 | declare | |
df9fba45 | 4380 | Init_Call : constant Node_Id := |
4381 | Remove_Init_Call (U_Ent, N); | |
4bba0a8d | 4382 | |
51ad5ad2 | 4383 | begin |
4384 | if Present (Init_Call) then | |
28a4283c | 4385 | Append_Freeze_Action (U_Ent, Init_Call); |
df9fba45 | 4386 | |
28a4283c | 4387 | -- Reset Initialization_Statements pointer so that |
4388 | -- if there is a pragma Import further down, it can | |
4389 | -- clear any default initialization. | |
df9fba45 | 4390 | |
28a4283c | 4391 | Set_Initialization_Statements (U_Ent, Init_Call); |
51ad5ad2 | 4392 | end if; |
4393 | end; | |
4394 | ||
d6f39728 | 4395 | if Is_Exported (U_Ent) then |
4396 | Error_Msg_N | |
4397 | ("& cannot be exported if an address clause is given", | |
4398 | Nam); | |
4399 | Error_Msg_N | |
4bba0a8d | 4400 | ("\define and export a variable " |
4401 | & "that holds its address instead", Nam); | |
d6f39728 | 4402 | end if; |
4403 | ||
44e4341e | 4404 | -- Entity has delayed freeze, so we will generate an |
4405 | -- alignment check at the freeze point unless suppressed. | |
d6f39728 | 4406 | |
44e4341e | 4407 | if not Range_Checks_Suppressed (U_Ent) |
4408 | and then not Alignment_Checks_Suppressed (U_Ent) | |
4409 | then | |
4410 | Set_Check_Address_Alignment (N); | |
4411 | end if; | |
d6f39728 | 4412 | |
4413 | -- Kill the size check code, since we are not allocating | |
4414 | -- the variable, it is somewhere else. | |
4415 | ||
4416 | Kill_Size_Check_Code (U_Ent); | |
83f8f0a6 | 4417 | |
d6da7448 | 4418 | -- If the address clause is of the form: |
83f8f0a6 | 4419 | |
d6da7448 | 4420 | -- for Y'Address use X'Address |
83f8f0a6 | 4421 | |
d6da7448 | 4422 | -- or |
83f8f0a6 | 4423 | |
d6da7448 | 4424 | -- Const : constant Address := X'Address; |
4425 | -- ... | |
4426 | -- for Y'Address use Const; | |
83f8f0a6 | 4427 | |
d6da7448 | 4428 | -- then we make an entry in the table for checking the size |
4429 | -- and alignment of the overlaying variable. We defer this | |
4430 | -- check till after code generation to take full advantage | |
f4623c89 | 4431 | -- of the annotation done by the back end. |
d64221a7 | 4432 | |
9474aa9c | 4433 | -- If the entity has a generic type, the check will be |
43dd6937 | 4434 | -- performed in the instance if the actual type justifies |
4435 | -- it, and we do not insert the clause in the table to | |
4436 | -- prevent spurious warnings. | |
83f8f0a6 | 4437 | |
f4623c89 | 4438 | -- Note: we used to test Comes_From_Source and only give |
4439 | -- this warning for source entities, but we have removed | |
4440 | -- this test. It really seems bogus to generate overlays | |
4441 | -- that would trigger this warning in generated code. | |
4442 | -- Furthermore, by removing the test, we handle the | |
4443 | -- aspect case properly. | |
4444 | ||
d6da7448 | 4445 | if Address_Clause_Overlay_Warnings |
d6da7448 | 4446 | and then Present (O_Ent) |
4447 | and then Is_Object (O_Ent) | |
4448 | then | |
9474aa9c | 4449 | if not Is_Generic_Type (Etype (U_Ent)) then |
4450 | Address_Clause_Checks.Append ((N, U_Ent, O_Ent, Off)); | |
4451 | end if; | |
177675a7 | 4452 | |
d6da7448 | 4453 | -- If variable overlays a constant view, and we are |
4454 | -- warning on overlays, then mark the variable as | |
4455 | -- overlaying a constant (we will give warnings later | |
4456 | -- if this variable is assigned). | |
177675a7 | 4457 | |
d6da7448 | 4458 | if Is_Constant_Object (O_Ent) |
4459 | and then Ekind (U_Ent) = E_Variable | |
4460 | then | |
4461 | Set_Overlays_Constant (U_Ent); | |
83f8f0a6 | 4462 | end if; |
d6da7448 | 4463 | end if; |
4464 | end; | |
83f8f0a6 | 4465 | |
d6f39728 | 4466 | -- Not a valid entity for an address clause |
4467 | ||
4468 | else | |
4469 | Error_Msg_N ("address cannot be given for &", Nam); | |
4470 | end if; | |
4471 | end Address; | |
4472 | ||
4473 | --------------- | |
4474 | -- Alignment -- | |
4475 | --------------- | |
4476 | ||
4477 | -- Alignment attribute definition clause | |
4478 | ||
b47769f0 | 4479 | when Attribute_Alignment => Alignment : declare |
208fd589 | 4480 | Align : constant Uint := Get_Alignment_Value (Expr); |
4481 | Max_Align : constant Uint := UI_From_Int (Maximum_Alignment); | |
41331dcf | 4482 | |
d6f39728 | 4483 | begin |
4484 | FOnly := True; | |
4485 | ||
4486 | if not Is_Type (U_Ent) | |
4487 | and then Ekind (U_Ent) /= E_Variable | |
4488 | and then Ekind (U_Ent) /= E_Constant | |
4489 | then | |
4490 | Error_Msg_N ("alignment cannot be given for &", Nam); | |
4491 | ||
ae888dbd | 4492 | elsif Duplicate_Clause then |
4493 | null; | |
d6f39728 | 4494 | |
4495 | elsif Align /= No_Uint then | |
4496 | Set_Has_Alignment_Clause (U_Ent); | |
208fd589 | 4497 | |
44705307 | 4498 | -- Tagged type case, check for attempt to set alignment to a |
4499 | -- value greater than Max_Align, and reset if so. | |
4500 | ||
41331dcf | 4501 | if Is_Tagged_Type (U_Ent) and then Align > Max_Align then |
208fd589 | 4502 | Error_Msg_N |
1e3532e7 | 4503 | ("alignment for & set to Maximum_Aligment??", Nam); |
44705307 | 4504 | Set_Alignment (U_Ent, Max_Align); |
4505 | ||
4506 | -- All other cases | |
4507 | ||
208fd589 | 4508 | else |
4509 | Set_Alignment (U_Ent, Align); | |
4510 | end if; | |
b47769f0 | 4511 | |
4512 | -- For an array type, U_Ent is the first subtype. In that case, | |
4513 | -- also set the alignment of the anonymous base type so that | |
4514 | -- other subtypes (such as the itypes for aggregates of the | |
4515 | -- type) also receive the expected alignment. | |
4516 | ||
4517 | if Is_Array_Type (U_Ent) then | |
4518 | Set_Alignment (Base_Type (U_Ent), Align); | |
4519 | end if; | |
d6f39728 | 4520 | end if; |
b47769f0 | 4521 | end Alignment; |
d6f39728 | 4522 | |
4523 | --------------- | |
4524 | -- Bit_Order -- | |
4525 | --------------- | |
4526 | ||
4527 | -- Bit_Order attribute definition clause | |
4528 | ||
4529 | when Attribute_Bit_Order => Bit_Order : declare | |
4530 | begin | |
4531 | if not Is_Record_Type (U_Ent) then | |
4532 | Error_Msg_N | |
4533 | ("Bit_Order can only be defined for record type", Nam); | |
4534 | ||
ae888dbd | 4535 | elsif Duplicate_Clause then |
4536 | null; | |
4537 | ||
d6f39728 | 4538 | else |
4539 | Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); | |
4540 | ||
4541 | if Etype (Expr) = Any_Type then | |
4542 | return; | |
4543 | ||
cda40848 | 4544 | elsif not Is_OK_Static_Expression (Expr) then |
9dfe12ae | 4545 | Flag_Non_Static_Expr |
4546 | ("Bit_Order requires static expression!", Expr); | |
d6f39728 | 4547 | |
4548 | else | |
4549 | if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then | |
fae4ea1f | 4550 | Set_Reverse_Bit_Order (Base_Type (U_Ent), True); |
d6f39728 | 4551 | end if; |
4552 | end if; | |
4553 | end if; | |
4554 | end Bit_Order; | |
4555 | ||
4556 | -------------------- | |
4557 | -- Component_Size -- | |
4558 | -------------------- | |
4559 | ||
4560 | -- Component_Size attribute definition clause | |
4561 | ||
4562 | when Attribute_Component_Size => Component_Size_Case : declare | |
4563 | Csize : constant Uint := Static_Integer (Expr); | |
a0fc8c5b | 4564 | Ctyp : Entity_Id; |
d6f39728 | 4565 | Btype : Entity_Id; |
4566 | Biased : Boolean; | |
4567 | New_Ctyp : Entity_Id; | |
4568 | Decl : Node_Id; | |
4569 | ||
4570 | begin | |
4571 | if not Is_Array_Type (U_Ent) then | |
4572 | Error_Msg_N ("component size requires array type", Nam); | |
4573 | return; | |
4574 | end if; | |
4575 | ||
4576 | Btype := Base_Type (U_Ent); | |
a0fc8c5b | 4577 | Ctyp := Component_Type (Btype); |
d6f39728 | 4578 | |
ae888dbd | 4579 | if Duplicate_Clause then |
4580 | null; | |
d6f39728 | 4581 | |
f3e4db96 | 4582 | elsif Rep_Item_Too_Early (Btype, N) then |
4583 | null; | |
4584 | ||
d6f39728 | 4585 | elsif Csize /= No_Uint then |
a0fc8c5b | 4586 | Check_Size (Expr, Ctyp, Csize, Biased); |
d6f39728 | 4587 | |
d74fc39a | 4588 | -- For the biased case, build a declaration for a subtype that |
4589 | -- will be used to represent the biased subtype that reflects | |
4590 | -- the biased representation of components. We need the subtype | |
4591 | -- to get proper conversions on referencing elements of the | |
4592 | -- array. Note: component size clauses are ignored in VM mode. | |
3062c401 | 4593 | |
4594 | if VM_Target = No_VM then | |
4595 | if Biased then | |
4596 | New_Ctyp := | |
4597 | Make_Defining_Identifier (Loc, | |
4598 | Chars => | |
4599 | New_External_Name (Chars (U_Ent), 'C', 0, 'T')); | |
4600 | ||
4601 | Decl := | |
4602 | Make_Subtype_Declaration (Loc, | |
4603 | Defining_Identifier => New_Ctyp, | |
4604 | Subtype_Indication => | |
4605 | New_Occurrence_Of (Component_Type (Btype), Loc)); | |
4606 | ||
4607 | Set_Parent (Decl, N); | |
4608 | Analyze (Decl, Suppress => All_Checks); | |
4609 | ||
4610 | Set_Has_Delayed_Freeze (New_Ctyp, False); | |
4611 | Set_Esize (New_Ctyp, Csize); | |
4612 | Set_RM_Size (New_Ctyp, Csize); | |
4613 | Init_Alignment (New_Ctyp); | |
3062c401 | 4614 | Set_Is_Itype (New_Ctyp, True); |
4615 | Set_Associated_Node_For_Itype (New_Ctyp, U_Ent); | |
4616 | ||
4617 | Set_Component_Type (Btype, New_Ctyp); | |
b77e4501 | 4618 | Set_Biased (New_Ctyp, N, "component size clause"); |
3062c401 | 4619 | end if; |
4620 | ||
4621 | Set_Component_Size (Btype, Csize); | |
4622 | ||
4623 | -- For VM case, we ignore component size clauses | |
4624 | ||
4625 | else | |
4626 | -- Give a warning unless we are in GNAT mode, in which case | |
4627 | -- the warning is suppressed since it is not useful. | |
4628 | ||
4629 | if not GNAT_Mode then | |
4630 | Error_Msg_N | |
1e3532e7 | 4631 | ("component size ignored in this configuration??", N); |
3062c401 | 4632 | end if; |
d6f39728 | 4633 | end if; |
4634 | ||
a0fc8c5b | 4635 | -- Deal with warning on overridden size |
4636 | ||
4637 | if Warn_On_Overridden_Size | |
4638 | and then Has_Size_Clause (Ctyp) | |
4639 | and then RM_Size (Ctyp) /= Csize | |
4640 | then | |
4641 | Error_Msg_NE | |
1e3532e7 | 4642 | ("component size overrides size clause for&?S?", N, Ctyp); |
a0fc8c5b | 4643 | end if; |
4644 | ||
d6f39728 | 4645 | Set_Has_Component_Size_Clause (Btype, True); |
f3e4db96 | 4646 | Set_Has_Non_Standard_Rep (Btype, True); |
d6f39728 | 4647 | end if; |
4648 | end Component_Size_Case; | |
4649 | ||
81b424ac | 4650 | ----------------------- |
4651 | -- Constant_Indexing -- | |
4652 | ----------------------- | |
4653 | ||
4654 | when Attribute_Constant_Indexing => | |
4655 | Check_Indexing_Functions; | |
4656 | ||
89f1e35c | 4657 | --------- |
4658 | -- CPU -- | |
4659 | --------- | |
4660 | ||
4661 | when Attribute_CPU => CPU : | |
4662 | begin | |
4663 | -- CPU attribute definition clause not allowed except from aspect | |
4664 | -- specification. | |
4665 | ||
4666 | if From_Aspect_Specification (N) then | |
4667 | if not Is_Task_Type (U_Ent) then | |
4668 | Error_Msg_N ("CPU can only be defined for task", Nam); | |
4669 | ||
4670 | elsif Duplicate_Clause then | |
4671 | null; | |
4672 | ||
4673 | else | |
4674 | -- The expression must be analyzed in the special manner | |
4675 | -- described in "Handling of Default and Per-Object | |
4676 | -- Expressions" in sem.ads. | |
4677 | ||
4678 | -- The visibility to the discriminants must be restored | |
4679 | ||
4680 | Push_Scope_And_Install_Discriminants (U_Ent); | |
4681 | Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range)); | |
4682 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
4683 | ||
cda40848 | 4684 | if not Is_OK_Static_Expression (Expr) then |
89f1e35c | 4685 | Check_Restriction (Static_Priorities, Expr); |
4686 | end if; | |
4687 | end if; | |
4688 | ||
4689 | else | |
4690 | Error_Msg_N | |
4691 | ("attribute& cannot be set with definition clause", N); | |
4692 | end if; | |
4693 | end CPU; | |
4694 | ||
89cc7147 | 4695 | ---------------------- |
4696 | -- Default_Iterator -- | |
4697 | ---------------------- | |
4698 | ||
4699 | when Attribute_Default_Iterator => Default_Iterator : declare | |
4700 | Func : Entity_Id; | |
4701 | ||
4702 | begin | |
4703 | if not Is_Tagged_Type (U_Ent) then | |
4704 | Error_Msg_N | |
4705 | ("aspect Default_Iterator applies to tagged type", Nam); | |
4706 | end if; | |
4707 | ||
4708 | Check_Iterator_Functions; | |
4709 | ||
4710 | Analyze (Expr); | |
4711 | ||
4712 | if not Is_Entity_Name (Expr) | |
4713 | or else Ekind (Entity (Expr)) /= E_Function | |
4714 | then | |
4715 | Error_Msg_N ("aspect Iterator must be a function", Expr); | |
4716 | else | |
4717 | Func := Entity (Expr); | |
4718 | end if; | |
4719 | ||
4720 | if No (First_Formal (Func)) | |
4721 | or else Etype (First_Formal (Func)) /= U_Ent | |
4722 | then | |
4723 | Error_Msg_NE | |
4724 | ("Default Iterator must be a primitive of&", Func, U_Ent); | |
4725 | end if; | |
4726 | end Default_Iterator; | |
4727 | ||
89f1e35c | 4728 | ------------------------ |
4729 | -- Dispatching_Domain -- | |
4730 | ------------------------ | |
4731 | ||
4732 | when Attribute_Dispatching_Domain => Dispatching_Domain : | |
4733 | begin | |
4734 | -- Dispatching_Domain attribute definition clause not allowed | |
4735 | -- except from aspect specification. | |
4736 | ||
4737 | if From_Aspect_Specification (N) then | |
4738 | if not Is_Task_Type (U_Ent) then | |
4739 | Error_Msg_N ("Dispatching_Domain can only be defined" & | |
4740 | "for task", | |
4741 | Nam); | |
4742 | ||
4743 | elsif Duplicate_Clause then | |
4744 | null; | |
4745 | ||
4746 | else | |
4747 | -- The expression must be analyzed in the special manner | |
4748 | -- described in "Handling of Default and Per-Object | |
4749 | -- Expressions" in sem.ads. | |
4750 | ||
4751 | -- The visibility to the discriminants must be restored | |
4752 | ||
4753 | Push_Scope_And_Install_Discriminants (U_Ent); | |
4754 | ||
4755 | Preanalyze_Spec_Expression | |
4756 | (Expr, RTE (RE_Dispatching_Domain)); | |
4757 | ||
4758 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
4759 | end if; | |
4760 | ||
4761 | else | |
4762 | Error_Msg_N | |
4763 | ("attribute& cannot be set with definition clause", N); | |
4764 | end if; | |
4765 | end Dispatching_Domain; | |
4766 | ||
d6f39728 | 4767 | ------------------ |
4768 | -- External_Tag -- | |
4769 | ------------------ | |
4770 | ||
4771 | when Attribute_External_Tag => External_Tag : | |
4772 | begin | |
4773 | if not Is_Tagged_Type (U_Ent) then | |
4774 | Error_Msg_N ("should be a tagged type", Nam); | |
4775 | end if; | |
4776 | ||
ae888dbd | 4777 | if Duplicate_Clause then |
4778 | null; | |
d6f39728 | 4779 | |
9af0ddc7 | 4780 | else |
ae888dbd | 4781 | Analyze_And_Resolve (Expr, Standard_String); |
fbc67f84 | 4782 | |
cda40848 | 4783 | if not Is_OK_Static_Expression (Expr) then |
ae888dbd | 4784 | Flag_Non_Static_Expr |
4785 | ("static string required for tag name!", Nam); | |
4786 | end if; | |
4787 | ||
15a67a0a | 4788 | if VM_Target /= No_VM then |
ae888dbd | 4789 | Error_Msg_Name_1 := Attr; |
4790 | Error_Msg_N | |
4791 | ("% attribute unsupported in this configuration", Nam); | |
4792 | end if; | |
4793 | ||
4794 | if not Is_Library_Level_Entity (U_Ent) then | |
4795 | Error_Msg_NE | |
1e3532e7 | 4796 | ("??non-unique external tag supplied for &", N, U_Ent); |
ae888dbd | 4797 | Error_Msg_N |
1e3532e7 | 4798 | ("\??same external tag applies to all " |
4799 | & "subprogram calls", N); | |
ae888dbd | 4800 | Error_Msg_N |
1e3532e7 | 4801 | ("\??corresponding internal tag cannot be obtained", N); |
ae888dbd | 4802 | end if; |
fbc67f84 | 4803 | end if; |
d6f39728 | 4804 | end External_Tag; |
4805 | ||
b57530b8 | 4806 | -------------------------- |
4807 | -- Implicit_Dereference -- | |
4808 | -------------------------- | |
7947a439 | 4809 | |
b57530b8 | 4810 | when Attribute_Implicit_Dereference => |
7947a439 | 4811 | |
2beb22b1 | 4812 | -- Legality checks already performed at the point of the type |
4813 | -- declaration, aspect is not delayed. | |
7947a439 | 4814 | |
89cc7147 | 4815 | null; |
b57530b8 | 4816 | |
d6f39728 | 4817 | ----------- |
4818 | -- Input -- | |
4819 | ----------- | |
4820 | ||
9f373bb8 | 4821 | when Attribute_Input => |
4822 | Analyze_Stream_TSS_Definition (TSS_Stream_Input); | |
4823 | Set_Has_Specified_Stream_Input (Ent); | |
d6f39728 | 4824 | |
89f1e35c | 4825 | ------------------------ |
4826 | -- Interrupt_Priority -- | |
4827 | ------------------------ | |
4828 | ||
4829 | when Attribute_Interrupt_Priority => Interrupt_Priority : | |
4830 | begin | |
4831 | -- Interrupt_Priority attribute definition clause not allowed | |
4832 | -- except from aspect specification. | |
4833 | ||
4834 | if From_Aspect_Specification (N) then | |
f02a9a9a | 4835 | if not Is_Concurrent_Type (U_Ent) then |
89f1e35c | 4836 | Error_Msg_N |
f02a9a9a | 4837 | ("Interrupt_Priority can only be defined for task " |
4838 | & "and protected object", Nam); | |
89f1e35c | 4839 | |
4840 | elsif Duplicate_Clause then | |
4841 | null; | |
4842 | ||
4843 | else | |
4844 | -- The expression must be analyzed in the special manner | |
4845 | -- described in "Handling of Default and Per-Object | |
4846 | -- Expressions" in sem.ads. | |
4847 | ||
4848 | -- The visibility to the discriminants must be restored | |
4849 | ||
4850 | Push_Scope_And_Install_Discriminants (U_Ent); | |
4851 | ||
4852 | Preanalyze_Spec_Expression | |
4853 | (Expr, RTE (RE_Interrupt_Priority)); | |
4854 | ||
4855 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
4856 | end if; | |
4857 | ||
4858 | else | |
4859 | Error_Msg_N | |
4860 | ("attribute& cannot be set with definition clause", N); | |
4861 | end if; | |
4862 | end Interrupt_Priority; | |
4863 | ||
b3f8228a | 4864 | -------------- |
4865 | -- Iterable -- | |
4866 | -------------- | |
4867 | ||
4868 | when Attribute_Iterable => | |
4869 | Analyze (Expr); | |
bde03454 | 4870 | |
b3f8228a | 4871 | if Nkind (Expr) /= N_Aggregate then |
4872 | Error_Msg_N ("aspect Iterable must be an aggregate", Expr); | |
4873 | end if; | |
4874 | ||
4875 | declare | |
4876 | Assoc : Node_Id; | |
4877 | ||
4878 | begin | |
4879 | Assoc := First (Component_Associations (Expr)); | |
4880 | while Present (Assoc) loop | |
4881 | if not Is_Entity_Name (Expression (Assoc)) then | |
4882 | Error_Msg_N ("value must be a function", Assoc); | |
4883 | end if; | |
bde03454 | 4884 | |
b3f8228a | 4885 | Next (Assoc); |
4886 | end loop; | |
4887 | end; | |
4888 | ||
89cc7147 | 4889 | ---------------------- |
4890 | -- Iterator_Element -- | |
4891 | ---------------------- | |
4892 | ||
4893 | when Attribute_Iterator_Element => | |
4894 | Analyze (Expr); | |
4895 | ||
4896 | if not Is_Entity_Name (Expr) | |
4897 | or else not Is_Type (Entity (Expr)) | |
4898 | then | |
4899 | Error_Msg_N ("aspect Iterator_Element must be a type", Expr); | |
4900 | end if; | |
4901 | ||
d6f39728 | 4902 | ------------------- |
4903 | -- Machine_Radix -- | |
4904 | ------------------- | |
4905 | ||
4906 | -- Machine radix attribute definition clause | |
4907 | ||
4908 | when Attribute_Machine_Radix => Machine_Radix : declare | |
4909 | Radix : constant Uint := Static_Integer (Expr); | |
4910 | ||
4911 | begin | |
4912 | if not Is_Decimal_Fixed_Point_Type (U_Ent) then | |
4913 | Error_Msg_N ("decimal fixed-point type expected for &", Nam); | |
4914 | ||
ae888dbd | 4915 | elsif Duplicate_Clause then |
4916 | null; | |
d6f39728 | 4917 | |
4918 | elsif Radix /= No_Uint then | |
4919 | Set_Has_Machine_Radix_Clause (U_Ent); | |
4920 | Set_Has_Non_Standard_Rep (Base_Type (U_Ent)); | |
4921 | ||
4922 | if Radix = 2 then | |
4923 | null; | |
4924 | elsif Radix = 10 then | |
4925 | Set_Machine_Radix_10 (U_Ent); | |
4926 | else | |
4927 | Error_Msg_N ("machine radix value must be 2 or 10", Expr); | |
4928 | end if; | |
4929 | end if; | |
4930 | end Machine_Radix; | |
4931 | ||
4932 | ----------------- | |
4933 | -- Object_Size -- | |
4934 | ----------------- | |
4935 | ||
4936 | -- Object_Size attribute definition clause | |
4937 | ||
4938 | when Attribute_Object_Size => Object_Size : declare | |
bfa5a9d9 | 4939 | Size : constant Uint := Static_Integer (Expr); |
4940 | ||
d6f39728 | 4941 | Biased : Boolean; |
bfa5a9d9 | 4942 | pragma Warnings (Off, Biased); |
d6f39728 | 4943 | |
4944 | begin | |
4945 | if not Is_Type (U_Ent) then | |
4946 | Error_Msg_N ("Object_Size cannot be given for &", Nam); | |
4947 | ||
ae888dbd | 4948 | elsif Duplicate_Clause then |
4949 | null; | |
d6f39728 | 4950 | |
4951 | else | |
4952 | Check_Size (Expr, U_Ent, Size, Biased); | |
4953 | ||
829cd457 | 4954 | if Is_Scalar_Type (U_Ent) then |
4955 | if Size /= 8 and then Size /= 16 and then Size /= 32 | |
4956 | and then UI_Mod (Size, 64) /= 0 | |
4957 | then | |
4958 | Error_Msg_N | |
4959 | ("Object_Size must be 8, 16, 32, or multiple of 64", | |
4960 | Expr); | |
4961 | end if; | |
4962 | ||
4963 | elsif Size mod 8 /= 0 then | |
4964 | Error_Msg_N ("Object_Size must be a multiple of 8", Expr); | |
d6f39728 | 4965 | end if; |
4966 | ||
4967 | Set_Esize (U_Ent, Size); | |
4968 | Set_Has_Object_Size_Clause (U_Ent); | |
1d366b32 | 4969 | Alignment_Check_For_Size_Change (U_Ent, Size); |
d6f39728 | 4970 | end if; |
4971 | end Object_Size; | |
4972 | ||
4973 | ------------ | |
4974 | -- Output -- | |
4975 | ------------ | |
4976 | ||
9f373bb8 | 4977 | when Attribute_Output => |
4978 | Analyze_Stream_TSS_Definition (TSS_Stream_Output); | |
4979 | Set_Has_Specified_Stream_Output (Ent); | |
d6f39728 | 4980 | |
89f1e35c | 4981 | -------------- |
4982 | -- Priority -- | |
4983 | -------------- | |
4984 | ||
4985 | when Attribute_Priority => Priority : | |
4986 | begin | |
4987 | -- Priority attribute definition clause not allowed except from | |
4988 | -- aspect specification. | |
4989 | ||
4990 | if From_Aspect_Specification (N) then | |
f02a9a9a | 4991 | if not (Is_Concurrent_Type (U_Ent) |
3a72f9c3 | 4992 | or else Ekind (U_Ent) = E_Procedure) |
89f1e35c | 4993 | then |
4994 | Error_Msg_N | |
f02a9a9a | 4995 | ("Priority can only be defined for task and protected " |
4996 | & "object", Nam); | |
89f1e35c | 4997 | |
4998 | elsif Duplicate_Clause then | |
4999 | null; | |
5000 | ||
5001 | else | |
5002 | -- The expression must be analyzed in the special manner | |
5003 | -- described in "Handling of Default and Per-Object | |
5004 | -- Expressions" in sem.ads. | |
5005 | ||
5006 | -- The visibility to the discriminants must be restored | |
5007 | ||
5008 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5009 | Preanalyze_Spec_Expression (Expr, Standard_Integer); | |
5010 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
5011 | ||
cda40848 | 5012 | if not Is_OK_Static_Expression (Expr) then |
89f1e35c | 5013 | Check_Restriction (Static_Priorities, Expr); |
5014 | end if; | |
5015 | end if; | |
5016 | ||
5017 | else | |
5018 | Error_Msg_N | |
5019 | ("attribute& cannot be set with definition clause", N); | |
5020 | end if; | |
5021 | end Priority; | |
5022 | ||
d6f39728 | 5023 | ---------- |
5024 | -- Read -- | |
5025 | ---------- | |
5026 | ||
9f373bb8 | 5027 | when Attribute_Read => |
5028 | Analyze_Stream_TSS_Definition (TSS_Stream_Read); | |
5029 | Set_Has_Specified_Stream_Read (Ent); | |
d6f39728 | 5030 | |
b7b74740 | 5031 | -------------------------- |
5032 | -- Scalar_Storage_Order -- | |
5033 | -------------------------- | |
5034 | ||
5035 | -- Scalar_Storage_Order attribute definition clause | |
5036 | ||
5037 | when Attribute_Scalar_Storage_Order => Scalar_Storage_Order : declare | |
5038 | begin | |
b43a5770 | 5039 | if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then |
b7b74740 | 5040 | Error_Msg_N |
b43a5770 | 5041 | ("Scalar_Storage_Order can only be defined for " |
5042 | & "record or array type", Nam); | |
b7b74740 | 5043 | |
5044 | elsif Duplicate_Clause then | |
5045 | null; | |
5046 | ||
5047 | else | |
5048 | Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); | |
5049 | ||
5050 | if Etype (Expr) = Any_Type then | |
5051 | return; | |
5052 | ||
cda40848 | 5053 | elsif not Is_OK_Static_Expression (Expr) then |
b7b74740 | 5054 | Flag_Non_Static_Expr |
5055 | ("Scalar_Storage_Order requires static expression!", Expr); | |
5056 | ||
c0912570 | 5057 | elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then |
5058 | ||
5059 | -- Here for the case of a non-default (i.e. non-confirming) | |
5060 | -- Scalar_Storage_Order attribute definition. | |
5061 | ||
5062 | if Support_Nondefault_SSO_On_Target then | |
d0a9ea3b | 5063 | Set_Reverse_Storage_Order (Base_Type (U_Ent), True); |
c0912570 | 5064 | else |
5065 | Error_Msg_N | |
5066 | ("non-default Scalar_Storage_Order " | |
5067 | & "not supported on target", Expr); | |
b7b74740 | 5068 | end if; |
5069 | end if; | |
b64082f2 | 5070 | |
5071 | -- Clear SSO default indications since explicit setting of the | |
5072 | -- order overrides the defaults. | |
5073 | ||
5074 | Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False); | |
5075 | Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False); | |
b7b74740 | 5076 | end if; |
5077 | end Scalar_Storage_Order; | |
5078 | ||
d6f39728 | 5079 | ---------- |
5080 | -- Size -- | |
5081 | ---------- | |
5082 | ||
5083 | -- Size attribute definition clause | |
5084 | ||
5085 | when Attribute_Size => Size : declare | |
5086 | Size : constant Uint := Static_Integer (Expr); | |
5087 | Etyp : Entity_Id; | |
5088 | Biased : Boolean; | |
5089 | ||
5090 | begin | |
5091 | FOnly := True; | |
5092 | ||
ae888dbd | 5093 | if Duplicate_Clause then |
5094 | null; | |
d6f39728 | 5095 | |
5096 | elsif not Is_Type (U_Ent) | |
5097 | and then Ekind (U_Ent) /= E_Variable | |
5098 | and then Ekind (U_Ent) /= E_Constant | |
5099 | then | |
5100 | Error_Msg_N ("size cannot be given for &", Nam); | |
5101 | ||
5102 | elsif Is_Array_Type (U_Ent) | |
5103 | and then not Is_Constrained (U_Ent) | |
5104 | then | |
5105 | Error_Msg_N | |
5106 | ("size cannot be given for unconstrained array", Nam); | |
5107 | ||
c2b89d6e | 5108 | elsif Size /= No_Uint then |
c2b89d6e | 5109 | if VM_Target /= No_VM and then not GNAT_Mode then |
47495553 | 5110 | |
c2b89d6e | 5111 | -- Size clause is not handled properly on VM targets. |
5112 | -- Display a warning unless we are in GNAT mode, in which | |
5113 | -- case this is useless. | |
47495553 | 5114 | |
682fa897 | 5115 | Error_Msg_N |
1e3532e7 | 5116 | ("size clauses are ignored in this configuration??", N); |
682fa897 | 5117 | end if; |
5118 | ||
d6f39728 | 5119 | if Is_Type (U_Ent) then |
5120 | Etyp := U_Ent; | |
5121 | else | |
5122 | Etyp := Etype (U_Ent); | |
5123 | end if; | |
5124 | ||
59ac57b5 | 5125 | -- Check size, note that Gigi is in charge of checking that the |
5126 | -- size of an array or record type is OK. Also we do not check | |
5127 | -- the size in the ordinary fixed-point case, since it is too | |
5128 | -- early to do so (there may be subsequent small clause that | |
5129 | -- affects the size). We can check the size if a small clause | |
5130 | -- has already been given. | |
d6f39728 | 5131 | |
5132 | if not Is_Ordinary_Fixed_Point_Type (U_Ent) | |
5133 | or else Has_Small_Clause (U_Ent) | |
5134 | then | |
5135 | Check_Size (Expr, Etyp, Size, Biased); | |
b77e4501 | 5136 | Set_Biased (U_Ent, N, "size clause", Biased); |
d6f39728 | 5137 | end if; |
5138 | ||
5139 | -- For types set RM_Size and Esize if possible | |
5140 | ||
5141 | if Is_Type (U_Ent) then | |
5142 | Set_RM_Size (U_Ent, Size); | |
5143 | ||
ada34def | 5144 | -- For elementary types, increase Object_Size to power of 2, |
5145 | -- but not less than a storage unit in any case (normally | |
59ac57b5 | 5146 | -- this means it will be byte addressable). |
d6f39728 | 5147 | |
ada34def | 5148 | -- For all other types, nothing else to do, we leave Esize |
5149 | -- (object size) unset, the back end will set it from the | |
5150 | -- size and alignment in an appropriate manner. | |
5151 | ||
1d366b32 | 5152 | -- In both cases, we check whether the alignment must be |
5153 | -- reset in the wake of the size change. | |
5154 | ||
ada34def | 5155 | if Is_Elementary_Type (U_Ent) then |
f15731c4 | 5156 | if Size <= System_Storage_Unit then |
5157 | Init_Esize (U_Ent, System_Storage_Unit); | |
d6f39728 | 5158 | elsif Size <= 16 then |
5159 | Init_Esize (U_Ent, 16); | |
5160 | elsif Size <= 32 then | |
5161 | Init_Esize (U_Ent, 32); | |
5162 | else | |
5163 | Set_Esize (U_Ent, (Size + 63) / 64 * 64); | |
5164 | end if; | |
5165 | ||
1d366b32 | 5166 | Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent)); |
5167 | else | |
5168 | Alignment_Check_For_Size_Change (U_Ent, Size); | |
d6f39728 | 5169 | end if; |
5170 | ||
d6f39728 | 5171 | -- For objects, set Esize only |
5172 | ||
5173 | else | |
9dfe12ae | 5174 | if Is_Elementary_Type (Etyp) then |
5175 | if Size /= System_Storage_Unit | |
5176 | and then | |
5177 | Size /= System_Storage_Unit * 2 | |
5178 | and then | |
5179 | Size /= System_Storage_Unit * 4 | |
5180 | and then | |
5181 | Size /= System_Storage_Unit * 8 | |
5182 | then | |
5c99c290 | 5183 | Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); |
87d5c1d0 | 5184 | Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8; |
9dfe12ae | 5185 | Error_Msg_N |
5c99c290 | 5186 | ("size for primitive object must be a power of 2" |
87d5c1d0 | 5187 | & " in the range ^-^", N); |
9dfe12ae | 5188 | end if; |
5189 | end if; | |
5190 | ||
d6f39728 | 5191 | Set_Esize (U_Ent, Size); |
5192 | end if; | |
5193 | ||
5194 | Set_Has_Size_Clause (U_Ent); | |
5195 | end if; | |
5196 | end Size; | |
5197 | ||
5198 | ----------- | |
5199 | -- Small -- | |
5200 | ----------- | |
5201 | ||
5202 | -- Small attribute definition clause | |
5203 | ||
5204 | when Attribute_Small => Small : declare | |
5205 | Implicit_Base : constant Entity_Id := Base_Type (U_Ent); | |
5206 | Small : Ureal; | |
5207 | ||
5208 | begin | |
5209 | Analyze_And_Resolve (Expr, Any_Real); | |
5210 | ||
5211 | if Etype (Expr) = Any_Type then | |
5212 | return; | |
5213 | ||
cda40848 | 5214 | elsif not Is_OK_Static_Expression (Expr) then |
9dfe12ae | 5215 | Flag_Non_Static_Expr |
5216 | ("small requires static expression!", Expr); | |
d6f39728 | 5217 | return; |
5218 | ||
5219 | else | |
5220 | Small := Expr_Value_R (Expr); | |
5221 | ||
5222 | if Small <= Ureal_0 then | |
5223 | Error_Msg_N ("small value must be greater than zero", Expr); | |
5224 | return; | |
5225 | end if; | |
5226 | ||
5227 | end if; | |
5228 | ||
5229 | if not Is_Ordinary_Fixed_Point_Type (U_Ent) then | |
5230 | Error_Msg_N | |
5231 | ("small requires an ordinary fixed point type", Nam); | |
5232 | ||
5233 | elsif Has_Small_Clause (U_Ent) then | |
5234 | Error_Msg_N ("small already given for &", Nam); | |
5235 | ||
5236 | elsif Small > Delta_Value (U_Ent) then | |
5237 | Error_Msg_N | |
ce3e25d6 | 5238 | ("small value must not be greater than delta value", Nam); |
d6f39728 | 5239 | |
5240 | else | |
5241 | Set_Small_Value (U_Ent, Small); | |
5242 | Set_Small_Value (Implicit_Base, Small); | |
5243 | Set_Has_Small_Clause (U_Ent); | |
5244 | Set_Has_Small_Clause (Implicit_Base); | |
5245 | Set_Has_Non_Standard_Rep (Implicit_Base); | |
5246 | end if; | |
5247 | end Small; | |
5248 | ||
d6f39728 | 5249 | ------------------ |
5250 | -- Storage_Pool -- | |
5251 | ------------------ | |
5252 | ||
5253 | -- Storage_Pool attribute definition clause | |
5254 | ||
b55f7641 | 5255 | when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool => declare |
d6f39728 | 5256 | Pool : Entity_Id; |
6b567c71 | 5257 | T : Entity_Id; |
d6f39728 | 5258 | |
5259 | begin | |
44e4341e | 5260 | if Ekind (U_Ent) = E_Access_Subprogram_Type then |
5261 | Error_Msg_N | |
5262 | ("storage pool cannot be given for access-to-subprogram type", | |
5263 | Nam); | |
5264 | return; | |
5265 | ||
d3ef794c | 5266 | elsif not |
5267 | Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type) | |
d6f39728 | 5268 | then |
44e4341e | 5269 | Error_Msg_N |
5270 | ("storage pool can only be given for access types", Nam); | |
d6f39728 | 5271 | return; |
5272 | ||
5273 | elsif Is_Derived_Type (U_Ent) then | |
5274 | Error_Msg_N | |
5275 | ("storage pool cannot be given for a derived access type", | |
5276 | Nam); | |
5277 | ||
ae888dbd | 5278 | elsif Duplicate_Clause then |
d6f39728 | 5279 | return; |
5280 | ||
5281 | elsif Present (Associated_Storage_Pool (U_Ent)) then | |
5282 | Error_Msg_N ("storage pool already given for &", Nam); | |
5283 | return; | |
5284 | end if; | |
5285 | ||
6653b695 | 5286 | -- Check for Storage_Size previously given |
5287 | ||
5288 | declare | |
5289 | SS : constant Node_Id := | |
5290 | Get_Attribute_Definition_Clause | |
5291 | (U_Ent, Attribute_Storage_Size); | |
5292 | begin | |
5293 | if Present (SS) then | |
5294 | Check_Pool_Size_Clash (U_Ent, N, SS); | |
5295 | end if; | |
5296 | end; | |
5297 | ||
5298 | -- Storage_Pool case | |
5299 | ||
b55f7641 | 5300 | if Id = Attribute_Storage_Pool then |
5301 | Analyze_And_Resolve | |
5302 | (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool))); | |
5303 | ||
5304 | -- In the Simple_Storage_Pool case, we allow a variable of any | |
b15003c3 | 5305 | -- simple storage pool type, so we Resolve without imposing an |
b55f7641 | 5306 | -- expected type. |
5307 | ||
5308 | else | |
5309 | Analyze_And_Resolve (Expr); | |
5310 | ||
5311 | if not Present (Get_Rep_Pragma | |
b15003c3 | 5312 | (Etype (Expr), Name_Simple_Storage_Pool_Type)) |
b55f7641 | 5313 | then |
5314 | Error_Msg_N | |
5315 | ("expression must be of a simple storage pool type", Expr); | |
5316 | end if; | |
5317 | end if; | |
d6f39728 | 5318 | |
8c5c7277 | 5319 | if not Denotes_Variable (Expr) then |
5320 | Error_Msg_N ("storage pool must be a variable", Expr); | |
5321 | return; | |
5322 | end if; | |
5323 | ||
6b567c71 | 5324 | if Nkind (Expr) = N_Type_Conversion then |
5325 | T := Etype (Expression (Expr)); | |
5326 | else | |
5327 | T := Etype (Expr); | |
5328 | end if; | |
5329 | ||
5330 | -- The Stack_Bounded_Pool is used internally for implementing | |
d64221a7 | 5331 | -- access types with a Storage_Size. Since it only work properly |
5332 | -- when used on one specific type, we need to check that it is not | |
5333 | -- hijacked improperly: | |
5334 | ||
6b567c71 | 5335 | -- type T is access Integer; |
5336 | -- for T'Storage_Size use n; | |
5337 | -- type Q is access Float; | |
5338 | -- for Q'Storage_Size use T'Storage_Size; -- incorrect | |
5339 | ||
15ebb600 | 5340 | if RTE_Available (RE_Stack_Bounded_Pool) |
5341 | and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool) | |
5342 | then | |
5343 | Error_Msg_N ("non-shareable internal Pool", Expr); | |
6b567c71 | 5344 | return; |
5345 | end if; | |
5346 | ||
d6f39728 | 5347 | -- If the argument is a name that is not an entity name, then |
5348 | -- we construct a renaming operation to define an entity of | |
5349 | -- type storage pool. | |
5350 | ||
5351 | if not Is_Entity_Name (Expr) | |
5352 | and then Is_Object_Reference (Expr) | |
5353 | then | |
11deeeb6 | 5354 | Pool := Make_Temporary (Loc, 'P', Expr); |
d6f39728 | 5355 | |
5356 | declare | |
5357 | Rnode : constant Node_Id := | |
5358 | Make_Object_Renaming_Declaration (Loc, | |
5359 | Defining_Identifier => Pool, | |
5360 | Subtype_Mark => | |
5361 | New_Occurrence_Of (Etype (Expr), Loc), | |
11deeeb6 | 5362 | Name => Expr); |
d6f39728 | 5363 | |
5364 | begin | |
f65f7fdf | 5365 | -- If the attribute definition clause comes from an aspect |
5366 | -- clause, then insert the renaming before the associated | |
5367 | -- entity's declaration, since the attribute clause has | |
5368 | -- not yet been appended to the declaration list. | |
5369 | ||
5370 | if From_Aspect_Specification (N) then | |
5371 | Insert_Before (Parent (Entity (N)), Rnode); | |
5372 | else | |
5373 | Insert_Before (N, Rnode); | |
5374 | end if; | |
5375 | ||
d6f39728 | 5376 | Analyze (Rnode); |
5377 | Set_Associated_Storage_Pool (U_Ent, Pool); | |
5378 | end; | |
5379 | ||
5380 | elsif Is_Entity_Name (Expr) then | |
5381 | Pool := Entity (Expr); | |
5382 | ||
5383 | -- If pool is a renamed object, get original one. This can | |
5384 | -- happen with an explicit renaming, and within instances. | |
5385 | ||
5386 | while Present (Renamed_Object (Pool)) | |
5387 | and then Is_Entity_Name (Renamed_Object (Pool)) | |
5388 | loop | |
5389 | Pool := Entity (Renamed_Object (Pool)); | |
5390 | end loop; | |
5391 | ||
5392 | if Present (Renamed_Object (Pool)) | |
5393 | and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion | |
5394 | and then Is_Entity_Name (Expression (Renamed_Object (Pool))) | |
5395 | then | |
5396 | Pool := Entity (Expression (Renamed_Object (Pool))); | |
5397 | end if; | |
5398 | ||
6b567c71 | 5399 | Set_Associated_Storage_Pool (U_Ent, Pool); |
d6f39728 | 5400 | |
5401 | elsif Nkind (Expr) = N_Type_Conversion | |
5402 | and then Is_Entity_Name (Expression (Expr)) | |
5403 | and then Nkind (Original_Node (Expr)) = N_Attribute_Reference | |
5404 | then | |
5405 | Pool := Entity (Expression (Expr)); | |
6b567c71 | 5406 | Set_Associated_Storage_Pool (U_Ent, Pool); |
d6f39728 | 5407 | |
5408 | else | |
5409 | Error_Msg_N ("incorrect reference to a Storage Pool", Expr); | |
5410 | return; | |
5411 | end if; | |
b55f7641 | 5412 | end; |
d6f39728 | 5413 | |
44e4341e | 5414 | ------------------ |
5415 | -- Storage_Size -- | |
5416 | ------------------ | |
5417 | ||
5418 | -- Storage_Size attribute definition clause | |
5419 | ||
5420 | when Attribute_Storage_Size => Storage_Size : declare | |
5421 | Btype : constant Entity_Id := Base_Type (U_Ent); | |
44e4341e | 5422 | |
5423 | begin | |
5424 | if Is_Task_Type (U_Ent) then | |
44e4341e | 5425 | |
39a0c1d3 | 5426 | -- Check obsolescent (but never obsolescent if from aspect) |
ceec4f7c | 5427 | |
5428 | if not From_Aspect_Specification (N) then | |
5429 | Check_Restriction (No_Obsolescent_Features, N); | |
5430 | ||
5431 | if Warn_On_Obsolescent_Feature then | |
5432 | Error_Msg_N | |
5433 | ("?j?storage size clause for task is an " & | |
5434 | "obsolescent feature (RM J.9)", N); | |
5435 | Error_Msg_N ("\?j?use Storage_Size pragma instead", N); | |
5436 | end if; | |
44e4341e | 5437 | end if; |
5438 | ||
5439 | FOnly := True; | |
5440 | end if; | |
5441 | ||
5442 | if not Is_Access_Type (U_Ent) | |
5443 | and then Ekind (U_Ent) /= E_Task_Type | |
5444 | then | |
5445 | Error_Msg_N ("storage size cannot be given for &", Nam); | |
5446 | ||
5447 | elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then | |
5448 | Error_Msg_N | |
5449 | ("storage size cannot be given for a derived access type", | |
5450 | Nam); | |
5451 | ||
ae888dbd | 5452 | elsif Duplicate_Clause then |
5453 | null; | |
44e4341e | 5454 | |
5455 | else | |
5456 | Analyze_And_Resolve (Expr, Any_Integer); | |
5457 | ||
5458 | if Is_Access_Type (U_Ent) then | |
6653b695 | 5459 | |
5460 | -- Check for Storage_Pool previously given | |
5461 | ||
5462 | declare | |
5463 | SP : constant Node_Id := | |
5464 | Get_Attribute_Definition_Clause | |
5465 | (U_Ent, Attribute_Storage_Pool); | |
5466 | ||
5467 | begin | |
5468 | if Present (SP) then | |
5469 | Check_Pool_Size_Clash (U_Ent, SP, N); | |
5470 | end if; | |
5471 | end; | |
5472 | ||
5473 | -- Special case of for x'Storage_Size use 0 | |
44e4341e | 5474 | |
5941a4e9 | 5475 | if Is_OK_Static_Expression (Expr) |
44e4341e | 5476 | and then Expr_Value (Expr) = 0 |
5477 | then | |
5478 | Set_No_Pool_Assigned (Btype); | |
5479 | end if; | |
44e4341e | 5480 | end if; |
5481 | ||
5482 | Set_Has_Storage_Size_Clause (Btype); | |
5483 | end if; | |
5484 | end Storage_Size; | |
5485 | ||
7189d17f | 5486 | ----------------- |
5487 | -- Stream_Size -- | |
5488 | ----------------- | |
5489 | ||
5490 | when Attribute_Stream_Size => Stream_Size : declare | |
5491 | Size : constant Uint := Static_Integer (Expr); | |
5492 | ||
5493 | begin | |
15ebb600 | 5494 | if Ada_Version <= Ada_95 then |
5495 | Check_Restriction (No_Implementation_Attributes, N); | |
5496 | end if; | |
5497 | ||
ae888dbd | 5498 | if Duplicate_Clause then |
5499 | null; | |
7189d17f | 5500 | |
5501 | elsif Is_Elementary_Type (U_Ent) then | |
5502 | if Size /= System_Storage_Unit | |
5503 | and then | |
5504 | Size /= System_Storage_Unit * 2 | |
5505 | and then | |
5506 | Size /= System_Storage_Unit * 4 | |
5507 | and then | |
5508 | Size /= System_Storage_Unit * 8 | |
5509 | then | |
5510 | Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); | |
5511 | Error_Msg_N | |
5512 | ("stream size for elementary type must be a" | |
5513 | & " power of 2 and at least ^", N); | |
5514 | ||
5515 | elsif RM_Size (U_Ent) > Size then | |
5516 | Error_Msg_Uint_1 := RM_Size (U_Ent); | |
5517 | Error_Msg_N | |
5518 | ("stream size for elementary type must be a" | |
5519 | & " power of 2 and at least ^", N); | |
5520 | end if; | |
5521 | ||
5522 | Set_Has_Stream_Size_Clause (U_Ent); | |
5523 | ||
5524 | else | |
5525 | Error_Msg_N ("Stream_Size cannot be given for &", Nam); | |
5526 | end if; | |
5527 | end Stream_Size; | |
5528 | ||
d6f39728 | 5529 | ---------------- |
5530 | -- Value_Size -- | |
5531 | ---------------- | |
5532 | ||
5533 | -- Value_Size attribute definition clause | |
5534 | ||
5535 | when Attribute_Value_Size => Value_Size : declare | |
5536 | Size : constant Uint := Static_Integer (Expr); | |
5537 | Biased : Boolean; | |
5538 | ||
5539 | begin | |
5540 | if not Is_Type (U_Ent) then | |
5541 | Error_Msg_N ("Value_Size cannot be given for &", Nam); | |
5542 | ||
ae888dbd | 5543 | elsif Duplicate_Clause then |
5544 | null; | |
d6f39728 | 5545 | |
59ac57b5 | 5546 | elsif Is_Array_Type (U_Ent) |
5547 | and then not Is_Constrained (U_Ent) | |
5548 | then | |
5549 | Error_Msg_N | |
5550 | ("Value_Size cannot be given for unconstrained array", Nam); | |
5551 | ||
d6f39728 | 5552 | else |
5553 | if Is_Elementary_Type (U_Ent) then | |
5554 | Check_Size (Expr, U_Ent, Size, Biased); | |
b77e4501 | 5555 | Set_Biased (U_Ent, N, "value size clause", Biased); |
d6f39728 | 5556 | end if; |
5557 | ||
5558 | Set_RM_Size (U_Ent, Size); | |
5559 | end if; | |
5560 | end Value_Size; | |
5561 | ||
81b424ac | 5562 | ----------------------- |
5563 | -- Variable_Indexing -- | |
5564 | ----------------------- | |
5565 | ||
5566 | when Attribute_Variable_Indexing => | |
5567 | Check_Indexing_Functions; | |
5568 | ||
d6f39728 | 5569 | ----------- |
5570 | -- Write -- | |
5571 | ----------- | |
5572 | ||
9f373bb8 | 5573 | when Attribute_Write => |
5574 | Analyze_Stream_TSS_Definition (TSS_Stream_Write); | |
5575 | Set_Has_Specified_Stream_Write (Ent); | |
d6f39728 | 5576 | |
5577 | -- All other attributes cannot be set | |
5578 | ||
5579 | when others => | |
5580 | Error_Msg_N | |
5581 | ("attribute& cannot be set with definition clause", N); | |
d6f39728 | 5582 | end case; |
5583 | ||
d64221a7 | 5584 | -- The test for the type being frozen must be performed after any |
5585 | -- expression the clause has been analyzed since the expression itself | |
5586 | -- might cause freezing that makes the clause illegal. | |
d6f39728 | 5587 | |
5588 | if Rep_Item_Too_Late (U_Ent, N, FOnly) then | |
5589 | return; | |
5590 | end if; | |
5591 | end Analyze_Attribute_Definition_Clause; | |
5592 | ||
5593 | ---------------------------- | |
5594 | -- Analyze_Code_Statement -- | |
5595 | ---------------------------- | |
5596 | ||
5597 | procedure Analyze_Code_Statement (N : Node_Id) is | |
5598 | HSS : constant Node_Id := Parent (N); | |
5599 | SBody : constant Node_Id := Parent (HSS); | |
5600 | Subp : constant Entity_Id := Current_Scope; | |
5601 | Stmt : Node_Id; | |
5602 | Decl : Node_Id; | |
5603 | StmtO : Node_Id; | |
5604 | DeclO : Node_Id; | |
5605 | ||
5606 | begin | |
5607 | -- Analyze and check we get right type, note that this implements the | |
5608 | -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that | |
5609 | -- is the only way that Asm_Insn could possibly be visible. | |
5610 | ||
5611 | Analyze_And_Resolve (Expression (N)); | |
5612 | ||
5613 | if Etype (Expression (N)) = Any_Type then | |
5614 | return; | |
5615 | elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then | |
5616 | Error_Msg_N ("incorrect type for code statement", N); | |
5617 | return; | |
5618 | end if; | |
5619 | ||
44e4341e | 5620 | Check_Code_Statement (N); |
5621 | ||
d6f39728 | 5622 | -- Make sure we appear in the handled statement sequence of a |
5623 | -- subprogram (RM 13.8(3)). | |
5624 | ||
5625 | if Nkind (HSS) /= N_Handled_Sequence_Of_Statements | |
5626 | or else Nkind (SBody) /= N_Subprogram_Body | |
5627 | then | |
5628 | Error_Msg_N | |
5629 | ("code statement can only appear in body of subprogram", N); | |
5630 | return; | |
5631 | end if; | |
5632 | ||
5633 | -- Do remaining checks (RM 13.8(3)) if not already done | |
5634 | ||
5635 | if not Is_Machine_Code_Subprogram (Subp) then | |
5636 | Set_Is_Machine_Code_Subprogram (Subp); | |
5637 | ||
5638 | -- No exception handlers allowed | |
5639 | ||
5640 | if Present (Exception_Handlers (HSS)) then | |
5641 | Error_Msg_N | |
5642 | ("exception handlers not permitted in machine code subprogram", | |
5643 | First (Exception_Handlers (HSS))); | |
5644 | end if; | |
5645 | ||
5646 | -- No declarations other than use clauses and pragmas (we allow | |
5647 | -- certain internally generated declarations as well). | |
5648 | ||
5649 | Decl := First (Declarations (SBody)); | |
5650 | while Present (Decl) loop | |
5651 | DeclO := Original_Node (Decl); | |
5652 | if Comes_From_Source (DeclO) | |
fdd294d1 | 5653 | and not Nkind_In (DeclO, N_Pragma, |
5654 | N_Use_Package_Clause, | |
5655 | N_Use_Type_Clause, | |
5656 | N_Implicit_Label_Declaration) | |
d6f39728 | 5657 | then |
5658 | Error_Msg_N | |
5659 | ("this declaration not allowed in machine code subprogram", | |
5660 | DeclO); | |
5661 | end if; | |
5662 | ||
5663 | Next (Decl); | |
5664 | end loop; | |
5665 | ||
5666 | -- No statements other than code statements, pragmas, and labels. | |
5667 | -- Again we allow certain internally generated statements. | |
3ab42ff7 | 5668 | |
c3107527 | 5669 | -- In Ada 2012, qualified expressions are names, and the code |
5670 | -- statement is initially parsed as a procedure call. | |
d6f39728 | 5671 | |
5672 | Stmt := First (Statements (HSS)); | |
5673 | while Present (Stmt) loop | |
5674 | StmtO := Original_Node (Stmt); | |
c3107527 | 5675 | |
59f2fcab | 5676 | -- A procedure call transformed into a code statement is OK. |
5677 | ||
c3107527 | 5678 | if Ada_Version >= Ada_2012 |
5679 | and then Nkind (StmtO) = N_Procedure_Call_Statement | |
59f2fcab | 5680 | and then Nkind (Name (StmtO)) = N_Qualified_Expression |
c3107527 | 5681 | then |
5682 | null; | |
5683 | ||
5684 | elsif Comes_From_Source (StmtO) | |
fdd294d1 | 5685 | and then not Nkind_In (StmtO, N_Pragma, |
5686 | N_Label, | |
5687 | N_Code_Statement) | |
d6f39728 | 5688 | then |
5689 | Error_Msg_N | |
5690 | ("this statement is not allowed in machine code subprogram", | |
5691 | StmtO); | |
5692 | end if; | |
5693 | ||
5694 | Next (Stmt); | |
5695 | end loop; | |
5696 | end if; | |
d6f39728 | 5697 | end Analyze_Code_Statement; |
5698 | ||
5699 | ----------------------------------------------- | |
5700 | -- Analyze_Enumeration_Representation_Clause -- | |
5701 | ----------------------------------------------- | |
5702 | ||
5703 | procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is | |
5704 | Ident : constant Node_Id := Identifier (N); | |
5705 | Aggr : constant Node_Id := Array_Aggregate (N); | |
5706 | Enumtype : Entity_Id; | |
5707 | Elit : Entity_Id; | |
5708 | Expr : Node_Id; | |
5709 | Assoc : Node_Id; | |
5710 | Choice : Node_Id; | |
5711 | Val : Uint; | |
b3190af0 | 5712 | |
5713 | Err : Boolean := False; | |
098d3082 | 5714 | -- Set True to avoid cascade errors and crashes on incorrect source code |
d6f39728 | 5715 | |
e30c7d84 | 5716 | Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer)); |
5717 | Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer)); | |
5718 | -- Allowed range of universal integer (= allowed range of enum lit vals) | |
5719 | ||
d6f39728 | 5720 | Min : Uint; |
5721 | Max : Uint; | |
e30c7d84 | 5722 | -- Minimum and maximum values of entries |
5723 | ||
5724 | Max_Node : Node_Id; | |
5725 | -- Pointer to node for literal providing max value | |
d6f39728 | 5726 | |
5727 | begin | |
ca301e17 | 5728 | if Ignore_Rep_Clauses then |
2ff55065 | 5729 | Kill_Rep_Clause (N); |
fbc67f84 | 5730 | return; |
5731 | end if; | |
5732 | ||
175a6969 | 5733 | -- Ignore enumeration rep clauses by default in CodePeer mode, |
5734 | -- unless -gnatd.I is specified, as a work around for potential false | |
5735 | -- positive messages. | |
5736 | ||
5737 | if CodePeer_Mode and not Debug_Flag_Dot_II then | |
5738 | return; | |
5739 | end if; | |
5740 | ||
d6f39728 | 5741 | -- First some basic error checks |
5742 | ||
5743 | Find_Type (Ident); | |
5744 | Enumtype := Entity (Ident); | |
5745 | ||
5746 | if Enumtype = Any_Type | |
5747 | or else Rep_Item_Too_Early (Enumtype, N) | |
5748 | then | |
5749 | return; | |
5750 | else | |
5751 | Enumtype := Underlying_Type (Enumtype); | |
5752 | end if; | |
5753 | ||
5754 | if not Is_Enumeration_Type (Enumtype) then | |
5755 | Error_Msg_NE | |
5756 | ("enumeration type required, found}", | |
5757 | Ident, First_Subtype (Enumtype)); | |
5758 | return; | |
5759 | end if; | |
5760 | ||
9dfe12ae | 5761 | -- Ignore rep clause on generic actual type. This will already have |
5762 | -- been flagged on the template as an error, and this is the safest | |
5763 | -- way to ensure we don't get a junk cascaded message in the instance. | |
5764 | ||
5765 | if Is_Generic_Actual_Type (Enumtype) then | |
5766 | return; | |
5767 | ||
5768 | -- Type must be in current scope | |
5769 | ||
5770 | elsif Scope (Enumtype) /= Current_Scope then | |
d6f39728 | 5771 | Error_Msg_N ("type must be declared in this scope", Ident); |
5772 | return; | |
5773 | ||
9dfe12ae | 5774 | -- Type must be a first subtype |
5775 | ||
d6f39728 | 5776 | elsif not Is_First_Subtype (Enumtype) then |
5777 | Error_Msg_N ("cannot give enumeration rep clause for subtype", N); | |
5778 | return; | |
5779 | ||
9dfe12ae | 5780 | -- Ignore duplicate rep clause |
5781 | ||
d6f39728 | 5782 | elsif Has_Enumeration_Rep_Clause (Enumtype) then |
5783 | Error_Msg_N ("duplicate enumeration rep clause ignored", N); | |
5784 | return; | |
5785 | ||
7189d17f | 5786 | -- Don't allow rep clause for standard [wide_[wide_]]character |
9dfe12ae | 5787 | |
177675a7 | 5788 | elsif Is_Standard_Character_Type (Enumtype) then |
d6f39728 | 5789 | Error_Msg_N ("enumeration rep clause not allowed for this type", N); |
9dfe12ae | 5790 | return; |
5791 | ||
d9125581 | 5792 | -- Check that the expression is a proper aggregate (no parentheses) |
5793 | ||
5794 | elsif Paren_Count (Aggr) /= 0 then | |
5795 | Error_Msg | |
5796 | ("extra parentheses surrounding aggregate not allowed", | |
5797 | First_Sloc (Aggr)); | |
5798 | return; | |
5799 | ||
9dfe12ae | 5800 | -- All tests passed, so set rep clause in place |
d6f39728 | 5801 | |
5802 | else | |
5803 | Set_Has_Enumeration_Rep_Clause (Enumtype); | |
5804 | Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype)); | |
5805 | end if; | |
5806 | ||
5807 | -- Now we process the aggregate. Note that we don't use the normal | |
5808 | -- aggregate code for this purpose, because we don't want any of the | |
5809 | -- normal expansion activities, and a number of special semantic | |
5810 | -- rules apply (including the component type being any integer type) | |
5811 | ||
d6f39728 | 5812 | Elit := First_Literal (Enumtype); |
5813 | ||
5814 | -- First the positional entries if any | |
5815 | ||
5816 | if Present (Expressions (Aggr)) then | |
5817 | Expr := First (Expressions (Aggr)); | |
5818 | while Present (Expr) loop | |
5819 | if No (Elit) then | |
5820 | Error_Msg_N ("too many entries in aggregate", Expr); | |
5821 | return; | |
5822 | end if; | |
5823 | ||
5824 | Val := Static_Integer (Expr); | |
5825 | ||
d9125581 | 5826 | -- Err signals that we found some incorrect entries processing |
5827 | -- the list. The final checks for completeness and ordering are | |
5828 | -- skipped in this case. | |
5829 | ||
d6f39728 | 5830 | if Val = No_Uint then |
5831 | Err := True; | |
f02a9a9a | 5832 | |
d6f39728 | 5833 | elsif Val < Lo or else Hi < Val then |
5834 | Error_Msg_N ("value outside permitted range", Expr); | |
5835 | Err := True; | |
5836 | end if; | |
5837 | ||
5838 | Set_Enumeration_Rep (Elit, Val); | |
5839 | Set_Enumeration_Rep_Expr (Elit, Expr); | |
5840 | Next (Expr); | |
5841 | Next (Elit); | |
5842 | end loop; | |
5843 | end if; | |
5844 | ||
5845 | -- Now process the named entries if present | |
5846 | ||
5847 | if Present (Component_Associations (Aggr)) then | |
5848 | Assoc := First (Component_Associations (Aggr)); | |
5849 | while Present (Assoc) loop | |
5850 | Choice := First (Choices (Assoc)); | |
5851 | ||
5852 | if Present (Next (Choice)) then | |
5853 | Error_Msg_N | |
5854 | ("multiple choice not allowed here", Next (Choice)); | |
5855 | Err := True; | |
5856 | end if; | |
5857 | ||
5858 | if Nkind (Choice) = N_Others_Choice then | |
5859 | Error_Msg_N ("others choice not allowed here", Choice); | |
5860 | Err := True; | |
5861 | ||
5862 | elsif Nkind (Choice) = N_Range then | |
b3190af0 | 5863 | |
d6f39728 | 5864 | -- ??? should allow zero/one element range here |
b3190af0 | 5865 | |
d6f39728 | 5866 | Error_Msg_N ("range not allowed here", Choice); |
5867 | Err := True; | |
5868 | ||
5869 | else | |
5870 | Analyze_And_Resolve (Choice, Enumtype); | |
b3190af0 | 5871 | |
098d3082 | 5872 | if Error_Posted (Choice) then |
d6f39728 | 5873 | Err := True; |
098d3082 | 5874 | end if; |
d6f39728 | 5875 | |
098d3082 | 5876 | if not Err then |
5877 | if Is_Entity_Name (Choice) | |
5878 | and then Is_Type (Entity (Choice)) | |
5879 | then | |
5880 | Error_Msg_N ("subtype name not allowed here", Choice); | |
d6f39728 | 5881 | Err := True; |
b3190af0 | 5882 | |
098d3082 | 5883 | -- ??? should allow static subtype with zero/one entry |
d6f39728 | 5884 | |
098d3082 | 5885 | elsif Etype (Choice) = Base_Type (Enumtype) then |
cda40848 | 5886 | if not Is_OK_Static_Expression (Choice) then |
098d3082 | 5887 | Flag_Non_Static_Expr |
5888 | ("non-static expression used for choice!", Choice); | |
d6f39728 | 5889 | Err := True; |
d6f39728 | 5890 | |
098d3082 | 5891 | else |
5892 | Elit := Expr_Value_E (Choice); | |
5893 | ||
5894 | if Present (Enumeration_Rep_Expr (Elit)) then | |
5895 | Error_Msg_Sloc := | |
5896 | Sloc (Enumeration_Rep_Expr (Elit)); | |
5897 | Error_Msg_NE | |
5898 | ("representation for& previously given#", | |
5899 | Choice, Elit); | |
5900 | Err := True; | |
5901 | end if; | |
d6f39728 | 5902 | |
098d3082 | 5903 | Set_Enumeration_Rep_Expr (Elit, Expression (Assoc)); |
d6f39728 | 5904 | |
098d3082 | 5905 | Expr := Expression (Assoc); |
5906 | Val := Static_Integer (Expr); | |
d6f39728 | 5907 | |
098d3082 | 5908 | if Val = No_Uint then |
5909 | Err := True; | |
5910 | ||
5911 | elsif Val < Lo or else Hi < Val then | |
5912 | Error_Msg_N ("value outside permitted range", Expr); | |
5913 | Err := True; | |
5914 | end if; | |
d6f39728 | 5915 | |
098d3082 | 5916 | Set_Enumeration_Rep (Elit, Val); |
5917 | end if; | |
d6f39728 | 5918 | end if; |
5919 | end if; | |
5920 | end if; | |
5921 | ||
5922 | Next (Assoc); | |
5923 | end loop; | |
5924 | end if; | |
5925 | ||
5926 | -- Aggregate is fully processed. Now we check that a full set of | |
5927 | -- representations was given, and that they are in range and in order. | |
5928 | -- These checks are only done if no other errors occurred. | |
5929 | ||
5930 | if not Err then | |
5931 | Min := No_Uint; | |
5932 | Max := No_Uint; | |
5933 | ||
5934 | Elit := First_Literal (Enumtype); | |
5935 | while Present (Elit) loop | |
5936 | if No (Enumeration_Rep_Expr (Elit)) then | |
5937 | Error_Msg_NE ("missing representation for&!", N, Elit); | |
5938 | ||
5939 | else | |
5940 | Val := Enumeration_Rep (Elit); | |
5941 | ||
5942 | if Min = No_Uint then | |
5943 | Min := Val; | |
5944 | end if; | |
5945 | ||
5946 | if Val /= No_Uint then | |
5947 | if Max /= No_Uint and then Val <= Max then | |
5948 | Error_Msg_NE | |
5949 | ("enumeration value for& not ordered!", | |
e30c7d84 | 5950 | Enumeration_Rep_Expr (Elit), Elit); |
d6f39728 | 5951 | end if; |
5952 | ||
e30c7d84 | 5953 | Max_Node := Enumeration_Rep_Expr (Elit); |
d6f39728 | 5954 | Max := Val; |
5955 | end if; | |
5956 | ||
e30c7d84 | 5957 | -- If there is at least one literal whose representation is not |
5958 | -- equal to the Pos value, then note that this enumeration type | |
5959 | -- has a non-standard representation. | |
d6f39728 | 5960 | |
5961 | if Val /= Enumeration_Pos (Elit) then | |
5962 | Set_Has_Non_Standard_Rep (Base_Type (Enumtype)); | |
5963 | end if; | |
5964 | end if; | |
5965 | ||
5966 | Next (Elit); | |
5967 | end loop; | |
5968 | ||
5969 | -- Now set proper size information | |
5970 | ||
5971 | declare | |
5972 | Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype)); | |
5973 | ||
5974 | begin | |
5975 | if Has_Size_Clause (Enumtype) then | |
e30c7d84 | 5976 | |
5977 | -- All OK, if size is OK now | |
5978 | ||
5979 | if RM_Size (Enumtype) >= Minsize then | |
d6f39728 | 5980 | null; |
5981 | ||
5982 | else | |
e30c7d84 | 5983 | -- Try if we can get by with biasing |
5984 | ||
d6f39728 | 5985 | Minsize := |
5986 | UI_From_Int (Minimum_Size (Enumtype, Biased => True)); | |
5987 | ||
e30c7d84 | 5988 | -- Error message if even biasing does not work |
5989 | ||
5990 | if RM_Size (Enumtype) < Minsize then | |
5991 | Error_Msg_Uint_1 := RM_Size (Enumtype); | |
5992 | Error_Msg_Uint_2 := Max; | |
5993 | Error_Msg_N | |
5994 | ("previously given size (^) is too small " | |
5995 | & "for this value (^)", Max_Node); | |
5996 | ||
5997 | -- If biasing worked, indicate that we now have biased rep | |
d6f39728 | 5998 | |
5999 | else | |
b77e4501 | 6000 | Set_Biased |
6001 | (Enumtype, Size_Clause (Enumtype), "size clause"); | |
d6f39728 | 6002 | end if; |
6003 | end if; | |
6004 | ||
6005 | else | |
6006 | Set_RM_Size (Enumtype, Minsize); | |
6007 | Set_Enum_Esize (Enumtype); | |
6008 | end if; | |
6009 | ||
6010 | Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype)); | |
6011 | Set_Esize (Base_Type (Enumtype), Esize (Enumtype)); | |
6012 | Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype)); | |
6013 | end; | |
6014 | end if; | |
6015 | ||
39a0c1d3 | 6016 | -- We repeat the too late test in case it froze itself |
d6f39728 | 6017 | |
6018 | if Rep_Item_Too_Late (Enumtype, N) then | |
6019 | null; | |
6020 | end if; | |
d6f39728 | 6021 | end Analyze_Enumeration_Representation_Clause; |
6022 | ||
6023 | ---------------------------- | |
6024 | -- Analyze_Free_Statement -- | |
6025 | ---------------------------- | |
6026 | ||
6027 | procedure Analyze_Free_Statement (N : Node_Id) is | |
6028 | begin | |
6029 | Analyze (Expression (N)); | |
6030 | end Analyze_Free_Statement; | |
6031 | ||
40ca69b9 | 6032 | --------------------------- |
6033 | -- Analyze_Freeze_Entity -- | |
6034 | --------------------------- | |
6035 | ||
6036 | procedure Analyze_Freeze_Entity (N : Node_Id) is | |
40ca69b9 | 6037 | begin |
d9f6a4ee | 6038 | Freeze_Entity_Checks (N); |
6039 | end Analyze_Freeze_Entity; | |
98f7db28 | 6040 | |
d9f6a4ee | 6041 | ----------------------------------- |
6042 | -- Analyze_Freeze_Generic_Entity -- | |
6043 | ----------------------------------- | |
98f7db28 | 6044 | |
d9f6a4ee | 6045 | procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is |
6046 | begin | |
6047 | Freeze_Entity_Checks (N); | |
6048 | end Analyze_Freeze_Generic_Entity; | |
40ca69b9 | 6049 | |
d9f6a4ee | 6050 | ------------------------------------------ |
6051 | -- Analyze_Record_Representation_Clause -- | |
6052 | ------------------------------------------ | |
c8da6114 | 6053 | |
d9f6a4ee | 6054 | -- Note: we check as much as we can here, but we can't do any checks |
6055 | -- based on the position values (e.g. overlap checks) until freeze time | |
6056 | -- because especially in Ada 2005 (machine scalar mode), the processing | |
6057 | -- for non-standard bit order can substantially change the positions. | |
6058 | -- See procedure Check_Record_Representation_Clause (called from Freeze) | |
6059 | -- for the remainder of this processing. | |
d00681a7 | 6060 | |
d9f6a4ee | 6061 | procedure Analyze_Record_Representation_Clause (N : Node_Id) is |
6062 | Ident : constant Node_Id := Identifier (N); | |
6063 | Biased : Boolean; | |
6064 | CC : Node_Id; | |
6065 | Comp : Entity_Id; | |
6066 | Fbit : Uint; | |
6067 | Hbit : Uint := Uint_0; | |
6068 | Lbit : Uint; | |
6069 | Ocomp : Entity_Id; | |
6070 | Posit : Uint; | |
6071 | Rectype : Entity_Id; | |
6072 | Recdef : Node_Id; | |
d00681a7 | 6073 | |
d9f6a4ee | 6074 | function Is_Inherited (Comp : Entity_Id) return Boolean; |
6075 | -- True if Comp is an inherited component in a record extension | |
d00681a7 | 6076 | |
d9f6a4ee | 6077 | ------------------ |
6078 | -- Is_Inherited -- | |
6079 | ------------------ | |
d00681a7 | 6080 | |
d9f6a4ee | 6081 | function Is_Inherited (Comp : Entity_Id) return Boolean is |
6082 | Comp_Base : Entity_Id; | |
d00681a7 | 6083 | |
d9f6a4ee | 6084 | begin |
6085 | if Ekind (Rectype) = E_Record_Subtype then | |
6086 | Comp_Base := Original_Record_Component (Comp); | |
6087 | else | |
6088 | Comp_Base := Comp; | |
d00681a7 | 6089 | end if; |
6090 | ||
d9f6a4ee | 6091 | return Comp_Base /= Original_Record_Component (Comp_Base); |
6092 | end Is_Inherited; | |
d00681a7 | 6093 | |
d9f6a4ee | 6094 | -- Local variables |
d00681a7 | 6095 | |
d9f6a4ee | 6096 | Is_Record_Extension : Boolean; |
6097 | -- True if Rectype is a record extension | |
d00681a7 | 6098 | |
d9f6a4ee | 6099 | CR_Pragma : Node_Id := Empty; |
6100 | -- Points to N_Pragma node if Complete_Representation pragma present | |
d00681a7 | 6101 | |
d9f6a4ee | 6102 | -- Start of processing for Analyze_Record_Representation_Clause |
d00681a7 | 6103 | |
d9f6a4ee | 6104 | begin |
6105 | if Ignore_Rep_Clauses then | |
2ff55065 | 6106 | Kill_Rep_Clause (N); |
d9f6a4ee | 6107 | return; |
d00681a7 | 6108 | end if; |
98f7db28 | 6109 | |
d9f6a4ee | 6110 | Find_Type (Ident); |
6111 | Rectype := Entity (Ident); | |
85377c9b | 6112 | |
d9f6a4ee | 6113 | if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then |
6114 | return; | |
6115 | else | |
6116 | Rectype := Underlying_Type (Rectype); | |
6117 | end if; | |
85377c9b | 6118 | |
d9f6a4ee | 6119 | -- First some basic error checks |
85377c9b | 6120 | |
d9f6a4ee | 6121 | if not Is_Record_Type (Rectype) then |
6122 | Error_Msg_NE | |
6123 | ("record type required, found}", Ident, First_Subtype (Rectype)); | |
6124 | return; | |
85377c9b | 6125 | |
d9f6a4ee | 6126 | elsif Scope (Rectype) /= Current_Scope then |
6127 | Error_Msg_N ("type must be declared in this scope", N); | |
6128 | return; | |
85377c9b | 6129 | |
d9f6a4ee | 6130 | elsif not Is_First_Subtype (Rectype) then |
6131 | Error_Msg_N ("cannot give record rep clause for subtype", N); | |
6132 | return; | |
9dc88aea | 6133 | |
d9f6a4ee | 6134 | elsif Has_Record_Rep_Clause (Rectype) then |
6135 | Error_Msg_N ("duplicate record rep clause ignored", N); | |
6136 | return; | |
9dc88aea | 6137 | |
d9f6a4ee | 6138 | elsif Rep_Item_Too_Late (Rectype, N) then |
6139 | return; | |
9dc88aea | 6140 | end if; |
fb7f2fc4 | 6141 | |
d9f6a4ee | 6142 | -- We know we have a first subtype, now possibly go the the anonymous |
6143 | -- base type to determine whether Rectype is a record extension. | |
89f1e35c | 6144 | |
d9f6a4ee | 6145 | Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype))); |
6146 | Is_Record_Extension := | |
6147 | Nkind (Recdef) = N_Derived_Type_Definition | |
6148 | and then Present (Record_Extension_Part (Recdef)); | |
89f1e35c | 6149 | |
d9f6a4ee | 6150 | if Present (Mod_Clause (N)) then |
fb7f2fc4 | 6151 | declare |
d9f6a4ee | 6152 | Loc : constant Source_Ptr := Sloc (N); |
6153 | M : constant Node_Id := Mod_Clause (N); | |
6154 | P : constant List_Id := Pragmas_Before (M); | |
6155 | AtM_Nod : Node_Id; | |
6156 | ||
6157 | Mod_Val : Uint; | |
6158 | pragma Warnings (Off, Mod_Val); | |
fb7f2fc4 | 6159 | |
6160 | begin | |
d9f6a4ee | 6161 | Check_Restriction (No_Obsolescent_Features, Mod_Clause (N)); |
fb7f2fc4 | 6162 | |
d9f6a4ee | 6163 | if Warn_On_Obsolescent_Feature then |
6164 | Error_Msg_N | |
6165 | ("?j?mod clause is an obsolescent feature (RM J.8)", N); | |
6166 | Error_Msg_N | |
6167 | ("\?j?use alignment attribute definition clause instead", N); | |
6168 | end if; | |
fb7f2fc4 | 6169 | |
d9f6a4ee | 6170 | if Present (P) then |
6171 | Analyze_List (P); | |
6172 | end if; | |
89f1e35c | 6173 | |
d9f6a4ee | 6174 | -- In ASIS_Mode mode, expansion is disabled, but we must convert |
6175 | -- the Mod clause into an alignment clause anyway, so that the | |
6176 | -- back-end can compute and back-annotate properly the size and | |
6177 | -- alignment of types that may include this record. | |
be9124d0 | 6178 | |
d9f6a4ee | 6179 | -- This seems dubious, this destroys the source tree in a manner |
6180 | -- not detectable by ASIS ??? | |
be9124d0 | 6181 | |
d9f6a4ee | 6182 | if Operating_Mode = Check_Semantics and then ASIS_Mode then |
6183 | AtM_Nod := | |
6184 | Make_Attribute_Definition_Clause (Loc, | |
83c6c069 | 6185 | Name => New_Occurrence_Of (Base_Type (Rectype), Loc), |
d9f6a4ee | 6186 | Chars => Name_Alignment, |
6187 | Expression => Relocate_Node (Expression (M))); | |
be9124d0 | 6188 | |
d9f6a4ee | 6189 | Set_From_At_Mod (AtM_Nod); |
6190 | Insert_After (N, AtM_Nod); | |
6191 | Mod_Val := Get_Alignment_Value (Expression (AtM_Nod)); | |
6192 | Set_Mod_Clause (N, Empty); | |
be9124d0 | 6193 | |
d9f6a4ee | 6194 | else |
6195 | -- Get the alignment value to perform error checking | |
be9124d0 | 6196 | |
d9f6a4ee | 6197 | Mod_Val := Get_Alignment_Value (Expression (M)); |
6198 | end if; | |
6199 | end; | |
6200 | end if; | |
be9124d0 | 6201 | |
d9f6a4ee | 6202 | -- For untagged types, clear any existing component clauses for the |
6203 | -- type. If the type is derived, this is what allows us to override | |
6204 | -- a rep clause for the parent. For type extensions, the representation | |
6205 | -- of the inherited components is inherited, so we want to keep previous | |
6206 | -- component clauses for completeness. | |
be9124d0 | 6207 | |
d9f6a4ee | 6208 | if not Is_Tagged_Type (Rectype) then |
6209 | Comp := First_Component_Or_Discriminant (Rectype); | |
6210 | while Present (Comp) loop | |
6211 | Set_Component_Clause (Comp, Empty); | |
6212 | Next_Component_Or_Discriminant (Comp); | |
6213 | end loop; | |
6214 | end if; | |
be9124d0 | 6215 | |
d9f6a4ee | 6216 | -- All done if no component clauses |
be9124d0 | 6217 | |
d9f6a4ee | 6218 | CC := First (Component_Clauses (N)); |
be9124d0 | 6219 | |
d9f6a4ee | 6220 | if No (CC) then |
6221 | return; | |
6222 | end if; | |
be9124d0 | 6223 | |
d9f6a4ee | 6224 | -- A representation like this applies to the base type |
be9124d0 | 6225 | |
d9f6a4ee | 6226 | Set_Has_Record_Rep_Clause (Base_Type (Rectype)); |
6227 | Set_Has_Non_Standard_Rep (Base_Type (Rectype)); | |
6228 | Set_Has_Specified_Layout (Base_Type (Rectype)); | |
be9124d0 | 6229 | |
d9f6a4ee | 6230 | -- Process the component clauses |
be9124d0 | 6231 | |
d9f6a4ee | 6232 | while Present (CC) loop |
be9124d0 | 6233 | |
d9f6a4ee | 6234 | -- Pragma |
be9124d0 | 6235 | |
d9f6a4ee | 6236 | if Nkind (CC) = N_Pragma then |
6237 | Analyze (CC); | |
be9124d0 | 6238 | |
d9f6a4ee | 6239 | -- The only pragma of interest is Complete_Representation |
be9124d0 | 6240 | |
d9f6a4ee | 6241 | if Pragma_Name (CC) = Name_Complete_Representation then |
6242 | CR_Pragma := CC; | |
6243 | end if; | |
be9124d0 | 6244 | |
d9f6a4ee | 6245 | -- Processing for real component clause |
be9124d0 | 6246 | |
d9f6a4ee | 6247 | else |
6248 | Posit := Static_Integer (Position (CC)); | |
6249 | Fbit := Static_Integer (First_Bit (CC)); | |
6250 | Lbit := Static_Integer (Last_Bit (CC)); | |
be9124d0 | 6251 | |
d9f6a4ee | 6252 | if Posit /= No_Uint |
6253 | and then Fbit /= No_Uint | |
6254 | and then Lbit /= No_Uint | |
6255 | then | |
6256 | if Posit < 0 then | |
6257 | Error_Msg_N | |
6258 | ("position cannot be negative", Position (CC)); | |
be9124d0 | 6259 | |
d9f6a4ee | 6260 | elsif Fbit < 0 then |
6261 | Error_Msg_N | |
6262 | ("first bit cannot be negative", First_Bit (CC)); | |
be9124d0 | 6263 | |
d9f6a4ee | 6264 | -- The Last_Bit specified in a component clause must not be |
6265 | -- less than the First_Bit minus one (RM-13.5.1(10)). | |
be9124d0 | 6266 | |
d9f6a4ee | 6267 | elsif Lbit < Fbit - 1 then |
6268 | Error_Msg_N | |
6269 | ("last bit cannot be less than first bit minus one", | |
6270 | Last_Bit (CC)); | |
be9124d0 | 6271 | |
d9f6a4ee | 6272 | -- Values look OK, so find the corresponding record component |
6273 | -- Even though the syntax allows an attribute reference for | |
6274 | -- implementation-defined components, GNAT does not allow the | |
6275 | -- tag to get an explicit position. | |
be9124d0 | 6276 | |
d9f6a4ee | 6277 | elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then |
6278 | if Attribute_Name (Component_Name (CC)) = Name_Tag then | |
6279 | Error_Msg_N ("position of tag cannot be specified", CC); | |
6280 | else | |
6281 | Error_Msg_N ("illegal component name", CC); | |
6282 | end if; | |
be9124d0 | 6283 | |
d9f6a4ee | 6284 | else |
6285 | Comp := First_Entity (Rectype); | |
6286 | while Present (Comp) loop | |
6287 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
6288 | Next_Entity (Comp); | |
6289 | end loop; | |
be9124d0 | 6290 | |
d9f6a4ee | 6291 | if No (Comp) then |
be9124d0 | 6292 | |
d9f6a4ee | 6293 | -- Maybe component of base type that is absent from |
6294 | -- statically constrained first subtype. | |
be9124d0 | 6295 | |
d9f6a4ee | 6296 | Comp := First_Entity (Base_Type (Rectype)); |
6297 | while Present (Comp) loop | |
6298 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
6299 | Next_Entity (Comp); | |
6300 | end loop; | |
6301 | end if; | |
be9124d0 | 6302 | |
d9f6a4ee | 6303 | if No (Comp) then |
6304 | Error_Msg_N | |
6305 | ("component clause is for non-existent field", CC); | |
be9124d0 | 6306 | |
d9f6a4ee | 6307 | -- Ada 2012 (AI05-0026): Any name that denotes a |
6308 | -- discriminant of an object of an unchecked union type | |
6309 | -- shall not occur within a record_representation_clause. | |
be9124d0 | 6310 | |
d9f6a4ee | 6311 | -- The general restriction of using record rep clauses on |
6312 | -- Unchecked_Union types has now been lifted. Since it is | |
6313 | -- possible to introduce a record rep clause which mentions | |
6314 | -- the discriminant of an Unchecked_Union in non-Ada 2012 | |
6315 | -- code, this check is applied to all versions of the | |
6316 | -- language. | |
be9124d0 | 6317 | |
d9f6a4ee | 6318 | elsif Ekind (Comp) = E_Discriminant |
6319 | and then Is_Unchecked_Union (Rectype) | |
6320 | then | |
6321 | Error_Msg_N | |
6322 | ("cannot reference discriminant of unchecked union", | |
6323 | Component_Name (CC)); | |
be9124d0 | 6324 | |
d9f6a4ee | 6325 | elsif Is_Record_Extension and then Is_Inherited (Comp) then |
6326 | Error_Msg_NE | |
6327 | ("component clause not allowed for inherited " | |
6328 | & "component&", CC, Comp); | |
40ca69b9 | 6329 | |
d9f6a4ee | 6330 | elsif Present (Component_Clause (Comp)) then |
462a079f | 6331 | |
d9f6a4ee | 6332 | -- Diagnose duplicate rep clause, or check consistency |
6333 | -- if this is an inherited component. In a double fault, | |
6334 | -- there may be a duplicate inconsistent clause for an | |
6335 | -- inherited component. | |
462a079f | 6336 | |
d9f6a4ee | 6337 | if Scope (Original_Record_Component (Comp)) = Rectype |
6338 | or else Parent (Component_Clause (Comp)) = N | |
6339 | then | |
6340 | Error_Msg_Sloc := Sloc (Component_Clause (Comp)); | |
6341 | Error_Msg_N ("component clause previously given#", CC); | |
3062c401 | 6342 | |
6343 | else | |
6344 | declare | |
6345 | Rep1 : constant Node_Id := Component_Clause (Comp); | |
3062c401 | 6346 | begin |
6347 | if Intval (Position (Rep1)) /= | |
6348 | Intval (Position (CC)) | |
6349 | or else Intval (First_Bit (Rep1)) /= | |
6350 | Intval (First_Bit (CC)) | |
6351 | or else Intval (Last_Bit (Rep1)) /= | |
6352 | Intval (Last_Bit (CC)) | |
6353 | then | |
b9e61b2a | 6354 | Error_Msg_N |
6355 | ("component clause inconsistent " | |
6356 | & "with representation of ancestor", CC); | |
6a06584c | 6357 | |
3062c401 | 6358 | elsif Warn_On_Redundant_Constructs then |
b9e61b2a | 6359 | Error_Msg_N |
6a06584c | 6360 | ("?r?redundant confirming component clause " |
6361 | & "for component!", CC); | |
3062c401 | 6362 | end if; |
6363 | end; | |
6364 | end if; | |
d6f39728 | 6365 | |
d2b860b4 | 6366 | -- Normal case where this is the first component clause we |
6367 | -- have seen for this entity, so set it up properly. | |
6368 | ||
d6f39728 | 6369 | else |
83f8f0a6 | 6370 | -- Make reference for field in record rep clause and set |
6371 | -- appropriate entity field in the field identifier. | |
6372 | ||
6373 | Generate_Reference | |
6374 | (Comp, Component_Name (CC), Set_Ref => False); | |
6375 | Set_Entity (Component_Name (CC), Comp); | |
6376 | ||
2866d595 | 6377 | -- Update Fbit and Lbit to the actual bit number |
d6f39728 | 6378 | |
6379 | Fbit := Fbit + UI_From_Int (SSU) * Posit; | |
6380 | Lbit := Lbit + UI_From_Int (SSU) * Posit; | |
6381 | ||
d6f39728 | 6382 | if Has_Size_Clause (Rectype) |
ada34def | 6383 | and then RM_Size (Rectype) <= Lbit |
d6f39728 | 6384 | then |
6385 | Error_Msg_N | |
6386 | ("bit number out of range of specified size", | |
6387 | Last_Bit (CC)); | |
6388 | else | |
6389 | Set_Component_Clause (Comp, CC); | |
6390 | Set_Component_Bit_Offset (Comp, Fbit); | |
6391 | Set_Esize (Comp, 1 + (Lbit - Fbit)); | |
6392 | Set_Normalized_First_Bit (Comp, Fbit mod SSU); | |
6393 | Set_Normalized_Position (Comp, Fbit / SSU); | |
6394 | ||
a0fc8c5b | 6395 | if Warn_On_Overridden_Size |
6396 | and then Has_Size_Clause (Etype (Comp)) | |
6397 | and then RM_Size (Etype (Comp)) /= Esize (Comp) | |
6398 | then | |
6399 | Error_Msg_NE | |
1e3532e7 | 6400 | ("?S?component size overrides size clause for&", |
a0fc8c5b | 6401 | Component_Name (CC), Etype (Comp)); |
6402 | end if; | |
6403 | ||
ea61a7ea | 6404 | -- This information is also set in the corresponding |
6405 | -- component of the base type, found by accessing the | |
6406 | -- Original_Record_Component link if it is present. | |
d6f39728 | 6407 | |
6408 | Ocomp := Original_Record_Component (Comp); | |
6409 | ||
6410 | if Hbit < Lbit then | |
6411 | Hbit := Lbit; | |
6412 | end if; | |
6413 | ||
6414 | Check_Size | |
6415 | (Component_Name (CC), | |
6416 | Etype (Comp), | |
6417 | Esize (Comp), | |
6418 | Biased); | |
6419 | ||
b77e4501 | 6420 | Set_Biased |
6421 | (Comp, First_Node (CC), "component clause", Biased); | |
cc46ff4b | 6422 | |
d6f39728 | 6423 | if Present (Ocomp) then |
6424 | Set_Component_Clause (Ocomp, CC); | |
6425 | Set_Component_Bit_Offset (Ocomp, Fbit); | |
6426 | Set_Normalized_First_Bit (Ocomp, Fbit mod SSU); | |
6427 | Set_Normalized_Position (Ocomp, Fbit / SSU); | |
6428 | Set_Esize (Ocomp, 1 + (Lbit - Fbit)); | |
6429 | ||
6430 | Set_Normalized_Position_Max | |
6431 | (Ocomp, Normalized_Position (Ocomp)); | |
6432 | ||
b77e4501 | 6433 | -- Note: we don't use Set_Biased here, because we |
6434 | -- already gave a warning above if needed, and we | |
6435 | -- would get a duplicate for the same name here. | |
6436 | ||
d6f39728 | 6437 | Set_Has_Biased_Representation |
6438 | (Ocomp, Has_Biased_Representation (Comp)); | |
6439 | end if; | |
6440 | ||
6441 | if Esize (Comp) < 0 then | |
6442 | Error_Msg_N ("component size is negative", CC); | |
6443 | end if; | |
6444 | end if; | |
6445 | end if; | |
6446 | end if; | |
6447 | end if; | |
6448 | end if; | |
6449 | ||
6450 | Next (CC); | |
6451 | end loop; | |
6452 | ||
67278d60 | 6453 | -- Check missing components if Complete_Representation pragma appeared |
d6f39728 | 6454 | |
67278d60 | 6455 | if Present (CR_Pragma) then |
6456 | Comp := First_Component_Or_Discriminant (Rectype); | |
6457 | while Present (Comp) loop | |
6458 | if No (Component_Clause (Comp)) then | |
6459 | Error_Msg_NE | |
6460 | ("missing component clause for &", CR_Pragma, Comp); | |
6461 | end if; | |
d6f39728 | 6462 | |
67278d60 | 6463 | Next_Component_Or_Discriminant (Comp); |
6464 | end loop; | |
d6f39728 | 6465 | |
1e3532e7 | 6466 | -- Give missing components warning if required |
15ebb600 | 6467 | |
fdd294d1 | 6468 | elsif Warn_On_Unrepped_Components then |
15ebb600 | 6469 | declare |
6470 | Num_Repped_Components : Nat := 0; | |
6471 | Num_Unrepped_Components : Nat := 0; | |
6472 | ||
6473 | begin | |
6474 | -- First count number of repped and unrepped components | |
6475 | ||
6476 | Comp := First_Component_Or_Discriminant (Rectype); | |
6477 | while Present (Comp) loop | |
6478 | if Present (Component_Clause (Comp)) then | |
6479 | Num_Repped_Components := Num_Repped_Components + 1; | |
6480 | else | |
6481 | Num_Unrepped_Components := Num_Unrepped_Components + 1; | |
6482 | end if; | |
6483 | ||
6484 | Next_Component_Or_Discriminant (Comp); | |
6485 | end loop; | |
6486 | ||
6487 | -- We are only interested in the case where there is at least one | |
6488 | -- unrepped component, and at least half the components have rep | |
6489 | -- clauses. We figure that if less than half have them, then the | |
87f9eef5 | 6490 | -- partial rep clause is really intentional. If the component |
6491 | -- type has no underlying type set at this point (as for a generic | |
6492 | -- formal type), we don't know enough to give a warning on the | |
6493 | -- component. | |
15ebb600 | 6494 | |
6495 | if Num_Unrepped_Components > 0 | |
6496 | and then Num_Unrepped_Components < Num_Repped_Components | |
6497 | then | |
6498 | Comp := First_Component_Or_Discriminant (Rectype); | |
6499 | while Present (Comp) loop | |
83f8f0a6 | 6500 | if No (Component_Clause (Comp)) |
3062c401 | 6501 | and then Comes_From_Source (Comp) |
87f9eef5 | 6502 | and then Present (Underlying_Type (Etype (Comp))) |
83f8f0a6 | 6503 | and then (Is_Scalar_Type (Underlying_Type (Etype (Comp))) |
67278d60 | 6504 | or else Size_Known_At_Compile_Time |
6505 | (Underlying_Type (Etype (Comp)))) | |
fdd294d1 | 6506 | and then not Has_Warnings_Off (Rectype) |
83f8f0a6 | 6507 | then |
15ebb600 | 6508 | Error_Msg_Sloc := Sloc (Comp); |
6509 | Error_Msg_NE | |
1e3532e7 | 6510 | ("?C?no component clause given for & declared #", |
15ebb600 | 6511 | N, Comp); |
6512 | end if; | |
6513 | ||
6514 | Next_Component_Or_Discriminant (Comp); | |
6515 | end loop; | |
6516 | end if; | |
6517 | end; | |
d6f39728 | 6518 | end if; |
d6f39728 | 6519 | end Analyze_Record_Representation_Clause; |
6520 | ||
eb66e842 | 6521 | ------------------------------------- |
6522 | -- Build_Discrete_Static_Predicate -- | |
6523 | ------------------------------------- | |
9ea61fdd | 6524 | |
eb66e842 | 6525 | procedure Build_Discrete_Static_Predicate |
6526 | (Typ : Entity_Id; | |
6527 | Expr : Node_Id; | |
6528 | Nam : Name_Id) | |
9ea61fdd | 6529 | is |
eb66e842 | 6530 | Loc : constant Source_Ptr := Sloc (Expr); |
9ea61fdd | 6531 | |
eb66e842 | 6532 | Non_Static : exception; |
6533 | -- Raised if something non-static is found | |
9ea61fdd | 6534 | |
eb66e842 | 6535 | Btyp : constant Entity_Id := Base_Type (Typ); |
9ea61fdd | 6536 | |
eb66e842 | 6537 | BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp)); |
6538 | BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp)); | |
6539 | -- Low bound and high bound value of base type of Typ | |
9ea61fdd | 6540 | |
eb66e842 | 6541 | TLo : constant Uint := Expr_Value (Type_Low_Bound (Typ)); |
6542 | THi : constant Uint := Expr_Value (Type_High_Bound (Typ)); | |
6543 | -- Low bound and high bound values of static subtype Typ | |
9ea61fdd | 6544 | |
eb66e842 | 6545 | type REnt is record |
6546 | Lo, Hi : Uint; | |
6547 | end record; | |
6548 | -- One entry in a Rlist value, a single REnt (range entry) value denotes | |
6549 | -- one range from Lo to Hi. To represent a single value range Lo = Hi = | |
6550 | -- value. | |
9ea61fdd | 6551 | |
eb66e842 | 6552 | type RList is array (Nat range <>) of REnt; |
6553 | -- A list of ranges. The ranges are sorted in increasing order, and are | |
6554 | -- disjoint (there is a gap of at least one value between each range in | |
6555 | -- the table). A value is in the set of ranges in Rlist if it lies | |
6556 | -- within one of these ranges. | |
9ea61fdd | 6557 | |
eb66e842 | 6558 | False_Range : constant RList := |
6559 | RList'(1 .. 0 => REnt'(No_Uint, No_Uint)); | |
6560 | -- An empty set of ranges represents a range list that can never be | |
6561 | -- satisfied, since there are no ranges in which the value could lie, | |
6562 | -- so it does not lie in any of them. False_Range is a canonical value | |
6563 | -- for this empty set, but general processing should test for an Rlist | |
6564 | -- with length zero (see Is_False predicate), since other null ranges | |
6565 | -- may appear which must be treated as False. | |
5b5df4a9 | 6566 | |
eb66e842 | 6567 | True_Range : constant RList := RList'(1 => REnt'(BLo, BHi)); |
6568 | -- Range representing True, value must be in the base range | |
5b5df4a9 | 6569 | |
eb66e842 | 6570 | function "and" (Left : RList; Right : RList) return RList; |
6571 | -- And's together two range lists, returning a range list. This is a set | |
6572 | -- intersection operation. | |
5b5df4a9 | 6573 | |
eb66e842 | 6574 | function "or" (Left : RList; Right : RList) return RList; |
6575 | -- Or's together two range lists, returning a range list. This is a set | |
6576 | -- union operation. | |
87f3d5d3 | 6577 | |
eb66e842 | 6578 | function "not" (Right : RList) return RList; |
6579 | -- Returns complement of a given range list, i.e. a range list | |
6580 | -- representing all the values in TLo .. THi that are not in the input | |
6581 | -- operand Right. | |
ed4adc99 | 6582 | |
eb66e842 | 6583 | function Build_Val (V : Uint) return Node_Id; |
6584 | -- Return an analyzed N_Identifier node referencing this value, suitable | |
5c6a5792 | 6585 | -- for use as an entry in the Static_Discrte_Predicate list. This node |
6586 | -- is typed with the base type. | |
5b5df4a9 | 6587 | |
eb66e842 | 6588 | function Build_Range (Lo : Uint; Hi : Uint) return Node_Id; |
6589 | -- Return an analyzed N_Range node referencing this range, suitable for | |
5c6a5792 | 6590 | -- use as an entry in the Static_Discrete_Predicate list. This node is |
6591 | -- typed with the base type. | |
5b5df4a9 | 6592 | |
eb66e842 | 6593 | function Get_RList (Exp : Node_Id) return RList; |
6594 | -- This is a recursive routine that converts the given expression into a | |
6595 | -- list of ranges, suitable for use in building the static predicate. | |
5b5df4a9 | 6596 | |
eb66e842 | 6597 | function Is_False (R : RList) return Boolean; |
6598 | pragma Inline (Is_False); | |
6599 | -- Returns True if the given range list is empty, and thus represents a | |
6600 | -- False list of ranges that can never be satisfied. | |
87f3d5d3 | 6601 | |
eb66e842 | 6602 | function Is_True (R : RList) return Boolean; |
6603 | -- Returns True if R trivially represents the True predicate by having a | |
6604 | -- single range from BLo to BHi. | |
5b5df4a9 | 6605 | |
eb66e842 | 6606 | function Is_Type_Ref (N : Node_Id) return Boolean; |
6607 | pragma Inline (Is_Type_Ref); | |
6608 | -- Returns if True if N is a reference to the type for the predicate in | |
6609 | -- the expression (i.e. if it is an identifier whose Chars field matches | |
7de4cba3 | 6610 | -- the Nam given in the call). N must not be parenthesized, if the type |
6611 | -- name appears in parens, this routine will return False. | |
5b5df4a9 | 6612 | |
eb66e842 | 6613 | function Lo_Val (N : Node_Id) return Uint; |
5c6a5792 | 6614 | -- Given an entry from a Static_Discrete_Predicate list that is either |
6615 | -- a static expression or static range, gets either the expression value | |
6616 | -- or the low bound of the range. | |
5b5df4a9 | 6617 | |
eb66e842 | 6618 | function Hi_Val (N : Node_Id) return Uint; |
5c6a5792 | 6619 | -- Given an entry from a Static_Discrete_Predicate list that is either |
6620 | -- a static expression or static range, gets either the expression value | |
6621 | -- or the high bound of the range. | |
5b5df4a9 | 6622 | |
eb66e842 | 6623 | function Membership_Entry (N : Node_Id) return RList; |
6624 | -- Given a single membership entry (range, value, or subtype), returns | |
6625 | -- the corresponding range list. Raises Static_Error if not static. | |
5b5df4a9 | 6626 | |
eb66e842 | 6627 | function Membership_Entries (N : Node_Id) return RList; |
6628 | -- Given an element on an alternatives list of a membership operation, | |
6629 | -- returns the range list corresponding to this entry and all following | |
6630 | -- entries (i.e. returns the "or" of this list of values). | |
b9e61b2a | 6631 | |
eb66e842 | 6632 | function Stat_Pred (Typ : Entity_Id) return RList; |
6633 | -- Given a type, if it has a static predicate, then return the predicate | |
6634 | -- as a range list, otherwise raise Non_Static. | |
c4968aa2 | 6635 | |
eb66e842 | 6636 | ----------- |
6637 | -- "and" -- | |
6638 | ----------- | |
c4968aa2 | 6639 | |
eb66e842 | 6640 | function "and" (Left : RList; Right : RList) return RList is |
6641 | FEnt : REnt; | |
6642 | -- First range of result | |
c4968aa2 | 6643 | |
eb66e842 | 6644 | SLeft : Nat := Left'First; |
6645 | -- Start of rest of left entries | |
c4968aa2 | 6646 | |
eb66e842 | 6647 | SRight : Nat := Right'First; |
6648 | -- Start of rest of right entries | |
2072eaa9 | 6649 | |
eb66e842 | 6650 | begin |
6651 | -- If either range is True, return the other | |
5b5df4a9 | 6652 | |
eb66e842 | 6653 | if Is_True (Left) then |
6654 | return Right; | |
6655 | elsif Is_True (Right) then | |
6656 | return Left; | |
6657 | end if; | |
87f3d5d3 | 6658 | |
eb66e842 | 6659 | -- If either range is False, return False |
5b5df4a9 | 6660 | |
eb66e842 | 6661 | if Is_False (Left) or else Is_False (Right) then |
6662 | return False_Range; | |
6663 | end if; | |
4c1fd062 | 6664 | |
eb66e842 | 6665 | -- Loop to remove entries at start that are disjoint, and thus just |
6666 | -- get discarded from the result entirely. | |
5b5df4a9 | 6667 | |
eb66e842 | 6668 | loop |
6669 | -- If no operands left in either operand, result is false | |
5b5df4a9 | 6670 | |
eb66e842 | 6671 | if SLeft > Left'Last or else SRight > Right'Last then |
6672 | return False_Range; | |
5b5df4a9 | 6673 | |
eb66e842 | 6674 | -- Discard first left operand entry if disjoint with right |
5b5df4a9 | 6675 | |
eb66e842 | 6676 | elsif Left (SLeft).Hi < Right (SRight).Lo then |
6677 | SLeft := SLeft + 1; | |
5b5df4a9 | 6678 | |
eb66e842 | 6679 | -- Discard first right operand entry if disjoint with left |
5b5df4a9 | 6680 | |
eb66e842 | 6681 | elsif Right (SRight).Hi < Left (SLeft).Lo then |
6682 | SRight := SRight + 1; | |
5b5df4a9 | 6683 | |
eb66e842 | 6684 | -- Otherwise we have an overlapping entry |
5b5df4a9 | 6685 | |
eb66e842 | 6686 | else |
6687 | exit; | |
6688 | end if; | |
6689 | end loop; | |
5b5df4a9 | 6690 | |
eb66e842 | 6691 | -- Now we have two non-null operands, and first entries overlap. The |
6692 | -- first entry in the result will be the overlapping part of these | |
6693 | -- two entries. | |
47a46747 | 6694 | |
eb66e842 | 6695 | FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo), |
6696 | Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi)); | |
47a46747 | 6697 | |
eb66e842 | 6698 | -- Now we can remove the entry that ended at a lower value, since its |
6699 | -- contribution is entirely contained in Fent. | |
5b5df4a9 | 6700 | |
eb66e842 | 6701 | if Left (SLeft).Hi <= Right (SRight).Hi then |
6702 | SLeft := SLeft + 1; | |
6703 | else | |
6704 | SRight := SRight + 1; | |
6705 | end if; | |
5b5df4a9 | 6706 | |
eb66e842 | 6707 | -- Compute result by concatenating this first entry with the "and" of |
6708 | -- the remaining parts of the left and right operands. Note that if | |
6709 | -- either of these is empty, "and" will yield empty, so that we will | |
6710 | -- end up with just Fent, which is what we want in that case. | |
5b5df4a9 | 6711 | |
eb66e842 | 6712 | return |
6713 | FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last)); | |
6714 | end "and"; | |
fb7f2fc4 | 6715 | |
eb66e842 | 6716 | ----------- |
6717 | -- "not" -- | |
6718 | ----------- | |
fb7f2fc4 | 6719 | |
eb66e842 | 6720 | function "not" (Right : RList) return RList is |
6721 | begin | |
6722 | -- Return True if False range | |
fb7f2fc4 | 6723 | |
eb66e842 | 6724 | if Is_False (Right) then |
6725 | return True_Range; | |
6726 | end if; | |
ed4adc99 | 6727 | |
eb66e842 | 6728 | -- Return False if True range |
fb7f2fc4 | 6729 | |
eb66e842 | 6730 | if Is_True (Right) then |
6731 | return False_Range; | |
6732 | end if; | |
fb7f2fc4 | 6733 | |
eb66e842 | 6734 | -- Here if not trivial case |
87f3d5d3 | 6735 | |
eb66e842 | 6736 | declare |
6737 | Result : RList (1 .. Right'Length + 1); | |
6738 | -- May need one more entry for gap at beginning and end | |
87f3d5d3 | 6739 | |
eb66e842 | 6740 | Count : Nat := 0; |
6741 | -- Number of entries stored in Result | |
4098232e | 6742 | |
eb66e842 | 6743 | begin |
6744 | -- Gap at start | |
4098232e | 6745 | |
eb66e842 | 6746 | if Right (Right'First).Lo > TLo then |
6747 | Count := Count + 1; | |
6748 | Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1); | |
6749 | end if; | |
ed4adc99 | 6750 | |
eb66e842 | 6751 | -- Gaps between ranges |
ed4adc99 | 6752 | |
eb66e842 | 6753 | for J in Right'First .. Right'Last - 1 loop |
6754 | Count := Count + 1; | |
6755 | Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1); | |
6756 | end loop; | |
5b5df4a9 | 6757 | |
eb66e842 | 6758 | -- Gap at end |
5b5df4a9 | 6759 | |
eb66e842 | 6760 | if Right (Right'Last).Hi < THi then |
6761 | Count := Count + 1; | |
6762 | Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi); | |
6763 | end if; | |
5b5df4a9 | 6764 | |
eb66e842 | 6765 | return Result (1 .. Count); |
6766 | end; | |
6767 | end "not"; | |
5b5df4a9 | 6768 | |
eb66e842 | 6769 | ---------- |
6770 | -- "or" -- | |
6771 | ---------- | |
5b5df4a9 | 6772 | |
eb66e842 | 6773 | function "or" (Left : RList; Right : RList) return RList is |
6774 | FEnt : REnt; | |
6775 | -- First range of result | |
5b5df4a9 | 6776 | |
eb66e842 | 6777 | SLeft : Nat := Left'First; |
6778 | -- Start of rest of left entries | |
5b5df4a9 | 6779 | |
eb66e842 | 6780 | SRight : Nat := Right'First; |
6781 | -- Start of rest of right entries | |
5b5df4a9 | 6782 | |
eb66e842 | 6783 | begin |
6784 | -- If either range is True, return True | |
5b5df4a9 | 6785 | |
eb66e842 | 6786 | if Is_True (Left) or else Is_True (Right) then |
6787 | return True_Range; | |
6788 | end if; | |
5b5df4a9 | 6789 | |
eb66e842 | 6790 | -- If either range is False (empty), return the other |
5b5df4a9 | 6791 | |
eb66e842 | 6792 | if Is_False (Left) then |
6793 | return Right; | |
6794 | elsif Is_False (Right) then | |
6795 | return Left; | |
6796 | end if; | |
5b5df4a9 | 6797 | |
eb66e842 | 6798 | -- Initialize result first entry from left or right operand depending |
6799 | -- on which starts with the lower range. | |
5b5df4a9 | 6800 | |
eb66e842 | 6801 | if Left (SLeft).Lo < Right (SRight).Lo then |
6802 | FEnt := Left (SLeft); | |
6803 | SLeft := SLeft + 1; | |
6804 | else | |
6805 | FEnt := Right (SRight); | |
6806 | SRight := SRight + 1; | |
6807 | end if; | |
5b5df4a9 | 6808 | |
eb66e842 | 6809 | -- This loop eats ranges from left and right operands that are |
6810 | -- contiguous with the first range we are gathering. | |
9ea61fdd | 6811 | |
eb66e842 | 6812 | loop |
6813 | -- Eat first entry in left operand if contiguous or overlapped by | |
6814 | -- gathered first operand of result. | |
9ea61fdd | 6815 | |
eb66e842 | 6816 | if SLeft <= Left'Last |
6817 | and then Left (SLeft).Lo <= FEnt.Hi + 1 | |
6818 | then | |
6819 | FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi); | |
6820 | SLeft := SLeft + 1; | |
9ea61fdd | 6821 | |
eb66e842 | 6822 | -- Eat first entry in right operand if contiguous or overlapped by |
6823 | -- gathered right operand of result. | |
9ea61fdd | 6824 | |
eb66e842 | 6825 | elsif SRight <= Right'Last |
6826 | and then Right (SRight).Lo <= FEnt.Hi + 1 | |
6827 | then | |
6828 | FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi); | |
6829 | SRight := SRight + 1; | |
9ea61fdd | 6830 | |
eb66e842 | 6831 | -- All done if no more entries to eat |
5b5df4a9 | 6832 | |
eb66e842 | 6833 | else |
6834 | exit; | |
6835 | end if; | |
6836 | end loop; | |
5b5df4a9 | 6837 | |
eb66e842 | 6838 | -- Obtain result as the first entry we just computed, concatenated |
6839 | -- to the "or" of the remaining results (if one operand is empty, | |
6840 | -- this will just concatenate with the other | |
5b5df4a9 | 6841 | |
eb66e842 | 6842 | return |
6843 | FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last)); | |
6844 | end "or"; | |
5b5df4a9 | 6845 | |
eb66e842 | 6846 | ----------------- |
6847 | -- Build_Range -- | |
6848 | ----------------- | |
5b5df4a9 | 6849 | |
eb66e842 | 6850 | function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is |
6851 | Result : Node_Id; | |
5b5df4a9 | 6852 | begin |
eb66e842 | 6853 | Result := |
6854 | Make_Range (Loc, | |
6855 | Low_Bound => Build_Val (Lo), | |
6856 | High_Bound => Build_Val (Hi)); | |
6857 | Set_Etype (Result, Btyp); | |
6858 | Set_Analyzed (Result); | |
6859 | return Result; | |
6860 | end Build_Range; | |
5b5df4a9 | 6861 | |
eb66e842 | 6862 | --------------- |
6863 | -- Build_Val -- | |
6864 | --------------- | |
5b5df4a9 | 6865 | |
eb66e842 | 6866 | function Build_Val (V : Uint) return Node_Id is |
6867 | Result : Node_Id; | |
5b5df4a9 | 6868 | |
eb66e842 | 6869 | begin |
6870 | if Is_Enumeration_Type (Typ) then | |
6871 | Result := Get_Enum_Lit_From_Pos (Typ, V, Loc); | |
6872 | else | |
6873 | Result := Make_Integer_Literal (Loc, V); | |
6874 | end if; | |
5b5df4a9 | 6875 | |
eb66e842 | 6876 | Set_Etype (Result, Btyp); |
6877 | Set_Is_Static_Expression (Result); | |
6878 | Set_Analyzed (Result); | |
6879 | return Result; | |
6880 | end Build_Val; | |
87f3d5d3 | 6881 | |
eb66e842 | 6882 | --------------- |
6883 | -- Get_RList -- | |
6884 | --------------- | |
87f3d5d3 | 6885 | |
eb66e842 | 6886 | function Get_RList (Exp : Node_Id) return RList is |
6887 | Op : Node_Kind; | |
6888 | Val : Uint; | |
87f3d5d3 | 6889 | |
eb66e842 | 6890 | begin |
6891 | -- Static expression can only be true or false | |
87f3d5d3 | 6892 | |
eb66e842 | 6893 | if Is_OK_Static_Expression (Exp) then |
6894 | if Expr_Value (Exp) = 0 then | |
6895 | return False_Range; | |
6896 | else | |
6897 | return True_Range; | |
9ea61fdd | 6898 | end if; |
eb66e842 | 6899 | end if; |
87f3d5d3 | 6900 | |
eb66e842 | 6901 | -- Otherwise test node type |
192b8dab | 6902 | |
eb66e842 | 6903 | Op := Nkind (Exp); |
192b8dab | 6904 | |
eb66e842 | 6905 | case Op is |
5d3fb947 | 6906 | |
eb66e842 | 6907 | -- And |
5d3fb947 | 6908 | |
eb66e842 | 6909 | when N_Op_And | N_And_Then => |
6910 | return Get_RList (Left_Opnd (Exp)) | |
6911 | and | |
6912 | Get_RList (Right_Opnd (Exp)); | |
5b5df4a9 | 6913 | |
eb66e842 | 6914 | -- Or |
9dc88aea | 6915 | |
eb66e842 | 6916 | when N_Op_Or | N_Or_Else => |
6917 | return Get_RList (Left_Opnd (Exp)) | |
6918 | or | |
6919 | Get_RList (Right_Opnd (Exp)); | |
7c443ae8 | 6920 | |
eb66e842 | 6921 | -- Not |
9dc88aea | 6922 | |
eb66e842 | 6923 | when N_Op_Not => |
6924 | return not Get_RList (Right_Opnd (Exp)); | |
9dc88aea | 6925 | |
eb66e842 | 6926 | -- Comparisons of type with static value |
84c8f0b8 | 6927 | |
eb66e842 | 6928 | when N_Op_Compare => |
490beba6 | 6929 | |
eb66e842 | 6930 | -- Type is left operand |
9dc88aea | 6931 | |
eb66e842 | 6932 | if Is_Type_Ref (Left_Opnd (Exp)) |
6933 | and then Is_OK_Static_Expression (Right_Opnd (Exp)) | |
6934 | then | |
6935 | Val := Expr_Value (Right_Opnd (Exp)); | |
84c8f0b8 | 6936 | |
eb66e842 | 6937 | -- Typ is right operand |
84c8f0b8 | 6938 | |
eb66e842 | 6939 | elsif Is_Type_Ref (Right_Opnd (Exp)) |
6940 | and then Is_OK_Static_Expression (Left_Opnd (Exp)) | |
6941 | then | |
6942 | Val := Expr_Value (Left_Opnd (Exp)); | |
84c8f0b8 | 6943 | |
eb66e842 | 6944 | -- Invert sense of comparison |
84c8f0b8 | 6945 | |
eb66e842 | 6946 | case Op is |
6947 | when N_Op_Gt => Op := N_Op_Lt; | |
6948 | when N_Op_Lt => Op := N_Op_Gt; | |
6949 | when N_Op_Ge => Op := N_Op_Le; | |
6950 | when N_Op_Le => Op := N_Op_Ge; | |
6951 | when others => null; | |
6952 | end case; | |
84c8f0b8 | 6953 | |
eb66e842 | 6954 | -- Other cases are non-static |
34d045d3 | 6955 | |
eb66e842 | 6956 | else |
6957 | raise Non_Static; | |
6958 | end if; | |
9dc88aea | 6959 | |
eb66e842 | 6960 | -- Construct range according to comparison operation |
9dc88aea | 6961 | |
eb66e842 | 6962 | case Op is |
6963 | when N_Op_Eq => | |
6964 | return RList'(1 => REnt'(Val, Val)); | |
9dc88aea | 6965 | |
eb66e842 | 6966 | when N_Op_Ge => |
6967 | return RList'(1 => REnt'(Val, BHi)); | |
84c8f0b8 | 6968 | |
eb66e842 | 6969 | when N_Op_Gt => |
6970 | return RList'(1 => REnt'(Val + 1, BHi)); | |
84c8f0b8 | 6971 | |
eb66e842 | 6972 | when N_Op_Le => |
6973 | return RList'(1 => REnt'(BLo, Val)); | |
fb7f2fc4 | 6974 | |
eb66e842 | 6975 | when N_Op_Lt => |
6976 | return RList'(1 => REnt'(BLo, Val - 1)); | |
9dc88aea | 6977 | |
eb66e842 | 6978 | when N_Op_Ne => |
6979 | return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi)); | |
9dc88aea | 6980 | |
eb66e842 | 6981 | when others => |
6982 | raise Program_Error; | |
6983 | end case; | |
9dc88aea | 6984 | |
eb66e842 | 6985 | -- Membership (IN) |
9dc88aea | 6986 | |
eb66e842 | 6987 | when N_In => |
6988 | if not Is_Type_Ref (Left_Opnd (Exp)) then | |
6989 | raise Non_Static; | |
6990 | end if; | |
9dc88aea | 6991 | |
eb66e842 | 6992 | if Present (Right_Opnd (Exp)) then |
6993 | return Membership_Entry (Right_Opnd (Exp)); | |
6994 | else | |
6995 | return Membership_Entries (First (Alternatives (Exp))); | |
6996 | end if; | |
9dc88aea | 6997 | |
eb66e842 | 6998 | -- Negative membership (NOT IN) |
9dc88aea | 6999 | |
eb66e842 | 7000 | when N_Not_In => |
7001 | if not Is_Type_Ref (Left_Opnd (Exp)) then | |
7002 | raise Non_Static; | |
7003 | end if; | |
9dc88aea | 7004 | |
eb66e842 | 7005 | if Present (Right_Opnd (Exp)) then |
7006 | return not Membership_Entry (Right_Opnd (Exp)); | |
7007 | else | |
7008 | return not Membership_Entries (First (Alternatives (Exp))); | |
7009 | end if; | |
9dc88aea | 7010 | |
eb66e842 | 7011 | -- Function call, may be call to static predicate |
9dc88aea | 7012 | |
eb66e842 | 7013 | when N_Function_Call => |
7014 | if Is_Entity_Name (Name (Exp)) then | |
7015 | declare | |
7016 | Ent : constant Entity_Id := Entity (Name (Exp)); | |
7017 | begin | |
7018 | if Is_Predicate_Function (Ent) | |
7019 | or else | |
7020 | Is_Predicate_Function_M (Ent) | |
7021 | then | |
7022 | return Stat_Pred (Etype (First_Formal (Ent))); | |
7023 | end if; | |
7024 | end; | |
7025 | end if; | |
9dc88aea | 7026 | |
eb66e842 | 7027 | -- Other function call cases are non-static |
9dc88aea | 7028 | |
eb66e842 | 7029 | raise Non_Static; |
490beba6 | 7030 | |
eb66e842 | 7031 | -- Qualified expression, dig out the expression |
c92e878b | 7032 | |
eb66e842 | 7033 | when N_Qualified_Expression => |
7034 | return Get_RList (Expression (Exp)); | |
4c1fd062 | 7035 | |
eb66e842 | 7036 | when N_Case_Expression => |
7037 | declare | |
7038 | Alt : Node_Id; | |
7039 | Choices : List_Id; | |
7040 | Dep : Node_Id; | |
4c1fd062 | 7041 | |
eb66e842 | 7042 | begin |
7043 | if not Is_Entity_Name (Expression (Expr)) | |
7044 | or else Etype (Expression (Expr)) /= Typ | |
7045 | then | |
7046 | Error_Msg_N | |
7047 | ("expression must denaote subtype", Expression (Expr)); | |
7048 | return False_Range; | |
7049 | end if; | |
9dc88aea | 7050 | |
eb66e842 | 7051 | -- Collect discrete choices in all True alternatives |
9dc88aea | 7052 | |
eb66e842 | 7053 | Choices := New_List; |
7054 | Alt := First (Alternatives (Exp)); | |
7055 | while Present (Alt) loop | |
7056 | Dep := Expression (Alt); | |
34d045d3 | 7057 | |
cda40848 | 7058 | if not Is_OK_Static_Expression (Dep) then |
eb66e842 | 7059 | raise Non_Static; |
ebbab42d | 7060 | |
eb66e842 | 7061 | elsif Is_True (Expr_Value (Dep)) then |
7062 | Append_List_To (Choices, | |
7063 | New_Copy_List (Discrete_Choices (Alt))); | |
7064 | end if; | |
fb7f2fc4 | 7065 | |
eb66e842 | 7066 | Next (Alt); |
7067 | end loop; | |
9dc88aea | 7068 | |
eb66e842 | 7069 | return Membership_Entries (First (Choices)); |
7070 | end; | |
9dc88aea | 7071 | |
eb66e842 | 7072 | -- Expression with actions: if no actions, dig out expression |
9dc88aea | 7073 | |
eb66e842 | 7074 | when N_Expression_With_Actions => |
7075 | if Is_Empty_List (Actions (Exp)) then | |
7076 | return Get_RList (Expression (Exp)); | |
7077 | else | |
7078 | raise Non_Static; | |
7079 | end if; | |
9dc88aea | 7080 | |
eb66e842 | 7081 | -- Xor operator |
490beba6 | 7082 | |
eb66e842 | 7083 | when N_Op_Xor => |
7084 | return (Get_RList (Left_Opnd (Exp)) | |
7085 | and not Get_RList (Right_Opnd (Exp))) | |
7086 | or (Get_RList (Right_Opnd (Exp)) | |
7087 | and not Get_RList (Left_Opnd (Exp))); | |
9dc88aea | 7088 | |
eb66e842 | 7089 | -- Any other node type is non-static |
fb7f2fc4 | 7090 | |
eb66e842 | 7091 | when others => |
7092 | raise Non_Static; | |
7093 | end case; | |
7094 | end Get_RList; | |
fb7f2fc4 | 7095 | |
eb66e842 | 7096 | ------------ |
7097 | -- Hi_Val -- | |
7098 | ------------ | |
fb7f2fc4 | 7099 | |
eb66e842 | 7100 | function Hi_Val (N : Node_Id) return Uint is |
7101 | begin | |
cda40848 | 7102 | if Is_OK_Static_Expression (N) then |
eb66e842 | 7103 | return Expr_Value (N); |
7104 | else | |
7105 | pragma Assert (Nkind (N) = N_Range); | |
7106 | return Expr_Value (High_Bound (N)); | |
7107 | end if; | |
7108 | end Hi_Val; | |
fb7f2fc4 | 7109 | |
eb66e842 | 7110 | -------------- |
7111 | -- Is_False -- | |
7112 | -------------- | |
fb7f2fc4 | 7113 | |
eb66e842 | 7114 | function Is_False (R : RList) return Boolean is |
7115 | begin | |
7116 | return R'Length = 0; | |
7117 | end Is_False; | |
9dc88aea | 7118 | |
eb66e842 | 7119 | ------------- |
7120 | -- Is_True -- | |
7121 | ------------- | |
9dc88aea | 7122 | |
eb66e842 | 7123 | function Is_True (R : RList) return Boolean is |
7124 | begin | |
7125 | return R'Length = 1 | |
7126 | and then R (R'First).Lo = BLo | |
7127 | and then R (R'First).Hi = BHi; | |
7128 | end Is_True; | |
9dc88aea | 7129 | |
eb66e842 | 7130 | ----------------- |
7131 | -- Is_Type_Ref -- | |
7132 | ----------------- | |
9dc88aea | 7133 | |
eb66e842 | 7134 | function Is_Type_Ref (N : Node_Id) return Boolean is |
7135 | begin | |
7de4cba3 | 7136 | return Nkind (N) = N_Identifier |
7137 | and then Chars (N) = Nam | |
7138 | and then Paren_Count (N) = 0; | |
eb66e842 | 7139 | end Is_Type_Ref; |
9dc88aea | 7140 | |
eb66e842 | 7141 | ------------ |
7142 | -- Lo_Val -- | |
7143 | ------------ | |
9dc88aea | 7144 | |
eb66e842 | 7145 | function Lo_Val (N : Node_Id) return Uint is |
84c8f0b8 | 7146 | begin |
cda40848 | 7147 | if Is_OK_Static_Expression (N) then |
eb66e842 | 7148 | return Expr_Value (N); |
84c8f0b8 | 7149 | else |
eb66e842 | 7150 | pragma Assert (Nkind (N) = N_Range); |
7151 | return Expr_Value (Low_Bound (N)); | |
84c8f0b8 | 7152 | end if; |
eb66e842 | 7153 | end Lo_Val; |
d97beb2f | 7154 | |
eb66e842 | 7155 | ------------------------ |
7156 | -- Membership_Entries -- | |
7157 | ------------------------ | |
d97beb2f | 7158 | |
eb66e842 | 7159 | function Membership_Entries (N : Node_Id) return RList is |
84c8f0b8 | 7160 | begin |
eb66e842 | 7161 | if No (Next (N)) then |
7162 | return Membership_Entry (N); | |
84c8f0b8 | 7163 | else |
eb66e842 | 7164 | return Membership_Entry (N) or Membership_Entries (Next (N)); |
84c8f0b8 | 7165 | end if; |
eb66e842 | 7166 | end Membership_Entries; |
84c8f0b8 | 7167 | |
eb66e842 | 7168 | ---------------------- |
7169 | -- Membership_Entry -- | |
7170 | ---------------------- | |
84c8f0b8 | 7171 | |
eb66e842 | 7172 | function Membership_Entry (N : Node_Id) return RList is |
7173 | Val : Uint; | |
7174 | SLo : Uint; | |
7175 | SHi : Uint; | |
d97beb2f | 7176 | |
eb66e842 | 7177 | begin |
7178 | -- Range case | |
d97beb2f | 7179 | |
eb66e842 | 7180 | if Nkind (N) = N_Range then |
cda40848 | 7181 | if not Is_OK_Static_Expression (Low_Bound (N)) |
eb66e842 | 7182 | or else |
cda40848 | 7183 | not Is_OK_Static_Expression (High_Bound (N)) |
eb66e842 | 7184 | then |
7185 | raise Non_Static; | |
7186 | else | |
7187 | SLo := Expr_Value (Low_Bound (N)); | |
7188 | SHi := Expr_Value (High_Bound (N)); | |
7189 | return RList'(1 => REnt'(SLo, SHi)); | |
7190 | end if; | |
84c8f0b8 | 7191 | |
eb66e842 | 7192 | -- Static expression case |
84c8f0b8 | 7193 | |
cda40848 | 7194 | elsif Is_OK_Static_Expression (N) then |
eb66e842 | 7195 | Val := Expr_Value (N); |
7196 | return RList'(1 => REnt'(Val, Val)); | |
d97beb2f | 7197 | |
eb66e842 | 7198 | -- Identifier (other than static expression) case |
d97beb2f | 7199 | |
eb66e842 | 7200 | else pragma Assert (Nkind (N) = N_Identifier); |
d97beb2f | 7201 | |
eb66e842 | 7202 | -- Type case |
d97beb2f | 7203 | |
eb66e842 | 7204 | if Is_Type (Entity (N)) then |
d97beb2f | 7205 | |
eb66e842 | 7206 | -- If type has predicates, process them |
d97beb2f | 7207 | |
eb66e842 | 7208 | if Has_Predicates (Entity (N)) then |
7209 | return Stat_Pred (Entity (N)); | |
d97beb2f | 7210 | |
eb66e842 | 7211 | -- For static subtype without predicates, get range |
9dc88aea | 7212 | |
cda40848 | 7213 | elsif Is_OK_Static_Subtype (Entity (N)) then |
eb66e842 | 7214 | SLo := Expr_Value (Type_Low_Bound (Entity (N))); |
7215 | SHi := Expr_Value (Type_High_Bound (Entity (N))); | |
7216 | return RList'(1 => REnt'(SLo, SHi)); | |
9f269bd8 | 7217 | |
eb66e842 | 7218 | -- Any other type makes us non-static |
9f269bd8 | 7219 | |
eb66e842 | 7220 | else |
7221 | raise Non_Static; | |
7222 | end if; | |
84c8f0b8 | 7223 | |
eb66e842 | 7224 | -- Any other kind of identifier in predicate (e.g. a non-static |
7225 | -- expression value) means this is not a static predicate. | |
84c8f0b8 | 7226 | |
eb66e842 | 7227 | else |
7228 | raise Non_Static; | |
7229 | end if; | |
7230 | end if; | |
7231 | end Membership_Entry; | |
84c8f0b8 | 7232 | |
eb66e842 | 7233 | --------------- |
7234 | -- Stat_Pred -- | |
7235 | --------------- | |
84c8f0b8 | 7236 | |
eb66e842 | 7237 | function Stat_Pred (Typ : Entity_Id) return RList is |
7238 | begin | |
7239 | -- Not static if type does not have static predicates | |
84c8f0b8 | 7240 | |
5c6a5792 | 7241 | if not Has_Static_Predicate (Typ) then |
eb66e842 | 7242 | raise Non_Static; |
7243 | end if; | |
84c8f0b8 | 7244 | |
eb66e842 | 7245 | -- Otherwise we convert the predicate list to a range list |
84c8f0b8 | 7246 | |
eb66e842 | 7247 | declare |
5c6a5792 | 7248 | Spred : constant List_Id := Static_Discrete_Predicate (Typ); |
7249 | Result : RList (1 .. List_Length (Spred)); | |
eb66e842 | 7250 | P : Node_Id; |
84c8f0b8 | 7251 | |
eb66e842 | 7252 | begin |
5c6a5792 | 7253 | P := First (Static_Discrete_Predicate (Typ)); |
eb66e842 | 7254 | for J in Result'Range loop |
7255 | Result (J) := REnt'(Lo_Val (P), Hi_Val (P)); | |
7256 | Next (P); | |
7257 | end loop; | |
84c8f0b8 | 7258 | |
eb66e842 | 7259 | return Result; |
7260 | end; | |
7261 | end Stat_Pred; | |
84c8f0b8 | 7262 | |
eb66e842 | 7263 | -- Start of processing for Build_Discrete_Static_Predicate |
84c8f0b8 | 7264 | |
eb66e842 | 7265 | begin |
7266 | -- Analyze the expression to see if it is a static predicate | |
84c8f0b8 | 7267 | |
eb66e842 | 7268 | declare |
7269 | Ranges : constant RList := Get_RList (Expr); | |
7270 | -- Range list from expression if it is static | |
84c8f0b8 | 7271 | |
eb66e842 | 7272 | Plist : List_Id; |
84c8f0b8 | 7273 | |
eb66e842 | 7274 | begin |
7275 | -- Convert range list into a form for the static predicate. In the | |
7276 | -- Ranges array, we just have raw ranges, these must be converted | |
7277 | -- to properly typed and analyzed static expressions or range nodes. | |
84c8f0b8 | 7278 | |
eb66e842 | 7279 | -- Note: here we limit ranges to the ranges of the subtype, so that |
7280 | -- a predicate is always false for values outside the subtype. That | |
7281 | -- seems fine, such values are invalid anyway, and considering them | |
7282 | -- to fail the predicate seems allowed and friendly, and furthermore | |
7283 | -- simplifies processing for case statements and loops. | |
84c8f0b8 | 7284 | |
eb66e842 | 7285 | Plist := New_List; |
7286 | ||
7287 | for J in Ranges'Range loop | |
84c8f0b8 | 7288 | declare |
eb66e842 | 7289 | Lo : Uint := Ranges (J).Lo; |
7290 | Hi : Uint := Ranges (J).Hi; | |
84c8f0b8 | 7291 | |
eb66e842 | 7292 | begin |
7293 | -- Ignore completely out of range entry | |
84c8f0b8 | 7294 | |
eb66e842 | 7295 | if Hi < TLo or else Lo > THi then |
7296 | null; | |
84c8f0b8 | 7297 | |
eb66e842 | 7298 | -- Otherwise process entry |
84c8f0b8 | 7299 | |
eb66e842 | 7300 | else |
7301 | -- Adjust out of range value to subtype range | |
490beba6 | 7302 | |
eb66e842 | 7303 | if Lo < TLo then |
7304 | Lo := TLo; | |
7305 | end if; | |
490beba6 | 7306 | |
eb66e842 | 7307 | if Hi > THi then |
7308 | Hi := THi; | |
7309 | end if; | |
84c8f0b8 | 7310 | |
eb66e842 | 7311 | -- Convert range into required form |
84c8f0b8 | 7312 | |
eb66e842 | 7313 | Append_To (Plist, Build_Range (Lo, Hi)); |
84c8f0b8 | 7314 | end if; |
eb66e842 | 7315 | end; |
7316 | end loop; | |
84c8f0b8 | 7317 | |
eb66e842 | 7318 | -- Processing was successful and all entries were static, so now we |
7319 | -- can store the result as the predicate list. | |
84c8f0b8 | 7320 | |
5c6a5792 | 7321 | Set_Static_Discrete_Predicate (Typ, Plist); |
84c8f0b8 | 7322 | |
eb66e842 | 7323 | -- The processing for static predicates put the expression into |
7324 | -- canonical form as a series of ranges. It also eliminated | |
7325 | -- duplicates and collapsed and combined ranges. We might as well | |
7326 | -- replace the alternatives list of the right operand of the | |
7327 | -- membership test with the static predicate list, which will | |
7328 | -- usually be more efficient. | |
84c8f0b8 | 7329 | |
eb66e842 | 7330 | declare |
7331 | New_Alts : constant List_Id := New_List; | |
7332 | Old_Node : Node_Id; | |
7333 | New_Node : Node_Id; | |
84c8f0b8 | 7334 | |
eb66e842 | 7335 | begin |
7336 | Old_Node := First (Plist); | |
7337 | while Present (Old_Node) loop | |
7338 | New_Node := New_Copy (Old_Node); | |
84c8f0b8 | 7339 | |
eb66e842 | 7340 | if Nkind (New_Node) = N_Range then |
7341 | Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node))); | |
7342 | Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node))); | |
7343 | end if; | |
84c8f0b8 | 7344 | |
eb66e842 | 7345 | Append_To (New_Alts, New_Node); |
7346 | Next (Old_Node); | |
7347 | end loop; | |
84c8f0b8 | 7348 | |
eb66e842 | 7349 | -- If empty list, replace by False |
84c8f0b8 | 7350 | |
eb66e842 | 7351 | if Is_Empty_List (New_Alts) then |
7352 | Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc)); | |
84c8f0b8 | 7353 | |
eb66e842 | 7354 | -- Else replace by set membership test |
84c8f0b8 | 7355 | |
eb66e842 | 7356 | else |
7357 | Rewrite (Expr, | |
7358 | Make_In (Loc, | |
7359 | Left_Opnd => Make_Identifier (Loc, Nam), | |
7360 | Right_Opnd => Empty, | |
7361 | Alternatives => New_Alts)); | |
490beba6 | 7362 | |
eb66e842 | 7363 | -- Resolve new expression in function context |
490beba6 | 7364 | |
eb66e842 | 7365 | Install_Formals (Predicate_Function (Typ)); |
7366 | Push_Scope (Predicate_Function (Typ)); | |
7367 | Analyze_And_Resolve (Expr, Standard_Boolean); | |
7368 | Pop_Scope; | |
7369 | end if; | |
7370 | end; | |
7371 | end; | |
9ab32fe9 | 7372 | |
eb66e842 | 7373 | -- If non-static, return doing nothing |
9ab32fe9 | 7374 | |
eb66e842 | 7375 | exception |
7376 | when Non_Static => | |
7377 | return; | |
7378 | end Build_Discrete_Static_Predicate; | |
64cc9e5d | 7379 | |
eb66e842 | 7380 | ------------------------------------------- |
7381 | -- Build_Invariant_Procedure_Declaration -- | |
7382 | ------------------------------------------- | |
9ab32fe9 | 7383 | |
eb66e842 | 7384 | function Build_Invariant_Procedure_Declaration |
7385 | (Typ : Entity_Id) return Node_Id | |
7386 | is | |
7387 | Loc : constant Source_Ptr := Sloc (Typ); | |
7388 | Object_Entity : constant Entity_Id := | |
7389 | Make_Defining_Identifier (Loc, New_Internal_Name ('I')); | |
7390 | Spec : Node_Id; | |
7391 | SId : Entity_Id; | |
9ab32fe9 | 7392 | |
eb66e842 | 7393 | begin |
7394 | Set_Etype (Object_Entity, Typ); | |
7395 | ||
7396 | -- Check for duplicate definiations. | |
7397 | ||
7398 | if Has_Invariants (Typ) and then Present (Invariant_Procedure (Typ)) then | |
7399 | return Empty; | |
d97beb2f | 7400 | end if; |
d97beb2f | 7401 | |
eb66e842 | 7402 | SId := |
7403 | Make_Defining_Identifier (Loc, | |
7404 | Chars => New_External_Name (Chars (Typ), "Invariant")); | |
7405 | Set_Has_Invariants (Typ); | |
7406 | Set_Ekind (SId, E_Procedure); | |
856a9917 | 7407 | Set_Etype (SId, Standard_Void_Type); |
eb66e842 | 7408 | Set_Is_Invariant_Procedure (SId); |
7409 | Set_Invariant_Procedure (Typ, SId); | |
d97beb2f | 7410 | |
eb66e842 | 7411 | Spec := |
7412 | Make_Procedure_Specification (Loc, | |
7413 | Defining_Unit_Name => SId, | |
7414 | Parameter_Specifications => New_List ( | |
7415 | Make_Parameter_Specification (Loc, | |
7416 | Defining_Identifier => Object_Entity, | |
7417 | Parameter_Type => New_Occurrence_Of (Typ, Loc)))); | |
d97beb2f | 7418 | |
eb66e842 | 7419 | return Make_Subprogram_Declaration (Loc, Specification => Spec); |
7420 | end Build_Invariant_Procedure_Declaration; | |
7421 | ||
7422 | ------------------------------- | |
7423 | -- Build_Invariant_Procedure -- | |
7424 | ------------------------------- | |
7425 | ||
7426 | -- The procedure that is constructed here has the form | |
7427 | ||
7428 | -- procedure typInvariant (Ixxx : typ) is | |
7429 | -- begin | |
7430 | -- pragma Check (Invariant, exp, "failed invariant from xxx"); | |
7431 | -- pragma Check (Invariant, exp, "failed invariant from xxx"); | |
7432 | -- ... | |
7433 | -- pragma Check (Invariant, exp, "failed inherited invariant from xxx"); | |
7434 | -- ... | |
7435 | -- end typInvariant; | |
7436 | ||
7437 | procedure Build_Invariant_Procedure (Typ : Entity_Id; N : Node_Id) is | |
7438 | Loc : constant Source_Ptr := Sloc (Typ); | |
7439 | Stmts : List_Id; | |
7440 | Spec : Node_Id; | |
7441 | SId : Entity_Id; | |
7442 | PDecl : Node_Id; | |
7443 | PBody : Node_Id; | |
d97beb2f | 7444 | |
eb66e842 | 7445 | Nam : Name_Id; |
7446 | -- Name for Check pragma, usually Invariant, but might be Type_Invariant | |
7447 | -- if we come from a Type_Invariant aspect, we make sure to build the | |
7448 | -- Check pragma with the right name, so that Check_Policy works right. | |
d7c2851f | 7449 | |
eb66e842 | 7450 | Visible_Decls : constant List_Id := Visible_Declarations (N); |
7451 | Private_Decls : constant List_Id := Private_Declarations (N); | |
d7c2851f | 7452 | |
eb66e842 | 7453 | procedure Add_Invariants (T : Entity_Id; Inherit : Boolean); |
7454 | -- Appends statements to Stmts for any invariants in the rep item chain | |
7455 | -- of the given type. If Inherit is False, then we only process entries | |
7456 | -- on the chain for the type Typ. If Inherit is True, then we ignore any | |
7457 | -- Invariant aspects, but we process all Invariant'Class aspects, adding | |
7458 | -- "inherited" to the exception message and generating an informational | |
7459 | -- message about the inheritance of an invariant. | |
d97beb2f | 7460 | |
eb66e842 | 7461 | Object_Name : Name_Id; |
7462 | -- Name for argument of invariant procedure | |
d97beb2f | 7463 | |
eb66e842 | 7464 | Object_Entity : Node_Id; |
7465 | -- The entity of the formal for the procedure | |
d97beb2f | 7466 | |
eb66e842 | 7467 | -------------------- |
7468 | -- Add_Invariants -- | |
7469 | -------------------- | |
d97beb2f | 7470 | |
eb66e842 | 7471 | procedure Add_Invariants (T : Entity_Id; Inherit : Boolean) is |
7472 | Ritem : Node_Id; | |
7473 | Arg1 : Node_Id; | |
7474 | Arg2 : Node_Id; | |
7475 | Arg3 : Node_Id; | |
7476 | Exp : Node_Id; | |
7477 | Loc : Source_Ptr; | |
7478 | Assoc : List_Id; | |
7479 | Str : String_Id; | |
d97beb2f | 7480 | |
eb66e842 | 7481 | procedure Replace_Type_Reference (N : Node_Id); |
7482 | -- Replace a single occurrence N of the subtype name with a reference | |
7483 | -- to the formal of the predicate function. N can be an identifier | |
7484 | -- referencing the subtype, or a selected component, representing an | |
7485 | -- appropriately qualified occurrence of the subtype name. | |
d97beb2f | 7486 | |
eb66e842 | 7487 | procedure Replace_Type_References is |
7488 | new Replace_Type_References_Generic (Replace_Type_Reference); | |
7489 | -- Traverse an expression replacing all occurrences of the subtype | |
7490 | -- name with appropriate references to the object that is the formal | |
7491 | -- parameter of the predicate function. Note that we must ensure | |
7492 | -- that the type and entity information is properly set in the | |
7493 | -- replacement node, since we will do a Preanalyze call of this | |
7494 | -- expression without proper visibility of the procedure argument. | |
d97beb2f | 7495 | |
eb66e842 | 7496 | ---------------------------- |
7497 | -- Replace_Type_Reference -- | |
7498 | ---------------------------- | |
d97beb2f | 7499 | |
eb66e842 | 7500 | -- Note: See comments in Add_Predicates.Replace_Type_Reference |
7501 | -- regarding handling of Sloc and Comes_From_Source. | |
d97beb2f | 7502 | |
eb66e842 | 7503 | procedure Replace_Type_Reference (N : Node_Id) is |
7504 | begin | |
d97beb2f | 7505 | |
eb66e842 | 7506 | -- Add semantic information to node to be rewritten, for ASIS |
7507 | -- navigation needs. | |
d97beb2f | 7508 | |
eb66e842 | 7509 | if Nkind (N) = N_Identifier then |
7510 | Set_Entity (N, T); | |
7511 | Set_Etype (N, T); | |
d7c2851f | 7512 | |
eb66e842 | 7513 | elsif Nkind (N) = N_Selected_Component then |
7514 | Analyze (Prefix (N)); | |
7515 | Set_Entity (Selector_Name (N), T); | |
7516 | Set_Etype (Selector_Name (N), T); | |
7517 | end if; | |
d7c2851f | 7518 | |
eb66e842 | 7519 | -- Invariant'Class, replace with T'Class (obj) |
69004fe6 | 7520 | -- In ASIS mode, an inherited item is analyzed already, and the |
7521 | -- replacement has been done, so do not repeat transformation | |
7522 | -- to prevent ill-formed tree. | |
d97beb2f | 7523 | |
eb66e842 | 7524 | if Class_Present (Ritem) then |
69004fe6 | 7525 | if ASIS_Mode |
7526 | and then Nkind (Parent (N)) = N_Attribute_Reference | |
7527 | and then Attribute_Name (Parent (N)) = Name_Class | |
7528 | then | |
7529 | null; | |
7530 | ||
7531 | else | |
7532 | Rewrite (N, | |
7533 | Make_Type_Conversion (Sloc (N), | |
7534 | Subtype_Mark => | |
7535 | Make_Attribute_Reference (Sloc (N), | |
7536 | Prefix => New_Occurrence_Of (T, Sloc (N)), | |
7537 | Attribute_Name => Name_Class), | |
7538 | Expression => | |
7539 | Make_Identifier (Sloc (N), Object_Name))); | |
7540 | ||
7541 | Set_Entity (Expression (N), Object_Entity); | |
7542 | Set_Etype (Expression (N), Typ); | |
7543 | end if; | |
d9f6a4ee | 7544 | |
eb66e842 | 7545 | -- Invariant, replace with obj |
d9f6a4ee | 7546 | |
eb66e842 | 7547 | else |
7548 | Rewrite (N, Make_Identifier (Sloc (N), Object_Name)); | |
7549 | Set_Entity (N, Object_Entity); | |
7550 | Set_Etype (N, Typ); | |
7551 | end if; | |
d9f6a4ee | 7552 | |
eb66e842 | 7553 | Set_Comes_From_Source (N, True); |
7554 | end Replace_Type_Reference; | |
d9f6a4ee | 7555 | |
eb66e842 | 7556 | -- Start of processing for Add_Invariants |
d9f6a4ee | 7557 | |
eb66e842 | 7558 | begin |
7559 | Ritem := First_Rep_Item (T); | |
7560 | while Present (Ritem) loop | |
7561 | if Nkind (Ritem) = N_Pragma | |
7562 | and then Pragma_Name (Ritem) = Name_Invariant | |
7563 | then | |
7564 | Arg1 := First (Pragma_Argument_Associations (Ritem)); | |
7565 | Arg2 := Next (Arg1); | |
7566 | Arg3 := Next (Arg2); | |
d9f6a4ee | 7567 | |
eb66e842 | 7568 | Arg1 := Get_Pragma_Arg (Arg1); |
7569 | Arg2 := Get_Pragma_Arg (Arg2); | |
d9f6a4ee | 7570 | |
eb66e842 | 7571 | -- For Inherit case, ignore Invariant, process only Class case |
d9f6a4ee | 7572 | |
eb66e842 | 7573 | if Inherit then |
7574 | if not Class_Present (Ritem) then | |
7575 | goto Continue; | |
7576 | end if; | |
d9f6a4ee | 7577 | |
eb66e842 | 7578 | -- For Inherit false, process only item for right type |
d9f6a4ee | 7579 | |
eb66e842 | 7580 | else |
7581 | if Entity (Arg1) /= Typ then | |
7582 | goto Continue; | |
7583 | end if; | |
7584 | end if; | |
d9f6a4ee | 7585 | |
eb66e842 | 7586 | if No (Stmts) then |
7587 | Stmts := Empty_List; | |
7588 | end if; | |
d9f6a4ee | 7589 | |
eb66e842 | 7590 | Exp := New_Copy_Tree (Arg2); |
d9f6a4ee | 7591 | |
eb66e842 | 7592 | -- Preserve sloc of original pragma Invariant |
d9f6a4ee | 7593 | |
eb66e842 | 7594 | Loc := Sloc (Ritem); |
d9f6a4ee | 7595 | |
eb66e842 | 7596 | -- We need to replace any occurrences of the name of the type |
7597 | -- with references to the object, converted to type'Class in | |
7598 | -- the case of Invariant'Class aspects. | |
d9f6a4ee | 7599 | |
37c6552c | 7600 | Replace_Type_References (Exp, T); |
d9f6a4ee | 7601 | |
eb66e842 | 7602 | -- If this invariant comes from an aspect, find the aspect |
7603 | -- specification, and replace the saved expression because | |
7604 | -- we need the subtype references replaced for the calls to | |
7605 | -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point | |
7606 | -- and Check_Aspect_At_End_Of_Declarations. | |
d9f6a4ee | 7607 | |
eb66e842 | 7608 | if From_Aspect_Specification (Ritem) then |
7609 | declare | |
7610 | Aitem : Node_Id; | |
d9f6a4ee | 7611 | |
eb66e842 | 7612 | begin |
7613 | -- Loop to find corresponding aspect, note that this | |
7614 | -- must be present given the pragma is marked delayed. | |
d9f6a4ee | 7615 | |
eb66e842 | 7616 | -- Note: in practice Next_Rep_Item (Ritem) is Empty so |
7617 | -- this loop does nothing. Furthermore, why isn't this | |
7618 | -- simply Corresponding_Aspect ??? | |
d9f6a4ee | 7619 | |
eb66e842 | 7620 | Aitem := Next_Rep_Item (Ritem); |
7621 | while Present (Aitem) loop | |
7622 | if Nkind (Aitem) = N_Aspect_Specification | |
7623 | and then Aspect_Rep_Item (Aitem) = Ritem | |
7624 | then | |
7625 | Set_Entity | |
7626 | (Identifier (Aitem), New_Copy_Tree (Exp)); | |
7627 | exit; | |
7628 | end if; | |
d9f6a4ee | 7629 | |
eb66e842 | 7630 | Aitem := Next_Rep_Item (Aitem); |
7631 | end loop; | |
7632 | end; | |
7633 | end if; | |
d9f6a4ee | 7634 | |
eb66e842 | 7635 | -- Now we need to preanalyze the expression to properly capture |
7636 | -- the visibility in the visible part. The expression will not | |
7637 | -- be analyzed for real until the body is analyzed, but that is | |
7638 | -- at the end of the private part and has the wrong visibility. | |
d9f6a4ee | 7639 | |
eb66e842 | 7640 | Set_Parent (Exp, N); |
7641 | Preanalyze_Assert_Expression (Exp, Standard_Boolean); | |
d9f6a4ee | 7642 | |
f02a9a9a | 7643 | -- A class-wide invariant may be inherited in a separate unit, |
7644 | -- where the corresponding expression cannot be resolved by | |
7645 | -- visibility, because it refers to a local function. Propagate | |
7646 | -- semantic information to the original representation item, to | |
7647 | -- be used when an invariant procedure for a derived type is | |
7648 | -- constructed. | |
7649 | ||
7650 | -- Unclear how to handle class-wide invariants that are not | |
7651 | -- function calls ??? | |
7652 | ||
7653 | if not Inherit | |
7654 | and then Class_Present (Ritem) | |
7655 | and then Nkind (Exp) = N_Function_Call | |
7656 | and then Nkind (Arg2) = N_Indexed_Component | |
7657 | then | |
7658 | Rewrite (Arg2, | |
7659 | Make_Function_Call (Loc, | |
7660 | Name => | |
7661 | New_Occurrence_Of (Entity (Name (Exp)), Loc), | |
7662 | Parameter_Associations => | |
7663 | New_Copy_List (Expressions (Arg2)))); | |
7664 | end if; | |
7665 | ||
eb66e842 | 7666 | -- In ASIS mode, even if assertions are not enabled, we must |
7667 | -- analyze the original expression in the aspect specification | |
7668 | -- because it is part of the original tree. | |
d9f6a4ee | 7669 | |
eb66e842 | 7670 | if ASIS_Mode and then From_Aspect_Specification (Ritem) then |
7671 | declare | |
7672 | Inv : constant Node_Id := | |
7673 | Expression (Corresponding_Aspect (Ritem)); | |
7674 | begin | |
37c6552c | 7675 | Replace_Type_References (Inv, T); |
eb66e842 | 7676 | Preanalyze_Assert_Expression (Inv, Standard_Boolean); |
7677 | end; | |
7678 | end if; | |
d9f6a4ee | 7679 | |
eb66e842 | 7680 | -- Get name to be used for Check pragma |
d9f6a4ee | 7681 | |
eb66e842 | 7682 | if not From_Aspect_Specification (Ritem) then |
7683 | Nam := Name_Invariant; | |
7684 | else | |
7685 | Nam := Chars (Identifier (Corresponding_Aspect (Ritem))); | |
7686 | end if; | |
d9f6a4ee | 7687 | |
eb66e842 | 7688 | -- Build first two arguments for Check pragma |
d9f6a4ee | 7689 | |
eb66e842 | 7690 | Assoc := |
7691 | New_List ( | |
7692 | Make_Pragma_Argument_Association (Loc, | |
7693 | Expression => Make_Identifier (Loc, Chars => Nam)), | |
7694 | Make_Pragma_Argument_Association (Loc, | |
7695 | Expression => Exp)); | |
d9f6a4ee | 7696 | |
eb66e842 | 7697 | -- Add message if present in Invariant pragma |
d9f6a4ee | 7698 | |
eb66e842 | 7699 | if Present (Arg3) then |
7700 | Str := Strval (Get_Pragma_Arg (Arg3)); | |
d9f6a4ee | 7701 | |
eb66e842 | 7702 | -- If inherited case, and message starts "failed invariant", |
7703 | -- change it to be "failed inherited invariant". | |
d9f6a4ee | 7704 | |
eb66e842 | 7705 | if Inherit then |
7706 | String_To_Name_Buffer (Str); | |
d9f6a4ee | 7707 | |
eb66e842 | 7708 | if Name_Buffer (1 .. 16) = "failed invariant" then |
7709 | Insert_Str_In_Name_Buffer ("inherited ", 8); | |
7710 | Str := String_From_Name_Buffer; | |
7711 | end if; | |
7712 | end if; | |
d9f6a4ee | 7713 | |
eb66e842 | 7714 | Append_To (Assoc, |
7715 | Make_Pragma_Argument_Association (Loc, | |
7716 | Expression => Make_String_Literal (Loc, Str))); | |
7717 | end if; | |
d9f6a4ee | 7718 | |
eb66e842 | 7719 | -- Add Check pragma to list of statements |
d97beb2f | 7720 | |
eb66e842 | 7721 | Append_To (Stmts, |
7722 | Make_Pragma (Loc, | |
7723 | Pragma_Identifier => | |
7724 | Make_Identifier (Loc, Name_Check), | |
7725 | Pragma_Argument_Associations => Assoc)); | |
d97beb2f | 7726 | |
eb66e842 | 7727 | -- If Inherited case and option enabled, output info msg. Note |
7728 | -- that we know this is a case of Invariant'Class. | |
d97beb2f | 7729 | |
eb66e842 | 7730 | if Inherit and Opt.List_Inherited_Aspects then |
7731 | Error_Msg_Sloc := Sloc (Ritem); | |
7732 | Error_Msg_N | |
7733 | ("info: & inherits `Invariant''Class` aspect from #?L?", | |
7734 | Typ); | |
7735 | end if; | |
d9f6a4ee | 7736 | end if; |
d97beb2f | 7737 | |
eb66e842 | 7738 | <<Continue>> |
7739 | Next_Rep_Item (Ritem); | |
7740 | end loop; | |
7741 | end Add_Invariants; | |
d97beb2f | 7742 | |
eb66e842 | 7743 | -- Start of processing for Build_Invariant_Procedure |
d97beb2f | 7744 | |
eb66e842 | 7745 | begin |
7746 | Stmts := No_List; | |
7747 | PDecl := Empty; | |
7748 | PBody := Empty; | |
7749 | SId := Empty; | |
d97beb2f | 7750 | |
eb66e842 | 7751 | -- If the aspect specification exists for some view of the type, the |
7752 | -- declaration for the procedure has been created. | |
d97beb2f | 7753 | |
eb66e842 | 7754 | if Has_Invariants (Typ) then |
7755 | SId := Invariant_Procedure (Typ); | |
7756 | end if; | |
9dc88aea | 7757 | |
0c2bde47 | 7758 | -- If the body is already present, nothing to do. This will occur when |
7759 | -- the type is already frozen, which is the case when the invariant | |
7760 | -- appears in a private part, and the freezing takes place before the | |
7761 | -- final pass over full declarations. | |
aba11c12 | 7762 | |
7763 | -- See Exp_Ch3.Insert_Component_Invariant_Checks for details. | |
0c2bde47 | 7764 | |
eb66e842 | 7765 | if Present (SId) then |
7766 | PDecl := Unit_Declaration_Node (SId); | |
0c2bde47 | 7767 | |
7768 | if Present (PDecl) | |
7769 | and then Nkind (PDecl) = N_Subprogram_Declaration | |
7770 | and then Present (Corresponding_Body (PDecl)) | |
7771 | then | |
7772 | return; | |
7773 | end if; | |
7774 | ||
eb66e842 | 7775 | else |
7776 | PDecl := Build_Invariant_Procedure_Declaration (Typ); | |
7777 | end if; | |
9dc88aea | 7778 | |
eb66e842 | 7779 | -- Recover formal of procedure, for use in the calls to invariant |
7780 | -- functions (including inherited ones). | |
d9f6a4ee | 7781 | |
eb66e842 | 7782 | Object_Entity := |
7783 | Defining_Identifier | |
7784 | (First (Parameter_Specifications (Specification (PDecl)))); | |
7785 | Object_Name := Chars (Object_Entity); | |
d9f6a4ee | 7786 | |
eb66e842 | 7787 | -- Add invariants for the current type |
9dc88aea | 7788 | |
eb66e842 | 7789 | Add_Invariants (Typ, Inherit => False); |
9dc88aea | 7790 | |
eb66e842 | 7791 | -- Add invariants for parent types |
9dc88aea | 7792 | |
eb66e842 | 7793 | declare |
7794 | Current_Typ : Entity_Id; | |
7795 | Parent_Typ : Entity_Id; | |
9dc88aea | 7796 | |
eb66e842 | 7797 | begin |
7798 | Current_Typ := Typ; | |
d97beb2f | 7799 | loop |
eb66e842 | 7800 | Parent_Typ := Etype (Current_Typ); |
9dc88aea | 7801 | |
eb66e842 | 7802 | if Is_Private_Type (Parent_Typ) |
7803 | and then Present (Full_View (Base_Type (Parent_Typ))) | |
d9f6a4ee | 7804 | then |
eb66e842 | 7805 | Parent_Typ := Full_View (Base_Type (Parent_Typ)); |
7806 | end if; | |
9dc88aea | 7807 | |
eb66e842 | 7808 | exit when Parent_Typ = Current_Typ; |
9dc88aea | 7809 | |
eb66e842 | 7810 | Current_Typ := Parent_Typ; |
7811 | Add_Invariants (Current_Typ, Inherit => True); | |
7812 | end loop; | |
7813 | end; | |
9dc88aea | 7814 | |
eb66e842 | 7815 | -- Build the procedure if we generated at least one Check pragma |
9dc88aea | 7816 | |
eb66e842 | 7817 | if Stmts /= No_List then |
7818 | Spec := Copy_Separate_Tree (Specification (PDecl)); | |
9dc88aea | 7819 | |
eb66e842 | 7820 | PBody := |
7821 | Make_Subprogram_Body (Loc, | |
7822 | Specification => Spec, | |
7823 | Declarations => Empty_List, | |
7824 | Handled_Statement_Sequence => | |
7825 | Make_Handled_Sequence_Of_Statements (Loc, | |
7826 | Statements => Stmts)); | |
9dc88aea | 7827 | |
eb66e842 | 7828 | -- Insert procedure declaration and spec at the appropriate points. |
7829 | -- If declaration is already analyzed, it was processed by the | |
7830 | -- generated pragma. | |
9dc88aea | 7831 | |
eb66e842 | 7832 | if Present (Private_Decls) then |
d97beb2f | 7833 | |
eb66e842 | 7834 | -- The spec goes at the end of visible declarations, but they have |
7835 | -- already been analyzed, so we need to explicitly do the analyze. | |
d9f6a4ee | 7836 | |
eb66e842 | 7837 | if not Analyzed (PDecl) then |
7838 | Append_To (Visible_Decls, PDecl); | |
7839 | Analyze (PDecl); | |
7840 | end if; | |
d9f6a4ee | 7841 | |
eb66e842 | 7842 | -- The body goes at the end of the private declarations, which we |
7843 | -- have not analyzed yet, so we do not need to perform an explicit | |
7844 | -- analyze call. We skip this if there are no private declarations | |
7845 | -- (this is an error that will be caught elsewhere); | |
d9f6a4ee | 7846 | |
eb66e842 | 7847 | Append_To (Private_Decls, PBody); |
d9f6a4ee | 7848 | |
eb66e842 | 7849 | -- If the invariant appears on the full view of a type, the |
7850 | -- analysis of the private part is complete, and we must | |
7851 | -- analyze the new body explicitly. | |
d9f6a4ee | 7852 | |
eb66e842 | 7853 | if In_Private_Part (Current_Scope) then |
7854 | Analyze (PBody); | |
7855 | end if; | |
d97beb2f | 7856 | |
eb66e842 | 7857 | -- If there are no private declarations this may be an error that |
7858 | -- will be diagnosed elsewhere. However, if this is a non-private | |
7859 | -- type that inherits invariants, it needs no completion and there | |
7860 | -- may be no private part. In this case insert invariant procedure | |
7861 | -- at end of current declarative list, and analyze at once, given | |
7862 | -- that the type is about to be frozen. | |
d97beb2f | 7863 | |
eb66e842 | 7864 | elsif not Is_Private_Type (Typ) then |
7865 | Append_To (Visible_Decls, PDecl); | |
7866 | Append_To (Visible_Decls, PBody); | |
7867 | Analyze (PDecl); | |
7868 | Analyze (PBody); | |
7869 | end if; | |
7870 | end if; | |
7871 | end Build_Invariant_Procedure; | |
d9f6a4ee | 7872 | |
eb66e842 | 7873 | ------------------------------- |
7874 | -- Build_Predicate_Functions -- | |
7875 | ------------------------------- | |
d9f6a4ee | 7876 | |
eb66e842 | 7877 | -- The procedures that are constructed here have the form: |
d9f6a4ee | 7878 | |
eb66e842 | 7879 | -- function typPredicate (Ixxx : typ) return Boolean is |
7880 | -- begin | |
7881 | -- return | |
7882 | -- exp1 and then exp2 and then ... | |
7883 | -- and then typ1Predicate (typ1 (Ixxx)) | |
7884 | -- and then typ2Predicate (typ2 (Ixxx)) | |
7885 | -- and then ...; | |
7886 | -- end typPredicate; | |
d9f6a4ee | 7887 | |
eb66e842 | 7888 | -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that |
7889 | -- this is the point at which these expressions get analyzed, providing the | |
7890 | -- required delay, and typ1, typ2, are entities from which predicates are | |
7891 | -- inherited. Note that we do NOT generate Check pragmas, that's because we | |
7892 | -- use this function even if checks are off, e.g. for membership tests. | |
d9f6a4ee | 7893 | |
eb66e842 | 7894 | -- If the expression has at least one Raise_Expression, then we also build |
7895 | -- the typPredicateM version of the function, in which any occurrence of a | |
7896 | -- Raise_Expression is converted to "return False". | |
d9f6a4ee | 7897 | |
eb66e842 | 7898 | procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is |
7899 | Loc : constant Source_Ptr := Sloc (Typ); | |
d9f6a4ee | 7900 | |
eb66e842 | 7901 | Expr : Node_Id; |
7902 | -- This is the expression for the result of the function. It is | |
7903 | -- is build by connecting the component predicates with AND THEN. | |
d9f6a4ee | 7904 | |
eb66e842 | 7905 | Expr_M : Node_Id; |
7906 | -- This is the corresponding return expression for the Predicate_M | |
7907 | -- function. It differs in that raise expressions are marked for | |
7908 | -- special expansion (see Process_REs). | |
d9f6a4ee | 7909 | |
eb66e842 | 7910 | Object_Name : constant Name_Id := New_Internal_Name ('I'); |
7911 | -- Name for argument of Predicate procedure. Note that we use the same | |
499918a7 | 7912 | -- name for both predicate functions. That way the reference within the |
eb66e842 | 7913 | -- predicate expression is the same in both functions. |
d9f6a4ee | 7914 | |
eb66e842 | 7915 | Object_Entity : constant Entity_Id := |
7916 | Make_Defining_Identifier (Loc, Chars => Object_Name); | |
7917 | -- Entity for argument of Predicate procedure | |
d9f6a4ee | 7918 | |
eb66e842 | 7919 | Object_Entity_M : constant Entity_Id := |
7920 | Make_Defining_Identifier (Loc, Chars => Object_Name); | |
7921 | -- Entity for argument of Predicate_M procedure | |
d9f6a4ee | 7922 | |
eb66e842 | 7923 | Raise_Expression_Present : Boolean := False; |
7924 | -- Set True if Expr has at least one Raise_Expression | |
d9f6a4ee | 7925 | |
eb66e842 | 7926 | procedure Add_Call (T : Entity_Id); |
7927 | -- Includes a call to the predicate function for type T in Expr if T | |
7928 | -- has predicates and Predicate_Function (T) is non-empty. | |
d9f6a4ee | 7929 | |
eb66e842 | 7930 | procedure Add_Predicates; |
7931 | -- Appends expressions for any Predicate pragmas in the rep item chain | |
7932 | -- Typ to Expr. Note that we look only at items for this exact entity. | |
7933 | -- Inheritance of predicates for the parent type is done by calling the | |
7934 | -- Predicate_Function of the parent type, using Add_Call above. | |
d9f6a4ee | 7935 | |
eb66e842 | 7936 | function Test_RE (N : Node_Id) return Traverse_Result; |
7937 | -- Used in Test_REs, tests one node for being a raise expression, and if | |
7938 | -- so sets Raise_Expression_Present True. | |
d9f6a4ee | 7939 | |
eb66e842 | 7940 | procedure Test_REs is new Traverse_Proc (Test_RE); |
7941 | -- Tests to see if Expr contains any raise expressions | |
d9f6a4ee | 7942 | |
eb66e842 | 7943 | function Process_RE (N : Node_Id) return Traverse_Result; |
7944 | -- Used in Process REs, tests if node N is a raise expression, and if | |
7945 | -- so, marks it to be converted to return False. | |
d9f6a4ee | 7946 | |
eb66e842 | 7947 | procedure Process_REs is new Traverse_Proc (Process_RE); |
7948 | -- Marks any raise expressions in Expr_M to return False | |
d9f6a4ee | 7949 | |
eb66e842 | 7950 | -------------- |
7951 | -- Add_Call -- | |
7952 | -------------- | |
d9f6a4ee | 7953 | |
eb66e842 | 7954 | procedure Add_Call (T : Entity_Id) is |
7955 | Exp : Node_Id; | |
d9f6a4ee | 7956 | |
eb66e842 | 7957 | begin |
7958 | if Present (T) and then Present (Predicate_Function (T)) then | |
7959 | Set_Has_Predicates (Typ); | |
d9f6a4ee | 7960 | |
eb66e842 | 7961 | -- Build the call to the predicate function of T |
d9f6a4ee | 7962 | |
eb66e842 | 7963 | Exp := |
7964 | Make_Predicate_Call | |
7965 | (T, Convert_To (T, Make_Identifier (Loc, Object_Name))); | |
d9f6a4ee | 7966 | |
eb66e842 | 7967 | -- Add call to evolving expression, using AND THEN if needed |
d9f6a4ee | 7968 | |
eb66e842 | 7969 | if No (Expr) then |
7970 | Expr := Exp; | |
3b23aaa0 | 7971 | |
eb66e842 | 7972 | else |
7973 | Expr := | |
3b23aaa0 | 7974 | Make_And_Then (Sloc (Expr), |
eb66e842 | 7975 | Left_Opnd => Relocate_Node (Expr), |
7976 | Right_Opnd => Exp); | |
7977 | end if; | |
d9f6a4ee | 7978 | |
eb66e842 | 7979 | -- Output info message on inheritance if required. Note we do not |
7980 | -- give this information for generic actual types, since it is | |
7981 | -- unwelcome noise in that case in instantiations. We also | |
7982 | -- generally suppress the message in instantiations, and also | |
7983 | -- if it involves internal names. | |
d9f6a4ee | 7984 | |
eb66e842 | 7985 | if Opt.List_Inherited_Aspects |
7986 | and then not Is_Generic_Actual_Type (Typ) | |
7987 | and then Instantiation_Depth (Sloc (Typ)) = 0 | |
7988 | and then not Is_Internal_Name (Chars (T)) | |
7989 | and then not Is_Internal_Name (Chars (Typ)) | |
7990 | then | |
7991 | Error_Msg_Sloc := Sloc (Predicate_Function (T)); | |
7992 | Error_Msg_Node_2 := T; | |
7993 | Error_Msg_N ("info: & inherits predicate from & #?L?", Typ); | |
7994 | end if; | |
7995 | end if; | |
7996 | end Add_Call; | |
d9f6a4ee | 7997 | |
eb66e842 | 7998 | -------------------- |
7999 | -- Add_Predicates -- | |
8000 | -------------------- | |
d9f6a4ee | 8001 | |
eb66e842 | 8002 | procedure Add_Predicates is |
8003 | Ritem : Node_Id; | |
8004 | Arg1 : Node_Id; | |
8005 | Arg2 : Node_Id; | |
d9f6a4ee | 8006 | |
eb66e842 | 8007 | procedure Replace_Type_Reference (N : Node_Id); |
8008 | -- Replace a single occurrence N of the subtype name with a reference | |
8009 | -- to the formal of the predicate function. N can be an identifier | |
8010 | -- referencing the subtype, or a selected component, representing an | |
8011 | -- appropriately qualified occurrence of the subtype name. | |
d9f6a4ee | 8012 | |
eb66e842 | 8013 | procedure Replace_Type_References is |
8014 | new Replace_Type_References_Generic (Replace_Type_Reference); | |
8015 | -- Traverse an expression changing every occurrence of an identifier | |
8016 | -- whose name matches the name of the subtype with a reference to | |
8017 | -- the formal parameter of the predicate function. | |
d9f6a4ee | 8018 | |
eb66e842 | 8019 | ---------------------------- |
8020 | -- Replace_Type_Reference -- | |
8021 | ---------------------------- | |
d9f6a4ee | 8022 | |
eb66e842 | 8023 | procedure Replace_Type_Reference (N : Node_Id) is |
8024 | begin | |
8025 | Rewrite (N, Make_Identifier (Sloc (N), Object_Name)); | |
8026 | -- Use the Sloc of the usage name, not the defining name | |
d97beb2f | 8027 | |
eb66e842 | 8028 | Set_Etype (N, Typ); |
8029 | Set_Entity (N, Object_Entity); | |
d97beb2f | 8030 | |
eb66e842 | 8031 | -- We want to treat the node as if it comes from source, so that |
8032 | -- ASIS will not ignore it | |
d97beb2f | 8033 | |
eb66e842 | 8034 | Set_Comes_From_Source (N, True); |
8035 | end Replace_Type_Reference; | |
d97beb2f | 8036 | |
eb66e842 | 8037 | -- Start of processing for Add_Predicates |
d97beb2f | 8038 | |
eb66e842 | 8039 | begin |
8040 | Ritem := First_Rep_Item (Typ); | |
8041 | while Present (Ritem) loop | |
8042 | if Nkind (Ritem) = N_Pragma | |
8043 | and then Pragma_Name (Ritem) = Name_Predicate | |
8044 | then | |
eb66e842 | 8045 | -- Acquire arguments |
d97beb2f | 8046 | |
eb66e842 | 8047 | Arg1 := First (Pragma_Argument_Associations (Ritem)); |
8048 | Arg2 := Next (Arg1); | |
d97beb2f | 8049 | |
eb66e842 | 8050 | Arg1 := Get_Pragma_Arg (Arg1); |
8051 | Arg2 := Get_Pragma_Arg (Arg2); | |
d97beb2f | 8052 | |
eb66e842 | 8053 | -- See if this predicate pragma is for the current type or for |
8054 | -- its full view. A predicate on a private completion is placed | |
8055 | -- on the partial view beause this is the visible entity that | |
8056 | -- is frozen. | |
639c3741 | 8057 | |
eb66e842 | 8058 | if Entity (Arg1) = Typ |
8059 | or else Full_View (Entity (Arg1)) = Typ | |
639c3741 | 8060 | then |
eb66e842 | 8061 | -- We have a match, this entry is for our subtype |
639c3741 | 8062 | |
eb66e842 | 8063 | -- We need to replace any occurrences of the name of the |
8064 | -- type with references to the object. | |
639c3741 | 8065 | |
37c6552c | 8066 | Replace_Type_References (Arg2, Typ); |
639c3741 | 8067 | |
eb66e842 | 8068 | -- If this predicate comes from an aspect, find the aspect |
8069 | -- specification, and replace the saved expression because | |
8070 | -- we need the subtype references replaced for the calls to | |
8071 | -- Preanalyze_Spec_Expressin in Check_Aspect_At_Freeze_Point | |
8072 | -- and Check_Aspect_At_End_Of_Declarations. | |
639c3741 | 8073 | |
eb66e842 | 8074 | if From_Aspect_Specification (Ritem) then |
8075 | declare | |
8076 | Aitem : Node_Id; | |
639c3741 | 8077 | |
eb66e842 | 8078 | begin |
8079 | -- Loop to find corresponding aspect, note that this | |
8080 | -- must be present given the pragma is marked delayed. | |
639c3741 | 8081 | |
eb66e842 | 8082 | Aitem := Next_Rep_Item (Ritem); |
8083 | loop | |
8084 | if Nkind (Aitem) = N_Aspect_Specification | |
8085 | and then Aspect_Rep_Item (Aitem) = Ritem | |
8086 | then | |
8087 | Set_Entity | |
8088 | (Identifier (Aitem), New_Copy_Tree (Arg2)); | |
8089 | exit; | |
8090 | end if; | |
639c3741 | 8091 | |
eb66e842 | 8092 | Aitem := Next_Rep_Item (Aitem); |
8093 | end loop; | |
8094 | end; | |
8095 | end if; | |
737e8460 | 8096 | |
eb66e842 | 8097 | -- Now we can add the expression |
737e8460 | 8098 | |
eb66e842 | 8099 | if No (Expr) then |
8100 | Expr := Relocate_Node (Arg2); | |
d97beb2f | 8101 | |
eb66e842 | 8102 | -- There already was a predicate, so add to it |
d97beb2f | 8103 | |
eb66e842 | 8104 | else |
8105 | Expr := | |
8106 | Make_And_Then (Loc, | |
8107 | Left_Opnd => Relocate_Node (Expr), | |
8108 | Right_Opnd => Relocate_Node (Arg2)); | |
8109 | end if; | |
8110 | end if; | |
8111 | end if; | |
d97beb2f | 8112 | |
eb66e842 | 8113 | Next_Rep_Item (Ritem); |
8114 | end loop; | |
8115 | end Add_Predicates; | |
d97beb2f | 8116 | |
eb66e842 | 8117 | ---------------- |
8118 | -- Process_RE -- | |
8119 | ---------------- | |
d97beb2f | 8120 | |
eb66e842 | 8121 | function Process_RE (N : Node_Id) return Traverse_Result is |
d9f6a4ee | 8122 | begin |
eb66e842 | 8123 | if Nkind (N) = N_Raise_Expression then |
8124 | Set_Convert_To_Return_False (N); | |
8125 | return Skip; | |
d9f6a4ee | 8126 | else |
eb66e842 | 8127 | return OK; |
d9f6a4ee | 8128 | end if; |
eb66e842 | 8129 | end Process_RE; |
d7c2851f | 8130 | |
d9f6a4ee | 8131 | ------------- |
eb66e842 | 8132 | -- Test_RE -- |
d9f6a4ee | 8133 | ------------- |
d7c2851f | 8134 | |
eb66e842 | 8135 | function Test_RE (N : Node_Id) return Traverse_Result is |
d97beb2f | 8136 | begin |
eb66e842 | 8137 | if Nkind (N) = N_Raise_Expression then |
8138 | Raise_Expression_Present := True; | |
8139 | return Abandon; | |
8140 | else | |
8141 | return OK; | |
8142 | end if; | |
8143 | end Test_RE; | |
d97beb2f | 8144 | |
eb66e842 | 8145 | -- Start of processing for Build_Predicate_Functions |
d97beb2f | 8146 | |
eb66e842 | 8147 | begin |
8148 | -- Return if already built or if type does not have predicates | |
9dc88aea | 8149 | |
eb66e842 | 8150 | if not Has_Predicates (Typ) |
8151 | or else Present (Predicate_Function (Typ)) | |
8152 | then | |
8153 | return; | |
8154 | end if; | |
d9f6a4ee | 8155 | |
eb66e842 | 8156 | -- Prepare to construct predicate expression |
d97beb2f | 8157 | |
eb66e842 | 8158 | Expr := Empty; |
d97beb2f | 8159 | |
eb66e842 | 8160 | -- Add Predicates for the current type |
d97beb2f | 8161 | |
eb66e842 | 8162 | Add_Predicates; |
d97beb2f | 8163 | |
eb66e842 | 8164 | -- Add predicates for ancestor if present |
d97beb2f | 8165 | |
eb66e842 | 8166 | declare |
8167 | Atyp : constant Entity_Id := Nearest_Ancestor (Typ); | |
d9f6a4ee | 8168 | begin |
eb66e842 | 8169 | if Present (Atyp) then |
8170 | Add_Call (Atyp); | |
8171 | end if; | |
8172 | end; | |
9dc88aea | 8173 | |
eb66e842 | 8174 | -- Case where predicates are present |
9dc88aea | 8175 | |
eb66e842 | 8176 | if Present (Expr) then |
726fd56a | 8177 | |
eb66e842 | 8178 | -- Test for raise expression present |
726fd56a | 8179 | |
eb66e842 | 8180 | Test_REs (Expr); |
9dc88aea | 8181 | |
eb66e842 | 8182 | -- If raise expression is present, capture a copy of Expr for use |
8183 | -- in building the predicateM function version later on. For this | |
8184 | -- copy we replace references to Object_Entity by Object_Entity_M. | |
9dc88aea | 8185 | |
eb66e842 | 8186 | if Raise_Expression_Present then |
8187 | declare | |
8188 | Map : constant Elist_Id := New_Elmt_List; | |
8189 | begin | |
8190 | Append_Elmt (Object_Entity, Map); | |
8191 | Append_Elmt (Object_Entity_M, Map); | |
8192 | Expr_M := New_Copy_Tree (Expr, Map => Map); | |
8193 | end; | |
8194 | end if; | |
d97beb2f | 8195 | |
eb66e842 | 8196 | -- Build the main predicate function |
9dc88aea | 8197 | |
eb66e842 | 8198 | declare |
8199 | SId : constant Entity_Id := | |
8200 | Make_Defining_Identifier (Loc, | |
8201 | Chars => New_External_Name (Chars (Typ), "Predicate")); | |
8202 | -- The entity for the the function spec | |
9dc88aea | 8203 | |
eb66e842 | 8204 | SIdB : constant Entity_Id := |
8205 | Make_Defining_Identifier (Loc, | |
8206 | Chars => New_External_Name (Chars (Typ), "Predicate")); | |
8207 | -- The entity for the function body | |
9dc88aea | 8208 | |
eb66e842 | 8209 | Spec : Node_Id; |
8210 | FDecl : Node_Id; | |
8211 | FBody : Node_Id; | |
9dc88aea | 8212 | |
eb66e842 | 8213 | begin |
8214 | -- Build function declaration | |
d97beb2f | 8215 | |
eb66e842 | 8216 | Set_Ekind (SId, E_Function); |
8217 | Set_Is_Internal (SId); | |
8218 | Set_Is_Predicate_Function (SId); | |
8219 | Set_Predicate_Function (Typ, SId); | |
d97beb2f | 8220 | |
eb66e842 | 8221 | -- The predicate function is shared between views of a type |
d97beb2f | 8222 | |
eb66e842 | 8223 | if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
8224 | Set_Predicate_Function (Full_View (Typ), SId); | |
d97beb2f | 8225 | end if; |
d97beb2f | 8226 | |
eb66e842 | 8227 | Spec := |
8228 | Make_Function_Specification (Loc, | |
8229 | Defining_Unit_Name => SId, | |
8230 | Parameter_Specifications => New_List ( | |
8231 | Make_Parameter_Specification (Loc, | |
8232 | Defining_Identifier => Object_Entity, | |
8233 | Parameter_Type => New_Occurrence_Of (Typ, Loc))), | |
8234 | Result_Definition => | |
8235 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
d97beb2f | 8236 | |
eb66e842 | 8237 | FDecl := |
8238 | Make_Subprogram_Declaration (Loc, | |
8239 | Specification => Spec); | |
d97beb2f | 8240 | |
eb66e842 | 8241 | -- Build function body |
d97beb2f | 8242 | |
eb66e842 | 8243 | Spec := |
8244 | Make_Function_Specification (Loc, | |
8245 | Defining_Unit_Name => SIdB, | |
8246 | Parameter_Specifications => New_List ( | |
8247 | Make_Parameter_Specification (Loc, | |
8248 | Defining_Identifier => | |
8249 | Make_Defining_Identifier (Loc, Object_Name), | |
8250 | Parameter_Type => | |
8251 | New_Occurrence_Of (Typ, Loc))), | |
8252 | Result_Definition => | |
8253 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
d97beb2f | 8254 | |
eb66e842 | 8255 | FBody := |
8256 | Make_Subprogram_Body (Loc, | |
8257 | Specification => Spec, | |
8258 | Declarations => Empty_List, | |
8259 | Handled_Statement_Sequence => | |
8260 | Make_Handled_Sequence_Of_Statements (Loc, | |
8261 | Statements => New_List ( | |
8262 | Make_Simple_Return_Statement (Loc, | |
8263 | Expression => Expr)))); | |
9dc88aea | 8264 | |
eb66e842 | 8265 | -- Insert declaration before freeze node and body after |
d97beb2f | 8266 | |
eb66e842 | 8267 | Insert_Before_And_Analyze (N, FDecl); |
8268 | Insert_After_And_Analyze (N, FBody); | |
d9f6a4ee | 8269 | end; |
d97beb2f | 8270 | |
eb66e842 | 8271 | -- Test for raise expressions present and if so build M version |
d97beb2f | 8272 | |
eb66e842 | 8273 | if Raise_Expression_Present then |
8274 | declare | |
8275 | SId : constant Entity_Id := | |
8276 | Make_Defining_Identifier (Loc, | |
8277 | Chars => New_External_Name (Chars (Typ), "PredicateM")); | |
8278 | -- The entity for the the function spec | |
d97beb2f | 8279 | |
eb66e842 | 8280 | SIdB : constant Entity_Id := |
8281 | Make_Defining_Identifier (Loc, | |
8282 | Chars => New_External_Name (Chars (Typ), "PredicateM")); | |
8283 | -- The entity for the function body | |
b9e61b2a | 8284 | |
eb66e842 | 8285 | Spec : Node_Id; |
8286 | FDecl : Node_Id; | |
8287 | FBody : Node_Id; | |
8288 | BTemp : Entity_Id; | |
d97beb2f | 8289 | |
eb66e842 | 8290 | begin |
8291 | -- Mark any raise expressions for special expansion | |
d97beb2f | 8292 | |
eb66e842 | 8293 | Process_REs (Expr_M); |
d97beb2f | 8294 | |
eb66e842 | 8295 | -- Build function declaration |
d97beb2f | 8296 | |
eb66e842 | 8297 | Set_Ekind (SId, E_Function); |
8298 | Set_Is_Predicate_Function_M (SId); | |
8299 | Set_Predicate_Function_M (Typ, SId); | |
d97beb2f | 8300 | |
eb66e842 | 8301 | -- The predicate function is shared between views of a type |
d97beb2f | 8302 | |
eb66e842 | 8303 | if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
8304 | Set_Predicate_Function_M (Full_View (Typ), SId); | |
8305 | end if; | |
9dc88aea | 8306 | |
eb66e842 | 8307 | Spec := |
8308 | Make_Function_Specification (Loc, | |
8309 | Defining_Unit_Name => SId, | |
8310 | Parameter_Specifications => New_List ( | |
8311 | Make_Parameter_Specification (Loc, | |
8312 | Defining_Identifier => Object_Entity_M, | |
8313 | Parameter_Type => New_Occurrence_Of (Typ, Loc))), | |
8314 | Result_Definition => | |
8315 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
9dc88aea | 8316 | |
eb66e842 | 8317 | FDecl := |
8318 | Make_Subprogram_Declaration (Loc, | |
8319 | Specification => Spec); | |
9dc88aea | 8320 | |
eb66e842 | 8321 | -- Build function body |
9dc88aea | 8322 | |
eb66e842 | 8323 | Spec := |
8324 | Make_Function_Specification (Loc, | |
8325 | Defining_Unit_Name => SIdB, | |
8326 | Parameter_Specifications => New_List ( | |
8327 | Make_Parameter_Specification (Loc, | |
8328 | Defining_Identifier => | |
8329 | Make_Defining_Identifier (Loc, Object_Name), | |
8330 | Parameter_Type => | |
8331 | New_Occurrence_Of (Typ, Loc))), | |
8332 | Result_Definition => | |
8333 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
9dc88aea | 8334 | |
eb66e842 | 8335 | -- Build the body, we declare the boolean expression before |
8336 | -- doing the return, because we are not really confident of | |
8337 | -- what happens if a return appears within a return. | |
9dc88aea | 8338 | |
eb66e842 | 8339 | BTemp := |
8340 | Make_Defining_Identifier (Loc, | |
8341 | Chars => New_Internal_Name ('B')); | |
9dc88aea | 8342 | |
eb66e842 | 8343 | FBody := |
8344 | Make_Subprogram_Body (Loc, | |
8345 | Specification => Spec, | |
9dc88aea | 8346 | |
eb66e842 | 8347 | Declarations => New_List ( |
8348 | Make_Object_Declaration (Loc, | |
8349 | Defining_Identifier => BTemp, | |
8350 | Constant_Present => True, | |
8351 | Object_Definition => | |
8352 | New_Occurrence_Of (Standard_Boolean, Loc), | |
8353 | Expression => Expr_M)), | |
d97beb2f | 8354 | |
eb66e842 | 8355 | Handled_Statement_Sequence => |
8356 | Make_Handled_Sequence_Of_Statements (Loc, | |
8357 | Statements => New_List ( | |
8358 | Make_Simple_Return_Statement (Loc, | |
8359 | Expression => New_Occurrence_Of (BTemp, Loc))))); | |
d97beb2f | 8360 | |
eb66e842 | 8361 | -- Insert declaration before freeze node and body after |
d97beb2f | 8362 | |
eb66e842 | 8363 | Insert_Before_And_Analyze (N, FDecl); |
8364 | Insert_After_And_Analyze (N, FBody); | |
8365 | end; | |
8366 | end if; | |
9dc88aea | 8367 | |
3b23aaa0 | 8368 | -- See if we have a static predicate. Note that the answer may be |
8369 | -- yes even if we have an explicit Dynamic_Predicate present. | |
9dc88aea | 8370 | |
3b23aaa0 | 8371 | declare |
94d896aa | 8372 | PS : Boolean; |
3b23aaa0 | 8373 | EN : Node_Id; |
9dc88aea | 8374 | |
3b23aaa0 | 8375 | begin |
94d896aa | 8376 | if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then |
8377 | PS := False; | |
8378 | else | |
8379 | PS := Is_Predicate_Static (Expr, Object_Name); | |
8380 | end if; | |
8381 | ||
a360a0f7 | 8382 | -- Case where we have a predicate-static aspect |
9dc88aea | 8383 | |
3b23aaa0 | 8384 | if PS then |
9dc88aea | 8385 | |
3b23aaa0 | 8386 | -- We don't set Has_Static_Predicate_Aspect, since we can have |
8387 | -- any of the three cases (Predicate, Dynamic_Predicate, or | |
8388 | -- Static_Predicate) generating a predicate with an expression | |
a360a0f7 | 8389 | -- that is predicate-static. We just indicate that we have a |
3b23aaa0 | 8390 | -- predicate that can be treated as static. |
d7c2851f | 8391 | |
3b23aaa0 | 8392 | Set_Has_Static_Predicate (Typ); |
d7c2851f | 8393 | |
3b23aaa0 | 8394 | -- For discrete subtype, build the static predicate list |
9dc88aea | 8395 | |
3b23aaa0 | 8396 | if Is_Discrete_Type (Typ) then |
d0988351 | 8397 | if not Is_Static_Subtype (Typ) then |
8398 | ||
8399 | -- This can only happen in the presence of previous | |
8400 | -- semantic errors. | |
8401 | ||
8402 | pragma Assert (Serious_Errors_Detected > 0); | |
8403 | return; | |
8404 | end if; | |
8405 | ||
3b23aaa0 | 8406 | Build_Discrete_Static_Predicate (Typ, Expr, Object_Name); |
8407 | ||
8408 | -- If we don't get a static predicate list, it means that we | |
8409 | -- have a case where this is not possible, most typically in | |
8410 | -- the case where we inherit a dynamic predicate. We do not | |
8411 | -- consider this an error, we just leave the predicate as | |
8412 | -- dynamic. But if we do succeed in building the list, then | |
8413 | -- we mark the predicate as static. | |
8414 | ||
5c6a5792 | 8415 | if No (Static_Discrete_Predicate (Typ)) then |
3b23aaa0 | 8416 | Set_Has_Static_Predicate (Typ, False); |
8417 | end if; | |
94d896aa | 8418 | |
8419 | -- For real or string subtype, save predicate expression | |
8420 | ||
8421 | elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then | |
8422 | Set_Static_Real_Or_String_Predicate (Typ, Expr); | |
3b23aaa0 | 8423 | end if; |
8424 | ||
8425 | -- Case of dynamic predicate (expression is not predicate-static) | |
9dc88aea | 8426 | |
eb66e842 | 8427 | else |
3b23aaa0 | 8428 | -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that |
8429 | -- is only set if we have an explicit Dynamic_Predicate aspect | |
8430 | -- given. Here we may simply have a Predicate aspect where the | |
8431 | -- expression happens not to be predicate-static. | |
8432 | ||
8433 | -- Emit an error when the predicate is categorized as static | |
8434 | -- but its expression is not predicate-static. | |
8435 | ||
8436 | -- First a little fiddling to get a nice location for the | |
8437 | -- message. If the expression is of the form (A and then B), | |
8438 | -- then use the left operand for the Sloc. This avoids getting | |
a360a0f7 | 8439 | -- confused by a call to a higher-level predicate with a less |
3b23aaa0 | 8440 | -- convenient source location. |
8441 | ||
8442 | EN := Expr; | |
8443 | while Nkind (EN) = N_And_Then loop | |
8444 | EN := Left_Opnd (EN); | |
8445 | end loop; | |
8446 | ||
8447 | -- Now post appropriate message | |
8448 | ||
8449 | if Has_Static_Predicate_Aspect (Typ) then | |
94d896aa | 8450 | if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then |
3b23aaa0 | 8451 | Error_Msg_F |
26279d91 | 8452 | ("expression is not predicate-static (RM 3.2.4(16-22))", |
3b23aaa0 | 8453 | EN); |
8454 | else | |
94d896aa | 8455 | Error_Msg_F |
8456 | ("static predicate requires scalar or string type", EN); | |
3b23aaa0 | 8457 | end if; |
8458 | end if; | |
eb66e842 | 8459 | end if; |
3b23aaa0 | 8460 | end; |
eb66e842 | 8461 | end if; |
8462 | end Build_Predicate_Functions; | |
9dc88aea | 8463 | |
d9f6a4ee | 8464 | ----------------------------------------- |
8465 | -- Check_Aspect_At_End_Of_Declarations -- | |
8466 | ----------------------------------------- | |
9dc88aea | 8467 | |
d9f6a4ee | 8468 | procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is |
8469 | Ent : constant Entity_Id := Entity (ASN); | |
8470 | Ident : constant Node_Id := Identifier (ASN); | |
8471 | A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); | |
d7c2851f | 8472 | |
d9f6a4ee | 8473 | End_Decl_Expr : constant Node_Id := Entity (Ident); |
8474 | -- Expression to be analyzed at end of declarations | |
d7c2851f | 8475 | |
d9f6a4ee | 8476 | Freeze_Expr : constant Node_Id := Expression (ASN); |
8477 | -- Expression from call to Check_Aspect_At_Freeze_Point | |
d7c2851f | 8478 | |
d9f6a4ee | 8479 | T : constant Entity_Id := Etype (Freeze_Expr); |
8480 | -- Type required for preanalyze call | |
d7c2851f | 8481 | |
d9f6a4ee | 8482 | Err : Boolean; |
8483 | -- Set False if error | |
9dc88aea | 8484 | |
d9f6a4ee | 8485 | -- On entry to this procedure, Entity (Ident) contains a copy of the |
8486 | -- original expression from the aspect, saved for this purpose, and | |
8487 | -- but Expression (Ident) is a preanalyzed copy of the expression, | |
8488 | -- preanalyzed just after the freeze point. | |
9dc88aea | 8489 | |
d9f6a4ee | 8490 | procedure Check_Overloaded_Name; |
8491 | -- For aspects whose expression is simply a name, this routine checks if | |
8492 | -- the name is overloaded or not. If so, it verifies there is an | |
8493 | -- interpretation that matches the entity obtained at the freeze point, | |
8494 | -- otherwise the compiler complains. | |
9dc88aea | 8495 | |
d9f6a4ee | 8496 | --------------------------- |
8497 | -- Check_Overloaded_Name -- | |
8498 | --------------------------- | |
8499 | ||
8500 | procedure Check_Overloaded_Name is | |
d97beb2f | 8501 | begin |
d9f6a4ee | 8502 | if not Is_Overloaded (End_Decl_Expr) then |
5ac76cee | 8503 | Err := not Is_Entity_Name (End_Decl_Expr) |
8504 | or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr); | |
d9f6a4ee | 8505 | |
d97beb2f | 8506 | else |
d9f6a4ee | 8507 | Err := True; |
9dc88aea | 8508 | |
d9f6a4ee | 8509 | declare |
8510 | Index : Interp_Index; | |
8511 | It : Interp; | |
9dc88aea | 8512 | |
d9f6a4ee | 8513 | begin |
8514 | Get_First_Interp (End_Decl_Expr, Index, It); | |
8515 | while Present (It.Typ) loop | |
8516 | if It.Nam = Entity (Freeze_Expr) then | |
8517 | Err := False; | |
8518 | exit; | |
8519 | end if; | |
8520 | ||
8521 | Get_Next_Interp (Index, It); | |
8522 | end loop; | |
8523 | end; | |
9dc88aea | 8524 | end if; |
d9f6a4ee | 8525 | end Check_Overloaded_Name; |
9dc88aea | 8526 | |
d9f6a4ee | 8527 | -- Start of processing for Check_Aspect_At_End_Of_Declarations |
9dc88aea | 8528 | |
d9f6a4ee | 8529 | begin |
8530 | -- Case of aspects Dimension, Dimension_System and Synchronization | |
9dc88aea | 8531 | |
d9f6a4ee | 8532 | if A_Id = Aspect_Synchronization then |
8533 | return; | |
d97beb2f | 8534 | |
d9f6a4ee | 8535 | -- Case of stream attributes, just have to compare entities. However, |
8536 | -- the expression is just a name (possibly overloaded), and there may | |
8537 | -- be stream operations declared for unrelated types, so we just need | |
8538 | -- to verify that one of these interpretations is the one available at | |
8539 | -- at the freeze point. | |
9dc88aea | 8540 | |
d9f6a4ee | 8541 | elsif A_Id = Aspect_Input or else |
f02a9a9a | 8542 | A_Id = Aspect_Output or else |
8543 | A_Id = Aspect_Read or else | |
8544 | A_Id = Aspect_Write | |
d9f6a4ee | 8545 | then |
8546 | Analyze (End_Decl_Expr); | |
8547 | Check_Overloaded_Name; | |
9dc88aea | 8548 | |
d9f6a4ee | 8549 | elsif A_Id = Aspect_Variable_Indexing or else |
8550 | A_Id = Aspect_Constant_Indexing or else | |
8551 | A_Id = Aspect_Default_Iterator or else | |
8552 | A_Id = Aspect_Iterator_Element | |
8553 | then | |
8554 | -- Make type unfrozen before analysis, to prevent spurious errors | |
8555 | -- about late attributes. | |
9dc88aea | 8556 | |
d9f6a4ee | 8557 | Set_Is_Frozen (Ent, False); |
8558 | Analyze (End_Decl_Expr); | |
8559 | Set_Is_Frozen (Ent, True); | |
9dc88aea | 8560 | |
d9f6a4ee | 8561 | -- If the end of declarations comes before any other freeze |
8562 | -- point, the Freeze_Expr is not analyzed: no check needed. | |
9dc88aea | 8563 | |
d9f6a4ee | 8564 | if Analyzed (Freeze_Expr) and then not In_Instance then |
8565 | Check_Overloaded_Name; | |
8566 | else | |
8567 | Err := False; | |
8568 | end if; | |
55e8372b | 8569 | |
d9f6a4ee | 8570 | -- All other cases |
55e8372b | 8571 | |
d9f6a4ee | 8572 | else |
c1efebf9 | 8573 | -- Indicate that the expression comes from an aspect specification, |
8574 | -- which is used in subsequent analysis even if expansion is off. | |
8575 | ||
8576 | Set_Parent (End_Decl_Expr, ASN); | |
8577 | ||
d9f6a4ee | 8578 | -- In a generic context the aspect expressions have not been |
8579 | -- preanalyzed, so do it now. There are no conformance checks | |
8580 | -- to perform in this case. | |
55e8372b | 8581 | |
d9f6a4ee | 8582 | if No (T) then |
8583 | Check_Aspect_At_Freeze_Point (ASN); | |
8584 | return; | |
55e8372b | 8585 | |
d9f6a4ee | 8586 | -- The default values attributes may be defined in the private part, |
8587 | -- and the analysis of the expression may take place when only the | |
8588 | -- partial view is visible. The expression must be scalar, so use | |
8589 | -- the full view to resolve. | |
55e8372b | 8590 | |
d9f6a4ee | 8591 | elsif (A_Id = Aspect_Default_Value |
8592 | or else | |
8593 | A_Id = Aspect_Default_Component_Value) | |
8594 | and then Is_Private_Type (T) | |
8595 | then | |
8596 | Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T)); | |
c1efebf9 | 8597 | |
d9f6a4ee | 8598 | else |
8599 | Preanalyze_Spec_Expression (End_Decl_Expr, T); | |
8600 | end if; | |
d97beb2f | 8601 | |
d9f6a4ee | 8602 | Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr); |
8603 | end if; | |
55e8372b | 8604 | |
c1efebf9 | 8605 | -- Output error message if error. Force error on aspect specification |
8606 | -- even if there is an error on the expression itself. | |
55e8372b | 8607 | |
d9f6a4ee | 8608 | if Err then |
8609 | Error_Msg_NE | |
c1efebf9 | 8610 | ("!visibility of aspect for& changes after freeze point", |
d9f6a4ee | 8611 | ASN, Ent); |
8612 | Error_Msg_NE | |
8613 | ("info: & is frozen here, aspects evaluated at this point??", | |
8614 | Freeze_Node (Ent), Ent); | |
8615 | end if; | |
8616 | end Check_Aspect_At_End_Of_Declarations; | |
55e8372b | 8617 | |
d9f6a4ee | 8618 | ---------------------------------- |
8619 | -- Check_Aspect_At_Freeze_Point -- | |
8620 | ---------------------------------- | |
9dc88aea | 8621 | |
d9f6a4ee | 8622 | procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is |
8623 | Ident : constant Node_Id := Identifier (ASN); | |
8624 | -- Identifier (use Entity field to save expression) | |
9dc88aea | 8625 | |
d9f6a4ee | 8626 | A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); |
9dc88aea | 8627 | |
d9f6a4ee | 8628 | T : Entity_Id := Empty; |
8629 | -- Type required for preanalyze call | |
9dc88aea | 8630 | |
d9f6a4ee | 8631 | begin |
8632 | -- On entry to this procedure, Entity (Ident) contains a copy of the | |
8633 | -- original expression from the aspect, saved for this purpose. | |
9dc88aea | 8634 | |
d9f6a4ee | 8635 | -- On exit from this procedure Entity (Ident) is unchanged, still |
8636 | -- containing that copy, but Expression (Ident) is a preanalyzed copy | |
8637 | -- of the expression, preanalyzed just after the freeze point. | |
d97beb2f | 8638 | |
d9f6a4ee | 8639 | -- Make a copy of the expression to be preanalyzed |
d97beb2f | 8640 | |
d9f6a4ee | 8641 | Set_Expression (ASN, New_Copy_Tree (Entity (Ident))); |
d97beb2f | 8642 | |
d9f6a4ee | 8643 | -- Find type for preanalyze call |
d97beb2f | 8644 | |
d9f6a4ee | 8645 | case A_Id is |
9dc88aea | 8646 | |
d9f6a4ee | 8647 | -- No_Aspect should be impossible |
d97beb2f | 8648 | |
d9f6a4ee | 8649 | when No_Aspect => |
8650 | raise Program_Error; | |
8651 | ||
8652 | -- Aspects taking an optional boolean argument | |
d97beb2f | 8653 | |
d9f6a4ee | 8654 | when Boolean_Aspects | |
8655 | Library_Unit_Aspects => | |
9dc88aea | 8656 | |
d9f6a4ee | 8657 | T := Standard_Boolean; |
d7c2851f | 8658 | |
d9f6a4ee | 8659 | -- Aspects corresponding to attribute definition clauses |
9dc88aea | 8660 | |
d9f6a4ee | 8661 | when Aspect_Address => |
8662 | T := RTE (RE_Address); | |
9dc88aea | 8663 | |
d9f6a4ee | 8664 | when Aspect_Attach_Handler => |
8665 | T := RTE (RE_Interrupt_ID); | |
d7c2851f | 8666 | |
d9f6a4ee | 8667 | when Aspect_Bit_Order | Aspect_Scalar_Storage_Order => |
8668 | T := RTE (RE_Bit_Order); | |
d7c2851f | 8669 | |
d9f6a4ee | 8670 | when Aspect_Convention => |
8671 | return; | |
d7c2851f | 8672 | |
d9f6a4ee | 8673 | when Aspect_CPU => |
8674 | T := RTE (RE_CPU_Range); | |
d7c2851f | 8675 | |
d9f6a4ee | 8676 | -- Default_Component_Value is resolved with the component type |
d7c2851f | 8677 | |
d9f6a4ee | 8678 | when Aspect_Default_Component_Value => |
8679 | T := Component_Type (Entity (ASN)); | |
d7c2851f | 8680 | |
d9f6a4ee | 8681 | -- Default_Value is resolved with the type entity in question |
d7c2851f | 8682 | |
d9f6a4ee | 8683 | when Aspect_Default_Value => |
8684 | T := Entity (ASN); | |
9dc88aea | 8685 | |
d9f6a4ee | 8686 | -- Depends is a delayed aspect because it mentiones names first |
8687 | -- introduced by aspect Global which is already delayed. There is | |
8688 | -- no action to be taken with respect to the aspect itself as the | |
8689 | -- analysis is done by the corresponding pragma. | |
9dc88aea | 8690 | |
d9f6a4ee | 8691 | when Aspect_Depends => |
8692 | return; | |
9dc88aea | 8693 | |
d9f6a4ee | 8694 | when Aspect_Dispatching_Domain => |
8695 | T := RTE (RE_Dispatching_Domain); | |
9dc88aea | 8696 | |
d9f6a4ee | 8697 | when Aspect_External_Tag => |
8698 | T := Standard_String; | |
9dc88aea | 8699 | |
d9f6a4ee | 8700 | when Aspect_External_Name => |
8701 | T := Standard_String; | |
9dc88aea | 8702 | |
d9f6a4ee | 8703 | -- Global is a delayed aspect because it may reference names that |
8704 | -- have not been declared yet. There is no action to be taken with | |
8705 | -- respect to the aspect itself as the reference checking is done | |
8706 | -- on the corresponding pragma. | |
9dc88aea | 8707 | |
d9f6a4ee | 8708 | when Aspect_Global => |
8709 | return; | |
9dc88aea | 8710 | |
d9f6a4ee | 8711 | when Aspect_Link_Name => |
8712 | T := Standard_String; | |
9dc88aea | 8713 | |
d9f6a4ee | 8714 | when Aspect_Priority | Aspect_Interrupt_Priority => |
8715 | T := Standard_Integer; | |
d97beb2f | 8716 | |
d9f6a4ee | 8717 | when Aspect_Relative_Deadline => |
8718 | T := RTE (RE_Time_Span); | |
d97beb2f | 8719 | |
d9f6a4ee | 8720 | when Aspect_Small => |
8721 | T := Universal_Real; | |
490beba6 | 8722 | |
d9f6a4ee | 8723 | -- For a simple storage pool, we have to retrieve the type of the |
8724 | -- pool object associated with the aspect's corresponding attribute | |
8725 | -- definition clause. | |
490beba6 | 8726 | |
d9f6a4ee | 8727 | when Aspect_Simple_Storage_Pool => |
8728 | T := Etype (Expression (Aspect_Rep_Item (ASN))); | |
d97beb2f | 8729 | |
d9f6a4ee | 8730 | when Aspect_Storage_Pool => |
8731 | T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); | |
d97beb2f | 8732 | |
d9f6a4ee | 8733 | when Aspect_Alignment | |
8734 | Aspect_Component_Size | | |
8735 | Aspect_Machine_Radix | | |
8736 | Aspect_Object_Size | | |
8737 | Aspect_Size | | |
8738 | Aspect_Storage_Size | | |
8739 | Aspect_Stream_Size | | |
8740 | Aspect_Value_Size => | |
8741 | T := Any_Integer; | |
9dc88aea | 8742 | |
04ae062f | 8743 | when Aspect_Linker_Section => |
8744 | T := Standard_String; | |
8745 | ||
d9f6a4ee | 8746 | when Aspect_Synchronization => |
8747 | return; | |
7d20685d | 8748 | |
d9f6a4ee | 8749 | -- Special case, the expression of these aspects is just an entity |
8750 | -- that does not need any resolution, so just analyze. | |
7d20685d | 8751 | |
d9f6a4ee | 8752 | when Aspect_Input | |
8753 | Aspect_Output | | |
8754 | Aspect_Read | | |
8755 | Aspect_Suppress | | |
8756 | Aspect_Unsuppress | | |
8757 | Aspect_Warnings | | |
8758 | Aspect_Write => | |
8759 | Analyze (Expression (ASN)); | |
8760 | return; | |
7d20685d | 8761 | |
d9f6a4ee | 8762 | -- Same for Iterator aspects, where the expression is a function |
8763 | -- name. Legality rules are checked separately. | |
89f1e35c | 8764 | |
d9f6a4ee | 8765 | when Aspect_Constant_Indexing | |
8766 | Aspect_Default_Iterator | | |
8767 | Aspect_Iterator_Element | | |
8768 | Aspect_Variable_Indexing => | |
8769 | Analyze (Expression (ASN)); | |
8770 | return; | |
7d20685d | 8771 | |
b3f8228a | 8772 | -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect. |
8773 | ||
8774 | when Aspect_Iterable => | |
3061ffde | 8775 | T := Entity (ASN); |
8776 | ||
b3f8228a | 8777 | declare |
a9f5fea7 | 8778 | Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T); |
3061ffde | 8779 | Assoc : Node_Id; |
8780 | Expr : Node_Id; | |
a9f5fea7 | 8781 | |
b3f8228a | 8782 | begin |
a9f5fea7 | 8783 | if Cursor = Any_Type then |
8784 | return; | |
8785 | end if; | |
8786 | ||
b3f8228a | 8787 | Assoc := First (Component_Associations (Expression (ASN))); |
8788 | while Present (Assoc) loop | |
3061ffde | 8789 | Expr := Expression (Assoc); |
8790 | Analyze (Expr); | |
a9f5fea7 | 8791 | |
8792 | if not Error_Posted (Expr) then | |
8793 | Resolve_Iterable_Operation | |
8794 | (Expr, Cursor, T, Chars (First (Choices (Assoc)))); | |
8795 | end if; | |
8796 | ||
b3f8228a | 8797 | Next (Assoc); |
8798 | end loop; | |
8799 | end; | |
3061ffde | 8800 | |
b3f8228a | 8801 | return; |
8802 | ||
d9f6a4ee | 8803 | -- Invariant/Predicate take boolean expressions |
7d20685d | 8804 | |
d9f6a4ee | 8805 | when Aspect_Dynamic_Predicate | |
8806 | Aspect_Invariant | | |
8807 | Aspect_Predicate | | |
8808 | Aspect_Static_Predicate | | |
8809 | Aspect_Type_Invariant => | |
8810 | T := Standard_Boolean; | |
7d20685d | 8811 | |
d9f6a4ee | 8812 | -- Here is the list of aspects that don't require delay analysis |
89f1e35c | 8813 | |
ec6f6da5 | 8814 | when Aspect_Abstract_State | |
8815 | Aspect_Annotate | | |
8816 | Aspect_Contract_Cases | | |
8817 | Aspect_Default_Initial_Condition | | |
8818 | Aspect_Dimension | | |
8819 | Aspect_Dimension_System | | |
8820 | Aspect_Implicit_Dereference | | |
8821 | Aspect_Initial_Condition | | |
8822 | Aspect_Initializes | | |
1fd4313f | 8823 | Aspect_Obsolescent | |
ec6f6da5 | 8824 | Aspect_Part_Of | |
8825 | Aspect_Post | | |
8826 | Aspect_Postcondition | | |
8827 | Aspect_Pre | | |
8828 | Aspect_Precondition | | |
8829 | Aspect_Refined_Depends | | |
8830 | Aspect_Refined_Global | | |
8831 | Aspect_Refined_Post | | |
8832 | Aspect_Refined_State | | |
8833 | Aspect_SPARK_Mode | | |
8834 | Aspect_Test_Case => | |
d9f6a4ee | 8835 | raise Program_Error; |
2b184b2f | 8836 | |
d9f6a4ee | 8837 | end case; |
2b184b2f | 8838 | |
d9f6a4ee | 8839 | -- Do the preanalyze call |
2b184b2f | 8840 | |
d9f6a4ee | 8841 | Preanalyze_Spec_Expression (Expression (ASN), T); |
8842 | end Check_Aspect_At_Freeze_Point; | |
2b184b2f | 8843 | |
d9f6a4ee | 8844 | ----------------------------------- |
8845 | -- Check_Constant_Address_Clause -- | |
8846 | ----------------------------------- | |
2b184b2f | 8847 | |
d9f6a4ee | 8848 | procedure Check_Constant_Address_Clause |
8849 | (Expr : Node_Id; | |
8850 | U_Ent : Entity_Id) | |
8851 | is | |
8852 | procedure Check_At_Constant_Address (Nod : Node_Id); | |
8853 | -- Checks that the given node N represents a name whose 'Address is | |
8854 | -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the | |
8855 | -- address value is the same at the point of declaration of U_Ent and at | |
8856 | -- the time of elaboration of the address clause. | |
84ed7523 | 8857 | |
d9f6a4ee | 8858 | procedure Check_Expr_Constants (Nod : Node_Id); |
8859 | -- Checks that Nod meets the requirements for a constant address clause | |
8860 | -- in the sense of the enclosing procedure. | |
84ed7523 | 8861 | |
d9f6a4ee | 8862 | procedure Check_List_Constants (Lst : List_Id); |
8863 | -- Check that all elements of list Lst meet the requirements for a | |
8864 | -- constant address clause in the sense of the enclosing procedure. | |
84ed7523 | 8865 | |
d9f6a4ee | 8866 | ------------------------------- |
8867 | -- Check_At_Constant_Address -- | |
8868 | ------------------------------- | |
84ed7523 | 8869 | |
d9f6a4ee | 8870 | procedure Check_At_Constant_Address (Nod : Node_Id) is |
8871 | begin | |
8872 | if Is_Entity_Name (Nod) then | |
8873 | if Present (Address_Clause (Entity ((Nod)))) then | |
8874 | Error_Msg_NE | |
8875 | ("invalid address clause for initialized object &!", | |
8876 | Nod, U_Ent); | |
8877 | Error_Msg_NE | |
8878 | ("address for& cannot" & | |
8879 | " depend on another address clause! (RM 13.1(22))!", | |
8880 | Nod, U_Ent); | |
84ed7523 | 8881 | |
d9f6a4ee | 8882 | elsif In_Same_Source_Unit (Entity (Nod), U_Ent) |
8883 | and then Sloc (U_Ent) < Sloc (Entity (Nod)) | |
8884 | then | |
8885 | Error_Msg_NE | |
8886 | ("invalid address clause for initialized object &!", | |
8887 | Nod, U_Ent); | |
8888 | Error_Msg_Node_2 := U_Ent; | |
8889 | Error_Msg_NE | |
8890 | ("\& must be defined before & (RM 13.1(22))!", | |
8891 | Nod, Entity (Nod)); | |
8892 | end if; | |
7d20685d | 8893 | |
d9f6a4ee | 8894 | elsif Nkind (Nod) = N_Selected_Component then |
8895 | declare | |
8896 | T : constant Entity_Id := Etype (Prefix (Nod)); | |
59f3e675 | 8897 | |
d9f6a4ee | 8898 | begin |
8899 | if (Is_Record_Type (T) | |
8900 | and then Has_Discriminants (T)) | |
8901 | or else | |
8902 | (Is_Access_Type (T) | |
f02a9a9a | 8903 | and then Is_Record_Type (Designated_Type (T)) |
8904 | and then Has_Discriminants (Designated_Type (T))) | |
d9f6a4ee | 8905 | then |
8906 | Error_Msg_NE | |
8907 | ("invalid address clause for initialized object &!", | |
8908 | Nod, U_Ent); | |
8909 | Error_Msg_N | |
8910 | ("\address cannot depend on component" & | |
8911 | " of discriminated record (RM 13.1(22))!", | |
8912 | Nod); | |
8913 | else | |
8914 | Check_At_Constant_Address (Prefix (Nod)); | |
8915 | end if; | |
8916 | end; | |
89cc7147 | 8917 | |
d9f6a4ee | 8918 | elsif Nkind (Nod) = N_Indexed_Component then |
8919 | Check_At_Constant_Address (Prefix (Nod)); | |
8920 | Check_List_Constants (Expressions (Nod)); | |
89cc7147 | 8921 | |
84ed7523 | 8922 | else |
d9f6a4ee | 8923 | Check_Expr_Constants (Nod); |
84ed7523 | 8924 | end if; |
d9f6a4ee | 8925 | end Check_At_Constant_Address; |
81b424ac | 8926 | |
d9f6a4ee | 8927 | -------------------------- |
8928 | -- Check_Expr_Constants -- | |
8929 | -------------------------- | |
7b9b2f05 | 8930 | |
d9f6a4ee | 8931 | procedure Check_Expr_Constants (Nod : Node_Id) is |
8932 | Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent); | |
8933 | Ent : Entity_Id := Empty; | |
7b9b2f05 | 8934 | |
d9f6a4ee | 8935 | begin |
8936 | if Nkind (Nod) in N_Has_Etype | |
8937 | and then Etype (Nod) = Any_Type | |
7b9b2f05 | 8938 | then |
d9f6a4ee | 8939 | return; |
309c3053 | 8940 | end if; |
8941 | ||
d9f6a4ee | 8942 | case Nkind (Nod) is |
8943 | when N_Empty | N_Error => | |
8944 | return; | |
7d20685d | 8945 | |
d9f6a4ee | 8946 | when N_Identifier | N_Expanded_Name => |
8947 | Ent := Entity (Nod); | |
7d20685d | 8948 | |
d9f6a4ee | 8949 | -- We need to look at the original node if it is different |
8950 | -- from the node, since we may have rewritten things and | |
8951 | -- substituted an identifier representing the rewrite. | |
7d20685d | 8952 | |
d9f6a4ee | 8953 | if Original_Node (Nod) /= Nod then |
8954 | Check_Expr_Constants (Original_Node (Nod)); | |
7d20685d | 8955 | |
d9f6a4ee | 8956 | -- If the node is an object declaration without initial |
8957 | -- value, some code has been expanded, and the expression | |
8958 | -- is not constant, even if the constituents might be | |
8959 | -- acceptable, as in A'Address + offset. | |
7d20685d | 8960 | |
d9f6a4ee | 8961 | if Ekind (Ent) = E_Variable |
8962 | and then | |
8963 | Nkind (Declaration_Node (Ent)) = N_Object_Declaration | |
8964 | and then | |
8965 | No (Expression (Declaration_Node (Ent))) | |
8966 | then | |
8967 | Error_Msg_NE | |
8968 | ("invalid address clause for initialized object &!", | |
8969 | Nod, U_Ent); | |
89f1e35c | 8970 | |
d9f6a4ee | 8971 | -- If entity is constant, it may be the result of expanding |
8972 | -- a check. We must verify that its declaration appears | |
8973 | -- before the object in question, else we also reject the | |
8974 | -- address clause. | |
7d20685d | 8975 | |
d9f6a4ee | 8976 | elsif Ekind (Ent) = E_Constant |
8977 | and then In_Same_Source_Unit (Ent, U_Ent) | |
8978 | and then Sloc (Ent) > Loc_U_Ent | |
8979 | then | |
8980 | Error_Msg_NE | |
8981 | ("invalid address clause for initialized object &!", | |
8982 | Nod, U_Ent); | |
8983 | end if; | |
7d20685d | 8984 | |
d9f6a4ee | 8985 | return; |
8986 | end if; | |
7d20685d | 8987 | |
d9f6a4ee | 8988 | -- Otherwise look at the identifier and see if it is OK |
7d20685d | 8989 | |
d9f6a4ee | 8990 | if Ekind_In (Ent, E_Named_Integer, E_Named_Real) |
8991 | or else Is_Type (Ent) | |
8992 | then | |
8993 | return; | |
7d20685d | 8994 | |
f02a9a9a | 8995 | elsif Ekind_In (Ent, E_Constant, E_In_Parameter) then |
8996 | ||
d9f6a4ee | 8997 | -- This is the case where we must have Ent defined before |
8998 | -- U_Ent. Clearly if they are in different units this | |
8999 | -- requirement is met since the unit containing Ent is | |
9000 | -- already processed. | |
7d20685d | 9001 | |
d9f6a4ee | 9002 | if not In_Same_Source_Unit (Ent, U_Ent) then |
9003 | return; | |
7d20685d | 9004 | |
d9f6a4ee | 9005 | -- Otherwise location of Ent must be before the location |
9006 | -- of U_Ent, that's what prior defined means. | |
7d20685d | 9007 | |
d9f6a4ee | 9008 | elsif Sloc (Ent) < Loc_U_Ent then |
9009 | return; | |
6c545057 | 9010 | |
d9f6a4ee | 9011 | else |
9012 | Error_Msg_NE | |
9013 | ("invalid address clause for initialized object &!", | |
9014 | Nod, U_Ent); | |
9015 | Error_Msg_Node_2 := U_Ent; | |
9016 | Error_Msg_NE | |
9017 | ("\& must be defined before & (RM 13.1(22))!", | |
9018 | Nod, Ent); | |
9019 | end if; | |
37c6e44c | 9020 | |
d9f6a4ee | 9021 | elsif Nkind (Original_Node (Nod)) = N_Function_Call then |
9022 | Check_Expr_Constants (Original_Node (Nod)); | |
6c545057 | 9023 | |
d9f6a4ee | 9024 | else |
9025 | Error_Msg_NE | |
9026 | ("invalid address clause for initialized object &!", | |
9027 | Nod, U_Ent); | |
3cdbaa5a | 9028 | |
d9f6a4ee | 9029 | if Comes_From_Source (Ent) then |
9030 | Error_Msg_NE | |
9031 | ("\reference to variable& not allowed" | |
9032 | & " (RM 13.1(22))!", Nod, Ent); | |
9033 | else | |
9034 | Error_Msg_N | |
9035 | ("non-static expression not allowed" | |
9036 | & " (RM 13.1(22))!", Nod); | |
9037 | end if; | |
9038 | end if; | |
3cdbaa5a | 9039 | |
d9f6a4ee | 9040 | when N_Integer_Literal => |
7f694ca2 | 9041 | |
d9f6a4ee | 9042 | -- If this is a rewritten unchecked conversion, in a system |
9043 | -- where Address is an integer type, always use the base type | |
9044 | -- for a literal value. This is user-friendly and prevents | |
9045 | -- order-of-elaboration issues with instances of unchecked | |
9046 | -- conversion. | |
3cdbaa5a | 9047 | |
d9f6a4ee | 9048 | if Nkind (Original_Node (Nod)) = N_Function_Call then |
9049 | Set_Etype (Nod, Base_Type (Etype (Nod))); | |
9050 | end if; | |
e1cedbae | 9051 | |
d9f6a4ee | 9052 | when N_Real_Literal | |
9053 | N_String_Literal | | |
9054 | N_Character_Literal => | |
9055 | return; | |
7d20685d | 9056 | |
d9f6a4ee | 9057 | when N_Range => |
9058 | Check_Expr_Constants (Low_Bound (Nod)); | |
9059 | Check_Expr_Constants (High_Bound (Nod)); | |
231eb581 | 9060 | |
d9f6a4ee | 9061 | when N_Explicit_Dereference => |
9062 | Check_Expr_Constants (Prefix (Nod)); | |
231eb581 | 9063 | |
d9f6a4ee | 9064 | when N_Indexed_Component => |
9065 | Check_Expr_Constants (Prefix (Nod)); | |
9066 | Check_List_Constants (Expressions (Nod)); | |
7d20685d | 9067 | |
d9f6a4ee | 9068 | when N_Slice => |
9069 | Check_Expr_Constants (Prefix (Nod)); | |
9070 | Check_Expr_Constants (Discrete_Range (Nod)); | |
cb4c311d | 9071 | |
d9f6a4ee | 9072 | when N_Selected_Component => |
9073 | Check_Expr_Constants (Prefix (Nod)); | |
6144c105 | 9074 | |
d9f6a4ee | 9075 | when N_Attribute_Reference => |
9076 | if Nam_In (Attribute_Name (Nod), Name_Address, | |
9077 | Name_Access, | |
9078 | Name_Unchecked_Access, | |
9079 | Name_Unrestricted_Access) | |
9080 | then | |
9081 | Check_At_Constant_Address (Prefix (Nod)); | |
6144c105 | 9082 | |
d9f6a4ee | 9083 | else |
9084 | Check_Expr_Constants (Prefix (Nod)); | |
9085 | Check_List_Constants (Expressions (Nod)); | |
9086 | end if; | |
a7a4a7c2 | 9087 | |
d9f6a4ee | 9088 | when N_Aggregate => |
9089 | Check_List_Constants (Component_Associations (Nod)); | |
9090 | Check_List_Constants (Expressions (Nod)); | |
7d20685d | 9091 | |
d9f6a4ee | 9092 | when N_Component_Association => |
9093 | Check_Expr_Constants (Expression (Nod)); | |
e1cedbae | 9094 | |
d9f6a4ee | 9095 | when N_Extension_Aggregate => |
9096 | Check_Expr_Constants (Ancestor_Part (Nod)); | |
9097 | Check_List_Constants (Component_Associations (Nod)); | |
9098 | Check_List_Constants (Expressions (Nod)); | |
3cdbaa5a | 9099 | |
d9f6a4ee | 9100 | when N_Null => |
9101 | return; | |
3cdbaa5a | 9102 | |
d9f6a4ee | 9103 | when N_Binary_Op | N_Short_Circuit | N_Membership_Test => |
9104 | Check_Expr_Constants (Left_Opnd (Nod)); | |
9105 | Check_Expr_Constants (Right_Opnd (Nod)); | |
e1cedbae | 9106 | |
d9f6a4ee | 9107 | when N_Unary_Op => |
9108 | Check_Expr_Constants (Right_Opnd (Nod)); | |
7f694ca2 | 9109 | |
d9f6a4ee | 9110 | when N_Type_Conversion | |
9111 | N_Qualified_Expression | | |
9112 | N_Allocator | | |
9113 | N_Unchecked_Type_Conversion => | |
9114 | Check_Expr_Constants (Expression (Nod)); | |
47a46747 | 9115 | |
d9f6a4ee | 9116 | when N_Function_Call => |
9117 | if not Is_Pure (Entity (Name (Nod))) then | |
9118 | Error_Msg_NE | |
9119 | ("invalid address clause for initialized object &!", | |
9120 | Nod, U_Ent); | |
7f694ca2 | 9121 | |
d9f6a4ee | 9122 | Error_Msg_NE |
9123 | ("\function & is not pure (RM 13.1(22))!", | |
9124 | Nod, Entity (Name (Nod))); | |
b55f7641 | 9125 | |
d9f6a4ee | 9126 | else |
9127 | Check_List_Constants (Parameter_Associations (Nod)); | |
9128 | end if; | |
b55f7641 | 9129 | |
d9f6a4ee | 9130 | when N_Parameter_Association => |
9131 | Check_Expr_Constants (Explicit_Actual_Parameter (Nod)); | |
7d20685d | 9132 | |
d9f6a4ee | 9133 | when others => |
9134 | Error_Msg_NE | |
9135 | ("invalid address clause for initialized object &!", | |
9136 | Nod, U_Ent); | |
9137 | Error_Msg_NE | |
9138 | ("\must be constant defined before& (RM 13.1(22))!", | |
9139 | Nod, U_Ent); | |
9140 | end case; | |
9141 | end Check_Expr_Constants; | |
7d20685d | 9142 | |
d9f6a4ee | 9143 | -------------------------- |
9144 | -- Check_List_Constants -- | |
9145 | -------------------------- | |
89f1e35c | 9146 | |
d9f6a4ee | 9147 | procedure Check_List_Constants (Lst : List_Id) is |
9148 | Nod1 : Node_Id; | |
7d20685d | 9149 | |
d9f6a4ee | 9150 | begin |
9151 | if Present (Lst) then | |
9152 | Nod1 := First (Lst); | |
9153 | while Present (Nod1) loop | |
9154 | Check_Expr_Constants (Nod1); | |
9155 | Next (Nod1); | |
9156 | end loop; | |
9157 | end if; | |
9158 | end Check_List_Constants; | |
81b424ac | 9159 | |
d9f6a4ee | 9160 | -- Start of processing for Check_Constant_Address_Clause |
81b424ac | 9161 | |
d9f6a4ee | 9162 | begin |
9163 | -- If rep_clauses are to be ignored, no need for legality checks. In | |
9164 | -- particular, no need to pester user about rep clauses that violate | |
9165 | -- the rule on constant addresses, given that these clauses will be | |
9166 | -- removed by Freeze before they reach the back end. | |
7d20685d | 9167 | |
d9f6a4ee | 9168 | if not Ignore_Rep_Clauses then |
9169 | Check_Expr_Constants (Expr); | |
9170 | end if; | |
9171 | end Check_Constant_Address_Clause; | |
7d20685d | 9172 | |
6653b695 | 9173 | --------------------------- |
9174 | -- Check_Pool_Size_Clash -- | |
9175 | --------------------------- | |
9176 | ||
9177 | procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is | |
9178 | Post : Node_Id; | |
9179 | ||
9180 | begin | |
9181 | -- We need to find out which one came first. Note that in the case of | |
9182 | -- aspects mixed with pragmas there are cases where the processing order | |
9183 | -- is reversed, which is why we do the check here. | |
9184 | ||
9185 | if Sloc (SP) < Sloc (SS) then | |
9186 | Error_Msg_Sloc := Sloc (SP); | |
9187 | Post := SS; | |
9188 | Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent); | |
9189 | ||
9190 | else | |
9191 | Error_Msg_Sloc := Sloc (SS); | |
9192 | Post := SP; | |
9193 | Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent); | |
9194 | end if; | |
9195 | ||
9196 | Error_Msg_N | |
9197 | ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post); | |
9198 | end Check_Pool_Size_Clash; | |
9199 | ||
d9f6a4ee | 9200 | ---------------------------------------- |
9201 | -- Check_Record_Representation_Clause -- | |
9202 | ---------------------------------------- | |
85696508 | 9203 | |
d9f6a4ee | 9204 | procedure Check_Record_Representation_Clause (N : Node_Id) is |
9205 | Loc : constant Source_Ptr := Sloc (N); | |
9206 | Ident : constant Node_Id := Identifier (N); | |
9207 | Rectype : Entity_Id; | |
9208 | Fent : Entity_Id; | |
9209 | CC : Node_Id; | |
9210 | Fbit : Uint; | |
9211 | Lbit : Uint; | |
9212 | Hbit : Uint := Uint_0; | |
9213 | Comp : Entity_Id; | |
9214 | Pcomp : Entity_Id; | |
89f1e35c | 9215 | |
d9f6a4ee | 9216 | Max_Bit_So_Far : Uint; |
9217 | -- Records the maximum bit position so far. If all field positions | |
9218 | -- are monotonically increasing, then we can skip the circuit for | |
9219 | -- checking for overlap, since no overlap is possible. | |
85696508 | 9220 | |
d9f6a4ee | 9221 | Tagged_Parent : Entity_Id := Empty; |
9222 | -- This is set in the case of a derived tagged type for which we have | |
9223 | -- Is_Fully_Repped_Tagged_Type True (indicating that all components are | |
9224 | -- positioned by record representation clauses). In this case we must | |
9225 | -- check for overlap between components of this tagged type, and the | |
9226 | -- components of its parent. Tagged_Parent will point to this parent | |
9227 | -- type. For all other cases Tagged_Parent is left set to Empty. | |
7d20685d | 9228 | |
d9f6a4ee | 9229 | Parent_Last_Bit : Uint; |
9230 | -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the | |
9231 | -- last bit position for any field in the parent type. We only need to | |
9232 | -- check overlap for fields starting below this point. | |
7d20685d | 9233 | |
d9f6a4ee | 9234 | Overlap_Check_Required : Boolean; |
9235 | -- Used to keep track of whether or not an overlap check is required | |
7d20685d | 9236 | |
d9f6a4ee | 9237 | Overlap_Detected : Boolean := False; |
9238 | -- Set True if an overlap is detected | |
d6f39728 | 9239 | |
d9f6a4ee | 9240 | Ccount : Natural := 0; |
9241 | -- Number of component clauses in record rep clause | |
d6f39728 | 9242 | |
d9f6a4ee | 9243 | procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id); |
9244 | -- Given two entities for record components or discriminants, checks | |
9245 | -- if they have overlapping component clauses and issues errors if so. | |
d6f39728 | 9246 | |
d9f6a4ee | 9247 | procedure Find_Component; |
9248 | -- Finds component entity corresponding to current component clause (in | |
9249 | -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin | |
9250 | -- start/stop bits for the field. If there is no matching component or | |
9251 | -- if the matching component does not have a component clause, then | |
9252 | -- that's an error and Comp is set to Empty, but no error message is | |
9253 | -- issued, since the message was already given. Comp is also set to | |
9254 | -- Empty if the current "component clause" is in fact a pragma. | |
d6f39728 | 9255 | |
d9f6a4ee | 9256 | ----------------------------- |
9257 | -- Check_Component_Overlap -- | |
9258 | ----------------------------- | |
9259 | ||
9260 | procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is | |
9261 | CC1 : constant Node_Id := Component_Clause (C1_Ent); | |
9262 | CC2 : constant Node_Id := Component_Clause (C2_Ent); | |
d6f39728 | 9263 | |
d6f39728 | 9264 | begin |
d9f6a4ee | 9265 | if Present (CC1) and then Present (CC2) then |
d6f39728 | 9266 | |
d9f6a4ee | 9267 | -- Exclude odd case where we have two tag components in the same |
9268 | -- record, both at location zero. This seems a bit strange, but | |
9269 | -- it seems to happen in some circumstances, perhaps on an error. | |
9270 | ||
9271 | if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then | |
9272 | return; | |
d6f39728 | 9273 | end if; |
9274 | ||
d9f6a4ee | 9275 | -- Here we check if the two fields overlap |
9276 | ||
d6f39728 | 9277 | declare |
d9f6a4ee | 9278 | S1 : constant Uint := Component_Bit_Offset (C1_Ent); |
9279 | S2 : constant Uint := Component_Bit_Offset (C2_Ent); | |
9280 | E1 : constant Uint := S1 + Esize (C1_Ent); | |
9281 | E2 : constant Uint := S2 + Esize (C2_Ent); | |
d6f39728 | 9282 | |
9283 | begin | |
d9f6a4ee | 9284 | if E2 <= S1 or else E1 <= S2 then |
9285 | null; | |
d6f39728 | 9286 | else |
d9f6a4ee | 9287 | Error_Msg_Node_2 := Component_Name (CC2); |
9288 | Error_Msg_Sloc := Sloc (Error_Msg_Node_2); | |
9289 | Error_Msg_Node_1 := Component_Name (CC1); | |
9290 | Error_Msg_N | |
9291 | ("component& overlaps & #", Component_Name (CC1)); | |
9292 | Overlap_Detected := True; | |
d6f39728 | 9293 | end if; |
9294 | end; | |
d6f39728 | 9295 | end if; |
d9f6a4ee | 9296 | end Check_Component_Overlap; |
d6f39728 | 9297 | |
d9f6a4ee | 9298 | -------------------- |
9299 | -- Find_Component -- | |
9300 | -------------------- | |
9dfe12ae | 9301 | |
d9f6a4ee | 9302 | procedure Find_Component is |
9dfe12ae | 9303 | |
d9f6a4ee | 9304 | procedure Search_Component (R : Entity_Id); |
9305 | -- Search components of R for a match. If found, Comp is set | |
9dfe12ae | 9306 | |
d9f6a4ee | 9307 | ---------------------- |
9308 | -- Search_Component -- | |
9309 | ---------------------- | |
e7b2d6bc | 9310 | |
d9f6a4ee | 9311 | procedure Search_Component (R : Entity_Id) is |
9312 | begin | |
9313 | Comp := First_Component_Or_Discriminant (R); | |
9314 | while Present (Comp) loop | |
e7b2d6bc | 9315 | |
d9f6a4ee | 9316 | -- Ignore error of attribute name for component name (we |
9317 | -- already gave an error message for this, so no need to | |
9318 | -- complain here) | |
e7b2d6bc | 9319 | |
d9f6a4ee | 9320 | if Nkind (Component_Name (CC)) = N_Attribute_Reference then |
9321 | null; | |
9322 | else | |
9323 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
9dfe12ae | 9324 | end if; |
9325 | ||
d9f6a4ee | 9326 | Next_Component_Or_Discriminant (Comp); |
9327 | end loop; | |
9328 | end Search_Component; | |
d6f39728 | 9329 | |
d9f6a4ee | 9330 | -- Start of processing for Find_Component |
d6f39728 | 9331 | |
d9f6a4ee | 9332 | begin |
9333 | -- Return with Comp set to Empty if we have a pragma | |
d6f39728 | 9334 | |
d9f6a4ee | 9335 | if Nkind (CC) = N_Pragma then |
9336 | Comp := Empty; | |
9337 | return; | |
9338 | end if; | |
d6f39728 | 9339 | |
d9f6a4ee | 9340 | -- Search current record for matching component |
d6f39728 | 9341 | |
d9f6a4ee | 9342 | Search_Component (Rectype); |
9dfe12ae | 9343 | |
d9f6a4ee | 9344 | -- If not found, maybe component of base type discriminant that is |
9345 | -- absent from statically constrained first subtype. | |
e7b2d6bc | 9346 | |
d9f6a4ee | 9347 | if No (Comp) then |
9348 | Search_Component (Base_Type (Rectype)); | |
9349 | end if; | |
e7b2d6bc | 9350 | |
d9f6a4ee | 9351 | -- If no component, or the component does not reference the component |
9352 | -- clause in question, then there was some previous error for which | |
9353 | -- we already gave a message, so just return with Comp Empty. | |
d6f39728 | 9354 | |
d9f6a4ee | 9355 | if No (Comp) or else Component_Clause (Comp) /= CC then |
9356 | Check_Error_Detected; | |
9357 | Comp := Empty; | |
93735cb8 | 9358 | |
d9f6a4ee | 9359 | -- Normal case where we have a component clause |
93735cb8 | 9360 | |
d9f6a4ee | 9361 | else |
9362 | Fbit := Component_Bit_Offset (Comp); | |
9363 | Lbit := Fbit + Esize (Comp) - 1; | |
9364 | end if; | |
9365 | end Find_Component; | |
93735cb8 | 9366 | |
d9f6a4ee | 9367 | -- Start of processing for Check_Record_Representation_Clause |
d6f39728 | 9368 | |
d9f6a4ee | 9369 | begin |
9370 | Find_Type (Ident); | |
9371 | Rectype := Entity (Ident); | |
d6f39728 | 9372 | |
d9f6a4ee | 9373 | if Rectype = Any_Type then |
9374 | return; | |
9375 | else | |
9376 | Rectype := Underlying_Type (Rectype); | |
9377 | end if; | |
d6f39728 | 9378 | |
d9f6a4ee | 9379 | -- See if we have a fully repped derived tagged type |
d6f39728 | 9380 | |
d9f6a4ee | 9381 | declare |
9382 | PS : constant Entity_Id := Parent_Subtype (Rectype); | |
d6f39728 | 9383 | |
d9f6a4ee | 9384 | begin |
9385 | if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then | |
9386 | Tagged_Parent := PS; | |
d6f39728 | 9387 | |
d9f6a4ee | 9388 | -- Find maximum bit of any component of the parent type |
d6f39728 | 9389 | |
d9f6a4ee | 9390 | Parent_Last_Bit := UI_From_Int (System_Address_Size - 1); |
9391 | Pcomp := First_Entity (Tagged_Parent); | |
9392 | while Present (Pcomp) loop | |
9393 | if Ekind_In (Pcomp, E_Discriminant, E_Component) then | |
9394 | if Component_Bit_Offset (Pcomp) /= No_Uint | |
9395 | and then Known_Static_Esize (Pcomp) | |
9396 | then | |
9397 | Parent_Last_Bit := | |
9398 | UI_Max | |
9399 | (Parent_Last_Bit, | |
9400 | Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1); | |
9401 | end if; | |
9402 | ||
9403 | Next_Entity (Pcomp); | |
d6f39728 | 9404 | end if; |
d9f6a4ee | 9405 | end loop; |
9406 | end if; | |
9407 | end; | |
d6f39728 | 9408 | |
d9f6a4ee | 9409 | -- All done if no component clauses |
d6f39728 | 9410 | |
d9f6a4ee | 9411 | CC := First (Component_Clauses (N)); |
d6f39728 | 9412 | |
d9f6a4ee | 9413 | if No (CC) then |
9414 | return; | |
9415 | end if; | |
d6f39728 | 9416 | |
d9f6a4ee | 9417 | -- If a tag is present, then create a component clause that places it |
9418 | -- at the start of the record (otherwise gigi may place it after other | |
9419 | -- fields that have rep clauses). | |
d6f39728 | 9420 | |
d9f6a4ee | 9421 | Fent := First_Entity (Rectype); |
d6f39728 | 9422 | |
d9f6a4ee | 9423 | if Nkind (Fent) = N_Defining_Identifier |
9424 | and then Chars (Fent) = Name_uTag | |
9425 | then | |
9426 | Set_Component_Bit_Offset (Fent, Uint_0); | |
9427 | Set_Normalized_Position (Fent, Uint_0); | |
9428 | Set_Normalized_First_Bit (Fent, Uint_0); | |
9429 | Set_Normalized_Position_Max (Fent, Uint_0); | |
9430 | Init_Esize (Fent, System_Address_Size); | |
d6f39728 | 9431 | |
d9f6a4ee | 9432 | Set_Component_Clause (Fent, |
9433 | Make_Component_Clause (Loc, | |
9434 | Component_Name => Make_Identifier (Loc, Name_uTag), | |
d6f39728 | 9435 | |
d9f6a4ee | 9436 | Position => Make_Integer_Literal (Loc, Uint_0), |
9437 | First_Bit => Make_Integer_Literal (Loc, Uint_0), | |
9438 | Last_Bit => | |
9439 | Make_Integer_Literal (Loc, | |
9440 | UI_From_Int (System_Address_Size)))); | |
d6f39728 | 9441 | |
d9f6a4ee | 9442 | Ccount := Ccount + 1; |
9443 | end if; | |
d6f39728 | 9444 | |
d9f6a4ee | 9445 | Max_Bit_So_Far := Uint_Minus_1; |
9446 | Overlap_Check_Required := False; | |
d6f39728 | 9447 | |
d9f6a4ee | 9448 | -- Process the component clauses |
d6f39728 | 9449 | |
d9f6a4ee | 9450 | while Present (CC) loop |
9451 | Find_Component; | |
d6f39728 | 9452 | |
d9f6a4ee | 9453 | if Present (Comp) then |
9454 | Ccount := Ccount + 1; | |
d6f39728 | 9455 | |
d9f6a4ee | 9456 | -- We need a full overlap check if record positions non-monotonic |
d6f39728 | 9457 | |
d9f6a4ee | 9458 | if Fbit <= Max_Bit_So_Far then |
9459 | Overlap_Check_Required := True; | |
9460 | end if; | |
d6f39728 | 9461 | |
d9f6a4ee | 9462 | Max_Bit_So_Far := Lbit; |
d6f39728 | 9463 | |
d9f6a4ee | 9464 | -- Check bit position out of range of specified size |
01cb2726 | 9465 | |
d9f6a4ee | 9466 | if Has_Size_Clause (Rectype) |
9467 | and then RM_Size (Rectype) <= Lbit | |
9468 | then | |
9469 | Error_Msg_N | |
9470 | ("bit number out of range of specified size", | |
9471 | Last_Bit (CC)); | |
d6f39728 | 9472 | |
d9f6a4ee | 9473 | -- Check for overlap with tag component |
67278d60 | 9474 | |
d9f6a4ee | 9475 | else |
9476 | if Is_Tagged_Type (Rectype) | |
9477 | and then Fbit < System_Address_Size | |
9478 | then | |
9479 | Error_Msg_NE | |
9480 | ("component overlaps tag field of&", | |
9481 | Component_Name (CC), Rectype); | |
9482 | Overlap_Detected := True; | |
9483 | end if; | |
67278d60 | 9484 | |
d9f6a4ee | 9485 | if Hbit < Lbit then |
9486 | Hbit := Lbit; | |
9487 | end if; | |
9488 | end if; | |
67278d60 | 9489 | |
d9f6a4ee | 9490 | -- Check parent overlap if component might overlap parent field |
67278d60 | 9491 | |
d9f6a4ee | 9492 | if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then |
9493 | Pcomp := First_Component_Or_Discriminant (Tagged_Parent); | |
9494 | while Present (Pcomp) loop | |
9495 | if not Is_Tag (Pcomp) | |
9496 | and then Chars (Pcomp) /= Name_uParent | |
9497 | then | |
9498 | Check_Component_Overlap (Comp, Pcomp); | |
9499 | end if; | |
67278d60 | 9500 | |
d9f6a4ee | 9501 | Next_Component_Or_Discriminant (Pcomp); |
9502 | end loop; | |
9503 | end if; | |
9504 | end if; | |
67278d60 | 9505 | |
d9f6a4ee | 9506 | Next (CC); |
9507 | end loop; | |
47495553 | 9508 | |
d9f6a4ee | 9509 | -- Now that we have processed all the component clauses, check for |
9510 | -- overlap. We have to leave this till last, since the components can | |
9511 | -- appear in any arbitrary order in the representation clause. | |
67278d60 | 9512 | |
d9f6a4ee | 9513 | -- We do not need this check if all specified ranges were monotonic, |
9514 | -- as recorded by Overlap_Check_Required being False at this stage. | |
67278d60 | 9515 | |
d9f6a4ee | 9516 | -- This first section checks if there are any overlapping entries at |
9517 | -- all. It does this by sorting all entries and then seeing if there are | |
9518 | -- any overlaps. If there are none, then that is decisive, but if there | |
9519 | -- are overlaps, they may still be OK (they may result from fields in | |
9520 | -- different variants). | |
67278d60 | 9521 | |
d9f6a4ee | 9522 | if Overlap_Check_Required then |
9523 | Overlap_Check1 : declare | |
67278d60 | 9524 | |
d9f6a4ee | 9525 | OC_Fbit : array (0 .. Ccount) of Uint; |
9526 | -- First-bit values for component clauses, the value is the offset | |
9527 | -- of the first bit of the field from start of record. The zero | |
9528 | -- entry is for use in sorting. | |
47495553 | 9529 | |
d9f6a4ee | 9530 | OC_Lbit : array (0 .. Ccount) of Uint; |
9531 | -- Last-bit values for component clauses, the value is the offset | |
9532 | -- of the last bit of the field from start of record. The zero | |
9533 | -- entry is for use in sorting. | |
9534 | ||
9535 | OC_Count : Natural := 0; | |
9536 | -- Count of entries in OC_Fbit and OC_Lbit | |
67278d60 | 9537 | |
d9f6a4ee | 9538 | function OC_Lt (Op1, Op2 : Natural) return Boolean; |
9539 | -- Compare routine for Sort | |
67278d60 | 9540 | |
d9f6a4ee | 9541 | procedure OC_Move (From : Natural; To : Natural); |
9542 | -- Move routine for Sort | |
67278d60 | 9543 | |
d9f6a4ee | 9544 | package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt); |
67278d60 | 9545 | |
d9f6a4ee | 9546 | ----------- |
9547 | -- OC_Lt -- | |
9548 | ----------- | |
67278d60 | 9549 | |
d9f6a4ee | 9550 | function OC_Lt (Op1, Op2 : Natural) return Boolean is |
67278d60 | 9551 | begin |
d9f6a4ee | 9552 | return OC_Fbit (Op1) < OC_Fbit (Op2); |
9553 | end OC_Lt; | |
67278d60 | 9554 | |
d9f6a4ee | 9555 | ------------- |
9556 | -- OC_Move -- | |
9557 | ------------- | |
67278d60 | 9558 | |
d9f6a4ee | 9559 | procedure OC_Move (From : Natural; To : Natural) is |
9560 | begin | |
9561 | OC_Fbit (To) := OC_Fbit (From); | |
9562 | OC_Lbit (To) := OC_Lbit (From); | |
9563 | end OC_Move; | |
67278d60 | 9564 | |
d9f6a4ee | 9565 | -- Start of processing for Overlap_Check |
67278d60 | 9566 | |
67278d60 | 9567 | begin |
d9f6a4ee | 9568 | CC := First (Component_Clauses (N)); |
9569 | while Present (CC) loop | |
67278d60 | 9570 | |
d9f6a4ee | 9571 | -- Exclude component clause already marked in error |
67278d60 | 9572 | |
d9f6a4ee | 9573 | if not Error_Posted (CC) then |
9574 | Find_Component; | |
9575 | ||
9576 | if Present (Comp) then | |
9577 | OC_Count := OC_Count + 1; | |
9578 | OC_Fbit (OC_Count) := Fbit; | |
9579 | OC_Lbit (OC_Count) := Lbit; | |
9580 | end if; | |
67278d60 | 9581 | end if; |
9582 | ||
d9f6a4ee | 9583 | Next (CC); |
67278d60 | 9584 | end loop; |
67278d60 | 9585 | |
d9f6a4ee | 9586 | Sorting.Sort (OC_Count); |
67278d60 | 9587 | |
d9f6a4ee | 9588 | Overlap_Check_Required := False; |
9589 | for J in 1 .. OC_Count - 1 loop | |
9590 | if OC_Lbit (J) >= OC_Fbit (J + 1) then | |
9591 | Overlap_Check_Required := True; | |
9592 | exit; | |
9593 | end if; | |
9594 | end loop; | |
9595 | end Overlap_Check1; | |
9596 | end if; | |
67278d60 | 9597 | |
d9f6a4ee | 9598 | -- If Overlap_Check_Required is still True, then we have to do the full |
9599 | -- scale overlap check, since we have at least two fields that do | |
9600 | -- overlap, and we need to know if that is OK since they are in | |
9601 | -- different variant, or whether we have a definite problem. | |
67278d60 | 9602 | |
d9f6a4ee | 9603 | if Overlap_Check_Required then |
9604 | Overlap_Check2 : declare | |
9605 | C1_Ent, C2_Ent : Entity_Id; | |
9606 | -- Entities of components being checked for overlap | |
67278d60 | 9607 | |
d9f6a4ee | 9608 | Clist : Node_Id; |
9609 | -- Component_List node whose Component_Items are being checked | |
67278d60 | 9610 | |
d9f6a4ee | 9611 | Citem : Node_Id; |
9612 | -- Component declaration for component being checked | |
67278d60 | 9613 | |
d9f6a4ee | 9614 | begin |
9615 | C1_Ent := First_Entity (Base_Type (Rectype)); | |
67278d60 | 9616 | |
d9f6a4ee | 9617 | -- Loop through all components in record. For each component check |
9618 | -- for overlap with any of the preceding elements on the component | |
9619 | -- list containing the component and also, if the component is in | |
9620 | -- a variant, check against components outside the case structure. | |
9621 | -- This latter test is repeated recursively up the variant tree. | |
67278d60 | 9622 | |
d9f6a4ee | 9623 | Main_Component_Loop : while Present (C1_Ent) loop |
9624 | if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then | |
9625 | goto Continue_Main_Component_Loop; | |
9626 | end if; | |
67278d60 | 9627 | |
d9f6a4ee | 9628 | -- Skip overlap check if entity has no declaration node. This |
9629 | -- happens with discriminants in constrained derived types. | |
9630 | -- Possibly we are missing some checks as a result, but that | |
9631 | -- does not seem terribly serious. | |
67278d60 | 9632 | |
d9f6a4ee | 9633 | if No (Declaration_Node (C1_Ent)) then |
9634 | goto Continue_Main_Component_Loop; | |
9635 | end if; | |
67278d60 | 9636 | |
d9f6a4ee | 9637 | Clist := Parent (List_Containing (Declaration_Node (C1_Ent))); |
67278d60 | 9638 | |
d9f6a4ee | 9639 | -- Loop through component lists that need checking. Check the |
9640 | -- current component list and all lists in variants above us. | |
67278d60 | 9641 | |
d9f6a4ee | 9642 | Component_List_Loop : loop |
67278d60 | 9643 | |
d9f6a4ee | 9644 | -- If derived type definition, go to full declaration |
9645 | -- If at outer level, check discriminants if there are any. | |
67278d60 | 9646 | |
d9f6a4ee | 9647 | if Nkind (Clist) = N_Derived_Type_Definition then |
9648 | Clist := Parent (Clist); | |
9649 | end if; | |
67278d60 | 9650 | |
d9f6a4ee | 9651 | -- Outer level of record definition, check discriminants |
67278d60 | 9652 | |
d9f6a4ee | 9653 | if Nkind_In (Clist, N_Full_Type_Declaration, |
9654 | N_Private_Type_Declaration) | |
67278d60 | 9655 | then |
d9f6a4ee | 9656 | if Has_Discriminants (Defining_Identifier (Clist)) then |
9657 | C2_Ent := | |
9658 | First_Discriminant (Defining_Identifier (Clist)); | |
9659 | while Present (C2_Ent) loop | |
9660 | exit when C1_Ent = C2_Ent; | |
9661 | Check_Component_Overlap (C1_Ent, C2_Ent); | |
9662 | Next_Discriminant (C2_Ent); | |
9663 | end loop; | |
9664 | end if; | |
67278d60 | 9665 | |
d9f6a4ee | 9666 | -- Record extension case |
67278d60 | 9667 | |
d9f6a4ee | 9668 | elsif Nkind (Clist) = N_Derived_Type_Definition then |
9669 | Clist := Empty; | |
67278d60 | 9670 | |
d9f6a4ee | 9671 | -- Otherwise check one component list |
67278d60 | 9672 | |
d9f6a4ee | 9673 | else |
9674 | Citem := First (Component_Items (Clist)); | |
9675 | while Present (Citem) loop | |
9676 | if Nkind (Citem) = N_Component_Declaration then | |
9677 | C2_Ent := Defining_Identifier (Citem); | |
9678 | exit when C1_Ent = C2_Ent; | |
9679 | Check_Component_Overlap (C1_Ent, C2_Ent); | |
9680 | end if; | |
67278d60 | 9681 | |
d9f6a4ee | 9682 | Next (Citem); |
9683 | end loop; | |
9684 | end if; | |
67278d60 | 9685 | |
d9f6a4ee | 9686 | -- Check for variants above us (the parent of the Clist can |
9687 | -- be a variant, in which case its parent is a variant part, | |
9688 | -- and the parent of the variant part is a component list | |
9689 | -- whose components must all be checked against the current | |
9690 | -- component for overlap). | |
67278d60 | 9691 | |
d9f6a4ee | 9692 | if Nkind (Parent (Clist)) = N_Variant then |
9693 | Clist := Parent (Parent (Parent (Clist))); | |
67278d60 | 9694 | |
d9f6a4ee | 9695 | -- Check for possible discriminant part in record, this |
9696 | -- is treated essentially as another level in the | |
9697 | -- recursion. For this case the parent of the component | |
9698 | -- list is the record definition, and its parent is the | |
9699 | -- full type declaration containing the discriminant | |
9700 | -- specifications. | |
9701 | ||
9702 | elsif Nkind (Parent (Clist)) = N_Record_Definition then | |
9703 | Clist := Parent (Parent ((Clist))); | |
9704 | ||
9705 | -- If neither of these two cases, we are at the top of | |
9706 | -- the tree. | |
9707 | ||
9708 | else | |
9709 | exit Component_List_Loop; | |
9710 | end if; | |
9711 | end loop Component_List_Loop; | |
67278d60 | 9712 | |
d9f6a4ee | 9713 | <<Continue_Main_Component_Loop>> |
9714 | Next_Entity (C1_Ent); | |
67278d60 | 9715 | |
d9f6a4ee | 9716 | end loop Main_Component_Loop; |
9717 | end Overlap_Check2; | |
67278d60 | 9718 | end if; |
9719 | ||
d9f6a4ee | 9720 | -- The following circuit deals with warning on record holes (gaps). We |
9721 | -- skip this check if overlap was detected, since it makes sense for the | |
9722 | -- programmer to fix this illegality before worrying about warnings. | |
67278d60 | 9723 | |
d9f6a4ee | 9724 | if not Overlap_Detected and Warn_On_Record_Holes then |
9725 | Record_Hole_Check : declare | |
9726 | Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype)); | |
9727 | -- Full declaration of record type | |
67278d60 | 9728 | |
d9f6a4ee | 9729 | procedure Check_Component_List |
9730 | (CL : Node_Id; | |
9731 | Sbit : Uint; | |
9732 | DS : List_Id); | |
9733 | -- Check component list CL for holes. The starting bit should be | |
9734 | -- Sbit. which is zero for the main record component list and set | |
9735 | -- appropriately for recursive calls for variants. DS is set to | |
9736 | -- a list of discriminant specifications to be included in the | |
9737 | -- consideration of components. It is No_List if none to consider. | |
67278d60 | 9738 | |
d9f6a4ee | 9739 | -------------------------- |
9740 | -- Check_Component_List -- | |
9741 | -------------------------- | |
47495553 | 9742 | |
d9f6a4ee | 9743 | procedure Check_Component_List |
9744 | (CL : Node_Id; | |
9745 | Sbit : Uint; | |
9746 | DS : List_Id) | |
9747 | is | |
9748 | Compl : Integer; | |
67278d60 | 9749 | |
d9f6a4ee | 9750 | begin |
9751 | Compl := Integer (List_Length (Component_Items (CL))); | |
47495553 | 9752 | |
d9f6a4ee | 9753 | if DS /= No_List then |
9754 | Compl := Compl + Integer (List_Length (DS)); | |
9755 | end if; | |
67278d60 | 9756 | |
d9f6a4ee | 9757 | declare |
9758 | Comps : array (Natural range 0 .. Compl) of Entity_Id; | |
9759 | -- Gather components (zero entry is for sort routine) | |
67278d60 | 9760 | |
d9f6a4ee | 9761 | Ncomps : Natural := 0; |
9762 | -- Number of entries stored in Comps (starting at Comps (1)) | |
67278d60 | 9763 | |
d9f6a4ee | 9764 | Citem : Node_Id; |
9765 | -- One component item or discriminant specification | |
67278d60 | 9766 | |
d9f6a4ee | 9767 | Nbit : Uint; |
9768 | -- Starting bit for next component | |
67278d60 | 9769 | |
d9f6a4ee | 9770 | CEnt : Entity_Id; |
9771 | -- Component entity | |
67278d60 | 9772 | |
d9f6a4ee | 9773 | Variant : Node_Id; |
9774 | -- One variant | |
67278d60 | 9775 | |
d9f6a4ee | 9776 | function Lt (Op1, Op2 : Natural) return Boolean; |
9777 | -- Compare routine for Sort | |
67278d60 | 9778 | |
d9f6a4ee | 9779 | procedure Move (From : Natural; To : Natural); |
9780 | -- Move routine for Sort | |
67278d60 | 9781 | |
d9f6a4ee | 9782 | package Sorting is new GNAT.Heap_Sort_G (Move, Lt); |
67278d60 | 9783 | |
d9f6a4ee | 9784 | -------- |
9785 | -- Lt -- | |
9786 | -------- | |
67278d60 | 9787 | |
d9f6a4ee | 9788 | function Lt (Op1, Op2 : Natural) return Boolean is |
9789 | begin | |
9790 | return Component_Bit_Offset (Comps (Op1)) | |
9791 | < | |
9792 | Component_Bit_Offset (Comps (Op2)); | |
9793 | end Lt; | |
67278d60 | 9794 | |
d9f6a4ee | 9795 | ---------- |
9796 | -- Move -- | |
9797 | ---------- | |
67278d60 | 9798 | |
d9f6a4ee | 9799 | procedure Move (From : Natural; To : Natural) is |
9800 | begin | |
9801 | Comps (To) := Comps (From); | |
9802 | end Move; | |
67278d60 | 9803 | |
d9f6a4ee | 9804 | begin |
9805 | -- Gather discriminants into Comp | |
67278d60 | 9806 | |
d9f6a4ee | 9807 | if DS /= No_List then |
9808 | Citem := First (DS); | |
9809 | while Present (Citem) loop | |
9810 | if Nkind (Citem) = N_Discriminant_Specification then | |
9811 | declare | |
9812 | Ent : constant Entity_Id := | |
9813 | Defining_Identifier (Citem); | |
9814 | begin | |
9815 | if Ekind (Ent) = E_Discriminant then | |
9816 | Ncomps := Ncomps + 1; | |
9817 | Comps (Ncomps) := Ent; | |
9818 | end if; | |
9819 | end; | |
9820 | end if; | |
67278d60 | 9821 | |
d9f6a4ee | 9822 | Next (Citem); |
9823 | end loop; | |
9824 | end if; | |
67278d60 | 9825 | |
d9f6a4ee | 9826 | -- Gather component entities into Comp |
67278d60 | 9827 | |
d9f6a4ee | 9828 | Citem := First (Component_Items (CL)); |
9829 | while Present (Citem) loop | |
9830 | if Nkind (Citem) = N_Component_Declaration then | |
9831 | Ncomps := Ncomps + 1; | |
9832 | Comps (Ncomps) := Defining_Identifier (Citem); | |
9833 | end if; | |
67278d60 | 9834 | |
d9f6a4ee | 9835 | Next (Citem); |
9836 | end loop; | |
67278d60 | 9837 | |
d9f6a4ee | 9838 | -- Now sort the component entities based on the first bit. |
9839 | -- Note we already know there are no overlapping components. | |
67278d60 | 9840 | |
d9f6a4ee | 9841 | Sorting.Sort (Ncomps); |
67278d60 | 9842 | |
d9f6a4ee | 9843 | -- Loop through entries checking for holes |
67278d60 | 9844 | |
d9f6a4ee | 9845 | Nbit := Sbit; |
9846 | for J in 1 .. Ncomps loop | |
9847 | CEnt := Comps (J); | |
9848 | Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit; | |
67278d60 | 9849 | |
d9f6a4ee | 9850 | if Error_Msg_Uint_1 > 0 then |
9851 | Error_Msg_NE | |
9852 | ("?H?^-bit gap before component&", | |
9853 | Component_Name (Component_Clause (CEnt)), CEnt); | |
9854 | end if; | |
67278d60 | 9855 | |
d9f6a4ee | 9856 | Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt); |
9857 | end loop; | |
67278d60 | 9858 | |
d9f6a4ee | 9859 | -- Process variant parts recursively if present |
67278d60 | 9860 | |
d9f6a4ee | 9861 | if Present (Variant_Part (CL)) then |
9862 | Variant := First (Variants (Variant_Part (CL))); | |
9863 | while Present (Variant) loop | |
9864 | Check_Component_List | |
9865 | (Component_List (Variant), Nbit, No_List); | |
9866 | Next (Variant); | |
9867 | end loop; | |
67278d60 | 9868 | end if; |
d9f6a4ee | 9869 | end; |
9870 | end Check_Component_List; | |
67278d60 | 9871 | |
d9f6a4ee | 9872 | -- Start of processing for Record_Hole_Check |
67278d60 | 9873 | |
d9f6a4ee | 9874 | begin |
9875 | declare | |
9876 | Sbit : Uint; | |
67278d60 | 9877 | |
d9f6a4ee | 9878 | begin |
9879 | if Is_Tagged_Type (Rectype) then | |
9880 | Sbit := UI_From_Int (System_Address_Size); | |
9881 | else | |
9882 | Sbit := Uint_0; | |
9883 | end if; | |
9884 | ||
9885 | if Nkind (Decl) = N_Full_Type_Declaration | |
9886 | and then Nkind (Type_Definition (Decl)) = N_Record_Definition | |
9887 | then | |
9888 | Check_Component_List | |
9889 | (Component_List (Type_Definition (Decl)), | |
9890 | Sbit, | |
9891 | Discriminant_Specifications (Decl)); | |
67278d60 | 9892 | end if; |
d9f6a4ee | 9893 | end; |
9894 | end Record_Hole_Check; | |
67278d60 | 9895 | end if; |
9896 | ||
d9f6a4ee | 9897 | -- For records that have component clauses for all components, and whose |
9898 | -- size is less than or equal to 32, we need to know the size in the | |
9899 | -- front end to activate possible packed array processing where the | |
9900 | -- component type is a record. | |
67278d60 | 9901 | |
d9f6a4ee | 9902 | -- At this stage Hbit + 1 represents the first unused bit from all the |
9903 | -- component clauses processed, so if the component clauses are | |
9904 | -- complete, then this is the length of the record. | |
67278d60 | 9905 | |
d9f6a4ee | 9906 | -- For records longer than System.Storage_Unit, and for those where not |
9907 | -- all components have component clauses, the back end determines the | |
9908 | -- length (it may for example be appropriate to round up the size | |
9909 | -- to some convenient boundary, based on alignment considerations, etc). | |
67278d60 | 9910 | |
d9f6a4ee | 9911 | if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then |
67278d60 | 9912 | |
d9f6a4ee | 9913 | -- Nothing to do if at least one component has no component clause |
67278d60 | 9914 | |
d9f6a4ee | 9915 | Comp := First_Component_Or_Discriminant (Rectype); |
9916 | while Present (Comp) loop | |
9917 | exit when No (Component_Clause (Comp)); | |
9918 | Next_Component_Or_Discriminant (Comp); | |
9919 | end loop; | |
67278d60 | 9920 | |
d9f6a4ee | 9921 | -- If we fall out of loop, all components have component clauses |
9922 | -- and so we can set the size to the maximum value. | |
67278d60 | 9923 | |
d9f6a4ee | 9924 | if No (Comp) then |
9925 | Set_RM_Size (Rectype, Hbit + 1); | |
9926 | end if; | |
9927 | end if; | |
9928 | end Check_Record_Representation_Clause; | |
67278d60 | 9929 | |
d9f6a4ee | 9930 | ---------------- |
9931 | -- Check_Size -- | |
9932 | ---------------- | |
67278d60 | 9933 | |
d9f6a4ee | 9934 | procedure Check_Size |
9935 | (N : Node_Id; | |
9936 | T : Entity_Id; | |
9937 | Siz : Uint; | |
9938 | Biased : out Boolean) | |
9939 | is | |
9940 | UT : constant Entity_Id := Underlying_Type (T); | |
9941 | M : Uint; | |
67278d60 | 9942 | |
d9f6a4ee | 9943 | begin |
9944 | Biased := False; | |
67278d60 | 9945 | |
d9f6a4ee | 9946 | -- Reject patently improper size values. |
67278d60 | 9947 | |
d9f6a4ee | 9948 | if Is_Elementary_Type (T) |
9949 | and then Siz > UI_From_Int (Int'Last) | |
9950 | then | |
9951 | Error_Msg_N ("Size value too large for elementary type", N); | |
67278d60 | 9952 | |
d9f6a4ee | 9953 | if Nkind (Original_Node (N)) = N_Op_Expon then |
9954 | Error_Msg_N | |
9955 | ("\maybe '* was meant, rather than '*'*", Original_Node (N)); | |
9956 | end if; | |
9957 | end if; | |
67278d60 | 9958 | |
d9f6a4ee | 9959 | -- Dismiss generic types |
67278d60 | 9960 | |
d9f6a4ee | 9961 | if Is_Generic_Type (T) |
9962 | or else | |
9963 | Is_Generic_Type (UT) | |
9964 | or else | |
9965 | Is_Generic_Type (Root_Type (UT)) | |
9966 | then | |
9967 | return; | |
67278d60 | 9968 | |
d9f6a4ee | 9969 | -- Guard against previous errors |
67278d60 | 9970 | |
d9f6a4ee | 9971 | elsif No (UT) or else UT = Any_Type then |
9972 | Check_Error_Detected; | |
9973 | return; | |
67278d60 | 9974 | |
d9f6a4ee | 9975 | -- Check case of bit packed array |
67278d60 | 9976 | |
d9f6a4ee | 9977 | elsif Is_Array_Type (UT) |
9978 | and then Known_Static_Component_Size (UT) | |
9979 | and then Is_Bit_Packed_Array (UT) | |
9980 | then | |
9981 | declare | |
9982 | Asiz : Uint; | |
9983 | Indx : Node_Id; | |
9984 | Ityp : Entity_Id; | |
67278d60 | 9985 | |
d9f6a4ee | 9986 | begin |
9987 | Asiz := Component_Size (UT); | |
9988 | Indx := First_Index (UT); | |
9989 | loop | |
9990 | Ityp := Etype (Indx); | |
67278d60 | 9991 | |
d9f6a4ee | 9992 | -- If non-static bound, then we are not in the business of |
9993 | -- trying to check the length, and indeed an error will be | |
9994 | -- issued elsewhere, since sizes of non-static array types | |
9995 | -- cannot be set implicitly or explicitly. | |
67278d60 | 9996 | |
cda40848 | 9997 | if not Is_OK_Static_Subtype (Ityp) then |
d9f6a4ee | 9998 | return; |
9999 | end if; | |
67278d60 | 10000 | |
d9f6a4ee | 10001 | -- Otherwise accumulate next dimension |
67278d60 | 10002 | |
d9f6a4ee | 10003 | Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) - |
10004 | Expr_Value (Type_Low_Bound (Ityp)) + | |
10005 | Uint_1); | |
67278d60 | 10006 | |
d9f6a4ee | 10007 | Next_Index (Indx); |
10008 | exit when No (Indx); | |
10009 | end loop; | |
67278d60 | 10010 | |
d9f6a4ee | 10011 | if Asiz <= Siz then |
10012 | return; | |
67278d60 | 10013 | |
d9f6a4ee | 10014 | else |
10015 | Error_Msg_Uint_1 := Asiz; | |
10016 | Error_Msg_NE | |
10017 | ("size for& too small, minimum allowed is ^", N, T); | |
10018 | Set_Esize (T, Asiz); | |
10019 | Set_RM_Size (T, Asiz); | |
10020 | end if; | |
10021 | end; | |
67278d60 | 10022 | |
d9f6a4ee | 10023 | -- All other composite types are ignored |
67278d60 | 10024 | |
d9f6a4ee | 10025 | elsif Is_Composite_Type (UT) then |
10026 | return; | |
47495553 | 10027 | |
d9f6a4ee | 10028 | -- For fixed-point types, don't check minimum if type is not frozen, |
10029 | -- since we don't know all the characteristics of the type that can | |
10030 | -- affect the size (e.g. a specified small) till freeze time. | |
47495553 | 10031 | |
d9f6a4ee | 10032 | elsif Is_Fixed_Point_Type (UT) |
10033 | and then not Is_Frozen (UT) | |
10034 | then | |
10035 | null; | |
47495553 | 10036 | |
d9f6a4ee | 10037 | -- Cases for which a minimum check is required |
47495553 | 10038 | |
d9f6a4ee | 10039 | else |
10040 | -- Ignore if specified size is correct for the type | |
47495553 | 10041 | |
d9f6a4ee | 10042 | if Known_Esize (UT) and then Siz = Esize (UT) then |
10043 | return; | |
10044 | end if; | |
47495553 | 10045 | |
d9f6a4ee | 10046 | -- Otherwise get minimum size |
47495553 | 10047 | |
d9f6a4ee | 10048 | M := UI_From_Int (Minimum_Size (UT)); |
47495553 | 10049 | |
d9f6a4ee | 10050 | if Siz < M then |
47495553 | 10051 | |
d9f6a4ee | 10052 | -- Size is less than minimum size, but one possibility remains |
10053 | -- that we can manage with the new size if we bias the type. | |
47495553 | 10054 | |
d9f6a4ee | 10055 | M := UI_From_Int (Minimum_Size (UT, Biased => True)); |
47495553 | 10056 | |
d9f6a4ee | 10057 | if Siz < M then |
10058 | Error_Msg_Uint_1 := M; | |
10059 | Error_Msg_NE | |
10060 | ("size for& too small, minimum allowed is ^", N, T); | |
10061 | Set_Esize (T, M); | |
10062 | Set_RM_Size (T, M); | |
10063 | else | |
10064 | Biased := True; | |
10065 | end if; | |
10066 | end if; | |
10067 | end if; | |
10068 | end Check_Size; | |
47495553 | 10069 | |
d9f6a4ee | 10070 | -------------------------- |
10071 | -- Freeze_Entity_Checks -- | |
10072 | -------------------------- | |
47495553 | 10073 | |
d9f6a4ee | 10074 | procedure Freeze_Entity_Checks (N : Node_Id) is |
8cf481c9 | 10075 | procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id); |
10076 | -- Inspect the primitive operations of type Typ and hide all pairs of | |
3118058b | 10077 | -- implicitly declared non-overridden non-fully conformant homographs |
10078 | -- (Ada RM 8.3 12.3/2). | |
8cf481c9 | 10079 | |
10080 | ------------------------------------- | |
10081 | -- Hide_Non_Overridden_Subprograms -- | |
10082 | ------------------------------------- | |
10083 | ||
10084 | procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is | |
10085 | procedure Hide_Matching_Homographs | |
10086 | (Subp_Id : Entity_Id; | |
10087 | Start_Elmt : Elmt_Id); | |
10088 | -- Inspect a list of primitive operations starting with Start_Elmt | |
3118058b | 10089 | -- and find matching implicitly declared non-overridden non-fully |
10090 | -- conformant homographs of Subp_Id. If found, all matches along | |
10091 | -- with Subp_Id are hidden from all visibility. | |
8cf481c9 | 10092 | |
10093 | function Is_Non_Overridden_Or_Null_Procedure | |
10094 | (Subp_Id : Entity_Id) return Boolean; | |
10095 | -- Determine whether subprogram Subp_Id is implicitly declared non- | |
10096 | -- overridden subprogram or an implicitly declared null procedure. | |
10097 | ||
10098 | ------------------------------ | |
10099 | -- Hide_Matching_Homographs -- | |
10100 | ------------------------------ | |
10101 | ||
10102 | procedure Hide_Matching_Homographs | |
10103 | (Subp_Id : Entity_Id; | |
10104 | Start_Elmt : Elmt_Id) | |
10105 | is | |
10106 | Prim : Entity_Id; | |
10107 | Prim_Elmt : Elmt_Id; | |
10108 | ||
10109 | begin | |
10110 | Prim_Elmt := Start_Elmt; | |
10111 | while Present (Prim_Elmt) loop | |
10112 | Prim := Node (Prim_Elmt); | |
10113 | ||
10114 | -- The current primitive is implicitly declared non-overridden | |
3118058b | 10115 | -- non-fully conformant homograph of Subp_Id. Both subprograms |
10116 | -- must be hidden from visibility. | |
8cf481c9 | 10117 | |
10118 | if Chars (Prim) = Chars (Subp_Id) | |
8cf481c9 | 10119 | and then Is_Non_Overridden_Or_Null_Procedure (Prim) |
3118058b | 10120 | and then not Fully_Conformant (Prim, Subp_Id) |
8cf481c9 | 10121 | then |
8c7ee4ac | 10122 | Set_Is_Hidden_Non_Overridden_Subpgm (Prim); |
10123 | Set_Is_Immediately_Visible (Prim, False); | |
10124 | Set_Is_Potentially_Use_Visible (Prim, False); | |
8cf481c9 | 10125 | |
8c7ee4ac | 10126 | Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id); |
10127 | Set_Is_Immediately_Visible (Subp_Id, False); | |
10128 | Set_Is_Potentially_Use_Visible (Subp_Id, False); | |
8cf481c9 | 10129 | end if; |
10130 | ||
10131 | Next_Elmt (Prim_Elmt); | |
10132 | end loop; | |
10133 | end Hide_Matching_Homographs; | |
10134 | ||
10135 | ----------------------------------------- | |
10136 | -- Is_Non_Overridden_Or_Null_Procedure -- | |
10137 | ----------------------------------------- | |
10138 | ||
10139 | function Is_Non_Overridden_Or_Null_Procedure | |
10140 | (Subp_Id : Entity_Id) return Boolean | |
10141 | is | |
10142 | Alias_Id : Entity_Id; | |
10143 | ||
10144 | begin | |
10145 | -- The subprogram is inherited (implicitly declared), it does not | |
10146 | -- override and does not cover a primitive of an interface. | |
10147 | ||
10148 | if Ekind_In (Subp_Id, E_Function, E_Procedure) | |
10149 | and then Present (Alias (Subp_Id)) | |
10150 | and then No (Interface_Alias (Subp_Id)) | |
10151 | and then No (Overridden_Operation (Subp_Id)) | |
10152 | then | |
10153 | Alias_Id := Alias (Subp_Id); | |
10154 | ||
10155 | if Requires_Overriding (Alias_Id) then | |
10156 | return True; | |
10157 | ||
10158 | elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification | |
10159 | and then Null_Present (Parent (Alias_Id)) | |
10160 | then | |
10161 | return True; | |
10162 | end if; | |
10163 | end if; | |
10164 | ||
10165 | return False; | |
10166 | end Is_Non_Overridden_Or_Null_Procedure; | |
10167 | ||
10168 | -- Local variables | |
10169 | ||
10170 | Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ); | |
10171 | Prim : Entity_Id; | |
10172 | Prim_Elmt : Elmt_Id; | |
10173 | ||
10174 | -- Start of processing for Hide_Non_Overridden_Subprograms | |
10175 | ||
10176 | begin | |
3118058b | 10177 | -- Inspect the list of primitives looking for non-overridden |
10178 | -- subprograms. | |
8cf481c9 | 10179 | |
10180 | if Present (Prim_Ops) then | |
10181 | Prim_Elmt := First_Elmt (Prim_Ops); | |
10182 | while Present (Prim_Elmt) loop | |
10183 | Prim := Node (Prim_Elmt); | |
10184 | Next_Elmt (Prim_Elmt); | |
10185 | ||
10186 | if Is_Non_Overridden_Or_Null_Procedure (Prim) then | |
10187 | Hide_Matching_Homographs | |
10188 | (Subp_Id => Prim, | |
10189 | Start_Elmt => Prim_Elmt); | |
10190 | end if; | |
10191 | end loop; | |
10192 | end if; | |
10193 | end Hide_Non_Overridden_Subprograms; | |
10194 | ||
10195 | --------------------- | |
10196 | -- Local variables -- | |
10197 | --------------------- | |
10198 | ||
d9f6a4ee | 10199 | E : constant Entity_Id := Entity (N); |
47495553 | 10200 | |
d9f6a4ee | 10201 | Non_Generic_Case : constant Boolean := Nkind (N) = N_Freeze_Entity; |
10202 | -- True in non-generic case. Some of the processing here is skipped | |
10203 | -- for the generic case since it is not needed. Basically in the | |
10204 | -- generic case, we only need to do stuff that might generate error | |
10205 | -- messages or warnings. | |
8cf481c9 | 10206 | |
10207 | -- Start of processing for Freeze_Entity_Checks | |
10208 | ||
d9f6a4ee | 10209 | begin |
10210 | -- Remember that we are processing a freezing entity. Required to | |
10211 | -- ensure correct decoration of internal entities associated with | |
10212 | -- interfaces (see New_Overloaded_Entity). | |
47495553 | 10213 | |
d9f6a4ee | 10214 | Inside_Freezing_Actions := Inside_Freezing_Actions + 1; |
47495553 | 10215 | |
d9f6a4ee | 10216 | -- For tagged types covering interfaces add internal entities that link |
10217 | -- the primitives of the interfaces with the primitives that cover them. | |
10218 | -- Note: These entities were originally generated only when generating | |
10219 | -- code because their main purpose was to provide support to initialize | |
10220 | -- the secondary dispatch tables. They are now generated also when | |
10221 | -- compiling with no code generation to provide ASIS the relationship | |
10222 | -- between interface primitives and tagged type primitives. They are | |
10223 | -- also used to locate primitives covering interfaces when processing | |
10224 | -- generics (see Derive_Subprograms). | |
47495553 | 10225 | |
d9f6a4ee | 10226 | -- This is not needed in the generic case |
47495553 | 10227 | |
d9f6a4ee | 10228 | if Ada_Version >= Ada_2005 |
10229 | and then Non_Generic_Case | |
10230 | and then Ekind (E) = E_Record_Type | |
10231 | and then Is_Tagged_Type (E) | |
10232 | and then not Is_Interface (E) | |
10233 | and then Has_Interfaces (E) | |
10234 | then | |
10235 | -- This would be a good common place to call the routine that checks | |
10236 | -- overriding of interface primitives (and thus factorize calls to | |
10237 | -- Check_Abstract_Overriding located at different contexts in the | |
10238 | -- compiler). However, this is not possible because it causes | |
10239 | -- spurious errors in case of late overriding. | |
47495553 | 10240 | |
d9f6a4ee | 10241 | Add_Internal_Interface_Entities (E); |
10242 | end if; | |
47495553 | 10243 | |
8cf481c9 | 10244 | -- After all forms of overriding have been resolved, a tagged type may |
10245 | -- be left with a set of implicitly declared and possibly erroneous | |
10246 | -- abstract subprograms, null procedures and subprograms that require | |
10247 | -- overriding. If this set contains fully conformat homographs, then one | |
10248 | -- is chosen arbitrarily (already done during resolution), otherwise all | |
3118058b | 10249 | -- remaining non-fully conformant homographs are hidden from visibility |
8cf481c9 | 10250 | -- (Ada RM 8.3 12.3/2). |
10251 | ||
10252 | if Is_Tagged_Type (E) then | |
10253 | Hide_Non_Overridden_Subprograms (E); | |
10254 | end if; | |
10255 | ||
d9f6a4ee | 10256 | -- Check CPP types |
47495553 | 10257 | |
d9f6a4ee | 10258 | if Ekind (E) = E_Record_Type |
10259 | and then Is_CPP_Class (E) | |
10260 | and then Is_Tagged_Type (E) | |
10261 | and then Tagged_Type_Expansion | |
d9f6a4ee | 10262 | then |
10263 | if CPP_Num_Prims (E) = 0 then | |
47495553 | 10264 | |
d9f6a4ee | 10265 | -- If the CPP type has user defined components then it must import |
10266 | -- primitives from C++. This is required because if the C++ class | |
10267 | -- has no primitives then the C++ compiler does not added the _tag | |
10268 | -- component to the type. | |
47495553 | 10269 | |
d9f6a4ee | 10270 | if First_Entity (E) /= Last_Entity (E) then |
10271 | Error_Msg_N | |
10272 | ("'C'P'P type must import at least one primitive from C++??", | |
10273 | E); | |
10274 | end if; | |
10275 | end if; | |
47495553 | 10276 | |
d9f6a4ee | 10277 | -- Check that all its primitives are abstract or imported from C++. |
10278 | -- Check also availability of the C++ constructor. | |
47495553 | 10279 | |
d9f6a4ee | 10280 | declare |
10281 | Has_Constructors : constant Boolean := Has_CPP_Constructors (E); | |
10282 | Elmt : Elmt_Id; | |
10283 | Error_Reported : Boolean := False; | |
10284 | Prim : Node_Id; | |
47495553 | 10285 | |
d9f6a4ee | 10286 | begin |
10287 | Elmt := First_Elmt (Primitive_Operations (E)); | |
10288 | while Present (Elmt) loop | |
10289 | Prim := Node (Elmt); | |
47495553 | 10290 | |
d9f6a4ee | 10291 | if Comes_From_Source (Prim) then |
10292 | if Is_Abstract_Subprogram (Prim) then | |
10293 | null; | |
47495553 | 10294 | |
d9f6a4ee | 10295 | elsif not Is_Imported (Prim) |
10296 | or else Convention (Prim) /= Convention_CPP | |
10297 | then | |
10298 | Error_Msg_N | |
10299 | ("primitives of 'C'P'P types must be imported from C++ " | |
10300 | & "or abstract??", Prim); | |
47495553 | 10301 | |
d9f6a4ee | 10302 | elsif not Has_Constructors |
10303 | and then not Error_Reported | |
10304 | then | |
10305 | Error_Msg_Name_1 := Chars (E); | |
10306 | Error_Msg_N | |
10307 | ("??'C'P'P constructor required for type %", Prim); | |
10308 | Error_Reported := True; | |
10309 | end if; | |
10310 | end if; | |
47495553 | 10311 | |
d9f6a4ee | 10312 | Next_Elmt (Elmt); |
10313 | end loop; | |
10314 | end; | |
10315 | end if; | |
47495553 | 10316 | |
d9f6a4ee | 10317 | -- Check Ada derivation of CPP type |
47495553 | 10318 | |
30ab103b | 10319 | if Expander_Active -- why? losing errors in -gnatc mode??? |
10320 | and then Present (Etype (E)) -- defend against errors | |
d9f6a4ee | 10321 | and then Tagged_Type_Expansion |
10322 | and then Ekind (E) = E_Record_Type | |
10323 | and then Etype (E) /= E | |
10324 | and then Is_CPP_Class (Etype (E)) | |
10325 | and then CPP_Num_Prims (Etype (E)) > 0 | |
10326 | and then not Is_CPP_Class (E) | |
10327 | and then not Has_CPP_Constructors (Etype (E)) | |
10328 | then | |
10329 | -- If the parent has C++ primitives but it has no constructor then | |
10330 | -- check that all the primitives are overridden in this derivation; | |
10331 | -- otherwise the constructor of the parent is needed to build the | |
10332 | -- dispatch table. | |
47495553 | 10333 | |
d9f6a4ee | 10334 | declare |
10335 | Elmt : Elmt_Id; | |
10336 | Prim : Node_Id; | |
47495553 | 10337 | |
10338 | begin | |
d9f6a4ee | 10339 | Elmt := First_Elmt (Primitive_Operations (E)); |
10340 | while Present (Elmt) loop | |
10341 | Prim := Node (Elmt); | |
47495553 | 10342 | |
d9f6a4ee | 10343 | if not Is_Abstract_Subprogram (Prim) |
10344 | and then No (Interface_Alias (Prim)) | |
10345 | and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E | |
47495553 | 10346 | then |
d9f6a4ee | 10347 | Error_Msg_Name_1 := Chars (Etype (E)); |
10348 | Error_Msg_N | |
10349 | ("'C'P'P constructor required for parent type %", E); | |
10350 | exit; | |
47495553 | 10351 | end if; |
d9f6a4ee | 10352 | |
10353 | Next_Elmt (Elmt); | |
10354 | end loop; | |
10355 | end; | |
47495553 | 10356 | end if; |
10357 | ||
d9f6a4ee | 10358 | Inside_Freezing_Actions := Inside_Freezing_Actions - 1; |
67278d60 | 10359 | |
d9f6a4ee | 10360 | -- If we have a type with predicates, build predicate function. This |
0e9014a7 | 10361 | -- is not needed in the generic case, and is not needed within TSS |
ea822fd4 | 10362 | -- subprograms and other predefined primitives. |
67278d60 | 10363 | |
ea822fd4 | 10364 | if Non_Generic_Case |
10365 | and then Is_Type (E) | |
10366 | and then Has_Predicates (E) | |
10367 | and then not Within_Internal_Subprogram | |
10368 | then | |
d9f6a4ee | 10369 | Build_Predicate_Functions (E, N); |
10370 | end if; | |
67278d60 | 10371 | |
d9f6a4ee | 10372 | -- If type has delayed aspects, this is where we do the preanalysis at |
10373 | -- the freeze point, as part of the consistent visibility check. Note | |
10374 | -- that this must be done after calling Build_Predicate_Functions or | |
10375 | -- Build_Invariant_Procedure since these subprograms fix occurrences of | |
10376 | -- the subtype name in the saved expression so that they will not cause | |
10377 | -- trouble in the preanalysis. | |
67278d60 | 10378 | |
d9f6a4ee | 10379 | -- This is also not needed in the generic case |
10380 | ||
10381 | if Non_Generic_Case | |
10382 | and then Has_Delayed_Aspects (E) | |
10383 | and then Scope (E) = Current_Scope | |
10384 | then | |
10385 | -- Retrieve the visibility to the discriminants in order to properly | |
10386 | -- analyze the aspects. | |
10387 | ||
10388 | Push_Scope_And_Install_Discriminants (E); | |
10389 | ||
10390 | declare | |
10391 | Ritem : Node_Id; | |
10392 | ||
10393 | begin | |
10394 | -- Look for aspect specification entries for this entity | |
67278d60 | 10395 | |
d9f6a4ee | 10396 | Ritem := First_Rep_Item (E); |
10397 | while Present (Ritem) loop | |
10398 | if Nkind (Ritem) = N_Aspect_Specification | |
10399 | and then Entity (Ritem) = E | |
10400 | and then Is_Delayed_Aspect (Ritem) | |
10401 | then | |
10402 | Check_Aspect_At_Freeze_Point (Ritem); | |
10403 | end if; | |
67278d60 | 10404 | |
d9f6a4ee | 10405 | Next_Rep_Item (Ritem); |
10406 | end loop; | |
10407 | end; | |
67278d60 | 10408 | |
d9f6a4ee | 10409 | Uninstall_Discriminants_And_Pop_Scope (E); |
67278d60 | 10410 | end if; |
67278d60 | 10411 | |
d9f6a4ee | 10412 | -- For a record type, deal with variant parts. This has to be delayed |
d0988351 | 10413 | -- to this point, because of the issue of statically predicated |
d9f6a4ee | 10414 | -- subtypes, which we have to ensure are frozen before checking |
10415 | -- choices, since we need to have the static choice list set. | |
d6f39728 | 10416 | |
d9f6a4ee | 10417 | if Is_Record_Type (E) then |
10418 | Check_Variant_Part : declare | |
10419 | D : constant Node_Id := Declaration_Node (E); | |
10420 | T : Node_Id; | |
10421 | C : Node_Id; | |
10422 | VP : Node_Id; | |
d6f39728 | 10423 | |
d9f6a4ee | 10424 | Others_Present : Boolean; |
10425 | pragma Warnings (Off, Others_Present); | |
10426 | -- Indicates others present, not used in this case | |
d6f39728 | 10427 | |
d9f6a4ee | 10428 | procedure Non_Static_Choice_Error (Choice : Node_Id); |
10429 | -- Error routine invoked by the generic instantiation below when | |
10430 | -- the variant part has a non static choice. | |
f117057b | 10431 | |
d9f6a4ee | 10432 | procedure Process_Declarations (Variant : Node_Id); |
10433 | -- Processes declarations associated with a variant. We analyzed | |
10434 | -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part), | |
10435 | -- but we still need the recursive call to Check_Choices for any | |
10436 | -- nested variant to get its choices properly processed. This is | |
10437 | -- also where we expand out the choices if expansion is active. | |
1f526845 | 10438 | |
d9f6a4ee | 10439 | package Variant_Choices_Processing is new |
10440 | Generic_Check_Choices | |
10441 | (Process_Empty_Choice => No_OP, | |
10442 | Process_Non_Static_Choice => Non_Static_Choice_Error, | |
10443 | Process_Associated_Node => Process_Declarations); | |
10444 | use Variant_Choices_Processing; | |
f117057b | 10445 | |
d9f6a4ee | 10446 | ----------------------------- |
10447 | -- Non_Static_Choice_Error -- | |
10448 | ----------------------------- | |
d6f39728 | 10449 | |
d9f6a4ee | 10450 | procedure Non_Static_Choice_Error (Choice : Node_Id) is |
10451 | begin | |
10452 | Flag_Non_Static_Expr | |
10453 | ("choice given in variant part is not static!", Choice); | |
10454 | end Non_Static_Choice_Error; | |
d6f39728 | 10455 | |
d9f6a4ee | 10456 | -------------------------- |
10457 | -- Process_Declarations -- | |
10458 | -------------------------- | |
dba36b60 | 10459 | |
d9f6a4ee | 10460 | procedure Process_Declarations (Variant : Node_Id) is |
10461 | CL : constant Node_Id := Component_List (Variant); | |
10462 | VP : Node_Id; | |
dba36b60 | 10463 | |
d9f6a4ee | 10464 | begin |
10465 | -- Check for static predicate present in this variant | |
ea61a7ea | 10466 | |
d9f6a4ee | 10467 | if Has_SP_Choice (Variant) then |
ea61a7ea | 10468 | |
d9f6a4ee | 10469 | -- Here we expand. You might expect to find this call in |
10470 | -- Expand_N_Variant_Part, but that is called when we first | |
10471 | -- see the variant part, and we cannot do this expansion | |
10472 | -- earlier than the freeze point, since for statically | |
10473 | -- predicated subtypes, the predicate is not known till | |
10474 | -- the freeze point. | |
ea61a7ea | 10475 | |
d9f6a4ee | 10476 | -- Furthermore, we do this expansion even if the expander |
10477 | -- is not active, because other semantic processing, e.g. | |
10478 | -- for aggregates, requires the expanded list of choices. | |
ea61a7ea | 10479 | |
d9f6a4ee | 10480 | -- If the expander is not active, then we can't just clobber |
10481 | -- the list since it would invalidate the ASIS -gnatct tree. | |
10482 | -- So we have to rewrite the variant part with a Rewrite | |
10483 | -- call that replaces it with a copy and clobber the copy. | |
10484 | ||
10485 | if not Expander_Active then | |
10486 | declare | |
10487 | NewV : constant Node_Id := New_Copy (Variant); | |
10488 | begin | |
10489 | Set_Discrete_Choices | |
10490 | (NewV, New_Copy_List (Discrete_Choices (Variant))); | |
10491 | Rewrite (Variant, NewV); | |
10492 | end; | |
10493 | end if; | |
10494 | ||
10495 | Expand_Static_Predicates_In_Choices (Variant); | |
ea61a7ea | 10496 | end if; |
10497 | ||
d9f6a4ee | 10498 | -- We don't need to worry about the declarations in the variant |
10499 | -- (since they were analyzed by Analyze_Choices when we first | |
10500 | -- encountered the variant), but we do need to take care of | |
10501 | -- expansion of any nested variants. | |
ea61a7ea | 10502 | |
d9f6a4ee | 10503 | if not Null_Present (CL) then |
10504 | VP := Variant_Part (CL); | |
ea61a7ea | 10505 | |
d9f6a4ee | 10506 | if Present (VP) then |
10507 | Check_Choices | |
10508 | (VP, Variants (VP), Etype (Name (VP)), Others_Present); | |
10509 | end if; | |
10510 | end if; | |
10511 | end Process_Declarations; | |
ea61a7ea | 10512 | |
d9f6a4ee | 10513 | -- Start of processing for Check_Variant_Part |
b9e61b2a | 10514 | |
d9f6a4ee | 10515 | begin |
10516 | -- Find component list | |
ea61a7ea | 10517 | |
d9f6a4ee | 10518 | C := Empty; |
ea61a7ea | 10519 | |
d9f6a4ee | 10520 | if Nkind (D) = N_Full_Type_Declaration then |
10521 | T := Type_Definition (D); | |
ea61a7ea | 10522 | |
d9f6a4ee | 10523 | if Nkind (T) = N_Record_Definition then |
10524 | C := Component_List (T); | |
d6f39728 | 10525 | |
d9f6a4ee | 10526 | elsif Nkind (T) = N_Derived_Type_Definition |
10527 | and then Present (Record_Extension_Part (T)) | |
10528 | then | |
10529 | C := Component_List (Record_Extension_Part (T)); | |
10530 | end if; | |
10531 | end if; | |
d6f39728 | 10532 | |
d9f6a4ee | 10533 | -- Case of variant part present |
d6f39728 | 10534 | |
d9f6a4ee | 10535 | if Present (C) and then Present (Variant_Part (C)) then |
10536 | VP := Variant_Part (C); | |
ea61a7ea | 10537 | |
d9f6a4ee | 10538 | -- Check choices |
ea61a7ea | 10539 | |
d9f6a4ee | 10540 | Check_Choices |
10541 | (VP, Variants (VP), Etype (Name (VP)), Others_Present); | |
ea61a7ea | 10542 | |
d9f6a4ee | 10543 | -- If the last variant does not contain the Others choice, |
10544 | -- replace it with an N_Others_Choice node since Gigi always | |
10545 | -- wants an Others. Note that we do not bother to call Analyze | |
10546 | -- on the modified variant part, since its only effect would be | |
10547 | -- to compute the Others_Discrete_Choices node laboriously, and | |
10548 | -- of course we already know the list of choices corresponding | |
39a0c1d3 | 10549 | -- to the others choice (it's the list we're replacing). |
d6f39728 | 10550 | |
d9f6a4ee | 10551 | -- We only want to do this if the expander is active, since |
39a0c1d3 | 10552 | -- we do not want to clobber the ASIS tree. |
d6f39728 | 10553 | |
d9f6a4ee | 10554 | if Expander_Active then |
10555 | declare | |
10556 | Last_Var : constant Node_Id := | |
10557 | Last_Non_Pragma (Variants (VP)); | |
d6f39728 | 10558 | |
d9f6a4ee | 10559 | Others_Node : Node_Id; |
d6f39728 | 10560 | |
d9f6a4ee | 10561 | begin |
10562 | if Nkind (First (Discrete_Choices (Last_Var))) /= | |
10563 | N_Others_Choice | |
10564 | then | |
10565 | Others_Node := Make_Others_Choice (Sloc (Last_Var)); | |
10566 | Set_Others_Discrete_Choices | |
10567 | (Others_Node, Discrete_Choices (Last_Var)); | |
10568 | Set_Discrete_Choices | |
10569 | (Last_Var, New_List (Others_Node)); | |
10570 | end if; | |
10571 | end; | |
10572 | end if; | |
d6f39728 | 10573 | end if; |
d9f6a4ee | 10574 | end Check_Variant_Part; |
d6f39728 | 10575 | end if; |
d9f6a4ee | 10576 | end Freeze_Entity_Checks; |
d6f39728 | 10577 | |
10578 | ------------------------- | |
10579 | -- Get_Alignment_Value -- | |
10580 | ------------------------- | |
10581 | ||
10582 | function Get_Alignment_Value (Expr : Node_Id) return Uint is | |
10583 | Align : constant Uint := Static_Integer (Expr); | |
10584 | ||
10585 | begin | |
10586 | if Align = No_Uint then | |
10587 | return No_Uint; | |
10588 | ||
10589 | elsif Align <= 0 then | |
10590 | Error_Msg_N ("alignment value must be positive", Expr); | |
10591 | return No_Uint; | |
10592 | ||
10593 | else | |
10594 | for J in Int range 0 .. 64 loop | |
10595 | declare | |
10596 | M : constant Uint := Uint_2 ** J; | |
10597 | ||
10598 | begin | |
10599 | exit when M = Align; | |
10600 | ||
10601 | if M > Align then | |
10602 | Error_Msg_N | |
10603 | ("alignment value must be power of 2", Expr); | |
10604 | return No_Uint; | |
10605 | end if; | |
10606 | end; | |
10607 | end loop; | |
10608 | ||
10609 | return Align; | |
10610 | end if; | |
10611 | end Get_Alignment_Value; | |
10612 | ||
99a2d5bd | 10613 | ------------------------------------- |
10614 | -- Inherit_Aspects_At_Freeze_Point -- | |
10615 | ------------------------------------- | |
10616 | ||
10617 | procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is | |
10618 | function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
10619 | (Rep_Item : Node_Id) return Boolean; | |
10620 | -- This routine checks if Rep_Item is either a pragma or an aspect | |
10621 | -- specification node whose correponding pragma (if any) is present in | |
10622 | -- the Rep Item chain of the entity it has been specified to. | |
10623 | ||
10624 | -------------------------------------------------- | |
10625 | -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item -- | |
10626 | -------------------------------------------------- | |
10627 | ||
10628 | function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
10629 | (Rep_Item : Node_Id) return Boolean | |
10630 | is | |
10631 | begin | |
ec6f6da5 | 10632 | return |
10633 | Nkind (Rep_Item) = N_Pragma | |
10634 | or else Present_In_Rep_Item | |
10635 | (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item)); | |
99a2d5bd | 10636 | end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item; |
10637 | ||
29a9d4be | 10638 | -- Start of processing for Inherit_Aspects_At_Freeze_Point |
10639 | ||
99a2d5bd | 10640 | begin |
10641 | -- A representation item is either subtype-specific (Size and Alignment | |
10642 | -- clauses) or type-related (all others). Subtype-specific aspects may | |
29a9d4be | 10643 | -- differ for different subtypes of the same type (RM 13.1.8). |
99a2d5bd | 10644 | |
10645 | -- A derived type inherits each type-related representation aspect of | |
10646 | -- its parent type that was directly specified before the declaration of | |
29a9d4be | 10647 | -- the derived type (RM 13.1.15). |
99a2d5bd | 10648 | |
10649 | -- A derived subtype inherits each subtype-specific representation | |
10650 | -- aspect of its parent subtype that was directly specified before the | |
29a9d4be | 10651 | -- declaration of the derived type (RM 13.1.15). |
99a2d5bd | 10652 | |
10653 | -- The general processing involves inheriting a representation aspect | |
10654 | -- from a parent type whenever the first rep item (aspect specification, | |
10655 | -- attribute definition clause, pragma) corresponding to the given | |
10656 | -- representation aspect in the rep item chain of Typ, if any, isn't | |
10657 | -- directly specified to Typ but to one of its parents. | |
10658 | ||
10659 | -- ??? Note that, for now, just a limited number of representation | |
29a9d4be | 10660 | -- aspects have been inherited here so far. Many of them are |
10661 | -- still inherited in Sem_Ch3. This will be fixed soon. Here is | |
10662 | -- a non- exhaustive list of aspects that likely also need to | |
10663 | -- be moved to this routine: Alignment, Component_Alignment, | |
10664 | -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates, | |
99a2d5bd | 10665 | -- Preelaborable_Initialization, RM_Size and Small. |
10666 | ||
8b6e9bf2 | 10667 | -- In addition, Convention must be propagated from base type to subtype, |
10668 | -- because the subtype may have been declared on an incomplete view. | |
10669 | ||
99a2d5bd | 10670 | if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then |
10671 | return; | |
10672 | end if; | |
10673 | ||
10674 | -- Ada_05/Ada_2005 | |
10675 | ||
10676 | if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False) | |
10677 | and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005) | |
10678 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
10679 | (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)) | |
10680 | then | |
10681 | Set_Is_Ada_2005_Only (Typ); | |
10682 | end if; | |
10683 | ||
10684 | -- Ada_12/Ada_2012 | |
10685 | ||
10686 | if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False) | |
10687 | and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012) | |
10688 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
10689 | (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)) | |
10690 | then | |
10691 | Set_Is_Ada_2012_Only (Typ); | |
10692 | end if; | |
10693 | ||
10694 | -- Atomic/Shared | |
10695 | ||
10696 | if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False) | |
10697 | and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared) | |
10698 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
10699 | (Get_Rep_Item (Typ, Name_Atomic, Name_Shared)) | |
10700 | then | |
10701 | Set_Is_Atomic (Typ); | |
10702 | Set_Treat_As_Volatile (Typ); | |
10703 | Set_Is_Volatile (Typ); | |
10704 | end if; | |
10705 | ||
8b6e9bf2 | 10706 | -- Convention |
10707 | ||
7ac4254e | 10708 | if Is_Record_Type (Typ) |
10709 | and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ)) | |
10710 | then | |
8b6e9bf2 | 10711 | Set_Convention (Typ, Convention (Base_Type (Typ))); |
10712 | end if; | |
10713 | ||
29a9d4be | 10714 | -- Default_Component_Value |
99a2d5bd | 10715 | |
10716 | if Is_Array_Type (Typ) | |
f3d70f08 | 10717 | and then Is_Base_Type (Typ) |
99a2d5bd | 10718 | and then Has_Rep_Item (Typ, Name_Default_Component_Value, False) |
10719 | and then Has_Rep_Item (Typ, Name_Default_Component_Value) | |
10720 | then | |
10721 | Set_Default_Aspect_Component_Value (Typ, | |
10722 | Default_Aspect_Component_Value | |
10723 | (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value)))); | |
10724 | end if; | |
10725 | ||
29a9d4be | 10726 | -- Default_Value |
99a2d5bd | 10727 | |
10728 | if Is_Scalar_Type (Typ) | |
f3d70f08 | 10729 | and then Is_Base_Type (Typ) |
99a2d5bd | 10730 | and then Has_Rep_Item (Typ, Name_Default_Value, False) |
10731 | and then Has_Rep_Item (Typ, Name_Default_Value) | |
10732 | then | |
10733 | Set_Default_Aspect_Value (Typ, | |
10734 | Default_Aspect_Value | |
10735 | (Entity (Get_Rep_Item (Typ, Name_Default_Value)))); | |
10736 | end if; | |
10737 | ||
10738 | -- Discard_Names | |
10739 | ||
10740 | if not Has_Rep_Item (Typ, Name_Discard_Names, False) | |
10741 | and then Has_Rep_Item (Typ, Name_Discard_Names) | |
10742 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
10743 | (Get_Rep_Item (Typ, Name_Discard_Names)) | |
10744 | then | |
10745 | Set_Discard_Names (Typ); | |
10746 | end if; | |
10747 | ||
10748 | -- Invariants | |
10749 | ||
10750 | if not Has_Rep_Item (Typ, Name_Invariant, False) | |
10751 | and then Has_Rep_Item (Typ, Name_Invariant) | |
10752 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
10753 | (Get_Rep_Item (Typ, Name_Invariant)) | |
10754 | then | |
10755 | Set_Has_Invariants (Typ); | |
10756 | ||
10757 | if Class_Present (Get_Rep_Item (Typ, Name_Invariant)) then | |
10758 | Set_Has_Inheritable_Invariants (Typ); | |
10759 | end if; | |
d7487d7d | 10760 | |
953378ae | 10761 | -- If we have a subtype with invariants, whose base type does not have |
10762 | -- invariants, copy these invariants to the base type. This happens for | |
10763 | -- the case of implicit base types created for scalar and array types. | |
d7487d7d | 10764 | |
953378ae | 10765 | elsif Has_Invariants (Typ) |
d7487d7d | 10766 | and then not Has_Invariants (Base_Type (Typ)) |
10767 | then | |
10768 | Set_Has_Invariants (Base_Type (Typ)); | |
10769 | Set_Invariant_Procedure (Base_Type (Typ), Invariant_Procedure (Typ)); | |
99a2d5bd | 10770 | end if; |
10771 | ||
10772 | -- Volatile | |
10773 | ||
10774 | if not Has_Rep_Item (Typ, Name_Volatile, False) | |
10775 | and then Has_Rep_Item (Typ, Name_Volatile) | |
10776 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
10777 | (Get_Rep_Item (Typ, Name_Volatile)) | |
10778 | then | |
10779 | Set_Treat_As_Volatile (Typ); | |
10780 | Set_Is_Volatile (Typ); | |
10781 | end if; | |
10782 | ||
10783 | -- Inheritance for derived types only | |
10784 | ||
10785 | if Is_Derived_Type (Typ) then | |
10786 | declare | |
10787 | Bas_Typ : constant Entity_Id := Base_Type (Typ); | |
10788 | Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ); | |
10789 | ||
10790 | begin | |
10791 | -- Atomic_Components | |
10792 | ||
10793 | if not Has_Rep_Item (Typ, Name_Atomic_Components, False) | |
10794 | and then Has_Rep_Item (Typ, Name_Atomic_Components) | |
10795 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
10796 | (Get_Rep_Item (Typ, Name_Atomic_Components)) | |
10797 | then | |
10798 | Set_Has_Atomic_Components (Imp_Bas_Typ); | |
10799 | end if; | |
10800 | ||
10801 | -- Volatile_Components | |
10802 | ||
10803 | if not Has_Rep_Item (Typ, Name_Volatile_Components, False) | |
10804 | and then Has_Rep_Item (Typ, Name_Volatile_Components) | |
10805 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
10806 | (Get_Rep_Item (Typ, Name_Volatile_Components)) | |
10807 | then | |
10808 | Set_Has_Volatile_Components (Imp_Bas_Typ); | |
10809 | end if; | |
10810 | ||
10811 | -- Finalize_Storage_Only. | |
10812 | ||
10813 | if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False) | |
10814 | and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only) | |
10815 | then | |
10816 | Set_Finalize_Storage_Only (Bas_Typ); | |
10817 | end if; | |
10818 | ||
10819 | -- Universal_Aliasing | |
10820 | ||
10821 | if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False) | |
10822 | and then Has_Rep_Item (Typ, Name_Universal_Aliasing) | |
10823 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
10824 | (Get_Rep_Item (Typ, Name_Universal_Aliasing)) | |
10825 | then | |
10826 | Set_Universal_Aliasing (Imp_Bas_Typ); | |
10827 | end if; | |
10828 | ||
10829 | -- Record type specific aspects | |
10830 | ||
10831 | if Is_Record_Type (Typ) then | |
29a9d4be | 10832 | |
99a2d5bd | 10833 | -- Bit_Order |
10834 | ||
10835 | if not Has_Rep_Item (Typ, Name_Bit_Order, False) | |
10836 | and then Has_Rep_Item (Typ, Name_Bit_Order) | |
10837 | then | |
10838 | Set_Reverse_Bit_Order (Bas_Typ, | |
10839 | Reverse_Bit_Order (Entity (Name | |
10840 | (Get_Rep_Item (Typ, Name_Bit_Order))))); | |
10841 | end if; | |
10842 | ||
10843 | -- Scalar_Storage_Order | |
10844 | ||
10845 | if not Has_Rep_Item (Typ, Name_Scalar_Storage_Order, False) | |
10846 | and then Has_Rep_Item (Typ, Name_Scalar_Storage_Order) | |
10847 | then | |
10848 | Set_Reverse_Storage_Order (Bas_Typ, | |
10849 | Reverse_Storage_Order (Entity (Name | |
10850 | (Get_Rep_Item (Typ, Name_Scalar_Storage_Order))))); | |
b64082f2 | 10851 | |
10852 | -- Clear default SSO indications, since the inherited aspect | |
10853 | -- which was set explicitly overrides the default. | |
10854 | ||
10855 | Set_SSO_Set_Low_By_Default (Bas_Typ, False); | |
10856 | Set_SSO_Set_High_By_Default (Bas_Typ, False); | |
99a2d5bd | 10857 | end if; |
10858 | end if; | |
10859 | end; | |
10860 | end if; | |
10861 | end Inherit_Aspects_At_Freeze_Point; | |
10862 | ||
d6f39728 | 10863 | ---------------- |
10864 | -- Initialize -- | |
10865 | ---------------- | |
10866 | ||
10867 | procedure Initialize is | |
10868 | begin | |
7717ea00 | 10869 | Address_Clause_Checks.Init; |
10870 | Independence_Checks.Init; | |
d6f39728 | 10871 | Unchecked_Conversions.Init; |
10872 | end Initialize; | |
10873 | ||
2625eb01 | 10874 | --------------------------- |
10875 | -- Install_Discriminants -- | |
10876 | --------------------------- | |
10877 | ||
10878 | procedure Install_Discriminants (E : Entity_Id) is | |
10879 | Disc : Entity_Id; | |
10880 | Prev : Entity_Id; | |
10881 | begin | |
10882 | Disc := First_Discriminant (E); | |
10883 | while Present (Disc) loop | |
10884 | Prev := Current_Entity (Disc); | |
10885 | Set_Current_Entity (Disc); | |
10886 | Set_Is_Immediately_Visible (Disc); | |
10887 | Set_Homonym (Disc, Prev); | |
10888 | Next_Discriminant (Disc); | |
10889 | end loop; | |
10890 | end Install_Discriminants; | |
10891 | ||
d6f39728 | 10892 | ------------------------- |
10893 | -- Is_Operational_Item -- | |
10894 | ------------------------- | |
10895 | ||
10896 | function Is_Operational_Item (N : Node_Id) return Boolean is | |
10897 | begin | |
10898 | if Nkind (N) /= N_Attribute_Definition_Clause then | |
10899 | return False; | |
b9e61b2a | 10900 | |
d6f39728 | 10901 | else |
10902 | declare | |
b9e61b2a | 10903 | Id : constant Attribute_Id := Get_Attribute_Id (Chars (N)); |
d6f39728 | 10904 | begin |
b9e61b2a | 10905 | return Id = Attribute_Input |
d6f39728 | 10906 | or else Id = Attribute_Output |
10907 | or else Id = Attribute_Read | |
f15731c4 | 10908 | or else Id = Attribute_Write |
10909 | or else Id = Attribute_External_Tag; | |
d6f39728 | 10910 | end; |
10911 | end if; | |
10912 | end Is_Operational_Item; | |
10913 | ||
3b23aaa0 | 10914 | ------------------------- |
10915 | -- Is_Predicate_Static -- | |
10916 | ------------------------- | |
10917 | ||
94d896aa | 10918 | -- Note: the basic legality of the expression has already been checked, so |
10919 | -- we don't need to worry about cases or ranges on strings for example. | |
10920 | ||
3b23aaa0 | 10921 | function Is_Predicate_Static |
10922 | (Expr : Node_Id; | |
10923 | Nam : Name_Id) return Boolean | |
10924 | is | |
10925 | function All_Static_Case_Alternatives (L : List_Id) return Boolean; | |
973c2fba | 10926 | -- Given a list of case expression alternatives, returns True if all |
10927 | -- the alternatives are static (have all static choices, and a static | |
10928 | -- expression). | |
3b23aaa0 | 10929 | |
10930 | function All_Static_Choices (L : List_Id) return Boolean; | |
a360a0f7 | 10931 | -- Returns true if all elements of the list are OK static choices |
3b23aaa0 | 10932 | -- as defined below for Is_Static_Choice. Used for case expression |
973c2fba | 10933 | -- alternatives and for the right operand of a membership test. An |
10934 | -- others_choice is static if the corresponding expression is static. | |
7c0c95b8 | 10935 | -- The staticness of the bounds is checked separately. |
3b23aaa0 | 10936 | |
10937 | function Is_Static_Choice (N : Node_Id) return Boolean; | |
10938 | -- Returns True if N represents a static choice (static subtype, or | |
a360a0f7 | 10939 | -- static subtype indication, or static expression, or static range). |
3b23aaa0 | 10940 | -- |
10941 | -- Note that this is a bit more inclusive than we actually need | |
10942 | -- (in particular membership tests do not allow the use of subtype | |
a360a0f7 | 10943 | -- indications). But that doesn't matter, we have already checked |
3b23aaa0 | 10944 | -- that the construct is legal to get this far. |
10945 | ||
10946 | function Is_Type_Ref (N : Node_Id) return Boolean; | |
10947 | pragma Inline (Is_Type_Ref); | |
973c2fba | 10948 | -- Returns True if N is a reference to the type for the predicate in the |
10949 | -- expression (i.e. if it is an identifier whose Chars field matches the | |
10950 | -- Nam given in the call). N must not be parenthesized, if the type name | |
10951 | -- appears in parens, this routine will return False. | |
3b23aaa0 | 10952 | |
10953 | ---------------------------------- | |
10954 | -- All_Static_Case_Alternatives -- | |
10955 | ---------------------------------- | |
10956 | ||
10957 | function All_Static_Case_Alternatives (L : List_Id) return Boolean is | |
10958 | N : Node_Id; | |
10959 | ||
10960 | begin | |
10961 | N := First (L); | |
10962 | while Present (N) loop | |
10963 | if not (All_Static_Choices (Discrete_Choices (N)) | |
10964 | and then Is_OK_Static_Expression (Expression (N))) | |
10965 | then | |
10966 | return False; | |
10967 | end if; | |
10968 | ||
10969 | Next (N); | |
10970 | end loop; | |
10971 | ||
10972 | return True; | |
10973 | end All_Static_Case_Alternatives; | |
10974 | ||
10975 | ------------------------ | |
10976 | -- All_Static_Choices -- | |
10977 | ------------------------ | |
10978 | ||
10979 | function All_Static_Choices (L : List_Id) return Boolean is | |
10980 | N : Node_Id; | |
10981 | ||
10982 | begin | |
10983 | N := First (L); | |
10984 | while Present (N) loop | |
10985 | if not Is_Static_Choice (N) then | |
10986 | return False; | |
10987 | end if; | |
10988 | ||
10989 | Next (N); | |
10990 | end loop; | |
10991 | ||
10992 | return True; | |
10993 | end All_Static_Choices; | |
10994 | ||
10995 | ---------------------- | |
10996 | -- Is_Static_Choice -- | |
10997 | ---------------------- | |
10998 | ||
10999 | function Is_Static_Choice (N : Node_Id) return Boolean is | |
11000 | begin | |
7c0c95b8 | 11001 | return Nkind (N) = N_Others_Choice |
11002 | or else Is_OK_Static_Expression (N) | |
3b23aaa0 | 11003 | or else (Is_Entity_Name (N) and then Is_Type (Entity (N)) |
11004 | and then Is_OK_Static_Subtype (Entity (N))) | |
11005 | or else (Nkind (N) = N_Subtype_Indication | |
11006 | and then Is_OK_Static_Subtype (Entity (N))) | |
11007 | or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N)); | |
11008 | end Is_Static_Choice; | |
11009 | ||
11010 | ----------------- | |
11011 | -- Is_Type_Ref -- | |
11012 | ----------------- | |
11013 | ||
11014 | function Is_Type_Ref (N : Node_Id) return Boolean is | |
11015 | begin | |
11016 | return Nkind (N) = N_Identifier | |
11017 | and then Chars (N) = Nam | |
11018 | and then Paren_Count (N) = 0; | |
11019 | end Is_Type_Ref; | |
11020 | ||
11021 | -- Start of processing for Is_Predicate_Static | |
11022 | ||
11023 | begin | |
3b23aaa0 | 11024 | -- Predicate_Static means one of the following holds. Numbers are the |
11025 | -- corresponding paragraph numbers in (RM 3.2.4(16-22)). | |
11026 | ||
11027 | -- 16: A static expression | |
11028 | ||
11029 | if Is_OK_Static_Expression (Expr) then | |
11030 | return True; | |
11031 | ||
11032 | -- 17: A membership test whose simple_expression is the current | |
11033 | -- instance, and whose membership_choice_list meets the requirements | |
11034 | -- for a static membership test. | |
11035 | ||
11036 | elsif Nkind (Expr) in N_Membership_Test | |
11037 | and then ((Present (Right_Opnd (Expr)) | |
11038 | and then Is_Static_Choice (Right_Opnd (Expr))) | |
11039 | or else | |
11040 | (Present (Alternatives (Expr)) | |
11041 | and then All_Static_Choices (Alternatives (Expr)))) | |
11042 | then | |
11043 | return True; | |
11044 | ||
11045 | -- 18. A case_expression whose selecting_expression is the current | |
11046 | -- instance, and whose dependent expressions are static expressions. | |
11047 | ||
11048 | elsif Nkind (Expr) = N_Case_Expression | |
11049 | and then Is_Type_Ref (Expression (Expr)) | |
11050 | and then All_Static_Case_Alternatives (Alternatives (Expr)) | |
11051 | then | |
11052 | return True; | |
11053 | ||
11054 | -- 19. A call to a predefined equality or ordering operator, where one | |
11055 | -- operand is the current instance, and the other is a static | |
11056 | -- expression. | |
11057 | ||
94d896aa | 11058 | -- Note: the RM is clearly wrong here in not excluding string types. |
11059 | -- Without this exclusion, we would allow expressions like X > "ABC" | |
11060 | -- to be considered as predicate-static, which is clearly not intended, | |
11061 | -- since the idea is for predicate-static to be a subset of normal | |
11062 | -- static expressions (and "DEF" > "ABC" is not a static expression). | |
11063 | ||
11064 | -- However, we do allow internally generated (not from source) equality | |
11065 | -- and inequality operations to be valid on strings (this helps deal | |
11066 | -- with cases where we transform A in "ABC" to A = "ABC). | |
11067 | ||
3b23aaa0 | 11068 | elsif Nkind (Expr) in N_Op_Compare |
94d896aa | 11069 | and then ((not Is_String_Type (Etype (Left_Opnd (Expr)))) |
11070 | or else (Nkind_In (Expr, N_Op_Eq, N_Op_Ne) | |
11071 | and then not Comes_From_Source (Expr))) | |
3b23aaa0 | 11072 | and then ((Is_Type_Ref (Left_Opnd (Expr)) |
11073 | and then Is_OK_Static_Expression (Right_Opnd (Expr))) | |
11074 | or else | |
11075 | (Is_Type_Ref (Right_Opnd (Expr)) | |
11076 | and then Is_OK_Static_Expression (Left_Opnd (Expr)))) | |
11077 | then | |
11078 | return True; | |
11079 | ||
11080 | -- 20. A call to a predefined boolean logical operator, where each | |
11081 | -- operand is predicate-static. | |
11082 | ||
11083 | elsif (Nkind_In (Expr, N_Op_And, N_Op_Or, N_Op_Xor) | |
11084 | and then Is_Predicate_Static (Left_Opnd (Expr), Nam) | |
11085 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam)) | |
11086 | or else | |
11087 | (Nkind (Expr) = N_Op_Not | |
11088 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam)) | |
11089 | then | |
11090 | return True; | |
11091 | ||
11092 | -- 21. A short-circuit control form where both operands are | |
11093 | -- predicate-static. | |
11094 | ||
11095 | elsif Nkind (Expr) in N_Short_Circuit | |
11096 | and then Is_Predicate_Static (Left_Opnd (Expr), Nam) | |
11097 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam) | |
11098 | then | |
11099 | return True; | |
11100 | ||
11101 | -- 22. A parenthesized predicate-static expression. This does not | |
11102 | -- require any special test, since we just ignore paren levels in | |
11103 | -- all the cases above. | |
11104 | ||
11105 | -- One more test that is an implementation artifact caused by the fact | |
499918a7 | 11106 | -- that we are analyzing not the original expression, but the generated |
3b23aaa0 | 11107 | -- expression in the body of the predicate function. This can include |
a360a0f7 | 11108 | -- references to inherited predicates, so that the expression we are |
3b23aaa0 | 11109 | -- processing looks like: |
11110 | ||
11111 | -- expression and then xxPredicate (typ (Inns)) | |
11112 | ||
11113 | -- Where the call is to a Predicate function for an inherited predicate. | |
11114 | -- We simply ignore such a call (which could be to either a dynamic or | |
499918a7 | 11115 | -- a static predicate, but remember that we can have a Static_Predicate |
3b23aaa0 | 11116 | -- for a non-static subtype). |
11117 | ||
11118 | elsif Nkind (Expr) = N_Function_Call | |
11119 | and then Is_Predicate_Function (Entity (Name (Expr))) | |
11120 | then | |
11121 | return True; | |
11122 | ||
11123 | -- That's an exhaustive list of tests, all other cases are not | |
a360a0f7 | 11124 | -- predicate-static, so we return False. |
3b23aaa0 | 11125 | |
11126 | else | |
11127 | return False; | |
11128 | end if; | |
11129 | end Is_Predicate_Static; | |
11130 | ||
2ff55065 | 11131 | --------------------- |
11132 | -- Kill_Rep_Clause -- | |
11133 | --------------------- | |
11134 | ||
11135 | procedure Kill_Rep_Clause (N : Node_Id) is | |
11136 | begin | |
11137 | pragma Assert (Ignore_Rep_Clauses); | |
360f426f | 11138 | |
11139 | -- Note: we use Replace rather than Rewrite, because we don't want | |
11140 | -- ASIS to be able to use Original_Node to dig out the (undecorated) | |
11141 | -- rep clause that is being replaced. | |
11142 | ||
4949ddd5 | 11143 | Replace (N, Make_Null_Statement (Sloc (N))); |
360f426f | 11144 | |
11145 | -- The null statement must be marked as not coming from source. This is | |
37c6552c | 11146 | -- so that ASIS ignores it, and also the back end does not expect bogus |
360f426f | 11147 | -- "from source" null statements in weird places (e.g. in declarative |
11148 | -- regions where such null statements are not allowed). | |
11149 | ||
11150 | Set_Comes_From_Source (N, False); | |
2ff55065 | 11151 | end Kill_Rep_Clause; |
11152 | ||
d6f39728 | 11153 | ------------------ |
11154 | -- Minimum_Size -- | |
11155 | ------------------ | |
11156 | ||
11157 | function Minimum_Size | |
11158 | (T : Entity_Id; | |
d5b349fa | 11159 | Biased : Boolean := False) return Nat |
d6f39728 | 11160 | is |
11161 | Lo : Uint := No_Uint; | |
11162 | Hi : Uint := No_Uint; | |
11163 | LoR : Ureal := No_Ureal; | |
11164 | HiR : Ureal := No_Ureal; | |
11165 | LoSet : Boolean := False; | |
11166 | HiSet : Boolean := False; | |
11167 | B : Uint; | |
11168 | S : Nat; | |
11169 | Ancest : Entity_Id; | |
f15731c4 | 11170 | R_Typ : constant Entity_Id := Root_Type (T); |
d6f39728 | 11171 | |
11172 | begin | |
11173 | -- If bad type, return 0 | |
11174 | ||
11175 | if T = Any_Type then | |
11176 | return 0; | |
11177 | ||
11178 | -- For generic types, just return zero. There cannot be any legitimate | |
11179 | -- need to know such a size, but this routine may be called with a | |
11180 | -- generic type as part of normal processing. | |
11181 | ||
f02a9a9a | 11182 | elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then |
d6f39728 | 11183 | return 0; |
11184 | ||
74c7ae52 | 11185 | -- Access types (cannot have size smaller than System.Address) |
d6f39728 | 11186 | |
11187 | elsif Is_Access_Type (T) then | |
74c7ae52 | 11188 | return System_Address_Size; |
d6f39728 | 11189 | |
11190 | -- Floating-point types | |
11191 | ||
11192 | elsif Is_Floating_Point_Type (T) then | |
f15731c4 | 11193 | return UI_To_Int (Esize (R_Typ)); |
d6f39728 | 11194 | |
11195 | -- Discrete types | |
11196 | ||
11197 | elsif Is_Discrete_Type (T) then | |
11198 | ||
fdd294d1 | 11199 | -- The following loop is looking for the nearest compile time known |
11200 | -- bounds following the ancestor subtype chain. The idea is to find | |
11201 | -- the most restrictive known bounds information. | |
d6f39728 | 11202 | |
11203 | Ancest := T; | |
11204 | loop | |
11205 | if Ancest = Any_Type or else Etype (Ancest) = Any_Type then | |
11206 | return 0; | |
11207 | end if; | |
11208 | ||
11209 | if not LoSet then | |
11210 | if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then | |
11211 | Lo := Expr_Rep_Value (Type_Low_Bound (Ancest)); | |
11212 | LoSet := True; | |
11213 | exit when HiSet; | |
11214 | end if; | |
11215 | end if; | |
11216 | ||
11217 | if not HiSet then | |
11218 | if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then | |
11219 | Hi := Expr_Rep_Value (Type_High_Bound (Ancest)); | |
11220 | HiSet := True; | |
11221 | exit when LoSet; | |
11222 | end if; | |
11223 | end if; | |
11224 | ||
11225 | Ancest := Ancestor_Subtype (Ancest); | |
11226 | ||
11227 | if No (Ancest) then | |
11228 | Ancest := Base_Type (T); | |
11229 | ||
11230 | if Is_Generic_Type (Ancest) then | |
11231 | return 0; | |
11232 | end if; | |
11233 | end if; | |
11234 | end loop; | |
11235 | ||
11236 | -- Fixed-point types. We can't simply use Expr_Value to get the | |
fdd294d1 | 11237 | -- Corresponding_Integer_Value values of the bounds, since these do not |
11238 | -- get set till the type is frozen, and this routine can be called | |
11239 | -- before the type is frozen. Similarly the test for bounds being static | |
11240 | -- needs to include the case where we have unanalyzed real literals for | |
11241 | -- the same reason. | |
d6f39728 | 11242 | |
11243 | elsif Is_Fixed_Point_Type (T) then | |
11244 | ||
fdd294d1 | 11245 | -- The following loop is looking for the nearest compile time known |
11246 | -- bounds following the ancestor subtype chain. The idea is to find | |
11247 | -- the most restrictive known bounds information. | |
d6f39728 | 11248 | |
11249 | Ancest := T; | |
11250 | loop | |
11251 | if Ancest = Any_Type or else Etype (Ancest) = Any_Type then | |
11252 | return 0; | |
11253 | end if; | |
11254 | ||
3062c401 | 11255 | -- Note: In the following two tests for LoSet and HiSet, it may |
11256 | -- seem redundant to test for N_Real_Literal here since normally | |
11257 | -- one would assume that the test for the value being known at | |
11258 | -- compile time includes this case. However, there is a glitch. | |
11259 | -- If the real literal comes from folding a non-static expression, | |
11260 | -- then we don't consider any non- static expression to be known | |
11261 | -- at compile time if we are in configurable run time mode (needed | |
11262 | -- in some cases to give a clearer definition of what is and what | |
11263 | -- is not accepted). So the test is indeed needed. Without it, we | |
11264 | -- would set neither Lo_Set nor Hi_Set and get an infinite loop. | |
11265 | ||
d6f39728 | 11266 | if not LoSet then |
11267 | if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal | |
11268 | or else Compile_Time_Known_Value (Type_Low_Bound (Ancest)) | |
11269 | then | |
11270 | LoR := Expr_Value_R (Type_Low_Bound (Ancest)); | |
11271 | LoSet := True; | |
11272 | exit when HiSet; | |
11273 | end if; | |
11274 | end if; | |
11275 | ||
11276 | if not HiSet then | |
11277 | if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal | |
11278 | or else Compile_Time_Known_Value (Type_High_Bound (Ancest)) | |
11279 | then | |
11280 | HiR := Expr_Value_R (Type_High_Bound (Ancest)); | |
11281 | HiSet := True; | |
11282 | exit when LoSet; | |
11283 | end if; | |
11284 | end if; | |
11285 | ||
11286 | Ancest := Ancestor_Subtype (Ancest); | |
11287 | ||
11288 | if No (Ancest) then | |
11289 | Ancest := Base_Type (T); | |
11290 | ||
11291 | if Is_Generic_Type (Ancest) then | |
11292 | return 0; | |
11293 | end if; | |
11294 | end if; | |
11295 | end loop; | |
11296 | ||
11297 | Lo := UR_To_Uint (LoR / Small_Value (T)); | |
11298 | Hi := UR_To_Uint (HiR / Small_Value (T)); | |
11299 | ||
11300 | -- No other types allowed | |
11301 | ||
11302 | else | |
11303 | raise Program_Error; | |
11304 | end if; | |
11305 | ||
2866d595 | 11306 | -- Fall through with Hi and Lo set. Deal with biased case |
d6f39728 | 11307 | |
cc46ff4b | 11308 | if (Biased |
11309 | and then not Is_Fixed_Point_Type (T) | |
11310 | and then not (Is_Enumeration_Type (T) | |
11311 | and then Has_Non_Standard_Rep (T))) | |
d6f39728 | 11312 | or else Has_Biased_Representation (T) |
11313 | then | |
11314 | Hi := Hi - Lo; | |
11315 | Lo := Uint_0; | |
11316 | end if; | |
11317 | ||
11318 | -- Signed case. Note that we consider types like range 1 .. -1 to be | |
fdd294d1 | 11319 | -- signed for the purpose of computing the size, since the bounds have |
1a34e48c | 11320 | -- to be accommodated in the base type. |
d6f39728 | 11321 | |
11322 | if Lo < 0 or else Hi < 0 then | |
11323 | S := 1; | |
11324 | B := Uint_1; | |
11325 | ||
da253936 | 11326 | -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1)) |
11327 | -- Note that we accommodate the case where the bounds cross. This | |
d6f39728 | 11328 | -- can happen either because of the way the bounds are declared |
11329 | -- or because of the algorithm in Freeze_Fixed_Point_Type. | |
11330 | ||
11331 | while Lo < -B | |
11332 | or else Hi < -B | |
11333 | or else Lo >= B | |
11334 | or else Hi >= B | |
11335 | loop | |
11336 | B := Uint_2 ** S; | |
11337 | S := S + 1; | |
11338 | end loop; | |
11339 | ||
11340 | -- Unsigned case | |
11341 | ||
11342 | else | |
11343 | -- If both bounds are positive, make sure that both are represen- | |
11344 | -- table in the case where the bounds are crossed. This can happen | |
11345 | -- either because of the way the bounds are declared, or because of | |
11346 | -- the algorithm in Freeze_Fixed_Point_Type. | |
11347 | ||
11348 | if Lo > Hi then | |
11349 | Hi := Lo; | |
11350 | end if; | |
11351 | ||
da253936 | 11352 | -- S = size, (can accommodate 0 .. (2**size - 1)) |
d6f39728 | 11353 | |
11354 | S := 0; | |
11355 | while Hi >= Uint_2 ** S loop | |
11356 | S := S + 1; | |
11357 | end loop; | |
11358 | end if; | |
11359 | ||
11360 | return S; | |
11361 | end Minimum_Size; | |
11362 | ||
44e4341e | 11363 | --------------------------- |
11364 | -- New_Stream_Subprogram -- | |
11365 | --------------------------- | |
d6f39728 | 11366 | |
44e4341e | 11367 | procedure New_Stream_Subprogram |
11368 | (N : Node_Id; | |
11369 | Ent : Entity_Id; | |
11370 | Subp : Entity_Id; | |
11371 | Nam : TSS_Name_Type) | |
d6f39728 | 11372 | is |
11373 | Loc : constant Source_Ptr := Sloc (N); | |
9dfe12ae | 11374 | Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam); |
f15731c4 | 11375 | Subp_Id : Entity_Id; |
d6f39728 | 11376 | Subp_Decl : Node_Id; |
11377 | F : Entity_Id; | |
11378 | Etyp : Entity_Id; | |
11379 | ||
44e4341e | 11380 | Defer_Declaration : constant Boolean := |
11381 | Is_Tagged_Type (Ent) or else Is_Private_Type (Ent); | |
11382 | -- For a tagged type, there is a declaration for each stream attribute | |
11383 | -- at the freeze point, and we must generate only a completion of this | |
11384 | -- declaration. We do the same for private types, because the full view | |
11385 | -- might be tagged. Otherwise we generate a declaration at the point of | |
11386 | -- the attribute definition clause. | |
11387 | ||
f15731c4 | 11388 | function Build_Spec return Node_Id; |
11389 | -- Used for declaration and renaming declaration, so that this is | |
11390 | -- treated as a renaming_as_body. | |
11391 | ||
11392 | ---------------- | |
11393 | -- Build_Spec -- | |
11394 | ---------------- | |
11395 | ||
d5b349fa | 11396 | function Build_Spec return Node_Id is |
44e4341e | 11397 | Out_P : constant Boolean := (Nam = TSS_Stream_Read); |
11398 | Formals : List_Id; | |
11399 | Spec : Node_Id; | |
83c6c069 | 11400 | T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc); |
44e4341e | 11401 | |
f15731c4 | 11402 | begin |
9dfe12ae | 11403 | Subp_Id := Make_Defining_Identifier (Loc, Sname); |
f15731c4 | 11404 | |
44e4341e | 11405 | -- S : access Root_Stream_Type'Class |
11406 | ||
11407 | Formals := New_List ( | |
11408 | Make_Parameter_Specification (Loc, | |
11409 | Defining_Identifier => | |
11410 | Make_Defining_Identifier (Loc, Name_S), | |
11411 | Parameter_Type => | |
11412 | Make_Access_Definition (Loc, | |
11413 | Subtype_Mark => | |
83c6c069 | 11414 | New_Occurrence_Of ( |
44e4341e | 11415 | Designated_Type (Etype (F)), Loc)))); |
11416 | ||
11417 | if Nam = TSS_Stream_Input then | |
4bba0a8d | 11418 | Spec := |
11419 | Make_Function_Specification (Loc, | |
11420 | Defining_Unit_Name => Subp_Id, | |
11421 | Parameter_Specifications => Formals, | |
11422 | Result_Definition => T_Ref); | |
44e4341e | 11423 | else |
11424 | -- V : [out] T | |
f15731c4 | 11425 | |
44e4341e | 11426 | Append_To (Formals, |
11427 | Make_Parameter_Specification (Loc, | |
11428 | Defining_Identifier => Make_Defining_Identifier (Loc, Name_V), | |
11429 | Out_Present => Out_P, | |
11430 | Parameter_Type => T_Ref)); | |
f15731c4 | 11431 | |
d3ef794c | 11432 | Spec := |
11433 | Make_Procedure_Specification (Loc, | |
11434 | Defining_Unit_Name => Subp_Id, | |
11435 | Parameter_Specifications => Formals); | |
44e4341e | 11436 | end if; |
f15731c4 | 11437 | |
44e4341e | 11438 | return Spec; |
11439 | end Build_Spec; | |
d6f39728 | 11440 | |
44e4341e | 11441 | -- Start of processing for New_Stream_Subprogram |
d6f39728 | 11442 | |
44e4341e | 11443 | begin |
11444 | F := First_Formal (Subp); | |
11445 | ||
11446 | if Ekind (Subp) = E_Procedure then | |
11447 | Etyp := Etype (Next_Formal (F)); | |
d6f39728 | 11448 | else |
44e4341e | 11449 | Etyp := Etype (Subp); |
d6f39728 | 11450 | end if; |
f15731c4 | 11451 | |
44e4341e | 11452 | -- Prepare subprogram declaration and insert it as an action on the |
11453 | -- clause node. The visibility for this entity is used to test for | |
11454 | -- visibility of the attribute definition clause (in the sense of | |
11455 | -- 8.3(23) as amended by AI-195). | |
9dfe12ae | 11456 | |
44e4341e | 11457 | if not Defer_Declaration then |
f15731c4 | 11458 | Subp_Decl := |
11459 | Make_Subprogram_Declaration (Loc, | |
11460 | Specification => Build_Spec); | |
44e4341e | 11461 | |
11462 | -- For a tagged type, there is always a visible declaration for each | |
15ebb600 | 11463 | -- stream TSS (it is a predefined primitive operation), and the |
44e4341e | 11464 | -- completion of this declaration occurs at the freeze point, which is |
11465 | -- not always visible at places where the attribute definition clause is | |
11466 | -- visible. So, we create a dummy entity here for the purpose of | |
11467 | -- tracking the visibility of the attribute definition clause itself. | |
11468 | ||
11469 | else | |
11470 | Subp_Id := | |
55868293 | 11471 | Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V')); |
44e4341e | 11472 | Subp_Decl := |
11473 | Make_Object_Declaration (Loc, | |
11474 | Defining_Identifier => Subp_Id, | |
11475 | Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc)); | |
f15731c4 | 11476 | end if; |
11477 | ||
44e4341e | 11478 | Insert_Action (N, Subp_Decl); |
11479 | Set_Entity (N, Subp_Id); | |
11480 | ||
d6f39728 | 11481 | Subp_Decl := |
11482 | Make_Subprogram_Renaming_Declaration (Loc, | |
f15731c4 | 11483 | Specification => Build_Spec, |
83c6c069 | 11484 | Name => New_Occurrence_Of (Subp, Loc)); |
d6f39728 | 11485 | |
44e4341e | 11486 | if Defer_Declaration then |
d6f39728 | 11487 | Set_TSS (Base_Type (Ent), Subp_Id); |
11488 | else | |
11489 | Insert_Action (N, Subp_Decl); | |
11490 | Copy_TSS (Subp_Id, Base_Type (Ent)); | |
11491 | end if; | |
44e4341e | 11492 | end New_Stream_Subprogram; |
d6f39728 | 11493 | |
2625eb01 | 11494 | ------------------------------------------ |
11495 | -- Push_Scope_And_Install_Discriminants -- | |
11496 | ------------------------------------------ | |
11497 | ||
11498 | procedure Push_Scope_And_Install_Discriminants (E : Entity_Id) is | |
11499 | begin | |
11500 | if Has_Discriminants (E) then | |
11501 | Push_Scope (E); | |
11502 | ||
11503 | -- Make discriminants visible for type declarations and protected | |
11504 | -- type declarations, not for subtype declarations (RM 13.1.1 (12/3)) | |
11505 | ||
11506 | if Nkind (Parent (E)) /= N_Subtype_Declaration then | |
11507 | Install_Discriminants (E); | |
11508 | end if; | |
11509 | end if; | |
11510 | end Push_Scope_And_Install_Discriminants; | |
11511 | ||
d6f39728 | 11512 | ------------------------ |
11513 | -- Rep_Item_Too_Early -- | |
11514 | ------------------------ | |
11515 | ||
80d4fec4 | 11516 | function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is |
d6f39728 | 11517 | begin |
44e4341e | 11518 | -- Cannot apply non-operational rep items to generic types |
d6f39728 | 11519 | |
f15731c4 | 11520 | if Is_Operational_Item (N) then |
11521 | return False; | |
11522 | ||
11523 | elsif Is_Type (T) | |
d6f39728 | 11524 | and then Is_Generic_Type (Root_Type (T)) |
11525 | then | |
503f7fd3 | 11526 | Error_Msg_N ("representation item not allowed for generic type", N); |
d6f39728 | 11527 | return True; |
11528 | end if; | |
11529 | ||
fdd294d1 | 11530 | -- Otherwise check for incomplete type |
d6f39728 | 11531 | |
11532 | if Is_Incomplete_Or_Private_Type (T) | |
11533 | and then No (Underlying_Type (T)) | |
d64221a7 | 11534 | and then |
11535 | (Nkind (N) /= N_Pragma | |
60014bc9 | 11536 | or else Get_Pragma_Id (N) /= Pragma_Import) |
d6f39728 | 11537 | then |
11538 | Error_Msg_N | |
11539 | ("representation item must be after full type declaration", N); | |
11540 | return True; | |
11541 | ||
1a34e48c | 11542 | -- If the type has incomplete components, a representation clause is |
d6f39728 | 11543 | -- illegal but stream attributes and Convention pragmas are correct. |
11544 | ||
11545 | elsif Has_Private_Component (T) then | |
f15731c4 | 11546 | if Nkind (N) = N_Pragma then |
d6f39728 | 11547 | return False; |
b9e61b2a | 11548 | |
d6f39728 | 11549 | else |
11550 | Error_Msg_N | |
11551 | ("representation item must appear after type is fully defined", | |
11552 | N); | |
11553 | return True; | |
11554 | end if; | |
11555 | else | |
11556 | return False; | |
11557 | end if; | |
11558 | end Rep_Item_Too_Early; | |
11559 | ||
11560 | ----------------------- | |
11561 | -- Rep_Item_Too_Late -- | |
11562 | ----------------------- | |
11563 | ||
11564 | function Rep_Item_Too_Late | |
11565 | (T : Entity_Id; | |
11566 | N : Node_Id; | |
d5b349fa | 11567 | FOnly : Boolean := False) return Boolean |
d6f39728 | 11568 | is |
11569 | S : Entity_Id; | |
11570 | Parent_Type : Entity_Id; | |
11571 | ||
4d0944e9 | 11572 | procedure No_Type_Rep_Item; |
11573 | -- Output message indicating that no type-related aspects can be | |
11574 | -- specified due to some property of the parent type. | |
11575 | ||
d6f39728 | 11576 | procedure Too_Late; |
4d0944e9 | 11577 | -- Output message for an aspect being specified too late |
11578 | ||
11579 | -- Note that neither of the above errors is considered a serious one, | |
11580 | -- since the effect is simply that we ignore the representation clause | |
11581 | -- in these cases. | |
04d38ee4 | 11582 | -- Is this really true? In any case if we make this change we must |
11583 | -- document the requirement in the spec of Rep_Item_Too_Late that | |
11584 | -- if True is returned, then the rep item must be completely ignored??? | |
4d0944e9 | 11585 | |
11586 | ---------------------- | |
11587 | -- No_Type_Rep_Item -- | |
11588 | ---------------------- | |
11589 | ||
11590 | procedure No_Type_Rep_Item is | |
11591 | begin | |
11592 | Error_Msg_N ("|type-related representation item not permitted!", N); | |
11593 | end No_Type_Rep_Item; | |
d53a018a | 11594 | |
11595 | -------------- | |
11596 | -- Too_Late -- | |
11597 | -------------- | |
d6f39728 | 11598 | |
11599 | procedure Too_Late is | |
11600 | begin | |
ce4da1ed | 11601 | -- Other compilers seem more relaxed about rep items appearing too |
11602 | -- late. Since analysis tools typically don't care about rep items | |
11603 | -- anyway, no reason to be too strict about this. | |
11604 | ||
a9cd517c | 11605 | if not Relaxed_RM_Semantics then |
11606 | Error_Msg_N ("|representation item appears too late!", N); | |
11607 | end if; | |
d6f39728 | 11608 | end Too_Late; |
11609 | ||
11610 | -- Start of processing for Rep_Item_Too_Late | |
11611 | ||
11612 | begin | |
a3248fc4 | 11613 | -- First make sure entity is not frozen (RM 13.1(9)) |
d6f39728 | 11614 | |
11615 | if Is_Frozen (T) | |
a3248fc4 | 11616 | |
11617 | -- Exclude imported types, which may be frozen if they appear in a | |
11618 | -- representation clause for a local type. | |
11619 | ||
4aa270d8 | 11620 | and then not From_Limited_With (T) |
a3248fc4 | 11621 | |
a9cd517c | 11622 | -- Exclude generated entities (not coming from source). The common |
a3248fc4 | 11623 | -- case is when we generate a renaming which prematurely freezes the |
11624 | -- renamed internal entity, but we still want to be able to set copies | |
11625 | -- of attribute values such as Size/Alignment. | |
11626 | ||
11627 | and then Comes_From_Source (T) | |
d6f39728 | 11628 | then |
11629 | Too_Late; | |
11630 | S := First_Subtype (T); | |
11631 | ||
11632 | if Present (Freeze_Node (S)) then | |
04d38ee4 | 11633 | if not Relaxed_RM_Semantics then |
11634 | Error_Msg_NE | |
11635 | ("??no more representation items for }", Freeze_Node (S), S); | |
11636 | end if; | |
d6f39728 | 11637 | end if; |
11638 | ||
11639 | return True; | |
11640 | ||
d1a2e31b | 11641 | -- Check for case of untagged derived type whose parent either has |
4d0944e9 | 11642 | -- primitive operations, or is a by reference type (RM 13.1(10)). In |
11643 | -- this case we do not output a Too_Late message, since there is no | |
11644 | -- earlier point where the rep item could be placed to make it legal. | |
d6f39728 | 11645 | |
11646 | elsif Is_Type (T) | |
11647 | and then not FOnly | |
11648 | and then Is_Derived_Type (T) | |
11649 | and then not Is_Tagged_Type (T) | |
11650 | then | |
11651 | Parent_Type := Etype (Base_Type (T)); | |
11652 | ||
11653 | if Has_Primitive_Operations (Parent_Type) then | |
4d0944e9 | 11654 | No_Type_Rep_Item; |
04d38ee4 | 11655 | |
11656 | if not Relaxed_RM_Semantics then | |
11657 | Error_Msg_NE | |
11658 | ("\parent type & has primitive operations!", N, Parent_Type); | |
11659 | end if; | |
11660 | ||
d6f39728 | 11661 | return True; |
11662 | ||
11663 | elsif Is_By_Reference_Type (Parent_Type) then | |
4d0944e9 | 11664 | No_Type_Rep_Item; |
04d38ee4 | 11665 | |
11666 | if not Relaxed_RM_Semantics then | |
11667 | Error_Msg_NE | |
11668 | ("\parent type & is a by reference type!", N, Parent_Type); | |
11669 | end if; | |
11670 | ||
d6f39728 | 11671 | return True; |
11672 | end if; | |
11673 | end if; | |
11674 | ||
04d38ee4 | 11675 | -- No error, but one more warning to consider. The RM (surprisingly) |
11676 | -- allows this pattern: | |
11677 | ||
11678 | -- type S is ... | |
11679 | -- primitive operations for S | |
11680 | -- type R is new S; | |
11681 | -- rep clause for S | |
11682 | ||
11683 | -- Meaning that calls on the primitive operations of S for values of | |
11684 | -- type R may require possibly expensive implicit conversion operations. | |
11685 | -- This is not an error, but is worth a warning. | |
11686 | ||
11687 | if not Relaxed_RM_Semantics and then Is_Type (T) then | |
11688 | declare | |
11689 | DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T)); | |
11690 | ||
11691 | begin | |
11692 | if Present (DTL) | |
11693 | and then Has_Primitive_Operations (Base_Type (T)) | |
11694 | ||
11695 | -- For now, do not generate this warning for the case of aspect | |
11696 | -- specification using Ada 2012 syntax, since we get wrong | |
11697 | -- messages we do not understand. The whole business of derived | |
11698 | -- types and rep items seems a bit confused when aspects are | |
11699 | -- used, since the aspects are not evaluated till freeze time. | |
11700 | ||
11701 | and then not From_Aspect_Specification (N) | |
11702 | then | |
11703 | Error_Msg_Sloc := Sloc (DTL); | |
11704 | Error_Msg_N | |
11705 | ("representation item for& appears after derived type " | |
11706 | & "declaration#??", N); | |
11707 | Error_Msg_NE | |
11708 | ("\may result in implicit conversions for primitive " | |
11709 | & "operations of&??", N, T); | |
11710 | Error_Msg_NE | |
11711 | ("\to change representations when called with arguments " | |
11712 | & "of type&??", N, DTL); | |
11713 | end if; | |
11714 | end; | |
11715 | end if; | |
11716 | ||
3062c401 | 11717 | -- No error, link item into head of chain of rep items for the entity, |
11718 | -- but avoid chaining if we have an overloadable entity, and the pragma | |
11719 | -- is one that can apply to multiple overloaded entities. | |
11720 | ||
b9e61b2a | 11721 | if Is_Overloadable (T) and then Nkind (N) = N_Pragma then |
fdd294d1 | 11722 | declare |
11723 | Pname : constant Name_Id := Pragma_Name (N); | |
11724 | begin | |
18393965 | 11725 | if Nam_In (Pname, Name_Convention, Name_Import, Name_Export, |
11726 | Name_External, Name_Interface) | |
fdd294d1 | 11727 | then |
11728 | return False; | |
11729 | end if; | |
11730 | end; | |
3062c401 | 11731 | end if; |
11732 | ||
fdd294d1 | 11733 | Record_Rep_Item (T, N); |
d6f39728 | 11734 | return False; |
11735 | end Rep_Item_Too_Late; | |
11736 | ||
2072eaa9 | 11737 | ------------------------------------- |
11738 | -- Replace_Type_References_Generic -- | |
11739 | ------------------------------------- | |
11740 | ||
37c6552c | 11741 | procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is |
11742 | TName : constant Name_Id := Chars (T); | |
2072eaa9 | 11743 | |
11744 | function Replace_Node (N : Node_Id) return Traverse_Result; | |
11745 | -- Processes a single node in the traversal procedure below, checking | |
11746 | -- if node N should be replaced, and if so, doing the replacement. | |
11747 | ||
11748 | procedure Replace_Type_Refs is new Traverse_Proc (Replace_Node); | |
11749 | -- This instantiation provides the body of Replace_Type_References | |
11750 | ||
11751 | ------------------ | |
11752 | -- Replace_Node -- | |
11753 | ------------------ | |
11754 | ||
11755 | function Replace_Node (N : Node_Id) return Traverse_Result is | |
11756 | S : Entity_Id; | |
11757 | P : Node_Id; | |
11758 | ||
11759 | begin | |
11760 | -- Case of identifier | |
11761 | ||
11762 | if Nkind (N) = N_Identifier then | |
11763 | ||
37c6552c | 11764 | -- If not the type name, check whether it is a reference to |
11765 | -- some other type, which must be frozen before the predicate | |
11766 | -- function is analyzed, i.e. before the freeze node of the | |
11767 | -- type to which the predicate applies. | |
2072eaa9 | 11768 | |
11769 | if Chars (N) /= TName then | |
37c6552c | 11770 | if Present (Current_Entity (N)) |
11771 | and then Is_Type (Current_Entity (N)) | |
11772 | then | |
11773 | Freeze_Before (Freeze_Node (T), Current_Entity (N)); | |
11774 | end if; | |
11775 | ||
2072eaa9 | 11776 | return Skip; |
11777 | ||
11778 | -- Otherwise do the replacement and we are done with this node | |
11779 | ||
11780 | else | |
11781 | Replace_Type_Reference (N); | |
11782 | return Skip; | |
11783 | end if; | |
11784 | ||
11785 | -- Case of selected component (which is what a qualification | |
11786 | -- looks like in the unanalyzed tree, which is what we have. | |
11787 | ||
11788 | elsif Nkind (N) = N_Selected_Component then | |
11789 | ||
11790 | -- If selector name is not our type, keeping going (we might | |
11791 | -- still have an occurrence of the type in the prefix). | |
11792 | ||
11793 | if Nkind (Selector_Name (N)) /= N_Identifier | |
11794 | or else Chars (Selector_Name (N)) /= TName | |
11795 | then | |
11796 | return OK; | |
11797 | ||
11798 | -- Selector name is our type, check qualification | |
11799 | ||
11800 | else | |
11801 | -- Loop through scopes and prefixes, doing comparison | |
11802 | ||
11803 | S := Current_Scope; | |
11804 | P := Prefix (N); | |
11805 | loop | |
11806 | -- Continue if no more scopes or scope with no name | |
11807 | ||
11808 | if No (S) or else Nkind (S) not in N_Has_Chars then | |
11809 | return OK; | |
11810 | end if; | |
11811 | ||
11812 | -- Do replace if prefix is an identifier matching the | |
11813 | -- scope that we are currently looking at. | |
11814 | ||
11815 | if Nkind (P) = N_Identifier | |
11816 | and then Chars (P) = Chars (S) | |
11817 | then | |
11818 | Replace_Type_Reference (N); | |
11819 | return Skip; | |
11820 | end if; | |
11821 | ||
11822 | -- Go check scope above us if prefix is itself of the | |
11823 | -- form of a selected component, whose selector matches | |
11824 | -- the scope we are currently looking at. | |
11825 | ||
11826 | if Nkind (P) = N_Selected_Component | |
11827 | and then Nkind (Selector_Name (P)) = N_Identifier | |
11828 | and then Chars (Selector_Name (P)) = Chars (S) | |
11829 | then | |
11830 | S := Scope (S); | |
11831 | P := Prefix (P); | |
11832 | ||
11833 | -- For anything else, we don't have a match, so keep on | |
11834 | -- going, there are still some weird cases where we may | |
11835 | -- still have a replacement within the prefix. | |
11836 | ||
11837 | else | |
11838 | return OK; | |
11839 | end if; | |
11840 | end loop; | |
11841 | end if; | |
11842 | ||
ec6f6da5 | 11843 | -- Continue for any other node kind |
2072eaa9 | 11844 | |
11845 | else | |
11846 | return OK; | |
11847 | end if; | |
11848 | end Replace_Node; | |
11849 | ||
11850 | begin | |
11851 | Replace_Type_Refs (N); | |
11852 | end Replace_Type_References_Generic; | |
11853 | ||
d6f39728 | 11854 | ------------------------- |
11855 | -- Same_Representation -- | |
11856 | ------------------------- | |
11857 | ||
11858 | function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is | |
11859 | T1 : constant Entity_Id := Underlying_Type (Typ1); | |
11860 | T2 : constant Entity_Id := Underlying_Type (Typ2); | |
11861 | ||
11862 | begin | |
11863 | -- A quick check, if base types are the same, then we definitely have | |
11864 | -- the same representation, because the subtype specific representation | |
11865 | -- attributes (Size and Alignment) do not affect representation from | |
11866 | -- the point of view of this test. | |
11867 | ||
11868 | if Base_Type (T1) = Base_Type (T2) then | |
11869 | return True; | |
11870 | ||
11871 | elsif Is_Private_Type (Base_Type (T2)) | |
11872 | and then Base_Type (T1) = Full_View (Base_Type (T2)) | |
11873 | then | |
11874 | return True; | |
11875 | end if; | |
11876 | ||
11877 | -- Tagged types never have differing representations | |
11878 | ||
11879 | if Is_Tagged_Type (T1) then | |
11880 | return True; | |
11881 | end if; | |
11882 | ||
11883 | -- Representations are definitely different if conventions differ | |
11884 | ||
11885 | if Convention (T1) /= Convention (T2) then | |
11886 | return False; | |
11887 | end if; | |
11888 | ||
ef0772bc | 11889 | -- Representations are different if component alignments or scalar |
11890 | -- storage orders differ. | |
d6f39728 | 11891 | |
11892 | if (Is_Record_Type (T1) or else Is_Array_Type (T1)) | |
726fd56a | 11893 | and then |
d6f39728 | 11894 | (Is_Record_Type (T2) or else Is_Array_Type (T2)) |
ef0772bc | 11895 | and then |
11896 | (Component_Alignment (T1) /= Component_Alignment (T2) | |
f02a9a9a | 11897 | or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2)) |
d6f39728 | 11898 | then |
11899 | return False; | |
11900 | end if; | |
11901 | ||
11902 | -- For arrays, the only real issue is component size. If we know the | |
11903 | -- component size for both arrays, and it is the same, then that's | |
11904 | -- good enough to know we don't have a change of representation. | |
11905 | ||
11906 | if Is_Array_Type (T1) then | |
11907 | if Known_Component_Size (T1) | |
11908 | and then Known_Component_Size (T2) | |
11909 | and then Component_Size (T1) = Component_Size (T2) | |
11910 | then | |
9f1130cc | 11911 | if VM_Target = No_VM then |
11912 | return True; | |
11913 | ||
11914 | -- In VM targets the representation of arrays with aliased | |
11915 | -- components differs from arrays with non-aliased components | |
11916 | ||
11917 | else | |
11918 | return Has_Aliased_Components (Base_Type (T1)) | |
0ba3592b | 11919 | = |
11920 | Has_Aliased_Components (Base_Type (T2)); | |
9f1130cc | 11921 | end if; |
d6f39728 | 11922 | end if; |
11923 | end if; | |
11924 | ||
11925 | -- Types definitely have same representation if neither has non-standard | |
11926 | -- representation since default representations are always consistent. | |
11927 | -- If only one has non-standard representation, and the other does not, | |
11928 | -- then we consider that they do not have the same representation. They | |
11929 | -- might, but there is no way of telling early enough. | |
11930 | ||
11931 | if Has_Non_Standard_Rep (T1) then | |
11932 | if not Has_Non_Standard_Rep (T2) then | |
11933 | return False; | |
11934 | end if; | |
11935 | else | |
11936 | return not Has_Non_Standard_Rep (T2); | |
11937 | end if; | |
11938 | ||
fdd294d1 | 11939 | -- Here the two types both have non-standard representation, and we need |
11940 | -- to determine if they have the same non-standard representation. | |
d6f39728 | 11941 | |
11942 | -- For arrays, we simply need to test if the component sizes are the | |
11943 | -- same. Pragma Pack is reflected in modified component sizes, so this | |
11944 | -- check also deals with pragma Pack. | |
11945 | ||
11946 | if Is_Array_Type (T1) then | |
11947 | return Component_Size (T1) = Component_Size (T2); | |
11948 | ||
11949 | -- Tagged types always have the same representation, because it is not | |
11950 | -- possible to specify different representations for common fields. | |
11951 | ||
11952 | elsif Is_Tagged_Type (T1) then | |
11953 | return True; | |
11954 | ||
11955 | -- Case of record types | |
11956 | ||
11957 | elsif Is_Record_Type (T1) then | |
11958 | ||
11959 | -- Packed status must conform | |
11960 | ||
11961 | if Is_Packed (T1) /= Is_Packed (T2) then | |
11962 | return False; | |
11963 | ||
11964 | -- Otherwise we must check components. Typ2 maybe a constrained | |
11965 | -- subtype with fewer components, so we compare the components | |
11966 | -- of the base types. | |
11967 | ||
11968 | else | |
11969 | Record_Case : declare | |
11970 | CD1, CD2 : Entity_Id; | |
11971 | ||
11972 | function Same_Rep return Boolean; | |
11973 | -- CD1 and CD2 are either components or discriminants. This | |
ef0772bc | 11974 | -- function tests whether they have the same representation. |
d6f39728 | 11975 | |
80d4fec4 | 11976 | -------------- |
11977 | -- Same_Rep -- | |
11978 | -------------- | |
11979 | ||
d6f39728 | 11980 | function Same_Rep return Boolean is |
11981 | begin | |
11982 | if No (Component_Clause (CD1)) then | |
11983 | return No (Component_Clause (CD2)); | |
d6f39728 | 11984 | else |
ef0772bc | 11985 | -- Note: at this point, component clauses have been |
11986 | -- normalized to the default bit order, so that the | |
11987 | -- comparison of Component_Bit_Offsets is meaningful. | |
11988 | ||
d6f39728 | 11989 | return |
11990 | Present (Component_Clause (CD2)) | |
11991 | and then | |
11992 | Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2) | |
11993 | and then | |
11994 | Esize (CD1) = Esize (CD2); | |
11995 | end if; | |
11996 | end Same_Rep; | |
11997 | ||
1e35409d | 11998 | -- Start of processing for Record_Case |
d6f39728 | 11999 | |
12000 | begin | |
12001 | if Has_Discriminants (T1) then | |
d6f39728 | 12002 | |
9dfe12ae | 12003 | -- The number of discriminants may be different if the |
12004 | -- derived type has fewer (constrained by values). The | |
12005 | -- invisible discriminants retain the representation of | |
12006 | -- the original, so the discrepancy does not per se | |
12007 | -- indicate a different representation. | |
12008 | ||
b9e61b2a | 12009 | CD1 := First_Discriminant (T1); |
12010 | CD2 := First_Discriminant (T2); | |
12011 | while Present (CD1) and then Present (CD2) loop | |
d6f39728 | 12012 | if not Same_Rep then |
12013 | return False; | |
12014 | else | |
12015 | Next_Discriminant (CD1); | |
12016 | Next_Discriminant (CD2); | |
12017 | end if; | |
12018 | end loop; | |
12019 | end if; | |
12020 | ||
12021 | CD1 := First_Component (Underlying_Type (Base_Type (T1))); | |
12022 | CD2 := First_Component (Underlying_Type (Base_Type (T2))); | |
d6f39728 | 12023 | while Present (CD1) loop |
12024 | if not Same_Rep then | |
12025 | return False; | |
12026 | else | |
12027 | Next_Component (CD1); | |
12028 | Next_Component (CD2); | |
12029 | end if; | |
12030 | end loop; | |
12031 | ||
12032 | return True; | |
12033 | end Record_Case; | |
12034 | end if; | |
12035 | ||
12036 | -- For enumeration types, we must check each literal to see if the | |
12037 | -- representation is the same. Note that we do not permit enumeration | |
1a34e48c | 12038 | -- representation clauses for Character and Wide_Character, so these |
d6f39728 | 12039 | -- cases were already dealt with. |
12040 | ||
12041 | elsif Is_Enumeration_Type (T1) then | |
d6f39728 | 12042 | Enumeration_Case : declare |
12043 | L1, L2 : Entity_Id; | |
12044 | ||
12045 | begin | |
12046 | L1 := First_Literal (T1); | |
12047 | L2 := First_Literal (T2); | |
d6f39728 | 12048 | while Present (L1) loop |
12049 | if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then | |
12050 | return False; | |
12051 | else | |
12052 | Next_Literal (L1); | |
12053 | Next_Literal (L2); | |
12054 | end if; | |
12055 | end loop; | |
12056 | ||
12057 | return True; | |
d6f39728 | 12058 | end Enumeration_Case; |
12059 | ||
12060 | -- Any other types have the same representation for these purposes | |
12061 | ||
12062 | else | |
12063 | return True; | |
12064 | end if; | |
d6f39728 | 12065 | end Same_Representation; |
12066 | ||
3061ffde | 12067 | -------------------------------- |
12068 | -- Resolve_Iterable_Operation -- | |
12069 | -------------------------------- | |
12070 | ||
12071 | procedure Resolve_Iterable_Operation | |
12072 | (N : Node_Id; | |
12073 | Cursor : Entity_Id; | |
12074 | Typ : Entity_Id; | |
12075 | Nam : Name_Id) | |
12076 | is | |
12077 | Ent : Entity_Id; | |
12078 | F1 : Entity_Id; | |
12079 | F2 : Entity_Id; | |
12080 | ||
12081 | begin | |
12082 | if not Is_Overloaded (N) then | |
12083 | if not Is_Entity_Name (N) | |
12084 | or else Ekind (Entity (N)) /= E_Function | |
12085 | or else Scope (Entity (N)) /= Scope (Typ) | |
12086 | or else No (First_Formal (Entity (N))) | |
12087 | or else Etype (First_Formal (Entity (N))) /= Typ | |
12088 | then | |
12089 | Error_Msg_N ("iterable primitive must be local function name " | |
12090 | & "whose first formal is an iterable type", N); | |
a9f5fea7 | 12091 | return; |
3061ffde | 12092 | end if; |
12093 | ||
12094 | Ent := Entity (N); | |
12095 | F1 := First_Formal (Ent); | |
12096 | if Nam = Name_First then | |
12097 | ||
12098 | -- First (Container) => Cursor | |
12099 | ||
12100 | if Etype (Ent) /= Cursor then | |
12101 | Error_Msg_N ("primitive for First must yield a curosr", N); | |
12102 | end if; | |
12103 | ||
12104 | elsif Nam = Name_Next then | |
12105 | ||
12106 | -- Next (Container, Cursor) => Cursor | |
12107 | ||
12108 | F2 := Next_Formal (F1); | |
12109 | ||
12110 | if Etype (F2) /= Cursor | |
12111 | or else Etype (Ent) /= Cursor | |
12112 | or else Present (Next_Formal (F2)) | |
12113 | then | |
12114 | Error_Msg_N ("no match for Next iterable primitive", N); | |
12115 | end if; | |
12116 | ||
12117 | elsif Nam = Name_Has_Element then | |
12118 | ||
12119 | -- Has_Element (Container, Cursor) => Boolean | |
12120 | ||
12121 | F2 := Next_Formal (F1); | |
12122 | if Etype (F2) /= Cursor | |
12123 | or else Etype (Ent) /= Standard_Boolean | |
12124 | or else Present (Next_Formal (F2)) | |
12125 | then | |
12126 | Error_Msg_N ("no match for Has_Element iterable primitive", N); | |
12127 | end if; | |
12128 | ||
12129 | elsif Nam = Name_Element then | |
b9b03799 | 12130 | F2 := Next_Formal (F1); |
12131 | ||
12132 | if No (F2) | |
12133 | or else Etype (F2) /= Cursor | |
12134 | or else Present (Next_Formal (F2)) | |
12135 | then | |
12136 | Error_Msg_N ("no match for Element iterable primitive", N); | |
12137 | end if; | |
3061ffde | 12138 | null; |
12139 | ||
12140 | else | |
12141 | raise Program_Error; | |
12142 | end if; | |
12143 | ||
12144 | else | |
12145 | -- Overloaded case: find subprogram with proper signature. | |
12146 | -- Caller will report error if no match is found. | |
12147 | ||
12148 | declare | |
12149 | I : Interp_Index; | |
12150 | It : Interp; | |
12151 | ||
12152 | begin | |
12153 | Get_First_Interp (N, I, It); | |
12154 | while Present (It.Typ) loop | |
12155 | if Ekind (It.Nam) = E_Function | |
b9b03799 | 12156 | and then Scope (It.Nam) = Scope (Typ) |
3061ffde | 12157 | and then Etype (First_Formal (It.Nam)) = Typ |
12158 | then | |
12159 | F1 := First_Formal (It.Nam); | |
12160 | ||
12161 | if Nam = Name_First then | |
12162 | if Etype (It.Nam) = Cursor | |
12163 | and then No (Next_Formal (F1)) | |
12164 | then | |
12165 | Set_Entity (N, It.Nam); | |
12166 | exit; | |
12167 | end if; | |
12168 | ||
12169 | elsif Nam = Name_Next then | |
12170 | F2 := Next_Formal (F1); | |
12171 | ||
12172 | if Present (F2) | |
12173 | and then No (Next_Formal (F2)) | |
12174 | and then Etype (F2) = Cursor | |
12175 | and then Etype (It.Nam) = Cursor | |
12176 | then | |
12177 | Set_Entity (N, It.Nam); | |
12178 | exit; | |
12179 | end if; | |
12180 | ||
12181 | elsif Nam = Name_Has_Element then | |
12182 | F2 := Next_Formal (F1); | |
12183 | ||
12184 | if Present (F2) | |
12185 | and then No (Next_Formal (F2)) | |
12186 | and then Etype (F2) = Cursor | |
12187 | and then Etype (It.Nam) = Standard_Boolean | |
12188 | then | |
12189 | Set_Entity (N, It.Nam); | |
12190 | F2 := Next_Formal (F1); | |
12191 | exit; | |
12192 | end if; | |
12193 | ||
12194 | elsif Nam = Name_Element then | |
b9b03799 | 12195 | F2 := Next_Formal (F1); |
12196 | ||
3061ffde | 12197 | if Present (F2) |
12198 | and then No (Next_Formal (F2)) | |
12199 | and then Etype (F2) = Cursor | |
12200 | then | |
12201 | Set_Entity (N, It.Nam); | |
12202 | exit; | |
12203 | end if; | |
12204 | end if; | |
12205 | end if; | |
12206 | ||
12207 | Get_Next_Interp (I, It); | |
12208 | end loop; | |
12209 | end; | |
12210 | end if; | |
12211 | end Resolve_Iterable_Operation; | |
12212 | ||
b77e4501 | 12213 | ---------------- |
12214 | -- Set_Biased -- | |
12215 | ---------------- | |
12216 | ||
12217 | procedure Set_Biased | |
12218 | (E : Entity_Id; | |
12219 | N : Node_Id; | |
12220 | Msg : String; | |
12221 | Biased : Boolean := True) | |
12222 | is | |
12223 | begin | |
12224 | if Biased then | |
12225 | Set_Has_Biased_Representation (E); | |
12226 | ||
12227 | if Warn_On_Biased_Representation then | |
12228 | Error_Msg_NE | |
1e3532e7 | 12229 | ("?B?" & Msg & " forces biased representation for&", N, E); |
b77e4501 | 12230 | end if; |
12231 | end if; | |
12232 | end Set_Biased; | |
12233 | ||
d6f39728 | 12234 | -------------------- |
12235 | -- Set_Enum_Esize -- | |
12236 | -------------------- | |
12237 | ||
12238 | procedure Set_Enum_Esize (T : Entity_Id) is | |
12239 | Lo : Uint; | |
12240 | Hi : Uint; | |
12241 | Sz : Nat; | |
12242 | ||
12243 | begin | |
12244 | Init_Alignment (T); | |
12245 | ||
12246 | -- Find the minimum standard size (8,16,32,64) that fits | |
12247 | ||
12248 | Lo := Enumeration_Rep (Entity (Type_Low_Bound (T))); | |
12249 | Hi := Enumeration_Rep (Entity (Type_High_Bound (T))); | |
12250 | ||
12251 | if Lo < 0 then | |
12252 | if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then | |
f15731c4 | 12253 | Sz := Standard_Character_Size; -- May be > 8 on some targets |
d6f39728 | 12254 | |
12255 | elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then | |
12256 | Sz := 16; | |
12257 | ||
12258 | elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then | |
12259 | Sz := 32; | |
12260 | ||
12261 | else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63); | |
12262 | Sz := 64; | |
12263 | end if; | |
12264 | ||
12265 | else | |
12266 | if Hi < Uint_2**08 then | |
f15731c4 | 12267 | Sz := Standard_Character_Size; -- May be > 8 on some targets |
d6f39728 | 12268 | |
12269 | elsif Hi < Uint_2**16 then | |
12270 | Sz := 16; | |
12271 | ||
12272 | elsif Hi < Uint_2**32 then | |
12273 | Sz := 32; | |
12274 | ||
12275 | else pragma Assert (Hi < Uint_2**63); | |
12276 | Sz := 64; | |
12277 | end if; | |
12278 | end if; | |
12279 | ||
12280 | -- That minimum is the proper size unless we have a foreign convention | |
12281 | -- and the size required is 32 or less, in which case we bump the size | |
12282 | -- up to 32. This is required for C and C++ and seems reasonable for | |
12283 | -- all other foreign conventions. | |
12284 | ||
12285 | if Has_Foreign_Convention (T) | |
12286 | and then Esize (T) < Standard_Integer_Size | |
db1eed69 | 12287 | |
12288 | -- Don't do this if Short_Enums on target | |
12289 | ||
e9185b9d | 12290 | and then not Target_Short_Enums |
d6f39728 | 12291 | then |
12292 | Init_Esize (T, Standard_Integer_Size); | |
d6f39728 | 12293 | else |
12294 | Init_Esize (T, Sz); | |
12295 | end if; | |
d6f39728 | 12296 | end Set_Enum_Esize; |
12297 | ||
2625eb01 | 12298 | ----------------------------- |
12299 | -- Uninstall_Discriminants -- | |
12300 | ----------------------------- | |
12301 | ||
12302 | procedure Uninstall_Discriminants (E : Entity_Id) is | |
12303 | Disc : Entity_Id; | |
12304 | Prev : Entity_Id; | |
12305 | Outer : Entity_Id; | |
12306 | ||
12307 | begin | |
12308 | -- Discriminants have been made visible for type declarations and | |
12309 | -- protected type declarations, not for subtype declarations. | |
12310 | ||
12311 | if Nkind (Parent (E)) /= N_Subtype_Declaration then | |
12312 | Disc := First_Discriminant (E); | |
12313 | while Present (Disc) loop | |
12314 | if Disc /= Current_Entity (Disc) then | |
12315 | Prev := Current_Entity (Disc); | |
12316 | while Present (Prev) | |
12317 | and then Present (Homonym (Prev)) | |
12318 | and then Homonym (Prev) /= Disc | |
12319 | loop | |
12320 | Prev := Homonym (Prev); | |
12321 | end loop; | |
12322 | else | |
12323 | Prev := Empty; | |
12324 | end if; | |
12325 | ||
12326 | Set_Is_Immediately_Visible (Disc, False); | |
12327 | ||
12328 | Outer := Homonym (Disc); | |
12329 | while Present (Outer) and then Scope (Outer) = E loop | |
12330 | Outer := Homonym (Outer); | |
12331 | end loop; | |
12332 | ||
12333 | -- Reset homonym link of other entities, but do not modify link | |
12334 | -- between entities in current scope, so that the back-end can | |
12335 | -- have a proper count of local overloadings. | |
12336 | ||
12337 | if No (Prev) then | |
12338 | Set_Name_Entity_Id (Chars (Disc), Outer); | |
12339 | ||
12340 | elsif Scope (Prev) /= Scope (Disc) then | |
12341 | Set_Homonym (Prev, Outer); | |
12342 | end if; | |
12343 | ||
12344 | Next_Discriminant (Disc); | |
12345 | end loop; | |
12346 | end if; | |
12347 | end Uninstall_Discriminants; | |
12348 | ||
12349 | ------------------------------------------- | |
12350 | -- Uninstall_Discriminants_And_Pop_Scope -- | |
12351 | ------------------------------------------- | |
12352 | ||
12353 | procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id) is | |
12354 | begin | |
12355 | if Has_Discriminants (E) then | |
12356 | Uninstall_Discriminants (E); | |
12357 | Pop_Scope; | |
12358 | end if; | |
12359 | end Uninstall_Discriminants_And_Pop_Scope; | |
12360 | ||
83f8f0a6 | 12361 | ------------------------------ |
12362 | -- Validate_Address_Clauses -- | |
12363 | ------------------------------ | |
12364 | ||
12365 | procedure Validate_Address_Clauses is | |
12366 | begin | |
12367 | for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop | |
12368 | declare | |
12369 | ACCR : Address_Clause_Check_Record | |
12370 | renames Address_Clause_Checks.Table (J); | |
12371 | ||
d6da7448 | 12372 | Expr : Node_Id; |
12373 | ||
83f8f0a6 | 12374 | X_Alignment : Uint; |
12375 | Y_Alignment : Uint; | |
12376 | ||
12377 | X_Size : Uint; | |
12378 | Y_Size : Uint; | |
12379 | ||
12380 | begin | |
12381 | -- Skip processing of this entry if warning already posted | |
12382 | ||
12383 | if not Address_Warning_Posted (ACCR.N) then | |
d6da7448 | 12384 | Expr := Original_Node (Expression (ACCR.N)); |
83f8f0a6 | 12385 | |
d6da7448 | 12386 | -- Get alignments |
83f8f0a6 | 12387 | |
d6da7448 | 12388 | X_Alignment := Alignment (ACCR.X); |
12389 | Y_Alignment := Alignment (ACCR.Y); | |
83f8f0a6 | 12390 | |
12391 | -- Similarly obtain sizes | |
12392 | ||
d6da7448 | 12393 | X_Size := Esize (ACCR.X); |
12394 | Y_Size := Esize (ACCR.Y); | |
83f8f0a6 | 12395 | |
12396 | -- Check for large object overlaying smaller one | |
12397 | ||
12398 | if Y_Size > Uint_0 | |
12399 | and then X_Size > Uint_0 | |
12400 | and then X_Size > Y_Size | |
12401 | then | |
d6da7448 | 12402 | Error_Msg_NE |
1581f2d7 | 12403 | ("??& overlays smaller object", ACCR.N, ACCR.X); |
83f8f0a6 | 12404 | Error_Msg_N |
1e3532e7 | 12405 | ("\??program execution may be erroneous", ACCR.N); |
83f8f0a6 | 12406 | Error_Msg_Uint_1 := X_Size; |
12407 | Error_Msg_NE | |
1e3532e7 | 12408 | ("\??size of & is ^", ACCR.N, ACCR.X); |
83f8f0a6 | 12409 | Error_Msg_Uint_1 := Y_Size; |
12410 | Error_Msg_NE | |
1e3532e7 | 12411 | ("\??size of & is ^", ACCR.N, ACCR.Y); |
83f8f0a6 | 12412 | |
d6da7448 | 12413 | -- Check for inadequate alignment, both of the base object |
12414 | -- and of the offset, if any. | |
83f8f0a6 | 12415 | |
d6da7448 | 12416 | -- Note: we do not check the alignment if we gave a size |
12417 | -- warning, since it would likely be redundant. | |
83f8f0a6 | 12418 | |
12419 | elsif Y_Alignment /= Uint_0 | |
d6da7448 | 12420 | and then (Y_Alignment < X_Alignment |
12421 | or else (ACCR.Off | |
12422 | and then | |
12423 | Nkind (Expr) = N_Attribute_Reference | |
12424 | and then | |
12425 | Attribute_Name (Expr) = Name_Address | |
12426 | and then | |
12427 | Has_Compatible_Alignment | |
12428 | (ACCR.X, Prefix (Expr)) | |
12429 | /= Known_Compatible)) | |
83f8f0a6 | 12430 | then |
12431 | Error_Msg_NE | |
1e3532e7 | 12432 | ("??specified address for& may be inconsistent " |
12433 | & "with alignment", ACCR.N, ACCR.X); | |
83f8f0a6 | 12434 | Error_Msg_N |
1e3532e7 | 12435 | ("\??program execution may be erroneous (RM 13.3(27))", |
83f8f0a6 | 12436 | ACCR.N); |
12437 | Error_Msg_Uint_1 := X_Alignment; | |
12438 | Error_Msg_NE | |
1e3532e7 | 12439 | ("\??alignment of & is ^", ACCR.N, ACCR.X); |
83f8f0a6 | 12440 | Error_Msg_Uint_1 := Y_Alignment; |
12441 | Error_Msg_NE | |
1e3532e7 | 12442 | ("\??alignment of & is ^", ACCR.N, ACCR.Y); |
d6da7448 | 12443 | if Y_Alignment >= X_Alignment then |
12444 | Error_Msg_N | |
1e3532e7 | 12445 | ("\??but offset is not multiple of alignment", ACCR.N); |
d6da7448 | 12446 | end if; |
83f8f0a6 | 12447 | end if; |
12448 | end if; | |
12449 | end; | |
12450 | end loop; | |
12451 | end Validate_Address_Clauses; | |
12452 | ||
7717ea00 | 12453 | --------------------------- |
12454 | -- Validate_Independence -- | |
12455 | --------------------------- | |
12456 | ||
12457 | procedure Validate_Independence is | |
12458 | SU : constant Uint := UI_From_Int (System_Storage_Unit); | |
12459 | N : Node_Id; | |
12460 | E : Entity_Id; | |
12461 | IC : Boolean; | |
12462 | Comp : Entity_Id; | |
12463 | Addr : Node_Id; | |
12464 | P : Node_Id; | |
12465 | ||
12466 | procedure Check_Array_Type (Atyp : Entity_Id); | |
12467 | -- Checks if the array type Atyp has independent components, and | |
12468 | -- if not, outputs an appropriate set of error messages. | |
12469 | ||
12470 | procedure No_Independence; | |
12471 | -- Output message that independence cannot be guaranteed | |
12472 | ||
12473 | function OK_Component (C : Entity_Id) return Boolean; | |
12474 | -- Checks one component to see if it is independently accessible, and | |
12475 | -- if so yields True, otherwise yields False if independent access | |
12476 | -- cannot be guaranteed. This is a conservative routine, it only | |
12477 | -- returns True if it knows for sure, it returns False if it knows | |
12478 | -- there is a problem, or it cannot be sure there is no problem. | |
12479 | ||
12480 | procedure Reason_Bad_Component (C : Entity_Id); | |
12481 | -- Outputs continuation message if a reason can be determined for | |
12482 | -- the component C being bad. | |
12483 | ||
12484 | ---------------------- | |
12485 | -- Check_Array_Type -- | |
12486 | ---------------------- | |
12487 | ||
12488 | procedure Check_Array_Type (Atyp : Entity_Id) is | |
12489 | Ctyp : constant Entity_Id := Component_Type (Atyp); | |
12490 | ||
12491 | begin | |
12492 | -- OK if no alignment clause, no pack, and no component size | |
12493 | ||
12494 | if not Has_Component_Size_Clause (Atyp) | |
12495 | and then not Has_Alignment_Clause (Atyp) | |
12496 | and then not Is_Packed (Atyp) | |
12497 | then | |
12498 | return; | |
12499 | end if; | |
12500 | ||
aa0a69ab | 12501 | -- Case of component size is greater than or equal to 64 and the |
12502 | -- alignment of the array is at least as large as the alignment | |
12503 | -- of the component. We are definitely OK in this situation. | |
12504 | ||
12505 | if Known_Component_Size (Atyp) | |
12506 | and then Component_Size (Atyp) >= 64 | |
12507 | and then Known_Alignment (Atyp) | |
12508 | and then Known_Alignment (Ctyp) | |
12509 | and then Alignment (Atyp) >= Alignment (Ctyp) | |
12510 | then | |
12511 | return; | |
12512 | end if; | |
12513 | ||
7717ea00 | 12514 | -- Check actual component size |
12515 | ||
12516 | if not Known_Component_Size (Atyp) | |
12517 | or else not (Addressable (Component_Size (Atyp)) | |
aa0a69ab | 12518 | and then Component_Size (Atyp) < 64) |
7717ea00 | 12519 | or else Component_Size (Atyp) mod Esize (Ctyp) /= 0 |
12520 | then | |
12521 | No_Independence; | |
12522 | ||
12523 | -- Bad component size, check reason | |
12524 | ||
12525 | if Has_Component_Size_Clause (Atyp) then | |
b9e61b2a | 12526 | P := Get_Attribute_Definition_Clause |
12527 | (Atyp, Attribute_Component_Size); | |
7717ea00 | 12528 | |
12529 | if Present (P) then | |
12530 | Error_Msg_Sloc := Sloc (P); | |
12531 | Error_Msg_N ("\because of Component_Size clause#", N); | |
12532 | return; | |
12533 | end if; | |
12534 | end if; | |
12535 | ||
12536 | if Is_Packed (Atyp) then | |
12537 | P := Get_Rep_Pragma (Atyp, Name_Pack); | |
12538 | ||
12539 | if Present (P) then | |
12540 | Error_Msg_Sloc := Sloc (P); | |
12541 | Error_Msg_N ("\because of pragma Pack#", N); | |
12542 | return; | |
12543 | end if; | |
12544 | end if; | |
12545 | ||
12546 | -- No reason found, just return | |
12547 | ||
12548 | return; | |
12549 | end if; | |
12550 | ||
12551 | -- Array type is OK independence-wise | |
12552 | ||
12553 | return; | |
12554 | end Check_Array_Type; | |
12555 | ||
12556 | --------------------- | |
12557 | -- No_Independence -- | |
12558 | --------------------- | |
12559 | ||
12560 | procedure No_Independence is | |
12561 | begin | |
12562 | if Pragma_Name (N) = Name_Independent then | |
18393965 | 12563 | Error_Msg_NE ("independence cannot be guaranteed for&", N, E); |
7717ea00 | 12564 | else |
12565 | Error_Msg_NE | |
12566 | ("independent components cannot be guaranteed for&", N, E); | |
12567 | end if; | |
12568 | end No_Independence; | |
12569 | ||
12570 | ------------------ | |
12571 | -- OK_Component -- | |
12572 | ------------------ | |
12573 | ||
12574 | function OK_Component (C : Entity_Id) return Boolean is | |
12575 | Rec : constant Entity_Id := Scope (C); | |
12576 | Ctyp : constant Entity_Id := Etype (C); | |
12577 | ||
12578 | begin | |
12579 | -- OK if no component clause, no Pack, and no alignment clause | |
12580 | ||
12581 | if No (Component_Clause (C)) | |
12582 | and then not Is_Packed (Rec) | |
12583 | and then not Has_Alignment_Clause (Rec) | |
12584 | then | |
12585 | return True; | |
12586 | end if; | |
12587 | ||
12588 | -- Here we look at the actual component layout. A component is | |
12589 | -- addressable if its size is a multiple of the Esize of the | |
12590 | -- component type, and its starting position in the record has | |
12591 | -- appropriate alignment, and the record itself has appropriate | |
12592 | -- alignment to guarantee the component alignment. | |
12593 | ||
12594 | -- Make sure sizes are static, always assume the worst for any | |
12595 | -- cases where we cannot check static values. | |
12596 | ||
12597 | if not (Known_Static_Esize (C) | |
b9e61b2a | 12598 | and then |
12599 | Known_Static_Esize (Ctyp)) | |
7717ea00 | 12600 | then |
12601 | return False; | |
12602 | end if; | |
12603 | ||
12604 | -- Size of component must be addressable or greater than 64 bits | |
12605 | -- and a multiple of bytes. | |
12606 | ||
b9e61b2a | 12607 | if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then |
7717ea00 | 12608 | return False; |
12609 | end if; | |
12610 | ||
12611 | -- Check size is proper multiple | |
12612 | ||
12613 | if Esize (C) mod Esize (Ctyp) /= 0 then | |
12614 | return False; | |
12615 | end if; | |
12616 | ||
12617 | -- Check alignment of component is OK | |
12618 | ||
12619 | if not Known_Component_Bit_Offset (C) | |
12620 | or else Component_Bit_Offset (C) < Uint_0 | |
12621 | or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0 | |
12622 | then | |
12623 | return False; | |
12624 | end if; | |
12625 | ||
12626 | -- Check alignment of record type is OK | |
12627 | ||
12628 | if not Known_Alignment (Rec) | |
12629 | or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0 | |
12630 | then | |
12631 | return False; | |
12632 | end if; | |
12633 | ||
12634 | -- All tests passed, component is addressable | |
12635 | ||
12636 | return True; | |
12637 | end OK_Component; | |
12638 | ||
12639 | -------------------------- | |
12640 | -- Reason_Bad_Component -- | |
12641 | -------------------------- | |
12642 | ||
12643 | procedure Reason_Bad_Component (C : Entity_Id) is | |
12644 | Rec : constant Entity_Id := Scope (C); | |
12645 | Ctyp : constant Entity_Id := Etype (C); | |
12646 | ||
12647 | begin | |
12648 | -- If component clause present assume that's the problem | |
12649 | ||
12650 | if Present (Component_Clause (C)) then | |
12651 | Error_Msg_Sloc := Sloc (Component_Clause (C)); | |
12652 | Error_Msg_N ("\because of Component_Clause#", N); | |
12653 | return; | |
12654 | end if; | |
12655 | ||
12656 | -- If pragma Pack clause present, assume that's the problem | |
12657 | ||
12658 | if Is_Packed (Rec) then | |
12659 | P := Get_Rep_Pragma (Rec, Name_Pack); | |
12660 | ||
12661 | if Present (P) then | |
12662 | Error_Msg_Sloc := Sloc (P); | |
12663 | Error_Msg_N ("\because of pragma Pack#", N); | |
12664 | return; | |
12665 | end if; | |
12666 | end if; | |
12667 | ||
12668 | -- See if record has bad alignment clause | |
12669 | ||
12670 | if Has_Alignment_Clause (Rec) | |
12671 | and then Known_Alignment (Rec) | |
12672 | and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0 | |
12673 | then | |
12674 | P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment); | |
12675 | ||
12676 | if Present (P) then | |
12677 | Error_Msg_Sloc := Sloc (P); | |
12678 | Error_Msg_N ("\because of Alignment clause#", N); | |
12679 | end if; | |
12680 | end if; | |
12681 | ||
12682 | -- Couldn't find a reason, so return without a message | |
12683 | ||
12684 | return; | |
12685 | end Reason_Bad_Component; | |
12686 | ||
12687 | -- Start of processing for Validate_Independence | |
12688 | ||
12689 | begin | |
12690 | for J in Independence_Checks.First .. Independence_Checks.Last loop | |
12691 | N := Independence_Checks.Table (J).N; | |
12692 | E := Independence_Checks.Table (J).E; | |
12693 | IC := Pragma_Name (N) = Name_Independent_Components; | |
12694 | ||
12695 | -- Deal with component case | |
12696 | ||
12697 | if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then | |
12698 | if not OK_Component (E) then | |
12699 | No_Independence; | |
12700 | Reason_Bad_Component (E); | |
12701 | goto Continue; | |
12702 | end if; | |
12703 | end if; | |
12704 | ||
12705 | -- Deal with record with Independent_Components | |
12706 | ||
12707 | if IC and then Is_Record_Type (E) then | |
12708 | Comp := First_Component_Or_Discriminant (E); | |
12709 | while Present (Comp) loop | |
12710 | if not OK_Component (Comp) then | |
12711 | No_Independence; | |
12712 | Reason_Bad_Component (Comp); | |
12713 | goto Continue; | |
12714 | end if; | |
12715 | ||
12716 | Next_Component_Or_Discriminant (Comp); | |
12717 | end loop; | |
12718 | end if; | |
12719 | ||
12720 | -- Deal with address clause case | |
12721 | ||
12722 | if Is_Object (E) then | |
12723 | Addr := Address_Clause (E); | |
12724 | ||
12725 | if Present (Addr) then | |
12726 | No_Independence; | |
12727 | Error_Msg_Sloc := Sloc (Addr); | |
12728 | Error_Msg_N ("\because of Address clause#", N); | |
12729 | goto Continue; | |
12730 | end if; | |
12731 | end if; | |
12732 | ||
12733 | -- Deal with independent components for array type | |
12734 | ||
12735 | if IC and then Is_Array_Type (E) then | |
12736 | Check_Array_Type (E); | |
12737 | end if; | |
12738 | ||
12739 | -- Deal with independent components for array object | |
12740 | ||
12741 | if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then | |
12742 | Check_Array_Type (Etype (E)); | |
12743 | end if; | |
12744 | ||
12745 | <<Continue>> null; | |
12746 | end loop; | |
12747 | end Validate_Independence; | |
12748 | ||
b3f8228a | 12749 | ------------------------------ |
12750 | -- Validate_Iterable_Aspect -- | |
12751 | ------------------------------ | |
12752 | ||
12753 | procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is | |
3061ffde | 12754 | Assoc : Node_Id; |
12755 | Expr : Node_Id; | |
b3f8228a | 12756 | |
bde03454 | 12757 | Prim : Node_Id; |
a9f5fea7 | 12758 | Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ); |
b3f8228a | 12759 | |
12760 | First_Id : Entity_Id; | |
12761 | Next_Id : Entity_Id; | |
12762 | Has_Element_Id : Entity_Id; | |
12763 | Element_Id : Entity_Id; | |
12764 | ||
b3f8228a | 12765 | begin |
9698629c | 12766 | -- If previous error aspect is unusable |
a9f5fea7 | 12767 | |
12768 | if Cursor = Any_Type then | |
3061ffde | 12769 | return; |
12770 | end if; | |
b3f8228a | 12771 | |
12772 | First_Id := Empty; | |
12773 | Next_Id := Empty; | |
12774 | Has_Element_Id := Empty; | |
32de816b | 12775 | Element_Id := Empty; |
b3f8228a | 12776 | |
12777 | -- Each expression must resolve to a function with the proper signature | |
12778 | ||
12779 | Assoc := First (Component_Associations (Expression (ASN))); | |
12780 | while Present (Assoc) loop | |
12781 | Expr := Expression (Assoc); | |
12782 | Analyze (Expr); | |
12783 | ||
b3f8228a | 12784 | Prim := First (Choices (Assoc)); |
bde03454 | 12785 | |
f02a9a9a | 12786 | if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then |
b3f8228a | 12787 | Error_Msg_N ("illegal name in association", Prim); |
12788 | ||
12789 | elsif Chars (Prim) = Name_First then | |
3061ffde | 12790 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First); |
b3f8228a | 12791 | First_Id := Entity (Expr); |
b3f8228a | 12792 | |
12793 | elsif Chars (Prim) = Name_Next then | |
3061ffde | 12794 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next); |
b3f8228a | 12795 | Next_Id := Entity (Expr); |
b3f8228a | 12796 | |
12797 | elsif Chars (Prim) = Name_Has_Element then | |
3061ffde | 12798 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element); |
b3f8228a | 12799 | Has_Element_Id := Entity (Expr); |
bde03454 | 12800 | |
b3f8228a | 12801 | elsif Chars (Prim) = Name_Element then |
3061ffde | 12802 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element); |
b3f8228a | 12803 | Element_Id := Entity (Expr); |
b3f8228a | 12804 | |
12805 | else | |
12806 | Error_Msg_N ("invalid name for iterable function", Prim); | |
12807 | end if; | |
12808 | ||
12809 | Next (Assoc); | |
12810 | end loop; | |
12811 | ||
12812 | if No (First_Id) then | |
3061ffde | 12813 | Error_Msg_N ("match for First primitive not found", ASN); |
b3f8228a | 12814 | |
12815 | elsif No (Next_Id) then | |
3061ffde | 12816 | Error_Msg_N ("match for Next primitive not found", ASN); |
b3f8228a | 12817 | |
12818 | elsif No (Has_Element_Id) then | |
3061ffde | 12819 | Error_Msg_N ("match for Has_Element primitive not found", ASN); |
12820 | ||
12821 | elsif No (Element_Id) then | |
12822 | null; -- Optional. | |
b3f8228a | 12823 | end if; |
12824 | end Validate_Iterable_Aspect; | |
12825 | ||
d6f39728 | 12826 | ----------------------------------- |
12827 | -- Validate_Unchecked_Conversion -- | |
12828 | ----------------------------------- | |
12829 | ||
12830 | procedure Validate_Unchecked_Conversion | |
12831 | (N : Node_Id; | |
12832 | Act_Unit : Entity_Id) | |
12833 | is | |
12834 | Source : Entity_Id; | |
12835 | Target : Entity_Id; | |
12836 | Vnode : Node_Id; | |
12837 | ||
12838 | begin | |
12839 | -- Obtain source and target types. Note that we call Ancestor_Subtype | |
12840 | -- here because the processing for generic instantiation always makes | |
12841 | -- subtypes, and we want the original frozen actual types. | |
12842 | ||
12843 | -- If we are dealing with private types, then do the check on their | |
12844 | -- fully declared counterparts if the full declarations have been | |
39a0c1d3 | 12845 | -- encountered (they don't have to be visible, but they must exist). |
d6f39728 | 12846 | |
12847 | Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit))); | |
12848 | ||
12849 | if Is_Private_Type (Source) | |
12850 | and then Present (Underlying_Type (Source)) | |
12851 | then | |
12852 | Source := Underlying_Type (Source); | |
12853 | end if; | |
12854 | ||
12855 | Target := Ancestor_Subtype (Etype (Act_Unit)); | |
12856 | ||
fdd294d1 | 12857 | -- If either type is generic, the instantiation happens within a generic |
95deda50 | 12858 | -- unit, and there is nothing to check. The proper check will happen |
12859 | -- when the enclosing generic is instantiated. | |
d6f39728 | 12860 | |
12861 | if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then | |
12862 | return; | |
12863 | end if; | |
12864 | ||
12865 | if Is_Private_Type (Target) | |
12866 | and then Present (Underlying_Type (Target)) | |
12867 | then | |
12868 | Target := Underlying_Type (Target); | |
12869 | end if; | |
12870 | ||
12871 | -- Source may be unconstrained array, but not target | |
12872 | ||
b9e61b2a | 12873 | if Is_Array_Type (Target) and then not Is_Constrained (Target) then |
d6f39728 | 12874 | Error_Msg_N |
12875 | ("unchecked conversion to unconstrained array not allowed", N); | |
12876 | return; | |
12877 | end if; | |
12878 | ||
fbc67f84 | 12879 | -- Warn if conversion between two different convention pointers |
12880 | ||
12881 | if Is_Access_Type (Target) | |
12882 | and then Is_Access_Type (Source) | |
12883 | and then Convention (Target) /= Convention (Source) | |
12884 | and then Warn_On_Unchecked_Conversion | |
12885 | then | |
74c7ae52 | 12886 | -- Give warnings for subprogram pointers only on most targets |
fdd294d1 | 12887 | |
12888 | if Is_Access_Subprogram_Type (Target) | |
12889 | or else Is_Access_Subprogram_Type (Source) | |
fdd294d1 | 12890 | then |
12891 | Error_Msg_N | |
cb97ae5c | 12892 | ("?z?conversion between pointers with different conventions!", |
1e3532e7 | 12893 | N); |
fdd294d1 | 12894 | end if; |
fbc67f84 | 12895 | end if; |
12896 | ||
3062c401 | 12897 | -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a |
12898 | -- warning when compiling GNAT-related sources. | |
12899 | ||
12900 | if Warn_On_Unchecked_Conversion | |
12901 | and then not In_Predefined_Unit (N) | |
12902 | and then RTU_Loaded (Ada_Calendar) | |
f02a9a9a | 12903 | and then (Chars (Source) = Name_Time |
12904 | or else | |
12905 | Chars (Target) = Name_Time) | |
3062c401 | 12906 | then |
12907 | -- If Ada.Calendar is loaded and the name of one of the operands is | |
12908 | -- Time, there is a good chance that this is Ada.Calendar.Time. | |
12909 | ||
12910 | declare | |
f02a9a9a | 12911 | Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time)); |
3062c401 | 12912 | begin |
12913 | pragma Assert (Present (Calendar_Time)); | |
12914 | ||
b9e61b2a | 12915 | if Source = Calendar_Time or else Target = Calendar_Time then |
3062c401 | 12916 | Error_Msg_N |
f02a9a9a | 12917 | ("?z?representation of 'Time values may change between " |
12918 | & "'G'N'A'T versions", N); | |
3062c401 | 12919 | end if; |
12920 | end; | |
12921 | end if; | |
12922 | ||
fdd294d1 | 12923 | -- Make entry in unchecked conversion table for later processing by |
12924 | -- Validate_Unchecked_Conversions, which will check sizes and alignments | |
12925 | -- (using values set by the back-end where possible). This is only done | |
12926 | -- if the appropriate warning is active. | |
d6f39728 | 12927 | |
9dfe12ae | 12928 | if Warn_On_Unchecked_Conversion then |
12929 | Unchecked_Conversions.Append | |
86d32751 | 12930 | (New_Val => UC_Entry'(Eloc => Sloc (N), |
12931 | Source => Source, | |
12932 | Target => Target, | |
12933 | Act_Unit => Act_Unit)); | |
9dfe12ae | 12934 | |
12935 | -- If both sizes are known statically now, then back end annotation | |
12936 | -- is not required to do a proper check but if either size is not | |
12937 | -- known statically, then we need the annotation. | |
12938 | ||
12939 | if Known_Static_RM_Size (Source) | |
1e3532e7 | 12940 | and then |
12941 | Known_Static_RM_Size (Target) | |
9dfe12ae | 12942 | then |
12943 | null; | |
12944 | else | |
12945 | Back_Annotate_Rep_Info := True; | |
12946 | end if; | |
12947 | end if; | |
d6f39728 | 12948 | |
fdd294d1 | 12949 | -- If unchecked conversion to access type, and access type is declared |
95deda50 | 12950 | -- in the same unit as the unchecked conversion, then set the flag |
12951 | -- No_Strict_Aliasing (no strict aliasing is implicit here) | |
28ed91d4 | 12952 | |
12953 | if Is_Access_Type (Target) and then | |
12954 | In_Same_Source_Unit (Target, N) | |
12955 | then | |
12956 | Set_No_Strict_Aliasing (Implementation_Base_Type (Target)); | |
12957 | end if; | |
3d875462 | 12958 | |
95deda50 | 12959 | -- Generate N_Validate_Unchecked_Conversion node for back end in case |
12960 | -- the back end needs to perform special validation checks. | |
3d875462 | 12961 | |
95deda50 | 12962 | -- Shouldn't this be in Exp_Ch13, since the check only gets done if we |
12963 | -- have full expansion and the back end is called ??? | |
3d875462 | 12964 | |
12965 | Vnode := | |
12966 | Make_Validate_Unchecked_Conversion (Sloc (N)); | |
12967 | Set_Source_Type (Vnode, Source); | |
12968 | Set_Target_Type (Vnode, Target); | |
12969 | ||
fdd294d1 | 12970 | -- If the unchecked conversion node is in a list, just insert before it. |
12971 | -- If not we have some strange case, not worth bothering about. | |
3d875462 | 12972 | |
12973 | if Is_List_Member (N) then | |
d6f39728 | 12974 | Insert_After (N, Vnode); |
12975 | end if; | |
12976 | end Validate_Unchecked_Conversion; | |
12977 | ||
12978 | ------------------------------------ | |
12979 | -- Validate_Unchecked_Conversions -- | |
12980 | ------------------------------------ | |
12981 | ||
12982 | procedure Validate_Unchecked_Conversions is | |
12983 | begin | |
12984 | for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop | |
12985 | declare | |
12986 | T : UC_Entry renames Unchecked_Conversions.Table (N); | |
12987 | ||
86d32751 | 12988 | Eloc : constant Source_Ptr := T.Eloc; |
12989 | Source : constant Entity_Id := T.Source; | |
12990 | Target : constant Entity_Id := T.Target; | |
12991 | Act_Unit : constant Entity_Id := T.Act_Unit; | |
d6f39728 | 12992 | |
44705307 | 12993 | Source_Siz : Uint; |
12994 | Target_Siz : Uint; | |
d6f39728 | 12995 | |
12996 | begin | |
86d32751 | 12997 | -- Skip if function marked as warnings off |
12998 | ||
12999 | if Warnings_Off (Act_Unit) then | |
13000 | goto Continue; | |
13001 | end if; | |
13002 | ||
fdd294d1 | 13003 | -- This validation check, which warns if we have unequal sizes for |
13004 | -- unchecked conversion, and thus potentially implementation | |
d6f39728 | 13005 | -- dependent semantics, is one of the few occasions on which we |
fdd294d1 | 13006 | -- use the official RM size instead of Esize. See description in |
13007 | -- Einfo "Handling of Type'Size Values" for details. | |
d6f39728 | 13008 | |
f15731c4 | 13009 | if Serious_Errors_Detected = 0 |
d6f39728 | 13010 | and then Known_Static_RM_Size (Source) |
13011 | and then Known_Static_RM_Size (Target) | |
f25f4252 | 13012 | |
13013 | -- Don't do the check if warnings off for either type, note the | |
13014 | -- deliberate use of OR here instead of OR ELSE to get the flag | |
13015 | -- Warnings_Off_Used set for both types if appropriate. | |
13016 | ||
13017 | and then not (Has_Warnings_Off (Source) | |
13018 | or | |
13019 | Has_Warnings_Off (Target)) | |
d6f39728 | 13020 | then |
13021 | Source_Siz := RM_Size (Source); | |
13022 | Target_Siz := RM_Size (Target); | |
13023 | ||
13024 | if Source_Siz /= Target_Siz then | |
299480f9 | 13025 | Error_Msg |
cb97ae5c | 13026 | ("?z?types for unchecked conversion have different sizes!", |
299480f9 | 13027 | Eloc); |
d6f39728 | 13028 | |
13029 | if All_Errors_Mode then | |
13030 | Error_Msg_Name_1 := Chars (Source); | |
13031 | Error_Msg_Uint_1 := Source_Siz; | |
13032 | Error_Msg_Name_2 := Chars (Target); | |
13033 | Error_Msg_Uint_2 := Target_Siz; | |
cb97ae5c | 13034 | Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc); |
d6f39728 | 13035 | |
13036 | Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz); | |
13037 | ||
13038 | if Is_Discrete_Type (Source) | |
b9e61b2a | 13039 | and then |
13040 | Is_Discrete_Type (Target) | |
d6f39728 | 13041 | then |
13042 | if Source_Siz > Target_Siz then | |
299480f9 | 13043 | Error_Msg |
cb97ae5c | 13044 | ("\?z?^ high order bits of source will " |
1e3532e7 | 13045 | & "be ignored!", Eloc); |
d6f39728 | 13046 | |
9dfe12ae | 13047 | elsif Is_Unsigned_Type (Source) then |
299480f9 | 13048 | Error_Msg |
cb97ae5c | 13049 | ("\?z?source will be extended with ^ high order " |
1581f2d7 | 13050 | & "zero bits!", Eloc); |
d6f39728 | 13051 | |
13052 | else | |
299480f9 | 13053 | Error_Msg |
cb97ae5c | 13054 | ("\?z?source will be extended with ^ high order " |
1e3532e7 | 13055 | & "sign bits!", Eloc); |
d6f39728 | 13056 | end if; |
13057 | ||
13058 | elsif Source_Siz < Target_Siz then | |
13059 | if Is_Discrete_Type (Target) then | |
13060 | if Bytes_Big_Endian then | |
299480f9 | 13061 | Error_Msg |
cb97ae5c | 13062 | ("\?z?target value will include ^ undefined " |
1e3532e7 | 13063 | & "low order bits!", Eloc); |
d6f39728 | 13064 | else |
299480f9 | 13065 | Error_Msg |
cb97ae5c | 13066 | ("\?z?target value will include ^ undefined " |
1e3532e7 | 13067 | & "high order bits!", Eloc); |
d6f39728 | 13068 | end if; |
13069 | ||
13070 | else | |
299480f9 | 13071 | Error_Msg |
cb97ae5c | 13072 | ("\?z?^ trailing bits of target value will be " |
1e3532e7 | 13073 | & "undefined!", Eloc); |
d6f39728 | 13074 | end if; |
13075 | ||
13076 | else pragma Assert (Source_Siz > Target_Siz); | |
299480f9 | 13077 | Error_Msg |
cb97ae5c | 13078 | ("\?z?^ trailing bits of source will be ignored!", |
299480f9 | 13079 | Eloc); |
d6f39728 | 13080 | end if; |
13081 | end if; | |
d6f39728 | 13082 | end if; |
13083 | end if; | |
13084 | ||
13085 | -- If both types are access types, we need to check the alignment. | |
13086 | -- If the alignment of both is specified, we can do it here. | |
13087 | ||
f15731c4 | 13088 | if Serious_Errors_Detected = 0 |
2a10e737 | 13089 | and then Is_Access_Type (Source) |
13090 | and then Is_Access_Type (Target) | |
d6f39728 | 13091 | and then Target_Strict_Alignment |
13092 | and then Present (Designated_Type (Source)) | |
13093 | and then Present (Designated_Type (Target)) | |
13094 | then | |
13095 | declare | |
13096 | D_Source : constant Entity_Id := Designated_Type (Source); | |
13097 | D_Target : constant Entity_Id := Designated_Type (Target); | |
13098 | ||
13099 | begin | |
13100 | if Known_Alignment (D_Source) | |
b9e61b2a | 13101 | and then |
13102 | Known_Alignment (D_Target) | |
d6f39728 | 13103 | then |
13104 | declare | |
13105 | Source_Align : constant Uint := Alignment (D_Source); | |
13106 | Target_Align : constant Uint := Alignment (D_Target); | |
13107 | ||
13108 | begin | |
13109 | if Source_Align < Target_Align | |
13110 | and then not Is_Tagged_Type (D_Source) | |
f25f4252 | 13111 | |
13112 | -- Suppress warning if warnings suppressed on either | |
13113 | -- type or either designated type. Note the use of | |
13114 | -- OR here instead of OR ELSE. That is intentional, | |
13115 | -- we would like to set flag Warnings_Off_Used in | |
13116 | -- all types for which warnings are suppressed. | |
13117 | ||
13118 | and then not (Has_Warnings_Off (D_Source) | |
13119 | or | |
13120 | Has_Warnings_Off (D_Target) | |
13121 | or | |
13122 | Has_Warnings_Off (Source) | |
13123 | or | |
13124 | Has_Warnings_Off (Target)) | |
d6f39728 | 13125 | then |
d6f39728 | 13126 | Error_Msg_Uint_1 := Target_Align; |
13127 | Error_Msg_Uint_2 := Source_Align; | |
299480f9 | 13128 | Error_Msg_Node_1 := D_Target; |
d6f39728 | 13129 | Error_Msg_Node_2 := D_Source; |
299480f9 | 13130 | Error_Msg |
cb97ae5c | 13131 | ("?z?alignment of & (^) is stricter than " |
1e3532e7 | 13132 | & "alignment of & (^)!", Eloc); |
f25f4252 | 13133 | Error_Msg |
cb97ae5c | 13134 | ("\?z?resulting access value may have invalid " |
1e3532e7 | 13135 | & "alignment!", Eloc); |
d6f39728 | 13136 | end if; |
13137 | end; | |
13138 | end if; | |
13139 | end; | |
13140 | end if; | |
13141 | end; | |
86d32751 | 13142 | |
13143 | <<Continue>> | |
13144 | null; | |
d6f39728 | 13145 | end loop; |
13146 | end Validate_Unchecked_Conversions; | |
13147 | ||
d6f39728 | 13148 | end Sem_Ch13; |