]>
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 | -- -- | |
e9c75a1a | 9 | -- Copyright (C) 1992-2019, Free Software Foundation, Inc. -- |
d6f39728 | 10 | -- -- |
11 | -- GNAT is free software; you can redistribute it and/or modify it under -- | |
12 | -- terms of the GNU General Public License as published by the Free Soft- -- | |
80df182a | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
d6f39728 | 14 | -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
15 | -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- | |
16 | -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- | |
17 | -- for more details. You should have received a copy of the GNU General -- | |
80df182a | 18 | -- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
19 | -- http://www.gnu.org/licenses for a complete copy of the license. -- | |
d6f39728 | 20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
e78e8c8e | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
d6f39728 | 23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
ae888dbd | 26 | with Aspects; use Aspects; |
d6f39728 | 27 | with Atree; use Atree; |
713c00d6 | 28 | with Checks; use Checks; |
175a6969 | 29 | with Debug; use Debug; |
d6f39728 | 30 | with Einfo; use Einfo; |
d00681a7 | 31 | with Elists; use Elists; |
d6f39728 | 32 | with Errout; use Errout; |
d00681a7 | 33 | with Exp_Disp; use Exp_Disp; |
d6f39728 | 34 | with Exp_Tss; use Exp_Tss; |
35 | with Exp_Util; use Exp_Util; | |
37c6552c | 36 | with Freeze; use Freeze; |
f9e26ff7 | 37 | with Ghost; use Ghost; |
d6f39728 | 38 | with Lib; use Lib; |
83f8f0a6 | 39 | with Lib.Xref; use Lib.Xref; |
15ebb600 | 40 | with Namet; use Namet; |
d6f39728 | 41 | with Nlists; use Nlists; |
42 | with Nmake; use Nmake; | |
43 | with Opt; use Opt; | |
42fb9d35 | 44 | with Par_SCO; use Par_SCO; |
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; |
81083222 | 53 | with Sem_Ch7; use Sem_Ch7; |
d6f39728 | 54 | with Sem_Ch8; use Sem_Ch8; |
85696508 | 55 | with Sem_Dim; use Sem_Dim; |
85377c9b | 56 | with Sem_Disp; use Sem_Disp; |
d6f39728 | 57 | with Sem_Eval; use Sem_Eval; |
51ea9c94 | 58 | with Sem_Prag; use Sem_Prag; |
d6f39728 | 59 | with Sem_Res; use Sem_Res; |
60 | with Sem_Type; use Sem_Type; | |
61 | with Sem_Util; use Sem_Util; | |
44e4341e | 62 | with Sem_Warn; use Sem_Warn; |
738ec25b | 63 | with Sinfo; use Sinfo; |
1e3c4ae6 | 64 | with Sinput; use Sinput; |
9dfe12ae | 65 | with Snames; use Snames; |
d6f39728 | 66 | with Stand; use Stand; |
93735cb8 | 67 | with Targparm; use Targparm; |
d6f39728 | 68 | with Ttypes; use Ttypes; |
69 | with Tbuild; use Tbuild; | |
70 | with Urealp; use Urealp; | |
f42f24d7 | 71 | with Warnsw; use Warnsw; |
d6f39728 | 72 | |
bfa5a9d9 | 73 | with GNAT.Heap_Sort_G; |
d6f39728 | 74 | |
75 | package body Sem_Ch13 is | |
76 | ||
77 | SSU : constant Pos := System_Storage_Unit; | |
78 | -- Convenient short hand for commonly used constant | |
79 | ||
80 | ----------------------- | |
81 | -- Local Subprograms -- | |
82 | ----------------------- | |
83 | ||
d95b8c89 | 84 | procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id); |
2d9fff4f | 85 | -- Helper routine providing the original (pre-AI95-0133) behavior for |
d95b8c89 | 86 | -- Adjust_Record_For_Reverse_Bit_Order. |
87 | ||
1d366b32 | 88 | procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint); |
89 | -- This routine is called after setting one of the sizes of type entity | |
90 | -- Typ to Size. The purpose is to deal with the situation of a derived | |
91 | -- type whose inherited alignment is no longer appropriate for the new | |
92 | -- size value. In this case, we reset the Alignment to unknown. | |
d6f39728 | 93 | |
eb66e842 | 94 | procedure Build_Discrete_Static_Predicate |
d97beb2f | 95 | (Typ : Entity_Id; |
96 | Expr : Node_Id; | |
97 | Nam : Name_Id); | |
d7c2851f | 98 | -- Given a predicated type Typ, where Typ is a discrete static subtype, |
99 | -- whose predicate expression is Expr, tests if Expr is a static predicate, | |
100 | -- and if so, builds the predicate range list. Nam is the name of the one | |
101 | -- argument to the predicate function. Occurrences of the type name in the | |
6fb3c314 | 102 | -- predicate expression have been replaced by identifier references to this |
d7c2851f | 103 | -- name, which is unique, so any identifier with Chars matching Nam must be |
104 | -- a reference to the type. If the predicate is non-static, this procedure | |
105 | -- returns doing nothing. If the predicate is static, then the predicate | |
5c6a5792 | 106 | -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is |
107 | -- rewritten as a canonicalized membership operation. | |
d97beb2f | 108 | |
ee2b7923 | 109 | function Build_Export_Import_Pragma |
110 | (Asp : Node_Id; | |
111 | Id : Entity_Id) return Node_Id; | |
112 | -- Create the corresponding pragma for aspect Export or Import denoted by | |
113 | -- Asp. Id is the related entity subject to the aspect. Return Empty when | |
114 | -- the expression of aspect Asp evaluates to False or is erroneous. | |
115 | ||
9c20237a | 116 | function Build_Predicate_Function_Declaration |
117 | (Typ : Entity_Id) return Node_Id; | |
118 | -- Build the declaration for a predicate function. The declaration is built | |
119 | -- at the end of the declarative part containing the type definition, which | |
120 | -- may be before the freeze point of the type. The predicate expression is | |
aefa1e7d | 121 | -- preanalyzed at this point, to catch visibility errors. |
9c20237a | 122 | |
eb66e842 | 123 | procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id); |
124 | -- If Typ has predicates (indicated by Has_Predicates being set for Typ), | |
125 | -- then either there are pragma Predicate entries on the rep chain for the | |
126 | -- type (note that Predicate aspects are converted to pragma Predicate), or | |
127 | -- there are inherited aspects from a parent type, or ancestor subtypes. | |
9c20237a | 128 | -- This procedure builds body for the Predicate function that tests these |
129 | -- predicates. N is the freeze node for the type. The spec of the function | |
130 | -- is inserted before the freeze node, and the body of the function is | |
131 | -- inserted after the freeze node. If the predicate expression has a least | |
132 | -- one Raise_Expression, then this procedure also builds the M version of | |
133 | -- the predicate function for use in membership tests. | |
eb66e842 | 134 | |
6653b695 | 135 | procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id); |
136 | -- Called if both Storage_Pool and Storage_Size attribute definition | |
137 | -- clauses (SP and SS) are present for entity Ent. Issue error message. | |
138 | ||
d9f6a4ee | 139 | procedure Freeze_Entity_Checks (N : Node_Id); |
140 | -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity | |
141 | -- to generate appropriate semantic checks that are delayed until this | |
142 | -- point (they had to be delayed this long for cases of delayed aspects, | |
143 | -- e.g. analysis of statically predicated subtypes in choices, for which | |
5f067114 | 144 | -- we have to be sure the subtypes in question are frozen before checking). |
d9f6a4ee | 145 | |
d6f39728 | 146 | function Get_Alignment_Value (Expr : Node_Id) return Uint; |
147 | -- Given the expression for an alignment value, returns the corresponding | |
148 | -- Uint value. If the value is inappropriate, then error messages are | |
149 | -- posted as required, and a value of No_Uint is returned. | |
150 | ||
151 | function Is_Operational_Item (N : Node_Id) return Boolean; | |
1e3c4ae6 | 152 | -- A specification for a stream attribute is allowed before the full type |
153 | -- is declared, as explained in AI-00137 and the corrigendum. Attributes | |
154 | -- that do not specify a representation characteristic are operational | |
155 | -- attributes. | |
d6f39728 | 156 | |
3b23aaa0 | 157 | function Is_Predicate_Static |
158 | (Expr : Node_Id; | |
159 | Nam : Name_Id) return Boolean; | |
160 | -- Given predicate expression Expr, tests if Expr is predicate-static in | |
161 | -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type | |
162 | -- name in the predicate expression have been replaced by references to | |
163 | -- an identifier whose Chars field is Nam. This name is unique, so any | |
164 | -- identifier with Chars matching Nam must be a reference to the type. | |
165 | -- Returns True if the expression is predicate-static and False otherwise, | |
166 | -- but is not in the business of setting flags or issuing error messages. | |
167 | -- | |
168 | -- Only scalar types can have static predicates, so False is always | |
169 | -- returned for non-scalar types. | |
170 | -- | |
171 | -- Note: the RM seems to suggest that string types can also have static | |
172 | -- predicates. But that really makes lttle sense as very few useful | |
173 | -- predicates can be constructed for strings. Remember that: | |
174 | -- | |
175 | -- "ABC" < "DEF" | |
176 | -- | |
177 | -- is not a static expression. So even though the clearly faulty RM wording | |
178 | -- allows the following: | |
179 | -- | |
180 | -- subtype S is String with Static_Predicate => S < "DEF" | |
181 | -- | |
182 | -- We can't allow this, otherwise we have predicate-static applying to a | |
183 | -- larger class than static expressions, which was never intended. | |
184 | ||
44e4341e | 185 | procedure New_Stream_Subprogram |
d6f39728 | 186 | (N : Node_Id; |
187 | Ent : Entity_Id; | |
188 | Subp : Entity_Id; | |
9dfe12ae | 189 | Nam : TSS_Name_Type); |
44e4341e | 190 | -- Create a subprogram renaming of a given stream attribute to the |
191 | -- designated subprogram and then in the tagged case, provide this as a | |
d1a2e31b | 192 | -- primitive operation, or in the untagged case make an appropriate TSS |
44e4341e | 193 | -- entry. This is more properly an expansion activity than just semantics, |
d1a2e31b | 194 | -- but the presence of user-defined stream functions for limited types |
195 | -- is a legality check, which is why this takes place here rather than in | |
44e4341e | 196 | -- exp_ch13, where it was previously. Nam indicates the name of the TSS |
197 | -- function to be generated. | |
9dfe12ae | 198 | -- |
f15731c4 | 199 | -- To avoid elaboration anomalies with freeze nodes, for untagged types |
200 | -- we generate both a subprogram declaration and a subprogram renaming | |
201 | -- declaration, so that the attribute specification is handled as a | |
202 | -- renaming_as_body. For tagged types, the specification is one of the | |
203 | -- primitive specs. | |
204 | ||
d10a1b95 | 205 | procedure Register_Address_Clause_Check |
206 | (N : Node_Id; | |
207 | X : Entity_Id; | |
208 | A : Uint; | |
209 | Y : Entity_Id; | |
210 | Off : Boolean); | |
211 | -- Register a check for the address clause N. The rest of the parameters | |
212 | -- are in keeping with the components of Address_Clause_Check_Record below. | |
213 | ||
3061ffde | 214 | procedure Resolve_Iterable_Operation |
215 | (N : Node_Id; | |
216 | Cursor : Entity_Id; | |
217 | Typ : Entity_Id; | |
218 | Nam : Name_Id); | |
219 | -- If the name of a primitive operation for an Iterable aspect is | |
220 | -- overloaded, resolve according to required signature. | |
221 | ||
b77e4501 | 222 | procedure Set_Biased |
223 | (E : Entity_Id; | |
224 | N : Node_Id; | |
225 | Msg : String; | |
226 | Biased : Boolean := True); | |
227 | -- If Biased is True, sets Has_Biased_Representation flag for E, and | |
228 | -- outputs a warning message at node N if Warn_On_Biased_Representation is | |
229 | -- is True. This warning inserts the string Msg to describe the construct | |
230 | -- causing biasing. | |
231 | ||
b4dcd57e | 232 | ----------------------------------------------------------- |
233 | -- Visibility of Discriminants in Aspect Specifications -- | |
234 | ----------------------------------------------------------- | |
235 | ||
236 | -- The discriminants of a type are visible when analyzing the aspect | |
237 | -- specifications of a type declaration or protected type declaration, | |
238 | -- but not when analyzing those of a subtype declaration. The following | |
239 | -- routines enforce this distinction. | |
240 | ||
241 | procedure Push_Type (E : Entity_Id); | |
242 | -- Push scope E and make visible the discriminants of type entity E if E | |
243 | -- has discriminants and is not a subtype. | |
244 | ||
245 | procedure Pop_Type (E : Entity_Id); | |
246 | -- Remove visibility to the discriminants of type entity E and pop the | |
247 | -- scope stack if E has discriminants and is not a subtype. | |
248 | ||
d6f39728 | 249 | ---------------------------------------------- |
250 | -- Table for Validate_Unchecked_Conversions -- | |
251 | ---------------------------------------------- | |
252 | ||
253 | -- The following table collects unchecked conversions for validation. | |
95deda50 | 254 | -- Entries are made by Validate_Unchecked_Conversion and then the call |
255 | -- to Validate_Unchecked_Conversions does the actual error checking and | |
256 | -- posting of warnings. The reason for this delayed processing is to take | |
257 | -- advantage of back-annotations of size and alignment values performed by | |
258 | -- the back end. | |
d6f39728 | 259 | |
95deda50 | 260 | -- Note: the reason we store a Source_Ptr value instead of a Node_Id is |
261 | -- that by the time Validate_Unchecked_Conversions is called, Sprint will | |
262 | -- already have modified all Sloc values if the -gnatD option is set. | |
299480f9 | 263 | |
d6f39728 | 264 | type UC_Entry is record |
86d32751 | 265 | Eloc : Source_Ptr; -- node used for posting warnings |
266 | Source : Entity_Id; -- source type for unchecked conversion | |
267 | Target : Entity_Id; -- target type for unchecked conversion | |
268 | Act_Unit : Entity_Id; -- actual function instantiated | |
d6f39728 | 269 | end record; |
270 | ||
271 | package Unchecked_Conversions is new Table.Table ( | |
272 | Table_Component_Type => UC_Entry, | |
273 | Table_Index_Type => Int, | |
274 | Table_Low_Bound => 1, | |
275 | Table_Initial => 50, | |
276 | Table_Increment => 200, | |
277 | Table_Name => "Unchecked_Conversions"); | |
278 | ||
83f8f0a6 | 279 | ---------------------------------------- |
280 | -- Table for Validate_Address_Clauses -- | |
281 | ---------------------------------------- | |
282 | ||
283 | -- If an address clause has the form | |
284 | ||
285 | -- for X'Address use Expr | |
286 | ||
514a5555 | 287 | -- where Expr has a value known at compile time or is of the form Y'Address |
288 | -- or recursively is a reference to a constant initialized with either of | |
289 | -- these forms, and the value of Expr is not a multiple of X's alignment, | |
290 | -- or if Y has a smaller alignment than X, then that merits a warning about | |
95deda50 | 291 | -- possible bad alignment. The following table collects address clauses of |
292 | -- this kind. We put these in a table so that they can be checked after the | |
293 | -- back end has completed annotation of the alignments of objects, since we | |
294 | -- can catch more cases that way. | |
83f8f0a6 | 295 | |
296 | type Address_Clause_Check_Record is record | |
297 | N : Node_Id; | |
298 | -- The address clause | |
299 | ||
300 | X : Entity_Id; | |
514a5555 | 301 | -- The entity of the object subject to the address clause |
302 | ||
303 | A : Uint; | |
304 | -- The value of the address in the first case | |
83f8f0a6 | 305 | |
306 | Y : Entity_Id; | |
514a5555 | 307 | -- The entity of the object being overlaid in the second case |
d6da7448 | 308 | |
309 | Off : Boolean; | |
514a5555 | 310 | -- Whether the address is offset within Y in the second case |
d10a1b95 | 311 | |
312 | Alignment_Checks_Suppressed : Boolean; | |
313 | -- Whether alignment checks are suppressed by an active scope suppress | |
314 | -- setting. We need to save the value in order to be able to reuse it | |
315 | -- after the back end has been run. | |
83f8f0a6 | 316 | end record; |
317 | ||
318 | package Address_Clause_Checks is new Table.Table ( | |
319 | Table_Component_Type => Address_Clause_Check_Record, | |
320 | Table_Index_Type => Int, | |
321 | Table_Low_Bound => 1, | |
322 | Table_Initial => 20, | |
323 | Table_Increment => 200, | |
324 | Table_Name => "Address_Clause_Checks"); | |
325 | ||
d10a1b95 | 326 | function Alignment_Checks_Suppressed |
327 | (ACCR : Address_Clause_Check_Record) return Boolean; | |
328 | -- Return whether the alignment check generated for the address clause | |
329 | -- is suppressed. | |
330 | ||
331 | --------------------------------- | |
332 | -- Alignment_Checks_Suppressed -- | |
333 | --------------------------------- | |
334 | ||
335 | function Alignment_Checks_Suppressed | |
336 | (ACCR : Address_Clause_Check_Record) return Boolean | |
337 | is | |
338 | begin | |
339 | if Checks_May_Be_Suppressed (ACCR.X) then | |
340 | return Is_Check_Suppressed (ACCR.X, Alignment_Check); | |
341 | else | |
342 | return ACCR.Alignment_Checks_Suppressed; | |
343 | end if; | |
344 | end Alignment_Checks_Suppressed; | |
345 | ||
59ac57b5 | 346 | ----------------------------------------- |
347 | -- Adjust_Record_For_Reverse_Bit_Order -- | |
348 | ----------------------------------------- | |
349 | ||
350 | procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is | |
d95b8c89 | 351 | Max_Machine_Scalar_Size : constant Uint := |
352 | UI_From_Int | |
353 | (Standard_Long_Long_Integer_Size); | |
354 | -- We use this as the maximum machine scalar size | |
59ac57b5 | 355 | |
7748ccb2 | 356 | SSU : constant Uint := UI_From_Int (System_Storage_Unit); |
357 | ||
358 | CC : Node_Id; | |
359 | Comp : Node_Id; | |
d95b8c89 | 360 | Num_CC : Natural; |
6797073f | 361 | |
d95b8c89 | 362 | begin |
2d9fff4f | 363 | -- Processing here used to depend on Ada version: the behavior was |
d95b8c89 | 364 | -- changed by AI95-0133. However this AI is a Binding interpretation, |
2d9fff4f | 365 | -- so we now implement it even in Ada 95 mode. The original behavior |
d95b8c89 | 366 | -- from unamended Ada 95 is still available for compatibility under |
367 | -- debugging switch -gnatd. | |
368 | ||
369 | if Ada_Version < Ada_2005 and then Debug_Flag_Dot_P then | |
370 | Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R); | |
371 | return; | |
372 | end if; | |
373 | ||
374 | -- For Ada 2005, we do machine scalar processing, as fully described In | |
375 | -- AI-133. This involves gathering all components which start at the | |
376 | -- same byte offset and processing them together. Same approach is still | |
377 | -- valid in later versions including Ada 2012. | |
6797073f | 378 | |
7748ccb2 | 379 | -- This first loop through components does two things. First it deals |
380 | -- with the case of components with component clauses whose length is | |
381 | -- greater than the maximum machine scalar size (either accepting them | |
382 | -- or rejecting as needed). Second, it counts the number of components | |
383 | -- with component clauses whose length does not exceed this maximum for | |
384 | -- later processing. | |
6797073f | 385 | |
d95b8c89 | 386 | Num_CC := 0; |
387 | Comp := First_Component_Or_Discriminant (R); | |
388 | while Present (Comp) loop | |
389 | CC := Component_Clause (Comp); | |
6797073f | 390 | |
d95b8c89 | 391 | if Present (CC) then |
392 | declare | |
393 | Fbit : constant Uint := Static_Integer (First_Bit (CC)); | |
394 | Lbit : constant Uint := Static_Integer (Last_Bit (CC)); | |
6797073f | 395 | |
d95b8c89 | 396 | begin |
397 | -- Case of component with last bit >= max machine scalar | |
6797073f | 398 | |
d95b8c89 | 399 | if Lbit >= Max_Machine_Scalar_Size then |
59ac57b5 | 400 | |
7748ccb2 | 401 | -- This is allowed only if first bit is zero, and last bit |
402 | -- + 1 is a multiple of storage unit size. | |
59ac57b5 | 403 | |
d95b8c89 | 404 | if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then |
59ac57b5 | 405 | |
d95b8c89 | 406 | -- This is the case to give a warning if enabled |
59ac57b5 | 407 | |
d95b8c89 | 408 | if Warn_On_Reverse_Bit_Order then |
6797073f | 409 | Error_Msg_N |
7a41db5b | 410 | ("info: multi-byte field specified with " |
d95b8c89 | 411 | & "non-standard Bit_Order?V?", CC); |
31486bc0 | 412 | |
6797073f | 413 | if Bytes_Big_Endian then |
31486bc0 | 414 | Error_Msg_N |
7a41db5b | 415 | ("\bytes are not reversed " |
d95b8c89 | 416 | & "(component is big-endian)?V?", CC); |
31486bc0 | 417 | else |
418 | Error_Msg_N | |
7a41db5b | 419 | ("\bytes are not reversed " |
d95b8c89 | 420 | & "(component is little-endian)?V?", CC); |
31486bc0 | 421 | end if; |
d95b8c89 | 422 | end if; |
59ac57b5 | 423 | |
d95b8c89 | 424 | -- Give error message for RM 13.5.1(10) violation |
425 | ||
426 | else | |
427 | Error_Msg_FE | |
428 | ("machine scalar rules not followed for&", | |
429 | First_Bit (CC), Comp); | |
430 | ||
431 | Error_Msg_Uint_1 := Lbit + 1; | |
432 | Error_Msg_Uint_2 := Max_Machine_Scalar_Size; | |
433 | Error_Msg_F | |
7748ccb2 | 434 | ("\last bit + 1 (^) exceeds maximum machine scalar " |
435 | & "size (^)", First_Bit (CC)); | |
d95b8c89 | 436 | |
437 | if (Lbit + 1) mod SSU /= 0 then | |
438 | Error_Msg_Uint_1 := SSU; | |
439 | Error_Msg_F | |
440 | ("\and is not a multiple of Storage_Unit (^) " | |
7748ccb2 | 441 | & "(RM 13.5.1(10))", First_Bit (CC)); |
59ac57b5 | 442 | |
67278d60 | 443 | else |
d95b8c89 | 444 | Error_Msg_Uint_1 := Fbit; |
445 | Error_Msg_F | |
446 | ("\and first bit (^) is non-zero " | |
7748ccb2 | 447 | & "(RM 13.4.1(10))", First_Bit (CC)); |
6797073f | 448 | end if; |
d95b8c89 | 449 | end if; |
59ac57b5 | 450 | |
7748ccb2 | 451 | -- OK case of machine scalar related component clause. For now, |
452 | -- just count them. | |
59ac57b5 | 453 | |
d95b8c89 | 454 | else |
455 | Num_CC := Num_CC + 1; | |
456 | end if; | |
457 | end; | |
458 | end if; | |
59ac57b5 | 459 | |
d95b8c89 | 460 | Next_Component_Or_Discriminant (Comp); |
461 | end loop; | |
59ac57b5 | 462 | |
7748ccb2 | 463 | -- We need to sort the component clauses on the basis of the Position |
464 | -- values in the clause, so we can group clauses with the same Position | |
465 | -- together to determine the relevant machine scalar size. | |
bfa5a9d9 | 466 | |
d95b8c89 | 467 | Sort_CC : declare |
468 | Comps : array (0 .. Num_CC) of Entity_Id; | |
7748ccb2 | 469 | -- Array to collect component and discriminant entities. The data |
470 | -- starts at index 1, the 0'th entry is for the sort routine. | |
59ac57b5 | 471 | |
d95b8c89 | 472 | function CP_Lt (Op1, Op2 : Natural) return Boolean; |
473 | -- Compare routine for Sort | |
59ac57b5 | 474 | |
d95b8c89 | 475 | procedure CP_Move (From : Natural; To : Natural); |
476 | -- Move routine for Sort | |
59ac57b5 | 477 | |
d95b8c89 | 478 | package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt); |
59ac57b5 | 479 | |
7748ccb2 | 480 | MaxL : Uint; |
481 | -- Maximum last bit value of any component in this set | |
482 | ||
483 | MSS : Uint; | |
484 | -- Corresponding machine scalar size | |
485 | ||
d95b8c89 | 486 | Start : Natural; |
487 | Stop : Natural; | |
488 | -- Start and stop positions in the component list of the set of | |
489 | -- components with the same starting position (that constitute | |
490 | -- components in a single machine scalar). | |
59ac57b5 | 491 | |
d95b8c89 | 492 | ----------- |
493 | -- CP_Lt -- | |
494 | ----------- | |
6797073f | 495 | |
d95b8c89 | 496 | function CP_Lt (Op1, Op2 : Natural) return Boolean is |
497 | begin | |
7748ccb2 | 498 | return |
499 | Position (Component_Clause (Comps (Op1))) < | |
d95b8c89 | 500 | Position (Component_Clause (Comps (Op2))); |
501 | end CP_Lt; | |
59ac57b5 | 502 | |
d95b8c89 | 503 | ------------- |
504 | -- CP_Move -- | |
505 | ------------- | |
59ac57b5 | 506 | |
d95b8c89 | 507 | procedure CP_Move (From : Natural; To : Natural) is |
6797073f | 508 | begin |
d95b8c89 | 509 | Comps (To) := Comps (From); |
510 | end CP_Move; | |
511 | ||
512 | -- Start of processing for Sort_CC | |
513 | ||
514 | begin | |
515 | -- Collect the machine scalar relevant component clauses | |
67278d60 | 516 | |
d95b8c89 | 517 | Num_CC := 0; |
518 | Comp := First_Component_Or_Discriminant (R); | |
519 | while Present (Comp) loop | |
520 | declare | |
521 | CC : constant Node_Id := Component_Clause (Comp); | |
67278d60 | 522 | |
d95b8c89 | 523 | begin |
7748ccb2 | 524 | -- Collect only component clauses whose last bit is less than |
525 | -- machine scalar size. Any component clause whose last bit | |
526 | -- exceeds this value does not take part in machine scalar | |
527 | -- layout considerations. The test for Error_Posted makes sure | |
528 | -- we exclude component clauses for which we already posted an | |
529 | -- error. | |
d95b8c89 | 530 | |
531 | if Present (CC) | |
532 | and then not Error_Posted (Last_Bit (CC)) | |
533 | and then Static_Integer (Last_Bit (CC)) < | |
534 | Max_Machine_Scalar_Size | |
535 | then | |
536 | Num_CC := Num_CC + 1; | |
537 | Comps (Num_CC) := Comp; | |
538 | end if; | |
539 | end; | |
67278d60 | 540 | |
d95b8c89 | 541 | Next_Component_Or_Discriminant (Comp); |
542 | end loop; | |
67278d60 | 543 | |
d95b8c89 | 544 | -- Sort by ascending position number |
545 | ||
546 | Sorting.Sort (Num_CC); | |
547 | ||
7748ccb2 | 548 | -- We now have all the components whose size does not exceed the max |
549 | -- machine scalar value, sorted by starting position. In this loop we | |
550 | -- gather groups of clauses starting at the same position, to process | |
551 | -- them in accordance with AI-133. | |
d95b8c89 | 552 | |
553 | Stop := 0; | |
554 | while Stop < Num_CC loop | |
555 | Start := Stop + 1; | |
556 | Stop := Start; | |
557 | MaxL := | |
558 | Static_Integer | |
559 | (Last_Bit (Component_Clause (Comps (Start)))); | |
560 | while Stop < Num_CC loop | |
561 | if Static_Integer | |
562 | (Position (Component_Clause (Comps (Stop + 1)))) = | |
563 | Static_Integer | |
564 | (Position (Component_Clause (Comps (Stop)))) | |
565 | then | |
566 | Stop := Stop + 1; | |
567 | MaxL := | |
568 | UI_Max | |
569 | (MaxL, | |
570 | Static_Integer | |
571 | (Last_Bit | |
572 | (Component_Clause (Comps (Stop))))); | |
573 | else | |
574 | exit; | |
575 | end if; | |
576 | end loop; | |
67278d60 | 577 | |
7748ccb2 | 578 | -- Now we have a group of component clauses from Start to Stop |
579 | -- whose positions are identical, and MaxL is the maximum last | |
580 | -- bit value of any of these components. | |
d95b8c89 | 581 | |
7748ccb2 | 582 | -- We need to determine the corresponding machine scalar size. |
583 | -- This loop assumes that machine scalar sizes are even, and that | |
584 | -- each possible machine scalar has twice as many bits as the next | |
585 | -- smaller one. | |
d95b8c89 | 586 | |
587 | MSS := Max_Machine_Scalar_Size; | |
588 | while MSS mod 2 = 0 | |
589 | and then (MSS / 2) >= SSU | |
590 | and then (MSS / 2) > MaxL | |
591 | loop | |
592 | MSS := MSS / 2; | |
593 | end loop; | |
67278d60 | 594 | |
7748ccb2 | 595 | -- Here is where we fix up the Component_Bit_Offset value to |
596 | -- account for the reverse bit order. Some examples of what needs | |
597 | -- to be done for the case of a machine scalar size of 8 are: | |
67278d60 | 598 | |
d95b8c89 | 599 | -- First_Bit .. Last_Bit Component_Bit_Offset |
600 | -- old new old new | |
67278d60 | 601 | |
d95b8c89 | 602 | -- 0 .. 0 7 .. 7 0 7 |
603 | -- 0 .. 1 6 .. 7 0 6 | |
604 | -- 0 .. 2 5 .. 7 0 5 | |
605 | -- 0 .. 7 0 .. 7 0 4 | |
b38e4131 | 606 | |
d95b8c89 | 607 | -- 1 .. 1 6 .. 6 1 6 |
608 | -- 1 .. 4 3 .. 6 1 3 | |
609 | -- 4 .. 7 0 .. 3 4 0 | |
67278d60 | 610 | |
7748ccb2 | 611 | -- The rule is that the first bit is obtained by subtracting the |
612 | -- old ending bit from machine scalar size - 1. | |
67278d60 | 613 | |
d95b8c89 | 614 | for C in Start .. Stop loop |
615 | declare | |
616 | Comp : constant Entity_Id := Comps (C); | |
617 | CC : constant Node_Id := Component_Clause (Comp); | |
59ac57b5 | 618 | |
d95b8c89 | 619 | LB : constant Uint := Static_Integer (Last_Bit (CC)); |
620 | NFB : constant Uint := MSS - Uint_1 - LB; | |
621 | NLB : constant Uint := NFB + Esize (Comp) - 1; | |
622 | Pos : constant Uint := Static_Integer (Position (CC)); | |
59ac57b5 | 623 | |
d95b8c89 | 624 | begin |
625 | if Warn_On_Reverse_Bit_Order then | |
626 | Error_Msg_Uint_1 := MSS; | |
627 | Error_Msg_N | |
7748ccb2 | 628 | ("info: reverse bit order in machine scalar of " |
629 | & "length^?V?", First_Bit (CC)); | |
d95b8c89 | 630 | Error_Msg_Uint_1 := NFB; |
631 | Error_Msg_Uint_2 := NLB; | |
632 | ||
633 | if Bytes_Big_Endian then | |
634 | Error_Msg_NE | |
7748ccb2 | 635 | ("\big-endian range for component & is ^ .. ^?V?", |
636 | First_Bit (CC), Comp); | |
6797073f | 637 | else |
d95b8c89 | 638 | Error_Msg_NE |
7748ccb2 | 639 | ("\little-endian range for component & is ^ .. ^?V?", |
640 | First_Bit (CC), Comp); | |
6797073f | 641 | end if; |
d95b8c89 | 642 | end if; |
59ac57b5 | 643 | |
d95b8c89 | 644 | Set_Component_Bit_Offset (Comp, Pos * SSU + NFB); |
ed7f78d7 | 645 | Set_Normalized_Position (Comp, Pos + NFB / SSU); |
d95b8c89 | 646 | Set_Normalized_First_Bit (Comp, NFB mod SSU); |
647 | end; | |
6797073f | 648 | end loop; |
d95b8c89 | 649 | end loop; |
650 | end Sort_CC; | |
651 | end Adjust_Record_For_Reverse_Bit_Order; | |
59ac57b5 | 652 | |
d95b8c89 | 653 | ------------------------------------------------ |
654 | -- Adjust_Record_For_Reverse_Bit_Order_Ada_95 -- | |
655 | ------------------------------------------------ | |
59ac57b5 | 656 | |
d95b8c89 | 657 | procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id) is |
d95b8c89 | 658 | CC : Node_Id; |
7748ccb2 | 659 | Comp : Node_Id; |
59ac57b5 | 660 | |
d95b8c89 | 661 | begin |
662 | -- For Ada 95, we just renumber bits within a storage unit. We do the | |
663 | -- same for Ada 83 mode, since we recognize the Bit_Order attribute in | |
664 | -- Ada 83, and are free to add this extension. | |
59ac57b5 | 665 | |
d95b8c89 | 666 | Comp := First_Component_Or_Discriminant (R); |
667 | while Present (Comp) loop | |
668 | CC := Component_Clause (Comp); | |
59ac57b5 | 669 | |
d95b8c89 | 670 | -- If component clause is present, then deal with the non-default |
671 | -- bit order case for Ada 95 mode. | |
59ac57b5 | 672 | |
d95b8c89 | 673 | -- We only do this processing for the base type, and in fact that |
674 | -- is important, since otherwise if there are record subtypes, we | |
675 | -- could reverse the bits once for each subtype, which is wrong. | |
59ac57b5 | 676 | |
d95b8c89 | 677 | if Present (CC) and then Ekind (R) = E_Record_Type then |
678 | declare | |
679 | CFB : constant Uint := Component_Bit_Offset (Comp); | |
680 | CSZ : constant Uint := Esize (Comp); | |
681 | CLC : constant Node_Id := Component_Clause (Comp); | |
682 | Pos : constant Node_Id := Position (CLC); | |
683 | FB : constant Node_Id := First_Bit (CLC); | |
59ac57b5 | 684 | |
d95b8c89 | 685 | Storage_Unit_Offset : constant Uint := |
686 | CFB / System_Storage_Unit; | |
67278d60 | 687 | |
d95b8c89 | 688 | Start_Bit : constant Uint := |
689 | CFB mod System_Storage_Unit; | |
67278d60 | 690 | |
d95b8c89 | 691 | begin |
692 | -- Cases where field goes over storage unit boundary | |
67278d60 | 693 | |
d95b8c89 | 694 | if Start_Bit + CSZ > System_Storage_Unit then |
67278d60 | 695 | |
d95b8c89 | 696 | -- Allow multi-byte field but generate warning |
67278d60 | 697 | |
d95b8c89 | 698 | if Start_Bit mod System_Storage_Unit = 0 |
699 | and then CSZ mod System_Storage_Unit = 0 | |
700 | then | |
701 | Error_Msg_N | |
7748ccb2 | 702 | ("info: multi-byte field specified with non-standard " |
703 | & "Bit_Order?V?", CLC); | |
59ac57b5 | 704 | |
d95b8c89 | 705 | if Bytes_Big_Endian then |
706 | Error_Msg_N | |
707 | ("\bytes are not reversed " | |
708 | & "(component is big-endian)?V?", CLC); | |
6797073f | 709 | else |
d95b8c89 | 710 | Error_Msg_N |
711 | ("\bytes are not reversed " | |
712 | & "(component is little-endian)?V?", CLC); | |
6797073f | 713 | end if; |
67278d60 | 714 | |
d95b8c89 | 715 | -- Do not allow non-contiguous field |
6797073f | 716 | |
d95b8c89 | 717 | else |
718 | Error_Msg_N | |
7748ccb2 | 719 | ("attempt to specify non-contiguous field not " |
720 | & "permitted", CLC); | |
d95b8c89 | 721 | Error_Msg_N |
7748ccb2 | 722 | ("\caused by non-standard Bit_Order specified in " |
723 | & "legacy Ada 95 mode", CLC); | |
d95b8c89 | 724 | end if; |
6797073f | 725 | |
d95b8c89 | 726 | -- Case where field fits in one storage unit |
727 | ||
728 | else | |
729 | -- Give warning if suspicious component clause | |
730 | ||
731 | if Intval (FB) >= System_Storage_Unit | |
732 | and then Warn_On_Reverse_Bit_Order | |
733 | then | |
734 | Error_Msg_N | |
7748ccb2 | 735 | ("info: Bit_Order clause does not affect byte " |
736 | & "ordering?V?", Pos); | |
d95b8c89 | 737 | Error_Msg_Uint_1 := |
738 | Intval (Pos) + Intval (FB) / | |
739 | System_Storage_Unit; | |
740 | Error_Msg_N | |
7748ccb2 | 741 | ("info: position normalized to ^ before bit order " |
742 | & "interpreted?V?", Pos); | |
d95b8c89 | 743 | end if; |
67278d60 | 744 | |
6797073f | 745 | -- Here is where we fix up the Component_Bit_Offset value |
746 | -- to account for the reverse bit order. Some examples of | |
d95b8c89 | 747 | -- what needs to be done are: |
67278d60 | 748 | |
6797073f | 749 | -- First_Bit .. Last_Bit Component_Bit_Offset |
750 | -- old new old new | |
67278d60 | 751 | |
6797073f | 752 | -- 0 .. 0 7 .. 7 0 7 |
753 | -- 0 .. 1 6 .. 7 0 6 | |
754 | -- 0 .. 2 5 .. 7 0 5 | |
755 | -- 0 .. 7 0 .. 7 0 4 | |
67278d60 | 756 | |
6797073f | 757 | -- 1 .. 1 6 .. 6 1 6 |
758 | -- 1 .. 4 3 .. 6 1 3 | |
759 | -- 4 .. 7 0 .. 3 4 0 | |
67278d60 | 760 | |
d95b8c89 | 761 | -- The rule is that the first bit is is obtained by |
762 | -- subtracting the old ending bit from storage_unit - 1. | |
67278d60 | 763 | |
7748ccb2 | 764 | Set_Component_Bit_Offset (Comp, |
765 | (Storage_Unit_Offset * System_Storage_Unit) + | |
766 | (System_Storage_Unit - 1) - | |
767 | (Start_Bit + CSZ - 1)); | |
b9e61b2a | 768 | |
ed7f78d7 | 769 | Set_Normalized_Position (Comp, |
770 | Component_Bit_Offset (Comp) / System_Storage_Unit); | |
771 | ||
7748ccb2 | 772 | Set_Normalized_First_Bit (Comp, |
773 | Component_Bit_Offset (Comp) mod System_Storage_Unit); | |
d95b8c89 | 774 | end if; |
775 | end; | |
776 | end if; | |
67278d60 | 777 | |
d95b8c89 | 778 | Next_Component_Or_Discriminant (Comp); |
779 | end loop; | |
780 | end Adjust_Record_For_Reverse_Bit_Order_Ada_95; | |
59ac57b5 | 781 | |
1d366b32 | 782 | ------------------------------------- |
783 | -- Alignment_Check_For_Size_Change -- | |
784 | ------------------------------------- | |
d6f39728 | 785 | |
1d366b32 | 786 | procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is |
d6f39728 | 787 | begin |
788 | -- If the alignment is known, and not set by a rep clause, and is | |
789 | -- inconsistent with the size being set, then reset it to unknown, | |
790 | -- we assume in this case that the size overrides the inherited | |
791 | -- alignment, and that the alignment must be recomputed. | |
792 | ||
793 | if Known_Alignment (Typ) | |
794 | and then not Has_Alignment_Clause (Typ) | |
1d366b32 | 795 | and then Size mod (Alignment (Typ) * SSU) /= 0 |
d6f39728 | 796 | then |
797 | Init_Alignment (Typ); | |
798 | end if; | |
1d366b32 | 799 | end Alignment_Check_For_Size_Change; |
d6f39728 | 800 | |
06ef5f86 | 801 | ------------------------------------- |
802 | -- Analyze_Aspects_At_Freeze_Point -- | |
803 | ------------------------------------- | |
804 | ||
805 | procedure Analyze_Aspects_At_Freeze_Point (E : Entity_Id) is | |
06ef5f86 | 806 | procedure Analyze_Aspect_Default_Value (ASN : Node_Id); |
807 | -- This routine analyzes an Aspect_Default_[Component_]Value denoted by | |
808 | -- the aspect specification node ASN. | |
809 | ||
37c6e44c | 810 | procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id); |
811 | -- As discussed in the spec of Aspects (see Aspect_Delay declaration), | |
812 | -- a derived type can inherit aspects from its parent which have been | |
813 | -- specified at the time of the derivation using an aspect, as in: | |
814 | -- | |
815 | -- type A is range 1 .. 10 | |
816 | -- with Size => Not_Defined_Yet; | |
817 | -- .. | |
818 | -- type B is new A; | |
819 | -- .. | |
820 | -- Not_Defined_Yet : constant := 64; | |
821 | -- | |
822 | -- In this example, the Size of A is considered to be specified prior | |
823 | -- to the derivation, and thus inherited, even though the value is not | |
824 | -- known at the time of derivation. To deal with this, we use two entity | |
825 | -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A | |
826 | -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in | |
827 | -- the derived type (B here). If this flag is set when the derived type | |
828 | -- is frozen, then this procedure is called to ensure proper inheritance | |
b21edad9 | 829 | -- of all delayed aspects from the parent type. The derived type is E, |
37c6e44c | 830 | -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first |
831 | -- aspect specification node in the Rep_Item chain for the parent type. | |
832 | ||
06ef5f86 | 833 | procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id); |
834 | -- Given an aspect specification node ASN whose expression is an | |
835 | -- optional Boolean, this routines creates the corresponding pragma | |
836 | -- at the freezing point. | |
837 | ||
838 | ---------------------------------- | |
839 | -- Analyze_Aspect_Default_Value -- | |
840 | ---------------------------------- | |
841 | ||
842 | procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is | |
ee2b7923 | 843 | A_Id : constant Aspect_Id := Get_Aspect_Id (ASN); |
06ef5f86 | 844 | Ent : constant Entity_Id := Entity (ASN); |
845 | Expr : constant Node_Id := Expression (ASN); | |
846 | Id : constant Node_Id := Identifier (ASN); | |
847 | ||
848 | begin | |
849 | Error_Msg_Name_1 := Chars (Id); | |
850 | ||
851 | if not Is_Type (Ent) then | |
852 | Error_Msg_N ("aspect% can only apply to a type", Id); | |
853 | return; | |
854 | ||
855 | elsif not Is_First_Subtype (Ent) then | |
856 | Error_Msg_N ("aspect% cannot apply to subtype", Id); | |
857 | return; | |
858 | ||
859 | elsif A_Id = Aspect_Default_Value | |
860 | and then not Is_Scalar_Type (Ent) | |
861 | then | |
862 | Error_Msg_N ("aspect% can only be applied to scalar type", Id); | |
863 | return; | |
864 | ||
865 | elsif A_Id = Aspect_Default_Component_Value then | |
866 | if not Is_Array_Type (Ent) then | |
867 | Error_Msg_N ("aspect% can only be applied to array type", Id); | |
868 | return; | |
869 | ||
870 | elsif not Is_Scalar_Type (Component_Type (Ent)) then | |
871 | Error_Msg_N ("aspect% requires scalar components", Id); | |
872 | return; | |
873 | end if; | |
874 | end if; | |
875 | ||
876 | Set_Has_Default_Aspect (Base_Type (Ent)); | |
877 | ||
878 | if Is_Scalar_Type (Ent) then | |
9f36e3fb | 879 | Set_Default_Aspect_Value (Base_Type (Ent), Expr); |
06ef5f86 | 880 | else |
f3d70f08 | 881 | Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr); |
06ef5f86 | 882 | end if; |
883 | end Analyze_Aspect_Default_Value; | |
884 | ||
37c6e44c | 885 | --------------------------------- |
886 | -- Inherit_Delayed_Rep_Aspects -- | |
887 | --------------------------------- | |
888 | ||
889 | procedure Inherit_Delayed_Rep_Aspects (ASN : Node_Id) is | |
ee2b7923 | 890 | A_Id : constant Aspect_Id := Get_Aspect_Id (ASN); |
891 | P : constant Entity_Id := Entity (ASN); | |
37c6e44c | 892 | -- Entithy for parent type |
893 | ||
894 | N : Node_Id; | |
895 | -- Item from Rep_Item chain | |
896 | ||
897 | A : Aspect_Id; | |
898 | ||
899 | begin | |
900 | -- Loop through delayed aspects for the parent type | |
901 | ||
902 | N := ASN; | |
903 | while Present (N) loop | |
904 | if Nkind (N) = N_Aspect_Specification then | |
905 | exit when Entity (N) /= P; | |
906 | ||
907 | if Is_Delayed_Aspect (N) then | |
908 | A := Get_Aspect_Id (Chars (Identifier (N))); | |
909 | ||
910 | -- Process delayed rep aspect. For Boolean attributes it is | |
911 | -- not possible to cancel an attribute once set (the attempt | |
912 | -- to use an aspect with xxx => False is an error) for a | |
913 | -- derived type. So for those cases, we do not have to check | |
914 | -- if a clause has been given for the derived type, since it | |
915 | -- is harmless to set it again if it is already set. | |
916 | ||
917 | case A is | |
918 | ||
919 | -- Alignment | |
920 | ||
921 | when Aspect_Alignment => | |
922 | if not Has_Alignment_Clause (E) then | |
923 | Set_Alignment (E, Alignment (P)); | |
924 | end if; | |
925 | ||
926 | -- Atomic | |
927 | ||
928 | when Aspect_Atomic => | |
929 | if Is_Atomic (P) then | |
930 | Set_Is_Atomic (E); | |
931 | end if; | |
932 | ||
933 | -- Atomic_Components | |
934 | ||
935 | when Aspect_Atomic_Components => | |
936 | if Has_Atomic_Components (P) then | |
937 | Set_Has_Atomic_Components (Base_Type (E)); | |
938 | end if; | |
939 | ||
940 | -- Bit_Order | |
941 | ||
942 | when Aspect_Bit_Order => | |
943 | if Is_Record_Type (E) | |
944 | and then No (Get_Attribute_Definition_Clause | |
945 | (E, Attribute_Bit_Order)) | |
946 | and then Reverse_Bit_Order (P) | |
947 | then | |
948 | Set_Reverse_Bit_Order (Base_Type (E)); | |
949 | end if; | |
950 | ||
951 | -- Component_Size | |
952 | ||
953 | when Aspect_Component_Size => | |
954 | if Is_Array_Type (E) | |
955 | and then not Has_Component_Size_Clause (E) | |
956 | then | |
957 | Set_Component_Size | |
958 | (Base_Type (E), Component_Size (P)); | |
959 | end if; | |
960 | ||
961 | -- Machine_Radix | |
962 | ||
963 | when Aspect_Machine_Radix => | |
964 | if Is_Decimal_Fixed_Point_Type (E) | |
965 | and then not Has_Machine_Radix_Clause (E) | |
966 | then | |
967 | Set_Machine_Radix_10 (E, Machine_Radix_10 (P)); | |
968 | end if; | |
969 | ||
970 | -- Object_Size (also Size which also sets Object_Size) | |
971 | ||
99378362 | 972 | when Aspect_Object_Size |
973 | | Aspect_Size | |
974 | => | |
37c6e44c | 975 | if not Has_Size_Clause (E) |
976 | and then | |
977 | No (Get_Attribute_Definition_Clause | |
978 | (E, Attribute_Object_Size)) | |
979 | then | |
980 | Set_Esize (E, Esize (P)); | |
981 | end if; | |
982 | ||
983 | -- Pack | |
984 | ||
985 | when Aspect_Pack => | |
986 | if not Is_Packed (E) then | |
987 | Set_Is_Packed (Base_Type (E)); | |
988 | ||
989 | if Is_Bit_Packed_Array (P) then | |
990 | Set_Is_Bit_Packed_Array (Base_Type (E)); | |
a88a5773 | 991 | Set_Packed_Array_Impl_Type |
992 | (E, Packed_Array_Impl_Type (P)); | |
37c6e44c | 993 | end if; |
994 | end if; | |
995 | ||
996 | -- Scalar_Storage_Order | |
997 | ||
998 | when Aspect_Scalar_Storage_Order => | |
999 | if (Is_Record_Type (E) or else Is_Array_Type (E)) | |
1000 | and then No (Get_Attribute_Definition_Clause | |
e163cac8 | 1001 | (E, Attribute_Scalar_Storage_Order)) |
37c6e44c | 1002 | and then Reverse_Storage_Order (P) |
1003 | then | |
1004 | Set_Reverse_Storage_Order (Base_Type (E)); | |
b64082f2 | 1005 | |
1006 | -- Clear default SSO indications, since the aspect | |
1007 | -- overrides the default. | |
1008 | ||
1009 | Set_SSO_Set_Low_By_Default (Base_Type (E), False); | |
1010 | Set_SSO_Set_High_By_Default (Base_Type (E), False); | |
37c6e44c | 1011 | end if; |
1012 | ||
1013 | -- Small | |
1014 | ||
1015 | when Aspect_Small => | |
1016 | if Is_Fixed_Point_Type (E) | |
1017 | and then not Has_Small_Clause (E) | |
1018 | then | |
1019 | Set_Small_Value (E, Small_Value (P)); | |
1020 | end if; | |
1021 | ||
1022 | -- Storage_Size | |
1023 | ||
1024 | when Aspect_Storage_Size => | |
1025 | if (Is_Access_Type (E) or else Is_Task_Type (E)) | |
1026 | and then not Has_Storage_Size_Clause (E) | |
1027 | then | |
1028 | Set_Storage_Size_Variable | |
1029 | (Base_Type (E), Storage_Size_Variable (P)); | |
1030 | end if; | |
1031 | ||
1032 | -- Value_Size | |
1033 | ||
1034 | when Aspect_Value_Size => | |
1035 | ||
1036 | -- Value_Size is never inherited, it is either set by | |
1037 | -- default, or it is explicitly set for the derived | |
1038 | -- type. So nothing to do here. | |
1039 | ||
1040 | null; | |
1041 | ||
1042 | -- Volatile | |
1043 | ||
1044 | when Aspect_Volatile => | |
1045 | if Is_Volatile (P) then | |
1046 | Set_Is_Volatile (E); | |
1047 | end if; | |
1048 | ||
2fe893b9 | 1049 | -- Volatile_Full_Access |
1050 | ||
1051 | when Aspect_Volatile_Full_Access => | |
4bf2acc9 | 1052 | if Is_Volatile_Full_Access (P) then |
1053 | Set_Is_Volatile_Full_Access (E); | |
2fe893b9 | 1054 | end if; |
1055 | ||
37c6e44c | 1056 | -- Volatile_Components |
1057 | ||
1058 | when Aspect_Volatile_Components => | |
1059 | if Has_Volatile_Components (P) then | |
1060 | Set_Has_Volatile_Components (Base_Type (E)); | |
1061 | end if; | |
1062 | ||
1063 | -- That should be all the Rep Aspects | |
1064 | ||
1065 | when others => | |
1066 | pragma Assert (Aspect_Delay (A_Id) /= Rep_Aspect); | |
1067 | null; | |
37c6e44c | 1068 | end case; |
1069 | end if; | |
1070 | end if; | |
1071 | ||
1072 | N := Next_Rep_Item (N); | |
1073 | end loop; | |
1074 | end Inherit_Delayed_Rep_Aspects; | |
1075 | ||
06ef5f86 | 1076 | ------------------------------------- |
1077 | -- Make_Pragma_From_Boolean_Aspect -- | |
1078 | ------------------------------------- | |
1079 | ||
1080 | procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is | |
1081 | Ident : constant Node_Id := Identifier (ASN); | |
1082 | A_Name : constant Name_Id := Chars (Ident); | |
1083 | A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name); | |
1084 | Ent : constant Entity_Id := Entity (ASN); | |
1085 | Expr : constant Node_Id := Expression (ASN); | |
1086 | Loc : constant Source_Ptr := Sloc (ASN); | |
1087 | ||
06ef5f86 | 1088 | procedure Check_False_Aspect_For_Derived_Type; |
1089 | -- This procedure checks for the case of a false aspect for a derived | |
1090 | -- type, which improperly tries to cancel an aspect inherited from | |
1091 | -- the parent. | |
1092 | ||
1093 | ----------------------------------------- | |
1094 | -- Check_False_Aspect_For_Derived_Type -- | |
1095 | ----------------------------------------- | |
1096 | ||
1097 | procedure Check_False_Aspect_For_Derived_Type is | |
1098 | Par : Node_Id; | |
1099 | ||
1100 | begin | |
1101 | -- We are only checking derived types | |
1102 | ||
1103 | if not Is_Derived_Type (E) then | |
1104 | return; | |
1105 | end if; | |
1106 | ||
1107 | Par := Nearest_Ancestor (E); | |
1108 | ||
1109 | case A_Id is | |
99378362 | 1110 | when Aspect_Atomic |
1111 | | Aspect_Shared | |
1112 | => | |
06ef5f86 | 1113 | if not Is_Atomic (Par) then |
1114 | return; | |
1115 | end if; | |
1116 | ||
1117 | when Aspect_Atomic_Components => | |
1118 | if not Has_Atomic_Components (Par) then | |
1119 | return; | |
1120 | end if; | |
1121 | ||
1122 | when Aspect_Discard_Names => | |
1123 | if not Discard_Names (Par) then | |
1124 | return; | |
1125 | end if; | |
1126 | ||
1127 | when Aspect_Pack => | |
1128 | if not Is_Packed (Par) then | |
1129 | return; | |
1130 | end if; | |
1131 | ||
1132 | when Aspect_Unchecked_Union => | |
1133 | if not Is_Unchecked_Union (Par) then | |
1134 | return; | |
1135 | end if; | |
1136 | ||
1137 | when Aspect_Volatile => | |
1138 | if not Is_Volatile (Par) then | |
1139 | return; | |
1140 | end if; | |
1141 | ||
1142 | when Aspect_Volatile_Components => | |
1143 | if not Has_Volatile_Components (Par) then | |
1144 | return; | |
1145 | end if; | |
1146 | ||
2fe893b9 | 1147 | when Aspect_Volatile_Full_Access => |
4bf2acc9 | 1148 | if not Is_Volatile_Full_Access (Par) then |
2fe893b9 | 1149 | return; |
1150 | end if; | |
1151 | ||
06ef5f86 | 1152 | when others => |
1153 | return; | |
1154 | end case; | |
1155 | ||
1156 | -- Fall through means we are canceling an inherited aspect | |
1157 | ||
1158 | Error_Msg_Name_1 := A_Name; | |
37c6e44c | 1159 | Error_Msg_NE |
1160 | ("derived type& inherits aspect%, cannot cancel", Expr, E); | |
06ef5f86 | 1161 | end Check_False_Aspect_For_Derived_Type; |
1162 | ||
ee2b7923 | 1163 | -- Local variables |
1164 | ||
1165 | Prag : Node_Id; | |
1166 | ||
06ef5f86 | 1167 | -- Start of processing for Make_Pragma_From_Boolean_Aspect |
1168 | ||
1169 | begin | |
37c6e44c | 1170 | -- Note that we know Expr is present, because for a missing Expr |
1171 | -- argument, we knew it was True and did not need to delay the | |
1172 | -- evaluation to the freeze point. | |
1173 | ||
06ef5f86 | 1174 | if Is_False (Static_Boolean (Expr)) then |
1175 | Check_False_Aspect_For_Derived_Type; | |
1176 | ||
1177 | else | |
1178 | Prag := | |
1179 | Make_Pragma (Loc, | |
ee2b7923 | 1180 | Pragma_Identifier => |
1181 | Make_Identifier (Sloc (Ident), Chars (Ident)), | |
06ef5f86 | 1182 | Pragma_Argument_Associations => New_List ( |
57cd943b | 1183 | Make_Pragma_Argument_Association (Sloc (Ident), |
ee2b7923 | 1184 | Expression => New_Occurrence_Of (Ent, Sloc (Ident))))); |
06ef5f86 | 1185 | |
1186 | Set_From_Aspect_Specification (Prag, True); | |
1187 | Set_Corresponding_Aspect (Prag, ASN); | |
1188 | Set_Aspect_Rep_Item (ASN, Prag); | |
1189 | Set_Is_Delayed_Aspect (Prag); | |
1190 | Set_Parent (Prag, ASN); | |
1191 | end if; | |
06ef5f86 | 1192 | end Make_Pragma_From_Boolean_Aspect; |
1193 | ||
ee2b7923 | 1194 | -- Local variables |
1195 | ||
1196 | A_Id : Aspect_Id; | |
1197 | ASN : Node_Id; | |
1198 | Ritem : Node_Id; | |
1199 | ||
06ef5f86 | 1200 | -- Start of processing for Analyze_Aspects_At_Freeze_Point |
1201 | ||
1202 | begin | |
5e67c1f8 | 1203 | -- Must be visible in current scope, but if this is a type from a nested |
1204 | -- package it may be frozen from an object declaration in the enclosing | |
1205 | -- scope, so install the package declarations to complete the analysis | |
1206 | -- of the aspects, if any. If the package itself is frozen the type will | |
1207 | -- have been frozen as well. | |
06ef5f86 | 1208 | |
ace3389d | 1209 | if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then |
3051730b | 1210 | if Is_Type (E) and then From_Nested_Package (E) then |
81083222 | 1211 | declare |
1212 | Pack : constant Entity_Id := Scope (E); | |
1213 | ||
1214 | begin | |
1215 | Push_Scope (Pack); | |
1216 | Install_Visible_Declarations (Pack); | |
1217 | Install_Private_Declarations (Pack); | |
1218 | Analyze_Aspects_At_Freeze_Point (E); | |
1219 | ||
1220 | if Is_Private_Type (E) | |
1221 | and then Present (Full_View (E)) | |
1222 | then | |
1223 | Analyze_Aspects_At_Freeze_Point (Full_View (E)); | |
1224 | end if; | |
1225 | ||
1226 | End_Package_Scope (Pack); | |
3051730b | 1227 | return; |
81083222 | 1228 | end; |
1229 | ||
5e67c1f8 | 1230 | -- Aspects from other entities in different contexts are analyzed |
1231 | -- elsewhere. | |
81083222 | 1232 | |
5e67c1f8 | 1233 | else |
81083222 | 1234 | return; |
1235 | end if; | |
06ef5f86 | 1236 | end if; |
1237 | ||
1238 | -- Look for aspect specification entries for this entity | |
1239 | ||
1240 | ASN := First_Rep_Item (E); | |
06ef5f86 | 1241 | while Present (ASN) loop |
37c6e44c | 1242 | if Nkind (ASN) = N_Aspect_Specification then |
1243 | exit when Entity (ASN) /= E; | |
06ef5f86 | 1244 | |
37c6e44c | 1245 | if Is_Delayed_Aspect (ASN) then |
1246 | A_Id := Get_Aspect_Id (ASN); | |
1247 | ||
1248 | case A_Id is | |
e4c87fa5 | 1249 | |
37c6e44c | 1250 | -- For aspects whose expression is an optional Boolean, make |
7d6fb253 | 1251 | -- the corresponding pragma at the freeze point. |
06ef5f86 | 1252 | |
99378362 | 1253 | when Boolean_Aspects |
1254 | | Library_Unit_Aspects | |
1255 | => | |
ee2b7923 | 1256 | -- Aspects Export and Import require special handling. |
1257 | -- Both are by definition Boolean and may benefit from | |
1258 | -- forward references, however their expressions are | |
1259 | -- treated as static. In addition, the syntax of their | |
1260 | -- corresponding pragmas requires extra "pieces" which | |
1261 | -- may also contain forward references. To account for | |
1262 | -- all of this, the corresponding pragma is created by | |
1263 | -- Analyze_Aspect_Export_Import, but is not analyzed as | |
1264 | -- the complete analysis must happen now. | |
1265 | ||
1266 | if A_Id = Aspect_Export or else A_Id = Aspect_Import then | |
1267 | null; | |
1268 | ||
1269 | -- Otherwise create a corresponding pragma | |
1270 | ||
1271 | else | |
1272 | Make_Pragma_From_Boolean_Aspect (ASN); | |
1273 | end if; | |
06ef5f86 | 1274 | |
37c6e44c | 1275 | -- Special handling for aspects that don't correspond to |
1276 | -- pragmas/attributes. | |
06ef5f86 | 1277 | |
99378362 | 1278 | when Aspect_Default_Value |
1279 | | Aspect_Default_Component_Value | |
1280 | => | |
81c2bc19 | 1281 | -- Do not inherit aspect for anonymous base type of a |
1282 | -- scalar or array type, because they apply to the first | |
1283 | -- subtype of the type, and will be processed when that | |
1284 | -- first subtype is frozen. | |
1285 | ||
1286 | if Is_Derived_Type (E) | |
1287 | and then not Comes_From_Source (E) | |
1288 | and then E /= First_Subtype (E) | |
1289 | then | |
1290 | null; | |
1291 | else | |
1292 | Analyze_Aspect_Default_Value (ASN); | |
1293 | end if; | |
06ef5f86 | 1294 | |
37c6e44c | 1295 | -- Ditto for iterator aspects, because the corresponding |
1296 | -- attributes may not have been analyzed yet. | |
af9fed8f | 1297 | |
99378362 | 1298 | when Aspect_Constant_Indexing |
1299 | | Aspect_Default_Iterator | |
1300 | | Aspect_Iterator_Element | |
1301 | | Aspect_Variable_Indexing | |
1302 | => | |
7d6fb253 | 1303 | Analyze (Expression (ASN)); |
af9fed8f | 1304 | |
7d6fb253 | 1305 | if Etype (Expression (ASN)) = Any_Type then |
1306 | Error_Msg_NE | |
1307 | ("\aspect must be fully defined before & is frozen", | |
1308 | ASN, E); | |
1309 | end if; | |
b3f8228a | 1310 | |
7d6fb253 | 1311 | when Aspect_Iterable => |
1312 | Validate_Iterable_Aspect (E, ASN); | |
1313 | ||
1314 | when others => | |
1315 | null; | |
37c6e44c | 1316 | end case; |
06ef5f86 | 1317 | |
37c6e44c | 1318 | Ritem := Aspect_Rep_Item (ASN); |
06ef5f86 | 1319 | |
37c6e44c | 1320 | if Present (Ritem) then |
1321 | Analyze (Ritem); | |
1322 | end if; | |
06ef5f86 | 1323 | end if; |
1324 | end if; | |
1325 | ||
1326 | Next_Rep_Item (ASN); | |
1327 | end loop; | |
37c6e44c | 1328 | |
1329 | -- This is where we inherit delayed rep aspects from our parent. Note | |
1330 | -- that if we fell out of the above loop with ASN non-empty, it means | |
1331 | -- we hit an aspect for an entity other than E, and it must be the | |
1332 | -- type from which we were derived. | |
1333 | ||
1334 | if May_Inherit_Delayed_Rep_Aspects (E) then | |
1335 | Inherit_Delayed_Rep_Aspects (ASN); | |
1336 | end if; | |
b4dcd57e | 1337 | |
1338 | if In_Instance | |
1339 | and then E /= Base_Type (E) | |
1340 | and then Is_First_Subtype (E) | |
1341 | then | |
1342 | Inherit_Rep_Item_Chain (Base_Type (E), E); | |
1343 | end if; | |
06ef5f86 | 1344 | end Analyze_Aspects_At_Freeze_Point; |
1345 | ||
ae888dbd | 1346 | ----------------------------------- |
1347 | -- Analyze_Aspect_Specifications -- | |
1348 | ----------------------------------- | |
1349 | ||
21ea3a4f | 1350 | procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is |
d39570ea | 1351 | pragma Assert (Present (E)); |
1352 | ||
e2bf777d | 1353 | procedure Decorate (Asp : Node_Id; Prag : Node_Id); |
6c5793cd | 1354 | -- Establish linkages between an aspect and its corresponding pragma |
5ddd846b | 1355 | |
5655be8a | 1356 | procedure Insert_Pragma |
1357 | (Prag : Node_Id; | |
1358 | Is_Instance : Boolean := False); | |
2f06c88a | 1359 | -- Subsidiary to the analysis of aspects |
1360 | -- Abstract_State | |
2f06c88a | 1361 | -- Attach_Handler |
1362 | -- Contract_Cases | |
1363 | -- Depends | |
5655be8a | 1364 | -- Ghost |
2f06c88a | 1365 | -- Global |
5655be8a | 1366 | -- Initial_Condition |
1367 | -- Initializes | |
2f06c88a | 1368 | -- Post |
1369 | -- Pre | |
1370 | -- Refined_Depends | |
1371 | -- Refined_Global | |
5655be8a | 1372 | -- Refined_State |
2f06c88a | 1373 | -- SPARK_Mode |
1374 | -- Warnings | |
e2bf777d | 1375 | -- Insert pragma Prag such that it mimics the placement of a source |
5655be8a | 1376 | -- pragma of the same kind. Flag Is_Generic should be set when the |
1377 | -- context denotes a generic instance. | |
e2bf777d | 1378 | |
1379 | -------------- | |
1380 | -- Decorate -- | |
1381 | -------------- | |
1382 | ||
1383 | procedure Decorate (Asp : Node_Id; Prag : Node_Id) is | |
5ddd846b | 1384 | begin |
6c5793cd | 1385 | Set_Aspect_Rep_Item (Asp, Prag); |
5ddd846b | 1386 | Set_Corresponding_Aspect (Prag, Asp); |
1387 | Set_From_Aspect_Specification (Prag); | |
5ddd846b | 1388 | Set_Parent (Prag, Asp); |
e2bf777d | 1389 | end Decorate; |
f0813d71 | 1390 | |
e2bf777d | 1391 | ------------------- |
1392 | -- Insert_Pragma -- | |
1393 | ------------------- | |
c1006d6d | 1394 | |
5655be8a | 1395 | procedure Insert_Pragma |
1396 | (Prag : Node_Id; | |
1397 | Is_Instance : Boolean := False) | |
1398 | is | |
3ff5e35d | 1399 | Aux : Node_Id; |
1400 | Decl : Node_Id; | |
1401 | Decls : List_Id; | |
1402 | Def : Node_Id; | |
1403 | Inserted : Boolean := False; | |
c1006d6d | 1404 | |
1405 | begin | |
3ff5e35d | 1406 | -- When the aspect appears on an entry, package, protected unit, |
1407 | -- subprogram, or task unit body, insert the generated pragma at the | |
1408 | -- top of the body declarations to emulate the behavior of a source | |
1409 | -- pragma. | |
2f06c88a | 1410 | |
1411 | -- package body Pack with Aspect is | |
1412 | ||
1413 | -- package body Pack is | |
1414 | -- pragma Prag; | |
1415 | ||
3ff5e35d | 1416 | if Nkind_In (N, N_Entry_Body, |
1417 | N_Package_Body, | |
2f06c88a | 1418 | N_Protected_Body, |
1419 | N_Subprogram_Body, | |
1420 | N_Task_Body) | |
1421 | then | |
1422 | Decls := Declarations (N); | |
1423 | ||
1424 | if No (Decls) then | |
1425 | Decls := New_List; | |
1426 | Set_Declarations (N, Decls); | |
1427 | end if; | |
e2bf777d | 1428 | |
3ff5e35d | 1429 | Prepend_To (Decls, Prag); |
2f06c88a | 1430 | |
1431 | -- When the aspect is associated with a [generic] package declaration | |
1432 | -- insert the generated pragma at the top of the visible declarations | |
1433 | -- to emulate the behavior of a source pragma. | |
1434 | ||
1435 | -- package Pack with Aspect is | |
1436 | ||
1437 | -- package Pack is | |
1438 | -- pragma Prag; | |
1439 | ||
1440 | elsif Nkind_In (N, N_Generic_Package_Declaration, | |
1441 | N_Package_Declaration) | |
1442 | then | |
1443 | Decls := Visible_Declarations (Specification (N)); | |
1444 | ||
1445 | if No (Decls) then | |
1446 | Decls := New_List; | |
1447 | Set_Visible_Declarations (Specification (N), Decls); | |
1448 | end if; | |
1449 | ||
5655be8a | 1450 | -- The visible declarations of a generic instance have the |
1451 | -- following structure: | |
1452 | ||
1453 | -- <renamings of generic formals> | |
1454 | -- <renamings of internally-generated spec and body> | |
1455 | -- <first source declaration> | |
1456 | ||
1457 | -- Insert the pragma before the first source declaration by | |
3ff5e35d | 1458 | -- skipping the instance "header" to ensure proper visibility of |
1459 | -- all formals. | |
5655be8a | 1460 | |
1461 | if Is_Instance then | |
1462 | Decl := First (Decls); | |
3ff5e35d | 1463 | while Present (Decl) loop |
1464 | if Comes_From_Source (Decl) then | |
1465 | Insert_Before (Decl, Prag); | |
1466 | Inserted := True; | |
1467 | exit; | |
1468 | else | |
1469 | Next (Decl); | |
1470 | end if; | |
5655be8a | 1471 | end loop; |
1472 | ||
3ff5e35d | 1473 | -- The pragma is placed after the instance "header" |
5655be8a | 1474 | |
3ff5e35d | 1475 | if not Inserted then |
5655be8a | 1476 | Append_To (Decls, Prag); |
1477 | end if; | |
1478 | ||
1479 | -- Otherwise this is not a generic instance | |
1480 | ||
1481 | else | |
1482 | Prepend_To (Decls, Prag); | |
1483 | end if; | |
2f06c88a | 1484 | |
1485 | -- When the aspect is associated with a protected unit declaration, | |
1486 | -- insert the generated pragma at the top of the visible declarations | |
1487 | -- the emulate the behavior of a source pragma. | |
1488 | ||
1489 | -- protected [type] Prot with Aspect is | |
1490 | ||
1491 | -- protected [type] Prot is | |
1492 | -- pragma Prag; | |
1493 | ||
1494 | elsif Nkind (N) = N_Protected_Type_Declaration then | |
736b80cc | 1495 | Def := Protected_Definition (N); |
1496 | ||
1497 | if No (Def) then | |
1498 | Def := | |
1499 | Make_Protected_Definition (Sloc (N), | |
1500 | Visible_Declarations => New_List, | |
1501 | End_Label => Empty); | |
1502 | ||
1503 | Set_Protected_Definition (N, Def); | |
1504 | end if; | |
1505 | ||
1506 | Decls := Visible_Declarations (Def); | |
2f06c88a | 1507 | |
1508 | if No (Decls) then | |
1509 | Decls := New_List; | |
736b80cc | 1510 | Set_Visible_Declarations (Def, Decls); |
2f06c88a | 1511 | end if; |
1512 | ||
1513 | Prepend_To (Decls, Prag); | |
1514 | ||
736b80cc | 1515 | -- When the aspect is associated with a task unit declaration, insert |
1516 | -- insert the generated pragma at the top of the visible declarations | |
1517 | -- the emulate the behavior of a source pragma. | |
2f06c88a | 1518 | |
1519 | -- task [type] Prot with Aspect is | |
1520 | ||
1521 | -- task [type] Prot is | |
1522 | -- pragma Prag; | |
1523 | ||
736b80cc | 1524 | elsif Nkind (N) = N_Task_Type_Declaration then |
1525 | Def := Task_Definition (N); | |
1526 | ||
1527 | if No (Def) then | |
1528 | Def := | |
1529 | Make_Task_Definition (Sloc (N), | |
1530 | Visible_Declarations => New_List, | |
1531 | End_Label => Empty); | |
1532 | ||
1533 | Set_Task_Definition (N, Def); | |
1534 | end if; | |
1535 | ||
1536 | Decls := Visible_Declarations (Def); | |
2f06c88a | 1537 | |
1538 | if No (Decls) then | |
1539 | Decls := New_List; | |
736b80cc | 1540 | Set_Visible_Declarations (Def, Decls); |
d324c418 | 1541 | end if; |
c1006d6d | 1542 | |
2f06c88a | 1543 | Prepend_To (Decls, Prag); |
1544 | ||
ed695684 | 1545 | -- When the context is a library unit, the pragma is added to the |
1546 | -- Pragmas_After list. | |
1547 | ||
1548 | elsif Nkind (Parent (N)) = N_Compilation_Unit then | |
1549 | Aux := Aux_Decls_Node (Parent (N)); | |
1550 | ||
1551 | if No (Pragmas_After (Aux)) then | |
1552 | Set_Pragmas_After (Aux, New_List); | |
1553 | end if; | |
1554 | ||
1555 | Prepend (Prag, Pragmas_After (Aux)); | |
1556 | ||
2f06c88a | 1557 | -- Default, the pragma is inserted after the context |
c1006d6d | 1558 | |
1559 | else | |
1560 | Insert_After (N, Prag); | |
c1006d6d | 1561 | end if; |
e2bf777d | 1562 | end Insert_Pragma; |
c1006d6d | 1563 | |
1564 | -- Local variables | |
1565 | ||
ae888dbd | 1566 | Aspect : Node_Id; |
d74fc39a | 1567 | Aitem : Node_Id; |
ae888dbd | 1568 | Ent : Node_Id; |
ae888dbd | 1569 | |
21ea3a4f | 1570 | L : constant List_Id := Aspect_Specifications (N); |
d39570ea | 1571 | pragma Assert (Present (L)); |
21ea3a4f | 1572 | |
ae888dbd | 1573 | Ins_Node : Node_Id := N; |
89f1e35c | 1574 | -- Insert pragmas/attribute definition clause after this node when no |
1575 | -- delayed analysis is required. | |
d74fc39a | 1576 | |
ee2b7923 | 1577 | -- Start of processing for Analyze_Aspect_Specifications |
f0813d71 | 1578 | |
ee2b7923 | 1579 | begin |
d74fc39a | 1580 | -- The general processing involves building an attribute definition |
89f1e35c | 1581 | -- clause or a pragma node that corresponds to the aspect. Then in order |
1582 | -- to delay the evaluation of this aspect to the freeze point, we attach | |
1583 | -- the corresponding pragma/attribute definition clause to the aspect | |
1584 | -- specification node, which is then placed in the Rep Item chain. In | |
1585 | -- this case we mark the entity by setting the flag Has_Delayed_Aspects | |
1586 | -- and we evaluate the rep item at the freeze point. When the aspect | |
1587 | -- doesn't have a corresponding pragma/attribute definition clause, then | |
1588 | -- its analysis is simply delayed at the freeze point. | |
1589 | ||
1590 | -- Some special cases don't require delay analysis, thus the aspect is | |
1591 | -- analyzed right now. | |
1592 | ||
51ea9c94 | 1593 | -- Note that there is a special handling for Pre, Post, Test_Case, |
e66f4e2a | 1594 | -- Contract_Cases aspects. In these cases, we do not have to worry |
51ea9c94 | 1595 | -- about delay issues, since the pragmas themselves deal with delay |
1596 | -- of visibility for the expression analysis. Thus, we just insert | |
1597 | -- the pragma after the node N. | |
ae888dbd | 1598 | |
6fb3c314 | 1599 | -- Loop through aspects |
f93e7257 | 1600 | |
ae888dbd | 1601 | Aspect := First (L); |
21ea3a4f | 1602 | Aspect_Loop : while Present (Aspect) loop |
0fd13d32 | 1603 | Analyze_One_Aspect : declare |
94153a42 | 1604 | Expr : constant Node_Id := Expression (Aspect); |
89f1e35c | 1605 | Id : constant Node_Id := Identifier (Aspect); |
1606 | Loc : constant Source_Ptr := Sloc (Aspect); | |
94153a42 | 1607 | Nam : constant Name_Id := Chars (Id); |
1608 | A_Id : constant Aspect_Id := Get_Aspect_Id (Nam); | |
ae888dbd | 1609 | Anod : Node_Id; |
1610 | ||
37c6e44c | 1611 | Delay_Required : Boolean; |
89f1e35c | 1612 | -- Set False if delay is not required |
1613 | ||
c0793fff | 1614 | Eloc : Source_Ptr := No_Location; |
1615 | -- Source location of expression, modified when we split PPC's. It | |
1616 | -- is set below when Expr is present. | |
39e1f22f | 1617 | |
ee2b7923 | 1618 | procedure Analyze_Aspect_Convention; |
1619 | -- Perform analysis of aspect Convention | |
1620 | ||
0b10029c | 1621 | procedure Analyze_Aspect_Disable_Controlled; |
1622 | -- Perform analysis of aspect Disable_Controlled | |
1623 | ||
ee2b7923 | 1624 | procedure Analyze_Aspect_Export_Import; |
1625 | -- Perform analysis of aspects Export or Import | |
1626 | ||
1627 | procedure Analyze_Aspect_External_Link_Name; | |
1628 | -- Perform analysis of aspects External_Name or Link_Name | |
21ea3a4f | 1629 | |
89f1e35c | 1630 | procedure Analyze_Aspect_Implicit_Dereference; |
9ab32fe9 | 1631 | -- Perform analysis of the Implicit_Dereference aspects |
0fd13d32 | 1632 | |
1633 | procedure Make_Aitem_Pragma | |
1634 | (Pragma_Argument_Associations : List_Id; | |
1635 | Pragma_Name : Name_Id); | |
1636 | -- This is a wrapper for Make_Pragma used for converting aspects | |
1637 | -- to pragmas. It takes care of Sloc (set from Loc) and building | |
1638 | -- the pragma identifier from the given name. In addition the | |
1639 | -- flags Class_Present and Split_PPC are set from the aspect | |
1640 | -- node, as well as Is_Ignored. This routine also sets the | |
1641 | -- From_Aspect_Specification in the resulting pragma node to | |
1642 | -- True, and sets Corresponding_Aspect to point to the aspect. | |
1643 | -- The resulting pragma is assigned to Aitem. | |
21ea3a4f | 1644 | |
ee2b7923 | 1645 | ------------------------------- |
1646 | -- Analyze_Aspect_Convention -- | |
1647 | ------------------------------- | |
1648 | ||
1649 | procedure Analyze_Aspect_Convention is | |
1650 | Conv : Node_Id; | |
1651 | Dummy_1 : Node_Id; | |
1652 | Dummy_2 : Node_Id; | |
1653 | Dummy_3 : Node_Id; | |
1654 | Expo : Node_Id; | |
1655 | Imp : Node_Id; | |
89f1e35c | 1656 | |
21ea3a4f | 1657 | begin |
ee2b7923 | 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 is subject to aspect Export or Import. | |
1671 | -- Do not process Convention now because it must be analysed | |
1672 | -- as part of Export or Import. | |
1673 | ||
1674 | if Present (Expo) or else Present (Imp) then | |
1675 | return; | |
21ea3a4f | 1676 | |
ee2b7923 | 1677 | -- Otherwise Convention appears by itself |
21ea3a4f | 1678 | |
ee2b7923 | 1679 | else |
1680 | -- The aspect specifies a particular convention | |
1681 | ||
1682 | if Present (Expr) then | |
1683 | Conv := New_Copy_Tree (Expr); | |
1684 | ||
1685 | -- Otherwise assume convention Ada | |
1686 | ||
1687 | else | |
1688 | Conv := Make_Identifier (Loc, Name_Ada); | |
1689 | end if; | |
1690 | ||
1691 | -- Generate: | |
1692 | -- pragma Convention (<Conv>, <E>); | |
1693 | ||
1694 | Make_Aitem_Pragma | |
1695 | (Pragma_Name => Name_Convention, | |
1696 | Pragma_Argument_Associations => New_List ( | |
1697 | Make_Pragma_Argument_Association (Loc, | |
1698 | Expression => Conv), | |
1699 | Make_Pragma_Argument_Association (Loc, | |
1700 | Expression => New_Occurrence_Of (E, Loc)))); | |
1701 | ||
1702 | Decorate (Aspect, Aitem); | |
1703 | Insert_Pragma (Aitem); | |
1704 | end if; | |
1705 | end Analyze_Aspect_Convention; | |
1706 | ||
0b10029c | 1707 | --------------------------------------- |
1708 | -- Analyze_Aspect_Disable_Controlled -- | |
1709 | --------------------------------------- | |
1710 | ||
1711 | procedure Analyze_Aspect_Disable_Controlled is | |
1712 | begin | |
1713 | -- The aspect applies only to controlled records | |
1714 | ||
1715 | if not (Ekind (E) = E_Record_Type | |
1716 | and then Is_Controlled_Active (E)) | |
1717 | then | |
1718 | Error_Msg_N | |
1719 | ("aspect % requires controlled record type", Aspect); | |
1720 | return; | |
1721 | end if; | |
1722 | ||
1723 | -- Preanalyze the expression (if any) when the aspect resides | |
1724 | -- in a generic unit. | |
1725 | ||
1726 | if Inside_A_Generic then | |
1727 | if Present (Expr) then | |
1728 | Preanalyze_And_Resolve (Expr, Any_Boolean); | |
1729 | end if; | |
1730 | ||
1731 | -- Otherwise the aspect resides in a nongeneric context | |
1732 | ||
1733 | else | |
1734 | -- A controlled record type loses its controlled semantics | |
1735 | -- when the expression statically evaluates to True. | |
1736 | ||
1737 | if Present (Expr) then | |
1738 | Analyze_And_Resolve (Expr, Any_Boolean); | |
1739 | ||
1740 | if Is_OK_Static_Expression (Expr) then | |
1741 | if Is_True (Static_Boolean (Expr)) then | |
1742 | Set_Disable_Controlled (E); | |
1743 | end if; | |
1744 | ||
1745 | -- Otherwise the expression is not static | |
1746 | ||
1747 | else | |
1748 | Error_Msg_N | |
1749 | ("expression of aspect % must be static", Aspect); | |
1750 | end if; | |
1751 | ||
1752 | -- Otherwise the aspect appears without an expression and | |
1753 | -- defaults to True. | |
1754 | ||
1755 | else | |
1756 | Set_Disable_Controlled (E); | |
1757 | end if; | |
1758 | end if; | |
1759 | end Analyze_Aspect_Disable_Controlled; | |
1760 | ||
ee2b7923 | 1761 | ---------------------------------- |
1762 | -- Analyze_Aspect_Export_Import -- | |
1763 | ---------------------------------- | |
21ea3a4f | 1764 | |
ee2b7923 | 1765 | procedure Analyze_Aspect_Export_Import is |
1766 | Dummy_1 : Node_Id; | |
1767 | Dummy_2 : Node_Id; | |
1768 | Dummy_3 : Node_Id; | |
1769 | Expo : Node_Id; | |
1770 | Imp : Node_Id; | |
1771 | ||
1772 | begin | |
1773 | -- Obtain all interfacing aspects that apply to the related | |
1774 | -- entity. | |
1775 | ||
1776 | Get_Interfacing_Aspects | |
1777 | (Iface_Asp => Aspect, | |
1778 | Conv_Asp => Dummy_1, | |
1779 | EN_Asp => Dummy_2, | |
1780 | Expo_Asp => Expo, | |
1781 | Imp_Asp => Imp, | |
1782 | LN_Asp => Dummy_3, | |
1783 | Do_Checks => True); | |
1784 | ||
1785 | -- The related entity cannot be subject to both aspects Export | |
1786 | -- and Import. | |
1787 | ||
1788 | if Present (Expo) and then Present (Imp) then | |
1789 | Error_Msg_N | |
1790 | ("incompatible interfacing aspects given for &", E); | |
1791 | Error_Msg_Sloc := Sloc (Expo); | |
1792 | Error_Msg_N ("\aspect `Export` #", E); | |
1793 | Error_Msg_Sloc := Sloc (Imp); | |
1794 | Error_Msg_N ("\aspect `Import` #", E); | |
1795 | end if; | |
1796 | ||
1797 | -- A variable is most likely modified from the outside. Take | |
051826ee | 1798 | -- the optimistic approach to avoid spurious errors. |
ee2b7923 | 1799 | |
1800 | if Ekind (E) = E_Variable then | |
1801 | Set_Never_Set_In_Source (E, False); | |
1802 | end if; | |
1803 | ||
1804 | -- Resolve the expression of an Import or Export here, and | |
1805 | -- require it to be of type Boolean and static. This is not | |
1806 | -- quite right, because in general this should be delayed, | |
1807 | -- but that seems tricky for these, because normally Boolean | |
1808 | -- aspects are replaced with pragmas at the freeze point in | |
1809 | -- Make_Pragma_From_Boolean_Aspect. | |
1810 | ||
1811 | if not Present (Expr) | |
1812 | or else Is_True (Static_Boolean (Expr)) | |
1813 | then | |
1814 | if A_Id = Aspect_Import then | |
1815 | Set_Has_Completion (E); | |
1816 | Set_Is_Imported (E); | |
1817 | ||
1818 | -- An imported object cannot be explicitly initialized | |
1819 | ||
1820 | if Nkind (N) = N_Object_Declaration | |
1821 | and then Present (Expression (N)) | |
1822 | then | |
1823 | Error_Msg_N | |
1824 | ("imported entities cannot be initialized " | |
1825 | & "(RM B.1(24))", Expression (N)); | |
1826 | end if; | |
1827 | ||
1828 | else | |
1829 | pragma Assert (A_Id = Aspect_Export); | |
1830 | Set_Is_Exported (E); | |
1831 | end if; | |
1832 | ||
1833 | -- Create the proper form of pragma Export or Import taking | |
1834 | -- into account Conversion, External_Name, and Link_Name. | |
1835 | ||
1836 | Aitem := Build_Export_Import_Pragma (Aspect, E); | |
d8e539ae | 1837 | |
1838 | -- Otherwise the expression is either False or erroneous. There | |
1839 | -- is no corresponding pragma. | |
1840 | ||
1841 | else | |
1842 | Aitem := Empty; | |
ee2b7923 | 1843 | end if; |
1844 | end Analyze_Aspect_Export_Import; | |
1845 | ||
1846 | --------------------------------------- | |
1847 | -- Analyze_Aspect_External_Link_Name -- | |
1848 | --------------------------------------- | |
1849 | ||
1850 | procedure Analyze_Aspect_External_Link_Name is | |
1851 | Dummy_1 : Node_Id; | |
1852 | Dummy_2 : Node_Id; | |
1853 | Dummy_3 : Node_Id; | |
1854 | Expo : Node_Id; | |
1855 | Imp : Node_Id; | |
1856 | ||
1857 | begin | |
1858 | -- Obtain all interfacing aspects that apply to the related | |
1859 | -- entity. | |
1860 | ||
1861 | Get_Interfacing_Aspects | |
1862 | (Iface_Asp => Aspect, | |
1863 | Conv_Asp => Dummy_1, | |
1864 | EN_Asp => Dummy_2, | |
1865 | Expo_Asp => Expo, | |
1866 | Imp_Asp => Imp, | |
1867 | LN_Asp => Dummy_3, | |
1868 | Do_Checks => True); | |
1869 | ||
1870 | -- Ensure that aspect External_Name applies to aspect Export or | |
1871 | -- Import. | |
1872 | ||
1873 | if A_Id = Aspect_External_Name then | |
1874 | if No (Expo) and then No (Imp) then | |
89f1e35c | 1875 | Error_Msg_N |
ee2b7923 | 1876 | ("aspect `External_Name` requires aspect `Import` or " |
1877 | & "`Export`", Aspect); | |
89f1e35c | 1878 | end if; |
ee2b7923 | 1879 | |
1880 | -- Otherwise ensure that aspect Link_Name applies to aspect | |
1881 | -- Export or Import. | |
1882 | ||
1883 | else | |
1884 | pragma Assert (A_Id = Aspect_Link_Name); | |
1885 | if No (Expo) and then No (Imp) then | |
1886 | Error_Msg_N | |
1887 | ("aspect `Link_Name` requires aspect `Import` or " | |
1888 | & "`Export`", Aspect); | |
1889 | end if; | |
1890 | end if; | |
1891 | end Analyze_Aspect_External_Link_Name; | |
21ea3a4f | 1892 | |
89f1e35c | 1893 | ----------------------------------------- |
1894 | -- Analyze_Aspect_Implicit_Dereference -- | |
1895 | ----------------------------------------- | |
21ea3a4f | 1896 | |
89f1e35c | 1897 | procedure Analyze_Aspect_Implicit_Dereference is |
1898 | begin | |
b9e61b2a | 1899 | if not Is_Type (E) or else not Has_Discriminants (E) then |
89f1e35c | 1900 | Error_Msg_N |
1ff43c00 | 1901 | ("aspect must apply to a type with discriminants", Expr); |
21ea3a4f | 1902 | |
1ff43c00 | 1903 | elsif not Is_Entity_Name (Expr) then |
1904 | Error_Msg_N | |
1905 | ("aspect must name a discriminant of current type", Expr); | |
21ea3a4f | 1906 | |
1ff43c00 | 1907 | else |
f021ee0f | 1908 | -- Discriminant type be an anonymous access type or an |
1909 | -- anonymous access to subprogram. | |
0d0a4e9b | 1910 | |
f021ee0f | 1911 | -- Missing synchronized types??? |
1912 | ||
d39570ea | 1913 | declare |
1914 | Disc : Entity_Id := First_Discriminant (E); | |
1915 | begin | |
1916 | while Present (Disc) loop | |
1917 | if Chars (Expr) = Chars (Disc) | |
1918 | and then Ekind_In | |
1919 | (Etype (Disc), | |
1920 | E_Anonymous_Access_Subprogram_Type, | |
1921 | E_Anonymous_Access_Type) | |
1922 | then | |
1923 | Set_Has_Implicit_Dereference (E); | |
1924 | Set_Has_Implicit_Dereference (Disc); | |
1925 | exit; | |
1926 | end if; | |
21ea3a4f | 1927 | |
d39570ea | 1928 | Next_Discriminant (Disc); |
1929 | end loop; | |
21ea3a4f | 1930 | |
d39570ea | 1931 | -- Error if no proper access discriminant |
1ff43c00 | 1932 | |
d39570ea | 1933 | if Present (Disc) then |
1934 | -- For a type extension, check whether parent has | |
1935 | -- a reference discriminant, to verify that use is | |
1936 | -- proper. | |
9b5b11fb | 1937 | |
d39570ea | 1938 | if Is_Derived_Type (E) |
1939 | and then Has_Discriminants (Etype (E)) | |
1940 | then | |
1941 | declare | |
1942 | Parent_Disc : constant Entity_Id := | |
1943 | Get_Reference_Discriminant (Etype (E)); | |
1944 | begin | |
1945 | if Present (Parent_Disc) | |
1946 | and then Corresponding_Discriminant (Disc) /= | |
1947 | Parent_Disc | |
1948 | then | |
1949 | Error_Msg_N | |
1950 | ("reference discriminant does not match " | |
1951 | & "discriminant of parent type", Expr); | |
1952 | end if; | |
1953 | end; | |
1954 | end if; | |
1ff43c00 | 1955 | |
d39570ea | 1956 | else |
1957 | Error_Msg_NE | |
1958 | ("not an access discriminant of&", Expr, E); | |
1959 | end if; | |
1960 | end; | |
89f1e35c | 1961 | end if; |
d39570ea | 1962 | |
89f1e35c | 1963 | end Analyze_Aspect_Implicit_Dereference; |
21ea3a4f | 1964 | |
0fd13d32 | 1965 | ----------------------- |
1966 | -- Make_Aitem_Pragma -- | |
1967 | ----------------------- | |
1968 | ||
1969 | procedure Make_Aitem_Pragma | |
1970 | (Pragma_Argument_Associations : List_Id; | |
1971 | Pragma_Name : Name_Id) | |
1972 | is | |
b855559d | 1973 | Args : List_Id := Pragma_Argument_Associations; |
1974 | ||
0fd13d32 | 1975 | begin |
1976 | -- We should never get here if aspect was disabled | |
1977 | ||
1978 | pragma Assert (not Is_Disabled (Aspect)); | |
1979 | ||
056dc987 | 1980 | -- Certain aspects allow for an optional name or expression. Do |
1981 | -- not generate a pragma with empty argument association list. | |
b855559d | 1982 | |
1983 | if No (Args) or else No (Expression (First (Args))) then | |
1984 | Args := No_List; | |
1985 | end if; | |
1986 | ||
0fd13d32 | 1987 | -- Build the pragma |
1988 | ||
1989 | Aitem := | |
1990 | Make_Pragma (Loc, | |
b855559d | 1991 | Pragma_Argument_Associations => Args, |
0fd13d32 | 1992 | Pragma_Identifier => |
1993 | Make_Identifier (Sloc (Id), Pragma_Name), | |
9ab32fe9 | 1994 | Class_Present => Class_Present (Aspect), |
1995 | Split_PPC => Split_PPC (Aspect)); | |
0fd13d32 | 1996 | |
1997 | -- Set additional semantic fields | |
1998 | ||
1999 | if Is_Ignored (Aspect) then | |
2000 | Set_Is_Ignored (Aitem); | |
57d8d1f3 | 2001 | elsif Is_Checked (Aspect) then |
a5109493 | 2002 | Set_Is_Checked (Aitem); |
0fd13d32 | 2003 | end if; |
2004 | ||
2005 | Set_Corresponding_Aspect (Aitem, Aspect); | |
fdec445e | 2006 | Set_From_Aspect_Specification (Aitem); |
0fd13d32 | 2007 | end Make_Aitem_Pragma; |
2008 | ||
738ec25b | 2009 | -- Start of processing for Analyze_One_Aspect |
0fd13d32 | 2010 | |
ae888dbd | 2011 | begin |
2d1acfa7 | 2012 | -- Skip aspect if already analyzed, to avoid looping in some cases |
fb7f2fc4 | 2013 | |
2014 | if Analyzed (Aspect) then | |
2015 | goto Continue; | |
2016 | end if; | |
2017 | ||
ef957022 | 2018 | -- Skip looking at aspect if it is totally disabled. Just mark it |
2019 | -- as such for later reference in the tree. This also sets the | |
2020 | -- Is_Ignored and Is_Checked flags appropriately. | |
51ea9c94 | 2021 | |
2022 | Check_Applicable_Policy (Aspect); | |
2023 | ||
2024 | if Is_Disabled (Aspect) then | |
2025 | goto Continue; | |
2026 | end if; | |
2027 | ||
c0793fff | 2028 | -- Set the source location of expression, used in the case of |
2029 | -- a failed precondition/postcondition or invariant. Note that | |
2030 | -- the source location of the expression is not usually the best | |
2031 | -- choice here. For example, it gets located on the last AND | |
2032 | -- keyword in a chain of boolean expressiond AND'ed together. | |
2033 | -- It is best to put the message on the first character of the | |
2034 | -- assertion, which is the effect of the First_Node call here. | |
2035 | ||
2036 | if Present (Expr) then | |
2037 | Eloc := Sloc (First_Node (Expr)); | |
2038 | end if; | |
2039 | ||
d7ed83a2 | 2040 | -- Check restriction No_Implementation_Aspect_Specifications |
2041 | ||
c171e1be | 2042 | if Implementation_Defined_Aspect (A_Id) then |
d7ed83a2 | 2043 | Check_Restriction |
2044 | (No_Implementation_Aspect_Specifications, Aspect); | |
2045 | end if; | |
2046 | ||
2047 | -- Check restriction No_Specification_Of_Aspect | |
2048 | ||
2049 | Check_Restriction_No_Specification_Of_Aspect (Aspect); | |
2050 | ||
f67ed4f5 | 2051 | -- Mark aspect analyzed (actual analysis is delayed till later) |
d7ed83a2 | 2052 | |
fb7f2fc4 | 2053 | Set_Analyzed (Aspect); |
d74fc39a | 2054 | Set_Entity (Aspect, E); |
738ec25b | 2055 | |
2056 | -- Build the reference to E that will be used in the built pragmas | |
2057 | ||
d74fc39a | 2058 | Ent := New_Occurrence_Of (E, Sloc (Id)); |
2059 | ||
738ec25b | 2060 | if A_Id = Aspect_Attach_Handler |
2061 | or else A_Id = Aspect_Interrupt_Handler | |
2062 | then | |
738ec25b | 2063 | |
f0e731f2 | 2064 | -- Treat the specification as a reference to the protected |
2065 | -- operation, which might otherwise appear unreferenced and | |
2066 | -- generate spurious warnings. | |
738ec25b | 2067 | |
f0e731f2 | 2068 | Generate_Reference (E, Id); |
738ec25b | 2069 | end if; |
2070 | ||
1e3c4ae6 | 2071 | -- Check for duplicate aspect. Note that the Comes_From_Source |
2072 | -- test allows duplicate Pre/Post's that we generate internally | |
2073 | -- to escape being flagged here. | |
ae888dbd | 2074 | |
6c545057 | 2075 | if No_Duplicates_Allowed (A_Id) then |
2076 | Anod := First (L); | |
2077 | while Anod /= Aspect loop | |
c171e1be | 2078 | if Comes_From_Source (Aspect) |
2079 | and then Same_Aspect (A_Id, Get_Aspect_Id (Anod)) | |
6c545057 | 2080 | then |
2081 | Error_Msg_Name_1 := Nam; | |
2082 | Error_Msg_Sloc := Sloc (Anod); | |
39e1f22f | 2083 | |
6c545057 | 2084 | -- Case of same aspect specified twice |
39e1f22f | 2085 | |
6c545057 | 2086 | if Class_Present (Anod) = Class_Present (Aspect) then |
2087 | if not Class_Present (Anod) then | |
2088 | Error_Msg_NE | |
2089 | ("aspect% for & previously given#", | |
2090 | Id, E); | |
2091 | else | |
2092 | Error_Msg_NE | |
2093 | ("aspect `%''Class` for & previously given#", | |
2094 | Id, E); | |
2095 | end if; | |
39e1f22f | 2096 | end if; |
6c545057 | 2097 | end if; |
ae888dbd | 2098 | |
6c545057 | 2099 | Next (Anod); |
2100 | end loop; | |
2101 | end if; | |
ae888dbd | 2102 | |
4db325e6 | 2103 | -- Check some general restrictions on language defined aspects |
2104 | ||
c171e1be | 2105 | if not Implementation_Defined_Aspect (A_Id) then |
4db325e6 | 2106 | Error_Msg_Name_1 := Nam; |
2107 | ||
d1edd78e | 2108 | -- Not allowed for renaming declarations. Examine the original |
da1b7592 | 2109 | -- node because a subprogram renaming may have been rewritten |
2110 | -- as a body. | |
4db325e6 | 2111 | |
da1b7592 | 2112 | if Nkind (Original_Node (N)) in N_Renaming_Declaration then |
4db325e6 | 2113 | Error_Msg_N |
2114 | ("aspect % not allowed for renaming declaration", | |
2115 | Aspect); | |
2116 | end if; | |
2117 | ||
2118 | -- Not allowed for formal type declarations | |
2119 | ||
2120 | if Nkind (N) = N_Formal_Type_Declaration then | |
2121 | Error_Msg_N | |
2122 | ("aspect % not allowed for formal type declaration", | |
2123 | Aspect); | |
2124 | end if; | |
2125 | end if; | |
2126 | ||
7d20685d | 2127 | -- Copy expression for later processing by the procedures |
2128 | -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations] | |
2129 | ||
2130 | Set_Entity (Id, New_Copy_Tree (Expr)); | |
2131 | ||
37c6e44c | 2132 | -- Set Delay_Required as appropriate to aspect |
2133 | ||
2134 | case Aspect_Delay (A_Id) is | |
2135 | when Always_Delay => | |
2136 | Delay_Required := True; | |
2137 | ||
2138 | when Never_Delay => | |
2139 | Delay_Required := False; | |
2140 | ||
2141 | when Rep_Aspect => | |
2142 | ||
2143 | -- If expression has the form of an integer literal, then | |
2144 | -- do not delay, since we know the value cannot change. | |
2145 | -- This optimization catches most rep clause cases. | |
2146 | ||
e43fc5c5 | 2147 | -- For Boolean aspects, don't delay if no expression |
2148 | ||
2149 | if A_Id in Boolean_Aspects and then No (Expr) then | |
2150 | Delay_Required := False; | |
2151 | ||
c5c6a638 | 2152 | -- For non-Boolean aspects, don't delay if integer literal, |
2153 | -- unless the aspect is Alignment, which affects the | |
2154 | -- freezing of an initialized object. | |
e43fc5c5 | 2155 | |
2156 | elsif A_Id not in Boolean_Aspects | |
c5c6a638 | 2157 | and then A_Id /= Aspect_Alignment |
e43fc5c5 | 2158 | and then Present (Expr) |
2159 | and then Nkind (Expr) = N_Integer_Literal | |
2160 | then | |
2161 | Delay_Required := False; | |
2162 | ||
2163 | -- All other cases are delayed | |
2164 | ||
2165 | else | |
2166 | Delay_Required := True; | |
2167 | Set_Has_Delayed_Rep_Aspects (E); | |
2168 | end if; | |
37c6e44c | 2169 | end case; |
2170 | ||
ae888dbd | 2171 | -- Processing based on specific aspect |
2172 | ||
d74fc39a | 2173 | case A_Id is |
aa2f48d2 | 2174 | when Aspect_Unimplemented => |
2175 | null; -- ??? temp for now | |
ae888dbd | 2176 | |
2177 | -- No_Aspect should be impossible | |
2178 | ||
2179 | when No_Aspect => | |
2180 | raise Program_Error; | |
2181 | ||
89f1e35c | 2182 | -- Case 1: Aspects corresponding to attribute definition |
2183 | -- clauses. | |
ae888dbd | 2184 | |
99378362 | 2185 | when Aspect_Address |
2186 | | Aspect_Alignment | |
2187 | | Aspect_Bit_Order | |
2188 | | Aspect_Component_Size | |
2189 | | Aspect_Constant_Indexing | |
2190 | | Aspect_Default_Iterator | |
2191 | | Aspect_Dispatching_Domain | |
2192 | | Aspect_External_Tag | |
2193 | | Aspect_Input | |
2194 | | Aspect_Iterable | |
2195 | | Aspect_Iterator_Element | |
2196 | | Aspect_Machine_Radix | |
2197 | | Aspect_Object_Size | |
2198 | | Aspect_Output | |
2199 | | Aspect_Read | |
2200 | | Aspect_Scalar_Storage_Order | |
99378362 | 2201 | | Aspect_Simple_Storage_Pool |
2202 | | Aspect_Size | |
2203 | | Aspect_Small | |
2204 | | Aspect_Storage_Pool | |
2205 | | Aspect_Stream_Size | |
2206 | | Aspect_Value_Size | |
2207 | | Aspect_Variable_Indexing | |
2208 | | Aspect_Write | |
2209 | => | |
89f1e35c | 2210 | -- Indexing aspects apply only to tagged type |
2211 | ||
2212 | if (A_Id = Aspect_Constant_Indexing | |
37c6e44c | 2213 | or else |
2214 | A_Id = Aspect_Variable_Indexing) | |
89f1e35c | 2215 | and then not (Is_Type (E) |
2216 | and then Is_Tagged_Type (E)) | |
2217 | then | |
05987af3 | 2218 | Error_Msg_N |
2219 | ("indexing aspect can only apply to a tagged type", | |
3f4c9ffc | 2220 | Aspect); |
89f1e35c | 2221 | goto Continue; |
2222 | end if; | |
2223 | ||
39616053 | 2224 | -- For the case of aspect Address, we don't consider that we |
588e7f97 | 2225 | -- know the entity is never set in the source, since it is |
2226 | -- is likely aliasing is occurring. | |
2227 | ||
2228 | -- Note: one might think that the analysis of the resulting | |
2229 | -- attribute definition clause would take care of that, but | |
2230 | -- that's not the case since it won't be from source. | |
2231 | ||
2232 | if A_Id = Aspect_Address then | |
2233 | Set_Never_Set_In_Source (E, False); | |
2234 | end if; | |
2235 | ||
5ac76cee | 2236 | -- Correctness of the profile of a stream operation is |
2237 | -- verified at the freeze point, but we must detect the | |
2238 | -- illegal specification of this aspect for a subtype now, | |
2239 | -- to prevent malformed rep_item chains. | |
2240 | ||
fbf4d6ef | 2241 | if A_Id = Aspect_Input or else |
2242 | A_Id = Aspect_Output or else | |
2243 | A_Id = Aspect_Read or else | |
2244 | A_Id = Aspect_Write | |
5ac76cee | 2245 | then |
fbf4d6ef | 2246 | if not Is_First_Subtype (E) then |
2247 | Error_Msg_N | |
2248 | ("local name must be a first subtype", Aspect); | |
2249 | goto Continue; | |
2250 | ||
2251 | -- If stream aspect applies to the class-wide type, | |
2252 | -- the generated attribute definition applies to the | |
2253 | -- class-wide type as well. | |
2254 | ||
2255 | elsif Class_Present (Aspect) then | |
2256 | Ent := | |
2257 | Make_Attribute_Reference (Loc, | |
2258 | Prefix => Ent, | |
2259 | Attribute_Name => Name_Class); | |
2260 | end if; | |
5ac76cee | 2261 | end if; |
2262 | ||
842e7c6b | 2263 | -- Construct the attribute_definition_clause. The expression |
2264 | -- in the aspect specification is simply shared with the | |
2265 | -- constructed attribute, because it will be fully analyzed | |
2266 | -- when the attribute is processed. However, in ASIS mode | |
2267 | -- the aspect expression itself is preanalyzed and resolved | |
2268 | -- to catch visibility errors that are otherwise caught | |
2269 | -- later, and we create a separate copy of the expression | |
2270 | -- to prevent analysis of a malformed tree (e.g. a function | |
2271 | -- call with parameter associations). | |
2272 | ||
2273 | if ASIS_Mode then | |
2274 | Aitem := | |
2275 | Make_Attribute_Definition_Clause (Loc, | |
2276 | Name => Ent, | |
2277 | Chars => Chars (Id), | |
2278 | Expression => New_Copy_Tree (Expr)); | |
2279 | else | |
2280 | Aitem := | |
2281 | Make_Attribute_Definition_Clause (Loc, | |
2282 | Name => Ent, | |
2283 | Chars => Chars (Id), | |
2284 | Expression => Relocate_Node (Expr)); | |
2285 | end if; | |
ae888dbd | 2286 | |
af9a0cc3 | 2287 | -- If the address is specified, then we treat the entity as |
41f06abf | 2288 | -- referenced, to avoid spurious warnings. This is analogous |
2289 | -- to what is done with an attribute definition clause, but | |
2290 | -- here we don't want to generate a reference because this | |
2291 | -- is the point of definition of the entity. | |
2292 | ||
2293 | if A_Id = Aspect_Address then | |
2294 | Set_Referenced (E); | |
2295 | end if; | |
2296 | ||
51ea9c94 | 2297 | -- Case 2: Aspects corresponding to pragmas |
d74fc39a | 2298 | |
89f1e35c | 2299 | -- Case 2a: Aspects corresponding to pragmas with two |
2300 | -- arguments, where the first argument is a local name | |
2301 | -- referring to the entity, and the second argument is the | |
2302 | -- aspect definition expression. | |
ae888dbd | 2303 | |
04ae062f | 2304 | -- Linker_Section/Suppress/Unsuppress |
0fd13d32 | 2305 | |
99378362 | 2306 | when Aspect_Linker_Section |
2307 | | Aspect_Suppress | |
2308 | | Aspect_Unsuppress | |
2309 | => | |
0fd13d32 | 2310 | Make_Aitem_Pragma |
2311 | (Pragma_Argument_Associations => New_List ( | |
2312 | Make_Pragma_Argument_Association (Loc, | |
2313 | Expression => New_Occurrence_Of (E, Loc)), | |
2314 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2315 | Expression => Relocate_Node (Expr))), | |
2316 | Pragma_Name => Chars (Id)); | |
57cd943b | 2317 | |
33dde36e | 2318 | -- Linker_Section does not need delaying, as its argument |
2319 | -- must be a static string. Furthermore, if applied to | |
2320 | -- an object with an explicit initialization, the object | |
2321 | -- must be frozen in order to elaborate the initialization | |
2322 | -- code. (This is already done for types with implicit | |
2323 | -- initialization, such as protected types.) | |
2324 | ||
2325 | if A_Id = Aspect_Linker_Section | |
2326 | and then Nkind (N) = N_Object_Declaration | |
2327 | and then Has_Init_Expression (N) | |
2328 | then | |
2329 | Delay_Required := False; | |
2330 | end if; | |
2331 | ||
0fd13d32 | 2332 | -- Synchronization |
d74fc39a | 2333 | |
0fd13d32 | 2334 | -- Corresponds to pragma Implemented, construct the pragma |
49213728 | 2335 | |
5bbfbad2 | 2336 | when Aspect_Synchronization => |
0fd13d32 | 2337 | Make_Aitem_Pragma |
2338 | (Pragma_Argument_Associations => New_List ( | |
2339 | Make_Pragma_Argument_Association (Loc, | |
2340 | Expression => New_Occurrence_Of (E, Loc)), | |
2341 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2342 | Expression => Relocate_Node (Expr))), | |
2343 | Pragma_Name => Name_Implemented); | |
49213728 | 2344 | |
e2bf777d | 2345 | -- Attach_Handler |
0fd13d32 | 2346 | |
89f1e35c | 2347 | when Aspect_Attach_Handler => |
0fd13d32 | 2348 | Make_Aitem_Pragma |
2349 | (Pragma_Argument_Associations => New_List ( | |
2350 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2351 | Expression => Ent), | |
2352 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2353 | Expression => Relocate_Node (Expr))), | |
2354 | Pragma_Name => Name_Attach_Handler); | |
2355 | ||
f67ed4f5 | 2356 | -- We need to insert this pragma into the tree to get proper |
2357 | -- processing and to look valid from a placement viewpoint. | |
2358 | ||
e2bf777d | 2359 | Insert_Pragma (Aitem); |
f67ed4f5 | 2360 | goto Continue; |
2361 | ||
0fd13d32 | 2362 | -- Dynamic_Predicate, Predicate, Static_Predicate |
89f1e35c | 2363 | |
99378362 | 2364 | when Aspect_Dynamic_Predicate |
2365 | | Aspect_Predicate | |
2366 | | Aspect_Static_Predicate | |
2367 | => | |
a47ce82d | 2368 | -- These aspects apply only to subtypes |
2369 | ||
2370 | if not Is_Type (E) then | |
2371 | Error_Msg_N | |
2372 | ("predicate can only be specified for a subtype", | |
2373 | Aspect); | |
2374 | goto Continue; | |
7c0c95b8 | 2375 | |
2376 | elsif Is_Incomplete_Type (E) then | |
2377 | Error_Msg_N | |
2378 | ("predicate cannot apply to incomplete view", Aspect); | |
4724c6b0 | 2379 | |
2380 | elsif Is_Generic_Type (E) then | |
2381 | Error_Msg_N | |
2382 | ("predicate cannot apply to formal type", Aspect); | |
7c0c95b8 | 2383 | goto Continue; |
a47ce82d | 2384 | end if; |
2385 | ||
89f1e35c | 2386 | -- Construct the pragma (always a pragma Predicate, with |
51ea9c94 | 2387 | -- flags recording whether it is static/dynamic). We also |
2388 | -- set flags recording this in the type itself. | |
89f1e35c | 2389 | |
0fd13d32 | 2390 | Make_Aitem_Pragma |
2391 | (Pragma_Argument_Associations => New_List ( | |
2392 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2393 | Expression => Ent), | |
2394 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2395 | Expression => Relocate_Node (Expr))), | |
fdec445e | 2396 | Pragma_Name => Name_Predicate); |
89f1e35c | 2397 | |
51ea9c94 | 2398 | -- Mark type has predicates, and remember what kind of |
2399 | -- aspect lead to this predicate (we need this to access | |
2400 | -- the right set of check policies later on). | |
2401 | ||
2402 | Set_Has_Predicates (E); | |
2403 | ||
2404 | if A_Id = Aspect_Dynamic_Predicate then | |
2405 | Set_Has_Dynamic_Predicate_Aspect (E); | |
0ec8f3e0 | 2406 | |
2407 | -- If the entity has a dynamic predicate, any inherited | |
2408 | -- static predicate becomes dynamic as well, and the | |
2409 | -- predicate function includes the conjunction of both. | |
2410 | ||
2411 | Set_Has_Static_Predicate_Aspect (E, False); | |
2412 | ||
51ea9c94 | 2413 | elsif A_Id = Aspect_Static_Predicate then |
2414 | Set_Has_Static_Predicate_Aspect (E); | |
2415 | end if; | |
2416 | ||
89f1e35c | 2417 | -- If the type is private, indicate that its completion |
6653b695 | 2418 | -- has a freeze node, because that is the one that will |
2419 | -- be visible at freeze time. | |
89f1e35c | 2420 | |
0fd13d32 | 2421 | if Is_Private_Type (E) and then Present (Full_View (E)) then |
89f1e35c | 2422 | Set_Has_Predicates (Full_View (E)); |
51ea9c94 | 2423 | |
2424 | if A_Id = Aspect_Dynamic_Predicate then | |
2425 | Set_Has_Dynamic_Predicate_Aspect (Full_View (E)); | |
2426 | elsif A_Id = Aspect_Static_Predicate then | |
2427 | Set_Has_Static_Predicate_Aspect (Full_View (E)); | |
2428 | end if; | |
2429 | ||
89f1e35c | 2430 | Set_Has_Delayed_Aspects (Full_View (E)); |
2431 | Ensure_Freeze_Node (Full_View (E)); | |
2432 | end if; | |
2433 | ||
fdec445e | 2434 | -- Predicate_Failure |
2435 | ||
2436 | when Aspect_Predicate_Failure => | |
2437 | ||
2438 | -- This aspect applies only to subtypes | |
2439 | ||
2440 | if not Is_Type (E) then | |
2441 | Error_Msg_N | |
2442 | ("predicate can only be specified for a subtype", | |
2443 | Aspect); | |
2444 | goto Continue; | |
2445 | ||
2446 | elsif Is_Incomplete_Type (E) then | |
2447 | Error_Msg_N | |
2448 | ("predicate cannot apply to incomplete view", Aspect); | |
2449 | goto Continue; | |
2450 | end if; | |
2451 | ||
2452 | -- Construct the pragma | |
2453 | ||
2454 | Make_Aitem_Pragma | |
2455 | (Pragma_Argument_Associations => New_List ( | |
2456 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2457 | Expression => Ent), | |
2458 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2459 | Expression => Relocate_Node (Expr))), | |
2460 | Pragma_Name => Name_Predicate_Failure); | |
2461 | ||
2462 | Set_Has_Predicates (E); | |
2463 | ||
2464 | -- If the type is private, indicate that its completion | |
2465 | -- has a freeze node, because that is the one that will | |
2466 | -- be visible at freeze time. | |
2467 | ||
2468 | if Is_Private_Type (E) and then Present (Full_View (E)) then | |
2469 | Set_Has_Predicates (Full_View (E)); | |
2470 | Set_Has_Delayed_Aspects (Full_View (E)); | |
2471 | Ensure_Freeze_Node (Full_View (E)); | |
2472 | end if; | |
2473 | ||
89f1e35c | 2474 | -- Case 2b: Aspects corresponding to pragmas with two |
2475 | -- arguments, where the second argument is a local name | |
2476 | -- referring to the entity, and the first argument is the | |
2477 | -- aspect definition expression. | |
ae888dbd | 2478 | |
0fd13d32 | 2479 | -- Convention |
2480 | ||
ee2b7923 | 2481 | when Aspect_Convention => |
2482 | Analyze_Aspect_Convention; | |
2483 | goto Continue; | |
97bf66e6 | 2484 | |
ee2b7923 | 2485 | -- External_Name, Link_Name |
97bf66e6 | 2486 | |
99378362 | 2487 | when Aspect_External_Name |
2488 | | Aspect_Link_Name | |
2489 | => | |
ee2b7923 | 2490 | Analyze_Aspect_External_Link_Name; |
2491 | goto Continue; | |
e1cedbae | 2492 | |
0fd13d32 | 2493 | -- CPU, Interrupt_Priority, Priority |
2494 | ||
d6814978 | 2495 | -- These three aspects can be specified for a subprogram spec |
2496 | -- or body, in which case we analyze the expression and export | |
2497 | -- the value of the aspect. | |
2498 | ||
2499 | -- Previously, we generated an equivalent pragma for bodies | |
2500 | -- (note that the specs cannot contain these pragmas). The | |
2501 | -- pragma was inserted ahead of local declarations, rather than | |
2502 | -- after the body. This leads to a certain duplication between | |
2503 | -- the processing performed for the aspect and the pragma, but | |
2504 | -- given the straightforward handling required it is simpler | |
2505 | -- to duplicate than to translate the aspect in the spec into | |
2506 | -- a pragma in the declarative part of the body. | |
3a72f9c3 | 2507 | |
99378362 | 2508 | when Aspect_CPU |
2509 | | Aspect_Interrupt_Priority | |
2510 | | Aspect_Priority | |
2511 | => | |
d6814978 | 2512 | if Nkind_In (N, N_Subprogram_Body, |
2513 | N_Subprogram_Declaration) | |
2514 | then | |
2515 | -- Analyze the aspect expression | |
2516 | ||
2517 | Analyze_And_Resolve (Expr, Standard_Integer); | |
2518 | ||
2519 | -- Interrupt_Priority aspect not allowed for main | |
078a74b8 | 2520 | -- subprograms. RM D.1 does not forbid this explicitly, |
2521 | -- but RM J.15.11(6/3) does not permit pragma | |
d6814978 | 2522 | -- Interrupt_Priority for subprograms. |
2523 | ||
2524 | if A_Id = Aspect_Interrupt_Priority then | |
2525 | Error_Msg_N | |
2526 | ("Interrupt_Priority aspect cannot apply to " | |
2527 | & "subprogram", Expr); | |
2528 | ||
2529 | -- The expression must be static | |
2530 | ||
cda40848 | 2531 | elsif not Is_OK_Static_Expression (Expr) then |
d6814978 | 2532 | Flag_Non_Static_Expr |
2533 | ("aspect requires static expression!", Expr); | |
2534 | ||
24d7b9d6 | 2535 | -- Check whether this is the main subprogram. Issue a |
2536 | -- warning only if it is obviously not a main program | |
2537 | -- (when it has parameters or when the subprogram is | |
2538 | -- within a package). | |
2539 | ||
2540 | elsif Present (Parameter_Specifications | |
2541 | (Specification (N))) | |
2542 | or else not Is_Compilation_Unit (Defining_Entity (N)) | |
d6814978 | 2543 | then |
078a74b8 | 2544 | -- See RM D.1(14/3) and D.16(12/3) |
d6814978 | 2545 | |
2546 | Error_Msg_N | |
2547 | ("aspect applied to subprogram other than the " | |
2548 | & "main subprogram has no effect??", Expr); | |
2549 | ||
2550 | -- Otherwise check in range and export the value | |
2551 | ||
2552 | -- For the CPU aspect | |
2553 | ||
2554 | elsif A_Id = Aspect_CPU then | |
2555 | if Is_In_Range (Expr, RTE (RE_CPU_Range)) then | |
2556 | ||
2557 | -- Value is correct so we export the value to make | |
2558 | -- it available at execution time. | |
2559 | ||
2560 | Set_Main_CPU | |
2561 | (Main_Unit, UI_To_Int (Expr_Value (Expr))); | |
2562 | ||
2563 | else | |
2564 | Error_Msg_N | |
2565 | ("main subprogram CPU is out of range", Expr); | |
2566 | end if; | |
2567 | ||
2568 | -- For the Priority aspect | |
2569 | ||
2570 | elsif A_Id = Aspect_Priority then | |
2571 | if Is_In_Range (Expr, RTE (RE_Priority)) then | |
2572 | ||
2573 | -- Value is correct so we export the value to make | |
2574 | -- it available at execution time. | |
2575 | ||
2576 | Set_Main_Priority | |
2577 | (Main_Unit, UI_To_Int (Expr_Value (Expr))); | |
2578 | ||
32572384 | 2579 | -- Ignore pragma if Relaxed_RM_Semantics to support |
2580 | -- other targets/non GNAT compilers. | |
2581 | ||
2582 | elsif not Relaxed_RM_Semantics then | |
d6814978 | 2583 | Error_Msg_N |
2584 | ("main subprogram priority is out of range", | |
2585 | Expr); | |
2586 | end if; | |
2587 | end if; | |
2588 | ||
2589 | -- Load an arbitrary entity from System.Tasking.Stages | |
2590 | -- or System.Tasking.Restricted.Stages (depending on | |
2591 | -- the supported profile) to make sure that one of these | |
2592 | -- packages is implicitly with'ed, since we need to have | |
2593 | -- the tasking run time active for the pragma Priority to | |
a0c3eeb9 | 2594 | -- have any effect. Previously we with'ed the package |
d6814978 | 2595 | -- System.Tasking, but this package does not trigger the |
2596 | -- required initialization of the run-time library. | |
2597 | ||
2598 | declare | |
2599 | Discard : Entity_Id; | |
d6814978 | 2600 | begin |
2601 | if Restricted_Profile then | |
2602 | Discard := RTE (RE_Activate_Restricted_Tasks); | |
2603 | else | |
2604 | Discard := RTE (RE_Activate_Tasks); | |
2605 | end if; | |
2606 | end; | |
2607 | ||
e6ce0468 | 2608 | -- Handling for these aspects in subprograms is complete |
d6814978 | 2609 | |
2610 | goto Continue; | |
2611 | ||
fa65ad5e | 2612 | -- For task and protected types pass the aspect as an |
2613 | -- attribute. | |
0fd13d32 | 2614 | |
3a72f9c3 | 2615 | else |
2616 | Aitem := | |
2617 | Make_Attribute_Definition_Clause (Loc, | |
2618 | Name => Ent, | |
2619 | Chars => Chars (Id), | |
2620 | Expression => Relocate_Node (Expr)); | |
2621 | end if; | |
2622 | ||
0fd13d32 | 2623 | -- Warnings |
2624 | ||
ae888dbd | 2625 | when Aspect_Warnings => |
0fd13d32 | 2626 | Make_Aitem_Pragma |
2627 | (Pragma_Argument_Associations => New_List ( | |
2628 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2629 | Expression => Relocate_Node (Expr)), | |
2630 | Make_Pragma_Argument_Association (Loc, | |
2631 | Expression => New_Occurrence_Of (E, Loc))), | |
2632 | Pragma_Name => Chars (Id)); | |
ae888dbd | 2633 | |
2f06c88a | 2634 | Decorate (Aspect, Aitem); |
2635 | Insert_Pragma (Aitem); | |
2636 | goto Continue; | |
2637 | ||
89f1e35c | 2638 | -- Case 2c: Aspects corresponding to pragmas with three |
2639 | -- arguments. | |
d64221a7 | 2640 | |
89f1e35c | 2641 | -- Invariant aspects have a first argument that references the |
2642 | -- entity, a second argument that is the expression and a third | |
2643 | -- argument that is an appropriate message. | |
d64221a7 | 2644 | |
0fd13d32 | 2645 | -- Invariant, Type_Invariant |
2646 | ||
99378362 | 2647 | when Aspect_Invariant |
2648 | | Aspect_Type_Invariant | |
2649 | => | |
89f1e35c | 2650 | -- Analysis of the pragma will verify placement legality: |
2651 | -- an invariant must apply to a private type, or appear in | |
2652 | -- the private part of a spec and apply to a completion. | |
d64221a7 | 2653 | |
0fd13d32 | 2654 | Make_Aitem_Pragma |
2655 | (Pragma_Argument_Associations => New_List ( | |
2656 | Make_Pragma_Argument_Association (Sloc (Ent), | |
2657 | Expression => Ent), | |
2658 | Make_Pragma_Argument_Association (Sloc (Expr), | |
2659 | Expression => Relocate_Node (Expr))), | |
2660 | Pragma_Name => Name_Invariant); | |
89f1e35c | 2661 | |
2662 | -- Add message unless exception messages are suppressed | |
2663 | ||
2664 | if not Opt.Exception_Locations_Suppressed then | |
2665 | Append_To (Pragma_Argument_Associations (Aitem), | |
2666 | Make_Pragma_Argument_Association (Eloc, | |
2667 | Chars => Name_Message, | |
2668 | Expression => | |
2669 | Make_String_Literal (Eloc, | |
2670 | Strval => "failed invariant from " | |
2671 | & Build_Location_String (Eloc)))); | |
d64221a7 | 2672 | end if; |
2673 | ||
89f1e35c | 2674 | -- For Invariant case, insert immediately after the entity |
2675 | -- declaration. We do not have to worry about delay issues | |
2676 | -- since the pragma processing takes care of this. | |
2677 | ||
89f1e35c | 2678 | Delay_Required := False; |
d64221a7 | 2679 | |
47a46747 | 2680 | -- Case 2d : Aspects that correspond to a pragma with one |
2681 | -- argument. | |
2682 | ||
0fd13d32 | 2683 | -- Abstract_State |
115f7b08 | 2684 | |
d4e369ad | 2685 | -- Aspect Abstract_State introduces implicit declarations for |
2686 | -- all state abstraction entities it defines. To emulate this | |
2687 | -- behavior, insert the pragma at the beginning of the visible | |
2688 | -- declarations of the related package so that it is analyzed | |
2689 | -- immediately. | |
2690 | ||
9129c28f | 2691 | when Aspect_Abstract_State => Abstract_State : declare |
eb4f7efa | 2692 | Context : Node_Id := N; |
9129c28f | 2693 | |
2694 | begin | |
eb4f7efa | 2695 | -- When aspect Abstract_State appears on a generic package, |
2696 | -- it is propageted to the package instance. The context in | |
2697 | -- this case is the instance spec. | |
2698 | ||
2699 | if Nkind (Context) = N_Package_Instantiation then | |
2700 | Context := Instance_Spec (Context); | |
2701 | end if; | |
2702 | ||
2703 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2704 | N_Package_Declaration) | |
9129c28f | 2705 | then |
9129c28f | 2706 | Make_Aitem_Pragma |
2707 | (Pragma_Argument_Associations => New_List ( | |
2708 | Make_Pragma_Argument_Association (Loc, | |
2709 | Expression => Relocate_Node (Expr))), | |
2710 | Pragma_Name => Name_Abstract_State); | |
630b6d55 | 2711 | |
5655be8a | 2712 | Decorate (Aspect, Aitem); |
2713 | Insert_Pragma | |
2714 | (Prag => Aitem, | |
2715 | Is_Instance => | |
2716 | Is_Generic_Instance (Defining_Entity (Context))); | |
9129c28f | 2717 | |
2718 | else | |
2719 | Error_Msg_NE | |
2720 | ("aspect & must apply to a package declaration", | |
2721 | Aspect, Id); | |
2722 | end if; | |
2723 | ||
2724 | goto Continue; | |
2725 | end Abstract_State; | |
115f7b08 | 2726 | |
85ee12c0 | 2727 | -- Aspect Async_Readers is never delayed because it is |
2728 | -- equivalent to a source pragma which appears after the | |
2729 | -- related object declaration. | |
2730 | ||
2731 | when Aspect_Async_Readers => | |
2732 | Make_Aitem_Pragma | |
2733 | (Pragma_Argument_Associations => New_List ( | |
2734 | Make_Pragma_Argument_Association (Loc, | |
2735 | Expression => Relocate_Node (Expr))), | |
2736 | Pragma_Name => Name_Async_Readers); | |
2737 | ||
2738 | Decorate (Aspect, Aitem); | |
2739 | Insert_Pragma (Aitem); | |
2740 | goto Continue; | |
2741 | ||
2742 | -- Aspect Async_Writers is never delayed because it is | |
2743 | -- equivalent to a source pragma which appears after the | |
2744 | -- related object declaration. | |
2745 | ||
2746 | when Aspect_Async_Writers => | |
2747 | Make_Aitem_Pragma | |
2748 | (Pragma_Argument_Associations => New_List ( | |
2749 | Make_Pragma_Argument_Association (Loc, | |
2750 | Expression => Relocate_Node (Expr))), | |
2751 | Pragma_Name => Name_Async_Writers); | |
2752 | ||
2753 | Decorate (Aspect, Aitem); | |
2754 | Insert_Pragma (Aitem); | |
2755 | goto Continue; | |
2756 | ||
d0849c23 | 2757 | -- Aspect Constant_After_Elaboration is never delayed because |
2758 | -- it is equivalent to a source pragma which appears after the | |
2759 | -- related object declaration. | |
2760 | ||
2761 | when Aspect_Constant_After_Elaboration => | |
2762 | Make_Aitem_Pragma | |
2763 | (Pragma_Argument_Associations => New_List ( | |
2764 | Make_Pragma_Argument_Association (Loc, | |
2765 | Expression => Relocate_Node (Expr))), | |
2766 | Pragma_Name => | |
2767 | Name_Constant_After_Elaboration); | |
2768 | ||
2769 | Decorate (Aspect, Aitem); | |
2770 | Insert_Pragma (Aitem); | |
2771 | goto Continue; | |
2772 | ||
ec6f6da5 | 2773 | -- Aspect Default_Internal_Condition is never delayed because |
2774 | -- it is equivalent to a source pragma which appears after the | |
2775 | -- related private type. To deal with forward references, the | |
2776 | -- generated pragma is stored in the rep chain of the related | |
2777 | -- private type as types do not carry contracts. The pragma is | |
2778 | -- wrapped inside of a procedure at the freeze point of the | |
2779 | -- private type's full view. | |
2780 | ||
2781 | when Aspect_Default_Initial_Condition => | |
2782 | Make_Aitem_Pragma | |
2783 | (Pragma_Argument_Associations => New_List ( | |
2784 | Make_Pragma_Argument_Association (Loc, | |
2785 | Expression => Relocate_Node (Expr))), | |
2786 | Pragma_Name => | |
2787 | Name_Default_Initial_Condition); | |
2788 | ||
2789 | Decorate (Aspect, Aitem); | |
2790 | Insert_Pragma (Aitem); | |
2791 | goto Continue; | |
2792 | ||
647fab54 | 2793 | -- Default_Storage_Pool |
2794 | ||
2795 | when Aspect_Default_Storage_Pool => | |
2796 | Make_Aitem_Pragma | |
2797 | (Pragma_Argument_Associations => New_List ( | |
2798 | Make_Pragma_Argument_Association (Loc, | |
2799 | Expression => Relocate_Node (Expr))), | |
2800 | Pragma_Name => | |
2801 | Name_Default_Storage_Pool); | |
2802 | ||
2803 | Decorate (Aspect, Aitem); | |
2804 | Insert_Pragma (Aitem); | |
2805 | goto Continue; | |
2806 | ||
0fd13d32 | 2807 | -- Depends |
2808 | ||
e2bf777d | 2809 | -- Aspect Depends is never delayed because it is equivalent to |
2810 | -- a source pragma which appears after the related subprogram. | |
2811 | -- To deal with forward references, the generated pragma is | |
2812 | -- stored in the contract of the related subprogram and later | |
2813 | -- analyzed at the end of the declarative region. See routine | |
2814 | -- Analyze_Depends_In_Decl_Part for details. | |
6144c105 | 2815 | |
12334c57 | 2816 | when Aspect_Depends => |
0fd13d32 | 2817 | Make_Aitem_Pragma |
2818 | (Pragma_Argument_Associations => New_List ( | |
2819 | Make_Pragma_Argument_Association (Loc, | |
2820 | Expression => Relocate_Node (Expr))), | |
2821 | Pragma_Name => Name_Depends); | |
2822 | ||
e2bf777d | 2823 | Decorate (Aspect, Aitem); |
2824 | Insert_Pragma (Aitem); | |
c1006d6d | 2825 | goto Continue; |
2826 | ||
adb8ac81 | 2827 | -- Aspect Effective_Reads is never delayed because it is |
85ee12c0 | 2828 | -- equivalent to a source pragma which appears after the |
2829 | -- related object declaration. | |
2830 | ||
2831 | when Aspect_Effective_Reads => | |
2832 | Make_Aitem_Pragma | |
2833 | (Pragma_Argument_Associations => New_List ( | |
2834 | Make_Pragma_Argument_Association (Loc, | |
2835 | Expression => Relocate_Node (Expr))), | |
2836 | Pragma_Name => Name_Effective_Reads); | |
2837 | ||
2838 | Decorate (Aspect, Aitem); | |
2839 | Insert_Pragma (Aitem); | |
2840 | goto Continue; | |
2841 | ||
2842 | -- Aspect Effective_Writes is never delayed because it is | |
2843 | -- equivalent to a source pragma which appears after the | |
2844 | -- related object declaration. | |
2845 | ||
2846 | when Aspect_Effective_Writes => | |
2847 | Make_Aitem_Pragma | |
2848 | (Pragma_Argument_Associations => New_List ( | |
2849 | Make_Pragma_Argument_Association (Loc, | |
2850 | Expression => Relocate_Node (Expr))), | |
2851 | Pragma_Name => Name_Effective_Writes); | |
2852 | ||
2853 | Decorate (Aspect, Aitem); | |
2854 | Insert_Pragma (Aitem); | |
2855 | goto Continue; | |
2856 | ||
cab27d2a | 2857 | -- Aspect Extensions_Visible is never delayed because it is |
2858 | -- equivalent to a source pragma which appears after the | |
2859 | -- related subprogram. | |
2860 | ||
2861 | when Aspect_Extensions_Visible => | |
2862 | Make_Aitem_Pragma | |
2863 | (Pragma_Argument_Associations => New_List ( | |
2864 | Make_Pragma_Argument_Association (Loc, | |
2865 | Expression => Relocate_Node (Expr))), | |
2866 | Pragma_Name => Name_Extensions_Visible); | |
2867 | ||
2868 | Decorate (Aspect, Aitem); | |
2869 | Insert_Pragma (Aitem); | |
2870 | goto Continue; | |
2871 | ||
3dbe7a69 | 2872 | -- Aspect Ghost is never delayed because it is equivalent to a |
2873 | -- source pragma which appears at the top of [generic] package | |
2874 | -- declarations or after an object, a [generic] subprogram, or | |
2875 | -- a type declaration. | |
2876 | ||
5655be8a | 2877 | when Aspect_Ghost => |
3dbe7a69 | 2878 | Make_Aitem_Pragma |
2879 | (Pragma_Argument_Associations => New_List ( | |
2880 | Make_Pragma_Argument_Association (Loc, | |
2881 | Expression => Relocate_Node (Expr))), | |
2882 | Pragma_Name => Name_Ghost); | |
2883 | ||
2884 | Decorate (Aspect, Aitem); | |
5655be8a | 2885 | Insert_Pragma (Aitem); |
3dbe7a69 | 2886 | goto Continue; |
3dbe7a69 | 2887 | |
0fd13d32 | 2888 | -- Global |
12334c57 | 2889 | |
e2bf777d | 2890 | -- Aspect Global is never delayed because it is equivalent to |
2891 | -- a source pragma which appears after the related subprogram. | |
2892 | -- To deal with forward references, the generated pragma is | |
2893 | -- stored in the contract of the related subprogram and later | |
2894 | -- analyzed at the end of the declarative region. See routine | |
2895 | -- Analyze_Global_In_Decl_Part for details. | |
3cdbaa5a | 2896 | |
2897 | when Aspect_Global => | |
0fd13d32 | 2898 | Make_Aitem_Pragma |
2899 | (Pragma_Argument_Associations => New_List ( | |
2900 | Make_Pragma_Argument_Association (Loc, | |
2901 | Expression => Relocate_Node (Expr))), | |
2902 | Pragma_Name => Name_Global); | |
2903 | ||
e2bf777d | 2904 | Decorate (Aspect, Aitem); |
2905 | Insert_Pragma (Aitem); | |
c1006d6d | 2906 | goto Continue; |
2907 | ||
9c138530 | 2908 | -- Initial_Condition |
2909 | ||
e2bf777d | 2910 | -- Aspect Initial_Condition is never delayed because it is |
2911 | -- equivalent to a source pragma which appears after the | |
2912 | -- related package. To deal with forward references, the | |
2913 | -- generated pragma is stored in the contract of the related | |
2914 | -- package and later analyzed at the end of the declarative | |
2915 | -- region. See routine Analyze_Initial_Condition_In_Decl_Part | |
2916 | -- for details. | |
9c138530 | 2917 | |
2918 | when Aspect_Initial_Condition => Initial_Condition : declare | |
eb4f7efa | 2919 | Context : Node_Id := N; |
9c138530 | 2920 | |
2921 | begin | |
e2bf777d | 2922 | -- When aspect Initial_Condition appears on a generic |
2923 | -- package, it is propageted to the package instance. The | |
2924 | -- context in this case is the instance spec. | |
eb4f7efa | 2925 | |
2926 | if Nkind (Context) = N_Package_Instantiation then | |
2927 | Context := Instance_Spec (Context); | |
2928 | end if; | |
2929 | ||
2930 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2931 | N_Package_Declaration) | |
9c138530 | 2932 | then |
9c138530 | 2933 | Make_Aitem_Pragma |
2934 | (Pragma_Argument_Associations => New_List ( | |
2935 | Make_Pragma_Argument_Association (Loc, | |
2936 | Expression => Relocate_Node (Expr))), | |
2937 | Pragma_Name => | |
2938 | Name_Initial_Condition); | |
9c138530 | 2939 | |
5655be8a | 2940 | Decorate (Aspect, Aitem); |
2941 | Insert_Pragma | |
2942 | (Prag => Aitem, | |
2943 | Is_Instance => | |
2944 | Is_Generic_Instance (Defining_Entity (Context))); | |
50e44732 | 2945 | |
5655be8a | 2946 | -- Otherwise the context is illegal |
9c138530 | 2947 | |
2948 | else | |
2949 | Error_Msg_NE | |
2950 | ("aspect & must apply to a package declaration", | |
2951 | Aspect, Id); | |
2952 | end if; | |
2953 | ||
2954 | goto Continue; | |
2955 | end Initial_Condition; | |
2956 | ||
d4e369ad | 2957 | -- Initializes |
2958 | ||
e2bf777d | 2959 | -- Aspect Initializes is never delayed because it is equivalent |
2960 | -- to a source pragma appearing after the related package. To | |
2961 | -- deal with forward references, the generated pragma is stored | |
2962 | -- in the contract of the related package and later analyzed at | |
2963 | -- the end of the declarative region. For details, see routine | |
2964 | -- Analyze_Initializes_In_Decl_Part. | |
d4e369ad | 2965 | |
2966 | when Aspect_Initializes => Initializes : declare | |
eb4f7efa | 2967 | Context : Node_Id := N; |
d4e369ad | 2968 | |
2969 | begin | |
50e44732 | 2970 | -- When aspect Initializes appears on a generic package, |
2971 | -- it is propageted to the package instance. The context | |
2972 | -- in this case is the instance spec. | |
eb4f7efa | 2973 | |
2974 | if Nkind (Context) = N_Package_Instantiation then | |
2975 | Context := Instance_Spec (Context); | |
2976 | end if; | |
2977 | ||
2978 | if Nkind_In (Context, N_Generic_Package_Declaration, | |
2979 | N_Package_Declaration) | |
d4e369ad | 2980 | then |
d4e369ad | 2981 | Make_Aitem_Pragma |
2982 | (Pragma_Argument_Associations => New_List ( | |
2983 | Make_Pragma_Argument_Association (Loc, | |
2984 | Expression => Relocate_Node (Expr))), | |
2985 | Pragma_Name => Name_Initializes); | |
d4e369ad | 2986 | |
5655be8a | 2987 | Decorate (Aspect, Aitem); |
2988 | Insert_Pragma | |
2989 | (Prag => Aitem, | |
2990 | Is_Instance => | |
2991 | Is_Generic_Instance (Defining_Entity (Context))); | |
50e44732 | 2992 | |
5655be8a | 2993 | -- Otherwise the context is illegal |
d4e369ad | 2994 | |
2995 | else | |
2996 | Error_Msg_NE | |
2997 | ("aspect & must apply to a package declaration", | |
2998 | Aspect, Id); | |
2999 | end if; | |
3000 | ||
3001 | goto Continue; | |
3002 | end Initializes; | |
3003 | ||
ebf6f618 | 3004 | -- Max_Entry_Queue_Depth |
3005 | ||
3006 | when Aspect_Max_Entry_Queue_Depth => | |
3007 | Make_Aitem_Pragma | |
3008 | (Pragma_Argument_Associations => New_List ( | |
3009 | Make_Pragma_Argument_Association (Loc, | |
3010 | Expression => Relocate_Node (Expr))), | |
3011 | Pragma_Name => Name_Max_Entry_Queue_Depth); | |
3012 | ||
3013 | Decorate (Aspect, Aitem); | |
3014 | Insert_Pragma (Aitem); | |
3015 | goto Continue; | |
3016 | ||
da558db0 | 3017 | -- Max_Entry_Queue_Length |
3018 | ||
3019 | when Aspect_Max_Entry_Queue_Length => | |
3020 | Make_Aitem_Pragma | |
3021 | (Pragma_Argument_Associations => New_List ( | |
3022 | Make_Pragma_Argument_Association (Loc, | |
3023 | Expression => Relocate_Node (Expr))), | |
3024 | Pragma_Name => Name_Max_Entry_Queue_Length); | |
3025 | ||
3026 | Decorate (Aspect, Aitem); | |
3027 | Insert_Pragma (Aitem); | |
3028 | goto Continue; | |
3029 | ||
cbd45084 | 3030 | -- Max_Queue_Length |
3031 | ||
3032 | when Aspect_Max_Queue_Length => | |
3033 | Make_Aitem_Pragma | |
3034 | (Pragma_Argument_Associations => New_List ( | |
3035 | Make_Pragma_Argument_Association (Loc, | |
3036 | Expression => Relocate_Node (Expr))), | |
3037 | Pragma_Name => Name_Max_Queue_Length); | |
3038 | ||
3039 | Decorate (Aspect, Aitem); | |
3040 | Insert_Pragma (Aitem); | |
3041 | goto Continue; | |
3042 | ||
adb8ac81 | 3043 | -- Aspect No_Caching is never delayed because it is equivalent |
3044 | -- to a source pragma which appears after the related object | |
3045 | -- declaration. | |
3046 | ||
3047 | when Aspect_No_Caching => | |
3048 | Make_Aitem_Pragma | |
3049 | (Pragma_Argument_Associations => New_List ( | |
3050 | Make_Pragma_Argument_Association (Loc, | |
3051 | Expression => Relocate_Node (Expr))), | |
3052 | Pragma_Name => Name_No_Caching); | |
3053 | ||
3054 | Decorate (Aspect, Aitem); | |
3055 | Insert_Pragma (Aitem); | |
3056 | goto Continue; | |
3057 | ||
1fd4313f | 3058 | -- Obsolescent |
3059 | ||
3060 | when Aspect_Obsolescent => declare | |
3061 | Args : List_Id; | |
3062 | ||
3063 | begin | |
3064 | if No (Expr) then | |
3065 | Args := No_List; | |
3066 | else | |
3067 | Args := New_List ( | |
3068 | Make_Pragma_Argument_Association (Sloc (Expr), | |
3069 | Expression => Relocate_Node (Expr))); | |
3070 | end if; | |
3071 | ||
3072 | Make_Aitem_Pragma | |
3073 | (Pragma_Argument_Associations => Args, | |
3074 | Pragma_Name => Chars (Id)); | |
3075 | end; | |
3076 | ||
5cc6f0cf | 3077 | -- Part_Of |
3078 | ||
3079 | when Aspect_Part_Of => | |
3080 | if Nkind_In (N, N_Object_Declaration, | |
3081 | N_Package_Instantiation) | |
736b80cc | 3082 | or else Is_Single_Concurrent_Type_Declaration (N) |
5cc6f0cf | 3083 | then |
3084 | Make_Aitem_Pragma | |
3085 | (Pragma_Argument_Associations => New_List ( | |
3086 | Make_Pragma_Argument_Association (Loc, | |
3087 | Expression => Relocate_Node (Expr))), | |
3088 | Pragma_Name => Name_Part_Of); | |
3089 | ||
736b80cc | 3090 | Decorate (Aspect, Aitem); |
3091 | Insert_Pragma (Aitem); | |
736b80cc | 3092 | |
5cc6f0cf | 3093 | else |
3094 | Error_Msg_NE | |
736b80cc | 3095 | ("aspect & must apply to package instantiation, " |
3096 | & "object, single protected type or single task type", | |
3097 | Aspect, Id); | |
5cc6f0cf | 3098 | end if; |
3099 | ||
d5c65b80 | 3100 | goto Continue; |
3101 | ||
5dd93a61 | 3102 | -- SPARK_Mode |
3103 | ||
2f06c88a | 3104 | when Aspect_SPARK_Mode => |
5dd93a61 | 3105 | Make_Aitem_Pragma |
3106 | (Pragma_Argument_Associations => New_List ( | |
3107 | Make_Pragma_Argument_Association (Loc, | |
3108 | Expression => Relocate_Node (Expr))), | |
3109 | Pragma_Name => Name_SPARK_Mode); | |
5dd93a61 | 3110 | |
2f06c88a | 3111 | Decorate (Aspect, Aitem); |
3112 | Insert_Pragma (Aitem); | |
3113 | goto Continue; | |
778ebf56 | 3114 | |
4befb1a0 | 3115 | -- Refined_Depends |
3116 | ||
e2bf777d | 3117 | -- Aspect Refined_Depends is never delayed because it is |
3118 | -- equivalent to a source pragma which appears in the | |
3119 | -- declarations of the related subprogram body. To deal with | |
3120 | -- forward references, the generated pragma is stored in the | |
3121 | -- contract of the related subprogram body and later analyzed | |
3122 | -- at the end of the declarative region. For details, see | |
3123 | -- routine Analyze_Refined_Depends_In_Decl_Part. | |
4befb1a0 | 3124 | |
3125 | when Aspect_Refined_Depends => | |
422073ed | 3126 | Make_Aitem_Pragma |
3127 | (Pragma_Argument_Associations => New_List ( | |
3128 | Make_Pragma_Argument_Association (Loc, | |
3129 | Expression => Relocate_Node (Expr))), | |
3130 | Pragma_Name => Name_Refined_Depends); | |
3131 | ||
e2bf777d | 3132 | Decorate (Aspect, Aitem); |
3133 | Insert_Pragma (Aitem); | |
422073ed | 3134 | goto Continue; |
4befb1a0 | 3135 | |
3136 | -- Refined_Global | |
3137 | ||
e2bf777d | 3138 | -- Aspect Refined_Global is never delayed because it is |
3139 | -- equivalent to a source pragma which appears in the | |
3140 | -- declarations of the related subprogram body. To deal with | |
3141 | -- forward references, the generated pragma is stored in the | |
3142 | -- contract of the related subprogram body and later analyzed | |
3143 | -- at the end of the declarative region. For details, see | |
3144 | -- routine Analyze_Refined_Global_In_Decl_Part. | |
4befb1a0 | 3145 | |
3146 | when Aspect_Refined_Global => | |
28ff117f | 3147 | Make_Aitem_Pragma |
3148 | (Pragma_Argument_Associations => New_List ( | |
3149 | Make_Pragma_Argument_Association (Loc, | |
3150 | Expression => Relocate_Node (Expr))), | |
3151 | Pragma_Name => Name_Refined_Global); | |
3152 | ||
e2bf777d | 3153 | Decorate (Aspect, Aitem); |
3154 | Insert_Pragma (Aitem); | |
28ff117f | 3155 | goto Continue; |
4befb1a0 | 3156 | |
63b65b2d | 3157 | -- Refined_Post |
3158 | ||
3159 | when Aspect_Refined_Post => | |
3160 | Make_Aitem_Pragma | |
3161 | (Pragma_Argument_Associations => New_List ( | |
3162 | Make_Pragma_Argument_Association (Loc, | |
3163 | Expression => Relocate_Node (Expr))), | |
3164 | Pragma_Name => Name_Refined_Post); | |
3165 | ||
3ff5e35d | 3166 | Decorate (Aspect, Aitem); |
3167 | Insert_Pragma (Aitem); | |
3168 | goto Continue; | |
3169 | ||
9129c28f | 3170 | -- Refined_State |
3171 | ||
5655be8a | 3172 | when Aspect_Refined_State => |
9129c28f | 3173 | |
9129c28f | 3174 | -- The corresponding pragma for Refined_State is inserted in |
3175 | -- the declarations of the related package body. This action | |
3176 | -- synchronizes both the source and from-aspect versions of | |
3177 | -- the pragma. | |
3178 | ||
3179 | if Nkind (N) = N_Package_Body then | |
9129c28f | 3180 | Make_Aitem_Pragma |
3181 | (Pragma_Argument_Associations => New_List ( | |
3182 | Make_Pragma_Argument_Association (Loc, | |
3183 | Expression => Relocate_Node (Expr))), | |
3184 | Pragma_Name => Name_Refined_State); | |
b9b2d6e5 | 3185 | |
5655be8a | 3186 | Decorate (Aspect, Aitem); |
3187 | Insert_Pragma (Aitem); | |
b9b2d6e5 | 3188 | |
5655be8a | 3189 | -- Otherwise the context is illegal |
9129c28f | 3190 | |
3191 | else | |
3192 | Error_Msg_NE | |
3193 | ("aspect & must apply to a package body", Aspect, Id); | |
3194 | end if; | |
3195 | ||
3196 | goto Continue; | |
9129c28f | 3197 | |
0fd13d32 | 3198 | -- Relative_Deadline |
3cdbaa5a | 3199 | |
3200 | when Aspect_Relative_Deadline => | |
0fd13d32 | 3201 | Make_Aitem_Pragma |
3202 | (Pragma_Argument_Associations => New_List ( | |
3203 | Make_Pragma_Argument_Association (Loc, | |
3204 | Expression => Relocate_Node (Expr))), | |
3205 | Pragma_Name => Name_Relative_Deadline); | |
47a46747 | 3206 | |
3207 | -- If the aspect applies to a task, the corresponding pragma | |
3208 | -- must appear within its declarations, not after. | |
3209 | ||
3210 | if Nkind (N) = N_Task_Type_Declaration then | |
3211 | declare | |
3212 | Def : Node_Id; | |
3213 | V : List_Id; | |
3214 | ||
3215 | begin | |
3216 | if No (Task_Definition (N)) then | |
3217 | Set_Task_Definition (N, | |
3218 | Make_Task_Definition (Loc, | |
3219 | Visible_Declarations => New_List, | |
3220 | End_Label => Empty)); | |
3221 | end if; | |
3222 | ||
3223 | Def := Task_Definition (N); | |
3224 | V := Visible_Declarations (Def); | |
3225 | if not Is_Empty_List (V) then | |
3226 | Insert_Before (First (V), Aitem); | |
3227 | ||
3228 | else | |
3229 | Set_Visible_Declarations (Def, New_List (Aitem)); | |
3230 | end if; | |
3231 | ||
3232 | goto Continue; | |
3233 | end; | |
3234 | end if; | |
3235 | ||
24b3ea8f | 3236 | -- Secondary_Stack_Size |
3237 | ||
3238 | -- Aspect Secondary_Stack_Size needs to be converted into a | |
3239 | -- pragma for two reasons: the attribute is not analyzed until | |
3240 | -- after the expansion of the task type declaration and the | |
3241 | -- attribute does not have visibility on the discriminant. | |
3242 | ||
3243 | when Aspect_Secondary_Stack_Size => | |
3244 | Make_Aitem_Pragma | |
3245 | (Pragma_Argument_Associations => New_List ( | |
3246 | Make_Pragma_Argument_Association (Loc, | |
3247 | Expression => Relocate_Node (Expr))), | |
3248 | Pragma_Name => | |
3249 | Name_Secondary_Stack_Size); | |
3250 | ||
3251 | Decorate (Aspect, Aitem); | |
3252 | Insert_Pragma (Aitem); | |
3253 | goto Continue; | |
3254 | ||
3255 | -- Volatile_Function | |
3256 | ||
85ee12c0 | 3257 | -- Aspect Volatile_Function is never delayed because it is |
3258 | -- equivalent to a source pragma which appears after the | |
3259 | -- related subprogram. | |
3260 | ||
3261 | when Aspect_Volatile_Function => | |
3262 | Make_Aitem_Pragma | |
3263 | (Pragma_Argument_Associations => New_List ( | |
3264 | Make_Pragma_Argument_Association (Loc, | |
3265 | Expression => Relocate_Node (Expr))), | |
3266 | Pragma_Name => Name_Volatile_Function); | |
3267 | ||
3268 | Decorate (Aspect, Aitem); | |
3269 | Insert_Pragma (Aitem); | |
3270 | goto Continue; | |
3271 | ||
956ffaf4 | 3272 | -- Case 2e: Annotate aspect |
3273 | ||
3274 | when Aspect_Annotate => | |
3275 | declare | |
3276 | Args : List_Id; | |
3277 | Pargs : List_Id; | |
3278 | Arg : Node_Id; | |
3279 | ||
3280 | begin | |
3281 | -- The argument can be a single identifier | |
3282 | ||
3283 | if Nkind (Expr) = N_Identifier then | |
3284 | ||
3285 | -- One level of parens is allowed | |
3286 | ||
3287 | if Paren_Count (Expr) > 1 then | |
3288 | Error_Msg_F ("extra parentheses ignored", Expr); | |
3289 | end if; | |
3290 | ||
3291 | Set_Paren_Count (Expr, 0); | |
3292 | ||
3293 | -- Add the single item to the list | |
3294 | ||
3295 | Args := New_List (Expr); | |
3296 | ||
3297 | -- Otherwise we must have an aggregate | |
3298 | ||
3299 | elsif Nkind (Expr) = N_Aggregate then | |
3300 | ||
3301 | -- Must be positional | |
3302 | ||
3303 | if Present (Component_Associations (Expr)) then | |
3304 | Error_Msg_F | |
3305 | ("purely positional aggregate required", Expr); | |
3306 | goto Continue; | |
3307 | end if; | |
3308 | ||
3309 | -- Must not be parenthesized | |
3310 | ||
3311 | if Paren_Count (Expr) /= 0 then | |
3312 | Error_Msg_F ("extra parentheses ignored", Expr); | |
3313 | end if; | |
3314 | ||
3315 | -- List of arguments is list of aggregate expressions | |
3316 | ||
3317 | Args := Expressions (Expr); | |
3318 | ||
3319 | -- Anything else is illegal | |
3320 | ||
3321 | else | |
3322 | Error_Msg_F ("wrong form for Annotate aspect", Expr); | |
3323 | goto Continue; | |
3324 | end if; | |
3325 | ||
3326 | -- Prepare pragma arguments | |
3327 | ||
3328 | Pargs := New_List; | |
3329 | Arg := First (Args); | |
3330 | while Present (Arg) loop | |
3331 | Append_To (Pargs, | |
3332 | Make_Pragma_Argument_Association (Sloc (Arg), | |
3333 | Expression => Relocate_Node (Arg))); | |
3334 | Next (Arg); | |
3335 | end loop; | |
3336 | ||
3337 | Append_To (Pargs, | |
3338 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3339 | Chars => Name_Entity, | |
3340 | Expression => Ent)); | |
3341 | ||
3342 | Make_Aitem_Pragma | |
3343 | (Pragma_Argument_Associations => Pargs, | |
3344 | Pragma_Name => Name_Annotate); | |
3345 | end; | |
3346 | ||
89f1e35c | 3347 | -- Case 3 : Aspects that don't correspond to pragma/attribute |
3348 | -- definition clause. | |
7b9b2f05 | 3349 | |
89f1e35c | 3350 | -- Case 3a: The aspects listed below don't correspond to |
3351 | -- pragmas/attributes but do require delayed analysis. | |
7f694ca2 | 3352 | |
51fa2a45 | 3353 | -- Default_Value can only apply to a scalar type |
3354 | ||
3355 | when Aspect_Default_Value => | |
3356 | if not Is_Scalar_Type (E) then | |
3357 | Error_Msg_N | |
1089ff19 | 3358 | ("aspect Default_Value must apply to a scalar type", N); |
51fa2a45 | 3359 | end if; |
3360 | ||
3361 | Aitem := Empty; | |
3362 | ||
3363 | -- Default_Component_Value can only apply to an array type | |
3364 | -- with scalar components. | |
3365 | ||
3366 | when Aspect_Default_Component_Value => | |
3367 | if not (Is_Array_Type (E) | |
3f4c9ffc | 3368 | and then Is_Scalar_Type (Component_Type (E))) |
51fa2a45 | 3369 | then |
ee2b7923 | 3370 | Error_Msg_N |
3371 | ("aspect Default_Component_Value can only apply to an " | |
3372 | & "array of scalar components", N); | |
51fa2a45 | 3373 | end if; |
0fd13d32 | 3374 | |
89f1e35c | 3375 | Aitem := Empty; |
7f694ca2 | 3376 | |
89f1e35c | 3377 | -- Case 3b: The aspects listed below don't correspond to |
3378 | -- pragmas/attributes and don't need delayed analysis. | |
95bc75fa | 3379 | |
0fd13d32 | 3380 | -- Implicit_Dereference |
3381 | ||
89f1e35c | 3382 | -- For Implicit_Dereference, External_Name and Link_Name, only |
3383 | -- the legality checks are done during the analysis, thus no | |
3384 | -- delay is required. | |
a8e38e1d | 3385 | |
89f1e35c | 3386 | when Aspect_Implicit_Dereference => |
3387 | Analyze_Aspect_Implicit_Dereference; | |
3388 | goto Continue; | |
7f694ca2 | 3389 | |
0fd13d32 | 3390 | -- Dimension |
3391 | ||
89f1e35c | 3392 | when Aspect_Dimension => |
3393 | Analyze_Aspect_Dimension (N, Id, Expr); | |
3394 | goto Continue; | |
cb4c311d | 3395 | |
0fd13d32 | 3396 | -- Dimension_System |
3397 | ||
89f1e35c | 3398 | when Aspect_Dimension_System => |
3399 | Analyze_Aspect_Dimension_System (N, Id, Expr); | |
3400 | goto Continue; | |
7f694ca2 | 3401 | |
ceec4f7c | 3402 | -- Case 4: Aspects requiring special handling |
51ea9c94 | 3403 | |
e66f4e2a | 3404 | -- Pre/Post/Test_Case/Contract_Cases whose corresponding |
3405 | -- pragmas take care of the delay. | |
7f694ca2 | 3406 | |
0fd13d32 | 3407 | -- Pre/Post |
3408 | ||
1e3c4ae6 | 3409 | -- Aspects Pre/Post generate Precondition/Postcondition pragmas |
3410 | -- with a first argument that is the expression, and a second | |
3411 | -- argument that is an informative message if the test fails. | |
3412 | -- This is inserted right after the declaration, to get the | |
5b5df4a9 | 3413 | -- required pragma placement. The processing for the pragmas |
3414 | -- takes care of the required delay. | |
ae888dbd | 3415 | |
5ddd846b | 3416 | when Pre_Post_Aspects => Pre_Post : declare |
1e3c4ae6 | 3417 | Pname : Name_Id; |
ae888dbd | 3418 | |
1e3c4ae6 | 3419 | begin |
77ae6789 | 3420 | if A_Id = Aspect_Pre or else A_Id = Aspect_Precondition then |
1e3c4ae6 | 3421 | Pname := Name_Precondition; |
3422 | else | |
3423 | Pname := Name_Postcondition; | |
3424 | end if; | |
d74fc39a | 3425 | |
26062729 | 3426 | -- Check that the class-wide predicate cannot be applied to |
051826ee | 3427 | -- an operation of a synchronized type. AI12-0182 forbids |
3428 | -- these altogether, while earlier language semantics made | |
3429 | -- them legal on tagged synchronized types. | |
3430 | ||
3431 | -- Other legality checks are performed when analyzing the | |
3432 | -- contract of the operation. | |
26062729 | 3433 | |
3434 | if Class_Present (Aspect) | |
3435 | and then Is_Concurrent_Type (Current_Scope) | |
26062729 | 3436 | and then Ekind_In (E, E_Entry, E_Function, E_Procedure) |
3437 | then | |
3438 | Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Aspect); | |
3439 | Error_Msg_N | |
3440 | ("aspect % can only be specified for a primitive " | |
3441 | & "operation of a tagged type", Aspect); | |
3442 | ||
3443 | goto Continue; | |
3444 | end if; | |
3445 | ||
1e3c4ae6 | 3446 | -- If the expressions is of the form A and then B, then |
3447 | -- we generate separate Pre/Post aspects for the separate | |
3448 | -- clauses. Since we allow multiple pragmas, there is no | |
3449 | -- problem in allowing multiple Pre/Post aspects internally. | |
a273015d | 3450 | -- These should be treated in reverse order (B first and |
3451 | -- A second) since they are later inserted just after N in | |
3452 | -- the order they are treated. This way, the pragma for A | |
3453 | -- ends up preceding the pragma for B, which may have an | |
3454 | -- importance for the error raised (either constraint error | |
3455 | -- or precondition error). | |
1e3c4ae6 | 3456 | |
39e1f22f | 3457 | -- We do not do this for Pre'Class, since we have to put |
51fa2a45 | 3458 | -- these conditions together in a complex OR expression. |
ae888dbd | 3459 | |
4282d342 | 3460 | -- We do not do this in ASIS mode, as ASIS relies on the |
3461 | -- original node representing the complete expression, when | |
5cbdf597 | 3462 | -- retrieving it through the source aspect table. Also, we |
3463 | -- don't do this in GNATprove mode, because it brings no | |
3464 | -- benefit for proof and causes annoynace for flow analysis, | |
3465 | -- which prefers to be as close to the original source code | |
3466 | -- as possible. | |
4282d342 | 3467 | |
5cbdf597 | 3468 | if not (ASIS_Mode or GNATprove_Mode) |
4282d342 | 3469 | and then (Pname = Name_Postcondition |
3470 | or else not Class_Present (Aspect)) | |
39e1f22f | 3471 | then |
3472 | while Nkind (Expr) = N_And_Then loop | |
3473 | Insert_After (Aspect, | |
a273015d | 3474 | Make_Aspect_Specification (Sloc (Left_Opnd (Expr)), |
39e1f22f | 3475 | Identifier => Identifier (Aspect), |
a273015d | 3476 | Expression => Relocate_Node (Left_Opnd (Expr)), |
39e1f22f | 3477 | Class_Present => Class_Present (Aspect), |
3478 | Split_PPC => True)); | |
a273015d | 3479 | Rewrite (Expr, Relocate_Node (Right_Opnd (Expr))); |
39e1f22f | 3480 | Eloc := Sloc (Expr); |
3481 | end loop; | |
3482 | end if; | |
ae888dbd | 3483 | |
48d6f069 | 3484 | -- Build the precondition/postcondition pragma |
3485 | ||
429822c1 | 3486 | -- We use Relocate_Node here rather than New_Copy_Tree |
3487 | -- because subsequent visibility analysis of the aspect | |
3488 | -- depends on this sharing. This should be cleaned up??? | |
d74fc39a | 3489 | |
b9bd5934 | 3490 | -- If the context is generic or involves ASIS, we want |
3491 | -- to preserve the original tree, and simply share it | |
3492 | -- between aspect and generated attribute. This parallels | |
3493 | -- what is done in sem_prag.adb (see Get_Argument). | |
3494 | ||
3495 | declare | |
3496 | New_Expr : Node_Id; | |
3497 | ||
3498 | begin | |
3499 | if ASIS_Mode or else Inside_A_Generic then | |
3500 | New_Expr := Expr; | |
3501 | else | |
3502 | New_Expr := Relocate_Node (Expr); | |
3503 | end if; | |
3504 | ||
3505 | Make_Aitem_Pragma | |
3506 | (Pragma_Argument_Associations => New_List ( | |
3507 | Make_Pragma_Argument_Association (Eloc, | |
3508 | Chars => Name_Check, | |
3509 | Expression => New_Expr)), | |
3510 | Pragma_Name => Pname); | |
3511 | end; | |
39e1f22f | 3512 | |
3513 | -- Add message unless exception messages are suppressed | |
3514 | ||
3515 | if not Opt.Exception_Locations_Suppressed then | |
3516 | Append_To (Pragma_Argument_Associations (Aitem), | |
3517 | Make_Pragma_Argument_Association (Eloc, | |
ed695684 | 3518 | Chars => Name_Message, |
39e1f22f | 3519 | Expression => |
3520 | Make_String_Literal (Eloc, | |
3521 | Strval => "failed " | |
3522 | & Get_Name_String (Pname) | |
3523 | & " from " | |
3524 | & Build_Location_String (Eloc)))); | |
3525 | end if; | |
d74fc39a | 3526 | |
7d20685d | 3527 | Set_Is_Delayed_Aspect (Aspect); |
d74fc39a | 3528 | |
1e3c4ae6 | 3529 | -- For Pre/Post cases, insert immediately after the entity |
3530 | -- declaration, since that is the required pragma placement. | |
3531 | -- Note that for these aspects, we do not have to worry | |
3532 | -- about delay issues, since the pragmas themselves deal | |
3533 | -- with delay of visibility for the expression analysis. | |
3534 | ||
e2bf777d | 3535 | Insert_Pragma (Aitem); |
299b347e | 3536 | |
1e3c4ae6 | 3537 | goto Continue; |
5ddd846b | 3538 | end Pre_Post; |
ae888dbd | 3539 | |
0fd13d32 | 3540 | -- Test_Case |
3541 | ||
e66f4e2a | 3542 | when Aspect_Test_Case => Test_Case : declare |
3543 | Args : List_Id; | |
3544 | Comp_Expr : Node_Id; | |
3545 | Comp_Assn : Node_Id; | |
3546 | New_Expr : Node_Id; | |
57cd943b | 3547 | |
e66f4e2a | 3548 | begin |
3549 | Args := New_List; | |
b0bc40fd | 3550 | |
e66f4e2a | 3551 | if Nkind (Parent (N)) = N_Compilation_Unit then |
3552 | Error_Msg_Name_1 := Nam; | |
3553 | Error_Msg_N ("incorrect placement of aspect `%`", E); | |
3554 | goto Continue; | |
3555 | end if; | |
6c545057 | 3556 | |
e66f4e2a | 3557 | if Nkind (Expr) /= N_Aggregate then |
3558 | Error_Msg_Name_1 := Nam; | |
3559 | Error_Msg_NE | |
3560 | ("wrong syntax for aspect `%` for &", Id, E); | |
3561 | goto Continue; | |
3562 | end if; | |
6c545057 | 3563 | |
e66f4e2a | 3564 | -- Make pragma expressions refer to the original aspect |
51fa2a45 | 3565 | -- expressions through the Original_Node link. This is used |
3566 | -- in semantic analysis for ASIS mode, so that the original | |
3567 | -- expression also gets analyzed. | |
e66f4e2a | 3568 | |
3569 | Comp_Expr := First (Expressions (Expr)); | |
3570 | while Present (Comp_Expr) loop | |
3571 | New_Expr := Relocate_Node (Comp_Expr); | |
e66f4e2a | 3572 | Append_To (Args, |
3573 | Make_Pragma_Argument_Association (Sloc (Comp_Expr), | |
3574 | Expression => New_Expr)); | |
3575 | Next (Comp_Expr); | |
3576 | end loop; | |
3577 | ||
3578 | Comp_Assn := First (Component_Associations (Expr)); | |
3579 | while Present (Comp_Assn) loop | |
3580 | if List_Length (Choices (Comp_Assn)) /= 1 | |
3581 | or else | |
3582 | Nkind (First (Choices (Comp_Assn))) /= N_Identifier | |
3583 | then | |
fad014fe | 3584 | Error_Msg_Name_1 := Nam; |
6c545057 | 3585 | Error_Msg_NE |
fad014fe | 3586 | ("wrong syntax for aspect `%` for &", Id, E); |
6c545057 | 3587 | goto Continue; |
3588 | end if; | |
3589 | ||
e66f4e2a | 3590 | Append_To (Args, |
3591 | Make_Pragma_Argument_Association (Sloc (Comp_Assn), | |
ed695684 | 3592 | Chars => Chars (First (Choices (Comp_Assn))), |
3593 | Expression => | |
3594 | Relocate_Node (Expression (Comp_Assn)))); | |
e66f4e2a | 3595 | Next (Comp_Assn); |
3596 | end loop; | |
6c545057 | 3597 | |
e66f4e2a | 3598 | -- Build the test-case pragma |
6c545057 | 3599 | |
0fd13d32 | 3600 | Make_Aitem_Pragma |
3601 | (Pragma_Argument_Associations => Args, | |
3602 | Pragma_Name => Nam); | |
e66f4e2a | 3603 | end Test_Case; |
85696508 | 3604 | |
0fd13d32 | 3605 | -- Contract_Cases |
3606 | ||
5ddd846b | 3607 | when Aspect_Contract_Cases => |
0fd13d32 | 3608 | Make_Aitem_Pragma |
3609 | (Pragma_Argument_Associations => New_List ( | |
3610 | Make_Pragma_Argument_Association (Loc, | |
3611 | Expression => Relocate_Node (Expr))), | |
3612 | Pragma_Name => Nam); | |
3a128918 | 3613 | |
e2bf777d | 3614 | Decorate (Aspect, Aitem); |
3615 | Insert_Pragma (Aitem); | |
5ddd846b | 3616 | goto Continue; |
3a128918 | 3617 | |
89f1e35c | 3618 | -- Case 5: Special handling for aspects with an optional |
3619 | -- boolean argument. | |
85696508 | 3620 | |
6c5793cd | 3621 | -- In the delayed case, the corresponding pragma cannot be |
0fd13d32 | 3622 | -- generated yet because the evaluation of the boolean needs |
3623 | -- to be delayed till the freeze point. | |
3624 | ||
99378362 | 3625 | when Boolean_Aspects |
3626 | | Library_Unit_Aspects | |
3627 | => | |
89f1e35c | 3628 | Set_Is_Boolean_Aspect (Aspect); |
a5a64273 | 3629 | |
89f1e35c | 3630 | -- Lock_Free aspect only apply to protected objects |
e1cedbae | 3631 | |
89f1e35c | 3632 | if A_Id = Aspect_Lock_Free then |
3633 | if Ekind (E) /= E_Protected_Type then | |
99a2d5bd | 3634 | Error_Msg_Name_1 := Nam; |
a5a64273 | 3635 | Error_Msg_N |
89f1e35c | 3636 | ("aspect % only applies to a protected object", |
3637 | Aspect); | |
3638 | ||
3639 | else | |
3640 | -- Set the Uses_Lock_Free flag to True if there is no | |
37c6e44c | 3641 | -- expression or if the expression is True. The |
89f1e35c | 3642 | -- evaluation of this aspect should be delayed to the |
37c6e44c | 3643 | -- freeze point (why???) |
89f1e35c | 3644 | |
e81df51c | 3645 | if No (Expr) |
3646 | or else Is_True (Static_Boolean (Expr)) | |
89f1e35c | 3647 | then |
3648 | Set_Uses_Lock_Free (E); | |
3649 | end if; | |
caf125ce | 3650 | |
3651 | Record_Rep_Item (E, Aspect); | |
a5a64273 | 3652 | end if; |
e1cedbae | 3653 | |
89f1e35c | 3654 | goto Continue; |
ae888dbd | 3655 | |
ee2b7923 | 3656 | elsif A_Id = Aspect_Export or else A_Id = Aspect_Import then |
3657 | Analyze_Aspect_Export_Import; | |
6c5793cd | 3658 | |
3659 | -- Disable_Controlled | |
3660 | ||
3661 | elsif A_Id = Aspect_Disable_Controlled then | |
0b10029c | 3662 | Analyze_Aspect_Disable_Controlled; |
89f1e35c | 3663 | goto Continue; |
3664 | end if; | |
d74fc39a | 3665 | |
37c6e44c | 3666 | -- Library unit aspects require special handling in the case |
3667 | -- of a package declaration, the pragma needs to be inserted | |
3668 | -- in the list of declarations for the associated package. | |
3669 | -- There is no issue of visibility delay for these aspects. | |
d64221a7 | 3670 | |
89f1e35c | 3671 | if A_Id in Library_Unit_Aspects |
178fec9b | 3672 | and then |
3673 | Nkind_In (N, N_Package_Declaration, | |
3674 | N_Generic_Package_Declaration) | |
89f1e35c | 3675 | and then Nkind (Parent (N)) /= N_Compilation_Unit |
3ad60f63 | 3676 | |
3677 | -- Aspect is legal on a local instantiation of a library- | |
3678 | -- level generic unit. | |
3679 | ||
b94a633e | 3680 | and then not Is_Generic_Instance (Defining_Entity (N)) |
89f1e35c | 3681 | then |
3682 | Error_Msg_N | |
dd4c44af | 3683 | ("incorrect context for library unit aspect&", Id); |
89f1e35c | 3684 | goto Continue; |
3685 | end if; | |
cce84b09 | 3686 | |
51fa2a45 | 3687 | -- Cases where we do not delay, includes all cases where the |
3688 | -- expression is missing other than the above cases. | |
d74fc39a | 3689 | |
85ee12c0 | 3690 | if not Delay_Required or else No (Expr) then |
ee2b7923 | 3691 | |
3692 | -- Exclude aspects Export and Import because their pragma | |
3693 | -- syntax does not map directly to a Boolean aspect. | |
3694 | ||
3695 | if A_Id /= Aspect_Export | |
3696 | and then A_Id /= Aspect_Import | |
3697 | then | |
3698 | Make_Aitem_Pragma | |
3699 | (Pragma_Argument_Associations => New_List ( | |
3700 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3701 | Expression => Ent)), | |
3702 | Pragma_Name => Chars (Id)); | |
3703 | end if; | |
3704 | ||
89f1e35c | 3705 | Delay_Required := False; |
ddf1337b | 3706 | |
89f1e35c | 3707 | -- In general cases, the corresponding pragma/attribute |
3708 | -- definition clause will be inserted later at the freezing | |
294709fa | 3709 | -- point, and we do not need to build it now. |
ddf1337b | 3710 | |
89f1e35c | 3711 | else |
3712 | Aitem := Empty; | |
3713 | end if; | |
ceec4f7c | 3714 | |
3715 | -- Storage_Size | |
3716 | ||
3717 | -- This is special because for access types we need to generate | |
3718 | -- an attribute definition clause. This also works for single | |
3719 | -- task declarations, but it does not work for task type | |
3720 | -- declarations, because we have the case where the expression | |
3721 | -- references a discriminant of the task type. That can't use | |
3722 | -- an attribute definition clause because we would not have | |
3723 | -- visibility on the discriminant. For that case we must | |
3724 | -- generate a pragma in the task definition. | |
3725 | ||
3726 | when Aspect_Storage_Size => | |
3727 | ||
3728 | -- Task type case | |
3729 | ||
3730 | if Ekind (E) = E_Task_Type then | |
3731 | declare | |
3732 | Decl : constant Node_Id := Declaration_Node (E); | |
3733 | ||
3734 | begin | |
3735 | pragma Assert (Nkind (Decl) = N_Task_Type_Declaration); | |
3736 | ||
3737 | -- If no task definition, create one | |
3738 | ||
3739 | if No (Task_Definition (Decl)) then | |
3740 | Set_Task_Definition (Decl, | |
3741 | Make_Task_Definition (Loc, | |
3742 | Visible_Declarations => Empty_List, | |
3743 | End_Label => Empty)); | |
3744 | end if; | |
3745 | ||
51fa2a45 | 3746 | -- Create a pragma and put it at the start of the task |
3747 | -- definition for the task type declaration. | |
ceec4f7c | 3748 | |
3749 | Make_Aitem_Pragma | |
3750 | (Pragma_Argument_Associations => New_List ( | |
3751 | Make_Pragma_Argument_Association (Loc, | |
3752 | Expression => Relocate_Node (Expr))), | |
3753 | Pragma_Name => Name_Storage_Size); | |
3754 | ||
3755 | Prepend | |
3756 | (Aitem, | |
3757 | Visible_Declarations (Task_Definition (Decl))); | |
3758 | goto Continue; | |
3759 | end; | |
3760 | ||
3761 | -- All other cases, generate attribute definition | |
3762 | ||
3763 | else | |
3764 | Aitem := | |
3765 | Make_Attribute_Definition_Clause (Loc, | |
3766 | Name => Ent, | |
3767 | Chars => Chars (Id), | |
3768 | Expression => Relocate_Node (Expr)); | |
3769 | end if; | |
89f1e35c | 3770 | end case; |
ddf1337b | 3771 | |
89f1e35c | 3772 | -- Attach the corresponding pragma/attribute definition clause to |
3773 | -- the aspect specification node. | |
d74fc39a | 3774 | |
89f1e35c | 3775 | if Present (Aitem) then |
e2bf777d | 3776 | Set_From_Aspect_Specification (Aitem); |
89f1e35c | 3777 | end if; |
53c179ea | 3778 | |
89f1e35c | 3779 | -- In the context of a compilation unit, we directly put the |
0fd13d32 | 3780 | -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux |
3781 | -- node (no delay is required here) except for aspects on a | |
51fa2a45 | 3782 | -- subprogram body (see below) and a generic package, for which we |
3783 | -- need to introduce the pragma before building the generic copy | |
3784 | -- (see sem_ch12), and for package instantiations, where the | |
3785 | -- library unit pragmas are better handled early. | |
ddf1337b | 3786 | |
9129c28f | 3787 | if Nkind (Parent (N)) = N_Compilation_Unit |
89f1e35c | 3788 | and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect)) |
3789 | then | |
3790 | declare | |
3791 | Aux : constant Node_Id := Aux_Decls_Node (Parent (N)); | |
7f694ca2 | 3792 | |
89f1e35c | 3793 | begin |
3794 | pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux); | |
7f694ca2 | 3795 | |
89f1e35c | 3796 | -- For a Boolean aspect, create the corresponding pragma if |
3797 | -- no expression or if the value is True. | |
7f694ca2 | 3798 | |
b9e61b2a | 3799 | if Is_Boolean_Aspect (Aspect) and then No (Aitem) then |
89f1e35c | 3800 | if Is_True (Static_Boolean (Expr)) then |
0fd13d32 | 3801 | Make_Aitem_Pragma |
3802 | (Pragma_Argument_Associations => New_List ( | |
3803 | Make_Pragma_Argument_Association (Sloc (Ent), | |
3804 | Expression => Ent)), | |
3805 | Pragma_Name => Chars (Id)); | |
7f694ca2 | 3806 | |
89f1e35c | 3807 | Set_From_Aspect_Specification (Aitem, True); |
3808 | Set_Corresponding_Aspect (Aitem, Aspect); | |
3809 | ||
3810 | else | |
3811 | goto Continue; | |
3812 | end if; | |
3813 | end if; | |
7f694ca2 | 3814 | |
d6814978 | 3815 | -- If the aspect is on a subprogram body (relevant aspect |
3816 | -- is Inline), add the pragma in front of the declarations. | |
3a72f9c3 | 3817 | |
3818 | if Nkind (N) = N_Subprogram_Body then | |
3819 | if No (Declarations (N)) then | |
3820 | Set_Declarations (N, New_List); | |
3821 | end if; | |
3822 | ||
3823 | Prepend (Aitem, Declarations (N)); | |
3824 | ||
178fec9b | 3825 | elsif Nkind (N) = N_Generic_Package_Declaration then |
3826 | if No (Visible_Declarations (Specification (N))) then | |
3827 | Set_Visible_Declarations (Specification (N), New_List); | |
3828 | end if; | |
3829 | ||
3830 | Prepend (Aitem, | |
3831 | Visible_Declarations (Specification (N))); | |
3832 | ||
c39cce40 | 3833 | elsif Nkind (N) = N_Package_Instantiation then |
df8b0dae | 3834 | declare |
3835 | Spec : constant Node_Id := | |
3836 | Specification (Instance_Spec (N)); | |
3837 | begin | |
3838 | if No (Visible_Declarations (Spec)) then | |
3839 | Set_Visible_Declarations (Spec, New_List); | |
3840 | end if; | |
3841 | ||
3842 | Prepend (Aitem, Visible_Declarations (Spec)); | |
3843 | end; | |
3844 | ||
3a72f9c3 | 3845 | else |
3846 | if No (Pragmas_After (Aux)) then | |
d4596fbe | 3847 | Set_Pragmas_After (Aux, New_List); |
3a72f9c3 | 3848 | end if; |
3849 | ||
3850 | Append (Aitem, Pragmas_After (Aux)); | |
89f1e35c | 3851 | end if; |
7f694ca2 | 3852 | |
89f1e35c | 3853 | goto Continue; |
3854 | end; | |
3855 | end if; | |
7f694ca2 | 3856 | |
89f1e35c | 3857 | -- The evaluation of the aspect is delayed to the freezing point. |
3858 | -- The pragma or attribute clause if there is one is then attached | |
37c6e44c | 3859 | -- to the aspect specification which is put in the rep item list. |
1a814552 | 3860 | |
89f1e35c | 3861 | if Delay_Required then |
3862 | if Present (Aitem) then | |
3863 | Set_Is_Delayed_Aspect (Aitem); | |
3864 | Set_Aspect_Rep_Item (Aspect, Aitem); | |
3865 | Set_Parent (Aitem, Aspect); | |
3866 | end if; | |
1a814552 | 3867 | |
89f1e35c | 3868 | Set_Is_Delayed_Aspect (Aspect); |
9f36e3fb | 3869 | |
cba2ae82 | 3870 | -- In the case of Default_Value, link the aspect to base type |
3871 | -- as well, even though it appears on a first subtype. This is | |
3872 | -- mandated by the semantics of the aspect. Do not establish | |
3873 | -- the link when processing the base type itself as this leads | |
3874 | -- to a rep item circularity. Verify that we are dealing with | |
3875 | -- a scalar type to prevent cascaded errors. | |
3876 | ||
3877 | if A_Id = Aspect_Default_Value | |
3878 | and then Is_Scalar_Type (E) | |
3879 | and then Base_Type (E) /= E | |
3880 | then | |
9f36e3fb | 3881 | Set_Has_Delayed_Aspects (Base_Type (E)); |
3882 | Record_Rep_Item (Base_Type (E), Aspect); | |
3883 | end if; | |
3884 | ||
89f1e35c | 3885 | Set_Has_Delayed_Aspects (E); |
3886 | Record_Rep_Item (E, Aspect); | |
ddf1337b | 3887 | |
b855559d | 3888 | -- When delay is not required and the context is a package or a |
3889 | -- subprogram body, insert the pragma in the body declarations. | |
f55ce169 | 3890 | |
b855559d | 3891 | elsif Nkind_In (N, N_Package_Body, N_Subprogram_Body) then |
f55ce169 | 3892 | if No (Declarations (N)) then |
3893 | Set_Declarations (N, New_List); | |
3894 | end if; | |
3895 | ||
3896 | -- The pragma is added before source declarations | |
3897 | ||
3898 | Prepend_To (Declarations (N), Aitem); | |
3899 | ||
89f1e35c | 3900 | -- When delay is not required and the context is not a compilation |
3901 | -- unit, we simply insert the pragma/attribute definition clause | |
3902 | -- in sequence. | |
ddf1337b | 3903 | |
ee2b7923 | 3904 | elsif Present (Aitem) then |
89f1e35c | 3905 | Insert_After (Ins_Node, Aitem); |
3906 | Ins_Node := Aitem; | |
d74fc39a | 3907 | end if; |
0fd13d32 | 3908 | end Analyze_One_Aspect; |
ae888dbd | 3909 | |
d64221a7 | 3910 | <<Continue>> |
3911 | Next (Aspect); | |
21ea3a4f | 3912 | end loop Aspect_Loop; |
89f1e35c | 3913 | |
3914 | if Has_Delayed_Aspects (E) then | |
3915 | Ensure_Freeze_Node (E); | |
3916 | end if; | |
21ea3a4f | 3917 | end Analyze_Aspect_Specifications; |
ae888dbd | 3918 | |
f38beee5 | 3919 | ------------------------------------------------ |
3920 | -- Analyze_Aspects_On_Subprogram_Body_Or_Stub -- | |
3921 | ------------------------------------------------ | |
eb8aeefc | 3922 | |
f38beee5 | 3923 | procedure Analyze_Aspects_On_Subprogram_Body_Or_Stub (N : Node_Id) is |
eb8aeefc | 3924 | Body_Id : constant Entity_Id := Defining_Entity (N); |
3925 | ||
3926 | procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id); | |
c02dccca | 3927 | -- Body [stub] N has aspects, but they are not properly placed. Emit an |
3928 | -- error message depending on the aspects involved. Spec_Id denotes the | |
3929 | -- entity of the corresponding spec. | |
eb8aeefc | 3930 | |
3931 | -------------------------------- | |
3932 | -- Diagnose_Misplaced_Aspects -- | |
3933 | -------------------------------- | |
3934 | ||
3935 | procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is | |
3936 | procedure Misplaced_Aspect_Error | |
3937 | (Asp : Node_Id; | |
3938 | Ref_Nam : Name_Id); | |
3939 | -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is | |
3940 | -- the name of the refined version of the aspect. | |
3941 | ||
3942 | ---------------------------- | |
3943 | -- Misplaced_Aspect_Error -- | |
3944 | ---------------------------- | |
3945 | ||
3946 | procedure Misplaced_Aspect_Error | |
3947 | (Asp : Node_Id; | |
3948 | Ref_Nam : Name_Id) | |
3949 | is | |
3950 | Asp_Nam : constant Name_Id := Chars (Identifier (Asp)); | |
3951 | Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam); | |
3952 | ||
3953 | begin | |
3954 | -- The corresponding spec already contains the aspect in question | |
3955 | -- and the one appearing on the body must be the refined form: | |
3956 | ||
3957 | -- procedure P with Global ...; | |
3958 | -- procedure P with Global ... is ... end P; | |
3959 | -- ^ | |
3960 | -- Refined_Global | |
3961 | ||
3962 | if Has_Aspect (Spec_Id, Asp_Id) then | |
3963 | Error_Msg_Name_1 := Asp_Nam; | |
3964 | ||
3965 | -- Subunits cannot carry aspects that apply to a subprogram | |
3966 | -- declaration. | |
3967 | ||
3968 | if Nkind (Parent (N)) = N_Subunit then | |
3969 | Error_Msg_N ("aspect % cannot apply to a subunit", Asp); | |
3970 | ||
3971 | -- Otherwise suggest the refined form | |
3972 | ||
3973 | else | |
3974 | Error_Msg_Name_2 := Ref_Nam; | |
3975 | Error_Msg_N ("aspect % should be %", Asp); | |
3976 | end if; | |
3977 | ||
3978 | -- Otherwise the aspect must appear on the spec, not on the body | |
3979 | ||
3980 | -- procedure P; | |
3981 | -- procedure P with Global ... is ... end P; | |
3982 | ||
3983 | else | |
3984 | Error_Msg_N | |
c02dccca | 3985 | ("aspect specification must appear on initial declaration", |
eb8aeefc | 3986 | Asp); |
3987 | end if; | |
3988 | end Misplaced_Aspect_Error; | |
3989 | ||
3990 | -- Local variables | |
3991 | ||
3992 | Asp : Node_Id; | |
3993 | Asp_Nam : Name_Id; | |
3994 | ||
3995 | -- Start of processing for Diagnose_Misplaced_Aspects | |
3996 | ||
3997 | begin | |
3998 | -- Iterate over the aspect specifications and emit specific errors | |
3999 | -- where applicable. | |
4000 | ||
4001 | Asp := First (Aspect_Specifications (N)); | |
4002 | while Present (Asp) loop | |
4003 | Asp_Nam := Chars (Identifier (Asp)); | |
4004 | ||
4005 | -- Do not emit errors on aspects that can appear on a subprogram | |
4006 | -- body. This scenario occurs when the aspect specification list | |
4007 | -- contains both misplaced and properly placed aspects. | |
4008 | ||
4009 | if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then | |
4010 | null; | |
4011 | ||
4012 | -- Special diagnostics for SPARK aspects | |
4013 | ||
4014 | elsif Asp_Nam = Name_Depends then | |
4015 | Misplaced_Aspect_Error (Asp, Name_Refined_Depends); | |
4016 | ||
4017 | elsif Asp_Nam = Name_Global then | |
4018 | Misplaced_Aspect_Error (Asp, Name_Refined_Global); | |
4019 | ||
4020 | elsif Asp_Nam = Name_Post then | |
4021 | Misplaced_Aspect_Error (Asp, Name_Refined_Post); | |
4022 | ||
4023 | -- Otherwise a language-defined aspect is misplaced | |
4024 | ||
4025 | else | |
4026 | Error_Msg_N | |
c02dccca | 4027 | ("aspect specification must appear on initial declaration", |
eb8aeefc | 4028 | Asp); |
4029 | end if; | |
4030 | ||
4031 | Next (Asp); | |
4032 | end loop; | |
4033 | end Diagnose_Misplaced_Aspects; | |
4034 | ||
4035 | -- Local variables | |
4036 | ||
c02dccca | 4037 | Spec_Id : constant Entity_Id := Unique_Defining_Entity (N); |
eb8aeefc | 4038 | |
f38beee5 | 4039 | -- Start of processing for Analyze_Aspects_On_Subprogram_Body_Or_Stub |
eb8aeefc | 4040 | |
4041 | begin | |
eb8aeefc | 4042 | -- Language-defined aspects cannot be associated with a subprogram body |
4043 | -- [stub] if the subprogram has a spec. Certain implementation defined | |
4044 | -- aspects are allowed to break this rule (for all applicable cases, see | |
4045 | -- table Aspects.Aspect_On_Body_Or_Stub_OK). | |
4046 | ||
c02dccca | 4047 | if Spec_Id /= Body_Id and then not Aspects_On_Body_Or_Stub_OK (N) then |
eb8aeefc | 4048 | Diagnose_Misplaced_Aspects (Spec_Id); |
4049 | else | |
4050 | Analyze_Aspect_Specifications (N, Body_Id); | |
4051 | end if; | |
f38beee5 | 4052 | end Analyze_Aspects_On_Subprogram_Body_Or_Stub; |
eb8aeefc | 4053 | |
d6f39728 | 4054 | ----------------------- |
4055 | -- Analyze_At_Clause -- | |
4056 | ----------------------- | |
4057 | ||
4058 | -- An at clause is replaced by the corresponding Address attribute | |
4059 | -- definition clause that is the preferred approach in Ada 95. | |
4060 | ||
4061 | procedure Analyze_At_Clause (N : Node_Id) is | |
177675a7 | 4062 | CS : constant Boolean := Comes_From_Source (N); |
4063 | ||
d6f39728 | 4064 | begin |
177675a7 | 4065 | -- This is an obsolescent feature |
4066 | ||
e0521a36 | 4067 | Check_Restriction (No_Obsolescent_Features, N); |
4068 | ||
9dfe12ae | 4069 | if Warn_On_Obsolescent_Feature then |
4070 | Error_Msg_N | |
b174444e | 4071 | ("?j?at clause is an obsolescent feature (RM J.7(2))", N); |
9dfe12ae | 4072 | Error_Msg_N |
b174444e | 4073 | ("\?j?use address attribute definition clause instead", N); |
9dfe12ae | 4074 | end if; |
4075 | ||
177675a7 | 4076 | -- Rewrite as address clause |
4077 | ||
d6f39728 | 4078 | Rewrite (N, |
4079 | Make_Attribute_Definition_Clause (Sloc (N), | |
935e86e0 | 4080 | Name => Identifier (N), |
4081 | Chars => Name_Address, | |
d6f39728 | 4082 | Expression => Expression (N))); |
177675a7 | 4083 | |
2beb22b1 | 4084 | -- We preserve Comes_From_Source, since logically the clause still comes |
4085 | -- from the source program even though it is changed in form. | |
177675a7 | 4086 | |
4087 | Set_Comes_From_Source (N, CS); | |
4088 | ||
4089 | -- Analyze rewritten clause | |
4090 | ||
d6f39728 | 4091 | Analyze_Attribute_Definition_Clause (N); |
4092 | end Analyze_At_Clause; | |
4093 | ||
4094 | ----------------------------------------- | |
4095 | -- Analyze_Attribute_Definition_Clause -- | |
4096 | ----------------------------------------- | |
4097 | ||
4098 | procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is | |
4099 | Loc : constant Source_Ptr := Sloc (N); | |
4100 | Nam : constant Node_Id := Name (N); | |
4101 | Attr : constant Name_Id := Chars (N); | |
4102 | Expr : constant Node_Id := Expression (N); | |
4103 | Id : constant Attribute_Id := Get_Attribute_Id (Attr); | |
d64221a7 | 4104 | |
4105 | Ent : Entity_Id; | |
4106 | -- The entity of Nam after it is analyzed. In the case of an incomplete | |
4107 | -- type, this is the underlying type. | |
4108 | ||
d6f39728 | 4109 | U_Ent : Entity_Id; |
d64221a7 | 4110 | -- The underlying entity to which the attribute applies. Generally this |
4111 | -- is the Underlying_Type of Ent, except in the case where the clause | |
69069c76 | 4112 | -- applies to the full view of an incomplete or private type, in which |
4113 | -- case U_Ent is just a copy of Ent. | |
d6f39728 | 4114 | |
4115 | FOnly : Boolean := False; | |
4116 | -- Reset to True for subtype specific attribute (Alignment, Size) | |
51fa2a45 | 4117 | -- and for stream attributes, i.e. those cases where in the call to |
4118 | -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules | |
4119 | -- are checked. Note that the case of stream attributes is not clear | |
4120 | -- from the RM, but see AI95-00137. Also, the RM seems to disallow | |
4121 | -- Storage_Size for derived task types, but that is also clearly | |
4122 | -- unintentional. | |
d6f39728 | 4123 | |
9f373bb8 | 4124 | procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type); |
4125 | -- Common processing for 'Read, 'Write, 'Input and 'Output attribute | |
4126 | -- definition clauses. | |
4127 | ||
ae888dbd | 4128 | function Duplicate_Clause return Boolean; |
4129 | -- This routine checks if the aspect for U_Ent being given by attribute | |
4130 | -- definition clause N is for an aspect that has already been specified, | |
4131 | -- and if so gives an error message. If there is a duplicate, True is | |
4132 | -- returned, otherwise if there is no error, False is returned. | |
4133 | ||
81b424ac | 4134 | procedure Check_Indexing_Functions; |
4135 | -- Check that the function in Constant_Indexing or Variable_Indexing | |
4136 | -- attribute has the proper type structure. If the name is overloaded, | |
cac18f71 | 4137 | -- check that some interpretation is legal. |
81b424ac | 4138 | |
89cc7147 | 4139 | procedure Check_Iterator_Functions; |
4140 | -- Check that there is a single function in Default_Iterator attribute | |
58a61b0f | 4141 | -- that has the proper type structure. |
89cc7147 | 4142 | |
4143 | function Check_Primitive_Function (Subp : Entity_Id) return Boolean; | |
d03bfaa1 | 4144 | -- Common legality check for the previous two |
89cc7147 | 4145 | |
177675a7 | 4146 | ----------------------------------- |
4147 | -- Analyze_Stream_TSS_Definition -- | |
4148 | ----------------------------------- | |
4149 | ||
9f373bb8 | 4150 | procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is |
4151 | Subp : Entity_Id := Empty; | |
4152 | I : Interp_Index; | |
4153 | It : Interp; | |
4154 | Pnam : Entity_Id; | |
4155 | ||
4156 | Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read); | |
ba662f09 | 4157 | -- True for Read attribute, False for other attributes |
9f373bb8 | 4158 | |
c41e404d | 4159 | function Has_Good_Profile |
4160 | (Subp : Entity_Id; | |
4161 | Report : Boolean := False) return Boolean; | |
9f373bb8 | 4162 | -- Return true if the entity is a subprogram with an appropriate |
ba662f09 | 4163 | -- profile for the attribute being defined. If result is False and |
4164 | -- Report is True, function emits appropriate error. | |
9f373bb8 | 4165 | |
4166 | ---------------------- | |
4167 | -- Has_Good_Profile -- | |
4168 | ---------------------- | |
4169 | ||
c41e404d | 4170 | function Has_Good_Profile |
4171 | (Subp : Entity_Id; | |
4172 | Report : Boolean := False) return Boolean | |
4173 | is | |
9f373bb8 | 4174 | Expected_Ekind : constant array (Boolean) of Entity_Kind := |
4175 | (False => E_Procedure, True => E_Function); | |
4a83cc35 | 4176 | Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input); |
4177 | F : Entity_Id; | |
9f373bb8 | 4178 | Typ : Entity_Id; |
4179 | ||
4180 | begin | |
4181 | if Ekind (Subp) /= Expected_Ekind (Is_Function) then | |
4182 | return False; | |
4183 | end if; | |
4184 | ||
4185 | F := First_Formal (Subp); | |
4186 | ||
4187 | if No (F) | |
4188 | or else Ekind (Etype (F)) /= E_Anonymous_Access_Type | |
4189 | or else Designated_Type (Etype (F)) /= | |
4a83cc35 | 4190 | Class_Wide_Type (RTE (RE_Root_Stream_Type)) |
9f373bb8 | 4191 | then |
4192 | return False; | |
4193 | end if; | |
4194 | ||
4195 | if not Is_Function then | |
4196 | Next_Formal (F); | |
4197 | ||
4198 | declare | |
4199 | Expected_Mode : constant array (Boolean) of Entity_Kind := | |
4200 | (False => E_In_Parameter, | |
4201 | True => E_Out_Parameter); | |
4202 | begin | |
4203 | if Parameter_Mode (F) /= Expected_Mode (Is_Read) then | |
4204 | return False; | |
4205 | end if; | |
4206 | end; | |
4207 | ||
4208 | Typ := Etype (F); | |
4209 | ||
b64082f2 | 4210 | -- If the attribute specification comes from an aspect |
51fa2a45 | 4211 | -- specification for a class-wide stream, the parameter must be |
4212 | -- a class-wide type of the entity to which the aspect applies. | |
b64082f2 | 4213 | |
4214 | if From_Aspect_Specification (N) | |
4215 | and then Class_Present (Parent (N)) | |
4216 | and then Is_Class_Wide_Type (Typ) | |
4217 | then | |
4218 | Typ := Etype (Typ); | |
4219 | end if; | |
4220 | ||
9f373bb8 | 4221 | else |
4222 | Typ := Etype (Subp); | |
4223 | end if; | |
4224 | ||
51fa2a45 | 4225 | -- Verify that the prefix of the attribute and the local name for |
5a8fe506 | 4226 | -- the type of the formal match, or one is the class-wide of the |
4227 | -- other, in the case of a class-wide stream operation. | |
48680a09 | 4228 | |
b8eacb12 | 4229 | if Base_Type (Typ) = Base_Type (Ent) |
5a8fe506 | 4230 | or else (Is_Class_Wide_Type (Typ) |
2be1f7d7 | 4231 | and then Typ = Class_Wide_Type (Base_Type (Ent))) |
fbf4d6ef | 4232 | or else (Is_Class_Wide_Type (Ent) |
4233 | and then Ent = Class_Wide_Type (Base_Type (Typ))) | |
5a8fe506 | 4234 | then |
4235 | null; | |
4236 | else | |
4237 | return False; | |
4238 | end if; | |
4239 | ||
4a83cc35 | 4240 | if Present (Next_Formal (F)) then |
48680a09 | 4241 | return False; |
4242 | ||
4243 | elsif not Is_Scalar_Type (Typ) | |
4244 | and then not Is_First_Subtype (Typ) | |
4245 | and then not Is_Class_Wide_Type (Typ) | |
4246 | then | |
c41e404d | 4247 | if Report and not Is_First_Subtype (Typ) then |
4248 | Error_Msg_N | |
ba662f09 | 4249 | ("subtype of formal in stream operation must be a first " |
4250 | & "subtype", Parameter_Type (Parent (F))); | |
c41e404d | 4251 | end if; |
4252 | ||
48680a09 | 4253 | return False; |
4254 | ||
4255 | else | |
4256 | return True; | |
4257 | end if; | |
9f373bb8 | 4258 | end Has_Good_Profile; |
4259 | ||
4260 | -- Start of processing for Analyze_Stream_TSS_Definition | |
4261 | ||
4262 | begin | |
4263 | FOnly := True; | |
4264 | ||
4265 | if not Is_Type (U_Ent) then | |
4266 | Error_Msg_N ("local name must be a subtype", Nam); | |
4267 | return; | |
48680a09 | 4268 | |
4269 | elsif not Is_First_Subtype (U_Ent) then | |
4270 | Error_Msg_N ("local name must be a first subtype", Nam); | |
4271 | return; | |
9f373bb8 | 4272 | end if; |
4273 | ||
4274 | Pnam := TSS (Base_Type (U_Ent), TSS_Nam); | |
4275 | ||
44e4341e | 4276 | -- If Pnam is present, it can be either inherited from an ancestor |
4277 | -- type (in which case it is legal to redefine it for this type), or | |
4278 | -- be a previous definition of the attribute for the same type (in | |
4279 | -- which case it is illegal). | |
4280 | ||
4281 | -- In the first case, it will have been analyzed already, and we | |
4282 | -- can check that its profile does not match the expected profile | |
4283 | -- for a stream attribute of U_Ent. In the second case, either Pnam | |
4284 | -- has been analyzed (and has the expected profile), or it has not | |
4285 | -- been analyzed yet (case of a type that has not been frozen yet | |
4286 | -- and for which the stream attribute has been set using Set_TSS). | |
4287 | ||
4288 | if Present (Pnam) | |
4289 | and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam)) | |
4290 | then | |
9f373bb8 | 4291 | Error_Msg_Sloc := Sloc (Pnam); |
4292 | Error_Msg_Name_1 := Attr; | |
4293 | Error_Msg_N ("% attribute already defined #", Nam); | |
4294 | return; | |
4295 | end if; | |
4296 | ||
4297 | Analyze (Expr); | |
4298 | ||
4299 | if Is_Entity_Name (Expr) then | |
4300 | if not Is_Overloaded (Expr) then | |
c41e404d | 4301 | if Has_Good_Profile (Entity (Expr), Report => True) then |
9f373bb8 | 4302 | Subp := Entity (Expr); |
4303 | end if; | |
4304 | ||
4305 | else | |
4306 | Get_First_Interp (Expr, I, It); | |
9f373bb8 | 4307 | while Present (It.Nam) loop |
4308 | if Has_Good_Profile (It.Nam) then | |
4309 | Subp := It.Nam; | |
4310 | exit; | |
4311 | end if; | |
4312 | ||
4313 | Get_Next_Interp (I, It); | |
4314 | end loop; | |
4315 | end if; | |
4316 | end if; | |
4317 | ||
4318 | if Present (Subp) then | |
59ac57b5 | 4319 | if Is_Abstract_Subprogram (Subp) then |
9f373bb8 | 4320 | Error_Msg_N ("stream subprogram must not be abstract", Expr); |
4321 | return; | |
e12b2502 | 4322 | |
299b347e | 4323 | -- A stream subprogram for an interface type must be a null |
bfbd9cf4 | 4324 | -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type |
4325 | -- of an interface is not an interface type (3.9.4 (6.b/2)). | |
e12b2502 | 4326 | |
4327 | elsif Is_Interface (U_Ent) | |
5a8fe506 | 4328 | and then not Is_Class_Wide_Type (U_Ent) |
e12b2502 | 4329 | and then not Inside_A_Generic |
e12b2502 | 4330 | and then |
5a8fe506 | 4331 | (Ekind (Subp) = E_Function |
4332 | or else | |
4333 | not Null_Present | |
2be1f7d7 | 4334 | (Specification |
4335 | (Unit_Declaration_Node (Ultimate_Alias (Subp))))) | |
e12b2502 | 4336 | then |
4337 | Error_Msg_N | |
4a83cc35 | 4338 | ("stream subprogram for interface type must be null " |
4339 | & "procedure", Expr); | |
9f373bb8 | 4340 | end if; |
4341 | ||
4342 | Set_Entity (Expr, Subp); | |
4343 | Set_Etype (Expr, Etype (Subp)); | |
4344 | ||
44e4341e | 4345 | New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam); |
9f373bb8 | 4346 | |
4347 | else | |
4348 | Error_Msg_Name_1 := Attr; | |
4349 | Error_Msg_N ("incorrect expression for% attribute", Expr); | |
4350 | end if; | |
4351 | end Analyze_Stream_TSS_Definition; | |
4352 | ||
81b424ac | 4353 | ------------------------------ |
4354 | -- Check_Indexing_Functions -- | |
4355 | ------------------------------ | |
4356 | ||
4357 | procedure Check_Indexing_Functions is | |
c8a2d809 | 4358 | Indexing_Found : Boolean := False; |
8df4f2a5 | 4359 | |
44d567c8 | 4360 | procedure Check_Inherited_Indexing; |
4361 | -- For a derived type, check that no indexing aspect is specified | |
4362 | -- for the type if it is also inherited | |
4363 | ||
81b424ac | 4364 | procedure Check_One_Function (Subp : Entity_Id); |
7796365f | 4365 | -- Check one possible interpretation. Sets Indexing_Found True if a |
4366 | -- legal indexing function is found. | |
81b424ac | 4367 | |
05987af3 | 4368 | procedure Illegal_Indexing (Msg : String); |
4369 | -- Diagnose illegal indexing function if not overloaded. In the | |
4370 | -- overloaded case indicate that no legal interpretation exists. | |
4371 | ||
44d567c8 | 4372 | ------------------------------ |
4373 | -- Check_Inherited_Indexing -- | |
4374 | ------------------------------ | |
4375 | ||
4376 | procedure Check_Inherited_Indexing is | |
4377 | Inherited : Node_Id; | |
4378 | ||
4379 | begin | |
4380 | if Attr = Name_Constant_Indexing then | |
4381 | Inherited := | |
4382 | Find_Aspect (Etype (Ent), Aspect_Constant_Indexing); | |
4383 | else pragma Assert (Attr = Name_Variable_Indexing); | |
4384 | Inherited := | |
4385 | Find_Aspect (Etype (Ent), Aspect_Variable_Indexing); | |
4386 | end if; | |
4387 | ||
4388 | if Present (Inherited) then | |
4389 | if Debug_Flag_Dot_XX then | |
4390 | null; | |
4391 | ||
83d39cd3 | 4392 | -- OK if current attribute_definition_clause is expansion of |
4393 | -- inherited aspect. | |
44d567c8 | 4394 | |
4395 | elsif Aspect_Rep_Item (Inherited) = N then | |
4396 | null; | |
4397 | ||
83d39cd3 | 4398 | -- Indicate the operation that must be overridden, rather than |
4399 | -- redefining the indexing aspect. | |
44d567c8 | 4400 | |
4401 | else | |
4402 | Illegal_Indexing | |
f2837ceb | 4403 | ("indexing function already inherited from parent type"); |
44d567c8 | 4404 | Error_Msg_NE |
4405 | ("!override & instead", | |
4406 | N, Entity (Expression (Inherited))); | |
4407 | end if; | |
4408 | end if; | |
4409 | end Check_Inherited_Indexing; | |
4410 | ||
81b424ac | 4411 | ------------------------ |
4412 | -- Check_One_Function -- | |
4413 | ------------------------ | |
4414 | ||
4415 | procedure Check_One_Function (Subp : Entity_Id) is | |
05987af3 | 4416 | Default_Element : Node_Id; |
4417 | Ret_Type : constant Entity_Id := Etype (Subp); | |
1b7510f9 | 4418 | |
81b424ac | 4419 | begin |
05987af3 | 4420 | if not Is_Overloadable (Subp) then |
4421 | Illegal_Indexing ("illegal indexing function for type&"); | |
4422 | return; | |
4423 | ||
7796365f | 4424 | elsif Scope (Subp) /= Scope (Ent) then |
4425 | if Nkind (Expr) = N_Expanded_Name then | |
4426 | ||
4427 | -- Indexing function can't be declared elsewhere | |
4428 | ||
4429 | Illegal_Indexing | |
4430 | ("indexing function must be declared in scope of type&"); | |
4431 | end if; | |
4432 | ||
05987af3 | 4433 | return; |
4434 | ||
4435 | elsif No (First_Formal (Subp)) then | |
4436 | Illegal_Indexing | |
4437 | ("Indexing requires a function that applies to type&"); | |
4438 | return; | |
4439 | ||
4440 | elsif No (Next_Formal (First_Formal (Subp))) then | |
4441 | Illegal_Indexing | |
2eb0ff42 | 4442 | ("indexing function must have at least two parameters"); |
05987af3 | 4443 | return; |
4444 | ||
4445 | elsif Is_Derived_Type (Ent) then | |
44d567c8 | 4446 | Check_Inherited_Indexing; |
05987af3 | 4447 | end if; |
4448 | ||
e81df51c | 4449 | if not Check_Primitive_Function (Subp) then |
05987af3 | 4450 | Illegal_Indexing |
4451 | ("Indexing aspect requires a function that applies to type&"); | |
4452 | return; | |
81b424ac | 4453 | end if; |
4454 | ||
7796365f | 4455 | -- If partial declaration exists, verify that it is not tagged. |
4456 | ||
4457 | if Ekind (Current_Scope) = E_Package | |
4458 | and then Has_Private_Declaration (Ent) | |
4459 | and then From_Aspect_Specification (N) | |
7c0c95b8 | 4460 | and then |
4461 | List_Containing (Parent (Ent)) = | |
4462 | Private_Declarations | |
7796365f | 4463 | (Specification (Unit_Declaration_Node (Current_Scope))) |
4464 | and then Nkind (N) = N_Attribute_Definition_Clause | |
4465 | then | |
4466 | declare | |
4467 | Decl : Node_Id; | |
4468 | ||
4469 | begin | |
4470 | Decl := | |
4471 | First (Visible_Declarations | |
7c0c95b8 | 4472 | (Specification |
4473 | (Unit_Declaration_Node (Current_Scope)))); | |
7796365f | 4474 | |
4475 | while Present (Decl) loop | |
4476 | if Nkind (Decl) = N_Private_Type_Declaration | |
4477 | and then Ent = Full_View (Defining_Identifier (Decl)) | |
4478 | and then Tagged_Present (Decl) | |
4479 | and then No (Aspect_Specifications (Decl)) | |
4480 | then | |
4481 | Illegal_Indexing | |
4482 | ("Indexing aspect cannot be specified on full view " | |
7c0c95b8 | 4483 | & "if partial view is tagged"); |
7796365f | 4484 | return; |
4485 | end if; | |
4486 | ||
4487 | Next (Decl); | |
4488 | end loop; | |
4489 | end; | |
4490 | end if; | |
4491 | ||
1b7510f9 | 4492 | -- An indexing function must return either the default element of |
cac18f71 | 4493 | -- the container, or a reference type. For variable indexing it |
a45d946f | 4494 | -- must be the latter. |
1b7510f9 | 4495 | |
05987af3 | 4496 | Default_Element := |
4497 | Find_Value_Of_Aspect | |
4498 | (Etype (First_Formal (Subp)), Aspect_Iterator_Element); | |
4499 | ||
1b7510f9 | 4500 | if Present (Default_Element) then |
4501 | Analyze (Default_Element); | |
1b7510f9 | 4502 | end if; |
4503 | ||
a45d946f | 4504 | -- For variable_indexing the return type must be a reference type |
1b7510f9 | 4505 | |
05987af3 | 4506 | if Attr = Name_Variable_Indexing then |
4507 | if not Has_Implicit_Dereference (Ret_Type) then | |
4508 | Illegal_Indexing | |
4509 | ("variable indexing must return a reference type"); | |
4510 | return; | |
4511 | ||
423b89fd | 4512 | elsif Is_Access_Constant |
4513 | (Etype (First_Discriminant (Ret_Type))) | |
05987af3 | 4514 | then |
4515 | Illegal_Indexing | |
4516 | ("variable indexing must return an access to variable"); | |
4517 | return; | |
4518 | end if; | |
cac18f71 | 4519 | |
4520 | else | |
05987af3 | 4521 | if Has_Implicit_Dereference (Ret_Type) |
4522 | and then not | |
4523 | Is_Access_Constant (Etype (First_Discriminant (Ret_Type))) | |
4524 | then | |
4525 | Illegal_Indexing | |
4526 | ("constant indexing must return an access to constant"); | |
4527 | return; | |
4528 | ||
4529 | elsif Is_Access_Type (Etype (First_Formal (Subp))) | |
4530 | and then not Is_Access_Constant (Etype (First_Formal (Subp))) | |
4531 | then | |
4532 | Illegal_Indexing | |
4533 | ("constant indexing must apply to an access to constant"); | |
4534 | return; | |
4535 | end if; | |
81b424ac | 4536 | end if; |
05987af3 | 4537 | |
4538 | -- All checks succeeded. | |
4539 | ||
4540 | Indexing_Found := True; | |
81b424ac | 4541 | end Check_One_Function; |
4542 | ||
05987af3 | 4543 | ----------------------- |
4544 | -- Illegal_Indexing -- | |
4545 | ----------------------- | |
4546 | ||
4547 | procedure Illegal_Indexing (Msg : String) is | |
4548 | begin | |
7796365f | 4549 | Error_Msg_NE (Msg, N, Ent); |
05987af3 | 4550 | end Illegal_Indexing; |
4551 | ||
81b424ac | 4552 | -- Start of processing for Check_Indexing_Functions |
4553 | ||
4554 | begin | |
89cc7147 | 4555 | if In_Instance then |
44d567c8 | 4556 | Check_Inherited_Indexing; |
89cc7147 | 4557 | end if; |
4558 | ||
81b424ac | 4559 | Analyze (Expr); |
4560 | ||
4561 | if not Is_Overloaded (Expr) then | |
4562 | Check_One_Function (Entity (Expr)); | |
4563 | ||
4564 | else | |
4565 | declare | |
2c5754de | 4566 | I : Interp_Index; |
81b424ac | 4567 | It : Interp; |
4568 | ||
4569 | begin | |
cac18f71 | 4570 | Indexing_Found := False; |
81b424ac | 4571 | Get_First_Interp (Expr, I, It); |
4572 | while Present (It.Nam) loop | |
4573 | ||
4574 | -- Note that analysis will have added the interpretation | |
4575 | -- that corresponds to the dereference. We only check the | |
1ef2e6ef | 4576 | -- subprogram itself. Ignore homonyms that may come from |
4577 | -- derived types in the context. | |
81b424ac | 4578 | |
1ef2e6ef | 4579 | if Is_Overloadable (It.Nam) |
4580 | and then Comes_From_Source (It.Nam) | |
4581 | then | |
4582 | Check_One_Function (It.Nam); | |
81b424ac | 4583 | end if; |
4584 | ||
4585 | Get_Next_Interp (I, It); | |
4586 | end loop; | |
4587 | end; | |
4588 | end if; | |
7796365f | 4589 | |
7c0c95b8 | 4590 | if not Indexing_Found and then not Error_Posted (N) then |
7796365f | 4591 | Error_Msg_NE |
1ef2e6ef | 4592 | ("aspect Indexing requires a local function that applies to " |
4593 | & "type&", Expr, Ent); | |
7796365f | 4594 | end if; |
81b424ac | 4595 | end Check_Indexing_Functions; |
4596 | ||
89cc7147 | 4597 | ------------------------------ |
4598 | -- Check_Iterator_Functions -- | |
4599 | ------------------------------ | |
4600 | ||
4601 | procedure Check_Iterator_Functions is | |
89cc7147 | 4602 | function Valid_Default_Iterator (Subp : Entity_Id) return Boolean; |
8df4f2a5 | 4603 | -- Check one possible interpretation for validity |
89cc7147 | 4604 | |
4605 | ---------------------------- | |
4606 | -- Valid_Default_Iterator -- | |
4607 | ---------------------------- | |
4608 | ||
4609 | function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is | |
8b8be176 | 4610 | Root_T : constant Entity_Id := Root_Type (Etype (Etype (Subp))); |
7f5dd8d8 | 4611 | Formal : Entity_Id; |
89cc7147 | 4612 | |
4613 | begin | |
4614 | if not Check_Primitive_Function (Subp) then | |
4615 | return False; | |
8b8be176 | 4616 | |
4617 | -- The return type must be derived from a type in an instance | |
4618 | -- of Iterator.Interfaces, and thus its root type must have a | |
4619 | -- predefined name. | |
4620 | ||
4621 | elsif Chars (Root_T) /= Name_Forward_Iterator | |
4622 | and then Chars (Root_T) /= Name_Reversible_Iterator | |
4623 | then | |
4624 | return False; | |
4625 | ||
89cc7147 | 4626 | else |
4627 | Formal := First_Formal (Subp); | |
4628 | end if; | |
4629 | ||
8df4f2a5 | 4630 | -- False if any subsequent formal has no default expression |
89cc7147 | 4631 | |
8df4f2a5 | 4632 | Formal := Next_Formal (Formal); |
4633 | while Present (Formal) loop | |
4634 | if No (Expression (Parent (Formal))) then | |
4635 | return False; | |
4636 | end if; | |
89cc7147 | 4637 | |
8df4f2a5 | 4638 | Next_Formal (Formal); |
4639 | end loop; | |
89cc7147 | 4640 | |
8df4f2a5 | 4641 | -- True if all subsequent formals have default expressions |
89cc7147 | 4642 | |
4643 | return True; | |
4644 | end Valid_Default_Iterator; | |
4645 | ||
4646 | -- Start of processing for Check_Iterator_Functions | |
4647 | ||
4648 | begin | |
4649 | Analyze (Expr); | |
4650 | ||
4651 | if not Is_Entity_Name (Expr) then | |
4652 | Error_Msg_N ("aspect Iterator must be a function name", Expr); | |
4653 | end if; | |
4654 | ||
4655 | if not Is_Overloaded (Expr) then | |
f6bd78dd | 4656 | if Entity (Expr) /= Any_Id |
4657 | and then not Check_Primitive_Function (Entity (Expr)) | |
4658 | then | |
89cc7147 | 4659 | Error_Msg_NE |
4660 | ("aspect Indexing requires a function that applies to type&", | |
f6bd78dd | 4661 | Entity (Expr), Ent); |
89cc7147 | 4662 | end if; |
4663 | ||
05f6f999 | 4664 | -- Flag the default_iterator as well as the denoted function. |
4665 | ||
89cc7147 | 4666 | if not Valid_Default_Iterator (Entity (Expr)) then |
05f6f999 | 4667 | Error_Msg_N ("improper function for default iterator!", Expr); |
89cc7147 | 4668 | end if; |
4669 | ||
4670 | else | |
89cc7147 | 4671 | declare |
270ee9c5 | 4672 | Default : Entity_Id := Empty; |
8be33fbe | 4673 | I : Interp_Index; |
4674 | It : Interp; | |
89cc7147 | 4675 | |
4676 | begin | |
4677 | Get_First_Interp (Expr, I, It); | |
4678 | while Present (It.Nam) loop | |
4679 | if not Check_Primitive_Function (It.Nam) | |
59f3e675 | 4680 | or else not Valid_Default_Iterator (It.Nam) |
89cc7147 | 4681 | then |
4682 | Remove_Interp (I); | |
4683 | ||
4684 | elsif Present (Default) then | |
89cc7147 | 4685 | |
8be33fbe | 4686 | -- An explicit one should override an implicit one |
4687 | ||
4688 | if Comes_From_Source (Default) = | |
4689 | Comes_From_Source (It.Nam) | |
4690 | then | |
4691 | Error_Msg_N ("default iterator must be unique", Expr); | |
4692 | Error_Msg_Sloc := Sloc (Default); | |
4693 | Error_Msg_N ("\\possible interpretation#", Expr); | |
4694 | Error_Msg_Sloc := Sloc (It.Nam); | |
4695 | Error_Msg_N ("\\possible interpretation#", Expr); | |
4696 | ||
4697 | elsif Comes_From_Source (It.Nam) then | |
4698 | Default := It.Nam; | |
4699 | end if; | |
89cc7147 | 4700 | else |
4701 | Default := It.Nam; | |
4702 | end if; | |
4703 | ||
4704 | Get_Next_Interp (I, It); | |
4705 | end loop; | |
89cc7147 | 4706 | |
270ee9c5 | 4707 | if Present (Default) then |
4708 | Set_Entity (Expr, Default); | |
4709 | Set_Is_Overloaded (Expr, False); | |
8b8be176 | 4710 | else |
4711 | Error_Msg_N | |
7f5dd8d8 | 4712 | ("no interpretation is a valid default iterator!", Expr); |
270ee9c5 | 4713 | end if; |
4714 | end; | |
89cc7147 | 4715 | end if; |
4716 | end Check_Iterator_Functions; | |
4717 | ||
4718 | ------------------------------- | |
4719 | -- Check_Primitive_Function -- | |
4720 | ------------------------------- | |
4721 | ||
4722 | function Check_Primitive_Function (Subp : Entity_Id) return Boolean is | |
4723 | Ctrl : Entity_Id; | |
4724 | ||
4725 | begin | |
4726 | if Ekind (Subp) /= E_Function then | |
4727 | return False; | |
4728 | end if; | |
4729 | ||
4730 | if No (First_Formal (Subp)) then | |
4731 | return False; | |
4732 | else | |
4733 | Ctrl := Etype (First_Formal (Subp)); | |
4734 | end if; | |
4735 | ||
05f6f999 | 4736 | -- To be a primitive operation subprogram has to be in same scope. |
4737 | ||
4738 | if Scope (Ctrl) /= Scope (Subp) then | |
4739 | return False; | |
4740 | end if; | |
4741 | ||
7d6fb253 | 4742 | -- Type of formal may be the class-wide type, an access to such, |
4743 | -- or an incomplete view. | |
4744 | ||
89cc7147 | 4745 | if Ctrl = Ent |
4746 | or else Ctrl = Class_Wide_Type (Ent) | |
4747 | or else | |
4748 | (Ekind (Ctrl) = E_Anonymous_Access_Type | |
b85d62ec | 4749 | and then (Designated_Type (Ctrl) = Ent |
4750 | or else | |
4751 | Designated_Type (Ctrl) = Class_Wide_Type (Ent))) | |
7d6fb253 | 4752 | or else |
4753 | (Ekind (Ctrl) = E_Incomplete_Type | |
4754 | and then Full_View (Ctrl) = Ent) | |
89cc7147 | 4755 | then |
4756 | null; | |
89cc7147 | 4757 | else |
4758 | return False; | |
4759 | end if; | |
4760 | ||
4761 | return True; | |
4762 | end Check_Primitive_Function; | |
4763 | ||
ae888dbd | 4764 | ---------------------- |
4765 | -- Duplicate_Clause -- | |
4766 | ---------------------- | |
4767 | ||
4768 | function Duplicate_Clause return Boolean is | |
d74fc39a | 4769 | A : Node_Id; |
ae888dbd | 4770 | |
4771 | begin | |
c8969ba6 | 4772 | -- Nothing to do if this attribute definition clause comes from |
4773 | -- an aspect specification, since we could not be duplicating an | |
ae888dbd | 4774 | -- explicit clause, and we dealt with the case of duplicated aspects |
4775 | -- in Analyze_Aspect_Specifications. | |
4776 | ||
4777 | if From_Aspect_Specification (N) then | |
4778 | return False; | |
4779 | end if; | |
4780 | ||
89f1e35c | 4781 | -- Otherwise current clause may duplicate previous clause, or a |
4782 | -- previously given pragma or aspect specification for the same | |
4783 | -- aspect. | |
d74fc39a | 4784 | |
89b3b365 | 4785 | A := Get_Rep_Item (U_Ent, Chars (N), Check_Parents => False); |
ae888dbd | 4786 | |
4787 | if Present (A) then | |
89f1e35c | 4788 | Error_Msg_Name_1 := Chars (N); |
4789 | Error_Msg_Sloc := Sloc (A); | |
4790 | ||
89b3b365 | 4791 | Error_Msg_NE ("aspect% for & previously given#", N, U_Ent); |
89f1e35c | 4792 | return True; |
ae888dbd | 4793 | end if; |
4794 | ||
4795 | return False; | |
4796 | end Duplicate_Clause; | |
4797 | ||
9f373bb8 | 4798 | -- Start of processing for Analyze_Attribute_Definition_Clause |
4799 | ||
d6f39728 | 4800 | begin |
d64221a7 | 4801 | -- The following code is a defense against recursion. Not clear that |
51fa2a45 | 4802 | -- this can happen legitimately, but perhaps some error situations can |
4803 | -- cause it, and we did see this recursion during testing. | |
d64221a7 | 4804 | |
4805 | if Analyzed (N) then | |
4806 | return; | |
4807 | else | |
4808 | Set_Analyzed (N, True); | |
4809 | end if; | |
4810 | ||
2609e4d0 | 4811 | Check_Restriction_No_Use_Of_Attribute (N); |
4812 | ||
a29bc1d9 | 4813 | -- Ignore some selected attributes in CodePeer mode since they are not |
4814 | -- relevant in this context. | |
4815 | ||
4816 | if CodePeer_Mode then | |
4817 | case Id is | |
4818 | ||
4819 | -- Ignore Component_Size in CodePeer mode, to avoid changing the | |
4820 | -- internal representation of types by implicitly packing them. | |
4821 | ||
4822 | when Attribute_Component_Size => | |
4823 | Rewrite (N, Make_Null_Statement (Sloc (N))); | |
4824 | return; | |
4825 | ||
4826 | when others => | |
4827 | null; | |
4828 | end case; | |
4829 | end if; | |
4830 | ||
d8ba53a8 | 4831 | -- Process Ignore_Rep_Clauses option |
eef1ca1e | 4832 | |
d8ba53a8 | 4833 | if Ignore_Rep_Clauses then |
9d627c41 | 4834 | case Id is |
4835 | ||
eef1ca1e | 4836 | -- The following should be ignored. They do not affect legality |
4837 | -- and may be target dependent. The basic idea of -gnatI is to | |
4838 | -- ignore any rep clauses that may be target dependent but do not | |
4839 | -- affect legality (except possibly to be rejected because they | |
4840 | -- are incompatible with the compilation target). | |
9d627c41 | 4841 | |
99378362 | 4842 | when Attribute_Alignment |
4843 | | Attribute_Bit_Order | |
4844 | | Attribute_Component_Size | |
5bcff344 | 4845 | | Attribute_Default_Scalar_Storage_Order |
99378362 | 4846 | | Attribute_Machine_Radix |
4847 | | Attribute_Object_Size | |
5bcff344 | 4848 | | Attribute_Scalar_Storage_Order |
99378362 | 4849 | | Attribute_Size |
4850 | | Attribute_Small | |
4851 | | Attribute_Stream_Size | |
4852 | | Attribute_Value_Size | |
4853 | => | |
2ff55065 | 4854 | Kill_Rep_Clause (N); |
9d627c41 | 4855 | return; |
4856 | ||
eef1ca1e | 4857 | -- The following should not be ignored, because in the first place |
51fa2a45 | 4858 | -- they are reasonably portable, and should not cause problems |
4859 | -- in compiling code from another target, and also they do affect | |
4860 | -- legality, e.g. failing to provide a stream attribute for a type | |
4861 | -- may make a program illegal. | |
9d627c41 | 4862 | |
99378362 | 4863 | when Attribute_External_Tag |
4864 | | Attribute_Input | |
4865 | | Attribute_Output | |
4866 | | Attribute_Read | |
4867 | | Attribute_Simple_Storage_Pool | |
4868 | | Attribute_Storage_Pool | |
4869 | | Attribute_Storage_Size | |
4870 | | Attribute_Write | |
4871 | => | |
9d627c41 | 4872 | null; |
4873 | ||
2ff55065 | 4874 | -- We do not do anything here with address clauses, they will be |
4875 | -- removed by Freeze later on, but for now, it works better to | |
c07717de | 4876 | -- keep them in the tree. |
2ff55065 | 4877 | |
4878 | when Attribute_Address => | |
4879 | null; | |
4880 | ||
b593a52c | 4881 | -- Other cases are errors ("attribute& cannot be set with |
4882 | -- definition clause"), which will be caught below. | |
9d627c41 | 4883 | |
4884 | when others => | |
4885 | null; | |
4886 | end case; | |
fbc67f84 | 4887 | end if; |
4888 | ||
d6f39728 | 4889 | Analyze (Nam); |
4890 | Ent := Entity (Nam); | |
4891 | ||
4892 | if Rep_Item_Too_Early (Ent, N) then | |
4893 | return; | |
4894 | end if; | |
4895 | ||
9f373bb8 | 4896 | -- Rep clause applies to full view of incomplete type or private type if |
4897 | -- we have one (if not, this is a premature use of the type). However, | |
4898 | -- certain semantic checks need to be done on the specified entity (i.e. | |
4899 | -- the private view), so we save it in Ent. | |
d6f39728 | 4900 | |
4901 | if Is_Private_Type (Ent) | |
4902 | and then Is_Derived_Type (Ent) | |
4903 | and then not Is_Tagged_Type (Ent) | |
4904 | and then No (Full_View (Ent)) | |
4905 | then | |
9f373bb8 | 4906 | -- If this is a private type whose completion is a derivation from |
4907 | -- another private type, there is no full view, and the attribute | |
4908 | -- belongs to the type itself, not its underlying parent. | |
d6f39728 | 4909 | |
4910 | U_Ent := Ent; | |
4911 | ||
4912 | elsif Ekind (Ent) = E_Incomplete_Type then | |
d5b349fa | 4913 | |
9f373bb8 | 4914 | -- The attribute applies to the full view, set the entity of the |
4915 | -- attribute definition accordingly. | |
d5b349fa | 4916 | |
d6f39728 | 4917 | Ent := Underlying_Type (Ent); |
4918 | U_Ent := Ent; | |
d5b349fa | 4919 | Set_Entity (Nam, Ent); |
4920 | ||
d6f39728 | 4921 | else |
4922 | U_Ent := Underlying_Type (Ent); | |
4923 | end if; | |
4924 | ||
44705307 | 4925 | -- Avoid cascaded error |
d6f39728 | 4926 | |
4927 | if Etype (Nam) = Any_Type then | |
4928 | return; | |
4929 | ||
89f1e35c | 4930 | -- Must be declared in current scope or in case of an aspect |
ace3389d | 4931 | -- specification, must be visible in current scope. |
44705307 | 4932 | |
89f1e35c | 4933 | elsif Scope (Ent) /= Current_Scope |
ace3389d | 4934 | and then |
4935 | not (From_Aspect_Specification (N) | |
4936 | and then Scope_Within_Or_Same (Current_Scope, Scope (Ent))) | |
89f1e35c | 4937 | then |
d6f39728 | 4938 | Error_Msg_N ("entity must be declared in this scope", Nam); |
4939 | return; | |
4940 | ||
44705307 | 4941 | -- Must not be a source renaming (we do have some cases where the |
4942 | -- expander generates a renaming, and those cases are OK, in such | |
a3248fc4 | 4943 | -- cases any attribute applies to the renamed object as well). |
44705307 | 4944 | |
4945 | elsif Is_Object (Ent) | |
4946 | and then Present (Renamed_Object (Ent)) | |
44705307 | 4947 | then |
8699de72 | 4948 | -- In the case of a renamed object from source, this is an error |
4949 | -- unless the object is an aggregate and the renaming is created | |
4950 | -- for an object declaration. | |
a3248fc4 | 4951 | |
0396441f | 4952 | if Comes_From_Source (Renamed_Object (Ent)) |
4953 | and then Nkind (Renamed_Object (Ent)) /= N_Aggregate | |
4954 | then | |
a3248fc4 | 4955 | Get_Name_String (Chars (N)); |
4956 | Error_Msg_Strlen := Name_Len; | |
4957 | Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); | |
4958 | Error_Msg_N | |
4959 | ("~ clause not allowed for a renaming declaration " | |
4960 | & "(RM 13.1(6))", Nam); | |
4961 | return; | |
4962 | ||
4963 | -- For the case of a compiler generated renaming, the attribute | |
4964 | -- definition clause applies to the renamed object created by the | |
4965 | -- expander. The easiest general way to handle this is to create a | |
4966 | -- copy of the attribute definition clause for this object. | |
4967 | ||
9a48fc56 | 4968 | elsif Is_Entity_Name (Renamed_Object (Ent)) then |
a3248fc4 | 4969 | Insert_Action (N, |
4970 | Make_Attribute_Definition_Clause (Loc, | |
4971 | Name => | |
4972 | New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc), | |
4973 | Chars => Chars (N), | |
4974 | Expression => Duplicate_Subexpr (Expression (N)))); | |
9a48fc56 | 4975 | |
4976 | -- If the renamed object is not an entity, it must be a dereference | |
4977 | -- of an unconstrained function call, and we must introduce a new | |
4978 | -- declaration to capture the expression. This is needed in the case | |
4979 | -- of 'Alignment, where the original declaration must be rewritten. | |
4980 | ||
4981 | else | |
4982 | pragma Assert | |
4983 | (Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference); | |
4984 | null; | |
a3248fc4 | 4985 | end if; |
44705307 | 4986 | |
4987 | -- If no underlying entity, use entity itself, applies to some | |
4988 | -- previously detected error cases ??? | |
4989 | ||
f15731c4 | 4990 | elsif No (U_Ent) then |
4991 | U_Ent := Ent; | |
4992 | ||
44705307 | 4993 | -- Cannot specify for a subtype (exception Object/Value_Size) |
4994 | ||
d6f39728 | 4995 | elsif Is_Type (U_Ent) |
4996 | and then not Is_First_Subtype (U_Ent) | |
4997 | and then Id /= Attribute_Object_Size | |
4998 | and then Id /= Attribute_Value_Size | |
4999 | and then not From_At_Mod (N) | |
5000 | then | |
5001 | Error_Msg_N ("cannot specify attribute for subtype", Nam); | |
5002 | return; | |
d6f39728 | 5003 | end if; |
5004 | ||
ae888dbd | 5005 | Set_Entity (N, U_Ent); |
5006 | ||
d6f39728 | 5007 | -- Switch on particular attribute |
5008 | ||
5009 | case Id is | |
5010 | ||
5011 | ------------- | |
5012 | -- Address -- | |
5013 | ------------- | |
5014 | ||
5015 | -- Address attribute definition clause | |
5016 | ||
5017 | when Attribute_Address => Address : begin | |
177675a7 | 5018 | |
5019 | -- A little error check, catch for X'Address use X'Address; | |
5020 | ||
5021 | if Nkind (Nam) = N_Identifier | |
5022 | and then Nkind (Expr) = N_Attribute_Reference | |
5023 | and then Attribute_Name (Expr) = Name_Address | |
5024 | and then Nkind (Prefix (Expr)) = N_Identifier | |
5025 | and then Chars (Nam) = Chars (Prefix (Expr)) | |
5026 | then | |
5027 | Error_Msg_NE | |
5028 | ("address for & is self-referencing", Prefix (Expr), Ent); | |
5029 | return; | |
5030 | end if; | |
5031 | ||
5032 | -- Not that special case, carry on with analysis of expression | |
5033 | ||
d6f39728 | 5034 | Analyze_And_Resolve (Expr, RTE (RE_Address)); |
5035 | ||
2f1aac99 | 5036 | -- Even when ignoring rep clauses we need to indicate that the |
5037 | -- entity has an address clause and thus it is legal to declare | |
2ff55065 | 5038 | -- it imported. Freeze will get rid of the address clause later. |
c07717de | 5039 | -- Also call Set_Address_Taken to indicate that an address clause |
5040 | -- was present, even if we are about to remove it. | |
2f1aac99 | 5041 | |
5042 | if Ignore_Rep_Clauses then | |
c07717de | 5043 | Set_Address_Taken (U_Ent); |
5044 | ||
d3ef794c | 5045 | if Ekind_In (U_Ent, E_Variable, E_Constant) then |
2f1aac99 | 5046 | Record_Rep_Item (U_Ent, N); |
5047 | end if; | |
5048 | ||
5049 | return; | |
5050 | end if; | |
5051 | ||
ae888dbd | 5052 | if Duplicate_Clause then |
5053 | null; | |
d6f39728 | 5054 | |
5055 | -- Case of address clause for subprogram | |
5056 | ||
5057 | elsif Is_Subprogram (U_Ent) then | |
d6f39728 | 5058 | if Has_Homonym (U_Ent) then |
5059 | Error_Msg_N | |
f74a102b | 5060 | ("address clause cannot be given for overloaded " |
5061 | & "subprogram", Nam); | |
83f8f0a6 | 5062 | return; |
d6f39728 | 5063 | end if; |
5064 | ||
83f8f0a6 | 5065 | -- For subprograms, all address clauses are permitted, and we |
5066 | -- mark the subprogram as having a deferred freeze so that Gigi | |
5067 | -- will not elaborate it too soon. | |
d6f39728 | 5068 | |
5069 | -- Above needs more comments, what is too soon about??? | |
5070 | ||
5071 | Set_Has_Delayed_Freeze (U_Ent); | |
5072 | ||
5073 | -- Case of address clause for entry | |
5074 | ||
5075 | elsif Ekind (U_Ent) = E_Entry then | |
d6f39728 | 5076 | if Nkind (Parent (N)) = N_Task_Body then |
5077 | Error_Msg_N | |
5078 | ("entry address must be specified in task spec", Nam); | |
83f8f0a6 | 5079 | return; |
d6f39728 | 5080 | end if; |
5081 | ||
5082 | -- For entries, we require a constant address | |
5083 | ||
5084 | Check_Constant_Address_Clause (Expr, U_Ent); | |
5085 | ||
83f8f0a6 | 5086 | -- Special checks for task types |
5087 | ||
f15731c4 | 5088 | if Is_Task_Type (Scope (U_Ent)) |
5089 | and then Comes_From_Source (Scope (U_Ent)) | |
5090 | then | |
5091 | Error_Msg_N | |
1e3532e7 | 5092 | ("??entry address declared for entry in task type", N); |
f15731c4 | 5093 | Error_Msg_N |
1e3532e7 | 5094 | ("\??only one task can be declared of this type", N); |
f15731c4 | 5095 | end if; |
5096 | ||
83f8f0a6 | 5097 | -- Entry address clauses are obsolescent |
5098 | ||
e0521a36 | 5099 | Check_Restriction (No_Obsolescent_Features, N); |
5100 | ||
9dfe12ae | 5101 | if Warn_On_Obsolescent_Feature then |
5102 | Error_Msg_N | |
f74a102b | 5103 | ("?j?attaching interrupt to task entry is an obsolescent " |
5104 | & "feature (RM J.7.1)", N); | |
9dfe12ae | 5105 | Error_Msg_N |
1e3532e7 | 5106 | ("\?j?use interrupt procedure instead", N); |
9dfe12ae | 5107 | end if; |
5108 | ||
8c252f6f | 5109 | -- Case of an address clause for a class-wide object, which is |
5110559b | 5110 | -- considered erroneous. |
5111 | ||
5112 | elsif Is_Class_Wide_Type (Etype (U_Ent)) then | |
5113 | Error_Msg_NE | |
5114 | ("??class-wide object & must not be overlaid", Nam, U_Ent); | |
9dfe12ae | 5115 | Error_Msg_N |
1e3532e7 | 5116 | ("\??Program_Error will be raised at run time", Nam); |
9dfe12ae | 5117 | Insert_Action (Declaration_Node (U_Ent), |
5118 | Make_Raise_Program_Error (Loc, | |
5119 | Reason => PE_Overlaid_Controlled_Object)); | |
83f8f0a6 | 5120 | return; |
9dfe12ae | 5121 | |
76be83f9 | 5122 | -- Case of address clause for an object |
d6f39728 | 5123 | |
76be83f9 | 5124 | elsif Ekind_In (U_Ent, E_Constant, E_Variable) then |
d6f39728 | 5125 | declare |
d6da7448 | 5126 | Expr : constant Node_Id := Expression (N); |
5127 | O_Ent : Entity_Id; | |
5128 | Off : Boolean; | |
d6f39728 | 5129 | |
5130 | begin | |
7ee315cc | 5131 | -- Exported variables cannot have an address clause, because |
5132 | -- this cancels the effect of the pragma Export. | |
d6f39728 | 5133 | |
5134 | if Is_Exported (U_Ent) then | |
5135 | Error_Msg_N | |
5136 | ("cannot export object with address clause", Nam); | |
83f8f0a6 | 5137 | return; |
d6da7448 | 5138 | end if; |
5139 | ||
5140 | Find_Overlaid_Entity (N, O_Ent, Off); | |
d6f39728 | 5141 | |
a9dd889b | 5142 | if Present (O_Ent) then |
798dec73 | 5143 | |
a9dd889b | 5144 | -- If the object overlays a constant object, mark it so |
b2d32174 | 5145 | |
a9dd889b | 5146 | if Is_Constant_Object (O_Ent) then |
5147 | Set_Overlays_Constant (U_Ent); | |
5148 | end if; | |
798dec73 | 5149 | |
514a5555 | 5150 | -- If the address clause is of the form: |
5151 | ||
5152 | -- for X'Address use Y'Address; | |
5153 | ||
5154 | -- or | |
5155 | ||
5156 | -- C : constant Address := Y'Address; | |
5157 | -- ... | |
5158 | -- for X'Address use C; | |
5159 | ||
5160 | -- then we make an entry in the table to check the size | |
5161 | -- and alignment of the overlaying variable. But we defer | |
5162 | -- this check till after code generation to take full | |
5163 | -- advantage of the annotation done by the back end. | |
5164 | ||
5165 | -- If the entity has a generic type, the check will be | |
5166 | -- performed in the instance if the actual type justifies | |
5167 | -- it, and we do not insert the clause in the table to | |
5168 | -- prevent spurious warnings. | |
5169 | ||
5170 | -- Note: we used to test Comes_From_Source and only give | |
5171 | -- this warning for source entities, but we have removed | |
5172 | -- this test. It really seems bogus to generate overlays | |
5173 | -- that would trigger this warning in generated code. | |
5174 | -- Furthermore, by removing the test, we handle the | |
5175 | -- aspect case properly. | |
5176 | ||
5177 | if Is_Object (O_Ent) | |
703ee0e0 | 5178 | and then not Is_Generic_Formal (O_Ent) |
514a5555 | 5179 | and then not Is_Generic_Type (Etype (U_Ent)) |
5180 | and then Address_Clause_Overlay_Warnings | |
5181 | then | |
d10a1b95 | 5182 | Register_Address_Clause_Check |
5183 | (N, U_Ent, No_Uint, O_Ent, Off); | |
514a5555 | 5184 | end if; |
9ab70407 | 5185 | |
5186 | -- If the overlay changes the storage order, mark the | |
5187 | -- entity as being volatile to block any optimization | |
5188 | -- for it since the construct is not really supported | |
5189 | -- by the back end. | |
5190 | ||
5191 | if (Is_Record_Type (Etype (U_Ent)) | |
5192 | or else Is_Array_Type (Etype (U_Ent))) | |
5193 | and then (Is_Record_Type (Etype (O_Ent)) | |
5194 | or else Is_Array_Type (Etype (O_Ent))) | |
88d1247a | 5195 | and then Reverse_Storage_Order (Etype (U_Ent)) /= |
5196 | Reverse_Storage_Order (Etype (O_Ent)) | |
9ab70407 | 5197 | then |
5198 | Set_Treat_As_Volatile (U_Ent); | |
5199 | end if; | |
5200 | ||
a9dd889b | 5201 | else |
5202 | -- If this is not an overlay, mark a variable as being | |
5203 | -- volatile to prevent unwanted optimizations. It's a | |
5204 | -- conservative interpretation of RM 13.3(19) for the | |
5205 | -- cases where the compiler cannot detect potential | |
5206 | -- aliasing issues easily and it also covers the case | |
5207 | -- of an absolute address where the volatile aspect is | |
5208 | -- kind of implicit. | |
5209 | ||
5210 | if Ekind (U_Ent) = E_Variable then | |
5211 | Set_Treat_As_Volatile (U_Ent); | |
5212 | end if; | |
514a5555 | 5213 | |
5214 | -- Make an entry in the table for an absolute address as | |
5215 | -- above to check that the value is compatible with the | |
5216 | -- alignment of the object. | |
5217 | ||
5218 | declare | |
5219 | Addr : constant Node_Id := Address_Value (Expr); | |
5220 | begin | |
5221 | if Compile_Time_Known_Value (Addr) | |
5222 | and then Address_Clause_Overlay_Warnings | |
5223 | then | |
d10a1b95 | 5224 | Register_Address_Clause_Check |
5225 | (N, U_Ent, Expr_Value (Addr), Empty, False); | |
514a5555 | 5226 | end if; |
5227 | end; | |
b2d32174 | 5228 | end if; |
5229 | ||
95009d64 | 5230 | -- Issue an unconditional warning for a constant overlaying |
5231 | -- a variable. For the reverse case, we will issue it only | |
b2d32174 | 5232 | -- if the variable is modified. |
95009d64 | 5233 | |
76be83f9 | 5234 | if Ekind (U_Ent) = E_Constant |
95009d64 | 5235 | and then Present (O_Ent) |
b2d32174 | 5236 | and then not Overlays_Constant (U_Ent) |
5237 | and then Address_Clause_Overlay_Warnings | |
9dfe12ae | 5238 | then |
1e3532e7 | 5239 | Error_Msg_N ("??constant overlays a variable", Expr); |
9dfe12ae | 5240 | |
d6f39728 | 5241 | -- Imported variables can have an address clause, but then |
5242 | -- the import is pretty meaningless except to suppress | |
5243 | -- initializations, so we do not need such variables to | |
5244 | -- be statically allocated (and in fact it causes trouble | |
5245 | -- if the address clause is a local value). | |
5246 | ||
5247 | elsif Is_Imported (U_Ent) then | |
5248 | Set_Is_Statically_Allocated (U_Ent, False); | |
5249 | end if; | |
5250 | ||
5251 | -- We mark a possible modification of a variable with an | |
5252 | -- address clause, since it is likely aliasing is occurring. | |
5253 | ||
177675a7 | 5254 | Note_Possible_Modification (Nam, Sure => False); |
d6f39728 | 5255 | |
9dfe12ae | 5256 | -- Legality checks on the address clause for initialized |
5257 | -- objects is deferred until the freeze point, because | |
2beb22b1 | 5258 | -- a subsequent pragma might indicate that the object |
42e09e36 | 5259 | -- is imported and thus not initialized. Also, the address |
5260 | -- clause might involve entities that have yet to be | |
5261 | -- elaborated. | |
9dfe12ae | 5262 | |
5263 | Set_Has_Delayed_Freeze (U_Ent); | |
5264 | ||
51ad5ad2 | 5265 | -- If an initialization call has been generated for this |
5266 | -- object, it needs to be deferred to after the freeze node | |
5267 | -- we have just now added, otherwise GIGI will see a | |
5268 | -- reference to the variable (as actual to the IP call) | |
5269 | -- before its definition. | |
5270 | ||
5271 | declare | |
df9fba45 | 5272 | Init_Call : constant Node_Id := |
5273 | Remove_Init_Call (U_Ent, N); | |
4bba0a8d | 5274 | |
51ad5ad2 | 5275 | begin |
5276 | if Present (Init_Call) then | |
28a4283c | 5277 | Append_Freeze_Action (U_Ent, Init_Call); |
df9fba45 | 5278 | |
28a4283c | 5279 | -- Reset Initialization_Statements pointer so that |
5280 | -- if there is a pragma Import further down, it can | |
5281 | -- clear any default initialization. | |
df9fba45 | 5282 | |
28a4283c | 5283 | Set_Initialization_Statements (U_Ent, Init_Call); |
51ad5ad2 | 5284 | end if; |
5285 | end; | |
5286 | ||
44e4341e | 5287 | -- Entity has delayed freeze, so we will generate an |
5288 | -- alignment check at the freeze point unless suppressed. | |
d6f39728 | 5289 | |
44e4341e | 5290 | if not Range_Checks_Suppressed (U_Ent) |
5291 | and then not Alignment_Checks_Suppressed (U_Ent) | |
5292 | then | |
5293 | Set_Check_Address_Alignment (N); | |
5294 | end if; | |
d6f39728 | 5295 | |
5296 | -- Kill the size check code, since we are not allocating | |
5297 | -- the variable, it is somewhere else. | |
5298 | ||
5299 | Kill_Size_Check_Code (U_Ent); | |
d6da7448 | 5300 | end; |
83f8f0a6 | 5301 | |
d6f39728 | 5302 | -- Not a valid entity for an address clause |
5303 | ||
5304 | else | |
5305 | Error_Msg_N ("address cannot be given for &", Nam); | |
5306 | end if; | |
5307 | end Address; | |
5308 | ||
5309 | --------------- | |
5310 | -- Alignment -- | |
5311 | --------------- | |
5312 | ||
5313 | -- Alignment attribute definition clause | |
5314 | ||
b47769f0 | 5315 | when Attribute_Alignment => Alignment : declare |
208fd589 | 5316 | Align : constant Uint := Get_Alignment_Value (Expr); |
5317 | Max_Align : constant Uint := UI_From_Int (Maximum_Alignment); | |
41331dcf | 5318 | |
d6f39728 | 5319 | begin |
5320 | FOnly := True; | |
5321 | ||
5322 | if not Is_Type (U_Ent) | |
5323 | and then Ekind (U_Ent) /= E_Variable | |
5324 | and then Ekind (U_Ent) /= E_Constant | |
5325 | then | |
5326 | Error_Msg_N ("alignment cannot be given for &", Nam); | |
5327 | ||
ae888dbd | 5328 | elsif Duplicate_Clause then |
5329 | null; | |
d6f39728 | 5330 | |
5331 | elsif Align /= No_Uint then | |
5332 | Set_Has_Alignment_Clause (U_Ent); | |
208fd589 | 5333 | |
44705307 | 5334 | -- Tagged type case, check for attempt to set alignment to a |
f74a102b | 5335 | -- value greater than Max_Align, and reset if so. This error |
5336 | -- is suppressed in ASIS mode to allow for different ASIS | |
f9906591 | 5337 | -- back ends or ASIS-based tools to query the illegal clause. |
44705307 | 5338 | |
f74a102b | 5339 | if Is_Tagged_Type (U_Ent) |
5340 | and then Align > Max_Align | |
5341 | and then not ASIS_Mode | |
5342 | then | |
208fd589 | 5343 | Error_Msg_N |
1e3532e7 | 5344 | ("alignment for & set to Maximum_Aligment??", Nam); |
f74a102b | 5345 | Set_Alignment (U_Ent, Max_Align); |
44705307 | 5346 | |
5347 | -- All other cases | |
5348 | ||
208fd589 | 5349 | else |
5350 | Set_Alignment (U_Ent, Align); | |
5351 | end if; | |
b47769f0 | 5352 | |
5353 | -- For an array type, U_Ent is the first subtype. In that case, | |
5354 | -- also set the alignment of the anonymous base type so that | |
5355 | -- other subtypes (such as the itypes for aggregates of the | |
5356 | -- type) also receive the expected alignment. | |
5357 | ||
5358 | if Is_Array_Type (U_Ent) then | |
5359 | Set_Alignment (Base_Type (U_Ent), Align); | |
5360 | end if; | |
d6f39728 | 5361 | end if; |
b47769f0 | 5362 | end Alignment; |
d6f39728 | 5363 | |
5364 | --------------- | |
5365 | -- Bit_Order -- | |
5366 | --------------- | |
5367 | ||
5368 | -- Bit_Order attribute definition clause | |
5369 | ||
99378362 | 5370 | when Attribute_Bit_Order => |
d6f39728 | 5371 | if not Is_Record_Type (U_Ent) then |
5372 | Error_Msg_N | |
5373 | ("Bit_Order can only be defined for record type", Nam); | |
5374 | ||
ddf6e250 | 5375 | elsif Is_Tagged_Type (U_Ent) and then Is_Derived_Type (U_Ent) then |
0a6b7a8e | 5376 | Error_Msg_N |
5377 | ("Bit_Order cannot be defined for record extensions", Nam); | |
5378 | ||
ae888dbd | 5379 | elsif Duplicate_Clause then |
5380 | null; | |
5381 | ||
d6f39728 | 5382 | else |
5383 | Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); | |
5384 | ||
5385 | if Etype (Expr) = Any_Type then | |
5386 | return; | |
5387 | ||
cda40848 | 5388 | elsif not Is_OK_Static_Expression (Expr) then |
9dfe12ae | 5389 | Flag_Non_Static_Expr |
5390 | ("Bit_Order requires static expression!", Expr); | |
d6f39728 | 5391 | |
ddf6e250 | 5392 | elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then |
5393 | Set_Reverse_Bit_Order (Base_Type (U_Ent), True); | |
d6f39728 | 5394 | end if; |
5395 | end if; | |
d6f39728 | 5396 | |
5397 | -------------------- | |
5398 | -- Component_Size -- | |
5399 | -------------------- | |
5400 | ||
5401 | -- Component_Size attribute definition clause | |
5402 | ||
5403 | when Attribute_Component_Size => Component_Size_Case : declare | |
5404 | Csize : constant Uint := Static_Integer (Expr); | |
a0fc8c5b | 5405 | Ctyp : Entity_Id; |
d6f39728 | 5406 | Btype : Entity_Id; |
5407 | Biased : Boolean; | |
5408 | New_Ctyp : Entity_Id; | |
5409 | Decl : Node_Id; | |
5410 | ||
5411 | begin | |
5412 | if not Is_Array_Type (U_Ent) then | |
5413 | Error_Msg_N ("component size requires array type", Nam); | |
5414 | return; | |
5415 | end if; | |
5416 | ||
5417 | Btype := Base_Type (U_Ent); | |
f74a102b | 5418 | Ctyp := Component_Type (Btype); |
d6f39728 | 5419 | |
ae888dbd | 5420 | if Duplicate_Clause then |
5421 | null; | |
d6f39728 | 5422 | |
f3e4db96 | 5423 | elsif Rep_Item_Too_Early (Btype, N) then |
5424 | null; | |
5425 | ||
d6f39728 | 5426 | elsif Csize /= No_Uint then |
a0fc8c5b | 5427 | Check_Size (Expr, Ctyp, Csize, Biased); |
d6f39728 | 5428 | |
d74fc39a | 5429 | -- For the biased case, build a declaration for a subtype that |
5430 | -- will be used to represent the biased subtype that reflects | |
5431 | -- the biased representation of components. We need the subtype | |
5432 | -- to get proper conversions on referencing elements of the | |
36ac5fbb | 5433 | -- array. |
3062c401 | 5434 | |
36ac5fbb | 5435 | if Biased then |
5436 | New_Ctyp := | |
5437 | Make_Defining_Identifier (Loc, | |
5438 | Chars => | |
5439 | New_External_Name (Chars (U_Ent), 'C', 0, 'T')); | |
3062c401 | 5440 | |
36ac5fbb | 5441 | Decl := |
5442 | Make_Subtype_Declaration (Loc, | |
5443 | Defining_Identifier => New_Ctyp, | |
5444 | Subtype_Indication => | |
5445 | New_Occurrence_Of (Component_Type (Btype), Loc)); | |
5446 | ||
5447 | Set_Parent (Decl, N); | |
5448 | Analyze (Decl, Suppress => All_Checks); | |
5449 | ||
5450 | Set_Has_Delayed_Freeze (New_Ctyp, False); | |
5451 | Set_Esize (New_Ctyp, Csize); | |
5452 | Set_RM_Size (New_Ctyp, Csize); | |
5453 | Init_Alignment (New_Ctyp); | |
5454 | Set_Is_Itype (New_Ctyp, True); | |
5455 | Set_Associated_Node_For_Itype (New_Ctyp, U_Ent); | |
5456 | ||
5457 | Set_Component_Type (Btype, New_Ctyp); | |
5458 | Set_Biased (New_Ctyp, N, "component size clause"); | |
d6f39728 | 5459 | end if; |
5460 | ||
36ac5fbb | 5461 | Set_Component_Size (Btype, Csize); |
5462 | ||
a0fc8c5b | 5463 | -- Deal with warning on overridden size |
5464 | ||
5465 | if Warn_On_Overridden_Size | |
5466 | and then Has_Size_Clause (Ctyp) | |
5467 | and then RM_Size (Ctyp) /= Csize | |
5468 | then | |
5469 | Error_Msg_NE | |
1e3532e7 | 5470 | ("component size overrides size clause for&?S?", N, Ctyp); |
a0fc8c5b | 5471 | end if; |
5472 | ||
d6f39728 | 5473 | Set_Has_Component_Size_Clause (Btype, True); |
f3e4db96 | 5474 | Set_Has_Non_Standard_Rep (Btype, True); |
d6f39728 | 5475 | end if; |
5476 | end Component_Size_Case; | |
5477 | ||
81b424ac | 5478 | ----------------------- |
5479 | -- Constant_Indexing -- | |
5480 | ----------------------- | |
5481 | ||
5482 | when Attribute_Constant_Indexing => | |
5483 | Check_Indexing_Functions; | |
5484 | ||
89f1e35c | 5485 | --------- |
5486 | -- CPU -- | |
5487 | --------- | |
5488 | ||
99378362 | 5489 | when Attribute_CPU => |
5490 | ||
89f1e35c | 5491 | -- CPU attribute definition clause not allowed except from aspect |
5492 | -- specification. | |
5493 | ||
5494 | if From_Aspect_Specification (N) then | |
5495 | if not Is_Task_Type (U_Ent) then | |
5496 | Error_Msg_N ("CPU can only be defined for task", Nam); | |
5497 | ||
5498 | elsif Duplicate_Clause then | |
5499 | null; | |
5500 | ||
5501 | else | |
5502 | -- The expression must be analyzed in the special manner | |
5503 | -- described in "Handling of Default and Per-Object | |
5504 | -- Expressions" in sem.ads. | |
5505 | ||
b4dcd57e | 5506 | -- The visibility to the components must be established |
5507 | -- and restored before and after analysis. | |
89f1e35c | 5508 | |
b4dcd57e | 5509 | Push_Type (U_Ent); |
89f1e35c | 5510 | Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range)); |
b4dcd57e | 5511 | Pop_Type (U_Ent); |
89f1e35c | 5512 | |
cda40848 | 5513 | if not Is_OK_Static_Expression (Expr) then |
89f1e35c | 5514 | Check_Restriction (Static_Priorities, Expr); |
5515 | end if; | |
5516 | end if; | |
5517 | ||
5518 | else | |
5519 | Error_Msg_N | |
5520 | ("attribute& cannot be set with definition clause", N); | |
5521 | end if; | |
89f1e35c | 5522 | |
89cc7147 | 5523 | ---------------------- |
5524 | -- Default_Iterator -- | |
5525 | ---------------------- | |
5526 | ||
40bff3a0 | 5527 | when Attribute_Default_Iterator => Default_Iterator : declare |
89cc7147 | 5528 | Func : Entity_Id; |
fbf4d6ef | 5529 | Typ : Entity_Id; |
89cc7147 | 5530 | |
5531 | begin | |
05f6f999 | 5532 | -- If target type is untagged, further checks are irrelevant |
5533 | ||
89cc7147 | 5534 | if not Is_Tagged_Type (U_Ent) then |
5535 | Error_Msg_N | |
05f6f999 | 5536 | ("aspect Default_Iterator applies to tagged type", Nam); |
5537 | return; | |
89cc7147 | 5538 | end if; |
5539 | ||
5540 | Check_Iterator_Functions; | |
5541 | ||
5542 | Analyze (Expr); | |
5543 | ||
5544 | if not Is_Entity_Name (Expr) | |
5545 | or else Ekind (Entity (Expr)) /= E_Function | |
5546 | then | |
5547 | Error_Msg_N ("aspect Iterator must be a function", Expr); | |
05f6f999 | 5548 | return; |
89cc7147 | 5549 | else |
5550 | Func := Entity (Expr); | |
5551 | end if; | |
5552 | ||
fbf4d6ef | 5553 | -- The type of the first parameter must be T, T'class, or a |
05f6f999 | 5554 | -- corresponding access type (5.5.1 (8/3). If function is |
5555 | -- parameterless label type accordingly. | |
fbf4d6ef | 5556 | |
5557 | if No (First_Formal (Func)) then | |
05f6f999 | 5558 | Typ := Any_Type; |
fbf4d6ef | 5559 | else |
5560 | Typ := Etype (First_Formal (Func)); | |
5561 | end if; | |
5562 | ||
5563 | if Typ = U_Ent | |
5564 | or else Typ = Class_Wide_Type (U_Ent) | |
5565 | or else (Is_Access_Type (Typ) | |
5566 | and then Designated_Type (Typ) = U_Ent) | |
5567 | or else (Is_Access_Type (Typ) | |
5568 | and then Designated_Type (Typ) = | |
5569 | Class_Wide_Type (U_Ent)) | |
89cc7147 | 5570 | then |
fbf4d6ef | 5571 | null; |
5572 | ||
5573 | else | |
89cc7147 | 5574 | Error_Msg_NE |
5575 | ("Default Iterator must be a primitive of&", Func, U_Ent); | |
5576 | end if; | |
5577 | end Default_Iterator; | |
5578 | ||
89f1e35c | 5579 | ------------------------ |
5580 | -- Dispatching_Domain -- | |
5581 | ------------------------ | |
5582 | ||
99378362 | 5583 | when Attribute_Dispatching_Domain => |
5584 | ||
89f1e35c | 5585 | -- Dispatching_Domain attribute definition clause not allowed |
5586 | -- except from aspect specification. | |
5587 | ||
5588 | if From_Aspect_Specification (N) then | |
5589 | if not Is_Task_Type (U_Ent) then | |
fbf4d6ef | 5590 | Error_Msg_N |
5591 | ("Dispatching_Domain can only be defined for task", Nam); | |
89f1e35c | 5592 | |
5593 | elsif Duplicate_Clause then | |
5594 | null; | |
5595 | ||
5596 | else | |
5597 | -- The expression must be analyzed in the special manner | |
5598 | -- described in "Handling of Default and Per-Object | |
5599 | -- Expressions" in sem.ads. | |
5600 | ||
b4dcd57e | 5601 | -- The visibility to the components must be restored |
89f1e35c | 5602 | |
b4dcd57e | 5603 | Push_Type (U_Ent); |
89f1e35c | 5604 | |
5605 | Preanalyze_Spec_Expression | |
5606 | (Expr, RTE (RE_Dispatching_Domain)); | |
5607 | ||
b4dcd57e | 5608 | Pop_Type (U_Ent); |
89f1e35c | 5609 | end if; |
5610 | ||
5611 | else | |
5612 | Error_Msg_N | |
5613 | ("attribute& cannot be set with definition clause", N); | |
5614 | end if; | |
89f1e35c | 5615 | |
d6f39728 | 5616 | ------------------ |
5617 | -- External_Tag -- | |
5618 | ------------------ | |
5619 | ||
99378362 | 5620 | when Attribute_External_Tag => |
d6f39728 | 5621 | if not Is_Tagged_Type (U_Ent) then |
5622 | Error_Msg_N ("should be a tagged type", Nam); | |
5623 | end if; | |
5624 | ||
ae888dbd | 5625 | if Duplicate_Clause then |
5626 | null; | |
d6f39728 | 5627 | |
9af0ddc7 | 5628 | else |
ae888dbd | 5629 | Analyze_And_Resolve (Expr, Standard_String); |
fbc67f84 | 5630 | |
cda40848 | 5631 | if not Is_OK_Static_Expression (Expr) then |
ae888dbd | 5632 | Flag_Non_Static_Expr |
5633 | ("static string required for tag name!", Nam); | |
5634 | end if; | |
5635 | ||
ae888dbd | 5636 | if not Is_Library_Level_Entity (U_Ent) then |
5637 | Error_Msg_NE | |
1e3532e7 | 5638 | ("??non-unique external tag supplied for &", N, U_Ent); |
ae888dbd | 5639 | Error_Msg_N |
f74a102b | 5640 | ("\??same external tag applies to all subprogram calls", |
5641 | N); | |
ae888dbd | 5642 | Error_Msg_N |
1e3532e7 | 5643 | ("\??corresponding internal tag cannot be obtained", N); |
ae888dbd | 5644 | end if; |
fbc67f84 | 5645 | end if; |
d6f39728 | 5646 | |
b57530b8 | 5647 | -------------------------- |
5648 | -- Implicit_Dereference -- | |
5649 | -------------------------- | |
7947a439 | 5650 | |
b57530b8 | 5651 | when Attribute_Implicit_Dereference => |
7947a439 | 5652 | |
2beb22b1 | 5653 | -- Legality checks already performed at the point of the type |
5654 | -- declaration, aspect is not delayed. | |
7947a439 | 5655 | |
89cc7147 | 5656 | null; |
b57530b8 | 5657 | |
d6f39728 | 5658 | ----------- |
5659 | -- Input -- | |
5660 | ----------- | |
5661 | ||
9f373bb8 | 5662 | when Attribute_Input => |
5663 | Analyze_Stream_TSS_Definition (TSS_Stream_Input); | |
5664 | Set_Has_Specified_Stream_Input (Ent); | |
d6f39728 | 5665 | |
89f1e35c | 5666 | ------------------------ |
5667 | -- Interrupt_Priority -- | |
5668 | ------------------------ | |
5669 | ||
99378362 | 5670 | when Attribute_Interrupt_Priority => |
5671 | ||
89f1e35c | 5672 | -- Interrupt_Priority attribute definition clause not allowed |
5673 | -- except from aspect specification. | |
5674 | ||
5675 | if From_Aspect_Specification (N) then | |
f02a9a9a | 5676 | if not Is_Concurrent_Type (U_Ent) then |
89f1e35c | 5677 | Error_Msg_N |
f74a102b | 5678 | ("Interrupt_Priority can only be defined for task and " |
5679 | & "protected object", Nam); | |
89f1e35c | 5680 | |
5681 | elsif Duplicate_Clause then | |
5682 | null; | |
5683 | ||
5684 | else | |
5685 | -- The expression must be analyzed in the special manner | |
5686 | -- described in "Handling of Default and Per-Object | |
5687 | -- Expressions" in sem.ads. | |
5688 | ||
b4dcd57e | 5689 | -- The visibility to the components must be restored |
89f1e35c | 5690 | |
b4dcd57e | 5691 | Push_Type (U_Ent); |
89f1e35c | 5692 | |
5693 | Preanalyze_Spec_Expression | |
5694 | (Expr, RTE (RE_Interrupt_Priority)); | |
5695 | ||
b4dcd57e | 5696 | Pop_Type (U_Ent); |
d4e1acfa | 5697 | |
5698 | -- Check the No_Task_At_Interrupt_Priority restriction | |
5699 | ||
5700 | if Is_Task_Type (U_Ent) then | |
5701 | Check_Restriction (No_Task_At_Interrupt_Priority, N); | |
5702 | end if; | |
89f1e35c | 5703 | end if; |
5704 | ||
5705 | else | |
5706 | Error_Msg_N | |
5707 | ("attribute& cannot be set with definition clause", N); | |
5708 | end if; | |
89f1e35c | 5709 | |
b3f8228a | 5710 | -------------- |
5711 | -- Iterable -- | |
5712 | -------------- | |
5713 | ||
5714 | when Attribute_Iterable => | |
5715 | Analyze (Expr); | |
bde03454 | 5716 | |
b3f8228a | 5717 | if Nkind (Expr) /= N_Aggregate then |
5718 | Error_Msg_N ("aspect Iterable must be an aggregate", Expr); | |
5719 | end if; | |
5720 | ||
5721 | declare | |
5722 | Assoc : Node_Id; | |
5723 | ||
5724 | begin | |
5725 | Assoc := First (Component_Associations (Expr)); | |
5726 | while Present (Assoc) loop | |
b4dcd57e | 5727 | Analyze (Expression (Assoc)); |
92038d64 | 5728 | |
b3f8228a | 5729 | if not Is_Entity_Name (Expression (Assoc)) then |
5730 | Error_Msg_N ("value must be a function", Assoc); | |
5731 | end if; | |
bde03454 | 5732 | |
b3f8228a | 5733 | Next (Assoc); |
5734 | end loop; | |
5735 | end; | |
5736 | ||
89cc7147 | 5737 | ---------------------- |
5738 | -- Iterator_Element -- | |
5739 | ---------------------- | |
5740 | ||
5741 | when Attribute_Iterator_Element => | |
5742 | Analyze (Expr); | |
5743 | ||
5744 | if not Is_Entity_Name (Expr) | |
5745 | or else not Is_Type (Entity (Expr)) | |
5746 | then | |
5747 | Error_Msg_N ("aspect Iterator_Element must be a type", Expr); | |
5748 | end if; | |
5749 | ||
d6f39728 | 5750 | ------------------- |
5751 | -- Machine_Radix -- | |
5752 | ------------------- | |
5753 | ||
5754 | -- Machine radix attribute definition clause | |
5755 | ||
5756 | when Attribute_Machine_Radix => Machine_Radix : declare | |
5757 | Radix : constant Uint := Static_Integer (Expr); | |
5758 | ||
5759 | begin | |
5760 | if not Is_Decimal_Fixed_Point_Type (U_Ent) then | |
5761 | Error_Msg_N ("decimal fixed-point type expected for &", Nam); | |
5762 | ||
ae888dbd | 5763 | elsif Duplicate_Clause then |
5764 | null; | |
d6f39728 | 5765 | |
5766 | elsif Radix /= No_Uint then | |
5767 | Set_Has_Machine_Radix_Clause (U_Ent); | |
5768 | Set_Has_Non_Standard_Rep (Base_Type (U_Ent)); | |
5769 | ||
5770 | if Radix = 2 then | |
5771 | null; | |
f74a102b | 5772 | |
d6f39728 | 5773 | elsif Radix = 10 then |
5774 | Set_Machine_Radix_10 (U_Ent); | |
f74a102b | 5775 | |
5776 | -- The following error is suppressed in ASIS mode to allow for | |
f9906591 | 5777 | -- different ASIS back ends or ASIS-based tools to query the |
f74a102b | 5778 | -- illegal clause. |
5779 | ||
5780 | elsif not ASIS_Mode then | |
d6f39728 | 5781 | Error_Msg_N ("machine radix value must be 2 or 10", Expr); |
5782 | end if; | |
5783 | end if; | |
5784 | end Machine_Radix; | |
5785 | ||
5786 | ----------------- | |
5787 | -- Object_Size -- | |
5788 | ----------------- | |
5789 | ||
5790 | -- Object_Size attribute definition clause | |
5791 | ||
5792 | when Attribute_Object_Size => Object_Size : declare | |
bfa5a9d9 | 5793 | Size : constant Uint := Static_Integer (Expr); |
5794 | ||
d6f39728 | 5795 | Biased : Boolean; |
bfa5a9d9 | 5796 | pragma Warnings (Off, Biased); |
d6f39728 | 5797 | |
5798 | begin | |
5799 | if not Is_Type (U_Ent) then | |
5800 | Error_Msg_N ("Object_Size cannot be given for &", Nam); | |
5801 | ||
ae888dbd | 5802 | elsif Duplicate_Clause then |
5803 | null; | |
d6f39728 | 5804 | |
5805 | else | |
5806 | Check_Size (Expr, U_Ent, Size, Biased); | |
5807 | ||
f74a102b | 5808 | -- The following errors are suppressed in ASIS mode to allow |
f9906591 | 5809 | -- for different ASIS back ends or ASIS-based tools to query |
f74a102b | 5810 | -- the illegal clause. |
5811 | ||
5812 | if ASIS_Mode then | |
5813 | null; | |
5814 | ||
a8e38e22 | 5815 | elsif Size <= 0 then |
5816 | Error_Msg_N ("Object_Size must be positive", Expr); | |
5817 | ||
f74a102b | 5818 | elsif Is_Scalar_Type (U_Ent) then |
829cd457 | 5819 | if Size /= 8 and then Size /= 16 and then Size /= 32 |
5820 | and then UI_Mod (Size, 64) /= 0 | |
5821 | then | |
5822 | Error_Msg_N | |
5823 | ("Object_Size must be 8, 16, 32, or multiple of 64", | |
5824 | Expr); | |
5825 | end if; | |
5826 | ||
5827 | elsif Size mod 8 /= 0 then | |
5828 | Error_Msg_N ("Object_Size must be a multiple of 8", Expr); | |
d6f39728 | 5829 | end if; |
5830 | ||
5831 | Set_Esize (U_Ent, Size); | |
5832 | Set_Has_Object_Size_Clause (U_Ent); | |
1d366b32 | 5833 | Alignment_Check_For_Size_Change (U_Ent, Size); |
d6f39728 | 5834 | end if; |
5835 | end Object_Size; | |
5836 | ||
5837 | ------------ | |
5838 | -- Output -- | |
5839 | ------------ | |
5840 | ||
9f373bb8 | 5841 | when Attribute_Output => |
5842 | Analyze_Stream_TSS_Definition (TSS_Stream_Output); | |
5843 | Set_Has_Specified_Stream_Output (Ent); | |
d6f39728 | 5844 | |
89f1e35c | 5845 | -------------- |
5846 | -- Priority -- | |
5847 | -------------- | |
5848 | ||
99378362 | 5849 | when Attribute_Priority => |
5850 | ||
89f1e35c | 5851 | -- Priority attribute definition clause not allowed except from |
5852 | -- aspect specification. | |
5853 | ||
5854 | if From_Aspect_Specification (N) then | |
f02a9a9a | 5855 | if not (Is_Concurrent_Type (U_Ent) |
3a72f9c3 | 5856 | or else Ekind (U_Ent) = E_Procedure) |
89f1e35c | 5857 | then |
5858 | Error_Msg_N | |
f02a9a9a | 5859 | ("Priority can only be defined for task and protected " |
5860 | & "object", Nam); | |
89f1e35c | 5861 | |
5862 | elsif Duplicate_Clause then | |
5863 | null; | |
5864 | ||
5865 | else | |
5866 | -- The expression must be analyzed in the special manner | |
5867 | -- described in "Handling of Default and Per-Object | |
5868 | -- Expressions" in sem.ads. | |
5869 | ||
b4dcd57e | 5870 | -- The visibility to the components must be restored |
89f1e35c | 5871 | |
b4dcd57e | 5872 | Push_Type (U_Ent); |
89f1e35c | 5873 | Preanalyze_Spec_Expression (Expr, Standard_Integer); |
b4dcd57e | 5874 | Pop_Type (U_Ent); |
89f1e35c | 5875 | |
cda40848 | 5876 | if not Is_OK_Static_Expression (Expr) then |
89f1e35c | 5877 | Check_Restriction (Static_Priorities, Expr); |
5878 | end if; | |
5879 | end if; | |
5880 | ||
5881 | else | |
5882 | Error_Msg_N | |
5883 | ("attribute& cannot be set with definition clause", N); | |
5884 | end if; | |
89f1e35c | 5885 | |
d6f39728 | 5886 | ---------- |
5887 | -- Read -- | |
5888 | ---------- | |
5889 | ||
9f373bb8 | 5890 | when Attribute_Read => |
5891 | Analyze_Stream_TSS_Definition (TSS_Stream_Read); | |
5892 | Set_Has_Specified_Stream_Read (Ent); | |
d6f39728 | 5893 | |
b7b74740 | 5894 | -------------------------- |
5895 | -- Scalar_Storage_Order -- | |
5896 | -------------------------- | |
5897 | ||
5898 | -- Scalar_Storage_Order attribute definition clause | |
5899 | ||
99378362 | 5900 | when Attribute_Scalar_Storage_Order => |
b43a5770 | 5901 | if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then |
b7b74740 | 5902 | Error_Msg_N |
f74a102b | 5903 | ("Scalar_Storage_Order can only be defined for record or " |
5904 | & "array type", Nam); | |
b7b74740 | 5905 | |
5906 | elsif Duplicate_Clause then | |
5907 | null; | |
5908 | ||
5909 | else | |
5910 | Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); | |
5911 | ||
5912 | if Etype (Expr) = Any_Type then | |
5913 | return; | |
5914 | ||
cda40848 | 5915 | elsif not Is_OK_Static_Expression (Expr) then |
b7b74740 | 5916 | Flag_Non_Static_Expr |
5917 | ("Scalar_Storage_Order requires static expression!", Expr); | |
5918 | ||
c0912570 | 5919 | elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then |
5920 | ||
5921 | -- Here for the case of a non-default (i.e. non-confirming) | |
5922 | -- Scalar_Storage_Order attribute definition. | |
5923 | ||
5924 | if Support_Nondefault_SSO_On_Target then | |
d0a9ea3b | 5925 | Set_Reverse_Storage_Order (Base_Type (U_Ent), True); |
c0912570 | 5926 | else |
5927 | Error_Msg_N | |
f74a102b | 5928 | ("non-default Scalar_Storage_Order not supported on " |
5929 | & "target", Expr); | |
b7b74740 | 5930 | end if; |
5931 | end if; | |
b64082f2 | 5932 | |
5933 | -- Clear SSO default indications since explicit setting of the | |
5934 | -- order overrides the defaults. | |
5935 | ||
5936 | Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False); | |
5937 | Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False); | |
b7b74740 | 5938 | end if; |
b7b74740 | 5939 | |
d6f39728 | 5940 | ---------- |
5941 | -- Size -- | |
5942 | ---------- | |
5943 | ||
5944 | -- Size attribute definition clause | |
5945 | ||
5946 | when Attribute_Size => Size : declare | |
5947 | Size : constant Uint := Static_Integer (Expr); | |
5948 | Etyp : Entity_Id; | |
5949 | Biased : Boolean; | |
5950 | ||
5951 | begin | |
5952 | FOnly := True; | |
5953 | ||
ae888dbd | 5954 | if Duplicate_Clause then |
5955 | null; | |
d6f39728 | 5956 | |
5957 | elsif not Is_Type (U_Ent) | |
5958 | and then Ekind (U_Ent) /= E_Variable | |
5959 | and then Ekind (U_Ent) /= E_Constant | |
5960 | then | |
5961 | Error_Msg_N ("size cannot be given for &", Nam); | |
5962 | ||
5963 | elsif Is_Array_Type (U_Ent) | |
5964 | and then not Is_Constrained (U_Ent) | |
5965 | then | |
5966 | Error_Msg_N | |
5967 | ("size cannot be given for unconstrained array", Nam); | |
5968 | ||
c2b89d6e | 5969 | elsif Size /= No_Uint then |
d6f39728 | 5970 | if Is_Type (U_Ent) then |
5971 | Etyp := U_Ent; | |
5972 | else | |
5973 | Etyp := Etype (U_Ent); | |
5974 | end if; | |
5975 | ||
59ac57b5 | 5976 | -- Check size, note that Gigi is in charge of checking that the |
5977 | -- size of an array or record type is OK. Also we do not check | |
5978 | -- the size in the ordinary fixed-point case, since it is too | |
5979 | -- early to do so (there may be subsequent small clause that | |
5980 | -- affects the size). We can check the size if a small clause | |
5981 | -- has already been given. | |
d6f39728 | 5982 | |
5983 | if not Is_Ordinary_Fixed_Point_Type (U_Ent) | |
5984 | or else Has_Small_Clause (U_Ent) | |
5985 | then | |
5986 | Check_Size (Expr, Etyp, Size, Biased); | |
b77e4501 | 5987 | Set_Biased (U_Ent, N, "size clause", Biased); |
d6f39728 | 5988 | end if; |
5989 | ||
5990 | -- For types set RM_Size and Esize if possible | |
5991 | ||
5992 | if Is_Type (U_Ent) then | |
5993 | Set_RM_Size (U_Ent, Size); | |
5994 | ||
ada34def | 5995 | -- For elementary types, increase Object_Size to power of 2, |
5996 | -- but not less than a storage unit in any case (normally | |
59ac57b5 | 5997 | -- this means it will be byte addressable). |
d6f39728 | 5998 | |
ada34def | 5999 | -- For all other types, nothing else to do, we leave Esize |
6000 | -- (object size) unset, the back end will set it from the | |
6001 | -- size and alignment in an appropriate manner. | |
6002 | ||
1d366b32 | 6003 | -- In both cases, we check whether the alignment must be |
6004 | -- reset in the wake of the size change. | |
6005 | ||
ada34def | 6006 | if Is_Elementary_Type (U_Ent) then |
f15731c4 | 6007 | if Size <= System_Storage_Unit then |
6008 | Init_Esize (U_Ent, System_Storage_Unit); | |
d6f39728 | 6009 | elsif Size <= 16 then |
6010 | Init_Esize (U_Ent, 16); | |
6011 | elsif Size <= 32 then | |
6012 | Init_Esize (U_Ent, 32); | |
6013 | else | |
6014 | Set_Esize (U_Ent, (Size + 63) / 64 * 64); | |
6015 | end if; | |
6016 | ||
1d366b32 | 6017 | Alignment_Check_For_Size_Change (U_Ent, Esize (U_Ent)); |
6018 | else | |
6019 | Alignment_Check_For_Size_Change (U_Ent, Size); | |
d6f39728 | 6020 | end if; |
6021 | ||
d6f39728 | 6022 | -- For objects, set Esize only |
6023 | ||
6024 | else | |
f74a102b | 6025 | -- The following error is suppressed in ASIS mode to allow |
f9906591 | 6026 | -- for different ASIS back ends or ASIS-based tools to query |
f74a102b | 6027 | -- the illegal clause. |
6028 | ||
6029 | if Is_Elementary_Type (Etyp) | |
6030 | and then Size /= System_Storage_Unit | |
6031 | and then Size /= System_Storage_Unit * 2 | |
6032 | and then Size /= System_Storage_Unit * 4 | |
6033 | and then Size /= System_Storage_Unit * 8 | |
6034 | and then not ASIS_Mode | |
6035 | then | |
6036 | Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); | |
6037 | Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8; | |
6038 | Error_Msg_N | |
6039 | ("size for primitive object must be a power of 2 in " | |
6040 | & "the range ^-^", N); | |
9dfe12ae | 6041 | end if; |
6042 | ||
d6f39728 | 6043 | Set_Esize (U_Ent, Size); |
6044 | end if; | |
6045 | ||
6046 | Set_Has_Size_Clause (U_Ent); | |
6047 | end if; | |
6048 | end Size; | |
6049 | ||
6050 | ----------- | |
6051 | -- Small -- | |
6052 | ----------- | |
6053 | ||
6054 | -- Small attribute definition clause | |
6055 | ||
6056 | when Attribute_Small => Small : declare | |
6057 | Implicit_Base : constant Entity_Id := Base_Type (U_Ent); | |
6058 | Small : Ureal; | |
6059 | ||
6060 | begin | |
6061 | Analyze_And_Resolve (Expr, Any_Real); | |
6062 | ||
6063 | if Etype (Expr) = Any_Type then | |
6064 | return; | |
6065 | ||
cda40848 | 6066 | elsif not Is_OK_Static_Expression (Expr) then |
9dfe12ae | 6067 | Flag_Non_Static_Expr |
6068 | ("small requires static expression!", Expr); | |
d6f39728 | 6069 | return; |
6070 | ||
6071 | else | |
6072 | Small := Expr_Value_R (Expr); | |
6073 | ||
6074 | if Small <= Ureal_0 then | |
6075 | Error_Msg_N ("small value must be greater than zero", Expr); | |
6076 | return; | |
6077 | end if; | |
6078 | ||
6079 | end if; | |
6080 | ||
6081 | if not Is_Ordinary_Fixed_Point_Type (U_Ent) then | |
6082 | Error_Msg_N | |
6083 | ("small requires an ordinary fixed point type", Nam); | |
6084 | ||
6085 | elsif Has_Small_Clause (U_Ent) then | |
6086 | Error_Msg_N ("small already given for &", Nam); | |
6087 | ||
6088 | elsif Small > Delta_Value (U_Ent) then | |
6089 | Error_Msg_N | |
ce3e25d6 | 6090 | ("small value must not be greater than delta value", Nam); |
d6f39728 | 6091 | |
6092 | else | |
6093 | Set_Small_Value (U_Ent, Small); | |
6094 | Set_Small_Value (Implicit_Base, Small); | |
6095 | Set_Has_Small_Clause (U_Ent); | |
6096 | Set_Has_Small_Clause (Implicit_Base); | |
6097 | Set_Has_Non_Standard_Rep (Implicit_Base); | |
6098 | end if; | |
6099 | end Small; | |
6100 | ||
d6f39728 | 6101 | ------------------ |
6102 | -- Storage_Pool -- | |
6103 | ------------------ | |
6104 | ||
6105 | -- Storage_Pool attribute definition clause | |
6106 | ||
99378362 | 6107 | when Attribute_Simple_Storage_Pool |
6108 | | Attribute_Storage_Pool | |
6109 | => | |
6110 | Storage_Pool : declare | |
d6f39728 | 6111 | Pool : Entity_Id; |
6b567c71 | 6112 | T : Entity_Id; |
d6f39728 | 6113 | |
6114 | begin | |
44e4341e | 6115 | if Ekind (U_Ent) = E_Access_Subprogram_Type then |
6116 | Error_Msg_N | |
6117 | ("storage pool cannot be given for access-to-subprogram type", | |
6118 | Nam); | |
6119 | return; | |
6120 | ||
99378362 | 6121 | elsif not Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type) |
d6f39728 | 6122 | then |
44e4341e | 6123 | Error_Msg_N |
6124 | ("storage pool can only be given for access types", Nam); | |
d6f39728 | 6125 | return; |
6126 | ||
6127 | elsif Is_Derived_Type (U_Ent) then | |
6128 | Error_Msg_N | |
6129 | ("storage pool cannot be given for a derived access type", | |
6130 | Nam); | |
6131 | ||
ae888dbd | 6132 | elsif Duplicate_Clause then |
d6f39728 | 6133 | return; |
6134 | ||
6135 | elsif Present (Associated_Storage_Pool (U_Ent)) then | |
6136 | Error_Msg_N ("storage pool already given for &", Nam); | |
6137 | return; | |
6138 | end if; | |
6139 | ||
6653b695 | 6140 | -- Check for Storage_Size previously given |
6141 | ||
6142 | declare | |
6143 | SS : constant Node_Id := | |
6144 | Get_Attribute_Definition_Clause | |
6145 | (U_Ent, Attribute_Storage_Size); | |
6146 | begin | |
6147 | if Present (SS) then | |
6148 | Check_Pool_Size_Clash (U_Ent, N, SS); | |
6149 | end if; | |
6150 | end; | |
6151 | ||
6152 | -- Storage_Pool case | |
6153 | ||
b55f7641 | 6154 | if Id = Attribute_Storage_Pool then |
6155 | Analyze_And_Resolve | |
6156 | (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool))); | |
6157 | ||
6158 | -- In the Simple_Storage_Pool case, we allow a variable of any | |
b15003c3 | 6159 | -- simple storage pool type, so we Resolve without imposing an |
b55f7641 | 6160 | -- expected type. |
6161 | ||
6162 | else | |
6163 | Analyze_And_Resolve (Expr); | |
6164 | ||
6165 | if not Present (Get_Rep_Pragma | |
b15003c3 | 6166 | (Etype (Expr), Name_Simple_Storage_Pool_Type)) |
b55f7641 | 6167 | then |
6168 | Error_Msg_N | |
6169 | ("expression must be of a simple storage pool type", Expr); | |
6170 | end if; | |
6171 | end if; | |
d6f39728 | 6172 | |
8c5c7277 | 6173 | if not Denotes_Variable (Expr) then |
6174 | Error_Msg_N ("storage pool must be a variable", Expr); | |
6175 | return; | |
6176 | end if; | |
6177 | ||
6b567c71 | 6178 | if Nkind (Expr) = N_Type_Conversion then |
6179 | T := Etype (Expression (Expr)); | |
6180 | else | |
6181 | T := Etype (Expr); | |
6182 | end if; | |
6183 | ||
6184 | -- The Stack_Bounded_Pool is used internally for implementing | |
d64221a7 | 6185 | -- access types with a Storage_Size. Since it only work properly |
6186 | -- when used on one specific type, we need to check that it is not | |
6187 | -- hijacked improperly: | |
6188 | ||
6b567c71 | 6189 | -- type T is access Integer; |
6190 | -- for T'Storage_Size use n; | |
6191 | -- type Q is access Float; | |
6192 | -- for Q'Storage_Size use T'Storage_Size; -- incorrect | |
6193 | ||
15ebb600 | 6194 | if RTE_Available (RE_Stack_Bounded_Pool) |
6195 | and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool) | |
6196 | then | |
6197 | Error_Msg_N ("non-shareable internal Pool", Expr); | |
6b567c71 | 6198 | return; |
6199 | end if; | |
6200 | ||
d6f39728 | 6201 | -- If the argument is a name that is not an entity name, then |
6202 | -- we construct a renaming operation to define an entity of | |
6203 | -- type storage pool. | |
6204 | ||
6205 | if not Is_Entity_Name (Expr) | |
6206 | and then Is_Object_Reference (Expr) | |
6207 | then | |
11deeeb6 | 6208 | Pool := Make_Temporary (Loc, 'P', Expr); |
d6f39728 | 6209 | |
6210 | declare | |
6211 | Rnode : constant Node_Id := | |
6212 | Make_Object_Renaming_Declaration (Loc, | |
6213 | Defining_Identifier => Pool, | |
6214 | Subtype_Mark => | |
6215 | New_Occurrence_Of (Etype (Expr), Loc), | |
11deeeb6 | 6216 | Name => Expr); |
d6f39728 | 6217 | |
6218 | begin | |
f65f7fdf | 6219 | -- If the attribute definition clause comes from an aspect |
6220 | -- clause, then insert the renaming before the associated | |
6221 | -- entity's declaration, since the attribute clause has | |
6222 | -- not yet been appended to the declaration list. | |
6223 | ||
6224 | if From_Aspect_Specification (N) then | |
6225 | Insert_Before (Parent (Entity (N)), Rnode); | |
6226 | else | |
6227 | Insert_Before (N, Rnode); | |
6228 | end if; | |
6229 | ||
d6f39728 | 6230 | Analyze (Rnode); |
6231 | Set_Associated_Storage_Pool (U_Ent, Pool); | |
6232 | end; | |
6233 | ||
6234 | elsif Is_Entity_Name (Expr) then | |
6235 | Pool := Entity (Expr); | |
6236 | ||
6237 | -- If pool is a renamed object, get original one. This can | |
6238 | -- happen with an explicit renaming, and within instances. | |
6239 | ||
6240 | while Present (Renamed_Object (Pool)) | |
6241 | and then Is_Entity_Name (Renamed_Object (Pool)) | |
6242 | loop | |
6243 | Pool := Entity (Renamed_Object (Pool)); | |
6244 | end loop; | |
6245 | ||
6246 | if Present (Renamed_Object (Pool)) | |
6247 | and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion | |
6248 | and then Is_Entity_Name (Expression (Renamed_Object (Pool))) | |
6249 | then | |
6250 | Pool := Entity (Expression (Renamed_Object (Pool))); | |
6251 | end if; | |
6252 | ||
6b567c71 | 6253 | Set_Associated_Storage_Pool (U_Ent, Pool); |
d6f39728 | 6254 | |
6255 | elsif Nkind (Expr) = N_Type_Conversion | |
6256 | and then Is_Entity_Name (Expression (Expr)) | |
6257 | and then Nkind (Original_Node (Expr)) = N_Attribute_Reference | |
6258 | then | |
6259 | Pool := Entity (Expression (Expr)); | |
6b567c71 | 6260 | Set_Associated_Storage_Pool (U_Ent, Pool); |
d6f39728 | 6261 | |
6262 | else | |
6263 | Error_Msg_N ("incorrect reference to a Storage Pool", Expr); | |
6264 | return; | |
6265 | end if; | |
99378362 | 6266 | end Storage_Pool; |
d6f39728 | 6267 | |
44e4341e | 6268 | ------------------ |
6269 | -- Storage_Size -- | |
6270 | ------------------ | |
6271 | ||
6272 | -- Storage_Size attribute definition clause | |
6273 | ||
6274 | when Attribute_Storage_Size => Storage_Size : declare | |
6275 | Btype : constant Entity_Id := Base_Type (U_Ent); | |
44e4341e | 6276 | |
6277 | begin | |
6278 | if Is_Task_Type (U_Ent) then | |
44e4341e | 6279 | |
39a0c1d3 | 6280 | -- Check obsolescent (but never obsolescent if from aspect) |
ceec4f7c | 6281 | |
6282 | if not From_Aspect_Specification (N) then | |
6283 | Check_Restriction (No_Obsolescent_Features, N); | |
6284 | ||
6285 | if Warn_On_Obsolescent_Feature then | |
6286 | Error_Msg_N | |
f74a102b | 6287 | ("?j?storage size clause for task is an obsolescent " |
6288 | & "feature (RM J.9)", N); | |
ceec4f7c | 6289 | Error_Msg_N ("\?j?use Storage_Size pragma instead", N); |
6290 | end if; | |
44e4341e | 6291 | end if; |
6292 | ||
6293 | FOnly := True; | |
6294 | end if; | |
6295 | ||
6296 | if not Is_Access_Type (U_Ent) | |
6297 | and then Ekind (U_Ent) /= E_Task_Type | |
6298 | then | |
6299 | Error_Msg_N ("storage size cannot be given for &", Nam); | |
6300 | ||
6301 | elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then | |
6302 | Error_Msg_N | |
6303 | ("storage size cannot be given for a derived access type", | |
6304 | Nam); | |
6305 | ||
ae888dbd | 6306 | elsif Duplicate_Clause then |
6307 | null; | |
44e4341e | 6308 | |
6309 | else | |
6310 | Analyze_And_Resolve (Expr, Any_Integer); | |
6311 | ||
6312 | if Is_Access_Type (U_Ent) then | |
6653b695 | 6313 | |
6314 | -- Check for Storage_Pool previously given | |
6315 | ||
6316 | declare | |
6317 | SP : constant Node_Id := | |
6318 | Get_Attribute_Definition_Clause | |
6319 | (U_Ent, Attribute_Storage_Pool); | |
6320 | ||
6321 | begin | |
6322 | if Present (SP) then | |
6323 | Check_Pool_Size_Clash (U_Ent, SP, N); | |
6324 | end if; | |
6325 | end; | |
6326 | ||
6327 | -- Special case of for x'Storage_Size use 0 | |
44e4341e | 6328 | |
5941a4e9 | 6329 | if Is_OK_Static_Expression (Expr) |
44e4341e | 6330 | and then Expr_Value (Expr) = 0 |
6331 | then | |
6332 | Set_No_Pool_Assigned (Btype); | |
6333 | end if; | |
44e4341e | 6334 | end if; |
6335 | ||
6336 | Set_Has_Storage_Size_Clause (Btype); | |
6337 | end if; | |
6338 | end Storage_Size; | |
6339 | ||
7189d17f | 6340 | ----------------- |
6341 | -- Stream_Size -- | |
6342 | ----------------- | |
6343 | ||
6344 | when Attribute_Stream_Size => Stream_Size : declare | |
6345 | Size : constant Uint := Static_Integer (Expr); | |
6346 | ||
6347 | begin | |
15ebb600 | 6348 | if Ada_Version <= Ada_95 then |
6349 | Check_Restriction (No_Implementation_Attributes, N); | |
6350 | end if; | |
6351 | ||
ae888dbd | 6352 | if Duplicate_Clause then |
6353 | null; | |
7189d17f | 6354 | |
6355 | elsif Is_Elementary_Type (U_Ent) then | |
f74a102b | 6356 | |
6357 | -- The following errors are suppressed in ASIS mode to allow | |
f9906591 | 6358 | -- for different ASIS back ends or ASIS-based tools to query |
f74a102b | 6359 | -- the illegal clause. |
6360 | ||
6361 | if ASIS_Mode then | |
6362 | null; | |
6363 | ||
6364 | elsif Size /= System_Storage_Unit | |
6365 | and then Size /= System_Storage_Unit * 2 | |
6366 | and then Size /= System_Storage_Unit * 4 | |
6367 | and then Size /= System_Storage_Unit * 8 | |
7189d17f | 6368 | then |
6369 | Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); | |
6370 | Error_Msg_N | |
f74a102b | 6371 | ("stream size for elementary type must be a power of 2 " |
6372 | & "and at least ^", N); | |
7189d17f | 6373 | |
6374 | elsif RM_Size (U_Ent) > Size then | |
6375 | Error_Msg_Uint_1 := RM_Size (U_Ent); | |
6376 | Error_Msg_N | |
f74a102b | 6377 | ("stream size for elementary type must be a power of 2 " |
6378 | & "and at least ^", N); | |
7189d17f | 6379 | end if; |
6380 | ||
6381 | Set_Has_Stream_Size_Clause (U_Ent); | |
6382 | ||
6383 | else | |
6384 | Error_Msg_N ("Stream_Size cannot be given for &", Nam); | |
6385 | end if; | |
6386 | end Stream_Size; | |
6387 | ||
d6f39728 | 6388 | ---------------- |
6389 | -- Value_Size -- | |
6390 | ---------------- | |
6391 | ||
6392 | -- Value_Size attribute definition clause | |
6393 | ||
6394 | when Attribute_Value_Size => Value_Size : declare | |
6395 | Size : constant Uint := Static_Integer (Expr); | |
6396 | Biased : Boolean; | |
6397 | ||
6398 | begin | |
6399 | if not Is_Type (U_Ent) then | |
6400 | Error_Msg_N ("Value_Size cannot be given for &", Nam); | |
6401 | ||
ae888dbd | 6402 | elsif Duplicate_Clause then |
6403 | null; | |
d6f39728 | 6404 | |
59ac57b5 | 6405 | elsif Is_Array_Type (U_Ent) |
6406 | and then not Is_Constrained (U_Ent) | |
6407 | then | |
6408 | Error_Msg_N | |
6409 | ("Value_Size cannot be given for unconstrained array", Nam); | |
6410 | ||
d6f39728 | 6411 | else |
6412 | if Is_Elementary_Type (U_Ent) then | |
6413 | Check_Size (Expr, U_Ent, Size, Biased); | |
b77e4501 | 6414 | Set_Biased (U_Ent, N, "value size clause", Biased); |
d6f39728 | 6415 | end if; |
6416 | ||
6417 | Set_RM_Size (U_Ent, Size); | |
6418 | end if; | |
6419 | end Value_Size; | |
6420 | ||
81b424ac | 6421 | ----------------------- |
6422 | -- Variable_Indexing -- | |
6423 | ----------------------- | |
6424 | ||
6425 | when Attribute_Variable_Indexing => | |
6426 | Check_Indexing_Functions; | |
6427 | ||
d6f39728 | 6428 | ----------- |
6429 | -- Write -- | |
6430 | ----------- | |
6431 | ||
9f373bb8 | 6432 | when Attribute_Write => |
6433 | Analyze_Stream_TSS_Definition (TSS_Stream_Write); | |
6434 | Set_Has_Specified_Stream_Write (Ent); | |
d6f39728 | 6435 | |
6436 | -- All other attributes cannot be set | |
6437 | ||
6438 | when others => | |
6439 | Error_Msg_N | |
6440 | ("attribute& cannot be set with definition clause", N); | |
d6f39728 | 6441 | end case; |
6442 | ||
d64221a7 | 6443 | -- The test for the type being frozen must be performed after any |
6444 | -- expression the clause has been analyzed since the expression itself | |
6445 | -- might cause freezing that makes the clause illegal. | |
d6f39728 | 6446 | |
6447 | if Rep_Item_Too_Late (U_Ent, N, FOnly) then | |
6448 | return; | |
6449 | end if; | |
6450 | end Analyze_Attribute_Definition_Clause; | |
6451 | ||
6452 | ---------------------------- | |
6453 | -- Analyze_Code_Statement -- | |
6454 | ---------------------------- | |
6455 | ||
6456 | procedure Analyze_Code_Statement (N : Node_Id) is | |
6457 | HSS : constant Node_Id := Parent (N); | |
6458 | SBody : constant Node_Id := Parent (HSS); | |
6459 | Subp : constant Entity_Id := Current_Scope; | |
6460 | Stmt : Node_Id; | |
6461 | Decl : Node_Id; | |
6462 | StmtO : Node_Id; | |
6463 | DeclO : Node_Id; | |
6464 | ||
6465 | begin | |
1d3f0c6b | 6466 | -- Accept foreign code statements for CodePeer. The analysis is skipped |
6467 | -- to avoid rejecting unrecognized constructs. | |
6468 | ||
6469 | if CodePeer_Mode then | |
6470 | Set_Analyzed (N); | |
6471 | return; | |
6472 | end if; | |
6473 | ||
d6f39728 | 6474 | -- Analyze and check we get right type, note that this implements the |
1d3f0c6b | 6475 | -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is |
6476 | -- the only way that Asm_Insn could possibly be visible. | |
d6f39728 | 6477 | |
6478 | Analyze_And_Resolve (Expression (N)); | |
6479 | ||
6480 | if Etype (Expression (N)) = Any_Type then | |
6481 | return; | |
6482 | elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then | |
6483 | Error_Msg_N ("incorrect type for code statement", N); | |
6484 | return; | |
6485 | end if; | |
6486 | ||
44e4341e | 6487 | Check_Code_Statement (N); |
6488 | ||
1d3f0c6b | 6489 | -- Make sure we appear in the handled statement sequence of a subprogram |
6490 | -- (RM 13.8(3)). | |
d6f39728 | 6491 | |
6492 | if Nkind (HSS) /= N_Handled_Sequence_Of_Statements | |
6493 | or else Nkind (SBody) /= N_Subprogram_Body | |
6494 | then | |
6495 | Error_Msg_N | |
6496 | ("code statement can only appear in body of subprogram", N); | |
6497 | return; | |
6498 | end if; | |
6499 | ||
6500 | -- Do remaining checks (RM 13.8(3)) if not already done | |
6501 | ||
6502 | if not Is_Machine_Code_Subprogram (Subp) then | |
6503 | Set_Is_Machine_Code_Subprogram (Subp); | |
6504 | ||
6505 | -- No exception handlers allowed | |
6506 | ||
6507 | if Present (Exception_Handlers (HSS)) then | |
6508 | Error_Msg_N | |
6509 | ("exception handlers not permitted in machine code subprogram", | |
6510 | First (Exception_Handlers (HSS))); | |
6511 | end if; | |
6512 | ||
6513 | -- No declarations other than use clauses and pragmas (we allow | |
6514 | -- certain internally generated declarations as well). | |
6515 | ||
6516 | Decl := First (Declarations (SBody)); | |
6517 | while Present (Decl) loop | |
6518 | DeclO := Original_Node (Decl); | |
6519 | if Comes_From_Source (DeclO) | |
fdd294d1 | 6520 | and not Nkind_In (DeclO, N_Pragma, |
6521 | N_Use_Package_Clause, | |
6522 | N_Use_Type_Clause, | |
6523 | N_Implicit_Label_Declaration) | |
d6f39728 | 6524 | then |
6525 | Error_Msg_N | |
6526 | ("this declaration not allowed in machine code subprogram", | |
6527 | DeclO); | |
6528 | end if; | |
6529 | ||
6530 | Next (Decl); | |
6531 | end loop; | |
6532 | ||
6533 | -- No statements other than code statements, pragmas, and labels. | |
6534 | -- Again we allow certain internally generated statements. | |
3ab42ff7 | 6535 | |
c3107527 | 6536 | -- In Ada 2012, qualified expressions are names, and the code |
6537 | -- statement is initially parsed as a procedure call. | |
d6f39728 | 6538 | |
6539 | Stmt := First (Statements (HSS)); | |
6540 | while Present (Stmt) loop | |
6541 | StmtO := Original_Node (Stmt); | |
c3107527 | 6542 | |
1d3f0c6b | 6543 | -- A procedure call transformed into a code statement is OK |
59f2fcab | 6544 | |
c3107527 | 6545 | if Ada_Version >= Ada_2012 |
6546 | and then Nkind (StmtO) = N_Procedure_Call_Statement | |
59f2fcab | 6547 | and then Nkind (Name (StmtO)) = N_Qualified_Expression |
c3107527 | 6548 | then |
6549 | null; | |
6550 | ||
6551 | elsif Comes_From_Source (StmtO) | |
fdd294d1 | 6552 | and then not Nkind_In (StmtO, N_Pragma, |
6553 | N_Label, | |
6554 | N_Code_Statement) | |
d6f39728 | 6555 | then |
6556 | Error_Msg_N | |
6557 | ("this statement is not allowed in machine code subprogram", | |
6558 | StmtO); | |
6559 | end if; | |
6560 | ||
6561 | Next (Stmt); | |
6562 | end loop; | |
6563 | end if; | |
d6f39728 | 6564 | end Analyze_Code_Statement; |
6565 | ||
6566 | ----------------------------------------------- | |
6567 | -- Analyze_Enumeration_Representation_Clause -- | |
6568 | ----------------------------------------------- | |
6569 | ||
6570 | procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is | |
21647c2d | 6571 | Ident : constant Node_Id := Identifier (N); |
6572 | Aggr : constant Node_Id := Array_Aggregate (N); | |
d6f39728 | 6573 | Enumtype : Entity_Id; |
6574 | Elit : Entity_Id; | |
6575 | Expr : Node_Id; | |
6576 | Assoc : Node_Id; | |
6577 | Choice : Node_Id; | |
6578 | Val : Uint; | |
b3190af0 | 6579 | |
6580 | Err : Boolean := False; | |
098d3082 | 6581 | -- Set True to avoid cascade errors and crashes on incorrect source code |
d6f39728 | 6582 | |
e30c7d84 | 6583 | Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer)); |
6584 | Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer)); | |
6585 | -- Allowed range of universal integer (= allowed range of enum lit vals) | |
6586 | ||
d6f39728 | 6587 | Min : Uint; |
6588 | Max : Uint; | |
e30c7d84 | 6589 | -- Minimum and maximum values of entries |
6590 | ||
d39570ea | 6591 | Max_Node : Node_Id := Empty; -- init to avoid warning |
e30c7d84 | 6592 | -- Pointer to node for literal providing max value |
d6f39728 | 6593 | |
6594 | begin | |
ca301e17 | 6595 | if Ignore_Rep_Clauses then |
2ff55065 | 6596 | Kill_Rep_Clause (N); |
fbc67f84 | 6597 | return; |
6598 | end if; | |
6599 | ||
175a6969 | 6600 | -- Ignore enumeration rep clauses by default in CodePeer mode, |
6601 | -- unless -gnatd.I is specified, as a work around for potential false | |
6602 | -- positive messages. | |
6603 | ||
6604 | if CodePeer_Mode and not Debug_Flag_Dot_II then | |
6605 | return; | |
6606 | end if; | |
6607 | ||
d6f39728 | 6608 | -- First some basic error checks |
6609 | ||
6610 | Find_Type (Ident); | |
6611 | Enumtype := Entity (Ident); | |
6612 | ||
6613 | if Enumtype = Any_Type | |
6614 | or else Rep_Item_Too_Early (Enumtype, N) | |
6615 | then | |
6616 | return; | |
6617 | else | |
6618 | Enumtype := Underlying_Type (Enumtype); | |
6619 | end if; | |
6620 | ||
6621 | if not Is_Enumeration_Type (Enumtype) then | |
6622 | Error_Msg_NE | |
6623 | ("enumeration type required, found}", | |
6624 | Ident, First_Subtype (Enumtype)); | |
6625 | return; | |
6626 | end if; | |
6627 | ||
9dfe12ae | 6628 | -- Ignore rep clause on generic actual type. This will already have |
6629 | -- been flagged on the template as an error, and this is the safest | |
6630 | -- way to ensure we don't get a junk cascaded message in the instance. | |
6631 | ||
6632 | if Is_Generic_Actual_Type (Enumtype) then | |
6633 | return; | |
6634 | ||
6635 | -- Type must be in current scope | |
6636 | ||
6637 | elsif Scope (Enumtype) /= Current_Scope then | |
d6f39728 | 6638 | Error_Msg_N ("type must be declared in this scope", Ident); |
6639 | return; | |
6640 | ||
9dfe12ae | 6641 | -- Type must be a first subtype |
6642 | ||
d6f39728 | 6643 | elsif not Is_First_Subtype (Enumtype) then |
6644 | Error_Msg_N ("cannot give enumeration rep clause for subtype", N); | |
6645 | return; | |
6646 | ||
9dfe12ae | 6647 | -- Ignore duplicate rep clause |
6648 | ||
d6f39728 | 6649 | elsif Has_Enumeration_Rep_Clause (Enumtype) then |
6650 | Error_Msg_N ("duplicate enumeration rep clause ignored", N); | |
6651 | return; | |
6652 | ||
7189d17f | 6653 | -- Don't allow rep clause for standard [wide_[wide_]]character |
9dfe12ae | 6654 | |
177675a7 | 6655 | elsif Is_Standard_Character_Type (Enumtype) then |
d6f39728 | 6656 | Error_Msg_N ("enumeration rep clause not allowed for this type", N); |
9dfe12ae | 6657 | return; |
6658 | ||
d9125581 | 6659 | -- Check that the expression is a proper aggregate (no parentheses) |
6660 | ||
6661 | elsif Paren_Count (Aggr) /= 0 then | |
6662 | Error_Msg | |
6663 | ("extra parentheses surrounding aggregate not allowed", | |
6664 | First_Sloc (Aggr)); | |
6665 | return; | |
6666 | ||
9dfe12ae | 6667 | -- All tests passed, so set rep clause in place |
d6f39728 | 6668 | |
6669 | else | |
6670 | Set_Has_Enumeration_Rep_Clause (Enumtype); | |
6671 | Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype)); | |
6672 | end if; | |
6673 | ||
6674 | -- Now we process the aggregate. Note that we don't use the normal | |
6675 | -- aggregate code for this purpose, because we don't want any of the | |
6676 | -- normal expansion activities, and a number of special semantic | |
6677 | -- rules apply (including the component type being any integer type) | |
6678 | ||
d6f39728 | 6679 | Elit := First_Literal (Enumtype); |
6680 | ||
6681 | -- First the positional entries if any | |
6682 | ||
6683 | if Present (Expressions (Aggr)) then | |
6684 | Expr := First (Expressions (Aggr)); | |
6685 | while Present (Expr) loop | |
6686 | if No (Elit) then | |
6687 | Error_Msg_N ("too many entries in aggregate", Expr); | |
6688 | return; | |
6689 | end if; | |
6690 | ||
6691 | Val := Static_Integer (Expr); | |
6692 | ||
d9125581 | 6693 | -- Err signals that we found some incorrect entries processing |
6694 | -- the list. The final checks for completeness and ordering are | |
6695 | -- skipped in this case. | |
6696 | ||
d6f39728 | 6697 | if Val = No_Uint then |
6698 | Err := True; | |
f02a9a9a | 6699 | |
d6f39728 | 6700 | elsif Val < Lo or else Hi < Val then |
6701 | Error_Msg_N ("value outside permitted range", Expr); | |
6702 | Err := True; | |
6703 | end if; | |
6704 | ||
6705 | Set_Enumeration_Rep (Elit, Val); | |
6706 | Set_Enumeration_Rep_Expr (Elit, Expr); | |
6707 | Next (Expr); | |
6708 | Next (Elit); | |
6709 | end loop; | |
6710 | end if; | |
6711 | ||
6712 | -- Now process the named entries if present | |
6713 | ||
6714 | if Present (Component_Associations (Aggr)) then | |
6715 | Assoc := First (Component_Associations (Aggr)); | |
6716 | while Present (Assoc) loop | |
6717 | Choice := First (Choices (Assoc)); | |
6718 | ||
6719 | if Present (Next (Choice)) then | |
6720 | Error_Msg_N | |
6721 | ("multiple choice not allowed here", Next (Choice)); | |
6722 | Err := True; | |
6723 | end if; | |
6724 | ||
6725 | if Nkind (Choice) = N_Others_Choice then | |
6726 | Error_Msg_N ("others choice not allowed here", Choice); | |
6727 | Err := True; | |
6728 | ||
6729 | elsif Nkind (Choice) = N_Range then | |
b3190af0 | 6730 | |
d6f39728 | 6731 | -- ??? should allow zero/one element range here |
b3190af0 | 6732 | |
d6f39728 | 6733 | Error_Msg_N ("range not allowed here", Choice); |
6734 | Err := True; | |
6735 | ||
6736 | else | |
6737 | Analyze_And_Resolve (Choice, Enumtype); | |
b3190af0 | 6738 | |
098d3082 | 6739 | if Error_Posted (Choice) then |
d6f39728 | 6740 | Err := True; |
098d3082 | 6741 | end if; |
d6f39728 | 6742 | |
098d3082 | 6743 | if not Err then |
6744 | if Is_Entity_Name (Choice) | |
6745 | and then Is_Type (Entity (Choice)) | |
6746 | then | |
6747 | Error_Msg_N ("subtype name not allowed here", Choice); | |
d6f39728 | 6748 | Err := True; |
b3190af0 | 6749 | |
098d3082 | 6750 | -- ??? should allow static subtype with zero/one entry |
d6f39728 | 6751 | |
098d3082 | 6752 | elsif Etype (Choice) = Base_Type (Enumtype) then |
cda40848 | 6753 | if not Is_OK_Static_Expression (Choice) then |
098d3082 | 6754 | Flag_Non_Static_Expr |
6755 | ("non-static expression used for choice!", Choice); | |
d6f39728 | 6756 | Err := True; |
d6f39728 | 6757 | |
098d3082 | 6758 | else |
6759 | Elit := Expr_Value_E (Choice); | |
6760 | ||
6761 | if Present (Enumeration_Rep_Expr (Elit)) then | |
6762 | Error_Msg_Sloc := | |
6763 | Sloc (Enumeration_Rep_Expr (Elit)); | |
6764 | Error_Msg_NE | |
6765 | ("representation for& previously given#", | |
6766 | Choice, Elit); | |
6767 | Err := True; | |
6768 | end if; | |
d6f39728 | 6769 | |
098d3082 | 6770 | Set_Enumeration_Rep_Expr (Elit, Expression (Assoc)); |
d6f39728 | 6771 | |
098d3082 | 6772 | Expr := Expression (Assoc); |
6773 | Val := Static_Integer (Expr); | |
d6f39728 | 6774 | |
098d3082 | 6775 | if Val = No_Uint then |
6776 | Err := True; | |
6777 | ||
6778 | elsif Val < Lo or else Hi < Val then | |
6779 | Error_Msg_N ("value outside permitted range", Expr); | |
6780 | Err := True; | |
6781 | end if; | |
d6f39728 | 6782 | |
098d3082 | 6783 | Set_Enumeration_Rep (Elit, Val); |
6784 | end if; | |
d6f39728 | 6785 | end if; |
6786 | end if; | |
6787 | end if; | |
6788 | ||
6789 | Next (Assoc); | |
6790 | end loop; | |
6791 | end if; | |
6792 | ||
6793 | -- Aggregate is fully processed. Now we check that a full set of | |
6794 | -- representations was given, and that they are in range and in order. | |
6795 | -- These checks are only done if no other errors occurred. | |
6796 | ||
6797 | if not Err then | |
6798 | Min := No_Uint; | |
6799 | Max := No_Uint; | |
6800 | ||
6801 | Elit := First_Literal (Enumtype); | |
6802 | while Present (Elit) loop | |
6803 | if No (Enumeration_Rep_Expr (Elit)) then | |
6804 | Error_Msg_NE ("missing representation for&!", N, Elit); | |
6805 | ||
6806 | else | |
6807 | Val := Enumeration_Rep (Elit); | |
6808 | ||
6809 | if Min = No_Uint then | |
6810 | Min := Val; | |
6811 | end if; | |
6812 | ||
6813 | if Val /= No_Uint then | |
6814 | if Max /= No_Uint and then Val <= Max then | |
6815 | Error_Msg_NE | |
6816 | ("enumeration value for& not ordered!", | |
e30c7d84 | 6817 | Enumeration_Rep_Expr (Elit), Elit); |
d6f39728 | 6818 | end if; |
6819 | ||
e30c7d84 | 6820 | Max_Node := Enumeration_Rep_Expr (Elit); |
d6f39728 | 6821 | Max := Val; |
6822 | end if; | |
6823 | ||
e30c7d84 | 6824 | -- If there is at least one literal whose representation is not |
6825 | -- equal to the Pos value, then note that this enumeration type | |
6826 | -- has a non-standard representation. | |
d6f39728 | 6827 | |
6828 | if Val /= Enumeration_Pos (Elit) then | |
6829 | Set_Has_Non_Standard_Rep (Base_Type (Enumtype)); | |
6830 | end if; | |
6831 | end if; | |
6832 | ||
6833 | Next (Elit); | |
6834 | end loop; | |
6835 | ||
6836 | -- Now set proper size information | |
6837 | ||
6838 | declare | |
6839 | Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype)); | |
6840 | ||
6841 | begin | |
6842 | if Has_Size_Clause (Enumtype) then | |
e30c7d84 | 6843 | |
6844 | -- All OK, if size is OK now | |
6845 | ||
6846 | if RM_Size (Enumtype) >= Minsize then | |
d6f39728 | 6847 | null; |
6848 | ||
6849 | else | |
e30c7d84 | 6850 | -- Try if we can get by with biasing |
6851 | ||
d6f39728 | 6852 | Minsize := |
6853 | UI_From_Int (Minimum_Size (Enumtype, Biased => True)); | |
6854 | ||
e30c7d84 | 6855 | -- Error message if even biasing does not work |
6856 | ||
6857 | if RM_Size (Enumtype) < Minsize then | |
6858 | Error_Msg_Uint_1 := RM_Size (Enumtype); | |
6859 | Error_Msg_Uint_2 := Max; | |
6860 | Error_Msg_N | |
6861 | ("previously given size (^) is too small " | |
6862 | & "for this value (^)", Max_Node); | |
6863 | ||
6864 | -- If biasing worked, indicate that we now have biased rep | |
d6f39728 | 6865 | |
6866 | else | |
b77e4501 | 6867 | Set_Biased |
6868 | (Enumtype, Size_Clause (Enumtype), "size clause"); | |
d6f39728 | 6869 | end if; |
6870 | end if; | |
6871 | ||
6872 | else | |
6873 | Set_RM_Size (Enumtype, Minsize); | |
6874 | Set_Enum_Esize (Enumtype); | |
6875 | end if; | |
6876 | ||
6877 | Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype)); | |
6878 | Set_Esize (Base_Type (Enumtype), Esize (Enumtype)); | |
6879 | Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype)); | |
6880 | end; | |
6881 | end if; | |
6882 | ||
39a0c1d3 | 6883 | -- We repeat the too late test in case it froze itself |
d6f39728 | 6884 | |
6885 | if Rep_Item_Too_Late (Enumtype, N) then | |
6886 | null; | |
6887 | end if; | |
d6f39728 | 6888 | end Analyze_Enumeration_Representation_Clause; |
6889 | ||
6890 | ---------------------------- | |
6891 | -- Analyze_Free_Statement -- | |
6892 | ---------------------------- | |
6893 | ||
6894 | procedure Analyze_Free_Statement (N : Node_Id) is | |
6895 | begin | |
6896 | Analyze (Expression (N)); | |
6897 | end Analyze_Free_Statement; | |
6898 | ||
40ca69b9 | 6899 | --------------------------- |
6900 | -- Analyze_Freeze_Entity -- | |
6901 | --------------------------- | |
6902 | ||
6903 | procedure Analyze_Freeze_Entity (N : Node_Id) is | |
40ca69b9 | 6904 | begin |
d9f6a4ee | 6905 | Freeze_Entity_Checks (N); |
6906 | end Analyze_Freeze_Entity; | |
98f7db28 | 6907 | |
d9f6a4ee | 6908 | ----------------------------------- |
6909 | -- Analyze_Freeze_Generic_Entity -- | |
6910 | ----------------------------------- | |
98f7db28 | 6911 | |
d9f6a4ee | 6912 | procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is |
61989dbb | 6913 | E : constant Entity_Id := Entity (N); |
6914 | ||
d9f6a4ee | 6915 | begin |
61989dbb | 6916 | if not Is_Frozen (E) and then Has_Delayed_Aspects (E) then |
6917 | Analyze_Aspects_At_Freeze_Point (E); | |
6918 | end if; | |
6919 | ||
d9f6a4ee | 6920 | Freeze_Entity_Checks (N); |
6921 | end Analyze_Freeze_Generic_Entity; | |
40ca69b9 | 6922 | |
d9f6a4ee | 6923 | ------------------------------------------ |
6924 | -- Analyze_Record_Representation_Clause -- | |
6925 | ------------------------------------------ | |
c8da6114 | 6926 | |
d9f6a4ee | 6927 | -- Note: we check as much as we can here, but we can't do any checks |
6928 | -- based on the position values (e.g. overlap checks) until freeze time | |
6929 | -- because especially in Ada 2005 (machine scalar mode), the processing | |
6930 | -- for non-standard bit order can substantially change the positions. | |
6931 | -- See procedure Check_Record_Representation_Clause (called from Freeze) | |
6932 | -- for the remainder of this processing. | |
d00681a7 | 6933 | |
d9f6a4ee | 6934 | procedure Analyze_Record_Representation_Clause (N : Node_Id) is |
6935 | Ident : constant Node_Id := Identifier (N); | |
6936 | Biased : Boolean; | |
6937 | CC : Node_Id; | |
6938 | Comp : Entity_Id; | |
6939 | Fbit : Uint; | |
6940 | Hbit : Uint := Uint_0; | |
6941 | Lbit : Uint; | |
6942 | Ocomp : Entity_Id; | |
6943 | Posit : Uint; | |
6944 | Rectype : Entity_Id; | |
6945 | Recdef : Node_Id; | |
d00681a7 | 6946 | |
d9f6a4ee | 6947 | function Is_Inherited (Comp : Entity_Id) return Boolean; |
6948 | -- True if Comp is an inherited component in a record extension | |
d00681a7 | 6949 | |
d9f6a4ee | 6950 | ------------------ |
6951 | -- Is_Inherited -- | |
6952 | ------------------ | |
d00681a7 | 6953 | |
d9f6a4ee | 6954 | function Is_Inherited (Comp : Entity_Id) return Boolean is |
6955 | Comp_Base : Entity_Id; | |
d00681a7 | 6956 | |
d9f6a4ee | 6957 | begin |
6958 | if Ekind (Rectype) = E_Record_Subtype then | |
6959 | Comp_Base := Original_Record_Component (Comp); | |
6960 | else | |
6961 | Comp_Base := Comp; | |
d00681a7 | 6962 | end if; |
6963 | ||
d9f6a4ee | 6964 | return Comp_Base /= Original_Record_Component (Comp_Base); |
6965 | end Is_Inherited; | |
d00681a7 | 6966 | |
d9f6a4ee | 6967 | -- Local variables |
d00681a7 | 6968 | |
d9f6a4ee | 6969 | Is_Record_Extension : Boolean; |
6970 | -- True if Rectype is a record extension | |
d00681a7 | 6971 | |
d9f6a4ee | 6972 | CR_Pragma : Node_Id := Empty; |
6973 | -- Points to N_Pragma node if Complete_Representation pragma present | |
d00681a7 | 6974 | |
d9f6a4ee | 6975 | -- Start of processing for Analyze_Record_Representation_Clause |
d00681a7 | 6976 | |
d9f6a4ee | 6977 | begin |
6978 | if Ignore_Rep_Clauses then | |
2ff55065 | 6979 | Kill_Rep_Clause (N); |
d9f6a4ee | 6980 | return; |
d00681a7 | 6981 | end if; |
98f7db28 | 6982 | |
d9f6a4ee | 6983 | Find_Type (Ident); |
6984 | Rectype := Entity (Ident); | |
85377c9b | 6985 | |
d9f6a4ee | 6986 | if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then |
6987 | return; | |
6988 | else | |
6989 | Rectype := Underlying_Type (Rectype); | |
6990 | end if; | |
85377c9b | 6991 | |
d9f6a4ee | 6992 | -- First some basic error checks |
85377c9b | 6993 | |
d9f6a4ee | 6994 | if not Is_Record_Type (Rectype) then |
6995 | Error_Msg_NE | |
6996 | ("record type required, found}", Ident, First_Subtype (Rectype)); | |
6997 | return; | |
85377c9b | 6998 | |
d9f6a4ee | 6999 | elsif Scope (Rectype) /= Current_Scope then |
7000 | Error_Msg_N ("type must be declared in this scope", N); | |
7001 | return; | |
85377c9b | 7002 | |
d9f6a4ee | 7003 | elsif not Is_First_Subtype (Rectype) then |
7004 | Error_Msg_N ("cannot give record rep clause for subtype", N); | |
7005 | return; | |
9dc88aea | 7006 | |
d9f6a4ee | 7007 | elsif Has_Record_Rep_Clause (Rectype) then |
7008 | Error_Msg_N ("duplicate record rep clause ignored", N); | |
7009 | return; | |
9dc88aea | 7010 | |
d9f6a4ee | 7011 | elsif Rep_Item_Too_Late (Rectype, N) then |
7012 | return; | |
9dc88aea | 7013 | end if; |
fb7f2fc4 | 7014 | |
2ced3742 | 7015 | -- We know we have a first subtype, now possibly go to the anonymous |
d9f6a4ee | 7016 | -- base type to determine whether Rectype is a record extension. |
89f1e35c | 7017 | |
d9f6a4ee | 7018 | Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype))); |
7019 | Is_Record_Extension := | |
7020 | Nkind (Recdef) = N_Derived_Type_Definition | |
7021 | and then Present (Record_Extension_Part (Recdef)); | |
89f1e35c | 7022 | |
d9f6a4ee | 7023 | if Present (Mod_Clause (N)) then |
fb7f2fc4 | 7024 | declare |
d9f6a4ee | 7025 | Loc : constant Source_Ptr := Sloc (N); |
7026 | M : constant Node_Id := Mod_Clause (N); | |
7027 | P : constant List_Id := Pragmas_Before (M); | |
7028 | AtM_Nod : Node_Id; | |
7029 | ||
7030 | Mod_Val : Uint; | |
7031 | pragma Warnings (Off, Mod_Val); | |
fb7f2fc4 | 7032 | |
7033 | begin | |
d9f6a4ee | 7034 | Check_Restriction (No_Obsolescent_Features, Mod_Clause (N)); |
fb7f2fc4 | 7035 | |
d9f6a4ee | 7036 | if Warn_On_Obsolescent_Feature then |
7037 | Error_Msg_N | |
7038 | ("?j?mod clause is an obsolescent feature (RM J.8)", N); | |
7039 | Error_Msg_N | |
7040 | ("\?j?use alignment attribute definition clause instead", N); | |
7041 | end if; | |
fb7f2fc4 | 7042 | |
d9f6a4ee | 7043 | if Present (P) then |
7044 | Analyze_List (P); | |
7045 | end if; | |
89f1e35c | 7046 | |
d9f6a4ee | 7047 | -- In ASIS_Mode mode, expansion is disabled, but we must convert |
7048 | -- the Mod clause into an alignment clause anyway, so that the | |
3ff5e35d | 7049 | -- back end can compute and back-annotate properly the size and |
d9f6a4ee | 7050 | -- alignment of types that may include this record. |
be9124d0 | 7051 | |
d9f6a4ee | 7052 | -- This seems dubious, this destroys the source tree in a manner |
7053 | -- not detectable by ASIS ??? | |
be9124d0 | 7054 | |
d9f6a4ee | 7055 | if Operating_Mode = Check_Semantics and then ASIS_Mode then |
7056 | AtM_Nod := | |
7057 | Make_Attribute_Definition_Clause (Loc, | |
83c6c069 | 7058 | Name => New_Occurrence_Of (Base_Type (Rectype), Loc), |
d9f6a4ee | 7059 | Chars => Name_Alignment, |
7060 | Expression => Relocate_Node (Expression (M))); | |
be9124d0 | 7061 | |
d9f6a4ee | 7062 | Set_From_At_Mod (AtM_Nod); |
7063 | Insert_After (N, AtM_Nod); | |
7064 | Mod_Val := Get_Alignment_Value (Expression (AtM_Nod)); | |
7065 | Set_Mod_Clause (N, Empty); | |
be9124d0 | 7066 | |
d9f6a4ee | 7067 | else |
7068 | -- Get the alignment value to perform error checking | |
be9124d0 | 7069 | |
d9f6a4ee | 7070 | Mod_Val := Get_Alignment_Value (Expression (M)); |
7071 | end if; | |
7072 | end; | |
7073 | end if; | |
be9124d0 | 7074 | |
d9f6a4ee | 7075 | -- For untagged types, clear any existing component clauses for the |
7076 | -- type. If the type is derived, this is what allows us to override | |
7077 | -- a rep clause for the parent. For type extensions, the representation | |
7078 | -- of the inherited components is inherited, so we want to keep previous | |
7079 | -- component clauses for completeness. | |
be9124d0 | 7080 | |
d9f6a4ee | 7081 | if not Is_Tagged_Type (Rectype) then |
7082 | Comp := First_Component_Or_Discriminant (Rectype); | |
7083 | while Present (Comp) loop | |
7084 | Set_Component_Clause (Comp, Empty); | |
7085 | Next_Component_Or_Discriminant (Comp); | |
7086 | end loop; | |
7087 | end if; | |
be9124d0 | 7088 | |
d9f6a4ee | 7089 | -- All done if no component clauses |
be9124d0 | 7090 | |
d9f6a4ee | 7091 | CC := First (Component_Clauses (N)); |
be9124d0 | 7092 | |
d9f6a4ee | 7093 | if No (CC) then |
7094 | return; | |
7095 | end if; | |
be9124d0 | 7096 | |
d9f6a4ee | 7097 | -- A representation like this applies to the base type |
be9124d0 | 7098 | |
d9f6a4ee | 7099 | Set_Has_Record_Rep_Clause (Base_Type (Rectype)); |
7100 | Set_Has_Non_Standard_Rep (Base_Type (Rectype)); | |
7101 | Set_Has_Specified_Layout (Base_Type (Rectype)); | |
be9124d0 | 7102 | |
d9f6a4ee | 7103 | -- Process the component clauses |
be9124d0 | 7104 | |
d9f6a4ee | 7105 | while Present (CC) loop |
be9124d0 | 7106 | |
d9f6a4ee | 7107 | -- Pragma |
be9124d0 | 7108 | |
d9f6a4ee | 7109 | if Nkind (CC) = N_Pragma then |
7110 | Analyze (CC); | |
be9124d0 | 7111 | |
d9f6a4ee | 7112 | -- The only pragma of interest is Complete_Representation |
be9124d0 | 7113 | |
ddccc924 | 7114 | if Pragma_Name (CC) = Name_Complete_Representation then |
d9f6a4ee | 7115 | CR_Pragma := CC; |
7116 | end if; | |
be9124d0 | 7117 | |
d9f6a4ee | 7118 | -- Processing for real component clause |
be9124d0 | 7119 | |
d9f6a4ee | 7120 | else |
7121 | Posit := Static_Integer (Position (CC)); | |
7122 | Fbit := Static_Integer (First_Bit (CC)); | |
7123 | Lbit := Static_Integer (Last_Bit (CC)); | |
be9124d0 | 7124 | |
d9f6a4ee | 7125 | if Posit /= No_Uint |
7126 | and then Fbit /= No_Uint | |
7127 | and then Lbit /= No_Uint | |
7128 | then | |
7129 | if Posit < 0 then | |
f74a102b | 7130 | Error_Msg_N ("position cannot be negative", Position (CC)); |
be9124d0 | 7131 | |
d9f6a4ee | 7132 | elsif Fbit < 0 then |
f74a102b | 7133 | Error_Msg_N ("first bit cannot be negative", First_Bit (CC)); |
be9124d0 | 7134 | |
d9f6a4ee | 7135 | -- The Last_Bit specified in a component clause must not be |
7136 | -- less than the First_Bit minus one (RM-13.5.1(10)). | |
be9124d0 | 7137 | |
d9f6a4ee | 7138 | elsif Lbit < Fbit - 1 then |
7139 | Error_Msg_N | |
7140 | ("last bit cannot be less than first bit minus one", | |
7141 | Last_Bit (CC)); | |
be9124d0 | 7142 | |
d9f6a4ee | 7143 | -- Values look OK, so find the corresponding record component |
7144 | -- Even though the syntax allows an attribute reference for | |
7145 | -- implementation-defined components, GNAT does not allow the | |
7146 | -- tag to get an explicit position. | |
be9124d0 | 7147 | |
d9f6a4ee | 7148 | elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then |
7149 | if Attribute_Name (Component_Name (CC)) = Name_Tag then | |
7150 | Error_Msg_N ("position of tag cannot be specified", CC); | |
7151 | else | |
7152 | Error_Msg_N ("illegal component name", CC); | |
7153 | end if; | |
be9124d0 | 7154 | |
d9f6a4ee | 7155 | else |
7156 | Comp := First_Entity (Rectype); | |
7157 | while Present (Comp) loop | |
7158 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
7159 | Next_Entity (Comp); | |
7160 | end loop; | |
be9124d0 | 7161 | |
d9f6a4ee | 7162 | if No (Comp) then |
be9124d0 | 7163 | |
d9f6a4ee | 7164 | -- Maybe component of base type that is absent from |
7165 | -- statically constrained first subtype. | |
be9124d0 | 7166 | |
d9f6a4ee | 7167 | Comp := First_Entity (Base_Type (Rectype)); |
7168 | while Present (Comp) loop | |
7169 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
7170 | Next_Entity (Comp); | |
7171 | end loop; | |
7172 | end if; | |
be9124d0 | 7173 | |
d9f6a4ee | 7174 | if No (Comp) then |
7175 | Error_Msg_N | |
7176 | ("component clause is for non-existent field", CC); | |
be9124d0 | 7177 | |
d9f6a4ee | 7178 | -- Ada 2012 (AI05-0026): Any name that denotes a |
7179 | -- discriminant of an object of an unchecked union type | |
7180 | -- shall not occur within a record_representation_clause. | |
be9124d0 | 7181 | |
d9f6a4ee | 7182 | -- The general restriction of using record rep clauses on |
7183 | -- Unchecked_Union types has now been lifted. Since it is | |
7184 | -- possible to introduce a record rep clause which mentions | |
7185 | -- the discriminant of an Unchecked_Union in non-Ada 2012 | |
7186 | -- code, this check is applied to all versions of the | |
7187 | -- language. | |
be9124d0 | 7188 | |
d9f6a4ee | 7189 | elsif Ekind (Comp) = E_Discriminant |
7190 | and then Is_Unchecked_Union (Rectype) | |
7191 | then | |
7192 | Error_Msg_N | |
7193 | ("cannot reference discriminant of unchecked union", | |
7194 | Component_Name (CC)); | |
be9124d0 | 7195 | |
d9f6a4ee | 7196 | elsif Is_Record_Extension and then Is_Inherited (Comp) then |
7197 | Error_Msg_NE | |
7198 | ("component clause not allowed for inherited " | |
7199 | & "component&", CC, Comp); | |
40ca69b9 | 7200 | |
d9f6a4ee | 7201 | elsif Present (Component_Clause (Comp)) then |
462a079f | 7202 | |
d9f6a4ee | 7203 | -- Diagnose duplicate rep clause, or check consistency |
7204 | -- if this is an inherited component. In a double fault, | |
7205 | -- there may be a duplicate inconsistent clause for an | |
7206 | -- inherited component. | |
462a079f | 7207 | |
d9f6a4ee | 7208 | if Scope (Original_Record_Component (Comp)) = Rectype |
7209 | or else Parent (Component_Clause (Comp)) = N | |
7210 | then | |
7211 | Error_Msg_Sloc := Sloc (Component_Clause (Comp)); | |
7212 | Error_Msg_N ("component clause previously given#", CC); | |
3062c401 | 7213 | |
7214 | else | |
7215 | declare | |
7216 | Rep1 : constant Node_Id := Component_Clause (Comp); | |
3062c401 | 7217 | begin |
7218 | if Intval (Position (Rep1)) /= | |
7219 | Intval (Position (CC)) | |
7220 | or else Intval (First_Bit (Rep1)) /= | |
7221 | Intval (First_Bit (CC)) | |
7222 | or else Intval (Last_Bit (Rep1)) /= | |
7223 | Intval (Last_Bit (CC)) | |
7224 | then | |
b9e61b2a | 7225 | Error_Msg_N |
f74a102b | 7226 | ("component clause inconsistent with " |
7227 | & "representation of ancestor", CC); | |
6a06584c | 7228 | |
3062c401 | 7229 | elsif Warn_On_Redundant_Constructs then |
b9e61b2a | 7230 | Error_Msg_N |
6a06584c | 7231 | ("?r?redundant confirming component clause " |
7232 | & "for component!", CC); | |
3062c401 | 7233 | end if; |
7234 | end; | |
7235 | end if; | |
d6f39728 | 7236 | |
d2b860b4 | 7237 | -- Normal case where this is the first component clause we |
7238 | -- have seen for this entity, so set it up properly. | |
7239 | ||
d6f39728 | 7240 | else |
83f8f0a6 | 7241 | -- Make reference for field in record rep clause and set |
7242 | -- appropriate entity field in the field identifier. | |
7243 | ||
7244 | Generate_Reference | |
7245 | (Comp, Component_Name (CC), Set_Ref => False); | |
7246 | Set_Entity (Component_Name (CC), Comp); | |
7247 | ||
2866d595 | 7248 | -- Update Fbit and Lbit to the actual bit number |
d6f39728 | 7249 | |
7250 | Fbit := Fbit + UI_From_Int (SSU) * Posit; | |
7251 | Lbit := Lbit + UI_From_Int (SSU) * Posit; | |
7252 | ||
d6f39728 | 7253 | if Has_Size_Clause (Rectype) |
ada34def | 7254 | and then RM_Size (Rectype) <= Lbit |
d6f39728 | 7255 | then |
7256 | Error_Msg_N | |
7257 | ("bit number out of range of specified size", | |
7258 | Last_Bit (CC)); | |
7259 | else | |
7260 | Set_Component_Clause (Comp, CC); | |
7261 | Set_Component_Bit_Offset (Comp, Fbit); | |
7262 | Set_Esize (Comp, 1 + (Lbit - Fbit)); | |
7263 | Set_Normalized_First_Bit (Comp, Fbit mod SSU); | |
7264 | Set_Normalized_Position (Comp, Fbit / SSU); | |
7265 | ||
a0fc8c5b | 7266 | if Warn_On_Overridden_Size |
7267 | and then Has_Size_Clause (Etype (Comp)) | |
7268 | and then RM_Size (Etype (Comp)) /= Esize (Comp) | |
7269 | then | |
7270 | Error_Msg_NE | |
1e3532e7 | 7271 | ("?S?component size overrides size clause for&", |
a0fc8c5b | 7272 | Component_Name (CC), Etype (Comp)); |
7273 | end if; | |
7274 | ||
ea61a7ea | 7275 | -- This information is also set in the corresponding |
7276 | -- component of the base type, found by accessing the | |
7277 | -- Original_Record_Component link if it is present. | |
d6f39728 | 7278 | |
7279 | Ocomp := Original_Record_Component (Comp); | |
7280 | ||
7281 | if Hbit < Lbit then | |
7282 | Hbit := Lbit; | |
7283 | end if; | |
7284 | ||
7285 | Check_Size | |
7286 | (Component_Name (CC), | |
7287 | Etype (Comp), | |
7288 | Esize (Comp), | |
7289 | Biased); | |
7290 | ||
b77e4501 | 7291 | Set_Biased |
7292 | (Comp, First_Node (CC), "component clause", Biased); | |
cc46ff4b | 7293 | |
d6f39728 | 7294 | if Present (Ocomp) then |
7295 | Set_Component_Clause (Ocomp, CC); | |
7296 | Set_Component_Bit_Offset (Ocomp, Fbit); | |
7297 | Set_Normalized_First_Bit (Ocomp, Fbit mod SSU); | |
7298 | Set_Normalized_Position (Ocomp, Fbit / SSU); | |
7299 | Set_Esize (Ocomp, 1 + (Lbit - Fbit)); | |
7300 | ||
7301 | Set_Normalized_Position_Max | |
7302 | (Ocomp, Normalized_Position (Ocomp)); | |
7303 | ||
b77e4501 | 7304 | -- Note: we don't use Set_Biased here, because we |
7305 | -- already gave a warning above if needed, and we | |
7306 | -- would get a duplicate for the same name here. | |
7307 | ||
d6f39728 | 7308 | Set_Has_Biased_Representation |
7309 | (Ocomp, Has_Biased_Representation (Comp)); | |
7310 | end if; | |
7311 | ||
7312 | if Esize (Comp) < 0 then | |
7313 | Error_Msg_N ("component size is negative", CC); | |
7314 | end if; | |
7315 | end if; | |
7316 | end if; | |
7317 | end if; | |
7318 | end if; | |
7319 | end if; | |
7320 | ||
7321 | Next (CC); | |
7322 | end loop; | |
7323 | ||
67278d60 | 7324 | -- Check missing components if Complete_Representation pragma appeared |
d6f39728 | 7325 | |
67278d60 | 7326 | if Present (CR_Pragma) then |
7327 | Comp := First_Component_Or_Discriminant (Rectype); | |
7328 | while Present (Comp) loop | |
7329 | if No (Component_Clause (Comp)) then | |
7330 | Error_Msg_NE | |
7331 | ("missing component clause for &", CR_Pragma, Comp); | |
7332 | end if; | |
d6f39728 | 7333 | |
67278d60 | 7334 | Next_Component_Or_Discriminant (Comp); |
7335 | end loop; | |
d6f39728 | 7336 | |
1e3532e7 | 7337 | -- Give missing components warning if required |
15ebb600 | 7338 | |
fdd294d1 | 7339 | elsif Warn_On_Unrepped_Components then |
15ebb600 | 7340 | declare |
7341 | Num_Repped_Components : Nat := 0; | |
7342 | Num_Unrepped_Components : Nat := 0; | |
7343 | ||
7344 | begin | |
7345 | -- First count number of repped and unrepped components | |
7346 | ||
7347 | Comp := First_Component_Or_Discriminant (Rectype); | |
7348 | while Present (Comp) loop | |
7349 | if Present (Component_Clause (Comp)) then | |
7350 | Num_Repped_Components := Num_Repped_Components + 1; | |
7351 | else | |
7352 | Num_Unrepped_Components := Num_Unrepped_Components + 1; | |
7353 | end if; | |
7354 | ||
7355 | Next_Component_Or_Discriminant (Comp); | |
7356 | end loop; | |
7357 | ||
7358 | -- We are only interested in the case where there is at least one | |
7359 | -- unrepped component, and at least half the components have rep | |
7360 | -- clauses. We figure that if less than half have them, then the | |
87f9eef5 | 7361 | -- partial rep clause is really intentional. If the component |
7362 | -- type has no underlying type set at this point (as for a generic | |
7363 | -- formal type), we don't know enough to give a warning on the | |
7364 | -- component. | |
15ebb600 | 7365 | |
7366 | if Num_Unrepped_Components > 0 | |
7367 | and then Num_Unrepped_Components < Num_Repped_Components | |
7368 | then | |
7369 | Comp := First_Component_Or_Discriminant (Rectype); | |
7370 | while Present (Comp) loop | |
83f8f0a6 | 7371 | if No (Component_Clause (Comp)) |
3062c401 | 7372 | and then Comes_From_Source (Comp) |
87f9eef5 | 7373 | and then Present (Underlying_Type (Etype (Comp))) |
83f8f0a6 | 7374 | and then (Is_Scalar_Type (Underlying_Type (Etype (Comp))) |
67278d60 | 7375 | or else Size_Known_At_Compile_Time |
7376 | (Underlying_Type (Etype (Comp)))) | |
fdd294d1 | 7377 | and then not Has_Warnings_Off (Rectype) |
2be1f7d7 | 7378 | |
7379 | -- Ignore discriminant in unchecked union, since it is | |
7380 | -- not there, and cannot have a component clause. | |
7381 | ||
7382 | and then (not Is_Unchecked_Union (Rectype) | |
7383 | or else Ekind (Comp) /= E_Discriminant) | |
83f8f0a6 | 7384 | then |
15ebb600 | 7385 | Error_Msg_Sloc := Sloc (Comp); |
7386 | Error_Msg_NE | |
1e3532e7 | 7387 | ("?C?no component clause given for & declared #", |
15ebb600 | 7388 | N, Comp); |
7389 | end if; | |
7390 | ||
7391 | Next_Component_Or_Discriminant (Comp); | |
7392 | end loop; | |
7393 | end if; | |
7394 | end; | |
d6f39728 | 7395 | end if; |
d6f39728 | 7396 | end Analyze_Record_Representation_Clause; |
7397 | ||
eb66e842 | 7398 | ------------------------------------- |
7399 | -- Build_Discrete_Static_Predicate -- | |
7400 | ------------------------------------- | |
9ea61fdd | 7401 | |
eb66e842 | 7402 | procedure Build_Discrete_Static_Predicate |
7403 | (Typ : Entity_Id; | |
7404 | Expr : Node_Id; | |
7405 | Nam : Name_Id) | |
9ea61fdd | 7406 | is |
eb66e842 | 7407 | Loc : constant Source_Ptr := Sloc (Expr); |
9ea61fdd | 7408 | |
eb66e842 | 7409 | Non_Static : exception; |
7410 | -- Raised if something non-static is found | |
9ea61fdd | 7411 | |
eb66e842 | 7412 | Btyp : constant Entity_Id := Base_Type (Typ); |
9ea61fdd | 7413 | |
eb66e842 | 7414 | BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp)); |
7415 | BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp)); | |
7416 | -- Low bound and high bound value of base type of Typ | |
9ea61fdd | 7417 | |
afc229da | 7418 | TLo : Uint; |
7419 | THi : Uint; | |
7420 | -- Bounds for constructing the static predicate. We use the bound of the | |
7421 | -- subtype if it is static, otherwise the corresponding base type bound. | |
7422 | -- Note: a non-static subtype can have a static predicate. | |
9ea61fdd | 7423 | |
eb66e842 | 7424 | type REnt is record |
7425 | Lo, Hi : Uint; | |
7426 | end record; | |
7427 | -- One entry in a Rlist value, a single REnt (range entry) value denotes | |
7428 | -- one range from Lo to Hi. To represent a single value range Lo = Hi = | |
7429 | -- value. | |
9ea61fdd | 7430 | |
eb66e842 | 7431 | type RList is array (Nat range <>) of REnt; |
7432 | -- A list of ranges. The ranges are sorted in increasing order, and are | |
7433 | -- disjoint (there is a gap of at least one value between each range in | |
7434 | -- the table). A value is in the set of ranges in Rlist if it lies | |
7435 | -- within one of these ranges. | |
9ea61fdd | 7436 | |
eb66e842 | 7437 | False_Range : constant RList := |
7438 | RList'(1 .. 0 => REnt'(No_Uint, No_Uint)); | |
7439 | -- An empty set of ranges represents a range list that can never be | |
7440 | -- satisfied, since there are no ranges in which the value could lie, | |
7441 | -- so it does not lie in any of them. False_Range is a canonical value | |
7442 | -- for this empty set, but general processing should test for an Rlist | |
7443 | -- with length zero (see Is_False predicate), since other null ranges | |
7444 | -- may appear which must be treated as False. | |
5b5df4a9 | 7445 | |
eb66e842 | 7446 | True_Range : constant RList := RList'(1 => REnt'(BLo, BHi)); |
7447 | -- Range representing True, value must be in the base range | |
5b5df4a9 | 7448 | |
eb66e842 | 7449 | function "and" (Left : RList; Right : RList) return RList; |
7450 | -- And's together two range lists, returning a range list. This is a set | |
7451 | -- intersection operation. | |
5b5df4a9 | 7452 | |
eb66e842 | 7453 | function "or" (Left : RList; Right : RList) return RList; |
7454 | -- Or's together two range lists, returning a range list. This is a set | |
7455 | -- union operation. | |
87f3d5d3 | 7456 | |
eb66e842 | 7457 | function "not" (Right : RList) return RList; |
7458 | -- Returns complement of a given range list, i.e. a range list | |
7459 | -- representing all the values in TLo .. THi that are not in the input | |
7460 | -- operand Right. | |
ed4adc99 | 7461 | |
eb66e842 | 7462 | function Build_Val (V : Uint) return Node_Id; |
7463 | -- Return an analyzed N_Identifier node referencing this value, suitable | |
5c6a5792 | 7464 | -- for use as an entry in the Static_Discrte_Predicate list. This node |
7465 | -- is typed with the base type. | |
5b5df4a9 | 7466 | |
eb66e842 | 7467 | function Build_Range (Lo : Uint; Hi : Uint) return Node_Id; |
7468 | -- Return an analyzed N_Range node referencing this range, suitable for | |
5c6a5792 | 7469 | -- use as an entry in the Static_Discrete_Predicate list. This node is |
7470 | -- typed with the base type. | |
5b5df4a9 | 7471 | |
eb66e842 | 7472 | function Get_RList (Exp : Node_Id) return RList; |
7473 | -- This is a recursive routine that converts the given expression into a | |
7474 | -- list of ranges, suitable for use in building the static predicate. | |
5b5df4a9 | 7475 | |
eb66e842 | 7476 | function Is_False (R : RList) return Boolean; |
7477 | pragma Inline (Is_False); | |
7478 | -- Returns True if the given range list is empty, and thus represents a | |
7479 | -- False list of ranges that can never be satisfied. | |
87f3d5d3 | 7480 | |
eb66e842 | 7481 | function Is_True (R : RList) return Boolean; |
7482 | -- Returns True if R trivially represents the True predicate by having a | |
7483 | -- single range from BLo to BHi. | |
5b5df4a9 | 7484 | |
eb66e842 | 7485 | function Is_Type_Ref (N : Node_Id) return Boolean; |
7486 | pragma Inline (Is_Type_Ref); | |
7487 | -- Returns if True if N is a reference to the type for the predicate in | |
7488 | -- the expression (i.e. if it is an identifier whose Chars field matches | |
7de4cba3 | 7489 | -- the Nam given in the call). N must not be parenthesized, if the type |
7490 | -- name appears in parens, this routine will return False. | |
5b5df4a9 | 7491 | |
eb66e842 | 7492 | function Lo_Val (N : Node_Id) return Uint; |
5c6a5792 | 7493 | -- Given an entry from a Static_Discrete_Predicate list that is either |
7494 | -- a static expression or static range, gets either the expression value | |
7495 | -- or the low bound of the range. | |
5b5df4a9 | 7496 | |
eb66e842 | 7497 | function Hi_Val (N : Node_Id) return Uint; |
5c6a5792 | 7498 | -- Given an entry from a Static_Discrete_Predicate list that is either |
7499 | -- a static expression or static range, gets either the expression value | |
7500 | -- or the high bound of the range. | |
5b5df4a9 | 7501 | |
eb66e842 | 7502 | function Membership_Entry (N : Node_Id) return RList; |
7503 | -- Given a single membership entry (range, value, or subtype), returns | |
7504 | -- the corresponding range list. Raises Static_Error if not static. | |
5b5df4a9 | 7505 | |
eb66e842 | 7506 | function Membership_Entries (N : Node_Id) return RList; |
7507 | -- Given an element on an alternatives list of a membership operation, | |
7508 | -- returns the range list corresponding to this entry and all following | |
7509 | -- entries (i.e. returns the "or" of this list of values). | |
b9e61b2a | 7510 | |
eb66e842 | 7511 | function Stat_Pred (Typ : Entity_Id) return RList; |
7512 | -- Given a type, if it has a static predicate, then return the predicate | |
7513 | -- as a range list, otherwise raise Non_Static. | |
c4968aa2 | 7514 | |
eb66e842 | 7515 | ----------- |
7516 | -- "and" -- | |
7517 | ----------- | |
c4968aa2 | 7518 | |
eb66e842 | 7519 | function "and" (Left : RList; Right : RList) return RList is |
7520 | FEnt : REnt; | |
7521 | -- First range of result | |
c4968aa2 | 7522 | |
eb66e842 | 7523 | SLeft : Nat := Left'First; |
7524 | -- Start of rest of left entries | |
c4968aa2 | 7525 | |
eb66e842 | 7526 | SRight : Nat := Right'First; |
7527 | -- Start of rest of right entries | |
2072eaa9 | 7528 | |
eb66e842 | 7529 | begin |
7530 | -- If either range is True, return the other | |
5b5df4a9 | 7531 | |
eb66e842 | 7532 | if Is_True (Left) then |
7533 | return Right; | |
7534 | elsif Is_True (Right) then | |
7535 | return Left; | |
7536 | end if; | |
87f3d5d3 | 7537 | |
eb66e842 | 7538 | -- If either range is False, return False |
5b5df4a9 | 7539 | |
eb66e842 | 7540 | if Is_False (Left) or else Is_False (Right) then |
7541 | return False_Range; | |
7542 | end if; | |
4c1fd062 | 7543 | |
eb66e842 | 7544 | -- Loop to remove entries at start that are disjoint, and thus just |
7545 | -- get discarded from the result entirely. | |
5b5df4a9 | 7546 | |
eb66e842 | 7547 | loop |
7548 | -- If no operands left in either operand, result is false | |
5b5df4a9 | 7549 | |
eb66e842 | 7550 | if SLeft > Left'Last or else SRight > Right'Last then |
7551 | return False_Range; | |
5b5df4a9 | 7552 | |
eb66e842 | 7553 | -- Discard first left operand entry if disjoint with right |
5b5df4a9 | 7554 | |
eb66e842 | 7555 | elsif Left (SLeft).Hi < Right (SRight).Lo then |
7556 | SLeft := SLeft + 1; | |
5b5df4a9 | 7557 | |
eb66e842 | 7558 | -- Discard first right operand entry if disjoint with left |
5b5df4a9 | 7559 | |
eb66e842 | 7560 | elsif Right (SRight).Hi < Left (SLeft).Lo then |
7561 | SRight := SRight + 1; | |
5b5df4a9 | 7562 | |
eb66e842 | 7563 | -- Otherwise we have an overlapping entry |
5b5df4a9 | 7564 | |
eb66e842 | 7565 | else |
7566 | exit; | |
7567 | end if; | |
7568 | end loop; | |
5b5df4a9 | 7569 | |
eb66e842 | 7570 | -- Now we have two non-null operands, and first entries overlap. The |
7571 | -- first entry in the result will be the overlapping part of these | |
7572 | -- two entries. | |
47a46747 | 7573 | |
eb66e842 | 7574 | FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo), |
7575 | Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi)); | |
47a46747 | 7576 | |
eb66e842 | 7577 | -- Now we can remove the entry that ended at a lower value, since its |
7578 | -- contribution is entirely contained in Fent. | |
5b5df4a9 | 7579 | |
eb66e842 | 7580 | if Left (SLeft).Hi <= Right (SRight).Hi then |
7581 | SLeft := SLeft + 1; | |
7582 | else | |
7583 | SRight := SRight + 1; | |
7584 | end if; | |
5b5df4a9 | 7585 | |
eb66e842 | 7586 | -- Compute result by concatenating this first entry with the "and" of |
7587 | -- the remaining parts of the left and right operands. Note that if | |
7588 | -- either of these is empty, "and" will yield empty, so that we will | |
7589 | -- end up with just Fent, which is what we want in that case. | |
5b5df4a9 | 7590 | |
eb66e842 | 7591 | return |
7592 | FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last)); | |
7593 | end "and"; | |
fb7f2fc4 | 7594 | |
eb66e842 | 7595 | ----------- |
7596 | -- "not" -- | |
7597 | ----------- | |
fb7f2fc4 | 7598 | |
eb66e842 | 7599 | function "not" (Right : RList) return RList is |
7600 | begin | |
7601 | -- Return True if False range | |
fb7f2fc4 | 7602 | |
eb66e842 | 7603 | if Is_False (Right) then |
7604 | return True_Range; | |
7605 | end if; | |
ed4adc99 | 7606 | |
eb66e842 | 7607 | -- Return False if True range |
fb7f2fc4 | 7608 | |
eb66e842 | 7609 | if Is_True (Right) then |
7610 | return False_Range; | |
7611 | end if; | |
fb7f2fc4 | 7612 | |
eb66e842 | 7613 | -- Here if not trivial case |
87f3d5d3 | 7614 | |
eb66e842 | 7615 | declare |
7616 | Result : RList (1 .. Right'Length + 1); | |
7617 | -- May need one more entry for gap at beginning and end | |
87f3d5d3 | 7618 | |
eb66e842 | 7619 | Count : Nat := 0; |
7620 | -- Number of entries stored in Result | |
4098232e | 7621 | |
eb66e842 | 7622 | begin |
7623 | -- Gap at start | |
4098232e | 7624 | |
eb66e842 | 7625 | if Right (Right'First).Lo > TLo then |
7626 | Count := Count + 1; | |
7627 | Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1); | |
7628 | end if; | |
ed4adc99 | 7629 | |
eb66e842 | 7630 | -- Gaps between ranges |
ed4adc99 | 7631 | |
eb66e842 | 7632 | for J in Right'First .. Right'Last - 1 loop |
7633 | Count := Count + 1; | |
7634 | Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1); | |
7635 | end loop; | |
5b5df4a9 | 7636 | |
eb66e842 | 7637 | -- Gap at end |
5b5df4a9 | 7638 | |
eb66e842 | 7639 | if Right (Right'Last).Hi < THi then |
7640 | Count := Count + 1; | |
7641 | Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi); | |
7642 | end if; | |
5b5df4a9 | 7643 | |
eb66e842 | 7644 | return Result (1 .. Count); |
7645 | end; | |
7646 | end "not"; | |
5b5df4a9 | 7647 | |
eb66e842 | 7648 | ---------- |
7649 | -- "or" -- | |
7650 | ---------- | |
5b5df4a9 | 7651 | |
eb66e842 | 7652 | function "or" (Left : RList; Right : RList) return RList is |
7653 | FEnt : REnt; | |
7654 | -- First range of result | |
5b5df4a9 | 7655 | |
eb66e842 | 7656 | SLeft : Nat := Left'First; |
7657 | -- Start of rest of left entries | |
5b5df4a9 | 7658 | |
eb66e842 | 7659 | SRight : Nat := Right'First; |
7660 | -- Start of rest of right entries | |
5b5df4a9 | 7661 | |
eb66e842 | 7662 | begin |
7663 | -- If either range is True, return True | |
5b5df4a9 | 7664 | |
eb66e842 | 7665 | if Is_True (Left) or else Is_True (Right) then |
7666 | return True_Range; | |
7667 | end if; | |
5b5df4a9 | 7668 | |
eb66e842 | 7669 | -- If either range is False (empty), return the other |
5b5df4a9 | 7670 | |
eb66e842 | 7671 | if Is_False (Left) then |
7672 | return Right; | |
7673 | elsif Is_False (Right) then | |
7674 | return Left; | |
7675 | end if; | |
5b5df4a9 | 7676 | |
eb66e842 | 7677 | -- Initialize result first entry from left or right operand depending |
7678 | -- on which starts with the lower range. | |
5b5df4a9 | 7679 | |
eb66e842 | 7680 | if Left (SLeft).Lo < Right (SRight).Lo then |
7681 | FEnt := Left (SLeft); | |
7682 | SLeft := SLeft + 1; | |
7683 | else | |
7684 | FEnt := Right (SRight); | |
7685 | SRight := SRight + 1; | |
7686 | end if; | |
5b5df4a9 | 7687 | |
eb66e842 | 7688 | -- This loop eats ranges from left and right operands that are |
7689 | -- contiguous with the first range we are gathering. | |
9ea61fdd | 7690 | |
eb66e842 | 7691 | loop |
7692 | -- Eat first entry in left operand if contiguous or overlapped by | |
7693 | -- gathered first operand of result. | |
9ea61fdd | 7694 | |
eb66e842 | 7695 | if SLeft <= Left'Last |
7696 | and then Left (SLeft).Lo <= FEnt.Hi + 1 | |
7697 | then | |
7698 | FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi); | |
7699 | SLeft := SLeft + 1; | |
9ea61fdd | 7700 | |
eb66e842 | 7701 | -- Eat first entry in right operand if contiguous or overlapped by |
7702 | -- gathered right operand of result. | |
9ea61fdd | 7703 | |
eb66e842 | 7704 | elsif SRight <= Right'Last |
7705 | and then Right (SRight).Lo <= FEnt.Hi + 1 | |
7706 | then | |
7707 | FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi); | |
7708 | SRight := SRight + 1; | |
9ea61fdd | 7709 | |
eb66e842 | 7710 | -- All done if no more entries to eat |
5b5df4a9 | 7711 | |
eb66e842 | 7712 | else |
7713 | exit; | |
7714 | end if; | |
7715 | end loop; | |
5b5df4a9 | 7716 | |
eb66e842 | 7717 | -- Obtain result as the first entry we just computed, concatenated |
7718 | -- to the "or" of the remaining results (if one operand is empty, | |
7719 | -- this will just concatenate with the other | |
5b5df4a9 | 7720 | |
eb66e842 | 7721 | return |
7722 | FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last)); | |
7723 | end "or"; | |
5b5df4a9 | 7724 | |
eb66e842 | 7725 | ----------------- |
7726 | -- Build_Range -- | |
7727 | ----------------- | |
5b5df4a9 | 7728 | |
eb66e842 | 7729 | function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is |
7730 | Result : Node_Id; | |
5b5df4a9 | 7731 | begin |
eb66e842 | 7732 | Result := |
7733 | Make_Range (Loc, | |
7734 | Low_Bound => Build_Val (Lo), | |
7735 | High_Bound => Build_Val (Hi)); | |
7736 | Set_Etype (Result, Btyp); | |
7737 | Set_Analyzed (Result); | |
7738 | return Result; | |
7739 | end Build_Range; | |
5b5df4a9 | 7740 | |
eb66e842 | 7741 | --------------- |
7742 | -- Build_Val -- | |
7743 | --------------- | |
5b5df4a9 | 7744 | |
eb66e842 | 7745 | function Build_Val (V : Uint) return Node_Id is |
7746 | Result : Node_Id; | |
5b5df4a9 | 7747 | |
eb66e842 | 7748 | begin |
7749 | if Is_Enumeration_Type (Typ) then | |
7750 | Result := Get_Enum_Lit_From_Pos (Typ, V, Loc); | |
7751 | else | |
7752 | Result := Make_Integer_Literal (Loc, V); | |
7753 | end if; | |
5b5df4a9 | 7754 | |
eb66e842 | 7755 | Set_Etype (Result, Btyp); |
7756 | Set_Is_Static_Expression (Result); | |
7757 | Set_Analyzed (Result); | |
7758 | return Result; | |
7759 | end Build_Val; | |
87f3d5d3 | 7760 | |
eb66e842 | 7761 | --------------- |
7762 | -- Get_RList -- | |
7763 | --------------- | |
87f3d5d3 | 7764 | |
eb66e842 | 7765 | function Get_RList (Exp : Node_Id) return RList is |
7766 | Op : Node_Kind; | |
7767 | Val : Uint; | |
87f3d5d3 | 7768 | |
eb66e842 | 7769 | begin |
7770 | -- Static expression can only be true or false | |
87f3d5d3 | 7771 | |
eb66e842 | 7772 | if Is_OK_Static_Expression (Exp) then |
7773 | if Expr_Value (Exp) = 0 then | |
7774 | return False_Range; | |
7775 | else | |
7776 | return True_Range; | |
9ea61fdd | 7777 | end if; |
eb66e842 | 7778 | end if; |
87f3d5d3 | 7779 | |
eb66e842 | 7780 | -- Otherwise test node type |
192b8dab | 7781 | |
eb66e842 | 7782 | Op := Nkind (Exp); |
192b8dab | 7783 | |
eb66e842 | 7784 | case Op is |
5d3fb947 | 7785 | |
eb66e842 | 7786 | -- And |
5d3fb947 | 7787 | |
99378362 | 7788 | when N_And_Then |
7789 | | N_Op_And | |
7790 | => | |
eb66e842 | 7791 | return Get_RList (Left_Opnd (Exp)) |
7792 | and | |
7793 | Get_RList (Right_Opnd (Exp)); | |
5b5df4a9 | 7794 | |
eb66e842 | 7795 | -- Or |
9dc88aea | 7796 | |
99378362 | 7797 | when N_Op_Or |
7798 | | N_Or_Else | |
7799 | => | |
eb66e842 | 7800 | return Get_RList (Left_Opnd (Exp)) |
7801 | or | |
7802 | Get_RList (Right_Opnd (Exp)); | |
7c443ae8 | 7803 | |
eb66e842 | 7804 | -- Not |
9dc88aea | 7805 | |
eb66e842 | 7806 | when N_Op_Not => |
7807 | return not Get_RList (Right_Opnd (Exp)); | |
9dc88aea | 7808 | |
eb66e842 | 7809 | -- Comparisons of type with static value |
84c8f0b8 | 7810 | |
eb66e842 | 7811 | when N_Op_Compare => |
490beba6 | 7812 | |
eb66e842 | 7813 | -- Type is left operand |
9dc88aea | 7814 | |
eb66e842 | 7815 | if Is_Type_Ref (Left_Opnd (Exp)) |
7816 | and then Is_OK_Static_Expression (Right_Opnd (Exp)) | |
7817 | then | |
7818 | Val := Expr_Value (Right_Opnd (Exp)); | |
84c8f0b8 | 7819 | |
eb66e842 | 7820 | -- Typ is right operand |
84c8f0b8 | 7821 | |
eb66e842 | 7822 | elsif Is_Type_Ref (Right_Opnd (Exp)) |
7823 | and then Is_OK_Static_Expression (Left_Opnd (Exp)) | |
7824 | then | |
7825 | Val := Expr_Value (Left_Opnd (Exp)); | |
84c8f0b8 | 7826 | |
eb66e842 | 7827 | -- Invert sense of comparison |
84c8f0b8 | 7828 | |
eb66e842 | 7829 | case Op is |
7830 | when N_Op_Gt => Op := N_Op_Lt; | |
7831 | when N_Op_Lt => Op := N_Op_Gt; | |
7832 | when N_Op_Ge => Op := N_Op_Le; | |
7833 | when N_Op_Le => Op := N_Op_Ge; | |
7834 | when others => null; | |
7835 | end case; | |
84c8f0b8 | 7836 | |
eb66e842 | 7837 | -- Other cases are non-static |
34d045d3 | 7838 | |
eb66e842 | 7839 | else |
7840 | raise Non_Static; | |
7841 | end if; | |
9dc88aea | 7842 | |
eb66e842 | 7843 | -- Construct range according to comparison operation |
9dc88aea | 7844 | |
eb66e842 | 7845 | case Op is |
7846 | when N_Op_Eq => | |
7847 | return RList'(1 => REnt'(Val, Val)); | |
9dc88aea | 7848 | |
eb66e842 | 7849 | when N_Op_Ge => |
7850 | return RList'(1 => REnt'(Val, BHi)); | |
84c8f0b8 | 7851 | |
eb66e842 | 7852 | when N_Op_Gt => |
7853 | return RList'(1 => REnt'(Val + 1, BHi)); | |
84c8f0b8 | 7854 | |
eb66e842 | 7855 | when N_Op_Le => |
7856 | return RList'(1 => REnt'(BLo, Val)); | |
fb7f2fc4 | 7857 | |
eb66e842 | 7858 | when N_Op_Lt => |
7859 | return RList'(1 => REnt'(BLo, Val - 1)); | |
9dc88aea | 7860 | |
eb66e842 | 7861 | when N_Op_Ne => |
7862 | return RList'(REnt'(BLo, Val - 1), REnt'(Val + 1, BHi)); | |
9dc88aea | 7863 | |
eb66e842 | 7864 | when others => |
7865 | raise Program_Error; | |
7866 | end case; | |
9dc88aea | 7867 | |
eb66e842 | 7868 | -- Membership (IN) |
9dc88aea | 7869 | |
eb66e842 | 7870 | when N_In => |
7871 | if not Is_Type_Ref (Left_Opnd (Exp)) then | |
7872 | raise Non_Static; | |
7873 | end if; | |
9dc88aea | 7874 | |
eb66e842 | 7875 | if Present (Right_Opnd (Exp)) then |
7876 | return Membership_Entry (Right_Opnd (Exp)); | |
7877 | else | |
7878 | return Membership_Entries (First (Alternatives (Exp))); | |
7879 | end if; | |
9dc88aea | 7880 | |
eb66e842 | 7881 | -- Negative membership (NOT IN) |
9dc88aea | 7882 | |
eb66e842 | 7883 | when N_Not_In => |
7884 | if not Is_Type_Ref (Left_Opnd (Exp)) then | |
7885 | raise Non_Static; | |
7886 | end if; | |
9dc88aea | 7887 | |
eb66e842 | 7888 | if Present (Right_Opnd (Exp)) then |
7889 | return not Membership_Entry (Right_Opnd (Exp)); | |
7890 | else | |
7891 | return not Membership_Entries (First (Alternatives (Exp))); | |
7892 | end if; | |
9dc88aea | 7893 | |
eb66e842 | 7894 | -- Function call, may be call to static predicate |
9dc88aea | 7895 | |
eb66e842 | 7896 | when N_Function_Call => |
7897 | if Is_Entity_Name (Name (Exp)) then | |
7898 | declare | |
7899 | Ent : constant Entity_Id := Entity (Name (Exp)); | |
7900 | begin | |
7901 | if Is_Predicate_Function (Ent) | |
7902 | or else | |
7903 | Is_Predicate_Function_M (Ent) | |
7904 | then | |
7905 | return Stat_Pred (Etype (First_Formal (Ent))); | |
7906 | end if; | |
7907 | end; | |
7908 | end if; | |
9dc88aea | 7909 | |
eb66e842 | 7910 | -- Other function call cases are non-static |
9dc88aea | 7911 | |
eb66e842 | 7912 | raise Non_Static; |
490beba6 | 7913 | |
eb66e842 | 7914 | -- Qualified expression, dig out the expression |
c92e878b | 7915 | |
eb66e842 | 7916 | when N_Qualified_Expression => |
7917 | return Get_RList (Expression (Exp)); | |
4c1fd062 | 7918 | |
eb66e842 | 7919 | when N_Case_Expression => |
7920 | declare | |
7921 | Alt : Node_Id; | |
7922 | Choices : List_Id; | |
7923 | Dep : Node_Id; | |
4c1fd062 | 7924 | |
eb66e842 | 7925 | begin |
7926 | if not Is_Entity_Name (Expression (Expr)) | |
7927 | or else Etype (Expression (Expr)) /= Typ | |
7928 | then | |
7929 | Error_Msg_N | |
7930 | ("expression must denaote subtype", Expression (Expr)); | |
7931 | return False_Range; | |
7932 | end if; | |
9dc88aea | 7933 | |
eb66e842 | 7934 | -- Collect discrete choices in all True alternatives |
9dc88aea | 7935 | |
eb66e842 | 7936 | Choices := New_List; |
7937 | Alt := First (Alternatives (Exp)); | |
7938 | while Present (Alt) loop | |
7939 | Dep := Expression (Alt); | |
34d045d3 | 7940 | |
cda40848 | 7941 | if not Is_OK_Static_Expression (Dep) then |
eb66e842 | 7942 | raise Non_Static; |
ebbab42d | 7943 | |
eb66e842 | 7944 | elsif Is_True (Expr_Value (Dep)) then |
7945 | Append_List_To (Choices, | |
7946 | New_Copy_List (Discrete_Choices (Alt))); | |
7947 | end if; | |
fb7f2fc4 | 7948 | |
eb66e842 | 7949 | Next (Alt); |
7950 | end loop; | |
9dc88aea | 7951 | |
eb66e842 | 7952 | return Membership_Entries (First (Choices)); |
7953 | end; | |
9dc88aea | 7954 | |
eb66e842 | 7955 | -- Expression with actions: if no actions, dig out expression |
9dc88aea | 7956 | |
eb66e842 | 7957 | when N_Expression_With_Actions => |
7958 | if Is_Empty_List (Actions (Exp)) then | |
7959 | return Get_RList (Expression (Exp)); | |
7960 | else | |
7961 | raise Non_Static; | |
7962 | end if; | |
9dc88aea | 7963 | |
eb66e842 | 7964 | -- Xor operator |
490beba6 | 7965 | |
eb66e842 | 7966 | when N_Op_Xor => |
7967 | return (Get_RList (Left_Opnd (Exp)) | |
7968 | and not Get_RList (Right_Opnd (Exp))) | |
7969 | or (Get_RList (Right_Opnd (Exp)) | |
7970 | and not Get_RList (Left_Opnd (Exp))); | |
9dc88aea | 7971 | |
eb66e842 | 7972 | -- Any other node type is non-static |
fb7f2fc4 | 7973 | |
eb66e842 | 7974 | when others => |
7975 | raise Non_Static; | |
7976 | end case; | |
7977 | end Get_RList; | |
fb7f2fc4 | 7978 | |
eb66e842 | 7979 | ------------ |
7980 | -- Hi_Val -- | |
7981 | ------------ | |
fb7f2fc4 | 7982 | |
eb66e842 | 7983 | function Hi_Val (N : Node_Id) return Uint is |
7984 | begin | |
cda40848 | 7985 | if Is_OK_Static_Expression (N) then |
eb66e842 | 7986 | return Expr_Value (N); |
7987 | else | |
7988 | pragma Assert (Nkind (N) = N_Range); | |
7989 | return Expr_Value (High_Bound (N)); | |
7990 | end if; | |
7991 | end Hi_Val; | |
fb7f2fc4 | 7992 | |
eb66e842 | 7993 | -------------- |
7994 | -- Is_False -- | |
7995 | -------------- | |
fb7f2fc4 | 7996 | |
eb66e842 | 7997 | function Is_False (R : RList) return Boolean is |
7998 | begin | |
7999 | return R'Length = 0; | |
8000 | end Is_False; | |
9dc88aea | 8001 | |
eb66e842 | 8002 | ------------- |
8003 | -- Is_True -- | |
8004 | ------------- | |
9dc88aea | 8005 | |
eb66e842 | 8006 | function Is_True (R : RList) return Boolean is |
8007 | begin | |
8008 | return R'Length = 1 | |
8009 | and then R (R'First).Lo = BLo | |
8010 | and then R (R'First).Hi = BHi; | |
8011 | end Is_True; | |
9dc88aea | 8012 | |
eb66e842 | 8013 | ----------------- |
8014 | -- Is_Type_Ref -- | |
8015 | ----------------- | |
9dc88aea | 8016 | |
eb66e842 | 8017 | function Is_Type_Ref (N : Node_Id) return Boolean is |
8018 | begin | |
7de4cba3 | 8019 | return Nkind (N) = N_Identifier |
8020 | and then Chars (N) = Nam | |
8021 | and then Paren_Count (N) = 0; | |
eb66e842 | 8022 | end Is_Type_Ref; |
9dc88aea | 8023 | |
eb66e842 | 8024 | ------------ |
8025 | -- Lo_Val -- | |
8026 | ------------ | |
9dc88aea | 8027 | |
eb66e842 | 8028 | function Lo_Val (N : Node_Id) return Uint is |
84c8f0b8 | 8029 | begin |
cda40848 | 8030 | if Is_OK_Static_Expression (N) then |
eb66e842 | 8031 | return Expr_Value (N); |
84c8f0b8 | 8032 | else |
eb66e842 | 8033 | pragma Assert (Nkind (N) = N_Range); |
8034 | return Expr_Value (Low_Bound (N)); | |
84c8f0b8 | 8035 | end if; |
eb66e842 | 8036 | end Lo_Val; |
d97beb2f | 8037 | |
eb66e842 | 8038 | ------------------------ |
8039 | -- Membership_Entries -- | |
8040 | ------------------------ | |
d97beb2f | 8041 | |
eb66e842 | 8042 | function Membership_Entries (N : Node_Id) return RList is |
84c8f0b8 | 8043 | begin |
eb66e842 | 8044 | if No (Next (N)) then |
8045 | return Membership_Entry (N); | |
84c8f0b8 | 8046 | else |
eb66e842 | 8047 | return Membership_Entry (N) or Membership_Entries (Next (N)); |
84c8f0b8 | 8048 | end if; |
eb66e842 | 8049 | end Membership_Entries; |
84c8f0b8 | 8050 | |
eb66e842 | 8051 | ---------------------- |
8052 | -- Membership_Entry -- | |
8053 | ---------------------- | |
84c8f0b8 | 8054 | |
eb66e842 | 8055 | function Membership_Entry (N : Node_Id) return RList is |
8056 | Val : Uint; | |
8057 | SLo : Uint; | |
8058 | SHi : Uint; | |
d97beb2f | 8059 | |
eb66e842 | 8060 | begin |
8061 | -- Range case | |
d97beb2f | 8062 | |
eb66e842 | 8063 | if Nkind (N) = N_Range then |
cda40848 | 8064 | if not Is_OK_Static_Expression (Low_Bound (N)) |
eb66e842 | 8065 | or else |
cda40848 | 8066 | not Is_OK_Static_Expression (High_Bound (N)) |
eb66e842 | 8067 | then |
8068 | raise Non_Static; | |
8069 | else | |
8070 | SLo := Expr_Value (Low_Bound (N)); | |
8071 | SHi := Expr_Value (High_Bound (N)); | |
8072 | return RList'(1 => REnt'(SLo, SHi)); | |
8073 | end if; | |
84c8f0b8 | 8074 | |
eb66e842 | 8075 | -- Static expression case |
84c8f0b8 | 8076 | |
cda40848 | 8077 | elsif Is_OK_Static_Expression (N) then |
eb66e842 | 8078 | Val := Expr_Value (N); |
8079 | return RList'(1 => REnt'(Val, Val)); | |
d97beb2f | 8080 | |
eb66e842 | 8081 | -- Identifier (other than static expression) case |
d97beb2f | 8082 | |
eb66e842 | 8083 | else pragma Assert (Nkind (N) = N_Identifier); |
d97beb2f | 8084 | |
eb66e842 | 8085 | -- Type case |
d97beb2f | 8086 | |
eb66e842 | 8087 | if Is_Type (Entity (N)) then |
d97beb2f | 8088 | |
eb66e842 | 8089 | -- If type has predicates, process them |
d97beb2f | 8090 | |
eb66e842 | 8091 | if Has_Predicates (Entity (N)) then |
8092 | return Stat_Pred (Entity (N)); | |
d97beb2f | 8093 | |
eb66e842 | 8094 | -- For static subtype without predicates, get range |
9dc88aea | 8095 | |
cda40848 | 8096 | elsif Is_OK_Static_Subtype (Entity (N)) then |
eb66e842 | 8097 | SLo := Expr_Value (Type_Low_Bound (Entity (N))); |
8098 | SHi := Expr_Value (Type_High_Bound (Entity (N))); | |
8099 | return RList'(1 => REnt'(SLo, SHi)); | |
9f269bd8 | 8100 | |
eb66e842 | 8101 | -- Any other type makes us non-static |
9f269bd8 | 8102 | |
eb66e842 | 8103 | else |
8104 | raise Non_Static; | |
8105 | end if; | |
84c8f0b8 | 8106 | |
eb66e842 | 8107 | -- Any other kind of identifier in predicate (e.g. a non-static |
8108 | -- expression value) means this is not a static predicate. | |
84c8f0b8 | 8109 | |
eb66e842 | 8110 | else |
8111 | raise Non_Static; | |
8112 | end if; | |
8113 | end if; | |
8114 | end Membership_Entry; | |
84c8f0b8 | 8115 | |
eb66e842 | 8116 | --------------- |
8117 | -- Stat_Pred -- | |
8118 | --------------- | |
84c8f0b8 | 8119 | |
eb66e842 | 8120 | function Stat_Pred (Typ : Entity_Id) return RList is |
8121 | begin | |
8122 | -- Not static if type does not have static predicates | |
84c8f0b8 | 8123 | |
5c6a5792 | 8124 | if not Has_Static_Predicate (Typ) then |
eb66e842 | 8125 | raise Non_Static; |
8126 | end if; | |
84c8f0b8 | 8127 | |
eb66e842 | 8128 | -- Otherwise we convert the predicate list to a range list |
84c8f0b8 | 8129 | |
eb66e842 | 8130 | declare |
5c6a5792 | 8131 | Spred : constant List_Id := Static_Discrete_Predicate (Typ); |
8132 | Result : RList (1 .. List_Length (Spred)); | |
eb66e842 | 8133 | P : Node_Id; |
84c8f0b8 | 8134 | |
eb66e842 | 8135 | begin |
5c6a5792 | 8136 | P := First (Static_Discrete_Predicate (Typ)); |
eb66e842 | 8137 | for J in Result'Range loop |
8138 | Result (J) := REnt'(Lo_Val (P), Hi_Val (P)); | |
8139 | Next (P); | |
8140 | end loop; | |
84c8f0b8 | 8141 | |
eb66e842 | 8142 | return Result; |
8143 | end; | |
8144 | end Stat_Pred; | |
84c8f0b8 | 8145 | |
eb66e842 | 8146 | -- Start of processing for Build_Discrete_Static_Predicate |
84c8f0b8 | 8147 | |
eb66e842 | 8148 | begin |
fdec445e | 8149 | -- Establish bounds for the predicate |
afc229da | 8150 | |
8151 | if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then | |
8152 | TLo := Expr_Value (Type_Low_Bound (Typ)); | |
8153 | else | |
8154 | TLo := BLo; | |
8155 | end if; | |
8156 | ||
8157 | if Compile_Time_Known_Value (Type_High_Bound (Typ)) then | |
8158 | THi := Expr_Value (Type_High_Bound (Typ)); | |
8159 | else | |
8160 | THi := BHi; | |
8161 | end if; | |
8162 | ||
eb66e842 | 8163 | -- Analyze the expression to see if it is a static predicate |
84c8f0b8 | 8164 | |
eb66e842 | 8165 | declare |
8166 | Ranges : constant RList := Get_RList (Expr); | |
8167 | -- Range list from expression if it is static | |
84c8f0b8 | 8168 | |
eb66e842 | 8169 | Plist : List_Id; |
84c8f0b8 | 8170 | |
eb66e842 | 8171 | begin |
8172 | -- Convert range list into a form for the static predicate. In the | |
8173 | -- Ranges array, we just have raw ranges, these must be converted | |
8174 | -- to properly typed and analyzed static expressions or range nodes. | |
84c8f0b8 | 8175 | |
eb66e842 | 8176 | -- Note: here we limit ranges to the ranges of the subtype, so that |
8177 | -- a predicate is always false for values outside the subtype. That | |
8178 | -- seems fine, such values are invalid anyway, and considering them | |
8179 | -- to fail the predicate seems allowed and friendly, and furthermore | |
8180 | -- simplifies processing for case statements and loops. | |
84c8f0b8 | 8181 | |
eb66e842 | 8182 | Plist := New_List; |
8183 | ||
8184 | for J in Ranges'Range loop | |
84c8f0b8 | 8185 | declare |
eb66e842 | 8186 | Lo : Uint := Ranges (J).Lo; |
8187 | Hi : Uint := Ranges (J).Hi; | |
84c8f0b8 | 8188 | |
eb66e842 | 8189 | begin |
8190 | -- Ignore completely out of range entry | |
84c8f0b8 | 8191 | |
eb66e842 | 8192 | if Hi < TLo or else Lo > THi then |
8193 | null; | |
84c8f0b8 | 8194 | |
eb66e842 | 8195 | -- Otherwise process entry |
84c8f0b8 | 8196 | |
eb66e842 | 8197 | else |
8198 | -- Adjust out of range value to subtype range | |
490beba6 | 8199 | |
eb66e842 | 8200 | if Lo < TLo then |
8201 | Lo := TLo; | |
8202 | end if; | |
490beba6 | 8203 | |
eb66e842 | 8204 | if Hi > THi then |
8205 | Hi := THi; | |
8206 | end if; | |
84c8f0b8 | 8207 | |
eb66e842 | 8208 | -- Convert range into required form |
84c8f0b8 | 8209 | |
eb66e842 | 8210 | Append_To (Plist, Build_Range (Lo, Hi)); |
84c8f0b8 | 8211 | end if; |
eb66e842 | 8212 | end; |
8213 | end loop; | |
84c8f0b8 | 8214 | |
eb66e842 | 8215 | -- Processing was successful and all entries were static, so now we |
8216 | -- can store the result as the predicate list. | |
84c8f0b8 | 8217 | |
5c6a5792 | 8218 | Set_Static_Discrete_Predicate (Typ, Plist); |
84c8f0b8 | 8219 | |
f3f142ac | 8220 | -- Within a generic the predicate functions themselves need not |
8221 | -- be constructed. | |
8222 | ||
8223 | if Inside_A_Generic then | |
8224 | return; | |
8225 | end if; | |
8226 | ||
eb66e842 | 8227 | -- The processing for static predicates put the expression into |
8228 | -- canonical form as a series of ranges. It also eliminated | |
8229 | -- duplicates and collapsed and combined ranges. We might as well | |
8230 | -- replace the alternatives list of the right operand of the | |
8231 | -- membership test with the static predicate list, which will | |
8232 | -- usually be more efficient. | |
84c8f0b8 | 8233 | |
eb66e842 | 8234 | declare |
8235 | New_Alts : constant List_Id := New_List; | |
8236 | Old_Node : Node_Id; | |
8237 | New_Node : Node_Id; | |
84c8f0b8 | 8238 | |
eb66e842 | 8239 | begin |
8240 | Old_Node := First (Plist); | |
8241 | while Present (Old_Node) loop | |
8242 | New_Node := New_Copy (Old_Node); | |
84c8f0b8 | 8243 | |
eb66e842 | 8244 | if Nkind (New_Node) = N_Range then |
8245 | Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node))); | |
8246 | Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node))); | |
8247 | end if; | |
84c8f0b8 | 8248 | |
eb66e842 | 8249 | Append_To (New_Alts, New_Node); |
8250 | Next (Old_Node); | |
8251 | end loop; | |
84c8f0b8 | 8252 | |
eb66e842 | 8253 | -- If empty list, replace by False |
84c8f0b8 | 8254 | |
eb66e842 | 8255 | if Is_Empty_List (New_Alts) then |
8256 | Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc)); | |
84c8f0b8 | 8257 | |
eb66e842 | 8258 | -- Else replace by set membership test |
84c8f0b8 | 8259 | |
eb66e842 | 8260 | else |
8261 | Rewrite (Expr, | |
8262 | Make_In (Loc, | |
8263 | Left_Opnd => Make_Identifier (Loc, Nam), | |
8264 | Right_Opnd => Empty, | |
8265 | Alternatives => New_Alts)); | |
490beba6 | 8266 | |
eb66e842 | 8267 | -- Resolve new expression in function context |
490beba6 | 8268 | |
eb66e842 | 8269 | Install_Formals (Predicate_Function (Typ)); |
8270 | Push_Scope (Predicate_Function (Typ)); | |
8271 | Analyze_And_Resolve (Expr, Standard_Boolean); | |
8272 | Pop_Scope; | |
8273 | end if; | |
8274 | end; | |
8275 | end; | |
9ab32fe9 | 8276 | |
eb66e842 | 8277 | -- If non-static, return doing nothing |
9ab32fe9 | 8278 | |
eb66e842 | 8279 | exception |
8280 | when Non_Static => | |
8281 | return; | |
8282 | end Build_Discrete_Static_Predicate; | |
64cc9e5d | 8283 | |
ee2b7923 | 8284 | -------------------------------- |
8285 | -- Build_Export_Import_Pragma -- | |
8286 | -------------------------------- | |
8287 | ||
8288 | function Build_Export_Import_Pragma | |
8289 | (Asp : Node_Id; | |
8290 | Id : Entity_Id) return Node_Id | |
8291 | is | |
8292 | Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp); | |
8293 | Expr : constant Node_Id := Expression (Asp); | |
8294 | Loc : constant Source_Ptr := Sloc (Asp); | |
8295 | ||
8296 | Args : List_Id; | |
8297 | Conv : Node_Id; | |
8298 | Conv_Arg : Node_Id; | |
8299 | Dummy_1 : Node_Id; | |
8300 | Dummy_2 : Node_Id; | |
8301 | EN : Node_Id; | |
8302 | LN : Node_Id; | |
8303 | Prag : Node_Id; | |
8304 | ||
8305 | Create_Pragma : Boolean := False; | |
8306 | -- This flag is set when the aspect form is such that it warrants the | |
8307 | -- creation of a corresponding pragma. | |
8308 | ||
8309 | begin | |
8310 | if Present (Expr) then | |
8311 | if Error_Posted (Expr) then | |
8312 | null; | |
8313 | ||
8314 | elsif Is_True (Expr_Value (Expr)) then | |
8315 | Create_Pragma := True; | |
8316 | end if; | |
8317 | ||
8318 | -- Otherwise the aspect defaults to True | |
8319 | ||
8320 | else | |
8321 | Create_Pragma := True; | |
8322 | end if; | |
8323 | ||
8324 | -- Nothing to do when the expression is False or is erroneous | |
8325 | ||
8326 | if not Create_Pragma then | |
8327 | return Empty; | |
8328 | end if; | |
8329 | ||
8330 | -- Obtain all interfacing aspects that apply to the related entity | |
8331 | ||
8332 | Get_Interfacing_Aspects | |
8333 | (Iface_Asp => Asp, | |
8334 | Conv_Asp => Conv, | |
8335 | EN_Asp => EN, | |
8336 | Expo_Asp => Dummy_1, | |
8337 | Imp_Asp => Dummy_2, | |
8338 | LN_Asp => LN); | |
8339 | ||
8340 | Args := New_List; | |
8341 | ||
8342 | -- Handle the convention argument | |
8343 | ||
8344 | if Present (Conv) then | |
8345 | Conv_Arg := New_Copy_Tree (Expression (Conv)); | |
8346 | ||
8347 | -- Assume convention "Ada' when aspect Convention is missing | |
8348 | ||
8349 | else | |
8350 | Conv_Arg := Make_Identifier (Loc, Name_Ada); | |
8351 | end if; | |
8352 | ||
8353 | Append_To (Args, | |
8354 | Make_Pragma_Argument_Association (Loc, | |
8355 | Chars => Name_Convention, | |
8356 | Expression => Conv_Arg)); | |
8357 | ||
8358 | -- Handle the entity argument | |
8359 | ||
8360 | Append_To (Args, | |
8361 | Make_Pragma_Argument_Association (Loc, | |
8362 | Chars => Name_Entity, | |
8363 | Expression => New_Occurrence_Of (Id, Loc))); | |
8364 | ||
8365 | -- Handle the External_Name argument | |
8366 | ||
8367 | if Present (EN) then | |
8368 | Append_To (Args, | |
8369 | Make_Pragma_Argument_Association (Loc, | |
8370 | Chars => Name_External_Name, | |
8371 | Expression => New_Copy_Tree (Expression (EN)))); | |
8372 | end if; | |
8373 | ||
8374 | -- Handle the Link_Name argument | |
8375 | ||
8376 | if Present (LN) then | |
8377 | Append_To (Args, | |
8378 | Make_Pragma_Argument_Association (Loc, | |
8379 | Chars => Name_Link_Name, | |
8380 | Expression => New_Copy_Tree (Expression (LN)))); | |
8381 | end if; | |
8382 | ||
8383 | -- Generate: | |
8384 | -- pragma Export/Import | |
8385 | -- (Convention => <Conv>/Ada, | |
8386 | -- Entity => <Id>, | |
8387 | -- [External_Name => <EN>,] | |
8388 | -- [Link_Name => <LN>]); | |
8389 | ||
8390 | Prag := | |
8391 | Make_Pragma (Loc, | |
8392 | Pragma_Identifier => | |
8393 | Make_Identifier (Loc, Chars (Identifier (Asp))), | |
8394 | Pragma_Argument_Associations => Args); | |
8395 | ||
8396 | -- Decorate the relevant aspect and the pragma | |
8397 | ||
8398 | Set_Aspect_Rep_Item (Asp, Prag); | |
8399 | ||
8400 | Set_Corresponding_Aspect (Prag, Asp); | |
8401 | Set_From_Aspect_Specification (Prag); | |
8402 | Set_Parent (Prag, Asp); | |
8403 | ||
8404 | if Asp_Id = Aspect_Import and then Is_Subprogram (Id) then | |
8405 | Set_Import_Pragma (Id, Prag); | |
8406 | end if; | |
8407 | ||
8408 | return Prag; | |
8409 | end Build_Export_Import_Pragma; | |
8410 | ||
eb66e842 | 8411 | ------------------------------- |
8412 | -- Build_Predicate_Functions -- | |
8413 | ------------------------------- | |
d9f6a4ee | 8414 | |
786b03d1 | 8415 | -- The functions that are constructed here have the form: |
d9f6a4ee | 8416 | |
eb66e842 | 8417 | -- function typPredicate (Ixxx : typ) return Boolean is |
8418 | -- begin | |
8419 | -- return | |
75491446 | 8420 | -- typ1Predicate (typ1 (Ixxx)) |
eb66e842 | 8421 | -- and then typ2Predicate (typ2 (Ixxx)) |
786b03d1 | 8422 | -- and then ... |
8423 | -- and then exp1 and then exp2 and then ...; | |
eb66e842 | 8424 | -- end typPredicate; |
d9f6a4ee | 8425 | |
eb66e842 | 8426 | -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that |
8427 | -- this is the point at which these expressions get analyzed, providing the | |
8428 | -- required delay, and typ1, typ2, are entities from which predicates are | |
8429 | -- inherited. Note that we do NOT generate Check pragmas, that's because we | |
8430 | -- use this function even if checks are off, e.g. for membership tests. | |
d9f6a4ee | 8431 | |
75491446 | 8432 | -- Note that the inherited predicates are evaluated first, as required by |
8433 | -- AI12-0071-1. | |
8434 | ||
8435 | -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on | |
8436 | -- the form of this return expression. | |
8437 | ||
eb66e842 | 8438 | -- If the expression has at least one Raise_Expression, then we also build |
8439 | -- the typPredicateM version of the function, in which any occurrence of a | |
8440 | -- Raise_Expression is converted to "return False". | |
d9f6a4ee | 8441 | |
1ecdfe4b | 8442 | -- WARNING: This routine manages Ghost regions. Return statements must be |
8443 | -- replaced by gotos which jump to the end of the routine and restore the | |
8444 | -- Ghost mode. | |
8445 | ||
eb66e842 | 8446 | procedure Build_Predicate_Functions (Typ : Entity_Id; N : Node_Id) is |
8447 | Loc : constant Source_Ptr := Sloc (Typ); | |
d9f6a4ee | 8448 | |
eb66e842 | 8449 | Expr : Node_Id; |
8450 | -- This is the expression for the result of the function. It is | |
8451 | -- is build by connecting the component predicates with AND THEN. | |
d9f6a4ee | 8452 | |
d39570ea | 8453 | Expr_M : Node_Id := Empty; -- init to avoid warning |
eb66e842 | 8454 | -- This is the corresponding return expression for the Predicate_M |
8455 | -- function. It differs in that raise expressions are marked for | |
8456 | -- special expansion (see Process_REs). | |
d9f6a4ee | 8457 | |
9c20237a | 8458 | Object_Name : Name_Id; |
eb66e842 | 8459 | -- Name for argument of Predicate procedure. Note that we use the same |
499918a7 | 8460 | -- name for both predicate functions. That way the reference within the |
eb66e842 | 8461 | -- predicate expression is the same in both functions. |
d9f6a4ee | 8462 | |
9c20237a | 8463 | Object_Entity : Entity_Id; |
eb66e842 | 8464 | -- Entity for argument of Predicate procedure |
d9f6a4ee | 8465 | |
9c20237a | 8466 | Object_Entity_M : Entity_Id; |
8467 | -- Entity for argument of separate Predicate procedure when exceptions | |
8468 | -- are present in expression. | |
8469 | ||
02e5d0d0 | 8470 | FDecl : Node_Id; |
8471 | -- The function declaration | |
9c20237a | 8472 | |
02e5d0d0 | 8473 | SId : Entity_Id; |
8474 | -- Its entity | |
d9f6a4ee | 8475 | |
eb66e842 | 8476 | Raise_Expression_Present : Boolean := False; |
8477 | -- Set True if Expr has at least one Raise_Expression | |
d9f6a4ee | 8478 | |
75491446 | 8479 | procedure Add_Condition (Cond : Node_Id); |
8480 | -- Append Cond to Expr using "and then" (or just copy Cond to Expr if | |
8481 | -- Expr is empty). | |
d9f6a4ee | 8482 | |
eb66e842 | 8483 | procedure Add_Predicates; |
8484 | -- Appends expressions for any Predicate pragmas in the rep item chain | |
8485 | -- Typ to Expr. Note that we look only at items for this exact entity. | |
8486 | -- Inheritance of predicates for the parent type is done by calling the | |
8487 | -- Predicate_Function of the parent type, using Add_Call above. | |
d9f6a4ee | 8488 | |
75491446 | 8489 | procedure Add_Call (T : Entity_Id); |
8490 | -- Includes a call to the predicate function for type T in Expr if T | |
8491 | -- has predicates and Predicate_Function (T) is non-empty. | |
8492 | ||
eb66e842 | 8493 | function Process_RE (N : Node_Id) return Traverse_Result; |
8494 | -- Used in Process REs, tests if node N is a raise expression, and if | |
8495 | -- so, marks it to be converted to return False. | |
d9f6a4ee | 8496 | |
eb66e842 | 8497 | procedure Process_REs is new Traverse_Proc (Process_RE); |
8498 | -- Marks any raise expressions in Expr_M to return False | |
d9f6a4ee | 8499 | |
f9e26ff7 | 8500 | function Test_RE (N : Node_Id) return Traverse_Result; |
8501 | -- Used in Test_REs, tests one node for being a raise expression, and if | |
8502 | -- so sets Raise_Expression_Present True. | |
8503 | ||
8504 | procedure Test_REs is new Traverse_Proc (Test_RE); | |
8505 | -- Tests to see if Expr contains any raise expressions | |
8506 | ||
eb66e842 | 8507 | -------------- |
8508 | -- Add_Call -- | |
8509 | -------------- | |
d9f6a4ee | 8510 | |
eb66e842 | 8511 | procedure Add_Call (T : Entity_Id) is |
8512 | Exp : Node_Id; | |
d9f6a4ee | 8513 | |
eb66e842 | 8514 | begin |
8515 | if Present (T) and then Present (Predicate_Function (T)) then | |
8516 | Set_Has_Predicates (Typ); | |
d9f6a4ee | 8517 | |
74d7e7f5 | 8518 | -- Build the call to the predicate function of T. The type may be |
8519 | -- derived, so use an unchecked conversion for the actual. | |
d9f6a4ee | 8520 | |
eb66e842 | 8521 | Exp := |
8522 | Make_Predicate_Call | |
74d7e7f5 | 8523 | (Typ => T, |
8524 | Expr => | |
8525 | Unchecked_Convert_To (T, | |
8526 | Make_Identifier (Loc, Object_Name))); | |
d9f6a4ee | 8527 | |
75491446 | 8528 | -- "and"-in the call to evolving expression |
d9f6a4ee | 8529 | |
75491446 | 8530 | Add_Condition (Exp); |
d9f6a4ee | 8531 | |
eb66e842 | 8532 | -- Output info message on inheritance if required. Note we do not |
8533 | -- give this information for generic actual types, since it is | |
8534 | -- unwelcome noise in that case in instantiations. We also | |
8535 | -- generally suppress the message in instantiations, and also | |
8536 | -- if it involves internal names. | |
d9f6a4ee | 8537 | |
eb66e842 | 8538 | if Opt.List_Inherited_Aspects |
8539 | and then not Is_Generic_Actual_Type (Typ) | |
8540 | and then Instantiation_Depth (Sloc (Typ)) = 0 | |
8541 | and then not Is_Internal_Name (Chars (T)) | |
8542 | and then not Is_Internal_Name (Chars (Typ)) | |
8543 | then | |
8544 | Error_Msg_Sloc := Sloc (Predicate_Function (T)); | |
8545 | Error_Msg_Node_2 := T; | |
8546 | Error_Msg_N ("info: & inherits predicate from & #?L?", Typ); | |
8547 | end if; | |
8548 | end if; | |
8549 | end Add_Call; | |
d9f6a4ee | 8550 | |
75491446 | 8551 | ------------------- |
8552 | -- Add_Condition -- | |
8553 | ------------------- | |
8554 | ||
8555 | procedure Add_Condition (Cond : Node_Id) is | |
8556 | begin | |
8557 | -- This is the first predicate expression | |
8558 | ||
8559 | if No (Expr) then | |
8560 | Expr := Cond; | |
8561 | ||
8562 | -- Otherwise concatenate to the existing predicate expressions by | |
8563 | -- using "and then". | |
8564 | ||
8565 | else | |
8566 | Expr := | |
8567 | Make_And_Then (Loc, | |
8568 | Left_Opnd => Relocate_Node (Expr), | |
8569 | Right_Opnd => Cond); | |
8570 | end if; | |
8571 | end Add_Condition; | |
8572 | ||
eb66e842 | 8573 | -------------------- |
8574 | -- Add_Predicates -- | |
8575 | -------------------- | |
d9f6a4ee | 8576 | |
eb66e842 | 8577 | procedure Add_Predicates is |
f9e26ff7 | 8578 | procedure Add_Predicate (Prag : Node_Id); |
8579 | -- Concatenate the expression of predicate pragma Prag to Expr by | |
8580 | -- using a short circuit "and then" operator. | |
d9f6a4ee | 8581 | |
f9e26ff7 | 8582 | ------------------- |
8583 | -- Add_Predicate -- | |
8584 | ------------------- | |
d9f6a4ee | 8585 | |
f9e26ff7 | 8586 | procedure Add_Predicate (Prag : Node_Id) is |
8587 | procedure Replace_Type_Reference (N : Node_Id); | |
8588 | -- Replace a single occurrence N of the subtype name with a | |
8589 | -- reference to the formal of the predicate function. N can be an | |
8590 | -- identifier referencing the subtype, or a selected component, | |
8591 | -- representing an appropriately qualified occurrence of the | |
8592 | -- subtype name. | |
8593 | ||
8594 | procedure Replace_Type_References is | |
8595 | new Replace_Type_References_Generic (Replace_Type_Reference); | |
8596 | -- Traverse an expression changing every occurrence of an | |
8597 | -- identifier whose name matches the name of the subtype with a | |
8598 | -- reference to the formal parameter of the predicate function. | |
8599 | ||
8600 | ---------------------------- | |
8601 | -- Replace_Type_Reference -- | |
8602 | ---------------------------- | |
8603 | ||
8604 | procedure Replace_Type_Reference (N : Node_Id) is | |
8605 | begin | |
8606 | Rewrite (N, Make_Identifier (Sloc (N), Object_Name)); | |
8607 | -- Use the Sloc of the usage name, not the defining name | |
d9f6a4ee | 8608 | |
f9e26ff7 | 8609 | Set_Etype (N, Typ); |
8610 | Set_Entity (N, Object_Entity); | |
d97beb2f | 8611 | |
f9e26ff7 | 8612 | -- We want to treat the node as if it comes from source, so |
8613 | -- that ASIS will not ignore it. | |
d97beb2f | 8614 | |
f9e26ff7 | 8615 | Set_Comes_From_Source (N, True); |
8616 | end Replace_Type_Reference; | |
d97beb2f | 8617 | |
f9e26ff7 | 8618 | -- Local variables |
d97beb2f | 8619 | |
f9e26ff7 | 8620 | Asp : constant Node_Id := Corresponding_Aspect (Prag); |
8621 | Arg1 : Node_Id; | |
8622 | Arg2 : Node_Id; | |
d97beb2f | 8623 | |
f9e26ff7 | 8624 | -- Start of processing for Add_Predicate |
24c8d764 | 8625 | |
f9e26ff7 | 8626 | begin |
42fb9d35 | 8627 | -- Mark corresponding SCO as enabled |
8628 | ||
8629 | Set_SCO_Pragma_Enabled (Sloc (Prag)); | |
8630 | ||
f9e26ff7 | 8631 | -- Extract the arguments of the pragma. The expression itself |
8632 | -- is copied for use in the predicate function, to preserve the | |
8633 | -- original version for ASIS use. | |
d97beb2f | 8634 | |
f9e26ff7 | 8635 | Arg1 := First (Pragma_Argument_Associations (Prag)); |
8636 | Arg2 := Next (Arg1); | |
d97beb2f | 8637 | |
f9e26ff7 | 8638 | Arg1 := Get_Pragma_Arg (Arg1); |
8639 | Arg2 := New_Copy_Tree (Get_Pragma_Arg (Arg2)); | |
d97beb2f | 8640 | |
f9e26ff7 | 8641 | -- When the predicate pragma applies to the current type or its |
8642 | -- full view, replace all occurrences of the subtype name with | |
8643 | -- references to the formal parameter of the predicate function. | |
639c3741 | 8644 | |
f9e26ff7 | 8645 | if Entity (Arg1) = Typ |
8646 | or else Full_View (Entity (Arg1)) = Typ | |
8647 | then | |
8648 | Replace_Type_References (Arg2, Typ); | |
639c3741 | 8649 | |
f9e26ff7 | 8650 | -- If the predicate pragma comes from an aspect, replace the |
8651 | -- saved expression because we need the subtype references | |
8652 | -- replaced for the calls to Preanalyze_Spec_Expression in | |
8653 | -- Check_Aspect_At_xxx routines. | |
639c3741 | 8654 | |
f9e26ff7 | 8655 | if Present (Asp) then |
f9e26ff7 | 8656 | Set_Entity (Identifier (Asp), New_Copy_Tree (Arg2)); |
8657 | end if; | |
24c8d764 | 8658 | |
75491446 | 8659 | -- "and"-in the Arg2 condition to evolving expression |
639c3741 | 8660 | |
75491446 | 8661 | Add_Condition (Relocate_Node (Arg2)); |
f9e26ff7 | 8662 | end if; |
8663 | end Add_Predicate; | |
737e8460 | 8664 | |
f9e26ff7 | 8665 | -- Local variables |
737e8460 | 8666 | |
f9e26ff7 | 8667 | Ritem : Node_Id; |
d97beb2f | 8668 | |
f9e26ff7 | 8669 | -- Start of processing for Add_Predicates |
d97beb2f | 8670 | |
f9e26ff7 | 8671 | begin |
8672 | Ritem := First_Rep_Item (Typ); | |
74d7e7f5 | 8673 | |
8674 | -- If the type is private, check whether full view has inherited | |
8675 | -- predicates. | |
8676 | ||
8677 | if Is_Private_Type (Typ) and then No (Ritem) then | |
8678 | Ritem := First_Rep_Item (Full_View (Typ)); | |
8679 | end if; | |
8680 | ||
f9e26ff7 | 8681 | while Present (Ritem) loop |
8682 | if Nkind (Ritem) = N_Pragma | |
ddccc924 | 8683 | and then Pragma_Name (Ritem) = Name_Predicate |
f9e26ff7 | 8684 | then |
8685 | Add_Predicate (Ritem); | |
0ea02224 | 8686 | |
8687 | -- If the type is declared in an inner package it may be frozen | |
8688 | -- outside of the package, and the generated pragma has not been | |
8689 | -- analyzed yet, so capture the expression for the predicate | |
8690 | -- function at this point. | |
8691 | ||
8692 | elsif Nkind (Ritem) = N_Aspect_Specification | |
238921ae | 8693 | and then Present (Aspect_Rep_Item (Ritem)) |
8694 | and then Scope (Typ) /= Current_Scope | |
0ea02224 | 8695 | then |
8696 | declare | |
8697 | Prag : constant Node_Id := Aspect_Rep_Item (Ritem); | |
8698 | ||
8699 | begin | |
8700 | if Nkind (Prag) = N_Pragma | |
ddccc924 | 8701 | and then Pragma_Name (Prag) = Name_Predicate |
0ea02224 | 8702 | then |
8703 | Add_Predicate (Prag); | |
8704 | end if; | |
8705 | end; | |
eb66e842 | 8706 | end if; |
d97beb2f | 8707 | |
eb66e842 | 8708 | Next_Rep_Item (Ritem); |
8709 | end loop; | |
8710 | end Add_Predicates; | |
d97beb2f | 8711 | |
eb66e842 | 8712 | ---------------- |
8713 | -- Process_RE -- | |
8714 | ---------------- | |
d97beb2f | 8715 | |
eb66e842 | 8716 | function Process_RE (N : Node_Id) return Traverse_Result is |
d9f6a4ee | 8717 | begin |
eb66e842 | 8718 | if Nkind (N) = N_Raise_Expression then |
8719 | Set_Convert_To_Return_False (N); | |
8720 | return Skip; | |
d9f6a4ee | 8721 | else |
eb66e842 | 8722 | return OK; |
d9f6a4ee | 8723 | end if; |
eb66e842 | 8724 | end Process_RE; |
d7c2851f | 8725 | |
d9f6a4ee | 8726 | ------------- |
eb66e842 | 8727 | -- Test_RE -- |
d9f6a4ee | 8728 | ------------- |
d7c2851f | 8729 | |
eb66e842 | 8730 | function Test_RE (N : Node_Id) return Traverse_Result is |
d97beb2f | 8731 | begin |
eb66e842 | 8732 | if Nkind (N) = N_Raise_Expression then |
8733 | Raise_Expression_Present := True; | |
8734 | return Abandon; | |
8735 | else | |
8736 | return OK; | |
8737 | end if; | |
8738 | end Test_RE; | |
d97beb2f | 8739 | |
f9e26ff7 | 8740 | -- Local variables |
8741 | ||
150bddeb | 8742 | Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
8743 | Saved_IGR : constant Node_Id := Ignored_Ghost_Region; | |
8744 | -- Save the Ghost-related attributes to restore on exit | |
f9e26ff7 | 8745 | |
eb66e842 | 8746 | -- Start of processing for Build_Predicate_Functions |
d97beb2f | 8747 | |
eb66e842 | 8748 | begin |
8749 | -- Return if already built or if type does not have predicates | |
9dc88aea | 8750 | |
9c20237a | 8751 | SId := Predicate_Function (Typ); |
eb66e842 | 8752 | if not Has_Predicates (Typ) |
9c20237a | 8753 | or else (Present (SId) and then Has_Completion (SId)) |
eb66e842 | 8754 | then |
8755 | return; | |
b4dcd57e | 8756 | |
8757 | -- Do not generate predicate bodies within a generic unit. The | |
8758 | -- expressions have been analyzed already, and the bodies play | |
f3f142ac | 8759 | -- no role if not within an executable unit. However, if a statc |
8760 | -- predicate is present it must be processed for legality checks | |
8761 | -- such as case coverage in an expression. | |
b4dcd57e | 8762 | |
f3f142ac | 8763 | elsif Inside_A_Generic |
8764 | and then not Has_Static_Predicate_Aspect (Typ) | |
8765 | then | |
b4dcd57e | 8766 | return; |
eb66e842 | 8767 | end if; |
d9f6a4ee | 8768 | |
30f8d103 | 8769 | -- The related type may be subject to pragma Ghost. Set the mode now to |
8770 | -- ensure that the predicate functions are properly marked as Ghost. | |
f9e26ff7 | 8771 | |
e02e4129 | 8772 | Set_Ghost_Mode (Typ); |
f9e26ff7 | 8773 | |
eb66e842 | 8774 | -- Prepare to construct predicate expression |
d97beb2f | 8775 | |
eb66e842 | 8776 | Expr := Empty; |
d97beb2f | 8777 | |
9c20237a | 8778 | if Present (SId) then |
8779 | FDecl := Unit_Declaration_Node (SId); | |
8780 | ||
8781 | else | |
8782 | FDecl := Build_Predicate_Function_Declaration (Typ); | |
8783 | SId := Defining_Entity (FDecl); | |
8784 | end if; | |
8785 | ||
8786 | -- Recover name of formal parameter of function that replaces references | |
8787 | -- to the type in predicate expressions. | |
8788 | ||
8789 | Object_Entity := | |
8790 | Defining_Identifier | |
8791 | (First (Parameter_Specifications (Specification (FDecl)))); | |
8792 | ||
8793 | Object_Name := Chars (Object_Entity); | |
8794 | Object_Entity_M := Make_Defining_Identifier (Loc, Chars => Object_Name); | |
8795 | ||
75491446 | 8796 | -- Add predicates for ancestor if present. These must come before the |
8797 | -- ones for the current type, as required by AI12-0071-1. | |
d97beb2f | 8798 | |
eb66e842 | 8799 | declare |
74d7e7f5 | 8800 | Atyp : Entity_Id; |
d9f6a4ee | 8801 | begin |
74d7e7f5 | 8802 | Atyp := Nearest_Ancestor (Typ); |
8803 | ||
8804 | -- The type may be private but the full view may inherit predicates | |
8805 | ||
8806 | if No (Atyp) and then Is_Private_Type (Typ) then | |
8807 | Atyp := Nearest_Ancestor (Full_View (Typ)); | |
8808 | end if; | |
8809 | ||
eb66e842 | 8810 | if Present (Atyp) then |
8811 | Add_Call (Atyp); | |
8812 | end if; | |
8813 | end; | |
02e5d0d0 | 8814 | |
75491446 | 8815 | -- Add Predicates for the current type |
8816 | ||
8817 | Add_Predicates; | |
8818 | ||
eb66e842 | 8819 | -- Case where predicates are present |
9dc88aea | 8820 | |
eb66e842 | 8821 | if Present (Expr) then |
96cb18c0 | 8822 | |
eb66e842 | 8823 | -- Test for raise expression present |
726fd56a | 8824 | |
eb66e842 | 8825 | Test_REs (Expr); |
9dc88aea | 8826 | |
eb66e842 | 8827 | -- If raise expression is present, capture a copy of Expr for use |
8828 | -- in building the predicateM function version later on. For this | |
8829 | -- copy we replace references to Object_Entity by Object_Entity_M. | |
9dc88aea | 8830 | |
eb66e842 | 8831 | if Raise_Expression_Present then |
8832 | declare | |
96cb18c0 | 8833 | function Reset_Loop_Variable |
8834 | (N : Node_Id) return Traverse_Result; | |
299b347e | 8835 | |
96cb18c0 | 8836 | procedure Reset_Loop_Variables is |
299b347e | 8837 | new Traverse_Proc (Reset_Loop_Variable); |
8838 | ||
8839 | ------------------------ | |
8840 | -- Reset_Loop_Variable -- | |
8841 | ------------------------ | |
8842 | ||
96cb18c0 | 8843 | function Reset_Loop_Variable |
8844 | (N : Node_Id) return Traverse_Result | |
299b347e | 8845 | is |
8846 | begin | |
8847 | if Nkind (N) = N_Iterator_Specification then | |
96cb18c0 | 8848 | Set_Defining_Identifier (N, |
8849 | Make_Defining_Identifier | |
8850 | (Sloc (N), Chars (Defining_Identifier (N)))); | |
299b347e | 8851 | end if; |
8852 | ||
8853 | return OK; | |
8854 | end Reset_Loop_Variable; | |
8855 | ||
96cb18c0 | 8856 | -- Local variables |
8857 | ||
8858 | Map : constant Elist_Id := New_Elmt_List; | |
8859 | ||
eb66e842 | 8860 | begin |
8861 | Append_Elmt (Object_Entity, Map); | |
8862 | Append_Elmt (Object_Entity_M, Map); | |
8863 | Expr_M := New_Copy_Tree (Expr, Map => Map); | |
96cb18c0 | 8864 | |
8865 | -- The unanalyzed expression will be copied and appear in | |
8866 | -- both functions. Normally expressions do not declare new | |
8867 | -- entities, but quantified expressions do, so we need to | |
8868 | -- create new entities for their bound variables, to prevent | |
8869 | -- multiple definitions in gigi. | |
8870 | ||
8871 | Reset_Loop_Variables (Expr_M); | |
eb66e842 | 8872 | end; |
8873 | end if; | |
d97beb2f | 8874 | |
eb66e842 | 8875 | -- Build the main predicate function |
9dc88aea | 8876 | |
eb66e842 | 8877 | declare |
eb66e842 | 8878 | SIdB : constant Entity_Id := |
8879 | Make_Defining_Identifier (Loc, | |
8880 | Chars => New_External_Name (Chars (Typ), "Predicate")); | |
8881 | -- The entity for the function body | |
9dc88aea | 8882 | |
eb66e842 | 8883 | Spec : Node_Id; |
eb66e842 | 8884 | FBody : Node_Id; |
9dc88aea | 8885 | |
eb66e842 | 8886 | begin |
37066559 | 8887 | Set_Ekind (SIdB, E_Function); |
8888 | Set_Is_Predicate_Function (SIdB); | |
8889 | ||
eb66e842 | 8890 | -- The predicate function is shared between views of a type |
d97beb2f | 8891 | |
eb66e842 | 8892 | if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
8893 | Set_Predicate_Function (Full_View (Typ), SId); | |
d97beb2f | 8894 | end if; |
d97beb2f | 8895 | |
eb66e842 | 8896 | -- Build function body |
d97beb2f | 8897 | |
eb66e842 | 8898 | Spec := |
8899 | Make_Function_Specification (Loc, | |
8900 | Defining_Unit_Name => SIdB, | |
8901 | Parameter_Specifications => New_List ( | |
8902 | Make_Parameter_Specification (Loc, | |
8903 | Defining_Identifier => | |
8904 | Make_Defining_Identifier (Loc, Object_Name), | |
8905 | Parameter_Type => | |
8906 | New_Occurrence_Of (Typ, Loc))), | |
8907 | Result_Definition => | |
8908 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
d97beb2f | 8909 | |
eb66e842 | 8910 | FBody := |
8911 | Make_Subprogram_Body (Loc, | |
8912 | Specification => Spec, | |
8913 | Declarations => Empty_List, | |
8914 | Handled_Statement_Sequence => | |
8915 | Make_Handled_Sequence_Of_Statements (Loc, | |
8916 | Statements => New_List ( | |
8917 | Make_Simple_Return_Statement (Loc, | |
8918 | Expression => Expr)))); | |
9dc88aea | 8919 | |
75c9ecc1 | 8920 | -- The declaration has been analyzed when created, and placed |
a9fa50ab | 8921 | -- after type declaration. Insert body itself after freeze node, |
8922 | -- unless subprogram declaration is already there, in which case | |
8923 | -- body better be placed afterwards. | |
d97beb2f | 8924 | |
a9fa50ab | 8925 | if FDecl = Next (N) then |
8926 | Insert_After_And_Analyze (FDecl, FBody); | |
8927 | else | |
8928 | Insert_After_And_Analyze (N, FBody); | |
8929 | end if; | |
6958c62c | 8930 | |
6aefdbe5 | 8931 | -- The defining identifier of a quantified expression carries the |
8932 | -- scope in which the type appears, but when unnesting we need | |
8933 | -- to indicate that its proper scope is the constructed predicate | |
8934 | -- function. The quantified expressions have been converted into | |
8935 | -- loops during analysis and expansion. | |
8936 | ||
8937 | declare | |
96cb18c0 | 8938 | function Reset_Quantified_Variable_Scope |
8939 | (N : Node_Id) return Traverse_Result; | |
6aefdbe5 | 8940 | |
8941 | procedure Reset_Quantified_Variables_Scope is | |
8942 | new Traverse_Proc (Reset_Quantified_Variable_Scope); | |
8943 | ||
8944 | ------------------------------------- | |
8945 | -- Reset_Quantified_Variable_Scope -- | |
8946 | ------------------------------------- | |
8947 | ||
96cb18c0 | 8948 | function Reset_Quantified_Variable_Scope |
8949 | (N : Node_Id) return Traverse_Result | |
6aefdbe5 | 8950 | is |
8951 | begin | |
8952 | if Nkind_In (N, N_Iterator_Specification, | |
8953 | N_Loop_Parameter_Specification) | |
8954 | then | |
8955 | Set_Scope (Defining_Identifier (N), | |
8956 | Predicate_Function (Typ)); | |
8957 | end if; | |
96cb18c0 | 8958 | |
6aefdbe5 | 8959 | return OK; |
8960 | end Reset_Quantified_Variable_Scope; | |
8961 | ||
8962 | begin | |
8963 | if Unnest_Subprogram_Mode then | |
8964 | Reset_Quantified_Variables_Scope (Expr); | |
8965 | end if; | |
8966 | end; | |
8967 | ||
75c9ecc1 | 8968 | -- within a generic unit, prevent a double analysis of the body |
8969 | -- which will not be marked analyzed yet. This will happen when | |
aefa1e7d | 8970 | -- the freeze node is created during the preanalysis of an |
75c9ecc1 | 8971 | -- expression function. |
8972 | ||
8973 | if Inside_A_Generic then | |
8974 | Set_Analyzed (FBody); | |
8975 | end if; | |
8976 | ||
6958c62c | 8977 | -- Static predicate functions are always side-effect free, and |
8978 | -- in most cases dynamic predicate functions are as well. Mark | |
8979 | -- them as such whenever possible, so redundant predicate checks | |
7dd0b9b3 | 8980 | -- can be optimized. If there is a variable reference within the |
8981 | -- expression, the function is not pure. | |
b2e821de | 8982 | |
6958c62c | 8983 | if Expander_Active then |
7dd0b9b3 | 8984 | Set_Is_Pure (SId, |
8985 | Side_Effect_Free (Expr, Variable_Ref => True)); | |
6958c62c | 8986 | Set_Is_Inlined (SId); |
8987 | end if; | |
d9f6a4ee | 8988 | end; |
d97beb2f | 8989 | |
eb66e842 | 8990 | -- Test for raise expressions present and if so build M version |
d97beb2f | 8991 | |
eb66e842 | 8992 | if Raise_Expression_Present then |
8993 | declare | |
8994 | SId : constant Entity_Id := | |
8995 | Make_Defining_Identifier (Loc, | |
8996 | Chars => New_External_Name (Chars (Typ), "PredicateM")); | |
c96806b2 | 8997 | -- The entity for the function spec |
d97beb2f | 8998 | |
eb66e842 | 8999 | SIdB : constant Entity_Id := |
9000 | Make_Defining_Identifier (Loc, | |
9001 | Chars => New_External_Name (Chars (Typ), "PredicateM")); | |
9002 | -- The entity for the function body | |
b9e61b2a | 9003 | |
eb66e842 | 9004 | Spec : Node_Id; |
eb66e842 | 9005 | FBody : Node_Id; |
9c20237a | 9006 | FDecl : Node_Id; |
eb66e842 | 9007 | BTemp : Entity_Id; |
d97beb2f | 9008 | |
eb66e842 | 9009 | begin |
9010 | -- Mark any raise expressions for special expansion | |
d97beb2f | 9011 | |
eb66e842 | 9012 | Process_REs (Expr_M); |
d97beb2f | 9013 | |
eb66e842 | 9014 | -- Build function declaration |
d97beb2f | 9015 | |
eb66e842 | 9016 | Set_Ekind (SId, E_Function); |
9017 | Set_Is_Predicate_Function_M (SId); | |
9018 | Set_Predicate_Function_M (Typ, SId); | |
d97beb2f | 9019 | |
eb66e842 | 9020 | -- The predicate function is shared between views of a type |
d97beb2f | 9021 | |
eb66e842 | 9022 | if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
9023 | Set_Predicate_Function_M (Full_View (Typ), SId); | |
9024 | end if; | |
9dc88aea | 9025 | |
eb66e842 | 9026 | Spec := |
9027 | Make_Function_Specification (Loc, | |
9028 | Defining_Unit_Name => SId, | |
9029 | Parameter_Specifications => New_List ( | |
9030 | Make_Parameter_Specification (Loc, | |
9031 | Defining_Identifier => Object_Entity_M, | |
9032 | Parameter_Type => New_Occurrence_Of (Typ, Loc))), | |
9033 | Result_Definition => | |
9034 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
9dc88aea | 9035 | |
eb66e842 | 9036 | FDecl := |
9037 | Make_Subprogram_Declaration (Loc, | |
9038 | Specification => Spec); | |
9dc88aea | 9039 | |
eb66e842 | 9040 | -- Build function body |
9dc88aea | 9041 | |
eb66e842 | 9042 | Spec := |
9043 | Make_Function_Specification (Loc, | |
9044 | Defining_Unit_Name => SIdB, | |
9045 | Parameter_Specifications => New_List ( | |
9046 | Make_Parameter_Specification (Loc, | |
9047 | Defining_Identifier => | |
9048 | Make_Defining_Identifier (Loc, Object_Name), | |
9049 | Parameter_Type => | |
9050 | New_Occurrence_Of (Typ, Loc))), | |
9051 | Result_Definition => | |
9052 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
9dc88aea | 9053 | |
eb66e842 | 9054 | -- Build the body, we declare the boolean expression before |
9055 | -- doing the return, because we are not really confident of | |
9056 | -- what happens if a return appears within a return. | |
9dc88aea | 9057 | |
eb66e842 | 9058 | BTemp := |
9059 | Make_Defining_Identifier (Loc, | |
9060 | Chars => New_Internal_Name ('B')); | |
9dc88aea | 9061 | |
eb66e842 | 9062 | FBody := |
9063 | Make_Subprogram_Body (Loc, | |
9064 | Specification => Spec, | |
9dc88aea | 9065 | |
eb66e842 | 9066 | Declarations => New_List ( |
9067 | Make_Object_Declaration (Loc, | |
9068 | Defining_Identifier => BTemp, | |
9069 | Constant_Present => True, | |
9070 | Object_Definition => | |
9071 | New_Occurrence_Of (Standard_Boolean, Loc), | |
9072 | Expression => Expr_M)), | |
d97beb2f | 9073 | |
eb66e842 | 9074 | Handled_Statement_Sequence => |
9075 | Make_Handled_Sequence_Of_Statements (Loc, | |
9076 | Statements => New_List ( | |
9077 | Make_Simple_Return_Statement (Loc, | |
9078 | Expression => New_Occurrence_Of (BTemp, Loc))))); | |
d97beb2f | 9079 | |
eb66e842 | 9080 | -- Insert declaration before freeze node and body after |
d97beb2f | 9081 | |
eb66e842 | 9082 | Insert_Before_And_Analyze (N, FDecl); |
9083 | Insert_After_And_Analyze (N, FBody); | |
6aefdbe5 | 9084 | |
9085 | -- Should quantified expressions be handled here as well ??? | |
eb66e842 | 9086 | end; |
9087 | end if; | |
9dc88aea | 9088 | |
3b23aaa0 | 9089 | -- See if we have a static predicate. Note that the answer may be |
9090 | -- yes even if we have an explicit Dynamic_Predicate present. | |
9dc88aea | 9091 | |
3b23aaa0 | 9092 | declare |
94d896aa | 9093 | PS : Boolean; |
3b23aaa0 | 9094 | EN : Node_Id; |
9dc88aea | 9095 | |
3b23aaa0 | 9096 | begin |
94d896aa | 9097 | if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then |
9098 | PS := False; | |
9099 | else | |
9100 | PS := Is_Predicate_Static (Expr, Object_Name); | |
9101 | end if; | |
9102 | ||
a360a0f7 | 9103 | -- Case where we have a predicate-static aspect |
9dc88aea | 9104 | |
3b23aaa0 | 9105 | if PS then |
9dc88aea | 9106 | |
3b23aaa0 | 9107 | -- We don't set Has_Static_Predicate_Aspect, since we can have |
9108 | -- any of the three cases (Predicate, Dynamic_Predicate, or | |
9109 | -- Static_Predicate) generating a predicate with an expression | |
a360a0f7 | 9110 | -- that is predicate-static. We just indicate that we have a |
3b23aaa0 | 9111 | -- predicate that can be treated as static. |
d7c2851f | 9112 | |
3b23aaa0 | 9113 | Set_Has_Static_Predicate (Typ); |
d7c2851f | 9114 | |
3b23aaa0 | 9115 | -- For discrete subtype, build the static predicate list |
9dc88aea | 9116 | |
3b23aaa0 | 9117 | if Is_Discrete_Type (Typ) then |
9118 | Build_Discrete_Static_Predicate (Typ, Expr, Object_Name); | |
9119 | ||
9120 | -- If we don't get a static predicate list, it means that we | |
9121 | -- have a case where this is not possible, most typically in | |
9122 | -- the case where we inherit a dynamic predicate. We do not | |
9123 | -- consider this an error, we just leave the predicate as | |
9124 | -- dynamic. But if we do succeed in building the list, then | |
9125 | -- we mark the predicate as static. | |
9126 | ||
5c6a5792 | 9127 | if No (Static_Discrete_Predicate (Typ)) then |
3b23aaa0 | 9128 | Set_Has_Static_Predicate (Typ, False); |
9129 | end if; | |
94d896aa | 9130 | |
9131 | -- For real or string subtype, save predicate expression | |
9132 | ||
9133 | elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then | |
9134 | Set_Static_Real_Or_String_Predicate (Typ, Expr); | |
3b23aaa0 | 9135 | end if; |
9136 | ||
9137 | -- Case of dynamic predicate (expression is not predicate-static) | |
9dc88aea | 9138 | |
eb66e842 | 9139 | else |
3b23aaa0 | 9140 | -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that |
9141 | -- is only set if we have an explicit Dynamic_Predicate aspect | |
9142 | -- given. Here we may simply have a Predicate aspect where the | |
9143 | -- expression happens not to be predicate-static. | |
9144 | ||
9145 | -- Emit an error when the predicate is categorized as static | |
9146 | -- but its expression is not predicate-static. | |
9147 | ||
9148 | -- First a little fiddling to get a nice location for the | |
9149 | -- message. If the expression is of the form (A and then B), | |
75491446 | 9150 | -- where A is an inherited predicate, then use the right |
9151 | -- operand for the Sloc. This avoids getting confused by a call | |
9152 | -- to an inherited predicate with a less convenient source | |
9153 | -- location. | |
3b23aaa0 | 9154 | |
9155 | EN := Expr; | |
75491446 | 9156 | while Nkind (EN) = N_And_Then |
9157 | and then Nkind (Left_Opnd (EN)) = N_Function_Call | |
9158 | and then Is_Predicate_Function | |
9159 | (Entity (Name (Left_Opnd (EN)))) | |
9160 | loop | |
9161 | EN := Right_Opnd (EN); | |
3b23aaa0 | 9162 | end loop; |
9163 | ||
9164 | -- Now post appropriate message | |
9165 | ||
9166 | if Has_Static_Predicate_Aspect (Typ) then | |
94d896aa | 9167 | if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then |
3b23aaa0 | 9168 | Error_Msg_F |
26279d91 | 9169 | ("expression is not predicate-static (RM 3.2.4(16-22))", |
3b23aaa0 | 9170 | EN); |
9171 | else | |
94d896aa | 9172 | Error_Msg_F |
9173 | ("static predicate requires scalar or string type", EN); | |
3b23aaa0 | 9174 | end if; |
9175 | end if; | |
eb66e842 | 9176 | end if; |
3b23aaa0 | 9177 | end; |
eb66e842 | 9178 | end if; |
f9e26ff7 | 9179 | |
150bddeb | 9180 | Restore_Ghost_Region (Saved_GM, Saved_IGR); |
eb66e842 | 9181 | end Build_Predicate_Functions; |
9dc88aea | 9182 | |
9c20237a | 9183 | ------------------------------------------ |
9184 | -- Build_Predicate_Function_Declaration -- | |
9185 | ------------------------------------------ | |
9186 | ||
1ecdfe4b | 9187 | -- WARNING: This routine manages Ghost regions. Return statements must be |
9188 | -- replaced by gotos which jump to the end of the routine and restore the | |
9189 | -- Ghost mode. | |
9190 | ||
9c20237a | 9191 | function Build_Predicate_Function_Declaration |
9192 | (Typ : Entity_Id) return Node_Id | |
9193 | is | |
9194 | Loc : constant Source_Ptr := Sloc (Typ); | |
9195 | ||
150bddeb | 9196 | Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
9197 | Saved_IGR : constant Node_Id := Ignored_Ghost_Region; | |
9198 | -- Save the Ghost-related attributes to restore on exit | |
e02e4129 | 9199 | |
72a98436 | 9200 | Func_Decl : Node_Id; |
9201 | Func_Id : Entity_Id; | |
72a98436 | 9202 | Spec : Node_Id; |
9c20237a | 9203 | |
72a98436 | 9204 | begin |
9205 | -- The related type may be subject to pragma Ghost. Set the mode now to | |
9206 | -- ensure that the predicate functions are properly marked as Ghost. | |
9c20237a | 9207 | |
e02e4129 | 9208 | Set_Ghost_Mode (Typ); |
9c20237a | 9209 | |
72a98436 | 9210 | Func_Id := |
9211 | Make_Defining_Identifier (Loc, | |
9212 | Chars => New_External_Name (Chars (Typ), "Predicate")); | |
9c20237a | 9213 | |
3db675d2 | 9214 | -- The predicate function requires debug info when the predicates are |
9215 | -- subject to Source Coverage Obligations. | |
9216 | ||
9217 | if Opt.Generate_SCO then | |
9218 | Set_Debug_Info_Needed (Func_Id); | |
9219 | end if; | |
9220 | ||
9c20237a | 9221 | Spec := |
9222 | Make_Function_Specification (Loc, | |
72a98436 | 9223 | Defining_Unit_Name => Func_Id, |
9c20237a | 9224 | Parameter_Specifications => New_List ( |
9225 | Make_Parameter_Specification (Loc, | |
72a98436 | 9226 | Defining_Identifier => Make_Temporary (Loc, 'I'), |
9c20237a | 9227 | Parameter_Type => New_Occurrence_Of (Typ, Loc))), |
9228 | Result_Definition => | |
9229 | New_Occurrence_Of (Standard_Boolean, Loc)); | |
9230 | ||
72a98436 | 9231 | Func_Decl := Make_Subprogram_Declaration (Loc, Specification => Spec); |
9c20237a | 9232 | |
72a98436 | 9233 | Set_Ekind (Func_Id, E_Function); |
9234 | Set_Etype (Func_Id, Standard_Boolean); | |
9235 | Set_Is_Internal (Func_Id); | |
9236 | Set_Is_Predicate_Function (Func_Id); | |
9237 | Set_Predicate_Function (Typ, Func_Id); | |
9c20237a | 9238 | |
72a98436 | 9239 | Insert_After (Parent (Typ), Func_Decl); |
9240 | Analyze (Func_Decl); | |
9c20237a | 9241 | |
150bddeb | 9242 | Restore_Ghost_Region (Saved_GM, Saved_IGR); |
9c20237a | 9243 | |
72a98436 | 9244 | return Func_Decl; |
9c20237a | 9245 | end Build_Predicate_Function_Declaration; |
9246 | ||
d9f6a4ee | 9247 | ----------------------------------------- |
9248 | -- Check_Aspect_At_End_Of_Declarations -- | |
9249 | ----------------------------------------- | |
9dc88aea | 9250 | |
d9f6a4ee | 9251 | procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is |
9252 | Ent : constant Entity_Id := Entity (ASN); | |
9253 | Ident : constant Node_Id := Identifier (ASN); | |
9254 | A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); | |
d7c2851f | 9255 | |
d9f6a4ee | 9256 | End_Decl_Expr : constant Node_Id := Entity (Ident); |
9257 | -- Expression to be analyzed at end of declarations | |
d7c2851f | 9258 | |
d9f6a4ee | 9259 | Freeze_Expr : constant Node_Id := Expression (ASN); |
6da581c1 | 9260 | -- Expression from call to Check_Aspect_At_Freeze_Point. |
d7c2851f | 9261 | |
25e4fa47 | 9262 | T : constant Entity_Id := Etype (Original_Node (Freeze_Expr)); |
6da581c1 | 9263 | -- Type required for preanalyze call. We use the original expression to |
9264 | -- get the proper type, to prevent cascaded errors when the expression | |
9265 | -- is constant-folded. | |
d7c2851f | 9266 | |
d9f6a4ee | 9267 | Err : Boolean; |
9268 | -- Set False if error | |
9dc88aea | 9269 | |
d9f6a4ee | 9270 | -- On entry to this procedure, Entity (Ident) contains a copy of the |
9271 | -- original expression from the aspect, saved for this purpose, and | |
9272 | -- but Expression (Ident) is a preanalyzed copy of the expression, | |
9273 | -- preanalyzed just after the freeze point. | |
9dc88aea | 9274 | |
d9f6a4ee | 9275 | procedure Check_Overloaded_Name; |
9276 | -- For aspects whose expression is simply a name, this routine checks if | |
9277 | -- the name is overloaded or not. If so, it verifies there is an | |
9278 | -- interpretation that matches the entity obtained at the freeze point, | |
9279 | -- otherwise the compiler complains. | |
9dc88aea | 9280 | |
d9f6a4ee | 9281 | --------------------------- |
9282 | -- Check_Overloaded_Name -- | |
9283 | --------------------------- | |
9284 | ||
9285 | procedure Check_Overloaded_Name is | |
d97beb2f | 9286 | begin |
d9f6a4ee | 9287 | if not Is_Overloaded (End_Decl_Expr) then |
5ac76cee | 9288 | Err := not Is_Entity_Name (End_Decl_Expr) |
9289 | or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr); | |
d9f6a4ee | 9290 | |
d97beb2f | 9291 | else |
d9f6a4ee | 9292 | Err := True; |
9dc88aea | 9293 | |
d9f6a4ee | 9294 | declare |
9295 | Index : Interp_Index; | |
9296 | It : Interp; | |
9dc88aea | 9297 | |
d9f6a4ee | 9298 | begin |
9299 | Get_First_Interp (End_Decl_Expr, Index, It); | |
9300 | while Present (It.Typ) loop | |
9301 | if It.Nam = Entity (Freeze_Expr) then | |
9302 | Err := False; | |
9303 | exit; | |
9304 | end if; | |
9305 | ||
9306 | Get_Next_Interp (Index, It); | |
9307 | end loop; | |
9308 | end; | |
9dc88aea | 9309 | end if; |
d9f6a4ee | 9310 | end Check_Overloaded_Name; |
9dc88aea | 9311 | |
d9f6a4ee | 9312 | -- Start of processing for Check_Aspect_At_End_Of_Declarations |
9dc88aea | 9313 | |
d9f6a4ee | 9314 | begin |
da3cad01 | 9315 | -- In an instance we do not perform the consistency check between freeze |
9316 | -- point and end of declarations, because it was done already in the | |
9317 | -- analysis of the generic. Furthermore, the delayed analysis of an | |
9318 | -- aspect of the instance may produce spurious errors when the generic | |
9319 | -- is a child unit that references entities in the parent (which might | |
9320 | -- not be in scope at the freeze point of the instance). | |
9321 | ||
9322 | if In_Instance then | |
9323 | return; | |
9324 | ||
1c164d44 | 9325 | -- The enclosing scope may have been rewritten during expansion (.e.g. a |
9326 | -- task body is rewritten as a procedure) after this conformance check | |
9327 | -- has been performed, so do not perform it again (it may not easily be | |
9328 | -- done if full visibility of local entities is not available). | |
ce450a94 | 9329 | |
9330 | elsif not Comes_From_Source (Current_Scope) then | |
9331 | return; | |
9332 | ||
d9f6a4ee | 9333 | -- Case of aspects Dimension, Dimension_System and Synchronization |
9dc88aea | 9334 | |
da3cad01 | 9335 | elsif A_Id = Aspect_Synchronization then |
d9f6a4ee | 9336 | return; |
d97beb2f | 9337 | |
d9f6a4ee | 9338 | -- Case of stream attributes, just have to compare entities. However, |
9339 | -- the expression is just a name (possibly overloaded), and there may | |
9340 | -- be stream operations declared for unrelated types, so we just need | |
9341 | -- to verify that one of these interpretations is the one available at | |
9342 | -- at the freeze point. | |
9dc88aea | 9343 | |
d9f6a4ee | 9344 | elsif A_Id = Aspect_Input or else |
f02a9a9a | 9345 | A_Id = Aspect_Output or else |
9346 | A_Id = Aspect_Read or else | |
9347 | A_Id = Aspect_Write | |
d9f6a4ee | 9348 | then |
9349 | Analyze (End_Decl_Expr); | |
9350 | Check_Overloaded_Name; | |
9dc88aea | 9351 | |
d9f6a4ee | 9352 | elsif A_Id = Aspect_Variable_Indexing or else |
9353 | A_Id = Aspect_Constant_Indexing or else | |
9354 | A_Id = Aspect_Default_Iterator or else | |
9355 | A_Id = Aspect_Iterator_Element | |
9356 | then | |
9357 | -- Make type unfrozen before analysis, to prevent spurious errors | |
9358 | -- about late attributes. | |
9dc88aea | 9359 | |
d9f6a4ee | 9360 | Set_Is_Frozen (Ent, False); |
9361 | Analyze (End_Decl_Expr); | |
9362 | Set_Is_Frozen (Ent, True); | |
9dc88aea | 9363 | |
99d90c85 | 9364 | -- If the end of declarations comes before any other freeze point, |
9365 | -- the Freeze_Expr is not analyzed: no check needed. | |
9dc88aea | 9366 | |
d9f6a4ee | 9367 | if Analyzed (Freeze_Expr) and then not In_Instance then |
9368 | Check_Overloaded_Name; | |
9369 | else | |
9370 | Err := False; | |
9371 | end if; | |
55e8372b | 9372 | |
d9f6a4ee | 9373 | -- All other cases |
55e8372b | 9374 | |
d9f6a4ee | 9375 | else |
99d90c85 | 9376 | -- In a generic context freeze nodes are not always generated, so |
429822c1 | 9377 | -- analyze the expression now. If the aspect is for a type, this |
9378 | -- makes its potential components accessible. | |
0396441f | 9379 | |
99d90c85 | 9380 | if not Analyzed (Freeze_Expr) and then Inside_A_Generic then |
429822c1 | 9381 | if A_Id = Aspect_Dynamic_Predicate |
9382 | or else A_Id = Aspect_Predicate | |
9383 | or else A_Id = Aspect_Priority | |
9384 | then | |
9385 | Push_Type (Ent); | |
9386 | Preanalyze (Freeze_Expr); | |
9387 | Pop_Type (Ent); | |
9388 | else | |
9389 | Preanalyze (Freeze_Expr); | |
9390 | end if; | |
0396441f | 9391 | end if; |
9392 | ||
c1efebf9 | 9393 | -- Indicate that the expression comes from an aspect specification, |
9394 | -- which is used in subsequent analysis even if expansion is off. | |
9395 | ||
9396 | Set_Parent (End_Decl_Expr, ASN); | |
9397 | ||
d9f6a4ee | 9398 | -- In a generic context the aspect expressions have not been |
9399 | -- preanalyzed, so do it now. There are no conformance checks | |
9400 | -- to perform in this case. | |
55e8372b | 9401 | |
d9f6a4ee | 9402 | if No (T) then |
9403 | Check_Aspect_At_Freeze_Point (ASN); | |
9404 | return; | |
55e8372b | 9405 | |
d9f6a4ee | 9406 | -- The default values attributes may be defined in the private part, |
9407 | -- and the analysis of the expression may take place when only the | |
9408 | -- partial view is visible. The expression must be scalar, so use | |
9409 | -- the full view to resolve. | |
55e8372b | 9410 | |
d9f6a4ee | 9411 | elsif (A_Id = Aspect_Default_Value |
9412 | or else | |
9413 | A_Id = Aspect_Default_Component_Value) | |
9414 | and then Is_Private_Type (T) | |
9415 | then | |
9416 | Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T)); | |
c1efebf9 | 9417 | |
b4dcd57e | 9418 | -- The following aspect expressions may contain references to |
9419 | -- components and discriminants of the type. | |
9420 | ||
92038d64 | 9421 | elsif A_Id = Aspect_Dynamic_Predicate |
796ad64d | 9422 | or else A_Id = Aspect_Predicate |
b4dcd57e | 9423 | or else A_Id = Aspect_Priority |
dcccb125 | 9424 | or else A_Id = Aspect_CPU |
b4dcd57e | 9425 | then |
9426 | Push_Type (Ent); | |
9427 | Preanalyze_Spec_Expression (End_Decl_Expr, T); | |
9428 | Pop_Type (Ent); | |
9429 | ||
d9f6a4ee | 9430 | else |
9431 | Preanalyze_Spec_Expression (End_Decl_Expr, T); | |
9432 | end if; | |
d97beb2f | 9433 | |
92038d64 | 9434 | Err := |
9435 | not Fully_Conformant_Expressions | |
b4dcd57e | 9436 | (End_Decl_Expr, Freeze_Expr, Report => True); |
d9f6a4ee | 9437 | end if; |
55e8372b | 9438 | |
c1efebf9 | 9439 | -- Output error message if error. Force error on aspect specification |
9440 | -- even if there is an error on the expression itself. | |
55e8372b | 9441 | |
d9f6a4ee | 9442 | if Err then |
9443 | Error_Msg_NE | |
c1efebf9 | 9444 | ("!visibility of aspect for& changes after freeze point", |
d9f6a4ee | 9445 | ASN, Ent); |
9446 | Error_Msg_NE | |
b4dcd57e | 9447 | ("info: & is frozen here, (RM 13.1.1 (13/3))??", |
d9f6a4ee | 9448 | Freeze_Node (Ent), Ent); |
9449 | end if; | |
9450 | end Check_Aspect_At_End_Of_Declarations; | |
55e8372b | 9451 | |
d9f6a4ee | 9452 | ---------------------------------- |
9453 | -- Check_Aspect_At_Freeze_Point -- | |
9454 | ---------------------------------- | |
9dc88aea | 9455 | |
d9f6a4ee | 9456 | procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is |
9457 | Ident : constant Node_Id := Identifier (ASN); | |
9458 | -- Identifier (use Entity field to save expression) | |
9dc88aea | 9459 | |
d9f6a4ee | 9460 | A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); |
9dc88aea | 9461 | |
d9f6a4ee | 9462 | T : Entity_Id := Empty; |
9463 | -- Type required for preanalyze call | |
9dc88aea | 9464 | |
d9f6a4ee | 9465 | begin |
9466 | -- On entry to this procedure, Entity (Ident) contains a copy of the | |
9467 | -- original expression from the aspect, saved for this purpose. | |
9dc88aea | 9468 | |
d9f6a4ee | 9469 | -- On exit from this procedure Entity (Ident) is unchanged, still |
9470 | -- containing that copy, but Expression (Ident) is a preanalyzed copy | |
9471 | -- of the expression, preanalyzed just after the freeze point. | |
d97beb2f | 9472 | |
d9f6a4ee | 9473 | -- Make a copy of the expression to be preanalyzed |
d97beb2f | 9474 | |
d9f6a4ee | 9475 | Set_Expression (ASN, New_Copy_Tree (Entity (Ident))); |
d97beb2f | 9476 | |
d9f6a4ee | 9477 | -- Find type for preanalyze call |
d97beb2f | 9478 | |
d9f6a4ee | 9479 | case A_Id is |
9dc88aea | 9480 | |
d9f6a4ee | 9481 | -- No_Aspect should be impossible |
d97beb2f | 9482 | |
d9f6a4ee | 9483 | when No_Aspect => |
9484 | raise Program_Error; | |
9485 | ||
9486 | -- Aspects taking an optional boolean argument | |
d97beb2f | 9487 | |
99378362 | 9488 | when Boolean_Aspects |
9489 | | Library_Unit_Aspects | |
9490 | => | |
d9f6a4ee | 9491 | T := Standard_Boolean; |
d7c2851f | 9492 | |
d9f6a4ee | 9493 | -- Aspects corresponding to attribute definition clauses |
9dc88aea | 9494 | |
d9f6a4ee | 9495 | when Aspect_Address => |
9496 | T := RTE (RE_Address); | |
9dc88aea | 9497 | |
d9f6a4ee | 9498 | when Aspect_Attach_Handler => |
9499 | T := RTE (RE_Interrupt_ID); | |
d7c2851f | 9500 | |
99378362 | 9501 | when Aspect_Bit_Order |
9502 | | Aspect_Scalar_Storage_Order | |
9503 | => | |
d9f6a4ee | 9504 | T := RTE (RE_Bit_Order); |
d7c2851f | 9505 | |
d9f6a4ee | 9506 | when Aspect_Convention => |
9507 | return; | |
d7c2851f | 9508 | |
d9f6a4ee | 9509 | when Aspect_CPU => |
9510 | T := RTE (RE_CPU_Range); | |
d7c2851f | 9511 | |
d9f6a4ee | 9512 | -- Default_Component_Value is resolved with the component type |
d7c2851f | 9513 | |
d9f6a4ee | 9514 | when Aspect_Default_Component_Value => |
9515 | T := Component_Type (Entity (ASN)); | |
d7c2851f | 9516 | |
647fab54 | 9517 | when Aspect_Default_Storage_Pool => |
9518 | T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); | |
9519 | ||
d9f6a4ee | 9520 | -- Default_Value is resolved with the type entity in question |
d7c2851f | 9521 | |
d9f6a4ee | 9522 | when Aspect_Default_Value => |
9523 | T := Entity (ASN); | |
9dc88aea | 9524 | |
d9f6a4ee | 9525 | when Aspect_Dispatching_Domain => |
9526 | T := RTE (RE_Dispatching_Domain); | |
9dc88aea | 9527 | |
d9f6a4ee | 9528 | when Aspect_External_Tag => |
9529 | T := Standard_String; | |
9dc88aea | 9530 | |
d9f6a4ee | 9531 | when Aspect_External_Name => |
9532 | T := Standard_String; | |
9dc88aea | 9533 | |
d9f6a4ee | 9534 | when Aspect_Link_Name => |
9535 | T := Standard_String; | |
9dc88aea | 9536 | |
99378362 | 9537 | when Aspect_Interrupt_Priority |
9538 | | Aspect_Priority | |
9539 | => | |
d9f6a4ee | 9540 | T := Standard_Integer; |
d97beb2f | 9541 | |
d9f6a4ee | 9542 | when Aspect_Relative_Deadline => |
9543 | T := RTE (RE_Time_Span); | |
d97beb2f | 9544 | |
e6ce0468 | 9545 | when Aspect_Secondary_Stack_Size => |
9546 | T := Standard_Integer; | |
9547 | ||
d9f6a4ee | 9548 | when Aspect_Small => |
edfb7dbc | 9549 | |
9550 | -- Note that the expression can be of any real type (not just a | |
9551 | -- real universal literal) as long as it is a static constant. | |
eba9690d | 9552 | |
9553 | T := Any_Real; | |
490beba6 | 9554 | |
d9f6a4ee | 9555 | -- For a simple storage pool, we have to retrieve the type of the |
9556 | -- pool object associated with the aspect's corresponding attribute | |
9557 | -- definition clause. | |
490beba6 | 9558 | |
d9f6a4ee | 9559 | when Aspect_Simple_Storage_Pool => |
9560 | T := Etype (Expression (Aspect_Rep_Item (ASN))); | |
d97beb2f | 9561 | |
d9f6a4ee | 9562 | when Aspect_Storage_Pool => |
9563 | T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); | |
d97beb2f | 9564 | |
99378362 | 9565 | when Aspect_Alignment |
9566 | | Aspect_Component_Size | |
9567 | | Aspect_Machine_Radix | |
9568 | | Aspect_Object_Size | |
9569 | | Aspect_Size | |
9570 | | Aspect_Storage_Size | |
9571 | | Aspect_Stream_Size | |
9572 | | Aspect_Value_Size | |
9573 | => | |
d9f6a4ee | 9574 | T := Any_Integer; |
9dc88aea | 9575 | |
04ae062f | 9576 | when Aspect_Linker_Section => |
9577 | T := Standard_String; | |
9578 | ||
d9f6a4ee | 9579 | when Aspect_Synchronization => |
9580 | return; | |
7d20685d | 9581 | |
d9f6a4ee | 9582 | -- Special case, the expression of these aspects is just an entity |
9583 | -- that does not need any resolution, so just analyze. | |
7d20685d | 9584 | |
99378362 | 9585 | when Aspect_Input |
9586 | | Aspect_Output | |
9587 | | Aspect_Read | |
9588 | | Aspect_Suppress | |
9589 | | Aspect_Unsuppress | |
9590 | | Aspect_Warnings | |
9591 | | Aspect_Write | |
9592 | => | |
d9f6a4ee | 9593 | Analyze (Expression (ASN)); |
9594 | return; | |
7d20685d | 9595 | |
d9f6a4ee | 9596 | -- Same for Iterator aspects, where the expression is a function |
9597 | -- name. Legality rules are checked separately. | |
89f1e35c | 9598 | |
99378362 | 9599 | when Aspect_Constant_Indexing |
9600 | | Aspect_Default_Iterator | |
9601 | | Aspect_Iterator_Element | |
9602 | | Aspect_Variable_Indexing | |
9603 | => | |
d9f6a4ee | 9604 | Analyze (Expression (ASN)); |
9605 | return; | |
7d20685d | 9606 | |
b3f8228a | 9607 | -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect. |
9608 | ||
9609 | when Aspect_Iterable => | |
3061ffde | 9610 | T := Entity (ASN); |
9611 | ||
b3f8228a | 9612 | declare |
a9f5fea7 | 9613 | Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T); |
3061ffde | 9614 | Assoc : Node_Id; |
9615 | Expr : Node_Id; | |
a9f5fea7 | 9616 | |
b3f8228a | 9617 | begin |
a9f5fea7 | 9618 | if Cursor = Any_Type then |
9619 | return; | |
9620 | end if; | |
9621 | ||
b3f8228a | 9622 | Assoc := First (Component_Associations (Expression (ASN))); |
9623 | while Present (Assoc) loop | |
3061ffde | 9624 | Expr := Expression (Assoc); |
9625 | Analyze (Expr); | |
a9f5fea7 | 9626 | |
9627 | if not Error_Posted (Expr) then | |
9628 | Resolve_Iterable_Operation | |
9629 | (Expr, Cursor, T, Chars (First (Choices (Assoc)))); | |
9630 | end if; | |
9631 | ||
b3f8228a | 9632 | Next (Assoc); |
9633 | end loop; | |
9634 | end; | |
3061ffde | 9635 | |
b3f8228a | 9636 | return; |
9637 | ||
d9f6a4ee | 9638 | -- Invariant/Predicate take boolean expressions |
7d20685d | 9639 | |
99378362 | 9640 | when Aspect_Dynamic_Predicate |
9641 | | Aspect_Invariant | |
9642 | | Aspect_Predicate | |
9643 | | Aspect_Static_Predicate | |
9644 | | Aspect_Type_Invariant | |
9645 | => | |
d9f6a4ee | 9646 | T := Standard_Boolean; |
7d20685d | 9647 | |
fdec445e | 9648 | when Aspect_Predicate_Failure => |
9649 | T := Standard_String; | |
9650 | ||
d9f6a4ee | 9651 | -- Here is the list of aspects that don't require delay analysis |
89f1e35c | 9652 | |
99378362 | 9653 | when Aspect_Abstract_State |
9654 | | Aspect_Annotate | |
9655 | | Aspect_Async_Readers | |
9656 | | Aspect_Async_Writers | |
9657 | | Aspect_Constant_After_Elaboration | |
9658 | | Aspect_Contract_Cases | |
9659 | | Aspect_Default_Initial_Condition | |
9660 | | Aspect_Depends | |
9661 | | Aspect_Dimension | |
9662 | | Aspect_Dimension_System | |
9663 | | Aspect_Effective_Reads | |
9664 | | Aspect_Effective_Writes | |
9665 | | Aspect_Extensions_Visible | |
9666 | | Aspect_Ghost | |
9667 | | Aspect_Global | |
9668 | | Aspect_Implicit_Dereference | |
9669 | | Aspect_Initial_Condition | |
9670 | | Aspect_Initializes | |
ebf6f618 | 9671 | | Aspect_Max_Entry_Queue_Depth |
da558db0 | 9672 | | Aspect_Max_Entry_Queue_Length |
99378362 | 9673 | | Aspect_Max_Queue_Length |
adb8ac81 | 9674 | | Aspect_No_Caching |
99378362 | 9675 | | Aspect_Obsolescent |
9676 | | Aspect_Part_Of | |
9677 | | Aspect_Post | |
9678 | | Aspect_Postcondition | |
9679 | | Aspect_Pre | |
9680 | | Aspect_Precondition | |
9681 | | Aspect_Refined_Depends | |
9682 | | Aspect_Refined_Global | |
9683 | | Aspect_Refined_Post | |
9684 | | Aspect_Refined_State | |
9685 | | Aspect_SPARK_Mode | |
9686 | | Aspect_Test_Case | |
9687 | | Aspect_Unimplemented | |
9688 | | Aspect_Volatile_Function | |
9689 | => | |
d9f6a4ee | 9690 | raise Program_Error; |
2b184b2f | 9691 | |
d9f6a4ee | 9692 | end case; |
2b184b2f | 9693 | |
d9f6a4ee | 9694 | -- Do the preanalyze call |
2b184b2f | 9695 | |
d9f6a4ee | 9696 | Preanalyze_Spec_Expression (Expression (ASN), T); |
9697 | end Check_Aspect_At_Freeze_Point; | |
2b184b2f | 9698 | |
d9f6a4ee | 9699 | ----------------------------------- |
9700 | -- Check_Constant_Address_Clause -- | |
9701 | ----------------------------------- | |
2b184b2f | 9702 | |
d9f6a4ee | 9703 | procedure Check_Constant_Address_Clause |
9704 | (Expr : Node_Id; | |
9705 | U_Ent : Entity_Id) | |
9706 | is | |
9707 | procedure Check_At_Constant_Address (Nod : Node_Id); | |
9708 | -- Checks that the given node N represents a name whose 'Address is | |
9709 | -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the | |
9710 | -- address value is the same at the point of declaration of U_Ent and at | |
9711 | -- the time of elaboration of the address clause. | |
84ed7523 | 9712 | |
d9f6a4ee | 9713 | procedure Check_Expr_Constants (Nod : Node_Id); |
9714 | -- Checks that Nod meets the requirements for a constant address clause | |
9715 | -- in the sense of the enclosing procedure. | |
84ed7523 | 9716 | |
d9f6a4ee | 9717 | procedure Check_List_Constants (Lst : List_Id); |
9718 | -- Check that all elements of list Lst meet the requirements for a | |
9719 | -- constant address clause in the sense of the enclosing procedure. | |
84ed7523 | 9720 | |
d9f6a4ee | 9721 | ------------------------------- |
9722 | -- Check_At_Constant_Address -- | |
9723 | ------------------------------- | |
84ed7523 | 9724 | |
d9f6a4ee | 9725 | procedure Check_At_Constant_Address (Nod : Node_Id) is |
9726 | begin | |
9727 | if Is_Entity_Name (Nod) then | |
9728 | if Present (Address_Clause (Entity ((Nod)))) then | |
9729 | Error_Msg_NE | |
9730 | ("invalid address clause for initialized object &!", | |
d9f6a4ee | 9731 | Nod, U_Ent); |
99378362 | 9732 | Error_Msg_NE |
9733 | ("address for& cannot depend on another address clause! " | |
9734 | & "(RM 13.1(22))!", Nod, U_Ent); | |
84ed7523 | 9735 | |
d9f6a4ee | 9736 | elsif In_Same_Source_Unit (Entity (Nod), U_Ent) |
9737 | and then Sloc (U_Ent) < Sloc (Entity (Nod)) | |
9738 | then | |
9739 | Error_Msg_NE | |
9740 | ("invalid address clause for initialized object &!", | |
9741 | Nod, U_Ent); | |
9742 | Error_Msg_Node_2 := U_Ent; | |
9743 | Error_Msg_NE | |
9744 | ("\& must be defined before & (RM 13.1(22))!", | |
9745 | Nod, Entity (Nod)); | |
9746 | end if; | |
7d20685d | 9747 | |
d9f6a4ee | 9748 | elsif Nkind (Nod) = N_Selected_Component then |
9749 | declare | |
9750 | T : constant Entity_Id := Etype (Prefix (Nod)); | |
59f3e675 | 9751 | |
d9f6a4ee | 9752 | begin |
9753 | if (Is_Record_Type (T) | |
9754 | and then Has_Discriminants (T)) | |
9755 | or else | |
9756 | (Is_Access_Type (T) | |
f02a9a9a | 9757 | and then Is_Record_Type (Designated_Type (T)) |
9758 | and then Has_Discriminants (Designated_Type (T))) | |
d9f6a4ee | 9759 | then |
9760 | Error_Msg_NE | |
9761 | ("invalid address clause for initialized object &!", | |
9762 | Nod, U_Ent); | |
9763 | Error_Msg_N | |
99378362 | 9764 | ("\address cannot depend on component of discriminated " |
9765 | & "record (RM 13.1(22))!", Nod); | |
d9f6a4ee | 9766 | else |
9767 | Check_At_Constant_Address (Prefix (Nod)); | |
9768 | end if; | |
9769 | end; | |
89cc7147 | 9770 | |
d9f6a4ee | 9771 | elsif Nkind (Nod) = N_Indexed_Component then |
9772 | Check_At_Constant_Address (Prefix (Nod)); | |
9773 | Check_List_Constants (Expressions (Nod)); | |
89cc7147 | 9774 | |
84ed7523 | 9775 | else |
d9f6a4ee | 9776 | Check_Expr_Constants (Nod); |
84ed7523 | 9777 | end if; |
d9f6a4ee | 9778 | end Check_At_Constant_Address; |
81b424ac | 9779 | |
d9f6a4ee | 9780 | -------------------------- |
9781 | -- Check_Expr_Constants -- | |
9782 | -------------------------- | |
7b9b2f05 | 9783 | |
d9f6a4ee | 9784 | procedure Check_Expr_Constants (Nod : Node_Id) is |
9785 | Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent); | |
9786 | Ent : Entity_Id := Empty; | |
7b9b2f05 | 9787 | |
d9f6a4ee | 9788 | begin |
9789 | if Nkind (Nod) in N_Has_Etype | |
9790 | and then Etype (Nod) = Any_Type | |
7b9b2f05 | 9791 | then |
d9f6a4ee | 9792 | return; |
309c3053 | 9793 | end if; |
9794 | ||
d9f6a4ee | 9795 | case Nkind (Nod) is |
99378362 | 9796 | when N_Empty |
9797 | | N_Error | |
9798 | => | |
d9f6a4ee | 9799 | return; |
7d20685d | 9800 | |
99378362 | 9801 | when N_Expanded_Name |
9802 | | N_Identifier | |
9803 | => | |
d9f6a4ee | 9804 | Ent := Entity (Nod); |
7d20685d | 9805 | |
d9f6a4ee | 9806 | -- We need to look at the original node if it is different |
9807 | -- from the node, since we may have rewritten things and | |
9808 | -- substituted an identifier representing the rewrite. | |
7d20685d | 9809 | |
f53cbecf | 9810 | if Is_Rewrite_Substitution (Nod) then |
d9f6a4ee | 9811 | Check_Expr_Constants (Original_Node (Nod)); |
7d20685d | 9812 | |
d9f6a4ee | 9813 | -- If the node is an object declaration without initial |
9814 | -- value, some code has been expanded, and the expression | |
9815 | -- is not constant, even if the constituents might be | |
9816 | -- acceptable, as in A'Address + offset. | |
7d20685d | 9817 | |
d9f6a4ee | 9818 | if Ekind (Ent) = E_Variable |
9819 | and then | |
9820 | Nkind (Declaration_Node (Ent)) = N_Object_Declaration | |
9821 | and then | |
9822 | No (Expression (Declaration_Node (Ent))) | |
9823 | then | |
9824 | Error_Msg_NE | |
9825 | ("invalid address clause for initialized object &!", | |
9826 | Nod, U_Ent); | |
89f1e35c | 9827 | |
d9f6a4ee | 9828 | -- If entity is constant, it may be the result of expanding |
9829 | -- a check. We must verify that its declaration appears | |
9830 | -- before the object in question, else we also reject the | |
9831 | -- address clause. | |
7d20685d | 9832 | |
d9f6a4ee | 9833 | elsif Ekind (Ent) = E_Constant |
9834 | and then In_Same_Source_Unit (Ent, U_Ent) | |
9835 | and then Sloc (Ent) > Loc_U_Ent | |
9836 | then | |
9837 | Error_Msg_NE | |
9838 | ("invalid address clause for initialized object &!", | |
9839 | Nod, U_Ent); | |
9840 | end if; | |
7d20685d | 9841 | |
d9f6a4ee | 9842 | return; |
9843 | end if; | |
7d20685d | 9844 | |
d9f6a4ee | 9845 | -- Otherwise look at the identifier and see if it is OK |
7d20685d | 9846 | |
d9f6a4ee | 9847 | if Ekind_In (Ent, E_Named_Integer, E_Named_Real) |
9848 | or else Is_Type (Ent) | |
9849 | then | |
9850 | return; | |
7d20685d | 9851 | |
f02a9a9a | 9852 | elsif Ekind_In (Ent, E_Constant, E_In_Parameter) then |
9853 | ||
d9f6a4ee | 9854 | -- This is the case where we must have Ent defined before |
9855 | -- U_Ent. Clearly if they are in different units this | |
9856 | -- requirement is met since the unit containing Ent is | |
9857 | -- already processed. | |
7d20685d | 9858 | |
d9f6a4ee | 9859 | if not In_Same_Source_Unit (Ent, U_Ent) then |
9860 | return; | |
7d20685d | 9861 | |
d9f6a4ee | 9862 | -- Otherwise location of Ent must be before the location |
9863 | -- of U_Ent, that's what prior defined means. | |
7d20685d | 9864 | |
d9f6a4ee | 9865 | elsif Sloc (Ent) < Loc_U_Ent then |
9866 | return; | |
6c545057 | 9867 | |
d9f6a4ee | 9868 | else |
9869 | Error_Msg_NE | |
9870 | ("invalid address clause for initialized object &!", | |
9871 | Nod, U_Ent); | |
9872 | Error_Msg_Node_2 := U_Ent; | |
9873 | Error_Msg_NE | |
9874 | ("\& must be defined before & (RM 13.1(22))!", | |
9875 | Nod, Ent); | |
9876 | end if; | |
37c6e44c | 9877 | |
d9f6a4ee | 9878 | elsif Nkind (Original_Node (Nod)) = N_Function_Call then |
9879 | Check_Expr_Constants (Original_Node (Nod)); | |
6c545057 | 9880 | |
d9f6a4ee | 9881 | else |
9882 | Error_Msg_NE | |
9883 | ("invalid address clause for initialized object &!", | |
9884 | Nod, U_Ent); | |
3cdbaa5a | 9885 | |
d9f6a4ee | 9886 | if Comes_From_Source (Ent) then |
9887 | Error_Msg_NE | |
9888 | ("\reference to variable& not allowed" | |
9889 | & " (RM 13.1(22))!", Nod, Ent); | |
9890 | else | |
9891 | Error_Msg_N | |
9892 | ("non-static expression not allowed" | |
9893 | & " (RM 13.1(22))!", Nod); | |
9894 | end if; | |
9895 | end if; | |
3cdbaa5a | 9896 | |
d9f6a4ee | 9897 | when N_Integer_Literal => |
7f694ca2 | 9898 | |
d9f6a4ee | 9899 | -- If this is a rewritten unchecked conversion, in a system |
9900 | -- where Address is an integer type, always use the base type | |
9901 | -- for a literal value. This is user-friendly and prevents | |
9902 | -- order-of-elaboration issues with instances of unchecked | |
9903 | -- conversion. | |
3cdbaa5a | 9904 | |
d9f6a4ee | 9905 | if Nkind (Original_Node (Nod)) = N_Function_Call then |
9906 | Set_Etype (Nod, Base_Type (Etype (Nod))); | |
9907 | end if; | |
e1cedbae | 9908 | |
99378362 | 9909 | when N_Character_Literal |
9910 | | N_Real_Literal | |
9911 | | N_String_Literal | |
9912 | => | |
d9f6a4ee | 9913 | return; |
7d20685d | 9914 | |
d9f6a4ee | 9915 | when N_Range => |
9916 | Check_Expr_Constants (Low_Bound (Nod)); | |
9917 | Check_Expr_Constants (High_Bound (Nod)); | |
231eb581 | 9918 | |
d9f6a4ee | 9919 | when N_Explicit_Dereference => |
9920 | Check_Expr_Constants (Prefix (Nod)); | |
231eb581 | 9921 | |
d9f6a4ee | 9922 | when N_Indexed_Component => |
9923 | Check_Expr_Constants (Prefix (Nod)); | |
9924 | Check_List_Constants (Expressions (Nod)); | |
7d20685d | 9925 | |
d9f6a4ee | 9926 | when N_Slice => |
9927 | Check_Expr_Constants (Prefix (Nod)); | |
9928 | Check_Expr_Constants (Discrete_Range (Nod)); | |
cb4c311d | 9929 | |
d9f6a4ee | 9930 | when N_Selected_Component => |
9931 | Check_Expr_Constants (Prefix (Nod)); | |
6144c105 | 9932 | |
d9f6a4ee | 9933 | when N_Attribute_Reference => |
9934 | if Nam_In (Attribute_Name (Nod), Name_Address, | |
9935 | Name_Access, | |
9936 | Name_Unchecked_Access, | |
9937 | Name_Unrestricted_Access) | |
9938 | then | |
9939 | Check_At_Constant_Address (Prefix (Nod)); | |
6144c105 | 9940 | |
686edddc | 9941 | -- Normally, System'To_Address will have been transformed into |
9942 | -- an Unchecked_Conversion, but in -gnatc mode, it will not, | |
9943 | -- and we don't want to give an error, because the whole point | |
9944 | -- of 'To_Address is that it is static. | |
9945 | ||
9946 | elsif Attribute_Name (Nod) = Name_To_Address then | |
9947 | pragma Assert (Operating_Mode = Check_Semantics); | |
9948 | null; | |
9949 | ||
d9f6a4ee | 9950 | else |
9951 | Check_Expr_Constants (Prefix (Nod)); | |
9952 | Check_List_Constants (Expressions (Nod)); | |
9953 | end if; | |
a7a4a7c2 | 9954 | |
d9f6a4ee | 9955 | when N_Aggregate => |
9956 | Check_List_Constants (Component_Associations (Nod)); | |
9957 | Check_List_Constants (Expressions (Nod)); | |
7d20685d | 9958 | |
d9f6a4ee | 9959 | when N_Component_Association => |
9960 | Check_Expr_Constants (Expression (Nod)); | |
e1cedbae | 9961 | |
d9f6a4ee | 9962 | when N_Extension_Aggregate => |
9963 | Check_Expr_Constants (Ancestor_Part (Nod)); | |
9964 | Check_List_Constants (Component_Associations (Nod)); | |
9965 | Check_List_Constants (Expressions (Nod)); | |
3cdbaa5a | 9966 | |
d9f6a4ee | 9967 | when N_Null => |
9968 | return; | |
3cdbaa5a | 9969 | |
99378362 | 9970 | when N_Binary_Op |
9971 | | N_Membership_Test | |
9972 | | N_Short_Circuit | |
9973 | => | |
d9f6a4ee | 9974 | Check_Expr_Constants (Left_Opnd (Nod)); |
9975 | Check_Expr_Constants (Right_Opnd (Nod)); | |
e1cedbae | 9976 | |
d9f6a4ee | 9977 | when N_Unary_Op => |
9978 | Check_Expr_Constants (Right_Opnd (Nod)); | |
7f694ca2 | 9979 | |
99378362 | 9980 | when N_Allocator |
9981 | | N_Qualified_Expression | |
9982 | | N_Type_Conversion | |
9983 | | N_Unchecked_Type_Conversion | |
9984 | => | |
d9f6a4ee | 9985 | Check_Expr_Constants (Expression (Nod)); |
47a46747 | 9986 | |
d9f6a4ee | 9987 | when N_Function_Call => |
9988 | if not Is_Pure (Entity (Name (Nod))) then | |
9989 | Error_Msg_NE | |
9990 | ("invalid address clause for initialized object &!", | |
9991 | Nod, U_Ent); | |
7f694ca2 | 9992 | |
d9f6a4ee | 9993 | Error_Msg_NE |
9994 | ("\function & is not pure (RM 13.1(22))!", | |
9995 | Nod, Entity (Name (Nod))); | |
b55f7641 | 9996 | |
d9f6a4ee | 9997 | else |
9998 | Check_List_Constants (Parameter_Associations (Nod)); | |
9999 | end if; | |
b55f7641 | 10000 | |
d9f6a4ee | 10001 | when N_Parameter_Association => |
10002 | Check_Expr_Constants (Explicit_Actual_Parameter (Nod)); | |
7d20685d | 10003 | |
d9f6a4ee | 10004 | when others => |
10005 | Error_Msg_NE | |
10006 | ("invalid address clause for initialized object &!", | |
10007 | Nod, U_Ent); | |
10008 | Error_Msg_NE | |
10009 | ("\must be constant defined before& (RM 13.1(22))!", | |
10010 | Nod, U_Ent); | |
10011 | end case; | |
10012 | end Check_Expr_Constants; | |
7d20685d | 10013 | |
d9f6a4ee | 10014 | -------------------------- |
10015 | -- Check_List_Constants -- | |
10016 | -------------------------- | |
89f1e35c | 10017 | |
d9f6a4ee | 10018 | procedure Check_List_Constants (Lst : List_Id) is |
10019 | Nod1 : Node_Id; | |
7d20685d | 10020 | |
d9f6a4ee | 10021 | begin |
10022 | if Present (Lst) then | |
10023 | Nod1 := First (Lst); | |
10024 | while Present (Nod1) loop | |
10025 | Check_Expr_Constants (Nod1); | |
10026 | Next (Nod1); | |
10027 | end loop; | |
10028 | end if; | |
10029 | end Check_List_Constants; | |
81b424ac | 10030 | |
d9f6a4ee | 10031 | -- Start of processing for Check_Constant_Address_Clause |
81b424ac | 10032 | |
d9f6a4ee | 10033 | begin |
10034 | -- If rep_clauses are to be ignored, no need for legality checks. In | |
9c7948d7 | 10035 | -- particular, no need to pester user about rep clauses that violate the |
10036 | -- rule on constant addresses, given that these clauses will be removed | |
10037 | -- by Freeze before they reach the back end. Similarly in CodePeer mode, | |
10038 | -- we want to relax these checks. | |
7d20685d | 10039 | |
f1a9be43 | 10040 | if not Ignore_Rep_Clauses and not CodePeer_Mode then |
d9f6a4ee | 10041 | Check_Expr_Constants (Expr); |
10042 | end if; | |
10043 | end Check_Constant_Address_Clause; | |
7d20685d | 10044 | |
6653b695 | 10045 | --------------------------- |
10046 | -- Check_Pool_Size_Clash -- | |
10047 | --------------------------- | |
10048 | ||
10049 | procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is | |
10050 | Post : Node_Id; | |
10051 | ||
10052 | begin | |
10053 | -- We need to find out which one came first. Note that in the case of | |
10054 | -- aspects mixed with pragmas there are cases where the processing order | |
10055 | -- is reversed, which is why we do the check here. | |
10056 | ||
10057 | if Sloc (SP) < Sloc (SS) then | |
10058 | Error_Msg_Sloc := Sloc (SP); | |
10059 | Post := SS; | |
10060 | Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent); | |
10061 | ||
10062 | else | |
10063 | Error_Msg_Sloc := Sloc (SS); | |
10064 | Post := SP; | |
10065 | Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent); | |
10066 | end if; | |
10067 | ||
10068 | Error_Msg_N | |
10069 | ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post); | |
10070 | end Check_Pool_Size_Clash; | |
10071 | ||
d9f6a4ee | 10072 | ---------------------------------------- |
10073 | -- Check_Record_Representation_Clause -- | |
10074 | ---------------------------------------- | |
85696508 | 10075 | |
d9f6a4ee | 10076 | procedure Check_Record_Representation_Clause (N : Node_Id) is |
10077 | Loc : constant Source_Ptr := Sloc (N); | |
10078 | Ident : constant Node_Id := Identifier (N); | |
10079 | Rectype : Entity_Id; | |
10080 | Fent : Entity_Id; | |
10081 | CC : Node_Id; | |
10082 | Fbit : Uint; | |
10083 | Lbit : Uint; | |
10084 | Hbit : Uint := Uint_0; | |
10085 | Comp : Entity_Id; | |
10086 | Pcomp : Entity_Id; | |
89f1e35c | 10087 | |
d9f6a4ee | 10088 | Max_Bit_So_Far : Uint; |
10089 | -- Records the maximum bit position so far. If all field positions | |
10090 | -- are monotonically increasing, then we can skip the circuit for | |
10091 | -- checking for overlap, since no overlap is possible. | |
85696508 | 10092 | |
d9f6a4ee | 10093 | Tagged_Parent : Entity_Id := Empty; |
53b51b7a | 10094 | -- This is set in the case of an extension for which we have either a |
10095 | -- size clause or Is_Fully_Repped_Tagged_Type True (indicating that all | |
10096 | -- components are positioned by record representation clauses) on the | |
10097 | -- parent type. In this case we check for overlap between components of | |
10098 | -- this tagged type and the parent component. Tagged_Parent will point | |
10099 | -- to this parent type. For all other cases, Tagged_Parent is Empty. | |
7d20685d | 10100 | |
d39570ea | 10101 | Parent_Last_Bit : Uint := No_Uint; -- init to avoid warning |
d9f6a4ee | 10102 | -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the |
10103 | -- last bit position for any field in the parent type. We only need to | |
10104 | -- check overlap for fields starting below this point. | |
7d20685d | 10105 | |
d9f6a4ee | 10106 | Overlap_Check_Required : Boolean; |
10107 | -- Used to keep track of whether or not an overlap check is required | |
7d20685d | 10108 | |
d9f6a4ee | 10109 | Overlap_Detected : Boolean := False; |
10110 | -- Set True if an overlap is detected | |
d6f39728 | 10111 | |
d9f6a4ee | 10112 | Ccount : Natural := 0; |
10113 | -- Number of component clauses in record rep clause | |
d6f39728 | 10114 | |
d9f6a4ee | 10115 | procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id); |
10116 | -- Given two entities for record components or discriminants, checks | |
10117 | -- if they have overlapping component clauses and issues errors if so. | |
d6f39728 | 10118 | |
d9f6a4ee | 10119 | procedure Find_Component; |
10120 | -- Finds component entity corresponding to current component clause (in | |
10121 | -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin | |
10122 | -- start/stop bits for the field. If there is no matching component or | |
10123 | -- if the matching component does not have a component clause, then | |
10124 | -- that's an error and Comp is set to Empty, but no error message is | |
10125 | -- issued, since the message was already given. Comp is also set to | |
10126 | -- Empty if the current "component clause" is in fact a pragma. | |
d6f39728 | 10127 | |
b3e3fdb9 | 10128 | procedure Record_Hole_Check |
10129 | (Rectype : Entity_Id; After_Last : out Uint; Warn : Boolean); | |
10130 | -- Checks for gaps in the given Rectype. Compute After_Last, the bit | |
10131 | -- number after the last component. Warn is True on the initial call, | |
10132 | -- and warnings are given for gaps. For a type extension, this is called | |
10133 | -- recursively to compute After_Last for the parent type; in this case | |
10134 | -- Warn is False and the warnings are suppressed. | |
10135 | ||
d9f6a4ee | 10136 | ----------------------------- |
10137 | -- Check_Component_Overlap -- | |
10138 | ----------------------------- | |
10139 | ||
10140 | procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is | |
10141 | CC1 : constant Node_Id := Component_Clause (C1_Ent); | |
10142 | CC2 : constant Node_Id := Component_Clause (C2_Ent); | |
d6f39728 | 10143 | |
d6f39728 | 10144 | begin |
d9f6a4ee | 10145 | if Present (CC1) and then Present (CC2) then |
d6f39728 | 10146 | |
d9f6a4ee | 10147 | -- Exclude odd case where we have two tag components in the same |
10148 | -- record, both at location zero. This seems a bit strange, but | |
10149 | -- it seems to happen in some circumstances, perhaps on an error. | |
10150 | ||
10151 | if Nam_In (Chars (C1_Ent), Name_uTag, Name_uTag) then | |
10152 | return; | |
d6f39728 | 10153 | end if; |
10154 | ||
d9f6a4ee | 10155 | -- Here we check if the two fields overlap |
10156 | ||
d6f39728 | 10157 | declare |
d9f6a4ee | 10158 | S1 : constant Uint := Component_Bit_Offset (C1_Ent); |
10159 | S2 : constant Uint := Component_Bit_Offset (C2_Ent); | |
10160 | E1 : constant Uint := S1 + Esize (C1_Ent); | |
10161 | E2 : constant Uint := S2 + Esize (C2_Ent); | |
d6f39728 | 10162 | |
10163 | begin | |
d9f6a4ee | 10164 | if E2 <= S1 or else E1 <= S2 then |
10165 | null; | |
d6f39728 | 10166 | else |
d9f6a4ee | 10167 | Error_Msg_Node_2 := Component_Name (CC2); |
10168 | Error_Msg_Sloc := Sloc (Error_Msg_Node_2); | |
10169 | Error_Msg_Node_1 := Component_Name (CC1); | |
10170 | Error_Msg_N | |
10171 | ("component& overlaps & #", Component_Name (CC1)); | |
10172 | Overlap_Detected := True; | |
d6f39728 | 10173 | end if; |
10174 | end; | |
d6f39728 | 10175 | end if; |
d9f6a4ee | 10176 | end Check_Component_Overlap; |
d6f39728 | 10177 | |
d9f6a4ee | 10178 | -------------------- |
10179 | -- Find_Component -- | |
10180 | -------------------- | |
9dfe12ae | 10181 | |
d9f6a4ee | 10182 | procedure Find_Component is |
9dfe12ae | 10183 | |
d9f6a4ee | 10184 | procedure Search_Component (R : Entity_Id); |
10185 | -- Search components of R for a match. If found, Comp is set | |
9dfe12ae | 10186 | |
d9f6a4ee | 10187 | ---------------------- |
10188 | -- Search_Component -- | |
10189 | ---------------------- | |
e7b2d6bc | 10190 | |
d9f6a4ee | 10191 | procedure Search_Component (R : Entity_Id) is |
10192 | begin | |
10193 | Comp := First_Component_Or_Discriminant (R); | |
10194 | while Present (Comp) loop | |
e7b2d6bc | 10195 | |
d9f6a4ee | 10196 | -- Ignore error of attribute name for component name (we |
10197 | -- already gave an error message for this, so no need to | |
10198 | -- complain here) | |
e7b2d6bc | 10199 | |
d9f6a4ee | 10200 | if Nkind (Component_Name (CC)) = N_Attribute_Reference then |
10201 | null; | |
10202 | else | |
10203 | exit when Chars (Comp) = Chars (Component_Name (CC)); | |
9dfe12ae | 10204 | end if; |
10205 | ||
d9f6a4ee | 10206 | Next_Component_Or_Discriminant (Comp); |
10207 | end loop; | |
10208 | end Search_Component; | |
d6f39728 | 10209 | |
d9f6a4ee | 10210 | -- Start of processing for Find_Component |
d6f39728 | 10211 | |
d9f6a4ee | 10212 | begin |
10213 | -- Return with Comp set to Empty if we have a pragma | |
d6f39728 | 10214 | |
d9f6a4ee | 10215 | if Nkind (CC) = N_Pragma then |
10216 | Comp := Empty; | |
10217 | return; | |
10218 | end if; | |
d6f39728 | 10219 | |
d9f6a4ee | 10220 | -- Search current record for matching component |
d6f39728 | 10221 | |
d9f6a4ee | 10222 | Search_Component (Rectype); |
9dfe12ae | 10223 | |
d9f6a4ee | 10224 | -- If not found, maybe component of base type discriminant that is |
10225 | -- absent from statically constrained first subtype. | |
e7b2d6bc | 10226 | |
d9f6a4ee | 10227 | if No (Comp) then |
10228 | Search_Component (Base_Type (Rectype)); | |
10229 | end if; | |
e7b2d6bc | 10230 | |
d9f6a4ee | 10231 | -- If no component, or the component does not reference the component |
10232 | -- clause in question, then there was some previous error for which | |
10233 | -- we already gave a message, so just return with Comp Empty. | |
d6f39728 | 10234 | |
d9f6a4ee | 10235 | if No (Comp) or else Component_Clause (Comp) /= CC then |
10236 | Check_Error_Detected; | |
10237 | Comp := Empty; | |
93735cb8 | 10238 | |
d9f6a4ee | 10239 | -- Normal case where we have a component clause |
93735cb8 | 10240 | |
d9f6a4ee | 10241 | else |
10242 | Fbit := Component_Bit_Offset (Comp); | |
10243 | Lbit := Fbit + Esize (Comp) - 1; | |
10244 | end if; | |
10245 | end Find_Component; | |
93735cb8 | 10246 | |
b3e3fdb9 | 10247 | ----------------------- |
10248 | -- Record_Hole_Check -- | |
10249 | ----------------------- | |
10250 | ||
10251 | procedure Record_Hole_Check | |
10252 | (Rectype : Entity_Id; After_Last : out Uint; Warn : Boolean) | |
10253 | is | |
10254 | Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype)); | |
10255 | -- Full declaration of record type | |
10256 | ||
10257 | procedure Check_Component_List | |
10258 | (DS : List_Id; | |
10259 | CL : Node_Id; | |
10260 | Sbit : Uint; | |
10261 | Abit : out Uint); | |
10262 | -- Check component list CL for holes. DS is a list of discriminant | |
10263 | -- specifications to be included in the consideration of components. | |
10264 | -- Sbit is the starting bit, which is zero if there are no preceding | |
10265 | -- components (before a variant part, or a parent type, or a tag | |
10266 | -- field). If there are preceding components, Sbit is the bit just | |
10267 | -- after the last such component. Abit is set to the bit just after | |
10268 | -- the last component of DS and CL. | |
10269 | ||
10270 | -------------------------- | |
10271 | -- Check_Component_List -- | |
10272 | -------------------------- | |
10273 | ||
10274 | procedure Check_Component_List | |
10275 | (DS : List_Id; | |
10276 | CL : Node_Id; | |
10277 | Sbit : Uint; | |
10278 | Abit : out Uint) | |
10279 | is | |
10280 | Compl : Integer; | |
10281 | ||
10282 | begin | |
10283 | Compl := Integer (List_Length (Component_Items (CL))); | |
10284 | ||
10285 | if DS /= No_List then | |
10286 | Compl := Compl + Integer (List_Length (DS)); | |
10287 | end if; | |
10288 | ||
10289 | declare | |
10290 | Comps : array (Natural range 0 .. Compl) of Entity_Id; | |
10291 | -- Gather components (zero entry is for sort routine) | |
10292 | ||
10293 | Ncomps : Natural := 0; | |
10294 | -- Number of entries stored in Comps (starting at Comps (1)) | |
10295 | ||
10296 | Citem : Node_Id; | |
10297 | -- One component item or discriminant specification | |
10298 | ||
10299 | Nbit : Uint; | |
10300 | -- Starting bit for next component | |
10301 | ||
10302 | CEnt : Entity_Id; | |
10303 | -- Component entity | |
10304 | ||
10305 | Variant : Node_Id; | |
10306 | -- One variant | |
10307 | ||
10308 | function Lt (Op1, Op2 : Natural) return Boolean; | |
10309 | -- Compare routine for Sort | |
10310 | ||
10311 | procedure Move (From : Natural; To : Natural); | |
10312 | -- Move routine for Sort | |
10313 | ||
10314 | package Sorting is new GNAT.Heap_Sort_G (Move, Lt); | |
10315 | ||
10316 | -------- | |
10317 | -- Lt -- | |
10318 | -------- | |
10319 | ||
10320 | function Lt (Op1, Op2 : Natural) return Boolean is | |
10321 | begin | |
10322 | return Component_Bit_Offset (Comps (Op1)) | |
10323 | < Component_Bit_Offset (Comps (Op2)); | |
10324 | end Lt; | |
10325 | ||
10326 | ---------- | |
10327 | -- Move -- | |
10328 | ---------- | |
10329 | ||
10330 | procedure Move (From : Natural; To : Natural) is | |
10331 | begin | |
10332 | Comps (To) := Comps (From); | |
10333 | end Move; | |
10334 | ||
10335 | begin | |
10336 | -- Gather discriminants into Comp | |
10337 | ||
10338 | if DS /= No_List then | |
10339 | Citem := First (DS); | |
10340 | while Present (Citem) loop | |
10341 | if Nkind (Citem) = N_Discriminant_Specification then | |
10342 | declare | |
10343 | Ent : constant Entity_Id := | |
10344 | Defining_Identifier (Citem); | |
10345 | begin | |
10346 | if Ekind (Ent) = E_Discriminant then | |
10347 | Ncomps := Ncomps + 1; | |
10348 | Comps (Ncomps) := Ent; | |
10349 | end if; | |
10350 | end; | |
10351 | end if; | |
10352 | ||
10353 | Next (Citem); | |
10354 | end loop; | |
10355 | end if; | |
10356 | ||
10357 | -- Gather component entities into Comp | |
10358 | ||
10359 | Citem := First (Component_Items (CL)); | |
10360 | while Present (Citem) loop | |
10361 | if Nkind (Citem) = N_Component_Declaration then | |
10362 | Ncomps := Ncomps + 1; | |
10363 | Comps (Ncomps) := Defining_Identifier (Citem); | |
10364 | end if; | |
10365 | ||
10366 | Next (Citem); | |
10367 | end loop; | |
10368 | ||
10369 | -- Now sort the component entities based on the first bit. | |
10370 | -- Note we already know there are no overlapping components. | |
10371 | ||
10372 | Sorting.Sort (Ncomps); | |
10373 | ||
10374 | -- Loop through entries checking for holes | |
10375 | ||
10376 | Nbit := Sbit; | |
10377 | for J in 1 .. Ncomps loop | |
10378 | CEnt := Comps (J); | |
10379 | ||
10380 | declare | |
10381 | CBO : constant Uint := Component_Bit_Offset (CEnt); | |
10382 | ||
10383 | begin | |
10384 | -- Skip components with unknown offsets | |
10385 | ||
10386 | if CBO /= No_Uint and then CBO >= 0 then | |
10387 | Error_Msg_Uint_1 := CBO - Nbit; | |
10388 | ||
10389 | if Warn and then Error_Msg_Uint_1 > 0 then | |
10390 | Error_Msg_NE | |
10391 | ("?H?^-bit gap before component&", | |
10392 | Component_Name (Component_Clause (CEnt)), | |
10393 | CEnt); | |
10394 | end if; | |
10395 | ||
10396 | Nbit := CBO + Esize (CEnt); | |
10397 | end if; | |
10398 | end; | |
10399 | end loop; | |
10400 | ||
10401 | -- Set Abit to just after the last nonvariant component | |
10402 | ||
10403 | Abit := Nbit; | |
10404 | ||
10405 | -- Process variant parts recursively if present. Set Abit to | |
10406 | -- the maximum for all variant parts. | |
10407 | ||
10408 | if Present (Variant_Part (CL)) then | |
10409 | declare | |
10410 | Var_Start : constant Uint := Nbit; | |
10411 | begin | |
10412 | Variant := First (Variants (Variant_Part (CL))); | |
10413 | while Present (Variant) loop | |
10414 | Check_Component_List | |
10415 | (No_List, Component_List (Variant), Var_Start, Nbit); | |
10416 | Next (Variant); | |
10417 | if Nbit > Abit then | |
10418 | Abit := Nbit; | |
10419 | end if; | |
10420 | end loop; | |
10421 | end; | |
10422 | end if; | |
10423 | end; | |
10424 | end Check_Component_List; | |
10425 | ||
10426 | Sbit : Uint; | |
10427 | -- Starting bit for call to Check_Component_List. Zero for an | |
10428 | -- untagged type. The size of the Tag for a nonderived tagged | |
10429 | -- type. Parent size for a type extension. | |
10430 | ||
10431 | Record_Definition : Node_Id; | |
10432 | -- Record_Definition containing Component_List to pass to | |
10433 | -- Check_Component_List. | |
10434 | ||
10435 | -- Start of processing for Record_Hole_Check | |
10436 | ||
10437 | begin | |
10438 | if Is_Tagged_Type (Rectype) then | |
10439 | Sbit := UI_From_Int (System_Address_Size); | |
10440 | else | |
10441 | Sbit := Uint_0; | |
10442 | end if; | |
10443 | ||
697113bd | 10444 | After_Last := Uint_0; |
10445 | ||
b3e3fdb9 | 10446 | if Nkind (Decl) = N_Full_Type_Declaration then |
10447 | Record_Definition := Type_Definition (Decl); | |
10448 | ||
10449 | -- If we have a record extension, set Sbit to point after the last | |
10450 | -- component of the parent type, by calling Record_Hole_Check | |
10451 | -- recursively. | |
10452 | ||
10453 | if Nkind (Record_Definition) = N_Derived_Type_Definition then | |
10454 | Record_Definition := Record_Extension_Part (Record_Definition); | |
10455 | Record_Hole_Check (Underlying_Type (Parent_Subtype (Rectype)), | |
10456 | After_Last => Sbit, Warn => False); | |
10457 | end if; | |
10458 | ||
10459 | if Nkind (Record_Definition) = N_Record_Definition then | |
10460 | Check_Component_List | |
10461 | (Discriminant_Specifications (Decl), | |
10462 | Component_List (Record_Definition), | |
10463 | Sbit, After_Last); | |
10464 | end if; | |
10465 | end if; | |
10466 | end Record_Hole_Check; | |
10467 | ||
d9f6a4ee | 10468 | -- Start of processing for Check_Record_Representation_Clause |
d6f39728 | 10469 | |
d9f6a4ee | 10470 | begin |
10471 | Find_Type (Ident); | |
10472 | Rectype := Entity (Ident); | |
d6f39728 | 10473 | |
d9f6a4ee | 10474 | if Rectype = Any_Type then |
10475 | return; | |
d9f6a4ee | 10476 | end if; |
d6f39728 | 10477 | |
53b51b7a | 10478 | Rectype := Underlying_Type (Rectype); |
10479 | ||
d9f6a4ee | 10480 | -- See if we have a fully repped derived tagged type |
d6f39728 | 10481 | |
d9f6a4ee | 10482 | declare |
10483 | PS : constant Entity_Id := Parent_Subtype (Rectype); | |
d6f39728 | 10484 | |
d9f6a4ee | 10485 | begin |
53b51b7a | 10486 | if Present (PS) and then Known_Static_RM_Size (PS) then |
10487 | Tagged_Parent := PS; | |
10488 | Parent_Last_Bit := RM_Size (PS) - 1; | |
10489 | ||
10490 | elsif Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then | |
d9f6a4ee | 10491 | Tagged_Parent := PS; |
d6f39728 | 10492 | |
d9f6a4ee | 10493 | -- Find maximum bit of any component of the parent type |
d6f39728 | 10494 | |
d9f6a4ee | 10495 | Parent_Last_Bit := UI_From_Int (System_Address_Size - 1); |
10496 | Pcomp := First_Entity (Tagged_Parent); | |
10497 | while Present (Pcomp) loop | |
10498 | if Ekind_In (Pcomp, E_Discriminant, E_Component) then | |
10499 | if Component_Bit_Offset (Pcomp) /= No_Uint | |
10500 | and then Known_Static_Esize (Pcomp) | |
10501 | then | |
10502 | Parent_Last_Bit := | |
10503 | UI_Max | |
10504 | (Parent_Last_Bit, | |
10505 | Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1); | |
10506 | end if; | |
b7df4cda | 10507 | else |
10508 | ||
10509 | -- Skip anonymous types generated for constrained array | |
10510 | -- or record components. | |
d9f6a4ee | 10511 | |
b7df4cda | 10512 | null; |
d6f39728 | 10513 | end if; |
b7df4cda | 10514 | |
10515 | Next_Entity (Pcomp); | |
d9f6a4ee | 10516 | end loop; |
10517 | end if; | |
10518 | end; | |
d6f39728 | 10519 | |
d9f6a4ee | 10520 | -- All done if no component clauses |
d6f39728 | 10521 | |
d9f6a4ee | 10522 | CC := First (Component_Clauses (N)); |
d6f39728 | 10523 | |
d9f6a4ee | 10524 | if No (CC) then |
10525 | return; | |
10526 | end if; | |
d6f39728 | 10527 | |
d9f6a4ee | 10528 | -- If a tag is present, then create a component clause that places it |
10529 | -- at the start of the record (otherwise gigi may place it after other | |
10530 | -- fields that have rep clauses). | |
d6f39728 | 10531 | |
d9f6a4ee | 10532 | Fent := First_Entity (Rectype); |
d6f39728 | 10533 | |
d9f6a4ee | 10534 | if Nkind (Fent) = N_Defining_Identifier |
10535 | and then Chars (Fent) = Name_uTag | |
10536 | then | |
10537 | Set_Component_Bit_Offset (Fent, Uint_0); | |
10538 | Set_Normalized_Position (Fent, Uint_0); | |
10539 | Set_Normalized_First_Bit (Fent, Uint_0); | |
10540 | Set_Normalized_Position_Max (Fent, Uint_0); | |
10541 | Init_Esize (Fent, System_Address_Size); | |
d6f39728 | 10542 | |
d9f6a4ee | 10543 | Set_Component_Clause (Fent, |
10544 | Make_Component_Clause (Loc, | |
10545 | Component_Name => Make_Identifier (Loc, Name_uTag), | |
d6f39728 | 10546 | |
d9f6a4ee | 10547 | Position => Make_Integer_Literal (Loc, Uint_0), |
10548 | First_Bit => Make_Integer_Literal (Loc, Uint_0), | |
10549 | Last_Bit => | |
10550 | Make_Integer_Literal (Loc, | |
10551 | UI_From_Int (System_Address_Size)))); | |
d6f39728 | 10552 | |
d9f6a4ee | 10553 | Ccount := Ccount + 1; |
10554 | end if; | |
d6f39728 | 10555 | |
d9f6a4ee | 10556 | Max_Bit_So_Far := Uint_Minus_1; |
10557 | Overlap_Check_Required := False; | |
d6f39728 | 10558 | |
d9f6a4ee | 10559 | -- Process the component clauses |
d6f39728 | 10560 | |
d9f6a4ee | 10561 | while Present (CC) loop |
10562 | Find_Component; | |
d6f39728 | 10563 | |
d9f6a4ee | 10564 | if Present (Comp) then |
10565 | Ccount := Ccount + 1; | |
d6f39728 | 10566 | |
d9f6a4ee | 10567 | -- We need a full overlap check if record positions non-monotonic |
d6f39728 | 10568 | |
d9f6a4ee | 10569 | if Fbit <= Max_Bit_So_Far then |
10570 | Overlap_Check_Required := True; | |
10571 | end if; | |
d6f39728 | 10572 | |
d9f6a4ee | 10573 | Max_Bit_So_Far := Lbit; |
d6f39728 | 10574 | |
d9f6a4ee | 10575 | -- Check bit position out of range of specified size |
01cb2726 | 10576 | |
d9f6a4ee | 10577 | if Has_Size_Clause (Rectype) |
10578 | and then RM_Size (Rectype) <= Lbit | |
10579 | then | |
10580 | Error_Msg_N | |
10581 | ("bit number out of range of specified size", | |
10582 | Last_Bit (CC)); | |
d6f39728 | 10583 | |
53b51b7a | 10584 | -- Check for overlap with tag or parent component |
67278d60 | 10585 | |
d9f6a4ee | 10586 | else |
10587 | if Is_Tagged_Type (Rectype) | |
10588 | and then Fbit < System_Address_Size | |
10589 | then | |
10590 | Error_Msg_NE | |
10591 | ("component overlaps tag field of&", | |
10592 | Component_Name (CC), Rectype); | |
10593 | Overlap_Detected := True; | |
53b51b7a | 10594 | |
10595 | elsif Present (Tagged_Parent) | |
10596 | and then Fbit <= Parent_Last_Bit | |
10597 | then | |
10598 | Error_Msg_NE | |
10599 | ("component overlaps parent field of&", | |
10600 | Component_Name (CC), Rectype); | |
10601 | Overlap_Detected := True; | |
d9f6a4ee | 10602 | end if; |
67278d60 | 10603 | |
d9f6a4ee | 10604 | if Hbit < Lbit then |
10605 | Hbit := Lbit; | |
10606 | end if; | |
10607 | end if; | |
d9f6a4ee | 10608 | end if; |
67278d60 | 10609 | |
d9f6a4ee | 10610 | Next (CC); |
10611 | end loop; | |
47495553 | 10612 | |
d9f6a4ee | 10613 | -- Now that we have processed all the component clauses, check for |
10614 | -- overlap. We have to leave this till last, since the components can | |
10615 | -- appear in any arbitrary order in the representation clause. | |
67278d60 | 10616 | |
d9f6a4ee | 10617 | -- We do not need this check if all specified ranges were monotonic, |
10618 | -- as recorded by Overlap_Check_Required being False at this stage. | |
67278d60 | 10619 | |
d9f6a4ee | 10620 | -- This first section checks if there are any overlapping entries at |
10621 | -- all. It does this by sorting all entries and then seeing if there are | |
10622 | -- any overlaps. If there are none, then that is decisive, but if there | |
10623 | -- are overlaps, they may still be OK (they may result from fields in | |
10624 | -- different variants). | |
67278d60 | 10625 | |
d9f6a4ee | 10626 | if Overlap_Check_Required then |
10627 | Overlap_Check1 : declare | |
67278d60 | 10628 | |
d9f6a4ee | 10629 | OC_Fbit : array (0 .. Ccount) of Uint; |
10630 | -- First-bit values for component clauses, the value is the offset | |
10631 | -- of the first bit of the field from start of record. The zero | |
10632 | -- entry is for use in sorting. | |
47495553 | 10633 | |
d9f6a4ee | 10634 | OC_Lbit : array (0 .. Ccount) of Uint; |
10635 | -- Last-bit values for component clauses, the value is the offset | |
10636 | -- of the last bit of the field from start of record. The zero | |
10637 | -- entry is for use in sorting. | |
10638 | ||
10639 | OC_Count : Natural := 0; | |
10640 | -- Count of entries in OC_Fbit and OC_Lbit | |
67278d60 | 10641 | |
d9f6a4ee | 10642 | function OC_Lt (Op1, Op2 : Natural) return Boolean; |
10643 | -- Compare routine for Sort | |
67278d60 | 10644 | |
d9f6a4ee | 10645 | procedure OC_Move (From : Natural; To : Natural); |
10646 | -- Move routine for Sort | |
67278d60 | 10647 | |
d9f6a4ee | 10648 | package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt); |
67278d60 | 10649 | |
d9f6a4ee | 10650 | ----------- |
10651 | -- OC_Lt -- | |
10652 | ----------- | |
67278d60 | 10653 | |
d9f6a4ee | 10654 | function OC_Lt (Op1, Op2 : Natural) return Boolean is |
67278d60 | 10655 | begin |
d9f6a4ee | 10656 | return OC_Fbit (Op1) < OC_Fbit (Op2); |
10657 | end OC_Lt; | |
67278d60 | 10658 | |
d9f6a4ee | 10659 | ------------- |
10660 | -- OC_Move -- | |
10661 | ------------- | |
67278d60 | 10662 | |
d9f6a4ee | 10663 | procedure OC_Move (From : Natural; To : Natural) is |
10664 | begin | |
10665 | OC_Fbit (To) := OC_Fbit (From); | |
10666 | OC_Lbit (To) := OC_Lbit (From); | |
10667 | end OC_Move; | |
67278d60 | 10668 | |
d9f6a4ee | 10669 | -- Start of processing for Overlap_Check |
67278d60 | 10670 | |
67278d60 | 10671 | begin |
d9f6a4ee | 10672 | CC := First (Component_Clauses (N)); |
10673 | while Present (CC) loop | |
67278d60 | 10674 | |
d9f6a4ee | 10675 | -- Exclude component clause already marked in error |
67278d60 | 10676 | |
d9f6a4ee | 10677 | if not Error_Posted (CC) then |
10678 | Find_Component; | |
10679 | ||
10680 | if Present (Comp) then | |
10681 | OC_Count := OC_Count + 1; | |
10682 | OC_Fbit (OC_Count) := Fbit; | |
10683 | OC_Lbit (OC_Count) := Lbit; | |
10684 | end if; | |
67278d60 | 10685 | end if; |
10686 | ||
d9f6a4ee | 10687 | Next (CC); |
67278d60 | 10688 | end loop; |
67278d60 | 10689 | |
d9f6a4ee | 10690 | Sorting.Sort (OC_Count); |
67278d60 | 10691 | |
d9f6a4ee | 10692 | Overlap_Check_Required := False; |
10693 | for J in 1 .. OC_Count - 1 loop | |
10694 | if OC_Lbit (J) >= OC_Fbit (J + 1) then | |
10695 | Overlap_Check_Required := True; | |
10696 | exit; | |
10697 | end if; | |
10698 | end loop; | |
10699 | end Overlap_Check1; | |
10700 | end if; | |
67278d60 | 10701 | |
d9f6a4ee | 10702 | -- If Overlap_Check_Required is still True, then we have to do the full |
10703 | -- scale overlap check, since we have at least two fields that do | |
10704 | -- overlap, and we need to know if that is OK since they are in | |
10705 | -- different variant, or whether we have a definite problem. | |
67278d60 | 10706 | |
d9f6a4ee | 10707 | if Overlap_Check_Required then |
10708 | Overlap_Check2 : declare | |
10709 | C1_Ent, C2_Ent : Entity_Id; | |
10710 | -- Entities of components being checked for overlap | |
67278d60 | 10711 | |
d9f6a4ee | 10712 | Clist : Node_Id; |
10713 | -- Component_List node whose Component_Items are being checked | |
67278d60 | 10714 | |
d9f6a4ee | 10715 | Citem : Node_Id; |
10716 | -- Component declaration for component being checked | |
67278d60 | 10717 | |
d9f6a4ee | 10718 | begin |
10719 | C1_Ent := First_Entity (Base_Type (Rectype)); | |
67278d60 | 10720 | |
d9f6a4ee | 10721 | -- Loop through all components in record. For each component check |
10722 | -- for overlap with any of the preceding elements on the component | |
10723 | -- list containing the component and also, if the component is in | |
10724 | -- a variant, check against components outside the case structure. | |
10725 | -- This latter test is repeated recursively up the variant tree. | |
67278d60 | 10726 | |
d9f6a4ee | 10727 | Main_Component_Loop : while Present (C1_Ent) loop |
10728 | if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then | |
10729 | goto Continue_Main_Component_Loop; | |
10730 | end if; | |
67278d60 | 10731 | |
d9f6a4ee | 10732 | -- Skip overlap check if entity has no declaration node. This |
10733 | -- happens with discriminants in constrained derived types. | |
10734 | -- Possibly we are missing some checks as a result, but that | |
10735 | -- does not seem terribly serious. | |
67278d60 | 10736 | |
d9f6a4ee | 10737 | if No (Declaration_Node (C1_Ent)) then |
10738 | goto Continue_Main_Component_Loop; | |
10739 | end if; | |
67278d60 | 10740 | |
d9f6a4ee | 10741 | Clist := Parent (List_Containing (Declaration_Node (C1_Ent))); |
67278d60 | 10742 | |
d9f6a4ee | 10743 | -- Loop through component lists that need checking. Check the |
10744 | -- current component list and all lists in variants above us. | |
67278d60 | 10745 | |
d9f6a4ee | 10746 | Component_List_Loop : loop |
67278d60 | 10747 | |
d9f6a4ee | 10748 | -- If derived type definition, go to full declaration |
10749 | -- If at outer level, check discriminants if there are any. | |
67278d60 | 10750 | |
d9f6a4ee | 10751 | if Nkind (Clist) = N_Derived_Type_Definition then |
10752 | Clist := Parent (Clist); | |
10753 | end if; | |
67278d60 | 10754 | |
d9f6a4ee | 10755 | -- Outer level of record definition, check discriminants |
67278d60 | 10756 | |
d9f6a4ee | 10757 | if Nkind_In (Clist, N_Full_Type_Declaration, |
10758 | N_Private_Type_Declaration) | |
67278d60 | 10759 | then |
d9f6a4ee | 10760 | if Has_Discriminants (Defining_Identifier (Clist)) then |
10761 | C2_Ent := | |
10762 | First_Discriminant (Defining_Identifier (Clist)); | |
10763 | while Present (C2_Ent) loop | |
10764 | exit when C1_Ent = C2_Ent; | |
10765 | Check_Component_Overlap (C1_Ent, C2_Ent); | |
10766 | Next_Discriminant (C2_Ent); | |
10767 | end loop; | |
10768 | end if; | |
67278d60 | 10769 | |
d9f6a4ee | 10770 | -- Record extension case |
67278d60 | 10771 | |
d9f6a4ee | 10772 | elsif Nkind (Clist) = N_Derived_Type_Definition then |
10773 | Clist := Empty; | |
67278d60 | 10774 | |
d9f6a4ee | 10775 | -- Otherwise check one component list |
67278d60 | 10776 | |
d9f6a4ee | 10777 | else |
10778 | Citem := First (Component_Items (Clist)); | |
10779 | while Present (Citem) loop | |
10780 | if Nkind (Citem) = N_Component_Declaration then | |
10781 | C2_Ent := Defining_Identifier (Citem); | |
10782 | exit when C1_Ent = C2_Ent; | |
10783 | Check_Component_Overlap (C1_Ent, C2_Ent); | |
10784 | end if; | |
67278d60 | 10785 | |
d9f6a4ee | 10786 | Next (Citem); |
10787 | end loop; | |
10788 | end if; | |
67278d60 | 10789 | |
d9f6a4ee | 10790 | -- Check for variants above us (the parent of the Clist can |
10791 | -- be a variant, in which case its parent is a variant part, | |
10792 | -- and the parent of the variant part is a component list | |
10793 | -- whose components must all be checked against the current | |
10794 | -- component for overlap). | |
67278d60 | 10795 | |
d9f6a4ee | 10796 | if Nkind (Parent (Clist)) = N_Variant then |
10797 | Clist := Parent (Parent (Parent (Clist))); | |
67278d60 | 10798 | |
d9f6a4ee | 10799 | -- Check for possible discriminant part in record, this |
10800 | -- is treated essentially as another level in the | |
10801 | -- recursion. For this case the parent of the component | |
10802 | -- list is the record definition, and its parent is the | |
10803 | -- full type declaration containing the discriminant | |
10804 | -- specifications. | |
10805 | ||
10806 | elsif Nkind (Parent (Clist)) = N_Record_Definition then | |
10807 | Clist := Parent (Parent ((Clist))); | |
10808 | ||
10809 | -- If neither of these two cases, we are at the top of | |
10810 | -- the tree. | |
10811 | ||
10812 | else | |
10813 | exit Component_List_Loop; | |
10814 | end if; | |
10815 | end loop Component_List_Loop; | |
67278d60 | 10816 | |
d9f6a4ee | 10817 | <<Continue_Main_Component_Loop>> |
10818 | Next_Entity (C1_Ent); | |
67278d60 | 10819 | |
d9f6a4ee | 10820 | end loop Main_Component_Loop; |
10821 | end Overlap_Check2; | |
67278d60 | 10822 | end if; |
10823 | ||
b3e3fdb9 | 10824 | -- Check for record holes (gaps). We skip this check if overlap was |
10825 | -- detected, since it makes sense for the programmer to fix this | |
10826 | -- error before worrying about warnings. | |
67278d60 | 10827 | |
b3e3fdb9 | 10828 | if Warn_On_Record_Holes and not Overlap_Detected then |
10829 | declare | |
10830 | Ignore : Uint; | |
d9f6a4ee | 10831 | begin |
b3e3fdb9 | 10832 | Record_Hole_Check (Rectype, After_Last => Ignore, Warn => True); |
10833 | end; | |
67278d60 | 10834 | end if; |
10835 | ||
d9f6a4ee | 10836 | -- For records that have component clauses for all components, and whose |
10837 | -- size is less than or equal to 32, we need to know the size in the | |
10838 | -- front end to activate possible packed array processing where the | |
10839 | -- component type is a record. | |
67278d60 | 10840 | |
d9f6a4ee | 10841 | -- At this stage Hbit + 1 represents the first unused bit from all the |
10842 | -- component clauses processed, so if the component clauses are | |
10843 | -- complete, then this is the length of the record. | |
67278d60 | 10844 | |
d9f6a4ee | 10845 | -- For records longer than System.Storage_Unit, and for those where not |
10846 | -- all components have component clauses, the back end determines the | |
10847 | -- length (it may for example be appropriate to round up the size | |
10848 | -- to some convenient boundary, based on alignment considerations, etc). | |
67278d60 | 10849 | |
d9f6a4ee | 10850 | if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then |
67278d60 | 10851 | |
d9f6a4ee | 10852 | -- Nothing to do if at least one component has no component clause |
67278d60 | 10853 | |
d9f6a4ee | 10854 | Comp := First_Component_Or_Discriminant (Rectype); |
10855 | while Present (Comp) loop | |
10856 | exit when No (Component_Clause (Comp)); | |
10857 | Next_Component_Or_Discriminant (Comp); | |
10858 | end loop; | |
67278d60 | 10859 | |
d9f6a4ee | 10860 | -- If we fall out of loop, all components have component clauses |
10861 | -- and so we can set the size to the maximum value. | |
67278d60 | 10862 | |
d9f6a4ee | 10863 | if No (Comp) then |
10864 | Set_RM_Size (Rectype, Hbit + 1); | |
10865 | end if; | |
10866 | end if; | |
10867 | end Check_Record_Representation_Clause; | |
67278d60 | 10868 | |
d9f6a4ee | 10869 | ---------------- |
10870 | -- Check_Size -- | |
10871 | ---------------- | |
67278d60 | 10872 | |
d9f6a4ee | 10873 | procedure Check_Size |
10874 | (N : Node_Id; | |
10875 | T : Entity_Id; | |
10876 | Siz : Uint; | |
10877 | Biased : out Boolean) | |
10878 | is | |
f74a102b | 10879 | procedure Size_Too_Small_Error (Min_Siz : Uint); |
10880 | -- Emit an error concerning illegal size Siz. Min_Siz denotes the | |
10881 | -- minimum size. | |
10882 | ||
10883 | -------------------------- | |
10884 | -- Size_Too_Small_Error -- | |
10885 | -------------------------- | |
10886 | ||
10887 | procedure Size_Too_Small_Error (Min_Siz : Uint) is | |
10888 | begin | |
10889 | -- This error is suppressed in ASIS mode to allow for different ASIS | |
f9906591 | 10890 | -- back ends or ASIS-based tools to query the illegal clause. |
f74a102b | 10891 | |
10892 | if not ASIS_Mode then | |
10893 | Error_Msg_Uint_1 := Min_Siz; | |
a0490886 | 10894 | Error_Msg_NE (Size_Too_Small_Message, N, T); |
f74a102b | 10895 | end if; |
10896 | end Size_Too_Small_Error; | |
10897 | ||
10898 | -- Local variables | |
10899 | ||
d9f6a4ee | 10900 | UT : constant Entity_Id := Underlying_Type (T); |
10901 | M : Uint; | |
67278d60 | 10902 | |
f74a102b | 10903 | -- Start of processing for Check_Size |
10904 | ||
d9f6a4ee | 10905 | begin |
10906 | Biased := False; | |
67278d60 | 10907 | |
f74a102b | 10908 | -- Reject patently improper size values |
67278d60 | 10909 | |
d9f6a4ee | 10910 | if Is_Elementary_Type (T) |
10911 | and then Siz > UI_From_Int (Int'Last) | |
10912 | then | |
10913 | Error_Msg_N ("Size value too large for elementary type", N); | |
67278d60 | 10914 | |
d9f6a4ee | 10915 | if Nkind (Original_Node (N)) = N_Op_Expon then |
10916 | Error_Msg_N | |
10917 | ("\maybe '* was meant, rather than '*'*", Original_Node (N)); | |
10918 | end if; | |
10919 | end if; | |
67278d60 | 10920 | |
d9f6a4ee | 10921 | -- Dismiss generic types |
67278d60 | 10922 | |
d9f6a4ee | 10923 | if Is_Generic_Type (T) |
10924 | or else | |
10925 | Is_Generic_Type (UT) | |
10926 | or else | |
10927 | Is_Generic_Type (Root_Type (UT)) | |
10928 | then | |
10929 | return; | |
67278d60 | 10930 | |
d9f6a4ee | 10931 | -- Guard against previous errors |
67278d60 | 10932 | |
d9f6a4ee | 10933 | elsif No (UT) or else UT = Any_Type then |
10934 | Check_Error_Detected; | |
10935 | return; | |
67278d60 | 10936 | |
d9f6a4ee | 10937 | -- Check case of bit packed array |
67278d60 | 10938 | |
d9f6a4ee | 10939 | elsif Is_Array_Type (UT) |
10940 | and then Known_Static_Component_Size (UT) | |
10941 | and then Is_Bit_Packed_Array (UT) | |
10942 | then | |
10943 | declare | |
10944 | Asiz : Uint; | |
10945 | Indx : Node_Id; | |
10946 | Ityp : Entity_Id; | |
67278d60 | 10947 | |
d9f6a4ee | 10948 | begin |
10949 | Asiz := Component_Size (UT); | |
10950 | Indx := First_Index (UT); | |
10951 | loop | |
10952 | Ityp := Etype (Indx); | |
67278d60 | 10953 | |
d9f6a4ee | 10954 | -- If non-static bound, then we are not in the business of |
10955 | -- trying to check the length, and indeed an error will be | |
10956 | -- issued elsewhere, since sizes of non-static array types | |
10957 | -- cannot be set implicitly or explicitly. | |
67278d60 | 10958 | |
cda40848 | 10959 | if not Is_OK_Static_Subtype (Ityp) then |
d9f6a4ee | 10960 | return; |
10961 | end if; | |
67278d60 | 10962 | |
d9f6a4ee | 10963 | -- Otherwise accumulate next dimension |
67278d60 | 10964 | |
d9f6a4ee | 10965 | Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) - |
10966 | Expr_Value (Type_Low_Bound (Ityp)) + | |
10967 | Uint_1); | |
67278d60 | 10968 | |
d9f6a4ee | 10969 | Next_Index (Indx); |
10970 | exit when No (Indx); | |
10971 | end loop; | |
67278d60 | 10972 | |
d9f6a4ee | 10973 | if Asiz <= Siz then |
10974 | return; | |
67278d60 | 10975 | |
d9f6a4ee | 10976 | else |
f74a102b | 10977 | Size_Too_Small_Error (Asiz); |
d9f6a4ee | 10978 | Set_Esize (T, Asiz); |
10979 | Set_RM_Size (T, Asiz); | |
10980 | end if; | |
10981 | end; | |
67278d60 | 10982 | |
d9f6a4ee | 10983 | -- All other composite types are ignored |
67278d60 | 10984 | |
d9f6a4ee | 10985 | elsif Is_Composite_Type (UT) then |
10986 | return; | |
47495553 | 10987 | |
d9f6a4ee | 10988 | -- For fixed-point types, don't check minimum if type is not frozen, |
10989 | -- since we don't know all the characteristics of the type that can | |
10990 | -- affect the size (e.g. a specified small) till freeze time. | |
47495553 | 10991 | |
f74a102b | 10992 | elsif Is_Fixed_Point_Type (UT) and then not Is_Frozen (UT) then |
d9f6a4ee | 10993 | null; |
47495553 | 10994 | |
d9f6a4ee | 10995 | -- Cases for which a minimum check is required |
47495553 | 10996 | |
d9f6a4ee | 10997 | else |
10998 | -- Ignore if specified size is correct for the type | |
47495553 | 10999 | |
d9f6a4ee | 11000 | if Known_Esize (UT) and then Siz = Esize (UT) then |
11001 | return; | |
11002 | end if; | |
47495553 | 11003 | |
d9f6a4ee | 11004 | -- Otherwise get minimum size |
47495553 | 11005 | |
d9f6a4ee | 11006 | M := UI_From_Int (Minimum_Size (UT)); |
47495553 | 11007 | |
d9f6a4ee | 11008 | if Siz < M then |
47495553 | 11009 | |
d9f6a4ee | 11010 | -- Size is less than minimum size, but one possibility remains |
11011 | -- that we can manage with the new size if we bias the type. | |
47495553 | 11012 | |
d9f6a4ee | 11013 | M := UI_From_Int (Minimum_Size (UT, Biased => True)); |
47495553 | 11014 | |
d9f6a4ee | 11015 | if Siz < M then |
f74a102b | 11016 | Size_Too_Small_Error (M); |
11017 | Set_Esize (T, M); | |
d9f6a4ee | 11018 | Set_RM_Size (T, M); |
11019 | else | |
11020 | Biased := True; | |
11021 | end if; | |
11022 | end if; | |
11023 | end if; | |
11024 | end Check_Size; | |
47495553 | 11025 | |
d9f6a4ee | 11026 | -------------------------- |
11027 | -- Freeze_Entity_Checks -- | |
11028 | -------------------------- | |
47495553 | 11029 | |
d9f6a4ee | 11030 | procedure Freeze_Entity_Checks (N : Node_Id) is |
8cf481c9 | 11031 | procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id); |
11032 | -- Inspect the primitive operations of type Typ and hide all pairs of | |
3118058b | 11033 | -- implicitly declared non-overridden non-fully conformant homographs |
11034 | -- (Ada RM 8.3 12.3/2). | |
8cf481c9 | 11035 | |
11036 | ------------------------------------- | |
11037 | -- Hide_Non_Overridden_Subprograms -- | |
11038 | ------------------------------------- | |
11039 | ||
11040 | procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is | |
11041 | procedure Hide_Matching_Homographs | |
11042 | (Subp_Id : Entity_Id; | |
11043 | Start_Elmt : Elmt_Id); | |
11044 | -- Inspect a list of primitive operations starting with Start_Elmt | |
3118058b | 11045 | -- and find matching implicitly declared non-overridden non-fully |
11046 | -- conformant homographs of Subp_Id. If found, all matches along | |
11047 | -- with Subp_Id are hidden from all visibility. | |
8cf481c9 | 11048 | |
11049 | function Is_Non_Overridden_Or_Null_Procedure | |
11050 | (Subp_Id : Entity_Id) return Boolean; | |
11051 | -- Determine whether subprogram Subp_Id is implicitly declared non- | |
11052 | -- overridden subprogram or an implicitly declared null procedure. | |
11053 | ||
11054 | ------------------------------ | |
11055 | -- Hide_Matching_Homographs -- | |
11056 | ------------------------------ | |
11057 | ||
11058 | procedure Hide_Matching_Homographs | |
11059 | (Subp_Id : Entity_Id; | |
11060 | Start_Elmt : Elmt_Id) | |
11061 | is | |
11062 | Prim : Entity_Id; | |
11063 | Prim_Elmt : Elmt_Id; | |
11064 | ||
11065 | begin | |
11066 | Prim_Elmt := Start_Elmt; | |
11067 | while Present (Prim_Elmt) loop | |
11068 | Prim := Node (Prim_Elmt); | |
11069 | ||
11070 | -- The current primitive is implicitly declared non-overridden | |
3118058b | 11071 | -- non-fully conformant homograph of Subp_Id. Both subprograms |
11072 | -- must be hidden from visibility. | |
8cf481c9 | 11073 | |
11074 | if Chars (Prim) = Chars (Subp_Id) | |
8cf481c9 | 11075 | and then Is_Non_Overridden_Or_Null_Procedure (Prim) |
3118058b | 11076 | and then not Fully_Conformant (Prim, Subp_Id) |
8cf481c9 | 11077 | then |
8c7ee4ac | 11078 | Set_Is_Hidden_Non_Overridden_Subpgm (Prim); |
11079 | Set_Is_Immediately_Visible (Prim, False); | |
11080 | Set_Is_Potentially_Use_Visible (Prim, False); | |
8cf481c9 | 11081 | |
8c7ee4ac | 11082 | Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id); |
11083 | Set_Is_Immediately_Visible (Subp_Id, False); | |
11084 | Set_Is_Potentially_Use_Visible (Subp_Id, False); | |
8cf481c9 | 11085 | end if; |
11086 | ||
11087 | Next_Elmt (Prim_Elmt); | |
11088 | end loop; | |
11089 | end Hide_Matching_Homographs; | |
11090 | ||
11091 | ----------------------------------------- | |
11092 | -- Is_Non_Overridden_Or_Null_Procedure -- | |
11093 | ----------------------------------------- | |
11094 | ||
11095 | function Is_Non_Overridden_Or_Null_Procedure | |
11096 | (Subp_Id : Entity_Id) return Boolean | |
11097 | is | |
11098 | Alias_Id : Entity_Id; | |
11099 | ||
11100 | begin | |
11101 | -- The subprogram is inherited (implicitly declared), it does not | |
11102 | -- override and does not cover a primitive of an interface. | |
11103 | ||
11104 | if Ekind_In (Subp_Id, E_Function, E_Procedure) | |
11105 | and then Present (Alias (Subp_Id)) | |
11106 | and then No (Interface_Alias (Subp_Id)) | |
11107 | and then No (Overridden_Operation (Subp_Id)) | |
11108 | then | |
11109 | Alias_Id := Alias (Subp_Id); | |
11110 | ||
11111 | if Requires_Overriding (Alias_Id) then | |
11112 | return True; | |
11113 | ||
11114 | elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification | |
11115 | and then Null_Present (Parent (Alias_Id)) | |
11116 | then | |
11117 | return True; | |
11118 | end if; | |
11119 | end if; | |
11120 | ||
11121 | return False; | |
11122 | end Is_Non_Overridden_Or_Null_Procedure; | |
11123 | ||
11124 | -- Local variables | |
11125 | ||
11126 | Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ); | |
11127 | Prim : Entity_Id; | |
11128 | Prim_Elmt : Elmt_Id; | |
11129 | ||
11130 | -- Start of processing for Hide_Non_Overridden_Subprograms | |
11131 | ||
11132 | begin | |
3118058b | 11133 | -- Inspect the list of primitives looking for non-overridden |
11134 | -- subprograms. | |
8cf481c9 | 11135 | |
11136 | if Present (Prim_Ops) then | |
11137 | Prim_Elmt := First_Elmt (Prim_Ops); | |
11138 | while Present (Prim_Elmt) loop | |
11139 | Prim := Node (Prim_Elmt); | |
11140 | Next_Elmt (Prim_Elmt); | |
11141 | ||
11142 | if Is_Non_Overridden_Or_Null_Procedure (Prim) then | |
11143 | Hide_Matching_Homographs | |
11144 | (Subp_Id => Prim, | |
11145 | Start_Elmt => Prim_Elmt); | |
11146 | end if; | |
11147 | end loop; | |
11148 | end if; | |
11149 | end Hide_Non_Overridden_Subprograms; | |
11150 | ||
97c23bbe | 11151 | -- Local variables |
8cf481c9 | 11152 | |
d9f6a4ee | 11153 | E : constant Entity_Id := Entity (N); |
47495553 | 11154 | |
0b10029c | 11155 | Nongeneric_Case : constant Boolean := Nkind (N) = N_Freeze_Entity; |
11156 | -- True in nongeneric case. Some of the processing here is skipped | |
d9f6a4ee | 11157 | -- for the generic case since it is not needed. Basically in the |
11158 | -- generic case, we only need to do stuff that might generate error | |
11159 | -- messages or warnings. | |
8cf481c9 | 11160 | |
11161 | -- Start of processing for Freeze_Entity_Checks | |
11162 | ||
d9f6a4ee | 11163 | begin |
11164 | -- Remember that we are processing a freezing entity. Required to | |
11165 | -- ensure correct decoration of internal entities associated with | |
11166 | -- interfaces (see New_Overloaded_Entity). | |
47495553 | 11167 | |
d9f6a4ee | 11168 | Inside_Freezing_Actions := Inside_Freezing_Actions + 1; |
47495553 | 11169 | |
d9f6a4ee | 11170 | -- For tagged types covering interfaces add internal entities that link |
11171 | -- the primitives of the interfaces with the primitives that cover them. | |
11172 | -- Note: These entities were originally generated only when generating | |
11173 | -- code because their main purpose was to provide support to initialize | |
11174 | -- the secondary dispatch tables. They are now generated also when | |
11175 | -- compiling with no code generation to provide ASIS the relationship | |
11176 | -- between interface primitives and tagged type primitives. They are | |
11177 | -- also used to locate primitives covering interfaces when processing | |
11178 | -- generics (see Derive_Subprograms). | |
47495553 | 11179 | |
d9f6a4ee | 11180 | -- This is not needed in the generic case |
47495553 | 11181 | |
d9f6a4ee | 11182 | if Ada_Version >= Ada_2005 |
0b10029c | 11183 | and then Nongeneric_Case |
d9f6a4ee | 11184 | and then Ekind (E) = E_Record_Type |
11185 | and then Is_Tagged_Type (E) | |
11186 | and then not Is_Interface (E) | |
11187 | and then Has_Interfaces (E) | |
11188 | then | |
11189 | -- This would be a good common place to call the routine that checks | |
11190 | -- overriding of interface primitives (and thus factorize calls to | |
11191 | -- Check_Abstract_Overriding located at different contexts in the | |
11192 | -- compiler). However, this is not possible because it causes | |
11193 | -- spurious errors in case of late overriding. | |
47495553 | 11194 | |
d9f6a4ee | 11195 | Add_Internal_Interface_Entities (E); |
11196 | end if; | |
47495553 | 11197 | |
8cf481c9 | 11198 | -- After all forms of overriding have been resolved, a tagged type may |
11199 | -- be left with a set of implicitly declared and possibly erroneous | |
11200 | -- abstract subprograms, null procedures and subprograms that require | |
0c4e0575 | 11201 | -- overriding. If this set contains fully conformant homographs, then |
11202 | -- one is chosen arbitrarily (already done during resolution), otherwise | |
11203 | -- all remaining non-fully conformant homographs are hidden from | |
11204 | -- visibility (Ada RM 8.3 12.3/2). | |
8cf481c9 | 11205 | |
11206 | if Is_Tagged_Type (E) then | |
11207 | Hide_Non_Overridden_Subprograms (E); | |
11208 | end if; | |
11209 | ||
d9f6a4ee | 11210 | -- Check CPP types |
47495553 | 11211 | |
d9f6a4ee | 11212 | if Ekind (E) = E_Record_Type |
11213 | and then Is_CPP_Class (E) | |
11214 | and then Is_Tagged_Type (E) | |
11215 | and then Tagged_Type_Expansion | |
d9f6a4ee | 11216 | then |
11217 | if CPP_Num_Prims (E) = 0 then | |
47495553 | 11218 | |
d9f6a4ee | 11219 | -- If the CPP type has user defined components then it must import |
11220 | -- primitives from C++. This is required because if the C++ class | |
11221 | -- has no primitives then the C++ compiler does not added the _tag | |
11222 | -- component to the type. | |
47495553 | 11223 | |
d9f6a4ee | 11224 | if First_Entity (E) /= Last_Entity (E) then |
11225 | Error_Msg_N | |
11226 | ("'C'P'P type must import at least one primitive from C++??", | |
11227 | E); | |
11228 | end if; | |
11229 | end if; | |
47495553 | 11230 | |
d9f6a4ee | 11231 | -- Check that all its primitives are abstract or imported from C++. |
11232 | -- Check also availability of the C++ constructor. | |
47495553 | 11233 | |
d9f6a4ee | 11234 | declare |
11235 | Has_Constructors : constant Boolean := Has_CPP_Constructors (E); | |
11236 | Elmt : Elmt_Id; | |
11237 | Error_Reported : Boolean := False; | |
11238 | Prim : Node_Id; | |
47495553 | 11239 | |
d9f6a4ee | 11240 | begin |
11241 | Elmt := First_Elmt (Primitive_Operations (E)); | |
11242 | while Present (Elmt) loop | |
11243 | Prim := Node (Elmt); | |
47495553 | 11244 | |
d9f6a4ee | 11245 | if Comes_From_Source (Prim) then |
11246 | if Is_Abstract_Subprogram (Prim) then | |
11247 | null; | |
47495553 | 11248 | |
d9f6a4ee | 11249 | elsif not Is_Imported (Prim) |
11250 | or else Convention (Prim) /= Convention_CPP | |
11251 | then | |
11252 | Error_Msg_N | |
11253 | ("primitives of 'C'P'P types must be imported from C++ " | |
11254 | & "or abstract??", Prim); | |
47495553 | 11255 | |
d9f6a4ee | 11256 | elsif not Has_Constructors |
11257 | and then not Error_Reported | |
11258 | then | |
11259 | Error_Msg_Name_1 := Chars (E); | |
11260 | Error_Msg_N | |
11261 | ("??'C'P'P constructor required for type %", Prim); | |
11262 | Error_Reported := True; | |
11263 | end if; | |
11264 | end if; | |
47495553 | 11265 | |
d9f6a4ee | 11266 | Next_Elmt (Elmt); |
11267 | end loop; | |
11268 | end; | |
11269 | end if; | |
47495553 | 11270 | |
d9f6a4ee | 11271 | -- Check Ada derivation of CPP type |
47495553 | 11272 | |
30ab103b | 11273 | if Expander_Active -- why? losing errors in -gnatc mode??? |
11274 | and then Present (Etype (E)) -- defend against errors | |
d9f6a4ee | 11275 | and then Tagged_Type_Expansion |
11276 | and then Ekind (E) = E_Record_Type | |
11277 | and then Etype (E) /= E | |
11278 | and then Is_CPP_Class (Etype (E)) | |
11279 | and then CPP_Num_Prims (Etype (E)) > 0 | |
11280 | and then not Is_CPP_Class (E) | |
11281 | and then not Has_CPP_Constructors (Etype (E)) | |
11282 | then | |
11283 | -- If the parent has C++ primitives but it has no constructor then | |
11284 | -- check that all the primitives are overridden in this derivation; | |
11285 | -- otherwise the constructor of the parent is needed to build the | |
11286 | -- dispatch table. | |
47495553 | 11287 | |
d9f6a4ee | 11288 | declare |
11289 | Elmt : Elmt_Id; | |
11290 | Prim : Node_Id; | |
47495553 | 11291 | |
11292 | begin | |
d9f6a4ee | 11293 | Elmt := First_Elmt (Primitive_Operations (E)); |
11294 | while Present (Elmt) loop | |
11295 | Prim := Node (Elmt); | |
47495553 | 11296 | |
d9f6a4ee | 11297 | if not Is_Abstract_Subprogram (Prim) |
11298 | and then No (Interface_Alias (Prim)) | |
11299 | and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E | |
47495553 | 11300 | then |
d9f6a4ee | 11301 | Error_Msg_Name_1 := Chars (Etype (E)); |
11302 | Error_Msg_N | |
11303 | ("'C'P'P constructor required for parent type %", E); | |
11304 | exit; | |
47495553 | 11305 | end if; |
d9f6a4ee | 11306 | |
11307 | Next_Elmt (Elmt); | |
11308 | end loop; | |
11309 | end; | |
47495553 | 11310 | end if; |
11311 | ||
d9f6a4ee | 11312 | Inside_Freezing_Actions := Inside_Freezing_Actions - 1; |
67278d60 | 11313 | |
97c23bbe | 11314 | -- If we have a type with predicates, build predicate function. This is |
11315 | -- not needed in the generic case, nor within TSS subprograms and other | |
c10c3c88 | 11316 | -- predefined primitives. For a derived type, ensure that the parent |
11317 | -- type is already frozen so that its predicate function has been | |
11318 | -- constructed already. This is necessary if the parent is declared | |
11319 | -- in a nested package and its own freeze point has not been reached. | |
67278d60 | 11320 | |
97c23bbe | 11321 | if Is_Type (E) |
0b10029c | 11322 | and then Nongeneric_Case |
ea822fd4 | 11323 | and then not Within_Internal_Subprogram |
97c23bbe | 11324 | and then Has_Predicates (E) |
ea822fd4 | 11325 | then |
c10c3c88 | 11326 | declare |
11327 | Atyp : constant Entity_Id := Nearest_Ancestor (E); | |
11328 | begin | |
11329 | if Present (Atyp) | |
11330 | and then Has_Predicates (Atyp) | |
11331 | and then not Is_Frozen (Atyp) | |
11332 | then | |
11333 | Freeze_Before (N, Atyp); | |
11334 | end if; | |
11335 | end; | |
11336 | ||
d9f6a4ee | 11337 | Build_Predicate_Functions (E, N); |
11338 | end if; | |
67278d60 | 11339 | |
d9f6a4ee | 11340 | -- If type has delayed aspects, this is where we do the preanalysis at |
11341 | -- the freeze point, as part of the consistent visibility check. Note | |
11342 | -- that this must be done after calling Build_Predicate_Functions or | |
11343 | -- Build_Invariant_Procedure since these subprograms fix occurrences of | |
11344 | -- the subtype name in the saved expression so that they will not cause | |
11345 | -- trouble in the preanalysis. | |
67278d60 | 11346 | |
61989dbb | 11347 | -- This is also not needed in the generic case |
d9f6a4ee | 11348 | |
0b10029c | 11349 | if Nongeneric_Case |
61989dbb | 11350 | and then Has_Delayed_Aspects (E) |
d9f6a4ee | 11351 | and then Scope (E) = Current_Scope |
11352 | then | |
d9f6a4ee | 11353 | declare |
92038d64 | 11354 | A_Id : Aspect_Id; |
d9f6a4ee | 11355 | Ritem : Node_Id; |
11356 | ||
11357 | begin | |
11358 | -- Look for aspect specification entries for this entity | |
67278d60 | 11359 | |
d9f6a4ee | 11360 | Ritem := First_Rep_Item (E); |
11361 | while Present (Ritem) loop | |
11362 | if Nkind (Ritem) = N_Aspect_Specification | |
11363 | and then Entity (Ritem) = E | |
11364 | and then Is_Delayed_Aspect (Ritem) | |
11365 | then | |
b4dcd57e | 11366 | A_Id := Get_Aspect_Id (Ritem); |
92038d64 | 11367 | |
b4dcd57e | 11368 | if A_Id = Aspect_Dynamic_Predicate |
796ad64d | 11369 | or else A_Id = Aspect_Predicate |
b4dcd57e | 11370 | or else A_Id = Aspect_Priority |
dcccb125 | 11371 | or else A_Id = Aspect_CPU |
b4dcd57e | 11372 | then |
11373 | -- Retrieve the visibility to components and discriminants | |
11374 | -- in order to properly analyze the aspects. | |
11375 | ||
11376 | Push_Type (E); | |
11377 | Check_Aspect_At_Freeze_Point (Ritem); | |
11378 | Pop_Type (E); | |
11379 | ||
11380 | else | |
11381 | Check_Aspect_At_Freeze_Point (Ritem); | |
11382 | end if; | |
d9f6a4ee | 11383 | end if; |
67278d60 | 11384 | |
d9f6a4ee | 11385 | Next_Rep_Item (Ritem); |
11386 | end loop; | |
11387 | end; | |
67278d60 | 11388 | |
67278d60 | 11389 | end if; |
67278d60 | 11390 | |
92038d64 | 11391 | -- For a record type, deal with variant parts. This has to be delayed to |
11392 | -- this point, because of the issue of statically predicated subtypes, | |
11393 | -- which we have to ensure are frozen before checking choices, since we | |
11394 | -- need to have the static choice list set. | |
d6f39728 | 11395 | |
d9f6a4ee | 11396 | if Is_Record_Type (E) then |
11397 | Check_Variant_Part : declare | |
11398 | D : constant Node_Id := Declaration_Node (E); | |
11399 | T : Node_Id; | |
11400 | C : Node_Id; | |
11401 | VP : Node_Id; | |
d6f39728 | 11402 | |
d9f6a4ee | 11403 | Others_Present : Boolean; |
11404 | pragma Warnings (Off, Others_Present); | |
11405 | -- Indicates others present, not used in this case | |
d6f39728 | 11406 | |
d9f6a4ee | 11407 | procedure Non_Static_Choice_Error (Choice : Node_Id); |
11408 | -- Error routine invoked by the generic instantiation below when | |
11409 | -- the variant part has a non static choice. | |
f117057b | 11410 | |
d9f6a4ee | 11411 | procedure Process_Declarations (Variant : Node_Id); |
11412 | -- Processes declarations associated with a variant. We analyzed | |
11413 | -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part), | |
11414 | -- but we still need the recursive call to Check_Choices for any | |
11415 | -- nested variant to get its choices properly processed. This is | |
11416 | -- also where we expand out the choices if expansion is active. | |
1f526845 | 11417 | |
d9f6a4ee | 11418 | package Variant_Choices_Processing is new |
11419 | Generic_Check_Choices | |
11420 | (Process_Empty_Choice => No_OP, | |
11421 | Process_Non_Static_Choice => Non_Static_Choice_Error, | |
11422 | Process_Associated_Node => Process_Declarations); | |
11423 | use Variant_Choices_Processing; | |
f117057b | 11424 | |
d9f6a4ee | 11425 | ----------------------------- |
11426 | -- Non_Static_Choice_Error -- | |
11427 | ----------------------------- | |
d6f39728 | 11428 | |
d9f6a4ee | 11429 | procedure Non_Static_Choice_Error (Choice : Node_Id) is |
11430 | begin | |
11431 | Flag_Non_Static_Expr | |
11432 | ("choice given in variant part is not static!", Choice); | |
11433 | end Non_Static_Choice_Error; | |
d6f39728 | 11434 | |
d9f6a4ee | 11435 | -------------------------- |
11436 | -- Process_Declarations -- | |
11437 | -------------------------- | |
dba36b60 | 11438 | |
d9f6a4ee | 11439 | procedure Process_Declarations (Variant : Node_Id) is |
11440 | CL : constant Node_Id := Component_List (Variant); | |
11441 | VP : Node_Id; | |
dba36b60 | 11442 | |
d9f6a4ee | 11443 | begin |
11444 | -- Check for static predicate present in this variant | |
ea61a7ea | 11445 | |
d9f6a4ee | 11446 | if Has_SP_Choice (Variant) then |
ea61a7ea | 11447 | |
d9f6a4ee | 11448 | -- Here we expand. You might expect to find this call in |
11449 | -- Expand_N_Variant_Part, but that is called when we first | |
11450 | -- see the variant part, and we cannot do this expansion | |
11451 | -- earlier than the freeze point, since for statically | |
11452 | -- predicated subtypes, the predicate is not known till | |
11453 | -- the freeze point. | |
ea61a7ea | 11454 | |
d9f6a4ee | 11455 | -- Furthermore, we do this expansion even if the expander |
11456 | -- is not active, because other semantic processing, e.g. | |
11457 | -- for aggregates, requires the expanded list of choices. | |
ea61a7ea | 11458 | |
d9f6a4ee | 11459 | -- If the expander is not active, then we can't just clobber |
11460 | -- the list since it would invalidate the ASIS -gnatct tree. | |
11461 | -- So we have to rewrite the variant part with a Rewrite | |
11462 | -- call that replaces it with a copy and clobber the copy. | |
11463 | ||
11464 | if not Expander_Active then | |
11465 | declare | |
11466 | NewV : constant Node_Id := New_Copy (Variant); | |
11467 | begin | |
11468 | Set_Discrete_Choices | |
11469 | (NewV, New_Copy_List (Discrete_Choices (Variant))); | |
11470 | Rewrite (Variant, NewV); | |
11471 | end; | |
11472 | end if; | |
11473 | ||
11474 | Expand_Static_Predicates_In_Choices (Variant); | |
ea61a7ea | 11475 | end if; |
11476 | ||
d9f6a4ee | 11477 | -- We don't need to worry about the declarations in the variant |
11478 | -- (since they were analyzed by Analyze_Choices when we first | |
11479 | -- encountered the variant), but we do need to take care of | |
11480 | -- expansion of any nested variants. | |
ea61a7ea | 11481 | |
d9f6a4ee | 11482 | if not Null_Present (CL) then |
11483 | VP := Variant_Part (CL); | |
ea61a7ea | 11484 | |
d9f6a4ee | 11485 | if Present (VP) then |
11486 | Check_Choices | |
11487 | (VP, Variants (VP), Etype (Name (VP)), Others_Present); | |
11488 | end if; | |
11489 | end if; | |
11490 | end Process_Declarations; | |
ea61a7ea | 11491 | |
d9f6a4ee | 11492 | -- Start of processing for Check_Variant_Part |
b9e61b2a | 11493 | |
d9f6a4ee | 11494 | begin |
11495 | -- Find component list | |
ea61a7ea | 11496 | |
d9f6a4ee | 11497 | C := Empty; |
ea61a7ea | 11498 | |
d9f6a4ee | 11499 | if Nkind (D) = N_Full_Type_Declaration then |
11500 | T := Type_Definition (D); | |
ea61a7ea | 11501 | |
d9f6a4ee | 11502 | if Nkind (T) = N_Record_Definition then |
11503 | C := Component_List (T); | |
d6f39728 | 11504 | |
d9f6a4ee | 11505 | elsif Nkind (T) = N_Derived_Type_Definition |
11506 | and then Present (Record_Extension_Part (T)) | |
11507 | then | |
11508 | C := Component_List (Record_Extension_Part (T)); | |
11509 | end if; | |
11510 | end if; | |
d6f39728 | 11511 | |
d9f6a4ee | 11512 | -- Case of variant part present |
d6f39728 | 11513 | |
d9f6a4ee | 11514 | if Present (C) and then Present (Variant_Part (C)) then |
11515 | VP := Variant_Part (C); | |
ea61a7ea | 11516 | |
d9f6a4ee | 11517 | -- Check choices |
ea61a7ea | 11518 | |
d9f6a4ee | 11519 | Check_Choices |
11520 | (VP, Variants (VP), Etype (Name (VP)), Others_Present); | |
ea61a7ea | 11521 | |
d9f6a4ee | 11522 | -- If the last variant does not contain the Others choice, |
11523 | -- replace it with an N_Others_Choice node since Gigi always | |
11524 | -- wants an Others. Note that we do not bother to call Analyze | |
11525 | -- on the modified variant part, since its only effect would be | |
11526 | -- to compute the Others_Discrete_Choices node laboriously, and | |
11527 | -- of course we already know the list of choices corresponding | |
39a0c1d3 | 11528 | -- to the others choice (it's the list we're replacing). |
d6f39728 | 11529 | |
d9f6a4ee | 11530 | -- We only want to do this if the expander is active, since |
39a0c1d3 | 11531 | -- we do not want to clobber the ASIS tree. |
d6f39728 | 11532 | |
d9f6a4ee | 11533 | if Expander_Active then |
11534 | declare | |
11535 | Last_Var : constant Node_Id := | |
11536 | Last_Non_Pragma (Variants (VP)); | |
d6f39728 | 11537 | |
d9f6a4ee | 11538 | Others_Node : Node_Id; |
d6f39728 | 11539 | |
d9f6a4ee | 11540 | begin |
11541 | if Nkind (First (Discrete_Choices (Last_Var))) /= | |
11542 | N_Others_Choice | |
11543 | then | |
11544 | Others_Node := Make_Others_Choice (Sloc (Last_Var)); | |
11545 | Set_Others_Discrete_Choices | |
11546 | (Others_Node, Discrete_Choices (Last_Var)); | |
11547 | Set_Discrete_Choices | |
11548 | (Last_Var, New_List (Others_Node)); | |
11549 | end if; | |
11550 | end; | |
11551 | end if; | |
d6f39728 | 11552 | end if; |
d9f6a4ee | 11553 | end Check_Variant_Part; |
d6f39728 | 11554 | end if; |
d9f6a4ee | 11555 | end Freeze_Entity_Checks; |
d6f39728 | 11556 | |
11557 | ------------------------- | |
11558 | -- Get_Alignment_Value -- | |
11559 | ------------------------- | |
11560 | ||
11561 | function Get_Alignment_Value (Expr : Node_Id) return Uint is | |
f5d97bf5 | 11562 | Align : constant Uint := Static_Integer (Expr); |
f74a102b | 11563 | |
f5d97bf5 | 11564 | begin |
11565 | if Align = No_Uint then | |
11566 | return No_Uint; | |
11567 | ||
551a164c | 11568 | elsif Align < 0 then |
f74a102b | 11569 | |
f74a102b | 11570 | -- This error is suppressed in ASIS mode to allow for different ASIS |
f9906591 | 11571 | -- back ends or ASIS-based tools to query the illegal clause. |
f74a102b | 11572 | |
11573 | if not ASIS_Mode then | |
11574 | Error_Msg_N ("alignment value must be positive", Expr); | |
11575 | end if; | |
f74a102b | 11576 | |
d6f39728 | 11577 | return No_Uint; |
11578 | ||
551a164c | 11579 | -- If Alignment is specified to be 0, we treat it the same as 1 |
11580 | ||
11581 | elsif Align = 0 then | |
11582 | return Uint_1; | |
11583 | ||
d6f39728 | 11584 | else |
11585 | for J in Int range 0 .. 64 loop | |
11586 | declare | |
11587 | M : constant Uint := Uint_2 ** J; | |
11588 | ||
11589 | begin | |
11590 | exit when M = Align; | |
11591 | ||
11592 | if M > Align then | |
f5d97bf5 | 11593 | |
11594 | -- This error is suppressed in ASIS mode to allow for | |
f9906591 | 11595 | -- different ASIS back ends or ASIS-based tools to query the |
f5d97bf5 | 11596 | -- illegal clause. |
11597 | ||
11598 | if not ASIS_Mode then | |
11599 | Error_Msg_N ("alignment value must be power of 2", Expr); | |
11600 | end if; | |
11601 | ||
d6f39728 | 11602 | return No_Uint; |
11603 | end if; | |
11604 | end; | |
11605 | end loop; | |
11606 | ||
11607 | return Align; | |
11608 | end if; | |
11609 | end Get_Alignment_Value; | |
11610 | ||
99a2d5bd | 11611 | ------------------------------------- |
11612 | -- Inherit_Aspects_At_Freeze_Point -- | |
11613 | ------------------------------------- | |
11614 | ||
11615 | procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is | |
11616 | function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11617 | (Rep_Item : Node_Id) return Boolean; | |
11618 | -- This routine checks if Rep_Item is either a pragma or an aspect | |
11619 | -- specification node whose correponding pragma (if any) is present in | |
11620 | -- the Rep Item chain of the entity it has been specified to. | |
11621 | ||
724be312 | 11622 | function Rep_Item_Entity (Rep_Item : Node_Id) return Entity_Id; |
11623 | -- Return the entity for which Rep_Item is specified | |
11624 | ||
c6056dd1 | 11625 | -------------------------------------------------- |
11626 | -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item -- | |
11627 | -------------------------------------------------- | |
11628 | ||
11629 | function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11630 | (Rep_Item : Node_Id) return Boolean | |
11631 | is | |
11632 | begin | |
11633 | return | |
11634 | Nkind (Rep_Item) = N_Pragma | |
11635 | or else Present_In_Rep_Item | |
11636 | (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item)); | |
11637 | end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item; | |
11638 | ||
724be312 | 11639 | --------------------- |
11640 | -- Rep_Item_Entity -- | |
11641 | --------------------- | |
11642 | ||
11643 | function Rep_Item_Entity (Rep_Item : Node_Id) return Entity_Id is | |
11644 | begin | |
11645 | if Nkind (Rep_Item) = N_Aspect_Specification then | |
11646 | return Entity (Rep_Item); | |
11647 | ||
11648 | else | |
11649 | pragma Assert (Nkind_In (Rep_Item, | |
c6056dd1 | 11650 | N_Attribute_Definition_Clause, |
11651 | N_Pragma)); | |
724be312 | 11652 | return Entity (Name (Rep_Item)); |
11653 | end if; | |
11654 | end Rep_Item_Entity; | |
11655 | ||
29a9d4be | 11656 | -- Start of processing for Inherit_Aspects_At_Freeze_Point |
11657 | ||
99a2d5bd | 11658 | begin |
11659 | -- A representation item is either subtype-specific (Size and Alignment | |
06d78d4c | 11660 | -- clauses) or type-related (all others). Subtype-specific aspects may |
29a9d4be | 11661 | -- differ for different subtypes of the same type (RM 13.1.8). |
99a2d5bd | 11662 | |
11663 | -- A derived type inherits each type-related representation aspect of | |
11664 | -- its parent type that was directly specified before the declaration of | |
29a9d4be | 11665 | -- the derived type (RM 13.1.15). |
99a2d5bd | 11666 | |
11667 | -- A derived subtype inherits each subtype-specific representation | |
11668 | -- aspect of its parent subtype that was directly specified before the | |
29a9d4be | 11669 | -- declaration of the derived type (RM 13.1.15). |
99a2d5bd | 11670 | |
11671 | -- The general processing involves inheriting a representation aspect | |
11672 | -- from a parent type whenever the first rep item (aspect specification, | |
11673 | -- attribute definition clause, pragma) corresponding to the given | |
11674 | -- representation aspect in the rep item chain of Typ, if any, isn't | |
11675 | -- directly specified to Typ but to one of its parents. | |
11676 | ||
11677 | -- ??? Note that, for now, just a limited number of representation | |
29a9d4be | 11678 | -- aspects have been inherited here so far. Many of them are |
11679 | -- still inherited in Sem_Ch3. This will be fixed soon. Here is | |
11680 | -- a non- exhaustive list of aspects that likely also need to | |
11681 | -- be moved to this routine: Alignment, Component_Alignment, | |
11682 | -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates, | |
99a2d5bd | 11683 | -- Preelaborable_Initialization, RM_Size and Small. |
11684 | ||
8b6e9bf2 | 11685 | -- In addition, Convention must be propagated from base type to subtype, |
11686 | -- because the subtype may have been declared on an incomplete view. | |
11687 | ||
99a2d5bd | 11688 | if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then |
11689 | return; | |
11690 | end if; | |
11691 | ||
11692 | -- Ada_05/Ada_2005 | |
11693 | ||
11694 | if not Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005, False) | |
11695 | and then Has_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005) | |
11696 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11697 | (Get_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005)) | |
11698 | then | |
11699 | Set_Is_Ada_2005_Only (Typ); | |
11700 | end if; | |
11701 | ||
11702 | -- Ada_12/Ada_2012 | |
11703 | ||
11704 | if not Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012, False) | |
11705 | and then Has_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012) | |
11706 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11707 | (Get_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012)) | |
11708 | then | |
11709 | Set_Is_Ada_2012_Only (Typ); | |
11710 | end if; | |
11711 | ||
11712 | -- Atomic/Shared | |
11713 | ||
11714 | if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False) | |
11715 | and then Has_Rep_Pragma (Typ, Name_Atomic, Name_Shared) | |
11716 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11717 | (Get_Rep_Item (Typ, Name_Atomic, Name_Shared)) | |
11718 | then | |
11719 | Set_Is_Atomic (Typ); | |
99a2d5bd | 11720 | Set_Is_Volatile (Typ); |
4bf2acc9 | 11721 | Set_Treat_As_Volatile (Typ); |
99a2d5bd | 11722 | end if; |
11723 | ||
8b6e9bf2 | 11724 | -- Convention |
11725 | ||
7ac4254e | 11726 | if Is_Record_Type (Typ) |
11727 | and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ)) | |
11728 | then | |
8b6e9bf2 | 11729 | Set_Convention (Typ, Convention (Base_Type (Typ))); |
11730 | end if; | |
11731 | ||
29a9d4be | 11732 | -- Default_Component_Value |
99a2d5bd | 11733 | |
81c2bc19 | 11734 | -- Verify that there is no rep_item declared for the type, and there |
11735 | -- is one coming from an ancestor. | |
11736 | ||
99a2d5bd | 11737 | if Is_Array_Type (Typ) |
f3d70f08 | 11738 | and then Is_Base_Type (Typ) |
81c2bc19 | 11739 | and then not Has_Rep_Item (Typ, Name_Default_Component_Value, False) |
99a2d5bd | 11740 | and then Has_Rep_Item (Typ, Name_Default_Component_Value) |
11741 | then | |
11742 | Set_Default_Aspect_Component_Value (Typ, | |
11743 | Default_Aspect_Component_Value | |
11744 | (Entity (Get_Rep_Item (Typ, Name_Default_Component_Value)))); | |
11745 | end if; | |
11746 | ||
29a9d4be | 11747 | -- Default_Value |
99a2d5bd | 11748 | |
11749 | if Is_Scalar_Type (Typ) | |
f3d70f08 | 11750 | and then Is_Base_Type (Typ) |
81c2bc19 | 11751 | and then not Has_Rep_Item (Typ, Name_Default_Value, False) |
99a2d5bd | 11752 | and then Has_Rep_Item (Typ, Name_Default_Value) |
11753 | then | |
81c2bc19 | 11754 | Set_Has_Default_Aspect (Typ); |
99a2d5bd | 11755 | Set_Default_Aspect_Value (Typ, |
11756 | Default_Aspect_Value | |
11757 | (Entity (Get_Rep_Item (Typ, Name_Default_Value)))); | |
11758 | end if; | |
11759 | ||
11760 | -- Discard_Names | |
11761 | ||
11762 | if not Has_Rep_Item (Typ, Name_Discard_Names, False) | |
11763 | and then Has_Rep_Item (Typ, Name_Discard_Names) | |
11764 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11765 | (Get_Rep_Item (Typ, Name_Discard_Names)) | |
11766 | then | |
11767 | Set_Discard_Names (Typ); | |
11768 | end if; | |
11769 | ||
99a2d5bd | 11770 | -- Volatile |
11771 | ||
11772 | if not Has_Rep_Item (Typ, Name_Volatile, False) | |
11773 | and then Has_Rep_Item (Typ, Name_Volatile) | |
11774 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11775 | (Get_Rep_Item (Typ, Name_Volatile)) | |
11776 | then | |
99a2d5bd | 11777 | Set_Is_Volatile (Typ); |
4bf2acc9 | 11778 | Set_Treat_As_Volatile (Typ); |
99a2d5bd | 11779 | end if; |
11780 | ||
2fe893b9 | 11781 | -- Volatile_Full_Access |
11782 | ||
11783 | if not Has_Rep_Item (Typ, Name_Volatile_Full_Access, False) | |
11784 | and then Has_Rep_Pragma (Typ, Name_Volatile_Full_Access) | |
11785 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11786 | (Get_Rep_Item (Typ, Name_Volatile_Full_Access)) | |
11787 | then | |
4bf2acc9 | 11788 | Set_Is_Volatile_Full_Access (Typ); |
2fe893b9 | 11789 | Set_Is_Volatile (Typ); |
4bf2acc9 | 11790 | Set_Treat_As_Volatile (Typ); |
2fe893b9 | 11791 | end if; |
11792 | ||
99a2d5bd | 11793 | -- Inheritance for derived types only |
11794 | ||
11795 | if Is_Derived_Type (Typ) then | |
11796 | declare | |
11797 | Bas_Typ : constant Entity_Id := Base_Type (Typ); | |
11798 | Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ); | |
11799 | ||
11800 | begin | |
11801 | -- Atomic_Components | |
11802 | ||
11803 | if not Has_Rep_Item (Typ, Name_Atomic_Components, False) | |
11804 | and then Has_Rep_Item (Typ, Name_Atomic_Components) | |
11805 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11806 | (Get_Rep_Item (Typ, Name_Atomic_Components)) | |
11807 | then | |
11808 | Set_Has_Atomic_Components (Imp_Bas_Typ); | |
11809 | end if; | |
11810 | ||
11811 | -- Volatile_Components | |
11812 | ||
11813 | if not Has_Rep_Item (Typ, Name_Volatile_Components, False) | |
11814 | and then Has_Rep_Item (Typ, Name_Volatile_Components) | |
11815 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11816 | (Get_Rep_Item (Typ, Name_Volatile_Components)) | |
11817 | then | |
11818 | Set_Has_Volatile_Components (Imp_Bas_Typ); | |
11819 | end if; | |
11820 | ||
e81df51c | 11821 | -- Finalize_Storage_Only |
99a2d5bd | 11822 | |
11823 | if not Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only, False) | |
11824 | and then Has_Rep_Pragma (Typ, Name_Finalize_Storage_Only) | |
11825 | then | |
11826 | Set_Finalize_Storage_Only (Bas_Typ); | |
11827 | end if; | |
11828 | ||
11829 | -- Universal_Aliasing | |
11830 | ||
11831 | if not Has_Rep_Item (Typ, Name_Universal_Aliasing, False) | |
11832 | and then Has_Rep_Item (Typ, Name_Universal_Aliasing) | |
11833 | and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item | |
11834 | (Get_Rep_Item (Typ, Name_Universal_Aliasing)) | |
11835 | then | |
11836 | Set_Universal_Aliasing (Imp_Bas_Typ); | |
11837 | end if; | |
11838 | ||
e81df51c | 11839 | -- Bit_Order |
99a2d5bd | 11840 | |
11841 | if Is_Record_Type (Typ) then | |
99a2d5bd | 11842 | if not Has_Rep_Item (Typ, Name_Bit_Order, False) |
11843 | and then Has_Rep_Item (Typ, Name_Bit_Order) | |
11844 | then | |
11845 | Set_Reverse_Bit_Order (Bas_Typ, | |
724be312 | 11846 | Reverse_Bit_Order (Rep_Item_Entity |
11847 | (Get_Rep_Item (Typ, Name_Bit_Order)))); | |
99a2d5bd | 11848 | end if; |
e81df51c | 11849 | end if; |
11850 | ||
e9218716 | 11851 | -- Scalar_Storage_Order |
11852 | ||
11853 | -- Note: the aspect is specified on a first subtype, but recorded | |
11854 | -- in a flag of the base type! | |
e81df51c | 11855 | |
11856 | if (Is_Record_Type (Typ) or else Is_Array_Type (Typ)) | |
29b91bc7 | 11857 | and then Typ = Bas_Typ |
e81df51c | 11858 | then |
e81df51c | 11859 | -- For a type extension, always inherit from parent; otherwise |
11860 | -- inherit if no default applies. Note: we do not check for | |
11861 | -- an explicit rep item on the parent type when inheriting, | |
11862 | -- because the parent SSO may itself have been set by default. | |
99a2d5bd | 11863 | |
e9218716 | 11864 | if not Has_Rep_Item (First_Subtype (Typ), |
11865 | Name_Scalar_Storage_Order, False) | |
e81df51c | 11866 | and then (Is_Tagged_Type (Bas_Typ) |
29b91bc7 | 11867 | or else not (SSO_Set_Low_By_Default (Bas_Typ) |
11868 | or else | |
11869 | SSO_Set_High_By_Default (Bas_Typ))) | |
99a2d5bd | 11870 | then |
11871 | Set_Reverse_Storage_Order (Bas_Typ, | |
423b89fd | 11872 | Reverse_Storage_Order |
11873 | (Implementation_Base_Type (Etype (Bas_Typ)))); | |
b64082f2 | 11874 | |
11875 | -- Clear default SSO indications, since the inherited aspect | |
11876 | -- which was set explicitly overrides the default. | |
11877 | ||
11878 | Set_SSO_Set_Low_By_Default (Bas_Typ, False); | |
11879 | Set_SSO_Set_High_By_Default (Bas_Typ, False); | |
99a2d5bd | 11880 | end if; |
11881 | end if; | |
11882 | end; | |
11883 | end if; | |
11884 | end Inherit_Aspects_At_Freeze_Point; | |
11885 | ||
d6f39728 | 11886 | ---------------- |
11887 | -- Initialize -- | |
11888 | ---------------- | |
11889 | ||
11890 | procedure Initialize is | |
11891 | begin | |
7717ea00 | 11892 | Address_Clause_Checks.Init; |
d6f39728 | 11893 | Unchecked_Conversions.Init; |
dba38d2f | 11894 | |
3a7fe2f3 | 11895 | -- ??? Might be needed in the future for some non GCC back-ends |
11896 | -- if AAMP_On_Target then | |
11897 | -- Independence_Checks.Init; | |
11898 | -- end if; | |
d6f39728 | 11899 | end Initialize; |
11900 | ||
2625eb01 | 11901 | --------------------------- |
11902 | -- Install_Discriminants -- | |
11903 | --------------------------- | |
11904 | ||
11905 | procedure Install_Discriminants (E : Entity_Id) is | |
11906 | Disc : Entity_Id; | |
11907 | Prev : Entity_Id; | |
11908 | begin | |
11909 | Disc := First_Discriminant (E); | |
11910 | while Present (Disc) loop | |
11911 | Prev := Current_Entity (Disc); | |
11912 | Set_Current_Entity (Disc); | |
11913 | Set_Is_Immediately_Visible (Disc); | |
11914 | Set_Homonym (Disc, Prev); | |
11915 | Next_Discriminant (Disc); | |
11916 | end loop; | |
11917 | end Install_Discriminants; | |
11918 | ||
d6f39728 | 11919 | ------------------------- |
11920 | -- Is_Operational_Item -- | |
11921 | ------------------------- | |
11922 | ||
11923 | function Is_Operational_Item (N : Node_Id) return Boolean is | |
11924 | begin | |
11925 | if Nkind (N) /= N_Attribute_Definition_Clause then | |
11926 | return False; | |
b9e61b2a | 11927 | |
d6f39728 | 11928 | else |
11929 | declare | |
b9e61b2a | 11930 | Id : constant Attribute_Id := Get_Attribute_Id (Chars (N)); |
d6f39728 | 11931 | begin |
078a74b8 | 11932 | |
55ab5265 | 11933 | -- List of operational items is given in AARM 13.1(8.mm/1). |
078a74b8 | 11934 | -- It is clearly incomplete, as it does not include iterator |
11935 | -- aspects, among others. | |
11936 | ||
11937 | return Id = Attribute_Constant_Indexing | |
11938 | or else Id = Attribute_Default_Iterator | |
11939 | or else Id = Attribute_Implicit_Dereference | |
11940 | or else Id = Attribute_Input | |
11941 | or else Id = Attribute_Iterator_Element | |
11942 | or else Id = Attribute_Iterable | |
d6f39728 | 11943 | or else Id = Attribute_Output |
11944 | or else Id = Attribute_Read | |
078a74b8 | 11945 | or else Id = Attribute_Variable_Indexing |
f15731c4 | 11946 | or else Id = Attribute_Write |
11947 | or else Id = Attribute_External_Tag; | |
d6f39728 | 11948 | end; |
11949 | end if; | |
11950 | end Is_Operational_Item; | |
11951 | ||
3b23aaa0 | 11952 | ------------------------- |
11953 | -- Is_Predicate_Static -- | |
11954 | ------------------------- | |
11955 | ||
94d896aa | 11956 | -- Note: the basic legality of the expression has already been checked, so |
11957 | -- we don't need to worry about cases or ranges on strings for example. | |
11958 | ||
3b23aaa0 | 11959 | function Is_Predicate_Static |
11960 | (Expr : Node_Id; | |
11961 | Nam : Name_Id) return Boolean | |
11962 | is | |
11963 | function All_Static_Case_Alternatives (L : List_Id) return Boolean; | |
973c2fba | 11964 | -- Given a list of case expression alternatives, returns True if all |
11965 | -- the alternatives are static (have all static choices, and a static | |
11966 | -- expression). | |
3b23aaa0 | 11967 | |
11968 | function All_Static_Choices (L : List_Id) return Boolean; | |
a360a0f7 | 11969 | -- Returns true if all elements of the list are OK static choices |
3b23aaa0 | 11970 | -- as defined below for Is_Static_Choice. Used for case expression |
973c2fba | 11971 | -- alternatives and for the right operand of a membership test. An |
11972 | -- others_choice is static if the corresponding expression is static. | |
7c0c95b8 | 11973 | -- The staticness of the bounds is checked separately. |
3b23aaa0 | 11974 | |
11975 | function Is_Static_Choice (N : Node_Id) return Boolean; | |
11976 | -- Returns True if N represents a static choice (static subtype, or | |
a360a0f7 | 11977 | -- static subtype indication, or static expression, or static range). |
3b23aaa0 | 11978 | -- |
11979 | -- Note that this is a bit more inclusive than we actually need | |
11980 | -- (in particular membership tests do not allow the use of subtype | |
a360a0f7 | 11981 | -- indications). But that doesn't matter, we have already checked |
3b23aaa0 | 11982 | -- that the construct is legal to get this far. |
11983 | ||
11984 | function Is_Type_Ref (N : Node_Id) return Boolean; | |
11985 | pragma Inline (Is_Type_Ref); | |
973c2fba | 11986 | -- Returns True if N is a reference to the type for the predicate in the |
11987 | -- expression (i.e. if it is an identifier whose Chars field matches the | |
11988 | -- Nam given in the call). N must not be parenthesized, if the type name | |
11989 | -- appears in parens, this routine will return False. | |
10f62e3a | 11990 | -- |
ea90be0f | 11991 | -- The routine also returns True for function calls generated during the |
11992 | -- expansion of comparison operators on strings, which are intended to | |
11993 | -- be legal in static predicates, and are converted into calls to array | |
11994 | -- comparison routines in the body of the corresponding predicate | |
11995 | -- function. | |
11996 | ||
3b23aaa0 | 11997 | ---------------------------------- |
11998 | -- All_Static_Case_Alternatives -- | |
11999 | ---------------------------------- | |
12000 | ||
12001 | function All_Static_Case_Alternatives (L : List_Id) return Boolean is | |
12002 | N : Node_Id; | |
12003 | ||
12004 | begin | |
12005 | N := First (L); | |
12006 | while Present (N) loop | |
12007 | if not (All_Static_Choices (Discrete_Choices (N)) | |
12008 | and then Is_OK_Static_Expression (Expression (N))) | |
12009 | then | |
12010 | return False; | |
12011 | end if; | |
12012 | ||
12013 | Next (N); | |
12014 | end loop; | |
12015 | ||
12016 | return True; | |
12017 | end All_Static_Case_Alternatives; | |
12018 | ||
12019 | ------------------------ | |
12020 | -- All_Static_Choices -- | |
12021 | ------------------------ | |
12022 | ||
12023 | function All_Static_Choices (L : List_Id) return Boolean is | |
12024 | N : Node_Id; | |
12025 | ||
12026 | begin | |
12027 | N := First (L); | |
12028 | while Present (N) loop | |
12029 | if not Is_Static_Choice (N) then | |
12030 | return False; | |
12031 | end if; | |
12032 | ||
12033 | Next (N); | |
12034 | end loop; | |
12035 | ||
12036 | return True; | |
12037 | end All_Static_Choices; | |
12038 | ||
12039 | ---------------------- | |
12040 | -- Is_Static_Choice -- | |
12041 | ---------------------- | |
12042 | ||
12043 | function Is_Static_Choice (N : Node_Id) return Boolean is | |
12044 | begin | |
7c0c95b8 | 12045 | return Nkind (N) = N_Others_Choice |
12046 | or else Is_OK_Static_Expression (N) | |
3b23aaa0 | 12047 | or else (Is_Entity_Name (N) and then Is_Type (Entity (N)) |
12048 | and then Is_OK_Static_Subtype (Entity (N))) | |
12049 | or else (Nkind (N) = N_Subtype_Indication | |
12050 | and then Is_OK_Static_Subtype (Entity (N))) | |
12051 | or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N)); | |
12052 | end Is_Static_Choice; | |
12053 | ||
12054 | ----------------- | |
12055 | -- Is_Type_Ref -- | |
12056 | ----------------- | |
12057 | ||
12058 | function Is_Type_Ref (N : Node_Id) return Boolean is | |
12059 | begin | |
ea90be0f | 12060 | return (Nkind (N) = N_Identifier |
12061 | and then Chars (N) = Nam | |
12062 | and then Paren_Count (N) = 0) | |
12063 | or else Nkind (N) = N_Function_Call; | |
3b23aaa0 | 12064 | end Is_Type_Ref; |
12065 | ||
12066 | -- Start of processing for Is_Predicate_Static | |
12067 | ||
12068 | begin | |
3b23aaa0 | 12069 | -- Predicate_Static means one of the following holds. Numbers are the |
12070 | -- corresponding paragraph numbers in (RM 3.2.4(16-22)). | |
12071 | ||
12072 | -- 16: A static expression | |
12073 | ||
12074 | if Is_OK_Static_Expression (Expr) then | |
12075 | return True; | |
12076 | ||
12077 | -- 17: A membership test whose simple_expression is the current | |
12078 | -- instance, and whose membership_choice_list meets the requirements | |
12079 | -- for a static membership test. | |
12080 | ||
12081 | elsif Nkind (Expr) in N_Membership_Test | |
12082 | and then ((Present (Right_Opnd (Expr)) | |
12083 | and then Is_Static_Choice (Right_Opnd (Expr))) | |
12084 | or else | |
12085 | (Present (Alternatives (Expr)) | |
12086 | and then All_Static_Choices (Alternatives (Expr)))) | |
12087 | then | |
12088 | return True; | |
12089 | ||
12090 | -- 18. A case_expression whose selecting_expression is the current | |
12091 | -- instance, and whose dependent expressions are static expressions. | |
12092 | ||
12093 | elsif Nkind (Expr) = N_Case_Expression | |
12094 | and then Is_Type_Ref (Expression (Expr)) | |
12095 | and then All_Static_Case_Alternatives (Alternatives (Expr)) | |
12096 | then | |
12097 | return True; | |
12098 | ||
12099 | -- 19. A call to a predefined equality or ordering operator, where one | |
12100 | -- operand is the current instance, and the other is a static | |
12101 | -- expression. | |
12102 | ||
94d896aa | 12103 | -- Note: the RM is clearly wrong here in not excluding string types. |
12104 | -- Without this exclusion, we would allow expressions like X > "ABC" | |
12105 | -- to be considered as predicate-static, which is clearly not intended, | |
12106 | -- since the idea is for predicate-static to be a subset of normal | |
12107 | -- static expressions (and "DEF" > "ABC" is not a static expression). | |
12108 | ||
12109 | -- However, we do allow internally generated (not from source) equality | |
12110 | -- and inequality operations to be valid on strings (this helps deal | |
12111 | -- with cases where we transform A in "ABC" to A = "ABC). | |
12112 | ||
ea90be0f | 12113 | -- In fact, it appears that the intent of the ARG is to extend static |
12114 | -- predicates to strings, and that the extension should probably apply | |
12115 | -- to static expressions themselves. The code below accepts comparison | |
12116 | -- operators that apply to static strings. | |
12117 | ||
3b23aaa0 | 12118 | elsif Nkind (Expr) in N_Op_Compare |
12119 | and then ((Is_Type_Ref (Left_Opnd (Expr)) | |
12120 | and then Is_OK_Static_Expression (Right_Opnd (Expr))) | |
12121 | or else | |
12122 | (Is_Type_Ref (Right_Opnd (Expr)) | |
12123 | and then Is_OK_Static_Expression (Left_Opnd (Expr)))) | |
12124 | then | |
12125 | return True; | |
12126 | ||
12127 | -- 20. A call to a predefined boolean logical operator, where each | |
12128 | -- operand is predicate-static. | |
12129 | ||
12130 | elsif (Nkind_In (Expr, N_Op_And, N_Op_Or, N_Op_Xor) | |
12131 | and then Is_Predicate_Static (Left_Opnd (Expr), Nam) | |
12132 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam)) | |
12133 | or else | |
12134 | (Nkind (Expr) = N_Op_Not | |
12135 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam)) | |
12136 | then | |
12137 | return True; | |
12138 | ||
12139 | -- 21. A short-circuit control form where both operands are | |
12140 | -- predicate-static. | |
12141 | ||
12142 | elsif Nkind (Expr) in N_Short_Circuit | |
12143 | and then Is_Predicate_Static (Left_Opnd (Expr), Nam) | |
12144 | and then Is_Predicate_Static (Right_Opnd (Expr), Nam) | |
12145 | then | |
12146 | return True; | |
12147 | ||
12148 | -- 22. A parenthesized predicate-static expression. This does not | |
12149 | -- require any special test, since we just ignore paren levels in | |
12150 | -- all the cases above. | |
12151 | ||
12152 | -- One more test that is an implementation artifact caused by the fact | |
499918a7 | 12153 | -- that we are analyzing not the original expression, but the generated |
3b23aaa0 | 12154 | -- expression in the body of the predicate function. This can include |
a360a0f7 | 12155 | -- references to inherited predicates, so that the expression we are |
3b23aaa0 | 12156 | -- processing looks like: |
12157 | ||
75491446 | 12158 | -- xxPredicate (typ (Inns)) and then expression |
3b23aaa0 | 12159 | |
12160 | -- Where the call is to a Predicate function for an inherited predicate. | |
60a4a5af | 12161 | -- We simply ignore such a call, which could be to either a dynamic or |
12162 | -- a static predicate. Note that if the parent predicate is dynamic then | |
12163 | -- eventually this type will be marked as dynamic, but you are allowed | |
12164 | -- to specify a static predicate for a subtype which is inheriting a | |
12165 | -- dynamic predicate, so the static predicate validation here ignores | |
12166 | -- the inherited predicate even if it is dynamic. | |
7db33803 | 12167 | -- In all cases, a static predicate can only apply to a scalar type. |
3b23aaa0 | 12168 | |
12169 | elsif Nkind (Expr) = N_Function_Call | |
12170 | and then Is_Predicate_Function (Entity (Name (Expr))) | |
7db33803 | 12171 | and then Is_Scalar_Type (Etype (First_Entity (Entity (Name (Expr))))) |
3b23aaa0 | 12172 | then |
12173 | return True; | |
12174 | ||
62c47568 | 12175 | elsif Is_Entity_Name (Expr) |
12176 | and then Entity (Expr) = Standard_True | |
12177 | then | |
12178 | Error_Msg_N ("predicate is redundant (always True)?", Expr); | |
12179 | return True; | |
12180 | ||
3b23aaa0 | 12181 | -- That's an exhaustive list of tests, all other cases are not |
a360a0f7 | 12182 | -- predicate-static, so we return False. |
3b23aaa0 | 12183 | |
12184 | else | |
12185 | return False; | |
12186 | end if; | |
12187 | end Is_Predicate_Static; | |
12188 | ||
2ff55065 | 12189 | --------------------- |
12190 | -- Kill_Rep_Clause -- | |
12191 | --------------------- | |
12192 | ||
12193 | procedure Kill_Rep_Clause (N : Node_Id) is | |
12194 | begin | |
12195 | pragma Assert (Ignore_Rep_Clauses); | |
360f426f | 12196 | |
12197 | -- Note: we use Replace rather than Rewrite, because we don't want | |
12198 | -- ASIS to be able to use Original_Node to dig out the (undecorated) | |
12199 | -- rep clause that is being replaced. | |
12200 | ||
4949ddd5 | 12201 | Replace (N, Make_Null_Statement (Sloc (N))); |
360f426f | 12202 | |
12203 | -- The null statement must be marked as not coming from source. This is | |
37c6552c | 12204 | -- so that ASIS ignores it, and also the back end does not expect bogus |
360f426f | 12205 | -- "from source" null statements in weird places (e.g. in declarative |
12206 | -- regions where such null statements are not allowed). | |
12207 | ||
12208 | Set_Comes_From_Source (N, False); | |
2ff55065 | 12209 | end Kill_Rep_Clause; |
12210 | ||
d6f39728 | 12211 | ------------------ |
12212 | -- Minimum_Size -- | |
12213 | ------------------ | |
12214 | ||
12215 | function Minimum_Size | |
12216 | (T : Entity_Id; | |
d5b349fa | 12217 | Biased : Boolean := False) return Nat |
d6f39728 | 12218 | is |
12219 | Lo : Uint := No_Uint; | |
12220 | Hi : Uint := No_Uint; | |
12221 | LoR : Ureal := No_Ureal; | |
12222 | HiR : Ureal := No_Ureal; | |
12223 | LoSet : Boolean := False; | |
12224 | HiSet : Boolean := False; | |
12225 | B : Uint; | |
12226 | S : Nat; | |
12227 | Ancest : Entity_Id; | |
f15731c4 | 12228 | R_Typ : constant Entity_Id := Root_Type (T); |
d6f39728 | 12229 | |
12230 | begin | |
12231 | -- If bad type, return 0 | |
12232 | ||
12233 | if T = Any_Type then | |
12234 | return 0; | |
12235 | ||
12236 | -- For generic types, just return zero. There cannot be any legitimate | |
12237 | -- need to know such a size, but this routine may be called with a | |
12238 | -- generic type as part of normal processing. | |
12239 | ||
f02a9a9a | 12240 | elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then |
d6f39728 | 12241 | return 0; |
12242 | ||
74c7ae52 | 12243 | -- Access types (cannot have size smaller than System.Address) |
d6f39728 | 12244 | |
12245 | elsif Is_Access_Type (T) then | |
74c7ae52 | 12246 | return System_Address_Size; |
d6f39728 | 12247 | |
12248 | -- Floating-point types | |
12249 | ||
12250 | elsif Is_Floating_Point_Type (T) then | |
f15731c4 | 12251 | return UI_To_Int (Esize (R_Typ)); |
d6f39728 | 12252 | |
12253 | -- Discrete types | |
12254 | ||
12255 | elsif Is_Discrete_Type (T) then | |
12256 | ||
fdd294d1 | 12257 | -- The following loop is looking for the nearest compile time known |
12258 | -- bounds following the ancestor subtype chain. The idea is to find | |
12259 | -- the most restrictive known bounds information. | |
d6f39728 | 12260 | |
12261 | Ancest := T; | |
12262 | loop | |
12263 | if Ancest = Any_Type or else Etype (Ancest) = Any_Type then | |
12264 | return 0; | |
12265 | end if; | |
12266 | ||
12267 | if not LoSet then | |
12268 | if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then | |
12269 | Lo := Expr_Rep_Value (Type_Low_Bound (Ancest)); | |
12270 | LoSet := True; | |
12271 | exit when HiSet; | |
12272 | end if; | |
12273 | end if; | |
12274 | ||
12275 | if not HiSet then | |
12276 | if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then | |
12277 | Hi := Expr_Rep_Value (Type_High_Bound (Ancest)); | |
12278 | HiSet := True; | |
12279 | exit when LoSet; | |
12280 | end if; | |
12281 | end if; | |
12282 | ||
12283 | Ancest := Ancestor_Subtype (Ancest); | |
12284 | ||
12285 | if No (Ancest) then | |
12286 | Ancest := Base_Type (T); | |
12287 | ||
12288 | if Is_Generic_Type (Ancest) then | |
12289 | return 0; | |
12290 | end if; | |
12291 | end if; | |
12292 | end loop; | |
12293 | ||
12294 | -- Fixed-point types. We can't simply use Expr_Value to get the | |
fdd294d1 | 12295 | -- Corresponding_Integer_Value values of the bounds, since these do not |
12296 | -- get set till the type is frozen, and this routine can be called | |
12297 | -- before the type is frozen. Similarly the test for bounds being static | |
12298 | -- needs to include the case where we have unanalyzed real literals for | |
12299 | -- the same reason. | |
d6f39728 | 12300 | |
12301 | elsif Is_Fixed_Point_Type (T) then | |
12302 | ||
fdd294d1 | 12303 | -- The following loop is looking for the nearest compile time known |
12304 | -- bounds following the ancestor subtype chain. The idea is to find | |
12305 | -- the most restrictive known bounds information. | |
d6f39728 | 12306 | |
12307 | Ancest := T; | |
12308 | loop | |
12309 | if Ancest = Any_Type or else Etype (Ancest) = Any_Type then | |
12310 | return 0; | |
12311 | end if; | |
12312 | ||
3062c401 | 12313 | -- Note: In the following two tests for LoSet and HiSet, it may |
12314 | -- seem redundant to test for N_Real_Literal here since normally | |
12315 | -- one would assume that the test for the value being known at | |
12316 | -- compile time includes this case. However, there is a glitch. | |
12317 | -- If the real literal comes from folding a non-static expression, | |
12318 | -- then we don't consider any non- static expression to be known | |
12319 | -- at compile time if we are in configurable run time mode (needed | |
12320 | -- in some cases to give a clearer definition of what is and what | |
12321 | -- is not accepted). So the test is indeed needed. Without it, we | |
12322 | -- would set neither Lo_Set nor Hi_Set and get an infinite loop. | |
12323 | ||
d6f39728 | 12324 | if not LoSet then |
12325 | if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal | |
12326 | or else Compile_Time_Known_Value (Type_Low_Bound (Ancest)) | |
12327 | then | |
12328 | LoR := Expr_Value_R (Type_Low_Bound (Ancest)); | |
12329 | LoSet := True; | |
12330 | exit when HiSet; | |
12331 | end if; | |
12332 | end if; | |
12333 | ||
12334 | if not HiSet then | |
12335 | if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal | |
12336 | or else Compile_Time_Known_Value (Type_High_Bound (Ancest)) | |
12337 | then | |
12338 | HiR := Expr_Value_R (Type_High_Bound (Ancest)); | |
12339 | HiSet := True; | |
12340 | exit when LoSet; | |
12341 | end if; | |
12342 | end if; | |
12343 | ||
12344 | Ancest := Ancestor_Subtype (Ancest); | |
12345 | ||
12346 | if No (Ancest) then | |
12347 | Ancest := Base_Type (T); | |
12348 | ||
12349 | if Is_Generic_Type (Ancest) then | |
12350 | return 0; | |
12351 | end if; | |
12352 | end if; | |
12353 | end loop; | |
12354 | ||
12355 | Lo := UR_To_Uint (LoR / Small_Value (T)); | |
12356 | Hi := UR_To_Uint (HiR / Small_Value (T)); | |
12357 | ||
12358 | -- No other types allowed | |
12359 | ||
12360 | else | |
12361 | raise Program_Error; | |
12362 | end if; | |
12363 | ||
2866d595 | 12364 | -- Fall through with Hi and Lo set. Deal with biased case |
d6f39728 | 12365 | |
cc46ff4b | 12366 | if (Biased |
12367 | and then not Is_Fixed_Point_Type (T) | |
12368 | and then not (Is_Enumeration_Type (T) | |
12369 | and then Has_Non_Standard_Rep (T))) | |
d6f39728 | 12370 | or else Has_Biased_Representation (T) |
12371 | then | |
12372 | Hi := Hi - Lo; | |
12373 | Lo := Uint_0; | |
12374 | end if; | |
12375 | ||
005366f7 | 12376 | -- Null range case, size is always zero. We only do this in the discrete |
12377 | -- type case, since that's the odd case that came up. Probably we should | |
12378 | -- also do this in the fixed-point case, but doing so causes peculiar | |
12379 | -- gigi failures, and it is not worth worrying about this incredibly | |
12380 | -- marginal case (explicit null-range fixed-point type declarations)??? | |
12381 | ||
12382 | if Lo > Hi and then Is_Discrete_Type (T) then | |
12383 | S := 0; | |
12384 | ||
d6f39728 | 12385 | -- Signed case. Note that we consider types like range 1 .. -1 to be |
fdd294d1 | 12386 | -- signed for the purpose of computing the size, since the bounds have |
1a34e48c | 12387 | -- to be accommodated in the base type. |
d6f39728 | 12388 | |
005366f7 | 12389 | elsif Lo < 0 or else Hi < 0 then |
d6f39728 | 12390 | S := 1; |
12391 | B := Uint_1; | |
12392 | ||
da253936 | 12393 | -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1)) |
12394 | -- Note that we accommodate the case where the bounds cross. This | |
d6f39728 | 12395 | -- can happen either because of the way the bounds are declared |
12396 | -- or because of the algorithm in Freeze_Fixed_Point_Type. | |
12397 | ||
12398 | while Lo < -B | |
12399 | or else Hi < -B | |
12400 | or else Lo >= B | |
12401 | or else Hi >= B | |
12402 | loop | |
12403 | B := Uint_2 ** S; | |
12404 | S := S + 1; | |
12405 | end loop; | |
12406 | ||
12407 | -- Unsigned case | |
12408 | ||
12409 | else | |
12410 | -- If both bounds are positive, make sure that both are represen- | |
12411 | -- table in the case where the bounds are crossed. This can happen | |
12412 | -- either because of the way the bounds are declared, or because of | |
12413 | -- the algorithm in Freeze_Fixed_Point_Type. | |
12414 | ||
12415 | if Lo > Hi then | |
12416 | Hi := Lo; | |
12417 | end if; | |
12418 | ||
da253936 | 12419 | -- S = size, (can accommodate 0 .. (2**size - 1)) |
d6f39728 | 12420 | |
12421 | S := 0; | |
12422 | while Hi >= Uint_2 ** S loop | |
12423 | S := S + 1; | |
12424 | end loop; | |
12425 | end if; | |
12426 | ||
12427 | return S; | |
12428 | end Minimum_Size; | |
12429 | ||
44e4341e | 12430 | --------------------------- |
12431 | -- New_Stream_Subprogram -- | |
12432 | --------------------------- | |
d6f39728 | 12433 | |
44e4341e | 12434 | procedure New_Stream_Subprogram |
12435 | (N : Node_Id; | |
12436 | Ent : Entity_Id; | |
12437 | Subp : Entity_Id; | |
12438 | Nam : TSS_Name_Type) | |
d6f39728 | 12439 | is |
12440 | Loc : constant Source_Ptr := Sloc (N); | |
9dfe12ae | 12441 | Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam); |
f15731c4 | 12442 | Subp_Id : Entity_Id; |
d6f39728 | 12443 | Subp_Decl : Node_Id; |
12444 | F : Entity_Id; | |
12445 | Etyp : Entity_Id; | |
12446 | ||
44e4341e | 12447 | Defer_Declaration : constant Boolean := |
12448 | Is_Tagged_Type (Ent) or else Is_Private_Type (Ent); | |
12449 | -- For a tagged type, there is a declaration for each stream attribute | |
12450 | -- at the freeze point, and we must generate only a completion of this | |
12451 | -- declaration. We do the same for private types, because the full view | |
12452 | -- might be tagged. Otherwise we generate a declaration at the point of | |
449c4f58 | 12453 | -- the attribute definition clause. If the attribute definition comes |
12454 | -- from an aspect specification the declaration is part of the freeze | |
12455 | -- actions of the type. | |
44e4341e | 12456 | |
f15731c4 | 12457 | function Build_Spec return Node_Id; |
12458 | -- Used for declaration and renaming declaration, so that this is | |
12459 | -- treated as a renaming_as_body. | |
12460 | ||
12461 | ---------------- | |
12462 | -- Build_Spec -- | |
12463 | ---------------- | |
12464 | ||
d5b349fa | 12465 | function Build_Spec return Node_Id is |
44e4341e | 12466 | Out_P : constant Boolean := (Nam = TSS_Stream_Read); |
12467 | Formals : List_Id; | |
12468 | Spec : Node_Id; | |
83c6c069 | 12469 | T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc); |
44e4341e | 12470 | |
f15731c4 | 12471 | begin |
9dfe12ae | 12472 | Subp_Id := Make_Defining_Identifier (Loc, Sname); |
f15731c4 | 12473 | |
44e4341e | 12474 | -- S : access Root_Stream_Type'Class |
12475 | ||
12476 | Formals := New_List ( | |
12477 | Make_Parameter_Specification (Loc, | |
12478 | Defining_Identifier => | |
12479 | Make_Defining_Identifier (Loc, Name_S), | |
12480 | Parameter_Type => | |
12481 | Make_Access_Definition (Loc, | |
12482 | Subtype_Mark => | |
83c6c069 | 12483 | New_Occurrence_Of ( |
44e4341e | 12484 | Designated_Type (Etype (F)), Loc)))); |
12485 | ||
12486 | if Nam = TSS_Stream_Input then | |
4bba0a8d | 12487 | Spec := |
12488 | Make_Function_Specification (Loc, | |
12489 | Defining_Unit_Name => Subp_Id, | |
12490 | Parameter_Specifications => Formals, | |
12491 | Result_Definition => T_Ref); | |
44e4341e | 12492 | else |
12493 | -- V : [out] T | |
f15731c4 | 12494 | |
44e4341e | 12495 | Append_To (Formals, |
12496 | Make_Parameter_Specification (Loc, | |
12497 | Defining_Identifier => Make_Defining_Identifier (Loc, Name_V), | |
12498 | Out_Present => Out_P, | |
12499 | Parameter_Type => T_Ref)); | |
f15731c4 | 12500 | |
d3ef794c | 12501 | Spec := |
12502 | Make_Procedure_Specification (Loc, | |
12503 | Defining_Unit_Name => Subp_Id, | |
12504 | Parameter_Specifications => Formals); | |
44e4341e | 12505 | end if; |
f15731c4 | 12506 | |
44e4341e | 12507 | return Spec; |
12508 | end Build_Spec; | |
d6f39728 | 12509 | |
44e4341e | 12510 | -- Start of processing for New_Stream_Subprogram |
d6f39728 | 12511 | |
44e4341e | 12512 | begin |
12513 | F := First_Formal (Subp); | |
12514 | ||
12515 | if Ekind (Subp) = E_Procedure then | |
12516 | Etyp := Etype (Next_Formal (F)); | |
d6f39728 | 12517 | else |
44e4341e | 12518 | Etyp := Etype (Subp); |
d6f39728 | 12519 | end if; |
f15731c4 | 12520 | |
44e4341e | 12521 | -- Prepare subprogram declaration and insert it as an action on the |
12522 | -- clause node. The visibility for this entity is used to test for | |
12523 | -- visibility of the attribute definition clause (in the sense of | |
12524 | -- 8.3(23) as amended by AI-195). | |
9dfe12ae | 12525 | |
44e4341e | 12526 | if not Defer_Declaration then |
f15731c4 | 12527 | Subp_Decl := |
12528 | Make_Subprogram_Declaration (Loc, | |
12529 | Specification => Build_Spec); | |
44e4341e | 12530 | |
12531 | -- For a tagged type, there is always a visible declaration for each | |
15ebb600 | 12532 | -- stream TSS (it is a predefined primitive operation), and the |
44e4341e | 12533 | -- completion of this declaration occurs at the freeze point, which is |
12534 | -- not always visible at places where the attribute definition clause is | |
12535 | -- visible. So, we create a dummy entity here for the purpose of | |
12536 | -- tracking the visibility of the attribute definition clause itself. | |
12537 | ||
12538 | else | |
12539 | Subp_Id := | |
55868293 | 12540 | Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V')); |
44e4341e | 12541 | Subp_Decl := |
12542 | Make_Object_Declaration (Loc, | |
12543 | Defining_Identifier => Subp_Id, | |
12544 | Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc)); | |
f15731c4 | 12545 | end if; |
12546 | ||
449c4f58 | 12547 | if not Defer_Declaration |
12548 | and then From_Aspect_Specification (N) | |
12549 | and then Has_Delayed_Freeze (Ent) | |
12550 | then | |
12551 | Append_Freeze_Action (Ent, Subp_Decl); | |
12552 | ||
12553 | else | |
12554 | Insert_Action (N, Subp_Decl); | |
12555 | Set_Entity (N, Subp_Id); | |
12556 | end if; | |
44e4341e | 12557 | |
d6f39728 | 12558 | Subp_Decl := |
12559 | Make_Subprogram_Renaming_Declaration (Loc, | |
f15731c4 | 12560 | Specification => Build_Spec, |
8acb75b4 | 12561 | Name => New_Occurrence_Of (Subp, Loc)); |
d6f39728 | 12562 | |
44e4341e | 12563 | if Defer_Declaration then |
d6f39728 | 12564 | Set_TSS (Base_Type (Ent), Subp_Id); |
449c4f58 | 12565 | |
d6f39728 | 12566 | else |
449c4f58 | 12567 | if From_Aspect_Specification (N) then |
12568 | Append_Freeze_Action (Ent, Subp_Decl); | |
449c4f58 | 12569 | else |
12570 | Insert_Action (N, Subp_Decl); | |
12571 | end if; | |
12572 | ||
d6f39728 | 12573 | Copy_TSS (Subp_Id, Base_Type (Ent)); |
12574 | end if; | |
44e4341e | 12575 | end New_Stream_Subprogram; |
d6f39728 | 12576 | |
92038d64 | 12577 | -------------- |
12578 | -- Pop_Type -- | |
12579 | -------------- | |
12580 | ||
12581 | procedure Pop_Type (E : Entity_Id) is | |
12582 | begin | |
12583 | if Ekind (E) = E_Record_Type and then E = Current_Scope then | |
12584 | End_Scope; | |
12585 | ||
12586 | elsif Is_Type (E) | |
12587 | and then Has_Discriminants (E) | |
12588 | and then Nkind (Parent (E)) /= N_Subtype_Declaration | |
12589 | then | |
12590 | Uninstall_Discriminants (E); | |
12591 | Pop_Scope; | |
12592 | end if; | |
12593 | end Pop_Type; | |
12594 | ||
b4dcd57e | 12595 | --------------- |
12596 | -- Push_Type -- | |
12597 | --------------- | |
2625eb01 | 12598 | |
b4dcd57e | 12599 | procedure Push_Type (E : Entity_Id) is |
12600 | Comp : Entity_Id; | |
92038d64 | 12601 | |
2625eb01 | 12602 | begin |
b4dcd57e | 12603 | if Ekind (E) = E_Record_Type then |
2625eb01 | 12604 | Push_Scope (E); |
92038d64 | 12605 | |
b4dcd57e | 12606 | Comp := First_Component (E); |
12607 | while Present (Comp) loop | |
12608 | Install_Entity (Comp); | |
12609 | Next_Component (Comp); | |
12610 | end loop; | |
2625eb01 | 12611 | |
b4dcd57e | 12612 | if Has_Discriminants (E) then |
2625eb01 | 12613 | Install_Discriminants (E); |
12614 | end if; | |
b4dcd57e | 12615 | |
12616 | elsif Is_Type (E) | |
92038d64 | 12617 | and then Has_Discriminants (E) |
12618 | and then Nkind (Parent (E)) /= N_Subtype_Declaration | |
b4dcd57e | 12619 | then |
12620 | Push_Scope (E); | |
12621 | Install_Discriminants (E); | |
2625eb01 | 12622 | end if; |
b4dcd57e | 12623 | end Push_Type; |
2625eb01 | 12624 | |
d10a1b95 | 12625 | ----------------------------------- |
12626 | -- Register_Address_Clause_Check -- | |
12627 | ----------------------------------- | |
12628 | ||
12629 | procedure Register_Address_Clause_Check | |
12630 | (N : Node_Id; | |
12631 | X : Entity_Id; | |
12632 | A : Uint; | |
12633 | Y : Entity_Id; | |
12634 | Off : Boolean) | |
12635 | is | |
12636 | ACS : constant Boolean := Scope_Suppress.Suppress (Alignment_Check); | |
12637 | begin | |
12638 | Address_Clause_Checks.Append ((N, X, A, Y, Off, ACS)); | |
12639 | end Register_Address_Clause_Check; | |
12640 | ||
d6f39728 | 12641 | ------------------------ |
12642 | -- Rep_Item_Too_Early -- | |
12643 | ------------------------ | |
12644 | ||
80d4fec4 | 12645 | function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is |
7667b40a | 12646 | function Has_Generic_Parent (E : Entity_Id) return Boolean; |
12647 | -- Return True if any ancestor is a generic type | |
12648 | ||
8c21443b | 12649 | ------------------------ |
12650 | -- Has_Generic_Parent -- | |
12651 | ------------------------ | |
12652 | ||
7667b40a | 12653 | function Has_Generic_Parent (E : Entity_Id) return Boolean is |
12654 | Ancestor_Type : Entity_Id := Etype (E); | |
12655 | ||
12656 | begin | |
12657 | while Present (Ancestor_Type) | |
12658 | and then not Is_Generic_Type (Ancestor_Type) | |
12659 | and then Etype (Ancestor_Type) /= Ancestor_Type | |
12660 | loop | |
12661 | Ancestor_Type := Etype (Ancestor_Type); | |
12662 | end loop; | |
12663 | ||
8c21443b | 12664 | return |
12665 | Present (Ancestor_Type) and then Is_Generic_Type (Ancestor_Type); | |
7667b40a | 12666 | end Has_Generic_Parent; |
12667 | ||
8c21443b | 12668 | -- Start of processing for Rep_Item_Too_Early |
12669 | ||
d6f39728 | 12670 | begin |
44e4341e | 12671 | -- Cannot apply non-operational rep items to generic types |
d6f39728 | 12672 | |
f15731c4 | 12673 | if Is_Operational_Item (N) then |
12674 | return False; | |
12675 | ||
12676 | elsif Is_Type (T) | |
7667b40a | 12677 | and then Has_Generic_Parent (T) |
e17c5076 | 12678 | and then (Nkind (N) /= N_Pragma |
12679 | or else Get_Pragma_Id (N) /= Pragma_Convention) | |
d6f39728 | 12680 | then |
503f7fd3 | 12681 | Error_Msg_N ("representation item not allowed for generic type", N); |
d6f39728 | 12682 | return True; |
12683 | end if; | |
12684 | ||
fdd294d1 | 12685 | -- Otherwise check for incomplete type |
d6f39728 | 12686 | |
12687 | if Is_Incomplete_Or_Private_Type (T) | |
12688 | and then No (Underlying_Type (T)) | |
d64221a7 | 12689 | and then |
12690 | (Nkind (N) /= N_Pragma | |
60014bc9 | 12691 | or else Get_Pragma_Id (N) /= Pragma_Import) |
d6f39728 | 12692 | then |
12693 | Error_Msg_N | |
12694 | ("representation item must be after full type declaration", N); | |
12695 | return True; | |
12696 | ||
1a34e48c | 12697 | -- If the type has incomplete components, a representation clause is |
d6f39728 | 12698 | -- illegal but stream attributes and Convention pragmas are correct. |
12699 | ||
12700 | elsif Has_Private_Component (T) then | |
f15731c4 | 12701 | if Nkind (N) = N_Pragma then |
d6f39728 | 12702 | return False; |
b9e61b2a | 12703 | |
d6f39728 | 12704 | else |
12705 | Error_Msg_N | |
12706 | ("representation item must appear after type is fully defined", | |
12707 | N); | |
12708 | return True; | |
12709 | end if; | |
12710 | else | |
12711 | return False; | |
12712 | end if; | |
12713 | end Rep_Item_Too_Early; | |
12714 | ||
12715 | ----------------------- | |
12716 | -- Rep_Item_Too_Late -- | |
12717 | ----------------------- | |
12718 | ||
12719 | function Rep_Item_Too_Late | |
12720 | (T : Entity_Id; | |
12721 | N : Node_Id; | |
d5b349fa | 12722 | FOnly : Boolean := False) return Boolean |
d6f39728 | 12723 | is |
b4dcd57e | 12724 | function Is_Derived_Type_With_Constraint return Boolean; |
12725 | -- Check whether T is a derived type with an explicit constraint, in | |
12726 | -- which case the constraint has frozen the type and the item is too | |
06d78d4c | 12727 | -- late. This compensates for the fact that for derived scalar types |
b4dcd57e | 12728 | -- we freeze the base type unconditionally on account of a long-standing |
12729 | -- issue in gigi. | |
12730 | ||
4d0944e9 | 12731 | procedure No_Type_Rep_Item; |
12732 | -- Output message indicating that no type-related aspects can be | |
12733 | -- specified due to some property of the parent type. | |
12734 | ||
d6f39728 | 12735 | procedure Too_Late; |
4d0944e9 | 12736 | -- Output message for an aspect being specified too late |
12737 | ||
12738 | -- Note that neither of the above errors is considered a serious one, | |
12739 | -- since the effect is simply that we ignore the representation clause | |
12740 | -- in these cases. | |
04d38ee4 | 12741 | -- Is this really true? In any case if we make this change we must |
12742 | -- document the requirement in the spec of Rep_Item_Too_Late that | |
12743 | -- if True is returned, then the rep item must be completely ignored??? | |
4d0944e9 | 12744 | |
b4dcd57e | 12745 | -------------------------------------- |
12746 | -- Is_Derived_Type_With_Constraint -- | |
12747 | -------------------------------------- | |
12748 | ||
12749 | function Is_Derived_Type_With_Constraint return Boolean is | |
12750 | Decl : constant Node_Id := Declaration_Node (T); | |
92038d64 | 12751 | |
b4dcd57e | 12752 | begin |
12753 | return Is_Derived_Type (T) | |
12754 | and then Is_Frozen (Base_Type (T)) | |
12755 | and then Is_Enumeration_Type (T) | |
12756 | and then False | |
12757 | and then Nkind (N) = N_Enumeration_Representation_Clause | |
12758 | and then Nkind (Decl) = N_Subtype_Declaration | |
12759 | and then not Is_Entity_Name (Subtype_Indication (Decl)); | |
12760 | end Is_Derived_Type_With_Constraint; | |
12761 | ||
4d0944e9 | 12762 | ---------------------- |
12763 | -- No_Type_Rep_Item -- | |
12764 | ---------------------- | |
12765 | ||
12766 | procedure No_Type_Rep_Item is | |
12767 | begin | |
12768 | Error_Msg_N ("|type-related representation item not permitted!", N); | |
12769 | end No_Type_Rep_Item; | |
d53a018a | 12770 | |
12771 | -------------- | |
12772 | -- Too_Late -- | |
12773 | -------------- | |
d6f39728 | 12774 | |
12775 | procedure Too_Late is | |
12776 | begin | |
ce4da1ed | 12777 | -- Other compilers seem more relaxed about rep items appearing too |
12778 | -- late. Since analysis tools typically don't care about rep items | |
12779 | -- anyway, no reason to be too strict about this. | |
12780 | ||
a9cd517c | 12781 | if not Relaxed_RM_Semantics then |
12782 | Error_Msg_N ("|representation item appears too late!", N); | |
12783 | end if; | |
d6f39728 | 12784 | end Too_Late; |
12785 | ||
92038d64 | 12786 | -- Local variables |
12787 | ||
12788 | Parent_Type : Entity_Id; | |
12789 | S : Entity_Id; | |
12790 | ||
d6f39728 | 12791 | -- Start of processing for Rep_Item_Too_Late |
12792 | ||
12793 | begin | |
a3248fc4 | 12794 | -- First make sure entity is not frozen (RM 13.1(9)) |
d6f39728 | 12795 | |
b4dcd57e | 12796 | if (Is_Frozen (T) |
92038d64 | 12797 | or else (Is_Type (T) |
12798 | and then Is_Derived_Type_With_Constraint)) | |
a3248fc4 | 12799 | |
12800 | -- Exclude imported types, which may be frozen if they appear in a | |
12801 | -- representation clause for a local type. | |
12802 | ||
4aa270d8 | 12803 | and then not From_Limited_With (T) |
a3248fc4 | 12804 | |
a9cd517c | 12805 | -- Exclude generated entities (not coming from source). The common |
a3248fc4 | 12806 | -- case is when we generate a renaming which prematurely freezes the |
12807 | -- renamed internal entity, but we still want to be able to set copies | |
12808 | -- of attribute values such as Size/Alignment. | |
12809 | ||
12810 | and then Comes_From_Source (T) | |
d6f39728 | 12811 | then |
58e133a6 | 12812 | -- A self-referential aspect is illegal if it forces freezing the |
12813 | -- entity before the corresponding pragma has been analyzed. | |
12814 | ||
12815 | if Nkind_In (N, N_Attribute_Definition_Clause, N_Pragma) | |
12816 | and then From_Aspect_Specification (N) | |
12817 | then | |
12818 | Error_Msg_NE | |
ea90be0f | 12819 | ("aspect specification causes premature freezing of&", N, T); |
58e133a6 | 12820 | Set_Has_Delayed_Freeze (T, False); |
12821 | return True; | |
12822 | end if; | |
12823 | ||
d6f39728 | 12824 | Too_Late; |
12825 | S := First_Subtype (T); | |
12826 | ||
12827 | if Present (Freeze_Node (S)) then | |
04d38ee4 | 12828 | if not Relaxed_RM_Semantics then |
12829 | Error_Msg_NE | |
12830 | ("??no more representation items for }", Freeze_Node (S), S); | |
12831 | end if; | |
d6f39728 | 12832 | end if; |
12833 | ||
12834 | return True; | |
12835 | ||
d1a2e31b | 12836 | -- Check for case of untagged derived type whose parent either has |
4d0944e9 | 12837 | -- primitive operations, or is a by reference type (RM 13.1(10)). In |
12838 | -- this case we do not output a Too_Late message, since there is no | |
12839 | -- earlier point where the rep item could be placed to make it legal. | |
d6f39728 | 12840 | |
12841 | elsif Is_Type (T) | |
12842 | and then not FOnly | |
12843 | and then Is_Derived_Type (T) | |
12844 | and then not Is_Tagged_Type (T) | |
12845 | then | |
12846 | Parent_Type := Etype (Base_Type (T)); | |
12847 | ||
12848 | if Has_Primitive_Operations (Parent_Type) then | |
4d0944e9 | 12849 | No_Type_Rep_Item; |
04d38ee4 | 12850 | |
12851 | if not Relaxed_RM_Semantics then | |
12852 | Error_Msg_NE | |
12853 | ("\parent type & has primitive operations!", N, Parent_Type); | |
12854 | end if; | |
12855 | ||
d6f39728 | 12856 | return True; |
12857 | ||
12858 | elsif Is_By_Reference_Type (Parent_Type) then | |
4d0944e9 | 12859 | No_Type_Rep_Item; |
04d38ee4 | 12860 | |
12861 | if not Relaxed_RM_Semantics then | |
12862 | Error_Msg_NE | |
12863 | ("\parent type & is a by reference type!", N, Parent_Type); | |
12864 | end if; | |
12865 | ||
d6f39728 | 12866 | return True; |
12867 | end if; | |
12868 | end if; | |
12869 | ||
04d38ee4 | 12870 | -- No error, but one more warning to consider. The RM (surprisingly) |
12871 | -- allows this pattern: | |
12872 | ||
12873 | -- type S is ... | |
12874 | -- primitive operations for S | |
12875 | -- type R is new S; | |
12876 | -- rep clause for S | |
12877 | ||
12878 | -- Meaning that calls on the primitive operations of S for values of | |
12879 | -- type R may require possibly expensive implicit conversion operations. | |
12880 | -- This is not an error, but is worth a warning. | |
12881 | ||
12882 | if not Relaxed_RM_Semantics and then Is_Type (T) then | |
12883 | declare | |
12884 | DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T)); | |
12885 | ||
12886 | begin | |
12887 | if Present (DTL) | |
12888 | and then Has_Primitive_Operations (Base_Type (T)) | |
12889 | ||
12890 | -- For now, do not generate this warning for the case of aspect | |
12891 | -- specification using Ada 2012 syntax, since we get wrong | |
12892 | -- messages we do not understand. The whole business of derived | |
12893 | -- types and rep items seems a bit confused when aspects are | |
12894 | -- used, since the aspects are not evaluated till freeze time. | |
12895 | ||
12896 | and then not From_Aspect_Specification (N) | |
12897 | then | |
12898 | Error_Msg_Sloc := Sloc (DTL); | |
12899 | Error_Msg_N | |
12900 | ("representation item for& appears after derived type " | |
12901 | & "declaration#??", N); | |
12902 | Error_Msg_NE | |
12903 | ("\may result in implicit conversions for primitive " | |
12904 | & "operations of&??", N, T); | |
12905 | Error_Msg_NE | |
12906 | ("\to change representations when called with arguments " | |
12907 | & "of type&??", N, DTL); | |
12908 | end if; | |
12909 | end; | |
12910 | end if; | |
12911 | ||
3062c401 | 12912 | -- No error, link item into head of chain of rep items for the entity, |
12913 | -- but avoid chaining if we have an overloadable entity, and the pragma | |
12914 | -- is one that can apply to multiple overloaded entities. | |
12915 | ||
b9e61b2a | 12916 | if Is_Overloadable (T) and then Nkind (N) = N_Pragma then |
fdd294d1 | 12917 | declare |
ddccc924 | 12918 | Pname : constant Name_Id := Pragma_Name (N); |
fdd294d1 | 12919 | begin |
18393965 | 12920 | if Nam_In (Pname, Name_Convention, Name_Import, Name_Export, |
12921 | Name_External, Name_Interface) | |
fdd294d1 | 12922 | then |
12923 | return False; | |
12924 | end if; | |
12925 | end; | |
3062c401 | 12926 | end if; |
12927 | ||
fdd294d1 | 12928 | Record_Rep_Item (T, N); |
d6f39728 | 12929 | return False; |
12930 | end Rep_Item_Too_Late; | |
12931 | ||
2072eaa9 | 12932 | ------------------------------------- |
12933 | -- Replace_Type_References_Generic -- | |
12934 | ------------------------------------- | |
12935 | ||
37c6552c | 12936 | procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is |
12937 | TName : constant Name_Id := Chars (T); | |
2072eaa9 | 12938 | |
97c23bbe | 12939 | function Replace_Type_Ref (N : Node_Id) return Traverse_Result; |
2072eaa9 | 12940 | -- Processes a single node in the traversal procedure below, checking |
12941 | -- if node N should be replaced, and if so, doing the replacement. | |
12942 | ||
d0931270 | 12943 | function Visible_Component (Comp : Name_Id) return Entity_Id; |
12944 | -- Given an identifier in the expression, check whether there is a | |
12945 | -- discriminant or component of the type that is directy visible, and | |
12946 | -- rewrite it as the corresponding selected component of the formal of | |
12947 | -- the subprogram. The entity is located by a sequential search, which | |
12948 | -- seems acceptable given the typical size of component lists and check | |
12949 | -- expressions. Possible optimization ??? | |
12950 | ||
97c23bbe | 12951 | ---------------------- |
12952 | -- Replace_Type_Ref -- | |
12953 | ---------------------- | |
2072eaa9 | 12954 | |
97c23bbe | 12955 | function Replace_Type_Ref (N : Node_Id) return Traverse_Result is |
d0931270 | 12956 | Loc : constant Source_Ptr := Sloc (N); |
2072eaa9 | 12957 | |
d0931270 | 12958 | procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id); |
77fd9c7a | 12959 | -- Add the proper prefix to a reference to a component of the type |
12960 | -- when it is not already a selected component. | |
d0931270 | 12961 | |
12962 | ---------------- | |
12963 | -- Add_Prefix -- | |
12964 | ---------------- | |
2072eaa9 | 12965 | |
d0931270 | 12966 | procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id) is |
12967 | begin | |
12968 | Rewrite (Ref, | |
12969 | Make_Selected_Component (Loc, | |
77fd9c7a | 12970 | Prefix => New_Occurrence_Of (T, Loc), |
d0931270 | 12971 | Selector_Name => New_Occurrence_Of (Comp, Loc))); |
12972 | Replace_Type_Reference (Prefix (Ref)); | |
12973 | end Add_Prefix; | |
12974 | ||
77fd9c7a | 12975 | -- Local variables |
12976 | ||
12977 | Comp : Entity_Id; | |
12978 | Pref : Node_Id; | |
12979 | Scop : Entity_Id; | |
12980 | ||
d0931270 | 12981 | -- Start of processing for Replace_Type_Ref |
12982 | ||
12983 | begin | |
2072eaa9 | 12984 | if Nkind (N) = N_Identifier then |
12985 | ||
97c23bbe | 12986 | -- If not the type name, check whether it is a reference to some |
12987 | -- other type, which must be frozen before the predicate function | |
12988 | -- is analyzed, i.e. before the freeze node of the type to which | |
12989 | -- the predicate applies. | |
2072eaa9 | 12990 | |
12991 | if Chars (N) /= TName then | |
37c6552c | 12992 | if Present (Current_Entity (N)) |
46532462 | 12993 | and then Is_Type (Current_Entity (N)) |
37c6552c | 12994 | then |
12995 | Freeze_Before (Freeze_Node (T), Current_Entity (N)); | |
12996 | end if; | |
12997 | ||
d0931270 | 12998 | -- The components of the type are directly visible and can |
12999 | -- be referenced without a prefix. | |
13000 | ||
13001 | if Nkind (Parent (N)) = N_Selected_Component then | |
13002 | null; | |
13003 | ||
13004 | -- In expression C (I), C may be a directly visible function | |
13005 | -- or a visible component that has an array type. Disambiguate | |
13006 | -- by examining the component type. | |
13007 | ||
13008 | elsif Nkind (Parent (N)) = N_Indexed_Component | |
13009 | and then N = Prefix (Parent (N)) | |
13010 | then | |
77fd9c7a | 13011 | Comp := Visible_Component (Chars (N)); |
d0931270 | 13012 | |
77fd9c7a | 13013 | if Present (Comp) and then Is_Array_Type (Etype (Comp)) then |
13014 | Add_Prefix (N, Comp); | |
d0931270 | 13015 | end if; |
13016 | ||
13017 | else | |
77fd9c7a | 13018 | Comp := Visible_Component (Chars (N)); |
d0931270 | 13019 | |
77fd9c7a | 13020 | if Present (Comp) then |
13021 | Add_Prefix (N, Comp); | |
d0931270 | 13022 | end if; |
13023 | end if; | |
13024 | ||
2072eaa9 | 13025 | return Skip; |
13026 | ||
c5685d96 | 13027 | -- Otherwise do the replacement if this is not a qualified |
13028 | -- reference to a homograph of the type itself. Note that the | |
13029 | -- current instance could not appear in such a context, e.g. | |
13030 | -- the prefix of a type conversion. | |
2072eaa9 | 13031 | |
13032 | else | |
c5685d96 | 13033 | if Nkind (Parent (N)) /= N_Selected_Component |
13034 | or else N /= Selector_Name (Parent (N)) | |
13035 | then | |
13036 | Replace_Type_Reference (N); | |
13037 | end if; | |
13038 | ||
2072eaa9 | 13039 | return Skip; |
13040 | end if; | |
13041 | ||
3e406e6d | 13042 | -- Case of selected component, which may be a subcomponent of the |
13043 | -- current instance, or an expanded name which is still unanalyzed. | |
2072eaa9 | 13044 | |
13045 | elsif Nkind (N) = N_Selected_Component then | |
13046 | ||
c5685d96 | 13047 | -- If selector name is not our type, keep going (we might still |
9a484c32 | 13048 | -- have an occurrence of the type in the prefix). If it is a |
13049 | -- subcomponent of the current entity, add prefix. | |
2072eaa9 | 13050 | |
13051 | if Nkind (Selector_Name (N)) /= N_Identifier | |
13052 | or else Chars (Selector_Name (N)) /= TName | |
13053 | then | |
3e406e6d | 13054 | if Nkind (Prefix (N)) = N_Identifier then |
13055 | Comp := Visible_Component (Chars (Prefix (N))); | |
13056 | ||
13057 | if Present (Comp) then | |
13058 | Add_Prefix (Prefix (N), Comp); | |
13059 | end if; | |
13060 | end if; | |
13061 | ||
2072eaa9 | 13062 | return OK; |
13063 | ||
13064 | -- Selector name is our type, check qualification | |
13065 | ||
13066 | else | |
13067 | -- Loop through scopes and prefixes, doing comparison | |
13068 | ||
77fd9c7a | 13069 | Scop := Current_Scope; |
13070 | Pref := Prefix (N); | |
2072eaa9 | 13071 | loop |
13072 | -- Continue if no more scopes or scope with no name | |
13073 | ||
77fd9c7a | 13074 | if No (Scop) or else Nkind (Scop) not in N_Has_Chars then |
2072eaa9 | 13075 | return OK; |
13076 | end if; | |
13077 | ||
97c23bbe | 13078 | -- Do replace if prefix is an identifier matching the scope |
13079 | -- that we are currently looking at. | |
2072eaa9 | 13080 | |
77fd9c7a | 13081 | if Nkind (Pref) = N_Identifier |
13082 | and then Chars (Pref) = Chars (Scop) | |
2072eaa9 | 13083 | then |
13084 | Replace_Type_Reference (N); | |
13085 | return Skip; | |
13086 | end if; | |
13087 | ||
97c23bbe | 13088 | -- Go check scope above us if prefix is itself of the form |
13089 | -- of a selected component, whose selector matches the scope | |
13090 | -- we are currently looking at. | |
2072eaa9 | 13091 | |
77fd9c7a | 13092 | if Nkind (Pref) = N_Selected_Component |
13093 | and then Nkind (Selector_Name (Pref)) = N_Identifier | |
13094 | and then Chars (Selector_Name (Pref)) = Chars (Scop) | |
2072eaa9 | 13095 | then |
77fd9c7a | 13096 | Scop := Scope (Scop); |
13097 | Pref := Prefix (Pref); | |
2072eaa9 | 13098 | |
13099 | -- For anything else, we don't have a match, so keep on | |
13100 | -- going, there are still some weird cases where we may | |
13101 | -- still have a replacement within the prefix. | |
13102 | ||
13103 | else | |
13104 | return OK; | |
13105 | end if; | |
13106 | end loop; | |
13107 | end if; | |
13108 | ||
ec6f6da5 | 13109 | -- Continue for any other node kind |
2072eaa9 | 13110 | |
13111 | else | |
13112 | return OK; | |
13113 | end if; | |
97c23bbe | 13114 | end Replace_Type_Ref; |
13115 | ||
77fd9c7a | 13116 | procedure Replace_Type_Refs is new Traverse_Proc (Replace_Type_Ref); |
13117 | ||
d0931270 | 13118 | ----------------------- |
13119 | -- Visible_Component -- | |
13120 | ----------------------- | |
13121 | ||
13122 | function Visible_Component (Comp : Name_Id) return Entity_Id is | |
13123 | E : Entity_Id; | |
77fd9c7a | 13124 | |
d0931270 | 13125 | begin |
1a5b3a27 | 13126 | -- Types with nameable components are records and discriminated |
13127 | -- private types. | |
13128 | ||
13129 | if Ekind (T) = E_Record_Type | |
13130 | or else (Is_Private_Type (T) and then Has_Discriminants (T)) | |
13131 | then | |
d0931270 | 13132 | E := First_Entity (T); |
13133 | while Present (E) loop | |
77fd9c7a | 13134 | if Comes_From_Source (E) and then Chars (E) = Comp then |
d0931270 | 13135 | return E; |
13136 | end if; | |
13137 | ||
13138 | Next_Entity (E); | |
13139 | end loop; | |
d0931270 | 13140 | end if; |
1a5b3a27 | 13141 | |
b58a7126 | 13142 | -- Nothing by that name, or the type has no components |
1a5b3a27 | 13143 | |
13144 | return Empty; | |
d0931270 | 13145 | end Visible_Component; |
13146 | ||
77fd9c7a | 13147 | -- Start of processing for Replace_Type_References_Generic |
2072eaa9 | 13148 | |
13149 | begin | |
13150 | Replace_Type_Refs (N); | |
13151 | end Replace_Type_References_Generic; | |
13152 | ||
81bd1c0d | 13153 | -------------------------------- |
13154 | -- Resolve_Aspect_Expressions -- | |
13155 | -------------------------------- | |
13156 | ||
13157 | procedure Resolve_Aspect_Expressions (E : Entity_Id) is | |
9c20237a | 13158 | function Resolve_Name (N : Node_Id) return Traverse_Result; |
13159 | -- Verify that all identifiers in the expression, with the exception | |
13160 | -- of references to the current entity, denote visible entities. This | |
13161 | -- is done only to detect visibility errors, as the expression will be | |
13162 | -- properly analyzed/expanded during analysis of the predicate function | |
c098acfb | 13163 | -- body. We omit quantified expressions from this test, given that they |
13164 | -- introduce a local identifier that would require proper expansion to | |
13165 | -- handle properly. | |
9c20237a | 13166 | |
25e4fa47 | 13167 | -- In ASIS_Mode we preserve the entity in the source because there is |
13168 | -- no subsequent expansion to decorate the tree. | |
13169 | ||
9c20237a | 13170 | ------------------ |
13171 | -- Resolve_Name -- | |
13172 | ------------------ | |
13173 | ||
13174 | function Resolve_Name (N : Node_Id) return Traverse_Result is | |
37066559 | 13175 | Dummy : Traverse_Result; |
85bbb15a | 13176 | |
9c20237a | 13177 | begin |
13178 | if Nkind (N) = N_Selected_Component then | |
13179 | if Nkind (Prefix (N)) = N_Identifier | |
13180 | and then Chars (Prefix (N)) /= Chars (E) | |
13181 | then | |
f4e18891 | 13182 | Find_Selected_Component (N); |
9c20237a | 13183 | end if; |
02e5d0d0 | 13184 | |
9c20237a | 13185 | return Skip; |
13186 | ||
2a6c14a6 | 13187 | -- Resolve identifiers that are not selectors in parameter |
13188 | -- associations (these are never resolved by visibility). | |
13189 | ||
13190 | elsif Nkind (N) = N_Identifier | |
13191 | and then Chars (N) /= Chars (E) | |
13192 | and then (Nkind (Parent (N)) /= N_Parameter_Association | |
13193 | or else N /= Selector_Name (Parent (N))) | |
13194 | then | |
9c20237a | 13195 | Find_Direct_Name (N); |
25e4fa47 | 13196 | |
156588cb | 13197 | -- In ASIS mode we must analyze overloaded identifiers to ensure |
13198 | -- their correct decoration because expansion is disabled (and | |
13199 | -- the expansion of freeze nodes takes care of resolving aspect | |
13200 | -- expressions). | |
13201 | ||
13202 | if ASIS_Mode then | |
13203 | if Is_Overloaded (N) then | |
13204 | Analyze (Parent (N)); | |
13205 | end if; | |
13206 | else | |
25e4fa47 | 13207 | Set_Entity (N, Empty); |
13208 | end if; | |
c098acfb | 13209 | |
37066559 | 13210 | -- The name is component association needs no resolution. |
13211 | ||
13212 | elsif Nkind (N) = N_Component_Association then | |
13213 | Dummy := Resolve_Name (Expression (N)); | |
13214 | return Skip; | |
13215 | ||
c098acfb | 13216 | elsif Nkind (N) = N_Quantified_Expression then |
13217 | return Skip; | |
9c20237a | 13218 | end if; |
13219 | ||
13220 | return OK; | |
13221 | end Resolve_Name; | |
13222 | ||
13223 | procedure Resolve_Aspect_Expression is new Traverse_Proc (Resolve_Name); | |
13224 | ||
85bbb15a | 13225 | -- Local variables |
13226 | ||
bfed3e04 | 13227 | ASN : Node_Id := First_Rep_Item (E); |
13228 | ||
02e5d0d0 | 13229 | -- Start of processing for Resolve_Aspect_Expressions |
13230 | ||
81bd1c0d | 13231 | begin |
b4dcd57e | 13232 | if No (ASN) then |
13233 | return; | |
13234 | end if; | |
97c23bbe | 13235 | |
bfed3e04 | 13236 | while Present (ASN) loop |
13237 | if Nkind (ASN) = N_Aspect_Specification and then Entity (ASN) = E then | |
13238 | declare | |
13239 | A_Id : constant Aspect_Id := Get_Aspect_Id (ASN); | |
13240 | Expr : constant Node_Id := Expression (ASN); | |
5535eed4 | 13241 | |
bfed3e04 | 13242 | begin |
13243 | case A_Id is | |
5535eed4 | 13244 | |
bfed3e04 | 13245 | -- For now we only deal with aspects that do not generate |
13246 | -- subprograms, or that may mention current instances of | |
13247 | -- types. These will require special handling (???TBD). | |
81bd1c0d | 13248 | |
bfed3e04 | 13249 | when Aspect_Invariant |
13250 | | Aspect_Predicate | |
13251 | | Aspect_Predicate_Failure | |
13252 | => | |
13253 | null; | |
81bd1c0d | 13254 | |
bfed3e04 | 13255 | when Aspect_Dynamic_Predicate |
13256 | | Aspect_Static_Predicate | |
13257 | => | |
13258 | -- Build predicate function specification and preanalyze | |
37066559 | 13259 | -- expression after type replacement. The function |
13260 | -- declaration must be analyzed in the scope of the | |
b4dcd57e | 13261 | -- type, but the the expression can reference components |
13262 | -- and discriminants of the type. | |
9c20237a | 13263 | |
bfed3e04 | 13264 | if No (Predicate_Function (E)) then |
13265 | declare | |
13266 | FDecl : constant Node_Id := | |
13267 | Build_Predicate_Function_Declaration (E); | |
13268 | pragma Unreferenced (FDecl); | |
37066559 | 13269 | |
bfed3e04 | 13270 | begin |
b4dcd57e | 13271 | Push_Type (E); |
bfed3e04 | 13272 | Resolve_Aspect_Expression (Expr); |
b4dcd57e | 13273 | Pop_Type (E); |
bfed3e04 | 13274 | end; |
13275 | end if; | |
9c20237a | 13276 | |
bfed3e04 | 13277 | when Pre_Post_Aspects => |
13278 | null; | |
81bd1c0d | 13279 | |
bfed3e04 | 13280 | when Aspect_Iterable => |
13281 | if Nkind (Expr) = N_Aggregate then | |
13282 | declare | |
13283 | Assoc : Node_Id; | |
81bd1c0d | 13284 | |
bfed3e04 | 13285 | begin |
13286 | Assoc := First (Component_Associations (Expr)); | |
13287 | while Present (Assoc) loop | |
13288 | Find_Direct_Name (Expression (Assoc)); | |
13289 | Next (Assoc); | |
13290 | end loop; | |
13291 | end; | |
13292 | end if; | |
81bd1c0d | 13293 | |
4cb8adff | 13294 | -- The expression for Default_Value is a static expression |
13295 | -- of the type, but this expression does not freeze the | |
13296 | -- type, so it can still appear in a representation clause | |
13297 | -- before the actual freeze point. | |
13298 | ||
13299 | when Aspect_Default_Value => | |
13300 | Set_Must_Not_Freeze (Expr); | |
13301 | Preanalyze_Spec_Expression (Expr, E); | |
13302 | ||
b4dcd57e | 13303 | when Aspect_Priority => |
13304 | Push_Type (E); | |
13305 | Preanalyze_Spec_Expression (Expr, Any_Integer); | |
13306 | Pop_Type (E); | |
13307 | ||
1728e3b3 | 13308 | -- Ditto for Storage_Size. Any other aspects that carry |
13309 | -- expressions that should not freeze ??? This is only | |
13310 | -- relevant to the misuse of deferred constants. | |
13311 | ||
13312 | when Aspect_Storage_Size => | |
13313 | Set_Must_Not_Freeze (Expr); | |
13314 | Preanalyze_Spec_Expression (Expr, Any_Integer); | |
13315 | ||
bfed3e04 | 13316 | when others => |
13317 | if Present (Expr) then | |
13318 | case Aspect_Argument (A_Id) is | |
13319 | when Expression | |
13320 | | Optional_Expression | |
13321 | => | |
13322 | Analyze_And_Resolve (Expr); | |
13323 | ||
13324 | when Name | |
13325 | | Optional_Name | |
13326 | => | |
13327 | if Nkind (Expr) = N_Identifier then | |
13328 | Find_Direct_Name (Expr); | |
13329 | ||
13330 | elsif Nkind (Expr) = N_Selected_Component then | |
13331 | Find_Selected_Component (Expr); | |
13332 | end if; | |
13333 | end case; | |
13334 | end if; | |
13335 | end case; | |
13336 | end; | |
81bd1c0d | 13337 | end if; |
13338 | ||
a738763e | 13339 | ASN := Next_Rep_Item (ASN); |
81bd1c0d | 13340 | end loop; |
13341 | end Resolve_Aspect_Expressions; | |
13342 | ||
d6f39728 | 13343 | ------------------------- |
13344 | -- Same_Representation -- | |
13345 | ------------------------- | |
13346 | ||
13347 | function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is | |
13348 | T1 : constant Entity_Id := Underlying_Type (Typ1); | |
13349 | T2 : constant Entity_Id := Underlying_Type (Typ2); | |
13350 | ||
13351 | begin | |
13352 | -- A quick check, if base types are the same, then we definitely have | |
13353 | -- the same representation, because the subtype specific representation | |
13354 | -- attributes (Size and Alignment) do not affect representation from | |
13355 | -- the point of view of this test. | |
13356 | ||
13357 | if Base_Type (T1) = Base_Type (T2) then | |
13358 | return True; | |
13359 | ||
13360 | elsif Is_Private_Type (Base_Type (T2)) | |
13361 | and then Base_Type (T1) = Full_View (Base_Type (T2)) | |
13362 | then | |
13363 | return True; | |
13364 | end if; | |
13365 | ||
3645e9c5 | 13366 | -- Tagged types always have the same representation, because it is not |
13367 | -- possible to specify different representations for common fields. | |
d6f39728 | 13368 | |
13369 | if Is_Tagged_Type (T1) then | |
13370 | return True; | |
13371 | end if; | |
13372 | ||
13373 | -- Representations are definitely different if conventions differ | |
13374 | ||
13375 | if Convention (T1) /= Convention (T2) then | |
13376 | return False; | |
13377 | end if; | |
13378 | ||
ef0772bc | 13379 | -- Representations are different if component alignments or scalar |
13380 | -- storage orders differ. | |
d6f39728 | 13381 | |
13382 | if (Is_Record_Type (T1) or else Is_Array_Type (T1)) | |
726fd56a | 13383 | and then |
d6f39728 | 13384 | (Is_Record_Type (T2) or else Is_Array_Type (T2)) |
ef0772bc | 13385 | and then |
13386 | (Component_Alignment (T1) /= Component_Alignment (T2) | |
f02a9a9a | 13387 | or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2)) |
d6f39728 | 13388 | then |
13389 | return False; | |
13390 | end if; | |
13391 | ||
13392 | -- For arrays, the only real issue is component size. If we know the | |
13393 | -- component size for both arrays, and it is the same, then that's | |
13394 | -- good enough to know we don't have a change of representation. | |
13395 | ||
13396 | if Is_Array_Type (T1) then | |
13397 | if Known_Component_Size (T1) | |
13398 | and then Known_Component_Size (T2) | |
13399 | and then Component_Size (T1) = Component_Size (T2) | |
13400 | then | |
36ac5fbb | 13401 | return True; |
d6f39728 | 13402 | end if; |
13403 | end if; | |
13404 | ||
3645e9c5 | 13405 | -- For records, representations are different if reorderings differ |
13406 | ||
13407 | if Is_Record_Type (T1) | |
13408 | and then Is_Record_Type (T2) | |
13409 | and then No_Reordering (T1) /= No_Reordering (T2) | |
13410 | then | |
13411 | return False; | |
13412 | end if; | |
13413 | ||
d6f39728 | 13414 | -- Types definitely have same representation if neither has non-standard |
13415 | -- representation since default representations are always consistent. | |
13416 | -- If only one has non-standard representation, and the other does not, | |
13417 | -- then we consider that they do not have the same representation. They | |
13418 | -- might, but there is no way of telling early enough. | |
13419 | ||
13420 | if Has_Non_Standard_Rep (T1) then | |
13421 | if not Has_Non_Standard_Rep (T2) then | |
13422 | return False; | |
13423 | end if; | |
13424 | else | |
13425 | return not Has_Non_Standard_Rep (T2); | |
13426 | end if; | |
13427 | ||
fdd294d1 | 13428 | -- Here the two types both have non-standard representation, and we need |
13429 | -- to determine if they have the same non-standard representation. | |
d6f39728 | 13430 | |
13431 | -- For arrays, we simply need to test if the component sizes are the | |
13432 | -- same. Pragma Pack is reflected in modified component sizes, so this | |
13433 | -- check also deals with pragma Pack. | |
13434 | ||
13435 | if Is_Array_Type (T1) then | |
13436 | return Component_Size (T1) = Component_Size (T2); | |
13437 | ||
d6f39728 | 13438 | -- Case of record types |
13439 | ||
13440 | elsif Is_Record_Type (T1) then | |
13441 | ||
13442 | -- Packed status must conform | |
13443 | ||
13444 | if Is_Packed (T1) /= Is_Packed (T2) then | |
13445 | return False; | |
13446 | ||
13447 | -- Otherwise we must check components. Typ2 maybe a constrained | |
13448 | -- subtype with fewer components, so we compare the components | |
13449 | -- of the base types. | |
13450 | ||
13451 | else | |
13452 | Record_Case : declare | |
13453 | CD1, CD2 : Entity_Id; | |
13454 | ||
13455 | function Same_Rep return Boolean; | |
13456 | -- CD1 and CD2 are either components or discriminants. This | |
ef0772bc | 13457 | -- function tests whether they have the same representation. |
d6f39728 | 13458 | |
80d4fec4 | 13459 | -------------- |
13460 | -- Same_Rep -- | |
13461 | -------------- | |
13462 | ||
d6f39728 | 13463 | function Same_Rep return Boolean is |
13464 | begin | |
13465 | if No (Component_Clause (CD1)) then | |
13466 | return No (Component_Clause (CD2)); | |
d6f39728 | 13467 | else |
ef0772bc | 13468 | -- Note: at this point, component clauses have been |
13469 | -- normalized to the default bit order, so that the | |
13470 | -- comparison of Component_Bit_Offsets is meaningful. | |
13471 | ||
d6f39728 | 13472 | return |
13473 | Present (Component_Clause (CD2)) | |
13474 | and then | |
13475 | Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2) | |
13476 | and then | |
13477 | Esize (CD1) = Esize (CD2); | |
13478 | end if; | |
13479 | end Same_Rep; | |
13480 | ||
1e35409d | 13481 | -- Start of processing for Record_Case |
d6f39728 | 13482 | |
13483 | begin | |
13484 | if Has_Discriminants (T1) then | |
d6f39728 | 13485 | |
9dfe12ae | 13486 | -- The number of discriminants may be different if the |
13487 | -- derived type has fewer (constrained by values). The | |
13488 | -- invisible discriminants retain the representation of | |
13489 | -- the original, so the discrepancy does not per se | |
13490 | -- indicate a different representation. | |
13491 | ||
b9e61b2a | 13492 | CD1 := First_Discriminant (T1); |
13493 | CD2 := First_Discriminant (T2); | |
13494 | while Present (CD1) and then Present (CD2) loop | |
d6f39728 | 13495 | if not Same_Rep then |
13496 | return False; | |
13497 | else | |
13498 | Next_Discriminant (CD1); | |
13499 | Next_Discriminant (CD2); | |
13500 | end if; | |
13501 | end loop; | |
13502 | end if; | |
13503 | ||
13504 | CD1 := First_Component (Underlying_Type (Base_Type (T1))); | |
13505 | CD2 := First_Component (Underlying_Type (Base_Type (T2))); | |
d6f39728 | 13506 | while Present (CD1) loop |
13507 | if not Same_Rep then | |
13508 | return False; | |
13509 | else | |
13510 | Next_Component (CD1); | |
13511 | Next_Component (CD2); | |
13512 | end if; | |
13513 | end loop; | |
13514 | ||
13515 | return True; | |
13516 | end Record_Case; | |
13517 | end if; | |
13518 | ||
13519 | -- For enumeration types, we must check each literal to see if the | |
13520 | -- representation is the same. Note that we do not permit enumeration | |
1a34e48c | 13521 | -- representation clauses for Character and Wide_Character, so these |
d6f39728 | 13522 | -- cases were already dealt with. |
13523 | ||
13524 | elsif Is_Enumeration_Type (T1) then | |
d6f39728 | 13525 | Enumeration_Case : declare |
13526 | L1, L2 : Entity_Id; | |
13527 | ||
13528 | begin | |
13529 | L1 := First_Literal (T1); | |
13530 | L2 := First_Literal (T2); | |
d6f39728 | 13531 | while Present (L1) loop |
13532 | if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then | |
13533 | return False; | |
13534 | else | |
13535 | Next_Literal (L1); | |
13536 | Next_Literal (L2); | |
13537 | end if; | |
13538 | end loop; | |
13539 | ||
13540 | return True; | |
d6f39728 | 13541 | end Enumeration_Case; |
13542 | ||
13543 | -- Any other types have the same representation for these purposes | |
13544 | ||
13545 | else | |
13546 | return True; | |
13547 | end if; | |
d6f39728 | 13548 | end Same_Representation; |
13549 | ||
3061ffde | 13550 | -------------------------------- |
13551 | -- Resolve_Iterable_Operation -- | |
13552 | -------------------------------- | |
13553 | ||
13554 | procedure Resolve_Iterable_Operation | |
13555 | (N : Node_Id; | |
13556 | Cursor : Entity_Id; | |
13557 | Typ : Entity_Id; | |
13558 | Nam : Name_Id) | |
13559 | is | |
13560 | Ent : Entity_Id; | |
13561 | F1 : Entity_Id; | |
13562 | F2 : Entity_Id; | |
13563 | ||
13564 | begin | |
13565 | if not Is_Overloaded (N) then | |
13566 | if not Is_Entity_Name (N) | |
13567 | or else Ekind (Entity (N)) /= E_Function | |
13568 | or else Scope (Entity (N)) /= Scope (Typ) | |
13569 | or else No (First_Formal (Entity (N))) | |
13570 | or else Etype (First_Formal (Entity (N))) /= Typ | |
13571 | then | |
e0e76328 | 13572 | Error_Msg_N |
13573 | ("iterable primitive must be local function name whose first " | |
13574 | & "formal is an iterable type", N); | |
a9f5fea7 | 13575 | return; |
3061ffde | 13576 | end if; |
13577 | ||
13578 | Ent := Entity (N); | |
e0e76328 | 13579 | F1 := First_Formal (Ent); |
3061ffde | 13580 | |
e0e76328 | 13581 | if Nam = Name_First or else Nam = Name_Last then |
cf0f46aa | 13582 | |
13583 | -- First or Last (Container) => Cursor | |
3061ffde | 13584 | |
13585 | if Etype (Ent) /= Cursor then | |
13586 | Error_Msg_N ("primitive for First must yield a curosr", N); | |
13587 | end if; | |
13588 | ||
13589 | elsif Nam = Name_Next then | |
13590 | ||
13591 | -- Next (Container, Cursor) => Cursor | |
13592 | ||
13593 | F2 := Next_Formal (F1); | |
13594 | ||
13595 | if Etype (F2) /= Cursor | |
13596 | or else Etype (Ent) /= Cursor | |
13597 | or else Present (Next_Formal (F2)) | |
13598 | then | |
13599 | Error_Msg_N ("no match for Next iterable primitive", N); | |
13600 | end if; | |
13601 | ||
cf0f46aa | 13602 | elsif Nam = Name_Previous then |
13603 | ||
13604 | -- Previous (Container, Cursor) => Cursor | |
13605 | ||
13606 | F2 := Next_Formal (F1); | |
13607 | ||
13608 | if Etype (F2) /= Cursor | |
13609 | or else Etype (Ent) /= Cursor | |
13610 | or else Present (Next_Formal (F2)) | |
13611 | then | |
13612 | Error_Msg_N ("no match for Previous iterable primitive", N); | |
13613 | end if; | |
13614 | ||
3061ffde | 13615 | elsif Nam = Name_Has_Element then |
13616 | ||
13617 | -- Has_Element (Container, Cursor) => Boolean | |
13618 | ||
13619 | F2 := Next_Formal (F1); | |
e0e76328 | 13620 | |
3061ffde | 13621 | if Etype (F2) /= Cursor |
13622 | or else Etype (Ent) /= Standard_Boolean | |
13623 | or else Present (Next_Formal (F2)) | |
13624 | then | |
13625 | Error_Msg_N ("no match for Has_Element iterable primitive", N); | |
13626 | end if; | |
13627 | ||
13628 | elsif Nam = Name_Element then | |
b9b03799 | 13629 | F2 := Next_Formal (F1); |
13630 | ||
13631 | if No (F2) | |
13632 | or else Etype (F2) /= Cursor | |
13633 | or else Present (Next_Formal (F2)) | |
13634 | then | |
13635 | Error_Msg_N ("no match for Element iterable primitive", N); | |
13636 | end if; | |
3061ffde | 13637 | |
13638 | else | |
13639 | raise Program_Error; | |
13640 | end if; | |
13641 | ||
13642 | else | |
e0e76328 | 13643 | -- Overloaded case: find subprogram with proper signature. Caller |
13644 | -- will report error if no match is found. | |
3061ffde | 13645 | |
13646 | declare | |
13647 | I : Interp_Index; | |
13648 | It : Interp; | |
13649 | ||
13650 | begin | |
13651 | Get_First_Interp (N, I, It); | |
13652 | while Present (It.Typ) loop | |
13653 | if Ekind (It.Nam) = E_Function | |
b9b03799 | 13654 | and then Scope (It.Nam) = Scope (Typ) |
3061ffde | 13655 | and then Etype (First_Formal (It.Nam)) = Typ |
13656 | then | |
13657 | F1 := First_Formal (It.Nam); | |
13658 | ||
13659 | if Nam = Name_First then | |
13660 | if Etype (It.Nam) = Cursor | |
13661 | and then No (Next_Formal (F1)) | |
13662 | then | |
13663 | Set_Entity (N, It.Nam); | |
13664 | exit; | |
13665 | end if; | |
13666 | ||
13667 | elsif Nam = Name_Next then | |
13668 | F2 := Next_Formal (F1); | |
13669 | ||
13670 | if Present (F2) | |
13671 | and then No (Next_Formal (F2)) | |
13672 | and then Etype (F2) = Cursor | |
13673 | and then Etype (It.Nam) = Cursor | |
13674 | then | |
13675 | Set_Entity (N, It.Nam); | |
13676 | exit; | |
13677 | end if; | |
13678 | ||
13679 | elsif Nam = Name_Has_Element then | |
13680 | F2 := Next_Formal (F1); | |
13681 | ||
13682 | if Present (F2) | |
13683 | and then No (Next_Formal (F2)) | |
13684 | and then Etype (F2) = Cursor | |
13685 | and then Etype (It.Nam) = Standard_Boolean | |
13686 | then | |
13687 | Set_Entity (N, It.Nam); | |
13688 | F2 := Next_Formal (F1); | |
13689 | exit; | |
13690 | end if; | |
13691 | ||
13692 | elsif Nam = Name_Element then | |
b9b03799 | 13693 | F2 := Next_Formal (F1); |
13694 | ||
3061ffde | 13695 | if Present (F2) |
13696 | and then No (Next_Formal (F2)) | |
13697 | and then Etype (F2) = Cursor | |
13698 | then | |
13699 | Set_Entity (N, It.Nam); | |
13700 | exit; | |
13701 | end if; | |
13702 | end if; | |
13703 | end if; | |
13704 | ||
13705 | Get_Next_Interp (I, It); | |
13706 | end loop; | |
13707 | end; | |
13708 | end if; | |
13709 | end Resolve_Iterable_Operation; | |
13710 | ||
b77e4501 | 13711 | ---------------- |
13712 | -- Set_Biased -- | |
13713 | ---------------- | |
13714 | ||
13715 | procedure Set_Biased | |
13716 | (E : Entity_Id; | |
13717 | N : Node_Id; | |
13718 | Msg : String; | |
13719 | Biased : Boolean := True) | |
13720 | is | |
13721 | begin | |
13722 | if Biased then | |
13723 | Set_Has_Biased_Representation (E); | |
13724 | ||
13725 | if Warn_On_Biased_Representation then | |
13726 | Error_Msg_NE | |
1e3532e7 | 13727 | ("?B?" & Msg & " forces biased representation for&", N, E); |
b77e4501 | 13728 | end if; |
13729 | end if; | |
13730 | end Set_Biased; | |
13731 | ||
d6f39728 | 13732 | -------------------- |
13733 | -- Set_Enum_Esize -- | |
13734 | -------------------- | |
13735 | ||
13736 | procedure Set_Enum_Esize (T : Entity_Id) is | |
13737 | Lo : Uint; | |
13738 | Hi : Uint; | |
13739 | Sz : Nat; | |
13740 | ||
13741 | begin | |
13742 | Init_Alignment (T); | |
13743 | ||
13744 | -- Find the minimum standard size (8,16,32,64) that fits | |
13745 | ||
13746 | Lo := Enumeration_Rep (Entity (Type_Low_Bound (T))); | |
13747 | Hi := Enumeration_Rep (Entity (Type_High_Bound (T))); | |
13748 | ||
13749 | if Lo < 0 then | |
13750 | if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then | |
f15731c4 | 13751 | Sz := Standard_Character_Size; -- May be > 8 on some targets |
d6f39728 | 13752 | |
13753 | elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then | |
13754 | Sz := 16; | |
13755 | ||
13756 | elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then | |
13757 | Sz := 32; | |
13758 | ||
13759 | else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63); | |
13760 | Sz := 64; | |
13761 | end if; | |
13762 | ||
13763 | else | |
13764 | if Hi < Uint_2**08 then | |
f15731c4 | 13765 | Sz := Standard_Character_Size; -- May be > 8 on some targets |
d6f39728 | 13766 | |
13767 | elsif Hi < Uint_2**16 then | |
13768 | Sz := 16; | |
13769 | ||
13770 | elsif Hi < Uint_2**32 then | |
13771 | Sz := 32; | |
13772 | ||
13773 | else pragma Assert (Hi < Uint_2**63); | |
13774 | Sz := 64; | |
13775 | end if; | |
13776 | end if; | |
13777 | ||
13778 | -- That minimum is the proper size unless we have a foreign convention | |
13779 | -- and the size required is 32 or less, in which case we bump the size | |
13780 | -- up to 32. This is required for C and C++ and seems reasonable for | |
13781 | -- all other foreign conventions. | |
13782 | ||
13783 | if Has_Foreign_Convention (T) | |
13784 | and then Esize (T) < Standard_Integer_Size | |
db1eed69 | 13785 | |
13786 | -- Don't do this if Short_Enums on target | |
13787 | ||
e9185b9d | 13788 | and then not Target_Short_Enums |
d6f39728 | 13789 | then |
13790 | Init_Esize (T, Standard_Integer_Size); | |
d6f39728 | 13791 | else |
13792 | Init_Esize (T, Sz); | |
13793 | end if; | |
d6f39728 | 13794 | end Set_Enum_Esize; |
13795 | ||
2625eb01 | 13796 | ----------------------------- |
13797 | -- Uninstall_Discriminants -- | |
13798 | ----------------------------- | |
13799 | ||
13800 | procedure Uninstall_Discriminants (E : Entity_Id) is | |
13801 | Disc : Entity_Id; | |
13802 | Prev : Entity_Id; | |
13803 | Outer : Entity_Id; | |
13804 | ||
13805 | begin | |
13806 | -- Discriminants have been made visible for type declarations and | |
13807 | -- protected type declarations, not for subtype declarations. | |
13808 | ||
13809 | if Nkind (Parent (E)) /= N_Subtype_Declaration then | |
13810 | Disc := First_Discriminant (E); | |
13811 | while Present (Disc) loop | |
13812 | if Disc /= Current_Entity (Disc) then | |
13813 | Prev := Current_Entity (Disc); | |
13814 | while Present (Prev) | |
13815 | and then Present (Homonym (Prev)) | |
13816 | and then Homonym (Prev) /= Disc | |
13817 | loop | |
13818 | Prev := Homonym (Prev); | |
13819 | end loop; | |
13820 | else | |
13821 | Prev := Empty; | |
13822 | end if; | |
13823 | ||
13824 | Set_Is_Immediately_Visible (Disc, False); | |
13825 | ||
13826 | Outer := Homonym (Disc); | |
13827 | while Present (Outer) and then Scope (Outer) = E loop | |
13828 | Outer := Homonym (Outer); | |
13829 | end loop; | |
13830 | ||
13831 | -- Reset homonym link of other entities, but do not modify link | |
3ff5e35d | 13832 | -- between entities in current scope, so that the back end can |
2625eb01 | 13833 | -- have a proper count of local overloadings. |
13834 | ||
13835 | if No (Prev) then | |
13836 | Set_Name_Entity_Id (Chars (Disc), Outer); | |
13837 | ||
13838 | elsif Scope (Prev) /= Scope (Disc) then | |
13839 | Set_Homonym (Prev, Outer); | |
13840 | end if; | |
13841 | ||
13842 | Next_Discriminant (Disc); | |
13843 | end loop; | |
13844 | end if; | |
13845 | end Uninstall_Discriminants; | |
13846 | ||
83f8f0a6 | 13847 | ------------------------------ |
13848 | -- Validate_Address_Clauses -- | |
13849 | ------------------------------ | |
13850 | ||
13851 | procedure Validate_Address_Clauses is | |
c7a1569a | 13852 | function Offset_Value (Expr : Node_Id) return Uint; |
13853 | -- Given an Address attribute reference, return the value in bits of its | |
13854 | -- offset from the first bit of the underlying entity, or 0 if it is not | |
13855 | -- known at compile time. | |
13856 | ||
13857 | ------------------ | |
13858 | -- Offset_Value -- | |
13859 | ------------------ | |
13860 | ||
13861 | function Offset_Value (Expr : Node_Id) return Uint is | |
13862 | N : Node_Id := Prefix (Expr); | |
13863 | Off : Uint; | |
13864 | Val : Uint := Uint_0; | |
13865 | ||
13866 | begin | |
13867 | -- Climb the prefix chain and compute the cumulative offset | |
13868 | ||
13869 | loop | |
13870 | if Is_Entity_Name (N) then | |
13871 | return Val; | |
13872 | ||
13873 | elsif Nkind (N) = N_Selected_Component then | |
13874 | Off := Component_Bit_Offset (Entity (Selector_Name (N))); | |
13875 | if Off /= No_Uint and then Off >= Uint_0 then | |
13876 | Val := Val + Off; | |
13877 | N := Prefix (N); | |
13878 | else | |
13879 | return Uint_0; | |
13880 | end if; | |
13881 | ||
13882 | elsif Nkind (N) = N_Indexed_Component then | |
13883 | Off := Indexed_Component_Bit_Offset (N); | |
13884 | if Off /= No_Uint then | |
13885 | Val := Val + Off; | |
13886 | N := Prefix (N); | |
13887 | else | |
13888 | return Uint_0; | |
13889 | end if; | |
13890 | ||
13891 | else | |
13892 | return Uint_0; | |
13893 | end if; | |
13894 | end loop; | |
13895 | end Offset_Value; | |
13896 | ||
13897 | -- Start of processing for Validate_Address_Clauses | |
13898 | ||
83f8f0a6 | 13899 | begin |
13900 | for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop | |
13901 | declare | |
13902 | ACCR : Address_Clause_Check_Record | |
13903 | renames Address_Clause_Checks.Table (J); | |
13904 | ||
d6da7448 | 13905 | Expr : Node_Id; |
13906 | ||
83f8f0a6 | 13907 | X_Alignment : Uint; |
f907cb13 | 13908 | Y_Alignment : Uint := Uint_0; |
83f8f0a6 | 13909 | |
13910 | X_Size : Uint; | |
f907cb13 | 13911 | Y_Size : Uint := Uint_0; |
83f8f0a6 | 13912 | |
c7a1569a | 13913 | X_Offs : Uint; |
13914 | ||
83f8f0a6 | 13915 | begin |
13916 | -- Skip processing of this entry if warning already posted | |
13917 | ||
13918 | if not Address_Warning_Posted (ACCR.N) then | |
d6da7448 | 13919 | Expr := Original_Node (Expression (ACCR.N)); |
83f8f0a6 | 13920 | |
514a5555 | 13921 | -- Get alignments, sizes and offset, if any |
83f8f0a6 | 13922 | |
d6da7448 | 13923 | X_Alignment := Alignment (ACCR.X); |
8650387e | 13924 | X_Size := Esize (ACCR.X); |
514a5555 | 13925 | |
13926 | if Present (ACCR.Y) then | |
13927 | Y_Alignment := Alignment (ACCR.Y); | |
8650387e | 13928 | Y_Size := Esize (ACCR.Y); |
514a5555 | 13929 | end if; |
83f8f0a6 | 13930 | |
c7a1569a | 13931 | if ACCR.Off |
13932 | and then Nkind (Expr) = N_Attribute_Reference | |
13933 | and then Attribute_Name (Expr) = Name_Address | |
13934 | then | |
13935 | X_Offs := Offset_Value (Expr); | |
13936 | else | |
13937 | X_Offs := Uint_0; | |
13938 | end if; | |
13939 | ||
514a5555 | 13940 | -- Check for known value not multiple of alignment |
13941 | ||
13942 | if No (ACCR.Y) then | |
d10a1b95 | 13943 | if not Alignment_Checks_Suppressed (ACCR) |
514a5555 | 13944 | and then X_Alignment /= 0 |
13945 | and then ACCR.A mod X_Alignment /= 0 | |
13946 | then | |
13947 | Error_Msg_NE | |
13948 | ("??specified address for& is inconsistent with " | |
13949 | & "alignment", ACCR.N, ACCR.X); | |
13950 | Error_Msg_N | |
13951 | ("\??program execution may be erroneous (RM 13.3(27))", | |
13952 | ACCR.N); | |
13953 | ||
13954 | Error_Msg_Uint_1 := X_Alignment; | |
13955 | Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X); | |
13956 | end if; | |
13957 | ||
83f8f0a6 | 13958 | -- Check for large object overlaying smaller one |
13959 | ||
514a5555 | 13960 | elsif Y_Size > Uint_0 |
83f8f0a6 | 13961 | and then X_Size > Uint_0 |
c7a1569a | 13962 | and then X_Offs + X_Size > Y_Size |
83f8f0a6 | 13963 | then |
7161e166 | 13964 | Error_Msg_NE ("??& overlays smaller object", ACCR.N, ACCR.X); |
83f8f0a6 | 13965 | Error_Msg_N |
1e3532e7 | 13966 | ("\??program execution may be erroneous", ACCR.N); |
7161e166 | 13967 | |
83f8f0a6 | 13968 | Error_Msg_Uint_1 := X_Size; |
7161e166 | 13969 | Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.X); |
13970 | ||
83f8f0a6 | 13971 | Error_Msg_Uint_1 := Y_Size; |
7161e166 | 13972 | Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.Y); |
83f8f0a6 | 13973 | |
f5cc2579 | 13974 | if Y_Size >= X_Size then |
c7a1569a | 13975 | Error_Msg_Uint_1 := X_Offs; |
f5cc2579 | 13976 | Error_Msg_NE ("\??but offset of & is ^", ACCR.N, ACCR.X); |
c7a1569a | 13977 | end if; |
13978 | ||
d6da7448 | 13979 | -- Check for inadequate alignment, both of the base object |
e556831e | 13980 | -- and of the offset, if any. We only do this check if the |
13981 | -- run-time Alignment_Check is active. No point in warning | |
13982 | -- if this check has been suppressed (or is suppressed by | |
13983 | -- default in the non-strict alignment machine case). | |
83f8f0a6 | 13984 | |
d6da7448 | 13985 | -- Note: we do not check the alignment if we gave a size |
13986 | -- warning, since it would likely be redundant. | |
83f8f0a6 | 13987 | |
d10a1b95 | 13988 | elsif not Alignment_Checks_Suppressed (ACCR) |
e556831e | 13989 | and then Y_Alignment /= Uint_0 |
7161e166 | 13990 | and then |
13991 | (Y_Alignment < X_Alignment | |
13992 | or else | |
13993 | (ACCR.Off | |
13994 | and then Nkind (Expr) = N_Attribute_Reference | |
13995 | and then Attribute_Name (Expr) = Name_Address | |
13996 | and then Has_Compatible_Alignment | |
13997 | (ACCR.X, Prefix (Expr), True) /= | |
13998 | Known_Compatible)) | |
83f8f0a6 | 13999 | then |
14000 | Error_Msg_NE | |
7161e166 | 14001 | ("??specified address for& may be inconsistent with " |
14002 | & "alignment", ACCR.N, ACCR.X); | |
83f8f0a6 | 14003 | Error_Msg_N |
1e3532e7 | 14004 | ("\??program execution may be erroneous (RM 13.3(27))", |
83f8f0a6 | 14005 | ACCR.N); |
7161e166 | 14006 | |
83f8f0a6 | 14007 | Error_Msg_Uint_1 := X_Alignment; |
7161e166 | 14008 | Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X); |
14009 | ||
83f8f0a6 | 14010 | Error_Msg_Uint_1 := Y_Alignment; |
7161e166 | 14011 | Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.Y); |
14012 | ||
d6da7448 | 14013 | if Y_Alignment >= X_Alignment then |
14014 | Error_Msg_N | |
7161e166 | 14015 | ("\??but offset is not multiple of alignment", ACCR.N); |
d6da7448 | 14016 | end if; |
83f8f0a6 | 14017 | end if; |
14018 | end if; | |
14019 | end; | |
14020 | end loop; | |
14021 | end Validate_Address_Clauses; | |
14022 | ||
7717ea00 | 14023 | --------------------------- |
14024 | -- Validate_Independence -- | |
14025 | --------------------------- | |
14026 | ||
14027 | procedure Validate_Independence is | |
14028 | SU : constant Uint := UI_From_Int (System_Storage_Unit); | |
14029 | N : Node_Id; | |
14030 | E : Entity_Id; | |
14031 | IC : Boolean; | |
14032 | Comp : Entity_Id; | |
14033 | Addr : Node_Id; | |
14034 | P : Node_Id; | |
14035 | ||
14036 | procedure Check_Array_Type (Atyp : Entity_Id); | |
14037 | -- Checks if the array type Atyp has independent components, and | |
14038 | -- if not, outputs an appropriate set of error messages. | |
14039 | ||
14040 | procedure No_Independence; | |
14041 | -- Output message that independence cannot be guaranteed | |
14042 | ||
14043 | function OK_Component (C : Entity_Id) return Boolean; | |
14044 | -- Checks one component to see if it is independently accessible, and | |
14045 | -- if so yields True, otherwise yields False if independent access | |
14046 | -- cannot be guaranteed. This is a conservative routine, it only | |
14047 | -- returns True if it knows for sure, it returns False if it knows | |
14048 | -- there is a problem, or it cannot be sure there is no problem. | |
14049 | ||
14050 | procedure Reason_Bad_Component (C : Entity_Id); | |
14051 | -- Outputs continuation message if a reason can be determined for | |
14052 | -- the component C being bad. | |
14053 | ||
14054 | ---------------------- | |
14055 | -- Check_Array_Type -- | |
14056 | ---------------------- | |
14057 | ||
14058 | procedure Check_Array_Type (Atyp : Entity_Id) is | |
14059 | Ctyp : constant Entity_Id := Component_Type (Atyp); | |
14060 | ||
14061 | begin | |
14062 | -- OK if no alignment clause, no pack, and no component size | |
14063 | ||
14064 | if not Has_Component_Size_Clause (Atyp) | |
14065 | and then not Has_Alignment_Clause (Atyp) | |
14066 | and then not Is_Packed (Atyp) | |
14067 | then | |
14068 | return; | |
14069 | end if; | |
14070 | ||
aa0a69ab | 14071 | -- Case of component size is greater than or equal to 64 and the |
14072 | -- alignment of the array is at least as large as the alignment | |
14073 | -- of the component. We are definitely OK in this situation. | |
14074 | ||
14075 | if Known_Component_Size (Atyp) | |
14076 | and then Component_Size (Atyp) >= 64 | |
14077 | and then Known_Alignment (Atyp) | |
14078 | and then Known_Alignment (Ctyp) | |
14079 | and then Alignment (Atyp) >= Alignment (Ctyp) | |
14080 | then | |
14081 | return; | |
14082 | end if; | |
14083 | ||
7717ea00 | 14084 | -- Check actual component size |
14085 | ||
14086 | if not Known_Component_Size (Atyp) | |
14087 | or else not (Addressable (Component_Size (Atyp)) | |
aa0a69ab | 14088 | and then Component_Size (Atyp) < 64) |
7717ea00 | 14089 | or else Component_Size (Atyp) mod Esize (Ctyp) /= 0 |
14090 | then | |
14091 | No_Independence; | |
14092 | ||
14093 | -- Bad component size, check reason | |
14094 | ||
14095 | if Has_Component_Size_Clause (Atyp) then | |
b9e61b2a | 14096 | P := Get_Attribute_Definition_Clause |
14097 | (Atyp, Attribute_Component_Size); | |
7717ea00 | 14098 | |
14099 | if Present (P) then | |
14100 | Error_Msg_Sloc := Sloc (P); | |
14101 | Error_Msg_N ("\because of Component_Size clause#", N); | |
14102 | return; | |
14103 | end if; | |
14104 | end if; | |
14105 | ||
14106 | if Is_Packed (Atyp) then | |
14107 | P := Get_Rep_Pragma (Atyp, Name_Pack); | |
14108 | ||
14109 | if Present (P) then | |
14110 | Error_Msg_Sloc := Sloc (P); | |
14111 | Error_Msg_N ("\because of pragma Pack#", N); | |
14112 | return; | |
14113 | end if; | |
14114 | end if; | |
14115 | ||
14116 | -- No reason found, just return | |
14117 | ||
14118 | return; | |
14119 | end if; | |
14120 | ||
14121 | -- Array type is OK independence-wise | |
14122 | ||
14123 | return; | |
14124 | end Check_Array_Type; | |
14125 | ||
14126 | --------------------- | |
14127 | -- No_Independence -- | |
14128 | --------------------- | |
14129 | ||
14130 | procedure No_Independence is | |
14131 | begin | |
ddccc924 | 14132 | if Pragma_Name (N) = Name_Independent then |
18393965 | 14133 | Error_Msg_NE ("independence cannot be guaranteed for&", N, E); |
7717ea00 | 14134 | else |
14135 | Error_Msg_NE | |
14136 | ("independent components cannot be guaranteed for&", N, E); | |
14137 | end if; | |
14138 | end No_Independence; | |
14139 | ||
14140 | ------------------ | |
14141 | -- OK_Component -- | |
14142 | ------------------ | |
14143 | ||
14144 | function OK_Component (C : Entity_Id) return Boolean is | |
14145 | Rec : constant Entity_Id := Scope (C); | |
14146 | Ctyp : constant Entity_Id := Etype (C); | |
14147 | ||
14148 | begin | |
14149 | -- OK if no component clause, no Pack, and no alignment clause | |
14150 | ||
14151 | if No (Component_Clause (C)) | |
14152 | and then not Is_Packed (Rec) | |
14153 | and then not Has_Alignment_Clause (Rec) | |
14154 | then | |
14155 | return True; | |
14156 | end if; | |
14157 | ||
14158 | -- Here we look at the actual component layout. A component is | |
14159 | -- addressable if its size is a multiple of the Esize of the | |
14160 | -- component type, and its starting position in the record has | |
14161 | -- appropriate alignment, and the record itself has appropriate | |
14162 | -- alignment to guarantee the component alignment. | |
14163 | ||
14164 | -- Make sure sizes are static, always assume the worst for any | |
14165 | -- cases where we cannot check static values. | |
14166 | ||
14167 | if not (Known_Static_Esize (C) | |
b9e61b2a | 14168 | and then |
14169 | Known_Static_Esize (Ctyp)) | |
7717ea00 | 14170 | then |
14171 | return False; | |
14172 | end if; | |
14173 | ||
14174 | -- Size of component must be addressable or greater than 64 bits | |
14175 | -- and a multiple of bytes. | |
14176 | ||
b9e61b2a | 14177 | if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then |
7717ea00 | 14178 | return False; |
14179 | end if; | |
14180 | ||
14181 | -- Check size is proper multiple | |
14182 | ||
14183 | if Esize (C) mod Esize (Ctyp) /= 0 then | |
14184 | return False; | |
14185 | end if; | |
14186 | ||
14187 | -- Check alignment of component is OK | |
14188 | ||
14189 | if not Known_Component_Bit_Offset (C) | |
14190 | or else Component_Bit_Offset (C) < Uint_0 | |
14191 | or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0 | |
14192 | then | |
14193 | return False; | |
14194 | end if; | |
14195 | ||
14196 | -- Check alignment of record type is OK | |
14197 | ||
14198 | if not Known_Alignment (Rec) | |
14199 | or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0 | |
14200 | then | |
14201 | return False; | |
14202 | end if; | |
14203 | ||
14204 | -- All tests passed, component is addressable | |
14205 | ||
14206 | return True; | |
14207 | end OK_Component; | |
14208 | ||
14209 | -------------------------- | |
14210 | -- Reason_Bad_Component -- | |
14211 | -------------------------- | |
14212 | ||
14213 | procedure Reason_Bad_Component (C : Entity_Id) is | |
14214 | Rec : constant Entity_Id := Scope (C); | |
14215 | Ctyp : constant Entity_Id := Etype (C); | |
14216 | ||
14217 | begin | |
14218 | -- If component clause present assume that's the problem | |
14219 | ||
14220 | if Present (Component_Clause (C)) then | |
14221 | Error_Msg_Sloc := Sloc (Component_Clause (C)); | |
14222 | Error_Msg_N ("\because of Component_Clause#", N); | |
14223 | return; | |
14224 | end if; | |
14225 | ||
14226 | -- If pragma Pack clause present, assume that's the problem | |
14227 | ||
14228 | if Is_Packed (Rec) then | |
14229 | P := Get_Rep_Pragma (Rec, Name_Pack); | |
14230 | ||
14231 | if Present (P) then | |
14232 | Error_Msg_Sloc := Sloc (P); | |
14233 | Error_Msg_N ("\because of pragma Pack#", N); | |
14234 | return; | |
14235 | end if; | |
14236 | end if; | |
14237 | ||
14238 | -- See if record has bad alignment clause | |
14239 | ||
14240 | if Has_Alignment_Clause (Rec) | |
14241 | and then Known_Alignment (Rec) | |
14242 | and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0 | |
14243 | then | |
14244 | P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment); | |
14245 | ||
14246 | if Present (P) then | |
14247 | Error_Msg_Sloc := Sloc (P); | |
14248 | Error_Msg_N ("\because of Alignment clause#", N); | |
14249 | end if; | |
14250 | end if; | |
14251 | ||
14252 | -- Couldn't find a reason, so return without a message | |
14253 | ||
14254 | return; | |
14255 | end Reason_Bad_Component; | |
14256 | ||
14257 | -- Start of processing for Validate_Independence | |
14258 | ||
14259 | begin | |
14260 | for J in Independence_Checks.First .. Independence_Checks.Last loop | |
14261 | N := Independence_Checks.Table (J).N; | |
14262 | E := Independence_Checks.Table (J).E; | |
ddccc924 | 14263 | IC := Pragma_Name (N) = Name_Independent_Components; |
7717ea00 | 14264 | |
14265 | -- Deal with component case | |
14266 | ||
14267 | if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then | |
14268 | if not OK_Component (E) then | |
14269 | No_Independence; | |
14270 | Reason_Bad_Component (E); | |
14271 | goto Continue; | |
14272 | end if; | |
14273 | end if; | |
14274 | ||
14275 | -- Deal with record with Independent_Components | |
14276 | ||
14277 | if IC and then Is_Record_Type (E) then | |
14278 | Comp := First_Component_Or_Discriminant (E); | |
14279 | while Present (Comp) loop | |
14280 | if not OK_Component (Comp) then | |
14281 | No_Independence; | |
14282 | Reason_Bad_Component (Comp); | |
14283 | goto Continue; | |
14284 | end if; | |
14285 | ||
14286 | Next_Component_Or_Discriminant (Comp); | |
14287 | end loop; | |
14288 | end if; | |
14289 | ||
14290 | -- Deal with address clause case | |
14291 | ||
14292 | if Is_Object (E) then | |
14293 | Addr := Address_Clause (E); | |
14294 | ||
14295 | if Present (Addr) then | |
14296 | No_Independence; | |
14297 | Error_Msg_Sloc := Sloc (Addr); | |
14298 | Error_Msg_N ("\because of Address clause#", N); | |
14299 | goto Continue; | |
14300 | end if; | |
14301 | end if; | |
14302 | ||
14303 | -- Deal with independent components for array type | |
14304 | ||
14305 | if IC and then Is_Array_Type (E) then | |
14306 | Check_Array_Type (E); | |
14307 | end if; | |
14308 | ||
14309 | -- Deal with independent components for array object | |
14310 | ||
14311 | if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then | |
14312 | Check_Array_Type (Etype (E)); | |
14313 | end if; | |
14314 | ||
14315 | <<Continue>> null; | |
14316 | end loop; | |
14317 | end Validate_Independence; | |
14318 | ||
b3f8228a | 14319 | ------------------------------ |
14320 | -- Validate_Iterable_Aspect -- | |
14321 | ------------------------------ | |
14322 | ||
14323 | procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is | |
3061ffde | 14324 | Assoc : Node_Id; |
14325 | Expr : Node_Id; | |
b3f8228a | 14326 | |
bde03454 | 14327 | Prim : Node_Id; |
a9f5fea7 | 14328 | Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ); |
b3f8228a | 14329 | |
14330 | First_Id : Entity_Id; | |
cf0f46aa | 14331 | Last_Id : Entity_Id; |
b3f8228a | 14332 | Next_Id : Entity_Id; |
14333 | Has_Element_Id : Entity_Id; | |
14334 | Element_Id : Entity_Id; | |
14335 | ||
b3f8228a | 14336 | begin |
9698629c | 14337 | -- If previous error aspect is unusable |
a9f5fea7 | 14338 | |
14339 | if Cursor = Any_Type then | |
3061ffde | 14340 | return; |
14341 | end if; | |
b3f8228a | 14342 | |
14343 | First_Id := Empty; | |
cf0f46aa | 14344 | Last_Id := Empty; |
b3f8228a | 14345 | Next_Id := Empty; |
14346 | Has_Element_Id := Empty; | |
32de816b | 14347 | Element_Id := Empty; |
b3f8228a | 14348 | |
14349 | -- Each expression must resolve to a function with the proper signature | |
14350 | ||
14351 | Assoc := First (Component_Associations (Expression (ASN))); | |
14352 | while Present (Assoc) loop | |
14353 | Expr := Expression (Assoc); | |
14354 | Analyze (Expr); | |
14355 | ||
b3f8228a | 14356 | Prim := First (Choices (Assoc)); |
bde03454 | 14357 | |
f02a9a9a | 14358 | if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then |
b3f8228a | 14359 | Error_Msg_N ("illegal name in association", Prim); |
14360 | ||
14361 | elsif Chars (Prim) = Name_First then | |
3061ffde | 14362 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First); |
b3f8228a | 14363 | First_Id := Entity (Expr); |
b3f8228a | 14364 | |
cf0f46aa | 14365 | elsif Chars (Prim) = Name_Last then |
14366 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Last); | |
14367 | Last_Id := Entity (Expr); | |
14368 | ||
14369 | elsif Chars (Prim) = Name_Previous then | |
14370 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Previous); | |
14371 | Last_Id := Entity (Expr); | |
14372 | ||
b3f8228a | 14373 | elsif Chars (Prim) = Name_Next then |
3061ffde | 14374 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next); |
b3f8228a | 14375 | Next_Id := Entity (Expr); |
b3f8228a | 14376 | |
14377 | elsif Chars (Prim) = Name_Has_Element then | |
3061ffde | 14378 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element); |
b3f8228a | 14379 | Has_Element_Id := Entity (Expr); |
bde03454 | 14380 | |
b3f8228a | 14381 | elsif Chars (Prim) = Name_Element then |
3061ffde | 14382 | Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element); |
b3f8228a | 14383 | Element_Id := Entity (Expr); |
b3f8228a | 14384 | |
14385 | else | |
14386 | Error_Msg_N ("invalid name for iterable function", Prim); | |
14387 | end if; | |
14388 | ||
14389 | Next (Assoc); | |
14390 | end loop; | |
14391 | ||
14392 | if No (First_Id) then | |
3061ffde | 14393 | Error_Msg_N ("match for First primitive not found", ASN); |
b3f8228a | 14394 | |
14395 | elsif No (Next_Id) then | |
3061ffde | 14396 | Error_Msg_N ("match for Next primitive not found", ASN); |
b3f8228a | 14397 | |
14398 | elsif No (Has_Element_Id) then | |
3061ffde | 14399 | Error_Msg_N ("match for Has_Element primitive not found", ASN); |
14400 | ||
e0e76328 | 14401 | elsif No (Element_Id) or else No (Last_Id) then |
14402 | null; -- optional | |
b3f8228a | 14403 | end if; |
14404 | end Validate_Iterable_Aspect; | |
14405 | ||
d6f39728 | 14406 | ----------------------------------- |
14407 | -- Validate_Unchecked_Conversion -- | |
14408 | ----------------------------------- | |
14409 | ||
14410 | procedure Validate_Unchecked_Conversion | |
14411 | (N : Node_Id; | |
14412 | Act_Unit : Entity_Id) | |
14413 | is | |
14414 | Source : Entity_Id; | |
14415 | Target : Entity_Id; | |
14416 | Vnode : Node_Id; | |
14417 | ||
14418 | begin | |
14419 | -- Obtain source and target types. Note that we call Ancestor_Subtype | |
14420 | -- here because the processing for generic instantiation always makes | |
14421 | -- subtypes, and we want the original frozen actual types. | |
14422 | ||
14423 | -- If we are dealing with private types, then do the check on their | |
14424 | -- fully declared counterparts if the full declarations have been | |
39a0c1d3 | 14425 | -- encountered (they don't have to be visible, but they must exist). |
d6f39728 | 14426 | |
14427 | Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit))); | |
14428 | ||
14429 | if Is_Private_Type (Source) | |
14430 | and then Present (Underlying_Type (Source)) | |
14431 | then | |
14432 | Source := Underlying_Type (Source); | |
14433 | end if; | |
14434 | ||
14435 | Target := Ancestor_Subtype (Etype (Act_Unit)); | |
14436 | ||
fdd294d1 | 14437 | -- If either type is generic, the instantiation happens within a generic |
95deda50 | 14438 | -- unit, and there is nothing to check. The proper check will happen |
14439 | -- when the enclosing generic is instantiated. | |
d6f39728 | 14440 | |
14441 | if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then | |
14442 | return; | |
14443 | end if; | |
14444 | ||
14445 | if Is_Private_Type (Target) | |
14446 | and then Present (Underlying_Type (Target)) | |
14447 | then | |
14448 | Target := Underlying_Type (Target); | |
14449 | end if; | |
14450 | ||
0924014e | 14451 | -- Source may be unconstrained array, but not target, except in relaxed |
14452 | -- semantics mode. | |
d6f39728 | 14453 | |
0924014e | 14454 | if Is_Array_Type (Target) |
14455 | and then not Is_Constrained (Target) | |
14456 | and then not Relaxed_RM_Semantics | |
14457 | then | |
d6f39728 | 14458 | Error_Msg_N |
14459 | ("unchecked conversion to unconstrained array not allowed", N); | |
14460 | return; | |
14461 | end if; | |
14462 | ||
fbc67f84 | 14463 | -- Warn if conversion between two different convention pointers |
14464 | ||
14465 | if Is_Access_Type (Target) | |
14466 | and then Is_Access_Type (Source) | |
14467 | and then Convention (Target) /= Convention (Source) | |
14468 | and then Warn_On_Unchecked_Conversion | |
14469 | then | |
74c7ae52 | 14470 | -- Give warnings for subprogram pointers only on most targets |
fdd294d1 | 14471 | |
14472 | if Is_Access_Subprogram_Type (Target) | |
14473 | or else Is_Access_Subprogram_Type (Source) | |
fdd294d1 | 14474 | then |
14475 | Error_Msg_N | |
cb97ae5c | 14476 | ("?z?conversion between pointers with different conventions!", |
1e3532e7 | 14477 | N); |
fdd294d1 | 14478 | end if; |
fbc67f84 | 14479 | end if; |
14480 | ||
3062c401 | 14481 | -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a |
14482 | -- warning when compiling GNAT-related sources. | |
14483 | ||
14484 | if Warn_On_Unchecked_Conversion | |
14485 | and then not In_Predefined_Unit (N) | |
14486 | and then RTU_Loaded (Ada_Calendar) | |
f02a9a9a | 14487 | and then (Chars (Source) = Name_Time |
14488 | or else | |
14489 | Chars (Target) = Name_Time) | |
3062c401 | 14490 | then |
14491 | -- If Ada.Calendar is loaded and the name of one of the operands is | |
14492 | -- Time, there is a good chance that this is Ada.Calendar.Time. | |
14493 | ||
14494 | declare | |
f02a9a9a | 14495 | Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time)); |
3062c401 | 14496 | begin |
14497 | pragma Assert (Present (Calendar_Time)); | |
14498 | ||
b9e61b2a | 14499 | if Source = Calendar_Time or else Target = Calendar_Time then |
3062c401 | 14500 | Error_Msg_N |
f02a9a9a | 14501 | ("?z?representation of 'Time values may change between " |
14502 | & "'G'N'A'T versions", N); | |
3062c401 | 14503 | end if; |
14504 | end; | |
14505 | end if; | |
14506 | ||
fdd294d1 | 14507 | -- Make entry in unchecked conversion table for later processing by |
14508 | -- Validate_Unchecked_Conversions, which will check sizes and alignments | |
3ff5e35d | 14509 | -- (using values set by the back end where possible). This is only done |
fdd294d1 | 14510 | -- if the appropriate warning is active. |
d6f39728 | 14511 | |
9dfe12ae | 14512 | if Warn_On_Unchecked_Conversion then |
14513 | Unchecked_Conversions.Append | |
86d32751 | 14514 | (New_Val => UC_Entry'(Eloc => Sloc (N), |
14515 | Source => Source, | |
14516 | Target => Target, | |
14517 | Act_Unit => Act_Unit)); | |
9dfe12ae | 14518 | |
f9906591 | 14519 | -- If both sizes are known statically now, then back-end annotation |
9dfe12ae | 14520 | -- is not required to do a proper check but if either size is not |
14521 | -- known statically, then we need the annotation. | |
14522 | ||
14523 | if Known_Static_RM_Size (Source) | |
1e3532e7 | 14524 | and then |
14525 | Known_Static_RM_Size (Target) | |
9dfe12ae | 14526 | then |
14527 | null; | |
14528 | else | |
14529 | Back_Annotate_Rep_Info := True; | |
14530 | end if; | |
14531 | end if; | |
d6f39728 | 14532 | |
fdd294d1 | 14533 | -- If unchecked conversion to access type, and access type is declared |
95deda50 | 14534 | -- in the same unit as the unchecked conversion, then set the flag |
14535 | -- No_Strict_Aliasing (no strict aliasing is implicit here) | |
28ed91d4 | 14536 | |
14537 | if Is_Access_Type (Target) and then | |
14538 | In_Same_Source_Unit (Target, N) | |
14539 | then | |
14540 | Set_No_Strict_Aliasing (Implementation_Base_Type (Target)); | |
14541 | end if; | |
3d875462 | 14542 | |
95deda50 | 14543 | -- Generate N_Validate_Unchecked_Conversion node for back end in case |
14544 | -- the back end needs to perform special validation checks. | |
3d875462 | 14545 | |
95deda50 | 14546 | -- Shouldn't this be in Exp_Ch13, since the check only gets done if we |
14547 | -- have full expansion and the back end is called ??? | |
3d875462 | 14548 | |
14549 | Vnode := | |
14550 | Make_Validate_Unchecked_Conversion (Sloc (N)); | |
14551 | Set_Source_Type (Vnode, Source); | |
14552 | Set_Target_Type (Vnode, Target); | |
14553 | ||
fdd294d1 | 14554 | -- If the unchecked conversion node is in a list, just insert before it. |
14555 | -- If not we have some strange case, not worth bothering about. | |
3d875462 | 14556 | |
14557 | if Is_List_Member (N) then | |
d6f39728 | 14558 | Insert_After (N, Vnode); |
14559 | end if; | |
14560 | end Validate_Unchecked_Conversion; | |
14561 | ||
14562 | ------------------------------------ | |
14563 | -- Validate_Unchecked_Conversions -- | |
14564 | ------------------------------------ | |
14565 | ||
14566 | procedure Validate_Unchecked_Conversions is | |
14567 | begin | |
14568 | for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop | |
14569 | declare | |
14570 | T : UC_Entry renames Unchecked_Conversions.Table (N); | |
14571 | ||
e13b1635 | 14572 | Act_Unit : constant Entity_Id := T.Act_Unit; |
86d32751 | 14573 | Eloc : constant Source_Ptr := T.Eloc; |
14574 | Source : constant Entity_Id := T.Source; | |
14575 | Target : constant Entity_Id := T.Target; | |
d6f39728 | 14576 | |
44705307 | 14577 | Source_Siz : Uint; |
14578 | Target_Siz : Uint; | |
d6f39728 | 14579 | |
14580 | begin | |
86d32751 | 14581 | -- Skip if function marked as warnings off |
14582 | ||
14583 | if Warnings_Off (Act_Unit) then | |
14584 | goto Continue; | |
14585 | end if; | |
14586 | ||
fdd294d1 | 14587 | -- This validation check, which warns if we have unequal sizes for |
14588 | -- unchecked conversion, and thus potentially implementation | |
d6f39728 | 14589 | -- dependent semantics, is one of the few occasions on which we |
fdd294d1 | 14590 | -- use the official RM size instead of Esize. See description in |
14591 | -- Einfo "Handling of Type'Size Values" for details. | |
d6f39728 | 14592 | |
f15731c4 | 14593 | if Serious_Errors_Detected = 0 |
d6f39728 | 14594 | and then Known_Static_RM_Size (Source) |
14595 | and then Known_Static_RM_Size (Target) | |
f25f4252 | 14596 | |
14597 | -- Don't do the check if warnings off for either type, note the | |
14598 | -- deliberate use of OR here instead of OR ELSE to get the flag | |
14599 | -- Warnings_Off_Used set for both types if appropriate. | |
14600 | ||
14601 | and then not (Has_Warnings_Off (Source) | |
14602 | or | |
14603 | Has_Warnings_Off (Target)) | |
d6f39728 | 14604 | then |
14605 | Source_Siz := RM_Size (Source); | |
14606 | Target_Siz := RM_Size (Target); | |
14607 | ||
14608 | if Source_Siz /= Target_Siz then | |
299480f9 | 14609 | Error_Msg |
cb97ae5c | 14610 | ("?z?types for unchecked conversion have different sizes!", |
97c85978 | 14611 | Eloc, Act_Unit); |
d6f39728 | 14612 | |
14613 | if All_Errors_Mode then | |
14614 | Error_Msg_Name_1 := Chars (Source); | |
14615 | Error_Msg_Uint_1 := Source_Siz; | |
14616 | Error_Msg_Name_2 := Chars (Target); | |
14617 | Error_Msg_Uint_2 := Target_Siz; | |
cb97ae5c | 14618 | Error_Msg ("\size of % is ^, size of % is ^?z?", Eloc); |
d6f39728 | 14619 | |
14620 | Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz); | |
14621 | ||
14622 | if Is_Discrete_Type (Source) | |
b9e61b2a | 14623 | and then |
14624 | Is_Discrete_Type (Target) | |
d6f39728 | 14625 | then |
14626 | if Source_Siz > Target_Siz then | |
299480f9 | 14627 | Error_Msg |
cb97ae5c | 14628 | ("\?z?^ high order bits of source will " |
1e3532e7 | 14629 | & "be ignored!", Eloc); |
d6f39728 | 14630 | |
9dfe12ae | 14631 | elsif Is_Unsigned_Type (Source) then |
299480f9 | 14632 | Error_Msg |
cb97ae5c | 14633 | ("\?z?source will be extended with ^ high order " |
1581f2d7 | 14634 | & "zero bits!", Eloc); |
d6f39728 | 14635 | |
14636 | else | |
299480f9 | 14637 | Error_Msg |
cb97ae5c | 14638 | ("\?z?source will be extended with ^ high order " |
1e3532e7 | 14639 | & "sign bits!", Eloc); |
d6f39728 | 14640 | end if; |
14641 | ||
14642 | elsif Source_Siz < Target_Siz then | |
14643 | if Is_Discrete_Type (Target) then | |
14644 | if Bytes_Big_Endian then | |
299480f9 | 14645 | Error_Msg |
cb97ae5c | 14646 | ("\?z?target value will include ^ undefined " |
97c85978 | 14647 | & "low order bits!", Eloc, Act_Unit); |
d6f39728 | 14648 | else |
299480f9 | 14649 | Error_Msg |
cb97ae5c | 14650 | ("\?z?target value will include ^ undefined " |
97c85978 | 14651 | & "high order bits!", Eloc, Act_Unit); |
d6f39728 | 14652 | end if; |
14653 | ||
14654 | else | |
299480f9 | 14655 | Error_Msg |
cb97ae5c | 14656 | ("\?z?^ trailing bits of target value will be " |
97c85978 | 14657 | & "undefined!", Eloc, Act_Unit); |
d6f39728 | 14658 | end if; |
14659 | ||
14660 | else pragma Assert (Source_Siz > Target_Siz); | |
0388e54e | 14661 | if Is_Discrete_Type (Source) then |
14662 | if Bytes_Big_Endian then | |
14663 | Error_Msg | |
14664 | ("\?z?^ low order bits of source will be " | |
97c85978 | 14665 | & "ignored!", Eloc, Act_Unit); |
0388e54e | 14666 | else |
14667 | Error_Msg | |
14668 | ("\?z?^ high order bits of source will be " | |
97c85978 | 14669 | & "ignored!", Eloc, Act_Unit); |
0388e54e | 14670 | end if; |
14671 | ||
14672 | else | |
14673 | Error_Msg | |
14674 | ("\?z?^ trailing bits of source will be " | |
97c85978 | 14675 | & "ignored!", Eloc, Act_Unit); |
0388e54e | 14676 | end if; |
d6f39728 | 14677 | end if; |
14678 | end if; | |
d6f39728 | 14679 | end if; |
14680 | end if; | |
14681 | ||
14682 | -- If both types are access types, we need to check the alignment. | |
14683 | -- If the alignment of both is specified, we can do it here. | |
14684 | ||
f15731c4 | 14685 | if Serious_Errors_Detected = 0 |
2a10e737 | 14686 | and then Is_Access_Type (Source) |
14687 | and then Is_Access_Type (Target) | |
d6f39728 | 14688 | and then Target_Strict_Alignment |
14689 | and then Present (Designated_Type (Source)) | |
14690 | and then Present (Designated_Type (Target)) | |
14691 | then | |
14692 | declare | |
14693 | D_Source : constant Entity_Id := Designated_Type (Source); | |
14694 | D_Target : constant Entity_Id := Designated_Type (Target); | |
14695 | ||
14696 | begin | |
14697 | if Known_Alignment (D_Source) | |
b9e61b2a | 14698 | and then |
14699 | Known_Alignment (D_Target) | |
d6f39728 | 14700 | then |
14701 | declare | |
14702 | Source_Align : constant Uint := Alignment (D_Source); | |
14703 | Target_Align : constant Uint := Alignment (D_Target); | |
14704 | ||
14705 | begin | |
14706 | if Source_Align < Target_Align | |
14707 | and then not Is_Tagged_Type (D_Source) | |
f25f4252 | 14708 | |
14709 | -- Suppress warning if warnings suppressed on either | |
14710 | -- type or either designated type. Note the use of | |
14711 | -- OR here instead of OR ELSE. That is intentional, | |
14712 | -- we would like to set flag Warnings_Off_Used in | |
14713 | -- all types for which warnings are suppressed. | |
14714 | ||
14715 | and then not (Has_Warnings_Off (D_Source) | |
14716 | or | |
14717 | Has_Warnings_Off (D_Target) | |
14718 | or | |
14719 | Has_Warnings_Off (Source) | |
14720 | or | |
14721 | Has_Warnings_Off (Target)) | |
d6f39728 | 14722 | then |
d6f39728 | 14723 | Error_Msg_Uint_1 := Target_Align; |
14724 | Error_Msg_Uint_2 := Source_Align; | |
299480f9 | 14725 | Error_Msg_Node_1 := D_Target; |
d6f39728 | 14726 | Error_Msg_Node_2 := D_Source; |
299480f9 | 14727 | Error_Msg |
cb97ae5c | 14728 | ("?z?alignment of & (^) is stricter than " |
97c85978 | 14729 | & "alignment of & (^)!", Eloc, Act_Unit); |
f25f4252 | 14730 | Error_Msg |
cb97ae5c | 14731 | ("\?z?resulting access value may have invalid " |
97c85978 | 14732 | & "alignment!", Eloc, Act_Unit); |
d6f39728 | 14733 | end if; |
14734 | end; | |
14735 | end if; | |
14736 | end; | |
14737 | end if; | |
14738 | end; | |
86d32751 | 14739 | |
14740 | <<Continue>> | |
14741 | null; | |
d6f39728 | 14742 | end loop; |
14743 | end Validate_Unchecked_Conversions; | |
14744 | ||
d6f39728 | 14745 | end Sem_Ch13; |