]>
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 | -- -- | |
74d7e7f5 | 9 | -- Copyright (C) 1992-2017, Free Software Foundation, Inc. -- |
d6f39728 | 10 | -- -- |
11 | -- GNAT is free software; you can redistribute it and/or modify it under -- | |
12 | -- terms of the GNU General Public License as published by the Free Soft- -- | |
80df182a | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
d6f39728 | 14 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
15 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- | |
16 | -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- | |
17 | -- for more details. You should have received a copy of the GNU General -- | |
80df182a | 18 | -- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
19 | -- http://www.gnu.org/licenses for a complete copy of the license. -- | |
d6f39728 | 20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
e78e8c8e | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
d6f39728 | 23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
ae888dbd | 26 | with Aspects; use Aspects; |
d6f39728 | 27 | with Atree; use Atree; |
713c00d6 | 28 | with Checks; use Checks; |
175a6969 | 29 | with Debug; use Debug; |
d6f39728 | 30 | with Einfo; use Einfo; |
d00681a7 | 31 | with Elists; use Elists; |
d6f39728 | 32 | with Errout; use Errout; |
76a6b7c7 | 33 | with Expander; use Expander; |
d00681a7 | 34 | with Exp_Disp; use Exp_Disp; |
d6f39728 | 35 | with Exp_Tss; use Exp_Tss; |
36 | with Exp_Util; use Exp_Util; | |
37c6552c | 37 | with Freeze; use Freeze; |
f9e26ff7 | 38 | with Ghost; use Ghost; |
d6f39728 | 39 | with Lib; use Lib; |
83f8f0a6 | 40 | with Lib.Xref; use Lib.Xref; |
15ebb600 | 41 | with Namet; use Namet; |
d6f39728 | 42 | with Nlists; use Nlists; |
43 | with Nmake; use Nmake; | |
44 | with Opt; use Opt; | |
e0521a36 | 45 | with Restrict; use Restrict; |
46 | with Rident; use Rident; | |
d6f39728 | 47 | with Rtsfind; use Rtsfind; |
48 | with Sem; use Sem; | |
d60c9ff7 | 49 | with Sem_Aux; use Sem_Aux; |
be9124d0 | 50 | with Sem_Case; use Sem_Case; |
40ca69b9 | 51 | with Sem_Ch3; use Sem_Ch3; |
490beba6 | 52 | with Sem_Ch6; use Sem_Ch6; |
d6f39728 | 53 | with Sem_Ch8; use Sem_Ch8; |
85696508 | 54 | with Sem_Dim; use Sem_Dim; |
85377c9b | 55 | with Sem_Disp; use Sem_Disp; |
d6f39728 | 56 | with Sem_Eval; use Sem_Eval; |
51ea9c94 | 57 | with Sem_Prag; use Sem_Prag; |
d6f39728 | 58 | with Sem_Res; use Sem_Res; |
59 | with Sem_Type; use Sem_Type; | |
60 | with Sem_Util; use Sem_Util; | |
44e4341e | 61 | with Sem_Warn; use Sem_Warn; |
738ec25b | 62 | with Sinfo; use Sinfo; |
1e3c4ae6 | 63 | with Sinput; use Sinput; |
9dfe12ae | 64 | with Snames; use Snames; |
d6f39728 | 65 | with Stand; use Stand; |
93735cb8 | 66 | with Targparm; use Targparm; |
d6f39728 | 67 | with Ttypes; use Ttypes; |
68 | with Tbuild; use Tbuild; | |
69 | with Urealp; use Urealp; | |
f42f24d7 | 70 | with Warnsw; use Warnsw; |
d6f39728 | 71 | |
bfa5a9d9 | 72 | with GNAT.Heap_Sort_G; |
d6f39728 | 73 | |
74 | package body Sem_Ch13 is | |
75 | ||
76 | SSU : constant Pos := System_Storage_Unit; | |
77 | -- Convenient short hand for commonly used constant | |
78 | ||
79 | ----------------------- | |
80 | -- Local Subprograms -- | |
81 | ----------------------- | |
82 | ||
d95b8c89 | 83 | procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id); |
2d9fff4f | 84 | -- Helper routine providing the original (pre-AI95-0133) behavior for |
d95b8c89 | 85 | -- Adjust_Record_For_Reverse_Bit_Order. |
86 | ||
1d366b32 | 87 | procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint); |
88 | -- This routine is called after setting one of the sizes of type entity | |
89 | -- Typ to Size. The purpose is to deal with the situation of a derived | |
90 | -- type whose inherited alignment is no longer appropriate for the new | |
91 | -- size value. In this case, we reset the Alignment to unknown. | |
d6f39728 | 92 | |
eb66e842 | 93 | procedure Build_Discrete_Static_Predicate |
d97beb2f | 94 | (Typ : Entity_Id; |
95 | Expr : Node_Id; | |
96 | Nam : Name_Id); | |
d7c2851f | 97 | -- Given a predicated type Typ, where Typ is a discrete static subtype, |
98 | -- whose predicate expression is Expr, tests if Expr is a static predicate, | |
99 | -- and if so, builds the predicate range list. Nam is the name of the one | |
100 | -- argument to the predicate function. Occurrences of the type name in the | |
6fb3c314 | 101 | -- predicate expression have been replaced by identifier references to this |
d7c2851f | 102 | -- name, which is unique, so any identifier with Chars matching Nam must be |
103 | -- a reference to the type. If the predicate is non-static, this procedure | |
104 | -- returns doing nothing. If the predicate is static, then the predicate | |
5c6a5792 | 105 | -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is |
106 | -- rewritten as a canonicalized membership operation. | |
d97beb2f | 107 | |
ee2b7923 | 108 | function Build_Export_Import_Pragma |
109 | (Asp : Node_Id; | |
110 | Id : Entity_Id) return Node_Id; | |
111 | -- Create the corresponding pragma for aspect Export or Import denoted by | |
112 | -- Asp. Id is the related entity subject to the aspect. Return Empty when | |
113 | -- the expression of aspect Asp evaluates to False or is erroneous. | |
114 | ||
9c20237a | 115 | function Build_Predicate_Function_Declaration |
116 | (Typ : Entity_Id) return Node_Id; | |
117 | -- Build the declaration for a predicate function. The declaration is built | |
118 | -- at the end of the declarative part containing the type definition, which | |
119 | -- may be before the freeze point of the type. The predicate expression is | |
120 | -- pre-analyzed at this point, to catch visibility errors. | |
121 | ||
eb66e842 | 122 | procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id); |
123 | -- If Typ has predicates (indicated by Has_Predicates being set for Typ), | |
124 | -- then either there are pragma Predicate entries on the rep chain for the | |
125 | -- type (note that Predicate aspects are converted to pragma Predicate), or | |
126 | -- there are inherited aspects from a parent type, or ancestor subtypes. | |
9c20237a | 127 | -- This procedure builds body for the Predicate function that tests these |
128 | -- predicates. N is the freeze node for the type. The spec of the function | |
129 | -- is inserted before the freeze node, and the body of the function is | |
130 | -- inserted after the freeze node. If the predicate expression has a least | |
131 | -- one Raise_Expression, then this procedure also builds the M version of | |
132 | -- the predicate function for use in membership tests. | |
eb66e842 | 133 | |
6653b695 | 134 | procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id); |
135 | -- Called if both Storage_Pool and Storage_Size attribute definition | |
136 | -- clauses (SP and SS) are present for entity Ent. Issue error message. | |
137 | ||
d9f6a4ee | 138 | procedure Freeze_Entity_Checks (N : Node_Id); |
139 | -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity | |
140 | -- to generate appropriate semantic checks that are delayed until this | |
141 | -- point (they had to be delayed this long for cases of delayed aspects, | |
142 | -- e.g. analysis of statically predicated subtypes in choices, for which | |
5f067114 | 143 | -- we have to be sure the subtypes in question are frozen before checking). |
d9f6a4ee | 144 | |
d6f39728 | 145 | function Get_Alignment_Value (Expr : Node_Id) return Uint; |
146 | -- Given the expression for an alignment value, returns the corresponding | |
147 | -- Uint value. If the value is inappropriate, then error messages are | |
148 | -- posted as required, and a value of No_Uint is returned. | |
149 | ||
150 | function Is_Operational_Item (N : Node_Id) return Boolean; | |
1e3c4ae6 | 151 | -- A specification for a stream attribute is allowed before the full type |
152 | -- is declared, as explained in AI-00137 and the corrigendum. Attributes | |
153 | -- that do not specify a representation characteristic are operational | |
154 | -- attributes. | |
d6f39728 | 155 | |
3b23aaa0 | 156 | function Is_Predicate_Static |
157 | (Expr : Node_Id; | |
158 | Nam : Name_Id) return Boolean; | |
159 | -- Given predicate expression Expr, tests if Expr is predicate-static in | |
160 | -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type | |
161 | -- name in the predicate expression have been replaced by references to | |
162 | -- an identifier whose Chars field is Nam. This name is unique, so any | |
163 | -- identifier with Chars matching Nam must be a reference to the type. | |
164 | -- Returns True if the expression is predicate-static and False otherwise, | |
165 | -- but is not in the business of setting flags or issuing error messages. | |
166 | -- | |
167 | -- Only scalar types can have static predicates, so False is always | |
168 | -- returned for non-scalar types. | |
169 | -- | |
170 | -- Note: the RM seems to suggest that string types can also have static | |
171 | -- predicates. But that really makes lttle sense as very few useful | |
172 | -- predicates can be constructed for strings. Remember that: | |
173 | -- | |
174 | -- "ABC" < "DEF" | |
175 | -- | |
176 | -- is not a static expression. So even though the clearly faulty RM wording | |
177 | -- allows the following: | |
178 | -- | |
179 | -- subtype S is String with Static_Predicate => S < "DEF" | |
180 | -- | |
181 | -- We can't allow this, otherwise we have predicate-static applying to a | |
182 | -- larger class than static expressions, which was never intended. | |
183 | ||
44e4341e | 184 | procedure New_Stream_Subprogram |
d6f39728 | 185 | (N : Node_Id; |
186 | Ent : Entity_Id; | |
187 | Subp : Entity_Id; | |
9dfe12ae | 188 | Nam : TSS_Name_Type); |
44e4341e | 189 | -- Create a subprogram renaming of a given stream attribute to the |
190 | -- designated subprogram and then in the tagged case, provide this as a | |
d1a2e31b | 191 | -- primitive operation, or in the untagged case make an appropriate TSS |
44e4341e | 192 | -- entry. This is more properly an expansion activity than just semantics, |
d1a2e31b | 193 | -- but the presence of user-defined stream functions for limited types |
194 | -- is a legality check, which is why this takes place here rather than in | |
44e4341e | 195 | -- exp_ch13, where it was previously. Nam indicates the name of the TSS |
196 | -- function to be generated. | |
9dfe12ae | 197 | -- |
f15731c4 | 198 | -- To avoid elaboration anomalies with freeze nodes, for untagged types |
199 | -- we generate both a subprogram declaration and a subprogram renaming | |
200 | -- declaration, so that the attribute specification is handled as a | |
201 | -- renaming_as_body. For tagged types, the specification is one of the | |
202 | -- primitive specs. | |
203 | ||
3061ffde | 204 | procedure Resolve_Iterable_Operation |
205 | (N : Node_Id; | |
206 | Cursor : Entity_Id; | |
207 | Typ : Entity_Id; | |
208 | Nam : Name_Id); | |
209 | -- If the name of a primitive operation for an Iterable aspect is | |
210 | -- overloaded, resolve according to required signature. | |
211 | ||
b77e4501 | 212 | procedure Set_Biased |
213 | (E : Entity_Id; | |
214 | N : Node_Id; | |
215 | Msg : String; | |
216 | Biased : Boolean := True); | |
217 | -- If Biased is True, sets Has_Biased_Representation flag for E, and | |
218 | -- outputs a warning message at node N if Warn_On_Biased_Representation is | |
219 | -- is True. This warning inserts the string Msg to describe the construct | |
220 | -- causing biasing. | |
221 | ||
76a6b7c7 | 222 | --------------------------------------------------- |
223 | -- Table for Validate_Compile_Time_Warning_Error -- | |
224 | --------------------------------------------------- | |
225 | ||
226 | -- The following table collects pragmas Compile_Time_Error and Compile_ | |
227 | -- Time_Warning for validation. Entries are made by calls to subprogram | |
228 | -- Validate_Compile_Time_Warning_Error, and the call to the procedure | |
229 | -- Validate_Compile_Time_Warning_Errors does the actual error checking | |
230 | -- and posting of warning and error messages. The reason for this delayed | |
231 | -- processing is to take advantage of back-annotations of attributes size | |
232 | -- and alignment values performed by the back end. | |
233 | ||
234 | -- Note: the reason we store a Source_Ptr value instead of a Node_Id is | |
235 | -- that by the time Validate_Unchecked_Conversions is called, Sprint will | |
236 | -- already have modified all Sloc values if the -gnatD option is set. | |
237 | ||
238 | type CTWE_Entry is record | |
239 | Eloc : Source_Ptr; | |
240 | -- Source location used in warnings and error messages | |
241 | ||
242 | Prag : Node_Id; | |
243 | -- Pragma Compile_Time_Error or Compile_Time_Warning | |
244 | ||
245 | Scope : Node_Id; | |
246 | -- The scope which encloses the pragma | |
247 | end record; | |
248 | ||
249 | package Compile_Time_Warnings_Errors is new Table.Table ( | |
250 | Table_Component_Type => CTWE_Entry, | |
251 | Table_Index_Type => Int, | |
252 | Table_Low_Bound => 1, | |
253 | Table_Initial => 50, | |
254 | Table_Increment => 200, | |
255 | Table_Name => "Compile_Time_Warnings_Errors"); | |
256 | ||
d6f39728 | 257 | ---------------------------------------------- |
258 | -- Table for Validate_Unchecked_Conversions -- | |
259 | ---------------------------------------------- | |
260 | ||
261 | -- The following table collects unchecked conversions for validation. | |
95deda50 | 262 | -- Entries are made by Validate_Unchecked_Conversion and then the call |
263 | -- to Validate_Unchecked_Conversions does the actual error checking and | |
264 | -- posting of warnings. The reason for this delayed processing is to take | |
265 | -- advantage of back-annotations of size and alignment values performed by | |
266 | -- the back end. | |
d6f39728 | 267 | |
95deda50 | 268 | -- Note: the reason we store a Source_Ptr value instead of a Node_Id is |
269 | -- that by the time Validate_Unchecked_Conversions is called, Sprint will | |
270 | -- already have modified all Sloc values if the -gnatD option is set. | |
299480f9 | 271 | |
d6f39728 | 272 | type UC_Entry is record |
86d32751 | 273 | Eloc : Source_Ptr; -- node used for posting warnings |
274 | Source : Entity_Id; -- source type for unchecked conversion | |
275 | Target : Entity_Id; -- target type for unchecked conversion | |
276 | Act_Unit : Entity_Id; -- actual function instantiated | |
d6f39728 | 277 | end record; |
278 | ||
279 | package Unchecked_Conversions is new Table.Table ( | |
280 | Table_Component_Type => UC_Entry, | |
281 | Table_Index_Type => Int, | |
282 | Table_Low_Bound => 1, | |
283 | Table_Initial => 50, | |
284 | Table_Increment => 200, | |
285 | Table_Name => "Unchecked_Conversions"); | |
286 | ||
83f8f0a6 | 287 | ---------------------------------------- |
288 | -- Table for Validate_Address_Clauses -- | |
289 | ---------------------------------------- | |
290 | ||
291 | -- If an address clause has the form | |
292 | ||
293 | -- for X'Address use Expr | |
294 | ||
514a5555 | 295 | -- where Expr has a value known at compile time or is of the form Y'Address |
296 | -- or recursively is a reference to a constant initialized with either of | |
297 | -- these forms, and the value of Expr is not a multiple of X's alignment, | |
298 | -- or if Y has a smaller alignment than X, then that merits a warning about | |
95deda50 | 299 | -- possible bad alignment. The following table collects address clauses of |
300 | -- this kind. We put these in a table so that they can be checked after the | |
301 | -- back end has completed annotation of the alignments of objects, since we | |
302 | -- can catch more cases that way. | |
83f8f0a6 | 303 | |
304 | type Address_Clause_Check_Record is record | |
305 | N : Node_Id; | |
306 | -- The address clause | |
307 | ||
308 | X : Entity_Id; | |
514a5555 | 309 | -- The entity of the object subject to the address clause |
310 | ||
311 | A : Uint; | |
312 | -- The value of the address in the first case | |
83f8f0a6 | 313 | |
314 | Y : Entity_Id; | |
514a5555 | 315 | -- The entity of the object being overlaid in the second case |
d6da7448 | 316 | |
317 | Off : Boolean; | |
514a5555 | 318 | -- Whether the address is offset within Y in the second case |
83f8f0a6 | 319 | end record; |
320 | ||
321 | package Address_Clause_Checks is new Table.Table ( | |
322 | Table_Component_Type => Address_Clause_Check_Record, | |
323 | Table_Index_Type => Int, | |
324 | Table_Low_Bound => 1, | |
325 | Table_Initial => 20, | |
326 | Table_Increment => 200, | |
327 | Table_Name => "Address_Clause_Checks"); | |
328 | ||
59ac57b5 | 329 | ----------------------------------------- |
330 | -- Adjust_Record_For_Reverse_Bit_Order -- | |
331 | ----------------------------------------- | |
332 | ||
333 | procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is | |
d95b8c89 | 334 | Max_Machine_Scalar_Size : constant Uint := |
335 | UI_From_Int | |
336 | (Standard_Long_Long_Integer_Size); | |
337 | -- We use this as the maximum machine scalar size | |
59ac57b5 | 338 | |
7748ccb2 | 339 | SSU : constant Uint := UI_From_Int (System_Storage_Unit); |
340 | ||
341 | CC : Node_Id; | |
342 | Comp : Node_Id; | |
d95b8c89 | 343 | Num_CC : Natural; |
6797073f | 344 | |
d95b8c89 | 345 | begin |
2d9fff4f | 346 | -- Processing here used to depend on Ada version: the behavior was |
d95b8c89 | 347 | -- changed by AI95-0133. However this AI is a Binding interpretation, |
2d9fff4f | 348 | -- so we now implement it even in Ada 95 mode. The original behavior |
d95b8c89 | 349 | -- from unamended Ada 95 is still available for compatibility under |
350 | -- debugging switch -gnatd. | |
351 | ||
352 | if Ada_Version < Ada_2005 and then Debug_Flag_Dot_P then | |
353 | Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R); | |
354 | return; | |
355 | end if; | |
356 | ||
357 | -- For Ada 2005, we do machine scalar processing, as fully described In | |
358 | -- AI-133. This involves gathering all components which start at the | |
359 | -- same byte offset and processing them together. Same approach is still | |
360 | -- valid in later versions including Ada 2012. | |
6797073f | 361 | |
7748ccb2 | 362 | -- This first loop through components does two things. First it deals |
363 | -- with the case of components with component clauses whose length is | |
364 | -- greater than the maximum machine scalar size (either accepting them | |
365 | -- or rejecting as needed). Second, it counts the number of components | |
366 | -- with component clauses whose length does not exceed this maximum for | |
367 | -- later processing. | |
6797073f | 368 | |
d95b8c89 | 369 | Num_CC := 0; |
370 | Comp := First_Component_Or_Discriminant (R); | |
371 | while Present (Comp) loop | |
372 | CC := Component_Clause (Comp); | |
6797073f | 373 | |
d95b8c89 | 374 | if Present (CC) then |
375 | declare | |
376 | Fbit : constant Uint := Static_Integer (First_Bit (CC)); | |
377 | Lbit : constant Uint := Static_Integer (Last_Bit (CC)); | |
6797073f | 378 | |
d95b8c89 | 379 | begin |
380 | -- Case of component with last bit >= max machine scalar | |
6797073f | 381 | |
d95b8c89 | 382 | if Lbit >= Max_Machine_Scalar_Size then |
59ac57b5 | 383 | |
7748ccb2 | 384 | -- This is allowed only if first bit is zero, and last bit |
385 | -- + 1 is a multiple of storage unit size. | |
59ac57b5 | 386 | |
d95b8c89 | 387 | if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then |
59ac57b5 | 388 | |
d95b8c89 | 389 | -- This is the case to give a warning if enabled |
59ac57b5 | 390 | |
d95b8c89 | 391 | if Warn_On_Reverse_Bit_Order then |
6797073f | 392 | Error_Msg_N |
7a41db5b | 393 | ("info: multi-byte field specified with " |
d95b8c89 | 394 | & "non-standard Bit_Order?V?", CC); |
31486bc0 | 395 | |
6797073f | 396 | if Bytes_Big_Endian then |
31486bc0 | 397 | Error_Msg_N |
7a41db5b | 398 | ("\bytes are not reversed " |
d95b8c89 | 399 | & "(component is big-endian)?V?", CC); |
31486bc0 | 400 | else |
401 | Error_Msg_N | |
7a41db5b | 402 | ("\bytes are not reversed " |
d95b8c89 | 403 | & "(component is little-endian)?V?", CC); |
31486bc0 | 404 | end if; |
d95b8c89 | 405 | end if; |
59ac57b5 | 406 | |
d95b8c89 | 407 | -- Give error message for RM 13.5.1(10) violation |
408 | ||
409 | else | |
410 | Error_Msg_FE | |
411 | ("machine scalar rules not followed for&", | |
412 | First_Bit (CC), Comp); | |
413 | ||
414 | Error_Msg_Uint_1 := Lbit + 1; | |
415 | Error_Msg_Uint_2 := Max_Machine_Scalar_Size; | |
416 | Error_Msg_F | |
7748ccb2 | 417 | ("\last bit + 1 (^) exceeds maximum machine scalar " |
418 | & "size (^)", First_Bit (CC)); | |
d95b8c89 | 419 | |
420 | if (Lbit + 1) mod SSU /= 0 then | |
421 | Error_Msg_Uint_1 := SSU; | |
422 | Error_Msg_F | |
423 | ("\and is not a multiple of Storage_Unit (^) " | |
7748ccb2 | 424 | & "(RM 13.5.1(10))", First_Bit (CC)); |
59ac57b5 | 425 | |
67278d60 | 426 | else |
d95b8c89 | 427 | Error_Msg_Uint_1 := Fbit; |
428 | Error_Msg_F | |
429 | ("\and first bit (^) is non-zero " | |
7748ccb2 | 430 | & "(RM 13.4.1(10))", First_Bit (CC)); |
6797073f | 431 | end if; |
d95b8c89 | 432 | end if; |
59ac57b5 | 433 | |
7748ccb2 | 434 | -- OK case of machine scalar related component clause. For now, |
435 | -- just count them. | |
59ac57b5 | 436 | |
d95b8c89 | 437 | else |
438 | Num_CC := Num_CC + 1; | |
439 | end if; | |
440 | end; | |
441 | end if; | |
59ac57b5 | 442 | |
d95b8c89 | 443 | Next_Component_Or_Discriminant (Comp); |
444 | end loop; | |
59ac57b5 | 445 | |
7748ccb2 | 446 | -- We need to sort the component clauses on the basis of the Position |
447 | -- values in the clause, so we can group clauses with the same Position | |
448 | -- together to determine the relevant machine scalar size. | |
bfa5a9d9 | 449 | |
d95b8c89 | 450 | Sort_CC : declare |
451 | Comps : array (0 .. Num_CC) of Entity_Id; | |
7748ccb2 | 452 | -- Array to collect component and discriminant entities. The data |
453 | -- starts at index 1, the 0'th entry is for the sort routine. | |
59ac57b5 | 454 | |
d95b8c89 | 455 | function CP_Lt (Op1, Op2 : Natural) return Boolean; |
456 | -- Compare routine for Sort | |
59ac57b5 | 457 | |
d95b8c89 | 458 | procedure CP_Move (From : Natural; To : Natural); |
459 | -- Move routine for Sort | |
59ac57b5 | 460 | |
d95b8c89 | 461 | package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt); |
59ac57b5 | 462 | |
7748ccb2 | 463 | MaxL : Uint; |
464 | -- Maximum last bit value of any component in this set | |
465 | ||
466 | MSS : Uint; | |
467 | -- Corresponding machine scalar size | |
468 | ||
d95b8c89 | 469 | Start : Natural; |
470 | Stop : Natural; | |
471 | -- Start and stop positions in the component list of the set of | |
472 | -- components with the same starting position (that constitute | |
473 | -- components in a single machine scalar). | |
59ac57b5 | 474 | |
d95b8c89 | 475 | ----------- |
476 | -- CP_Lt -- | |
477 | ----------- | |
6797073f | 478 | |
d95b8c89 | 479 | function CP_Lt (Op1, Op2 : Natural) return Boolean is |
480 | begin | |
7748ccb2 | 481 | return |
482 | Position (Component_Clause (Comps (Op1))) < | |
d95b8c89 | 483 | Position (Component_Clause (Comps (Op2))); |
484 | end CP_Lt; | |
59ac57b5 | 485 | |
d95b8c89 | 486 | ------------- |
487 | -- CP_Move -- | |
488 | ------------- | |
59ac57b5 | 489 | |
d95b8c89 | 490 | procedure CP_Move (From : Natural; To : Natural) is |
6797073f | 491 | begin |
d95b8c89 | 492 | Comps (To) := Comps (From); |
493 | end CP_Move; | |
494 | ||
495 | -- Start of processing for Sort_CC | |
496 | ||
497 | begin | |
498 | -- Collect the machine scalar relevant component clauses | |
67278d60 | 499 | |
d95b8c89 | 500 | Num_CC := 0; |
501 | Comp := First_Component_Or_Discriminant (R); | |
502 | while Present (Comp) loop | |
503 | declare | |
504 | CC : constant Node_Id := Component_Clause (Comp); | |
67278d60 | 505 | |
d95b8c89 | 506 | begin |
7748ccb2 | 507 | -- Collect only component clauses whose last bit is less than |
508 | -- machine scalar size. Any component clause whose last bit | |
509 | -- exceeds this value does not take part in machine scalar | |
510 | -- layout considerations. The test for Error_Posted makes sure | |
511 | -- we exclude component clauses for which we already posted an | |
512 | -- error. | |
d95b8c89 | 513 | |
514 | if Present (CC) | |
515 | and then not Error_Posted (Last_Bit (CC)) | |
516 | and then Static_Integer (Last_Bit (CC)) < | |
517 | Max_Machine_Scalar_Size | |
518 | then | |
519 | Num_CC := Num_CC + 1; | |
520 | Comps (Num_CC) := Comp; | |
521 | end if; | |
522 | end; | |
67278d60 | 523 | |
d95b8c89 | 524 | Next_Component_Or_Discriminant (Comp); |
525 | end loop; | |
67278d60 | 526 | |
d95b8c89 | 527 | -- Sort by ascending position number |
528 | ||
529 | Sorting.Sort (Num_CC); | |
530 | ||
7748ccb2 | 531 | -- We now have all the components whose size does not exceed the max |
532 | -- machine scalar value, sorted by starting position. In this loop we | |
533 | -- gather groups of clauses starting at the same position, to process | |
534 | -- them in accordance with AI-133. | |
d95b8c89 | 535 | |
536 | Stop := 0; | |
537 | while Stop < Num_CC loop | |
538 | Start := Stop + 1; | |
539 | Stop := Start; | |
540 | MaxL := | |
541 | Static_Integer | |
542 | (Last_Bit (Component_Clause (Comps (Start)))); | |
543 | while Stop < Num_CC loop | |
544 | if Static_Integer | |
545 | (Position (Component_Clause (Comps (Stop + 1)))) = | |
546 | Static_Integer | |
547 | (Position (Component_Clause (Comps (Stop)))) | |
548 | then | |
549 | Stop := Stop + 1; | |
550 | MaxL := | |
551 | UI_Max | |
552 | (MaxL, | |
553 | Static_Integer | |
554 | (Last_Bit | |
555 | (Component_Clause (Comps (Stop))))); | |
556 | else | |
557 | exit; | |
558 | end if; | |
559 | end loop; | |
67278d60 | 560 | |
7748ccb2 | 561 | -- Now we have a group of component clauses from Start to Stop |
562 | -- whose positions are identical, and MaxL is the maximum last | |
563 | -- bit value of any of these components. | |
d95b8c89 | 564 | |
7748ccb2 | 565 | -- We need to determine the corresponding machine scalar size. |
566 | -- This loop assumes that machine scalar sizes are even, and that | |
567 | -- each possible machine scalar has twice as many bits as the next | |
568 | -- smaller one. | |
d95b8c89 | 569 | |
570 | MSS := Max_Machine_Scalar_Size; | |
571 | while MSS mod 2 = 0 | |
572 | and then (MSS / 2) >= SSU | |
573 | and then (MSS / 2) > MaxL | |
574 | loop | |
575 | MSS := MSS / 2; | |
576 | end loop; | |
67278d60 | 577 | |
7748ccb2 | 578 | -- Here is where we fix up the Component_Bit_Offset value to |
579 | -- account for the reverse bit order. Some examples of what needs | |
580 | -- to be done for the case of a machine scalar size of 8 are: | |
67278d60 | 581 | |
d95b8c89 | 582 | -- First_Bit .. Last_Bit Component_Bit_Offset |
583 | -- old new old new | |
67278d60 | 584 | |
d95b8c89 | 585 | -- 0 .. 0 7 .. 7 0 7 |
586 | -- 0 .. 1 6 .. 7 0 6 | |
587 | -- 0 .. 2 5 .. 7 0 5 | |
588 | -- 0 .. 7 0 .. 7 0 4 | |
b38e4131 | 589 | |
d95b8c89 | 590 | -- 1 .. 1 6 .. 6 1 6 |
591 | -- 1 .. 4 3 .. 6 1 3 | |
592 | -- 4 .. 7 0 .. 3 4 0 | |
67278d60 | 593 | |
7748ccb2 | 594 | -- The rule is that the first bit is obtained by subtracting the |
595 | -- old ending bit from machine scalar size - 1. | |
67278d60 | 596 | |
d95b8c89 | 597 | for C in Start .. Stop loop |
598 | declare | |
599 | Comp : constant Entity_Id := Comps (C); | |
600 | CC : constant Node_Id := Component_Clause (Comp); | |
59ac57b5 | 601 | |
d95b8c89 | 602 | LB : constant Uint := Static_Integer (Last_Bit (CC)); |
603 | NFB : constant Uint := MSS - Uint_1 - LB; | |
604 | NLB : constant Uint := NFB + Esize (Comp) - 1; | |
605 | Pos : constant Uint := Static_Integer (Position (CC)); | |
59ac57b5 | 606 | |
d95b8c89 | 607 | begin |
608 | if Warn_On_Reverse_Bit_Order then | |
609 | Error_Msg_Uint_1 := MSS; | |
610 | Error_Msg_N | |
7748ccb2 | 611 | ("info: reverse bit order in machine scalar of " |
612 | & "length^?V?", First_Bit (CC)); | |
d95b8c89 | 613 | Error_Msg_Uint_1 := NFB; |
614 | Error_Msg_Uint_2 := NLB; | |
615 | ||
616 | if Bytes_Big_Endian then | |
617 | Error_Msg_NE | |
7748ccb2 | 618 | ("\big-endian range for component & is ^ .. ^?V?", |
619 | First_Bit (CC), Comp); | |
6797073f | 620 | else |
d95b8c89 | 621 | Error_Msg_NE |
7748ccb2 | 622 | ("\little-endian range for component & is ^ .. ^?V?", |
623 | First_Bit (CC), Comp); | |
6797073f | 624 | end if; |
d95b8c89 | 625 | end if; |
59ac57b5 | 626 | |
d95b8c89 | 627 | Set_Component_Bit_Offset (Comp, Pos * SSU + NFB); |
628 | Set_Normalized_First_Bit (Comp, NFB mod SSU); | |
629 | end; | |
6797073f | 630 | end loop; |
d95b8c89 | 631 | end loop; |
632 | end Sort_CC; | |
633 | end Adjust_Record_For_Reverse_Bit_Order; | |
59ac57b5 | 634 | |
d95b8c89 | 635 | ------------------------------------------------ |
636 | -- Adjust_Record_For_Reverse_Bit_Order_Ada_95 -- | |
637 | ------------------------------------------------ | |
59ac57b5 | 638 | |
d95b8c89 | 639 | procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id) is |
d95b8c89 | 640 | CC : Node_Id; |
7748ccb2 | 641 | Comp : Node_Id; |
59ac57b5 | 642 | |
d95b8c89 | 643 | begin |
644 | -- For Ada 95, we just renumber bits within a storage unit. We do the | |
645 | -- same for Ada 83 mode, since we recognize the Bit_Order attribute in | |
646 | -- Ada 83, and are free to add this extension. | |
59ac57b5 | 647 | |
d95b8c89 | 648 | Comp := First_Component_Or_Discriminant (R); |
649 | while Present (Comp) loop | |
650 | CC := Component_Clause (Comp); | |
59ac57b5 | 651 | |
d95b8c89 | 652 | -- If component clause is present, then deal with the non-default |
653 | -- bit order case for Ada 95 mode. | |
59ac57b5 | 654 | |
d95b8c89 | 655 | -- We only do this processing for the base type, and in fact that |
656 | -- is important, since otherwise if there are record subtypes, we | |
657 | -- could reverse the bits once for each subtype, which is wrong. | |
59ac57b5 | 658 | |
d95b8c89 | 659 | if Present (CC) and then Ekind (R) = E_Record_Type then |
660 | declare | |
661 | CFB : constant Uint := Component_Bit_Offset (Comp); | |
662 | CSZ : constant Uint := Esize (Comp); | |
663 | CLC : constant Node_Id := Component_Clause (Comp); | |
664 | Pos : constant Node_Id := Position (CLC); | |
665 | FB : constant Node_Id := First_Bit (CLC); | |
59ac57b5 | 666 | |
d95b8c89 | 667 | Storage_Unit_Offset : constant Uint := |
668 | CFB / System_Storage_Unit; | |
67278d60 | 669 | |
d95b8c89 | 670 | Start_Bit : constant Uint := |
671 | CFB mod System_Storage_Unit; | |
67278d60 | 672 | |
d95b8c89 | 673 | begin |
674 | -- Cases where field goes over storage unit boundary | |
67278d60 | 675 | |
d95b8c89 | 676 | if Start_Bit + CSZ > System_Storage_Unit then |
67278d60 | 677 | |
d95b8c89 | 678 | -- Allow multi-byte field but generate warning |
67278d60 | 679 | |
d95b8c89 | 680 | if Start_Bit mod System_Storage_Unit = 0 |
681 | and then CSZ mod System_Storage_Unit = 0 | |
682 | then | |
683 | Error_Msg_N | |
7748ccb2 | 684 | ("info: multi-byte field specified with non-standard " |
685 | & "Bit_Order?V?", CLC); | |
59ac57b5 | 686 | |
d95b8c89 | 687 | if Bytes_Big_Endian then |
688 | Error_Msg_N | |
689 | ("\bytes are not reversed " | |
690 | & "(component is big-endian)?V?", CLC); | |
6797073f | 691 | else |
d95b8c89 | 692 | Error_Msg_N |
693 | ("\bytes are not reversed " | |
694 | & "(component is little-endian)?V?", CLC); | |
6797073f | 695 | end if; |
67278d60 | 696 | |
d95b8c89 | 697 | -- Do not allow non-contiguous field |
6797073f | 698 | |
d95b8c89 | 699 | else |
700 | Error_Msg_N | |
7748ccb2 | 701 | ("attempt to specify non-contiguous field not " |
702 | & "permitted", CLC); | |
d95b8c89 | 703 | Error_Msg_N |
7748ccb2 | 704 | ("\caused by non-standard Bit_Order specified in " |
705 | & "legacy Ada 95 mode", CLC); | |
d95b8c89 | 706 | end if; |
6797073f | 707 | |
d95b8c89 | 708 | -- Case where field fits in one storage unit |
709 | ||
710 | else | |
711 | -- Give warning if suspicious component clause | |
712 | ||
713 | if Intval (FB) >= System_Storage_Unit | |
714 | and then Warn_On_Reverse_Bit_Order | |
715 | then | |
716 | Error_Msg_N | |
7748ccb2 | 717 | ("info: Bit_Order clause does not affect byte " |
718 | & "ordering?V?", Pos); | |
d95b8c89 | 719 | Error_Msg_Uint_1 := |
720 | Intval (Pos) + Intval (FB) / | |
721 | System_Storage_Unit; | |
722 | Error_Msg_N | |
7748ccb2 | 723 | ("info: position normalized to ^ before bit order " |
724 | & "interpreted?V?", Pos); | |
d95b8c89 | 725 | end if; |
67278d60 | 726 | |
6797073f | 727 | -- Here is where we fix up the Component_Bit_Offset value |
728 | -- to account for the reverse bit order. Some examples of | |
d95b8c89 | 729 | -- what needs to be done are: |
67278d60 | 730 | |
6797073f | 731 | -- First_Bit .. Last_Bit Component_Bit_Offset |
732 | -- old new old new | |
67278d60 | 733 | |
6797073f | 734 | -- 0 .. 0 7 .. 7 0 7 |
735 | -- 0 .. 1 6 .. 7 0 6 | |
736 | -- 0 .. 2 5 .. 7 0 5 | |
737 | -- 0 .. 7 0 .. 7 0 4 | |
67278d60 | 738 | |
6797073f | 739 | -- 1 .. 1 6 .. 6 1 6 |
740 | -- 1 .. 4 3 .. 6 1 3 | |
741 | -- 4 .. 7 0 .. 3 4 0 | |
67278d60 | 742 | |
d95b8c89 | 743 | -- The rule is that the first bit is is obtained by |
744 | -- subtracting the old ending bit from storage_unit - 1. | |
67278d60 | 745 | |
7748ccb2 | 746 | Set_Component_Bit_Offset (Comp, |
747 | (Storage_Unit_Offset * System_Storage_Unit) + | |
748 | (System_Storage_Unit - 1) - | |
749 | (Start_Bit + CSZ - 1)); | |
b9e61b2a | 750 | |
7748ccb2 | 751 | Set_Normalized_First_Bit (Comp, |
752 | Component_Bit_Offset (Comp) mod System_Storage_Unit); | |
d95b8c89 | 753 | end if; |
754 | end; | |
755 | end if; | |
67278d60 | 756 | |
d95b8c89 | 757 | Next_Component_Or_Discriminant (Comp); |
758 | end loop; | |
759 | end Adjust_Record_For_Reverse_Bit_Order_Ada_95; | |
59ac57b5 | 760 | |
1d366b32 | 761 | ------------------------------------- |
762 | -- Alignment_Check_For_Size_Change -- | |
763 | ------------------------------------- | |
d6f39728 | 764 | |
1d366b32 | 765 | procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is |
d6f39728 | 766 | begin |
767 | -- If the alignment is known, and not set by a rep clause, and is | |
768 | -- inconsistent with the size being set, then reset it to unknown, | |
769 | -- we assume in this case that the size overrides the inherited | |
770 | -- alignment, and that the alignment must be recomputed. | |
771 | ||
772 | if Known_Alignment (Typ) | |
773 | and then not Has_Alignment_Clause (Typ) | |
1d366b32 | 774 | and then Size mod (Alignment (Typ) * SSU) /= 0 |
d6f39728 | 775 | then |
776 | Init_Alignment (Typ); | |
777 | end if; | |
1d366b32 | 778 | end Alignment_Check_For_Size_Change; |
d6f39728 | 779 | |
06ef5f86 | 780 | ------------------------------------- |
781 | -- Analyze_Aspects_At_Freeze_Point -- | |
782 | ------------------------------------- | |
783 | ||
784 | procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is | |
06ef5f86 | 785 | procedure Analyze_Aspect_Default_Value (ASN : Node_Id); |
786 | -- This routine analyzes an Aspect_Default_[Component_]Value denoted by | |
787 | -- the aspect specification node ASN. | |
788 | ||
37c6e44c | 789 | procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id); |
790 | -- As discussed in the spec of Aspects (see Aspect_Delay declaration), | |
791 | -- a derived type can inherit aspects from its parent which have been | |
792 | -- specified at the time of the derivation using an aspect, as in: | |
793 | -- | |
794 | -- type A is range 1 .. 10 | |
795 | -- with Size => Not_Defined_Yet; | |
796 | -- .. | |
797 | -- type B is new A; | |
798 | -- .. | |
799 | -- Not_Defined_Yet : constant := 64; | |
800 | -- | |
801 | -- In this example, the Size of A is considered to be specified prior | |
802 | -- to the derivation, and thus inherited, even though the value is not | |
803 | -- known at the time of derivation. To deal with this, we use two entity | |
804 | -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A | |
805 | -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in | |
806 | -- the derived type (B here). If this flag is set when the derived type | |
807 | -- is frozen, then this procedure is called to ensure proper inheritance | |
b21edad9 | 808 | -- of all delayed aspects from the parent type. The derived type is E, |
37c6e44c | 809 | -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first |
810 | -- aspect specification node in the Rep_Item chain for the parent type. | |
811 | ||
06ef5f86 | 812 | procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id); |
813 | -- Given an aspect specification node ASN whose expression is an | |
814 | -- optional Boolean, this routines creates the corresponding pragma | |
815 | -- at the freezing point. | |
816 | ||
817 | ---------------------------------- | |
818 | -- Analyze_Aspect_Default_Value -- | |
819 | ---------------------------------- | |
820 | ||
821 | procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is | |
ee2b7923 | 822 | A_Id : constant Aspect_Id := Get_Aspect_Id (ASN); |
06ef5f86 | 823 | Ent : constant Entity_Id := Entity (ASN); |
824 | Expr : constant Node_Id := Expression (ASN); | |
825 | Id : constant Node_Id := Identifier (ASN); | |
826 | ||
827 | begin | |
828 | Error_Msg_Name_1 := Chars (Id); | |
829 | ||
830 | if not Is_Type (Ent) then | |
831 | Error_Msg_N ("aspect% can only apply to a type", Id); | |
832 | return; | |
833 | ||
834 | elsif not Is_First_Subtype (Ent) then | |
835 | Error_Msg_N ("aspect% cannot apply to subtype", Id); | |
836 | return; | |
837 | ||
838 | elsif A_Id = Aspect_Default_Value | |
839 | and then not Is_Scalar_Type (Ent) | |
840 | then | |
841 | Error_Msg_N ("aspect% can only be applied to scalar type", Id); | |
842 | return; | |
843 | ||
844 | elsif A_Id = Aspect_Default_Component_Value then | |
845 | if not Is_Array_Type (Ent) then | |
846 | Error_Msg_N ("aspect% can only be applied to array type", Id); | |
847 | return; | |
848 | ||
849 | elsif not Is_Scalar_Type (Component_Type (Ent)) then | |
850 | Error_Msg_N ("aspect% requires scalar components", Id); | |
851 | return; | |
852 | end if; | |
853 | end if; | |
854 | ||
855 | Set_Has_Default_Aspect (Base_Type (Ent)); | |
856 | ||
857 | if Is_Scalar_Type (Ent) then | |
9f36e3fb | 858 | Set_Default_Aspect_Value (Base_Type (Ent), Expr); |
06ef5f86 | 859 | else |
f3d70f08 | 860 | Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr); |
06ef5f86 | 861 | end if; |
862 | end Analyze_Aspect_Default_Value; | |
863 | ||
37c6e44c | 864 | --------------------------------- |
865 | -- Inherit_Delayed_Rep_Aspects -- | |
866 | --------------------------------- | |
867 | ||
868 | procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is | |
ee2b7923 | 869 | A_Id : constant Aspect_Id := Get_Aspect_Id (ASN); |
870 | P : constant Entity_Id := Entity (ASN); | |
37c6e44c | 871 | -- Entithy for parent type |
872 | ||
873 | N : Node_Id; | |
874 | -- Item from Rep_Item chain | |
875 | ||
876 | A : Aspect_Id; | |
877 | ||
878 | begin | |
879 | -- Loop through delayed aspects for the parent type | |
880 | ||
881 | N := ASN; | |
882 | while Present (N) loop | |
883 | if Nkind (N) = N_Aspect_Specification then | |
884 | exit when Entity (N) /= P; | |
885 | ||
886 | if Is_Delayed_Aspect (N) then | |
887 | A := Get_Aspect_Id (Chars (Identifier (N))); | |
888 | ||
889 | -- Process delayed rep aspect. For Boolean attributes it is | |
890 | -- not possible to cancel an attribute once set (the attempt | |
891 | -- to use an aspect with xxx => False is an error) for a | |
892 | -- derived type. So for those cases, we do not have to check | |
893 | -- if a clause has been given for the derived type, since it | |
894 | -- is harmless to set it again if it is already set. | |
895 | ||
896 | case A is | |
897 | ||
898 | -- Alignment | |
899 | ||
900 | when Aspect_Alignment => | |
901 | if not Has_Alignment_Clause (E) then | |
902 | Set_Alignment (E, Alignment (P)); | |
903 | end if; | |
904 | ||
905 | -- Atomic | |
906 | ||
907 | when Aspect_Atomic => | |
908 | if Is_Atomic (P) then | |
909 | Set_Is_Atomic (E); | |
910 | end if; | |
911 | ||
912 | -- Atomic_Components | |
913 | ||
914 | when Aspect_Atomic_Components => | |
915 | if Has_Atomic_Components (P) then | |
916 | Set_Has_Atomic_Components (Base_Type (E)); | |
917 | end if; | |
918 | ||
919 | -- Bit_Order | |
920 | ||
921 | when Aspect_Bit_Order => | |
922 | if Is_Record_Type (E) | |
923 | and then No (Get_Attribute_Definition_Clause | |
924 | (E, Attribute_Bit_Order)) | |
925 | and then Reverse_Bit_Order (P) | |
926 | then | |
927 | Set_Reverse_Bit_Order (Base_Type (E)); | |
928 | end if; | |
929 | ||
930 | -- Component_Size | |
931 | ||
932 | when Aspect_Component_Size => | |
933 | if Is_Array_Type (E) | |
934 | and then not Has_Component_Size_Clause (E) | |
935 | then | |
936 | Set_Component_Size | |
937 | (Base_Type (E), Component_Size (P)); | |
938 | end if; | |
939 | ||
940 | -- Machine_Radix | |
941 | ||
942 | when Aspect_Machine_Radix => | |
943 | if Is_Decimal_Fixed_Point_Type (E) | |
944 | and then not Has_Machine_Radix_Clause (E) | |
945 | then | |
946 | Set_Machine_Radix_10 (E, Machine_Radix_10 (P)); | |
947 | end if; | |
948 | ||
949 | -- Object_Size (also Size which also sets Object_Size) | |
950 | ||
99378362 | 951 | when Aspect_Object_Size |
952 | | Aspect_Size | |
953 | => | |
37c6e44c | 954 | if not Has_Size_Clause (E) |
955 | and then | |
956 | No (Get_Attribute_Definition_Clause | |
957 | (E, Attribute_Object_Size)) | |
958 | then | |
959 | Set_Esize (E, Esize (P)); | |
960 | end if; | |
961 | ||
962 | -- Pack | |
963 | ||
964 | when Aspect_Pack => | |
965 | if not Is_Packed (E) then | |
966 | Set_Is_Packed (Base_Type (E)); | |
967 | ||
968 | if Is_Bit_Packed_Array (P) then | |
969 | Set_Is_Bit_Packed_Array (Base_Type (E)); | |
a88a5773 | 970 | Set_Packed_Array_Impl_Type |
971 | (E, Packed_Array_Impl_Type (P)); | |
37c6e44c | 972 | end if; |
973 | end if; | |
974 | ||
975 | -- Scalar_Storage_Order | |
976 | ||
977 | when Aspect_Scalar_Storage_Order => | |
978 | if (Is_Record_Type (E) or else Is_Array_Type (E)) | |
979 | and then No (Get_Attribute_Definition_Clause | |
e163cac8 | 980 | (E, Attribute_Scalar_Storage_Order)) |
37c6e44c | 981 | and then Reverse_Storage_Order (P) |
982 | then | |
983 | Set_Reverse_Storage_Order (Base_Type (E)); | |
b64082f2 | 984 | |
985 | -- Clear default SSO indications, since the aspect | |
986 | -- overrides the default. | |
987 | ||
988 | Set_SSO_Set_Low_By_Default (Base_Type (E), False); | |
989 | Set_SSO_Set_High_By_Default (Base_Type (E), False); | |
37c6e44c | 990 | end if; |
991 | ||
992 | -- Small | |
993 | ||
994 | when Aspect_Small => | |
995 | if Is_Fixed_Point_Type (E) | |
996 | and then not Has_Small_Clause (E) | |
997 | then | |
998 | Set_Small_Value (E, Small_Value (P)); | |
999 | end if; | |
1000 | ||
1001 | -- Storage_Size | |
1002 | ||
1003 | when Aspect_Storage_Size => | |
1004 | if (Is_Access_Type (E) or else Is_Task_Type (E)) | |
1005 | and then not Has_Storage_Size_Clause (E) | |
1006 | then | |
1007 | Set_Storage_Size_Variable | |
1008 | (Base_Type (E), Storage_Size_Variable (P)); | |
1009 | end if; | |
1010 | ||
1011 | -- Value_Size | |
1012 | ||
1013 | when Aspect_Value_Size => | |
1014 | ||
1015 | -- Value_Size is never inherited, it is either set by | |
1016 | -- default, or it is explicitly set for the derived | |
1017 | -- type. So nothing to do here. | |
1018 | ||
1019 | null; | |
1020 | ||
1021 | -- Volatile | |
1022 | ||
1023 | when Aspect_Volatile => | |
1024 | if Is_Volatile (P) then | |
1025 | Set_Is_Volatile (E); | |
1026 | end if; | |
1027 | ||
2fe893b9 | 1028 | -- Volatile_Full_Access |
1029 | ||
1030 | when Aspect_Volatile_Full_Access => | |
4bf2acc9 | 1031 | if Is_Volatile_Full_Access (P) then |
1032 | Set_Is_Volatile_Full_Access (E); | |
2fe893b9 | 1033 | end if; |
1034 | ||
37c6e44c | 1035 | -- Volatile_Components |
1036 | ||
1037 | when Aspect_Volatile_Components => | |
1038 | if Has_Volatile_Components (P) then | |
1039 | Set_Has_Volatile_Components (Base_Type (E)); | |
1040 | end if; | |
1041 | ||
1042 | -- That should be all the Rep Aspects | |
1043 | ||
1044 | when others => | |
1045 | pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect); | |
1046 | null; | |
37c6e44c | 1047 | end case; |
1048 | end if; | |
1049 | end if; | |
1050 | ||
1051 | N := Next_Rep_Item (N); | |
1052 | end loop; | |
1053 | end Inherit_Delayed_Rep_Aspects; | |
1054 | ||
06ef5f86 | 1055 | ------------------------------------- |
1056 | -- Make_Pragma_From_Boolean_Aspect -- | |
1057 | ------------------------------------- | |
1058 | ||
1059 | procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is | |
1060 | Ident : constant Node_Id := Identifier (ASN); | |
1061 | A_Name : constant Name_Id := Chars (Ident); | |
1062 | A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name); | |
1063 | Ent : constant Entity_Id := Entity (ASN); | |
1064 | Expr : constant Node_Id := Expression (ASN); | |
1065 | Loc : constant Source_Ptr := Sloc (ASN); | |
1066 | ||
06ef5f86 | 1067 | procedure Check_False_Aspect_For_Derived_Type; |
1068 | -- This procedure checks for the case of a false aspect for a derived | |
1069 | -- type, which improperly tries to cancel an aspect inherited from | |
1070 | -- the parent. | |
1071 | ||
1072 | ----------------------------------------- | |
1073 | -- Check_False_Aspect_For_Derived_Type -- | |
1074 | ----------------------------------------- | |
1075 | ||
1076 | procedure Check_False_Aspect_For_Derived_Type is | |
1077 | Par : Node_Id; | |
1078 | ||
1079 | begin | |
1080 | -- We are only checking derived types | |
1081 | ||
1082 | if not Is_Derived_Type (E) then | |
1083 | return; | |
1084 | end if; | |
1085 | ||
1086 | Par := Nearest_Ancestor (E); | |
1087 | ||
1088 | case A_Id is | |
99378362 | 1089 | when Aspect_Atomic |
1090 | | Aspect_Shared | |
1091 | => | |
06ef5f86 | 1092 | if not Is_Atomic (Par) then |
1093 | return; | |
1094 | end if; | |
1095 | ||
1096 | when Aspect_Atomic_Components => | |
1097 | if not Has_Atomic_Components (Par) then | |
1098 | return; | |
1099 | end if; | |
1100 | ||
1101 | when Aspect_Discard_Names => | |
1102 | if not Discard_Names (Par) then | |
1103 | return; | |
1104 | end if; | |
1105 | ||
1106 | when Aspect_Pack => | |
1107 | if not Is_Packed (Par) then | |
1108 | return; | |
1109 | end if; | |
1110 | ||
1111 | when Aspect_Unchecked_Union => | |
1112 | if not Is_Unchecked_Union (Par) then | |
1113 | return; | |
1114 | end if; | |
1115 | ||
1116 | when Aspect_Volatile => | |
1117 | if not Is_Volatile (Par) then | |
1118 | return; | |
1119 | end if; | |
1120 | ||
1121 | when Aspect_Volatile_Components => | |
1122 | if not Has_Volatile_Components (Par) then | |
1123 | return; | |
1124 | end if; | |
1125 | ||
2fe893b9 | 1126 | when Aspect_Volatile_Full_Access => |
4bf2acc9 | 1127 | if not Is_Volatile_Full_Access (Par) then |
2fe893b9 | 1128 | return; |
1129 | end if; | |
1130 | ||
06ef5f86 | 1131 | when others => |
1132 | return; | |
1133 | end case; | |
1134 | ||
1135 | -- Fall through means we are canceling an inherited aspect | |
1136 | ||
1137 | Error_Msg_Name_1 := A_Name; | |
37c6e44c | 1138 | Error_Msg_NE |
1139 | ("derived type& inherits aspect%, cannot cancel", Expr, E); | |
06ef5f86 | 1140 | end Check_False_Aspect_For_Derived_Type; |
1141 | ||
ee2b7923 | 1142 | -- Local variables |
1143 | ||
1144 | Prag : Node_Id; | |
1145 | ||
06ef5f86 | 1146 | -- Start of processing for Make_Pragma_From_Boolean_Aspect |
1147 | ||
1148 | begin | |
37c6e44c | 1149 | -- Note that we know Expr is present, because for a missing Expr |
1150 | -- argument, we knew it was True and did not need to delay the | |
1151 | -- evaluation to the freeze point. | |
1152 | ||
06ef5f86 | 1153 | if Is_False (Static_Boolean (Expr)) then |
1154 | Check_False_Aspect_For_Derived_Type; | |
1155 | ||
1156 | else | |
1157 | Prag := | |
1158 | Make_Pragma (Loc, | |
ee2b7923 | 1159 | Pragma_Identifier => |
1160 | Make_Identifier (Sloc (Ident), Chars (Ident)), | |
06ef5f86 | 1161 | Pragma_Argument_Associations => New_List ( |
57cd943b | 1162 | Make_Pragma_Argument_Association (Sloc (Ident), |
ee2b7923 | 1163 | Expression => New_Occurrence_Of (Ent, Sloc (Ident))))); |
06ef5f86 | 1164 | |
1165 | Set_From_Aspect_Specification (Prag, True); | |
1166 | Set_Corresponding_Aspect (Prag, ASN); | |
1167 | Set_Aspect_Rep_Item (ASN, Prag); | |
1168 | Set_Is_Delayed_Aspect (Prag); | |
1169 | Set_Parent (Prag, ASN); | |
1170 | end if; | |
06ef5f86 | 1171 | end Make_Pragma_From_Boolean_Aspect; |
1172 | ||
ee2b7923 | 1173 | -- Local variables |
1174 | ||
1175 | A_Id : Aspect_Id; | |
1176 | ASN : Node_Id; | |
1177 | Ritem : Node_Id; | |
1178 | ||
06ef5f86 | 1179 | -- Start of processing for Analyze_Aspects_At_Freeze_Point |
1180 | ||
1181 | begin | |
29a9d4be | 1182 | -- Must be visible in current scope |
06ef5f86 | 1183 | |
ace3389d | 1184 | if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then |
06ef5f86 | 1185 | return; |
1186 | end if; | |
1187 | ||
1188 | -- Look for aspect specification entries for this entity | |
1189 | ||
1190 | ASN := First_Rep_Item (E); | |
06ef5f86 | 1191 | while Present (ASN) loop |
37c6e44c | 1192 | if Nkind (ASN) = N_Aspect_Specification then |
1193 | exit when Entity (ASN) /= E; | |
06ef5f86 | 1194 | |
37c6e44c | 1195 | if Is_Delayed_Aspect (ASN) then |
1196 | A_Id := Get_Aspect_Id (ASN); | |
1197 | ||
1198 | case A_Id is | |
e4c87fa5 | 1199 | |
37c6e44c | 1200 | -- For aspects whose expression is an optional Boolean, make |
7d6fb253 | 1201 | -- the corresponding pragma at the freeze point. |
06ef5f86 | 1202 | |
99378362 | 1203 | when Boolean_Aspects |
1204 | | Library_Unit_Aspects | |
1205 | => | |
ee2b7923 | 1206 | -- Aspects Export and Import require special handling. |
1207 | -- Both are by definition Boolean and may benefit from | |
1208 | -- forward references, however their expressions are | |
1209 | -- treated as static. In addition, the syntax of their | |
1210 | -- corresponding pragmas requires extra "pieces" which | |
1211 | -- may also contain forward references. To account for | |
1212 | -- all of this, the corresponding pragma is created by | |
1213 | -- Analyze_Aspect_Export_Import, but is not analyzed as | |
1214 | -- the complete analysis must happen now. | |
1215 | ||
1216 | if A_Id = Aspect_Export or else A_Id = Aspect_Import then | |
1217 | null; | |
1218 | ||
1219 | -- Otherwise create a corresponding pragma | |
1220 | ||
1221 | else | |
1222 | Make_Pragma_From_Boolean_Aspect (ASN); | |
1223 | end if; | |
06ef5f86 | 1224 | |
37c6e44c | 1225 | -- Special handling for aspects that don't correspond to |
1226 | -- pragmas/attributes. | |
06ef5f86 | 1227 | |
99378362 | 1228 | when Aspect_Default_Value |
1229 | | Aspect_Default_Component_Value | |
1230 | => | |
81c2bc19 | 1231 | -- Do not inherit aspect for anonymous base type of a |
1232 | -- scalar or array type, because they apply to the first | |
1233 | -- subtype of the type, and will be processed when that | |
1234 | -- first subtype is frozen. | |
1235 | ||
1236 | if Is_Derived_Type (E) | |
1237 | and then not Comes_From_Source (E) | |
1238 | and then E /= First_Subtype (E) | |
1239 | then | |
1240 | null; | |
1241 | else | |
1242 | Analyze_Aspect_Default_Value (ASN); | |
1243 | end if; | |
06ef5f86 | 1244 | |
37c6e44c | 1245 | -- Ditto for iterator aspects, because the corresponding |
1246 | -- attributes may not have been analyzed yet. | |
af9fed8f | 1247 | |
99378362 | 1248 | when Aspect_Constant_Indexing |
1249 | | Aspect_Default_Iterator | |
1250 | | Aspect_Iterator_Element | |
1251 | | Aspect_Variable_Indexing | |
1252 | => | |
7d6fb253 | 1253 | Analyze (Expression (ASN)); |
af9fed8f | 1254 | |
7d6fb253 | 1255 | if Etype (Expression (ASN)) = Any_Type then |
1256 | Error_Msg_NE | |
1257 | ("\aspect must be fully defined before & is frozen", | |
1258 | ASN, E); | |
1259 | end if; | |
b3f8228a | 1260 | |
7d6fb253 | 1261 | when Aspect_Iterable => |
1262 | Validate_Iterable_Aspect (E, ASN); | |
1263 | ||
1264 | when others => | |
1265 | null; | |
37c6e44c | 1266 | end case; |
06ef5f86 | 1267 | |
37c6e44c | 1268 | Ritem := Aspect_Rep_Item (ASN); |
06ef5f86 | 1269 | |
37c6e44c | 1270 | if Present (Ritem) then |
1271 | Analyze (Ritem); | |
1272 | end if; | |
06ef5f86 | 1273 | end if; |
1274 | end if; | |
1275 | ||
1276 | Next_Rep_Item (ASN); | |
1277 | end loop; | |
37c6e44c | 1278 | |
1279 | -- This is where we inherit delayed rep aspects from our parent. Note | |
1280 | -- that if we fell out of the above loop with ASN non-empty, it means | |
1281 | -- we hit an aspect for an entity other than E, and it must be the | |
1282 | -- type from which we were derived. | |
1283 | ||
1284 | if May_Inherit_Delayed_Rep_Aspects (E) then | |
1285 | Inherit_Delayed_Rep_Aspects (ASN); | |
1286 | end if; | |
06ef5f86 | 1287 | end Analyze_Aspects_At_Freeze_Point; |
1288 | ||
ae888dbd | 1289 | ----------------------------------- |
1290 | -- Analyze_Aspect_Specifications -- | |
1291 | ----------------------------------- | |
1292 | ||
21ea3a4f | 1293 | procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is |
e2bf777d | 1294 | procedure Decorate (Asp : Node_Id; Prag : Node_Id); |
6c5793cd | 1295 | -- Establish linkages between an aspect and its corresponding pragma |
5ddd846b | 1296 | |
5655be8a | 1297 | procedure Insert_Pragma |
1298 | (Prag : Node_Id; | |
1299 | Is_Instance : Boolean := False); | |
2f06c88a | 1300 | -- Subsidiary to the analysis of aspects |
1301 | -- Abstract_State | |
2f06c88a | 1302 | -- Attach_Handler |
1303 | -- Contract_Cases | |
1304 | -- Depends | |
5655be8a | 1305 | -- Ghost |
2f06c88a | 1306 | -- Global |
5655be8a | 1307 | -- Initial_Condition |
1308 | -- Initializes | |
2f06c88a | 1309 | -- Post |
1310 | -- Pre | |
1311 | -- Refined_Depends | |
1312 | -- Refined_Global | |
5655be8a | 1313 | -- Refined_State |
2f06c88a | 1314 | -- SPARK_Mode |
1315 | -- Warnings | |
e2bf777d | 1316 | -- Insert pragma Prag such that it mimics the placement of a source |
5655be8a | 1317 | -- pragma of the same kind. Flag Is_Generic should be set when the |
1318 | -- context denotes a generic instance. | |
e2bf777d | 1319 | |
1320 | -------------- | |
1321 | -- Decorate -- | |
1322 | -------------- | |
1323 | ||
1324 | procedure Decorate (Asp : Node_Id; Prag : Node_Id) is | |
5ddd846b | 1325 | begin |
6c5793cd | 1326 | Set_Aspect_Rep_Item (Asp, Prag); |
5ddd846b | 1327 | Set_Corresponding_Aspect (Prag, Asp); |
1328 | Set_From_Aspect_Specification (Prag); | |
5ddd846b | 1329 | Set_Parent (Prag, Asp); |
e2bf777d | 1330 | end Decorate; |
f0813d71 | 1331 | |
e2bf777d | 1332 | ------------------- |
1333 | -- Insert_Pragma -- | |
1334 | ------------------- | |
c1006d6d | 1335 | |
5655be8a | 1336 | procedure Insert_Pragma |
1337 | (Prag : Node_Id; | |
1338 | Is_Instance : Boolean := False) | |
1339 | is | |
3ff5e35d | 1340 | Aux : Node_Id; |
1341 | Decl : Node_Id; | |
1342 | Decls : List_Id; | |
1343 | Def : Node_Id; | |
1344 | Inserted : Boolean := False; | |
c1006d6d | 1345 | |
1346 | begin | |
3ff5e35d | 1347 | -- When the aspect appears on an entry, package, protected unit, |
1348 | -- subprogram, or task unit body, insert the generated pragma at the | |
1349 | -- top of the body declarations to emulate the behavior of a source | |
1350 | -- pragma. | |
2f06c88a | 1351 | |
1352 | -- package body Pack with Aspect is | |
1353 | ||
1354 | -- package body Pack is | |
1355 | -- pragma Prag; | |
1356 | ||
3ff5e35d | 1357 | if Nkind_In (N, N_Entry_Body, |
1358 | N_Package_Body, | |
2f06c88a | 1359 | N_Protected_Body, |
1360 | N_Subprogram_Body, | |
1361 | N_Task_Body) | |
1362 | then | |
1363 | Decls := Declarations (N); | |
1364 | ||
1365 | if No (Decls) then | |
1366 | Decls := New_List; | |
1367 | Set_Declarations (N, Decls); | |
1368 | end if; | |
e2bf777d | 1369 | |
3ff5e35d | 1370 | Prepend_To (Decls, Prag); |
2f06c88a | 1371 | |
1372 | -- When the aspect is associated with a [generic] package declaration | |
1373 | -- insert the generated pragma at the top of the visible declarations | |
1374 | -- to emulate the behavior of a source pragma. | |
1375 | ||
1376 | -- package Pack with Aspect is | |
1377 | ||
1378 | -- package Pack is | |
1379 | -- pragma Prag; | |
1380 | ||
1381 | elsif Nkind_In (N, N_Generic_Package_Declaration, | |
1382 | N_Package_Declaration) | |
1383 | then | |
1384 | Decls := Visible_Declarations (Specification (N)); | |
1385 | ||
1386 | if No (Decls) then | |
1387 | Decls := New_List; | |
1388 | Set_Visible_Declarations (Specification (N), Decls); | |
1389 | end if; | |
1390 | ||
5655be8a | 1391 | -- The visible declarations of a generic instance have the |
1392 | -- following structure: | |
1393 | ||
1394 | -- <renamings of generic formals> | |
1395 | -- <renamings of internally-generated spec and body> | |
1396 | -- <first source declaration> | |
1397 | ||
1398 | -- Insert the pragma before the first source declaration by | |
3ff5e35d | 1399 | -- skipping the instance "header" to ensure proper visibility of |
1400 | -- all formals. | |
5655be8a | 1401 | |
1402 | if Is_Instance then | |
1403 | Decl := First (Decls); | |
3ff5e35d | 1404 | while Present (Decl) loop |
1405 | if Comes_From_Source (Decl) then | |
1406 | Insert_Before (Decl, Prag); | |
1407 | Inserted := True; | |
1408 | exit; | |
1409 | else | |
1410 | Next (Decl); | |
1411 | end if; | |
5655be8a | 1412 | end loop; |
1413 | ||
3ff5e35d | 1414 | -- The pragma is placed after the instance "header" |
5655be8a | 1415 | |
3ff5e35d | 1416 | if not Inserted then |
5655be8a | 1417 | Append_To (Decls, Prag); |
1418 | end if; | |
1419 | ||
1420 | -- Otherwise this is not a generic instance | |
1421 | ||
1422 | else | |
1423 | Prepend_To (Decls, Prag); | |
1424 | end if; | |
2f06c88a | 1425 | |
1426 | -- When the aspect is associated with a protected unit declaration, | |
1427 | -- insert the generated pragma at the top of the visible declarations | |
1428 | -- the emulate the behavior of a source pragma. | |
1429 | ||
1430 | -- protected [type] Prot with Aspect is | |
1431 | ||
1432 | -- protected [type] Prot is | |
1433 | -- pragma Prag; | |
1434 | ||
1435 | elsif Nkind (N) = N_Protected_Type_Declaration then | |
736b80cc | 1436 | Def := Protected_Definition (N); |
1437 | ||
1438 | if No (Def) then | |
1439 | Def := | |
1440 | Make_Protected_Definition (Sloc (N), | |
1441 | Visible_Declarations => New_List, | |
1442 | End_Label => Empty); | |
1443 | ||
1444 | Set_Protected_Definition (N, Def); | |
1445 | end if; | |
1446 | ||
1447 | Decls := Visible_Declarations (Def); | |
2f06c88a | 1448 | |
1449 | if No (Decls) then | |
1450 | Decls := New_List; | |
736b80cc | 1451 | Set_Visible_Declarations (Def, Decls); |
2f06c88a | 1452 | end if; |
1453 | ||
1454 | Prepend_To (Decls, Prag); | |
1455 | ||
736b80cc | 1456 | -- When the aspect is associated with a task unit declaration, insert |
1457 | -- insert the generated pragma at the top of the visible declarations | |
1458 | -- the emulate the behavior of a source pragma. | |
2f06c88a | 1459 | |
1460 | -- task [type] Prot with Aspect is | |
1461 | ||
1462 | -- task [type] Prot is | |
1463 | -- pragma Prag; | |
1464 | ||
736b80cc | 1465 | elsif Nkind (N) = N_Task_Type_Declaration then |
1466 | Def := Task_Definition (N); | |
1467 | ||
1468 | if No (Def) then | |
1469 | Def := | |
1470 | Make_Task_Definition (Sloc (N), | |
1471 | Visible_Declarations => New_List, | |
1472 | End_Label => Empty); | |
1473 | ||
1474 | Set_Task_Definition (N, Def); | |
1475 | end if; | |
1476 | ||
1477 | Decls := Visible_Declarations (Def); | |
2f06c88a | 1478 | |
1479 | if No (Decls) then | |
1480 | Decls := New_List; | |
736b80cc | 1481 | Set_Visible_Declarations (Def, Decls); |
d324c418 | 1482 | end if; |
c1006d6d | 1483 | |
2f06c88a | 1484 | Prepend_To (Decls, Prag); |
1485 | ||
ed695684 | 1486 | -- When the context is a library unit, the pragma is added to the |
1487 | -- Pragmas_After list. | |
1488 | ||
1489 | elsif Nkind (Parent (N)) = N_Compilation_Unit then | |
1490 | Aux := Aux_Decls_Node (Parent (N)); | |
1491 | ||
1492 | if No (Pragmas_After (Aux)) then | |
1493 | Set_Pragmas_After (Aux, New_List); | |
1494 | end if; | |
1495 | ||
1496 | Prepend (Prag, Pragmas_After (Aux)); | |
1497 | ||
2f06c88a | 1498 | -- Default, the pragma is inserted after the context |
c1006d6d | 1499 | |
1500 | else | |
1501 | Insert_After (N, Prag); | |
c1006d6d | 1502 | end if; |
e2bf777d | 1503 | end Insert_Pragma; |
c1006d6d | 1504 | |
1505 | -- Local variables | |
1506 | ||
ae888dbd | 1507 | Aspect : Node_Id; |
d74fc39a | 1508 | Aitem : Node_Id; |
ae888dbd | 1509 | Ent : Node_Id; |
ae888dbd | 1510 | |
21ea3a4f | 1511 | L : constant List_Id := Aspect_Specifications (N); |
1512 | ||
ae888dbd | 1513 | Ins_Node : Node_Id := N; |
89f1e35c | 1514 | -- Insert pragmas/attribute definition clause after this node when no |
1515 | -- delayed analysis is required. | |
d74fc39a | 1516 | |
ee2b7923 | 1517 | -- Start of processing for Analyze_Aspect_Specifications |
f0813d71 | 1518 | |
ee2b7923 | 1519 | begin |
d74fc39a | 1520 | -- The general processing involves building an attribute definition |
89f1e35c | 1521 | -- clause or a pragma node that corresponds to the aspect. Then in order |
1522 | -- to delay the evaluation of this aspect to the freeze point, we attach | |
1523 | -- the corresponding pragma/attribute definition clause to the aspect | |
1524 | -- specification node, which is then placed in the Rep Item chain. In | |
1525 | -- this case we mark the entity by setting the flag Has_Delayed_Aspects | |
1526 | -- and we evaluate the rep item at the freeze point. When the aspect | |
1527 | -- doesn't have a corresponding pragma/attribute definition clause, then | |
1528 | -- its analysis is simply delayed at the freeze point. | |
1529 | ||
1530 | -- Some special cases don't require delay analysis, thus the aspect is | |
1531 | -- analyzed right now. | |
1532 | ||
51ea9c94 | 1533 | -- Note that there is a special handling for Pre, Post, Test_Case, |
e66f4e2a | 1534 | -- Contract_Cases aspects. In these cases, we do not have to worry |
51ea9c94 | 1535 | -- about delay issues, since the pragmas themselves deal with delay |
1536 | -- of visibility for the expression analysis. Thus, we just insert | |
1537 | -- the pragma after the node N. | |
ae888dbd | 1538 | |
21ea3a4f | 1539 | pragma Assert (Present (L)); |
1540 | ||
6fb3c314 | 1541 | -- Loop through aspects |
f93e7257 | 1542 | |
ae888dbd | 1543 | Aspect := First (L); |
21ea3a4f | 1544 | Aspect_Loop : while Present (Aspect) loop |
0fd13d32 | 1545 | Analyze_One_Aspect : declare |
94153a42 | 1546 | Expr : constant Node_Id := Expression (Aspect); |
89f1e35c | 1547 | Id : constant Node_Id := Identifier (Aspect); |
1548 | Loc : constant Source_Ptr := Sloc (Aspect); | |
94153a42 | 1549 | Nam : constant Name_Id := Chars (Id); |
1550 | A_Id : constant Aspect_Id := Get_Aspect_Id (Nam); | |
ae888dbd | 1551 | Anod : Node_Id; |
1552 | ||
37c6e44c | 1553 | Delay_Required : Boolean; |
89f1e35c | 1554 | -- Set False if delay is not required |
1555 | ||
c0793fff | 1556 | Eloc : Source_Ptr := No_Location; |
1557 | -- Source location of expression, modified when we split PPC's. It | |
1558 | -- is set below when Expr is present. | |
39e1f22f | 1559 | |
ee2b7923 | 1560 | procedure Analyze_Aspect_Convention; |
1561 | -- Perform analysis of aspect Convention | |
1562 | ||
1563 | procedure Analyze_Aspect_Export_Import; | |
1564 | -- Perform analysis of aspects Export or Import | |
1565 | ||
1566 | procedure Analyze_Aspect_External_Link_Name; | |
1567 | -- Perform analysis of aspects External_Name or Link_Name | |
21ea3a4f | 1568 | |
89f1e35c | 1569 | procedure Analyze_Aspect_Implicit_Dereference; |
9ab32fe9 | 1570 | -- Perform analysis of the Implicit_Dereference aspects |
0fd13d32 | 1571 | |
1572 | procedure Make_Aitem_Pragma | |
1573 | (Pragma_Argument_Associations : List_Id; | |
1574 | Pragma_Name : Name_Id); | |
1575 | -- This is a wrapper for Make_Pragma used for converting aspects | |
1576 | -- to pragmas. It takes care of Sloc (set from Loc) and building | |
1577 | -- the pragma identifier from the given name. In addition the | |
1578 | -- flags Class_Present and Split_PPC are set from the aspect | |
1579 | -- node, as well as Is_Ignored. This routine also sets the | |
1580 | -- From_Aspect_Specification in the resulting pragma node to | |
1581 | -- True, and sets Corresponding_Aspect to point to the aspect. | |
1582 | -- The resulting pragma is assigned to Aitem. | |
21ea3a4f | 1583 | |
ee2b7923 | 1584 | ------------------------------- |
1585 | -- Analyze_Aspect_Convention -- | |
1586 | ------------------------------- | |
1587 | ||
1588 | procedure Analyze_Aspect_Convention is | |
1589 | Conv : Node_Id; | |
1590 | Dummy_1 : Node_Id; | |
1591 | Dummy_2 : Node_Id; | |
1592 | Dummy_3 : Node_Id; | |
1593 | Expo : Node_Id; | |
1594 | Imp : Node_Id; | |
89f1e35c | 1595 | |
21ea3a4f | 1596 | begin |
ee2b7923 | 1597 | -- Obtain all interfacing aspects that apply to the related |
1598 | -- entity. | |
1599 | ||
1600 | Get_Interfacing_Aspects | |
1601 | (Iface_Asp => Aspect, | |
1602 | Conv_Asp => Dummy_1, | |
1603 | EN_Asp => Dummy_2, | |
1604 | Expo_Asp => Expo, | |
1605 | Imp_Asp => Imp, | |
1606 | LN_Asp => Dummy_3, | |
1607 | Do_Checks => True); | |
1608 | ||
1609 | -- The related entity is subject to aspect Export or Import. | |
1610 | -- Do not process Convention now because it must be analysed | |
1611 | -- as part of Export or Import. | |
1612 | ||
1613 | if Present (Expo) or else Present (Imp) then | |
1614 | return; | |
21ea3a4f | 1615 | |
ee2b7923 | 1616 | -- Otherwise Convention appears by itself |
21ea3a4f | 1617 | |
ee2b7923 | 1618 | else |
1619 | -- The aspect specifies a particular convention | |
1620 | ||
1621 | if Present (Expr) then | |
1622 | Conv := New_Copy_Tree (Expr); | |
1623 | ||
1624 | -- Otherwise assume convention Ada | |
1625 | ||
1626 | else | |
1627 | Conv := Make_Identifier (Loc, Name_Ada); | |
1628 | end if; | |
1629 | ||
1630 | -- Generate: | |
1631 | -- pragma Convention (<Conv>, <E>); | |
1632 | ||
1633 | Make_Aitem_Pragma | |
1634 | (Pragma_Name => Name_Convention, | |
1635 | Pragma_Argument_Associations => New_List ( | |
1636 | Make_Pragma_Argument_Association (Loc, | |
1637 | Expression => Conv), | |
1638 | Make_Pragma_Argument_Association (Loc, | |
1639 | Expression => New_Occurrence_Of (E, Loc)))); | |
1640 | ||
1641 | Decorate (Aspect, Aitem); | |
1642 | Insert_Pragma (Aitem); | |
1643 | end if; | |
1644 | end Analyze_Aspect_Convention; | |
1645 | ||
1646 | ---------------------------------- | |
1647 | -- Analyze_Aspect_Export_Import -- | |
1648 | ---------------------------------- | |
21ea3a4f | 1649 | |
ee2b7923 | 1650 | procedure Analyze_Aspect_Export_Import is |
1651 | Dummy_1 : Node_Id; | |
1652 | Dummy_2 : Node_Id; | |
1653 | Dummy_3 : Node_Id; | |
1654 | Expo : Node_Id; | |
1655 | Imp : Node_Id; | |
1656 | ||
1657 | begin | |
1658 | -- Obtain all interfacing aspects that apply to the related | |
1659 | -- entity. | |
1660 | ||
1661 | Get_Interfacing_Aspects | |
1662 | (Iface_Asp => Aspect, | |
1663 | Conv_Asp => Dummy_1, | |
1664 | EN_Asp => Dummy_2, | |
1665 | Expo_Asp => Expo, | |
1666 | Imp_Asp => Imp, | |
1667 | LN_Asp => Dummy_3, | |
1668 | Do_Checks => True); | |
1669 | ||
1670 | -- The related entity cannot be subject to both aspects Export | |
1671 | -- and Import. | |
1672 | ||
1673 | if Present (Expo) and then Present (Imp) then | |
1674 | Error_Msg_N | |
1675 | ("incompatible interfacing aspects given for &", E); | |
1676 | Error_Msg_Sloc := Sloc (Expo); | |
1677 | Error_Msg_N ("\aspect `Export` #", E); | |
1678 | Error_Msg_Sloc := Sloc (Imp); | |
1679 | Error_Msg_N ("\aspect `Import` #", E); | |
1680 | end if; | |
1681 | ||
1682 | -- A variable is most likely modified from the outside. Take | |
051826ee | 1683 | -- the optimistic approach to avoid spurious errors. |
ee2b7923 | 1684 | |
1685 | if Ekind (E) = E_Variable then | |
1686 | Set_Never_Set_In_Source (E, False); | |
1687 | end if; | |
1688 | ||
1689 | -- Resolve the expression of an Import or Export here, and | |
1690 | -- require it to be of type Boolean and static. This is not | |
1691 | -- quite right, because in general this should be delayed, | |
1692 | -- but that seems tricky for these, because normally Boolean | |
1693 | -- aspects are replaced with pragmas at the freeze point in | |
1694 | -- Make_Pragma_From_Boolean_Aspect. | |
1695 | ||
1696 | if not Present (Expr) | |
1697 | or else Is_True (Static_Boolean (Expr)) | |
1698 | then | |
1699 | if A_Id = Aspect_Import then | |
1700 | Set_Has_Completion (E); | |
1701 | Set_Is_Imported (E); | |
1702 | ||
1703 | -- An imported object cannot be explicitly initialized | |
1704 | ||
1705 | if Nkind (N) = N_Object_Declaration | |
1706 | and then Present (Expression (N)) | |
1707 | then | |
1708 | Error_Msg_N | |
1709 | ("imported entities cannot be initialized " | |
1710 | & "(RM B.1(24))", Expression (N)); | |
1711 | end if; | |
1712 | ||
1713 | else | |
1714 | pragma Assert (A_Id = Aspect_Export); | |
1715 | Set_Is_Exported (E); | |
1716 | end if; | |
1717 | ||
1718 | -- Create the proper form of pragma Export or Import taking | |
1719 | -- into account Conversion, External_Name, and Link_Name. | |
1720 | ||
1721 | Aitem := Build_Export_Import_Pragma (Aspect, E); | |
d8e539ae | 1722 | |
1723 | -- Otherwise the expression is either False or erroneous. There | |
1724 | -- is no corresponding pragma. | |
1725 | ||
1726 | else | |
1727 | Aitem := Empty; | |
ee2b7923 | 1728 | end if; |
1729 | end Analyze_Aspect_Export_Import; | |
1730 | ||
1731 | --------------------------------------- | |
1732 | -- Analyze_Aspect_External_Link_Name -- | |
1733 | --------------------------------------- | |
1734 | ||
1735 | procedure Analyze_Aspect_External_Link_Name is | |
1736 | Dummy_1 : Node_Id; | |
1737 | Dummy_2 : Node_Id; | |
1738 | Dummy_3 : Node_Id; | |
1739 | Expo : Node_Id; | |
1740 | Imp : Node_Id; | |
1741 | ||
1742 | begin | |
1743 | -- Obtain all interfacing aspects that apply to the related | |
1744 | -- entity. | |
1745 | ||
1746 | Get_Interfacing_Aspects | |
1747 | (Iface_Asp => Aspect, | |
1748 | Conv_Asp => Dummy_1, | |
1749 | EN_Asp => Dummy_2, | |
1750 | Expo_Asp => Expo, | |
1751 | Imp_Asp => Imp, | |
1752 | LN_Asp => Dummy_3, | |
1753 | Do_Checks => True); | |
1754 | ||
1755 | -- Ensure that aspect External_Name applies to aspect Export or | |
1756 | -- Import. | |
1757 | ||
1758 | if A_Id = Aspect_External_Name then | |
1759 | if No (Expo) and then No (Imp) then | |
89f1e35c | 1760 | Error_Msg_N |
ee2b7923 | 1761 | ("aspect `External_Name` requires aspect `Import` or " |
1762 | & "`Export`", Aspect); | |
89f1e35c | 1763 | end if; |
ee2b7923 | 1764 | |
1765 | -- Otherwise ensure that aspect Link_Name applies to aspect | |
1766 | -- Export or Import. | |
1767 | ||
1768 | else | |
1769 | pragma Assert (A_Id = Aspect_Link_Name); | |
1770 | if No (Expo) and then No (Imp) then | |
1771 | Error_Msg_N | |
1772 | ("aspect `Link_Name` requires aspect `Import` or " | |
1773 | & "`Export`", Aspect); | |
1774 | end if; | |
1775 | end if; | |
1776 | end Analyze_Aspect_External_Link_Name; | |
21ea3a4f | 1777 | |
89f1e35c | 1778 | ----------------------------------------- |
1779 | -- Analyze_Aspect_Implicit_Dereference -- | |
1780 | ----------------------------------------- | |
21ea3a4f | 1781 | |
89f1e35c | 1782 | procedure Analyze_Aspect_Implicit_Dereference is |
1ff43c00 | 1783 | Disc : Entity_Id; |
1784 | Parent_Disc : Entity_Id; | |
1785 | ||
89f1e35c | 1786 | begin |
b9e61b2a | 1787 | if not Is_Type (E) or else not Has_Discriminants (E) then |
89f1e35c | 1788 | Error_Msg_N |
1ff43c00 | 1789 | ("aspect must apply to a type with discriminants", Expr); |
21ea3a4f | 1790 | |
1ff43c00 | 1791 | elsif not Is_Entity_Name (Expr) then |
1792 | Error_Msg_N | |
1793 | ("aspect must name a discriminant of current type", Expr); | |
21ea3a4f | 1794 | |
1ff43c00 | 1795 | else |
f021ee0f | 1796 | -- Discriminant type be an anonymous access type or an |
1797 | -- anonymous access to subprogram. | |
0d0a4e9b | 1798 | |
f021ee0f | 1799 | -- Missing synchronized types??? |
1800 | ||
1ff43c00 | 1801 | Disc := First_Discriminant (E); |
1802 | while Present (Disc) loop | |
1803 | if Chars (Expr) = Chars (Disc) | |
f021ee0f | 1804 | and then Ekind_In (Etype (Disc), |
0d0a4e9b | 1805 | E_Anonymous_Access_Subprogram_Type, |
1806 | E_Anonymous_Access_Type) | |
1ff43c00 | 1807 | then |
1808 | Set_Has_Implicit_Dereference (E); | |
1809 | Set_Has_Implicit_Dereference (Disc); | |
1810 | exit; | |
1811 | end if; | |
21ea3a4f | 1812 | |
1ff43c00 | 1813 | Next_Discriminant (Disc); |
1814 | end loop; | |
21ea3a4f | 1815 | |
9b5b11fb | 1816 | -- Error if no proper access discriminant |
21ea3a4f | 1817 | |
1ff43c00 | 1818 | if No (Disc) then |
ee2b7923 | 1819 | Error_Msg_NE ("not an access discriminant of&", Expr, E); |
1ff43c00 | 1820 | return; |
1821 | end if; | |
1822 | end if; | |
1823 | ||
9b5b11fb | 1824 | -- For a type extension, check whether parent has a |
1825 | -- reference discriminant, to verify that use is proper. | |
1826 | ||
1ff43c00 | 1827 | if Is_Derived_Type (E) |
1828 | and then Has_Discriminants (Etype (E)) | |
1829 | then | |
1830 | Parent_Disc := Get_Reference_Discriminant (Etype (E)); | |
1831 | ||
1832 | if Present (Parent_Disc) | |
1833 | and then Corresponding_Discriminant (Disc) /= Parent_Disc | |
1834 | then | |
ee2b7923 | 1835 | Error_Msg_N |
1836 | ("reference discriminant does not match discriminant " | |
1837 | & "of parent type", Expr); | |
1ff43c00 | 1838 | end if; |
89f1e35c | 1839 | end if; |
1840 | end Analyze_Aspect_Implicit_Dereference; | |
21ea3a4f | 1841 | |
0fd13d32 | 1842 | ----------------------- |
1843 | -- Make_Aitem_Pragma -- | |
1844 | ----------------------- | |
1845 | ||
1846 | procedure Make_Aitem_Pragma | |
1847 | (Pragma_Argument_Associations : List_Id; | |
1848 | Pragma_Name : Name_Id) | |
1849 | is | |
b855559d | 1850 | Args : List_Id := Pragma_Argument_Associations; |
1851 | ||
0fd13d32 | 1852 | begin |
1853 | -- We should never get here if aspect was disabled | |
1854 | ||
1855 | pragma Assert (not Is_Disabled (Aspect)); | |
1856 | ||
056dc987 | 1857 | -- Certain aspects allow for an optional name or expression. Do |
1858 | -- not generate a pragma with empty argument association list. | |
b855559d | 1859 | |
1860 | if No (Args) or else No (Expression (First (Args))) then | |
1861 | Args := No_List; | |
1862 | end if; | |
1863 | ||
0fd13d32 | 1864 | -- Build the pragma |
1865 | ||
1866 | Aitem := | |
1867 | Make_Pragma (Loc, | |
b855559d | 1868 | Pragma_Argument_Associations => Args, |
0fd13d32 | 1869 | Pragma_Identifier => |
1870 | Make_Identifier (Sloc (Id), Pragma_Name), | |
9ab32fe9 | 1871 | Class_Present => Class_Present (Aspect), |
1872 | Split_PPC => Split_PPC (Aspect)); | |
0fd13d32 | 1873 | |
1874 | -- Set additional semantic fields | |
1875 | ||
1876 | if Is_Ignored (Aspect) then | |
1877 | Set_Is_Ignored (Aitem); | |
57d8d1f3 | 1878 | elsif Is_Checked (Aspect) then |
a5109493 | 1879 | Set_Is_Checked (Aitem); |
0fd13d32 | 1880 | end if; |
1881 | ||
1882 | Set_Corresponding_Aspect (Aitem, Aspect); | |
fdec445e | 1883 | Set_From_Aspect_Specification (Aitem); |
0fd13d32 | 1884 | end Make_Aitem_Pragma; |
1885 | ||
738ec25b | 1886 | -- Start of processing for Analyze_One_Aspect |
0fd13d32 | 1887 | |
ae888dbd | 1888 | begin |
2d1acfa7 | 1889 | -- Skip aspect if already analyzed, to avoid looping in some cases |
fb7f2fc4 | 1890 | |
1891 | if Analyzed (Aspect) then | |
1892 | goto Continue; | |
1893 | end if; | |
1894 | ||
ef957022 | 1895 | -- Skip looking at aspect if it is totally disabled. Just mark it |
1896 | -- as such for later reference in the tree. This also sets the | |
1897 | -- Is_Ignored and Is_Checked flags appropriately. | |
51ea9c94 | 1898 | |
1899 | Check_Applicable_Policy (Aspect); | |
1900 | ||
1901 | if Is_Disabled (Aspect) then | |
1902 | goto Continue; | |
1903 | end if; | |
1904 | ||
c0793fff | 1905 | -- Set the source location of expression, used in the case of |
1906 | -- a failed precondition/postcondition or invariant. Note that | |
1907 | -- the source location of the expression is not usually the best | |
1908 | -- choice here. For example, it gets located on the last AND | |
1909 | -- keyword in a chain of boolean expressiond AND'ed together. | |
1910 | -- It is best to put the message on the first character of the | |
1911 | -- assertion, which is the effect of the First_Node call here. | |
1912 | ||
1913 | if Present (Expr) then | |
1914 | Eloc := Sloc (First_Node (Expr)); | |
1915 | end if; | |
1916 | ||
d7ed83a2 | 1917 | -- Check restriction No_Implementation_Aspect_Specifications |
1918 | ||
c171e1be | 1919 | if Implementation_Defined_Aspect (A_Id) then |
d7ed83a2 | 1920 | Check_Restriction |
1921 | (No_Implementation_Aspect_Specifications, Aspect); | |
1922 | end if; | |
1923 | ||
1924 | -- Check restriction No_Specification_Of_Aspect | |
1925 | ||
1926 | Check_Restriction_No_Specification_Of_Aspect (Aspect); | |
1927 | ||
f67ed4f5 | 1928 | -- Mark aspect analyzed (actual analysis is delayed till later) |
d7ed83a2 | 1929 | |
fb7f2fc4 | 1930 | Set_Analyzed (Aspect); |
d74fc39a | 1931 | Set_Entity (Aspect, E); |
738ec25b | 1932 | |
1933 | -- Build the reference to E that will be used in the built pragmas | |
1934 | ||
d74fc39a | 1935 | Ent := New_Occurrence_Of (E, Sloc (Id)); |
1936 | ||
738ec25b | 1937 | if A_Id = Aspect_Attach_Handler |
1938 | or else A_Id = Aspect_Interrupt_Handler | |
1939 | then | |
1940 | -- Decorate the reference as comming from the sources and force | |
1941 | -- its reanalysis to generate the reference to E; required to | |
1942 | -- avoid reporting spurious warning on E as unreferenced entity | |
1943 | -- (because aspects are not fully analyzed). | |
1944 | ||
1945 | Set_Comes_From_Source (Ent, Comes_From_Source (Id)); | |
1946 | Set_Entity (Ent, Empty); | |
1947 | ||
1948 | Analyze (Ent); | |
1949 | end if; | |
1950 | ||
1e3c4ae6 | 1951 | -- Check for duplicate aspect. Note that the Comes_From_Source |
1952 | -- test allows duplicate Pre/Post's that we generate internally | |
1953 | -- to escape being flagged here. | |
ae888dbd | 1954 | |
6c545057 | 1955 | if No_Duplicates_Allowed (A_Id) then |
1956 | Anod := First (L); | |
1957 | while Anod /= Aspect loop | |
c171e1be | 1958 | if Comes_From_Source (Aspect) |
1959 | and then Same_Aspect (A_Id, Get_Aspect_Id (Anod)) | |
6c545057 | 1960 | then |
1961 | Error_Msg_Name_1 := Nam; | |
1962 | Error_Msg_Sloc := Sloc (Anod); | |
39e1f22f | 1963 | |
6c545057 | 1964 | -- Case of same aspect specified twice |
39e1f22f | 1965 | |
6c545057 | 1966 | if Class_Present (Anod) = Class_Present (Aspect) then |
1967 | if not Class_Present (Anod) then | |
1968 | Error_Msg_NE | |
1969 | ("aspect% for & previously given#", | |
1970 | Id, E); | |
1971 | else | |
1972 | Error_Msg_NE | |
1973 | ("aspect `%''Class` for & previously given#", | |
1974 | Id, E); | |
1975 | end if; | |
39e1f22f | 1976 | end if; |
6c545057 | 1977 | end if; |
ae888dbd | 1978 | |
6c545057 | 1979 | Next (Anod); |
1980 | end loop; | |
1981 | end if; | |
ae888dbd | 1982 | |
4db325e6 | 1983 | -- Check some general restrictions on language defined aspects |
1984 | ||
c171e1be | 1985 | if not Implementation_Defined_Aspect (A_Id) then |
4db325e6 | 1986 | Error_Msg_Name_1 := Nam; |
1987 | ||
d1edd78e | 1988 | -- Not allowed for renaming declarations. Examine the original |
da1b7592 | 1989 | -- node because a subprogram renaming may have been rewritten |
1990 | -- as a body. | |
4db325e6 | 1991 | |
da1b7592 | 1992 | if Nkind (Original_Node (N)) in N_Renaming_Declaration then |
4db325e6 | 1993 | Error_Msg_N |
1994 | ("aspect % not allowed for renaming declaration", | |
1995 | Aspect); | |
1996 | end if; | |
1997 | ||
1998 | -- Not allowed for formal type declarations | |
1999 | ||
2000 | if Nkind (N) = N_Formal_Type_Declaration then | |
2001 | Error_Msg_N | |
2002 | ("aspect % not allowed for formal type declaration", | |
2003 | Aspect); | |
2004 | end if; | |
2005 | end if; | |
2006 | ||
7d20685d | 2007 | -- Copy expression for later processing by the procedures |
2008 | -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations] | |
2009 | ||
2010 | Set_Entity (Id, New_Copy_Tree (Expr)); | |
2011 | ||
37c6e44c | 2012 | -- Set Delay_Required as appropriate to aspect |
2013 | ||
2014 | case Aspect_Delay (A_Id) is | |
2015 | when Always_Delay => | |
2016 | Delay_Required := True; | |
2017 | ||
2018 | when Never_Delay => | |
2019 | Delay_Required := False; | |
2020 | ||
2021 | when Rep_Aspect => | |
2022 | ||
2023 | -- If expression has the form of an integer literal, then | |
2024 | -- do not delay, since we know the value cannot change. | |
2025 | -- This optimization catches most rep clause cases. | |
2026 | ||
e43fc5c5 | 2027 | -- For Boolean aspects, don't delay if no expression |
2028 | ||
2029 | if A_Id in Boolean_Aspects and then No (Expr) then | |
2030 | Delay_Required := False; | |
2031 | ||
c5c6a638 | 2032 | -- For non-Boolean aspects, don't delay if integer literal, |
2033 | -- unless the aspect is Alignment, which affects the | |
2034 | -- freezing of an initialized object. | |
e43fc5c5 | 2035 | |
2036 | elsif A_Id not in Boolean_Aspects | |
c5c6a638 | 2037 | and then A_Id /= Aspect_Alignment |
e43fc5c5 | 2038 | and then Present (Expr) |
2039 | and then Nkind (Expr) = N_Integer_Literal | |
2040 | then | |
2041 | Delay_Required := False; | |
2042 | ||
2043 | -- All other cases are delayed | |
2044 | ||
2045 | else | |
2046 | Delay_Required := True; | |
2047 | Set_Has_Delayed_Rep_Aspects (E); | |
2048 | end if; | |
37c6e44c | 2049 | end case; |
2050 | ||
ae888dbd | 2051 | -- Processing based on specific aspect |
2052 | ||
d74fc39a | 2053 | case A_Id is |
aa2f48d2 | 2054 | when Aspect_Unimplemented => |
2055 | null; -- ??? temp for now | |
ae888dbd | 2056 | |
2057 | -- No_Aspect should be impossible | |
2058 | ||
2059 | when No_Aspect => | |
2060 | raise Program_Error; | |
2061 | ||
89f1e35c | 2062 | -- Case 1: Aspects corresponding to attribute definition |
2063 | -- clauses. | |
ae888dbd | 2064 | |
99378362 | 2065 | when Aspect_Address |
2066 | | Aspect_Alignment | |
2067 | | Aspect_Bit_Order | |
2068 | | Aspect_Component_Size | |
2069 | | Aspect_Constant_Indexing | |
2070 | | Aspect_Default_Iterator | |
2071 | | Aspect_Dispatching_Domain | |
2072 | | Aspect_External_Tag | |
2073 | | Aspect_Input | |
2074 | | Aspect_Iterable | |
2075 | | Aspect_Iterator_Element | |
2076 | | Aspect_Machine_Radix | |
2077 | | Aspect_Object_Size | |
2078 | | Aspect_Output | |
2079 | | Aspect_Read | |
2080 | | Aspect_Scalar_Storage_Order | |
2081 | | Aspect_Secondary_Stack_Size | |
2082 | | Aspect_Simple_Storage_Pool | |
2083 | | Aspect_Size | |
2084 | | Aspect_Small | |
2085 | | Aspect_Storage_Pool | |
2086 | | Aspect_Stream_Size | |
2087 | | Aspect_Value_Size | |
2088 | | Aspect_Variable_Indexing | |
2089 | | Aspect_Write | |
2090 | => | |
89f1e35c | 2091 | -- Indexing aspects apply only to tagged type |
2092 | ||
2093 | if (A_Id = Aspect_Constant_Indexing | |
37c6e44c | 2094 | or else |
2095 | A_Id = Aspect_Variable_Indexing) | |
89f1e35c | 2096 | and then not (Is_Type (E) |
2097 | and then Is_Tagged_Type (E)) | |
2098 | then | |
05987af3 | 2099 | Error_Msg_N |
2100 | ("indexing aspect can only apply to a tagged type", | |
3f4c9ffc | 2101 | Aspect); |
89f1e35c | 2102 | goto Continue; |
2103 | end if; | |
2104 | ||
39616053 | 2105 | -- For the case of aspect Address, we don't consider that we |
588e7f97 | 2106 | -- know the entity is never set in the source, since it is |
2107 | -- is likely aliasing is occurring. | |
2108 | ||
2109 | -- Note: one might think that the analysis of the resulting | |
2110 | -- attribute definition clause would take care of that, but | |
2111 | -- that's not the case since it won't be from source. | |
2112 | ||
2113 | if A_Id = Aspect_Address then | |
2114 | Set_Never_Set_In_Source (E, False); | |
2115 | end if; | |
2116 | ||
5ac76cee | 2117 | -- Correctness of the profile of a stream operation is |
2118 | -- verified at the freeze point, but we must detect the | |
2119 | -- illegal specification of this aspect for a subtype now, | |
2120 | -- to prevent malformed rep_item chains. | |
2121 | ||
fbf4d6ef | 2122 | if A_Id = Aspect_Input or else |
2123 | A_Id = Aspect_Output or else | |
2124 | A_Id = Aspect_Read or else | |
2125 | A_Id = Aspect_Write | |
5ac76cee | 2126 | then |
fbf4d6ef | 2127 | if not Is_First_Subtype (E) then |
2128 | Error_Msg_N | |
2129 | ("local name must be a first subtype", Aspect); | |
2130 | goto Continue; | |
2131 | ||
2132 | -- If stream aspect applies to the class-wide type, | |
2133 | -- the generated attribute definition applies to the | |
2134 | -- class-wide type as well. | |
2135 | ||
2136 | elsif Class_Present (Aspect) then | |
2137 | Ent := | |
2138 | Make_Attribute_Reference (Loc, | |
2139 | Prefix => Ent, | |
2140 | Attribute_Name => Name_Class); | |
2141 | end if; | |
5ac76cee | 2142 | end if; |
2143 | ||
d74fc39a | 2144 | -- Construct the attribute definition clause |
2145 | ||
2146 | Aitem := | |
94153a42 | 2147 | Make_Attribute_Definition_Clause (Loc, |
d74fc39a | 2148 | Name => Ent, |
ae888dbd | 2149 | Chars => Chars (Id), |
2150 | Expression => Relocate_Node (Expr)); | |
2151 | ||
af9a0cc3 | 2152 | -- If the address is specified, then we treat the entity as |
41f06abf | 2153 | -- referenced, to avoid spurious warnings. This is analogous |
2154 | -- to what is done with an attribute definition clause, but | |
2155 | -- here we don't want to generate a reference because this | |
2156 | -- is the point of definition of the entity. | |
2157 | ||
2158 | if A_Id = Aspect_Address then | |
2159 | Set_Referenced (E); | |
2160 | end if; | |
2161 | ||
51ea9c94 | 2162 | -- Case 2: Aspects corresponding to pragmas |
d74fc39a | 2163 | |
89f1e35c | 2164 | -- Case 2a: Aspects corresponding to pragmas with two |
2165 | -- arguments, where the first argument is a local name | |
2166 | -- referring to the entity, and the second argument is the | |
2167 | -- aspect definition expression. | |
ae888dbd | 2168 | |
04ae062f | 2169 | -- Linker_Section/Suppress/Unsuppress |
0fd13d32 | 2170 | |
99378362 | 2171 | when Aspect_Linker_Section |
2172 | | Aspect_Suppress | |
2173 | | Aspect_Unsuppress | |
2174 | => | |
0fd13d32 | 2175 | Make_Aitem_Pragma |
2176 | (Pragma_Argument_Associations => New_List ( | |
2177 | Make_Pragma_Argument_Association (Loc, | |
2178 | Expression => New_Occurrence_Of (E, Loc)), | |
2179 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2180 | Expression => Relocate_Node (Expr))), | |
2181 | Pragma_Name => Chars (Id)); | |
57cd943b | 2182 | |
0fd13d32 | 2183 | -- Synchronization |
d74fc39a | 2184 | |
0fd13d32 | 2185 | -- Corresponds to pragma Implemented, construct the pragma |
49213728 | 2186 | |
5bbfbad2 | 2187 | when Aspect_Synchronization => |
0fd13d32 | 2188 | Make_Aitem_Pragma |
2189 | (Pragma_Argument_Associations => New_List ( | |
2190 | Make_Pragma_Argument_Association (Loc, | |
2191 | Expression => New_Occurrence_Of (E, Loc)), | |
2192 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2193 | Expression => Relocate_Node (Expr))), | |
2194 | Pragma_Name => Name_Implemented); | |
49213728 | 2195 | |
e2bf777d | 2196 | -- Attach_Handler |
0fd13d32 | 2197 | |
89f1e35c | 2198 | when Aspect_Attach_Handler => |
0fd13d32 | 2199 | Make_Aitem_Pragma |
2200 | (Pragma_Argument_Associations => New_List ( | |
2201 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2202 | Expression => Ent), | |
2203 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2204 | Expression => Relocate_Node (Expr))), | |
2205 | Pragma_Name => Name_Attach_Handler); | |
2206 | ||
f67ed4f5 | 2207 | -- We need to insert this pragma into the tree to get proper |
2208 | -- processing and to look valid from a placement viewpoint. | |
2209 | ||
e2bf777d | 2210 | Insert_Pragma (Aitem); |
f67ed4f5 | 2211 | goto Continue; |
2212 | ||
0fd13d32 | 2213 | -- Dynamic_Predicate, Predicate, Static_Predicate |
89f1e35c | 2214 | |
99378362 | 2215 | when Aspect_Dynamic_Predicate |
2216 | | Aspect_Predicate | |
2217 | | Aspect_Static_Predicate | |
2218 | => | |
a47ce82d | 2219 | -- These aspects apply only to subtypes |
2220 | ||
2221 | if not Is_Type (E) then | |
2222 | Error_Msg_N | |
2223 | ("predicate can only be specified for a subtype", | |
2224 | Aspect); | |
2225 | goto Continue; | |
7c0c95b8 | 2226 | |
2227 | elsif Is_Incomplete_Type (E) then | |
2228 | Error_Msg_N | |
2229 | ("predicate cannot apply to incomplete view", Aspect); | |
2230 | goto Continue; | |
a47ce82d | 2231 | end if; |
2232 | ||
89f1e35c | 2233 | -- Construct the pragma (always a pragma Predicate, with |
51ea9c94 | 2234 | -- flags recording whether it is static/dynamic). We also |
2235 | -- set flags recording this in the type itself. | |
89f1e35c | 2236 | |
0fd13d32 | 2237 | Make_Aitem_Pragma |
2238 | (Pragma_Argument_Associations => New_List ( | |
2239 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2240 | Expression => Ent), | |
2241 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2242 | Expression => Relocate_Node (Expr))), | |
fdec445e | 2243 | Pragma_Name => Name_Predicate); |
89f1e35c | 2244 | |
51ea9c94 | 2245 | -- Mark type has predicates, and remember what kind of |
2246 | -- aspect lead to this predicate (we need this to access | |
2247 | -- the right set of check policies later on). | |
2248 | ||
2249 | Set_Has_Predicates (E); | |
2250 | ||
2251 | if A_Id = Aspect_Dynamic_Predicate then | |
2252 | Set_Has_Dynamic_Predicate_Aspect (E); | |
0ec8f3e0 | 2253 | |
2254 | -- If the entity has a dynamic predicate, any inherited | |
2255 | -- static predicate becomes dynamic as well, and the | |
2256 | -- predicate function includes the conjunction of both. | |
2257 | ||
2258 | Set_Has_Static_Predicate_Aspect (E, False); | |
2259 | ||
51ea9c94 | 2260 | elsif A_Id = Aspect_Static_Predicate then |
2261 | Set_Has_Static_Predicate_Aspect (E); | |
2262 | end if; | |
2263 | ||
89f1e35c | 2264 | -- If the type is private, indicate that its completion |
6653b695 | 2265 | -- has a freeze node, because that is the one that will |
2266 | -- be visible at freeze time. | |
89f1e35c | 2267 | |
0fd13d32 | 2268 | if Is_Private_Type (E) and then Present (Full_View (E)) then |
89f1e35c | 2269 | Set_Has_Predicates (Full_View (E)); |
51ea9c94 | 2270 | |
2271 | if A_Id = Aspect_Dynamic_Predicate then | |
2272 | Set_Has_Dynamic_Predicate_Aspect (Full_View (E)); | |
2273 | elsif A_Id = Aspect_Static_Predicate then | |
2274 | Set_Has_Static_Predicate_Aspect (Full_View (E)); | |
2275 | end if; | |
2276 | ||
89f1e35c | 2277 | Set_Has_Delayed_Aspects (Full_View (E)); |
2278 | Ensure_Freeze_Node (Full_View (E)); | |
2279 | end if; | |
2280 | ||
fdec445e | 2281 | -- Predicate_Failure |
2282 | ||
2283 | when Aspect_Predicate_Failure => | |
2284 | ||
2285 | -- This aspect applies only to subtypes | |
2286 | ||
2287 | if not Is_Type (E) then | |
2288 | Error_Msg_N | |
2289 | ("predicate can only be specified for a subtype", | |
2290 | Aspect); | |
2291 | goto Continue; | |
2292 | ||
2293 | elsif Is_Incomplete_Type (E) then | |
2294 | Error_Msg_N | |
2295 | ("predicate cannot apply to incomplete view", Aspect); | |
2296 | goto Continue; | |
2297 | end if; | |
2298 | ||
2299 | -- Construct the pragma | |
2300 | ||
2301 | Make_Aitem_Pragma | |
2302 | (Pragma_Argument_Associations => New_List ( | |
2303 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2304 | Expression => Ent), | |
2305 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2306 | Expression => Relocate_Node (Expr))), | |
2307 | Pragma_Name => Name_Predicate_Failure); | |
2308 | ||
2309 | Set_Has_Predicates (E); | |
2310 | ||
2311 | -- If the type is private, indicate that its completion | |
2312 | -- has a freeze node, because that is the one that will | |
2313 | -- be visible at freeze time. | |
2314 | ||
2315 | if Is_Private_Type (E) and then Present (Full_View (E)) then | |
2316 | Set_Has_Predicates (Full_View (E)); | |
2317 | Set_Has_Delayed_Aspects (Full_View (E)); | |
2318 | Ensure_Freeze_Node (Full_View (E)); | |
2319 | end if; | |
2320 | ||
89f1e35c | 2321 | -- Case 2b: Aspects corresponding to pragmas with two |
2322 | -- arguments, where the second argument is a local name | |
2323 | -- referring to the entity, and the first argument is the | |
2324 | -- aspect definition expression. | |
ae888dbd | 2325 | |
0fd13d32 | 2326 | -- Convention |
2327 | ||
ee2b7923 | 2328 | when Aspect_Convention => |
2329 | Analyze_Aspect_Convention; | |
2330 | goto Continue; | |
97bf66e6 | 2331 | |
ee2b7923 | 2332 | -- External_Name, Link_Name |
97bf66e6 | 2333 | |
99378362 | 2334 | when Aspect_External_Name |
2335 | | Aspect_Link_Name | |
2336 | => | |
ee2b7923 | 2337 | Analyze_Aspect_External_Link_Name; |
2338 | goto Continue; | |
e1cedbae | 2339 | |
0fd13d32 | 2340 | -- CPU, Interrupt_Priority, Priority |
2341 | ||
d6814978 | 2342 | -- These three aspects can be specified for a subprogram spec |
2343 | -- or body, in which case we analyze the expression and export | |
2344 | -- the value of the aspect. | |
2345 | ||
2346 | -- Previously, we generated an equivalent pragma for bodies | |
2347 | -- (note that the specs cannot contain these pragmas). The | |
2348 | -- pragma was inserted ahead of local declarations, rather than | |
2349 | -- after the body. This leads to a certain duplication between | |
2350 | -- the processing performed for the aspect and the pragma, but | |
2351 | -- given the straightforward handling required it is simpler | |
2352 | -- to duplicate than to translate the aspect in the spec into | |
2353 | -- a pragma in the declarative part of the body. | |
3a72f9c3 | 2354 | |
99378362 | 2355 | when Aspect_CPU |
2356 | | Aspect_Interrupt_Priority | |
2357 | | Aspect_Priority | |
2358 | => | |
d6814978 | 2359 | if Nkind_In (N, N_Subprogram_Body, |
2360 | N_Subprogram_Declaration) | |
2361 | then | |
2362 | -- Analyze the aspect expression | |
2363 | ||
2364 | Analyze_And_Resolve (Expr, Standard_Integer); | |
2365 | ||
2366 | -- Interrupt_Priority aspect not allowed for main | |
078a74b8 | 2367 | -- subprograms. RM D.1 does not forbid this explicitly, |
2368 | -- but RM J.15.11(6/3) does not permit pragma | |
d6814978 | 2369 | -- Interrupt_Priority for subprograms. |
2370 | ||
2371 | if A_Id = Aspect_Interrupt_Priority then | |
2372 | Error_Msg_N | |
2373 | ("Interrupt_Priority aspect cannot apply to " | |
2374 | & "subprogram", Expr); | |
2375 | ||
2376 | -- The expression must be static | |
2377 | ||
cda40848 | 2378 | elsif not Is_OK_Static_Expression (Expr) then |
d6814978 | 2379 | Flag_Non_Static_Expr |
2380 | ("aspect requires static expression!", Expr); | |
2381 | ||
24d7b9d6 | 2382 | -- Check whether this is the main subprogram. Issue a |
2383 | -- warning only if it is obviously not a main program | |
2384 | -- (when it has parameters or when the subprogram is | |
2385 | -- within a package). | |
2386 | ||
2387 | elsif Present (Parameter_Specifications | |
2388 | (Specification (N))) | |
2389 | or else not Is_Compilation_Unit (Defining_Entity (N)) | |
d6814978 | 2390 | then |
078a74b8 | 2391 | -- See RM D.1(14/3) and D.16(12/3) |
d6814978 | 2392 | |
2393 | Error_Msg_N | |
2394 | ("aspect applied to subprogram other than the " | |
2395 | & "main subprogram has no effect??", Expr); | |
2396 | ||
2397 | -- Otherwise check in range and export the value | |
2398 | ||
2399 | -- For the CPU aspect | |
2400 | ||
2401 | elsif A_Id = Aspect_CPU then | |
2402 | if Is_In_Range (Expr, RTE (RE_CPU_Range)) then | |
2403 | ||
2404 | -- Value is correct so we export the value to make | |
2405 | -- it available at execution time. | |
2406 | ||
2407 | Set_Main_CPU | |
2408 | (Main_Unit, UI_To_Int (Expr_Value (Expr))); | |
2409 | ||
2410 | else | |
2411 | Error_Msg_N | |
2412 | ("main subprogram CPU is out of range", Expr); | |
2413 | end if; | |
2414 | ||
2415 | -- For the Priority aspect | |
2416 | ||
2417 | elsif A_Id = Aspect_Priority then | |
2418 | if Is_In_Range (Expr, RTE (RE_Priority)) then | |
2419 | ||
2420 | -- Value is correct so we export the value to make | |
2421 | -- it available at execution time. | |
2422 | ||
2423 | Set_Main_Priority | |
2424 | (Main_Unit, UI_To_Int (Expr_Value (Expr))); | |
2425 | ||
32572384 | 2426 | -- Ignore pragma if Relaxed_RM_Semantics to support |
2427 | -- other targets/non GNAT compilers. | |
2428 | ||
2429 | elsif not Relaxed_RM_Semantics then | |
d6814978 | 2430 | Error_Msg_N |
2431 | ("main subprogram priority is out of range", | |
2432 | Expr); | |
2433 | end if; | |
2434 | end if; | |
2435 | ||
2436 | -- Load an arbitrary entity from System.Tasking.Stages | |
2437 | -- or System.Tasking.Restricted.Stages (depending on | |
2438 | -- the supported profile) to make sure that one of these | |
2439 | -- packages is implicitly with'ed, since we need to have | |
2440 | -- the tasking run time active for the pragma Priority to | |
a0c3eeb9 | 2441 | -- have any effect. Previously we with'ed the package |
d6814978 | 2442 | -- System.Tasking, but this package does not trigger the |
2443 | -- required initialization of the run-time library. | |
2444 | ||
2445 | declare | |
2446 | Discard : Entity_Id; | |
d6814978 | 2447 | begin |
2448 | if Restricted_Profile then | |
2449 | Discard := RTE (RE_Activate_Restricted_Tasks); | |
2450 | else | |
2451 | Discard := RTE (RE_Activate_Tasks); | |
2452 | end if; | |
2453 | end; | |
2454 | ||
e6ce0468 | 2455 | -- Handling for these aspects in subprograms is complete |
d6814978 | 2456 | |
2457 | goto Continue; | |
2458 | ||
2f06c88a | 2459 | -- For tasks pass the aspect as an attribute |
0fd13d32 | 2460 | |
3a72f9c3 | 2461 | else |
2462 | Aitem := | |
2463 | Make_Attribute_Definition_Clause (Loc, | |
2464 | Name => Ent, | |
2465 | Chars => Chars (Id), | |
2466 | Expression => Relocate_Node (Expr)); | |
2467 | end if; | |
2468 | ||
0fd13d32 | 2469 | -- Warnings |
2470 | ||
ae888dbd | 2471 | when Aspect_Warnings => |
0fd13d32 | 2472 | Make_Aitem_Pragma |
2473 | (Pragma_Argument_Associations => New_List ( | |
2474 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2475 | Expression => Relocate_Node (Expr)), | |
2476 | Make_Pragma_Argument_Association (Loc, | |
2477 | Expression => New_Occurrence_Of (E, Loc))), | |
2478 | Pragma_Name => Chars (Id)); | |
ae888dbd | 2479 | |
2f06c88a | 2480 | Decorate (Aspect, Aitem); |
2481 | Insert_Pragma (Aitem); | |
2482 | goto Continue; | |
2483 | ||
89f1e35c | 2484 | -- Case 2c: Aspects corresponding to pragmas with three |
2485 | -- arguments. | |
d64221a7 | 2486 | |
89f1e35c | 2487 | -- Invariant aspects have a first argument that references the |
2488 | -- entity, a second argument that is the expression and a third | |
2489 | -- argument that is an appropriate message. | |
d64221a7 | 2490 | |
0fd13d32 | 2491 | -- Invariant, Type_Invariant |
2492 | ||
99378362 | 2493 | when Aspect_Invariant |
2494 | | Aspect_Type_Invariant | |
2495 | => | |
89f1e35c | 2496 | -- Analysis of the pragma will verify placement legality: |
2497 | -- an invariant must apply to a private type, or appear in | |
2498 | -- the private part of a spec and apply to a completion. | |
d64221a7 | 2499 | |
0fd13d32 | 2500 | Make_Aitem_Pragma |
2501 | (Pragma_Argument_Associations => New_List ( | |
2502 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2503 | Expression => Ent), | |
2504 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2505 | Expression => Relocate_Node (Expr))), | |
2506 | Pragma_Name => Name_Invariant); | |
89f1e35c | 2507 | |
2508 | -- Add message unless exception messages are suppressed | |
2509 | ||
2510 | if not Opt.Exception_Locations_Suppressed then | |
2511 | Append_To (Pragma_Argument_Associations (Aitem), | |
2512 | Make_Pragma_Argument_Association (Eloc, | |
2513 | Chars => Name_Message, | |
2514 | Expression => | |
2515 | Make_String_Literal (Eloc, | |
2516 | Strval => "failed invariant from " | |
2517 | & Build_Location_String (Eloc)))); | |
d64221a7 | 2518 | end if; |
2519 | ||
89f1e35c | 2520 | -- For Invariant case, insert immediately after the entity |
2521 | -- declaration. We do not have to worry about delay issues | |
2522 | -- since the pragma processing takes care of this. | |
2523 | ||
89f1e35c | 2524 | Delay_Required := False; |
d64221a7 | 2525 | |
47a46747 | 2526 | -- Case 2d : Aspects that correspond to a pragma with one |
2527 | -- argument. | |
2528 | ||
0fd13d32 | 2529 | -- Abstract_State |
115f7b08 | 2530 | |
d4e369ad | 2531 | -- Aspect Abstract_State introduces implicit declarations for |
2532 | -- all state abstraction entities it defines. To emulate this | |
2533 | -- behavior, insert the pragma at the beginning of the visible | |
2534 | -- declarations of the related package so that it is analyzed | |
2535 | -- immediately. | |
2536 | ||
9129c28f | 2537 | when Aspect_Abstract_State => Abstract_State : declare |
eb4f7efa | 2538 | Context : Node_Id := N; |
9129c28f | 2539 | |
2540 | begin | |
eb4f7efa | 2541 | -- When aspect Abstract_State appears on a generic package, |
2542 | -- it is propageted to the package instance. The context in | |
2543 | -- this case is the instance spec. | |
2544 | ||
2545 | if Nkind (Context) = N_Package_Instantiation then | |
2546 | Context := Instance_Spec (Context); | |
2547 | end if; | |
2548 | ||
2549 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2550 | N_Package_Declaration) | |
9129c28f | 2551 | then |
9129c28f | 2552 | Make_Aitem_Pragma |
2553 | (Pragma_Argument_Associations => New_List ( | |
2554 | Make_Pragma_Argument_Association (Loc, | |
2555 | Expression => Relocate_Node (Expr))), | |
2556 | Pragma_Name => Name_Abstract_State); | |
630b6d55 | 2557 | |
5655be8a | 2558 | Decorate (Aspect, Aitem); |
2559 | Insert_Pragma | |
2560 | (Prag => Aitem, | |
2561 | Is_Instance => | |
2562 | Is_Generic_Instance (Defining_Entity (Context))); | |
9129c28f | 2563 | |
2564 | else | |
2565 | Error_Msg_NE | |
2566 | ("aspect & must apply to a package declaration", | |
2567 | Aspect, Id); | |
2568 | end if; | |
2569 | ||
2570 | goto Continue; | |
2571 | end Abstract_State; | |
115f7b08 | 2572 | |
85ee12c0 | 2573 | -- Aspect Async_Readers is never delayed because it is |
2574 | -- equivalent to a source pragma which appears after the | |
2575 | -- related object declaration. | |
2576 | ||
2577 | when Aspect_Async_Readers => | |
2578 | Make_Aitem_Pragma | |
2579 | (Pragma_Argument_Associations => New_List ( | |
2580 | Make_Pragma_Argument_Association (Loc, | |
2581 | Expression => Relocate_Node (Expr))), | |
2582 | Pragma_Name => Name_Async_Readers); | |
2583 | ||
2584 | Decorate (Aspect, Aitem); | |
2585 | Insert_Pragma (Aitem); | |
2586 | goto Continue; | |
2587 | ||
2588 | -- Aspect Async_Writers is never delayed because it is | |
2589 | -- equivalent to a source pragma which appears after the | |
2590 | -- related object declaration. | |
2591 | ||
2592 | when Aspect_Async_Writers => | |
2593 | Make_Aitem_Pragma | |
2594 | (Pragma_Argument_Associations => New_List ( | |
2595 | Make_Pragma_Argument_Association (Loc, | |
2596 | Expression => Relocate_Node (Expr))), | |
2597 | Pragma_Name => Name_Async_Writers); | |
2598 | ||
2599 | Decorate (Aspect, Aitem); | |
2600 | Insert_Pragma (Aitem); | |
2601 | goto Continue; | |
2602 | ||
d0849c23 | 2603 | -- Aspect Constant_After_Elaboration is never delayed because |
2604 | -- it is equivalent to a source pragma which appears after the | |
2605 | -- related object declaration. | |
2606 | ||
2607 | when Aspect_Constant_After_Elaboration => | |
2608 | Make_Aitem_Pragma | |
2609 | (Pragma_Argument_Associations => New_List ( | |
2610 | Make_Pragma_Argument_Association (Loc, | |
2611 | Expression => Relocate_Node (Expr))), | |
2612 | Pragma_Name => | |
2613 | Name_Constant_After_Elaboration); | |
2614 | ||
2615 | Decorate (Aspect, Aitem); | |
2616 | Insert_Pragma (Aitem); | |
2617 | goto Continue; | |
2618 | ||
ec6f6da5 | 2619 | -- Aspect Default_Internal_Condition is never delayed because |
2620 | -- it is equivalent to a source pragma which appears after the | |
2621 | -- related private type. To deal with forward references, the | |
2622 | -- generated pragma is stored in the rep chain of the related | |
2623 | -- private type as types do not carry contracts. The pragma is | |
2624 | -- wrapped inside of a procedure at the freeze point of the | |
2625 | -- private type's full view. | |
2626 | ||
2627 | when Aspect_Default_Initial_Condition => | |
2628 | Make_Aitem_Pragma | |
2629 | (Pragma_Argument_Associations => New_List ( | |
2630 | Make_Pragma_Argument_Association (Loc, | |
2631 | Expression => Relocate_Node (Expr))), | |
2632 | Pragma_Name => | |
2633 | Name_Default_Initial_Condition); | |
2634 | ||
2635 | Decorate (Aspect, Aitem); | |
2636 | Insert_Pragma (Aitem); | |
2637 | goto Continue; | |
2638 | ||
647fab54 | 2639 | -- Default_Storage_Pool |
2640 | ||
2641 | when Aspect_Default_Storage_Pool => | |
2642 | Make_Aitem_Pragma | |
2643 | (Pragma_Argument_Associations => New_List ( | |
2644 | Make_Pragma_Argument_Association (Loc, | |
2645 | Expression => Relocate_Node (Expr))), | |
2646 | Pragma_Name => | |
2647 | Name_Default_Storage_Pool); | |
2648 | ||
2649 | Decorate (Aspect, Aitem); | |
2650 | Insert_Pragma (Aitem); | |
2651 | goto Continue; | |
2652 | ||
0fd13d32 | 2653 | -- Depends |
2654 | ||
e2bf777d | 2655 | -- Aspect Depends is never delayed because it is equivalent to |
2656 | -- a source pragma which appears after the related subprogram. | |
2657 | -- To deal with forward references, the generated pragma is | |
2658 | -- stored in the contract of the related subprogram and later | |
2659 | -- analyzed at the end of the declarative region. See routine | |
2660 | -- Analyze_Depends_In_Decl_Part for details. | |
6144c105 | 2661 | |
12334c57 | 2662 | when Aspect_Depends => |
0fd13d32 | 2663 | Make_Aitem_Pragma |
2664 | (Pragma_Argument_Associations => New_List ( | |
2665 | Make_Pragma_Argument_Association (Loc, | |
2666 | Expression => Relocate_Node (Expr))), | |
2667 | Pragma_Name => Name_Depends); | |
2668 | ||
e2bf777d | 2669 | Decorate (Aspect, Aitem); |
2670 | Insert_Pragma (Aitem); | |
c1006d6d | 2671 | goto Continue; |
2672 | ||
85ee12c0 | 2673 | -- Aspect Effecitve_Reads is never delayed because it is |
2674 | -- equivalent to a source pragma which appears after the | |
2675 | -- related object declaration. | |
2676 | ||
2677 | when Aspect_Effective_Reads => | |
2678 | Make_Aitem_Pragma | |
2679 | (Pragma_Argument_Associations => New_List ( | |
2680 | Make_Pragma_Argument_Association (Loc, | |
2681 | Expression => Relocate_Node (Expr))), | |
2682 | Pragma_Name => Name_Effective_Reads); | |
2683 | ||
2684 | Decorate (Aspect, Aitem); | |
2685 | Insert_Pragma (Aitem); | |
2686 | goto Continue; | |
2687 | ||
2688 | -- Aspect Effective_Writes is never delayed because it is | |
2689 | -- equivalent to a source pragma which appears after the | |
2690 | -- related object declaration. | |
2691 | ||
2692 | when Aspect_Effective_Writes => | |
2693 | Make_Aitem_Pragma | |
2694 | (Pragma_Argument_Associations => New_List ( | |
2695 | Make_Pragma_Argument_Association (Loc, | |
2696 | Expression => Relocate_Node (Expr))), | |
2697 | Pragma_Name => Name_Effective_Writes); | |
2698 | ||
2699 | Decorate (Aspect, Aitem); | |
2700 | Insert_Pragma (Aitem); | |
2701 | goto Continue; | |
2702 | ||
cab27d2a | 2703 | -- Aspect Extensions_Visible is never delayed because it is |
2704 | -- equivalent to a source pragma which appears after the | |
2705 | -- related subprogram. | |
2706 | ||
2707 | when Aspect_Extensions_Visible => | |
2708 | Make_Aitem_Pragma | |
2709 | (Pragma_Argument_Associations => New_List ( | |
2710 | Make_Pragma_Argument_Association (Loc, | |
2711 | Expression => Relocate_Node (Expr))), | |
2712 | Pragma_Name => Name_Extensions_Visible); | |
2713 | ||
2714 | Decorate (Aspect, Aitem); | |
2715 | Insert_Pragma (Aitem); | |
2716 | goto Continue; | |
2717 | ||
3dbe7a69 | 2718 | -- Aspect Ghost is never delayed because it is equivalent to a |
2719 | -- source pragma which appears at the top of [generic] package | |
2720 | -- declarations or after an object, a [generic] subprogram, or | |
2721 | -- a type declaration. | |
2722 | ||
5655be8a | 2723 | when Aspect_Ghost => |
3dbe7a69 | 2724 | Make_Aitem_Pragma |
2725 | (Pragma_Argument_Associations => New_List ( | |
2726 | Make_Pragma_Argument_Association (Loc, | |
2727 | Expression => Relocate_Node (Expr))), | |
2728 | Pragma_Name => Name_Ghost); | |
2729 | ||
2730 | Decorate (Aspect, Aitem); | |
5655be8a | 2731 | Insert_Pragma (Aitem); |
3dbe7a69 | 2732 | goto Continue; |
3dbe7a69 | 2733 | |
0fd13d32 | 2734 | -- Global |
12334c57 | 2735 | |
e2bf777d | 2736 | -- Aspect Global is never delayed because it is equivalent to |
2737 | -- a source pragma which appears after the related subprogram. | |
2738 | -- To deal with forward references, the generated pragma is | |
2739 | -- stored in the contract of the related subprogram and later | |
2740 | -- analyzed at the end of the declarative region. See routine | |
2741 | -- Analyze_Global_In_Decl_Part for details. | |
3cdbaa5a | 2742 | |
2743 | when Aspect_Global => | |
0fd13d32 | 2744 | Make_Aitem_Pragma |
2745 | (Pragma_Argument_Associations => New_List ( | |
2746 | Make_Pragma_Argument_Association (Loc, | |
2747 | Expression => Relocate_Node (Expr))), | |
2748 | Pragma_Name => Name_Global); | |
2749 | ||
e2bf777d | 2750 | Decorate (Aspect, Aitem); |
2751 | Insert_Pragma (Aitem); | |
c1006d6d | 2752 | goto Continue; |
2753 | ||
9c138530 | 2754 | -- Initial_Condition |
2755 | ||
e2bf777d | 2756 | -- Aspect Initial_Condition is never delayed because it is |
2757 | -- equivalent to a source pragma which appears after the | |
2758 | -- related package. To deal with forward references, the | |
2759 | -- generated pragma is stored in the contract of the related | |
2760 | -- package and later analyzed at the end of the declarative | |
2761 | -- region. See routine Analyze_Initial_Condition_In_Decl_Part | |
2762 | -- for details. | |
9c138530 | 2763 | |
2764 | when Aspect_Initial_Condition => Initial_Condition : declare | |
eb4f7efa | 2765 | Context : Node_Id := N; |
9c138530 | 2766 | |
2767 | begin | |
e2bf777d | 2768 | -- When aspect Initial_Condition appears on a generic |
2769 | -- package, it is propageted to the package instance. The | |
2770 | -- context in this case is the instance spec. | |
eb4f7efa | 2771 | |
2772 | if Nkind (Context) = N_Package_Instantiation then | |
2773 | Context := Instance_Spec (Context); | |
2774 | end if; | |
2775 | ||
2776 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2777 | N_Package_Declaration) | |
9c138530 | 2778 | then |
9c138530 | 2779 | Make_Aitem_Pragma |
2780 | (Pragma_Argument_Associations => New_List ( | |
2781 | Make_Pragma_Argument_Association (Loc, | |
2782 | Expression => Relocate_Node (Expr))), | |
2783 | Pragma_Name => | |
2784 | Name_Initial_Condition); | |
9c138530 | 2785 | |
5655be8a | 2786 | Decorate (Aspect, Aitem); |
2787 | Insert_Pragma | |
2788 | (Prag => Aitem, | |
2789 | Is_Instance => | |
2790 | Is_Generic_Instance (Defining_Entity (Context))); | |
50e44732 | 2791 | |
5655be8a | 2792 | -- Otherwise the context is illegal |
9c138530 | 2793 | |
2794 | else | |
2795 | Error_Msg_NE | |
2796 | ("aspect & must apply to a package declaration", | |
2797 | Aspect, Id); | |
2798 | end if; | |
2799 | ||
2800 | goto Continue; | |
2801 | end Initial_Condition; | |
2802 | ||
d4e369ad | 2803 | -- Initializes |
2804 | ||
e2bf777d | 2805 | -- Aspect Initializes is never delayed because it is equivalent |
2806 | -- to a source pragma appearing after the related package. To | |
2807 | -- deal with forward references, the generated pragma is stored | |
2808 | -- in the contract of the related package and later analyzed at | |
2809 | -- the end of the declarative region. For details, see routine | |
2810 | -- Analyze_Initializes_In_Decl_Part. | |
d4e369ad | 2811 | |
2812 | when Aspect_Initializes => Initializes : declare | |
eb4f7efa | 2813 | Context : Node_Id := N; |
d4e369ad | 2814 | |
2815 | begin | |
50e44732 | 2816 | -- When aspect Initializes appears on a generic package, |
2817 | -- it is propageted to the package instance. The context | |
2818 | -- in this case is the instance spec. | |
eb4f7efa | 2819 | |
2820 | if Nkind (Context) = N_Package_Instantiation then | |
2821 | Context := Instance_Spec (Context); | |
2822 | end if; | |
2823 | ||
2824 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2825 | N_Package_Declaration) | |
d4e369ad | 2826 | then |
d4e369ad | 2827 | Make_Aitem_Pragma |
2828 | (Pragma_Argument_Associations => New_List ( | |
2829 | Make_Pragma_Argument_Association (Loc, | |
2830 | Expression => Relocate_Node (Expr))), | |
2831 | Pragma_Name => Name_Initializes); | |
d4e369ad | 2832 | |
5655be8a | 2833 | Decorate (Aspect, Aitem); |
2834 | Insert_Pragma | |
2835 | (Prag => Aitem, | |
2836 | Is_Instance => | |
2837 | Is_Generic_Instance (Defining_Entity (Context))); | |
50e44732 | 2838 | |
5655be8a | 2839 | -- Otherwise the context is illegal |
d4e369ad | 2840 | |
2841 | else | |
2842 | Error_Msg_NE | |
2843 | ("aspect & must apply to a package declaration", | |
2844 | Aspect, Id); | |
2845 | end if; | |
2846 | ||
2847 | goto Continue; | |
2848 | end Initializes; | |
2849 | ||
cbd45084 | 2850 | -- Max_Queue_Length |
2851 | ||
2852 | when Aspect_Max_Queue_Length => | |
2853 | Make_Aitem_Pragma | |
2854 | (Pragma_Argument_Associations => New_List ( | |
2855 | Make_Pragma_Argument_Association (Loc, | |
2856 | Expression => Relocate_Node (Expr))), | |
2857 | Pragma_Name => Name_Max_Queue_Length); | |
2858 | ||
2859 | Decorate (Aspect, Aitem); | |
2860 | Insert_Pragma (Aitem); | |
2861 | goto Continue; | |
2862 | ||
1fd4313f | 2863 | -- Obsolescent |
2864 | ||
2865 | when Aspect_Obsolescent => declare | |
2866 | Args : List_Id; | |
2867 | ||
2868 | begin | |
2869 | if No (Expr) then | |
2870 | Args := No_List; | |
2871 | else | |
2872 | Args := New_List ( | |
2873 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2874 | Expression => Relocate_Node (Expr))); | |
2875 | end if; | |
2876 | ||
2877 | Make_Aitem_Pragma | |
2878 | (Pragma_Argument_Associations => Args, | |
2879 | Pragma_Name => Chars (Id)); | |
2880 | end; | |
2881 | ||
5cc6f0cf | 2882 | -- Part_Of |
2883 | ||
2884 | when Aspect_Part_Of => | |
2885 | if Nkind_In (N, N_Object_Declaration, | |
2886 | N_Package_Instantiation) | |
736b80cc | 2887 | or else Is_Single_Concurrent_Type_Declaration (N) |
5cc6f0cf | 2888 | then |
2889 | Make_Aitem_Pragma | |
2890 | (Pragma_Argument_Associations => New_List ( | |
2891 | Make_Pragma_Argument_Association (Loc, | |
2892 | Expression => Relocate_Node (Expr))), | |
2893 | Pragma_Name => Name_Part_Of); | |
2894 | ||
736b80cc | 2895 | Decorate (Aspect, Aitem); |
2896 | Insert_Pragma (Aitem); | |
736b80cc | 2897 | |
5cc6f0cf | 2898 | else |
2899 | Error_Msg_NE | |
736b80cc | 2900 | ("aspect & must apply to package instantiation, " |
2901 | & "object, single protected type or single task type", | |
2902 | Aspect, Id); | |
5cc6f0cf | 2903 | end if; |
2904 | ||
d5c65b80 | 2905 | goto Continue; |
2906 | ||
5dd93a61 | 2907 | -- SPARK_Mode |
2908 | ||
2f06c88a | 2909 | when Aspect_SPARK_Mode => |
5dd93a61 | 2910 | Make_Aitem_Pragma |
2911 | (Pragma_Argument_Associations => New_List ( | |
2912 | Make_Pragma_Argument_Association (Loc, | |
2913 | Expression => Relocate_Node (Expr))), | |
2914 | Pragma_Name => Name_SPARK_Mode); | |
5dd93a61 | 2915 | |
2f06c88a | 2916 | Decorate (Aspect, Aitem); |
2917 | Insert_Pragma (Aitem); | |
2918 | goto Continue; | |
778ebf56 | 2919 | |
4befb1a0 | 2920 | -- Refined_Depends |
2921 | ||
e2bf777d | 2922 | -- Aspect Refined_Depends is never delayed because it is |
2923 | -- equivalent to a source pragma which appears in the | |
2924 | -- declarations of the related subprogram body. To deal with | |
2925 | -- forward references, the generated pragma is stored in the | |
2926 | -- contract of the related subprogram body and later analyzed | |
2927 | -- at the end of the declarative region. For details, see | |
2928 | -- routine Analyze_Refined_Depends_In_Decl_Part. | |
4befb1a0 | 2929 | |
2930 | when Aspect_Refined_Depends => | |
422073ed | 2931 | Make_Aitem_Pragma |
2932 | (Pragma_Argument_Associations => New_List ( | |
2933 | Make_Pragma_Argument_Association (Loc, | |
2934 | Expression => Relocate_Node (Expr))), | |
2935 | Pragma_Name => Name_Refined_Depends); | |
2936 | ||
e2bf777d | 2937 | Decorate (Aspect, Aitem); |
2938 | Insert_Pragma (Aitem); | |
422073ed | 2939 | goto Continue; |
4befb1a0 | 2940 | |
2941 | -- Refined_Global | |
2942 | ||
e2bf777d | 2943 | -- Aspect Refined_Global is never delayed because it is |
2944 | -- equivalent to a source pragma which appears in the | |
2945 | -- declarations of the related subprogram body. To deal with | |
2946 | -- forward references, the generated pragma is stored in the | |
2947 | -- contract of the related subprogram body and later analyzed | |
2948 | -- at the end of the declarative region. For details, see | |
2949 | -- routine Analyze_Refined_Global_In_Decl_Part. | |
4befb1a0 | 2950 | |
2951 | when Aspect_Refined_Global => | |
28ff117f | 2952 | Make_Aitem_Pragma |
2953 | (Pragma_Argument_Associations => New_List ( | |
2954 | Make_Pragma_Argument_Association (Loc, | |
2955 | Expression => Relocate_Node (Expr))), | |
2956 | Pragma_Name => Name_Refined_Global); | |
2957 | ||
e2bf777d | 2958 | Decorate (Aspect, Aitem); |
2959 | Insert_Pragma (Aitem); | |
28ff117f | 2960 | goto Continue; |
4befb1a0 | 2961 | |
63b65b2d | 2962 | -- Refined_Post |
2963 | ||
2964 | when Aspect_Refined_Post => | |
2965 | Make_Aitem_Pragma | |
2966 | (Pragma_Argument_Associations => New_List ( | |
2967 | Make_Pragma_Argument_Association (Loc, | |
2968 | Expression => Relocate_Node (Expr))), | |
2969 | Pragma_Name => Name_Refined_Post); | |
2970 | ||
3ff5e35d | 2971 | Decorate (Aspect, Aitem); |
2972 | Insert_Pragma (Aitem); | |
2973 | goto Continue; | |
2974 | ||
9129c28f | 2975 | -- Refined_State |
2976 | ||
5655be8a | 2977 | when Aspect_Refined_State => |
9129c28f | 2978 | |
9129c28f | 2979 | -- The corresponding pragma for Refined_State is inserted in |
2980 | -- the declarations of the related package body. This action | |
2981 | -- synchronizes both the source and from-aspect versions of | |
2982 | -- the pragma. | |
2983 | ||
2984 | if Nkind (N) = N_Package_Body then | |
9129c28f | 2985 | Make_Aitem_Pragma |
2986 | (Pragma_Argument_Associations => New_List ( | |
2987 | Make_Pragma_Argument_Association (Loc, | |
2988 | Expression => Relocate_Node (Expr))), | |
2989 | Pragma_Name => Name_Refined_State); | |
b9b2d6e5 | 2990 | |
5655be8a | 2991 | Decorate (Aspect, Aitem); |
2992 | Insert_Pragma (Aitem); | |
b9b2d6e5 | 2993 | |
5655be8a | 2994 | -- Otherwise the context is illegal |
9129c28f | 2995 | |
2996 | else | |
2997 | Error_Msg_NE | |
2998 | ("aspect & must apply to a package body", Aspect, Id); | |
2999 | end if; | |
3000 | ||
3001 | goto Continue; | |
9129c28f | 3002 | |
0fd13d32 | 3003 | -- Relative_Deadline |
3cdbaa5a | 3004 | |
3005 | when Aspect_Relative_Deadline => | |
0fd13d32 | 3006 | Make_Aitem_Pragma |
3007 | (Pragma_Argument_Associations => New_List ( | |
3008 | Make_Pragma_Argument_Association (Loc, | |
3009 | Expression => Relocate_Node (Expr))), | |
3010 | Pragma_Name => Name_Relative_Deadline); | |
47a46747 | 3011 | |
3012 | -- If the aspect applies to a task, the corresponding pragma | |
3013 | -- must appear within its declarations, not after. | |
3014 | ||
3015 | if Nkind (N) = N_Task_Type_Declaration then | |
3016 | declare | |
3017 | Def : Node_Id; | |
3018 | V : List_Id; | |
3019 | ||
3020 | begin | |
3021 | if No (Task_Definition (N)) then | |
3022 | Set_Task_Definition (N, | |
3023 | Make_Task_Definition (Loc, | |
3024 | Visible_Declarations => New_List, | |
3025 | End_Label => Empty)); | |
3026 | end if; | |
3027 | ||
3028 | Def := Task_Definition (N); | |
3029 | V := Visible_Declarations (Def); | |
3030 | if not Is_Empty_List (V) then | |
3031 | Insert_Before (First (V), Aitem); | |
3032 | ||
3033 | else | |
3034 | Set_Visible_Declarations (Def, New_List (Aitem)); | |
3035 | end if; | |
3036 | ||
3037 | goto Continue; | |
3038 | end; | |
3039 | end if; | |
3040 | ||
85ee12c0 | 3041 | -- Aspect Volatile_Function is never delayed because it is |
3042 | -- equivalent to a source pragma which appears after the | |
3043 | -- related subprogram. | |
3044 | ||
3045 | when Aspect_Volatile_Function => | |
3046 | Make_Aitem_Pragma | |
3047 | (Pragma_Argument_Associations => New_List ( | |
3048 | Make_Pragma_Argument_Association (Loc, | |
3049 | Expression => Relocate_Node (Expr))), | |
3050 | Pragma_Name => Name_Volatile_Function); | |
3051 | ||
3052 | Decorate (Aspect, Aitem); | |
3053 | Insert_Pragma (Aitem); | |
3054 | goto Continue; | |
3055 | ||
956ffaf4 | 3056 | -- Case 2e: Annotate aspect |
3057 | ||
3058 | when Aspect_Annotate => | |
3059 | declare | |
3060 | Args : List_Id; | |
3061 | Pargs : List_Id; | |
3062 | Arg : Node_Id; | |
3063 | ||
3064 | begin | |
3065 | -- The argument can be a single identifier | |
3066 | ||
3067 | if Nkind (Expr) = N_Identifier then | |
3068 | ||
3069 | -- One level of parens is allowed | |
3070 | ||
3071 | if Paren_Count (Expr) > 1 then | |
3072 | Error_Msg_F ("extra parentheses ignored", Expr); | |
3073 | end if; | |
3074 | ||
3075 | Set_Paren_Count (Expr, 0); | |
3076 | ||
3077 | -- Add the single item to the list | |
3078 | ||
3079 | Args := New_List (Expr); | |
3080 | ||
3081 | -- Otherwise we must have an aggregate | |
3082 | ||
3083 | elsif Nkind (Expr) = N_Aggregate then | |
3084 | ||
3085 | -- Must be positional | |
3086 | ||
3087 | if Present (Component_Associations (Expr)) then | |
3088 | Error_Msg_F | |
3089 | ("purely positional aggregate required", Expr); | |
3090 | goto Continue; | |
3091 | end if; | |
3092 | ||
3093 | -- Must not be parenthesized | |
3094 | ||
3095 | if Paren_Count (Expr) /= 0 then | |
3096 | Error_Msg_F ("extra parentheses ignored", Expr); | |
3097 | end if; | |
3098 | ||
3099 | -- List of arguments is list of aggregate expressions | |
3100 | ||
3101 | Args := Expressions (Expr); | |
3102 | ||
3103 | -- Anything else is illegal | |
3104 | ||
3105 | else | |
3106 | Error_Msg_F ("wrong form for Annotate aspect", Expr); | |
3107 | goto Continue; | |
3108 | end if; | |
3109 | ||
3110 | -- Prepare pragma arguments | |
3111 | ||
3112 | Pargs := New_List; | |
3113 | Arg := First (Args); | |
3114 | while Present (Arg) loop | |
3115 | Append_To (Pargs, | |
3116 | Make_Pragma_Argument_Association (Sloc (Arg), | |
3117 | Expression => Relocate_Node (Arg))); | |
3118 | Next (Arg); | |
3119 | end loop; | |
3120 | ||
3121 | Append_To (Pargs, | |
3122 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3123 | Chars => Name_Entity, | |
3124 | Expression => Ent)); | |
3125 | ||
3126 | Make_Aitem_Pragma | |
3127 | (Pragma_Argument_Associations => Pargs, | |
3128 | Pragma_Name => Name_Annotate); | |
3129 | end; | |
3130 | ||
89f1e35c | 3131 | -- Case 3 : Aspects that don't correspond to pragma/attribute |
3132 | -- definition clause. | |
7b9b2f05 | 3133 | |
89f1e35c | 3134 | -- Case 3a: The aspects listed below don't correspond to |
3135 | -- pragmas/attributes but do require delayed analysis. | |
7f694ca2 | 3136 | |
51fa2a45 | 3137 | -- Default_Value can only apply to a scalar type |
3138 | ||
3139 | when Aspect_Default_Value => | |
3140 | if not Is_Scalar_Type (E) then | |
3141 | Error_Msg_N | |
1089ff19 | 3142 | ("aspect Default_Value must apply to a scalar type", N); |
51fa2a45 | 3143 | end if; |
3144 | ||
3145 | Aitem := Empty; | |
3146 | ||
3147 | -- Default_Component_Value can only apply to an array type | |
3148 | -- with scalar components. | |
3149 | ||
3150 | when Aspect_Default_Component_Value => | |
3151 | if not (Is_Array_Type (E) | |
3f4c9ffc | 3152 | and then Is_Scalar_Type (Component_Type (E))) |
51fa2a45 | 3153 | then |
ee2b7923 | 3154 | Error_Msg_N |
3155 | ("aspect Default_Component_Value can only apply to an " | |
3156 | & "array of scalar components", N); | |
51fa2a45 | 3157 | end if; |
0fd13d32 | 3158 | |
89f1e35c | 3159 | Aitem := Empty; |
7f694ca2 | 3160 | |
89f1e35c | 3161 | -- Case 3b: The aspects listed below don't correspond to |
3162 | -- pragmas/attributes and don't need delayed analysis. | |
95bc75fa | 3163 | |
0fd13d32 | 3164 | -- Implicit_Dereference |
3165 | ||
89f1e35c | 3166 | -- For Implicit_Dereference, External_Name and Link_Name, only |
3167 | -- the legality checks are done during the analysis, thus no | |
3168 | -- delay is required. | |
a8e38e1d | 3169 | |
89f1e35c | 3170 | when Aspect_Implicit_Dereference => |
3171 | Analyze_Aspect_Implicit_Dereference; | |
3172 | goto Continue; | |
7f694ca2 | 3173 | |
0fd13d32 | 3174 | -- Dimension |
3175 | ||
89f1e35c | 3176 | when Aspect_Dimension => |
3177 | Analyze_Aspect_Dimension (N, Id, Expr); | |
3178 | goto Continue; | |
cb4c311d | 3179 | |
0fd13d32 | 3180 | -- Dimension_System |
3181 | ||
89f1e35c | 3182 | when Aspect_Dimension_System => |
3183 | Analyze_Aspect_Dimension_System (N, Id, Expr); | |
3184 | goto Continue; | |
7f694ca2 | 3185 | |
ceec4f7c | 3186 | -- Case 4: Aspects requiring special handling |
51ea9c94 | 3187 | |
e66f4e2a | 3188 | -- Pre/Post/Test_Case/Contract_Cases whose corresponding |
3189 | -- pragmas take care of the delay. | |
7f694ca2 | 3190 | |
0fd13d32 | 3191 | -- Pre/Post |
3192 | ||
1e3c4ae6 | 3193 | -- Aspects Pre/Post generate Precondition/Postcondition pragmas |
3194 | -- with a first argument that is the expression, and a second | |
3195 | -- argument that is an informative message if the test fails. | |
3196 | -- This is inserted right after the declaration, to get the | |
5b5df4a9 | 3197 | -- required pragma placement. The processing for the pragmas |
3198 | -- takes care of the required delay. | |
ae888dbd | 3199 | |
5ddd846b | 3200 | when Pre_Post_Aspects => Pre_Post : declare |
1e3c4ae6 | 3201 | Pname : Name_Id; |
ae888dbd | 3202 | |
1e3c4ae6 | 3203 | begin |
77ae6789 | 3204 | if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then |
1e3c4ae6 | 3205 | Pname := Name_Precondition; |
3206 | else | |
3207 | Pname := Name_Postcondition; | |
3208 | end if; | |
d74fc39a | 3209 | |
26062729 | 3210 | -- Check that the class-wide predicate cannot be applied to |
051826ee | 3211 | -- an operation of a synchronized type. AI12-0182 forbids |
3212 | -- these altogether, while earlier language semantics made | |
3213 | -- them legal on tagged synchronized types. | |
3214 | ||
3215 | -- Other legality checks are performed when analyzing the | |
3216 | -- contract of the operation. | |
26062729 | 3217 | |
3218 | if Class_Present (Aspect) | |
3219 | and then Is_Concurrent_Type (Current_Scope) | |
26062729 | 3220 | and then Ekind_In (E, E_Entry, E_Function, E_Procedure) |
3221 | then | |
3222 | Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Aspect); | |
3223 | Error_Msg_N | |
3224 | ("aspect % can only be specified for a primitive " | |
3225 | & "operation of a tagged type", Aspect); | |
3226 | ||
3227 | goto Continue; | |
3228 | end if; | |
3229 | ||
1e3c4ae6 | 3230 | -- If the expressions is of the form A and then B, then |
3231 | -- we generate separate Pre/Post aspects for the separate | |
3232 | -- clauses. Since we allow multiple pragmas, there is no | |
3233 | -- problem in allowing multiple Pre/Post aspects internally. | |
a273015d | 3234 | -- These should be treated in reverse order (B first and |
3235 | -- A second) since they are later inserted just after N in | |
3236 | -- the order they are treated. This way, the pragma for A | |
3237 | -- ends up preceding the pragma for B, which may have an | |
3238 | -- importance for the error raised (either constraint error | |
3239 | -- or precondition error). | |
1e3c4ae6 | 3240 | |
39e1f22f | 3241 | -- We do not do this for Pre'Class, since we have to put |
51fa2a45 | 3242 | -- these conditions together in a complex OR expression. |
ae888dbd | 3243 | |
4282d342 | 3244 | -- We do not do this in ASIS mode, as ASIS relies on the |
3245 | -- original node representing the complete expression, when | |
3246 | -- retrieving it through the source aspect table. | |
3247 | ||
3248 | if not ASIS_Mode | |
3249 | and then (Pname = Name_Postcondition | |
3250 | or else not Class_Present (Aspect)) | |
39e1f22f | 3251 | then |
3252 | while Nkind (Expr) = N_And_Then loop | |
3253 | Insert_After (Aspect, | |
a273015d | 3254 | Make_Aspect_Specification (Sloc (Left_Opnd (Expr)), |
39e1f22f | 3255 | Identifier => Identifier (Aspect), |
a273015d | 3256 | Expression => Relocate_Node (Left_Opnd (Expr)), |
39e1f22f | 3257 | Class_Present => Class_Present (Aspect), |
3258 | Split_PPC => True)); | |
a273015d | 3259 | Rewrite (Expr, Relocate_Node (Right_Opnd (Expr))); |
39e1f22f | 3260 | Eloc := Sloc (Expr); |
3261 | end loop; | |
3262 | end if; | |
ae888dbd | 3263 | |
48d6f069 | 3264 | -- Build the precondition/postcondition pragma |
3265 | ||
51fa2a45 | 3266 | -- Add note about why we do NOT need Copy_Tree here??? |
d74fc39a | 3267 | |
0fd13d32 | 3268 | Make_Aitem_Pragma |
3269 | (Pragma_Argument_Associations => New_List ( | |
3270 | Make_Pragma_Argument_Association (Eloc, | |
3271 | Chars => Name_Check, | |
a19e1763 | 3272 | Expression => Relocate_Node (Expr))), |
0fd13d32 | 3273 | Pragma_Name => Pname); |
39e1f22f | 3274 | |
3275 | -- Add message unless exception messages are suppressed | |
3276 | ||
3277 | if not Opt.Exception_Locations_Suppressed then | |
3278 | Append_To (Pragma_Argument_Associations (Aitem), | |
3279 | Make_Pragma_Argument_Association (Eloc, | |
ed695684 | 3280 | Chars => Name_Message, |
39e1f22f | 3281 | Expression => |
3282 | Make_String_Literal (Eloc, | |
3283 | Strval => "failed " | |
3284 | & Get_Name_String (Pname) | |
3285 | & " from " | |
3286 | & Build_Location_String (Eloc)))); | |
3287 | end if; | |
d74fc39a | 3288 | |
7d20685d | 3289 | Set_Is_Delayed_Aspect (Aspect); |
d74fc39a | 3290 | |
1e3c4ae6 | 3291 | -- For Pre/Post cases, insert immediately after the entity |
3292 | -- declaration, since that is the required pragma placement. | |
3293 | -- Note that for these aspects, we do not have to worry | |
3294 | -- about delay issues, since the pragmas themselves deal | |
3295 | -- with delay of visibility for the expression analysis. | |
3296 | ||
e2bf777d | 3297 | Insert_Pragma (Aitem); |
299b347e | 3298 | |
1e3c4ae6 | 3299 | goto Continue; |
5ddd846b | 3300 | end Pre_Post; |
ae888dbd | 3301 | |
0fd13d32 | 3302 | -- Test_Case |
3303 | ||
e66f4e2a | 3304 | when Aspect_Test_Case => Test_Case : declare |
3305 | Args : List_Id; | |
3306 | Comp_Expr : Node_Id; | |
3307 | Comp_Assn : Node_Id; | |
3308 | New_Expr : Node_Id; | |
57cd943b | 3309 | |
e66f4e2a | 3310 | begin |
3311 | Args := New_List; | |
b0bc40fd | 3312 | |
e66f4e2a | 3313 | if Nkind (Parent (N)) = N_Compilation_Unit then |
3314 | Error_Msg_Name_1 := Nam; | |
3315 | Error_Msg_N ("incorrect placement of aspect `%`", E); | |
3316 | goto Continue; | |
3317 | end if; | |
6c545057 | 3318 | |
e66f4e2a | 3319 | if Nkind (Expr) /= N_Aggregate then |
3320 | Error_Msg_Name_1 := Nam; | |
3321 | Error_Msg_NE | |
3322 | ("wrong syntax for aspect `%` for &", Id, E); | |
3323 | goto Continue; | |
3324 | end if; | |
6c545057 | 3325 | |
e66f4e2a | 3326 | -- Make pragma expressions refer to the original aspect |
51fa2a45 | 3327 | -- expressions through the Original_Node link. This is used |
3328 | -- in semantic analysis for ASIS mode, so that the original | |
3329 | -- expression also gets analyzed. | |
e66f4e2a | 3330 | |
3331 | Comp_Expr := First (Expressions (Expr)); | |
3332 | while Present (Comp_Expr) loop | |
3333 | New_Expr := Relocate_Node (Comp_Expr); | |
e66f4e2a | 3334 | Append_To (Args, |
3335 | Make_Pragma_Argument_Association (Sloc (Comp_Expr), | |
3336 | Expression => New_Expr)); | |
3337 | Next (Comp_Expr); | |
3338 | end loop; | |
3339 | ||
3340 | Comp_Assn := First (Component_Associations (Expr)); | |
3341 | while Present (Comp_Assn) loop | |
3342 | if List_Length (Choices (Comp_Assn)) /= 1 | |
3343 | or else | |
3344 | Nkind (First (Choices (Comp_Assn))) /= N_Identifier | |
3345 | then | |
fad014fe | 3346 | Error_Msg_Name_1 := Nam; |
6c545057 | 3347 | Error_Msg_NE |
fad014fe | 3348 | ("wrong syntax for aspect `%` for &", Id, E); |
6c545057 | 3349 | goto Continue; |
3350 | end if; | |
3351 | ||
e66f4e2a | 3352 | Append_To (Args, |
3353 | Make_Pragma_Argument_Association (Sloc (Comp_Assn), | |
ed695684 | 3354 | Chars => Chars (First (Choices (Comp_Assn))), |
3355 | Expression => | |
3356 | Relocate_Node (Expression (Comp_Assn)))); | |
e66f4e2a | 3357 | Next (Comp_Assn); |
3358 | end loop; | |
6c545057 | 3359 | |
e66f4e2a | 3360 | -- Build the test-case pragma |
6c545057 | 3361 | |
0fd13d32 | 3362 | Make_Aitem_Pragma |
3363 | (Pragma_Argument_Associations => Args, | |
3364 | Pragma_Name => Nam); | |
e66f4e2a | 3365 | end Test_Case; |
85696508 | 3366 | |
0fd13d32 | 3367 | -- Contract_Cases |
3368 | ||
5ddd846b | 3369 | when Aspect_Contract_Cases => |
0fd13d32 | 3370 | Make_Aitem_Pragma |
3371 | (Pragma_Argument_Associations => New_List ( | |
3372 | Make_Pragma_Argument_Association (Loc, | |
3373 | Expression => Relocate_Node (Expr))), | |
3374 | Pragma_Name => Nam); | |
3a128918 | 3375 | |
e2bf777d | 3376 | Decorate (Aspect, Aitem); |
3377 | Insert_Pragma (Aitem); | |
5ddd846b | 3378 | goto Continue; |
3a128918 | 3379 | |
89f1e35c | 3380 | -- Case 5: Special handling for aspects with an optional |
3381 | -- boolean argument. | |
85696508 | 3382 | |
6c5793cd | 3383 | -- In the delayed case, the corresponding pragma cannot be |
0fd13d32 | 3384 | -- generated yet because the evaluation of the boolean needs |
3385 | -- to be delayed till the freeze point. | |
3386 | ||
99378362 | 3387 | when Boolean_Aspects |
3388 | | Library_Unit_Aspects | |
3389 | => | |
89f1e35c | 3390 | Set_Is_Boolean_Aspect (Aspect); |
a5a64273 | 3391 | |
89f1e35c | 3392 | -- Lock_Free aspect only apply to protected objects |
e1cedbae | 3393 | |
89f1e35c | 3394 | if A_Id = Aspect_Lock_Free then |
3395 | if Ekind (E) /= E_Protected_Type then | |
99a2d5bd | 3396 | Error_Msg_Name_1 := Nam; |
a5a64273 | 3397 | Error_Msg_N |
89f1e35c | 3398 | ("aspect % only applies to a protected object", |
3399 | Aspect); | |
3400 | ||
3401 | else | |
3402 | -- Set the Uses_Lock_Free flag to True if there is no | |
37c6e44c | 3403 | -- expression or if the expression is True. The |
89f1e35c | 3404 | -- evaluation of this aspect should be delayed to the |
37c6e44c | 3405 | -- freeze point (why???) |
89f1e35c | 3406 | |
e81df51c | 3407 | if No (Expr) |
3408 | or else Is_True (Static_Boolean (Expr)) | |
89f1e35c | 3409 | then |
3410 | Set_Uses_Lock_Free (E); | |
3411 | end if; | |
caf125ce | 3412 | |
3413 | Record_Rep_Item (E, Aspect); | |
a5a64273 | 3414 | end if; |
e1cedbae | 3415 | |
89f1e35c | 3416 | goto Continue; |
ae888dbd | 3417 | |
ee2b7923 | 3418 | elsif A_Id = Aspect_Export or else A_Id = Aspect_Import then |
3419 | Analyze_Aspect_Export_Import; | |
6c5793cd | 3420 | |
3421 | -- Disable_Controlled | |
3422 | ||
3423 | elsif A_Id = Aspect_Disable_Controlled then | |
3424 | if Ekind (E) /= E_Record_Type | |
3425 | or else not Is_Controlled (E) | |
3426 | then | |
3427 | Error_Msg_N | |
3428 | ("aspect % requires controlled record type", Aspect); | |
3429 | goto Continue; | |
3430 | end if; | |
3431 | ||
3f716509 | 3432 | -- If we're in a generic template, we don't want to try |
3433 | -- to disable controlled types, because typical usage is | |
3434 | -- "Disable_Controlled => not <some_check>'Enabled", and | |
3435 | -- the value of Enabled is not known until we see a | |
7e2d3667 | 3436 | -- particular instance. In such a context, we just need |
3437 | -- to preanalyze the expression for legality. | |
3f716509 | 3438 | |
3439 | if Expander_Active then | |
aae9bc79 | 3440 | Analyze_And_Resolve (Expr, Standard_Boolean); |
3441 | ||
3f716509 | 3442 | if not Present (Expr) |
3443 | or else Is_True (Static_Boolean (Expr)) | |
3444 | then | |
3445 | Set_Disable_Controlled (E); | |
3446 | end if; | |
7e2d3667 | 3447 | |
3448 | elsif Serious_Errors_Detected = 0 then | |
3449 | Preanalyze_And_Resolve (Expr, Standard_Boolean); | |
6c5793cd | 3450 | end if; |
3451 | ||
89f1e35c | 3452 | goto Continue; |
3453 | end if; | |
d74fc39a | 3454 | |
37c6e44c | 3455 | -- Library unit aspects require special handling in the case |
3456 | -- of a package declaration, the pragma needs to be inserted | |
3457 | -- in the list of declarations for the associated package. | |
3458 | -- There is no issue of visibility delay for these aspects. | |
d64221a7 | 3459 | |
89f1e35c | 3460 | if A_Id in Library_Unit_Aspects |
178fec9b | 3461 | and then |
3462 | Nkind_In (N, N_Package_Declaration, | |
3463 | N_Generic_Package_Declaration) | |
89f1e35c | 3464 | and then Nkind (Parent (N)) /= N_Compilation_Unit |
3ad60f63 | 3465 | |
3466 | -- Aspect is legal on a local instantiation of a library- | |
3467 | -- level generic unit. | |
3468 | ||
b94a633e | 3469 | and then not Is_Generic_Instance (Defining_Entity (N)) |
89f1e35c | 3470 | then |
3471 | Error_Msg_N | |
dd4c44af | 3472 | ("incorrect context for library unit aspect&", Id); |
89f1e35c | 3473 | goto Continue; |
3474 | end if; | |
cce84b09 | 3475 | |
51fa2a45 | 3476 | -- Cases where we do not delay, includes all cases where the |
3477 | -- expression is missing other than the above cases. | |
d74fc39a | 3478 | |
85ee12c0 | 3479 | if not Delay_Required or else No (Expr) then |
ee2b7923 | 3480 | |
3481 | -- Exclude aspects Export and Import because their pragma | |
3482 | -- syntax does not map directly to a Boolean aspect. | |
3483 | ||
3484 | if A_Id /= Aspect_Export | |
3485 | and then A_Id /= Aspect_Import | |
3486 | then | |
3487 | Make_Aitem_Pragma | |
3488 | (Pragma_Argument_Associations => New_List ( | |
3489 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3490 | Expression => Ent)), | |
3491 | Pragma_Name => Chars (Id)); | |
3492 | end if; | |
3493 | ||
89f1e35c | 3494 | Delay_Required := False; |
ddf1337b | 3495 | |
89f1e35c | 3496 | -- In general cases, the corresponding pragma/attribute |
3497 | -- definition clause will be inserted later at the freezing | |
294709fa | 3498 | -- point, and we do not need to build it now. |
ddf1337b | 3499 | |
89f1e35c | 3500 | else |
3501 | Aitem := Empty; | |
3502 | end if; | |
ceec4f7c | 3503 | |
3504 | -- Storage_Size | |
3505 | ||
3506 | -- This is special because for access types we need to generate | |
3507 | -- an attribute definition clause. This also works for single | |
3508 | -- task declarations, but it does not work for task type | |
3509 | -- declarations, because we have the case where the expression | |
3510 | -- references a discriminant of the task type. That can't use | |
3511 | -- an attribute definition clause because we would not have | |
3512 | -- visibility on the discriminant. For that case we must | |
3513 | -- generate a pragma in the task definition. | |
3514 | ||
3515 | when Aspect_Storage_Size => | |
3516 | ||
3517 | -- Task type case | |
3518 | ||
3519 | if Ekind (E) = E_Task_Type then | |
3520 | declare | |
3521 | Decl : constant Node_Id := Declaration_Node (E); | |
3522 | ||
3523 | begin | |
3524 | pragma Assert (Nkind (Decl) = N_Task_Type_Declaration); | |
3525 | ||
3526 | -- If no task definition, create one | |
3527 | ||
3528 | if No (Task_Definition (Decl)) then | |
3529 | Set_Task_Definition (Decl, | |
3530 | Make_Task_Definition (Loc, | |
3531 | Visible_Declarations => Empty_List, | |
3532 | End_Label => Empty)); | |
3533 | end if; | |
3534 | ||
51fa2a45 | 3535 | -- Create a pragma and put it at the start of the task |
3536 | -- definition for the task type declaration. | |
ceec4f7c | 3537 | |
3538 | Make_Aitem_Pragma | |
3539 | (Pragma_Argument_Associations => New_List ( | |
3540 | Make_Pragma_Argument_Association (Loc, | |
3541 | Expression => Relocate_Node (Expr))), | |
3542 | Pragma_Name => Name_Storage_Size); | |
3543 | ||
3544 | Prepend | |
3545 | (Aitem, | |
3546 | Visible_Declarations (Task_Definition (Decl))); | |
3547 | goto Continue; | |
3548 | end; | |
3549 | ||
3550 | -- All other cases, generate attribute definition | |
3551 | ||
3552 | else | |
3553 | Aitem := | |
3554 | Make_Attribute_Definition_Clause (Loc, | |
3555 | Name => Ent, | |
3556 | Chars => Chars (Id), | |
3557 | Expression => Relocate_Node (Expr)); | |
3558 | end if; | |
89f1e35c | 3559 | end case; |
ddf1337b | 3560 | |
89f1e35c | 3561 | -- Attach the corresponding pragma/attribute definition clause to |
3562 | -- the aspect specification node. | |
d74fc39a | 3563 | |
89f1e35c | 3564 | if Present (Aitem) then |
e2bf777d | 3565 | Set_From_Aspect_Specification (Aitem); |
89f1e35c | 3566 | end if; |
53c179ea | 3567 | |
89f1e35c | 3568 | -- In the context of a compilation unit, we directly put the |
0fd13d32 | 3569 | -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux |
3570 | -- node (no delay is required here) except for aspects on a | |
51fa2a45 | 3571 | -- subprogram body (see below) and a generic package, for which we |
3572 | -- need to introduce the pragma before building the generic copy | |
3573 | -- (see sem_ch12), and for package instantiations, where the | |
3574 | -- library unit pragmas are better handled early. | |
ddf1337b | 3575 | |
9129c28f | 3576 | if Nkind (Parent (N)) = N_Compilation_Unit |
89f1e35c | 3577 | and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect)) |
3578 | then | |
3579 | declare | |
3580 | Aux : constant Node_Id := Aux_Decls_Node (Parent (N)); | |
7f694ca2 | 3581 | |
89f1e35c | 3582 | begin |
3583 | pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux); | |
7f694ca2 | 3584 | |
89f1e35c | 3585 | -- For a Boolean aspect, create the corresponding pragma if |
3586 | -- no expression or if the value is True. | |
7f694ca2 | 3587 | |
b9e61b2a | 3588 | if Is_Boolean_Aspect (Aspect) and then No (Aitem) then |
89f1e35c | 3589 | if Is_True (Static_Boolean (Expr)) then |
0fd13d32 | 3590 | Make_Aitem_Pragma |
3591 | (Pragma_Argument_Associations => New_List ( | |
3592 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3593 | Expression => Ent)), | |
3594 | Pragma_Name => Chars (Id)); | |
7f694ca2 | 3595 | |
89f1e35c | 3596 | Set_From_Aspect_Specification (Aitem, True); |
3597 | Set_Corresponding_Aspect (Aitem, Aspect); | |
3598 | ||
3599 | else | |
3600 | goto Continue; | |
3601 | end if; | |
3602 | end if; | |
7f694ca2 | 3603 | |
d6814978 | 3604 | -- If the aspect is on a subprogram body (relevant aspect |
3605 | -- is Inline), add the pragma in front of the declarations. | |
3a72f9c3 | 3606 | |
3607 | if Nkind (N) = N_Subprogram_Body then | |
3608 | if No (Declarations (N)) then | |
3609 | Set_Declarations (N, New_List); | |
3610 | end if; | |
3611 | ||
3612 | Prepend (Aitem, Declarations (N)); | |
3613 | ||
178fec9b | 3614 | elsif Nkind (N) = N_Generic_Package_Declaration then |
3615 | if No (Visible_Declarations (Specification (N))) then | |
3616 | Set_Visible_Declarations (Specification (N), New_List); | |
3617 | end if; | |
3618 | ||
3619 | Prepend (Aitem, | |
3620 | Visible_Declarations (Specification (N))); | |
3621 | ||
c39cce40 | 3622 | elsif Nkind (N) = N_Package_Instantiation then |
df8b0dae | 3623 | declare |
3624 | Spec : constant Node_Id := | |
3625 | Specification (Instance_Spec (N)); | |
3626 | begin | |
3627 | if No (Visible_Declarations (Spec)) then | |
3628 | Set_Visible_Declarations (Spec, New_List); | |
3629 | end if; | |
3630 | ||
3631 | Prepend (Aitem, Visible_Declarations (Spec)); | |
3632 | end; | |
3633 | ||
3a72f9c3 | 3634 | else |
3635 | if No (Pragmas_After (Aux)) then | |
d4596fbe | 3636 | Set_Pragmas_After (Aux, New_List); |
3a72f9c3 | 3637 | end if; |
3638 | ||
3639 | Append (Aitem, Pragmas_After (Aux)); | |
89f1e35c | 3640 | end if; |
7f694ca2 | 3641 | |
89f1e35c | 3642 | goto Continue; |
3643 | end; | |
3644 | end if; | |
7f694ca2 | 3645 | |
89f1e35c | 3646 | -- The evaluation of the aspect is delayed to the freezing point. |
3647 | -- The pragma or attribute clause if there is one is then attached | |
37c6e44c | 3648 | -- to the aspect specification which is put in the rep item list. |
1a814552 | 3649 | |
89f1e35c | 3650 | if Delay_Required then |
3651 | if Present (Aitem) then | |
3652 | Set_Is_Delayed_Aspect (Aitem); | |
3653 | Set_Aspect_Rep_Item (Aspect, Aitem); | |
3654 | Set_Parent (Aitem, Aspect); | |
3655 | end if; | |
1a814552 | 3656 | |
89f1e35c | 3657 | Set_Is_Delayed_Aspect (Aspect); |
9f36e3fb | 3658 | |
cba2ae82 | 3659 | -- In the case of Default_Value, link the aspect to base type |
3660 | -- as well, even though it appears on a first subtype. This is | |
3661 | -- mandated by the semantics of the aspect. Do not establish | |
3662 | -- the link when processing the base type itself as this leads | |
3663 | -- to a rep item circularity. Verify that we are dealing with | |
3664 | -- a scalar type to prevent cascaded errors. | |
3665 | ||
3666 | if A_Id = Aspect_Default_Value | |
3667 | and then Is_Scalar_Type (E) | |
3668 | and then Base_Type (E) /= E | |
3669 | then | |
9f36e3fb | 3670 | Set_Has_Delayed_Aspects (Base_Type (E)); |
3671 | Record_Rep_Item (Base_Type (E), Aspect); | |
3672 | end if; | |
3673 | ||
89f1e35c | 3674 | Set_Has_Delayed_Aspects (E); |
3675 | Record_Rep_Item (E, Aspect); | |
ddf1337b | 3676 | |
b855559d | 3677 | -- When delay is not required and the context is a package or a |
3678 | -- subprogram body, insert the pragma in the body declarations. | |
f55ce169 | 3679 | |
b855559d | 3680 | elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then |
f55ce169 | 3681 | if No (Declarations (N)) then |
3682 | Set_Declarations (N, New_List); | |
3683 | end if; | |
3684 | ||
3685 | -- The pragma is added before source declarations | |
3686 | ||
3687 | Prepend_To (Declarations (N), Aitem); | |
3688 | ||
89f1e35c | 3689 | -- When delay is not required and the context is not a compilation |
3690 | -- unit, we simply insert the pragma/attribute definition clause | |
3691 | -- in sequence. | |
ddf1337b | 3692 | |
ee2b7923 | 3693 | elsif Present (Aitem) then |
89f1e35c | 3694 | Insert_After (Ins_Node, Aitem); |
3695 | Ins_Node := Aitem; | |
d74fc39a | 3696 | end if; |
0fd13d32 | 3697 | end Analyze_One_Aspect; |
ae888dbd | 3698 | |
d64221a7 | 3699 | <<Continue>> |
3700 | Next (Aspect); | |
21ea3a4f | 3701 | end loop Aspect_Loop; |
89f1e35c | 3702 | |
3703 | if Has_Delayed_Aspects (E) then | |
3704 | Ensure_Freeze_Node (E); | |
3705 | end if; | |
21ea3a4f | 3706 | end Analyze_Aspect_Specifications; |
ae888dbd | 3707 | |
eb8aeefc | 3708 | --------------------------------------------------- |
3709 | -- Analyze_Aspect_Specifications_On_Body_Or_Stub -- | |
3710 | --------------------------------------------------- | |
3711 | ||
3712 | procedure Analyze_Aspect_Specifications_On_Body_Or_Stub (N : Node_Id) is | |
3713 | Body_Id : constant Entity_Id := Defining_Entity (N); | |
3714 | ||
3715 | procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id); | |
c02dccca | 3716 | -- Body [stub] N has aspects, but they are not properly placed. Emit an |
3717 | -- error message depending on the aspects involved. Spec_Id denotes the | |
3718 | -- entity of the corresponding spec. | |
eb8aeefc | 3719 | |
3720 | -------------------------------- | |
3721 | -- Diagnose_Misplaced_Aspects -- | |
3722 | -------------------------------- | |
3723 | ||
3724 | procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is | |
3725 | procedure Misplaced_Aspect_Error | |
3726 | (Asp : Node_Id; | |
3727 | Ref_Nam : Name_Id); | |
3728 | -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is | |
3729 | -- the name of the refined version of the aspect. | |
3730 | ||
3731 | ---------------------------- | |
3732 | -- Misplaced_Aspect_Error -- | |
3733 | ---------------------------- | |
3734 | ||
3735 | procedure Misplaced_Aspect_Error | |
3736 | (Asp : Node_Id; | |
3737 | Ref_Nam : Name_Id) | |
3738 | is | |
3739 | Asp_Nam : constant Name_Id := Chars (Identifier (Asp)); | |
3740 | Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam); | |
3741 | ||
3742 | begin | |
3743 | -- The corresponding spec already contains the aspect in question | |
3744 | -- and the one appearing on the body must be the refined form: | |
3745 | ||
3746 | -- procedure P with Global ...; | |
3747 | -- procedure P with Global ... is ... end P; | |
3748 | -- ^ | |
3749 | -- Refined_Global | |
3750 | ||
3751 | if Has_Aspect (Spec_Id, Asp_Id) then | |
3752 | Error_Msg_Name_1 := Asp_Nam; | |
3753 | ||
3754 | -- Subunits cannot carry aspects that apply to a subprogram | |
3755 | -- declaration. | |
3756 | ||
3757 | if Nkind (Parent (N)) = N_Subunit then | |
3758 | Error_Msg_N ("aspect % cannot apply to a subunit", Asp); | |
3759 | ||
3760 | -- Otherwise suggest the refined form | |
3761 | ||
3762 | else | |
3763 | Error_Msg_Name_2 := Ref_Nam; | |
3764 | Error_Msg_N ("aspect % should be %", Asp); | |
3765 | end if; | |
3766 | ||
3767 | -- Otherwise the aspect must appear on the spec, not on the body | |
3768 | ||
3769 | -- procedure P; | |
3770 | -- procedure P with Global ... is ... end P; | |
3771 | ||
3772 | else | |
3773 | Error_Msg_N | |
c02dccca | 3774 | ("aspect specification must appear on initial declaration", |
eb8aeefc | 3775 | Asp); |
3776 | end if; | |
3777 | end Misplaced_Aspect_Error; | |
3778 | ||
3779 | -- Local variables | |
3780 | ||
3781 | Asp : Node_Id; | |
3782 | Asp_Nam : Name_Id; | |
3783 | ||
3784 | -- Start of processing for Diagnose_Misplaced_Aspects | |
3785 | ||
3786 | begin | |
3787 | -- Iterate over the aspect specifications and emit specific errors | |
3788 | -- where applicable. | |
3789 | ||
3790 | Asp := First (Aspect_Specifications (N)); | |
3791 | while Present (Asp) loop | |
3792 | Asp_Nam := Chars (Identifier (Asp)); | |
3793 | ||
3794 | -- Do not emit errors on aspects that can appear on a subprogram | |
3795 | -- body. This scenario occurs when the aspect specification list | |
3796 | -- contains both misplaced and properly placed aspects. | |
3797 | ||
3798 | if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then | |
3799 | null; | |
3800 | ||
3801 | -- Special diagnostics for SPARK aspects | |
3802 | ||
3803 | elsif Asp_Nam = Name_Depends then | |
3804 | Misplaced_Aspect_Error (Asp, Name_Refined_Depends); | |
3805 | ||
3806 | elsif Asp_Nam = Name_Global then | |
3807 | Misplaced_Aspect_Error (Asp, Name_Refined_Global); | |
3808 | ||
3809 | elsif Asp_Nam = Name_Post then | |
3810 | Misplaced_Aspect_Error (Asp, Name_Refined_Post); | |
3811 | ||
3812 | -- Otherwise a language-defined aspect is misplaced | |
3813 | ||
3814 | else | |
3815 | Error_Msg_N | |
c02dccca | 3816 | ("aspect specification must appear on initial declaration", |
eb8aeefc | 3817 | Asp); |
3818 | end if; | |
3819 | ||
3820 | Next (Asp); | |
3821 | end loop; | |
3822 | end Diagnose_Misplaced_Aspects; | |
3823 | ||
3824 | -- Local variables | |
3825 | ||
c02dccca | 3826 | Spec_Id : constant Entity_Id := Unique_Defining_Entity (N); |
eb8aeefc | 3827 | |
3828 | -- Start of processing for Analyze_Aspects_On_Body_Or_Stub | |
3829 | ||
3830 | begin | |
eb8aeefc | 3831 | -- Language-defined aspects cannot be associated with a subprogram body |
3832 | -- [stub] if the subprogram has a spec. Certain implementation defined | |
3833 | -- aspects are allowed to break this rule (for all applicable cases, see | |
3834 | -- table Aspects.Aspect_On_Body_Or_Stub_OK). | |
3835 | ||
c02dccca | 3836 | if Spec_Id /= Body_Id and then not Aspects_On_Body_Or_Stub_OK (N) then |
eb8aeefc | 3837 | Diagnose_Misplaced_Aspects (Spec_Id); |
3838 | else | |
3839 | Analyze_Aspect_Specifications (N, Body_Id); | |
3840 | end if; | |
3841 | end Analyze_Aspect_Specifications_On_Body_Or_Stub; | |
3842 | ||
d6f39728 | 3843 | ----------------------- |
3844 | -- Analyze_At_Clause -- | |
3845 | ----------------------- | |
3846 | ||
3847 | -- An at clause is replaced by the corresponding Address attribute | |
3848 | -- definition clause that is the preferred approach in Ada 95. | |
3849 | ||
3850 | procedure Analyze_At_Clause (N : Node_Id) is | |
177675a7 | 3851 | CS : constant Boolean := Comes_From_Source (N); |
3852 | ||
d6f39728 | 3853 | begin |
177675a7 | 3854 | -- This is an obsolescent feature |
3855 | ||
e0521a36 | 3856 | Check_Restriction (No_Obsolescent_Features, N); |
3857 | ||
9dfe12ae | 3858 | if Warn_On_Obsolescent_Feature then |
3859 | Error_Msg_N | |
b174444e | 3860 | ("?j?at clause is an obsolescent feature (RM J.7(2))", N); |
9dfe12ae | 3861 | Error_Msg_N |
b174444e | 3862 | ("\?j?use address attribute definition clause instead", N); |
9dfe12ae | 3863 | end if; |
3864 | ||
177675a7 | 3865 | -- Rewrite as address clause |
3866 | ||
d6f39728 | 3867 | Rewrite (N, |
3868 | Make_Attribute_Definition_Clause (Sloc (N), | |
935e86e0 | 3869 | Name => Identifier (N), |
3870 | Chars => Name_Address, | |
d6f39728 | 3871 | Expression => Expression (N))); |
177675a7 | 3872 | |
2beb22b1 | 3873 | -- We preserve Comes_From_Source, since logically the clause still comes |
3874 | -- from the source program even though it is changed in form. | |
177675a7 | 3875 | |
3876 | Set_Comes_From_Source (N, CS); | |
3877 | ||
3878 | -- Analyze rewritten clause | |
3879 | ||
d6f39728 | 3880 | Analyze_Attribute_Definition_Clause (N); |
3881 | end Analyze_At_Clause; | |
3882 | ||
3883 | ----------------------------------------- | |
3884 | -- Analyze_Attribute_Definition_Clause -- | |
3885 | ----------------------------------------- | |
3886 | ||
3887 | procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is | |
3888 | Loc : constant Source_Ptr := Sloc (N); | |
3889 | Nam : constant Node_Id := Name (N); | |
3890 | Attr : constant Name_Id := Chars (N); | |
3891 | Expr : constant Node_Id := Expression (N); | |
3892 | Id : constant Attribute_Id := Get_Attribute_Id (Attr); | |
d64221a7 | 3893 | |
3894 | Ent : Entity_Id; | |
3895 | -- The entity of Nam after it is analyzed. In the case of an incomplete | |
3896 | -- type, this is the underlying type. | |
3897 | ||
d6f39728 | 3898 | U_Ent : Entity_Id; |
d64221a7 | 3899 | -- The underlying entity to which the attribute applies. Generally this |
3900 | -- is the Underlying_Type of Ent, except in the case where the clause | |
69069c76 | 3901 | -- applies to the full view of an incomplete or private type, in which |
3902 | -- case U_Ent is just a copy of Ent. | |
d6f39728 | 3903 | |
3904 | FOnly : Boolean := False; | |
3905 | -- Reset to True for subtype specific attribute (Alignment, Size) | |
51fa2a45 | 3906 | -- and for stream attributes, i.e. those cases where in the call to |
3907 | -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules | |
3908 | -- are checked. Note that the case of stream attributes is not clear | |
3909 | -- from the RM, but see AI95-00137. Also, the RM seems to disallow | |
3910 | -- Storage_Size for derived task types, but that is also clearly | |
3911 | -- unintentional. | |
d6f39728 | 3912 | |
9f373bb8 | 3913 | procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type); |
3914 | -- Common processing for 'Read, 'Write, 'Input and 'Output attribute | |
3915 | -- definition clauses. | |
3916 | ||
ae888dbd | 3917 | function Duplicate_Clause return Boolean; |
3918 | -- This routine checks if the aspect for U_Ent being given by attribute | |
3919 | -- definition clause N is for an aspect that has already been specified, | |
3920 | -- and if so gives an error message. If there is a duplicate, True is | |
3921 | -- returned, otherwise if there is no error, False is returned. | |
3922 | ||
81b424ac | 3923 | procedure Check_Indexing_Functions; |
3924 | -- Check that the function in Constant_Indexing or Variable_Indexing | |
3925 | -- attribute has the proper type structure. If the name is overloaded, | |
cac18f71 | 3926 | -- check that some interpretation is legal. |
81b424ac | 3927 | |
89cc7147 | 3928 | procedure Check_Iterator_Functions; |
3929 | -- Check that there is a single function in Default_Iterator attribute | |
8df4f2a5 | 3930 | -- has the proper type structure. |
89cc7147 | 3931 | |
3932 | function Check_Primitive_Function (Subp : Entity_Id) return Boolean; | |
d03bfaa1 | 3933 | -- Common legality check for the previous two |
89cc7147 | 3934 | |
177675a7 | 3935 | ----------------------------------- |
3936 | -- Analyze_Stream_TSS_Definition -- | |
3937 | ----------------------------------- | |
3938 | ||
9f373bb8 | 3939 | procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is |
3940 | Subp : Entity_Id := Empty; | |
3941 | I : Interp_Index; | |
3942 | It : Interp; | |
3943 | Pnam : Entity_Id; | |
3944 | ||
3945 | Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read); | |
ba662f09 | 3946 | -- True for Read attribute, False for other attributes |
9f373bb8 | 3947 | |
c41e404d | 3948 | function Has_Good_Profile |
3949 | (Subp : Entity_Id; | |
3950 | Report : Boolean := False) return Boolean; | |
9f373bb8 | 3951 | -- Return true if the entity is a subprogram with an appropriate |
ba662f09 | 3952 | -- profile for the attribute being defined. If result is False and |
3953 | -- Report is True, function emits appropriate error. | |
9f373bb8 | 3954 | |
3955 | ---------------------- | |
3956 | -- Has_Good_Profile -- | |
3957 | ---------------------- | |
3958 | ||
c41e404d | 3959 | function Has_Good_Profile |
3960 | (Subp : Entity_Id; | |
3961 | Report : Boolean := False) return Boolean | |
3962 | is | |
9f373bb8 | 3963 | Expected_Ekind : constant array (Boolean) of Entity_Kind := |
3964 | (False => E_Procedure, True => E_Function); | |
4a83cc35 | 3965 | Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input); |
3966 | F : Entity_Id; | |
9f373bb8 | 3967 | Typ : Entity_Id; |
3968 | ||
3969 | begin | |
3970 | if Ekind (Subp) /= Expected_Ekind (Is_Function) then | |
3971 | return False; | |
3972 | end if; | |
3973 | ||
3974 | F := First_Formal (Subp); | |
3975 | ||
3976 | if No (F) | |
3977 | or else Ekind (Etype (F)) /= E_Anonymous_Access_Type | |
3978 | or else Designated_Type (Etype (F)) /= | |
4a83cc35 | 3979 | Class_Wide_Type (RTE (RE_Root_Stream_Type)) |
9f373bb8 | 3980 | then |
3981 | return False; | |
3982 | end if; | |
3983 | ||
3984 | if not Is_Function then | |
3985 | Next_Formal (F); | |
3986 | ||
3987 | declare | |
3988 | Expected_Mode : constant array (Boolean) of Entity_Kind := | |
3989 | (False => E_In_Parameter, | |
3990 | True => E_Out_Parameter); | |
3991 | begin | |
3992 | if Parameter_Mode (F) /= Expected_Mode (Is_Read) then | |
3993 | return False; | |
3994 | end if; | |
3995 | end; | |
3996 | ||
3997 | Typ := Etype (F); | |
3998 | ||
b64082f2 | 3999 | -- If the attribute specification comes from an aspect |
51fa2a45 | 4000 | -- specification for a class-wide stream, the parameter must be |
4001 | -- a class-wide type of the entity to which the aspect applies. | |
b64082f2 | 4002 | |
4003 | if From_Aspect_Specification (N) | |
4004 | and then Class_Present (Parent (N)) | |
4005 | and then Is_Class_Wide_Type (Typ) | |
4006 | then | |
4007 | Typ := Etype (Typ); | |
4008 | end if; | |
4009 | ||
9f373bb8 | 4010 | else |
4011 | Typ := Etype (Subp); | |
4012 | end if; | |
4013 | ||
51fa2a45 | 4014 | -- Verify that the prefix of the attribute and the local name for |
5a8fe506 | 4015 | -- the type of the formal match, or one is the class-wide of the |
4016 | -- other, in the case of a class-wide stream operation. | |
48680a09 | 4017 | |
b8eacb12 | 4018 | if Base_Type (Typ) = Base_Type (Ent) |
5a8fe506 | 4019 | or else (Is_Class_Wide_Type (Typ) |
2be1f7d7 | 4020 | and then Typ = Class_Wide_Type (Base_Type (Ent))) |
fbf4d6ef | 4021 | or else (Is_Class_Wide_Type (Ent) |
4022 | and then Ent = Class_Wide_Type (Base_Type (Typ))) | |
5a8fe506 | 4023 | then |
4024 | null; | |
4025 | else | |
4026 | return False; | |
4027 | end if; | |
4028 | ||
4a83cc35 | 4029 | if Present (Next_Formal (F)) then |
48680a09 | 4030 | return False; |
4031 | ||
4032 | elsif not Is_Scalar_Type (Typ) | |
4033 | and then not Is_First_Subtype (Typ) | |
4034 | and then not Is_Class_Wide_Type (Typ) | |
4035 | then | |
c41e404d | 4036 | if Report and not Is_First_Subtype (Typ) then |
4037 | Error_Msg_N | |
ba662f09 | 4038 | ("subtype of formal in stream operation must be a first " |
4039 | & "subtype", Parameter_Type (Parent (F))); | |
c41e404d | 4040 | end if; |
4041 | ||
48680a09 | 4042 | return False; |
4043 | ||
4044 | else | |
4045 | return True; | |
4046 | end if; | |
9f373bb8 | 4047 | end Has_Good_Profile; |
4048 | ||
4049 | -- Start of processing for Analyze_Stream_TSS_Definition | |
4050 | ||
4051 | begin | |
4052 | FOnly := True; | |
4053 | ||
4054 | if not Is_Type (U_Ent) then | |
4055 | Error_Msg_N ("local name must be a subtype", Nam); | |
4056 | return; | |
48680a09 | 4057 | |
4058 | elsif not Is_First_Subtype (U_Ent) then | |
4059 | Error_Msg_N ("local name must be a first subtype", Nam); | |
4060 | return; | |
9f373bb8 | 4061 | end if; |
4062 | ||
4063 | Pnam := TSS (Base_Type (U_Ent), TSS_Nam); | |
4064 | ||
44e4341e | 4065 | -- If Pnam is present, it can be either inherited from an ancestor |
4066 | -- type (in which case it is legal to redefine it for this type), or | |
4067 | -- be a previous definition of the attribute for the same type (in | |
4068 | -- which case it is illegal). | |
4069 | ||
4070 | -- In the first case, it will have been analyzed already, and we | |
4071 | -- can check that its profile does not match the expected profile | |
4072 | -- for a stream attribute of U_Ent. In the second case, either Pnam | |
4073 | -- has been analyzed (and has the expected profile), or it has not | |
4074 | -- been analyzed yet (case of a type that has not been frozen yet | |
4075 | -- and for which the stream attribute has been set using Set_TSS). | |
4076 | ||
4077 | if Present (Pnam) | |
4078 | and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam)) | |
4079 | then | |
9f373bb8 | 4080 | Error_Msg_Sloc := Sloc (Pnam); |
4081 | Error_Msg_Name_1 := Attr; | |
4082 | Error_Msg_N ("% attribute already defined #", Nam); | |
4083 | return; | |
4084 | end if; | |
4085 | ||
4086 | Analyze (Expr); | |
4087 | ||
4088 | if Is_Entity_Name (Expr) then | |
4089 | if not Is_Overloaded (Expr) then | |
c41e404d | 4090 | if Has_Good_Profile (Entity (Expr), Report => True) then |
9f373bb8 | 4091 | Subp := Entity (Expr); |
4092 | end if; | |
4093 | ||
4094 | else | |
4095 | Get_First_Interp (Expr, I, It); | |
9f373bb8 | 4096 | while Present (It.Nam) loop |
4097 | if Has_Good_Profile (It.Nam) then | |
4098 | Subp := It.Nam; | |
4099 | exit; | |
4100 | end if; | |
4101 | ||
4102 | Get_Next_Interp (I, It); | |
4103 | end loop; | |
4104 | end if; | |
4105 | end if; | |
4106 | ||
4107 | if Present (Subp) then | |
59ac57b5 | 4108 | if Is_Abstract_Subprogram (Subp) then |
9f373bb8 | 4109 | Error_Msg_N ("stream subprogram must not be abstract", Expr); |
4110 | return; | |
e12b2502 | 4111 | |
299b347e | 4112 | -- A stream subprogram for an interface type must be a null |
bfbd9cf4 | 4113 | -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type |
4114 | -- of an interface is not an interface type (3.9.4 (6.b/2)). | |
e12b2502 | 4115 | |
4116 | elsif Is_Interface (U_Ent) | |
5a8fe506 | 4117 | and then not Is_Class_Wide_Type (U_Ent) |
e12b2502 | 4118 | and then not Inside_A_Generic |
e12b2502 | 4119 | and then |
5a8fe506 | 4120 | (Ekind (Subp) = E_Function |
4121 | or else | |
4122 | not Null_Present | |
2be1f7d7 | 4123 | (Specification |
4124 | (Unit_Declaration_Node (Ultimate_Alias (Subp))))) | |
e12b2502 | 4125 | then |
4126 | Error_Msg_N | |
4a83cc35 | 4127 | ("stream subprogram for interface type must be null " |
4128 | & "procedure", Expr); | |
9f373bb8 | 4129 | end if; |
4130 | ||
4131 | Set_Entity (Expr, Subp); | |
4132 | Set_Etype (Expr, Etype (Subp)); | |
4133 | ||
44e4341e | 4134 | New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam); |
9f373bb8 | 4135 | |
4136 | else | |
4137 | Error_Msg_Name_1 := Attr; | |
4138 | Error_Msg_N ("incorrect expression for% attribute", Expr); | |
4139 | end if; | |
4140 | end Analyze_Stream_TSS_Definition; | |
4141 | ||
81b424ac | 4142 | ------------------------------ |
4143 | -- Check_Indexing_Functions -- | |
4144 | ------------------------------ | |
4145 | ||
4146 | procedure Check_Indexing_Functions is | |
c8a2d809 | 4147 | Indexing_Found : Boolean := False; |
8df4f2a5 | 4148 | |
44d567c8 | 4149 | procedure Check_Inherited_Indexing; |
4150 | -- For a derived type, check that no indexing aspect is specified | |
4151 | -- for the type if it is also inherited | |
4152 | ||
81b424ac | 4153 | procedure Check_One_Function (Subp : Entity_Id); |
7796365f | 4154 | -- Check one possible interpretation. Sets Indexing_Found True if a |
4155 | -- legal indexing function is found. | |
81b424ac | 4156 | |
05987af3 | 4157 | procedure Illegal_Indexing (Msg : String); |
4158 | -- Diagnose illegal indexing function if not overloaded. In the | |
4159 | -- overloaded case indicate that no legal interpretation exists. | |
4160 | ||
44d567c8 | 4161 | ------------------------------ |
4162 | -- Check_Inherited_Indexing -- | |
4163 | ------------------------------ | |
4164 | ||
4165 | procedure Check_Inherited_Indexing is | |
4166 | Inherited : Node_Id; | |
4167 | ||
4168 | begin | |
4169 | if Attr = Name_Constant_Indexing then | |
4170 | Inherited := | |
4171 | Find_Aspect (Etype (Ent), Aspect_Constant_Indexing); | |
4172 | else pragma Assert (Attr = Name_Variable_Indexing); | |
4173 | Inherited := | |
4174 | Find_Aspect (Etype (Ent), Aspect_Variable_Indexing); | |
4175 | end if; | |
4176 | ||
4177 | if Present (Inherited) then | |
4178 | if Debug_Flag_Dot_XX then | |
4179 | null; | |
4180 | ||
83d39cd3 | 4181 | -- OK if current attribute_definition_clause is expansion of |
4182 | -- inherited aspect. | |
44d567c8 | 4183 | |
4184 | elsif Aspect_Rep_Item (Inherited) = N then | |
4185 | null; | |
4186 | ||
83d39cd3 | 4187 | -- Indicate the operation that must be overridden, rather than |
4188 | -- redefining the indexing aspect. | |
44d567c8 | 4189 | |
4190 | else | |
4191 | Illegal_Indexing | |
f2837ceb | 4192 | ("indexing function already inherited from parent type"); |
44d567c8 | 4193 | Error_Msg_NE |
4194 | ("!override & instead", | |
4195 | N, Entity (Expression (Inherited))); | |
4196 | end if; | |
4197 | end if; | |
4198 | end Check_Inherited_Indexing; | |
4199 | ||
81b424ac | 4200 | ------------------------ |
4201 | -- Check_One_Function -- | |
4202 | ------------------------ | |
4203 | ||
4204 | procedure Check_One_Function (Subp : Entity_Id) is | |
05987af3 | 4205 | Default_Element : Node_Id; |
4206 | Ret_Type : constant Entity_Id := Etype (Subp); | |
1b7510f9 | 4207 | |
81b424ac | 4208 | begin |
05987af3 | 4209 | if not Is_Overloadable (Subp) then |
4210 | Illegal_Indexing ("illegal indexing function for type&"); | |
4211 | return; | |
4212 | ||
7796365f | 4213 | elsif Scope (Subp) /= Scope (Ent) then |
4214 | if Nkind (Expr) = N_Expanded_Name then | |
4215 | ||
4216 | -- Indexing function can't be declared elsewhere | |
4217 | ||
4218 | Illegal_Indexing | |
4219 | ("indexing function must be declared in scope of type&"); | |
4220 | end if; | |
4221 | ||
05987af3 | 4222 | return; |
4223 | ||
4224 | elsif No (First_Formal (Subp)) then | |
4225 | Illegal_Indexing | |
4226 | ("Indexing requires a function that applies to type&"); | |
4227 | return; | |
4228 | ||
4229 | elsif No (Next_Formal (First_Formal (Subp))) then | |
4230 | Illegal_Indexing | |
2eb0ff42 | 4231 | ("indexing function must have at least two parameters"); |
05987af3 | 4232 | return; |
4233 | ||
4234 | elsif Is_Derived_Type (Ent) then | |
44d567c8 | 4235 | Check_Inherited_Indexing; |
05987af3 | 4236 | end if; |
4237 | ||
e81df51c | 4238 | if not Check_Primitive_Function (Subp) then |
05987af3 | 4239 | Illegal_Indexing |
4240 | ("Indexing aspect requires a function that applies to type&"); | |
4241 | return; | |
81b424ac | 4242 | end if; |
4243 | ||
7796365f | 4244 | -- If partial declaration exists, verify that it is not tagged. |
4245 | ||
4246 | if Ekind (Current_Scope) = E_Package | |
4247 | and then Has_Private_Declaration (Ent) | |
4248 | and then From_Aspect_Specification (N) | |
7c0c95b8 | 4249 | and then |
4250 | List_Containing (Parent (Ent)) = | |
4251 | Private_Declarations | |
7796365f | 4252 | (Specification (Unit_Declaration_Node (Current_Scope))) |
4253 | and then Nkind (N) = N_Attribute_Definition_Clause | |
4254 | then | |
4255 | declare | |
4256 | Decl : Node_Id; | |
4257 | ||
4258 | begin | |
4259 | Decl := | |
4260 | First (Visible_Declarations | |
7c0c95b8 | 4261 | (Specification |
4262 | (Unit_Declaration_Node (Current_Scope)))); | |
7796365f | 4263 | |
4264 | while Present (Decl) loop | |
4265 | if Nkind (Decl) = N_Private_Type_Declaration | |
4266 | and then Ent = Full_View (Defining_Identifier (Decl)) | |
4267 | and then Tagged_Present (Decl) | |
4268 | and then No (Aspect_Specifications (Decl)) | |
4269 | then | |
4270 | Illegal_Indexing | |
4271 | ("Indexing aspect cannot be specified on full view " | |
7c0c95b8 | 4272 | & "if partial view is tagged"); |
7796365f | 4273 | return; |
4274 | end if; | |
4275 | ||
4276 | Next (Decl); | |
4277 | end loop; | |
4278 | end; | |
4279 | end if; | |
4280 | ||
1b7510f9 | 4281 | -- An indexing function must return either the default element of |
cac18f71 | 4282 | -- the container, or a reference type. For variable indexing it |
a45d946f | 4283 | -- must be the latter. |
1b7510f9 | 4284 | |
05987af3 | 4285 | Default_Element := |
4286 | Find_Value_Of_Aspect | |
4287 | (Etype (First_Formal (Subp)), Aspect_Iterator_Element); | |
4288 | ||
1b7510f9 | 4289 | if Present (Default_Element) then |
4290 | Analyze (Default_Element); | |
a45d946f | 4291 | |
1b7510f9 | 4292 | if Is_Entity_Name (Default_Element) |
05987af3 | 4293 | and then not Covers (Entity (Default_Element), Ret_Type) |
4294 | and then False | |
1b7510f9 | 4295 | then |
05987af3 | 4296 | Illegal_Indexing |
4297 | ("wrong return type for indexing function"); | |
1b7510f9 | 4298 | return; |
4299 | end if; | |
4300 | end if; | |
4301 | ||
a45d946f | 4302 | -- For variable_indexing the return type must be a reference type |
1b7510f9 | 4303 | |
05987af3 | 4304 | if Attr = Name_Variable_Indexing then |
4305 | if not Has_Implicit_Dereference (Ret_Type) then | |
4306 | Illegal_Indexing | |
4307 | ("variable indexing must return a reference type"); | |
4308 | return; | |
4309 | ||
423b89fd | 4310 | elsif Is_Access_Constant |
4311 | (Etype (First_Discriminant (Ret_Type))) | |
05987af3 | 4312 | then |
4313 | Illegal_Indexing | |
4314 | ("variable indexing must return an access to variable"); | |
4315 | return; | |
4316 | end if; | |
cac18f71 | 4317 | |
4318 | else | |
05987af3 | 4319 | if Has_Implicit_Dereference (Ret_Type) |
4320 | and then not | |
4321 | Is_Access_Constant (Etype (First_Discriminant (Ret_Type))) | |
4322 | then | |
4323 | Illegal_Indexing | |
4324 | ("constant indexing must return an access to constant"); | |
4325 | return; | |
4326 | ||
4327 | elsif Is_Access_Type (Etype (First_Formal (Subp))) | |
4328 | and then not Is_Access_Constant (Etype (First_Formal (Subp))) | |
4329 | then | |
4330 | Illegal_Indexing | |
4331 | ("constant indexing must apply to an access to constant"); | |
4332 | return; | |
4333 | end if; | |
81b424ac | 4334 | end if; |
05987af3 | 4335 | |
4336 | -- All checks succeeded. | |
4337 | ||
4338 | Indexing_Found := True; | |
81b424ac | 4339 | end Check_One_Function; |
4340 | ||
05987af3 | 4341 | ----------------------- |
4342 | -- Illegal_Indexing -- | |
4343 | ----------------------- | |
4344 | ||
4345 | procedure Illegal_Indexing (Msg : String) is | |
4346 | begin | |
7796365f | 4347 | Error_Msg_NE (Msg, N, Ent); |
05987af3 | 4348 | end Illegal_Indexing; |
4349 | ||
81b424ac | 4350 | -- Start of processing for Check_Indexing_Functions |
4351 | ||
4352 | begin | |
89cc7147 | 4353 | if In_Instance then |
44d567c8 | 4354 | Check_Inherited_Indexing; |
89cc7147 | 4355 | end if; |
4356 | ||
81b424ac | 4357 | Analyze (Expr); |
4358 | ||
4359 | if not Is_Overloaded (Expr) then | |
4360 | Check_One_Function (Entity (Expr)); | |
4361 | ||
4362 | else | |
4363 | declare | |
2c5754de | 4364 | I : Interp_Index; |
81b424ac | 4365 | It : Interp; |
4366 | ||
4367 | begin | |
cac18f71 | 4368 | Indexing_Found := False; |
81b424ac | 4369 | Get_First_Interp (Expr, I, It); |
4370 | while Present (It.Nam) loop | |
4371 | ||
4372 | -- Note that analysis will have added the interpretation | |
4373 | -- that corresponds to the dereference. We only check the | |
1ef2e6ef | 4374 | -- subprogram itself. Ignore homonyms that may come from |
4375 | -- derived types in the context. | |
81b424ac | 4376 | |
1ef2e6ef | 4377 | if Is_Overloadable (It.Nam) |
4378 | and then Comes_From_Source (It.Nam) | |
4379 | then | |
4380 | Check_One_Function (It.Nam); | |
81b424ac | 4381 | end if; |
4382 | ||
4383 | Get_Next_Interp (I, It); | |
4384 | end loop; | |
4385 | end; | |
4386 | end if; | |
7796365f | 4387 | |
7c0c95b8 | 4388 | if not Indexing_Found and then not Error_Posted (N) then |
7796365f | 4389 | Error_Msg_NE |
1ef2e6ef | 4390 | ("aspect Indexing requires a local function that applies to " |
4391 | & "type&", Expr, Ent); | |
7796365f | 4392 | end if; |
81b424ac | 4393 | end Check_Indexing_Functions; |
4394 | ||
89cc7147 | 4395 | ------------------------------ |
4396 | -- Check_Iterator_Functions -- | |
4397 | ------------------------------ | |
4398 | ||
4399 | procedure Check_Iterator_Functions is | |
89cc7147 | 4400 | function Valid_Default_Iterator (Subp : Entity_Id) return Boolean; |
8df4f2a5 | 4401 | -- Check one possible interpretation for validity |
89cc7147 | 4402 | |
4403 | ---------------------------- | |
4404 | -- Valid_Default_Iterator -- | |
4405 | ---------------------------- | |
4406 | ||
4407 | function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is | |
8b8be176 | 4408 | Root_T : constant Entity_Id := Root_Type (Etype (Etype (Subp))); |
7f5dd8d8 | 4409 | Formal : Entity_Id; |
89cc7147 | 4410 | |
4411 | begin | |
4412 | if not Check_Primitive_Function (Subp) then | |
4413 | return False; | |
8b8be176 | 4414 | |
4415 | -- The return type must be derived from a type in an instance | |
4416 | -- of Iterator.Interfaces, and thus its root type must have a | |
4417 | -- predefined name. | |
4418 | ||
4419 | elsif Chars (Root_T) /= Name_Forward_Iterator | |
4420 | and then Chars (Root_T) /= Name_Reversible_Iterator | |
4421 | then | |
4422 | return False; | |
4423 | ||
89cc7147 | 4424 | else |
4425 | Formal := First_Formal (Subp); | |
4426 | end if; | |
4427 | ||
8df4f2a5 | 4428 | -- False if any subsequent formal has no default expression |
89cc7147 | 4429 | |
8df4f2a5 | 4430 | Formal := Next_Formal (Formal); |
4431 | while Present (Formal) loop | |
4432 | if No (Expression (Parent (Formal))) then | |
4433 | return False; | |
4434 | end if; | |
89cc7147 | 4435 | |
8df4f2a5 | 4436 | Next_Formal (Formal); |
4437 | end loop; | |
89cc7147 | 4438 | |
8df4f2a5 | 4439 | -- True if all subsequent formals have default expressions |
89cc7147 | 4440 | |
4441 | return True; | |
4442 | end Valid_Default_Iterator; | |
4443 | ||
4444 | -- Start of processing for Check_Iterator_Functions | |
4445 | ||
4446 | begin | |
4447 | Analyze (Expr); | |
4448 | ||
4449 | if not Is_Entity_Name (Expr) then | |
4450 | Error_Msg_N ("aspect Iterator must be a function name", Expr); | |
4451 | end if; | |
4452 | ||
4453 | if not Is_Overloaded (Expr) then | |
4454 | if not Check_Primitive_Function (Entity (Expr)) then | |
4455 | Error_Msg_NE | |
4456 | ("aspect Indexing requires a function that applies to type&", | |
4457 | Entity (Expr), Ent); | |
4458 | end if; | |
4459 | ||
05f6f999 | 4460 | -- Flag the default_iterator as well as the denoted function. |
4461 | ||
89cc7147 | 4462 | if not Valid_Default_Iterator (Entity (Expr)) then |
05f6f999 | 4463 | Error_Msg_N ("improper function for default iterator!", Expr); |
89cc7147 | 4464 | end if; |
4465 | ||
4466 | else | |
89cc7147 | 4467 | declare |
270ee9c5 | 4468 | Default : Entity_Id := Empty; |
8be33fbe | 4469 | I : Interp_Index; |
4470 | It : Interp; | |
89cc7147 | 4471 | |
4472 | begin | |
4473 | Get_First_Interp (Expr, I, It); | |
4474 | while Present (It.Nam) loop | |
4475 | if not Check_Primitive_Function (It.Nam) | |
59f3e675 | 4476 | or else not Valid_Default_Iterator (It.Nam) |
89cc7147 | 4477 | then |
4478 | Remove_Interp (I); | |
4479 | ||
4480 | elsif Present (Default) then | |
89cc7147 | 4481 | |
8be33fbe | 4482 | -- An explicit one should override an implicit one |
4483 | ||
4484 | if Comes_From_Source (Default) = | |
4485 | Comes_From_Source (It.Nam) | |
4486 | then | |
4487 | Error_Msg_N ("default iterator must be unique", Expr); | |
4488 | Error_Msg_Sloc := Sloc (Default); | |
4489 | Error_Msg_N ("\\possible interpretation#", Expr); | |
4490 | Error_Msg_Sloc := Sloc (It.Nam); | |
4491 | Error_Msg_N ("\\possible interpretation#", Expr); | |
4492 | ||
4493 | elsif Comes_From_Source (It.Nam) then | |
4494 | Default := It.Nam; | |
4495 | end if; | |
89cc7147 | 4496 | else |
4497 | Default := It.Nam; | |
4498 | end if; | |
4499 | ||
4500 | Get_Next_Interp (I, It); | |
4501 | end loop; | |
89cc7147 | 4502 | |
270ee9c5 | 4503 | if Present (Default) then |
4504 | Set_Entity (Expr, Default); | |
4505 | Set_Is_Overloaded (Expr, False); | |
8b8be176 | 4506 | else |
4507 | Error_Msg_N | |
7f5dd8d8 | 4508 | ("no interpretation is a valid default iterator!", Expr); |
270ee9c5 | 4509 | end if; |
4510 | end; | |
89cc7147 | 4511 | end if; |
4512 | end Check_Iterator_Functions; | |
4513 | ||
4514 | ------------------------------- | |
4515 | -- Check_Primitive_Function -- | |
4516 | ------------------------------- | |
4517 | ||
4518 | function Check_Primitive_Function (Subp : Entity_Id) return Boolean is | |
4519 | Ctrl : Entity_Id; | |
4520 | ||
4521 | begin | |
4522 | if Ekind (Subp) /= E_Function then | |
4523 | return False; | |
4524 | end if; | |
4525 | ||
4526 | if No (First_Formal (Subp)) then | |
4527 | return False; | |
4528 | else | |
4529 | Ctrl := Etype (First_Formal (Subp)); | |
4530 | end if; | |
4531 | ||
05f6f999 | 4532 | -- To be a primitive operation subprogram has to be in same scope. |
4533 | ||
4534 | if Scope (Ctrl) /= Scope (Subp) then | |
4535 | return False; | |
4536 | end if; | |
4537 | ||
7d6fb253 | 4538 | -- Type of formal may be the class-wide type, an access to such, |
4539 | -- or an incomplete view. | |
4540 | ||
89cc7147 | 4541 | if Ctrl = Ent |
4542 | or else Ctrl = Class_Wide_Type (Ent) | |
4543 | or else | |
4544 | (Ekind (Ctrl) = E_Anonymous_Access_Type | |
b85d62ec | 4545 | and then (Designated_Type (Ctrl) = Ent |
4546 | or else | |
4547 | Designated_Type (Ctrl) = Class_Wide_Type (Ent))) | |
7d6fb253 | 4548 | or else |
4549 | (Ekind (Ctrl) = E_Incomplete_Type | |
4550 | and then Full_View (Ctrl) = Ent) | |
89cc7147 | 4551 | then |
4552 | null; | |
89cc7147 | 4553 | else |
4554 | return False; | |
4555 | end if; | |
4556 | ||
4557 | return True; | |
4558 | end Check_Primitive_Function; | |
4559 | ||
ae888dbd | 4560 | ---------------------- |
4561 | -- Duplicate_Clause -- | |
4562 | ---------------------- | |
4563 | ||
4564 | function Duplicate_Clause return Boolean is | |
d74fc39a | 4565 | A : Node_Id; |
ae888dbd | 4566 | |
4567 | begin | |
c8969ba6 | 4568 | -- Nothing to do if this attribute definition clause comes from |
4569 | -- an aspect specification, since we could not be duplicating an | |
ae888dbd | 4570 | -- explicit clause, and we dealt with the case of duplicated aspects |
4571 | -- in Analyze_Aspect_Specifications. | |
4572 | ||
4573 | if From_Aspect_Specification (N) then | |
4574 | return False; | |
4575 | end if; | |
4576 | ||
89f1e35c | 4577 | -- Otherwise current clause may duplicate previous clause, or a |
4578 | -- previously given pragma or aspect specification for the same | |
4579 | -- aspect. | |
d74fc39a | 4580 | |
89b3b365 | 4581 | A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False); |
ae888dbd | 4582 | |
4583 | if Present (A) then | |
89f1e35c | 4584 | Error_Msg_Name_1 := Chars (N); |
4585 | Error_Msg_Sloc := Sloc (A); | |
4586 | ||
89b3b365 | 4587 | Error_Msg_NE ("aspect% for & previously given#", N, U_Ent); |
89f1e35c | 4588 | return True; |
ae888dbd | 4589 | end if; |
4590 | ||
4591 | return False; | |
4592 | end Duplicate_Clause; | |
4593 | ||
9f373bb8 | 4594 | -- Start of processing for Analyze_Attribute_Definition_Clause |
4595 | ||
d6f39728 | 4596 | begin |
d64221a7 | 4597 | -- The following code is a defense against recursion. Not clear that |
51fa2a45 | 4598 | -- this can happen legitimately, but perhaps some error situations can |
4599 | -- cause it, and we did see this recursion during testing. | |
d64221a7 | 4600 | |
4601 | if Analyzed (N) then | |
4602 | return; | |
4603 | else | |
4604 | Set_Analyzed (N, True); | |
4605 | end if; | |
4606 | ||
2609e4d0 | 4607 | Check_Restriction_No_Use_Of_Attribute (N); |
4608 | ||
a29bc1d9 | 4609 | -- Ignore some selected attributes in CodePeer mode since they are not |
4610 | -- relevant in this context. | |
4611 | ||
4612 | if CodePeer_Mode then | |
4613 | case Id is | |
4614 | ||
4615 | -- Ignore Component_Size in CodePeer mode, to avoid changing the | |
4616 | -- internal representation of types by implicitly packing them. | |
4617 | ||
4618 | when Attribute_Component_Size => | |
4619 | Rewrite (N, Make_Null_Statement (Sloc (N))); | |
4620 | return; | |
4621 | ||
4622 | when others => | |
4623 | null; | |
4624 | end case; | |
4625 | end if; | |
4626 | ||
d8ba53a8 | 4627 | -- Process Ignore_Rep_Clauses option |
eef1ca1e | 4628 | |
d8ba53a8 | 4629 | if Ignore_Rep_Clauses then |
9d627c41 | 4630 | case Id is |
4631 | ||
eef1ca1e | 4632 | -- The following should be ignored. They do not affect legality |
4633 | -- and may be target dependent. The basic idea of -gnatI is to | |
4634 | -- ignore any rep clauses that may be target dependent but do not | |
4635 | -- affect legality (except possibly to be rejected because they | |
4636 | -- are incompatible with the compilation target). | |
9d627c41 | 4637 | |
99378362 | 4638 | when Attribute_Alignment |
4639 | | Attribute_Bit_Order | |
4640 | | Attribute_Component_Size | |
4641 | | Attribute_Machine_Radix | |
4642 | | Attribute_Object_Size | |
4643 | | Attribute_Size | |
4644 | | Attribute_Small | |
4645 | | Attribute_Stream_Size | |
4646 | | Attribute_Value_Size | |
4647 | => | |
2ff55065 | 4648 | Kill_Rep_Clause (N); |
9d627c41 | 4649 | return; |
4650 | ||
eef1ca1e | 4651 | -- The following should not be ignored, because in the first place |
51fa2a45 | 4652 | -- they are reasonably portable, and should not cause problems |
4653 | -- in compiling code from another target, and also they do affect | |
4654 | -- legality, e.g. failing to provide a stream attribute for a type | |
4655 | -- may make a program illegal. | |
9d627c41 | 4656 | |
99378362 | 4657 | when Attribute_External_Tag |
4658 | | Attribute_Input | |
4659 | | Attribute_Output | |
4660 | | Attribute_Read | |
4661 | | Attribute_Simple_Storage_Pool | |
4662 | | Attribute_Storage_Pool | |
4663 | | Attribute_Storage_Size | |
4664 | | Attribute_Write | |
4665 | => | |
9d627c41 | 4666 | null; |
4667 | ||
2ff55065 | 4668 | -- We do not do anything here with address clauses, they will be |
4669 | -- removed by Freeze later on, but for now, it works better to | |
4670 | -- keep then in the tree. | |
4671 | ||
4672 | when Attribute_Address => | |
4673 | null; | |
4674 | ||
b593a52c | 4675 | -- Other cases are errors ("attribute& cannot be set with |
4676 | -- definition clause"), which will be caught below. | |
9d627c41 | 4677 | |
4678 | when others => | |
4679 | null; | |
4680 | end case; | |
fbc67f84 | 4681 | end if; |
4682 | ||
d6f39728 | 4683 | Analyze (Nam); |
4684 | Ent := Entity (Nam); | |
4685 | ||
4686 | if Rep_Item_Too_Early (Ent, N) then | |
4687 | return; | |
4688 | end if; | |
4689 | ||
9f373bb8 | 4690 | -- Rep clause applies to full view of incomplete type or private type if |
4691 | -- we have one (if not, this is a premature use of the type). However, | |
4692 | -- certain semantic checks need to be done on the specified entity (i.e. | |
4693 | -- the private view), so we save it in Ent. | |
d6f39728 | 4694 | |
4695 | if Is_Private_Type (Ent) | |
4696 | and then Is_Derived_Type (Ent) | |
4697 | and then not Is_Tagged_Type (Ent) | |
4698 | and then No (Full_View (Ent)) | |
4699 | then | |
9f373bb8 | 4700 | -- If this is a private type whose completion is a derivation from |
4701 | -- another private type, there is no full view, and the attribute | |
4702 | -- belongs to the type itself, not its underlying parent. | |
d6f39728 | 4703 | |
4704 | U_Ent := Ent; | |
4705 | ||
4706 | elsif Ekind (Ent) = E_Incomplete_Type then | |
d5b349fa | 4707 | |
9f373bb8 | 4708 | -- The attribute applies to the full view, set the entity of the |
4709 | -- attribute definition accordingly. | |
d5b349fa | 4710 | |
d6f39728 | 4711 | Ent := Underlying_Type (Ent); |
4712 | U_Ent := Ent; | |
d5b349fa | 4713 | Set_Entity (Nam, Ent); |
4714 | ||
d6f39728 | 4715 | else |
4716 | U_Ent := Underlying_Type (Ent); | |
4717 | end if; | |
4718 | ||
44705307 | 4719 | -- Avoid cascaded error |
d6f39728 | 4720 | |
4721 | if Etype (Nam) = Any_Type then | |
4722 | return; | |
4723 | ||
89f1e35c | 4724 | -- Must be declared in current scope or in case of an aspect |
ace3389d | 4725 | -- specification, must be visible in current scope. |
44705307 | 4726 | |
89f1e35c | 4727 | elsif Scope (Ent) /= Current_Scope |
ace3389d | 4728 | and then |
4729 | not (From_Aspect_Specification (N) | |
4730 | and then Scope_Within_Or_Same (Current_Scope, Scope (Ent))) | |
89f1e35c | 4731 | then |
d6f39728 | 4732 | Error_Msg_N ("entity must be declared in this scope", Nam); |
4733 | return; | |
4734 | ||
44705307 | 4735 | -- Must not be a source renaming (we do have some cases where the |
4736 | -- expander generates a renaming, and those cases are OK, in such | |
a3248fc4 | 4737 | -- cases any attribute applies to the renamed object as well). |
44705307 | 4738 | |
4739 | elsif Is_Object (Ent) | |
4740 | and then Present (Renamed_Object (Ent)) | |
44705307 | 4741 | then |
a3248fc4 | 4742 | -- Case of renamed object from source, this is an error |
4743 | ||
4744 | if Comes_From_Source (Renamed_Object (Ent)) then | |
4745 | Get_Name_String (Chars (N)); | |
4746 | Error_Msg_Strlen := Name_Len; | |
4747 | Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); | |
4748 | Error_Msg_N | |
4749 | ("~ clause not allowed for a renaming declaration " | |
4750 | & "(RM 13.1(6))", Nam); | |
4751 | return; | |
4752 | ||
4753 | -- For the case of a compiler generated renaming, the attribute | |
4754 | -- definition clause applies to the renamed object created by the | |
4755 | -- expander. The easiest general way to handle this is to create a | |
4756 | -- copy of the attribute definition clause for this object. | |
4757 | ||
9a48fc56 | 4758 | elsif Is_Entity_Name (Renamed_Object (Ent)) then |
a3248fc4 | 4759 | Insert_Action (N, |
4760 | Make_Attribute_Definition_Clause (Loc, | |
4761 | Name => | |
4762 | New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc), | |
4763 | Chars => Chars (N), | |
4764 | Expression => Duplicate_Subexpr (Expression (N)))); | |
9a48fc56 | 4765 | |
4766 | -- If the renamed object is not an entity, it must be a dereference | |
4767 | -- of an unconstrained function call, and we must introduce a new | |
4768 | -- declaration to capture the expression. This is needed in the case | |
4769 | -- of 'Alignment, where the original declaration must be rewritten. | |
4770 | ||
4771 | else | |
4772 | pragma Assert | |
4773 | (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference); | |
4774 | null; | |
a3248fc4 | 4775 | end if; |
44705307 | 4776 | |
4777 | -- If no underlying entity, use entity itself, applies to some | |
4778 | -- previously detected error cases ??? | |
4779 | ||
f15731c4 | 4780 | elsif No (U_Ent) then |
4781 | U_Ent := Ent; | |
4782 | ||
44705307 | 4783 | -- Cannot specify for a subtype (exception Object/Value_Size) |
4784 | ||
d6f39728 | 4785 | elsif Is_Type (U_Ent) |
4786 | and then not Is_First_Subtype (U_Ent) | |
4787 | and then Id /= Attribute_Object_Size | |
4788 | and then Id /= Attribute_Value_Size | |
4789 | and then not From_At_Mod (N) | |
4790 | then | |
4791 | Error_Msg_N ("cannot specify attribute for subtype", Nam); | |
4792 | return; | |
d6f39728 | 4793 | end if; |
4794 | ||
ae888dbd | 4795 | Set_Entity (N, U_Ent); |
4796 | ||
d6f39728 | 4797 | -- Switch on particular attribute |
4798 | ||
4799 | case Id is | |
4800 | ||
4801 | ------------- | |
4802 | -- Address -- | |
4803 | ------------- | |
4804 | ||
4805 | -- Address attribute definition clause | |
4806 | ||
4807 | when Attribute_Address => Address : begin | |
177675a7 | 4808 | |
4809 | -- A little error check, catch for X'Address use X'Address; | |
4810 | ||
4811 | if Nkind (Nam) = N_Identifier | |
4812 | and then Nkind (Expr) = N_Attribute_Reference | |
4813 | and then Attribute_Name (Expr) = Name_Address | |
4814 | and then Nkind (Prefix (Expr)) = N_Identifier | |
4815 | and then Chars (Nam) = Chars (Prefix (Expr)) | |
4816 | then | |
4817 | Error_Msg_NE | |
4818 | ("address for & is self-referencing", Prefix (Expr), Ent); | |
4819 | return; | |
4820 | end if; | |
4821 | ||
4822 | -- Not that special case, carry on with analysis of expression | |
4823 | ||
d6f39728 | 4824 | Analyze_And_Resolve (Expr, RTE (RE_Address)); |
4825 | ||
2f1aac99 | 4826 | -- Even when ignoring rep clauses we need to indicate that the |
4827 | -- entity has an address clause and thus it is legal to declare | |
2ff55065 | 4828 | -- it imported. Freeze will get rid of the address clause later. |
2f1aac99 | 4829 | |
4830 | if Ignore_Rep_Clauses then | |
d3ef794c | 4831 | if Ekind_In (U_Ent, E_Variable, E_Constant) then |
2f1aac99 | 4832 | Record_Rep_Item (U_Ent, N); |
4833 | end if; | |
4834 | ||
4835 | return; | |
4836 | end if; | |
4837 | ||
ae888dbd | 4838 | if Duplicate_Clause then |
4839 | null; | |
d6f39728 | 4840 | |
4841 | -- Case of address clause for subprogram | |
4842 | ||
4843 | elsif Is_Subprogram (U_Ent) then | |
d6f39728 | 4844 | if Has_Homonym (U_Ent) then |
4845 | Error_Msg_N | |
f74a102b | 4846 | ("address clause cannot be given for overloaded " |
4847 | & "subprogram", Nam); | |
83f8f0a6 | 4848 | return; |
d6f39728 | 4849 | end if; |
4850 | ||
83f8f0a6 | 4851 | -- For subprograms, all address clauses are permitted, and we |
4852 | -- mark the subprogram as having a deferred freeze so that Gigi | |
4853 | -- will not elaborate it too soon. | |
d6f39728 | 4854 | |
4855 | -- Above needs more comments, what is too soon about??? | |
4856 | ||
4857 | Set_Has_Delayed_Freeze (U_Ent); | |
4858 | ||
4859 | -- Case of address clause for entry | |
4860 | ||
4861 | elsif Ekind (U_Ent) = E_Entry then | |
d6f39728 | 4862 | if Nkind (Parent (N)) = N_Task_Body then |
4863 | Error_Msg_N | |
4864 | ("entry address must be specified in task spec", Nam); | |
83f8f0a6 | 4865 | return; |
d6f39728 | 4866 | end if; |
4867 | ||
4868 | -- For entries, we require a constant address | |
4869 | ||
4870 | Check_Constant_Address_Clause (Expr, U_Ent); | |
4871 | ||
83f8f0a6 | 4872 | -- Special checks for task types |
4873 | ||
f15731c4 | 4874 | if Is_Task_Type (Scope (U_Ent)) |
4875 | and then Comes_From_Source (Scope (U_Ent)) | |
4876 | then | |
4877 | Error_Msg_N | |
1e3532e7 | 4878 | ("??entry address declared for entry in task type", N); |
f15731c4 | 4879 | Error_Msg_N |
1e3532e7 | 4880 | ("\??only one task can be declared of this type", N); |
f15731c4 | 4881 | end if; |
4882 | ||
83f8f0a6 | 4883 | -- Entry address clauses are obsolescent |
4884 | ||
e0521a36 | 4885 | Check_Restriction (No_Obsolescent_Features, N); |
4886 | ||
9dfe12ae | 4887 | if Warn_On_Obsolescent_Feature then |
4888 | Error_Msg_N | |
f74a102b | 4889 | ("?j?attaching interrupt to task entry is an obsolescent " |
4890 | & "feature (RM J.7.1)", N); | |
9dfe12ae | 4891 | Error_Msg_N |
1e3532e7 | 4892 | ("\?j?use interrupt procedure instead", N); |
9dfe12ae | 4893 | end if; |
4894 | ||
8c252f6f | 4895 | -- Case of an address clause for a class-wide object, which is |
5110559b | 4896 | -- considered erroneous. |
4897 | ||
4898 | elsif Is_Class_Wide_Type (Etype (U_Ent)) then | |
4899 | Error_Msg_NE | |
4900 | ("??class-wide object & must not be overlaid", Nam, U_Ent); | |
9dfe12ae | 4901 | Error_Msg_N |
1e3532e7 | 4902 | ("\??Program_Error will be raised at run time", Nam); |
9dfe12ae | 4903 | Insert_Action (Declaration_Node (U_Ent), |
4904 | Make_Raise_Program_Error (Loc, | |
4905 | Reason => PE_Overlaid_Controlled_Object)); | |
83f8f0a6 | 4906 | return; |
9dfe12ae | 4907 | |
76be83f9 | 4908 | -- Case of address clause for an object |
d6f39728 | 4909 | |
76be83f9 | 4910 | elsif Ekind_In (U_Ent, E_Constant, E_Variable) then |
d6f39728 | 4911 | declare |
d6da7448 | 4912 | Expr : constant Node_Id := Expression (N); |
4913 | O_Ent : Entity_Id; | |
4914 | Off : Boolean; | |
d6f39728 | 4915 | |
4916 | begin | |
7ee315cc | 4917 | -- Exported variables cannot have an address clause, because |
4918 | -- this cancels the effect of the pragma Export. | |
d6f39728 | 4919 | |
4920 | if Is_Exported (U_Ent) then | |
4921 | Error_Msg_N | |
4922 | ("cannot export object with address clause", Nam); | |
83f8f0a6 | 4923 | return; |
d6da7448 | 4924 | end if; |
4925 | ||
4926 | Find_Overlaid_Entity (N, O_Ent, Off); | |
d6f39728 | 4927 | |
a9dd889b | 4928 | if Present (O_Ent) then |
798dec73 | 4929 | |
a9dd889b | 4930 | -- If the object overlays a constant object, mark it so |
b2d32174 | 4931 | |
a9dd889b | 4932 | if Is_Constant_Object (O_Ent) then |
4933 | Set_Overlays_Constant (U_Ent); | |
4934 | end if; | |
798dec73 | 4935 | |
514a5555 | 4936 | -- If the address clause is of the form: |
4937 | ||
4938 | -- for X'Address use Y'Address; | |
4939 | ||
4940 | -- or | |
4941 | ||
4942 | -- C : constant Address := Y'Address; | |
4943 | -- ... | |
4944 | -- for X'Address use C; | |
4945 | ||
4946 | -- then we make an entry in the table to check the size | |
4947 | -- and alignment of the overlaying variable. But we defer | |
4948 | -- this check till after code generation to take full | |
4949 | -- advantage of the annotation done by the back end. | |
4950 | ||
4951 | -- If the entity has a generic type, the check will be | |
4952 | -- performed in the instance if the actual type justifies | |
4953 | -- it, and we do not insert the clause in the table to | |
4954 | -- prevent spurious warnings. | |
4955 | ||
4956 | -- Note: we used to test Comes_From_Source and only give | |
4957 | -- this warning for source entities, but we have removed | |
4958 | -- this test. It really seems bogus to generate overlays | |
4959 | -- that would trigger this warning in generated code. | |
4960 | -- Furthermore, by removing the test, we handle the | |
4961 | -- aspect case properly. | |
4962 | ||
4963 | if Is_Object (O_Ent) | |
4964 | and then not Is_Generic_Type (Etype (U_Ent)) | |
4965 | and then Address_Clause_Overlay_Warnings | |
4966 | then | |
4967 | Address_Clause_Checks.Append | |
4968 | ((N, U_Ent, No_Uint, O_Ent, Off)); | |
4969 | end if; | |
a9dd889b | 4970 | else |
4971 | -- If this is not an overlay, mark a variable as being | |
4972 | -- volatile to prevent unwanted optimizations. It's a | |
4973 | -- conservative interpretation of RM 13.3(19) for the | |
4974 | -- cases where the compiler cannot detect potential | |
4975 | -- aliasing issues easily and it also covers the case | |
4976 | -- of an absolute address where the volatile aspect is | |
4977 | -- kind of implicit. | |
4978 | ||
4979 | if Ekind (U_Ent) = E_Variable then | |
4980 | Set_Treat_As_Volatile (U_Ent); | |
4981 | end if; | |
514a5555 | 4982 | |
4983 | -- Make an entry in the table for an absolute address as | |
4984 | -- above to check that the value is compatible with the | |
4985 | -- alignment of the object. | |
4986 | ||
4987 | declare | |
4988 | Addr : constant Node_Id := Address_Value (Expr); | |
4989 | begin | |
4990 | if Compile_Time_Known_Value (Addr) | |
4991 | and then Address_Clause_Overlay_Warnings | |
4992 | then | |
4993 | Address_Clause_Checks.Append | |
4994 | ((N, U_Ent, Expr_Value (Addr), Empty, False)); | |
4995 | end if; | |
4996 | end; | |
b2d32174 | 4997 | end if; |
4998 | ||
95009d64 | 4999 | -- Issue an unconditional warning for a constant overlaying |
5000 | -- a variable. For the reverse case, we will issue it only | |
b2d32174 | 5001 | -- if the variable is modified. |
95009d64 | 5002 | |
76be83f9 | 5003 | if Ekind (U_Ent) = E_Constant |
95009d64 | 5004 | and then Present (O_Ent) |
b2d32174 | 5005 | and then not Overlays_Constant (U_Ent) |
5006 | and then Address_Clause_Overlay_Warnings | |
9dfe12ae | 5007 | then |
1e3532e7 | 5008 | Error_Msg_N ("??constant overlays a variable", Expr); |
9dfe12ae | 5009 | |
d6f39728 | 5010 | -- Imported variables can have an address clause, but then |
5011 | -- the import is pretty meaningless except to suppress | |
5012 | -- initializations, so we do not need such variables to | |
5013 | -- be statically allocated (and in fact it causes trouble | |
5014 | -- if the address clause is a local value). | |
5015 | ||
5016 | elsif Is_Imported (U_Ent) then | |
5017 | Set_Is_Statically_Allocated (U_Ent, False); | |
5018 | end if; | |
5019 | ||
5020 | -- We mark a possible modification of a variable with an | |
5021 | -- address clause, since it is likely aliasing is occurring. | |
5022 | ||
177675a7 | 5023 | Note_Possible_Modification (Nam, Sure => False); |
d6f39728 | 5024 | |
9dfe12ae | 5025 | -- Legality checks on the address clause for initialized |
5026 | -- objects is deferred until the freeze point, because | |
2beb22b1 | 5027 | -- a subsequent pragma might indicate that the object |
42e09e36 | 5028 | -- is imported and thus not initialized. Also, the address |
5029 | -- clause might involve entities that have yet to be | |
5030 | -- elaborated. | |
9dfe12ae | 5031 | |
5032 | Set_Has_Delayed_Freeze (U_Ent); | |
5033 | ||
51ad5ad2 | 5034 | -- If an initialization call has been generated for this |
5035 | -- object, it needs to be deferred to after the freeze node | |
5036 | -- we have just now added, otherwise GIGI will see a | |
5037 | -- reference to the variable (as actual to the IP call) | |
5038 | -- before its definition. | |
5039 | ||
5040 | declare | |
df9fba45 | 5041 | Init_Call : constant Node_Id := |
5042 | Remove_Init_Call (U_Ent, N); | |
4bba0a8d | 5043 | |
51ad5ad2 | 5044 | begin |
5045 | if Present (Init_Call) then | |
28a4283c | 5046 | Append_Freeze_Action (U_Ent, Init_Call); |
df9fba45 | 5047 | |
28a4283c | 5048 | -- Reset Initialization_Statements pointer so that |
5049 | -- if there is a pragma Import further down, it can | |
5050 | -- clear any default initialization. | |
df9fba45 | 5051 | |
28a4283c | 5052 | Set_Initialization_Statements (U_Ent, Init_Call); |
51ad5ad2 | 5053 | end if; |
5054 | end; | |
5055 | ||
44e4341e | 5056 | -- Entity has delayed freeze, so we will generate an |
5057 | -- alignment check at the freeze point unless suppressed. | |
d6f39728 | 5058 | |
44e4341e | 5059 | if not Range_Checks_Suppressed (U_Ent) |
5060 | and then not Alignment_Checks_Suppressed (U_Ent) | |
5061 | then | |
5062 | Set_Check_Address_Alignment (N); | |
5063 | end if; | |
d6f39728 | 5064 | |
5065 | -- Kill the size check code, since we are not allocating | |
5066 | -- the variable, it is somewhere else. | |
5067 | ||
5068 | Kill_Size_Check_Code (U_Ent); | |
d6da7448 | 5069 | end; |
83f8f0a6 | 5070 | |
d6f39728 | 5071 | -- Not a valid entity for an address clause |
5072 | ||
5073 | else | |
5074 | Error_Msg_N ("address cannot be given for &", Nam); | |
5075 | end if; | |
5076 | end Address; | |
5077 | ||
5078 | --------------- | |
5079 | -- Alignment -- | |
5080 | --------------- | |
5081 | ||
5082 | -- Alignment attribute definition clause | |
5083 | ||
b47769f0 | 5084 | when Attribute_Alignment => Alignment : declare |
208fd589 | 5085 | Align : constant Uint := Get_Alignment_Value (Expr); |
5086 | Max_Align : constant Uint := UI_From_Int (Maximum_Alignment); | |
41331dcf | 5087 | |
d6f39728 | 5088 | begin |
5089 | FOnly := True; | |
5090 | ||
5091 | if not Is_Type (U_Ent) | |
5092 | and then Ekind (U_Ent) /= E_Variable | |
5093 | and then Ekind (U_Ent) /= E_Constant | |
5094 | then | |
5095 | Error_Msg_N ("alignment cannot be given for &", Nam); | |
5096 | ||
ae888dbd | 5097 | elsif Duplicate_Clause then |
5098 | null; | |
d6f39728 | 5099 | |
5100 | elsif Align /= No_Uint then | |
5101 | Set_Has_Alignment_Clause (U_Ent); | |
208fd589 | 5102 | |
44705307 | 5103 | -- Tagged type case, check for attempt to set alignment to a |
f74a102b | 5104 | -- value greater than Max_Align, and reset if so. This error |
5105 | -- is suppressed in ASIS mode to allow for different ASIS | |
f9906591 | 5106 | -- back ends or ASIS-based tools to query the illegal clause. |
44705307 | 5107 | |
f74a102b | 5108 | if Is_Tagged_Type (U_Ent) |
5109 | and then Align > Max_Align | |
5110 | and then not ASIS_Mode | |
5111 | then | |
208fd589 | 5112 | Error_Msg_N |
1e3532e7 | 5113 | ("alignment for & set to Maximum_Aligment??", Nam); |
f74a102b | 5114 | Set_Alignment (U_Ent, Max_Align); |
44705307 | 5115 | |
5116 | -- All other cases | |
5117 | ||
208fd589 | 5118 | else |
5119 | Set_Alignment (U_Ent, Align); | |
5120 | end if; | |
b47769f0 | 5121 | |
5122 | -- For an array type, U_Ent is the first subtype. In that case, | |
5123 | -- also set the alignment of the anonymous base type so that | |
5124 | -- other subtypes (such as the itypes for aggregates of the | |
5125 | -- type) also receive the expected alignment. | |
5126 | ||
5127 | if Is_Array_Type (U_Ent) then | |
5128 | Set_Alignment (Base_Type (U_Ent), Align); | |
5129 | end if; | |
d6f39728 | 5130 | end if; |
b47769f0 | 5131 | end Alignment; |
d6f39728 | 5132 | |
5133 | --------------- | |
5134 | -- Bit_Order -- | |
5135 | --------------- | |
5136 | ||
5137 | -- Bit_Order attribute definition clause | |
5138 | ||
99378362 | 5139 | when Attribute_Bit_Order => |
d6f39728 | 5140 | if not Is_Record_Type (U_Ent) then |
5141 | Error_Msg_N | |
5142 | ("Bit_Order can only be defined for record type", Nam); | |
5143 | ||
ae888dbd | 5144 | elsif Duplicate_Clause then |
5145 | null; | |
5146 | ||
d6f39728 | 5147 | else |
5148 | Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); | |
5149 | ||
5150 | if Etype (Expr) = Any_Type then | |
5151 | return; | |
5152 | ||
cda40848 | 5153 | elsif not Is_OK_Static_Expression (Expr) then |
9dfe12ae | 5154 | Flag_Non_Static_Expr |
5155 | ("Bit_Order requires static expression!", Expr); | |
d6f39728 | 5156 | |
5157 | else | |
5158 | if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then | |
fae4ea1f | 5159 | Set_Reverse_Bit_Order (Base_Type (U_Ent), True); |
d6f39728 | 5160 | end if; |
5161 | end if; | |
5162 | end if; | |
d6f39728 | 5163 | |
5164 | -------------------- | |
5165 | -- Component_Size -- | |
5166 | -------------------- | |
5167 | ||
5168 | -- Component_Size attribute definition clause | |
5169 | ||
5170 | when Attribute_Component_Size => Component_Size_Case : declare | |
5171 | Csize : constant Uint := Static_Integer (Expr); | |
a0fc8c5b | 5172 | Ctyp : Entity_Id; |
d6f39728 | 5173 | Btype : Entity_Id; |
5174 | Biased : Boolean; | |
5175 | New_Ctyp : Entity_Id; | |
5176 | Decl : Node_Id; | |
5177 | ||
5178 | begin | |
5179 | if not Is_Array_Type (U_Ent) then | |
5180 | Error_Msg_N ("component size requires array type", Nam); | |
5181 | return; | |
5182 | end if; | |
5183 | ||
5184 | Btype := Base_Type (U_Ent); | |
f74a102b | 5185 | Ctyp := Component_Type (Btype); |
d6f39728 | 5186 | |
ae888dbd | 5187 | if Duplicate_Clause then |
5188 | null; | |
d6f39728 | 5189 | |
f3e4db96 | 5190 | elsif Rep_Item_Too_Early (Btype, N) then |
5191 | null; | |
5192 | ||
d6f39728 | 5193 | elsif Csize /= No_Uint then |
a0fc8c5b | 5194 | Check_Size (Expr, Ctyp, Csize, Biased); |
d6f39728 | 5195 | |
d74fc39a | 5196 | -- For the biased case, build a declaration for a subtype that |
5197 | -- will be used to represent the biased subtype that reflects | |
5198 | -- the biased representation of components. We need the subtype | |
5199 | -- to get proper conversions on referencing elements of the | |
36ac5fbb | 5200 | -- array. |
3062c401 | 5201 | |
36ac5fbb | 5202 | if Biased then |
5203 | New_Ctyp := | |
5204 | Make_Defining_Identifier (Loc, | |
5205 | Chars => | |
5206 | New_External_Name (Chars (U_Ent), 'C', 0, 'T')); | |
3062c401 | 5207 | |
36ac5fbb | 5208 | Decl := |
5209 | Make_Subtype_Declaration (Loc, | |
5210 | Defining_Identifier => New_Ctyp, | |
5211 | Subtype_Indication => | |
5212 | New_Occurrence_Of (Component_Type (Btype), Loc)); | |
5213 | ||
5214 | Set_Parent (Decl, N); | |
5215 | Analyze (Decl, Suppress => All_Checks); | |
5216 | ||
5217 | Set_Has_Delayed_Freeze (New_Ctyp, False); | |
5218 | Set_Esize (New_Ctyp, Csize); | |
5219 | Set_RM_Size (New_Ctyp, Csize); | |
5220 | Init_Alignment (New_Ctyp); | |
5221 | Set_Is_Itype (New_Ctyp, True); | |
5222 | Set_Associated_Node_For_Itype (New_Ctyp, U_Ent); | |
5223 | ||
5224 | Set_Component_Type (Btype, New_Ctyp); | |
5225 | Set_Biased (New_Ctyp, N, "component size clause"); | |
d6f39728 | 5226 | end if; |
5227 | ||
36ac5fbb | 5228 | Set_Component_Size (Btype, Csize); |
5229 | ||
a0fc8c5b | 5230 | -- Deal with warning on overridden size |
5231 | ||
5232 | if Warn_On_Overridden_Size | |
5233 | and then Has_Size_Clause (Ctyp) | |
5234 | and then RM_Size (Ctyp) /= Csize | |
5235 | then | |
5236 | Error_Msg_NE | |
1e3532e7 | 5237 | ("component size overrides size clause for&?S?", N, Ctyp); |
a0fc8c5b | 5238 | end if; |
5239 | ||
d6f39728 | 5240 | Set_Has_Component_Size_Clause (Btype, True); |
f3e4db96 | 5241 | Set_Has_Non_Standard_Rep (Btype, True); |
d6f39728 | 5242 | end if; |
5243 | end Component_Size_Case; | |
5244 | ||
81b424ac | 5245 | ----------------------- |
5246 | -- Constant_Indexing -- | |
5247 | ----------------------- | |
5248 | ||
5249 | when Attribute_Constant_Indexing => | |
5250 | Check_Indexing_Functions; | |
5251 | ||
89f1e35c | 5252 | --------- |
5253 | -- CPU -- | |
5254 | --------- | |
5255 | ||
99378362 | 5256 | when Attribute_CPU => |
5257 | ||
89f1e35c | 5258 | -- CPU attribute definition clause not allowed except from aspect |
5259 | -- specification. | |
5260 | ||
5261 | if From_Aspect_Specification (N) then | |
5262 | if not Is_Task_Type (U_Ent) then | |
5263 | Error_Msg_N ("CPU can only be defined for task", Nam); | |
5264 | ||
5265 | elsif Duplicate_Clause then | |
5266 | null; | |
5267 | ||
5268 | else | |
5269 | -- The expression must be analyzed in the special manner | |
5270 | -- described in "Handling of Default and Per-Object | |
5271 | -- Expressions" in sem.ads. | |
5272 | ||
5273 | -- The visibility to the discriminants must be restored | |
5274 | ||
5275 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5276 | Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range)); | |
5277 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
5278 | ||
cda40848 | 5279 | if not Is_OK_Static_Expression (Expr) then |
89f1e35c | 5280 | Check_Restriction (Static_Priorities, Expr); |
5281 | end if; | |
5282 | end if; | |
5283 | ||
5284 | else | |
5285 | Error_Msg_N | |
5286 | ("attribute& cannot be set with definition clause", N); | |
5287 | end if; | |
89f1e35c | 5288 | |
89cc7147 | 5289 | ---------------------- |
5290 | -- Default_Iterator -- | |
5291 | ---------------------- | |
5292 | ||
5293 | when Attribute_Default_Iterator => Default_Iterator : declare | |
5294 | Func : Entity_Id; | |
fbf4d6ef | 5295 | Typ : Entity_Id; |
89cc7147 | 5296 | |
5297 | begin | |
05f6f999 | 5298 | -- If target type is untagged, further checks are irrelevant |
5299 | ||
89cc7147 | 5300 | if not Is_Tagged_Type (U_Ent) then |
5301 | Error_Msg_N | |
05f6f999 | 5302 | ("aspect Default_Iterator applies to tagged type", Nam); |
5303 | return; | |
89cc7147 | 5304 | end if; |
5305 | ||
5306 | Check_Iterator_Functions; | |
5307 | ||
5308 | Analyze (Expr); | |
5309 | ||
5310 | if not Is_Entity_Name (Expr) | |
5311 | or else Ekind (Entity (Expr)) /= E_Function | |
5312 | then | |
5313 | Error_Msg_N ("aspect Iterator must be a function", Expr); | |
05f6f999 | 5314 | return; |
89cc7147 | 5315 | else |
5316 | Func := Entity (Expr); | |
5317 | end if; | |
5318 | ||
fbf4d6ef | 5319 | -- The type of the first parameter must be T, T'class, or a |
05f6f999 | 5320 | -- corresponding access type (5.5.1 (8/3). If function is |
5321 | -- parameterless label type accordingly. | |
fbf4d6ef | 5322 | |
5323 | if No (First_Formal (Func)) then | |
05f6f999 | 5324 | Typ := Any_Type; |
fbf4d6ef | 5325 | else |
5326 | Typ := Etype (First_Formal (Func)); | |
5327 | end if; | |
5328 | ||
5329 | if Typ = U_Ent | |
5330 | or else Typ = Class_Wide_Type (U_Ent) | |
5331 | or else (Is_Access_Type (Typ) | |
5332 | and then Designated_Type (Typ) = U_Ent) | |
5333 | or else (Is_Access_Type (Typ) | |
5334 | and then Designated_Type (Typ) = | |
5335 | Class_Wide_Type (U_Ent)) | |
89cc7147 | 5336 | then |
fbf4d6ef | 5337 | null; |
5338 | ||
5339 | else | |
89cc7147 | 5340 | Error_Msg_NE |
5341 | ("Default Iterator must be a primitive of&", Func, U_Ent); | |
5342 | end if; | |
5343 | end Default_Iterator; | |
5344 | ||
89f1e35c | 5345 | ------------------------ |
5346 | -- Dispatching_Domain -- | |
5347 | ------------------------ | |
5348 | ||
99378362 | 5349 | when Attribute_Dispatching_Domain => |
5350 | ||
89f1e35c | 5351 | -- Dispatching_Domain attribute definition clause not allowed |
5352 | -- except from aspect specification. | |
5353 | ||
5354 | if From_Aspect_Specification (N) then | |
5355 | if not Is_Task_Type (U_Ent) then | |
fbf4d6ef | 5356 | Error_Msg_N |
5357 | ("Dispatching_Domain can only be defined for task", Nam); | |
89f1e35c | 5358 | |
5359 | elsif Duplicate_Clause then | |
5360 | null; | |
5361 | ||
5362 | else | |
5363 | -- The expression must be analyzed in the special manner | |
5364 | -- described in "Handling of Default and Per-Object | |
5365 | -- Expressions" in sem.ads. | |
5366 | ||
5367 | -- The visibility to the discriminants must be restored | |
5368 | ||
5369 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5370 | ||
5371 | Preanalyze_Spec_Expression | |
5372 | (Expr, RTE (RE_Dispatching_Domain)); | |
5373 | ||
5374 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
5375 | end if; | |
5376 | ||
5377 | else | |
5378 | Error_Msg_N | |
5379 | ("attribute& cannot be set with definition clause", N); | |
5380 | end if; | |
89f1e35c | 5381 | |
d6f39728 | 5382 | ------------------ |
5383 | -- External_Tag -- | |
5384 | ------------------ | |
5385 | ||
99378362 | 5386 | when Attribute_External_Tag => |
d6f39728 | 5387 | if not Is_Tagged_Type (U_Ent) then |
5388 | Error_Msg_N ("should be a tagged type", Nam); | |
5389 | end if; | |
5390 | ||
ae888dbd | 5391 | if Duplicate_Clause then |
5392 | null; | |
d6f39728 | 5393 | |
9af0ddc7 | 5394 | else |
ae888dbd | 5395 | Analyze_And_Resolve (Expr, Standard_String); |
fbc67f84 | 5396 | |
cda40848 | 5397 | if not Is_OK_Static_Expression (Expr) then |
ae888dbd | 5398 | Flag_Non_Static_Expr |
5399 | ("static string required for tag name!", Nam); | |
5400 | end if; | |
5401 | ||
ae888dbd | 5402 | if not Is_Library_Level_Entity (U_Ent) then |
5403 | Error_Msg_NE | |
1e3532e7 | 5404 | ("??non-unique external tag supplied for &", N, U_Ent); |
ae888dbd | 5405 | Error_Msg_N |
f74a102b | 5406 | ("\??same external tag applies to all subprogram calls", |
5407 | N); | |
ae888dbd | 5408 | Error_Msg_N |
1e3532e7 | 5409 | ("\??corresponding internal tag cannot be obtained", N); |
ae888dbd | 5410 | end if; |
fbc67f84 | 5411 | end if; |
d6f39728 | 5412 | |
b57530b8 | 5413 | -------------------------- |
5414 | -- Implicit_Dereference -- | |
5415 | -------------------------- | |
7947a439 | 5416 | |
b57530b8 | 5417 | when Attribute_Implicit_Dereference => |
7947a439 | 5418 | |
2beb22b1 | 5419 | -- Legality checks already performed at the point of the type |
5420 | -- declaration, aspect is not delayed. | |
7947a439 | 5421 | |
89cc7147 | 5422 | null; |
b57530b8 | 5423 | |
d6f39728 | 5424 | ----------- |
5425 | -- Input -- | |
5426 | ----------- | |
5427 | ||
9f373bb8 | 5428 | when Attribute_Input => |
5429 | Analyze_Stream_TSS_Definition (TSS_Stream_Input); | |
5430 | Set_Has_Specified_Stream_Input (Ent); | |
d6f39728 | 5431 | |
89f1e35c | 5432 | ------------------------ |
5433 | -- Interrupt_Priority -- | |
5434 | ------------------------ | |
5435 | ||
99378362 | 5436 | when Attribute_Interrupt_Priority => |
5437 | ||
89f1e35c | 5438 | -- Interrupt_Priority attribute definition clause not allowed |
5439 | -- except from aspect specification. | |
5440 | ||
5441 | if From_Aspect_Specification (N) then | |
f02a9a9a | 5442 | if not Is_Concurrent_Type (U_Ent) then |
89f1e35c | 5443 | Error_Msg_N |
f74a102b | 5444 | ("Interrupt_Priority can only be defined for task and " |
5445 | & "protected object", Nam); | |
89f1e35c | 5446 | |
5447 | elsif Duplicate_Clause then | |
5448 | null; | |
5449 | ||
5450 | else | |
5451 | -- The expression must be analyzed in the special manner | |
5452 | -- described in "Handling of Default and Per-Object | |
5453 | -- Expressions" in sem.ads. | |
5454 | ||
5455 | -- The visibility to the discriminants must be restored | |
5456 | ||
5457 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5458 | ||
5459 | Preanalyze_Spec_Expression | |
5460 | (Expr, RTE (RE_Interrupt_Priority)); | |
5461 | ||
5462 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
d4e1acfa | 5463 | |
5464 | -- Check the No_Task_At_Interrupt_Priority restriction | |
5465 | ||
5466 | if Is_Task_Type (U_Ent) then | |
5467 | Check_Restriction (No_Task_At_Interrupt_Priority, N); | |
5468 | end if; | |
89f1e35c | 5469 | end if; |
5470 | ||
5471 | else | |
5472 | Error_Msg_N | |
5473 | ("attribute& cannot be set with definition clause", N); | |
5474 | end if; | |
89f1e35c | 5475 | |
b3f8228a | 5476 | -------------- |
5477 | -- Iterable -- | |
5478 | -------------- | |
5479 | ||
5480 | when Attribute_Iterable => | |
5481 | Analyze (Expr); | |
bde03454 | 5482 | |
b3f8228a | 5483 | if Nkind (Expr) /= N_Aggregate then |
5484 | Error_Msg_N ("aspect Iterable must be an aggregate", Expr); | |
5485 | end if; | |
5486 | ||
5487 | declare | |
5488 | Assoc : Node_Id; | |
5489 | ||
5490 | begin | |
5491 | Assoc := First (Component_Associations (Expr)); | |
5492 | while Present (Assoc) loop | |
5493 | if not Is_Entity_Name (Expression (Assoc)) then | |
5494 | Error_Msg_N ("value must be a function", Assoc); | |
5495 | end if; | |
bde03454 | 5496 | |
b3f8228a | 5497 | Next (Assoc); |
5498 | end loop; | |
5499 | end; | |
5500 | ||
89cc7147 | 5501 | ---------------------- |
5502 | -- Iterator_Element -- | |
5503 | ---------------------- | |
5504 | ||
5505 | when Attribute_Iterator_Element => | |
5506 | Analyze (Expr); | |
5507 | ||
5508 | if not Is_Entity_Name (Expr) | |
5509 | or else not Is_Type (Entity (Expr)) | |
5510 | then | |
5511 | Error_Msg_N ("aspect Iterator_Element must be a type", Expr); | |
5512 | end if; | |
5513 | ||
d6f39728 | 5514 | ------------------- |
5515 | -- Machine_Radix -- | |
5516 | ------------------- | |
5517 | ||
5518 | -- Machine radix attribute definition clause | |
5519 | ||
5520 | when Attribute_Machine_Radix => Machine_Radix : declare | |
5521 | Radix : constant Uint := Static_Integer (Expr); | |
5522 | ||
5523 | begin | |
5524 | if not Is_Decimal_Fixed_Point_Type (U_Ent) then | |
5525 | Error_Msg_N ("decimal fixed-point type expected for &", Nam); | |
5526 | ||
ae888dbd | 5527 | elsif Duplicate_Clause then |
5528 | null; | |
d6f39728 | 5529 | |
5530 | elsif Radix /= No_Uint then | |
5531 | Set_Has_Machine_Radix_Clause (U_Ent); | |
5532 | Set_Has_Non_Standard_Rep (Base_Type (U_Ent)); | |
5533 | ||
5534 | if Radix = 2 then | |
5535 | null; | |
f74a102b | 5536 | |
d6f39728 | 5537 | elsif Radix = 10 then |
5538 | Set_Machine_Radix_10 (U_Ent); | |
f74a102b | 5539 | |
5540 | -- The following error is suppressed in ASIS mode to allow for | |
f9906591 | 5541 | -- different ASIS back ends or ASIS-based tools to query the |
f74a102b | 5542 | -- illegal clause. |
5543 | ||
5544 | elsif not ASIS_Mode then | |
d6f39728 | 5545 | Error_Msg_N ("machine radix value must be 2 or 10", Expr); |
5546 | end if; | |
5547 | end if; | |
5548 | end Machine_Radix; | |
5549 | ||
5550 | ----------------- | |
5551 | -- Object_Size -- | |
5552 | ----------------- | |
5553 | ||
5554 | -- Object_Size attribute definition clause | |
5555 | ||
5556 | when Attribute_Object_Size => Object_Size : declare | |
bfa5a9d9 | 5557 | Size : constant Uint := Static_Integer (Expr); |
5558 | ||
d6f39728 | 5559 | Biased : Boolean; |
bfa5a9d9 | 5560 | pragma Warnings (Off, Biased); |
d6f39728 | 5561 | |
5562 | begin | |
5563 | if not Is_Type (U_Ent) then | |
5564 | Error_Msg_N ("Object_Size cannot be given for &", Nam); | |
5565 | ||
ae888dbd | 5566 | elsif Duplicate_Clause then |
5567 | null; | |
d6f39728 | 5568 | |
5569 | else | |
5570 | Check_Size (Expr, U_Ent, Size, Biased); | |
5571 | ||
f74a102b | 5572 | -- The following errors are suppressed in ASIS mode to allow |
f9906591 | 5573 | -- for different ASIS back ends or ASIS-based tools to query |
f74a102b | 5574 | -- the illegal clause. |
5575 | ||
5576 | if ASIS_Mode then | |
5577 | null; | |
5578 | ||
5579 | elsif Is_Scalar_Type (U_Ent) then | |
829cd457 | 5580 | if Size /= 8 and then Size /= 16 and then Size /= 32 |
5581 | and then UI_Mod (Size, 64) /= 0 | |
5582 | then | |
5583 | Error_Msg_N | |
5584 | ("Object_Size must be 8, 16, 32, or multiple of 64", | |
5585 | Expr); | |
5586 | end if; | |
5587 | ||
5588 | elsif Size mod 8 /= 0 then | |
5589 | Error_Msg_N ("Object_Size must be a multiple of 8", Expr); | |
d6f39728 | 5590 | end if; |
5591 | ||
5592 | Set_Esize (U_Ent, Size); | |
5593 | Set_Has_Object_Size_Clause (U_Ent); | |
1d366b32 | 5594 | Alignment_Check_For_Size_Change (U_Ent, Size); |
d6f39728 | 5595 | end if; |
5596 | end Object_Size; | |
5597 | ||
5598 | ------------ | |
5599 | -- Output -- | |
5600 | ------------ | |
5601 | ||
9f373bb8 | 5602 | when Attribute_Output => |
5603 | Analyze_Stream_TSS_Definition (TSS_Stream_Output); | |
5604 | Set_Has_Specified_Stream_Output (Ent); | |
d6f39728 | 5605 | |
89f1e35c | 5606 | -------------- |
5607 | -- Priority -- | |
5608 | -------------- | |
5609 | ||
99378362 | 5610 | when Attribute_Priority => |
5611 | ||
89f1e35c | 5612 | -- Priority attribute definition clause not allowed except from |
5613 | -- aspect specification. | |
5614 | ||
5615 | if From_Aspect_Specification (N) then | |
f02a9a9a | 5616 | if not (Is_Concurrent_Type (U_Ent) |
3a72f9c3 | 5617 | or else Ekind (U_Ent) = E_Procedure) |
89f1e35c | 5618 | then |
5619 | Error_Msg_N | |
f02a9a9a | 5620 | ("Priority can only be defined for task and protected " |
5621 | & "object", Nam); | |
89f1e35c | 5622 | |
5623 | elsif Duplicate_Clause then | |
5624 | null; | |
5625 | ||
5626 | else | |
5627 | -- The expression must be analyzed in the special manner | |
5628 | -- described in "Handling of Default and Per-Object | |
5629 | -- Expressions" in sem.ads. | |
5630 | ||
5631 | -- The visibility to the discriminants must be restored | |
5632 | ||
5633 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5634 | Preanalyze_Spec_Expression (Expr, Standard_Integer); | |
5635 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
5636 | ||
cda40848 | 5637 | if not Is_OK_Static_Expression (Expr) then |
89f1e35c | 5638 | Check_Restriction (Static_Priorities, Expr); |
5639 | end if; | |
5640 | end if; | |
5641 | ||
5642 | else | |
5643 | Error_Msg_N | |
5644 | ("attribute& cannot be set with definition clause", N); | |
5645 | end if; | |
89f1e35c | 5646 | |
d6f39728 | 5647 | ---------- |
5648 | -- Read -- | |
5649 | ---------- | |
5650 | ||
9f373bb8 | 5651 | when Attribute_Read => |
5652 | Analyze_Stream_TSS_Definition (TSS_Stream_Read); | |
5653 | Set_Has_Specified_Stream_Read (Ent); | |
d6f39728 | 5654 | |
b7b74740 | 5655 | -------------------------- |
5656 | -- Scalar_Storage_Order -- | |
5657 | -------------------------- | |
5658 | ||
5659 | -- Scalar_Storage_Order attribute definition clause | |
5660 | ||
99378362 | 5661 | when Attribute_Scalar_Storage_Order => |
b43a5770 | 5662 | if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then |
b7b74740 | 5663 | Error_Msg_N |
f74a102b | 5664 | ("Scalar_Storage_Order can only be defined for record or " |
5665 | & "array type", Nam); | |
b7b74740 | 5666 | |
5667 | elsif Duplicate_Clause then | |
5668 | null; | |
5669 | ||
5670 | else | |
5671 | Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); | |
5672 | ||
5673 | if Etype (Expr) = Any_Type then | |
5674 | return; | |
5675 | ||
cda40848 | 5676 | elsif not Is_OK_Static_Expression (Expr) then |
b7b74740 | 5677 | Flag_Non_Static_Expr |
5678 | ("Scalar_Storage_Order requires static expression!", Expr); | |
5679 | ||
c0912570 | 5680 | elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then |
5681 | ||
5682 | -- Here for the case of a non-default (i.e. non-confirming) | |
5683 | -- Scalar_Storage_Order attribute definition. | |
5684 | ||
5685 | if Support_Nondefault_SSO_On_Target then | |
d0a9ea3b | 5686 | Set_Reverse_Storage_Order (Base_Type (U_Ent), True); |
c0912570 | 5687 | else |
5688 | Error_Msg_N | |
f74a102b | 5689 | ("non-default Scalar_Storage_Order not supported on " |
5690 | & "target", Expr); | |
b7b74740 | 5691 | end if; |
5692 | end if; | |
b64082f2 | 5693 | |
5694 | -- Clear SSO default indications since explicit setting of the | |
5695 | -- order overrides the defaults. | |
5696 | ||
5697 | Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False); | |
5698 | Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False); | |
b7b74740 | 5699 | end if; |
b7b74740 | 5700 | |
e6ce0468 | 5701 | -------------------------- |
5702 | -- Secondary_Stack_Size -- | |
5703 | -------------------------- | |
5704 | ||
99378362 | 5705 | when Attribute_Secondary_Stack_Size => |
5706 | ||
e6ce0468 | 5707 | -- Secondary_Stack_Size attribute definition clause not allowed |
5708 | -- except from aspect specification. | |
5709 | ||
5710 | if From_Aspect_Specification (N) then | |
5711 | if not Is_Task_Type (U_Ent) then | |
fe696bd7 | 5712 | Error_Msg_N |
5713 | ("Secondary Stack Size can only be defined for task", Nam); | |
e6ce0468 | 5714 | |
5715 | elsif Duplicate_Clause then | |
5716 | null; | |
5717 | ||
5718 | else | |
5719 | Check_Restriction (No_Secondary_Stack, Expr); | |
5720 | ||
5721 | -- The expression must be analyzed in the special manner | |
5722 | -- described in "Handling of Default and Per-Object | |
5723 | -- Expressions" in sem.ads. | |
5724 | ||
5725 | -- The visibility to the discriminants must be restored | |
5726 | ||
5727 | Push_Scope_And_Install_Discriminants (U_Ent); | |
5728 | Preanalyze_Spec_Expression (Expr, Any_Integer); | |
5729 | Uninstall_Discriminants_And_Pop_Scope (U_Ent); | |
5730 | ||
5731 | if not Is_OK_Static_Expression (Expr) then | |
5732 | Check_Restriction (Static_Storage_Size, Expr); | |
5733 | end if; | |
5734 | end if; | |
5735 | ||
5736 | else | |
5737 | Error_Msg_N | |
5738 | ("attribute& cannot be set with definition clause", N); | |
5739 | end if; | |
e6ce0468 | 5740 | |
d6f39728 | 5741 | ---------- |
5742 | -- Size -- | |
5743 | ---------- | |
5744 | ||
5745 | -- Size attribute definition clause | |
5746 | ||
5747 | when Attribute_Size => Size : declare | |
5748 | Size : constant Uint := Static_Integer (Expr); | |
5749 | Etyp : Entity_Id; | |
5750 | Biased : Boolean; | |
5751 | ||
5752 | begin | |
5753 | FOnly := True; | |
5754 | ||
ae888dbd | 5755 | if Duplicate_Clause then |
5756 | null; | |
d6f39728 | 5757 | |
5758 | elsif not Is_Type (U_Ent) | |
5759 | and then Ekind (U_Ent) /= E_Variable | |
5760 | and then Ekind (U_Ent) /= E_Constant | |
5761 | then | |
5762 | Error_Msg_N ("size cannot be given for &", Nam); | |
5763 | ||
5764 | elsif Is_Array_Type (U_Ent) | |
5765 | and then not Is_Constrained (U_Ent) | |
5766 | then | |
5767 | Error_Msg_N | |
5768 | ("size cannot be given for unconstrained array", Nam); | |
5769 | ||
c2b89d6e | 5770 | elsif Size /= No_Uint then |
d6f39728 | 5771 | if Is_Type (U_Ent) then |
5772 | Etyp := U_Ent; | |
5773 | else | |
5774 | Etyp := Etype (U_Ent); | |
5775 | end if; | |
5776 | ||
59ac57b5 | 5777 | -- Check size, note that Gigi is in charge of checking that the |
5778 | -- size of an array or record type is OK. Also we do not check | |
5779 | -- the size in the ordinary fixed-point case, since it is too | |
5780 | -- early to do so (there may be subsequent small clause that | |
5781 | -- affects the size). We can check the size if a small clause | |
5782 | -- has already been given. | |
d6f39728 | 5783 | |
5784 | if not Is_Ordinary_Fixed_Point_Type (U_Ent) | |
5785 | or else Has_Small_Clause (U_Ent) | |
5786 | then | |
5787 | Check_Size (Expr, Etyp, Size, Biased); | |
b77e4501 | 5788 | Set_Biased (U_Ent, N, "size clause", Biased); |
d6f39728 | 5789 | end if; |
5790 | ||
5791 | -- For types set RM_Size and Esize if possible | |
5792 | ||
5793 | if Is_Type (U_Ent) then | |
5794 | Set_RM_Size (U_Ent, Size); | |
5795 | ||
ada34def | 5796 | -- For elementary types, increase Object_Size to power of 2, |
5797 | -- but not less than a storage unit in any case (normally | |
59ac57b5 | 5798 | -- this means it will be byte addressable). |
d6f39728 | 5799 | |
ada34def | 5800 | -- For all other types, nothing else to do, we leave Esize |
5801 | -- (object size) unset, the back end will set it from the | |
5802 | -- size and alignment in an appropriate manner. | |
5803 | ||
1d366b32 | 5804 | -- In both cases, we check whether the alignment must be |
5805 | -- reset in the wake of the size change. | |
5806 | ||
ada34def | 5807 | if Is_Elementary_Type (U_Ent) then |
f15731c4 | 5808 | if Size <= System_Storage_Unit then |
5809 | Init_Esize (U_Ent, System_Storage_Unit); | |
d6f39728 | 5810 | elsif Size <= 16 then |
5811 | Init_Esize (U_Ent, 16); | |
5812 | elsif Size <= 32 then | |
5813 | Init_Esize (U_Ent, 32); | |
5814 | else | |
5815 | Set_Esize (U_Ent, (Size + 63) / 64 * 64); | |
5816 | end if; | |
5817 | ||
1d366b32 | 5818 | Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent)); |
5819 | else | |
5820 | Alignment_Check_For_Size_Change (U_Ent, Size); | |
d6f39728 | 5821 | end if; |
5822 | ||
d6f39728 | 5823 | -- For objects, set Esize only |
5824 | ||
5825 | else | |
f74a102b | 5826 | -- The following error is suppressed in ASIS mode to allow |
f9906591 | 5827 | -- for different ASIS back ends or ASIS-based tools to query |
f74a102b | 5828 | -- the illegal clause. |
5829 | ||
5830 | if Is_Elementary_Type (Etyp) | |
5831 | and then Size /= System_Storage_Unit | |
5832 | and then Size /= System_Storage_Unit * 2 | |
5833 | and then Size /= System_Storage_Unit * 4 | |
5834 | and then Size /= System_Storage_Unit * 8 | |
5835 | and then not ASIS_Mode | |
5836 | then | |
5837 | Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); | |
5838 | Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8; | |
5839 | Error_Msg_N | |
5840 | ("size for primitive object must be a power of 2 in " | |
5841 | & "the range ^-^", N); | |
9dfe12ae | 5842 | end if; |
5843 | ||
d6f39728 | 5844 | Set_Esize (U_Ent, Size); |
5845 | end if; | |
5846 | ||
5847 | Set_Has_Size_Clause (U_Ent); | |
5848 | end if; | |
5849 | end Size; | |
5850 | ||
5851 | ----------- | |
5852 | -- Small -- | |
5853 | ----------- | |
5854 | ||
5855 | -- Small attribute definition clause | |
5856 | ||
5857 | when Attribute_Small => Small : declare | |
5858 | Implicit_Base : constant Entity_Id := Base_Type (U_Ent); | |
5859 | Small : Ureal; | |
5860 | ||
5861 | begin | |
5862 | Analyze_And_Resolve (Expr, Any_Real); | |
5863 | ||
5864 | if Etype (Expr) = Any_Type then | |
5865 | return; | |
5866 | ||
cda40848 | 5867 | elsif not Is_OK_Static_Expression (Expr) then |
9dfe12ae | 5868 | Flag_Non_Static_Expr |
5869 | ("small requires static expression!", Expr); | |
d6f39728 | 5870 | return; |
5871 | ||
5872 | else | |
5873 | Small := Expr_Value_R (Expr); | |
5874 | ||
5875 | if Small <= Ureal_0 then | |
5876 | Error_Msg_N ("small value must be greater than zero", Expr); | |
5877 | return; | |
5878 | end if; | |
5879 | ||
5880 | end if; | |
5881 | ||
5882 | if not Is_Ordinary_Fixed_Point_Type (U_Ent) then | |
5883 | Error_Msg_N | |
5884 | ("small requires an ordinary fixed point type", Nam); | |
5885 | ||
5886 | elsif Has_Small_Clause (U_Ent) then | |
5887 | Error_Msg_N ("small already given for &", Nam); | |
5888 | ||
5889 | elsif Small > Delta_Value (U_Ent) then | |
5890 | Error_Msg_N | |
ce3e25d6 | 5891 | ("small value must not be greater than delta value", Nam); |
d6f39728 | 5892 | |
5893 | else | |
5894 | Set_Small_Value (U_Ent, Small); | |
5895 | Set_Small_Value (Implicit_Base, Small); | |
5896 | Set_Has_Small_Clause (U_Ent); | |
5897 | Set_Has_Small_Clause (Implicit_Base); | |
5898 | Set_Has_Non_Standard_Rep (Implicit_Base); | |
5899 | end if; | |
5900 | end Small; | |
5901 | ||
d6f39728 | 5902 | ------------------ |
5903 | -- Storage_Pool -- | |
5904 | ------------------ | |
5905 | ||
5906 | -- Storage_Pool attribute definition clause | |
5907 | ||
99378362 | 5908 | when Attribute_Simple_Storage_Pool |
5909 | | Attribute_Storage_Pool | |
5910 | => | |
5911 | Storage_Pool : declare | |
d6f39728 | 5912 | Pool : Entity_Id; |
6b567c71 | 5913 | T : Entity_Id; |
d6f39728 | 5914 | |
5915 | begin | |
44e4341e | 5916 | if Ekind (U_Ent) = E_Access_Subprogram_Type then |
5917 | Error_Msg_N | |
5918 | ("storage pool cannot be given for access-to-subprogram type", | |
5919 | Nam); | |
5920 | return; | |
5921 | ||
99378362 | 5922 | elsif not Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type) |
d6f39728 | 5923 | then |
44e4341e | 5924 | Error_Msg_N |
5925 | ("storage pool can only be given for access types", Nam); | |
d6f39728 | 5926 | return; |
5927 | ||
5928 | elsif Is_Derived_Type (U_Ent) then | |
5929 | Error_Msg_N | |
5930 | ("storage pool cannot be given for a derived access type", | |
5931 | Nam); | |
5932 | ||
ae888dbd | 5933 | elsif Duplicate_Clause then |
d6f39728 | 5934 | return; |
5935 | ||
5936 | elsif Present (Associated_Storage_Pool (U_Ent)) then | |
5937 | Error_Msg_N ("storage pool already given for &", Nam); | |
5938 | return; | |
5939 | end if; | |
5940 | ||
6653b695 | 5941 | -- Check for Storage_Size previously given |
5942 | ||
5943 | declare | |
5944 | SS : constant Node_Id := | |
5945 | Get_Attribute_Definition_Clause | |
5946 | (U_Ent, Attribute_Storage_Size); | |
5947 | begin | |
5948 | if Present (SS) then | |
5949 | Check_Pool_Size_Clash (U_Ent, N, SS); | |
5950 | end if; | |
5951 | end; | |
5952 | ||
5953 | -- Storage_Pool case | |
5954 | ||
b55f7641 | 5955 | if Id = Attribute_Storage_Pool then |
5956 | Analyze_And_Resolve | |
5957 | (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool))); | |
5958 | ||
5959 | -- In the Simple_Storage_Pool case, we allow a variable of any | |
b15003c3 | 5960 | -- simple storage pool type, so we Resolve without imposing an |
b55f7641 | 5961 | -- expected type. |
5962 | ||
5963 | else | |
5964 | Analyze_And_Resolve (Expr); | |
5965 | ||
5966 | if not Present (Get_Rep_Pragma | |
b15003c3 | 5967 | (Etype (Expr), Name_Simple_Storage_Pool_Type)) |
b55f7641 | 5968 | then |
5969 | Error_Msg_N | |
5970 | ("expression must be of a simple storage pool type", Expr); | |
5971 | end if; | |
5972 | end if; | |
d6f39728 | 5973 | |
8c5c7277 | 5974 | if not Denotes_Variable (Expr) then |
5975 | Error_Msg_N ("storage pool must be a variable", Expr); | |
5976 | return; | |
5977 | end if; | |
5978 | ||
6b567c71 | 5979 | if Nkind (Expr) = N_Type_Conversion then |
5980 | T := Etype (Expression (Expr)); | |
5981 | else | |
5982 | T := Etype (Expr); | |
5983 | end if; | |
5984 | ||
5985 | -- The Stack_Bounded_Pool is used internally for implementing | |
d64221a7 | 5986 | -- access types with a Storage_Size. Since it only work properly |
5987 | -- when used on one specific type, we need to check that it is not | |
5988 | -- hijacked improperly: | |
5989 | ||
6b567c71 | 5990 | -- type T is access Integer; |
5991 | -- for T'Storage_Size use n; | |
5992 | -- type Q is access Float; | |
5993 | -- for Q'Storage_Size use T'Storage_Size; -- incorrect | |
5994 | ||
15ebb600 | 5995 | if RTE_Available (RE_Stack_Bounded_Pool) |
5996 | and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool) | |
5997 | then | |
5998 | Error_Msg_N ("non-shareable internal Pool", Expr); | |
6b567c71 | 5999 | return; |
6000 | end if; | |
6001 | ||
d6f39728 | 6002 | -- If the argument is a name that is not an entity name, then |
6003 | -- we construct a renaming operation to define an entity of | |
6004 | -- type storage pool. | |
6005 | ||
6006 | if not Is_Entity_Name (Expr) | |
6007 | and then Is_Object_Reference (Expr) | |
6008 | then | |
11deeeb6 | 6009 | Pool := Make_Temporary (Loc, 'P', Expr); |
d6f39728 | 6010 | |
6011 | declare | |
6012 | Rnode : constant Node_Id := | |
6013 | Make_Object_Renaming_Declaration (Loc, | |
6014 | Defining_Identifier => Pool, | |
6015 | Subtype_Mark => | |
6016 | New_Occurrence_Of (Etype (Expr), Loc), | |
11deeeb6 | 6017 | Name => Expr); |
d6f39728 | 6018 | |
6019 | begin | |
f65f7fdf | 6020 | -- If the attribute definition clause comes from an aspect |
6021 | -- clause, then insert the renaming before the associated | |
6022 | -- entity's declaration, since the attribute clause has | |
6023 | -- not yet been appended to the declaration list. | |
6024 | ||
6025 | if From_Aspect_Specification (N) then | |
6026 | Insert_Before (Parent (Entity (N)), Rnode); | |
6027 | else | |
6028 | Insert_Before (N, Rnode); | |
6029 | end if; | |
6030 | ||
d6f39728 | 6031 | Analyze (Rnode); |
6032 | Set_Associated_Storage_Pool (U_Ent, Pool); | |
6033 | end; | |
6034 | ||
6035 | elsif Is_Entity_Name (Expr) then | |
6036 | Pool := Entity (Expr); | |
6037 | ||
6038 | -- If pool is a renamed object, get original one. This can | |
6039 | -- happen with an explicit renaming, and within instances. | |
6040 | ||
6041 | while Present (Renamed_Object (Pool)) | |
6042 | and then Is_Entity_Name (Renamed_Object (Pool)) | |
6043 | loop | |
6044 | Pool := Entity (Renamed_Object (Pool)); | |
6045 | end loop; | |
6046 | ||
6047 | if Present (Renamed_Object (Pool)) | |
6048 | and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion | |
6049 | and then Is_Entity_Name (Expression (Renamed_Object (Pool))) | |
6050 | then | |
6051 | Pool := Entity (Expression (Renamed_Object (Pool))); | |
6052 | end if; | |
6053 | ||
6b567c71 | 6054 | Set_Associated_Storage_Pool (U_Ent, Pool); |
d6f39728 | 6055 | |
6056 | elsif Nkind (Expr) = N_Type_Conversion | |
6057 | and then Is_Entity_Name (Expression (Expr)) | |
6058 | and then Nkind (Original_Node (Expr)) = N_Attribute_Reference | |
6059 | then | |
6060 | Pool := Entity (Expression (Expr)); | |
6b567c71 | 6061 | Set_Associated_Storage_Pool (U_Ent, Pool); |
d6f39728 | 6062 | |
6063 | else | |
6064 | Error_Msg_N ("incorrect reference to a Storage Pool", Expr); | |
6065 | return; | |
6066 | end if; | |
99378362 | 6067 | end Storage_Pool; |
d6f39728 | 6068 | |
44e4341e | 6069 | ------------------ |
6070 | -- Storage_Size -- | |
6071 | ------------------ | |
6072 | ||
6073 | -- Storage_Size attribute definition clause | |
6074 | ||
6075 | when Attribute_Storage_Size => Storage_Size : declare | |
6076 | Btype : constant Entity_Id := Base_Type (U_Ent); | |
44e4341e | 6077 | |
6078 | begin | |
6079 | if Is_Task_Type (U_Ent) then | |
44e4341e | 6080 | |
39a0c1d3 | 6081 | -- Check obsolescent (but never obsolescent if from aspect) |
ceec4f7c | 6082 | |
6083 | if not From_Aspect_Specification (N) then | |
6084 | Check_Restriction (No_Obsolescent_Features, N); | |
6085 | ||
6086 | if Warn_On_Obsolescent_Feature then | |
6087 | Error_Msg_N | |
f74a102b | 6088 | ("?j?storage size clause for task is an obsolescent " |
6089 | & "feature (RM J.9)", N); | |
ceec4f7c | 6090 | Error_Msg_N ("\?j?use Storage_Size pragma instead", N); |
6091 | end if; | |
44e4341e | 6092 | end if; |
6093 | ||
6094 | FOnly := True; | |
6095 | end if; | |
6096 | ||
6097 | if not Is_Access_Type (U_Ent) | |
6098 | and then Ekind (U_Ent) /= E_Task_Type | |
6099 | then | |
6100 | Error_Msg_N ("storage size cannot be given for &", Nam); | |
6101 | ||
6102 | elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then | |
6103 | Error_Msg_N | |
6104 | ("storage size cannot be given for a derived access type", | |
6105 | Nam); | |
6106 | ||
ae888dbd | 6107 | elsif Duplicate_Clause then |
6108 | null; | |
44e4341e | 6109 | |
6110 | else | |
6111 | Analyze_And_Resolve (Expr, Any_Integer); | |
6112 | ||
6113 | if Is_Access_Type (U_Ent) then | |
6653b695 | 6114 | |
6115 | -- Check for Storage_Pool previously given | |
6116 | ||
6117 | declare | |
6118 | SP : constant Node_Id := | |
6119 | Get_Attribute_Definition_Clause | |
6120 | (U_Ent, Attribute_Storage_Pool); | |
6121 | ||
6122 | begin | |
6123 | if Present (SP) then | |
6124 | Check_Pool_Size_Clash (U_Ent, SP, N); | |
6125 | end if; | |
6126 | end; | |
6127 | ||
6128 | -- Special case of for x'Storage_Size use 0 | |
44e4341e | 6129 | |
5941a4e9 | 6130 | if Is_OK_Static_Expression (Expr) |
44e4341e | 6131 | and then Expr_Value (Expr) = 0 |
6132 | then | |
6133 | Set_No_Pool_Assigned (Btype); | |
6134 | end if; | |
44e4341e | 6135 | end if; |
6136 | ||
6137 | Set_Has_Storage_Size_Clause (Btype); | |
6138 | end if; | |
6139 | end Storage_Size; | |
6140 | ||
7189d17f | 6141 | ----------------- |
6142 | -- Stream_Size -- | |
6143 | ----------------- | |
6144 | ||
6145 | when Attribute_Stream_Size => Stream_Size : declare | |
6146 | Size : constant Uint := Static_Integer (Expr); | |
6147 | ||
6148 | begin | |
15ebb600 | 6149 | if Ada_Version <= Ada_95 then |
6150 | Check_Restriction (No_Implementation_Attributes, N); | |
6151 | end if; | |
6152 | ||
ae888dbd | 6153 | if Duplicate_Clause then |
6154 | null; | |
7189d17f | 6155 | |
6156 | elsif Is_Elementary_Type (U_Ent) then | |
f74a102b | 6157 | |
6158 | -- The following errors are suppressed in ASIS mode to allow | |
f9906591 | 6159 | -- for different ASIS back ends or ASIS-based tools to query |
f74a102b | 6160 | -- the illegal clause. |
6161 | ||
6162 | if ASIS_Mode then | |
6163 | null; | |
6164 | ||
6165 | elsif Size /= System_Storage_Unit | |
6166 | and then Size /= System_Storage_Unit * 2 | |
6167 | and then Size /= System_Storage_Unit * 4 | |
6168 | and then Size /= System_Storage_Unit * 8 | |
7189d17f | 6169 | then |
6170 | Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); | |
6171 | Error_Msg_N | |
f74a102b | 6172 | ("stream size for elementary type must be a power of 2 " |
6173 | & "and at least ^", N); | |
7189d17f | 6174 | |
6175 | elsif RM_Size (U_Ent) > Size then | |
6176 | Error_Msg_Uint_1 := RM_Size (U_Ent); | |
6177 | Error_Msg_N | |
f74a102b | 6178 | ("stream size for elementary type must be a power of 2 " |
6179 | & "and at least ^", N); | |
7189d17f | 6180 | end if; |
6181 | ||
6182 | Set_Has_Stream_Size_Clause (U_Ent); | |
6183 | ||
6184 | else | |
6185 | Error_Msg_N ("Stream_Size cannot be given for &", Nam); | |
6186 | end if; | |
6187 | end Stream_Size; | |
6188 | ||
d6f39728 | 6189 | ---------------- |
6190 | -- Value_Size -- | |
6191 | ---------------- | |
6192 | ||
6193 | -- Value_Size attribute definition clause | |
6194 | ||
6195 | when Attribute_Value_Size => Value_Size : declare | |
6196 | Size : constant Uint := Static_Integer (Expr); | |
6197 | Biased : Boolean; | |
6198 | ||
6199 | begin | |
6200 | if not Is_Type (U_Ent) then | |
6201 | Error_Msg_N ("Value_Size cannot be given for &", Nam); | |
6202 | ||
ae888dbd | 6203 | elsif Duplicate_Clause then |
6204 | null; | |
d6f39728 | 6205 | |
59ac57b5 | 6206 | elsif Is_Array_Type (U_Ent) |
6207 | and then not Is_Constrained (U_Ent) | |
6208 | then | |
6209 | Error_Msg_N | |
6210 | ("Value_Size cannot be given for unconstrained array", Nam); | |
6211 | ||
d6f39728 | 6212 | else |
6213 | if Is_Elementary_Type (U_Ent) then | |
6214 | Check_Size (Expr, U_Ent, Size, Biased); | |
b77e4501 | 6215 | Set_Biased (U_Ent, N, "value size clause", Biased); |
d6f39728 | 6216 | end if; |
6217 | ||
6218 | Set_RM_Size (U_Ent, Size); | |
6219 | end if; | |
6220 | end Value_Size; | |
6221 | ||
81b424ac | 6222 | ----------------------- |
6223 | -- Variable_Indexing -- | |
6224 | ----------------------- | |
6225 | ||
6226 | when Attribute_Variable_Indexing => | |
6227 | Check_Indexing_Functions; | |
6228 | ||
d6f39728 | 6229 | ----------- |
6230 | -- Write -- | |
6231 | ----------- | |
6232 | ||
9f373bb8 | 6233 | when Attribute_Write => |
6234 | Analyze_Stream_TSS_Definition (TSS_Stream_Write); | |
6235 | Set_Has_Specified_Stream_Write (Ent); | |
d6f39728 | 6236 | |
6237 | -- All other attributes cannot be set | |
6238 | ||
6239 | when others => | |
6240 | Error_Msg_N | |
6241 | ("attribute& cannot be set with definition clause", N); | |
d6f39728 | 6242 | end case; |
6243 | ||
d64221a7 | 6244 | -- The test for the type being frozen must be performed after any |
6245 | -- expression the clause has been analyzed since the expression itself | |
6246 | -- might cause freezing that makes the clause illegal. | |
d6f39728 | 6247 | |
6248 | if Rep_Item_Too_Late (U_Ent, N, FOnly) then | |
6249 | return; | |
6250 | end if; | |
6251 | end Analyze_Attribute_Definition_Clause; | |
6252 | ||
6253 | ---------------------------- | |
6254 | -- Analyze_Code_Statement -- | |
6255 | ---------------------------- | |
6256 | ||
6257 | procedure Analyze_Code_Statement (N : Node_Id) is | |
6258 | HSS : constant Node_Id := Parent (N); | |
6259 | SBody : constant Node_Id := Parent (HSS); | |
6260 | Subp : constant Entity_Id := Current_Scope; | |
6261 | Stmt : Node_Id; | |
6262 | Decl : Node_Id; | |
6263 | StmtO : Node_Id; | |
6264 | DeclO : Node_Id; | |
6265 | ||
6266 | begin | |
1d3f0c6b | 6267 | -- Accept foreign code statements for CodePeer. The analysis is skipped |
6268 | -- to avoid rejecting unrecognized constructs. | |
6269 | ||
6270 | if CodePeer_Mode then | |
6271 | Set_Analyzed (N); | |
6272 | return; | |
6273 | end if; | |
6274 | ||
d6f39728 | 6275 | -- Analyze and check we get right type, note that this implements the |
1d3f0c6b | 6276 | -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is |
6277 | -- the only way that Asm_Insn could possibly be visible. | |
d6f39728 | 6278 | |
6279 | Analyze_And_Resolve (Expression (N)); | |
6280 | ||
6281 | if Etype (Expression (N)) = Any_Type then | |
6282 | return; | |
6283 | elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then | |
6284 | Error_Msg_N ("incorrect type for code statement", N); | |
6285 | return; | |
6286 | end if; | |
6287 | ||
44e4341e | 6288 | Check_Code_Statement (N); |
6289 | ||
1d3f0c6b | 6290 | -- Make sure we appear in the handled statement sequence of a subprogram |
6291 | -- (RM 13.8(3)). | |
d6f39728 | 6292 | |
6293 | if Nkind (HSS) /= N_Handled_Sequence_Of_Statements | |
6294 | or else Nkind (SBody) /= N_Subprogram_Body | |
6295 | then | |
6296 | Error_Msg_N | |
6297 | ("code statement can only appear in body of subprogram", N); | |
6298 | return; | |
6299 | end if; | |
6300 | ||
6301 | -- Do remaining checks (RM 13.8(3)) if not already done | |
6302 | ||
6303 | if not Is_Machine_Code_Subprogram (Subp) then | |
6304 | Set_Is_Machine_Code_Subprogram (Subp); | |
6305 | ||
6306 | -- No exception handlers allowed | |
6307 | ||
6308 | if Present (Exception_Handlers (HSS)) then | |
6309 | Error_Msg_N | |
6310 | ("exception handlers not permitted in machine code subprogram", | |
6311 | First (Exception_Handlers (HSS))); | |
6312 | end if; | |
6313 | ||
6314 | -- No declarations other than use clauses and pragmas (we allow | |
6315 | -- certain internally generated declarations as well). | |
6316 | ||
6317 | Decl := First (Declarations (SBody)); | |
6318 | while Present (Decl) loop | |
6319 | DeclO := Original_Node (Decl); | |
6320 | if Comes_From_Source (DeclO) | |
fdd294d1 | 6321 | and not Nkind_In (DeclO, N_Pragma, |
6322 | N_Use_Package_Clause, | |
6323 | N_Use_Type_Clause, | |
6324 | N_Implicit_Label_Declaration) | |
d6f39728 | 6325 | then |
6326 | Error_Msg_N | |
6327 | ("this declaration not allowed in machine code subprogram", | |
6328 | DeclO); | |
6329 | end if; | |
6330 | ||
6331 | Next (Decl); | |
6332 | end loop; | |
6333 | ||
6334 | -- No statements other than code statements, pragmas, and labels. | |
6335 | -- Again we allow certain internally generated statements. | |
3ab42ff7 | 6336 | |
c3107527 | 6337 | -- In Ada 2012, qualified expressions are names, and the code |
6338 | -- statement is initially parsed as a procedure call. | |
d6f39728 | 6339 | |
6340 | Stmt := First (Statements (HSS)); | |
6341 | while Present (Stmt) loop | |
6342 | StmtO := Original_Node (Stmt); | |
c3107527 | 6343 | |
1d3f0c6b | 6344 | -- A procedure call transformed into a code statement is OK |
59f2fcab | 6345 | |
c3107527 | 6346 | if Ada_Version >= Ada_2012 |
6347 | and then Nkind (StmtO) = N_Procedure_Call_Statement | |
59f2fcab | 6348 | and then Nkind (Name (StmtO)) = N_Qualified_Expression |
c3107527 | 6349 | then |
6350 | null; | |
6351 | ||
6352 | elsif Comes_From_Source (StmtO) | |
fdd294d1 | 6353 | and then not Nkind_In (StmtO, N_Pragma, |
6354 | N_Label, | |
6355 | N_Code_Statement) | |
d6f39728 | 6356 | then |
6357 | Error_Msg_N | |
6358 | ("this statement is not allowed in machine code subprogram", | |
6359 | StmtO); | |
6360 | end if; | |
6361 | ||
6362 | Next (Stmt); | |
6363 | end loop; | |
6364 | end if; | |
d6f39728 | 6365 | end Analyze_Code_Statement; |
6366 | ||
6367 | ----------------------------------------------- | |
6368 | -- Analyze_Enumeration_Representation_Clause -- | |
6369 | ----------------------------------------------- | |
6370 | ||
6371 | procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is | |
21647c2d | 6372 | Ident : constant Node_Id := Identifier (N); |
6373 | Aggr : constant Node_Id := Array_Aggregate (N); | |
d6f39728 | 6374 | Enumtype : Entity_Id; |
6375 | Elit : Entity_Id; | |
6376 | Expr : Node_Id; | |
6377 | Assoc : Node_Id; | |
6378 | Choice : Node_Id; | |
6379 | Val : Uint; | |
b3190af0 | 6380 | |
6381 | Err : Boolean := False; | |
098d3082 | 6382 | -- Set True to avoid cascade errors and crashes on incorrect source code |
d6f39728 | 6383 | |
e30c7d84 | 6384 | Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer)); |
6385 | Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer)); | |
6386 | -- Allowed range of universal integer (= allowed range of enum lit vals) | |
6387 | ||
d6f39728 | 6388 | Min : Uint; |
6389 | Max : Uint; | |
e30c7d84 | 6390 | -- Minimum and maximum values of entries |
6391 | ||
6392 | Max_Node : Node_Id; | |
6393 | -- Pointer to node for literal providing max value | |
d6f39728 | 6394 | |
6395 | begin | |
ca301e17 | 6396 | if Ignore_Rep_Clauses then |
2ff55065 | 6397 | Kill_Rep_Clause (N); |
fbc67f84 | 6398 | return; |
6399 | end if; | |
6400 | ||
175a6969 | 6401 | -- Ignore enumeration rep clauses by default in CodePeer mode, |
6402 | -- unless -gnatd.I is specified, as a work around for potential false | |
6403 | -- positive messages. | |
6404 | ||
6405 | if CodePeer_Mode and not Debug_Flag_Dot_II then | |
6406 | return; | |
6407 | end if; | |
6408 | ||
d6f39728 | 6409 | -- First some basic error checks |
6410 | ||
6411 | Find_Type (Ident); | |
6412 | Enumtype := Entity (Ident); | |
6413 | ||
6414 | if Enumtype = Any_Type | |
6415 | or else Rep_Item_Too_Early (Enumtype, N) | |
6416 | then | |
6417 | return; | |
6418 | else | |
6419 | Enumtype := Underlying_Type (Enumtype); | |
6420 | end if; | |
6421 | ||
6422 | if not Is_Enumeration_Type (Enumtype) then | |
6423 | Error_Msg_NE | |
6424 | ("enumeration type required, found}", | |
6425 | Ident, First_Subtype (Enumtype)); | |
6426 | return; | |
6427 | end if; | |
6428 | ||
9dfe12ae | 6429 | -- Ignore rep clause on generic actual type. This will already have |
6430 | -- been flagged on the template as an error, and this is the safest | |
6431 | -- way to ensure we don't get a junk cascaded message in the instance. | |
6432 | ||
6433 | if Is_Generic_Actual_Type (Enumtype) then | |
6434 | return; | |
6435 | ||
6436 | -- Type must be in current scope | |
6437 | ||
6438 | elsif Scope (Enumtype) /= Current_Scope then | |
d6f39728 | 6439 | Error_Msg_N ("type must be declared in this scope", Ident); |
6440 | return; | |
6441 | ||
9dfe12ae | 6442 | -- Type must be a first subtype |
6443 | ||
d6f39728 | 6444 | elsif not Is_First_Subtype (Enumtype) then |
6445 | Error_Msg_N ("cannot give enumeration rep clause for subtype", N); | |
6446 | return; | |
6447 | ||
9dfe12ae | 6448 | -- Ignore duplicate rep clause |
6449 | ||
d6f39728 | 6450 | elsif Has_Enumeration_Rep_Clause (Enumtype) then |
6451 | Error_Msg_N ("duplicate enumeration rep clause ignored", N); | |
6452 | return; | |
6453 | ||
7189d17f | 6454 | -- Don't allow rep clause for standard [wide_[wide_]]character |
9dfe12ae | 6455 | |
177675a7 | 6456 | elsif Is_Standard_Character_Type (Enumtype) then |
d6f39728 | 6457 | Error_Msg_N ("enumeration rep clause not allowed for this type", N); |
9dfe12ae | 6458 | return; |
6459 | ||
d9125581 | 6460 | -- Check that the expression is a proper aggregate (no parentheses) |
6461 | ||
6462 | elsif Paren_Count (Aggr) /= 0 then | |
6463 | Error_Msg | |
6464 | ("extra parentheses surrounding aggregate not allowed", | |
6465 | First_Sloc (Aggr)); | |
6466 | return; | |
6467 | ||
9dfe12ae | 6468 | -- All tests passed, so set rep clause in place |
d6f39728 | 6469 | |
6470 | else | |
6471 | Set_Has_Enumeration_Rep_Clause (Enumtype); | |
6472 | Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype)); | |
6473 | end if; | |
6474 | ||
6475 | -- Now we process the aggregate. Note that we don't use the normal | |
6476 | -- aggregate code for this purpose, because we don't want any of the | |
6477 | -- normal expansion activities, and a number of special semantic | |
6478 | -- rules apply (including the component type being any integer type) | |
6479 | ||
d6f39728 | 6480 | Elit := First_Literal (Enumtype); |
6481 | ||
6482 | -- First the positional entries if any | |
6483 | ||
6484 | if Present (Expressions (Aggr)) then | |
6485 | Expr := First (Expressions (Aggr)); | |
6486 | while Present (Expr) loop | |
6487 | if No (Elit) then | |
6488 | Error_Msg_N ("too many entries in aggregate", Expr); | |
6489 | return; | |
6490 | end if; | |
6491 | ||
6492 | Val := Static_Integer (Expr); | |
6493 | ||
d9125581 | 6494 | -- Err signals that we found some incorrect entries processing |
6495 | -- the list. The final checks for completeness and ordering are | |
6496 | -- skipped in this case. | |
6497 | ||
d6f39728 | 6498 | if Val = No_Uint then |
6499 | Err := True; | |
f02a9a9a | 6500 | |
d6f39728 | 6501 | elsif Val < Lo or else Hi < Val then |
6502 | Error_Msg_N ("value outside permitted range", Expr); | |
6503 | Err := True; | |
6504 | end if; | |
6505 | ||
6506 | Set_Enumeration_Rep (Elit, Val); | |
6507 | Set_Enumeration_Rep_Expr (Elit, Expr); | |
6508 | Next (Expr); | |
6509 | Next (Elit); | |
6510 | end loop; | |
6511 | end if; | |
6512 | ||
6513 | -- Now process the named entries if present | |
6514 | ||
6515 | if Present (Component_Associations (Aggr)) then | |
6516 | Assoc := First (Component_Associations (Aggr)); | |
6517 | while Present (Assoc) loop | |
6518 | Choice := First (Choices (Assoc)); | |
6519 | ||
6520 | if Present (Next (Choice)) then | |
6521 | Error_Msg_N | |
6522 | ("multiple choice not allowed here", Next (Choice)); | |
6523 | Err := True; | |
6524 | end if; | |
6525 | ||
6526 | if Nkind (Choice) = N_Others_Choice then | |
6527 | Error_Msg_N ("others choice not allowed here", Choice); | |
6528 | Err := True; | |
6529 | ||
6530 | elsif Nkind (Choice) = N_Range then | |
b3190af0 | 6531 | |
d6f39728 | 6532 | -- ??? should allow zero/one element range here |
b3190af0 | 6533 | |
d6f39728 | 6534 | Error_Msg_N ("range not allowed here", Choice); |
6535 | Err := True; | |
6536 | ||
6537 | else | |
6538 | Analyze_And_Resolve (Choice, Enumtype); | |
b3190af0 | 6539 | |
098d3082 | 6540 | if Error_Posted (Choice) then |
d6f39728 | 6541 | Err := True; |
098d3082 | 6542 | end if; |
d6f39728 | 6543 | |
098d3082 | 6544 | if not Err then |
6545 | if Is_Entity_Name (Choice) | |
6546 | and then Is_Type (Entity (Choice)) | |
6547 | then | |
6548 | Error_Msg_N ("subtype name not allowed here", Choice); | |
d6f39728 | 6549 | Err := True; |
b3190af0 | 6550 | |
098d3082 | 6551 | -- ??? should allow static subtype with zero/one entry |
d6f39728 | 6552 | |
098d3082 | 6553 | elsif Etype (Choice) = Base_Type (Enumtype) then |
cda40848 | 6554 | if not Is_OK_Static_Expression (Choice) then |
098d3082 | 6555 | Flag_Non_Static_Expr |
6556 | ("non-static expression used for choice!", Choice); | |
d6f39728 | 6557 | Err := True; |
d6f39728 | 6558 | |
098d3082 | 6559 | else |
6560 | Elit := Expr_Value_E (Choice); | |
6561 | ||
6562 | if Present (Enumeration_Rep_Expr (Elit)) then | |
6563 | Error_Msg_Sloc := | |
6564 | Sloc (Enumeration_Rep_Expr (Elit)); | |
6565 | Error_Msg_NE | |
6566 | ("representation for& previously given#", | |
6567 | Choice, Elit); | |
6568 | Err := True; | |
6569 | end if; | |
d6f39728 | 6570 | |
098d3082 | 6571 | Set_Enumeration_Rep_Expr (Elit, Expression (Assoc)); |
d6f39728 | 6572 | |
098d3082 | 6573 | Expr := Expression (Assoc); |
6574 | Val := Static_Integer (Expr); | |
d6f39728 | 6575 | |
098d3082 | 6576 | if Val = No_Uint then |
6577 | Err := True; | |
6578 | ||
6579 | elsif Val < Lo or else Hi < Val then | |
6580 | Error_Msg_N ("value outside permitted range", Expr); | |
6581 | Err := True; | |
6582 | end if; | |
d6f39728 | 6583 | |
098d3082 | 6584 | Set_Enumeration_Rep (Elit, Val); |
6585 | end if; | |
d6f39728 | 6586 | end if; |
6587 | end if; | |
6588 | end if; | |
6589 | ||
6590 | Next (Assoc); | |
6591 | end loop; | |
6592 | end if; | |
6593 | ||
6594 | -- Aggregate is fully processed. Now we check that a full set of | |
6595 | -- representations was given, and that they are in range and in order. | |
6596 | -- These checks are only done if no other errors occurred. | |
6597 | ||
6598 | if not Err then | |
6599 | Min := No_Uint; | |
6600 | Max := No_Uint; | |
6601 | ||
6602 | Elit := First_Literal (Enumtype); | |
6603 | while Present (Elit) loop | |
6604 | if No (Enumeration_Rep_Expr (Elit)) then | |
6605 | Error_Msg_NE ("missing representation for&!", N, Elit); | |
6606 | ||
6607 | else | |
6608 | Val := Enumeration_Rep (Elit); | |
6609 | ||
6610 | if Min = No_Uint then | |
6611 | Min := Val; | |
6612 | end if; | |
6613 | ||
6614 | if Val /= No_Uint then | |
6615 | if Max /= No_Uint and then Val <= Max then | |
6616 | Error_Msg_NE | |
6617 | ("enumeration value for& not ordered!", | |
e30c7d84 | 6618 | Enumeration_Rep_Expr (Elit), Elit); |
d6f39728 | 6619 | end if; |
6620 | ||
e30c7d84 | 6621 | Max_Node := Enumeration_Rep_Expr (Elit); |
d6f39728 | 6622 | Max := Val; |
6623 | end if; | |
6624 | ||
e30c7d84 | 6625 | -- If there is at least one literal whose representation is not |
6626 | -- equal to the Pos value, then note that this enumeration type | |
6627 | -- has a non-standard representation. | |
d6f39728 | 6628 | |
6629 | if Val /= Enumeration_Pos (Elit) then | |
6630 | Set_Has_Non_Standard_Rep (Base_Type (Enumtype)); | |
6631 | end if; | |
6632 | end if; | |
6633 | ||
6634 | Next (Elit); | |
6635 | end loop; | |
6636 | ||
6637 | -- Now set proper size information | |
6638 | ||
6639 | declare | |
6640 | Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype)); | |
6641 | ||
6642 | begin | |
6643 | if Has_Size_Clause (Enumtype) then | |
e30c7d84 | 6644 | |
6645 | -- All OK, if size is OK now | |
6646 | ||
6647 | if RM_Size (Enumtype) >= Minsize then | |
d6f39728 | 6648 | null; |
6649 | ||
6650 | else | |
e30c7d84 | 6651 | -- Try if we can get by with biasing |
6652 | ||
d6f39728 | 6653 | Minsize := |
6654 | UI_From_Int (Minimum_Size (Enumtype, Biased => True)); | |
6655 | ||
e30c7d84 | 6656 | -- Error message if even biasing does not work |
6657 | ||
6658 | if RM_Size (Enumtype) < Minsize then | |
6659 | Error_Msg_Uint_1 := RM_Size (Enumtype); | |
6660 | Error_Msg_Uint_2 := Max; | |
6661 | Error_Msg_N | |
6662 | ("previously given size (^) is too small " | |
6663 | & "for this value (^)", Max_Node); | |
6664 | ||
6665 | -- If biasing worked, indicate that we now have biased rep | |
d6f39728 | 6666 | |
6667 | else | |
b77e4501 | 6668 | Set_Biased |
6669 | (Enumtype, Size_Clause (Enumtype), "size clause"); | |
d6f39728 | 6670 | end if; |
6671 | end if; | |
6672 | ||
6673 | else | |
6674 | Set_RM_Size (Enumtype, Minsize); | |
6675 | Set_Enum_Esize (Enumtype); | |
6676 | end if; | |
6677 | ||
6678 | Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype)); | |
6679 | Set_Esize (Base_Type (Enumtype), Esize (Enumtype)); | |
6680 | Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype)); | |
6681 | end; | |
6682 | end if; | |
6683 | ||
39a0c1d3 | 6684 | -- We repeat the too late test in case it froze itself |
d6f39728 | 6685 | |
6686 | if Rep_Item_Too_Late (Enumtype, N) then | |
6687 | null; | |
6688 | end if; | |
d6f39728 | 6689 | end Analyze_Enumeration_Representation_Clause; |
6690 | ||
6691 | ---------------------------- | |
6692 | -- Analyze_Free_Statement -- | |
6693 | ---------------------------- | |
6694 | ||
6695 | procedure Analyze_Free_Statement (N : Node_Id) is | |
6696 | begin | |
6697 | Analyze (Expression (N)); | |
6698 | end Analyze_Free_Statement; | |
6699 | ||
40ca69b9 | 6700 | --------------------------- |
6701 | -- Analyze_Freeze_Entity -- | |
6702 | --------------------------- | |
6703 | ||
6704 | procedure Analyze_Freeze_Entity (N : Node_Id) is | |
40ca69b9 | 6705 | begin |
d9f6a4ee | 6706 | Freeze_Entity_Checks (N); |
6707 | end Analyze_Freeze_Entity; | |
98f7db28 | 6708 | |
d9f6a4ee | 6709 | ----------------------------------- |
6710 | -- Analyze_Freeze_Generic_Entity -- | |
6711 | ----------------------------------- | |
98f7db28 | 6712 | |
d9f6a4ee | 6713 | procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is |
61989dbb | 6714 | E : constant Entity_Id := Entity (N); |
6715 | ||
d9f6a4ee | 6716 | begin |
61989dbb | 6717 | if not Is_Frozen (E) and then Has_Delayed_Aspects (E) then |
6718 | Analyze_Aspects_At_Freeze_Point (E); | |
6719 | end if; | |
6720 | ||
d9f6a4ee | 6721 | Freeze_Entity_Checks (N); |
6722 | end Analyze_Freeze_Generic_Entity; | |
40ca69b9 | 6723 | |
d9f6a4ee | 6724 | ------------------------------------------ |
6725 | -- Analyze_Record_Representation_Clause -- | |
6726 | ------------------------------------------ | |
c8da6114 | 6727 | |
d9f6a4ee | 6728 | -- Note: we check as much as we can here, but we can't do any checks |
6729 | -- based on the position values (e.g. overlap checks) until freeze time | |
6730 | -- because especially in Ada 2005 (machine scalar mode), the processing | |
6731 | -- for non-standard bit order can substantially change the positions. | |
6732 | -- See procedure Check_Record_Representation_Clause (called from Freeze) | |
6733 | -- for the remainder of this processing. | |
d00681a7 | 6734 | |
d9f6a4ee | 6735 | procedure Analyze_Record_Representation_Clause (N : Node_Id) is |
6736 | Ident : constant Node_Id := Identifier (N); | |
6737 | Biased : Boolean; | |
6738 | CC : Node_Id; | |
6739 | Comp : Entity_Id; | |
6740 | Fbit : Uint; | |
6741 | Hbit : Uint := Uint_0; | |
6742 | Lbit : Uint; | |
6743 | Ocomp : Entity_Id; | |
6744 | Posit : Uint; | |
6745 | Rectype : Entity_Id; | |
6746 | Recdef : Node_Id; | |
d00681a7 | 6747 | |
d9f6a4ee | 6748 | function Is_Inherited (Comp : Entity_Id) return Boolean; |
6749 | -- True if Comp is an inherited component in a record extension | |
d00681a7 | 6750 | |
d9f6a4ee | 6751 | ------------------ |
6752 | -- Is_Inherited -- | |
6753 | ------------------ | |
d00681a7 | 6754 | |
d9f6a4ee | 6755 | function Is_Inherited (Comp : Entity_Id) return Boolean is |
6756 | Comp_Base : Entity_Id; | |
d00681a7 | 6757 | |
d9f6a4ee | 6758 | begin |
6759 | if Ekind (Rectype) = E_Record_Subtype then | |
6760 | Comp_Base := Original_Record_Component (Comp); | |
6761 | else | |
6762 | Comp_Base := Comp; | |
d00681a7 | 6763 | end if; |
6764 | ||
d9f6a4ee | 6765 | return Comp_Base /= Original_Record_Component (Comp_Base); |
6766 | end Is_Inherited; | |
d00681a7 | 6767 | |
d9f6a4ee | 6768 | -- Local variables |
d00681a7 | 6769 | |
d9f6a4ee | 6770 | Is_Record_Extension : Boolean; |
6771 | -- True if Rectype is a record extension | |
d00681a7 | 6772 | |
d9f6a4ee | 6773 | CR_Pragma : Node_Id := Empty; |
6774 | -- Points to N_Pragma node if Complete_Representation pragma present | |
d00681a7 | 6775 | |
d9f6a4ee | 6776 | -- Start of processing for Analyze_Record_Representation_Clause |
d00681a7 | 6777 | |
d9f6a4ee | 6778 | begin |
6779 | if Ignore_Rep_Clauses then | |
2ff55065 | 6780 | Kill_Rep_Clause (N); |
d9f6a4ee | 6781 | return; |
d00681a7 | 6782 | end if; |
98f7db28 | 6783 | |
d9f6a4ee | 6784 | Find_Type (Ident); |
6785 | Rectype := Entity (Ident); | |
85377c9b | 6786 | |
d9f6a4ee | 6787 | if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then |
6788 | return; | |
6789 | else | |
6790 | Rectype := Underlying_Type (Rectype); | |
6791 | end if; | |
85377c9b | 6792 | |
d9f6a4ee | 6793 | -- First some basic error checks |
85377c9b | 6794 | |
d9f6a4ee | 6795 | if not Is_Record_Type (Rectype) then |
6796 | Error_Msg_NE | |
6797 | ("record type required, found}", Ident, First_Subtype (Rectype)); | |
6798 | return; | |
85377c9b | 6799 | |
d9f6a4ee | 6800 | elsif Scope (Rectype) /= Current_Scope then |
6801 | Error_Msg_N ("type must be declared in this scope", N); | |
6802 | return; | |
85377c9b | 6803 | |
d9f6a4ee | 6804 | elsif not Is_First_Subtype (Rectype) then |
6805 | Error_Msg_N ("cannot give record rep clause for subtype", N); | |
6806 | return; | |
9dc88aea | 6807 | |
d9f6a4ee | 6808 | elsif Has_Record_Rep_Clause (Rectype) then |
6809 | Error_Msg_N ("duplicate record rep clause ignored", N); | |
6810 | return; | |
9dc88aea | 6811 | |
d9f6a4ee | 6812 | elsif Rep_Item_Too_Late (Rectype, N) then |
6813 | return; | |
9dc88aea | 6814 | end if; |
fb7f2fc4 | 6815 | |
2ced3742 | 6816 | -- We know we have a first subtype, now possibly go to the anonymous |
d9f6a4ee | 6817 | -- base type to determine whether Rectype is a record extension. |
89f1e35c | 6818 | |
d9f6a4ee | 6819 | Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype))); |
6820 | Is_Record_Extension := | |
6821 | Nkind (Recdef) = N_Derived_Type_Definition | |
6822 | and then Present (Record_Extension_Part (Recdef)); | |
89f1e35c | 6823 | |
d9f6a4ee | 6824 | if Present (Mod_Clause (N)) then |
fb7f2fc4 | 6825 | declare |
d9f6a4ee | 6826 | Loc : constant Source_Ptr := Sloc (N); |
6827 | M : constant Node_Id := Mod_Clause (N); | |
6828 | P : constant List_Id := Pragmas_Before (M); | |
6829 | AtM_Nod : Node_Id; | |
6830 | ||
6831 | Mod_Val : Uint; | |
6832 | pragma Warnings (Off, Mod_Val); | |
fb7f2fc4 | 6833 | |
6834 | begin | |
d9f6a4ee | 6835 | Check_Restriction (No_Obsolescent_Features, Mod_Clause (N)); |
fb7f2fc4 | 6836 | |
d9f6a4ee | 6837 | if Warn_On_Obsolescent_Feature then |
6838 | Error_Msg_N | |
6839 | ("?j?mod clause is an obsolescent feature (RM J.8)", N); | |
6840 | Error_Msg_N | |
6841 | ("\?j?use alignment attribute definition clause instead", N); | |
6842 | end if; | |
fb7f2fc4 | 6843 | |
d9f6a4ee | 6844 | if Present (P) then |
6845 | Analyze_List (P); | |
6846 | end if; | |
89f1e35c | 6847 | |
d9f6a4ee | 6848 | -- In ASIS_Mode mode, expansion is disabled, but we must convert |
6849 | -- the Mod clause into an alignment clause anyway, so that the | |
3ff5e35d | 6850 | -- back end can compute and back-annotate properly the size and |
d9f6a4ee | 6851 | -- alignment of types that may include this record. |
be9124d0 | 6852 | |
d9f6a4ee | 6853 | -- This seems dubious, this destroys the source tree in a manner |
6854 | -- not detectable by ASIS ??? | |
be9124d0 | 6855 | |
d9f6a4ee | 6856 | if Operating_Mode = Check_Semantics and then ASIS_Mode then |
6857 | AtM_Nod := | |
6858 | Make_Attribute_Definition_Clause (Loc, | |
83c6c069 | 6859 | Name => New_Occurrence_Of (Base_Type (Rectype), Loc), |
d9f6a4ee | 6860 | Chars => Name_Alignment, |
6861 | Expression => Relocate_Node (Expression (M))); | |
be9124d0 | 6862 | |
d9f6a4ee | 6863 | Set_From_At_Mod (AtM_Nod); |
6864 | Insert_After (N, AtM_Nod); | |
6865 | Mod_Val := Get_Alignment_Value (Expression (AtM_Nod)); | |
6866 | Set_Mod_Clause (N, Empty); | |
be9124d0 | 6867 | |
d9f6a4ee | 6868 | else |
6869 | -- Get the alignment value to perform error checking | |
be9124d0 | 6870 | |
d9f6a4ee | 6871 | Mod_Val := Get_Alignment_Value (Expression (M)); |
6872 | end if; | |
6873 | end; | |
6874 | end if; | |
be9124d0 | 6875 | |
d9f6a4ee | 6876 | -- For untagged types, clear any existing component clauses for the |
6877 | -- type. If the type is derived, this is what allows us to override | |
6878 | -- a rep clause for the parent. For type extensions, the representation | |
6879 | -- of the inherited components is inherited, so we want to keep previous | |
6880 | -- component clauses for completeness. | |
be9124d0 | 6881 | |
d9f6a4ee | 6882 | if not Is_Tagged_Type (Rectype) then |
6883 | Comp := First_Component_Or_Discriminant (Rectype); | |
6884 | while Present (Comp) loop | |
6885 | Set_Component_Clause (Comp, Empty); | |
6886 | Next_Component_Or_Discriminant (Comp); | |
6887 | end loop; | |
6888 | end if; | |
be9124d0 | 6889 | |
d9f6a4ee | 6890 | -- All done if no component clauses |
be9124d0 | 6891 | |
d9f6a4ee | 6892 | CC := First (Component_Clauses (N)); |
be9124d0 | 6893 | |
d9f6a4ee | 6894 | if No (CC) then |
6895 | return; | |
6896 | end if; | |
be9124d0 | 6897 | |
d9f6a4ee | 6898 | -- A representation like this applies to the base type |
be9124d0 | 6899 | |
d9f6a4ee | 6900 | Set_Has_Record_Rep_Clause (Base_Type (Rectype)); |
6901 | Set_Has_Non_Standard_Rep (Base_Type (Rectype)); | |
6902 | Set_Has_Specified_Layout (Base_Type (Rectype)); | |
be9124d0 | 6903 | |
d9f6a4ee | 6904 | -- Process the component clauses |
be9124d0 | 6905 | |
d9f6a4ee | 6906 | while Present (CC) loop |
be9124d0 | 6907 | |
d9f6a4ee | 6908 | -- Pragma |
be9124d0 | 6909 | |
d9f6a4ee | 6910 | if Nkind (CC) = N_Pragma then |
6911 | Analyze (CC); | |
be9124d0 | 6912 | |
d9f6a4ee | 6913 | -- The only pragma of interest is Complete_Representation |
be9124d0 | 6914 | |
ddccc924 | 6915 | if Pragma_Name (CC) = Name_Complete_Representation then |
d9f6a4ee | 6916 | CR_Pragma := CC; |
6917 | end if; | |
be9124d0 | 6918 | |
d9f6a4ee | 6919 | -- Processing for real component clause |
be9124d0 | 6920 | |
d9f6a4ee | 6921 | else |
6922 | Posit := Static_Integer (Position (CC)); | |
6923 | Fbit := Static_Integer (First_Bit (CC)); | |
6924 | Lbit := Static_Integer (Last_Bit (CC)); | |
be9124d0 | 6925 | |
d9f6a4ee | 6926 | if Posit /= No_Uint |
6927 | and then Fbit /= No_Uint | |
6928 | and then Lbit /= No_Uint | |
6929 | then | |
6930 | if Posit < 0 then | |
f74a102b | 6931 | Error_Msg_N ("position cannot be negative", Position (CC)); |
be9124d0 | 6932 | |
d9f6a4ee | 6933 | elsif Fbit < 0 then |
f74a102b | 6934 | Error_Msg_N ("first bit cannot be negative", First_Bit (CC)); |
be9124d0 | 6935 | |
d9f6a4ee | 6936 | -- The Last_Bit specified in a component clause must not be |
6937 | -- less than the First_Bit minus one (RM-13.5.1(10)). | |
be9124d0 | 6938 | |
d9f6a4ee | 6939 | elsif Lbit < Fbit - 1 then |
6940 | Error_Msg_N | |
6941 | ("last bit cannot be less than first bit minus one", | |
6942 | Last_Bit (CC)); | |
be9124d0 | 6943 | |
d9f6a4ee | 6944 | -- Values look OK, so find the corresponding record component |
6945 | -- Even though the syntax allows an attribute reference for | |
6946 | -- implementation-defined components, GNAT does not allow the | |
6947 | -- tag to get an explicit position. | |
be9124d0 | 6948 | |
d9f6a4ee | 6949 | elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then |
6950 | if Attribute_Name (Component_Name (CC)) = Name_Tag then | |
6951 | Error_Msg_N ("position of tag cannot be specified", CC); | |
6952 | else | |
6953 | Error_Msg_N ("illegal component name", CC); | |
6954 | end if; | |
be9124d0 | 6955 | |
d9f6a4ee | 6956 | else |
6957 | Comp := First_Entity (Rectype); | |
6958 | while Present (Comp) loop | |
6959 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
6960 | Next_Entity (Comp); | |
6961 | end loop; | |
be9124d0 | 6962 | |
d9f6a4ee | 6963 | if No (Comp) then |
be9124d0 | 6964 | |
d9f6a4ee | 6965 | -- Maybe component of base type that is absent from |
6966 | -- statically constrained first subtype. | |
be9124d0 | 6967 | |
d9f6a4ee | 6968 | Comp := First_Entity (Base_Type (Rectype)); |
6969 | while Present (Comp) loop | |
6970 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
6971 | Next_Entity (Comp); | |
6972 | end loop; | |
6973 | end if; | |
be9124d0 | 6974 | |
d9f6a4ee | 6975 | if No (Comp) then |
6976 | Error_Msg_N | |
6977 | ("component clause is for non-existent field", CC); | |
be9124d0 | 6978 | |
d9f6a4ee | 6979 | -- Ada 2012 (AI05-0026): Any name that denotes a |
6980 | -- discriminant of an object of an unchecked union type | |
6981 | -- shall not occur within a record_representation_clause. | |
be9124d0 | 6982 | |
d9f6a4ee | 6983 | -- The general restriction of using record rep clauses on |
6984 | -- Unchecked_Union types has now been lifted. Since it is | |
6985 | -- possible to introduce a record rep clause which mentions | |
6986 | -- the discriminant of an Unchecked_Union in non-Ada 2012 | |
6987 | -- code, this check is applied to all versions of the | |
6988 | -- language. | |
be9124d0 | 6989 | |
d9f6a4ee | 6990 | elsif Ekind (Comp) = E_Discriminant |
6991 | and then Is_Unchecked_Union (Rectype) | |
6992 | then | |
6993 | Error_Msg_N | |
6994 | ("cannot reference discriminant of unchecked union", | |
6995 | Component_Name (CC)); | |
be9124d0 | 6996 | |
d9f6a4ee | 6997 | elsif Is_Record_Extension and then Is_Inherited (Comp) then |
6998 | Error_Msg_NE | |
6999 | ("component clause not allowed for inherited " | |
7000 | & "component&", CC, Comp); | |
40ca69b9 | 7001 | |
d9f6a4ee | 7002 | elsif Present (Component_Clause (Comp)) then |
462a079f | 7003 | |
d9f6a4ee | 7004 | -- Diagnose duplicate rep clause, or check consistency |
7005 | -- if this is an inherited component. In a double fault, | |
7006 | -- there may be a duplicate inconsistent clause for an | |
7007 | -- inherited component. | |
462a079f | 7008 | |
d9f6a4ee | 7009 | if Scope (Original_Record_Component (Comp)) = Rectype |
7010 | or else Parent (Component_Clause (Comp)) = N | |
7011 | then | |
7012 | Error_Msg_Sloc := Sloc (Component_Clause (Comp)); | |
7013 | Error_Msg_N ("component clause previously given#", CC); | |
3062c401 | 7014 | |
7015 | else | |
7016 | declare | |
7017 | Rep1 : constant Node_Id := Component_Clause (Comp); | |
3062c401 | 7018 | begin |
7019 | if Intval (Position (Rep1)) /= | |
7020 | Intval (Position (CC)) | |
7021 | or else Intval (First_Bit (Rep1)) /= | |
7022 | Intval (First_Bit (CC)) | |
7023 | or else Intval (Last_Bit (Rep1)) /= | |
7024 | Intval (Last_Bit (CC)) | |
7025 | then | |
b9e61b2a | 7026 | Error_Msg_N |
f74a102b | 7027 | ("component clause inconsistent with " |
7028 | & "representation of ancestor", CC); | |
6a06584c | 7029 | |
3062c401 | 7030 | elsif Warn_On_Redundant_Constructs then |
b9e61b2a | 7031 | Error_Msg_N |
6a06584c | 7032 | ("?r?redundant confirming component clause " |
7033 | & "for component!", CC); | |
3062c401 | 7034 | end if; |
7035 | end; | |
7036 | end if; | |
d6f39728 | 7037 | |
d2b860b4 | 7038 | -- Normal case where this is the first component clause we |
7039 | -- have seen for this entity, so set it up properly. | |
7040 | ||
d6f39728 | 7041 | else |
83f8f0a6 | 7042 | -- Make reference for field in record rep clause and set |
7043 | -- appropriate entity field in the field identifier. | |
7044 | ||
7045 | Generate_Reference | |
7046 | (Comp, Component_Name (CC), Set_Ref => False); | |
7047 | Set_Entity (Component_Name (CC), Comp); | |
7048 | ||
2866d595 | 7049 | -- Update Fbit and Lbit to the actual bit number |
d6f39728 | 7050 | |
7051 | Fbit := Fbit + UI_From_Int (SSU) * Posit; | |
7052 | Lbit := Lbit + UI_From_Int (SSU) * Posit; | |
7053 | ||
d6f39728 | 7054 | if Has_Size_Clause (Rectype) |
ada34def | 7055 | and then RM_Size (Rectype) <= Lbit |
d6f39728 | 7056 | then |
7057 | Error_Msg_N | |
7058 | ("bit number out of range of specified size", | |
7059 | Last_Bit (CC)); | |
7060 | else | |
7061 | Set_Component_Clause (Comp, CC); | |
7062 | Set_Component_Bit_Offset (Comp, Fbit); | |
7063 | Set_Esize (Comp, 1 + (Lbit - Fbit)); | |
7064 | Set_Normalized_First_Bit (Comp, Fbit mod SSU); | |
7065 | Set_Normalized_Position (Comp, Fbit / SSU); | |
7066 | ||
a0fc8c5b | 7067 | if Warn_On_Overridden_Size |
7068 | and then Has_Size_Clause (Etype (Comp)) | |
7069 | and then RM_Size (Etype (Comp)) /= Esize (Comp) | |
7070 | then | |
7071 | Error_Msg_NE | |
1e3532e7 | 7072 | ("?S?component size overrides size clause for&", |
a0fc8c5b | 7073 | Component_Name (CC), Etype (Comp)); |
7074 | end if; | |
7075 | ||
ea61a7ea | 7076 | -- This information is also set in the corresponding |
7077 | -- component of the base type, found by accessing the | |
7078 | -- Original_Record_Component link if it is present. | |
d6f39728 | 7079 | |
7080 | Ocomp := Original_Record_Component (Comp); | |
7081 | ||
7082 | if Hbit < Lbit then | |
7083 | Hbit := Lbit; | |
7084 | end if; | |
7085 | ||
7086 | Check_Size | |
7087 | (Component_Name (CC), | |
7088 | Etype (Comp), | |
7089 | Esize (Comp), | |
7090 | Biased); | |
7091 | ||
b77e4501 | 7092 | Set_Biased |
7093 | (Comp, First_Node (CC), "component clause", Biased); | |
cc46ff4b | 7094 | |
d6f39728 | 7095 | if Present (Ocomp) then |
7096 | Set_Component_Clause (Ocomp, CC); | |
7097 | Set_Component_Bit_Offset (Ocomp, Fbit); | |
7098 | Set_Normalized_First_Bit (Ocomp, Fbit mod SSU); | |
7099 | Set_Normalized_Position (Ocomp, Fbit / SSU); | |
7100 | Set_Esize (Ocomp, 1 + (Lbit - Fbit)); | |
7101 | ||
7102 | Set_Normalized_Position_Max | |
7103 | (Ocomp, Normalized_Position (Ocomp)); | |
7104 | ||
b77e4501 | 7105 | -- Note: we don't use Set_Biased here, because we |
7106 | -- already gave a warning above if needed, and we | |
7107 | -- would get a duplicate for the same name here. | |
7108 | ||
d6f39728 | 7109 | Set_Has_Biased_Representation |
7110 | (Ocomp, Has_Biased_Representation (Comp)); | |
7111 | end if; | |
7112 | ||
7113 | if Esize (Comp) < 0 then | |
7114 | Error_Msg_N ("component size is negative", CC); | |
7115 | end if; | |
7116 | end if; | |
7117 | end if; | |
7118 | end if; | |
7119 | end if; | |
7120 | end if; | |
7121 | ||
7122 | Next (CC); | |
7123 | end loop; | |
7124 | ||
67278d60 | 7125 | -- Check missing components if Complete_Representation pragma appeared |
d6f39728 | 7126 | |
67278d60 | 7127 | if Present (CR_Pragma) then |
7128 | Comp := First_Component_Or_Discriminant (Rectype); | |
7129 | while Present (Comp) loop | |
7130 | if No (Component_Clause (Comp)) then | |
7131 | Error_Msg_NE | |
7132 | ("missing component clause for &", CR_Pragma, Comp); | |
7133 | end if; | |
d6f39728 | 7134 | |
67278d60 | 7135 | Next_Component_Or_Discriminant (Comp); |
7136 | end loop; | |
d6f39728 | 7137 | |
1e3532e7 | 7138 | -- Give missing components warning if required |
15ebb600 | 7139 | |
fdd294d1 | 7140 | elsif Warn_On_Unrepped_Components then |
15ebb600 | 7141 | declare |
7142 | Num_Repped_Components : Nat := 0; | |
7143 | Num_Unrepped_Components : Nat := 0; | |
7144 | ||
7145 | begin | |
7146 | -- First count number of repped and unrepped components | |
7147 | ||
7148 | Comp := First_Component_Or_Discriminant (Rectype); | |
7149 | while Present (Comp) loop | |
7150 | if Present (Component_Clause (Comp)) then | |
7151 | Num_Repped_Components := Num_Repped_Components + 1; | |
7152 | else | |
7153 | Num_Unrepped_Components := Num_Unrepped_Components + 1; | |
7154 | end if; | |
7155 | ||
7156 | Next_Component_Or_Discriminant (Comp); | |
7157 | end loop; | |
7158 | ||
7159 | -- We are only interested in the case where there is at least one | |
7160 | -- unrepped component, and at least half the components have rep | |
7161 | -- clauses. We figure that if less than half have them, then the | |
87f9eef5 | 7162 | -- partial rep clause is really intentional. If the component |
7163 | -- type has no underlying type set at this point (as for a generic | |
7164 | -- formal type), we don't know enough to give a warning on the | |
7165 | -- component. | |
15ebb600 | 7166 | |
7167 | if Num_Unrepped_Components > 0 | |
7168 | and then Num_Unrepped_Components < Num_Repped_Components | |
7169 | then | |
7170 | Comp := First_Component_Or_Discriminant (Rectype); | |
7171 | while Present (Comp) loop | |
83f8f0a6 | 7172 | if No (Component_Clause (Comp)) |
3062c401 | 7173 | and then Comes_From_Source (Comp) |
87f9eef5 | 7174 | and then Present (Underlying_Type (Etype (Comp))) |
83f8f0a6 | 7175 | and then (Is_Scalar_Type (Underlying_Type (Etype (Comp))) |
67278d60 | 7176 | or else Size_Known_At_Compile_Time |
7177 | (Underlying_Type (Etype (Comp)))) | |
fdd294d1 | 7178 | and then not Has_Warnings_Off (Rectype) |
2be1f7d7 | 7179 | |
7180 | -- Ignore discriminant in unchecked union, since it is | |
7181 | -- not there, and cannot have a component clause. | |
7182 | ||
7183 | and then (not Is_Unchecked_Union (Rectype) | |
7184 | or else Ekind (Comp) /= E_Discriminant) | |
83f8f0a6 | 7185 | then |
15ebb600 | 7186 | Error_Msg_Sloc := Sloc (Comp); |
7187 | Error_Msg_NE | |
1e3532e7 | 7188 | ("?C?no component clause given for & declared #", |
15ebb600 | 7189 | N, Comp); |
7190 | end if; | |
7191 | ||
7192 | Next_Component_Or_Discriminant (Comp); | |
7193 | end loop; | |
7194 | end if; | |
7195 | end; | |
d6f39728 | 7196 | end if; |
d6f39728 | 7197 | end Analyze_Record_Representation_Clause; |
7198 | ||
eb66e842 | 7199 | ------------------------------------- |
7200 | -- Build_Discrete_Static_Predicate -- | |
7201 | ------------------------------------- | |
9ea61fdd | 7202 | |
eb66e842 | 7203 | procedure Build_Discrete_Static_Predicate |
7204 | (Typ : Entity_Id; | |
7205 | Expr : Node_Id; | |
7206 | Nam : Name_Id) | |
9ea61fdd | 7207 | is |
eb66e842 | 7208 | Loc : constant Source_Ptr := Sloc (Expr); |
9ea61fdd | 7209 | |
eb66e842 | 7210 | Non_Static : exception; |
7211 | -- Raised if something non-static is found | |
9ea61fdd | 7212 | |
eb66e842 | 7213 | Btyp : constant Entity_Id := Base_Type (Typ); |
9ea61fdd | 7214 | |
eb66e842 | 7215 | BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp)); |
7216 | BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp)); | |
7217 | -- Low bound and high bound value of base type of Typ | |
9ea61fdd | 7218 | |
afc229da | 7219 | TLo : Uint; |
7220 | THi : Uint; | |
7221 | -- Bounds for constructing the static predicate. We use the bound of the | |
7222 | -- subtype if it is static, otherwise the corresponding base type bound. | |
7223 | -- Note: a non-static subtype can have a static predicate. | |
9ea61fdd | 7224 | |
eb66e842 | 7225 | type REnt is record |
7226 | Lo, Hi : Uint; | |
7227 | end record; | |
7228 | -- One entry in a Rlist value, a single REnt (range entry) value denotes | |
7229 | -- one range from Lo to Hi. To represent a single value range Lo = Hi = | |
7230 | -- value. | |
9ea61fdd | 7231 | |
eb66e842 | 7232 | type RList is array (Nat range <>) of REnt; |
7233 | -- A list of ranges. The ranges are sorted in increasing order, and are | |
7234 | -- disjoint (there is a gap of at least one value between each range in | |
7235 | -- the table). A value is in the set of ranges in Rlist if it lies | |
7236 | -- within one of these ranges. | |
9ea61fdd | 7237 | |
eb66e842 | 7238 | False_Range : constant RList := |
7239 | RList'(1 .. 0 => REnt'(No_Uint, No_Uint)); | |
7240 | -- An empty set of ranges represents a range list that can never be | |
7241 | -- satisfied, since there are no ranges in which the value could lie, | |
7242 | -- so it does not lie in any of them. False_Range is a canonical value | |
7243 | -- for this empty set, but general processing should test for an Rlist | |
7244 | -- with length zero (see Is_False predicate), since other null ranges | |
7245 | -- may appear which must be treated as False. | |
5b5df4a9 | 7246 | |
eb66e842 | 7247 | True_Range : constant RList := RList'(1 => REnt'(BLo, BHi)); |
7248 | -- Range representing True, value must be in the base range | |
5b5df4a9 | 7249 | |
eb66e842 | 7250 | function "and" (Left : RList; Right : RList) return RList; |
7251 | -- And's together two range lists, returning a range list. This is a set | |
7252 | -- intersection operation. | |
5b5df4a9 | 7253 | |
eb66e842 | 7254 | function "or" (Left : RList; Right : RList) return RList; |
7255 | -- Or's together two range lists, returning a range list. This is a set | |
7256 | -- union operation. | |
87f3d5d3 | 7257 | |
eb66e842 | 7258 | function "not" (Right : RList) return RList; |
7259 | -- Returns complement of a given range list, i.e. a range list | |
7260 | -- representing all the values in TLo .. THi that are not in the input | |
7261 | -- operand Right. | |
ed4adc99 | 7262 | |
eb66e842 | 7263 | function Build_Val (V : Uint) return Node_Id; |
7264 | -- Return an analyzed N_Identifier node referencing this value, suitable | |
5c6a5792 | 7265 | -- for use as an entry in the Static_Discrte_Predicate list. This node |
7266 | -- is typed with the base type. | |
5b5df4a9 | 7267 | |
eb66e842 | 7268 | function Build_Range (Lo : Uint; Hi : Uint) return Node_Id; |
7269 | -- Return an analyzed N_Range node referencing this range, suitable for | |
5c6a5792 | 7270 | -- use as an entry in the Static_Discrete_Predicate list. This node is |
7271 | -- typed with the base type. | |
5b5df4a9 | 7272 | |
eb66e842 | 7273 | function Get_RList (Exp : Node_Id) return RList; |
7274 | -- This is a recursive routine that converts the given expression into a | |
7275 | -- list of ranges, suitable for use in building the static predicate. | |
5b5df4a9 | 7276 | |
eb66e842 | 7277 | function Is_False (R : RList) return Boolean; |
7278 | pragma Inline (Is_False); | |
7279 | -- Returns True if the given range list is empty, and thus represents a | |
7280 | -- False list of ranges that can never be satisfied. | |
87f3d5d3 | 7281 | |
eb66e842 | 7282 | function Is_True (R : RList) return Boolean; |
7283 | -- Returns True if R trivially represents the True predicate by having a | |
7284 | -- single range from BLo to BHi. | |
5b5df4a9 | 7285 | |
eb66e842 | 7286 | function Is_Type_Ref (N : Node_Id) return Boolean; |
7287 | pragma Inline (Is_Type_Ref); | |
7288 | -- Returns if True if N is a reference to the type for the predicate in | |
7289 | -- the expression (i.e. if it is an identifier whose Chars field matches | |
7de4cba3 | 7290 | -- the Nam given in the call). N must not be parenthesized, if the type |
7291 | -- name appears in parens, this routine will return False. | |
5b5df4a9 | 7292 | |
eb66e842 | 7293 | function Lo_Val (N : Node_Id) return Uint; |
5c6a5792 | 7294 | -- Given an entry from a Static_Discrete_Predicate list that is either |
7295 | -- a static expression or static range, gets either the expression value | |
7296 | -- or the low bound of the range. | |
5b5df4a9 | 7297 | |
eb66e842 | 7298 | function Hi_Val (N : Node_Id) return Uint; |
5c6a5792 | 7299 | -- Given an entry from a Static_Discrete_Predicate list that is either |
7300 | -- a static expression or static range, gets either the expression value | |
7301 | -- or the high bound of the range. | |
5b5df4a9 | 7302 | |
eb66e842 | 7303 | function Membership_Entry (N : Node_Id) return RList; |
7304 | -- Given a single membership entry (range, value, or subtype), returns | |
7305 | -- the corresponding range list. Raises Static_Error if not static. | |
5b5df4a9 | 7306 | |
eb66e842 | 7307 | function Membership_Entries (N : Node_Id) return RList; |
7308 | -- Given an element on an alternatives list of a membership operation, | |
7309 | -- returns the range list corresponding to this entry and all following | |
7310 | -- entries (i.e. returns the "or" of this list of values). | |
b9e61b2a | 7311 | |
eb66e842 | 7312 | function Stat_Pred (Typ : Entity_Id) return RList; |
7313 | -- Given a type, if it has a static predicate, then return the predicate | |
7314 | -- as a range list, otherwise raise Non_Static. | |
c4968aa2 | 7315 | |
eb66e842 | 7316 | ----------- |
7317 | -- "and" -- | |
7318 | ----------- | |
c4968aa2 | 7319 | |
eb66e842 | 7320 | function "and" (Left : RList; Right : RList) return RList is |
7321 | FEnt : REnt; | |
7322 | -- First range of result | |
c4968aa2 | 7323 | |
eb66e842 | 7324 | SLeft : Nat := Left'First; |
7325 | -- Start of rest of left entries | |
c4968aa2 | 7326 | |
eb66e842 | 7327 | SRight : Nat := Right'First; |
7328 | -- Start of rest of right entries | |
2072eaa9 | 7329 | |
eb66e842 | 7330 | begin |
7331 | -- If either range is True, return the other | |
5b5df4a9 | 7332 | |
eb66e842 | 7333 | if Is_True (Left) then |
7334 | return Right; | |
7335 | elsif Is_True (Right) then | |
7336 | return Left; | |
7337 | end if; | |
87f3d5d3 | 7338 | |
eb66e842 | 7339 | -- If either range is False, return False |
5b5df4a9 | 7340 | |
eb66e842 | 7341 | if Is_False (Left) or else Is_False (Right) then |
7342 | return False_Range; | |
7343 | end if; | |
4c1fd062 | 7344 | |
eb66e842 | 7345 | -- Loop to remove entries at start that are disjoint, and thus just |
7346 | -- get discarded from the result entirely. | |
5b5df4a9 | 7347 | |
eb66e842 | 7348 | loop |
7349 | -- If no operands left in either operand, result is false | |
5b5df4a9 | 7350 | |
eb66e842 | 7351 | if SLeft > Left'Last or else SRight > Right'Last then |
7352 | return False_Range; | |
5b5df4a9 | 7353 | |
eb66e842 | 7354 | -- Discard first left operand entry if disjoint with right |
5b5df4a9 | 7355 | |
eb66e842 | 7356 | elsif Left (SLeft).Hi < Right (SRight).Lo then |
7357 | SLeft := SLeft + 1; | |
5b5df4a9 | 7358 | |
eb66e842 | 7359 | -- Discard first right operand entry if disjoint with left |
5b5df4a9 | 7360 | |
eb66e842 | 7361 | elsif Right (SRight).Hi < Left (SLeft).Lo then |
7362 | SRight := SRight + 1; | |
5b5df4a9 | 7363 | |
eb66e842 | 7364 | -- Otherwise we have an overlapping entry |
5b5df4a9 | 7365 | |
eb66e842 | 7366 | else |
7367 | exit; | |
7368 | end if; | |
7369 | end loop; | |
5b5df4a9 | 7370 | |
eb66e842 | 7371 | -- Now we have two non-null operands, and first entries overlap. The |
7372 | -- first entry in the result will be the overlapping part of these | |
7373 | -- two entries. | |
47a46747 | 7374 | |
eb66e842 | 7375 | FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo), |
7376 | Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi)); | |
47a46747 | 7377 | |
eb66e842 | 7378 | -- Now we can remove the entry that ended at a lower value, since its |
7379 | -- contribution is entirely contained in Fent. | |
5b5df4a9 | 7380 | |
eb66e842 | 7381 | if Left (SLeft).Hi <= Right (SRight).Hi then |
7382 | SLeft := SLeft + 1; | |
7383 | else | |
7384 | SRight := SRight + 1; | |
7385 | end if; | |
5b5df4a9 | 7386 | |
eb66e842 | 7387 | -- Compute result by concatenating this first entry with the "and" of |
7388 | -- the remaining parts of the left and right operands. Note that if | |
7389 | -- either of these is empty, "and" will yield empty, so that we will | |
7390 | -- end up with just Fent, which is what we want in that case. | |
5b5df4a9 | 7391 | |
eb66e842 | 7392 | return |
7393 | FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last)); | |
7394 | end "and"; | |
fb7f2fc4 | 7395 | |
eb66e842 | 7396 | ----------- |
7397 | -- "not" -- | |
7398 | ----------- | |
fb7f2fc4 | 7399 | |
eb66e842 | 7400 | function "not" (Right : RList) return RList is |
7401 | begin | |
7402 | -- Return True if False range | |
fb7f2fc4 | 7403 | |
eb66e842 | 7404 | if Is_False (Right) then |
7405 | return True_Range; | |
7406 | end if; | |
ed4adc99 | 7407 | |
eb66e842 | 7408 | -- Return False if True range |
fb7f2fc4 | 7409 | |
eb66e842 | 7410 | if Is_True (Right) then |
7411 | return False_Range; | |
7412 | end if; | |
fb7f2fc4 | 7413 | |
eb66e842 | 7414 | -- Here if not trivial case |
87f3d5d3 | 7415 | |
eb66e842 | 7416 | declare |
7417 | Result : RList (1 .. Right'Length + 1); | |
7418 | -- May need one more entry for gap at beginning and end | |
87f3d5d3 | 7419 | |
eb66e842 | 7420 | Count : Nat := 0; |
7421 | -- Number of entries stored in Result | |
4098232e | 7422 | |
eb66e842 | 7423 | begin |
7424 | -- Gap at start | |
4098232e | 7425 | |
eb66e842 | 7426 | if Right (Right'First).Lo > TLo then |
7427 | Count := Count + 1; | |
7428 | Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1); | |
7429 | end if; | |
ed4adc99 | 7430 | |
eb66e842 | 7431 | -- Gaps between ranges |
ed4adc99 | 7432 | |
eb66e842 | 7433 | for J in Right'First .. Right'Last - 1 loop |
7434 | Count := Count + 1; | |
7435 | Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1); | |
7436 | end loop; | |
5b5df4a9 | 7437 | |
eb66e842 | 7438 | -- Gap at end |
5b5df4a9 | 7439 | |
eb66e842 | 7440 | if Right (Right'Last).Hi < THi then |
7441 | Count := Count + 1; | |
7442 | Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi); | |
7443 | end if; | |
5b5df4a9 | 7444 | |
eb66e842 | 7445 | return Result (1 .. Count); |
7446 | end; | |
7447 | end "not"; | |
5b5df4a9 | 7448 | |
eb66e842 | 7449 | ---------- |
7450 | -- "or" -- | |
7451 | ---------- | |
5b5df4a9 | 7452 | |
eb66e842 | 7453 | function "or" (Left : RList; Right : RList) return RList is |
7454 | FEnt : REnt; | |
7455 | -- First range of result | |
5b5df4a9 | 7456 | |
eb66e842 | 7457 | SLeft : Nat := Left'First; |
7458 | -- Start of rest of left entries | |
5b5df4a9 | 7459 | |
eb66e842 | 7460 | SRight : Nat := Right'First; |
7461 | -- Start of rest of right entries | |
5b5df4a9 | 7462 | |
eb66e842 | 7463 | begin |
7464 | -- If either range is True, return True | |
5b5df4a9 | 7465 | |
eb66e842 | 7466 | if Is_True (Left) or else Is_True (Right) then |
7467 | return True_Range; | |
7468 | end if; | |
5b5df4a9 | 7469 | |
eb66e842 | 7470 | -- If either range is False (empty), return the other |
5b5df4a9 | 7471 | |
eb66e842 | 7472 | if Is_False (Left) then |
7473 | return Right; | |
7474 | elsif Is_False (Right) then | |
7475 | return Left; | |
7476 | end if; | |
5b5df4a9 | 7477 | |
eb66e842 | 7478 | -- Initialize result first entry from left or right operand depending |
7479 | -- on which starts with the lower range. | |
5b5df4a9 | 7480 | |
eb66e842 | 7481 | if Left (SLeft).Lo < Right (SRight).Lo then |
7482 | FEnt := Left (SLeft); | |
7483 | SLeft := SLeft + 1; | |
7484 | else | |
7485 | FEnt := Right (SRight); | |
7486 | SRight := SRight + 1; | |
7487 | end if; | |
5b5df4a9 | 7488 | |
eb66e842 | 7489 | -- This loop eats ranges from left and right operands that are |
7490 | -- contiguous with the first range we are gathering. | |
9ea61fdd | 7491 | |
eb66e842 | 7492 | loop |
7493 | -- Eat first entry in left operand if contiguous or overlapped by | |
7494 | -- gathered first operand of result. | |
9ea61fdd | 7495 | |
eb66e842 | 7496 | if SLeft <= Left'Last |
7497 | and then Left (SLeft).Lo <= FEnt.Hi + 1 | |
7498 | then | |
7499 | FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi); | |
7500 | SLeft := SLeft + 1; | |
9ea61fdd | 7501 | |
eb66e842 | 7502 | -- Eat first entry in right operand if contiguous or overlapped by |
7503 | -- gathered right operand of result. | |
9ea61fdd | 7504 | |
eb66e842 | 7505 | elsif SRight <= Right'Last |
7506 | and then Right (SRight).Lo <= FEnt.Hi + 1 | |
7507 | then | |
7508 | FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi); | |
7509 | SRight := SRight + 1; | |
9ea61fdd | 7510 | |
eb66e842 | 7511 | -- All done if no more entries to eat |
5b5df4a9 | 7512 | |
eb66e842 | 7513 | else |
7514 | exit; | |
7515 | end if; | |
7516 | end loop; | |
5b5df4a9 | 7517 | |
eb66e842 | 7518 | -- Obtain result as the first entry we just computed, concatenated |
7519 | -- to the "or" of the remaining results (if one operand is empty, | |
7520 | -- this will just concatenate with the other | |
5b5df4a9 | 7521 | |
eb66e842 | 7522 | return |
7523 | FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last)); | |
7524 | end "or"; | |
5b5df4a9 | 7525 | |
eb66e842 | 7526 | ----------------- |
7527 | -- Build_Range -- | |
7528 | ----------------- | |
5b5df4a9 | 7529 | |
eb66e842 | 7530 | function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is |
7531 | Result : Node_Id; | |
5b5df4a9 | 7532 | begin |
eb66e842 | 7533 | Result := |
7534 | Make_Range (Loc, | |
7535 | Low_Bound => Build_Val (Lo), | |
7536 | High_Bound => Build_Val (Hi)); | |
7537 | Set_Etype (Result, Btyp); | |
7538 | Set_Analyzed (Result); | |
7539 | return Result; | |
7540 | end Build_Range; | |
5b5df4a9 | 7541 | |
eb66e842 | 7542 | --------------- |
7543 | -- Build_Val -- | |
7544 | --------------- | |
5b5df4a9 | 7545 | |
eb66e842 | 7546 | function Build_Val (V : Uint) return Node_Id is |
7547 | Result : Node_Id; | |
5b5df4a9 | 7548 | |
eb66e842 | 7549 | begin |
7550 | if Is_Enumeration_Type (Typ) then | |
7551 | Result := Get_Enum_Lit_From_Pos (Typ, V, Loc); | |
7552 | else | |
7553 | Result := Make_Integer_Literal (Loc, V); | |
7554 | end if; | |
5b5df4a9 | 7555 | |
eb66e842 | 7556 | Set_Etype (Result, Btyp); |
7557 | Set_Is_Static_Expression (Result); | |
7558 | Set_Analyzed (Result); | |
7559 | return Result; | |
7560 | end Build_Val; | |
87f3d5d3 | 7561 | |
eb66e842 | 7562 | --------------- |
7563 | -- Get_RList -- | |
7564 | --------------- | |
87f3d5d3 | 7565 | |
eb66e842 | 7566 | function Get_RList (Exp : Node_Id) return RList is |
7567 | Op : Node_Kind; | |
7568 | Val : Uint; | |
87f3d5d3 | 7569 | |
eb66e842 | 7570 | begin |
7571 | -- Static expression can only be true or false | |
87f3d5d3 | 7572 | |
eb66e842 | 7573 | if Is_OK_Static_Expression (Exp) then |
7574 | if Expr_Value (Exp) = 0 then | |
7575 | return False_Range; | |
7576 | else | |
7577 | return True_Range; | |
9ea61fdd | 7578 | end if; |
eb66e842 | 7579 | end if; |
87f3d5d3 | 7580 | |
eb66e842 | 7581 | -- Otherwise test node type |
192b8dab | 7582 | |
eb66e842 | 7583 | Op := Nkind (Exp); |
192b8dab | 7584 | |
eb66e842 | 7585 | case Op is |
5d3fb947 | 7586 | |
eb66e842 | 7587 | -- And |
5d3fb947 | 7588 | |
99378362 | 7589 | when N_And_Then |
7590 | | N_Op_And | |
7591 | => | |
eb66e842 | 7592 | return Get_RList (Left_Opnd (Exp)) |
7593 | and | |
7594 | Get_RList (Right_Opnd (Exp)); | |
5b5df4a9 | 7595 | |
eb66e842 | 7596 | -- Or |
9dc88aea | 7597 | |
99378362 | 7598 | when N_Op_Or |
7599 | | N_Or_Else | |
7600 | => | |
eb66e842 | 7601 | return Get_RList (Left_Opnd (Exp)) |
7602 | or | |
7603 | Get_RList (Right_Opnd (Exp)); | |
7c443ae8 | 7604 | |
eb66e842 | 7605 | -- Not |
9dc88aea | 7606 | |
eb66e842 | 7607 | when N_Op_Not => |
7608 | return not Get_RList (Right_Opnd (Exp)); | |
9dc88aea | 7609 | |
eb66e842 | 7610 | -- Comparisons of type with static value |
84c8f0b8 | 7611 | |
eb66e842 | 7612 | when N_Op_Compare => |
490beba6 | 7613 | |
eb66e842 | 7614 | -- Type is left operand |
9dc88aea | 7615 | |
eb66e842 | 7616 | if Is_Type_Ref (Left_Opnd (Exp)) |
7617 | and then Is_OK_Static_Expression (Right_Opnd (Exp)) | |
7618 | then | |
7619 | Val := Expr_Value (Right_Opnd (Exp)); | |
84c8f0b8 | 7620 | |
eb66e842 | 7621 | -- Typ is right operand |
84c8f0b8 | 7622 | |
eb66e842 | 7623 | elsif Is_Type_Ref (Right_Opnd (Exp)) |
7624 | and then Is_OK_Static_Expression (Left_Opnd (Exp)) | |
7625 | then | |
7626 | Val := Expr_Value (Left_Opnd (Exp)); | |
84c8f0b8 | 7627 | |
eb66e842 | 7628 | -- Invert sense of comparison |
84c8f0b8 | 7629 | |
eb66e842 | 7630 | case Op is |
7631 | when N_Op_Gt => Op := N_Op_Lt; | |
7632 | when N_Op_Lt => Op := N_Op_Gt; | |
7633 | when N_Op_Ge => Op := N_Op_Le; | |
7634 | when N_Op_Le => Op := N_Op_Ge; | |
7635 | when others => null; | |
7636 | end case; | |
84c8f0b8 | 7637 | |
eb66e842 | 7638 | -- Other cases are non-static |
34d045d3 | 7639 | |
eb66e842 | 7640 | else |
7641 | raise Non_Static; | |
7642 | end if; | |
9dc88aea | 7643 | |
eb66e842 | 7644 | -- Construct range according to comparison operation |
9dc88aea | 7645 | |
eb66e842 | 7646 | case Op is |
7647 | when N_Op_Eq => | |
7648 | return RList'(1 => REnt'(Val, Val)); | |
9dc88aea | 7649 | |
eb66e842 | 7650 | when N_Op_Ge => |
7651 | return RList'(1 => REnt'(Val, BHi)); | |
84c8f0b8 | 7652 | |
eb66e842 | 7653 | when N_Op_Gt => |
7654 | return RList'(1 => REnt'(Val + 1, BHi)); | |
84c8f0b8 | 7655 | |
eb66e842 | 7656 | when N_Op_Le => |
7657 | return RList'(1 => REnt'(BLo, Val)); | |
fb7f2fc4 | 7658 | |
eb66e842 | 7659 | when N_Op_Lt => |
7660 | return RList'(1 => REnt'(BLo, Val - 1)); | |
9dc88aea | 7661 | |
eb66e842 | 7662 | when N_Op_Ne => |
7663 | return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi)); | |
9dc88aea | 7664 | |
eb66e842 | 7665 | when others => |
7666 | raise Program_Error; | |
7667 | end case; | |
9dc88aea | 7668 | |
eb66e842 | 7669 | -- Membership (IN) |
9dc88aea | 7670 | |
eb66e842 | 7671 | when N_In => |
7672 | if not Is_Type_Ref (Left_Opnd (Exp)) then | |
7673 | raise Non_Static; | |
7674 | end if; | |
9dc88aea | 7675 | |
eb66e842 | 7676 | if Present (Right_Opnd (Exp)) then |
7677 | return Membership_Entry (Right_Opnd (Exp)); | |
7678 | else | |
7679 | return Membership_Entries (First (Alternatives (Exp))); | |
7680 | end if; | |
9dc88aea | 7681 | |
eb66e842 | 7682 | -- Negative membership (NOT IN) |
9dc88aea | 7683 | |
eb66e842 | 7684 | when N_Not_In => |
7685 | if not Is_Type_Ref (Left_Opnd (Exp)) then | |
7686 | raise Non_Static; | |
7687 | end if; | |
9dc88aea | 7688 | |
eb66e842 | 7689 | if Present (Right_Opnd (Exp)) then |
7690 | return not Membership_Entry (Right_Opnd (Exp)); | |
7691 | else | |
7692 | return not Membership_Entries (First (Alternatives (Exp))); | |
7693 | end if; | |
9dc88aea | 7694 | |
eb66e842 | 7695 | -- Function call, may be call to static predicate |
9dc88aea | 7696 | |
eb66e842 | 7697 | when N_Function_Call => |
7698 | if Is_Entity_Name (Name (Exp)) then | |
7699 | declare | |
7700 | Ent : constant Entity_Id := Entity (Name (Exp)); | |
7701 | begin | |
7702 | if Is_Predicate_Function (Ent) | |
7703 | or else | |
7704 | Is_Predicate_Function_M (Ent) | |
7705 | then | |
7706 | return Stat_Pred (Etype (First_Formal (Ent))); | |
7707 | end if; | |
7708 | end; | |
7709 | end if; | |
9dc88aea | 7710 | |
eb66e842 | 7711 | -- Other function call cases are non-static |
9dc88aea | 7712 | |
eb66e842 | 7713 | raise Non_Static; |
490beba6 | 7714 | |
eb66e842 | 7715 | -- Qualified expression, dig out the expression |
c92e878b | 7716 | |
eb66e842 | 7717 | when N_Qualified_Expression => |
7718 | return Get_RList (Expression (Exp)); | |
4c1fd062 | 7719 | |
eb66e842 | 7720 | when N_Case_Expression => |
7721 | declare | |
7722 | Alt : Node_Id; | |
7723 | Choices : List_Id; | |
7724 | Dep : Node_Id; | |
4c1fd062 | 7725 | |
eb66e842 | 7726 | begin |
7727 | if not Is_Entity_Name (Expression (Expr)) | |
7728 | or else Etype (Expression (Expr)) /= Typ | |
7729 | then | |
7730 | Error_Msg_N | |
7731 | ("expression must denaote subtype", Expression (Expr)); | |
7732 | return False_Range; | |
7733 | end if; | |
9dc88aea | 7734 | |
eb66e842 | 7735 | -- Collect discrete choices in all True alternatives |
9dc88aea | 7736 | |
eb66e842 | 7737 | Choices := New_List; |
7738 | Alt := First (Alternatives (Exp)); | |
7739 | while Present (Alt) loop | |
7740 | Dep := Expression (Alt); | |
34d045d3 | 7741 | |
cda40848 | 7742 | if not Is_OK_Static_Expression (Dep) then |
eb66e842 | 7743 | raise Non_Static; |
ebbab42d | 7744 | |
eb66e842 | 7745 | elsif Is_True (Expr_Value (Dep)) then |
7746 | Append_List_To (Choices, | |
7747 | New_Copy_List (Discrete_Choices (Alt))); | |
7748 | end if; | |
fb7f2fc4 | 7749 | |
eb66e842 | 7750 | Next (Alt); |
7751 | end loop; | |
9dc88aea | 7752 | |
eb66e842 | 7753 | return Membership_Entries (First (Choices)); |
7754 | end; | |
9dc88aea | 7755 | |
eb66e842 | 7756 | -- Expression with actions: if no actions, dig out expression |
9dc88aea | 7757 | |
eb66e842 | 7758 | when N_Expression_With_Actions => |
7759 | if Is_Empty_List (Actions (Exp)) then | |
7760 | return Get_RList (Expression (Exp)); | |
7761 | else | |
7762 | raise Non_Static; | |
7763 | end if; | |
9dc88aea | 7764 | |
eb66e842 | 7765 | -- Xor operator |
490beba6 | 7766 | |
eb66e842 | 7767 | when N_Op_Xor => |
7768 | return (Get_RList (Left_Opnd (Exp)) | |
7769 | and not Get_RList (Right_Opnd (Exp))) | |
7770 | or (Get_RList (Right_Opnd (Exp)) | |
7771 | and not Get_RList (Left_Opnd (Exp))); | |
9dc88aea | 7772 | |
eb66e842 | 7773 | -- Any other node type is non-static |
fb7f2fc4 | 7774 | |
eb66e842 | 7775 | when others => |
7776 | raise Non_Static; | |
7777 | end case; | |
7778 | end Get_RList; | |
fb7f2fc4 | 7779 | |
eb66e842 | 7780 | ------------ |
7781 | -- Hi_Val -- | |
7782 | ------------ | |
fb7f2fc4 | 7783 | |
eb66e842 | 7784 | function Hi_Val (N : Node_Id) return Uint is |
7785 | begin | |
cda40848 | 7786 | if Is_OK_Static_Expression (N) then |
eb66e842 | 7787 | return Expr_Value (N); |
7788 | else | |
7789 | pragma Assert (Nkind (N) = N_Range); | |
7790 | return Expr_Value (High_Bound (N)); | |
7791 | end if; | |
7792 | end Hi_Val; | |
fb7f2fc4 | 7793 | |
eb66e842 | 7794 | -------------- |
7795 | -- Is_False -- | |
7796 | -------------- | |
fb7f2fc4 | 7797 | |
eb66e842 | 7798 | function Is_False (R : RList) return Boolean is |
7799 | begin | |
7800 | return R'Length = 0; | |
7801 | end Is_False; | |
9dc88aea | 7802 | |
eb66e842 | 7803 | ------------- |
7804 | -- Is_True -- | |
7805 | ------------- | |
9dc88aea | 7806 | |
eb66e842 | 7807 | function Is_True (R : RList) return Boolean is |
7808 | begin | |
7809 | return R'Length = 1 | |
7810 | and then R (R'First).Lo = BLo | |
7811 | and then R (R'First).Hi = BHi; | |
7812 | end Is_True; | |
9dc88aea | 7813 | |
eb66e842 | 7814 | ----------------- |
7815 | -- Is_Type_Ref -- | |
7816 | ----------------- | |
9dc88aea | 7817 | |
eb66e842 | 7818 | function Is_Type_Ref (N : Node_Id) return Boolean is |
7819 | begin | |
7de4cba3 | 7820 | return Nkind (N) = N_Identifier |
7821 | and then Chars (N) = Nam | |
7822 | and then Paren_Count (N) = 0; | |
eb66e842 | 7823 | end Is_Type_Ref; |
9dc88aea | 7824 | |
eb66e842 | 7825 | ------------ |
7826 | -- Lo_Val -- | |
7827 | ------------ | |
9dc88aea | 7828 | |
eb66e842 | 7829 | function Lo_Val (N : Node_Id) return Uint is |
84c8f0b8 | 7830 | begin |
cda40848 | 7831 | if Is_OK_Static_Expression (N) then |
eb66e842 | 7832 | return Expr_Value (N); |
84c8f0b8 | 7833 | else |
eb66e842 | 7834 | pragma Assert (Nkind (N) = N_Range); |
7835 | return Expr_Value (Low_Bound (N)); | |
84c8f0b8 | 7836 | end if; |
eb66e842 | 7837 | end Lo_Val; |
d97beb2f | 7838 | |
eb66e842 | 7839 | ------------------------ |
7840 | -- Membership_Entries -- | |
7841 | ------------------------ | |
d97beb2f | 7842 | |
eb66e842 | 7843 | function Membership_Entries (N : Node_Id) return RList is |
84c8f0b8 | 7844 | begin |
eb66e842 | 7845 | if No (Next (N)) then |
7846 | return Membership_Entry (N); | |
84c8f0b8 | 7847 | else |
eb66e842 | 7848 | return Membership_Entry (N) or Membership_Entries (Next (N)); |
84c8f0b8 | 7849 | end if; |
eb66e842 | 7850 | end Membership_Entries; |
84c8f0b8 | 7851 | |
eb66e842 | 7852 | ---------------------- |
7853 | -- Membership_Entry -- | |
7854 | ---------------------- | |
84c8f0b8 | 7855 | |
eb66e842 | 7856 | function Membership_Entry (N : Node_Id) return RList is |
7857 | Val : Uint; | |
7858 | SLo : Uint; | |
7859 | SHi : Uint; | |
d97beb2f | 7860 | |
eb66e842 | 7861 | begin |
7862 | -- Range case | |
d97beb2f | 7863 | |
eb66e842 | 7864 | if Nkind (N) = N_Range then |
cda40848 | 7865 | if not Is_OK_Static_Expression (Low_Bound (N)) |
eb66e842 | 7866 | or else |
cda40848 | 7867 | not Is_OK_Static_Expression (High_Bound (N)) |
eb66e842 | 7868 | then |
7869 | raise Non_Static; | |
7870 | else | |
7871 | SLo := Expr_Value (Low_Bound (N)); | |
7872 | SHi := Expr_Value (High_Bound (N)); | |
7873 | return RList'(1 => REnt'(SLo, SHi)); | |
7874 | end if; | |
84c8f0b8 | 7875 | |
eb66e842 | 7876 | -- Static expression case |
84c8f0b8 | 7877 | |
cda40848 | 7878 | elsif Is_OK_Static_Expression (N) then |
eb66e842 | 7879 | Val := Expr_Value (N); |
7880 | return RList'(1 => REnt'(Val, Val)); | |
d97beb2f | 7881 | |
eb66e842 | 7882 | -- Identifier (other than static expression) case |
d97beb2f | 7883 | |
eb66e842 | 7884 | else pragma Assert (Nkind (N) = N_Identifier); |
d97beb2f | 7885 | |
eb66e842 | 7886 | -- Type case |
d97beb2f | 7887 | |
eb66e842 | 7888 | if Is_Type (Entity (N)) then |
d97beb2f | 7889 | |
eb66e842 | 7890 | -- If type has predicates, process them |
d97beb2f | 7891 | |
eb66e842 | 7892 | if Has_Predicates (Entity (N)) then |
7893 | return Stat_Pred (Entity (N)); | |
d97beb2f | 7894 | |
eb66e842 | 7895 | -- For static subtype without predicates, get range |
9dc88aea | 7896 | |
cda40848 | 7897 | elsif Is_OK_Static_Subtype (Entity (N)) then |
eb66e842 | 7898 | SLo := Expr_Value (Type_Low_Bound (Entity (N))); |
7899 | SHi := Expr_Value (Type_High_Bound (Entity (N))); | |
7900 | return RList'(1 => REnt'(SLo, SHi)); | |
9f269bd8 | 7901 | |
eb66e842 | 7902 | -- Any other type makes us non-static |
9f269bd8 | 7903 | |
eb66e842 | 7904 | else |
7905 | raise Non_Static; | |
7906 | end if; | |
84c8f0b8 | 7907 | |
eb66e842 | 7908 | -- Any other kind of identifier in predicate (e.g. a non-static |
7909 | -- expression value) means this is not a static predicate. | |
84c8f0b8 | 7910 | |
eb66e842 | 7911 | else |
7912 | raise Non_Static; | |
7913 | end if; | |
7914 | end if; | |
7915 | end Membership_Entry; | |
84c8f0b8 | 7916 | |
eb66e842 | 7917 | --------------- |
7918 | -- Stat_Pred -- | |
7919 | --------------- | |
84c8f0b8 | 7920 | |
eb66e842 | 7921 | function Stat_Pred (Typ : Entity_Id) return RList is |
7922 | begin | |
7923 | -- Not static if type does not have static predicates | |
84c8f0b8 | 7924 | |
5c6a5792 | 7925 | if not Has_Static_Predicate (Typ) then |
eb66e842 | 7926 | raise Non_Static; |
7927 | end if; | |
84c8f0b8 | 7928 | |
eb66e842 | 7929 | -- Otherwise we convert the predicate list to a range list |
84c8f0b8 | 7930 | |
eb66e842 | 7931 | declare |
5c6a5792 | 7932 | Spred : constant List_Id := Static_Discrete_Predicate (Typ); |
7933 | Result : RList (1 .. List_Length (Spred)); | |
eb66e842 | 7934 | P : Node_Id; |
84c8f0b8 | 7935 | |
eb66e842 | 7936 | begin |
5c6a5792 | 7937 | P := First (Static_Discrete_Predicate (Typ)); |
eb66e842 | 7938 | for J in Result'Range loop |
7939 | Result (J) := REnt'(Lo_Val (P), Hi_Val (P)); | |
7940 | Next (P); | |
7941 | end loop; | |
84c8f0b8 | 7942 | |
eb66e842 | 7943 | return Result; |
7944 | end; | |
7945 | end Stat_Pred; | |
84c8f0b8 | 7946 | |
eb66e842 | 7947 | -- Start of processing for Build_Discrete_Static_Predicate |
84c8f0b8 | 7948 | |
eb66e842 | 7949 | begin |
fdec445e | 7950 | -- Establish bounds for the predicate |
afc229da | 7951 | |
7952 | if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then | |
7953 | TLo := Expr_Value (Type_Low_Bound (Typ)); | |
7954 | else | |
7955 | TLo := BLo; | |
7956 | end if; | |
7957 | ||
7958 | if Compile_Time_Known_Value (Type_High_Bound (Typ)) then | |
7959 | THi := Expr_Value (Type_High_Bound (Typ)); | |
7960 | else | |
7961 | THi := BHi; | |
7962 | end if; | |
7963 | ||
eb66e842 | 7964 | -- Analyze the expression to see if it is a static predicate |
84c8f0b8 | 7965 | |
eb66e842 | 7966 | declare |
7967 | Ranges : constant RList := Get_RList (Expr); | |
7968 | -- Range list from expression if it is static | |
84c8f0b8 | 7969 | |
eb66e842 | 7970 | Plist : List_Id; |
84c8f0b8 | 7971 | |
eb66e842 | 7972 | begin |
7973 | -- Convert range list into a form for the static predicate. In the | |
7974 | -- Ranges array, we just have raw ranges, these must be converted | |
7975 | -- to properly typed and analyzed static expressions or range nodes. | |
84c8f0b8 | 7976 | |
eb66e842 | 7977 | -- Note: here we limit ranges to the ranges of the subtype, so that |
7978 | -- a predicate is always false for values outside the subtype. That | |
7979 | -- seems fine, such values are invalid anyway, and considering them | |
7980 | -- to fail the predicate seems allowed and friendly, and furthermore | |
7981 | -- simplifies processing for case statements and loops. | |
84c8f0b8 | 7982 | |
eb66e842 | 7983 | Plist := New_List; |
7984 | ||
7985 | for J in Ranges'Range loop | |
84c8f0b8 | 7986 | declare |
eb66e842 | 7987 | Lo : Uint := Ranges (J).Lo; |
7988 | Hi : Uint := Ranges (J).Hi; | |
84c8f0b8 | 7989 | |
eb66e842 | 7990 | begin |
7991 | -- Ignore completely out of range entry | |
84c8f0b8 | 7992 | |
eb66e842 | 7993 | if Hi < TLo or else Lo > THi then |
7994 | null; | |
84c8f0b8 | 7995 | |
eb66e842 | 7996 | -- Otherwise process entry |
84c8f0b8 | 7997 | |
eb66e842 | 7998 | else |
7999 | -- Adjust out of range value to subtype range | |
490beba6 | 8000 | |
eb66e842 | 8001 | if Lo < TLo then |
8002 | Lo := TLo; | |
8003 | end if; | |
490beba6 | 8004 | |
eb66e842 | 8005 | if Hi > THi then |
8006 | Hi := THi; | |
8007 | end if; | |
84c8f0b8 | 8008 | |
eb66e842 | 8009 | -- Convert range into required form |
84c8f0b8 | 8010 | |
eb66e842 | 8011 | Append_To (Plist, Build_Range (Lo, Hi)); |
84c8f0b8 | 8012 | end if; |
eb66e842 | 8013 | end; |
8014 | end loop; | |
84c8f0b8 | 8015 | |
eb66e842 | 8016 | -- Processing was successful and all entries were static, so now we |
8017 | -- can store the result as the predicate list. | |
84c8f0b8 | 8018 | |
5c6a5792 | 8019 | Set_Static_Discrete_Predicate (Typ, Plist); |
84c8f0b8 | 8020 | |
eb66e842 | 8021 | -- The processing for static predicates put the expression into |
8022 | -- canonical form as a series of ranges. It also eliminated | |
8023 | -- duplicates and collapsed and combined ranges. We might as well | |
8024 | -- replace the alternatives list of the right operand of the | |
8025 | -- membership test with the static predicate list, which will | |
8026 | -- usually be more efficient. | |
84c8f0b8 | 8027 | |
eb66e842 | 8028 | declare |
8029 | New_Alts : constant List_Id := New_List; | |
8030 | Old_Node : Node_Id; | |
8031 | New_Node : Node_Id; | |
84c8f0b8 | 8032 | |
eb66e842 | 8033 | begin |
8034 | Old_Node := First (Plist); | |
8035 | while Present (Old_Node) loop | |
8036 | New_Node := New_Copy (Old_Node); | |
84c8f0b8 | 8037 | |
eb66e842 | 8038 | if Nkind (New_Node) = N_Range then |
8039 | Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node))); | |
8040 | Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node))); | |
8041 | end if; | |
84c8f0b8 | 8042 | |
eb66e842 | 8043 | Append_To (New_Alts, New_Node); |
8044 | Next (Old_Node); | |
8045 | end loop; | |
84c8f0b8 | 8046 | |
eb66e842 | 8047 | -- If empty list, replace by False |
84c8f0b8 | 8048 | |
eb66e842 | 8049 | if Is_Empty_List (New_Alts) then |
8050 | Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc)); | |
84c8f0b8 | 8051 | |
eb66e842 | 8052 | -- Else replace by set membership test |
84c8f0b8 | 8053 | |
eb66e842 | 8054 | else |
8055 | Rewrite (Expr, | |
8056 | Make_In (Loc, | |
8057 | Left_Opnd => Make_Identifier (Loc, Nam), | |
8058 | Right_Opnd => Empty, | |
8059 | Alternatives => New_Alts)); | |
490beba6 | 8060 | |
eb66e842 | 8061 | -- Resolve new expression in function context |
490beba6 | 8062 | |
eb66e842 | 8063 | Install_Formals (Predicate_Function (Typ)); |
8064 | Push_Scope (Predicate_Function (Typ)); | |
8065 | Analyze_And_Resolve (Expr, Standard_Boolean); | |
8066 | Pop_Scope; | |
8067 | end if; | |
8068 | end; | |
8069 | end; | |
9ab32fe9 | 8070 | |
eb66e842 | 8071 | -- If non-static, return doing nothing |
9ab32fe9 | 8072 | |
eb66e842 | 8073 | exception |
8074 | when Non_Static => | |
8075 | return; | |
8076 | end Build_Discrete_Static_Predicate; | |
64cc9e5d | 8077 | |
ee2b7923 | 8078 | -------------------------------- |
8079 | -- Build_Export_Import_Pragma -- | |
8080 | -------------------------------- | |
8081 | ||
8082 | function Build_Export_Import_Pragma | |
8083 | (Asp : Node_Id; | |
8084 | Id : Entity_Id) return Node_Id | |
8085 | is | |
8086 | Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp); | |
8087 | Expr : constant Node_Id := Expression (Asp); | |
8088 | Loc : constant Source_Ptr := Sloc (Asp); | |
8089 | ||
8090 | Args : List_Id; | |
8091 | Conv : Node_Id; | |
8092 | Conv_Arg : Node_Id; | |
8093 | Dummy_1 : Node_Id; | |
8094 | Dummy_2 : Node_Id; | |
8095 | EN : Node_Id; | |
8096 | LN : Node_Id; | |
8097 | Prag : Node_Id; | |
8098 | ||
8099 | Create_Pragma : Boolean := False; | |
8100 | -- This flag is set when the aspect form is such that it warrants the | |
8101 | -- creation of a corresponding pragma. | |
8102 | ||
8103 | begin | |
8104 | if Present (Expr) then | |
8105 | if Error_Posted (Expr) then | |
8106 | null; | |
8107 | ||
8108 | elsif Is_True (Expr_Value (Expr)) then | |
8109 | Create_Pragma := True; | |
8110 | end if; | |
8111 | ||
8112 | -- Otherwise the aspect defaults to True | |
8113 | ||
8114 | else | |
8115 | Create_Pragma := True; | |
8116 | end if; | |
8117 | ||
8118 | -- Nothing to do when the expression is False or is erroneous | |
8119 | ||
8120 | if not Create_Pragma then | |
8121 | return Empty; | |
8122 | end if; | |
8123 | ||
8124 | -- Obtain all interfacing aspects that apply to the related entity | |
8125 | ||
8126 | Get_Interfacing_Aspects | |
8127 | (Iface_Asp => Asp, | |
8128 | Conv_Asp => Conv, | |
8129 | EN_Asp => EN, | |
8130 | Expo_Asp => Dummy_1, | |
8131 | Imp_Asp => Dummy_2, | |
8132 | LN_Asp => LN); | |
8133 | ||
8134 | Args := New_List; | |
8135 | ||
8136 | -- Handle the convention argument | |
8137 | ||
8138 | if Present (Conv) then | |
8139 | Conv_Arg := New_Copy_Tree (Expression (Conv)); | |
8140 | ||
8141 | -- Assume convention "Ada' when aspect Convention is missing | |
8142 | ||
8143 | else | |
8144 | Conv_Arg := Make_Identifier (Loc, Name_Ada); | |
8145 | end if; | |
8146 | ||
8147 | Append_To (Args, | |
8148 | Make_Pragma_Argument_Association (Loc, | |
8149 | Chars => Name_Convention, | |
8150 | Expression => Conv_Arg)); | |
8151 | ||
8152 | -- Handle the entity argument | |
8153 | ||
8154 | Append_To (Args, | |
8155 | Make_Pragma_Argument_Association (Loc, | |
8156 | Chars => Name_Entity, | |
8157 | Expression => New_Occurrence_Of (Id, Loc))); | |
8158 | ||
8159 | -- Handle the External_Name argument | |
8160 | ||
8161 | if Present (EN) then | |
8162 | Append_To (Args, | |
8163 | Make_Pragma_Argument_Association (Loc, | |
8164 | Chars => Name_External_Name, | |
8165 | Expression => New_Copy_Tree (Expression (EN)))); | |
8166 | end if; | |
8167 | ||
8168 | -- Handle the Link_Name argument | |
8169 | ||
8170 | if Present (LN) then | |
8171 | Append_To (Args, | |
8172 | Make_Pragma_Argument_Association (Loc, | |
8173 | Chars => Name_Link_Name, | |
8174 | Expression => New_Copy_Tree (Expression (LN)))); | |
8175 | end if; | |
8176 | ||
8177 | -- Generate: | |
8178 | -- pragma Export/Import | |
8179 | -- (Convention => <Conv>/Ada, | |
8180 | -- Entity => <Id>, | |
8181 | -- [External_Name => <EN>,] | |
8182 | -- [Link_Name => <LN>]); | |
8183 | ||
8184 | Prag := | |
8185 | Make_Pragma (Loc, | |
8186 | Pragma_Identifier => | |
8187 | Make_Identifier (Loc, Chars (Identifier (Asp))), | |
8188 | Pragma_Argument_Associations => Args); | |
8189 | ||
8190 | -- Decorate the relevant aspect and the pragma | |
8191 | ||
8192 | Set_Aspect_Rep_Item (Asp, Prag); | |
8193 | ||
8194 | Set_Corresponding_Aspect (Prag, Asp); | |
8195 | Set_From_Aspect_Specification (Prag); | |
8196 | Set_Parent (Prag, Asp); | |
8197 | ||
8198 | if Asp_Id = Aspect_Import and then Is_Subprogram (Id) then | |
8199 | Set_Import_Pragma (Id, Prag); | |
8200 | end if; | |
8201 | ||
8202 | return Prag; | |
8203 | end Build_Export_Import_Pragma; | |
8204 | ||
eb66e842 | 8205 | ------------------------------- |
8206 | -- Build_Predicate_Functions -- | |
8207 | ------------------------------- | |
d9f6a4ee | 8208 | |
eb66e842 | 8209 | -- The procedures that are constructed here have the form: |
d9f6a4ee | 8210 | |
eb66e842 | 8211 | -- function typPredicate (Ixxx : typ) return Boolean is |
8212 | -- begin | |
8213 | -- return | |
75491446 | 8214 | -- typ1Predicate (typ1 (Ixxx)) |
eb66e842 | 8215 | -- and then typ2Predicate (typ2 (Ixxx)) |
8216 | -- and then ...; | |
75491446 | 8217 | -- exp1 and then exp2 and then ... |
eb66e842 | 8218 | -- end typPredicate; |
d9f6a4ee | 8219 | |
eb66e842 | 8220 | -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that |
8221 | -- this is the point at which these expressions get analyzed, providing the | |
8222 | -- required delay, and typ1, typ2, are entities from which predicates are | |
8223 | -- inherited. Note that we do NOT generate Check pragmas, that's because we | |
8224 | -- use this function even if checks are off, e.g. for membership tests. | |
d9f6a4ee | 8225 | |
75491446 | 8226 | -- Note that the inherited predicates are evaluated first, as required by |
8227 | -- AI12-0071-1. | |
8228 | ||
8229 | -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on | |
8230 | -- the form of this return expression. | |
8231 | ||
eb66e842 | 8232 | -- If the expression has at least one Raise_Expression, then we also build |
8233 | -- the typPredicateM version of the function, in which any occurrence of a | |
8234 | -- Raise_Expression is converted to "return False". | |
d9f6a4ee | 8235 | |
1ecdfe4b | 8236 | -- WARNING: This routine manages Ghost regions. Return statements must be |
8237 | -- replaced by gotos which jump to the end of the routine and restore the | |
8238 | -- Ghost mode. | |
8239 | ||
eb66e842 | 8240 | procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is |
8241 | Loc : constant Source_Ptr := Sloc (Typ); | |
d9f6a4ee | 8242 | |
eb66e842 | 8243 | Expr : Node_Id; |
8244 | -- This is the expression for the result of the function. It is | |
8245 | -- is build by connecting the component predicates with AND THEN. | |
d9f6a4ee | 8246 | |
eb66e842 | 8247 | Expr_M : Node_Id; |
8248 | -- This is the corresponding return expression for the Predicate_M | |
8249 | -- function. It differs in that raise expressions are marked for | |
8250 | -- special expansion (see Process_REs). | |
d9f6a4ee | 8251 | |
9c20237a | 8252 | Object_Name : Name_Id; |
eb66e842 | 8253 | -- Name for argument of Predicate procedure. Note that we use the same |
499918a7 | 8254 | -- name for both predicate functions. That way the reference within the |
eb66e842 | 8255 | -- predicate expression is the same in both functions. |
d9f6a4ee | 8256 | |
9c20237a | 8257 | Object_Entity : Entity_Id; |
eb66e842 | 8258 | -- Entity for argument of Predicate procedure |
d9f6a4ee | 8259 | |
9c20237a | 8260 | Object_Entity_M : Entity_Id; |
8261 | -- Entity for argument of separate Predicate procedure when exceptions | |
8262 | -- are present in expression. | |
8263 | ||
02e5d0d0 | 8264 | FDecl : Node_Id; |
8265 | -- The function declaration | |
9c20237a | 8266 | |
02e5d0d0 | 8267 | SId : Entity_Id; |
8268 | -- Its entity | |
d9f6a4ee | 8269 | |
eb66e842 | 8270 | Raise_Expression_Present : Boolean := False; |
8271 | -- Set True if Expr has at least one Raise_Expression | |
d9f6a4ee | 8272 | |
75491446 | 8273 | procedure Add_Condition (Cond : Node_Id); |
8274 | -- Append Cond to Expr using "and then" (or just copy Cond to Expr if | |
8275 | -- Expr is empty). | |
d9f6a4ee | 8276 | |
eb66e842 | 8277 | procedure Add_Predicates; |
8278 | -- Appends expressions for any Predicate pragmas in the rep item chain | |
8279 | -- Typ to Expr. Note that we look only at items for this exact entity. | |
8280 | -- Inheritance of predicates for the parent type is done by calling the | |
8281 | -- Predicate_Function of the parent type, using Add_Call above. | |
d9f6a4ee | 8282 | |
75491446 | 8283 | procedure Add_Call (T : Entity_Id); |
8284 | -- Includes a call to the predicate function for type T in Expr if T | |
8285 | -- has predicates and Predicate_Function (T) is non-empty. | |
8286 | ||
eb66e842 | 8287 | function Process_RE (N : Node_Id) return Traverse_Result; |
8288 | -- Used in Process REs, tests if node N is a raise expression, and if | |
8289 | -- so, marks it to be converted to return False. | |
d9f6a4ee | 8290 | |
eb66e842 | 8291 | procedure Process_REs is new Traverse_Proc (Process_RE); |
8292 | -- Marks any raise expressions in Expr_M to return False | |
d9f6a4ee | 8293 | |
f9e26ff7 | 8294 | function Test_RE (N : Node_Id) return Traverse_Result; |
8295 | -- Used in Test_REs, tests one node for being a raise expression, and if | |
8296 | -- so sets Raise_Expression_Present True. | |
8297 | ||
8298 | procedure Test_REs is new Traverse_Proc (Test_RE); | |
8299 | -- Tests to see if Expr contains any raise expressions | |
8300 | ||
eb66e842 | 8301 | -------------- |
8302 | -- Add_Call -- | |
8303 | -------------- | |
d9f6a4ee | 8304 | |
eb66e842 | 8305 | procedure Add_Call (T : Entity_Id) is |
8306 | Exp : Node_Id; | |
d9f6a4ee | 8307 | |
eb66e842 | 8308 | begin |
8309 | if Present (T) and then Present (Predicate_Function (T)) then | |
8310 | Set_Has_Predicates (Typ); | |
d9f6a4ee | 8311 | |
74d7e7f5 | 8312 | -- Build the call to the predicate function of T. The type may be |
8313 | -- derived, so use an unchecked conversion for the actual. | |
d9f6a4ee | 8314 | |
eb66e842 | 8315 | Exp := |
8316 | Make_Predicate_Call | |
74d7e7f5 | 8317 | (Typ => T, |
8318 | Expr => | |
8319 | Unchecked_Convert_To (T, | |
8320 | Make_Identifier (Loc, Object_Name))); | |
d9f6a4ee | 8321 | |
75491446 | 8322 | -- "and"-in the call to evolving expression |
d9f6a4ee | 8323 | |
75491446 | 8324 | Add_Condition (Exp); |
d9f6a4ee | 8325 | |
eb66e842 | 8326 | -- Output info message on inheritance if required. Note we do not |
8327 | -- give this information for generic actual types, since it is | |
8328 | -- unwelcome noise in that case in instantiations. We also | |
8329 | -- generally suppress the message in instantiations, and also | |
8330 | -- if it involves internal names. | |
d9f6a4ee | 8331 | |
eb66e842 | 8332 | if Opt.List_Inherited_Aspects |
8333 | and then not Is_Generic_Actual_Type (Typ) | |
8334 | and then Instantiation_Depth (Sloc (Typ)) = 0 | |
8335 | and then not Is_Internal_Name (Chars (T)) | |
8336 | and then not Is_Internal_Name (Chars (Typ)) | |
8337 | then | |
8338 | Error_Msg_Sloc := Sloc (Predicate_Function (T)); | |
8339 | Error_Msg_Node_2 := T; | |
8340 | Error_Msg_N ("info: & inherits predicate from & #?L?", Typ); | |
8341 | end if; | |
8342 | end if; | |
8343 | end Add_Call; | |
d9f6a4ee | 8344 | |
75491446 | 8345 | ------------------- |
8346 | -- Add_Condition -- | |
8347 | ------------------- | |
8348 | ||
8349 | procedure Add_Condition (Cond : Node_Id) is | |
8350 | begin | |
8351 | -- This is the first predicate expression | |
8352 | ||
8353 | if No (Expr) then | |
8354 | Expr := Cond; | |
8355 | ||
8356 | -- Otherwise concatenate to the existing predicate expressions by | |
8357 | -- using "and then". | |
8358 | ||
8359 | else | |
8360 | Expr := | |
8361 | Make_And_Then (Loc, | |
8362 | Left_Opnd => Relocate_Node (Expr), | |
8363 | Right_Opnd => Cond); | |
8364 | end if; | |
8365 | end Add_Condition; | |
8366 | ||
eb66e842 | 8367 | -------------------- |
8368 | -- Add_Predicates -- | |
8369 | -------------------- | |
d9f6a4ee | 8370 | |
eb66e842 | 8371 | procedure Add_Predicates is |
f9e26ff7 | 8372 | procedure Add_Predicate (Prag : Node_Id); |
8373 | -- Concatenate the expression of predicate pragma Prag to Expr by | |
8374 | -- using a short circuit "and then" operator. | |
d9f6a4ee | 8375 | |
f9e26ff7 | 8376 | ------------------- |
8377 | -- Add_Predicate -- | |
8378 | ------------------- | |
d9f6a4ee | 8379 | |
f9e26ff7 | 8380 | procedure Add_Predicate (Prag : Node_Id) is |
8381 | procedure Replace_Type_Reference (N : Node_Id); | |
8382 | -- Replace a single occurrence N of the subtype name with a | |
8383 | -- reference to the formal of the predicate function. N can be an | |
8384 | -- identifier referencing the subtype, or a selected component, | |
8385 | -- representing an appropriately qualified occurrence of the | |
8386 | -- subtype name. | |
8387 | ||
8388 | procedure Replace_Type_References is | |
8389 | new Replace_Type_References_Generic (Replace_Type_Reference); | |
8390 | -- Traverse an expression changing every occurrence of an | |
8391 | -- identifier whose name matches the name of the subtype with a | |
8392 | -- reference to the formal parameter of the predicate function. | |
8393 | ||
8394 | ---------------------------- | |
8395 | -- Replace_Type_Reference -- | |
8396 | ---------------------------- | |
8397 | ||
8398 | procedure Replace_Type_Reference (N : Node_Id) is | |
8399 | begin | |
8400 | Rewrite (N, Make_Identifier (Sloc (N), Object_Name)); | |
8401 | -- Use the Sloc of the usage name, not the defining name | |
d9f6a4ee | 8402 | |
f9e26ff7 | 8403 | Set_Etype (N, Typ); |
8404 | Set_Entity (N, Object_Entity); | |
d97beb2f | 8405 | |
f9e26ff7 | 8406 | -- We want to treat the node as if it comes from source, so |
8407 | -- that ASIS will not ignore it. | |
d97beb2f | 8408 | |
f9e26ff7 | 8409 | Set_Comes_From_Source (N, True); |
8410 | end Replace_Type_Reference; | |
d97beb2f | 8411 | |
f9e26ff7 | 8412 | -- Local variables |
d97beb2f | 8413 | |
f9e26ff7 | 8414 | Asp : constant Node_Id := Corresponding_Aspect (Prag); |
8415 | Arg1 : Node_Id; | |
8416 | Arg2 : Node_Id; | |
d97beb2f | 8417 | |
f9e26ff7 | 8418 | -- Start of processing for Add_Predicate |
24c8d764 | 8419 | |
f9e26ff7 | 8420 | begin |
8421 | -- Extract the arguments of the pragma. The expression itself | |
8422 | -- is copied for use in the predicate function, to preserve the | |
8423 | -- original version for ASIS use. | |
d97beb2f | 8424 | |
f9e26ff7 | 8425 | Arg1 := First (Pragma_Argument_Associations (Prag)); |
8426 | Arg2 := Next (Arg1); | |
d97beb2f | 8427 | |
f9e26ff7 | 8428 | Arg1 := Get_Pragma_Arg (Arg1); |
8429 | Arg2 := New_Copy_Tree (Get_Pragma_Arg (Arg2)); | |
d97beb2f | 8430 | |
f9e26ff7 | 8431 | -- When the predicate pragma applies to the current type or its |
8432 | -- full view, replace all occurrences of the subtype name with | |
8433 | -- references to the formal parameter of the predicate function. | |
639c3741 | 8434 | |
f9e26ff7 | 8435 | if Entity (Arg1) = Typ |
8436 | or else Full_View (Entity (Arg1)) = Typ | |
8437 | then | |
8438 | Replace_Type_References (Arg2, Typ); | |
639c3741 | 8439 | |
f9e26ff7 | 8440 | -- If the predicate pragma comes from an aspect, replace the |
8441 | -- saved expression because we need the subtype references | |
8442 | -- replaced for the calls to Preanalyze_Spec_Expression in | |
8443 | -- Check_Aspect_At_xxx routines. | |
639c3741 | 8444 | |
f9e26ff7 | 8445 | if Present (Asp) then |
f9e26ff7 | 8446 | Set_Entity (Identifier (Asp), New_Copy_Tree (Arg2)); |
8447 | end if; | |
24c8d764 | 8448 | |
75491446 | 8449 | -- "and"-in the Arg2 condition to evolving expression |
639c3741 | 8450 | |
75491446 | 8451 | Add_Condition (Relocate_Node (Arg2)); |
f9e26ff7 | 8452 | end if; |
8453 | end Add_Predicate; | |
737e8460 | 8454 | |
f9e26ff7 | 8455 | -- Local variables |
737e8460 | 8456 | |
f9e26ff7 | 8457 | Ritem : Node_Id; |
d97beb2f | 8458 | |
f9e26ff7 | 8459 | -- Start of processing for Add_Predicates |
d97beb2f | 8460 | |
f9e26ff7 | 8461 | begin |
8462 | Ritem := First_Rep_Item (Typ); | |
74d7e7f5 | 8463 | |
8464 | -- If the type is private, check whether full view has inherited | |
8465 | -- predicates. | |
8466 | ||
8467 | if Is_Private_Type (Typ) and then No (Ritem) then | |
8468 | Ritem := First_Rep_Item (Full_View (Typ)); | |
8469 | end if; | |
8470 | ||
f9e26ff7 | 8471 | while Present (Ritem) loop |
8472 | if Nkind (Ritem) = N_Pragma | |
ddccc924 | 8473 | and then Pragma_Name (Ritem) = Name_Predicate |
f9e26ff7 | 8474 | then |
8475 | Add_Predicate (Ritem); | |
0ea02224 | 8476 | |
8477 | -- If the type is declared in an inner package it may be frozen | |
8478 | -- outside of the package, and the generated pragma has not been | |
8479 | -- analyzed yet, so capture the expression for the predicate | |
8480 | -- function at this point. | |
8481 | ||
8482 | elsif Nkind (Ritem) = N_Aspect_Specification | |
238921ae | 8483 | and then Present (Aspect_Rep_Item (Ritem)) |
8484 | and then Scope (Typ) /= Current_Scope | |
0ea02224 | 8485 | then |
8486 | declare | |
8487 | Prag : constant Node_Id := Aspect_Rep_Item (Ritem); | |
8488 | ||
8489 | begin | |
8490 | if Nkind (Prag) = N_Pragma | |
ddccc924 | 8491 | and then Pragma_Name (Prag) = Name_Predicate |
0ea02224 | 8492 | then |
8493 | Add_Predicate (Prag); | |
8494 | end if; | |
8495 | end; | |
eb66e842 | 8496 | end if; |
d97beb2f | 8497 | |
eb66e842 | 8498 | Next_Rep_Item (Ritem); |
8499 | end loop; | |
8500 | end Add_Predicates; | |
d97beb2f | 8501 | |
eb66e842 | 8502 | ---------------- |
8503 | -- Process_RE -- | |
8504 | ---------------- | |
d97beb2f | 8505 | |
eb66e842 | 8506 | function Process_RE (N : Node_Id) return Traverse_Result is |
d9f6a4ee | 8507 | begin |
eb66e842 | 8508 | if Nkind (N) = N_Raise_Expression then |
8509 | Set_Convert_To_Return_False (N); | |
8510 | return Skip; | |
d9f6a4ee | 8511 | else |
eb66e842 | 8512 | return OK; |
d9f6a4ee | 8513 | end if; |
eb66e842 | 8514 | end Process_RE; |
d7c2851f | 8515 | |
d9f6a4ee | 8516 | ------------- |
eb66e842 | 8517 | -- Test_RE -- |
d9f6a4ee | 8518 | ------------- |
d7c2851f | 8519 | |
eb66e842 | 8520 | function Test_RE (N : Node_Id) return Traverse_Result is |
d97beb2f | 8521 | begin |
eb66e842 | 8522 | if Nkind (N) = N_Raise_Expression then |
8523 | Raise_Expression_Present := True; | |
8524 | return Abandon; | |
8525 | else | |
8526 | return OK; | |
8527 | end if; | |
8528 | end Test_RE; | |
d97beb2f | 8529 | |
f9e26ff7 | 8530 | -- Local variables |
8531 | ||
72a98436 | 8532 | Mode : Ghost_Mode_Type; |
f9e26ff7 | 8533 | |
eb66e842 | 8534 | -- Start of processing for Build_Predicate_Functions |
d97beb2f | 8535 | |
eb66e842 | 8536 | begin |
8537 | -- Return if already built or if type does not have predicates | |
9dc88aea | 8538 | |
9c20237a | 8539 | SId := Predicate_Function (Typ); |
eb66e842 | 8540 | if not Has_Predicates (Typ) |
9c20237a | 8541 | or else (Present (SId) and then Has_Completion (SId)) |
eb66e842 | 8542 | then |
8543 | return; | |
8544 | end if; | |
d9f6a4ee | 8545 | |
30f8d103 | 8546 | -- The related type may be subject to pragma Ghost. Set the mode now to |
8547 | -- ensure that the predicate functions are properly marked as Ghost. | |
f9e26ff7 | 8548 | |
72a98436 | 8549 | Set_Ghost_Mode (Typ, Mode); |
f9e26ff7 | 8550 | |
eb66e842 | 8551 | -- Prepare to construct predicate expression |
d97beb2f | 8552 | |
eb66e842 | 8553 | Expr := Empty; |
d97beb2f | 8554 | |
9c20237a | 8555 | if Present (SId) then |
8556 | FDecl := Unit_Declaration_Node (SId); | |
8557 | ||
8558 | else | |
8559 | FDecl := Build_Predicate_Function_Declaration (Typ); | |
8560 | SId := Defining_Entity (FDecl); | |
8561 | end if; | |
8562 | ||
8563 | -- Recover name of formal parameter of function that replaces references | |
8564 | -- to the type in predicate expressions. | |
8565 | ||
8566 | Object_Entity := | |
8567 | Defining_Identifier | |
8568 | (First (Parameter_Specifications (Specification (FDecl)))); | |
8569 | ||
8570 | Object_Name := Chars (Object_Entity); | |
8571 | Object_Entity_M := Make_Defining_Identifier (Loc, Chars => Object_Name); | |
8572 | ||
75491446 | 8573 | -- Add predicates for ancestor if present. These must come before the |
8574 | -- ones for the current type, as required by AI12-0071-1. | |
d97beb2f | 8575 | |
eb66e842 | 8576 | declare |
74d7e7f5 | 8577 | Atyp : Entity_Id; |
d9f6a4ee | 8578 | begin |
74d7e7f5 | 8579 | Atyp := Nearest_Ancestor (Typ); |
8580 | ||
8581 | -- The type may be private but the full view may inherit predicates | |
8582 | ||
8583 | if No (Atyp) and then Is_Private_Type (Typ) then | |
8584 | Atyp := Nearest_Ancestor (Full_View (Typ)); | |
8585 | end if; | |
8586 | ||
eb66e842 | 8587 | if Present (Atyp) then |
8588 | Add_Call (Atyp); | |
8589 | end if; | |
8590 | end; | |
02e5d0d0 | 8591 | |
75491446 | 8592 | -- Add Predicates for the current type |
8593 | ||
8594 | Add_Predicates; | |
8595 | ||
eb66e842 | 8596 | -- Case where predicates are present |
9dc88aea | 8597 | |
eb66e842 | 8598 | if Present (Expr) then |
726fd56a | 8599 | |
eb66e842 | 8600 | -- Test for raise expression present |
726fd56a | 8601 | |
eb66e842 | 8602 | Test_REs (Expr); |
9dc88aea | 8603 | |
eb66e842 | 8604 | -- If raise expression is present, capture a copy of Expr for use |
8605 | -- in building the predicateM function version later on. For this | |
8606 | -- copy we replace references to Object_Entity by Object_Entity_M. | |
9dc88aea | 8607 | |
eb66e842 | 8608 | if Raise_Expression_Present then |
8609 | declare | |
299b347e | 8610 | Map : constant Elist_Id := New_Elmt_List; |
8611 | New_V : Entity_Id := Empty; | |
8612 | ||
8613 | -- The unanalyzed expression will be copied and appear in | |
8614 | -- both functions. Normally expressions do not declare new | |
8615 | -- entities, but quantified expressions do, so we need to | |
8616 | -- create new entities for their bound variables, to prevent | |
8617 | -- multiple definitions in gigi. | |
8618 | ||
8619 | function Reset_Loop_Variable (N : Node_Id) | |
8620 | return Traverse_Result; | |
8621 | ||
8622 | procedure Collect_Loop_Variables is | |
8623 | new Traverse_Proc (Reset_Loop_Variable); | |
8624 | ||
8625 | ------------------------ | |
8626 | -- Reset_Loop_Variable -- | |
8627 | ------------------------ | |
8628 | ||
8629 | function Reset_Loop_Variable (N : Node_Id) | |
8630 | return Traverse_Result | |
8631 | is | |
8632 | begin | |
8633 | if Nkind (N) = N_Iterator_Specification then | |
8634 | New_V := Make_Defining_Identifier | |
8635 | (Sloc (N), Chars (Defining_Identifier (N))); | |
8636 | ||
8637 | Set_Defining_Identifier (N, New_V); | |
8638 | end if; | |
8639 | ||
8640 | return OK; | |
8641 | end Reset_Loop_Variable; | |
8642 | ||
eb66e842 | 8643 | begin |
8644 | Append_Elmt (Object_Entity, Map); | |
8645 | Append_Elmt (Object_Entity_M, Map); | |
8646 | Expr_M := New_Copy_Tree (Expr, Map => Map); | |
299b347e | 8647 | Collect_Loop_Variables (Expr_M); |
eb66e842 | 8648 | end; |
8649 | end if; | |
d97beb2f | 8650 | |
eb66e842 | 8651 | -- Build the main predicate function |
9dc88aea | 8652 | |
eb66e842 | 8653 | declare |
eb66e842 | 8654 | SIdB : constant Entity_Id := |
8655 | Make_Defining_Identifier (Loc, | |
8656 | Chars => New_External_Name (Chars (Typ), "Predicate")); | |
8657 | -- The entity for the function body | |
9dc88aea | 8658 | |
eb66e842 | 8659 | Spec : Node_Id; |
eb66e842 | 8660 | FBody : Node_Id; |
9dc88aea | 8661 | |
eb66e842 | 8662 | begin |
eb66e842 | 8663 | -- The predicate function is shared between views of a type |
d97beb2f | 8664 | |
eb66e842 | 8665 | if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
8666 | Set_Predicate_Function (Full_View (Typ), SId); | |
d97beb2f | 8667 | end if; |
d97beb2f | 8668 | |
eb66e842 | 8669 | -- Build function body |
d97beb2f | 8670 | |
eb66e842 | 8671 | Spec := |
8672 | Make_Function_Specification (Loc, | |
8673 | Defining_Unit_Name => SIdB, | |
8674 | Parameter_Specifications => New_List ( | |
8675 | Make_Parameter_Specification (Loc, | |
8676 | Defining_Identifier => | |
8677 | Make_Defining_Identifier (Loc, Object_Name), | |
8678 | Parameter_Type => | |
8679 | New_Occurrence_Of (Typ, Loc))), | |
8680 | Result_Definition => | |
8681 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
d97beb2f | 8682 | |
eb66e842 | 8683 | FBody := |
8684 | Make_Subprogram_Body (Loc, | |
8685 | Specification => Spec, | |
8686 | Declarations => Empty_List, | |
8687 | Handled_Statement_Sequence => | |
8688 | Make_Handled_Sequence_Of_Statements (Loc, | |
8689 | Statements => New_List ( | |
8690 | Make_Simple_Return_Statement (Loc, | |
8691 | Expression => Expr)))); | |
9dc88aea | 8692 | |
9c20237a | 8693 | -- If declaration has not been analyzed yet, Insert declaration |
f021ee0f | 8694 | -- before freeze node. Insert body itself after freeze node. |
9c20237a | 8695 | |
8696 | if not Analyzed (FDecl) then | |
8697 | Insert_Before_And_Analyze (N, FDecl); | |
8698 | end if; | |
d97beb2f | 8699 | |
02e5d0d0 | 8700 | Insert_After_And_Analyze (N, FBody); |
6958c62c | 8701 | |
8702 | -- Static predicate functions are always side-effect free, and | |
8703 | -- in most cases dynamic predicate functions are as well. Mark | |
8704 | -- them as such whenever possible, so redundant predicate checks | |
7dd0b9b3 | 8705 | -- can be optimized. If there is a variable reference within the |
8706 | -- expression, the function is not pure. | |
b2e821de | 8707 | |
6958c62c | 8708 | if Expander_Active then |
7dd0b9b3 | 8709 | Set_Is_Pure (SId, |
8710 | Side_Effect_Free (Expr, Variable_Ref => True)); | |
6958c62c | 8711 | Set_Is_Inlined (SId); |
8712 | end if; | |
d9f6a4ee | 8713 | end; |
d97beb2f | 8714 | |
eb66e842 | 8715 | -- Test for raise expressions present and if so build M version |
d97beb2f | 8716 | |
eb66e842 | 8717 | if Raise_Expression_Present then |
8718 | declare | |
8719 | SId : constant Entity_Id := | |
8720 | Make_Defining_Identifier (Loc, | |
8721 | Chars => New_External_Name (Chars (Typ), "PredicateM")); | |
c96806b2 | 8722 | -- The entity for the function spec |
d97beb2f | 8723 | |
eb66e842 | 8724 | SIdB : constant Entity_Id := |
8725 | Make_Defining_Identifier (Loc, | |
8726 | Chars => New_External_Name (Chars (Typ), "PredicateM")); | |
8727 | -- The entity for the function body | |
b9e61b2a | 8728 | |
eb66e842 | 8729 | Spec : Node_Id; |
eb66e842 | 8730 | FBody : Node_Id; |
9c20237a | 8731 | FDecl : Node_Id; |
eb66e842 | 8732 | BTemp : Entity_Id; |
d97beb2f | 8733 | |
eb66e842 | 8734 | begin |
8735 | -- Mark any raise expressions for special expansion | |
d97beb2f | 8736 | |
eb66e842 | 8737 | Process_REs (Expr_M); |
d97beb2f | 8738 | |
eb66e842 | 8739 | -- Build function declaration |
d97beb2f | 8740 | |
eb66e842 | 8741 | Set_Ekind (SId, E_Function); |
8742 | Set_Is_Predicate_Function_M (SId); | |
8743 | Set_Predicate_Function_M (Typ, SId); | |
d97beb2f | 8744 | |
eb66e842 | 8745 | -- The predicate function is shared between views of a type |
d97beb2f | 8746 | |
eb66e842 | 8747 | if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
8748 | Set_Predicate_Function_M (Full_View (Typ), SId); | |
8749 | end if; | |
9dc88aea | 8750 | |
eb66e842 | 8751 | Spec := |
8752 | Make_Function_Specification (Loc, | |
8753 | Defining_Unit_Name => SId, | |
8754 | Parameter_Specifications => New_List ( | |
8755 | Make_Parameter_Specification (Loc, | |
8756 | Defining_Identifier => Object_Entity_M, | |
8757 | Parameter_Type => New_Occurrence_Of (Typ, Loc))), | |
8758 | Result_Definition => | |
8759 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
9dc88aea | 8760 | |
eb66e842 | 8761 | FDecl := |
8762 | Make_Subprogram_Declaration (Loc, | |
8763 | Specification => Spec); | |
9dc88aea | 8764 | |
eb66e842 | 8765 | -- Build function body |
9dc88aea | 8766 | |
eb66e842 | 8767 | Spec := |
8768 | Make_Function_Specification (Loc, | |
8769 | Defining_Unit_Name => SIdB, | |
8770 | Parameter_Specifications => New_List ( | |
8771 | Make_Parameter_Specification (Loc, | |
8772 | Defining_Identifier => | |
8773 | Make_Defining_Identifier (Loc, Object_Name), | |
8774 | Parameter_Type => | |
8775 | New_Occurrence_Of (Typ, Loc))), | |
8776 | Result_Definition => | |
8777 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
9dc88aea | 8778 | |
eb66e842 | 8779 | -- Build the body, we declare the boolean expression before |
8780 | -- doing the return, because we are not really confident of | |
8781 | -- what happens if a return appears within a return. | |
9dc88aea | 8782 | |
eb66e842 | 8783 | BTemp := |
8784 | Make_Defining_Identifier (Loc, | |
8785 | Chars => New_Internal_Name ('B')); | |
9dc88aea | 8786 | |
eb66e842 | 8787 | FBody := |
8788 | Make_Subprogram_Body (Loc, | |
8789 | Specification => Spec, | |
9dc88aea | 8790 | |
eb66e842 | 8791 | Declarations => New_List ( |
8792 | Make_Object_Declaration (Loc, | |
8793 | Defining_Identifier => BTemp, | |
8794 | Constant_Present => True, | |
8795 | Object_Definition => | |
8796 | New_Occurrence_Of (Standard_Boolean, Loc), | |
8797 | Expression => Expr_M)), | |
d97beb2f | 8798 | |
eb66e842 | 8799 | Handled_Statement_Sequence => |
8800 | Make_Handled_Sequence_Of_Statements (Loc, | |
8801 | Statements => New_List ( | |
8802 | Make_Simple_Return_Statement (Loc, | |
8803 | Expression => New_Occurrence_Of (BTemp, Loc))))); | |
d97beb2f | 8804 | |
eb66e842 | 8805 | -- Insert declaration before freeze node and body after |
d97beb2f | 8806 | |
eb66e842 | 8807 | Insert_Before_And_Analyze (N, FDecl); |
8808 | Insert_After_And_Analyze (N, FBody); | |
8809 | end; | |
8810 | end if; | |
9dc88aea | 8811 | |
3b23aaa0 | 8812 | -- See if we have a static predicate. Note that the answer may be |
8813 | -- yes even if we have an explicit Dynamic_Predicate present. | |
9dc88aea | 8814 | |
3b23aaa0 | 8815 | declare |
94d896aa | 8816 | PS : Boolean; |
3b23aaa0 | 8817 | EN : Node_Id; |
9dc88aea | 8818 | |
3b23aaa0 | 8819 | begin |
94d896aa | 8820 | if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then |
8821 | PS := False; | |
8822 | else | |
8823 | PS := Is_Predicate_Static (Expr, Object_Name); | |
8824 | end if; | |
8825 | ||
a360a0f7 | 8826 | -- Case where we have a predicate-static aspect |
9dc88aea | 8827 | |
3b23aaa0 | 8828 | if PS then |
9dc88aea | 8829 | |
3b23aaa0 | 8830 | -- We don't set Has_Static_Predicate_Aspect, since we can have |
8831 | -- any of the three cases (Predicate, Dynamic_Predicate, or | |
8832 | -- Static_Predicate) generating a predicate with an expression | |
a360a0f7 | 8833 | -- that is predicate-static. We just indicate that we have a |
3b23aaa0 | 8834 | -- predicate that can be treated as static. |
d7c2851f | 8835 | |
3b23aaa0 | 8836 | Set_Has_Static_Predicate (Typ); |
d7c2851f | 8837 | |
3b23aaa0 | 8838 | -- For discrete subtype, build the static predicate list |
9dc88aea | 8839 | |
3b23aaa0 | 8840 | if Is_Discrete_Type (Typ) then |
8841 | Build_Discrete_Static_Predicate (Typ, Expr, Object_Name); | |
8842 | ||
8843 | -- If we don't get a static predicate list, it means that we | |
8844 | -- have a case where this is not possible, most typically in | |
8845 | -- the case where we inherit a dynamic predicate. We do not | |
8846 | -- consider this an error, we just leave the predicate as | |
8847 | -- dynamic. But if we do succeed in building the list, then | |
8848 | -- we mark the predicate as static. | |
8849 | ||
5c6a5792 | 8850 | if No (Static_Discrete_Predicate (Typ)) then |
3b23aaa0 | 8851 | Set_Has_Static_Predicate (Typ, False); |
8852 | end if; | |
94d896aa | 8853 | |
8854 | -- For real or string subtype, save predicate expression | |
8855 | ||
8856 | elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then | |
8857 | Set_Static_Real_Or_String_Predicate (Typ, Expr); | |
3b23aaa0 | 8858 | end if; |
8859 | ||
8860 | -- Case of dynamic predicate (expression is not predicate-static) | |
9dc88aea | 8861 | |
eb66e842 | 8862 | else |
3b23aaa0 | 8863 | -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that |
8864 | -- is only set if we have an explicit Dynamic_Predicate aspect | |
8865 | -- given. Here we may simply have a Predicate aspect where the | |
8866 | -- expression happens not to be predicate-static. | |
8867 | ||
8868 | -- Emit an error when the predicate is categorized as static | |
8869 | -- but its expression is not predicate-static. | |
8870 | ||
8871 | -- First a little fiddling to get a nice location for the | |
8872 | -- message. If the expression is of the form (A and then B), | |
75491446 | 8873 | -- where A is an inherited predicate, then use the right |
8874 | -- operand for the Sloc. This avoids getting confused by a call | |
8875 | -- to an inherited predicate with a less convenient source | |
8876 | -- location. | |
3b23aaa0 | 8877 | |
8878 | EN := Expr; | |
75491446 | 8879 | while Nkind (EN) = N_And_Then |
8880 | and then Nkind (Left_Opnd (EN)) = N_Function_Call | |
8881 | and then Is_Predicate_Function | |
8882 | (Entity (Name (Left_Opnd (EN)))) | |
8883 | loop | |
8884 | EN := Right_Opnd (EN); | |
3b23aaa0 | 8885 | end loop; |
8886 | ||
8887 | -- Now post appropriate message | |
8888 | ||
8889 | if Has_Static_Predicate_Aspect (Typ) then | |
94d896aa | 8890 | if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then |
3b23aaa0 | 8891 | Error_Msg_F |
26279d91 | 8892 | ("expression is not predicate-static (RM 3.2.4(16-22))", |
3b23aaa0 | 8893 | EN); |
8894 | else | |
94d896aa | 8895 | Error_Msg_F |
8896 | ("static predicate requires scalar or string type", EN); | |
3b23aaa0 | 8897 | end if; |
8898 | end if; | |
eb66e842 | 8899 | end if; |
3b23aaa0 | 8900 | end; |
eb66e842 | 8901 | end if; |
f9e26ff7 | 8902 | |
72a98436 | 8903 | Restore_Ghost_Mode (Mode); |
eb66e842 | 8904 | end Build_Predicate_Functions; |
9dc88aea | 8905 | |
9c20237a | 8906 | ------------------------------------------ |
8907 | -- Build_Predicate_Function_Declaration -- | |
8908 | ------------------------------------------ | |
8909 | ||
1ecdfe4b | 8910 | -- WARNING: This routine manages Ghost regions. Return statements must be |
8911 | -- replaced by gotos which jump to the end of the routine and restore the | |
8912 | -- Ghost mode. | |
8913 | ||
9c20237a | 8914 | function Build_Predicate_Function_Declaration |
8915 | (Typ : Entity_Id) return Node_Id | |
8916 | is | |
8917 | Loc : constant Source_Ptr := Sloc (Typ); | |
8918 | ||
72a98436 | 8919 | Func_Decl : Node_Id; |
8920 | Func_Id : Entity_Id; | |
8921 | Mode : Ghost_Mode_Type; | |
8922 | Spec : Node_Id; | |
9c20237a | 8923 | |
72a98436 | 8924 | begin |
8925 | -- The related type may be subject to pragma Ghost. Set the mode now to | |
8926 | -- ensure that the predicate functions are properly marked as Ghost. | |
9c20237a | 8927 | |
72a98436 | 8928 | Set_Ghost_Mode (Typ, Mode); |
9c20237a | 8929 | |
72a98436 | 8930 | Func_Id := |
8931 | Make_Defining_Identifier (Loc, | |
8932 | Chars => New_External_Name (Chars (Typ), "Predicate")); | |
9c20237a | 8933 | |
3db675d2 | 8934 | -- The predicate function requires debug info when the predicates are |
8935 | -- subject to Source Coverage Obligations. | |
8936 | ||
8937 | if Opt.Generate_SCO then | |
8938 | Set_Debug_Info_Needed (Func_Id); | |
8939 | end if; | |
8940 | ||
9c20237a | 8941 | Spec := |
8942 | Make_Function_Specification (Loc, | |
72a98436 | 8943 | Defining_Unit_Name => Func_Id, |
9c20237a | 8944 | Parameter_Specifications => New_List ( |
8945 | Make_Parameter_Specification (Loc, | |
72a98436 | 8946 | Defining_Identifier => Make_Temporary (Loc, 'I'), |
9c20237a | 8947 | Parameter_Type => New_Occurrence_Of (Typ, Loc))), |
8948 | Result_Definition => | |
8949 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
8950 | ||
72a98436 | 8951 | Func_Decl := Make_Subprogram_Declaration (Loc, Specification => Spec); |
9c20237a | 8952 | |
72a98436 | 8953 | Set_Ekind (Func_Id, E_Function); |
8954 | Set_Etype (Func_Id, Standard_Boolean); | |
8955 | Set_Is_Internal (Func_Id); | |
8956 | Set_Is_Predicate_Function (Func_Id); | |
8957 | Set_Predicate_Function (Typ, Func_Id); | |
9c20237a | 8958 | |
72a98436 | 8959 | Insert_After (Parent (Typ), Func_Decl); |
8960 | Analyze (Func_Decl); | |
9c20237a | 8961 | |
72a98436 | 8962 | Restore_Ghost_Mode (Mode); |
9c20237a | 8963 | |
72a98436 | 8964 | return Func_Decl; |
9c20237a | 8965 | end Build_Predicate_Function_Declaration; |
8966 | ||
d9f6a4ee | 8967 | ----------------------------------------- |
8968 | -- Check_Aspect_At_End_Of_Declarations -- | |
8969 | ----------------------------------------- | |
9dc88aea | 8970 | |
d9f6a4ee | 8971 | procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is |
8972 | Ent : constant Entity_Id := Entity (ASN); | |
8973 | Ident : constant Node_Id := Identifier (ASN); | |
8974 | A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); | |
d7c2851f | 8975 | |
d9f6a4ee | 8976 | End_Decl_Expr : constant Node_Id := Entity (Ident); |
8977 | -- Expression to be analyzed at end of declarations | |
d7c2851f | 8978 | |
d9f6a4ee | 8979 | Freeze_Expr : constant Node_Id := Expression (ASN); |
6da581c1 | 8980 | -- Expression from call to Check_Aspect_At_Freeze_Point. |
d7c2851f | 8981 | |
25e4fa47 | 8982 | T : constant Entity_Id := Etype (Original_Node (Freeze_Expr)); |
6da581c1 | 8983 | -- Type required for preanalyze call. We use the original expression to |
8984 | -- get the proper type, to prevent cascaded errors when the expression | |
8985 | -- is constant-folded. | |
d7c2851f | 8986 | |
d9f6a4ee | 8987 | Err : Boolean; |
8988 | -- Set False if error | |
9dc88aea | 8989 | |
d9f6a4ee | 8990 | -- On entry to this procedure, Entity (Ident) contains a copy of the |
8991 | -- original expression from the aspect, saved for this purpose, and | |
8992 | -- but Expression (Ident) is a preanalyzed copy of the expression, | |
8993 | -- preanalyzed just after the freeze point. | |
9dc88aea | 8994 | |
d9f6a4ee | 8995 | procedure Check_Overloaded_Name; |
8996 | -- For aspects whose expression is simply a name, this routine checks if | |
8997 | -- the name is overloaded or not. If so, it verifies there is an | |
8998 | -- interpretation that matches the entity obtained at the freeze point, | |
8999 | -- otherwise the compiler complains. | |
9dc88aea | 9000 | |
d9f6a4ee | 9001 | --------------------------- |
9002 | -- Check_Overloaded_Name -- | |
9003 | --------------------------- | |
9004 | ||
9005 | procedure Check_Overloaded_Name is | |
d97beb2f | 9006 | begin |
d9f6a4ee | 9007 | if not Is_Overloaded (End_Decl_Expr) then |
5ac76cee | 9008 | Err := not Is_Entity_Name (End_Decl_Expr) |
9009 | or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr); | |
d9f6a4ee | 9010 | |
d97beb2f | 9011 | else |
d9f6a4ee | 9012 | Err := True; |
9dc88aea | 9013 | |
d9f6a4ee | 9014 | declare |
9015 | Index : Interp_Index; | |
9016 | It : Interp; | |
9dc88aea | 9017 | |
d9f6a4ee | 9018 | begin |
9019 | Get_First_Interp (End_Decl_Expr, Index, It); | |
9020 | while Present (It.Typ) loop | |
9021 | if It.Nam = Entity (Freeze_Expr) then | |
9022 | Err := False; | |
9023 | exit; | |
9024 | end if; | |
9025 | ||
9026 | Get_Next_Interp (Index, It); | |
9027 | end loop; | |
9028 | end; | |
9dc88aea | 9029 | end if; |
d9f6a4ee | 9030 | end Check_Overloaded_Name; |
9dc88aea | 9031 | |
d9f6a4ee | 9032 | -- Start of processing for Check_Aspect_At_End_Of_Declarations |
9dc88aea | 9033 | |
d9f6a4ee | 9034 | begin |
da3cad01 | 9035 | -- In an instance we do not perform the consistency check between freeze |
9036 | -- point and end of declarations, because it was done already in the | |
9037 | -- analysis of the generic. Furthermore, the delayed analysis of an | |
9038 | -- aspect of the instance may produce spurious errors when the generic | |
9039 | -- is a child unit that references entities in the parent (which might | |
9040 | -- not be in scope at the freeze point of the instance). | |
9041 | ||
9042 | if In_Instance then | |
9043 | return; | |
9044 | ||
d9f6a4ee | 9045 | -- Case of aspects Dimension, Dimension_System and Synchronization |
9dc88aea | 9046 | |
da3cad01 | 9047 | elsif A_Id = Aspect_Synchronization then |
d9f6a4ee | 9048 | return; |
d97beb2f | 9049 | |
d9f6a4ee | 9050 | -- Case of stream attributes, just have to compare entities. However, |
9051 | -- the expression is just a name (possibly overloaded), and there may | |
9052 | -- be stream operations declared for unrelated types, so we just need | |
9053 | -- to verify that one of these interpretations is the one available at | |
9054 | -- at the freeze point. | |
9dc88aea | 9055 | |
d9f6a4ee | 9056 | elsif A_Id = Aspect_Input or else |
f02a9a9a | 9057 | A_Id = Aspect_Output or else |
9058 | A_Id = Aspect_Read or else | |
9059 | A_Id = Aspect_Write | |
d9f6a4ee | 9060 | then |
9061 | Analyze (End_Decl_Expr); | |
9062 | Check_Overloaded_Name; | |
9dc88aea | 9063 | |
d9f6a4ee | 9064 | elsif A_Id = Aspect_Variable_Indexing or else |
9065 | A_Id = Aspect_Constant_Indexing or else | |
9066 | A_Id = Aspect_Default_Iterator or else | |
9067 | A_Id = Aspect_Iterator_Element | |
9068 | then | |
9069 | -- Make type unfrozen before analysis, to prevent spurious errors | |
9070 | -- about late attributes. | |
9dc88aea | 9071 | |
d9f6a4ee | 9072 | Set_Is_Frozen (Ent, False); |
9073 | Analyze (End_Decl_Expr); | |
9074 | Set_Is_Frozen (Ent, True); | |
9dc88aea | 9075 | |
d9f6a4ee | 9076 | -- If the end of declarations comes before any other freeze |
9077 | -- point, the Freeze_Expr is not analyzed: no check needed. | |
9dc88aea | 9078 | |
d9f6a4ee | 9079 | if Analyzed (Freeze_Expr) and then not In_Instance then |
9080 | Check_Overloaded_Name; | |
9081 | else | |
9082 | Err := False; | |
9083 | end if; | |
55e8372b | 9084 | |
d9f6a4ee | 9085 | -- All other cases |
55e8372b | 9086 | |
d9f6a4ee | 9087 | else |
c1efebf9 | 9088 | -- Indicate that the expression comes from an aspect specification, |
9089 | -- which is used in subsequent analysis even if expansion is off. | |
9090 | ||
9091 | Set_Parent (End_Decl_Expr, ASN); | |
9092 | ||
d9f6a4ee | 9093 | -- In a generic context the aspect expressions have not been |
9094 | -- preanalyzed, so do it now. There are no conformance checks | |
9095 | -- to perform in this case. | |
55e8372b | 9096 | |
d9f6a4ee | 9097 | if No (T) then |
9098 | Check_Aspect_At_Freeze_Point (ASN); | |
9099 | return; | |
55e8372b | 9100 | |
d9f6a4ee | 9101 | -- The default values attributes may be defined in the private part, |
9102 | -- and the analysis of the expression may take place when only the | |
9103 | -- partial view is visible. The expression must be scalar, so use | |
9104 | -- the full view to resolve. | |
55e8372b | 9105 | |
d9f6a4ee | 9106 | elsif (A_Id = Aspect_Default_Value |
9107 | or else | |
9108 | A_Id = Aspect_Default_Component_Value) | |
9109 | and then Is_Private_Type (T) | |
9110 | then | |
9111 | Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T)); | |
c1efebf9 | 9112 | |
d9f6a4ee | 9113 | else |
9114 | Preanalyze_Spec_Expression (End_Decl_Expr, T); | |
9115 | end if; | |
d97beb2f | 9116 | |
d9f6a4ee | 9117 | Err := not Fully_Conformant_Expressions (End_Decl_Expr, Freeze_Expr); |
9118 | end if; | |
55e8372b | 9119 | |
c1efebf9 | 9120 | -- Output error message if error. Force error on aspect specification |
9121 | -- even if there is an error on the expression itself. | |
55e8372b | 9122 | |
d9f6a4ee | 9123 | if Err then |
9124 | Error_Msg_NE | |
c1efebf9 | 9125 | ("!visibility of aspect for& changes after freeze point", |
d9f6a4ee | 9126 | ASN, Ent); |
9127 | Error_Msg_NE | |
9128 | ("info: & is frozen here, aspects evaluated at this point??", | |
9129 | Freeze_Node (Ent), Ent); | |
9130 | end if; | |
9131 | end Check_Aspect_At_End_Of_Declarations; | |
55e8372b | 9132 | |
d9f6a4ee | 9133 | ---------------------------------- |
9134 | -- Check_Aspect_At_Freeze_Point -- | |
9135 | ---------------------------------- | |
9dc88aea | 9136 | |
d9f6a4ee | 9137 | procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is |
9138 | Ident : constant Node_Id := Identifier (ASN); | |
9139 | -- Identifier (use Entity field to save expression) | |
9dc88aea | 9140 | |
d9f6a4ee | 9141 | A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); |
9dc88aea | 9142 | |
d9f6a4ee | 9143 | T : Entity_Id := Empty; |
9144 | -- Type required for preanalyze call | |
9dc88aea | 9145 | |
d9f6a4ee | 9146 | begin |
9147 | -- On entry to this procedure, Entity (Ident) contains a copy of the | |
9148 | -- original expression from the aspect, saved for this purpose. | |
9dc88aea | 9149 | |
d9f6a4ee | 9150 | -- On exit from this procedure Entity (Ident) is unchanged, still |
9151 | -- containing that copy, but Expression (Ident) is a preanalyzed copy | |
9152 | -- of the expression, preanalyzed just after the freeze point. | |
d97beb2f | 9153 | |
d9f6a4ee | 9154 | -- Make a copy of the expression to be preanalyzed |
d97beb2f | 9155 | |
d9f6a4ee | 9156 | Set_Expression (ASN, New_Copy_Tree (Entity (Ident))); |
d97beb2f | 9157 | |
d9f6a4ee | 9158 | -- Find type for preanalyze call |
d97beb2f | 9159 | |
d9f6a4ee | 9160 | case A_Id is |
9dc88aea | 9161 | |
d9f6a4ee | 9162 | -- No_Aspect should be impossible |
d97beb2f | 9163 | |
d9f6a4ee | 9164 | when No_Aspect => |
9165 | raise Program_Error; | |
9166 | ||
9167 | -- Aspects taking an optional boolean argument | |
d97beb2f | 9168 | |
99378362 | 9169 | when Boolean_Aspects |
9170 | | Library_Unit_Aspects | |
9171 | => | |
d9f6a4ee | 9172 | T := Standard_Boolean; |
d7c2851f | 9173 | |
d9f6a4ee | 9174 | -- Aspects corresponding to attribute definition clauses |
9dc88aea | 9175 | |
d9f6a4ee | 9176 | when Aspect_Address => |
9177 | T := RTE (RE_Address); | |
9dc88aea | 9178 | |
d9f6a4ee | 9179 | when Aspect_Attach_Handler => |
9180 | T := RTE (RE_Interrupt_ID); | |
d7c2851f | 9181 | |
99378362 | 9182 | when Aspect_Bit_Order |
9183 | | Aspect_Scalar_Storage_Order | |
9184 | => | |
d9f6a4ee | 9185 | T := RTE (RE_Bit_Order); |
d7c2851f | 9186 | |
d9f6a4ee | 9187 | when Aspect_Convention => |
9188 | return; | |
d7c2851f | 9189 | |
d9f6a4ee | 9190 | when Aspect_CPU => |
9191 | T := RTE (RE_CPU_Range); | |
d7c2851f | 9192 | |
d9f6a4ee | 9193 | -- Default_Component_Value is resolved with the component type |
d7c2851f | 9194 | |
d9f6a4ee | 9195 | when Aspect_Default_Component_Value => |
9196 | T := Component_Type (Entity (ASN)); | |
d7c2851f | 9197 | |
647fab54 | 9198 | when Aspect_Default_Storage_Pool => |
9199 | T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); | |
9200 | ||
d9f6a4ee | 9201 | -- Default_Value is resolved with the type entity in question |
d7c2851f | 9202 | |
d9f6a4ee | 9203 | when Aspect_Default_Value => |
9204 | T := Entity (ASN); | |
9dc88aea | 9205 | |
d9f6a4ee | 9206 | when Aspect_Dispatching_Domain => |
9207 | T := RTE (RE_Dispatching_Domain); | |
9dc88aea | 9208 | |
d9f6a4ee | 9209 | when Aspect_External_Tag => |
9210 | T := Standard_String; | |
9dc88aea | 9211 | |
d9f6a4ee | 9212 | when Aspect_External_Name => |
9213 | T := Standard_String; | |
9dc88aea | 9214 | |
d9f6a4ee | 9215 | when Aspect_Link_Name => |
9216 | T := Standard_String; | |
9dc88aea | 9217 | |
99378362 | 9218 | when Aspect_Interrupt_Priority |
9219 | | Aspect_Priority | |
9220 | => | |
d9f6a4ee | 9221 | T := Standard_Integer; |
d97beb2f | 9222 | |
d9f6a4ee | 9223 | when Aspect_Relative_Deadline => |
9224 | T := RTE (RE_Time_Span); | |
d97beb2f | 9225 | |
e6ce0468 | 9226 | when Aspect_Secondary_Stack_Size => |
9227 | T := Standard_Integer; | |
9228 | ||
d9f6a4ee | 9229 | when Aspect_Small => |
9230 | T := Universal_Real; | |
490beba6 | 9231 | |
d9f6a4ee | 9232 | -- For a simple storage pool, we have to retrieve the type of the |
9233 | -- pool object associated with the aspect's corresponding attribute | |
9234 | -- definition clause. | |
490beba6 | 9235 | |
d9f6a4ee | 9236 | when Aspect_Simple_Storage_Pool => |
9237 | T := Etype (Expression (Aspect_Rep_Item (ASN))); | |
d97beb2f | 9238 | |
d9f6a4ee | 9239 | when Aspect_Storage_Pool => |
9240 | T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); | |
d97beb2f | 9241 | |
99378362 | 9242 | when Aspect_Alignment |
9243 | | Aspect_Component_Size | |
9244 | | Aspect_Machine_Radix | |
9245 | | Aspect_Object_Size | |
9246 | | Aspect_Size | |
9247 | | Aspect_Storage_Size | |
9248 | | Aspect_Stream_Size | |
9249 | | Aspect_Value_Size | |
9250 | => | |
d9f6a4ee | 9251 | T := Any_Integer; |
9dc88aea | 9252 | |
04ae062f | 9253 | when Aspect_Linker_Section => |
9254 | T := Standard_String; | |
9255 | ||
d9f6a4ee | 9256 | when Aspect_Synchronization => |
9257 | return; | |
7d20685d | 9258 | |
d9f6a4ee | 9259 | -- Special case, the expression of these aspects is just an entity |
9260 | -- that does not need any resolution, so just analyze. | |
7d20685d | 9261 | |
99378362 | 9262 | when Aspect_Input |
9263 | | Aspect_Output | |
9264 | | Aspect_Read | |
9265 | | Aspect_Suppress | |
9266 | | Aspect_Unsuppress | |
9267 | | Aspect_Warnings | |
9268 | | Aspect_Write | |
9269 | => | |
d9f6a4ee | 9270 | Analyze (Expression (ASN)); |
9271 | return; | |
7d20685d | 9272 | |
d9f6a4ee | 9273 | -- Same for Iterator aspects, where the expression is a function |
9274 | -- name. Legality rules are checked separately. | |
89f1e35c | 9275 | |
99378362 | 9276 | when Aspect_Constant_Indexing |
9277 | | Aspect_Default_Iterator | |
9278 | | Aspect_Iterator_Element | |
9279 | | Aspect_Variable_Indexing | |
9280 | => | |
d9f6a4ee | 9281 | Analyze (Expression (ASN)); |
9282 | return; | |
7d20685d | 9283 | |
b3f8228a | 9284 | -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect. |
9285 | ||
9286 | when Aspect_Iterable => | |
3061ffde | 9287 | T := Entity (ASN); |
9288 | ||
b3f8228a | 9289 | declare |
a9f5fea7 | 9290 | Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T); |
3061ffde | 9291 | Assoc : Node_Id; |
9292 | Expr : Node_Id; | |
a9f5fea7 | 9293 | |
b3f8228a | 9294 | begin |
a9f5fea7 | 9295 | if Cursor = Any_Type then |
9296 | return; | |
9297 | end if; | |
9298 | ||
b3f8228a | 9299 | Assoc := First (Component_Associations (Expression (ASN))); |
9300 | while Present (Assoc) loop | |
3061ffde | 9301 | Expr := Expression (Assoc); |
9302 | Analyze (Expr); | |
a9f5fea7 | 9303 | |
9304 | if not Error_Posted (Expr) then | |
9305 | Resolve_Iterable_Operation | |
9306 | (Expr, Cursor, T, Chars (First (Choices (Assoc)))); | |
9307 | end if; | |
9308 | ||
b3f8228a | 9309 | Next (Assoc); |
9310 | end loop; | |
9311 | end; | |
3061ffde | 9312 | |
b3f8228a | 9313 | return; |
9314 | ||
d9f6a4ee | 9315 | -- Invariant/Predicate take boolean expressions |
7d20685d | 9316 | |
99378362 | 9317 | when Aspect_Dynamic_Predicate |
9318 | | Aspect_Invariant | |
9319 | | Aspect_Predicate | |
9320 | | Aspect_Static_Predicate | |
9321 | | Aspect_Type_Invariant | |
9322 | => | |
d9f6a4ee | 9323 | T := Standard_Boolean; |
7d20685d | 9324 | |
fdec445e | 9325 | when Aspect_Predicate_Failure => |
9326 | T := Standard_String; | |
9327 | ||
d9f6a4ee | 9328 | -- Here is the list of aspects that don't require delay analysis |
89f1e35c | 9329 | |
99378362 | 9330 | when Aspect_Abstract_State |
9331 | | Aspect_Annotate | |
9332 | | Aspect_Async_Readers | |
9333 | | Aspect_Async_Writers | |
9334 | | Aspect_Constant_After_Elaboration | |
9335 | | Aspect_Contract_Cases | |
9336 | | Aspect_Default_Initial_Condition | |
9337 | | Aspect_Depends | |
9338 | | Aspect_Dimension | |
9339 | | Aspect_Dimension_System | |
9340 | | Aspect_Effective_Reads | |
9341 | | Aspect_Effective_Writes | |
9342 | | Aspect_Extensions_Visible | |
9343 | | Aspect_Ghost | |
9344 | | Aspect_Global | |
9345 | | Aspect_Implicit_Dereference | |
9346 | | Aspect_Initial_Condition | |
9347 | | Aspect_Initializes | |
9348 | | Aspect_Max_Queue_Length | |
9349 | | Aspect_Obsolescent | |
9350 | | Aspect_Part_Of | |
9351 | | Aspect_Post | |
9352 | | Aspect_Postcondition | |
9353 | | Aspect_Pre | |
9354 | | Aspect_Precondition | |
9355 | | Aspect_Refined_Depends | |
9356 | | Aspect_Refined_Global | |
9357 | | Aspect_Refined_Post | |
9358 | | Aspect_Refined_State | |
9359 | | Aspect_SPARK_Mode | |
9360 | | Aspect_Test_Case | |
9361 | | Aspect_Unimplemented | |
9362 | | Aspect_Volatile_Function | |
9363 | => | |
d9f6a4ee | 9364 | raise Program_Error; |
2b184b2f | 9365 | |
d9f6a4ee | 9366 | end case; |
2b184b2f | 9367 | |
d9f6a4ee | 9368 | -- Do the preanalyze call |
2b184b2f | 9369 | |
d9f6a4ee | 9370 | Preanalyze_Spec_Expression (Expression (ASN), T); |
9371 | end Check_Aspect_At_Freeze_Point; | |
2b184b2f | 9372 | |
d9f6a4ee | 9373 | ----------------------------------- |
9374 | -- Check_Constant_Address_Clause -- | |
9375 | ----------------------------------- | |
2b184b2f | 9376 | |
d9f6a4ee | 9377 | procedure Check_Constant_Address_Clause |
9378 | (Expr : Node_Id; | |
9379 | U_Ent : Entity_Id) | |
9380 | is | |
9381 | procedure Check_At_Constant_Address (Nod : Node_Id); | |
9382 | -- Checks that the given node N represents a name whose 'Address is | |
9383 | -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the | |
9384 | -- address value is the same at the point of declaration of U_Ent and at | |
9385 | -- the time of elaboration of the address clause. | |
84ed7523 | 9386 | |
d9f6a4ee | 9387 | procedure Check_Expr_Constants (Nod : Node_Id); |
9388 | -- Checks that Nod meets the requirements for a constant address clause | |
9389 | -- in the sense of the enclosing procedure. | |
84ed7523 | 9390 | |
d9f6a4ee | 9391 | procedure Check_List_Constants (Lst : List_Id); |
9392 | -- Check that all elements of list Lst meet the requirements for a | |
9393 | -- constant address clause in the sense of the enclosing procedure. | |
84ed7523 | 9394 | |
d9f6a4ee | 9395 | ------------------------------- |
9396 | -- Check_At_Constant_Address -- | |
9397 | ------------------------------- | |
84ed7523 | 9398 | |
d9f6a4ee | 9399 | procedure Check_At_Constant_Address (Nod : Node_Id) is |
9400 | begin | |
9401 | if Is_Entity_Name (Nod) then | |
9402 | if Present (Address_Clause (Entity ((Nod)))) then | |
9403 | Error_Msg_NE | |
9404 | ("invalid address clause for initialized object &!", | |
d9f6a4ee | 9405 | Nod, U_Ent); |
99378362 | 9406 | Error_Msg_NE |
9407 | ("address for& cannot depend on another address clause! " | |
9408 | & "(RM 13.1(22))!", Nod, U_Ent); | |
84ed7523 | 9409 | |
d9f6a4ee | 9410 | elsif In_Same_Source_Unit (Entity (Nod), U_Ent) |
9411 | and then Sloc (U_Ent) < Sloc (Entity (Nod)) | |
9412 | then | |
9413 | Error_Msg_NE | |
9414 | ("invalid address clause for initialized object &!", | |
9415 | Nod, U_Ent); | |
9416 | Error_Msg_Node_2 := U_Ent; | |
9417 | Error_Msg_NE | |
9418 | ("\& must be defined before & (RM 13.1(22))!", | |
9419 | Nod, Entity (Nod)); | |
9420 | end if; | |
7d20685d | 9421 | |
d9f6a4ee | 9422 | elsif Nkind (Nod) = N_Selected_Component then |
9423 | declare | |
9424 | T : constant Entity_Id := Etype (Prefix (Nod)); | |
59f3e675 | 9425 | |
d9f6a4ee | 9426 | begin |
9427 | if (Is_Record_Type (T) | |
9428 | and then Has_Discriminants (T)) | |
9429 | or else | |
9430 | (Is_Access_Type (T) | |
f02a9a9a | 9431 | and then Is_Record_Type (Designated_Type (T)) |
9432 | and then Has_Discriminants (Designated_Type (T))) | |
d9f6a4ee | 9433 | then |
9434 | Error_Msg_NE | |
9435 | ("invalid address clause for initialized object &!", | |
9436 | Nod, U_Ent); | |
9437 | Error_Msg_N | |
99378362 | 9438 | ("\address cannot depend on component of discriminated " |
9439 | & "record (RM 13.1(22))!", Nod); | |
d9f6a4ee | 9440 | else |
9441 | Check_At_Constant_Address (Prefix (Nod)); | |
9442 | end if; | |
9443 | end; | |
89cc7147 | 9444 | |
d9f6a4ee | 9445 | elsif Nkind (Nod) = N_Indexed_Component then |
9446 | Check_At_Constant_Address (Prefix (Nod)); | |
9447 | Check_List_Constants (Expressions (Nod)); | |
89cc7147 | 9448 | |
84ed7523 | 9449 | else |
d9f6a4ee | 9450 | Check_Expr_Constants (Nod); |
84ed7523 | 9451 | end if; |
d9f6a4ee | 9452 | end Check_At_Constant_Address; |
81b424ac | 9453 | |
d9f6a4ee | 9454 | -------------------------- |
9455 | -- Check_Expr_Constants -- | |
9456 | -------------------------- | |
7b9b2f05 | 9457 | |
d9f6a4ee | 9458 | procedure Check_Expr_Constants (Nod : Node_Id) is |
9459 | Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent); | |
9460 | Ent : Entity_Id := Empty; | |
7b9b2f05 | 9461 | |
d9f6a4ee | 9462 | begin |
9463 | if Nkind (Nod) in N_Has_Etype | |
9464 | and then Etype (Nod) = Any_Type | |
7b9b2f05 | 9465 | then |
d9f6a4ee | 9466 | return; |
309c3053 | 9467 | end if; |
9468 | ||
d9f6a4ee | 9469 | case Nkind (Nod) is |
99378362 | 9470 | when N_Empty |
9471 | | N_Error | |
9472 | => | |
d9f6a4ee | 9473 | return; |
7d20685d | 9474 | |
99378362 | 9475 | when N_Expanded_Name |
9476 | | N_Identifier | |
9477 | => | |
d9f6a4ee | 9478 | Ent := Entity (Nod); |
7d20685d | 9479 | |
d9f6a4ee | 9480 | -- We need to look at the original node if it is different |
9481 | -- from the node, since we may have rewritten things and | |
9482 | -- substituted an identifier representing the rewrite. | |
7d20685d | 9483 | |
d9f6a4ee | 9484 | if Original_Node (Nod) /= Nod then |
9485 | Check_Expr_Constants (Original_Node (Nod)); | |
7d20685d | 9486 | |
d9f6a4ee | 9487 | -- If the node is an object declaration without initial |
9488 | -- value, some code has been expanded, and the expression | |
9489 | -- is not constant, even if the constituents might be | |
9490 | -- acceptable, as in A'Address + offset. | |
7d20685d | 9491 | |
d9f6a4ee | 9492 | if Ekind (Ent) = E_Variable |
9493 | and then | |
9494 | Nkind (Declaration_Node (Ent)) = N_Object_Declaration | |
9495 | and then | |
9496 | No (Expression (Declaration_Node (Ent))) | |
9497 | then | |
9498 | Error_Msg_NE | |
9499 | ("invalid address clause for initialized object &!", | |
9500 | Nod, U_Ent); | |
89f1e35c | 9501 | |
d9f6a4ee | 9502 | -- If entity is constant, it may be the result of expanding |
9503 | -- a check. We must verify that its declaration appears | |
9504 | -- before the object in question, else we also reject the | |
9505 | -- address clause. | |
7d20685d | 9506 | |
d9f6a4ee | 9507 | elsif Ekind (Ent) = E_Constant |
9508 | and then In_Same_Source_Unit (Ent, U_Ent) | |
9509 | and then Sloc (Ent) > Loc_U_Ent | |
9510 | then | |
9511 | Error_Msg_NE | |
9512 | ("invalid address clause for initialized object &!", | |
9513 | Nod, U_Ent); | |
9514 | end if; | |
7d20685d | 9515 | |
d9f6a4ee | 9516 | return; |
9517 | end if; | |
7d20685d | 9518 | |
d9f6a4ee | 9519 | -- Otherwise look at the identifier and see if it is OK |
7d20685d | 9520 | |
d9f6a4ee | 9521 | if Ekind_In (Ent, E_Named_Integer, E_Named_Real) |
9522 | or else Is_Type (Ent) | |
9523 | then | |
9524 | return; | |
7d20685d | 9525 | |
f02a9a9a | 9526 | elsif Ekind_In (Ent, E_Constant, E_In_Parameter) then |
9527 | ||
d9f6a4ee | 9528 | -- This is the case where we must have Ent defined before |
9529 | -- U_Ent. Clearly if they are in different units this | |
9530 | -- requirement is met since the unit containing Ent is | |
9531 | -- already processed. | |
7d20685d | 9532 | |
d9f6a4ee | 9533 | if not In_Same_Source_Unit (Ent, U_Ent) then |
9534 | return; | |
7d20685d | 9535 | |
d9f6a4ee | 9536 | -- Otherwise location of Ent must be before the location |
9537 | -- of U_Ent, that's what prior defined means. | |
7d20685d | 9538 | |
d9f6a4ee | 9539 | elsif Sloc (Ent) < Loc_U_Ent then |
9540 | return; | |
6c545057 | 9541 | |
d9f6a4ee | 9542 | else |
9543 | Error_Msg_NE | |
9544 | ("invalid address clause for initialized object &!", | |
9545 | Nod, U_Ent); | |
9546 | Error_Msg_Node_2 := U_Ent; | |
9547 | Error_Msg_NE | |
9548 | ("\& must be defined before & (RM 13.1(22))!", | |
9549 | Nod, Ent); | |
9550 | end if; | |
37c6e44c | 9551 | |
d9f6a4ee | 9552 | elsif Nkind (Original_Node (Nod)) = N_Function_Call then |
9553 | Check_Expr_Constants (Original_Node (Nod)); | |
6c545057 | 9554 | |
d9f6a4ee | 9555 | else |
9556 | Error_Msg_NE | |
9557 | ("invalid address clause for initialized object &!", | |
9558 | Nod, U_Ent); | |
3cdbaa5a | 9559 | |
d9f6a4ee | 9560 | if Comes_From_Source (Ent) then |
9561 | Error_Msg_NE | |
9562 | ("\reference to variable& not allowed" | |
9563 | & " (RM 13.1(22))!", Nod, Ent); | |
9564 | else | |
9565 | Error_Msg_N | |
9566 | ("non-static expression not allowed" | |
9567 | & " (RM 13.1(22))!", Nod); | |
9568 | end if; | |
9569 | end if; | |
3cdbaa5a | 9570 | |
d9f6a4ee | 9571 | when N_Integer_Literal => |
7f694ca2 | 9572 | |
d9f6a4ee | 9573 | -- If this is a rewritten unchecked conversion, in a system |
9574 | -- where Address is an integer type, always use the base type | |
9575 | -- for a literal value. This is user-friendly and prevents | |
9576 | -- order-of-elaboration issues with instances of unchecked | |
9577 | -- conversion. | |
3cdbaa5a | 9578 | |
d9f6a4ee | 9579 | if Nkind (Original_Node (Nod)) = N_Function_Call then |
9580 | Set_Etype (Nod, Base_Type (Etype (Nod))); | |
9581 | end if; | |
e1cedbae | 9582 | |
99378362 | 9583 | when N_Character_Literal |
9584 | | N_Real_Literal | |
9585 | | N_String_Literal | |
9586 | => | |
d9f6a4ee | 9587 | return; |
7d20685d | 9588 | |
d9f6a4ee | 9589 | when N_Range => |
9590 | Check_Expr_Constants (Low_Bound (Nod)); | |
9591 | Check_Expr_Constants (High_Bound (Nod)); | |
231eb581 | 9592 | |
d9f6a4ee | 9593 | when N_Explicit_Dereference => |
9594 | Check_Expr_Constants (Prefix (Nod)); | |
231eb581 | 9595 | |
d9f6a4ee | 9596 | when N_Indexed_Component => |
9597 | Check_Expr_Constants (Prefix (Nod)); | |
9598 | Check_List_Constants (Expressions (Nod)); | |
7d20685d | 9599 | |
d9f6a4ee | 9600 | when N_Slice => |
9601 | Check_Expr_Constants (Prefix (Nod)); | |
9602 | Check_Expr_Constants (Discrete_Range (Nod)); | |
cb4c311d | 9603 | |
d9f6a4ee | 9604 | when N_Selected_Component => |
9605 | Check_Expr_Constants (Prefix (Nod)); | |
6144c105 | 9606 | |
d9f6a4ee | 9607 | when N_Attribute_Reference => |
9608 | if Nam_In (Attribute_Name (Nod), Name_Address, | |
9609 | Name_Access, | |
9610 | Name_Unchecked_Access, | |
9611 | Name_Unrestricted_Access) | |
9612 | then | |
9613 | Check_At_Constant_Address (Prefix (Nod)); | |
6144c105 | 9614 | |
d9f6a4ee | 9615 | else |
9616 | Check_Expr_Constants (Prefix (Nod)); | |
9617 | Check_List_Constants (Expressions (Nod)); | |
9618 | end if; | |
a7a4a7c2 | 9619 | |
d9f6a4ee | 9620 | when N_Aggregate => |
9621 | Check_List_Constants (Component_Associations (Nod)); | |
9622 | Check_List_Constants (Expressions (Nod)); | |
7d20685d | 9623 | |
d9f6a4ee | 9624 | when N_Component_Association => |
9625 | Check_Expr_Constants (Expression (Nod)); | |
e1cedbae | 9626 | |
d9f6a4ee | 9627 | when N_Extension_Aggregate => |
9628 | Check_Expr_Constants (Ancestor_Part (Nod)); | |
9629 | Check_List_Constants (Component_Associations (Nod)); | |
9630 | Check_List_Constants (Expressions (Nod)); | |
3cdbaa5a | 9631 | |
d9f6a4ee | 9632 | when N_Null => |
9633 | return; | |
3cdbaa5a | 9634 | |
99378362 | 9635 | when N_Binary_Op |
9636 | | N_Membership_Test | |
9637 | | N_Short_Circuit | |
9638 | => | |
d9f6a4ee | 9639 | Check_Expr_Constants (Left_Opnd (Nod)); |
9640 | Check_Expr_Constants (Right_Opnd (Nod)); | |
e1cedbae | 9641 | |
d9f6a4ee | 9642 | when N_Unary_Op => |
9643 | Check_Expr_Constants (Right_Opnd (Nod)); | |
7f694ca2 | 9644 | |
99378362 | 9645 | when N_Allocator |
9646 | | N_Qualified_Expression | |
9647 | | N_Type_Conversion | |
9648 | | N_Unchecked_Type_Conversion | |
9649 | => | |
d9f6a4ee | 9650 | Check_Expr_Constants (Expression (Nod)); |
47a46747 | 9651 | |
d9f6a4ee | 9652 | when N_Function_Call => |
9653 | if not Is_Pure (Entity (Name (Nod))) then | |
9654 | Error_Msg_NE | |
9655 | ("invalid address clause for initialized object &!", | |
9656 | Nod, U_Ent); | |
7f694ca2 | 9657 | |
d9f6a4ee | 9658 | Error_Msg_NE |
9659 | ("\function & is not pure (RM 13.1(22))!", | |
9660 | Nod, Entity (Name (Nod))); | |
b55f7641 | 9661 | |
d9f6a4ee | 9662 | else |
9663 | Check_List_Constants (Parameter_Associations (Nod)); | |
9664 | end if; | |
b55f7641 | 9665 | |
d9f6a4ee | 9666 | when N_Parameter_Association => |
9667 | Check_Expr_Constants (Explicit_Actual_Parameter (Nod)); | |
7d20685d | 9668 | |
d9f6a4ee | 9669 | when others => |
9670 | Error_Msg_NE | |
9671 | ("invalid address clause for initialized object &!", | |
9672 | Nod, U_Ent); | |
9673 | Error_Msg_NE | |
9674 | ("\must be constant defined before& (RM 13.1(22))!", | |
9675 | Nod, U_Ent); | |
9676 | end case; | |
9677 | end Check_Expr_Constants; | |
7d20685d | 9678 | |
d9f6a4ee | 9679 | -------------------------- |
9680 | -- Check_List_Constants -- | |
9681 | -------------------------- | |
89f1e35c | 9682 | |
d9f6a4ee | 9683 | procedure Check_List_Constants (Lst : List_Id) is |
9684 | Nod1 : Node_Id; | |
7d20685d | 9685 | |
d9f6a4ee | 9686 | begin |
9687 | if Present (Lst) then | |
9688 | Nod1 := First (Lst); | |
9689 | while Present (Nod1) loop | |
9690 | Check_Expr_Constants (Nod1); | |
9691 | Next (Nod1); | |
9692 | end loop; | |
9693 | end if; | |
9694 | end Check_List_Constants; | |
81b424ac | 9695 | |
d9f6a4ee | 9696 | -- Start of processing for Check_Constant_Address_Clause |
81b424ac | 9697 | |
d9f6a4ee | 9698 | begin |
9699 | -- If rep_clauses are to be ignored, no need for legality checks. In | |
9c7948d7 | 9700 | -- particular, no need to pester user about rep clauses that violate the |
9701 | -- rule on constant addresses, given that these clauses will be removed | |
9702 | -- by Freeze before they reach the back end. Similarly in CodePeer mode, | |
9703 | -- we want to relax these checks. | |
7d20685d | 9704 | |
f1a9be43 | 9705 | if not Ignore_Rep_Clauses and not CodePeer_Mode then |
d9f6a4ee | 9706 | Check_Expr_Constants (Expr); |
9707 | end if; | |
9708 | end Check_Constant_Address_Clause; | |
7d20685d | 9709 | |
6653b695 | 9710 | --------------------------- |
9711 | -- Check_Pool_Size_Clash -- | |
9712 | --------------------------- | |
9713 | ||
9714 | procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is | |
9715 | Post : Node_Id; | |
9716 | ||
9717 | begin | |
9718 | -- We need to find out which one came first. Note that in the case of | |
9719 | -- aspects mixed with pragmas there are cases where the processing order | |
9720 | -- is reversed, which is why we do the check here. | |
9721 | ||
9722 | if Sloc (SP) < Sloc (SS) then | |
9723 | Error_Msg_Sloc := Sloc (SP); | |
9724 | Post := SS; | |
9725 | Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent); | |
9726 | ||
9727 | else | |
9728 | Error_Msg_Sloc := Sloc (SS); | |
9729 | Post := SP; | |
9730 | Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent); | |
9731 | end if; | |
9732 | ||
9733 | Error_Msg_N | |
9734 | ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post); | |
9735 | end Check_Pool_Size_Clash; | |
9736 | ||
d9f6a4ee | 9737 | ---------------------------------------- |
9738 | -- Check_Record_Representation_Clause -- | |
9739 | ---------------------------------------- | |
85696508 | 9740 | |
d9f6a4ee | 9741 | procedure Check_Record_Representation_Clause (N : Node_Id) is |
9742 | Loc : constant Source_Ptr := Sloc (N); | |
9743 | Ident : constant Node_Id := Identifier (N); | |
9744 | Rectype : Entity_Id; | |
9745 | Fent : Entity_Id; | |
9746 | CC : Node_Id; | |
9747 | Fbit : Uint; | |
9748 | Lbit : Uint; | |
9749 | Hbit : Uint := Uint_0; | |
9750 | Comp : Entity_Id; | |
9751 | Pcomp : Entity_Id; | |
89f1e35c | 9752 | |
d9f6a4ee | 9753 | Max_Bit_So_Far : Uint; |
9754 | -- Records the maximum bit position so far. If all field positions | |
9755 | -- are monotonically increasing, then we can skip the circuit for | |
9756 | -- checking for overlap, since no overlap is possible. | |
85696508 | 9757 | |
d9f6a4ee | 9758 | Tagged_Parent : Entity_Id := Empty; |
9759 | -- This is set in the case of a derived tagged type for which we have | |
9760 | -- Is_Fully_Repped_Tagged_Type True (indicating that all components are | |
9761 | -- positioned by record representation clauses). In this case we must | |
9762 | -- check for overlap between components of this tagged type, and the | |
9763 | -- components of its parent. Tagged_Parent will point to this parent | |
9764 | -- type. For all other cases Tagged_Parent is left set to Empty. | |
7d20685d | 9765 | |
d9f6a4ee | 9766 | Parent_Last_Bit : Uint; |
9767 | -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the | |
9768 | -- last bit position for any field in the parent type. We only need to | |
9769 | -- check overlap for fields starting below this point. | |
7d20685d | 9770 | |
d9f6a4ee | 9771 | Overlap_Check_Required : Boolean; |
9772 | -- Used to keep track of whether or not an overlap check is required | |
7d20685d | 9773 | |
d9f6a4ee | 9774 | Overlap_Detected : Boolean := False; |
9775 | -- Set True if an overlap is detected | |
d6f39728 | 9776 | |
d9f6a4ee | 9777 | Ccount : Natural := 0; |
9778 | -- Number of component clauses in record rep clause | |
d6f39728 | 9779 | |
d9f6a4ee | 9780 | procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id); |
9781 | -- Given two entities for record components or discriminants, checks | |
9782 | -- if they have overlapping component clauses and issues errors if so. | |
d6f39728 | 9783 | |
d9f6a4ee | 9784 | procedure Find_Component; |
9785 | -- Finds component entity corresponding to current component clause (in | |
9786 | -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin | |
9787 | -- start/stop bits for the field. If there is no matching component or | |
9788 | -- if the matching component does not have a component clause, then | |
9789 | -- that's an error and Comp is set to Empty, but no error message is | |
9790 | -- issued, since the message was already given. Comp is also set to | |
9791 | -- Empty if the current "component clause" is in fact a pragma. | |
d6f39728 | 9792 | |
d9f6a4ee | 9793 | ----------------------------- |
9794 | -- Check_Component_Overlap -- | |
9795 | ----------------------------- | |
9796 | ||
9797 | procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is | |
9798 | CC1 : constant Node_Id := Component_Clause (C1_Ent); | |
9799 | CC2 : constant Node_Id := Component_Clause (C2_Ent); | |
d6f39728 | 9800 | |
d6f39728 | 9801 | begin |
d9f6a4ee | 9802 | if Present (CC1) and then Present (CC2) then |
d6f39728 | 9803 | |
d9f6a4ee | 9804 | -- Exclude odd case where we have two tag components in the same |
9805 | -- record, both at location zero. This seems a bit strange, but | |
9806 | -- it seems to happen in some circumstances, perhaps on an error. | |
9807 | ||
9808 | if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then | |
9809 | return; | |
d6f39728 | 9810 | end if; |
9811 | ||
d9f6a4ee | 9812 | -- Here we check if the two fields overlap |
9813 | ||
d6f39728 | 9814 | declare |
d9f6a4ee | 9815 | S1 : constant Uint := Component_Bit_Offset (C1_Ent); |
9816 | S2 : constant Uint := Component_Bit_Offset (C2_Ent); | |
9817 | E1 : constant Uint := S1 + Esize (C1_Ent); | |
9818 | E2 : constant Uint := S2 + Esize (C2_Ent); | |
d6f39728 | 9819 | |
9820 | begin | |
d9f6a4ee | 9821 | if E2 <= S1 or else E1 <= S2 then |
9822 | null; | |
d6f39728 | 9823 | else |
d9f6a4ee | 9824 | Error_Msg_Node_2 := Component_Name (CC2); |
9825 | Error_Msg_Sloc := Sloc (Error_Msg_Node_2); | |
9826 | Error_Msg_Node_1 := Component_Name (CC1); | |
9827 | Error_Msg_N | |
9828 | ("component& overlaps & #", Component_Name (CC1)); | |
9829 | Overlap_Detected := True; | |
d6f39728 | 9830 | end if; |
9831 | end; | |
d6f39728 | 9832 | end if; |
d9f6a4ee | 9833 | end Check_Component_Overlap; |
d6f39728 | 9834 | |
d9f6a4ee | 9835 | -------------------- |
9836 | -- Find_Component -- | |
9837 | -------------------- | |
9dfe12ae | 9838 | |
d9f6a4ee | 9839 | procedure Find_Component is |
9dfe12ae | 9840 | |
d9f6a4ee | 9841 | procedure Search_Component (R : Entity_Id); |
9842 | -- Search components of R for a match. If found, Comp is set | |
9dfe12ae | 9843 | |
d9f6a4ee | 9844 | ---------------------- |
9845 | -- Search_Component -- | |
9846 | ---------------------- | |
e7b2d6bc | 9847 | |
d9f6a4ee | 9848 | procedure Search_Component (R : Entity_Id) is |
9849 | begin | |
9850 | Comp := First_Component_Or_Discriminant (R); | |
9851 | while Present (Comp) loop | |
e7b2d6bc | 9852 | |
d9f6a4ee | 9853 | -- Ignore error of attribute name for component name (we |
9854 | -- already gave an error message for this, so no need to | |
9855 | -- complain here) | |
e7b2d6bc | 9856 | |
d9f6a4ee | 9857 | if Nkind (Component_Name (CC)) = N_Attribute_Reference then |
9858 | null; | |
9859 | else | |
9860 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
9dfe12ae | 9861 | end if; |
9862 | ||
d9f6a4ee | 9863 | Next_Component_Or_Discriminant (Comp); |
9864 | end loop; | |
9865 | end Search_Component; | |
d6f39728 | 9866 | |
d9f6a4ee | 9867 | -- Start of processing for Find_Component |
d6f39728 | 9868 | |
d9f6a4ee | 9869 | begin |
9870 | -- Return with Comp set to Empty if we have a pragma | |
d6f39728 | 9871 | |
d9f6a4ee | 9872 | if Nkind (CC) = N_Pragma then |
9873 | Comp := Empty; | |
9874 | return; | |
9875 | end if; | |
d6f39728 | 9876 | |
d9f6a4ee | 9877 | -- Search current record for matching component |
d6f39728 | 9878 | |
d9f6a4ee | 9879 | Search_Component (Rectype); |
9dfe12ae | 9880 | |
d9f6a4ee | 9881 | -- If not found, maybe component of base type discriminant that is |
9882 | -- absent from statically constrained first subtype. | |
e7b2d6bc | 9883 | |
d9f6a4ee | 9884 | if No (Comp) then |
9885 | Search_Component (Base_Type (Rectype)); | |
9886 | end if; | |
e7b2d6bc | 9887 | |
d9f6a4ee | 9888 | -- If no component, or the component does not reference the component |
9889 | -- clause in question, then there was some previous error for which | |
9890 | -- we already gave a message, so just return with Comp Empty. | |
d6f39728 | 9891 | |
d9f6a4ee | 9892 | if No (Comp) or else Component_Clause (Comp) /= CC then |
9893 | Check_Error_Detected; | |
9894 | Comp := Empty; | |
93735cb8 | 9895 | |
d9f6a4ee | 9896 | -- Normal case where we have a component clause |
93735cb8 | 9897 | |
d9f6a4ee | 9898 | else |
9899 | Fbit := Component_Bit_Offset (Comp); | |
9900 | Lbit := Fbit + Esize (Comp) - 1; | |
9901 | end if; | |
9902 | end Find_Component; | |
93735cb8 | 9903 | |
d9f6a4ee | 9904 | -- Start of processing for Check_Record_Representation_Clause |
d6f39728 | 9905 | |
d9f6a4ee | 9906 | begin |
9907 | Find_Type (Ident); | |
9908 | Rectype := Entity (Ident); | |
d6f39728 | 9909 | |
d9f6a4ee | 9910 | if Rectype = Any_Type then |
9911 | return; | |
9912 | else | |
9913 | Rectype := Underlying_Type (Rectype); | |
9914 | end if; | |
d6f39728 | 9915 | |
d9f6a4ee | 9916 | -- See if we have a fully repped derived tagged type |
d6f39728 | 9917 | |
d9f6a4ee | 9918 | declare |
9919 | PS : constant Entity_Id := Parent_Subtype (Rectype); | |
d6f39728 | 9920 | |
d9f6a4ee | 9921 | begin |
9922 | if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then | |
9923 | Tagged_Parent := PS; | |
d6f39728 | 9924 | |
d9f6a4ee | 9925 | -- Find maximum bit of any component of the parent type |
d6f39728 | 9926 | |
d9f6a4ee | 9927 | Parent_Last_Bit := UI_From_Int (System_Address_Size - 1); |
9928 | Pcomp := First_Entity (Tagged_Parent); | |
9929 | while Present (Pcomp) loop | |
9930 | if Ekind_In (Pcomp, E_Discriminant, E_Component) then | |
9931 | if Component_Bit_Offset (Pcomp) /= No_Uint | |
9932 | and then Known_Static_Esize (Pcomp) | |
9933 | then | |
9934 | Parent_Last_Bit := | |
9935 | UI_Max | |
9936 | (Parent_Last_Bit, | |
9937 | Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1); | |
9938 | end if; | |
b7df4cda | 9939 | else |
9940 | ||
9941 | -- Skip anonymous types generated for constrained array | |
9942 | -- or record components. | |
d9f6a4ee | 9943 | |
b7df4cda | 9944 | null; |
d6f39728 | 9945 | end if; |
b7df4cda | 9946 | |
9947 | Next_Entity (Pcomp); | |
d9f6a4ee | 9948 | end loop; |
9949 | end if; | |
9950 | end; | |
d6f39728 | 9951 | |
d9f6a4ee | 9952 | -- All done if no component clauses |
d6f39728 | 9953 | |
d9f6a4ee | 9954 | CC := First (Component_Clauses (N)); |
d6f39728 | 9955 | |
d9f6a4ee | 9956 | if No (CC) then |
9957 | return; | |
9958 | end if; | |
d6f39728 | 9959 | |
d9f6a4ee | 9960 | -- If a tag is present, then create a component clause that places it |
9961 | -- at the start of the record (otherwise gigi may place it after other | |
9962 | -- fields that have rep clauses). | |
d6f39728 | 9963 | |
d9f6a4ee | 9964 | Fent := First_Entity (Rectype); |
d6f39728 | 9965 | |
d9f6a4ee | 9966 | if Nkind (Fent) = N_Defining_Identifier |
9967 | and then Chars (Fent) = Name_uTag | |
9968 | then | |
9969 | Set_Component_Bit_Offset (Fent, Uint_0); | |
9970 | Set_Normalized_Position (Fent, Uint_0); | |
9971 | Set_Normalized_First_Bit (Fent, Uint_0); | |
9972 | Set_Normalized_Position_Max (Fent, Uint_0); | |
9973 | Init_Esize (Fent, System_Address_Size); | |
d6f39728 | 9974 | |
d9f6a4ee | 9975 | Set_Component_Clause (Fent, |
9976 | Make_Component_Clause (Loc, | |
9977 | Component_Name => Make_Identifier (Loc, Name_uTag), | |
d6f39728 | 9978 | |
d9f6a4ee | 9979 | Position => Make_Integer_Literal (Loc, Uint_0), |
9980 | First_Bit => Make_Integer_Literal (Loc, Uint_0), | |
9981 | Last_Bit => | |
9982 | Make_Integer_Literal (Loc, | |
9983 | UI_From_Int (System_Address_Size)))); | |
d6f39728 | 9984 | |
d9f6a4ee | 9985 | Ccount := Ccount + 1; |
9986 | end if; | |
d6f39728 | 9987 | |
d9f6a4ee | 9988 | Max_Bit_So_Far := Uint_Minus_1; |
9989 | Overlap_Check_Required := False; | |
d6f39728 | 9990 | |
d9f6a4ee | 9991 | -- Process the component clauses |
d6f39728 | 9992 | |
d9f6a4ee | 9993 | while Present (CC) loop |
9994 | Find_Component; | |
d6f39728 | 9995 | |
d9f6a4ee | 9996 | if Present (Comp) then |
9997 | Ccount := Ccount + 1; | |
d6f39728 | 9998 | |
d9f6a4ee | 9999 | -- We need a full overlap check if record positions non-monotonic |
d6f39728 | 10000 | |
d9f6a4ee | 10001 | if Fbit <= Max_Bit_So_Far then |
10002 | Overlap_Check_Required := True; | |
10003 | end if; | |
d6f39728 | 10004 | |
d9f6a4ee | 10005 | Max_Bit_So_Far := Lbit; |
d6f39728 | 10006 | |
d9f6a4ee | 10007 | -- Check bit position out of range of specified size |
01cb2726 | 10008 | |
d9f6a4ee | 10009 | if Has_Size_Clause (Rectype) |
10010 | and then RM_Size (Rectype) <= Lbit | |
10011 | then | |
10012 | Error_Msg_N | |
10013 | ("bit number out of range of specified size", | |
10014 | Last_Bit (CC)); | |
d6f39728 | 10015 | |
d9f6a4ee | 10016 | -- Check for overlap with tag component |
67278d60 | 10017 | |
d9f6a4ee | 10018 | else |
10019 | if Is_Tagged_Type (Rectype) | |
10020 | and then Fbit < System_Address_Size | |
10021 | then | |
10022 | Error_Msg_NE | |
10023 | ("component overlaps tag field of&", | |
10024 | Component_Name (CC), Rectype); | |
10025 | Overlap_Detected := True; | |
10026 | end if; | |
67278d60 | 10027 | |
d9f6a4ee | 10028 | if Hbit < Lbit then |
10029 | Hbit := Lbit; | |
10030 | end if; | |
10031 | end if; | |
67278d60 | 10032 | |
d9f6a4ee | 10033 | -- Check parent overlap if component might overlap parent field |
67278d60 | 10034 | |
d9f6a4ee | 10035 | if Present (Tagged_Parent) and then Fbit <= Parent_Last_Bit then |
10036 | Pcomp := First_Component_Or_Discriminant (Tagged_Parent); | |
10037 | while Present (Pcomp) loop | |
10038 | if not Is_Tag (Pcomp) | |
10039 | and then Chars (Pcomp) /= Name_uParent | |
10040 | then | |
10041 | Check_Component_Overlap (Comp, Pcomp); | |
10042 | end if; | |
67278d60 | 10043 | |
d9f6a4ee | 10044 | Next_Component_Or_Discriminant (Pcomp); |
10045 | end loop; | |
10046 | end if; | |
10047 | end if; | |
67278d60 | 10048 | |
d9f6a4ee | 10049 | Next (CC); |
10050 | end loop; | |
47495553 | 10051 | |
d9f6a4ee | 10052 | -- Now that we have processed all the component clauses, check for |
10053 | -- overlap. We have to leave this till last, since the components can | |
10054 | -- appear in any arbitrary order in the representation clause. | |
67278d60 | 10055 | |
d9f6a4ee | 10056 | -- We do not need this check if all specified ranges were monotonic, |
10057 | -- as recorded by Overlap_Check_Required being False at this stage. | |
67278d60 | 10058 | |
d9f6a4ee | 10059 | -- This first section checks if there are any overlapping entries at |
10060 | -- all. It does this by sorting all entries and then seeing if there are | |
10061 | -- any overlaps. If there are none, then that is decisive, but if there | |
10062 | -- are overlaps, they may still be OK (they may result from fields in | |
10063 | -- different variants). | |
67278d60 | 10064 | |
d9f6a4ee | 10065 | if Overlap_Check_Required then |
10066 | Overlap_Check1 : declare | |
67278d60 | 10067 | |
d9f6a4ee | 10068 | OC_Fbit : array (0 .. Ccount) of Uint; |
10069 | -- First-bit values for component clauses, the value is the offset | |
10070 | -- of the first bit of the field from start of record. The zero | |
10071 | -- entry is for use in sorting. | |
47495553 | 10072 | |
d9f6a4ee | 10073 | OC_Lbit : array (0 .. Ccount) of Uint; |
10074 | -- Last-bit values for component clauses, the value is the offset | |
10075 | -- of the last bit of the field from start of record. The zero | |
10076 | -- entry is for use in sorting. | |
10077 | ||
10078 | OC_Count : Natural := 0; | |
10079 | -- Count of entries in OC_Fbit and OC_Lbit | |
67278d60 | 10080 | |
d9f6a4ee | 10081 | function OC_Lt (Op1, Op2 : Natural) return Boolean; |
10082 | -- Compare routine for Sort | |
67278d60 | 10083 | |
d9f6a4ee | 10084 | procedure OC_Move (From : Natural; To : Natural); |
10085 | -- Move routine for Sort | |
67278d60 | 10086 | |
d9f6a4ee | 10087 | package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt); |
67278d60 | 10088 | |
d9f6a4ee | 10089 | ----------- |
10090 | -- OC_Lt -- | |
10091 | ----------- | |
67278d60 | 10092 | |
d9f6a4ee | 10093 | function OC_Lt (Op1, Op2 : Natural) return Boolean is |
67278d60 | 10094 | begin |
d9f6a4ee | 10095 | return OC_Fbit (Op1) < OC_Fbit (Op2); |
10096 | end OC_Lt; | |
67278d60 | 10097 | |
d9f6a4ee | 10098 | ------------- |
10099 | -- OC_Move -- | |
10100 | ------------- | |
67278d60 | 10101 | |
d9f6a4ee | 10102 | procedure OC_Move (From : Natural; To : Natural) is |
10103 | begin | |
10104 | OC_Fbit (To) := OC_Fbit (From); | |
10105 | OC_Lbit (To) := OC_Lbit (From); | |
10106 | end OC_Move; | |
67278d60 | 10107 | |
d9f6a4ee | 10108 | -- Start of processing for Overlap_Check |
67278d60 | 10109 | |
67278d60 | 10110 | begin |
d9f6a4ee | 10111 | CC := First (Component_Clauses (N)); |
10112 | while Present (CC) loop | |
67278d60 | 10113 | |
d9f6a4ee | 10114 | -- Exclude component clause already marked in error |
67278d60 | 10115 | |
d9f6a4ee | 10116 | if not Error_Posted (CC) then |
10117 | Find_Component; | |
10118 | ||
10119 | if Present (Comp) then | |
10120 | OC_Count := OC_Count + 1; | |
10121 | OC_Fbit (OC_Count) := Fbit; | |
10122 | OC_Lbit (OC_Count) := Lbit; | |
10123 | end if; | |
67278d60 | 10124 | end if; |
10125 | ||
d9f6a4ee | 10126 | Next (CC); |
67278d60 | 10127 | end loop; |
67278d60 | 10128 | |
d9f6a4ee | 10129 | Sorting.Sort (OC_Count); |
67278d60 | 10130 | |
d9f6a4ee | 10131 | Overlap_Check_Required := False; |
10132 | for J in 1 .. OC_Count - 1 loop | |
10133 | if OC_Lbit (J) >= OC_Fbit (J + 1) then | |
10134 | Overlap_Check_Required := True; | |
10135 | exit; | |
10136 | end if; | |
10137 | end loop; | |
10138 | end Overlap_Check1; | |
10139 | end if; | |
67278d60 | 10140 | |
d9f6a4ee | 10141 | -- If Overlap_Check_Required is still True, then we have to do the full |
10142 | -- scale overlap check, since we have at least two fields that do | |
10143 | -- overlap, and we need to know if that is OK since they are in | |
10144 | -- different variant, or whether we have a definite problem. | |
67278d60 | 10145 | |
d9f6a4ee | 10146 | if Overlap_Check_Required then |
10147 | Overlap_Check2 : declare | |
10148 | C1_Ent, C2_Ent : Entity_Id; | |
10149 | -- Entities of components being checked for overlap | |
67278d60 | 10150 | |
d9f6a4ee | 10151 | Clist : Node_Id; |
10152 | -- Component_List node whose Component_Items are being checked | |
67278d60 | 10153 | |
d9f6a4ee | 10154 | Citem : Node_Id; |
10155 | -- Component declaration for component being checked | |
67278d60 | 10156 | |
d9f6a4ee | 10157 | begin |
10158 | C1_Ent := First_Entity (Base_Type (Rectype)); | |
67278d60 | 10159 | |
d9f6a4ee | 10160 | -- Loop through all components in record. For each component check |
10161 | -- for overlap with any of the preceding elements on the component | |
10162 | -- list containing the component and also, if the component is in | |
10163 | -- a variant, check against components outside the case structure. | |
10164 | -- This latter test is repeated recursively up the variant tree. | |
67278d60 | 10165 | |
d9f6a4ee | 10166 | Main_Component_Loop : while Present (C1_Ent) loop |
10167 | if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then | |
10168 | goto Continue_Main_Component_Loop; | |
10169 | end if; | |
67278d60 | 10170 | |
d9f6a4ee | 10171 | -- Skip overlap check if entity has no declaration node. This |
10172 | -- happens with discriminants in constrained derived types. | |
10173 | -- Possibly we are missing some checks as a result, but that | |
10174 | -- does not seem terribly serious. | |
67278d60 | 10175 | |
d9f6a4ee | 10176 | if No (Declaration_Node (C1_Ent)) then |
10177 | goto Continue_Main_Component_Loop; | |
10178 | end if; | |
67278d60 | 10179 | |
d9f6a4ee | 10180 | Clist := Parent (List_Containing (Declaration_Node (C1_Ent))); |
67278d60 | 10181 | |
d9f6a4ee | 10182 | -- Loop through component lists that need checking. Check the |
10183 | -- current component list and all lists in variants above us. | |
67278d60 | 10184 | |
d9f6a4ee | 10185 | Component_List_Loop : loop |
67278d60 | 10186 | |
d9f6a4ee | 10187 | -- If derived type definition, go to full declaration |
10188 | -- If at outer level, check discriminants if there are any. | |
67278d60 | 10189 | |
d9f6a4ee | 10190 | if Nkind (Clist) = N_Derived_Type_Definition then |
10191 | Clist := Parent (Clist); | |
10192 | end if; | |
67278d60 | 10193 | |
d9f6a4ee | 10194 | -- Outer level of record definition, check discriminants |
67278d60 | 10195 | |
d9f6a4ee | 10196 | if Nkind_In (Clist, N_Full_Type_Declaration, |
10197 | N_Private_Type_Declaration) | |
67278d60 | 10198 | then |
d9f6a4ee | 10199 | if Has_Discriminants (Defining_Identifier (Clist)) then |
10200 | C2_Ent := | |
10201 | First_Discriminant (Defining_Identifier (Clist)); | |
10202 | while Present (C2_Ent) loop | |
10203 | exit when C1_Ent = C2_Ent; | |
10204 | Check_Component_Overlap (C1_Ent, C2_Ent); | |
10205 | Next_Discriminant (C2_Ent); | |
10206 | end loop; | |
10207 | end if; | |
67278d60 | 10208 | |
d9f6a4ee | 10209 | -- Record extension case |
67278d60 | 10210 | |
d9f6a4ee | 10211 | elsif Nkind (Clist) = N_Derived_Type_Definition then |
10212 | Clist := Empty; | |
67278d60 | 10213 | |
d9f6a4ee | 10214 | -- Otherwise check one component list |
67278d60 | 10215 | |
d9f6a4ee | 10216 | else |
10217 | Citem := First (Component_Items (Clist)); | |
10218 | while Present (Citem) loop | |
10219 | if Nkind (Citem) = N_Component_Declaration then | |
10220 | C2_Ent := Defining_Identifier (Citem); | |
10221 | exit when C1_Ent = C2_Ent; | |
10222 | Check_Component_Overlap (C1_Ent, C2_Ent); | |
10223 | end if; | |
67278d60 | 10224 | |
d9f6a4ee | 10225 | Next (Citem); |
10226 | end loop; | |
10227 | end if; | |
67278d60 | 10228 | |
d9f6a4ee | 10229 | -- Check for variants above us (the parent of the Clist can |
10230 | -- be a variant, in which case its parent is a variant part, | |
10231 | -- and the parent of the variant part is a component list | |
10232 | -- whose components must all be checked against the current | |
10233 | -- component for overlap). | |
67278d60 | 10234 | |
d9f6a4ee | 10235 | if Nkind (Parent (Clist)) = N_Variant then |
10236 | Clist := Parent (Parent (Parent (Clist))); | |
67278d60 | 10237 | |
d9f6a4ee | 10238 | -- Check for possible discriminant part in record, this |
10239 | -- is treated essentially as another level in the | |
10240 | -- recursion. For this case the parent of the component | |
10241 | -- list is the record definition, and its parent is the | |
10242 | -- full type declaration containing the discriminant | |
10243 | -- specifications. | |
10244 | ||
10245 | elsif Nkind (Parent (Clist)) = N_Record_Definition then | |
10246 | Clist := Parent (Parent ((Clist))); | |
10247 | ||
10248 | -- If neither of these two cases, we are at the top of | |
10249 | -- the tree. | |
10250 | ||
10251 | else | |
10252 | exit Component_List_Loop; | |
10253 | end if; | |
10254 | end loop Component_List_Loop; | |
67278d60 | 10255 | |
d9f6a4ee | 10256 | <<Continue_Main_Component_Loop>> |
10257 | Next_Entity (C1_Ent); | |
67278d60 | 10258 | |
d9f6a4ee | 10259 | end loop Main_Component_Loop; |
10260 | end Overlap_Check2; | |
67278d60 | 10261 | end if; |
10262 | ||
d9f6a4ee | 10263 | -- The following circuit deals with warning on record holes (gaps). We |
10264 | -- skip this check if overlap was detected, since it makes sense for the | |
10265 | -- programmer to fix this illegality before worrying about warnings. | |
67278d60 | 10266 | |
d9f6a4ee | 10267 | if not Overlap_Detected and Warn_On_Record_Holes then |
10268 | Record_Hole_Check : declare | |
10269 | Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype)); | |
10270 | -- Full declaration of record type | |
67278d60 | 10271 | |
d9f6a4ee | 10272 | procedure Check_Component_List |
10273 | (CL : Node_Id; | |
10274 | Sbit : Uint; | |
10275 | DS : List_Id); | |
10276 | -- Check component list CL for holes. The starting bit should be | |
10277 | -- Sbit. which is zero for the main record component list and set | |
10278 | -- appropriately for recursive calls for variants. DS is set to | |
10279 | -- a list of discriminant specifications to be included in the | |
10280 | -- consideration of components. It is No_List if none to consider. | |
67278d60 | 10281 | |
d9f6a4ee | 10282 | -------------------------- |
10283 | -- Check_Component_List -- | |
10284 | -------------------------- | |
47495553 | 10285 | |
d9f6a4ee | 10286 | procedure Check_Component_List |
10287 | (CL : Node_Id; | |
10288 | Sbit : Uint; | |
10289 | DS : List_Id) | |
10290 | is | |
10291 | Compl : Integer; | |
67278d60 | 10292 | |
d9f6a4ee | 10293 | begin |
10294 | Compl := Integer (List_Length (Component_Items (CL))); | |
47495553 | 10295 | |
d9f6a4ee | 10296 | if DS /= No_List then |
10297 | Compl := Compl + Integer (List_Length (DS)); | |
10298 | end if; | |
67278d60 | 10299 | |
d9f6a4ee | 10300 | declare |
10301 | Comps : array (Natural range 0 .. Compl) of Entity_Id; | |
10302 | -- Gather components (zero entry is for sort routine) | |
67278d60 | 10303 | |
d9f6a4ee | 10304 | Ncomps : Natural := 0; |
10305 | -- Number of entries stored in Comps (starting at Comps (1)) | |
67278d60 | 10306 | |
d9f6a4ee | 10307 | Citem : Node_Id; |
10308 | -- One component item or discriminant specification | |
67278d60 | 10309 | |
d9f6a4ee | 10310 | Nbit : Uint; |
10311 | -- Starting bit for next component | |
67278d60 | 10312 | |
d9f6a4ee | 10313 | CEnt : Entity_Id; |
10314 | -- Component entity | |
67278d60 | 10315 | |
d9f6a4ee | 10316 | Variant : Node_Id; |
10317 | -- One variant | |
67278d60 | 10318 | |
d9f6a4ee | 10319 | function Lt (Op1, Op2 : Natural) return Boolean; |
10320 | -- Compare routine for Sort | |
67278d60 | 10321 | |
d9f6a4ee | 10322 | procedure Move (From : Natural; To : Natural); |
10323 | -- Move routine for Sort | |
67278d60 | 10324 | |
d9f6a4ee | 10325 | package Sorting is new GNAT.Heap_Sort_G (Move, Lt); |
67278d60 | 10326 | |
d9f6a4ee | 10327 | -------- |
10328 | -- Lt -- | |
10329 | -------- | |
67278d60 | 10330 | |
d9f6a4ee | 10331 | function Lt (Op1, Op2 : Natural) return Boolean is |
10332 | begin | |
10333 | return Component_Bit_Offset (Comps (Op1)) | |
10334 | < | |
10335 | Component_Bit_Offset (Comps (Op2)); | |
10336 | end Lt; | |
67278d60 | 10337 | |
d9f6a4ee | 10338 | ---------- |
10339 | -- Move -- | |
10340 | ---------- | |
67278d60 | 10341 | |
d9f6a4ee | 10342 | procedure Move (From : Natural; To : Natural) is |
10343 | begin | |
10344 | Comps (To) := Comps (From); | |
10345 | end Move; | |
67278d60 | 10346 | |
d9f6a4ee | 10347 | begin |
10348 | -- Gather discriminants into Comp | |
67278d60 | 10349 | |
d9f6a4ee | 10350 | if DS /= No_List then |
10351 | Citem := First (DS); | |
10352 | while Present (Citem) loop | |
10353 | if Nkind (Citem) = N_Discriminant_Specification then | |
10354 | declare | |
10355 | Ent : constant Entity_Id := | |
10356 | Defining_Identifier (Citem); | |
10357 | begin | |
10358 | if Ekind (Ent) = E_Discriminant then | |
10359 | Ncomps := Ncomps + 1; | |
10360 | Comps (Ncomps) := Ent; | |
10361 | end if; | |
10362 | end; | |
10363 | end if; | |
67278d60 | 10364 | |
d9f6a4ee | 10365 | Next (Citem); |
10366 | end loop; | |
10367 | end if; | |
67278d60 | 10368 | |
d9f6a4ee | 10369 | -- Gather component entities into Comp |
67278d60 | 10370 | |
d9f6a4ee | 10371 | Citem := First (Component_Items (CL)); |
10372 | while Present (Citem) loop | |
10373 | if Nkind (Citem) = N_Component_Declaration then | |
10374 | Ncomps := Ncomps + 1; | |
10375 | Comps (Ncomps) := Defining_Identifier (Citem); | |
10376 | end if; | |
67278d60 | 10377 | |
d9f6a4ee | 10378 | Next (Citem); |
10379 | end loop; | |
67278d60 | 10380 | |
d9f6a4ee | 10381 | -- Now sort the component entities based on the first bit. |
10382 | -- Note we already know there are no overlapping components. | |
67278d60 | 10383 | |
d9f6a4ee | 10384 | Sorting.Sort (Ncomps); |
67278d60 | 10385 | |
d9f6a4ee | 10386 | -- Loop through entries checking for holes |
67278d60 | 10387 | |
d9f6a4ee | 10388 | Nbit := Sbit; |
10389 | for J in 1 .. Ncomps loop | |
10390 | CEnt := Comps (J); | |
67278d60 | 10391 | |
f55a6472 | 10392 | declare |
10393 | CBO : constant Uint := Component_Bit_Offset (CEnt); | |
10394 | ||
10395 | begin | |
10396 | -- Skip components with unknown offsets | |
10397 | ||
10398 | if CBO /= No_Uint and then CBO >= 0 then | |
10399 | Error_Msg_Uint_1 := CBO - Nbit; | |
67278d60 | 10400 | |
f55a6472 | 10401 | if Error_Msg_Uint_1 > 0 then |
10402 | Error_Msg_NE | |
10403 | ("?H?^-bit gap before component&", | |
10404 | Component_Name (Component_Clause (CEnt)), | |
10405 | CEnt); | |
10406 | end if; | |
10407 | ||
10408 | Nbit := CBO + Esize (CEnt); | |
10409 | end if; | |
10410 | end; | |
d9f6a4ee | 10411 | end loop; |
67278d60 | 10412 | |
d9f6a4ee | 10413 | -- Process variant parts recursively if present |
67278d60 | 10414 | |
d9f6a4ee | 10415 | if Present (Variant_Part (CL)) then |
10416 | Variant := First (Variants (Variant_Part (CL))); | |
10417 | while Present (Variant) loop | |
10418 | Check_Component_List | |
10419 | (Component_List (Variant), Nbit, No_List); | |
10420 | Next (Variant); | |
10421 | end loop; | |
67278d60 | 10422 | end if; |
d9f6a4ee | 10423 | end; |
10424 | end Check_Component_List; | |
67278d60 | 10425 | |
d9f6a4ee | 10426 | -- Start of processing for Record_Hole_Check |
67278d60 | 10427 | |
d9f6a4ee | 10428 | begin |
10429 | declare | |
10430 | Sbit : Uint; | |
67278d60 | 10431 | |
d9f6a4ee | 10432 | begin |
10433 | if Is_Tagged_Type (Rectype) then | |
10434 | Sbit := UI_From_Int (System_Address_Size); | |
10435 | else | |
10436 | Sbit := Uint_0; | |
10437 | end if; | |
10438 | ||
10439 | if Nkind (Decl) = N_Full_Type_Declaration | |
10440 | and then Nkind (Type_Definition (Decl)) = N_Record_Definition | |
10441 | then | |
10442 | Check_Component_List | |
10443 | (Component_List (Type_Definition (Decl)), | |
10444 | Sbit, | |
10445 | Discriminant_Specifications (Decl)); | |
67278d60 | 10446 | end if; |
d9f6a4ee | 10447 | end; |
10448 | end Record_Hole_Check; | |
67278d60 | 10449 | end if; |
10450 | ||
d9f6a4ee | 10451 | -- For records that have component clauses for all components, and whose |
10452 | -- size is less than or equal to 32, we need to know the size in the | |
10453 | -- front end to activate possible packed array processing where the | |
10454 | -- component type is a record. | |
67278d60 | 10455 | |
d9f6a4ee | 10456 | -- At this stage Hbit + 1 represents the first unused bit from all the |
10457 | -- component clauses processed, so if the component clauses are | |
10458 | -- complete, then this is the length of the record. | |
67278d60 | 10459 | |
d9f6a4ee | 10460 | -- For records longer than System.Storage_Unit, and for those where not |
10461 | -- all components have component clauses, the back end determines the | |
10462 | -- length (it may for example be appropriate to round up the size | |
10463 | -- to some convenient boundary, based on alignment considerations, etc). | |
67278d60 | 10464 | |
d9f6a4ee | 10465 | if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then |
67278d60 | 10466 | |
d9f6a4ee | 10467 | -- Nothing to do if at least one component has no component clause |
67278d60 | 10468 | |
d9f6a4ee | 10469 | Comp := First_Component_Or_Discriminant (Rectype); |
10470 | while Present (Comp) loop | |
10471 | exit when No (Component_Clause (Comp)); | |
10472 | Next_Component_Or_Discriminant (Comp); | |
10473 | end loop; | |
67278d60 | 10474 | |
d9f6a4ee | 10475 | -- If we fall out of loop, all components have component clauses |
10476 | -- and so we can set the size to the maximum value. | |
67278d60 | 10477 | |
d9f6a4ee | 10478 | if No (Comp) then |
10479 | Set_RM_Size (Rectype, Hbit + 1); | |
10480 | end if; | |
10481 | end if; | |
10482 | end Check_Record_Representation_Clause; | |
67278d60 | 10483 | |
d9f6a4ee | 10484 | ---------------- |
10485 | -- Check_Size -- | |
10486 | ---------------- | |
67278d60 | 10487 | |
d9f6a4ee | 10488 | procedure Check_Size |
10489 | (N : Node_Id; | |
10490 | T : Entity_Id; | |
10491 | Siz : Uint; | |
10492 | Biased : out Boolean) | |
10493 | is | |
f74a102b | 10494 | procedure Size_Too_Small_Error (Min_Siz : Uint); |
10495 | -- Emit an error concerning illegal size Siz. Min_Siz denotes the | |
10496 | -- minimum size. | |
10497 | ||
10498 | -------------------------- | |
10499 | -- Size_Too_Small_Error -- | |
10500 | -------------------------- | |
10501 | ||
10502 | procedure Size_Too_Small_Error (Min_Siz : Uint) is | |
10503 | begin | |
10504 | -- This error is suppressed in ASIS mode to allow for different ASIS | |
f9906591 | 10505 | -- back ends or ASIS-based tools to query the illegal clause. |
f74a102b | 10506 | |
10507 | if not ASIS_Mode then | |
10508 | Error_Msg_Uint_1 := Min_Siz; | |
6d22398d | 10509 | Error_Msg_NE ("size for& too small, minimum allowed is ^", N, T); |
f74a102b | 10510 | end if; |
10511 | end Size_Too_Small_Error; | |
10512 | ||
10513 | -- Local variables | |
10514 | ||
d9f6a4ee | 10515 | UT : constant Entity_Id := Underlying_Type (T); |
10516 | M : Uint; | |
67278d60 | 10517 | |
f74a102b | 10518 | -- Start of processing for Check_Size |
10519 | ||
d9f6a4ee | 10520 | begin |
10521 | Biased := False; | |
67278d60 | 10522 | |
f74a102b | 10523 | -- Reject patently improper size values |
67278d60 | 10524 | |
d9f6a4ee | 10525 | if Is_Elementary_Type (T) |
10526 | and then Siz > UI_From_Int (Int'Last) | |
10527 | then | |
10528 | Error_Msg_N ("Size value too large for elementary type", N); | |
67278d60 | 10529 | |
d9f6a4ee | 10530 | if Nkind (Original_Node (N)) = N_Op_Expon then |
10531 | Error_Msg_N | |
10532 | ("\maybe '* was meant, rather than '*'*", Original_Node (N)); | |
10533 | end if; | |
10534 | end if; | |
67278d60 | 10535 | |
d9f6a4ee | 10536 | -- Dismiss generic types |
67278d60 | 10537 | |
d9f6a4ee | 10538 | if Is_Generic_Type (T) |
10539 | or else | |
10540 | Is_Generic_Type (UT) | |
10541 | or else | |
10542 | Is_Generic_Type (Root_Type (UT)) | |
10543 | then | |
10544 | return; | |
67278d60 | 10545 | |
d9f6a4ee | 10546 | -- Guard against previous errors |
67278d60 | 10547 | |
d9f6a4ee | 10548 | elsif No (UT) or else UT = Any_Type then |
10549 | Check_Error_Detected; | |
10550 | return; | |
67278d60 | 10551 | |
d9f6a4ee | 10552 | -- Check case of bit packed array |
67278d60 | 10553 | |
d9f6a4ee | 10554 | elsif Is_Array_Type (UT) |
10555 | and then Known_Static_Component_Size (UT) | |
10556 | and then Is_Bit_Packed_Array (UT) | |
10557 | then | |
10558 | declare | |
10559 | Asiz : Uint; | |
10560 | Indx : Node_Id; | |
10561 | Ityp : Entity_Id; | |
67278d60 | 10562 | |
d9f6a4ee | 10563 | begin |
10564 | Asiz := Component_Size (UT); | |
10565 | Indx := First_Index (UT); | |
10566 | loop | |
10567 | Ityp := Etype (Indx); | |
67278d60 | 10568 | |
d9f6a4ee | 10569 | -- If non-static bound, then we are not in the business of |
10570 | -- trying to check the length, and indeed an error will be | |
10571 | -- issued elsewhere, since sizes of non-static array types | |
10572 | -- cannot be set implicitly or explicitly. | |
67278d60 | 10573 | |
cda40848 | 10574 | if not Is_OK_Static_Subtype (Ityp) then |
d9f6a4ee | 10575 | return; |
10576 | end if; | |
67278d60 | 10577 | |
d9f6a4ee | 10578 | -- Otherwise accumulate next dimension |
67278d60 | 10579 | |
d9f6a4ee | 10580 | Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) - |
10581 | Expr_Value (Type_Low_Bound (Ityp)) + | |
10582 | Uint_1); | |
67278d60 | 10583 | |
d9f6a4ee | 10584 | Next_Index (Indx); |
10585 | exit when No (Indx); | |
10586 | end loop; | |
67278d60 | 10587 | |
d9f6a4ee | 10588 | if Asiz <= Siz then |
10589 | return; | |
67278d60 | 10590 | |
d9f6a4ee | 10591 | else |
f74a102b | 10592 | Size_Too_Small_Error (Asiz); |
d9f6a4ee | 10593 | Set_Esize (T, Asiz); |
10594 | Set_RM_Size (T, Asiz); | |
10595 | end if; | |
10596 | end; | |
67278d60 | 10597 | |
d9f6a4ee | 10598 | -- All other composite types are ignored |
67278d60 | 10599 | |
d9f6a4ee | 10600 | elsif Is_Composite_Type (UT) then |
10601 | return; | |
47495553 | 10602 | |
d9f6a4ee | 10603 | -- For fixed-point types, don't check minimum if type is not frozen, |
10604 | -- since we don't know all the characteristics of the type that can | |
10605 | -- affect the size (e.g. a specified small) till freeze time. | |
47495553 | 10606 | |
f74a102b | 10607 | elsif Is_Fixed_Point_Type (UT) and then not Is_Frozen (UT) then |
d9f6a4ee | 10608 | null; |
47495553 | 10609 | |
d9f6a4ee | 10610 | -- Cases for which a minimum check is required |
47495553 | 10611 | |
d9f6a4ee | 10612 | else |
10613 | -- Ignore if specified size is correct for the type | |
47495553 | 10614 | |
d9f6a4ee | 10615 | if Known_Esize (UT) and then Siz = Esize (UT) then |
10616 | return; | |
10617 | end if; | |
47495553 | 10618 | |
d9f6a4ee | 10619 | -- Otherwise get minimum size |
47495553 | 10620 | |
d9f6a4ee | 10621 | M := UI_From_Int (Minimum_Size (UT)); |
47495553 | 10622 | |
d9f6a4ee | 10623 | if Siz < M then |
47495553 | 10624 | |
d9f6a4ee | 10625 | -- Size is less than minimum size, but one possibility remains |
10626 | -- that we can manage with the new size if we bias the type. | |
47495553 | 10627 | |
d9f6a4ee | 10628 | M := UI_From_Int (Minimum_Size (UT, Biased => True)); |
47495553 | 10629 | |
d9f6a4ee | 10630 | if Siz < M then |
f74a102b | 10631 | Size_Too_Small_Error (M); |
10632 | Set_Esize (T, M); | |
d9f6a4ee | 10633 | Set_RM_Size (T, M); |
10634 | else | |
10635 | Biased := True; | |
10636 | end if; | |
10637 | end if; | |
10638 | end if; | |
10639 | end Check_Size; | |
47495553 | 10640 | |
d9f6a4ee | 10641 | -------------------------- |
10642 | -- Freeze_Entity_Checks -- | |
10643 | -------------------------- | |
47495553 | 10644 | |
d9f6a4ee | 10645 | procedure Freeze_Entity_Checks (N : Node_Id) is |
8cf481c9 | 10646 | procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id); |
10647 | -- Inspect the primitive operations of type Typ and hide all pairs of | |
3118058b | 10648 | -- implicitly declared non-overridden non-fully conformant homographs |
10649 | -- (Ada RM 8.3 12.3/2). | |
8cf481c9 | 10650 | |
10651 | ------------------------------------- | |
10652 | -- Hide_Non_Overridden_Subprograms -- | |
10653 | ------------------------------------- | |
10654 | ||
10655 | procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is | |
10656 | procedure Hide_Matching_Homographs | |
10657 | (Subp_Id : Entity_Id; | |
10658 | Start_Elmt : Elmt_Id); | |
10659 | -- Inspect a list of primitive operations starting with Start_Elmt | |
3118058b | 10660 | -- and find matching implicitly declared non-overridden non-fully |
10661 | -- conformant homographs of Subp_Id. If found, all matches along | |
10662 | -- with Subp_Id are hidden from all visibility. | |
8cf481c9 | 10663 | |
10664 | function Is_Non_Overridden_Or_Null_Procedure | |
10665 | (Subp_Id : Entity_Id) return Boolean; | |
10666 | -- Determine whether subprogram Subp_Id is implicitly declared non- | |
10667 | -- overridden subprogram or an implicitly declared null procedure. | |
10668 | ||
10669 | ------------------------------ | |
10670 | -- Hide_Matching_Homographs -- | |
10671 | ------------------------------ | |
10672 | ||
10673 | procedure Hide_Matching_Homographs | |
10674 | (Subp_Id : Entity_Id; | |
10675 | Start_Elmt : Elmt_Id) | |
10676 | is | |
10677 | Prim : Entity_Id; | |
10678 | Prim_Elmt : Elmt_Id; | |
10679 | ||
10680 | begin | |
10681 | Prim_Elmt := Start_Elmt; | |
10682 | while Present (Prim_Elmt) loop | |
10683 | Prim := Node (Prim_Elmt); | |
10684 | ||
10685 | -- The current primitive is implicitly declared non-overridden | |
3118058b | 10686 | -- non-fully conformant homograph of Subp_Id. Both subprograms |
10687 | -- must be hidden from visibility. | |
8cf481c9 | 10688 | |
10689 | if Chars (Prim) = Chars (Subp_Id) | |
8cf481c9 | 10690 | and then Is_Non_Overridden_Or_Null_Procedure (Prim) |
3118058b | 10691 | and then not Fully_Conformant (Prim, Subp_Id) |
8cf481c9 | 10692 | then |
8c7ee4ac | 10693 | Set_Is_Hidden_Non_Overridden_Subpgm (Prim); |
10694 | Set_Is_Immediately_Visible (Prim, False); | |
10695 | Set_Is_Potentially_Use_Visible (Prim, False); | |
8cf481c9 | 10696 | |
8c7ee4ac | 10697 | Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id); |
10698 | Set_Is_Immediately_Visible (Subp_Id, False); | |
10699 | Set_Is_Potentially_Use_Visible (Subp_Id, False); | |
8cf481c9 | 10700 | end if; |
10701 | ||
10702 | Next_Elmt (Prim_Elmt); | |
10703 | end loop; | |
10704 | end Hide_Matching_Homographs; | |
10705 | ||
10706 | ----------------------------------------- | |
10707 | -- Is_Non_Overridden_Or_Null_Procedure -- | |
10708 | ----------------------------------------- | |
10709 | ||
10710 | function Is_Non_Overridden_Or_Null_Procedure | |
10711 | (Subp_Id : Entity_Id) return Boolean | |
10712 | is | |
10713 | Alias_Id : Entity_Id; | |
10714 | ||
10715 | begin | |
10716 | -- The subprogram is inherited (implicitly declared), it does not | |
10717 | -- override and does not cover a primitive of an interface. | |
10718 | ||
10719 | if Ekind_In (Subp_Id, E_Function, E_Procedure) | |
10720 | and then Present (Alias (Subp_Id)) | |
10721 | and then No (Interface_Alias (Subp_Id)) | |
10722 | and then No (Overridden_Operation (Subp_Id)) | |
10723 | then | |
10724 | Alias_Id := Alias (Subp_Id); | |
10725 | ||
10726 | if Requires_Overriding (Alias_Id) then | |
10727 | return True; | |
10728 | ||
10729 | elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification | |
10730 | and then Null_Present (Parent (Alias_Id)) | |
10731 | then | |
10732 | return True; | |
10733 | end if; | |
10734 | end if; | |
10735 | ||
10736 | return False; | |
10737 | end Is_Non_Overridden_Or_Null_Procedure; | |
10738 | ||
10739 | -- Local variables | |
10740 | ||
10741 | Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ); | |
10742 | Prim : Entity_Id; | |
10743 | Prim_Elmt : Elmt_Id; | |
10744 | ||
10745 | -- Start of processing for Hide_Non_Overridden_Subprograms | |
10746 | ||
10747 | begin | |
3118058b | 10748 | -- Inspect the list of primitives looking for non-overridden |
10749 | -- subprograms. | |
8cf481c9 | 10750 | |
10751 | if Present (Prim_Ops) then | |
10752 | Prim_Elmt := First_Elmt (Prim_Ops); | |
10753 | while Present (Prim_Elmt) loop | |
10754 | Prim := Node (Prim_Elmt); | |
10755 | Next_Elmt (Prim_Elmt); | |
10756 | ||
10757 | if Is_Non_Overridden_Or_Null_Procedure (Prim) then | |
10758 | Hide_Matching_Homographs | |
10759 | (Subp_Id => Prim, | |
10760 | Start_Elmt => Prim_Elmt); | |
10761 | end if; | |
10762 | end loop; | |
10763 | end if; | |
10764 | end Hide_Non_Overridden_Subprograms; | |
10765 | ||
97c23bbe | 10766 | -- Local variables |
8cf481c9 | 10767 | |
d9f6a4ee | 10768 | E : constant Entity_Id := Entity (N); |
47495553 | 10769 | |
d9f6a4ee | 10770 | Non_Generic_Case : constant Boolean := Nkind (N) = N_Freeze_Entity; |
10771 | -- True in non-generic case. Some of the processing here is skipped | |
10772 | -- for the generic case since it is not needed. Basically in the | |
10773 | -- generic case, we only need to do stuff that might generate error | |
10774 | -- messages or warnings. | |
8cf481c9 | 10775 | |
10776 | -- Start of processing for Freeze_Entity_Checks | |
10777 | ||
d9f6a4ee | 10778 | begin |
10779 | -- Remember that we are processing a freezing entity. Required to | |
10780 | -- ensure correct decoration of internal entities associated with | |
10781 | -- interfaces (see New_Overloaded_Entity). | |
47495553 | 10782 | |
d9f6a4ee | 10783 | Inside_Freezing_Actions := Inside_Freezing_Actions + 1; |
47495553 | 10784 | |
d9f6a4ee | 10785 | -- For tagged types covering interfaces add internal entities that link |
10786 | -- the primitives of the interfaces with the primitives that cover them. | |
10787 | -- Note: These entities were originally generated only when generating | |
10788 | -- code because their main purpose was to provide support to initialize | |
10789 | -- the secondary dispatch tables. They are now generated also when | |
10790 | -- compiling with no code generation to provide ASIS the relationship | |
10791 | -- between interface primitives and tagged type primitives. They are | |
10792 | -- also used to locate primitives covering interfaces when processing | |
10793 | -- generics (see Derive_Subprograms). | |
47495553 | 10794 | |
d9f6a4ee | 10795 | -- This is not needed in the generic case |
47495553 | 10796 | |
d9f6a4ee | 10797 | if Ada_Version >= Ada_2005 |
10798 | and then Non_Generic_Case | |
10799 | and then Ekind (E) = E_Record_Type | |
10800 | and then Is_Tagged_Type (E) | |
10801 | and then not Is_Interface (E) | |
10802 | and then Has_Interfaces (E) | |
10803 | then | |
10804 | -- This would be a good common place to call the routine that checks | |
10805 | -- overriding of interface primitives (and thus factorize calls to | |
10806 | -- Check_Abstract_Overriding located at different contexts in the | |
10807 | -- compiler). However, this is not possible because it causes | |
10808 | -- spurious errors in case of late overriding. | |
47495553 | 10809 | |
d9f6a4ee | 10810 | Add_Internal_Interface_Entities (E); |
10811 | end if; | |
47495553 | 10812 | |
8cf481c9 | 10813 | -- After all forms of overriding have been resolved, a tagged type may |
10814 | -- be left with a set of implicitly declared and possibly erroneous | |
10815 | -- abstract subprograms, null procedures and subprograms that require | |
0c4e0575 | 10816 | -- overriding. If this set contains fully conformant homographs, then |
10817 | -- one is chosen arbitrarily (already done during resolution), otherwise | |
10818 | -- all remaining non-fully conformant homographs are hidden from | |
10819 | -- visibility (Ada RM 8.3 12.3/2). | |
8cf481c9 | 10820 | |
10821 | if Is_Tagged_Type (E) then | |
10822 | Hide_Non_Overridden_Subprograms (E); | |
10823 | end if; | |
10824 | ||
d9f6a4ee | 10825 | -- Check CPP types |
47495553 | 10826 | |
d9f6a4ee | 10827 | if Ekind (E) = E_Record_Type |
10828 | and then Is_CPP_Class (E) | |
10829 | and then Is_Tagged_Type (E) | |
10830 | and then Tagged_Type_Expansion | |
d9f6a4ee | 10831 | then |
10832 | if CPP_Num_Prims (E) = 0 then | |
47495553 | 10833 | |
d9f6a4ee | 10834 | -- If the CPP type has user defined components then it must import |
10835 | -- primitives from C++. This is required because if the C++ class | |
10836 | -- has no primitives then the C++ compiler does not added the _tag | |
10837 | -- component to the type. | |
47495553 | 10838 | |
d9f6a4ee | 10839 | if First_Entity (E) /= Last_Entity (E) then |
10840 | Error_Msg_N | |
10841 | ("'C'P'P type must import at least one primitive from C++??", | |
10842 | E); | |
10843 | end if; | |
10844 | end if; | |
47495553 | 10845 | |
d9f6a4ee | 10846 | -- Check that all its primitives are abstract or imported from C++. |
10847 | -- Check also availability of the C++ constructor. | |
47495553 | 10848 | |
d9f6a4ee | 10849 | declare |
10850 | Has_Constructors : constant Boolean := Has_CPP_Constructors (E); | |
10851 | Elmt : Elmt_Id; | |
10852 | Error_Reported : Boolean := False; | |
10853 | Prim : Node_Id; | |
47495553 | 10854 | |
d9f6a4ee | 10855 | begin |
10856 | Elmt := First_Elmt (Primitive_Operations (E)); | |
10857 | while Present (Elmt) loop | |
10858 | Prim := Node (Elmt); | |
47495553 | 10859 | |
d9f6a4ee | 10860 | if Comes_From_Source (Prim) then |
10861 | if Is_Abstract_Subprogram (Prim) then | |
10862 | null; | |
47495553 | 10863 | |
d9f6a4ee | 10864 | elsif not Is_Imported (Prim) |
10865 | or else Convention (Prim) /= Convention_CPP | |
10866 | then | |
10867 | Error_Msg_N | |
10868 | ("primitives of 'C'P'P types must be imported from C++ " | |
10869 | & "or abstract??", Prim); | |
47495553 | 10870 | |
d9f6a4ee | 10871 | elsif not Has_Constructors |
10872 | and then not Error_Reported | |
10873 | then | |
10874 | Error_Msg_Name_1 := Chars (E); | |
10875 | Error_Msg_N | |
10876 | ("??'C'P'P constructor required for type %", Prim); | |
10877 | Error_Reported := True; | |
10878 | end if; | |
10879 | end if; | |
47495553 | 10880 | |
d9f6a4ee | 10881 | Next_Elmt (Elmt); |
10882 | end loop; | |
10883 | end; | |
10884 | end if; | |
47495553 | 10885 | |
d9f6a4ee | 10886 | -- Check Ada derivation of CPP type |
47495553 | 10887 | |
30ab103b | 10888 | if Expander_Active -- why? losing errors in -gnatc mode??? |
10889 | and then Present (Etype (E)) -- defend against errors | |
d9f6a4ee | 10890 | and then Tagged_Type_Expansion |
10891 | and then Ekind (E) = E_Record_Type | |
10892 | and then Etype (E) /= E | |
10893 | and then Is_CPP_Class (Etype (E)) | |
10894 | and then CPP_Num_Prims (Etype (E)) > 0 | |
10895 | and then not Is_CPP_Class (E) | |
10896 | and then not Has_CPP_Constructors (Etype (E)) | |
10897 | then | |
10898 | -- If the parent has C++ primitives but it has no constructor then | |
10899 | -- check that all the primitives are overridden in this derivation; | |
10900 | -- otherwise the constructor of the parent is needed to build the | |
10901 | -- dispatch table. | |
47495553 | 10902 | |
d9f6a4ee | 10903 | declare |
10904 | Elmt : Elmt_Id; | |
10905 | Prim : Node_Id; | |
47495553 | 10906 | |
10907 | begin | |
d9f6a4ee | 10908 | Elmt := First_Elmt (Primitive_Operations (E)); |
10909 | while Present (Elmt) loop | |
10910 | Prim := Node (Elmt); | |
47495553 | 10911 | |
d9f6a4ee | 10912 | if not Is_Abstract_Subprogram (Prim) |
10913 | and then No (Interface_Alias (Prim)) | |
10914 | and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E | |
47495553 | 10915 | then |
d9f6a4ee | 10916 | Error_Msg_Name_1 := Chars (Etype (E)); |
10917 | Error_Msg_N | |
10918 | ("'C'P'P constructor required for parent type %", E); | |
10919 | exit; | |
47495553 | 10920 | end if; |
d9f6a4ee | 10921 | |
10922 | Next_Elmt (Elmt); | |
10923 | end loop; | |
10924 | end; | |
47495553 | 10925 | end if; |
10926 | ||
d9f6a4ee | 10927 | Inside_Freezing_Actions := Inside_Freezing_Actions - 1; |
67278d60 | 10928 | |
97c23bbe | 10929 | -- If we have a type with predicates, build predicate function. This is |
10930 | -- not needed in the generic case, nor within TSS subprograms and other | |
10931 | -- predefined primitives. | |
67278d60 | 10932 | |
97c23bbe | 10933 | if Is_Type (E) |
10934 | and then Non_Generic_Case | |
ea822fd4 | 10935 | and then not Within_Internal_Subprogram |
97c23bbe | 10936 | and then Has_Predicates (E) |
ea822fd4 | 10937 | then |
d9f6a4ee | 10938 | Build_Predicate_Functions (E, N); |
10939 | end if; | |
67278d60 | 10940 | |
d9f6a4ee | 10941 | -- If type has delayed aspects, this is where we do the preanalysis at |
10942 | -- the freeze point, as part of the consistent visibility check. Note | |
10943 | -- that this must be done after calling Build_Predicate_Functions or | |
10944 | -- Build_Invariant_Procedure since these subprograms fix occurrences of | |
10945 | -- the subtype name in the saved expression so that they will not cause | |
10946 | -- trouble in the preanalysis. | |
67278d60 | 10947 | |
61989dbb | 10948 | -- This is also not needed in the generic case |
d9f6a4ee | 10949 | |
61989dbb | 10950 | if Non_Generic_Case |
10951 | and then Has_Delayed_Aspects (E) | |
d9f6a4ee | 10952 | and then Scope (E) = Current_Scope |
10953 | then | |
10954 | -- Retrieve the visibility to the discriminants in order to properly | |
10955 | -- analyze the aspects. | |
10956 | ||
10957 | Push_Scope_And_Install_Discriminants (E); | |
10958 | ||
10959 | declare | |
10960 | Ritem : Node_Id; | |
10961 | ||
10962 | begin | |
10963 | -- Look for aspect specification entries for this entity | |
67278d60 | 10964 | |
d9f6a4ee | 10965 | Ritem := First_Rep_Item (E); |
10966 | while Present (Ritem) loop | |
10967 | if Nkind (Ritem) = N_Aspect_Specification | |
10968 | and then Entity (Ritem) = E | |
10969 | and then Is_Delayed_Aspect (Ritem) | |
10970 | then | |
10971 | Check_Aspect_At_Freeze_Point (Ritem); | |
10972 | end if; | |
67278d60 | 10973 | |
d9f6a4ee | 10974 | Next_Rep_Item (Ritem); |
10975 | end loop; | |
10976 | end; | |
67278d60 | 10977 | |
d9f6a4ee | 10978 | Uninstall_Discriminants_And_Pop_Scope (E); |
67278d60 | 10979 | end if; |
67278d60 | 10980 | |
d9f6a4ee | 10981 | -- For a record type, deal with variant parts. This has to be delayed |
d0988351 | 10982 | -- to this point, because of the issue of statically predicated |
d9f6a4ee | 10983 | -- subtypes, which we have to ensure are frozen before checking |
10984 | -- choices, since we need to have the static choice list set. | |
d6f39728 | 10985 | |
d9f6a4ee | 10986 | if Is_Record_Type (E) then |
10987 | Check_Variant_Part : declare | |
10988 | D : constant Node_Id := Declaration_Node (E); | |
10989 | T : Node_Id; | |
10990 | C : Node_Id; | |
10991 | VP : Node_Id; | |
d6f39728 | 10992 | |
d9f6a4ee | 10993 | Others_Present : Boolean; |
10994 | pragma Warnings (Off, Others_Present); | |
10995 | -- Indicates others present, not used in this case | |
d6f39728 | 10996 | |
d9f6a4ee | 10997 | procedure Non_Static_Choice_Error (Choice : Node_Id); |
10998 | -- Error routine invoked by the generic instantiation below when | |
10999 | -- the variant part has a non static choice. | |
f117057b | 11000 | |
d9f6a4ee | 11001 | procedure Process_Declarations (Variant : Node_Id); |
11002 | -- Processes declarations associated with a variant. We analyzed | |
11003 | -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part), | |
11004 | -- but we still need the recursive call to Check_Choices for any | |
11005 | -- nested variant to get its choices properly processed. This is | |
11006 | -- also where we expand out the choices if expansion is active. | |
1f526845 | 11007 | |
d9f6a4ee | 11008 | package Variant_Choices_Processing is new |
11009 | Generic_Check_Choices | |
11010 | (Process_Empty_Choice => No_OP, | |
11011 | Process_Non_Static_Choice => Non_Static_Choice_Error, | |
11012 | Process_Associated_Node => Process_Declarations); | |
11013 | use Variant_Choices_Processing; | |
f117057b | 11014 | |
d9f6a4ee | 11015 | ----------------------------- |
11016 | -- Non_Static_Choice_Error -- | |
11017 | ----------------------------- | |
d6f39728 | 11018 | |
d9f6a4ee | 11019 | procedure Non_Static_Choice_Error (Choice : Node_Id) is |
11020 | begin | |
11021 | Flag_Non_Static_Expr | |
11022 | ("choice given in variant part is not static!", Choice); | |
11023 | end Non_Static_Choice_Error; | |
d6f39728 | 11024 | |
d9f6a4ee | 11025 | -------------------------- |
11026 | -- Process_Declarations -- | |
11027 | -------------------------- | |
dba36b60 | 11028 | |
d9f6a4ee | 11029 | procedure Process_Declarations (Variant : Node_Id) is |
11030 | CL : constant Node_Id := Component_List (Variant); | |
11031 | VP : Node_Id; | |
dba36b60 | 11032 | |
d9f6a4ee | 11033 | begin |
11034 | -- Check for static predicate present in this variant | |
ea61a7ea | 11035 | |
d9f6a4ee | 11036 | if Has_SP_Choice (Variant) then |
ea61a7ea | 11037 | |
d9f6a4ee | 11038 | -- Here we expand. You might expect to find this call in |
11039 | -- Expand_N_Variant_Part, but that is called when we first | |
11040 | -- see the variant part, and we cannot do this expansion | |
11041 | -- earlier than the freeze point, since for statically | |
11042 | -- predicated subtypes, the predicate is not known till | |
11043 | -- the freeze point. | |
ea61a7ea | 11044 | |
d9f6a4ee | 11045 | -- Furthermore, we do this expansion even if the expander |
11046 | -- is not active, because other semantic processing, e.g. | |
11047 | -- for aggregates, requires the expanded list of choices. | |
ea61a7ea | 11048 | |
d9f6a4ee | 11049 | -- If the expander is not active, then we can't just clobber |
11050 | -- the list since it would invalidate the ASIS -gnatct tree. | |
11051 | -- So we have to rewrite the variant part with a Rewrite | |
11052 | -- call that replaces it with a copy and clobber the copy. | |
11053 | ||
11054 | if not Expander_Active then | |
11055 | declare | |
11056 | NewV : constant Node_Id := New_Copy (Variant); | |
11057 | begin | |
11058 | Set_Discrete_Choices | |
11059 | (NewV, New_Copy_List (Discrete_Choices (Variant))); | |
11060 | Rewrite (Variant, NewV); | |
11061 | end; | |
11062 | end if; | |
11063 | ||
11064 | Expand_Static_Predicates_In_Choices (Variant); | |
ea61a7ea | 11065 | end if; |
11066 | ||
d9f6a4ee | 11067 | -- We don't need to worry about the declarations in the variant |
11068 | -- (since they were analyzed by Analyze_Choices when we first | |
11069 | -- encountered the variant), but we do need to take care of | |
11070 | -- expansion of any nested variants. | |
ea61a7ea | 11071 | |
d9f6a4ee | 11072 | if not Null_Present (CL) then |
11073 | VP := Variant_Part (CL); | |
ea61a7ea | 11074 | |
d9f6a4ee | 11075 | if Present (VP) then |
11076 | Check_Choices | |
11077 | (VP, Variants (VP), Etype (Name (VP)), Others_Present); | |
11078 | end if; | |
11079 | end if; | |
11080 | end Process_Declarations; | |
ea61a7ea | 11081 | |
d9f6a4ee | 11082 | -- Start of processing for Check_Variant_Part |
b9e61b2a | 11083 | |
d9f6a4ee | 11084 | begin |
11085 | -- Find component list | |
ea61a7ea | 11086 | |
d9f6a4ee | 11087 | C := Empty; |
ea61a7ea | 11088 | |
d9f6a4ee | 11089 | if Nkind (D) = N_Full_Type_Declaration then |
11090 | T := Type_Definition (D); | |
ea61a7ea | 11091 | |
d9f6a4ee | 11092 | if Nkind (T) = N_Record_Definition then |
11093 | C := Component_List (T); | |
d6f39728 | 11094 | |
d9f6a4ee | 11095 | elsif Nkind (T) = N_Derived_Type_Definition |
11096 | and then Present (Record_Extension_Part (T)) | |
11097 | then | |
11098 | C := Component_List (Record_Extension_Part (T)); | |
11099 | end if; | |
11100 | end if; | |
d6f39728 | 11101 | |
d9f6a4ee | 11102 | -- Case of variant part present |
d6f39728 | 11103 | |
d9f6a4ee | 11104 | if Present (C) and then Present (Variant_Part (C)) then |
11105 | VP := Variant_Part (C); | |
ea61a7ea | 11106 | |
d9f6a4ee | 11107 | -- Check choices |
ea61a7ea | 11108 | |
d9f6a4ee | 11109 | Check_Choices |
11110 | (VP, Variants (VP), Etype (Name (VP)), Others_Present); | |
ea61a7ea | 11111 | |
d9f6a4ee | 11112 | -- If the last variant does not contain the Others choice, |
11113 | -- replace it with an N_Others_Choice node since Gigi always | |
11114 | -- wants an Others. Note that we do not bother to call Analyze | |
11115 | -- on the modified variant part, since its only effect would be | |
11116 | -- to compute the Others_Discrete_Choices node laboriously, and | |
11117 | -- of course we already know the list of choices corresponding | |
39a0c1d3 | 11118 | -- to the others choice (it's the list we're replacing). |
d6f39728 | 11119 | |
d9f6a4ee | 11120 | -- We only want to do this if the expander is active, since |
39a0c1d3 | 11121 | -- we do not want to clobber the ASIS tree. |
d6f39728 | 11122 | |
d9f6a4ee | 11123 | if Expander_Active then |
11124 | declare | |
11125 | Last_Var : constant Node_Id := | |
11126 | Last_Non_Pragma (Variants (VP)); | |
d6f39728 | 11127 | |
d9f6a4ee | 11128 | Others_Node : Node_Id; |
d6f39728 | 11129 | |
d9f6a4ee | 11130 | begin |
11131 | if Nkind (First (Discrete_Choices (Last_Var))) /= | |
11132 | N_Others_Choice | |
11133 | then | |
11134 | Others_Node := Make_Others_Choice (Sloc (Last_Var)); | |
11135 | Set_Others_Discrete_Choices | |
11136 | (Others_Node, Discrete_Choices (Last_Var)); | |
11137 | Set_Discrete_Choices | |
11138 | (Last_Var, New_List (Others_Node)); | |
11139 | end if; | |
11140 | end; | |
11141 | end if; | |
d6f39728 | 11142 | end if; |
d9f6a4ee | 11143 | end Check_Variant_Part; |
d6f39728 | 11144 | end if; |
d9f6a4ee | 11145 | end Freeze_Entity_Checks; |
d6f39728 | 11146 | |
11147 | ------------------------- | |
11148 | -- Get_Alignment_Value -- | |
11149 | ------------------------- | |
11150 | ||
11151 | function Get_Alignment_Value (Expr : Node_Id) return Uint is | |
f5d97bf5 | 11152 | Align : constant Uint := Static_Integer (Expr); |
f74a102b | 11153 | |
f5d97bf5 | 11154 | begin |
11155 | if Align = No_Uint then | |
11156 | return No_Uint; | |
11157 | ||
11158 | elsif Align <= 0 then | |
f74a102b | 11159 | |
f74a102b | 11160 | -- This error is suppressed in ASIS mode to allow for different ASIS |
f9906591 | 11161 | -- back ends or ASIS-based tools to query the illegal clause. |
f74a102b | 11162 | |
11163 | if not ASIS_Mode then | |
11164 | Error_Msg_N ("alignment value must be positive", Expr); | |
11165 | end if; | |
f74a102b | 11166 | |
d6f39728 | 11167 | return No_Uint; |
11168 | ||
11169 | else | |
11170 | for J in Int range 0 .. 64 loop | |
11171 | declare | |
11172 | M : constant Uint := Uint_2 ** J; | |
11173 | ||
11174 | begin | |
11175 | exit when M = Align; | |
11176 | ||
11177 | if M > Align then | |
f5d97bf5 | 11178 | |
11179 | -- This error is suppressed in ASIS mode to allow for | |
f9906591 | 11180 | -- different ASIS back ends or ASIS-based tools to query the |
f5d97bf5 | 11181 | -- illegal clause. |
11182 | ||
11183 | if not ASIS_Mode then | |
11184 | Error_Msg_N ("alignment value must be power of 2", Expr); | |
11185 | end if; | |
11186 | ||
d6f39728 | 11187 | return No_Uint; |
11188 | end if; | |
11189 | end; | |
11190 | end loop; | |
11191 | ||
11192 | return Align; | |
11193 | end if; | |
11194 | end Get_Alignment_Value; | |
11195 | ||
99a2d5bd | 11196 | ------------------------------------- |
11197 | -- Inherit_Aspects_At_Freeze_Point -- | |
11198 | ------------------------------------- | |
11199 | ||
11200 | procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is | |
11201 | function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11202 | (Rep_Item : Node_Id) return Boolean; | |
11203 | -- This routine checks if Rep_Item is either a pragma or an aspect | |
11204 | -- specification node whose correponding pragma (if any) is present in | |
11205 | -- the Rep Item chain of the entity it has been specified to. | |
11206 | ||
11207 | -------------------------------------------------- | |
11208 | -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item -- | |
11209 | -------------------------------------------------- | |
11210 | ||
11211 | function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11212 | (Rep_Item : Node_Id) return Boolean | |
11213 | is | |
11214 | begin | |
ec6f6da5 | 11215 | return |
11216 | Nkind (Rep_Item) = N_Pragma | |
11217 | or else Present_In_Rep_Item | |
11218 | (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item)); | |
99a2d5bd | 11219 | end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item; |
11220 | ||
29a9d4be | 11221 | -- Start of processing for Inherit_Aspects_At_Freeze_Point |
11222 | ||
99a2d5bd | 11223 | begin |
11224 | -- A representation item is either subtype-specific (Size and Alignment | |
11225 | -- clauses) or type-related (all others). Subtype-specific aspects may | |
29a9d4be | 11226 | -- differ for different subtypes of the same type (RM 13.1.8). |
99a2d5bd | 11227 | |
11228 | -- A derived type inherits each type-related representation aspect of | |
11229 | -- its parent type that was directly specified before the declaration of | |
29a9d4be | 11230 | -- the derived type (RM 13.1.15). |
99a2d5bd | 11231 | |
11232 | -- A derived subtype inherits each subtype-specific representation | |
11233 | -- aspect of its parent subtype that was directly specified before the | |
29a9d4be | 11234 | -- declaration of the derived type (RM 13.1.15). |
99a2d5bd | 11235 | |
11236 | -- The general processing involves inheriting a representation aspect | |
11237 | -- from a parent type whenever the first rep item (aspect specification, | |
11238 | -- attribute definition clause, pragma) corresponding to the given | |
11239 | -- representation aspect in the rep item chain of Typ, if any, isn't | |
11240 | -- directly specified to Typ but to one of its parents. | |
11241 | ||
11242 | -- ??? Note that, for now, just a limited number of representation | |
29a9d4be | 11243 | -- aspects have been inherited here so far. Many of them are |
11244 | -- still inherited in Sem_Ch3. This will be fixed soon. Here is | |
11245 | -- a non- exhaustive list of aspects that likely also need to | |
11246 | -- be moved to this routine: Alignment, Component_Alignment, | |
11247 | -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates, | |
99a2d5bd | 11248 | -- Preelaborable_Initialization, RM_Size and Small. |
11249 | ||
8b6e9bf2 | 11250 | -- In addition, Convention must be propagated from base type to subtype, |
11251 | -- because the subtype may have been declared on an incomplete view. | |
11252 | ||
99a2d5bd | 11253 | if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then |
11254 | return; | |
11255 | end if; | |
11256 | ||
11257 | -- Ada_05/Ada_2005 | |
11258 | ||
11259 | if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False) | |
11260 | and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005) | |
11261 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11262 | (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)) | |
11263 | then | |
11264 | Set_Is_Ada_2005_Only (Typ); | |
11265 | end if; | |
11266 | ||
11267 | -- Ada_12/Ada_2012 | |
11268 | ||
11269 | if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False) | |
11270 | and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012) | |
11271 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11272 | (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)) | |
11273 | then | |
11274 | Set_Is_Ada_2012_Only (Typ); | |
11275 | end if; | |
11276 | ||
11277 | -- Atomic/Shared | |
11278 | ||
11279 | if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False) | |
11280 | and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared) | |
11281 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11282 | (Get_Rep_Item (Typ, Name_Atomic, Name_Shared)) | |
11283 | then | |
11284 | Set_Is_Atomic (Typ); | |
99a2d5bd | 11285 | Set_Is_Volatile (Typ); |
4bf2acc9 | 11286 | Set_Treat_As_Volatile (Typ); |
99a2d5bd | 11287 | end if; |
11288 | ||
8b6e9bf2 | 11289 | -- Convention |
11290 | ||
7ac4254e | 11291 | if Is_Record_Type (Typ) |
11292 | and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ)) | |
11293 | then | |
8b6e9bf2 | 11294 | Set_Convention (Typ, Convention (Base_Type (Typ))); |
11295 | end if; | |
11296 | ||
29a9d4be | 11297 | -- Default_Component_Value |
99a2d5bd | 11298 | |
81c2bc19 | 11299 | -- Verify that there is no rep_item declared for the type, and there |
11300 | -- is one coming from an ancestor. | |
11301 | ||
99a2d5bd | 11302 | if Is_Array_Type (Typ) |
f3d70f08 | 11303 | and then Is_Base_Type (Typ) |
81c2bc19 | 11304 | and then not Has_Rep_Item (Typ, Name_Default_Component_Value, False) |
99a2d5bd | 11305 | and then Has_Rep_Item (Typ, Name_Default_Component_Value) |
11306 | then | |
11307 | Set_Default_Aspect_Component_Value (Typ, | |
11308 | Default_Aspect_Component_Value | |
11309 | (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value)))); | |
11310 | end if; | |
11311 | ||
29a9d4be | 11312 | -- Default_Value |
99a2d5bd | 11313 | |
11314 | if Is_Scalar_Type (Typ) | |
f3d70f08 | 11315 | and then Is_Base_Type (Typ) |
81c2bc19 | 11316 | and then not Has_Rep_Item (Typ, Name_Default_Value, False) |
99a2d5bd | 11317 | and then Has_Rep_Item (Typ, Name_Default_Value) |
11318 | then | |
81c2bc19 | 11319 | Set_Has_Default_Aspect (Typ); |
99a2d5bd | 11320 | Set_Default_Aspect_Value (Typ, |
11321 | Default_Aspect_Value | |
11322 | (Entity (Get_Rep_Item (Typ, Name_Default_Value)))); | |
11323 | end if; | |
11324 | ||
11325 | -- Discard_Names | |
11326 | ||
11327 | if not Has_Rep_Item (Typ, Name_Discard_Names, False) | |
11328 | and then Has_Rep_Item (Typ, Name_Discard_Names) | |
11329 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11330 | (Get_Rep_Item (Typ, Name_Discard_Names)) | |
11331 | then | |
11332 | Set_Discard_Names (Typ); | |
11333 | end if; | |
11334 | ||
99a2d5bd | 11335 | -- Volatile |
11336 | ||
11337 | if not Has_Rep_Item (Typ, Name_Volatile, False) | |
11338 | and then Has_Rep_Item (Typ, Name_Volatile) | |
11339 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11340 | (Get_Rep_Item (Typ, Name_Volatile)) | |
11341 | then | |
99a2d5bd | 11342 | Set_Is_Volatile (Typ); |
4bf2acc9 | 11343 | Set_Treat_As_Volatile (Typ); |
99a2d5bd | 11344 | end if; |
11345 | ||
2fe893b9 | 11346 | -- Volatile_Full_Access |
11347 | ||
11348 | if not Has_Rep_Item (Typ, Name_Volatile_Full_Access, False) | |
11349 | and then Has_Rep_Pragma (Typ, Name_Volatile_Full_Access) | |
11350 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11351 | (Get_Rep_Item (Typ, Name_Volatile_Full_Access)) | |
11352 | then | |
4bf2acc9 | 11353 | Set_Is_Volatile_Full_Access (Typ); |
2fe893b9 | 11354 | Set_Is_Volatile (Typ); |
4bf2acc9 | 11355 | Set_Treat_As_Volatile (Typ); |
2fe893b9 | 11356 | end if; |
11357 | ||
99a2d5bd | 11358 | -- Inheritance for derived types only |
11359 | ||
11360 | if Is_Derived_Type (Typ) then | |
11361 | declare | |
11362 | Bas_Typ : constant Entity_Id := Base_Type (Typ); | |
11363 | Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ); | |
11364 | ||
11365 | begin | |
11366 | -- Atomic_Components | |
11367 | ||
11368 | if not Has_Rep_Item (Typ, Name_Atomic_Components, False) | |
11369 | and then Has_Rep_Item (Typ, Name_Atomic_Components) | |
11370 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11371 | (Get_Rep_Item (Typ, Name_Atomic_Components)) | |
11372 | then | |
11373 | Set_Has_Atomic_Components (Imp_Bas_Typ); | |
11374 | end if; | |
11375 | ||
11376 | -- Volatile_Components | |
11377 | ||
11378 | if not Has_Rep_Item (Typ, Name_Volatile_Components, False) | |
11379 | and then Has_Rep_Item (Typ, Name_Volatile_Components) | |
11380 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11381 | (Get_Rep_Item (Typ, Name_Volatile_Components)) | |
11382 | then | |
11383 | Set_Has_Volatile_Components (Imp_Bas_Typ); | |
11384 | end if; | |
11385 | ||
e81df51c | 11386 | -- Finalize_Storage_Only |
99a2d5bd | 11387 | |
11388 | if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False) | |
11389 | and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only) | |
11390 | then | |
11391 | Set_Finalize_Storage_Only (Bas_Typ); | |
11392 | end if; | |
11393 | ||
11394 | -- Universal_Aliasing | |
11395 | ||
11396 | if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False) | |
11397 | and then Has_Rep_Item (Typ, Name_Universal_Aliasing) | |
11398 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11399 | (Get_Rep_Item (Typ, Name_Universal_Aliasing)) | |
11400 | then | |
11401 | Set_Universal_Aliasing (Imp_Bas_Typ); | |
11402 | end if; | |
11403 | ||
e81df51c | 11404 | -- Bit_Order |
99a2d5bd | 11405 | |
11406 | if Is_Record_Type (Typ) then | |
99a2d5bd | 11407 | if not Has_Rep_Item (Typ, Name_Bit_Order, False) |
11408 | and then Has_Rep_Item (Typ, Name_Bit_Order) | |
11409 | then | |
11410 | Set_Reverse_Bit_Order (Bas_Typ, | |
11411 | Reverse_Bit_Order (Entity (Name | |
11412 | (Get_Rep_Item (Typ, Name_Bit_Order))))); | |
11413 | end if; | |
e81df51c | 11414 | end if; |
11415 | ||
e9218716 | 11416 | -- Scalar_Storage_Order |
11417 | ||
11418 | -- Note: the aspect is specified on a first subtype, but recorded | |
11419 | -- in a flag of the base type! | |
e81df51c | 11420 | |
11421 | if (Is_Record_Type (Typ) or else Is_Array_Type (Typ)) | |
29b91bc7 | 11422 | and then Typ = Bas_Typ |
e81df51c | 11423 | then |
e81df51c | 11424 | -- For a type extension, always inherit from parent; otherwise |
11425 | -- inherit if no default applies. Note: we do not check for | |
11426 | -- an explicit rep item on the parent type when inheriting, | |
11427 | -- because the parent SSO may itself have been set by default. | |
99a2d5bd | 11428 | |
e9218716 | 11429 | if not Has_Rep_Item (First_Subtype (Typ), |
11430 | Name_Scalar_Storage_Order, False) | |
e81df51c | 11431 | and then (Is_Tagged_Type (Bas_Typ) |
29b91bc7 | 11432 | or else not (SSO_Set_Low_By_Default (Bas_Typ) |
11433 | or else | |
11434 | SSO_Set_High_By_Default (Bas_Typ))) | |
99a2d5bd | 11435 | then |
11436 | Set_Reverse_Storage_Order (Bas_Typ, | |
423b89fd | 11437 | Reverse_Storage_Order |
11438 | (Implementation_Base_Type (Etype (Bas_Typ)))); | |
b64082f2 | 11439 | |
11440 | -- Clear default SSO indications, since the inherited aspect | |
11441 | -- which was set explicitly overrides the default. | |
11442 | ||
11443 | Set_SSO_Set_Low_By_Default (Bas_Typ, False); | |
11444 | Set_SSO_Set_High_By_Default (Bas_Typ, False); | |
99a2d5bd | 11445 | end if; |
11446 | end if; | |
11447 | end; | |
11448 | end if; | |
11449 | end Inherit_Aspects_At_Freeze_Point; | |
11450 | ||
d6f39728 | 11451 | ---------------- |
11452 | -- Initialize -- | |
11453 | ---------------- | |
11454 | ||
11455 | procedure Initialize is | |
11456 | begin | |
7717ea00 | 11457 | Address_Clause_Checks.Init; |
76a6b7c7 | 11458 | Compile_Time_Warnings_Errors.Init; |
d6f39728 | 11459 | Unchecked_Conversions.Init; |
dba38d2f | 11460 | |
36ac5fbb | 11461 | if AAMP_On_Target then |
dba38d2f | 11462 | Independence_Checks.Init; |
11463 | end if; | |
d6f39728 | 11464 | end Initialize; |
11465 | ||
2625eb01 | 11466 | --------------------------- |
11467 | -- Install_Discriminants -- | |
11468 | --------------------------- | |
11469 | ||
11470 | procedure Install_Discriminants (E : Entity_Id) is | |
11471 | Disc : Entity_Id; | |
11472 | Prev : Entity_Id; | |
11473 | begin | |
11474 | Disc := First_Discriminant (E); | |
11475 | while Present (Disc) loop | |
11476 | Prev := Current_Entity (Disc); | |
11477 | Set_Current_Entity (Disc); | |
11478 | Set_Is_Immediately_Visible (Disc); | |
11479 | Set_Homonym (Disc, Prev); | |
11480 | Next_Discriminant (Disc); | |
11481 | end loop; | |
11482 | end Install_Discriminants; | |
11483 | ||
d6f39728 | 11484 | ------------------------- |
11485 | -- Is_Operational_Item -- | |
11486 | ------------------------- | |
11487 | ||
11488 | function Is_Operational_Item (N : Node_Id) return Boolean is | |
11489 | begin | |
11490 | if Nkind (N) /= N_Attribute_Definition_Clause then | |
11491 | return False; | |
b9e61b2a | 11492 | |
d6f39728 | 11493 | else |
11494 | declare | |
b9e61b2a | 11495 | Id : constant Attribute_Id := Get_Attribute_Id (Chars (N)); |
d6f39728 | 11496 | begin |
078a74b8 | 11497 | |
55ab5265 | 11498 | -- List of operational items is given in AARM 13.1(8.mm/1). |
078a74b8 | 11499 | -- It is clearly incomplete, as it does not include iterator |
11500 | -- aspects, among others. | |
11501 | ||
11502 | return Id = Attribute_Constant_Indexing | |
11503 | or else Id = Attribute_Default_Iterator | |
11504 | or else Id = Attribute_Implicit_Dereference | |
11505 | or else Id = Attribute_Input | |
11506 | or else Id = Attribute_Iterator_Element | |
11507 | or else Id = Attribute_Iterable | |
d6f39728 | 11508 | or else Id = Attribute_Output |
11509 | or else Id = Attribute_Read | |
078a74b8 | 11510 | or else Id = Attribute_Variable_Indexing |
f15731c4 | 11511 | or else Id = Attribute_Write |
11512 | or else Id = Attribute_External_Tag; | |
d6f39728 | 11513 | end; |
11514 | end if; | |
11515 | end Is_Operational_Item; | |
11516 | ||
3b23aaa0 | 11517 | ------------------------- |
11518 | -- Is_Predicate_Static -- | |
11519 | ------------------------- | |
11520 | ||
94d896aa | 11521 | -- Note: the basic legality of the expression has already been checked, so |
11522 | -- we don't need to worry about cases or ranges on strings for example. | |
11523 | ||
3b23aaa0 | 11524 | function Is_Predicate_Static |
11525 | (Expr : Node_Id; | |
11526 | Nam : Name_Id) return Boolean | |
11527 | is | |
11528 | function All_Static_Case_Alternatives (L : List_Id) return Boolean; | |
973c2fba | 11529 | -- Given a list of case expression alternatives, returns True if all |
11530 | -- the alternatives are static (have all static choices, and a static | |
11531 | -- expression). | |
3b23aaa0 | 11532 | |
11533 | function All_Static_Choices (L : List_Id) return Boolean; | |
a360a0f7 | 11534 | -- Returns true if all elements of the list are OK static choices |
3b23aaa0 | 11535 | -- as defined below for Is_Static_Choice. Used for case expression |
973c2fba | 11536 | -- alternatives and for the right operand of a membership test. An |
11537 | -- others_choice is static if the corresponding expression is static. | |
7c0c95b8 | 11538 | -- The staticness of the bounds is checked separately. |
3b23aaa0 | 11539 | |
11540 | function Is_Static_Choice (N : Node_Id) return Boolean; | |
11541 | -- Returns True if N represents a static choice (static subtype, or | |
a360a0f7 | 11542 | -- static subtype indication, or static expression, or static range). |
3b23aaa0 | 11543 | -- |
11544 | -- Note that this is a bit more inclusive than we actually need | |
11545 | -- (in particular membership tests do not allow the use of subtype | |
a360a0f7 | 11546 | -- indications). But that doesn't matter, we have already checked |
3b23aaa0 | 11547 | -- that the construct is legal to get this far. |
11548 | ||
11549 | function Is_Type_Ref (N : Node_Id) return Boolean; | |
11550 | pragma Inline (Is_Type_Ref); | |
973c2fba | 11551 | -- Returns True if N is a reference to the type for the predicate in the |
11552 | -- expression (i.e. if it is an identifier whose Chars field matches the | |
11553 | -- Nam given in the call). N must not be parenthesized, if the type name | |
11554 | -- appears in parens, this routine will return False. | |
10f62e3a | 11555 | -- |
ea90be0f | 11556 | -- The routine also returns True for function calls generated during the |
11557 | -- expansion of comparison operators on strings, which are intended to | |
11558 | -- be legal in static predicates, and are converted into calls to array | |
11559 | -- comparison routines in the body of the corresponding predicate | |
11560 | -- function. | |
11561 | ||
3b23aaa0 | 11562 | ---------------------------------- |
11563 | -- All_Static_Case_Alternatives -- | |
11564 | ---------------------------------- | |
11565 | ||
11566 | function All_Static_Case_Alternatives (L : List_Id) return Boolean is | |
11567 | N : Node_Id; | |
11568 | ||
11569 | begin | |
11570 | N := First (L); | |
11571 | while Present (N) loop | |
11572 | if not (All_Static_Choices (Discrete_Choices (N)) | |
11573 | and then Is_OK_Static_Expression (Expression (N))) | |
11574 | then | |
11575 | return False; | |
11576 | end if; | |
11577 | ||
11578 | Next (N); | |
11579 | end loop; | |
11580 | ||
11581 | return True; | |
11582 | end All_Static_Case_Alternatives; | |
11583 | ||
11584 | ------------------------ | |
11585 | -- All_Static_Choices -- | |
11586 | ------------------------ | |
11587 | ||
11588 | function All_Static_Choices (L : List_Id) return Boolean is | |
11589 | N : Node_Id; | |
11590 | ||
11591 | begin | |
11592 | N := First (L); | |
11593 | while Present (N) loop | |
11594 | if not Is_Static_Choice (N) then | |
11595 | return False; | |
11596 | end if; | |
11597 | ||
11598 | Next (N); | |
11599 | end loop; | |
11600 | ||
11601 | return True; | |
11602 | end All_Static_Choices; | |
11603 | ||
11604 | ---------------------- | |
11605 | -- Is_Static_Choice -- | |
11606 | ---------------------- | |
11607 | ||
11608 | function Is_Static_Choice (N : Node_Id) return Boolean is | |
11609 | begin | |
7c0c95b8 | 11610 | return Nkind (N) = N_Others_Choice |
11611 | or else Is_OK_Static_Expression (N) | |
3b23aaa0 | 11612 | or else (Is_Entity_Name (N) and then Is_Type (Entity (N)) |
11613 | and then Is_OK_Static_Subtype (Entity (N))) | |
11614 | or else (Nkind (N) = N_Subtype_Indication | |
11615 | and then Is_OK_Static_Subtype (Entity (N))) | |
11616 | or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N)); | |
11617 | end Is_Static_Choice; | |
11618 | ||
11619 | ----------------- | |
11620 | -- Is_Type_Ref -- | |
11621 | ----------------- | |
11622 | ||
11623 | function Is_Type_Ref (N : Node_Id) return Boolean is | |
11624 | begin | |
ea90be0f | 11625 | return (Nkind (N) = N_Identifier |
11626 | and then Chars (N) = Nam | |
11627 | and then Paren_Count (N) = 0) | |
11628 | or else Nkind (N) = N_Function_Call; | |
3b23aaa0 | 11629 | end Is_Type_Ref; |
11630 | ||
11631 | -- Start of processing for Is_Predicate_Static | |
11632 | ||
11633 | begin | |
3b23aaa0 | 11634 | -- Predicate_Static means one of the following holds. Numbers are the |
11635 | -- corresponding paragraph numbers in (RM 3.2.4(16-22)). | |
11636 | ||
11637 | -- 16: A static expression | |
11638 | ||
11639 | if Is_OK_Static_Expression (Expr) then | |
11640 | return True; | |
11641 | ||
11642 | -- 17: A membership test whose simple_expression is the current | |
11643 | -- instance, and whose membership_choice_list meets the requirements | |
11644 | -- for a static membership test. | |
11645 | ||
11646 | elsif Nkind (Expr) in N_Membership_Test | |
11647 | and then ((Present (Right_Opnd (Expr)) | |
11648 | and then Is_Static_Choice (Right_Opnd (Expr))) | |
11649 | or else | |
11650 | (Present (Alternatives (Expr)) | |
11651 | and then All_Static_Choices (Alternatives (Expr)))) | |
11652 | then | |
11653 | return True; | |
11654 | ||
11655 | -- 18. A case_expression whose selecting_expression is the current | |
11656 | -- instance, and whose dependent expressions are static expressions. | |
11657 | ||
11658 | elsif Nkind (Expr) = N_Case_Expression | |
11659 | and then Is_Type_Ref (Expression (Expr)) | |
11660 | and then All_Static_Case_Alternatives (Alternatives (Expr)) | |
11661 | then | |
11662 | return True; | |
11663 | ||
11664 | -- 19. A call to a predefined equality or ordering operator, where one | |
11665 | -- operand is the current instance, and the other is a static | |
11666 | -- expression. | |
11667 | ||
94d896aa | 11668 | -- Note: the RM is clearly wrong here in not excluding string types. |
11669 | -- Without this exclusion, we would allow expressions like X > "ABC" | |
11670 | -- to be considered as predicate-static, which is clearly not intended, | |
11671 | -- since the idea is for predicate-static to be a subset of normal | |
11672 | -- static expressions (and "DEF" > "ABC" is not a static expression). | |
11673 | ||
11674 | -- However, we do allow internally generated (not from source) equality | |
11675 | -- and inequality operations to be valid on strings (this helps deal | |
11676 | -- with cases where we transform A in "ABC" to A = "ABC). | |
11677 | ||
ea90be0f | 11678 | -- In fact, it appears that the intent of the ARG is to extend static |
11679 | -- predicates to strings, and that the extension should probably apply | |
11680 | -- to static expressions themselves. The code below accepts comparison | |
11681 | -- operators that apply to static strings. | |
11682 | ||
3b23aaa0 | 11683 | elsif Nkind (Expr) in N_Op_Compare |
11684 | and then ((Is_Type_Ref (Left_Opnd (Expr)) | |
11685 | and then Is_OK_Static_Expression (Right_Opnd (Expr))) | |
11686 | or else | |
11687 | (Is_Type_Ref (Right_Opnd (Expr)) | |
11688 | and then Is_OK_Static_Expression (Left_Opnd (Expr)))) | |
11689 | then | |
11690 | return True; | |
11691 | ||
11692 | -- 20. A call to a predefined boolean logical operator, where each | |
11693 | -- operand is predicate-static. | |
11694 | ||
11695 | elsif (Nkind_In (Expr, N_Op_And, N_Op_Or, N_Op_Xor) | |
11696 | and then Is_Predicate_Static (Left_Opnd (Expr), Nam) | |
11697 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam)) | |
11698 | or else | |
11699 | (Nkind (Expr) = N_Op_Not | |
11700 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam)) | |
11701 | then | |
11702 | return True; | |
11703 | ||
11704 | -- 21. A short-circuit control form where both operands are | |
11705 | -- predicate-static. | |
11706 | ||
11707 | elsif Nkind (Expr) in N_Short_Circuit | |
11708 | and then Is_Predicate_Static (Left_Opnd (Expr), Nam) | |
11709 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam) | |
11710 | then | |
11711 | return True; | |
11712 | ||
11713 | -- 22. A parenthesized predicate-static expression. This does not | |
11714 | -- require any special test, since we just ignore paren levels in | |
11715 | -- all the cases above. | |
11716 | ||
11717 | -- One more test that is an implementation artifact caused by the fact | |
499918a7 | 11718 | -- that we are analyzing not the original expression, but the generated |
3b23aaa0 | 11719 | -- expression in the body of the predicate function. This can include |
a360a0f7 | 11720 | -- references to inherited predicates, so that the expression we are |
3b23aaa0 | 11721 | -- processing looks like: |
11722 | ||
75491446 | 11723 | -- xxPredicate (typ (Inns)) and then expression |
3b23aaa0 | 11724 | |
11725 | -- Where the call is to a Predicate function for an inherited predicate. | |
60a4a5af | 11726 | -- We simply ignore such a call, which could be to either a dynamic or |
11727 | -- a static predicate. Note that if the parent predicate is dynamic then | |
11728 | -- eventually this type will be marked as dynamic, but you are allowed | |
11729 | -- to specify a static predicate for a subtype which is inheriting a | |
11730 | -- dynamic predicate, so the static predicate validation here ignores | |
11731 | -- the inherited predicate even if it is dynamic. | |
7db33803 | 11732 | -- In all cases, a static predicate can only apply to a scalar type. |
3b23aaa0 | 11733 | |
11734 | elsif Nkind (Expr) = N_Function_Call | |
11735 | and then Is_Predicate_Function (Entity (Name (Expr))) | |
7db33803 | 11736 | and then Is_Scalar_Type (Etype (First_Entity (Entity (Name (Expr))))) |
3b23aaa0 | 11737 | then |
11738 | return True; | |
11739 | ||
11740 | -- That's an exhaustive list of tests, all other cases are not | |
a360a0f7 | 11741 | -- predicate-static, so we return False. |
3b23aaa0 | 11742 | |
11743 | else | |
11744 | return False; | |
11745 | end if; | |
11746 | end Is_Predicate_Static; | |
11747 | ||
2ff55065 | 11748 | --------------------- |
11749 | -- Kill_Rep_Clause -- | |
11750 | --------------------- | |
11751 | ||
11752 | procedure Kill_Rep_Clause (N : Node_Id) is | |
11753 | begin | |
11754 | pragma Assert (Ignore_Rep_Clauses); | |
360f426f | 11755 | |
11756 | -- Note: we use Replace rather than Rewrite, because we don't want | |
11757 | -- ASIS to be able to use Original_Node to dig out the (undecorated) | |
11758 | -- rep clause that is being replaced. | |
11759 | ||
4949ddd5 | 11760 | Replace (N, Make_Null_Statement (Sloc (N))); |
360f426f | 11761 | |
11762 | -- The null statement must be marked as not coming from source. This is | |
37c6552c | 11763 | -- so that ASIS ignores it, and also the back end does not expect bogus |
360f426f | 11764 | -- "from source" null statements in weird places (e.g. in declarative |
11765 | -- regions where such null statements are not allowed). | |
11766 | ||
11767 | Set_Comes_From_Source (N, False); | |
2ff55065 | 11768 | end Kill_Rep_Clause; |
11769 | ||
d6f39728 | 11770 | ------------------ |
11771 | -- Minimum_Size -- | |
11772 | ------------------ | |
11773 | ||
11774 | function Minimum_Size | |
11775 | (T : Entity_Id; | |
d5b349fa | 11776 | Biased : Boolean := False) return Nat |
d6f39728 | 11777 | is |
11778 | Lo : Uint := No_Uint; | |
11779 | Hi : Uint := No_Uint; | |
11780 | LoR : Ureal := No_Ureal; | |
11781 | HiR : Ureal := No_Ureal; | |
11782 | LoSet : Boolean := False; | |
11783 | HiSet : Boolean := False; | |
11784 | B : Uint; | |
11785 | S : Nat; | |
11786 | Ancest : Entity_Id; | |
f15731c4 | 11787 | R_Typ : constant Entity_Id := Root_Type (T); |
d6f39728 | 11788 | |
11789 | begin | |
11790 | -- If bad type, return 0 | |
11791 | ||
11792 | if T = Any_Type then | |
11793 | return 0; | |
11794 | ||
11795 | -- For generic types, just return zero. There cannot be any legitimate | |
11796 | -- need to know such a size, but this routine may be called with a | |
11797 | -- generic type as part of normal processing. | |
11798 | ||
f02a9a9a | 11799 | elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then |
d6f39728 | 11800 | return 0; |
11801 | ||
74c7ae52 | 11802 | -- Access types (cannot have size smaller than System.Address) |
d6f39728 | 11803 | |
11804 | elsif Is_Access_Type (T) then | |
74c7ae52 | 11805 | return System_Address_Size; |
d6f39728 | 11806 | |
11807 | -- Floating-point types | |
11808 | ||
11809 | elsif Is_Floating_Point_Type (T) then | |
f15731c4 | 11810 | return UI_To_Int (Esize (R_Typ)); |
d6f39728 | 11811 | |
11812 | -- Discrete types | |
11813 | ||
11814 | elsif Is_Discrete_Type (T) then | |
11815 | ||
fdd294d1 | 11816 | -- The following loop is looking for the nearest compile time known |
11817 | -- bounds following the ancestor subtype chain. The idea is to find | |
11818 | -- the most restrictive known bounds information. | |
d6f39728 | 11819 | |
11820 | Ancest := T; | |
11821 | loop | |
11822 | if Ancest = Any_Type or else Etype (Ancest) = Any_Type then | |
11823 | return 0; | |
11824 | end if; | |
11825 | ||
11826 | if not LoSet then | |
11827 | if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then | |
11828 | Lo := Expr_Rep_Value (Type_Low_Bound (Ancest)); | |
11829 | LoSet := True; | |
11830 | exit when HiSet; | |
11831 | end if; | |
11832 | end if; | |
11833 | ||
11834 | if not HiSet then | |
11835 | if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then | |
11836 | Hi := Expr_Rep_Value (Type_High_Bound (Ancest)); | |
11837 | HiSet := True; | |
11838 | exit when LoSet; | |
11839 | end if; | |
11840 | end if; | |
11841 | ||
11842 | Ancest := Ancestor_Subtype (Ancest); | |
11843 | ||
11844 | if No (Ancest) then | |
11845 | Ancest := Base_Type (T); | |
11846 | ||
11847 | if Is_Generic_Type (Ancest) then | |
11848 | return 0; | |
11849 | end if; | |
11850 | end if; | |
11851 | end loop; | |
11852 | ||
11853 | -- Fixed-point types. We can't simply use Expr_Value to get the | |
fdd294d1 | 11854 | -- Corresponding_Integer_Value values of the bounds, since these do not |
11855 | -- get set till the type is frozen, and this routine can be called | |
11856 | -- before the type is frozen. Similarly the test for bounds being static | |
11857 | -- needs to include the case where we have unanalyzed real literals for | |
11858 | -- the same reason. | |
d6f39728 | 11859 | |
11860 | elsif Is_Fixed_Point_Type (T) then | |
11861 | ||
fdd294d1 | 11862 | -- The following loop is looking for the nearest compile time known |
11863 | -- bounds following the ancestor subtype chain. The idea is to find | |
11864 | -- the most restrictive known bounds information. | |
d6f39728 | 11865 | |
11866 | Ancest := T; | |
11867 | loop | |
11868 | if Ancest = Any_Type or else Etype (Ancest) = Any_Type then | |
11869 | return 0; | |
11870 | end if; | |
11871 | ||
3062c401 | 11872 | -- Note: In the following two tests for LoSet and HiSet, it may |
11873 | -- seem redundant to test for N_Real_Literal here since normally | |
11874 | -- one would assume that the test for the value being known at | |
11875 | -- compile time includes this case. However, there is a glitch. | |
11876 | -- If the real literal comes from folding a non-static expression, | |
11877 | -- then we don't consider any non- static expression to be known | |
11878 | -- at compile time if we are in configurable run time mode (needed | |
11879 | -- in some cases to give a clearer definition of what is and what | |
11880 | -- is not accepted). So the test is indeed needed. Without it, we | |
11881 | -- would set neither Lo_Set nor Hi_Set and get an infinite loop. | |
11882 | ||
d6f39728 | 11883 | if not LoSet then |
11884 | if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal | |
11885 | or else Compile_Time_Known_Value (Type_Low_Bound (Ancest)) | |
11886 | then | |
11887 | LoR := Expr_Value_R (Type_Low_Bound (Ancest)); | |
11888 | LoSet := True; | |
11889 | exit when HiSet; | |
11890 | end if; | |
11891 | end if; | |
11892 | ||
11893 | if not HiSet then | |
11894 | if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal | |
11895 | or else Compile_Time_Known_Value (Type_High_Bound (Ancest)) | |
11896 | then | |
11897 | HiR := Expr_Value_R (Type_High_Bound (Ancest)); | |
11898 | HiSet := True; | |
11899 | exit when LoSet; | |
11900 | end if; | |
11901 | end if; | |
11902 | ||
11903 | Ancest := Ancestor_Subtype (Ancest); | |
11904 | ||
11905 | if No (Ancest) then | |
11906 | Ancest := Base_Type (T); | |
11907 | ||
11908 | if Is_Generic_Type (Ancest) then | |
11909 | return 0; | |
11910 | end if; | |
11911 | end if; | |
11912 | end loop; | |
11913 | ||
11914 | Lo := UR_To_Uint (LoR / Small_Value (T)); | |
11915 | Hi := UR_To_Uint (HiR / Small_Value (T)); | |
11916 | ||
11917 | -- No other types allowed | |
11918 | ||
11919 | else | |
11920 | raise Program_Error; | |
11921 | end if; | |
11922 | ||
2866d595 | 11923 | -- Fall through with Hi and Lo set. Deal with biased case |
d6f39728 | 11924 | |
cc46ff4b | 11925 | if (Biased |
11926 | and then not Is_Fixed_Point_Type (T) | |
11927 | and then not (Is_Enumeration_Type (T) | |
11928 | and then Has_Non_Standard_Rep (T))) | |
d6f39728 | 11929 | or else Has_Biased_Representation (T) |
11930 | then | |
11931 | Hi := Hi - Lo; | |
11932 | Lo := Uint_0; | |
11933 | end if; | |
11934 | ||
005366f7 | 11935 | -- Null range case, size is always zero. We only do this in the discrete |
11936 | -- type case, since that's the odd case that came up. Probably we should | |
11937 | -- also do this in the fixed-point case, but doing so causes peculiar | |
11938 | -- gigi failures, and it is not worth worrying about this incredibly | |
11939 | -- marginal case (explicit null-range fixed-point type declarations)??? | |
11940 | ||
11941 | if Lo > Hi and then Is_Discrete_Type (T) then | |
11942 | S := 0; | |
11943 | ||
d6f39728 | 11944 | -- Signed case. Note that we consider types like range 1 .. -1 to be |
fdd294d1 | 11945 | -- signed for the purpose of computing the size, since the bounds have |
1a34e48c | 11946 | -- to be accommodated in the base type. |
d6f39728 | 11947 | |
005366f7 | 11948 | elsif Lo < 0 or else Hi < 0 then |
d6f39728 | 11949 | S := 1; |
11950 | B := Uint_1; | |
11951 | ||
da253936 | 11952 | -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1)) |
11953 | -- Note that we accommodate the case where the bounds cross. This | |
d6f39728 | 11954 | -- can happen either because of the way the bounds are declared |
11955 | -- or because of the algorithm in Freeze_Fixed_Point_Type. | |
11956 | ||
11957 | while Lo < -B | |
11958 | or else Hi < -B | |
11959 | or else Lo >= B | |
11960 | or else Hi >= B | |
11961 | loop | |
11962 | B := Uint_2 ** S; | |
11963 | S := S + 1; | |
11964 | end loop; | |
11965 | ||
11966 | -- Unsigned case | |
11967 | ||
11968 | else | |
11969 | -- If both bounds are positive, make sure that both are represen- | |
11970 | -- table in the case where the bounds are crossed. This can happen | |
11971 | -- either because of the way the bounds are declared, or because of | |
11972 | -- the algorithm in Freeze_Fixed_Point_Type. | |
11973 | ||
11974 | if Lo > Hi then | |
11975 | Hi := Lo; | |
11976 | end if; | |
11977 | ||
da253936 | 11978 | -- S = size, (can accommodate 0 .. (2**size - 1)) |
d6f39728 | 11979 | |
11980 | S := 0; | |
11981 | while Hi >= Uint_2 ** S loop | |
11982 | S := S + 1; | |
11983 | end loop; | |
11984 | end if; | |
11985 | ||
11986 | return S; | |
11987 | end Minimum_Size; | |
11988 | ||
44e4341e | 11989 | --------------------------- |
11990 | -- New_Stream_Subprogram -- | |
11991 | --------------------------- | |
d6f39728 | 11992 | |
44e4341e | 11993 | procedure New_Stream_Subprogram |
11994 | (N : Node_Id; | |
11995 | Ent : Entity_Id; | |
11996 | Subp : Entity_Id; | |
11997 | Nam : TSS_Name_Type) | |
d6f39728 | 11998 | is |
11999 | Loc : constant Source_Ptr := Sloc (N); | |
9dfe12ae | 12000 | Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam); |
f15731c4 | 12001 | Subp_Id : Entity_Id; |
d6f39728 | 12002 | Subp_Decl : Node_Id; |
12003 | F : Entity_Id; | |
12004 | Etyp : Entity_Id; | |
12005 | ||
44e4341e | 12006 | Defer_Declaration : constant Boolean := |
12007 | Is_Tagged_Type (Ent) or else Is_Private_Type (Ent); | |
12008 | -- For a tagged type, there is a declaration for each stream attribute | |
12009 | -- at the freeze point, and we must generate only a completion of this | |
12010 | -- declaration. We do the same for private types, because the full view | |
12011 | -- might be tagged. Otherwise we generate a declaration at the point of | |
449c4f58 | 12012 | -- the attribute definition clause. If the attribute definition comes |
12013 | -- from an aspect specification the declaration is part of the freeze | |
12014 | -- actions of the type. | |
44e4341e | 12015 | |
f15731c4 | 12016 | function Build_Spec return Node_Id; |
12017 | -- Used for declaration and renaming declaration, so that this is | |
12018 | -- treated as a renaming_as_body. | |
12019 | ||
12020 | ---------------- | |
12021 | -- Build_Spec -- | |
12022 | ---------------- | |
12023 | ||
d5b349fa | 12024 | function Build_Spec return Node_Id is |
44e4341e | 12025 | Out_P : constant Boolean := (Nam = TSS_Stream_Read); |
12026 | Formals : List_Id; | |
12027 | Spec : Node_Id; | |
83c6c069 | 12028 | T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc); |
44e4341e | 12029 | |
f15731c4 | 12030 | begin |
9dfe12ae | 12031 | Subp_Id := Make_Defining_Identifier (Loc, Sname); |
f15731c4 | 12032 | |
44e4341e | 12033 | -- S : access Root_Stream_Type'Class |
12034 | ||
12035 | Formals := New_List ( | |
12036 | Make_Parameter_Specification (Loc, | |
12037 | Defining_Identifier => | |
12038 | Make_Defining_Identifier (Loc, Name_S), | |
12039 | Parameter_Type => | |
12040 | Make_Access_Definition (Loc, | |
12041 | Subtype_Mark => | |
83c6c069 | 12042 | New_Occurrence_Of ( |
44e4341e | 12043 | Designated_Type (Etype (F)), Loc)))); |
12044 | ||
12045 | if Nam = TSS_Stream_Input then | |
4bba0a8d | 12046 | Spec := |
12047 | Make_Function_Specification (Loc, | |
12048 | Defining_Unit_Name => Subp_Id, | |
12049 | Parameter_Specifications => Formals, | |
12050 | Result_Definition => T_Ref); | |
44e4341e | 12051 | else |
12052 | -- V : [out] T | |
f15731c4 | 12053 | |
44e4341e | 12054 | Append_To (Formals, |
12055 | Make_Parameter_Specification (Loc, | |
12056 | Defining_Identifier => Make_Defining_Identifier (Loc, Name_V), | |
12057 | Out_Present => Out_P, | |
12058 | Parameter_Type => T_Ref)); | |
f15731c4 | 12059 | |
d3ef794c | 12060 | Spec := |
12061 | Make_Procedure_Specification (Loc, | |
12062 | Defining_Unit_Name => Subp_Id, | |
12063 | Parameter_Specifications => Formals); | |
44e4341e | 12064 | end if; |
f15731c4 | 12065 | |
44e4341e | 12066 | return Spec; |
12067 | end Build_Spec; | |
d6f39728 | 12068 | |
44e4341e | 12069 | -- Start of processing for New_Stream_Subprogram |
d6f39728 | 12070 | |
44e4341e | 12071 | begin |
12072 | F := First_Formal (Subp); | |
12073 | ||
12074 | if Ekind (Subp) = E_Procedure then | |
12075 | Etyp := Etype (Next_Formal (F)); | |
d6f39728 | 12076 | else |
44e4341e | 12077 | Etyp := Etype (Subp); |
d6f39728 | 12078 | end if; |
f15731c4 | 12079 | |
44e4341e | 12080 | -- Prepare subprogram declaration and insert it as an action on the |
12081 | -- clause node. The visibility for this entity is used to test for | |
12082 | -- visibility of the attribute definition clause (in the sense of | |
12083 | -- 8.3(23) as amended by AI-195). | |
9dfe12ae | 12084 | |
44e4341e | 12085 | if not Defer_Declaration then |
f15731c4 | 12086 | Subp_Decl := |
12087 | Make_Subprogram_Declaration (Loc, | |
12088 | Specification => Build_Spec); | |
44e4341e | 12089 | |
12090 | -- For a tagged type, there is always a visible declaration for each | |
15ebb600 | 12091 | -- stream TSS (it is a predefined primitive operation), and the |
44e4341e | 12092 | -- completion of this declaration occurs at the freeze point, which is |
12093 | -- not always visible at places where the attribute definition clause is | |
12094 | -- visible. So, we create a dummy entity here for the purpose of | |
12095 | -- tracking the visibility of the attribute definition clause itself. | |
12096 | ||
12097 | else | |
12098 | Subp_Id := | |
55868293 | 12099 | Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V')); |
44e4341e | 12100 | Subp_Decl := |
12101 | Make_Object_Declaration (Loc, | |
12102 | Defining_Identifier => Subp_Id, | |
12103 | Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc)); | |
f15731c4 | 12104 | end if; |
12105 | ||
449c4f58 | 12106 | if not Defer_Declaration |
12107 | and then From_Aspect_Specification (N) | |
12108 | and then Has_Delayed_Freeze (Ent) | |
12109 | then | |
12110 | Append_Freeze_Action (Ent, Subp_Decl); | |
12111 | ||
12112 | else | |
12113 | Insert_Action (N, Subp_Decl); | |
12114 | Set_Entity (N, Subp_Id); | |
12115 | end if; | |
44e4341e | 12116 | |
d6f39728 | 12117 | Subp_Decl := |
12118 | Make_Subprogram_Renaming_Declaration (Loc, | |
f15731c4 | 12119 | Specification => Build_Spec, |
8acb75b4 | 12120 | Name => New_Occurrence_Of (Subp, Loc)); |
d6f39728 | 12121 | |
44e4341e | 12122 | if Defer_Declaration then |
d6f39728 | 12123 | Set_TSS (Base_Type (Ent), Subp_Id); |
449c4f58 | 12124 | |
d6f39728 | 12125 | else |
449c4f58 | 12126 | if From_Aspect_Specification (N) then |
12127 | Append_Freeze_Action (Ent, Subp_Decl); | |
449c4f58 | 12128 | else |
12129 | Insert_Action (N, Subp_Decl); | |
12130 | end if; | |
12131 | ||
d6f39728 | 12132 | Copy_TSS (Subp_Id, Base_Type (Ent)); |
12133 | end if; | |
44e4341e | 12134 | end New_Stream_Subprogram; |
d6f39728 | 12135 | |
2625eb01 | 12136 | ------------------------------------------ |
12137 | -- Push_Scope_And_Install_Discriminants -- | |
12138 | ------------------------------------------ | |
12139 | ||
12140 | procedure Push_Scope_And_Install_Discriminants (E : Entity_Id) is | |
12141 | begin | |
12142 | if Has_Discriminants (E) then | |
12143 | Push_Scope (E); | |
12144 | ||
97c23bbe | 12145 | -- Make the discriminants visible for type declarations and protected |
2625eb01 | 12146 | -- type declarations, not for subtype declarations (RM 13.1.1 (12/3)) |
12147 | ||
12148 | if Nkind (Parent (E)) /= N_Subtype_Declaration then | |
12149 | Install_Discriminants (E); | |
12150 | end if; | |
12151 | end if; | |
12152 | end Push_Scope_And_Install_Discriminants; | |
12153 | ||
d6f39728 | 12154 | ------------------------ |
12155 | -- Rep_Item_Too_Early -- | |
12156 | ------------------------ | |
12157 | ||
80d4fec4 | 12158 | function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is |
d6f39728 | 12159 | begin |
44e4341e | 12160 | -- Cannot apply non-operational rep items to generic types |
d6f39728 | 12161 | |
f15731c4 | 12162 | if Is_Operational_Item (N) then |
12163 | return False; | |
12164 | ||
12165 | elsif Is_Type (T) | |
d6f39728 | 12166 | and then Is_Generic_Type (Root_Type (T)) |
e17c5076 | 12167 | and then (Nkind (N) /= N_Pragma |
12168 | or else Get_Pragma_Id (N) /= Pragma_Convention) | |
d6f39728 | 12169 | then |
503f7fd3 | 12170 | Error_Msg_N ("representation item not allowed for generic type", N); |
d6f39728 | 12171 | return True; |
12172 | end if; | |
12173 | ||
fdd294d1 | 12174 | -- Otherwise check for incomplete type |
d6f39728 | 12175 | |
12176 | if Is_Incomplete_Or_Private_Type (T) | |
12177 | and then No (Underlying_Type (T)) | |
d64221a7 | 12178 | and then |
12179 | (Nkind (N) /= N_Pragma | |
60014bc9 | 12180 | or else Get_Pragma_Id (N) /= Pragma_Import) |
d6f39728 | 12181 | then |
12182 | Error_Msg_N | |
12183 | ("representation item must be after full type declaration", N); | |
12184 | return True; | |
12185 | ||
1a34e48c | 12186 | -- If the type has incomplete components, a representation clause is |
d6f39728 | 12187 | -- illegal but stream attributes and Convention pragmas are correct. |
12188 | ||
12189 | elsif Has_Private_Component (T) then | |
f15731c4 | 12190 | if Nkind (N) = N_Pragma then |
d6f39728 | 12191 | return False; |
b9e61b2a | 12192 | |
d6f39728 | 12193 | else |
12194 | Error_Msg_N | |
12195 | ("representation item must appear after type is fully defined", | |
12196 | N); | |
12197 | return True; | |
12198 | end if; | |
12199 | else | |
12200 | return False; | |
12201 | end if; | |
12202 | end Rep_Item_Too_Early; | |
12203 | ||
12204 | ----------------------- | |
12205 | -- Rep_Item_Too_Late -- | |
12206 | ----------------------- | |
12207 | ||
12208 | function Rep_Item_Too_Late | |
12209 | (T : Entity_Id; | |
12210 | N : Node_Id; | |
d5b349fa | 12211 | FOnly : Boolean := False) return Boolean |
d6f39728 | 12212 | is |
12213 | S : Entity_Id; | |
12214 | Parent_Type : Entity_Id; | |
12215 | ||
4d0944e9 | 12216 | procedure No_Type_Rep_Item; |
12217 | -- Output message indicating that no type-related aspects can be | |
12218 | -- specified due to some property of the parent type. | |
12219 | ||
d6f39728 | 12220 | procedure Too_Late; |
4d0944e9 | 12221 | -- Output message for an aspect being specified too late |
12222 | ||
12223 | -- Note that neither of the above errors is considered a serious one, | |
12224 | -- since the effect is simply that we ignore the representation clause | |
12225 | -- in these cases. | |
04d38ee4 | 12226 | -- Is this really true? In any case if we make this change we must |
12227 | -- document the requirement in the spec of Rep_Item_Too_Late that | |
12228 | -- if True is returned, then the rep item must be completely ignored??? | |
4d0944e9 | 12229 | |
12230 | ---------------------- | |
12231 | -- No_Type_Rep_Item -- | |
12232 | ---------------------- | |
12233 | ||
12234 | procedure No_Type_Rep_Item is | |
12235 | begin | |
12236 | Error_Msg_N ("|type-related representation item not permitted!", N); | |
12237 | end No_Type_Rep_Item; | |
d53a018a | 12238 | |
12239 | -------------- | |
12240 | -- Too_Late -- | |
12241 | -------------- | |
d6f39728 | 12242 | |
12243 | procedure Too_Late is | |
12244 | begin | |
ce4da1ed | 12245 | -- Other compilers seem more relaxed about rep items appearing too |
12246 | -- late. Since analysis tools typically don't care about rep items | |
12247 | -- anyway, no reason to be too strict about this. | |
12248 | ||
a9cd517c | 12249 | if not Relaxed_RM_Semantics then |
12250 | Error_Msg_N ("|representation item appears too late!", N); | |
12251 | end if; | |
d6f39728 | 12252 | end Too_Late; |
12253 | ||
12254 | -- Start of processing for Rep_Item_Too_Late | |
12255 | ||
12256 | begin | |
a3248fc4 | 12257 | -- First make sure entity is not frozen (RM 13.1(9)) |
d6f39728 | 12258 | |
12259 | if Is_Frozen (T) | |
a3248fc4 | 12260 | |
12261 | -- Exclude imported types, which may be frozen if they appear in a | |
12262 | -- representation clause for a local type. | |
12263 | ||
4aa270d8 | 12264 | and then not From_Limited_With (T) |
a3248fc4 | 12265 | |
a9cd517c | 12266 | -- Exclude generated entities (not coming from source). The common |
a3248fc4 | 12267 | -- case is when we generate a renaming which prematurely freezes the |
12268 | -- renamed internal entity, but we still want to be able to set copies | |
12269 | -- of attribute values such as Size/Alignment. | |
12270 | ||
12271 | and then Comes_From_Source (T) | |
d6f39728 | 12272 | then |
58e133a6 | 12273 | -- A self-referential aspect is illegal if it forces freezing the |
12274 | -- entity before the corresponding pragma has been analyzed. | |
12275 | ||
12276 | if Nkind_In (N, N_Attribute_Definition_Clause, N_Pragma) | |
12277 | and then From_Aspect_Specification (N) | |
12278 | then | |
12279 | Error_Msg_NE | |
ea90be0f | 12280 | ("aspect specification causes premature freezing of&", N, T); |
58e133a6 | 12281 | Set_Has_Delayed_Freeze (T, False); |
12282 | return True; | |
12283 | end if; | |
12284 | ||
d6f39728 | 12285 | Too_Late; |
12286 | S := First_Subtype (T); | |
12287 | ||
12288 | if Present (Freeze_Node (S)) then | |
04d38ee4 | 12289 | if not Relaxed_RM_Semantics then |
12290 | Error_Msg_NE | |
12291 | ("??no more representation items for }", Freeze_Node (S), S); | |
12292 | end if; | |
d6f39728 | 12293 | end if; |
12294 | ||
12295 | return True; | |
12296 | ||
d1a2e31b | 12297 | -- Check for case of untagged derived type whose parent either has |
4d0944e9 | 12298 | -- primitive operations, or is a by reference type (RM 13.1(10)). In |
12299 | -- this case we do not output a Too_Late message, since there is no | |
12300 | -- earlier point where the rep item could be placed to make it legal. | |
d6f39728 | 12301 | |
12302 | elsif Is_Type (T) | |
12303 | and then not FOnly | |
12304 | and then Is_Derived_Type (T) | |
12305 | and then not Is_Tagged_Type (T) | |
12306 | then | |
12307 | Parent_Type := Etype (Base_Type (T)); | |
12308 | ||
12309 | if Has_Primitive_Operations (Parent_Type) then | |
4d0944e9 | 12310 | No_Type_Rep_Item; |
04d38ee4 | 12311 | |
12312 | if not Relaxed_RM_Semantics then | |
12313 | Error_Msg_NE | |
12314 | ("\parent type & has primitive operations!", N, Parent_Type); | |
12315 | end if; | |
12316 | ||
d6f39728 | 12317 | return True; |
12318 | ||
12319 | elsif Is_By_Reference_Type (Parent_Type) then | |
4d0944e9 | 12320 | No_Type_Rep_Item; |
04d38ee4 | 12321 | |
12322 | if not Relaxed_RM_Semantics then | |
12323 | Error_Msg_NE | |
12324 | ("\parent type & is a by reference type!", N, Parent_Type); | |
12325 | end if; | |
12326 | ||
d6f39728 | 12327 | return True; |
12328 | end if; | |
12329 | end if; | |
12330 | ||
04d38ee4 | 12331 | -- No error, but one more warning to consider. The RM (surprisingly) |
12332 | -- allows this pattern: | |
12333 | ||
12334 | -- type S is ... | |
12335 | -- primitive operations for S | |
12336 | -- type R is new S; | |
12337 | -- rep clause for S | |
12338 | ||
12339 | -- Meaning that calls on the primitive operations of S for values of | |
12340 | -- type R may require possibly expensive implicit conversion operations. | |
12341 | -- This is not an error, but is worth a warning. | |
12342 | ||
12343 | if not Relaxed_RM_Semantics and then Is_Type (T) then | |
12344 | declare | |
12345 | DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T)); | |
12346 | ||
12347 | begin | |
12348 | if Present (DTL) | |
12349 | and then Has_Primitive_Operations (Base_Type (T)) | |
12350 | ||
12351 | -- For now, do not generate this warning for the case of aspect | |
12352 | -- specification using Ada 2012 syntax, since we get wrong | |
12353 | -- messages we do not understand. The whole business of derived | |
12354 | -- types and rep items seems a bit confused when aspects are | |
12355 | -- used, since the aspects are not evaluated till freeze time. | |
12356 | ||
12357 | and then not From_Aspect_Specification (N) | |
12358 | then | |
12359 | Error_Msg_Sloc := Sloc (DTL); | |
12360 | Error_Msg_N | |
12361 | ("representation item for& appears after derived type " | |
12362 | & "declaration#??", N); | |
12363 | Error_Msg_NE | |
12364 | ("\may result in implicit conversions for primitive " | |
12365 | & "operations of&??", N, T); | |
12366 | Error_Msg_NE | |
12367 | ("\to change representations when called with arguments " | |
12368 | & "of type&??", N, DTL); | |
12369 | end if; | |
12370 | end; | |
12371 | end if; | |
12372 | ||
3062c401 | 12373 | -- No error, link item into head of chain of rep items for the entity, |
12374 | -- but avoid chaining if we have an overloadable entity, and the pragma | |
12375 | -- is one that can apply to multiple overloaded entities. | |
12376 | ||
b9e61b2a | 12377 | if Is_Overloadable (T) and then Nkind (N) = N_Pragma then |
fdd294d1 | 12378 | declare |
ddccc924 | 12379 | Pname : constant Name_Id := Pragma_Name (N); |
fdd294d1 | 12380 | begin |
18393965 | 12381 | if Nam_In (Pname, Name_Convention, Name_Import, Name_Export, |
12382 | Name_External, Name_Interface) | |
fdd294d1 | 12383 | then |
12384 | return False; | |
12385 | end if; | |
12386 | end; | |
3062c401 | 12387 | end if; |
12388 | ||
fdd294d1 | 12389 | Record_Rep_Item (T, N); |
d6f39728 | 12390 | return False; |
12391 | end Rep_Item_Too_Late; | |
12392 | ||
2072eaa9 | 12393 | ------------------------------------- |
12394 | -- Replace_Type_References_Generic -- | |
12395 | ------------------------------------- | |
12396 | ||
37c6552c | 12397 | procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is |
12398 | TName : constant Name_Id := Chars (T); | |
2072eaa9 | 12399 | |
97c23bbe | 12400 | function Replace_Type_Ref (N : Node_Id) return Traverse_Result; |
2072eaa9 | 12401 | -- Processes a single node in the traversal procedure below, checking |
12402 | -- if node N should be replaced, and if so, doing the replacement. | |
12403 | ||
d0931270 | 12404 | function Visible_Component (Comp : Name_Id) return Entity_Id; |
12405 | -- Given an identifier in the expression, check whether there is a | |
12406 | -- discriminant or component of the type that is directy visible, and | |
12407 | -- rewrite it as the corresponding selected component of the formal of | |
12408 | -- the subprogram. The entity is located by a sequential search, which | |
12409 | -- seems acceptable given the typical size of component lists and check | |
12410 | -- expressions. Possible optimization ??? | |
12411 | ||
97c23bbe | 12412 | ---------------------- |
12413 | -- Replace_Type_Ref -- | |
12414 | ---------------------- | |
2072eaa9 | 12415 | |
97c23bbe | 12416 | function Replace_Type_Ref (N : Node_Id) return Traverse_Result is |
d0931270 | 12417 | Loc : constant Source_Ptr := Sloc (N); |
2072eaa9 | 12418 | |
d0931270 | 12419 | procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id); |
77fd9c7a | 12420 | -- Add the proper prefix to a reference to a component of the type |
12421 | -- when it is not already a selected component. | |
d0931270 | 12422 | |
12423 | ---------------- | |
12424 | -- Add_Prefix -- | |
12425 | ---------------- | |
2072eaa9 | 12426 | |
d0931270 | 12427 | procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id) is |
12428 | begin | |
12429 | Rewrite (Ref, | |
12430 | Make_Selected_Component (Loc, | |
77fd9c7a | 12431 | Prefix => New_Occurrence_Of (T, Loc), |
d0931270 | 12432 | Selector_Name => New_Occurrence_Of (Comp, Loc))); |
12433 | Replace_Type_Reference (Prefix (Ref)); | |
12434 | end Add_Prefix; | |
12435 | ||
77fd9c7a | 12436 | -- Local variables |
12437 | ||
12438 | Comp : Entity_Id; | |
12439 | Pref : Node_Id; | |
12440 | Scop : Entity_Id; | |
12441 | ||
d0931270 | 12442 | -- Start of processing for Replace_Type_Ref |
12443 | ||
12444 | begin | |
2072eaa9 | 12445 | if Nkind (N) = N_Identifier then |
12446 | ||
97c23bbe | 12447 | -- If not the type name, check whether it is a reference to some |
12448 | -- other type, which must be frozen before the predicate function | |
12449 | -- is analyzed, i.e. before the freeze node of the type to which | |
12450 | -- the predicate applies. | |
2072eaa9 | 12451 | |
12452 | if Chars (N) /= TName then | |
37c6552c | 12453 | if Present (Current_Entity (N)) |
46532462 | 12454 | and then Is_Type (Current_Entity (N)) |
37c6552c | 12455 | then |
12456 | Freeze_Before (Freeze_Node (T), Current_Entity (N)); | |
12457 | end if; | |
12458 | ||
d0931270 | 12459 | -- The components of the type are directly visible and can |
12460 | -- be referenced without a prefix. | |
12461 | ||
12462 | if Nkind (Parent (N)) = N_Selected_Component then | |
12463 | null; | |
12464 | ||
12465 | -- In expression C (I), C may be a directly visible function | |
12466 | -- or a visible component that has an array type. Disambiguate | |
12467 | -- by examining the component type. | |
12468 | ||
12469 | elsif Nkind (Parent (N)) = N_Indexed_Component | |
12470 | and then N = Prefix (Parent (N)) | |
12471 | then | |
77fd9c7a | 12472 | Comp := Visible_Component (Chars (N)); |
d0931270 | 12473 | |
77fd9c7a | 12474 | if Present (Comp) and then Is_Array_Type (Etype (Comp)) then |
12475 | Add_Prefix (N, Comp); | |
d0931270 | 12476 | end if; |
12477 | ||
12478 | else | |
77fd9c7a | 12479 | Comp := Visible_Component (Chars (N)); |
d0931270 | 12480 | |
77fd9c7a | 12481 | if Present (Comp) then |
12482 | Add_Prefix (N, Comp); | |
d0931270 | 12483 | end if; |
12484 | end if; | |
12485 | ||
2072eaa9 | 12486 | return Skip; |
12487 | ||
12488 | -- Otherwise do the replacement and we are done with this node | |
12489 | ||
12490 | else | |
12491 | Replace_Type_Reference (N); | |
12492 | return Skip; | |
12493 | end if; | |
12494 | ||
97c23bbe | 12495 | -- Case of selected component (which is what a qualification looks |
12496 | -- like in the unanalyzed tree, which is what we have. | |
2072eaa9 | 12497 | |
12498 | elsif Nkind (N) = N_Selected_Component then | |
12499 | ||
97c23bbe | 12500 | -- If selector name is not our type, keeping going (we might still |
12501 | -- have an occurrence of the type in the prefix). | |
2072eaa9 | 12502 | |
12503 | if Nkind (Selector_Name (N)) /= N_Identifier | |
12504 | or else Chars (Selector_Name (N)) /= TName | |
12505 | then | |
12506 | return OK; | |
12507 | ||
12508 | -- Selector name is our type, check qualification | |
12509 | ||
12510 | else | |
12511 | -- Loop through scopes and prefixes, doing comparison | |
12512 | ||
77fd9c7a | 12513 | Scop := Current_Scope; |
12514 | Pref := Prefix (N); | |
2072eaa9 | 12515 | loop |
12516 | -- Continue if no more scopes or scope with no name | |
12517 | ||
77fd9c7a | 12518 | if No (Scop) or else Nkind (Scop) not in N_Has_Chars then |
2072eaa9 | 12519 | return OK; |
12520 | end if; | |
12521 | ||
97c23bbe | 12522 | -- Do replace if prefix is an identifier matching the scope |
12523 | -- that we are currently looking at. | |
2072eaa9 | 12524 | |
77fd9c7a | 12525 | if Nkind (Pref) = N_Identifier |
12526 | and then Chars (Pref) = Chars (Scop) | |
2072eaa9 | 12527 | then |
12528 | Replace_Type_Reference (N); | |
12529 | return Skip; | |
12530 | end if; | |
12531 | ||
97c23bbe | 12532 | -- Go check scope above us if prefix is itself of the form |
12533 | -- of a selected component, whose selector matches the scope | |
12534 | -- we are currently looking at. | |
2072eaa9 | 12535 | |
77fd9c7a | 12536 | if Nkind (Pref) = N_Selected_Component |
12537 | and then Nkind (Selector_Name (Pref)) = N_Identifier | |
12538 | and then Chars (Selector_Name (Pref)) = Chars (Scop) | |
2072eaa9 | 12539 | then |
77fd9c7a | 12540 | Scop := Scope (Scop); |
12541 | Pref := Prefix (Pref); | |
2072eaa9 | 12542 | |
12543 | -- For anything else, we don't have a match, so keep on | |
12544 | -- going, there are still some weird cases where we may | |
12545 | -- still have a replacement within the prefix. | |
12546 | ||
12547 | else | |
12548 | return OK; | |
12549 | end if; | |
12550 | end loop; | |
12551 | end if; | |
12552 | ||
ec6f6da5 | 12553 | -- Continue for any other node kind |
2072eaa9 | 12554 | |
12555 | else | |
12556 | return OK; | |
12557 | end if; | |
97c23bbe | 12558 | end Replace_Type_Ref; |
12559 | ||
77fd9c7a | 12560 | procedure Replace_Type_Refs is new Traverse_Proc (Replace_Type_Ref); |
12561 | ||
d0931270 | 12562 | ----------------------- |
12563 | -- Visible_Component -- | |
12564 | ----------------------- | |
12565 | ||
12566 | function Visible_Component (Comp : Name_Id) return Entity_Id is | |
12567 | E : Entity_Id; | |
77fd9c7a | 12568 | |
d0931270 | 12569 | begin |
1a5b3a27 | 12570 | -- Types with nameable components are records and discriminated |
12571 | -- private types. | |
12572 | ||
12573 | if Ekind (T) = E_Record_Type | |
12574 | or else (Is_Private_Type (T) and then Has_Discriminants (T)) | |
12575 | then | |
d0931270 | 12576 | E := First_Entity (T); |
12577 | while Present (E) loop | |
77fd9c7a | 12578 | if Comes_From_Source (E) and then Chars (E) = Comp then |
d0931270 | 12579 | return E; |
12580 | end if; | |
12581 | ||
12582 | Next_Entity (E); | |
12583 | end loop; | |
d0931270 | 12584 | end if; |
1a5b3a27 | 12585 | |
b58a7126 | 12586 | -- Nothing by that name, or the type has no components |
1a5b3a27 | 12587 | |
12588 | return Empty; | |
d0931270 | 12589 | end Visible_Component; |
12590 | ||
77fd9c7a | 12591 | -- Start of processing for Replace_Type_References_Generic |
2072eaa9 | 12592 | |
12593 | begin | |
12594 | Replace_Type_Refs (N); | |
12595 | end Replace_Type_References_Generic; | |
12596 | ||
81bd1c0d | 12597 | -------------------------------- |
12598 | -- Resolve_Aspect_Expressions -- | |
12599 | -------------------------------- | |
12600 | ||
12601 | procedure Resolve_Aspect_Expressions (E : Entity_Id) is | |
12602 | ASN : Node_Id; | |
12603 | A_Id : Aspect_Id; | |
12604 | Expr : Node_Id; | |
12605 | ||
9c20237a | 12606 | function Resolve_Name (N : Node_Id) return Traverse_Result; |
12607 | -- Verify that all identifiers in the expression, with the exception | |
12608 | -- of references to the current entity, denote visible entities. This | |
12609 | -- is done only to detect visibility errors, as the expression will be | |
12610 | -- properly analyzed/expanded during analysis of the predicate function | |
c098acfb | 12611 | -- body. We omit quantified expressions from this test, given that they |
12612 | -- introduce a local identifier that would require proper expansion to | |
12613 | -- handle properly. | |
9c20237a | 12614 | |
25e4fa47 | 12615 | -- In ASIS_Mode we preserve the entity in the source because there is |
12616 | -- no subsequent expansion to decorate the tree. | |
12617 | ||
9c20237a | 12618 | ------------------ |
12619 | -- Resolve_Name -- | |
12620 | ------------------ | |
12621 | ||
12622 | function Resolve_Name (N : Node_Id) return Traverse_Result is | |
12623 | begin | |
12624 | if Nkind (N) = N_Selected_Component then | |
12625 | if Nkind (Prefix (N)) = N_Identifier | |
12626 | and then Chars (Prefix (N)) /= Chars (E) | |
12627 | then | |
f4e18891 | 12628 | Find_Selected_Component (N); |
9c20237a | 12629 | end if; |
02e5d0d0 | 12630 | |
9c20237a | 12631 | return Skip; |
12632 | ||
02e5d0d0 | 12633 | elsif Nkind (N) = N_Identifier and then Chars (N) /= Chars (E) then |
9c20237a | 12634 | Find_Direct_Name (N); |
25e4fa47 | 12635 | |
6b1f5205 | 12636 | if not ASIS_Mode then |
25e4fa47 | 12637 | Set_Entity (N, Empty); |
12638 | end if; | |
c098acfb | 12639 | |
12640 | elsif Nkind (N) = N_Quantified_Expression then | |
12641 | return Skip; | |
9c20237a | 12642 | end if; |
12643 | ||
12644 | return OK; | |
12645 | end Resolve_Name; | |
12646 | ||
12647 | procedure Resolve_Aspect_Expression is new Traverse_Proc (Resolve_Name); | |
12648 | ||
02e5d0d0 | 12649 | -- Start of processing for Resolve_Aspect_Expressions |
12650 | ||
81bd1c0d | 12651 | begin |
12652 | ASN := First_Rep_Item (E); | |
12653 | while Present (ASN) loop | |
12654 | if Nkind (ASN) = N_Aspect_Specification and then Entity (ASN) = E then | |
12655 | A_Id := Get_Aspect_Id (ASN); | |
12656 | Expr := Expression (ASN); | |
12657 | ||
12658 | case A_Id is | |
97c23bbe | 12659 | |
81bd1c0d | 12660 | -- For now we only deal with aspects that do not generate |
12661 | -- subprograms, or that may mention current instances of | |
fdec445e | 12662 | -- types. These will require special handling (???TBD). |
81bd1c0d | 12663 | |
99378362 | 12664 | when Aspect_Invariant |
12665 | | Aspect_Predicate | |
12666 | | Aspect_Predicate_Failure | |
12667 | => | |
81bd1c0d | 12668 | null; |
12669 | ||
99378362 | 12670 | when Aspect_Dynamic_Predicate |
12671 | | Aspect_Static_Predicate | |
12672 | => | |
02e5d0d0 | 12673 | -- Build predicate function specification and preanalyze |
9c20237a | 12674 | -- expression after type replacement. |
12675 | ||
12676 | if No (Predicate_Function (E)) then | |
12677 | declare | |
12678 | FDecl : constant Node_Id := | |
02e5d0d0 | 12679 | Build_Predicate_Function_Declaration (E); |
9c20237a | 12680 | pragma Unreferenced (FDecl); |
12681 | begin | |
12682 | Resolve_Aspect_Expression (Expr); | |
12683 | end; | |
12684 | end if; | |
12685 | ||
81bd1c0d | 12686 | when Pre_Post_Aspects => |
12687 | null; | |
12688 | ||
12689 | when Aspect_Iterable => | |
12690 | if Nkind (Expr) = N_Aggregate then | |
12691 | declare | |
12692 | Assoc : Node_Id; | |
12693 | ||
12694 | begin | |
12695 | Assoc := First (Component_Associations (Expr)); | |
12696 | while Present (Assoc) loop | |
12697 | Find_Direct_Name (Expression (Assoc)); | |
12698 | Next (Assoc); | |
12699 | end loop; | |
12700 | end; | |
12701 | end if; | |
12702 | ||
12703 | when others => | |
12704 | if Present (Expr) then | |
12705 | case Aspect_Argument (A_Id) is | |
99378362 | 12706 | when Expression |
12707 | | Optional_Expression | |
12708 | => | |
81bd1c0d | 12709 | Analyze_And_Resolve (Expression (ASN)); |
12710 | ||
99378362 | 12711 | when Name |
12712 | | Optional_Name | |
12713 | => | |
81bd1c0d | 12714 | if Nkind (Expr) = N_Identifier then |
12715 | Find_Direct_Name (Expr); | |
12716 | ||
12717 | elsif Nkind (Expr) = N_Selected_Component then | |
12718 | Find_Selected_Component (Expr); | |
81bd1c0d | 12719 | end if; |
12720 | end case; | |
12721 | end if; | |
12722 | end case; | |
12723 | end if; | |
12724 | ||
a738763e | 12725 | ASN := Next_Rep_Item (ASN); |
81bd1c0d | 12726 | end loop; |
12727 | end Resolve_Aspect_Expressions; | |
12728 | ||
d6f39728 | 12729 | ------------------------- |
12730 | -- Same_Representation -- | |
12731 | ------------------------- | |
12732 | ||
12733 | function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is | |
12734 | T1 : constant Entity_Id := Underlying_Type (Typ1); | |
12735 | T2 : constant Entity_Id := Underlying_Type (Typ2); | |
12736 | ||
12737 | begin | |
12738 | -- A quick check, if base types are the same, then we definitely have | |
12739 | -- the same representation, because the subtype specific representation | |
12740 | -- attributes (Size and Alignment) do not affect representation from | |
12741 | -- the point of view of this test. | |
12742 | ||
12743 | if Base_Type (T1) = Base_Type (T2) then | |
12744 | return True; | |
12745 | ||
12746 | elsif Is_Private_Type (Base_Type (T2)) | |
12747 | and then Base_Type (T1) = Full_View (Base_Type (T2)) | |
12748 | then | |
12749 | return True; | |
12750 | end if; | |
12751 | ||
12752 | -- Tagged types never have differing representations | |
12753 | ||
12754 | if Is_Tagged_Type (T1) then | |
12755 | return True; | |
12756 | end if; | |
12757 | ||
12758 | -- Representations are definitely different if conventions differ | |
12759 | ||
12760 | if Convention (T1) /= Convention (T2) then | |
12761 | return False; | |
12762 | end if; | |
12763 | ||
ef0772bc | 12764 | -- Representations are different if component alignments or scalar |
12765 | -- storage orders differ. | |
d6f39728 | 12766 | |
12767 | if (Is_Record_Type (T1) or else Is_Array_Type (T1)) | |
726fd56a | 12768 | and then |
d6f39728 | 12769 | (Is_Record_Type (T2) or else Is_Array_Type (T2)) |
ef0772bc | 12770 | and then |
12771 | (Component_Alignment (T1) /= Component_Alignment (T2) | |
f02a9a9a | 12772 | or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2)) |
d6f39728 | 12773 | then |
12774 | return False; | |
12775 | end if; | |
12776 | ||
12777 | -- For arrays, the only real issue is component size. If we know the | |
12778 | -- component size for both arrays, and it is the same, then that's | |
12779 | -- good enough to know we don't have a change of representation. | |
12780 | ||
12781 | if Is_Array_Type (T1) then | |
12782 | if Known_Component_Size (T1) | |
12783 | and then Known_Component_Size (T2) | |
12784 | and then Component_Size (T1) = Component_Size (T2) | |
12785 | then | |
36ac5fbb | 12786 | return True; |
d6f39728 | 12787 | end if; |
12788 | end if; | |
12789 | ||
12790 | -- Types definitely have same representation if neither has non-standard | |
12791 | -- representation since default representations are always consistent. | |
12792 | -- If only one has non-standard representation, and the other does not, | |
12793 | -- then we consider that they do not have the same representation. They | |
12794 | -- might, but there is no way of telling early enough. | |
12795 | ||
12796 | if Has_Non_Standard_Rep (T1) then | |
12797 | if not Has_Non_Standard_Rep (T2) then | |
12798 | return False; | |
12799 | end if; | |
12800 | else | |
12801 | return not Has_Non_Standard_Rep (T2); | |
12802 | end if; | |
12803 | ||
fdd294d1 | 12804 | -- Here the two types both have non-standard representation, and we need |
12805 | -- to determine if they have the same non-standard representation. | |
d6f39728 | 12806 | |
12807 | -- For arrays, we simply need to test if the component sizes are the | |
12808 | -- same. Pragma Pack is reflected in modified component sizes, so this | |
12809 | -- check also deals with pragma Pack. | |
12810 | ||
12811 | if Is_Array_Type (T1) then | |
12812 | return Component_Size (T1) = Component_Size (T2); | |
12813 | ||
12814 | -- Tagged types always have the same representation, because it is not | |
12815 | -- possible to specify different representations for common fields. | |
12816 | ||
12817 | elsif Is_Tagged_Type (T1) then | |
12818 | return True; | |
12819 | ||
12820 | -- Case of record types | |
12821 | ||
12822 | elsif Is_Record_Type (T1) then | |
12823 | ||
12824 | -- Packed status must conform | |
12825 | ||
12826 | if Is_Packed (T1) /= Is_Packed (T2) then | |
12827 | return False; | |
12828 | ||
12829 | -- Otherwise we must check components. Typ2 maybe a constrained | |
12830 | -- subtype with fewer components, so we compare the components | |
12831 | -- of the base types. | |
12832 | ||
12833 | else | |
12834 | Record_Case : declare | |
12835 | CD1, CD2 : Entity_Id; | |
12836 | ||
12837 | function Same_Rep return Boolean; | |
12838 | -- CD1 and CD2 are either components or discriminants. This | |
ef0772bc | 12839 | -- function tests whether they have the same representation. |
d6f39728 | 12840 | |
80d4fec4 | 12841 | -------------- |
12842 | -- Same_Rep -- | |
12843 | -------------- | |
12844 | ||
d6f39728 | 12845 | function Same_Rep return Boolean is |
12846 | begin | |
12847 | if No (Component_Clause (CD1)) then | |
12848 | return No (Component_Clause (CD2)); | |
d6f39728 | 12849 | else |
ef0772bc | 12850 | -- Note: at this point, component clauses have been |
12851 | -- normalized to the default bit order, so that the | |
12852 | -- comparison of Component_Bit_Offsets is meaningful. | |
12853 | ||
d6f39728 | 12854 | return |
12855 | Present (Component_Clause (CD2)) | |
12856 | and then | |
12857 | Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2) | |
12858 | and then | |
12859 | Esize (CD1) = Esize (CD2); | |
12860 | end if; | |
12861 | end Same_Rep; | |
12862 | ||
1e35409d | 12863 | -- Start of processing for Record_Case |
d6f39728 | 12864 | |
12865 | begin | |
12866 | if Has_Discriminants (T1) then | |
d6f39728 | 12867 | |
9dfe12ae | 12868 | -- The number of discriminants may be different if the |
12869 | -- derived type has fewer (constrained by values). The | |
12870 | -- invisible discriminants retain the representation of | |
12871 | -- the original, so the discrepancy does not per se | |
12872 | -- indicate a different representation. | |
12873 | ||
b9e61b2a | 12874 | CD1 := First_Discriminant (T1); |
12875 | CD2 := First_Discriminant (T2); | |
12876 | while Present (CD1) and then Present (CD2) loop | |
d6f39728 | 12877 | if not Same_Rep then |
12878 | return False; | |
12879 | else | |
12880 | Next_Discriminant (CD1); | |
12881 | Next_Discriminant (CD2); | |
12882 | end if; | |
12883 | end loop; | |
12884 | end if; | |
12885 | ||
12886 | CD1 := First_Component (Underlying_Type (Base_Type (T1))); | |
12887 | CD2 := First_Component (Underlying_Type (Base_Type (T2))); | |
d6f39728 | 12888 | while Present (CD1) loop |
12889 | if not Same_Rep then | |
12890 | return False; | |
12891 | else | |
12892 | Next_Component (CD1); | |
12893 | Next_Component (CD2); | |
12894 | end if; | |
12895 | end loop; | |
12896 | ||
12897 | return True; | |
12898 | end Record_Case; | |
12899 | end if; | |
12900 | ||
12901 | -- For enumeration types, we must check each literal to see if the | |
12902 | -- representation is the same. Note that we do not permit enumeration | |
1a34e48c | 12903 | -- representation clauses for Character and Wide_Character, so these |
d6f39728 | 12904 | -- cases were already dealt with. |
12905 | ||
12906 | elsif Is_Enumeration_Type (T1) then | |
d6f39728 | 12907 | Enumeration_Case : declare |
12908 | L1, L2 : Entity_Id; | |
12909 | ||
12910 | begin | |
12911 | L1 := First_Literal (T1); | |
12912 | L2 := First_Literal (T2); | |
d6f39728 | 12913 | while Present (L1) loop |
12914 | if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then | |
12915 | return False; | |
12916 | else | |
12917 | Next_Literal (L1); | |
12918 | Next_Literal (L2); | |
12919 | end if; | |
12920 | end loop; | |
12921 | ||
12922 | return True; | |
d6f39728 | 12923 | end Enumeration_Case; |
12924 | ||
12925 | -- Any other types have the same representation for these purposes | |
12926 | ||
12927 | else | |
12928 | return True; | |
12929 | end if; | |
d6f39728 | 12930 | end Same_Representation; |
12931 | ||
3061ffde | 12932 | -------------------------------- |
12933 | -- Resolve_Iterable_Operation -- | |
12934 | -------------------------------- | |
12935 | ||
12936 | procedure Resolve_Iterable_Operation | |
12937 | (N : Node_Id; | |
12938 | Cursor : Entity_Id; | |
12939 | Typ : Entity_Id; | |
12940 | Nam : Name_Id) | |
12941 | is | |
12942 | Ent : Entity_Id; | |
12943 | F1 : Entity_Id; | |
12944 | F2 : Entity_Id; | |
12945 | ||
12946 | begin | |
12947 | if not Is_Overloaded (N) then | |
12948 | if not Is_Entity_Name (N) | |
12949 | or else Ekind (Entity (N)) /= E_Function | |
12950 | or else Scope (Entity (N)) /= Scope (Typ) | |
12951 | or else No (First_Formal (Entity (N))) | |
12952 | or else Etype (First_Formal (Entity (N))) /= Typ | |
12953 | then | |
12954 | Error_Msg_N ("iterable primitive must be local function name " | |
12955 | & "whose first formal is an iterable type", N); | |
a9f5fea7 | 12956 | return; |
3061ffde | 12957 | end if; |
12958 | ||
12959 | Ent := Entity (N); | |
12960 | F1 := First_Formal (Ent); | |
12961 | if Nam = Name_First then | |
12962 | ||
12963 | -- First (Container) => Cursor | |
12964 | ||
12965 | if Etype (Ent) /= Cursor then | |
12966 | Error_Msg_N ("primitive for First must yield a curosr", N); | |
12967 | end if; | |
12968 | ||
12969 | elsif Nam = Name_Next then | |
12970 | ||
12971 | -- Next (Container, Cursor) => Cursor | |
12972 | ||
12973 | F2 := Next_Formal (F1); | |
12974 | ||
12975 | if Etype (F2) /= Cursor | |
12976 | or else Etype (Ent) /= Cursor | |
12977 | or else Present (Next_Formal (F2)) | |
12978 | then | |
12979 | Error_Msg_N ("no match for Next iterable primitive", N); | |
12980 | end if; | |
12981 | ||
12982 | elsif Nam = Name_Has_Element then | |
12983 | ||
12984 | -- Has_Element (Container, Cursor) => Boolean | |
12985 | ||
12986 | F2 := Next_Formal (F1); | |
12987 | if Etype (F2) /= Cursor | |
12988 | or else Etype (Ent) /= Standard_Boolean | |
12989 | or else Present (Next_Formal (F2)) | |
12990 | then | |
12991 | Error_Msg_N ("no match for Has_Element iterable primitive", N); | |
12992 | end if; | |
12993 | ||
12994 | elsif Nam = Name_Element then | |
b9b03799 | 12995 | F2 := Next_Formal (F1); |
12996 | ||
12997 | if No (F2) | |
12998 | or else Etype (F2) /= Cursor | |
12999 | or else Present (Next_Formal (F2)) | |
13000 | then | |
13001 | Error_Msg_N ("no match for Element iterable primitive", N); | |
13002 | end if; | |
3061ffde | 13003 | null; |
13004 | ||
13005 | else | |
13006 | raise Program_Error; | |
13007 | end if; | |
13008 | ||
13009 | else | |
13010 | -- Overloaded case: find subprogram with proper signature. | |
13011 | -- Caller will report error if no match is found. | |
13012 | ||
13013 | declare | |
13014 | I : Interp_Index; | |
13015 | It : Interp; | |
13016 | ||
13017 | begin | |
13018 | Get_First_Interp (N, I, It); | |
13019 | while Present (It.Typ) loop | |
13020 | if Ekind (It.Nam) = E_Function | |
b9b03799 | 13021 | and then Scope (It.Nam) = Scope (Typ) |
3061ffde | 13022 | and then Etype (First_Formal (It.Nam)) = Typ |
13023 | then | |
13024 | F1 := First_Formal (It.Nam); | |
13025 | ||
13026 | if Nam = Name_First then | |
13027 | if Etype (It.Nam) = Cursor | |
13028 | and then No (Next_Formal (F1)) | |
13029 | then | |
13030 | Set_Entity (N, It.Nam); | |
13031 | exit; | |
13032 | end if; | |
13033 | ||
13034 | elsif Nam = Name_Next then | |
13035 | F2 := Next_Formal (F1); | |
13036 | ||
13037 | if Present (F2) | |
13038 | and then No (Next_Formal (F2)) | |
13039 | and then Etype (F2) = Cursor | |
13040 | and then Etype (It.Nam) = Cursor | |
13041 | then | |
13042 | Set_Entity (N, It.Nam); | |
13043 | exit; | |
13044 | end if; | |
13045 | ||
13046 | elsif Nam = Name_Has_Element then | |
13047 | F2 := Next_Formal (F1); | |
13048 | ||
13049 | if Present (F2) | |
13050 | and then No (Next_Formal (F2)) | |
13051 | and then Etype (F2) = Cursor | |
13052 | and then Etype (It.Nam) = Standard_Boolean | |
13053 | then | |
13054 | Set_Entity (N, It.Nam); | |
13055 | F2 := Next_Formal (F1); | |
13056 | exit; | |
13057 | end if; | |
13058 | ||
13059 | elsif Nam = Name_Element then | |
b9b03799 | 13060 | F2 := Next_Formal (F1); |
13061 | ||
3061ffde | 13062 | if Present (F2) |
13063 | and then No (Next_Formal (F2)) | |
13064 | and then Etype (F2) = Cursor | |
13065 | then | |
13066 | Set_Entity (N, It.Nam); | |
13067 | exit; | |
13068 | end if; | |
13069 | end if; | |
13070 | end if; | |
13071 | ||
13072 | Get_Next_Interp (I, It); | |
13073 | end loop; | |
13074 | end; | |
13075 | end if; | |
13076 | end Resolve_Iterable_Operation; | |
13077 | ||
b77e4501 | 13078 | ---------------- |
13079 | -- Set_Biased -- | |
13080 | ---------------- | |
13081 | ||
13082 | procedure Set_Biased | |
13083 | (E : Entity_Id; | |
13084 | N : Node_Id; | |
13085 | Msg : String; | |
13086 | Biased : Boolean := True) | |
13087 | is | |
13088 | begin | |
13089 | if Biased then | |
13090 | Set_Has_Biased_Representation (E); | |
13091 | ||
13092 | if Warn_On_Biased_Representation then | |
13093 | Error_Msg_NE | |
1e3532e7 | 13094 | ("?B?" & Msg & " forces biased representation for&", N, E); |
b77e4501 | 13095 | end if; |
13096 | end if; | |
13097 | end Set_Biased; | |
13098 | ||
d6f39728 | 13099 | -------------------- |
13100 | -- Set_Enum_Esize -- | |
13101 | -------------------- | |
13102 | ||
13103 | procedure Set_Enum_Esize (T : Entity_Id) is | |
13104 | Lo : Uint; | |
13105 | Hi : Uint; | |
13106 | Sz : Nat; | |
13107 | ||
13108 | begin | |
13109 | Init_Alignment (T); | |
13110 | ||
13111 | -- Find the minimum standard size (8,16,32,64) that fits | |
13112 | ||
13113 | Lo := Enumeration_Rep (Entity (Type_Low_Bound (T))); | |
13114 | Hi := Enumeration_Rep (Entity (Type_High_Bound (T))); | |
13115 | ||
13116 | if Lo < 0 then | |
13117 | if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then | |
f15731c4 | 13118 | Sz := Standard_Character_Size; -- May be > 8 on some targets |
d6f39728 | 13119 | |
13120 | elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then | |
13121 | Sz := 16; | |
13122 | ||
13123 | elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then | |
13124 | Sz := 32; | |
13125 | ||
13126 | else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63); | |
13127 | Sz := 64; | |
13128 | end if; | |
13129 | ||
13130 | else | |
13131 | if Hi < Uint_2**08 then | |
f15731c4 | 13132 | Sz := Standard_Character_Size; -- May be > 8 on some targets |
d6f39728 | 13133 | |
13134 | elsif Hi < Uint_2**16 then | |
13135 | Sz := 16; | |
13136 | ||
13137 | elsif Hi < Uint_2**32 then | |
13138 | Sz := 32; | |
13139 | ||
13140 | else pragma Assert (Hi < Uint_2**63); | |
13141 | Sz := 64; | |
13142 | end if; | |
13143 | end if; | |
13144 | ||
13145 | -- That minimum is the proper size unless we have a foreign convention | |
13146 | -- and the size required is 32 or less, in which case we bump the size | |
13147 | -- up to 32. This is required for C and C++ and seems reasonable for | |
13148 | -- all other foreign conventions. | |
13149 | ||
13150 | if Has_Foreign_Convention (T) | |
13151 | and then Esize (T) < Standard_Integer_Size | |
db1eed69 | 13152 | |
13153 | -- Don't do this if Short_Enums on target | |
13154 | ||
e9185b9d | 13155 | and then not Target_Short_Enums |
d6f39728 | 13156 | then |
13157 | Init_Esize (T, Standard_Integer_Size); | |
d6f39728 | 13158 | else |
13159 | Init_Esize (T, Sz); | |
13160 | end if; | |
d6f39728 | 13161 | end Set_Enum_Esize; |
13162 | ||
2625eb01 | 13163 | ----------------------------- |
13164 | -- Uninstall_Discriminants -- | |
13165 | ----------------------------- | |
13166 | ||
13167 | procedure Uninstall_Discriminants (E : Entity_Id) is | |
13168 | Disc : Entity_Id; | |
13169 | Prev : Entity_Id; | |
13170 | Outer : Entity_Id; | |
13171 | ||
13172 | begin | |
13173 | -- Discriminants have been made visible for type declarations and | |
13174 | -- protected type declarations, not for subtype declarations. | |
13175 | ||
13176 | if Nkind (Parent (E)) /= N_Subtype_Declaration then | |
13177 | Disc := First_Discriminant (E); | |
13178 | while Present (Disc) loop | |
13179 | if Disc /= Current_Entity (Disc) then | |
13180 | Prev := Current_Entity (Disc); | |
13181 | while Present (Prev) | |
13182 | and then Present (Homonym (Prev)) | |
13183 | and then Homonym (Prev) /= Disc | |
13184 | loop | |
13185 | Prev := Homonym (Prev); | |
13186 | end loop; | |
13187 | else | |
13188 | Prev := Empty; | |
13189 | end if; | |
13190 | ||
13191 | Set_Is_Immediately_Visible (Disc, False); | |
13192 | ||
13193 | Outer := Homonym (Disc); | |
13194 | while Present (Outer) and then Scope (Outer) = E loop | |
13195 | Outer := Homonym (Outer); | |
13196 | end loop; | |
13197 | ||
13198 | -- Reset homonym link of other entities, but do not modify link | |
3ff5e35d | 13199 | -- between entities in current scope, so that the back end can |
2625eb01 | 13200 | -- have a proper count of local overloadings. |
13201 | ||
13202 | if No (Prev) then | |
13203 | Set_Name_Entity_Id (Chars (Disc), Outer); | |
13204 | ||
13205 | elsif Scope (Prev) /= Scope (Disc) then | |
13206 | Set_Homonym (Prev, Outer); | |
13207 | end if; | |
13208 | ||
13209 | Next_Discriminant (Disc); | |
13210 | end loop; | |
13211 | end if; | |
13212 | end Uninstall_Discriminants; | |
13213 | ||
13214 | ------------------------------------------- | |
13215 | -- Uninstall_Discriminants_And_Pop_Scope -- | |
13216 | ------------------------------------------- | |
13217 | ||
13218 | procedure Uninstall_Discriminants_And_Pop_Scope (E : Entity_Id) is | |
13219 | begin | |
13220 | if Has_Discriminants (E) then | |
13221 | Uninstall_Discriminants (E); | |
13222 | Pop_Scope; | |
13223 | end if; | |
13224 | end Uninstall_Discriminants_And_Pop_Scope; | |
13225 | ||
83f8f0a6 | 13226 | ------------------------------ |
13227 | -- Validate_Address_Clauses -- | |
13228 | ------------------------------ | |
13229 | ||
13230 | procedure Validate_Address_Clauses is | |
c7a1569a | 13231 | function Offset_Value (Expr : Node_Id) return Uint; |
13232 | -- Given an Address attribute reference, return the value in bits of its | |
13233 | -- offset from the first bit of the underlying entity, or 0 if it is not | |
13234 | -- known at compile time. | |
13235 | ||
13236 | ------------------ | |
13237 | -- Offset_Value -- | |
13238 | ------------------ | |
13239 | ||
13240 | function Offset_Value (Expr : Node_Id) return Uint is | |
13241 | N : Node_Id := Prefix (Expr); | |
13242 | Off : Uint; | |
13243 | Val : Uint := Uint_0; | |
13244 | ||
13245 | begin | |
13246 | -- Climb the prefix chain and compute the cumulative offset | |
13247 | ||
13248 | loop | |
13249 | if Is_Entity_Name (N) then | |
13250 | return Val; | |
13251 | ||
13252 | elsif Nkind (N) = N_Selected_Component then | |
13253 | Off := Component_Bit_Offset (Entity (Selector_Name (N))); | |
13254 | if Off /= No_Uint and then Off >= Uint_0 then | |
13255 | Val := Val + Off; | |
13256 | N := Prefix (N); | |
13257 | else | |
13258 | return Uint_0; | |
13259 | end if; | |
13260 | ||
13261 | elsif Nkind (N) = N_Indexed_Component then | |
13262 | Off := Indexed_Component_Bit_Offset (N); | |
13263 | if Off /= No_Uint then | |
13264 | Val := Val + Off; | |
13265 | N := Prefix (N); | |
13266 | else | |
13267 | return Uint_0; | |
13268 | end if; | |
13269 | ||
13270 | else | |
13271 | return Uint_0; | |
13272 | end if; | |
13273 | end loop; | |
13274 | end Offset_Value; | |
13275 | ||
13276 | -- Start of processing for Validate_Address_Clauses | |
13277 | ||
83f8f0a6 | 13278 | begin |
13279 | for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop | |
13280 | declare | |
13281 | ACCR : Address_Clause_Check_Record | |
13282 | renames Address_Clause_Checks.Table (J); | |
13283 | ||
d6da7448 | 13284 | Expr : Node_Id; |
13285 | ||
83f8f0a6 | 13286 | X_Alignment : Uint; |
13287 | Y_Alignment : Uint; | |
13288 | ||
13289 | X_Size : Uint; | |
13290 | Y_Size : Uint; | |
13291 | ||
c7a1569a | 13292 | X_Offs : Uint; |
13293 | ||
83f8f0a6 | 13294 | begin |
13295 | -- Skip processing of this entry if warning already posted | |
13296 | ||
13297 | if not Address_Warning_Posted (ACCR.N) then | |
d6da7448 | 13298 | Expr := Original_Node (Expression (ACCR.N)); |
83f8f0a6 | 13299 | |
514a5555 | 13300 | -- Get alignments, sizes and offset, if any |
83f8f0a6 | 13301 | |
d6da7448 | 13302 | X_Alignment := Alignment (ACCR.X); |
8650387e | 13303 | X_Size := Esize (ACCR.X); |
514a5555 | 13304 | |
13305 | if Present (ACCR.Y) then | |
13306 | Y_Alignment := Alignment (ACCR.Y); | |
8650387e | 13307 | Y_Size := Esize (ACCR.Y); |
514a5555 | 13308 | end if; |
83f8f0a6 | 13309 | |
c7a1569a | 13310 | if ACCR.Off |
13311 | and then Nkind (Expr) = N_Attribute_Reference | |
13312 | and then Attribute_Name (Expr) = Name_Address | |
13313 | then | |
13314 | X_Offs := Offset_Value (Expr); | |
13315 | else | |
13316 | X_Offs := Uint_0; | |
13317 | end if; | |
13318 | ||
514a5555 | 13319 | -- Check for known value not multiple of alignment |
13320 | ||
13321 | if No (ACCR.Y) then | |
13322 | if not Alignment_Checks_Suppressed (ACCR.X) | |
13323 | and then X_Alignment /= 0 | |
13324 | and then ACCR.A mod X_Alignment /= 0 | |
13325 | then | |
13326 | Error_Msg_NE | |
13327 | ("??specified address for& is inconsistent with " | |
13328 | & "alignment", ACCR.N, ACCR.X); | |
13329 | Error_Msg_N | |
13330 | ("\??program execution may be erroneous (RM 13.3(27))", | |
13331 | ACCR.N); | |
13332 | ||
13333 | Error_Msg_Uint_1 := X_Alignment; | |
13334 | Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X); | |
13335 | end if; | |
13336 | ||
83f8f0a6 | 13337 | -- Check for large object overlaying smaller one |
13338 | ||
514a5555 | 13339 | elsif Y_Size > Uint_0 |
83f8f0a6 | 13340 | and then X_Size > Uint_0 |
c7a1569a | 13341 | and then X_Offs + X_Size > Y_Size |
83f8f0a6 | 13342 | then |
7161e166 | 13343 | Error_Msg_NE ("??& overlays smaller object", ACCR.N, ACCR.X); |
83f8f0a6 | 13344 | Error_Msg_N |
1e3532e7 | 13345 | ("\??program execution may be erroneous", ACCR.N); |
7161e166 | 13346 | |
83f8f0a6 | 13347 | Error_Msg_Uint_1 := X_Size; |
7161e166 | 13348 | Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.X); |
13349 | ||
83f8f0a6 | 13350 | Error_Msg_Uint_1 := Y_Size; |
7161e166 | 13351 | Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.Y); |
83f8f0a6 | 13352 | |
f5cc2579 | 13353 | if Y_Size >= X_Size then |
c7a1569a | 13354 | Error_Msg_Uint_1 := X_Offs; |
f5cc2579 | 13355 | Error_Msg_NE ("\??but offset of & is ^", ACCR.N, ACCR.X); |
c7a1569a | 13356 | end if; |
13357 | ||
d6da7448 | 13358 | -- Check for inadequate alignment, both of the base object |
e556831e | 13359 | -- and of the offset, if any. We only do this check if the |
13360 | -- run-time Alignment_Check is active. No point in warning | |
13361 | -- if this check has been suppressed (or is suppressed by | |
13362 | -- default in the non-strict alignment machine case). | |
83f8f0a6 | 13363 | |
d6da7448 | 13364 | -- Note: we do not check the alignment if we gave a size |
13365 | -- warning, since it would likely be redundant. | |
83f8f0a6 | 13366 | |
514a5555 | 13367 | elsif not Alignment_Checks_Suppressed (ACCR.X) |
e556831e | 13368 | and then Y_Alignment /= Uint_0 |
7161e166 | 13369 | and then |
13370 | (Y_Alignment < X_Alignment | |
13371 | or else | |
13372 | (ACCR.Off | |
13373 | and then Nkind (Expr) = N_Attribute_Reference | |
13374 | and then Attribute_Name (Expr) = Name_Address | |
13375 | and then Has_Compatible_Alignment | |
13376 | (ACCR.X, Prefix (Expr), True) /= | |
13377 | Known_Compatible)) | |
83f8f0a6 | 13378 | then |
13379 | Error_Msg_NE | |
7161e166 | 13380 | ("??specified address for& may be inconsistent with " |
13381 | & "alignment", ACCR.N, ACCR.X); | |
83f8f0a6 | 13382 | Error_Msg_N |
1e3532e7 | 13383 | ("\??program execution may be erroneous (RM 13.3(27))", |
83f8f0a6 | 13384 | ACCR.N); |
7161e166 | 13385 | |
83f8f0a6 | 13386 | Error_Msg_Uint_1 := X_Alignment; |
7161e166 | 13387 | Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X); |
13388 | ||
83f8f0a6 | 13389 | Error_Msg_Uint_1 := Y_Alignment; |
7161e166 | 13390 | Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.Y); |
13391 | ||
d6da7448 | 13392 | if Y_Alignment >= X_Alignment then |
13393 | Error_Msg_N | |
7161e166 | 13394 | ("\??but offset is not multiple of alignment", ACCR.N); |
d6da7448 | 13395 | end if; |
83f8f0a6 | 13396 | end if; |
13397 | end if; | |
13398 | end; | |
13399 | end loop; | |
13400 | end Validate_Address_Clauses; | |
13401 | ||
76a6b7c7 | 13402 | ----------------------------------------- |
13403 | -- Validate_Compile_Time_Warning_Error -- | |
13404 | ----------------------------------------- | |
13405 | ||
13406 | procedure Validate_Compile_Time_Warning_Error (N : Node_Id) is | |
13407 | begin | |
13408 | Compile_Time_Warnings_Errors.Append | |
13409 | (New_Val => CTWE_Entry'(Eloc => Sloc (N), | |
13410 | Scope => Current_Scope, | |
13411 | Prag => N)); | |
13412 | end Validate_Compile_Time_Warning_Error; | |
13413 | ||
13414 | ------------------------------------------ | |
13415 | -- Validate_Compile_Time_Warning_Errors -- | |
13416 | ------------------------------------------ | |
13417 | ||
13418 | procedure Validate_Compile_Time_Warning_Errors is | |
13419 | procedure Set_Scope (S : Entity_Id); | |
13420 | -- Install all enclosing scopes of S along with S itself | |
13421 | ||
13422 | procedure Unset_Scope (S : Entity_Id); | |
13423 | -- Uninstall all enclosing scopes of S along with S itself | |
13424 | ||
13425 | --------------- | |
13426 | -- Set_Scope -- | |
13427 | --------------- | |
13428 | ||
13429 | procedure Set_Scope (S : Entity_Id) is | |
13430 | begin | |
13431 | if S /= Standard_Standard then | |
13432 | Set_Scope (Scope (S)); | |
13433 | end if; | |
13434 | ||
13435 | Push_Scope (S); | |
13436 | end Set_Scope; | |
13437 | ||
13438 | ----------------- | |
13439 | -- Unset_Scope -- | |
13440 | ----------------- | |
13441 | ||
13442 | procedure Unset_Scope (S : Entity_Id) is | |
13443 | begin | |
13444 | if S /= Standard_Standard then | |
13445 | Unset_Scope (Scope (S)); | |
13446 | end if; | |
13447 | ||
13448 | Pop_Scope; | |
13449 | end Unset_Scope; | |
13450 | ||
13451 | -- Start of processing for Validate_Compile_Time_Warning_Errors | |
13452 | ||
13453 | begin | |
13454 | Expander_Mode_Save_And_Set (False); | |
13455 | In_Compile_Time_Warning_Or_Error := True; | |
13456 | ||
13457 | for N in Compile_Time_Warnings_Errors.First .. | |
13458 | Compile_Time_Warnings_Errors.Last | |
13459 | loop | |
13460 | declare | |
13461 | T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N); | |
13462 | ||
13463 | begin | |
13464 | Set_Scope (T.Scope); | |
13465 | Reset_Analyzed_Flags (T.Prag); | |
13466 | Process_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc); | |
13467 | Unset_Scope (T.Scope); | |
13468 | end; | |
13469 | end loop; | |
13470 | ||
13471 | In_Compile_Time_Warning_Or_Error := False; | |
13472 | Expander_Mode_Restore; | |
13473 | end Validate_Compile_Time_Warning_Errors; | |
13474 | ||
7717ea00 | 13475 | --------------------------- |
13476 | -- Validate_Independence -- | |
13477 | --------------------------- | |
13478 | ||
13479 | procedure Validate_Independence is | |
13480 | SU : constant Uint := UI_From_Int (System_Storage_Unit); | |
13481 | N : Node_Id; | |
13482 | E : Entity_Id; | |
13483 | IC : Boolean; | |
13484 | Comp : Entity_Id; | |
13485 | Addr : Node_Id; | |
13486 | P : Node_Id; | |
13487 | ||
13488 | procedure Check_Array_Type (Atyp : Entity_Id); | |
13489 | -- Checks if the array type Atyp has independent components, and | |
13490 | -- if not, outputs an appropriate set of error messages. | |
13491 | ||
13492 | procedure No_Independence; | |
13493 | -- Output message that independence cannot be guaranteed | |
13494 | ||
13495 | function OK_Component (C : Entity_Id) return Boolean; | |
13496 | -- Checks one component to see if it is independently accessible, and | |
13497 | -- if so yields True, otherwise yields False if independent access | |
13498 | -- cannot be guaranteed. This is a conservative routine, it only | |
13499 | -- returns True if it knows for sure, it returns False if it knows | |
13500 | -- there is a problem, or it cannot be sure there is no problem. | |
13501 | ||
13502 | procedure Reason_Bad_Component (C : Entity_Id); | |
13503 | -- Outputs continuation message if a reason can be determined for | |
13504 | -- the component C being bad. | |
13505 | ||
13506 | ---------------------- | |
13507 | -- Check_Array_Type -- | |
13508 | ---------------------- | |
13509 | ||
13510 | procedure Check_Array_Type (Atyp : Entity_Id) is | |
13511 | Ctyp : constant Entity_Id := Component_Type (Atyp); | |
13512 | ||
13513 | begin | |
13514 | -- OK if no alignment clause, no pack, and no component size | |
13515 | ||
13516 | if not Has_Component_Size_Clause (Atyp) | |
13517 | and then not Has_Alignment_Clause (Atyp) | |
13518 | and then not Is_Packed (Atyp) | |
13519 | then | |
13520 | return; | |
13521 | end if; | |
13522 | ||
aa0a69ab | 13523 | -- Case of component size is greater than or equal to 64 and the |
13524 | -- alignment of the array is at least as large as the alignment | |
13525 | -- of the component. We are definitely OK in this situation. | |
13526 | ||
13527 | if Known_Component_Size (Atyp) | |
13528 | and then Component_Size (Atyp) >= 64 | |
13529 | and then Known_Alignment (Atyp) | |
13530 | and then Known_Alignment (Ctyp) | |
13531 | and then Alignment (Atyp) >= Alignment (Ctyp) | |
13532 | then | |
13533 | return; | |
13534 | end if; | |
13535 | ||
7717ea00 | 13536 | -- Check actual component size |
13537 | ||
13538 | if not Known_Component_Size (Atyp) | |
13539 | or else not (Addressable (Component_Size (Atyp)) | |
aa0a69ab | 13540 | and then Component_Size (Atyp) < 64) |
7717ea00 | 13541 | or else Component_Size (Atyp) mod Esize (Ctyp) /= 0 |
13542 | then | |
13543 | No_Independence; | |
13544 | ||
13545 | -- Bad component size, check reason | |
13546 | ||
13547 | if Has_Component_Size_Clause (Atyp) then | |
b9e61b2a | 13548 | P := Get_Attribute_Definition_Clause |
13549 | (Atyp, Attribute_Component_Size); | |
7717ea00 | 13550 | |
13551 | if Present (P) then | |
13552 | Error_Msg_Sloc := Sloc (P); | |
13553 | Error_Msg_N ("\because of Component_Size clause#", N); | |
13554 | return; | |
13555 | end if; | |
13556 | end if; | |
13557 | ||
13558 | if Is_Packed (Atyp) then | |
13559 | P := Get_Rep_Pragma (Atyp, Name_Pack); | |
13560 | ||
13561 | if Present (P) then | |
13562 | Error_Msg_Sloc := Sloc (P); | |
13563 | Error_Msg_N ("\because of pragma Pack#", N); | |
13564 | return; | |
13565 | end if; | |
13566 | end if; | |
13567 | ||
13568 | -- No reason found, just return | |
13569 | ||
13570 | return; | |
13571 | end if; | |
13572 | ||
13573 | -- Array type is OK independence-wise | |
13574 | ||
13575 | return; | |
13576 | end Check_Array_Type; | |
13577 | ||
13578 | --------------------- | |
13579 | -- No_Independence -- | |
13580 | --------------------- | |
13581 | ||
13582 | procedure No_Independence is | |
13583 | begin | |
ddccc924 | 13584 | if Pragma_Name (N) = Name_Independent then |
18393965 | 13585 | Error_Msg_NE ("independence cannot be guaranteed for&", N, E); |
7717ea00 | 13586 | else |
13587 | Error_Msg_NE | |
13588 | ("independent components cannot be guaranteed for&", N, E); | |
13589 | end if; | |
13590 | end No_Independence; | |
13591 | ||
13592 | ------------------ | |
13593 | -- OK_Component -- | |
13594 | ------------------ | |
13595 | ||
13596 | function OK_Component (C : Entity_Id) return Boolean is | |
13597 | Rec : constant Entity_Id := Scope (C); | |
13598 | Ctyp : constant Entity_Id := Etype (C); | |
13599 | ||
13600 | begin | |
13601 | -- OK if no component clause, no Pack, and no alignment clause | |
13602 | ||
13603 | if No (Component_Clause (C)) | |
13604 | and then not Is_Packed (Rec) | |
13605 | and then not Has_Alignment_Clause (Rec) | |
13606 | then | |
13607 | return True; | |
13608 | end if; | |
13609 | ||
13610 | -- Here we look at the actual component layout. A component is | |
13611 | -- addressable if its size is a multiple of the Esize of the | |
13612 | -- component type, and its starting position in the record has | |
13613 | -- appropriate alignment, and the record itself has appropriate | |
13614 | -- alignment to guarantee the component alignment. | |
13615 | ||
13616 | -- Make sure sizes are static, always assume the worst for any | |
13617 | -- cases where we cannot check static values. | |
13618 | ||
13619 | if not (Known_Static_Esize (C) | |
b9e61b2a | 13620 | and then |
13621 | Known_Static_Esize (Ctyp)) | |
7717ea00 | 13622 | then |
13623 | return False; | |
13624 | end if; | |
13625 | ||
13626 | -- Size of component must be addressable or greater than 64 bits | |
13627 | -- and a multiple of bytes. | |
13628 | ||
b9e61b2a | 13629 | if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then |
7717ea00 | 13630 | return False; |
13631 | end if; | |
13632 | ||
13633 | -- Check size is proper multiple | |
13634 | ||
13635 | if Esize (C) mod Esize (Ctyp) /= 0 then | |
13636 | return False; | |
13637 | end if; | |
13638 | ||
13639 | -- Check alignment of component is OK | |
13640 | ||
13641 | if not Known_Component_Bit_Offset (C) | |
13642 | or else Component_Bit_Offset (C) < Uint_0 | |
13643 | or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0 | |
13644 | then | |
13645 | return False; | |
13646 | end if; | |
13647 | ||
13648 | -- Check alignment of record type is OK | |
13649 | ||
13650 | if not Known_Alignment (Rec) | |
13651 | or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0 | |
13652 | then | |
13653 | return False; | |
13654 | end if; | |
13655 | ||
13656 | -- All tests passed, component is addressable | |
13657 | ||
13658 | return True; | |
13659 | end OK_Component; | |
13660 | ||
13661 | -------------------------- | |
13662 | -- Reason_Bad_Component -- | |
13663 | -------------------------- | |
13664 | ||
13665 | procedure Reason_Bad_Component (C : Entity_Id) is | |
13666 | Rec : constant Entity_Id := Scope (C); | |
13667 | Ctyp : constant Entity_Id := Etype (C); | |
13668 | ||
13669 | begin | |
13670 | -- If component clause present assume that's the problem | |
13671 | ||
13672 | if Present (Component_Clause (C)) then | |
13673 | Error_Msg_Sloc := Sloc (Component_Clause (C)); | |
13674 | Error_Msg_N ("\because of Component_Clause#", N); | |
13675 | return; | |
13676 | end if; | |
13677 | ||
13678 | -- If pragma Pack clause present, assume that's the problem | |
13679 | ||
13680 | if Is_Packed (Rec) then | |
13681 | P := Get_Rep_Pragma (Rec, Name_Pack); | |
13682 | ||
13683 | if Present (P) then | |
13684 | Error_Msg_Sloc := Sloc (P); | |
13685 | Error_Msg_N ("\because of pragma Pack#", N); | |
13686 | return; | |
13687 | end if; | |
13688 | end if; | |
13689 | ||
13690 | -- See if record has bad alignment clause | |
13691 | ||
13692 | if Has_Alignment_Clause (Rec) | |
13693 | and then Known_Alignment (Rec) | |
13694 | and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0 | |
13695 | then | |
13696 | P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment); | |
13697 | ||
13698 | if Present (P) then | |
13699 | Error_Msg_Sloc := Sloc (P); | |
13700 | Error_Msg_N ("\because of Alignment clause#", N); | |
13701 | end if; | |
13702 | end if; | |
13703 | ||
13704 | -- Couldn't find a reason, so return without a message | |
13705 | ||
13706 | return; | |
13707 | end Reason_Bad_Component; | |
13708 | ||
13709 | -- Start of processing for Validate_Independence | |
13710 | ||
13711 | begin | |
13712 | for J in Independence_Checks.First .. Independence_Checks.Last loop | |
13713 | N := Independence_Checks.Table (J).N; | |
13714 | E := Independence_Checks.Table (J).E; | |
ddccc924 | 13715 | IC := Pragma_Name (N) = Name_Independent_Components; |
7717ea00 | 13716 | |
13717 | -- Deal with component case | |
13718 | ||
13719 | if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then | |
13720 | if not OK_Component (E) then | |
13721 | No_Independence; | |
13722 | Reason_Bad_Component (E); | |
13723 | goto Continue; | |
13724 | end if; | |
13725 | end if; | |
13726 | ||
13727 | -- Deal with record with Independent_Components | |
13728 | ||
13729 | if IC and then Is_Record_Type (E) then | |
13730 | Comp := First_Component_Or_Discriminant (E); | |
13731 | while Present (Comp) loop | |
13732 | if not OK_Component (Comp) then | |
13733 | No_Independence; | |
13734 | Reason_Bad_Component (Comp); | |
13735 | goto Continue; | |
13736 | end if; | |
13737 | ||
13738 | Next_Component_Or_Discriminant (Comp); | |
13739 | end loop; | |
13740 | end if; | |
13741 | ||
13742 | -- Deal with address clause case | |
13743 | ||
13744 | if Is_Object (E) then | |
13745 | Addr := Address_Clause (E); | |
13746 | ||
13747 | if Present (Addr) then | |
13748 | No_Independence; | |
13749 | Error_Msg_Sloc := Sloc (Addr); | |
13750 | Error_Msg_N ("\because of Address clause#", N); | |
13751 | goto Continue; | |
13752 | end if; | |
13753 | end if; | |
13754 | ||
13755 | -- Deal with independent components for array type | |
13756 | ||
13757 | if IC and then Is_Array_Type (E) then | |
13758 | Check_Array_Type (E); | |
13759 | end if; | |
13760 | ||
13761 | -- Deal with independent components for array object | |
13762 | ||
13763 | if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then | |
13764 | Check_Array_Type (Etype (E)); | |
13765 | end if; | |
13766 | ||
13767 | <<Continue>> null; | |
13768 | end loop; | |
13769 | end Validate_Independence; | |
13770 | ||
b3f8228a | 13771 | ------------------------------ |
13772 | -- Validate_Iterable_Aspect -- | |
13773 | ------------------------------ | |
13774 | ||
13775 | procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is | |
3061ffde | 13776 | Assoc : Node_Id; |
13777 | Expr : Node_Id; | |
b3f8228a | 13778 | |
bde03454 | 13779 | Prim : Node_Id; |
a9f5fea7 | 13780 | Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ); |
b3f8228a | 13781 | |
13782 | First_Id : Entity_Id; | |
13783 | Next_Id : Entity_Id; | |
13784 | Has_Element_Id : Entity_Id; | |
13785 | Element_Id : Entity_Id; | |
13786 | ||
b3f8228a | 13787 | begin |
9698629c | 13788 | -- If previous error aspect is unusable |
a9f5fea7 | 13789 | |
13790 | if Cursor = Any_Type then | |
3061ffde | 13791 | return; |
13792 | end if; | |
b3f8228a | 13793 | |
13794 | First_Id := Empty; | |
13795 | Next_Id := Empty; | |
13796 | Has_Element_Id := Empty; | |
32de816b | 13797 | Element_Id := Empty; |
b3f8228a | 13798 | |
13799 | -- Each expression must resolve to a function with the proper signature | |
13800 | ||
13801 | Assoc := First (Component_Associations (Expression (ASN))); | |
13802 | while Present (Assoc) loop | |
13803 | Expr := Expression (Assoc); | |
13804 | Analyze (Expr); | |
13805 | ||
b3f8228a | 13806 | Prim := First (Choices (Assoc)); |
bde03454 | 13807 | |
f02a9a9a | 13808 | if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then |
b3f8228a | 13809 | Error_Msg_N ("illegal name in association", Prim); |
13810 | ||
13811 | elsif Chars (Prim) = Name_First then | |
3061ffde | 13812 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First); |
b3f8228a | 13813 | First_Id := Entity (Expr); |
b3f8228a | 13814 | |
13815 | elsif Chars (Prim) = Name_Next then | |
3061ffde | 13816 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next); |
b3f8228a | 13817 | Next_Id := Entity (Expr); |
b3f8228a | 13818 | |
13819 | elsif Chars (Prim) = Name_Has_Element then | |
3061ffde | 13820 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element); |
b3f8228a | 13821 | Has_Element_Id := Entity (Expr); |
bde03454 | 13822 | |
b3f8228a | 13823 | elsif Chars (Prim) = Name_Element then |
3061ffde | 13824 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element); |
b3f8228a | 13825 | Element_Id := Entity (Expr); |
b3f8228a | 13826 | |
13827 | else | |
13828 | Error_Msg_N ("invalid name for iterable function", Prim); | |
13829 | end if; | |
13830 | ||
13831 | Next (Assoc); | |
13832 | end loop; | |
13833 | ||
13834 | if No (First_Id) then | |
3061ffde | 13835 | Error_Msg_N ("match for First primitive not found", ASN); |
b3f8228a | 13836 | |
13837 | elsif No (Next_Id) then | |
3061ffde | 13838 | Error_Msg_N ("match for Next primitive not found", ASN); |
b3f8228a | 13839 | |
13840 | elsif No (Has_Element_Id) then | |
3061ffde | 13841 | Error_Msg_N ("match for Has_Element primitive not found", ASN); |
13842 | ||
13843 | elsif No (Element_Id) then | |
13844 | null; -- Optional. | |
b3f8228a | 13845 | end if; |
13846 | end Validate_Iterable_Aspect; | |
13847 | ||
d6f39728 | 13848 | ----------------------------------- |
13849 | -- Validate_Unchecked_Conversion -- | |
13850 | ----------------------------------- | |
13851 | ||
13852 | procedure Validate_Unchecked_Conversion | |
13853 | (N : Node_Id; | |
13854 | Act_Unit : Entity_Id) | |
13855 | is | |
13856 | Source : Entity_Id; | |
13857 | Target : Entity_Id; | |
13858 | Vnode : Node_Id; | |
13859 | ||
13860 | begin | |
13861 | -- Obtain source and target types. Note that we call Ancestor_Subtype | |
13862 | -- here because the processing for generic instantiation always makes | |
13863 | -- subtypes, and we want the original frozen actual types. | |
13864 | ||
13865 | -- If we are dealing with private types, then do the check on their | |
13866 | -- fully declared counterparts if the full declarations have been | |
39a0c1d3 | 13867 | -- encountered (they don't have to be visible, but they must exist). |
d6f39728 | 13868 | |
13869 | Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit))); | |
13870 | ||
13871 | if Is_Private_Type (Source) | |
13872 | and then Present (Underlying_Type (Source)) | |
13873 | then | |
13874 | Source := Underlying_Type (Source); | |
13875 | end if; | |
13876 | ||
13877 | Target := Ancestor_Subtype (Etype (Act_Unit)); | |
13878 | ||
fdd294d1 | 13879 | -- If either type is generic, the instantiation happens within a generic |
95deda50 | 13880 | -- unit, and there is nothing to check. The proper check will happen |
13881 | -- when the enclosing generic is instantiated. | |
d6f39728 | 13882 | |
13883 | if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then | |
13884 | return; | |
13885 | end if; | |
13886 | ||
13887 | if Is_Private_Type (Target) | |
13888 | and then Present (Underlying_Type (Target)) | |
13889 | then | |
13890 | Target := Underlying_Type (Target); | |
13891 | end if; | |
13892 | ||
0924014e | 13893 | -- Source may be unconstrained array, but not target, except in relaxed |
13894 | -- semantics mode. | |
d6f39728 | 13895 | |
0924014e | 13896 | if Is_Array_Type (Target) |
13897 | and then not Is_Constrained (Target) | |
13898 | and then not Relaxed_RM_Semantics | |
13899 | then | |
d6f39728 | 13900 | Error_Msg_N |
13901 | ("unchecked conversion to unconstrained array not allowed", N); | |
13902 | return; | |
13903 | end if; | |
13904 | ||
fbc67f84 | 13905 | -- Warn if conversion between two different convention pointers |
13906 | ||
13907 | if Is_Access_Type (Target) | |
13908 | and then Is_Access_Type (Source) | |
13909 | and then Convention (Target) /= Convention (Source) | |
13910 | and then Warn_On_Unchecked_Conversion | |
13911 | then | |
74c7ae52 | 13912 | -- Give warnings for subprogram pointers only on most targets |
fdd294d1 | 13913 | |
13914 | if Is_Access_Subprogram_Type (Target) | |
13915 | or else Is_Access_Subprogram_Type (Source) | |
fdd294d1 | 13916 | then |
13917 | Error_Msg_N | |
cb97ae5c | 13918 | ("?z?conversion between pointers with different conventions!", |
1e3532e7 | 13919 | N); |
fdd294d1 | 13920 | end if; |
fbc67f84 | 13921 | end if; |
13922 | ||
3062c401 | 13923 | -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a |
13924 | -- warning when compiling GNAT-related sources. | |
13925 | ||
13926 | if Warn_On_Unchecked_Conversion | |
13927 | and then not In_Predefined_Unit (N) | |
13928 | and then RTU_Loaded (Ada_Calendar) | |
f02a9a9a | 13929 | and then (Chars (Source) = Name_Time |
13930 | or else | |
13931 | Chars (Target) = Name_Time) | |
3062c401 | 13932 | then |
13933 | -- If Ada.Calendar is loaded and the name of one of the operands is | |
13934 | -- Time, there is a good chance that this is Ada.Calendar.Time. | |
13935 | ||
13936 | declare | |
f02a9a9a | 13937 | Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time)); |
3062c401 | 13938 | begin |
13939 | pragma Assert (Present (Calendar_Time)); | |
13940 | ||
b9e61b2a | 13941 | if Source = Calendar_Time or else Target = Calendar_Time then |
3062c401 | 13942 | Error_Msg_N |
f02a9a9a | 13943 | ("?z?representation of 'Time values may change between " |
13944 | & "'G'N'A'T versions", N); | |
3062c401 | 13945 | end if; |
13946 | end; | |
13947 | end if; | |
13948 | ||
fdd294d1 | 13949 | -- Make entry in unchecked conversion table for later processing by |
13950 | -- Validate_Unchecked_Conversions, which will check sizes and alignments | |
3ff5e35d | 13951 | -- (using values set by the back end where possible). This is only done |
fdd294d1 | 13952 | -- if the appropriate warning is active. |
d6f39728 | 13953 | |
9dfe12ae | 13954 | if Warn_On_Unchecked_Conversion then |
13955 | Unchecked_Conversions.Append | |
86d32751 | 13956 | (New_Val => UC_Entry'(Eloc => Sloc (N), |
13957 | Source => Source, | |
13958 | Target => Target, | |
13959 | Act_Unit => Act_Unit)); | |
9dfe12ae | 13960 | |
f9906591 | 13961 | -- If both sizes are known statically now, then back-end annotation |
9dfe12ae | 13962 | -- is not required to do a proper check but if either size is not |
13963 | -- known statically, then we need the annotation. | |
13964 | ||
13965 | if Known_Static_RM_Size (Source) | |
1e3532e7 | 13966 | and then |
13967 | Known_Static_RM_Size (Target) | |
9dfe12ae | 13968 | then |
13969 | null; | |
13970 | else | |
13971 | Back_Annotate_Rep_Info := True; | |
13972 | end if; | |
13973 | end if; | |
d6f39728 | 13974 | |
fdd294d1 | 13975 | -- If unchecked conversion to access type, and access type is declared |
95deda50 | 13976 | -- in the same unit as the unchecked conversion, then set the flag |
13977 | -- No_Strict_Aliasing (no strict aliasing is implicit here) | |
28ed91d4 | 13978 | |
13979 | if Is_Access_Type (Target) and then | |
13980 | In_Same_Source_Unit (Target, N) | |
13981 | then | |
13982 | Set_No_Strict_Aliasing (Implementation_Base_Type (Target)); | |
13983 | end if; | |
3d875462 | 13984 | |
95deda50 | 13985 | -- Generate N_Validate_Unchecked_Conversion node for back end in case |
13986 | -- the back end needs to perform special validation checks. | |
3d875462 | 13987 | |
95deda50 | 13988 | -- Shouldn't this be in Exp_Ch13, since the check only gets done if we |
13989 | -- have full expansion and the back end is called ??? | |
3d875462 | 13990 | |
13991 | Vnode := | |
13992 | Make_Validate_Unchecked_Conversion (Sloc (N)); | |
13993 | Set_Source_Type (Vnode, Source); | |
13994 | Set_Target_Type (Vnode, Target); | |
13995 | ||
fdd294d1 | 13996 | -- If the unchecked conversion node is in a list, just insert before it. |
13997 | -- If not we have some strange case, not worth bothering about. | |
3d875462 | 13998 | |
13999 | if Is_List_Member (N) then | |
d6f39728 | 14000 | Insert_After (N, Vnode); |
14001 | end if; | |
14002 | end Validate_Unchecked_Conversion; | |
14003 | ||
14004 | ------------------------------------ | |
14005 | -- Validate_Unchecked_Conversions -- | |
14006 | ------------------------------------ | |
14007 | ||
14008 | procedure Validate_Unchecked_Conversions is | |
14009 | begin | |
14010 | for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop | |
14011 | declare | |
14012 | T : UC_Entry renames Unchecked_Conversions.Table (N); | |
14013 | ||
e13b1635 | 14014 | Act_Unit : constant Entity_Id := T.Act_Unit; |
86d32751 | 14015 | Eloc : constant Source_Ptr := T.Eloc; |
14016 | Source : constant Entity_Id := T.Source; | |
14017 | Target : constant Entity_Id := T.Target; | |
d6f39728 | 14018 | |
44705307 | 14019 | Source_Siz : Uint; |
14020 | Target_Siz : Uint; | |
d6f39728 | 14021 | |
14022 | begin | |
86d32751 | 14023 | -- Skip if function marked as warnings off |
14024 | ||
14025 | if Warnings_Off (Act_Unit) then | |
14026 | goto Continue; | |
14027 | end if; | |
14028 | ||
fdd294d1 | 14029 | -- This validation check, which warns if we have unequal sizes for |
14030 | -- unchecked conversion, and thus potentially implementation | |
d6f39728 | 14031 | -- dependent semantics, is one of the few occasions on which we |
fdd294d1 | 14032 | -- use the official RM size instead of Esize. See description in |
14033 | -- Einfo "Handling of Type'Size Values" for details. | |
d6f39728 | 14034 | |
f15731c4 | 14035 | if Serious_Errors_Detected = 0 |
d6f39728 | 14036 | and then Known_Static_RM_Size (Source) |
14037 | and then Known_Static_RM_Size (Target) | |
f25f4252 | 14038 | |
14039 | -- Don't do the check if warnings off for either type, note the | |
14040 | -- deliberate use of OR here instead of OR ELSE to get the flag | |
14041 | -- Warnings_Off_Used set for both types if appropriate. | |
14042 | ||
14043 | and then not (Has_Warnings_Off (Source) | |
14044 | or | |
14045 | Has_Warnings_Off (Target)) | |
d6f39728 | 14046 | then |
14047 | Source_Siz := RM_Size (Source); | |
14048 | Target_Siz := RM_Size (Target); | |
14049 | ||
14050 | if Source_Siz /= Target_Siz then | |
299480f9 | 14051 | Error_Msg |
cb97ae5c | 14052 | ("?z?types for unchecked conversion have different sizes!", |
299480f9 | 14053 | Eloc); |
d6f39728 | 14054 | |
14055 | if All_Errors_Mode then | |
14056 | Error_Msg_Name_1 := Chars (Source); | |
14057 | Error_Msg_Uint_1 := Source_Siz; | |
14058 | Error_Msg_Name_2 := Chars (Target); | |
14059 | Error_Msg_Uint_2 := Target_Siz; | |
cb97ae5c | 14060 | Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc); |
d6f39728 | 14061 | |
14062 | Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz); | |
14063 | ||
14064 | if Is_Discrete_Type (Source) | |
b9e61b2a | 14065 | and then |
14066 | Is_Discrete_Type (Target) | |
d6f39728 | 14067 | then |
14068 | if Source_Siz > Target_Siz then | |
299480f9 | 14069 | Error_Msg |
cb97ae5c | 14070 | ("\?z?^ high order bits of source will " |
1e3532e7 | 14071 | & "be ignored!", Eloc); |
d6f39728 | 14072 | |
9dfe12ae | 14073 | elsif Is_Unsigned_Type (Source) then |
299480f9 | 14074 | Error_Msg |
cb97ae5c | 14075 | ("\?z?source will be extended with ^ high order " |
1581f2d7 | 14076 | & "zero bits!", Eloc); |
d6f39728 | 14077 | |
14078 | else | |
299480f9 | 14079 | Error_Msg |
cb97ae5c | 14080 | ("\?z?source will be extended with ^ high order " |
1e3532e7 | 14081 | & "sign bits!", Eloc); |
d6f39728 | 14082 | end if; |
14083 | ||
14084 | elsif Source_Siz < Target_Siz then | |
14085 | if Is_Discrete_Type (Target) then | |
14086 | if Bytes_Big_Endian then | |
299480f9 | 14087 | Error_Msg |
cb97ae5c | 14088 | ("\?z?target value will include ^ undefined " |
1e3532e7 | 14089 | & "low order bits!", Eloc); |
d6f39728 | 14090 | else |
299480f9 | 14091 | Error_Msg |
cb97ae5c | 14092 | ("\?z?target value will include ^ undefined " |
1e3532e7 | 14093 | & "high order bits!", Eloc); |
d6f39728 | 14094 | end if; |
14095 | ||
14096 | else | |
299480f9 | 14097 | Error_Msg |
cb97ae5c | 14098 | ("\?z?^ trailing bits of target value will be " |
1e3532e7 | 14099 | & "undefined!", Eloc); |
d6f39728 | 14100 | end if; |
14101 | ||
14102 | else pragma Assert (Source_Siz > Target_Siz); | |
0388e54e | 14103 | if Is_Discrete_Type (Source) then |
14104 | if Bytes_Big_Endian then | |
14105 | Error_Msg | |
14106 | ("\?z?^ low order bits of source will be " | |
14107 | & "ignored!", Eloc); | |
14108 | else | |
14109 | Error_Msg | |
14110 | ("\?z?^ high order bits of source will be " | |
14111 | & "ignored!", Eloc); | |
14112 | end if; | |
14113 | ||
14114 | else | |
14115 | Error_Msg | |
14116 | ("\?z?^ trailing bits of source will be " | |
14117 | & "ignored!", Eloc); | |
14118 | end if; | |
d6f39728 | 14119 | end if; |
14120 | end if; | |
d6f39728 | 14121 | end if; |
14122 | end if; | |
14123 | ||
14124 | -- If both types are access types, we need to check the alignment. | |
14125 | -- If the alignment of both is specified, we can do it here. | |
14126 | ||
f15731c4 | 14127 | if Serious_Errors_Detected = 0 |
2a10e737 | 14128 | and then Is_Access_Type (Source) |
14129 | and then Is_Access_Type (Target) | |
d6f39728 | 14130 | and then Target_Strict_Alignment |
14131 | and then Present (Designated_Type (Source)) | |
14132 | and then Present (Designated_Type (Target)) | |
14133 | then | |
14134 | declare | |
14135 | D_Source : constant Entity_Id := Designated_Type (Source); | |
14136 | D_Target : constant Entity_Id := Designated_Type (Target); | |
14137 | ||
14138 | begin | |
14139 | if Known_Alignment (D_Source) | |
b9e61b2a | 14140 | and then |
14141 | Known_Alignment (D_Target) | |
d6f39728 | 14142 | then |
14143 | declare | |
14144 | Source_Align : constant Uint := Alignment (D_Source); | |
14145 | Target_Align : constant Uint := Alignment (D_Target); | |
14146 | ||
14147 | begin | |
14148 | if Source_Align < Target_Align | |
14149 | and then not Is_Tagged_Type (D_Source) | |
f25f4252 | 14150 | |
14151 | -- Suppress warning if warnings suppressed on either | |
14152 | -- type or either designated type. Note the use of | |
14153 | -- OR here instead of OR ELSE. That is intentional, | |
14154 | -- we would like to set flag Warnings_Off_Used in | |
14155 | -- all types for which warnings are suppressed. | |
14156 | ||
14157 | and then not (Has_Warnings_Off (D_Source) | |
14158 | or | |
14159 | Has_Warnings_Off (D_Target) | |
14160 | or | |
14161 | Has_Warnings_Off (Source) | |
14162 | or | |
14163 | Has_Warnings_Off (Target)) | |
d6f39728 | 14164 | then |
d6f39728 | 14165 | Error_Msg_Uint_1 := Target_Align; |
14166 | Error_Msg_Uint_2 := Source_Align; | |
299480f9 | 14167 | Error_Msg_Node_1 := D_Target; |
d6f39728 | 14168 | Error_Msg_Node_2 := D_Source; |
299480f9 | 14169 | Error_Msg |
cb97ae5c | 14170 | ("?z?alignment of & (^) is stricter than " |
1e3532e7 | 14171 | & "alignment of & (^)!", Eloc); |
f25f4252 | 14172 | Error_Msg |
cb97ae5c | 14173 | ("\?z?resulting access value may have invalid " |
1e3532e7 | 14174 | & "alignment!", Eloc); |
d6f39728 | 14175 | end if; |
14176 | end; | |
14177 | end if; | |
14178 | end; | |
14179 | end if; | |
14180 | end; | |
86d32751 | 14181 | |
14182 | <<Continue>> | |
14183 | null; | |
d6f39728 | 14184 | end loop; |
14185 | end Validate_Unchecked_Conversions; | |
14186 | ||
d6f39728 | 14187 | end Sem_Ch13; |